@portabletext/editor 3.3.3 → 3.3.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 (306) hide show
  1. package/package.json +11 -12
  2. package/src/behaviors/_exports/index.ts +0 -1
  3. package/src/behaviors/behavior.abstract.annotation.ts +0 -77
  4. package/src/behaviors/behavior.abstract.decorator.ts +0 -39
  5. package/src/behaviors/behavior.abstract.delete.ts +0 -273
  6. package/src/behaviors/behavior.abstract.deserialize.ts +0 -232
  7. package/src/behaviors/behavior.abstract.insert.ts +0 -525
  8. package/src/behaviors/behavior.abstract.keyboard.ts +0 -189
  9. package/src/behaviors/behavior.abstract.list-item.ts +0 -70
  10. package/src/behaviors/behavior.abstract.move.ts +0 -79
  11. package/src/behaviors/behavior.abstract.select.ts +0 -118
  12. package/src/behaviors/behavior.abstract.serialize.ts +0 -96
  13. package/src/behaviors/behavior.abstract.split.ts +0 -170
  14. package/src/behaviors/behavior.abstract.style.ts +0 -55
  15. package/src/behaviors/behavior.abstract.ts +0 -139
  16. package/src/behaviors/behavior.config.ts +0 -7
  17. package/src/behaviors/behavior.core.annotations.ts +0 -62
  18. package/src/behaviors/behavior.core.block-element.ts +0 -116
  19. package/src/behaviors/behavior.core.block-objects.ts +0 -285
  20. package/src/behaviors/behavior.core.decorators.ts +0 -44
  21. package/src/behaviors/behavior.core.dnd.ts +0 -356
  22. package/src/behaviors/behavior.core.insert-break.ts +0 -266
  23. package/src/behaviors/behavior.core.insert.ts +0 -52
  24. package/src/behaviors/behavior.core.lists.ts +0 -691
  25. package/src/behaviors/behavior.core.ts +0 -44
  26. package/src/behaviors/behavior.perform-event.ts +0 -354
  27. package/src/behaviors/behavior.types.action.ts +0 -102
  28. package/src/behaviors/behavior.types.behavior.ts +0 -83
  29. package/src/behaviors/behavior.types.event.ts +0 -667
  30. package/src/behaviors/behavior.types.guard.ts +0 -11
  31. package/src/behaviors/index.ts +0 -17
  32. package/src/converters/converter.json.ts +0 -53
  33. package/src/converters/converter.portable-text.deserialize.test.ts +0 -680
  34. package/src/converters/converter.portable-text.ts +0 -75
  35. package/src/converters/converter.text-html.deserialize.test.ts +0 -406
  36. package/src/converters/converter.text-html.serialize.test.ts +0 -246
  37. package/src/converters/converter.text-html.ts +0 -87
  38. package/src/converters/converter.text-markdown.ts +0 -67
  39. package/src/converters/converter.text-plain.test.ts +0 -245
  40. package/src/converters/converter.text-plain.ts +0 -126
  41. package/src/converters/converter.types.ts +0 -72
  42. package/src/converters/converters.core.ts +0 -18
  43. package/src/editor/Editable.tsx +0 -1012
  44. package/src/editor/PortableTextEditor.tsx +0 -791
  45. package/src/editor/components/drop-indicator.tsx +0 -17
  46. package/src/editor/components/render-block-object.tsx +0 -121
  47. package/src/editor/components/render-default-object.tsx +0 -21
  48. package/src/editor/components/render-element.tsx +0 -88
  49. package/src/editor/components/render-inline-object.tsx +0 -129
  50. package/src/editor/components/render-leaf.tsx +0 -64
  51. package/src/editor/components/render-span.tsx +0 -303
  52. package/src/editor/components/render-text-block.tsx +0 -265
  53. package/src/editor/components/render-text.tsx +0 -18
  54. package/src/editor/components/use-core-block-element-behaviors.ts +0 -39
  55. package/src/editor/create-editor.ts +0 -323
  56. package/src/editor/create-slate-editor.tsx +0 -64
  57. package/src/editor/editor-actor-context.ts +0 -4
  58. package/src/editor/editor-context.tsx +0 -7
  59. package/src/editor/editor-dom.ts +0 -220
  60. package/src/editor/editor-machine.ts +0 -751
  61. package/src/editor/editor-provider.tsx +0 -111
  62. package/src/editor/editor-schema.ts +0 -6
  63. package/src/editor/editor-selector.ts +0 -89
  64. package/src/editor/editor-snapshot.ts +0 -68
  65. package/src/editor/event-to-change.tsx +0 -49
  66. package/src/editor/hooks/usePortableTextEditor.ts +0 -25
  67. package/src/editor/hooks/usePortableTextEditorSelection.tsx +0 -28
  68. package/src/editor/mutation-machine.ts +0 -322
  69. package/src/editor/plugins/create-with-event-listeners.ts +0 -271
  70. package/src/editor/plugins/createWithEditableAPI.ts +0 -529
  71. package/src/editor/plugins/createWithHotKeys.ts +0 -68
  72. package/src/editor/plugins/createWithObjectKeys.ts +0 -289
  73. package/src/editor/plugins/createWithPatches.ts +0 -272
  74. package/src/editor/plugins/createWithPortableTextMarkModel.ts +0 -559
  75. package/src/editor/plugins/createWithSchemaTypes.ts +0 -121
  76. package/src/editor/plugins/slate-plugin.update-selection.ts +0 -51
  77. package/src/editor/plugins/slate-plugin.update-value.ts +0 -46
  78. package/src/editor/plugins/with-plugins.ts +0 -69
  79. package/src/editor/range-decorations-machine.ts +0 -421
  80. package/src/editor/relay-actor-context.ts +0 -4
  81. package/src/editor/relay-machine.ts +0 -152
  82. package/src/editor/sync-machine.ts +0 -961
  83. package/src/editor/use-editor.ts +0 -27
  84. package/src/editor/validate-selection-machine.test.ts +0 -47
  85. package/src/editor/validate-selection-machine.ts +0 -149
  86. package/src/editor/weakMaps.ts +0 -15
  87. package/src/editor/with-normalizing-node.ts +0 -14
  88. package/src/editor/with-performing-behavior-operation.ts +0 -21
  89. package/src/editor/withChanges.ts +0 -13
  90. package/src/editor/without-normalizing-conditional.ts +0 -13
  91. package/src/editor/withoutPatching.ts +0 -14
  92. package/src/editor.ts +0 -59
  93. package/src/history/behavior.operation.history.redo.ts +0 -67
  94. package/src/history/behavior.operation.history.undo.ts +0 -71
  95. package/src/history/event.history.undo.test.tsx +0 -672
  96. package/src/history/history.preserving-keys.test.tsx +0 -112
  97. package/src/history/remote-patches.ts +0 -20
  98. package/src/history/slate-plugin.history.ts +0 -142
  99. package/src/history/slate-plugin.redoing.ts +0 -21
  100. package/src/history/slate-plugin.undoing.ts +0 -21
  101. package/src/history/slate-plugin.without-history.ts +0 -23
  102. package/src/history/transform-operation.ts +0 -245
  103. package/src/history/undo-redo-collaboration.test.tsx +0 -541
  104. package/src/history/undo-redo.feature +0 -125
  105. package/src/history/undo-redo.test.tsx +0 -195
  106. package/src/history/undo-step.ts +0 -148
  107. package/src/index.ts +0 -107
  108. package/src/internal-utils/__tests__/ranges.test.ts +0 -23
  109. package/src/internal-utils/__tests__/values.test.ts +0 -110
  110. package/src/internal-utils/apply-operation-to-portable-text.test.ts +0 -1861
  111. package/src/internal-utils/apply-operation-to-portable-text.ts +0 -615
  112. package/src/internal-utils/applyPatch.ts +0 -644
  113. package/src/internal-utils/block-keys.ts +0 -9
  114. package/src/internal-utils/build-index-maps.test.ts +0 -464
  115. package/src/internal-utils/build-index-maps.ts +0 -131
  116. package/src/internal-utils/collapse-selection.ts +0 -36
  117. package/src/internal-utils/compound-client-rect.ts +0 -28
  118. package/src/internal-utils/create-placeholder-block.ts +0 -21
  119. package/src/internal-utils/create-test-snapshot.ts +0 -28
  120. package/src/internal-utils/debug.ts +0 -12
  121. package/src/internal-utils/editor-selection.test.ts +0 -44
  122. package/src/internal-utils/editor-selection.ts +0 -56
  123. package/src/internal-utils/event-position.ts +0 -318
  124. package/src/internal-utils/global-scope.ts +0 -27
  125. package/src/internal-utils/globally-scoped-context.ts +0 -39
  126. package/src/internal-utils/is-hotkey.test.ts +0 -114
  127. package/src/internal-utils/is-hotkey.ts +0 -209
  128. package/src/internal-utils/mime-type.ts +0 -1
  129. package/src/internal-utils/move-range-by-operation.ts +0 -19
  130. package/src/internal-utils/operation-to-patches.test.ts +0 -522
  131. package/src/internal-utils/operation-to-patches.ts +0 -571
  132. package/src/internal-utils/portable-text-node.ts +0 -209
  133. package/src/internal-utils/schema.ts +0 -8
  134. package/src/internal-utils/selection-block-keys.ts +0 -20
  135. package/src/internal-utils/selection-focus-text.ts +0 -40
  136. package/src/internal-utils/selection-text.test.ts +0 -32
  137. package/src/internal-utils/selection-text.ts +0 -21
  138. package/src/internal-utils/selection.ts +0 -77
  139. package/src/internal-utils/sibling-utils.ts +0 -55
  140. package/src/internal-utils/slate-utils.test.tsx +0 -121
  141. package/src/internal-utils/slate-utils.ts +0 -417
  142. package/src/internal-utils/split-string.ts +0 -12
  143. package/src/internal-utils/stop-actor.ts +0 -43
  144. package/src/internal-utils/string-overlap.test.ts +0 -14
  145. package/src/internal-utils/string-overlap.ts +0 -28
  146. package/src/internal-utils/string-utils.ts +0 -7
  147. package/src/internal-utils/text-block-key.test.ts +0 -41
  148. package/src/internal-utils/text-block-key.ts +0 -26
  149. package/src/internal-utils/text-marks.test.ts +0 -41
  150. package/src/internal-utils/text-marks.ts +0 -22
  151. package/src/internal-utils/text-selection.test.ts +0 -211
  152. package/src/internal-utils/text-selection.ts +0 -121
  153. package/src/internal-utils/to-slate-range.test.ts +0 -278
  154. package/src/internal-utils/to-slate-range.ts +0 -171
  155. package/src/internal-utils/validateValue.ts +0 -443
  156. package/src/internal-utils/value-annotations.ts +0 -33
  157. package/src/internal-utils/values.test.ts +0 -282
  158. package/src/internal-utils/values.ts +0 -266
  159. package/src/keyboard-shortcuts/default-keyboard-shortcuts.ts +0 -146
  160. package/src/operations/behavior.operation.annotation.add.ts +0 -99
  161. package/src/operations/behavior.operation.annotation.remove.ts +0 -150
  162. package/src/operations/behavior.operation.block.set.ts +0 -104
  163. package/src/operations/behavior.operation.block.unset.ts +0 -54
  164. package/src/operations/behavior.operation.child.set.ts +0 -107
  165. package/src/operations/behavior.operation.child.unset.ts +0 -116
  166. package/src/operations/behavior.operation.decorator.add.ts +0 -131
  167. package/src/operations/behavior.operation.delete.ts +0 -294
  168. package/src/operations/behavior.operation.insert.block.ts +0 -495
  169. package/src/operations/behavior.operation.insert.child.ts +0 -129
  170. package/src/operations/behavior.operation.insert.text.ts +0 -8
  171. package/src/operations/behavior.operation.move.backward.ts +0 -12
  172. package/src/operations/behavior.operation.move.block.ts +0 -44
  173. package/src/operations/behavior.operation.move.forward.ts +0 -11
  174. package/src/operations/behavior.operation.select.ts +0 -27
  175. package/src/operations/behavior.operations.ts +0 -221
  176. package/src/plugins/_exports/index.ts +0 -1
  177. package/src/plugins/index.ts +0 -3
  178. package/src/plugins/plugin.behavior.tsx +0 -24
  179. package/src/plugins/plugin.editor-ref.tsx +0 -17
  180. package/src/plugins/plugin.event-listener.tsx +0 -68
  181. package/src/plugins/plugin.internal.auto-close-brackets.test.tsx +0 -71
  182. package/src/plugins/plugin.internal.auto-close-brackets.ts +0 -62
  183. package/src/plugins/plugin.internal.change-ref.tsx +0 -19
  184. package/src/plugins/plugin.internal.portable-text-editor-ref.tsx +0 -16
  185. package/src/plugins/plugin.internal.slate-editor-ref.tsx +0 -15
  186. package/src/priority/priority.core.ts +0 -3
  187. package/src/priority/priority.sort.test.ts +0 -319
  188. package/src/priority/priority.sort.ts +0 -123
  189. package/src/priority/priority.types.ts +0 -24
  190. package/src/selectors/_exports/index.ts +0 -1
  191. package/src/selectors/drag-selection.test.ts +0 -578
  192. package/src/selectors/drag-selection.ts +0 -118
  193. package/src/selectors/index.ts +0 -54
  194. package/src/selectors/selector.get-active-annotation-marks.ts +0 -12
  195. package/src/selectors/selector.get-active-annotations.ts +0 -36
  196. package/src/selectors/selector.get-active-decorators.ts +0 -29
  197. package/src/selectors/selector.get-active-list-item.ts +0 -38
  198. package/src/selectors/selector.get-active-style.ts +0 -38
  199. package/src/selectors/selector.get-anchor-block.ts +0 -22
  200. package/src/selectors/selector.get-anchor-child.ts +0 -36
  201. package/src/selectors/selector.get-anchor-span.ts +0 -17
  202. package/src/selectors/selector.get-anchor-text-block.ts +0 -18
  203. package/src/selectors/selector.get-block-offsets.ts +0 -34
  204. package/src/selectors/selector.get-caret-word-selection.test.ts +0 -284
  205. package/src/selectors/selector.get-caret-word-selection.ts +0 -134
  206. package/src/selectors/selector.get-first-block.ts +0 -14
  207. package/src/selectors/selector.get-focus-block-object.ts +0 -18
  208. package/src/selectors/selector.get-focus-block.ts +0 -23
  209. package/src/selectors/selector.get-focus-child.ts +0 -36
  210. package/src/selectors/selector.get-focus-inline-object.ts +0 -17
  211. package/src/selectors/selector.get-focus-list-block.ts +0 -18
  212. package/src/selectors/selector.get-focus-span.ts +0 -18
  213. package/src/selectors/selector.get-focus-text-block.ts +0 -18
  214. package/src/selectors/selector.get-last-block.ts +0 -16
  215. package/src/selectors/selector.get-mark-state.test.ts +0 -325
  216. package/src/selectors/selector.get-mark-state.ts +0 -263
  217. package/src/selectors/selector.get-next-block.ts +0 -29
  218. package/src/selectors/selector.get-next-inline-object.ts +0 -53
  219. package/src/selectors/selector.get-next-inline-objects.ts +0 -50
  220. package/src/selectors/selector.get-next-span.ts +0 -56
  221. package/src/selectors/selector.get-previous-block.ts +0 -29
  222. package/src/selectors/selector.get-previous-inline-object.ts +0 -50
  223. package/src/selectors/selector.get-previous-inline-objects.ts +0 -47
  224. package/src/selectors/selector.get-previous-span.ts +0 -53
  225. package/src/selectors/selector.get-selected-blocks.ts +0 -61
  226. package/src/selectors/selector.get-selected-spans.test.ts +0 -347
  227. package/src/selectors/selector.get-selected-spans.ts +0 -155
  228. package/src/selectors/selector.get-selected-text-blocks.ts +0 -73
  229. package/src/selectors/selector.get-selected-value.test.ts +0 -834
  230. package/src/selectors/selector.get-selected-value.ts +0 -66
  231. package/src/selectors/selector.get-selection-end-block.ts +0 -33
  232. package/src/selectors/selector.get-selection-end-child.ts +0 -33
  233. package/src/selectors/selector.get-selection-end-point.ts +0 -17
  234. package/src/selectors/selector.get-selection-start-block.ts +0 -33
  235. package/src/selectors/selector.get-selection-start-child.ts +0 -33
  236. package/src/selectors/selector.get-selection-start-point.ts +0 -17
  237. package/src/selectors/selector.get-selection-text.test.ts +0 -421
  238. package/src/selectors/selector.get-selection-text.ts +0 -27
  239. package/src/selectors/selector.get-selection.ts +0 -9
  240. package/src/selectors/selector.get-text-after.ts +0 -46
  241. package/src/selectors/selector.get-text-before.ts +0 -46
  242. package/src/selectors/selector.get-value.ts +0 -11
  243. package/src/selectors/selector.is-active-annotation.test.ts +0 -320
  244. package/src/selectors/selector.is-active-annotation.ts +0 -52
  245. package/src/selectors/selector.is-active-decorator.test.ts +0 -136
  246. package/src/selectors/selector.is-active-decorator.ts +0 -24
  247. package/src/selectors/selector.is-active-list-item.ts +0 -13
  248. package/src/selectors/selector.is-active-style.ts +0 -13
  249. package/src/selectors/selector.is-at-the-end-of-block.ts +0 -30
  250. package/src/selectors/selector.is-at-the-start-of-block.ts +0 -30
  251. package/src/selectors/selector.is-overlapping-selection.test.ts +0 -304
  252. package/src/selectors/selector.is-overlapping-selection.ts +0 -181
  253. package/src/selectors/selector.is-point-after-selection.ts +0 -97
  254. package/src/selectors/selector.is-point-before-selection.ts +0 -97
  255. package/src/selectors/selector.is-selecting-entire-blocks.ts +0 -43
  256. package/src/selectors/selector.is-selection-collapsed.ts +0 -17
  257. package/src/selectors/selector.is-selection-expanded.test.ts +0 -63
  258. package/src/selectors/selector.is-selection-expanded.ts +0 -9
  259. package/src/test/_exports/index.ts +0 -1
  260. package/src/test/gherkin-parameter-types.ts +0 -112
  261. package/src/test/index.ts +0 -1
  262. package/src/test/vitest/_exports/index.ts +0 -1
  263. package/src/test/vitest/index.ts +0 -3
  264. package/src/test/vitest/step-context.ts +0 -13
  265. package/src/test/vitest/step-definitions.tsx +0 -960
  266. package/src/test/vitest/test-editor.tsx +0 -198
  267. package/src/type-utils.ts +0 -29
  268. package/src/types/block-offset.ts +0 -9
  269. package/src/types/block-with-optional-key.ts +0 -25
  270. package/src/types/editor.ts +0 -509
  271. package/src/types/options.ts +0 -13
  272. package/src/types/paths.ts +0 -35
  273. package/src/types/slate-editor.ts +0 -50
  274. package/src/types/slate.ts +0 -27
  275. package/src/utils/_exports/index.ts +0 -1
  276. package/src/utils/asserters.ts +0 -9
  277. package/src/utils/index.ts +0 -24
  278. package/src/utils/key-generator.ts +0 -33
  279. package/src/utils/parse-blocks.test.ts +0 -836
  280. package/src/utils/parse-blocks.ts +0 -504
  281. package/src/utils/util.at-the-beginning-of-block.ts +0 -32
  282. package/src/utils/util.block-offset-to-block-selection-point.ts +0 -28
  283. package/src/utils/util.block-offset-to-selection-point.ts +0 -33
  284. package/src/utils/util.block-offset.test.ts +0 -375
  285. package/src/utils/util.block-offset.ts +0 -136
  286. package/src/utils/util.block-offsets-to-selection.ts +0 -38
  287. package/src/utils/util.child-selection-point-to-block-offset.ts +0 -51
  288. package/src/utils/util.get-block-end-point.ts +0 -35
  289. package/src/utils/util.get-block-start-point.ts +0 -31
  290. package/src/utils/util.get-selection-end-point.ts +0 -20
  291. package/src/utils/util.get-selection-start-point.ts +0 -20
  292. package/src/utils/util.get-text-block-text.ts +0 -8
  293. package/src/utils/util.is-empty-text-block.ts +0 -21
  294. package/src/utils/util.is-equal-selection-points.ts +0 -13
  295. package/src/utils/util.is-equal-selections.ts +0 -20
  296. package/src/utils/util.is-keyed-segment.ts +0 -8
  297. package/src/utils/util.is-selection-collapsed.ts +0 -16
  298. package/src/utils/util.is-selection-expanded.ts +0 -13
  299. package/src/utils/util.merge-text-blocks.ts +0 -40
  300. package/src/utils/util.reverse-selection.ts +0 -26
  301. package/src/utils/util.selection-point-to-block-offset.ts +0 -30
  302. package/src/utils/util.selection-point.ts +0 -22
  303. package/src/utils/util.slice-blocks.ts +0 -221
  304. package/src/utils/util.slice-text-block.test.ts +0 -190
  305. package/src/utils/util.slice-text-block.ts +0 -89
  306. package/src/utils/util.split-text-block.ts +0 -54
