@portabletext/editor 1.55.13 → 1.55.14

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 (74) hide show
  1. package/lib/_chunks-cjs/{selector.is-selection-expanded.cjs → selector.get-focus-span.cjs} +27 -27
  2. package/lib/_chunks-cjs/selector.get-focus-span.cjs.map +1 -0
  3. package/lib/_chunks-cjs/selector.get-text-before.cjs +3 -3
  4. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  5. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +291 -168
  6. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
  7. package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs +1 -1
  8. package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs.map +1 -1
  9. package/lib/_chunks-cjs/{util.is-equal-selection-points.cjs → util.is-selection-collapsed.cjs} +7 -3
  10. package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +1 -0
  11. package/lib/_chunks-cjs/util.slice-blocks.cjs +2 -2
  12. package/lib/_chunks-cjs/util.slice-text-block.cjs +2 -6
  13. package/lib/_chunks-cjs/util.slice-text-block.cjs.map +1 -1
  14. package/lib/_chunks-es/{selector.is-selection-expanded.js → selector.get-focus-span.js} +27 -27
  15. package/lib/_chunks-es/selector.get-focus-span.js.map +1 -0
  16. package/lib/_chunks-es/selector.get-text-before.js +1 -1
  17. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +266 -143
  18. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
  19. package/lib/_chunks-es/util.child-selection-point-to-block-offset.js +1 -1
  20. package/lib/_chunks-es/{util.is-equal-selection-points.js → util.is-selection-collapsed.js} +7 -3
  21. package/lib/_chunks-es/util.is-selection-collapsed.js.map +1 -0
  22. package/lib/_chunks-es/util.slice-blocks.js +2 -2
  23. package/lib/_chunks-es/util.slice-text-block.js +1 -5
  24. package/lib/_chunks-es/util.slice-text-block.js.map +1 -1
  25. package/lib/behaviors/index.d.cts +3 -6
  26. package/lib/behaviors/index.d.ts +3 -6
  27. package/lib/index.cjs +110 -239
  28. package/lib/index.cjs.map +1 -1
  29. package/lib/index.d.cts +11 -20
  30. package/lib/index.d.ts +11 -20
  31. package/lib/index.js +49 -178
  32. package/lib/index.js.map +1 -1
  33. package/lib/plugins/index.cjs +16 -16
  34. package/lib/plugins/index.cjs.map +1 -1
  35. package/lib/plugins/index.d.cts +3 -6
  36. package/lib/plugins/index.d.ts +3 -6
  37. package/lib/plugins/index.js +1 -1
  38. package/lib/selectors/index.cjs +14 -14
  39. package/lib/selectors/index.cjs.map +1 -1
  40. package/lib/selectors/index.d.cts +3 -6
  41. package/lib/selectors/index.d.ts +3 -6
  42. package/lib/selectors/index.js +2 -2
  43. package/lib/utils/index.cjs +9 -9
  44. package/lib/utils/index.cjs.map +1 -1
  45. package/lib/utils/index.d.cts +3 -6
  46. package/lib/utils/index.d.ts +3 -6
  47. package/lib/utils/index.js +5 -5
  48. package/package.json +3 -3
  49. package/src/behaviors/behavior.abstract.ts +2 -1
  50. package/src/editor/create-slate-editor.tsx +0 -1
  51. package/src/editor/editor-selector.ts +1 -13
  52. package/src/editor/editor-snapshot.ts +4 -19
  53. package/src/editor/plugins/createWithEditableAPI.ts +9 -5
  54. package/src/editor/plugins/createWithPortableTextMarkModel.ts +13 -4
  55. package/src/editor/plugins/with-plugins.ts +4 -8
  56. package/src/internal-utils/create-test-snapshot.ts +2 -5
  57. package/src/operations/behavior.operation.decorator.add.ts +1 -4
  58. package/src/operations/behavior.operation.insert.text.ts +34 -20
  59. package/src/selectors/selector.get-active-annotation-marks.ts +12 -0
  60. package/src/selectors/selector.get-active-annotations.ts +8 -20
  61. package/src/{editor/get-active-decorators.ts → selectors/selector.get-active-decorators.ts} +6 -11
  62. package/src/{internal-utils/mark-state.ts → selectors/selector.get-mark-state.ts} +41 -67
  63. package/src/selectors/selector.get-next-span.ts +56 -0
  64. package/src/selectors/selector.get-previous-span.ts +53 -0
  65. package/src/selectors/selector.is-active-annotation.ts +3 -1
  66. package/src/selectors/selector.is-active-decorator.ts +4 -1
  67. package/src/types/editor.ts +0 -2
  68. package/src/utils/util.is-selection-expanded.ts +13 -0
  69. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +0 -1
  70. package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +0 -1
  71. package/lib/_chunks-es/selector.is-selection-expanded.js.map +0 -1
  72. package/lib/_chunks-es/util.is-equal-selection-points.js.map +0 -1
  73. package/src/editor/get-active-annotations.ts +0 -15
  74. package/src/editor/plugins/slate-plugin.update-mark-state.ts +0 -21
@@ -1,10 +1,8 @@
1
1
  import type {PortableTextObject} from '@sanity/types'
2
2
  import type {EditorSelector} from '../editor/editor-selector'
3
3
  import {isTextBlock} from '../internal-utils/parse-blocks'
4
- import {getFocusSpan} from './selector.get-focus-span'
4
+ import {getMarkState} from './selector.get-mark-state'
5
5
  import {getSelectedBlocks} from './selector.get-selected-blocks'
