@portabletext/editor 1.55.13 → 1.55.14

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 (74) hide show
  1. package/lib/_chunks-cjs/{selector.is-selection-expanded.cjs → selector.get-focus-span.cjs} +27 -27
  2. package/lib/_chunks-cjs/selector.get-focus-span.cjs.map +1 -0
  3. package/lib/_chunks-cjs/selector.get-text-before.cjs +3 -3
  4. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  5. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +291 -168
  6. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
  7. package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs +1 -1
  8. package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs.map +1 -1
  9. package/lib/_chunks-cjs/{util.is-equal-selection-points.cjs → util.is-selection-collapsed.cjs} +7 -3
  10. package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +1 -0
  11. package/lib/_chunks-cjs/util.slice-blocks.cjs +2 -2
  12. package/lib/_chunks-cjs/util.slice-text-block.cjs +2 -6
  13. package/lib/_chunks-cjs/util.slice-text-block.cjs.map +1 -1
  14. package/lib/_chunks-es/{selector.is-selection-expanded.js → selector.get-focus-span.js} +27 -27
  15. package/lib/_chunks-es/selector.get-focus-span.js.map +1 -0
  16. package/lib/_chunks-es/selector.get-text-before.js +1 -1
  17. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +266 -143
  18. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
  19. package/lib/_chunks-es/util.child-selection-point-to-block-offset.js +1 -1
  20. package/lib/_chunks-es/{util.is-equal-selection-points.js → util.is-selection-collapsed.js} +7 -3
  21. package/lib/_chunks-es/util.is-selection-collapsed.js.map +1 -0
  22. package/lib/_chunks-es/util.slice-blocks.js +2 -2
  23. package/lib/_chunks-es/util.slice-text-block.js +1 -5
  24. package/lib/_chunks-es/util.slice-text-block.js.map +1 -1
  25. package/lib/behaviors/index.d.cts +3 -6
  26. package/lib/behaviors/index.d.ts +3 -6
  27. package/lib/index.cjs +110 -239
  28. package/lib/index.cjs.map +1 -1
  29. package/lib/index.d.cts +11 -20
  30. package/lib/index.d.ts +11 -20
  31. package/lib/index.js +49 -178
  32. package/lib/index.js.map +1 -1
  33. package/lib/plugins/index.cjs +16 -16
  34. package/lib/plugins/index.cjs.map +1 -1
  35. package/lib/plugins/index.d.cts +3 -6
  36. package/lib/plugins/index.d.ts +3 -6
  37. package/lib/plugins/index.js +1 -1
  38. package/lib/selectors/index.cjs +14 -14
  39. package/lib/selectors/index.cjs.map +1 -1
  40. package/lib/selectors/index.d.cts +3 -6
  41. package/lib/selectors/index.d.ts +3 -6
  42. package/lib/selectors/index.js +2 -2
  43. package/lib/utils/index.cjs +9 -9
  44. package/lib/utils/index.cjs.map +1 -1
  45. package/lib/utils/index.d.cts +3 -6
  46. package/lib/utils/index.d.ts +3 -6
  47. package/lib/utils/index.js +5 -5
  48. package/package.json +3 -3
  49. package/src/behaviors/behavior.abstract.ts +2 -1
  50. package/src/editor/create-slate-editor.tsx +0 -1
  51. package/src/editor/editor-selector.ts +1 -13
  52. package/src/editor/editor-snapshot.ts +4 -19
  53. package/src/editor/plugins/createWithEditableAPI.ts +9 -5
  54. package/src/editor/plugins/createWithPortableTextMarkModel.ts +13 -4
  55. package/src/editor/plugins/with-plugins.ts +4 -8
  56. package/src/internal-utils/create-test-snapshot.ts +2 -5
  57. package/src/operations/behavior.operation.decorator.add.ts +1 -4
  58. package/src/operations/behavior.operation.insert.text.ts +34 -20
  59. package/src/selectors/selector.get-active-annotation-marks.ts +12 -0
  60. package/src/selectors/selector.get-active-annotations.ts +8 -20
  61. package/src/{editor/get-active-decorators.ts → selectors/selector.get-active-decorators.ts} +6 -11
  62. package/src/{internal-utils/mark-state.ts → selectors/selector.get-mark-state.ts} +41 -67
  63. package/src/selectors/selector.get-next-span.ts +56 -0
  64. package/src/selectors/selector.get-previous-span.ts +53 -0
  65. package/src/selectors/selector.is-active-annotation.ts +3 -1
  66. package/src/selectors/selector.is-active-decorator.ts +4 -1
  67. package/src/types/editor.ts +0 -2
  68. package/src/utils/util.is-selection-expanded.ts +13 -0
  69. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +0 -1
  70. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +0 -1
  71. package/lib/_chunks-es/selector.is-selection-expanded.js.map +0 -1
  72. package/lib/_chunks-es/util.is-equal-selection-points.js.map +0 -1
  73. package/src/editor/get-active-annotations.ts +0 -15
  74. package/src/editor/plugins/slate-plugin.update-mark-state.ts +0 -21
@@ -1,6 +1,150 @@
1
1
  "use strict";
