@portabletext/editor 1.37.0 → 1.38.1

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 (109) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +84 -49
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/editor-provider.cjs +868 -534
  4. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  5. package/lib/_chunks-cjs/{util.block-offsets-to-selection.cjs → parse-blocks.cjs} +36 -21
  6. package/lib/_chunks-cjs/parse-blocks.cjs.map +1 -0
  7. package/lib/_chunks-cjs/selector.get-text-before.cjs +2 -2
  8. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  9. package/lib/_chunks-cjs/{selector.is-active-style.cjs → selector.is-overlapping-selection.cjs} +144 -3
  10. package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -0
  11. package/lib/_chunks-cjs/util.slice-blocks.cjs +12 -0
  12. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  13. package/lib/_chunks-es/behavior.core.js +84 -49
  14. package/lib/_chunks-es/behavior.core.js.map +1 -1
  15. package/lib/_chunks-es/editor-provider.js +858 -523
  16. package/lib/_chunks-es/editor-provider.js.map +1 -1
  17. package/lib/_chunks-es/{util.block-offsets-to-selection.js → parse-blocks.js} +37 -22
  18. package/lib/_chunks-es/parse-blocks.js.map +1 -0
  19. package/lib/_chunks-es/selector.get-text-before.js +1 -2
  20. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  21. package/lib/_chunks-es/{selector.is-active-style.js → selector.is-overlapping-selection.js} +146 -5
  22. package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -0
  23. package/lib/_chunks-es/util.slice-blocks.js +12 -0
  24. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  25. package/lib/behaviors/index.d.cts +10534 -4689
  26. package/lib/behaviors/index.d.ts +10534 -4689
  27. package/lib/index.cjs +578 -209
  28. package/lib/index.cjs.map +1 -1
  29. package/lib/index.d.cts +5296 -1178
  30. package/lib/index.d.ts +5296 -1178
  31. package/lib/index.js +587 -213
  32. package/lib/index.js.map +1 -1
  33. package/lib/plugins/index.cjs +2 -2
  34. package/lib/plugins/index.cjs.map +1 -1
  35. package/lib/plugins/index.d.cts +5296 -1178
  36. package/lib/plugins/index.d.ts +5296 -1178
  37. package/lib/plugins/index.js +1 -1
  38. package/lib/selectors/index.cjs +15 -152
  39. package/lib/selectors/index.cjs.map +1 -1
  40. package/lib/selectors/index.d.cts +5296 -1178
  41. package/lib/selectors/index.d.ts +5296 -1178
  42. package/lib/selectors/index.js +7 -145
  43. package/lib/selectors/index.js.map +1 -1
  44. package/lib/utils/index.cjs +4 -4
  45. package/lib/utils/index.cjs.map +1 -1
  46. package/lib/utils/index.d.cts +5296 -1178
  47. package/lib/utils/index.d.ts +5296 -1178
  48. package/lib/utils/index.js +3 -4
  49. package/lib/utils/index.js.map +1 -1
  50. package/package.json +16 -15
  51. package/src/behavior-actions/behavior.action.blur.ts +8 -0
  52. package/src/behavior-actions/behavior.action.decorator.add.ts +1 -1
  53. package/src/behavior-actions/behavior.action.delete.backward.ts +7 -0
  54. package/src/behavior-actions/behavior.action.delete.block.ts +24 -0
  55. package/src/behavior-actions/behavior.action.delete.forward.ts +7 -0
  56. package/src/behavior-actions/behavior.action.delete.text.ts +1 -1
  57. package/src/behavior-actions/behavior.action.deserialization.failure.ts +9 -0
  58. package/src/behavior-actions/behavior.action.deserialization.success.ts +16 -0
  59. package/src/behavior-actions/behavior.action.effect.ts +7 -0
  60. package/src/behavior-actions/behavior.action.focus.ts +8 -0
  61. package/src/behavior-actions/behavior.action.insert-blocks.ts +118 -139
  62. package/src/behavior-actions/behavior.action.insert-break.ts +1 -0
  63. package/src/behavior-actions/{behavior.action.insert-block-object.ts → behavior.action.insert.block-object.ts} +9 -14
  64. package/src/behavior-actions/behavior.action.insert.block.ts +247 -2
  65. package/src/behavior-actions/behavior.action.insert.text-block.ts +33 -0
  66. package/src/behavior-actions/behavior.action.insert.text.ts +7 -0
  67. package/src/behavior-actions/behavior.action.move.block-down.ts +48 -0
  68. package/src/behavior-actions/behavior.action.move.block-up.ts +53 -0
  69. package/src/behavior-actions/behavior.action.move.block.ts +16 -0
  70. package/src/behavior-actions/behavior.action.noop.ts +5 -0
  71. package/src/behavior-actions/behavior.action.select.next-block.ts +44 -0
  72. package/src/behavior-actions/behavior.action.select.previous-block.ts +48 -0
  73. package/src/behavior-actions/behavior.action.select.ts +15 -0
  74. package/src/behavior-actions/behavior.action.serialization.failure.ts +9 -0
  75. package/src/behavior-actions/behavior.action.serialization.success.ts +14 -0
  76. package/src/behavior-actions/behavior.actions.ts +54 -212
  77. package/src/behaviors/behavior.core.block-objects.ts +35 -6
  78. package/src/behaviors/behavior.core.insert-break.ts +1 -0
  79. package/src/behaviors/behavior.core.ts +2 -0
  80. package/src/behaviors/behavior.default.ts +241 -33
  81. package/src/behaviors/behavior.types.ts +138 -20
  82. package/src/converters/converter.portable-text.ts +5 -2
  83. package/src/converters/converter.text-html.serialize.test.ts +4 -4
  84. package/src/converters/converter.text-html.ts +5 -2
  85. package/src/converters/converter.text-plain.test.ts +6 -6
  86. package/src/converters/converter.text-plain.ts +5 -2
  87. package/src/converters/converter.types.ts +3 -3
  88. package/src/editor/Editable.tsx +401 -48
  89. package/src/editor/components/Element.tsx +133 -18
  90. package/src/editor/components/use-draggable.ts +34 -102
  91. package/src/editor/editor-machine.ts +50 -7
  92. package/src/editor/editor-selector.ts +1 -0
  93. package/src/editor/editor-snapshot.ts +13 -0
  94. package/src/editor/plugins/create-with-event-listeners.ts +6 -40
  95. package/src/internal-utils/create-test-snapshot.ts +1 -0
  96. package/src/internal-utils/event-position.ts +210 -0
  97. package/src/internal-utils/slate-utils.ts +56 -0
  98. package/src/internal-utils/weakMaps.ts +1 -15
  99. package/lib/_chunks-cjs/selector.is-active-style.cjs.map +0 -1
  100. package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs.map +0 -1
  101. package/lib/_chunks-cjs/util.reverse-selection.cjs +0 -14
  102. package/lib/_chunks-cjs/util.reverse-selection.cjs.map +0 -1
  103. package/lib/_chunks-es/selector.is-active-style.js.map +0 -1
  104. package/lib/_chunks-es/util.block-offsets-to-selection.js.map +0 -1
  105. package/lib/_chunks-es/util.reverse-selection.js +0 -15
  106. package/lib/_chunks-es/util.reverse-selection.js.map +0 -1
  107. package/src/behavior-actions/behavior.action-utils.insert-block.ts +0 -61
  108. package/src/editor/__tests__/handleClick.test.tsx +0 -277
  109. package/src/editor/components/use-droppable.ts +0 -135
