@portabletext/editor 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -2441,7 +2441,6 @@ function toInt(num) {
2441
2441
  }
2442
2442
  const debug$i = debugWithName("applyPatches"), debugVerbose$4 = debug$i.enabled && !0;
2443
2443
  function createApplyPatch(schemaTypes) {
2444
- let previousPatch;
2445
2444
  return (editor, patch) => {
2446
2445
  let changed = !1;
2447
2446
  debugVerbose$4 && (debug$i(
@@ -2455,7 +2454,7 @@ NEW PATCH =============================================================`
2455
2454
  changed = insertPatch(editor, patch, schemaTypes);
2456
2455
  break;
2457
2456
  case "unset":
2458
- changed = unsetPatch(editor, patch, previousPatch);
2457
+ changed = unsetPatch(editor, patch);
2459
2458
  break;
2460
2459
  case "set":
2461
2460
  changed = setPatch(editor, patch);
@@ -2469,7 +2468,7 @@ NEW PATCH =============================================================`
2469
2468
  } catch (err) {
2470
2469
  console.error(err);
2471
2470
  }
2472
- return previousPatch = patch, changed;
2471
+ return changed;
2473
2472
  };
2474
2473
  }
2475
2474
  function diffMatchPatch(editor, patch) {
@@ -2584,11 +2583,11 @@ function setPatch(editor, patch) {
2584
2583
  }
2585
2584
  return debugState(editor, "after"), !0;
2586
2585
  }
2587
- function unsetPatch(editor, patch, previousPatch) {
2586
+ function unsetPatch(editor, patch) {
2588
2587
  if (patch.path.length === 0) {
2589
2588
  debug$i("Removing everything"), debugState(editor, "before");
2590
2589
  const previousSelection = editor.selection;
2591
- return slate.Transforms.deselect(editor), editor.children.forEach((c, i) => {
2590
+ return slate.Transforms.deselect(editor), editor.children.forEach((_child, i) => {
2592
2591
  slate.Transforms.removeNodes(editor, { at: [i] });
2593
2592
  }), slate.Transforms.insertNodes(editor, editor.pteCreateTextBlock({ decorators: [] })), previousSelection && slate.Transforms.select(editor, {
2594
2593
  anchor: { path: [0, 0], offset: 0 },
@@ -3354,27 +3353,24 @@ function createWithPortableTextMarkModel(editorActor, types2, keyGenerator) {
3354
3353
  return;
3355
3354
  }
3356
3355
  if (op.type === "insert_text") {
3357
- const { selection } = editor;
3358
- if (selection && slate.Range.isCollapsed(selection) && slate.Editor.marks(editor)?.marks?.some(
3359
- (mark) => !decorators.includes(mark)
3360
- )) {
3361
- const [node] = Array.from(
3356
+ const { selection } = editor, collapsedSelection = selection ? slate.Range.isCollapsed(selection) : !1;
3357
+ if (selection && collapsedSelection) {
3358
+ const [span] = Array.from(
3362
3359
  slate.Editor.nodes(editor, {
3363
3360
  mode: "lowest",
3364
3361
  at: selection.focus,
3365
- match: (n) => n._type === types2.span.name,
3362
+ match: (n) => editor.isTextSpan(n),
3366
3363
  voids: !1
3367
3364
  })
3368
- )[0] || [void 0];
3369
- if (slate.Text.isText(node) && node.text.length === selection.focus.offset && Array.isArray(node.marks) && node.marks.length > 0) {
3370
- const marksWithoutAnnotationMarks = ({
3371
- ...slate.Editor.marks(editor) || {}
3372
- }.marks || []).filter((mark) => decorators.includes(mark));
3365
+ )[0], marks = span.marks ?? [], marksWithoutAnnotations = marks.filter(
3366
+ (mark) => decorators.includes(mark)
3367
+ );
3368
+ if (marks.length > marksWithoutAnnotations.length && (selection.anchor.offset === 0 || span.text.length === selection.focus.offset)) {
3373
3369
  slate.Transforms.insertNodes(editor, {
3374
3370
  _type: "span",
3375
3371
  _key: keyGenerator(),
3376
3372
  text: op.text,
3377
- marks: marksWithoutAnnotationMarks
3373
+ marks: marksWithoutAnnotations
3378
3374
  }), debug$c("Inserting text at end of annotation");
3379
3375
  return;
3380
3376
  }
@@ -4964,7 +4960,7 @@ class PortableTextEditor extends react.Component {
4964
4960
  static insertBlock = (editor, type, value) => editor.editable?.insertBlock(type, value);
4965
4961
  static insertBreak = (editor) => editor.editable?.insertBreak();
4966
4962
  static isVoid = (editor, element) => editor.editable?.isVoid(element);
4967
- static isObjectPath = (editor, path) => {
4963
+ static isObjectPath = (_editor, path) => {
4968
4964
  if (!path || !Array.isArray(path)) return !1;
4969
4965
  const isChildObjectEditPath = path.length > 3 && path[1] === "children";
4970
4966
  return path.length > 1 && path[1] !== "children" || isChildObjectEditPath;
@@ -5465,7 +5461,7 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
5465
5461
  [props, slateEditor]
5466
5462
  ), scrollSelectionIntoViewToSlate = react.useMemo(() => {
5467
5463
  if (scrollSelectionIntoView !== void 0)
5468
- return scrollSelectionIntoView === null ? noop__default.default : (editor, domRange) => {
5464
+ return scrollSelectionIntoView === null ? noop__default.default : (_editor, domRange) => {
5469
5465
  scrollSelectionIntoView(portableTextEditor, domRange);
5470
5466
  };
5471
5467
  }, [portableTextEditor, scrollSelectionIntoView]), decorate = react.useCallback(