@portabletext/editor 1.49.1 → 1.49.3

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 (95) hide show
  1. package/lib/_chunks-cjs/selector.get-text-before.cjs +2 -2
  2. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +40 -230
  4. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
  5. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs +201 -0
  6. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -0
  7. package/lib/_chunks-cjs/use-editor.cjs +28 -0
  8. package/lib/_chunks-cjs/use-editor.cjs.map +1 -0
  9. package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs +79 -0
  10. package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs.map +1 -0
  11. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs +34 -0
  12. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +1 -0
  13. package/lib/_chunks-cjs/util.merge-text-blocks.cjs +2 -1
  14. package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
  15. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +6 -78
  16. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
  17. package/lib/_chunks-cjs/util.slice-blocks.cjs +26 -39
  18. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  19. package/lib/_chunks-es/selector.get-text-before.js +1 -1
  20. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +13 -201
  21. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
  22. package/lib/_chunks-es/selector.is-selection-expanded.js +203 -0
  23. package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -0
  24. package/lib/_chunks-es/use-editor.js +25 -0
  25. package/lib/_chunks-es/use-editor.js.map +1 -0
  26. package/lib/_chunks-es/util.child-selection-point-to-block-offset.js +80 -0
  27. package/lib/_chunks-es/util.child-selection-point-to-block-offset.js.map +1 -0
  28. package/lib/_chunks-es/util.is-equal-selection-points.js +35 -0
  29. package/lib/_chunks-es/util.is-equal-selection-points.js.map +1 -0
  30. package/lib/_chunks-es/util.merge-text-blocks.js +2 -1
  31. package/lib/_chunks-es/util.merge-text-blocks.js.map +1 -1
  32. package/lib/_chunks-es/util.selection-point-to-block-offset.js +6 -77
  33. package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
  34. package/lib/_chunks-es/util.slice-blocks.js +26 -39
  35. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  36. package/lib/index.cjs +9004 -292
  37. package/lib/index.cjs.map +1 -1
  38. package/lib/index.d.cts +2 -2
  39. package/lib/index.d.ts +2 -2
  40. package/lib/index.js +8947 -220
  41. package/lib/index.js.map +1 -1
  42. package/lib/plugins/index.cjs +23 -23
  43. package/lib/plugins/index.cjs.map +1 -1
  44. package/lib/plugins/index.js +3 -3
  45. package/lib/plugins/index.js.map +1 -1
  46. package/lib/selectors/index.cjs +22 -22
  47. package/lib/selectors/index.cjs.map +1 -1
  48. package/lib/selectors/index.js +4 -3
  49. package/lib/selectors/index.js.map +1 -1
  50. package/lib/utils/index.cjs +10 -10
  51. package/lib/utils/index.cjs.map +1 -1
  52. package/lib/utils/index.js +6 -4
  53. package/lib/utils/index.js.map +1 -1
  54. package/package.json +14 -14
  55. package/src/behaviors/behavior.abstract.split.ts +2 -2
  56. package/src/converters/converter.portable-text.ts +1 -0
  57. package/src/converters/converter.text-html.ts +1 -0
  58. package/src/converters/converter.text-plain.ts +1 -0
  59. package/src/editor/Editable.tsx +1 -0
  60. package/src/editor/components/render-element.tsx +3 -3
  61. package/src/editor/create-editor.ts +2 -58
  62. package/src/editor/editor-context.tsx +1 -1
  63. package/src/editor/editor-provider.tsx +4 -31
  64. package/src/editor/editor-selector.ts +2 -1
  65. package/src/editor/use-editor.ts +27 -0
  66. package/src/editor-event-listener.tsx +1 -1
  67. package/src/editor.ts +57 -0
  68. package/src/index.ts +9 -9
  69. package/src/internal-utils/parse-blocks.test.ts +20 -20
  70. package/src/internal-utils/parse-blocks.ts +57 -20
  71. package/src/internal-utils/text-selection.test.ts +11 -0
  72. package/src/operations/behavior.operation.annotation.add.ts +1 -1
  73. package/src/operations/behavior.operation.block.set.ts +1 -1
  74. package/src/operations/behavior.operation.block.unset.ts +2 -2
  75. package/src/operations/behavior.operation.insert-inline-object.ts +1 -1
  76. package/src/operations/behavior.operation.insert.block.ts +1 -1
  77. package/src/plugins/plugin.behavior.tsx +1 -1
  78. package/src/plugins/plugin.decorator-shortcut.ts +2 -2
  79. package/src/plugins/plugin.editor-ref.tsx +2 -2
  80. package/src/plugins/plugin.event-listener.tsx +1 -1
  81. package/src/plugins/plugin.markdown.tsx +1 -1
  82. package/src/selectors/selector.get-trimmed-selection.test.ts +1 -0
  83. package/src/utils/util.merge-text-blocks.ts +1 -1
  84. package/lib/_chunks-cjs/editor-provider.cjs +0 -8745
  85. package/lib/_chunks-cjs/editor-provider.cjs.map +0 -1
  86. package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs +0 -11
  87. package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs.map +0 -1
  88. package/lib/_chunks-cjs/util.is-selection-collapsed.cjs +0 -6
  89. package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +0 -1
  90. package/lib/_chunks-es/editor-provider.js +0 -8771
  91. package/lib/_chunks-es/editor-provider.js.map +0 -1
  92. package/lib/_chunks-es/selector.get-focus-inline-object.js +0 -13
  93. package/lib/_chunks-es/selector.get-focus-inline-object.js.map +0 -1
  94. package/lib/_chunks-es/util.is-selection-collapsed.js +0 -7
  95. package/lib/_chunks-es/util.is-selection-collapsed.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- var util_sliceBlocks = require("./util.slice-blocks.cjs"), selector_isSelectingEntireBlocks = require("./selector.is-selecting-entire-blocks.cjs");