6
- import {getSelectedSpans} from './selector.get-selected-spans'
7
- import {isSelectionCollapsed} from './selector.is-selection-collapsed'
8
6
 
9
7
  /**
10
8
  * @public
@@ -17,25 +15,15 @@ export const getActiveAnnotations: EditorSelector<Array<PortableTextObject>> = (
17
15
  }
18
16
 
19
17
  const selectedBlocks = getSelectedBlocks(snapshot)
20
- const selectedSpans = getSelectedSpans(snapshot)
21
- const focusSpan = getFocusSpan(snapshot)
18
+ const markState = getMarkState(snapshot)
22
19
 
23
- if (selectedSpans.length === 0 || !focusSpan) {
24
- return []
25
- }
26
-
27
- if (selectedSpans.length === 1 && isSelectionCollapsed(snapshot)) {
28
- if (snapshot.context.selection.focus.offset === 0) {
29
- return []
30
- }
31
- if (
32
- snapshot.context.selection.focus.offset === focusSpan.node.text.length
33
- ) {
34
- return []
35
- }
36
- }
20
+ const activeAnnotations = (markState?.marks ?? []).filter(
21
+ (mark) =>
22
+ !snapshot.context.schema.decorators
23
+ .map((decorator) => decorator.name)
24
+ .includes(mark),
25
+ )
37
26
 
38
- const activeAnnotations = snapshot.beta.activeAnnotations
39
27
  const selectionMarkDefs = selectedBlocks.flatMap((block) =>
40
28
  isTextBlock(snapshot.context, block.node)
41
29
  ? (block.node.markDefs ?? [])
@@ -1,15 +1,10 @@
1
- import type {MarkState} from '../internal-utils/mark-state'
2
- import type {EditorSchema} from './editor-schema'
1
+ import type {EditorSnapshot} from '../editor/editor-snapshot'
2
+ import {getMarkState} from './selector.get-mark-state'
3
3
 
4
- export function getActiveDecorators({
5
- decoratorState,
6
- markState,
7
- schema,
8
- }: {
9
- decoratorState: Record<string, boolean | undefined>
10
- markState: MarkState | undefined
11
- schema: EditorSchema
12
- }) {
4
+ export function getActiveDecorators(snapshot: EditorSnapshot) {
5
+ const schema = snapshot.context.schema
6
+ const decoratorState = snapshot.decoratorState
7
+ const markState = getMarkState(snapshot)
13
8
  const decorators = schema.decorators.map((decorator) => decorator.name)
14
9
 
15
10
  const markStateDecorators = (markState?.marks ?? []).filter((mark) =>
@@ -1,9 +1,8 @@
1
- import {Range} from 'slate'
2
- import type {EditorSchema} from '../editor/editor-schema'
3
- import {getSelectedSpans} from '../selectors'
4
- import type {PortableTextSlateEditor} from '../types/editor'
5
- import {getNextSpan, getPreviousSpan} from './sibling-utils'
6
- import {getFocusBlock, getFocusSpan, slateRangeToSelection} from './slate-utils'
1
+ import type {EditorSelector} from '../editor/editor-selector'
2
+ import {getFocusSpan, getFocusTextBlock, getSelectedSpans} from '../selectors'
3
+ import {isSelectionExpanded} from '../utils/util.is-selection-expanded'
4
+ import {getNextSpan} from './selector.get-next-span'
5
+ import {getPreviousSpan} from './selector.get-previous-span'
7
6
 
8
7
  export type MarkState = {
9
8
  state: 'changed' | 'unchanged'
@@ -14,52 +13,22 @@ export type MarkState = {
14
13
  * Given that text is inserted at the current position, what marks should
15
14
  * be applied?
16
15
  */