@@ -5,7 +5,7 @@ import { useActorRef } from "@xstate/react";
5
5
  import isEqual from "lodash/isEqual.js";
6
6
  import { setup, fromCallback, assign } from "xstate";
7
7
  import { spanSelectionPointToBlockOffset, getBlockStartPoint, getBlockEndPoint, isEqualSelectionPoints } from "../_chunks-es/util.slice-blocks.js";
8
- import { blockOffsetsToSelection } from "../_chunks-es/util.block-offsets-to-selection.js";
8
+ import { blockOffsetsToSelection } from "../_chunks-es/parse-blocks.js";
9
9
  import { childSelectionPointToBlockOffset, isTextBlock, splitTextBlock, mergeTextBlocks } from "../utils/index.js";
10
10
  import { getFocusTextBlock, getPreviousInlineObject, getSelectionStartPoint, isSelectionExpanded, getSelectionEndPoint } from "../_chunks-es/selector.is-at-the-start-of-block.js";
11
11
  import { getBlockTextBefore } from "../_chunks-es/selector.get-text-before.js";
@@ -1,18 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"), selector_isAtTheStartOfBlock = require("../_chunks-cjs/selector.is-at-the-start-of-block.cjs"), types = require("@sanity/types"), selector_isActiveStyle = require("../_chunks-cjs/selector.is-active-style.cjs"), selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs"), util_reverseSelection = require("../_chunks-cjs/util.reverse-selection.cjs");
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 = selector_isAtTheStartOfBlock.getSelectionStartBlock(snapshot), endBlock = selector_isAtTheStartOfBlock.getSelectionEndBlock(snapshot);
8
- if (!startBlock || !endBlock)
9
- return !1;
10
- const startBlockStartPoint = util_sliceBlocks.getBlockStartPoint(startBlock), endBlockEndPoint = util_sliceBlocks.getBlockEndPoint(endBlock);
11
- return util_sliceBlocks.isEqualSelectionPoints(startBlockStartPoint, startPoint) && util_sliceBlocks.isEqualSelectionPoints(endBlockEndPoint, endPoint);
12
- }, getActiveAnnotations = (snapshot) => {
3
+ var selector_isOverlappingSelection = require("../_chunks-cjs/selector.is-overlapping-selection.cjs"), types = require("@sanity/types"), selector_isAtTheStartOfBlock = require("../_chunks-cjs/selector.is-at-the-start-of-block.cjs"), util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"), selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs");
4
+ const getActiveAnnotations = (snapshot) => {
13
5
  if (!snapshot.context.selection)
14
6
  return [];
15
- const selectedBlocks = selector_isAtTheStartOfBlock.getSelectedBlocks(snapshot), selectedSpans = selector_isActiveStyle.getSelectedSpans(snapshot);
7
+ const selectedBlocks = selector_isAtTheStartOfBlock.getSelectedBlocks(snapshot), selectedSpans = selector_isOverlappingSelection.getSelectedSpans(snapshot);
16
8
  return selectedSpans.length === 0 ? [] : selectedBlocks.flatMap((block) => types.isPortableTextTextBlock(block.node) ? block.node.markDefs ?? [] : []).filter((markDef) => selectedSpans.some((span) => span.node.marks?.includes(markDef._key)));
17
9
  }, getAnchorBlock = (snapshot) => {
18
10
  const key = snapshot.context.selection && 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;
@@ -69,135 +61,18 @@ const isSelectingEntireBlocks = (snapshot) => {
69
61
  path: focusChild.path
70
62
  } : void 0;
71
63
  }, getSelection = (snapshot) => snapshot.context.selection, getValue = (snapshot) => snapshot.context.value;
