@portabletext/editor 7.0.5 → 7.1.0

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.
@@ -1,6 +1,6 @@
1
- import { resolveContainerAt, isInline, isSpanNode, getEnclosingBlock, hasNode, getBlock, getNodes, parentPath, getPathSubSchema, isTextBlockNode, getSibling } from "./get-path-sub-schema.js";
2
- import { isKeyedSegment, getNode, isObjectNode, getNodeChildren, getChildren } from "./get-node.js";
3
- import { isEqualPaths, getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint as getSelectionEndPoint$1, sliceBlocks, getBlockStartPoint, getBlockEndPoint, isEqualSelectionPoints, isSelectionCollapsed as isSelectionCollapsed$1, blockOffsetToSpanSelectionPoint, getAncestorTextBlock, spanSelectionPointToBlockOffset, isListBlock } from "./util.slice-blocks.js";
1
+ import { isInline, isSpanNode, isObject, getEnclosingBlock, resolveContainerAt, hasNode, getBlock, getNodes, getSibling, getPathSubSchema, isTextBlockNode, isEditableContainer } from "./get-path-sub-schema.js";
2
+ import { isKeyedSegment, getNode, getNodeChildren, getParent, getChildren, parentPath } from "./get-parent.js";
3
+ import { isEqualPaths, getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint as getSelectionEndPoint$1, sliceBlocks, getBlockStartPoint, getBlockEndPoint, isEqualSelectionPoints, isSelectionCollapsed as isSelectionCollapsed$1, blockOffsetToSpanSelectionPoint, spanSelectionPointToBlockOffset, isListBlock } from "./util.slice-blocks.js";
4
4
  import { isSpan, isTextBlock } from "@portabletext/schema";
5
5
  function comparePaths(path, another, root) {
6
6
  const min = Math.min(path.length, another.length);
@@ -69,12 +69,6 @@ function rangeEdges(range, root) {
69
69
  } = range;
70
70
  return isBackwardRange(range, root) ? [focus, anchor] : [anchor, focus];
71
71
  }
