@portabletext/toolbar 2.1.2 → 2.2.1

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 CHANGED
@@ -18,7 +18,7 @@ function _interopNamespaceCompat(e) {
18
18
  }
19
19
  var selectors__namespace = /* @__PURE__ */ _interopNamespaceCompat(selectors), React__namespace = /* @__PURE__ */ _interopNamespaceCompat(React);
20
20
  function useToolbarSchema(props) {
21
- const $ = compilerRuntime.c(37), editor$1 = editor.useEditor(), schema = editor.useEditorSelector(editor$1, _temp$1);
21
+ const $ = compilerRuntime.c(37), editor$1 = editor.useEditor(), schema = editor.useEditorSelector(editor$1, _temp$2);
22
22
  let t0;
23
23
  if ($[0] !== props || $[1] !== schema.decorators) {
24
24
  let t12;
@@ -65,7 +65,7 @@ function useToolbarSchema(props) {
65
65
  styles: t5
66
66
  }, $[30] = t0, $[31] = t1, $[32] = t2, $[33] = t3, $[34] = t4, $[35] = t5, $[36] = t6) : t6 = $[36], t6;
67
67
  }
68
- function _temp$1(snapshot) {
68
+ function _temp$2(snapshot) {
69
69
  return snapshot.context.schema;
70
70
  }
71
71
  const disableListener = xstate.fromCallback(({
@@ -77,7 +77,49 @@ const disableListener = xstate.fromCallback(({
77
77
  }) : sendBack({
78
78
  type: "enable"
79
79
  });
80
- }).unsubscribe), activeListener$6 = xstate.fromCallback(({
80
+ }).unsubscribe);
81
+ function useMutuallyExclusiveAnnotation(props) {
82
+ const $ = compilerRuntime.c(5), editor$1 = editor.useEditor();
83
+ let t0, t1;
84
+ $[0] !== editor$1 || $[1] !== props.schemaType.mutuallyExclusive || $[2] !== props.schemaType.name ? (t0 = () => {
85
+ const mutuallyExclusive = props.schemaType.mutuallyExclusive;
86
+ if (mutuallyExclusive)
87
+ return editor$1.registerBehavior({
88
+ behavior: behaviors.defineBehavior({
89
+ on: "annotation.add",
90
+ guard: (t2) => {
91
+ const {
92
+ snapshot,
93
+ event
94
+ } = t2;
95
+ return event.annotation.name !== props.schemaType.name ? !1 : {
96
+ activeMutuallyExclusive: mutuallyExclusive.filter((annotation) => selectors.isActiveAnnotation(annotation, {
97
+ mode: "partial"
98
+ })(snapshot))
99
+ };
100
+ },
101
+ actions: [_temp2]
102
+ })
103
+ });
104
+ }, 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);
105
+ }
106
+ function _temp2(t0, t1) {
107
+ const {
108
+ event: event_0
109
+ } = t0, {
110
+ activeMutuallyExclusive: activeMutuallyExclusive_0
111
+ } = t1;
112
+ return [...activeMutuallyExclusive_0.map(_temp$1), behaviors.execute(event_0)];
113
+ }
114
+ function _temp$1(annotation_0) {
115
+ return behaviors.raise({
116
+ type: "annotation.remove",
117
+ annotation: {
118
+ name: annotation_0
119
+ }
120
+ });
121
+ }
122
+ const activeListener$6 = xstate.fromCallback(({
81
123
  input,
82
124
  sendBack
83
125
  }) => input.editor.on("*", () => {
@@ -299,6 +341,7 @@ function useAnnotationButton(props) {
299
341
  }
300
342
  }, $[0] = editor$1, $[1] = props.schemaType, $[2] = t0) : t0 = $[2];
301
343
  const [snapshot, send] = react.useActor(annotationButtonMachine, t0);
344
+ useMutuallyExclusiveAnnotation(props);
302
345
  let t1;
303
346
  $[3] !== snapshot ? (t1 = {
304
347
  matches: (state) => snapshot.matches(state)