mirror of https://github.com/status-im/codimd.git
lint: lib/realtime/realtime.ts
- add ot typing Signed-off-by: Raccoon <raccoon@hackmd.io>
This commit is contained in:
parent
847acda4de
commit
f35d68409d
|
@ -72,7 +72,7 @@ export interface RealtimeNoteData {
|
|||
updatetime: number
|
||||
|
||||
// type: ot.EditorSocketIOServer
|
||||
server: any
|
||||
server: ot.EditorSocketIOServer
|
||||
|
||||
authors: Record<string, RealtimeAuthorData>
|
||||
authorship: Authorship[]
|
||||
|
@ -714,7 +714,7 @@ export function ifMayEdit(socket: SocketIO.Socket, callback: (canEdit: boolean)
|
|||
}
|
||||
|
||||
// TODO: test it
|
||||
function operationCallback(socket: SocketIO.Socket, operation: any) {
|
||||
function operationCallback(socket: SocketIO.Socket, operation: ot.Operation[]) {
|
||||
const noteId = socket.noteId
|
||||
if (!noteId || !notes[noteId]) return
|
||||
const note = notes[noteId]
|
||||
|
|
|
@ -17,7 +17,8 @@
|
|||
|
||||
"typeRoots": ["./typings", "./node_modules/@types"],
|
||||
"paths": {
|
||||
"@hackmd/diff-match-patch": ["./typings/diff-match-patch/"]
|
||||
"@hackmd/diff-match-patch": ["./typings/diff-match-patch/"],
|
||||
"ot": ["./typings/ot/"]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
import SocketIO from "socket.io";
|
||||
import EventEmitter from "events";
|
||||
|
||||
declare module 'ot' {
|
||||
|
||||
export const version: number
|
||||
|
||||
export type Operation = number | string
|
||||
|
||||
export class TextOperation {
|
||||
static isRetain(op: Operation): boolean
|
||||
|
||||
static isInsert(op: Operation): boolean
|
||||
|
||||
static isDelete(op: Operation): boolean
|
||||
}
|
||||
|
||||
export class EditorSocketIOServer extends EventEmitter {
|
||||
|
||||
public isDirty: boolean
|
||||
public document: string
|
||||
public debug: boolean
|
||||
public operations: Operation[]
|
||||
|
||||
constructor(
|
||||
document: string,
|
||||
operations: Operation[],
|
||||
docId: string,
|
||||
mayWrite: (
|
||||
socket: SocketIO.Socket,
|
||||
callback: (canEdit: boolean) => void) => void,
|
||||
operationCallback: (
|
||||
socket: SocketIO.Socket,
|
||||
operation: Operation[]) => void,
|
||||
operationEventCallback?: any)
|
||||
|
||||
setLogger(logger): void
|
||||
|
||||
debugLog(mes: string): void
|
||||
|
||||
setDocumentMaxLength(number): void
|
||||
|
||||
addClient(socket: SocketIO.Socket): void
|
||||
|
||||
onOperation(socket: SocketIO.Server, revision, operation, selection)
|
||||
|
||||
onGetOperations(socket, base, head)
|
||||
|
||||
updateSelection(socket, selection)
|
||||
|
||||
setName(socket, name)
|
||||
|
||||
setColor(socket, color)
|
||||
|
||||
getClient(clientId)
|
||||
|
||||
onDisconnect(socket)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue