@portabletext/editor 1.33.3 → 1.33.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +11 -204
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/behavior.markdown.cjs +7 -7
  4. package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
  5. package/lib/_chunks-cjs/plugin.event-listener.cjs +196 -25
  6. package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -1
  7. package/lib/_chunks-cjs/selector.get-text-before.cjs +3 -3
  8. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  9. package/lib/_chunks-cjs/selector.is-active-style.cjs +246 -0
  10. package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -0
  11. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +23 -198
  12. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
  13. package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs +3 -3
  14. package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs.map +1 -1
  15. package/lib/_chunks-cjs/util.reverse-selection.cjs +0 -135
  16. package/lib/_chunks-cjs/util.reverse-selection.cjs.map +1 -1
  17. package/lib/_chunks-cjs/util.slice-blocks.cjs +138 -1
  18. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  19. package/lib/_chunks-es/behavior.core.js +9 -202
  20. package/lib/_chunks-es/behavior.core.js.map +1 -1
  21. package/lib/_chunks-es/behavior.markdown.js +1 -1
  22. package/lib/_chunks-es/plugin.event-listener.js +193 -23
  23. package/lib/_chunks-es/plugin.event-listener.js.map +1 -1
  24. package/lib/_chunks-es/selector.get-text-before.js +2 -1
  25. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  26. package/lib/_chunks-es/selector.is-active-style.js +249 -0
  27. package/lib/_chunks-es/selector.is-active-style.js.map +1 -0
  28. package/lib/_chunks-es/selector.is-at-the-start-of-block.js +12 -187
  29. package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
  30. package/lib/_chunks-es/util.block-offsets-to-selection.js +1 -1
  31. package/lib/_chunks-es/util.reverse-selection.js +1 -136
  32. package/lib/_chunks-es/util.reverse-selection.js.map +1 -1
  33. package/lib/_chunks-es/util.slice-blocks.js +140 -3
  34. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  35. package/lib/index.d.cts +1 -115
  36. package/lib/index.d.ts +1 -115
  37. package/lib/plugins/index.cjs +11 -11
  38. package/lib/plugins/index.cjs.map +1 -1
  39. package/lib/plugins/index.d.cts +1 -115
  40. package/lib/plugins/index.d.ts +1 -115
  41. package/lib/plugins/index.js +1 -1
  42. package/lib/selectors/index.cjs +16 -21
  43. package/lib/selectors/index.cjs.map +1 -1
  44. package/lib/selectors/index.js +7 -11
  45. package/lib/selectors/index.js.map +1 -1
  46. package/lib/utils/index.cjs +13 -13
  47. package/lib/utils/index.cjs.map +1 -1
  48. package/lib/utils/index.js +3 -3
  49. package/package.json +1 -1
  50. package/src/behaviors/behavior.core.annotations.ts +0 -24
  51. package/src/behaviors/behavior.core.decorators.ts +0 -19
  52. package/src/behaviors/behavior.core.insert-break.ts +4 -4
  53. package/src/behaviors/behavior.core.lists.ts +0 -30
  54. package/src/behaviors/behavior.core.ts +2 -17
  55. package/src/behaviors/behavior.default.ts +198 -0
  56. package/src/behaviors/behavior.foundational.ts +12 -12
  57. package/src/converters/converter.text-html.serialize.test.ts +1 -1
  58. package/src/editor/editor-machine.ts +8 -8
  59. package/src/selectors/selector.get-selection-text.ts +14 -89
  60. package/src/utils/util.slice-blocks.ts +12 -1
  61. package/lib/_chunks-cjs/selector.get-trimmed-selection.cjs +0 -97
  62. package/lib/_chunks-cjs/selector.get-trimmed-selection.cjs.map +0 -1
  63. package/lib/_chunks-es/selector.get-trimmed-selection.js +0 -100
  64. package/lib/_chunks-es/selector.get-trimmed-selection.js.map +0 -1
  65. package/src/behaviors/behavior.core.deserialize.ts +0 -60
  66. package/src/behaviors/behavior.core.serialize.ts +0 -44
  67. package/src/behaviors/behavior.core.style.ts +0 -19
@@ -46,12 +46,10 @@ import {
46
46
  } from 'xstate'
47
47
  import {GuardArgs} from 'xstate/guards'
48
48
  import {
49
- BehaviorEvent as BehaviorEvent_2,
50
49
  BlockOffset as BlockOffset_2,
51
50
  PortableTextMemberSchemaTypes as PortableTextMemberSchemaTypes_2,
52
51
  } from '..'
53
52
  import {MIMEType as MIMEType_2} from '../internal-utils/mime-type'
