@portabletext/editor 1.57.3 → 1.57.5
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-cjs/selector.get-text-before.cjs +3 -3
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +114 -114
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/{selector.get-focus-span.cjs → selector.is-selection-expanded.cjs} +25 -25
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -0
- package/lib/_chunks-es/selector.get-text-before.js +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +93 -93
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/{selector.get-focus-span.js → selector.is-selection-expanded.js} +26 -26
- package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -0
- package/lib/index.cjs +143 -137
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +108 -102
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +16 -16
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.js +1 -1
- package/lib/selectors/index.cjs +14 -14
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.js +2 -2
- package/package.json +13 -13
- package/src/editor/Editable.tsx +1 -1
- package/src/editor/editor-dom.ts +1 -1
- package/src/editor/plugins/createWithEditableAPI.ts +1 -1
- package/src/editor/range-decorations-machine.ts +2 -1
- package/src/internal-utils/__tests__/ranges.test.ts +1 -1
- package/src/internal-utils/move-range-by-operation.ts +19 -0
- package/src/internal-utils/{ranges.test.ts → to-slate-range.test.ts} +101 -1
- package/src/internal-utils/to-slate-range.ts +171 -0
- package/src/operations/behavior.operation.block.set.ts +1 -1
- package/src/operations/behavior.operation.block.unset.ts +1 -1
- package/src/operations/behavior.operation.child.set.ts +1 -1
- package/src/operations/behavior.operation.child.unset.ts +1 -1
- package/src/operations/behavior.operation.decorator.add.ts +1 -1
- package/src/operations/behavior.operation.delete.ts +25 -1
- package/src/operations/behavior.operation.move.block.ts +34 -28
- package/src/operations/behavior.operation.select.ts +1 -1
- package/src/selectors/selector.get-mark-state.ts +3 -1
- package/lib/_chunks-cjs/selector.get-focus-span.cjs.map +0 -1
- package/lib/_chunks-es/selector.get-focus-span.js.map +0 -1
- package/src/internal-utils/paths.ts +0 -110
- package/src/internal-utils/ranges.ts +0 -70
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var util_sliceBlocks = require("./util.slice-blocks.cjs"),
|
|
2
|
+
var util_sliceBlocks = require("./util.slice-blocks.cjs"), selector_isSelectionExpanded = require("./selector.is-selection-expanded.cjs");
|
|
3
3
|
const getBlockTextBefore = (snapshot) => {
|
|
4
4
|
if (!snapshot.context.selection)
|
|
5
5
|
return "";
|
|
6
|
-
const startPoint = util_sliceBlocks.getSelectionStartPoint(snapshot.context.selection), block =
|
|
6
|
+
const startPoint = util_sliceBlocks.getSelectionStartPoint(snapshot.context.selection), block = selector_isSelectionExpanded.getFocusBlock({
|
|
7
7
|
...snapshot,
|
|
8
8
|
context: {
|
|
9
9
|
...snapshot.context,
|
|
@@ -19,7 +19,7 @@ const getBlockTextBefore = (snapshot) => {
|
|
|
19
19
|
context: snapshot.context,
|
|
20
20
|
block
|
|
21
21
|
});
|
|
22
|
-
return
|
|
22
|
+
return selector_isSelectionExpanded.getSelectionText({
|
|
23
23
|
...snapshot,
|
|
24
24
|
context: {
|
|
25
25
|
...snapshot.context,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selector.get-text-before.cjs","sources":["../../src/selectors/selector.get-text-before.ts"],"sourcesContent":["import type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectionStartPoint} from '../utils'\nimport {getBlockStartPoint} from '../utils/util.get-block-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"],"names":["getBlockTextBefore","snapshot","context","selection","startPoint","getSelectionStartPoint","block","getFocusBlock","anchor","focus","startOfBlock","getBlockStartPoint","getSelectionText"],"mappings":";;AASO,MAAMA,qBAA8CC,CAAAA,aAAa;AACtE,MAAI,CAACA,SAASC,QAAQC;AACpB,WAAO;AAGT,QAAMC,aAAaC,iBAAAA,uBAAuBJ,SAASC,QAAQC,SAAS,GAC9DG,QAAQC,
|
|
1
|
+
{"version":3,"file":"selector.get-text-before.cjs","sources":["../../src/selectors/selector.get-text-before.ts"],"sourcesContent":["import type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectionStartPoint} from '../utils'\nimport {getBlockStartPoint} from '../utils/util.get-block-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"],"names":["getBlockTextBefore","snapshot","context","selection","startPoint","getSelectionStartPoint","block","getFocusBlock","anchor","focus","startOfBlock","getBlockStartPoint","getSelectionText"],"mappings":";;AASO,MAAMA,qBAA8CC,CAAAA,aAAa;AACtE,MAAI,CAACA,SAASC,QAAQC;AACpB,WAAO;AAGT,QAAMC,aAAaC,iBAAAA,uBAAuBJ,SAASC,QAAQC,SAAS,GAC9DG,QAAQC,2CAAc;AAAA,IAC1B,GAAGN;AAAAA,IACHC,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTK,QAAQJ;AAAAA,QACRK,OAAOL;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AAED,MAAI,CAACE;AACH,WAAO;AAGT,QAAMI,eAAeC,iBAAAA,mBAAmB;AAAA,IACtCT,SAASD,SAASC;AAAAA,IAClBI;AAAAA,EAAAA,CACD;AAED,SAAOM,8CAAiB;AAAA,IACtB,GAAGX;AAAAA,IACHC,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTK,QAAQE;AAAAA,QACRD,OAAOL;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AACH;;"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var util_sliceBlocks = require("./util.slice-blocks.cjs"), util_isSelectionCollapsed = require("./util.is-selection-collapsed.cjs"),
|
|
2
|
+
var util_sliceBlocks = require("./util.slice-blocks.cjs"), util_isSelectionCollapsed = require("./util.is-selection-collapsed.cjs"), selector_isSelectionExpanded = require("./selector.is-selection-expanded.cjs"), types = require("@sanity/types");
|
|
3
3
|
function isSelectionExpanded(selection) {
|
|
4
4
|
return selection ? !util_isSelectionCollapsed.isSelectionCollapsed(selection) : !1;
|
|
5
5
|
}
|
|
6
6
|
const getSelectionEndBlock = (snapshot) => {
|
|
7
7
|
const endPoint = util_sliceBlocks.getSelectionEndPoint(snapshot.context.selection);
|
|
8
8
|
if (endPoint)
|
|
9
|
-
return
|
|
9
|
+
return selector_isSelectionExpanded.getFocusBlock({
|
|
10
10
|
...snapshot,
|
|
11
11
|
context: {
|
|
12
12
|
...snapshot.context,
|
|
@@ -44,7 +44,7 @@ const getSelectionEndBlock = (snapshot) => {
|
|
|
44
44
|
}, getSelectionStartBlock = (snapshot) => {
|
|
45
45
|
const startPoint = util_sliceBlocks.getSelectionStartPoint(snapshot.context.selection);
|
|
46
46
|
if (startPoint)
|
|
47
|
-
return
|
|
47
|
+
return selector_isSelectionExpanded.getFocusBlock({
|
|
48
48
|
...snapshot,
|
|
49
49
|
context: {
|
|
50
50
|
...snapshot.context,
|
|
@@ -55,7 +55,7 @@ const getSelectionEndBlock = (snapshot) => {
|
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
}, getPreviousSpan = (snapshot) => {
|
|
58
|
-
const selectionStartBlock = getSelectionStartBlock(snapshot), selectionStartPoint =
|
|
58
|
+
const selectionStartBlock = getSelectionStartBlock(snapshot), selectionStartPoint = selector_isSelectionExpanded.getSelectionStartPoint(snapshot);
|
|
59
59
|
if (!selectionStartBlock || !selectionStartPoint || !util_sliceBlocks.isTextBlock(snapshot.context, selectionStartBlock.node))
|
|
60
60
|
return;
|
|
61
61
|
const selectionStartPointChildKey = util_sliceBlocks.getChildKeyFromSelectionPoint(selectionStartPoint);
|
|
@@ -71,10 +71,102 @@ const getSelectionEndBlock = (snapshot) => {
|
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
return previousSpan;
|
|
74
|
+
}, getSelectedSpans = (snapshot) => {
|
|
75
|
+
if (!snapshot.context.selection)
|
|
76
|
+
return [];
|
|
77
|
+
const selectedSpans = [], startPoint = selector_isSelectionExpanded.getSelectionStartPoint(snapshot), endPoint = getSelectionEndPoint(snapshot);
|
|
78
|
+
if (!startPoint || !endPoint)
|
|
79
|
+
return selectedSpans;
|
|
80
|
+
const startBlockKey = util_sliceBlocks.getBlockKeyFromSelectionPoint(startPoint), endBlockKey = util_sliceBlocks.getBlockKeyFromSelectionPoint(endPoint), startSpanKey = util_sliceBlocks.getChildKeyFromSelectionPoint(startPoint), endSpanKey = util_sliceBlocks.getChildKeyFromSelectionPoint(endPoint);
|
|
81
|
+
if (!startBlockKey || !endBlockKey)
|
|
82
|
+
return selectedSpans;
|
|
83
|
+
const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey), endBlockIndex = snapshot.blockIndexMap.get(endBlockKey);
|
|
84
|
+
if (startBlockIndex === void 0 || endBlockIndex === void 0)
|
|
85
|
+
return selectedSpans;
|
|
86
|
+
const slicedValue = snapshot.context.value.slice(startBlockIndex, endBlockIndex + 1);
|
|
87
|
+
let startBlockFound = !1;
|
|
88
|
+
for (const block of slicedValue)
|
|
89
|
+
if (block._key === startBlockKey && (startBlockFound = !0), !!util_sliceBlocks.isTextBlock(snapshot.context, block)) {
|
|
90
|
+
if (block._key === startBlockKey) {
|
|
91
|
+
for (const child of block.children)
|
|
92
|
+
if (util_sliceBlocks.isSpan(snapshot.context, child)) {
|
|
93
|
+
if (startSpanKey && child._key === startSpanKey) {
|
|
94
|
+
if (startPoint.offset < child.text.length && selectedSpans.push({
|
|
95
|
+
node: child,
|
|
96
|
+
path: [{
|
|
97
|
+
_key: block._key
|
|
98
|
+
}, "children", {
|
|
99
|
+
_key: child._key
|
|
100
|
+
}]
|
|
101
|
+
}), startSpanKey === endSpanKey)
|
|
102
|
+
break;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (endSpanKey && child._key === endSpanKey) {
|
|
106
|
+
endPoint.offset > 0 && selectedSpans.push({
|
|
107
|
+
node: child,
|
|
108
|
+
path: [{
|
|
109
|
+
_key: block._key
|
|
110
|
+
}, "children", {
|
|
111
|
+
_key: child._key
|
|
112
|
+
}]
|
|
113
|
+
});
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
selectedSpans.length > 0 && selectedSpans.push({
|
|
117
|
+
node: child,
|
|
118
|
+
path: [{
|
|
119
|
+
_key: block._key
|
|
120
|
+
}, "children", {
|
|
121
|
+
_key: child._key
|
|
122
|
+
}]
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
if (startBlockKey === endBlockKey)
|
|
126
|
+
break;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (block._key === endBlockKey) {
|
|
130
|
+
for (const child of block.children)
|
|
131
|
+
if (util_sliceBlocks.isSpan(snapshot.context, child)) {
|
|
132
|
+
if (endSpanKey && child._key === endSpanKey) {
|
|
133
|
+
endPoint.offset > 0 && selectedSpans.push({
|
|
134
|
+
node: child,
|
|
135
|
+
path: [{
|
|
136
|
+
_key: block._key
|
|
137
|
+
}, "children", {
|
|
138
|
+
_key: child._key
|
|
139
|
+
}]
|
|
140
|
+
});
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
selectedSpans.push({
|
|
144
|
+
node: child,
|
|
145
|
+
path: [{
|
|
146
|
+
_key: block._key
|
|
147
|
+
}, "children", {
|
|
148
|
+
_key: child._key
|
|
149
|
+
}]
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
if (startBlockFound)
|
|
155
|
+
for (const child of block.children)
|
|
156
|
+
util_sliceBlocks.isSpan(snapshot.context, child) && selectedSpans.push({
|
|
157
|
+
node: child,
|
|
158
|
+
path: [{
|
|
159
|
+
_key: block._key
|
|
160
|
+
}, "children", {
|
|
161
|
+
_key: child._key
|
|
162
|
+
}]
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return selectedSpans;
|
|
74
166
|
}, getMarkState = (snapshot) => {
|
|
75
167
|
if (!snapshot.context.selection)
|
|
76
168
|
return;
|
|
77
|
-
const focusTextBlock =
|
|
169
|
+
const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot), focusSpan = selector_isSelectionExpanded.getFocusSpan(snapshot);
|
|
78
170
|
if (!focusTextBlock || !focusSpan)
|
|
79
171
|
return;
|
|
80
172
|
if (isSelectionExpanded(snapshot.context.selection)) {
|
|
@@ -206,7 +298,7 @@ const getSelectionEndBlock = (snapshot) => {
|
|
|
206
298
|
if (firstStyle && selectedTextBlocks.every((block) => block.style === firstStyle))
|
|
207
299
|
return firstStyle;
|
|
208
300
|
}, getNextInlineObject = (snapshot) => {
|
|
209
|
-
const focusTextBlock =
|
|
301
|
+
const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot), selectionEndPointChildKey = selectionEndPoint && types.isKeySegment(selectionEndPoint.path[2]) ? selectionEndPoint.path[2]._key : void 0;
|
|
210
302
|
if (!focusTextBlock || !selectionEndPointChildKey)
|
|
211
303
|
return;
|
|
212
304
|
let endPointChildFound = !1, inlineObject;
|
|
@@ -227,18 +319,18 @@ const getSelectionEndBlock = (snapshot) => {
|
|
|
227
319
|
}
|
|
228
320
|
return inlineObject;
|
|
229
321
|
}, getCaretWordSelection = (snapshot) => {
|
|
230
|
-
if (!snapshot.context.selection || !
|
|
322
|
+
if (!snapshot.context.selection || !selector_isSelectionExpanded.isSelectionCollapsed(snapshot))
|
|
231
323
|
return null;
|
|
232
|
-
const focusTextBlock =
|
|
324
|
+
const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot), selectionStartPoint = selector_isSelectionExpanded.getSelectionStartPoint(snapshot), selectionStartOffset = selectionStartPoint ? util_sliceBlocks.spanSelectionPointToBlockOffset({
|
|
233
325
|
context: snapshot.context,
|
|
234
326
|
selectionPoint: selectionStartPoint
|
|
235
327
|
}) : void 0;
|
|
236
328
|
if (!focusTextBlock || !selectionStartPoint || !selectionStartOffset)
|
|
237
329
|
return null;
|
|
238
|
-
const previousInlineObject =
|
|
330
|
+
const previousInlineObject = selector_isSelectionExpanded.getPreviousInlineObject(snapshot), blockStartPoint = util_sliceBlocks.getBlockStartPoint({
|
|
239
331
|
context: snapshot.context,
|
|
240
332
|
block: focusTextBlock
|
|
241
|
-
}), textDirectlyBefore =
|
|
333
|
+
}), textDirectlyBefore = selector_isSelectionExpanded.getSelectionText({
|
|
242
334
|
...snapshot,
|
|
243
335
|
context: {
|
|
244
336
|
...snapshot.context,
|
|
@@ -253,7 +345,7 @@ const getSelectionEndBlock = (snapshot) => {
|
|
|
253
345
|
}).split(/\s+/).at(-1), nextInlineObject = getNextInlineObject(snapshot), blockEndPoint = util_isSelectionCollapsed.getBlockEndPoint({
|
|
254
346
|
context: snapshot.context,
|
|
255
347
|
block: focusTextBlock
|
|
256
|
-
}), textDirectlyAfter =
|
|
348
|
+
}), textDirectlyAfter = selector_isSelectionExpanded.getSelectionText({
|
|
257
349
|
...snapshot,
|
|
258
350
|
context: {
|
|
259
351
|
...snapshot.context,
|
|
@@ -289,7 +381,7 @@ const getSelectionEndBlock = (snapshot) => {
|
|
|
289
381
|
anchor: caretWordStartSelectionPoint,
|
|
290
382
|
focus: caretWordEndSelectionPoint
|
|
291
383
|
};
|
|
292
|
-
return
|
|
384
|
+
return selector_isSelectionExpanded.isSelectionExpanded({
|
|
293
385
|
context: {
|
|
294
386
|
...snapshot.context,
|
|
295
387
|
selection: caretWordSelection
|
|
@@ -304,19 +396,19 @@ const getSelectionEndBlock = (snapshot) => {
|
|
|
304
396
|
}]
|
|
305
397
|
} : void 0;
|
|
306
398
|
}, getFocusBlockObject = (snapshot) => {
|
|
307
|
-
const focusBlock =
|
|
399
|
+
const focusBlock = selector_isSelectionExpanded.getFocusBlock(snapshot);
|
|
308
400
|
return focusBlock && !util_sliceBlocks.isTextBlock(snapshot.context, focusBlock.node) ? {
|
|
309
401
|
node: focusBlock.node,
|
|
310
402
|
path: focusBlock.path
|
|
311
403
|
} : void 0;
|
|
312
404
|
}, getFocusInlineObject = (snapshot) => {
|
|
313
|
-
const focusChild =
|
|
405
|
+
const focusChild = selector_isSelectionExpanded.getFocusChild(snapshot);
|
|
314
406
|
return focusChild && !types.isPortableTextSpan(focusChild.node) ? {
|
|
315
407
|
node: focusChild.node,
|
|
316
408
|
path: focusChild.path
|
|
317
409
|
} : void 0;
|
|
318
410
|
}, getFocusListBlock = (snapshot) => {
|
|
319
|
-
const focusTextBlock =
|
|
411
|
+
const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot);
|
|
320
412
|
return focusTextBlock && util_sliceBlocks.isListBlock(snapshot.context, focusTextBlock.node) ? {
|
|
321
413
|
node: focusTextBlock.node,
|
|
322
414
|
path: focusTextBlock.path
|
|
@@ -357,98 +449,6 @@ const getSelectionEndBlock = (snapshot) => {
|
|
|
357
449
|
_key: previousBlock._key
|
|
358
450
|
}]
|
|
359
451
|
} : void 0;
|
|
360
|
-
}, getSelectedSpans = (snapshot) => {
|
|
361
|
-
if (!snapshot.context.selection)
|
|
362
|
-
return [];
|
|
363
|
-
const selectedSpans = [], startPoint = selector_getFocusSpan.getSelectionStartPoint(snapshot), endPoint = getSelectionEndPoint(snapshot);
|
|
364
|
-
if (!startPoint || !endPoint)
|
|
365
|
-
return selectedSpans;
|
|
366
|
-
const startBlockKey = util_sliceBlocks.getBlockKeyFromSelectionPoint(startPoint), endBlockKey = util_sliceBlocks.getBlockKeyFromSelectionPoint(endPoint), startSpanKey = util_sliceBlocks.getChildKeyFromSelectionPoint(startPoint), endSpanKey = util_sliceBlocks.getChildKeyFromSelectionPoint(endPoint);
|
|
367
|
-
if (!startBlockKey || !endBlockKey)
|
|
368
|
-
return selectedSpans;
|
|
369
|
-
const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey), endBlockIndex = snapshot.blockIndexMap.get(endBlockKey);
|
|
370
|
-
if (startBlockIndex === void 0 || endBlockIndex === void 0)
|
|
371
|
-
return selectedSpans;
|
|
372
|
-
const slicedValue = snapshot.context.value.slice(startBlockIndex, endBlockIndex + 1);
|
|
373
|
-
let startBlockFound = !1;
|
|
374
|
-
for (const block of slicedValue)
|
|
375
|
-
if (block._key === startBlockKey && (startBlockFound = !0), !!util_sliceBlocks.isTextBlock(snapshot.context, block)) {
|
|
376
|
-
if (block._key === startBlockKey) {
|
|
377
|
-
for (const child of block.children)
|
|
378
|
-
if (util_sliceBlocks.isSpan(snapshot.context, child)) {
|
|
379
|
-
if (startSpanKey && child._key === startSpanKey) {
|
|
380
|
-
if (startPoint.offset < child.text.length && selectedSpans.push({
|
|
381
|
-
node: child,
|
|
382
|
-
path: [{
|
|
383
|
-
_key: block._key
|
|
384
|
-
}, "children", {
|
|
385
|
-
_key: child._key
|
|
386
|
-
}]
|
|
387
|
-
}), startSpanKey === endSpanKey)
|
|
388
|
-
break;
|
|
389
|
-
continue;
|
|
390
|
-
}
|
|
391
|
-
if (endSpanKey && child._key === endSpanKey) {
|
|
392
|
-
endPoint.offset > 0 && selectedSpans.push({
|
|
393
|
-
node: child,
|
|
394
|
-
path: [{
|
|
395
|
-
_key: block._key
|
|
396
|
-
}, "children", {
|
|
397
|
-
_key: child._key
|
|
398
|
-
}]
|
|
399
|
-
});
|
|
400
|
-
break;
|
|
401
|
-
}
|
|
402
|
-
selectedSpans.length > 0 && selectedSpans.push({
|
|
403
|
-
node: child,
|
|
404
|
-
path: [{
|
|
405
|
-
_key: block._key
|
|
406
|
-
}, "children", {
|
|
407
|
-
_key: child._key
|
|
408
|
-
}]
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
if (startBlockKey === endBlockKey)
|
|
412
|
-
break;
|
|
413
|
-
continue;
|
|
414
|
-
}
|
|
415
|
-
if (block._key === endBlockKey) {
|
|
416
|
-
for (const child of block.children)
|
|
417
|
-
if (util_sliceBlocks.isSpan(snapshot.context, child)) {
|
|
418
|
-
if (endSpanKey && child._key === endSpanKey) {
|
|
419
|
-
endPoint.offset > 0 && selectedSpans.push({
|
|
420
|
-
node: child,
|
|
421
|
-
path: [{
|
|
422
|
-
_key: block._key
|
|
423
|
-
}, "children", {
|
|
424
|
-
_key: child._key
|
|
425
|
-
}]
|
|
426
|
-
});
|
|
427
|
-
break;
|
|
428
|
-
}
|
|
429
|
-
selectedSpans.push({
|
|
430
|
-
node: child,
|
|
431
|
-
path: [{
|
|
432
|
-
_key: block._key
|
|
433
|
-
}, "children", {
|
|
434
|
-
_key: child._key
|
|
435
|
-
}]
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
break;
|
|
439
|
-
}
|
|
440
|
-
if (startBlockFound)
|
|
441
|
-
for (const child of block.children)
|
|
442
|
-
util_sliceBlocks.isSpan(snapshot.context, child) && selectedSpans.push({
|
|
443
|
-
node: child,
|
|
444
|
-
path: [{
|
|
445
|
-
_key: block._key
|
|
446
|
-
}, "children", {
|
|
447
|
-
_key: child._key
|
|
448
|
-
}]
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
return selectedSpans;
|
|
452
452
|
}, getSelectedTextBlocks = (snapshot) => {
|
|
453
453
|
if (!snapshot.context.selection)
|
|
454
454
|
return [];
|
|
@@ -558,13 +558,13 @@ const getSelectionEndBlock = (snapshot) => {
|
|
|
558
558
|
anchor: adjustedStartPoint ?? startPoint,
|
|
559
559
|
focus: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint
|
|
560
560
|
};
|
|
561
|
-
if (
|
|
561
|
+
if (selector_isSelectionExpanded.isSelectionCollapsed({
|
|
562
562
|
context: {
|
|
563
563
|
...snapshot.context,
|
|
564
564
|
selection: trimmedSelection
|
|
565
565
|
}
|
|
566
566
|
})) {
|
|
567
|
-
const focusTextBlock =
|
|
567
|
+
const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock({
|
|
568
568
|
...snapshot,
|
|
569
569
|
context: {
|
|
570
570
|
...snapshot.context,
|
|
@@ -595,7 +595,7 @@ function getActiveDecorators(snapshot) {
|
|
|
595
595
|
}
|
|
596
596
|
function isActiveDecorator(decorator) {
|
|
597
597
|
return (snapshot) => {
|
|
598
|
-
if (
|
|
598
|
+
if (selector_isSelectionExpanded.isSelectionExpanded(snapshot)) {
|
|
599
599
|
const selectedSpans = getSelectedSpans(snapshot);
|
|
600
600
|
return selectedSpans.length > 0 && selectedSpans.every((span) => span.node.marks?.includes(decorator));
|
|
601
601
|
}
|
|
@@ -610,7 +610,7 @@ function isActiveStyle(style) {
|
|
|
610
610
|
}
|
|
611
611
|
function isAtTheEndOfBlock(block) {
|
|
612
612
|
return (snapshot) => {
|
|
613
|
-
if (!snapshot.context.selection || !
|
|
613
|
+
if (!snapshot.context.selection || !selector_isSelectionExpanded.isSelectionCollapsed(snapshot))
|
|
614
614
|
return !1;
|
|
615
615
|
const blockEndPoint = util_isSelectionCollapsed.getBlockEndPoint({
|
|
616
616
|
context: snapshot.context,
|
|
@@ -621,7 +621,7 @@ function isAtTheEndOfBlock(block) {
|
|
|
621
621
|
}
|
|
622
622
|
function isAtTheStartOfBlock(block) {
|
|
623
623
|
return (snapshot) => {
|
|
624
|
-
if (!snapshot.context.selection || !
|
|
624
|
+
if (!snapshot.context.selection || !selector_isSelectionExpanded.isSelectionCollapsed(snapshot))
|
|
625
625
|
return !1;
|
|
626
626
|
const blockStartPoint = util_sliceBlocks.getBlockStartPoint({
|
|
627
627
|
context: snapshot.context,
|
|
@@ -688,7 +688,7 @@ function isOverlappingSelection(selection) {
|
|
|
688
688
|
return (snapshot) => {
|
|
689
689
|
if (!selection || !snapshot.context.selection)
|
|
690
690
|
return !1;
|
|
691
|
-
const selectionStartPoint =
|
|
691
|
+
const selectionStartPoint = selector_isSelectionExpanded.getSelectionStartPoint({
|
|
692
692
|
context: {
|
|
693
693
|
...snapshot.context,
|
|
694
694
|
selection
|
|
@@ -698,7 +698,7 @@ function isOverlappingSelection(selection) {
|
|
|
698
698
|
...snapshot.context,
|
|
699
699
|
selection
|
|
700
700
|
}
|
|
701
|
-
}), originalSelectionStartPoint =
|
|
701
|
+
}), originalSelectionStartPoint = selector_isSelectionExpanded.getSelectionStartPoint(snapshot), originalSelectionEndPoint = getSelectionEndPoint(snapshot);
|
|
702
702
|
if (!selectionStartPoint || !selectionEndPoint || !originalSelectionStartPoint || !originalSelectionEndPoint)
|
|
703
703
|
return !1;
|
|
704
704
|
const startPointBeforeSelection = isPointBeforeSelection(selectionStartPoint)(snapshot), startPointAfterSelection = isPointAfterSelection(selectionStartPoint)(snapshot), endPointBeforeSelection = isPointBeforeSelection(selectionEndPoint)(snapshot), endPointAfterSelection = isPointAfterSelection(selectionEndPoint)(snapshot), originalStartPointBeforeStartPoint = isPointBeforeSelection(originalSelectionStartPoint)({
|