@portabletext/editor 1.52.0 → 1.52.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.cjs CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$h = require("debug"), slateDom = require("slate-dom"), selectionPoint = require("./_chunks-cjs/selection-point.cjs"), util_isEqualSelectionPoints = require("./_chunks-cjs/util.is-equal-selection-points.cjs"), util_selectionPointToBlockOffset = require("./_chunks-cjs/util.selection-point-to-block-offset.cjs"), isEqual = require("lodash/isEqual.js"), types = require("@sanity/types"), selector_isSelectionExpanded = require("./_chunks-cjs/selector.is-selection-expanded.cjs"), selector_isSelectingEntireBlocks = require("./_chunks-cjs/selector.is-selecting-entire-blocks.cjs"), getRandomValues = require("get-random-values-esm"), behaviors_index = require("./behaviors/index.cjs"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), xstate = require("xstate"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), flatten = require("lodash/flatten.js"), omit = require("lodash/omit.js"), util_childSelectionPointToBlockOffset = require("./_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), patches = require("@portabletext/patches"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), immer = require("immer"), startCase = require("lodash.startcase"), isPlainObject = require("lodash/isPlainObject.js");
3
+ var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$g = require("debug"), slateDom = require("slate-dom"), selectionPoint = require("./_chunks-cjs/selection-point.cjs"), util_isEqualSelectionPoints = require("./_chunks-cjs/util.is-equal-selection-points.cjs"), util_selectionPointToBlockOffset = require("./_chunks-cjs/util.selection-point-to-block-offset.cjs"), isEqual = require("lodash/isEqual.js"), types = require("@sanity/types"), selector_isSelectionExpanded = require("./_chunks-cjs/selector.is-selection-expanded.cjs"), selector_isSelectingEntireBlocks = require("./_chunks-cjs/selector.is-selecting-entire-blocks.cjs"), getRandomValues = require("get-random-values-esm"), behaviors_index = require("./behaviors/index.cjs"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), xstate = require("xstate"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), flatten = require("lodash/flatten.js"), omit = require("lodash/omit.js"), util_childSelectionPointToBlockOffset = require("./_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), patches = require("@portabletext/patches"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), immer = require("immer"), startCase = require("lodash.startcase"), isPlainObject = require("lodash/isPlainObject.js");
4
4
  function _interopDefaultCompat(e) {
5
5
  return e && typeof e == "object" && "default" in e ? e : { default: e };
6
6
  }
7
- var React__default = /* @__PURE__ */ _interopDefaultCompat(React), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$h), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), omit__default = /* @__PURE__ */ _interopDefaultCompat(omit), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject);
7
+ var React__default = /* @__PURE__ */ _interopDefaultCompat(React), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$g), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), omit__default = /* @__PURE__ */ _interopDefaultCompat(omit), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject);
8
8
  function EditorEventListener(props) {
9
9
  const $ = reactCompilerRuntime.c(5), editor = useEditor.useEditor(), on = useEffectEvent.useEffectEvent(props.on);
10
10
  let t0;
@@ -984,93 +984,49 @@ function RenderTextBlock(props) {
984
984
  ] });
985
985
  }
