@portabletext/editor 1.41.3 → 1.41.4

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 (48) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +52 -28
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/behavior.markdown.cjs +11 -11
  4. package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
  5. package/lib/_chunks-cjs/editor-provider.cjs +24 -21
  6. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  7. package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs +2 -2
  8. package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs.map +1 -1
  9. package/lib/_chunks-cjs/selector.get-text-before.cjs +2 -2
  10. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  11. package/lib/_chunks-cjs/selector.is-active-style.cjs +240 -0
  12. package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -0
  13. package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +300 -218
  14. package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
  15. package/lib/_chunks-es/behavior.core.js +27 -3
  16. package/lib/_chunks-es/behavior.core.js.map +1 -1
  17. package/lib/_chunks-es/behavior.markdown.js +1 -1
  18. package/lib/_chunks-es/editor-provider.js +5 -2
  19. package/lib/_chunks-es/editor-provider.js.map +1 -1
  20. package/lib/_chunks-es/selector.get-focus-inline-object.js +1 -1
  21. package/lib/_chunks-es/selector.get-text-before.js +1 -1
  22. package/lib/_chunks-es/selector.is-active-style.js +243 -0
  23. package/lib/_chunks-es/selector.is-active-style.js.map +1 -0
  24. package/lib/_chunks-es/selector.is-overlapping-selection.js +298 -217
  25. package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
  26. package/lib/behaviors/index.cjs +9 -9
  27. package/lib/behaviors/index.cjs.map +1 -1
  28. package/lib/behaviors/index.js +1 -1
  29. package/lib/index.cjs +75 -102
  30. package/lib/index.cjs.map +1 -1
  31. package/lib/index.js +66 -93
  32. package/lib/index.js.map +1 -1
  33. package/lib/plugins/index.cjs +6 -6
  34. package/lib/plugins/index.cjs.map +1 -1
  35. package/lib/plugins/index.js +1 -1
  36. package/lib/selectors/index.cjs +36 -36
  37. package/lib/selectors/index.cjs.map +1 -1
  38. package/lib/selectors/index.js +4 -4
  39. package/package.json +1 -1
  40. package/src/behaviors/behavior.core.dnd.ts +27 -0
  41. package/src/behaviors/behavior.core.ts +2 -0
  42. package/src/behaviors/behavior.default.ts +4 -0
  43. package/src/editor/Editable.tsx +22 -40
  44. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +0 -322
  45. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +0 -1
  46. package/lib/_chunks-es/selector.is-at-the-start-of-block.js +0 -324
  47. package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +0 -1
  48. package/src/internal-utils/dragging-on-drag-origin.ts +0 -22
