@portabletext/editor 1.48.7 → 1.48.8
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/behavior.core.cjs +20 -8
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +5 -5
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +121 -90
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs +2 -2
- package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +7 -4
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +63 -47
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +29 -23
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +3 -3
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +15 -15
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs +258 -38
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +21 -10
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +5 -6
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +75 -46
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/selector.get-focus-inline-object.js +1 -2
- package/lib/_chunks-es/selector.get-focus-inline-object.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +7 -4
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-overlapping-selection.js +61 -46
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +30 -26
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/util.merge-text-blocks.js +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +15 -16
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js +258 -38
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/behaviors/index.d.cts +2552 -251
- package/lib/behaviors/index.d.ts +2552 -251
- package/lib/index.cjs +45 -21
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +2350 -51
- package/lib/index.d.ts +2350 -51
- package/lib/index.js +44 -21
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +16 -7
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +2324 -24
- package/lib/plugins/index.d.ts +2324 -24
- package/lib/plugins/index.js +16 -7
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs +5 -5
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +2321 -28
- package/lib/selectors/index.d.ts +2321 -28
- package/lib/selectors/index.js +5 -6
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +30 -24
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +2350 -44
- package/lib/utils/index.d.ts +2350 -44
- package/lib/utils/index.js +30 -24
- package/lib/utils/index.js.map +1 -1
- package/package.json +1 -2
- package/src/behavior-actions/behavior.action.block.unset.ts +1 -1
- package/src/behavior-actions/behavior.action.decorator.add.ts +20 -5
- package/src/behaviors/behavior.abstract.decorator.ts +1 -1
- package/src/behaviors/behavior.abstract.delete.ts +1 -1
- package/src/behaviors/behavior.abstract.insert.ts +2 -2
- package/src/behaviors/behavior.abstract.select.ts +16 -4
- package/src/behaviors/behavior.abstract.split.ts +9 -6
- package/src/behaviors/behavior.core.block-objects.ts +5 -5
- package/src/behaviors/behavior.core.insert-break.ts +16 -4
- package/src/behaviors/behavior.core.lists.ts +4 -6
- package/src/behaviors/behavior.decorator-pair.ts +13 -4
- package/src/behaviors/behavior.default.ts +1 -1
- package/src/behaviors/behavior.markdown.ts +5 -5
- package/src/converters/converter.portable-text.ts +1 -1
- package/src/converters/converter.text-html.ts +1 -1
- package/src/converters/converter.text-plain.ts +4 -4
- package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +10 -2
- package/src/editor/plugins/createWithSchemaTypes.ts +12 -19
- package/src/internal-utils/__tests__/dmpToOperations.test.ts +13 -12
- package/src/internal-utils/drag-selection.ts +16 -4
- package/src/internal-utils/event-position.ts +20 -8
- package/src/internal-utils/parse-blocks.ts +17 -5
- package/src/internal-utils/validateValue.ts +6 -6
- package/src/plugins/plugin.decorator-shortcut.ts +2 -2
- package/src/selectors/selector.get-active-annotations.ts +5 -2
- package/src/selectors/selector.get-active-list-item.ts +4 -3
- package/src/selectors/selector.get-active-style.ts +4 -3
- package/src/selectors/selector.get-anchor-text-block.ts +3 -6
- package/src/selectors/selector.get-block-offsets.ts +2 -2
- package/src/selectors/selector.get-caret-word-selection.ts +11 -5
- package/src/selectors/selector.get-selected-slice.ts +1 -1
- package/src/selectors/selector.get-selected-spans.ts +11 -15
- package/src/selectors/selector.get-selected-text-blocks.ts +3 -3
- package/src/selectors/selector.get-selection-text.ts +3 -3
- package/src/selectors/selector.get-text-before.ts +5 -2
- package/src/selectors/selector.get-trimmed-selection.ts +20 -14
- package/src/selectors/selector.is-active-annotation.ts +4 -2
- package/src/selectors/selector.is-active-decorator.test.ts +3 -3
- package/src/selectors/selector.is-at-the-end-of-block.ts +4 -1
- package/src/selectors/selector.is-at-the-start-of-block.ts +4 -1
- package/src/selectors/selector.is-point-after-selection.ts +7 -6
- package/src/selectors/selector.is-point-before-selection.ts +7 -6
- package/src/selectors/selector.is-selecting-entire-blocks.ts +8 -2
- package/src/selectors/selectors.ts +25 -28
- package/src/utils/util.block-offset-to-block-selection-point.ts +4 -4
- package/src/utils/util.block-offset-to-selection-point.ts +5 -5
- package/src/utils/util.block-offset.test.ts +219 -156
- package/src/utils/util.block-offset.ts +14 -17
- package/src/utils/util.block-offsets-to-selection.ts +5 -5
- package/src/utils/util.child-selection-point-to-block-offset.ts +7 -10
- package/src/utils/util.get-block-end-point.ts +15 -15
- package/src/utils/util.get-block-start-point.ts +13 -12
- package/src/utils/util.is-empty-text-block.ts +9 -8
- package/src/utils/util.selection-point-to-block-offset.ts +4 -4
- package/src/utils/util.slice-blocks.test.ts +178 -121
- package/src/utils/util.slice-blocks.ts +25 -24
- package/src/utils/util.split-text-block.ts +18 -12
- package/lib/_chunks-cjs/parse-blocks.cjs +0 -205
- package/lib/_chunks-cjs/parse-blocks.cjs.map +0 -1
- package/lib/_chunks-es/parse-blocks.js +0 -206
- package/lib/_chunks-es/parse-blocks.js.map +0 -1
- package/src/behavior-actions/behavior.guards.ts +0 -24
|
@@ -1,19 +1,231 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
function isTypedObject(object) {
|
|
3
|
+
return isRecord(object) && typeof object._type == "string";
|
|
4
|
+
}
|
|
5
|
+
function isRecord(value) {
|
|
6
|
+
return !!value && (typeof value == "object" || typeof value == "function");
|
|
7
|
+
}
|
|
8
|
+
function parseBlocks({
|
|
9
|
+
context,
|
|
10
|
+
blocks,
|
|
11
|
+
options
|
|
12
|
+
}) {
|
|
13
|
+
return Array.isArray(blocks) ? blocks.flatMap((block) => {
|
|
14
|
+
const parsedBlock = parseBlock({
|
|
15
|
+
context,
|
|
16
|
+
block,
|
|
17
|
+
options
|
|
18
|
+
});
|
|
19
|
+
return parsedBlock ? [parsedBlock] : [];
|
|
20
|
+
}) : [];
|
|
21
|
+
}
|
|
22
|
+
function parseBlock({
|
|
23
|
+
context,
|
|
24
|
+
block,
|
|
25
|
+
options
|
|
26
|
+
}) {
|
|
27
|
+
return parseTextBlock({
|
|
28
|
+
block,
|
|
29
|
+
context,
|
|
30
|
+
options
|
|
31
|
+
}) ?? parseBlockObject({
|
|
32
|
+
blockObject: block,
|
|
33
|
+
context,
|
|
34
|
+
options
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function parseBlockObject({
|
|
38
|
+
blockObject,
|
|
39
|
+
context,
|
|
40
|
+
options
|
|
41
|
+
}) {
|
|
42
|
+
if (!isTypedObject(blockObject))
|
|
43
|
+
return;
|
|
44
|
+
const schemaType = context.schema.blockObjects.find(({
|
|
45
|
+
name
|
|
46
|
+
}) => name === blockObject._type);
|
|
47
|
+
if (schemaType)
|
|
48
|
+
return parseObject({
|
|
49
|
+
object: blockObject,
|
|
50
|
+
context: {
|
|
51
|
+
keyGenerator: context.keyGenerator,
|
|
52
|
+
schemaType
|
|
53
|
+
},
|
|
54
|
+
options
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function isListBlock(context, block) {
|
|
58
|
+
return isTextBlock(context, block) && block.level !== void 0 && block.listItem !== void 0;
|
|
59
|
+
}
|
|
60
|
+
function isTextBlock(context, block) {
|
|
61
|
+
return parseTextBlock({
|
|
62
|
+
block,
|
|
63
|
+
context: {
|
|
64
|
+
schema: context.schema,
|
|
65
|
+
keyGenerator: () => ""
|
|
66
|
+
},
|
|
67
|
+
options: {
|
|
68
|
+
refreshKeys: !1
|
|
69
|
+
}
|
|
70
|
+
}) !== void 0;
|
|
71
|
+
}
|
|
72
|
+
function parseTextBlock({
|
|
73
|
+
block,
|
|
74
|
+
context,
|
|
75
|
+
options
|
|
76
|
+
}) {
|
|
77
|
+
if (!isTypedObject(block) || block._type !== context.schema.block.name)
|
|
78
|
+
return;
|
|
79
|
+
const _key = options.refreshKeys ? context.keyGenerator() : typeof block._key == "string" ? block._key : context.keyGenerator(), unparsedMarkDefs = Array.isArray(block.markDefs) ? block.markDefs : [], markDefKeyMap = /* @__PURE__ */ new Map(), markDefs = unparsedMarkDefs.flatMap((markDef) => {
|
|
80
|
+
if (!isTypedObject(markDef))
|
|
81
|
+
return [];
|
|
82
|
+
const schemaType = context.schema.annotations.find(({
|
|
83
|
+
name
|
|
84
|
+
}) => name === markDef._type);
|
|
85
|
+
if (!schemaType)
|
|
86
|
+
return [];
|
|
87
|
+
if (typeof markDef._key != "string")
|
|
88
|
+
return [];
|
|
89
|
+
const parsedAnnotation = parseObject({
|
|
90
|
+
object: markDef,
|
|
91
|
+
context: {
|
|
92
|
+
schemaType,
|
|
93
|
+
keyGenerator: context.keyGenerator
|
|
94
|
+
},
|
|
95
|
+
options
|
|
96
|
+
});
|
|
97
|
+
return parsedAnnotation ? (markDefKeyMap.set(markDef._key, parsedAnnotation._key), [parsedAnnotation]) : [];
|
|
98
|
+
}), children = (Array.isArray(block.children) ? block.children : []).map((child) => parseSpan({
|
|
99
|
+
span: child,
|
|
100
|
+
context,
|
|
101
|
+
markDefKeyMap,
|
|
102
|
+
options
|
|
103
|
+
}) ?? parseInlineObject({
|
|
104
|
+
inlineObject: child,
|
|
105
|
+
context,
|
|
106
|
+
options
|
|
107
|
+
})).filter((child) => child !== void 0), parsedBlock = {
|
|
108
|
+
_type: context.schema.block.name,
|
|
109
|
+
_key,
|
|
110
|
+
children: children.length > 0 ? children : [{
|
|
111
|
+
_key: context.keyGenerator(),
|
|
112
|
+
_type: context.schema.span.name,
|
|
113
|
+
text: "",
|
|
114
|
+
marks: []
|
|
115
|
+
}],
|
|
116
|
+
markDefs
|
|
117
|
+
};
|
|
118
|
+
if (typeof block.style == "string" && context.schema.styles.find((style) => style.name === block.style))
|
|
119
|
+
parsedBlock.style = block.style;
|
|
120
|
+
else {
|
|
121
|
+
const defaultStyle = context.schema.styles.at(0)?.name;
|
|
122
|
+
defaultStyle !== void 0 ? parsedBlock.style = defaultStyle : console.error("Expected default style");
|
|
123
|
+
}
|
|
124
|
+
return typeof block.listItem == "string" && context.schema.lists.find((list) => list.name === block.listItem) && (parsedBlock.listItem = block.listItem), typeof block.level == "number" && (parsedBlock.level = block.level), parsedBlock;
|
|
125
|
+
}
|
|
126
|
+
function isSpan$1(context, child) {
|
|
127
|
+
return parseSpan({
|
|
128
|
+
span: child,
|
|
129
|
+
markDefKeyMap: /* @__PURE__ */ new Map(),
|
|
130
|
+
context: {
|
|
131
|
+
schema: context.schema,
|
|
132
|
+
keyGenerator: () => ""
|
|
133
|
+
},
|
|
134
|
+
options: {
|
|
135
|
+
refreshKeys: !1
|
|
136
|
+
}
|
|
137
|
+
}) !== void 0;
|
|
138
|
+
}
|
|
139
|
+
function parseSpan({
|
|
140
|
+
span,
|
|
141
|
+
context,
|
|
142
|
+
markDefKeyMap,
|
|
143
|
+
options
|
|
144
|
+
}) {
|
|
145
|
+
if (!isTypedObject(span) || span._type !== context.schema.span.name || span._type !== "span")
|
|
146
|
+
return;
|
|
147
|
+
const marks = (Array.isArray(span.marks) ? span.marks : []).flatMap((mark) => {
|
|
148
|
+
if (typeof mark != "string")
|
|
149
|
+
return [];
|
|
150
|
+
const markDefKey = markDefKeyMap.get(mark);
|
|
151
|
+
return markDefKey !== void 0 ? [markDefKey] : context.schema.decorators.some((decorator) => decorator.name === mark) ? [mark] : [];
|
|
152
|
+
});
|
|
153
|
+
return {
|
|
154
|
+
_type: "span",
|
|
155
|
+
_key: options.refreshKeys ? context.keyGenerator() : typeof span._key == "string" ? span._key : context.keyGenerator(),
|
|
156
|
+
text: typeof span.text == "string" ? span.text : "",
|
|
157
|
+
marks
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function parseInlineObject({
|
|
161
|
+
inlineObject,
|
|
162
|
+
context,
|
|
163
|
+
options
|
|
164
|
+
}) {
|
|
165
|
+
if (!isTypedObject(inlineObject))
|
|
166
|
+
return;
|
|
167
|
+
const schemaType = context.schema.inlineObjects.find(({
|
|
168
|
+
name
|
|
169
|
+
}) => name === inlineObject._type);
|
|
170
|
+
if (schemaType)
|
|
171
|
+
return parseObject({
|
|
172
|
+
object: inlineObject,
|
|
173
|
+
context: {
|
|
174
|
+
keyGenerator: context.keyGenerator,
|
|
175
|
+
schemaType
|
|
176
|
+
},
|
|
177
|
+
options
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
function parseAnnotation({
|
|
181
|
+
annotation,
|
|
182
|
+
context,
|
|
183
|
+
options
|
|
184
|
+
}) {
|
|
185
|
+
if (!isTypedObject(annotation))
|
|
186
|
+
return;
|
|
187
|
+
const schemaType = context.schema.annotations.find(({
|
|
188
|
+
name
|
|
189
|
+
}) => name === annotation._type);
|
|
190
|
+
if (schemaType)
|
|
191
|
+
return parseObject({
|
|
192
|
+
object: annotation,
|
|
193
|
+
context: {
|
|
194
|
+
keyGenerator: context.keyGenerator,
|
|
195
|
+
schemaType
|
|
196
|
+
},
|
|
197
|
+
options
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
function parseObject({
|
|
201
|
+
object,
|
|
202
|
+
context,
|
|
203
|
+
options
|
|
204
|
+
}) {
|
|
205
|
+
const values = context.schemaType.fields.reduce((fieldValues, field) => {
|
|
206
|
+
const fieldValue = object[field.name];
|
|
207
|
+
return fieldValue !== void 0 && (fieldValues[field.name] = fieldValue), fieldValues;
|
|
208
|
+
}, {});
|
|
209
|
+
return {
|
|
210
|
+
_type: context.schemaType.name,
|
|
211
|
+
_key: options.refreshKeys ? context.keyGenerator() : typeof object._key == "string" ? object._key : context.keyGenerator(),
|
|
212
|
+
...values
|
|
213
|
+
};
|
|
214
|
+
}
|
|
3
215
|
function isKeyedSegment(segment) {
|
|
4
216
|
return typeof segment == "object" && segment !== null && "_key" in segment;
|
|
5
217
|
}
|
|
6
218
|
function blockOffsetToSpanSelectionPoint({
|
|
7
|
-
|
|
219
|
+
context,
|
|
8
220
|
blockOffset,
|
|
9
221
|
direction
|
|
10
222
|
}) {
|
|
11
223
|
let offsetLeft = blockOffset.offset, selectionPoint, skippedInlineObject = !1;
|
|
12
|
-
for (const block of value)
|
|
13
|
-
if (block._key === blockOffset.path[0]._key &&
|
|
224
|
+
for (const block of context.value)
|
|
225
|
+
if (block._key === blockOffset.path[0]._key && isTextBlock(context, block))
|
|
14
226
|
for (const child of block.children) {
|
|
15
227
|
if (direction === "forward") {
|
|
16
|
-
if (!
|
|
228
|
+
if (!isSpan$1(context, child))
|
|
17
229
|
continue;
|
|
18
230
|
if (offsetLeft <= child.text.length) {
|
|
19
231
|
selectionPoint = {
|
|
@@ -27,7 +239,7 @@ function blockOffsetToSpanSelectionPoint({
|
|
|
27
239
|
offsetLeft -= child.text.length;
|
|
28
240
|
continue;
|
|
29
241
|
}
|
|
30
|
-
if (!
|
|
242
|
+
if (!isSpan$1(context, child)) {
|
|
31
243
|
skippedInlineObject = !0;
|
|
32
244
|
continue;
|
|
33
245
|
}
|
|
@@ -55,16 +267,16 @@ function blockOffsetToSpanSelectionPoint({
|
|
|
55
267
|
return selectionPoint;
|
|
56
268
|
}
|
|
57
269
|
function spanSelectionPointToBlockOffset({
|
|
58
|
-
|
|
270
|
+
context,
|
|
59
271
|
selectionPoint
|
|
60
272
|
}) {
|
|
61
273
|
let offset = 0;
|
|
62
274
|
const blockKey = isKeyedSegment(selectionPoint.path[0]) ? selectionPoint.path[0]._key : void 0, spanKey = isKeyedSegment(selectionPoint.path[2]) ? selectionPoint.path[2]._key : void 0;
|
|
63
275
|
if (!(!blockKey || !spanKey)) {
|
|
64
|
-
for (const block of value)
|
|
65
|
-
if (block._key === blockKey &&
|
|
276
|
+
for (const block of context.value)
|
|
277
|
+
if (block._key === blockKey && isTextBlock(context, block)) {
|
|
66
278
|
for (const child of block.children)
|
|
67
|
-
if (
|
|
279
|
+
if (isSpan$1(context, child)) {
|
|
68
280
|
if (child._key === spanKey)
|
|
69
281
|
return {
|
|
70
282
|
path: [{
|
|
@@ -78,45 +290,45 @@ function spanSelectionPointToBlockOffset({
|
|
|
78
290
|
}
|
|
79
291
|
}
|
|
80
292
|
function getBlockEndPoint({
|
|
81
|
-
|
|
82
|
-
|
|
293
|
+
context,
|
|
294
|
+
block
|
|
83
295
|
}) {
|
|
84
|
-
if (
|
|
85
|
-
const lastChild = node.children[node.children.length - 1];
|
|
296
|
+
if (isTextBlock(context, block.node)) {
|
|
297
|
+
const lastChild = block.node.children[block.node.children.length - 1];
|
|
86
298
|
if (lastChild)
|
|
87
299
|
return {
|
|
88
|
-
path: [...path, "children", {
|
|
300
|
+
path: [...block.path, "children", {
|
|
89
301
|
_key: lastChild._key
|
|
90
302
|
}],
|
|
91
|
-
offset:
|
|
303
|
+
offset: isSpan$1(context, lastChild) ? lastChild.text.length : 0
|
|
92
304
|
};
|
|
93
305
|
}
|
|
94
306
|
return {
|
|
95
|
-
path,
|
|
307
|
+
path: block.path,
|
|
96
308
|
offset: 0
|
|
97
309
|
};
|
|
98
310
|
}
|
|
99
311
|
function getBlockStartPoint({
|
|
100
|
-
|
|
101
|
-
|
|
312
|
+
context,
|
|
313
|
+
block
|
|
102
314
|
}) {
|
|
103
|
-
return
|
|
104
|
-
path: [...path, "children", {
|
|
105
|
-
_key: node.children[0]._key
|
|
315
|
+
return isTextBlock(context, block.node) ? {
|
|
316
|
+
path: [...block.path, "children", {
|
|
317
|
+
_key: block.node.children[0]._key
|
|
106
318
|
}],
|
|
107
319
|
offset: 0
|
|
108
320
|
} : {
|
|
109
|
-
path,
|
|
321
|
+
path: block.path,
|
|
110
322
|
offset: 0
|
|
111
323
|
};
|
|
112
324
|
}
|
|
113
325
|
function getTextBlockText(block) {
|
|
114
326
|
return block.children.map((child) => child.text ?? "").join("");
|
|
115
327
|
}
|
|
116
|
-
function isEmptyTextBlock(block) {
|
|
117
|
-
if (!
|
|
328
|
+
function isEmptyTextBlock(context, block) {
|
|
329
|
+
if (!isTextBlock(context, block))
|
|
118
330
|
return !1;
|
|
119
|
-
const onlyText = block.children.every(
|
|
331
|
+
const onlyText = block.children.every((child) => isSpan$1(context, child)), blockText = getTextBlockText(block);
|
|
120
332
|
return onlyText && blockText === "";
|
|
121
333
|
}
|
|
122
334
|
function isEqualSelectionPoints(a, b) {
|
|
@@ -137,32 +349,32 @@ function reverseSelection(selection) {
|
|
|
137
349
|
});
|
|
138
350
|
}
|
|
139
351
|
function sliceBlocks({
|
|
140
|
-
|
|
141
|
-
|
|
352
|
+
context,
|
|
353
|
+
blocks
|
|
142
354
|
}) {
|
|
143
355
|
const slice = [];
|
|
144
|
-
if (!selection)
|
|
356
|
+
if (!context.selection)
|
|
145
357
|
return slice;
|
|
146
358
|
let startBlock;
|
|
147
359
|
const middleBlocks = [];
|
|
148
360
|
let endBlock;
|
|
149
|
-
const startPoint = selection.backward ? selection.focus : selection.anchor, endPoint = selection.backward ? selection.anchor : selection.focus, startBlockKey =
|
|
361
|
+
const startPoint = context.selection.backward ? context.selection.focus : context.selection.anchor, endPoint = context.selection.backward ? context.selection.anchor : context.selection.focus, startBlockKey = isKeyedSegment(startPoint.path[0]) ? startPoint.path[0]._key : void 0, endBlockKey = isKeyedSegment(endPoint.path[0]) ? endPoint.path[0]._key : void 0, startChildKey = isKeyedSegment(startPoint.path[2]) ? startPoint.path[2]._key : void 0, endChildKey = isKeyedSegment(endPoint.path[2]) ? endPoint.path[2]._key : void 0;
|
|
150
362
|
if (!startBlockKey || !endBlockKey)
|
|
151
363
|
return slice;
|
|
152
364
|
for (const block of blocks) {
|
|
153
|
-
if (!
|
|
365
|
+
if (!isTextBlock(context, block) && block._key === startBlockKey && block._key === endBlockKey) {
|
|
154
366
|
startBlock = block;
|
|
155
367
|
break;
|
|
156
368
|
}
|
|
157
369
|
if (block._key === startBlockKey) {
|
|
158
|
-
if (!
|
|
370
|
+
if (!isTextBlock(context, block)) {
|
|
159
371
|
startBlock = block;
|
|
160
372
|
continue;
|
|
161
373
|
}
|
|
162
374
|
if (startChildKey) {
|
|
163
375
|
for (const child of block.children) {
|
|
164
376
|
if (child._key === startChildKey) {
|
|
165
|
-
if (
|
|
377
|
+
if (isSpan$1(context, child)) {
|
|
166
378
|
const text = child._key === endChildKey ? child.text.slice(startPoint.offset, endPoint.offset) : child.text.slice(startPoint.offset);
|
|
167
379
|
startBlock = {
|
|
168
380
|
...block,
|
|
@@ -180,7 +392,7 @@ function sliceBlocks({
|
|
|
180
392
|
break;
|
|
181
393
|
continue;
|
|
182
394
|
}
|
|
183
|
-
if (startBlock &&
|
|
395
|
+
if (startBlock && isTextBlock(context, startBlock) && (endChildKey && child._key === endChildKey && isSpan$1(context, child) ? startBlock.children.push({
|
|
184
396
|
...child,
|
|
185
397
|
text: child.text.slice(0, endPoint.offset)
|
|
186
398
|
}) : startBlock.children.push(child), block._key === endBlockKey && endChildKey && child._key === endChildKey))
|
|
@@ -194,7 +406,7 @@ function sliceBlocks({
|
|
|
194
406
|
break;
|
|
195
407
|
}
|
|
196
408
|
if (block._key === endBlockKey) {
|
|
197
|
-
if (!
|
|
409
|
+
if (!isTextBlock(context, block)) {
|
|
198
410
|
endBlock = block;
|
|
199
411
|
break;
|
|
200
412
|
}
|
|
@@ -204,8 +416,8 @@ function sliceBlocks({
|
|
|
204
416
|
children: []
|
|
205
417
|
};
|
|
206
418
|
for (const child of block.children)
|
|
207
|
-
if (endBlock &&
|
|
208
|
-
if (child._key === endChildKey &&
|
|
419
|
+
if (endBlock && isTextBlock(context, endBlock)) {
|
|
420
|
+
if (child._key === endChildKey && isSpan$1(context, child)) {
|
|
209
421
|
endBlock.children.push({
|
|
210
422
|
...child,
|
|
211
423
|
text: child.text.slice(0, endPoint.offset)
|
|
@@ -231,7 +443,15 @@ exports.getTextBlockText = getTextBlockText;
|
|
|
231
443
|
exports.isEmptyTextBlock = isEmptyTextBlock;
|
|
232
444
|
exports.isEqualSelectionPoints = isEqualSelectionPoints;
|
|
233
445
|
exports.isKeyedSegment = isKeyedSegment;
|
|
234
|
-
exports.
|
|
446
|
+
exports.isListBlock = isListBlock;
|
|
447
|
+
exports.isSpan = isSpan$1;
|
|
448
|
+
exports.isSpan$1 = isSpan;
|
|
449
|
+
exports.isTextBlock = isTextBlock;
|
|
450
|
+
exports.isTypedObject = isTypedObject;
|
|
451
|
+
exports.parseAnnotation = parseAnnotation;
|
|
452
|
+
exports.parseBlock = parseBlock;
|
|
453
|
+
exports.parseBlocks = parseBlocks;
|
|
454
|
+
exports.parseInlineObject = parseInlineObject;
|
|
235
455
|
exports.reverseSelection = reverseSelection;
|
|
236
456
|
exports.sliceBlocks = sliceBlocks;
|
|
237
457
|
exports.spanSelectionPointToBlockOffset = spanSelectionPointToBlockOffset;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.slice-blocks.cjs","sources":["../../src/utils/util.is-keyed-segment.ts","../../src/utils/util.block-offset.ts","../../src/utils/util.get-block-end-point.ts","../../src/utils/util.get-block-start-point.ts","../../src/utils/util.get-text-block-text.ts","../../src/utils/util.is-empty-text-block.ts","../../src/utils/util.is-equal-selection-points.ts","../../src/utils/util.is-span.ts","../../src/utils/util.reverse-selection.ts","../../src/utils/util.slice-blocks.ts"],"sourcesContent":["import type {KeyedSegment} from '@sanity/types'\n\n/**\n * @public\n */\nexport function isKeyedSegment(segment: unknown): segment is KeyedSegment {\n return typeof segment === 'object' && segment !== null && '_key' in segment\n}\n","import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {isKeyedSegment} from './util.is-keyed-segment'\n\n/**\n * @public\n */\nexport function blockOffsetToSpanSelectionPoint({\n value,\n blockOffset,\n direction,\n}: {\n value: Array<PortableTextBlock>\n blockOffset: BlockOffset\n direction: 'forward' | 'backward'\n}) {\n let offsetLeft = blockOffset.offset\n let selectionPoint:\n | {path: [KeyedSegment, 'children', KeyedSegment]; offset: number}\n | undefined\n let skippedInlineObject = false\n\n for (const block of value) {\n if (block._key !== blockOffset.path[0]._key) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n for (const child of block.children) {\n if (direction === 'forward') {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (offsetLeft <= child.text.length) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: offsetLeft,\n }\n break\n }\n\n offsetLeft -= child.text.length\n\n continue\n }\n\n if (!isPortableTextSpan(child)) {\n skippedInlineObject = true\n continue\n }\n\n if (offsetLeft === 0 && selectionPoint && !skippedInlineObject) {\n if (skippedInlineObject) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: 0,\n }\n }\n break\n }\n\n if (offsetLeft > child.text.length) {\n offsetLeft -= child.text.length\n continue\n }\n\n if (offsetLeft <= child.text.length) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: offsetLeft,\n }\n\n offsetLeft -= child.text.length\n\n if (offsetLeft !== 0) {\n break\n }\n }\n }\n }\n\n return selectionPoint\n}\n\n/**\n * @public\n */\nexport function spanSelectionPointToBlockOffset({\n value,\n selectionPoint,\n}: {\n value: Array<PortableTextBlock>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n let offset = 0\n\n const blockKey = isKeyedSegment(selectionPoint.path[0])\n ? selectionPoint.path[0]._key\n : undefined\n const spanKey = isKeyedSegment(selectionPoint.path[2])\n ? selectionPoint.path[2]._key\n : undefined\n\n if (!blockKey || !spanKey) {\n return undefined\n }\n\n for (const block of value) {\n if (block._key !== blockKey) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (child._key === spanKey) {\n return {\n path: [{_key: block._key}],\n offset: offset + selectionPoint.offset,\n }\n }\n\n offset += child.text.length\n }\n }\n}\n","import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getBlockEndPoint({\n node,\n path,\n}: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelectionPoint {\n if (isPortableTextTextBlock(node)) {\n const lastChild = node.children[node.children.length - 1]\n\n if (lastChild) {\n return {\n path: [...path, 'children', {_key: lastChild._key}],\n offset: isPortableTextSpan(lastChild) ? lastChild.text.length : 0,\n }\n }\n }\n\n return {\n path,\n offset: 0,\n }\n}\n","import {\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getBlockStartPoint({\n node,\n path,\n}: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelectionPoint {\n if (isPortableTextTextBlock(node)) {\n return {\n path: [...path, 'children', {_key: node.children[0]._key}],\n offset: 0,\n }\n }\n\n return {\n path,\n offset: 0,\n }\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\n\n/**\n * @public\n */\nexport function getTextBlockText(block: PortableTextTextBlock) {\n return block.children.map((child) => child.text ?? '').join('')\n}\n","import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type PortableTextBlock,\n} from '@sanity/types'\nimport {getTextBlockText} from './util.get-text-block-text'\n\n/**\n * @public\n */\nexport function isEmptyTextBlock(block: PortableTextBlock) {\n if (!isPortableTextTextBlock(block)) {\n return false\n }\n\n const onlyText = block.children.every(isPortableTextSpan)\n const blockText = getTextBlockText(block)\n\n return onlyText && blockText === ''\n}\n","import type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function isEqualSelectionPoints(\n a: EditorSelectionPoint,\n b: EditorSelectionPoint,\n) {\n return (\n a.offset === b.offset && JSON.stringify(a.path) === JSON.stringify(b.path)\n )\n}\n","import type {PortableTextChild, PortableTextSpan} from '@sanity/types'\nimport type {EditorContext} from '..'\n\n/**\n * @public\n */\nexport function isSpan(\n context: Pick<EditorContext, 'schema'>,\n child: PortableTextChild,\n): child is PortableTextSpan {\n return child._type === context.schema.span.name\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 {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {EditorSelection} from '..'\n\n/**\n * @public\n */\nexport function sliceBlocks({\n blocks,\n selection,\n}: {\n blocks: Array<PortableTextBlock>\n selection: EditorSelection\n}): Array<PortableTextBlock> {\n const slice: Array<PortableTextBlock> = []\n\n if (!selection) {\n return slice\n }\n\n let startBlock: PortableTextBlock | undefined\n const middleBlocks: PortableTextBlock[] = []\n let endBlock: PortableTextBlock | undefined\n\n const startPoint = selection.backward ? selection.focus : selection.anchor\n const endPoint = selection.backward ? selection.anchor : selection.focus\n\n const startBlockKey = isKeySegment(startPoint.path[0])\n ? startPoint.path[0]._key\n : undefined\n const endBlockKey = isKeySegment(endPoint.path[0])\n ? endPoint.path[0]._key\n : undefined\n const startChildKey = isKeySegment(startPoint.path[2])\n ? startPoint.path[2]._key\n : undefined\n const endChildKey = isKeySegment(endPoint.path[2])\n ? endPoint.path[2]._key\n : undefined\n\n if (!startBlockKey || !endBlockKey) {\n return slice\n }\n\n for (const block of blocks) {\n if (!isPortableTextTextBlock(block)) {\n if (block._key === startBlockKey && block._key === endBlockKey) {\n startBlock = block\n break\n }\n }\n\n if (block._key === startBlockKey) {\n if (!isPortableTextTextBlock(block)) {\n startBlock = block\n continue\n }\n\n if (startChildKey) {\n for (const child of block.children) {\n if (child._key === startChildKey) {\n if (isPortableTextSpan(child)) {\n const text =\n child._key === endChildKey\n ? child.text.slice(startPoint.offset, endPoint.offset)\n : child.text.slice(startPoint.offset)\n\n startBlock = {\n ...block,\n children: [\n {\n ...child,\n text,\n },\n ],\n }\n } else {\n startBlock = {\n ...block,\n children: [child],\n }\n }\n\n if (startChildKey === endChildKey) {\n break\n }\n continue\n }\n\n if (startBlock && isPortableTextTextBlock(startBlock)) {\n if (\n endChildKey &&\n child._key === endChildKey &&\n isPortableTextSpan(child)\n ) {\n startBlock.children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n } else {\n startBlock.children.push(child)\n }\n\n if (\n block._key === endBlockKey &&\n endChildKey &&\n child._key === endChildKey\n ) {\n break\n }\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n startBlock = block\n\n if (startBlockKey === endBlockKey) {\n break\n }\n }\n\n if (block._key === endBlockKey) {\n if (!isPortableTextTextBlock(block)) {\n endBlock = block\n break\n }\n\n if (endChildKey) {\n endBlock = {\n ...block,\n children: [],\n }\n\n for (const child of block.children) {\n if (endBlock && isPortableTextTextBlock(endBlock)) {\n if (child._key === endChildKey && isPortableTextSpan(child)) {\n endBlock.children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n\n break\n }\n\n endBlock.children.push(child)\n\n if (endChildKey && child._key === endChildKey) {\n break\n }\n }\n }\n\n break\n }\n\n endBlock = block\n\n break\n }\n\n if (startBlock) {\n middleBlocks.push(block)\n }\n }\n\n return [\n ...(startBlock ? [startBlock] : []),\n ...middleBlocks,\n ...(endBlock ? [endBlock] : []),\n ]\n}\n"],"names":["isKeyedSegment","segment","blockOffsetToSpanSelectionPoint","value","blockOffset","direction","offsetLeft","offset","selectionPoint","skippedInlineObject","block","_key","path","isPortableTextTextBlock","child","children","isPortableTextSpan","text","length","spanSelectionPointToBlockOffset","blockKey","undefined","spanKey","getBlockEndPoint","node","lastChild","getBlockStartPoint","getTextBlockText","map","join","isEmptyTextBlock","onlyText","every","blockText","isEqualSelectionPoints","a","b","JSON","stringify","isSpan","context","_type","schema","span","name","reverseSelection","selection","backward","anchor","focus","sliceBlocks","blocks","slice","startBlock","middleBlocks","endBlock","startPoint","endPoint","startBlockKey","isKeySegment","endBlockKey","startChildKey","endChildKey","push"],"mappings":";;AAKO,SAASA,eAAeC,SAA2C;AACxE,SAAO,OAAOA,WAAY,YAAYA,YAAY,QAAQ,UAAUA;AACtE;ACMO,SAASC,gCAAgC;AAAA,EAC9CC;AAAAA,EACAC;AAAAA,EACAC;AAKF,GAAG;AACD,MAAIC,aAAaF,YAAYG,QACzBC,gBAGAC,sBAAsB;AAE1B,aAAWC,SAASP;AACdO,QAAAA,MAAMC,SAASP,YAAYQ,KAAK,CAAC,EAAED,QAIlCE,8BAAwBH,KAAK;AAIvBI,iBAAAA,SAASJ,MAAMK,UAAU;AAClC,YAAIV,cAAc,WAAW;AACvB,cAAA,CAACW,yBAAmBF,KAAK;AAC3B;AAGER,cAAAA,cAAcQ,MAAMG,KAAKC,QAAQ;AAClB,6BAAA;AAAA,cACfN,MAAM,CAAC,GAAGR,YAAYQ,MAAM,YAAY;AAAA,gBAACD,MAAMG,MAAMH;AAAAA,cAAAA,CAAK;AAAA,cAC1DJ,QAAQD;AAAAA,YACV;AACA;AAAA,UAAA;AAGFA,wBAAcQ,MAAMG,KAAKC;AAEzB;AAAA,QAAA;AAGE,YAAA,CAACF,MAAAA,mBAAmBF,KAAK,GAAG;AACR,gCAAA;AACtB;AAAA,QAAA;AAGF,YAAIR,eAAe,KAAKE,kBAAkB,CAACC,qBAAqB;AAC1DA,kCACFD,iBAAiB;AAAA,YACfI,MAAM,CAAC,GAAGR,YAAYQ,MAAM,YAAY;AAAA,cAACD,MAAMG,MAAMH;AAAAA,YAAAA,CAAK;AAAA,YAC1DJ,QAAQ;AAAA,UAAA;AAGZ;AAAA,QAAA;AAGED,YAAAA,aAAaQ,MAAMG,KAAKC,QAAQ;AAClCZ,wBAAcQ,MAAMG,KAAKC;AACzB;AAAA,QAA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,GAAGjD;AAAAA,gBACHG,MAAMH,MAAMG,KAAKmC,MAAM,GAAGK,SAASlD,MAAM;AAAA,cAAA,CAC1C;AAED;AAAA,YAAA;AAKF,gBAFAgD,SAASxC,SAASgD,KAAKjD,KAAK,GAExBgD,eAAehD,MAAMH,SAASmD;AAChC;AAAA,UAAA;AAKN;AAAA,MAAA;AAGSpD,iBAAAA;AAEX;AAAA,IAAA;AAGE2C,kBACFC,aAAaS,KAAKrD,KAAK;AAAA,EAAA;AAI3B,SAAO,CACL,GAAI2C,aAAa,CAACA,UAAU,IAAI,CAAA,GAChC,GAAGC,cACH,GAAIC,WAAW,CAACA,QAAQ,IAAI,CAAA,CAAG;AAEnC;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"util.slice-blocks.cjs","sources":["../../src/internal-utils/asserters.ts","../../src/internal-utils/parse-blocks.ts","../../src/utils/util.is-keyed-segment.ts","../../src/utils/util.block-offset.ts","../../src/utils/util.get-block-end-point.ts","../../src/utils/util.get-block-start-point.ts","../../src/utils/util.get-text-block-text.ts","../../src/utils/util.is-empty-text-block.ts","../../src/utils/util.is-equal-selection-points.ts","../../src/utils/util.is-span.ts","../../src/utils/util.reverse-selection.ts","../../src/utils/util.slice-blocks.ts"],"sourcesContent":["import type {TypedObject} from '@sanity/types'\n\nexport function isTypedObject(object: unknown): object is TypedObject {\n return isRecord(object) && typeof object._type === 'string'\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && (typeof value === 'object' || typeof value === 'function')\n}\n","import type {\n PortableTextBlock,\n PortableTextListBlock,\n PortableTextObject,\n PortableTextSpan,\n PortableTextTextBlock,\n TypedObject,\n} from '@sanity/types'\nimport type {EditorSchema} from '../editor/editor-schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isTypedObject} from './asserters'\n\nexport function parseBlocks({\n context,\n blocks,\n options,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n blocks: unknown\n options: {\n refreshKeys: boolean\n }\n}): Array<PortableTextBlock> {\n if (!Array.isArray(blocks)) {\n return []\n }\n\n return blocks.flatMap((block) => {\n const parsedBlock = parseBlock({context, block, options})\n\n return parsedBlock ? [parsedBlock] : []\n })\n}\n\nexport function parseBlock({\n context,\n block,\n options,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n block: unknown\n options: {\n refreshKeys: boolean\n }\n}): PortableTextBlock | undefined {\n return (\n parseTextBlock({block, context, options}) ??\n parseBlockObject({blockObject: block, context, options})\n )\n}\n\nfunction parseBlockObject({\n blockObject,\n context,\n options,\n}: {\n blockObject: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {refreshKeys: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(blockObject)) {\n return undefined\n }\n\n const schemaType = context.schema.blockObjects.find(\n ({name}) => name === blockObject._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: blockObject,\n context: {\n keyGenerator: context.keyGenerator,\n schemaType,\n },\n options,\n })\n}\n\nexport function isListBlock(\n context: Pick<EditorContext, 'schema'>,\n block: unknown,\n): block is PortableTextListBlock {\n return (\n isTextBlock(context, block) &&\n block.level !== undefined &&\n block.listItem !== undefined\n )\n}\n\nexport function isTextBlock(\n context: Pick<EditorContext, 'schema'>,\n block: unknown,\n): block is PortableTextTextBlock {\n return (\n parseTextBlock({\n block,\n context: {schema: context.schema, keyGenerator: () => ''},\n options: {refreshKeys: false},\n }) !== undefined\n )\n}\n\nfunction parseTextBlock({\n block,\n context,\n options,\n}: {\n block: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {refreshKeys: boolean}\n}): PortableTextTextBlock | undefined {\n if (!isTypedObject(block)) {\n return undefined\n }\n\n if (block._type !== context.schema.block.name) {\n return undefined\n }\n\n const _key = options.refreshKeys\n ? context.keyGenerator()\n : typeof block._key === 'string'\n ? block._key\n : context.keyGenerator()\n\n const unparsedMarkDefs: Array<unknown> = Array.isArray(block.markDefs)\n ? block.markDefs\n : []\n const markDefKeyMap = new Map<string, string>()\n const markDefs = unparsedMarkDefs.flatMap((markDef) => {\n if (!isTypedObject(markDef)) {\n return []\n }\n\n const schemaType = context.schema.annotations.find(\n ({name}) => name === markDef._type,\n )\n\n if (!schemaType) {\n return []\n }\n\n if (typeof markDef._key !== 'string') {\n // If the `markDef` doesn't have a `_key` then we don't know what spans\n // it belongs to and therefore we have to discard it.\n return []\n }\n\n const parsedAnnotation = parseObject({\n object: markDef,\n context: {\n schemaType,\n keyGenerator: context.keyGenerator,\n },\n options,\n })\n\n if (!parsedAnnotation) {\n return []\n }\n\n markDefKeyMap.set(markDef._key, parsedAnnotation._key)\n\n return [parsedAnnotation]\n })\n\n const unparsedChildren: Array<unknown> = Array.isArray(block.children)\n ? block.children\n : []\n\n const children = unparsedChildren\n .map(\n (child) =>\n parseSpan({span: child, context, markDefKeyMap, options}) ??\n parseInlineObject({inlineObject: child, context, options}),\n )\n .filter((child) => child !== undefined)\n\n const parsedBlock: PortableTextTextBlock = {\n _type: context.schema.block.name,\n _key,\n children:\n children.length > 0\n ? children\n : [\n {\n _key: context.keyGenerator(),\n _type: context.schema.span.name,\n text: '',\n marks: [],\n },\n ],\n markDefs,\n }\n\n if (\n typeof block.style === 'string' &&\n context.schema.styles.find((style) => style.name === block.style)\n ) {\n parsedBlock.style = block.style\n } else {\n const defaultStyle = context.schema.styles.at(0)?.name\n\n if (defaultStyle !== undefined) {\n parsedBlock.style = defaultStyle\n } else {\n console.error('Expected default style')\n }\n }\n\n if (\n typeof block.listItem === 'string' &&\n context.schema.lists.find((list) => list.name === block.listItem)\n ) {\n parsedBlock.listItem = block.listItem\n }\n\n if (typeof block.level === 'number') {\n parsedBlock.level = block.level\n }\n\n return parsedBlock\n}\n\nexport function isSpan(\n context: Pick<EditorContext, 'schema'>,\n child: unknown,\n): child is PortableTextSpan {\n return (\n parseSpan({\n span: child,\n markDefKeyMap: new Map(),\n context: {schema: context.schema, keyGenerator: () => ''},\n options: {refreshKeys: false},\n }) !== undefined\n )\n}\n\nexport function parseSpan({\n span,\n context,\n markDefKeyMap,\n options,\n}: {\n span: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n markDefKeyMap: Map<string, string>\n options: {refreshKeys: boolean}\n}): PortableTextSpan | undefined {\n if (!isTypedObject(span)) {\n return undefined\n }\n\n // In reality, the span schema name is always 'span', but we only the check here anyway\n if (span._type !== context.schema.span.name || span._type !== 'span') {\n return undefined\n }\n\n const unparsedMarks: Array<unknown> = Array.isArray(span.marks)\n ? span.marks\n : []\n const marks = unparsedMarks.flatMap((mark) => {\n if (typeof mark !== 'string') {\n return []\n }\n\n const markDefKey = markDefKeyMap.get(mark)\n\n if (markDefKey !== undefined) {\n return [markDefKey]\n }\n\n if (\n context.schema.decorators.some((decorator) => decorator.name === mark)\n ) {\n return [mark]\n }\n\n return []\n })\n\n return {\n _type: 'span',\n _key: options.refreshKeys\n ? context.keyGenerator()\n : typeof span._key === 'string'\n ? span._key\n : context.keyGenerator(),\n text: typeof span.text === 'string' ? span.text : '',\n marks,\n }\n}\n\nexport function parseInlineObject({\n inlineObject,\n context,\n options,\n}: {\n inlineObject: unknown\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {refreshKeys: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(inlineObject)) {\n return undefined\n }\n\n const schemaType = context.schema.inlineObjects.find(\n ({name}) => name === inlineObject._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: inlineObject,\n context: {\n keyGenerator: context.keyGenerator,\n schemaType,\n },\n options,\n })\n}\n\nexport function parseAnnotation({\n annotation,\n context,\n options,\n}: {\n annotation: TypedObject\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n options: {refreshKeys: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(annotation)) {\n return undefined\n }\n\n const schemaType = context.schema.annotations.find(\n ({name}) => name === annotation._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: annotation,\n context: {\n keyGenerator: context.keyGenerator,\n schemaType,\n },\n options,\n })\n}\n\nfunction parseObject({\n object,\n context,\n options,\n}: {\n object: TypedObject\n context: Pick<EditorContext, 'keyGenerator'> & {\n schemaType: EditorSchema['blockObjects'][0]\n }\n options: {refreshKeys: boolean}\n}): PortableTextObject {\n // Validates all props on the object and only takes those that match\n // the name of a field\n const values = context.schemaType.fields.reduce<Record<string, unknown>>(\n (fieldValues, field) => {\n const fieldValue = object[field.name]\n\n if (fieldValue !== undefined) {\n fieldValues[field.name] = fieldValue\n }\n\n return fieldValues\n },\n {},\n )\n\n return {\n _type: context.schemaType.name,\n _key: options.refreshKeys\n ? context.keyGenerator()\n : typeof object._key === 'string'\n ? object._key\n : context.keyGenerator(),\n ...values,\n }\n}\n","import type {KeyedSegment} from '@sanity/types'\n\n/**\n * @public\n */\nexport function isKeyedSegment(segment: unknown): segment is KeyedSegment {\n return typeof segment === 'object' && segment !== null && '_key' in segment\n}\n","import type {KeyedSegment} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan, isTextBlock} from '../internal-utils/parse-blocks'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {isKeyedSegment} from './util.is-keyed-segment'\n\n/**\n * @public\n */\nexport function blockOffsetToSpanSelectionPoint({\n context,\n blockOffset,\n direction,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n blockOffset: BlockOffset\n direction: 'forward' | 'backward'\n}) {\n let offsetLeft = blockOffset.offset\n let selectionPoint:\n | {path: [KeyedSegment, 'children', KeyedSegment]; offset: number}\n | undefined\n let skippedInlineObject = false\n\n for (const block of context.value) {\n if (block._key !== blockOffset.path[0]._key) {\n continue\n }\n\n if (!isTextBlock(context, block)) {\n continue\n }\n\n for (const child of block.children) {\n if (direction === 'forward') {\n if (!isSpan(context, child)) {\n continue\n }\n\n if (offsetLeft <= child.text.length) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: offsetLeft,\n }\n break\n }\n\n offsetLeft -= child.text.length\n\n continue\n }\n\n if (!isSpan(context, child)) {\n skippedInlineObject = true\n continue\n }\n\n if (offsetLeft === 0 && selectionPoint && !skippedInlineObject) {\n if (skippedInlineObject) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: 0,\n }\n }\n break\n }\n\n if (offsetLeft > child.text.length) {\n offsetLeft -= child.text.length\n continue\n }\n\n if (offsetLeft <= child.text.length) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: offsetLeft,\n }\n\n offsetLeft -= child.text.length\n\n if (offsetLeft !== 0) {\n break\n }\n }\n }\n }\n\n return selectionPoint\n}\n\n/**\n * @public\n */\nexport function spanSelectionPointToBlockOffset({\n context,\n selectionPoint,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n let offset = 0\n\n const blockKey = isKeyedSegment(selectionPoint.path[0])\n ? selectionPoint.path[0]._key\n : undefined\n const spanKey = isKeyedSegment(selectionPoint.path[2])\n ? selectionPoint.path[2]._key\n : undefined\n\n if (!blockKey || !spanKey) {\n return undefined\n }\n\n for (const block of context.value) {\n if (block._key !== blockKey) {\n continue\n }\n\n if (!isTextBlock(context, block)) {\n continue\n }\n\n for (const child of block.children) {\n if (!isSpan(context, child)) {\n continue\n }\n\n if (child._key === spanKey) {\n return {\n path: [{_key: block._key}],\n offset: offset + selectionPoint.offset,\n }\n }\n\n offset += child.text.length\n }\n }\n}\n","import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan, isTextBlock} from '../internal-utils/parse-blocks'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getBlockEndPoint({\n context,\n block,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n}): EditorSelectionPoint {\n if (isTextBlock(context, block.node)) {\n const lastChild = block.node.children[block.node.children.length - 1]\n\n if (lastChild) {\n return {\n path: [...block.path, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n }\n }\n }\n\n return {\n path: block.path,\n offset: 0,\n }\n}\n","import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getBlockStartPoint({\n context,\n block,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n}): EditorSelectionPoint {\n if (isTextBlock(context, block.node)) {\n return {\n path: [...block.path, 'children', {_key: block.node.children[0]._key}],\n offset: 0,\n }\n }\n\n return {\n path: block.path,\n offset: 0,\n }\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\n\n/**\n * @public\n */\nexport function getTextBlockText(block: PortableTextTextBlock) {\n return block.children.map((child) => child.text ?? '').join('')\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan, isTextBlock} from '../internal-utils/parse-blocks'\nimport {getTextBlockText} from './util.get-text-block-text'\n\n/**\n * @public\n */\nexport function isEmptyTextBlock(\n context: Pick<EditorContext, 'schema'>,\n block: PortableTextBlock,\n) {\n if (!isTextBlock(context, block)) {\n return false\n }\n\n const onlyText = block.children.every((child) => isSpan(context, child))\n const blockText = getTextBlockText(block)\n\n return onlyText && blockText === ''\n}\n","import type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function isEqualSelectionPoints(\n a: EditorSelectionPoint,\n b: EditorSelectionPoint,\n) {\n return (\n a.offset === b.offset && JSON.stringify(a.path) === JSON.stringify(b.path)\n )\n}\n","import type {PortableTextChild, PortableTextSpan} from '@sanity/types'\nimport type {EditorContext} from '..'\n\n/**\n * @public\n */\nexport function isSpan(\n context: Pick<EditorContext, 'schema'>,\n child: PortableTextChild,\n): child is PortableTextSpan {\n return child._type === context.schema.span.name\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 type {PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\nimport {isSpan, isTextBlock} from '../internal-utils/parse-blocks'\nimport {isKeyedSegment} from './util.is-keyed-segment'\n\n/**\n * @public\n */\nexport function sliceBlocks({\n context,\n blocks,\n}: {\n context: Pick<EditorContext, 'schema' | 'selection'>\n blocks: Array<PortableTextBlock>\n}): Array<PortableTextBlock> {\n const slice: Array<PortableTextBlock> = []\n\n if (!context.selection) {\n return slice\n }\n\n let startBlock: PortableTextBlock | undefined\n const middleBlocks: PortableTextBlock[] = []\n let endBlock: PortableTextBlock | undefined\n\n const startPoint = context.selection.backward\n ? context.selection.focus\n : context.selection.anchor\n const endPoint = context.selection.backward\n ? context.selection.anchor\n : context.selection.focus\n\n const startBlockKey = isKeyedSegment(startPoint.path[0])\n ? startPoint.path[0]._key\n : undefined\n const endBlockKey = isKeyedSegment(endPoint.path[0])\n ? endPoint.path[0]._key\n : undefined\n const startChildKey = isKeyedSegment(startPoint.path[2])\n ? startPoint.path[2]._key\n : undefined\n const endChildKey = isKeyedSegment(endPoint.path[2])\n ? endPoint.path[2]._key\n : undefined\n\n if (!startBlockKey || !endBlockKey) {\n return slice\n }\n\n for (const block of blocks) {\n if (!isTextBlock(context, block)) {\n if (block._key === startBlockKey && block._key === endBlockKey) {\n startBlock = block\n break\n }\n }\n\n if (block._key === startBlockKey) {\n if (!isTextBlock(context, block)) {\n startBlock = block\n continue\n }\n\n if (startChildKey) {\n for (const child of block.children) {\n if (child._key === startChildKey) {\n if (isSpan(context, child)) {\n const text =\n child._key === endChildKey\n ? child.text.slice(startPoint.offset, endPoint.offset)\n : child.text.slice(startPoint.offset)\n\n startBlock = {\n ...block,\n children: [\n {\n ...child,\n text,\n },\n ],\n }\n } else {\n startBlock = {\n ...block,\n children: [child],\n }\n }\n\n if (startChildKey === endChildKey) {\n break\n }\n continue\n }\n\n if (startBlock && isTextBlock(context, startBlock)) {\n if (\n endChildKey &&\n child._key === endChildKey &&\n isSpan(context, child)\n ) {\n startBlock.children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n } else {\n startBlock.children.push(child)\n }\n\n if (\n block._key === endBlockKey &&\n endChildKey &&\n child._key === endChildKey\n ) {\n break\n }\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n startBlock = block\n\n if (startBlockKey === endBlockKey) {\n break\n }\n }\n\n if (block._key === endBlockKey) {\n if (!isTextBlock(context, block)) {\n endBlock = block\n break\n }\n\n if (endChildKey) {\n endBlock = {\n ...block,\n children: [],\n }\n\n for (const child of block.children) {\n if (endBlock && isTextBlock(context, endBlock)) {\n if (child._key === endChildKey && isSpan(context, child)) {\n endBlock.children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n\n break\n }\n\n endBlock.children.push(child)\n\n if (endChildKey && child._key === endChildKey) {\n break\n }\n }\n }\n\n break\n }\n\n endBlock = block\n\n break\n }\n\n if (startBlock) {\n middleBlocks.push(block)\n }\n }\n\n return [\n ...(startBlock ? [startBlock] : []),\n ...middleBlocks,\n ...(endBlock ? [endBlock] : []),\n ]\n}\n"],"names":["isTypedObject","object","isRecord","_type","value","parseBlocks","context","blocks","options","Array","isArray","flatMap","block","parsedBlock","parseBlock","parseTextBlock","parseBlockObject","blockObject","schemaType","schema","blockObjects","find","name","parseObject","keyGenerator","isListBlock","isTextBlock","level","undefined","listItem","refreshKeys","_key","unparsedMarkDefs","markDefs","markDefKeyMap","Map","markDef","annotations","parsedAnnotation","set","children","map","child","parseSpan","span","parseInlineObject","inlineObject","filter","length","text","marks","style","styles","defaultStyle","at","console","error","lists","list","isSpan","mark","markDefKey","get","decorators","some","decorator","inlineObjects","parseAnnotation","annotation","values","fields","reduce","fieldValues","field","fieldValue","isKeyedSegment","segment","blockOffsetToSpanSelectionPoint","blockOffset","direction","offsetLeft","offset","selectionPoint","skippedInlineObject","path","spanSelectionPointToBlockOffset","blockKey","spanKey","getBlockEndPoint","node","lastChild","getBlockStartPoint","getTextBlockText","join","isEmptyTextBlock","onlyText","every","blockText","isEqualSelectionPoints","a","b","JSON","stringify","reverseSelection","selection","backward","anchor","focus","sliceBlocks","slice","startBlock","middleBlocks","endBlock","startPoint","endPoint","startBlockKey","endBlockKey","startChildKey","endChildKey","push"],"mappings":";AAEO,SAASA,cAAcC,QAAwC;AACpE,SAAOC,SAASD,MAAM,KAAK,OAAOA,OAAOE,SAAU;AACrD;AAEA,SAASD,SAASE,OAAkD;AAClE,SAAO,CAAC,CAACA,UAAU,OAAOA,SAAU,YAAY,OAAOA,SAAU;AACnE;ACIO,SAASC,YAAY;AAAA,EAC1BC;AAAAA,EACAC;AAAAA,EACAC;AAOF,GAA6B;AAC3B,SAAKC,MAAMC,QAAQH,MAAM,IAIlBA,OAAOI,QAASC,CAAU,UAAA;AAC/B,UAAMC,cAAcC,WAAW;AAAA,MAACR;AAAAA,MAASM;AAAAA,MAAOJ;AAAAA,IAAAA,CAAQ;AAExD,WAAOK,cAAc,CAACA,WAAW,IAAI,CAAE;AAAA,EACxC,CAAA,IAPQ,CAAE;AAQb;AAEO,SAASC,WAAW;AAAA,EACzBR;AAAAA,EACAM;AAAAA,EACAJ;AAOF,GAAkC;AAChC,SACEO,eAAe;AAAA,IAACH;AAAAA,IAAON;AAAAA,IAASE;AAAAA,EAAQ,CAAA,KACxCQ,iBAAiB;AA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A,aAAalG,OAETuG,kBAAkBC;AACpB;AAAA,IAAA;AAIAxG,QAAAA,MAAMmB,SAASqF,aAAa;AAC9B,UAAI,CAAC1F,YAAYpB,SAASM,KAAK,GAAG;AACrBA,mBAAAA;AACX;AAAA,MAAA;AAGF,UAAI0G,aAAa;AACJ,mBAAA;AAAA,UACT,GAAG1G;AAAAA,UACH4B,UAAU,CAAA;AAAA,QACZ;AAEA,mBAAWE,SAAS9B,MAAM4B;AACxB,cAAIwE,YAAYtF,YAAYpB,SAAS0G,QAAQ,GAAG;AAC9C,gBAAItE,MAAMX,SAASuF,eAAe3D,SAAOrD,SAASoC,KAAK,GAAG;AACxDsE,uBAASxE,SAAS+E,KAAK;AAAA,gBACrB,GAAG7E;AAAAA,gBACHO,MAAMP,MAAMO,KAAK4D,MAAM,GAAGK,SAASjC,MAAM;AAAA,cAAA,CAC1C;AAED;AAAA,YAAA;AAKF,gBAFA+B,SAASxE,SAAS+E,KAAK7E,KAAK,GAExB4E,eAAe5E,MAAMX,SAASuF;AAChC;AAAA,UAAA;AAKN;AAAA,MAAA;AAGS1G,iBAAAA;AAEX;AAAA,IAAA;AAGEkG,kBACFC,aAAaQ,KAAK3G,KAAK;AAAA,EAAA;AAI3B,SAAO,CACL,GAAIkG,aAAa,CAACA,UAAU,IAAI,CAAA,GAChC,GAAGC,cACH,GAAIC,WAAW,CAACA,QAAQ,IAAI,CAAA,CAAG;AAEnC;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { isSelectionCollapsed, getCaretWordSelection, isSelectionExpanded, getFocusBlockObject, getPreviousBlock, getNextBlock, getFocusTextBlock, isOverlappingSelection, isAtTheEndOfBlock, getFocusSpan, isAtTheStartOfBlock, getFirstBlock, getLastBlock, getSelectedBlocks, getSelectionStartBlock, getSelectionEndBlock, getFocusListBlock
|
|
2
|
-
import {
|
|
3
|
-
import { isEmptyTextBlock, getBlockStartPoint, getBlockEndPoint, isEqualSelectionPoints } from "./util.slice-blocks.js";
|
|
1
|
+
import { isSelectionCollapsed, getCaretWordSelection, isSelectionExpanded, getFocusBlockObject, getPreviousBlock, getNextBlock, getFocusTextBlock, isOverlappingSelection, isAtTheEndOfBlock, getFocusSpan, isAtTheStartOfBlock, getFirstBlock, getLastBlock, getSelectedBlocks, getSelectionStartBlock, getSelectionEndBlock, getFocusListBlock } from "./selector.is-overlapping-selection.js";
|
|
2
|
+
import { isEmptyTextBlock, isTextBlock, getBlockStartPoint, getBlockEndPoint, isEqualSelectionPoints, isListBlock } from "./util.slice-blocks.js";
|
|
4
3
|
import { getSelectionStartPoint, getSelectionEndPoint } from "./util.get-selection-start-point.js";
|
|
5
4
|
function execute(event) {
|
|
6
5
|
return {
|
|
@@ -304,7 +303,7 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
304
303
|
snapshot
|
|
305
304
|
}) => {
|
|
306
305
|
const focusTextBlock = getFocusTextBlock(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot), previousBlock = getPreviousBlock(snapshot);
|
|
307
|
-
return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !
|
|
306
|
+
return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : isEmptyTextBlock(snapshot.context, focusTextBlock.node) && !isTextBlock(snapshot.context, previousBlock.node) ? {
|
|
308
307
|
focusTextBlock,
|
|
309
308
|
previousBlock
|
|
310
309
|
} : !1;
|
|
@@ -334,7 +333,7 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
334
333
|
snapshot
|
|
335
334
|
}) => {
|
|
336
335
|
const focusTextBlock = getFocusTextBlock(snapshot), selectionCollapsed = isSelectionCollapsed(snapshot), nextBlock = getNextBlock(snapshot);
|
|
337
|
-
return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !
|
|
336
|
+
return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : isEmptyTextBlock(snapshot.context, focusTextBlock.node) && !isTextBlock(snapshot.context, nextBlock.node) ? {
|
|
338
337
|
focusTextBlock,
|
|
339
338
|
nextBlock
|
|
340
339
|
} : !1;
|
|
@@ -517,7 +516,13 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
517
516
|
const firstBlock = getFirstBlock(snapshot), lastBlock = getLastBlock(snapshot);
|
|
518
517
|
if (!firstBlock || !lastBlock)
|
|
519
518
|
return !1;
|
|
520
|
-
const firstBlockStartPoint = getBlockStartPoint(
|
|
519
|
+
const firstBlockStartPoint = getBlockStartPoint({
|
|
520
|
+
context: snapshot.context,
|
|
521
|
+
block: firstBlock
|
|
522
|
+
}), selectionStartPoint = getSelectionStartPoint(snapshot.context.selection), lastBlockEndPoint = getBlockEndPoint({
|
|
523
|
+
context: snapshot.context,
|
|
524
|
+
block: lastBlock
|
|
525
|
+
}), selectionEndPoint = getSelectionEndPoint(snapshot.context.selection);
|
|
521
526
|
return isEqualSelectionPoints(firstBlockStartPoint, selectionStartPoint) && isEqualSelectionPoints(lastBlockEndPoint, selectionEndPoint) ? {
|
|
522
527
|
selection: snapshot.context.selection
|
|
523
528
|
} : !1;
|
|
@@ -538,7 +543,13 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
538
543
|
const selectedBlocks = getSelectedBlocks(snapshot), selectionStartBlock = getSelectionStartBlock(snapshot), selectionEndBlock = getSelectionEndBlock(snapshot);
|
|
539
544
|
if (!selectionStartBlock || !selectionEndBlock)
|
|
540
545
|
return !1;
|
|
541
|
-
const startBlockStartPoint = getBlockStartPoint(
|
|
546
|
+
const startBlockStartPoint = getBlockStartPoint({
|
|
547
|
+
context: snapshot.context,
|
|
548
|
+
block: selectionStartBlock
|
|
549
|
+
}), selectionStartPoint = getSelectionStartPoint(snapshot.context.selection), endBlockEndPoint = getBlockEndPoint({
|
|
550
|
+
context: snapshot.context,
|
|
551
|
+
block: selectionEndBlock
|
|
552
|
+
}), selectionEndPoint = getSelectionEndPoint(snapshot.context.selection);
|
|
542
553
|
return isEqualSelectionPoints(selectionStartPoint, startBlockStartPoint) && isEqualSelectionPoints(selectionEndPoint, endBlockEndPoint) ? {
|
|
543
554
|
selectedBlocks
|
|
544
555
|
} : !1;
|
|
@@ -612,7 +623,7 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
612
623
|
snapshot
|
|
613
624
|
}) => {
|
|
614
625
|
const selectionCollapsed = isSelectionCollapsed(snapshot), focusListBlock = getFocusListBlock(snapshot);
|
|
615
|
-
return !selectionCollapsed || !focusListBlock || !isEmptyTextBlock(focusListBlock.node) ? !1 : {
|
|
626
|
+
return !selectionCollapsed || !focusListBlock || !isEmptyTextBlock(snapshot.context, focusListBlock.node) ? !1 : {
|
|
616
627
|
focusListBlock
|
|
617
628
|
};
|
|
618
629
|
},
|
|
@@ -631,7 +642,7 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
631
642
|
}) => {
|
|
632
643
|
if (!isHotkey("Tab", event.originEvent))
|
|
633
644
|
return !1;
|
|
634
|
-
const selectedBlocks = getSelectedBlocks(snapshot),
|
|
645
|
+
const selectedBlocks = getSelectedBlocks(snapshot), selectedListBlocks = selectedBlocks.flatMap((block) => isListBlock(snapshot.context, block.node) ? [{
|
|
635
646
|
node: block.node,
|
|
636
647
|
path: block.path
|
|
637
648
|
}] : []);
|
|
@@ -656,7 +667,7 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
656
667
|
}) => {
|
|
657
668
|
if (!isHotkey("Shift+Tab", event.originEvent))
|
|
658
669
|
return !1;
|
|
659
|
-
const selectedBlocks = getSelectedBlocks(snapshot),
|
|
670
|
+
const selectedBlocks = getSelectedBlocks(snapshot), selectedListBlocks = selectedBlocks.flatMap((block) => isListBlock(snapshot.context, block.node) ? [{
|
|
660
671
|
node: block.node,
|
|
661
672
|
path: block.path
|
|
662
673
|
}] : []);
|