@portabletext/editor 1.3.1 → 1.4.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/lib/index.js CHANGED
@@ -1,10 +1,250 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var jsxRuntime = require("react/jsx-runtime"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), react = require("react"), slate = require("slate"), slateReact = require("slate-react"), debug$m = require("debug"), types = require("@sanity/types"), reactCompilerRuntime = require("react-compiler-runtime"), styledComponents = require("styled-components"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), xstate = require("xstate"), schema = require("@sanity/schema"), patches = require("@portabletext/patches"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), flatten = require("lodash/flatten.js"), isHotkeyEsm = require("is-hotkey-esm"), blockTools = require("@sanity/block-tools"), isPlainObject = require("lodash/isPlainObject.js"), throttle = require("lodash/throttle.js"), useEffectEvent = require("use-effect-event"), debounce = require("lodash/debounce.js"), content = require("@sanity/util/content");
3
+ var types = require("@sanity/types"), jsxRuntime = require("react/jsx-runtime"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), require$$0 = require("react"), slate = require("slate"), slateReact = require("slate-react"), debug$m = require("debug"), reactCompilerRuntime = require("react-compiler-runtime"), styledComponents = require("styled-components"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), xstate = require("xstate"), schema = require("@sanity/schema"), patches = require("@portabletext/patches"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), flatten = require("lodash/flatten.js"), isHotkeyEsm = require("is-hotkey-esm"), blockTools = require("@sanity/block-tools"), isPlainObject = require("lodash/isPlainObject.js"), throttle = require("lodash/throttle.js"), useEffectEvent = require("use-effect-event"), debounce = require("lodash/debounce.js"), content = require("@sanity/util/content");
4
4
  function _interopDefaultCompat(e) {
5
5
  return e && typeof e == "object" && "default" in e ? e : { default: e };
6
6
  }
7
- var isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$m), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject), throttle__default = /* @__PURE__ */ _interopDefaultCompat(throttle), debounce__default = /* @__PURE__ */ _interopDefaultCompat(debounce);
7
+ var isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), require$$0__default = /* @__PURE__ */ _interopDefaultCompat(require$$0), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$m), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject), throttle__default = /* @__PURE__ */ _interopDefaultCompat(throttle), debounce__default = /* @__PURE__ */ _interopDefaultCompat(debounce);
8
+ function defineBehavior(behavior) {
9
+ return behavior;
10
+ }
11
+ function selectionIsCollapsed(context) {
12
+ return context.selection?.anchor.path.join() === context.selection?.focus.path.join() && context.selection?.anchor.offset === context.selection?.focus.offset;
13
+ }
14
+ function getFocusBlock(context) {
15
+ const key = context.selection && types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
16
+ return node && key ? {
17
+ node,
18
+ path: [{
19
+ _key: key
20
+ }]
21
+ } : void 0;
22
+ }
23
+ function getFocusTextBlock(context) {
24
+ const focusBlock = getFocusBlock(context);
25
+ return focusBlock && types.isPortableTextTextBlock(focusBlock.node) ? {
26
+ node: focusBlock.node,
27
+ path: focusBlock.path
28
+ } : void 0;
29
+ }
30
+ function getFocusBlockObject(context) {
31
+ const focusBlock = getFocusBlock(context);
32
+ return focusBlock && !types.isPortableTextTextBlock(focusBlock.node) ? {
33
+ node: focusBlock.node,
34
+ path: focusBlock.path
35
+ } : void 0;
36
+ }
37
+ function getFocusChild(context) {
38
+ const focusBlock = getFocusTextBlock(context);
39
+ if (!focusBlock)
40
+ return;
41
+ const key = context.selection && types.isKeySegment(context.selection.focus.path[2]) ? context.selection.focus.path[2]._key : void 0, node = key ? focusBlock.node.children.find((span) => span._key === key) : void 0;
42
+ return node && key ? {
43
+ node,
44
+ path: [...focusBlock.path, "children", {
45
+ _key: key
46
+ }]
47
+ } : void 0;
48
+ }
49
+ function getFocusSpan(context) {
50
+ const focusChild = getFocusChild(context);
51
+ return focusChild && types.isPortableTextSpan(focusChild.node) ? {
52
+ node: focusChild.node,
53
+ path: focusChild.path
54
+ } : void 0;
55
+ }
56
+ function getSelectionStartBlock(context) {
57
+ const key = context.selection.backward ? types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0 : types.isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
58
+ return node && key ? {
59
+ node,
60
+ path: [{
61
+ _key: key
62
+ }]
63
+ } : void 0;
64
+ }
65
+ function getSelectionEndBlock(context) {
66
+ const key = context.selection.backward ? types.isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0 : types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
67
+ return node && key ? {
68
+ node,
69
+ path: [{
70
+ _key: key
71
+ }]
72
+ } : void 0;
73
+ }
74
+ function getPreviousBlock(context) {
75
+ let previousBlock;
76
+ const selectionStartBlock = getSelectionStartBlock(context);
77
+ if (!selectionStartBlock)
78
+ return;
79
+ let foundSelectionStartBlock = !1;
80
+ for (const block of context.value) {
81
+ if (block._key === selectionStartBlock.node._key) {
82
+ foundSelectionStartBlock = !0;
83
+ break;
84
+ }
85
+ previousBlock = {
86
+ node: block,
87
+ path: [{
88
+ _key: block._key
89
+ }]
90
+ };
91
+ }
92
+ if (foundSelectionStartBlock && previousBlock)
93
+ return previousBlock;
94
+ }
95
+ function getNextBlock(context) {
96
+ let nextBlock;
97
+ const selectionEndBlock = getSelectionEndBlock(context);
98
+ if (!selectionEndBlock)
99
+ return;
100
+ let foundSelectionEndBlock = !1;
101
+ for (const block of context.value) {
102
+ if (block._key === selectionEndBlock.node._key) {
103
+ foundSelectionEndBlock = !0;
104
+ continue;
105
+ }
106
+ if (foundSelectionEndBlock) {
107
+ nextBlock = {
108
+ node: block,
109
+ path: [{
110
+ _key: block._key
111
+ }]
112
+ };
113
+ break;
114
+ }
115
+ }
116
+ if (foundSelectionEndBlock && nextBlock)
117
+ return nextBlock;
118
+ }
119
+ function isEmptyTextBlock(block) {
120
+ return block.children.length === 1 && block.children[0].text === "";
121
+ }
122
+ function createMarkdownBehaviors(config) {
123
+ const automaticStyleOnSpace = {
124
+ on: "insert text",
125
+ guard: ({
126
+ context,
127
+ event
128
+ }) => {
129
+ if (event.text !== " ")
130
+ return !1;
131
+ const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
132
+ if (!selectionCollapsed || !focusTextBlock || !focusSpan)
133
+ return !1;
134
+ const looksLikeMarkdownHeading = /^#+/.test(focusSpan.node.text), headingStyle = config.mapHeadingStyle(context.schema, focusSpan.node.text.length), looksLikeMarkdownQuote = /^>/.test(focusSpan.node.text), blockquoteStyle = config.mapBlockquoteStyle(context.schema);
135
+ return looksLikeMarkdownHeading && headingStyle !== void 0 ? {
136
+ focusTextBlock,
137
+ focusSpan,
138
+ style: headingStyle
139
+ } : looksLikeMarkdownQuote && blockquoteStyle !== void 0 ? {
140
+ focusTextBlock,
141
+ focusSpan,
142
+ style: blockquoteStyle
143
+ } : !1;
144
+ },
145
+ actions: [() => [{
146
+ type: "insert text",
147
+ text: " "
148
+ }], (_, {
149
+ focusTextBlock,
150
+ focusSpan,
151
+ style
152
+ }) => [{
153
+ type: "set block",
154
+ style,
155
+ paths: [focusTextBlock.path]
156
+ }, {
157
+ type: "delete",
158
+ selection: {
159
+ anchor: {
160
+ path: focusSpan.path,
161
+ offset: 0
162
+ },
163
+ focus: {
164
+ path: focusSpan.path,
165
+ offset: focusSpan.node.text.length + 1
166
+ }
167
+ }
168
+ }]]
169
+ }, clearStyleOnBackspace = {
170
+ on: "delete backward",
171
+ guard: ({
172
+ context
173
+ }) => {
174
+ const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
175
+ if (!selectionCollapsed || !focusTextBlock || !focusSpan)
176
+ return !1;
177
+ const defaultStyle = config.mapDefaultStyle(context.schema);
178
+ return defaultStyle && focusTextBlock.node.children.length === 1 && focusTextBlock.node.style !== config.mapDefaultStyle(context.schema) && focusSpan.node.text === "" ? {
179
+ defaultStyle,
180
+ focusTextBlock
181
+ } : !1;
182
+ },
183
+ actions: [(_, {
184
+ defaultStyle,
185
+ focusTextBlock
186
+ }) => [{
187
+ type: "set block",
188
+ style: defaultStyle,
189
+ paths: [focusTextBlock.path]
190
+ }]]
191
+ }, automaticListOnSpace = {
192
+ on: "insert text",
193
+ guard: ({
194
+ context,
195
+ event
196
+ }) => {
197
+ if (event.text !== " ")
198
+ return !1;
199
+ const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
200
+ if (!selectionCollapsed || !focusTextBlock || !focusSpan)
201
+ return !1;
202
+ const looksLikeUnorderedList = /^-/.test(focusSpan.node.text), unorderedListStyle = config.mapUnorderedListStyle(context.schema);
203
+ if (looksLikeUnorderedList && unorderedListStyle !== void 0)
204
+ return {
205
+ focusTextBlock,
206
+ focusSpan,
207
+ listItem: unorderedListStyle
208
+ };
209
+ const looksLikeOrderedList = /^1./.test(focusSpan.node.text), orderedListStyle = config.mapOrderedListStyle(context.schema);
210
+ return looksLikeOrderedList && orderedListStyle !== void 0 ? {
211
+ focusTextBlock,
212
+ focusSpan,
213
+ listItem: orderedListStyle
214
+ } : !1;
215
+ },
216
+ actions: [() => [{
217
+ type: "insert text",
218
+ text: " "
219
+ }], (_, {
220
+ focusTextBlock,
221
+ focusSpan,
222
+ listItem
223
+ }) => [{
224
+ type: "unset block",
225
+ props: ["style"],
226
+ paths: [focusTextBlock.path]
227
+ }, {
228
+ type: "set block",
229
+ listItem,
230
+ level: 1,
231
+ paths: [focusTextBlock.path]
232
+ }, {
233
+ type: "delete",
234
+ selection: {
235
+ anchor: {
236
+ path: focusSpan.path,
237
+ offset: 0
238
+ },
239
+ focus: {
240
+ path: focusSpan.path,
241
+ offset: focusSpan.node.text.length + 1
242
+ }
243
+ }
244
+ }]]
245
+ };
246
+ return [automaticStyleOnSpace, clearStyleOnBackspace, automaticListOnSpace];
247
+ }
8
248
  const rootName = "sanity-pte:";
9
249
  debug__default.default(rootName);
10
250
  function debugWithName(name) {
@@ -414,15 +654,15 @@ const debug$l = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
414
654
  element,
415
655
  readOnly,
416
656
  blockRef
417
- } = t0, editor = slateReact.useSlateStatic(), dragGhostRef = react.useRef(), [isDragOver, setIsDragOver] = react.useState(!1);
657
+ } = t0, editor = slateReact.useSlateStatic(), dragGhostRef = require$$0.useRef(), [isDragOver, setIsDragOver] = require$$0.useState(!1);
418
658
  let t1, t2;
419
659
  $[0] !== editor || $[1] !== element ? (t2 = slate.Editor.isVoid(editor, element), $[0] = editor, $[1] = element, $[2] = t2) : t2 = $[2], t1 = t2;
420
660
  const isVoid = t1;
421
661
  let t3, t4;
422
662
  $[3] !== editor || $[4] !== element ? (t4 = slate.Editor.isInline(editor, element), $[3] = editor, $[4] = element, $[5] = t4) : t4 = $[5], t3 = t4;
423
- const isInline = t3, [blockElement, setBlockElement] = react.useState(null);
663
+ const isInline = t3, [blockElement, setBlockElement] = require$$0.useState(null);
424
664
  let t5, t6;
