@portabletext/editor 2.3.6 → 2.3.7

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
@@ -1416,21 +1416,6 @@ const insertTextOperationImplementation = ({
1416
1416
  marks: [...activeDecorators, ...activeAnnotations]
1417
1417
  }), EDITOR_TO_PENDING_SELECTION.set(operation.editor, operation.editor.selection), operation.editor.decoratorState = {};
1418
1418
  };
1419
- function isPortableTextSpan(node) {
1420
- return node._type === "span" && "text" in node && typeof node.text == "string" && (typeof node.marks > "u" || Array.isArray(node.marks) && node.marks.every((mark) => typeof mark == "string"));
1421
- }
1422
- function isPortableTextBlock(node) {
1423
- return (
1424
- // A block doesn't _have_ to be named 'block' - to differentiate between
1425
- // allowed child types and marks, one might name them differently
1426
- typeof node._type == "string" && // Toolkit-types like nested spans are @-prefixed
1427
- node._type[0] !== "@" && // `markDefs` isn't _required_ per say, but if it's there, it needs to be an array
1428
- (!("markDefs" in node) || !node.markDefs || Array.isArray(node.markDefs) && // Every mark definition needs to have an `_key` to be mappable in child spans
1429
- node.markDefs.every((def) => typeof def._key == "string")) && // `children` is required and needs to be an array
1430
- "children" in node && Array.isArray(node.children) && // All children are objects with `_type` (usually spans, but can contain other stuff)
1431
- node.children.every((child) => typeof child == "object" && "_type" in child)
1432
- );
1433
- }
1434
1419
  function getPreviousSpan({
1435
1420
  editor,
1436
1421
  blockPath,
@@ -1703,7 +1688,7 @@ function createWithPortableTextMarkModel(editorActor) {
1703
1688
  blockPath,
1704
1689
  spanPath: [op.path[0], op.path[1] - 1]
1705
1690
  }), nextSpanAnnotations = nextSpan ? nextSpan.marks?.filter((mark) => !decorators.includes(mark)) : [], annotationsEnding = previousSpanAnnotations?.filter((annotation) => !nextSpanAnnotations?.includes(annotation)) ?? [], atTheEndOfAnnotation = annotationsEnding.length > 0;
1706
- if (atTheEndOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.some((mark) => annotationsEnding.includes(mark))) {
1691
+ if (atTheEndOfAnnotation && isSpan(editorActor.getSnapshot().context, op.node) && op.node.marks?.some((mark) => annotationsEnding.includes(mark))) {
1707
1692
  Transforms.insertNodes(editor, {
1708
1693
  ...op.node,
1709
1694
  _key: editorActor.getSnapshot().context.keyGenerator(),
@@ -1712,7 +1697,7 @@ function createWithPortableTextMarkModel(editorActor) {
1712
1697
  return;
1713
1698
  }
1714
1699
  const annotationsStarting = nextSpanAnnotations?.filter((annotation) => !previousSpanAnnotations?.includes(annotation)) ?? [], atTheStartOfAnnotation = annotationsStarting.length > 0;
1715
- if (atTheStartOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.some((mark) => annotationsStarting.includes(mark))) {
1700
+ if (atTheStartOfAnnotation && isSpan(editorActor.getSnapshot().context, op.node) && op.node.marks?.some((mark) => annotationsStarting.includes(mark))) {
1716
1701
  Transforms.insertNodes(editor, {
1717
1702
  ...op.node,
1718
1703
  _key: editorActor.getSnapshot().context.keyGenerator(),
@@ -1721,7 +1706,7 @@ function createWithPortableTextMarkModel(editorActor) {
1721
1706
  return;
1722
1707
  }
1723
1708
  const nextSpanDecorators = nextSpan?.marks?.filter((mark) => decorators.includes(mark)) ?? [];
1724
- if (nextSpanDecorators.length > 0 && atTheEndOfAnnotation && !atTheStartOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.length === 0) {
1709
+ if (nextSpanDecorators.length > 0 && atTheEndOfAnnotation && !atTheStartOfAnnotation && isSpan(editorActor.getSnapshot().context, op.node) && op.node.marks?.length === 0) {
1725
1710
  Transforms.insertNodes(editor, {
1726
1711
  ...op.node,
1727
1712
  _key: editorActor.getSnapshot().context.keyGenerator(),
@@ -1768,7 +1753,7 @@ function createWithPortableTextMarkModel(editorActor) {
1768
1753
  match: (n) => editor.isTextSpan(n),
1769
1754
  voids: !1
1770
1755
  }))[0] ?? [void 0, void 0];
1771
- if (span && block && isPortableTextBlock(block)) {
1756
+ if (span && block && isTextBlock(editorActor.getSnapshot().context, block)) {
1772
1757
  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({
1773
1758
  editor,
1774
1759
  blockPath,