@portabletext/editor 7.10.16 → 7.10.17
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 → behavior.types.action-CYtiRDck.d.ts} +260 -59
- package/lib/behavior.types.action-CYtiRDck.d.ts.map +1 -0
- package/lib/behavior.types.behavior-B_77VtQR.js +159 -0
- package/lib/behavior.types.behavior-B_77VtQR.js.map +1 -0
- package/lib/behaviors/index.d.ts +1 -1
- package/lib/behaviors/index.js +2 -35
- package/lib/get-container-BeXYKpoi.js +222 -0
- package/lib/get-container-BeXYKpoi.js.map +1 -0
- package/lib/get-parent-51Kzgaf9.js +237 -0
- package/lib/get-parent-51Kzgaf9.js.map +1 -0
- package/lib/get-path-sub-schema--2I4NJbG.js +513 -0
- package/lib/get-path-sub-schema--2I4NJbG.js.map +1 -0
- package/lib/index.d.ts +2 -67
- package/lib/index.js +16743 -18963
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.ts +1 -2
- package/lib/plugins/index.d.ts.map +1 -1
- package/lib/plugins/index.js +103 -41
- package/lib/plugins/index.js.map +1 -1
- package/lib/selector.is-at-the-start-of-block-gJIMWRpU.js +822 -0
- package/lib/selector.is-at-the-start-of-block-gJIMWRpU.js.map +1 -0
- package/lib/selectors/index.d.ts +1 -3
- package/lib/selectors/index.d.ts.map +1 -1
- package/lib/selectors/index.js +256 -215
- package/lib/selectors/index.js.map +1 -1
- package/lib/traversal/index.d.ts +1 -1
- package/lib/traversal/index.d.ts.map +1 -1
- package/lib/traversal/index.js +33 -52
- package/lib/traversal/index.js.map +1 -1
- package/lib/use-editor-CwNeVwVC.js +47 -0
- package/lib/use-editor-CwNeVwVC.js.map +1 -0
- package/lib/util.is-equal-selections-BF4WJtz5.js +25 -0
- package/lib/util.is-equal-selections-BF4WJtz5.js.map +1 -0
- package/lib/util.slice-blocks-DQnr9X2s.js +633 -0
- package/lib/util.slice-blocks-DQnr9X2s.js.map +1 -0
- package/lib/utils/index.d.ts +11 -39
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +87 -123
- package/lib/utils/index.js.map +1 -1
- package/package.json +18 -15
- package/lib/_chunks-dts/behavior.types.action.d.ts.map +0 -1
- package/lib/_chunks-dts/block-offset.d.ts +0 -10
- package/lib/_chunks-dts/block-offset.d.ts.map +0 -1
- package/lib/_chunks-dts/editor-selector.d.ts +0 -33
- package/lib/_chunks-dts/editor-selector.d.ts.map +0 -1
- package/lib/_chunks-dts/editor.d.ts +0 -99
- package/lib/_chunks-dts/editor.d.ts.map +0 -1
- package/lib/_chunks-es/get-container.js +0 -187
- package/lib/_chunks-es/get-container.js.map +0 -1
- package/lib/_chunks-es/get-parent.js +0 -195
- package/lib/_chunks-es/get-parent.js.map +0 -1
- package/lib/_chunks-es/get-path-sub-schema.js +0 -399
- package/lib/_chunks-es/get-path-sub-schema.js.map +0 -1
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +0 -947
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +0 -1
- package/lib/_chunks-es/use-editor.js +0 -20
- package/lib/_chunks-es/use-editor.js.map +0 -1
- package/lib/_chunks-es/util.is-equal-selections.js +0 -20
- package/lib/_chunks-es/util.is-equal-selections.js.map +0 -1
- package/lib/_chunks-es/util.slice-blocks.js +0 -720
- package/lib/_chunks-es/util.slice-blocks.js.map +0 -1
- package/lib/behaviors/index.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
package/lib/selectors/index.js
CHANGED
|
@@ -1,231 +1,272 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { i as getChildren, n as parentPath, u as isKeyedSegment } from "../get-parent-51Kzgaf9.js";
|
|
2
|
+
import { i as getEnclosingBlock, o as getBlock, r as comparePoints, t as getPathSubSchema, y as isObject } from "../get-path-sub-schema--2I4NJbG.js";
|
|
3
|
+
import { d as getSelectionEndPoint$1, m as getBlockEndPoint, p as getBlockStartPoint, u as getSelectionStartPoint$1, y as spanSelectionPointToBlockOffset } from "../util.slice-blocks-DQnr9X2s.js";
|
|
4
|
+
import { A as isSelectingEntireBlocks, B as getFocusTextBlock, D as getSelectionStartPoint, E as getPreviousSpan, F as getSelectionStartBlock, G as getInline, H as getFocusSpan, I as getSelectionEndBlock, L as getFragment, M as isSelectionExpanded, N as isSelectionCollapsed, O as getNextSpan, P as isOverlappingSelection, R as getSelectedValue, S as getSelectedTextBlocks, T as getSelectedSpans, U as getFocusInlineObject, V as getFocusBlock, W as getFocusChild, _ as getActiveStyle, a as isActiveDecorator, b as isActiveAnnotation, c as getPreviousBlock, d as getFocusListBlock, f as getFocusBlockObject, g as getNextInlineObject, h as getPreviousInlineObject, i as isActiveListItem, j as getSelectedBlocks, k as getSelectionEndPoint, l as getNextBlock, m as getSelectionText, n as isAtTheEndOfBlock, o as getSelectionStartChild, p as getCaretWordSelection, r as isActiveStyle, s as getSelectionEndChild, t as isAtTheStartOfBlock, u as getLastBlock, v as getActiveListItem, w as getMarkState, y as getActiveAnnotations } from "../selector.is-at-the-start-of-block-gJIMWRpU.js";
|
|
4
5
|
import { isSpan, isTextBlock } from "@portabletext/schema";
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Resolve which schema members are applicable at the current selection. For
|
|
8
|
+
* each named category (decorators, annotations, lists, styles, block objects,
|
|
9
|
+
* inline objects) returns the set of names that the editor allows at the
|
|
10
|
+
* current selection.
|
|
11
|
+
*
|
|
12
|
+
* Categories split by what they apply to:
|
|
13
|
+
*
|
|
14
|
+
* Text-only (decorators, annotations, lists, styles): require text-block
|
|
15
|
+
* content in the selection. A name is applicable when at least one text
|
|
16
|
+
* block the range covers declares it (union). The underlying operations
|
|
17
|
+
* apply per-block, validating each block's sub-schema and skipping blocks
|
|
18
|
+
* that don't declare the type, so the result reflects "will this produce
|
|
19
|
+
* any effect?" semantics. Selection on a void block, or no selection,
|
|
20
|
+
* returns empty sets.
|
|
21
|
+
*
|
|
22
|
+
* Insertion (blockObjects, inlineObjects): the things consumers might
|
|
23
|
+
* insert AT the current selection. The focus block's sub-schema applies
|
|
24
|
+
* even when the selection is on a void block (the question "what can I
|
|
25
|
+
* insert here?" still has an answer). No selection returns empty sets.
|
|
26
|
+
*
|
|
27
|
+
* Useful for gating toolbar buttons, slash-command items, command palettes,
|
|
28
|
+
* keyboard-shortcut hints and other selection-aware UIs.
|
|
29
|
+
*
|
|
30
|
+
* Pair with `getUnionSchema` (from `@portabletext/editor/traversal`) to render a static toolbar whose
|
|
31
|
+
* buttons stay stable across selection moves while gating their enabled
|
|
32
|
+
* state on whether the corresponding name is in the relevant set.
|
|
33
|
+
*
|
|
34
|
+
* Note for React consumers: the returned object is a fresh value on every
|
|
35
|
+
* call, so subscribing via `useEditorSelector` requires a structural
|
|
36
|
+
* compare to avoid re-rendering on every editor tick. Use
|
|
37
|
+
* {@link compareApplicableSchema} as the third argument.
|
|
38
|
+
*
|
|
39
|
+
* @beta
|
|
40
|
+
*/
|
|
41
|
+
const getApplicableSchema = (snapshot) => {
|
|
42
|
+
if (!snapshot.context.selection) return EMPTY;
|
|
43
|
+
let focusBlock = getFocusBlock(snapshot), focusSub = focusBlock ? getPathSubSchema(snapshot, focusBlock.path) : void 0, insertion = focusSub ? {
|
|
44
|
+
blockObjects: namesOfArray(focusSub.blockObjects),
|
|
45
|
+
inlineObjects: namesOfArray(focusSub.inlineObjects)
|
|
46
|
+
} : {
|
|
47
|
+
blockObjects: EMPTY_SET,
|
|
48
|
+
inlineObjects: EMPTY_SET
|
|
49
|
+
}, textBlocks = getSelectedTextBlocks(snapshot);
|
|
50
|
+
if (textBlocks.length === 0) return {
|
|
51
|
+
decorators: EMPTY_SET,
|
|
52
|
+
annotations: EMPTY_SET,
|
|
53
|
+
lists: EMPTY_SET,
|
|
54
|
+
styles: EMPTY_SET,
|
|
55
|
+
...insertion
|
|
56
|
+
};
|
|
57
|
+
let textApplicable = textCategoryNames(getPathSubSchema(snapshot, textBlocks[0].path));
|
|
58
|
+
for (let i = 1; i < textBlocks.length; i++) textApplicable = unionTextCategories(textApplicable, textCategoryNames(getPathSubSchema(snapshot, textBlocks[i].path)));
|
|
59
|
+
return {
|
|
60
|
+
...textApplicable,
|
|
61
|
+
...insertion
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Structural comparator for {@link ApplicableSchema} values. Two results
|
|
66
|
+
* compare equal when every category contains the same names (set equality).
|
|
67
|
+
* Pass as the `compare` argument to `useEditorSelector` to keep React
|
|
68
|
+
* subscriptions stable.
|
|
69
|
+
*
|
|
70
|
+
* @beta
|
|
71
|
+
*/
|
|
72
|
+
function compareApplicableSchema(a, b) {
|
|
73
|
+
return a === b || sameSet(a.decorators, b.decorators) && sameSet(a.annotations, b.annotations) && sameSet(a.lists, b.lists) && sameSet(a.styles, b.styles) && sameSet(a.blockObjects, b.blockObjects) && sameSet(a.inlineObjects, b.inlineObjects);
|
|
74
|
+
}
|
|
75
|
+
const EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set()), EMPTY = Object.freeze({
|
|
76
|
+
decorators: EMPTY_SET,
|
|
77
|
+
annotations: EMPTY_SET,
|
|
78
|
+
lists: EMPTY_SET,
|
|
79
|
+
styles: EMPTY_SET,
|
|
80
|
+
blockObjects: EMPTY_SET,
|
|
81
|
+
inlineObjects: EMPTY_SET
|
|
82
|
+
});
|
|
83
|
+
function textCategoryNames(schema) {
|
|
84
|
+
return {
|
|
85
|
+
decorators: namesOfArray(schema.decorators),
|
|
86
|
+
annotations: namesOfArray(schema.annotations),
|
|
87
|
+
lists: namesOfArray(schema.lists),
|
|
88
|
+
styles: namesOfArray(schema.styles)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function unionTextCategories(a, b) {
|
|
92
|
+
return {
|
|
93
|
+
decorators: unionSet(a.decorators, b.decorators),
|
|
94
|
+
annotations: unionSet(a.annotations, b.annotations),
|
|
95
|
+
lists: unionSet(a.lists, b.lists),
|
|
96
|
+
styles: unionSet(a.styles, b.styles)
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function namesOfArray(entries) {
|
|
100
|
+
return new Set(entries.map((entry) => entry.name));
|
|
101
|
+
}
|
|
102
|
+
function unionSet(a, b) {
|
|
103
|
+
let result = new Set(a);
|
|
104
|
+
for (let item of b) result.add(item);
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
function sameSet(a, b) {
|
|
108
|
+
if (a === b) return !0;
|
|
109
|
+
if (a.size !== b.size) return !1;
|
|
110
|
+
for (let item of a) if (!b.has(item)) return !1;
|
|
111
|
+
return !0;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Returns the block containing the anchor selection, resolved at any depth.
|
|
115
|
+
*
|
|
116
|
+
* @public
|
|
117
|
+
*/
|
|
7
118
|
const getAnchorBlock = (snapshot) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return getEnclosingBlock(snapshot, selection.anchor.path);
|
|
119
|
+
let selection = snapshot.context.selection;
|
|
120
|
+
if (selection) return getEnclosingBlock(snapshot, selection.anchor.path);
|
|
11
121
|
}, getAnchorChild = (snapshot) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return getInline(snapshot, selection.anchor.path);
|
|
122
|
+
let selection = snapshot.context.selection;
|
|
123
|
+
if (selection) return getInline(snapshot, selection.anchor.path);
|
|
15
124
|
}, getAnchorSpan = (snapshot) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
125
|
+
let anchorChild = getAnchorChild(snapshot);
|
|
126
|
+
return anchorChild && isSpan(snapshot.context, anchorChild.node) ? {
|
|
127
|
+
node: anchorChild.node,
|
|
128
|
+
path: anchorChild.path
|
|
129
|
+
} : void 0;
|
|
21
130
|
}, getAnchorTextBlock = (snapshot) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
131
|
+
let anchorBlock = getAnchorBlock(snapshot);
|
|
132
|
+
return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node) ? {
|
|
133
|
+
node: anchorBlock.node,
|
|
134
|
+
path: anchorBlock.path
|
|
135
|
+
} : void 0;
|
|
27
136
|
}, getBlockOffsets = (snapshot) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
end
|
|
43
|
-
} : void 0;
|
|
137
|
+
if (!snapshot.context.selection) return;
|
|
138
|
+
let selectionStartPoint = getSelectionStartPoint(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot);
|
|
139
|
+
if (!selectionStartPoint || !selectionEndPoint) return;
|
|
140
|
+
let start = spanSelectionPointToBlockOffset({
|
|
141
|
+
snapshot,
|
|
142
|
+
selectionPoint: selectionStartPoint
|
|
143
|
+
}), end = spanSelectionPointToBlockOffset({
|
|
144
|
+
snapshot,
|
|
145
|
+
selectionPoint: selectionEndPoint
|
|
146
|
+
});
|
|
147
|
+
return start && end ? {
|
|
148
|
+
start,
|
|
149
|
+
end
|
|
150
|
+
} : void 0;
|
|
44
151
|
}, getFirstBlock = (snapshot) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
_key: node._key
|
|
56
|
-
}]
|
|
57
|
-
} : void 0;
|
|
152
|
+
let focusBlock = getFocusBlock(snapshot);
|
|
153
|
+
if (focusBlock) {
|
|
154
|
+
let first = getChildren(snapshot, parentPath(focusBlock.path)).at(0);
|
|
155
|
+
if (first) return getBlock(snapshot, first.path);
|
|
156
|
+
}
|
|
157
|
+
let node = snapshot.context.value[0];
|
|
158
|
+
return node ? {
|
|
159
|
+
node,
|
|
160
|
+
path: [{ _key: node._key }]
|
|
161
|
+
} : void 0;
|
|
58
162
|
}, getNextInlineObjects = (snapshot) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
return inlineObjects;
|
|
163
|
+
let point = getSelectionEndPoint(snapshot);
|
|
164
|
+
if (!point) return [];
|
|
165
|
+
let endSegment = point.path.at(-1), endKey = isKeyedSegment(endSegment) ? endSegment._key : void 0;
|
|
166
|
+
if (!endKey) return [];
|
|
167
|
+
let children = getChildren(snapshot, parentPath(point.path)), inlineObjects = [], endFound = !1;
|
|
168
|
+
for (let child of children) {
|
|
169
|
+
let segment = child.path.at(-1);
|
|
170
|
+
if ((isKeyedSegment(segment) ? segment._key : void 0) === endKey) {
|
|
171
|
+
endFound = !0;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
endFound && isObject(snapshot, child.node) && inlineObjects.push({
|
|
175
|
+
node: child.node,
|
|
176
|
+
path: child.path
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
return inlineObjects;
|
|
79
180
|
}, getPreviousInlineObjects = (snapshot) => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
return inlineObjects;
|
|
181
|
+
let point = getSelectionStartPoint(snapshot);
|
|
182
|
+
if (!point) return [];
|
|
183
|
+
let startSegment = point.path.at(-1), startKey = isKeyedSegment(startSegment) ? startSegment._key : void 0;
|
|
184
|
+
if (!startKey) return [];
|
|
185
|
+
let children = getChildren(snapshot, parentPath(point.path)), inlineObjects = [];
|
|
186
|
+
for (let child of children) {
|
|
187
|
+
let segment = child.path.at(-1);
|
|
188
|
+
if ((isKeyedSegment(segment) ? segment._key : void 0) === startKey) break;
|
|
189
|
+
isObject(snapshot, child.node) && inlineObjects.push({
|
|
190
|
+
node: child.node,
|
|
191
|
+
path: child.path
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return inlineObjects;
|
|
97
195
|
}, getSelection = (snapshot) => snapshot.context.selection, getBlockTextAfter = (snapshot) => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
});
|
|
196
|
+
if (!snapshot.context.selection) return "";
|
|
197
|
+
let endPoint = getSelectionEndPoint$1(snapshot.context.selection), block = getFocusTextBlock({
|
|
198
|
+
...snapshot,
|
|
199
|
+
context: {
|
|
200
|
+
...snapshot.context,
|
|
201
|
+
selection: {
|
|
202
|
+
anchor: endPoint,
|
|
203
|
+
focus: endPoint
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
if (!block) return "";
|
|
208
|
+
let endOfBlock = getBlockEndPoint({
|
|
209
|
+
context: snapshot.context,
|
|
210
|
+
block
|
|
211
|
+
});
|
|
212
|
+
return getSelectionText({
|
|
213
|
+
...snapshot,
|
|
214
|
+
context: {
|
|
215
|
+
...snapshot.context,
|
|
216
|
+
selection: {
|
|
217
|
+
anchor: endPoint,
|
|
218
|
+
focus: endOfBlock
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
});
|
|
126
222
|
}, getBlockTextBefore = (snapshot) => {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
});
|
|
223
|
+
if (!snapshot.context.selection) return "";
|
|
224
|
+
let startPoint = getSelectionStartPoint$1(snapshot.context.selection), block = getFocusTextBlock({
|
|
225
|
+
...snapshot,
|
|
226
|
+
context: {
|
|
227
|
+
...snapshot.context,
|
|
228
|
+
selection: {
|
|
229
|
+
anchor: startPoint,
|
|
230
|
+
focus: startPoint
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
if (!block) return "";
|
|
235
|
+
let startOfBlock = getBlockStartPoint({
|
|
236
|
+
context: snapshot.context,
|
|
237
|
+
block
|
|
238
|
+
});
|
|
239
|
+
return getSelectionText({
|
|
240
|
+
...snapshot,
|
|
241
|
+
context: {
|
|
242
|
+
...snapshot.context,
|
|
243
|
+
selection: {
|
|
244
|
+
anchor: startOfBlock,
|
|
245
|
+
focus: startPoint
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
});
|
|
155
249
|
}, getValue = (snapshot) => snapshot.context.value;
|
|
250
|
+
/**
|
|
251
|
+
* @public
|
|
252
|
+
*/
|
|
156
253
|
function isPointAfterSelection(point) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
};
|
|
254
|
+
return (snapshot) => {
|
|
255
|
+
if (!snapshot.context.selection) return !1;
|
|
256
|
+
let endPoint = getSelectionEndPoint$1(snapshot.context.selection);
|
|
257
|
+
return comparePoints(snapshot, point, endPoint) === 1;
|
|
258
|
+
};
|
|
163
259
|
}
|
|
260
|
+
/**
|
|
261
|
+
* @public
|
|
262
|
+
*/
|
|
164
263
|
function isPointBeforeSelection(point) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
};
|
|
264
|
+
return (snapshot) => {
|
|
265
|
+
if (!snapshot.context.selection) return !1;
|
|
266
|
+
let startPoint = getSelectionStartPoint$1(snapshot.context.selection);
|
|
267
|
+
return comparePoints(snapshot, point, startPoint) === -1;
|
|
268
|
+
};
|
|
171
269
|
}
|
|
172
|
-
export {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
getActiveListItem,
|
|
176
|
-
getActiveStyle,
|
|
177
|
-
getAnchorBlock,
|
|
178
|
-
getAnchorChild,
|
|
179
|
-
getAnchorSpan,
|
|
180
|
-
getAnchorTextBlock,
|
|
181
|
-
getApplicableSchema,
|
|
182
|
-
getBlockOffsets,
|
|
183
|
-
getBlockTextAfter,
|
|
184
|
-
getBlockTextBefore,
|
|
185
|
-
getCaretWordSelection,
|
|
186
|
-
getFirstBlock,
|
|
187
|
-
getFocusBlock,
|
|
188
|
-
getFocusBlockObject,
|
|
189
|
-
getFocusChild,
|
|
190
|
-
getFocusInlineObject,
|
|
191
|
-
getFocusListBlock,
|
|
192
|
-
getFocusSpan,
|
|
193
|
-
getFocusTextBlock,
|
|
194
|
-
getFragment,
|
|
195
|
-
getLastBlock,
|
|
196
|
-
getMarkState,
|
|
197
|
-
getNextBlock,
|
|
198
|
-
getNextInlineObject,
|
|
199
|
-
getNextInlineObjects,
|
|
200
|
-
getNextSpan,
|
|
201
|
-
getPreviousBlock,
|
|
202
|
-
getPreviousInlineObject,
|
|
203
|
-
getPreviousInlineObjects,
|
|
204
|
-
getPreviousSpan,
|
|
205
|
-
getSelectedBlocks,
|
|
206
|
-
getSelectedSpans,
|
|
207
|
-
getSelectedTextBlocks,
|
|
208
|
-
getSelectedValue,
|
|
209
|
-
getSelection,
|
|
210
|
-
getSelectionEndBlock,
|
|
211
|
-
getSelectionEndChild,
|
|
212
|
-
getSelectionEndPoint,
|
|
213
|
-
getSelectionStartBlock,
|
|
214
|
-
getSelectionStartChild,
|
|
215
|
-
getSelectionStartPoint,
|
|
216
|
-
getSelectionText,
|
|
217
|
-
getValue,
|
|
218
|
-
isActiveAnnotation,
|
|
219
|
-
isActiveDecorator,
|
|
220
|
-
isActiveListItem,
|
|
221
|
-
isActiveStyle,
|
|
222
|
-
isAtTheEndOfBlock,
|
|
223
|
-
isAtTheStartOfBlock,
|
|
224
|
-
isOverlappingSelection,
|
|
225
|
-
isPointAfterSelection,
|
|
226
|
-
isPointBeforeSelection,
|
|
227
|
-
isSelectingEntireBlocks,
|
|
228
|
-
isSelectionCollapsed,
|
|
229
|
-
isSelectionExpanded
|
|
230
|
-
};
|
|
231
|
-
//# sourceMappingURL=index.js.map
|
|
270
|
+
export { compareApplicableSchema, getActiveAnnotations, getActiveListItem, getActiveStyle, getAnchorBlock, getAnchorChild, getAnchorSpan, getAnchorTextBlock, getApplicableSchema, getBlockOffsets, getBlockTextAfter, getBlockTextBefore, getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusInlineObject, getFocusListBlock, getFocusSpan, getFocusTextBlock, getFragment, getLastBlock, getMarkState, getNextBlock, getNextInlineObject, getNextInlineObjects, getNextSpan, getPreviousBlock, getPreviousInlineObject, getPreviousInlineObjects, getPreviousSpan, getSelectedBlocks, getSelectedSpans, getSelectedTextBlocks, getSelectedValue, getSelection, getSelectionEndBlock, getSelectionEndChild, getSelectionEndPoint, getSelectionStartBlock, getSelectionStartChild, getSelectionStartPoint, getSelectionText, getValue, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks, isSelectionCollapsed, isSelectionExpanded };
|
|
271
|
+
|
|
272
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
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-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 {getEnclosingBlock} from '../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 '../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 {PortableTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {parentPath} from '../engine/path/parent-path'\nimport {getChildren} from '../traversal/get-children'\nimport {getBlock} from '../traversal/is-block'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * Returns the first block at the current container scope.\n *\n * When the focus is inside an editable container (e.g. a code block's line),\n * this returns the first block within that container (the first line). When\n * the focus is at root, or there is no selection, this returns the first\n * block in the document.\n *\n * @public\n */\nexport const getFirstBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n if (focusBlock) {\n const siblings = getChildren(snapshot, parentPath(focusBlock.path))\n const first = siblings.at(0)\n\n if (first) {\n return getBlock(snapshot, first.path)\n }\n }\n\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 {parentPath} from '../engine/path/parent-path'\nimport {getChildren} from '../traversal/get-children'\nimport {isObject} from '../traversal/is-object'\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 (endFound && isObject(snapshot, child.node)) {\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 {parentPath} from '../engine/path/parent-path'\nimport {getChildren} from '../traversal/get-children'\nimport {isObject} from '../traversal/is-object'\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 (isObject(snapshot, 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 {EditorSelector} from '../editor/editor-selector'\nimport {comparePoints} from '../traversal/compare-points'\nimport type {EditorSelectionPoint} from '../types/editor'\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 {comparePoints} from '../traversal/compare-points'\nimport type {EditorSelectionPoint} from '../types/editor'\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","getFirstBlock","focusBlock","getFocusBlock","first","getChildren","parentPath","at","getBlock","value","_key","getNextInlineObjects","point","endSegment","endKey","isKeyedSegment","children","inlineObjects","endFound","child","segment","isObject","push","getPreviousInlineObjects","startSegment","startKey","getSelection","getBlockTextAfter","endPoint","block","getFocusTextBlock","focus","endOfBlock","getBlockEndPoint","getSelectionText","getBlockTextBefore","startPoint","startOfBlock","getBlockStartPoint","getValue","isPointAfterSelection","comparePoints","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,U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GT,QAAMQ,eAAeC,mBAAmB;AAAA,IACtC5D,SAASF,SAASE;AAAAA,IAClBmD;AAAAA,EAAAA,CACD;AAED,SAAOK,iBAAiB;AAAA,IACtB,GAAG1D;AAAAA,IACHE,SAAS;AAAA,MACP,GAAGF,SAASE;AAAAA,MACZD,WAAW;AAAA,QACTG,QAAQyD;AAAAA,QACRN,OAAOK;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AACH,GCvCaG,WACX/D,CAAAA,aAEOA,SAASE,QAAQ+B;ACDnB,SAAS+B,sBACd5B,OACyB;AACzB,SAAQpC,CAAAA,aAAa;AACnB,QAAI,CAACA,SAASE,QAAQD;AACpB,aAAO;AAGT,UAAMmD,WAAWhC,uBAAqBpB,SAASE,QAAQD,SAAS;AAEhE,WAAOgE,cAAcjE,UAAUoC,OAAOgB,QAAQ,MAAM;AAAA,EACtD;AACF;ACZO,SAASc,uBACd9B,OACyB;AACzB,SAAQpC,CAAAA,aAAa;AACnB,QAAI,CAACA,SAASE,QAAQD;AACpB,aAAO;AAGT,UAAM2D,aAAa1C,yBAAuBlB,SAASE,QAAQD,SAAS;AAEpE,WAAOgE,cAAcjE,UAAUoC,OAAOwB,UAAU,MAAM;AAAA,EACxD;AACF;"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["EditorSelector","getPathSubSchema","getFocusBlock","getSelectedTextBlocks","ApplicableSchema","decorators","ReadonlySet","annotations","lists","styles","blockObjects","inlineObjects","getApplicableSchema","snapshot","context","selection","EMPTY","focusBlock","focusSub","path","undefined","insertion","namesOfArray","EMPTY_SET","textBlocks","length","textApplicable","textCategoryNames","i","unionTextCategories","compareApplicableSchema","a","b","sameSet","Object","freeze","Set","TextCategoryNames","Pick","schema","ReadonlyArray","name","unionSet","entries","map","entry","result","item","add","size","has","PortableTextBlock","EditorSelector","getEnclosingBlock","BlockPath","getAnchorBlock","node","path","snapshot","selection","context","undefined","anchor","PortableTextObject","PortableTextSpan","EditorSelector","getInline","ChildPath","getAnchorChild","node","path","snapshot","selection","context","undefined","anchor","isSpan","PortableTextSpan","EditorSelector","ChildPath","getAnchorChild","getAnchorSpan","node","path","snapshot","anchorChild","context","undefined","isTextBlock","PortableTextTextBlock","EditorSelector","BlockPath","getAnchorBlock","getAnchorTextBlock","node","path","snapshot","anchorBlock","context","undefined","EditorSelector","BlockOffset","spanSelectionPointToBlockOffset","getSelectionEndPoint","getSelectionStartPoint","getBlockOffsets","start","end","snapshot","context","selection","undefined","selectionStartPoint","selectionEndPoint","selectionPoint","PortableTextBlock","EditorSelector","parentPath","getChildren","getBlock","BlockPath","getFocusBlock","getFirstBlock","node","path","snapshot","focusBlock","siblings","first","at","context","value","_key","undefined","PortableTextObject","EditorSelector","parentPath","getChildren","isObject","ChildPath","isKeyedSegment","getSelectionEndPoint","getNextInlineObjects","Array","node","path","snapshot","point","endSegment","at","endKey","_key","undefined","children","inlineObjects","endFound","child","segment","childKey","push","PortableTextObject","EditorSelector","parentPath","getChildren","isObject","ChildPath","isKeyedSegment","getSelectionStartPoint","getPreviousInlineObjects","Array","node","path","snapshot","point","startSegment","at","startKey","_key","undefined","children","inlineObjects","child","segment","childKey","push","EditorSelector","EditorSelection","getSelection","snapshot","context","selection","EditorSelector","getBlockEndPoint","getSelectionEndPoint","getFocusTextBlock","getSelectionText","getBlockTextAfter","snapshot","context","selection","endPoint","block","anchor","focus","endOfBlock","EditorSelector","getBlockStartPoint","getSelectionStartPoint","getFocusTextBlock","getSelectionText","getBlockTextBefore","snapshot","context","selection","startPoint","block","anchor","focus","startOfBlock","PortableTextBlock","EditorSelector","getValue","Array","snapshot","context","value","EditorSelector","comparePoints","EditorSelectionPoint","getSelectionEndPoint","isPointAfterSelection","point","snapshot","context","selection","endPoint","EditorSelector","comparePoints","EditorSelectionPoint","getSelectionStartPoint","isPointBeforeSelection","point","snapshot","context","selection","startPoint"],"sources":["../../src/selectors/selector.get-applicable-schema.ts","../../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-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 {EditorSelector} from '../editor/editor-selector'\nimport {getPathSubSchema} from '../traversal/get-path-sub-schema'\nimport {getFocusBlock} from './selector.get-focus-block'\nimport {getSelectedTextBlocks} from './selector.get-selected-text-blocks'\n\n/**\n * The set of schema member names applicable at the current selection,\n * grouped by category.\n *\n * @beta\n */\nexport type ApplicableSchema = {\n decorators: ReadonlySet<string>\n annotations: ReadonlySet<string>\n lists: ReadonlySet<string>\n styles: ReadonlySet<string>\n blockObjects: ReadonlySet<string>\n inlineObjects: ReadonlySet<string>\n}\n\n/**\n * Resolve which schema members are applicable at the current selection. For\n * each named category (decorators, annotations, lists, styles, block objects,\n * inline objects) returns the set of names that the editor allows at the\n * current selection.\n *\n * Categories split by what they apply to:\n *\n * Text-only (decorators, annotations, lists, styles): require text-block\n * content in the selection. A name is applicable when at least one text\n * block the range covers declares it (union). The underlying operations\n * apply per-block, validating each block's sub-schema and skipping blocks\n * that don't declare the type, so the result reflects \"will this produce\n * any effect?\" semantics. Selection on a void block, or no selection,\n * returns empty sets.\n *\n * Insertion (blockObjects, inlineObjects): the things consumers might\n * insert AT the current selection. The focus block's sub-schema applies\n * even when the selection is on a void block (the question \"what can I\n * insert here?\" still has an answer). No selection returns empty sets.\n *\n * Useful for gating toolbar buttons, slash-command items, command palettes,\n * keyboard-shortcut hints and other selection-aware UIs.\n *\n * Pair with `getUnionSchema` (from `@portabletext/editor/traversal`) to render a static toolbar whose\n * buttons stay stable across selection moves while gating their enabled\n * state on whether the corresponding name is in the relevant set.\n *\n * Note for React consumers: the returned object is a fresh value on every\n * call, so subscribing via `useEditorSelector` requires a structural\n * compare to avoid re-rendering on every editor tick. Use\n * {@link compareApplicableSchema} as the third argument.\n *\n * @beta\n */\nexport const getApplicableSchema: EditorSelector<ApplicableSchema> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return EMPTY\n }\n\n const focusBlock = getFocusBlock(snapshot)\n const focusSub = focusBlock\n ? getPathSubSchema(snapshot, focusBlock.path)\n : undefined\n\n const insertion = focusSub\n ? {\n blockObjects: namesOfArray(focusSub.blockObjects),\n inlineObjects: namesOfArray(focusSub.inlineObjects),\n }\n : {blockObjects: EMPTY_SET, inlineObjects: EMPTY_SET}\n\n const textBlocks = getSelectedTextBlocks(snapshot)\n\n if (textBlocks.length === 0) {\n return {\n decorators: EMPTY_SET,\n annotations: EMPTY_SET,\n lists: EMPTY_SET,\n styles: EMPTY_SET,\n ...insertion,\n }\n }\n\n let textApplicable = textCategoryNames(\n getPathSubSchema(snapshot, textBlocks[0]!.path),\n )\n for (let i = 1; i < textBlocks.length; i++) {\n textApplicable = unionTextCategories(\n textApplicable,\n textCategoryNames(getPathSubSchema(snapshot, textBlocks[i]!.path)),\n )\n }\n\n return {\n ...textApplicable,\n ...insertion,\n }\n}\n\n/**\n * Structural comparator for {@link ApplicableSchema} values. Two results\n * compare equal when every category contains the same names (set equality).\n * Pass as the `compare` argument to `useEditorSelector` to keep React\n * subscriptions stable.\n *\n * @beta\n */\nexport function compareApplicableSchema(\n a: ApplicableSchema,\n b: ApplicableSchema,\n): boolean {\n if (a === b) {\n return true\n }\n return (\n sameSet(a.decorators, b.decorators) &&\n sameSet(a.annotations, b.annotations) &&\n sameSet(a.lists, b.lists) &&\n sameSet(a.styles, b.styles) &&\n sameSet(a.blockObjects, b.blockObjects) &&\n sameSet(a.inlineObjects, b.inlineObjects)\n )\n}\n\nconst EMPTY_SET: ReadonlySet<string> = Object.freeze(new Set<string>())\n\nconst EMPTY: ApplicableSchema = Object.freeze({\n decorators: EMPTY_SET,\n annotations: EMPTY_SET,\n lists: EMPTY_SET,\n styles: EMPTY_SET,\n blockObjects: EMPTY_SET,\n inlineObjects: EMPTY_SET,\n})\n\ntype TextCategoryNames = Pick<\n ApplicableSchema,\n 'decorators' | 'annotations' | 'lists' | 'styles'\n>\n\nfunction textCategoryNames(schema: {\n decorators: ReadonlyArray<{name: string}>\n annotations: ReadonlyArray<{name: string}>\n lists: ReadonlyArray<{name: string}>\n styles: ReadonlyArray<{name: string}>\n}): TextCategoryNames {\n return {\n decorators: namesOfArray(schema.decorators),\n annotations: namesOfArray(schema.annotations),\n lists: namesOfArray(schema.lists),\n styles: namesOfArray(schema.styles),\n }\n}\n\nfunction unionTextCategories(\n a: TextCategoryNames,\n b: TextCategoryNames,\n): TextCategoryNames {\n return {\n decorators: unionSet(a.decorators, b.decorators),\n annotations: unionSet(a.annotations, b.annotations),\n lists: unionSet(a.lists, b.lists),\n styles: unionSet(a.styles, b.styles),\n }\n}\n\nfunction namesOfArray(\n entries: ReadonlyArray<{name: string}>,\n): ReadonlySet<string> {\n return new Set(entries.map((entry) => entry.name))\n}\n\nfunction unionSet(a: ReadonlySet<string>, b: ReadonlySet<string>): Set<string> {\n const result = new Set<string>(a)\n for (const item of b) {\n result.add(item)\n }\n return result\n}\n\nfunction sameSet(a: ReadonlySet<string>, b: ReadonlySet<string>) {\n if (a === b) {\n return true\n }\n if (a.size !== b.size) {\n return false\n }\n for (const item of a) {\n if (!b.has(item)) {\n return false\n }\n }\n return true\n}\n","import type {PortableTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getEnclosingBlock} from '../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 '../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 {PortableTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {parentPath} from '../engine/path/parent-path'\nimport {getChildren} from '../traversal/get-children'\nimport {getBlock} from '../traversal/is-block'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * Returns the first block at the current container scope.\n *\n * When the focus is inside an editable container (e.g. a code block's line),\n * this returns the first block within that container (the first line). When\n * the focus is at root, or there is no selection, this returns the first\n * block in the document.\n *\n * @public\n */\nexport const getFirstBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n if (focusBlock) {\n const siblings = getChildren(snapshot, parentPath(focusBlock.path))\n const first = siblings.at(0)\n\n if (first) {\n return getBlock(snapshot, first.path)\n }\n }\n\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 {parentPath} from '../engine/path/parent-path'\nimport {getChildren} from '../traversal/get-children'\nimport {isObject} from '../traversal/is-object'\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 (endFound && isObject(snapshot, child.node)) {\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 {parentPath} from '../engine/path/parent-path'\nimport {getChildren} from '../traversal/get-children'\nimport {isObject} from '../traversal/is-object'\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 (isObject(snapshot, 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 {EditorSelector} from '../editor/editor-selector'\nimport {comparePoints} from '../traversal/compare-points'\nimport type {EditorSelectionPoint} from '../types/editor'\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 {comparePoints} from '../traversal/compare-points'\nimport type {EditorSelectionPoint} from '../types/editor'\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,MAAaY,uBACXC,aACG;CACH,IAAI,CAACA,SAASC,QAAQC,WACpB,OAAOC;CAGT,IAAMC,aAAaf,cAAcW,QAAQ,GACnCK,WAAWD,aACbhB,iBAAiBY,UAAUI,WAAWE,IAAI,IAC1CC,KAAAA,GAEEC,YAAYH,WACd;EACER,cAAcY,aAAaJ,SAASR,YAAY;EAChDC,eAAeW,aAAaJ,SAASP,aAAa;CACpD,IACA;EAACD,cAAca;EAAWZ,eAAeY;CAAS,GAEhDC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;IACTG,QAAQF;IACRG,OAAOC;GACT;EACF;CACF,CAAC;AACH,GCpCaM,sBAA8CC,aAAa;CACtE,IAAI,CAACA,SAASC,QAAQC,WACpB,OAAO;CAGT,IAAMC,aAAaP,yBAAuBI,SAASC,QAAQC,SAAS,GAC9DE,QAAQP,kBAAkB;EAC9B,GAAGG;EACHC,SAAS;GACP,GAAGD,SAASC;GACZC,WAAW;IACTG,QAAQF;IACRG,OAAOH;GACT;EACF;CACF,CAAC;CAED,IAAI,CAACC,OACH,OAAO;CAGT,IAAMG,eAAeZ,mBAAmB;EACtCM,SAASD,SAASC;EAClBG;CACF,CAAC;CAED,OAAON,iBAAiB;EACtB,GAAGE;EACHC,SAAS;GACP,GAAGD,SAASC;GACZC,WAAW;IACTG,QAAQE;IACRD,OAAOH;GACT;EACF;CACF,CAAC;AACH,GCvCaO,YACXE,aAEOA,SAASC,QAAQC;;;;ACD1B,SAAgBK,sBACdC,OACyB;CACzB,QAAQC,aAAa;EACnB,IAAI,CAACA,SAASC,QAAQC,WACpB,OAAO;EAGT,IAAMC,WAAWN,uBAAqBG,SAASC,QAAQC,SAAS;EAEhE,OAAOP,cAAcK,UAAUD,OAAOI,QAAQ,MAAM;CACtD;AACF;;;;ACZA,SAAgBK,uBACdC,OACyB;CACzB,QAAQC,aAAa;EACnB,IAAI,CAACA,SAASC,QAAQC,WACpB,OAAO;EAGT,IAAMC,aAAaN,yBAAuBG,SAASC,QAAQC,SAAS;EAEpE,OAAOP,cAAcK,UAAUD,OAAOI,UAAU,MAAM;CACxD;AACF"}
|
package/lib/traversal/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { It as
|
|
1
|
+
import { It as Containers, Nt as TraversalSnapshot, Pt as Node, Rt as RegisteredContainer, lt as EditorSelection, pn as Path, ut as EditorSelectionPoint } from "../behavior.types.action-CYtiRDck.js";
|
|
2
2
|
import { PortableTextBlock, PortableTextObject, PortableTextSpan, PortableTextTextBlock, Schema } from "@portabletext/schema";
|
|
3
3
|
/**
|
|
4
4
|
* Find an ancestor of the node at a given path that matches a predicate.
|