@@ -1,263 +0,0 @@
1
- import type {EditorSelector} from '../editor/editor-selector'
2
- import {isBlockPath} from '../types/paths'
3
- import {blockOffsetToSpanSelectionPoint} from '../utils/util.block-offset'
4
- import {isSelectionExpanded} from '../utils/util.is-selection-expanded'
5
- import {getFocusSpan} from './selector.get-focus-span'
6
- import {getFocusTextBlock} from './selector.get-focus-text-block'
7
- import {getNextSpan} from './selector.get-next-span'
8
- import {getPreviousSpan} from './selector.get-previous-span'
9
- import {getSelectedSpans} from './selector.get-selected-spans'
10
-
11
- /**
12
- * @beta
13
- */
14
- export type MarkState =
15
- | {
16
- state: 'unchanged'
17
- marks: Array<string>
18
- }
19
- | {
20
- state: 'changed'
21
- marks: Array<string>
22
- previousMarks: Array<string>
23
- }
24
-
25
- /**
26
- * Given that text is inserted at the current position, what marks should
27
- * be applied?
28
- * @beta
29
- */
30
- export const getMarkState: EditorSelector<MarkState | undefined> = (
31
- snapshot,
32
- ) => {
33
- if (!snapshot.context.selection) {
34
- return undefined
35
- }
36
-
37
- let selection = snapshot.context.selection
38
- const focusTextBlock = getFocusTextBlock(snapshot)
39
-
40
- if (!focusTextBlock) {
41
- return undefined
42
- }
43
-
44
- if (isBlockPath(selection.anchor.path)) {
45
- const spanSelectionPoint = blockOffsetToSpanSelectionPoint({
46
- context: snapshot.context,
47
- blockOffset: {
48
- path: selection.anchor.path,
49
- offset: selection.anchor.offset,
50
- },
51
- direction: selection.backward ? 'backward' : 'forward',
52
- })
53
-
54
- selection = spanSelectionPoint
55
- ? {
56
- ...selection,
57
- anchor: spanSelectionPoint,
58
- }
59
- : selection
60
- }
61
-
62
- if (isBlockPath(selection.focus.path)) {
63
- const spanSelectionPoint = blockOffsetToSpanSelectionPoint({
64
- context: snapshot.context,
65
- blockOffset: {
66
- path: selection.focus.path,
67
- offset: selection.focus.offset,
68
- },
69
- direction: selection.backward ? 'backward' : 'forward',
70
- })
71
-
72
- selection = spanSelectionPoint
73
- ? {
74
- ...selection,
75
- focus: spanSelectionPoint,
76
- }
77
- : selection
78
- }
79
-
80
- const focusSpan = getFocusSpan({
81
- ...snapshot,
82
- context: {
83
- ...snapshot.context,
84
- selection,
85
- },
86
- })
87
-
88
- if (!focusSpan) {
89
- return undefined
90
- }
91
-
92
- if (isSelectionExpanded(selection)) {
93
- const selectedSpans = getSelectedSpans({
94
- ...snapshot,
95
- context: {
96
- ...snapshot.context,
97
- selection,
98
- },
99
- })
100
-
101
- let index = 0
102
- let marks: Array<string> = []
103
-
104
- for (const span of selectedSpans) {
105
- if (index === 0) {
106
- marks = span.node.marks ?? []
107
- } else {
108
- if (span.node.marks?.length === 0) {
109
- marks = []
110
- continue
111
- }
112
-
113
- marks = marks.filter((mark) =>
114
- (span.node.marks ?? []).some((spanMark) => spanMark === mark),
115
- )
116
- }
117
-
118
- index++
119
- }
120
-
121
- return {
122
- state: 'unchanged',
123
- marks,
124
- }
125
- }
126
-
127
- const decorators = snapshot.context.schema.decorators.map(
128
- (decorator) => decorator.name,
129
- )
130
- const marks = focusSpan.node.marks ?? []
131
- const marksWithoutAnnotations = marks.filter((mark) =>
132
- decorators.includes(mark),
133
- )
134
-
135
- const spanHasAnnotations = marks.length > marksWithoutAnnotations.length
136
-
137
- const spanIsEmpty = focusSpan.node.text.length === 0
138
-
139
- const atTheBeginningOfSpan = snapshot.context.selection.anchor.offset === 0
140
- const atTheEndOfSpan =
141
- snapshot.context.selection.anchor.offset === focusSpan.node.text.length
142
-
143
- const previousSpan = getPreviousSpan({
144
- ...snapshot,
145
- context: {
146
- ...snapshot.context,
147
- selection,
148
- },
149
- })
150
- const nextSpan = getNextSpan({
151
- ...snapshot,
152
- context: {
153
- ...snapshot.context,
154
- selection,
155
- },
156
- })
157
- const nextSpanAnnotations =
158
- nextSpan?.node?.marks?.filter((mark) => !decorators.includes(mark)) ?? []
159
- const spanAnnotations = marks.filter((mark) => !decorators.includes(mark))
160
-
161
- const previousSpanHasAnnotations = previousSpan
162
- ? previousSpan.node.marks?.some((mark) => !decorators.includes(mark))
163
- : false
164
- const previousSpanHasSameAnnotations = previousSpan
165
- ? previousSpan.node.marks
166
- ?.filter((mark) => !decorators.includes(mark))
167
- .every((mark) => marks.includes(mark))
168
- : false
169
- const previousSpanHasSameAnnotation = previousSpan
170
- ? previousSpan.node.marks?.some(
171
- (mark) => !decorators.includes(mark) && marks.includes(mark),
172
- )
173
- : false
174
-
175
- const previousSpanHasSameMarks = previousSpan
176
- ? previousSpan.node.marks?.every((mark) => marks.includes(mark))
177
- : false
178
- const nextSpanSharesSomeAnnotations = spanAnnotations.some((mark) =>
179
- nextSpanAnnotations?.includes(mark),
180
- )
181
-
182
- if (spanHasAnnotations && !spanIsEmpty) {
183
- if (atTheBeginningOfSpan) {
184
- if (previousSpanHasSameMarks) {
185
- return {
186
- state: 'changed',
187
- previousMarks: marks,
188
- marks: previousSpan?.node.marks ?? [],
189
- }
190
- } else if (previousSpanHasSameAnnotations) {
191
- return {
192
- state: 'changed',
193
- previousMarks: marks,
194
- marks: previousSpan?.node.marks ?? [],
195
- }
196
- } else if (previousSpanHasSameAnnotation) {
197
- return {
198
- state: 'unchanged',
199
- marks: focusSpan.node.marks ?? [],
200
- }
201
- } else if (!previousSpan) {
202
- return {
203
- state: 'changed',
204
- previousMarks: marks,
205
- marks: [],
206
- }
207
- }
208
- }
209
-
210
- if (atTheEndOfSpan) {
211
- if (!nextSpan) {
212
- return {
213
- state: 'changed',
214
- previousMarks: marks,
215
- marks: [],
216
- }
217
- }
218
-
219
- if (nextSpanAnnotations.length > 0 && !nextSpanSharesSomeAnnotations) {
220
- return {
221
- state: 'changed',
222
- previousMarks: marks,
223
- marks: [],
224
- }
225
- }
226
-
227
- if (
228
- (nextSpanSharesSomeAnnotations &&
229
- nextSpanAnnotations.length < spanAnnotations.length) ||
230
- !nextSpanSharesSomeAnnotations
231
- ) {
232
- return {
233
- state: 'changed',
234
- previousMarks: marks,
235
- marks: nextSpan?.node.marks ?? [],
236
- }
237
- }
238
- }
239
- }
240
-
241
- if (atTheBeginningOfSpan && !spanIsEmpty && !!previousSpan) {
242
- if (previousSpanHasAnnotations) {
243
- return {
244
- state: 'changed',
245
- marks,
246
- previousMarks: previousSpan?.node.marks ?? [],
247
- }
248
- } else {
249
- return {
250
- state: 'changed',
251
- previousMarks: marks,
252
- marks: (previousSpan?.node.marks ?? []).filter((mark) =>
253
- decorators.includes(mark),
254
- ),
255
- }
256
- }
257
- }
258
-
259
- return {
260
- state: 'unchanged',
261
- marks,
262
- }
263
- }
@@ -1,29 +0,0 @@
1
- import type {PortableTextBlock} from '@sanity/types'
2
- import type {EditorSelector} from '../editor/editor-selector'
3
- import type {BlockPath} from '../types/paths'
4
- import {getSelectionEndBlock} from './selector.get-selection-end-block'
5
-
6
- /**
7
- * @public
8
- */
9
- export const getNextBlock: EditorSelector<
10
- {node: PortableTextBlock; path: BlockPath} | undefined
11
- > = (snapshot) => {
12
- const selectionEndBlock = getSelectionEndBlock(snapshot)
13
-
14
- if (!selectionEndBlock) {
15
- return undefined
16
- }
17
-
18
- const index = snapshot.blockIndexMap.get(selectionEndBlock.node._key)
19
-
20
- if (index === undefined || index === snapshot.context.value.length - 1) {
21
- return undefined
22
- }
23
-
24
- const nextBlock = snapshot.context.value.at(index + 1)
25
-
26
- return nextBlock
27
- ? {node: nextBlock, path: [{_key: nextBlock._key}]}
28
- : undefined
29
- }
@@ -1,53 +0,0 @@
1
- import {isSpan} from '@portabletext/schema'
2
- import {isKeySegment, type PortableTextObject} from '@sanity/types'
3
- import type {EditorSelector} from '../editor/editor-selector'
4
- import type {ChildPath} from '../types/paths'
5
- import {getFocusTextBlock} from './selector.get-focus-text-block'
6
- import {getSelectionEndPoint} from './selector.get-selection-end-point'
7
-
8
- /**
9
- * @public
10
- */
11
- export const getNextInlineObject: EditorSelector<
12
- | {
13
- node: PortableTextObject
14
- path: ChildPath
15
- }
16
- | undefined
17
- > = (snapshot) => {
18
- const focusTextBlock = getFocusTextBlock(snapshot)
19
- const selectionEndPoint = getSelectionEndPoint(snapshot)
20
- const selectionEndPointChildKey =
21
- selectionEndPoint && isKeySegment(selectionEndPoint.path[2])
22
- ? selectionEndPoint.path[2]._key
23
- : undefined
24
-
25
- if (!focusTextBlock || !selectionEndPointChildKey) {
26
- return undefined
27
- }
28
-
29
- let endPointChildFound = false
30
- let inlineObject:
31
- | {
32
- node: PortableTextObject
33
- path: ChildPath
34
- }
35
- | undefined
36
-
37
- for (const child of focusTextBlock.node.children) {
38
- if (child._key === selectionEndPointChildKey) {
39
- endPointChildFound = true
40
- continue
41
- }
42
-
43
- if (!isSpan(snapshot.context, child) && endPointChildFound) {
44
- inlineObject = {
45
- node: child,
46
- path: [...focusTextBlock.path, 'children', {_key: child._key}],
47
- }
48
- break
49
- }
50
- }
51
-
52
- return inlineObject
53
- }
@@ -1,50 +0,0 @@
1
- import {isSpan} from '@portabletext/schema'
2
- import {isKeySegment, type PortableTextObject} from '@sanity/types'
3
- import type {EditorSelector} from '../editor/editor-selector'
4
- import type {ChildPath} from '../types/paths'
5
- import {getFocusTextBlock} from './selector.get-focus-text-block'
6
- import {getSelectionEndPoint} from './selector.get-selection-end-point'
7
-
8
- /**
9
- * @public
10
- */
11
- export const getNextInlineObjects: EditorSelector<
12
- Array<{
13
- node: PortableTextObject
14
- path: ChildPath
15
- }>
16
- > = (snapshot) => {
17
- const focusTextBlock = getFocusTextBlock(snapshot)
18
- const selectionEndPoint = getSelectionEndPoint(snapshot)
19
- const selectionEndPointChildKey =
20
- selectionEndPoint && isKeySegment(selectionEndPoint.path[2])
21
- ? selectionEndPoint.path[2]._key
22
- : undefined
23
-
24
- if (!focusTextBlock || !selectionEndPointChildKey) {
25
- return []
26
- }
27
-
28
- let endPointChildFound = false
29
- const inlineObjects: Array<{
30
- node: PortableTextObject
31
- path: ChildPath
32
- }> = []
33
-
34
- for (const child of focusTextBlock.node.children) {
35
- if (child._key === selectionEndPointChildKey) {
36
- endPointChildFound = true
37
- continue
38
- }
39
-
40
- if (!isSpan(snapshot.context, child) && endPointChildFound) {
41
- inlineObjects.push({
42
- node: child,
43
- path: [...focusTextBlock.path, 'children', {_key: child._key}],
44
- })
45
- break
46
- }
47
- }
48
-
49
- return inlineObjects
50
- }
@@ -1,56 +0,0 @@
1
- import {isSpan, isTextBlock} from '@portabletext/schema'
2
- import type {KeyedSegment, PortableTextSpan} from '@sanity/types'
3
- import type {EditorSelector} from '../editor/editor-selector'
4
- import {getChildKeyFromSelectionPoint} from '../utils/util.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
- }
@@ -1,29 +0,0 @@
1
- import type {PortableTextBlock} from '@sanity/types'
2
- import type {EditorSelector} from '../editor/editor-selector'
3
- import type {BlockPath} from '../types/paths'
4
- import {getSelectionStartBlock} from './selector.get-selection-start-block'
5
-
6
- /**
7
- * @public
8
- */
9
- export const getPreviousBlock: EditorSelector<
10
- {node: PortableTextBlock; path: BlockPath} | undefined
11
- > = (snapshot) => {
12
- const selectionStartBlock = getSelectionStartBlock(snapshot)
13
-
14
- if (!selectionStartBlock) {
15
- return undefined
16
- }
17
-
18
- const index = snapshot.blockIndexMap.get(selectionStartBlock.node._key)
19
-
20
- if (index === undefined || index === 0) {
21
- return undefined
22
- }
23
-
24
- const previousBlock = snapshot.context.value.at(index - 1)
25
-
26
- return previousBlock
27
- ? {node: previousBlock, path: [{_key: previousBlock._key}]}
28
- : undefined
29
- }
@@ -1,50 +0,0 @@
1
- import {isSpan} from '@portabletext/schema'
2
- import {isKeySegment, type PortableTextObject} from '@sanity/types'
3
- import type {EditorSelector} from '../editor/editor-selector'
4
- import type {ChildPath} from '../types/paths'
5
- import {getFocusTextBlock} from './selector.get-focus-text-block'
6
- import {getSelectionStartPoint} from './selector.get-selection-start-point'
7
-
8
- /**
9
- * @public
10
- */
11
- export const getPreviousInlineObject: EditorSelector<
12
- | {
13
- node: PortableTextObject
14
- path: ChildPath
15
- }
16
- | undefined
17
- > = (snapshot) => {
18
- const focusTextBlock = getFocusTextBlock(snapshot)
19
- const selectionStartPoint = getSelectionStartPoint(snapshot)
20
- const selectionStartPointChildKey =
21
- selectionStartPoint && isKeySegment(selectionStartPoint.path[2])
22
- ? selectionStartPoint.path[2]._key
23
- : undefined
24
-
25
- if (!focusTextBlock || !selectionStartPointChildKey) {
26
- return undefined
27
- }
28
-
29
- let inlineObject:
30
- | {
31
- node: PortableTextObject
32
- path: ChildPath
33
- }
34
- | undefined
35
-
36
- for (const child of focusTextBlock.node.children) {
37
- if (child._key === selectionStartPointChildKey) {
38
- break
39
- }
40
-
41
- if (!isSpan(snapshot.context, child)) {
42
- inlineObject = {
43
- node: child,
44
- path: [...focusTextBlock.path, 'children', {_key: child._key}],
45
- }
46
- }
47
- }
48
-
49
- return inlineObject
50
- }
@@ -1,47 +0,0 @@
1
- import {isSpan} from '@portabletext/schema'
2
- import {isKeySegment, type PortableTextObject} from '@sanity/types'
3
- import type {EditorSelector} from '../editor/editor-selector'
4
- import type {ChildPath} from '../types/paths'
5
- import {getFocusTextBlock} from './selector.get-focus-text-block'
6
- import {getSelectionStartPoint} from './selector.get-selection-start-point'
7
-
8
- /**
9
- * @public
10
- */
11
- export const getPreviousInlineObjects: EditorSelector<
12
- Array<{
13
- node: PortableTextObject
14
- path: ChildPath
15
- }>
16
- > = (snapshot) => {
17
- const focusTextBlock = getFocusTextBlock(snapshot)
18
- const selectionStartPoint = getSelectionStartPoint(snapshot)
19
- const selectionStartPointChildKey =
20
- selectionStartPoint && isKeySegment(selectionStartPoint.path[2])
21
- ? selectionStartPoint.path[2]._key
22
- : undefined
23
-
24
- if (!focusTextBlock || !selectionStartPointChildKey) {
25
- return []
26
- }
27
-
28
- const inlineObjects: Array<{
29
- node: PortableTextObject
30
- path: ChildPath
31
- }> = []
32
-
33
- for (const child of focusTextBlock.node.children) {
34
- if (child._key === selectionStartPointChildKey) {
35
- break
36
- }
37
-
38
- if (!isSpan(snapshot.context, child)) {
39
- inlineObjects.push({
40
- node: child,
41
- path: [...focusTextBlock.path, 'children', {_key: child._key}],
42
- })
43
- }
44
- }
45
-
46
- return inlineObjects
47
- }
@@ -1,53 +0,0 @@
1
- import {isSpan, isTextBlock} from '@portabletext/schema'
2
- import type {KeyedSegment, PortableTextSpan} from '@sanity/types'
3
- import type {EditorSelector} from '../editor/editor-selector'
4
- import {getChildKeyFromSelectionPoint} from '../utils/util.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,61 +0,0 @@
1
- import type {PortableTextBlock} from '@sanity/types'
2
- import type {EditorSelector} from '../editor/editor-selector'
3
- import type {BlockPath} from '../types/paths'
4
- import {getSelectionEndPoint} from '../utils/util.get-selection-end-point'
5
- import {getSelectionStartPoint} from '../utils/util.get-selection-start-point'
6
- import {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'
7
-
8
- /**
9
- * @public
10
- */
11
- export const getSelectedBlocks: EditorSelector<
12
- Array<{node: PortableTextBlock; path: BlockPath}>
13
- > = (snapshot) => {
14
- if (!snapshot.context.selection) {
15
- return []
16
- }
17
-
18
- const selectedBlocks: Array<{node: PortableTextBlock; path: BlockPath}> = []
19
- const startPoint = getSelectionStartPoint(snapshot.context.selection)
20
- const endPoint = getSelectionEndPoint(snapshot.context.selection)
21
- const startKey = getBlockKeyFromSelectionPoint(startPoint)
22
- const endKey = getBlockKeyFromSelectionPoint(endPoint)
23
-
24
- if (!startKey || !endKey) {
25
- return selectedBlocks
26
- }
27
-
28
- const startBlockIndex = snapshot.blockIndexMap.get(startKey)
29
- const endBlockIndex = snapshot.blockIndexMap.get(endKey)
30
-
31
- if (startBlockIndex === undefined || endBlockIndex === undefined) {
32
- return selectedBlocks
33
- }
34
-
35
- const slicedValue = snapshot.context.value.slice(
36
- startBlockIndex,
37
- endBlockIndex + 1,
38
- )
39
-
40
- for (const block of slicedValue) {
41
- if (block._key === startKey) {
42
- selectedBlocks.push({node: block, path: [{_key: block._key}]})
43
-
44
- if (startKey === endKey) {
45
- break
46
- }
47
- continue
48
- }
49
-
50
- if (block._key === endKey) {
51
- selectedBlocks.push({node: block, path: [{_key: block._key}]})
52
- break
53
- }
54
-
55
- if (selectedBlocks.length > 0) {
56
- selectedBlocks.push({node: block, path: [{_key: block._key}]})
57
- }
58
- }
59
-
60
- return selectedBlocks
61
- }