425
- $[6] !== blockRef || $[7] !== editor || $[8] !== element ? (t5 = () => setBlockElement(blockRef ? blockRef.current : slateReact.ReactEditor.toDOMNode(editor, element)), t6 = [editor, element, blockRef], $[6] = blockRef, $[7] = editor, $[8] = element, $[9] = t5, $[10] = t6) : (t5 = $[9], t6 = $[10]), react.useEffect(t5, t6);
665
+ $[6] !== blockRef || $[7] !== editor || $[8] !== element ? (t5 = () => setBlockElement(blockRef ? blockRef.current : slateReact.ReactEditor.toDOMNode(editor, element)), t6 = [editor, element, blockRef], $[6] = blockRef, $[7] = editor, $[8] = element, $[9] = t5, $[10] = t6) : (t5 = $[9], t6 = $[10]), require$$0.useEffect(t5, t6);
426
666
  let t7;
427
667
  $[11] !== editor || $[12] !== blockElement || $[13] !== element ? (t7 = (event) => {
428
668
  const isMyDragOver = IS_DRAGGING_BLOCK_ELEMENT.get(editor);
@@ -553,9 +793,9 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
553
793
  renderStyle,
554
794
  spellCheck
555
795
  }) => {
556
- const editor = slateReact.useSlateStatic(), selected = slateReact.useSelected(), blockRef = react.useRef(null), inlineBlockObjectRef = react.useRef(null), focused = selected && editor.selection && slate.Range.isCollapsed(editor.selection) || !1, value = react.useMemo(() => fromSlateValue([element], schemaTypes.block.name, KEY_TO_VALUE_ELEMENT.get(editor))[0], [editor, element, schemaTypes.block.name]);
796
+ const editor = slateReact.useSlateStatic(), selected = slateReact.useSelected(), blockRef = require$$0.useRef(null), inlineBlockObjectRef = require$$0.useRef(null), focused = selected && editor.selection && slate.Range.isCollapsed(editor.selection) || !1, value = require$$0.useMemo(() => fromSlateValue([element], schemaTypes.block.name, KEY_TO_VALUE_ELEMENT.get(editor))[0], [editor, element, schemaTypes.block.name]);
557
797
  let renderedBlock = children, className;
558
- const blockPath = react.useMemo(() => [{
798
+ const blockPath = require$$0.useMemo(() => [{
559
799
  _key: element._key
560
800
  }], [element]);
561
801
  if (typeof element._type != "string")
@@ -676,8 +916,8 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
676
916
  ] }, element._key);
677
917
  };
678
918
  Element.displayName = "Element";
