@portabletext/editor 2.17.2 → 2.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-dts/{behavior.types.action.d.ts → index.d.ts} +9 -9
- package/lib/behaviors/index.d.ts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/plugins/index.d.ts +2 -2
- package/lib/selectors/index.d.ts +2 -2
- package/lib/utils/index.d.ts +1 -1
- package/package.json +14 -25
- package/src/test/vitest/step-definitions.tsx +2 -0
- package/src/test/vitest/test-editor.tsx +18 -4
- package/lib/_chunks-cjs/selector.get-selection-text.cjs +0 -89
- package/lib/_chunks-cjs/selector.get-selection-text.cjs.map +0 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +0 -34
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +0 -1
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +0 -875
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +0 -1
- package/lib/_chunks-cjs/use-editor.cjs +0 -28
- package/lib/_chunks-cjs/use-editor.cjs.map +0 -1
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs +0 -79
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs.map +0 -1
- package/lib/_chunks-cjs/util.get-text-block-text.cjs +0 -473
- package/lib/_chunks-cjs/util.get-text-block-text.cjs.map +0 -1
- package/lib/_chunks-cjs/util.is-empty-text-block.cjs +0 -38
- package/lib/_chunks-cjs/util.is-empty-text-block.cjs.map +0 -1
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +0 -23
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +0 -1
- package/lib/_chunks-cjs/util.slice-text-block.cjs +0 -63
- package/lib/_chunks-cjs/util.slice-text-block.cjs.map +0 -1
- package/lib/_chunks-dts/behavior.types.action.d.cts +0 -3650
- package/lib/behaviors/index.cjs +0 -35
- package/lib/behaviors/index.cjs.map +0 -1
- package/lib/behaviors/index.d.cts +0 -2
- package/lib/index.cjs +0 -12952
- package/lib/index.cjs.map +0 -1
- package/lib/index.d.cts +0 -2
- package/lib/plugins/index.cjs +0 -826
- package/lib/plugins/index.cjs.map +0 -1
- package/lib/plugins/index.d.cts +0 -196
- package/lib/selectors/index.cjs +0 -243
- package/lib/selectors/index.cjs.map +0 -1
- package/lib/selectors/index.d.cts +0 -357
- package/lib/utils/index.cjs +0 -97
- package/lib/utils/index.cjs.map +0 -1
- package/lib/utils/index.d.cts +0 -186
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
import { BlockOffset, BlockPath, ChildPath, EditorSelection, EditorSelectionPoint, EditorSelector } from "../_chunks-dts/behavior.types.action.cjs";
|
|
2
|
-
import { KeyedSegment, PortableTextBlock, PortableTextListBlock, PortableTextObject, PortableTextSpan, PortableTextTextBlock } from "@sanity/types";
|
|
3
|
-
/**
|
|
4
|
-
* @public
|
|
5
|
-
*/
|
|
6
|
-
declare const getActiveAnnotations: EditorSelector<Array<PortableTextObject>>;
|
|
7
|
-
/**
|
|
8
|
-
* @public
|
|
9
|
-
*/
|
|
10
|
-
declare const getActiveListItem: EditorSelector<PortableTextListBlock['listItem'] | undefined>;
|
|
11
|
-
/**
|
|
12
|
-
* @public
|
|
13
|
-
*/
|
|
14
|
-
declare const getActiveStyle: EditorSelector<PortableTextTextBlock['style']>;
|
|
15
|
-
/**
|
|
16
|
-
* @public
|
|
17
|
-
*/
|
|
18
|
-
declare const getAnchorBlock: EditorSelector<{
|
|
19
|
-
node: PortableTextBlock;
|
|
20
|
-
path: BlockPath;
|
|
21
|
-
} | undefined>;
|
|
22
|
-
/**
|
|
23
|
-
* @public
|
|
24
|
-
*/
|
|
25
|
-
declare const getAnchorChild: EditorSelector<{
|
|
26
|
-
node: PortableTextObject | PortableTextSpan;
|
|
27
|
-
path: ChildPath;
|
|
28
|
-
} | undefined>;
|
|
29
|
-
/**
|
|
30
|
-
* @public
|
|
31
|
-
*/
|
|
32
|
-
declare const getAnchorSpan: EditorSelector<{
|
|
33
|
-
node: PortableTextSpan;
|
|
34
|
-
path: ChildPath;
|
|
35
|
-
} | undefined>;
|
|
36
|
-
/**
|
|
37
|
-
* @public
|
|
38
|
-
*/
|
|
39
|
-
declare const getAnchorTextBlock: EditorSelector<{
|
|
40
|
-
node: PortableTextTextBlock;
|
|
41
|
-
path: BlockPath;
|
|
42
|
-
} | undefined>;
|
|
43
|
-
/**
|
|
44
|
-
* @public
|
|
45
|
-
*/
|
|
46
|
-
declare const getBlockOffsets: EditorSelector<{
|
|
47
|
-
start: BlockOffset;
|
|
48
|
-
end: BlockOffset;
|
|
49
|
-
} | undefined>;
|
|
50
|
-
/**
|
|
51
|
-
* @public
|
|
52
|
-
* Returns the selection of the of the word the caret is placed in.
|
|
53
|
-
* Note: Only returns a word selection if the current selection is collapsed
|
|
54
|
-
*/
|
|
55
|
-
declare const getCaretWordSelection: EditorSelector<EditorSelection>;
|
|
56
|
-
/**
|
|
57
|
-
* @public
|
|
58
|
-
*/
|
|
59
|
-
declare const getFirstBlock: EditorSelector<{
|
|
60
|
-
node: PortableTextBlock;
|
|
61
|
-
path: BlockPath;
|
|
62
|
-
} | undefined>;
|
|
63
|
-
/**
|
|
64
|
-
* @public
|
|
65
|
-
*/
|
|
66
|
-
declare const getFocusBlock: EditorSelector<{
|
|
67
|
-
node: PortableTextBlock;
|
|
68
|
-
path: BlockPath;
|
|
69
|
-
} | undefined>;
|
|
70
|
-
/**
|
|
71
|
-
* @public
|
|
72
|
-
*/
|
|
73
|
-
declare const getFocusBlockObject: EditorSelector<{
|
|
74
|
-
node: PortableTextObject;
|
|
75
|
-
path: BlockPath;
|
|
76
|
-
} | undefined>;
|
|
77
|
-
/**
|
|
78
|
-
* @public
|
|
79
|
-
*/
|
|
80
|
-
declare const getFocusChild: EditorSelector<{
|
|
81
|
-
node: PortableTextObject | PortableTextSpan;
|
|
82
|
-
path: ChildPath;
|
|
83
|
-
} | undefined>;
|
|
84
|
-
/**
|
|
85
|
-
* @public
|
|
86
|
-
*/
|
|
87
|
-
declare const getFocusInlineObject: EditorSelector<{
|
|
88
|
-
node: PortableTextObject;
|
|
89
|
-
path: ChildPath;
|
|
90
|
-
} | undefined>;
|
|
91
|
-
/**
|
|
92
|
-
* @public
|
|
93
|
-
*/
|
|
94
|
-
declare const getFocusListBlock: EditorSelector<{
|
|
95
|
-
node: PortableTextListBlock;
|
|
96
|
-
path: BlockPath;
|
|
97
|
-
} | undefined>;
|
|
98
|
-
/**
|
|
99
|
-
* @public
|
|
100
|
-
*/
|
|
101
|
-
declare const getFocusSpan: EditorSelector<{
|
|
102
|
-
node: PortableTextSpan;
|
|
103
|
-
path: ChildPath;
|
|
104
|
-
} | undefined>;
|
|
105
|
-
/**
|
|
106
|
-
* @public
|
|
107
|
-
*/
|
|
108
|
-
declare const getFocusTextBlock: EditorSelector<{
|
|
109
|
-
node: PortableTextTextBlock;
|
|
110
|
-
path: BlockPath;
|
|
111
|
-
} | undefined>;
|
|
112
|
-
/**
|
|
113
|
-
* @public
|
|
114
|
-
*/
|
|
115
|
-
declare const getLastBlock: EditorSelector<{
|
|
116
|
-
node: PortableTextBlock;
|
|
117
|
-
path: BlockPath;
|
|
118
|
-
} | undefined>;
|
|
119
|
-
/**
|
|
120
|
-
* @beta
|
|
121
|
-
* @deprecated Use the precomputed `data-list-index` on text blocks instead.
|
|
122
|
-
* Given the `path` of a block, this selector will return the "list index" of
|
|
123
|
-
* the block.
|
|
124
|
-
*/
|
|
125
|
-
declare function getListIndex({
|
|
126
|
-
path
|
|
127
|
-
}: {
|
|
128
|
-
path: BlockPath;
|
|
129
|
-
}): EditorSelector<number | undefined>;
|
|
130
|
-
/**
|
|
131
|
-
* @beta
|
|
132
|
-
*/
|
|
133
|
-
type MarkState = {
|
|
134
|
-
state: 'unchanged';
|
|
135
|
-
marks: Array<string>;
|
|
136
|
-
} | {
|
|
137
|
-
state: 'changed';
|
|
138
|
-
marks: Array<string>;
|
|
139
|
-
previousMarks: Array<string>;
|
|
140
|
-
};
|
|
141
|
-
/**
|
|
142
|
-
* Given that text is inserted at the current position, what marks should
|
|
143
|
-
* be applied?
|
|
144
|
-
* @beta
|
|
145
|
-
*/
|
|
146
|
-
declare const getMarkState: EditorSelector<MarkState | undefined>;
|
|
147
|
-
/**
|
|
148
|
-
* @public
|
|
149
|
-
*/
|
|
150
|
-
declare const getNextBlock: EditorSelector<{
|
|
151
|
-
node: PortableTextBlock;
|
|
152
|
-
path: BlockPath;
|
|
153
|
-
} | undefined>;
|
|
154
|
-
/**
|
|
155
|
-
* @public
|
|
156
|
-
*/
|
|
157
|
-
declare const getNextInlineObject: EditorSelector<{
|
|
158
|
-
node: PortableTextObject;
|
|
159
|
-
path: ChildPath;
|
|
160
|
-
} | undefined>;
|
|
161
|
-
/**
|
|
162
|
-
* @public
|
|
163
|
-
*/
|
|
164
|
-
declare const getNextInlineObjects: EditorSelector<Array<{
|
|
165
|
-
node: PortableTextObject;
|
|
166
|
-
path: ChildPath;
|
|
167
|
-
}>>;
|
|
168
|
-
/**
|
|
169
|
-
* @public
|
|
170
|
-
*/
|
|
171
|
-
declare const getNextSpan: EditorSelector<{
|
|
172
|
-
node: PortableTextSpan;
|
|
173
|
-
path: [KeyedSegment, 'children', KeyedSegment];
|
|
174
|
-
} | undefined>;
|
|
175
|
-
/**
|
|
176
|
-
* @public
|
|
177
|
-
*/
|
|
178
|
-
declare const getPreviousBlock: EditorSelector<{
|
|
179
|
-
node: PortableTextBlock;
|
|
180
|
-
path: BlockPath;
|
|
181
|
-
} | undefined>;
|
|
182
|
-
/**
|
|
183
|
-
* @public
|
|
184
|
-
*/
|
|
185
|
-
declare const getPreviousInlineObject: EditorSelector<{
|
|
186
|
-
node: PortableTextObject;
|
|
187
|
-
path: ChildPath;
|
|
188
|
-
} | undefined>;
|
|
189
|
-
/**
|
|
190
|
-
* @public
|
|
191
|
-
*/
|
|
192
|
-
declare const getPreviousInlineObjects: EditorSelector<Array<{
|
|
193
|
-
node: PortableTextObject;
|
|
194
|
-
path: ChildPath;
|
|
195
|
-
}>>;
|
|
196
|
-
/**
|
|
197
|
-
* @public
|
|
198
|
-
*/
|
|
199
|
-
declare const getPreviousSpan: EditorSelector<{
|
|
200
|
-
node: PortableTextSpan;
|
|
201
|
-
path: [KeyedSegment, 'children', KeyedSegment];
|
|
202
|
-
} | undefined>;
|
|
203
|
-
/**
|
|
204
|
-
* @public
|
|
205
|
-
*/
|
|
206
|
-
declare const getSelectedBlocks: EditorSelector<Array<{
|
|
207
|
-
node: PortableTextBlock;
|
|
208
|
-
path: BlockPath;
|
|
209
|
-
}>>;
|
|
210
|
-
/**
|
|
211
|
-
* @public
|
|
212
|
-
* @deprecated Renamed to `getSelectedValue`.
|
|
213
|
-
*/
|
|
214
|
-
declare const getSelectedSlice: EditorSelector<Array<PortableTextBlock>>;
|
|
215
|
-
/**
|
|
216
|
-
* @public
|
|
217
|
-
*/
|
|
218
|
-
declare const getSelectedSpans: EditorSelector<Array<{
|
|
219
|
-
node: PortableTextSpan;
|
|
220
|
-
path: ChildPath;
|
|
221
|
-
}>>;
|
|
222
|
-
/**
|
|
223
|
-
* @public
|
|
224
|
-
*/
|
|
225
|
-
declare const getSelectedTextBlocks: EditorSelector<Array<{
|
|
226
|
-
node: PortableTextTextBlock;
|
|
227
|
-
path: BlockPath;
|
|
228
|
-
}>>;
|
|
229
|
-
/**
|
|
230
|
-
* @public
|
|
231
|
-
*/
|
|
232
|
-
declare const getSelectedValue: EditorSelector<Array<PortableTextBlock>>;
|
|
233
|
-
/**
|
|
234
|
-
* @public
|
|
235
|
-
*/
|
|
236
|
-
declare const getSelection: EditorSelector<EditorSelection>;
|
|
237
|
-
/**
|
|
238
|
-
* @public
|
|
239
|
-
*/
|
|
240
|
-
declare const getSelectionEndBlock: EditorSelector<{
|
|
241
|
-
node: PortableTextBlock;
|
|
242
|
-
path: BlockPath;
|
|
243
|
-
} | undefined>;
|
|
244
|
-
/**
|
|
245
|
-
* @public
|
|
246
|
-
*/
|
|
247
|
-
declare const getSelectionEndChild: EditorSelector<{
|
|
248
|
-
node: PortableTextSpan | PortableTextObject;
|
|
249
|
-
path: ChildPath;
|
|
250
|
-
} | undefined>;
|
|
251
|
-
/**
|
|
252
|
-
* @public
|
|
253
|
-
*/
|
|
254
|
-
declare const getSelectionEndPoint: EditorSelector<EditorSelectionPoint | undefined>;
|
|
255
|
-
/**
|
|
256
|
-
* @public
|
|
257
|
-
*/
|
|
258
|
-
declare const getSelectionStartBlock: EditorSelector<{
|
|
259
|
-
node: PortableTextBlock;
|
|
260
|
-
path: BlockPath;
|
|
261
|
-
} | undefined>;
|
|
262
|
-
/**
|
|
263
|
-
* @public
|
|
264
|
-
*/
|
|
265
|
-
declare const getSelectionStartChild: EditorSelector<{
|
|
266
|
-
node: PortableTextSpan | PortableTextObject;
|
|
267
|
-
path: ChildPath;
|
|
268
|
-
} | undefined>;
|
|
269
|
-
/**
|
|
270
|
-
* @public
|
|
271
|
-
*/
|
|
272
|
-
declare const getSelectionStartPoint: EditorSelector<EditorSelectionPoint | undefined>;
|
|
273
|
-
/**
|
|
274
|
-
* @public
|
|
275
|
-
*/
|
|
276
|
-
declare const getSelectionText: EditorSelector<string>;
|
|
277
|
-
/**
|
|
278
|
-
* @public
|
|
279
|
-
*/
|
|
280
|
-
declare const getBlockTextAfter: EditorSelector<string>;
|
|
281
|
-
/**
|
|
282
|
-
* @public
|
|
283
|
-
*/
|
|
284
|
-
declare const getBlockTextBefore: EditorSelector<string>;
|
|
285
|
-
/**
|
|
286
|
-
* @public
|
|
287
|
-
*/
|
|
288
|
-
declare const getTrimmedSelection: EditorSelector<EditorSelection>;
|
|
289
|
-
/**
|
|
290
|
-
* @public
|
|
291
|
-
*/
|
|
292
|
-
declare const getValue: EditorSelector<Array<PortableTextBlock>>;
|
|
293
|
-
/**
|
|
294
|
-
* Check whether an annotation is active in the given `snapshot`.
|
|
295
|
-
*
|
|
296
|
-
* @public
|
|
297
|
-
*/
|
|
298
|
-
declare function isActiveAnnotation(annotation: string, options?: {
|
|
299
|
-
/**
|
|
300
|
-
* Choose whether the annotation has to take up the entire selection in the
|
|
301
|
-
* `snapshot` or if the annotation can be partially selected.
|
|
302
|
-
*
|
|
303
|
-
* Defaults to 'full'
|
|
304
|
-
*/
|
|
305
|
-
mode?: 'partial' | 'full';
|
|
306
|
-
}): EditorSelector<boolean>;
|
|
307
|
-
/**
|
|
308
|
-
* @public
|
|
309
|
-
*/
|
|
310
|
-
declare function isActiveDecorator(decorator: string): EditorSelector<boolean>;
|
|
311
|
-
/**
|
|
312
|
-
* @public
|
|
313
|
-
*/
|
|
314
|
-
declare function isActiveListItem(listItem: string): EditorSelector<boolean>;
|
|
315
|
-
/**
|
|
316
|
-
* @public
|
|
317
|
-
*/
|
|
318
|
-
declare function isActiveStyle(style: string): EditorSelector<boolean>;
|
|
319
|
-
/**
|
|
320
|
-
* @public
|
|
321
|
-
*/
|
|
322
|
-
declare function isAtTheEndOfBlock(block: {
|
|
323
|
-
node: PortableTextBlock;
|
|
324
|
-
path: BlockPath;
|
|
325
|
-
}): EditorSelector<boolean>;
|
|
326
|
-
/**
|
|
327
|
-
* @public
|
|
328
|
-
*/
|
|
329
|
-
declare function isAtTheStartOfBlock(block: {
|
|
330
|
-
node: PortableTextBlock;
|
|
331
|
-
path: BlockPath;
|
|
332
|
-
}): EditorSelector<boolean>;
|
|
333
|
-
/**
|
|
334
|
-
* @public
|
|
335
|
-
*/
|
|
336
|
-
declare function isOverlappingSelection(selection: EditorSelection): EditorSelector<boolean>;
|
|
337
|
-
/**
|
|
338
|
-
* @public
|
|
339
|
-
*/
|
|
340
|
-
declare function isPointAfterSelection(point: EditorSelectionPoint): EditorSelector<boolean>;
|
|
341
|
-
/**
|
|
342
|
-
* @public
|
|
343
|
-
*/
|
|
344
|
-
declare function isPointBeforeSelection(point: EditorSelectionPoint): EditorSelector<boolean>;
|
|
345
|
-
/**
|
|
346
|
-
* @public
|
|
347
|
-
*/
|
|
348
|
-
declare const isSelectingEntireBlocks: EditorSelector<boolean>;
|
|
349
|
-
/**
|
|
350
|
-
* @public
|
|
351
|
-
*/
|
|
352
|
-
declare const isSelectionCollapsed: EditorSelector<boolean>;
|
|
353
|
-
/**
|
|
354
|
-
* @public
|
|
355
|
-
*/
|
|
356
|
-
declare const isSelectionExpanded: EditorSelector<boolean>;
|
|
357
|
-
export { MarkState, getActiveAnnotations, getActiveListItem, getActiveStyle, getAnchorBlock, getAnchorChild, getAnchorSpan, getAnchorTextBlock, getBlockOffsets, getBlockTextAfter, getBlockTextBefore, getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusInlineObject, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getListIndex, getMarkState, getNextBlock, getNextInlineObject, getNextInlineObjects, getNextSpan, getPreviousBlock, getPreviousInlineObject, getPreviousInlineObjects, getPreviousSpan, getSelectedBlocks, getSelectedSlice, getSelectedSpans, getSelectedTextBlocks, getSelectedValue, getSelection, getSelectionEndBlock, getSelectionEndChild, getSelectionEndPoint, getSelectionStartBlock, getSelectionStartChild, getSelectionStartPoint, getSelectionText, getTrimmedSelection, getValue, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks, isSelectionCollapsed, isSelectionExpanded };
|
package/lib/utils/index.cjs
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var util_getTextBlockText = require("../_chunks-cjs/util.get-text-block-text.cjs"), util_childSelectionPointToBlockOffset = require("../_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), util_isEmptyTextBlock = require("../_chunks-cjs/util.is-empty-text-block.cjs"), schema = require("@portabletext/schema"), util_mergeTextBlocks = require("../_chunks-cjs/util.merge-text-blocks.cjs"), util_sliceTextBlock = require("../_chunks-cjs/util.slice-text-block.cjs");
|
|
4
|
-
function isEqualSelections(a, b) {
|
|
5
|
-
return !a && !b ? !0 : !a || !b ? !1 : util_isEmptyTextBlock.isEqualSelectionPoints(a.anchor, b.anchor) && util_isEmptyTextBlock.isEqualSelectionPoints(a.focus, b.focus);
|
|
6
|
-
}
|
|
7
|
-
function reverseSelection(selection) {
|
|
8
|
-
return selection && (selection.backward ? {
|
|
9
|
-
anchor: selection.focus,
|
|
10
|
-
focus: selection.anchor,
|
|
11
|
-
backward: !1
|
|
12
|
-
} : {
|
|
13
|
-
anchor: selection.focus,
|
|
14
|
-
focus: selection.anchor,
|
|
15
|
-
backward: !0
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
function splitTextBlock({
|
|
19
|
-
context,
|
|
20
|
-
block,
|
|
21
|
-
point
|
|
22
|
-
}) {
|
|
23
|
-
const firstChild = block.children.at(0), lastChild = block.children.at(block.children.length - 1);
|
|
24
|
-
if (!firstChild || !lastChild)
|
|
25
|
-
return;
|
|
26
|
-
const before = util_sliceTextBlock.sliceTextBlock({
|
|
27
|
-
context: {
|
|
28
|
-
schema: context.schema,
|
|
29
|
-
selection: {
|
|
30
|
-
anchor: {
|
|
31
|
-
path: [{
|
|
32
|
-
_key: block._key
|
|
33
|
-
}, "children", {
|
|
34
|
-
_key: firstChild._key
|
|
35
|
-
}],
|
|
36
|
-
offset: 0
|
|
37
|
-
},
|
|
38
|
-
focus: point
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
block
|
|
42
|
-
}), after = util_sliceTextBlock.sliceTextBlock({
|
|
43
|
-
context: {
|
|
44
|
-
schema: context.schema,
|
|
45
|
-
selection: {
|
|
46
|
-
anchor: point,
|
|
47
|
-
focus: {
|
|
48
|
-
path: [{
|
|
49
|
-
_key: block._key
|
|
50
|
-
}, "children", {
|
|
51
|
-
_key: lastChild._key
|
|
52
|
-
}],
|
|
53
|
-
offset: schema.isSpan(context, lastChild) ? lastChild.text.length : 0
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
block
|
|
58
|
-
});
|
|
59
|
-
return {
|
|
60
|
-
before,
|
|
61
|
-
after
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
exports.blockOffsetToSpanSelectionPoint = util_getTextBlockText.blockOffsetToSpanSelectionPoint;
|
|
65
|
-
exports.getBlockStartPoint = util_getTextBlockText.getBlockStartPoint;
|
|
66
|
-
exports.getSelectionEndPoint = util_getTextBlockText.getSelectionEndPoint;
|
|
67
|
-
exports.getSelectionStartPoint = util_getTextBlockText.getSelectionStartPoint;
|
|
68
|
-
exports.getTextBlockText = util_getTextBlockText.getTextBlockText;
|
|
69
|
-
exports.isKeyedSegment = util_getTextBlockText.isKeyedSegment;
|
|
70
|
-
exports.sliceBlocks = util_getTextBlockText.sliceBlocks;
|
|
71
|
-
exports.spanSelectionPointToBlockOffset = util_getTextBlockText.spanSelectionPointToBlockOffset;
|
|
72
|
-
exports.blockOffsetToBlockSelectionPoint = util_childSelectionPointToBlockOffset.blockOffsetToBlockSelectionPoint;
|
|
73
|
-
exports.blockOffsetToSelectionPoint = util_childSelectionPointToBlockOffset.blockOffsetToSelectionPoint;
|
|
74
|
-
exports.blockOffsetsToSelection = util_childSelectionPointToBlockOffset.blockOffsetsToSelection;
|
|
75
|
-
exports.childSelectionPointToBlockOffset = util_childSelectionPointToBlockOffset.childSelectionPointToBlockOffset;
|
|
76
|
-
exports.getBlockEndPoint = util_isEmptyTextBlock.getBlockEndPoint;
|
|
77
|
-
exports.isEmptyTextBlock = util_isEmptyTextBlock.isEmptyTextBlock;
|
|
78
|
-
exports.isEqualSelectionPoints = util_isEmptyTextBlock.isEqualSelectionPoints;
|
|
79
|
-
exports.isSelectionCollapsed = util_isEmptyTextBlock.isSelectionCollapsed;
|
|
80
|
-
Object.defineProperty(exports, "isSpan", {
|
|
81
|
-
enumerable: !0,
|
|
82
|
-
get: function() {
|
|
83
|
-
return schema.isSpan;
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
Object.defineProperty(exports, "isTextBlock", {
|
|
87
|
-
enumerable: !0,
|
|
88
|
-
get: function() {
|
|
89
|
-
return schema.isTextBlock;
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
exports.mergeTextBlocks = util_mergeTextBlocks.mergeTextBlocks;
|
|
93
|
-
exports.selectionPointToBlockOffset = util_sliceTextBlock.selectionPointToBlockOffset;
|
|
94
|
-
exports.isEqualSelections = isEqualSelections;
|
|
95
|
-
exports.reverseSelection = reverseSelection;
|
|
96
|
-
exports.splitTextBlock = splitTextBlock;
|
|
97
|
-
//# sourceMappingURL=index.cjs.map
|
package/lib/utils/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.reverse-selection.ts","../../src/utils/util.split-text-block.ts"],"sourcesContent":["import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n","import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function reverseSelection<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n>(selection: TEditorSelection): TEditorSelection {\n if (!selection) {\n return selection\n }\n\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n } as TEditorSelection\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n } as TEditorSelection\n}\n","import {isSpan} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {sliceTextBlock} from './util.slice-text-block'\n\n/**\n * @beta\n */\nexport function splitTextBlock({\n context,\n block,\n point,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: PortableTextTextBlock\n point: EditorSelectionPoint\n}): {before: PortableTextTextBlock; after: PortableTextTextBlock} | undefined {\n const firstChild = block.children.at(0)\n const lastChild = block.children.at(block.children.length - 1)\n\n if (!firstChild || !lastChild) {\n return undefined\n }\n\n const before = sliceTextBlock({\n context: {\n schema: context.schema,\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n },\n block,\n })\n const after = sliceTextBlock({\n context: {\n schema: context.schema,\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n },\n block,\n })\n\n return {before, after}\n}\n"],"names":["isEqualSelections","a","b","isEqualSelectionPoints","anchor","focus","reverseSelection","selection","backward","splitTextBlock","context","block","point","firstChild","children","at","lastChild","length","before","sliceTextBlock","schema","path","_key","offset","after","isSpan","text"],"mappings":";;;AAMO,SAASA,kBAAkBC,GAAoBC,GAAoB;AACxE,SAAI,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,sBAAAA,uBAAuBF,EAAEG,QAAQF,EAAEE,MAAM,KACzCD,sBAAAA,uBAAuBF,EAAEI,OAAOH,EAAEG,KAAK;AAE3C;ACdO,SAASC,iBAEdC,WAA+C;AAC/C,SAAKA,cAIDA,UAAUC,WACL;AAAA,IACLJ,QAAQG,UAAUF;AAAAA,IAClBA,OAAOE,UAAUH;AAAAA,IACjBI,UAAU;AAAA,EAAA,IAIP;AAAA,IACLJ,QAAQG,UAAUF;AAAAA,IAClBA,OAAOE,UAAUH;AAAAA,IACjBI,UAAU;AAAA,EAAA;AAEd;AChBO,SAASC,eAAe;AAAA,EAC7BC;AAAAA,EACAC;AAAAA,EACAC;AAKF,GAA8E;AAC5E,QAAMC,aAAaF,MAAMG,SAASC,GAAG,CAAC,GAChCC,YAAYL,MAAMG,SAASC,GAAGJ,MAAMG,SAASG,SAAS,CAAC;AAE7D,MAAI,CAACJ,cAAc,CAACG;AAClB;AAGF,QAAME,SAASC,oBAAAA,eAAe;AAAA,IAC5BT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBb,WAAW;AAAA,QACTH,QAAQ;AAAA,UACNiB,MAAM,CAAC;AAAA,YAACC,MAAMX,MAAMW;AAAAA,UAAAA,GAAO,YAAY;AAAA,YAACA,MAAMT,WAAWS;AAAAA,UAAAA,CAAK;AAAA,UAC9DC,QAAQ;AAAA,QAAA;AAAA,QAEVlB,OAAOO;AAAAA,MAAAA;AAAAA,IACT;AAAA,IAEFD;AAAAA,EAAAA,CACD,GACKa,QAAQL,mCAAe;AAAA,IAC3BT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBb,WAAW;AAAA,QACTH,QAAQQ;AAAAA,QACRP,OAAO;AAAA,UACLgB,MAAM,CAAC;AAAA,YAACC,MAAMX,MAAMW;AAAAA,UAAAA,GAAO,YAAY;AAAA,YAACA,MAAMN,UAAUM;AAAAA,UAAAA,CAAK;AAAA,UAC7DC,QAAQE,OAAAA,OAAOf,SAASM,SAAS,IAAIA,UAAUU,KAAKT,SAAS;AAAA,QAAA;AAAA,MAC/D;AAAA,IACF;AAAA,IAEFN;AAAAA,EAAAA,CACD;AAED,SAAO;AAAA,IAACO;AAAAA,IAAQM;AAAAA,EAAAA;AAClB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/lib/utils/index.d.cts
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { BlockOffset, BlockPath, ChildPath, EditorContext, EditorSelection, EditorSelectionPoint } from "../_chunks-dts/behavior.types.action.cjs";
|
|
2
|
-
import * as _sanity_types8 from "@sanity/types";
|
|
3
|
-
import { KeyedSegment, PortableTextBlock, PortableTextTextBlock } from "@sanity/types";
|
|
4
|
-
import { isSpan, isTextBlock } from "@portabletext/schema";
|
|
5
|
-
/**
|
|
6
|
-
* @public
|
|
7
|
-
*/
|
|
8
|
-
declare function blockOffsetToSpanSelectionPoint({
|
|
9
|
-
context,
|
|
10
|
-
blockOffset,
|
|
11
|
-
direction
|
|
12
|
-
}: {
|
|
13
|
-
context: Pick<EditorContext, 'schema' | 'value'>;
|
|
14
|
-
blockOffset: BlockOffset;
|
|
15
|
-
direction: 'forward' | 'backward';
|
|
16
|
-
}): {
|
|
17
|
-
path: ChildPath;
|
|
18
|
-
offset: number;
|
|
19
|
-
} | undefined;
|
|
20
|
-
/**
|
|
21
|
-
* @public
|
|
22
|
-
*/
|
|
23
|
-
declare function spanSelectionPointToBlockOffset({
|
|
24
|
-
context,
|
|
25
|
-
selectionPoint
|
|
26
|
-
}: {
|
|
27
|
-
context: Pick<EditorContext, 'schema' | 'value'>;
|
|
28
|
-
selectionPoint: EditorSelectionPoint;
|
|
29
|
-
}): BlockOffset | undefined;
|
|
30
|
-
/**
|
|
31
|
-
* @public
|
|
32
|
-
*/
|
|
33
|
-
declare function blockOffsetToBlockSelectionPoint({
|
|
34
|
-
context,
|
|
35
|
-
blockOffset
|
|
36
|
-
}: {
|
|
37
|
-
context: Pick<EditorContext, 'value'>;
|
|
38
|
-
blockOffset: BlockOffset;
|
|
39
|
-
}): EditorSelectionPoint | undefined;
|
|
40
|
-
/**
|
|
41
|
-
* @public
|
|
42
|
-
*/
|
|
43
|
-
declare function blockOffsetToSelectionPoint({
|
|
44
|
-
context,
|
|
45
|
-
blockOffset,
|
|
46
|
-
direction
|
|
47
|
-
}: {
|
|
48
|
-
context: Pick<EditorContext, 'schema' | 'value'>;
|
|
49
|
-
blockOffset: BlockOffset;
|
|
50
|
-
direction: 'forward' | 'backward';
|
|
51
|
-
}): EditorSelectionPoint | undefined;
|
|
52
|
-
/**
|
|
53
|
-
* @public
|
|
54
|
-
*/
|
|
55
|
-
declare function blockOffsetsToSelection({
|
|
56
|
-
context,
|
|
57
|
-
offsets,
|
|
58
|
-
backward
|
|
59
|
-
}: {
|
|
60
|
-
context: Pick<EditorContext, 'schema' | 'value'>;
|
|
61
|
-
offsets: {
|
|
62
|
-
anchor: BlockOffset;
|
|
63
|
-
focus: BlockOffset;
|
|
64
|
-
};
|
|
65
|
-
backward?: boolean;
|
|
66
|
-
}): EditorSelection;
|
|
67
|
-
/**
|
|
68
|
-
* @public
|
|
69
|
-
*/
|
|
70
|
-
declare function childSelectionPointToBlockOffset({
|
|
71
|
-
context,
|
|
72
|
-
selectionPoint
|
|
73
|
-
}: {
|
|
74
|
-
context: Pick<EditorContext, 'schema' | 'value'>;
|
|
75
|
-
selectionPoint: EditorSelectionPoint;
|
|
76
|
-
}): BlockOffset | undefined;
|
|
77
|
-
/**
|
|
78
|
-
* @public
|
|
79
|
-
*/
|
|
80
|
-
declare function getBlockEndPoint({
|
|
81
|
-
context,
|
|
82
|
-
block
|
|
83
|
-
}: {
|
|
84
|
-
context: Pick<EditorContext, 'schema'>;
|
|
85
|
-
block: {
|
|
86
|
-
node: PortableTextBlock;
|
|
87
|
-
path: BlockPath;
|
|
88
|
-
};
|
|
89
|
-
}): EditorSelectionPoint;
|
|
90
|
-
/**
|
|
91
|
-
* @public
|
|
92
|
-
*/
|
|
93
|
-
declare function getBlockStartPoint({
|
|
94
|
-
context,
|
|
95
|
-
block
|
|
96
|
-
}: {
|
|
97
|
-
context: Pick<EditorContext, 'schema'>;
|
|
98
|
-
block: {
|
|
99
|
-
node: PortableTextBlock;
|
|
100
|
-
path: BlockPath;
|
|
101
|
-
};
|
|
102
|
-
}): EditorSelectionPoint;
|
|
103
|
-
/**
|
|
104
|
-
* @public
|
|
105
|
-
*/
|
|
106
|
-
declare function getSelectionEndPoint<TEditorSelection extends NonNullable<EditorSelection> | null, TEditorSelectionPoint extends EditorSelectionPoint | null = (TEditorSelection extends NonNullable<EditorSelection> ? EditorSelectionPoint : null)>(selection: TEditorSelection): TEditorSelectionPoint;
|
|
107
|
-
/**
|
|
108
|
-
* @public
|
|
109
|
-
*/
|
|
110
|
-
declare function getSelectionStartPoint<TEditorSelection extends NonNullable<EditorSelection> | null, TEditorSelectionPoint extends EditorSelectionPoint | null = (TEditorSelection extends NonNullable<EditorSelection> ? EditorSelectionPoint : null)>(selection: TEditorSelection): TEditorSelectionPoint;
|
|
111
|
-
/**
|
|
112
|
-
* @public
|
|
113
|
-
*/
|
|
114
|
-
declare function getTextBlockText(block: PortableTextTextBlock): string;
|
|
115
|
-
/**
|
|
116
|
-
* @public
|
|
117
|
-
*/
|
|
118
|
-
declare function isEmptyTextBlock(context: Pick<EditorContext, 'schema'>, block: PortableTextBlock): boolean;
|
|
119
|
-
/**
|
|
120
|
-
* @public
|
|
121
|
-
*/
|
|
122
|
-
declare function isEqualSelectionPoints(a: EditorSelectionPoint, b: EditorSelectionPoint): boolean;
|
|
123
|
-
/**
|
|
124
|
-
* @public
|
|
125
|
-
*/
|
|
126
|
-
declare function isEqualSelections(a: EditorSelection, b: EditorSelection): boolean;
|
|
127
|
-
/**
|
|
128
|
-
* @public
|
|
129
|
-
*/
|
|
130
|
-
declare function isKeyedSegment(segment: unknown): segment is KeyedSegment;
|
|
131
|
-
/**
|
|
132
|
-
* @public
|
|
133
|
-
*/
|
|
134
|
-
declare function isSelectionCollapsed(selection: EditorSelection): boolean;
|
|
135
|
-
/**
|
|
136
|
-
* @beta
|
|
137
|
-
*/
|
|
138
|
-
declare function mergeTextBlocks({
|
|
139
|
-
context,
|
|
140
|
-
targetBlock,
|
|
141
|
-
incomingBlock
|
|
142
|
-
}: {
|
|
143
|
-
context: Pick<EditorContext, 'keyGenerator' | 'schema'>;
|
|
144
|
-
targetBlock: PortableTextTextBlock;
|
|
145
|
-
incomingBlock: PortableTextTextBlock;
|
|
146
|
-
}): PortableTextTextBlock<_sanity_types8.PortableTextObject | _sanity_types8.PortableTextSpan>;
|
|
147
|
-
/**
|
|
148
|
-
* @public
|
|
149
|
-
*/
|
|
150
|
-
declare function reverseSelection<TEditorSelection extends NonNullable<EditorSelection> | null>(selection: TEditorSelection): TEditorSelection;
|
|
151
|
-
/**
|
|
152
|
-
* @public
|
|
153
|
-
*/
|
|
154
|
-
declare function selectionPointToBlockOffset({
|
|
155
|
-
context,
|
|
156
|
-
selectionPoint
|
|
157
|
-
}: {
|
|
158
|
-
context: Pick<EditorContext, 'schema' | 'value'>;
|
|
159
|
-
selectionPoint: EditorSelectionPoint;
|
|
160
|
-
}): BlockOffset | undefined;
|
|
161
|
-
/**
|
|
162
|
-
* @public
|
|
163
|
-
*/
|
|
164
|
-
declare function sliceBlocks({
|
|
165
|
-
context,
|
|
166
|
-
blocks
|
|
167
|
-
}: {
|
|
168
|
-
context: Pick<EditorContext, 'schema' | 'selection'>;
|
|
169
|
-
blocks: Array<PortableTextBlock>;
|
|
170
|
-
}): Array<PortableTextBlock>;
|
|
171
|
-
/**
|
|
172
|
-
* @beta
|
|
173
|
-
*/
|
|
174
|
-
declare function splitTextBlock({
|
|
175
|
-
context,
|
|
176
|
-
block,
|
|
177
|
-
point
|
|
178
|
-
}: {
|
|
179
|
-
context: Pick<EditorContext, 'schema'>;
|
|
180
|
-
block: PortableTextTextBlock;
|
|
181
|
-
point: EditorSelectionPoint;
|
|
182
|
-
}): {
|
|
183
|
-
before: PortableTextTextBlock;
|
|
184
|
-
after: PortableTextTextBlock;
|
|
185
|
-
} | undefined;
|
|
186
|
-
export { blockOffsetToBlockSelectionPoint, blockOffsetToSelectionPoint, blockOffsetToSpanSelectionPoint, blockOffsetsToSelection, childSelectionPointToBlockOffset, getBlockEndPoint, getBlockStartPoint, getSelectionEndPoint, getSelectionStartPoint, getTextBlockText, isEmptyTextBlock, isEqualSelectionPoints, isEqualSelections, isKeyedSegment, isSelectionCollapsed, isSpan, isTextBlock, mergeTextBlocks, reverseSelection, selectionPointToBlockOffset, sliceBlocks, spanSelectionPointToBlockOffset, splitTextBlock };
|