2023-10-24 10:57:17 -04:00
|
|
|
import { Project } from '../../../../types/project'
|
2023-11-23 07:03:22 -05:00
|
|
|
import { PermissionsLevel } from '@/features/ide-react/types/permissions'
|
2023-10-26 04:57:00 -04:00
|
|
|
import { ShareJsDoc } from '@/features/ide-react/editor/share-js-doc'
|
2023-10-24 10:57:17 -04:00
|
|
|
import { GotoLineOptions } from '@/features/ide-react/types/goto-line-options'
|
|
|
|
import { CursorPosition } from '@/features/ide-react/types/cursor-position'
|
2023-11-02 07:36:04 -04:00
|
|
|
import { FileTreeFindResult } from '@/features/ide-react/types/file-tree'
|
2023-10-24 10:57:17 -04:00
|
|
|
|
|
|
|
export type IdeEvents = {
|
|
|
|
'project:joined': [{ project: Project; permissionsLevel: PermissionsLevel }]
|
2023-10-26 04:57:00 -04:00
|
|
|
'document:closed': [doc: ShareJsDoc]
|
|
|
|
'doc:changed': [{ doc_id: string }]
|
|
|
|
'doc:saved': [{ doc_id: string }]
|
|
|
|
'doc:opened': []
|
|
|
|
'ide:opAcknowledged': [{ doc_id: string; op: any }]
|
|
|
|
'store-doc-position': []
|
2023-10-24 10:57:17 -04:00
|
|
|
'editor:gotoOffset': [gotoOffset: number]
|
|
|
|
'editor:gotoLine': [options: GotoLineOptions]
|
|
|
|
'cursor:editor:update': [position: CursorPosition]
|
2023-10-26 04:57:00 -04:00
|
|
|
'outline-toggled': [isOpen: boolean]
|
2023-10-24 10:57:17 -04:00
|
|
|
'cursor:editor:syncToPdf': []
|
|
|
|
'scroll:editor:update': []
|
|
|
|
'comment:start_adding': []
|
2023-11-28 06:24:23 -05:00
|
|
|
'history:toggle': []
|
2023-11-02 07:36:04 -04:00
|
|
|
'entity:deleted': [entity: FileTreeFindResult]
|
2023-10-24 10:57:17 -04:00
|
|
|
}
|
|
|
|
|
2024-01-05 05:05:07 -05:00
|
|
|
export class IdeEventEmitter extends EventTarget {
|
|
|
|
emit<T extends keyof IdeEvents>(eventName: T, ...detail: IdeEvents[T]) {
|
|
|
|
this.dispatchEvent(new CustomEvent<IdeEvents[T]>(eventName, { detail }))
|
|
|
|
}
|
2023-10-24 10:57:17 -04:00
|
|
|
|
2024-01-05 05:05:07 -05:00
|
|
|
on<T extends keyof IdeEvents>(
|
|
|
|
eventName: T,
|
|
|
|
listener: (event: CustomEvent<IdeEvents[T]>) => void
|
|
|
|
) {
|
|
|
|
this.addEventListener(eventName, listener as EventListener)
|
|
|
|
}
|
|
|
|
|
|
|
|
once<T extends keyof IdeEvents>(
|
|
|
|
eventName: T,
|
|
|
|
listener: (event: CustomEvent<IdeEvents[T]>) => void
|
|
|
|
) {
|
|
|
|
this.addEventListener(eventName, listener as EventListener, { once: true })
|
|
|
|
}
|
|
|
|
|
|
|
|
off<T extends keyof IdeEvents>(
|
|
|
|
eventName: T,
|
|
|
|
listener: (event: CustomEvent<IdeEvents[T]>) => void
|
|
|
|
) {
|
|
|
|
this.removeEventListener(eventName, listener as EventListener)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function createIdeEventEmitter() {
|
|
|
|
return new IdeEventEmitter()
|
2023-10-24 10:57:17 -04:00
|
|
|
}
|