54
- import {PickFromUnion as PickFromUnion_2} from '../type-utils'
55
53
 
56
54
  /**
57
55
  * @beta
@@ -1872,119 +1870,7 @@ declare const editorMachine: StateMachine<
1872
1870
  AnyEventObject
1873
1871
  >
1874
1872
  }) => {
1875
- behaviors: Set<
1876
- Behavior<
1877
- | 'focus'
1878
- | 'delete'
1879
- | 'select'
1880
- | 'serialize'
1881
- | 'copy'
1882
- | 'serialization.failure'
1883
- | 'serialization.success'
1884
- | 'deserialize'
1885
- | 'deserialization.failure'
1886
- | 'deserialization.success'
1887
- | 'annotation.add'
1888
- | 'annotation.remove'
1889
- | 'annotation.toggle'
1890
- | 'block.set'
1891
- | 'block.unset'
1892
- | 'blur'
1893
- | 'data transfer.set'
1894
- | 'decorator.add'
1895
- | 'decorator.remove'
1896
- | 'decorator.toggle'
1897
- | 'delete.backward'
1898
- | 'delete.block'
1899
- | 'delete.forward'
1900
- | 'delete.text'
1901
- | 'history.redo'
1902
- | 'history.undo'
1903
- | 'insert.blocks'
1904
- | 'insert.block object'
1905
- | 'insert.inline object'
1906
- | 'insert.break'
1907
- | 'insert.soft break'
1908
- | 'insert.block'
1909
- | 'insert.span'
1910
- | 'insert.text'
1911
- | 'insert.text block'
1912
- | 'list item.add'
1913
- | 'list item.remove'
1914
- | 'list item.toggle'
1915
- | 'move.block'
1916
- | 'move.block down'
1917
- | 'move.block up'
1918
- | 'select.previous block'
1919
- | 'select.next block'
1920
- | 'style.add'
1921
- | 'style.remove'
1922
- | 'style.toggle'
1923
- | 'text block.set'
1924
- | 'text block.unset'
1925
- | 'key.down'
1926
- | 'key.up'
1927
- | 'paste'
1928
- | `custom.${string}`,
1929
- true,
1930
- PickFromUnion_2<
1931
- BehaviorEvent_2,
1932
- 'type',
1933
- | 'focus'
1934
- | 'delete'
1935
- | 'select'
1936
- | 'serialize'
1937
- | 'copy'
1938
- | 'serialization.failure'
1939
- | 'serialization.success'
1940
- | 'deserialize'
1941
- | 'deserialization.failure'
1942
- | 'deserialization.success'
1943
- | 'annotation.add'
1944
- | 'annotation.remove'
1945
- | 'annotation.toggle'
1946
- | 'block.set'
1947
- | 'block.unset'
1948
- | 'blur'
1949
- | 'data transfer.set'
1950
- | 'decorator.add'
1951
- | 'decorator.remove'
1952
- | 'decorator.toggle'
1953
- | 'delete.backward'
1954
- | 'delete.block'
1955
- | 'delete.forward'
1956
- | 'delete.text'
1957
- | 'history.redo'
1958
- | 'history.undo'
1959
- | 'insert.blocks'
1960
- | 'insert.block object'
1961
- | 'insert.inline object'
1962
- | 'insert.break'
1963
- | 'insert.soft break'
1964
- | 'insert.block'
1965
- | 'insert.span'
1966
- | 'insert.text'
1967
- | 'insert.text block'
1968
- | 'list item.add'
1969
- | 'list item.remove'
1970
- | 'list item.toggle'
1971
- | 'move.block'
1972
- | 'move.block down'
1973
- | 'move.block up'
1974
- | 'select.previous block'
1975
- | 'select.next block'
1976
- | 'style.add'
1977
- | 'style.remove'
1978
- | 'style.toggle'
1979
- | 'text block.set'
1980
- | 'text block.unset'
1981
- | 'key.down'
1982
- | 'key.up'
1983
- | 'paste'
1984
- | `custom.${string}`
1985
- >
1986
- >
1987
- >
1873
+ behaviors: Set<Behavior>
1988
1874
  converters: Set<Converter>
1989
1875
  keyGenerator: () => string
1990
1876
  pendingEvents: never[]
@@ -46,12 +46,10 @@ import {
46
46
  } from 'xstate'
47
47
  import {GuardArgs} from 'xstate/guards'
48
48
  import {
49
- BehaviorEvent as BehaviorEvent_2,
50
49
  BlockOffset as BlockOffset_2,
51
50
  PortableTextMemberSchemaTypes as PortableTextMemberSchemaTypes_2,
52
51
  } from '..'
53
52
  import {MIMEType as MIMEType_2} from '../internal-utils/mime-type'
54
- import {PickFromUnion as PickFromUnion_2} from '../type-utils'
55
53
 
56
54
  /**
57
55
  * @beta
@@ -1872,119 +1870,7 @@ declare const editorMachine: StateMachine<
1872
1870
  AnyEventObject
1873
1871
  >
1874
1872
  }) => {
1875
- behaviors: Set<
1876
- Behavior<
1877
- | 'focus'
1878
- | 'delete'
1879
- | 'select'
1880
- | 'serialize'
1881
- | 'copy'
1882
- | 'serialization.failure'
1883
- | 'serialization.success'
1884
- | 'deserialize'
1885
- | 'deserialization.failure'
1886
- | 'deserialization.success'
1887
- | 'annotation.add'
1888
- | 'annotation.remove'
1889
- | 'annotation.toggle'
1890
- | 'block.set'
1891
- | 'block.unset'
1892
- | 'blur'
1893
- | 'data transfer.set'
1894
- | 'decorator.add'
1895
- | 'decorator.remove'
1896
- | 'decorator.toggle'
1897
- | 'delete.backward'
1898
- | 'delete.block'
1899
- | 'delete.forward'
1900
- | 'delete.text'
1901
- | 'history.redo'
1902
- | 'history.undo'
1903
- | 'insert.blocks'
1904
- | 'insert.block object'
1905
- | 'insert.inline object'
1906
- | 'insert.break'
1907
- | 'insert.soft break'
1908
- | 'insert.block'
1909
- | 'insert.span'
1910
- | 'insert.text'
1911
- | 'insert.text block'
1912
- | 'list item.add'
1913
- | 'list item.remove'
1914
- | 'list item.toggle'
1915
- | 'move.block'
1916
- | 'move.block down'
1917
- | 'move.block up'
1918
- | 'select.previous block'
1919
- | 'select.next block'
1920
- | 'style.add'
1921
- | 'style.remove'
1922
- | 'style.toggle'
1923
- | 'text block.set'
1924
- | 'text block.unset'
1925
- | 'key.down'
1926
- | 'key.up'
1927
- | 'paste'
1928
- | `custom.${string}`,
1929
- true,
1930
- PickFromUnion_2<
1931
- BehaviorEvent_2,
1932
- 'type',
1933
- | 'focus'
1934
- | 'delete'
1935
- | 'select'
1936
- | 'serialize'
1937
- | 'copy'
1938
- | 'serialization.failure'
1939
- | 'serialization.success'
1940
- | 'deserialize'
1941
- | 'deserialization.failure'
1942
- | 'deserialization.success'
1943
- | 'annotation.add'
1944
- | 'annotation.remove'
1945
- | 'annotation.toggle'
1946
- | 'block.set'
1947
- | 'block.unset'
1948
- | 'blur'
1949
- | 'data transfer.set'
1950
- | 'decorator.add'
1951
- | 'decorator.remove'
1952
- | 'decorator.toggle'
1953
- | 'delete.backward'
1954
- | 'delete.block'
1955
- | 'delete.forward'
1956
- | 'delete.text'
1957
- | 'history.redo'
1958
- | 'history.undo'
1959
- | 'insert.blocks'
1960
- | 'insert.block object'
1961
- | 'insert.inline object'
1962
- | 'insert.break'
1963
- | 'insert.soft break'
1964
- | 'insert.block'
1965
- | 'insert.span'
1966
- | 'insert.text'
1967
- | 'insert.text block'
1968
- | 'list item.add'
1969
- | 'list item.remove'
1970
- | 'list item.toggle'
1971
- | 'move.block'
1972
- | 'move.block down'
1973
- | 'move.block up'
1974
- | 'select.previous block'
1975
- | 'select.next block'
1976
- | 'style.add'
1977
- | 'style.remove'
1978
- | 'style.toggle'
1979
- | 'text block.set'
1980
- | 'text block.unset'
1981
- | 'key.down'
1982
- | 'key.up'
1983
- | 'paste'
1984
- | `custom.${string}`
1985
- >
1986
- >
1987
- >
1873
+ behaviors: Set<Behavior>
1988
1874
  converters: Set<Converter>
1989
1875
  keyGenerator: () => string
1990
1876
  pendingEvents: never[]
@@ -7,7 +7,7 @@ import { useActorRef } from "@xstate/react";
7
7
  import isEqual from "lodash/isEqual.js";
8
8
  import { setup, fromCallback, assign } from "xstate";
9
9
  import { getFocusTextBlock, getSelectionStartPoint, isSelectionExpanded, getSelectionEndPoint } from "../_chunks-es/selector.is-at-the-start-of-block.js";
10
- import { spanSelectionPointToBlockOffset, blockOffsetToSpanSelectionPoint, getBlockStartPoint, getBlockEndPoint, isEqualSelectionPoints } from "../_chunks-es/util.reverse-selection.js";
10
+ import { spanSelectionPointToBlockOffset, blockOffsetToSpanSelectionPoint, getBlockStartPoint, getBlockEndPoint, isEqualSelectionPoints } from "../_chunks-es/util.slice-blocks.js";
11
11
  import { getBlockTextBefore } from "../_chunks-es/selector.get-text-before.js";
12
12
  import { defineBehavior, raise } from "../_chunks-es/behavior.core.js";
13
13
  import { jsx } from "react/jsx-runtime";
@@ -1,15 +1,15 @@
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_reverseSelection = require("../_chunks-cjs/util.reverse-selection.cjs"), util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"), selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs"), selector_getTrimmedSelection = require("../_chunks-cjs/selector.get-trimmed-selection.cjs");
3
+ var types = require("@sanity/types"), selector_isActiveStyle = require("../_chunks-cjs/selector.is-active-style.cjs"), 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");
4
4
  const getActiveAnnotations = (snapshot) => {
5
5
  if (!snapshot.context.selection)
6
6
  return [];
7
- const selectedBlocks = selector_isAtTheStartOfBlock.getSelectedBlocks(snapshot), selectedSpans = selector_isAtTheStartOfBlock.getSelectedSpans(snapshot);
7
+ const selectedBlocks = selector_isAtTheStartOfBlock.getSelectedBlocks(snapshot), selectedSpans = selector_isActiveStyle.getSelectedSpans(snapshot);
8
8
  return selectedSpans.length === 0 ? [] : selectedBlocks.flatMap((block) => types.isPortableTextTextBlock(block.node) ? block.node.markDefs ?? [] : []).filter((markDef) => selectedSpans.some((span) => span.node.marks?.includes(markDef._key)));
9
9
  }, getAnchorBlock = ({
10
10
  context
11
11
  }) => {
12
- const key = context.selection && util_reverseSelection.isKeyedSegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
12
+ const key = context.selection && util_sliceBlocks.isKeyedSegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
13
13
  return node && key ? {
14
14
  node,
15
15
  path: [{
@@ -34,7 +34,7 @@ const getActiveAnnotations = (snapshot) => {
34
34
  });
35
35
  if (!anchorBlock)
36
36
  return;
37
- const key = context.selection && util_reverseSelection.isKeyedSegment(context.selection.anchor.path[2]) ? context.selection.anchor.path[2]._key : void 0, node = key ? anchorBlock.node.children.find((span) => span._key === key) : void 0;
37
+ const key = context.selection && util_sliceBlocks.isKeyedSegment(context.selection.anchor.path[2]) ? context.selection.anchor.path[2]._key : void 0, node = key ? anchorBlock.node.children.find((span) => span._key === key) : void 0;
38
38
  return node && key ? {
39
39
  node,
40
40
  path: [...anchorBlock.path, "children", {
@@ -63,10 +63,10 @@ const getActiveAnnotations = (snapshot) => {
63
63
  });
64
64
  if (!selectionStartPoint || !selectionEndPoint)
65
65
  return;
66
- const start = util_reverseSelection.spanSelectionPointToBlockOffset({
66
+ const start = util_sliceBlocks.spanSelectionPointToBlockOffset({
67
67
  value: context.value,
68
68
  selectionPoint: selectionStartPoint
69
- }), end = util_reverseSelection.spanSelectionPointToBlockOffset({
69
+ }), end = util_sliceBlocks.spanSelectionPointToBlockOffset({
70
70
  value: context.value,
71
71
  selectionPoint: selectionEndPoint
72
72
  });
@@ -74,12 +74,7 @@ const getActiveAnnotations = (snapshot) => {
74
74
  start,
75
75
  end
76
76
  } : void 0;
77
- }, getSelectedSlice = ({
78
- context
79
- }) => util_sliceBlocks.sliceBlocks({
80
- blocks: context.value,
81
- selection: context.selection
82
- }), getSelection = ({
77
+ }, getSelection = ({
83
78
  context
84
79
  }) => context.selection, getValue = ({
85
80
  context
@@ -178,8 +173,14 @@ function isOverlappingSelection(selection) {
178
173
  }));
179
174
  };
180
175
  }
181
- exports.getActiveListItem = selector_isAtTheStartOfBlock.getActiveListItem;
182
- exports.getActiveStyle = selector_isAtTheStartOfBlock.getActiveStyle;
176
+ exports.getActiveListItem = selector_isActiveStyle.getActiveListItem;
177
+ exports.getActiveStyle = selector_isActiveStyle.getActiveStyle;
178
+ exports.getSelectedSpans = selector_isActiveStyle.getSelectedSpans;
179
+ exports.getTrimmedSelection = selector_isActiveStyle.getTrimmedSelection;
180
+ exports.isActiveAnnotation = selector_isActiveStyle.isActiveAnnotation;
181
+ exports.isActiveDecorator = selector_isActiveStyle.isActiveDecorator;
182
+ exports.isActiveListItem = selector_isActiveStyle.isActiveListItem;
183
+ exports.isActiveStyle = selector_isActiveStyle.isActiveStyle;
183
184
  exports.getCaretWordSelection = selector_isAtTheStartOfBlock.getCaretWordSelection;
184
185
  exports.getFirstBlock = selector_isAtTheStartOfBlock.getFirstBlock;
185
186
  exports.getFocusBlock = selector_isAtTheStartOfBlock.getFocusBlock;
@@ -194,29 +195,23 @@ exports.getNextInlineObject = selector_isAtTheStartOfBlock.getNextInlineObject;
194
195
  exports.getPreviousBlock = selector_isAtTheStartOfBlock.getPreviousBlock;
195
196
  exports.getPreviousInlineObject = selector_isAtTheStartOfBlock.getPreviousInlineObject;
196
197
  exports.getSelectedBlocks = selector_isAtTheStartOfBlock.getSelectedBlocks;
197
- exports.getSelectedSpans = selector_isAtTheStartOfBlock.getSelectedSpans;
198
+ exports.getSelectedSlice = selector_isAtTheStartOfBlock.getSelectedSlice;
198
199
  exports.getSelectionEndBlock = selector_isAtTheStartOfBlock.getSelectionEndBlock;
199
200
  exports.getSelectionEndPoint = selector_isAtTheStartOfBlock.getSelectionEndPoint;
200
201
  exports.getSelectionStartBlock = selector_isAtTheStartOfBlock.getSelectionStartBlock;
201
202
  exports.getSelectionStartPoint = selector_isAtTheStartOfBlock.getSelectionStartPoint;
202
203
  exports.getSelectionText = selector_isAtTheStartOfBlock.getSelectionText;
203
- exports.isActiveAnnotation = selector_isAtTheStartOfBlock.isActiveAnnotation;
204
- exports.isActiveDecorator = selector_isAtTheStartOfBlock.isActiveDecorator;
205
- exports.isActiveListItem = selector_isAtTheStartOfBlock.isActiveListItem;
206
- exports.isActiveStyle = selector_isAtTheStartOfBlock.isActiveStyle;
207
204
  exports.isAtTheEndOfBlock = selector_isAtTheStartOfBlock.isAtTheEndOfBlock;
208
205
  exports.isAtTheStartOfBlock = selector_isAtTheStartOfBlock.isAtTheStartOfBlock;
209
206
  exports.isSelectionCollapsed = selector_isAtTheStartOfBlock.isSelectionCollapsed;
210
207
  exports.isSelectionExpanded = selector_isAtTheStartOfBlock.isSelectionExpanded;
211
208
  exports.getBlockTextBefore = selector_getTextBefore.getBlockTextBefore;
212
- exports.getTrimmedSelection = selector_getTrimmedSelection.getTrimmedSelection;
213
209
  exports.getActiveAnnotations = getActiveAnnotations;
214
210
  exports.getAnchorBlock = getAnchorBlock;
215
211
  exports.getAnchorChild = getAnchorChild;
216
212
  exports.getAnchorSpan = getAnchorSpan;
217
213
  exports.getAnchorTextBlock = getAnchorTextBlock;
218
214
  exports.getBlockOffsets = getBlockOffsets;
219
- exports.getSelectedSlice = getSelectedSlice;
220
215
  exports.getSelection = getSelection;
221
216
  exports.getValue = getValue;
222
217
  exports.isOverlappingSelection = isOverlappingSelection;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-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 {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const key = context.selection\n ? isKeyedSegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const anchorBlock = getAnchorBlock({context})\n\n return anchorBlock && isPortableTextTextBlock(anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n const anchorBlock = getAnchorTextBlock({context})\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = context.selection\n ? isKeyedSegment(context.selection.anchor.path[2])\n ? context.selection.anchor.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = ({context}) => {\n const anchorChild = getAnchorChild({context})\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: utils.BlockOffset; end: utils.BlockOffset} | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint({context})\n const selectionEndPoint = getSelectionEndPoint({context})\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n value: context.value,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n value: context.value,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\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","getAnchorBlock","key","isKeyedSegment","anchor","path","undefined","value","find","getAnchorTextBlock","anchorBlock","getAnchorChild","children","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getSelectedSlice","sliceBlocks","blocks","getSelection","getValue","isPointAfterSelection","point","reverseSelection","pointBlockKey","isKeySegment","pointChildKey","endBlockKey","focus","endChildKey","after","child","offset","isPointBeforeSelection","startBlockKey","startChildKey","before","isOverlappingSelection"],"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,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ChB,QAAA,CAACC,aAAa,CAACD,QAAQC;AAClB,aAAA;AAGT,UAAMkC,sBAAsBC,6BAAAA,uBAAuB;AAAA,MACjDpC,SAAS;AAAA,QACP,GAAGA;AAAAA,QACHC;AAAAA,MAAAA;AAAAA,IACF,CACD,GACKoC,oBAAoBC,kDAAqB;AAAA,MAC7CtC,SAAS;AAAA,QACP,GAAGA;AAAAA,QACHC;AAAAA,MAAAA;AAAAA,IACF,CACD;AAUD,WARI,GAACkC,uBAAuB,CAACE,qBAIzB,CAACW,sBAAsBb,mBAAmB,EAAE;AAAA,MAACnC;AAAAA,IAAAA,CAAQ,KAIrD,CAAC4D,uBAAuBvB,iBAAiB,EAAE;AAAA,MAACrC;AAAAA,IAAAA,CAAQ;AAAA,EAK1D;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-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 {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const key = context.selection\n ? isKeyedSegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const anchorBlock = getAnchorBlock({context})\n\n return anchorBlock && isPortableTextTextBlock(anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n const anchorBlock = getAnchorTextBlock({context})\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = context.selection\n ? isKeyedSegment(context.selection.anchor.path[2])\n ? context.selection.anchor.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = ({context}) => {\n const anchorChild = getAnchorChild({context})\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: utils.BlockOffset; end: utils.BlockOffset} | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint({context})\n const selectionEndPoint = getSelectionEndPoint({context})\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n value: context.value,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n value: context.value,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\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","getAnchorBlock","key","isKeyedSegment","anchor","path","undefined","value","find","getAnchorTextBlock","anchorBlock","getAnchorChild","children","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getSelection","getValue","isPointAfterSelection","point","reverseSelection","pointBlockKey","isKeySegment","pointChildKey","endBlockKey","focus","endChildKey","after","child","offset","isPointBeforeSelection","startBlockKey","startChildKey","before","isOverlappingSelection"],"mappings":";;;AAQO,MAAMA,uBACXC,CACG,aAAA;AACC,MAAA,CAACA,SAASC,QAAQC;AACpB,WAAO,CAAE;AAGX,QAAMC,iBAAiBC,6BAAAA,kBAAkBJ,QAAQ,GAC3CK,gBAAgBC,wCAAiBN,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,iBAETA,CAAC;AAAA,EAACnB;AAAO,MAAM;AACjB,QAAMoB,MAAMpB,QAAQC,aAChBoB,iBAAAA,eAAerB,QAAQC,UAAUqB,OAAOC,KAAK,CAAC,CAAC,IAC7CvB,QAAQC,UAAUqB,OAAOC,KAAK,CAAC,EAAEL,OAEnCM,QAEEd,OAAOU,MACTpB,QAAQyB,MAAMC,KAAMlB,CAAUA,UAAAA,MAAMU,SAASE,GAAG,IAChDI;AAEJ,SAAOd,QAAQU,MAAM;AAAA,IAACV;AAAAA,IAAMa,MAAM,CAAC;AAAA,MAACL,MAAME;AAAAA,IAAI,CAAA;AAAA,EAAA,IAAKI;AACrD,GCVaG,qBAETA,CAAC;AAAA,EAAC3B;AAAO,MAAM;AACjB,QAAM4B,cAAcT,eAAe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,MAAAA,wBAAwBD,KAAK,KAI9B,CAAC0C,iBAAiB,CAACS;AACrB;AAGSJ,mBAAAA,SAAS/C,MAAMsB,UAAU;AAC9ByB,cAAAA,MAAMrC,SAASgC,eAAe;AAC5BK,gBAAAA,MAAMrC,SAASyC,eAAe;AACvB,uBAAA;AACT;AAAA,YAAA;AAKOb,qBAAAA,MAAMU,SAASvD,UAAUqB,OAAOkC;AACzC;AAAA,UAAA;AAGF,cAAID,MAAMrC,SAASyC;AACjB;AAAA,QAAA;AAAA,MAEJ;AAGF,UAAInD,MAAMU,SAASwC;AACjB;AAAA,IAAA;AAIGE,WAAAA;AAAAA,EACT;AACF;ACvEO,SAASC,uBACd5D,WACyB;AACzB,SAAO,CAAC;AAAA,IAACD;AAAAA,EAAAA,MAAa;AAChB,QAAA,CAACC,aAAa,CAACD,QAAQC;AAClB,aAAA;AAGT,UAAMkC,sBAAsBC,6BAAAA,uBAAuB;AAAA,MACjDpC,SAAS;AAAA,QACP,GAAGA;AAAAA,QACHC;AAAAA,MAAAA;AAAAA,IACF,CACD,GACKoC,oBAAoBC,kDAAqB;AAAA,MAC7CtC,SAAS;AAAA,QACP,GAAGA;AAAAA,QACHC;AAAAA,MAAAA;AAAAA,IACF,CACD;AAUD,WARI,GAACkC,uBAAuB,CAACE,qBAIzB,CAACQ,sBAAsBV,mBAAmB,EAAE;AAAA,MAACnC;AAAAA,IAAAA,CAAQ,KAIrD,CAACyD,uBAAuBpB,iBAAiB,EAAE;AAAA,MAACrC;AAAAA,IAAAA,CAAQ;AAAA,EAK1D;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,10 +1,11 @@
1
1
  import { isPortableTextTextBlock, isPortableTextSpan, isKeySegment } from "@sanity/types";
2
- import { getSelectedBlocks, getSelectedSpans, getSelectionStartPoint, getSelectionEndPoint } from "../_chunks-es/selector.is-at-the-start-of-block.js";
3
- import { getActiveListItem, getActiveStyle, getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getNextBlock, getNextInlineObject, getPreviousBlock, getPreviousInlineObject, getSelectionEndBlock, getSelectionStartBlock, getSelectionText, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-at-the-start-of-block.js";
4
- import { isKeyedSegment, spanSelectionPointToBlockOffset, reverseSelection } from "../_chunks-es/util.reverse-selection.js";
5
- import { sliceBlocks } from "../_chunks-es/util.slice-blocks.js";
2
+ import { getSelectedSpans } from "../_chunks-es/selector.is-active-style.js";
3
+ import { getActiveListItem, getActiveStyle, getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle } from "../_chunks-es/selector.is-active-style.js";
4
+ import { getSelectedBlocks, getSelectionStartPoint, getSelectionEndPoint } from "../_chunks-es/selector.is-at-the-start-of-block.js";
5
+ import { getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getNextBlock, getNextInlineObject, getPreviousBlock, getPreviousInlineObject, getSelectedSlice, getSelectionEndBlock, getSelectionStartBlock, getSelectionText, isAtTheEndOfBlock, isAtTheStartOfBlock, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-at-the-start-of-block.js";
6
+ import { isKeyedSegment, spanSelectionPointToBlockOffset } from "../_chunks-es/util.slice-blocks.js";
6
7
  import { getBlockTextBefore } from "../_chunks-es/selector.get-text-before.js";
7
- import { getTrimmedSelection } from "../_chunks-es/selector.get-trimmed-selection.js";
8
+ import { reverseSelection } from "../_chunks-es/util.reverse-selection.js";
8
9
  const getActiveAnnotations = (snapshot) => {
9
10
  if (!snapshot.context.selection)
10
11
  return [];
@@ -78,12 +79,7 @@ const getActiveAnnotations = (snapshot) => {
78
79
  start,
79
80
  end
80
81
  } : void 0;
81
- }, getSelectedSlice = ({
82
- context
83
- }) => sliceBlocks({
84
- blocks: context.value,
85
- selection: context.selection
86
- }), getSelection = ({
82
+ }, getSelection = ({
87
83
  context
88
84
  }) => context.selection, getValue = ({
89
85
  context
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-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 {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const key = context.selection\n ? isKeyedSegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const anchorBlock = getAnchorBlock({context})\n\n return anchorBlock && isPortableTextTextBlock(anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n const anchorBlock = getAnchorTextBlock({context})\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = context.selection\n ? isKeyedSegment(context.selection.anchor.path[2])\n ? context.selection.anchor.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = ({context}) => {\n const anchorChild = getAnchorChild({context})\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: utils.BlockOffset; end: utils.BlockOffset} | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint({context})\n const selectionEndPoint = getSelectionEndPoint({context})\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n value: context.value,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n value: context.value,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\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","getAnchorBlock","key","isKeyedSegment","anchor","path","undefined","value","find","getAnchorTextBlock","anchorBlock","getAnchorChild","children","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getSelectedSlice","sliceBlocks","blocks","getSelection","getValue","isPointAfterSelection","point","reverseSelection","pointBlockKey","isKeySegment","pointChildKey","endBlockKey","focus","endChildKey","after","child","offset","isPointBeforeSelection","startBlockKey","startChildKey","before","isOverlappingSelection"],"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,iBAETA,CAAC;AAAA,EAACnB;AAAO,MAAM;AACjB,QAAMoB,MAAMpB,QAAQC,aAChBoB,eAAerB,QAAQC,UAAUqB,OAAOC,KAAK,CAAC,CAAC,IAC7CvB,QAAQC,UAAUqB,OAAOC,KAAK,CAAC,EAAEL,OAEnCM,QAEEd,OAAOU,MACTpB,QAAQyB,MAAMC,KAAMlB,CAAUA,UAAAA,MAAMU,SAASE,GAAG,IAChDI;AAEJ,SAAOd,QAAQU,MAAM;AAAA,IAACV;AAAAA,IAAMa,MAAM,CAAC;AAAA,MAACL,MAAME;AAAAA,IAAI,CAAA;AAAA,EAAA,IAAKI;AACrD,GCVaG,qBAETA,CAAC;AAAA,EAAC3B;AAAO,MAAM;AACjB,QAAM4B,cAAcT,eAAe;AAAA,IAACnB;AAAAA,EAAAA,CAAQ;AAE5C,SAAO4B,eAAenB,wBAAwBmB,YAAYlB,IAAI,IAC1D;AAAA,IAACA,MAAMkB,YAAYlB;AAAAA,IAAMa,MAA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AAC5BK,gBAAAA,MAAMxC,SAAS4C,eAAe;AACvB,uBAAA;AACT;AAAA,YAAA;AAKOb,qBAAAA,MAAMU,SAAS1D,UAAUqB,OAAOqC;AACzC;AAAA,UAAA;AAGF,cAAID,MAAMxC,SAAS4C;AACjB;AAAA,QAAA;AAAA,MAEJ;AAGF,UAAItD,MAAMU,SAAS2C;AACjB;AAAA,IAAA;AAIGE,WAAAA;AAAAA,EACT;AACF;ACvEO,SAASC,uBACd/D,WACyB;AACzB,SAAO,CAAC;AAAA,IAACD;AAAAA,EAAAA,MAAa;AAChB,QAAA,CAACC,aAAa,CAACD,QAAQC;AAClB,aAAA;AAGT,UAAMkC,sBAAsBC,uBAAuB;AAAA,MACjDpC,SAAS;AAAA,QACP,GAAGA;AAAAA,QACHC;AAAAA,MAAAA;AAAAA,IACF,CACD,GACKoC,oBAAoBC,qBAAqB;AAAA,MAC7CtC,SAAS;AAAA,QACP,GAAGA;AAAAA,QACHC;AAAAA,MAAAA;AAAAA,IACF,CACD;AAUD,WARI,GAACkC,uBAAuB,CAACE,qBAIzB,CAACW,sBAAsBb,mBAAmB,EAAE;AAAA,MAACnC;AAAAA,IAAAA,CAAQ,KAIrD,CAAC4D,uBAAuBvB,iBAAiB,EAAE;AAAA,MAACrC;AAAAA,IAAAA,CAAQ;AAAA,EAK1D;AACF;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-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 {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const key = context.selection\n ? isKeyedSegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const anchorBlock = getAnchorBlock({context})\n\n return anchorBlock && isPortableTextTextBlock(anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n const anchorBlock = getAnchorTextBlock({context})\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = context.selection\n ? isKeyedSegment(context.selection.anchor.path[2])\n ? context.selection.anchor.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = ({context}) => {\n const anchorChild = getAnchorChild({context})\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: utils.BlockOffset; end: utils.BlockOffset} | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint({context})\n const selectionEndPoint = getSelectionEndPoint({context})\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n value: context.value,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n value: context.value,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\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","getAnchorBlock","key","isKeyedSegment","anchor","path","undefined","value","find","getAnchorTextBlock","anchorBlock","getAnchorChild","children","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getSelection","getValue","isPointAfterSelection","point","reverseSelection","pointBlockKey","isKeySegment","pointChildKey","endBlockKey","focus","endChildKey","after","child","offset","isPointBeforeSelection","startBlockKey","startChildKey","before","isOverlappingSelection"],"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,iBAETA,CAAC;AAAA,EAACnB;AAAO,MAAM;AACjB,QAAMoB,MAAMpB,QAAQC,aAChBoB,eAAerB,QAAQC,UAAUqB,OAAOC,KAAK,CAAC,CAAC,IAC7CvB,QAAQC,UAAUqB,OAAOC,KAAK,CAAC,EAAEL,OAEnCM,QAEEd,OAAOU,M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