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