@portabletext/editor 1.24.0 → 1.26.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.
Files changed (89) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +283 -64
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.get-text-before.cjs +8 -8
  4. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  5. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +412 -0
  6. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -0
  7. package/lib/_chunks-cjs/util.is-empty-text-block.cjs +2 -2
  8. package/lib/_chunks-cjs/util.is-empty-text-block.cjs.map +1 -1
  9. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs +46 -0
  10. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +1 -0
  11. package/lib/_chunks-cjs/util.reverse-selection.cjs +0 -16
  12. package/lib/_chunks-cjs/util.reverse-selection.cjs.map +1 -1
  13. package/lib/_chunks-es/behavior.core.js +259 -40
  14. package/lib/_chunks-es/behavior.core.js.map +1 -1
  15. package/lib/_chunks-es/selector.get-text-before.js +2 -2
  16. package/lib/_chunks-es/selector.is-at-the-start-of-block.js +414 -0
  17. package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -0
  18. package/lib/_chunks-es/util.is-empty-text-block.js +1 -1
  19. package/lib/_chunks-es/util.is-equal-selection-points.js +47 -0
  20. package/lib/_chunks-es/util.is-equal-selection-points.js.map +1 -0
  21. package/lib/_chunks-es/util.reverse-selection.js +0 -16
  22. package/lib/_chunks-es/util.reverse-selection.js.map +1 -1
  23. package/lib/behaviors/index.cjs +27 -27
  24. package/lib/behaviors/index.cjs.map +1 -1
  25. package/lib/behaviors/index.d.cts +2208 -171
  26. package/lib/behaviors/index.d.ts +2208 -171
  27. package/lib/behaviors/index.js +1 -1
  28. package/lib/index.cjs +306 -298
  29. package/lib/index.cjs.map +1 -1
  30. package/lib/index.d.cts +10499 -521
  31. package/lib/index.d.ts +10499 -521
  32. package/lib/index.js +302 -294
  33. package/lib/index.js.map +1 -1
  34. package/lib/selectors/index.cjs +26 -171
  35. package/lib/selectors/index.cjs.map +1 -1
  36. package/lib/selectors/index.d.cts +16 -0
  37. package/lib/selectors/index.d.ts +16 -0
  38. package/lib/selectors/index.js +5 -151
  39. package/lib/selectors/index.js.map +1 -1
  40. package/lib/utils/index.cjs +5 -3
  41. package/lib/utils/index.cjs.map +1 -1
  42. package/lib/utils/index.d.cts +19 -0
  43. package/lib/utils/index.d.ts +19 -0
  44. package/lib/utils/index.js +4 -2
  45. package/package.json +6 -6
  46. package/src/behavior-actions/behavior.action-utils.insert-block.ts +3 -3
  47. package/src/behavior-actions/behavior.action.block.set.ts +23 -0
  48. package/src/behavior-actions/behavior.action.block.unset.ts +21 -0
  49. package/src/behavior-actions/behavior.action.insert-break.ts +2 -69
  50. package/src/behavior-actions/behavior.action.insert.block.ts +29 -0
  51. package/src/behavior-actions/behavior.actions.ts +116 -96
  52. package/src/behaviors/behavior.core.annotations.ts +29 -0
  53. package/src/behaviors/behavior.core.block-objects.ts +13 -13
  54. package/src/behaviors/behavior.core.decorators.ts +19 -0
  55. package/src/behaviors/behavior.core.insert-break.ts +122 -0
  56. package/src/behaviors/behavior.core.lists.ts +57 -23
  57. package/src/behaviors/behavior.core.style.ts +19 -0
  58. package/src/behaviors/behavior.core.ts +18 -2
  59. package/src/behaviors/behavior.types.ts +103 -88
  60. package/src/converters/converter.json.ts +4 -4
  61. package/src/converters/converter.portable-text.deserialize.test.ts +1 -1
  62. package/src/converters/converter.portable-text.ts +4 -4
  63. package/src/converters/converter.text-html.deserialize.test.ts +1 -1
  64. package/src/converters/converter.text-html.serialize.test.ts +1 -1
  65. package/src/converters/converter.text-html.ts +4 -4
  66. package/src/converters/converter.text-plain.test.ts +1 -1
  67. package/src/converters/converter.text-plain.ts +3 -3
  68. package/src/converters/{converter.ts → converter.types.ts} +6 -0
  69. package/src/editor/create-editor.ts +50 -7
  70. package/src/editor/editor-machine.ts +46 -3
  71. package/src/editor/editor-snapshot.ts +1 -1
  72. package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +2 -2
  73. package/src/editor/plugins/create-with-event-listeners.ts +41 -106
  74. package/src/selectors/index.ts +2 -0
  75. package/src/selectors/selector.is-at-the-end-of-block.ts +22 -0
  76. package/src/selectors/selector.is-at-the-start-of-block.ts +25 -0
  77. package/src/selectors/selector.is-selection-collapsed.ts +6 -2
  78. package/src/utils/index.ts +2 -0
  79. package/src/utils/util.get-block-end-point.ts +34 -0
  80. package/src/utils/util.is-equal-selection-points.ts +13 -0
  81. package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs +0 -231
  82. package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs.map +0 -1
  83. package/lib/_chunks-cjs/util.is-keyed-segment.cjs +0 -6
  84. package/lib/_chunks-cjs/util.is-keyed-segment.cjs.map +0 -1
  85. package/lib/_chunks-es/selector.is-selection-collapsed.js +0 -232
  86. package/lib/_chunks-es/selector.is-selection-collapsed.js.map +0 -1
  87. package/lib/_chunks-es/util.is-keyed-segment.js +0 -7
  88. package/lib/_chunks-es/util.is-keyed-segment.js.map +0 -1
  89. /package/src/converters/{converters.ts → converters.core.ts} +0 -0
