@portabletext/editor 7.5.1 → 7.6.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.
- package/lib/_chunks-dts/behavior.types.action.d.ts +4 -4
- package/lib/_chunks-es/get-parent.js +37 -19
- package/lib/_chunks-es/get-parent.js.map +1 -1
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +2 -3
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/index.js +311 -283
- package/lib/index.js.map +1 -1
- package/lib/traversal/index.d.ts +23 -2
- package/lib/traversal/index.d.ts.map +1 -1
- package/lib/traversal/index.js +2 -1
- package/package.json +2 -2
|
@@ -2,7 +2,7 @@ import * as _portabletext_schema6 from "@portabletext/schema";
|
|
|
2
2
|
import { AnnotationDefinition, AnnotationSchemaType, AnnotationSchemaType as AnnotationSchemaType$1, BaseDefinition, BlockObjectDefinition, BlockObjectSchemaType, BlockObjectSchemaType as BlockObjectSchemaType$1, DecoratorDefinition, DecoratorSchemaType, DecoratorSchemaType as DecoratorSchemaType$1, FieldDefinition, FieldDefinition as FieldDefinition$1, InlineObjectDefinition, InlineObjectSchemaType, InlineObjectSchemaType as InlineObjectSchemaType$1, ListDefinition, ListSchemaType, ListSchemaType as ListSchemaType$1, OfDefinition, PortableTextBlock, PortableTextBlock as PortableTextBlock$1, PortableTextChild, PortableTextChild as PortableTextChild$1, PortableTextObject, PortableTextObject as PortableTextObject$1, PortableTextSpan, PortableTextSpan as PortableTextSpan$1, PortableTextTextBlock, PortableTextTextBlock as PortableTextTextBlock$1, Schema, SchemaDefinition, SchemaDefinition as SchemaDefinition$1, StyleDefinition, StyleSchemaType, StyleSchemaType as StyleSchemaType$1, TypedObject, defineSchema } from "@portabletext/schema";
|
|
3
3
|
import * as xstate31 from "xstate";
|
|
4
4
|
import { ActorRef, ActorRefFrom, EventObject, Snapshot } from "xstate";
|
|
5
|
-
import * as
|
|
5
|
+
import * as react6 from "react";
|
|
6
6
|
import React$1, { BaseSyntheticEvent, ClipboardEvent as ClipboardEvent$1, FocusEvent, JSX, PropsWithChildren, ReactElement, RefObject, TextareaHTMLAttributes } from "react";
|
|
7
7
|
import { Patch, Patch as Patch$1 } from "@portabletext/patches";
|
|
8
8
|
type MIMEType = `${string}/${string}`;
|
|
@@ -1177,7 +1177,7 @@ type PortableTextEditableProps = Omit<TextareaHTMLAttributes<HTMLDivElement>, 'o
|
|
|
1177
1177
|
* ```
|
|
1178
1178
|
* @group Components
|
|
1179
1179
|
*/
|
|
1180
|
-
declare const PortableTextEditable:
|
|
1180
|
+
declare const PortableTextEditable: react6.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react6.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
|
|
1181
1181
|
/** @beta */
|
|
1182
1182
|
interface EditableAPIDeleteOptions {
|
|
1183
1183
|
mode?: 'blocks' | 'children' | 'selected';
|
|
@@ -2451,7 +2451,7 @@ declare const editorMachine: xstate31.StateMachine<{
|
|
|
2451
2451
|
initialValue?: Array<PortableTextBlock>;
|
|
2452
2452
|
}, xstate31.NonReducibleUnknown, InternalPatchEvent | MutationEvent | PatchesEvent | {
|
|
2453
2453
|
type: "blurred";
|
|
2454
|
-
event:
|
|
2454
|
+
event: react6.FocusEvent<HTMLDivElement, Element>;
|
|
2455
2455
|
} | {
|
|
2456
2456
|
type: "done loading";
|
|
2457
2457
|
} | {
|
|
@@ -2463,7 +2463,7 @@ declare const editorMachine: xstate31.StateMachine<{
|
|
|
2463
2463
|
data: unknown;
|
|
2464
2464
|
} | {
|
|
2465
2465
|
type: "focused";
|
|
2466
|
-
event:
|
|
2466
|
+
event: react6.FocusEvent<HTMLDivElement, Element>;
|
|
2467
2467
|
} | {
|
|
2468
2468
|
type: "invalid value";
|
|
2469
2469
|
resolution: InvalidValueResolution | null;
|
|
@@ -11,13 +11,40 @@ function isTypedObject(object) {
|
|
|
11
11
|
function isRecord(value) {
|
|
12
12
|
return !!value && (typeof value == "object" || typeof value == "function");
|
|
13
13
|
}
|
|
14
|
+
function getContainerChildren(containers, node, parent) {
|
|
15
|
+
const resolved = resolveNodeContainer(containers, parent, node);
|
|
16
|
+
if (!resolved)
|
|
17
|
+
return;
|
|
18
|
+
const fieldValue = node[resolved.field.name];
|
|
19
|
+
if (Array.isArray(fieldValue))
|
|
20
|
+
return {
|
|
21
|
+
children: fieldValue,
|
|
22
|
+
container: resolved
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function resolveNodeContainer(containers, parent, node) {
|
|
26
|
+
if (parent?.of) {
|
|
27
|
+
for (const entry of parent.of)
|
|
28
|
+
if (entry.type === node._type)
|
|
29
|
+
return "field" in entry ? entry : void 0;
|
|
30
|
+
}
|
|
31
|
+
return containers.get(node._type);
|
|
32
|
+
}
|
|
14
33
|
function getChildren(snapshot, path) {
|
|
15
34
|
let currentChildren = snapshot.context.value, currentFieldName = "value", currentPath = [], isRoot = !0, currentParent;
|
|
16
35
|
for (const segment of path) {
|
|
17
36
|
if (typeof segment == "string")
|
|
18
37
|
continue;
|
|
19
38
|
let node;
|
|
20
|
-
if (isKeyedSegment(segment)
|
|
39
|
+
if (isKeyedSegment(segment)) {
|
|
40
|
+
const candidatePath = isRoot ? [{
|
|
41
|
+
_key: segment._key
|
|
42
|
+
}] : [...currentPath, currentFieldName, {
|
|
43
|
+
_key: segment._key
|
|
44
|
+
}], index = snapshot.blockIndexMap.get(serializePath(candidatePath));
|
|
45
|
+
node = index !== void 0 && currentChildren[index]?._key === segment._key ? currentChildren[index] : currentChildren.find((child) => child._key === segment._key);
|
|
46
|
+
} else typeof segment == "number" && (node = currentChildren.at(segment));
|
|
47
|
+
if (!node)
|
|
21
48
|
return [];
|
|
22
49
|
currentPath = isRoot ? [{
|
|
23
50
|
_key: node._key
|
|
@@ -45,16 +72,14 @@ function getNodeChildren(context, node, parent) {
|
|
|
45
72
|
fieldName: "children",
|
|
46
73
|
parent: void 0
|
|
47
74
|
};
|
|
48
|
-
if (isTypedObject(node)
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
51
|
-
return
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
parent: resolved
|
|
57
|
-
} : void 0;
|
|
75
|
+
if (isTypedObject(node)) {
|
|
76
|
+
const result = getContainerChildren(context.containers, node, parent);
|
|
77
|
+
if (result)
|
|
78
|
+
return {
|
|
79
|
+
children: result.children,
|
|
80
|
+
fieldName: result.container.field.name,
|
|
81
|
+
parent: result.container
|
|
82
|
+
};
|
|
58
83
|
}
|
|
59
84
|
if ("value" in node && Array.isArray(node.value) && !("_key" in node) && !("_type" in node))
|
|
60
85
|
return {
|
|
@@ -63,14 +88,6 @@ function getNodeChildren(context, node, parent) {
|
|
|
63
88
|
parent: void 0
|
|
64
89
|
};
|
|
65
90
|
}
|
|
66
|
-
function resolveNodeContainer(containers, parent, node) {
|
|
67
|
-
if (parent?.of) {
|
|
68
|
-
for (const entry of parent.of)
|
|
69
|
-
if (entry.type === node._type)
|
|
70
|
-
return "field" in entry ? entry : void 0;
|
|
71
|
-
}
|
|
72
|
-
return containers.get(node._type);
|
|
73
|
-
}
|
|
74
91
|
function getNode(snapshot, path) {
|
|
75
92
|
if (path.length === 0)
|
|
76
93
|
return;
|
|
@@ -153,6 +170,7 @@ function getParent(snapshot, path, options) {
|
|
|
153
170
|
}
|
|
154
171
|
export {
|
|
155
172
|
getChildren,
|
|
173
|
+
getContainerChildren,
|
|
156
174
|
getNode,
|
|
157
175
|
getNodeChildren,
|
|
158
176
|
getParent,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-parent.js","sources":["../../src/utils/util.is-keyed-segment.ts","../../src/paths/serialize-path.ts","../../src/utils/asserters.ts","../../src/traversal/get-children.ts","../../src/traversal/get-node.ts","../../src/engine/path/parent-path.ts","../../src/traversal/get-parent.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 {Path} from '../types/paths'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\n\n/**\n * Serialize a keyed path to a string using Sanity's bracket notation.\n *\n * - `[{_key: 'k0'}]` -> `[_key==\"k0\"]`\n * - `[{_key: 'k0'}, 'children', {_key: 's0'}]` -> `[_key==\"k0\"].children[_key==\"s0\"]`\n * - `[{_key: 't0'}, 'rows', {_key: 'r0'}, 'cells', {_key: 'c0'}, 'content', {_key: 'b0'}, 'children', {_key: 's0'}]` -> `[_key==\"t0\"].rows[_key==\"r0\"].cells[_key==\"c0\"].content[_key==\"b0\"].children[_key==\"s0\"]`\n */\nexport function serializePath(path: Path): string {\n return path.reduce<string>((result, segment, index) => {\n if (isKeyedSegment(segment)) {\n return `${result}[_key==\"${segment._key}\"]`\n }\n\n const separator = index === 0 ? '' : '.'\n return `${result}${separator}${segment}`\n }, '')\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 {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 type {\n Containers,\n RegisteredContainer,\n} from '../schema/resolve-containers'\nimport {isTypedObject} from '../utils/asserters'\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 */\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 (\n isTypedObject(node) &&\n node._type !== context.schema.block.name &&\n node._type !== context.schema.span.name\n ) {\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 {serializePath} from '../paths/serialize-path'\nimport type {RegisteredContainer} from '../schema/resolve-containers'\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: RegisteredContainer | undefined\n const resolvedPath: Path = []\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 resolvedPath.push(segment)\n const index = blockIndexMap.get(serializePath(resolvedPath))\n if (\n index !== undefined &&\n currentChildren[index]?._key === segment._key\n ) {\n node = currentChildren[index]\n } else {\n // The map can miss (unkeyed transient nodes, e.g. `{_type:'table'}`\n // inserted by a remote patch before normalize mints a key) or\n // disagree with the traversed value (snapshots that pair the live\n // map with a pre-apply value, e.g. `textPatch`). Fall back to a\n // linear scan in both cases.\n node = currentChildren.find((child) => child._key === segment._key)\n if (node && node._key !== undefined) {\n resolvedPath[resolvedPath.length - 1] = {_key: node._key}\n }\n }\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","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 {PortableTextBlock} from '@portabletext/schema'\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 * A parent has children, so it is always a `PortableTextBlock` (text block\n * or object node).\n *\n * When `match` is provided and the parent does not satisfy it, returns\n * `undefined`.\n *\n * @beta\n */\nexport function getParent<TMatch extends PortableTextBlock>(\n snapshot: TraversalSnapshot,\n path: Path,\n options: {\n match: (node: PortableTextBlock, path: Path) => node is TMatch\n },\n): {node: TMatch; path: Path} | undefined\n/**\n * @beta\n */\nexport function getParent(\n snapshot: TraversalSnapshot,\n path: Path,\n options?: {\n match?: (node: PortableTextBlock, path: Path) => boolean\n },\n): {node: PortableTextBlock; path: Path} | undefined\nexport function getParent(\n snapshot: TraversalSnapshot,\n path: Path,\n options?: {\n match?: (node: PortableTextBlock, path: Path) => boolean\n },\n): {node: PortableTextBlock; 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 const entry = getNode(snapshot, parent)\n\n if (!entry) {\n return undefined\n }\n\n const result = {node: entry.node as PortableTextBlock, path: entry.path}\n\n if (options?.match && !options.match(result.node, result.path)) {\n return undefined\n }\n\n return result\n}\n"],"names":["isKeyedSegment","segment","serializePath","path","reduce","result","index","_key","isTypedObject","object","isRecord","value","getChildren","snapshot","currentChildren","context","currentFieldName","currentPath","isRoot","currentParent","node","find","child","at","next","getNodeChildren","children","fieldName","parent","map","isTextBlock","undefined","_type","schema","block","name","span","resolved","resolveNodeContainer","containers","fieldValue","field","Array","isArray","of","entry","type","get","getNode","length","blockIndexMap","resolvedPath","i","push","hasMoreSegments","j","s","parentPath","Error","lastNodeIndex","slice","getParent","options","match"],"mappings":";AAKO,SAASA,eAAeC,SAA2C;AACxE,SAAO,OAAOA,WAAY,YAAYA,YAAY,QAAQ,UAAUA;AACtE;ACGO,SAASC,cAAcC,MAAoB;AAChD,SAAOA,KAAKC,OAAe,CAACC,QAAQJ,SAASK,UACvCN,eAAeC,OAAO,IACjB,GAAGI,MAAM,WAAWJ,QAAQM,IAAI,OA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WAAW;AAClB,UAAM,IAAIS,MAAM,gDAAgDvD,IAAI,IAAI;AAG1E,MAAIwD,gBAAgB;AACpB,WAASP,IAAIjD,KAAK8C,SAAS,GAAGG,KAAK,GAAGA;AACpC,QAAIpD,eAAeG,KAAKiD,CAAC,CAAC,KAAK,OAAOjD,KAAKiD,CAAC,KAAM,UAAU;AAC1DO,sBAAgBP;AAChB;AAAA,IACF;AAGF,MAAIO,kBAAkB;AACpB,WAAO,CAAA;AAGT,QAAMtD,SAASF,KAAKyD,MAAM,GAAGD,aAAa;AAE1C,SAAItD,OAAO4C,SAAS,KAAK,OAAO5C,OAAOA,OAAO4C,SAAS,CAAC,KAAM,WACrD5C,OAAOuD,MAAM,GAAG,EAAE,IAGpBvD;AACT;ACHO,SAASwD,UACdhD,UACAV,MACA2D,SAGmD;AACnD,MAAI3D,KAAK8C,WAAW;AAClB;AAGF,QAAMrB,SAAS6B,WAAWtD,IAAI;AAE9B,MAAIyB,OAAOqB,WAAW;AACpB;AAGF,QAAMJ,QAAQG,QAAQnC,UAAUe,MAAM;AAEtC,MAAI,CAACiB;AACH;AAGF,QAAMxC,SAAS;AAAA,IAACe,MAAMyB,MAAMzB;AAAAA,IAA2BjB,MAAM0C,MAAM1C;AAAAA,EAAAA;AAEnE,MAAI2D,EAAAA,SAASC,SAAS,CAACD,QAAQC,MAAM1D,OAAOe,MAAMf,OAAOF,IAAI;AAI7D,WAAOE;AACT;"}
|
|
1
|
+
{"version":3,"file":"get-parent.js","sources":["../../src/utils/util.is-keyed-segment.ts","../../src/paths/serialize-path.ts","../../src/utils/asserters.ts","../../src/traversal/get-container-children.ts","../../src/traversal/get-children.ts","../../src/traversal/get-node.ts","../../src/engine/path/parent-path.ts","../../src/traversal/get-parent.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 {Path} from '../types/paths'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\n\n/**\n * Serialize a keyed path to a string using Sanity's bracket notation.\n *\n * - `[{_key: 'k0'}]` -> `[_key==\"k0\"]`\n * - `[{_key: 'k0'}, 'children', {_key: 's0'}]` -> `[_key==\"k0\"].children[_key==\"s0\"]`\n * - `[{_key: 't0'}, 'rows', {_key: 'r0'}, 'cells', {_key: 'c0'}, 'content', {_key: 'b0'}, 'children', {_key: 's0'}]` -> `[_key==\"t0\"].rows[_key==\"r0\"].cells[_key==\"c0\"].content[_key==\"b0\"].children[_key==\"s0\"]`\n */\nexport function serializePath(path: Path): string {\n return path.reduce<string>((result, segment, index) => {\n if (isKeyedSegment(segment)) {\n return `${result}[_key==\"${segment._key}\"]`\n }\n\n const separator = index === 0 ? '' : '.'\n return `${result}${separator}${segment}`\n }, '')\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 {Node} from '../engine/interfaces/node'\nimport type {\n Containers,\n RegisteredContainer,\n} from '../schema/resolve-containers'\n\n/**\n * Resolve a container node's editable child array.\n *\n * Returns `{children, container}` for a node registered as a container:\n * `children` is the node's editable child array, and `container` is the\n * node's own container registration. Read `container.field.name` for the\n * path segment that reaches `children`, and thread `container` back in as\n * `parent` when descending into them.\n *\n * Returns `undefined` for anything that is not a container: text blocks,\n * spans, leaves, and unregistered objects. It is node-based and resolves\n * in one step with no path re-walk, so recursive descent over containers\n * is linear in nesting depth. The caller seeds the document root from\n * `context.value` itself.\n *\n * @beta\n */\nexport function getContainerChildren(\n containers: Containers,\n node: Node,\n parent?: RegisteredContainer,\n):\n | {\n children: Array<Node>\n container: RegisteredContainer\n }\n | undefined {\n const resolved = resolveNodeContainer(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 container: resolved,\n }\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 {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 {serializePath} from '../paths/serialize-path'\nimport type {\n Containers,\n RegisteredContainer,\n} from '../schema/resolve-containers'\nimport {isTypedObject} from '../utils/asserters'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {getContainerChildren} from './get-container-children'\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 // Resolve via `blockIndexMap` (O(1)) and fall back to a linear scan on a\n // miss or when the snapshot's map disagrees with the value, mirroring\n // `getNode`. The candidate path is this segment's full keyed path.\n const candidatePath: Path = isRoot\n ? [{_key: segment._key}]\n : [...currentPath, currentFieldName, {_key: segment._key}]\n const index = snapshot.blockIndexMap.get(serializePath(candidatePath))\n node =\n index !== undefined && currentChildren[index]?._key === segment._key\n ? currentChildren[index]\n : 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 * Internal descent kernel shared by the positional traversal utilities\n * (`getChildren`, `getNode`, `getNodes`, `getAncestors`); it folds the\n * text-block, container, and root-document cases. Public consumers that\n * only need to descend containers use {@link getContainerChildren}.\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 (isTypedObject(node)) {\n const result = getContainerChildren(context.containers, node, parent)\n\n if (result) {\n return {\n children: result.children,\n fieldName: result.container.field.name,\n parent: result.container,\n }\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","import type {Node} from '../engine/interfaces/node'\nimport type {Path} from '../engine/interfaces/path'\nimport {serializePath} from '../paths/serialize-path'\nimport type {RegisteredContainer} from '../schema/resolve-containers'\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: RegisteredContainer | undefined\n const resolvedPath: Path = []\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 resolvedPath.push(segment)\n const index = blockIndexMap.get(serializePath(resolvedPath))\n if (\n index !== undefined &&\n currentChildren[index]?._key === segment._key\n ) {\n node = currentChildren[index]\n } else {\n // The map can miss (unkeyed transient nodes, e.g. `{_type:'table'}`\n // inserted by a remote patch before normalize mints a key) or\n // disagree with the traversed value (snapshots that pair the live\n // map with a pre-apply value, e.g. `textPatch`). Fall back to a\n // linear scan in both cases.\n node = currentChildren.find((child) => child._key === segment._key)\n if (node && node._key !== undefined) {\n resolvedPath[resolvedPath.length - 1] = {_key: node._key}\n }\n }\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","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 {PortableTextBlock} from '@portabletext/schema'\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 * A parent has children, so it is always a `PortableTextBlock` (text block\n * or object node).\n *\n * When `match` is provided and the parent does not satisfy it, returns\n * `undefined`.\n *\n * @beta\n */\nexport function getParent<TMatch extends PortableTextBlock>(\n snapshot: TraversalSnapshot,\n path: Path,\n options: {\n match: (node: PortableTextBlock, path: Path) => node is TMatch\n },\n): {node: TMatch; path: Path} | undefined\n/**\n * @beta\n */\nexport function getParent(\n snapshot: TraversalSnapshot,\n path: Path,\n options?: {\n match?: (node: PortableTextBlock, path: Path) => boolean\n },\n): {node: PortableTextBlock; path: Path} | undefined\nexport function getParent(\n snapshot: TraversalSnapshot,\n path: Path,\n options?: {\n match?: (node: PortableTextBlock, path: Path) => boolean\n },\n): {node: PortableTextBlock; 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 const entry = getNode(snapshot, parent)\n\n if (!entry) {\n return undefined\n }\n\n const result = {node: entry.node as PortableTextBlock, path: entry.path}\n\n if (options?.match && !options.match(result.node, result.path)) {\n return undefined\n }\n\n return result\n}\n"],"names":["isKeyedSegment","segment","serializePath","path","reduce","result","index","_key","isTypedObject","object","isRecord","value","getContainerChildren","containers","node","parent","resolved","resolveNodeContainer","fieldValue","field","name","Array","isArray","children","container","of","entry","type","_type","get","getChildren","snapshot","currentChildren","context","currentFieldName","currentPath","isRoot","currentParent","candidatePath","blockIndexMap","undefined","find","child","at","next","getNodeChildren","fieldName","map","isTextBlock","getNode","length","resolvedPath","i","push","hasMoreSegments","j","s","parentPath","Error","lastNodeIndex","slice","getParent","options","match"],"mappings":";AAKO,SAASA,eAAeC,SAA2C;AACxE,SAAO,OAAOA,WAAY,YAAYA,YAAY,QAAQ,UAAUA;AACtE;ACGO,SAASC,cAAcC,MAAoB;AAChD,SAAOA,KAAKC,OAAe,CAACC,QAAQJ,SAASK,UACvCN,eAAeC,OAAO,IACjB,GAAGI,MAAM,WAAWJ,QAAQM,IAAI,OAIlC,GAAGF,MAAM,GADEC,UAAU,IAAI,KAAK,GACT,GAAGL,OAAO,IACrC,EAAE;AACP;ACjBO,SAASO,cAAcC,QAAwC;AACpE,SAAOC,SAASD,MAAM,KAAK,OAAOA,OAAO,SAAa;AACxD;AAEO,SAASC,SAASC,OAAkD;AACzE,SAAO,CAAC,CAACA,UAAU,OAAOA,SAAU,YAAY,OAAOA,SAAU;AACnE;ACeO,SAASC,qBACdC,YACAC,MACAC,QAMY;AACZ,QAAMC,WAAWC,qBAAqBJ,YAAYE,QAAQD,IAAI;AAE9D,MAAI,CAACE;AACH;AAGF,QAAME,aA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IL,WAAO;AAAA,MAACA;AAAAA,MAAMX,MAAMgD;AAAAA,IAAAA;AACtB;ACxFO,SAASM,WAAWtD,MAAkB;AAC3C,MAAIA,KAAK+C,WAAW;AAClB,UAAM,IAAIQ,MAAM,gDAAgDvD,IAAI,IAAI;AAG1E,MAAIwD,gBAAgB;AACpB,WAASP,IAAIjD,KAAK+C,SAAS,GAAGE,KAAK,GAAGA;AACpC,QAAIpD,eAAeG,KAAKiD,CAAC,CAAC,KAAK,OAAOjD,KAAKiD,CAAC,KAAM,UAAU;AAC1DO,sBAAgBP;AAChB;AAAA,IACF;AAGF,MAAIO,kBAAkB;AACpB,WAAO,CAAA;AAGT,QAAMtD,SAASF,KAAKyD,MAAM,GAAGD,aAAa;AAE1C,SAAItD,OAAO6C,SAAS,KAAK,OAAO7C,OAAOA,OAAO6C,SAAS,CAAC,KAAM,WACrD7C,OAAOuD,MAAM,GAAG,EAAE,IAGpBvD;AACT;ACHO,SAASwD,UACd9B,UACA5B,MACA2D,SAGmD;AACnD,MAAI3D,KAAK+C,WAAW;AAClB;AAGF,QAAMnC,SAAS0C,WAAWtD,IAAI;AAE9B,MAAIY,OAAOmC,WAAW;AACpB;AAGF,QAAMxB,QAAQuB,QAAQlB,UAAUhB,MAAM;AAEtC,MAAI,CAACW;AACH;AAGF,QAAMrB,SAAS;AAAA,IAACS,MAAMY,MAAMZ;AAAAA,IAA2BX,MAAMuB,MAAMvB;AAAAA,EAAAA;AAEnE,MAAI2D,EAAAA,SAASC,SAAS,CAACD,QAAQC,MAAM1D,OAAOS,MAAMT,OAAOF,IAAI;AAI7D,WAAOE;AACT;"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { rangeEdges, comparePoints$1 as comparePoints, isInline, isSpanNode, isObject, getEnclosingBlock, resolveContainerAt, hasNode, getBlock, getNodes, getSibling, getPathSubSchema, isTextBlockNode, isEditableContainer } from "./get-path-sub-schema.js";
|
|
2
|
-
import {
|
|
2
|
+
import { getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint as getSelectionEndPoint$1, sliceBlocks, isSelectionCollapsed as isSelectionCollapsed$1, getBlockStartPoint, getBlockEndPoint, isEqualSelectionPoints, blockOffsetToSpanSelectionPoint, spanSelectionPointToBlockOffset, isListBlock } from "./util.slice-blocks.js";
|
|
3
3
|
import { getNode, getNodeChildren, isKeyedSegment, getParent, getChildren, parentPath } from "./get-parent.js";
|
|
4
4
|
import { isSpan, isTextBlock } from "@portabletext/schema";
|
|
5
5
|
function rangesOverlap(rangeA, rangeB, root) {
|
|
6
6
|
const [startA, endA] = rangeEdges(rangeA, root), [startB, endB] = rangeEdges(rangeB, root);
|
|
7
7
|
return comparePoints(startA, endB, root) <= 0 && comparePoints(startB, endA, root) <= 0;
|
|
8
8
|
}
|
|
9
|
-
const isSelectionCollapsed = (snapshot) => isSelectionCollapsed$1(snapshot.context.selection);
|
|
10
9
|
function getInline(snapshot, path) {
|
|
11
10
|
const entry = getNode(snapshot, path);
|
|
12
11
|
if (!(!entry || !isInline(snapshot, entry.path)) && !(!isSpanNode({
|
|
@@ -252,7 +251,7 @@ function isOverlappingSelection(selection) {
|
|
|
252
251
|
});
|
|
253
252
|
};
|
|
254
253
|
}
|
|
255
|
-
const isSelectionExpanded$1 = (snapshot) => snapshot.context.selection !== null && !isSelectionCollapsed(snapshot), getSelectedBlocks = (snapshot) => {
|
|
254
|
+
const isSelectionCollapsed = (snapshot) => isSelectionCollapsed$1(snapshot.context.selection), isSelectionExpanded$1 = (snapshot) => snapshot.context.selection !== null && !isSelectionCollapsed(snapshot), getSelectedBlocks = (snapshot) => {
|
|
256
255
|
const selection = snapshot.context.selection;
|
|
257
256
|
if (!selection)
|
|
258
257
|
return [];
|