@portabletext/editor 1.0.12 → 1.0.13

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
@@ -714,7 +714,6 @@ function compileType(rawType) {
714
714
  }).get(rawType.name);
715
715
  }
716
716
  const debug$k = debugWithName("operationToPatches");
717
- debug$k.enabled = !1;
718
717
  function createOperationToPatches(types) {
719
718
  const textBlockName = types.block.name;
720
719
  function insertTextPatch(editor, operation, beforeValue) {
@@ -2745,7 +2744,7 @@ function isPortableTextBlock(node) {
2745
2744
  );
2746
2745
  }
2747
2746
  const debug$c = debugWithName("plugin:withPortableTextMarkModel");
2748
- function createWithPortableTextMarkModel(types, change$) {
2747
+ function createWithPortableTextMarkModel(types, change$, keyGenerator) {
2749
2748
  return function(editor) {
2750
2749
  const { apply: apply2, normalizeNode } = editor, decorators = types.decorators.map((t) => t.value), forceNewSelection = () => {
2751
2750
  editor.selection && (Transforms.select(editor, { ...editor.selection }), editor.selection = { ...editor.selection });
@@ -2835,18 +2834,15 @@ function createWithPortableTextMarkModel(types, change$) {
2835
2834
  })
2836
2835
  )[0] || [void 0];
2837
2836
  if (Text.isText(node) && node.text.length === selection.focus.offset && Array.isArray(node.marks) && node.marks.length > 0) {
2838
- apply2(op), Transforms.splitNodes(editor, {
2839
- match: Text.isText,
2840
- at: { ...selection.focus, offset: selection.focus.offset }
2841
- });
2842
2837
  const marksWithoutAnnotationMarks = ({
2843
2838
  ...Editor.marks(editor) || {}
2844
2839
  }.marks || []).filter((mark) => decorators.includes(mark));
2845
- Transforms.setNodes(
2846
- editor,
2847
- { marks: marksWithoutAnnotationMarks },
2848
- { at: Path.next(selection.focus.path) }
2849
- ), debug$c("Inserting text at end of annotation");
2840
+ Transforms.insertNodes(editor, {
2841
+ _type: "span",
2842
+ _key: keyGenerator(),
2843
+ text: op.text,
2844
+ marks: marksWithoutAnnotationMarks
2845
+ }), debug$c("Inserting text at end of annotation");
2850
2846
  return;
2851
2847
  }
2852
2848
  }
@@ -2965,18 +2961,22 @@ function createWithPortableTextMarkModel(types, change$) {
2965
2961
  };
2966
2962
  function mergeSpans(editor) {
2967
2963
  const { selection } = editor;
2968
- if (selection)
2969
- for (const [node, path] of Array.from(
2964
+ if (selection) {
2965
+ const textNodesInSelection = Array.from(
2970
2966
  Editor.nodes(editor, {
2971
- at: Editor.range(editor, [selection.anchor.path[0]], [selection.focus.path[0]])
2967
+ at: Editor.range(editor, [selection.anchor.path[0]], [selection.focus.path[0]]),
2968
+ match: Text.isText,
2969
+ reverse: !0
2972
2970
  })
2973
- ).reverse()) {
2971
+ );
2972
+ for (const [node, path] of textNodesInSelection) {
2974
2973
  const [parent] = path.length > 1 ? Editor.node(editor, Path.parent(path)) : [void 0], nextPath = [path[0], path[1] + 1];
2975
2974
  if (editor.isTextBlock(parent)) {
2976
2975
  const nextNode = parent.children[nextPath[1]];
2977
- Text.isText(node) && Text.isText(nextNode) && isEqual(nextNode.marks, node.marks) && (debug$c("Merging spans"), Transforms.mergeNodes(editor, { at: nextPath, voids: !0 }), editor.onChange());
2976
+ Text.isText(nextNode) && isEqual(nextNode.marks, node.marks) && (debug$c("Merging spans"), Transforms.mergeNodes(editor, { at: nextPath, voids: !0 }), editor.onChange());
2978
2977
  }
2979
2978
  }
2979
+ }
2980
2980
  }
2981
2981
  }
2982
2982
  const debug$b = debugWithName("plugin:withPortableTextSelections"), debugVerbose$2 = debug$b.enabled && !1;
@@ -3657,7 +3657,11 @@ const originalFnMap = /* @__PURE__ */ new WeakMap(), withPlugins = (editor, opti
3657
3657
  readOnly,
3658
3658
  patches$,
3659
3659
  blockSchemaType: schemaTypes.block
3660
- }), withPortableTextMarkModel = createWithPortableTextMarkModel(schemaTypes, change$), withPortableTextBlockStyle = createWithPortableTextBlockStyle(schemaTypes), withPlaceholderBlock = createWithPlaceholderBlock(), withInsertBreak = createWithInsertBreak(schemaTypes), withUtils = createWithUtils({ keyGenerator, schemaTypes, portableTextEditor }), withPortableTextSelections = createWithPortableTextSelections(change$, schemaTypes);
3660
+ }), withPortableTextMarkModel = createWithPortableTextMarkModel(
3661
+ schemaTypes,
3662
+ change$,
3663
+ keyGenerator
3664
+ ), withPortableTextBlockStyle = createWithPortableTextBlockStyle(schemaTypes), withPlaceholderBlock = createWithPlaceholderBlock(), withInsertBreak = createWithInsertBreak(schemaTypes), withUtils = createWithUtils({ keyGenerator, schemaTypes, portableTextEditor }), withPortableTextSelections = createWithPortableTextSelections(change$, schemaTypes);
3661
3665
  return e.destroy = () => {
3662
3666
  const originalFunctions = originalFnMap.get(e);
3663
3667
  if (!originalFunctions)