@portabletext/editor 6.6.4 → 7.0.1
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 +683 -512
- package/lib/_chunks-dts/behavior.types.action.d.ts.map +1 -1
- package/lib/_chunks-dts/resolve-containers.d.ts +688 -0
- package/lib/_chunks-dts/resolve-containers.d.ts.map +1 -0
- package/lib/_chunks-es/get-ancestor.js +192 -0
- package/lib/_chunks-es/get-ancestor.js.map +1 -0
- package/lib/_chunks-es/get-first-child.js +130 -0
- package/lib/_chunks-es/get-first-child.js.map +1 -0
- package/lib/_chunks-es/get-path-sub-schema.js +266 -0
- package/lib/_chunks-es/get-path-sub-schema.js.map +1 -0
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +1021 -0
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -0
- package/lib/_chunks-es/use-editor.js +4 -13
- package/lib/_chunks-es/use-editor.js.map +1 -1
- package/lib/_chunks-es/util.is-empty-text-block.js +15 -0
- package/lib/_chunks-es/util.is-empty-text-block.js.map +1 -0
- package/lib/_chunks-es/util.slice-blocks.js +347 -198
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/behaviors/index.d.ts +2 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.js +5457 -5611
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.ts +18 -2
- package/lib/plugins/index.d.ts.map +1 -1
- package/lib/plugins/index.js +18 -2
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.ts +220 -5
- package/lib/selectors/index.d.ts.map +1 -1
- package/lib/selectors/index.js +62 -71
- package/lib/selectors/index.js.map +1 -1
- package/lib/traversal/index.d.ts +235 -0
- package/lib/traversal/index.d.ts.map +1 -0
- package/lib/traversal/index.js +30 -0
- package/lib/traversal/index.js.map +1 -0
- package/lib/utils/index.d.ts +11 -57
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +36 -107
- package/lib/utils/index.js.map +1 -1
- package/package.json +19 -17
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +0 -806
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +0 -1
- package/lib/_chunks-es/util.slice-text-block.js +0 -60
- package/lib/_chunks-es/util.slice-text-block.js.map +0 -1
package/lib/selectors/index.js
CHANGED
|
@@ -1,42 +1,29 @@
|
|
|
1
|
-
import { getSelectionStartPoint, getSelectionEndPoint, getFocusTextBlock,
|
|
2
|
-
import { getActiveAnnotations, getActiveListItem, getActiveStyle, getCaretWordSelection, getFocusBlockObject, getFocusChild, getFocusInlineObject, getFocusListBlock, getFocusSpan, getLastBlock, getMarkState, getNextBlock, getNextInlineObject, getNextSpan, getPreviousBlock, getPreviousInlineObject, getPreviousSpan, getSelectedBlocks, getSelectedSpans, getSelectedTextBlocks, getSelectedValue, getSelectionEndBlock, getSelectionEndChild, getSelectionStartBlock, getSelectionStartChild, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isSelectingEntireBlocks, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { getInline, getSelectionStartPoint, getSelectionEndPoint, getFocusTextBlock, getSelectionText, comparePaths } from "../_chunks-es/selector.is-at-the-start-of-block.js";
|
|
2
|
+
import { compareApplicableSchema, getActiveAnnotations, getActiveListItem, getActiveStyle, getApplicableSchema, getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusInlineObject, getFocusListBlock, getFocusSpan, getFragment, getLastBlock, getMarkState, getNextBlock, getNextInlineObject, getNextSpan, getPreviousBlock, getPreviousInlineObject, getPreviousSpan, getSelectedBlocks, getSelectedSpans, getSelectedTextBlocks, getSelectedValue, getSelectionEndBlock, getSelectionEndChild, getSelectionStartBlock, getSelectionStartChild, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isSelectingEntireBlocks, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-at-the-start-of-block.js";
|
|
3
|
+
import { getEnclosingBlock, parentPath } from "../_chunks-es/get-path-sub-schema.js";
|
|
4
|
+
import { isSpan, isTextBlock } from "@portabletext/schema";
|
|
5
|
+
import { spanSelectionPointToBlockOffset, getBlockEndPoint, getSelectionEndPoint as getSelectionEndPoint$1, getBlockStartPoint, getSelectionStartPoint as getSelectionStartPoint$1 } from "../_chunks-es/util.slice-blocks.js";
|
|
6
|
+
import { getChildren, isKeyedSegment, isObjectNode } from "../_chunks-es/get-ancestor.js";
|
|
5
7
|
const getAnchorBlock = (snapshot) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return node && key ? {
|
|
10
|
-
node,
|
|
11
|
-
path: [{
|
|
12
|
-
_key: key
|
|
13
|
-
}]
|
|
14
|
-
} : void 0;
|
|
15
|
-
}, getAnchorTextBlock = (snapshot) => {
|
|
16
|
-
const anchorBlock = getAnchorBlock(snapshot);
|
|
17
|
-
return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node) ? {
|
|
18
|
-
node: anchorBlock.node,
|
|
19
|
-
path: anchorBlock.path
|
|
20
|
-
} : void 0;
|
|
8
|
+
const selection = snapshot.context.selection;
|
|
9
|
+
if (selection)
|
|
10
|
+
return getEnclosingBlock(snapshot, selection.anchor.path);
|
|
21
11
|
}, getAnchorChild = (snapshot) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (!anchorBlock)
|
|
26
|
-
return;
|
|
27
|
-
const key = getChildKeyFromSelectionPoint(snapshot.context.selection.anchor), node = key ? anchorBlock.node.children.find((span) => span._key === key) : void 0;
|
|
28
|
-
return node && key ? {
|
|
29
|
-
node,
|
|
30
|
-
path: [...anchorBlock.path, "children", {
|
|
31
|
-
_key: key
|
|
32
|
-
}]
|
|
33
|
-
} : void 0;
|
|
12
|
+
const selection = snapshot.context.selection;
|
|
13
|
+
if (selection)
|
|
14
|
+
return getInline(snapshot, selection.anchor.path);
|
|
34
15
|
}, getAnchorSpan = (snapshot) => {
|
|
35
16
|
const anchorChild = getAnchorChild(snapshot);
|
|
36
17
|
return anchorChild && isSpan(snapshot.context, anchorChild.node) ? {
|
|
37
18
|
node: anchorChild.node,
|
|
38
19
|
path: anchorChild.path
|
|
39
20
|
} : void 0;
|
|
21
|
+
}, getAnchorTextBlock = (snapshot) => {
|
|
22
|
+
const anchorBlock = getAnchorBlock(snapshot);
|
|
23
|
+
return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node) ? {
|
|
24
|
+
node: anchorBlock.node,
|
|
25
|
+
path: anchorBlock.path
|
|
26
|
+
} : void 0;
|
|
40
27
|
}, getBlockOffsets = (snapshot) => {
|
|
41
28
|
if (!snapshot.context.selection)
|
|
42
29
|
return;
|
|
@@ -44,66 +31,63 @@ const getAnchorBlock = (snapshot) => {
|
|
|
44
31
|
if (!selectionStartPoint || !selectionEndPoint)
|
|
45
32
|
return;
|
|
46
33
|
const start = spanSelectionPointToBlockOffset({
|
|
47
|
-
|
|
34
|
+
snapshot,
|
|
48
35
|
selectionPoint: selectionStartPoint
|
|
49
36
|
}), end = spanSelectionPointToBlockOffset({
|
|
50
|
-
|
|
37
|
+
snapshot,
|
|
51
38
|
selectionPoint: selectionEndPoint
|
|
52
39
|
});
|
|
53
40
|
return start && end ? {
|
|
54
41
|
start,
|
|
55
42
|
end
|
|
56
43
|
} : void 0;
|
|
57
|
-
}, getFirstBlock = (snapshot) => {
|
|
58
|
-
const node = snapshot.context.value[0];
|
|
59
|
-
return node ? {
|
|
60
|
-
node,
|
|
61
|
-
path: [{
|
|
62
|
-
_key: node._key
|
|
63
|
-
}]
|
|
64
|
-
} : void 0;
|
|
65
44
|
}, getNextInlineObjects = (snapshot) => {
|
|
66
|
-
const
|
|
67
|
-
if (!
|
|
45
|
+
const point = getSelectionEndPoint(snapshot);
|
|
46
|
+
if (!point)
|
|
68
47
|
return [];
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
48
|
+
const endSegment = point.path.at(-1), endKey = isKeyedSegment(endSegment) ? endSegment._key : void 0;
|
|
49
|
+
if (!endKey)
|
|
50
|
+
return [];
|
|
51
|
+
const children = getChildren(snapshot, parentPath(point.path)), inlineObjects = [];
|
|
52
|
+
let endFound = !1;
|
|
53
|
+
for (const child of children) {
|
|
54
|
+
const segment = child.path.at(-1);
|
|
55
|
+
if ((isKeyedSegment(segment) ? segment._key : void 0) === endKey) {
|
|
56
|
+
endFound = !0;
|
|
74
57
|
continue;
|
|
75
58
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
});
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
59
|
+
endFound && isObjectNode({
|
|
60
|
+
schema: snapshot.context.schema
|
|
61
|
+
}, child.node) && inlineObjects.push({
|
|
62
|
+
node: child.node,
|
|
63
|
+
path: child.path
|
|
64
|
+
});
|
|
85
65
|
}
|
|
86
66
|
return inlineObjects;
|
|
87
67
|
}, getPreviousInlineObjects = (snapshot) => {
|
|
88
|
-
const
|
|
89
|
-
if (!
|
|
68
|
+
const point = getSelectionStartPoint(snapshot);
|
|
69
|
+
if (!point)
|
|
90
70
|
return [];
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
71
|
+
const startSegment = point.path.at(-1), startKey = isKeyedSegment(startSegment) ? startSegment._key : void 0;
|
|
72
|
+
if (!startKey)
|
|
73
|
+
return [];
|
|
74
|
+
const children = getChildren(snapshot, parentPath(point.path)), inlineObjects = [];
|
|
75
|
+
for (const child of children) {
|
|
76
|
+
const segment = child.path.at(-1);
|
|
77
|
+
if ((isKeyedSegment(segment) ? segment._key : void 0) === startKey)
|
|
94
78
|
break;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
79
|
+
isObjectNode({
|
|
80
|
+
schema: snapshot.context.schema
|
|
81
|
+
}, child.node) && inlineObjects.push({
|
|
82
|
+
node: child.node,
|
|
83
|
+
path: child.path
|
|
100
84
|
});
|
|
101
85
|
}
|
|
102
86
|
return inlineObjects;
|
|
103
87
|
}, getSelection = (snapshot) => snapshot.context.selection, getBlockTextAfter = (snapshot) => {
|
|
104
88
|
if (!snapshot.context.selection)
|
|
105
89
|
return "";
|
|
106
|
-
const endPoint = getSelectionEndPoint$1(snapshot.context.selection), block =
|
|
90
|
+
const endPoint = getSelectionEndPoint$1(snapshot.context.selection), block = getFocusTextBlock({
|
|
107
91
|
...snapshot,
|
|
108
92
|
context: {
|
|
109
93
|
...snapshot.context,
|
|
@@ -120,7 +104,6 @@ const getAnchorBlock = (snapshot) => {
|
|
|
120
104
|
block
|
|
121
105
|
});
|
|
122
106
|
return getSelectionText({
|
|
123
|
-
...snapshot,
|
|
124
107
|
context: {
|
|
125
108
|
...snapshot.context,
|
|
126
109
|
selection: {
|
|
@@ -132,7 +115,7 @@ const getAnchorBlock = (snapshot) => {
|
|
|
132
115
|
}, getBlockTextBefore = (snapshot) => {
|
|
133
116
|
if (!snapshot.context.selection)
|
|
134
117
|
return "";
|
|
135
|
-
const startPoint = getSelectionStartPoint$1(snapshot.context.selection), block =
|
|
118
|
+
const startPoint = getSelectionStartPoint$1(snapshot.context.selection), block = getFocusTextBlock({
|
|
136
119
|
...snapshot,
|
|
137
120
|
context: {
|
|
138
121
|
...snapshot.context,
|
|
@@ -149,7 +132,6 @@ const getAnchorBlock = (snapshot) => {
|
|
|
149
132
|
block
|
|
150
133
|
});
|
|
151
134
|
return getSelectionText({
|
|
152
|
-
...snapshot,
|
|
153
135
|
context: {
|
|
154
136
|
...snapshot.context,
|
|
155
137
|
selection: {
|
|
@@ -159,6 +141,12 @@ const getAnchorBlock = (snapshot) => {
|
|
|
159
141
|
}
|
|
160
142
|
});
|
|
161
143
|
}, getValue = (snapshot) => snapshot.context.value;
|
|
144
|
+
function comparePoints(snapshot, pointA, pointB) {
|
|
145
|
+
const pathComparison = comparePaths(pointA.path, pointB.path, {
|
|
146
|
+
children: snapshot.context.value
|
|
147
|
+
});
|
|
148
|
+
return pathComparison !== 0 ? pathComparison : pointA.offset < pointB.offset ? -1 : pointA.offset > pointB.offset ? 1 : 0;
|
|
149
|
+
}
|
|
162
150
|
function isPointAfterSelection(point) {
|
|
163
151
|
return (snapshot) => {
|
|
164
152
|
if (!snapshot.context.selection)
|
|
@@ -176,6 +164,7 @@ function isPointBeforeSelection(point) {
|
|
|
176
164
|
};
|
|
177
165
|
}
|
|
178
166
|
export {
|
|
167
|
+
compareApplicableSchema,
|
|
179
168
|
getActiveAnnotations,
|
|
180
169
|
getActiveListItem,
|
|
181
170
|
getActiveStyle,
|
|
@@ -183,6 +172,7 @@ export {
|
|
|
183
172
|
getAnchorChild,
|
|
184
173
|
getAnchorSpan,
|
|
185
174
|
getAnchorTextBlock,
|
|
175
|
+
getApplicableSchema,
|
|
186
176
|
getBlockOffsets,
|
|
187
177
|
getBlockTextAfter,
|
|
188
178
|
getBlockTextBefore,
|
|
@@ -195,6 +185,7 @@ export {
|
|
|
195
185
|
getFocusListBlock,
|
|
196
186
|
getFocusSpan,
|
|
197
187
|
getFocusTextBlock,
|
|
188
|
+
getFragment,
|
|
198
189
|
getLastBlock,
|
|
199
190
|
getMarkState,
|
|
200
191
|
getNextBlock,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-first-block.ts","../../src/selectors/selector.get-next-inline-objects.ts","../../src/selectors/selector.get-previous-inline-objects.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-text-after.ts","../../src/selectors/selector.get-text-before.ts","../../src/selectors/selector.get-value.ts","../../src/selectors/selector.is-point-after-selection.ts","../../src/selectors/selector.is-point-before-selection.ts"],"sourcesContent":["import type {PortableTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.anchor)\n const index = key ? snapshot.blockIndexMap.get(key) : undefined\n const node =\n index !== undefined ? snapshot.context.value.at(index) : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {isTextBlock, type PortableTextTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {PortableTextObject, PortableTextSpan} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getChildKeyFromSelectionPoint} from '../utils/util.selection-point'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.anchor)\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import {isSpan, type PortableTextSpan} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n {node: PortableTextSpan; path: ChildPath} | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isSpan(snapshot.context, anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport {spanSelectionPointToBlockOffset} from '../utils/util.block-offset'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {PortableTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport const getFirstBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const node = snapshot.context.value[0]\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n","import type {PortableTextObject} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isSpanNode} from '../slate/node/is-span-node'\nimport type {ChildPath} from '../types/paths'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\n\n/**\n * @public\n */\nexport const getNextInlineObjects: EditorSelector<\n Array<{\n node: PortableTextObject\n path: ChildPath\n }>\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n const selectionEndPointChildKey =\n selectionEndPoint && isKeyedSegment(selectionEndPoint.path[2])\n ? selectionEndPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionEndPointChildKey) {\n return []\n }\n\n let endPointChildFound = false\n const inlineObjects: Array<{\n node: PortableTextObject\n path: ChildPath\n }> = []\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionEndPointChildKey) {\n endPointChildFound = true\n continue\n }\n\n if (!isSpanNode(snapshot.context, child) && endPointChildFound) {\n inlineObjects.push({\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n })\n break\n }\n }\n\n return inlineObjects\n}\n","import type {PortableTextObject} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isSpanNode} from '../slate/node/is-span-node'\nimport type {ChildPath} from '../types/paths'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getPreviousInlineObjects: EditorSelector<\n Array<{\n node: PortableTextObject\n path: ChildPath\n }>\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartPointChildKey =\n selectionStartPoint && isKeyedSegment(selectionStartPoint.path[2])\n ? selectionStartPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionStartPointChildKey) {\n return []\n }\n\n const inlineObjects: Array<{\n node: PortableTextObject\n path: ChildPath\n }> = []\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionStartPointChildKey) {\n break\n }\n\n if (!isSpanNode(snapshot.context, child)) {\n inlineObjects.push({\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n })\n }\n }\n\n return inlineObjects\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockEndPoint} from '../utils/util.get-block-end-point'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getFocusBlock} from './selector.get-focus-block'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @public\n */\nexport const getBlockTextAfter: EditorSelector<string> = (snapshot) => {\n if (!snapshot.context.selection) {\n return ''\n }\n\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n const block = getFocusBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endPoint,\n },\n },\n })\n\n if (!block) {\n return ''\n }\n\n const endOfBlock = getBlockEndPoint({\n context: snapshot.context,\n block,\n })\n\n return getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endOfBlock,\n },\n },\n })\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getFocusBlock} from './selector.get-focus-block'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @public\n */\nexport const getBlockTextBefore: EditorSelector<string> = (snapshot) => {\n if (!snapshot.context.selection) {\n return ''\n }\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const block = getFocusBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\n\n if (!block) {\n return ''\n }\n\n const startOfBlock = getBlockStartPoint({\n context: snapshot.context,\n block,\n })\n\n return getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startOfBlock,\n focus: startPoint,\n },\n },\n })\n}\n","import type {PortableTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {comparePoints} from '../utils/util.compare-points'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\n\n/**\n * @public\n */\nexport function isPointAfterSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n\n return comparePoints(snapshot, point, endPoint) === 1\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {comparePoints} from '../utils/util.compare-points'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\n\n/**\n * @public\n */\nexport function isPointBeforeSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n\n return comparePoints(snapshot, point, startPoint) === -1\n }\n}\n"],"names":["getAnchorBlock","snapshot","context","selection","key","getBlockKeyFromSelectionPoint","anchor","index","blockIndexMap","get","undefined","node","value","at","path","_key","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","getChildKeyFromSelectionPoint","children","find","span","getAnchorSpan","anchorChild","isSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","spanSelectionPointToBlockOffset","selectionPoint","end","getFirstBlock","getNextInlineObjects","focusTextBlock","getFocusTextBlock","selectionEndPointChildKey","isKeyedSegment","endPointChildFound","inlineObjects","child","isSpanNode","push","getPreviousInlineObjects","selectionStartPointChildKey","getSelection","getBlockTextAfter","endPoint","block","getFocusBlock","focus","endOfBlock","getBlockEndPoint","getSelectionText","getBlockTextBefore","startPoint","startOfBlock","getBlockStartPoint","getValue","isPointAfterSelection","point","comparePoints","isPointBeforeSelection"],"mappings":";;;;AAQO,MAAMA,iBAERC,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,8BAA8BJ,SAASC,QAAQC,UAAUG,MAAM,GACrEC,QAAQH,MAAMH,SAASO,cAAcC,IAAIL,GAAG,IAAIM,QAChDC,OACJJ,UAAUG,SAAYT,SAASC,QAAQU,MAAMC,GAAGN,KAAK,IAAIG;AAE3D,SAAOC,QAAQP,MAAM;AAAA,IAACO;AAAAA,IAAMG,MAAM,CAAC;AAAA,MAACC,MAAMX;AAAAA,IAAAA,CAAI;AAAA,EAAA,IAAKM;AACrD,GCbaM,qBAERf,CAAAA,aAAa;AAChB,QAAMgB,cAAcjB,eAAeC,QAAQ;AAE3C,SAAOgB,eAAeC,YAAYjB,SAASC,SAASe,YAAYN,IAAI,IAChE;AAAA,IAACA,MAAMM,YAAYN;AAAAA,IAAMG,MAAMG,YAAYH;AAAAA,EAAAA,IAC3CJ;AACN,GCPaS,iBAMRlB,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMc,cAAcD,mBAAmBf,QAAQ;AAE/C,MAAI,CAACgB;AACH;AAGF,QAAMb,MAAMgB,8BAA8BnB,SAASC,QAAQC,UAAUG,MAAM,GAErEK,OAAOP,MACTa,YAAYN,KAAKU,SAAS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A,EACF,CACD;AACH,GCvCaG,WACX7D,CAAAA,aAEOA,SAASC,QAAQU;ACDnB,SAASmD,sBACdC,OACyB;AACzB,SAAQ/D,CAAAA,aAAa;AACnB,QAAI,CAACA,SAASC,QAAQC;AACpB,aAAO;AAGT,UAAMgD,WAAWpB,uBAAqB9B,SAASC,QAAQC,SAAS;AAEhE,WAAO8D,cAAchE,UAAU+D,OAAOb,QAAQ,MAAM;AAAA,EACtD;AACF;ACZO,SAASe,uBACdF,OACyB;AACzB,SAAQ/D,CAAAA,aAAa;AACnB,QAAI,CAACA,SAASC,QAAQC;AACpB,aAAO;AAGT,UAAMwD,aAAa9B,yBAAuB5B,SAASC,QAAQC,SAAS;AAEpE,WAAO8D,cAAchE,UAAU+D,OAAOL,UAAU,MAAM;AAAA,EACxD;AACF;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-next-inline-objects.ts","../../src/selectors/selector.get-previous-inline-objects.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-text-after.ts","../../src/selectors/selector.get-text-before.ts","../../src/selectors/selector.get-value.ts","../../src/utils/util.compare-points.ts","../../src/selectors/selector.is-point-after-selection.ts","../../src/selectors/selector.is-point-before-selection.ts"],"sourcesContent":["import type {PortableTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getEnclosingBlock} from '../node-traversal/get-enclosing-block'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * Returns the block containing the anchor selection, resolved at any depth.\n *\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const selection = snapshot.context.selection\n\n if (!selection) {\n return undefined\n }\n\n return getEnclosingBlock(snapshot, selection.anchor.path)\n}\n","import type {PortableTextObject, PortableTextSpan} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getInline} from '../node-traversal/get-inline'\nimport type {ChildPath} from '../types/paths'\n\n/**\n * Returns the child (span or inline object) containing the anchor selection,\n * resolved at any depth.\n *\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const selection = snapshot.context.selection\n\n if (!selection) {\n return undefined\n }\n\n return getInline(snapshot, selection.anchor.path)\n}\n","import {isSpan, type PortableTextSpan} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * Returns the span containing the anchor selection, resolved at any depth.\n *\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n {node: PortableTextSpan; path: ChildPath} | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isSpan(snapshot.context, anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import {isTextBlock, type PortableTextTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * Returns the text block containing the anchor selection, resolved at any\n * depth.\n *\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport {spanSelectionPointToBlockOffset} from '../utils/util.block-offset'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = spanSelectionPointToBlockOffset({\n snapshot,\n selectionPoint: selectionStartPoint,\n })\n const end = spanSelectionPointToBlockOffset({\n snapshot,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {PortableTextObject} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildren} from '../node-traversal/get-children'\nimport {isObjectNode} from '../slate/node/is-object-node'\nimport {parentPath} from '../slate/path/parent-path'\nimport type {ChildPath} from '../types/paths'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\n\n/**\n * Returns all inline objects after the selection end within the same text\n * block, resolved at any depth.\n *\n * @public\n */\nexport const getNextInlineObjects: EditorSelector<\n Array<{node: PortableTextObject; path: ChildPath}>\n> = (snapshot) => {\n const point = getSelectionEndPoint(snapshot)\n\n if (!point) {\n return []\n }\n\n const endSegment = point.path.at(-1)\n const endKey = isKeyedSegment(endSegment) ? endSegment._key : undefined\n\n if (!endKey) {\n return []\n }\n\n const children = getChildren(snapshot, parentPath(point.path))\n const inlineObjects: Array<{node: PortableTextObject; path: ChildPath}> = []\n let endFound = false\n\n for (const child of children) {\n const segment = child.path.at(-1)\n const childKey = isKeyedSegment(segment) ? segment._key : undefined\n\n if (childKey === endKey) {\n endFound = true\n continue\n }\n\n if (\n endFound &&\n isObjectNode({schema: snapshot.context.schema}, child.node)\n ) {\n inlineObjects.push({\n node: child.node,\n path: child.path,\n })\n }\n }\n\n return inlineObjects\n}\n","import type {PortableTextObject} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildren} from '../node-traversal/get-children'\nimport {isObjectNode} from '../slate/node/is-object-node'\nimport {parentPath} from '../slate/path/parent-path'\nimport type {ChildPath} from '../types/paths'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * Returns all inline objects before the selection start within the same text\n * block, resolved at any depth.\n *\n * @public\n */\nexport const getPreviousInlineObjects: EditorSelector<\n Array<{node: PortableTextObject; path: ChildPath}>\n> = (snapshot) => {\n const point = getSelectionStartPoint(snapshot)\n\n if (!point) {\n return []\n }\n\n const startSegment = point.path.at(-1)\n const startKey = isKeyedSegment(startSegment) ? startSegment._key : undefined\n\n if (!startKey) {\n return []\n }\n\n const children = getChildren(snapshot, parentPath(point.path))\n const inlineObjects: Array<{node: PortableTextObject; path: ChildPath}> = []\n\n for (const child of children) {\n const segment = child.path.at(-1)\n const childKey = isKeyedSegment(segment) ? segment._key : undefined\n\n if (childKey === startKey) {\n break\n }\n\n if (isObjectNode({schema: snapshot.context.schema}, child.node)) {\n inlineObjects.push({\n node: child.node,\n path: child.path,\n })\n }\n }\n\n return inlineObjects\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockEndPoint} from '../utils/util.get-block-end-point'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @public\n */\nexport const getBlockTextAfter: EditorSelector<string> = (snapshot) => {\n if (!snapshot.context.selection) {\n return ''\n }\n\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n const block = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endPoint,\n },\n },\n })\n\n if (!block) {\n return ''\n }\n\n const endOfBlock = getBlockEndPoint({\n context: snapshot.context,\n block,\n })\n\n return getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endOfBlock,\n },\n },\n })\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @public\n */\nexport const getBlockTextBefore: EditorSelector<string> = (snapshot) => {\n if (!snapshot.context.selection) {\n return ''\n }\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const block = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\n\n if (!block) {\n return ''\n }\n\n const startOfBlock = getBlockStartPoint({\n context: snapshot.context,\n block,\n })\n\n return getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startOfBlock,\n focus: startPoint,\n },\n },\n })\n}\n","import type {PortableTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n","import type {EditorSnapshot} from '../editor/editor-snapshot'\nimport {comparePaths} from '../slate/path/compare-paths'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * Returns:\n *\n * - `-1` if `pointA` is before `pointB`\n * - `0` if `pointA` and `pointB` are equal\n * - `1` if `pointA` is after `pointB`.\n *\n * Compares the two points by document order, resolved at any depth. When\n * the paths are equal, compares offsets.\n */\nexport function comparePoints(\n snapshot: EditorSnapshot,\n pointA: EditorSelectionPoint,\n pointB: EditorSelectionPoint,\n): -1 | 0 | 1 {\n const pathComparison = comparePaths(pointA.path, pointB.path, {\n children: snapshot.context.value,\n })\n\n if (pathComparison !== 0) {\n return pathComparison\n }\n\n if (pointA.offset < pointB.offset) {\n return -1\n }\n\n if (pointA.offset > pointB.offset) {\n return 1\n }\n\n return 0\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {comparePoints} from '../utils/util.compare-points'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\n\n/**\n * @public\n */\nexport function isPointAfterSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n\n return comparePoints(snapshot, point, endPoint) === 1\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {comparePoints} from '../utils/util.compare-points'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\n\n/**\n * @public\n */\nexport function isPointBeforeSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n\n return comparePoints(snapshot, point, startPoint) === -1\n }\n}\n"],"names":["getAnchorBlock","snapshot","selection","context","getEnclosingBlock","anchor","path","getAnchorChild","getInline","getAnchorSpan","anchorChild","isSpan","node","undefined","getAnchorTextBlock","anchorBlock","isTextBlock","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","spanSelectionPointToBlockOffset","selectionPoint","end","getNextInlineObjects","point","endSegment","at","endKey","isKeyedSegment","_key","children","getChildren","parentPath","inlineObjects","endFound","child","segment","isObjectNode","schema","push","getPreviousInlineObjects","startSegment","startKey","getSelection","getBlockTextAfter","endPoint","block","getFocusTextBlock","focus","endOfBlock","getBlockEndPoint","getSelectionText","getBlockTextBefore","startPoint","startOfBlock","getBlockStartPoint","getValue","value","comparePoints","pointA","pointB","pathComparison","comparePaths","offset","isPointAfterSelection","isPointBeforeSelection"],"mappings":";;;;;;AAUO,MAAMA,iBAERC,CAAAA,aAAa;AAChB,QAAMC,YAAYD,SAASE,QAAQD;AAEnC,MAAKA;AAIL,WAAOE,kBAAkBH,UAAUC,UAAUG,OAAOC,IAAI;AAC1D,GCTaC,iBAMRN,CAAAA,aAAa;AAChB,QAAMC,YAAYD,SAASE,QAAQD;AAEnC,MAAKA;AAIL,WAAOM,UAAUP,UAAUC,UAAUG,OAAOC,IAAI;AAClD,GCfaG,gBAERR,CAAAA,aAAa;AAChB,QAAMS,cAAcH,eAAeN,QAAQ;AAE3C,SAAOS,eAAeC,OAAOV,SAASE,SAASO,YAAYE,IAAI,IAC3D;AAAA,IAACA,MAAMF,YAAYE;AAAAA,IAAMN,MAAMI,YAAYJ;AAAAA,EAAAA,IAC3CO;AACN,GCPaC,qBAERb,CAAAA,aAAa;AAChB,QAAMc,cAAcf,eAAeC,QAAQ;AAE3C,SAAOc,eAAeC,YAAYf,SAASE,SAASY,YAAYH,IAAI,IAChE;AAAA,IAACA,MAAMG,YAAYH;AAAAA,IAAMN,MAAMS,YAAYT;AAAAA,EAAAA,IAC3CO;AACN,GCVaI,kBAERhB,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASE,QAAQD;AACpB;AAGF,QAAMgB,sBAAsBC,uBAAuBlB,QAAQ,GACrDmB,oBAAoBC,qBAAqBpB,QAAQ;AAEvD,MAAI,CAACiB,uBAAuB,CAACE;AAC3B;AAGF,QAAME,QAAQC,gCAAgC;AAAA,IAC5CtB;AAAAA,IACAuB,gBAAgBN;AAAAA,EAAAA,CACjB,GACKO,MAAMF,gCAAgC;AAAA,IAC1CtB;AAAAA,IACAuB,gBAAgBJ;AAAAA,EAAAA,CACjB;AAED,SAAOE,SAASG,MAAM;AAAA,IAACH;AAAAA,IAAOG;AAAAA,EAAAA,IAAOZ;AACvC,GClBaa,uBAERzB,CAAAA,aAAa;AA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A,IACtCvD,SAASF,SAASE;AAAAA,IAClB8C;AAAAA,EAAAA,CACD;AAED,SAAOK,iBAAiB;AAAA,IAEtBnD,SAAS;AAAA,MACP,GAAGF,SAASE;AAAAA,MACZD,WAAW;AAAA,QACTG,QAAQoD;AAAAA,QACRN,OAAOK;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AACH,GCvCaG,WACX1D,CAAAA,aAEOA,SAASE,QAAQyD;ACKnB,SAASC,cACd5D,UACA6D,QACAC,QACY;AACZ,QAAMC,iBAAiBC,aAAaH,OAAOxD,MAAMyD,OAAOzD,MAAM;AAAA,IAC5D2B,UAAUhC,SAASE,QAAQyD;AAAAA,EAAAA,CAC5B;AAED,SAAII,mBAAmB,IACdA,iBAGLF,OAAOI,SAASH,OAAOG,SAClB,KAGLJ,OAAOI,SAASH,OAAOG,SAClB,IAGF;AACT;AC5BO,SAASC,sBACdxC,OACyB;AACzB,SAAQ1B,CAAAA,aAAa;AACnB,QAAI,CAACA,SAASE,QAAQD;AACpB,aAAO;AAGT,UAAM8C,WAAW3B,uBAAqBpB,SAASE,QAAQD,SAAS;AAEhE,WAAO2D,cAAc5D,UAAU0B,OAAOqB,QAAQ,MAAM;AAAA,EACtD;AACF;ACZO,SAASoB,uBACdzC,OACyB;AACzB,SAAQ1B,CAAAA,aAAa;AACnB,QAAI,CAACA,SAASE,QAAQD;AACpB,aAAO;AAGT,UAAMsD,aAAarC,yBAAuBlB,SAASE,QAAQD,SAAS;AAEpE,WAAO2D,cAAc5D,UAAU0B,OAAO6B,UAAU,MAAM;AAAA,EACxD;AACF;"}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { D as Path, a as Containers, n as TraversalSnapshot, r as Node } from "../_chunks-dts/resolve-containers.js";
|
|
2
|
+
import { PortableTextBlock, PortableTextSpan, PortableTextTextBlock, Schema } from "@portabletext/schema";
|
|
3
|
+
/**
|
|
4
|
+
* Find the first ancestor of the node at a given path that matches a predicate.
|
|
5
|
+
* Does not check the node at the path itself, only its ancestors.
|
|
6
|
+
*
|
|
7
|
+
* When `match` is a type predicate, the returned `node` narrows to that type.
|
|
8
|
+
*
|
|
9
|
+
* @beta
|
|
10
|
+
*/
|
|
11
|
+
declare function getAncestor<TMatch extends Node>(snapshot: TraversalSnapshot, path: Path, match: (node: Node, path: Path) => node is TMatch): {
|
|
12
|
+
node: TMatch;
|
|
13
|
+
path: Path;
|
|
14
|
+
} | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* @beta
|
|
17
|
+
*/
|
|
18
|
+
declare function getAncestor(snapshot: TraversalSnapshot, path: Path, match: (node: Node, path: Path) => boolean): {
|
|
19
|
+
node: Node;
|
|
20
|
+
path: Path;
|
|
21
|
+
} | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Get all ancestors of the node at a given path, from nearest to furthest.
|
|
24
|
+
*
|
|
25
|
+
* For a path like [{_key:'t1'}, 'rows', {_key:'r1'}, 'cells', {_key:'c1'}],
|
|
26
|
+
* the ancestors are (nearest first):
|
|
27
|
+
* [{_key:'t1'}, 'rows', {_key:'r1'}]
|
|
28
|
+
* [{_key:'t1'}]
|
|
29
|
+
*
|
|
30
|
+
* Walks from root to the target in a single pass collecting each ancestor
|
|
31
|
+
* as it goes.
|
|
32
|
+
*
|
|
33
|
+
* @beta
|
|
34
|
+
*/
|
|
35
|
+
declare function getAncestors(snapshot: TraversalSnapshot, path: Path): Array<{
|
|
36
|
+
node: Node;
|
|
37
|
+
path: Path;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* Determine if a node at the given path is a block.
|
|
41
|
+
*
|
|
42
|
+
* A node is a block if its parent is not a text block. Top-level nodes
|
|
43
|
+
* (direct children of the editor) are always blocks. Children of text blocks
|
|
44
|
+
* (spans and inline objects) are not blocks. Children of containers are
|
|
45
|
+
* blocks within that container.
|
|
46
|
+
*
|
|
47
|
+
* @beta
|
|
48
|
+
*/
|
|
49
|
+
declare function isBlock(snapshot: TraversalSnapshot, path: Path): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Get the node at the given path if it is a block.
|
|
52
|
+
*
|
|
53
|
+
* Returns the node narrowed to PortableTextBlock, or undefined if the node
|
|
54
|
+
* doesn't exist or is not a block.
|
|
55
|
+
*
|
|
56
|
+
* @beta
|
|
57
|
+
*/
|
|
58
|
+
declare function getBlock(snapshot: TraversalSnapshot, path: Path): {
|
|
59
|
+
node: PortableTextBlock;
|
|
60
|
+
path: Path;
|
|
61
|
+
} | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Get the children of a node at a given path.
|
|
64
|
+
*
|
|
65
|
+
* @beta
|
|
66
|
+
*/
|
|
67
|
+
declare function getChildren(snapshot: TraversalSnapshot, path: Path): Array<{
|
|
68
|
+
node: Node;
|
|
69
|
+
path: Path;
|
|
70
|
+
}>;
|
|
71
|
+
/**
|
|
72
|
+
* Walk up from a path to find the nearest enclosing block.
|
|
73
|
+
*
|
|
74
|
+
* Returns the node at the path if it is a block, otherwise the first ancestor
|
|
75
|
+
* that is a block. Works at any depth — inside a container this returns the
|
|
76
|
+
* container-internal block, not the outer container.
|
|
77
|
+
*
|
|
78
|
+
* @beta
|
|
79
|
+
*/
|
|
80
|
+
declare function getEnclosingBlock(snapshot: TraversalSnapshot, path: Path): {
|
|
81
|
+
node: PortableTextBlock;
|
|
82
|
+
path: Path;
|
|
83
|
+
} | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Get the first child of a node at a given path.
|
|
86
|
+
*
|
|
87
|
+
* @beta
|
|
88
|
+
*/
|
|
89
|
+
declare function getFirstChild(snapshot: TraversalSnapshot, path: Path): {
|
|
90
|
+
node: Node;
|
|
91
|
+
path: Path;
|
|
92
|
+
} | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Get the last child of a node at a given path.
|
|
95
|
+
*
|
|
96
|
+
* @beta
|
|
97
|
+
*/
|
|
98
|
+
declare function getLastChild(snapshot: TraversalSnapshot, path: Path): {
|
|
99
|
+
node: Node;
|
|
100
|
+
path: Path;
|
|
101
|
+
} | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Get the deepest leaf node starting from a path, walking toward either the
|
|
104
|
+
* start or end edge. A leaf is any node that has no children according to the
|
|
105
|
+
* traversal context.
|
|
106
|
+
*
|
|
107
|
+
* @beta
|
|
108
|
+
*/
|
|
109
|
+
declare function getLeaf(snapshot: TraversalSnapshot, path: Path, options: {
|
|
110
|
+
edge: 'start' | 'end';
|
|
111
|
+
}): {
|
|
112
|
+
node: Node;
|
|
113
|
+
path: Path;
|
|
114
|
+
} | undefined;
|
|
115
|
+
/**
|
|
116
|
+
* Get the node at a given path.
|
|
117
|
+
*
|
|
118
|
+
* The path can be either keyed (KeyedSegment + field name strings) or
|
|
119
|
+
* indexed (numbers). Keyed segments are resolved by matching `_key`,
|
|
120
|
+
* field name strings are skipped (they're structural), and numbers
|
|
121
|
+
* are resolved by index.
|
|
122
|
+
*
|
|
123
|
+
* The returned path is always fully keyed, even if the input path
|
|
124
|
+
* contained numeric indices.
|
|
125
|
+
*
|
|
126
|
+
* @beta
|
|
127
|
+
*/
|
|
128
|
+
declare function getNode(snapshot: TraversalSnapshot, path: Path): {
|
|
129
|
+
node: Node;
|
|
130
|
+
path: Path;
|
|
131
|
+
} | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* Get the parent of a node at a given path.
|
|
134
|
+
*
|
|
135
|
+
* @beta
|
|
136
|
+
*/
|
|
137
|
+
declare function getParent(snapshot: TraversalSnapshot, path: Path): {
|
|
138
|
+
node: Node;
|
|
139
|
+
path: Path;
|
|
140
|
+
} | undefined;
|
|
141
|
+
/**
|
|
142
|
+
* Return the `Schema` view that applies at a given path.
|
|
143
|
+
*
|
|
144
|
+
* For paths at the root of the document, or for paths where no ancestor is
|
|
145
|
+
* a registered container, returns the top-level schema. For paths inside a
|
|
146
|
+
* container, walks ancestors to find the nearest container and returns the
|
|
147
|
+
* sub-schema derived from its `of` declaration.
|
|
148
|
+
*
|
|
149
|
+
* @beta
|
|
150
|
+
*/
|
|
151
|
+
declare function getPathSubSchema(snapshot: TraversalSnapshot, path: Path): Schema;
|
|
152
|
+
/**
|
|
153
|
+
* Get the next or previous sibling of the node at a given path.
|
|
154
|
+
*
|
|
155
|
+
* @beta
|
|
156
|
+
*/
|
|
157
|
+
declare function getSibling(snapshot: TraversalSnapshot, path: Path, direction: 'next' | 'previous'): {
|
|
158
|
+
node: Node;
|
|
159
|
+
path: Path;
|
|
160
|
+
} | undefined;
|
|
161
|
+
/**
|
|
162
|
+
* Get the span node at a given path.
|
|
163
|
+
*
|
|
164
|
+
* @beta
|
|
165
|
+
*/
|
|
166
|
+
declare function getSpanNode(snapshot: TraversalSnapshot, path: Path): {
|
|
167
|
+
node: PortableTextSpan;
|
|
168
|
+
path: Path;
|
|
169
|
+
} | undefined;
|
|
170
|
+
/**
|
|
171
|
+
* Get the concatenated text content of the node at a given path.
|
|
172
|
+
*
|
|
173
|
+
* @beta
|
|
174
|
+
*/
|
|
175
|
+
declare function getText(snapshot: TraversalSnapshot, path: Path): string | undefined;
|
|
176
|
+
/**
|
|
177
|
+
* Get the text block node at a given path.
|
|
178
|
+
*
|
|
179
|
+
* @beta
|
|
180
|
+
*/
|
|
181
|
+
declare function getTextBlockNode(snapshot: TraversalSnapshot, path: Path): {
|
|
182
|
+
node: PortableTextTextBlock;
|
|
183
|
+
path: Path;
|
|
184
|
+
} | undefined;
|
|
185
|
+
/**
|
|
186
|
+
* Return a `Schema` that contains every named member declared anywhere
|
|
187
|
+
* in the editor's schema graph that is reachable from a position where text
|
|
188
|
+
* is edited - the root schema merged with the sub-schema of every registered
|
|
189
|
+
* container whose field accepts text blocks, deduped by name. Useful for
|
|
190
|
+
* rendering a static toolbar whose buttons stay stable across selection
|
|
191
|
+
* moves while still reflecting everything that could plausibly be edited or
|
|
192
|
+
* inserted somewhere.
|
|
193
|
+
*
|
|
194
|
+
* Containers whose field does NOT accept text blocks (e.g. a `table`
|
|
195
|
+
* container whose `rows` field only accepts `row` objects, or a `row`
|
|
196
|
+
* container whose `cells` field only accepts `cell` objects) are
|
|
197
|
+
* **structural**: their immediate `of` types are organizational, not
|
|
198
|
+
* insertable user content. Those structural types are excluded from the
|
|
199
|
+
* union. Their nested text-block-accepting descendants (e.g. a `cell`
|
|
200
|
+
* that contains a `content` field of `{type: 'block'}`) are reached via
|
|
201
|
+
* those descendants' own container registration.
|
|
202
|
+
*
|
|
203
|
+
* Pair with `getPathSubSchema` (or a path-based intersection across a
|
|
204
|
+
* range) to determine which of the union's members are applicable at the
|
|
205
|
+
* current selection.
|
|
206
|
+
*
|
|
207
|
+
* @beta
|
|
208
|
+
*/
|
|
209
|
+
declare function getUnionSchema(schema: Schema, containers: Containers): Schema;
|
|
210
|
+
/**
|
|
211
|
+
* Check if a node exists at a given path.
|
|
212
|
+
*
|
|
213
|
+
* @beta
|
|
214
|
+
*/
|
|
215
|
+
declare function hasNode(snapshot: TraversalSnapshot, path: Path): boolean;
|
|
216
|
+
/**
|
|
217
|
+
* Determine if a node at the given path is inline.
|
|
218
|
+
*
|
|
219
|
+
* A node is inline if its parent is a text block. This is the inverse of
|
|
220
|
+
* `isBlock`. Top-level nodes are never inline.
|
|
221
|
+
*
|
|
222
|
+
* @beta
|
|
223
|
+
*/
|
|
224
|
+
declare function isInline(snapshot: TraversalSnapshot, path: Path): boolean;
|
|
225
|
+
/**
|
|
226
|
+
* Determine if a node at the given path is a leaf.
|
|
227
|
+
*
|
|
228
|
+
* A leaf node cannot have children. Spans and non-editable object nodes are
|
|
229
|
+
* leaves. Text blocks and editable container objects are not.
|
|
230
|
+
*
|
|
231
|
+
* @beta
|
|
232
|
+
*/
|
|
233
|
+
declare function isLeaf(snapshot: TraversalSnapshot, path: Path): boolean;
|
|
234
|
+
export { getAncestor, getAncestors, getBlock, getChildren, getEnclosingBlock, getFirstChild, getLastChild, getLeaf, getNode, getParent, getPathSubSchema, getSibling, getSpanNode, getText, getTextBlockNode, getUnionSchema, hasNode, isBlock, isInline, isLeaf };
|
|
235
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/node-traversal/get-ancestor.ts","../../src/node-traversal/get-ancestors.ts","../../src/node-traversal/is-block.ts","../../src/node-traversal/get-children.ts","../../src/node-traversal/get-enclosing-block.ts","../../src/node-traversal/get-first-child.ts","../../src/node-traversal/get-last-child.ts","../../src/node-traversal/get-leaf.ts","../../src/node-traversal/get-node.ts","../../src/node-traversal/get-parent.ts","../../src/traversal/get-path-sub-schema.ts","../../src/node-traversal/get-sibling.ts","../../src/node-traversal/get-span-node.ts","../../src/node-traversal/get-text.ts","../../src/node-traversal/get-text-block-node.ts","../../src/traversal/get-union-schema.ts","../../src/node-traversal/has-node.ts","../../src/node-traversal/is-inline.ts","../../src/node-traversal/is-leaf.ts"],"sourcesContent":[],"mappings":";;AAaA;;;;;;;;AAIwB,iBAJR,WAIQ,CAAA,eAJmB,IAInB,CAAA,CAAA,QAAA,EAHZ,iBAGY,EAAA,IAAA,EAFhB,IAEgB,EAAA,KAAA,EAAA,CAAA,IAAA,EADR,IACQ,EAAA,IAAA,EADI,IACJ,EAAA,GAAA,IAAA,IADqB,MACrB,CAAA,EAAA;EAAI,IAAA,EAAlB,MAAkB;EAIZ,IAAA,EAJQ,IAIR;CACJ,GAAA,SAAA;;;;AAGF,iBAJM,WAAA,CAIN,QAAA,EAHE,iBAGF,EAAA,IAAA,EAFF,IAEE,EAAA,KAAA,EAAA,CAAA,IAAA,EADM,IACN,EAAA,IAAA,EADkB,IAClB,EAAA,GAAA,OAAA,CAAA,EAAA;EAAY,IAAA,EAAZ,IAAY;EAAI,IAAA,EAAJ,IAAI;;AAZ1B;;;;;;;;;;AAQA;;;AAGgB,iBCLA,YAAA,CDKA,QAAA,ECJJ,iBDII,EAAA,IAAA,ECHR,IDGQ,CAAA,ECFb,KDEa,CAAA;EAAY,IAAA,ECFZ,IDEY;EAClB,IAAA,ECHkB,IDGlB;CAAY,CAAA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GgB,iBgBPA,OAAA,ChBOA,QAAA,EgBPkB,iBhBOlB,EAAA,IAAA,EgBP2C,IhBO3C,CAAA,EAAA,OAAA;;AAHhB;;;;;;;AAIU,iBiBLM,QAAA,CjBKN,QAAA,EiBLyB,iBjBKzB,EAAA,IAAA,EiBLkD,IjBKlD,CAAA,EAAA,OAAA;;AAJV;;;;;;;AAIU,iBkBHM,MAAA,ClBGN,QAAA,EkBHuB,iBlBGvB,EAAA,IAAA,EkBHgD,IlBGhD,CAAA,EAAA,OAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getChildren } from "../_chunks-es/get-ancestor.js";
|
|
2
|
+
import { getAncestor, getAncestors, getNode } from "../_chunks-es/get-ancestor.js";
|
|
3
|
+
import { getBlock, getEnclosingBlock, getParent, getPathSubSchema, getSibling, hasNode, isBlock, isInline } from "../_chunks-es/get-path-sub-schema.js";
|
|
4
|
+
import { getFirstChild, getLeaf, getSpanNode, getText, getTextBlockNode, getUnionSchema, isLeaf } from "../_chunks-es/get-first-child.js";
|
|
5
|
+
function getLastChild(snapshot, path) {
|
|
6
|
+
return getChildren(snapshot, path).at(-1);
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
getAncestor,
|
|
10
|
+
getAncestors,
|
|
11
|
+
getBlock,
|
|
12
|
+
getChildren,
|
|
13
|
+
getEnclosingBlock,
|
|
14
|
+
getFirstChild,
|
|
15
|
+
getLastChild,
|
|
16
|
+
getLeaf,
|
|
17
|
+
getNode,
|
|
18
|
+
getParent,
|
|
19
|
+
getPathSubSchema,
|
|
20
|
+
getSibling,
|
|
21
|
+
getSpanNode,
|
|
22
|
+
getText,
|
|
23
|
+
getTextBlockNode,
|
|
24
|
+
getUnionSchema,
|
|
25
|
+
hasNode,
|
|
26
|
+
isBlock,
|
|
27
|
+
isInline,
|
|
28
|
+
isLeaf
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/node-traversal/get-last-child.ts"],"sourcesContent":["import type {Node} from '../slate/interfaces/node'\nimport type {Path} from '../slate/interfaces/path'\nimport {getChildren} from './get-children'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Get the last child of a node at a given path.\n *\n * @beta\n */\nexport function getLastChild(\n snapshot: TraversalSnapshot,\n path: Path,\n): {node: Node; path: Path} | undefined {\n const children = getChildren(snapshot, path)\n\n return children.at(-1)\n}\n"],"names":["getLastChild","snapshot","path","getChildren","at"],"mappings":";;;;AAUO,SAASA,aACdC,UACAC,MACsC;AAGtC,SAFiBC,YAAYF,UAAUC,IAAI,EAE3BE,GAAG,EAAE;AACvB;"}
|