17
- export function getMarkState({
18
- schema,
19
- editor,
20
- }: {
21
- schema: EditorSchema
22
- editor: PortableTextSlateEditor
23
- }): MarkState | undefined {
24
- if (!editor.selection) {
16
+ export const getMarkState: EditorSelector<MarkState | undefined> = (
17
+ snapshot,
18
+ ) => {
19
+ if (!snapshot.context.selection) {
25
20
  return undefined
26
21
  }
27
22
 
28
- const [block, blockPath] = getFocusBlock({
29
- editor,
30
- })
31
- const [span, spanPath] = getFocusSpan({
32
- editor,
33
- })
23
+ const focusTextBlock = getFocusTextBlock(snapshot)
24
+ const focusSpan = getFocusSpan(snapshot)
34
25
 
35
- if (!block || !editor.isTextBlock(block) || !span) {
26
+ if (!focusTextBlock || !focusSpan) {
36
27
  return undefined
37
28
  }
38
29
 
39
- if (Range.isExpanded(editor.selection)) {
40
- const selection = editor.selection
41
- ? slateRangeToSelection({
42
- schema,
43
- editor,
44
- range: editor.selection,
45
- })
46
- : null
47
-
48
- const selectedSpans = getSelectedSpans({
49
- blockIndexMap: editor.blockIndexMap,
50
- context: {
51
- value: editor.value,
52
- selection,
53
- schema,
54
- converters: [],
55
- keyGenerator: () => '',
56
- readOnly: false,
57
- },
58
- beta: {
59
- activeAnnotations: [],
60
- activeDecorators: [],
61
- },
62
- })
30
+ if (isSelectionExpanded(snapshot.context.selection)) {
31
+ const selectedSpans = getSelectedSpans(snapshot)
63
32
 
64
33
  let index = 0
65
34
  let marks: Array<string> = []
@@ -68,12 +37,14 @@ export function getMarkState({
68
37
  if (index === 0) {
69
38
  marks = span.node.marks ?? []
70
39
  } else {
71
- if (
72
- span.node.marks?.length === 0 ||
73
- (span.node.marks ?? [])?.some((mark) => !marks.includes(mark))
74
- ) {
40
+ if (span.node.marks?.length === 0) {
75
41
  marks = []
42
+ continue
76
43
  }
44
+
45
+ marks = marks.filter((mark) =>
46
+ (span.node.marks ?? []).some((spanMark) => spanMark === mark),
47
+ )
77
48
  }
78
49
 
79
50
  index++
@@ -85,41 +56,44 @@ export function getMarkState({
85
56
  }
86
57
  }
87
58
 
88
- const decorators = schema.decorators.map((decorator) => decorator.name)
89
- const marks = span.marks ?? []
59
+ const decorators = snapshot.context.schema.decorators.map(
60
+ (decorator) => decorator.name,
61
+ )
62
+ const marks = focusSpan.node.marks ?? []
90
63
  const marksWithoutAnnotations = marks.filter((mark) =>
91
64
  decorators.includes(mark),
92
65
  )
93
66
 
94
67
  const spanHasAnnotations = marks.length > marksWithoutAnnotations.length
95
68
 
96
- const spanIsEmpty = span.text.length === 0
69
+ const spanIsEmpty = focusSpan.node.text.length === 0
97
70
 
98
- const atTheBeginningOfSpan = editor.selection.anchor.offset === 0
99
- const atTheEndOfSpan = editor.selection.anchor.offset === span.text.length
71
+ const atTheBeginningOfSpan = snapshot.context.selection.anchor.offset === 0
72
+ const atTheEndOfSpan =
73
+ snapshot.context.selection.anchor.offset === focusSpan.node.text.length
100
74
 
101
- const previousSpan = getPreviousSpan({editor, blockPath, spanPath})
102
- const nextSpan = getNextSpan({editor, blockPath, spanPath})
75
+ const previousSpan = getPreviousSpan(snapshot)
76
+ const nextSpan = getNextSpan(snapshot)
103
77
  const nextSpanAnnotations =
104
- nextSpan?.marks?.filter((mark) => !decorators.includes(mark)) ?? []
78
+ nextSpan?.node?.marks?.filter((mark) => !decorators.includes(mark)) ?? []
105
79
  const spanAnnotations = marks.filter((mark) => !decorators.includes(mark))
106
80
 
107
81
  const previousSpanHasAnnotations = previousSpan
108
- ? previousSpan.marks?.some((mark) => !decorators.includes(mark))
82
+ ? previousSpan.node.marks?.some((mark) => !decorators.includes(mark))
109
83
  : false
110
84
  const previousSpanHasSameAnnotations = previousSpan
111
- ? previousSpan.marks
85
+ ? previousSpan.node.marks
112
86
  ?.filter((mark) => !decorators.includes(mark))
113
87
  .every((mark) => marks.includes(mark))
114
88
  : false
115
89
  const previousSpanHasSameAnnotation = previousSpan
116
- ? previousSpan.marks?.some(
90
+ ? previousSpan.node.marks?.some(
117
91
  (mark) => !decorators.includes(mark) && marks.includes(mark),
118
92
  )
119
93
  : false
120
94
 
121
95
  const previousSpanHasSameMarks = previousSpan
122
- ? previousSpan.marks?.every((mark) => marks.includes(mark))
96
+ ? previousSpan.node.marks?.every((mark) => marks.includes(mark))
123
97
  : false
124
98
  const nextSpanSharesSomeAnnotations = spanAnnotations.some((mark) =>
125
99
  nextSpanAnnotations?.includes(mark),
@@ -130,17 +104,17 @@ export function getMarkState({
130
104
  if (previousSpanHasSameMarks) {
131
105
  return {
132
106
  state: 'changed',
133
- marks: previousSpan?.marks ?? [],
107
+ marks: previousSpan?.node.marks ?? [],
134
108
  }
135
109
  } else if (previousSpanHasSameAnnotations) {
136
110
  return {
137
111
  state: 'changed',
138
- marks: previousSpan?.marks ?? [],
112
+ marks: previousSpan?.node.marks ?? [],
139
113
  }
140
114
  } else if (previousSpanHasSameAnnotation) {
141
115
  return {
142
116
  state: 'unchanged',
143
- marks: span.marks ?? [],
117
+ marks: focusSpan.node.marks ?? [],
144
118
  }
145
119
  } else if (!previousSpan) {
146
120
  return {
@@ -159,7 +133,7 @@ export function getMarkState({
159
133
  ) {
160
134
  return {
161
135
  state: 'changed',
162
- marks: nextSpan?.marks ?? [],
136
+ marks: nextSpan?.node.marks ?? [],
163
137
  }
164
138
  }
165
139
 
@@ -181,7 +155,7 @@ export function getMarkState({
181
155
  } else {
182
156
  return {
183
157
  state: 'changed',
184
- marks: (previousSpan?.marks ?? []).filter((mark) =>
158
+ marks: (previousSpan?.node.marks ?? []).filter((mark) =>
185
159
  decorators.includes(mark),
186
160
  ),
187
161
  }
@@ -190,6 +164,6 @@ export function getMarkState({
190
164
 
191
165
  return {
192
166
  state: 'unchanged',
193
- marks: span.marks ?? [],
167
+ marks: focusSpan.node.marks ?? [],
194
168
  }
195
169
  }
@@ -0,0 +1,56 @@
1
+ import type {KeyedSegment, PortableTextSpan} from '@sanity/types'
2
+ import type {EditorSelector} from '../editor/editor-selector'
3
+ import {isSpan, isTextBlock} from '../internal-utils/parse-blocks'
4
+ import {getChildKeyFromSelectionPoint} from '../selection/selection-point'
5
+ import {getSelectionEndBlock} from './selector.get-selection-end-block'
6
+ import {getSelectionEndPoint} from './selector.get-selection-end-point'
7
+
8
+ /**
9
+ * @public
10
+ */
11
+ export const getNextSpan: EditorSelector<
12
+ | {
13
+ node: PortableTextSpan
14
+ path: [KeyedSegment, 'children', KeyedSegment]
15
+ }
16
+ | undefined
17
+ > = (snapshot) => {
18
+ const selectionEndBlock = getSelectionEndBlock(snapshot)
19
+ const selectionEndPoint = getSelectionEndPoint(snapshot)
20
+
21
+ if (!selectionEndBlock || !selectionEndPoint) {
22
+ return undefined
23
+ }
24
+
25
+ if (!isTextBlock(snapshot.context, selectionEndBlock.node)) {
26
+ return undefined
27
+ }
28
+
29
+ const selectionEndPointChildKey =
30
+ getChildKeyFromSelectionPoint(selectionEndPoint)
31
+
32
+ let endPointChildFound = false
33
+ let nextSpan:
34
+ | {
35
+ node: PortableTextSpan
36
+ path: [KeyedSegment, 'children', KeyedSegment]
37
+ }
38
+ | undefined
39
+
40
+ for (const child of selectionEndBlock.node.children) {
41
+ if (child._key === selectionEndPointChildKey) {
42
+ endPointChildFound = true
43
+ continue
44
+ }
45
+
46
+ if (isSpan(snapshot.context, child) && endPointChildFound) {
47
+ nextSpan = {
48
+ node: child,
49
+ path: [...selectionEndBlock.path, 'children', {_key: child._key}],
50
+ }
51
+ break
52
+ }
53
+ }
54
+
55
+ return nextSpan
56
+ }
@@ -0,0 +1,53 @@
1
+ import type {KeyedSegment, PortableTextSpan} from '@sanity/types'
2
+ import type {EditorSelector} from '../editor/editor-selector'
3
+ import {isSpan, isTextBlock} from '../internal-utils/parse-blocks'
4
+ import {getChildKeyFromSelectionPoint} from '../selection/selection-point'
5
+ import {getSelectionStartBlock} from './selector.get-selection-start-block'
6
+ import {getSelectionStartPoint} from './selector.get-selection-start-point'
7
+
8
+ /**
9
+ * @public
10
+ */
11
+ export const getPreviousSpan: EditorSelector<
12
+ | {
13
+ node: PortableTextSpan
14
+ path: [KeyedSegment, 'children', KeyedSegment]
15
+ }
16
+ | undefined
17
+ > = (snapshot) => {
18
+ const selectionStartBlock = getSelectionStartBlock(snapshot)
19
+ const selectionStartPoint = getSelectionStartPoint(snapshot)
20
+
21
+ if (!selectionStartBlock || !selectionStartPoint) {
22
+ return undefined
23
+ }
24
+
25
+ if (!isTextBlock(snapshot.context, selectionStartBlock.node)) {
26
+ return undefined
27
+ }
28
+
29
+ const selectionStartPointChildKey =
30
+ getChildKeyFromSelectionPoint(selectionStartPoint)
31
+
32
+ let previousSpan:
33
+ | {
34
+ node: PortableTextSpan
35
+ path: [KeyedSegment, 'children', KeyedSegment]
36
+ }
37
+ | undefined
38
+
39
+ for (const child of selectionStartBlock.node.children) {
40
+ if (child._key === selectionStartPointChildKey) {
41
+ break
42
+ }
43
+
44
+ if (isSpan(snapshot.context, child)) {
45
+ previousSpan = {
46
+ node: child,
47
+ path: [...selectionStartBlock.path, 'children', {_key: child._key}],
48
+ }
49
+ }
50
+ }
51
+
52
+ return previousSpan
53
+ }
@@ -1,5 +1,6 @@
1
1
  import type {EditorSelector} from '../editor/editor-selector'
2
2
  import {isTextBlock} from '../internal-utils/parse-blocks'
3
+ import {getActiveAnnotationsMarks} from './selector.get-active-annotation-marks'
3
4
  import {getSelectedBlocks} from './selector.get-selected-blocks'
4
5
 
5
6
  /**
@@ -15,10 +16,11 @@ export function isActiveAnnotation(
15
16
  ? (block.node.markDefs ?? [])
16
17
  : [],
17
18
  )
19
+ const activeAnnotations = getActiveAnnotationsMarks(snapshot)
18
20
  const activeMarkDefs = selectionMarkDefs.filter(
19
21
  (markDef) =>
20
22
  markDef._type === annotation &&
21
- snapshot.beta.activeAnnotations.includes(markDef._key),
23
+ activeAnnotations.includes(markDef._key),
22
24
  )
23
25
 
24
26
  return activeMarkDefs.length > 0
@@ -1,4 +1,5 @@
1
1
  import type {EditorSelector} from '../editor/editor-selector'
2
+ import {getActiveDecorators} from './selector.get-active-decorators'
2
3
  import {getSelectedSpans} from './selector.get-selected-spans'
3
4
  import {isSelectionExpanded} from './selector.is-selection-expanded'
4
5
 
@@ -16,6 +17,8 @@ export function isActiveDecorator(decorator: string): EditorSelector<boolean> {
16
17
  )
17
18
  }
18
19
 
19
- return snapshot.beta.activeDecorators.includes(decorator)
20
+ const activeDecorators = getActiveDecorators(snapshot)
21
+
22
+ return activeDecorators.includes(decorator)
20
23
  }
21
24
  }
@@ -30,7 +30,6 @@ import type {ReactEditor} from 'slate-react'
30
30
  import type {PortableTextEditableProps} from '../editor/Editable'
31
31
  import type {PortableTextEditor} from '../editor/PortableTextEditor'
32
32
  import type {DecoratedRange} from '../editor/range-decorations-machine'
33
- import type {MarkState} from '../internal-utils/mark-state'
34
33
  import type {BlockPath} from './paths'
35
34
 
36
35
  /** @beta */
@@ -129,7 +128,6 @@ export interface PortableTextSlateEditor extends ReactEditor {
129
128
  value: Array<PortableTextBlock>
130
129
  decoratedRanges: Array<DecoratedRange>
131
130
  decoratorState: Record<string, boolean | undefined>
132
- markState: MarkState | undefined
133
131
  blockIndexMap: Map<string, number>
134
132
  listIndexMap: Map<string, number>
135
133
 
@@ -0,0 +1,13 @@
1
+ import type {EditorSelection} from '../types/editor'
2
+ import {isSelectionCollapsed} from './util.is-selection-collapsed'
3
+
4
+ /**
5
+ * @public
6
+ */
7
+ export function isSelectionExpanded(selection: EditorSelection) {
8
+ if (!selection) {
9
+ return false
10
+ }
11
+
12
+ return !isSelectionCollapsed(selection)
13
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"selector.is-selection-expanded.cjs","sources":["../../src/selectors/selector.get-focus-block.ts","../../src/selectors/selector.get-focus-text-block.ts","../../src/selectors/selector.get-focus-child.ts","../../src/selectors/selector.get-focus-span.ts","../../src/selectors/selector.get-selection-start-point.ts","../../src/selectors/selector.is-selection-collapsed.ts","../../src/selectors/selector.get-previous-inline-object.ts","../../src/selectors/selector.get-selected-value.ts","../../src/selectors/selector.get-selection-text.ts","../../src/selectors/selector.is-selection-expanded.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.focus)\n const index = key ? snapshot.blockIndexMap.get(key) : undefined\n\n const node =\n index !== undefined ? snapshot.context.value.at(index) : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * @public\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n return focusBlock && isTextBlock(snapshot.context, focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @public\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const focusBlock = getFocusTextBlock(snapshot)\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.focus)\n\n const node = key\n ? focusBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...focusBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isSpan} from '../internal-utils/parse-blocks'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getFocusSpan: EditorSelector<\n {node: PortableTextSpan; path: ChildPath} | undefined\n> = (snapshot) => {\n const focusChild = getFocusChild(snapshot)\n\n return focusChild && isSpan(snapshot.context, focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n","import type {EditorSelectionPoint} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelectionStartPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n return snapshot.context.selection.backward\n ? snapshot.context.selection.focus\n : snapshot.context.selection.anchor\n}\n","import type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n return (\n JSON.stringify(snapshot.context.selection.anchor.path) ===\n JSON.stringify(snapshot.context.selection.focus.path) &&\n snapshot.context.selection?.anchor.offset ===\n snapshot.context.selection?.focus.offset\n )\n}\n","import {isKeySegment, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {isSpan} from '../utils'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getPreviousInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartPointChildKey =\n selectionStartPoint && isKeySegment(selectionStartPoint.path[2])\n ? selectionStartPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionStartPointChildKey) {\n return undefined\n }\n\n let inlineObject:\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionStartPointChildKey) {\n break\n }\n\n if (!isSpan(snapshot.context, child)) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n }\n }\n\n return inlineObject\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\nimport {\n getSelectionEndPoint,\n getSelectionStartPoint,\n sliceBlocks,\n} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectedValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n const selection = snapshot.context.selection\n\n if (!selection) {\n return []\n }\n\n const startPoint = getSelectionStartPoint(selection)\n const endPoint = getSelectionEndPoint(selection)\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n\n if (!startBlockKey || !endBlockKey) {\n return []\n }\n\n const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey)\n const endBlockIndex = snapshot.blockIndexMap.get(endBlockKey)\n\n if (startBlockIndex === undefined || endBlockIndex === undefined) {\n return []\n }\n\n const slicedValue = snapshot.context.value.slice(\n startBlockIndex,\n endBlockIndex + 1,\n )\n\n return sliceBlocks({\n context: snapshot.context,\n blocks: slicedValue,\n })\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSpan, isTextBlock} from '../internal-utils/parse-blocks'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * @public\n */\nexport const getSelectionText: EditorSelector<string> = (snapshot) => {\n const selectedValue = getSelectedValue(snapshot)\n\n return selectedValue.reduce((text, block) => {\n if (!isTextBlock(snapshot.context, block)) {\n return text\n }\n\n return (\n text +\n block.children.reduce((text, child) => {\n if (isSpan(snapshot.context, child)) {\n return text + child.text\n }\n\n return text\n }, '')\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> = (snapshot) => {\n return !isSelectionCollapsed(snapshot)\n}\n"],"names":["getFocusBlock","snapshot","context","selection","key","getBlockKeyFromSelectionPoint","focus","index","blockIndexMap","get","undefined","node","value","at","path","_key","getFocusTextBlock","focusBlock","isTextBlock","getFocusChild","getChildKeyFromSelectionPoint","children","find","span","getFocusSpan","focusChild","isSpan","getSelectionStartPoint","backward","anchor","isSelectionCollapsed","JSON","stringify","offset","getPreviousInlineObject","focusTextBlock","selectionStartPoint","selectionStartPointChildKey","isKeySegment","inlineObject","child","getSelectedValue","startPoint","endPoint","getSelectionEndPoint","startBlockKey","endBlockKey","startBlockIndex","endBlockIndex","slicedValue","slice","sliceBlocks","blocks","getSelectionText","reduce","text","block","isSelectionExpanded"],"mappings":";;AAQO,MAAMA,gBAERC,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,iBAAAA,8BAA8BJ,SAASC,QAAQC,UAAUG,KAAK,GACpEC,QAAQH,MAAMH,SAASO,cAAcC,IAAIL,GAAG,IAAIM,QAEhDC,OACJJ,UAAUG,SAAYT,SAASC,QAAQU,MAAMC,GAAGN,KAAK,IAAIG;AAE3D,SAAOC,QAAQP,MAAM;AAAA,IAACO;AAAAA,IAAMG,MAAM,CAAC;AAAA,MAACC,MAAMX;AAAAA,IAAAA,CAAI;AAAA,EAAA,IAAKM;AACrD,GCbaM,oBAERf,CAAAA,aAAa;AAChB,QAAMgB,aAAajB,cAAcC,QAAQ;AAEzC,SAAOgB,cAAcC,iBAAAA,YAAYjB,SAASC,SAASe,WAAWN,IAAI,IAC9D;AAAA,IAACA,MAAMM,WAAWN;AAAAA,IAAMG,MAAMG,WAAWH;AAAAA,EAAAA,IACzCJ;AACN,GCRaS,gBAMRlB,CAAAA,a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AASC,SAASsC,KAAK,IACzBe,QAAOf,MAAMe,OAGfA,OACN,EAAE,IAXEA,MAaR,EAAE,GCnBME,sBAAgDxD,CAAAA,aACpD,CAAC6B,qBAAqB7B,QAAQ;;;;;;;;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.is-equal-selection-points.cjs","sources":["../../src/utils/util.get-block-end-point.ts","../../src/utils/util.is-empty-text-block.ts","../../src/utils/util.is-equal-selection-points.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan, isTextBlock} from '../internal-utils/parse-blocks'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport function getBlockEndPoint({\n context,\n block,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: {\n node: PortableTextBlock\n path: BlockPath\n }\n}): EditorSelectionPoint {\n if (isTextBlock(context, block.node)) {\n const lastChild = block.node.children[block.node.children.length - 1]\n\n if (lastChild) {\n return {\n path: [...block.path, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n }\n }\n }\n\n return {\n path: block.path,\n offset: 0,\n }\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan, isTextBlock} from '../internal-utils/parse-blocks'\nimport {getTextBlockText} from './util.get-text-block-text'\n\n/**\n * @public\n */\nexport function isEmptyTextBlock(\n context: Pick<EditorContext, 'schema'>,\n block: PortableTextBlock,\n) {\n if (!isTextBlock(context, block)) {\n return false\n }\n\n const onlyText = block.children.every((child) => isSpan(context, child))\n const blockText = getTextBlockText(block)\n\n return onlyText && blockText === ''\n}\n","import type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function isEqualSelectionPoints(\n a: EditorSelectionPoint,\n b: EditorSelectionPoint,\n) {\n return (\n a.offset === b.offset && JSON.stringify(a.path) === JSON.stringify(b.path)\n )\n}\n"],"names":["getBlockEndPoint","context","block","isTextBlock","node","lastChild","children","length","path","_key","offset","isSpan","text","isEmptyTextBlock","onlyText","every","child","blockText","getTextBlockText","isEqualSelectionPoints","a","b","JSON","stringify"],"mappings":";;AASO,SAASA,iBAAiB;AAAA,EAC/BC;AAAAA,EACAC;AAOF,GAAyB;AACvB,MAAIC,6BAAYF,SAASC,MAAME,IAAI,GAAG;AACpC,UAAMC,YAAYH,MAAME,KAAKE,SAASJ,MAAME,KAAKE,SAASC,SAAS,CAAC;AAEpE,QAAIF;AACF,aAAO;AAAA,QACLG,MAAM,CAAC,GAAGN,MAAMM,MAAM,YAAY;AAAA,UAACC,MAAMJ,UAAUI;AAAAA,QAAAA,CAAK;AAAA,QACxDC,QAAQC,iBAAAA,SAAOV,SAASI,SAAS,IAAIA,UAAUO,KAAKL,SAAS;AAAA,MAAA;AAAA,EAC/D;AAIJ,SAAO;AAAA,IACLC,MAAMN,MAAMM;AAAAA,IACZE,QAAQ;AAAA,EAAA;AAEZ;AC1BO,SAASG,iBACdZ,SACAC,OACA;AACA,MAAI,CAACC,iBAAAA,YAAYF,SAASC,KAAK;AAC7B,WAAO;AAGT,QAAMY,WAAWZ,MAAMI,SAASS,MAAOC,CAAAA,UAAUL,0BAAOV,SAASe,KAAK,CAAC,GACjEC,YAAYC,iBAAAA,iBAAiBhB,KAAK;AAExC,SAAOY,YAAYG,cAAc;AACnC;ACfO,SAASE,uBACdC,GACAC,GACA;AACA,SACED,EAAEV,WAAWW,EAAEX,UAAUY,KAAKC,UAAUH,EAAEZ,IAAI,MAAMc,KAAKC,UAAUF,EAAEb,IAAI;AAE7E;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"selector.is-selection-expanded.js","sources":["../../src/selectors/selector.get-focus-block.ts","../../src/selectors/selector.get-focus-text-block.ts","../../src/selectors/selector.get-focus-child.ts","../../src/selectors/selector.get-focus-span.ts","../../src/selectors/selector.get-selection-start-point.ts","../../src/selectors/selector.is-selection-collapsed.ts","../../src/selectors/selector.get-previous-inline-object.ts","../../src/selectors/selector.get-selected-value.ts","../../src/selectors/selector.get-selection-text.ts","../../src/selectors/selector.is-selection-expanded.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.focus)\n const index = key ? snapshot.blockIndexMap.get(key) : undefined\n\n const node =\n index !== undefined ? snapshot.context.value.at(index) : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * @public\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n return focusBlock && isTextBlock(snapshot.context, focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @public\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const focusBlock = getFocusTextBlock(snapshot)\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.focus)\n\n const node = key\n ? focusBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...focusBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isSpan} from '../internal-utils/parse-blocks'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getFocusSpan: EditorSelector<\n {node: PortableTextSpan; path: ChildPath} | undefined\n> = (snapshot) => {\n const focusChild = getFocusChild(snapshot)\n\n return focusChild && isSpan(snapshot.context, focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n","import type {EditorSelectionPoint} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelectionStartPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n return snapshot.context.selection.backward\n ? snapshot.context.selection.focus\n : snapshot.context.selection.anchor\n}\n","import type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n return (\n JSON.stringify(snapshot.context.selection.anchor.path) ===\n JSON.stringify(snapshot.context.selection.focus.path) &&\n snapshot.context.selection?.anchor.offset ===\n snapshot.context.selection?.focus.offset\n )\n}\n","import {isKeySegment, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {isSpan} from '../utils'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getPreviousInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartPointChildKey =\n selectionStartPoint && isKeySegment(selectionStartPoint.path[2])\n ? selectionStartPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionStartPointChildKey) {\n return undefined\n }\n\n let inlineObject:\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionStartPointChildKey) {\n break\n }\n\n if (!isSpan(snapshot.context, child)) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n }\n }\n\n return inlineObject\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\nimport {\n getSelectionEndPoint,\n getSelectionStartPoint,\n sliceBlocks,\n} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectedValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n const selection = snapshot.context.selection\n\n if (!selection) {\n return []\n }\n\n const startPoint = getSelectionStartPoint(selection)\n const endPoint = getSelectionEndPoint(selection)\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n\n if (!startBlockKey || !endBlockKey) {\n return []\n }\n\n const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey)\n const endBlockIndex = snapshot.blockIndexMap.get(endBlockKey)\n\n if (startBlockIndex === undefined || endBlockIndex === undefined) {\n return []\n }\n\n const slicedValue = snapshot.context.value.slice(\n startBlockIndex,\n endBlockIndex + 1,\n )\n\n return sliceBlocks({\n context: snapshot.context,\n blocks: slicedValue,\n })\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSpan, isTextBlock} from '../internal-utils/parse-blocks'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * @public\n */\nexport const getSelectionText: EditorSelector<string> = (snapshot) => {\n const selectedValue = getSelectedValue(snapshot)\n\n return selectedValue.reduce((text, block) => {\n if (!isTextBlock(snapshot.context, block)) {\n return text\n }\n\n return (\n text +\n block.children.reduce((text, child) => {\n if (isSpan(snapshot.context, child)) {\n return text + child.text\n }\n\n return text\n }, '')\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> = (snapshot) => {\n return !isSelectionCollapsed(snapshot)\n}\n"],"names":["getFocusBlock","snapshot","context","selection","key","getBlockKeyFromSelectionPoint","focus","index","blockIndexMap","get","undefined","node","value","at","path","_key","getFocusTextBlock","focusBlock","isTextBlock","getFocusChild","getChildKeyFromSelectionPoint","children","find","span","getFocusSpan","focusChild","isSpan","getSelectionStartPoint","backward","anchor","isSelectionCollapsed","JSON","stringify","offset","getPreviousInlineObject","focusTextBlock","selectionStartPoint","selectionStartPointChildKey","isKeySegment","inlineObject","child","getSelectedValue","startPoint","endPoint","getSelectionEndPoint","startBlockKey","endBlockKey","startBlockIndex","endBlockIndex","slicedValue","slice","sliceBlocks","blocks","getSelectionText","reduce","text","block","isSelectionExpanded"],"mappings":";;AAQO,MAAMA,gBAERC,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,8BAA8BJ,SAASC,QAAQC,UAAUG,KAAK,GACpEC,QAAQH,MAAMH,SAASO,cAAcC,IAAIL,GAAG,IAAIM,QAEhDC,OACJJ,UAAUG,SAAYT,SAASC,QAAQU,MAAMC,GAAGN,KAAK,IAAIG;AAE3D,SAAOC,QAAQP,MAAM;AAAA,IAACO;AAAAA,IAAMG,MAAM,CAAC;AAAA,MAACC,MAAMX;AAAAA,IAAAA,CAAI;AAAA,EAAA,IAAKM;AACrD,GCbaM,oBAERf,CAAAA,aAAa;AAChB,QAAMgB,aAAajB,cAAcC,QAAQ;AAEzC,SAAOg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D,KAAK,IAKtCD,OACAC,MAAMnC,SAASiC,OAAO,CAACC,OAAMf,UACvBd,OAAOzB,SAASC,SAASsC,KAAK,IACzBe,QAAOf,MAAMe,OAGfA,OACN,EAAE,IAXEA,MAaR,EAAE,GCnBME,sBAAgDxD,CAAAA,aACpD,CAAC6B,qBAAqB7B,QAAQ;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.is-equal-selection-points.js","sources":["../../src/utils/util.get-block-end-point.ts","../../src/utils/util.is-empty-text-block.ts","../../src/utils/util.is-equal-selection-points.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan, isTextBlock} from '../internal-utils/parse-blocks'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport function getBlockEndPoint({\n context,\n block,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: {\n node: PortableTextBlock\n path: BlockPath\n }\n}): EditorSelectionPoint {\n if (isTextBlock(context, block.node)) {\n const lastChild = block.node.children[block.node.children.length - 1]\n\n if (lastChild) {\n return {\n path: [...block.path, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n }\n }\n }\n\n return {\n path: block.path,\n offset: 0,\n }\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan, isTextBlock} from '../internal-utils/parse-blocks'\nimport {getTextBlockText} from './util.get-text-block-text'\n\n/**\n * @public\n */\nexport function isEmptyTextBlock(\n context: Pick<EditorContext, 'schema'>,\n block: PortableTextBlock,\n) {\n if (!isTextBlock(context, block)) {\n return false\n }\n\n const onlyText = block.children.every((child) => isSpan(context, child))\n const blockText = getTextBlockText(block)\n\n return onlyText && blockText === ''\n}\n","import type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function isEqualSelectionPoints(\n a: EditorSelectionPoint,\n b: EditorSelectionPoint,\n) {\n return (\n a.offset === b.offset && JSON.stringify(a.path) === JSON.stringify(b.path)\n )\n}\n"],"names":["getBlockEndPoint","context","block","isTextBlock","node","lastChild","children","length","path","_key","offset","isSpan","text","isEmptyTextBlock","onlyText","every","child","blockText","getTextBlockText","isEqualSelectionPoints","a","b","JSON","stringify"],"mappings":";AASO,SAASA,iBAAiB;AAAA,EAC/BC;AAAAA,EACAC;AAOF,GAAyB;AACvB,MAAIC,YAAYF,SAASC,MAAME,IAAI,GAAG;AACpC,UAAMC,YAAYH,MAAME,KAAKE,SAASJ,MAAME,KAAKE,SAASC,SAAS,CAAC;AAEpE,QAAIF;AACF,aAAO;AAAA,QACLG,MAAM,CAAC,GAAGN,MAAMM,MAAM,YAAY;AAAA,UAACC,MAAMJ,UAAUI;AAAAA,QAAAA,CAAK;AAAA,QACxDC,QAAQC,OAAOV,SAASI,SAAS,IAAIA,UAAUO,KAAKL,SAAS;AAAA,MAAA;AAAA,EAC/D;AAIJ,SAAO;AAAA,IACLC,MAAMN,MAAMM;AAAAA,IACZE,QAAQ;AAAA,EAAA;AAEZ;AC1BO,SAASG,iBACdZ,SACAC,OACA;AACA,MAAI,CAACC,YAAYF,SAASC,KAAK;AAC7B,WAAO;AAGT,QAAMY,WAAWZ,MAAMI,SAASS,MAAOC,CAAAA,UAAUL,OAAOV,SAASe,KAAK,CAAC,GACjEC,YAAYC,iBAAiBhB,KAAK;AAExC,SAAOY,YAAYG,cAAc;AACnC;ACfO,SAASE,uBACdC,GACAC,GACA;AACA,SACED,EAAEV,WAAWW,EAAEX,UAAUY,KAAKC,UAAUH,EAAEZ,IAAI,MAAMc,KAAKC,UAAUF,EAAEb,IAAI;AAE7E;"}
@@ -1,15 +0,0 @@
1
- import type {MarkState} from '../internal-utils/mark-state'
2
- import type {EditorSchema} from './editor-schema'
3
-
4
- export function getActiveAnnotations({
5
- markState,
6
- schema,
7
- }: {
8
- markState: MarkState | undefined
9
- schema: EditorSchema
10
- }) {
11
- return (markState?.marks ?? []).filter(
12
- (mark) =>
13
- !schema.decorators.map((decorator) => decorator.name).includes(mark),
14
- )
15
- }
@@ -1,21 +0,0 @@
1
- import {getMarkState} from '../../internal-utils/mark-state'
2
- import type {PortableTextSlateEditor} from '../../types/editor'
3
- import type {EditorContext} from '../editor-snapshot'
4
-
5
- export function pluginUpdateMarkState(
6
- context: Pick<EditorContext, 'schema'>,
7
- editor: PortableTextSlateEditor,
8
- ) {
9
- const {apply} = editor
10
-
11
- editor.apply = (operation) => {
12
- apply(operation)
13
-
14
- editor.markState = getMarkState({
15
- editor,
16
- schema: context.schema,
17
- })
18
- }
19
-
20
- return editor
21
- }