2
- var util_sliceBlocks = require("./util.slice-blocks.cjs"), selector_isSelectionExpanded = require("./selector.is-selection-expanded.cjs"), util_isEqualSelectionPoints = require("./util.is-equal-selection-points.cjs"), types = require("@sanity/types");
3
- const getSelectedBlocks = (snapshot) => {
2
+ var util_sliceBlocks = require("./util.slice-blocks.cjs"), util_isSelectionCollapsed = require("./util.is-selection-collapsed.cjs"), selector_getFocusSpan = require("./selector.get-focus-span.cjs"), types = require("@sanity/types");
3
+ function isSelectionExpanded(selection) {
4
+ return selection ? !util_isSelectionCollapsed.isSelectionCollapsed(selection) : !1;
5
+ }
6
+ const getSelectionEndBlock = (snapshot) => {
7
+ const endPoint = util_sliceBlocks.getSelectionEndPoint(snapshot.context.selection);
8
+ if (endPoint)
9
+ return selector_getFocusSpan.getFocusBlock({
10
+ ...snapshot,
11
+ context: {
12
+ ...snapshot.context,
13
+ selection: {
14
+ anchor: endPoint,
15
+ focus: endPoint
16
+ }
17
+ }
18
+ });
19
+ }, getSelectionEndPoint = (snapshot) => {
20
+ if (snapshot.context.selection)
21
+ return snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus;
22
+ }, getNextSpan = (snapshot) => {
23
+ const selectionEndBlock = getSelectionEndBlock(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot);
24
+ if (!selectionEndBlock || !selectionEndPoint || !util_sliceBlocks.isTextBlock(snapshot.context, selectionEndBlock.node))
25
+ return;
26
+ const selectionEndPointChildKey = util_sliceBlocks.getChildKeyFromSelectionPoint(selectionEndPoint);
27
+ let endPointChildFound = !1, nextSpan;
28
+ for (const child of selectionEndBlock.node.children) {
29
+ if (child._key === selectionEndPointChildKey) {
30
+ endPointChildFound = !0;
31
+ continue;
32
+ }
33
+ if (util_sliceBlocks.isSpan(snapshot.context, child) && endPointChildFound) {
34
+ nextSpan = {
35
+ node: child,
36
+ path: [...selectionEndBlock.path, "children", {
37
+ _key: child._key
38
+ }]
39
+ };
40
+ break;
41
+ }
42
+ }
43
+ return nextSpan;
44
+ }, getSelectionStartBlock = (snapshot) => {
45
+ const startPoint = util_sliceBlocks.getSelectionStartPoint(snapshot.context.selection);
46
+ if (startPoint)
47
+ return selector_getFocusSpan.getFocusBlock({
48
+ ...snapshot,
49
+ context: {
50
+ ...snapshot.context,
51
+ selection: {
52
+ anchor: startPoint,
53
+ focus: startPoint
54
+ }
55
+ }
56
+ });
57
+ }, getPreviousSpan = (snapshot) => {
58
+ const selectionStartBlock = getSelectionStartBlock(snapshot), selectionStartPoint = selector_getFocusSpan.getSelectionStartPoint(snapshot);
59
+ if (!selectionStartBlock || !selectionStartPoint || !util_sliceBlocks.isTextBlock(snapshot.context, selectionStartBlock.node))
60
+ return;
61
+ const selectionStartPointChildKey = util_sliceBlocks.getChildKeyFromSelectionPoint(selectionStartPoint);
62
+ let previousSpan;
63
+ for (const child of selectionStartBlock.node.children) {
64
+ if (child._key === selectionStartPointChildKey)
65
+ break;
66
+ util_sliceBlocks.isSpan(snapshot.context, child) && (previousSpan = {
67
+ node: child,
68
+ path: [...selectionStartBlock.path, "children", {
69
+ _key: child._key
70
+ }]
71
+ });
72
+ }
73
+ return previousSpan;
74
+ }, getMarkState = (snapshot) => {
75
+ if (!snapshot.context.selection)
76
+ return;
77
+ const focusTextBlock = selector_getFocusSpan.getFocusTextBlock(snapshot), focusSpan = selector_getFocusSpan.getFocusSpan(snapshot);
78
+ if (!focusTextBlock || !focusSpan)
79
+ return;
80
+ if (isSelectionExpanded(snapshot.context.selection)) {
81
+ const selectedSpans = getSelectedSpans(snapshot);
82
+ let index = 0, marks2 = [];
83
+ for (const span of selectedSpans) {
84
+ if (index === 0)
85
+ marks2 = span.node.marks ?? [];
86
+ else {
87
+ if (span.node.marks?.length === 0) {
88
+ marks2 = [];
89
+ continue;
90
+ }
91
+ marks2 = marks2.filter((mark) => (span.node.marks ?? []).some((spanMark) => spanMark === mark));
92
+ }
93
+ index++;
94
+ }
95
+ return {
96
+ state: "unchanged",
97
+ marks: marks2
98
+ };
99
+ }
100
+ const decorators = snapshot.context.schema.decorators.map((decorator) => decorator.name), marks = focusSpan.node.marks ?? [], marksWithoutAnnotations = marks.filter((mark) => decorators.includes(mark)), spanHasAnnotations = marks.length > marksWithoutAnnotations.length, spanIsEmpty = focusSpan.node.text.length === 0, atTheBeginningOfSpan = snapshot.context.selection.anchor.offset === 0, atTheEndOfSpan = snapshot.context.selection.anchor.offset === focusSpan.node.text.length, previousSpan = getPreviousSpan(snapshot), nextSpan = getNextSpan(snapshot), nextSpanAnnotations = nextSpan?.node?.marks?.filter((mark) => !decorators.includes(mark)) ?? [], spanAnnotations = marks.filter((mark) => !decorators.includes(mark)), previousSpanHasAnnotations = previousSpan ? previousSpan.node.marks?.some((mark) => !decorators.includes(mark)) : !1, previousSpanHasSameAnnotations = previousSpan ? previousSpan.node.marks?.filter((mark) => !decorators.includes(mark)).every((mark) => marks.includes(mark)) : !1, previousSpanHasSameAnnotation = previousSpan ? previousSpan.node.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, previousSpanHasSameMarks = previousSpan ? previousSpan.node.marks?.every((mark) => marks.includes(mark)) : !1, nextSpanSharesSomeAnnotations = spanAnnotations.some((mark) => nextSpanAnnotations?.includes(mark));
101
+ if (spanHasAnnotations && !spanIsEmpty) {
102
+ if (atTheBeginningOfSpan) {
103
+ if (previousSpanHasSameMarks)
104
+ return {
105
+ state: "changed",
106
+ marks: previousSpan?.node.marks ?? []
107
+ };
108
+ if (previousSpanHasSameAnnotations)
109
+ return {
110
+ state: "changed",
111
+ marks: previousSpan?.node.marks ?? []
112
+ };
113
+ if (previousSpanHasSameAnnotation)
114
+ return {
115
+ state: "unchanged",
116
+ marks: focusSpan.node.marks ?? []
117
+ };
118
+ if (!previousSpan)
119
+ return {
120
+ state: "changed",
121
+ marks: []
122
+ };
123
+ }
124
+ if (atTheEndOfSpan) {
125
+ if (nextSpan && nextSpanSharesSomeAnnotations && nextSpanAnnotations.length < spanAnnotations.length || !nextSpanSharesSomeAnnotations)
126
+ return {
127
+ state: "changed",
128
+ marks: nextSpan?.node.marks ?? []
129
+ };
130
+ if (!nextSpan)
131
+ return {
132
+ state: "changed",
133
+ marks: []
134
+ };
135
+ }
136
+ }
137
+ return atTheBeginningOfSpan && !spanIsEmpty && previousSpan ? previousSpanHasAnnotations ? {
138
+ state: "changed",
139
+ marks: []
140
+ } : {
141
+ state: "changed",
142
+ marks: (previousSpan?.node.marks ?? []).filter((mark) => decorators.includes(mark))
143
+ } : {
144
+ state: "unchanged",
145
+ marks: focusSpan.node.marks ?? []
146
+ };
147
+ }, getSelectedBlocks = (snapshot) => {
4
148
  if (!snapshot.context.selection)
5
149
  return [];
6
150
  const selectedBlocks = [], startPoint = util_sliceBlocks.getSelectionStartPoint(snapshot.context.selection), endPoint = util_sliceBlocks.getSelectionEndPoint(snapshot.context.selection), startKey = util_sliceBlocks.getBlockKeyFromSelectionPoint(startPoint), endKey = util_sliceBlocks.getBlockKeyFromSelectionPoint(endPoint);
@@ -38,114 +182,10 @@ const getSelectedBlocks = (snapshot) => {
38
182
  });
39
183
  }