72
- function isPointAfterSelection(point) {
73
- return (snapshot) => {
74
- if (!snapshot.context.selection)
75
- return !1;
76
- const selection = snapshot.context.selection.backward ? util_reverseSelection.reverseSelection(snapshot.context.selection) : snapshot.context.selection, pointBlockKey = types.isKeySegment(point.path[0]) ? point.path[0]._key : void 0, pointChildKey = types.isKeySegment(point.path[2]) ? point.path[2]._key : void 0, endBlockKey = types.isKeySegment(selection.focus.path[0]) ? selection.focus.path[0]._key : void 0, endChildKey = types.isKeySegment(selection.focus.path[2]) ? selection.focus.path[2]._key : void 0;
77
- if (!pointBlockKey || !endBlockKey)
78
- return !1;
79
- let after = !1;
80
- for (const block of snapshot.context.value) {
81
- if (block._key === endBlockKey) {
82
- if (block._key !== pointBlockKey) {
83
- after = !0;
84
- break;
85
- }
86
- if (!types.isPortableTextTextBlock(block) || !pointChildKey || !endChildKey)
87
- break;
88
- for (const child of block.children) {
89
- if (child._key === endChildKey) {
90
- if (child._key !== pointChildKey) {
91
- after = !0;
92
- break;
93
- }
94
- after = point.offset > selection.focus.offset;
95
- break;
96
- }
97
- if (child._key === pointChildKey)
98
- break;
99
- }
100
- }
101
- if (block._key === pointBlockKey)
102
- break;
103
- }
104
- return after;
105
- };
106
- }
107
- function isPointBeforeSelection(point) {
108
- return (snapshot) => {
109
- if (!snapshot.context.selection)
110
- return !1;
111
- const selection = snapshot.context.selection.backward ? util_reverseSelection.reverseSelection(snapshot.context.selection) : snapshot.context.selection, pointBlockKey = types.isKeySegment(point.path[0]) ? point.path[0]._key : void 0, pointChildKey = types.isKeySegment(point.path[2]) ? point.path[2]._key : void 0, startBlockKey = types.isKeySegment(selection.anchor.path[0]) ? selection.anchor.path[0]._key : void 0, startChildKey = types.isKeySegment(selection.anchor.path[2]) ? selection.anchor.path[2]._key : void 0;
112
- if (!pointBlockKey || !startBlockKey)
113
- return !1;
114
- let before = !1;
115
- for (const block of snapshot.context.value) {
116
- if (block._key === pointBlockKey) {
117
- if (block._key !== startBlockKey) {
118
- before = !0;
119
- break;
120
- }
121
- if (!types.isPortableTextTextBlock(block) || !pointChildKey || !startChildKey)
122
- break;
123
- for (const child of block.children) {
124
- if (child._key === pointChildKey) {
125
- if (child._key !== startChildKey) {
126
- before = !0;
127
- break;
128
- }
129
- before = point.offset < selection.anchor.offset;
130
- break;
131
- }
132
- if (child._key === startChildKey)
133
- break;
134
- }
135
- }
136
- if (block._key === startBlockKey)
137
- break;
138
- }
139
- return before;
140
- };
141
- }
142
- function isOverlappingSelection(selection) {
143
- return (snapshot) => {
144
- if (!selection || !snapshot.context.selection)
145
- return !1;
146
- const selectionStartPoint = selector_isAtTheStartOfBlock.getSelectionStartPoint({
147
- ...snapshot,
148
- context: {
149
- ...snapshot.context,
150
- selection
151
- }
152
- }), selectionEndPoint = selector_isAtTheStartOfBlock.getSelectionEndPoint({
153
- ...snapshot,
154
- context: {
155
- ...snapshot.context,
156
- selection
157
- }
158
- }), originalSelectionStartPoint = selector_isAtTheStartOfBlock.getSelectionStartPoint(snapshot), originalSelectionEndPoint = selector_isAtTheStartOfBlock.getSelectionEndPoint(snapshot);
159
- if (!selectionStartPoint || !selectionEndPoint || !originalSelectionStartPoint || !originalSelectionEndPoint)
160
- return !1;
161
- const startPointBeforeSelection = isPointBeforeSelection(selectionStartPoint)(snapshot), startPointAfterSelection = isPointAfterSelection(selectionStartPoint)(snapshot), endPointBeforeSelection = isPointBeforeSelection(selectionEndPoint)(snapshot), endPointAfterSelection = isPointAfterSelection(selectionEndPoint)(snapshot), originalStartPointBeforeStartPoint = isPointBeforeSelection(originalSelectionStartPoint)({
162
- ...snapshot,
163
- context: {
164
- ...snapshot.context,
165
- selection: {
166
- anchor: selectionStartPoint,
167
- focus: selectionStartPoint
168
- }
169
- }
170
- }), originalStartPointAfterStartPoint = isPointAfterSelection(originalSelectionStartPoint)({
171
- ...snapshot,
172
- context: {
173
- ...snapshot.context,
174
- selection: {
175
- anchor: selectionStartPoint,
176
- focus: selectionStartPoint
177
- }
178
- }
179
- }), originalEndPointBeforeEndPoint = isPointBeforeSelection(originalSelectionEndPoint)({
180
- ...snapshot,
181
- context: {
182
- ...snapshot.context,
183
- selection: {
184
- anchor: selectionEndPoint,
185
- focus: selectionEndPoint
186
- }
187
- }
188
- }), originalEndPointAfterEndPoint = isPointAfterSelection(originalSelectionEndPoint)({
189
- ...snapshot,
190
- context: {
191
- ...snapshot.context,
192
- selection: {
193
- anchor: selectionEndPoint,
194
- focus: selectionEndPoint
195
- }
196
- }
197
- }), endPointEqualToOriginalStartPoint = util_sliceBlocks.isEqualSelectionPoints(selectionEndPoint, originalSelectionStartPoint), startPointEqualToOriginalEndPoint = util_sliceBlocks.isEqualSelectionPoints(selectionStartPoint, originalSelectionEndPoint);
198
- return endPointBeforeSelection && !endPointEqualToOriginalStartPoint || startPointAfterSelection && !startPointEqualToOriginalEndPoint ? !1 : !originalStartPointBeforeStartPoint && originalStartPointAfterStartPoint && !originalEndPointBeforeEndPoint && originalEndPointAfterEndPoint ? !endPointEqualToOriginalStartPoint : originalStartPointBeforeStartPoint && !originalStartPointAfterStartPoint && originalEndPointBeforeEndPoint && !originalEndPointAfterEndPoint ? !startPointEqualToOriginalEndPoint : !startPointAfterSelection || !startPointBeforeSelection || !endPointAfterSelection || !endPointBeforeSelection;
199
- };
200
- }
64
+ exports.getActiveListItem = selector_isOverlappingSelection.getActiveListItem;
65
+ exports.getActiveStyle = selector_isOverlappingSelection.getActiveStyle;
66
+ exports.getSelectedSpans = selector_isOverlappingSelection.getSelectedSpans;
67
+ exports.getTrimmedSelection = selector_isOverlappingSelection.getTrimmedSelection;
68
+ exports.isActiveAnnotation = selector_isOverlappingSelection.isActiveAnnotation;
69
+ exports.isActiveDecorator = selector_isOverlappingSelection.isActiveDecorator;
70
+ exports.isActiveListItem = selector_isOverlappingSelection.isActiveListItem;
71
+ exports.isActiveStyle = selector_isOverlappingSelection.isActiveStyle;
72
+ exports.isOverlappingSelection = selector_isOverlappingSelection.isOverlappingSelection;
73
+ exports.isPointAfterSelection = selector_isOverlappingSelection.isPointAfterSelection;
74
+ exports.isPointBeforeSelection = selector_isOverlappingSelection.isPointBeforeSelection;
75
+ exports.isSelectingEntireBlocks = selector_isOverlappingSelection.isSelectingEntireBlocks;
201
76
  exports.getCaretWordSelection = selector_isAtTheStartOfBlock.getCaretWordSelection;
