@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.mjs CHANGED
@@ -2458,7 +2458,6 @@ function toInt(num) {
2458
2458
  }
2459
2459
  const debug$i = debugWithName("applyPatches"), debugVerbose$4 = debug$i.enabled && !0;
2460
2460
  function createApplyPatch(schemaTypes) {
2461
- let previousPatch;
2462
2461
  return (editor, patch) => {
2463
2462
  let changed = !1;
2464
2463
  debugVerbose$4 && (debug$i(
@@ -2472,7 +2471,7 @@ NEW PATCH =============================================================`
2472
2471
  changed = insertPatch(editor, patch, schemaTypes);
2473
2472
  break;
2474
2473
  case "unset":
2475
- changed = unsetPatch(editor, patch, previousPatch);
2474
+ changed = unsetPatch(editor, patch);
2476
2475
  break;
2477
2476
  case "set":
2478
2477
  changed = setPatch(editor, patch);
@@ -2486,7 +2485,7 @@ NEW PATCH =============================================================`
2486
2485
  } catch (err) {
2487
2486
  console.error(err);
2488
2487
  }
2489
- return previousPatch = patch, changed;
2488
+ return changed;
2490
2489
  };
2491
2490
  }
2492
2491
  function diffMatchPatch(editor, patch) {
@@ -2601,11 +2600,11 @@ function setPatch(editor, patch) {
2601
2600
  }
2602
2601
  return debugState(editor, "after"), !0;
2603
2602
  }
2604
- function unsetPatch(editor, patch, previousPatch) {
2603
+ function unsetPatch(editor, patch) {
2605
2604
  if (patch.path.length === 0) {
2606
2605
  debug$i("Removing everything"), debugState(editor, "before");
2607
2606
  const previousSelection = editor.selection;
2608
- return Transforms.deselect(editor), editor.children.forEach((c, i) => {
2607
+ return Transforms.deselect(editor), editor.children.forEach((_child, i) => {
2609
2608
  Transforms.removeNodes(editor, { at: [i] });
2610
2609
  }), Transforms.insertNodes(editor, editor.pteCreateTextBlock({ decorators: [] })), previousSelection && Transforms.select(editor, {
2611
2610
  anchor: { path: [0, 0], offset: 0 },
@@ -3371,27 +3370,24 @@ function createWithPortableTextMarkModel(editorActor, types, keyGenerator) {
3371
3370
  return;
3372
3371
  }
3373
3372
  if (op.type === "insert_text") {
3374
- const { selection } = editor;
3375
- if (selection && Range.isCollapsed(selection) && Editor.marks(editor)?.marks?.some(
3376
- (mark) => !decorators.includes(mark)
3377
- )) {
3378
- const [node] = Array.from(
3373
+ const { selection } = editor, collapsedSelection = selection ? Range.isCollapsed(selection) : !1;
3374
+ if (selection && collapsedSelection) {
3375
+ const [span] = Array.from(
3379
3376
  Editor.nodes(editor, {
3380
3377
  mode: "lowest",
3381
3378
  at: selection.focus,
3382
- match: (n) => n._type === types.span.name,
3379
+ match: (n) => editor.isTextSpan(n),
3383
3380
  voids: !1
3384
3381
  })
3385
- )[0] || [void 0];
3386
- if (Text.isText(node) && node.text.length === selection.focus.offset && Array.isArray(node.marks) && node.marks.length > 0) {
3387
- const marksWithoutAnnotationMarks = ({
3388
- ...Editor.marks(editor) || {}
3389
- }.marks || []).filter((mark) => decorators.includes(mark));
3382
+ )[0], marks = span.marks ?? [], marksWithoutAnnotations = marks.filter(
3383
+ (mark) => decorators.includes(mark)
3384
+ );
3385
+ if (marks.length > marksWithoutAnnotations.length && (selection.anchor.offset === 0 || span.text.length === selection.focus.offset)) {
3390
3386
  Transforms.insertNodes(editor, {
3391
3387
  _type: "span",
3392
3388
  _key: keyGenerator(),
3393
3389
  text: op.text,
3394
- marks: marksWithoutAnnotationMarks
3390
+ marks: marksWithoutAnnotations
3395
3391
  }), debug$c("Inserting text at end of annotation");
3396
3392
  return;
3397
3393
  }
@@ -4981,7 +4977,7 @@ class PortableTextEditor extends Component {
4981
4977
  static insertBlock = (editor, type, value) => editor.editable?.insertBlock(type, value);
4982
4978
  static insertBreak = (editor) => editor.editable?.insertBreak();
4983
4979
  static isVoid = (editor, element) => editor.editable?.isVoid(element);
4984
- static isObjectPath = (editor, path) => {
4980
+ static isObjectPath = (_editor, path) => {
4985
4981
  if (!path || !Array.isArray(path)) return !1;
4986
4982
  const isChildObjectEditPath = path.length > 3 && path[1] === "children";
4987
4983
  return path.length > 1 && path[1] !== "children" || isChildObjectEditPath;
@@ -5482,7 +5478,7 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
5482
5478
  [props, slateEditor]
5483
5479
  ), scrollSelectionIntoViewToSlate = useMemo(() => {
5484
5480
  if (scrollSelectionIntoView !== void 0)
5485
- return scrollSelectionIntoView === null ? noop : (editor, domRange) => {
5481
+ return scrollSelectionIntoView === null ? noop : (_editor, domRange) => {
5486
5482
  scrollSelectionIntoView(portableTextEditor, domRange);
5487
5483
  };
5488
5484
  }, [portableTextEditor, scrollSelectionIntoView]), decorate = useCallback(