@portabletext/editor 1.14.2 → 1.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/lib/_chunks-cjs/selector.get-text-before.cjs +16 -5
  2. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  3. package/lib/_chunks-es/selector.get-text-before.js +16 -5
  4. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  5. package/lib/index.cjs +877 -544
  6. package/lib/index.cjs.map +1 -1
  7. package/lib/index.d.cts +15 -15
  8. package/lib/index.d.ts +15 -15
  9. package/lib/index.js +877 -544
  10. package/lib/index.js.map +1 -1
  11. package/package.json +9 -9
  12. package/src/editor/__tests__/PortableTextEditor.test.tsx +6 -6
  13. package/src/editor/__tests__/RangeDecorations.test.tsx +1 -1
  14. package/src/editor/__tests__/handleClick.test.tsx +4 -4
  15. package/src/editor/__tests__/insert-block.test.tsx +3 -3
  16. package/src/editor/__tests__/pteWarningsSelfSolving.test.tsx +6 -6
  17. package/src/editor/__tests__/self-solving.test.tsx +1 -1
  18. package/src/editor/components/DraggableBlock.tsx +1 -1
  19. package/src/editor/components/Element.tsx +8 -2
  20. package/src/editor/components/Leaf.tsx +1 -1
  21. package/src/editor/create-editor.ts +18 -29
  22. package/src/editor/hooks/useSyncValue.test.tsx +2 -2
  23. package/src/editor/hooks/useSyncValue.ts +2 -2
  24. package/src/editor/nodes/DefaultObject.tsx +1 -0
  25. package/src/editor/plugins/__tests__/withEditableAPIDelete.test.tsx +4 -4
  26. package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +2 -2
  27. package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +7 -7
  28. package/src/editor/plugins/__tests__/withEditableAPISelectionsOverlapping.test.tsx +4 -4
  29. package/src/editor/plugins/__tests__/withPortableTextLists.test.tsx +1 -1
  30. package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +9 -9
  31. package/src/editor/plugins/__tests__/withPortableTextSelections.test.tsx +1 -1
  32. package/src/editor/plugins/__tests__/withUndoRedo.test.tsx +2 -2
  33. package/src/types/editor.ts +14 -13
  34. package/src/utils/__tests__/valueNormalization.test.tsx +1 -1
package/lib/index.js CHANGED
@@ -1,3 +1,14 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty, __propIsEnum = Object.prototype.propertyIsEnumerable;
4
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues = (a, b) => {
5
+ for (var prop in b || (b = {}))
6
+ __hasOwnProp.call(b, prop) && __defNormalProp(a, prop, b[prop]);
7
+ if (__getOwnPropSymbols)
8
+ for (var prop of __getOwnPropSymbols(b))
9
+ __propIsEnum.call(b, prop) && __defNormalProp(a, prop, b[prop]);
10
+ return a;
11
+ };
1
12
  import { getFirstBlock, getSelectedBlocks, getLastBlock, getFocusBlockObject, getNextBlock, getPreviousBlock, selectionIsCollapsed, getFocusTextBlock, getFocusSpan, getFocusListBlock, createGuards, getBlockTextBefore, getFocusBlock } from "./_chunks-es/selector.get-text-before.js";
2
13
  import { isPortableTextTextBlock, isPortableTextSpan as isPortableTextSpan$1, defineType, defineField, isKeySegment, isPortableTextListBlock } from "@sanity/types";
3
14
  import { Schema } from "@sanity/schema";
@@ -131,12 +142,14 @@ function compareHotkey(parsedHotkey, event) {
131
142
  return (parsedHotkey.altKey == null || parsedHotkey.altKey === event.altKey) && (parsedHotkey.ctrlKey == null || parsedHotkey.ctrlKey === event.ctrlKey) && (parsedHotkey.metaKey == null || parsedHotkey.metaKey === event.metaKey) && (parsedHotkey.shiftKey == null || parsedHotkey.shiftKey === event.shiftKey) ? parsedHotkey.keyCode !== void 0 && event.keyCode !== void 0 ? parsedHotkey.keyCode === 91 && event.keyCode === 93 ? !0 : parsedHotkey.keyCode === event.keyCode : parsedHotkey.keyCode === event.keyCode || parsedHotkey.key === event.key.toLowerCase() : !1;
132
143
  }
133
144
  function toKeyCode(name) {
145
+ var _a;
134
146
  const keyName = toKeyName(name);
135
- return keyCodes[keyName] ?? keyName.toUpperCase().charCodeAt(0);
147
+ return (_a = keyCodes[keyName]) != null ? _a : keyName.toUpperCase().charCodeAt(0);
136
148
  }
137
149
  function toKeyName(name) {
150
+ var _a;
138
151
  const keyName = name.toLowerCase();
139
- return aliases[keyName] ?? keyName;
152
+ return (_a = aliases[keyName]) != null ? _a : keyName;
140
153
  }
141
154
  function defineBehavior(behavior) {
142
155
  return behavior;
@@ -148,11 +161,12 @@ function createCodeEditorBehaviors(config) {
148
161
  context,
149
162
  event
150
163
  }) => {
164
+ var _a;
151
165
  const isMoveUpShortcut = isHotkey(config.moveBlockUpShortcut, event.keyboardEvent), firstBlock = getFirstBlock({
152
166
  context
153
167
  }), selectedBlocks = getSelectedBlocks({
154
168
  context
155
- }), blocksAbove = firstBlock?.node._key !== selectedBlocks[0]?.node._key;
169
+ }), blocksAbove = (firstBlock == null ? void 0 : firstBlock.node._key) !== ((_a = selectedBlocks[0]) == null ? void 0 : _a.node._key);
156
170
  return !isMoveUpShortcut || !blocksAbove ? !1 : {
157
171
  paths: selectedBlocks.map((block) => block.path)
158
172
  };
@@ -169,11 +183,12 @@ function createCodeEditorBehaviors(config) {
169
183
  context,
170
184
  event
171
185
  }) => {
186
+ var _a;
172
187
  const isMoveDownShortcut = isHotkey(config.moveBlockDownShortcut, event.keyboardEvent), lastBlock = getLastBlock({
173
188
  context
174
189
  }), selectedBlocks = getSelectedBlocks({
175
190
  context
176
- }), blocksBelow = lastBlock?.node._key !== selectedBlocks[selectedBlocks.length - 1]?.node._key;
191
+ }), blocksBelow = (lastBlock == null ? void 0 : lastBlock.node._key) !== ((_a = selectedBlocks[selectedBlocks.length - 1]) == null ? void 0 : _a.node._key);
177
192
  return !isMoveDownShortcut || !blocksBelow ? !1 : {
178
193
  paths: selectedBlocks.map((block) => block.path).reverse()
179
194
  };
@@ -193,7 +208,10 @@ function isEmptyTextBlock(block) {
193
208
  return onlyText && blockText === "";
194
209
  }
195
210
  function getTextBlockText(block) {
196
- return block.children.map((child) => child.text ?? "").join("");
211
+ return block.children.map((child) => {
212
+ var _a;
213
+ return (_a = child.text) != null ? _a : "";
214
+ }).join("");
197
215
  }