986
986
  function RenderElement(props) {
987
- const $ = reactCompilerRuntime.c(45), editorActor = React.useContext(EditorActorContext), schema2 = react.useSelector(editorActor, _temp$1);
987
+ const $ = reactCompilerRuntime.c(43), editorActor = React.useContext(EditorActorContext), schema2 = react.useSelector(editorActor, _temp$1);
988
988
  if ("__inline" in props.element && props.element.__inline === !0) {
989
989
  let t02;
990
- if ($[0] !== props.element || $[1] !== schema2) {
991
- let t13;
992
- $[3] !== props.element ? (t13 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[3] = props.element, $[4] = t13) : t13 = $[4], t02 = selectionPoint.parseInlineObject({
993
- context: {
994
- keyGenerator: _temp2,
995
- schema: schema2
996
- },
997
- options: {
998
- refreshKeys: !1,
999
- validateFields: !1
1000
- },
1001
- inlineObject: {
1002
- _key: props.element._key,
1003
- _type: props.element._type,
1004
- ...t13
1005
- }
1006
- }), $[0] = props.element, $[1] = schema2, $[2] = t02;
1007
- } else
1008
- t02 = $[2];
1009
- const inlineObject = t02;
1010
- inlineObject || console.error(`Unable to find Inline Object "${props.element._type}" in Schema`);
990
+ $[0] !== props.element ? (t02 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[0] = props.element, $[1] = t02) : t02 = $[1];
1011
991
  let t12;
1012
- $[5] !== inlineObject || $[6] !== props.element._key || $[7] !== props.element._type ? (t12 = inlineObject ?? {
992
+ $[2] !== props.element._key || $[3] !== props.element._type || $[4] !== t02 ? (t12 = {
1013
993
  _key: props.element._key,
1014
- _type: props.element._type
1015
- }, $[5] = inlineObject, $[6] = props.element._key, $[7] = props.element._type, $[8] = t12) : t12 = $[8];
994
+ _type: props.element._type,
995
+ ...t02
996
+ }, $[2] = props.element._key, $[3] = props.element._type, $[4] = t02, $[5] = t12) : t12 = $[5];
997
+ const inlineObject = t12;
998
+ schema2.inlineObjects.find((inlineObject_0) => inlineObject_0.name === props.element._type) || console.error(`Unable to find Inline Object "${props.element._type}" in Schema`);
1016
999
  let t22;
1017
- return $[9] !== props.attributes || $[10] !== props.children || $[11] !== props.element || $[12] !== props.readOnly || $[13] !== props.renderChild || $[14] !== t12 ? (t22 = /* @__PURE__ */ jsxRuntime.jsx(RenderInlineObject, { attributes: props.attributes, element: props.element, inlineObject: t12, readOnly: props.readOnly, renderChild: props.renderChild, children: props.children }), $[9] = props.attributes, $[10] = props.children, $[11] = props.element, $[12] = props.readOnly, $[13] = props.renderChild, $[14] = t12, $[15] = t22) : t22 = $[15], t22;
1000
+ $[6] !== inlineObject || $[7] !== props.element._key || $[8] !== props.element._type ? (t22 = inlineObject ?? {
1001
+ _key: props.element._key,
1002
+ _type: props.element._type
1003
+ }, $[6] = inlineObject, $[7] = props.element._key, $[8] = props.element._type, $[9] = t22) : t22 = $[9];
1004
+ let t32;
1005
+ return $[10] !== props.attributes || $[11] !== props.children || $[12] !== props.element || $[13] !== props.readOnly || $[14] !== props.renderChild || $[15] !== t22 ? (t32 = /* @__PURE__ */ jsxRuntime.jsx(RenderInlineObject, { attributes: props.attributes, element: props.element, inlineObject: t22, readOnly: props.readOnly, renderChild: props.renderChild, children: props.children }), $[10] = props.attributes, $[11] = props.children, $[12] = props.element, $[13] = props.readOnly, $[14] = props.renderChild, $[15] = t22, $[16] = t32) : t32 = $[16], t32;
1018
1006
  }
1019
- let t0;
1020
- $[16] !== props.element || $[17] !== schema2 ? (t0 = selectionPoint.parseTextBlock({
1021
- context: {
1022
- keyGenerator: _temp3,
1023
- schema: schema2
1024
- },
1025
- options: {
1026
- refreshKeys: !1,
1027
- validateFields: !1
1028
- },
1029
- block: props.element
1030
- }), $[16] = props.element, $[17] = schema2, $[18] = t0) : t0 = $[18];
1031
- const textBlock = t0;
1032
- if (textBlock) {
1033
- let t12;
1034
- return $[19] !== props.attributes || $[20] !== props.children || $[21] !== props.element || $[22] !== props.readOnly || $[23] !== props.renderBlock || $[24] !== props.renderListItem || $[25] !== props.renderStyle || $[26] !== props.spellCheck || $[27] !== textBlock ? (t12 = /* @__PURE__ */ jsxRuntime.jsx(RenderTextBlock, { attributes: props.attributes, element: props.element, readOnly: props.readOnly, renderBlock: props.renderBlock, renderListItem: props.renderListItem, renderStyle: props.renderStyle, spellCheck: props.spellCheck, textBlock, children: props.children }), $[19] = props.attributes, $[20] = props.children, $[21] = props.element, $[22] = props.readOnly, $[23] = props.renderBlock, $[24] = props.renderListItem, $[25] = props.renderStyle, $[26] = props.spellCheck, $[27] = textBlock, $[28] = t12) : t12 = $[28], t12;
1007
+ if (selectionPoint.isTextBlock({
1008
+ schema: schema2
1009
+ }, props.element)) {
1010
+ let t02;
1011
+ return $[17] !== props.attributes || $[18] !== props.children || $[19] !== props.element || $[20] !== props.readOnly || $[21] !== props.renderBlock || $[22] !== props.renderListItem || $[23] !== props.renderStyle || $[24] !== props.spellCheck ? (t02 = /* @__PURE__ */ jsxRuntime.jsx(RenderTextBlock, { attributes: props.attributes, element: props.element, readOnly: props.readOnly, renderBlock: props.renderBlock, renderListItem: props.renderListItem, renderStyle: props.renderStyle, spellCheck: props.spellCheck, textBlock: props.element, children: props.children }), $[17] = props.attributes, $[18] = props.children, $[19] = props.element, $[20] = props.readOnly, $[21] = props.renderBlock, $[22] = props.renderListItem, $[23] = props.renderStyle, $[24] = props.spellCheck, $[25] = t02) : t02 = $[25], t02;
1035
1012
  }
1013
+ let t0;
1014
+ $[26] !== props.element ? (t0 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[26] = props.element, $[27] = t0) : t0 = $[27];
1036
1015
  let t1;
1037
- if ($[29] !== props.element || $[30] !== schema2) {
1038
- let t22;
1039
- $[32] !== props.element ? (t22 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[32] = props.element, $[33] = t22) : t22 = $[33], t1 = selectionPoint.parseBlockObject({
1040
- context: {
1041
- keyGenerator: _temp4,
1042
- schema: schema2
1043
- },
1044
- options: {
1045
- refreshKeys: !1,
1046
- validateFields: !1
1047
- },
1048
- blockObject: {
1049
- _key: props.element._key,
1050
- _type: props.element._type,
1051
- ...t22
1052
- }
1053
- }), $[29] = props.element, $[30] = schema2, $[31] = t1;
1054
- } else
1055
- t1 = $[31];
1016
+ $[28] !== props.element._key || $[29] !== props.element._type || $[30] !== t0 ? (t1 = {
1017
+ _key: props.element._key,
1018
+ _type: props.element._type,
1019
+ ...t0
1020
+ }, $[28] = props.element._key, $[29] = props.element._type, $[30] = t0, $[31] = t1) : t1 = $[31];
1056
1021
  const blockObject = t1;
1057
- blockObject || console.error(`Unable to find Block Object "${props.element._type}" in Schema`);
1022
+ schema2.blockObjects.find((blockObject_0) => blockObject_0.name === props.element._type) || console.error(`Unable to find Block Object "${props.element._type}" in Schema`);
1058
1023
  let t2;
1059
- $[34] !== blockObject || $[35] !== props.element._key || $[36] !== props.element._type ? (t2 = blockObject ?? {
1024
+ $[32] !== blockObject || $[33] !== props.element._key || $[34] !== props.element._type ? (t2 = blockObject ?? {
1060
1025
  _key: props.element._key,
1061
1026
  _type: props.element._type
1062
- }, $[34] = blockObject, $[35] = props.element._key, $[36] = props.element._type, $[37] = t2) : t2 = $[37];
1027
+ }, $[32] = blockObject, $[33] = props.element._key, $[34] = props.element._type, $[35] = t2) : t2 = $[35];
1063
1028
  let t3;
1064
- return $[38] !== props.attributes || $[39] !== props.children || $[40] !== props.element || $[41] !== props.readOnly || $[42] !== props.renderBlock || $[43] !== t2 ? (t3 = /* @__PURE__ */ jsxRuntime.jsx(RenderBlockObject, { attributes: props.attributes, blockObject: t2, element: props.element, readOnly: props.readOnly, renderBlock: props.renderBlock, children: props.children }), $[38] = props.attributes, $[39] = props.children, $[40] = props.element, $[41] = props.readOnly, $[42] = props.renderBlock, $[43] = t2, $[44] = t3) : t3 = $[44], t3;
1065
- }
1066
- function _temp4() {
1067
- return "";
1068
- }
1069
- function _temp3() {
1070
- return "";
1071
- }
1072
- function _temp2() {
1073
- return "";
1029
+ return $[36] !== props.attributes || $[37] !== props.children || $[38] !== props.element || $[39] !== props.readOnly || $[40] !== props.renderBlock || $[41] !== t2 ? (t3 = /* @__PURE__ */ jsxRuntime.jsx(RenderBlockObject, { attributes: props.attributes, blockObject: t2, element: props.element, readOnly: props.readOnly, renderBlock: props.renderBlock, children: props.children }), $[36] = props.attributes, $[37] = props.children, $[38] = props.element, $[39] = props.readOnly, $[40] = props.renderBlock, $[41] = t2, $[42] = t3) : t3 = $[42], t3;
1074
1030
  }
1075
1031
  function _temp$1(s) {
1076
1032
  return s.context.schema;
@@ -1527,7 +1483,7 @@ function getEditorSnapshot({
1527
1483
  }
1528
1484
  };
1529
1485
  }
1530
- const debug$g = debugWithName("plugin:withPortableTextMarkModel");
1486
+ const debug$f = debugWithName("plugin:withPortableTextMarkModel");
1531
1487
  function createWithPortableTextMarkModel(editorActor) {
1532
1488
  return function(editor) {
1533
1489
  const {
@@ -1541,7 +1497,7 @@ function createWithPortableTextMarkModel(editorActor) {
1541
1497
  for (const [child, childPath] of children) {
1542
1498
  const nextNode = node.children[childPath[1] + 1];
1543
1499
  if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
1544
- debug$g("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
1500
+ debug$f("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
1545
1501
  type: "normalizing"
1546
1502
  }), slate.Transforms.mergeNodes(editor, {
1547
1503
  at: [childPath[0], childPath[1] + 1],
@@ -1554,7 +1510,7 @@ function createWithPortableTextMarkModel(editorActor) {
1554
1510
  }
1555
1511
  }
1556
1512
  if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
1557
- debug$g("Adding .markDefs to block node"), editorActor.send({
1513
+ debug$f("Adding .markDefs to block node"), editorActor.send({
1558
1514
  type: "normalizing"
1559
1515
  }), slate.Transforms.setNodes(editor, {
1560
1516
  markDefs: []
@@ -1566,7 +1522,7 @@ function createWithPortableTextMarkModel(editorActor) {
1566
1522
  return;
1567
1523
  }
1568
1524
  if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
1569
- debug$g("Adding .marks to span node"), editorActor.send({
1525
+ debug$f("Adding .marks to span node"), editorActor.send({
1570
1526
  type: "normalizing"
1571
1527
  }), slate.Transforms.setNodes(editor, {
1572
1528
  marks: []
@@ -1580,7 +1536,7 @@ function createWithPortableTextMarkModel(editorActor) {
1580
1536
  if (editor.isTextSpan(node)) {
1581
1537
  const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath), decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
1582
1538
  if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
1583
- debug$g("Removing annotations from empty span node"), editorActor.send({
1539
+ debug$f("Removing annotations from empty span node"), editorActor.send({
1584
1540
  type: "normalizing"
1585
1541
  }), slate.Transforms.setNodes(editor, {
1586
1542
  marks: node.marks?.filter((mark) => decorators2.includes(mark))
@@ -1598,7 +1554,7 @@ function createWithPortableTextMarkModel(editorActor) {
1598
1554
  if (editor.isTextSpan(child)) {
1599
1555
  const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
1600
1556
  if (orphanedAnnotations.length > 0) {
1601
- debug$g("Removing orphaned annotations from span node"), editorActor.send({
1557
+ debug$f("Removing orphaned annotations from span node"), editorActor.send({
1602
1558
  type: "normalizing"
1603
1559
  }), slate.Transforms.setNodes(editor, {
1604
1560
  marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
@@ -1616,7 +1572,7 @@ function createWithPortableTextMarkModel(editorActor) {
1616
1572
  if (editor.isTextBlock(block)) {
1617
1573
  const decorators2 = editorActor.getSnapshot().context.schema.decorators.map((decorator) => decorator.name), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
1618
1574
  if (orphanedAnnotations.length > 0) {
1619
- debug$g("Removing orphaned annotations from span node"), editorActor.send({
1575
+ debug$f("Removing orphaned annotations from span node"), editorActor.send({
1620
1576
  type: "normalizing"
1621
1577
  }), slate.Transforms.setNodes(editor, {
1622
1578
  marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
@@ -1634,7 +1590,7 @@ function createWithPortableTextMarkModel(editorActor) {
1634
1590
  for (const markDef of markDefs)
1635
1591
  markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
1636
1592
  if (markDefs.length !== newMarkDefs.length) {
1637
- debug$g("Removing duplicate markDefs"), editorActor.send({
1593
+ debug$f("Removing duplicate markDefs"), editorActor.send({
1638
1594
  type: "normalizing"
1639
1595
  }), slate.Transforms.setNodes(editor, {
1640
1596
  markDefs: newMarkDefs
@@ -1649,7 +1605,7 @@ function createWithPortableTextMarkModel(editorActor) {
1649
1605
  if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
1650
1606
  const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => slate.Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
1651
1607
  if (node.markDefs && !isEqual__default.default(newMarkDefs, node.markDefs)) {
1652
- debug$g("Removing markDef not in use"), editorActor.send({
1608
+ debug$f("Removing markDef not in use"), editorActor.send({
1653
1609
  type: "normalizing"
1654
1610
  }), slate.Transforms.setNodes(editor, {
1655
1611
  markDefs: newMarkDefs
@@ -1802,7 +1758,7 @@ function createWithPortableTextMarkModel(editorActor) {
1802
1758
  const [targetBlock, targetPath] = slate.Editor.node(editor, [op.path[0] - 1]);
1803
1759
  if (editor.isTextBlock(targetBlock)) {
1804
1760
  const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq__default.default([...oldDefs, ...op.properties.markDefs]);
1805
- debug$g("Copying markDefs over to merged block", op), slate.Transforms.setNodes(editor, {
1761
+ debug$f("Copying markDefs over to merged block", op), slate.Transforms.setNodes(editor, {
1806
1762
  markDefs: newMarkDefs
1807
1763
  }, {
1808
1764
  at: targetPath,
@@ -2512,7 +2468,7 @@ function withUndoStep(editor, fn) {
2512
2468
  function getCurrentUndoStepId(editor) {
2513
2469
  return CURRENT_UNDO_STEP.get(editor)?.undoStepId;
2514
2470
  }
2515
- const debug$f = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
2471
+ const debug$e = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
2516
2472
  const state = SAVING.get(editor);
2517
2473
  return state === void 0 ? !0 : state;
2518
2474
  }, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
@@ -2525,7 +2481,7 @@ function createWithUndoRedo(options) {
2525
2481
  const remotePatches = getRemotePatches(editor);
2526
2482
  let previousUndoStepId = getCurrentUndoStepId(editor);
2527
2483
  options.subscriptions.push(() => {
2528
- debug$f("Subscribing to patches");
2484
+ debug$e("Subscribing to patches");
2529
2485
  const sub = editorActor.on("patches", ({
2530
2486
  patches: patches2,
2531
2487
  snapshot
@@ -2534,7 +2490,7 @@ function createWithUndoRedo(options) {
2534
2490
  patches2.forEach((patch) => {
2535
2491
  if (!reset && patch.origin !== "local" && remotePatches) {
2536
2492
  if (patch.type === "unset" && patch.path.length === 0) {
2537
- debug$f("Someone else cleared the content, resetting undo/redo history"), editor.history = {
2493
+ debug$e("Someone else cleared the content, resetting undo/redo history"), editor.history = {
2538
2494
  undos: [],
2539
2495
  redos: []
2540
2496
  }, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
@@ -2550,7 +2506,7 @@ function createWithUndoRedo(options) {
2550
2506
  }), previousSnapshot = snapshot;
2551
2507
  });
2552
2508
  return () => {
2553
- debug$f("Unsubscribing to patches"), sub.unsubscribe();
2509
+ debug$e("Unsubscribing to patches"), sub.unsubscribe();
2554
2510
  };
2555
2511
  }), editor.history = {
2556
2512
  undos: [],
@@ -2589,7 +2545,7 @@ function createWithUndoRedo(options) {
2589
2545
  operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
2590
2546
  timestamp: /* @__PURE__ */ new Date()
2591
2547
  };
2592
- undos.push(newStep), debug$f("Created new undo step", step);
2548
+ undos.push(newStep), debug$e("Created new undo step", step);
2593
2549
  }
2594
2550
  for (; undos.length > UNDO_STEP_LIMIT; )
2595
2551
  undos.shift();
@@ -2607,7 +2563,7 @@ const historyUndoOperationImplementation = ({
2607
2563
  } = editor.history, remotePatches = getRemotePatches(editor);
2608
2564
  if (undos.length > 0) {
2609
2565
  const step = undos[undos.length - 1];
2610
- if (debug$f("Undoing", step), step.operations.length > 0) {
2566
+ if (debug$e("Undoing", step), step.operations.length > 0) {
2611
2567
  const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
2612
2568
  let transformedOperations = step.operations;
2613
2569
  otherPatches.forEach((item) => {
@@ -2625,7 +2581,7 @@ const historyUndoOperationImplementation = ({
2625
2581
  });
2626
2582
  });
2627
2583
  } catch (err) {
2628
- debug$f("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
2584
+ debug$e("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
2629
2585
  undos: [],
2630
2586
  redos: []
2631
2587
  }, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
@@ -2642,7 +2598,7 @@ const historyUndoOperationImplementation = ({
2642
2598
  } = editor.history, remotePatches = getRemotePatches(editor);
2643
2599
  if (redos.length > 0) {
2644
2600
  const step = redos[redos.length - 1];
2645
- if (debug$f("Redoing", step), step.operations.length > 0) {
2601
+ if (debug$e("Redoing", step), step.operations.length > 0) {
2646
2602
  const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
2647
2603
  let transformedOperations = step.operations;
2648
2604
  otherPatches.forEach((item) => {
@@ -2659,7 +2615,7 @@ const historyUndoOperationImplementation = ({
2659
2615
  });
2660
2616
  });
2661
2617
  } catch (err) {
2662
- debug$f("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
2618
+ debug$e("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), slate.Transforms.deselect(editor), editor.history = {
2663
2619
  undos: [],
2664
2620
  redos: []
2665
2621
  }, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
@@ -2677,16 +2633,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
2677
2633
  const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual__default.default({
2678
2634
  _key: blk._key
2679
2635
  }, patch.path[0]));
2680
- return debug$f(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
2636
+ return debug$e(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
2681
2637
  }
2682
2638
  if (patch.type === "unset" && patch.path.length === 1) {
2683
2639
  const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual__default.default({
2684
2640
  _key: blk._key
2685
2641
  }, patch.path[0]));
2686
- return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$f("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
2642
+ return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$e("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
2687
2643
  }
2688
2644
  if (patch.type === "unset" && patch.path.length === 0)
2689
- return debug$f(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
2645
+ return debug$e(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
2690
2646
  if (patch.type === "diffMatchPatch") {
2691
2647
  const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
2692
2648
  return !operationTargetBlock || !isEqual__default.default({
@@ -3136,6 +3092,7 @@ const addAnnotationOperationImplementation = ({
3136
3092
  };
3137
3093
  }
3138
3094
  }, deleteOperationImplementation = ({
3095
+ context,
3139
3096
  operation
3140
3097
  }) => {
3141
3098
  const anchorBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(operation.at.anchor), focusBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(operation.at.focus), anchorBlockPath = anchorBlockKey !== void 0 ? getBlockPath({
@@ -3148,7 +3105,7 @@ const addAnnotationOperationImplementation = ({
3148
3105
  if (operation.at.anchor.path.length === 1 && operation.at.focus.path.length === 1 && anchorBlockPath && focusBlockPath && anchorBlockPath[0] === focusBlockPath[0]) {
3149
3106
  slate.Transforms.removeNodes(operation.editor, {
3150
3107
  at: [anchorBlockPath[0]]
3151
- });
3108
+ }), operation.editor.children.length === 0 && slate.Transforms.insertNodes(operation.editor, createPlaceholderBlock(context));
3152
3109
  return;
3153
3110
  }
3154
3111
  const range = toSlateRange(operation.at, operation.editor);
@@ -4451,7 +4408,7 @@ function withoutPatching(editor, fn) {
4451
4408
  function isPatching(editor) {
4452
4409
  return PATCHING.get(editor);
4453
4410
  }
4454
- const debug$e = debugWithName("plugin:withPatches");
4411
+ const debug$d = debugWithName("plugin:withPatches");
4455
4412
  function createWithPatches({
4456
4413
  editorActor,
4457
4414
  relayActor,
@@ -4476,7 +4433,7 @@ function createWithPatches({
4476
4433
  withoutPatching(editor, () => {
4477
4434
  withoutSaving(editor, () => {
4478
4435
  for (const patch of patches2) {
4479
- debug$e.enabled && debug$e(`Handling remote patch ${JSON.stringify(patch)}`);
4436
+ debug$d.enabled && debug$d(`Handling remote patch ${JSON.stringify(patch)}`);
4480
4437
  try {
4481
4438
  changed = applyPatch(editor, patch);
4482
4439
  } catch (error) {
@@ -4494,10 +4451,10 @@ function createWithPatches({
4494
4451
  remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
4495
4452
  };
4496
4453
  return subscriptions.push(() => {
4497
- debug$e("Subscribing to remote patches");
4454
+ debug$d("Subscribing to remote patches");
4498
4455
  const sub = editorActor.on("patches", handlePatches);
4499
4456
  return () => {
4500
- debug$e("Unsubscribing to remote patches"), sub.unsubscribe();
4457
+ debug$d("Unsubscribing to remote patches"), sub.unsubscribe();
4501
4458
  };
4502
4459
  }), editor.apply = (operation) => {
4503
4460
  let patches$1 = [];
@@ -4551,7 +4508,7 @@ function createWithPatches({
4551
4508
  }, editor;
4552
4509
  };
4553
4510
  }
4554
- const debug$d = debugWithName("plugin:withPlaceholderBlock");
4511
+ const debug$c = debugWithName("plugin:withPlaceholderBlock");
4555
4512
  function createWithPlaceholderBlock(editorActor) {
4556
4513
  return function(editor) {
4557
4514
  const {
@@ -4576,7 +4533,7 @@ function createWithPlaceholderBlock(editorActor) {
4576
4533
  const node = op.node;
4577
4534
  if (op.path[0] === 0 && slate.Editor.isVoid(editor, node)) {
4578
4535
  const nextPath = slate.Path.next(op.path);
4579
- editor.children[nextPath[0]] || (debug$d("Adding placeholder block"), slate.Editor.insertNode(editor, editor.pteCreateTextBlock({
4536
+ editor.children[nextPath[0]] || (debug$c("Adding placeholder block"), slate.Editor.insertNode(editor, editor.pteCreateTextBlock({
4580
4537
  decorators: []
4581
4538
  })));
4582
4539
  }
@@ -4585,36 +4542,6 @@ function createWithPlaceholderBlock(editorActor) {
4585
4542
  }, editor;
4586
4543
  };
4587
4544
  }
4588
- const debug$c = debugWithName("plugin:withPortableTextBlockStyle");
4589
- function createWithPortableTextBlockStyle(editorActor) {
4590
- const defaultStyle = editorActor.getSnapshot().context.schema.styles[0].name;
4591
- return function(editor) {
4592
- const {
4593
- normalizeNode
4594
- } = editor;
4595
- return editor.normalizeNode = (nodeEntry) => {
4596
- const [, path] = nodeEntry;
4597
- for (const op of editor.operations)
4598
- if (op.type === "split_node" && op.path.length === 1 && editor.isTextBlock(op.properties) && op.properties.style !== defaultStyle && op.path[0] === path[0] && !slate.Path.equals(path, op.path)) {
4599
- const [child] = slate.Editor.node(editor, [op.path[0] + 1, 0]);
4600
- if (slate.Text.isText(child) && child.text === "") {
4601
- debug$c(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
4602
- type: "normalizing"
4603
- }), slate.Transforms.setNodes(editor, {
4604
- style: defaultStyle
4605
- }, {
4606
- at: [op.path[0] + 1],
4607
- voids: !1
4608
- }), editorActor.send({
4609
- type: "done normalizing"
4610
- });
4611
- return;
4612
- }
4613
- }
4614
- normalizeNode(nodeEntry);
4615
- }, editor;
4616
- };
4617
- }
4618
4545
  debugWithName("plugin:withPortableTextSelections");
4619
4546
  function createWithPortableTextSelections(editorActor) {
4620
4547
  let prevSelection = null;
@@ -4654,7 +4581,7 @@ function createWithSchemaTypes({
4654
4581
  editorActor
4655
4582
  }) {
4656
4583
  return function(editor) {
4657
- editor.isTextBlock = (value) => selectionPoint.isTextBlock(editorActor.getSnapshot().context, value), editor.isTextSpan = (value) => selectionPoint.isSpan$1(editorActor.getSnapshot().context, value), editor.isListBlock = (value) => selectionPoint.isListBlock(editorActor.getSnapshot().context, value), editor.isVoid = (element) => editorActor.getSnapshot().context.schema.block.name !== element._type && (editorActor.getSnapshot().context.schema.blockObjects.map((obj) => obj.name).includes(element._type) || editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type)), editor.isInline = (element) => editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type) && "__inline" in element && element.__inline === !0;
4584
+ editor.isTextBlock = (value) => slate.Editor.isEditor(value) ? !1 : selectionPoint.isTextBlock(editorActor.getSnapshot().context, value), editor.isTextSpan = (value) => slate.Editor.isEditor(value) ? !1 : selectionPoint.isSpan$1(editorActor.getSnapshot().context, value), editor.isListBlock = (value) => slate.Editor.isEditor(value) ? !1 : selectionPoint.isListBlock(editorActor.getSnapshot().context, value), editor.isVoid = (element) => slate.Editor.isEditor(element) ? !1 : editorActor.getSnapshot().context.schema.block.name !== element._type && (editorActor.getSnapshot().context.schema.blockObjects.map((obj) => obj.name).includes(element._type) || editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type)), editor.isInline = (element) => slate.Editor.isEditor(element) ? !1 : editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type) && "__inline" in element && element.__inline === !0;
4658
4585
  const {
4659
4586
  normalizeNode
4660
4587
  } = editor;
@@ -5107,10 +5034,10 @@ const withPlugins = (editor, options) => {
5107
5034
  }), withMaxBlocks = createWithMaxBlocks(editorActor), withUndoRedo = createWithUndoRedo({
5108
5035
  editorActor,
5109
5036
  subscriptions: options.subscriptions
5110
- }), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPortableTextBlockStyle = createWithPortableTextBlockStyle(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor), withUtils = createWithUtils({
5037
+ }), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor), withUtils = createWithUtils({
5111
5038
  editorActor
5112
5039
  }), withPortableTextSelections = createWithPortableTextSelections(editorActor);
5113
- return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(pluginUpdateValue(editorActor.getSnapshot().context, pluginUpdateMarkState(editorActor.getSnapshot().context, e)))))))))))));
5040
+ return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(pluginUpdateValue(editorActor.getSnapshot().context, pluginUpdateMarkState(editorActor.getSnapshot().context, e))))))))))));
5114
5041
  }, debug$a = debugWithName("setup");
5115
5042
  function createSlateEditor(config) {
5116
5043
  debug$a("Creating new Slate editor instance");