@portabletext/editor 1.28.0 → 1.30.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 (61) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +40 -37
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/parse-blocks.cjs +79 -0
  4. package/lib/_chunks-cjs/parse-blocks.cjs.map +1 -0
  5. package/lib/_chunks-cjs/plugin.event-listener.cjs +55 -97
  6. package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -1
  7. package/lib/_chunks-cjs/selector.get-selection-start-point.cjs +15 -0
  8. package/lib/_chunks-cjs/selector.get-selection-start-point.cjs.map +1 -0
  9. package/lib/_chunks-es/behavior.core.js +40 -37
  10. package/lib/_chunks-es/behavior.core.js.map +1 -1
  11. package/lib/_chunks-es/parse-blocks.js +80 -0
  12. package/lib/_chunks-es/parse-blocks.js.map +1 -0
  13. package/lib/_chunks-es/plugin.event-listener.js +57 -98
  14. package/lib/_chunks-es/plugin.event-listener.js.map +1 -1
  15. package/lib/_chunks-es/selector.get-selection-start-point.js +16 -0
  16. package/lib/_chunks-es/selector.get-selection-start-point.js.map +1 -0
  17. package/lib/behaviors/index.d.cts +196 -124
  18. package/lib/behaviors/index.d.ts +196 -124
  19. package/lib/index.d.cts +248 -0
  20. package/lib/index.d.ts +248 -0
  21. package/lib/plugins/index.cjs +249 -1
  22. package/lib/plugins/index.cjs.map +1 -1
  23. package/lib/plugins/index.d.cts +246 -1
  24. package/lib/plugins/index.d.ts +246 -1
  25. package/lib/plugins/index.js +257 -3
  26. package/lib/plugins/index.js.map +1 -1
  27. package/lib/selectors/index.cjs +28 -1
  28. package/lib/selectors/index.cjs.map +1 -1
  29. package/lib/selectors/index.d.cts +21 -0
  30. package/lib/selectors/index.d.ts +21 -0
  31. package/lib/selectors/index.js +28 -0
  32. package/lib/selectors/index.js.map +1 -1
  33. package/lib/utils/index.cjs +70 -1
  34. package/lib/utils/index.cjs.map +1 -1
  35. package/lib/utils/index.d.cts +168 -2
  36. package/lib/utils/index.d.ts +168 -2
  37. package/lib/utils/index.js +71 -1
  38. package/lib/utils/index.js.map +1 -1
  39. package/package.json +5 -5
  40. package/src/behavior-actions/behavior.action.delete.ts +18 -0
  41. package/src/behavior-actions/behavior.action.insert-break.ts +3 -8
  42. package/src/behavior-actions/behavior.actions.ts +9 -0
  43. package/src/behaviors/_exports/index.ts +1 -0
  44. package/src/behaviors/behavior.core.deserialize.ts +52 -38
  45. package/src/behaviors/behavior.core.ts +4 -11
  46. package/src/behaviors/behavior.types.ts +4 -0
  47. package/src/editor/PortableTextEditor.tsx +20 -0
  48. package/src/internal-utils/__tests__/patchToOperations.test.ts +19 -21
  49. package/src/internal-utils/applyPatch.ts +11 -3
  50. package/src/plugins/index.ts +2 -0
  51. package/src/plugins/plugin.behavior.tsx +22 -0
  52. package/src/plugins/plugin.one-line.tsx +225 -0
  53. package/src/selectors/index.ts +3 -0
  54. package/src/selectors/selector.get-selection-end-point.ts +17 -0
  55. package/src/selectors/selector.get-selection-start-point.ts +17 -0
  56. package/src/selectors/selector.is-overlapping-selection.ts +46 -0
  57. package/src/utils/index.ts +4 -0
  58. package/src/utils/util.is-span.ts +12 -0
  59. package/src/utils/util.is-text-block.ts +12 -0
  60. package/src/utils/util.merge-text-blocks.ts +36 -0
  61. package/src/utils/util.split-text-block.ts +55 -0
@@ -1,8 +1,29 @@
1
- import { useEditor } from "../_chunks-es/plugin.event-listener.js";
2
- import { EventListenerPlugin } from "../_chunks-es/plugin.event-listener.js";
3
1
  import { c } from "react-compiler-runtime";
4
2
  import React, { useEffect } from "react";
3
+ import { useEditor } from "../_chunks-es/plugin.event-listener.js";
4
+ import { EventListenerPlugin } from "../_chunks-es/plugin.event-listener.js";
5
5
  import { createMarkdownBehaviors } from "../_chunks-es/behavior.markdown.js";
6
+ import { jsx } from "react/jsx-runtime";
7
+ import { isSelectionExpanded, getFocusTextBlock } from "../_chunks-es/selector.is-at-the-start-of-block.js";
8
+ import { getBlockStartPoint, getBlockEndPoint, isEqualSelectionPoints } from "../_chunks-es/util.is-equal-selection-points.js";
9
+ import { isTextBlock, splitTextBlock, mergeTextBlocks } from "../utils/index.js";
10
+ import { getSelectionStartPoint, getSelectionEndPoint } from "../_chunks-es/selector.get-selection-start-point.js";
11
+ import { defineBehavior, raise } from "../_chunks-es/behavior.core.js";
12
+ function BehaviorPlugin(props) {
13
+ const $ = c(4), editor = useEditor();
14
+ let t0, t1;
15
+ return $[0] !== editor || $[1] !== props.behaviors ? (t0 = () => {
16
+ const unregisterBehaviors = props.behaviors.map((behavior) => editor.registerBehavior({
17
+ behavior
18
+ }));
19
+ return () => {
20
+ unregisterBehaviors.forEach(_temp);
21
+ };
22
+ }, t1 = [editor, props.behaviors], $[0] = editor, $[1] = props.behaviors, $[2] = t0, $[3] = t1) : (t0 = $[2], t1 = $[3]), useEffect(t0, t1), null;
23
+ }
24
+ function _temp(unregister) {
25
+ return unregister();
26
+ }
6
27
  const EditorRefPlugin = React.forwardRef((_, ref) => {
7
28
  const $ = c(2), editor = useEditor(), portableTextEditorRef = React.useRef(editor);
8
29
  let t0, t1;
@@ -21,9 +42,242 @@ function MarkdownPlugin(props) {
21
42
  };
22
43
  }, [editor, props.config]), null;