198
216
  const arrowDownOnLonelyBlockObject = {
199
217
  on: "key.down",
@@ -519,9 +537,10 @@ function createLinkBehaviors(config) {
519
537
  context,
520
538
  event
521
539
  }) => {
540
+ var _a;
522
541
  const selectionCollapsed = selectionIsCollapsed({
523
542
  context
524
- }), text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.linkAnnotation?.({
543
+ }), text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? (_a = config.linkAnnotation) == null ? void 0 : _a.call(config, {
525
544
  url,
526
545
  schema: context.schema
527
546
  }) : void 0;
@@ -541,6 +560,7 @@ function createLinkBehaviors(config) {
541
560
  context,
542
561
  event
543
562
  }) => {
563
+ var _a;
544
564
  const focusSpan = getFocusSpan({
545
565
  context
546
566
  }), selectionCollapsed = selectionIsCollapsed({
@@ -548,7 +568,7 @@ function createLinkBehaviors(config) {
548
568
  });
549
569
  if (!focusSpan || !selectionCollapsed)
550
570
  return !1;
551
- const text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.linkAnnotation?.({
571
+ const text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? (_a = config.linkAnnotation) == null ? void 0 : _a.call(config, {
552
572
  url,
553
573
  schema: context.schema
554
574
  }) : void 0;
@@ -573,7 +593,7 @@ function looksLikeUrl(text) {
573
593
  let looksLikeUrl2 = !1;
574
594
  try {
575
595
  new URL(text), looksLikeUrl2 = !0;
576
- } catch {
596
+ } catch (e) {
577
597
  }
578
598
  return looksLikeUrl2;
579
599
  }
@@ -629,6 +649,14 @@ function spanSelectionPointToBlockOffset({
629
649
  }
630
650
  }
631
651
  }
652
+ var __defProp$q = Object.defineProperty, __getOwnPropSymbols$q = Object.getOwnPropertySymbols, __hasOwnProp$q = Object.prototype.hasOwnProperty, __propIsEnum$q = Object.prototype.propertyIsEnumerable, __defNormalProp$q = (obj, key, value) => key in obj ? __defProp$q(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$q = (a, b) => {
653
+ for (var prop in b || (b = {}))
654
+ __hasOwnProp$q.call(b, prop) && __defNormalProp$q(a, prop, b[prop]);
655
+ if (__getOwnPropSymbols$q)
656
+ for (var prop of __getOwnPropSymbols$q(b))
657
+ __propIsEnum$q.call(b, prop) && __defNormalProp$q(a, prop, b[prop]);
658
+ return a;
659
+ };
632
660
  function createMarkdownBehaviors(config) {
633
661
  const automaticBlockquoteOnSpace = {
634
662
  on: "insert.text",
@@ -636,6 +664,7 @@ function createMarkdownBehaviors(config) {
636
664
  context,
637
665
  event
638
666
  }) => {
667
+ var _a;
639
668
  if (event.text !== " ")
640
669
  return !1;
641
670
  const selectionCollapsed = selectionIsCollapsed({
@@ -660,7 +689,7 @@ function createMarkdownBehaviors(config) {
660
689
  });
661
690
  if (!blockOffset)
662
691
  return !1;
663
- const blockText = getTextBlockText(focusTextBlock.node), caretAtTheEndOfQuote = blockOffset.offset === 1, looksLikeMarkdownQuote = /^>/.test(blockText), blockquoteStyle = config.blockquoteStyle?.(context);
692
+ const blockText = getTextBlockText(focusTextBlock.node), caretAtTheEndOfQuote = blockOffset.offset === 1, looksLikeMarkdownQuote = /^>/.test(blockText), blockquoteStyle = (_a = config.blockquoteStyle) == null ? void 0 : _a.call(config, context);
664
693
  return caretAtTheEndOfQuote && looksLikeMarkdownQuote && blockquoteStyle !== void 0 ? {
665
694
  focusTextBlock,
666
695
  style: blockquoteStyle
@@ -697,10 +726,11 @@ function createMarkdownBehaviors(config) {
697
726
  context,
698
727
  event
699
728
  }) => {
729
+ var _a;
700
730
  const hrCharacter = event.text === "-" ? "-" : event.text === "*" ? "*" : event.text === "_" ? "_" : void 0;
701
731
  if (hrCharacter === void 0)
702
732
  return !1;
703
- const hrObject = config.horizontalRuleObject?.(context), focusBlock = getFocusTextBlock({
733
+ const hrObject = (_a = config.horizontalRuleObject) == null ? void 0 : _a.call(config, context), focusBlock = getFocusTextBlock({
704
734
  context
705
735
  }), selectionCollapsed = selectionIsCollapsed({
706
736
  context
@@ -738,17 +768,17 @@ function createMarkdownBehaviors(config) {
738
768
  type: "insert.block object",
739
769
  placement: "before",
740
770
  blockObject: hrObject
741
- }, {
742
- type: "delete.text",
743
- ...hrBlockOffsets
744
- }]]
771
+ }, __spreadValues$q({
772
+ type: "delete.text"
773
+ }, hrBlockOffsets)]]
745
774
  }, automaticHrOnPaste = {
746
775
  on: "paste",
747
776
  guard: ({
748
777
  context,
749
778
  event
750
779
  }) => {
751
- const text = event.data.getData("text/plain"), hrRegExp = /^(---)$|(___)$|(\*\*\*)$/gm, hrCharacters = text.match(hrRegExp)?.[0], hrObject = config.horizontalRuleObject?.(context), focusBlock = getFocusBlock({
780
+ var _a, _b;
781
+ const text = event.data.getData("text/plain"), hrRegExp = /^(---)$|(___)$|(\*\*\*)$/gm, hrCharacters = (_a = text.match(hrRegExp)) == null ? void 0 : _a[0], hrObject = (_b = config.horizontalRuleObject) == null ? void 0 : _b.call(config, context), focusBlock = getFocusBlock({
752
782
  context
753
783
  });
754
784
  return !hrCharacters || !hrObject || !focusBlock ? !1 : {
@@ -789,6 +819,7 @@ function createMarkdownBehaviors(config) {
789
819
  context,
790
820
  event
791
821
  }) => {
822
+ var _a;
792
823
  if (event.text !== " ")
793
824
  return !1;
794
825
  const selectionCollapsed = selectionIsCollapsed({
@@ -816,7 +847,7 @@ function createMarkdownBehaviors(config) {
816
847
  const blockText = getTextBlockText(focusTextBlock.node), markdownHeadingSearch = /^#+/.exec(blockText), level = markdownHeadingSearch ? markdownHeadingSearch[0].length : void 0;
817
848
  if (blockOffset.offset !== level)
818
849
  return !1;
819
- const style = level !== void 0 ? config.headingStyle?.({
850
+ const style = level !== void 0 ? (_a = config.headingStyle) == null ? void 0 : _a.call(config, {
820
851
  schema: context.schema,
821
852
  level
822
853
  }) : void 0;
@@ -857,6 +888,7 @@ function createMarkdownBehaviors(config) {
857
888
  guard: ({
858
889
  context
859
890
  }) => {
891
+ var _a;
860
892
  const selectionCollapsed = selectionIsCollapsed({
861
893
  context
862
894
  }), focusTextBlock = getFocusTextBlock({
@@ -866,7 +898,7 @@ function createMarkdownBehaviors(config) {
866
898
  });
867
899
  if (!selectionCollapsed || !focusTextBlock || !focusSpan)
868
900
  return !1;
869
- const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0, defaultStyle = config.defaultStyle?.(context);
901
+ const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0, defaultStyle = (_a = config.defaultStyle) == null ? void 0 : _a.call(config, context);
870
902
  return atTheBeginningOfBLock && defaultStyle && focusTextBlock.node.style !== defaultStyle ? {
871
903
  defaultStyle,
872
904
  focusTextBlock
@@ -886,6 +918,7 @@ function createMarkdownBehaviors(config) {
886
918
  context,
887
919
  event
888
920
  }) => {
921
+ var _a, _b, _c;
889
922
  if (event.text !== " ")
890
923
  return !1;
891
924
  const selectionCollapsed = selectionIsCollapsed({
@@ -910,7 +943,7 @@ function createMarkdownBehaviors(config) {
910
943
  });
911
944
  if (!blockOffset)
912
945
  return !1;
913
- const blockText = getTextBlockText(focusTextBlock.node), defaultStyle = config.defaultStyle?.(context), looksLikeUnorderedList = /^(-|\*)/.test(blockText), unorderedListStyle = config.unorderedListStyle?.(context), caretAtTheEndOfUnorderedList = blockOffset.offset === 1;
946
+ const blockText = getTextBlockText(focusTextBlock.node), defaultStyle = (_a = config.defaultStyle) == null ? void 0 : _a.call(config, context), looksLikeUnorderedList = /^(-|\*)/.test(blockText), unorderedListStyle = (_b = config.unorderedListStyle) == null ? void 0 : _b.call(config, context), caretAtTheEndOfUnorderedList = blockOffset.offset === 1;
914
947
  if (defaultStyle && caretAtTheEndOfUnorderedList && looksLikeUnorderedList && unorderedListStyle !== void 0)
915
948
  return {
916
949
  focusTextBlock,
@@ -918,7 +951,7 @@ function createMarkdownBehaviors(config) {
918
951
  listItemLength: 1,
919
952
  style: defaultStyle
920
953
  };
921
- const looksLikeOrderedList = /^1\./.test(blockText), orderedListStyle = config.orderedListStyle?.(context), caretAtTheEndOfOrderedList = blockOffset.offset === 2;
954
+ const looksLikeOrderedList = /^1\./.test(blockText), orderedListStyle = (_c = config.orderedListStyle) == null ? void 0 : _c.call(config, context), caretAtTheEndOfOrderedList = blockOffset.offset === 2;
922
955
  return defaultStyle && caretAtTheEndOfOrderedList && looksLikeOrderedList && orderedListStyle !== void 0 ? {
923
956
  focusTextBlock,
924
957
  listItem: orderedListStyle,
@@ -955,12 +988,13 @@ function createMarkdownBehaviors(config) {
955
988
  return [automaticBlockquoteOnSpace, automaticHeadingOnSpace, automaticHr, automaticHrOnPaste, clearStyleOnBackspace, automaticListOnSpace];
956
989
  }
957
990
  function getPortableTextMemberSchemaTypes(portableTextType) {
991
+ var _a, _b, _c;
958
992
  if (!portableTextType)
959
993
  throw new Error("Parameter 'portabletextType' missing (required)");
960
- const blockType = portableTextType.of?.find(findBlockType);
994
+ const blockType = (_a = portableTextType.of) == null ? void 0 : _a.find(findBlockType);
961
995
  if (!blockType)
962
996
  throw new Error("Block type is not defined in this schema (required)");
963
- const childrenField = blockType.fields?.find((field) => field.name === "children");
997
+ const childrenField = (_b = blockType.fields) == null ? void 0 : _b.find((field) => field.name === "children");
964
998
  if (!childrenField)
965
999
  throw new Error("Children field for block type found in schema (required)");
966
1000
  const ofType = childrenField.type.of;
@@ -969,7 +1003,7 @@ function getPortableTextMemberSchemaTypes(portableTextType) {
969
1003
  const spanType = ofType.find((memberType) => memberType.name === "span");
970
1004
  if (!spanType)
971
1005
  throw new Error("Span type not found in schema (required)");
972
- const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = portableTextType.of?.filter((field) => field.name !== blockType.name) || [];
1006
+ const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = ((_c = portableTextType.of) == null ? void 0 : _c.filter((field) => field.name !== blockType.name)) || [];
973
1007
  return {
974
1008
  styles: resolveEnabledStyles(blockType),
975
1009
  decorators: resolveEnabledDecorators(spanType),
@@ -983,10 +1017,11 @@ function getPortableTextMemberSchemaTypes(portableTextType) {
983
1017
  };
984
1018
  }
985
1019
  function resolveEnabledStyles(blockType) {
986
- const styleField = blockType.fields?.find((btField) => btField.name === "style");
1020
+ var _a, _b, _c;
1021
+ const styleField = (_a = blockType.fields) == null ? void 0 : _a.find((btField) => btField.name === "style");
987
1022
  if (!styleField)
988
1023
  throw new Error("A field with name 'style' is not defined in the block type (required).");
989
- const textStyles = styleField.type.options?.list && styleField.type.options.list?.filter((style) => style.value);
1024
+ const textStyles = ((_b = styleField.type.options) == null ? void 0 : _b.list) && ((_c = styleField.type.options.list) == null ? void 0 : _c.filter((style) => style.value));
990
1025
  if (!textStyles || textStyles.length === 0)
991
1026
  throw new Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");
992
1027
  return textStyles;
@@ -995,10 +1030,11 @@ function resolveEnabledDecorators(spanType) {
995
1030
  return spanType.decorators;
996
1031
  }
997
1032
  function resolveEnabledListItems(blockType) {
998
- const listField = blockType.fields?.find((btField) => btField.name === "listItem");
1033
+ var _a, _b;
1034
+ const listField = (_a = blockType.fields) == null ? void 0 : _a.find((btField) => btField.name === "listItem");
999
1035
  if (!listField)
1000
1036
  throw new Error("A field with name 'listItem' is not defined in the block type (required).");
1001
- const listItems = listField.type.options?.list && listField.type.options.list.filter((list) => list.value);
1037
+ const listItems = ((_b = listField.type.options) == null ? void 0 : _b.list) && listField.type.options.list.filter((list) => list.value);
1002
1038
  if (!listItems)
1003
1039
  throw new Error("The list field need at least to be an empty array");
1004
1040
  return listItems;
@@ -1006,11 +1042,20 @@ function resolveEnabledListItems(blockType) {
1006
1042
  function findBlockType(type) {
1007
1043
  return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
1008
1044
  }
1045
+ var __defProp$p = Object.defineProperty, __defProps$j = Object.defineProperties, __getOwnPropDescs$j = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$p = Object.getOwnPropertySymbols, __hasOwnProp$p = Object.prototype.hasOwnProperty, __propIsEnum$p = Object.prototype.propertyIsEnumerable, __defNormalProp$p = (obj, key, value) => key in obj ? __defProp$p(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$p = (a, b) => {
1046
+ for (var prop in b || (b = {}))
1047
+ __hasOwnProp$p.call(b, prop) && __defNormalProp$p(a, prop, b[prop]);
1048
+ if (__getOwnPropSymbols$p)
1049
+ for (var prop of __getOwnPropSymbols$p(b))
1050
+ __propIsEnum$p.call(b, prop) && __defNormalProp$p(a, prop, b[prop]);
1051
+ return a;
1052
+ }, __spreadProps$j = (a, b) => __defProps$j(a, __getOwnPropDescs$j(b));
1009
1053
  function defineSchema(definition) {
1010
1054
  return definition;
1011
1055
  }
1012
1056
  function compileSchemaDefinition(definition) {
1013
- const blockObjects = definition?.blockObjects?.map((blockObject) => defineType({
1057
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1058
+ const blockObjects = (_b = (_a = definition == null ? void 0 : definition.blockObjects) == null ? void 0 : _a.map((blockObject) => defineType({
1014
1059
  type: "object",
1015
1060
  // Very naive way to work around `SanitySchema.compile` adding default
1016
1061
  // fields to objects with the name `image`
@@ -1018,13 +1063,13 @@ function compileSchemaDefinition(definition) {
1018
1063
  title: blockObject.title,
1019
1064
  icon: blockObject.icon,
1020
1065
  fields: []
1021
- })) ?? [], inlineObjects = definition?.inlineObjects?.map((inlineObject) => defineType({
1066
+ }))) != null ? _b : [], inlineObjects = (_d = (_c = definition == null ? void 0 : definition.inlineObjects) == null ? void 0 : _c.map((inlineObject) => defineType({
1022
1067
  type: "object",
1023
1068
  name: inlineObject.name,
1024
1069
  title: inlineObject.title,
1025
1070
  icon: inlineObject.icon,
1026
1071
  fields: []
1027
- })) ?? [], portableTextSchema = defineField({
1072
+ }))) != null ? _d : [], portableTextSchema = defineField({
1028
1073
  type: "array",
1029
1074
  name: "portable-text",
1030
1075
  of: [...blockObjects.map((blockObject) => ({
@@ -1036,43 +1081,49 @@ function compileSchemaDefinition(definition) {
1036
1081
  type: inlineObject.name
1037
1082
  })),
1038
1083
  marks: {
1039
- decorators: definition?.decorators?.map((decorator) => ({
1040
- title: decorator.title ?? startCase(decorator.name),
1041
- value: decorator.name,
1042
- icon: decorator.icon
1043
- })) ?? [],
1044
- annotations: definition?.annotations?.map((annotation) => ({
1084
+ decorators: (_f = (_e = definition == null ? void 0 : definition.decorators) == null ? void 0 : _e.map((decorator) => {
1085
+ var _a2;
1086
+ return {
1087
+ title: (_a2 = decorator.title) != null ? _a2 : startCase(decorator.name),
1088
+ value: decorator.name,
1089
+ icon: decorator.icon
1090
+ };
1091
+ })) != null ? _f : [],
1092
+ annotations: (_h = (_g = definition == null ? void 0 : definition.annotations) == null ? void 0 : _g.map((annotation) => ({
1045
1093
  name: annotation.name,
1046
1094
  type: "object",
1047
1095
  title: annotation.title,
1048
1096
  icon: annotation.icon
1049
- })) ?? []
1097
+ }))) != null ? _h : []
1050
1098
  },
1051
- lists: definition?.lists?.map((list) => ({
1052
- value: list.name,
1053
- title: list.title ?? startCase(list.name),
1054
- icon: list.icon
1055
- })) ?? [],
1056
- styles: definition?.styles?.map((style) => ({
1057
- value: style.name,
1058
- title: style.title ?? startCase(style.name),
1059
- icon: style.icon
1060
- })) ?? []
1099
+ lists: (_j = (_i = definition == null ? void 0 : definition.lists) == null ? void 0 : _i.map((list) => {
1100
+ var _a2;
1101
+ return {
1102
+ value: list.name,
1103
+ title: (_a2 = list.title) != null ? _a2 : startCase(list.name),
1104
+ icon: list.icon
1105
+ };
1106
+ })) != null ? _j : [],
1107
+ styles: (_l = (_k = definition == null ? void 0 : definition.styles) == null ? void 0 : _k.map((style) => {
1108
+ var _a2;
1109
+ return {
1110
+ value: style.name,
1111
+ title: (_a2 = style.title) != null ? _a2 : startCase(style.name),
1112
+ icon: style.icon
1113
+ };
1114
+ })) != null ? _l : []
1061
1115
  }]
1062
1116
  }), schema = Schema.compile({
1063
1117
  types: [portableTextSchema, ...blockObjects, ...inlineObjects]
1064
1118
  }).get("portable-text"), pteSchema = getPortableTextMemberSchemaTypes(schema);
1065
- return {
1066
- ...pteSchema,
1067
- blockObjects: pteSchema.blockObjects.map((blockObject) => blockObject.name === "tmp-image" ? {
1068
- ...blockObject,
1119
+ return __spreadProps$j(__spreadValues$p({}, pteSchema), {
1120
+ blockObjects: pteSchema.blockObjects.map((blockObject) => blockObject.name === "tmp-image" ? __spreadProps$j(__spreadValues$p({}, blockObject), {
1069
1121
  name: "image",
1070
- type: {
1071
- ...blockObject.type,
1122
+ type: __spreadProps$j(__spreadValues$p({}, blockObject.type), {
1072
1123
  name: "image"
1073
- }
1074
- } : blockObject)
1075
- };
1124
+ })
1125
+ }) : blockObject)
1126
+ });
1076
1127
  }
1077
1128
  const rootName = "sanity-pte:";
1078
1129
  var debug$l = debug$m(rootName);
@@ -1207,6 +1258,22 @@ function normalizeSelection(selection, value) {
1207
1258
  backward: selection.backward
1208
1259
  } : null;
1209
1260
  }
1261
+ var __defProp$o = Object.defineProperty, __defProps$i = Object.defineProperties, __getOwnPropDescs$i = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$o = Object.getOwnPropertySymbols, __hasOwnProp$o = Object.prototype.hasOwnProperty, __propIsEnum$o = Object.prototype.propertyIsEnumerable, __defNormalProp$o = (obj, key, value) => key in obj ? __defProp$o(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$o = (a, b) => {
1262
+ for (var prop in b || (b = {}))
1263
+ __hasOwnProp$o.call(b, prop) && __defNormalProp$o(a, prop, b[prop]);
1264
+ if (__getOwnPropSymbols$o)
1265
+ for (var prop of __getOwnPropSymbols$o(b))
1266
+ __propIsEnum$o.call(b, prop) && __defNormalProp$o(a, prop, b[prop]);
1267
+ return a;
1268
+ }, __spreadProps$i = (a, b) => __defProps$i(a, __getOwnPropDescs$i(b)), __objRest$3 = (source, exclude) => {
1269
+ var target = {};
1270
+ for (var prop in source)
1271
+ __hasOwnProp$o.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
1272
+ if (source != null && __getOwnPropSymbols$o)
1273
+ for (var prop of __getOwnPropSymbols$o(source))
1274
+ exclude.indexOf(prop) < 0 && __propIsEnum$o.call(source, prop) && (target[prop] = source[prop]);
1275
+ return target;
1276
+ };
1210
1277
  const VOID_CHILD_KEY = "void-child";
1211
1278
  function keepObjectEquality(object, keyMap) {
1212
1279
  const value = keyMap[object._key];
@@ -1216,11 +1283,13 @@ function toSlateValue(value, {
1216
1283
  schemaTypes
1217
1284
  }, keyMap = {}) {
1218
1285
  return value && Array.isArray(value) ? value.map((block) => {
1219
- const {
1286
+ const _a = block, {
1220
1287
  _type,
1221
- _key,
1222
- ...rest
1223
- } = block, voidChildren = [{
1288
+ _key
1289
+ } = _a, rest = __objRest$3(_a, [
1290
+ "_type",
1291
+ "_key"
1292
+ ]), voidChildren = [{
1224
1293
  _key: VOID_CHILD_KEY,
1225
1294
  _type: "span",
1226
1295
  text: "",
@@ -1230,11 +1299,13 @@ function toSlateValue(value, {
1230
1299
  const textBlock = block;
1231
1300
  let hasInlines = !1;
1232
1301
  const hasMissingStyle = typeof textBlock.style > "u", hasMissingMarkDefs = typeof textBlock.markDefs > "u", hasMissingChildren = typeof textBlock.children > "u", children = (textBlock.children || []).map((child) => {
1233
- const {
1302
+ const _a2 = child, {
1234
1303
  _type: cType,
1235
- _key: cKey,
1236
- ...cRest
1237
- } = child;
1304
+ _key: cKey
1305
+ } = _a2, cRest = __objRest$3(_a2, [
1306
+ "_type",
1307
+ "_key"
1308
+ ]);
1238
1309
  return cType !== "span" ? (hasInlines = !0, keepObjectEquality({
1239
1310
  _type: cType,
1240
1311
  _key: cKey,
@@ -1243,12 +1314,12 @@ function toSlateValue(value, {
1243
1314
  __inline: !0
1244
1315
  }, keyMap)) : child;
1245
1316
  });
1246
- return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && Element$1.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].value), keepObjectEquality({
1317
+ return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && Element$1.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].value), keepObjectEquality(__spreadProps$i(__spreadValues$o({
1247
1318
  _type,
1248
- _key,
1249
- ...rest,
1319
+ _key
1320
+ }, rest), {
1250
1321
  children
1251
- }, keyMap));
1322
+ }), keyMap));
1252
1323
  }
1253
1324
  return keepObjectEquality({
1254
1325
  _type,
@@ -1274,40 +1345,42 @@ function fromSlateValue(value, textBlockType, keyMap = {}) {
1274
1345
  } = child;
1275
1346
  if ("value" in child && _cType !== "span") {
1276
1347
  hasInlines = !0;
1277
- const {
1348
+ const _a = child, {
1278
1349
  value: v,
1279
1350
  _key: k,
1280
1351
  _type: t,
1281
1352
  __inline: _i,
1282
- children: _c,
1283
- ...rest
1284
- } = child;
1285
- return keepObjectEquality({
1286
- ...rest,
1287
- ...v,
1353
+ children: _c
1354
+ } = _a, rest = __objRest$3(_a, [
1355
+ "value",
1356
+ "_key",
1357
+ "_type",
1358
+ "__inline",
1359
+ "children"
1360
+ ]);
1361
+ return keepObjectEquality(__spreadProps$i(__spreadValues$o(__spreadValues$o({}, rest), v), {
1288
1362
  _key: k,
1289
1363
  _type: t
1290
- }, keyMap);
1364
+ }), keyMap);
1291
1365
  }
1292
1366
  return child;
1293
1367
  });
1294
- return hasInlines ? keepObjectEquality({
1295
- ...block,
1368
+ return hasInlines ? keepObjectEquality(__spreadProps$i(__spreadValues$o({}, block), {
1296
1369
  children,
1297
1370
  _key,
1298
1371
  _type
1299
- }, keyMap) : block;
1372
+ }), keyMap) : block;
1300
1373
  }
1301
1374
  const blockValue = "value" in block && block.value;
1302
- return keepObjectEquality({
1375
+ return keepObjectEquality(__spreadValues$o({
1303
1376
  _key,
1304
- _type,
1305
- ...typeof blockValue == "object" ? blockValue : {}
1306
- }, keyMap);
1377
+ _type
1378
+ }, typeof blockValue == "object" ? blockValue : {}), keyMap);
1307
1379
  });
1308
1380
  }
1309
1381
  function isEqualToEmptyEditor(children, schemaTypes) {
1310
- return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && Element$1.isElement(children[0]) && children[0]._type === schemaTypes.block.name && "style" in children[0] && children[0].style === schemaTypes.styles[0].value && !("listItem" in children[0]) && Array.isArray(children[0].children) && children[0].children.length === 1 && Text.isText(children[0].children[0]) && children[0].children[0]._type === "span" && !children[0].children[0].marks?.join("") && children[0].children[0].text === "";
1382
+ var _a;
1383
+ return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && Element$1.isElement(children[0]) && children[0]._type === schemaTypes.block.name && "style" in children[0] && children[0].style === schemaTypes.styles[0].value && !("listItem" in children[0]) && Array.isArray(children[0].children) && children[0].children.length === 1 && Text.isText(children[0].children[0]) && children[0].children[0]._type === "span" && !((_a = children[0].children[0].marks) != null && _a.join("")) && children[0].children[0].text === "";
1311
1384
  }
1312
1385
  const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), IS_PROCESSING_LOCAL_CHANGES = /* @__PURE__ */ new WeakMap(), IS_DRAGGING = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_BLOCK_ELEMENT = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_ELEMENT_TARGET = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_BLOCK_TARGET_POSITION = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE_ELEMENT = /* @__PURE__ */ new WeakMap(), KEY_TO_VALUE_ELEMENT = /* @__PURE__ */ new WeakMap(), SLATE_TO_PORTABLE_TEXT_RANGE = /* @__PURE__ */ new WeakMap(), DefaultObject = (props) => {
1313
1386
  const $ = c(4);
@@ -1483,7 +1556,7 @@ const debug$k = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
1483
1556
  element,
1484
1557
  readOnly,
1485
1558
  blockRef
1486
- } = t0, editor = useSlateStatic(), dragGhostRef = useRef(), [isDragOver, setIsDragOver] = useState(!1);
1559
+ } = t0, editor = useSlateStatic(), dragGhostRef = useRef(void 0), [isDragOver, setIsDragOver] = useState(!1);
1487
1560
  let t1, t2;
1488
1561
  $[0] !== editor || $[1] !== element ? (t2 = Editor.isVoid(editor, element), $[0] = editor, $[1] = element, $[2] = t2) : t2 = $[2], t1 = t2;
1489
1562
  const isVoid = t1;
@@ -1607,6 +1680,14 @@ const debug$k = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
1607
1680
  ] }), $[41] = children, $[42] = handleDrag, $[43] = handleDragEnd, $[44] = handleDragOver, $[45] = handleDragStart, $[46] = handleDrop, $[47] = isVoid, $[48] = t17, $[49] = t18, $[50] = t19) : t19 = $[50], t19;
1608
1681
  };
1609
1682
  DraggableBlock.displayName = "DraggableBlock";
1683
+ var __defProp$n = Object.defineProperty, __defProps$h = Object.defineProperties, __getOwnPropDescs$h = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$n = Object.getOwnPropertySymbols, __hasOwnProp$n = Object.prototype.hasOwnProperty, __propIsEnum$n = Object.prototype.propertyIsEnumerable, __defNormalProp$n = (obj, key, value) => key in obj ? __defProp$n(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$n = (a, b) => {
1684
+ for (var prop in b || (b = {}))
1685
+ __hasOwnProp$n.call(b, prop) && __defNormalProp$n(a, prop, b[prop]);
1686
+ if (__getOwnPropSymbols$n)
1687
+ for (var prop of __getOwnPropSymbols$n(b))
1688
+ __propIsEnum$n.call(b, prop) && __defNormalProp$n(a, prop, b[prop]);
1689
+ return a;
1690
+ }, __spreadProps$h = (a, b) => __defProps$h(a, __getOwnPropDescs$h(b));
1610
1691
  debugWithName("components:Element");
1611
1692
  const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
1612
1693
  display: "inline-block"
@@ -1643,7 +1724,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
1643
1724
  }, "children", {
1644
1725
  _key: element._key
1645
1726
  }];
1646
- return /* @__PURE__ */ jsxs("span", { ...attributes, children: [
1727
+ return /* @__PURE__ */ jsxs("span", __spreadProps$h(__spreadValues$n({}, attributes), { children: [
1647
1728
  children,
1648
1729
  /* @__PURE__ */ jsxs("span", { draggable: !readOnly, className: "pt-inline-object", "data-testid": "pt-inline-object", ref: inlineBlockObjectRef, style: inlineBlockStyle, contentEditable: !1, children: [
1649
1730
  renderChild && renderChild({
@@ -1660,7 +1741,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
1660
1741
  }),
1661
1742
  !renderChild && /* @__PURE__ */ jsx(DefaultObject, { value })
1662
1743
  ] }, element._key)
1663
- ] });
1744
+ ] }));
1664
1745
  }
1665
1746
  throw new Error("Block not found!");
1666
1747
  }
@@ -1711,7 +1792,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
1711
1792
  return console.warn("Property 'type' is deprecated, use 'schemaType' instead."), schemaTypes.block;
1712
1793
  }
1713
1794
  }), propsOrDefaultRendered = renderBlock ? renderBlock(renderProps) : children;
1714
- return /* @__PURE__ */ jsx("div", { ...attributes, className, spellCheck, children: /* @__PURE__ */ jsx(DraggableBlock, { element, readOnly, blockRef, children: /* @__PURE__ */ jsx("div", { ref: blockRef, children: propsOrDefaultRendered }) }) }, element._key);
1795
+ return /* @__PURE__ */ jsx("div", __spreadProps$h(__spreadValues$n({}, attributes), { className, spellCheck, children: /* @__PURE__ */ jsx(DraggableBlock, { element, readOnly, blockRef, children: /* @__PURE__ */ jsx("div", { ref: blockRef, children: propsOrDefaultRendered }) }) }), element._key);
1715
1796
  }
1716
1797
  const schemaType_0 = schemaTypes.blockObjects.find((_type_0) => _type_0.name === element._type);
1717
1798
  if (!schemaType_0)
@@ -1736,13 +1817,13 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
1736
1817
  });
1737
1818
  renderedBlockFromProps = renderBlock(_props);
1738
1819
  }
1739
- return /* @__PURE__ */ jsxs("div", { ...attributes, className, children: [
1820
+ return /* @__PURE__ */ jsxs("div", __spreadProps$h(__spreadValues$n({}, attributes), { className, children: [
1740
1821
  children,
1741
1822
  /* @__PURE__ */ jsxs(DraggableBlock, { element, readOnly, blockRef, children: [
1742
1823
  renderedBlockFromProps && /* @__PURE__ */ jsx("div", { ref: blockRef, contentEditable: !1, children: renderedBlockFromProps }),
1743
1824
  !renderedBlockFromProps && /* @__PURE__ */ jsx(DefaultBlockObject, { selected, children: /* @__PURE__ */ jsx(DefaultObject, { value }) })
1744
1825
  ] })
1745
- ] }, element._key);
1826
+ ] }), element._key);
1746
1827
  };
1747
1828
  Element.displayName = "Element";
1748
1829
  const PortableTextEditorContext = createContext(null), usePortableTextEditor = () => {
@@ -1770,6 +1851,14 @@ function compileType(rawType) {
1770
1851
  types: [rawType]
1771
1852
  }).get(rawType.name);
1772
1853
  }
1854
+ var __defProp$m = Object.defineProperty, __defProps$g = Object.defineProperties, __getOwnPropDescs$g = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$m = Object.getOwnPropertySymbols, __hasOwnProp$m = Object.prototype.hasOwnProperty, __propIsEnum$m = Object.prototype.propertyIsEnumerable, __defNormalProp$m = (obj, key, value) => key in obj ? __defProp$m(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$m = (a, b) => {
1855
+ for (var prop in b || (b = {}))
1856
+ __hasOwnProp$m.call(b, prop) && __defNormalProp$m(a, prop, b[prop]);
1857
+ if (__getOwnPropSymbols$m)
1858
+ for (var prop of __getOwnPropSymbols$m(b))
1859
+ __propIsEnum$m.call(b, prop) && __defNormalProp$m(a, prop, b[prop]);
1860
+ return a;
1861
+ }, __spreadProps$g = (a, b) => __defProps$g(a, __getOwnPropDescs$g(b));
1773
1862
  function validateValue(value, types, keyGenerator) {
1774
1863
  let resolution = null, valid = !0;
1775
1864
  const validChildTypes = [types.span.name, ...types.inlineObjects.map((t) => t.name)], validBlockTypes = [types.block.name, ...types.blockObjects.map((t) => t.name)];
@@ -1807,10 +1896,9 @@ function validateValue(value, types, keyGenerator) {
1807
1896
  }, !0;
1808
1897
  if (!blk._key || typeof blk._key != "string")
1809
1898
  return resolution = {
1810
- patches: [set({
1811
- ...blk,
1899
+ patches: [set(__spreadProps$g(__spreadValues$m({}, blk), {
1812
1900
  _key: keyGenerator()
1813
- }, [index])],
1901
+ }), [index])],
1814
1902
  description: `Block at index ${index} is missing required _key.`,
1815
1903
  action: "Set the block with a random _key value",
1816
1904
  item: blk,
@@ -1826,10 +1914,9 @@ function validateValue(value, types, keyGenerator) {
1826
1914
  if (blk._type === "block") {
1827
1915
  const currentBlockTypeName = types.block.name;
1828
1916
  return resolution = {
1829
- patches: [set({
1830
- ...blk,
1917
+ patches: [set(__spreadProps$g(__spreadValues$m({}, blk), {
1831
1918
  _type: currentBlockTypeName
1832
- }, [{
1919
+ }), [{
1833
1920
  _key: blk._key
1834
1921
  }])],
1835
1922
  description: `Block with _key '${blk._key}' has invalid type name '${blk._type}'. According to the schema, the block type name is '${currentBlockTypeName}'`,
@@ -1845,14 +1932,12 @@ function validateValue(value, types, keyGenerator) {
1845
1932
  }
1846
1933
  }, !0;
1847
1934
  }
1848
- return !blk._type && isPortableTextTextBlock({
1849
- ...blk,
1935
+ return !blk._type && isPortableTextTextBlock(__spreadProps$g(__spreadValues$m({}, blk), {
1850
1936
  _type: types.block.name
1851
- }) ? (resolution = {
1852
- patches: [set({
1853
- ...blk,
1937
+ })) ? (resolution = {
1938
+ patches: [set(__spreadProps$g(__spreadValues$m({}, blk), {
1854
1939
  _type: types.block.name
1855
- }, [{
1940
+ }), [{
1856
1941
  _key: blk._key
1857
1942
  }])],
1858
1943
  description: `Block with _key '${blk._key}' is missing a type name. According to the schema, the block type name is '${types.block.name}'`,
@@ -2012,10 +2097,9 @@ function validateValue(value, types, keyGenerator) {
2012
2097
  }
2013
2098
  }, !0;
2014
2099
  if (!child._key || typeof child._key != "string") {
2015
- const newChild = {
2016
- ...child,
2100
+ const newChild = __spreadProps$g(__spreadValues$m({}, child), {
2017
2101
  _key: keyGenerator()
2018
- };
2102
+ });
2019
2103
  return resolution = {
2020
2104
  autoResolve: !0,
2021
2105
  patches: [set(newChild, [{
@@ -2035,10 +2119,9 @@ function validateValue(value, types, keyGenerator) {
2035
2119
  }, !0;
2036
2120
  }
2037
2121
  return child._type ? validChildTypes.includes(child._type) ? child._type === types.span.name && typeof child.text != "string" ? (resolution = {
2038
- patches: [set({
2039
- ...child,
2122
+ patches: [set(__spreadProps$g(__spreadValues$m({}, child), {
2040
2123
  text: ""
2041
- }, [{
2124
+ }), [{
2042
2125
  _key: blk._key
2043
2126
  }, "children", {
2044
2127
  _key: child._key
@@ -2449,11 +2532,10 @@ function createDeadLine(timeout) {
2449
2532
  return typeof timeout < "u" && (t = timeout <= 0 ? Number.MAX_VALUE : timeout), Date.now() + t * 1e3;
2450
2533
  }
2451
2534
  function createInternalOpts(opts) {
2452
- return {
2535
+ return __spreadValues({
2453
2536
  checkLines: !0,
2454
- deadline: createDeadLine(opts.timeout || 1),
2455
- ...opts
2456
- };
2537
+ deadline: createDeadLine(opts.timeout || 1)
2538
+ }, opts);
2457
2539
  }
2458
2540
  function combineChar(data, char, dir) {
2459
2541
  return dir === 1 ? data + char : char + data;
@@ -2517,10 +2599,7 @@ const DEFAULT_OPTIONS = {
2517
2599
  distance: 1e3
2518
2600
  };
2519
2601
  function applyDefaults(options) {
2520
- return {
2521
- ...DEFAULT_OPTIONS,
2522
- ...options
2523
- };
2602
+ return __spreadValues(__spreadValues({}, DEFAULT_OPTIONS), options);
2524
2603
  }
2525
2604
  const MAX_BITS$1 = 32;
2526
2605
  function bitap(text, pattern, loc) {
@@ -2792,7 +2871,7 @@ function parse(textline) {
2792
2871
  let line;
2793
2872
  try {
2794
2873
  line = decodeURI(currentLine.slice(1));
2795
- } catch {
2874
+ } catch (ex) {
2796
2875
  throw new Error("Illegal escape in parse: ".concat(currentLine));
2797
2876
  }
2798
2877
  const utf8Diff = countUtf8Bytes(line) - line.length;
@@ -2818,7 +2897,8 @@ function withUndoing(editor, fn) {
2818
2897
  IS_UDOING.set(editor, !0), fn(), IS_UDOING.set(editor, prev);
2819
2898
  }
2820
2899
  function isUndoing(editor) {
2821
- return IS_UDOING.get(editor) ?? !1;
2900
+ var _a;
2901
+ return (_a = IS_UDOING.get(editor)) != null ? _a : !1;
2822
2902
  }
2823
2903
  function setIsUndoing(editor, isUndoing2) {
2824
2904
  IS_UDOING.set(editor, isUndoing2);
@@ -2828,11 +2908,20 @@ function withRedoing(editor, fn) {
2828
2908
  IS_REDOING.set(editor, !0), fn(), IS_REDOING.set(editor, prev);
2829
2909
  }
2830
2910
  function isRedoing(editor) {
2831
- return IS_REDOING.get(editor) ?? !1;
2911
+ var _a;
2912
+ return (_a = IS_REDOING.get(editor)) != null ? _a : !1;
2832
2913
  }
2833
2914
  function setIsRedoing(editor, isRedoing2) {
2834
2915
  IS_REDOING.set(editor, isRedoing2);
2835
2916
  }
2917
+ var __defProp$l = Object.defineProperty, __getOwnPropSymbols$l = Object.getOwnPropertySymbols, __hasOwnProp$l = Object.prototype.hasOwnProperty, __propIsEnum$l = Object.prototype.propertyIsEnumerable, __defNormalProp$l = (obj, key, value) => key in obj ? __defProp$l(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$l = (a, b) => {
2918
+ for (var prop in b || (b = {}))
2919
+ __hasOwnProp$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
2920
+ if (__getOwnPropSymbols$l)
2921
+ for (var prop of __getOwnPropSymbols$l(b))
2922
+ __propIsEnum$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
2923
+ return a;
2924
+ };
2836
2925
  const debug$j = debugWithName("plugin:withUndoRedo"), debugVerbose$4 = debug$j.enabled && !1, SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
2837
2926
  const state = SAVING.get(editor);
2838
2927
  return state === void 0 ? !0 : state;
@@ -2989,9 +3078,7 @@ function createWithUndoRedo(options) {
2989
3078
  }
2990
3079
  function transformOperation(editor, patch, operation, snapshot, previousSnapshot) {
2991
3080
  debugVerbose$4 && (debug$j(`Adjusting '${operation.type}' operation paths for '${patch.type}' patch`), debug$j(`Operation ${JSON.stringify(operation)}`), debug$j(`Patch ${JSON.stringify(patch)}`));
2992
- const transformedOperation = {
2993
- ...operation
2994
- };
3081
+ const transformedOperation = __spreadValues$l({}, operation);
2995
3082
  if (patch.type === "insert" && patch.path.length === 1) {
2996
3083
  const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual({
2997
3084
  _key: blk._key
@@ -3011,6 +3098,7 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
3011
3098
  return !operationTargetBlock || !isEqual({
3012
3099
  _key: operationTargetBlock._key
3013
3100
  }, patch.path[0]) ? [transformedOperation] : (parse(patch.value).forEach((diffPatch) => {
3101
+ var _a, _b, _c, _d;
3014
3102
  let adjustOffsetBy = 0, changedOffset = diffPatch.utf8Start1;
3015
3103
  const {
3016
3104
  diffs
@@ -3019,15 +3107,7 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
3019
3107
  const [diffType, text] = diff2;
3020
3108
  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));
3021
3109
  }), 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") {
3022
- const currentFocus = transformedOperation.properties?.focus ? {
3023
- ...transformedOperation.properties.focus
3024
- } : void 0, currentAnchor = transformedOperation?.properties?.anchor ? {
3025
- ...transformedOperation.properties.anchor
3026
- } : void 0, newFocus = transformedOperation?.newProperties?.focus ? {
3027
- ...transformedOperation.newProperties.focus
3028
- } : void 0, newAnchor = transformedOperation?.newProperties?.anchor ? {
3029
- ...transformedOperation.newProperties.anchor
3030
- } : void 0;
3110
+ const currentFocus = (_a = transformedOperation.properties) != null && _a.focus ? __spreadValues$l({}, transformedOperation.properties.focus) : void 0, currentAnchor = (_b = transformedOperation == null ? void 0 : transformedOperation.properties) != null && _b.anchor ? __spreadValues$l({}, transformedOperation.properties.anchor) : void 0, newFocus = (_c = transformedOperation == null ? void 0 : transformedOperation.newProperties) != null && _c.focus ? __spreadValues$l({}, transformedOperation.newProperties.focus) : void 0, newAnchor = (_d = transformedOperation == null ? void 0 : transformedOperation.newProperties) != null && _d.anchor ? __spreadValues$l({}, transformedOperation.newProperties.anchor) : void 0;
3031
3111
  (currentFocus && currentAnchor || newFocus && newAnchor) && ([currentFocus, currentAnchor, newFocus, newAnchor].forEach((point) => {
3032
3112
  point && changedOffset < point.offset && (point.offset += adjustOffsetBy);
3033
3113
  }), currentFocus && currentAnchor && (transformedOperation.properties = {
@@ -3043,23 +3123,14 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
3043
3123
  return [transformedOperation];
3044
3124
  }
3045
3125
  function adjustBlockPath(operation, level, blockIndex) {
3046
- const transformedOperation = {
3047
- ...operation
3048
- };
3126
+ var _a, _b, _c, _d;
3127
+ const transformedOperation = __spreadValues$l({}, operation);
3049
3128
  if (blockIndex >= 0 && transformedOperation.type !== "set_selection" && Array.isArray(transformedOperation.path) && transformedOperation.path[0] >= blockIndex + level && transformedOperation.path[0] + level > -1) {
3050
3129
  const newPath = [transformedOperation.path[0] + level, ...transformedOperation.path.slice(1)];
3051
3130
  transformedOperation.path = newPath;
3052
3131
  }
3053
3132
  if (transformedOperation.type === "set_selection") {
3054
- const currentFocus = transformedOperation.properties?.focus ? {
3055
- ...transformedOperation.properties.focus
3056
- } : void 0, currentAnchor = transformedOperation?.properties?.anchor ? {
3057
- ...transformedOperation.properties.anchor
3058
- } : void 0, newFocus = transformedOperation?.newProperties?.focus ? {
3059
- ...transformedOperation.newProperties.focus
3060
- } : void 0, newAnchor = transformedOperation?.newProperties?.anchor ? {
3061
- ...transformedOperation.newProperties.anchor
3062
- } : void 0;
3133
+ const currentFocus = (_a = transformedOperation.properties) != null && _a.focus ? __spreadValues$l({}, transformedOperation.properties.focus) : void 0, currentAnchor = (_b = transformedOperation == null ? void 0 : transformedOperation.properties) != null && _b.anchor ? __spreadValues$l({}, transformedOperation.properties.anchor) : void 0, newFocus = (_c = transformedOperation == null ? void 0 : transformedOperation.newProperties) != null && _c.focus ? __spreadValues$l({}, transformedOperation.newProperties.focus) : void 0, newAnchor = (_d = transformedOperation == null ? void 0 : transformedOperation.newProperties) != null && _d.anchor ? __spreadValues$l({}, transformedOperation.newProperties.anchor) : void 0;
3063
3134
  (currentFocus && currentAnchor || newFocus && newAnchor) && ([currentFocus, currentAnchor, newFocus, newAnchor].forEach((point) => {
3064
3135
  point && point.path[0] >= blockIndex + level && point.path[0] + level > -1 && (point.path = [point.path[0] + level, ...point.path.slice(1)]);
3065
3136
  }), currentFocus && currentAnchor && (transformedOperation.properties = {
@@ -3080,12 +3151,8 @@ function withoutSaving(editor, fn) {
3080
3151
  function createSelectOperation(editor) {
3081
3152
  return {
3082
3153
  type: "set_selection",
3083
- properties: {
3084
- ...editor.selection
3085
- },
3086
- newProperties: {
3087
- ...editor.selection
3088
- }
3154
+ properties: __spreadValues$l({}, editor.selection),
3155
+ newProperties: __spreadValues$l({}, editor.selection)
3089
3156
  };
3090
3157
  }
3091
3158
  function findOperationTargetBlock(editor, operation) {
@@ -3099,7 +3166,7 @@ function useSyncValue(props) {
3099
3166
  portableTextEditor,
3100
3167
  readOnly,
3101
3168
  slateEditor
3102
- } = props, schemaTypes = editorActor.getSnapshot().context.schema, previousValue = useRef(), updateValueFunctionRef = useRef(), updateFromCurrentValue = useCallback(() => {
3169
+ } = props, schemaTypes = editorActor.getSnapshot().context.schema, previousValue = useRef(void 0), updateValueFunctionRef = useRef(void 0), updateFromCurrentValue = useCallback(() => {
3103
3170
  const currentValue = CURRENT_VALUE.get(portableTextEditor);
3104
3171
  if (previousValue.current === currentValue) {
3105
3172
  debug$i("Value is the same object as previous, not need to sync");
@@ -3159,15 +3226,16 @@ function useSyncValue(props) {
3159
3226
  isChanged = !0;
3160
3227
  }
3161
3228
  slateValueFromProps.forEach((currentBlock, currentBlockIndex) => {
3229
+ var _a, _b, _c, _d, _e;
3162
3230
  const oldBlock = slateEditor.children[currentBlockIndex];
3163
3231
  if (oldBlock && !isEqual(currentBlock, oldBlock) && isValid) {
3164
3232
  const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
3165
- !validation.valid && validation.resolution?.autoResolve && validation.resolution?.patches.length > 0 && !readOnly && previousValue.current && previousValue.current !== value && (console.warn(`${validation.resolution.action} for block with _key '${validationValue[0]._key}'. ${validation.resolution?.description}`), validation.resolution.patches.forEach((patch) => {
3233
+ !validation.valid && (_a = validation.resolution) != null && _a.autoResolve && ((_b = validation.resolution) == null ? void 0 : _b.patches.length) > 0 && !readOnly && previousValue.current && previousValue.current !== value && (console.warn(`${validation.resolution.action} for block with _key '${validationValue[0]._key}'. ${(_c = validation.resolution) == null ? void 0 : _c.description}`), validation.resolution.patches.forEach((patch) => {
3166
3234
  editorActor.send({
3167
3235
  type: "patch",
3168
3236
  patch
3169
3237
  });
3170
- })), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$i.enabled && debug$i("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$i.enabled && debug$i("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), isChanged = !0) : (editorActor.send({
3238
+ })), validation.valid || (_d = validation.resolution) != null && _d.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$i.enabled && debug$i("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$i.enabled && debug$i("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), isChanged = !0) : (editorActor.send({
3171
3239
  type: "invalid value",
3172
3240
  resolution: validation.resolution,
3173
3241
  value
@@ -3175,7 +3243,7 @@ function useSyncValue(props) {
3175
3243
  }
3176
3244
  if (!oldBlock && isValid) {
3177
3245
  const validationValue_0 = [value[currentBlockIndex]], validation_0 = validateValue(validationValue_0, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
3178
- debug$i.enabled && debug$i("Validating and inserting new block in the end of the value", currentBlock), validation_0.valid || validation_0.resolution?.autoResolve ? Transforms.insertNodes(slateEditor, currentBlock, {
3246
+ debug$i.enabled && debug$i("Validating and inserting new block in the end of the value", currentBlock), validation_0.valid || (_e = validation_0.resolution) != null && _e.autoResolve ? Transforms.insertNodes(slateEditor, currentBlock, {
3179
3247
  at: [currentBlockIndex]
3180
3248
  }) : (debug$i("Invalid", validation_0), editorActor.send({
3181
3249
  type: "invalid value",
@@ -3244,9 +3312,9 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
3244
3312
  at: [currentBlockIndex, childIndex]
3245
3313
  }));
3246
3314
  }), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
3247
- const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual(currentBlockChild, oldBlockChild), isTextChanged = !isEqual(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
3315
+ const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual(currentBlockChild, oldBlockChild), isTextChanged = !isEqual(currentBlockChild.text, oldBlockChild == null ? void 0 : oldBlockChild.text), path = [currentBlockIndex, currentBlockChildIndex];
3248
3316
  if (isChildChanged)
3249
- if (currentBlockChild._key === oldBlockChild?._key) {
3317
+ if (currentBlockChild._key === (oldBlockChild == null ? void 0 : oldBlockChild._key)) {
3250
3318
  debug$i("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
3251
3319
  at: path
3252
3320
  });
@@ -3357,6 +3425,14 @@ function _temp(s) {
3357
3425
  return s.context.readOnly;
3358
3426
  }
3359
3427
  Synchronizer.displayName = "Synchronizer";
3428
+ var __defProp$k = Object.defineProperty, __defProps$f = Object.defineProperties, __getOwnPropDescs$f = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$k = Object.getOwnPropertySymbols, __hasOwnProp$k = Object.prototype.hasOwnProperty, __propIsEnum$k = Object.prototype.propertyIsEnumerable, __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$k = (a, b) => {
3429
+ for (var prop in b || (b = {}))
3430
+ __hasOwnProp$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
3431
+ if (__getOwnPropSymbols$k)
3432
+ for (var prop of __getOwnPropSymbols$k(b))
3433
+ __propIsEnum$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
3434
+ return a;
3435
+ }, __spreadProps$f = (a, b) => __defProps$f(a, __getOwnPropDescs$f(b));
3360
3436
  const debug$g = debugWithName("operationToPatches");
3361
3437
  function createOperationToPatches(types) {
3362
3438
  const textBlockName = types.block.name;
@@ -3396,10 +3472,7 @@ function createOperationToPatches(types) {
3396
3472
  const block = editor.children[operation.path[0]];
3397
3473
  if (typeof block._key != "string")
3398
3474
  throw new Error("Expected block to have a _key");
3399
- const setNode = omitBy({
3400
- ...editor.children[operation.path[0]],
3401
- ...operation.newProperties
3402
- }, isUndefined);
3475
+ const setNode = omitBy(__spreadValues$k(__spreadValues$k({}, editor.children[operation.path[0]]), operation.newProperties), isUndefined);
3403
3476
  return [set(fromSlateValue([setNode], textBlockName)[0], [{
3404
3477
  _key: block._key
3405
3478
  }])];
@@ -3434,14 +3507,12 @@ function createOperationToPatches(types) {
3434
3507
  function insertNodePatch(editor, operation, beforeValue) {
3435
3508
  const block = beforeValue[operation.path[0]], isTextBlock = editor.isTextBlock(block);
3436
3509
  if (operation.path.length === 1) {
3437
- const position = operation.path[0] === 0 ? "before" : "after", beforeBlock = beforeValue[operation.path[0] - 1], targetKey = operation.path[0] === 0 ? block?._key : beforeBlock?._key;
3510
+ const position = operation.path[0] === 0 ? "before" : "after", beforeBlock = beforeValue[operation.path[0] - 1], targetKey = operation.path[0] === 0 ? block == null ? void 0 : block._key : beforeBlock == null ? void 0 : beforeBlock._key;
3438
3511
  return targetKey ? [insert([fromSlateValue([operation.node], textBlockName)[0]], position, [{
3439
3512
  _key: targetKey
3440
3513
  }])] : [setIfMissing(beforeValue, []), insert([fromSlateValue([operation.node], textBlockName)[0]], "before", [operation.path[0]])];
3441
3514
  } else if (isTextBlock && operation.path.length === 2 && editor.children[operation.path[0]]) {
3442
- const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node = {
3443
- ...operation.node
3444
- };
3515
+ const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node = __spreadValues$k({}, operation.node);
3445
3516
  !node._type && Text.isText(node) && (node._type = "span", node.marks = []);
3446
3517
  const child = fromSlateValue([{
3447
3518
  _key: "bogus",
@@ -3480,10 +3551,9 @@ function createOperationToPatches(types) {
3480
3551
  if (operation.path.length === 2) {
3481
3552
  const splitSpan = splitBlock.children[operation.path[1]];
3482
3553
  if (editor.isTextSpan(splitSpan)) {
3483
- const targetSpans = fromSlateValue([{
3484
- ...splitBlock,
3554
+ const targetSpans = fromSlateValue([__spreadProps$f(__spreadValues$k({}, splitBlock), {
3485
3555
  children: splitBlock.children.slice(operation.path[1] + 1, operation.path[1] + 2)
3486
- }], textBlockName)[0].children;
3556
+ })], textBlockName)[0].children;
3487
3557
  patches.push(insert(targetSpans, "after", [{
3488
3558
  _key: splitBlock._key
3489
3559
  }, "children", {
@@ -3519,7 +3589,7 @@ function createOperationToPatches(types) {
3519
3589
  function mergeNodePatch(editor, operation, beforeValue) {
3520
3590
  const patches = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
3521
3591
  if (operation.path.length === 1)
3522
- if (block?._key) {
3592
+ if (block != null && block._key) {
3523
3593
  const newBlock = fromSlateValue([editor.children[operation.path[0] - 1]], textBlockName)[0];
3524
3594
  patches.push(set(newBlock, [{
3525
3595
  _key: newBlock._key
@@ -3791,6 +3861,7 @@ function createWithMaxBlocks(editorActor) {
3791
3861
  apply: apply2
3792
3862
  } = editor;
3793
3863
  return editor.apply = (operation) => {
3864
+ var _a;
3794
3865
  if (editorActor.getSnapshot().context.readOnly) {
3795
3866
  apply2(operation);
3796
3867
  return;
@@ -3803,11 +3874,19 @@ function createWithMaxBlocks(editorActor) {
3803
3874
  apply2(operation);
3804
3875
  return;
3805
3876
  }
3806
- const rows = editorActor.getSnapshot().context.maxBlocks ?? -1;
3877
+ const rows = (_a = editorActor.getSnapshot().context.maxBlocks) != null ? _a : -1;
3807
3878
  rows > 0 && editor.children.length >= rows && (operation.type === "insert_node" || operation.type === "split_node") && operation.path.length === 1 || apply2(operation);
3808
3879
  }, editor;
3809
3880
  };
3810
3881
  }
3882
+ var __defProp$j = Object.defineProperty, __defProps$e = Object.defineProperties, __getOwnPropDescs$e = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$j = Object.getOwnPropertySymbols, __hasOwnProp$j = Object.prototype.hasOwnProperty, __propIsEnum$j = Object.prototype.propertyIsEnumerable, __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$j = (a, b) => {
3883
+ for (var prop in b || (b = {}))
3884
+ __hasOwnProp$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
3885
+ if (__getOwnPropSymbols$j)
3886
+ for (var prop of __getOwnPropSymbols$j(b))
3887
+ __propIsEnum$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
3888
+ return a;
3889
+ }, __spreadProps$e = (a, b) => __defProps$e(a, __getOwnPropDescs$e(b));
3811
3890
  function createWithObjectKeys(editorActor, schemaTypes) {
3812
3891
  return function(editor) {
3813
3892
  const {
@@ -3824,23 +3903,19 @@ function createWithObjectKeys(editorActor, schemaTypes) {
3824
3903
  return;
3825
3904
  }
3826
3905
  if (operation.type === "split_node") {
3827
- apply2({
3828
- ...operation,
3829
- properties: {
3830
- ...operation.properties,
3906
+ apply2(__spreadProps$e(__spreadValues$j({}, operation), {
3907
+ properties: __spreadProps$e(__spreadValues$j({}, operation.properties), {
3831
3908
  _key: editorActor.getSnapshot().context.keyGenerator()
3832
- }
3833
- });
3909
+ })
3910
+ }));
3834
3911
  return;
3835
3912
  }
3836
3913
  if (operation.type === "insert_node" && !Editor.isEditor(operation.node)) {
3837
- apply2({
3838
- ...operation,
3839
- node: {
3840
- ...operation.node,
3914
+ apply2(__spreadProps$e(__spreadValues$j({}, operation), {
3915
+ node: __spreadProps$e(__spreadValues$j({}, operation.node), {
3841
3916
  _key: editorActor.getSnapshot().context.keyGenerator()
3842
- }
3843
- });
3917
+ })
3918
+ }));
3844
3919
  return;
3845
3920
  }
3846
3921
  apply2(operation);
@@ -3877,6 +3952,22 @@ function createWithObjectKeys(editorActor, schemaTypes) {
3877
3952
  }, editor;
3878
3953
  };
3879
3954
  }
3955
+ var __defProp$i = Object.defineProperty, __defProps$d = Object.defineProperties, __getOwnPropDescs$d = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$i = Object.getOwnPropertySymbols, __hasOwnProp$i = Object.prototype.hasOwnProperty, __propIsEnum$i = Object.prototype.propertyIsEnumerable, __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$i = (a, b) => {
3956
+ for (var prop in b || (b = {}))
3957
+ __hasOwnProp$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
3958
+ if (__getOwnPropSymbols$i)
3959
+ for (var prop of __getOwnPropSymbols$i(b))
3960
+ __propIsEnum$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
3961
+ return a;
3962
+ }, __spreadProps$d = (a, b) => __defProps$d(a, __getOwnPropDescs$d(b)), __objRest$2 = (source, exclude) => {
3963
+ var target = {};
3964
+ for (var prop in source)
3965
+ __hasOwnProp$i.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
3966
+ if (source != null && __getOwnPropSymbols$i)
3967
+ for (var prop of __getOwnPropSymbols$i(source))
3968
+ exclude.indexOf(prop) < 0 && __propIsEnum$i.call(source, prop) && (target[prop] = source[prop]);
3969
+ return target;
3970
+ };
3880
3971
  const debug$f = debugWithName("applyPatches"), debugVerbose$2 = debug$f.enabled && !0;
3881
3972
  function createApplyPatch(schemaTypes) {
3882
3973
  return (editor, patch) => {
@@ -3966,10 +4057,9 @@ function insertPatch(editor, patch, schemaTypes) {
3966
4057
  } = patch;
3967
4058
  if (!targetChild || !targetChildPath)
3968
4059
  return debug$f("Child not found"), !1;
3969
- const childrenToInsert = targetBlock && toSlateValue([{
3970
- ...targetBlock,
4060
+ const childrenToInsert = targetBlock && toSlateValue([__spreadProps$d(__spreadValues$i({}, targetBlock), {
3971
4061
  children: items
3972
- }], {
4062
+ })], {
3973
4063
  schemaTypes
3974
4064
  }, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
3975
4065
  return debug$f(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && Element$1.isElement(childrenToInsert[0]) && Transforms.insertNodes(editor, childrenToInsert[0].children, {
@@ -4014,21 +4104,19 @@ function setPatch(editor, patch) {
4014
4104
  return !0;
4015
4105
  } else if (Element$1.isElement(block) && patch.path.length === 1 && blockPath) {
4016
4106
  debug$f("Setting block property");
4017
- const {
4018
- children,
4019
- ...nextRest
4020
- } = value, {
4021
- children: prevChildren,
4022
- ...prevRest
4023
- } = block || {
4107
+ const _a = value, {
4108
+ children
4109
+ } = _a, nextRest = __objRest$2(_a, [
4110
+ "children"
4111
+ ]), _b = block || {
4024
4112
  children: void 0
4025
- };
4113
+ }, prevRest = __objRest$2(_b, [
4114
+ "children"
4115
+ ]);
4026
4116
  editor.apply({
4027
4117
  type: "set_node",
4028
4118
  path: blockPath,
4029
- properties: {
4030
- ...prevRest
4031
- },
4119
+ properties: __spreadValues$i({}, prevRest),
4032
4120
  newProperties: nextRest
4033
4121
  }), debug$f("Setting children"), block.children.forEach((c2, cIndex) => {
4034
4122
  editor.apply({
@@ -4045,10 +4133,9 @@ function setPatch(editor, patch) {
4045
4133
  });
4046
4134
  } else if (block && "value" in block) {
4047
4135
  const newVal = applyAll([block.value], [patch])[0];
4048
- return Transforms.setNodes(editor, {
4049
- ...block,
4136
+ return Transforms.setNodes(editor, __spreadProps$d(__spreadValues$i({}, block), {
4050
4137
  value: newVal
4051
- }, {
4138
+ }), {
4052
4139
  at: blockPath
4053
4140
  }), !0;
4054
4141
  }
@@ -4131,7 +4218,7 @@ function findBlockAndChildFromPath(editor, path) {
4131
4218
  block,
4132
4219
  child,
4133
4220
  blockPath,
4134
- childPath: blockPath?.concat(childIndex)
4221
+ childPath: blockPath == null ? void 0 : blockPath.concat(childIndex)
4135
4222
  } : {
4136
4223
  block,
4137
4224
  blockPath,
@@ -4139,6 +4226,14 @@ function findBlockAndChildFromPath(editor, path) {
4139
4226
  childPath: void 0
4140
4227
  };
4141
4228
  }
4229
+ var __defProp$h = Object.defineProperty, __defProps$c = Object.defineProperties, __getOwnPropDescs$c = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$h = Object.getOwnPropertySymbols, __hasOwnProp$h = Object.prototype.hasOwnProperty, __propIsEnum$h = Object.prototype.propertyIsEnumerable, __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$h = (a, b) => {
4230
+ for (var prop in b || (b = {}))
4231
+ __hasOwnProp$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
4232
+ if (__getOwnPropSymbols$h)
4233
+ for (var prop of __getOwnPropSymbols$h(b))
4234
+ __propIsEnum$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
4235
+ return a;
4236
+ }, __spreadProps$c = (a, b) => __defProps$c(a, __getOwnPropDescs$c(b));
4142
4237
  const debug$e = debugWithName("plugin:withPatches");
4143
4238
  function createWithPatches({
4144
4239
  editorActor,
@@ -4225,10 +4320,9 @@ function createWithPatches({
4225
4320
  })), editorWasEmpty && patches.length > 0 && (patches = [setIfMissing([], []), ...patches]), patches.length > 0 && patches.forEach((patch) => {
4226
4321
  editorActor.send({
4227
4322
  type: "patch",
4228
- patch: {
4229
- ...patch,
4323
+ patch: __spreadProps$c(__spreadValues$h({}, patch), {
4230
4324
  origin: "local"
4231
- }
4325
+ })
4232
4326
  });
4233
4327
  }), editor;
4234
4328
  }, editor;
@@ -4339,6 +4433,14 @@ function getNextSpan({
4339
4433
  }
4340
4434
  return nextSpan;
4341
4435
  }
4436
+ var __defProp$g = Object.defineProperty, __defProps$b = Object.defineProperties, __getOwnPropDescs$b = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$g = Object.getOwnPropertySymbols, __hasOwnProp$g = Object.prototype.hasOwnProperty, __propIsEnum$g = Object.prototype.propertyIsEnumerable, __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$g = (a, b) => {
4437
+ for (var prop in b || (b = {}))
4438
+ __hasOwnProp$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
4439
+ if (__getOwnPropSymbols$g)
4440
+ for (var prop of __getOwnPropSymbols$g(b))
4441
+ __propIsEnum$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
4442
+ return a;
4443
+ }, __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
4342
4444
  const debug$b = debugWithName("plugin:withPortableTextMarkModel");
4343
4445
  function createWithPortableTextMarkModel(editorActor, types) {
4344
4446
  return function(editor) {
@@ -4347,12 +4449,19 @@ function createWithPortableTextMarkModel(editorActor, types) {
4347
4449
  normalizeNode
4348
4450
  } = editor, decorators = types.decorators.map((t) => t.value);
4349
4451
  return editor.normalizeNode = (nodeEntry) => {
4452
+ var _a, _b, _c, _d, _e, _f, _g;
4350
4453
  const [node, path] = nodeEntry;
4351
4454
  if (editor.isTextBlock(node)) {
4352
4455
  const children = Node.children(editor, path);
4353
4456
  for (const [child, childPath] of children) {
4354
4457
  const nextNode = node.children[childPath[1] + 1];
4355
- if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
4458
+ if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && (_a = child.marks) != null && _a.every((mark) => {
4459
+ var _a2;
4460
+ return (_a2 = nextNode.marks) == null ? void 0 : _a2.includes(mark);
4461
+ }) && (_b = nextNode.marks) != null && _b.every((mark) => {
4462
+ var _a2;
4463
+ return (_a2 = child.marks) == null ? void 0 : _a2.includes(mark);
4464
+ })) {
4356
4465
  debug$b("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
4357
4466
  type: "normalizing"
4358
4467
  }), Transforms.mergeNodes(editor, {
@@ -4390,12 +4499,12 @@ function createWithPortableTextMarkModel(editorActor, types) {
4390
4499
  return;
4391
4500
  }
4392
4501
  if (editor.isTextSpan(node)) {
4393
- const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath), decorators2 = types.decorators.map((decorator) => decorator.value), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
4502
+ const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath), decorators2 = types.decorators.map((decorator) => decorator.value), annotations = (_c = node.marks) == null ? void 0 : _c.filter((mark) => !decorators2.includes(mark));
4394
4503
  if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
4395
4504
  debug$b("Removing annotations from empty span node"), editorActor.send({
4396
4505
  type: "normalizing"
4397
4506
  }), Transforms.setNodes(editor, {
4398
- marks: node.marks?.filter((mark) => decorators2.includes(mark))
4507
+ marks: (_d = node.marks) == null ? void 0 : _d.filter((mark) => decorators2.includes(mark))
4399
4508
  }, {
4400
4509
  at: path
4401
4510
  }), editorActor.send({
@@ -4408,7 +4517,10 @@ function createWithPortableTextMarkModel(editorActor, types) {
4408
4517
  const decorators2 = types.decorators.map((decorator) => decorator.value);
4409
4518
  for (const [child, childPath] of Node.children(editor, path))
4410
4519
  if (editor.isTextSpan(child)) {
4411
- const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
4520
+ const marks = (_e = child.marks) != null ? _e : [], orphanedAnnotations = marks.filter((mark) => {
4521
+ var _a2;
4522
+ return !decorators2.includes(mark) && !((_a2 = node.markDefs) != null && _a2.find((def) => def._key === mark));
4523
+ });
4412
4524
  if (orphanedAnnotations.length > 0) {
4413
4525
  debug$b("Removing orphaned annotations from span node"), editorActor.send({
4414
4526
  type: "normalizing"
@@ -4426,7 +4538,10 @@ function createWithPortableTextMarkModel(editorActor, types) {
4426
4538
  if (editor.isTextSpan(node)) {
4427
4539
  const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath);
4428
4540
  if (editor.isTextBlock(block)) {
4429
- const decorators2 = types.decorators.map((decorator) => decorator.value), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
4541
+ const decorators2 = types.decorators.map((decorator) => decorator.value), marks = (_f = node.marks) != null ? _f : [], orphanedAnnotations = marks.filter((mark) => {
4542
+ var _a2;
4543
+ return !decorators2.includes(mark) && !((_a2 = block.markDefs) != null && _a2.find((def) => def._key === mark));
4544
+ });
4430
4545
  if (orphanedAnnotations.length > 0) {
4431
4546
  debug$b("Removing orphaned annotations from span node"), editorActor.send({
4432
4547
  type: "normalizing"
@@ -4442,7 +4557,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
4442
4557
  }
4443
4558
  }
4444
4559
  if (editor.isTextBlock(node)) {
4445
- const markDefs = node.markDefs ?? [], markDefKeys = /* @__PURE__ */ new Set(), newMarkDefs = [];
4560
+ const markDefs = (_g = node.markDefs) != null ? _g : [], markDefKeys = /* @__PURE__ */ new Set(), newMarkDefs = [];
4446
4561
  for (const markDef of markDefs)
4447
4562
  markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
4448
4563
  if (markDefs.length !== newMarkDefs.length) {
@@ -4475,6 +4590,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
4475
4590
  }
4476
4591
  normalizeNode(nodeEntry);
4477
4592
  }, editor.apply = (op) => {
4593
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
4478
4594
  if (isChangingRemotely(editor)) {
4479
4595
  apply2(op);
4480
4596
  return;
@@ -4492,17 +4608,17 @@ function createWithPortableTextMarkModel(editorActor, types) {
4492
4608
  focus: op.newProperties.focus
4493
4609
  });
4494
4610
  if (previousSelectionIsCollapsed && newSelectionIsCollapsed) {
4495
- const focusSpan = Array.from(Editor.nodes(editor, {
4611
+ const focusSpan = (_a = Array.from(Editor.nodes(editor, {
4496
4612
  mode: "lowest",
4497
4613
  at: op.properties.focus,
4498
4614
  match: (n) => editor.isTextSpan(n),
4499
4615
  voids: !1
4500
- }))[0]?.[0], newFocusSpan = Array.from(Editor.nodes(editor, {
4616
+ }))[0]) == null ? void 0 : _a[0], newFocusSpan = (_b = Array.from(Editor.nodes(editor, {
4501
4617
  mode: "lowest",
4502
4618
  at: op.newProperties.focus,
4503
4619
  match: (n) => editor.isTextSpan(n),
4504
4620
  voids: !1
4505
- }))[0]?.[0], movedToNextSpan = focusSpan && newFocusSpan && op.newProperties.focus.path[0] === op.properties.focus.path[0] && op.newProperties.focus.path[1] === op.properties.focus.path[1] + 1 && focusSpan.text.length === op.properties.focus.offset && op.newProperties.focus.offset === 0, movedToPreviousSpan = focusSpan && newFocusSpan && op.newProperties.focus.path[0] === op.properties.focus.path[0] && op.newProperties.focus.path[1] === op.properties.focus.path[1] - 1 && op.properties.focus.offset === 0 && newFocusSpan.text.length === op.newProperties.focus.offset;
4621
+ }))[0]) == null ? void 0 : _b[0], movedToNextSpan = focusSpan && newFocusSpan && op.newProperties.focus.path[0] === op.properties.focus.path[0] && op.newProperties.focus.path[1] === op.properties.focus.path[1] + 1 && focusSpan.text.length === op.properties.focus.offset && op.newProperties.focus.offset === 0, movedToPreviousSpan = focusSpan && newFocusSpan && op.newProperties.focus.path[0] === op.properties.focus.path[0] && op.newProperties.focus.path[1] === op.properties.focus.path[1] - 1 && op.properties.focus.offset === 0 && newFocusSpan.text.length === op.newProperties.focus.offset;
4506
4622
  if (movedToNextSpan || movedToPreviousSpan)
4507
4623
  return;
4508
4624
  }
@@ -4518,32 +4634,29 @@ function createWithPortableTextMarkModel(editorActor, types) {
4518
4634
  editor,
4519
4635
  blockPath,
4520
4636
  spanPath: op.path
4521
- }), previousSpanAnnotations = previousSpan ? previousSpan.marks?.filter((mark) => !decorators.includes(mark)) : [], nextSpan = getNextSpan({
4637
+ }), previousSpanAnnotations = previousSpan ? (_c = previousSpan.marks) == null ? void 0 : _c.filter((mark) => !decorators.includes(mark)) : [], nextSpan = getNextSpan({
4522
4638
  editor,
4523
4639
  blockPath,
4524
4640
  spanPath: [op.path[0], op.path[1] - 1]
4525
- }), nextSpanAnnotations = nextSpan ? nextSpan.marks?.filter((mark) => !decorators.includes(mark)) : [], annotationsEnding = previousSpanAnnotations?.filter((annotation) => !nextSpanAnnotations?.includes(annotation)) ?? [], atTheEndOfAnnotation = annotationsEnding.length > 0;
4526
- if (atTheEndOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.some((mark) => annotationsEnding.includes(mark))) {
4527
- Transforms.insertNodes(editor, {
4528
- ...op.node,
4529
- marks: op.node.marks?.filter((mark) => !annotationsEnding.includes(mark)) ?? []
4530
- });
4641
+ }), nextSpanAnnotations = nextSpan ? (_d = nextSpan.marks) == null ? void 0 : _d.filter((mark) => !decorators.includes(mark)) : [], annotationsEnding = (_e = previousSpanAnnotations == null ? void 0 : previousSpanAnnotations.filter((annotation) => !(nextSpanAnnotations != null && nextSpanAnnotations.includes(annotation)))) != null ? _e : [], atTheEndOfAnnotation = annotationsEnding.length > 0;
4642
+ if (atTheEndOfAnnotation && isPortableTextSpan(op.node) && (_f = op.node.marks) != null && _f.some((mark) => annotationsEnding.includes(mark))) {
4643
+ Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$g({}, op.node), {
4644
+ marks: (_h = (_g = op.node.marks) == null ? void 0 : _g.filter((mark) => !annotationsEnding.includes(mark))) != null ? _h : []
4645
+ }));
4531
4646
  return;
4532
4647
  }
4533
- const annotationsStarting = nextSpanAnnotations?.filter((annotation) => !previousSpanAnnotations?.includes(annotation)) ?? [], atTheStartOfAnnotation = annotationsStarting.length > 0;
4534
- if (atTheStartOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.some((mark) => annotationsStarting.includes(mark))) {
4535
- Transforms.insertNodes(editor, {
4536
- ...op.node,
4537
- marks: op.node.marks?.filter((mark) => !annotationsStarting.includes(mark)) ?? []
4538
- });
4648
+ const annotationsStarting = (_i = nextSpanAnnotations == null ? void 0 : nextSpanAnnotations.filter((annotation) => !(previousSpanAnnotations != null && previousSpanAnnotations.includes(annotation)))) != null ? _i : [], atTheStartOfAnnotation = annotationsStarting.length > 0;
4649
+ if (atTheStartOfAnnotation && isPortableTextSpan(op.node) && (_j = op.node.marks) != null && _j.some((mark) => annotationsStarting.includes(mark))) {
4650
+ Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$g({}, op.node), {
4651
+ marks: (_l = (_k = op.node.marks) == null ? void 0 : _k.filter((mark) => !annotationsStarting.includes(mark))) != null ? _l : []
4652
+ }));
4539
4653
  return;
4540
4654
  }
4541
- const nextSpanDecorators = nextSpan?.marks?.filter((mark) => decorators.includes(mark)) ?? [];
4542
- if (nextSpanDecorators.length > 0 && atTheEndOfAnnotation && !atTheStartOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.length === 0) {
4543
- Transforms.insertNodes(editor, {
4544
- ...op.node,
4655
+ const nextSpanDecorators = (_n = (_m = nextSpan == null ? void 0 : nextSpan.marks) == null ? void 0 : _m.filter((mark) => decorators.includes(mark))) != null ? _n : [];
4656
+ if (nextSpanDecorators.length > 0 && atTheEndOfAnnotation && !atTheStartOfAnnotation && isPortableTextSpan(op.node) && ((_o = op.node.marks) == null ? void 0 : _o.length) === 0) {
4657
+ Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$g({}, op.node), {
4545
4658
  marks: nextSpanDecorators
4546
- });
4659
+ }));
4547
4660
  return;
4548
4661
  }
4549
4662
  }
@@ -4555,12 +4668,12 @@ function createWithPortableTextMarkModel(editorActor, types) {
4555
4668
  if (selection && collapsedSelection) {
4556
4669
  const [_block, blockPath] = Editor.node(editor, selection, {
4557
4670
  depth: 1
4558
- }), [span, spanPath] = Array.from(Editor.nodes(editor, {
4671
+ }), [span, spanPath] = (_p = Array.from(Editor.nodes(editor, {
4559
4672
  mode: "lowest",
4560
4673
  at: selection.focus,
4561
4674
  match: (n) => editor.isTextSpan(n),
4562
4675
  voids: !1
4563
- }))[0] ?? [void 0, void 0], marks = span.marks ?? [], marksWithoutAnnotations = marks.filter((mark) => decorators.includes(mark)), spanHasAnnotations = marks.length > marksWithoutAnnotations.length, spanIsEmpty = span.text.length === 0, atTheBeginningOfSpan = selection.anchor.offset === 0, atTheEndOfSpan = selection.anchor.offset === span.text.length, previousSpan = getPreviousSpan({
4676
+ }))[0]) != null ? _p : [void 0, void 0], marks = (_q = span.marks) != null ? _q : [], marksWithoutAnnotations = marks.filter((mark) => decorators.includes(mark)), spanHasAnnotations = marks.length > marksWithoutAnnotations.length, spanIsEmpty = span.text.length === 0, atTheBeginningOfSpan = selection.anchor.offset === 0, atTheEndOfSpan = selection.anchor.offset === span.text.length, previousSpan = getPreviousSpan({
4564
4677
  editor,
4565
4678
  blockPath,
4566
4679
  spanPath
@@ -4568,7 +4681,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
4568
4681
  editor,
4569
4682
  blockPath,
4570
4683
  spanPath
4571
- }), nextSpanAnnotations = nextSpan?.marks?.filter((mark) => !decorators.includes(mark)) ?? [], spanAnnotations = marks.filter((mark) => !decorators.includes(mark)), previousSpanHasAnnotations = previousSpan ? previousSpan.marks?.some((mark) => !decorators.includes(mark)) : !1, previousSpanHasSameAnnotations = previousSpan ? previousSpan.marks?.filter((mark) => !decorators.includes(mark)).every((mark) => marks.includes(mark)) : !1, previousSpanHasSameAnnotation = previousSpan ? previousSpan.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, previousSpanHasSameMarks = previousSpan ? previousSpan.marks?.every((mark) => marks.includes(mark)) : !1, nextSpanSharesSomeAnnotations = spanAnnotations.some((mark) => nextSpanAnnotations?.includes(mark));
4684
+ }), nextSpanAnnotations = (_s = (_r = nextSpan == null ? void 0 : nextSpan.marks) == null ? void 0 : _r.filter((mark) => !decorators.includes(mark))) != null ? _s : [], spanAnnotations = marks.filter((mark) => !decorators.includes(mark)), previousSpanHasAnnotations = previousSpan ? (_t = previousSpan.marks) == null ? void 0 : _t.some((mark) => !decorators.includes(mark)) : !1, previousSpanHasSameAnnotations = previousSpan ? (_u = previousSpan.marks) == null ? void 0 : _u.filter((mark) => !decorators.includes(mark)).every((mark) => marks.includes(mark)) : !1, previousSpanHasSameAnnotation = previousSpan ? (_v = previousSpan.marks) == null ? void 0 : _v.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, previousSpanHasSameMarks = previousSpan ? (_w = previousSpan.marks) == null ? void 0 : _w.every((mark) => marks.includes(mark)) : !1, nextSpanSharesSomeAnnotations = spanAnnotations.some((mark) => nextSpanAnnotations == null ? void 0 : nextSpanAnnotations.includes(mark));
4572
4685
  if (spanHasAnnotations && !spanIsEmpty) {
4573
4686
  if (atTheBeginningOfSpan) {
4574
4687
  if (previousSpanHasSameMarks) {
@@ -4576,7 +4689,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
4576
4689
  _type: "span",
4577
4690
  _key: editorActor.getSnapshot().context.keyGenerator(),
4578
4691
  text: op.text,
4579
- marks: previousSpan?.marks ?? []
4692
+ marks: (_x = previousSpan == null ? void 0 : previousSpan.marks) != null ? _x : []
4580
4693
  });
4581
4694
  return;
4582
4695
  } else if (previousSpanHasSameAnnotations) {
@@ -4584,7 +4697,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
4584
4697
  _type: "span",
4585
4698
  _key: editorActor.getSnapshot().context.keyGenerator(),
4586
4699
  text: op.text,
4587
- marks: previousSpan?.marks ?? []
4700
+ marks: (_y = previousSpan == null ? void 0 : previousSpan.marks) != null ? _y : []
4588
4701
  });
4589
4702
  return;
4590
4703
  } else if (previousSpanHasSameAnnotation) {
@@ -4606,7 +4719,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
4606
4719
  _type: "span",
4607
4720
  _key: editorActor.getSnapshot().context.keyGenerator(),
4608
4721
  text: op.text,
4609
- marks: nextSpan?.marks ?? []
4722
+ marks: (_z = nextSpan == null ? void 0 : nextSpan.marks) != null ? _z : []
4610
4723
  });
4611
4724
  return;
4612
4725
  }
@@ -4626,7 +4739,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
4626
4739
  _type: "span",
4627
4740
  _key: editorActor.getSnapshot().context.keyGenerator(),
4628
4741
  text: op.text,
4629
- marks: previousSpanHasAnnotations ? [] : (previousSpan.marks ?? []).filter((mark) => decorators.includes(mark))
4742
+ marks: previousSpanHasAnnotations ? [] : ((_A = previousSpan.marks) != null ? _A : []).filter((mark) => decorators.includes(mark))
4630
4743
  });
4631
4744
  return;
4632
4745
  }
@@ -4639,7 +4752,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
4639
4752
  if (selection && Range.isExpanded(selection)) {
4640
4753
  const [block, blockPath] = Editor.node(editor, selection, {
4641
4754
  depth: 1
4642
- }), [span, spanPath] = Array.from(Editor.nodes(editor, {
4755
+ }), [span, spanPath] = (_B = Array.from(Editor.nodes(editor, {
4643
4756
  mode: "lowest",
4644
4757
  at: {
4645
4758
  path: op.path,
@@ -4647,9 +4760,9 @@ function createWithPortableTextMarkModel(editorActor, types) {
4647
4760
  },
4648
4761
  match: (n) => editor.isTextSpan(n),
4649
4762
  voids: !1
4650
- }))[0] ?? [void 0, void 0];
4763
+ }))[0]) != null ? _B : [void 0, void 0];
4651
4764
  if (span && block && isPortableTextBlock(block)) {
4652
- const markDefs = block.markDefs ?? [], marks = span.marks ?? [], spanHasAnnotations = marks.some((mark) => markDefs.find((markDef) => markDef._key === mark)), deletingFromTheEnd = op.offset + op.text.length === span.text.length, deletingAllText = op.offset === 0 && deletingFromTheEnd, previousSpan = getPreviousSpan({
4765
+ const markDefs = (_C = block.markDefs) != null ? _C : [], marks = (_D = span.marks) != null ? _D : [], spanHasAnnotations = marks.some((mark) => markDefs.find((markDef) => markDef._key === mark)), deletingFromTheEnd = op.offset + op.text.length === span.text.length, deletingAllText = op.offset === 0 && deletingFromTheEnd, previousSpan = getPreviousSpan({
4653
4766
  editor,
4654
4767
  blockPath,
4655
4768
  spanPath
@@ -4657,11 +4770,9 @@ function createWithPortableTextMarkModel(editorActor, types) {
4657
4770
  editor,
4658
4771
  blockPath,
4659
4772
  spanPath
4660
- }), previousSpanHasSameAnnotation = previousSpan ? previousSpan.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, nextSpanHasSameAnnotation = nextSpan ? nextSpan.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1;
4773
+ }), previousSpanHasSameAnnotation = previousSpan ? (_E = previousSpan.marks) == null ? void 0 : _E.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, nextSpanHasSameAnnotation = nextSpan ? (_F = nextSpan.marks) == null ? void 0 : _F.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1;
4661
4774
  if (spanHasAnnotations && deletingAllText && !previousSpanHasSameAnnotation && !nextSpanHasSameAnnotation) {
4662
- const marksWithoutAnnotationMarks = ({
4663
- ...Editor.marks(editor) || {}
4664
- }.marks || []).filter((mark) => decorators.includes(mark));
4775
+ const marksWithoutAnnotationMarks = (__spreadValues$g({}, Editor.marks(editor) || {}).marks || []).filter((mark) => decorators.includes(mark));
4665
4776
  Editor.withoutNormalizing(editor, () => {
4666
4777
  apply2(op), Transforms.setNodes(editor, {
4667
4778
  marks: marksWithoutAnnotationMarks
@@ -4694,6 +4805,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
4694
4805
  const addDecoratorActionImplementation = ({
4695
4806
  action
4696
4807
  }) => {
4808
+ var _a;
4697
4809
  const editor = action.editor, mark = action.decorator;
4698
4810
  if (editor.selection) {
4699
4811
  if (Range.isExpanded(editor.selection)) {
@@ -4706,7 +4818,10 @@ const addDecoratorActionImplementation = ({
4706
4818
  at: editor.selection,
4707
4819
  match: Text.isText
4708
4820
  })] : [];
4709
- splitTextNodes.length > 1 && splitTextNodes.every((node) => node[0].marks?.includes(mark)) ? editor.removeMark(mark) : splitTextNodes.forEach(([node, path]) => {
4821
+ splitTextNodes.length > 1 && splitTextNodes.every((node) => {
4822
+ var _a2;
4823
+ return (_a2 = node[0].marks) == null ? void 0 : _a2.includes(mark);
4824
+ }) ? editor.removeMark(mark) : splitTextNodes.forEach(([node, path]) => {
4710
4825
  const marks = [...(Array.isArray(node.marks) ? node.marks : []).filter((eMark) => eMark !== mark), mark];
4711
4826
  Transforms.setNodes(editor, {
4712
4827
  marks
@@ -4722,7 +4837,7 @@ const addDecoratorActionImplementation = ({
4722
4837
  depth: 1
4723
4838
  }), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
4724
4839
  if (lonelyEmptySpan) {
4725
- const existingMarks = lonelyEmptySpan.marks ?? [], existingMarksWithoutDecorator = existingMarks.filter((existingMark) => existingMark !== mark);
4840
+ const existingMarks = (_a = lonelyEmptySpan.marks) != null ? _a : [], existingMarksWithoutDecorator = existingMarks.filter((existingMark) => existingMark !== mark);
4726
4841
  Transforms.setNodes(editor, {
4727
4842
  marks: existingMarks.length === existingMarksWithoutDecorator.length ? [...existingMarks, mark] : existingMarksWithoutDecorator
4728
4843
  }, {
@@ -4730,12 +4845,9 @@ const addDecoratorActionImplementation = ({
4730
4845
  match: (node) => editor.isTextSpan(node)
4731
4846
  });
4732
4847
  } else {
4733
- const existingMarks = {
4734
- ...Editor.marks(editor) || {}
4735
- }.marks || [], marks = {
4736
- ...Editor.marks(editor) || {},
4848
+ const existingMarks = __spreadValues$g({}, Editor.marks(editor) || {}).marks || [], marks = __spreadProps$b(__spreadValues$g({}, Editor.marks(editor) || {}), {
4737
4849
  marks: [...existingMarks, mark]
4738
- };
4850
+ });
4739
4851
  editor.marks = marks;
4740
4852
  }
4741
4853
  }
@@ -4744,6 +4856,7 @@ const addDecoratorActionImplementation = ({
4744
4856
  }, removeDecoratorActionImplementation = ({
4745
4857
  action
4746
4858
  }) => {
4859
+ var _a;
4747
4860
  const editor = action.editor, mark = action.decorator, {
4748
4861
  selection
4749
4862
  } = editor;
@@ -4770,7 +4883,7 @@ const addDecoratorActionImplementation = ({
4770
4883
  depth: 1
4771
4884
  }), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
4772
4885
  if (lonelyEmptySpan) {
4773
- const existingMarksWithoutDecorator = (lonelyEmptySpan.marks ?? []).filter((existingMark) => existingMark !== mark);
4886
+ const existingMarksWithoutDecorator = ((_a = lonelyEmptySpan.marks) != null ? _a : []).filter((existingMark) => existingMark !== mark);
4774
4887
  Transforms.setNodes(editor, {
4775
4888
  marks: existingMarksWithoutDecorator
4776
4889
  }, {
@@ -4778,12 +4891,9 @@ const addDecoratorActionImplementation = ({
4778
4891
  match: (node) => editor.isTextSpan(node)
4779
4892
  });
4780
4893
  } else {
4781
- const existingMarks = {
4782
- ...Editor.marks(editor) || {}
4783
- }.marks || [], marks = {
4784
- ...Editor.marks(editor) || {},
4894
+ const existingMarks = __spreadValues$g({}, Editor.marks(editor) || {}).marks || [], marks = __spreadProps$b(__spreadValues$g({}, Editor.marks(editor) || {}), {
4785
4895
  marks: existingMarks.filter((eMark) => eMark !== mark)
4786
- };
4896
+ });
4787
4897
  editor.marks = {
4788
4898
  marks: marks.marks,
4789
4899
  _type: "span"
@@ -4802,11 +4912,10 @@ function isDecoratorActive({
4802
4912
  at: editor.selection
4803
4913
  }));
4804
4914
  return selectedTextNodes.length === 0 ? !1 : Range.isExpanded(editor.selection) ? selectedTextNodes.every((n) => {
4915
+ var _a;
4805
4916
  const [node] = n;
4806
- return node.marks?.includes(decorator);
4807
- }) : ({
4808
- ...Editor.marks(editor) || {}
4809
- }.marks || []).includes(decorator);
4917
+ return (_a = node.marks) == null ? void 0 : _a.includes(decorator);
4918
+ }) : (__spreadValues$g({}, Editor.marks(editor) || {}).marks || []).includes(decorator);
4810
4919
  }
4811
4920
  const toggleDecoratorActionImplementation = ({
4812
4921
  context,
@@ -4864,6 +4973,14 @@ function createWithPortableTextSelections(editorActor, types) {
4864
4973
  }, editor;
4865
4974
  };
4866
4975
  }
4976
+ var __defProp$f = Object.defineProperty, __defProps$a = Object.defineProperties, __getOwnPropDescs$a = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$f = Object.getOwnPropertySymbols, __hasOwnProp$f = Object.prototype.hasOwnProperty, __propIsEnum$f = Object.prototype.propertyIsEnumerable, __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$f = (a, b) => {
4977
+ for (var prop in b || (b = {}))
4978
+ __hasOwnProp$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
4979
+ if (__getOwnPropSymbols$f)
4980
+ for (var prop of __getOwnPropSymbols$f(b))
4981
+ __propIsEnum$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
4982
+ return a;
4983
+ }, __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
4867
4984
  const debug$9 = debugWithName("plugin:withSchemaTypes");
4868
4985
  function createWithSchemaTypes({
4869
4986
  editorActor,
@@ -4881,11 +4998,10 @@ function createWithSchemaTypes({
4881
4998
  const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
4882
4999
  editorActor.send({
4883
5000
  type: "normalizing"
4884
- }), Transforms.setNodes(editor, {
4885
- ...span,
5001
+ }), Transforms.setNodes(editor, __spreadProps$a(__spreadValues$f({}, span), {
4886
5002
  _type: schemaTypes.span.name,
4887
5003
  _key: key
4888
- }, {
5004
+ }), {
4889
5005
  at: path
4890
5006
  }), editorActor.send({
4891
5007
  type: "done normalizing"
@@ -4910,6 +5026,14 @@ function createWithSchemaTypes({
4910
5026
  }, editor;
4911
5027
  };
4912
5028
  }
5029
+ var __defProp$e = Object.defineProperty, __defProps$9 = Object.defineProperties, __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$e = Object.getOwnPropertySymbols, __hasOwnProp$e = Object.prototype.hasOwnProperty, __propIsEnum$e = Object.prototype.propertyIsEnumerable, __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$e = (a, b) => {
5030
+ for (var prop in b || (b = {}))
5031
+ __hasOwnProp$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
5032
+ if (__getOwnPropSymbols$e)
5033
+ for (var prop of __getOwnPropSymbols$e(b))
5034
+ __propIsEnum$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
5035
+ return a;
5036
+ }, __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
4913
5037
  const debug$8 = debugWithName("plugin:withUtils");
4914
5038
  function createWithUtils({
4915
5039
  editorActor,
@@ -4933,29 +5057,26 @@ function createWithUtils({
4933
5057
  } = selection, focusOffset = focus.offset, charsBefore = textNode.text.slice(0, focusOffset), charsAfter = textNode.text.slice(focusOffset, -1), isEmpty = (str) => str.match(/\s/g), whiteSpaceBeforeIndex = charsBefore.split("").reverse().findIndex((str) => isEmpty(str)), newStartOffset = whiteSpaceBeforeIndex > -1 ? charsBefore.length - whiteSpaceBeforeIndex : 0, whiteSpaceAfterIndex = charsAfter.split("").findIndex((obj) => isEmpty(obj)), newEndOffset = charsBefore.length + (whiteSpaceAfterIndex > -1 ? whiteSpaceAfterIndex : charsAfter.length + 1);
4934
5058
  if (!(newStartOffset === newEndOffset || Number.isNaN(newStartOffset) || Number.isNaN(newEndOffset))) {
4935
5059
  debug$8("pteExpandToWord: Expanding to focused word"), Transforms.setSelection(editor, {
4936
- anchor: {
4937
- ...selection.anchor,
5060
+ anchor: __spreadProps$9(__spreadValues$e({}, selection.anchor), {
4938
5061
  offset: newStartOffset
4939
- },
4940
- focus: {
4941
- ...selection.focus,
5062
+ }),
5063
+ focus: __spreadProps$9(__spreadValues$e({}, selection.focus), {
4942
5064
  offset: newEndOffset
4943
- }
5065
+ })
4944
5066
  });
4945
5067
  return;
4946
5068
  }
4947
5069
  debug$8("pteExpandToWord: Can't expand to word here");
4948
5070
  }
4949
- }, editor.pteCreateTextBlock = (options) => toSlateValue([{
5071
+ }, editor.pteCreateTextBlock = (options) => toSlateValue([__spreadProps$9(__spreadValues$e(__spreadValues$e({
4950
5072
  _type: schemaTypes.block.name,
4951
5073
  _key: editorActor.getSnapshot().context.keyGenerator(),
4952
- style: schemaTypes.styles[0].value || "normal",
4953
- ...options.listItem ? {
4954
- listItem: options.listItem
4955
- } : {},
4956
- ...options.level ? {
4957
- level: options.level
4958
- } : {},
5074
+ style: schemaTypes.styles[0].value || "normal"
5075
+ }, options.listItem ? {
5076
+ listItem: options.listItem
5077
+ } : {}), options.level ? {
5078
+ level: options.level
5079
+ } : {}), {
4959
5080
  markDefs: [],
4960
5081
  children: [{
4961
5082
  _type: "span",
@@ -4965,7 +5086,7 @@ function createWithUtils({
4965
5086
  value
4966
5087
  }) => value === decorator))
4967
5088
  }]
4968
- }], {
5089
+ })], {
4969
5090
  schemaTypes
4970
5091
  })[0], editor;
4971
5092
  };
@@ -5011,6 +5132,14 @@ function createSlateEditor(config) {
5011
5132
  };
5012
5133
  return slateEditors.set(config.editorActor, slateEditor), slateEditor;
5013
5134
  }
5135
+ var __defProp$d = Object.defineProperty, __defProps$8 = Object.defineProperties, __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$d = Object.getOwnPropertySymbols, __hasOwnProp$d = Object.prototype.hasOwnProperty, __propIsEnum$d = Object.prototype.propertyIsEnumerable, __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$d = (a, b) => {
5136
+ for (var prop in b || (b = {}))
5137
+ __hasOwnProp$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
5138
+ if (__getOwnPropSymbols$d)
5139
+ for (var prop of __getOwnPropSymbols$d(b))
5140
+ __propIsEnum$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
5141
+ return a;
5142
+ }, __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
5014
5143
  const toggleListItemActionImplementation = ({
5015
5144
  context,
5016
5145
  action
@@ -5020,16 +5149,14 @@ const toggleListItemActionImplementation = ({
5020
5149
  listItem: action.listItem
5021
5150
  }) ? removeListItemActionImplementation({
5022
5151
  context,
5023
- action: {
5024
- ...action,
5152
+ action: __spreadProps$8(__spreadValues$d({}, action), {
5025
5153
  type: "list item.remove"
5026
- }
5154
+ })
5027
5155
  }) : addListItemActionImplementation({
5028
5156
  context,
5029
- action: {
5030
- ...action,
5157
+ action: __spreadProps$8(__spreadValues$d({}, action), {
5031
5158
  type: "list item.add"
5032
- }
5159
+ })
5033
5160
  });
5034
5161
  }, removeListItemActionImplementation = ({
5035
5162
  context,
@@ -5075,6 +5202,14 @@ function isListItemActive({
5075
5202
  })];
5076
5203
  return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => editor.isListBlock(node) && node.listItem === listItem) : !1;
5077
5204
  }
5205
+ var __defProp$c = Object.defineProperty, __defProps$7 = Object.defineProperties, __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$c = Object.getOwnPropertySymbols, __hasOwnProp$c = Object.prototype.hasOwnProperty, __propIsEnum$c = Object.prototype.propertyIsEnumerable, __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$c = (a, b) => {
5206
+ for (var prop in b || (b = {}))
5207
+ __hasOwnProp$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
5208
+ if (__getOwnPropSymbols$c)
5209
+ for (var prop of __getOwnPropSymbols$c(b))
5210
+ __propIsEnum$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
5211
+ return a;
5212
+ }, __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
5078
5213
  const toggleStyleActionImplementation = ({
5079
5214
  context,
5080
5215
  action
@@ -5084,16 +5219,14 @@ const toggleStyleActionImplementation = ({
5084
5219
  style: action.style
5085
5220
  }) ? removeStyleActionImplementation({
5086
5221
  context,
5087
- action: {
5088
- ...action,
5222
+ action: __spreadProps$7(__spreadValues$c({}, action), {
5089
5223
  type: "style.remove"
5090
- }
5224
+ })
5091
5225
  }) : addStyleActionImplementation({
5092
5226
  context,
5093
- action: {
5094
- ...action,
5227
+ action: __spreadProps$7(__spreadValues$c({}, action), {
5095
5228
  type: "style.add"
5096
- }
5229
+ })
5097
5230
  });
5098
5231
  }, removeStyleActionImplementation = ({
5099
5232
  context,
@@ -5140,6 +5273,14 @@ function isStyleActive({
5140
5273
  })];
5141
5274
  return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
5142
5275
  }
5276
+ var __defProp$b = Object.defineProperty, __getOwnPropSymbols$b = Object.getOwnPropertySymbols, __hasOwnProp$b = Object.prototype.hasOwnProperty, __propIsEnum$b = Object.prototype.propertyIsEnumerable, __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$b = (a, b) => {
5277
+ for (var prop in b || (b = {}))
5278
+ __hasOwnProp$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
5279
+ if (__getOwnPropSymbols$b)
5280
+ for (var prop of __getOwnPropSymbols$b(b))
5281
+ __propIsEnum$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
5282
+ return a;
5283
+ };
5143
5284
  const debug$6 = debugWithName("API:editable");
5144
5285
  function createEditableAPI(editor, editorActor) {
5145
5286
  const types = editorActor.getSnapshot().context.schema;
@@ -5202,9 +5343,7 @@ function createEditableAPI(editor, editorActor) {
5202
5343
  return console.warn(err), !1;
5203
5344
  }
5204
5345
  },
5205
- marks: () => ({
5206
- ...Editor.marks(editor) || {}
5207
- }).marks || [],
5346
+ marks: () => __spreadValues$b({}, Editor.marks(editor) || {}).marks || [],
5208
5347
  undo: () => editor.undo(),
5209
5348
  redo: () => editor.redo(),
5210
5349
  select: (selection) => {
@@ -5226,6 +5365,7 @@ function createEditableAPI(editor, editorActor) {
5226
5365
  }
5227
5366
  },
5228
5367
  insertChild: (type, value) => {
5368
+ var _a, _b, _c;
5229
5369
  if (type.name !== types.span.name)
5230
5370
  return editorActor.send({
5231
5371
  type: "behavior event",
@@ -5237,7 +5377,7 @@ function createEditableAPI(editor, editorActor) {
5237
5377
  }
5238
5378
  },
5239
5379
  editor
5240
- }), toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)?.focus.path ?? [];
5380
+ }), (_b = (_a = toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)) == null ? void 0 : _a.focus.path) != null ? _b : [];
5241
5381
  if (!editor.selection)
5242
5382
  throw new Error("The editor has no selection");
5243
5383
  const [focusBlock] = Array.from(Editor.nodes(editor, {
@@ -5251,11 +5391,10 @@ function createEditableAPI(editor, editorActor) {
5251
5391
  const child = toSlateValue([{
5252
5392
  _key: editorActor.getSnapshot().context.keyGenerator(),
5253
5393
  _type: types.block.name,
5254
- children: [{
5394
+ children: [__spreadValues$b({
5255
5395
  _key: editorActor.getSnapshot().context.keyGenerator(),
5256
- _type: type.name,
5257
- ...value || {}
5258
- }]
5396
+ _type: type.name
5397
+ }, value || {})]
5259
5398
  }], {
5260
5399
  schemaTypes: editorActor.getSnapshot().context.schema
5261
5400
  })[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types.span.name, focusNode = Node.get(editor, focusChildPath);
@@ -5265,27 +5404,30 @@ function createEditableAPI(editor, editorActor) {
5265
5404
  })), Transforms.insertNodes(editor, child, {
5266
5405
  select: !0,
5267
5406
  at: editor.selection
5268
- }), editor.onChange(), toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)?.focus.path || [];
5407
+ }), editor.onChange(), ((_c = toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)) == null ? void 0 : _c.focus.path) || [];
5269
5408
  },
5270
- insertBlock: (type, value) => (editorActor.send({
5271
- type: "behavior event",
5272
- behaviorEvent: {
5273
- type: "insert.block object",
5274
- blockObject: {
5275
- name: type.name,
5276
- value
5409
+ insertBlock: (type, value) => {
5410
+ var _a, _b;
5411
+ return editorActor.send({
5412
+ type: "behavior event",
5413
+ behaviorEvent: {
5414
+ type: "insert.block object",
5415
+ blockObject: {
5416
+ name: type.name,
5417
+ value
5418
+ },
5419
+ placement: "auto"
5277
5420
  },
5278
- placement: "auto"
5279
- },
5280
- editor
5281
- }), toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)?.focus.path ?? []),
5421
+ editor
5422
+ }), (_b = (_a = toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)) == null ? void 0 : _a.focus.path) != null ? _b : [];
5423
+ },
5282
5424
  hasBlockStyle: (style) => {
5283
5425
  try {
5284
5426
  return isStyleActive({
5285
5427
  editor,
5286
5428
  style
5287
5429
  });
5288
- } catch {
5430
+ } catch (e) {
5289
5431
  return !1;
5290
5432
  }
5291
5433
  },
@@ -5295,7 +5437,7 @@ function createEditableAPI(editor, editorActor) {
5295
5437
  editor,
5296
5438
  listItem
5297
5439
  });
5298
- } catch {
5440
+ } catch (e) {
5299
5441
  return !1;
5300
5442
  }
5301
5443
  },
@@ -5340,11 +5482,12 @@ function createEditableAPI(editor, editorActor) {
5340
5482
  match: (n) => n._key === element._key
5341
5483
  }) || [])[0] || [void 0];
5342
5484
  node = ReactEditor.toDOMNode(editor, item);
5343
- } catch {
5485
+ } catch (e) {
5344
5486
  }
5345
5487
  return node;
5346
5488
  },
5347
5489
  activeAnnotations: () => {
5490
+ var _a;
5348
5491
  if (!editor.selection || editor.selection.focus.path.length < 2)
5349
5492
  return [];
5350
5493
  try {
@@ -5356,12 +5499,12 @@ function createEditableAPI(editor, editorActor) {
5356
5499
  const [block] = Editor.node(editor, path, {
5357
5500
  depth: 1
5358
5501
  });
5359
- editor.isTextBlock(block) && block.markDefs?.forEach((def) => {
5502
+ editor.isTextBlock(block) && ((_a = block.markDefs) == null || _a.forEach((def) => {
5360
5503
  Text.isText(span) && span.marks && Array.isArray(span.marks) && span.marks.includes(def._key) && activeAnnotations.push(def);
5361
- });
5504
+ }));
5362
5505
  }
5363
5506
  return activeAnnotations;
5364
- } catch {
5507
+ } catch (e) {
5365
5508
  return [];
5366
5509
  }
5367
5510
  },
@@ -5383,7 +5526,7 @@ function createEditableAPI(editor, editorActor) {
5383
5526
  type: "annotation.add",
5384
5527
  annotation: {
5385
5528
  name: type.name,
5386
- value: value ?? {}
5529
+ value: value != null ? value : {}
5387
5530
  },
5388
5531
  editor
5389
5532
  }
@@ -5396,7 +5539,7 @@ function createEditableAPI(editor, editorActor) {
5396
5539
  if (!(range && range.anchor.path.length > 0 && range.focus.path.length > 0))
5397
5540
  throw new Error("Invalid range");
5398
5541
  if (range) {
5399
- if (!options?.mode || options?.mode === "selected") {
5542
+ if (!(options != null && options.mode) || (options == null ? void 0 : options.mode) === "selected") {
5400
5543
  debug$6("Deleting content in selection"), Transforms.delete(editor, {
5401
5544
  at: range,
5402
5545
  hanging: !0,
@@ -5404,11 +5547,11 @@ function createEditableAPI(editor, editorActor) {
5404
5547
  }), editor.onChange();
5405
5548
  return;
5406
5549
  }
5407
- options?.mode === "blocks" && (debug$6("Deleting blocks touched by selection"), Transforms.removeNodes(editor, {
5550
+ (options == null ? void 0 : options.mode) === "blocks" && (debug$6("Deleting blocks touched by selection"), Transforms.removeNodes(editor, {
5408
5551
  at: range,
5409
5552
  voids: !0,
5410
5553
  match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && Element$1.isElement(node)
5411
- })), options?.mode === "children" && (debug$6("Deleting children touched by selection"), Transforms.removeNodes(editor, {
5554
+ })), (options == null ? void 0 : options.mode) === "children" && (debug$6("Deleting children touched by selection"), Transforms.removeNodes(editor, {
5412
5555
  at: range,
5413
5556
  voids: !0,
5414
5557
  match: (node) => node._type === types.span.name || // Text children
@@ -5465,15 +5608,26 @@ function isAnnotationActive({
5465
5608
  at: editor.selection,
5466
5609
  match: (node) => Text.isText(node)
5467
5610
  })];
5468
- if (spans.length === 0 || spans.some(([span]) => !isPortableTextSpan$1(span) || !span.marks || span.marks?.length === 0)) return !1;
5611
+ if (spans.length === 0 || spans.some(([span]) => {
5612
+ var _a;
5613
+ return !isPortableTextSpan$1(span) || !span.marks || ((_a = span.marks) == null ? void 0 : _a.length) === 0;
5614
+ })) return !1;
5469
5615
  const selectionMarkDefs = spans.reduce((accMarkDefs, [, path]) => {
5470
5616
  const [block] = Editor.node(editor, path, {
5471
5617
  depth: 1
5472
5618
  });
5473
5619
  return editor.isTextBlock(block) && block.markDefs ? [...accMarkDefs, ...block.markDefs] : accMarkDefs;
5474
5620
  }, []);
5475
- return spans.every(([span]) => isPortableTextSpan$1(span) ? span.marks?.map((markKey) => selectionMarkDefs.find((def) => def?._key === markKey)?._type)?.includes(annotation.name) : !1);
5476
- } catch {
5621
+ return spans.every(([span]) => {
5622
+ var _a;
5623
+ if (!isPortableTextSpan$1(span)) return !1;
5624
+ const spanMarkDefs = (_a = span.marks) == null ? void 0 : _a.map((markKey) => {
5625
+ var _a2;
5626
+ return (_a2 = selectionMarkDefs.find((def) => (def == null ? void 0 : def._key) === markKey)) == null ? void 0 : _a2._type;
5627
+ });
5628
+ return spanMarkDefs == null ? void 0 : spanMarkDefs.includes(annotation.name);
5629
+ });
5630
+ } catch (e) {
5477
5631
  return !1;
5478
5632
  }
5479
5633
  }
@@ -5481,6 +5635,7 @@ const addAnnotationActionImplementation = ({
5481
5635
  context,
5482
5636
  action
5483
5637
  }) => {
5638
+ var _a, _b;
5484
5639
  const editor = action.editor, {
5485
5640
  selection: originalSelection
5486
5641
  } = editor;
@@ -5498,13 +5653,12 @@ const addAnnotationActionImplementation = ({
5498
5653
  for (const [block, blockPath] of selectedBlocks) {
5499
5654
  if (block.children.length === 0 || block.children.length === 1 && block.children[0].text === "")
5500
5655
  continue;
5501
- const annotationKey = context.keyGenerator(), markDefs = block.markDefs ?? [];
5656
+ const annotationKey = context.keyGenerator(), markDefs = (_a = block.markDefs) != null ? _a : [];
5502
5657
  markDefs.find((markDef) => markDef._type === action.annotation.name && markDef._key === annotationKey) === void 0 && (Transforms.setNodes(editor, {
5503
- markDefs: [...markDefs, {
5658
+ markDefs: [...markDefs, __spreadValues$b({
5504
5659
  _type: action.annotation.name,
5505
- _key: annotationKey,
5506
- ...action.annotation.value
5507
- }]
5660
+ _key: annotationKey
5661
+ }, action.annotation.value)]
5508
5662
  }, {
5509
5663
  at: blockPath
5510
5664
  }), markDefPath = [{
@@ -5519,7 +5673,7 @@ const addAnnotationActionImplementation = ({
5519
5673
  for (const [span, path] of children) {
5520
5674
  if (!editor.isTextSpan(span) || !Range.includes(editor.selection, path))
5521
5675
  continue;
5522
- const marks = span.marks ?? [], existingSameTypeAnnotations = marks.filter((mark) => markDefs.some((markDef) => markDef._key === mark && markDef._type === action.annotation.name));
5676
+ const marks = (_b = span.marks) != null ? _b : [], existingSameTypeAnnotations = marks.filter((mark) => markDefs.some((markDef) => markDef._key === mark && markDef._type === action.annotation.name));
5523
5677
  Transforms.setNodes(editor, {
5524
5678
  marks: [...marks.filter((mark) => !existingSameTypeAnnotations.includes(mark)), annotationKey]
5525
5679
  }, {
@@ -5541,6 +5695,7 @@ const addAnnotationActionImplementation = ({
5541
5695
  }, removeAnnotationActionImplementation = ({
5542
5696
  action
5543
5697
  }) => {
5698
+ var _a, _b, _c, _d, _e, _f, _g;
5544
5699
  const editor = action.editor;
5545
5700
  if (debug$6("Removing annotation", action.annotation.name), !!editor.selection)
5546
5701
  if (Range.isCollapsed(editor.selection)) {
@@ -5549,12 +5704,12 @@ const addAnnotationActionImplementation = ({
5549
5704
  });
5550
5705
  if (!editor.isTextBlock(block))
5551
5706
  return;
5552
- const potentialAnnotations = (block.markDefs ?? []).filter((markDef) => markDef._type === action.annotation.name), [selectedChild, selectedChildPath] = Editor.node(editor, editor.selection, {
5707
+ const potentialAnnotations = ((_a = block.markDefs) != null ? _a : []).filter((markDef) => markDef._type === action.annotation.name), [selectedChild, selectedChildPath] = Editor.node(editor, editor.selection, {
5553
5708
  depth: 2
5554
5709
  });
5555
5710
  if (!editor.isTextSpan(selectedChild))
5556
5711
  return;
5557
- const annotationToRemove = selectedChild.marks?.find((mark) => potentialAnnotations.some((markDef) => markDef._key === mark));
5712
+ const annotationToRemove = (_b = selectedChild.marks) == null ? void 0 : _b.find((mark) => potentialAnnotations.some((markDef) => markDef._key === mark));
5558
5713
  if (!annotationToRemove)
5559
5714
  return;
5560
5715
  const previousSpansWithSameAnnotation = [];
@@ -5562,20 +5717,20 @@ const addAnnotationActionImplementation = ({
5562
5717
  reverse: !0
5563
5718
  }))
5564
5719
  if (editor.isTextSpan(child) && Path.isBefore(childPath, selectedChildPath))
5565
- if (child.marks?.includes(annotationToRemove))
5720
+ if ((_c = child.marks) != null && _c.includes(annotationToRemove))
5566
5721
  previousSpansWithSameAnnotation.push([child, childPath]);
5567
5722
  else
5568
5723
  break;
5569
5724
  const nextSpansWithSameAnnotation = [];
5570
5725
  for (const [child, childPath] of Node.children(editor, blockPath))
5571
5726
  if (editor.isTextSpan(child) && Path.isAfter(childPath, selectedChildPath))
5572
- if (child.marks?.includes(annotationToRemove))
5727
+ if ((_d = child.marks) != null && _d.includes(annotationToRemove))
5573
5728
  nextSpansWithSameAnnotation.push([child, childPath]);
5574
5729
  else
5575
5730
  break;
5576
5731
  for (const [child, childPath] of [...previousSpansWithSameAnnotation, [selectedChild, selectedChildPath], ...nextSpansWithSameAnnotation])
5577
5732
  Transforms.setNodes(editor, {
5578
- marks: child.marks?.filter((mark) => mark !== annotationToRemove)
5733
+ marks: (_e = child.marks) == null ? void 0 : _e.filter((mark) => mark !== annotationToRemove)
5579
5734
  }, {
5580
5735
  at: childPath
5581
5736
  });
@@ -5594,7 +5749,10 @@ const addAnnotationActionImplementation = ({
5594
5749
  for (const [child, childPath] of children) {
5595
5750
  if (!editor.isTextSpan(child) || !Range.includes(editor.selection, childPath))
5596
5751
  continue;
5597
- const markDefs = block.markDefs ?? [], marks = child.marks ?? [], marksWithoutAnnotation = marks.filter((mark) => markDefs.find((markDef2) => markDef2._key === mark)?._type !== action.annotation.name);
5752
+ const markDefs = (_f = block.markDefs) != null ? _f : [], marks = (_g = child.marks) != null ? _g : [], marksWithoutAnnotation = marks.filter((mark) => {
5753
+ const markDef = markDefs.find((markDef2) => markDef2._key === mark);
5754
+ return (markDef == null ? void 0 : markDef._type) !== action.annotation.name;
5755
+ });
5598
5756
  marksWithoutAnnotation.length !== marks.length && Transforms.setNodes(editor, {
5599
5757
  marks: marksWithoutAnnotation
5600
5758
  }, {
@@ -5637,11 +5795,12 @@ function insertBlock({
5637
5795
  editor,
5638
5796
  schema
5639
5797
  }) {
5798
+ var _a;
5640
5799
  if (editor.selection) {
5641
- const [focusBlock, focusBlockPath] = Array.from(Editor.nodes(editor, {
5800
+ const [focusBlock, focusBlockPath] = (_a = Array.from(Editor.nodes(editor, {
5642
5801
  at: editor.selection.focus.path.slice(0, 1),
5643
5802
  match: (n) => !Editor.isEditor(n)
5644
- }))[0] ?? [void 0, void 0];
5803
+ }))[0]) != null ? _a : [void 0, void 0];
5645
5804
  if (placement === "after") {
5646
5805
  const nextPath = [focusBlockPath[0] + 1];
5647
5806
  Transforms.insertNodes(editor, block, {
@@ -5673,15 +5832,22 @@ function insertBlock({
5673
5832
  });
5674
5833
  }
5675
5834
  }
5835
+ var __defProp$a = Object.defineProperty, __getOwnPropSymbols$a = Object.getOwnPropertySymbols, __hasOwnProp$a = Object.prototype.hasOwnProperty, __propIsEnum$a = Object.prototype.propertyIsEnumerable, __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$a = (a, b) => {
5836
+ for (var prop in b || (b = {}))
5837
+ __hasOwnProp$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
5838
+ if (__getOwnPropSymbols$a)
5839
+ for (var prop of __getOwnPropSymbols$a(b))
5840
+ __propIsEnum$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
5841
+ return a;
5842
+ };
5676
5843
  const insertBlockObjectActionImplementation = ({
5677
5844
  context,
5678
5845
  action
5679
5846
  }) => {
5680
- const block = toSlateValue([{
5847
+ const block = toSlateValue([__spreadValues$a({
5681
5848
  _key: context.keyGenerator(),
5682
- _type: action.blockObject.name,
5683
- ...action.blockObject.value ? action.blockObject.value : {}
5684
- }], {
5849
+ _type: action.blockObject.name
5850
+ }, action.blockObject.value ? action.blockObject.value : {})], {
5685
5851
  schemaTypes: context.schema
5686
5852
  })[0];
5687
5853
  insertBlock({
@@ -5690,19 +5856,29 @@ const insertBlockObjectActionImplementation = ({
5690
5856
  editor: action.editor,
5691
5857
  schema: context.schema
5692
5858
  });
5693
- }, insertBreakActionImplementation = ({
5859
+ };
5860
+ var __defProp$9 = Object.defineProperty, __defProps$6 = Object.defineProperties, __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$9 = Object.getOwnPropertySymbols, __hasOwnProp$9 = Object.prototype.hasOwnProperty, __propIsEnum$9 = Object.prototype.propertyIsEnumerable, __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$9 = (a, b) => {
5861
+ for (var prop in b || (b = {}))
5862
+ __hasOwnProp$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
5863
+ if (__getOwnPropSymbols$9)
5864
+ for (var prop of __getOwnPropSymbols$9(b))
5865
+ __propIsEnum$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
5866
+ return a;
5867
+ }, __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
5868
+ const insertBreakActionImplementation = ({
5694
5869
  context,
5695
5870
  action
5696
5871
  }) => {
5872
+ var _a, _b, _c, _d, _e;
5697
5873
  const keyGenerator = context.keyGenerator, schema = context.schema, editor = action.editor;
5698
5874
  if (!editor.selection)
5699
5875
  return;
5700
- const [focusSpan] = Array.from(Editor.nodes(editor, {
5876
+ const [focusSpan] = (_a = Array.from(Editor.nodes(editor, {
5701
5877
  mode: "lowest",
5702
5878
  at: editor.selection.focus,
5703
5879
  match: (n) => editor.isTextSpan(n),
5704
5880
  voids: !1
5705
- }))[0] ?? [void 0], focusDecorators = focusSpan?.marks?.filter((mark) => schema.decorators.some((decorator) => decorator.value === mark)) ?? [], focusAnnotations = focusSpan?.marks?.filter((mark) => !schema.decorators.some((decorator) => decorator.value === mark)) ?? [], anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = Node.descendant(editor, focusBlockPath);
5881
+ }))[0]) != null ? _a : [void 0], focusDecorators = (_c = (_b = focusSpan == null ? void 0 : focusSpan.marks) == null ? void 0 : _b.filter((mark) => schema.decorators.some((decorator) => decorator.value === mark))) != null ? _c : [], focusAnnotations = (_e = (_d = focusSpan == null ? void 0 : focusSpan.marks) == null ? void 0 : _d.filter((mark) => !schema.decorators.some((decorator) => decorator.value === mark))) != null ? _e : [], anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = Node.descendant(editor, focusBlockPath);
5706
5882
  if (editor.isTextBlock(focusBlock)) {
5707
5883
  const [start, end] = Range.edges(editor.selection), lastFocusBlockChild = focusBlock.children[focusBlock.children.length - 1], atTheEndOfBlock = isEqual(start, {
5708
5884
  path: [...focusBlockPath, focusBlock.children.length - 1],
@@ -5741,6 +5917,7 @@ const insertBlockObjectActionImplementation = ({
5741
5917
  const selectionAcrossBlocks = anchorBlockPath[0] !== focusBlockPath[0];
5742
5918
  if (!atTheStartOfBlock && !atTheEndOfBlock && !selectionAcrossBlocks) {
5743
5919
  Editor.withoutNormalizing(editor, () => {
5920
+ var _a2;
5744
5921
  if (!editor.selection)
5745
5922
  return;
5746
5923
  Transforms.splitNodes(editor, {
@@ -5763,20 +5940,28 @@ const insertBlockObjectActionImplementation = ({
5763
5940
  for (const [child, childPath] of children) {
5764
5941
  if (!editor.isTextSpan(child))
5765
5942
  continue;
5766
- const marks = child.marks ?? [];
5943
+ const marks = (_a2 = child.marks) != null ? _a2 : [];
5767
5944
  for (const mark of marks)
5768
- schema.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) => prevNodeSpan.marks?.includes(mark)) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
5769
- const newMarks = marks.map((mark) => newMarkDefKeys.get(mark) ?? mark);
5945
+ schema.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) => {
5946
+ var _a3;
5947
+ return (_a3 = prevNodeSpan.marks) == null ? void 0 : _a3.includes(mark);
5948
+ }) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
5949
+ const newMarks = marks.map((mark) => {
5950
+ var _a3;
5951
+ return (_a3 = newMarkDefKeys.get(mark)) != null ? _a3 : mark;
5952
+ });
5770
5953
  isEqual(marks, newMarks) || Transforms.setNodes(editor, {
5771
5954
  marks: newMarks
5772
5955
  }, {
5773
5956
  at: childPath
5774
5957
  });
5775
5958
  }
5776
- const newMarkDefs = nextNode.markDefs.map((markDef) => ({
5777
- ...markDef,
5778
- _key: newMarkDefKeys.get(markDef._key) ?? markDef._key
5779
- }));
5959
+ const newMarkDefs = nextNode.markDefs.map((markDef) => {
5960
+ var _a3;
5961
+ return __spreadProps$6(__spreadValues$9({}, markDef), {
5962
+ _key: (_a3 = newMarkDefKeys.get(markDef._key)) != null ? _a3 : markDef._key
5963
+ });
5964
+ });
5780
5965
  isEqual(nextNode.markDefs, newMarkDefs) || Transforms.setNodes(editor, {
5781
5966
  markDefs: newMarkDefs
5782
5967
  }, {
@@ -5797,15 +5982,24 @@ const insertBlockObjectActionImplementation = ({
5797
5982
  }) => {
5798
5983
  insertBreakActionImplementation({
5799
5984
  context,
5800
- action: {
5801
- ...action,
5985
+ action: __spreadProps$6(__spreadValues$9({}, action), {
5802
5986
  type: "insert.break"
5803
- }
5987
+ })
5804
5988
  });
5805
- }, insertInlineObjectActionImplementation = ({
5989
+ };
5990
+ var __defProp$8 = Object.defineProperty, __getOwnPropSymbols$8 = Object.getOwnPropertySymbols, __hasOwnProp$8 = Object.prototype.hasOwnProperty, __propIsEnum$8 = Object.prototype.propertyIsEnumerable, __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$8 = (a, b) => {
5991
+ for (var prop in b || (b = {}))
5992
+ __hasOwnProp$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
5993
+ if (__getOwnPropSymbols$8)
5994
+ for (var prop of __getOwnPropSymbols$8(b))
5995
+ __propIsEnum$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
5996
+ return a;
5997
+ };
5998
+ const insertInlineObjectActionImplementation = ({
5806
5999
  context,
5807
6000
  action
5808
6001
  }) => {
6002
+ var _a, _b;
5809
6003
  if (!context.schema.inlineObjects.some((inlineObject) => inlineObject.name === action.inlineObject.name)) {
5810
6004
  console.error("Unable to insert unknown inline object");
5811
6005
  return;
@@ -5814,60 +6008,77 @@ const insertBlockObjectActionImplementation = ({
5814
6008
  console.error("Unable to insert inline object without selection");
5815
6009
  return;
5816
6010
  }
5817
- const [focusTextBlock] = Array.from(Editor.nodes(action.editor, {
6011
+ const [focusTextBlock] = (_a = Array.from(Editor.nodes(action.editor, {
5818
6012
  at: action.editor.selection.focus.path,
5819
6013
  match: (node) => action.editor.isTextBlock(node)
5820
- })).at(0) ?? [void 0, void 0];
6014
+ })).at(0)) != null ? _a : [void 0, void 0];
5821
6015
  if (!focusTextBlock) {
5822
6016
  console.error("Unable to perform action without focus text block");
5823
6017
  return;
5824
6018
  }
5825
- const child = toSlateValue([{
6019
+ const block = toSlateValue([{
5826
6020
  _type: context.schema.block.name,
5827
6021
  _key: context.keyGenerator(),
5828
- children: [{
6022
+ children: [__spreadValues$8({
5829
6023
  _type: action.inlineObject.name,
5830
- _key: context.keyGenerator(),
5831
- ...action.inlineObject.value ?? {}
5832
- }]
6024
+ _key: context.keyGenerator()
6025
+ }, (_b = action.inlineObject.value) != null ? _b : {})]
5833
6026
  }], {
5834
6027
  schemaTypes: context.schema
5835
- }).at(0)?.children.at(0);
6028
+ }).at(0), child = block == null ? void 0 : block.children.at(0);
5836
6029
  if (!child) {
5837
6030
  console.error("Unable to insert inline object");
5838
6031
  return;
5839
6032
  }
5840
6033
  Transforms.insertNodes(action.editor, child);
5841
- }, insertSpanActionImplementation = ({
6034
+ };
6035
+ var __defProp$7 = Object.defineProperty, __getOwnPropSymbols$7 = Object.getOwnPropertySymbols, __hasOwnProp$7 = Object.prototype.hasOwnProperty, __propIsEnum$7 = Object.prototype.propertyIsEnumerable, __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$7 = (a, b) => {
6036
+ for (var prop in b || (b = {}))
6037
+ __hasOwnProp$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
6038
+ if (__getOwnPropSymbols$7)
6039
+ for (var prop of __getOwnPropSymbols$7(b))
6040
+ __propIsEnum$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
6041
+ return a;
6042
+ };
6043
+ const insertSpanActionImplementation = ({
5842
6044
  context,
5843
6045
  action
5844
6046
  }) => {
6047
+ var _a, _b, _c, _d;
5845
6048
  if (!action.editor.selection) {
5846
6049
  console.error("Unable to perform action without selection", action);
5847
6050
  return;
5848
6051
  }
5849
- const [focusBlock, focusBlockPath] = Array.from(Editor.nodes(action.editor, {
6052
+ const [focusBlock, focusBlockPath] = (_a = Array.from(Editor.nodes(action.editor, {
5850
6053
  at: action.editor.selection.focus.path,
5851
6054
  match: (node) => action.editor.isTextBlock(node)
5852
- }))[0] ?? [void 0, void 0];
6055
+ }))[0]) != null ? _a : [void 0, void 0];
5853
6056
  if (!focusBlock || !focusBlockPath) {
5854
6057
  console.error("Unable to perform action without focus block", action);
5855
6058
  return;
5856
6059
  }
5857
- const markDefs = focusBlock.markDefs ?? [], annotations = action.annotations ? action.annotations.map((annotation) => ({
6060
+ const markDefs = (_b = focusBlock.markDefs) != null ? _b : [], annotations = action.annotations ? action.annotations.map((annotation) => __spreadValues$7({
5858
6061
  _type: annotation.name,
5859
- _key: context.keyGenerator(),
5860
- ...annotation.value
5861
- })) : void 0;
6062
+ _key: context.keyGenerator()
6063
+ }, annotation.value)) : void 0;
5862
6064
  annotations && annotations.length > 0 && Transforms.setNodes(action.editor, {
5863
6065
  markDefs: [...markDefs, ...annotations]
5864
6066
  }), Transforms.insertNodes(action.editor, {
5865
6067
  _type: "span",
5866
6068
  _key: context.keyGenerator(),
5867
6069
  text: action.text,
5868
- marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...action.decorators ?? []]
6070
+ marks: [...(_c = annotations == null ? void 0 : annotations.map((annotation) => annotation._key)) != null ? _c : [], ...(_d = action.decorators) != null ? _d : []]
5869
6071
  });
5870
- }, textBlockSetActionImplementation = ({
6072
+ };
6073
+ var __defProp$6 = Object.defineProperty, __getOwnPropSymbols$6 = Object.getOwnPropertySymbols, __hasOwnProp$6 = Object.prototype.hasOwnProperty, __propIsEnum$6 = Object.prototype.propertyIsEnumerable, __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$6 = (a, b) => {
6074
+ for (var prop in b || (b = {}))
6075
+ __hasOwnProp$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
6076
+ if (__getOwnPropSymbols$6)
6077
+ for (var prop of __getOwnPropSymbols$6(b))
6078
+ __propIsEnum$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
6079
+ return a;
6080
+ };
6081
+ const textBlockSetActionImplementation = ({
5871
6082
  action
5872
6083
  }) => {
5873
6084
  const at = toSlateRange({
@@ -5880,17 +6091,13 @@ const insertBlockObjectActionImplementation = ({
5880
6091
  offset: 0
5881
6092
  }
5882
6093
  }, action.editor);
5883
- Transforms.setNodes(action.editor, {
5884
- ...action.style ? {
5885
- style: action.style
5886
- } : {},
5887
- ...action.listItem ? {
5888
- listItem: action.listItem
5889
- } : {},
5890
- ...action.level ? {
5891
- level: action.level
5892
- } : {}
5893
- }, {
6094
+ Transforms.setNodes(action.editor, __spreadValues$6(__spreadValues$6(__spreadValues$6({}, action.style ? {
6095
+ style: action.style
6096
+ } : {}), action.listItem ? {
6097
+ listItem: action.listItem
6098
+ } : {}), action.level ? {
6099
+ level: action.level
6100
+ } : {}), {
5894
6101
  at
5895
6102
  });
5896
6103
  }, textBlockUnsetActionImplementation = ({
@@ -5909,7 +6116,16 @@ const insertBlockObjectActionImplementation = ({
5909
6116
  Transforms.unsetNodes(action.editor, action.props, {
5910
6117
  at
5911
6118
  });
5912
- }, behaviorActionImplementations = {
6119
+ };
6120
+ var __defProp$5 = Object.defineProperty, __defProps$5 = Object.defineProperties, __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$5 = Object.getOwnPropertySymbols, __hasOwnProp$5 = Object.prototype.hasOwnProperty, __propIsEnum$5 = Object.prototype.propertyIsEnumerable, __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$5 = (a, b) => {
6121
+ for (var prop in b || (b = {}))
6122
+ __hasOwnProp$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
6123
+ if (__getOwnPropSymbols$5)
6124
+ for (var prop of __getOwnPropSymbols$5(b))
6125
+ __propIsEnum$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
6126
+ return a;
6127
+ }, __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
6128
+ const behaviorActionImplementations = {
5913
6129
  "annotation.add": addAnnotationActionImplementation,
5914
6130
  "annotation.remove": removeAnnotationActionImplementation,
5915
6131
  "annotation.toggle": toggleAnnotationActionImplementation,
@@ -5998,15 +6214,15 @@ const insertBlockObjectActionImplementation = ({
5998
6214
  context,
5999
6215
  action
6000
6216
  }) => {
6217
+ var _a, _b, _c, _d;
6001
6218
  const block = toSlateValue([{
6002
6219
  _key: context.keyGenerator(),
6003
6220
  _type: context.schema.block.name,
6004
- style: context.schema.styles[0].value ?? "normal",
6221
+ style: (_a = context.schema.styles[0].value) != null ? _a : "normal",
6005
6222
  markDefs: [],
6006
- children: action.textBlock?.children?.map((child) => ({
6007
- ...child,
6223
+ children: (_d = (_c = (_b = action.textBlock) == null ? void 0 : _b.children) == null ? void 0 : _c.map((child) => __spreadProps$5(__spreadValues$5({}, child), {
6008
6224
  _key: context.keyGenerator()
6009
- })) ?? [{
6225
+ }))) != null ? _d : [{
6010
6226
  _type: context.schema.span.name,
6011
6227
  _key: context.keyGenerator(),
6012
6228
  text: ""
@@ -6099,11 +6315,7 @@ const insertBlockObjectActionImplementation = ({
6099
6315
  action
6100
6316
  }) => {
6101
6317
  const selection = action.editor.selection;
6102
- selection && (Transforms.select(action.editor, {
6103
- ...selection
6104
- }), action.editor.selection = {
6105
- ...selection
6106
- });
6318
+ selection && (Transforms.select(action.editor, __spreadValues$5({}, selection)), action.editor.selection = __spreadValues$5({}, selection));
6107
6319
  },
6108
6320
  "style.toggle": toggleStyleActionImplementation,
6109
6321
  "style.add": addStyleActionImplementation,
@@ -6375,6 +6587,14 @@ function performDefaultAction({
6375
6587
  });
6376
6588
  }
6377
6589
  }
6590
+ var __defProp$4 = Object.defineProperty, __defProps$4 = Object.defineProperties, __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$4 = Object.getOwnPropertySymbols, __hasOwnProp$4 = Object.prototype.hasOwnProperty, __propIsEnum$4 = Object.prototype.propertyIsEnumerable, __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$4 = (a, b) => {
6591
+ for (var prop in b || (b = {}))
6592
+ __hasOwnProp$4.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
6593
+ if (__getOwnPropSymbols$4)
6594
+ for (var prop of __getOwnPropSymbols$4(b))
6595
+ __propIsEnum$4.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
6596
+ return a;
6597
+ }, __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
6378
6598
  const editorMachine = setup({
6379
6599
  types: {
6380
6600
  context: {},
@@ -6420,11 +6640,11 @@ const editorMachine = setup({
6420
6640
  event,
6421
6641
  enqueue
6422
6642
  }) => {
6643
+ var _a;
6423
6644
  assertEvent(event, ["behavior event"]), debug$l("Behavior event", event);
6424
- const defaultAction = event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" ? void 0 : {
6425
- ...event.behaviorEvent,
6645
+ const defaultAction = event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" ? void 0 : __spreadProps$4(__spreadValues$4({}, event.behaviorEvent), {
6426
6646
  editor: event.editor
6427
- }, eventBehaviors = context.behaviors.filter((behavior) => behavior.on === event.behaviorEvent.type);
6647
+ }), eventBehaviors = context.behaviors.filter((behavior) => behavior.on === event.behaviorEvent.type);
6428
6648
  if (eventBehaviors.length === 0) {
6429
6649
  if (!defaultAction)
6430
6650
  return;
@@ -6468,7 +6688,7 @@ const editorMachine = setup({
6468
6688
  actionIntends
6469
6689
  });
6470
6690
  if (behaviorOverwritten) {
6471
- event.nativeEvent?.preventDefault();
6691
+ (_a = event.nativeEvent) == null || _a.preventDefault();
6472
6692
  break;
6473
6693
  }
6474
6694
  }
@@ -6487,16 +6707,19 @@ const editorMachine = setup({
6487
6707
  id: "editor",
6488
6708
  context: ({
6489
6709
  input
6490
- }) => ({
6491
- behaviors: input.behaviors ?? coreBehaviors,
6492
- keyGenerator: input.keyGenerator,
6493
- pendingEvents: [],
6494
- schema: input.schema,
6495
- selection: void 0,
6496
- readOnly: input.readOnly ?? !1,
6497
- maxBlocks: input.maxBlocks,
6498
- value: input.value
6499
- }),
6710
+ }) => {
6711
+ var _a, _b;
6712
+ return {
6713
+ behaviors: (_a = input.behaviors) != null ? _a : coreBehaviors,
6714
+ keyGenerator: input.keyGenerator,
6715
+ pendingEvents: [],
6716
+ schema: input.schema,
6717
+ selection: void 0,
6718
+ readOnly: (_b = input.readOnly) != null ? _b : !1,
6719
+ maxBlocks: input.maxBlocks,
6720
+ value: input.value
6721
+ };
6722
+ },
6500
6723
  on: {
6501
6724
  "annotation.add": {
6502
6725
  actions: emit(({
@@ -6599,7 +6822,10 @@ const editorMachine = setup({
6599
6822
  actions: [assign({
6600
6823
  selection: ({
6601
6824
  event
6602
- }) => event.selection ?? void 0
6825
+ }) => {
6826
+ var _a;
6827
+ return (_a = event.selection) != null ? _a : void 0;
6828
+ }
6603
6829
  }), emit(({
6604
6830
  event
6605
6831
  }) => event)]
@@ -6674,10 +6900,9 @@ const editorMachine = setup({
6674
6900
  }) => {
6675
6901
  Editor.withoutNormalizing(event.editor, () => {
6676
6902
  for (const actionIntend of event.actionIntends) {
6677
- const action = {
6678
- ...actionIntend,
6903
+ const action = __spreadProps$4(__spreadValues$4({}, actionIntend), {
6679
6904
  editor: event.editor
6680
- };
6905
+ });
6681
6906
  performAction({
6682
6907
  context,
6683
6908
  action
@@ -6776,7 +7001,7 @@ function createEditor(config) {
6776
7001
  },
6777
7002
  on: (event, listener) => editorActor.on(
6778
7003
  event,
6779
- // @ts-ignore
7004
+ // @ts-expect-error
6780
7005
  listener
6781
7006
  ),
6782
7007
  _internal: {
@@ -6787,31 +7012,41 @@ function createEditor(config) {
6787
7012
  };
6788
7013
  }
6789
7014
  function useCreateEditor(config) {
6790
- const editorActor = useActorRef(editorMachine, {
6791
- input: editorConfigToMachineInput(config)
6792
- }), slateEditor = createSlateEditor({
7015
+ const $ = c(18);
7016
+ let t0;
7017
+ $[0] !== config ? (t0 = editorConfigToMachineInput(config), $[0] = config, $[1] = t0) : t0 = $[1];
7018
+ let t1;
7019
+ $[2] !== t0 ? (t1 = {
7020
+ input: t0
7021
+ }, $[2] = t0, $[3] = t1) : t1 = $[3];
7022
+ const editorActor = useActorRef(editorMachine, t1);
7023
+ let t2, slateEditor, t3;
7024
+ $[4] !== editorActor ? (slateEditor = createSlateEditor({
6793
7025
  editorActor
6794
- }), editable = useMemo(() => createEditableAPI(slateEditor.instance, editorActor), [slateEditor.instance, editorActor]), send = useCallback((event) => {
7026
+ }), t3 = createEditableAPI(slateEditor.instance, editorActor), $[4] = editorActor, $[5] = slateEditor, $[6] = t3) : (slateEditor = $[5], t3 = $[6]);
7027
+ const editable = t3;
7028
+ let t4, t5;
7029
+ $[7] !== editorActor ? (t4 = (event) => {
6795
7030
  editorActor.send(event);
6796
- }, [editorActor]), on = useCallback((event_0, listener) => editorActor.on(
6797
- event_0,
6798
- // @ts-ignore
6799
- listener
6800
- ), [editorActor]);
6801
- return useMemo(() => ({
6802
- send,
6803
- on,
6804
- _internal: {
6805
- editable,
6806
- editorActor,
6807
- slateEditor
6808
- }
6809
- }), [send, on, editable, editorActor, slateEditor]);
7031
+ }, t5 = (event_0, listener) => editorActor.on(event_0, listener), $[7] = editorActor, $[8] = t4, $[9] = t5) : (t4 = $[8], t5 = $[9]);
7032
+ let t6;
7033
+ $[10] !== editable || $[11] !== editorActor || $[12] !== slateEditor ? (t6 = {
7034
+ editable,
7035
+ editorActor,
7036
+ slateEditor
7037
+ }, $[10] = editable, $[11] = editorActor, $[12] = slateEditor, $[13] = t6) : t6 = $[13];
7038
+ let t7;
7039
+ return $[14] !== t4 || $[15] !== t5 || $[16] !== t6 ? (t7 = {
7040
+ send: t4,
7041
+ on: t5,
7042
+ _internal: t6
7043
+ }, $[14] = t4, $[15] = t5, $[16] = t6, $[17] = t7) : t7 = $[17], t2 = t7, t2;
6810
7044
  }
6811
7045
  function editorConfigToMachineInput(config) {
7046
+ var _a;
6812
7047
  return {
6813
7048
  behaviors: config.behaviors,
6814
- keyGenerator: config.keyGenerator ?? defaultKeyGenerator,
7049
+ keyGenerator: (_a = config.keyGenerator) != null ? _a : defaultKeyGenerator,
6815
7050
  maxBlocks: config.maxBlocks,
6816
7051
  readOnly: config.readOnly,
6817
7052
  schema: config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : getPortableTextMemberSchemaTypes(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)),
@@ -6841,13 +7076,16 @@ function PortableTextEditorSelectionProvider(props) {
6841
7076
  let t2;
6842
7077
  return $[3] !== props.children || $[4] !== selection ? (t2 = /* @__PURE__ */ jsx(PortableTextEditorSelectionContext.Provider, { value: selection, children: props.children }), $[3] = props.children, $[4] = selection, $[5] = t2) : t2 = $[5], t2;
6843
7078
  }
7079
+ var __defProp$3 = Object.defineProperty, __defProps$3 = Object.defineProperties, __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$3 = Object.getOwnPropertySymbols, __hasOwnProp$3 = Object.prototype.hasOwnProperty, __propIsEnum$3 = Object.prototype.propertyIsEnumerable, __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$3 = (a, b) => {
7080
+ for (var prop in b || (b = {}))
7081
+ __hasOwnProp$3.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
7082
+ if (__getOwnPropSymbols$3)
7083
+ for (var prop of __getOwnPropSymbols$3(b))
7084
+ __propIsEnum$3.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
7085
+ return a;
7086
+ }, __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b)), __publicField = (obj, key, value) => __defNormalProp$3(obj, typeof key != "symbol" ? key + "" : key, value);
6844
7087
  const debug$4 = debugWithName("component:PortableTextEditor");
6845
7088
  class PortableTextEditor extends Component {
6846
- static displayName = "PortableTextEditor";
6847
- /**
6848
- * An observable of all the editor changes.
6849
- */
6850
- change$ = new Subject();
6851
7089
  /**
6852
7090
  * A lookup table for all the relevant schema types for this portable text type.
6853
7091
  */
@@ -6858,8 +7096,11 @@ class PortableTextEditor extends Component {
6858
7096
  * The editor API (currently implemented with Slate).
6859
7097
  */
6860
7098
  constructor(props) {
6861
- super(props), props.editor ? this.editor = props.editor : this.editor = createEditor({
6862
- keyGenerator: props.keyGenerator ?? defaultKeyGenerator,
7099
+ var _a;
7100
+ super(props), __publicField(this, "change$", new Subject()), __publicField(this, "setEditable", (editable) => {
7101
+ this.editor._internal.editable = __spreadValues$3(__spreadValues$3({}, this.editor._internal.editable), editable);
7102
+ }), props.editor ? this.editor = props.editor : this.editor = createEditor({
7103
+ keyGenerator: (_a = props.keyGenerator) != null ? _a : defaultKeyGenerator,
6863
7104
  schema: props.schemaType,
6864
7105
  initialValue: props.value,
6865
7106
  maxBlocks: props.maxBlocks === void 0 ? void 0 : Number.parseInt(props.maxBlocks.toString(), 10),
@@ -6880,14 +7121,9 @@ class PortableTextEditor extends Component {
6880
7121
  value: this.props.value
6881
7122
  }), this.props.editorRef !== prevProps.editorRef && this.props.editorRef && (this.props.editorRef.current = this));
6882
7123
  }
6883
- setEditable = (editable) => {
6884
- this.editor._internal.editable = {
6885
- ...this.editor._internal.editable,
6886
- ...editable
6887
- };
6888
- };
6889
7124
  render() {
6890
- const legacyPatches = this.props.editor ? void 0 : this.props.incomingPatches$ ?? this.props.patches$;
7125
+ var _a;
7126
+ const legacyPatches = this.props.editor ? void 0 : (_a = this.props.incomingPatches$) != null ? _a : this.props.patches$;
6891
7127
  return /* @__PURE__ */ jsxs(Fragment, { children: [
6892
7128
  legacyPatches ? /* @__PURE__ */ jsx(RoutePatchesObservableToEditorActor, { editorActor: this.editor._internal.editorActor, patches$: legacyPatches }) : null,
6893
7129
  /* @__PURE__ */ jsx(RouteEventsToChanges, { editorActor: this.editor._internal.editorActor, onChange: (change) => {
@@ -6897,65 +7133,105 @@ class PortableTextEditor extends Component {
6897
7133
  /* @__PURE__ */ jsx(EditorActorContext.Provider, { value: this.editor._internal.editorActor, children: /* @__PURE__ */ jsx(Slate, { editor: this.editor._internal.slateEditor.instance, initialValue: this.editor._internal.slateEditor.initialValue, children: /* @__PURE__ */ jsx(PortableTextEditorContext.Provider, { value: this, children: /* @__PURE__ */ jsx(PortableTextEditorSelectionProvider, { editorActor: this.editor._internal.editorActor, children: this.props.children }) }) }) })
6898
7134
  ] });
6899
7135
  }
6900
- // Static API methods
6901
- static activeAnnotations = (editor) => editor && editor.editable ? editor.editable.activeAnnotations() : [];
6902
- static isAnnotationActive = (editor, annotationType) => editor && editor.editable ? editor.editable.isAnnotationActive(annotationType) : !1;
6903
- static addAnnotation = (editor, type, value) => editor.editable?.addAnnotation(type, value);
6904
- static blur = (editor) => {
6905
- debug$4("Host blurred"), editor.editable?.blur();
6906
- };
6907
- static delete = (editor, selection, options) => editor.editable?.delete(selection, options);
6908
- static findDOMNode = (editor, element) => editor.editable?.findDOMNode(element);
6909
- static findByPath = (editor, path) => editor.editable?.findByPath(path) || [];
6910
- static focus = (editor) => {
6911
- debug$4("Host requesting focus"), editor.editable?.focus();
6912
- };
6913
- static focusBlock = (editor) => editor.editable?.focusBlock();
6914
- static focusChild = (editor) => editor.editable?.focusChild();
6915
- static getSelection = (editor) => editor.editable ? editor.editable.getSelection() : null;
6916
- static getValue = (editor) => editor.editable?.getValue();
6917
- static hasBlockStyle = (editor, blockStyle) => editor.editable?.hasBlockStyle(blockStyle);
6918
- static hasListStyle = (editor, listStyle) => editor.editable?.hasListStyle(listStyle);
6919
- static isCollapsedSelection = (editor) => editor.editable?.isCollapsedSelection();
6920
- static isExpandedSelection = (editor) => editor.editable?.isExpandedSelection();
6921
- static isMarkActive = (editor, mark) => editor.editable?.isMarkActive(mark);
6922
- static insertChild = (editor, type, value) => (debug$4("Host inserting child"), editor.editable?.insertChild(type, value));
6923
- static insertBlock = (editor, type, value) => editor.editable?.insertBlock(type, value);
6924
- static insertBreak = (editor) => editor.editable?.insertBreak();
6925
- static isVoid = (editor, element) => editor.editable?.isVoid(element);
6926
- static isObjectPath = (_editor, path) => {
6927
- if (!path || !Array.isArray(path)) return !1;
6928
- const isChildObjectEditPath = path.length > 3 && path[1] === "children";
6929
- return path.length > 1 && path[1] !== "children" || isChildObjectEditPath;
6930
- };
6931
- static marks = (editor) => editor.editable?.marks();
6932
- static select = (editor, selection) => {
6933
- debug$4("Host setting selection", selection), editor.editable?.select(selection);
6934
- };
6935
- static removeAnnotation = (editor, type) => editor.editable?.removeAnnotation(type);
6936
- static toggleBlockStyle = (editor, blockStyle) => (debug$4("Host is toggling block style"), editor.editable?.toggleBlockStyle(blockStyle));
6937
- static toggleList = (editor, listStyle) => editor.editable?.toggleList(listStyle);
6938
- static toggleMark = (editor, mark) => {
6939
- debug$4("Host toggling mark", mark), editor.editable?.toggleMark(mark);
6940
- };
6941
- static getFragment = (editor) => (debug$4("Host getting fragment"), editor.editable?.getFragment());
6942
- static undo = (editor) => {
6943
- debug$4("Host undoing"), editor.editable?.undo();
6944
- };
6945
- static redo = (editor) => {
6946
- debug$4("Host redoing"), editor.editable?.redo();
6947
- };
6948
- static isSelectionsOverlapping = (editor, selectionA, selectionB) => editor.editable?.isSelectionsOverlapping(selectionA, selectionB);
6949
7136
  }
7137
+ __publicField(PortableTextEditor, "displayName", "PortableTextEditor"), // Static API methods
7138
+ __publicField(PortableTextEditor, "activeAnnotations", (editor) => editor && editor.editable ? editor.editable.activeAnnotations() : []), __publicField(PortableTextEditor, "isAnnotationActive", (editor, annotationType) => editor && editor.editable ? editor.editable.isAnnotationActive(annotationType) : !1), __publicField(PortableTextEditor, "addAnnotation", (editor, type, value) => {
7139
+ var _a;
7140
+ return (_a = editor.editable) == null ? void 0 : _a.addAnnotation(type, value);
7141
+ }), __publicField(PortableTextEditor, "blur", (editor) => {
7142
+ var _a;
7143
+ debug$4("Host blurred"), (_a = editor.editable) == null || _a.blur();
7144
+ }), __publicField(PortableTextEditor, "delete", (editor, selection, options) => {
7145
+ var _a;
7146
+ return (_a = editor.editable) == null ? void 0 : _a.delete(selection, options);
7147
+ }), __publicField(PortableTextEditor, "findDOMNode", (editor, element) => {
7148
+ var _a;
7149
+ return (_a = editor.editable) == null ? void 0 : _a.findDOMNode(element);
7150
+ }), __publicField(PortableTextEditor, "findByPath", (editor, path) => {
7151
+ var _a;
7152
+ return ((_a = editor.editable) == null ? void 0 : _a.findByPath(path)) || [];
7153
+ }), __publicField(PortableTextEditor, "focus", (editor) => {
7154
+ var _a;
7155
+ debug$4("Host requesting focus"), (_a = editor.editable) == null || _a.focus();
7156
+ }), __publicField(PortableTextEditor, "focusBlock", (editor) => {
7157
+ var _a;
7158
+ return (_a = editor.editable) == null ? void 0 : _a.focusBlock();
7159
+ }), __publicField(PortableTextEditor, "focusChild", (editor) => {
7160
+ var _a;
7161
+ return (_a = editor.editable) == null ? void 0 : _a.focusChild();
7162
+ }), __publicField(PortableTextEditor, "getSelection", (editor) => editor.editable ? editor.editable.getSelection() : null), __publicField(PortableTextEditor, "getValue", (editor) => {
7163
+ var _a;
7164
+ return (_a = editor.editable) == null ? void 0 : _a.getValue();
7165
+ }), __publicField(PortableTextEditor, "hasBlockStyle", (editor, blockStyle) => {
7166
+ var _a;
7167
+ return (_a = editor.editable) == null ? void 0 : _a.hasBlockStyle(blockStyle);
7168
+ }), __publicField(PortableTextEditor, "hasListStyle", (editor, listStyle) => {
7169
+ var _a;
7170
+ return (_a = editor.editable) == null ? void 0 : _a.hasListStyle(listStyle);
7171
+ }), __publicField(PortableTextEditor, "isCollapsedSelection", (editor) => {
7172
+ var _a;
7173
+ return (_a = editor.editable) == null ? void 0 : _a.isCollapsedSelection();
7174
+ }), __publicField(PortableTextEditor, "isExpandedSelection", (editor) => {
7175
+ var _a;
7176
+ return (_a = editor.editable) == null ? void 0 : _a.isExpandedSelection();
7177
+ }), __publicField(PortableTextEditor, "isMarkActive", (editor, mark) => {
7178
+ var _a;
7179
+ return (_a = editor.editable) == null ? void 0 : _a.isMarkActive(mark);
7180
+ }), __publicField(PortableTextEditor, "insertChild", (editor, type, value) => {
7181
+ var _a;
7182
+ return debug$4("Host inserting child"), (_a = editor.editable) == null ? void 0 : _a.insertChild(type, value);
7183
+ }), __publicField(PortableTextEditor, "insertBlock", (editor, type, value) => {
7184
+ var _a;
7185
+ return (_a = editor.editable) == null ? void 0 : _a.insertBlock(type, value);
7186
+ }), __publicField(PortableTextEditor, "insertBreak", (editor) => {
7187
+ var _a;
7188
+ return (_a = editor.editable) == null ? void 0 : _a.insertBreak();
7189
+ }), __publicField(PortableTextEditor, "isVoid", (editor, element) => {
7190
+ var _a;
7191
+ return (_a = editor.editable) == null ? void 0 : _a.isVoid(element);
7192
+ }), __publicField(PortableTextEditor, "isObjectPath", (_editor, path) => {
7193
+ if (!path || !Array.isArray(path)) return !1;
7194
+ const isChildObjectEditPath = path.length > 3 && path[1] === "children";
7195
+ return path.length > 1 && path[1] !== "children" || isChildObjectEditPath;
7196
+ }), __publicField(PortableTextEditor, "marks", (editor) => {
7197
+ var _a;
7198
+ return (_a = editor.editable) == null ? void 0 : _a.marks();
7199
+ }), __publicField(PortableTextEditor, "select", (editor, selection) => {
7200
+ var _a;
7201
+ debug$4("Host setting selection", selection), (_a = editor.editable) == null || _a.select(selection);
7202
+ }), __publicField(PortableTextEditor, "removeAnnotation", (editor, type) => {
7203
+ var _a;
7204
+ return (_a = editor.editable) == null ? void 0 : _a.removeAnnotation(type);
7205
+ }), __publicField(PortableTextEditor, "toggleBlockStyle", (editor, blockStyle) => {
7206
+ var _a;
7207
+ return debug$4("Host is toggling block style"), (_a = editor.editable) == null ? void 0 : _a.toggleBlockStyle(blockStyle);
7208
+ }), __publicField(PortableTextEditor, "toggleList", (editor, listStyle) => {
7209
+ var _a;
7210
+ return (_a = editor.editable) == null ? void 0 : _a.toggleList(listStyle);
7211
+ }), __publicField(PortableTextEditor, "toggleMark", (editor, mark) => {
7212
+ var _a;
7213
+ debug$4("Host toggling mark", mark), (_a = editor.editable) == null || _a.toggleMark(mark);
7214
+ }), __publicField(PortableTextEditor, "getFragment", (editor) => {
7215
+ var _a;
7216
+ return debug$4("Host getting fragment"), (_a = editor.editable) == null ? void 0 : _a.getFragment();
7217
+ }), __publicField(PortableTextEditor, "undo", (editor) => {
7218
+ var _a;
7219
+ debug$4("Host undoing"), (_a = editor.editable) == null || _a.undo();
7220
+ }), __publicField(PortableTextEditor, "redo", (editor) => {
7221
+ var _a;
7222
+ debug$4("Host redoing"), (_a = editor.editable) == null || _a.redo();
7223
+ }), __publicField(PortableTextEditor, "isSelectionsOverlapping", (editor, selectionA, selectionB) => {
7224
+ var _a;
7225
+ return (_a = editor.editable) == null ? void 0 : _a.isSelectionsOverlapping(selectionA, selectionB);
7226
+ });
6950
7227
  function RoutePatchesObservableToEditorActor(props) {
6951
7228
  const $ = c(4);
6952
7229
  let t0, t1;
6953
7230
  return $[0] !== props.editorActor || $[1] !== props.patches$ ? (t0 = () => {
6954
7231
  const subscription = props.patches$.subscribe((payload) => {
6955
- props.editorActor.send({
6956
- type: "patches",
6957
- ...payload
6958
- });
7232
+ props.editorActor.send(__spreadValues$3({
7233
+ type: "patches"
7234
+ }, payload));
6959
7235
  });
6960
7236
  return () => {
6961
7237
  subscription.unsubscribe();
@@ -7020,10 +7296,9 @@ function RouteEventsToChanges(props) {
7020
7296
  break bb5;
7021
7297
  }
7022
7298
  case "error": {
7023
- handleChange({
7024
- ...event,
7299
+ handleChange(__spreadProps$3(__spreadValues$3({}, event), {
7025
7300
  level: "warning"
7026
- });
7301
+ }));
7027
7302
  break bb5;
7028
7303
  }
7029
7304
  case "annotation.add":
@@ -7050,6 +7325,14 @@ function RouteEventsToChanges(props) {
7050
7325
  };
7051
7326
  }, t2 = [props.editorActor, handleChange], $[2] = handleChange, $[3] = props.editorActor, $[4] = t1, $[5] = t2) : (t1 = $[4], t2 = $[5]), useEffect(t1, t2), null;
7052
7327
  }
7328
+ var __defProp$2 = Object.defineProperty, __defProps$2 = Object.defineProperties, __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$2 = Object.getOwnPropertySymbols, __hasOwnProp$2 = Object.prototype.hasOwnProperty, __propIsEnum$2 = Object.prototype.propertyIsEnumerable, __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$2 = (a, b) => {
7329
+ for (var prop in b || (b = {}))
7330
+ __hasOwnProp$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
7331
+ if (__getOwnPropSymbols$2)
7332
+ for (var prop of __getOwnPropSymbols$2(b))
7333
+ __propIsEnum$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
7334
+ return a;
7335
+ }, __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
7053
7336
  const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (props) => {
7054
7337
  const {
7055
7338
  editorActor,
@@ -7061,10 +7344,13 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
7061
7344
  renderDecorator,
7062
7345
  renderAnnotation
7063
7346
  } = props, spanRef = useRef(null), portableTextEditor = usePortableTextEditor(), blockSelected = useSelected(), [focused, setFocused] = useState(!1), [selected, setSelected] = useState(!1), block = children.props.parent, path = useMemo(() => block ? [{
7064
- _key: block?._key
7347
+ _key: block == null ? void 0 : block._key
7065
7348
  }, "children", {
7066
7349
  _key: leaf._key
7067
- }] : [], [block, leaf._key]), decoratorValues = useMemo(() => schemaTypes.decorators.map((dec) => dec.value), [schemaTypes.decorators]), marks = useMemo(() => uniq((leaf.marks || EMPTY_MARKS).filter((mark) => decoratorValues.includes(mark))), [decoratorValues, leaf.marks]), annotationMarks = Array.isArray(leaf.marks) ? leaf.marks : EMPTY_MARKS, annotations = 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;
7350
+ }] : [], [block, leaf._key]), decoratorValues = useMemo(() => schemaTypes.decorators.map((dec) => dec.value), [schemaTypes.decorators]), marks = useMemo(() => uniq((leaf.marks || EMPTY_MARKS).filter((mark) => decoratorValues.includes(mark))), [decoratorValues, leaf.marks]), annotationMarks = Array.isArray(leaf.marks) ? leaf.marks : EMPTY_MARKS, annotations = useMemo(() => annotationMarks.map((mark_0) => {
7351
+ var _a;
7352
+ return !decoratorValues.includes(mark_0) && ((_a = block == null ? void 0 : block.markDefs) == null ? void 0 : _a.find((def) => def._key === mark_0));
7353
+ }).filter(Boolean), [annotationMarks, block, decoratorValues]), shouldTrackSelectionAndFocus = annotations.length > 0 && blockSelected;
7068
7354
  useEffect(() => {
7069
7355
  if (!shouldTrackSelectionAndFocus) {
7070
7356
  setFocused(!1);
@@ -7171,7 +7457,7 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
7171
7457
  }
7172
7458
  return returnedChildren;
7173
7459
  }, [annotations, block, children, focused, leaf, marks, path, renderAnnotation, renderChild, renderDecorator, schemaTypes.annotations, schemaTypes.decorators, schemaTypes.span, selected]);
7174
- return useMemo(() => /* @__PURE__ */ jsx("span", { ...attributes, ref: spanRef, children: content }, leaf._key), [leaf, attributes, content]);
7460
+ return useMemo(() => /* @__PURE__ */ jsx("span", __spreadProps$2(__spreadValues$2({}, attributes), { ref: spanRef, children: content }), leaf._key), [leaf, attributes, content]);
7175
7461
  };
7176
7462
  Leaf.displayName = "Leaf";
7177
7463
  const debug$2 = debugWithName("plugin:withHotKeys"), DEFAULT_HOTKEYS = {
@@ -7224,10 +7510,32 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
7224
7510
  }, editor;
7225
7511
  };
7226
7512
  }
7513
+ var __defProp$1 = Object.defineProperty, __defProps$1 = Object.defineProperties, __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$1 = Object.getOwnPropertySymbols, __hasOwnProp$1 = Object.prototype.hasOwnProperty, __propIsEnum$1 = Object.prototype.propertyIsEnumerable, __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$1 = (a, b) => {
7514
+ for (var prop in b || (b = {}))
7515
+ __hasOwnProp$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
7516
+ if (__getOwnPropSymbols$1)
7517
+ for (var prop of __getOwnPropSymbols$1(b))
7518
+ __propIsEnum$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
7519
+ return a;
7520
+ }, __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b)), __objRest$1 = (source, exclude) => {
7521
+ var target = {};
7522
+ for (var prop in source)
7523
+ __hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
7524
+ if (source != null && __getOwnPropSymbols$1)
7525
+ for (var prop of __getOwnPropSymbols$1(source))
7526
+ exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop) && (target[prop] = source[prop]);
7527
+ return target;
7528
+ };
7227
7529
  const debug$1 = debugWithName("plugin:withInsertData");
7228
7530
  function createWithInsertData(editorActor, schemaTypes) {
7229
7531
  return function(editor) {
7230
- const blockTypeName = schemaTypes.block.name, spanTypeName = schemaTypes.span.name, whitespaceOnPasteMode = schemaTypes.block.options.unstable_whitespaceOnPasteMode, toPlainText = (blocks) => blocks.map((block) => editor.isTextBlock(block) ? block.children.map((child) => child._type === spanTypeName ? child.text : `[${schemaTypes.inlineObjects.find((t) => t.name === child._type)?.title || "Object"}]`).join("") : `[${schemaTypes.blockObjects.find((t) => t.name === block._type)?.title || "Object"}]`).join(`
7532
+ const blockTypeName = schemaTypes.block.name, spanTypeName = schemaTypes.span.name, whitespaceOnPasteMode = schemaTypes.block.options.unstable_whitespaceOnPasteMode, toPlainText = (blocks) => blocks.map((block) => {
7533
+ var _a;
7534
+ return editor.isTextBlock(block) ? block.children.map((child) => {
7535
+ var _a2;
7536
+ return child._type === spanTypeName ? child.text : `[${((_a2 = schemaTypes.inlineObjects.find((t) => t.name === child._type)) == null ? void 0 : _a2.title) || "Object"}]`;
7537
+ }).join("") : `[${((_a = schemaTypes.blockObjects.find((t) => t.name === block._type)) == null ? void 0 : _a.title) || "Object"}]`;
7538
+ }).join(`
7231
7539
 
7232
7540
  `);
7233
7541
  return editor.setFragmentData = (data, originEvent) => {
@@ -7265,6 +7573,7 @@ function createWithInsertData(editorActor, schemaTypes) {
7265
7573
  const fragment = editor.getFragment(), portableText = fromSlateValue(fragment, blockTypeName), asJSON = JSON.stringify(portableText), asPlainText = toPlainText(portableText);
7266
7574
  data.clearData(), data.setData("text/plain", asPlainText), data.setData("text/html", asHTML), data.setData("application/json", asJSON), data.setData("application/x-portable-text", asJSON), debug$1("text", asPlainText), data.setData("application/x-portable-text-event-origin", originEvent || "external"), debug$1("Set fragment data", asJSON, asHTML);
7267
7575
  }, editor.insertPortableTextData = (data) => {
7576
+ var _a, _b;
7268
7577
  if (!editor.selection)
7269
7578
  return !1;
7270
7579
  const pText = data.getData("application/x-portable-text"), origin = data.getData("application/x-portable-text-event-origin");
@@ -7274,8 +7583,8 @@ function createWithInsertData(editorActor, schemaTypes) {
7274
7583
  const slateValue = _regenerateKeys(editor, toSlateValue(parsed, {
7275
7584
  schemaTypes
7276
7585
  }), editorActor.getSnapshot().context.keyGenerator, spanTypeName, schemaTypes), validation = validateValue(parsed, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
7277
- if (!validation.valid && !validation.resolution?.autoResolve) {
7278
- const errorDescription = `${validation.resolution?.description}`;
7586
+ if (!validation.valid && !((_a = validation.resolution) != null && _a.autoResolve)) {
7587
+ const errorDescription = `${(_b = validation.resolution) == null ? void 0 : _b.description}`;
7279
7588
  return editorActor.send({
7280
7589
  type: "error",
7281
7590
  name: "pasteError",
@@ -7288,6 +7597,7 @@ function createWithInsertData(editorActor, schemaTypes) {
7288
7597
  }
7289
7598
  return !1;
7290
7599
  }, editor.insertTextOrHTMLData = (data) => {
7600
+ var _a;
7291
7601
  if (!editor.selection)
7292
7602
  return debug$1("No selection, not inserting"), !1;
7293
7603
  const html = data.getData("text/html"), text = data.getData("text/plain");
@@ -7314,7 +7624,7 @@ function createWithInsertData(editorActor, schemaTypes) {
7314
7624
  const validation = validateValue(portableText, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
7315
7625
  if (!validation.valid) {
7316
7626
  const errorDescription = `Could not validate the resulting portable text to insert.
7317
- ${validation.resolution?.description}
7627
+ ${(_a = validation.resolution) == null ? void 0 : _a.description}
7318
7628
  Try to insert as plain text (shift-paste) instead.`;
7319
7629
  return editorActor.send({
7320
7630
  type: "error",
@@ -7353,46 +7663,37 @@ function escapeHtml(str) {
7353
7663
  }
7354
7664
  function _regenerateKeys(editor, fragment, keyGenerator, spanTypeName, editorTypes) {
7355
7665
  return fragment.map((node) => {
7356
- const newNode = {
7357
- ...node
7358
- };
7666
+ const newNode = __spreadValues$1({}, node);
7359
7667
  if (editor.isTextBlock(newNode)) {
7360
7668
  const annotations = editorTypes.annotations.map((t) => t.name);
7361
7669
  if (annotations.length === 0) {
7362
- const {
7363
- markDefs,
7364
- ...NewNodeNoDefs
7365
- } = newNode;
7366
- return {
7367
- ...NewNodeNoDefs,
7670
+ const _a = newNode, NewNodeNoDefs = __objRest$1(_a, [
7671
+ "markDefs"
7672
+ ]);
7673
+ return __spreadProps$1(__spreadValues$1({}, NewNodeNoDefs), {
7368
7674
  _key: keyGenerator()
7369
- };
7675
+ });
7370
7676
  }
7371
7677
  if ((newNode.markDefs || []).some((def) => !annotations.includes(def._type))) {
7372
7678
  const allowedAnnotations = (newNode.markDefs || []).filter((def) => annotations.includes(def._type));
7373
- return {
7374
- ...newNode,
7679
+ return __spreadProps$1(__spreadValues$1({}, newNode), {
7375
7680
  markDefs: allowedAnnotations,
7376
7681
  _key: keyGenerator()
7377
- };
7682
+ });
7378
7683
  }
7379
7684
  newNode.markDefs = (newNode.markDefs || []).map((def) => {
7380
7685
  const oldKey = def._key, newKey = keyGenerator();
7381
- return newNode.children = newNode.children.map((child) => child._type === spanTypeName && editor.isTextSpan(child) ? {
7382
- ...child,
7686
+ return newNode.children = newNode.children.map((child) => child._type === spanTypeName && editor.isTextSpan(child) ? __spreadProps$1(__spreadValues$1({}, child), {
7383
7687
  marks: child.marks && child.marks.includes(oldKey) ? [...child.marks].filter((mark) => mark !== oldKey).concat(newKey) : child.marks
7384
- } : child), {
7385
- ...def,
7688
+ }) : child), __spreadProps$1(__spreadValues$1({}, def), {
7386
7689
  _key: newKey
7387
- };
7690
+ });
7388
7691
  });
7389
7692
  }
7390
- const nodeWithNewKeys = {
7391
- ...newNode,
7693
+ const nodeWithNewKeys = __spreadProps$1(__spreadValues$1({}, newNode), {
7392
7694
  _key: keyGenerator()
7393
- };
7394
- return editor.isTextBlock(nodeWithNewKeys) && (nodeWithNewKeys.children = nodeWithNewKeys.children.map((child) => ({
7395
- ...child,
7695
+ });
7696
+ return editor.isTextBlock(nodeWithNewKeys) && (nodeWithNewKeys.children = nodeWithNewKeys.children.map((child) => __spreadProps$1(__spreadValues$1({}, child), {
7396
7697
  _key: keyGenerator()
7397
7698
  }))), nodeWithNewKeys;
7398
7699
  });
@@ -7431,6 +7732,22 @@ function withSyncRangeDecorations(slateEditor, syncRangeDecorations) {
7431
7732
  slateEditor.apply = originalApply;
7432
7733
  };
7433
7734
  }
7735
+ var __defProp2 = Object.defineProperty, __defProps = Object.defineProperties, __getOwnPropDescs = Object.getOwnPropertyDescriptors, __getOwnPropSymbols2 = Object.getOwnPropertySymbols, __hasOwnProp2 = Object.prototype.hasOwnProperty, __propIsEnum2 = Object.prototype.propertyIsEnumerable, __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues2 = (a, b) => {
7736
+ for (var prop in b || (b = {}))
7737
+ __hasOwnProp2.call(b, prop) && __defNormalProp2(a, prop, b[prop]);
7738
+ if (__getOwnPropSymbols2)
7739
+ for (var prop of __getOwnPropSymbols2(b))
7740
+ __propIsEnum2.call(b, prop) && __defNormalProp2(a, prop, b[prop]);
7741
+ return a;
7742
+ }, __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)), __objRest = (source, exclude) => {
7743
+ var target = {};
7744
+ for (var prop in source)
7745
+ __hasOwnProp2.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
7746
+ if (source != null && __getOwnPropSymbols2)
7747
+ for (var prop of __getOwnPropSymbols2(source))
7748
+ exclude.indexOf(prop) < 0 && __propIsEnum2.call(source, prop) && (target[prop] = source[prop]);
7749
+ return target;
7750
+ };
7434
7751
  const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
7435
7752
  position: "absolute",
7436
7753
  userSelect: "none",
@@ -7438,7 +7755,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
7438
7755
  left: 0,
7439
7756
  right: 0
7440
7757
  }, PortableTextEditable = forwardRef(function(props, forwardedRef) {
7441
- const {
7758
+ const _a = props, {
7442
7759
  hotkeys,
7443
7760
  onBlur,
7444
7761
  onFocus,
@@ -7456,9 +7773,27 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
7456
7773
  renderStyle,
7457
7774
  selection: propsSelection,
7458
7775
  scrollSelectionIntoView,
7459
- spellCheck,
7460
- ...restProps
7461
- } = props, portableTextEditor = usePortableTextEditor(), ref = useRef(null), [editableElement, setEditableElement] = useState(null), [hasInvalidValue, setHasInvalidValue] = useState(!1), [rangeDecorationState, setRangeDecorationsState] = useState([]);
7776
+ spellCheck
7777
+ } = _a, restProps = __objRest(_a, [
7778
+ "hotkeys",
7779
+ "onBlur",
7780
+ "onFocus",
7781
+ "onBeforeInput",
7782
+ "onPaste",
7783
+ "onCopy",
7784
+ "onClick",
7785
+ "rangeDecorations",
7786
+ "renderAnnotation",
7787
+ "renderBlock",
7788
+ "renderChild",
7789
+ "renderDecorator",
7790
+ "renderListItem",
7791
+ "renderPlaceholder",
7792
+ "renderStyle",
7793
+ "selection",
7794
+ "scrollSelectionIntoView",
7795
+ "spellCheck"
7796
+ ]), portableTextEditor = usePortableTextEditor(), ref = useRef(null), [editableElement, setEditableElement] = useState(null), [hasInvalidValue, setHasInvalidValue] = useState(!1), [rangeDecorationState, setRangeDecorationsState] = useState([]);
7462
7797
  useImperativeHandle(forwardedRef, () => ref.current);
7463
7798
  const rangeDecorationsRef = useRef(rangeDecorations), editorActor = useContext(EditorActorContext), readOnly = useSelector(editorActor, (s) => s.context.readOnly), schemaTypes = useSelector(editorActor, (s_0) => s_0.context.schema), slateEditor = useSlate(), blockTypeName = schemaTypes.block.name;
7464
7799
  useMemo(() => {
@@ -7468,9 +7803,9 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
7468
7803
  const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
7469
7804
  return debug("Editable is in edit mode"), withInsertData(withHotKeys(slateEditor));
7470
7805
  }, [editorActor, hotkeys, portableTextEditor, readOnly, schemaTypes, slateEditor]);
7471
- const renderElement = useCallback((eProps) => /* @__PURE__ */ jsx(Element, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, schemaTypes, spellCheck }), [schemaTypes, spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = useCallback((lProps) => {
7806
+ const renderElement = useCallback((eProps) => /* @__PURE__ */ jsx(Element, __spreadProps(__spreadValues2({}, eProps), { readOnly, renderBlock, renderChild, renderListItem, renderStyle, schemaTypes, spellCheck })), [schemaTypes, spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = useCallback((lProps) => {
7472
7807
  if (lProps.leaf._type === "span") {
7473
- let rendered = /* @__PURE__ */ jsx(Leaf, { ...lProps, editorActor, schemaTypes, renderAnnotation, renderChild, renderDecorator, readOnly });
7808
+ let rendered = /* @__PURE__ */ jsx(Leaf, __spreadProps(__spreadValues2({}, lProps), { editorActor, schemaTypes, renderAnnotation, renderChild, renderDecorator, readOnly }));
7474
7809
  if (renderPlaceholder && lProps.leaf.placeholder && lProps.text.text === "")
7475
7810
  return /* @__PURE__ */ jsxs(Fragment, { children: [
7476
7811
  /* @__PURE__ */ jsx("span", { style: PLACEHOLDER_STYLE, contentEditable: !1, children: renderPlaceholder() }),
@@ -7517,10 +7852,9 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
7517
7852
  origin: "local"
7518
7853
  });
7519
7854
  }
7520
- newRange !== null && newSlateRanges.push({
7521
- ...newRange || slateRange_0,
7855
+ newRange !== null && newSlateRanges.push(__spreadProps(__spreadValues2({}, newRange || slateRange_0), {
7522
7856
  rangeDecoration: rangeDecorationItem
7523
- });
7857
+ }));
7524
7858
  }), newSlateRanges.length > 0) {
7525
7859
  setRangeDecorationsState(newSlateRanges);
7526
7860
  return;
@@ -7562,7 +7896,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
7562
7896
  nativeEvent: event
7563
7897
  });
7564
7898
  }, [onCopy, editorActor, slateEditor]), handlePaste = useCallback((event_0) => {
7565
- const value_0 = PortableTextEditor.getValue(portableTextEditor), path = toPortableTextRange(value_0, slateEditor.selection, schemaTypes)?.focus.path || [], onPasteResult = onPaste?.({
7899
+ const value_0 = PortableTextEditor.getValue(portableTextEditor), ptRange = toPortableTextRange(value_0, slateEditor.selection, schemaTypes), path = (ptRange == null ? void 0 : ptRange.focus.path) || [], onPasteResult = onPaste == null ? void 0 : onPaste({
7566
7900
  event: event_0,
7567
7901
  value: value_0,
7568
7902
  path,
@@ -7627,8 +7961,8 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
7627
7961
  const existingDOMRange = domSelection.getRangeAt(0);
7628
7962
  try {
7629
7963
  const newDOMRange = ReactEditor.toDOMRange(slateEditor, slateEditor.selection);
7630
- (newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug("DOM range out of sync, validating selection"), domSelection?.removeAllRanges(), domSelection.addRange(newDOMRange));
7631
- } catch {
7964
+ (newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug("DOM range out of sync, validating selection"), domSelection == null || domSelection.removeAllRanges(), domSelection.addRange(newDOMRange));
7965
+ } catch (e) {
7632
7966
  debug("Could not resolve selection, selecting top document"), Transforms.deselect(slateEditor), slateEditor.children.length > 0 && Transforms.select(slateEditor, [0, 0]), slateEditor.onChange();
7633
7967
  }
7634
7968
  }, [ref, slateEditor]);
@@ -7716,8 +8050,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
7716
8050
  ref.current = ReactEditor.toDOMNode(slateEditor, slateEditor), setEditableElement(ref.current);
7717
8051
  }, [slateEditor, ref]), portableTextEditor ? hasInvalidValue ? null : /* @__PURE__ */ jsx(
7718
8052
  Editable,
7719
- {
7720
- ...restProps,
8053
+ __spreadProps(__spreadValues2({}, restProps), {
7721
8054
  autoFocus: !1,
7722
8055
  className: restProps.className || "pt-editable",
7723
8056
  decorate,
@@ -7734,7 +8067,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
7734
8067
  renderElement,
7735
8068
  renderLeaf,
7736
8069
  scrollSelectionIntoView: scrollSelectionIntoViewToSlate
7737
- }
8070
+ })
7738
8071
  ) : null;
7739
8072
  });
7740
8073
  PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";