@portabletext/editor 1.20.0 → 1.21.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 (128) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +8 -68
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.get-text-before.cjs +11 -39
  4. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  5. package/lib/_chunks-cjs/util.get-block-start-point.cjs +30 -0
  6. package/lib/_chunks-cjs/util.get-block-start-point.cjs.map +1 -0
  7. package/lib/_chunks-cjs/util.is-empty-text-block.cjs +71 -0
  8. package/lib/_chunks-cjs/util.is-empty-text-block.cjs.map +1 -0
  9. package/lib/_chunks-cjs/util.is-keyed-segment.cjs +6 -0
  10. package/lib/_chunks-cjs/util.is-keyed-segment.cjs.map +1 -0
  11. package/lib/_chunks-es/behavior.core.js +7 -66
  12. package/lib/_chunks-es/behavior.core.js.map +1 -1
  13. package/lib/_chunks-es/selector.get-text-before.js +5 -31
  14. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  15. package/lib/_chunks-es/util.get-block-start-point.js +31 -0
  16. package/lib/_chunks-es/util.get-block-start-point.js.map +1 -0
  17. package/lib/_chunks-es/util.is-empty-text-block.js +73 -0
  18. package/lib/_chunks-es/util.is-empty-text-block.js.map +1 -0
  19. package/lib/_chunks-es/util.is-keyed-segment.js +7 -0
  20. package/lib/_chunks-es/util.is-keyed-segment.js.map +1 -0
  21. package/lib/behaviors/index.cjs +7 -7
  22. package/lib/behaviors/index.cjs.map +1 -1
  23. package/lib/behaviors/index.d.cts +179 -119
  24. package/lib/behaviors/index.d.ts +179 -119
  25. package/lib/behaviors/index.js +3 -2
  26. package/lib/behaviors/index.js.map +1 -1
  27. package/lib/index.cjs +112 -21
  28. package/lib/index.cjs.map +1 -1
  29. package/lib/index.d.cts +870 -141
  30. package/lib/index.d.ts +870 -141
  31. package/lib/index.js +111 -19
  32. package/lib/index.js.map +1 -1
  33. package/lib/selectors/index.cjs +73 -1
  34. package/lib/selectors/index.cjs.map +1 -1
  35. package/lib/selectors/index.d.cts +14 -0
  36. package/lib/selectors/index.d.ts +14 -0
  37. package/lib/selectors/index.js +73 -0
  38. package/lib/selectors/index.js.map +1 -1
  39. package/lib/utils/index.cjs +11 -0
  40. package/lib/utils/index.cjs.map +1 -0
  41. package/lib/utils/index.d.cts +87 -0
  42. package/lib/utils/index.d.ts +87 -0
  43. package/lib/utils/index.js +13 -0
  44. package/lib/utils/index.js.map +1 -0
  45. package/package.json +15 -9
  46. package/src/behavior-actions/behavior.action-utils.insert-block.ts +1 -1
  47. package/src/behavior-actions/behavior.action.insert-block-object.ts +1 -1
  48. package/src/behavior-actions/behavior.action.insert-inline-object.ts +1 -1
  49. package/src/behavior-actions/behavior.action.text-block.set.ts +1 -1
  50. package/src/behavior-actions/behavior.action.text-block.unset.ts +1 -1
  51. package/src/behavior-actions/behavior.actions.ts +5 -5
  52. package/src/behaviors/behavior.code-editor.ts +1 -1
  53. package/src/behaviors/behavior.core.block-objects.ts +2 -2
  54. package/src/behaviors/behavior.core.decorators.ts +1 -1
  55. package/src/behaviors/behavior.core.lists.ts +2 -2
  56. package/src/behaviors/behavior.emoji-picker.ts +1 -1
  57. package/src/behaviors/behavior.links.ts +1 -1
  58. package/src/behaviors/behavior.markdown.ts +2 -2
  59. package/src/behaviors/behavior.types.ts +52 -19
  60. package/src/behaviors/index.ts +1 -0
  61. package/src/editor/Editable.tsx +12 -12
  62. package/src/editor/PortableTextEditor.tsx +2 -2
  63. package/src/editor/components/DraggableBlock.tsx +2 -2
  64. package/src/editor/components/Element.tsx +3 -3
  65. package/src/editor/components/Leaf.tsx +1 -1
  66. package/src/editor/components/Synchronizer.tsx +1 -1
  67. package/src/editor/create-editor.ts +22 -20
  68. package/src/editor/create-slate-editor.tsx +5 -2
  69. package/src/editor/editor-machine.ts +115 -23
  70. package/src/editor/get-value.ts +2 -2
  71. package/src/editor/hooks/usePortableTextEditorSelection.tsx +1 -1
  72. package/src/editor/mutation-machine.ts +2 -2
  73. package/src/editor/plugins/create-with-event-listeners.ts +50 -4
  74. package/src/editor/plugins/createWithEditableAPI.ts +7 -7
  75. package/src/editor/plugins/createWithHotKeys.ts +2 -2
  76. package/src/editor/plugins/createWithInsertData.ts +7 -7
  77. package/src/editor/plugins/createWithMaxBlocks.ts +2 -2
  78. package/src/editor/plugins/createWithObjectKeys.ts +2 -2
  79. package/src/editor/plugins/createWithPatches.ts +10 -10
  80. package/src/editor/plugins/createWithPlaceholderBlock.ts +3 -3
  81. package/src/editor/plugins/createWithPortableTextBlockStyle.ts +1 -1
  82. package/src/editor/plugins/createWithPortableTextMarkModel.ts +4 -4
  83. package/src/editor/plugins/createWithPortableTextSelections.ts +6 -6
  84. package/src/editor/plugins/createWithSchemaTypes.ts +1 -1
  85. package/src/editor/plugins/createWithUndoRedo.ts +5 -5
  86. package/src/editor/plugins/createWithUtils.ts +2 -2
  87. package/src/editor/plugins/with-plugins.ts +1 -1
  88. package/src/editor/sync-machine.ts +8 -5
  89. package/src/index.ts +5 -1
  90. package/src/selectors/index.ts +2 -0
  91. package/src/selectors/selector.get-selection-text.test.ts +75 -0
  92. package/src/selectors/selector.get-selection-text.ts +3 -3
  93. package/src/selectors/selector.get-text-before.ts +7 -4
  94. package/src/selectors/selector.is-point-after-selection.ts +82 -0
  95. package/src/selectors/selector.is-point-before-selection.ts +82 -0
  96. package/src/utils/_exports/index.ts +1 -0
  97. package/src/utils/index.ts +11 -0
  98. package/src/{editor/utils/utils.block-offset.test.ts → utils/util.block-offset.test.ts} +1 -1
  99. package/src/{editor/utils/utils.block-offset.ts → utils/util.block-offset.ts} +23 -7
  100. package/src/{editor/utils/utils.get-start-point.ts → utils/util.get-block-start-point.ts} +5 -2
  101. package/src/utils/util.get-text-block-text.ts +8 -0
  102. package/src/{editor/utils/utils.ts → utils/util.is-empty-text-block.ts} +4 -5
  103. package/src/{editor/utils/utils.is-keyed-segment.ts → utils/util.is-keyed-segment.ts} +3 -0
  104. package/src/{editor/utils/utils.reverse-selection.ts → utils/util.reverse-selection.ts} +4 -1
  105. /package/src/{utils → internal-utils}/__tests__/dmpToOperations.test.ts +0 -0
  106. /package/src/{utils → internal-utils}/__tests__/operationToPatches.test.ts +0 -0
  107. /package/src/{utils → internal-utils}/__tests__/patchToOperations.test.ts +0 -0
  108. /package/src/{utils → internal-utils}/__tests__/ranges.test.ts +0 -0
  109. /package/src/{utils → internal-utils}/__tests__/valueNormalization.test.tsx +0 -0
  110. /package/src/{utils → internal-utils}/__tests__/values.test.ts +0 -0
  111. /package/src/{utils → internal-utils}/applyPatch.ts +0 -0
  112. /package/src/{utils → internal-utils}/debug.ts +0 -0
  113. /package/src/{utils → internal-utils}/is-hotkey.test.ts +0 -0
  114. /package/src/{utils → internal-utils}/is-hotkey.ts +0 -0
  115. /package/src/{utils → internal-utils}/looks-like-url.test.ts +0 -0
  116. /package/src/{utils → internal-utils}/looks-like-url.ts +0 -0
  117. /package/src/{utils → internal-utils}/operationToPatches.ts +0 -0
  118. /package/src/{utils → internal-utils}/paths.ts +0 -0
  119. /package/src/{utils → internal-utils}/ranges.ts +0 -0
  120. /package/src/{utils → internal-utils}/schema.ts +0 -0
  121. /package/src/{utils → internal-utils}/selection.ts +0 -0
  122. /package/src/{utils → internal-utils}/sibling-utils.ts +0 -0
  123. /package/src/{utils → internal-utils}/validateValue.ts +0 -0
  124. /package/src/{utils → internal-utils}/values.ts +0 -0
  125. /package/src/{utils → internal-utils}/weakMaps.ts +0 -0
  126. /package/src/{utils → internal-utils}/withChanges.ts +0 -0
  127. /package/src/{utils → internal-utils}/withUndoRedo.ts +0 -0
  128. /package/src/{utils → internal-utils}/withoutPatching.ts +0 -0
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var selector_isSelectionCollapsed = require("../_chunks-cjs/selector.is-selection-collapsed.cjs"), types = require("@sanity/types"), selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs");
3
+ var selector_isSelectionCollapsed = require("../_chunks-cjs/selector.is-selection-collapsed.cjs"), types = require("@sanity/types"), selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs"), util_getBlockStartPoint = require("../_chunks-cjs/util.get-block-start-point.cjs");
4
4
  const getActiveListItem = ({
5
5
  context
6
6
  }) => {
@@ -149,6 +149,76 @@ function isActiveListItem(listItem) {
149
149
  function isActiveStyle(style) {
150
150
  return (snapshot) => getActiveStyle(snapshot) === style;
151
151
  }
152
+ function isPointAfterSelection(point) {
153
+ return (snapshot) => {
154
+ if (!snapshot.context.selection)
155
+ return !1;
156
+ const selection = util_getBlockStartPoint.reverseSelection(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;
157
+ if (!pointBlockKey || !endBlockKey)
158
+ return !1;
159
+ let after = !1;
160
+ for (const block of snapshot.context.value) {
161
+ if (block._key === endBlockKey) {
162
+ if (block._key !== pointBlockKey) {
163
+ after = !0;
164
+ break;
165
+ }
166
+ if (!types.isPortableTextTextBlock(block) || !pointChildKey || !endChildKey)
167
+ break;
168
+ for (const child of block.children) {
169
+ if (child._key === endChildKey) {
170
+ if (child._key !== pointChildKey) {
171
+ after = !0;
172
+ break;
173
+ }
174
+ after = point.offset > selection.focus.offset;
175
+ break;
176
+ }
177
+ if (child._key === pointChildKey)
178
+ break;
179
+ }
180
+ }
181
+ if (block._key === pointBlockKey)
182
+ break;
183
+ }
184
+ return after;
185
+ };
186
+ }
187
+ function isPointBeforeSelection(point) {
188
+ return (snapshot) => {
189
+ if (!snapshot.context.selection)
190
+ return !1;
191
+ const selection = util_getBlockStartPoint.reverseSelection(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;
192
+ if (!pointBlockKey || !startBlockKey)
193
+ return !1;
194
+ let before = !1;
195
+ for (const block of snapshot.context.value) {
196
+ if (block._key === pointBlockKey) {
197
+ if (block._key !== startBlockKey) {
198
+ before = !0;
199
+ break;
200
+ }
201
+ if (!types.isPortableTextTextBlock(block) || !pointChildKey || !startChildKey)
202
+ break;
203
+ for (const child of block.children) {
204
+ if (child._key === pointChildKey) {
205
+ if (child._key !== startChildKey) {
206
+ before = !0;
207
+ break;
208
+ }
209
+ before = point.offset < selection.anchor.offset;
210
+ break;
211
+ }
212
+ if (child._key === startChildKey)
213
+ break;
214
+ }
215
+ }
216
+ if (block._key === startBlockKey)
217
+ break;
218
+ }
219
+ return before;
220
+ };
221
+ }
152
222
  exports.getFirstBlock = selector_isSelectionCollapsed.getFirstBlock;
153
223
  exports.getFocusBlock = selector_isSelectionCollapsed.getFocusBlock;
154
224
  exports.getFocusBlockObject = selector_isSelectionCollapsed.getFocusBlockObject;
@@ -172,5 +242,7 @@ exports.isActiveAnnotation = isActiveAnnotation;
172
242
  exports.isActiveDecorator = isActiveDecorator;
173
243
  exports.isActiveListItem = isActiveListItem;
174
244
  exports.isActiveStyle = isActiveStyle;
245
+ exports.isPointAfterSelection = isPointAfterSelection;
246
+ exports.isPointBeforeSelection = isPointBeforeSelection;
175
247
  exports.isSelectionExpanded = isSelectionExpanded;
176
248
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-active-list-item.ts","../../src/selectors/selector.get-active-style.ts","../../src/selectors/selector.get-selected-spans.ts","../../src/selectors/selector.is-active-annotation.ts","../../src/selectors/selector.is-selection-expanded.ts","../../src/selectors/selector.is-active-decorator.ts","../../src/selectors/selector.is-active-list-item.ts","../../src/selectors/selector.is-active-style.ts"],"sourcesContent":["import type {PortableTextListBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveListItem: EditorSelector<\n PortableTextListBlock['listItem'] | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const guards = createGuards(context)\n const selectedBlocks = getSelectedBlocks({context}).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstListItem = firstTextBlock.listItem\n\n if (!firstListItem) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.listItem === firstListItem)) {\n return firstListItem\n }\n\n return undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveStyle: EditorSelector<PortableTextTextBlock['style']> = ({\n context,\n}) => {\n if (!context.selection) {\n return undefined\n }\n\n const guards = createGuards(context)\n const selectedBlocks = getSelectedBlocks({context}).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstStyle = firstTextBlock.style\n\n if (!firstStyle) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.style === firstStyle)) {\n return firstStyle\n }\n\n return undefined\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextSpan,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelectedSpans: EditorSelector<\n Array<{\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }>\n> = ({context}) => {\n if (!context.selection) {\n return []\n }\n\n const selectedSpans: Array<{\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }> = []\n\n const startPoint = context.selection.backward\n ? context.selection.focus\n : context.selection.anchor\n const endPoint = context.selection.backward\n ? context.selection.anchor\n : context.selection.focus\n\n const startBlockKey = isKeySegment(startPoint.path[0])\n ? startPoint.path[0]._key\n : undefined\n const endBlockKey = isKeySegment(endPoint.path[0])\n ? endPoint.path[0]._key\n : undefined\n\n if (!startBlockKey || !endBlockKey) {\n return selectedSpans\n }\n\n const startSpanKey = isKeySegment(startPoint.path[2])\n ? startPoint.path[2]._key\n : undefined\n const endSpanKey = isKeySegment(endPoint.path[2])\n ? endPoint.path[2]._key\n : undefined\n\n for (const block of context.value) {\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n if (block._key === startBlockKey) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (startSpanKey && child._key === startSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n\n if (startSpanKey === endSpanKey) {\n break\n }\n\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n break\n }\n\n if (selectedSpans.length > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n if (block._key === endBlockKey) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n break\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n\n break\n }\n\n if (selectedSpans.length > 0) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n }\n\n return selectedSpans\n}\n","import {isPortableTextTextBlock} 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 function isActiveAnnotation(\n annotation: string,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const selectedSpans = getSelectedSpans(snapshot)\n\n if (selectedSpans.length === 0) {\n return false\n }\n\n if (\n selectedSpans.some(\n (span) => !span.node.marks || span.node.marks?.length === 0,\n )\n ) {\n return false\n }\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isPortableTextTextBlock(block.node) ? (block.node.markDefs ?? []) : [],\n )\n\n return selectedSpans.every((span) => {\n const spanMarkDefs =\n span.node.marks?.flatMap((mark) => {\n const markDef = selectionMarkDefs.find(\n (markDef) => markDef._key === mark,\n )\n\n return markDef ? [markDef._type] : []\n }) ?? []\n\n return spanMarkDefs.includes(annotation)\n })\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const isSelectionExpanded: EditorSelector<boolean> = ({context}) => {\n return !isSelectionCollapsed({context})\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\n\n/**\n * @public\n */\nexport function isActiveDecorator(decorator: string): EditorSelector<boolean> {\n return (snapshot) => {\n if (isSelectionExpanded(snapshot)) {\n const selectedSpans = getSelectedSpans(snapshot)\n\n return (\n selectedSpans.length > 0 &&\n selectedSpans.every((span) => span.node.marks?.includes(decorator))\n )\n }\n\n return snapshot.context.activeDecorators.includes(decorator)\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveListItem} from './selector.get-active-list-item'\n\n/**\n * @public\n */\nexport function isActiveListItem(listItem: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeListItem = getActiveListItem(snapshot)\n\n return activeListItem === listItem\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveStyle} from './selector.get-active-style'\n\n/**\n * @public\n */\nexport function isActiveStyle(style: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeStyle = getActiveStyle(snapshot)\n\n return activeStyle === style\n }\n}\n"],"names":["getActiveListItem","context","selection","guards","createGuards","selectedTextBlocks","getSelectedBlocks","map","block","node","filter","isTextBlock","firstTextBlock","at","firstListItem","listItem","every","getActiveStyle","firstStyle","style","getSelectedSpans","selectedSpans","startPoint","backward","focus","anchor","endPoint","startBlockKey","isKeySegment","path","_key","undefined","endBlockKey","startSpanKey","endSpanKey","value","isPortableTextTextBlock","child","children","isPortableTextSpan","push","length","isActiveAnnotation","annotation","snapshot","selectedBlocks","some","span","marks","selectionMarkDefs","flatMap","markDefs","mark","markDef","find","_type","includes","isSelectionExpanded","isSelectionCollapsed","isActiveDecorator","decorator","activeDecorators","isActiveListItem","isActiveStyle"],"mappings":";;;AAQO,MAAMA,oBAETA,CAAC;AAAA,EAACC;AAAO,MAAM;AACjB,MAAI,CAACA,QAAQC;AACX;AAGF,QAAMC,SAASC,8BAAAA,aAAaH,OAAO,GAE7BI,qBADiBC,8BAAAA,kBAAkB;AAAA,IAACL;AAAAA,EAAQ,CAAA,EAAEM,IAAKC,CAAAA,UAAUA,MAAMC,IAAI,EACnCC,OAAOP,OAAOQ,WAAW,GAE7DC,iBAAiBP,mBAAmBQ,GAAG,CAAC;AAE9C,MAAI,CAACD;AACH;AAGF,QAAME,gBAAgBF,eAAeG;AAEr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kBAAkBK,KAC/BD,CAAAA,aAAYA,SAAQvB,SAASsB,IAChC;AAEA,aAAOC,UAAU,CAACA,QAAQE,KAAK,IAAI,CAAE;AAAA,IACtC,CAAA,KAAK,CAEYC,GAAAA,SAASb,UAAU,CACxC;AAAA,EACH;AACF;AC1CO,MAAMc,sBAA+CA,CAAC;AAAA,EAACxD;AAAO,MAC5D,CAACyD,8BAAAA,qBAAqB;AAAA,EAACzD;AAAO,CAAC;ACAjC,SAAS0D,kBAAkBC,WAA4C;AAC5E,SAAQhB,CAAa,aAAA;AACfa,QAAAA,oBAAoBb,QAAQ,GAAG;AAC3BvB,YAAAA,gBAAgBD,iBAAiBwB,QAAQ;AAG7CvB,aAAAA,cAAcoB,SAAS,KACvBpB,cAAcL,MAAO+B,CAASA,SAAAA,KAAKtC,KAAKuC,OAAOQ,SAASI,SAAS,CAAC;AAAA,IAAA;AAItE,WAAOhB,SAAS3C,QAAQ4D,iBAAiBL,SAASI,SAAS;AAAA,EAC7D;AACF;ACdO,SAASE,iBAAiB/C,UAA2C;AAClE6B,SAAAA,CAAAA,aACiB5C,kBAAkB4C,QAAQ,MAEvB7B;AAE9B;ACNO,SAASgD,cAAc5C,OAAwC;AAC5DyB,SAAAA,CAAAA,aACc3B,eAAe2B,QAAQ,MAEpBzB;AAE3B;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-active-list-item.ts","../../src/selectors/selector.get-active-style.ts","../../src/selectors/selector.get-selected-spans.ts","../../src/selectors/selector.is-active-annotation.ts","../../src/selectors/selector.is-selection-expanded.ts","../../src/selectors/selector.is-active-decorator.ts","../../src/selectors/selector.is-active-list-item.ts","../../src/selectors/selector.is-active-style.ts","../../src/selectors/selector.is-point-after-selection.ts","../../src/selectors/selector.is-point-before-selection.ts"],"sourcesContent":["import type {PortableTextListBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveListItem: EditorSelector<\n PortableTextListBlock['listItem'] | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const guards = createGuards(context)\n const selectedBlocks = getSelectedBlocks({context}).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstListItem = firstTextBlock.listItem\n\n if (!firstListItem) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.listItem === firstListItem)) {\n return firstListItem\n }\n\n return undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveStyle: EditorSelector<PortableTextTextBlock['style']> = ({\n context,\n}) => {\n if (!context.selection) {\n return undefined\n }\n\n const guards = createGuards(context)\n const selectedBlocks = getSelectedBlocks({context}).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstStyle = firstTextBlock.style\n\n if (!firstStyle) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.style === firstStyle)) {\n return firstStyle\n }\n\n return undefined\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextSpan,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelectedSpans: EditorSelector<\n Array<{\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }>\n> = ({context}) => {\n if (!context.selection) {\n return []\n }\n\n const selectedSpans: Array<{\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }> = []\n\n const startPoint = context.selection.backward\n ? context.selection.focus\n : context.selection.anchor\n const endPoint = context.selection.backward\n ? context.selection.anchor\n : context.selection.focus\n\n const startBlockKey = isKeySegment(startPoint.path[0])\n ? startPoint.path[0]._key\n : undefined\n const endBlockKey = isKeySegment(endPoint.path[0])\n ? endPoint.path[0]._key\n : undefined\n\n if (!startBlockKey || !endBlockKey) {\n return selectedSpans\n }\n\n const startSpanKey = isKeySegment(startPoint.path[2])\n ? startPoint.path[2]._key\n : undefined\n const endSpanKey = isKeySegment(endPoint.path[2])\n ? endPoint.path[2]._key\n : undefined\n\n for (const block of context.value) {\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n if (block._key === startBlockKey) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (startSpanKey && child._key === startSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n\n if (startSpanKey === endSpanKey) {\n break\n }\n\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n break\n }\n\n if (selectedSpans.length > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n if (block._key === endBlockKey) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n break\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n\n break\n }\n\n if (selectedSpans.length > 0) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n }\n\n return selectedSpans\n}\n","import {isPortableTextTextBlock} 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 function isActiveAnnotation(\n annotation: string,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const selectedSpans = getSelectedSpans(snapshot)\n\n if (selectedSpans.length === 0) {\n return false\n }\n\n if (\n selectedSpans.some(\n (span) => !span.node.marks || span.node.marks?.length === 0,\n )\n ) {\n return false\n }\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isPortableTextTextBlock(block.node) ? (block.node.markDefs ?? []) : [],\n )\n\n return selectedSpans.every((span) => {\n const spanMarkDefs =\n span.node.marks?.flatMap((mark) => {\n const markDef = selectionMarkDefs.find(\n (markDef) => markDef._key === mark,\n )\n\n return markDef ? [markDef._type] : []\n }) ?? []\n\n return spanMarkDefs.includes(annotation)\n })\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const isSelectionExpanded: EditorSelector<boolean> = ({context}) => {\n return !isSelectionCollapsed({context})\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\n\n/**\n * @public\n */\nexport function isActiveDecorator(decorator: string): EditorSelector<boolean> {\n return (snapshot) => {\n if (isSelectionExpanded(snapshot)) {\n const selectedSpans = getSelectedSpans(snapshot)\n\n return (\n selectedSpans.length > 0 &&\n selectedSpans.every((span) => span.node.marks?.includes(decorator))\n )\n }\n\n return snapshot.context.activeDecorators.includes(decorator)\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveListItem} from './selector.get-active-list-item'\n\n/**\n * @public\n */\nexport function isActiveListItem(listItem: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeListItem = getActiveListItem(snapshot)\n\n return activeListItem === listItem\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveStyle} from './selector.get-active-style'\n\n/**\n * @public\n */\nexport function isActiveStyle(style: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeStyle = getActiveStyle(snapshot)\n\n return activeStyle === style\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 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":["getActiveListItem","context","selection","guards","createGuards","selectedTextBlocks","getSelectedBlocks","map","block","node","filter","isTextBlock","firstTextBlock","at","firstListItem","listItem","every","getActiveStyle","firstStyle","style","getSelectedSpans","selectedSpans","startPoint","backward","focus","anchor","endPoint","startBlockKey","isKeySegment","path","_key","undefined","endBlockKey","startSpanKey","endSpanKey","value","isPortableTextTextBlock","child","children","isPortableTextSpan","push","length","isActiveAnnotation","annotation","snapshot","selectedBlocks","some","span","marks","selectionMarkDefs","flatMap","markDefs","mark","markDef","find","_type","includes","isSelectionExpanded","isSelectionCollapsed","isActiveDecorator","decorator","activeDecorators","isActiveListItem","isActiveStyle","isPointAfterSelection","point","reverseSelection","pointBlockKey","pointChildKey","endChildKey","after","offset","isPointBeforeSelection","startChildKey","before"],"mappings":";;;AAQO,MAAMA,oBAETA,CAAC;AAAA,EAACC;AAAO,MAAM;AACjB,MAAI,CAACA,QAAQC;AACX;AAGF,QAAMC,SAASC,8BAAAA,aAAaH,OAAO,GAE7BI,qBADiBC,8BAAAA,kBAAkB;AAAA,IAACL;AAAAA,EAAQ,CAAA,EAAEM,IAAKC,CAAAA,UAAUA,MAAMC,IAAI,EACnCC,OAAOP,OAAOQ,WAAW,GAE7DC,iBAAiBP,mBAAmBQ,GAAG,CAAC;AAE9C,MAAI,CAACD;AACH;AAGF,QAAME,gBAAgBF,eAAeG;AAErC,MAAKD,iBAIDT,mBAAmBW,MAAOR,CAAUA,UAAAA,MAAMO,aAAaD,aAAa;AAC/DA,WAAAA;AAIX,GC5BaG,iBAAiEA,CAAC;AAAA,EAC7EhB;AACF,MAAM;AACJ,MAAI,CAACA,QAAQC;AACX;AAGF,QAAMC,SAASC,8BAAAA,aAAaH,OAAO,GAE7BI,qBADiBC,8BAAAA,kBAAkB;AAAA,IAACL;AAAAA,EAAQ,CAAA,EAAEM,IAAKC,CAAAA,UAAUA,MAAMC,IAAI,EACnCC,OAAOP,OAAOQ,WAAW,GAE7DC,iBAAiBP,mBAAmBQ,GAAG,CAAC;AAE9C,MAAI,CAACD;AACH;AAGF,QAAMM,aAAaN,eAAeO;AAElC,MAAKD,cAIDb,mBAAmBW,MAAOR,CAAUA,UAAAA,MAAMW,UAAUD,UAAU;AACzDA,WAAAA;AAIX,GCxBaE,mBAKTA,CAAC;AAAA,EAACnB;AAAO,MAAM;AACjB,MAAI,CAACA,QAAQC;AACX,WAAO,CAAE;AAGLmB,QAAAA,gBAGD,IAECC,aAAarB,QAAQC,UAAUqB,WACjCtB,QAAQC,UAAUsB,QAClBvB,QAAQC,UAAUuB,QAChBC,WAAWzB,QAAQC,UAAUqB,WAC/BtB,QAAQ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MAAMsB,SAASH;AACjB;AAAA,IAAA;AAIG+C,WAAAA;AAAAA,EACT;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -260,6 +260,20 @@ export declare function isActiveListItem(
260
260
  */
261
261
  export declare function isActiveStyle(style: string): EditorSelector<boolean>
262
262
 
263
+ /**
264
+ * @public
265
+ */
266
+ export declare function isPointAfterSelection(
267
+ point: EditorSelectionPoint,
268
+ ): EditorSelector<boolean>
269
+
270
+ /**
271
+ * @public
272
+ */
273
+ export declare function isPointBeforeSelection(
274
+ point: EditorSelectionPoint,
275
+ ): EditorSelector<boolean>
276
+
263
277
  /**
264
278
  * @public
265
279
  */
@@ -260,6 +260,20 @@ export declare function isActiveListItem(
260
260
  */
261
261
  export declare function isActiveStyle(style: string): EditorSelector<boolean>
262
262
 
263
+ /**
264
+ * @public
265
+ */
266
+ export declare function isPointAfterSelection(
267
+ point: EditorSelectionPoint,
268
+ ): EditorSelector<boolean>
269
+
270
+ /**
271
+ * @public
272
+ */
273
+ export declare function isPointBeforeSelection(
274
+ point: EditorSelectionPoint,
275
+ ): EditorSelector<boolean>
276
+
263
277
  /**
264
278
  * @public
265
279
  */
@@ -2,6 +2,7 @@ import { getSelectedBlocks, createGuards, isSelectionCollapsed } from "../_chunk
2
2
  import { getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getNextBlock, getPreviousBlock, getSelectionEndBlock, getSelectionStartBlock } from "../_chunks-es/selector.is-selection-collapsed.js";
3
3
  import { isKeySegment, isPortableTextTextBlock, isPortableTextSpan } from "@sanity/types";
4
4
  import { getBlockTextBefore, getSelectionText } from "../_chunks-es/selector.get-text-before.js";
5
+ import { reverseSelection } from "../_chunks-es/util.get-block-start-point.js";
5
6
  const getActiveListItem = ({
6
7
  context
7
8
  }) => {
@@ -150,6 +151,76 @@ function isActiveListItem(listItem) {
150
151
  function isActiveStyle(style) {
151
152
  return (snapshot) => getActiveStyle(snapshot) === style;
152
153
  }
154
+ function isPointAfterSelection(point) {
155
+ return (snapshot) => {
156
+ if (!snapshot.context.selection)
157
+ return !1;
158
+ const selection = reverseSelection(snapshot.context.selection), pointBlockKey = isKeySegment(point.path[0]) ? point.path[0]._key : void 0, pointChildKey = isKeySegment(point.path[2]) ? point.path[2]._key : void 0, endBlockKey = isKeySegment(selection.focus.path[0]) ? selection.focus.path[0]._key : void 0, endChildKey = isKeySegment(selection.focus.path[2]) ? selection.focus.path[2]._key : void 0;
159
+ if (!pointBlockKey || !endBlockKey)
160
+ return !1;
161
+ let after = !1;
162
+ for (const block of snapshot.context.value) {
163
+ if (block._key === endBlockKey) {
164
+ if (block._key !== pointBlockKey) {
165
+ after = !0;
166
+ break;
167
+ }
168
+ if (!isPortableTextTextBlock(block) || !pointChildKey || !endChildKey)
169
+ break;
170
+ for (const child of block.children) {
171
+ if (child._key === endChildKey) {
172
+ if (child._key !== pointChildKey) {
173
+ after = !0;
174
+ break;
175
+ }
176
+ after = point.offset > selection.focus.offset;
177
+ break;
178
+ }
179
+ if (child._key === pointChildKey)
180
+ break;
181
+ }
182
+ }
183
+ if (block._key === pointBlockKey)
184
+ break;
185
+ }
186
+ return after;
187
+ };
188
+ }
189
+ function isPointBeforeSelection(point) {
190
+ return (snapshot) => {
191
+ if (!snapshot.context.selection)
192
+ return !1;
193
+ const selection = reverseSelection(snapshot.context.selection), pointBlockKey = isKeySegment(point.path[0]) ? point.path[0]._key : void 0, pointChildKey = isKeySegment(point.path[2]) ? point.path[2]._key : void 0, startBlockKey = isKeySegment(selection.anchor.path[0]) ? selection.anchor.path[0]._key : void 0, startChildKey = isKeySegment(selection.anchor.path[2]) ? selection.anchor.path[2]._key : void 0;
194
+ if (!pointBlockKey || !startBlockKey)
195
+ return !1;
196
+ let before = !1;
197
+ for (const block of snapshot.context.value) {
198
+ if (block._key === pointBlockKey) {
199
+ if (block._key !== startBlockKey) {
200
+ before = !0;
201
+ break;
202
+ }
203
+ if (!isPortableTextTextBlock(block) || !pointChildKey || !startChildKey)
204
+ break;
205
+ for (const child of block.children) {
206
+ if (child._key === pointChildKey) {
207
+ if (child._key !== startChildKey) {
208
+ before = !0;
209
+ break;
210
+ }
211
+ before = point.offset < selection.anchor.offset;
212
+ break;
213
+ }
214
+ if (child._key === startChildKey)
215
+ break;
216
+ }
217
+ }
218
+ if (block._key === startBlockKey)
219
+ break;
220
+ }
221
+ return before;
222
+ };
223
+ }
153
224
  export {
154
225
  getActiveListItem,
155
226
  getActiveStyle,
@@ -173,6 +244,8 @@ export {
173
244
  isActiveDecorator,
174
245
  isActiveListItem,
175
246
  isActiveStyle,
247
+ isPointAfterSelection,
248
+ isPointBeforeSelection,
176
249
  isSelectionCollapsed,
177
250
  isSelectionExpanded
178
251
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-active-list-item.ts","../../src/selectors/selector.get-active-style.ts","../../src/selectors/selector.get-selected-spans.ts","../../src/selectors/selector.is-active-annotation.ts","../../src/selectors/selector.is-selection-expanded.ts","../../src/selectors/selector.is-active-decorator.ts","../../src/selectors/selector.is-active-list-item.ts","../../src/selectors/selector.is-active-style.ts"],"sourcesContent":["import type {PortableTextListBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveListItem: EditorSelector<\n PortableTextListBlock['listItem'] | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const guards = createGuards(context)\n const selectedBlocks = getSelectedBlocks({context}).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstListItem = firstTextBlock.listItem\n\n if (!firstListItem) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.listItem === firstListItem)) {\n return firstListItem\n }\n\n return undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveStyle: EditorSelector<PortableTextTextBlock['style']> = ({\n context,\n}) => {\n if (!context.selection) {\n return undefined\n }\n\n const guards = createGuards(context)\n const selectedBlocks = getSelectedBlocks({context}).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstStyle = firstTextBlock.style\n\n if (!firstStyle) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.style === firstStyle)) {\n return firstStyle\n }\n\n return undefined\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextSpan,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelectedSpans: EditorSelector<\n Array<{\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }>\n> = ({context}) => {\n if (!context.selection) {\n return []\n }\n\n const selectedSpans: Array<{\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }> = []\n\n const startPoint = context.selection.backward\n ? context.selection.focus\n : context.selection.anchor\n const endPoint = context.selection.backward\n ? context.selection.anchor\n : context.selection.focus\n\n const startBlockKey = isKeySegment(startPoint.path[0])\n ? startPoint.path[0]._key\n : undefined\n const endBlockKey = isKeySegment(endPoint.path[0])\n ? endPoint.path[0]._key\n : undefined\n\n if (!startBlockKey || !endBlockKey) {\n return selectedSpans\n }\n\n const startSpanKey = isKeySegment(startPoint.path[2])\n ? startPoint.path[2]._key\n : undefined\n const endSpanKey = isKeySegment(endPoint.path[2])\n ? endPoint.path[2]._key\n : undefined\n\n for (const block of context.value) {\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n if (block._key === startBlockKey) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (startSpanKey && child._key === startSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n\n if (startSpanKey === endSpanKey) {\n break\n }\n\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n break\n }\n\n if (selectedSpans.length > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n if (block._key === endBlockKey) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n break\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n\n break\n }\n\n if (selectedSpans.length > 0) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n }\n\n return selectedSpans\n}\n","import {isPortableTextTextBlock} 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 function isActiveAnnotation(\n annotation: string,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const selectedSpans = getSelectedSpans(snapshot)\n\n if (selectedSpans.length === 0) {\n return false\n }\n\n if (\n selectedSpans.some(\n (span) => !span.node.marks || span.node.marks?.length === 0,\n )\n ) {\n return false\n }\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isPortableTextTextBlock(block.node) ? (block.node.markDefs ?? []) : [],\n )\n\n return selectedSpans.every((span) => {\n const spanMarkDefs =\n span.node.marks?.flatMap((mark) => {\n const markDef = selectionMarkDefs.find(\n (markDef) => markDef._key === mark,\n )\n\n return markDef ? [markDef._type] : []\n }) ?? []\n\n return spanMarkDefs.includes(annotation)\n })\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const isSelectionExpanded: EditorSelector<boolean> = ({context}) => {\n return !isSelectionCollapsed({context})\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\n\n/**\n * @public\n */\nexport function isActiveDecorator(decorator: string): EditorSelector<boolean> {\n return (snapshot) => {\n if (isSelectionExpanded(snapshot)) {\n const selectedSpans = getSelectedSpans(snapshot)\n\n return (\n selectedSpans.length > 0 &&\n selectedSpans.every((span) => span.node.marks?.includes(decorator))\n )\n }\n\n return snapshot.context.activeDecorators.includes(decorator)\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveListItem} from './selector.get-active-list-item'\n\n/**\n * @public\n */\nexport function isActiveListItem(listItem: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeListItem = getActiveListItem(snapshot)\n\n return activeListItem === listItem\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveStyle} from './selector.get-active-style'\n\n/**\n * @public\n */\nexport function isActiveStyle(style: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeStyle = getActiveStyle(snapshot)\n\n return activeStyle === style\n }\n}\n"],"names":["getActiveListItem","context","selection","guards","createGuards","selectedTextBlocks","getSelectedBlocks","map","block","node","filter","isTextBlock","firstTextBlock","at","firstListItem","listItem","every","getActiveStyle","firstStyle","style","getSelectedSpans","selectedSpans","startPoint","backward","focus","anchor","endPoint","startBlockKey","isKeySegment","path","_key","undefined","endBlockKey","startSpanKey","endSpanKey","value","isPortableTextTextBlock","child","children","isPortableTextSpan","push","length","isActiveAnnotation","annotation","snapshot","selectedBlocks","some","span","marks","selectionMarkDefs","flatMap","markDefs","mark","markDef","find","_type","includes","isSelectionExpanded","isSelectionCollapsed","isActiveDecorator","decorator","activeDecorators","isActiveListItem","isActiveStyle"],"mappings":";;;;AAQO,MAAMA,oBAETA,CAAC;AAAA,EAACC;AAAO,MAAM;AACjB,MAAI,CAACA,QAAQC;AACX;AAGF,QAAMC,SAASC,aAAaH,OAAO,GAE7BI,qBADiBC,kBAAkB;AAAA,IAACL;AAAAA,EAAQ,CAAA,EAAEM,IAAKC,CAAAA,UAAUA,MAAMC,IAAI,EACnCC,OAAOP,OAAOQ,WAAW,GAE7DC,iBAAiBP,mBAAmBQ,GAAG,CAAC;AAE9C,MAAI,CAACD;AACH;AAGF,QAAME,gBAAgBF,eAAeG;AAErC,MAAKD,iBAIDT,mBAAmBW,MAAOR,CAAUA,UAAAA,MAAMO,aAAaD,aAAa;AAC/DA,WAAAA;AAIX,GC5BaG,iBAAiEA,CAAC;AAAA,EAC7EhB;AACF,MAAM;AACJ,MAAI,CAACA,QAAQC;AACX;AAGF,QAAMC,SAASC,aAAaH,OAAO,GAE7BI,qBADiBC,kBAAkB;AAAA,IAACL;AAAAA,EAAQ,CAAA,EAAEM,IAAKC,CAAAA,UAAUA,MAAMC,IAAI,EACnCC,OAAOP,OAAOQ,WAAW,GAE7DC,iBAAiBP,mBAAmBQ,GAAG,CAAC;AAE9C,MAAI,CAACD;AACH;AAGF,QAAMM,aAAaN,eAAeO;AAElC,MAAKD,cAIDb,mBAAmBW,MAAOR,CAAUA,UAAAA,MAAMW,UAAUD,UAAU;AACzDA,WAAAA;AAIX,GCxBaE,mBAKTA,CAAC;AAAA,EAACnB;AAAO,MAAM;AACjB,MAAI,CAACA,QAAQC;AACX,WAAO,CAAE;AAGLmB,QAAAA,gBAGD,IA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,cAAc5C,OAAwC;AAC5DyB,SAAAA,CAAAA,aACc3B,eAAe2B,QAAQ,MAEpBzB;AAE3B;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-active-list-item.ts","../../src/selectors/selector.get-active-style.ts","../../src/selectors/selector.get-selected-spans.ts","../../src/selectors/selector.is-active-annotation.ts","../../src/selectors/selector.is-selection-expanded.ts","../../src/selectors/selector.is-active-decorator.ts","../../src/selectors/selector.is-active-list-item.ts","../../src/selectors/selector.is-active-style.ts","../../src/selectors/selector.is-point-after-selection.ts","../../src/selectors/selector.is-point-before-selection.ts"],"sourcesContent":["import type {PortableTextListBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveListItem: EditorSelector<\n PortableTextListBlock['listItem'] | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const guards = createGuards(context)\n const selectedBlocks = getSelectedBlocks({context}).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstListItem = firstTextBlock.listItem\n\n if (!firstListItem) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.listItem === firstListItem)) {\n return firstListItem\n }\n\n return undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveStyle: EditorSelector<PortableTextTextBlock['style']> = ({\n context,\n}) => {\n if (!context.selection) {\n return undefined\n }\n\n const guards = createGuards(context)\n const selectedBlocks = getSelectedBlocks({context}).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstStyle = firstTextBlock.style\n\n if (!firstStyle) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.style === firstStyle)) {\n return firstStyle\n }\n\n return undefined\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextSpan,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelectedSpans: EditorSelector<\n Array<{\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }>\n> = ({context}) => {\n if (!context.selection) {\n return []\n }\n\n const selectedSpans: Array<{\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }> = []\n\n const startPoint = context.selection.backward\n ? context.selection.focus\n : context.selection.anchor\n const endPoint = context.selection.backward\n ? context.selection.anchor\n : context.selection.focus\n\n const startBlockKey = isKeySegment(startPoint.path[0])\n ? startPoint.path[0]._key\n : undefined\n const endBlockKey = isKeySegment(endPoint.path[0])\n ? endPoint.path[0]._key\n : undefined\n\n if (!startBlockKey || !endBlockKey) {\n return selectedSpans\n }\n\n const startSpanKey = isKeySegment(startPoint.path[2])\n ? startPoint.path[2]._key\n : undefined\n const endSpanKey = isKeySegment(endPoint.path[2])\n ? endPoint.path[2]._key\n : undefined\n\n for (const block of context.value) {\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n if (block._key === startBlockKey) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (startSpanKey && child._key === startSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n\n if (startSpanKey === endSpanKey) {\n break\n }\n\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n break\n }\n\n if (selectedSpans.length > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n if (block._key === endBlockKey) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n break\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n\n break\n }\n\n if (selectedSpans.length > 0) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n }\n\n return selectedSpans\n}\n","import {isPortableTextTextBlock} 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 function isActiveAnnotation(\n annotation: string,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const selectedSpans = getSelectedSpans(snapshot)\n\n if (selectedSpans.length === 0) {\n return false\n }\n\n if (\n selectedSpans.some(\n (span) => !span.node.marks || span.node.marks?.length === 0,\n )\n ) {\n return false\n }\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isPortableTextTextBlock(block.node) ? (block.node.markDefs ?? []) : [],\n )\n\n return selectedSpans.every((span) => {\n const spanMarkDefs =\n span.node.marks?.flatMap((mark) => {\n const markDef = selectionMarkDefs.find(\n (markDef) => markDef._key === mark,\n )\n\n return markDef ? [markDef._type] : []\n }) ?? []\n\n return spanMarkDefs.includes(annotation)\n })\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const isSelectionExpanded: EditorSelector<boolean> = ({context}) => {\n return !isSelectionCollapsed({context})\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\n\n/**\n * @public\n */\nexport function isActiveDecorator(decorator: string): EditorSelector<boolean> {\n return (snapshot) => {\n if (isSelectionExpanded(snapshot)) {\n const selectedSpans = getSelectedSpans(snapshot)\n\n return (\n selectedSpans.length > 0 &&\n selectedSpans.every((span) => span.node.marks?.includes(decorator))\n )\n }\n\n return snapshot.context.activeDecorators.includes(decorator)\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveListItem} from './selector.get-active-list-item'\n\n/**\n * @public\n */\nexport function isActiveListItem(listItem: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeListItem = getActiveListItem(snapshot)\n\n return activeListItem === listItem\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveStyle} from './selector.get-active-style'\n\n/**\n * @public\n */\nexport function isActiveStyle(style: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeStyle = getActiveStyle(snapshot)\n\n return activeStyle === style\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 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":["getActiveListItem","context","selection","guards","createGuards","selectedTextBlocks","getSelectedBlocks","map","block","node","filter","isTextBlock","firstTextBlock","at","firstListItem","listItem","every","getActiveStyle","firstStyle","style","getSelectedSpans","selectedSpans","startPoint","backward","focus","anchor","endPoint","startBlockKey","isKeySegment","path","_key","undefined","endBlockKey","startSpanKey","endSpanKey","value","isPortableTextTextBlock","child","children","isPortableTextSpan","push","length","isActiveAnnotation","annotation","snapshot","selectedBlocks","some","span","marks","selectionMarkDefs","flatMap","markDefs","mark","markDef","find","_type","includes","isSelectionExpanded","isSelectionCollapsed","isActiveDecorator","decorator","activeDecorators","isActiveListItem","isActiveStyle","isPointAfterSelection","point","reverseSelection","pointBlockKey","pointChildKey","endChildKey","after","offset","isPointBeforeSelection","startChildKey","before"],"mappings":";;;;;AAQO,MAAMA,oBAETA,CAAC;AAAA,EAACC;AAAO,MAAM;AACjB,MAAI,CAACA,QAAQC;AACX;AAGF,QAAMC,SAASC,aAAaH,OAAO,GAE7BI,qBADiBC,kBAAkB;AAAA,IAACL;AAAAA,EAAQ,CAAA,EAAEM,IAAKC,CAAAA,UAAUA,MAAMC,IAAI,EACnCC,OAAOP,OAAOQ,WAAW,GAE7DC,iBAAiBP,mBAAmBQ,GAAG,CAAC;AAE9C,MAAI,CAACD;AACH;AAGF,QAAME,gBAAgBF,eAAeG;AAErC,MAAKD,iBAIDT,mBAAmBW,MAAOR,CAAUA,UAAAA,MAAMO,aAAaD,aAAa;AAC/DA,WAAAA;AAIX,GC5BaG,iBAAiEA,CAAC;AAAA,EAC7EhB;AACF,MAAM;AACJ,MAAI,CAACA,QAAQC;AACX;AAGF,QAAMC,SAASC,aAAaH,OAAO,GAE7BI,qBADiBC,kBAAkB;AAAA,IAACL;AAAAA,EAAQ,CAAA,EAAEM,IAAKC,CAAAA,UAAUA,MAAMC,IAAI,EACnCC,O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AAAA,SAAS7B,MAAM8B,UAAU;AAC9BD,cAAAA,MAAMP,SAASsC,eAAe;AAC5B/B,gBAAAA,MAAMP,SAAS2C,eAAe;AACvB,uBAAA;AACT;AAAA,YAAA;AAKOR,qBAAAA,MAAMM,SAASrE,UAAUuB,OAAO8C;AACzC;AAAA,UAAA;AAGF,cAAIlC,MAAMP,SAAS2C;AACjB;AAAA,QAAA;AAAA,MAEJ;AAGF,UAAIjE,MAAMsB,SAASH;AACjB;AAAA,IAAA;AAIG+C,WAAAA;AAAAA,EACT;AACF;"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: !0 });
3
+ var util_isEmptyTextBlock = require("../_chunks-cjs/util.is-empty-text-block.cjs"), util_getBlockStartPoint = require("../_chunks-cjs/util.get-block-start-point.cjs"), util_isKeyedSegment = require("../_chunks-cjs/util.is-keyed-segment.cjs");
4
+ exports.blockOffsetToSpanSelectionPoint = util_isEmptyTextBlock.blockOffsetToSpanSelectionPoint;
5
+ exports.getTextBlockText = util_isEmptyTextBlock.getTextBlockText;
6
+ exports.isEmptyTextBlock = util_isEmptyTextBlock.isEmptyTextBlock;
7
+ exports.spanSelectionPointToBlockOffset = util_isEmptyTextBlock.spanSelectionPointToBlockOffset;
8
+ exports.getBlockStartPoint = util_getBlockStartPoint.getBlockStartPoint;
9
+ exports.reverseSelection = util_getBlockStartPoint.reverseSelection;
10
+ exports.isKeyedSegment = util_isKeyedSegment.isKeyedSegment;
11
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
@@ -0,0 +1,87 @@
1
+ import {KeyedSegment, PortableTextBlock} from '@sanity/types'
2
+ import type {Path, PathSegment, PortableTextTextBlock} from '@sanity/types'
3
+
4
+ /**
5
+ * @beta
6
+ */
7
+ export declare type BlockOffset = {
8
+ path: [KeyedSegment]
9
+ offset: number
10
+ }
11
+
12
+ /**
13
+ * @public
14
+ */
15
+ export declare function blockOffsetToSpanSelectionPoint({
16
+ value,
17
+ blockOffset,
18
+ }: {
19
+ value: Array<PortableTextBlock>
20
+ blockOffset: BlockOffset
21
+ }):
22
+ | {
23
+ path: [KeyedSegment, 'children', KeyedSegment]
24
+ offset: number
25
+ }
26
+ | undefined
27
+
28
+ /** @public */
29
+ export declare type EditorSelection = {
30
+ anchor: EditorSelectionPoint
31
+ focus: EditorSelectionPoint
32
+ backward?: boolean
33
+ } | null
34
+
35
+ /** @public */
36
+ export declare type EditorSelectionPoint = {
37
+ path: Path
38
+ offset: number
39
+ }
40
+
41
+ /**
42
+ * @public
43
+ */
44
+ export declare function getBlockStartPoint({
45
+ node,
46
+ path,
47
+ }: {
48
+ node: PortableTextBlock
49
+ path: [KeyedSegment]
50
+ }): EditorSelectionPoint
51
+
52
+ /**
53
+ * @public
54
+ */
55
+ export declare function getTextBlockText(block: PortableTextTextBlock): string
56
+
57
+ /**
58
+ * @public
59
+ */
60
+ export declare function isEmptyTextBlock(block: PortableTextBlock): boolean
61
+
62
+ /**
63
+ * @public
64
+ */
65
+ export declare function isKeyedSegment(
66
+ segment: PathSegment,
67
+ ): segment is KeyedSegment
68
+
69
+ /**
70
+ * @public
71
+ */
72
+ export declare function reverseSelection(
73
+ selection: NonNullable<EditorSelection>,
74
+ ): NonNullable<EditorSelection>
75
+
76
+ /**
77
+ * @public
78
+ */
79
+ export declare function spanSelectionPointToBlockOffset({
80
+ value,
81
+ selectionPoint,
82
+ }: {
83
+ value: Array<PortableTextBlock>
84
+ selectionPoint: EditorSelectionPoint
85
+ }): BlockOffset | undefined
86
+
87
+ export {}
@@ -0,0 +1,87 @@
1
+ import {KeyedSegment, PortableTextBlock} from '@sanity/types'
2
+ import type {Path, PathSegment, PortableTextTextBlock} from '@sanity/types'
3
+
4
+ /**
5
+ * @beta
6
+ */
7
+ export declare type BlockOffset = {
8
+ path: [KeyedSegment]
9
+ offset: number
10
+ }
11
+
12
+ /**
13
+ * @public
14
+ */
15
+ export declare function blockOffsetToSpanSelectionPoint({
16
+ value,
17
+ blockOffset,
18
+ }: {
19
+ value: Array<PortableTextBlock>
20
+ blockOffset: BlockOffset
21
+ }):
22
+ | {
23
+ path: [KeyedSegment, 'children', KeyedSegment]
24
+ offset: number
25
+ }
26
+ | undefined
27
+
28
+ /** @public */
29
+ export declare type EditorSelection = {
30
+ anchor: EditorSelectionPoint
31
+ focus: EditorSelectionPoint
32
+ backward?: boolean
33
+ } | null
34
+
35
+ /** @public */
36
+ export declare type EditorSelectionPoint = {
37
+ path: Path
38
+ offset: number
39
+ }
40
+
41
+ /**
42
+ * @public
43
+ */
44
+ export declare function getBlockStartPoint({
45
+ node,
46
+ path,
47
+ }: {
48
+ node: PortableTextBlock
49
+ path: [KeyedSegment]
50
+ }): EditorSelectionPoint
51
+
52
+ /**
53
+ * @public
54
+ */
55
+ export declare function getTextBlockText(block: PortableTextTextBlock): string
56
+
57
+ /**
58
+ * @public
59
+ */
60
+ export declare function isEmptyTextBlock(block: PortableTextBlock): boolean
61
+
62
+ /**
63
+ * @public
64
+ */
65
+ export declare function isKeyedSegment(
66
+ segment: PathSegment,
67
+ ): segment is KeyedSegment
68
+
69
+ /**
70
+ * @public
71
+ */
72
+ export declare function reverseSelection(
73
+ selection: NonNullable<EditorSelection>,
74
+ ): NonNullable<EditorSelection>
75
+
76
+ /**
77
+ * @public
78
+ */
79
+ export declare function spanSelectionPointToBlockOffset({
80
+ value,
81
+ selectionPoint,
82
+ }: {
83
+ value: Array<PortableTextBlock>
84
+ selectionPoint: EditorSelectionPoint
85
+ }): BlockOffset | undefined
86
+
87
+ export {}
@@ -0,0 +1,13 @@
1
+ import { blockOffsetToSpanSelectionPoint, getTextBlockText, isEmptyTextBlock, spanSelectionPointToBlockOffset } from "../_chunks-es/util.is-empty-text-block.js";
2
+ import { getBlockStartPoint, reverseSelection } from "../_chunks-es/util.get-block-start-point.js";
3
+ import { isKeyedSegment } from "../_chunks-es/util.is-keyed-segment.js";
4
+ export {
5
+ blockOffsetToSpanSelectionPoint,
6
+ getBlockStartPoint,
7
+ getTextBlockText,
8
+ isEmptyTextBlock,
9
+ isKeyedSegment,
10
+ reverseSelection,
11
+ spanSelectionPointToBlockOffset
12
+ };
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}