40
184
  return selectedBlocks;
41
- }, getSelectionEndPoint = (snapshot) => {
42
- if (snapshot.context.selection)
43
- return snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus;
44
- }, getSelectedSpans = (snapshot) => {
45
- if (!snapshot.context.selection)
46
- return [];
47
- const selectedSpans = [], startPoint = selector_isSelectionExpanded.getSelectionStartPoint(snapshot), endPoint = getSelectionEndPoint(snapshot);
48
- if (!startPoint || !endPoint)
49
- return selectedSpans;
50
- const startBlockKey = util_sliceBlocks.getBlockKeyFromSelectionPoint(startPoint), endBlockKey = util_sliceBlocks.getBlockKeyFromSelectionPoint(endPoint), startSpanKey = util_sliceBlocks.getChildKeyFromSelectionPoint(startPoint), endSpanKey = util_sliceBlocks.getChildKeyFromSelectionPoint(endPoint);
51
- if (!startBlockKey || !endBlockKey)
52
- return selectedSpans;
53
- const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey), endBlockIndex = snapshot.blockIndexMap.get(endBlockKey);
54
- if (startBlockIndex === void 0 || endBlockIndex === void 0)
55
- return selectedSpans;
56
- const slicedValue = snapshot.context.value.slice(startBlockIndex, endBlockIndex + 1);
57
- let startBlockFound = !1;
58
- for (const block of slicedValue)
59
- if (block._key === startBlockKey && (startBlockFound = !0), !!util_sliceBlocks.isTextBlock(snapshot.context, block)) {
60
- if (block._key === startBlockKey) {
61
- for (const child of block.children)
62
- if (util_sliceBlocks.isSpan$1(snapshot.context, child)) {
63
- if (startSpanKey && child._key === startSpanKey) {
64
- if (startPoint.offset < child.text.length && selectedSpans.push({
65
- node: child,
66
- path: [{
67
- _key: block._key
68
- }, "children", {
69
- _key: child._key
70
- }]
71
- }), startSpanKey === endSpanKey)
72
- break;
73
- continue;
74
- }
75
- if (endSpanKey && child._key === endSpanKey) {
76
- endPoint.offset > 0 && selectedSpans.push({
77
- node: child,
78
- path: [{
79
- _key: block._key
80
- }, "children", {
81
- _key: child._key
82
- }]
83
- });
84
- break;
85
- }
86
- selectedSpans.length > 0 && selectedSpans.push({
87
- node: child,
88
- path: [{
89
- _key: block._key
90
- }, "children", {
91
- _key: child._key
92
- }]
93
- });
94
- }
95
- if (startBlockKey === endBlockKey)
96
- break;
97
- continue;
98
- }
99
- if (block._key === endBlockKey) {
100
- for (const child of block.children)
101
- if (util_sliceBlocks.isSpan$1(snapshot.context, child)) {
102
- if (endSpanKey && child._key === endSpanKey) {
103
- endPoint.offset > 0 && selectedSpans.push({
104
- node: child,
105
- path: [{
106
- _key: block._key
107
- }, "children", {
108
- _key: child._key
109
- }]
110
- });
111
- break;
112
- }
113
- selectedSpans.push({
114
- node: child,
115
- path: [{
116
- _key: block._key
117
- }, "children", {
118
- _key: child._key
119
- }]
120
- });
121
- }
122
- break;
123
- }
124
- if (startBlockFound)
125
- for (const child of block.children)
126
- util_sliceBlocks.isSpan$1(snapshot.context, child) && selectedSpans.push({
127
- node: child,
128
- path: [{
129
- _key: block._key
130
- }, "children", {
131
- _key: child._key
132
- }]
133
- });
134
- }
135
- return selectedSpans;
136
185
  }, getActiveAnnotations = (snapshot) => {
137
186
  if (!snapshot.context.selection)
138
187
  return [];
139
- const selectedBlocks = getSelectedBlocks(snapshot), selectedSpans = getSelectedSpans(snapshot), focusSpan = selector_isSelectionExpanded.getFocusSpan(snapshot);
140
- if (selectedSpans.length === 0 || !focusSpan)
141
- return [];
142
- if (selectedSpans.length === 1 && selector_isSelectionExpanded.isSelectionCollapsed(snapshot)) {
143
- if (snapshot.context.selection.focus.offset === 0)
144
- return [];
145
- if (snapshot.context.selection.focus.offset === focusSpan.node.text.length)
146
- return [];
147
- }
148
- const activeAnnotations = snapshot.beta.activeAnnotations;
188
+ const selectedBlocks = getSelectedBlocks(snapshot), activeAnnotations = (getMarkState(snapshot)?.marks ?? []).filter((mark) => !snapshot.context.schema.decorators.map((decorator) => decorator.name).includes(mark));
149
189
  return selectedBlocks.flatMap((block) => util_sliceBlocks.isTextBlock(snapshot.context, block.node) ? block.node.markDefs ?? [] : []).filter((markDef) => activeAnnotations.includes(markDef._key));
150
190
  }, getActiveListItem = (snapshot) => {
151
191
  if (!snapshot.context.selection)
@@ -166,7 +206,7 @@ const getSelectedBlocks = (snapshot) => {
166
206
  if (firstStyle && selectedTextBlocks.every((block) => block.style === firstStyle))
167
207
  return firstStyle;
168
208
  }, getNextInlineObject = (snapshot) => {
169
- const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot), selectionEndPointChildKey = selectionEndPoint && types.isKeySegment(selectionEndPoint.path[2]) ? selectionEndPoint.path[2]._key : void 0;
209
+ const focusTextBlock = selector_getFocusSpan.getFocusTextBlock(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot), selectionEndPointChildKey = selectionEndPoint && types.isKeySegment(selectionEndPoint.path[2]) ? selectionEndPoint.path[2]._key : void 0;
170
210
  if (!focusTextBlock || !selectionEndPointChildKey)
171
211
  return;
172
212
  let endPointChildFound = !1, inlineObject;
@@ -175,7 +215,7 @@ const getSelectedBlocks = (snapshot) => {
175
215
  endPointChildFound = !0;
176
216
  continue;
177
217
  }
178
- if (!util_sliceBlocks.isSpan(snapshot.context, child) && endPointChildFound) {
218
+ if (!util_sliceBlocks.isSpan$1(snapshot.context, child) && endPointChildFound) {
179
219
  inlineObject = {
180
220
  node: child,
181
221
  path: [...focusTextBlock.path, "children", {
@@ -187,18 +227,18 @@ const getSelectedBlocks = (snapshot) => {
187
227
  }
188
228
  return inlineObject;
189
229
  }, getCaretWordSelection = (snapshot) => {
190
- if (!snapshot.context.selection || !selector_isSelectionExpanded.isSelectionCollapsed(snapshot))
230
+ if (!snapshot.context.selection || !selector_getFocusSpan.isSelectionCollapsed(snapshot))
191
231
  return null;
192
- const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot), selectionStartPoint = selector_isSelectionExpanded.getSelectionStartPoint(snapshot), selectionStartOffset = selectionStartPoint ? util_sliceBlocks.spanSelectionPointToBlockOffset({
232
+ const focusTextBlock = selector_getFocusSpan.getFocusTextBlock(snapshot), selectionStartPoint = selector_getFocusSpan.getSelectionStartPoint(snapshot), selectionStartOffset = selectionStartPoint ? util_sliceBlocks.spanSelectionPointToBlockOffset({
193
233
  context: snapshot.context,
194
234
  selectionPoint: selectionStartPoint
195
235
  }) : void 0;
196
236
  if (!focusTextBlock || !selectionStartPoint || !selectionStartOffset)
197
237
  return null;
198
- const previousInlineObject = selector_isSelectionExpanded.getPreviousInlineObject(snapshot), blockStartPoint = util_sliceBlocks.getBlockStartPoint({
238
+ const previousInlineObject = selector_getFocusSpan.getPreviousInlineObject(snapshot), blockStartPoint = util_sliceBlocks.getBlockStartPoint({
199
239
  context: snapshot.context,
200
240
  block: focusTextBlock
201
- }), textDirectlyBefore = selector_isSelectionExpanded.getSelectionText({
241
+ }), textDirectlyBefore = selector_getFocusSpan.getSelectionText({
202
242
  ...snapshot,
203
243
  context: {
204
244
  ...snapshot.context,
@@ -210,10 +250,10 @@ const getSelectedBlocks = (snapshot) => {
210
250
  focus: selectionStartPoint
211
251
  }
212
252
  }
213
- }).split(/\s+/).at(-1), nextInlineObject = getNextInlineObject(snapshot), blockEndPoint = util_isEqualSelectionPoints.getBlockEndPoint({
253
+ }).split(/\s+/).at(-1), nextInlineObject = getNextInlineObject(snapshot), blockEndPoint = util_isSelectionCollapsed.getBlockEndPoint({
214
254
  context: snapshot.context,
215
255
  block: focusTextBlock
216
- }), textDirectlyAfter = selector_isSelectionExpanded.getSelectionText({
256
+ }), textDirectlyAfter = selector_getFocusSpan.getSelectionText({
217
257
  ...snapshot,
218
258
  context: {
219
259
  ...snapshot.context,
@@ -249,7 +289,7 @@ const getSelectedBlocks = (snapshot) => {
249
289
  anchor: caretWordStartSelectionPoint,
250
290
  focus: caretWordEndSelectionPoint
251
291
  };
252
- return selector_isSelectionExpanded.isSelectionExpanded({
292
+ return selector_getFocusSpan.isSelectionExpanded({
253
293
  context: {
254
294
  ...snapshot.context,
255
295
  selection: caretWordSelection
@@ -264,19 +304,19 @@ const getSelectedBlocks = (snapshot) => {
264
304
  }]
265
305
  } : void 0;
266
306
  }, getFocusBlockObject = (snapshot) => {
267
- const focusBlock = selector_isSelectionExpanded.getFocusBlock(snapshot);
307
+ const focusBlock = selector_getFocusSpan.getFocusBlock(snapshot);
268
308
  return focusBlock && !util_sliceBlocks.isTextBlock(snapshot.context, focusBlock.node) ? {
269
309
  node: focusBlock.node,
270
310
  path: focusBlock.path
271
311
  } : void 0;
272
312
  }, getFocusInlineObject = (snapshot) => {
273
- const focusChild = selector_isSelectionExpanded.getFocusChild(snapshot);
313
+ const focusChild = selector_getFocusSpan.getFocusChild(snapshot);
274
314
  return focusChild && !types.isPortableTextSpan(focusChild.node) ? {
275
315
  node: focusChild.node,
276
316
  path: focusChild.path
277
317
  } : void 0;
278
318
  }, getFocusListBlock = (snapshot) => {
279
- const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot);
319
+ const focusTextBlock = selector_getFocusSpan.getFocusTextBlock(snapshot);
280
320
  return focusTextBlock && util_sliceBlocks.isListBlock(snapshot.context, focusTextBlock.node) ? {
281
321
  node: focusTextBlock.node,
282
322
  path: focusTextBlock.path
@@ -289,19 +329,6 @@ const getSelectedBlocks = (snapshot) => {
289
329
  _key: node._key
290
330
  }]
291
331
  } : void 0;
292
- }, getSelectionEndBlock = (snapshot) => {
293
- const endPoint = util_sliceBlocks.getSelectionEndPoint(snapshot.context.selection);
294
- if (endPoint)
295
- return selector_isSelectionExpanded.getFocusBlock({
296
- ...snapshot,
297
- context: {
298
- ...snapshot.context,
299
- selection: {
300
- anchor: endPoint,
301
- focus: endPoint
302
- }
303
- }
304
- });
305
332
  }, getNextBlock = (snapshot) => {
306
333
  const selectionEndBlock = getSelectionEndBlock(snapshot);
307
334
  if (!selectionEndBlock)
@@ -316,19 +343,6 @@ const getSelectedBlocks = (snapshot) => {
316
343
  _key: nextBlock._key
317
344
  }]
318
345
  } : void 0;
319
- }, getSelectionStartBlock = (snapshot) => {
320
- const startPoint = util_sliceBlocks.getSelectionStartPoint(snapshot.context.selection);
321
- if (startPoint)
322
- return selector_isSelectionExpanded.getFocusBlock({
323
- ...snapshot,
324
- context: {
325
- ...snapshot.context,
326
- selection: {
327
- anchor: startPoint,
328
- focus: startPoint
329
- }
330
- }
331
- });
332
346
  }, getPreviousBlock = (snapshot) => {
333
347
  const selectionStartBlock = getSelectionStartBlock(snapshot);
334
348
  if (!selectionStartBlock)
@@ -343,6 +357,98 @@ const getSelectedBlocks = (snapshot) => {
343
357
  _key: previousBlock._key
344
358
  }]
345
359
  } : void 0;
360
+ }, getSelectedSpans = (snapshot) => {
361
+ if (!snapshot.context.selection)
362
+ return [];
363
+ const selectedSpans = [], startPoint = selector_getFocusSpan.getSelectionStartPoint(snapshot), endPoint = getSelectionEndPoint(snapshot);
364
+ if (!startPoint || !endPoint)
365
+ return selectedSpans;
366
+ const startBlockKey = util_sliceBlocks.getBlockKeyFromSelectionPoint(startPoint), endBlockKey = util_sliceBlocks.getBlockKeyFromSelectionPoint(endPoint), startSpanKey = util_sliceBlocks.getChildKeyFromSelectionPoint(startPoint), endSpanKey = util_sliceBlocks.getChildKeyFromSelectionPoint(endPoint);
367
+ if (!startBlockKey || !endBlockKey)
368
+ return selectedSpans;
369
+ const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey), endBlockIndex = snapshot.blockIndexMap.get(endBlockKey);
370
+ if (startBlockIndex === void 0 || endBlockIndex === void 0)
371
+ return selectedSpans;
372
+ const slicedValue = snapshot.context.value.slice(startBlockIndex, endBlockIndex + 1);
373
+ let startBlockFound = !1;
374
+ for (const block of slicedValue)
375
+ if (block._key === startBlockKey && (startBlockFound = !0), !!util_sliceBlocks.isTextBlock(snapshot.context, block)) {
376
+ if (block._key === startBlockKey) {
377
+ for (const child of block.children)
378
+ if (util_sliceBlocks.isSpan(snapshot.context, child)) {
379
+ if (startSpanKey && child._key === startSpanKey) {
380
+ if (startPoint.offset < child.text.length && selectedSpans.push({
381
+ node: child,
382
+ path: [{
383
+ _key: block._key
384
+ }, "children", {
385
+ _key: child._key
386
+ }]
387
+ }), startSpanKey === endSpanKey)
388
+ break;
389
+ continue;
390
+ }
391
+ if (endSpanKey && child._key === endSpanKey) {
392
+ endPoint.offset > 0 && selectedSpans.push({
393
+ node: child,
394
+ path: [{
395
+ _key: block._key
396
+ }, "children", {
397
+ _key: child._key
398
+ }]
399
+ });
400
+ break;
401
+ }
402
+ selectedSpans.length > 0 && selectedSpans.push({
403
+ node: child,
404
+ path: [{
405
+ _key: block._key
406
+ }, "children", {
407
+ _key: child._key
408
+ }]
409
+ });
410
+ }
411
+ if (startBlockKey === endBlockKey)
412
+ break;
413
+ continue;
414
+ }
415
+ if (block._key === endBlockKey) {
416
+ for (const child of block.children)
417
+ if (util_sliceBlocks.isSpan(snapshot.context, child)) {
418
+ if (endSpanKey && child._key === endSpanKey) {
419
+ endPoint.offset > 0 && selectedSpans.push({
420
+ node: child,
421
+ path: [{
422
+ _key: block._key
423
+ }, "children", {
424
+ _key: child._key
425
+ }]
426
+ });
427
+ break;
428
+ }
429
+ selectedSpans.push({
430
+ node: child,
431
+ path: [{
432
+ _key: block._key
433
+ }, "children", {
434
+ _key: child._key
435
+ }]
436
+ });
437
+ }
438
+ break;
439
+ }
440
+ if (startBlockFound)
441
+ for (const child of block.children)
442
+ util_sliceBlocks.isSpan(snapshot.context, child) && selectedSpans.push({
443
+ node: child,
444
+ path: [{
445
+ _key: block._key
446
+ }, "children", {
447
+ _key: child._key
448
+ }]
449
+ });
450
+ }
451
+ return selectedSpans;
346
452
  }, getSelectedTextBlocks = (snapshot) => {
347
453
  if (!snapshot.context.selection)
348
454
  return [];
@@ -393,11 +499,11 @@ const getSelectedBlocks = (snapshot) => {
393
499
  const slicedValue = snapshot.context.value.slice(startBlockIndex, endBlockIndex + 1);
394
500
  let startBlockFound = !1, adjustedStartPoint, trimStartPoint = !1, adjustedEndPoint, trimEndPoint = !1, previousPotentialEndpoint;
395
501
  for (const block of slicedValue)
396
- if (!(block._key === startBlockKey && (startBlockFound = !0, util_sliceBlocks.isTextBlock(snapshot.context, block) && util_isEqualSelectionPoints.isEmptyTextBlock(snapshot.context, block))) && startBlockFound && util_sliceBlocks.isTextBlock(snapshot.context, block)) {
397
- if (block._key === endBlockKey && util_isEqualSelectionPoints.isEmptyTextBlock(snapshot.context, block))
502
+ if (!(block._key === startBlockKey && (startBlockFound = !0, util_sliceBlocks.isTextBlock(snapshot.context, block) && util_isSelectionCollapsed.isEmptyTextBlock(snapshot.context, block))) && startBlockFound && util_sliceBlocks.isTextBlock(snapshot.context, block)) {
503
+ if (block._key === endBlockKey && util_isSelectionCollapsed.isEmptyTextBlock(snapshot.context, block))
398
504
  break;
399
505
  for (const child of block.children) {
400
- if (child._key === endChildKey && (!util_sliceBlocks.isSpan$1(snapshot.context, child) || endPoint.offset === 0)) {
506
+ if (child._key === endChildKey && (!util_sliceBlocks.isSpan(snapshot.context, child) || endPoint.offset === 0)) {
401
507
  adjustedEndPoint = previousPotentialEndpoint ? {
402
508
  path: [{
403
509
  _key: previousPotentialEndpoint.blockKey
@@ -409,8 +515,8 @@ const getSelectedBlocks = (snapshot) => {
409
515
  break;
410
516
  }
411
517
  if (trimStartPoint) {
412
- const lonelySpan = util_sliceBlocks.isSpan$1(snapshot.context, child) && block.children.length === 1;
413
- (util_sliceBlocks.isSpan$1(snapshot.context, child) && child.text.length > 0 || lonelySpan) && (adjustedStartPoint = {
518
+ const lonelySpan = util_sliceBlocks.isSpan(snapshot.context, child) && block.children.length === 1;
519
+ (util_sliceBlocks.isSpan(snapshot.context, child) && child.text.length > 0 || lonelySpan) && (adjustedStartPoint = {
414
520
  path: [{
415
521
  _key: block._key
416
522
  }, "children", {
@@ -424,7 +530,7 @@ const getSelectedBlocks = (snapshot) => {
424
530
  continue;
425
531
  }
426
532
  if (child._key === startChildKey) {
427
- if (!util_sliceBlocks.isSpan$1(snapshot.context, child)) {
533
+ if (!util_sliceBlocks.isSpan(snapshot.context, child)) {
428
534
  trimStartPoint = !0;
429
535
  continue;
430
536
  }
@@ -436,7 +542,7 @@ const getSelectedBlocks = (snapshot) => {
436
542
  continue;
437
543
  }
438
544
  }
439
- previousPotentialEndpoint = util_sliceBlocks.isSpan$1(snapshot.context, child) && child.text.length > 0 ? {
545
+ previousPotentialEndpoint = util_sliceBlocks.isSpan(snapshot.context, child) && child.text.length > 0 ? {
440
546
  blockKey: block._key,
441
547
  span: child
442
548
  } : previousPotentialEndpoint;
@@ -452,34 +558,48 @@ const getSelectedBlocks = (snapshot) => {
452
558
  anchor: adjustedStartPoint ?? startPoint,
453
559
  focus: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint
454
560
  };
455
- if (selector_isSelectionExpanded.isSelectionCollapsed({
561
+ if (selector_getFocusSpan.isSelectionCollapsed({
456
562
  context: {
457
563
  ...snapshot.context,
458
564
  selection: trimmedSelection
459
565
  }
460
566
  })) {
461
- const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock({
567
+ const focusTextBlock = selector_getFocusSpan.getFocusTextBlock({
462
568
  ...snapshot,
463
569
  context: {
464
570
  ...snapshot.context,
465
571
  selection: trimmedSelection
466
572
  }
467
573
  });
468
- if (focusTextBlock && !util_isEqualSelectionPoints.isEmptyTextBlock(snapshot.context, focusTextBlock.node))
574
+ if (focusTextBlock && !util_isSelectionCollapsed.isEmptyTextBlock(snapshot.context, focusTextBlock.node))
469
575
  return null;
470
576
  }
471
577
  return trimmedSelection;
472
578
  };
579
+ function getActiveAnnotationsMarks(snapshot) {
580
+ const schema = snapshot.context.schema;
581
+ return (getMarkState(snapshot)?.marks ?? []).filter((mark) => !schema.decorators.map((decorator) => decorator.name).includes(mark));
582
+ }
473
583
  function isActiveAnnotation(annotation) {
474
- return (snapshot) => getSelectedBlocks(snapshot).flatMap((block) => util_sliceBlocks.isTextBlock(snapshot.context, block.node) ? block.node.markDefs ?? [] : []).filter((markDef) => markDef._type === annotation && snapshot.beta.activeAnnotations.includes(markDef._key)).length > 0;
584
+ return (snapshot) => {
585
+ const selectionMarkDefs = getSelectedBlocks(snapshot).flatMap((block) => util_sliceBlocks.isTextBlock(snapshot.context, block.node) ? block.node.markDefs ?? [] : []), activeAnnotations = getActiveAnnotationsMarks(snapshot);
586
+ return selectionMarkDefs.filter((markDef) => markDef._type === annotation && activeAnnotations.includes(markDef._key)).length > 0;
587
+ };
588
+ }
589
+ function getActiveDecorators(snapshot) {
590
+ const schema = snapshot.context.schema, decoratorState = snapshot.decoratorState, markState = getMarkState(snapshot), decorators = schema.decorators.map((decorator) => decorator.name);
591
+ let activeDecorators = (markState?.marks ?? []).filter((mark) => decorators.includes(mark));
592
+ for (const decorator in decoratorState)
593
+ decoratorState[decorator] === !1 ? activeDecorators = activeDecorators.filter((activeDecorator) => activeDecorator !== decorator) : decoratorState[decorator] === !0 && (activeDecorators.includes(decorator) || activeDecorators.push(decorator));
594
+ return activeDecorators;
475
595
  }
476
596
  function isActiveDecorator(decorator) {
477
597
  return (snapshot) => {
478
- if (selector_isSelectionExpanded.isSelectionExpanded(snapshot)) {
598
+ if (selector_getFocusSpan.isSelectionExpanded(snapshot)) {
479
599
  const selectedSpans = getSelectedSpans(snapshot);
480
600
  return selectedSpans.length > 0 && selectedSpans.every((span) => span.node.marks?.includes(decorator));
481
601
  }
482
- return snapshot.beta.activeDecorators.includes(decorator);
602
+ return getActiveDecorators(snapshot).includes(decorator);
483
603
  };
484
604
  }
485
605
  function isActiveListItem(listItem) {
@@ -490,24 +610,24 @@ function isActiveStyle(style) {
490
610
  }
491
611
  function isAtTheEndOfBlock(block) {
492
612
  return (snapshot) => {
493
- if (!snapshot.context.selection || !selector_isSelectionExpanded.isSelectionCollapsed(snapshot))
613
+ if (!snapshot.context.selection || !selector_getFocusSpan.isSelectionCollapsed(snapshot))
494
614
  return !1;
495
- const blockEndPoint = util_isEqualSelectionPoints.getBlockEndPoint({
615
+ const blockEndPoint = util_isSelectionCollapsed.getBlockEndPoint({
496
616
  context: snapshot.context,
497
617
  block
498
618
  });
499
- return util_isEqualSelectionPoints.isEqualSelectionPoints(snapshot.context.selection.focus, blockEndPoint);
619
+ return util_isSelectionCollapsed.isEqualSelectionPoints(snapshot.context.selection.focus, blockEndPoint);
500
620
  };
501
621
  }
502
622
  function isAtTheStartOfBlock(block) {
503
623
  return (snapshot) => {
504
- if (!snapshot.context.selection || !selector_isSelectionExpanded.isSelectionCollapsed(snapshot))
624
+ if (!snapshot.context.selection || !selector_getFocusSpan.isSelectionCollapsed(snapshot))
505
625
  return !1;
506
626
  const blockStartPoint = util_sliceBlocks.getBlockStartPoint({
507
627
  context: snapshot.context,
508
628
  block
509
629
  });
510
- return util_isEqualSelectionPoints.isEqualSelectionPoints(snapshot.context.selection.focus, blockStartPoint);
630
+ return util_isSelectionCollapsed.isEqualSelectionPoints(snapshot.context.selection.focus, blockStartPoint);
511
631
  };
512
632
  }
513
633
  function isPointAfterSelection(point) {
@@ -568,7 +688,7 @@ function isOverlappingSelection(selection) {
568
688
  return (snapshot) => {
569
689
  if (!selection || !snapshot.context.selection)
570
690
  return !1;
571
- const selectionStartPoint = selector_isSelectionExpanded.getSelectionStartPoint({
691
+ const selectionStartPoint = selector_getFocusSpan.getSelectionStartPoint({
572
692
  context: {
573
693
  ...snapshot.context,
574
694
  selection
@@ -578,7 +698,7 @@ function isOverlappingSelection(selection) {
578
698
  ...snapshot.context,
579
699
  selection
580
700
  }
581
- }), originalSelectionStartPoint = selector_isSelectionExpanded.getSelectionStartPoint(snapshot), originalSelectionEndPoint = getSelectionEndPoint(snapshot);
701
+ }), originalSelectionStartPoint = selector_getFocusSpan.getSelectionStartPoint(snapshot), originalSelectionEndPoint = getSelectionEndPoint(snapshot);
582
702
  if (!selectionStartPoint || !selectionEndPoint || !originalSelectionStartPoint || !originalSelectionEndPoint)
583
703
  return !1;
584
704
  const startPointBeforeSelection = isPointBeforeSelection(selectionStartPoint)(snapshot), startPointAfterSelection = isPointAfterSelection(selectionStartPoint)(snapshot), endPointBeforeSelection = isPointBeforeSelection(selectionEndPoint)(snapshot), endPointAfterSelection = isPointAfterSelection(selectionEndPoint)(snapshot), originalStartPointBeforeStartPoint = isPointBeforeSelection(originalSelectionStartPoint)({
@@ -617,7 +737,7 @@ function isOverlappingSelection(selection) {
617
737
  focus: selectionEndPoint
618
738
  }
619
739
  }
620
- }), endPointEqualToOriginalStartPoint = util_isEqualSelectionPoints.isEqualSelectionPoints(selectionEndPoint, originalSelectionStartPoint), startPointEqualToOriginalEndPoint = util_isEqualSelectionPoints.isEqualSelectionPoints(selectionStartPoint, originalSelectionEndPoint);
740
+ }), endPointEqualToOriginalStartPoint = util_isSelectionCollapsed.isEqualSelectionPoints(selectionEndPoint, originalSelectionStartPoint), startPointEqualToOriginalEndPoint = util_isSelectionCollapsed.isEqualSelectionPoints(selectionStartPoint, originalSelectionEndPoint);
621
741
  return endPointBeforeSelection && !endPointEqualToOriginalStartPoint || startPointAfterSelection && !startPointEqualToOriginalEndPoint ? !1 : !originalStartPointBeforeStartPoint && originalStartPointAfterStartPoint && !originalEndPointBeforeEndPoint && originalEndPointAfterEndPoint ? !endPointEqualToOriginalStartPoint : originalStartPointBeforeStartPoint && !originalStartPointAfterStartPoint && originalEndPointBeforeEndPoint && !originalEndPointAfterEndPoint ? !startPointEqualToOriginalEndPoint : !startPointAfterSelection || !startPointBeforeSelection || !endPointAfterSelection || !endPointBeforeSelection;
622
742
  };
623
743
  }
@@ -630,13 +750,15 @@ const isSelectingEntireBlocks = (snapshot) => {
630
750
  const startBlockStartPoint = util_sliceBlocks.getBlockStartPoint({
631
751
  context: snapshot.context,
632
752
  block: startBlock
633
- }), endBlockEndPoint = util_isEqualSelectionPoints.getBlockEndPoint({
753
+ }), endBlockEndPoint = util_isSelectionCollapsed.getBlockEndPoint({
634
754
  context: snapshot.context,
635
755
  block: endBlock
636
756
  });
637
- return util_isEqualSelectionPoints.isEqualSelectionPoints(startBlockStartPoint, startPoint) && util_isEqualSelectionPoints.isEqualSelectionPoints(endBlockEndPoint, endPoint);
757
+ return util_isSelectionCollapsed.isEqualSelectionPoints(startBlockStartPoint, startPoint) && util_isSelectionCollapsed.isEqualSelectionPoints(endBlockEndPoint, endPoint);
638
758
  };
639
759
  exports.getActiveAnnotations = getActiveAnnotations;
760
+ exports.getActiveAnnotationsMarks = getActiveAnnotationsMarks;
761
+ exports.getActiveDecorators = getActiveDecorators;
640
762
  exports.getActiveListItem = getActiveListItem;
641
763
  exports.getActiveStyle = getActiveStyle;
642
764
  exports.getCaretWordSelection = getCaretWordSelection;
@@ -645,6 +767,7 @@ exports.getFocusBlockObject = getFocusBlockObject;
645
767
  exports.getFocusInlineObject = getFocusInlineObject;
646
768
  exports.getFocusListBlock = getFocusListBlock;
647
769
  exports.getLastBlock = getLastBlock;
770
+ exports.getMarkState = getMarkState;
648
771
  exports.getNextBlock = getNextBlock;
649
772
  exports.getNextInlineObject = getNextInlineObject;
650
773
  exports.getPreviousBlock = getPreviousBlock;