@portabletext/toolbar 2.2.36 → 3.0.0

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