@portabletext/editor 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint, getSelectionEndPoint as getSelectionEndPoint$1, getSelectionStartPoint as getSelectionStartPoint$1, isEqualSelectionPoints, getBlockStartPoint, getBlockEndPoint, sliceBlocks, isSelectionCollapsed as isSelectionCollapsed$1, blockOffsetToSpanSelectionPoint, isKeyedSegment, spanSelectionPointToBlockOffset, isListBlock } from "./util.slice-blocks.js";
|
|
1
2
|
import { isTextBlock, isSpan } from "@portabletext/schema";
|
|
2
|
-
import { getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint, getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint as getSelectionEndPoint$1, isEqualSelectionPoints, getBlockStartPoint, getBlockEndPoint, sliceBlocks, isSelectionCollapsed as isSelectionCollapsed$1, blockOffsetToSpanSelectionPoint, isKeyedSegment, spanSelectionPointToBlockOffset, isListBlock } from "./util.slice-blocks.js";
|
|
3
3
|
const getFocusBlock = (snapshot) => {
|
|
4
4
|
if (!snapshot.context.selection)
|
|
5
5
|
return;
|
|
@@ -29,82 +29,12 @@ const getFocusBlock = (snapshot) => {
|
|
|
29
29
|
_key: key
|
|
30
30
|
}]
|
|
31
31
|
} : void 0;
|
|
32
|
-
}, getFocusInlineObject = (snapshot) => {
|
|
33
|
-
const focusChild = getFocusChild(snapshot);
|
|
34
|
-
return focusChild && !isSpan(snapshot.context, focusChild.node) ? {
|
|
35
|
-
node: focusChild.node,
|
|
36
|
-
path: focusChild.path
|
|
37
|
-
} : void 0;
|
|
38
32
|
}, getFocusSpan = (snapshot) => {
|
|
39
33
|
const focusChild = getFocusChild(snapshot);
|
|
40
34
|
return focusChild && isSpan(snapshot.context, focusChild.node) ? {
|
|
41
35
|
node: focusChild.node,
|
|
42
36
|
path: focusChild.path
|
|
43
37
|
} : void 0;
|
|
44
|
-
}, getSelectedBlocks = (snapshot) => {
|
|
45
|
-
if (!snapshot.context.selection)
|
|
46
|
-
return [];
|
|
47
|
-
const selectedBlocks = [], startPoint = getSelectionStartPoint$1(snapshot.context.selection), endPoint = getSelectionEndPoint$1(snapshot.context.selection), startKey = getBlockKeyFromSelectionPoint(startPoint), endKey = getBlockKeyFromSelectionPoint(endPoint);
|
|
48
|
-
if (!startKey || !endKey)
|
|
49
|
-
return selectedBlocks;
|
|
50
|
-
const startBlockIndex = snapshot.blockIndexMap.get(startKey), endBlockIndex = snapshot.blockIndexMap.get(endKey);
|
|
51
|
-
if (startBlockIndex === void 0 || endBlockIndex === void 0)
|
|
52
|
-
return selectedBlocks;
|
|
53
|
-
const slicedValue = snapshot.context.value.slice(startBlockIndex, endBlockIndex + 1);
|
|
54
|
-
for (const block of slicedValue) {
|
|
55
|
-
if (block._key === startKey) {
|
|
56
|
-
if (selectedBlocks.push({
|
|
57
|
-
node: block,
|
|
58
|
-
path: [{
|
|
59
|
-
_key: block._key
|
|
60
|
-
}]
|
|
61
|
-
}), startKey === endKey)
|
|
62
|
-
break;
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
if (block._key === endKey) {
|
|
66
|
-
selectedBlocks.push({
|
|
67
|
-
node: block,
|
|
68
|
-
path: [{
|
|
69
|
-
_key: block._key
|
|
70
|
-
}]
|
|
71
|
-
});
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
selectedBlocks.length > 0 && selectedBlocks.push({
|
|
75
|
-
node: block,
|
|
76
|
-
path: [{
|
|
77
|
-
_key: block._key
|
|
78
|
-
}]
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
return selectedBlocks;
|
|
82
|
-
}, getSelectionEndBlock = (snapshot) => {
|
|
83
|
-
const endPoint = getSelectionEndPoint$1(snapshot.context.selection);
|
|
84
|
-
if (endPoint)
|
|
85
|
-
return getFocusBlock({
|
|
86
|
-
...snapshot,
|
|
87
|
-
context: {
|
|
88
|
-
...snapshot.context,
|
|
89
|
-
selection: {
|
|
90
|
-
anchor: endPoint,
|
|
91
|
-
focus: endPoint
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}, getSelectionStartBlock = (snapshot) => {
|
|
96
|
-
const startPoint = getSelectionStartPoint$1(snapshot.context.selection);
|
|
97
|
-
if (startPoint)
|
|
98
|
-
return getFocusBlock({
|
|
99
|
-
...snapshot,
|
|
100
|
-
context: {
|
|
101
|
-
...snapshot.context,
|
|
102
|
-
selection: {
|
|
103
|
-
anchor: startPoint,
|
|
104
|
-
focus: startPoint
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
38
|
}, getSelectionEndPoint = (snapshot) => {
|
|
109
39
|
if (snapshot.context.selection)
|
|
110
40
|
return snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus;
|
|
@@ -226,7 +156,77 @@ function isOverlappingSelection(selection) {
|
|
|
226
156
|
return !endPointEqualToOriginalStartPoint && !startPointEqualToOriginalEndPoint && !originalStartPointBeforeStartPoint && !originalStartPointAfterStartPoint && !originalEndPointBeforeEndPoint && !originalEndPointAfterEndPoint || endPointBeforeSelection && !endPointEqualToOriginalStartPoint || startPointAfterSelection && !startPointEqualToOriginalEndPoint ? !1 : !originalStartPointBeforeStartPoint && originalStartPointAfterStartPoint && !originalEndPointBeforeEndPoint && originalEndPointAfterEndPoint ? !endPointEqualToOriginalStartPoint : originalStartPointBeforeStartPoint && !originalStartPointAfterStartPoint && originalEndPointBeforeEndPoint && !originalEndPointAfterEndPoint ? !startPointEqualToOriginalEndPoint : !startPointAfterSelection || !startPointBeforeSelection || !endPointAfterSelection || !endPointBeforeSelection;
|
|
227
157
|
};
|
|
228
158
|
}
|
|
229
|
-
const isSelectionCollapsed = (snapshot) => snapshot.context.selection ? JSON.stringify(snapshot.context.selection.anchor.path) === JSON.stringify(snapshot.context.selection.focus.path) && snapshot.context.selection?.anchor.offset === snapshot.context.selection?.focus.offset : !1,
|
|
159
|
+
const isSelectionCollapsed = (snapshot) => snapshot.context.selection ? JSON.stringify(snapshot.context.selection.anchor.path) === JSON.stringify(snapshot.context.selection.focus.path) && snapshot.context.selection?.anchor.offset === snapshot.context.selection?.focus.offset : !1, getFocusInlineObject = (snapshot) => {
|
|
160
|
+
const focusChild = getFocusChild(snapshot);
|
|
161
|
+
return focusChild && !isSpan(snapshot.context, focusChild.node) ? {
|
|
162
|
+
node: focusChild.node,
|
|
163
|
+
path: focusChild.path
|
|
164
|
+
} : void 0;
|
|
165
|
+
}, getSelectedBlocks = (snapshot) => {
|
|
166
|
+
if (!snapshot.context.selection)
|
|
167
|
+
return [];
|
|
168
|
+
const selectedBlocks = [], startPoint = getSelectionStartPoint$1(snapshot.context.selection), endPoint = getSelectionEndPoint$1(snapshot.context.selection), startKey = getBlockKeyFromSelectionPoint(startPoint), endKey = getBlockKeyFromSelectionPoint(endPoint);
|
|
169
|
+
if (!startKey || !endKey)
|
|
170
|
+
return selectedBlocks;
|
|
171
|
+
const startBlockIndex = snapshot.blockIndexMap.get(startKey), endBlockIndex = snapshot.blockIndexMap.get(endKey);
|
|
172
|
+
if (startBlockIndex === void 0 || endBlockIndex === void 0)
|
|
173
|
+
return selectedBlocks;
|
|
174
|
+
const slicedValue = snapshot.context.value.slice(startBlockIndex, endBlockIndex + 1);
|
|
175
|
+
for (const block of slicedValue) {
|
|
176
|
+
if (block._key === startKey) {
|
|
177
|
+
if (selectedBlocks.push({
|
|
178
|
+
node: block,
|
|
179
|
+
path: [{
|
|
180
|
+
_key: block._key
|
|
181
|
+
}]
|
|
182
|
+
}), startKey === endKey)
|
|
183
|
+
break;
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (block._key === endKey) {
|
|
187
|
+
selectedBlocks.push({
|
|
188
|
+
node: block,
|
|
189
|
+
path: [{
|
|
190
|
+
_key: block._key
|
|
191
|
+
}]
|
|
192
|
+
});
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
selectedBlocks.length > 0 && selectedBlocks.push({
|
|
196
|
+
node: block,
|
|
197
|
+
path: [{
|
|
198
|
+
_key: block._key
|
|
199
|
+
}]
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
return selectedBlocks;
|
|
203
|
+
}, getSelectionEndBlock = (snapshot) => {
|
|
204
|
+
const endPoint = getSelectionEndPoint$1(snapshot.context.selection);
|
|
205
|
+
if (endPoint)
|
|
206
|
+
return getFocusBlock({
|
|
207
|
+
...snapshot,
|
|
208
|
+
context: {
|
|
209
|
+
...snapshot.context,
|
|
210
|
+
selection: {
|
|
211
|
+
anchor: endPoint,
|
|
212
|
+
focus: endPoint
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}, getSelectionStartBlock = (snapshot) => {
|
|
217
|
+
const startPoint = getSelectionStartPoint$1(snapshot.context.selection);
|
|
218
|
+
if (startPoint)
|
|
219
|
+
return getFocusBlock({
|
|
220
|
+
...snapshot,
|
|
221
|
+
context: {
|
|
222
|
+
...snapshot.context,
|
|
223
|
+
selection: {
|
|
224
|
+
anchor: startPoint,
|
|
225
|
+
focus: startPoint
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}, isSelectionExpanded$1 = (snapshot) => snapshot.context.selection !== null && !isSelectionCollapsed(snapshot), isSelectingEntireBlocks = (snapshot) => {
|
|
230
230
|
if (!snapshot.context.selection)
|
|
231
231
|
return !1;
|
|
232
232
|
const startPoint = snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor, endPoint = snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus, startBlock = getSelectionStartBlock(snapshot), endBlock = getSelectionEndBlock(snapshot);
|