679
- const PortableTextEditorContext = react.createContext(null), usePortableTextEditor = () => {
680
- const editor = react.useContext(PortableTextEditorContext);
919
+ const PortableTextEditorContext = require$$0.createContext(null), usePortableTextEditor = () => {
920
+ const editor = require$$0.useContext(PortableTextEditorContext);
681
921
  if (!editor)
682
922
  throw new Error("The `usePortableTextEditor` hook must be used inside the <PortableTextEditor> component's context.");
683
923
  return editor;
@@ -694,307 +934,66 @@ function DefaultAnnotation(props) {
694
934
  let t2;
695
935
  return $[3] !== handleClick || $[4] !== props.children ? (t2 = /* @__PURE__ */ jsxRuntime.jsx("span", { style: t1, onClick: handleClick, children: props.children }), $[3] = handleClick, $[4] = props.children, $[5] = t2) : t2 = $[5], t2;
696
936
  }
697
- DefaultAnnotation.displayName = "DefaultAnnotation";
698
- function getPortableTextMemberSchemaTypes(portableTextType) {
699
- if (!portableTextType)
700
- throw new Error("Parameter 'portabletextType' missing (required)");
701
- const blockType = portableTextType.of?.find(findBlockType);
702
- if (!blockType)
703
- throw new Error("Block type is not defined in this schema (required)");
704
- const childrenField = blockType.fields?.find((field) => field.name === "children");
705
- if (!childrenField)
706
- throw new Error("Children field for block type found in schema (required)");
707
- const ofType = childrenField.type.of;
708
- if (!ofType)
709
- throw new Error("Valid types for block children not found in schema (required)");
710
- const spanType = ofType.find((memberType) => memberType.name === "span");
711
- if (!spanType)
712
- throw new Error("Span type not found in schema (required)");
713
- const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = portableTextType.of?.filter((field) => field.name !== blockType.name) || [];
714
- return {
715
- styles: resolveEnabledStyles(blockType),
716
- decorators: resolveEnabledDecorators(spanType),
717
- lists: resolveEnabledListItems(blockType),
718
- block: blockType,
719
- span: spanType,
720
- portableText: portableTextType,
721
- inlineObjects: inlineObjectTypes,
722
- blockObjects: blockObjectTypes,
723
- annotations: spanType.annotations
724
- };
725
- }
726
- function resolveEnabledStyles(blockType) {
727
- const styleField = blockType.fields?.find((btField) => btField.name === "style");
728
- if (!styleField)
729
- throw new Error("A field with name 'style' is not defined in the block type (required).");
730
- const textStyles = styleField.type.options?.list && styleField.type.options.list?.filter((style) => style.value);
731
- if (!textStyles || textStyles.length === 0)
732
- throw new Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");
733
- return textStyles;
734
- }
735
- function resolveEnabledDecorators(spanType) {
736
- return spanType.decorators;
737
- }
738
- function resolveEnabledListItems(blockType) {
739
- const listField = blockType.fields?.find((btField) => btField.name === "listItem");
740
- if (!listField)
741
- throw new Error("A field with name 'listItem' is not defined in the block type (required).");
742
- const listItems = listField.type.options?.list && listField.type.options.list.filter((list) => list.value);
743
- if (!listItems)
744
- throw new Error("The list field need at least to be an empty array");
745
- return listItems;
746
- }
747
- function findBlockType(type) {
748
- return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
749
- }
750
- function compileType(rawType) {
751
- return schema.Schema.compile({
752
- name: "blockTypeSchema",
753
- types: [rawType]
754
- }).get(rawType.name);
755
- }
756
- function selectionIsCollapsed(context) {
757
- return context.selection?.anchor.path.join() === context.selection?.focus.path.join() && context.selection?.anchor.offset === context.selection?.focus.offset;
758
- }
759
- function getFocusBlock(context) {
760
- const key = context.selection && types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
761
- return node && key ? {
762
- node,
763
- path: [{
764
- _key: key
765
- }]
766
- } : void 0;
767
- }
768
- function getFocusTextBlock(context) {
769
- const focusBlock = getFocusBlock(context);
770
- return focusBlock && types.isPortableTextTextBlock(focusBlock.node) ? {
771
- node: focusBlock.node,
772
- path: focusBlock.path
773
- } : void 0;
774
- }
775
- function getFocusBlockObject(context) {
776
- const focusBlock = getFocusBlock(context);
777
- return focusBlock && !types.isPortableTextTextBlock(focusBlock.node) ? {
778
- node: focusBlock.node,
779
- path: focusBlock.path
780
- } : void 0;
781
- }
782
- function getFocusChild(context) {
783
- const focusBlock = getFocusTextBlock(context);
784
- if (!focusBlock)
785
- return;
786
- const key = context.selection && types.isKeySegment(context.selection.focus.path[2]) ? context.selection.focus.path[2]._key : void 0, node = key ? focusBlock.node.children.find((span) => span._key === key) : void 0;
787
- return node && key ? {
788
- node,
789
- path: [...focusBlock.path, "children", {
790
- _key: key
791
- }]
792
- } : void 0;
793
- }
794
- function getFocusSpan(context) {
795
- const focusChild = getFocusChild(context);
796
- return focusChild && types.isPortableTextSpan(focusChild.node) ? {
797
- node: focusChild.node,
798
- path: focusChild.path
799
- } : void 0;
800
- }
801
- function getSelectionStartBlock(context) {
802
- const key = context.selection.backward ? types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0 : types.isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
803
- return node && key ? {
804
- node,
805
- path: [{
806
- _key: key
807
- }]
808
- } : void 0;
809
- }
810
- function getSelectionEndBlock(context) {
811
- const key = context.selection.backward ? types.isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0 : types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
812
- return node && key ? {
813
- node,
814
- path: [{
815
- _key: key
816
- }]
817
- } : void 0;
818
- }
819
- function getPreviousBlock(context) {
820
- let previousBlock;
821
- const selectionStartBlock = getSelectionStartBlock(context);
822
- if (!selectionStartBlock)
823
- return;
824
- let foundSelectionStartBlock = !1;
825
- for (const block of context.value) {
826
- if (block._key === selectionStartBlock.node._key) {
827
- foundSelectionStartBlock = !0;
828
- break;
829
- }
830
- previousBlock = {
831
- node: block,
832
- path: [{
833
- _key: block._key
834
- }]
835
- };
836
- }
837
- if (foundSelectionStartBlock && previousBlock)
838
- return previousBlock;
839
- }
840
- function getNextBlock(context) {
841
- let nextBlock;
842
- const selectionEndBlock = getSelectionEndBlock(context);
843
- if (!selectionEndBlock)
844
- return;
845
- let foundSelectionEndBlock = !1;
846
- for (const block of context.value) {
847
- if (block._key === selectionEndBlock.node._key) {
848
- foundSelectionEndBlock = !0;
849
- continue;
850
- }
851
- if (foundSelectionEndBlock) {
852
- nextBlock = {
853
- node: block,
854
- path: [{
855
- _key: block._key
856
- }]
857
- };
858
- break;
859
- }
860
- }
861
- if (foundSelectionEndBlock && nextBlock)
862
- return nextBlock;
863
- }
864
- function isEmptyTextBlock(block) {
865
- return block.children.length === 1 && block.children[0].text === "";
866
- }
867
- const breakingVoidBlock = {
868
- on: "insert break",
869
- guard: ({
870
- context
871
- }) => !!getFocusBlockObject(context),
872
- actions: [() => [{
873
- type: "insert text block",
874
- decorators: []
875
- }]]
876
- }, deletingEmptyTextBlockAfterBlockObject = {
877
- on: "delete backward",
878
- guard: ({
879
- context
880
- }) => {
881
- const focusTextBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context), previousBlock = getPreviousBlock(context);
882
- return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !types.isPortableTextTextBlock(previousBlock.node) ? {
883
- focusTextBlock,
884
- previousBlock
885
- } : !1;
886
- },
887
- actions: [(_, {
888
- focusTextBlock,
889
- previousBlock
890
- }) => [{
891
- type: "delete",
892
- selection: {
893
- anchor: {
894
- path: focusTextBlock.path,
895
- offset: 0
896
- },
897
- focus: {
898
- path: focusTextBlock.path,
899
- offset: 0
900
- }
901
- }
902
- }, {
903
- type: "select",
904
- selection: {
905
- anchor: {
906
- path: previousBlock.path,
907
- offset: 0
908
- },
909
- focus: {
910
- path: previousBlock.path,
911
- offset: 0
912
- }
913
- }
914
- }]]
915
- }, deletingEmptyTextBlockBeforeBlockObject = {
916
- on: "delete forward",
917
- guard: ({
918
- context
919
- }) => {
920
- const focusTextBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context), nextBlock = getNextBlock(context);
921
- return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !types.isPortableTextTextBlock(nextBlock.node) ? {
922
- focusTextBlock,
923
- nextBlock
924
- } : !1;
925
- },
926
- actions: [(_, {
927
- focusTextBlock,
928
- nextBlock
929
- }) => [{
930
- type: "delete",
931
- selection: {
932
- anchor: {
933
- path: focusTextBlock.path,
934
- offset: 0
935
- },
936
- focus: {
937
- path: focusTextBlock.path,
938
- offset: 0
939
- }
940
- }
941
- }, {
942
- type: "select",
943
- selection: {
944
- anchor: {
945
- path: nextBlock.path,
946
- offset: 0
947
- },
948
- focus: {
949
- path: nextBlock.path,
950
- offset: 0
951
- }
952
- }
953
- }]]
954
- }, coreBlockObjectBehaviors = [breakingVoidBlock, deletingEmptyTextBlockAfterBlockObject, deletingEmptyTextBlockBeforeBlockObject], clearListOnBackspace = {
955
- on: "delete backward",
956
- guard: ({
957
- context
958
- }) => {
959
- const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
960
- return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
961
- focusTextBlock
962
- } : !1;
963
- },
964
- actions: [(_, {
965
- focusTextBlock
966
- }) => [{
967
- type: "unset block",
968
- props: ["listItem", "level"],
969
- paths: [focusTextBlock.path]
970
- }]]
971
- }, unindentListOnBackspace = {
972
- on: "delete backward",
973
- guard: ({
974
- context
975
- }) => {
976
- const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
977
- return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level !== void 0 && focusTextBlock.node.level > 1 ? {
978
- focusTextBlock,
979
- level: focusTextBlock.node.level - 1
980
- } : !1;
981
- },
982
- actions: [(_, {
983
- focusTextBlock,
984
- level
985
- }) => [{
986
- type: "set block",
987
- level,
988
- paths: [focusTextBlock.path]
989
- }]]
990
- }, coreListBehaviors = [clearListOnBackspace, unindentListOnBackspace], softReturn = {
991
- on: "insert soft break",
992
- actions: [() => [{
993
- type: "insert text",
994
- text: `
995
- `
996
- }]]
997
- }, coreBehaviors = [softReturn, ...coreBlockObjectBehaviors, ...coreListBehaviors], debug$k = debugWithName("operationToPatches");
937
+ DefaultAnnotation.displayName = "DefaultAnnotation";
938
+ function getPortableTextMemberSchemaTypes(portableTextType) {
939
+ if (!portableTextType)
940
+ throw new Error("Parameter 'portabletextType' missing (required)");
941
+ const blockType = portableTextType.of?.find(findBlockType);
942
+ if (!blockType)
943
+ throw new Error("Block type is not defined in this schema (required)");
944
+ const childrenField = blockType.fields?.find((field) => field.name === "children");
945
+ if (!childrenField)
946
+ throw new Error("Children field for block type found in schema (required)");
947
+ const ofType = childrenField.type.of;
948
+ if (!ofType)
949
+ throw new Error("Valid types for block children not found in schema (required)");
950
+ const spanType = ofType.find((memberType) => memberType.name === "span");
951
+ if (!spanType)
952
+ throw new Error("Span type not found in schema (required)");
953
+ const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = portableTextType.of?.filter((field) => field.name !== blockType.name) || [];
954
+ return {
955
+ styles: resolveEnabledStyles(blockType),
956
+ decorators: resolveEnabledDecorators(spanType),
957
+ lists: resolveEnabledListItems(blockType),
958
+ block: blockType,
959
+ span: spanType,
960
+ portableText: portableTextType,
961
+ inlineObjects: inlineObjectTypes,
962
+ blockObjects: blockObjectTypes,
963
+ annotations: spanType.annotations
964
+ };
965
+ }
966
+ function resolveEnabledStyles(blockType) {
967
+ const styleField = blockType.fields?.find((btField) => btField.name === "style");
968
+ if (!styleField)
969
+ throw new Error("A field with name 'style' is not defined in the block type (required).");
970
+ const textStyles = styleField.type.options?.list && styleField.type.options.list?.filter((style) => style.value);
971
+ if (!textStyles || textStyles.length === 0)
972
+ throw new Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");
973
+ return textStyles;
974
+ }
975
+ function resolveEnabledDecorators(spanType) {
976
+ return spanType.decorators;
977
+ }
978
+ function resolveEnabledListItems(blockType) {
979
+ const listField = blockType.fields?.find((btField) => btField.name === "listItem");
980
+ if (!listField)
981
+ throw new Error("A field with name 'listItem' is not defined in the block type (required).");
982
+ const listItems = listField.type.options?.list && listField.type.options.list.filter((list) => list.value);
983
+ if (!listItems)
984
+ throw new Error("The list field need at least to be an empty array");
985
+ return listItems;
986
+ }
987
+ function findBlockType(type) {
988
+ return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
989
+ }
990
+ function compileType(rawType) {
991
+ return schema.Schema.compile({
992
+ name: "blockTypeSchema",
993
+ types: [rawType]
994
+ }).get(rawType.name);
995
+ }
996
+ const debug$k = debugWithName("operationToPatches");
998
997
  function createOperationToPatches(types2) {
999
998
  const textBlockName = types2.block.name;
1000
999
  function insertTextPatch(editor, operation, beforeValue) {
@@ -2681,9 +2680,9 @@ function debugState(editor, stateName) {
2681
2680
  }
2682
2681
  function findBlockFromPath(editor, path) {
2683
2682
  let blockIndex = -1;
2684
- const block = editor.children.find((node, index) => {
2685
- const isMatch = isKeyedSegment(path[0]) ? node._key === path[0]._key : index === path[0];
2686
- return isMatch && (blockIndex = index), isMatch;
2683
+ const block = editor.children.find((node, index2) => {
2684
+ const isMatch = isKeyedSegment(path[0]) ? node._key === path[0]._key : index2 === path[0];
2685
+ return isMatch && (blockIndex = index2), isMatch;
2687
2686
  });
2688
2687
  return block ? {
2689
2688
  block,
@@ -2703,9 +2702,9 @@ function findBlockAndChildFromPath(editor, path) {
2703
2702
  childPath: void 0
2704
2703
  };
2705
2704
  let childIndex = -1;
2706
- const child = block.children.find((node, index) => {
2707
- const isMatch = isKeyedSegment(path[2]) ? node._key === path[2]._key : index === path[2];
2708
- return isMatch && (childIndex = index), isMatch;
2705
+ const child = block.children.find((node, index2) => {
2706
+ const isMatch = isKeyedSegment(path[2]) ? node._key === path[2]._key : index2 === path[2];
2707
+ return isMatch && (childIndex = index2), isMatch;
2709
2708
  });
2710
2709
  return child ? {
2711
2710
  block,
@@ -2902,9 +2901,9 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
2902
2901
  const {
2903
2902
  diffs
2904
2903
  } = diffPatch;
2905
- if (diffs.forEach((diff2, index) => {
2904
+ if (diffs.forEach((diff2, index2) => {
2906
2905
  const [diffType, text] = diff2;
2907
- diffType === DIFF_INSERT ? (adjustOffsetBy += text.length, changedOffset += text.length) : diffType === DIFF_DELETE ? (adjustOffsetBy -= text.length, changedOffset -= text.length) : diffType === DIFF_EQUAL && (diffs.slice(index).every(([dType]) => dType === DIFF_EQUAL) || (changedOffset += text.length));
2906
+ diffType === DIFF_INSERT ? (adjustOffsetBy += text.length, changedOffset += text.length) : diffType === DIFF_DELETE ? (adjustOffsetBy -= text.length, changedOffset -= text.length) : diffType === DIFF_EQUAL && (diffs.slice(index2).every(([dType]) => dType === DIFF_EQUAL) || (changedOffset += text.length));
2908
2907
  }), transformedOperation.type === "insert_text" && changedOffset < transformedOperation.offset && (transformedOperation.offset += adjustOffsetBy), transformedOperation.type === "remove_text" && changedOffset <= transformedOperation.offset - transformedOperation.text.length && (transformedOperation.offset += adjustOffsetBy), transformedOperation.type === "set_selection") {
2909
2908
  const currentFocus = transformedOperation.properties?.focus ? {
2910
2909
  ...transformedOperation.properties.focus
@@ -3998,10 +3997,10 @@ function validateValue(value, types$1, keyGenerator) {
3998
3997
  }
3999
3998
  },
4000
3999
  value
4001
- } : (value.some((blk, index) => {
4000
+ } : (value.some((blk, index2) => {
4002
4001
  if (!isPlainObject__default.default(blk))
4003
4002
  return resolution = {
4004
- patches: [patches.unset([index])],
4003
+ patches: [patches.unset([index2])],
4005
4004
  description: `Block must be an object, got ${String(blk)}`,
4006
4005
  action: "Unset invalid item",
4007
4006
  item: blk,
@@ -4009,7 +4008,7 @@ function validateValue(value, types$1, keyGenerator) {
4009
4008
  description: "inputs.portable-text.invalid-value.not-an-object.description",
4010
4009
  action: "inputs.portable-text.invalid-value.not-an-object.action",
4011
4010
  values: {
4012
- index
4011
+ index: index2
4013
4012
  }
4014
4013
  }
4015
4014
  }, !0;
@@ -4018,15 +4017,15 @@ function validateValue(value, types$1, keyGenerator) {
4018
4017
  patches: [patches.set({
4019
4018
  ...blk,
4020
4019
  _key: keyGenerator()
4021
- }, [index])],
4022
- description: `Block at index ${index} is missing required _key.`,
4020
+ }, [index2])],
4021
+ description: `Block at index ${index2} is missing required _key.`,
4023
4022
  action: "Set the block with a random _key value",
4024
4023
  item: blk,
4025
4024
  i18n: {
4026
4025
  description: "inputs.portable-text.invalid-value.missing-key.description",
4027
4026
  action: "inputs.portable-text.invalid-value.missing-key.action",
4028
4027
  values: {
4029
- index
4028
+ index: index2
4030
4029
  }
4031
4030
  }
4032
4031
  }, !0;
@@ -4583,14 +4582,14 @@ function SlateContainer(props) {
4583
4582
  });
4584
4583
  return KEY_TO_VALUE_ELEMENT.set(editor, {}), KEY_TO_SLATE_ELEMENT.set(editor, {}), [editor, _sub];
4585
4584
  }, $[0] = editorActor, $[1] = maxBlocks, $[2] = portableTextEditor, $[3] = readOnly, $[4] = t0) : t0 = $[4];
4586
- const [t1] = react.useState(t0), [slateEditor, subscribe] = t1;
4585
+ const [t1] = require$$0.useState(t0), [slateEditor, subscribe] = t1;
4587
4586
  let t2, t3;
4588
4587
  $[5] !== subscribe ? (t2 = () => {
4589
4588
  const unsubscribe = subscribe();
4590
4589
  return () => {
4591
4590
  unsubscribe();
4592
4591
  };
4593
- }, t3 = [subscribe], $[5] = subscribe, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]), react.useEffect(t2, t3);
4592
+ }, t3 = [subscribe], $[5] = subscribe, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]), require$$0.useEffect(t2, t3);
4594
4593
  let t4, t5;
4595
4594
  $[8] !== slateEditor || $[9] !== editorActor || $[10] !== maxBlocks || $[11] !== portableTextEditor || $[12] !== readOnly ? (t4 = () => {
4596
4595
  debug$6("Re-initializing plugin chain"), withPlugins(slateEditor, {
@@ -4599,7 +4598,7 @@ function SlateContainer(props) {
4599
4598
  portableTextEditor,
4600
4599
  readOnly
4601
4600
  });
4602
- }, t5 = [editorActor, portableTextEditor, maxBlocks, readOnly, slateEditor], $[8] = slateEditor, $[9] = editorActor, $[10] = maxBlocks, $[11] = portableTextEditor, $[12] = readOnly, $[13] = t4, $[14] = t5) : (t4 = $[13], t5 = $[14]), react.useEffect(t4, t5);
4601
+ }, t5 = [editorActor, portableTextEditor, maxBlocks, readOnly, slateEditor], $[8] = slateEditor, $[9] = editorActor, $[10] = maxBlocks, $[11] = portableTextEditor, $[12] = readOnly, $[13] = t4, $[14] = t5) : (t4 = $[13], t5 = $[14]), require$$0.useEffect(t4, t5);
4603
4602
  let t6, t7;
4604
4603
  $[15] !== slateEditor ? (t7 = slateEditor.pteCreateTextBlock({
4605
4604
  decorators: []
@@ -4610,13 +4609,13 @@ function SlateContainer(props) {
4610
4609
  let t9, t10;
4611
4610
  $[19] !== slateEditor ? (t9 = () => () => {
4612
4611
  debug$6("Destroying Slate editor"), slateEditor.destroy();
4613
- }, t10 = [slateEditor], $[19] = slateEditor, $[20] = t9, $[21] = t10) : (t9 = $[20], t10 = $[21]), react.useEffect(t9, t10);
4612
+ }, t10 = [slateEditor], $[19] = slateEditor, $[20] = t9, $[21] = t10) : (t9 = $[20], t10 = $[21]), require$$0.useEffect(t9, t10);
4614
4613
  let t11;
4615
4614
  return $[22] !== slateEditor || $[23] !== initialValue || $[24] !== props.children ? (t11 = /* @__PURE__ */ jsxRuntime.jsx(slateReact.Slate, { editor: slateEditor, initialValue, children: props.children }), $[22] = slateEditor, $[23] = initialValue, $[24] = props.children, $[25] = t11) : t11 = $[25], t11;
4616
4615
  }
4617
4616
  SlateContainer.displayName = "SlateContainer";
4618
- const PortableTextEditorReadOnlyContext = react.createContext(!1), usePortableTextEditorReadOnlyStatus = () => {
4619
- const readOnly = react.useContext(PortableTextEditorReadOnlyContext);
4617
+ const PortableTextEditorReadOnlyContext = require$$0.createContext(!1), usePortableTextEditorReadOnlyStatus = () => {
4618
+ const readOnly = require$$0.useContext(PortableTextEditorReadOnlyContext);
4620
4619
  if (readOnly === void 0)
4621
4620
  throw new Error("The `usePortableTextEditorReadOnly` hook must be used inside the <PortableTextEditor> component's context.");
4622
4621
  return readOnly;
@@ -4626,18 +4625,18 @@ function useSyncValue(props) {
4626
4625
  editorActor,
4627
4626
  portableTextEditor,
4628
4627
  readOnly
4629
- } = props, schemaTypes = editorActor.getSnapshot().context.schema, previousValue = react.useRef(), slateEditor = slateReact.useSlate(), updateValueFunctionRef = react.useRef(), updateFromCurrentValue = react.useCallback(() => {
4628
+ } = props, schemaTypes = editorActor.getSnapshot().context.schema, previousValue = require$$0.useRef(), slateEditor = slateReact.useSlate(), updateValueFunctionRef = require$$0.useRef(), updateFromCurrentValue = require$$0.useCallback(() => {
4630
4629
  const currentValue = CURRENT_VALUE.get(portableTextEditor);
4631
4630
  if (previousValue.current === currentValue) {
4632
4631
  debug$5("Value is the same object as previous, not need to sync");
4633
4632
  return;
4634
4633
  }
4635
4634
  updateValueFunctionRef.current && currentValue && (debug$5("Updating the value debounced"), updateValueFunctionRef.current(currentValue));
4636
- }, [portableTextEditor]), updateValueDebounced = react.useMemo(() => debounce__default.default(updateFromCurrentValue, 1e3, {
4635
+ }, [portableTextEditor]), updateValueDebounced = require$$0.useMemo(() => debounce__default.default(updateFromCurrentValue, 1e3, {
4637
4636
  trailing: !0,
4638
4637
  leading: !1
4639
4638
  }), [updateFromCurrentValue]);
4640
- return react.useMemo(() => {
4639
+ return require$$0.useMemo(() => {
4641
4640
  const updateFunction = (value) => {
4642
4641
  CURRENT_VALUE.set(portableTextEditor, value);
4643
4642
  const isProcessingLocalChanges = isChangingLocally(slateEditor), isProcessingRemoteChanges = isChangingRemotely(slateEditor);
@@ -4658,9 +4657,9 @@ function useSyncValue(props) {
4658
4657
  withoutPatching(slateEditor, () => {
4659
4658
  hadSelection && slate.Transforms.deselect(slateEditor);
4660
4659
  const childrenLength = slateEditor.children.length;
4661
- slateEditor.children.forEach((_, index) => {
4660
+ slateEditor.children.forEach((_, index2) => {
4662
4661
  slate.Transforms.removeNodes(slateEditor, {
4663
- at: [childrenLength - 1 - index]
4662
+ at: [childrenLength - 1 - index2]
4664
4663
  });
4665
4664
  }), slate.Transforms.insertNodes(slateEditor, slateEditor.pteCreateTextBlock({
4666
4665
  decorators: []
@@ -4765,8 +4764,8 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
4765
4764
  at: [currentBlockIndex]
4766
4765
  }), slateEditor.isTextBlock(currentBlock) && slateEditor.isTextBlock(oldBlock)) {
4767
4766
  const oldBlockChildrenLength = oldBlock.children.length;
4768
- currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
4769
- const childIndex = oldBlockChildrenLength - 1 - index;
4767
+ currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index2) => {
4768
+ const childIndex = oldBlockChildrenLength - 1 - index2;
4770
4769
  childIndex > 0 && (debug$5("Removing child"), slate.Transforms.removeNodes(slateEditor, {
4771
4770
  at: [currentBlockIndex, childIndex]
4772
4771
  }));
@@ -4817,7 +4816,7 @@ function Synchronizer(props) {
4817
4816
  } = props;
4818
4817
  let t0;
4819
4818
  $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = [], $[0] = t0) : t0 = $[0];
4820
- const pendingPatches = react.useRef(t0);
4819
+ const pendingPatches = require$$0.useRef(t0);
4821
4820
  let t1;
4822
4821
  $[1] !== editorActor || $[2] !== portableTextEditor || $[3] !== readOnly ? (t1 = {
4823
4822
  editorActor,
@@ -4828,7 +4827,7 @@ function Synchronizer(props) {
4828
4827
  let t2, t3;
4829
4828
  $[5] !== slateEditor ? (t2 = () => {
4830
4829
  IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !1);
4831
- }, t3 = [slateEditor], $[5] = slateEditor, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]), react.useEffect(t2, t3);
4830
+ }, t3 = [slateEditor], $[5] = slateEditor, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]), require$$0.useEffect(t2, t3);
4832
4831
  let t4;
4833
4832
  $[8] !== getValue || $[9] !== editorActor || $[10] !== slateEditor ? (t4 = () => {
4834
4833
  if (pendingPatches.current.length > 0) {
@@ -4847,7 +4846,7 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
4847
4846
  let t5, t6;
4848
4847
  $[12] !== onFlushPendingPatches ? (t5 = () => () => {
4849
4848
  onFlushPendingPatches();
4850
- }, t6 = [onFlushPendingPatches], $[12] = onFlushPendingPatches, $[13] = t5, $[14] = t6) : (t5 = $[13], t6 = $[14]), react.useEffect(t5, t6);
4849
+ }, t6 = [onFlushPendingPatches], $[12] = onFlushPendingPatches, $[13] = t5, $[14] = t6) : (t5 = $[13], t6 = $[14]), require$$0.useEffect(t5, t6);
4851
4850
  let t7;
4852
4851
  $[15] !== onChange ? (t7 = (change) => onChange(change), $[15] = onChange, $[16] = t7) : t7 = $[16];
4853
4852
  const handleChange = useEffectEvent.useEffectEvent(t7);
@@ -4929,7 +4928,7 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
4929
4928
  return () => {
4930
4929
  debug$4("Unsubscribing to changes"), sub.unsubscribe();
4931
4930
  };
4932
- }, t9 = [editorActor, handleChange, onFlushPendingPatches, slateEditor], $[17] = slateEditor, $[18] = onFlushPendingPatches, $[19] = editorActor, $[20] = handleChange, $[21] = t8, $[22] = t9) : (t8 = $[21], t9 = $[22]), react.useEffect(t8, t9);
4931
+ }, t9 = [editorActor, handleChange, onFlushPendingPatches, slateEditor], $[17] = slateEditor, $[18] = onFlushPendingPatches, $[19] = editorActor, $[20] = handleChange, $[21] = t8, $[22] = t9) : (t8 = $[21], t9 = $[22]), require$$0.useEffect(t8, t9);
4933
4932
  let t10;
4934
4933
  $[23] !== syncValue || $[24] !== value ? (t10 = () => {
4935
4934
  debug$4("Editor is online, syncing from props.value"), syncValue(value);
@@ -4941,17 +4940,17 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
4941
4940
  return () => {
4942
4941
  subscription.unsubscribe();
4943
4942
  };
4944
- }, t12 = [handleOnline, editorActor], $[26] = editorActor, $[27] = handleOnline, $[28] = t11, $[29] = t12) : (t11 = $[28], t12 = $[29]), react.useEffect(t11, t12);
4945
- const isInitialValueFromProps = react.useRef(!0);
4943
+ }, t12 = [handleOnline, editorActor], $[26] = editorActor, $[27] = handleOnline, $[28] = t11, $[29] = t12) : (t11 = $[28], t12 = $[29]), require$$0.useEffect(t11, t12);
4944
+ const isInitialValueFromProps = require$$0.useRef(!0);
4946
4945
  let t13, t14;
4947
4946
  return $[30] !== syncValue || $[31] !== value || $[32] !== editorActor ? (t13 = () => {
4948
4947
  debug$4("Value from props changed, syncing new value"), syncValue(value), isInitialValueFromProps.current && (editorActor.send({
4949
4948
  type: "ready"
4950
4949
  }), isInitialValueFromProps.current = !1);
4951
- }, t14 = [editorActor, syncValue, value], $[30] = syncValue, $[31] = value, $[32] = editorActor, $[33] = t13, $[34] = t14) : (t13 = $[33], t14 = $[34]), react.useEffect(t13, t14), null;
4950
+ }, t14 = [editorActor, syncValue, value], $[30] = syncValue, $[31] = value, $[32] = editorActor, $[33] = t13, $[34] = t14) : (t13 = $[33], t14 = $[34]), require$$0.useEffect(t13, t14), null;
4952
4951
  }
4953
4952
  Synchronizer.displayName = "Synchronizer";
4954
- const EditorActorContext = react.createContext({}), insertBreakActionImplementation = ({
4953
+ const EditorActorContext = require$$0.createContext({}), insertBreakActionImplementation = ({
4955
4954
  context,
4956
4955
  action
4957
4956
  }) => {
@@ -5263,7 +5262,137 @@ function performDefaultAction({
5263
5262
  });
5264
5263
  }
5265
5264
  }
5266
- const networkLogic = xstate.fromCallback(({
5265
+ const breakingVoidBlock = {
5266
+ on: "insert break",
5267
+ guard: ({
5268
+ context
5269
+ }) => !!getFocusBlockObject(context),
5270
+ actions: [() => [{
5271
+ type: "insert text block",
5272
+ decorators: []
5273
+ }]]
5274
+ }, deletingEmptyTextBlockAfterBlockObject = {
5275
+ on: "delete backward",
5276
+ guard: ({
5277
+ context
5278
+ }) => {
5279
+ const focusTextBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context), previousBlock = getPreviousBlock(context);
5280
+ return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !types.isPortableTextTextBlock(previousBlock.node) ? {
5281
+ focusTextBlock,
5282
+ previousBlock
5283
+ } : !1;
5284
+ },
5285
+ actions: [(_, {
5286
+ focusTextBlock,
5287
+ previousBlock
5288
+ }) => [{
5289
+ type: "delete",
5290
+ selection: {
5291
+ anchor: {
5292
+ path: focusTextBlock.path,
5293
+ offset: 0
5294
+ },
5295
+ focus: {
5296
+ path: focusTextBlock.path,
5297
+ offset: 0
5298
+ }
5299
+ }
5300
+ }, {
5301
+ type: "select",
5302
+ selection: {
5303
+ anchor: {
5304
+ path: previousBlock.path,
5305
+ offset: 0
5306
+ },
5307
+ focus: {
5308
+ path: previousBlock.path,
5309
+ offset: 0
5310
+ }
5311
+ }
5312
+ }]]
5313
+ }, deletingEmptyTextBlockBeforeBlockObject = {
5314
+ on: "delete forward",
5315
+ guard: ({
5316
+ context
5317
+ }) => {
5318
+ const focusTextBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context), nextBlock = getNextBlock(context);
5319
+ return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !types.isPortableTextTextBlock(nextBlock.node) ? {
5320
+ focusTextBlock,
5321
+ nextBlock
5322
+ } : !1;
5323
+ },
5324
+ actions: [(_, {
5325
+ focusTextBlock,
5326
+ nextBlock
5327
+ }) => [{
5328
+ type: "delete",
5329
+ selection: {
5330
+ anchor: {
5331
+ path: focusTextBlock.path,
5332
+ offset: 0
5333
+ },
5334
+ focus: {
5335
+ path: focusTextBlock.path,
5336
+ offset: 0
5337
+ }
5338
+ }
5339
+ }, {
5340
+ type: "select",
5341
+ selection: {
5342
+ anchor: {
5343
+ path: nextBlock.path,
5344
+ offset: 0
5345
+ },
5346
+ focus: {
5347
+ path: nextBlock.path,
5348
+ offset: 0
5349
+ }
5350
+ }
5351
+ }]]
5352
+ }, coreBlockObjectBehaviors = [breakingVoidBlock, deletingEmptyTextBlockAfterBlockObject, deletingEmptyTextBlockBeforeBlockObject], clearListOnBackspace = {
5353
+ on: "delete backward",
5354
+ guard: ({
5355
+ context
5356
+ }) => {
5357
+ const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
5358
+ return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
5359
+ focusTextBlock
5360
+ } : !1;
5361
+ },
5362
+ actions: [(_, {
5363
+ focusTextBlock
5364
+ }) => [{
5365
+ type: "unset block",
5366
+ props: ["listItem", "level"],
5367
+ paths: [focusTextBlock.path]
5368
+ }]]
5369
+ }, unindentListOnBackspace = {
5370
+ on: "delete backward",
5371
+ guard: ({
5372
+ context
5373
+ }) => {
5374
+ const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
5375
+ return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level !== void 0 && focusTextBlock.node.level > 1 ? {
5376
+ focusTextBlock,
5377
+ level: focusTextBlock.node.level - 1
5378
+ } : !1;
5379
+ },
5380
+ actions: [(_, {
5381
+ focusTextBlock,
5382
+ level
5383
+ }) => [{
5384
+ type: "set block",
5385
+ level,
5386
+ paths: [focusTextBlock.path]
5387
+ }]]
5388
+ }, coreListBehaviors = [clearListOnBackspace, unindentListOnBackspace], softReturn = {
5389
+ on: "insert soft break",
5390
+ actions: [() => [{
5391
+ type: "insert text",
5392
+ text: `
5393
+ `
5394
+ }]]
5395
+ }, coreBehaviors = [softReturn, ...coreBlockObjectBehaviors, ...coreListBehaviors], networkLogic = xstate.fromCallback(({
5267
5396
  sendBack
5268
5397
  }) => {
5269
5398
  const onlineHandler = () => {
@@ -5286,6 +5415,11 @@ const networkLogic = xstate.fromCallback(({
5286
5415
  input: {}
5287
5416
  },
5288
5417
  actions: {
5418
+ "assign behaviors": xstate.assign({
5419
+ behaviors: ({
5420
+ event
5421
+ }) => (xstate.assertEvent(event, "update behaviors"), [...coreBehaviors, ...event.behaviors])
5422
+ }),
5289
5423
  "assign schema": xstate.assign({
5290
5424
  schema: ({
5291
5425
  event
@@ -5378,7 +5512,7 @@ const networkLogic = xstate.fromCallback(({
5378
5512
  context: ({
5379
5513
  input
5380
5514
  }) => ({
5381
- behaviors: input.behaviors,
5515
+ behaviors: input.behaviors ? [...coreBehaviors, ...input.behaviors] : coreBehaviors,
5382
5516
  keyGenerator: input.keyGenerator,
5383
5517
  pendingEvents: [],
5384
5518
  schema: input.schema
@@ -5453,6 +5587,9 @@ const networkLogic = xstate.fromCallback(({
5453
5587
  type: "done loading"
5454
5588
  })
5455
5589
  },
5590
+ "update behaviors": {
5591
+ actions: "assign behaviors"
5592
+ },
5456
5593
  "update schema": {
5457
5594
  actions: "assign schema"
5458
5595
  },
@@ -5526,31 +5663,31 @@ const networkLogic = xstate.fromCallback(({
5526
5663
  }
5527
5664
  }
5528
5665
  }
5529
- }), PortableTextEditorSelectionContext = react.createContext(null), usePortableTextEditorSelection = () => {
5530
- const selection = react.useContext(PortableTextEditorSelectionContext);
5666
+ }), PortableTextEditorSelectionContext = require$$0.createContext(null), usePortableTextEditorSelection = () => {
5667
+ const selection = require$$0.useContext(PortableTextEditorSelectionContext);
5531
5668
  if (selection === void 0)
5532
5669
  throw new Error("The `usePortableTextEditorSelection` hook must be used inside the <PortableTextEditor> component's context.");
5533
5670
  return selection;
5534
5671
  }, debug$3 = debugWithName("component:PortableTextEditor:SelectionProvider"), debugVerbose = debug$3.enabled && !1;
5535
5672
  function PortableTextEditorSelectionProvider(props) {
5536
- const $ = reactCompilerRuntime.c(6), [selection, setSelection] = react.useState(null);
5673
+ const $ = reactCompilerRuntime.c(6), [selection, setSelection] = require$$0.useState(null);
5537
5674
  let t0, t1;
5538
5675
  $[0] !== props.editorActor ? (t0 = () => {
5539
5676
  debug$3("Subscribing to selection changes");
5540
5677
  const subscription = props.editorActor.on("selection", (event) => {
5541
- react.startTransition(() => {
5678
+ require$$0.startTransition(() => {
5542
5679
  debugVerbose && debug$3("Setting selection"), setSelection(event.selection);
5543
5680
  });
5544
5681
  });
5545
5682
  return () => {
5546
5683
  debug$3("Unsubscribing to selection changes"), subscription.unsubscribe();
5547
5684
  };
5548
- }, t1 = [props.editorActor], $[0] = props.editorActor, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), react.useEffect(t0, t1);
5685
+ }, t1 = [props.editorActor], $[0] = props.editorActor, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), require$$0.useEffect(t0, t1);
5549
5686
  let t2;
5550
5687
  return $[3] !== selection || $[4] !== props.children ? (t2 = /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorSelectionContext.Provider, { value: selection, children: props.children }), $[3] = selection, $[4] = props.children, $[5] = t2) : t2 = $[5], t2;
5551
5688
  }
5552
5689
  const defaultKeyGenerator = () => content.randomKey(12), debug$2 = debugWithName("component:PortableTextEditor");
5553
- class PortableTextEditor extends react.Component {
5690
+ class PortableTextEditor extends require$$0.Component {
5554
5691
  static displayName = "PortableTextEditor";
5555
5692
  /**
5556
5693
  * An observable of all the editor changes.
@@ -5563,18 +5700,21 @@ class PortableTextEditor extends react.Component {
5563
5700
  * The editor API (currently implemented with Slate).
5564
5701
  */
5565
5702
  constructor(props) {
5566
- if (super(props), !props.schemaType)
5567
- throw new Error('PortableTextEditor: missing "schemaType" property');
5568
- props.incomingPatches$ && console.warn("The prop 'incomingPatches$' is deprecated and renamed to 'patches$'"), this.schemaTypes = getPortableTextMemberSchemaTypes(props.schemaType.hasOwnProperty("jsonType") ? props.schemaType : compileType(props.schemaType)), this.editorActor = xstate.createActor(editorMachine, {
5569
- input: {
5570
- behaviors: coreBehaviors,
5571
- keyGenerator: props.keyGenerator || defaultKeyGenerator,
5572
- schema: this.schemaTypes
5573
- }
5574
- }), this.editorActor.start();
5703
+ if (super(props), props.editor)
5704
+ this.editorActor = props.editor, this.editorActor.start(), this.schemaTypes = this.editorActor.getSnapshot().context.schema;
5705
+ else {
5706
+ if (!props.schemaType)
5707
+ throw new Error('PortableTextEditor: missing "schemaType" property');
5708
+ props.incomingPatches$ && console.warn("The prop 'incomingPatches$' is deprecated and renamed to 'patches$'"), this.schemaTypes = getPortableTextMemberSchemaTypes(props.schemaType.hasOwnProperty("jsonType") ? props.schemaType : compileType(props.schemaType)), this.editorActor = props.editor ?? xstate.createActor(editorMachine, {
5709
+ input: {
5710
+ keyGenerator: props.keyGenerator || defaultKeyGenerator,
5711
+ schema: this.schemaTypes
5712
+ }
5713
+ }), this.editorActor.start();
5714
+ }
5575
5715
  }
5576
5716
  componentDidUpdate(prevProps) {
5577
- this.props.schemaType !== prevProps.schemaType && (this.schemaTypes = getPortableTextMemberSchemaTypes(this.props.schemaType.hasOwnProperty("jsonType") ? this.props.schemaType : compileType(this.props.schemaType)), this.editorActor.send({
5717
+ !this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && (this.schemaTypes = getPortableTextMemberSchemaTypes(this.props.schemaType.hasOwnProperty("jsonType") ? this.props.schemaType : compileType(this.props.schemaType)), this.editorActor.send({
5578
5718
  type: "update schema",
5579
5719
  schema: this.schemaTypes
5580
5720
  })), this.props.editorRef !== prevProps.editorRef && this.props.editorRef && (this.props.editorRef.current = this);
@@ -5590,19 +5730,14 @@ class PortableTextEditor extends react.Component {
5590
5730
  return this.editable.getValue();
5591
5731
  };
5592
5732
  render() {
5593
- const {
5594
- value,
5595
- children,
5596
- patches$,
5597
- incomingPatches$
5598
- } = this.props, _patches$ = incomingPatches$ || patches$, maxBlocks = typeof this.props.maxBlocks > "u" ? void 0 : Number.parseInt(this.props.maxBlocks.toString(), 10) || void 0, readOnly = !!this.props.readOnly;
5733
+ const maxBlocks = this.props.editor || typeof this.props.maxBlocks > "u" ? void 0 : Number.parseInt(this.props.maxBlocks.toString(), 10) || void 0, readOnly = !!this.props.readOnly, legacyPatches = this.props.editor ? void 0 : this.props.incomingPatches$ ?? this.props.patches$;
5599
5734
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5600
- _patches$ ? /* @__PURE__ */ jsxRuntime.jsx(RoutePatchesObservableToEditorActor, { editorActor: this.editorActor, patches$: _patches$ }) : null,
5735
+ legacyPatches ? /* @__PURE__ */ jsxRuntime.jsx(RoutePatchesObservableToEditorActor, { editorActor: this.editorActor, patches$: legacyPatches }) : null,
5601
5736
  /* @__PURE__ */ jsxRuntime.jsx(EditorActorContext.Provider, { value: this.editorActor, children: /* @__PURE__ */ jsxRuntime.jsx(SlateContainer, { editorActor: this.editorActor, maxBlocks, portableTextEditor: this, readOnly, children: /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorContext.Provider, { value: this, children: /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorReadOnlyContext.Provider, { value: readOnly, children: /* @__PURE__ */ jsxRuntime.jsxs(PortableTextEditorSelectionProvider, { editorActor: this.editorActor, children: [
5602
5737
  /* @__PURE__ */ jsxRuntime.jsx(Synchronizer, { editorActor: this.editorActor, getValue: this.getValue, onChange: (change) => {
5603
- this.props.onChange(change), this.change$.next(change);
5604
- }, value }),
5605
- children
5738
+ this.props.editor || this.props.onChange(change), this.change$.next(change);
5739
+ }, value: this.props.value }),
5740
+ this.props.children
5606
5741
  ] }) }) }) }) })
5607
5742
  ] });
5608
5743
  }
@@ -5669,7 +5804,7 @@ function RoutePatchesObservableToEditorActor(props) {
5669
5804
  return () => {
5670
5805
  subscription.unsubscribe();
5671
5806
  };
5672
- }, t1 = [props.editorActor, props.patches$], $[0] = props.patches$, $[1] = props.editorActor, $[2] = t0, $[3] = t1) : (t0 = $[2], t1 = $[3]), react.useEffect(t0, t1), null;
5807
+ }, t1 = [props.editorActor, props.patches$], $[0] = props.patches$, $[1] = props.editorActor, $[2] = t0, $[3] = t1) : (t0 = $[2], t1 = $[3]), require$$0.useEffect(t0, t1), null;
5673
5808
  }
5674
5809
  const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (props) => {
5675
5810
  const {
@@ -5681,22 +5816,22 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
5681
5816
  renderChild,
5682
5817
  renderDecorator,
5683
5818
  renderAnnotation
5684
- } = props, spanRef = react.useRef(null), portableTextEditor = usePortableTextEditor(), blockSelected = slateReact.useSelected(), [focused, setFocused] = react.useState(!1), [selected, setSelected] = react.useState(!1), block = children.props.parent, path = react.useMemo(() => block ? [{
5819
+ } = props, spanRef = require$$0.useRef(null), portableTextEditor = usePortableTextEditor(), blockSelected = slateReact.useSelected(), [focused, setFocused] = require$$0.useState(!1), [selected, setSelected] = require$$0.useState(!1), block = children.props.parent, path = require$$0.useMemo(() => block ? [{
5685
5820
  _key: block?._key
5686
5821
  }, "children", {
5687
5822
  _key: leaf._key
5688
- }] : [], [block, leaf._key]), decoratorValues = react.useMemo(() => schemaTypes.decorators.map((dec) => dec.value), [schemaTypes.decorators]), marks = react.useMemo(() => uniq__default.default((leaf.marks || EMPTY_MARKS).filter((mark) => decoratorValues.includes(mark))), [decoratorValues, leaf.marks]), annotationMarks = Array.isArray(leaf.marks) ? leaf.marks : EMPTY_MARKS, annotations = react.useMemo(() => annotationMarks.map((mark_0) => !decoratorValues.includes(mark_0) && block?.markDefs?.find((def) => def._key === mark_0)).filter(Boolean), [annotationMarks, block, decoratorValues]), shouldTrackSelectionAndFocus = annotations.length > 0 && blockSelected;
5689
- react.useEffect(() => {
5823
+ }] : [], [block, leaf._key]), decoratorValues = require$$0.useMemo(() => schemaTypes.decorators.map((dec) => dec.value), [schemaTypes.decorators]), marks = require$$0.useMemo(() => uniq__default.default((leaf.marks || EMPTY_MARKS).filter((mark) => decoratorValues.includes(mark))), [decoratorValues, leaf.marks]), annotationMarks = Array.isArray(leaf.marks) ? leaf.marks : EMPTY_MARKS, annotations = require$$0.useMemo(() => annotationMarks.map((mark_0) => !decoratorValues.includes(mark_0) && block?.markDefs?.find((def) => def._key === mark_0)).filter(Boolean), [annotationMarks, block, decoratorValues]), shouldTrackSelectionAndFocus = annotations.length > 0 && blockSelected;
5824
+ require$$0.useEffect(() => {
5690
5825
  if (!shouldTrackSelectionAndFocus) {
5691
5826
  setFocused(!1);
5692
5827
  return;
5693
5828
  }
5694
5829
  const sel = PortableTextEditor.getSelection(portableTextEditor);
5695
- sel && isEqual__default.default(sel.focus.path, path) && PortableTextEditor.isCollapsedSelection(portableTextEditor) && react.startTransition(() => {
5830
+ sel && isEqual__default.default(sel.focus.path, path) && PortableTextEditor.isCollapsedSelection(portableTextEditor) && require$$0.startTransition(() => {
5696
5831
  setFocused(!0);
5697
5832
  });
5698
5833
  }, [shouldTrackSelectionAndFocus, path, portableTextEditor]);
5699
- const setSelectedFromRange = react.useCallback(() => {
5834
+ const setSelectedFromRange = require$$0.useCallback(() => {
5700
5835
  if (!shouldTrackSelectionAndFocus)
5701
5836
  return;
5702
5837
  debug$1("Setting selection and focus from range");
@@ -5711,7 +5846,7 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
5711
5846
  } else
5712
5847
  setSelected(!1);
5713
5848
  }, [shouldTrackSelectionAndFocus]);
5714
- react.useEffect(() => {
5849
+ require$$0.useEffect(() => {
5715
5850
  if (!shouldTrackSelectionAndFocus)
5716
5851
  return;
5717
5852
  const onBlur = editorActor.on("blur", () => {
@@ -5725,8 +5860,8 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
5725
5860
  return () => {
5726
5861
  onBlur.unsubscribe(), onFocus.unsubscribe(), onSelection.unsubscribe();
5727
5862
  };
5728
- }, [editorActor, path, portableTextEditor, setSelectedFromRange, shouldTrackSelectionAndFocus]), react.useEffect(() => setSelectedFromRange(), [setSelectedFromRange]);
5729
- const content2 = react.useMemo(() => {
5863
+ }, [editorActor, path, portableTextEditor, setSelectedFromRange, shouldTrackSelectionAndFocus]), require$$0.useEffect(() => setSelectedFromRange(), [setSelectedFromRange]);
5864
+ const content2 = require$$0.useMemo(() => {
5730
5865
  let returnedChildren = children;
5731
5866
  if (slate.Text.isText(leaf) && leaf._type === schemaTypes.span.name && (marks.forEach((mark_1) => {
5732
5867
  const schemaType = schemaTypes.decorators.find((dec_0) => dec_0.value === mark_1);
@@ -5792,7 +5927,7 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
5792
5927
  }
5793
5928
  return returnedChildren;
5794
5929
  }, [annotations, block, children, focused, leaf, marks, path, renderAnnotation, renderChild, renderDecorator, schemaTypes.annotations, schemaTypes.decorators, schemaTypes.span, selected]);
5795
- return react.useMemo(() => /* @__PURE__ */ jsxRuntime.jsx("span", { ...attributes, ref: spanRef, children: content2 }, leaf._key), [leaf, attributes, content2]);
5930
+ return require$$0.useMemo(() => /* @__PURE__ */ jsxRuntime.jsx("span", { ...attributes, ref: spanRef, children: content2 }, leaf._key), [leaf, attributes, content2]);
5796
5931
  };
5797
5932
  Leaf.displayName = "Leaf";
5798
5933
  const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
@@ -5801,7 +5936,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
5801
5936
  pointerEvents: "none",
5802
5937
  left: 0,
5803
5938
  right: 0
5804
- }, PortableTextEditable = react.forwardRef(function(props, forwardedRef) {
5939
+ }, PortableTextEditable = require$$0.forwardRef(function(props, forwardedRef) {
5805
5940
  const {
5806
5941
  hotkeys,
5807
5942
  onBlur,
@@ -5822,13 +5957,13 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
5822
5957
  scrollSelectionIntoView,
5823
5958
  spellCheck,
5824
5959
  ...restProps
5825
- } = props, portableTextEditor = usePortableTextEditor(), readOnly = usePortableTextEditorReadOnlyStatus(), ref = react.useRef(null), [editableElement, setEditableElement] = react.useState(null), [hasInvalidValue, setHasInvalidValue] = react.useState(!1), [rangeDecorationState, setRangeDecorationsState] = react.useState([]);
5826
- react.useImperativeHandle(forwardedRef, () => ref.current);
5827
- const rangeDecorationsRef = react.useRef(rangeDecorations), editorActor = react.useContext(EditorActorContext), {
5960
+ } = props, portableTextEditor = usePortableTextEditor(), readOnly = usePortableTextEditorReadOnlyStatus(), ref = require$$0.useRef(null), [editableElement, setEditableElement] = require$$0.useState(null), [hasInvalidValue, setHasInvalidValue] = require$$0.useState(!1), [rangeDecorationState, setRangeDecorationsState] = require$$0.useState([]);
5961
+ require$$0.useImperativeHandle(forwardedRef, () => ref.current);
5962
+ const rangeDecorationsRef = require$$0.useRef(rangeDecorations), editorActor = require$$0.useContext(EditorActorContext), {
5828
5963
  schemaTypes
5829
- } = portableTextEditor, slateEditor = slateReact.useSlate(), blockTypeName = schemaTypes.block.name, withInsertData = react.useMemo(() => createWithInsertData(editorActor, schemaTypes), [editorActor, schemaTypes]), withHotKeys = react.useMemo(() => createWithHotkeys(portableTextEditor, hotkeys), [hotkeys, portableTextEditor]);
5830
- react.useMemo(() => readOnly ? (debug("Editable is in read only mode"), withInsertData(slateEditor)) : (debug("Editable is in edit mode"), withInsertData(withHotKeys(slateEditor))), [readOnly, slateEditor, withHotKeys, withInsertData]);
5831
- const renderElement = react.useCallback((eProps) => /* @__PURE__ */ jsxRuntime.jsx(Element, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, schemaTypes, spellCheck }), [schemaTypes, spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = react.useCallback((lProps) => {
5964
+ } = portableTextEditor, slateEditor = slateReact.useSlate(), blockTypeName = schemaTypes.block.name, withInsertData = require$$0.useMemo(() => createWithInsertData(editorActor, schemaTypes), [editorActor, schemaTypes]), withHotKeys = require$$0.useMemo(() => createWithHotkeys(portableTextEditor, hotkeys), [hotkeys, portableTextEditor]);
5965
+ require$$0.useMemo(() => readOnly ? (debug("Editable is in read only mode"), withInsertData(slateEditor)) : (debug("Editable is in edit mode"), withInsertData(withHotKeys(slateEditor))), [readOnly, slateEditor, withHotKeys, withInsertData]);
5966
+ const renderElement = require$$0.useCallback((eProps) => /* @__PURE__ */ jsxRuntime.jsx(Element, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, schemaTypes, spellCheck }), [schemaTypes, spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = require$$0.useCallback((lProps) => {
5832
5967
  if (lProps.leaf._type === "span") {
5833
5968
  let rendered = /* @__PURE__ */ jsxRuntime.jsx(Leaf, { ...lProps, editorActor, schemaTypes, renderAnnotation, renderChild, renderDecorator, readOnly });
5834
5969
  if (renderPlaceholder && lProps.leaf.placeholder && lProps.text.text === "")
@@ -5842,7 +5977,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
5842
5977
  })), rendered;
5843
5978
  }
5844
5979
  return lProps.children;
5845
- }, [editorActor, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder, schemaTypes]), restoreSelectionFromProps = react.useCallback(() => {
5980
+ }, [editorActor, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder, schemaTypes]), restoreSelectionFromProps = require$$0.useCallback(() => {
5846
5981
  if (propsSelection) {
5847
5982
  debug(`Selection from props ${JSON.stringify(propsSelection)}`);
5848
5983
  const normalizedSelection = normalizeSelection(propsSelection, fromSlateValue(slateEditor.children, blockTypeName));
@@ -5855,7 +5990,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
5855
5990
  }), slateEditor.onChange());
5856
5991
  }
5857
5992
  }
5858
- }, [blockTypeName, editorActor, propsSelection, slateEditor]), syncRangeDecorations = react.useCallback((operation) => {
5993
+ }, [blockTypeName, editorActor, propsSelection, slateEditor]), syncRangeDecorations = require$$0.useCallback((operation) => {
5859
5994
  if (rangeDecorations && rangeDecorations.length > 0) {
5860
5995
  const newSlateRanges = [];
5861
5996
  if (rangeDecorations.forEach((rangeDecorationItem) => {
@@ -5888,7 +6023,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
5888
6023
  }
5889
6024
  setRangeDecorationsState((rangeDecorationState_0) => rangeDecorationState_0.length > 0 ? [] : rangeDecorationState_0);
5890
6025
  }, [portableTextEditor, rangeDecorations, schemaTypes, slateEditor]);
5891
- react.useEffect(() => {
6026
+ require$$0.useEffect(() => {
5892
6027
  const onReady = editorActor.on("ready", () => {
5893
6028
  restoreSelectionFromProps();
5894
6029
  }), onInvalidValue = editorActor.on("invalid value", () => {
@@ -5899,22 +6034,22 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
5899
6034
  return () => {
5900
6035
  onReady.unsubscribe(), onInvalidValue.unsubscribe(), onValueChanged.unsubscribe();
5901
6036
  };
5902
- }, [editorActor, restoreSelectionFromProps]), react.useEffect(() => {
6037
+ }, [editorActor, restoreSelectionFromProps]), require$$0.useEffect(() => {
5903
6038
  propsSelection && !hasInvalidValue && restoreSelectionFromProps();
5904
6039
  }, [hasInvalidValue, propsSelection, restoreSelectionFromProps]);
5905
- const originalApply = react.useMemo(() => slateEditor.apply, [slateEditor]), [syncedRangeDecorations, setSyncedRangeDecorations] = react.useState(!1);
5906
- react.useEffect(() => {
6040
+ const originalApply = require$$0.useMemo(() => slateEditor.apply, [slateEditor]), [syncedRangeDecorations, setSyncedRangeDecorations] = require$$0.useState(!1);
6041
+ require$$0.useEffect(() => {
5907
6042
  syncedRangeDecorations || (setSyncedRangeDecorations(!0), syncRangeDecorations());
5908
- }, [syncRangeDecorations, syncedRangeDecorations]), react.useEffect(() => {
6043
+ }, [syncRangeDecorations, syncedRangeDecorations]), require$$0.useEffect(() => {
5909
6044
  isEqual__default.default(rangeDecorations, rangeDecorationsRef.current) || syncRangeDecorations(), rangeDecorationsRef.current = rangeDecorations;
5910
- }, [rangeDecorations, syncRangeDecorations]), react.useEffect(() => (slateEditor.apply = (op) => {
6045
+ }, [rangeDecorations, syncRangeDecorations]), require$$0.useEffect(() => (slateEditor.apply = (op) => {
5911
6046
  originalApply(op), op.type !== "set_selection" && syncRangeDecorations(op);
5912
6047
  }, () => {
5913
6048
  slateEditor.apply = originalApply;
5914
6049
  }), [originalApply, slateEditor, syncRangeDecorations]);
5915
- const handleCopy = react.useCallback((event) => {
6050
+ const handleCopy = require$$0.useCallback((event) => {
5916
6051
  onCopy && onCopy(event) !== void 0 && event.preventDefault();
5917
- }, [onCopy]), handlePaste = react.useCallback((event_0) => {
6052
+ }, [onCopy]), handlePaste = require$$0.useCallback((event_0) => {
5918
6053
  if (event_0.preventDefault(), !slateEditor.selection)
5919
6054
  return;
5920
6055
  if (!onPaste) {
@@ -5938,7 +6073,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
5938
6073
  type: "done loading"
5939
6074
  });
5940
6075
  }));
5941
- }, [editorActor, onPaste, portableTextEditor, schemaTypes, slateEditor]), handleOnFocus = react.useCallback((event_1) => {
6076
+ }, [editorActor, onPaste, portableTextEditor, schemaTypes, slateEditor]), handleOnFocus = require$$0.useCallback((event_1) => {
5942
6077
  if (onFocus && onFocus(event_1), !event_1.isDefaultPrevented()) {
5943
6078
  const selection = PortableTextEditor.getSelection(portableTextEditor);
5944
6079
  selection === null && (slate.Transforms.select(slateEditor, slate.Editor.start(slateEditor, [])), slateEditor.onChange()), editorActor.send({
@@ -5951,7 +6086,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
5951
6086
  selection
5952
6087
  });
5953
6088
  }
5954
- }, [editorActor, onFocus, portableTextEditor, slateEditor]), handleClick = react.useCallback((event_2) => {
6089
+ }, [editorActor, onFocus, portableTextEditor, slateEditor]), handleClick = require$$0.useCallback((event_2) => {
5955
6090
  if (onClick && onClick(event_2), slateEditor.selection && event_2.target === event_2.currentTarget) {
5956
6091
  const [lastBlock, path_0] = slate.Node.last(slateEditor, []), focusPath = slateEditor.selection.focus.path.slice(0, 1), lastPath = path_0.slice(0, 1);
5957
6092
  if (slate.Path.equals(focusPath, lastPath)) {
@@ -5961,14 +6096,14 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
5961
6096
  })), slateEditor.onChange());
5962
6097
  }
5963
6098
  }
5964
- }, [onClick, slateEditor]), handleOnBlur = react.useCallback((event_3) => {
6099
+ }, [onClick, slateEditor]), handleOnBlur = require$$0.useCallback((event_3) => {
5965
6100
  onBlur && onBlur(event_3), event_3.isPropagationStopped() || editorActor.send({
5966
6101
  type: "blur",
5967
6102
  event: event_3
5968
6103
  });
5969
- }, [editorActor, onBlur]), handleOnBeforeInput = react.useCallback((event_4) => {
6104
+ }, [editorActor, onBlur]), handleOnBeforeInput = require$$0.useCallback((event_4) => {
5970
6105
  onBeforeInput && onBeforeInput(event_4);
5971
- }, [onBeforeInput]), validateSelection = react.useCallback(() => {
6106
+ }, [onBeforeInput]), validateSelection = require$$0.useCallback(() => {
5972
6107
  if (!slateEditor.selection)
5973
6108
  return;
5974
6109
  const root = slateReact.ReactEditor.findDocumentOrShadowRoot(slateEditor), {
@@ -5987,7 +6122,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
5987
6122
  debug("Could not resolve selection, selecting top document"), slate.Transforms.deselect(slateEditor), slateEditor.children.length > 0 && slate.Transforms.select(slateEditor, [0, 0]), slateEditor.onChange();
5988
6123
  }
5989
6124
  }, [ref, slateEditor]);
5990
- react.useEffect(() => {
6125
+ require$$0.useEffect(() => {
5991
6126
  if (editableElement) {
5992
6127
  const mutationObserver = new MutationObserver(validateSelection);
5993
6128
  return mutationObserver.observe(editableElement, {
@@ -6001,14 +6136,14 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
6001
6136
  };
6002
6137
  }
6003
6138
  }, [validateSelection, editableElement]);
6004
- const handleKeyDown = react.useCallback((event_5) => {
6139
+ const handleKeyDown = require$$0.useCallback((event_5) => {
6005
6140
  props.onKeyDown && props.onKeyDown(event_5), event_5.isDefaultPrevented() || slateEditor.pteWithHotKeys(event_5);
6006
- }, [props, slateEditor]), scrollSelectionIntoViewToSlate = react.useMemo(() => {
6141
+ }, [props, slateEditor]), scrollSelectionIntoViewToSlate = require$$0.useMemo(() => {
6007
6142
  if (scrollSelectionIntoView !== void 0)
6008
6143
  return scrollSelectionIntoView === null ? noop__default.default : (_editor, domRange) => {
6009
6144
  scrollSelectionIntoView(portableTextEditor, domRange);
6010
6145
  };
6011
- }, [portableTextEditor, scrollSelectionIntoView]), decorate = react.useCallback(([, path_1]) => {
6146
+ }, [portableTextEditor, scrollSelectionIntoView]), decorate = require$$0.useCallback(([, path_1]) => {
6012
6147
  if (isEqualToEmptyEditor(slateEditor.children, schemaTypes))
6013
6148
  return [{
6014
6149
  anchor: {
@@ -6035,7 +6170,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
6035
6170
  }) || slate.Range.includes(item, path_1));
6036
6171
  return result_1.length > 0 ? result_1 : [];
6037
6172
  }, [slateEditor, schemaTypes, rangeDecorationState]);
6038
- return react.useEffect(() => {
6173
+ return require$$0.useEffect(() => {
6039
6174
  ref.current = slateReact.ReactEditor.toDOMNode(slateEditor, slateEditor), setEditableElement(ref.current);
6040
6175
  }, [slateEditor, ref]), portableTextEditor ? hasInvalidValue ? null : /* @__PURE__ */ jsxRuntime.jsx(
6041
6176
  slateReact.Editable,
@@ -6060,10 +6195,333 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
6060
6195
  ) : null;
6061
6196
  });
6062
6197
  PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
6198
+ var index = typeof document < "u" ? require$$0.useLayoutEffect : require$$0.useEffect, withSelector = { exports: {} }, withSelector_production_min = {}, shim = { exports: {} }, useSyncExternalStoreShim_production_min = {};
6199
+ /**
6200
+ * @license React
6201
+ * use-sync-external-store-shim.production.min.js
6202
+ *
6203
+ * Copyright (c) Facebook, Inc. and its affiliates.
6204
+ *
6205
+ * This source code is licensed under the MIT license found in the
6206
+ * LICENSE file in the root directory of this source tree.
6207
+ */
6208
+ var hasRequiredUseSyncExternalStoreShim_production_min;
6209
+ function requireUseSyncExternalStoreShim_production_min() {
6210
+ if (hasRequiredUseSyncExternalStoreShim_production_min) return useSyncExternalStoreShim_production_min;
6211
+ hasRequiredUseSyncExternalStoreShim_production_min = 1;
6212
+ var e = require$$0__default.default;
6213
+ function h(a, b) {
6214
+ return a === b && (a !== 0 || 1 / a === 1 / b) || a !== a && b !== b;
6215
+ }
6216
+ var k = typeof Object.is == "function" ? Object.is : h, l = e.useState, m = e.useEffect, n = e.useLayoutEffect, p = e.useDebugValue;
6217
+ function q(a, b) {
6218
+ var d = b(), f = l({
6219
+ inst: {
6220
+ value: d,
6221
+ getSnapshot: b
6222
+ }
6223
+ }), c = f[0].inst, g = f[1];
6224
+ return n(function() {
6225
+ c.value = d, c.getSnapshot = b, r(c) && g({
6226
+ inst: c
6227
+ });
6228
+ }, [a, d, b]), m(function() {
6229
+ return r(c) && g({
6230
+ inst: c
6231
+ }), a(function() {
6232
+ r(c) && g({
6233
+ inst: c
6234
+ });
6235
+ });
6236
+ }, [a]), p(d), d;
6237
+ }
6238
+ function r(a) {
6239
+ var b = a.getSnapshot;
6240
+ a = a.value;
6241
+ try {
6242
+ var d = b();
6243
+ return !k(a, d);
6244
+ } catch {
6245
+ return !0;
6246
+ }
6247
+ }
6248
+ function t(a, b) {
6249
+ return b();
6250
+ }
6251
+ var u = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? t : q;
6252
+ return useSyncExternalStoreShim_production_min.useSyncExternalStore = e.useSyncExternalStore !== void 0 ? e.useSyncExternalStore : u, useSyncExternalStoreShim_production_min;
6253
+ }
6254
+ var useSyncExternalStoreShim_development = {};
6255
+ /**
6256
+ * @license React
6257
+ * use-sync-external-store-shim.development.js
6258
+ *
6259
+ * Copyright (c) Facebook, Inc. and its affiliates.
6260
+ *
6261
+ * This source code is licensed under the MIT license found in the
6262
+ * LICENSE file in the root directory of this source tree.
6263
+ */
6264
+ var hasRequiredUseSyncExternalStoreShim_development;
6265
+ function requireUseSyncExternalStoreShim_development() {
6266
+ return hasRequiredUseSyncExternalStoreShim_development || (hasRequiredUseSyncExternalStoreShim_development = 1, process.env.NODE_ENV !== "production" && function() {
6267
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
6268
+ var React = require$$0__default.default, ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
6269
+ function error(format) {
6270
+ {
6271
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++)
6272
+ args[_key2 - 1] = arguments[_key2];
6273
+ printWarning("error", format, args);
6274
+ }
6275
+ }
6276
+ function printWarning(level, format, args) {
6277
+ {
6278
+ var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame, stack = ReactDebugCurrentFrame.getStackAddendum();
6279
+ stack !== "" && (format += "%s", args = args.concat([stack]));
6280
+ var argsWithFormat = args.map(function(item) {
6281
+ return String(item);
6282
+ });
6283
+ argsWithFormat.unshift("Warning: " + format), Function.prototype.apply.call(console[level], console, argsWithFormat);
6284
+ }
6285
+ }
6286
+ function is(x, y) {
6287
+ return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
6288
+ }
6289
+ var objectIs = typeof Object.is == "function" ? Object.is : is, useState = React.useState, useEffect = React.useEffect, useLayoutEffect = React.useLayoutEffect, useDebugValue = React.useDebugValue, didWarnOld18Alpha = !1, didWarnUncachedGetSnapshot = !1;
6290
+ function useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
6291
+ didWarnOld18Alpha || React.startTransition !== void 0 && (didWarnOld18Alpha = !0, error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));
6292
+ var value = getSnapshot();
6293
+ if (!didWarnUncachedGetSnapshot) {
6294
+ var cachedValue = getSnapshot();
6295
+ objectIs(value, cachedValue) || (error("The result of getSnapshot should be cached to avoid an infinite loop"), didWarnUncachedGetSnapshot = !0);
6296
+ }
6297
+ var _useState = useState({
6298
+ inst: {
6299
+ value,
6300
+ getSnapshot
6301
+ }
6302
+ }), inst = _useState[0].inst, forceUpdate = _useState[1];
6303
+ return useLayoutEffect(function() {
6304
+ inst.value = value, inst.getSnapshot = getSnapshot, checkIfSnapshotChanged(inst) && forceUpdate({
6305
+ inst
6306
+ });
6307
+ }, [subscribe, value, getSnapshot]), useEffect(function() {
6308
+ checkIfSnapshotChanged(inst) && forceUpdate({
6309
+ inst
6310
+ });
6311
+ var handleStoreChange = function() {
6312
+ checkIfSnapshotChanged(inst) && forceUpdate({
6313
+ inst
6314
+ });
6315
+ };
6316
+ return subscribe(handleStoreChange);
6317
+ }, [subscribe]), useDebugValue(value), value;
6318
+ }
6319
+ function checkIfSnapshotChanged(inst) {
6320
+ var latestGetSnapshot = inst.getSnapshot, prevValue = inst.value;
6321
+ try {
6322
+ var nextValue = latestGetSnapshot();
6323
+ return !objectIs(prevValue, nextValue);
6324
+ } catch {
6325
+ return !0;
6326
+ }
6327
+ }
6328
+ function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
6329
+ return getSnapshot();
6330
+ }
6331
+ var canUseDOM = typeof window < "u" && typeof window.document < "u" && typeof window.document.createElement < "u", isServerEnvironment = !canUseDOM, shim2 = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore, useSyncExternalStore$2 = React.useSyncExternalStore !== void 0 ? React.useSyncExternalStore : shim2;
6332
+ useSyncExternalStoreShim_development.useSyncExternalStore = useSyncExternalStore$2, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
6333
+ }()), useSyncExternalStoreShim_development;
6334
+ }
6335
+ var hasRequiredShim;
6336
+ function requireShim() {
6337
+ return hasRequiredShim || (hasRequiredShim = 1, process.env.NODE_ENV === "production" ? shim.exports = requireUseSyncExternalStoreShim_production_min() : shim.exports = requireUseSyncExternalStoreShim_development()), shim.exports;
6338
+ }
6339
+ /**
6340
+ * @license React
6341
+ * use-sync-external-store-shim/with-selector.production.min.js
6342
+ *
6343
+ * Copyright (c) Facebook, Inc. and its affiliates.
6344
+ *
6345
+ * This source code is licensed under the MIT license found in the
6346
+ * LICENSE file in the root directory of this source tree.
6347
+ */
6348
+ var hasRequiredWithSelector_production_min;
6349
+ function requireWithSelector_production_min() {
6350
+ if (hasRequiredWithSelector_production_min) return withSelector_production_min;
6351
+ hasRequiredWithSelector_production_min = 1;
6352
+ var h = require$$0__default.default, n = requireShim();
6353
+ function p(a, b) {
6354
+ return a === b && (a !== 0 || 1 / a === 1 / b) || a !== a && b !== b;
6355
+ }
6356
+ var q = typeof Object.is == "function" ? Object.is : p, r = n.useSyncExternalStore, t = h.useRef, u = h.useEffect, v = h.useMemo, w = h.useDebugValue;
6357
+ return withSelector_production_min.useSyncExternalStoreWithSelector = function(a, b, e, l, g) {
6358
+ var c = t(null);
6359
+ if (c.current === null) {
6360
+ var f = {
6361
+ hasValue: !1,
6362
+ value: null
6363
+ };
6364
+ c.current = f;
6365
+ } else f = c.current;
6366
+ c = v(function() {
6367
+ function a2(a3) {
6368
+ if (!c2) {
6369
+ if (c2 = !0, d2 = a3, a3 = l(a3), g !== void 0 && f.hasValue) {
6370
+ var b2 = f.value;
6371
+ if (g(b2, a3)) return k = b2;
6372
+ }
6373
+ return k = a3;
6374
+ }
6375
+ if (b2 = k, q(d2, a3)) return b2;
6376
+ var e2 = l(a3);
6377
+ return g !== void 0 && g(b2, e2) ? b2 : (d2 = a3, k = e2);
6378
+ }
6379
+ var c2 = !1, d2, k, m = e === void 0 ? null : e;
6380
+ return [function() {
6381
+ return a2(b());
6382
+ }, m === null ? void 0 : function() {
6383
+ return a2(m());
6384
+ }];
6385
+ }, [b, e, l, g]);
6386
+ var d = r(a, c[0], c[1]);
6387
+ return u(function() {
6388
+ f.hasValue = !0, f.value = d;
6389
+ }, [d]), w(d), d;
6390
+ }, withSelector_production_min;
6391
+ }
6392
+ var withSelector_development = {};
6393
+ /**
6394
+ * @license React
6395
+ * use-sync-external-store-shim/with-selector.development.js
6396
+ *
6397
+ * Copyright (c) Facebook, Inc. and its affiliates.
6398
+ *
6399
+ * This source code is licensed under the MIT license found in the
6400
+ * LICENSE file in the root directory of this source tree.
6401
+ */
6402
+ var hasRequiredWithSelector_development;
6403
+ function requireWithSelector_development() {
6404
+ return hasRequiredWithSelector_development || (hasRequiredWithSelector_development = 1, process.env.NODE_ENV !== "production" && function() {
6405
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
6406
+ var React = require$$0__default.default, shim2 = requireShim();
6407
+ function is(x, y) {
6408
+ return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
6409
+ }
6410
+ var objectIs = typeof Object.is == "function" ? Object.is : is, useSyncExternalStore = shim2.useSyncExternalStore, useRef = React.useRef, useEffect = React.useEffect, useMemo = React.useMemo, useDebugValue = React.useDebugValue;
6411
+ function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual2) {
6412
+ var instRef = useRef(null), inst;
6413
+ instRef.current === null ? (inst = {
6414
+ hasValue: !1,
6415
+ value: null
6416
+ }, instRef.current = inst) : inst = instRef.current;
6417
+ var _useMemo = useMemo(function() {
6418
+ var hasMemo = !1, memoizedSnapshot, memoizedSelection, memoizedSelector = function(nextSnapshot) {
6419
+ if (!hasMemo) {
6420
+ hasMemo = !0, memoizedSnapshot = nextSnapshot;
6421
+ var _nextSelection = selector(nextSnapshot);
6422
+ if (isEqual2 !== void 0 && inst.hasValue) {
6423
+ var currentSelection = inst.value;
6424
+ if (isEqual2(currentSelection, _nextSelection))
6425
+ return memoizedSelection = currentSelection, currentSelection;
6426
+ }
6427
+ return memoizedSelection = _nextSelection, _nextSelection;
6428
+ }
6429
+ var prevSnapshot = memoizedSnapshot, prevSelection = memoizedSelection;
6430
+ if (objectIs(prevSnapshot, nextSnapshot))
6431
+ return prevSelection;
6432
+ var nextSelection = selector(nextSnapshot);
6433
+ return isEqual2 !== void 0 && isEqual2(prevSelection, nextSelection) ? prevSelection : (memoizedSnapshot = nextSnapshot, memoizedSelection = nextSelection, nextSelection);
6434
+ }, maybeGetServerSnapshot = getServerSnapshot === void 0 ? null : getServerSnapshot, getSnapshotWithSelector = function() {
6435
+ return memoizedSelector(getSnapshot());
6436
+ }, getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? void 0 : function() {
6437
+ return memoizedSelector(maybeGetServerSnapshot());
6438
+ };
6439
+ return [getSnapshotWithSelector, getServerSnapshotWithSelector];
6440
+ }, [getSnapshot, getServerSnapshot, selector, isEqual2]), getSelection = _useMemo[0], getServerSelection = _useMemo[1], value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
6441
+ return useEffect(function() {
6442
+ inst.hasValue = !0, inst.value = value;
6443
+ }, [value]), useDebugValue(value), value;
6444
+ }
6445
+ withSelector_development.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
6446
+ }()), withSelector_development;
6447
+ }
6448
+ var hasRequiredWithSelector;
6449
+ function requireWithSelector() {
6450
+ return hasRequiredWithSelector || (hasRequiredWithSelector = 1, process.env.NODE_ENV === "production" ? withSelector.exports = requireWithSelector_production_min() : withSelector.exports = requireWithSelector_development()), withSelector.exports;
6451
+ }
6452
+ requireWithSelector();
6453
+ requireShim();
6454
+ const forEachActor = (actorRef, callback) => {
6455
+ callback(actorRef);
6456
+ const children = actorRef.getSnapshot().children;
6457
+ children && Object.values(children).forEach((child) => {
6458
+ forEachActor(child, callback);
6459
+ });
6460
+ };
6461
+ function stopRootWithRehydration(actorRef) {
6462
+ const persistedSnapshots = [];
6463
+ forEachActor(actorRef, (ref) => {
6464
+ persistedSnapshots.push([ref, ref.getSnapshot()]), ref.observers = /* @__PURE__ */ new Set();
6465
+ });
6466
+ const systemSnapshot = actorRef.system.getSnapshot?.();
6467
+ actorRef.stop(), actorRef.system._snapshot = systemSnapshot, persistedSnapshots.forEach(([ref, snapshot]) => {
6468
+ ref._processingStatus = 0, ref._snapshot = snapshot;
6469
+ });
6470
+ }
6471
+ function useIdleActorRef(logic, ...[options]) {
6472
+ let [[currentConfig, actorRef], setCurrent] = require$$0.useState(() => {
6473
+ const actorRef2 = xstate.createActor(logic, options);
6474
+ return [logic.config, actorRef2];
6475
+ });
6476
+ if (logic.config !== currentConfig) {
6477
+ const newActorRef = xstate.createActor(logic, {
6478
+ ...options,
6479
+ snapshot: actorRef.getPersistedSnapshot({
6480
+ __unsafeAllowInlineActors: !0
6481
+ })
6482
+ });
6483
+ setCurrent([logic.config, newActorRef]), actorRef = newActorRef;
6484
+ }
6485
+ return index(() => {
6486
+ actorRef.logic.implementations = logic.implementations;
6487
+ }), actorRef;
6488
+ }
6489
+ function useActorRef(machine, ...[options, observerOrListener]) {
6490
+ const actorRef = useIdleActorRef(machine, options);
6491
+ return require$$0.useEffect(() => {
6492
+ if (!observerOrListener)
6493
+ return;
6494
+ let sub = actorRef.subscribe(xstate.toObserver(observerOrListener));
6495
+ return () => {
6496
+ sub.unsubscribe();
6497
+ };
6498
+ }, [observerOrListener]), require$$0.useEffect(() => (actorRef.start(), () => {
6499
+ stopRootWithRehydration(actorRef);
6500
+ }), [actorRef]), actorRef;
6501
+ }
6502
+ function useEditor(config) {
6503
+ const $ = reactCompilerRuntime.c(8);
6504
+ let t0;
6505
+ $[0] !== config.schema ? (t0 = config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema), $[0] = config.schema, $[1] = t0) : t0 = $[1];
6506
+ let t1;
6507
+ $[2] !== t0 ? (t1 = getPortableTextMemberSchemaTypes(t0), $[2] = t0, $[3] = t1) : t1 = $[3];
6508
+ const schema2 = t1, t2 = config.keyGenerator ?? defaultKeyGenerator;
6509
+ let t3;
6510
+ return $[4] !== config.behaviors || $[5] !== t2 || $[6] !== schema2 ? (t3 = {
6511
+ input: {
6512
+ behaviors: config.behaviors,
6513
+ keyGenerator: t2,
6514
+ schema: schema2
6515
+ }
6516
+ }, $[4] = config.behaviors, $[5] = t2, $[6] = schema2, $[7] = t3) : t3 = $[7], useActorRef(editorMachine, t3);
6517
+ }
6063
6518
  exports.PortableTextEditable = PortableTextEditable;
6064
6519
  exports.PortableTextEditor = PortableTextEditor;
6520
+ exports.createMarkdownBehaviors = createMarkdownBehaviors;
6521
+ exports.defineBehavior = defineBehavior;
6065
6522
  exports.editorMachine = editorMachine;
6066
6523
  exports.keyGenerator = defaultKeyGenerator;
6524
+ exports.useEditor = useEditor;
6067
6525
  exports.usePortableTextEditor = usePortableTextEditor;
6068
6526
  exports.usePortableTextEditorSelection = usePortableTextEditorSelection;
6069
6527
  //# sourceMappingURL=index.js.map