@portabletext/toolbar 8.0.42 → 8.0.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +376 -523
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1300 -1953
- package/dist/index.js.map +1 -1
- package/package.json +12 -10
package/dist/index.js
CHANGED
|
@@ -1,2032 +1,1379 @@
|
|
|
1
1
|
import { useEditor, useEditorSelector } from "@portabletext/editor";
|
|
2
2
|
import * as selectors from "@portabletext/editor/selectors";
|
|
3
|
-
import {
|
|
3
|
+
import { compareApplicableSchema, getApplicableSchema, isSelectionExpanded } from "@portabletext/editor/selectors";
|
|
4
4
|
import { c } from "react/compiler-runtime";
|
|
5
5
|
import { getUnionSchema } from "@portabletext/editor/traversal";
|
|
6
|
-
import { defineBehavior,
|
|
6
|
+
import { defineBehavior, effect, execute, forward, raise } from "@portabletext/editor/behaviors";
|
|
7
7
|
import { useActor, useActorRef } from "@xstate/react";
|
|
8
|
-
import { fromCallback, setup
|
|
8
|
+
import { assign, fromCallback, setup } from "xstate";
|
|
9
9
|
import * as React from "react";
|
|
10
10
|
import { useEffect } from "react";
|
|
11
|
+
/**
|
|
12
|
+
* @beta
|
|
13
|
+
*
|
|
14
|
+
* React hook that subscribes to {@link getApplicableSchema} for the active
|
|
15
|
+
* editor and returns a stable reference across editor ticks while the
|
|
16
|
+
* applicable set is unchanged.
|
|
17
|
+
*
|
|
18
|
+
* Pair with {@link useToolbarSchema} to render a static toolbar whose
|
|
19
|
+
* buttons stay stable across selection moves and gate their enabled state
|
|
20
|
+
* on whether the corresponding name is in the relevant set.
|
|
21
|
+
*/
|
|
11
22
|
function useApplicableSchema() {
|
|
12
|
-
|
|
13
|
-
|
|
23
|
+
let editor = useEditor();
|
|
24
|
+
return useEditorSelector(editor, getApplicableSchema, compareApplicableSchema);
|
|
14
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* @beta
|
|
28
|
+
*
|
|
29
|
+
* Resolve the editor's full toolbar schema. Returns the union of every
|
|
30
|
+
* decorator, annotation, list, style, block object and inline object declared
|
|
31
|
+
* anywhere in the editor's schema graph that is reachable from a position
|
|
32
|
+
* where text is edited - the root schema merged with the sub-schema of every
|
|
33
|
+
* registered container whose field accepts text blocks. Useful for rendering
|
|
34
|
+
* a static toolbar whose buttons stay stable across selection moves.
|
|
35
|
+
*
|
|
36
|
+
* Re-renders only when the schema graph or the extension callbacks change.
|
|
37
|
+
* Pair with {@link useApplicableSchema} to determine which entries are
|
|
38
|
+
* applicable at the current selection (which buttons should be enabled vs.
|
|
39
|
+
* disabled).
|
|
40
|
+
*/
|
|
15
41
|
function useToolbarSchema(props) {
|
|
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
|
-
decorators: t0,
|
|
56
|
-
annotations: t1,
|
|
57
|
-
lists: t2,
|
|
58
|
-
blockObjects: t3,
|
|
59
|
-
inlineObjects: t4,
|
|
60
|
-
styles: t5
|
|
61
|
-
}, $[30] = t0, $[31] = t1, $[32] = t2, $[33] = t3, $[34] = t4, $[35] = t5, $[36] = t6) : t6 = $[36], t6;
|
|
42
|
+
let $ = c(37), editor = useEditor(), union = useEditorSelector(editor, _temp$2, compareSchemas), t0;
|
|
43
|
+
if ($[0] !== props || $[1] !== union.decorators) {
|
|
44
|
+
let t1;
|
|
45
|
+
$[3] === props ? t1 = $[4] : (t1 = (decorator) => props.extendDecorator?.(decorator) ?? decorator, $[3] = props, $[4] = t1), t0 = union.decorators.map(t1), $[0] = props, $[1] = union.decorators, $[2] = t0;
|
|
46
|
+
} else t0 = $[2];
|
|
47
|
+
let t1;
|
|
48
|
+
if ($[5] !== props || $[6] !== union.annotations) {
|
|
49
|
+
let t2;
|
|
50
|
+
$[8] === props ? t2 = $[9] : (t2 = (annotation) => props.extendAnnotation?.(annotation) ?? annotation, $[8] = props, $[9] = t2), t1 = union.annotations.map(t2), $[5] = props, $[6] = union.annotations, $[7] = t1;
|
|
51
|
+
} else t1 = $[7];
|
|
52
|
+
let t2;
|
|
53
|
+
if ($[10] !== props || $[11] !== union.lists) {
|
|
54
|
+
let t3;
|
|
55
|
+
$[13] === props ? t3 = $[14] : (t3 = (list) => props.extendList?.(list) ?? list, $[13] = props, $[14] = t3), t2 = union.lists.map(t3), $[10] = props, $[11] = union.lists, $[12] = t2;
|
|
56
|
+
} else t2 = $[12];
|
|
57
|
+
let t3;
|
|
58
|
+
if ($[15] !== props || $[16] !== union.blockObjects) {
|
|
59
|
+
let t4;
|
|
60
|
+
$[18] === props ? t4 = $[19] : (t4 = (blockObject) => props.extendBlockObject?.(blockObject) ?? blockObject, $[18] = props, $[19] = t4), t3 = union.blockObjects.map(t4), $[15] = props, $[16] = union.blockObjects, $[17] = t3;
|
|
61
|
+
} else t3 = $[17];
|
|
62
|
+
let t4;
|
|
63
|
+
if ($[20] !== props || $[21] !== union.inlineObjects) {
|
|
64
|
+
let t5;
|
|
65
|
+
$[23] === props ? t5 = $[24] : (t5 = (inlineObject) => props.extendInlineObject?.(inlineObject) ?? inlineObject, $[23] = props, $[24] = t5), t4 = union.inlineObjects.map(t5), $[20] = props, $[21] = union.inlineObjects, $[22] = t4;
|
|
66
|
+
} else t4 = $[22];
|
|
67
|
+
let t5;
|
|
68
|
+
if ($[25] !== props || $[26] !== union.styles) {
|
|
69
|
+
let t6;
|
|
70
|
+
$[28] === props ? t6 = $[29] : (t6 = (style) => props.extendStyle?.(style) ?? style, $[28] = props, $[29] = t6), t5 = union.styles.map(t6), $[25] = props, $[26] = union.styles, $[27] = t5;
|
|
71
|
+
} else t5 = $[27];
|
|
72
|
+
let t6;
|
|
73
|
+
return $[30] !== t0 || $[31] !== t1 || $[32] !== t2 || $[33] !== t3 || $[34] !== t4 || $[35] !== t5 ? (t6 = {
|
|
74
|
+
decorators: t0,
|
|
75
|
+
annotations: t1,
|
|
76
|
+
lists: t2,
|
|
77
|
+
blockObjects: t3,
|
|
78
|
+
inlineObjects: t4,
|
|
79
|
+
styles: t5
|
|
80
|
+
}, $[30] = t0, $[31] = t1, $[32] = t2, $[33] = t3, $[34] = t4, $[35] = t5, $[36] = t6) : t6 = $[36], t6;
|
|
62
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* @beta
|
|
84
|
+
*/
|
|
63
85
|
function _temp$2(snapshot) {
|
|
64
|
-
|
|
86
|
+
return getUnionSchema(snapshot.context.schema, snapshot.context.containers);
|
|
65
87
|
}
|
|
66
88
|
function compareSchemas(a, b) {
|
|
67
|
-
|
|
89
|
+
return a === b || compareNamed(a.decorators, b.decorators) && compareNamed(a.annotations, b.annotations) && compareNamed(a.lists, b.lists) && compareNamed(a.styles, b.styles) && compareNamed(a.blockObjects, b.blockObjects) && compareNamed(a.inlineObjects, b.inlineObjects);
|
|
68
90
|
}
|
|
69
91
|
function compareNamed(a, b) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
for (let i = 0; i < a.length; i++)
|
|
75
|
-
if (a[i].name !== b[i].name)
|
|
76
|
-
return !1;
|
|
77
|
-
return !0;
|
|
92
|
+
if (a === b) return !0;
|
|
93
|
+
if (a.length !== b.length) return !1;
|
|
94
|
+
for (let i = 0; i < a.length; i++) if (a[i].name !== b[i].name) return !1;
|
|
95
|
+
return !0;
|
|
78
96
|
}
|
|
79
|
-
const disableListener = fromCallback(({
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}) => (input.editor.getSnapshot().context.readOnly ? sendBack({
|
|
83
|
-
type: "disable"
|
|
84
|
-
}) : sendBack({
|
|
85
|
-
type: "enable"
|
|
86
|
-
}), input.editor.on("*", () => {
|
|
87
|
-
input.editor.getSnapshot().context.readOnly ? sendBack({
|
|
88
|
-
type: "disable"
|
|
89
|
-
}) : sendBack({
|
|
90
|
-
type: "enable"
|
|
91
|
-
});
|
|
92
|
-
}, {
|
|
93
|
-
batch: !0
|
|
94
|
-
}).unsubscribe));
|
|
97
|
+
const disableListener = fromCallback(({ input, sendBack }) => (input.editor.getSnapshot().context.readOnly ? sendBack({ type: "disable" }) : sendBack({ type: "enable" }), input.editor.on("*", () => {
|
|
98
|
+
input.editor.getSnapshot().context.readOnly ? sendBack({ type: "disable" }) : sendBack({ type: "enable" });
|
|
99
|
+
}, { batch: !0 }).unsubscribe));
|
|
95
100
|
function useMutuallyExclusiveAnnotation(props) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return [...mutuallyExclusive.map(_temp$1), execute(event_0)];
|
|
116
|
-
}]
|
|
117
|
-
})
|
|
118
|
-
});
|
|
119
|
-
}, t1 = [editor, props.schemaType.name, props.schemaType.mutuallyExclusive], $[0] = editor, $[1] = props.schemaType.mutuallyExclusive, $[2] = props.schemaType.name, $[3] = t0, $[4] = t1) : (t0 = $[3], t1 = $[4]), useEffect(t0, t1);
|
|
101
|
+
let $ = c(5), editor = useEditor(), t0, t1;
|
|
102
|
+
$[0] !== editor || $[1] !== props.schemaType.mutuallyExclusive || $[2] !== props.schemaType.name ? (t0 = () => {
|
|
103
|
+
let mutuallyExclusive = props.schemaType.mutuallyExclusive;
|
|
104
|
+
if (mutuallyExclusive) return editor.registerBehavior({ behavior: defineBehavior({
|
|
105
|
+
on: "annotation.add",
|
|
106
|
+
guard: (t2) => {
|
|
107
|
+
let { snapshot, event } = t2;
|
|
108
|
+
return event.annotation.name === props.schemaType.name && isSelectionExpanded(snapshot);
|
|
109
|
+
},
|
|
110
|
+
actions: [(t3) => {
|
|
111
|
+
let { event: event_0 } = t3;
|
|
112
|
+
return [...mutuallyExclusive.map(_temp$1), execute(event_0)];
|
|
113
|
+
}]
|
|
114
|
+
}) });
|
|
115
|
+
}, t1 = [
|
|
116
|
+
editor,
|
|
117
|
+
props.schemaType.name,
|
|
118
|
+
props.schemaType.mutuallyExclusive
|
|
119
|
+
], $[0] = editor, $[1] = props.schemaType.mutuallyExclusive, $[2] = props.schemaType.name, $[3] = t0, $[4] = t1) : (t0 = $[3], t1 = $[4]), useEffect(t0, t1);
|
|
120
120
|
}
|
|
121
121
|
function _temp$1(annotation) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
});
|
|
122
|
+
return raise({
|
|
123
|
+
type: "annotation.remove",
|
|
124
|
+
annotation: { name: annotation }
|
|
125
|
+
});
|
|
128
126
|
}
|
|
129
|
-
const activeListener$6 = fromCallback(({
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
guard: ({
|
|
154
|
-
event
|
|
155
|
-
}) => shortcut.guard(event.originEvent),
|
|
156
|
-
actions: [() => [raise({
|
|
157
|
-
type: "annotation.remove",
|
|
158
|
-
annotation: {
|
|
159
|
-
name: input.schemaType.name
|
|
160
|
-
}
|
|
161
|
-
}), effect(() => {
|
|
162
|
-
input.editor.send({
|
|
163
|
-
type: "focus"
|
|
164
|
-
});
|
|
165
|
-
})]]
|
|
166
|
-
})
|
|
167
|
-
});
|
|
168
|
-
}), keyboardShortcutShowInsertDialog = fromCallback(({
|
|
169
|
-
input,
|
|
170
|
-
sendBack
|
|
171
|
-
}) => {
|
|
172
|
-
const shortcut = input.schemaType.shortcut;
|
|
173
|
-
if (shortcut)
|
|
174
|
-
return input.editor.registerBehavior({
|
|
175
|
-
behavior: defineBehavior({
|
|
176
|
-
on: "keyboard.keydown",
|
|
177
|
-
guard: ({
|
|
178
|
-
event
|
|
179
|
-
}) => shortcut.guard(event.originEvent),
|
|
180
|
-
actions: [() => [effect(() => {
|
|
181
|
-
sendBack({
|
|
182
|
-
type: "open dialog"
|
|
183
|
-
});
|
|
184
|
-
})]]
|
|
185
|
-
})
|
|
186
|
-
});
|
|
127
|
+
const activeListener$6 = fromCallback(({ input, sendBack }) => (selectors.isActiveAnnotation(input.schemaType.name)(input.editor.getSnapshot()) ? sendBack({ type: "set active" }) : sendBack({ type: "set inactive" }), input.editor.on("*", () => {
|
|
128
|
+
let snapshot = input.editor.getSnapshot();
|
|
129
|
+
selectors.isActiveAnnotation(input.schemaType.name)(snapshot) ? sendBack({ type: "set active" }) : sendBack({ type: "set inactive" });
|
|
130
|
+
}, { batch: !0 }).unsubscribe)), keyboardShortcutRemove = fromCallback(({ input }) => {
|
|
131
|
+
let shortcut = input.schemaType.shortcut;
|
|
132
|
+
if (shortcut) return input.editor.registerBehavior({ behavior: defineBehavior({
|
|
133
|
+
on: "keyboard.keydown",
|
|
134
|
+
guard: ({ event }) => shortcut.guard(event.originEvent),
|
|
135
|
+
actions: [() => [raise({
|
|
136
|
+
type: "annotation.remove",
|
|
137
|
+
annotation: { name: input.schemaType.name }
|
|
138
|
+
}), effect(() => {
|
|
139
|
+
input.editor.send({ type: "focus" });
|
|
140
|
+
})]]
|
|
141
|
+
}) });
|
|
142
|
+
}), keyboardShortcutShowInsertDialog = fromCallback(({ input, sendBack }) => {
|
|
143
|
+
let shortcut = input.schemaType.shortcut;
|
|
144
|
+
if (shortcut) return input.editor.registerBehavior({ behavior: defineBehavior({
|
|
145
|
+
on: "keyboard.keydown",
|
|
146
|
+
guard: ({ event }) => shortcut.guard(event.originEvent),
|
|
147
|
+
actions: [() => [effect(() => {
|
|
148
|
+
sendBack({ type: "open dialog" });
|
|
149
|
+
})]]
|
|
150
|
+
}) });
|
|
187
151
|
}), annotationButtonMachine = setup({
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}), context.editor.send({
|
|
217
|
-
type: "focus"
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
},
|
|
221
|
-
actors: {
|
|
222
|
-
"active listener": activeListener$6,
|
|
223
|
-
"disable listener": disableListener,
|
|
224
|
-
"keyboard shortcut.remove": keyboardShortcutRemove,
|
|
225
|
-
"keyboard shortcut.show insert dialog": keyboardShortcutShowInsertDialog
|
|
226
|
-
}
|
|
152
|
+
types: {
|
|
153
|
+
context: {},
|
|
154
|
+
input: {},
|
|
155
|
+
events: {}
|
|
156
|
+
},
|
|
157
|
+
actions: {
|
|
158
|
+
"add annotation": ({ context, event }) => {
|
|
159
|
+
event.type === "add" && (context.editor.send({
|
|
160
|
+
type: "annotation.add",
|
|
161
|
+
annotation: {
|
|
162
|
+
name: context.schemaType.name,
|
|
163
|
+
value: event.annotation.value
|
|
164
|
+
}
|
|
165
|
+
}), context.editor.send({ type: "focus" }));
|
|
166
|
+
},
|
|
167
|
+
"remove annotation": ({ context }) => {
|
|
168
|
+
context.editor.send({
|
|
169
|
+
type: "annotation.remove",
|
|
170
|
+
annotation: { name: context.schemaType.name }
|
|
171
|
+
}), context.editor.send({ type: "focus" });
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
actors: {
|
|
175
|
+
"active listener": activeListener$6,
|
|
176
|
+
"disable listener": disableListener,
|
|
177
|
+
"keyboard shortcut.remove": keyboardShortcutRemove,
|
|
178
|
+
"keyboard shortcut.show insert dialog": keyboardShortcutShowInsertDialog
|
|
179
|
+
}
|
|
227
180
|
}).createMachine({
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
editor: context.editor,
|
|
303
|
-
schemaType: context.schemaType
|
|
304
|
-
})
|
|
305
|
-
},
|
|
306
|
-
on: {
|
|
307
|
-
"open dialog": {
|
|
308
|
-
target: "showing dialog"
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
},
|
|
312
|
-
"showing dialog": {
|
|
313
|
-
on: {
|
|
314
|
-
"close dialog": {
|
|
315
|
-
target: "idle"
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
},
|
|
321
|
-
active: {
|
|
322
|
-
invoke: {
|
|
323
|
-
src: "keyboard shortcut.remove",
|
|
324
|
-
input: ({
|
|
325
|
-
context
|
|
326
|
-
}) => ({
|
|
327
|
-
editor: context.editor,
|
|
328
|
-
schemaType: context.schemaType
|
|
329
|
-
})
|
|
330
|
-
},
|
|
331
|
-
on: {
|
|
332
|
-
"set inactive": {
|
|
333
|
-
target: "#annotation button.enabled.inactive"
|
|
334
|
-
},
|
|
335
|
-
disable: {
|
|
336
|
-
target: "#annotation button.disabled.active"
|
|
337
|
-
},
|
|
338
|
-
remove: {
|
|
339
|
-
actions: "remove annotation"
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
181
|
+
id: "annotation button",
|
|
182
|
+
context: ({ input }) => ({
|
|
183
|
+
editor: input.editor,
|
|
184
|
+
schemaType: input.schemaType
|
|
185
|
+
}),
|
|
186
|
+
invoke: [{
|
|
187
|
+
src: "active listener",
|
|
188
|
+
input: ({ context }) => ({
|
|
189
|
+
editor: context.editor,
|
|
190
|
+
schemaType: context.schemaType
|
|
191
|
+
})
|
|
192
|
+
}, {
|
|
193
|
+
src: "disable listener",
|
|
194
|
+
input: ({ context }) => ({
|
|
195
|
+
editor: context.editor,
|
|
196
|
+
schemaType: context.schemaType
|
|
197
|
+
})
|
|
198
|
+
}],
|
|
199
|
+
initial: "disabled",
|
|
200
|
+
states: {
|
|
201
|
+
disabled: {
|
|
202
|
+
initial: "inactive",
|
|
203
|
+
states: {
|
|
204
|
+
inactive: { on: {
|
|
205
|
+
enable: { target: "#annotation button.enabled.inactive" },
|
|
206
|
+
"set active": { target: "active" }
|
|
207
|
+
} },
|
|
208
|
+
active: { on: {
|
|
209
|
+
enable: { target: "#annotation button.enabled.active" },
|
|
210
|
+
"set inactive": { target: "inactive" }
|
|
211
|
+
} }
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
enabled: {
|
|
215
|
+
initial: "inactive",
|
|
216
|
+
states: {
|
|
217
|
+
inactive: {
|
|
218
|
+
initial: "idle",
|
|
219
|
+
on: {
|
|
220
|
+
disable: { target: "#annotation button.disabled.inactive" },
|
|
221
|
+
"set active": { target: "#annotation button.enabled.active" },
|
|
222
|
+
add: { actions: "add annotation" }
|
|
223
|
+
},
|
|
224
|
+
states: {
|
|
225
|
+
idle: {
|
|
226
|
+
invoke: {
|
|
227
|
+
src: "keyboard shortcut.show insert dialog",
|
|
228
|
+
input: ({ context }) => ({
|
|
229
|
+
editor: context.editor,
|
|
230
|
+
schemaType: context.schemaType
|
|
231
|
+
})
|
|
232
|
+
},
|
|
233
|
+
on: { "open dialog": { target: "showing dialog" } }
|
|
234
|
+
},
|
|
235
|
+
"showing dialog": { on: { "close dialog": { target: "idle" } } }
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
active: {
|
|
239
|
+
invoke: {
|
|
240
|
+
src: "keyboard shortcut.remove",
|
|
241
|
+
input: ({ context }) => ({
|
|
242
|
+
editor: context.editor,
|
|
243
|
+
schemaType: context.schemaType
|
|
244
|
+
})
|
|
245
|
+
},
|
|
246
|
+
on: {
|
|
247
|
+
"set inactive": { target: "#annotation button.enabled.inactive" },
|
|
248
|
+
disable: { target: "#annotation button.disabled.active" },
|
|
249
|
+
remove: { actions: "remove annotation" }
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
346
255
|
});
|
|
256
|
+
/**
|
|
257
|
+
* @beta
|
|
258
|
+
* Manages the state, keyboard shortcut and available events for an annotation
|
|
259
|
+
* button.
|
|
260
|
+
*
|
|
261
|
+
* Note: This hook assumes that the button triggers a dialog for inputting
|
|
262
|
+
* the annotation value.
|
|
263
|
+
*/
|
|
347
264
|
function useAnnotationButton(props) {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
let t2;
|
|
363
|
-
return $[5] !== send || $[6] !== t1 ? (t2 = {
|
|
364
|
-
snapshot: t1,
|
|
365
|
-
send
|
|
366
|
-
}, $[5] = send, $[6] = t1, $[7] = t2) : t2 = $[7], t2;
|
|
265
|
+
let $ = c(8), editor = useEditor(), t0;
|
|
266
|
+
$[0] !== editor || $[1] !== props.schemaType ? (t0 = { input: {
|
|
267
|
+
editor,
|
|
268
|
+
schemaType: props.schemaType
|
|
269
|
+
} }, $[0] = editor, $[1] = props.schemaType, $[2] = t0) : t0 = $[2];
|
|
270
|
+
let [snapshot, send] = useActor(annotationButtonMachine, t0);
|
|
271
|
+
useMutuallyExclusiveAnnotation(props);
|
|
272
|
+
let t1;
|
|
273
|
+
$[3] === snapshot ? t1 = $[4] : (t1 = { matches: (state) => snapshot.matches(state) }, $[3] = snapshot, $[4] = t1);
|
|
274
|
+
let t2;
|
|
275
|
+
return $[5] !== send || $[6] !== t1 ? (t2 = {
|
|
276
|
+
snapshot: t1,
|
|
277
|
+
send
|
|
278
|
+
}, $[5] = send, $[6] = t1, $[7] = t2) : t2 = $[7], t2;
|
|
367
279
|
}
|
|
368
|
-
const activeListener$5 = fromCallback(({
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
},
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
event.type === "remove" && (context.editor.send({
|
|
419
|
-
type: "annotation.remove",
|
|
420
|
-
annotation: {
|
|
421
|
-
name: event.schemaType.name
|
|
422
|
-
}
|
|
423
|
-
}), context.editor.send({
|
|
424
|
-
type: "focus"
|
|
425
|
-
}));
|
|
426
|
-
}
|
|
427
|
-
},
|
|
428
|
-
actors: {
|
|
429
|
-
"disable listener": disableListener,
|
|
430
|
-
"active listener": activeListener$5
|
|
431
|
-
}
|
|
280
|
+
const activeListener$5 = fromCallback(({ input, sendBack }) => input.editor.on("*", () => {
|
|
281
|
+
let snapshot = input.editor.getSnapshot(), activeAnnotations = selectors.getActiveAnnotations(snapshot), focusBlock = selectors.getFocusBlock(snapshot);
|
|
282
|
+
if (activeAnnotations.length === 0 || !focusBlock) {
|
|
283
|
+
sendBack({ type: "set inactive" });
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
let firstSelectedChild = input.editor.dom.getChildNodes(snapshot).at(0);
|
|
287
|
+
if (!firstSelectedChild || !(firstSelectedChild instanceof Element)) {
|
|
288
|
+
sendBack({ type: "set inactive" });
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
let elementRef = React.createRef();
|
|
292
|
+
elementRef.current = firstSelectedChild, sendBack({
|
|
293
|
+
type: "set active",
|
|
294
|
+
annotations: activeAnnotations.flatMap((annotation) => {
|
|
295
|
+
let schemaType = input.schemaTypes.find((schemaType) => schemaType.name === annotation._type);
|
|
296
|
+
return schemaType ? {
|
|
297
|
+
value: annotation,
|
|
298
|
+
schemaType,
|
|
299
|
+
at: [
|
|
300
|
+
...focusBlock.path,
|
|
301
|
+
"markDefs",
|
|
302
|
+
{ _key: annotation._key }
|
|
303
|
+
]
|
|
304
|
+
} : [];
|
|
305
|
+
}),
|
|
306
|
+
elementRef
|
|
307
|
+
});
|
|
308
|
+
}, { batch: !0 }).unsubscribe), annotationPopoverMachine = setup({
|
|
309
|
+
types: {
|
|
310
|
+
context: {},
|
|
311
|
+
input: {},
|
|
312
|
+
events: {}
|
|
313
|
+
},
|
|
314
|
+
actions: {
|
|
315
|
+
reset: assign({
|
|
316
|
+
annotations: [],
|
|
317
|
+
elementRef: React.createRef()
|
|
318
|
+
}),
|
|
319
|
+
remove: ({ context, event }) => {
|
|
320
|
+
event.type === "remove" && (context.editor.send({
|
|
321
|
+
type: "annotation.remove",
|
|
322
|
+
annotation: { name: event.schemaType.name }
|
|
323
|
+
}), context.editor.send({ type: "focus" }));
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
actors: {
|
|
327
|
+
"disable listener": disableListener,
|
|
328
|
+
"active listener": activeListener$5
|
|
329
|
+
}
|
|
432
330
|
}).createMachine({
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
},
|
|
522
|
-
disable: {
|
|
523
|
-
target: "#annotation popover.disabled.active"
|
|
524
|
-
},
|
|
525
|
-
"set active": {
|
|
526
|
-
actions: assign({
|
|
527
|
-
annotations: ({
|
|
528
|
-
event
|
|
529
|
-
}) => event.annotations,
|
|
530
|
-
elementRef: ({
|
|
531
|
-
event
|
|
532
|
-
}) => event.elementRef
|
|
533
|
-
})
|
|
534
|
-
},
|
|
535
|
-
edit: {
|
|
536
|
-
actions: ({
|
|
537
|
-
context,
|
|
538
|
-
event
|
|
539
|
-
}) => {
|
|
540
|
-
context.editor.send({
|
|
541
|
-
type: "annotation.set",
|
|
542
|
-
at: event.at,
|
|
543
|
-
props: event.props
|
|
544
|
-
}), context.editor.send({
|
|
545
|
-
type: "focus"
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
},
|
|
549
|
-
remove: {
|
|
550
|
-
actions: ({
|
|
551
|
-
context,
|
|
552
|
-
event
|
|
553
|
-
}) => {
|
|
554
|
-
context.editor.send({
|
|
555
|
-
type: "annotation.remove",
|
|
556
|
-
annotation: {
|
|
557
|
-
name: event.schemaType.name
|
|
558
|
-
}
|
|
559
|
-
}), context.editor.send({
|
|
560
|
-
type: "focus"
|
|
561
|
-
});
|
|
562
|
-
}
|
|
563
|
-
},
|
|
564
|
-
close: {
|
|
565
|
-
actions: ({
|
|
566
|
-
context
|
|
567
|
-
}) => {
|
|
568
|
-
context.editor.send({
|
|
569
|
-
type: "focus"
|
|
570
|
-
});
|
|
571
|
-
},
|
|
572
|
-
target: "inactive"
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
}
|
|
331
|
+
id: "annotation popover",
|
|
332
|
+
context: ({ input }) => ({
|
|
333
|
+
editor: input.editor,
|
|
334
|
+
schemaTypes: input.schemaTypes,
|
|
335
|
+
annotations: [],
|
|
336
|
+
elementRef: React.createRef()
|
|
337
|
+
}),
|
|
338
|
+
invoke: [{
|
|
339
|
+
src: "disable listener",
|
|
340
|
+
input: ({ context }) => ({ editor: context.editor })
|
|
341
|
+
}],
|
|
342
|
+
initial: "disabled",
|
|
343
|
+
states: {
|
|
344
|
+
disabled: {
|
|
345
|
+
initial: "inactive",
|
|
346
|
+
states: {
|
|
347
|
+
inactive: {
|
|
348
|
+
entry: ["reset"],
|
|
349
|
+
on: {
|
|
350
|
+
"set active": {
|
|
351
|
+
actions: assign({
|
|
352
|
+
annotations: ({ event }) => event.annotations,
|
|
353
|
+
elementRef: ({ event }) => event.elementRef
|
|
354
|
+
}),
|
|
355
|
+
target: "active"
|
|
356
|
+
},
|
|
357
|
+
enable: { target: "#annotation popover.enabled.inactive" }
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
active: { on: {
|
|
361
|
+
"set inactive": { target: "inactive" },
|
|
362
|
+
enable: { target: "#annotation popover.enabled.active" }
|
|
363
|
+
} }
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
enabled: {
|
|
367
|
+
invoke: [{
|
|
368
|
+
src: "active listener",
|
|
369
|
+
input: ({ context }) => ({
|
|
370
|
+
editor: context.editor,
|
|
371
|
+
schemaTypes: context.schemaTypes
|
|
372
|
+
})
|
|
373
|
+
}],
|
|
374
|
+
initial: "inactive",
|
|
375
|
+
states: {
|
|
376
|
+
inactive: {
|
|
377
|
+
entry: ["reset"],
|
|
378
|
+
on: {
|
|
379
|
+
"set active": {
|
|
380
|
+
target: "active",
|
|
381
|
+
actions: assign({
|
|
382
|
+
annotations: ({ event }) => event.annotations,
|
|
383
|
+
elementRef: ({ event }) => event.elementRef
|
|
384
|
+
})
|
|
385
|
+
},
|
|
386
|
+
disable: { target: "#annotation popover.disabled.inactive" }
|
|
387
|
+
}
|
|
388
|
+
},
|
|
389
|
+
active: { on: {
|
|
390
|
+
"set inactive": { target: "inactive" },
|
|
391
|
+
disable: { target: "#annotation popover.disabled.active" },
|
|
392
|
+
"set active": { actions: assign({
|
|
393
|
+
annotations: ({ event }) => event.annotations,
|
|
394
|
+
elementRef: ({ event }) => event.elementRef
|
|
395
|
+
}) },
|
|
396
|
+
edit: { actions: ({ context, event }) => {
|
|
397
|
+
context.editor.send({
|
|
398
|
+
type: "annotation.set",
|
|
399
|
+
at: event.at,
|
|
400
|
+
props: event.props
|
|
401
|
+
}), context.editor.send({ type: "focus" });
|
|
402
|
+
} },
|
|
403
|
+
remove: { actions: ({ context, event }) => {
|
|
404
|
+
context.editor.send({
|
|
405
|
+
type: "annotation.remove",
|
|
406
|
+
annotation: { name: event.schemaType.name }
|
|
407
|
+
}), context.editor.send({ type: "focus" });
|
|
408
|
+
} },
|
|
409
|
+
close: {
|
|
410
|
+
actions: ({ context }) => {
|
|
411
|
+
context.editor.send({ type: "focus" });
|
|
412
|
+
},
|
|
413
|
+
target: "inactive"
|
|
414
|
+
}
|
|
415
|
+
} }
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
579
419
|
});
|
|
420
|
+
/**
|
|
421
|
+
* @beta
|
|
422
|
+
* Manages the state and available events for an annotation popover.
|
|
423
|
+
*/
|
|
580
424
|
function useAnnotationPopover(props) {
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
return $[11] !== send || $[12] !== t3 ? (t4 = {
|
|
604
|
-
snapshot: t3,
|
|
605
|
-
send
|
|
606
|
-
}, $[11] = send, $[12] = t3, $[13] = t4) : t4 = $[13], t4;
|
|
425
|
+
let $ = c(14), editor = useEditor(), t0;
|
|
426
|
+
$[0] !== editor || $[1] !== props.schemaTypes ? (t0 = { input: {
|
|
427
|
+
editor,
|
|
428
|
+
schemaTypes: props.schemaTypes
|
|
429
|
+
} }, $[0] = editor, $[1] = props.schemaTypes, $[2] = t0) : t0 = $[2];
|
|
430
|
+
let [actorSnapshot, send] = useActor(annotationPopoverMachine, t0), t1;
|
|
431
|
+
$[3] !== actorSnapshot.context.annotations || $[4] !== actorSnapshot.context.elementRef ? (t1 = {
|
|
432
|
+
annotations: actorSnapshot.context.annotations,
|
|
433
|
+
elementRef: actorSnapshot.context.elementRef
|
|
434
|
+
}, $[3] = actorSnapshot.context.annotations, $[4] = actorSnapshot.context.elementRef, $[5] = t1) : t1 = $[5];
|
|
435
|
+
let t2;
|
|
436
|
+
$[6] === actorSnapshot ? t2 = $[7] : (t2 = (state) => actorSnapshot.matches(state), $[6] = actorSnapshot, $[7] = t2);
|
|
437
|
+
let t3;
|
|
438
|
+
$[8] !== t1 || $[9] !== t2 ? (t3 = {
|
|
439
|
+
context: t1,
|
|
440
|
+
matches: t2
|
|
441
|
+
}, $[8] = t1, $[9] = t2, $[10] = t3) : t3 = $[10];
|
|
442
|
+
let t4;
|
|
443
|
+
return $[11] !== send || $[12] !== t3 ? (t4 = {
|
|
444
|
+
snapshot: t3,
|
|
445
|
+
send
|
|
446
|
+
}, $[11] = send, $[12] = t3, $[13] = t4) : t4 = $[13], t4;
|
|
607
447
|
}
|
|
608
|
-
const keyboardShortcutListener$2 = fromCallback(({
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
guard: ({
|
|
618
|
-
event
|
|
619
|
-
}) => shortcut.guard(event.originEvent),
|
|
620
|
-
actions: [() => [effect(() => {
|
|
621
|
-
sendBack({
|
|
622
|
-
type: "open dialog"
|
|
623
|
-
});
|
|
624
|
-
})]]
|
|
625
|
-
})
|
|
626
|
-
});
|
|
448
|
+
const keyboardShortcutListener$2 = fromCallback(({ input, sendBack }) => {
|
|
449
|
+
let shortcut = input.schemaType.shortcut;
|
|
450
|
+
if (shortcut) return input.editor.registerBehavior({ behavior: defineBehavior({
|
|
451
|
+
on: "keyboard.keydown",
|
|
452
|
+
guard: ({ event }) => shortcut.guard(event.originEvent),
|
|
453
|
+
actions: [() => [effect(() => {
|
|
454
|
+
sendBack({ type: "open dialog" });
|
|
455
|
+
})]]
|
|
456
|
+
}) });
|
|
627
457
|
}), blockObjectButtonMachine = setup({
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
}));
|
|
648
|
-
}
|
|
649
|
-
},
|
|
650
|
-
actors: {
|
|
651
|
-
"disable listener": disableListener,
|
|
652
|
-
"keyboard shortcut listener": keyboardShortcutListener$2
|
|
653
|
-
}
|
|
458
|
+
types: {
|
|
459
|
+
context: {},
|
|
460
|
+
input: {},
|
|
461
|
+
events: {}
|
|
462
|
+
},
|
|
463
|
+
actions: { insert: ({ context, event }) => {
|
|
464
|
+
event.type === "insert" && (context.editor.send({
|
|
465
|
+
type: "insert.block object",
|
|
466
|
+
blockObject: {
|
|
467
|
+
name: context.schemaType.name,
|
|
468
|
+
value: event.value
|
|
469
|
+
},
|
|
470
|
+
placement: event.placement ?? "auto"
|
|
471
|
+
}), context.editor.send({ type: "focus" }));
|
|
472
|
+
} },
|
|
473
|
+
actors: {
|
|
474
|
+
"disable listener": disableListener,
|
|
475
|
+
"keyboard shortcut listener": keyboardShortcutListener$2
|
|
476
|
+
}
|
|
654
477
|
}).createMachine({
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
context
|
|
692
|
-
}) => ({
|
|
693
|
-
editor: context.editor,
|
|
694
|
-
schemaType: context.schemaType
|
|
695
|
-
})
|
|
696
|
-
}],
|
|
697
|
-
on: {
|
|
698
|
-
"open dialog": {
|
|
699
|
-
target: "showing dialog"
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
},
|
|
703
|
-
"showing dialog": {
|
|
704
|
-
on: {
|
|
705
|
-
"close dialog": {
|
|
706
|
-
target: "idle"
|
|
707
|
-
},
|
|
708
|
-
insert: {
|
|
709
|
-
actions: ["insert"],
|
|
710
|
-
target: "idle"
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
}
|
|
478
|
+
id: "block object button",
|
|
479
|
+
context: ({ input }) => ({
|
|
480
|
+
editor: input.editor,
|
|
481
|
+
schemaType: input.schemaType
|
|
482
|
+
}),
|
|
483
|
+
invoke: [{
|
|
484
|
+
src: "disable listener",
|
|
485
|
+
input: ({ context }) => ({ editor: context.editor })
|
|
486
|
+
}],
|
|
487
|
+
initial: "disabled",
|
|
488
|
+
states: {
|
|
489
|
+
disabled: { on: { enable: { target: "enabled" } } },
|
|
490
|
+
enabled: {
|
|
491
|
+
on: { disable: { target: "disabled" } },
|
|
492
|
+
initial: "idle",
|
|
493
|
+
states: {
|
|
494
|
+
idle: {
|
|
495
|
+
invoke: [{
|
|
496
|
+
src: "keyboard shortcut listener",
|
|
497
|
+
input: ({ context }) => ({
|
|
498
|
+
editor: context.editor,
|
|
499
|
+
schemaType: context.schemaType
|
|
500
|
+
})
|
|
501
|
+
}],
|
|
502
|
+
on: { "open dialog": { target: "showing dialog" } }
|
|
503
|
+
},
|
|
504
|
+
"showing dialog": { on: {
|
|
505
|
+
"close dialog": { target: "idle" },
|
|
506
|
+
insert: {
|
|
507
|
+
actions: ["insert"],
|
|
508
|
+
target: "idle"
|
|
509
|
+
}
|
|
510
|
+
} }
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
717
514
|
});
|
|
515
|
+
/**
|
|
516
|
+
* @beta
|
|
517
|
+
* Manages the state, keyboard shortcut and available events for a block
|
|
518
|
+
* object button.
|
|
519
|
+
*
|
|
520
|
+
* Note: This hook assumes that the button triggers a dialog for inputting
|
|
521
|
+
* the block object value.
|
|
522
|
+
*/
|
|
718
523
|
function useBlockObjectButton(props) {
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
}, $[3] = actorSnapshot, $[4] = t1) : t1 = $[4];
|
|
732
|
-
let t2;
|
|
733
|
-
return $[5] !== send || $[6] !== t1 ? (t2 = {
|
|
734
|
-
snapshot: t1,
|
|
735
|
-
send
|
|
736
|
-
}, $[5] = send, $[6] = t1, $[7] = t2) : t2 = $[7], t2;
|
|
524
|
+
let $ = c(8), editor = useEditor(), t0;
|
|
525
|
+
$[0] !== editor || $[1] !== props.schemaType ? (t0 = { input: {
|
|
526
|
+
editor,
|
|
527
|
+
schemaType: props.schemaType
|
|
528
|
+
} }, $[0] = editor, $[1] = props.schemaType, $[2] = t0) : t0 = $[2];
|
|
529
|
+
let [actorSnapshot, send] = useActor(blockObjectButtonMachine, t0), t1;
|
|
530
|
+
$[3] === actorSnapshot ? t1 = $[4] : (t1 = { matches: (state) => actorSnapshot.matches(state) }, $[3] = actorSnapshot, $[4] = t1);
|
|
531
|
+
let t2;
|
|
532
|
+
return $[5] !== send || $[6] !== t1 ? (t2 = {
|
|
533
|
+
snapshot: t1,
|
|
534
|
+
send
|
|
535
|
+
}, $[5] = send, $[6] = t1, $[7] = t2) : t2 = $[7], t2;
|
|
737
536
|
}
|
|
738
|
-
const activeListener$4 = fromCallback(({
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
}
|
|
783
|
-
types: {
|
|
784
|
-
context: {},
|
|
785
|
-
input: {},
|
|
786
|
-
events: {}
|
|
787
|
-
},
|
|
788
|
-
actions: {
|
|
789
|
-
reset: assign({
|
|
790
|
-
blockObjects: [],
|
|
791
|
-
elementRef: React.createRef()
|
|
792
|
-
})
|
|
793
|
-
},
|
|
794
|
-
actors: {
|
|
795
|
-
"disable listener": disableListener,
|
|
796
|
-
"active listener": activeListener$4
|
|
797
|
-
}
|
|
537
|
+
const activeListener$4 = fromCallback(({ input, sendBack }) => input.editor.on("selection", () => {
|
|
538
|
+
let snapshot = input.editor.getSnapshot();
|
|
539
|
+
if (!selectors.isSelectionCollapsed(snapshot)) {
|
|
540
|
+
sendBack({ type: "set inactive" });
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
let focusBlockObject = selectors.getFocusBlockObject(snapshot);
|
|
544
|
+
if (!focusBlockObject) {
|
|
545
|
+
sendBack({ type: "set inactive" });
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
let schemaType = input.schemaTypes.find((schemaType) => schemaType.name === focusBlockObject.node._type);
|
|
549
|
+
if (!schemaType) {
|
|
550
|
+
sendBack({ type: "set inactive" });
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
let firstSelectedNode = input.editor.dom.getBlockNodes(snapshot).at(0);
|
|
554
|
+
if (!firstSelectedNode || !(firstSelectedNode instanceof Element)) {
|
|
555
|
+
sendBack({ type: "set inactive" });
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
let elementRef = React.createRef();
|
|
559
|
+
elementRef.current = firstSelectedNode, sendBack({
|
|
560
|
+
type: "set active",
|
|
561
|
+
blockObjects: [{
|
|
562
|
+
value: focusBlockObject.node,
|
|
563
|
+
schemaType,
|
|
564
|
+
at: focusBlockObject.path
|
|
565
|
+
}],
|
|
566
|
+
elementRef
|
|
567
|
+
});
|
|
568
|
+
}, { batch: !0 }).unsubscribe), blockObjectPopoverMachine = setup({
|
|
569
|
+
types: {
|
|
570
|
+
context: {},
|
|
571
|
+
input: {},
|
|
572
|
+
events: {}
|
|
573
|
+
},
|
|
574
|
+
actions: { reset: assign({
|
|
575
|
+
blockObjects: [],
|
|
576
|
+
elementRef: React.createRef()
|
|
577
|
+
}) },
|
|
578
|
+
actors: {
|
|
579
|
+
"disable listener": disableListener,
|
|
580
|
+
"active listener": activeListener$4
|
|
581
|
+
}
|
|
798
582
|
}).createMachine({
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
},
|
|
887
|
-
disable: {
|
|
888
|
-
target: "#block object popover.disabled.active"
|
|
889
|
-
},
|
|
890
|
-
"set active": {
|
|
891
|
-
actions: assign({
|
|
892
|
-
blockObjects: ({
|
|
893
|
-
event
|
|
894
|
-
}) => event.blockObjects,
|
|
895
|
-
elementRef: ({
|
|
896
|
-
event
|
|
897
|
-
}) => event.elementRef
|
|
898
|
-
})
|
|
899
|
-
},
|
|
900
|
-
edit: {
|
|
901
|
-
actions: ({
|
|
902
|
-
context,
|
|
903
|
-
event
|
|
904
|
-
}) => {
|
|
905
|
-
context.editor.send({
|
|
906
|
-
type: "block.set",
|
|
907
|
-
at: event.at,
|
|
908
|
-
props: event.props
|
|
909
|
-
}), context.editor.send({
|
|
910
|
-
type: "focus"
|
|
911
|
-
});
|
|
912
|
-
}
|
|
913
|
-
},
|
|
914
|
-
remove: {
|
|
915
|
-
actions: ({
|
|
916
|
-
context,
|
|
917
|
-
event
|
|
918
|
-
}) => {
|
|
919
|
-
context.editor.send({
|
|
920
|
-
type: "delete.block",
|
|
921
|
-
at: event.at
|
|
922
|
-
}), context.editor.send({
|
|
923
|
-
type: "focus"
|
|
924
|
-
});
|
|
925
|
-
}
|
|
926
|
-
},
|
|
927
|
-
close: {
|
|
928
|
-
actions: ({
|
|
929
|
-
context
|
|
930
|
-
}) => {
|
|
931
|
-
context.editor.send({
|
|
932
|
-
type: "focus"
|
|
933
|
-
});
|
|
934
|
-
},
|
|
935
|
-
target: "inactive"
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
}
|
|
583
|
+
id: "block object popover",
|
|
584
|
+
context: ({ input }) => ({
|
|
585
|
+
editor: input.editor,
|
|
586
|
+
schemaTypes: input.schemaTypes,
|
|
587
|
+
blockObjects: [],
|
|
588
|
+
elementRef: React.createRef()
|
|
589
|
+
}),
|
|
590
|
+
invoke: [{
|
|
591
|
+
src: "disable listener",
|
|
592
|
+
input: ({ context }) => ({ editor: context.editor })
|
|
593
|
+
}, {
|
|
594
|
+
src: "active listener",
|
|
595
|
+
input: ({ context }) => ({
|
|
596
|
+
editor: context.editor,
|
|
597
|
+
schemaTypes: context.schemaTypes
|
|
598
|
+
})
|
|
599
|
+
}],
|
|
600
|
+
initial: "disabled",
|
|
601
|
+
states: {
|
|
602
|
+
disabled: {
|
|
603
|
+
initial: "inactive",
|
|
604
|
+
states: {
|
|
605
|
+
inactive: {
|
|
606
|
+
entry: ["reset"],
|
|
607
|
+
on: {
|
|
608
|
+
"set active": {
|
|
609
|
+
actions: assign({
|
|
610
|
+
blockObjects: ({ event }) => event.blockObjects,
|
|
611
|
+
elementRef: ({ event }) => event.elementRef
|
|
612
|
+
}),
|
|
613
|
+
target: "active"
|
|
614
|
+
},
|
|
615
|
+
enable: { target: "#block object popover.enabled.inactive" }
|
|
616
|
+
}
|
|
617
|
+
},
|
|
618
|
+
active: { on: {
|
|
619
|
+
"set inactive": { target: "inactive" },
|
|
620
|
+
enable: { target: "#block object popover.enabled.active" }
|
|
621
|
+
} }
|
|
622
|
+
}
|
|
623
|
+
},
|
|
624
|
+
enabled: {
|
|
625
|
+
initial: "inactive",
|
|
626
|
+
states: {
|
|
627
|
+
inactive: {
|
|
628
|
+
entry: ["reset"],
|
|
629
|
+
on: {
|
|
630
|
+
"set active": {
|
|
631
|
+
target: "active",
|
|
632
|
+
actions: assign({
|
|
633
|
+
blockObjects: ({ event }) => event.blockObjects,
|
|
634
|
+
elementRef: ({ event }) => event.elementRef
|
|
635
|
+
})
|
|
636
|
+
},
|
|
637
|
+
disable: { target: "#block object popover.disabled.inactive" }
|
|
638
|
+
}
|
|
639
|
+
},
|
|
640
|
+
active: { on: {
|
|
641
|
+
"set inactive": { target: "inactive" },
|
|
642
|
+
disable: { target: "#block object popover.disabled.active" },
|
|
643
|
+
"set active": { actions: assign({
|
|
644
|
+
blockObjects: ({ event }) => event.blockObjects,
|
|
645
|
+
elementRef: ({ event }) => event.elementRef
|
|
646
|
+
}) },
|
|
647
|
+
edit: { actions: ({ context, event }) => {
|
|
648
|
+
context.editor.send({
|
|
649
|
+
type: "block.set",
|
|
650
|
+
at: event.at,
|
|
651
|
+
props: event.props
|
|
652
|
+
}), context.editor.send({ type: "focus" });
|
|
653
|
+
} },
|
|
654
|
+
remove: { actions: ({ context, event }) => {
|
|
655
|
+
context.editor.send({
|
|
656
|
+
type: "delete.block",
|
|
657
|
+
at: event.at
|
|
658
|
+
}), context.editor.send({ type: "focus" });
|
|
659
|
+
} },
|
|
660
|
+
close: {
|
|
661
|
+
actions: ({ context }) => {
|
|
662
|
+
context.editor.send({ type: "focus" });
|
|
663
|
+
},
|
|
664
|
+
target: "inactive"
|
|
665
|
+
}
|
|
666
|
+
} }
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
}
|
|
942
670
|
});
|
|
671
|
+
/**
|
|
672
|
+
* @beta
|
|
673
|
+
* Manages the state and available events for a block object popover.
|
|
674
|
+
*/
|
|
943
675
|
function useBlockObjectPopover(props) {
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
return $[11] !== send || $[12] !== t3 ? (t4 = {
|
|
967
|
-
snapshot: t3,
|
|
968
|
-
send
|
|
969
|
-
}, $[11] = send, $[12] = t3, $[13] = t4) : t4 = $[13], t4;
|
|
676
|
+
let $ = c(14), editor = useEditor(), t0;
|
|
677
|
+
$[0] !== editor || $[1] !== props.schemaTypes ? (t0 = { input: {
|
|
678
|
+
editor,
|
|
679
|
+
schemaTypes: props.schemaTypes
|
|
680
|
+
} }, $[0] = editor, $[1] = props.schemaTypes, $[2] = t0) : t0 = $[2];
|
|
681
|
+
let [actorSnapshot, send] = useActor(blockObjectPopoverMachine, t0), t1;
|
|
682
|
+
$[3] !== actorSnapshot.context.blockObjects || $[4] !== actorSnapshot.context.elementRef ? (t1 = {
|
|
683
|
+
blockObjects: actorSnapshot.context.blockObjects,
|
|
684
|
+
elementRef: actorSnapshot.context.elementRef
|
|
685
|
+
}, $[3] = actorSnapshot.context.blockObjects, $[4] = actorSnapshot.context.elementRef, $[5] = t1) : t1 = $[5];
|
|
686
|
+
let t2;
|
|
687
|
+
$[6] === actorSnapshot ? t2 = $[7] : (t2 = (state) => actorSnapshot.matches(state), $[6] = actorSnapshot, $[7] = t2);
|
|
688
|
+
let t3;
|
|
689
|
+
$[8] !== t1 || $[9] !== t2 ? (t3 = {
|
|
690
|
+
context: t1,
|
|
691
|
+
matches: t2
|
|
692
|
+
}, $[8] = t1, $[9] = t2, $[10] = t3) : t3 = $[10];
|
|
693
|
+
let t4;
|
|
694
|
+
return $[11] !== send || $[12] !== t3 ? (t4 = {
|
|
695
|
+
snapshot: t3,
|
|
696
|
+
send
|
|
697
|
+
}, $[11] = send, $[12] = t3, $[13] = t4) : t4 = $[13], t4;
|
|
970
698
|
}
|
|
971
|
-
const keyboardShortcutListener$1 = fromCallback(({
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
}) => shortcut.guard(event.originEvent),
|
|
982
|
-
actions: [() => [raise({
|
|
983
|
-
type: "decorator.toggle",
|
|
984
|
-
decorator: input.schemaType.name
|
|
985
|
-
})]]
|
|
986
|
-
})
|
|
987
|
-
});
|
|
699
|
+
const keyboardShortcutListener$1 = fromCallback(({ input }) => {
|
|
700
|
+
let shortcut = input.schemaType.shortcut;
|
|
701
|
+
if (shortcut) return input.editor.registerBehavior({ behavior: defineBehavior({
|
|
702
|
+
on: "keyboard.keydown",
|
|
703
|
+
guard: ({ event }) => shortcut.guard(event.originEvent),
|
|
704
|
+
actions: [() => [raise({
|
|
705
|
+
type: "decorator.toggle",
|
|
706
|
+
decorator: input.schemaType.name
|
|
707
|
+
})]]
|
|
708
|
+
}) });
|
|
988
709
|
}), decoratorKeyboardShortcutMachine = setup({
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
710
|
+
types: {
|
|
711
|
+
context: {},
|
|
712
|
+
input: {},
|
|
713
|
+
events: {}
|
|
714
|
+
},
|
|
715
|
+
actors: {
|
|
716
|
+
"disable listener": disableListener,
|
|
717
|
+
"keyboard shortcut listener": keyboardShortcutListener$1
|
|
718
|
+
}
|
|
998
719
|
}).createMachine({
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
},
|
|
1023
|
-
enabled: {
|
|
1024
|
-
invoke: {
|
|
1025
|
-
src: "keyboard shortcut listener",
|
|
1026
|
-
input: ({
|
|
1027
|
-
context
|
|
1028
|
-
}) => ({
|
|
1029
|
-
editor: context.editor,
|
|
1030
|
-
schemaType: context.schemaType
|
|
1031
|
-
})
|
|
1032
|
-
},
|
|
1033
|
-
on: {
|
|
1034
|
-
disable: {
|
|
1035
|
-
target: "disabled"
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
720
|
+
id: "decorator keyboard shortcut",
|
|
721
|
+
context: ({ input }) => ({
|
|
722
|
+
editor: input.editor,
|
|
723
|
+
schemaType: input.schemaType
|
|
724
|
+
}),
|
|
725
|
+
invoke: {
|
|
726
|
+
src: "disable listener",
|
|
727
|
+
input: ({ context }) => ({ editor: context.editor })
|
|
728
|
+
},
|
|
729
|
+
initial: "disabled",
|
|
730
|
+
states: {
|
|
731
|
+
disabled: { on: { enable: { target: "enabled" } } },
|
|
732
|
+
enabled: {
|
|
733
|
+
invoke: {
|
|
734
|
+
src: "keyboard shortcut listener",
|
|
735
|
+
input: ({ context }) => ({
|
|
736
|
+
editor: context.editor,
|
|
737
|
+
schemaType: context.schemaType
|
|
738
|
+
})
|
|
739
|
+
},
|
|
740
|
+
on: { disable: { target: "disabled" } }
|
|
741
|
+
}
|
|
742
|
+
}
|
|
1040
743
|
});
|
|
1041
744
|
function useDecoratorKeyboardShortcut(props) {
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
schemaType: props.schemaType
|
|
1048
|
-
}
|
|
1049
|
-
}, $[0] = editor, $[1] = props.schemaType, $[2] = t0) : t0 = $[2], useActorRef(decoratorKeyboardShortcutMachine, t0);
|
|
745
|
+
let $ = c(3), editor = useEditor(), t0;
|
|
746
|
+
$[0] !== editor || $[1] !== props.schemaType ? (t0 = { input: {
|
|
747
|
+
editor,
|
|
748
|
+
schemaType: props.schemaType
|
|
749
|
+
} }, $[0] = editor, $[1] = props.schemaType, $[2] = t0) : t0 = $[2], useActorRef(decoratorKeyboardShortcutMachine, t0);
|
|
1050
750
|
}
|
|
1051
751
|
function useMutuallyExclusiveDecorator(props) {
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
}]
|
|
1072
|
-
})
|
|
1073
|
-
});
|
|
1074
|
-
}, t1 = [editor, props.schemaType.name, props.schemaType.mutuallyExclusive], $[0] = editor, $[1] = props.schemaType.mutuallyExclusive, $[2] = props.schemaType.name, $[3] = t0, $[4] = t1) : (t0 = $[3], t1 = $[4]), useEffect(t0, t1);
|
|
752
|
+
let $ = c(5), editor = useEditor(), t0, t1;
|
|
753
|
+
$[0] !== editor || $[1] !== props.schemaType.mutuallyExclusive || $[2] !== props.schemaType.name ? (t0 = () => {
|
|
754
|
+
let mutuallyExclusive = props.schemaType.mutuallyExclusive;
|
|
755
|
+
if (mutuallyExclusive) return editor.registerBehavior({ behavior: defineBehavior({
|
|
756
|
+
on: "decorator.add",
|
|
757
|
+
guard: (t2) => {
|
|
758
|
+
let { event } = t2;
|
|
759
|
+
return event.decorator === props.schemaType.name;
|
|
760
|
+
},
|
|
761
|
+
actions: [(t3) => {
|
|
762
|
+
let { event: event_0 } = t3;
|
|
763
|
+
return [forward(event_0), ...mutuallyExclusive.map(_temp)];
|
|
764
|
+
}]
|
|
765
|
+
}) });
|
|
766
|
+
}, t1 = [
|
|
767
|
+
editor,
|
|
768
|
+
props.schemaType.name,
|
|
769
|
+
props.schemaType.mutuallyExclusive
|
|
770
|
+
], $[0] = editor, $[1] = props.schemaType.mutuallyExclusive, $[2] = props.schemaType.name, $[3] = t0, $[4] = t1) : (t0 = $[3], t1 = $[4]), useEffect(t0, t1);
|
|
1075
771
|
}
|
|
1076
772
|
function _temp(decorator) {
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
773
|
+
return raise({
|
|
774
|
+
type: "decorator.remove",
|
|
775
|
+
decorator
|
|
776
|
+
});
|
|
1081
777
|
}
|
|
1082
|
-
const activeListener$3 = fromCallback(({
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
},
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
input: {},
|
|
1102
|
-
events: {}
|
|
1103
|
-
},
|
|
1104
|
-
actions: {
|
|
1105
|
-
toggle: ({
|
|
1106
|
-
context,
|
|
1107
|
-
event
|
|
1108
|
-
}) => {
|
|
1109
|
-
event.type === "toggle" && (context.editor.send({
|
|
1110
|
-
type: "decorator.toggle",
|
|
1111
|
-
decorator: context.schemaType.name
|
|
1112
|
-
}), context.editor.send({
|
|
1113
|
-
type: "focus"
|
|
1114
|
-
}));
|
|
1115
|
-
}
|
|
1116
|
-
},
|
|
1117
|
-
actors: {
|
|
1118
|
-
"disable listener": disableListener,
|
|
1119
|
-
"active listener": activeListener$3
|
|
1120
|
-
}
|
|
778
|
+
const activeListener$3 = fromCallback(({ input, sendBack }) => (selectors.isActiveDecorator(input.schemaType.name)(input.editor.getSnapshot()) ? sendBack({ type: "set active" }) : sendBack({ type: "set inactive" }), input.editor.on("*", () => {
|
|
779
|
+
let snapshot = input.editor.getSnapshot();
|
|
780
|
+
selectors.isActiveDecorator(input.schemaType.name)(snapshot) ? sendBack({ type: "set active" }) : sendBack({ type: "set inactive" });
|
|
781
|
+
}, { batch: !0 }).unsubscribe)), decoratorButtonMachine = setup({
|
|
782
|
+
types: {
|
|
783
|
+
context: {},
|
|
784
|
+
input: {},
|
|
785
|
+
events: {}
|
|
786
|
+
},
|
|
787
|
+
actions: { toggle: ({ context, event }) => {
|
|
788
|
+
event.type === "toggle" && (context.editor.send({
|
|
789
|
+
type: "decorator.toggle",
|
|
790
|
+
decorator: context.schemaType.name
|
|
791
|
+
}), context.editor.send({ type: "focus" }));
|
|
792
|
+
} },
|
|
793
|
+
actors: {
|
|
794
|
+
"disable listener": disableListener,
|
|
795
|
+
"active listener": activeListener$3
|
|
796
|
+
}
|
|
1121
797
|
}).createMachine({
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
},
|
|
1172
|
-
enabled: {
|
|
1173
|
-
on: {
|
|
1174
|
-
toggle: {
|
|
1175
|
-
actions: ["toggle"]
|
|
1176
|
-
}
|
|
1177
|
-
},
|
|
1178
|
-
initial: "inactive",
|
|
1179
|
-
states: {
|
|
1180
|
-
inactive: {
|
|
1181
|
-
on: {
|
|
1182
|
-
disable: {
|
|
1183
|
-
target: "#decorator button.disabled.inactive"
|
|
1184
|
-
},
|
|
1185
|
-
"set active": {
|
|
1186
|
-
target: "active"
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
},
|
|
1190
|
-
active: {
|
|
1191
|
-
on: {
|
|
1192
|
-
disable: {
|
|
1193
|
-
target: "#decorator button.disabled.active"
|
|
1194
|
-
},
|
|
1195
|
-
"set inactive": {
|
|
1196
|
-
target: "inactive"
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
798
|
+
id: "decorator button",
|
|
799
|
+
context: ({ input }) => ({
|
|
800
|
+
editor: input.editor,
|
|
801
|
+
schemaType: input.schemaType
|
|
802
|
+
}),
|
|
803
|
+
invoke: [{
|
|
804
|
+
src: "disable listener",
|
|
805
|
+
input: ({ context }) => ({ editor: context.editor })
|
|
806
|
+
}, {
|
|
807
|
+
src: "active listener",
|
|
808
|
+
input: ({ context }) => ({
|
|
809
|
+
editor: context.editor,
|
|
810
|
+
schemaType: context.schemaType
|
|
811
|
+
})
|
|
812
|
+
}],
|
|
813
|
+
initial: "disabled",
|
|
814
|
+
states: {
|
|
815
|
+
disabled: {
|
|
816
|
+
initial: "inactive",
|
|
817
|
+
states: {
|
|
818
|
+
inactive: { on: {
|
|
819
|
+
enable: { target: "#decorator button.enabled.inactive" },
|
|
820
|
+
"set active": { target: "active" }
|
|
821
|
+
} },
|
|
822
|
+
active: { on: {
|
|
823
|
+
enable: { target: "#decorator button.enabled.active" },
|
|
824
|
+
"set inactive": { target: "inactive" }
|
|
825
|
+
} }
|
|
826
|
+
}
|
|
827
|
+
},
|
|
828
|
+
enabled: {
|
|
829
|
+
on: { toggle: { actions: ["toggle"] } },
|
|
830
|
+
initial: "inactive",
|
|
831
|
+
states: {
|
|
832
|
+
inactive: { on: {
|
|
833
|
+
disable: { target: "#decorator button.disabled.inactive" },
|
|
834
|
+
"set active": { target: "active" }
|
|
835
|
+
} },
|
|
836
|
+
active: { on: {
|
|
837
|
+
disable: { target: "#decorator button.disabled.active" },
|
|
838
|
+
"set inactive": { target: "inactive" }
|
|
839
|
+
} }
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
}
|
|
1203
843
|
});
|
|
844
|
+
/**
|
|
845
|
+
* @beta
|
|
846
|
+
* Manages the state, keyboard shortcuts and available events for a decorator
|
|
847
|
+
* button and sets up mutually exclusive decorator behaviors.
|
|
848
|
+
*/
|
|
1204
849
|
function useDecoratorButton(props) {
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
let t2;
|
|
1220
|
-
return $[5] !== send || $[6] !== t1 ? (t2 = {
|
|
1221
|
-
snapshot: t1,
|
|
1222
|
-
send
|
|
1223
|
-
}, $[5] = send, $[6] = t1, $[7] = t2) : t2 = $[7], t2;
|
|
850
|
+
let $ = c(8), editor = useEditor(), t0;
|
|
851
|
+
$[0] !== editor || $[1] !== props.schemaType ? (t0 = { input: {
|
|
852
|
+
editor,
|
|
853
|
+
schemaType: props.schemaType
|
|
854
|
+
} }, $[0] = editor, $[1] = props.schemaType, $[2] = t0) : t0 = $[2];
|
|
855
|
+
let [actorSnapshot, send] = useActor(decoratorButtonMachine, t0);
|
|
856
|
+
useDecoratorKeyboardShortcut(props), useMutuallyExclusiveDecorator(props);
|
|
857
|
+
let t1;
|
|
858
|
+
$[3] === actorSnapshot ? t1 = $[4] : (t1 = { matches: (state) => actorSnapshot.matches(state) }, $[3] = actorSnapshot, $[4] = t1);
|
|
859
|
+
let t2;
|
|
860
|
+
return $[5] !== send || $[6] !== t1 ? (t2 = {
|
|
861
|
+
snapshot: t1,
|
|
862
|
+
send
|
|
863
|
+
}, $[5] = send, $[6] = t1, $[7] = t2) : t2 = $[7], t2;
|
|
1224
864
|
}
|
|
1225
865
|
const historyButtonsMachine = setup({
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
"disable listener": disableListener
|
|
1233
|
-
}
|
|
866
|
+
types: {
|
|
867
|
+
context: {},
|
|
868
|
+
input: {},
|
|
869
|
+
events: {}
|
|
870
|
+
},
|
|
871
|
+
actors: { "disable listener": disableListener }
|
|
1234
872
|
}).createMachine({
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
target: "enabled"
|
|
1255
|
-
}
|
|
1256
|
-
}
|
|
1257
|
-
},
|
|
1258
|
-
enabled: {
|
|
1259
|
-
on: {
|
|
1260
|
-
disable: {
|
|
1261
|
-
target: "disabled"
|
|
1262
|
-
},
|
|
1263
|
-
"history.undo": {
|
|
1264
|
-
actions: ({
|
|
1265
|
-
context
|
|
1266
|
-
}) => {
|
|
1267
|
-
context.editor.send({
|
|
1268
|
-
type: "history.undo"
|
|
1269
|
-
}), context.editor.send({
|
|
1270
|
-
type: "focus"
|
|
1271
|
-
});
|
|
1272
|
-
}
|
|
1273
|
-
},
|
|
1274
|
-
"history.redo": {
|
|
1275
|
-
actions: ({
|
|
1276
|
-
context
|
|
1277
|
-
}) => {
|
|
1278
|
-
context.editor.send({
|
|
1279
|
-
type: "history.redo"
|
|
1280
|
-
}), context.editor.send({
|
|
1281
|
-
type: "focus"
|
|
1282
|
-
});
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
873
|
+
id: "history buttons",
|
|
874
|
+
context: ({ input }) => ({ editor: input.editor }),
|
|
875
|
+
invoke: {
|
|
876
|
+
src: "disable listener",
|
|
877
|
+
input: ({ context }) => ({ editor: context.editor })
|
|
878
|
+
},
|
|
879
|
+
initial: "disabled",
|
|
880
|
+
states: {
|
|
881
|
+
disabled: { on: { enable: { target: "enabled" } } },
|
|
882
|
+
enabled: { on: {
|
|
883
|
+
disable: { target: "disabled" },
|
|
884
|
+
"history.undo": { actions: ({ context }) => {
|
|
885
|
+
context.editor.send({ type: "history.undo" }), context.editor.send({ type: "focus" });
|
|
886
|
+
} },
|
|
887
|
+
"history.redo": { actions: ({ context }) => {
|
|
888
|
+
context.editor.send({ type: "history.redo" }), context.editor.send({ type: "focus" });
|
|
889
|
+
} }
|
|
890
|
+
} }
|
|
891
|
+
}
|
|
1288
892
|
});
|
|
893
|
+
/**
|
|
894
|
+
* @beta
|
|
895
|
+
*/
|
|
1289
896
|
function useHistoryButtons() {
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
$[2] !== actorSnapshot ? (t1 = {
|
|
1300
|
-
matches: (state) => actorSnapshot.matches(state)
|
|
1301
|
-
}, $[2] = actorSnapshot, $[3] = t1) : t1 = $[3];
|
|
1302
|
-
let t2;
|
|
1303
|
-
return $[4] !== send || $[5] !== t1 ? (t2 = {
|
|
1304
|
-
snapshot: t1,
|
|
1305
|
-
send
|
|
1306
|
-
}, $[4] = send, $[5] = t1, $[6] = t2) : t2 = $[6], t2;
|
|
897
|
+
let $ = c(7), editor = useEditor(), t0;
|
|
898
|
+
$[0] === editor ? t0 = $[1] : (t0 = { input: { editor } }, $[0] = editor, $[1] = t0);
|
|
899
|
+
let [actorSnapshot, send] = useActor(historyButtonsMachine, t0), t1;
|
|
900
|
+
$[2] === actorSnapshot ? t1 = $[3] : (t1 = { matches: (state) => actorSnapshot.matches(state) }, $[2] = actorSnapshot, $[3] = t1);
|
|
901
|
+
let t2;
|
|
902
|
+
return $[4] !== send || $[5] !== t1 ? (t2 = {
|
|
903
|
+
snapshot: t1,
|
|
904
|
+
send
|
|
905
|
+
}, $[4] = send, $[5] = t1, $[6] = t2) : t2 = $[6], t2;
|
|
1307
906
|
}
|
|
1308
|
-
const keyboardShortcutListener = fromCallback(({
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
guard: ({
|
|
1318
|
-
event
|
|
1319
|
-
}) => shortcut.guard(event.originEvent),
|
|
1320
|
-
actions: [() => [effect(() => {
|
|
1321
|
-
sendBack({
|
|
1322
|
-
type: "open dialog"
|
|
1323
|
-
});
|
|
1324
|
-
})]]
|
|
1325
|
-
})
|
|
1326
|
-
});
|
|
907
|
+
const keyboardShortcutListener = fromCallback(({ input, sendBack }) => {
|
|
908
|
+
let shortcut = input.schemaType.shortcut;
|
|
909
|
+
if (shortcut) return input.editor.registerBehavior({ behavior: defineBehavior({
|
|
910
|
+
on: "keyboard.keydown",
|
|
911
|
+
guard: ({ event }) => shortcut.guard(event.originEvent),
|
|
912
|
+
actions: [() => [effect(() => {
|
|
913
|
+
sendBack({ type: "open dialog" });
|
|
914
|
+
})]]
|
|
915
|
+
}) });
|
|
1327
916
|
}), inlineObjectButtonMachine = setup({
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
}));
|
|
1347
|
-
}
|
|
1348
|
-
},
|
|
1349
|
-
actors: {
|
|
1350
|
-
"disable listener": disableListener,
|
|
1351
|
-
"keyboard shortcut listener": keyboardShortcutListener
|
|
1352
|
-
}
|
|
917
|
+
types: {
|
|
918
|
+
context: {},
|
|
919
|
+
input: {},
|
|
920
|
+
events: {}
|
|
921
|
+
},
|
|
922
|
+
actions: { insert: ({ context, event }) => {
|
|
923
|
+
event.type === "insert" && (context.editor.send({
|
|
924
|
+
type: "insert.inline object",
|
|
925
|
+
inlineObject: {
|
|
926
|
+
name: context.schemaType.name,
|
|
927
|
+
value: event.value
|
|
928
|
+
}
|
|
929
|
+
}), context.editor.send({ type: "focus" }));
|
|
930
|
+
} },
|
|
931
|
+
actors: {
|
|
932
|
+
"disable listener": disableListener,
|
|
933
|
+
"keyboard shortcut listener": keyboardShortcutListener
|
|
934
|
+
}
|
|
1353
935
|
}).createMachine({
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
context
|
|
1391
|
-
}) => ({
|
|
1392
|
-
editor: context.editor,
|
|
1393
|
-
schemaType: context.schemaType
|
|
1394
|
-
})
|
|
1395
|
-
}],
|
|
1396
|
-
on: {
|
|
1397
|
-
"open dialog": {
|
|
1398
|
-
target: "showing dialog"
|
|
1399
|
-
}
|
|
1400
|
-
}
|
|
1401
|
-
},
|
|
1402
|
-
"showing dialog": {
|
|
1403
|
-
on: {
|
|
1404
|
-
"close dialog": {
|
|
1405
|
-
target: "idle"
|
|
1406
|
-
},
|
|
1407
|
-
insert: {
|
|
1408
|
-
actions: ["insert"],
|
|
1409
|
-
target: "idle"
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
}
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
936
|
+
id: "inline object button",
|
|
937
|
+
context: ({ input }) => ({
|
|
938
|
+
editor: input.editor,
|
|
939
|
+
schemaType: input.schemaType
|
|
940
|
+
}),
|
|
941
|
+
invoke: [{
|
|
942
|
+
src: "disable listener",
|
|
943
|
+
input: ({ context }) => ({ editor: context.editor })
|
|
944
|
+
}],
|
|
945
|
+
initial: "disabled",
|
|
946
|
+
states: {
|
|
947
|
+
disabled: { on: { enable: { target: "enabled" } } },
|
|
948
|
+
enabled: {
|
|
949
|
+
on: { disable: { target: "disabled" } },
|
|
950
|
+
initial: "idle",
|
|
951
|
+
states: {
|
|
952
|
+
idle: {
|
|
953
|
+
invoke: [{
|
|
954
|
+
src: "keyboard shortcut listener",
|
|
955
|
+
input: ({ context }) => ({
|
|
956
|
+
editor: context.editor,
|
|
957
|
+
schemaType: context.schemaType
|
|
958
|
+
})
|
|
959
|
+
}],
|
|
960
|
+
on: { "open dialog": { target: "showing dialog" } }
|
|
961
|
+
},
|
|
962
|
+
"showing dialog": { on: {
|
|
963
|
+
"close dialog": { target: "idle" },
|
|
964
|
+
insert: {
|
|
965
|
+
actions: ["insert"],
|
|
966
|
+
target: "idle"
|
|
967
|
+
}
|
|
968
|
+
} }
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
}
|
|
1416
972
|
});
|
|
973
|
+
/**
|
|
974
|
+
* @beta
|
|
975
|
+
* Manages the state, keyboard shortcut and available events for an inline
|
|
976
|
+
* object button.
|
|
977
|
+
*
|
|
978
|
+
* Note: This hook assumes that the button triggers a dialog for inputting
|
|
979
|
+
* the inline object value.
|
|
980
|
+
*/
|
|
1417
981
|
function useInlineObjectButton(props) {
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
}, $[3] = actorSnapshot, $[4] = t1) : t1 = $[4];
|
|
1431
|
-
let t2;
|
|
1432
|
-
return $[5] !== send || $[6] !== t1 ? (t2 = {
|
|
1433
|
-
snapshot: t1,
|
|
1434
|
-
send
|
|
1435
|
-
}, $[5] = send, $[6] = t1, $[7] = t2) : t2 = $[7], t2;
|
|
982
|
+
let $ = c(8), editor = useEditor(), t0;
|
|
983
|
+
$[0] !== editor || $[1] !== props.schemaType ? (t0 = { input: {
|
|
984
|
+
editor,
|
|
985
|
+
schemaType: props.schemaType
|
|
986
|
+
} }, $[0] = editor, $[1] = props.schemaType, $[2] = t0) : t0 = $[2];
|
|
987
|
+
let [actorSnapshot, send] = useActor(inlineObjectButtonMachine, t0), t1;
|
|
988
|
+
$[3] === actorSnapshot ? t1 = $[4] : (t1 = { matches: (state) => actorSnapshot.matches(state) }, $[3] = actorSnapshot, $[4] = t1);
|
|
989
|
+
let t2;
|
|
990
|
+
return $[5] !== send || $[6] !== t1 ? (t2 = {
|
|
991
|
+
snapshot: t1,
|
|
992
|
+
send
|
|
993
|
+
}, $[5] = send, $[6] = t1, $[7] = t2) : t2 = $[7], t2;
|
|
1436
994
|
}
|
|
1437
|
-
const activeListener$2 = fromCallback(({
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
}
|
|
1482
|
-
types: {
|
|
1483
|
-
context: {},
|
|
1484
|
-
input: {},
|
|
1485
|
-
events: {}
|
|
1486
|
-
},
|
|
1487
|
-
actions: {
|
|
1488
|
-
reset: assign({
|
|
1489
|
-
inlineObjects: [],
|
|
1490
|
-
elementRef: React.createRef()
|
|
1491
|
-
})
|
|
1492
|
-
},
|
|
1493
|
-
actors: {
|
|
1494
|
-
"disable listener": disableListener,
|
|
1495
|
-
"active listener": activeListener$2
|
|
1496
|
-
}
|
|
995
|
+
const activeListener$2 = fromCallback(({ input, sendBack }) => input.editor.on("selection", () => {
|
|
996
|
+
let snapshot = input.editor.getSnapshot();
|
|
997
|
+
if (!selectors.isSelectionCollapsed(snapshot)) {
|
|
998
|
+
sendBack({ type: "set inactive" });
|
|
999
|
+
return;
|
|
1000
|
+
}
|
|
1001
|
+
let focusInlineObject = selectors.getFocusInlineObject(snapshot);
|
|
1002
|
+
if (!focusInlineObject) {
|
|
1003
|
+
sendBack({ type: "set inactive" });
|
|
1004
|
+
return;
|
|
1005
|
+
}
|
|
1006
|
+
let schemaType = input.schemaTypes.find((schemaType) => schemaType.name === focusInlineObject.node._type);
|
|
1007
|
+
if (!schemaType) {
|
|
1008
|
+
sendBack({ type: "set inactive" });
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
let firstSelectedNode = input.editor.dom.getChildNodes(snapshot).at(0);
|
|
1012
|
+
if (!firstSelectedNode || !(firstSelectedNode instanceof Element)) {
|
|
1013
|
+
sendBack({ type: "set inactive" });
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
let elementRef = React.createRef();
|
|
1017
|
+
elementRef.current = firstSelectedNode, sendBack({
|
|
1018
|
+
type: "set active",
|
|
1019
|
+
inlineObjects: [{
|
|
1020
|
+
value: focusInlineObject.node,
|
|
1021
|
+
schemaType,
|
|
1022
|
+
at: focusInlineObject.path
|
|
1023
|
+
}],
|
|
1024
|
+
elementRef
|
|
1025
|
+
});
|
|
1026
|
+
}, { batch: !0 }).unsubscribe), inlineObjectPopoverMachine = setup({
|
|
1027
|
+
types: {
|
|
1028
|
+
context: {},
|
|
1029
|
+
input: {},
|
|
1030
|
+
events: {}
|
|
1031
|
+
},
|
|
1032
|
+
actions: { reset: assign({
|
|
1033
|
+
inlineObjects: [],
|
|
1034
|
+
elementRef: React.createRef()
|
|
1035
|
+
}) },
|
|
1036
|
+
actors: {
|
|
1037
|
+
"disable listener": disableListener,
|
|
1038
|
+
"active listener": activeListener$2
|
|
1039
|
+
}
|
|
1497
1040
|
}).createMachine({
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
},
|
|
1586
|
-
disable: {
|
|
1587
|
-
target: "#inline object popover.disabled.active"
|
|
1588
|
-
},
|
|
1589
|
-
"set active": {
|
|
1590
|
-
actions: assign({
|
|
1591
|
-
inlineObjects: ({
|
|
1592
|
-
event
|
|
1593
|
-
}) => event.inlineObjects,
|
|
1594
|
-
elementRef: ({
|
|
1595
|
-
event
|
|
1596
|
-
}) => event.elementRef
|
|
1597
|
-
})
|
|
1598
|
-
},
|
|
1599
|
-
edit: {
|
|
1600
|
-
actions: ({
|
|
1601
|
-
context,
|
|
1602
|
-
event
|
|
1603
|
-
}) => {
|
|
1604
|
-
context.editor.send({
|
|
1605
|
-
type: "child.set",
|
|
1606
|
-
at: event.at,
|
|
1607
|
-
props: event.props
|
|
1608
|
-
}), context.editor.send({
|
|
1609
|
-
type: "focus"
|
|
1610
|
-
});
|
|
1611
|
-
}
|
|
1612
|
-
},
|
|
1613
|
-
remove: {
|
|
1614
|
-
actions: ({
|
|
1615
|
-
context,
|
|
1616
|
-
event
|
|
1617
|
-
}) => {
|
|
1618
|
-
context.editor.send({
|
|
1619
|
-
type: "delete.child",
|
|
1620
|
-
at: event.at
|
|
1621
|
-
}), context.editor.send({
|
|
1622
|
-
type: "focus"
|
|
1623
|
-
});
|
|
1624
|
-
}
|
|
1625
|
-
},
|
|
1626
|
-
close: {
|
|
1627
|
-
actions: ({
|
|
1628
|
-
context
|
|
1629
|
-
}) => {
|
|
1630
|
-
context.editor.send({
|
|
1631
|
-
type: "focus"
|
|
1632
|
-
});
|
|
1633
|
-
},
|
|
1634
|
-
target: "inactive"
|
|
1635
|
-
}
|
|
1636
|
-
}
|
|
1637
|
-
}
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1041
|
+
id: "inline object popover",
|
|
1042
|
+
context: ({ input }) => ({
|
|
1043
|
+
editor: input.editor,
|
|
1044
|
+
schemaTypes: input.schemaTypes,
|
|
1045
|
+
inlineObjects: [],
|
|
1046
|
+
elementRef: React.createRef()
|
|
1047
|
+
}),
|
|
1048
|
+
invoke: [{
|
|
1049
|
+
src: "disable listener",
|
|
1050
|
+
input: ({ context }) => ({ editor: context.editor })
|
|
1051
|
+
}, {
|
|
1052
|
+
src: "active listener",
|
|
1053
|
+
input: ({ context }) => ({
|
|
1054
|
+
editor: context.editor,
|
|
1055
|
+
schemaTypes: context.schemaTypes
|
|
1056
|
+
})
|
|
1057
|
+
}],
|
|
1058
|
+
initial: "disabled",
|
|
1059
|
+
states: {
|
|
1060
|
+
disabled: {
|
|
1061
|
+
initial: "inactive",
|
|
1062
|
+
states: {
|
|
1063
|
+
inactive: {
|
|
1064
|
+
entry: ["reset"],
|
|
1065
|
+
on: {
|
|
1066
|
+
"set active": {
|
|
1067
|
+
actions: assign({
|
|
1068
|
+
inlineObjects: ({ event }) => event.inlineObjects,
|
|
1069
|
+
elementRef: ({ event }) => event.elementRef
|
|
1070
|
+
}),
|
|
1071
|
+
target: "active"
|
|
1072
|
+
},
|
|
1073
|
+
enable: { target: "#inline object popover.enabled.inactive" }
|
|
1074
|
+
}
|
|
1075
|
+
},
|
|
1076
|
+
active: { on: {
|
|
1077
|
+
"set inactive": { target: "inactive" },
|
|
1078
|
+
enable: { target: "#inline object popover.enabled.active" }
|
|
1079
|
+
} }
|
|
1080
|
+
}
|
|
1081
|
+
},
|
|
1082
|
+
enabled: {
|
|
1083
|
+
initial: "inactive",
|
|
1084
|
+
states: {
|
|
1085
|
+
inactive: {
|
|
1086
|
+
entry: ["reset"],
|
|
1087
|
+
on: {
|
|
1088
|
+
"set active": {
|
|
1089
|
+
target: "active",
|
|
1090
|
+
actions: assign({
|
|
1091
|
+
inlineObjects: ({ event }) => event.inlineObjects,
|
|
1092
|
+
elementRef: ({ event }) => event.elementRef
|
|
1093
|
+
})
|
|
1094
|
+
},
|
|
1095
|
+
disable: { target: "#inline object popover.disabled.inactive" }
|
|
1096
|
+
}
|
|
1097
|
+
},
|
|
1098
|
+
active: { on: {
|
|
1099
|
+
"set inactive": { target: "inactive" },
|
|
1100
|
+
disable: { target: "#inline object popover.disabled.active" },
|
|
1101
|
+
"set active": { actions: assign({
|
|
1102
|
+
inlineObjects: ({ event }) => event.inlineObjects,
|
|
1103
|
+
elementRef: ({ event }) => event.elementRef
|
|
1104
|
+
}) },
|
|
1105
|
+
edit: { actions: ({ context, event }) => {
|
|
1106
|
+
context.editor.send({
|
|
1107
|
+
type: "child.set",
|
|
1108
|
+
at: event.at,
|
|
1109
|
+
props: event.props
|
|
1110
|
+
}), context.editor.send({ type: "focus" });
|
|
1111
|
+
} },
|
|
1112
|
+
remove: { actions: ({ context, event }) => {
|
|
1113
|
+
context.editor.send({
|
|
1114
|
+
type: "delete.child",
|
|
1115
|
+
at: event.at
|
|
1116
|
+
}), context.editor.send({ type: "focus" });
|
|
1117
|
+
} },
|
|
1118
|
+
close: {
|
|
1119
|
+
actions: ({ context }) => {
|
|
1120
|
+
context.editor.send({ type: "focus" });
|
|
1121
|
+
},
|
|
1122
|
+
target: "inactive"
|
|
1123
|
+
}
|
|
1124
|
+
} }
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1641
1128
|
});
|
|
1129
|
+
/**
|
|
1130
|
+
* @beta
|
|
1131
|
+
* Manages the state and available events for an inline object popover.
|
|
1132
|
+
*/
|
|
1642
1133
|
function useInlineObjectPopover(props) {
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
return $[11] !== send || $[12] !== t3 ? (t4 = {
|
|
1666
|
-
snapshot: t3,
|
|
1667
|
-
send
|
|
1668
|
-
}, $[11] = send, $[12] = t3, $[13] = t4) : t4 = $[13], t4;
|
|
1134
|
+
let $ = c(14), editor = useEditor(), t0;
|
|
1135
|
+
$[0] !== editor || $[1] !== props.schemaTypes ? (t0 = { input: {
|
|
1136
|
+
editor,
|
|
1137
|
+
schemaTypes: props.schemaTypes
|
|
1138
|
+
} }, $[0] = editor, $[1] = props.schemaTypes, $[2] = t0) : t0 = $[2];
|
|
1139
|
+
let [actorSnapshot, send] = useActor(inlineObjectPopoverMachine, t0), t1;
|
|
1140
|
+
$[3] !== actorSnapshot.context.elementRef || $[4] !== actorSnapshot.context.inlineObjects ? (t1 = {
|
|
1141
|
+
inlineObjects: actorSnapshot.context.inlineObjects,
|
|
1142
|
+
elementRef: actorSnapshot.context.elementRef
|
|
1143
|
+
}, $[3] = actorSnapshot.context.elementRef, $[4] = actorSnapshot.context.inlineObjects, $[5] = t1) : t1 = $[5];
|
|
1144
|
+
let t2;
|
|
1145
|
+
$[6] === actorSnapshot ? t2 = $[7] : (t2 = (state) => actorSnapshot.matches(state), $[6] = actorSnapshot, $[7] = t2);
|
|
1146
|
+
let t3;
|
|
1147
|
+
$[8] !== t1 || $[9] !== t2 ? (t3 = {
|
|
1148
|
+
context: t1,
|
|
1149
|
+
matches: t2
|
|
1150
|
+
}, $[8] = t1, $[9] = t2, $[10] = t3) : t3 = $[10];
|
|
1151
|
+
let t4;
|
|
1152
|
+
return $[11] !== send || $[12] !== t3 ? (t4 = {
|
|
1153
|
+
snapshot: t3,
|
|
1154
|
+
send
|
|
1155
|
+
}, $[11] = send, $[12] = t3, $[13] = t4) : t4 = $[13], t4;
|
|
1669
1156
|
}
|
|
1670
|
-
const activeListener$1 = fromCallback(({
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
}
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
},
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
input: {},
|
|
1690
|
-
events: {}
|
|
1691
|
-
},
|
|
1692
|
-
actions: {
|
|
1693
|
-
toggle: ({
|
|
1694
|
-
context,
|
|
1695
|
-
event
|
|
1696
|
-
}) => {
|
|
1697
|
-
event.type === "toggle" && (context.editor.send({
|
|
1698
|
-
type: "list item.toggle",
|
|
1699
|
-
listItem: context.schemaType.name
|
|
1700
|
-
}), context.editor.send({
|
|
1701
|
-
type: "focus"
|
|
1702
|
-
}));
|
|
1703
|
-
}
|
|
1704
|
-
},
|
|
1705
|
-
actors: {
|
|
1706
|
-
"disable listener": disableListener,
|
|
1707
|
-
"active listener": activeListener$1
|
|
1708
|
-
}
|
|
1157
|
+
const activeListener$1 = fromCallback(({ input, sendBack }) => (selectors.isActiveListItem(input.schemaType.name)(input.editor.getSnapshot()) ? sendBack({ type: "set active" }) : sendBack({ type: "set inactive" }), input.editor.on("*", () => {
|
|
1158
|
+
let snapshot = input.editor.getSnapshot();
|
|
1159
|
+
selectors.isActiveListItem(input.schemaType.name)(snapshot) ? sendBack({ type: "set active" }) : sendBack({ type: "set inactive" });
|
|
1160
|
+
}, { batch: !0 }).unsubscribe)), listButtonMachine = setup({
|
|
1161
|
+
types: {
|
|
1162
|
+
context: {},
|
|
1163
|
+
input: {},
|
|
1164
|
+
events: {}
|
|
1165
|
+
},
|
|
1166
|
+
actions: { toggle: ({ context, event }) => {
|
|
1167
|
+
event.type === "toggle" && (context.editor.send({
|
|
1168
|
+
type: "list item.toggle",
|
|
1169
|
+
listItem: context.schemaType.name
|
|
1170
|
+
}), context.editor.send({ type: "focus" }));
|
|
1171
|
+
} },
|
|
1172
|
+
actors: {
|
|
1173
|
+
"disable listener": disableListener,
|
|
1174
|
+
"active listener": activeListener$1
|
|
1175
|
+
}
|
|
1709
1176
|
}).createMachine({
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
}
|
|
1756
|
-
}
|
|
1757
|
-
}
|
|
1758
|
-
}
|
|
1759
|
-
},
|
|
1760
|
-
enabled: {
|
|
1761
|
-
on: {
|
|
1762
|
-
toggle: {
|
|
1763
|
-
actions: ["toggle"]
|
|
1764
|
-
}
|
|
1765
|
-
},
|
|
1766
|
-
initial: "inactive",
|
|
1767
|
-
states: {
|
|
1768
|
-
inactive: {
|
|
1769
|
-
on: {
|
|
1770
|
-
disable: {
|
|
1771
|
-
target: "#list button.disabled.inactive"
|
|
1772
|
-
},
|
|
1773
|
-
"set active": {
|
|
1774
|
-
target: "active"
|
|
1775
|
-
}
|
|
1776
|
-
}
|
|
1777
|
-
},
|
|
1778
|
-
active: {
|
|
1779
|
-
on: {
|
|
1780
|
-
disable: {
|
|
1781
|
-
target: "#list button.disabled.active"
|
|
1782
|
-
},
|
|
1783
|
-
"set inactive": {
|
|
1784
|
-
target: "inactive"
|
|
1785
|
-
}
|
|
1786
|
-
}
|
|
1787
|
-
}
|
|
1788
|
-
}
|
|
1789
|
-
}
|
|
1790
|
-
}
|
|
1177
|
+
id: "list button",
|
|
1178
|
+
context: ({ input }) => ({
|
|
1179
|
+
editor: input.editor,
|
|
1180
|
+
schemaType: input.schemaType
|
|
1181
|
+
}),
|
|
1182
|
+
invoke: [{
|
|
1183
|
+
src: "disable listener",
|
|
1184
|
+
input: ({ context }) => ({ editor: context.editor })
|
|
1185
|
+
}, {
|
|
1186
|
+
src: "active listener",
|
|
1187
|
+
input: ({ context }) => ({
|
|
1188
|
+
editor: context.editor,
|
|
1189
|
+
schemaType: context.schemaType
|
|
1190
|
+
})
|
|
1191
|
+
}],
|
|
1192
|
+
initial: "disabled",
|
|
1193
|
+
states: {
|
|
1194
|
+
disabled: {
|
|
1195
|
+
initial: "inactive",
|
|
1196
|
+
states: {
|
|
1197
|
+
inactive: { on: {
|
|
1198
|
+
enable: { target: "#list button.enabled.inactive" },
|
|
1199
|
+
"set active": { target: "active" }
|
|
1200
|
+
} },
|
|
1201
|
+
active: { on: {
|
|
1202
|
+
enable: { target: "#list button.enabled.active" },
|
|
1203
|
+
"set inactive": { target: "inactive" }
|
|
1204
|
+
} }
|
|
1205
|
+
}
|
|
1206
|
+
},
|
|
1207
|
+
enabled: {
|
|
1208
|
+
on: { toggle: { actions: ["toggle"] } },
|
|
1209
|
+
initial: "inactive",
|
|
1210
|
+
states: {
|
|
1211
|
+
inactive: { on: {
|
|
1212
|
+
disable: { target: "#list button.disabled.inactive" },
|
|
1213
|
+
"set active": { target: "active" }
|
|
1214
|
+
} },
|
|
1215
|
+
active: { on: {
|
|
1216
|
+
disable: { target: "#list button.disabled.active" },
|
|
1217
|
+
"set inactive": { target: "inactive" }
|
|
1218
|
+
} }
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1791
1222
|
});
|
|
1223
|
+
/**
|
|
1224
|
+
* @beta
|
|
1225
|
+
* Manages the state, keyboard shortcuts and available events for a list button.
|
|
1226
|
+
*/
|
|
1792
1227
|
function useListButton(props) {
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
}, $[3] = actorSnapshot, $[4] = t1) : t1 = $[4];
|
|
1806
|
-
let t2;
|
|
1807
|
-
return $[5] !== send || $[6] !== t1 ? (t2 = {
|
|
1808
|
-
snapshot: t1,
|
|
1809
|
-
send
|
|
1810
|
-
}, $[5] = send, $[6] = t1, $[7] = t2) : t2 = $[7], t2;
|
|
1228
|
+
let $ = c(8), editor = useEditor(), t0;
|
|
1229
|
+
$[0] !== editor || $[1] !== props.schemaType ? (t0 = { input: {
|
|
1230
|
+
editor,
|
|
1231
|
+
schemaType: props.schemaType
|
|
1232
|
+
} }, $[0] = editor, $[1] = props.schemaType, $[2] = t0) : t0 = $[2];
|
|
1233
|
+
let [actorSnapshot, send] = useActor(listButtonMachine, t0), t1;
|
|
1234
|
+
$[3] === actorSnapshot ? t1 = $[4] : (t1 = { matches: (state) => actorSnapshot.matches(state) }, $[3] = actorSnapshot, $[4] = t1);
|
|
1235
|
+
let t2;
|
|
1236
|
+
return $[5] !== send || $[6] !== t1 ? (t2 = {
|
|
1237
|
+
snapshot: t1,
|
|
1238
|
+
send
|
|
1239
|
+
}, $[5] = send, $[6] = t1, $[7] = t2) : t2 = $[7], t2;
|
|
1811
1240
|
}
|
|
1812
|
-
const styleKeyboardShortcutsListener = fromCallback(({
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
})
|
|
1828
|
-
})] : [];
|
|
1829
|
-
});
|
|
1830
|
-
return () => {
|
|
1831
|
-
for (const unregisterBehavior of unregisterBehaviors)
|
|
1832
|
-
unregisterBehavior();
|
|
1833
|
-
};
|
|
1241
|
+
const styleKeyboardShortcutsListener = fromCallback(({ input }) => {
|
|
1242
|
+
let unregisterBehaviors = input.schemaTypes.flatMap((schemaType) => {
|
|
1243
|
+
let shortcut = schemaType.shortcut;
|
|
1244
|
+
return shortcut ? [input.editor.registerBehavior({ behavior: defineBehavior({
|
|
1245
|
+
on: "keyboard.keydown",
|
|
1246
|
+
guard: ({ event }) => shortcut.guard(event.originEvent),
|
|
1247
|
+
actions: [() => [raise({
|
|
1248
|
+
type: "style.toggle",
|
|
1249
|
+
style: schemaType.name
|
|
1250
|
+
})]]
|
|
1251
|
+
}) })] : [];
|
|
1252
|
+
});
|
|
1253
|
+
return () => {
|
|
1254
|
+
for (let unregisterBehavior of unregisterBehaviors) unregisterBehavior();
|
|
1255
|
+
};
|
|
1834
1256
|
}), styleKeyboardShortcutsMachine = setup({
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1257
|
+
types: {
|
|
1258
|
+
context: {},
|
|
1259
|
+
input: {},
|
|
1260
|
+
events: {}
|
|
1261
|
+
},
|
|
1262
|
+
actors: {
|
|
1263
|
+
"disable listener": disableListener,
|
|
1264
|
+
"style keyboard shortcuts listener": styleKeyboardShortcutsListener
|
|
1265
|
+
}
|
|
1844
1266
|
}).createMachine({
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
},
|
|
1869
|
-
enabled: {
|
|
1870
|
-
invoke: {
|
|
1871
|
-
src: "style keyboard shortcuts listener",
|
|
1872
|
-
input: ({
|
|
1873
|
-
context
|
|
1874
|
-
}) => ({
|
|
1875
|
-
editor: context.editor,
|
|
1876
|
-
schemaTypes: context.schemaTypes
|
|
1877
|
-
})
|
|
1878
|
-
},
|
|
1879
|
-
on: {
|
|
1880
|
-
disable: {
|
|
1881
|
-
target: "disabled"
|
|
1882
|
-
}
|
|
1883
|
-
}
|
|
1884
|
-
}
|
|
1885
|
-
}
|
|
1267
|
+
id: "style keyboard shortcuts",
|
|
1268
|
+
context: ({ input }) => ({
|
|
1269
|
+
editor: input.editor,
|
|
1270
|
+
schemaTypes: input.schemaTypes
|
|
1271
|
+
}),
|
|
1272
|
+
invoke: {
|
|
1273
|
+
src: "disable listener",
|
|
1274
|
+
input: ({ context }) => ({ editor: context.editor })
|
|
1275
|
+
},
|
|
1276
|
+
initial: "disabled",
|
|
1277
|
+
states: {
|
|
1278
|
+
disabled: { on: { enable: { target: "enabled" } } },
|
|
1279
|
+
enabled: {
|
|
1280
|
+
invoke: {
|
|
1281
|
+
src: "style keyboard shortcuts listener",
|
|
1282
|
+
input: ({ context }) => ({
|
|
1283
|
+
editor: context.editor,
|
|
1284
|
+
schemaTypes: context.schemaTypes
|
|
1285
|
+
})
|
|
1286
|
+
},
|
|
1287
|
+
on: { disable: { target: "disabled" } }
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1886
1290
|
});
|
|
1291
|
+
/**
|
|
1292
|
+
* @beta
|
|
1293
|
+
* Registers keyboard shortcuts for a set of style schema types.
|
|
1294
|
+
*/
|
|
1887
1295
|
function useStyleKeyboardShortcuts(props) {
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
schemaTypes: props.schemaTypes
|
|
1894
|
-
}
|
|
1895
|
-
}, $[0] = editor, $[1] = props.schemaTypes, $[2] = t0) : t0 = $[2], useActorRef(styleKeyboardShortcutsMachine, t0);
|
|
1296
|
+
let $ = c(3), editor = useEditor(), t0;
|
|
1297
|
+
$[0] !== editor || $[1] !== props.schemaTypes ? (t0 = { input: {
|
|
1298
|
+
editor,
|
|
1299
|
+
schemaTypes: props.schemaTypes
|
|
1300
|
+
} }, $[0] = editor, $[1] = props.schemaTypes, $[2] = t0) : t0 = $[2], useActorRef(styleKeyboardShortcutsMachine, t0);
|
|
1896
1301
|
}
|
|
1897
|
-
const activeListener = fromCallback(({
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
}) => {
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
context: {},
|
|
1917
|
-
input: {},
|
|
1918
|
-
events: {}
|
|
1919
|
-
},
|
|
1920
|
-
actors: {
|
|
1921
|
-
"disable listener": disableListener,
|
|
1922
|
-
"active listener": activeListener
|
|
1923
|
-
}
|
|
1302
|
+
const activeListener = fromCallback(({ input, sendBack }) => (sendBack({
|
|
1303
|
+
type: "set active style",
|
|
1304
|
+
style: selectors.getActiveStyle(input.editor.getSnapshot())
|
|
1305
|
+
}), input.editor.on("*", () => {
|
|
1306
|
+
let snapshot = input.editor.getSnapshot();
|
|
1307
|
+
sendBack({
|
|
1308
|
+
type: "set active style",
|
|
1309
|
+
style: selectors.getActiveStyle(snapshot)
|
|
1310
|
+
});
|
|
1311
|
+
}, { batch: !0 }).unsubscribe)), styleSelectorMachine = setup({
|
|
1312
|
+
types: {
|
|
1313
|
+
context: {},
|
|
1314
|
+
input: {},
|
|
1315
|
+
events: {}
|
|
1316
|
+
},
|
|
1317
|
+
actors: {
|
|
1318
|
+
"disable listener": disableListener,
|
|
1319
|
+
"active listener": activeListener
|
|
1320
|
+
}
|
|
1924
1321
|
}).createMachine({
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
activeStyle: ({
|
|
1955
|
-
event
|
|
1956
|
-
}) => event.style
|
|
1957
|
-
})
|
|
1958
|
-
}
|
|
1959
|
-
},
|
|
1960
|
-
initial: "disabled",
|
|
1961
|
-
states: {
|
|
1962
|
-
disabled: {
|
|
1963
|
-
on: {
|
|
1964
|
-
enable: {
|
|
1965
|
-
target: "enabled"
|
|
1966
|
-
}
|
|
1967
|
-
}
|
|
1968
|
-
},
|
|
1969
|
-
enabled: {
|
|
1970
|
-
on: {
|
|
1971
|
-
disable: {
|
|
1972
|
-
target: "disabled"
|
|
1973
|
-
},
|
|
1974
|
-
toggle: {
|
|
1975
|
-
actions: [({
|
|
1976
|
-
context,
|
|
1977
|
-
event
|
|
1978
|
-
}) => {
|
|
1979
|
-
context.editor.send({
|
|
1980
|
-
type: "style.toggle",
|
|
1981
|
-
style: event.style
|
|
1982
|
-
}), context.editor.send({
|
|
1983
|
-
type: "focus"
|
|
1984
|
-
});
|
|
1985
|
-
}]
|
|
1986
|
-
}
|
|
1987
|
-
}
|
|
1988
|
-
}
|
|
1989
|
-
}
|
|
1322
|
+
id: "style selector",
|
|
1323
|
+
context: ({ input }) => ({
|
|
1324
|
+
editor: input.editor,
|
|
1325
|
+
activeStyle: void 0
|
|
1326
|
+
}),
|
|
1327
|
+
invoke: [{
|
|
1328
|
+
src: "disable listener",
|
|
1329
|
+
input: ({ context }) => ({ editor: context.editor })
|
|
1330
|
+
}, {
|
|
1331
|
+
src: "active listener",
|
|
1332
|
+
input: ({ context }) => ({ editor: context.editor })
|
|
1333
|
+
}],
|
|
1334
|
+
on: { "set active style": {
|
|
1335
|
+
guard: ({ context, event }) => context.activeStyle !== event.style,
|
|
1336
|
+
actions: assign({ activeStyle: ({ event }) => event.style })
|
|
1337
|
+
} },
|
|
1338
|
+
initial: "disabled",
|
|
1339
|
+
states: {
|
|
1340
|
+
disabled: { on: { enable: { target: "enabled" } } },
|
|
1341
|
+
enabled: { on: {
|
|
1342
|
+
disable: { target: "disabled" },
|
|
1343
|
+
toggle: { actions: [({ context, event }) => {
|
|
1344
|
+
context.editor.send({
|
|
1345
|
+
type: "style.toggle",
|
|
1346
|
+
style: event.style
|
|
1347
|
+
}), context.editor.send({ type: "focus" });
|
|
1348
|
+
}] }
|
|
1349
|
+
} }
|
|
1350
|
+
}
|
|
1990
1351
|
});
|
|
1352
|
+
/**
|
|
1353
|
+
* @beta
|
|
1354
|
+
* Manages the state, keyboard shortcuts and available events for a style
|
|
1355
|
+
* selector.
|
|
1356
|
+
*/
|
|
1991
1357
|
function useStyleSelector(props) {
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
context: t2
|
|
2011
|
-
}, $[6] = t1, $[7] = t2, $[8] = t3) : t3 = $[8];
|
|
2012
|
-
let t4;
|
|
2013
|
-
return $[9] !== send || $[10] !== t3 ? (t4 = {
|
|
2014
|
-
snapshot: t3,
|
|
2015
|
-
send
|
|
2016
|
-
}, $[9] = send, $[10] = t3, $[11] = t4) : t4 = $[11], t4;
|
|
1358
|
+
let $ = c(12), editor = useEditor(), t0;
|
|
1359
|
+
$[0] === editor ? t0 = $[1] : (t0 = { input: { editor } }, $[0] = editor, $[1] = t0);
|
|
1360
|
+
let [actorSnapshot, send] = useActor(styleSelectorMachine, t0);
|
|
1361
|
+
useStyleKeyboardShortcuts(props);
|
|
1362
|
+
let t1;
|
|
1363
|
+
$[2] === actorSnapshot ? t1 = $[3] : (t1 = (state) => actorSnapshot.matches(state), $[2] = actorSnapshot, $[3] = t1);
|
|
1364
|
+
let t2;
|
|
1365
|
+
$[4] === actorSnapshot.context.activeStyle ? t2 = $[5] : (t2 = { activeStyle: actorSnapshot.context.activeStyle }, $[4] = actorSnapshot.context.activeStyle, $[5] = t2);
|
|
1366
|
+
let t3;
|
|
1367
|
+
$[6] !== t1 || $[7] !== t2 ? (t3 = {
|
|
1368
|
+
matches: t1,
|
|
1369
|
+
context: t2
|
|
1370
|
+
}, $[6] = t1, $[7] = t2, $[8] = t3) : t3 = $[8];
|
|
1371
|
+
let t4;
|
|
1372
|
+
return $[9] !== send || $[10] !== t3 ? (t4 = {
|
|
1373
|
+
snapshot: t3,
|
|
1374
|
+
send
|
|
1375
|
+
}, $[9] = send, $[10] = t3, $[11] = t4) : t4 = $[11], t4;
|
|
2017
1376
|
}
|
|
2018
|
-
export {
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
useApplicableSchema,
|
|
2022
|
-
useBlockObjectButton,
|
|
2023
|
-
useBlockObjectPopover,
|
|
2024
|
-
useDecoratorButton,
|
|
2025
|
-
useHistoryButtons,
|
|
2026
|
-
useInlineObjectButton,
|
|
2027
|
-
useInlineObjectPopover,
|
|
2028
|
-
useListButton,
|
|
2029
|
-
useStyleSelector,
|
|
2030
|
-
useToolbarSchema
|
|
2031
|
-
};
|
|
2032
|
-
//# sourceMappingURL=index.js.map
|
|
1377
|
+
export { useAnnotationButton, useAnnotationPopover, useApplicableSchema, useBlockObjectButton, useBlockObjectPopover, useDecoratorButton, useHistoryButtons, useInlineObjectButton, useInlineObjectPopover, useListButton, useStyleSelector, useToolbarSchema };
|
|
1378
|
+
|
|
1379
|
+
//# sourceMappingURL=index.js.map
|