@@ -0,0 +1,412 @@
1
+ "use strict";
2
+ var types = require("@sanity/types"), util_isEqualSelectionPoints = require("./util.is-equal-selection-points.cjs");
3
+ function createGuards({
4
+ schema
5
+ }) {
6
+ function isListBlock(block) {
7
+ return types.isPortableTextListBlock(block) && block._type === schema.block.name;
8
+ }
9
+ function isTextBlock(block) {
10
+ return types.isPortableTextTextBlock(block) && block._type === schema.block.name;
11
+ }
12
+ return {
13
+ isListBlock,
14
+ isTextBlock
15
+ };
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;
21
+ return node && key ? {
22
+ node,
23
+ path: [{
24
+ _key: key
25
+ }]
26
+ } : void 0;
27
+ }, getFocusListBlock = ({
28
+ context
29
+ }) => {
30
+ const guards = createGuards(context), focusBlock = getFocusBlock({
31
+ context
32
+ });
33
+ return focusBlock && guards.isListBlock(focusBlock.node) ? {
34
+ node: focusBlock.node,
35
+ path: focusBlock.path
36
+ } : void 0;
37
+ }, getFocusTextBlock = ({
38
+ context
39
+ }) => {
40
+ const focusBlock = getFocusBlock({
41
+ context
42
+ });
43
+ return focusBlock && types.isPortableTextTextBlock(focusBlock.node) ? {
44
+ node: focusBlock.node,
45
+ path: focusBlock.path
46
+ } : void 0;
47
+ }, getFocusBlockObject = ({
48
+ context
49
+ }) => {
50
+ const focusBlock = getFocusBlock({
51
+ context
52
+ });
53
+ return focusBlock && !types.isPortableTextTextBlock(focusBlock.node) ? {
54
+ node: focusBlock.node,
55
+ path: focusBlock.path
56
+ } : void 0;
57
+ }, getFocusChild = ({
58
+ context
59
+ }) => {
60
+ const focusBlock = getFocusTextBlock({
61
+ context
62
+ });
63
+ if (!focusBlock)
64
+ 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;
66
+ return node && key ? {
67
+ node,
68
+ path: [...focusBlock.path, "children", {
69
+ _key: key
70
+ }]
71
+ } : void 0;
72
+ }, getFocusSpan = ({
73
+ context
74
+ }) => {
75
+ const focusChild = getFocusChild({
76
+ context
77
+ });
78
+ return focusChild && types.isPortableTextSpan(focusChild.node) ? {
79
+ node: focusChild.node,
80
+ path: focusChild.path
81
+ } : void 0;
82
+ }, getFirstBlock = ({
83
+ context
84
+ }) => {
85
+ const node = context.value[0];
86
+ return node ? {
87
+ node,
88
+ path: [{
89
+ _key: node._key
90
+ }]
91
+ } : void 0;
92
+ }, getLastBlock = ({
93
+ context
94
+ }) => {
95
+ const node = context.value[context.value.length - 1] ? context.value[context.value.length - 1] : void 0;
96
+ return node ? {
97
+ node,
98
+ path: [{
99
+ _key: node._key
100
+ }]
101
+ } : void 0;
102
+ }, getSelectedBlocks = ({
103
+ context
104
+ }) => {
105
+ if (!context.selection)
106
+ 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;
108
+ if (!startKey || !endKey)
109
+ return selectedBlocks;
110
+ for (const block of context.value) {
111
+ if (block._key === startKey) {
112
+ if (selectedBlocks.push({
113
+ node: block,
114
+ path: [{
115
+ _key: block._key
116
+ }]
117
+ }), startKey === endKey)
118
+ break;
119
+ continue;
120
+ }
121
+ if (block._key === endKey) {
122
+ selectedBlocks.push({
123
+ node: block,
124
+ path: [{
125
+ _key: block._key
126
+ }]
127
+ });
128
+ break;
129
+ }
130
+ selectedBlocks.length > 0 && selectedBlocks.push({
131
+ node: block,
132
+ path: [{
133
+ _key: block._key
134
+ }]
135
+ });
136
+ }
137
+ return selectedBlocks;
138
+ }, getSelectionStartBlock = ({
139
+ context
140
+ }) => {
141
+ if (!context.selection)
142
+ 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;
144
+ return node && key ? {
145
+ node,
146
+ path: [{
147
+ _key: key
148
+ }]
149
+ } : void 0;
150
+ }, getSelectionEndBlock = ({
151
+ context
152
+ }) => {
153
+ if (!context.selection)
154
+ 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;
156
+ return node && key ? {
157
+ node,
158
+ path: [{
159
+ _key: key
160
+ }]
161
+ } : void 0;
162
+ }, getPreviousBlock = ({
163
+ context
164
+ }) => {
165
+ let previousBlock;
166
+ const selectionStartBlock = getSelectionStartBlock({
167
+ context
168
+ });
169
+ if (!selectionStartBlock)
170
+ return;
171
+ let foundSelectionStartBlock = !1;
172
+ for (const block of context.value) {
173
+ if (block._key === selectionStartBlock.node._key) {
174
+ foundSelectionStartBlock = !0;
175
+ break;
176
+ }
177
+ previousBlock = {
178
+ node: block,
179
+ path: [{
180
+ _key: block._key
181
+ }]
182
+ };
183
+ }
184
+ if (foundSelectionStartBlock && previousBlock)
185
+ return previousBlock;
186
+ }, getNextBlock = ({
187
+ context
188
+ }) => {
189
+ let nextBlock;
190
+ const selectionEndBlock = getSelectionEndBlock({
191
+ context
192
+ });
193
+ if (!selectionEndBlock)
194
+ return;
195
+ let foundSelectionEndBlock = !1;
196
+ for (const block of context.value) {
197
+ if (block._key === selectionEndBlock.node._key) {
198
+ foundSelectionEndBlock = !0;
199
+ continue;
200
+ }
201
+ if (foundSelectionEndBlock) {
202
+ nextBlock = {
203
+ node: block,
204
+ path: [{
205
+ _key: block._key
206
+ }]
207
+ };
208
+ break;
209
+ }
210
+ }
211
+ if (foundSelectionEndBlock && nextBlock)
212
+ return nextBlock;
213
+ }, getActiveListItem = ({
214
+ context
215
+ }) => {
216
+ if (!context.selection)
217
+ return;
218
+ const guards = createGuards(context), selectedTextBlocks = getSelectedBlocks({
219
+ context
220
+ }).map((block) => block.node).filter(guards.isTextBlock), firstTextBlock = selectedTextBlocks.at(0);
221
+ if (!firstTextBlock)
222
+ return;
223
+ const firstListItem = firstTextBlock.listItem;
224
+ if (firstListItem && selectedTextBlocks.every((block) => block.listItem === firstListItem))
225
+ return firstListItem;
226
+ }, getActiveStyle = ({
227
+ context
228
+ }) => {
229
+ if (!context.selection)
230
+ return;
231
+ const guards = createGuards(context), selectedTextBlocks = getSelectedBlocks({
232
+ context
233
+ }).map((block) => block.node).filter(guards.isTextBlock), firstTextBlock = selectedTextBlocks.at(0);
234
+ if (!firstTextBlock)
235
+ return;
236
+ const firstStyle = firstTextBlock.style;
237
+ if (firstStyle && selectedTextBlocks.every((block) => block.style === firstStyle))
238
+ return firstStyle;
239
+ }, getSelectedSpans = ({
240
+ context
241
+ }) => {
242
+ if (!context.selection)
243
+ return [];
244
+ const selectedSpans = [], startPoint = context.selection.backward ? context.selection.focus : context.selection.anchor, endPoint = context.selection.backward ? context.selection.anchor : context.selection.focus, startBlockKey = types.isKeySegment(startPoint.path[0]) ? startPoint.path[0]._key : void 0, endBlockKey = types.isKeySegment(endPoint.path[0]) ? endPoint.path[0]._key : void 0;
245
+ if (!startBlockKey || !endBlockKey)
246
+ return selectedSpans;
247
+ const startSpanKey = types.isKeySegment(startPoint.path[2]) ? startPoint.path[2]._key : void 0, endSpanKey = types.isKeySegment(endPoint.path[2]) ? endPoint.path[2]._key : void 0;
248
+ for (const block of context.value)
249
+ if (types.isPortableTextTextBlock(block)) {
250
+ if (block._key === startBlockKey) {
251
+ for (const child of block.children)
252
+ if (types.isPortableTextSpan(child)) {
253
+ if (startSpanKey && child._key === startSpanKey) {
254
+ if (selectedSpans.push({
255
+ node: child,
256
+ path: [{
257
+ _key: block._key
258
+ }, "children", {
259
+ _key: child._key
260
+ }]
261
+ }), startSpanKey === endSpanKey)
262
+ break;
263
+ continue;
264
+ }
265
+ if (endSpanKey && child._key === endSpanKey) {
266
+ selectedSpans.push({
267
+ node: child,
268
+ path: [{
269
+ _key: block._key
270
+ }, "children", {
271
+ _key: child._key
272
+ }]
273
+ });
274
+ break;
275
+ }
276
+ selectedSpans.length > 0 && selectedSpans.push({
277
+ node: child,
278
+ path: [{
279
+ _key: block._key
280
+ }, "children", {
281
+ _key: child._key
282
+ }]
283
+ });
284
+ }
285
+ if (startBlockKey === endBlockKey)
286
+ break;
287
+ continue;
288
+ }
289
+ if (block._key === endBlockKey) {
290
+ for (const child of block.children)
291
+ if (types.isPortableTextSpan(child)) {
292
+ if (endSpanKey && child._key === endSpanKey) {
293
+ selectedSpans.push({
294
+ node: child,
295
+ path: [{
296
+ _key: block._key
297
+ }, "children", {
298
+ _key: child._key
299
+ }]
300
+ });
301
+ break;
302
+ }
303
+ selectedSpans.push({
304
+ node: child,
305
+ path: [{
306
+ _key: block._key
307
+ }, "children", {
308
+ _key: child._key
309
+ }]
310
+ });
311
+ }
312
+ break;
313
+ }
314
+ if (selectedSpans.length > 0)
315
+ for (const child of block.children)
316
+ types.isPortableTextSpan(child) && selectedSpans.push({
317
+ node: child,
318
+ path: [{
319
+ _key: block._key
320
+ }, "children", {
321
+ _key: child._key
322
+ }]
323
+ });
324
+ }
325
+ return selectedSpans;
326
+ };
327
+ function isActiveAnnotation(annotation) {
328
+ return (snapshot) => {
329
+ if (!snapshot.context.selection)
330
+ return !1;
331
+ const selectedBlocks = getSelectedBlocks(snapshot), selectedSpans = getSelectedSpans(snapshot);
332
+ if (selectedSpans.length === 0 || selectedSpans.some((span) => !span.node.marks || span.node.marks?.length === 0))
333
+ return !1;
334
+ const selectionMarkDefs = selectedBlocks.flatMap((block) => types.isPortableTextTextBlock(block.node) ? block.node.markDefs ?? [] : []);
335
+ return selectedSpans.every((span) => (span.node.marks?.flatMap((mark) => {
336
+ const markDef = selectionMarkDefs.find((markDef2) => markDef2._key === mark);
337
+ return markDef ? [markDef._type] : [];
338
+ }) ?? []).includes(annotation));
339
+ };
340
+ }
341
+ const isSelectionCollapsed = ({
342
+ context
343
+ }) => context.selection ? JSON.stringify(context.selection.anchor.path) === JSON.stringify(context.selection.focus.path) && context.selection?.anchor.offset === context.selection?.focus.offset : !1, isSelectionExpanded = ({
344
+ context
345
+ }) => !isSelectionCollapsed({
346
+ context
347
+ });
348
+ function isActiveDecorator(decorator) {
349
+ return (snapshot) => {
350
+ if (isSelectionExpanded(snapshot)) {
351
+ const selectedSpans = getSelectedSpans(snapshot);
352
+ return selectedSpans.length > 0 && selectedSpans.every((span) => span.node.marks?.includes(decorator));
353
+ }
354
+ return snapshot.context.activeDecorators.includes(decorator);
355
+ };
356
+ }
357
+ function isActiveListItem(listItem) {
358
+ return (snapshot) => getActiveListItem(snapshot) === listItem;
359
+ }
360
+ function isActiveStyle(style) {
361
+ return (snapshot) => getActiveStyle(snapshot) === style;
362
+ }
363
+ function isAtTheEndOfBlock(block) {
364
+ return ({
365
+ context
366
+ }) => {
367
+ if (!context.selection || !isSelectionCollapsed({
368
+ context
369
+ }))
370
+ return !1;
371
+ const blockEndPoint = util_isEqualSelectionPoints.getBlockEndPoint(block);
372
+ return util_isEqualSelectionPoints.isEqualSelectionPoints(context.selection.focus, blockEndPoint);
373
+ };
374
+ }
375
+ function isAtTheStartOfBlock(block) {
376
+ return ({
377
+ context
378
+ }) => {
379
+ if (!context.selection || !isSelectionCollapsed({
380
+ context
381
+ }))
382
+ return !1;
383
+ const blockStartPoint = util_isEqualSelectionPoints.getBlockStartPoint(block);
384
+ return util_isEqualSelectionPoints.isEqualSelectionPoints(context.selection.focus, blockStartPoint);
385
+ };
386
+ }
387
+ exports.createGuards = createGuards;
388
+ exports.getActiveListItem = getActiveListItem;
389
+ exports.getActiveStyle = getActiveStyle;
390
+ exports.getFirstBlock = getFirstBlock;
391
+ exports.getFocusBlock = getFocusBlock;
392
+ exports.getFocusBlockObject = getFocusBlockObject;
393
+ exports.getFocusChild = getFocusChild;
394
+ exports.getFocusListBlock = getFocusListBlock;
395
+ exports.getFocusSpan = getFocusSpan;
396
+ exports.getFocusTextBlock = getFocusTextBlock;
397
+ exports.getLastBlock = getLastBlock;
398
+ exports.getNextBlock = getNextBlock;
399
+ exports.getPreviousBlock = getPreviousBlock;
400
+ exports.getSelectedBlocks = getSelectedBlocks;
401
+ exports.getSelectedSpans = getSelectedSpans;
402
+ exports.getSelectionEndBlock = getSelectionEndBlock;
403
+ exports.getSelectionStartBlock = getSelectionStartBlock;
404
+ exports.isActiveAnnotation = isActiveAnnotation;
405
+ exports.isActiveDecorator = isActiveDecorator;
406
+ exports.isActiveListItem = isActiveListItem;
407
+ exports.isActiveStyle = isActiveStyle;
408
+ exports.isAtTheEndOfBlock = isAtTheEndOfBlock;
409
+ exports.isAtTheStartOfBlock = isAtTheStartOfBlock;
410
+ exports.isSelectionCollapsed = isSelectionCollapsed;
411
+ exports.isSelectionExpanded = isSelectionExpanded;
412
+ //# sourceMappingURL=selector.is-at-the-start-of-block.cjs.map
@@ -0,0 +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-active-list-item.ts","../../src/selectors/selector.get-active-style.ts","../../src/selectors/selector.get-selected-spans.ts","../../src/selectors/selector.is-active-annotation.ts","../../src/selectors/selector.is-selection-collapsed.ts","../../src/selectors/selector.is-selection-expanded.ts","../../src/selectors/selector.is-active-decorator.ts","../../src/selectors/selector.is-active-list-item.ts","../../src/selectors/selector.is-active-style.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 {PortableTextListBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveListItem: EditorSelector<\n PortableTextListBlock['listItem'] | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const guards = createGuards(context)\n const selectedBlocks = getSelectedBlocks({context}).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstListItem = firstTextBlock.listItem\n\n if (!firstListItem) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.listItem === firstListItem)) {\n return firstListItem\n }\n\n return undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveStyle: EditorSelector<PortableTextTextBlock['style']> = ({\n context,\n}) => {\n if (!context.selection) {\n return undefined\n }\n\n const guards = createGuards(context)\n const selectedBlocks = getSelectedBlocks({context}).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstStyle = firstTextBlock.style\n\n if (!firstStyle) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.style === firstStyle)) {\n return firstStyle\n }\n\n return undefined\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextSpan,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelectedSpans: EditorSelector<\n Array<{\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }>\n> = ({context}) => {\n if (!context.selection) {\n return []\n }\n\n const selectedSpans: Array<{\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }> = []\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 = 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\n if (!startBlockKey || !endBlockKey) {\n return selectedSpans\n }\n\n const startSpanKey = isKeySegment(startPoint.path[2])\n ? startPoint.path[2]._key\n : undefined\n const endSpanKey = isKeySegment(endPoint.path[2])\n ? endPoint.path[2]._key\n : undefined\n\n for (const block of context.value) {\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n if (block._key === startBlockKey) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (startSpanKey && child._key === startSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n\n if (startSpanKey === endSpanKey) {\n break\n }\n\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n break\n }\n\n if (selectedSpans.length > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n if (block._key === endBlockKey) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n break\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n\n break\n }\n\n if (selectedSpans.length > 0) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n }\n\n return selectedSpans\n}\n","import {isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport function isActiveAnnotation(\n annotation: string,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const selectedSpans = getSelectedSpans(snapshot)\n\n if (selectedSpans.length === 0) {\n return false\n }\n\n if (\n selectedSpans.some(\n (span) => !span.node.marks || span.node.marks?.length === 0,\n )\n ) {\n return false\n }\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isPortableTextTextBlock(block.node) ? (block.node.markDefs ?? []) : [],\n )\n\n return selectedSpans.every((span) => {\n const spanMarkDefs =\n span.node.marks?.flatMap((mark) => {\n const markDef = selectionMarkDefs.find(\n (markDef) => markDef._key === mark,\n )\n\n return markDef ? [markDef._type] : []\n }) ?? []\n\n return spanMarkDefs.includes(annotation)\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 {getSelectedSpans} from './selector.get-selected-spans'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\n\n/**\n * @public\n */\nexport function isActiveDecorator(decorator: string): EditorSelector<boolean> {\n return (snapshot) => {\n if (isSelectionExpanded(snapshot)) {\n const selectedSpans = getSelectedSpans(snapshot)\n\n return (\n selectedSpans.length > 0 &&\n selectedSpans.every((span) => span.node.marks?.includes(decorator))\n )\n }\n\n return snapshot.context.activeDecorators.includes(decorator)\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveListItem} from './selector.get-active-list-item'\n\n/**\n * @public\n */\nexport function isActiveListItem(listItem: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeListItem = getActiveListItem(snapshot)\n\n return activeListItem === listItem\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveStyle} from './selector.get-active-style'\n\n/**\n * @public\n */\nexport function isActiveStyle(style: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeStyle = getActiveStyle(snapshot)\n\n return activeStyle === style\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 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","getActiveListItem","selectedTextBlocks","map","filter","firstTextBlock","at","firstListItem","listItem","every","getActiveStyle","firstStyle","style","getSelectedSpans","selectedSpans","startPoint","endPoint","startBlockKey","endBlockKey","startSpanKey","endSpanKey","child","isActiveAnnotation","annotation","snapshot","some","marks","selectionMarkDefs","flatMap","markDefs","mark","markDef","includes","isSelectionCollapsed","JSON","stringify","offset","isSelectionExpanded","isActiveDecorator","decorator","activeDecorators","isActiveListItem","isActiveStyle","isAtTheEndOfBlock","blockEndPoint","utils","getBlockEndPoint","isEqualSelectionPoints","isAtTheStartOfBlock","blockStartPoint","getBlockStartPoint"],"mappings":";;AAaO,SAASA,aAAa;AAAA,EAACC;AAA8B,GAAG;AAC7D,WAASC,YAAYC,OAAgD;AACnE,WAAOC,MAAAA,wB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BvB,kBAAkBuB,QAAQ,MAEvBhB;AAE9B;ACNO,SAASkC,cAAc9B,OAAwC;AAC5DY,SAAAA,CAAAA,aACcd,eAAec,QAAQ,MAEpBZ;AAE3B;ACJO,SAAS+B,kBAAkB3F,OAGN;AAC1B,SAAO,CAAC;AAAA,IAACO;AAAAA,EAAAA,MAAa;AACpB,QAAI,CAACA,QAAQE,aAAa,CAACwE,qBAAqB;AAAA,MAAC1E;AAAAA,IAAAA,CAAQ;AAChD,aAAA;AAGHqF,UAAAA,gBAAgBC,4BAAMC,iBAAiB9F,KAAK;AAElD,WAAO6F,4BAAME,uBAAuBxF,QAAQE,UAAUE,OAAOiF,aAAa;AAAA,EAC5E;AACF;ACbO,SAASI,oBAAoBhG,OAGR;AAC1B,SAAO,CAAC;AAAA,IAACO;AAAAA,EAAAA,MAAa;AACpB,QAAI,CAACA,QAAQE,aAAa,CAACwE,qBAAqB;AAAA,MAAC1E;AAAAA,IAAAA,CAAQ;AAChD,aAAA;AAGH0F,UAAAA,kBAAkBJ,4BAAMK,mBAAmBlG,KAAK;AAEtD,WAAO6F,4BAAME,uBACXxF,QAAQE,UAAUE,OAClBsF,eACF;AAAA,EACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- var types = require("@sanity/types"), util_isKeyedSegment = require("./util.is-keyed-segment.cjs");
2
+ var types = require("@sanity/types"), util_isEqualSelectionPoints = require("./util.is-equal-selection-points.cjs");
3
3
  function blockOffsetToSpanSelectionPoint({
4
4
  value,
5
5
  blockOffset
@@ -37,7 +37,7 @@ function spanSelectionPointToBlockOffset({
37
37
  selectionPoint
38
38
  }) {
39
39
  let offset = 0;
40
- const blockKey = util_isKeyedSegment.isKeyedSegment(selectionPoint.path[0]) ? selectionPoint.path[0]._key : void 0, spanKey = util_isKeyedSegment.isKeyedSegment(selectionPoint.path[2]) ? selectionPoint.path[2]._key : void 0;
40
+ const blockKey = util_isEqualSelectionPoints.isKeyedSegment(selectionPoint.path[0]) ? selectionPoint.path[0]._key : void 0, spanKey = util_isEqualSelectionPoints.isKeyedSegment(selectionPoint.path[2]) ? selectionPoint.path[2]._key : void 0;
41
41
  if (!(!blockKey || !spanKey)) {
42
42
  for (const block of value)
43
43
  if (block._key === blockKey && types.isPortableTextTextBlock(block)) {
@@ -1 +1 @@
1
- {"version":3,"file":"util.is-empty-text-block.cjs","sources":["../../src/utils/util.block-offset.ts","../../src/utils/util.get-text-block-text.ts","../../src/utils/util.is-empty-text-block.ts"],"sourcesContent":["import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {BlockOffset} from '../behaviors/behavior.types'\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}: {\n value: Array<PortableTextBlock>\n blockOffset: BlockOffset\n}) {\n let offsetLeft = blockOffset.offset\n let selectionPoint:\n | {path: [KeyedSegment, 'children', KeyedSegment]; offset: number}\n | undefined\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 (!isPortableTextSpan(child)) {\n continue\n }\n\n if (offsetLeft === 0) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: 0,\n }\n break\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 }\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 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"],"names":["blockOffsetToSpanSelectionPoint","value","blockOffset","offsetLeft","offset","selectionPoint","block","_key","path","isPortableTextTextBlock","child","children","isPortableTextSpan","text","length","spanSelectionPointToBlockOffset","blockKey","isKeyedSegment","undefined","spanKey","getTextBlockText","map","join","isEmptyTextBlock","onlyText","every","blockText"],"mappings":";;AAaO,SAASA,gCAAgC;AAAA,EAC9CC;AAAAA,EACAC;AAIF,GAAG;AACGC,MAAAA,aAAaD,YAAYE,QACzBC;AAIJ,aAAWC,SAASL;AACdK,QAAAA,MAAMC,SAASL,YAAYM,KAAK,CAAC,EAAED,QAIlCE,8BAAwBH,KAAK;AAIlC,iBAAWI,SAASJ,MAAMK;AACnBC,YAAAA,MAAAA,mBAAmBF,KAAK,GAI7B;AAAA,cAAIP,eAAe,GAAG;AACH,6BAAA;AAAA,cACfK,MAAM,CA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ASC,iBAAiBjB,OAA0B;AACrD,MAAA,CAACG,8BAAwBH,KAAK;AACzB,WAAA;AAGHkB,QAAAA,WAAWlB,MAAMK,SAASc,MAAMb,MAAAA,kBAAkB,GAClDc,YAAYN,iBAAiBd,KAAK;AAExC,SAAOkB,YAAYE,cAAc;AACnC;;;;;"}
1
+ {"version":3,"file":"util.is-empty-text-block.cjs","sources":["../../src/utils/util.block-offset.ts","../../src/utils/util.get-text-block-text.ts","../../src/utils/util.is-empty-text-block.ts"],"sourcesContent":["import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {BlockOffset} from '../behaviors/behavior.types'\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}: {\n value: Array<PortableTextBlock>\n blockOffset: BlockOffset\n}) {\n let offsetLeft = blockOffset.offset\n let selectionPoint:\n | {path: [KeyedSegment, 'children', KeyedSegment]; offset: number}\n | undefined\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 (!isPortableTextSpan(child)) {\n continue\n }\n\n if (offsetLeft === 0) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: 0,\n }\n break\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 }\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 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"],"names":["blockOffsetToSpanSelectionPoint","value","blockOffset","offsetLeft","offset","selectionPoint","block","_key","path","isPortableTextTextBlock","child","children","isPortableTextSpan","text","length","spanSelectionPointToBlockOffset","blockKey","isKeyedSegment","undefined","spanKey","getTextBlockText","map","join","isEmptyTextBlock","onlyText","every","blockText"],"mappings":";;AAaO,SAASA,gCAAgC;AAAA,EAC9CC;AAAAA,EACAC;AAIF,GAAG;AACGC,MAAAA,aAAaD,YAAYE,QACzBC;AAIJ,aAAWC,SAASL;AACdK,QAAAA,MAAMC,SAASL,YAAYM,KAAK,CAAC,EAAED,QAIlCE,8BAAwBH,KAAK;AAIlC,iBAAWI,SAASJ,MAAMK;AACnBC,YAAAA,MAAAA,mBAAmBF,KAAK,GAI7B;AAAA,cAAIP,eAAe,GAAG;AACH,6BAAA;AAAA,cACfK,MAAM,CAAC,GAAGN,YAAYM,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0B;AACrD,MAAA,CAACG,8BAAwBH,KAAK;AACzB,WAAA;AAGHkB,QAAAA,WAAWlB,MAAMK,SAASc,MAAMb,MAAAA,kBAAkB,GAClDc,YAAYN,iBAAiBd,KAAK;AAExC,SAAOkB,YAAYE,cAAc;AACnC;;;;;"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var types = require("@sanity/types");
3
+ function isKeyedSegment(segment) {
4
+ return typeof segment == "object" && segment !== null && "_key" in segment;
5
+ }
6
+ function getBlockEndPoint({
7
+ node,
8
+ path
9
+ }) {
10
+ if (types.isPortableTextTextBlock(node)) {
11
+ const lastChild = node.children[node.children.length - 1];
12
+ if (lastChild)
13
+ return {
14
+ path: [...path, "children", {
15
+ _key: lastChild._key
16
+ }],
17
+ offset: types.isPortableTextSpan(lastChild) ? lastChild.text.length : 0
18
+ };
19
+ }
20
+ return {
21
+ path,
22
+ offset: 0
23
+ };
24
+ }
25
+ function getBlockStartPoint({
26
+ node,
27
+ path
28
+ }) {
29
+ return types.isPortableTextTextBlock(node) ? {
30
+ path: [...path, "children", {
31
+ _key: node.children[0]._key
32
+ }],
33
+ offset: 0
34
+ } : {
35
+ path,
36
+ offset: 0
37
+ };
38
+ }
39
+ function isEqualSelectionPoints(a, b) {
40
+ return a.offset === b.offset && JSON.stringify(a.path) === JSON.stringify(b.path);
41
+ }
42
+ exports.getBlockEndPoint = getBlockEndPoint;
43
+ exports.getBlockStartPoint = getBlockStartPoint;
44
+ exports.isEqualSelectionPoints = isEqualSelectionPoints;
45
+ exports.isKeyedSegment = isKeyedSegment;
46
+ //# sourceMappingURL=util.is-equal-selection-points.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.is-equal-selection-points.cjs","sources":["../../src/utils/util.is-keyed-segment.ts","../../src/utils/util.get-block-end-point.ts","../../src/utils/util.get-block-start-point.ts","../../src/utils/util.is-equal-selection-points.ts"],"sourcesContent":["import type {KeyedSegment, PathSegment} from '@sanity/types'\n\n/**\n * @public\n */\nexport function isKeyedSegment(segment: PathSegment): 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 {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 {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"],"names":["isKeyedSegment","segment","getBlockEndPoint","node","path","isPortableTextTextBlock","lastChild","children","length","_key","offset","isPortableTextSpan","text","getBlockStartPoint","isEqualSelectionPoints","a","b","JSON","stringify"],"mappings":";;AAKO,SAASA,eAAeC,SAA+C;AAC5E,SAAO,OAAOA,WAAY,YAAYA,YAAY,QAAQ,UAAUA;AACtE;ACIO,SAASC,iBAAiB;AAAA,EAC/BC;AAAAA,EACAC;AAIF,GAAyB;AACnBC,MAAAA,MAAAA,wBAAwBF,IAAI,GAAG;AACjC,UAAMG,YAAYH,KAAKI,SAASJ,KAAKI,SAASC,SAAS,CAAC;AAEpDF,QAAAA;AACK,aAAA;AAAA,QACLF,MAAM,CAAC,GAAGA,MAAM,YAAY;AAAA,UAACK,MAAMH,UAAUG;AAAAA,QAAAA,CAAK;AAAA,QAClDC,QAAQC,MAAmBL,mBAAAA,SAAS,IAAIA,UAAUM,KAAKJ,SAAS;AAAA,MAClE;AAAA,EAAA;AAIG,SAAA;AAAA,IACLJ;AAAAA,IACAM,QAAQ;AAAA,EACV;AACF;ACvBO,SAASG,mBAAmB;AAAA,EACjCV;AAAAA,EACAC;AAIF,GAAyB;AACnBC,SAAAA,MAAAA,wBAAwBF,IAAI,IACvB;AAAA,IACLC,MAAM,CAAC,GAAGA,MAAM,YAAY;AAAA,MAACK,MAAMN,KAAKI,SAAS,CAAC,EAAEE;AAAAA,IAAAA,CAAK;AAAA,IACzDC,QAAQ;AAAA,EAAA,IAIL;AAAA,IACLN;AAAAA,IACAM,QAAQ;AAAA,EACV;AACF;ACvBgBI,SAAAA,uBACdC,GACAC,GACA;AACA,SACED,EAAEL,WAAWM,EAAEN,UAAUO,KAAKC,UAAUH,EAAEX,IAAI,MAAMa,KAAKC,UAAUF,EAAEZ,IAAI;AAE7E;;;;;"}
@@ -1,19 +1,4 @@
1
1
  "use strict";
2
- var types = require("@sanity/types");
3
- function getBlockStartPoint({
4
- node,
5
- path
6
- }) {
7
- return types.isPortableTextTextBlock(node) ? {
8
- path: [...path, "children", {
9
- _key: node.children[0]._key
10
- }],
11
- offset: 0
12
- } : {
13
- path,
14
- offset: 0
15
- };
16
- }
17
2
  function reverseSelection(selection) {
18
3
  return selection.backward ? {
19
4
  anchor: selection.focus,
@@ -25,6 +10,5 @@ function reverseSelection(selection) {
25
10
  backward: !0
26
11
  };
27
12
  }
28
- exports.getBlockStartPoint = getBlockStartPoint;
29
13
  exports.reverseSelection = reverseSelection;
30
14
  //# sourceMappingURL=util.reverse-selection.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.reverse-selection.cjs","sources":["../../src/utils/util.get-block-start-point.ts","../../src/utils/util.reverse-selection.ts"],"sourcesContent":["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 {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function reverseSelection(\n selection: NonNullable<EditorSelection>,\n): NonNullable<EditorSelection> {\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n }\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n }\n}\n"],"names":["getBlockStartPoint","node","path","isPortableTextTextBlock","_key","children","offset","reverseSelection","selection","backward","anchor","focus"],"mappings":";;AAUO,SAASA,mBAAmB;AAAA,EACjCC;AAAAA,EACAC;AAIF,GAAyB;AACnBC,SAAAA,MAAAA,wBAAwBF,IAAI,IACvB;AAAA,IACLC,MAAM,CAAC,GAAGA,MAAM,YAAY;AAAA,MAACE,MAAMH,KAAKI,SAAS,CAAC,EAAED;AAAAA,IAAAA,CAAK;AAAA,IACzDE,QAAQ;AAAA,EAAA,IAIL;AAAA,IACLJ;AAAAA,IACAI,QAAQ;AAAA,EACV;AACF;ACvBO,SAASC,iBACdC,WAC8B;AAC9B,SAAIA,UAAUC,WACL;AAAA,IACLC,QAAQF,UAAUG;AAAAA,IAClBA,OAAOH,UAAUE;AAAAA,IACjBD,UAAU;AAAA,EAAA,IAIP;AAAA,IACLC,QAAQF,UAAUG;AAAAA,IAClBA,OAAOH,UAAUE;AAAAA,IACjBD,UAAU;AAAA,EACZ;AACF;;;"}
1
+ {"version":3,"file":"util.reverse-selection.cjs","sources":["../../src/utils/util.reverse-selection.ts"],"sourcesContent":["import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function reverseSelection(\n selection: NonNullable<EditorSelection>,\n): NonNullable<EditorSelection> {\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n }\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n }\n}\n"],"names":["reverseSelection","selection","backward","anchor","focus"],"mappings":";AAKO,SAASA,iBACdC,WAC8B;AAC9B,SAAIA,UAAUC,WACL;AAAA,IACLC,QAAQF,UAAUG;AAAAA,IAClBA,OAAOH,UAAUE;AAAAA,IACjBD,UAAU;AAAA,EAAA,IAIP;AAAA,IACLC,QAAQF,UAAUG;AAAAA,IAClBA,OAAOH,UAAUE;AAAAA,IACjBD,UAAU;AAAA,EACZ;AACF;;"}