-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
TLReactSubscriptions.tsx
45 lines (41 loc) · 1.67 KB
/
TLReactSubscriptions.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import type { TLSubscriptionEventInfo, TLSubscriptionEventName } from '@tldraw/core'
import type { TLReactShape } from '../lib'
import type { TLReactApp } from '../lib/TLReactApp'
export type TLReactSubscription<
S extends TLReactShape = TLReactShape,
R extends TLReactApp<S> = TLReactApp<S>,
E extends TLSubscriptionEventName = TLSubscriptionEventName
> = {
event: E
callback: TLReactCallback<S, R, E>
}
export type TLReactSubscribe<
S extends TLReactShape = TLReactShape,
R extends TLReactApp<S> = TLReactApp<S>
> = {
<E extends TLSubscriptionEventName>(subscription: TLReactSubscription<S, R, E>): () => void
<E extends TLSubscriptionEventName>(event: E, callback: TLReactCallback<S, R, E>): () => void
}
export type TLReactCallback<
S extends TLReactShape = TLReactShape,
R extends TLReactApp<S> = TLReactApp<S>,
E extends TLSubscriptionEventName = TLSubscriptionEventName
> = (app: R, info: TLSubscriptionEventInfo<E>) => void
export interface TLReactCallbacks<
S extends TLReactShape = TLReactShape,
R extends TLReactApp<S> = TLReactApp<S>
> {
onMount: TLReactCallback<S, R, 'mount'>
onPersist: TLReactCallback<S, R, 'persist'>
onSave: TLReactCallback<S, R, 'save'>
onSaveAs: TLReactCallback<S, R, 'saveAs'>
onError: TLReactCallback<S, R, 'error'>
onCreateShapes: TLReactCallback<S, R, 'create-shapes'>
onCreateAssets: TLReactCallback<S, R, 'create-assets'>
onDeleteShapes: TLReactCallback<S, R, 'delete-shapes'>
onDeleteAssets: TLReactCallback<S, R, 'delete-assets'>
onDrop: TLReactCallback<S, R, 'drop'>
onCanvasDBClick: TLReactCallback<S, R, 'canvas-dbclick'>
onPaste: TLReactCallback<S, R, 'paste'>
onCopy: TLReactCallback<S, R, 'copy'>
}