@@ -1,234 +1,299 @@
1
- import { getBlockStartPoint, getBlockEndPoint, isEqualSelectionPoints, isEmptyTextBlock, isKeyedSegment, reverseSelection } from "./util.slice-blocks.js";
2
- import { getSelectionStartBlock, getSelectionEndBlock, getSelectedBlocks, createGuards, isSelectionCollapsed, getSelectionStartPoint, getSelectionEndPoint, getFocusTextBlock, getFocusSpan, isSelectionExpanded } from "./selector.is-at-the-start-of-block.js";
3
- import { isKeySegment, isPortableTextTextBlock, isPortableTextSpan } from "@sanity/types";
4
- const isSelectingEntireBlocks = (snapshot) => {
5
- if (!snapshot.context.selection)
6
- return !1;
7
- const startPoint = snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor, endPoint = snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus, startBlock = getSelectionStartBlock(snapshot), endBlock = getSelectionEndBlock(snapshot);
8
- if (!startBlock || !endBlock)
9
- return !1;
10
- const startBlockStartPoint = getBlockStartPoint(startBlock), endBlockEndPoint = getBlockEndPoint(endBlock);
11
- return isEqualSelectionPoints(startBlockStartPoint, startPoint) && isEqualSelectionPoints(endBlockEndPoint, endPoint);
12
- }, getSelectedSpans = (snapshot) => {
1
+ import { isSpan, sliceBlocks, spanSelectionPointToBlockOffset, getBlockStartPoint, getBlockEndPoint, blockOffsetToSpanSelectionPoint, isEqualSelectionPoints, reverseSelection } from "./util.slice-blocks.js";
2
+ import { isPortableTextTextBlock, isPortableTextListBlock, isPortableTextSpan, isKeySegment } from "@sanity/types";
3
+ function createGuards({
4
+ schema
5
+ }) {
6
+ function isListBlock(block) {
7
+ return isPortableTextListBlock(block) && block._type === schema.block.name;
8
+ }
9
+ function isTextBlock(block) {
10
+ return isPortableTextTextBlock(block) && block._type === schema.block.name;
11
+ }
12
+ return {
13
+ isListBlock,
14
+ isTextBlock
15
+ };
16
+ }
17
+ const getFocusBlock = (snapshot) => {
18
+ const key = snapshot.context.selection && isKeySegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0, node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
19
+ return node && key ? {
20
+ node,
21
+ path: [{
22
+ _key: key
23
+ }]
24
+ } : void 0;
25
+ }, getFocusListBlock = (snapshot) => {
26
+ const guards = createGuards(snapshot.context), focusBlock = getFocusBlock(snapshot);
27
+ return focusBlock && guards.isListBlock(focusBlock.node) ? {
28
+ node: focusBlock.node,
29
+ path: focusBlock.path
30
+ } : void 0;
31
+ }, getFocusTextBlock = (snapshot) => {
32
+ const focusBlock = getFocusBlock(snapshot);
33
+ return focusBlock && isPortableTextTextBlock(focusBlock.node) ? {
34
+ node: focusBlock.node,
35
+ path: focusBlock.path
36
+ } : void 0;
37
+ }, getFocusBlockObject = (snapshot) => {
38
+ const focusBlock = getFocusBlock(snapshot);
39
+ return focusBlock && !isPortableTextTextBlock(focusBlock.node) ? {
40
+ node: focusBlock.node,
41
+ path: focusBlock.path
42
+ } : void 0;
43
+ }, getFocusChild = (snapshot) => {
44
+ const focusBlock = getFocusTextBlock(snapshot);
45
+ if (!focusBlock)
46
+ return;
47
+ const key = snapshot.context.selection && isKeySegment(snapshot.context.selection.focus.path[2]) ? snapshot.context.selection.focus.path[2]._key : void 0, node = key ? focusBlock.node.children.find((span) => span._key === key) : void 0;
48
+ return node && key ? {
49
+ node,
50
+ path: [...focusBlock.path, "children", {
51
+ _key: key
52
+ }]
53
+ } : void 0;
54
+ }, getFocusSpan = (snapshot) => {
55
+ const focusChild = getFocusChild(snapshot);
56
+ return focusChild && isPortableTextSpan(focusChild.node) ? {
57
+ node: focusChild.node,
58
+ path: focusChild.path
59
+ } : void 0;
60
+ }, getFirstBlock = (snapshot) => {
61
+ const node = snapshot.context.value[0];
62
+ return node ? {
63
+ node,
64
+ path: [{
65
+ _key: node._key
66
+ }]
67
+ } : void 0;
68
+ }, getLastBlock = (snapshot) => {
69
+ const node = snapshot.context.value[snapshot.context.value.length - 1] ? snapshot.context.value[snapshot.context.value.length - 1] : void 0;
70
+ return node ? {
71
+ node,
72
+ path: [{
73
+ _key: node._key
74
+ }]
75
+ } : void 0;
76
+ }, getSelectedBlocks = (snapshot) => {
13
77
  if (!snapshot.context.selection)
14
78
  return [];
15
- const selectedSpans = [], startPoint = snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor, endPoint = snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus, startBlockKey = isKeySegment(startPoint.path[0]) ? startPoint.path[0]._key : void 0, endBlockKey = isKeySegment(endPoint.path[0]) ? endPoint.path[0]._key : void 0;
16
- if (!startBlockKey || !endBlockKey)
17
- return selectedSpans;
18
- const startSpanKey = isKeySegment(startPoint.path[2]) ? startPoint.path[2]._key : void 0, endSpanKey = isKeySegment(endPoint.path[2]) ? endPoint.path[2]._key : void 0;
19
- let startBlockFound = !1;
20
- for (const block of snapshot.context.value)
21
- if (block._key === startBlockKey && (startBlockFound = !0), !!isPortableTextTextBlock(block)) {
22
- if (block._key === startBlockKey) {
23
- for (const child of block.children)
24
- if (isPortableTextSpan(child)) {
25
- if (startSpanKey && child._key === startSpanKey) {
26
- if (startPoint.offset < child.text.length && selectedSpans.push({
27
- node: child,
28
- path: [{
29
- _key: block._key
30
- }, "children", {
31
- _key: child._key
32
- }]
33
- }), startSpanKey === endSpanKey)
34
- break;
35
- continue;
36
- }
37
- if (endSpanKey && child._key === endSpanKey) {
38
- endPoint.offset > 0 && selectedSpans.push({
39
- node: child,
40
- path: [{
41
- _key: block._key
42
- }, "children", {
43
- _key: child._key
44
- }]
45
- });
46
- break;
47
- }
48
- selectedSpans.length > 0 && selectedSpans.push({
49
- node: child,
50
- path: [{
51
- _key: block._key
52
- }, "children", {
53
- _key: child._key
54
- }]
55
- });
56
- }
57
- if (startBlockKey === endBlockKey)
58
- break;
59
- continue;
60
- }
61
- if (block._key === endBlockKey) {
62
- for (const child of block.children)
63
- if (isPortableTextSpan(child)) {
64
- if (endSpanKey && child._key === endSpanKey) {
65
- endPoint.offset > 0 && selectedSpans.push({
66
- node: child,
67
- path: [{
68
- _key: block._key
69
- }, "children", {
70
- _key: child._key
71
- }]
72
- });
73
- break;
74
- }
75
- selectedSpans.push({
76
- node: child,
77
- path: [{
78
- _key: block._key
79
- }, "children", {
80
- _key: child._key
81
- }]
82
- });
83
- }
79
+ const selectedBlocks = [], startKey = snapshot.context.selection.backward ? isKeySegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0 : isKeySegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0, endKey = snapshot.context.selection.backward ? isKeySegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0 : isKeySegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0;
80
+ if (!startKey || !endKey)
81
+ return selectedBlocks;
82
+ for (const block of snapshot.context.value) {
83
+ if (block._key === startKey) {
84
+ if (selectedBlocks.push({
85
+ node: block,
86
+ path: [{
87
+ _key: block._key
88
+ }]
89
+ }), startKey === endKey)
84
90
  break;
85
- }
86
- if (startBlockFound)
87
- for (const child of block.children)
88
- isPortableTextSpan(child) && selectedSpans.push({
89
- node: child,
90
- path: [{
91
- _key: block._key
92
- }, "children", {
93
- _key: child._key
94
- }]
95
- });
91
+ continue;
96
92
  }
97
- return selectedSpans;
98
- }, getActiveListItem = (snapshot) => {
93
+ if (block._key === endKey) {
94
+ selectedBlocks.push({
95
+ node: block,
96
+ path: [{
97
+ _key: block._key
98
+ }]
99
+ });
100
+ break;
101
+ }
102
+ selectedBlocks.length > 0 && selectedBlocks.push({
103
+ node: block,
104
+ path: [{
105
+ _key: block._key
106
+ }]
107
+ });
108
+ }
109
+ return selectedBlocks;
110
+ }, getSelectionStartBlock = (snapshot) => {
99
111
  if (!snapshot.context.selection)
100
112
  return;
101
- const guards = createGuards(snapshot.context), selectedTextBlocks = getSelectedBlocks(snapshot).map((block) => block.node).filter(guards.isTextBlock), firstTextBlock = selectedTextBlocks.at(0);
102
- if (!firstTextBlock)
103
- return;
104
- const firstListItem = firstTextBlock.listItem;
105
- if (firstListItem && selectedTextBlocks.every((block) => block.listItem === firstListItem))
106
- return firstListItem;
107
- }, getActiveStyle = (snapshot) => {
113
+ const key = snapshot.context.selection.backward ? isKeySegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0 : isKeySegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0, node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
114
+ return node && key ? {
115
+ node,
116
+ path: [{
117
+ _key: key
118
+ }]
119
+ } : void 0;
120
+ }, getSelectionEndBlock = (snapshot) => {
108
121
  if (!snapshot.context.selection)
109
122
  return;
110
- const guards = createGuards(snapshot.context), selectedTextBlocks = getSelectedBlocks(snapshot).map((block) => block.node).filter(guards.isTextBlock), firstTextBlock = selectedTextBlocks.at(0);
111
- if (!firstTextBlock)
123
+ const key = snapshot.context.selection.backward ? isKeySegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0 : isKeySegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0, node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
124
+ return node && key ? {
125
+ node,
126
+ path: [{
127
+ _key: key
128
+ }]
129
+ } : void 0;
130
+ }, getPreviousBlock = (snapshot) => {
131
+ let previousBlock;
132
+ const selectionStartBlock = getSelectionStartBlock(snapshot);
133
+ if (!selectionStartBlock)
112
134
  return;
113
- const firstStyle = firstTextBlock.style;
114
- if (firstStyle && selectedTextBlocks.every((block) => block.style === firstStyle))
115
- return firstStyle;
116
- }, getTrimmedSelection = (snapshot) => {
117
- if (!snapshot.context.selection)
118
- return snapshot.context.selection;
119
- const startPoint = getSelectionStartPoint(snapshot), endPoint = getSelectionEndPoint(snapshot);
120
- if (!startPoint || !endPoint)
121
- return snapshot.context.selection;
122
- const startBlockKey = isKeyedSegment(startPoint.path[0]) ? startPoint.path[0]._key : null, startChildKey = isKeyedSegment(startPoint.path[2]) ? startPoint.path[2]._key : null, endBlockKey = isKeyedSegment(endPoint.path[0]) ? endPoint.path[0]._key : null, endChildKey = isKeyedSegment(endPoint.path[2]) ? endPoint.path[2]._key : null;
123
- if (!startBlockKey || !endBlockKey)
124
- return snapshot.context.selection;
125
- let startBlockFound = !1, adjustedStartPoint, trimStartPoint = !1, adjustedEndPoint, trimEndPoint = !1, previousPotentialEndpoint;
126
- for (const block of snapshot.context.value)
127
- if (!(block._key === startBlockKey && (startBlockFound = !0, isPortableTextTextBlock(block) && isEmptyTextBlock(block))) && startBlockFound && isPortableTextTextBlock(block)) {
128
- if (block._key === endBlockKey && isEmptyTextBlock(block))
129
- break;
130
- for (const child of block.children) {
131
- if (child._key === endChildKey && (!isPortableTextSpan(child) || endPoint.offset === 0)) {
132
- adjustedEndPoint = previousPotentialEndpoint ? {
133
- path: [{
134
- _key: previousPotentialEndpoint.blockKey
135
- }, "children", {
136
- _key: previousPotentialEndpoint.span._key
137
- }],
138
- offset: previousPotentialEndpoint.span.text.length
139
- } : void 0, trimEndPoint = !0;
140
- break;
141
- }
142
- if (trimStartPoint) {
143
- const lonelySpan = isPortableTextSpan(child) && block.children.length === 1;
144
- (isPortableTextSpan(child) && child.text.length > 0 || lonelySpan) && (adjustedStartPoint = {
145
- path: [{
146
- _key: block._key
147
- }, "children", {
148
- _key: child._key
149
- }],
150
- offset: 0
151
- }, previousPotentialEndpoint = {
152
- blockKey: block._key,
153
- span: child
154
- }, trimStartPoint = !1);
155
- continue;
156
- }
157
- if (child._key === startChildKey) {
158
- if (!isPortableTextSpan(child)) {
159
- trimStartPoint = !0;
160
- continue;
161
- }
162
- if (startPoint.offset === child.text.length) {
163
- trimStartPoint = !0, previousPotentialEndpoint = child.text.length > 0 ? {
164
- blockKey: block._key,
165
- span: child
166
- } : previousPotentialEndpoint;
167
- continue;
168
- }
169
- }
170
- previousPotentialEndpoint = isPortableTextSpan(child) && child.text.length > 0 ? {
171
- blockKey: block._key,
172
- span: child
173
- } : previousPotentialEndpoint;
135
+ let foundSelectionStartBlock = !1;
136
+ for (const block of snapshot.context.value) {
137
+ if (block._key === selectionStartBlock.node._key) {
138
+ foundSelectionStartBlock = !0;
139
+ break;
140
+ }
141
+ previousBlock = {
142
+ node: block,
143
+ path: [{
144
+ _key: block._key
145
+ }]
146
+ };
147
+ }
148
+ if (foundSelectionStartBlock && previousBlock)
149
+ return previousBlock;
150
+ }, getNextBlock = (snapshot) => {
151
+ let nextBlock;
152
+ const selectionEndBlock = getSelectionEndBlock(snapshot);
153
+ if (!selectionEndBlock)
154
+ return;
155
+ let foundSelectionEndBlock = !1;
156
+ for (const block of snapshot.context.value) {
157
+ if (block._key === selectionEndBlock.node._key) {
158
+ foundSelectionEndBlock = !0;
159
+ continue;
160
+ }
161
+ if (foundSelectionEndBlock) {
162
+ nextBlock = {
163
+ node: block,
164
+ path: [{
165
+ _key: block._key
166
+ }]
167
+ };
168
+ break;
169
+ }
170
+ }
171
+ if (foundSelectionEndBlock && nextBlock)
172
+ return nextBlock;
173
+ }, getSelectionEndPoint = (snapshot) => {
174
+ if (snapshot.context.selection)
175
+ return snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus;
176
+ }, getSelectionStartPoint = (snapshot) => {
177
+ if (snapshot.context.selection)
178
+ return snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor;
179
+ }, getNextInlineObject = (snapshot) => {
180
+ const focusTextBlock = getFocusTextBlock(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot), selectionEndPointChildKey = selectionEndPoint && isKeySegment(selectionEndPoint.path[2]) ? selectionEndPoint.path[2]._key : void 0;
181
+ if (!focusTextBlock || !selectionEndPointChildKey)
182
+ return;
183
+ let endPointChildFound = !1, inlineObject;
184
+ for (const child of focusTextBlock.node.children) {
185
+ if (child._key === selectionEndPointChildKey) {
186
+ endPointChildFound = !0;
187
+ continue;
188
+ }
189
+ if (!isSpan(snapshot.context, child) && endPointChildFound) {
190
+ inlineObject = {
191
+ node: child,
192
+ path: [...focusTextBlock.path, "children", {
193
+ _key: child._key
194
+ }]
195
+ };
196
+ break;
197
+ }
198
+ }
199
+ return inlineObject;
200
+ }, getPreviousInlineObject = (snapshot) => {
201
+ const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartPointChildKey = selectionStartPoint && isKeySegment(selectionStartPoint.path[2]) ? selectionStartPoint.path[2]._key : void 0;
202
+ if (!focusTextBlock || !selectionStartPointChildKey)
203
+ return;
204
+ let inlineObject;
205
+ for (const child of focusTextBlock.node.children) {
206
+ if (child._key === selectionStartPointChildKey)
207
+ break;
208
+ isSpan(snapshot.context, child) || (inlineObject = {
209
+ node: child,
210
+ path: [...focusTextBlock.path, "children", {
211
+ _key: child._key
212
+ }]
213
+ });
214
+ }
215
+ return inlineObject;
216
+ }, getSelectedSlice = (snapshot) => sliceBlocks({
217
+ blocks: snapshot.context.value,
218
+ selection: snapshot.context.selection
219
+ }), getSelectionText = (snapshot) => getSelectedSlice(snapshot).reduce((text, block) => isPortableTextTextBlock(block) ? text + block.children.reduce((text2, child) => isPortableTextSpan(child) ? text2 + child.text : text2, "") : text, ""), isSelectionCollapsed = (snapshot) => snapshot.context.selection ? JSON.stringify(snapshot.context.selection.anchor.path) === JSON.stringify(snapshot.context.selection.focus.path) && snapshot.context.selection?.anchor.offset === snapshot.context.selection?.focus.offset : !1, isSelectionExpanded = (snapshot) => !isSelectionCollapsed(snapshot), getCaretWordSelection = (snapshot) => {
220
+ if (!snapshot.context.selection || !isSelectionCollapsed(snapshot))
221
+ return null;
222
+ const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartOffset = selectionStartPoint ? spanSelectionPointToBlockOffset({
223
+ value: snapshot.context.value,
224
+ selectionPoint: selectionStartPoint
225
+ }) : void 0;
226
+ if (!focusTextBlock || !selectionStartPoint || !selectionStartOffset)
227
+ return null;
228
+ const previousInlineObject = getPreviousInlineObject(snapshot), blockStartPoint = getBlockStartPoint(focusTextBlock), textDirectlyBefore = getSelectionText({
229
+ context: {
230
+ ...snapshot.context,
231
+ selection: {
232
+ anchor: previousInlineObject ? {
233
+ path: previousInlineObject.path,
234
+ offset: 0
235
+ } : blockStartPoint,
236
+ focus: selectionStartPoint
174
237
  }
175
- if (block._key === endBlockKey)
176
- break;
177
238
  }
178
- const trimmedSelection = snapshot.context.selection.backward ? {
179
- anchor: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint,
180
- focus: adjustedStartPoint ?? startPoint,
181
- backward: !0
182
- } : {
183
- anchor: adjustedStartPoint ?? startPoint,
184
- focus: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint
239
+ }).split(/\s+/).at(-1), nextInlineObject = getNextInlineObject(snapshot), blockEndPoint = getBlockEndPoint(focusTextBlock), textDirectlyAfter = getSelectionText({
240
+ context: {
241
+ ...snapshot.context,
242
+ selection: {
243
+ anchor: selectionStartPoint,
244
+ focus: nextInlineObject ? {
245
+ path: nextInlineObject.path,
246
+ offset: 0
247
+ } : blockEndPoint
248
+ }
249
+ }
250
+ }).split(/\s+/).at(0);
251
+ if ((textDirectlyBefore === void 0 || textDirectlyBefore === "") && (textDirectlyAfter === void 0 || textDirectlyAfter === ""))
252
+ return null;
253
+ const caretWordStartOffset = textDirectlyBefore ? {
254
+ ...selectionStartOffset,
255
+ offset: selectionStartOffset.offset - textDirectlyBefore.length
256
+ } : selectionStartOffset, caretWordEndOffset = textDirectlyAfter ? {
257
+ ...selectionStartOffset,
258
+ offset: selectionStartOffset.offset + textDirectlyAfter.length
259
+ } : selectionStartOffset, caretWordStartSelectionPoint = blockOffsetToSpanSelectionPoint({
260
+ value: snapshot.context.value,
261
+ blockOffset: caretWordStartOffset,
262
+ direction: "backward"
263
+ }), caretWordEndSelectionPoint = blockOffsetToSpanSelectionPoint({
264
+ value: snapshot.context.value,
265
+ blockOffset: caretWordEndOffset,
266
+ direction: "forward"
267
+ });
268
+ if (!caretWordStartSelectionPoint || !caretWordEndSelectionPoint)
269
+ return null;
270
+ const caretWordSelection = {
271
+ anchor: caretWordStartSelectionPoint,
272
+ focus: caretWordEndSelectionPoint
185
273
  };
186
- if (isSelectionCollapsed({
274
+ return isSelectionExpanded({
187
275
  context: {
188
276
  ...snapshot.context,
189
- selection: trimmedSelection
277
+ selection: caretWordSelection
190
278
  }
191
- })) {
192
- const focusTextBlock = getFocusTextBlock({
193
- context: {
194
- ...snapshot.context,
195
- selection: trimmedSelection
196
- }
197
- });
198
- if (focusTextBlock && !isEmptyTextBlock(focusTextBlock.node))
199
- return null;
200
- }
201
- return trimmedSelection;
279
+ }) ? caretWordSelection : null;
202
280
  };
203
- function isActiveAnnotation(annotation) {
281
+ function isAtTheEndOfBlock(block) {
204
282
  return (snapshot) => {
205
- if (!snapshot.context.selection)
283
+ if (!snapshot.context.selection || !isSelectionCollapsed(snapshot))
206
284
  return !1;
207
- const selectedBlocks = getSelectedBlocks(snapshot), focusSpan = getFocusSpan(snapshot), selectedSpans = isSelectionExpanded(snapshot) ? getSelectedSpans(snapshot) : focusSpan ? [focusSpan] : [];
208
- if (selectedSpans.length === 0 || selectedSpans.some((span) => !span.node.marks || span.node.marks?.length === 0))
209
- return !1;
210
- const selectionMarkDefs = selectedBlocks.flatMap((block) => isPortableTextTextBlock(block.node) ? block.node.markDefs ?? [] : []);
211
- return selectedSpans.every((span) => (span.node.marks?.flatMap((mark) => {
212
- const markDef = selectionMarkDefs.find((markDef2) => markDef2._key === mark);
213
- return markDef ? [markDef._type] : [];
214
- }) ?? []).includes(annotation));
285
+ const blockEndPoint = getBlockEndPoint(block);
286
+ return isEqualSelectionPoints(snapshot.context.selection.focus, blockEndPoint);
215
287
  };
216
288
  }
217
- function isActiveDecorator(decorator) {
289
+ function isAtTheStartOfBlock(block) {
218
290
  return (snapshot) => {
219
- if (isSelectionExpanded(snapshot)) {
220
- const selectedSpans = getSelectedSpans(snapshot);
221
- return selectedSpans.length > 0 && selectedSpans.every((span) => span.node.marks?.includes(decorator));
222
- }
223
- return snapshot.context.activeDecorators.includes(decorator);
291
+ if (!snapshot.context.selection || !isSelectionCollapsed(snapshot))
292
+ return !1;
293
+ const blockStartPoint = getBlockStartPoint(block);
294
+ return isEqualSelectionPoints(snapshot.context.selection.focus, blockStartPoint);
224
295
  };
225
296
  }
226
- function isActiveListItem(listItem) {
227
- return (snapshot) => getActiveListItem(snapshot) === listItem;
228
- }
229
- function isActiveStyle(style) {
230
- return (snapshot) => getActiveStyle(snapshot) === style;
231
- }
232
297
  function isPointAfterSelection(point) {
233
298
  return (snapshot) => {
234
299
  if (!snapshot.context.selection)
@@ -357,17 +422,33 @@ function isOverlappingSelection(selection) {
357
422
  };
358
423
  }
359
424
  export {
360
- getActiveListItem,
361
- getActiveStyle,
362
- getSelectedSpans,
363
- getTrimmedSelection,
364
- isActiveAnnotation,
365
- isActiveDecorator,
366
- isActiveListItem,
367
- isActiveStyle,
425
+ createGuards,
426
+ getCaretWordSelection,
427
+ getFirstBlock,
428
+ getFocusBlock,
429
+ getFocusBlockObject,
430
+ getFocusChild,
431
+ getFocusListBlock,
432
+ getFocusSpan,
433
+ getFocusTextBlock,
434
+ getLastBlock,
435
+ getNextBlock,
436
+ getNextInlineObject,
437
+ getPreviousBlock,
438
+ getPreviousInlineObject,
439
+ getSelectedBlocks,
440
+ getSelectedSlice,
441
+ getSelectionEndBlock,
442
+ getSelectionEndPoint,
443
+ getSelectionStartBlock,
444
+ getSelectionStartPoint,
445
+ getSelectionText,
446
+ isAtTheEndOfBlock,
447
+ isAtTheStartOfBlock,
368
448
  isOverlappingSelection,
369
449
  isPointAfterSelection,
370
450
  isPointBeforeSelection,
371
- isSelectingEntireBlocks
451
+ isSelectionCollapsed,
452
+ isSelectionExpanded
372
453
  };
373
454
  //# sourceMappingURL=selector.is-overlapping-selection.js.map