23
44
  }
45
+ const oneLineBehaviors = [
46
+ /**
47
+ * Hitting Enter on an expanded selection should just delete that selection
48
+ * without causing a line break.
49
+ */
50
+ defineBehavior({
51
+ on: "insert.break",
52
+ guard: ({
53
+ context
54
+ }) => context.selection && isSelectionExpanded({
55
+ context
56
+ }) ? {
57
+ selection: context.selection
58
+ } : !1,
59
+ actions: [(_, {
60
+ selection
61
+ }) => [{
62
+ type: "delete",
63
+ selection
64
+ }]]
65
+ }),
66
+ /**
67
+ * All other cases of `insert.break` should be aborted.
68
+ */
69
+ defineBehavior({
70
+ on: "insert.break",
71
+ actions: [() => [{
72
+ type: "noop"
73
+ }]]
74
+ }),
75
+ /**
76
+ * `insert.block` `before` or `after` is not allowed in a one-line editor.
77
+ */
78
+ defineBehavior({
79
+ on: "insert.block",
80
+ guard: ({
81
+ event
82
+ }) => event.placement === "before" || event.placement === "after",
83
+ actions: [() => [{
84
+ type: "noop"
85
+ }]]
86
+ }),
87
+ /**
88
+ * Other cases of `insert.block` are allowed.
89
+ *
90
+ * If a text block is inserted and the focus block is fully selected, then
91
+ * the focus block can be replaced with the inserted block.
92
+ */
93
+ defineBehavior({
94
+ on: "insert.block",
95
+ guard: ({
96
+ context,
97
+ event
98
+ }) => {
99
+ const focusTextBlock = getFocusTextBlock({
100
+ context
101
+ }), selectionStartPoint = getSelectionStartPoint({
102
+ context
103
+ }), selectionEndPoint = getSelectionEndPoint({
104
+ context
105
+ });
106
+ if (!focusTextBlock || !isTextBlock(context, event.block) || !selectionStartPoint || !selectionEndPoint)
107
+ return !1;
108
+ const blockStartPoint = getBlockStartPoint(focusTextBlock), blockEndPoint = getBlockEndPoint(focusTextBlock), newFocus = getBlockEndPoint({
109
+ node: event.block,
110
+ path: [{
111
+ _key: event.block._key
112
+ }]
113
+ });
114
+ return isEqualSelectionPoints(blockStartPoint, selectionStartPoint) && isEqualSelectionPoints(blockEndPoint, selectionEndPoint) ? {
115
+ focusTextBlock,
116
+ newFocus
117
+ } : !1;
118
+ },
119
+ actions: [({
120
+ event
121
+ }, {
122
+ focusTextBlock,
123
+ newFocus
124
+ }) => [{
125
+ type: "delete.block",
126
+ blockPath: focusTextBlock.path
127
+ }, {
128
+ type: "insert.block",
129
+ block: event.block,
130
+ placement: "auto"
131
+ }, {
132
+ type: "select",
133
+ selection: {
134
+ anchor: newFocus,
135
+ focus: newFocus
136
+ }
137
+ }]]
138
+ }),
139
+ /**
140
+ * An ordinary `insert.block` is acceptable if it's a text block. In that
141
+ * case it will get merged into the existing text block.
142
+ */
143
+ defineBehavior({
144
+ on: "insert.block",
145
+ guard: ({
146
+ context,
147
+ event
148
+ }) => {
149
+ const focusTextBlock = getFocusTextBlock({
150
+ context
151
+ }), selectionStartPoint = getSelectionStartPoint({
152
+ context
153
+ }), selectionEndPoint = getSelectionEndPoint({
154
+ context
155
+ });
156
+ if (!focusTextBlock || !isTextBlock(context, event.block) || !selectionStartPoint || !selectionEndPoint)
157
+ return !1;
158
+ const blockBeforeStartPoint = splitTextBlock({
159
+ context,
160
+ block: focusTextBlock.node,
161
+ point: selectionStartPoint
162
+ })?.before, blockAfterEndPoint = splitTextBlock({
163
+ context,
164
+ block: focusTextBlock.node,
165
+ point: selectionEndPoint
166
+ })?.after;
167
+ if (!blockBeforeStartPoint || !blockAfterEndPoint)
168
+ return !1;
169
+ const targetBlock = mergeTextBlocks({
170
+ context,
171
+ targetBlock: blockBeforeStartPoint,
172
+ incomingBlock: event.block
173
+ }), newFocus = getBlockEndPoint({
174
+ node: targetBlock,
175
+ path: [{
176
+ _key: targetBlock._key
177
+ }]
178
+ }), mergedBlock = mergeTextBlocks({
179
+ context,
180
+ targetBlock,
181
+ incomingBlock: blockAfterEndPoint
182
+ });
183
+ return {
184
+ focusTextBlock,
185
+ mergedBlock,
186
+ newFocus
187
+ };
188
+ },
189
+ actions: [(_, {
190
+ focusTextBlock,
191
+ mergedBlock,
192
+ newFocus
193
+ }) => [{
194
+ type: "delete.block",
195
+ blockPath: focusTextBlock.path
196
+ }, {
197
+ type: "insert.block",
198
+ block: mergedBlock,
199
+ placement: "auto"
200
+ }, {
201
+ type: "select",
202
+ selection: {
203
+ anchor: newFocus,
204
+ focus: newFocus
205
+ }
206
+ }]]
207
+ }),
208
+ /**
209
+ * Fallback Behavior to avoid `insert.block` in case the Behaviors above all
210
+ * end up with a falsy guard.
211
+ */
212
+ defineBehavior({
213
+ on: "insert.block",
214
+ actions: [() => [{
215
+ type: "noop"
216
+ }]]
217
+ }),
218
+ /**
219
+ * If multiple blocks are inserted, then the non-text blocks are filtered out
220
+ * and the text blocks are merged into one block
221
+ */
222
+ defineBehavior({
223
+ on: "insert.blocks",
224
+ guard: ({
225
+ context,
226
+ event
227
+ }) => event.blocks.filter((block) => isTextBlock(context, block)).reduce((targetBlock, incomingBlock) => mergeTextBlocks({
228
+ context,
229
+ targetBlock,
230
+ incomingBlock
231
+ })),
232
+ actions: [
233
+ // `insert.block` is raised so the Behavior above can handle the
234
+ // insertion
235
+ (_, block) => [raise({
236
+ type: "insert.block",
237
+ block,
238
+ placement: "auto"
239
+ })]
240
+ ]
241
+ }),
242
+ /**
243
+ * Block objects do not fit in a one-line editor
244
+ */
245
+ defineBehavior({
246
+ on: "insert.block object",
247
+ actions: [() => [{
248
+ type: "noop"
249
+ }]]
250
+ }),
251
+ /**
252
+ * `insert.text block` is raised as an `insert.block` so it can be handled
253
+ * by the Behaviors above.
254
+ */
255
+ defineBehavior({
256
+ on: "insert.text block",
257
+ actions: [({
258
+ context,
259
+ event
260
+ }) => [raise({
261
+ type: "insert.block",
262
+ block: {
263
+ _key: context.keyGenerator(),
264
+ _type: context.schema.block.name,
265
+ children: event.textBlock?.children ?? []
266
+ },
267
+ placement: event.placement
268
+ })]]
269
+ })
270
+ ];
271
+ function OneLinePlugin() {
272
+ const $ = c(1);
273
+ let t0;
274
+ return $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = /* @__PURE__ */ jsx(BehaviorPlugin, { behaviors: oneLineBehaviors }), $[0] = t0) : t0 = $[0], t0;
275
+ }
24
276
  export {
277
+ BehaviorPlugin,
25
278
  EditorRefPlugin,
26
279
  EventListenerPlugin,
27
- MarkdownPlugin
280
+ MarkdownPlugin,
281
+ OneLinePlugin
28
282
  };