72
- function isEditableContainer(snapshot, _node, path) {
73
- if (snapshot.context.containers.size === 0)
74
- return !1;
75
- const resolved = resolveContainerAt(snapshot.context.containers, snapshot.context.value, path);
76
- return !!(resolved && "field" in resolved);
77
- }
78
72
  function rangesOverlap(rangeA, rangeB, root) {
79
73
  const [startA, endA] = rangeEdges(rangeA, root), [startB, endB] = rangeEdges(rangeB, root);
80
74
  return comparePoints(startA, endB, root) <= 0 && comparePoints(startB, endA, root) <= 0;
@@ -82,11 +76,9 @@ function rangesOverlap(rangeA, rangeB, root) {
82
76
  const isSelectionCollapsed = (snapshot) => snapshot.context.selection ? isEqualPaths(snapshot.context.selection.anchor.path, snapshot.context.selection.focus.path) && snapshot.context.selection.anchor.offset === snapshot.context.selection.focus.offset : !1;
83
77
  function getInline(snapshot, path) {
84
78
  const entry = getNode(snapshot, path);
85
- if (!(!entry || !isInline(snapshot, path)) && !(!isSpanNode({
79
+ if (!(!entry || !isInline(snapshot, entry.path)) && !(!isSpanNode({
86
80
  schema: snapshot.context.schema
87
- }, entry.node) && !isObjectNode({
88
- schema: snapshot.context.schema
89
- }, entry.node)))
81
+ }, entry.node) && !isObject(snapshot, entry.node)))
90
82
  return {
91
83
  node: entry.node,
92
84
  path: entry.path
@@ -383,29 +375,26 @@ function isRecord(value) {
383
375
  function isSelectionExpanded(selection) {
384
376
  return selection ? !isSelectionCollapsed$1(selection) : !1;
385
377
  }
386
- function findSibling(snapshot, path, direction, match) {
387
- if (path.length === 0)
388
- return;
389
- const lastSegment = path.at(-1);
390
- if (!isKeyedSegment(lastSegment))
391
- return;
392
- const parent = parentPath(path), children = getChildren(snapshot, parent), currentIndex = children.findIndex((child) => child.node._key === lastSegment._key);
393
- return currentIndex === -1 ? void 0 : (direction === "next" ? children.slice(currentIndex + 1) : children.slice(0, currentIndex).reverse()).find(match);
394
- }
395
378
  const getSelectionEndPoint = (snapshot) => {
396
379
  if (snapshot.context.selection)
397
380
  return snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus;
398
381
  }, getNextSpan = (snapshot) => {
399
382
  const point = getSelectionEndPoint(snapshot);
400
383
  if (point)
401
- return findSibling(snapshot, point.path, "next", (entry) => isSpan(snapshot.context, entry.node));
384
+ return getSibling(snapshot, point.path, {
385
+ direction: "next",
386
+ match: (node) => isSpan(snapshot.context, node)
387
+ });
402
388
  }, getSelectionStartPoint = (snapshot) => {
403
389
  if (snapshot.context.selection)
404
390
  return snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor;
405
391
  }, getPreviousSpan = (snapshot) => {
406
392
  const point = getSelectionStartPoint(snapshot);
407
393
  if (point)
408
- return findSibling(snapshot, point.path, "previous", (entry) => isSpan(snapshot.context, entry.node));
394
+ return getSibling(snapshot, point.path, {
395
+ direction: "previous",
396
+ match: (node) => isSpan(snapshot.context, node)
397
+ });
409
398
  };
410
399
  function getSelectedChildren(options) {
411
400
  const filter = options?.filter;
@@ -491,7 +480,11 @@ const getSelectedSpans = (snapshot) => snapshot.context.selection ? getSelectedC
491
480
  selection
492
481
  }
493
482
  }).map((span) => {
494
- const block = getAncestorTextBlock(snapshot, span.path);
483
+ const block = getParent(snapshot, span.path, {
484
+ match: (node) => isTextBlock({
485
+ schema: snapshot.context.schema
486
+ }, node)
487
+ });
495
488
  return {
496
489
  marks: span.node.marks ?? [],
497
490
  decoratorNames: getPathSubSchema(snapshot, span.path).decorators.map((decorator) => decorator.name),
@@ -750,14 +743,16 @@ const getActiveAnnotations = (snapshot) => {
750
743
  return firstStyle;
751
744
  }, getNextInlineObject = (snapshot) => {
752
745
  const point = getSelectionEndPoint(snapshot);
753
- return point ? findSibling(snapshot, point.path, "next", (entry) => isObjectNode({
754
- schema: snapshot.context.schema
755
- }, entry.node)) : void 0;
746
+ return point ? getSibling(snapshot, point.path, {
747
+ direction: "next",
748
+ match: (node) => isObject(snapshot, node)
749
+ }) : void 0;
756
750
  }, getPreviousInlineObject = (snapshot) => {
757
751
  const point = getSelectionStartPoint(snapshot);
758
- return point ? findSibling(snapshot, point.path, "previous", (entry) => isObjectNode({
759
- schema: snapshot.context.schema
760
- }, entry.node)) : void 0;
752
+ return point ? getSibling(snapshot, point.path, {
753
+ direction: "previous",
754
+ match: (node) => isObject(snapshot, node)
755
+ }) : void 0;
761
756
  }, getSelectionText = (snapshot) => {
762
757
  const selectedValue = getSelectedValue(snapshot);
763
758
  return collectText(snapshot.context, selectedValue);
@@ -887,14 +882,18 @@ const getCaretWordSelection = (snapshot) => {
887
882
  const selectionEndBlock = getSelectionEndBlock(snapshot);
888
883
  if (!selectionEndBlock)
889
884
  return;
890
- const next = getSibling(snapshot, selectionEndBlock.path, "next");
885
+ const next = getSibling(snapshot, selectionEndBlock.path, {
886
+ direction: "next"
887
+ });
891
888
  if (next)
892
889
  return getBlock(snapshot, next.path);
893
890
  }, getPreviousBlock = (snapshot) => {
894
891
  const selectionStartBlock = getSelectionStartBlock(snapshot);
895
892
  if (!selectionStartBlock)
896
893
  return;
897
- const previous = getSibling(snapshot, selectionStartBlock.path, "previous");
894
+ const previous = getSibling(snapshot, selectionStartBlock.path, {
895
+ direction: "previous"
896
+ });
898
897
  if (previous)
899
898
  return getBlock(snapshot, previous.path);
900
899
  }, getSelectionEndChild = (snapshot) => {
@@ -1010,7 +1009,6 @@ export {
1010
1009
  isAtTheEndOfBlock,
1011
1010
  isAtTheStartOfBlock,
1012
1011
  isBackwardRange,
1013
- isEditableContainer,
1014
1012
  isOverlappingSelection,
1015
1013
  isSelectingEntireBlocks,
1016
1014
  isSelectionCollapsed,