@portabletext/editor 7.0.2 → 7.0.4

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,4 +1,7 @@
1
1
  import { isTextBlock } from "@portabletext/schema";
2
+ function isKeyedSegment(segment) {
3
+ return typeof segment == "object" && segment !== null && "_key" in segment;
4
+ }
2
5
  function isTypedObject(object) {
3
6
  return isRecord(object) && typeof object._type == "string";
4
7
  }
@@ -8,9 +11,6 @@ function isRecord(value) {
8
11
  function isObjectNode(context, node) {
9
12
  return isTypedObject(node) && node._type !== context.schema.block.name && node._type !== context.schema.span.name;
10
13
  }
11
- function isKeyedSegment(segment) {
12
- return typeof segment == "object" && segment !== null && "_key" in segment;
13
- }
14
14
  function getChildren(snapshot, path) {
15
15
  let currentChildren = snapshot.context.value, currentFieldName = "value", currentPath = [], isRoot = !0, currentParent;
16
16
  for (const segment of path) {
@@ -71,6 +71,57 @@ function resolveNodeContainer(containers, parent, node) {
71
71
  }
72
72
  return containers.get(node._type);
73
73
  }
74
+ function getAncestors(snapshot, path) {
75
+ const keyedIndices = [];
76
+ for (let i = 0; i < path.length; i++)
77
+ isKeyedSegment(path[i]) && keyedIndices.push(i);
78
+ if (keyedIndices.length <= 1)
79
+ return [];
80
+ const {
81
+ context,
82
+ blockIndexMap
83
+ } = snapshot;
84
+ let currentChildren = context.value, isRootLevel = !0, currentParent;
85
+ const ancestorsByDepth = [], resolvedPath = [], targetKeyedIndex = keyedIndices[keyedIndices.length - 1];
86
+ let segmentIndex = 0;
87
+ for (; segmentIndex < targetKeyedIndex; ) {
88
+ const segment = path[segmentIndex];
89
+ if (typeof segment == "string") {
90
+ resolvedPath.push(segment), segmentIndex++;
91
+ continue;
92
+ }
93
+ let node;
94
+ if (isKeyedSegment(segment)) {
95
+ if (isRootLevel && blockIndexMap.size === currentChildren.length) {
96
+ const index = blockIndexMap.get(segment._key);
97
+ node = index !== void 0 ? currentChildren[index] : currentChildren.find((child) => child._key === segment._key);
98
+ } else
99
+ node = currentChildren.find((child) => child._key === segment._key);
100
+ resolvedPath.push(segment), isRootLevel = !1;
101
+ } else if (typeof segment == "number")
102
+ node = currentChildren.at(segment), node && resolvedPath.push({
103
+ _key: node._key
104
+ });
105
+ else
106
+ return [];
107
+ if (!node)
108
+ return [];
109
+ const next = getNodeChildren(context, node, currentParent);
110
+ if (!next)
111
+ return [];
112
+ ancestorsByDepth.push({
113
+ node,
114
+ path: resolvedPath.slice()
115
+ }), currentChildren = next.children, currentParent = next.parent, segmentIndex++;
116
+ }
117
+ return ancestorsByDepth.reverse();
118
+ }
119
+ function getAncestor(snapshot, path, match) {
120
+ const ancestors = getAncestors(snapshot, path);
121
+ for (const ancestor of ancestors)
122
+ if (match(ancestor.node, ancestor.path))
123
+ return ancestor;
124
+ }
74
125
  function getNode(snapshot, path) {
75
126
  if (path.length === 0)
76
127
  return;
@@ -127,57 +178,6 @@ function getNode(snapshot, path) {
127
178
  path: resolvedPath
128
179
  };
129
180
  }
130
- function getAncestors(snapshot, path) {
131
- const keyedIndices = [];
132
- for (let i = 0; i < path.length; i++)
133
- isKeyedSegment(path[i]) && keyedIndices.push(i);
134
- if (keyedIndices.length <= 1)
135
- return [];
136
- const {
137
- context,
138
- blockIndexMap
139
- } = snapshot;
140
- let currentChildren = context.value, isRootLevel = !0, currentParent;
141
- const ancestorsByDepth = [], resolvedPath = [], targetKeyedIndex = keyedIndices[keyedIndices.length - 1];
142
- let segmentIndex = 0;
143
- for (; segmentIndex < targetKeyedIndex; ) {
144
- const segment = path[segmentIndex];
145
- if (typeof segment == "string") {
146
- resolvedPath.push(segment), segmentIndex++;
147
- continue;
148
- }
149
- let node;
150
- if (isKeyedSegment(segment)) {
151
- if (isRootLevel && blockIndexMap.size === currentChildren.length) {
152
- const index = blockIndexMap.get(segment._key);
153
- node = index !== void 0 ? currentChildren[index] : currentChildren.find((child) => child._key === segment._key);
154
- } else
155
- node = currentChildren.find((child) => child._key === segment._key);
156
- resolvedPath.push(segment), isRootLevel = !1;
157
- } else if (typeof segment == "number")
158
- node = currentChildren.at(segment), node && resolvedPath.push({
159
- _key: node._key
160
- });
161
- else
162
- return [];
163
- if (!node)
164
- return [];
165
- const next = getNodeChildren(context, node, currentParent);
166
- if (!next)
167
- return [];
168
- ancestorsByDepth.push({
169
- node,
170
- path: resolvedPath.slice()
171
- }), currentChildren = next.children, currentParent = next.parent, segmentIndex++;
172
- }
173
- return ancestorsByDepth.reverse();
174
- }
175
- function getAncestor(snapshot, path, match) {
176
- const ancestors = getAncestors(snapshot, path);
177
- for (const ancestor of ancestors)
178
- if (match(ancestor.node, ancestor.path))
179
- return ancestor;
180
- }
181
181
  export {
182
182
  getAncestor,
183
183
  getAncestors,
@@ -189,4 +189,4 @@ export {
189
189
  isRecord,
190
190
  isTypedObject
191
191
  };
192
- //# sourceMappingURL=get-ancestor.js.map
192
+ //# sourceMappingURL=get-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-node.js","sources":["../../src/utils/util.is-keyed-segment.ts","../../src/utils/asserters.ts","../../src/engine/node/is-object-node.ts","../../src/node-traversal/get-children.ts","../../src/node-traversal/get-ancestors.ts","../../src/node-traversal/get-ancestor.ts","../../src/node-traversal/get-node.ts"],"sourcesContent":["import type {KeyedSegment} from '../types/paths'\n\n/**\n * @public\n */\nexport function isKeyedSegment(segment: unknown): segment is KeyedSegment {\n return typeof segment === 'object' && segment !== null && '_key' in segment\n}\n","import type {TypedObject} from '@portabletext/schema'\n\nexport function isTypedObject(object: unknown): object is TypedObject {\n return isRecord(object) && typeof object['_type'] === 'string'\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && (typeof value === 'object' || typeof value === 'function')\n}\n","import type {PortableTextObject} from '@portabletext/schema'\nimport type {EditorSchema} from '../../editor/editor-schema'\nimport {isTypedObject} from '../../utils/asserters'\n\nexport function isObjectNode(\n context: {schema: EditorSchema},\n node: unknown,\n): node is PortableTextObject {\n return (\n isTypedObject(node) &&\n node._type !== context.schema.block.name &&\n node._type !== context.schema.span.name\n )\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {EditorSchema} from '../editor/editor-schema'\nimport type {Node} from '../engine/interfaces/node'\nimport type {Path} from '../engine/interfaces/path'\nimport {isObjectNode} from '../engine/node/is-object-node'\nimport type {\n Containers,\n RegisteredContainer,\n} from '../schema/resolve-containers'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Get the children of a node at a given path.\n *\n * @beta\n */\nexport function getChildren(\n snapshot: TraversalSnapshot,\n path: Path,\n): Array<{node: Node; path: Path}> {\n let currentChildren: Array<Node> = snapshot.context.value\n let currentFieldName = 'value'\n let currentPath: Path = []\n let isRoot = true\n let currentParent: RegisteredContainer | undefined\n\n for (const segment of path) {\n if (typeof segment === 'string') {\n continue\n }\n\n let node: Node | undefined\n if (isKeyedSegment(segment)) {\n node = currentChildren.find((child) => child._key === segment._key)\n } else if (typeof segment === 'number') {\n node = currentChildren.at(segment)\n }\n\n if (!node) {\n return []\n }\n\n currentPath = isRoot\n ? [{_key: node._key}]\n : [...currentPath, currentFieldName, {_key: node._key}]\n isRoot = false\n\n const next = getNodeChildren(snapshot.context, node, currentParent)\n\n if (!next) {\n return []\n }\n\n currentChildren = next.children\n currentFieldName = next.fieldName\n currentParent = next.parent\n }\n\n return currentChildren.map((child) => ({\n node: child,\n path: isRoot\n ? [{_key: child._key}]\n : [...currentPath, currentFieldName, {_key: child._key}],\n }))\n}\n\n/**\n * Resolve a node's editable child array.\n *\n * When `parent` is provided and its `of` declares a positional entry\n * matching `node._type`, that positional entry's `field` is used.\n * Otherwise the top-level `containers.get(node._type)` provides the\n * fallback.\n *\n * The returned `parent` is the resolved container entry for `node`\n * itself (used by the caller to thread further descent).\n *\n * @beta\n */\nexport function getNodeChildren(\n context: {\n schema: EditorSchema\n containers: Containers\n },\n node: Node | {value: Array<Node>},\n parent?: RegisteredContainer,\n):\n | {\n children: Array<Node>\n fieldName: string\n parent: RegisteredContainer | undefined\n }\n | undefined {\n // Text blocks store children in .children\n if (isTextBlock(context, node)) {\n return {\n children: node.children,\n fieldName: 'children',\n parent: undefined,\n }\n }\n\n if (isObjectNode(context, node)) {\n const resolved = resolveNodeContainer(context.containers, parent, node)\n\n if (!resolved) {\n return undefined\n }\n\n const fieldValue = (node as Record<string, unknown>)[resolved.field.name]\n\n if (!Array.isArray(fieldValue)) {\n return undefined\n }\n\n return {\n children: fieldValue as Array<Node>,\n fieldName: resolved.field.name,\n parent: resolved,\n }\n }\n\n // Root context: has .value array but no _key or _type\n if (\n 'value' in node &&\n Array.isArray(node['value']) &&\n !('_key' in node) &&\n !('_type' in node)\n ) {\n return {\n children: node['value'] as Array<Node>,\n fieldName: 'value',\n parent: undefined,\n }\n }\n\n return undefined\n}\n\n/**\n * Pick the positional override from `parent.of` if present; fall back\n * to the top-level entry. Returns only `RegisteredContainer` entries\n * since leaves do not have editable children.\n */\nfunction resolveNodeContainer(\n containers: Containers,\n parent: RegisteredContainer | undefined,\n node: Node,\n): RegisteredContainer | undefined {\n if (parent?.of) {\n for (const entry of parent.of) {\n if (entry.type === node._type) {\n // Only return container entries; leaves have no editable children.\n if ('field' in entry) {\n return entry\n }\n return undefined\n }\n }\n }\n return containers.get(node._type)\n}\n","import type {Node} from '../engine/interfaces/node'\nimport type {Path} from '../engine/interfaces/path'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {getNodeChildren} from './get-children'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Get all ancestors of the node at a given path, from nearest to furthest.\n *\n * For a path like [{_key:'t1'}, 'rows', {_key:'r1'}, 'cells', {_key:'c1'}],\n * the ancestors are (nearest first):\n * [{_key:'t1'}, 'rows', {_key:'r1'}]\n * [{_key:'t1'}]\n *\n * Walks from root to the target in a single pass collecting each ancestor\n * as it goes.\n *\n * @beta\n */\nexport function getAncestors(\n snapshot: TraversalSnapshot,\n path: Path,\n): Array<{node: Node; path: Path}> {\n // Collect keyed-segment indices to know where each ancestor's path ends.\n const keyedIndices: Array<number> = []\n for (let i = 0; i < path.length; i++) {\n if (isKeyedSegment(path[i])) {\n keyedIndices.push(i)\n }\n }\n\n // Need at least 2 keyed segments to have an ancestor (the last is self).\n if (keyedIndices.length <= 1) {\n return []\n }\n\n const {context, blockIndexMap} = snapshot\n let currentChildren: Array<Node> = context.value\n let isRootLevel = true\n let currentParent:\n | import('../schema/resolve-containers').RegisteredContainer\n | undefined\n\n const ancestorsByDepth: Array<{node: Node; path: Path}> = []\n const resolvedPath: Path = []\n\n // Descend once. We walk only as far as the second-to-last keyed segment;\n // the last keyed segment is the target itself, which is not an ancestor.\n const targetKeyedIndex = keyedIndices[keyedIndices.length - 1]!\n\n let segmentIndex = 0\n while (segmentIndex < targetKeyedIndex) {\n const segment = path[segmentIndex]!\n\n if (typeof segment === 'string') {\n resolvedPath.push(segment)\n segmentIndex++\n continue\n }\n\n let node: Node | undefined\n if (isKeyedSegment(segment)) {\n // Production snapshots maintain `blockIndexMap` in lockstep with\n // `context.value` so this fast path always fires. Some test\n // fixtures still pass empty or stale maps, which is the debt this\n // size check is working around - see /specs/snapshot-invariants.md.\n // When the fixtures are aligned, drop the guard and use the map\n // directly.\n if (isRootLevel && blockIndexMap.size === currentChildren.length) {\n const index = blockIndexMap.get(segment._key)\n node =\n index !== undefined\n ? currentChildren[index]\n : currentChildren.find((child) => child._key === segment._key)\n } else {\n node = currentChildren.find((child) => child._key === segment._key)\n }\n resolvedPath.push(segment)\n isRootLevel = false\n } else if (typeof segment === 'number') {\n node = currentChildren.at(segment)\n if (node) {\n resolvedPath.push({_key: node._key})\n }\n } else {\n return []\n }\n\n if (!node) {\n return []\n }\n\n // Descend with positional awareness. `getNodeChildren` checks the\n // current parent's `of` for a positional override before falling\n // back to the top-level `containers` map - so same-`_type`\n // registered under different parents with different `field`\n // resolves to the right entry at this position.\n const next = getNodeChildren(context, node, currentParent)\n if (!next) {\n return []\n }\n\n ancestorsByDepth.push({\n node,\n path: resolvedPath.slice(),\n })\n\n currentChildren = next.children\n currentParent = next.parent\n segmentIndex++\n }\n\n // Return nearest-first (reverse of document order at the call site).\n return ancestorsByDepth.reverse()\n}\n","import type {Node} from '../engine/interfaces/node'\nimport type {Path} from '../engine/interfaces/path'\nimport {getAncestors} from './get-ancestors'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Find the first ancestor of the node at a given path that matches a predicate.\n * Does not check the node at the path itself, only its ancestors.\n *\n * When `match` is a type predicate, the returned `node` narrows to that type.\n *\n * @beta\n */\nexport function getAncestor<TMatch extends Node>(\n snapshot: TraversalSnapshot,\n path: Path,\n match: (node: Node, path: Path) => node is TMatch,\n): {node: TMatch; path: Path} | undefined\n/**\n * @beta\n */\nexport function getAncestor(\n snapshot: TraversalSnapshot,\n path: Path,\n match: (node: Node, path: Path) => boolean,\n): {node: Node; path: Path} | undefined\nexport function getAncestor(\n snapshot: TraversalSnapshot,\n path: Path,\n match: (node: Node, path: Path) => boolean,\n): {node: Node; path: Path} | undefined {\n const ancestors = getAncestors(snapshot, path)\n\n for (const ancestor of ancestors) {\n if (match(ancestor.node, ancestor.path)) {\n return ancestor\n }\n }\n\n return undefined\n}\n","import type {Node} from '../engine/interfaces/node'\nimport type {Path} from '../engine/interfaces/path'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {getNodeChildren} from './get-children'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Get the node at a given path.\n *\n * The path can be either keyed (KeyedSegment + field name strings) or\n * indexed (numbers). Keyed segments are resolved by matching `_key`,\n * field name strings are skipped (they're structural), and numbers\n * are resolved by index.\n *\n * The returned path is always fully keyed, even if the input path\n * contained numeric indices.\n *\n * @beta\n */\nexport function getNode(\n snapshot: TraversalSnapshot,\n path: Path,\n): {node: Node; path: Path} | undefined {\n if (path.length === 0) {\n return undefined\n }\n\n const {context, blockIndexMap} = snapshot\n let currentChildren: Array<Node> = context.value\n let node: Node | undefined\n let currentParent:\n | import('../schema/resolve-containers').RegisteredContainer\n | undefined\n const resolvedPath: Path = []\n let isRootLevel = true\n\n for (let i = 0; i < path.length; i++) {\n const segment = path[i]\n\n if (typeof segment === 'string') {\n resolvedPath.push(segment)\n continue\n }\n\n if (isKeyedSegment(segment)) {\n if (isRootLevel && blockIndexMap.size === currentChildren.length) {\n const index = blockIndexMap.get(segment._key)\n if (index !== undefined) {\n const candidate = currentChildren[index]\n if (candidate && candidate._key === segment._key) {\n node = candidate\n } else {\n node = currentChildren.find((child) => child._key === segment._key)\n }\n } else {\n node = currentChildren.find((child) => child._key === segment._key)\n }\n } else {\n node = currentChildren.find((child) => child._key === segment._key)\n }\n resolvedPath.push(segment)\n isRootLevel = false\n } else if (typeof segment === 'number') {\n node = currentChildren.at(segment)\n if (node) {\n resolvedPath.push({_key: node._key})\n }\n } else {\n return undefined\n }\n\n if (!node) {\n return undefined\n }\n\n let hasMoreSegments = false\n for (let j = i + 1; j < path.length; j++) {\n const s = path[j]\n if (isKeyedSegment(s) || typeof s === 'number') {\n hasMoreSegments = true\n break\n }\n }\n\n if (hasMoreSegments) {\n const next = getNodeChildren(context, node, currentParent)\n\n if (!next) {\n return undefined\n }\n\n currentChildren = next.children\n currentParent = next.parent\n }\n }\n\n if (!node) {\n return undefined\n }\n\n return {node, path: resolvedPath}\n}\n"],"names":["isKeyedSegment","segment","isTypedObject","object","isRecord","value","isObjectNode","context","node","_type","schema","block","name","span","getChildren","snapshot","path","currentChildren","currentFieldName","currentPath","isRoot","currentParent","find","child","_key","at","next","getNodeChildren","children","fieldName","parent","map","isTextBlock","undefined","resolved","resolveNodeContainer","containers","fieldValue","field","Array","isArray","of","entry","type","get","getAncestors","keyedIndices","i","length","push","blockIndexMap","isRootLevel","ancestorsByDepth","resolvedPath","targetKeyedIndex","segmentIndex","size","index","slice","reverse","getAncestor","match","ancestors","ancestor","getNode","candidate","hasMoreSegments","j","s"],"mappings":";AAKO,SAASA,eAA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AKhD,OAAO,GACzBkD,cAAc;AAAA,IAChB,WAAW,OAAOlD,WAAY;AAC5BO,aAAOS,gBAAgBQ,GAAGxB,OAAO,GAC7BO,QACF6C,aAAaJ,KAAK;AAAA,QAACzB,MAAMhB,KAAKgB;AAAAA,MAAAA,CAAK;AAAA;AAGrC;AAGF,QAAI,CAAChB;AACH;AAGF,QAAI0D,kBAAkB;AACtB,aAASC,IAAIpB,IAAI,GAAGoB,IAAInD,KAAKgC,QAAQmB,KAAK;AACxC,YAAMC,IAAIpD,KAAKmD,CAAC;AAChB,UAAInE,eAAeoE,CAAC,KAAK,OAAOA,KAAM,UAAU;AAC9CF,0BAAkB;AAClB;AAAA,MACF;AAAA,IACF;AAEA,QAAIA,iBAAiB;AACnB,YAAMxC,OAAOC,gBAAgBpB,SAASC,MAAMa,aAAa;AAEzD,UAAI,CAACK;AACH;AAGFT,wBAAkBS,KAAKE,UACvBP,gBAAgBK,KAAKI;AAAAA,IACvB;AAAA,EACF;AAEA,MAAKtB;AAIL,WAAO;AAAA,MAACA;AAAAA,MAAMQ,MAAMqC;AAAAA,IAAAA;AACtB;"}
@@ -1,51 +1,11 @@
1
- import { isTypedObject, isKeyedSegment, getNode, getAncestors, getChildren, getNodeChildren, isObjectNode } from "./get-ancestor.js";
1
+ import { getNode, isTypedObject, isKeyedSegment, getChildren, getNodeChildren, getAncestors, isObjectNode } from "./get-node.js";
2
2
  import { getSubSchema } from "@portabletext/schema";
3
- function isSpanNode(context, node) {
4
- return isTypedObject(node) && node._type === context.schema.span.name;
3
+ function hasNode(snapshot, path) {
4
+ return getNode(snapshot, path) !== void 0;
5
5
  }
6
6
  function isTextBlockNode(context, node) {
7
7
  return isTypedObject(node) && node._type === context.schema.block.name;
8
8
  }
9
- function parentPath(path) {
10
- if (path.length === 0)
11
- throw new Error(`Cannot get the parent path of the root path [${path}].`);
12
- let lastNodeIndex = -1;
13
- for (let i = path.length - 1; i >= 0; i--)
14
- if (isKeyedSegment(path[i]) || typeof path[i] == "number") {
15
- lastNodeIndex = i;
16
- break;
17
- }
18
- if (lastNodeIndex === -1)
19
- return [];
20
- const result = path.slice(0, lastNodeIndex);
21
- return result.length > 0 && typeof result[result.length - 1] == "string" ? result.slice(0, -1) : result;
22
- }
23
- function getParent(snapshot, path) {
24
- if (path.length === 0)
25
- return;
26
- const parent = parentPath(path);
27
- if (parent.length !== 0)
28
- return getNode(snapshot, parent);
29
- }
30
- function isBlock(snapshot, path) {
31
- const parent = getParent(snapshot, path);
32
- return parent ? !isTextBlockNode({
33
- schema: snapshot.context.schema
34
- }, parent.node) : !0;
35
- }
36
- function getBlock(snapshot, path) {
37
- const entry = getNode(snapshot, path);
38
- if (entry && isBlock(snapshot, path) && !isSpanNode({
39
- schema: snapshot.context.schema
40
- }, entry.node))
41
- return {
42
- node: entry.node,
43
- path: entry.path
44
- };
45
- }
46
- function hasNode(snapshot, path) {
47
- return getNode(snapshot, path) !== void 0;
48
- }
49
9
  function resolveContainerAt(containers, value, path) {
50
10
  const keyedIndices = [];
51
11
  for (let index = 0; index < path.length; index++)
@@ -90,17 +50,6 @@ function resolveNodeEntry(containers, parent, node) {
90
50
  }
91
51
  return containers.get(node._type);
92
52
  }
93
- function getEnclosingBlock(snapshot, path) {
94
- const direct = getBlock(snapshot, path);
95
- if (direct)
96
- return direct;
97
- for (const ancestor of getAncestors(snapshot, path))
98
- if (isBlock(snapshot, ancestor.path)) {
99
- const block = getBlock(snapshot, ancestor.path);
100
- if (block)
101
- return block;
102
- }
103
- }
104
53
  function isAncestorPath(path, another) {
105
54
  if (path.length >= another.length)
106
55
  return !1;
@@ -204,6 +153,20 @@ function couldContainInRangeNodes(snapshot, nodePath, from, to) {
204
153
  function canStopTraversal(snapshot, nodePath, from, to, reverse) {
205
154
  return reverse ? from === void 0 ? !1 : comparePathsInTree(snapshot, nodePath, from) === -1 && !isAncestorPath(nodePath, from) : to === void 0 ? !1 : comparePathsInTree(snapshot, nodePath, to) === 1;
206
155
  }
156
+ function parentPath(path) {
157
+ if (path.length === 0)
158
+ throw new Error(`Cannot get the parent path of the root path [${path}].`);
159
+ let lastNodeIndex = -1;
160
+ for (let i = path.length - 1; i >= 0; i--)
161
+ if (isKeyedSegment(path[i]) || typeof path[i] == "number") {
162
+ lastNodeIndex = i;
163
+ break;
164
+ }
165
+ if (lastNodeIndex === -1)
166
+ return [];
167
+ const result = path.slice(0, lastNodeIndex);
168
+ return result.length > 0 && typeof result[result.length - 1] == "string" ? result.slice(0, -1) : result;
169
+ }
207
170
  function getSibling(snapshot, path, direction) {
208
171
  if (path.length === 0)
209
172
  return;
@@ -217,9 +180,46 @@ function getSibling(snapshot, path, direction) {
217
180
  if (!(siblingIndex < 0 || siblingIndex >= children.length))
218
181
  return children[siblingIndex];
219
182
  }
183
+ function isSpanNode(context, node) {
184
+ return isTypedObject(node) && node._type === context.schema.span.name;
185
+ }
186
+ function getParent(snapshot, path) {
187
+ if (path.length === 0)
188
+ return;
189
+ const parent = parentPath(path);
190
+ if (parent.length !== 0)
191
+ return getNode(snapshot, parent);
192
+ }
193
+ function isBlock(snapshot, path) {
194
+ const parent = getParent(snapshot, path);
195
+ return parent ? !isTextBlockNode({
196
+ schema: snapshot.context.schema
197
+ }, parent.node) : !0;
198
+ }
199
+ function getBlock(snapshot, path) {
200
+ const entry = getNode(snapshot, path);
201
+ if (entry && isBlock(snapshot, path) && !isSpanNode({
202
+ schema: snapshot.context.schema
203
+ }, entry.node))
204
+ return {
205
+ node: entry.node,
206
+ path: entry.path
207
+ };
208
+ }
220
209
  function isInline(snapshot, path) {
221
210
  return !isBlock(snapshot, path);
222
211
  }
212
+ function getEnclosingBlock(snapshot, path) {
213
+ const direct = getBlock(snapshot, path);
214
+ if (direct)
215
+ return direct;
216
+ for (const ancestor of getAncestors(snapshot, path))
217
+ if (isBlock(snapshot, ancestor.path)) {
218
+ const block = getBlock(snapshot, ancestor.path);
219
+ if (block)
220
+ return block;
221
+ }
222
+ }
223
223
  function descendToParent(snapshot, path) {
224
224
  const ancestors = getAncestors(snapshot, path);
225
225
  for (const ancestor of ancestors) {
@@ -1 +1 @@
1
- {"version":3,"file":"get-path-sub-schema.js","sources":["../../src/slate/node/is-span-node.ts","../../src/slate/node/is-text-block-node.ts","../../src/slate/path/parent-path.ts","../../src/node-traversal/get-parent.ts","../../src/node-traversal/is-block.ts","../../src/node-traversal/has-node.ts","../../src/schema/resolve-container-at.ts","../../src/node-traversal/get-enclosing-block.ts","../../src/slate/path/is-ancestor-path.ts","../../src/node-traversal/get-nodes.ts","../../src/node-traversal/get-sibling.ts","../../src/node-traversal/is-inline.ts","../../src/schema/descend-to-parent.ts","../../src/schema/get-enclosing-container.ts","../../src/traversal/get-path-sub-schema.ts"],"sourcesContent":["import type {EditorSchema} from '../../editor/editor-schema'\nimport {isTypedObject} from '../../utils/asserters'\n\nexport type SpanNode = {\n _type: string\n _key: string\n text?: string\n marks?: Array<string>\n}\n\n/**\n * Checks if a node is a span based on `_type` alone, without requiring `text`\n * to be present. This is needed to identify spans before normalization has had\n * a chance to add the missing `text` property.\n */\nexport function isSpanNode(\n context: {schema: EditorSchema},\n node: unknown,\n): node is SpanNode {\n return isTypedObject(node) && node._type === context.schema.span.name\n}\n","import type {PortableTextObject, PortableTextSpan} from '@portabletext/schema'\nimport type {EditorSchema} from '../../editor/editor-schema'\nimport {isTypedObject} from '../../utils/asserters'\n\ntype TextBlockNode = {\n _type: string\n _key: string\n children?: Array<PortableTextSpan | PortableTextObject>\n markDefs?: Array<PortableTextObject>\n style?: string\n listItem?: string\n level?: number\n}\n\n/**\n * Checks if a node is a text block based on `_type` alone, without requiring\n * `children` to be present. This is needed to identify text blocks before\n * normalization has had a chance to add the missing `children` property.\n */\nexport function isTextBlockNode(\n context: {schema: EditorSchema},\n node: unknown,\n): node is TextBlockNode {\n return isTypedObject(node) && node._type === context.schema.block.name\n}\n","import {isKeyedSegment} from '../../utils/util.is-keyed-segment'\nimport type {Path} from '../interfaces/path'\n\n/**\n * Get the parent path of a path.\n *\n * Drops the last node segment (keyed or numeric) and the preceding field\n * name string.\n *\n * [{_key:'b1'}, 'children', {_key:'s1'}] → [{_key:'b1'}]\n * [{_key:'b1'}, 'children', 0] → [{_key:'b1'}]\n * [{_key:'b1'}] → []\n */\nexport function parentPath(path: Path): Path {\n if (path.length === 0) {\n throw new Error(`Cannot get the parent path of the root path [${path}].`)\n }\n\n let lastNodeIndex = -1\n for (let i = path.length - 1; i >= 0; i--) {\n if (isKeyedSegment(path[i]) || typeof path[i] === 'number') {\n lastNodeIndex = i\n break\n }\n }\n\n if (lastNodeIndex === -1) {\n return []\n }\n\n const result = path.slice(0, lastNodeIndex)\n\n if (result.length > 0 && typeof result[result.length - 1] === 'string') {\n return result.slice(0, -1)\n }\n\n return result\n}\n","import type {Node} from '../slate/interfaces/node'\nimport type {Path} from '../slate/interfaces/path'\nimport {parentPath} from '../slate/path/parent-path'\nimport {getNode} from './get-node'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Get the parent of a node at a given path.\n *\n * @beta\n */\nexport function getParent(\n snapshot: TraversalSnapshot,\n path: Path,\n): {node: Node; path: Path} | undefined {\n if (path.length === 0) {\n return undefined\n }\n\n const parent = parentPath(path)\n\n if (parent.length === 0) {\n return undefined\n }\n\n return getNode(snapshot, parent)\n}\n","import type {PortableTextBlock} from '@portabletext/schema'\nimport type {Path} from '../slate/interfaces/path'\nimport {isSpanNode} from '../slate/node/is-span-node'\nimport {isTextBlockNode} from '../slate/node/is-text-block-node'\nimport {getNode} from './get-node'\nimport {getParent} from './get-parent'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Determine if a node at the given path is a block.\n *\n * A node is a block if its parent is not a text block. Top-level nodes\n * (direct children of the editor) are always blocks. Children of text blocks\n * (spans and inline objects) are not blocks. Children of containers are\n * blocks within that container.\n *\n * @beta\n */\nexport function isBlock(snapshot: TraversalSnapshot, path: Path): boolean {\n const parent = getParent(snapshot, path)\n\n if (!parent) {\n return true\n }\n\n return !isTextBlockNode({schema: snapshot.context.schema}, parent.node)\n}\n\n/**\n * Get the node at the given path if it is a block.\n *\n * Returns the node narrowed to PortableTextBlock, or undefined if the node\n * doesn't exist or is not a block.\n *\n * @beta\n */\nexport function getBlock(\n snapshot: TraversalSnapshot,\n path: Path,\n): {node: PortableTextBlock; path: Path} | undefined {\n const entry = getNode(snapshot, path)\n\n if (!entry) {\n return undefined\n }\n\n if (!isBlock(snapshot, path)) {\n return undefined\n }\n\n // Narrow the type: a block is never a span (spans always have a text block\n // parent, so isBlock returns false for them).\n if (isSpanNode({schema: snapshot.context.schema}, entry.node)) {\n return undefined\n }\n\n // Node minus PortableTextSpan = PortableTextTextBlock | PortableTextObject = PortableTextBlock\n return {node: entry.node, path: entry.path}\n}\n","import type {Path} from '../slate/interfaces/path'\nimport {getNode} from './get-node'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Check if a node exists at a given path.\n *\n * @beta\n */\nexport function hasNode(snapshot: TraversalSnapshot, path: Path): boolean {\n return getNode(snapshot, path) !== undefined\n}\n","import type {Node} from '../slate/interfaces/node'\nimport type {Path} from '../slate/interfaces/path'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport type {\n Containers,\n RegisteredContainer,\n RegisteredPositional,\n} from './container-types'\n\n/**\n * Walk the editor value following `path` and return the\n * {@link RegisteredContainer} or {@link RegisteredPositional} that applies\n * at `path`'s target position.\n *\n * Resolution rules at each step:\n *\n * 1. **Positional override.** If the current parent declares the\n * child's `_type` in its `of`, the positional entry wins.\n * Used to resolve same-`_type` registered under different\n * parents with different `field` values.\n *\n * 2. **Global fallback.** If the parent has no positional override,\n * fall back to the top-level entry for `_type` in\n * `containers`.\n *\n * 3. **Chain validity.** If any ancestor along the path has no\n * resolved container entry (unregistered or not reachable as a\n * container at its position), return `undefined`.\n *\n * Returns `undefined` when the target's `_type` is not registered\n * at this position. Returns a {@link RegisteredPositional} when the target\n * resolves to a leaf in a positional `of` (terminal node with no\n * editable children).\n *\n * @alpha\n */\nexport function resolveContainerAt(\n containers: Containers,\n value: ReadonlyArray<Node>,\n path: Path,\n): RegisteredContainer | RegisteredPositional | undefined {\n const keyedIndices: Array<number> = []\n for (let index = 0; index < path.length; index++) {\n if (isKeyedSegment(path[index])) {\n keyedIndices.push(index)\n }\n }\n if (keyedIndices.length === 0) {\n return undefined\n }\n\n let currentChildren: ReadonlyArray<Node> = value\n let parent: RegisteredContainer | undefined\n let resolved: RegisteredContainer | RegisteredPositional | undefined\n const targetKeyedIndex = keyedIndices[keyedIndices.length - 1]!\n\n let segmentIndex = 0\n while (segmentIndex <= targetKeyedIndex) {\n const segment = path[segmentIndex]!\n if (typeof segment === 'string') {\n segmentIndex++\n continue\n }\n\n let node: Node | undefined\n if (isKeyedSegment(segment)) {\n node = currentChildren.find((child) => child._key === segment._key)\n } else if (typeof segment === 'number') {\n node = currentChildren.at(segment)\n } else {\n return undefined\n }\n if (!node) {\n return undefined\n }\n\n resolved = resolveNodeEntry(containers, parent, node)\n if (!resolved) {\n return undefined\n }\n\n if (segmentIndex < targetKeyedIndex) {\n // Walk one more level. The resolved entry must be a container\n // (have children) for descent to continue.\n if (!('field' in resolved)) {\n return undefined\n }\n const fieldValue = (node as Record<string, unknown>)[resolved.field.name]\n if (!Array.isArray(fieldValue)) {\n return undefined\n }\n parent = resolved\n currentChildren = fieldValue as Array<Node>\n }\n segmentIndex++\n }\n\n return resolved\n}\n\nfunction resolveNodeEntry(\n containers: Containers,\n parent: RegisteredContainer | undefined,\n node: Node,\n): RegisteredContainer | RegisteredPositional | undefined {\n if (parent?.of) {\n for (const entry of parent.of) {\n if (entry.type === node._type) {\n return entry\n }\n }\n }\n return containers.get(node._type)\n}\n","import type {PortableTextBlock} from '@portabletext/schema'\nimport type {Path} from '../slate/interfaces/path'\nimport {getAncestors} from './get-ancestors'\nimport {getBlock, isBlock} from './is-block'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Walk up from a path to find the nearest enclosing block.\n *\n * Returns the node at the path if it is a block, otherwise the first ancestor\n * that is a block. Works at any depth — inside a container this returns the\n * container-internal block, not the outer container.\n *\n * @beta\n */\nexport function getEnclosingBlock(\n snapshot: TraversalSnapshot,\n path: Path,\n): {node: PortableTextBlock; path: Path} | undefined {\n const direct = getBlock(snapshot, path)\n\n if (direct) {\n return direct\n }\n\n for (const ancestor of getAncestors(snapshot, path)) {\n if (isBlock(snapshot, ancestor.path)) {\n const block = getBlock(snapshot, ancestor.path)\n\n if (block) {\n return block\n }\n }\n }\n\n return undefined\n}\n","import {isKeyedSegment} from '../../utils/util.is-keyed-segment'\nimport type {Path} from '../interfaces/path'\n\nexport function isAncestorPath(path: Path, another: Path): boolean {\n if (path.length >= another.length) {\n return false\n }\n\n for (let i = 0; i < path.length; i++) {\n const segment = path[i]\n const otherSegment = another[i]\n\n if (isKeyedSegment(segment) && isKeyedSegment(otherSegment)) {\n if (segment._key !== otherSegment._key) {\n return false\n }\n } else if (segment !== otherSegment) {\n return false\n }\n }\n\n return true\n}\n","import type {EditorSchema} from '../editor/editor-schema'\nimport type {\n Containers,\n RegisteredContainer,\n} from '../schema/resolve-containers'\nimport type {Node} from '../slate/interfaces/node'\nimport type {Path} from '../slate/interfaces/path'\nimport {isAncestorPath} from '../slate/path/is-ancestor-path'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {getChildren, getNodeChildren} from './get-children'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Get the descendant nodes of the node at a given path.\n *\n * When `from` and `to` are provided, performs a range-bounded DFS traversal,\n * yielding only nodes between `from` and `to` (inclusive). Both paths are\n * always in document order: `from` is the earlier path, `to` is the later\n * path. The `reverse` flag controls iteration direction within that range.\n *\n * When `match` is provided, only yields nodes where the predicate returns true.\n * The traversal still visits all nodes in range - `match` is a filter, not a\n * traversal control.\n *\n * When `at` is provided, traverses descendants of the node at that path\n * instead of the root.\n */\nexport function* getNodes(\n snapshot: TraversalSnapshot,\n options: {\n at?: Path\n from?: Path\n to?: Path\n match?: (node: Node, path: Path) => boolean\n reverse?: boolean\n } = {},\n): Generator<{node: Node; path: Path}, void, undefined> {\n const {at = [], from, to, match, reverse = false} = options\n\n if (from === undefined && to === undefined) {\n yield* getNodesSimple(snapshot, at, {match, reverse})\n return\n }\n\n yield* getNodesInRange(snapshot, at, {from, to, match, reverse})\n}\n\n/**\n * Get descendant nodes of a standalone node (not in the editor tree).\n * Used for cases like getDirtyPaths where the node hasn't been inserted yet.\n */\nexport function* getNodeDescendants(\n context: {\n schema: EditorSchema\n containers: Containers\n },\n node: Node | {value: Array<Node>},\n): Generator<{node: Node; path: Path}, void, undefined> {\n // The editor root wrapper ({value: [...]}) is not a real node, so its field\n // name is not part of paths. For standalone nodes (a real {_key, _type, ...}\n // passed in by callers like getDirtyPaths), the field name IS part of the\n // path.\n const isRoot = !('_key' in node) && !('_type' in node)\n yield* walkStandalone(context, node, [], isRoot)\n}\n\nfunction* walkStandalone(\n context: {\n schema: EditorSchema\n containers: Containers\n },\n node: Node | {value: Array<Node>},\n path: Path,\n isRoot: boolean,\n parent?: RegisteredContainer,\n): Generator<{node: Node; path: Path}, void, undefined> {\n const next = getNodeChildren(context, node, parent)\n if (!next) {\n return\n }\n\n for (const child of next.children) {\n const childPath: Path = isRoot\n ? [{_key: child._key}]\n : [...path, next.fieldName, {_key: child._key}]\n yield {node: child, path: childPath}\n yield* walkStandalone(context, child, childPath, false, next.parent)\n }\n}\n\n/**\n * Simple recursive DFS - the original behavior.\n * Yields all descendants of the node at `path`.\n */\nfunction* getNodesSimple(\n snapshot: TraversalSnapshot,\n path: Path,\n options: {\n match?: (node: Node, path: Path) => boolean\n reverse?: boolean\n },\n): Generator<{node: Node; path: Path}, void, undefined> {\n const {match, reverse = false} = options\n\n const children = getChildren(snapshot, path)\n\n const entries = reverse ? [...children].reverse() : children\n\n for (const entry of entries) {\n if (!match || match(entry.node, entry.path)) {\n yield entry\n }\n\n yield* getNodesSimple(snapshot, entry.path, options)\n }\n}\n\n/**\n * Compare two keyed paths in document order. Returns -1, 0, or 1.\n *\n * Descends both paths from the root in a single pass, advancing\n * `currentNode` and `currentChildren` together so each level costs\n * one keyed-segment scan instead of an O(depth) walk from root.\n *\n * Uses `blockIndexMap` for O(1) lookup at the root level. Deeper\n * levels fall back to a linear scan of the current sibling array.\n */\nfunction comparePathsInTree(\n snapshot: TraversalSnapshot,\n pathA: Path,\n pathB: Path,\n): -1 | 0 | 1 {\n const keysA = pathA.filter(isKeyedSegment)\n const keysB = pathB.filter(isKeyedSegment)\n\n const {context} = snapshot\n let currentChildren: Array<Node> = context.value\n let currentParent: RegisteredContainer | undefined\n let isRootLevel = true\n\n const minDepth = Math.min(keysA.length, keysB.length)\n\n for (let depth = 0; depth < minDepth; depth++) {\n const keyA = keysA[depth]!\n const keyB = keysB[depth]!\n\n if (keyA._key === keyB._key) {\n // Same node at this depth: descend into its children for the next\n // iteration. The root level can short-circuit via blockIndexMap;\n // deeper levels scan the current sibling array.\n let matchedNode: Node | undefined\n if (isRootLevel && snapshot.blockIndexMap.has(keyA._key)) {\n const index = snapshot.blockIndexMap.get(keyA._key)\n if (index !== undefined) {\n matchedNode = currentChildren[index]\n }\n } else {\n matchedNode = currentChildren.find((c) => c._key === keyA._key)\n }\n if (!matchedNode) {\n return 0\n }\n const next = getNodeChildren(context, matchedNode, currentParent)\n if (!next) {\n return 0\n }\n currentChildren = next.children\n currentParent = next.parent\n\n isRootLevel = false\n continue\n }\n\n if (isRootLevel) {\n const indexA = snapshot.blockIndexMap.get(keyA._key) ?? -1\n const indexB = snapshot.blockIndexMap.get(keyB._key) ?? -1\n if (indexA !== -1 && indexB !== -1) {\n if (indexA < indexB) {\n return -1\n }\n if (indexA > indexB) {\n return 1\n }\n return 0\n }\n }\n\n let indexA = -1\n let indexB = -1\n for (let i = 0; i < currentChildren.length; i++) {\n const sibling = currentChildren[i]!\n if (sibling._key === keyA._key) {\n indexA = i\n }\n if (sibling._key === keyB._key) {\n indexB = i\n }\n if (indexA !== -1 && indexB !== -1) {\n break\n }\n }\n\n if (indexA < indexB) {\n return -1\n }\n if (indexA > indexB) {\n return 1\n }\n\n return 0\n }\n\n // One path is a prefix of the other (ancestor relationship)\n // In DFS order, shorter path (ancestor) comes first\n if (keysA.length < keysB.length) {\n return -1\n }\n if (keysA.length > keysB.length) {\n return 1\n }\n\n return 0\n}\n\n/**\n * Range-bounded recursive DFS traversal.\n *\n * `from` and `to` are always in document order (from is earlier, to is\n * later), regardless of traversal direction.\n */\nfunction* getNodesInRange(\n snapshot: TraversalSnapshot,\n path: Path,\n options: {\n from?: Path\n to?: Path\n match?: (node: Node, path: Path) => boolean\n reverse?: boolean\n },\n): Generator<{node: Node; path: Path}, void, undefined> {\n const {from, to, match, reverse = false} = options\n\n const children = getChildren(snapshot, path)\n const entries = reverse ? [...children].reverse() : children\n\n for (const entry of entries) {\n if (canStopTraversal(snapshot, entry.path, from, to, reverse)) {\n return\n }\n\n if (!couldContainInRangeNodes(snapshot, entry.path, from, to)) {\n continue\n }\n\n if (isInRange(snapshot, entry.path, from, to)) {\n if (!match || match(entry.node, entry.path)) {\n yield entry\n }\n }\n\n yield* getNodesInRange(snapshot, entry.path, options)\n }\n}\n\n/**\n * Check if a node is within the [from, to] range in document order.\n * Both bounds are inclusive. Ancestor nodes of from or to are also\n * considered in range since they contain the range boundary.\n */\nfunction isInRange(\n snapshot: TraversalSnapshot,\n nodePath: Path,\n from: Path | undefined,\n to: Path | undefined,\n): boolean {\n if (\n from !== undefined &&\n comparePathsInTree(snapshot, nodePath, from) === -1\n ) {\n if (!isAncestorPath(nodePath, from)) {\n return false\n }\n }\n\n if (to !== undefined && comparePathsInTree(snapshot, nodePath, to) === 1) {\n if (!isAncestorPath(nodePath, to)) {\n return false\n }\n }\n\n return true\n}\n\n/**\n * Check if a subtree rooted at `nodePath` could contain any nodes in the\n * [from, to] range.\n */\nfunction couldContainInRangeNodes(\n snapshot: TraversalSnapshot,\n nodePath: Path,\n from: Path | undefined,\n to: Path | undefined,\n): boolean {\n if (isInRange(snapshot, nodePath, from, to)) {\n return true\n }\n\n if (from !== undefined && isAncestorPath(nodePath, from)) {\n return true\n }\n\n if (to !== undefined && isAncestorPath(nodePath, to)) {\n return true\n }\n\n return false\n}\n\n/**\n * Check if all remaining nodes in iteration order will be outside the range.\n */\nfunction canStopTraversal(\n snapshot: TraversalSnapshot,\n nodePath: Path,\n from: Path | undefined,\n to: Path | undefined,\n reverse: boolean,\n): boolean {\n if (reverse) {\n if (from === undefined) {\n return false\n }\n\n return (\n comparePathsInTree(snapshot, nodePath, from) === -1 &&\n !isAncestorPath(nodePath, from)\n )\n }\n\n if (to === undefined) {\n return false\n }\n\n return comparePathsInTree(snapshot, nodePath, to) === 1\n}\n","import type {Node} from '../slate/interfaces/node'\nimport type {Path} from '../slate/interfaces/path'\nimport {parentPath} from '../slate/path/parent-path'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {getChildren} from './get-children'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Get the next or previous sibling of the node at a given path.\n *\n * @beta\n */\nexport function getSibling(\n snapshot: TraversalSnapshot,\n path: Path,\n direction: 'next' | 'previous',\n): {node: Node; path: Path} | undefined {\n if (path.length === 0) {\n return undefined\n }\n\n const lastSegment = path.at(-1)\n\n if (!isKeyedSegment(lastSegment)) {\n return undefined\n }\n\n const parent = parentPath(path)\n const children = getChildren(snapshot, parent)\n\n const currentIndex = children.findIndex(\n (child) => child.node._key === lastSegment._key,\n )\n\n if (currentIndex === -1) {\n return undefined\n }\n\n const siblingIndex =\n direction === 'next' ? currentIndex + 1 : currentIndex - 1\n\n if (siblingIndex < 0 || siblingIndex >= children.length) {\n return undefined\n }\n\n return children[siblingIndex]\n}\n","import type {Path} from '../slate/interfaces/path'\nimport {isBlock} from './is-block'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Determine if a node at the given path is inline.\n *\n * A node is inline if its parent is a text block. This is the inverse of\n * `isBlock`. Top-level nodes are never inline.\n *\n * @beta\n */\nexport function isInline(snapshot: TraversalSnapshot, path: Path): boolean {\n return !isBlock(snapshot, path)\n}\n","import {getAncestors} from '../node-traversal/get-ancestors'\nimport type {TraversalSnapshot} from '../node-traversal/traversal-snapshot'\nimport type {Path} from '../slate/interfaces/path'\nimport {isObjectNode} from '../slate/node/is-object-node'\nimport type {RegisteredContainer} from './container-types'\nimport {resolveContainerAt} from './resolve-container-at'\n\n/**\n * Descent primitive: return the immediate parent\n * {@link RegisteredContainer} of the node at `path` (and that parent's\n * path), or `undefined` when the target's immediate parent is the\n * editor root, when no object-node ancestor is a registered container,\n * or when descent hits an ancestor whose `_type` is not registered.\n *\n * Walks ancestors and resolves each object-node ancestor positionally\n * via {@link resolveContainerAt}. Text-block and span ancestors are\n * skipped - \"container\" here means the enclosing object container,\n * not the text-block holding spans.\n */\nexport function descendToParent(\n snapshot: TraversalSnapshot,\n path: Path,\n): {parent: RegisteredContainer; parentPath: Path} | undefined {\n const ancestors = getAncestors(snapshot, path)\n for (const ancestor of ancestors) {\n if (!isObjectNode({schema: snapshot.context.schema}, ancestor.node)) {\n continue\n }\n const resolved = resolveContainerAt(\n snapshot.context.containers,\n snapshot.context.value,\n ancestor.path,\n )\n if (!resolved || !('field' in resolved)) {\n return undefined\n }\n return {parent: resolved, parentPath: ancestor.path}\n }\n return undefined\n}\n","import type {OfDefinition} from '@portabletext/schema'\nimport type {TraversalSnapshot} from '../node-traversal/traversal-snapshot'\nimport type {Path} from '../slate/interfaces/path'\nimport {descendToParent} from './descend-to-parent'\n\n/**\n * Return the immediate registered-container ancestor of `path` along\n * with its `of` array (the schema definitions accepted at this position).\n *\n * Position-aware: nested-only registrations (e.g. `cell` registered\n * only inside `table.row.of`) are recognized via the same descent\n * primitive used by all parent-aware traversal.\n *\n * Returns `undefined` when `path` has no registered-container ancestor\n * (i.e. is at the document root) or when descent hits a leaf-resolved\n * ancestor.\n */\nexport function getEnclosingContainer(\n snapshot: TraversalSnapshot,\n path: Path,\n):\n | {\n of: ReadonlyArray<OfDefinition>\n path: Path\n }\n | undefined {\n const descent = descendToParent(snapshot, path)\n if (!descent) {\n return undefined\n }\n return {\n of: descent.parent.field.of,\n path: descent.parentPath,\n }\n}\n","import {getSubSchema, type Schema} from '@portabletext/schema'\nimport type {TraversalSnapshot} from '../node-traversal/traversal-snapshot'\nimport {getEnclosingContainer} from '../schema/get-enclosing-container'\nimport type {Path} from '../slate/interfaces/path'\n\n/**\n * Return the `Schema` view that applies at a given path.\n *\n * For paths at the root of the document, or for paths where no ancestor is\n * a registered container, returns the top-level schema. For paths inside a\n * container, walks ancestors to find the nearest container and returns the\n * sub-schema derived from its `of` declaration.\n *\n * @beta\n */\nexport function getPathSubSchema(\n snapshot: TraversalSnapshot,\n path: Path,\n): Schema {\n const enclosing = getEnclosingContainer(snapshot, path)\n\n if (!enclosing) {\n return snapshot.context.schema\n }\n\n return getSubSchema(snapshot.context.schema, enclosing.of)\n}\n"],"names":["isSpanNode","context","node","isTypedObject","_type","schema","span","name","isTextBlockNode","block","parentPath","path","length","Error","lastNodeIndex","i","isKeyedSegment","result","slice","getParent","snapshot","parent","getNode","isBlock","getBlock","entry","hasNode","undefined","resolveContainerAt","containers","value","keyedIndices","index","push","currentChildren","resolved","targetKeyedIndex","segmentIndex","segment","find","child","_key","at","resolveNodeEntry","fieldValue","field","Array","isArray","of","type","get","getEnclosingBlock","direct","ancestor","getAncestors","isAncestorPath","another","otherSegment","getNodes","options","from","to","match","reverse","getNodesSimple","getNodesInRange","children","getChildren","entries","comparePathsInTree","pathA","pathB","keysA","filter","keysB","currentParent","isRootLevel","minDepth","Math","min","depth","keyA","keyB","matchedNode","blockIndexMap","has","c","next","getNodeChildren","indexA","indexB","sibling","canStopTraversal","couldContainInRangeNodes","isInRange","nodePath","getSibling","direction","lastSegment","currentIndex","findIndex","siblingIndex","isInline","descendToParent","ancestors","isObjectNode","getEnclosingContainer","descent","getPathSubSchema","enclosing","getSubSchema"],"mappings":";;AAeO,SAASA,WACdC,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;AAC9B;AClCO,SAASC,SAASlF,UAA6BT,MAAqB;AACzE,SAAO,CAACY,QAAQH,UAAUT,IAAI;AAChC;ACKO,SAAS4F,gBACdnF,UACAT,MAC6D;AAC7D,QAAM6F,YAAYlD,aAAalC,UAAUT,IAAI;AAC7C,aAAW0C,YAAYmD,WAAW;AAChC,QAAI,CAACC,aAAa;AAAA,MAACpG,QAAQe,SAASnB,QAAQI;AAAAA,IAAAA,GAASgD,SAASnD,IAAI;AAChE;AAEF,UAAMiC,WAAWP,mBACfR,SAASnB,QAAQ4B,YACjBT,SAASnB,QAAQ6B,OACjBuB,SAAS1C,IACX;AACA,WAAI,CAACwB,YAAY,EAAE,WAAWA,YAC5B,SAEK;AAAA,MAACd,QAAQc;AAAAA,MAAUzB,YAAY2C,SAAS1C;AAAAA,IAAAA;AAAAA,EACjD;AAEF;ACtBO,SAAS+F,sBACdtF,UACAT,MAMY;AACZ,QAAMgG,UAAUJ,gBAAgBnF,UAAUT,IAAI;AAC9C,MAAKgG;AAGL,WAAO;AAAA,MACL3D,IAAI2D,QAAQtF,OAAOwB,MAAMG;AAAAA,MACzBrC,MAAMgG,QAAQjG;AAAAA,IAAAA;AAElB;ACnBO,SAASkG,iBACdxF,UACAT,MACQ;AACR,QAAMkG,YAAYH,sBAAsBtF,UAAUT,IAAI;AAEtD,SAAKkG,YAIEC,aAAa1F,SAASnB,QAAQI,QAAQwG,UAAU7D,EAAE,IAHhD5B,SAASnB,QAAQI;AAI5B;"}
1
+ {"version":3,"file":"get-path-sub-schema.js","sources":["../../src/node-traversal/has-node.ts","../../src/engine/node/is-text-block-node.ts","../../src/schema/resolve-container-at.ts","../../src/engine/path/is-ancestor-path.ts","../../src/node-traversal/get-nodes.ts","../../src/engine/path/parent-path.ts","../../src/node-traversal/get-sibling.ts","../../src/engine/node/is-span-node.ts","../../src/node-traversal/get-parent.ts","../../src/node-traversal/is-block.ts","../../src/node-traversal/is-inline.ts","../../src/node-traversal/get-enclosing-block.ts","../../src/schema/descend-to-parent.ts","../../src/schema/get-enclosing-container.ts","../../src/traversal/get-path-sub-schema.ts"],"sourcesContent":["import type {Path} from '../engine/interfaces/path'\nimport {getNode} from './get-node'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Check if a node exists at a given path.\n *\n * @beta\n */\nexport function hasNode(snapshot: TraversalSnapshot, path: Path): boolean {\n return getNode(snapshot, path) !== undefined\n}\n","import type {PortableTextObject, PortableTextSpan} from '@portabletext/schema'\nimport type {EditorSchema} from '../../editor/editor-schema'\nimport {isTypedObject} from '../../utils/asserters'\n\ntype TextBlockNode = {\n _type: string\n _key: string\n children?: Array<PortableTextSpan | PortableTextObject>\n markDefs?: Array<PortableTextObject>\n style?: string\n listItem?: string\n level?: number\n}\n\n/**\n * Checks if a node is a text block based on `_type` alone, without requiring\n * `children` to be present. This is needed to identify text blocks before\n * normalization has had a chance to add the missing `children` property.\n */\nexport function isTextBlockNode(\n context: {schema: EditorSchema},\n node: unknown,\n): node is TextBlockNode {\n return isTypedObject(node) && node._type === context.schema.block.name\n}\n","import type {Node} from '../engine/interfaces/node'\nimport type {Path} from '../engine/interfaces/path'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport type {\n Containers,\n RegisteredContainer,\n RegisteredPositional,\n} from './container-types'\n\n/**\n * Walk the editor value following `path` and return the\n * {@link RegisteredContainer} or {@link RegisteredPositional} that applies\n * at `path`'s target position.\n *\n * Resolution rules at each step:\n *\n * 1. **Positional override.** If the current parent declares the\n * child's `_type` in its `of`, the positional entry wins.\n * Used to resolve same-`_type` registered under different\n * parents with different `field` values.\n *\n * 2. **Global fallback.** If the parent has no positional override,\n * fall back to the top-level entry for `_type` in\n * `containers`.\n *\n * 3. **Chain validity.** If any ancestor along the path has no\n * resolved container entry (unregistered or not reachable as a\n * container at its position), return `undefined`.\n *\n * Returns `undefined` when the target's `_type` is not registered\n * at this position. Returns a {@link RegisteredPositional} when the target\n * resolves to a leaf in a positional `of` (terminal node with no\n * editable children).\n *\n * @alpha\n */\nexport function resolveContainerAt(\n containers: Containers,\n value: ReadonlyArray<Node>,\n path: Path,\n): RegisteredContainer | RegisteredPositional | undefined {\n const keyedIndices: Array<number> = []\n for (let index = 0; index < path.length; index++) {\n if (isKeyedSegment(path[index])) {\n keyedIndices.push(index)\n }\n }\n if (keyedIndices.length === 0) {\n return undefined\n }\n\n let currentChildren: ReadonlyArray<Node> = value\n let parent: RegisteredContainer | undefined\n let resolved: RegisteredContainer | RegisteredPositional | undefined\n const targetKeyedIndex = keyedIndices[keyedIndices.length - 1]!\n\n let segmentIndex = 0\n while (segmentIndex <= targetKeyedIndex) {\n const segment = path[segmentIndex]!\n if (typeof segment === 'string') {\n segmentIndex++\n continue\n }\n\n let node: Node | undefined\n if (isKeyedSegment(segment)) {\n node = currentChildren.find((child) => child._key === segment._key)\n } else if (typeof segment === 'number') {\n node = currentChildren.at(segment)\n } else {\n return undefined\n }\n if (!node) {\n return undefined\n }\n\n resolved = resolveNodeEntry(containers, parent, node)\n if (!resolved) {\n return undefined\n }\n\n if (segmentIndex < targetKeyedIndex) {\n // Walk one more level. The resolved entry must be a container\n // (have children) for descent to continue.\n if (!('field' in resolved)) {\n return undefined\n }\n const fieldValue = (node as Record<string, unknown>)[resolved.field.name]\n if (!Array.isArray(fieldValue)) {\n return undefined\n }\n parent = resolved\n currentChildren = fieldValue as Array<Node>\n }\n segmentIndex++\n }\n\n return resolved\n}\n\nfunction resolveNodeEntry(\n containers: Containers,\n parent: RegisteredContainer | undefined,\n node: Node,\n): RegisteredContainer | RegisteredPositional | undefined {\n if (parent?.of) {\n for (const entry of parent.of) {\n if (entry.type === node._type) {\n return entry\n }\n }\n }\n return containers.get(node._type)\n}\n","import {isKeyedSegment} from '../../utils/util.is-keyed-segment'\nimport type {Path} from '../interfaces/path'\n\nexport function isAncestorPath(path: Path, another: Path): boolean {\n if (path.length >= another.length) {\n return false\n }\n\n for (let i = 0; i < path.length; i++) {\n const segment = path[i]\n const otherSegment = another[i]\n\n if (isKeyedSegment(segment) && isKeyedSegment(otherSegment)) {\n if (segment._key !== otherSegment._key) {\n return false\n }\n } else if (segment !== otherSegment) {\n return false\n }\n }\n\n return true\n}\n","import type {EditorSchema} from '../editor/editor-schema'\nimport type {Node} from '../engine/interfaces/node'\nimport type {Path} from '../engine/interfaces/path'\nimport {isAncestorPath} from '../engine/path/is-ancestor-path'\nimport type {\n Containers,\n RegisteredContainer,\n} from '../schema/resolve-containers'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {getChildren, getNodeChildren} from './get-children'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Get the descendant nodes of the node at a given path.\n *\n * When `from` and `to` are provided, performs a range-bounded DFS traversal,\n * yielding only nodes between `from` and `to` (inclusive). Both paths are\n * always in document order: `from` is the earlier path, `to` is the later\n * path. The `reverse` flag controls iteration direction within that range.\n *\n * When `match` is provided, only yields nodes where the predicate returns true.\n * The traversal still visits all nodes in range - `match` is a filter, not a\n * traversal control.\n *\n * When `at` is provided, traverses descendants of the node at that path\n * instead of the root.\n */\nexport function* getNodes(\n snapshot: TraversalSnapshot,\n options: {\n at?: Path\n from?: Path\n to?: Path\n match?: (node: Node, path: Path) => boolean\n reverse?: boolean\n } = {},\n): Generator<{node: Node; path: Path}, void, undefined> {\n const {at = [], from, to, match, reverse = false} = options\n\n if (from === undefined && to === undefined) {\n yield* getNodesSimple(snapshot, at, {match, reverse})\n return\n }\n\n yield* getNodesInRange(snapshot, at, {from, to, match, reverse})\n}\n\n/**\n * Get descendant nodes of a standalone node (not in the editor tree).\n * Used for cases like getDirtyPaths where the node hasn't been inserted yet.\n */\nexport function* getNodeDescendants(\n context: {\n schema: EditorSchema\n containers: Containers\n },\n node: Node | {value: Array<Node>},\n): Generator<{node: Node; path: Path}, void, undefined> {\n // The editor root wrapper ({value: [...]}) is not a real node, so its field\n // name is not part of paths. For standalone nodes (a real {_key, _type, ...}\n // passed in by callers like getDirtyPaths), the field name IS part of the\n // path.\n const isRoot = !('_key' in node) && !('_type' in node)\n yield* walkStandalone(context, node, [], isRoot)\n}\n\nfunction* walkStandalone(\n context: {\n schema: EditorSchema\n containers: Containers\n },\n node: Node | {value: Array<Node>},\n path: Path,\n isRoot: boolean,\n parent?: RegisteredContainer,\n): Generator<{node: Node; path: Path}, void, undefined> {\n const next = getNodeChildren(context, node, parent)\n if (!next) {\n return\n }\n\n for (const child of next.children) {\n const childPath: Path = isRoot\n ? [{_key: child._key}]\n : [...path, next.fieldName, {_key: child._key}]\n yield {node: child, path: childPath}\n yield* walkStandalone(context, child, childPath, false, next.parent)\n }\n}\n\n/**\n * Simple recursive DFS - the original behavior.\n * Yields all descendants of the node at `path`.\n */\nfunction* getNodesSimple(\n snapshot: TraversalSnapshot,\n path: Path,\n options: {\n match?: (node: Node, path: Path) => boolean\n reverse?: boolean\n },\n): Generator<{node: Node; path: Path}, void, undefined> {\n const {match, reverse = false} = options\n\n const children = getChildren(snapshot, path)\n\n const entries = reverse ? [...children].reverse() : children\n\n for (const entry of entries) {\n if (!match || match(entry.node, entry.path)) {\n yield entry\n }\n\n yield* getNodesSimple(snapshot, entry.path, options)\n }\n}\n\n/**\n * Compare two keyed paths in document order. Returns -1, 0, or 1.\n *\n * Descends both paths from the root in a single pass, advancing\n * `currentNode` and `currentChildren` together so each level costs\n * one keyed-segment scan instead of an O(depth) walk from root.\n *\n * Uses `blockIndexMap` for O(1) lookup at the root level. Deeper\n * levels fall back to a linear scan of the current sibling array.\n */\nfunction comparePathsInTree(\n snapshot: TraversalSnapshot,\n pathA: Path,\n pathB: Path,\n): -1 | 0 | 1 {\n const keysA = pathA.filter(isKeyedSegment)\n const keysB = pathB.filter(isKeyedSegment)\n\n const {context} = snapshot\n let currentChildren: Array<Node> = context.value\n let currentParent: RegisteredContainer | undefined\n let isRootLevel = true\n\n const minDepth = Math.min(keysA.length, keysB.length)\n\n for (let depth = 0; depth < minDepth; depth++) {\n const keyA = keysA[depth]!\n const keyB = keysB[depth]!\n\n if (keyA._key === keyB._key) {\n // Same node at this depth: descend into its children for the next\n // iteration. The root level can short-circuit via blockIndexMap;\n // deeper levels scan the current sibling array.\n let matchedNode: Node | undefined\n if (isRootLevel && snapshot.blockIndexMap.has(keyA._key)) {\n const index = snapshot.blockIndexMap.get(keyA._key)\n if (index !== undefined) {\n matchedNode = currentChildren[index]\n }\n } else {\n matchedNode = currentChildren.find((c) => c._key === keyA._key)\n }\n if (!matchedNode) {\n return 0\n }\n const next = getNodeChildren(context, matchedNode, currentParent)\n if (!next) {\n return 0\n }\n currentChildren = next.children\n currentParent = next.parent\n\n isRootLevel = false\n continue\n }\n\n if (isRootLevel) {\n const indexA = snapshot.blockIndexMap.get(keyA._key) ?? -1\n const indexB = snapshot.blockIndexMap.get(keyB._key) ?? -1\n if (indexA !== -1 && indexB !== -1) {\n if (indexA < indexB) {\n return -1\n }\n if (indexA > indexB) {\n return 1\n }\n return 0\n }\n }\n\n let indexA = -1\n let indexB = -1\n for (let i = 0; i < currentChildren.length; i++) {\n const sibling = currentChildren[i]!\n if (sibling._key === keyA._key) {\n indexA = i\n }\n if (sibling._key === keyB._key) {\n indexB = i\n }\n if (indexA !== -1 && indexB !== -1) {\n break\n }\n }\n\n if (indexA < indexB) {\n return -1\n }\n if (indexA > indexB) {\n return 1\n }\n\n return 0\n }\n\n // One path is a prefix of the other (ancestor relationship)\n // In DFS order, shorter path (ancestor) comes first\n if (keysA.length < keysB.length) {\n return -1\n }\n if (keysA.length > keysB.length) {\n return 1\n }\n\n return 0\n}\n\n/**\n * Range-bounded recursive DFS traversal.\n *\n * `from` and `to` are always in document order (from is earlier, to is\n * later), regardless of traversal direction.\n */\nfunction* getNodesInRange(\n snapshot: TraversalSnapshot,\n path: Path,\n options: {\n from?: Path\n to?: Path\n match?: (node: Node, path: Path) => boolean\n reverse?: boolean\n },\n): Generator<{node: Node; path: Path}, void, undefined> {\n const {from, to, match, reverse = false} = options\n\n const children = getChildren(snapshot, path)\n const entries = reverse ? [...children].reverse() : children\n\n for (const entry of entries) {\n if (canStopTraversal(snapshot, entry.path, from, to, reverse)) {\n return\n }\n\n if (!couldContainInRangeNodes(snapshot, entry.path, from, to)) {\n continue\n }\n\n if (isInRange(snapshot, entry.path, from, to)) {\n if (!match || match(entry.node, entry.path)) {\n yield entry\n }\n }\n\n yield* getNodesInRange(snapshot, entry.path, options)\n }\n}\n\n/**\n * Check if a node is within the [from, to] range in document order.\n * Both bounds are inclusive. Ancestor nodes of from or to are also\n * considered in range since they contain the range boundary.\n */\nfunction isInRange(\n snapshot: TraversalSnapshot,\n nodePath: Path,\n from: Path | undefined,\n to: Path | undefined,\n): boolean {\n if (\n from !== undefined &&\n comparePathsInTree(snapshot, nodePath, from) === -1\n ) {\n if (!isAncestorPath(nodePath, from)) {\n return false\n }\n }\n\n if (to !== undefined && comparePathsInTree(snapshot, nodePath, to) === 1) {\n if (!isAncestorPath(nodePath, to)) {\n return false\n }\n }\n\n return true\n}\n\n/**\n * Check if a subtree rooted at `nodePath` could contain any nodes in the\n * [from, to] range.\n */\nfunction couldContainInRangeNodes(\n snapshot: TraversalSnapshot,\n nodePath: Path,\n from: Path | undefined,\n to: Path | undefined,\n): boolean {\n if (isInRange(snapshot, nodePath, from, to)) {\n return true\n }\n\n if (from !== undefined && isAncestorPath(nodePath, from)) {\n return true\n }\n\n if (to !== undefined && isAncestorPath(nodePath, to)) {\n return true\n }\n\n return false\n}\n\n/**\n * Check if all remaining nodes in iteration order will be outside the range.\n */\nfunction canStopTraversal(\n snapshot: TraversalSnapshot,\n nodePath: Path,\n from: Path | undefined,\n to: Path | undefined,\n reverse: boolean,\n): boolean {\n if (reverse) {\n if (from === undefined) {\n return false\n }\n\n return (\n comparePathsInTree(snapshot, nodePath, from) === -1 &&\n !isAncestorPath(nodePath, from)\n )\n }\n\n if (to === undefined) {\n return false\n }\n\n return comparePathsInTree(snapshot, nodePath, to) === 1\n}\n","import {isKeyedSegment} from '../../utils/util.is-keyed-segment'\nimport type {Path} from '../interfaces/path'\n\n/**\n * Get the parent path of a path.\n *\n * Drops the last node segment (keyed or numeric) and the preceding field\n * name string.\n *\n * [{_key:'b1'}, 'children', {_key:'s1'}] → [{_key:'b1'}]\n * [{_key:'b1'}, 'children', 0] → [{_key:'b1'}]\n * [{_key:'b1'}] → []\n */\nexport function parentPath(path: Path): Path {\n if (path.length === 0) {\n throw new Error(`Cannot get the parent path of the root path [${path}].`)\n }\n\n let lastNodeIndex = -1\n for (let i = path.length - 1; i >= 0; i--) {\n if (isKeyedSegment(path[i]) || typeof path[i] === 'number') {\n lastNodeIndex = i\n break\n }\n }\n\n if (lastNodeIndex === -1) {\n return []\n }\n\n const result = path.slice(0, lastNodeIndex)\n\n if (result.length > 0 && typeof result[result.length - 1] === 'string') {\n return result.slice(0, -1)\n }\n\n return result\n}\n","import type {Node} from '../engine/interfaces/node'\nimport type {Path} from '../engine/interfaces/path'\nimport {parentPath} from '../engine/path/parent-path'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {getChildren} from './get-children'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Get the next or previous sibling of the node at a given path.\n *\n * @beta\n */\nexport function getSibling(\n snapshot: TraversalSnapshot,\n path: Path,\n direction: 'next' | 'previous',\n): {node: Node; path: Path} | undefined {\n if (path.length === 0) {\n return undefined\n }\n\n const lastSegment = path.at(-1)\n\n if (!isKeyedSegment(lastSegment)) {\n return undefined\n }\n\n const parent = parentPath(path)\n const children = getChildren(snapshot, parent)\n\n const currentIndex = children.findIndex(\n (child) => child.node._key === lastSegment._key,\n )\n\n if (currentIndex === -1) {\n return undefined\n }\n\n const siblingIndex =\n direction === 'next' ? currentIndex + 1 : currentIndex - 1\n\n if (siblingIndex < 0 || siblingIndex >= children.length) {\n return undefined\n }\n\n return children[siblingIndex]\n}\n","import type {EditorSchema} from '../../editor/editor-schema'\nimport {isTypedObject} from '../../utils/asserters'\n\nexport type SpanNode = {\n _type: string\n _key: string\n text?: string\n marks?: Array<string>\n}\n\n/**\n * Checks if a node is a span based on `_type` alone, without requiring `text`\n * to be present. This is needed to identify spans before normalization has had\n * a chance to add the missing `text` property.\n */\nexport function isSpanNode(\n context: {schema: EditorSchema},\n node: unknown,\n): node is SpanNode {\n return isTypedObject(node) && node._type === context.schema.span.name\n}\n","import type {Node} from '../engine/interfaces/node'\nimport type {Path} from '../engine/interfaces/path'\nimport {parentPath} from '../engine/path/parent-path'\nimport {getNode} from './get-node'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Get the parent of a node at a given path.\n *\n * @beta\n */\nexport function getParent(\n snapshot: TraversalSnapshot,\n path: Path,\n): {node: Node; path: Path} | undefined {\n if (path.length === 0) {\n return undefined\n }\n\n const parent = parentPath(path)\n\n if (parent.length === 0) {\n return undefined\n }\n\n return getNode(snapshot, parent)\n}\n","import type {PortableTextBlock} from '@portabletext/schema'\nimport type {Path} from '../engine/interfaces/path'\nimport {isSpanNode} from '../engine/node/is-span-node'\nimport {isTextBlockNode} from '../engine/node/is-text-block-node'\nimport {getNode} from './get-node'\nimport {getParent} from './get-parent'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Determine if a node at the given path is a block.\n *\n * A node is a block if its parent is not a text block. Top-level nodes\n * (direct children of the editor) are always blocks. Children of text blocks\n * (spans and inline objects) are not blocks. Children of containers are\n * blocks within that container.\n *\n * @beta\n */\nexport function isBlock(snapshot: TraversalSnapshot, path: Path): boolean {\n const parent = getParent(snapshot, path)\n\n if (!parent) {\n return true\n }\n\n return !isTextBlockNode({schema: snapshot.context.schema}, parent.node)\n}\n\n/**\n * Get the node at the given path if it is a block.\n *\n * Returns the node narrowed to PortableTextBlock, or undefined if the node\n * doesn't exist or is not a block.\n *\n * @beta\n */\nexport function getBlock(\n snapshot: TraversalSnapshot,\n path: Path,\n): {node: PortableTextBlock; path: Path} | undefined {\n const entry = getNode(snapshot, path)\n\n if (!entry) {\n return undefined\n }\n\n if (!isBlock(snapshot, path)) {\n return undefined\n }\n\n // Narrow the type: a block is never a span (spans always have a text block\n // parent, so isBlock returns false for them).\n if (isSpanNode({schema: snapshot.context.schema}, entry.node)) {\n return undefined\n }\n\n // Node minus PortableTextSpan = PortableTextTextBlock | PortableTextObject = PortableTextBlock\n return {node: entry.node, path: entry.path}\n}\n","import type {Path} from '../engine/interfaces/path'\nimport {isBlock} from './is-block'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Determine if a node at the given path is inline.\n *\n * A node is inline if its parent is a text block. This is the inverse of\n * `isBlock`. Top-level nodes are never inline.\n *\n * @beta\n */\nexport function isInline(snapshot: TraversalSnapshot, path: Path): boolean {\n return !isBlock(snapshot, path)\n}\n","import type {PortableTextBlock} from '@portabletext/schema'\nimport type {Path} from '../engine/interfaces/path'\nimport {getAncestors} from './get-ancestors'\nimport {getBlock, isBlock} from './is-block'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Walk up from a path to find the nearest enclosing block.\n *\n * Returns the node at the path if it is a block, otherwise the first ancestor\n * that is a block. Works at any depth — inside a container this returns the\n * container-internal block, not the outer container.\n *\n * @beta\n */\nexport function getEnclosingBlock(\n snapshot: TraversalSnapshot,\n path: Path,\n): {node: PortableTextBlock; path: Path} | undefined {\n const direct = getBlock(snapshot, path)\n\n if (direct) {\n return direct\n }\n\n for (const ancestor of getAncestors(snapshot, path)) {\n if (isBlock(snapshot, ancestor.path)) {\n const block = getBlock(snapshot, ancestor.path)\n\n if (block) {\n return block\n }\n }\n }\n\n return undefined\n}\n","import type {Path} from '../engine/interfaces/path'\nimport {isObjectNode} from '../engine/node/is-object-node'\nimport {getAncestors} from '../node-traversal/get-ancestors'\nimport type {TraversalSnapshot} from '../node-traversal/traversal-snapshot'\nimport type {RegisteredContainer} from './container-types'\nimport {resolveContainerAt} from './resolve-container-at'\n\n/**\n * Descent primitive: return the immediate parent\n * {@link RegisteredContainer} of the node at `path` (and that parent's\n * path), or `undefined` when the target's immediate parent is the\n * editor root, when no object-node ancestor is a registered container,\n * or when descent hits an ancestor whose `_type` is not registered.\n *\n * Walks ancestors and resolves each object-node ancestor positionally\n * via {@link resolveContainerAt}. Text-block and span ancestors are\n * skipped - \"container\" here means the enclosing object container,\n * not the text-block holding spans.\n */\nexport function descendToParent(\n snapshot: TraversalSnapshot,\n path: Path,\n): {parent: RegisteredContainer; parentPath: Path} | undefined {\n const ancestors = getAncestors(snapshot, path)\n for (const ancestor of ancestors) {\n if (!isObjectNode({schema: snapshot.context.schema}, ancestor.node)) {\n continue\n }\n const resolved = resolveContainerAt(\n snapshot.context.containers,\n snapshot.context.value,\n ancestor.path,\n )\n if (!resolved || !('field' in resolved)) {\n return undefined\n }\n return {parent: resolved, parentPath: ancestor.path}\n }\n return undefined\n}\n","import type {OfDefinition} from '@portabletext/schema'\nimport type {Path} from '../engine/interfaces/path'\nimport type {TraversalSnapshot} from '../node-traversal/traversal-snapshot'\nimport {descendToParent} from './descend-to-parent'\n\n/**\n * Return the immediate registered-container ancestor of `path` along\n * with its `of` array (the schema definitions accepted at this position).\n *\n * Position-aware: nested-only registrations (e.g. `cell` registered\n * only inside `table.row.of`) are recognized via the same descent\n * primitive used by all parent-aware traversal.\n *\n * Returns `undefined` when `path` has no registered-container ancestor\n * (i.e. is at the document root) or when descent hits a leaf-resolved\n * ancestor.\n */\nexport function getEnclosingContainer(\n snapshot: TraversalSnapshot,\n path: Path,\n):\n | {\n of: ReadonlyArray<OfDefinition>\n path: Path\n }\n | undefined {\n const descent = descendToParent(snapshot, path)\n if (!descent) {\n return undefined\n }\n return {\n of: descent.parent.field.of,\n path: descent.parentPath,\n }\n}\n","import {getSubSchema, type Schema} from '@portabletext/schema'\nimport type {Path} from '../engine/interfaces/path'\nimport type {TraversalSnapshot} from '../node-traversal/traversal-snapshot'\nimport {getEnclosingContainer} from '../schema/get-enclosing-container'\n\n/**\n * Return the `Schema` view that applies at a given path.\n *\n * For paths at the root of the document, or for paths where no ancestor is\n * a registered container, returns the top-level schema. For paths inside a\n * container, walks ancestors to find the nearest container and returns the\n * sub-schema derived from its `of` declaration.\n *\n * @beta\n */\nexport function getPathSubSchema(\n snapshot: TraversalSnapshot,\n path: Path,\n): Schema {\n const enclosing = getEnclosingContainer(snapshot, path)\n\n if (!enclosing) {\n return snapshot.context.schema\n }\n\n return getSubSchema(snapshot.context.schema, enclosing.of)\n}\n"],"names":["hasNode","snapshot","path","getNode","undefined","isTextBlockNode","context","node","isTypedObject","_type","schema","block","name","resolveContainerAt","containers","value","keyedIndices","index","length","isKeyedSegment","push","currentChildren","parent","resolved","targetKeyedIndex","segmentIndex","segment","find","child","_key","at","resolveNodeEntry","fieldValue","field","Array","isArray","of","entry","type","get","isAncestorPath","another","i","otherSegment","getNodes","options","from","to","match","reverse","getNodesSimple","getNodesInRange","children","getChildren","entries","comparePathsInTree","pathA","pathB","keysA","filter","keysB","currentParent","isRootLevel","minDepth","Math","min","depth","keyA","keyB","matchedNode","blockIndexMap","has","c","next","getNodeChildren","indexA","indexB","sibling","canStopTraversal","couldContainInRangeNodes","isInRange","nodePath","parentPath","Error","lastNodeIndex","result","slice","getSibling","direction","lastSegment","currentIndex","findIndex","siblingIndex","isSpanNode","span","getParent","isBlock","getBlock","isInline","getEnclosingBlock","direct","ancestor","getAncestors","descendToParent","ancestors","isObjectNode","getEnclosingContainer","descent","getPathSubSchema","enclosing","getSubSchema"],"mappings":";;AASO,SAASA,QAAQC,UAA6BC,MAAqB;AACxE,SAAOC,QAAQF,UAAUC,IAAI,MAAME;AACrC;ACQO,SAASC,gBACdC,SACAC,MACuB;AACvB,SAAOC,cAAcD,IAAI,KAAKA,KAAKE,UAAUH,QAAQI,OAAOC,MAAMC;AACpE;ACYO,SAASC,mBACdC,YACAC,OACAb,MACwD;AACxD,QAAMc,eAA8B,CAAA;AACpC,WAASC,QAAQ,GAAGA,QAAQf,KAAKgB,QAAQD;AACnCE,mBAAejB,KAAKe,KAAK,CAAC,KAC5BD,aAAaI,KAAKH,KAAK;AAG3B,MAAID,aAAaE,WAAW;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MgB,WAAWV,mBACfZ,SAASK,QAAQQ,YACjBb,SAASK,QAAQS,OACjBsF,SAASnG,IACX;AACA,WAAI,CAACqB,YAAY,EAAE,WAAWA,YAC5B,SAEK;AAAA,MAACD,QAAQC;AAAAA,MAAU2D,YAAYmB,SAASnG;AAAAA,IAAAA;AAAAA,EACjD;AAEF;ACtBO,SAASwG,sBACdzG,UACAC,MAMY;AACZ,QAAMyG,UAAUJ,gBAAgBtG,UAAUC,IAAI;AAC9C,MAAKyG;AAGL,WAAO;AAAA,MACLvE,IAAIuE,QAAQrF,OAAOW,MAAMG;AAAAA,MACzBlC,MAAMyG,QAAQzB;AAAAA,IAAAA;AAElB;ACnBO,SAAS0B,iBACd3G,UACAC,MACQ;AACR,QAAM2G,YAAYH,sBAAsBzG,UAAUC,IAAI;AAEtD,SAAK2G,YAIEC,aAAa7G,SAASK,QAAQI,QAAQmG,UAAUzE,EAAE,IAHhDnC,SAASK,QAAQI;AAI5B;"}
@@ -1,5 +1,5 @@
1
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-ancestor.js";
2
+ import { isKeyedSegment, getNode, isObjectNode, getNodeChildren, getChildren } from "./get-node.js";
3
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";
4
4
  import { isSpan, isTextBlock } from "@portabletext/schema";
5
5
  function comparePaths(path, another, root) {