-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimplementer-types.ts
137 lines (125 loc) · 4.39 KB
/
implementer-types.ts
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import type { Extension } from '@codemirror/state';
import type { DOCUMENT } from './document.js';
export interface SetupProps {
/**
* Given a document, create a new Inspector instance and render it to the DOM element
* provided.
*
* @param doc
* @returns
*/
createAndMountInspector: (elem: HTMLDivElement, doc: DOCUMENT) => Inspector | void;
/**
* Codemirror extensions to pass to new codemirror views. The default is
*
* ```javascript
* import { EditorView, keymap, lineNumbers } from '@codemirror/view';
* import { defaultKeymap, history, historyKeymap } from '@codemirror/commands';
*
* [
* lineNumbers(),
* history(),
* EditorView.lineWrapping,
* keymap.of([...defaultKeymap, ...historyKeymap]),
* ]
* ```
*
*/
codemirrorExtensions?: Extension[];
/**
* sketchzone follows the GraphiQL convention of pulling the tab title out of the
* document itself, rather than having some separate UI for document names. This means
* that the implementor needs to tell sketchzone how to parse a document just enough
* to get a title.
*
* Optional: if omitted, the first line of the document is used
*
* @param doc
* @returns
*/
extractTitleFromDoc?: (doc: DOCUMENT) => string;
/**
* Creates a new document.
*
* Optional: if omitted, just creates the empty-string doc
*/
emptyDocument?: () => DOCUMENT;
/**
* What should we call a document? What should the button that says "load ___" and
* loads a document into the inspector say in that blank?
*
* Optional: if omitted, they're called "document"
*/
documentName?: string;
/**
* What's the name of the editor? This will be used to change the page title: if you
* put "Jibber" then a document with title "Jabber #4 THIS ONE" will cause the page
* title to be "Jibber | Jabber #4 THIS ONE". This title get inserted into the
* #sketchzone-logo element **if that element is non-empty**.
*
* Optional: if omitted, the `document.title` value will be used instead.
*/
appName?: string;
/**
* If this is a brand session for sketchzone, with no saved sketches, it can be
* confusing to look at a totally blank editor for the first time, so providing a
* couple of template sketches is a friendly thing to do.
*
* Optional: if omitted, there will be a single sketch containing a new empty
* document.
*/
defaultEntries?: DOCUMENT[];
/**
* Where should the circle-question-mark button in the upper left go?
*
* Option: if omitted, there won't be a circle-question-mark button.
*/
infoUrl?: string;
}
export interface Inspector {
/**
* Called when the "reload" button is pressed with the updated document.
*
* Will only be called on a mounted Inspector. If omitted, reloading will be done
* by first calling unmount(), then calling destroy(), then calling the initial
* `createAndMountInspector` function again.
*/
reload?: (doc: DOCUMENT) => Promise<void>;
/**
* Called when we switch to another tab, so that the #sketchzone-inspector-contents
* needs to be taken over by something else.
*
* If unmount returns `true`, that signals that any resources associated with this
* inspector have been reclaimed. No additional methods on this object (including
* destroy()) will ever be called. If the tab is re-opened, a new `Inspector`
* object will be created.
*
* Will only be called on a mounted inspector, just before the element the inspector
* is mounted to is removed from the DOM tree.
*
* Optional: if omitted, does nothing.
*/
unmount?: () => Promise<boolean | void>;
/**
* Called when we return to a tab that had an active inspector.
*
* The previously active inspectors unmount() method will already have returned
* before this method is called.
*
* Will only be called on an unmounted Inspector, just after the element the inspector
* is mounted to is re-inserted into the DOM tree.
*
* Optional: if omitted, does nothing.
*/
remount?: () => Promise<void>;
/**
* If the Inspector is keeping state around after unmounting, this function signals
* that the relevant resources should be reclaimed. No additional methods on this
* object will be called after destroy() is called.
*
* Will only be called on an unmounted Inspector.
*
* Optional: if omitted, does nothing.
*/
destroy?: () => Promise<void>;
}