@portabletext/toolbar 2.1.1 → 2.2.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 +46 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +48 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/use-annotation-button.ts +3 -0
- package/src/use-mutually-exclusive-annotation.ts +48 -0
- package/src/use-toolbar-schema.ts +2 -0
package/dist/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { c } from "react/compiler-runtime";
|
|
2
2
|
import { useEditor, useEditorSelector } from "@portabletext/editor";
|
|
3
|
-
import { defineBehavior, raise, effect, forward } from "@portabletext/editor/behaviors";
|
|
3
|
+
import { defineBehavior, execute, raise, effect, forward } from "@portabletext/editor/behaviors";
|
|
4
4
|
import * as selectors from "@portabletext/editor/selectors";
|
|
5
|
+
import { isActiveAnnotation } from "@portabletext/editor/selectors";
|
|
5
6
|
import { useActor, useActorRef } from "@xstate/react";
|
|
6
7
|
import { fromCallback, setup, assign } from "xstate";
|
|
7
8
|
import * as React from "react";
|
|
8
9
|
import { useEffect } from "react";
|
|
9
10
|
function useToolbarSchema(props) {
|
|
10
|
-
const $ = c(37), editor = useEditor(), schema = useEditorSelector(editor, _temp$
|
|
11
|
+
const $ = c(37), editor = useEditor(), schema = useEditorSelector(editor, _temp$2);
|
|
11
12
|
let t0;
|
|
12
13
|
if ($[0] !== props || $[1] !== schema.decorators) {
|
|
13
14
|
let t12;
|
|
@@ -54,7 +55,7 @@ function useToolbarSchema(props) {
|
|
|
54
55
|
styles: t5
|
|
55
56
|
}, $[30] = t0, $[31] = t1, $[32] = t2, $[33] = t3, $[34] = t4, $[35] = t5, $[36] = t6) : t6 = $[36], t6;
|
|
56
57
|
}
|
|
57
|
-
function _temp$
|
|
58
|
+
function _temp$2(snapshot) {
|
|
58
59
|
return snapshot.context.schema;
|
|
59
60
|
}
|
|
60
61
|
const disableListener = fromCallback(({
|
|
@@ -66,7 +67,49 @@ const disableListener = fromCallback(({
|
|
|
66
67
|
}) : sendBack({
|
|
67
68
|
type: "enable"
|
|
68
69
|
});
|
|
69
|
-
}).unsubscribe)
|
|
70
|
+
}).unsubscribe);
|
|
71
|
+
function useMutuallyExclusiveAnnotation(props) {
|
|
72
|
+
const $ = c(5), editor = useEditor();
|
|
73
|
+
let t0, t1;
|
|
74
|
+
$[0] !== editor || $[1] !== props.schemaType.mutuallyExclusive || $[2] !== props.schemaType.name ? (t0 = () => {
|
|
75
|
+
const mutuallyExclusive = props.schemaType.mutuallyExclusive;
|
|
76
|
+
if (mutuallyExclusive)
|
|
77
|
+
return editor.registerBehavior({
|
|
78
|
+
behavior: defineBehavior({
|
|
79
|
+
on: "annotation.add",
|
|
80
|
+
guard: (t2) => {
|
|
81
|
+
const {
|
|
82
|
+
snapshot,
|
|
83
|
+
event
|
|
84
|
+
} = t2;
|
|
85
|
+
return event.annotation.name !== props.schemaType.name ? !1 : {
|
|
86
|
+
activeMutuallyExclusive: mutuallyExclusive.filter((annotation) => isActiveAnnotation(annotation, {
|
|
87
|
+
mode: "partial"
|
|
88
|
+
})(snapshot))
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
actions: [_temp2]
|
|
92
|
+
})
|
|
93
|
+
});
|
|
94
|
+
}, t1 = [editor, props.schemaType.name, props.schemaType.mutuallyExclusive], $[0] = editor, $[1] = props.schemaType.mutuallyExclusive, $[2] = props.schemaType.name, $[3] = t0, $[4] = t1) : (t0 = $[3], t1 = $[4]), useEffect(t0, t1);
|
|
95
|
+
}
|
|
96
|
+
function _temp2(t0, t1) {
|
|
97
|
+
const {
|
|
98
|
+
event: event_0
|
|
99
|
+
} = t0, {
|
|
100
|
+
activeMutuallyExclusive: activeMutuallyExclusive_0
|
|
101
|
+
} = t1;
|
|
102
|
+
return [...activeMutuallyExclusive_0.map(_temp$1), execute(event_0)];
|
|
103
|
+
}
|
|
104
|
+
function _temp$1(annotation_0) {
|
|
105
|
+
return raise({
|
|
106
|
+
type: "annotation.remove",
|
|
107
|
+
annotation: {
|
|
108
|
+
name: annotation_0
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const activeListener$6 = fromCallback(({
|
|
70
113
|
input,
|
|
71
114
|
sendBack
|
|
72
115
|
}) => input.editor.on("*", () => {
|
|
@@ -288,6 +331,7 @@ function useAnnotationButton(props) {
|
|
|
288
331
|
}
|
|
289
332
|
}, $[0] = editor, $[1] = props.schemaType, $[2] = t0) : t0 = $[2];
|
|
290
333
|
const [snapshot, send] = useActor(annotationButtonMachine, t0);
|
|
334
|
+
useMutuallyExclusiveAnnotation(props);
|
|
291
335
|
let t1;
|
|
292
336
|
$[3] !== snapshot ? (t1 = {
|
|
293
337
|
matches: (state) => snapshot.matches(state)
|