202
77
  exports.getFirstBlock = selector_isAtTheStartOfBlock.getFirstBlock;
203
78
  exports.getFocusBlock = selector_isAtTheStartOfBlock.getFocusBlock;
@@ -222,14 +97,6 @@ exports.isAtTheEndOfBlock = selector_isAtTheStartOfBlock.isAtTheEndOfBlock;
222
97
  exports.isAtTheStartOfBlock = selector_isAtTheStartOfBlock.isAtTheStartOfBlock;
223
98
  exports.isSelectionCollapsed = selector_isAtTheStartOfBlock.isSelectionCollapsed;
224
99
  exports.isSelectionExpanded = selector_isAtTheStartOfBlock.isSelectionExpanded;
225
- exports.getActiveListItem = selector_isActiveStyle.getActiveListItem;
226
- exports.getActiveStyle = selector_isActiveStyle.getActiveStyle;
227
- exports.getSelectedSpans = selector_isActiveStyle.getSelectedSpans;
228
- exports.getTrimmedSelection = selector_isActiveStyle.getTrimmedSelection;
229
- exports.isActiveAnnotation = selector_isActiveStyle.isActiveAnnotation;
230
- exports.isActiveDecorator = selector_isActiveStyle.isActiveDecorator;
231
- exports.isActiveListItem = selector_isActiveStyle.isActiveListItem;
232
- exports.isActiveStyle = selector_isActiveStyle.isActiveStyle;
233
100
  exports.getBlockTextBefore = selector_getTextBefore.getBlockTextBefore;