29
283
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/plugins/plugin.editor-ref.tsx","../../src/plugins/plugin.markdown.tsx"],"sourcesContent":["import React from 'react'\nimport type {Editor} from '../editor/create-editor'\nimport {useEditor} from '../editor/editor-provider'\n\n/**\n * @beta\n */\nexport const EditorRefPlugin = React.forwardRef<Editor | null>((_, ref) => {\n const editor = useEditor()\n\n const portableTextEditorRef = React.useRef(editor)\n\n React.useImperativeHandle(ref, () => portableTextEditorRef.current, [])\n\n return null\n})\nEditorRefPlugin.displayName = 'EditorRefPlugin'\n","import {useEffect} from 'react'\nimport {\n createMarkdownBehaviors,\n type MarkdownBehaviorsConfig,\n} from '../behaviors/behavior.markdown'\nimport {useEditor} from '../editor/editor-provider'\n\n/**\n * @beta\n */\nexport type MarkdownPluginConfig = MarkdownBehaviorsConfig\n\n/**\n * @beta\n * Add markdown behaviors for common markdown actions such as converting ### to headings, --- to HRs, and more.\n *\n * @example\n * Configure the bundled markdown behaviors\n * ```ts\n * import {EditorProvider} from '@portabletext/editor'\n * import {MarkdownPlugin} from '@portabletext/editor/plugins'\n *\n * function App() {\n * return (\n * <EditorProvider>\n * <MarkdownPlugin\n * config={{\n * horizontalRuleObject: ({schema}) => {\n * const name = schema.blockObjects.find(\n * (object) => object.name === 'break',\n * )?.name\n * return name ? {name} : undefined\n * },\n * defaultStyle: ({schema}) => schema.styles[0].value,\n * headingStyle: ({schema, level}) =>\n * schema.styles.find((style) => style.value === `h${level}`)\n * ?.value,\n * blockquoteStyle: ({schema}) =>\n * schema.styles.find((style) => style.value === 'blockquote')\n * ?.value,\n * unorderedListStyle: ({schema}) =>\n * schema.lists.find((list) => list.value === 'bullet')?.value,\n * orderedListStyle: ({schema}) =>\n * schema.lists.find((list) => list.value === 'number')?.value,\n * }}\n * />\n * {...}\n * </EditorProvider>\n * )\n * }\n */\nexport function MarkdownPlugin(props: {config: MarkdownPluginConfig}) {\n const editor = useEditor()\n\n useEffect(() => {\n const behaviors = createMarkdownBehaviors(props.config)\n\n const unregisterBehaviors = behaviors.map((behavior) =>\n editor.registerBehavior({behavior}),\n )\n\n return () => {\n for (const unregisterBehavior of unregisterBehaviors) {\n unregisterBehavior()\n }\n }\n }, [editor, props.config])\n\n return null\n}\n"],"names":["EditorRefPlugin","React","forwardRef","_","ref","$","_c","editor","useEditor","portableTextEditorRef","useRef","t0","t1","Symbol","for","current","useImperativeHandle","displayName","MarkdownPlugin","props","useEffect","unregisterBehaviors","createMarkdownBehaviors","config","map","behavior","registerBehavior","unregisterBehavior"],"mappings":";;;;;AAOO,MAAMA,kBAAkBC,MAAMC,WAA0B,CAAAC,GAAAC,QAAA;AAAAC,QAAAA,IAAAC,EAAA,CAAA,GAC7DC,SAAeC,UAEfC,GAAAA,wBAA8BR,MAAAS,OAAaH,MAAM;AAAC,MAAAI,IAAAC;AAAA,SAAAP,EAAA,CAAA,MAAAQ,OAAAC,IAAA,2BAAA,KAEnBH,KAAAA,MAAMF,sBAAqBM,SAAUH,KAAA,CAAA,GAAEP,OAAAM,IAAAN,OAAAO,OAAAD,KAAAN,EAAA,CAAA,GAAAO,KAAAP,EAAA,CAAA,IAAtEJ,MAAAe,oBAA0BZ,KAAKO,IAAqCC,EAAE,GAAC;AAAA,CAGxE;AACDZ,gBAAgBiB,cAAc;ACmCvB,SAASC,eAAeC,OAAuC;AACpE,QAAMZ,SAASC,UAAU;AAEzBY,SAAAA,UAAU,MAAM;AAGRC,UAAAA,sBAFYC,wBAAwBH,MAAMI,MAAM,EAEhBC,IAAKC,CAAAA,aACzClB,OAAOmB,iBAAiB;AAAA,MAACD;AAAAA,IAAAA,CAAS,CACpC;AAEA,WAAO,MAAM;AACX,iBAAWE,sBAAsBN;AACZ,2BAAA;AAAA,IAEvB;AAAA,KACC,CAACd,QAAQY,MAAMI,MAAM,CAAC,GAElB;AACT;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/plugins/plugin.behavior.tsx","../../src/plugins/plugin.editor-ref.tsx","../../src/plugins/plugin.markdown.tsx","../../src/plugins/plugin.one-line.tsx"],"sourcesContent":["import {useEffect} from 'react'\nimport type {Behavior} from '../behaviors'\nimport {useEditor} from '../editor/editor-provider'\n\n/**\n * @beta\n */\nexport function BehaviorPlugin(props: {behaviors: Array<Behavior>}) {\n const editor = useEditor()\n\n useEffect(() => {\n const unregisterBehaviors = props.behaviors.map((behavior) =>\n editor.registerBehavior({behavior}),\n )\n\n return () => {\n unregisterBehaviors.forEach((unregister) => unregister())\n }\n }, [editor, props.behaviors])\n\n return null\n}\n","import React from 'react'\nimport type {Editor} from '../editor/create-editor'\nimport {useEditor} from '../editor/editor-provider'\n\n/**\n * @beta\n */\nexport const EditorRefPlugin = React.forwardRef<Editor | null>((_, ref) => {\n const editor = useEditor()\n\n const portableTextEditorRef = React.useRef(editor)\n\n React.useImperativeHandle(ref, () => portableTextEditorRef.current, [])\n\n return null\n})\nEditorRefPlugin.displayName = 'EditorRefPlugin'\n","import {useEffect} from 'react'\nimport {\n createMarkdownBehaviors,\n type MarkdownBehaviorsConfig,\n} from '../behaviors/behavior.markdown'\nimport {useEditor} from '../editor/editor-provider'\n\n/**\n * @beta\n */\nexport type MarkdownPluginConfig = MarkdownBehaviorsConfig\n\n/**\n * @beta\n * Add markdown behaviors for common markdown actions such as converting ### to headings, --- to HRs, and more.\n *\n * @example\n * Configure the bundled markdown behaviors\n * ```ts\n * import {EditorProvider} from '@portabletext/editor'\n * import {MarkdownPlugin} from '@portabletext/editor/plugins'\n *\n * function App() {\n * return (\n * <EditorProvider>\n * <MarkdownPlugin\n * config={{\n * horizontalRuleObject: ({schema}) => {\n * const name = schema.blockObjects.find(\n * (object) => object.name === 'break',\n * )?.name\n * return name ? {name} : undefined\n * },\n * defaultStyle: ({schema}) => schema.styles[0].value,\n * headingStyle: ({schema, level}) =>\n * schema.styles.find((style) => style.value === `h${level}`)\n * ?.value,\n * blockquoteStyle: ({schema}) =>\n * schema.styles.find((style) => style.value === 'blockquote')\n * ?.value,\n * unorderedListStyle: ({schema}) =>\n * schema.lists.find((list) => list.value === 'bullet')?.value,\n * orderedListStyle: ({schema}) =>\n * schema.lists.find((list) => list.value === 'number')?.value,\n * }}\n * />\n * {...}\n * </EditorProvider>\n * )\n * }\n */\nexport function MarkdownPlugin(props: {config: MarkdownPluginConfig}) {\n const editor = useEditor()\n\n useEffect(() => {\n const behaviors = createMarkdownBehaviors(props.config)\n\n const unregisterBehaviors = behaviors.map((behavior) =>\n editor.registerBehavior({behavior}),\n )\n\n return () => {\n for (const unregisterBehavior of unregisterBehaviors) {\n unregisterBehavior()\n }\n }\n }, [editor, props.config])\n\n return null\n}\n","import {defineBehavior, raise} from '../behaviors'\nimport * as selectors from '../selectors'\nimport * as utils from '../utils'\nimport {BehaviorPlugin} from './plugin.behavior'\n\nconst oneLineBehaviors = [\n /**\n * Hitting Enter on an expanded selection should just delete that selection\n * without causing a line break.\n */\n defineBehavior({\n on: 'insert.break',\n guard: ({context}) =>\n context.selection && selectors.isSelectionExpanded({context})\n ? {selection: context.selection}\n : false,\n actions: [(_, {selection}) => [{type: 'delete', selection}]],\n }),\n /**\n * All other cases of `insert.break` should be aborted.\n */\n defineBehavior({\n on: 'insert.break',\n actions: [() => [{type: 'noop'}]],\n }),\n /**\n * `insert.block` `before` or `after` is not allowed in a one-line editor.\n */\n defineBehavior({\n on: 'insert.block',\n guard: ({event}) =>\n event.placement === 'before' || event.placement === 'after',\n actions: [() => [{type: 'noop'}]],\n }),\n /**\n * Other cases of `insert.block` are allowed.\n *\n * If a text block is inserted and the focus block is fully selected, then\n * the focus block can be replaced with the inserted block.\n */\n defineBehavior({\n on: 'insert.block',\n guard: ({context, event}) => {\n const focusTextBlock = selectors.getFocusTextBlock({context})\n const selectionStartPoint = selectors.getSelectionStartPoint({context})\n const selectionEndPoint = selectors.getSelectionEndPoint({context})\n\n if (\n !focusTextBlock ||\n !utils.isTextBlock(context, event.block) ||\n !selectionStartPoint ||\n !selectionEndPoint\n ) {\n return false\n }\n\n const blockStartPoint = utils.getBlockStartPoint(focusTextBlock)\n const blockEndPoint = utils.getBlockEndPoint(focusTextBlock)\n const newFocus = utils.getBlockEndPoint({\n node: event.block,\n path: [{_key: event.block._key}],\n })\n\n if (\n utils.isEqualSelectionPoints(blockStartPoint, selectionStartPoint) &&\n utils.isEqualSelectionPoints(blockEndPoint, selectionEndPoint)\n ) {\n return {focusTextBlock, newFocus}\n }\n\n return false\n },\n actions: [\n ({event}, {focusTextBlock, newFocus}) => [\n {type: 'delete.block', blockPath: focusTextBlock.path},\n {type: 'insert.block', block: event.block, placement: 'auto'},\n {\n type: 'select',\n selection: {\n anchor: newFocus,\n focus: newFocus,\n },\n },\n ],\n ],\n }),\n /**\n * An ordinary `insert.block` is acceptable if it's a text block. In that\n * case it will get merged into the existing text block.\n */\n defineBehavior({\n on: 'insert.block',\n guard: ({context, event}) => {\n const focusTextBlock = selectors.getFocusTextBlock({context})\n const selectionStartPoint = selectors.getSelectionStartPoint({context})\n const selectionEndPoint = selectors.getSelectionEndPoint({context})\n\n if (\n !focusTextBlock ||\n !utils.isTextBlock(context, event.block) ||\n !selectionStartPoint ||\n !selectionEndPoint\n ) {\n return false\n }\n\n const blockBeforeStartPoint = utils.splitTextBlock({\n context,\n block: focusTextBlock.node,\n point: selectionStartPoint,\n })?.before\n const blockAfterEndPoint = utils.splitTextBlock({\n context,\n block: focusTextBlock.node,\n point: selectionEndPoint,\n })?.after\n\n if (!blockBeforeStartPoint || !blockAfterEndPoint) {\n return false\n }\n\n const targetBlock = utils.mergeTextBlocks({\n context,\n targetBlock: blockBeforeStartPoint,\n incomingBlock: event.block,\n })\n\n const newFocus = utils.getBlockEndPoint({\n node: targetBlock,\n path: [{_key: targetBlock._key}],\n })\n\n const mergedBlock = utils.mergeTextBlocks({\n context,\n targetBlock,\n incomingBlock: blockAfterEndPoint,\n })\n\n return {focusTextBlock, mergedBlock, newFocus}\n },\n actions: [\n (_, {focusTextBlock, mergedBlock, newFocus}) => [\n {type: 'delete.block', blockPath: focusTextBlock.path},\n {type: 'insert.block', block: mergedBlock, placement: 'auto'},\n {\n type: 'select',\n selection: {\n anchor: newFocus,\n focus: newFocus,\n },\n },\n ],\n ],\n }),\n /**\n * Fallback Behavior to avoid `insert.block` in case the Behaviors above all\n * end up with a falsy guard.\n */\n defineBehavior({\n on: 'insert.block',\n actions: [() => [{type: 'noop'}]],\n }),\n /**\n * If multiple blocks are inserted, then the non-text blocks are filtered out\n * and the text blocks are merged into one block\n */\n defineBehavior({\n on: 'insert.blocks',\n guard: ({context, event}) => {\n return event.blocks\n .filter((block) => utils.isTextBlock(context, block))\n .reduce((targetBlock, incomingBlock) => {\n return utils.mergeTextBlocks({\n context,\n targetBlock,\n incomingBlock,\n })\n })\n },\n actions: [\n // `insert.block` is raised so the Behavior above can handle the\n // insertion\n (_, block) => [raise({type: 'insert.block', block, placement: 'auto'})],\n ],\n }),\n /**\n * Block objects do not fit in a one-line editor\n */\n defineBehavior({\n on: 'insert.block object',\n actions: [() => [{type: 'noop'}]],\n }),\n /**\n * `insert.text block` is raised as an `insert.block` so it can be handled\n * by the Behaviors above.\n */\n defineBehavior({\n on: 'insert.text block',\n actions: [\n ({context, event}) => [\n raise({\n type: 'insert.block',\n block: {\n _key: context.keyGenerator(),\n _type: context.schema.block.name,\n children: event.textBlock?.children ?? [],\n },\n placement: event.placement,\n }),\n ],\n ],\n }),\n]\n\n/**\n * @beta\n * Restrict the editor to one line. The plugin takes care of blocking\n * `insert.break` events and smart handling of other `insert.*` events.\n *\n * Place it with as high priority as possible to make sure other plugins don't\n * overwrite `insert.*` events before this plugin gets a chance to do so.\n */\nexport function OneLinePlugin() {\n return <BehaviorPlugin behaviors={oneLineBehaviors} />\n}\n"],"names":["BehaviorPlugin","props","$","_c","editor","useEditor","t0","t1","behaviors","unregisterBehaviors","map","behavior","registerBehavior","forEach","_temp","useEffect","unregister","EditorRefPlugin","React","forwardRef","_","ref","portableTextEditorRef","useRef","Symbol","for","current","useImperativeHandle","displayName","MarkdownPlugin","createMarkdownBehaviors","config","unregisterBehavior","oneLineBehaviors","defineBehavior","on","guard","context","selection","selectors","actions","type","event","placement","focusTextBlock","selectionStartPoint","selectionEndPoint","utils","block","blockStartPoint","blockEndPoint","newFocus","node","path","_key","blockPath","anchor","focus","blockBeforeStartPoint","point","before","blockAfterEndPoint","after","targetBlock","incomingBlock","mergedBlock","blocks","filter","reduce","raise","keyGenerator","_type","schema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CAAC,CACH;AAAA,EAEJ,CAAA;AAAC;AAWG,SAAAiC,gBAAA;AAAA1E,QAAAA,IAAAC,EAAA,CAAA;AAAAG,MAAAA;AAAAJ,SAAAA,EAAA,CAAA,MAAAsB,OAAAC,IAAA,2BAAA,KACEnB,KAAC,oBAAA,gBAAA,EAA0B2B,WAAAA,iBAAoB,CAAA,GAAA/B,OAAAI,MAAAA,KAAAJ,EAAA,CAAA,GAA/CI;AAA+C;"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var 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"), util_reverseSelection = require("../_chunks-cjs/util.reverse-selection.cjs");
3
+ var 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_getSelectionStartPoint = require("../_chunks-cjs/selector.get-selection-start-point.cjs"), selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs"), util_reverseSelection = require("../_chunks-cjs/util.reverse-selection.cjs");
4
4
  const getActiveAnnotations = (snapshot) => {
5
5
  if (!snapshot.context.selection)
6
6
  return [];
@@ -86,6 +86,30 @@ function isPointBeforeSelection(point) {
86
86
  return before;
87
87
  };
88
88
  }
89
+ function isOverlappingSelection(selection) {
90
+ return ({
91
+ context
92
+ }) => {
93
+ if (!selection || !context.selection)
94
+ return !1;
95
+ const selectionStartPoint = selector_getSelectionStartPoint.getSelectionStartPoint({
96
+ context: {
97
+ ...context,
98
+ selection
99
+ }
100
+ }), selectionEndPoint = selector_getSelectionStartPoint.getSelectionEndPoint({
101
+ context: {
102
+ ...context,
103
+ selection
104
+ }
105
+ });
106
+ return !(!selectionStartPoint || !selectionEndPoint || !isPointAfterSelection(selectionStartPoint)({
107
+ context
108
+ }) || !isPointBeforeSelection(selectionEndPoint)({
109
+ context
110
+ }));
111
+ };
112
+ }
89
113
  exports.getActiveListItem = selector_isAtTheStartOfBlock.getActiveListItem;
90
114
  exports.getActiveStyle = selector_isAtTheStartOfBlock.getActiveStyle;
91
115
  exports.getFirstBlock = selector_isAtTheStartOfBlock.getFirstBlock;
@@ -110,12 +134,15 @@ exports.isAtTheEndOfBlock = selector_isAtTheStartOfBlock.isAtTheEndOfBlock;
110
134
  exports.isAtTheStartOfBlock = selector_isAtTheStartOfBlock.isAtTheStartOfBlock;
111
135
  exports.isSelectionCollapsed = selector_isAtTheStartOfBlock.isSelectionCollapsed;
112
136
  exports.isSelectionExpanded = selector_isAtTheStartOfBlock.isSelectionExpanded;
137
+ exports.getSelectionEndPoint = selector_getSelectionStartPoint.getSelectionEndPoint;
138
+ exports.getSelectionStartPoint = selector_getSelectionStartPoint.getSelectionStartPoint;
113
139
  exports.getBlockTextBefore = selector_getTextBefore.getBlockTextBefore;
114
140
  exports.getSelectionText = selector_getTextBefore.getSelectionText;
115
141
  exports.getActiveAnnotations = getActiveAnnotations;
116
142
  exports.getSelectedSlice = getSelectedSlice;
117
143
  exports.getSelection = getSelection;
118
144
  exports.getValue = getValue;
145
+ exports.isOverlappingSelection = isOverlappingSelection;
119
146
  exports.isPointAfterSelection = isPointAfterSelection;
120
147
  exports.isPointBeforeSelection = isPointBeforeSelection;
121
148
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-selected-slice.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"],"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 {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {sliceBlocks} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = ({\n context,\n}) => {\n return sliceBlocks({blocks: context.value, selection: context.selection})\n}\n","import type {EditorSelection, EditorSelector} from './_exports'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = ({context}) => {\n return context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from './_exports'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = ({\n context,\n}) => {\n return 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 = reverseSelection(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 = reverseSelection(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"],"names":["getActiveAnnotations","snapshot","context","selection","selectedBlocks","getSelectedBlocks","selectedSpans","getSelectedSpans","length","flatMap","block","isPortableTextTextBlock","node","markDefs","filter","markDef","some","span","marks","includes","_key","getSelectedSlice","sliceBlocks","blocks","value","getSelection","getValue","isPointAfterSelection","point","reverseSelection","pointBlockKey","isKeySegment","path","undefined","pointChildKey","endBlockKey","focus","endChildKey","after","child","children","offset","isPointBeforeSelection","startBlockKey","anchor","startChildKey","before"],"mappings":";;;AAQO,MAAMA,uBACXC,CACG,aAAA;AACC,MAAA,CAACA,SAASC,QAAQC;AACpB,WAAO,CAAE;AAGX,QAAMC,iBAAiBC,6BAAAA,kBAAkBJ,QAAQ,GAC3CK,gBAAgBC,8CAAiBN,QAAQ;AAE/C,SAAIK,cAAcE,WAAW,IACpB,KAGiBJ,eAAeK,QAASC,CAChDC,UAAAA,MAAAA,wBAAwBD,MAAME,IAAI,IAAKF,MAAME,KAAKC,YAAY,CAAM,IAAA,CACtE,CAAA,EAEyBC,OAAQC,CAAAA,YAC/BT,cAAcU,KAAMC,CAAAA,SAASA,KAAKL,KAAKM,OAAOC,SAASJ,QAAQK,IAAI,CAAC,CACtE;AACF,GCtBaC,mBAA6DA,CAAC;AAAA,EACzEnB;AACF,MACSoB,6BAAY;AAAA,EAACC,QAAQrB,QAAQsB;AAAAA,EAAOrB,WAAWD,QAAQC;AAAS,CAAC,GCL7DsB,eAAgDA,CAAC;AAAA,EAACvB;AAAO,MAC7DA,QAAQC,WCAJuB,WAAqDA,CAAC;AAAA,EACjExB;AACF,MACSA,QAAQsB;ACDV,SAASG,sBACdC,OACyB;AACzB,SAAQ3B,CAAa,aAAA;AACf,QAAA,CAAC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../../src/selectors/selector.get-selected-slice.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 {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 {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {sliceBlocks} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = ({\n context,\n}) => {\n return sliceBlocks({blocks: context.value, selection: context.selection})\n}\n","import type {EditorSelection, EditorSelector} from './_exports'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = ({context}) => {\n return context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from './_exports'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = ({\n context,\n}) => {\n return 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 = reverseSelection(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 = reverseSelection(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 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 ({context}) => {\n if (!selection || !context.selection) {\n return false\n }\n\n const selectionStartPoint = getSelectionStartPoint({\n context: {\n ...context,\n selection,\n },\n })\n const selectionEndPoint = getSelectionEndPoint({\n context: {\n ...context,\n selection,\n },\n })\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return false\n }\n\n if (!isPointAfterSelection(selectionStartPoint)({context})) {\n return false\n }\n\n if (!isPointBeforeSelection(selectionEndPoint)({context})) {\n return false\n }\n\n return true\n }\n}\n"],"names":["getActiveAnnotations","snapshot","context","selection","selectedBlocks","getSelectedBlocks","selectedSpans","getSelectedSpans","length","flatMap","block","isPortableTextTextBlock","node","markDefs","filter","markDef","some","span","marks","includes","_key","getSelectedSlice","sliceBlocks","blocks","value","getSelection","getValue","isPointAfterSelection","point","reverseSelection","pointBlockKey","isKeySegment","path","undefined","pointChildKey","endBlockKey","focus","endChildKey","after","child","children","offset","isPointBeforeSelection","startBlockKey","anchor","startChildKey","before","isOverlappingSelection","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint"],"mappings":";;;AAQO,MAAMA,uBACXC,CACG,aAAA;AACC,MAAA,CAACA,SAASC,QAAQC;AACpB,WAAO,CAAE;AAGX,QAAMC,iBAAiBC,6BAAAA,kBAAkBJ,QAAQ,GAC3CK,gBAAgBC,8CAAiBN,QAAQ;AAE/C,SAAIK,cAAcE,WAAW,IACpB,KAGiBJ,eAAeK,QAASC,CAChDC,UAAAA,MAAAA,wBAAwBD,MAAME,IAAI,IAAKF,MAAME,KAAKC,YAAY,CAAM,IAAA,CACtE,CAAA,EAEyBC,OAAQC,CAAAA,YAC/BT,cAAcU,KAAMC,CAAAA,SAASA,KAAKL,KAAKM,OAAOC,SAASJ,QAAQK,IAAI,CAAC,CACtE;AACF,GCtBaC,mBAA6DA,CAAC;AAAA,EACzEnB;AACF,MACSoB,6BAAY;AAAA,EAACC,QAAQrB,QAAQsB;AAAAA,EAAOrB,WAAWD,QAAQC;AAAS,CAAC,GCL7DsB,eAAgDA,CAAC;AAAA,EAACvB;AAAO,MAC7DA,QAAQC,WCAJuB,WAAqDA,CAAC;AAAA,EACjExB;AACF,MACSA,QAAQsB;ACDV,SAASG,sBACdC,OACyB;AACzB,SAAQ3B,CAAa,aAAA;AACf,QAAA,CAACA,SAASC,QAAQC;AACb,aAAA;AAGT,UAAMA,YAAY0B,sBAAAA,iBAAiB5B,SAASC,QAAQC,SAAS,GAEvD2B,gBAAgBC,MAAAA,aAAaH,MAAMI,KAAK,CAAC,CAAC,IAC5CJ,MAAMI,KAAK,CAAC,EAAEZ,OACda,QACEC,gBAAgBH,MAAAA,aAAaH,MAAMI,KAAK,CAAC,CAAC,IAC5CJ,MAAMI,KAAK,CAAC,EAAEZ,OACda,QAEEE,cAAcJ,MAAAA,aAAa5B,UAAUiC,MAAMJ,KAAK,CAAC,CAAC,IACpD7B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,IAAAA,CAAQ,KAIrD,CAACwC,uBAAuBQ,iBAAiB,EAAE;AAAA,MAAChD;AAAAA,IAAAA,CAAQ;AAAA,EAK1D;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -286,6 +286,13 @@ export declare const getSelectionEndBlock: EditorSelector<
286
286
  | undefined
287
287
  >
288
288
 
289
+ /**
290
+ * @public
291
+ */
292
+ export declare const getSelectionEndPoint: EditorSelector<
293
+ EditorSelectionPoint | undefined
294
+ >
295
+
289
296
  /**
290
297
  * @public
291
298
  */
@@ -297,6 +304,13 @@ export declare const getSelectionStartBlock: EditorSelector<
297
304
  | undefined
298
305
  >
299
306
 
307
+ /**
308
+ * @public
309
+ */
310
+ export declare const getSelectionStartPoint: EditorSelector<
311
+ EditorSelectionPoint | undefined
312
+ >
313
+
300
314
  /**
301
315
  * @public
302
316
  */
@@ -349,6 +363,13 @@ export declare function isAtTheStartOfBlock(block: {
349
363
  path: [KeyedSegment]
350
364
  }): EditorSelector<boolean>
351
365
 
366
+ /**
367
+ * @public
368
+ */
369
+ export declare function isOverlappingSelection(
370
+ selection: EditorSelection,
371
+ ): EditorSelector<boolean>
372
+
352
373
  /**
353
374
  * @public
354
375
  */
@@ -286,6 +286,13 @@ export declare const getSelectionEndBlock: EditorSelector<
286
286
  | undefined
287
287
  >
288
288
 
289
+ /**
290
+ * @public
291
+ */
292
+ export declare const getSelectionEndPoint: EditorSelector<
293
+ EditorSelectionPoint | undefined
294
+ >
295
+
289
296
  /**
290
297
  * @public
291
298
  */
@@ -297,6 +304,13 @@ export declare const getSelectionStartBlock: EditorSelector<
297
304
  | undefined
298
305
  >
299
306
 
307
+ /**
308
+ * @public
309
+ */
310
+ export declare const getSelectionStartPoint: EditorSelector<
311
+ EditorSelectionPoint | undefined
312
+ >
313
+
300
314
  /**
301
315
  * @public
302
316
  */
@@ -349,6 +363,13 @@ export declare function isAtTheStartOfBlock(block: {
349
363
  path: [KeyedSegment]
350
364
  }): EditorSelector<boolean>
351
365
 
366
+ /**
367
+ * @public
368
+ */
369
+ export declare function isOverlappingSelection(
370
+ selection: EditorSelection,
371
+ ): EditorSelector<boolean>
372
+
352
373
  /**
353
374
  * @public
354
375
  */
@@ -2,6 +2,7 @@ import { isPortableTextTextBlock, isKeySegment } from "@sanity/types";
2
2
  import { getSelectedBlocks, getSelectedSpans } from "../_chunks-es/selector.is-at-the-start-of-block.js";
3
3
  import { getActiveListItem, getActiveStyle, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getNextBlock, getPreviousBlock, getSelectionEndBlock, getSelectionStartBlock, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-at-the-start-of-block.js";
4
4
  import { sliceBlocks } from "../_chunks-es/util.slice-blocks.js";
5
+ import { getSelectionStartPoint, getSelectionEndPoint } from "../_chunks-es/selector.get-selection-start-point.js";
5
6
  import { getBlockTextBefore, getSelectionText } from "../_chunks-es/selector.get-text-before.js";
6
7
  import { reverseSelection } from "../_chunks-es/util.reverse-selection.js";
7
8
  const getActiveAnnotations = (snapshot) => {
@@ -89,6 +90,30 @@ function isPointBeforeSelection(point) {
89
90
  return before;
90
91
  };
91
92
  }
93
+ function isOverlappingSelection(selection) {
94
+ return ({
95
+ context
96
+ }) => {
97
+ if (!selection || !context.selection)
98
+ return !1;
99
+ const selectionStartPoint = getSelectionStartPoint({
100
+ context: {
101
+ ...context,
102
+ selection
103
+ }
104
+ }), selectionEndPoint = getSelectionEndPoint({
105
+ context: {
106
+ ...context,
107
+ selection
108
+ }
109
+ });
110
+ return !(!selectionStartPoint || !selectionEndPoint || !isPointAfterSelection(selectionStartPoint)({
111
+ context
112
+ }) || !isPointBeforeSelection(selectionEndPoint)({
113
+ context
114
+ }));
115
+ };
116
+ }
92
117
  export {
93
118
  getActiveAnnotations,
94
119
  getActiveListItem,
@@ -109,7 +134,9 @@ export {
109
134
  getSelectedSpans,
110
135
  getSelection,
111
136
  getSelectionEndBlock,
137
+ getSelectionEndPoint,
112
138
  getSelectionStartBlock,
139
+ getSelectionStartPoint,
113
140
  getSelectionText,
114
141
  getValue,
115
142
  isActiveAnnotation,
@@ -118,6 +145,7 @@ export {
118
145
  isActiveStyle,
119
146
  isAtTheEndOfBlock,
120
147
  isAtTheStartOfBlock,
148
+ isOverlappingSelection,
121
149
  isPointAfterSelection,
122
150
  isPointBeforeSelection,
123
151
  isSelectionCollapsed,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-selected-slice.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"],"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 {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {sliceBlocks} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = ({\n context,\n}) => {\n return sliceBlocks({blocks: context.value, selection: context.selection})\n}\n","import type {EditorSelection, EditorSelector} from './_exports'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = ({context}) => {\n return context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from './_exports'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = ({\n context,\n}) => {\n return 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 = reverseSelection(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 = reverseSelection(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"],"names":["getActiveAnnotations","snapshot","context","selection","selectedBlocks","getSelectedBlocks","selectedSpans","getSelectedSpans","length","flatMap","block","isPortableTextTextBlock","node","markDefs","filter","markDef","some","span","marks","includes","_key","getSelectedSlice","sliceBlocks","blocks","value","getSelection","getValue","isPointAfterSelection","point","reverseSelection","pointBlockKey","isKeySegment","path","undefined","pointChildKey","endBlockKey","focus","endChildKey","after","child","children","offset","isPointBeforeSelection","startBlockKey","anchor","startChildKey","before"],"mappings":";;;;;;AAQO,MAAMA,uBACXC,CACG,aAAA;AACC,MAAA,CAACA,SAASC,QAAQC;AACpB,WAAO,CAAE;AAGX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ASuB,eAAe;AACvB,mBAAA;AACT;AAAA,QAAA;AASF,YAJI,CAAChC,wBAAwBD,KAAK,KAI9B,CAACwB,iBAAiB,CAACW;AACrB;AAGSN,mBAAAA,SAAS7B,MAAM8B,UAAU;AAC9BD,cAAAA,MAAMnB,SAASc,eAAe;AAC5BK,gBAAAA,MAAMnB,SAASyB,eAAe;AACvB,uBAAA;AACT;AAAA,YAAA;AAKOjB,qBAAAA,MAAMa,SAAStC,UAAUyC,OAAOH;AACzC;AAAA,UAAA;AAGF,cAAIF,MAAMnB,SAASyB;AACjB;AAAA,QAAA;AAAA,MAEJ;AAGF,UAAInC,MAAMU,SAASuB;AACjB;AAAA,IAAA;AAIGG,WAAAA;AAAAA,EACT;AACF;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-selected-slice.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 {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 {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {sliceBlocks} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = ({\n context,\n}) => {\n return sliceBlocks({blocks: context.value, selection: context.selection})\n}\n","import type {EditorSelection, EditorSelector} from './_exports'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = ({context}) => {\n return context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from './_exports'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = ({\n context,\n}) => {\n return 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 = reverseSelection(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 = reverseSelection(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 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 ({context}) => {\n if (!selection || !context.selection) {\n return false\n }\n\n const selectionStartPoint = getSelectionStartPoint({\n context: {\n ...context,\n selection,\n },\n })\n const selectionEndPoint = getSelectionEndPoint({\n context: {\n ...context,\n selection,\n },\n })\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return false\n }\n\n if (!isPointAfterSelection(selectionStartPoint)({context})) {\n return false\n }\n\n if (!isPointBeforeSelection(selectionEndPoint)({context})) {\n return false\n }\n\n return true\n }\n}\n"],"names":["getActiveAnnotations","snapshot","context","selection","selectedBlocks","getSelectedBlocks","selectedSpans","getSelectedSpans","length","flatMap","block","isPortableTextTextBlock","node","markDefs","filter","markDef","some","span","marks","includes","_key","getSelectedSlice","sliceBlocks","blocks","value","getSelection","getValue","isPointAfterSelection","point","reverseSelection","pointBlockKey","isKeySegment","path","undefined","pointChildKey","endBlockKey","focus","endChildKey","after","child","children","offset","isPointBeforeSelection","startBlockKey","anchor","startChildKey","before","isOverlappingSelection","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint"],"mappings":";;;;;;;AAQO,MAAMA,uBACXC,CACG,aAAA;AACC,MAAA,CAACA,SAASC,QAAQC;AACpB,WAAO,CAAE;AAGX,QAAMC,iBAAiBC,kBAAkBJ,QAAQ,GAC3CK,gBAAgBC,iBAAiBN,QAAQ;AAE/C,SAAIK,cAAcE,WAAW,IACpB,KAGiBJ,eAAeK,QAASC,CAChDC,UAAAA,wBAAwBD,MAAME,IAAI,IAAKF,MAAME,KAAKC,YAAY,CAAM,IAAA,CACtE,CAAA,EAEyBC,OAAQC,CAAAA,YAC/BT,cAAcU,KAAMC,CAAAA,SAASA,KAAKL,KAAKM,OAAOC,SAASJ,QAAQK,IAAI,CAAC,CACtE;AACF,GCtBaC,mBAA6DA,CAAC;AAAA,EACzEnB;AACF,MACSoB,YAAY;AAAA,EAACC,QAAQrB,QAAQsB;AAAAA,EAAOrB,WAAWD,QAAQC;AAAS,CAAC,GCL7DsB,eAAgDA,CAAC;AAAA,EAACvB;AAA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