@portabletext/editor 1.34.0 → 1.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/behavior.core.cjs +57 -118
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +27 -67
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/plugin.event-listener.cjs +53 -71
- package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +5 -7
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-active-style.cjs +22 -36
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +68 -153
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
- package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +57 -118
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +27 -67
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/plugin.event-listener.js +53 -71
- package/lib/_chunks-es/plugin.event-listener.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +5 -7
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-active-style.js +22 -36
- package/lib/_chunks-es/selector.is-active-style.js.map +1 -1
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +68 -153
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/_chunks-es/util.block-offsets-to-selection.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/behaviors/index.cjs +18 -48
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +28 -16
- package/lib/behaviors/index.d.ts +28 -16
- package/lib/behaviors/index.js +18 -48
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.d.cts +132 -71
- package/lib/index.d.ts +132 -71
- package/lib/plugins/index.cjs +182 -186
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +147 -82
- package/lib/plugins/index.d.ts +147 -82
- package/lib/plugins/index.js +182 -186
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs +22 -50
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +9 -200
- package/lib/selectors/index.d.ts +9 -200
- package/lib/selectors/index.js +22 -50
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +15 -7
- package/lib/utils/index.d.ts +15 -7
- package/lib/utils/index.js.map +1 -1
- package/package.json +6 -6
- package/src/behaviors/behavior.code-editor.ts +6 -6
- package/src/behaviors/behavior.core.annotations.ts +5 -4
- package/src/behaviors/behavior.core.block-objects.ts +17 -17
- package/src/behaviors/behavior.core.decorators.ts +12 -8
- package/src/behaviors/behavior.core.insert-break.ts +27 -29
- package/src/behaviors/behavior.core.lists.ts +19 -19
- package/src/behaviors/behavior.decorator-pair.ts +200 -0
- package/src/behaviors/behavior.default.ts +35 -30
- package/src/behaviors/behavior.emoji-picker.ts +12 -12
- package/src/behaviors/behavior.links.ts +7 -7
- package/src/behaviors/behavior.markdown.ts +41 -42
- package/src/behaviors/behavior.types.ts +15 -18
- package/src/behaviors/index.ts +0 -1
- package/src/converters/converter.json.ts +6 -6
- package/src/converters/converter.portable-text.deserialize.test.ts +28 -26
- package/src/converters/converter.portable-text.ts +6 -6
- package/src/converters/converter.text-html.deserialize.test.ts +17 -15
- package/src/converters/converter.text-html.serialize.test.ts +57 -53
- package/src/converters/converter.text-html.ts +14 -10
- package/src/converters/converter.text-plain.test.ts +17 -15
- package/src/converters/converter.text-plain.ts +15 -11
- package/src/converters/converter.types.ts +8 -7
- package/src/editor/editor-machine.ts +6 -1
- package/src/editor/plugins/create-with-event-listeners.ts +0 -5
- package/src/index.ts +3 -3
- package/src/internal-utils/get-text-to-emphasize.ts +29 -7
- package/src/plugins/plugin.decorator-shortcut.ts +235 -0
- package/src/plugins/plugin.markdown.tsx +56 -8
- package/src/plugins/plugin.one-line.tsx +17 -17
- package/src/selectors/selector.get-active-list-item.ts +4 -4
- package/src/selectors/selector.get-active-style.ts +6 -6
- package/src/selectors/selector.get-anchor-block.ts +5 -5
- package/src/selectors/selector.get-anchor-child.ts +5 -5
- package/src/selectors/selector.get-anchor-span.ts +2 -2
- package/src/selectors/selector.get-anchor-text-block.ts +2 -2
- package/src/selectors/selector.get-block-offsets.ts +8 -7
- package/src/selectors/selector.get-caret-word-selection.ts +19 -16
- package/src/selectors/selector.get-next-inline-object.ts +4 -4
- package/src/selectors/selector.get-previous-inline-object.ts +4 -4
- package/src/selectors/selector.get-selected-slice.ts +7 -4
- package/src/selectors/selector.get-selected-spans.ts +9 -9
- package/src/selectors/selector.get-selection-end-point.ts +5 -5
- package/src/selectors/selector.get-selection-start-point.ts +5 -5
- package/src/selectors/selector.get-selection-text.ts +2 -2
- package/src/selectors/selector.get-selection.ts +2 -2
- package/src/selectors/selector.get-text-before.ts +8 -8
- package/src/selectors/selector.get-trimmed-selection.ts +15 -13
- package/src/selectors/selector.get-value.ts +4 -4
- package/src/selectors/selector.is-at-the-end-of-block.ts +6 -3
- package/src/selectors/selector.is-at-the-start-of-block.ts +3 -3
- package/src/selectors/selector.is-overlapping-selection.ts +8 -6
- package/src/selectors/selector.is-selection-collapsed.ts +6 -5
- package/src/selectors/selector.is-selection-expanded.ts +2 -2
- package/src/selectors/selectors.ts +59 -59
- package/src/types/block-offset.ts +9 -0
- package/src/utils/index.ts +0 -1
- package/src/utils/util.block-offset.ts +1 -1
- package/src/utils/util.block-offsets-to-selection.ts +1 -1
- package/src/utils/util.child-selection-point-to-block-offset.ts +1 -1
- package/src/behaviors/behavior.markdown-emphasis.ts +0 -437
|
@@ -14,100 +14,72 @@ function createGuards({
|
|
|
14
14
|
isTextBlock
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
const getFocusBlock = ({
|
|
18
|
-
context
|
|
19
|
-
}) => {
|
|
20
|
-
const key = context.selection && types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
|
|
17
|
+
const getFocusBlock = (snapshot) => {
|
|
18
|
+
const key = snapshot.context.selection && types.isKeySegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0, node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
|
|
21
19
|
return node && key ? {
|
|
22
20
|
node,
|
|
23
21
|
path: [{
|
|
24
22
|
_key: key
|
|
25
23
|
}]
|
|
26
24
|
} : void 0;
|
|
27
|
-
}, getFocusListBlock = ({
|
|
28
|
-
context
|
|
29
|
-
}) => {
|
|
30
|
-
const guards = createGuards(context), focusBlock = getFocusBlock({
|
|
31
|
-
context
|
|
32
|
-
});
|
|
25
|
+
}, getFocusListBlock = (snapshot) => {
|
|
26
|
+
const guards = createGuards(snapshot.context), focusBlock = getFocusBlock(snapshot);
|
|
33
27
|
return focusBlock && guards.isListBlock(focusBlock.node) ? {
|
|
34
28
|
node: focusBlock.node,
|
|
35
29
|
path: focusBlock.path
|
|
36
30
|
} : void 0;
|
|
37
|
-
}, getFocusTextBlock = ({
|
|
38
|
-
|
|
39
|
-
}) => {
|
|
40
|
-
const focusBlock = getFocusBlock({
|
|
41
|
-
context
|
|
42
|
-
});
|
|
31
|
+
}, getFocusTextBlock = (snapshot) => {
|
|
32
|
+
const focusBlock = getFocusBlock(snapshot);
|
|
43
33
|
return focusBlock && types.isPortableTextTextBlock(focusBlock.node) ? {
|
|
44
34
|
node: focusBlock.node,
|
|
45
35
|
path: focusBlock.path
|
|
46
36
|
} : void 0;
|
|
47
|
-
}, getFocusBlockObject = ({
|
|
48
|
-
|
|
49
|
-
}) => {
|
|
50
|
-
const focusBlock = getFocusBlock({
|
|
51
|
-
context
|
|
52
|
-
});
|
|
37
|
+
}, getFocusBlockObject = (snapshot) => {
|
|
38
|
+
const focusBlock = getFocusBlock(snapshot);
|
|
53
39
|
return focusBlock && !types.isPortableTextTextBlock(focusBlock.node) ? {
|
|
54
40
|
node: focusBlock.node,
|
|
55
41
|
path: focusBlock.path
|
|
56
42
|
} : void 0;
|
|
57
|
-
}, getFocusChild = ({
|
|
58
|
-
|
|
59
|
-
}) => {
|
|
60
|
-
const focusBlock = getFocusTextBlock({
|
|
61
|
-
context
|
|
62
|
-
});
|
|
43
|
+
}, getFocusChild = (snapshot) => {
|
|
44
|
+
const focusBlock = getFocusTextBlock(snapshot);
|
|
63
45
|
if (!focusBlock)
|
|
64
46
|
return;
|
|
65
|
-
const key = context.selection && types.isKeySegment(context.selection.focus.path[2]) ? context.selection.focus.path[2]._key : void 0, node = key ? focusBlock.node.children.find((span) => span._key === key) : void 0;
|
|
47
|
+
const key = snapshot.context.selection && types.isKeySegment(snapshot.context.selection.focus.path[2]) ? snapshot.context.selection.focus.path[2]._key : void 0, node = key ? focusBlock.node.children.find((span) => span._key === key) : void 0;
|
|
66
48
|
return node && key ? {
|
|
67
49
|
node,
|
|
68
50
|
path: [...focusBlock.path, "children", {
|
|
69
51
|
_key: key
|
|
70
52
|
}]
|
|
71
53
|
} : void 0;
|
|
72
|
-
}, getFocusSpan = ({
|
|
73
|
-
|
|
74
|
-
}) => {
|
|
75
|
-
const focusChild = getFocusChild({
|
|
76
|
-
context
|
|
77
|
-
});
|
|
54
|
+
}, getFocusSpan = (snapshot) => {
|
|
55
|
+
const focusChild = getFocusChild(snapshot);
|
|
78
56
|
return focusChild && types.isPortableTextSpan(focusChild.node) ? {
|
|
79
57
|
node: focusChild.node,
|
|
80
58
|
path: focusChild.path
|
|
81
59
|
} : void 0;
|
|
82
|
-
}, getFirstBlock = ({
|
|
83
|
-
context
|
|
84
|
-
}) => {
|
|
85
|
-
const node = context.value[0];
|
|
60
|
+
}, getFirstBlock = (snapshot) => {
|
|
61
|
+
const node = snapshot.context.value[0];
|
|
86
62
|
return node ? {
|
|
87
63
|
node,
|
|
88
64
|
path: [{
|
|
89
65
|
_key: node._key
|
|
90
66
|
}]
|
|
91
67
|
} : void 0;
|
|
92
|
-
}, getLastBlock = ({
|
|
93
|
-
context
|
|
94
|
-
}) => {
|
|
95
|
-
const node = context.value[context.value.length - 1] ? context.value[context.value.length - 1] : void 0;
|
|
68
|
+
}, getLastBlock = (snapshot) => {
|
|
69
|
+
const node = snapshot.context.value[snapshot.context.value.length - 1] ? snapshot.context.value[snapshot.context.value.length - 1] : void 0;
|
|
96
70
|
return node ? {
|
|
97
71
|
node,
|
|
98
72
|
path: [{
|
|
99
73
|
_key: node._key
|
|
100
74
|
}]
|
|
101
75
|
} : void 0;
|
|
102
|
-
}, getSelectedBlocks = ({
|
|
103
|
-
context
|
|
104
|
-
}) => {
|
|
105
|
-
if (!context.selection)
|
|
76
|
+
}, getSelectedBlocks = (snapshot) => {
|
|
77
|
+
if (!snapshot.context.selection)
|
|
106
78
|
return [];
|
|
107
|
-
const selectedBlocks = [], startKey = context.selection.backward ? types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0 : types.isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0, endKey = context.selection.backward ? types.isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0 : types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0;
|
|
79
|
+
const selectedBlocks = [], startKey = snapshot.context.selection.backward ? types.isKeySegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0 : types.isKeySegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0, endKey = snapshot.context.selection.backward ? types.isKeySegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0 : types.isKeySegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0;
|
|
108
80
|
if (!startKey || !endKey)
|
|
109
81
|
return selectedBlocks;
|
|
110
|
-
for (const block of context.value) {
|
|
82
|
+
for (const block of snapshot.context.value) {
|
|
111
83
|
if (block._key === startKey) {
|
|
112
84
|
if (selectedBlocks.push({
|
|
113
85
|
node: block,
|
|
@@ -135,41 +107,33 @@ const getFocusBlock = ({
|
|
|
135
107
|
});
|
|
136
108
|
}
|
|
137
109
|
return selectedBlocks;
|
|
138
|
-
}, getSelectionStartBlock = ({
|
|
139
|
-
context
|
|
140
|
-
}) => {
|
|
141
|
-
if (!context.selection)
|
|
110
|
+
}, getSelectionStartBlock = (snapshot) => {
|
|
111
|
+
if (!snapshot.context.selection)
|
|
142
112
|
return;
|
|
143
|
-
const key = context.selection.backward ? types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0 : types.isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
|
|
113
|
+
const key = snapshot.context.selection.backward ? types.isKeySegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0 : types.isKeySegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0, node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
|
|
144
114
|
return node && key ? {
|
|
145
115
|
node,
|
|
146
116
|
path: [{
|
|
147
117
|
_key: key
|
|
148
118
|
}]
|
|
149
119
|
} : void 0;
|
|
150
|
-
}, getSelectionEndBlock = ({
|
|
151
|
-
context
|
|
152
|
-
}) => {
|
|
153
|
-
if (!context.selection)
|
|
120
|
+
}, getSelectionEndBlock = (snapshot) => {
|
|
121
|
+
if (!snapshot.context.selection)
|
|
154
122
|
return;
|
|
155
|
-
const key = context.selection.backward ? types.isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0 : types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
|
|
123
|
+
const key = snapshot.context.selection.backward ? types.isKeySegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0 : types.isKeySegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0, node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
|
|
156
124
|
return node && key ? {
|
|
157
125
|
node,
|
|
158
126
|
path: [{
|
|
159
127
|
_key: key
|
|
160
128
|
}]
|
|
161
129
|
} : void 0;
|
|
162
|
-
}, getPreviousBlock = ({
|
|
163
|
-
context
|
|
164
|
-
}) => {
|
|
130
|
+
}, getPreviousBlock = (snapshot) => {
|
|
165
131
|
let previousBlock;
|
|
166
|
-
const selectionStartBlock = getSelectionStartBlock(
|
|
167
|
-
context
|
|
168
|
-
});
|
|
132
|
+
const selectionStartBlock = getSelectionStartBlock(snapshot);
|
|
169
133
|
if (!selectionStartBlock)
|
|
170
134
|
return;
|
|
171
135
|
let foundSelectionStartBlock = !1;
|
|
172
|
-
for (const block of context.value) {
|
|
136
|
+
for (const block of snapshot.context.value) {
|
|
173
137
|
if (block._key === selectionStartBlock.node._key) {
|
|
174
138
|
foundSelectionStartBlock = !0;
|
|
175
139
|
break;
|
|
@@ -183,17 +147,13 @@ const getFocusBlock = ({
|
|
|
183
147
|
}
|
|
184
148
|
if (foundSelectionStartBlock && previousBlock)
|
|
185
149
|
return previousBlock;
|
|
186
|
-
}, getNextBlock = ({
|
|
187
|
-
context
|
|
188
|
-
}) => {
|
|
150
|
+
}, getNextBlock = (snapshot) => {
|
|
189
151
|
let nextBlock;
|
|
190
|
-
const selectionEndBlock = getSelectionEndBlock(
|
|
191
|
-
context
|
|
192
|
-
});
|
|
152
|
+
const selectionEndBlock = getSelectionEndBlock(snapshot);
|
|
193
153
|
if (!selectionEndBlock)
|
|
194
154
|
return;
|
|
195
155
|
let foundSelectionEndBlock = !1;
|
|
196
|
-
for (const block of context.value) {
|
|
156
|
+
for (const block of snapshot.context.value) {
|
|
197
157
|
if (block._key === selectionEndBlock.node._key) {
|
|
198
158
|
foundSelectionEndBlock = !0;
|
|
199
159
|
continue;
|
|
@@ -210,24 +170,14 @@ const getFocusBlock = ({
|
|
|
210
170
|
}
|
|
211
171
|
if (foundSelectionEndBlock && nextBlock)
|
|
212
172
|
return nextBlock;
|
|
213
|
-
}, getSelectionEndPoint = ({
|
|
214
|
-
context
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (context.selection)
|
|
222
|
-
return context.selection.backward ? context.selection.focus : context.selection.anchor;
|
|
223
|
-
}, getNextInlineObject = ({
|
|
224
|
-
context
|
|
225
|
-
}) => {
|
|
226
|
-
const focusTextBlock = getFocusTextBlock({
|
|
227
|
-
context
|
|
228
|
-
}), selectionEndPoint = getSelectionEndPoint({
|
|
229
|
-
context
|
|
230
|
-
}), selectionEndPointChildKey = selectionEndPoint && types.isKeySegment(selectionEndPoint.path[2]) ? selectionEndPoint.path[2]._key : void 0;
|
|
173
|
+
}, getSelectionEndPoint = (snapshot) => {
|
|
174
|
+
if (snapshot.context.selection)
|
|
175
|
+
return snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus;
|
|
176
|
+
}, getSelectionStartPoint = (snapshot) => {
|
|
177
|
+
if (snapshot.context.selection)
|
|
178
|
+
return snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor;
|
|
179
|
+
}, getNextInlineObject = (snapshot) => {
|
|
180
|
+
const focusTextBlock = getFocusTextBlock(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot), selectionEndPointChildKey = selectionEndPoint && types.isKeySegment(selectionEndPoint.path[2]) ? selectionEndPoint.path[2]._key : void 0;
|
|
231
181
|
if (!focusTextBlock || !selectionEndPointChildKey)
|
|
232
182
|
return;
|
|
233
183
|
let endPointChildFound = !1, inlineObject;
|
|
@@ -236,7 +186,7 @@ const getFocusBlock = ({
|
|
|
236
186
|
endPointChildFound = !0;
|
|
237
187
|
continue;
|
|
238
188
|
}
|
|
239
|
-
if (!util_sliceBlocks.isSpan(context, child) && endPointChildFound) {
|
|
189
|
+
if (!util_sliceBlocks.isSpan(snapshot.context, child) && endPointChildFound) {
|
|
240
190
|
inlineObject = {
|
|
241
191
|
node: child,
|
|
242
192
|
path: [...focusTextBlock.path, "children", {
|
|
@@ -247,21 +197,15 @@ const getFocusBlock = ({
|
|
|
247
197
|
}
|
|
248
198
|
}
|
|
249
199
|
return inlineObject;
|
|
250
|
-
}, getPreviousInlineObject = ({
|
|
251
|
-
|
|
252
|
-
}) => {
|
|
253
|
-
const focusTextBlock = getFocusTextBlock({
|
|
254
|
-
context
|
|
255
|
-
}), selectionStartPoint = getSelectionStartPoint({
|
|
256
|
-
context
|
|
257
|
-
}), selectionStartPointChildKey = selectionStartPoint && types.isKeySegment(selectionStartPoint.path[2]) ? selectionStartPoint.path[2]._key : void 0;
|
|
200
|
+
}, getPreviousInlineObject = (snapshot) => {
|
|
201
|
+
const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartPointChildKey = selectionStartPoint && types.isKeySegment(selectionStartPoint.path[2]) ? selectionStartPoint.path[2]._key : void 0;
|
|
258
202
|
if (!focusTextBlock || !selectionStartPointChildKey)
|
|
259
203
|
return;
|
|
260
204
|
let inlineObject;
|
|
261
205
|
for (const child of focusTextBlock.node.children) {
|
|
262
206
|
if (child._key === selectionStartPointChildKey)
|
|
263
207
|
break;
|
|
264
|
-
util_sliceBlocks.isSpan(context, child) || (inlineObject = {
|
|
208
|
+
util_sliceBlocks.isSpan(snapshot.context, child) || (inlineObject = {
|
|
265
209
|
node: child,
|
|
266
210
|
path: [...focusTextBlock.path, "children", {
|
|
267
211
|
_key: child._key
|
|
@@ -269,43 +213,22 @@ const getFocusBlock = ({
|
|
|
269
213
|
});
|
|
270
214
|
}
|
|
271
215
|
return inlineObject;
|
|
272
|
-
}, getSelectedSlice = ({
|
|
273
|
-
context
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}), getSelectionText = ({
|
|
278
|
-
context
|
|
279
|
-
}) => getSelectedSlice({
|
|
280
|
-
context
|
|
281
|
-
}).reduce((text, block) => types.isPortableTextTextBlock(block) ? text + block.children.reduce((text2, child) => types.isPortableTextSpan(child) ? text2 + child.text : text2, "") : text, ""), isSelectionCollapsed = ({
|
|
282
|
-
context
|
|
283
|
-
}) => context.selection ? JSON.stringify(context.selection.anchor.path) === JSON.stringify(context.selection.focus.path) && context.selection?.anchor.offset === context.selection?.focus.offset : !1, isSelectionExpanded = ({
|
|
284
|
-
context
|
|
285
|
-
}) => !isSelectionCollapsed({
|
|
286
|
-
context
|
|
287
|
-
}), getCaretWordSelection = ({
|
|
288
|
-
context
|
|
289
|
-
}) => {
|
|
290
|
-
if (!context.selection || !isSelectionCollapsed({
|
|
291
|
-
context
|
|
292
|
-
}))
|
|
216
|
+
}, getSelectedSlice = (snapshot) => util_sliceBlocks.sliceBlocks({
|
|
217
|
+
blocks: snapshot.context.value,
|
|
218
|
+
selection: snapshot.context.selection
|
|
219
|
+
}), getSelectionText = (snapshot) => getSelectedSlice(snapshot).reduce((text, block) => types.isPortableTextTextBlock(block) ? text + block.children.reduce((text2, child) => types.isPortableTextSpan(child) ? text2 + child.text : text2, "") : text, ""), 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, isSelectionExpanded = (snapshot) => !isSelectionCollapsed(snapshot), getCaretWordSelection = (snapshot) => {
|
|
220
|
+
if (!snapshot.context.selection || !isSelectionCollapsed(snapshot))
|
|
293
221
|
return null;
|
|
294
|
-
const focusTextBlock = getFocusTextBlock({
|
|
295
|
-
context
|
|
296
|
-
}), selectionStartPoint = getSelectionStartPoint({
|
|
297
|
-
context
|
|
298
|
-
}), selectionStartOffset = selectionStartPoint ? util_sliceBlocks.spanSelectionPointToBlockOffset({
|
|
299
|
-
value: context.value,
|
|
222
|
+
const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartOffset = selectionStartPoint ? util_sliceBlocks.spanSelectionPointToBlockOffset({
|
|
223
|
+
value: snapshot.context.value,
|
|
300
224
|
selectionPoint: selectionStartPoint
|
|
301
225
|
}) : void 0;
|
|
302
226
|
if (!focusTextBlock || !selectionStartPoint || !selectionStartOffset)
|
|
303
227
|
return null;
|
|
304
|
-
const previousInlineObject = getPreviousInlineObject({
|
|
305
|
-
|
|
306
|
-
}), blockStartPoint = util_sliceBlocks.getBlockStartPoint(focusTextBlock), textDirectlyBefore = getSelectionText({
|
|
228
|
+
const previousInlineObject = getPreviousInlineObject(snapshot), blockStartPoint = util_sliceBlocks.getBlockStartPoint(focusTextBlock), textDirectlyBefore = getSelectionText({
|
|
229
|
+
...snapshot,
|
|
307
230
|
context: {
|
|
308
|
-
...context,
|
|
231
|
+
...snapshot.context,
|
|
309
232
|
selection: {
|
|
310
233
|
anchor: previousInlineObject ? {
|
|
311
234
|
path: previousInlineObject.path,
|
|
@@ -314,11 +237,10 @@ const getFocusBlock = ({
|
|
|
314
237
|
focus: selectionStartPoint
|
|
315
238
|
}
|
|
316
239
|
}
|
|
317
|
-
}).split(/\s+/).at(-1), nextInlineObject = getNextInlineObject({
|
|
318
|
-
|
|
319
|
-
}), blockEndPoint = util_sliceBlocks.getBlockEndPoint(focusTextBlock), textDirectlyAfter = getSelectionText({
|
|
240
|
+
}).split(/\s+/).at(-1), nextInlineObject = getNextInlineObject(snapshot), blockEndPoint = util_sliceBlocks.getBlockEndPoint(focusTextBlock), textDirectlyAfter = getSelectionText({
|
|
241
|
+
...snapshot,
|
|
320
242
|
context: {
|
|
321
|
-
...context,
|
|
243
|
+
...snapshot.context,
|
|
322
244
|
selection: {
|
|
323
245
|
anchor: selectionStartPoint,
|
|
324
246
|
focus: nextInlineObject ? {
|
|
@@ -337,11 +259,11 @@ const getFocusBlock = ({
|
|
|
337
259
|
...selectionStartOffset,
|
|
338
260
|
offset: selectionStartOffset.offset + textDirectlyAfter.length
|
|
339
261
|
} : selectionStartOffset, caretWordStartSelectionPoint = util_sliceBlocks.blockOffsetToSpanSelectionPoint({
|
|
340
|
-
value: context.value,
|
|
262
|
+
value: snapshot.context.value,
|
|
341
263
|
blockOffset: caretWordStartOffset,
|
|
342
264
|
direction: "backward"
|
|
343
265
|
}), caretWordEndSelectionPoint = util_sliceBlocks.blockOffsetToSpanSelectionPoint({
|
|
344
|
-
value: context.value,
|
|
266
|
+
value: snapshot.context.value,
|
|
345
267
|
blockOffset: caretWordEndOffset,
|
|
346
268
|
direction: "forward"
|
|
347
269
|
});
|
|
@@ -352,34 +274,27 @@ const getFocusBlock = ({
|
|
|
352
274
|
focus: caretWordEndSelectionPoint
|
|
353
275
|
};
|
|
354
276
|
return isSelectionExpanded({
|
|
277
|
+
...snapshot,
|
|
355
278
|
context: {
|
|
356
|
-
...context,
|
|
279
|
+
...snapshot.context,
|
|
357
280
|
selection: caretWordSelection
|
|
358
281
|
}
|
|
359
282
|
}) ? caretWordSelection : null;
|
|
360
283
|
};
|
|
361
284
|
function isAtTheEndOfBlock(block) {
|
|
362
|
-
return ({
|
|
363
|
-
context
|
|
364
|
-
}) => {
|
|
365
|
-
if (!context.selection || !isSelectionCollapsed({
|
|
366
|
-
context
|
|
367
|
-
}))
|
|
285
|
+
return (snapshot) => {
|
|
286
|
+
if (!snapshot.context.selection || !isSelectionCollapsed(snapshot))
|
|
368
287
|
return !1;
|
|
369
288
|
const blockEndPoint = util_sliceBlocks.getBlockEndPoint(block);
|
|
370
|
-
return util_sliceBlocks.isEqualSelectionPoints(context.selection.focus, blockEndPoint);
|
|
289
|
+
return util_sliceBlocks.isEqualSelectionPoints(snapshot.context.selection.focus, blockEndPoint);
|
|
371
290
|
};
|
|
372
291
|
}
|
|
373
292
|
function isAtTheStartOfBlock(block) {
|
|
374
|
-
return ({
|
|
375
|
-
context
|
|
376
|
-
}) => {
|
|
377
|
-
if (!context.selection || !isSelectionCollapsed({
|
|
378
|
-
context
|
|
379
|
-
}))
|
|
293
|
+
return (snapshot) => {
|
|
294
|
+
if (!snapshot.context.selection || !isSelectionCollapsed(snapshot))
|
|
380
295
|
return !1;
|
|
381
296
|
const blockStartPoint = util_sliceBlocks.getBlockStartPoint(block);
|
|
382
|
-
return util_sliceBlocks.isEqualSelectionPoints(context.selection.focus, blockStartPoint);
|
|
297
|
+
return util_sliceBlocks.isEqualSelectionPoints(snapshot.context.selection.focus, blockStartPoint);
|
|
383
298
|
};
|
|
384
299
|
}
|
|
385
300
|
exports.createGuards = createGuards;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selector.is-at-the-start-of-block.cjs","sources":["../../src/behavior-actions/behavior.guards.ts","../../src/selectors/selectors.ts","../../src/selectors/selector.get-selection-end-point.ts","../../src/selectors/selector.get-selection-start-point.ts","../../src/selectors/selector.get-next-inline-object.ts","../../src/selectors/selector.get-previous-inline-object.ts","../../src/selectors/selector.get-selected-slice.ts","../../src/selectors/selector.get-selection-text.ts","../../src/selectors/selector.is-selection-collapsed.ts","../../src/selectors/selector.is-selection-expanded.ts","../../src/selectors/selector.get-caret-word-selection.ts","../../src/selectors/selector.is-at-the-end-of-block.ts","../../src/selectors/selector.is-at-the-start-of-block.ts"],"sourcesContent":["import {\n isPortableTextListBlock,\n isPortableTextTextBlock,\n type PortableTextListBlock,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSchema} from '../editor/define-schema'\n\n/**\n * @alpha\n */\nexport type BehaviorGuards = ReturnType<typeof createGuards>\n\nexport function createGuards({schema}: {schema: EditorSchema}) {\n function isListBlock(block: unknown): block is PortableTextListBlock {\n return isPortableTextListBlock(block) && block._type === schema.block.name\n }\n\n function isTextBlock(block: unknown): block is PortableTextTextBlock {\n return isPortableTextTextBlock(block) && block._type === schema.block.name\n }\n\n return {isListBlock, isTextBlock}\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n type PortableTextListBlock,\n type PortableTextObject,\n type PortableTextSpan,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusListBlock: EditorSelector<\n {node: PortableTextListBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const guards = createGuards(context)\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && guards.isListBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusBlockObject: EditorSelector<\n {node: PortableTextObject; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && !isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n const focusBlock = getFocusTextBlock({context})\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[2])\n ? context.selection.focus.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? focusBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...focusBlock.path, 'children', {_key: key}]}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = ({context}) => {\n const focusChild = getFocusChild({context})\n\n return focusChild && isPortableTextSpan(focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFirstBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const node = context.value[0]\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getLastBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const node = context.value[context.value.length - 1]\n ? context.value[context.value.length - 1]\n : undefined\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getSelectedBlocks: EditorSelector<\n Array<{node: PortableTextBlock; path: [KeyedSegment]}>\n> = ({context}) => {\n if (!context.selection) {\n return []\n }\n\n const selectedBlocks: Array<{node: PortableTextBlock; path: [KeyedSegment]}> =\n []\n const startKey = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n const endKey = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n if (!startKey || !endKey) {\n return selectedBlocks\n }\n\n for (const block of context.value) {\n if (block._key === startKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n\n if (startKey === endKey) {\n break\n }\n continue\n }\n\n if (block._key === endKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n break\n }\n\n if (selectedBlocks.length > 0) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n }\n }\n\n return selectedBlocks\n}\n\n/**\n * @public\n */\nexport const getSelectionStartBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getSelectionEndBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getPreviousBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n let previousBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionStartBlock = getSelectionStartBlock({context})\n\n if (!selectionStartBlock) {\n return undefined\n }\n\n let foundSelectionStartBlock = false\n\n for (const block of context.value) {\n if (block._key === selectionStartBlock.node._key) {\n foundSelectionStartBlock = true\n break\n }\n\n previousBlock = {node: block, path: [{_key: block._key}]}\n }\n\n if (foundSelectionStartBlock && previousBlock) {\n return previousBlock\n }\n\n return undefined\n}\n\n/**\n * @public\n */\nexport const getNextBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n let nextBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionEndBlock = getSelectionEndBlock({context})\n\n if (!selectionEndBlock) {\n return undefined\n }\n\n let foundSelectionEndBlock = false\n\n for (const block of context.value) {\n if (block._key === selectionEndBlock.node._key) {\n foundSelectionEndBlock = true\n continue\n }\n\n if (foundSelectionEndBlock) {\n nextBlock = {node: block, path: [{_key: block._key}]}\n break\n }\n }\n\n if (foundSelectionEndBlock && nextBlock) {\n return nextBlock\n }\n\n return undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectionEndPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n return context.selection.backward\n ? context.selection.anchor\n : context.selection.focus\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectionStartPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n return context.selection.backward\n ? context.selection.focus\n : context.selection.anchor\n}\n","import {\n isKeySegment,\n type KeyedSegment,\n type PortableTextObject,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isSpan} from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getFocusTextBlock} from './selectors'\n\n/**\n * @public\n */\nexport const getNextInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n const focusTextBlock = getFocusTextBlock({context})\n const selectionEndPoint = getSelectionEndPoint({context})\n const selectionEndPointChildKey =\n selectionEndPoint && isKeySegment(selectionEndPoint.path[2])\n ? selectionEndPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionEndPointChildKey) {\n return undefined\n }\n\n let endPointChildFound = false\n let inlineObject:\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionEndPointChildKey) {\n endPointChildFound = true\n continue\n }\n\n if (!isSpan(context, child) && endPointChildFound) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n break\n }\n }\n\n return inlineObject\n}\n","import {\n isKeySegment,\n type KeyedSegment,\n type PortableTextObject,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isSpan} from '../utils'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {getFocusTextBlock} from './selectors'\n\n/**\n * @public\n */\nexport const getPreviousInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n const focusTextBlock = getFocusTextBlock({context})\n const selectionStartPoint = getSelectionStartPoint({context})\n const selectionStartPointChildKey =\n selectionStartPoint && isKeySegment(selectionStartPoint.path[2])\n ? selectionStartPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionStartPointChildKey) {\n return undefined\n }\n\n let inlineObject:\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionStartPointChildKey) {\n break\n }\n\n if (!isSpan(context, child)) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n }\n }\n\n return inlineObject\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {sliceBlocks} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = ({\n context,\n}) => {\n return sliceBlocks({blocks: context.value, selection: context.selection})\n}\n","import {isPortableTextSpan, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSlice} from './selector.get-selected-slice'\n\n/**\n * @public\n */\nexport const getSelectionText: EditorSelector<string> = ({context}) => {\n const selectedSlice = getSelectedSlice({context})\n\n return selectedSlice.reduce((text, block) => {\n if (!isPortableTextTextBlock(block)) {\n return text\n }\n\n return (\n text +\n block.children.reduce((text, child) => {\n if (isPortableTextSpan(child)) {\n return text + child.text\n }\n\n return text\n }, '')\n )\n }, '')\n}\n","import type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = ({context}) => {\n if (!context.selection) {\n return false\n }\n\n return (\n JSON.stringify(context.selection.anchor.path) ===\n JSON.stringify(context.selection.focus.path) &&\n context.selection?.anchor.offset === context.selection?.focus.offset\n )\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const isSelectionExpanded: EditorSelector<boolean> = ({context}) => {\n return !isSelectionCollapsed({context})\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelection} from '../types/editor'\nimport {\n blockOffsetToSpanSelectionPoint,\n getBlockEndPoint,\n getBlockStartPoint,\n spanSelectionPointToBlockOffset,\n type BlockOffset,\n} from '../utils'\nimport {getNextInlineObject} from './selector.get-next-inline-object'\nimport {getPreviousInlineObject} from './selector.get-previous-inline-object'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {getSelectionText} from './selector.get-selection-text'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\nimport {getFocusTextBlock} from './selectors'\n\n/**\n * @public\n * Returns the selection of the of the word the caret is placed in.\n * Note: Only returns a word selection if the current selection is collapsed\n */\nexport const getCaretWordSelection: EditorSelector<EditorSelection> = ({\n context,\n}) => {\n if (!context.selection) {\n return null\n }\n\n if (!isSelectionCollapsed({context})) {\n return null\n }\n\n const focusTextBlock = getFocusTextBlock({context})\n const selectionStartPoint = getSelectionStartPoint({context})\n const selectionStartOffset = selectionStartPoint\n ? spanSelectionPointToBlockOffset({\n value: context.value,\n selectionPoint: selectionStartPoint,\n })\n : undefined\n\n if (!focusTextBlock || !selectionStartPoint || !selectionStartOffset) {\n return null\n }\n\n const previousInlineObject = getPreviousInlineObject({context})\n const blockStartPoint = getBlockStartPoint(focusTextBlock)\n const textBefore = getSelectionText({\n context: {\n ...context,\n selection: {\n anchor: previousInlineObject\n ? {path: previousInlineObject.path, offset: 0}\n : blockStartPoint,\n focus: selectionStartPoint,\n },\n },\n })\n const textDirectlyBefore = textBefore.split(/\\s+/).at(-1)\n\n const nextInlineObject = getNextInlineObject({context})\n const blockEndPoint = getBlockEndPoint(focusTextBlock)\n const textAfter = getSelectionText({\n context: {\n ...context,\n selection: {\n anchor: selectionStartPoint,\n focus: nextInlineObject\n ? {path: nextInlineObject.path, offset: 0}\n : blockEndPoint,\n },\n },\n })\n const textDirectlyAfter = textAfter.split(/\\s+/).at(0)\n\n if (\n (textDirectlyBefore === undefined || textDirectlyBefore === '') &&\n (textDirectlyAfter === undefined || textDirectlyAfter === '')\n ) {\n return null\n }\n\n const caretWordStartOffset: BlockOffset = textDirectlyBefore\n ? {\n ...selectionStartOffset,\n offset: selectionStartOffset.offset - textDirectlyBefore.length,\n }\n : selectionStartOffset\n const caretWordEndOffset: BlockOffset = textDirectlyAfter\n ? {\n ...selectionStartOffset,\n offset: selectionStartOffset.offset + textDirectlyAfter.length,\n }\n : selectionStartOffset\n\n const caretWordStartSelectionPoint = blockOffsetToSpanSelectionPoint({\n value: context.value,\n blockOffset: caretWordStartOffset,\n direction: 'backward',\n })\n const caretWordEndSelectionPoint = blockOffsetToSpanSelectionPoint({\n value: context.value,\n blockOffset: caretWordEndOffset,\n direction: 'forward',\n })\n\n if (!caretWordStartSelectionPoint || !caretWordEndSelectionPoint) {\n return null\n }\n\n const caretWordSelection = {\n anchor: caretWordStartSelectionPoint,\n focus: caretWordEndSelectionPoint,\n }\n\n return isSelectionExpanded({\n context: {\n ...context,\n selection: caretWordSelection,\n },\n })\n ? caretWordSelection\n : null\n}\n","import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isAtTheEndOfBlock(block: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelector<boolean> {\n return ({context}) => {\n if (!context.selection || !isSelectionCollapsed({context})) {\n return false\n }\n\n const blockEndPoint = utils.getBlockEndPoint(block)\n\n return utils.isEqualSelectionPoints(context.selection.focus, blockEndPoint)\n }\n}\n","import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isAtTheStartOfBlock(block: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelector<boolean> {\n return ({context}) => {\n if (!context.selection || !isSelectionCollapsed({context})) {\n return false\n }\n\n const blockStartPoint = utils.getBlockStartPoint(block)\n\n return utils.isEqualSelectionPoints(\n context.selection.focus,\n blockStartPoint,\n )\n }\n}\n"],"names":["createGuards","schema","isListBlock","block","isPortableTextListBlock","_type","name","isTextBlock","isPortableTextTextBlock","getFocusBlock","context","key","selection","isKeySegment","focus","path","_key","undefined","node","value","find","getFocusListBlock","guards","focusBlock","getFocusTextBlock","getFocusBlockObject","getFocusChild","children","span","getFocusSpan","focusChild","isPortableTextSpan","getFirstBlock","getLastBlock","length","getSelectedBlocks","selectedBlocks","startKey","backward","anchor","endKey","push","getSelectionStartBlock","getSelectionEndBlock","getPreviousBlock","previousBlock","selectionStartBlock","foundSelectionStartBlock","getNextBlock","nextBlock","selectionEndBlock","foundSelectionEndBlock","getSelectionEndPoint","getSelectionStartPoint","getNextInlineObject","focusTextBlock","selectionEndPoint","selectionEndPointChildKey","endPointChildFound","inlineObject","child","isSpan","getPreviousInlineObject","selectionStartPoint","selectionStartPointChildKey","getSelectedSlice","sliceBlocks","blocks","getSelectionText","reduce","text","isSelectionCollapsed","JSON","stringify","offset","isSelectionExpanded","getCaretWordSelection","selectionStartOffset","spanSelectionPointToBlockOffset","selectionPoint","previousInlineObject","blockStartPoint","getBlockStartPoint","textDirectlyBefore","split","at","nextInlineObject","blockEndPoint","getBlockEndPoint","textDirectlyAfter","caretWordStartOffset","caretWordEndOffset","caretWordStartSelectionPoint","blockOffsetToSpanSelectionPoint","blockOffset","direction","caretWordEndSelectionPoint","caretWordSelection","isAtTheEndOfBlock","utils","isEqualSelectionPoints","isAtTheStartOfBlock"],"mappings":";;AAaO,SAASA,aAAa;AAAA,EAACC;AAA8B,GAAG;AAC7D,WAASC,YAAYC,OAAgD;AACnE,WAAOC,MAAAA,wBAAwBD,KAAK,KAAKA,MAAME,UAAUJ,OAAOE,MAAMG;AAAAA,EAAAA;AAGxE,WAASC,YAAYJ,OAAgD;AACnE,WAAOK,MAAAA,wBAAwBL,KAAK,KAAKA,MAAME,UAAUJ,OAAOE,MAAMG;AAAAA,EAAAA;AAGjE,SAAA;AAAA,IAACJ;AAAAA,IAAaK;AAAAA,EAAW;AAClC;ACNO,MAAME,gBAETA,CAAC;AAAA,EAACC;AAAO,MAAM;AACjB,QAAMC,MAAMD,QAAQE,aAChBC,MAAAA,aAAaH,QAAQE,UAAUE,MAAMC,KAAK,CAAC,CAAC,IAC1CL,QAAQE,UAAUE,MAAMC,KAAK,CAAC,EAAEC,OAElC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QS;AAAAA,IACf2E,aAAaH;AAAAA,IACbI,WAAW;AAAA,EAAA,CACZ;AAEG,MAAA,CAACH,gCAAgC,CAACI;AAC7B,WAAA;AAGT,QAAMC,qBAAqB;AAAA,IACzB1D,QAAQqD;AAAAA,IACR9E,OAAOkF;AAAAA,EACT;AAEA,SAAOrB,oBAAoB;AAAA,IACzBjE,SAAS;AAAA,MACP,GAAGA;AAAAA,MACHE,WAAWqF;AAAAA,IAAAA;AAAAA,EACb,CACD,IACGA,qBACA;AACN;ACpHO,SAASC,kBAAkB/F,OAGN;AAC1B,SAAO,CAAC;AAAA,IAACO;AAAAA,EAAAA,MAAa;AACpB,QAAI,CAACA,QAAQE,aAAa,CAAC2D,qBAAqB;AAAA,MAAC7D;AAAAA,IAAAA,CAAQ;AAChD,aAAA;AAGH6E,UAAAA,gBAAgBY,iBAAMX,iBAAiBrF,KAAK;AAElD,WAAOgG,iBAAMC,uBAAuB1F,QAAQE,UAAUE,OAAOyE,aAAa;AAAA,EAC5E;AACF;ACbO,SAASc,oBAAoBlG,OAGR;AAC1B,SAAO,CAAC;AAAA,IAACO;AAAAA,EAAAA,MAAa;AACpB,QAAI,CAACA,QAAQE,aAAa,CAAC2D,qBAAqB;AAAA,MAAC7D;AAAAA,IAAAA,CAAQ;AAChD,aAAA;AAGHuE,UAAAA,kBAAkBkB,iBAAMjB,mBAAmB/E,KAAK;AAEtD,WAAOgG,iBAAMC,uBACX1F,QAAQE,UAAUE,OAClBmE,eACF;AAAA,EACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"selector.is-at-the-start-of-block.cjs","sources":["../../src/behavior-actions/behavior.guards.ts","../../src/selectors/selectors.ts","../../src/selectors/selector.get-selection-end-point.ts","../../src/selectors/selector.get-selection-start-point.ts","../../src/selectors/selector.get-next-inline-object.ts","../../src/selectors/selector.get-previous-inline-object.ts","../../src/selectors/selector.get-selected-slice.ts","../../src/selectors/selector.get-selection-text.ts","../../src/selectors/selector.is-selection-collapsed.ts","../../src/selectors/selector.is-selection-expanded.ts","../../src/selectors/selector.get-caret-word-selection.ts","../../src/selectors/selector.is-at-the-end-of-block.ts","../../src/selectors/selector.is-at-the-start-of-block.ts"],"sourcesContent":["import {\n isPortableTextListBlock,\n isPortableTextTextBlock,\n type PortableTextListBlock,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSchema} from '../editor/define-schema'\n\n/**\n * @alpha\n */\nexport type BehaviorGuards = ReturnType<typeof createGuards>\n\nexport function createGuards({schema}: {schema: EditorSchema}) {\n function isListBlock(block: unknown): block is PortableTextListBlock {\n return isPortableTextListBlock(block) && block._type === schema.block.name\n }\n\n function isTextBlock(block: unknown): block is PortableTextTextBlock {\n return isPortableTextTextBlock(block) && block._type === schema.block.name\n }\n\n return {isListBlock, isTextBlock}\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n type PortableTextListBlock,\n type PortableTextObject,\n type PortableTextSpan,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const key = snapshot.context.selection\n ? isKeySegment(snapshot.context.selection.focus.path[0])\n ? snapshot.context.selection.focus.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusListBlock: EditorSelector<\n {node: PortableTextListBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const guards = createGuards(snapshot.context)\n const focusBlock = getFocusBlock(snapshot)\n\n return focusBlock && guards.isListBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n return focusBlock && isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusBlockObject: EditorSelector<\n {node: PortableTextObject; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n return focusBlock && !isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const focusBlock = getFocusTextBlock(snapshot)\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = snapshot.context.selection\n ? isKeySegment(snapshot.context.selection.focus.path[2])\n ? snapshot.context.selection.focus.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? focusBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...focusBlock.path, 'children', {_key: key}]}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const focusChild = getFocusChild(snapshot)\n\n return focusChild && isPortableTextSpan(focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFirstBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const node = snapshot.context.value[0]\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getLastBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const node = snapshot.context.value[snapshot.context.value.length - 1]\n ? snapshot.context.value[snapshot.context.value.length - 1]\n : undefined\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getSelectedBlocks: EditorSelector<\n Array<{node: PortableTextBlock; path: [KeyedSegment]}>\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedBlocks: Array<{node: PortableTextBlock; path: [KeyedSegment]}> =\n []\n const startKey = snapshot.context.selection.backward\n ? isKeySegment(snapshot.context.selection.focus.path[0])\n ? snapshot.context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n const endKey = snapshot.context.selection.backward\n ? isKeySegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(snapshot.context.selection.focus.path[0])\n ? snapshot.context.selection.focus.path[0]._key\n : undefined\n\n if (!startKey || !endKey) {\n return selectedBlocks\n }\n\n for (const block of snapshot.context.value) {\n if (block._key === startKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n\n if (startKey === endKey) {\n break\n }\n continue\n }\n\n if (block._key === endKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n break\n }\n\n if (selectedBlocks.length > 0) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n }\n }\n\n return selectedBlocks\n}\n\n/**\n * @public\n */\nexport const getSelectionStartBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = snapshot.context.selection.backward\n ? isKeySegment(snapshot.context.selection.focus.path[0])\n ? snapshot.context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getSelectionEndBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = snapshot.context.selection.backward\n ? isKeySegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(snapshot.context.selection.focus.path[0])\n ? snapshot.context.selection.focus.path[0]._key\n : undefined\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getPreviousBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n let previousBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionStartBlock = getSelectionStartBlock(snapshot)\n\n if (!selectionStartBlock) {\n return undefined\n }\n\n let foundSelectionStartBlock = false\n\n for (const block of snapshot.context.value) {\n if (block._key === selectionStartBlock.node._key) {\n foundSelectionStartBlock = true\n break\n }\n\n previousBlock = {node: block, path: [{_key: block._key}]}\n }\n\n if (foundSelectionStartBlock && previousBlock) {\n return previousBlock\n }\n\n return undefined\n}\n\n/**\n * @public\n */\nexport const getNextBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n let nextBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionEndBlock = getSelectionEndBlock(snapshot)\n\n if (!selectionEndBlock) {\n return undefined\n }\n\n let foundSelectionEndBlock = false\n\n for (const block of snapshot.context.value) {\n if (block._key === selectionEndBlock.node._key) {\n foundSelectionEndBlock = true\n continue\n }\n\n if (foundSelectionEndBlock) {\n nextBlock = {node: block, path: [{_key: block._key}]}\n break\n }\n }\n\n if (foundSelectionEndBlock && nextBlock) {\n return nextBlock\n }\n\n return undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectionEndPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n return snapshot.context.selection.backward\n ? snapshot.context.selection.anchor\n : snapshot.context.selection.focus\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectionStartPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n return snapshot.context.selection.backward\n ? snapshot.context.selection.focus\n : snapshot.context.selection.anchor\n}\n","import {\n isKeySegment,\n type KeyedSegment,\n type PortableTextObject,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isSpan} from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getFocusTextBlock} from './selectors'\n\n/**\n * @public\n */\nexport const getNextInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n const selectionEndPointChildKey =\n selectionEndPoint && isKeySegment(selectionEndPoint.path[2])\n ? selectionEndPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionEndPointChildKey) {\n return undefined\n }\n\n let endPointChildFound = false\n let inlineObject:\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionEndPointChildKey) {\n endPointChildFound = true\n continue\n }\n\n if (!isSpan(snapshot.context, child) && endPointChildFound) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n break\n }\n }\n\n return inlineObject\n}\n","import {\n isKeySegment,\n type KeyedSegment,\n type PortableTextObject,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isSpan} from '../utils'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {getFocusTextBlock} from './selectors'\n\n/**\n * @public\n */\nexport const getPreviousInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartPointChildKey =\n selectionStartPoint && isKeySegment(selectionStartPoint.path[2])\n ? selectionStartPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionStartPointChildKey) {\n return undefined\n }\n\n let inlineObject:\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionStartPointChildKey) {\n break\n }\n\n if (!isSpan(snapshot.context, child)) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n }\n }\n\n return inlineObject\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {sliceBlocks} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return sliceBlocks({\n blocks: snapshot.context.value,\n selection: snapshot.context.selection,\n })\n}\n","import {isPortableTextSpan, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSlice} from './selector.get-selected-slice'\n\n/**\n * @public\n */\nexport const getSelectionText: EditorSelector<string> = (snapshot) => {\n const selectedSlice = getSelectedSlice(snapshot)\n\n return selectedSlice.reduce((text, block) => {\n if (!isPortableTextTextBlock(block)) {\n return text\n }\n\n return (\n text +\n block.children.reduce((text, child) => {\n if (isPortableTextSpan(child)) {\n return text + child.text\n }\n\n return text\n }, '')\n )\n }, '')\n}\n","import type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n return (\n JSON.stringify(snapshot.context.selection.anchor.path) ===\n JSON.stringify(snapshot.context.selection.focus.path) &&\n snapshot.context.selection?.anchor.offset ===\n snapshot.context.selection?.focus.offset\n )\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const isSelectionExpanded: EditorSelector<boolean> = (snapshot) => {\n return !isSelectionCollapsed(snapshot)\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelection} from '../types/editor'\nimport {\n blockOffsetToSpanSelectionPoint,\n getBlockEndPoint,\n getBlockStartPoint,\n spanSelectionPointToBlockOffset,\n} from '../utils'\nimport {getNextInlineObject} from './selector.get-next-inline-object'\nimport {getPreviousInlineObject} from './selector.get-previous-inline-object'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {getSelectionText} from './selector.get-selection-text'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\nimport {getFocusTextBlock} from './selectors'\n\n/**\n * @public\n * Returns the selection of the of the word the caret is placed in.\n * Note: Only returns a word selection if the current selection is collapsed\n */\nexport const getCaretWordSelection: EditorSelector<EditorSelection> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return null\n }\n\n if (!isSelectionCollapsed(snapshot)) {\n return null\n }\n\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartOffset = selectionStartPoint\n ? spanSelectionPointToBlockOffset({\n value: snapshot.context.value,\n selectionPoint: selectionStartPoint,\n })\n : undefined\n\n if (!focusTextBlock || !selectionStartPoint || !selectionStartOffset) {\n return null\n }\n\n const previousInlineObject = getPreviousInlineObject(snapshot)\n const blockStartPoint = getBlockStartPoint(focusTextBlock)\n const textBefore = getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: previousInlineObject\n ? {path: previousInlineObject.path, offset: 0}\n : blockStartPoint,\n focus: selectionStartPoint,\n },\n },\n })\n const textDirectlyBefore = textBefore.split(/\\s+/).at(-1)\n\n const nextInlineObject = getNextInlineObject(snapshot)\n const blockEndPoint = getBlockEndPoint(focusTextBlock)\n const textAfter = getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: selectionStartPoint,\n focus: nextInlineObject\n ? {path: nextInlineObject.path, offset: 0}\n : blockEndPoint,\n },\n },\n })\n const textDirectlyAfter = textAfter.split(/\\s+/).at(0)\n\n if (\n (textDirectlyBefore === undefined || textDirectlyBefore === '') &&\n (textDirectlyAfter === undefined || textDirectlyAfter === '')\n ) {\n return null\n }\n\n const caretWordStartOffset: BlockOffset = textDirectlyBefore\n ? {\n ...selectionStartOffset,\n offset: selectionStartOffset.offset - textDirectlyBefore.length,\n }\n : selectionStartOffset\n const caretWordEndOffset: BlockOffset = textDirectlyAfter\n ? {\n ...selectionStartOffset,\n offset: selectionStartOffset.offset + textDirectlyAfter.length,\n }\n : selectionStartOffset\n\n const caretWordStartSelectionPoint = blockOffsetToSpanSelectionPoint({\n value: snapshot.context.value,\n blockOffset: caretWordStartOffset,\n direction: 'backward',\n })\n const caretWordEndSelectionPoint = blockOffsetToSpanSelectionPoint({\n value: snapshot.context.value,\n blockOffset: caretWordEndOffset,\n direction: 'forward',\n })\n\n if (!caretWordStartSelectionPoint || !caretWordEndSelectionPoint) {\n return null\n }\n\n const caretWordSelection = {\n anchor: caretWordStartSelectionPoint,\n focus: caretWordEndSelectionPoint,\n }\n\n return isSelectionExpanded({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: caretWordSelection,\n },\n })\n ? caretWordSelection\n : null\n}\n","import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isAtTheEndOfBlock(block: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection || !isSelectionCollapsed(snapshot)) {\n return false\n }\n\n const blockEndPoint = utils.getBlockEndPoint(block)\n\n return utils.isEqualSelectionPoints(\n snapshot.context.selection.focus,\n blockEndPoint,\n )\n }\n}\n","import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isAtTheStartOfBlock(block: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection || !isSelectionCollapsed(snapshot)) {\n return false\n }\n\n const blockStartPoint = utils.getBlockStartPoint(block)\n\n return utils.isEqualSelectionPoints(\n snapshot.context.selection.focus,\n blockStartPoint,\n )\n }\n}\n"],"names":["createGuards","schema","isListBlock","block","isPortableTextListBlock","_type","name","isTextBlock","isPortableTextTextBlock","getFocusBlock","snapshot","key","context","selection","isKeySegment","focus","path","_key","undefined","node","value","find","getFocusListBlock","guards","focusBlock","getFocusTextBlock","getFocusBlockObject","getFocusChild","children","span","getFocusSpan","focusChild","isPortableTextSpan","getFirstBlock","getLastBlock","length","getSelectedBlocks","selectedBlocks","startKey","backward","anchor","endKey","push","getSelectionStartBlock","getSelectionEndBlock","getPreviousBlock","previousBlock","selectionStartBlock","foundSelectionStartBlock","getNextBlock","nextBlock","selectionEndBlock","foundSelectionEndBlock","getSelectionEndPoint","getSelectionStartPoint","getNextInlineObject","focusTextBlock","selectionEndPoint","selectionEndPointChildKey","endPointChildFound","inlineObject","child","isSpan","getPreviousInlineObject","selectionStartPoint","selectionStartPointChildKey","getSelectedSlice","sliceBlocks","blocks","getSelectionText","reduce","text","isSelectionCollapsed","JSON","stringify","offset","isSelectionExpanded","getCaretWordSelection","selectionStartOffset","spanSelectionPointToBlockOffset","selectionPoint","previousInlineObject","blockStartPoint","getBlockStartPoint","textDirectlyBefore","split","at","nextInlineObject","blockEndPoint","getBlockEndPoint","textDirectlyAfter","caretWordStartOffset","caretWordEndOffset","caretWordStartSelectionPoint","blockOffsetToSpanSelectionPoint","blockOffset","direction","caretWordEndSelectionPoint","caretWordSelection","isAtTheEndOfBlock","utils","isAtTheStartOfBlock"],"mappings":";;AAaO,SAASA,aAAa;AAAA,EAACC;AAA8B,GAAG;AAC7D,WAASC,YAAYC,OAAgD;AACnE,WAAOC,MAAAA,wBAAwBD,KAAK,KAAKA,MAAME,UAAUJ,OAAOE,MAAMG;AAAAA,EAAAA;AAGxE,WAASC,YAAYJ,OAAgD;AACnE,WAAOK,MAAAA,wBAAwBL,KAAK,KAAKA,MAAME,UAAUJ,OAAOE,MAAMG;AAAAA,EAAAA;AAGjE,SAAA;AAAA,IAACJ;AAAAA,IAAaK;AAAAA,EAAW;AAClC;ACNO,MAAME,gBAERC,CAAa,aAAA;AAChB,QAAMC,MAAMD,SAASE,QAAQC,aACzBC,MAAAA,aAAaJ,SAASE,QAAQC,UAAUE,MAAMC,KAAK,CAAC,CAAC,IACnDN,SAASE,QAAQC,UAAUE,MAAMC,KAAK,CAAC,EAAEC,OAE3CC,QAEEC,OAAOR,MACTD,SAASE,QAAQQ,MAAMC,KAAMlB,CAAAA,UAAUA,MAAMc,SAASN,GAAG,IACzDO;AAEJ,SAAOC,QAAQR,MAAM;AAAA,IAACQ;AAAAA,IAAMH,MAAM,CAAC;AAAA,MAACC,MAAMN;AAAAA,IAAI,CAAA;AAAA,EAAA,IAAKO;AACrD,GAKaI,oBAERZ,CAAa,aAAA;AAChB,QAAMa,SAASvB,aAAaU,SAASE,OAAO,GACtCY,aAAaf,cAAcC,QAAQ;AAEzC,SAA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I,CAACA,SAASE,QAAQC,aAAa,CAAC2D,qBAAqB9D,QAAQ;AACxD,aAAA;AAGHwE,UAAAA,kBAAkBkB,iBAAMjB,mBAAmBhF,KAAK;AAEtD,WAAOiG,iBAAAA,uBACL1F,SAASE,QAAQC,UAAUE,OAC3BmE,eACF;AAAA,EACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.block-offsets-to-selection.cjs","sources":["../../src/internal-utils/asserters.ts","../../src/internal-utils/parse-blocks.ts","../../src/utils/util.block-offsets-to-selection.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 PortableTextObject,\n PortableTextSpan,\n PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSchema} from '../editor/define-schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isTypedObject} from './asserters'\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 if (\n blockObject._type === context.schema.block.name ||\n blockObject._type === 'block' ||\n !context.schema.blockObjects.some(({name}) => name === blockObject._type)\n ) {\n return undefined\n }\n\n return {\n ...blockObject,\n _key: options.refreshKeys\n ? context.keyGenerator()\n : typeof blockObject._key === 'string'\n ? blockObject._key\n : context.keyGenerator(),\n }\n}\n\nexport function isTextBlock(\n schema: EditorSchema,\n block: unknown,\n): block is PortableTextTextBlock {\n return (\n parseTextBlock({\n block,\n 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 if (typeof markDef._key !== 'string') {\n return []\n }\n\n if (\n context.schema.annotations.some(\n (annotation) => annotation.name === markDef._type,\n )\n ) {\n const _key = options.refreshKeys ? context.keyGenerator() : markDef._key\n markDefKeyMap.set(markDef._key, _key)\n\n return [\n {\n ...markDef,\n _key,\n },\n ]\n }\n\n return []\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 // Spread the entire block to allow custom properties on it\n ...block,\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 /**\n * Reset text block .style if it's somehow set to an invalid type\n */\n if (\n typeof parsedBlock.style !== 'string' ||\n !context.schema.styles.find((style) => style.value === block.style)\n ) {\n const defaultStyle = context.schema.styles.at(0)?.value\n\n if (defaultStyle !== undefined) {\n parsedBlock.style = defaultStyle\n } else {\n delete parsedBlock.style\n }\n }\n\n /**\n * Reset text block .listItem if it's somehow set to an invalid type\n */\n if (\n typeof parsedBlock.listItem !== 'string' ||\n !context.schema.lists.find((list) => list.value === block.listItem)\n ) {\n delete parsedBlock.listItem\n }\n\n /**\n * Reset text block .level if it's somehow set to an invalid type\n */\n if (typeof parsedBlock.level !== 'number') {\n delete parsedBlock.level\n }\n\n return parsedBlock\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.value === mark)\n ) {\n return [mark]\n }\n\n return []\n })\n\n return {\n // Spread the entire span to allow custom properties on it\n ...span,\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\nfunction 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 if (\n inlineObject._type === context.schema.span.name ||\n inlineObject._type === 'span' ||\n // Respect the schema definition and don't parse inline objects that are not defined\n !context.schema.inlineObjects.some(({name}) => name === inlineObject._type)\n ) {\n return undefined\n }\n\n return {\n // Spread the entire inline object to allow custom properties on it\n ...inlineObject,\n _key: options.refreshKeys\n ? context.keyGenerator()\n : typeof inlineObject._key === 'string'\n ? inlineObject._key\n : context.keyGenerator(),\n }\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {BlockOffset} from '../behaviors'\nimport type {EditorSelection} from '../selectors'\nimport {blockOffsetToSpanSelectionPoint} from './util.block-offset'\n\n/**\n * @public\n */\nexport function blockOffsetsToSelection({\n value,\n offsets,\n backward,\n}: {\n value: Array<PortableTextBlock>\n offsets: {anchor: BlockOffset; focus: BlockOffset}\n backward?: boolean\n}): EditorSelection {\n const anchor = blockOffsetToSpanSelectionPoint({\n value,\n blockOffset: offsets.anchor,\n direction: backward ? 'backward' : 'forward',\n })\n const focus = blockOffsetToSpanSelectionPoint({\n value,\n blockOffset: offsets.focus,\n direction: backward ? 'forward' : 'backward',\n })\n\n if (!anchor || !focus) {\n return null\n }\n\n return {\n anchor,\n focus,\n backward,\n }\n}\n"],"names":["isTypedObject","object","isRecord","_type","value","parseBlock","context","block","options","parseTextBlock","parseBlockObject","blockObject","schema","name","blockObjects","some","_key","refreshKeys","keyGenerator","isTextBlock","undefined","unparsedMarkDefs","Array","isArray","markDefs","markDefKeyMap","Map","flatMap","markDef","annotations","annotation","set","children","map","child","parseSpan","span","parseInlineObject","inlineObject","filter","parsedBlock","length","text","marks","style","styles","find","defaultStyle","at","listItem","lists","list","level","mark","markDefKey","get","decorators","decorator","inlineObjects","blockOffsetsToSelection","offsets","backward","anchor","blockOffsetToSpanSelectionPoint","blockOffset","direction","focus"],"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;A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AAA,cAAcsC,YAAY,KAK7BA,EAAanC,aAAAA,UAAUG,QAAQM,OAAOwB,KAAKvB,QAC3CyB,aAAanC,UAAU;AAAA,EAEvB,CAACG,QAAQM,OAAO8C,cAAc3C,KAAK,CAAC;AAAA,IAACF;AAAAA,EAAAA,MAAUA,SAASyB,aAAanC,KAAK;AAKrE,WAAA;AAAA;AAAA,MAEL,GAAGmC;AAAAA,MACHtB,MAAMR,QAAQS,cACVX,QAAQY,aAAa,IACrB,OAAOoB,aAAatB,QAAS,WAC3BsB,aAAatB,OACbV,QAAQY,aAAa;AAAA,IAC7B;AACF;AChRO,SAASyC,wBAAwB;AAAA,EACtCvD;AAAAA,EACAwD;AAAAA,EACAC;AAKF,GAAoB;AAClB,QAAMC,SAASC,iBAAAA,gCAAgC;AAAA,IAC7C3D;AAAAA,IACA4D,aAAaJ,QAAQE;AAAAA,IACrBG,WAAWJ,WAAW,aAAa;AAAA,EAAA,CACpC,GACKK,QAAQH,iDAAgC;AAAA,IAC5C3D;AAAAA,IACA4D,aAAaJ,QAAQM;AAAAA,IACrBD,WAAWJ,WAAW,YAAY;AAAA,EAAA,CACnC;AAED,SAAI,CAACC,UAAU,CAACI,QACP,OAGF;AAAA,IACLJ;AAAAA,IACAI;AAAAA,IACAL;AAAAA,EACF;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"util.block-offsets-to-selection.cjs","sources":["../../src/internal-utils/asserters.ts","../../src/internal-utils/parse-blocks.ts","../../src/utils/util.block-offsets-to-selection.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 PortableTextObject,\n PortableTextSpan,\n PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSchema} from '../editor/define-schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isTypedObject} from './asserters'\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 if (\n blockObject._type === context.schema.block.name ||\n blockObject._type === 'block' ||\n !context.schema.blockObjects.some(({name}) => name === blockObject._type)\n ) {\n return undefined\n }\n\n return {\n ...blockObject,\n _key: options.refreshKeys\n ? context.keyGenerator()\n : typeof blockObject._key === 'string'\n ? blockObject._key\n : context.keyGenerator(),\n }\n}\n\nexport function isTextBlock(\n schema: EditorSchema,\n block: unknown,\n): block is PortableTextTextBlock {\n return (\n parseTextBlock({\n block,\n 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 if (typeof markDef._key !== 'string') {\n return []\n }\n\n if (\n context.schema.annotations.some(\n (annotation) => annotation.name === markDef._type,\n )\n ) {\n const _key = options.refreshKeys ? context.keyGenerator() : markDef._key\n markDefKeyMap.set(markDef._key, _key)\n\n return [\n {\n ...markDef,\n _key,\n },\n ]\n }\n\n return []\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 // Spread the entire block to allow custom properties on it\n ...block,\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 /**\n * Reset text block .style if it's somehow set to an invalid type\n */\n if (\n typeof parsedBlock.style !== 'string' ||\n !context.schema.styles.find((style) => style.value === block.style)\n ) {\n const defaultStyle = context.schema.styles.at(0)?.value\n\n if (defaultStyle !== undefined) {\n parsedBlock.style = defaultStyle\n } else {\n delete parsedBlock.style\n }\n }\n\n /**\n * Reset text block .listItem if it's somehow set to an invalid type\n */\n if (\n typeof parsedBlock.listItem !== 'string' ||\n !context.schema.lists.find((list) => list.value === block.listItem)\n ) {\n delete parsedBlock.listItem\n }\n\n /**\n * Reset text block .level if it's somehow set to an invalid type\n */\n if (typeof parsedBlock.level !== 'number') {\n delete parsedBlock.level\n }\n\n return parsedBlock\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.value === mark)\n ) {\n return [mark]\n }\n\n return []\n })\n\n return {\n // Spread the entire span to allow custom properties on it\n ...span,\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\nfunction 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 if (\n inlineObject._type === context.schema.span.name ||\n inlineObject._type === 'span' ||\n // Respect the schema definition and don't parse inline objects that are not defined\n !context.schema.inlineObjects.some(({name}) => name === inlineObject._type)\n ) {\n return undefined\n }\n\n return {\n // Spread the entire inline object to allow custom properties on it\n ...inlineObject,\n _key: options.refreshKeys\n ? context.keyGenerator()\n : typeof inlineObject._key === 'string'\n ? inlineObject._key\n : context.keyGenerator(),\n }\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelection} from '../selectors'\nimport type {BlockOffset} from '../types/block-offset'\nimport {blockOffsetToSpanSelectionPoint} from './util.block-offset'\n\n/**\n * @public\n */\nexport function blockOffsetsToSelection({\n value,\n offsets,\n backward,\n}: {\n value: Array<PortableTextBlock>\n offsets: {anchor: BlockOffset; focus: BlockOffset}\n backward?: boolean\n}): EditorSelection {\n const anchor = blockOffsetToSpanSelectionPoint({\n value,\n blockOffset: offsets.anchor,\n direction: backward ? 'backward' : 'forward',\n })\n const focus = blockOffsetToSpanSelectionPoint({\n value,\n blockOffset: offsets.focus,\n direction: backward ? 'forward' : 'backward',\n })\n\n if (!anchor || !focus) {\n return null\n }\n\n return {\n anchor,\n focus,\n backward,\n }\n}\n"],"names":["isTypedObject","object","isRecord","_type","value","parseBlock","context","block","options","parseTextBlock","parseBlockObject","blockObject","schema","name","blockObjects","some","_key","refreshKeys","keyGenerator","isTextBlock","undefined","unparsedMarkDefs","Array","isArray","markDefs","markDefKeyMap","Map","flatMap","markDef","annotations","annotation","set","children","map","child","parseSpan","span","parseInlineObject","inlineObject","filter","parsedBlock","length","text","marks","style","styles","find","defaultStyle","at","listItem","lists","list","level","mark","markDefKey","get","decorators","decorator","inlineObjects","blockOffsetsToSelection","offsets","backward","anchor","blockOffsetToSpanSelectionPoint","blockOffset","direction","focus"],"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;ACEO,SAASC,WAAW;AAAA,EACzBC;AAAAA,EACAC;AAAAA,EACAC;AAOF,GAAkC;AAChC,SACEC,eAAe;AAAA,IAACF;AAAAA,IAAOD;AAAAA,IAASE;AAAAA,EAAQ,CAAA,KACxCE,iBAAiB;AAAA,IAACC,aAAaJ;AAAAA,IAAOD;AAAAA,IAASE;AAAAA,EAAAA,CAAQ;AAE3D;AAEA,SAASE,iBAAiB;AAAA,EACxBC;AAAAA,EACAL;AAAAA,EACAE;AAKF,GAAmC;AACjC,MAAKR,cAAcW,WAAW,KAK5BA,EAAYR,YAAAA,UAAUG,QAAQM,OAAOL,MAAMM,QAC3CF,YAAYR,UAAU,WACtB,CAACG,QAAQM,OAAOE,aAAaC,KAAK,CAAC;AAAA,IAACF;AAAAA,EAAAA,MAAUA,SAASF,YAAYR,KAAK;AAKnE,WAAA;AAAA,MACL,GAAGQ;AAAAA,MACHK,MAAMR,QAAQS,cACVX,QAAQY,aAAa,IACrB,OAAOP,YAAYK,QAAS,WAC1BL,YAAYK,OACZV,QAAQY,aAAa;AAAA,IAC7B;AACF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