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