234
101
  exports.getActiveAnnotations = getActiveAnnotations;
235
102
  exports.getAnchorBlock = getAnchorBlock;
@@ -240,8 +107,4 @@ exports.getBlockOffsets = getBlockOffsets;
240
107
  exports.getFocusInlineObject = getFocusInlineObject;
241
108
  exports.getSelection = getSelection;
242
109
  exports.getValue = getValue;
243
- exports.isOverlappingSelection = isOverlappingSelection;
244
- exports.isPointAfterSelection = isPointAfterSelection;
245
- exports.isPointBeforeSelection = isPointBeforeSelection;
246
- exports.isSelectingEntireBlocks = isSelectingEntireBlocks;
247
110
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.is-selecting-entire-blocks.ts","../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-focus-inline-object.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts","../../src/selectors/selector.is-point-after-selection.ts","../../src/selectors/selector.is-point-before-selection.ts","../../src/selectors/selector.is-overlapping-selection.ts"],"sourcesContent":["import type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {getSelectionEndBlock, getSelectionStartBlock} from './selectors'\n\n/**\n * @public\n */\nexport const isSelectingEntireBlocks: EditorSelector<boolean> = (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const startPoint = snapshot.context.selection.backward\n ? snapshot.context.selection.focus\n : snapshot.context.selection.anchor\n const endPoint = snapshot.context.selection.backward\n ? snapshot.context.selection.anchor\n : snapshot.context.selection.focus\n\n const startBlock = getSelectionStartBlock(snapshot)\n const endBlock = getSelectionEndBlock(snapshot)\n\n if (!startBlock || !endBlock) {\n return false\n }\n\n const startBlockStartPoint = utils.getBlockStartPoint(startBlock)\n const endBlockEndPoint = utils.getBlockEndPoint(endBlock)\n\n return (\n utils.isEqualSelectionPoints(startBlockStartPoint, startPoint) &&\n utils.isEqualSelectionPoints(endBlockEndPoint, endPoint)\n )\n}\n","import {isPortableTextTextBlock, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveAnnotations: EditorSelector<Array<PortableTextObject>> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const selectedSpans = getSelectedSpans(snapshot)\n\n if (selectedSpans.length === 0) {\n return []\n }\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isPortableTextTextBlock(block.node) ? (block.node.markDefs ?? []) : [],\n )\n\n return selectionMarkDefs.filter((markDef) =>\n selectedSpans.some((span) => span.node.marks?.includes(markDef._key)),\n )\n}\n","import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isPortableTextTextBlock(anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[2])\n ? snapshot.context.selection.anchor.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n value: snapshot.context.value,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n value: snapshot.context.value,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import {\n isPortableTextSpan,\n type KeyedSegment,\n type PortableTextObject,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getFocusChild} from './selectors'\n\n/**\n * @public\n */\nexport const getFocusInlineObject: EditorSelector<\n | {node: PortableTextObject; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const focusChild = getFocusChild(snapshot)\n\n return focusChild && !isPortableTextSpan(focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n","import {isKeySegment, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {reverseSelection} from '../utils/util.reverse-selection'\n\n/**\n * @public\n */\nexport function isPointAfterSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selection = snapshot.context.selection.backward\n ? reverseSelection(snapshot.context.selection)\n : snapshot.context.selection\n\n const pointBlockKey = isKeySegment(point.path[0])\n ? point.path[0]._key\n : undefined\n const pointChildKey = isKeySegment(point.path[2])\n ? point.path[2]._key\n : undefined\n\n const endBlockKey = isKeySegment(selection.focus.path[0])\n ? selection.focus.path[0]._key\n : undefined\n const endChildKey = isKeySegment(selection.focus.path[2])\n ? selection.focus.path[2]._key\n : undefined\n\n if (!pointBlockKey || !endBlockKey) {\n return false\n }\n\n let after = false\n\n for (const block of snapshot.context.value) {\n if (block._key === endBlockKey) {\n if (block._key !== pointBlockKey) {\n after = true\n break\n }\n\n // Both the point and the selection end in this block\n\n if (!isPortableTextTextBlock(block)) {\n break\n }\n\n if (!pointChildKey || !endChildKey) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === endChildKey) {\n if (child._key !== pointChildKey) {\n after = true\n break\n }\n\n // Both the point and the selection end in this child\n\n after = point.offset > selection.focus.offset\n break\n }\n\n if (child._key === pointChildKey) {\n break\n }\n }\n }\n\n if (block._key === pointBlockKey) {\n break\n }\n }\n\n return after\n }\n}\n","import {isKeySegment, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {reverseSelection} from '../utils/util.reverse-selection'\n\n/**\n * @public\n */\nexport function isPointBeforeSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selection = snapshot.context.selection.backward\n ? reverseSelection(snapshot.context.selection)\n : snapshot.context.selection\n\n const pointBlockKey = isKeySegment(point.path[0])\n ? point.path[0]._key\n : undefined\n const pointChildKey = isKeySegment(point.path[2])\n ? point.path[2]._key\n : undefined\n\n const startBlockKey = isKeySegment(selection.anchor.path[0])\n ? selection.anchor.path[0]._key\n : undefined\n const startChildKey = isKeySegment(selection.anchor.path[2])\n ? selection.anchor.path[2]._key\n : undefined\n\n if (!pointBlockKey || !startBlockKey) {\n return false\n }\n\n let before = false\n\n for (const block of snapshot.context.value) {\n if (block._key === pointBlockKey) {\n if (block._key !== startBlockKey) {\n before = true\n break\n }\n\n // Both the point and the selection start in this block\n\n if (!isPortableTextTextBlock(block)) {\n break\n }\n\n if (!pointChildKey || !startChildKey) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === pointChildKey) {\n if (child._key !== startChildKey) {\n before = true\n break\n }\n\n // Both the point and the selection start in this child\n\n before = point.offset < selection.anchor.offset\n break\n }\n\n if (child._key === startChildKey) {\n break\n }\n }\n }\n\n if (block._key === startBlockKey) {\n break\n }\n }\n\n return before\n }\n}\n","import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from '../utils'\nimport type {EditorSelector} from './../editor/editor-selector'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {isPointAfterSelection} from './selector.is-point-after-selection'\nimport {isPointBeforeSelection} from './selector.is-point-before-selection'\n\n/**\n * @public\n */\nexport function isOverlappingSelection(\n selection: EditorSelection,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!selection || !snapshot.context.selection) {\n return false\n }\n\n const selectionStartPoint = getSelectionStartPoint({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n const selectionEndPoint = getSelectionEndPoint({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n const originalSelectionStartPoint = getSelectionStartPoint(snapshot)\n const originalSelectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (\n !selectionStartPoint ||\n !selectionEndPoint ||\n !originalSelectionStartPoint ||\n !originalSelectionEndPoint\n ) {\n return false\n }\n\n const startPointBeforeSelection =\n isPointBeforeSelection(selectionStartPoint)(snapshot)\n const startPointAfterSelection =\n isPointAfterSelection(selectionStartPoint)(snapshot)\n const endPointBeforeSelection =\n isPointBeforeSelection(selectionEndPoint)(snapshot)\n const endPointAfterSelection =\n isPointAfterSelection(selectionEndPoint)(snapshot)\n\n const originalStartPointBeforeStartPoint = isPointBeforeSelection(\n originalSelectionStartPoint,\n )({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: selectionStartPoint,\n focus: selectionStartPoint,\n },\n },\n })\n const originalStartPointAfterStartPoint = isPointAfterSelection(\n originalSelectionStartPoint,\n )({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: selectionStartPoint,\n focus: selectionStartPoint,\n },\n },\n })\n\n const originalEndPointBeforeEndPoint = isPointBeforeSelection(\n originalSelectionEndPoint,\n )({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: selectionEndPoint,\n focus: selectionEndPoint,\n },\n },\n })\n const originalEndPointAfterEndPoint = isPointAfterSelection(\n originalSelectionEndPoint,\n )({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: selectionEndPoint,\n focus: selectionEndPoint,\n },\n },\n })\n\n const endPointEqualToOriginalStartPoint = isEqualSelectionPoints(\n selectionEndPoint,\n originalSelectionStartPoint,\n )\n const startPointEqualToOriginalEndPoint = isEqualSelectionPoints(\n selectionStartPoint,\n originalSelectionEndPoint,\n )\n\n if (endPointBeforeSelection && !endPointEqualToOriginalStartPoint) {\n return false\n }\n\n if (startPointAfterSelection && !startPointEqualToOriginalEndPoint) {\n return false\n }\n\n if (\n !originalStartPointBeforeStartPoint &&\n originalStartPointAfterStartPoint &&\n !originalEndPointBeforeEndPoint &&\n originalEndPointAfterEndPoint\n ) {\n return !endPointEqualToOriginalStartPoint\n }\n\n if (\n originalStartPointBeforeStartPoint &&\n !originalStartPointAfterStartPoint &&\n originalEndPointBeforeEndPoint &&\n !originalEndPointAfterEndPoint\n ) {\n return !startPointEqualToOriginalEndPoint\n }\n\n if (\n !startPointAfterSelection ||\n !startPointBeforeSelection ||\n !endPointAfterSelection ||\n !endPointBeforeSelection\n ) {\n return true\n }\n\n return false\n }\n}\n"],"names":["isSelectingEntireBlocks","snapshot","context","selection","startPoint","backward","focus","anchor","endPoint","startBlock","getSelectionStartBlock","endBlock","getSelectionEndBlock","startBlockStartPoint","utils","endBlockEndPoint","isEqualSelectionPoints","getActiveAnnotations","selectedBlocks","getSelectedBlocks","selectedSpans","getSelectedSpans","length","flatMap","block","isPortableTextTextBlock","node","markDefs","filter","markDef","some","span","marks","includes","_key","getAnchorBlock","key","isKeyedSegment","path","undefined","value","find","getAnchorTextBlock","anchorBlock","getAnchorChild","children","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","selectionPoint","end","getFocusInlineObject","focusChild","getFocusChild","getSelection","getValue","isPointAfterSelection","point","reverseSelection","pointBlockKey","isKeySegment","pointChildKey","endBlockKey","endChildKey","after","child","offset","isPointBeforeSelection","startBlockKey","startChildKey","before","isOverlappingSelection","originalSelectionStartPoint","originalSelectionEndPoint","startPointBeforeSelection","startPointAfterSelection","endPointBeforeSelection","endPointAfterSelection","originalStartPointBeforeStartPoint","originalStartPointAfterStartPoint","originalEndPointBeforeEndPoint","originalEndPointAfterEndPoint","endPointEqualToOriginalStartPoint","startPointEqualToOriginalEndPoint"],"mappings":";;;AAOO,MAAMA,0BAAoDC,CAAa,aAAA;AACxE,MAAA,CAACA,SAASC,QAAQC;AACb,WAAA;AAGT,QAAMC,aAAaH,SAASC,QAAQC,UAAUE,WAC1CJ,SAASC,QAAQC,UAAUG,QAC3BL,SAASC,QAAQC,UAAUI,QACzBC,WAAWP,SAASC,QAAQC,UAAUE,WACxCJ,SAASC,QAAQC,UAAUI,SAC3BN,SAASC,QAAQC,UAAUG,OAEzBG,aAAaC,oDAAuBT,QAAQ,GAC5CU,WAAWC,kDAAqBX,QAAQ;AAE1C,MAAA,CAACQ,cAAc,CAACE;AACX,WAAA;AAGHE,QAAAA,uBAAuBC,iBAAAA,mBAAyBL,UAAU,GAC1DM,mBAAmBD,kCAAuBH,QAAQ;AAGtDG,SAAAA,iBAAAA,uBAA6BD,sBAAsBT,UAAU,KAC7DU,iBAAME,uBAAuBD,kBAAkBP,QAAQ;AAE3D,GCzBaS,uBACXhB,CACG,aAAA;AACC,MAAA,CAACA,SAASC,QAAQC;AACpB,WAAO,CAAE;AAGX,QAAMe,iBAAiBC,6BAAAA,kBAAkBlB,QAAQ,GAC3CmB,gBAAgBC,wCAAiBpB,QAAQ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ACT;AAAA,IAEH,CAAA,GAEKoC,iCAAiCb,uBACrCM,yBACF,EAAE;AAAA,MACA,GAAG9E;AAAAA,MACHC,SAAS;AAAA,QACP,GAAGD,SAASC;AAAAA,QACZC,WAAW;AAAA,UACTI,QAAQ6C;AAAAA,UACR9C,OAAO8C;AAAAA,QAAAA;AAAAA,MACT;AAAA,IAEH,CAAA,GACKmC,gCAAgCzB,sBACpCiB,yBACF,EAAE;AAAA,MACA,GAAG9E;AAAAA,MACHC,SAAS;AAAA,QACP,GAAGD,SAASC;AAAAA,QACZC,WAAW;AAAA,UACTI,QAAQ6C;AAAAA,UACR9C,OAAO8C;AAAAA,QAAAA;AAAAA,MACT;AAAA,IACF,CACD,GAEKoC,oCAAoCxE,iBACxCoC,uBAAAA,mBACA0B,2BACF,GACMW,oCAAoCzE,iBAAAA,uBACxCkC,qBACA6B,yBACF;AAMA,WAJIG,2BAA2B,CAACM,qCAI5BP,4BAA4B,CAACQ,oCACxB,KAIP,CAACL,sCACDC,qCACA,CAACC,kCACDC,gCAEO,CAACC,oCAIRJ,sCACA,CAACC,qCACDC,kCACA,CAACC,gCAEM,CAACE,oCAIR,CAACR,4BACD,CAACD,6BACD,CAACG,0BACD,CAACD;AAAAA,EAML;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-focus-inline-object.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import {isPortableTextTextBlock, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveAnnotations: EditorSelector<Array<PortableTextObject>> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const selectedSpans = getSelectedSpans(snapshot)\n\n if (selectedSpans.length === 0) {\n return []\n }\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isPortableTextTextBlock(block.node) ? (block.node.markDefs ?? []) : [],\n )\n\n return selectionMarkDefs.filter((markDef) =>\n selectedSpans.some((span) => span.node.marks?.includes(markDef._key)),\n )\n}\n","import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[0])\n ? snapshot.context.selection.anchor.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isPortableTextTextBlock(anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = snapshot.context.selection\n ? isKeyedSegment(snapshot.context.selection.anchor.path[2])\n ? snapshot.context.selection.anchor.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n value: snapshot.context.value,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n value: snapshot.context.value,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import {\n isPortableTextSpan,\n type KeyedSegment,\n type PortableTextObject,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getFocusChild} from './selectors'\n\n/**\n * @public\n */\nexport const getFocusInlineObject: EditorSelector<\n | {node: PortableTextObject; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const focusChild = getFocusChild(snapshot)\n\n return focusChild && !isPortableTextSpan(focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n"],"names":["getActiveAnnotations","snapshot","context","selection","selectedBlocks","getSelectedBlocks","selectedSpans","getSelectedSpans","length","flatMap","block","isPortableTextTextBlock","node","markDefs","filter","markDef","some","span","marks","includes","_key","getAnchorBlock","key","isKeyedSegment","anchor","path","undefined","value","find","getAnchorTextBlock","anchorBlock","getAnchorChild","children","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getFocusInlineObject","focusChild","getFocusChild","getSelection","getValue"],"mappings":";;;AAQO,MAAMA,uBACXC,CACG,aAAA;AACC,MAAA,CAACA,SAASC,QAAQC;AACpB,WAAO,CAAE;AAGX,QAAMC,iBAAiBC,6BAAAA,kBAAkBJ,QAAQ,GAC3CK,gBAAgBC,iDAAiBN,QAAQ;AAE/C,SAAIK,cAAcE,WAAW,IACpB,KAGiBJ,eAAeK,QAASC,CAChDC,UAAAA,MAAA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