2
+ var util_sliceBlocks = require("./util.slice-blocks.cjs"), selector_isSelectionExpanded = require("./selector.is-selection-expanded.cjs");
3
3
  const getBlockTextBefore = (snapshot) => {
4
4
  if (!snapshot.context.selection)
5
5
  return "";
@@ -15,7 +15,7 @@ const getBlockTextBefore = (snapshot) => {
15
15
  }]
16
16
  }
17
17
  });
18
- return selector_isSelectingEntireBlocks.getSelectionText({
18
+ return selector_isSelectionExpanded.getSelectionText({
19
19
  context: {
20
20
  ...snapshot.context,
21
21
  selection: {
@@ -1 +1 @@
1
- {"version":3,"file":"selector.get-text-before.cjs","sources":["../../src/selectors/selector.get-text-before.ts"],"sourcesContent":["import type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {reverseSelection} from '../utils/util.reverse-selection'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @public\n */\nexport const getBlockTextBefore: EditorSelector<string> = (snapshot) => {\n if (!snapshot.context.selection) {\n return ''\n }\n\n const selection = snapshot.context.selection.backward\n ? reverseSelection(snapshot.context.selection)\n : snapshot.context.selection\n const point = selection.anchor\n const key = isKeyedSegment(point.path[0]) ? point.path[0]._key : undefined\n\n const block = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n if (!block) {\n return ''\n }\n\n const startOfBlock = getBlockStartPoint({\n context: snapshot.context,\n block: {\n node: block,\n path: [{_key: block._key}],\n },\n })\n\n return getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startOfBlock,\n focus: point,\n },\n },\n })\n}\n"],"names":["getBlockTextBefore","snapshot","context","selection","point","backward","reverseSelection","anchor","key","isKeyedSegment","path","_key","undefined","block","value","find","startOfBlock","getBlockStartPoint","node","getSelectionText","focus"],"mappings":";;AASO,MAAMA,qBAA8CC,CAAa,aAAA;AAClE,MAAA,CAACA,SAASC,QAAQC;AACb,WAAA;AAMT,QAAMC,SAHYH,SAASC,QAAQC,UAAUE,WACzCC,kCAAiBL,SAASC,QAAQC,SAAS,IAC3CF,SAASC,QAAQC,WACGI,QAClBC,MAAMC,iBAAAA,eAAeL,MAAMM,KAAK,CAAC,CAAC,IAAIN,MAAMM,KAAK,CAAC,EAAEC,OAAOC,QAE3DC,QAAQL,MACVP,SAASC,QAAQY,MAAMC,KAAMF,CAAAA,WAAUA,OAAMF,SAASH,GAAG,IACzDI;AAEJ,MAAI,CAACC;AACI,WAAA;AAGT,QAAMG,eAAeC,iBAAAA,mBAAmB;AAAA,IACtCf,SAASD,SAASC;AAAAA,IAClBW,OAAO;AAAA,MACLK,MAAML;AAAAA,MACNH,MAAM,CAAC;AAAA,QAACC,MAAME,MAAMF;AAAAA,MAAK,CAAA;AAAA,IAAA;AAAA,EAC3B,CACD;AAED,SAAOQ,kDAAiB;AAAA,IAEtBjB,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTI,QAAQS;AAAAA,QACRI,OAAOhB;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AACH;;"}
1
+ {"version":3,"file":"selector.get-text-before.cjs","sources":["../../src/selectors/selector.get-text-before.ts"],"sourcesContent":["import type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {reverseSelection} from '../utils/util.reverse-selection'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @public\n */\nexport const getBlockTextBefore: EditorSelector<string> = (snapshot) => {\n if (!snapshot.context.selection) {\n return ''\n }\n\n const selection = snapshot.context.selection.backward\n ? reverseSelection(snapshot.context.selection)\n : snapshot.context.selection\n const point = selection.anchor\n const key = isKeyedSegment(point.path[0]) ? point.path[0]._key : undefined\n\n const block = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n if (!block) {\n return ''\n }\n\n const startOfBlock = getBlockStartPoint({\n context: snapshot.context,\n block: {\n node: block,\n path: [{_key: block._key}],\n },\n })\n\n return getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startOfBlock,\n focus: point,\n },\n },\n })\n}\n"],"names":["getBlockTextBefore","snapshot","context","selection","point","backward","reverseSelection","anchor","key","isKeyedSegment","path","_key","undefined","block","value","find","startOfBlock","getBlockStartPoint","node","getSelectionText","focus"],"mappings":";;AASO,MAAMA,qBAA8CC,CAAa,aAAA;AAClE,MAAA,CAACA,SAASC,QAAQC;AACb,WAAA;AAMT,QAAMC,SAHYH,SAASC,QAAQC,UAAUE,WACzCC,kCAAiBL,SAASC,QAAQC,SAAS,IAC3CF,SAASC,QAAQC,WACGI,QAClBC,MAAMC,iBAAAA,eAAeL,MAAMM,KAAK,CAAC,CAAC,IAAIN,MAAMM,KAAK,CAAC,EAAEC,OAAOC,QAE3DC,QAAQL,MACVP,SAASC,QAAQY,MAAMC,KAAMF,CAAAA,WAAUA,OAAMF,SAASH,GAAG,IACzDI;AAEJ,MAAI,CAACC;AACI,WAAA;AAGT,QAAMG,eAAeC,iBAAAA,mBAAmB;AAAA,IACtCf,SAASD,SAASC;AAAAA,IAClBW,OAAO;AAAA,MACLK,MAAML;AAAAA,MACNH,MAAM,CAAC;AAAA,QAACC,MAAME,MAAMF;AAAAA,MAAK,CAAA;AAAA,IAAA;AAAA,EAC3B,CACD;AAED,SAAOQ,8CAAiB;AAAA,IAEtBjB,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTI,QAAQS;AAAAA,QACRI,OAAOhB;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AACH;;"}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- var util_sliceBlocks = require("./util.slice-blocks.cjs"), types = require("@sanity/types");
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
3
  const getSelectedSpans = (snapshot) => {
4
4
  if (!snapshot.context.selection)
5
5
  return [];
@@ -86,169 +86,13 @@ const getSelectedSpans = (snapshot) => {
86
86
  });
87
87
  }
88
88
  return selectedSpans;
89
- }, 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, getFocusBlock = (snapshot) => {
90
- const key = snapshot.context.selection && util_sliceBlocks.isKeyedSegment(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;
91
- return node && key ? {
92
- node,
93
- path: [{
94
- _key: key
95
- }]
96
- } : void 0;
97
- }, getFocusListBlock = (snapshot) => {
98
- const focusTextBlock = getFocusTextBlock(snapshot);
99
- return focusTextBlock && util_sliceBlocks.isListBlock(snapshot.context, focusTextBlock.node) ? {
100
- node: focusTextBlock.node,
101
- path: focusTextBlock.path
102
- } : void 0;
103
- }, getFocusTextBlock = (snapshot) => {
104
- const focusBlock = getFocusBlock(snapshot);
105
- return focusBlock && util_sliceBlocks.isTextBlock(snapshot.context, focusBlock.node) ? {
106
- node: focusBlock.node,
107
- path: focusBlock.path
108
- } : void 0;
109
- }, getFocusBlockObject = (snapshot) => {
110
- const focusBlock = getFocusBlock(snapshot);
111
- return focusBlock && !util_sliceBlocks.isTextBlock(snapshot.context, focusBlock.node) ? {
112
- node: focusBlock.node,
113
- path: focusBlock.path
114
- } : void 0;
115
- }, getFocusChild = (snapshot) => {
116
- const focusBlock = getFocusTextBlock(snapshot);
117
- if (!focusBlock)
118
- return;
119
- const key = snapshot.context.selection && util_sliceBlocks.isKeyedSegment(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;
120
- return node && key ? {
121
- node,
122
- path: [...focusBlock.path, "children", {
123
- _key: key
124
- }]
125
- } : void 0;
126
- }, getFocusSpan = (snapshot) => {
127
- const focusChild = getFocusChild(snapshot);
128
- return focusChild && util_sliceBlocks.isSpan$1(snapshot.context, focusChild.node) ? {
129
- node: focusChild.node,
130
- path: focusChild.path
131
- } : void 0;
132
- }, getFirstBlock = (snapshot) => {
133
- const node = snapshot.context.value[0];
134
- return node ? {
135
- node,
136
- path: [{
137
- _key: node._key
138
- }]
139
- } : void 0;
140
- }, getLastBlock = (snapshot) => {
141
- const node = snapshot.context.value[snapshot.context.value.length - 1] ? snapshot.context.value[snapshot.context.value.length - 1] : void 0;
142
- return node ? {
143
- node,
144
- path: [{
145
- _key: node._key
146
- }]
147
- } : void 0;
148
- }, getSelectedBlocks = (snapshot) => {
149
- if (!snapshot.context.selection)
150
- return [];
151
- const selectedBlocks = [], startKey = snapshot.context.selection.backward ? util_sliceBlocks.isKeyedSegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0 : util_sliceBlocks.isKeyedSegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0, endKey = snapshot.context.selection.backward ? util_sliceBlocks.isKeyedSegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0 : util_sliceBlocks.isKeyedSegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0;
152
- if (!startKey || !endKey)
153
- return selectedBlocks;
154
- for (const block of snapshot.context.value) {
155
- if (block._key === startKey) {
156
- if (selectedBlocks.push({
157
- node: block,
158
- path: [{
159
- _key: block._key
160
- }]
161
- }), startKey === endKey)
162
- break;
163
- continue;
164
- }
165
- if (block._key === endKey) {
166
- selectedBlocks.push({
167
- node: block,
168
- path: [{
169
- _key: block._key
170
- }]
171
- });
172
- break;
173
- }
174
- selectedBlocks.length > 0 && selectedBlocks.push({
175
- node: block,
176
- path: [{
177
- _key: block._key
178
- }]
179
- });
180
- }
181
- return selectedBlocks;
182
- }, getSelectionStartBlock = (snapshot) => {
183
- if (!snapshot.context.selection)
184
- return;
185
- const key = snapshot.context.selection.backward ? util_sliceBlocks.isKeyedSegment(snapshot.context.selection.focus.path[0]) ? snapshot.context.selection.focus.path[0]._key : void 0 : util_sliceBlocks.isKeyedSegment(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;
186
- return node && key ? {
187
- node,
188
- path: [{
189
- _key: key
190
- }]
191
- } : void 0;
192
- }, getSelectionEndBlock = (snapshot) => {
193
- if (!snapshot.context.selection)
194
- return;
195
- const key = snapshot.context.selection.backward ? util_sliceBlocks.isKeyedSegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0 : util_sliceBlocks.isKeyedSegment(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;
196
- return node && key ? {
197
- node,
198
- path: [{
199
- _key: key
200
- }]
201
- } : void 0;
202
- }, getPreviousBlock = (snapshot) => {
203
- let previousBlock;
204
- const selectionStartBlock = getSelectionStartBlock(snapshot);
205
- if (!selectionStartBlock)
206
- return;
207
- let foundSelectionStartBlock = !1;
208
- for (const block of snapshot.context.value) {
209
- if (block._key === selectionStartBlock.node._key) {
210
- foundSelectionStartBlock = !0;
211
- break;
212
- }
213
- previousBlock = {
214
- node: block,
215
- path: [{
216
- _key: block._key
217
- }]
218
- };
219
- }
220
- if (foundSelectionStartBlock && previousBlock)
221
- return previousBlock;
222
- }, getNextBlock = (snapshot) => {
223
- let nextBlock;
224
- const selectionEndBlock = getSelectionEndBlock(snapshot);
225
- if (!selectionEndBlock)
226
- return;
227
- let foundSelectionEndBlock = !1;
228
- for (const block of snapshot.context.value) {
229
- if (block._key === selectionEndBlock.node._key) {
230
- foundSelectionEndBlock = !0;
231
- continue;
232
- }
233
- if (foundSelectionEndBlock) {
234
- nextBlock = {
235
- node: block,
236
- path: [{
237
- _key: block._key
238
- }]
239
- };
240
- break;
241
- }
242
- }
243
- if (foundSelectionEndBlock && nextBlock)
244
- return nextBlock;
245
89
  }, getActiveAnnotations = (snapshot) => {
246
90
  if (!snapshot.context.selection)
247
91
  return [];
248
- const selectedBlocks = getSelectedBlocks(snapshot), selectedSpans = getSelectedSpans(snapshot), focusSpan = getFocusSpan(snapshot);
92
+ const selectedBlocks = selector_isSelectionExpanded.getSelectedBlocks(snapshot), selectedSpans = getSelectedSpans(snapshot), focusSpan = selector_isSelectionExpanded.getFocusSpan(snapshot);
249
93
  if (selectedSpans.length === 0 || !focusSpan)
250
94
  return [];
251
- if (selectedSpans.length === 1 && isSelectionCollapsed(snapshot)) {
95
+ if (selectedSpans.length === 1 && selector_isSelectionExpanded.isSelectionCollapsed(snapshot)) {
252
96
  if (snapshot.context.selection.focus.offset === 0)
253
97
  return [];
254
98
  if (snapshot.context.selection.focus.offset === focusSpan.node.text.length)
@@ -258,7 +102,7 @@ const getSelectedSpans = (snapshot) => {
258
102
  }, getActiveListItem = (snapshot) => {
259
103
  if (!snapshot.context.selection)
260
104
  return;
261
- const selectedTextBlocks = getSelectedBlocks(snapshot).map((block) => block.node).filter((block) => util_sliceBlocks.isTextBlock(snapshot.context, block)), firstTextBlock = selectedTextBlocks.at(0);
105
+ const selectedTextBlocks = selector_isSelectionExpanded.getSelectedBlocks(snapshot).map((block) => block.node).filter((block) => util_sliceBlocks.isTextBlock(snapshot.context, block)), firstTextBlock = selectedTextBlocks.at(0);
262
106
  if (!firstTextBlock)
263
107
  return;
264
108
  const firstListItem = firstTextBlock.listItem;
@@ -267,7 +111,7 @@ const getSelectedSpans = (snapshot) => {
267
111
  }, getActiveStyle = (snapshot) => {
268
112
  if (!snapshot.context.selection)
269
113
  return;
270
- const selectedTextBlocks = getSelectedBlocks(snapshot).map((block) => block.node).filter((block) => util_sliceBlocks.isTextBlock(snapshot.context, block)), firstTextBlock = selectedTextBlocks.at(0);
114
+ const selectedTextBlocks = selector_isSelectionExpanded.getSelectedBlocks(snapshot).map((block) => block.node).filter((block) => util_sliceBlocks.isTextBlock(snapshot.context, block)), firstTextBlock = selectedTextBlocks.at(0);
271
115
  if (!firstTextBlock)
272
116
  return;
273
117
  const firstStyle = firstTextBlock.style;
@@ -276,11 +120,8 @@ const getSelectedSpans = (snapshot) => {
276
120
  }, getSelectionEndPoint = (snapshot) => {
277
121
  if (snapshot.context.selection)
278
122
  return snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus;
279
- }, getSelectionStartPoint = (snapshot) => {
280
- if (snapshot.context.selection)
281
- return snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor;
282
123
  }, getNextInlineObject = (snapshot) => {
283
- const focusTextBlock = getFocusTextBlock(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot), selectionEndPointChildKey = selectionEndPoint && types.isKeySegment(selectionEndPoint.path[2]) ? selectionEndPoint.path[2]._key : void 0;
124
+ const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot), selectionEndPointChildKey = selectionEndPoint && types.isKeySegment(selectionEndPoint.path[2]) ? selectionEndPoint.path[2]._key : void 0;
284
125
  if (!focusTextBlock || !selectionEndPointChildKey)
285
126
  return;
286
127
  let endPointChildFound = !1, inlineObject;
@@ -300,38 +141,19 @@ const getSelectedSpans = (snapshot) => {
300
141
  }
301
142
  }
302
143
  return inlineObject;
303
- }, getPreviousInlineObject = (snapshot) => {
304
- const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartPointChildKey = selectionStartPoint && types.isKeySegment(selectionStartPoint.path[2]) ? selectionStartPoint.path[2]._key : void 0;
305
- if (!focusTextBlock || !selectionStartPointChildKey)
306
- return;
307
- let inlineObject;
308
- for (const child of focusTextBlock.node.children) {
309
- if (child._key === selectionStartPointChildKey)
310
- break;
311
- util_sliceBlocks.isSpan(snapshot.context, child) || (inlineObject = {
312
- node: child,
313
- path: [...focusTextBlock.path, "children", {
314
- _key: child._key
315
- }]
316
- });
317
- }
318
- return inlineObject;
319
- }, getSelectedSlice = (snapshot) => util_sliceBlocks.sliceBlocks({
320
- context: snapshot.context,
321
- blocks: snapshot.context.value
322
- }), getSelectionText = (snapshot) => getSelectedSlice(snapshot).reduce((text, block) => util_sliceBlocks.isTextBlock(snapshot.context, block) ? text + block.children.reduce((text2, child) => util_sliceBlocks.isSpan$1(snapshot.context, child) ? text2 + child.text : text2, "") : text, ""), isSelectionExpanded = (snapshot) => !isSelectionCollapsed(snapshot), getCaretWordSelection = (snapshot) => {
323
- if (!snapshot.context.selection || !isSelectionCollapsed(snapshot))
144
+ }, getCaretWordSelection = (snapshot) => {
145
+ if (!snapshot.context.selection || !selector_isSelectionExpanded.isSelectionCollapsed(snapshot))
324
146
  return null;
325
- const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartOffset = selectionStartPoint ? util_sliceBlocks.spanSelectionPointToBlockOffset({
147
+ const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot), selectionStartPoint = selector_isSelectionExpanded.getSelectionStartPoint(snapshot), selectionStartOffset = selectionStartPoint ? util_sliceBlocks.spanSelectionPointToBlockOffset({
326
148
  context: snapshot.context,
327
149
  selectionPoint: selectionStartPoint
328
150
  }) : void 0;
329
151
  if (!focusTextBlock || !selectionStartPoint || !selectionStartOffset)
330
152
  return null;
331
- const previousInlineObject = getPreviousInlineObject(snapshot), blockStartPoint = util_sliceBlocks.getBlockStartPoint({
153
+ const previousInlineObject = selector_isSelectionExpanded.getPreviousInlineObject(snapshot), blockStartPoint = util_sliceBlocks.getBlockStartPoint({
332
154
  context: snapshot.context,
333
155
  block: focusTextBlock
334
- }), textDirectlyBefore = getSelectionText({
156
+ }), textDirectlyBefore = selector_isSelectionExpanded.getSelectionText({
335
157
  context: {
336
158
  ...snapshot.context,
337
159
  selection: {
@@ -342,10 +164,10 @@ const getSelectedSpans = (snapshot) => {
342
164
  focus: selectionStartPoint
343
165
  }
344
166
  }
345
- }).split(/\s+/).at(-1), nextInlineObject = getNextInlineObject(snapshot), blockEndPoint = util_sliceBlocks.getBlockEndPoint({
167
+ }).split(/\s+/).at(-1), nextInlineObject = getNextInlineObject(snapshot), blockEndPoint = util_isEqualSelectionPoints.getBlockEndPoint({
346
168
  context: snapshot.context,
347
169
  block: focusTextBlock
348
- }), textDirectlyAfter = getSelectionText({
170
+ }), textDirectlyAfter = selector_isSelectionExpanded.getSelectionText({
349
171
  context: {
350
172
  ...snapshot.context,
351
173
  selection: {
@@ -380,12 +202,18 @@ const getSelectedSpans = (snapshot) => {
380
202
  anchor: caretWordStartSelectionPoint,
381
203
  focus: caretWordEndSelectionPoint
382
204
  };
383
- return isSelectionExpanded({
205
+ return selector_isSelectionExpanded.isSelectionExpanded({
384
206
  context: {
385
207
  ...snapshot.context,
386
208
  selection: caretWordSelection
387
209
  }
388
210
  }) ? caretWordSelection : null;
211
+ }, getFocusInlineObject = (snapshot) => {
212
+ const focusChild = selector_isSelectionExpanded.getFocusChild(snapshot);
213
+ return focusChild && !types.isPortableTextSpan(focusChild.node) ? {
214
+ node: focusChild.node,
215
+ path: focusChild.path
216
+ } : void 0;
389
217
  }, getSelectedTextBlocks = (snapshot) => {
390
218
  if (!snapshot.context.selection)
391
219
  return [];
@@ -423,7 +251,7 @@ const getSelectedSpans = (snapshot) => {
423
251
  }, getTrimmedSelection = (snapshot) => {
424
252
  if (!snapshot.context.selection)
425
253
  return snapshot.context.selection;
426
- const startPoint = getSelectionStartPoint(snapshot), endPoint = getSelectionEndPoint(snapshot);
254
+ const startPoint = selector_isSelectionExpanded.getSelectionStartPoint(snapshot), endPoint = getSelectionEndPoint(snapshot);
427
255
  if (!startPoint || !endPoint)
428
256
  return snapshot.context.selection;
429
257
  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;
@@ -431,8 +259,8 @@ const getSelectedSpans = (snapshot) => {
431
259
  return snapshot.context.selection;
432
260
  let startBlockFound = !1, adjustedStartPoint, trimStartPoint = !1, adjustedEndPoint, trimEndPoint = !1, previousPotentialEndpoint;
433
261
  for (const block of snapshot.context.value)
434
- if (!(block._key === startBlockKey && (startBlockFound = !0, util_sliceBlocks.isTextBlock(snapshot.context, block) && util_sliceBlocks.isEmptyTextBlock(snapshot.context, block))) && startBlockFound && util_sliceBlocks.isTextBlock(snapshot.context, block)) {
435
- if (block._key === endBlockKey && util_sliceBlocks.isEmptyTextBlock(snapshot.context, block))
262
+ 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)) {
263
+ if (block._key === endBlockKey && util_isEqualSelectionPoints.isEmptyTextBlock(snapshot.context, block))
436
264
  break;
437
265
  for (const child of block.children) {
438
266
  if (child._key === endChildKey && (!util_sliceBlocks.isSpan$1(snapshot.context, child) || endPoint.offset === 0)) {
@@ -490,19 +318,19 @@ const getSelectedSpans = (snapshot) => {
490
318
  anchor: adjustedStartPoint ?? startPoint,
491
319
  focus: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint
492
320
  };
493
- if (isSelectionCollapsed({
321
+ if (selector_isSelectionExpanded.isSelectionCollapsed({
494
322
  context: {
495
323
  ...snapshot.context,
496
324
  selection: trimmedSelection
497
325
  }
498
326
  })) {
499
- const focusTextBlock = getFocusTextBlock({
327
+ const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock({
500
328
  context: {
501
329
  ...snapshot.context,
502
330
  selection: trimmedSelection
503
331
  }
504
332
  });
505
- if (focusTextBlock && !util_sliceBlocks.isEmptyTextBlock(snapshot.context, focusTextBlock.node))
333
+ if (focusTextBlock && !util_isEqualSelectionPoints.isEmptyTextBlock(snapshot.context, focusTextBlock.node))
506
334
  return null;
507
335
  }
508
336
  return trimmedSelection;
@@ -511,7 +339,7 @@ function isActiveAnnotation(annotation) {
511
339
  return (snapshot) => {
512
340
  if (!snapshot.context.selection)
513
341
  return !1;
514
- const selectedBlocks = getSelectedBlocks(snapshot), focusSpan = getFocusSpan(snapshot), selectedSpans = isSelectionExpanded(snapshot) ? getSelectedSpans(snapshot) : focusSpan ? [focusSpan] : [];
342
+ const selectedBlocks = selector_isSelectionExpanded.getSelectedBlocks(snapshot), focusSpan = selector_isSelectionExpanded.getFocusSpan(snapshot), selectedSpans = selector_isSelectionExpanded.isSelectionExpanded(snapshot) ? getSelectedSpans(snapshot) : focusSpan ? [focusSpan] : [];
515
343
  if (selectedSpans.length === 0 || selectedSpans.some((span) => !span.node.marks || span.node.marks?.length === 0))
516
344
  return !1;
517
345
  const selectionMarkDefs = selectedBlocks.flatMap((block) => util_sliceBlocks.isTextBlock(snapshot.context, block.node) ? block.node.markDefs ?? [] : []);
@@ -523,7 +351,7 @@ function isActiveAnnotation(annotation) {
523
351
  }
524
352
  function isActiveDecorator(decorator) {
525
353
  return (snapshot) => {
526
- if (isSelectionExpanded(snapshot)) {
354
+ if (selector_isSelectionExpanded.isSelectionExpanded(snapshot)) {
527
355
  const selectedSpans = getSelectedSpans(snapshot);
528
356
  return selectedSpans.length > 0 && selectedSpans.every((span) => span.node.marks?.includes(decorator));
529
357
  }
@@ -538,24 +366,24 @@ function isActiveStyle(style) {
538
366
  }
539
367
  function isAtTheEndOfBlock(block) {
540
368
  return (snapshot) => {
541
- if (!snapshot.context.selection || !isSelectionCollapsed(snapshot))
369
+ if (!snapshot.context.selection || !selector_isSelectionExpanded.isSelectionCollapsed(snapshot))
542
370
  return !1;
543
- const blockEndPoint = util_sliceBlocks.getBlockEndPoint({
371
+ const blockEndPoint = util_isEqualSelectionPoints.getBlockEndPoint({
544
372
  context: snapshot.context,
545
373
  block
546
374
  });
547
- return util_sliceBlocks.isEqualSelectionPoints(snapshot.context.selection.focus, blockEndPoint);
375
+ return util_isEqualSelectionPoints.isEqualSelectionPoints(snapshot.context.selection.focus, blockEndPoint);
548
376
  };
549
377
  }
550
378
  function isAtTheStartOfBlock(block) {
551
379
  return (snapshot) => {
552
- if (!snapshot.context.selection || !isSelectionCollapsed(snapshot))
380
+ if (!snapshot.context.selection || !selector_isSelectionExpanded.isSelectionCollapsed(snapshot))
553
381
  return !1;
554
382
  const blockStartPoint = util_sliceBlocks.getBlockStartPoint({
555
383
  context: snapshot.context,
556
384
  block
557
385
  });
558
- return util_sliceBlocks.isEqualSelectionPoints(snapshot.context.selection.focus, blockStartPoint);
386
+ return util_isEqualSelectionPoints.isEqualSelectionPoints(snapshot.context.selection.focus, blockStartPoint);
559
387
  };
560
388
  }
561
389
  function isPointAfterSelection(point) {
@@ -632,7 +460,7 @@ function isOverlappingSelection(selection) {
632
460
  return (snapshot) => {
633
461
  if (!selection || !snapshot.context.selection)
634
462
  return !1;
635
- const selectionStartPoint = getSelectionStartPoint({
463
+ const selectionStartPoint = selector_isSelectionExpanded.getSelectionStartPoint({
636
464
  context: {
637
465
  ...snapshot.context,
638
466
  selection
@@ -642,7 +470,7 @@ function isOverlappingSelection(selection) {
642
470
  ...snapshot.context,
643
471
  selection
644
472
  }
645
- }), originalSelectionStartPoint = getSelectionStartPoint(snapshot), originalSelectionEndPoint = getSelectionEndPoint(snapshot);
473
+ }), originalSelectionStartPoint = selector_isSelectionExpanded.getSelectionStartPoint(snapshot), originalSelectionEndPoint = getSelectionEndPoint(snapshot);
646
474
  if (!selectionStartPoint || !selectionEndPoint || !originalSelectionStartPoint || !originalSelectionEndPoint)
647
475
  return !1;
648
476
  const startPointBeforeSelection = isPointBeforeSelection(selectionStartPoint)(snapshot), startPointAfterSelection = isPointAfterSelection(selectionStartPoint)(snapshot), endPointBeforeSelection = isPointBeforeSelection(selectionEndPoint)(snapshot), endPointAfterSelection = isPointAfterSelection(selectionEndPoint)(snapshot), originalStartPointBeforeStartPoint = isPointBeforeSelection(originalSelectionStartPoint)({
@@ -681,50 +509,34 @@ function isOverlappingSelection(selection) {
681
509
  focus: selectionEndPoint
682
510
  }
683
511
  }
684
- }), endPointEqualToOriginalStartPoint = util_sliceBlocks.isEqualSelectionPoints(selectionEndPoint, originalSelectionStartPoint), startPointEqualToOriginalEndPoint = util_sliceBlocks.isEqualSelectionPoints(selectionStartPoint, originalSelectionEndPoint);
512
+ }), endPointEqualToOriginalStartPoint = util_isEqualSelectionPoints.isEqualSelectionPoints(selectionEndPoint, originalSelectionStartPoint), startPointEqualToOriginalEndPoint = util_isEqualSelectionPoints.isEqualSelectionPoints(selectionStartPoint, originalSelectionEndPoint);
685
513
  return endPointBeforeSelection && !endPointEqualToOriginalStartPoint || startPointAfterSelection && !startPointEqualToOriginalEndPoint ? !1 : !originalStartPointBeforeStartPoint && originalStartPointAfterStartPoint && !originalEndPointBeforeEndPoint && originalEndPointAfterEndPoint ? !endPointEqualToOriginalStartPoint : originalStartPointBeforeStartPoint && !originalStartPointAfterStartPoint && originalEndPointBeforeEndPoint && !originalEndPointAfterEndPoint ? !startPointEqualToOriginalEndPoint : !startPointAfterSelection || !startPointBeforeSelection || !endPointAfterSelection || !endPointBeforeSelection;
686
514
  };
687
515
  }
688
516
  const isSelectingEntireBlocks = (snapshot) => {
689
517
  if (!snapshot.context.selection)
690
518
  return !1;
691
- 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);
519
+ 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_isSelectionExpanded.getSelectionStartBlock(snapshot), endBlock = selector_isSelectionExpanded.getSelectionEndBlock(snapshot);
692
520
  if (!startBlock || !endBlock)
693
521
  return !1;
694
522
  const startBlockStartPoint = util_sliceBlocks.getBlockStartPoint({
695
523
  context: snapshot.context,
696
524
  block: startBlock
697
- }), endBlockEndPoint = util_sliceBlocks.getBlockEndPoint({
525
+ }), endBlockEndPoint = util_isEqualSelectionPoints.getBlockEndPoint({
698
526
  context: snapshot.context,
699
527
  block: endBlock
700
528
  });
701
- return util_sliceBlocks.isEqualSelectionPoints(startBlockStartPoint, startPoint) && util_sliceBlocks.isEqualSelectionPoints(endBlockEndPoint, endPoint);
529
+ return util_isEqualSelectionPoints.isEqualSelectionPoints(startBlockStartPoint, startPoint) && util_isEqualSelectionPoints.isEqualSelectionPoints(endBlockEndPoint, endPoint);
702
530
  };
703
531
  exports.getActiveAnnotations = getActiveAnnotations;
704
532
  exports.getActiveListItem = getActiveListItem;
705
533
  exports.getActiveStyle = getActiveStyle;
706
534
  exports.getCaretWordSelection = getCaretWordSelection;
707
- exports.getFirstBlock = getFirstBlock;
708
- exports.getFocusBlock = getFocusBlock;
709
- exports.getFocusBlockObject = getFocusBlockObject;
710
- exports.getFocusChild = getFocusChild;
711
- exports.getFocusListBlock = getFocusListBlock;
712
- exports.getFocusSpan = getFocusSpan;
713
- exports.getFocusTextBlock = getFocusTextBlock;
714
- exports.getLastBlock = getLastBlock;
715
- exports.getNextBlock = getNextBlock;
535
+ exports.getFocusInlineObject = getFocusInlineObject;
716
536
  exports.getNextInlineObject = getNextInlineObject;
717
- exports.getPreviousBlock = getPreviousBlock;
718
- exports.getPreviousInlineObject = getPreviousInlineObject;
719
- exports.getSelectedBlocks = getSelectedBlocks;
720
- exports.getSelectedSlice = getSelectedSlice;
721
537
  exports.getSelectedSpans = getSelectedSpans;
722
538
  exports.getSelectedTextBlocks = getSelectedTextBlocks;
723
- exports.getSelectionEndBlock = getSelectionEndBlock;
724
539
  exports.getSelectionEndPoint = getSelectionEndPoint;
725
- exports.getSelectionStartBlock = getSelectionStartBlock;
726
- exports.getSelectionStartPoint = getSelectionStartPoint;
727
- exports.getSelectionText = getSelectionText;
728
540
  exports.getTrimmedSelection = getTrimmedSelection;
729
541
  exports.isActiveAnnotation = isActiveAnnotation;
730
542
  exports.isActiveDecorator = isActiveDecorator;
@@ -736,6 +548,4 @@ exports.isOverlappingSelection = isOverlappingSelection;
736
548
  exports.isPointAfterSelection = isPointAfterSelection;
737
549
  exports.isPointBeforeSelection = isPointBeforeSelection;
738
550
  exports.isSelectingEntireBlocks = isSelectingEntireBlocks;
739
- exports.isSelectionCollapsed = isSelectionCollapsed;
740
- exports.isSelectionExpanded = isSelectionExpanded;
741
551
  //# sourceMappingURL=selector.is-selecting-entire-blocks.cjs.map