@portabletext/editor 3.3.3 → 3.3.5

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 (309) hide show
  1. package/lib/_chunks-dts/index.d.ts +21 -1667
  2. package/lib/index.js +511 -9010
  3. package/lib/index.js.map +1 -1
  4. package/package.json +14 -15
  5. package/src/behaviors/_exports/index.ts +0 -1
  6. package/src/behaviors/behavior.abstract.annotation.ts +0 -77
  7. package/src/behaviors/behavior.abstract.decorator.ts +0 -39
  8. package/src/behaviors/behavior.abstract.delete.ts +0 -273
  9. package/src/behaviors/behavior.abstract.deserialize.ts +0 -232
  10. package/src/behaviors/behavior.abstract.insert.ts +0 -525
  11. package/src/behaviors/behavior.abstract.keyboard.ts +0 -189
  12. package/src/behaviors/behavior.abstract.list-item.ts +0 -70
  13. package/src/behaviors/behavior.abstract.move.ts +0 -79
  14. package/src/behaviors/behavior.abstract.select.ts +0 -118
  15. package/src/behaviors/behavior.abstract.serialize.ts +0 -96
  16. package/src/behaviors/behavior.abstract.split.ts +0 -170
  17. package/src/behaviors/behavior.abstract.style.ts +0 -55
  18. package/src/behaviors/behavior.abstract.ts +0 -139
  19. package/src/behaviors/behavior.config.ts +0 -7
  20. package/src/behaviors/behavior.core.annotations.ts +0 -62
  21. package/src/behaviors/behavior.core.block-element.ts +0 -116
  22. package/src/behaviors/behavior.core.block-objects.ts +0 -285
  23. package/src/behaviors/behavior.core.decorators.ts +0 -44
  24. package/src/behaviors/behavior.core.dnd.ts +0 -356
  25. package/src/behaviors/behavior.core.insert-break.ts +0 -266
  26. package/src/behaviors/behavior.core.insert.ts +0 -52
  27. package/src/behaviors/behavior.core.lists.ts +0 -691
  28. package/src/behaviors/behavior.core.ts +0 -44
  29. package/src/behaviors/behavior.perform-event.ts +0 -354
  30. package/src/behaviors/behavior.types.action.ts +0 -102
  31. package/src/behaviors/behavior.types.behavior.ts +0 -83
  32. package/src/behaviors/behavior.types.event.ts +0 -667
  33. package/src/behaviors/behavior.types.guard.ts +0 -11
  34. package/src/behaviors/index.ts +0 -17
  35. package/src/converters/converter.json.ts +0 -53
  36. package/src/converters/converter.portable-text.deserialize.test.ts +0 -680
  37. package/src/converters/converter.portable-text.ts +0 -75
  38. package/src/converters/converter.text-html.deserialize.test.ts +0 -406
  39. package/src/converters/converter.text-html.serialize.test.ts +0 -246
  40. package/src/converters/converter.text-html.ts +0 -87
  41. package/src/converters/converter.text-markdown.ts +0 -67
  42. package/src/converters/converter.text-plain.test.ts +0 -245
  43. package/src/converters/converter.text-plain.ts +0 -126
  44. package/src/converters/converter.types.ts +0 -72
  45. package/src/converters/converters.core.ts +0 -18
  46. package/src/editor/Editable.tsx +0 -1012
  47. package/src/editor/PortableTextEditor.tsx +0 -791
  48. package/src/editor/components/drop-indicator.tsx +0 -17
  49. package/src/editor/components/render-block-object.tsx +0 -121
  50. package/src/editor/components/render-default-object.tsx +0 -21
  51. package/src/editor/components/render-element.tsx +0 -88
  52. package/src/editor/components/render-inline-object.tsx +0 -129
  53. package/src/editor/components/render-leaf.tsx +0 -64
  54. package/src/editor/components/render-span.tsx +0 -303
  55. package/src/editor/components/render-text-block.tsx +0 -265
  56. package/src/editor/components/render-text.tsx +0 -18
  57. package/src/editor/components/use-core-block-element-behaviors.ts +0 -39
  58. package/src/editor/create-editor.ts +0 -323
  59. package/src/editor/create-slate-editor.tsx +0 -64
  60. package/src/editor/editor-actor-context.ts +0 -4
  61. package/src/editor/editor-context.tsx +0 -7
  62. package/src/editor/editor-dom.ts +0 -220
  63. package/src/editor/editor-machine.ts +0 -751
  64. package/src/editor/editor-provider.tsx +0 -111
  65. package/src/editor/editor-schema.ts +0 -6
  66. package/src/editor/editor-selector.ts +0 -89
  67. package/src/editor/editor-snapshot.ts +0 -68
  68. package/src/editor/event-to-change.tsx +0 -49
  69. package/src/editor/hooks/usePortableTextEditor.ts +0 -25
  70. package/src/editor/hooks/usePortableTextEditorSelection.tsx +0 -28
  71. package/src/editor/mutation-machine.ts +0 -322
  72. package/src/editor/plugins/create-with-event-listeners.ts +0 -271
  73. package/src/editor/plugins/createWithEditableAPI.ts +0 -529
  74. package/src/editor/plugins/createWithHotKeys.ts +0 -68
  75. package/src/editor/plugins/createWithObjectKeys.ts +0 -289
  76. package/src/editor/plugins/createWithPatches.ts +0 -272
  77. package/src/editor/plugins/createWithPortableTextMarkModel.ts +0 -559
  78. package/src/editor/plugins/createWithSchemaTypes.ts +0 -121
  79. package/src/editor/plugins/slate-plugin.update-selection.ts +0 -51
  80. package/src/editor/plugins/slate-plugin.update-value.ts +0 -46
  81. package/src/editor/plugins/with-plugins.ts +0 -69
  82. package/src/editor/range-decorations-machine.ts +0 -421
  83. package/src/editor/relay-actor-context.ts +0 -4
  84. package/src/editor/relay-machine.ts +0 -152
  85. package/src/editor/sync-machine.ts +0 -961
  86. package/src/editor/use-editor.ts +0 -27
  87. package/src/editor/validate-selection-machine.test.ts +0 -47
  88. package/src/editor/validate-selection-machine.ts +0 -149
  89. package/src/editor/weakMaps.ts +0 -15
  90. package/src/editor/with-normalizing-node.ts +0 -14
  91. package/src/editor/with-performing-behavior-operation.ts +0 -21
  92. package/src/editor/withChanges.ts +0 -13
  93. package/src/editor/without-normalizing-conditional.ts +0 -13
  94. package/src/editor/withoutPatching.ts +0 -14
  95. package/src/editor.ts +0 -59
  96. package/src/history/behavior.operation.history.redo.ts +0 -67
  97. package/src/history/behavior.operation.history.undo.ts +0 -71
  98. package/src/history/event.history.undo.test.tsx +0 -672
  99. package/src/history/history.preserving-keys.test.tsx +0 -112
  100. package/src/history/remote-patches.ts +0 -20
  101. package/src/history/slate-plugin.history.ts +0 -142
  102. package/src/history/slate-plugin.redoing.ts +0 -21
  103. package/src/history/slate-plugin.undoing.ts +0 -21
  104. package/src/history/slate-plugin.without-history.ts +0 -23
  105. package/src/history/transform-operation.ts +0 -245
  106. package/src/history/undo-redo-collaboration.test.tsx +0 -541
  107. package/src/history/undo-redo.feature +0 -125
  108. package/src/history/undo-redo.test.tsx +0 -195
  109. package/src/history/undo-step.ts +0 -148
  110. package/src/index.ts +0 -107
  111. package/src/internal-utils/__tests__/ranges.test.ts +0 -23
  112. package/src/internal-utils/__tests__/values.test.ts +0 -110
  113. package/src/internal-utils/apply-operation-to-portable-text.test.ts +0 -1861
  114. package/src/internal-utils/apply-operation-to-portable-text.ts +0 -615
  115. package/src/internal-utils/applyPatch.ts +0 -644
  116. package/src/internal-utils/block-keys.ts +0 -9
  117. package/src/internal-utils/build-index-maps.test.ts +0 -464
  118. package/src/internal-utils/build-index-maps.ts +0 -131
  119. package/src/internal-utils/collapse-selection.ts +0 -36
  120. package/src/internal-utils/compound-client-rect.ts +0 -28
  121. package/src/internal-utils/create-placeholder-block.ts +0 -21
  122. package/src/internal-utils/create-test-snapshot.ts +0 -28
  123. package/src/internal-utils/debug.ts +0 -12
  124. package/src/internal-utils/editor-selection.test.ts +0 -44
  125. package/src/internal-utils/editor-selection.ts +0 -56
  126. package/src/internal-utils/event-position.ts +0 -318
  127. package/src/internal-utils/global-scope.ts +0 -27
  128. package/src/internal-utils/globally-scoped-context.ts +0 -39
  129. package/src/internal-utils/is-hotkey.test.ts +0 -114
  130. package/src/internal-utils/is-hotkey.ts +0 -209
  131. package/src/internal-utils/mime-type.ts +0 -1
  132. package/src/internal-utils/move-range-by-operation.ts +0 -19
  133. package/src/internal-utils/operation-to-patches.test.ts +0 -522
  134. package/src/internal-utils/operation-to-patches.ts +0 -571
  135. package/src/internal-utils/portable-text-node.ts +0 -209
  136. package/src/internal-utils/schema.ts +0 -8
  137. package/src/internal-utils/selection-block-keys.ts +0 -20
  138. package/src/internal-utils/selection-focus-text.ts +0 -40
  139. package/src/internal-utils/selection-text.test.ts +0 -32
  140. package/src/internal-utils/selection-text.ts +0 -21
  141. package/src/internal-utils/selection.ts +0 -77
  142. package/src/internal-utils/sibling-utils.ts +0 -55
  143. package/src/internal-utils/slate-utils.test.tsx +0 -121
  144. package/src/internal-utils/slate-utils.ts +0 -417
  145. package/src/internal-utils/split-string.ts +0 -12
  146. package/src/internal-utils/stop-actor.ts +0 -43
  147. package/src/internal-utils/string-overlap.test.ts +0 -14
  148. package/src/internal-utils/string-overlap.ts +0 -28
  149. package/src/internal-utils/string-utils.ts +0 -7
  150. package/src/internal-utils/text-block-key.test.ts +0 -41
  151. package/src/internal-utils/text-block-key.ts +0 -26
  152. package/src/internal-utils/text-marks.test.ts +0 -41
  153. package/src/internal-utils/text-marks.ts +0 -22
  154. package/src/internal-utils/text-selection.test.ts +0 -211
  155. package/src/internal-utils/text-selection.ts +0 -121
  156. package/src/internal-utils/to-slate-range.test.ts +0 -278
  157. package/src/internal-utils/to-slate-range.ts +0 -171
  158. package/src/internal-utils/validateValue.ts +0 -443
  159. package/src/internal-utils/value-annotations.ts +0 -33
  160. package/src/internal-utils/values.test.ts +0 -282
  161. package/src/internal-utils/values.ts +0 -266
  162. package/src/keyboard-shortcuts/default-keyboard-shortcuts.ts +0 -146
  163. package/src/operations/behavior.operation.annotation.add.ts +0 -99
  164. package/src/operations/behavior.operation.annotation.remove.ts +0 -150
  165. package/src/operations/behavior.operation.block.set.ts +0 -104
  166. package/src/operations/behavior.operation.block.unset.ts +0 -54
  167. package/src/operations/behavior.operation.child.set.ts +0 -107
  168. package/src/operations/behavior.operation.child.unset.ts +0 -116
  169. package/src/operations/behavior.operation.decorator.add.ts +0 -131
  170. package/src/operations/behavior.operation.delete.ts +0 -294
  171. package/src/operations/behavior.operation.insert.block.ts +0 -495
  172. package/src/operations/behavior.operation.insert.child.ts +0 -129
  173. package/src/operations/behavior.operation.insert.text.ts +0 -8
  174. package/src/operations/behavior.operation.move.backward.ts +0 -12
  175. package/src/operations/behavior.operation.move.block.ts +0 -44
  176. package/src/operations/behavior.operation.move.forward.ts +0 -11
  177. package/src/operations/behavior.operation.select.ts +0 -27
  178. package/src/operations/behavior.operations.ts +0 -221
  179. package/src/plugins/_exports/index.ts +0 -1
  180. package/src/plugins/index.ts +0 -3
  181. package/src/plugins/plugin.behavior.tsx +0 -24
  182. package/src/plugins/plugin.editor-ref.tsx +0 -17
  183. package/src/plugins/plugin.event-listener.tsx +0 -68
  184. package/src/plugins/plugin.internal.auto-close-brackets.test.tsx +0 -71
  185. package/src/plugins/plugin.internal.auto-close-brackets.ts +0 -62
  186. package/src/plugins/plugin.internal.change-ref.tsx +0 -19
  187. package/src/plugins/plugin.internal.portable-text-editor-ref.tsx +0 -16
  188. package/src/plugins/plugin.internal.slate-editor-ref.tsx +0 -15
  189. package/src/priority/priority.core.ts +0 -3
  190. package/src/priority/priority.sort.test.ts +0 -319
  191. package/src/priority/priority.sort.ts +0 -123
  192. package/src/priority/priority.types.ts +0 -24
  193. package/src/selectors/_exports/index.ts +0 -1
  194. package/src/selectors/drag-selection.test.ts +0 -578
  195. package/src/selectors/drag-selection.ts +0 -118
  196. package/src/selectors/index.ts +0 -54
  197. package/src/selectors/selector.get-active-annotation-marks.ts +0 -12
  198. package/src/selectors/selector.get-active-annotations.ts +0 -36
  199. package/src/selectors/selector.get-active-decorators.ts +0 -29
  200. package/src/selectors/selector.get-active-list-item.ts +0 -38
  201. package/src/selectors/selector.get-active-style.ts +0 -38
  202. package/src/selectors/selector.get-anchor-block.ts +0 -22
  203. package/src/selectors/selector.get-anchor-child.ts +0 -36
  204. package/src/selectors/selector.get-anchor-span.ts +0 -17
  205. package/src/selectors/selector.get-anchor-text-block.ts +0 -18
  206. package/src/selectors/selector.get-block-offsets.ts +0 -34
  207. package/src/selectors/selector.get-caret-word-selection.test.ts +0 -284
  208. package/src/selectors/selector.get-caret-word-selection.ts +0 -134
  209. package/src/selectors/selector.get-first-block.ts +0 -14
  210. package/src/selectors/selector.get-focus-block-object.ts +0 -18
  211. package/src/selectors/selector.get-focus-block.ts +0 -23
  212. package/src/selectors/selector.get-focus-child.ts +0 -36
  213. package/src/selectors/selector.get-focus-inline-object.ts +0 -17
  214. package/src/selectors/selector.get-focus-list-block.ts +0 -18
  215. package/src/selectors/selector.get-focus-span.ts +0 -18
  216. package/src/selectors/selector.get-focus-text-block.ts +0 -18
  217. package/src/selectors/selector.get-last-block.ts +0 -16
  218. package/src/selectors/selector.get-mark-state.test.ts +0 -325
  219. package/src/selectors/selector.get-mark-state.ts +0 -263
  220. package/src/selectors/selector.get-next-block.ts +0 -29
  221. package/src/selectors/selector.get-next-inline-object.ts +0 -53
  222. package/src/selectors/selector.get-next-inline-objects.ts +0 -50
  223. package/src/selectors/selector.get-next-span.ts +0 -56
  224. package/src/selectors/selector.get-previous-block.ts +0 -29
  225. package/src/selectors/selector.get-previous-inline-object.ts +0 -50
  226. package/src/selectors/selector.get-previous-inline-objects.ts +0 -47
  227. package/src/selectors/selector.get-previous-span.ts +0 -53
  228. package/src/selectors/selector.get-selected-blocks.ts +0 -61
  229. package/src/selectors/selector.get-selected-spans.test.ts +0 -347
  230. package/src/selectors/selector.get-selected-spans.ts +0 -155
  231. package/src/selectors/selector.get-selected-text-blocks.ts +0 -73
  232. package/src/selectors/selector.get-selected-value.test.ts +0 -834
  233. package/src/selectors/selector.get-selected-value.ts +0 -66
  234. package/src/selectors/selector.get-selection-end-block.ts +0 -33
  235. package/src/selectors/selector.get-selection-end-child.ts +0 -33
  236. package/src/selectors/selector.get-selection-end-point.ts +0 -17
  237. package/src/selectors/selector.get-selection-start-block.ts +0 -33
  238. package/src/selectors/selector.get-selection-start-child.ts +0 -33
  239. package/src/selectors/selector.get-selection-start-point.ts +0 -17
  240. package/src/selectors/selector.get-selection-text.test.ts +0 -421
  241. package/src/selectors/selector.get-selection-text.ts +0 -27
  242. package/src/selectors/selector.get-selection.ts +0 -9
  243. package/src/selectors/selector.get-text-after.ts +0 -46
  244. package/src/selectors/selector.get-text-before.ts +0 -46
  245. package/src/selectors/selector.get-value.ts +0 -11
  246. package/src/selectors/selector.is-active-annotation.test.ts +0 -320
  247. package/src/selectors/selector.is-active-annotation.ts +0 -52
  248. package/src/selectors/selector.is-active-decorator.test.ts +0 -136
  249. package/src/selectors/selector.is-active-decorator.ts +0 -24
  250. package/src/selectors/selector.is-active-list-item.ts +0 -13
  251. package/src/selectors/selector.is-active-style.ts +0 -13
  252. package/src/selectors/selector.is-at-the-end-of-block.ts +0 -30
  253. package/src/selectors/selector.is-at-the-start-of-block.ts +0 -30
  254. package/src/selectors/selector.is-overlapping-selection.test.ts +0 -304
  255. package/src/selectors/selector.is-overlapping-selection.ts +0 -181
  256. package/src/selectors/selector.is-point-after-selection.ts +0 -97
  257. package/src/selectors/selector.is-point-before-selection.ts +0 -97
  258. package/src/selectors/selector.is-selecting-entire-blocks.ts +0 -43
  259. package/src/selectors/selector.is-selection-collapsed.ts +0 -17
  260. package/src/selectors/selector.is-selection-expanded.test.ts +0 -63
  261. package/src/selectors/selector.is-selection-expanded.ts +0 -9
  262. package/src/test/_exports/index.ts +0 -1
  263. package/src/test/gherkin-parameter-types.ts +0 -112
  264. package/src/test/index.ts +0 -1
  265. package/src/test/vitest/_exports/index.ts +0 -1
  266. package/src/test/vitest/index.ts +0 -3
  267. package/src/test/vitest/step-context.ts +0 -13
  268. package/src/test/vitest/step-definitions.tsx +0 -960
  269. package/src/test/vitest/test-editor.tsx +0 -198
  270. package/src/type-utils.ts +0 -29
  271. package/src/types/block-offset.ts +0 -9
  272. package/src/types/block-with-optional-key.ts +0 -25
  273. package/src/types/editor.ts +0 -509
  274. package/src/types/options.ts +0 -13
  275. package/src/types/paths.ts +0 -35
  276. package/src/types/slate-editor.ts +0 -50
  277. package/src/types/slate.ts +0 -27
  278. package/src/utils/_exports/index.ts +0 -1
  279. package/src/utils/asserters.ts +0 -9
  280. package/src/utils/index.ts +0 -24
  281. package/src/utils/key-generator.ts +0 -33
  282. package/src/utils/parse-blocks.test.ts +0 -836
  283. package/src/utils/parse-blocks.ts +0 -504
  284. package/src/utils/util.at-the-beginning-of-block.ts +0 -32
  285. package/src/utils/util.block-offset-to-block-selection-point.ts +0 -28
  286. package/src/utils/util.block-offset-to-selection-point.ts +0 -33
  287. package/src/utils/util.block-offset.test.ts +0 -375
  288. package/src/utils/util.block-offset.ts +0 -136
  289. package/src/utils/util.block-offsets-to-selection.ts +0 -38
  290. package/src/utils/util.child-selection-point-to-block-offset.ts +0 -51
  291. package/src/utils/util.get-block-end-point.ts +0 -35
  292. package/src/utils/util.get-block-start-point.ts +0 -31
  293. package/src/utils/util.get-selection-end-point.ts +0 -20
  294. package/src/utils/util.get-selection-start-point.ts +0 -20
  295. package/src/utils/util.get-text-block-text.ts +0 -8
  296. package/src/utils/util.is-empty-text-block.ts +0 -21
  297. package/src/utils/util.is-equal-selection-points.ts +0 -13
  298. package/src/utils/util.is-equal-selections.ts +0 -20
  299. package/src/utils/util.is-keyed-segment.ts +0 -8
  300. package/src/utils/util.is-selection-collapsed.ts +0 -16
  301. package/src/utils/util.is-selection-expanded.ts +0 -13
  302. package/src/utils/util.merge-text-blocks.ts +0 -40
  303. package/src/utils/util.reverse-selection.ts +0 -26
  304. package/src/utils/util.selection-point-to-block-offset.ts +0 -30
  305. package/src/utils/util.selection-point.ts +0 -22
  306. package/src/utils/util.slice-blocks.ts +0 -221
  307. package/src/utils/util.slice-text-block.test.ts +0 -190
  308. package/src/utils/util.slice-text-block.ts +0 -89
  309. package/src/utils/util.split-text-block.ts +0 -54
@@ -1,834 +0,0 @@
1
- import {compileSchema, defineSchema} from '@portabletext/schema'
2
- import {createTestKeyGenerator} from '@portabletext/test'
3
- import type {PortableTextBlock, PortableTextTextBlock} from '@sanity/types'
4
- import {describe, expect, test} from 'vitest'
5
- import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
6
- import {getSelectedValue} from './selector.get-selected-value'
7
-
8
- const b1: PortableTextTextBlock = {
9
- _type: 'block',
10
- _key: 'b1',
11
- children: [
12
- {
13
- _type: 'span',
14
- _key: 'b1c1',
15
- text: 'foo',
16
- marks: [],
17
- },
18
- {
19
- _type: 'span',
20
- _key: 'b1c2',
21
- text: 'bar',
22
- marks: [],
23
- },
24
- ],
25
- markDefs: [],
26
- style: 'normal',
27
- }
28
- const b2: PortableTextBlock = {
29
- _type: 'image',
30
- _key: 'b2',
31
- src: 'https://example.com/image.jpg',
32
- alt: 'Example',
33
- }
34
- const b3: PortableTextTextBlock = {
35
- _type: 'block',
36
- _key: 'b3',
37
- children: [
38
- {
39
- _type: 'span',
40
- _key: 'b3c1',
41
- text: 'baz',
42
- marks: [],
43
- },
44
- ],
45
- markDefs: [],
46
- style: 'normal',
47
- }
48
- const b4: PortableTextTextBlock = {
49
- _type: 'block',
50
- _key: 'b4',
51
- children: [
52
- {
53
- _type: 'span',
54
- _key: 'b4c1',
55
- text: 'fizz',
56
- marks: [],
57
- },
58
- {
59
- _type: 'stock-ticker',
60
- _key: 'b4c2',
61
- symbol: 'AAPL',
62
- },
63
- {
64
- _type: 'span',
65
- _key: 'b4c3',
66
- text: 'buzz',
67
- marks: [],
68
- },
69
- ],
70
- markDefs: [],
71
- style: 'normal',
72
- }
73
-
74
- const schema = compileSchema(
75
- defineSchema({
76
- decorators: [{name: 'strong'}],
77
- blockObjects: [{name: 'image'}],
78
- inlineObjects: [{name: 'stock-ticker'}],
79
- }),
80
- )
81
- const blocks: Array<PortableTextBlock> = [b1, b2, b3, b4]
82
-
83
- describe(getSelectedValue.name, () => {
84
- test('sensible defaults', () => {
85
- expect(
86
- getSelectedValue(
87
- createTestSnapshot({
88
- context: {
89
- schema,
90
- selection: null,
91
- value: [],
92
- },
93
- }),
94
- ),
95
- ).toEqual([])
96
- expect(
97
- getSelectedValue(
98
- createTestSnapshot({
99
- context: {
100
- schema,
101
- selection: null,
102
- value: [],
103
- },
104
- }),
105
- ),
106
- ).toEqual([])
107
- })
108
-
109
- test('slicing a single block', () => {
110
- expect(
111
- getSelectedValue(
112
- createTestSnapshot({
113
- context: {
114
- schema,
115
- selection: {
116
- anchor: {
117
- path: [
118
- {_key: b1._key},
119
- 'children',
120
- {_key: b1.children[0]._key},
121
- ],
122
- offset: 0,
123
- },
124
- focus: {
125
- path: [
126
- {_key: b1._key},
127
- 'children',
128
- {_key: b1.children[0]._key},
129
- ],
130
- offset: 3,
131
- },
132
- },
133
- value: blocks,
134
- },
135
- }),
136
- ),
137
- ).toEqual([
138
- {
139
- ...b1,
140
- children: [b1.children[0]],
141
- },
142
- ])
143
- })
144
-
145
- test('slicing a single span', () => {
146
- expect(
147
- getSelectedValue(
148
- createTestSnapshot({
149
- context: {
150
- schema,
151
- selection: {
152
- anchor: {
153
- path: [
154
- {_key: b1._key},
155
- 'children',
156
- {_key: b1.children[0]._key},
157
- ],
158
- offset: 1,
159
- },
160
- focus: {
161
- path: [
162
- {_key: b1._key},
163
- 'children',
164
- {_key: b1.children[0]._key},
165
- ],
166
- offset: 2,
167
- },
168
- },
169
- value: blocks,
170
- },
171
- }),
172
- ),
173
- ).toEqual([
174
- {
175
- ...b1,
176
- children: [
177
- {
178
- ...b1.children[0],
179
- text: 'o',
180
- },
181
- ],
182
- },
183
- ])
184
- })
185
-
186
- test('starting and ending selection on a block object', () => {
187
- expect(
188
- getSelectedValue(
189
- createTestSnapshot({
190
- context: {
191
- schema,
192
- selection: {
193
- anchor: {
194
- path: [{_key: b2._key}],
195
- offset: 0,
196
- },
197
- focus: {
198
- path: [{_key: b2._key}],
199
- offset: 0,
200
- },
201
- },
202
- value: blocks,
203
- },
204
- }),
205
- ),
206
- ).toEqual([b2])
207
- })
208
-
209
- test('starting selection on a block object', () => {
210
- expect(
211
- getSelectedValue(
212
- createTestSnapshot({
213
- context: {
214
- schema,
215
- selection: {
216
- anchor: {
217
- path: [{_key: b2._key}],
218
- offset: 0,
219
- },
220
- focus: {
221
- path: [
222
- {_key: b3._key},
223
- 'children',
224
- {_key: b3.children[0]._key},
225
- ],
226
- offset: 3,
227
- },
228
- },
229
- value: blocks,
230
- },
231
- }),
232
- ),
233
- ).toEqual([b2, b3])
234
- })
235
-
236
- test('ending selection on a block object', () => {
237
- expect(
238
- getSelectedValue(
239
- createTestSnapshot({
240
- context: {
241
- schema,
242
- selection: {
243
- anchor: {
244
- path: [
245
- {_key: b1._key},
246
- 'children',
247
- {_key: b1.children[0]._key},
248
- ],
249
- offset: 3,
250
- },
251
- focus: {
252
- path: [{_key: b2._key}],
253
- offset: 0,
254
- },
255
- },
256
- value: blocks,
257
- },
258
- }),
259
- ),
260
- ).toEqual([
261
- {
262
- ...b1,
263
- children: [
264
- {
265
- ...b1.children[0],
266
- text: '',
267
- },
268
- ...b1.children.slice(1),
269
- ],
270
- },
271
- blocks[1],
272
- ])
273
- })
274
-
275
- test('slicing across block object', () => {
276
- expect(
277
- getSelectedValue(
278
- createTestSnapshot({
279
- context: {
280
- schema,
281
- selection: {
282
- anchor: {
283
- path: [
284
- {_key: b1._key},
285
- 'children',
286
- {_key: b1.children[0]._key},
287
- ],
288
- offset: 0,
289
- },
290
- focus: {
291
- path: [
292
- {_key: b3._key},
293
- 'children',
294
- {_key: b3.children[0]._key},
295
- ],
296
- offset: 3,
297
- },
298
- },
299
- value: blocks,
300
- },
301
- }),
302
- ),
303
- ).toEqual([b1, b2, b3])
304
- })
305
-
306
- test('starting and ending mid-span', () => {
307
- expect(
308
- getSelectedValue(
309
- createTestSnapshot({
310
- context: {
311
- schema,
312
- selection: {
313
- anchor: {
314
- path: [
315
- {_key: b3._key},
316
- 'children',
317
- {_key: b3.children[0]._key},
318
- ],
319
- offset: 2,
320
- },
321
- focus: {
322
- path: [
323
- {_key: b4._key},
324
- 'children',
325
- {_key: b4.children[0]._key},
326
- ],
327
- offset: 1,
328
- },
329
- },
330
- value: blocks,
331
- },
332
- }),
333
- ),
334
- ).toEqual([
335
- {
336
- ...b3,
337
- children: [
338
- {
339
- ...b3.children[0],
340
- text: 'z',
341
- },
342
- ],
343
- },
344
- {
345
- ...b4,
346
- children: [
347
- {
348
- ...b4.children[0],
349
- text: 'f',
350
- },
351
- ],
352
- },
353
- ])
354
- })
355
-
356
- test('starting mid-span and ending end-span', () => {
357
- expect(
358
- getSelectedValue(
359
- createTestSnapshot({
360
- context: {
361
- schema,
362
- selection: {
363
- anchor: {
364
- path: [
365
- {_key: b3._key},
366
- 'children',
367
- {_key: b3.children[0]._key},
368
- ],
369
- offset: 2,
370
- },
371
- focus: {
372
- path: [
373
- {_key: b4._key},
374
- 'children',
375
- {_key: b4.children[0]._key},
376
- ],
377
- offset: 4,
378
- },
379
- },
380
- value: blocks,
381
- },
382
- }),
383
- ),
384
- ).toEqual([
385
- {
386
- ...b3,
387
- children: [
388
- {
389
- ...b3.children[0],
390
- text: 'z',
391
- },
392
- ],
393
- },
394
- {
395
- ...b4,
396
- children: [
397
- {
398
- ...b4.children[0],
399
- },
400
- ],
401
- },
402
- ])
403
- })
404
-
405
- test('starting on inline object', () => {
406
- expect(
407
- getSelectedValue(
408
- createTestSnapshot({
409
- context: {
410
- schema,
411
- selection: {
412
- anchor: {
413
- path: [
414
- {_key: b4._key},
415
- 'children',
416
- {_key: b4.children[1]._key},
417
- ],
418
- offset: 0,
419
- },
420
- focus: {
421
- path: [
422
- {_key: b4._key},
423
- 'children',
424
- {_key: b4.children[2]._key},
425
- ],
426
- offset: 4,
427
- },
428
- },
429
- value: blocks,
430
- },
431
- }),
432
- ),
433
- ).toEqual([
434
- {
435
- ...b4,
436
- children: [b4.children[1], b4.children[2]],
437
- },
438
- ])
439
- })
440
-
441
- test('ending on inline object', () => {
442
- expect(
443
- getSelectedValue(
444
- createTestSnapshot({
445
- context: {
446
- schema,
447
- selection: {
448
- anchor: {
449
- path: [
450
- {_key: b4._key},
451
- 'children',
452
- {_key: b4.children[0]._key},
453
- ],
454
- offset: 0,
455
- },
456
- focus: {
457
- path: [
458
- {_key: b4._key},
459
- 'children',
460
- {_key: b4.children[1]._key},
461
- ],
462
- offset: 0,
463
- },
464
- },
465
- value: blocks,
466
- },
467
- }),
468
- ),
469
- ).toEqual([
470
- {
471
- ...b4,
472
- children: [b4.children[0], b4.children[1]],
473
- },
474
- ])
475
- })
476
-
477
- test('starting and ending on inline object', () => {
478
- expect(
479
- getSelectedValue(
480
- createTestSnapshot({
481
- context: {
482
- schema,
483
- selection: {
484
- anchor: {
485
- path: [
486
- {_key: b4._key},
487
- 'children',
488
- {_key: b4.children[1]._key},
489
- ],
490
- offset: 0,
491
- },
492
- focus: {
493
- path: [
494
- {_key: b4._key},
495
- 'children',
496
- {_key: b4.children[1]._key},
497
- ],
498
- offset: 0,
499
- },
500
- },
501
- value: blocks,
502
- },
503
- }),
504
- ),
505
- ).toEqual([
506
- {
507
- ...b4,
508
- children: [b4.children[1]],
509
- },
510
- ])
511
- })
512
-
513
- test('slicing text block with custom props', () => {
514
- expect(
515
- getSelectedValue(
516
- createTestSnapshot({
517
- context: {
518
- schema,
519
- selection: {
520
- anchor: {
521
- path: [{_key: 'b0'}, 'children', {_key: 's0'}],
522
- offset: 7,
523
- },
524
- focus: {
525
- path: [{_key: 'b0'}, 'children', {_key: 's0'}],
526
- offset: 12,
527
- },
528
- },
529
- value: [
530
- {
531
- _key: 'b0',
532
- _type: 'block',
533
- children: [
534
- {_key: 's0', _type: 'span', text: 'Hello, world!', marks: []},
535
- ],
536
- markDefs: [],
537
- style: 'normal',
538
- _map: {},
539
- },
540
- ],
541
- },
542
- }),
543
- ),
544
- ).toEqual([
545
- {
546
- _key: 'b0',
547
- _type: 'block',
548
- children: [{_key: 's0', _type: 'span', text: 'world', marks: []}],
549
- markDefs: [],
550
- style: 'normal',
551
- _map: {},
552
- },
553
- ])
554
- })
555
-
556
- test('slicing span with custom props', () => {
557
- expect(
558
- getSelectedValue(
559
- createTestSnapshot({
560
- context: {
561
- schema,
562
- selection: {
563
- anchor: {
564
- path: [{_key: 'b0'}, 'children', {_key: 's0'}],
565
- offset: 7,
566
- },
567
- focus: {
568
- path: [{_key: 'b0'}, 'children', {_key: 's0'}],
569
- offset: 12,
570
- },
571
- },
572
- value: [
573
- {
574
- _key: 'b0',
575
- _type: 'block',
576
- children: [
577
- {
578
- _key: 's0',
579
- _type: 'span',
580
- text: 'Hello, world!',
581
- _map: {},
582
- marks: [],
583
- },
584
- ],
585
- markDefs: [],
586
- style: 'normal',
587
- },
588
- ],
589
- },
590
- }),
591
- ),
592
- ).toEqual([
593
- {
594
- _key: 'b0',
595
- _type: 'block',
596
- children: [
597
- {_key: 's0', _type: 'span', text: 'world', _map: {}, marks: []},
598
- ],
599
- markDefs: [],
600
- style: 'normal',
601
- },
602
- ])
603
- })
604
-
605
- test('filters out unused markDefs', () => {
606
- const keyGenerator = createTestKeyGenerator()
607
- const linkAKey = keyGenerator()
608
- const linkBKey = keyGenerator()
609
- const block0Key = keyGenerator()
610
- const bazKey = keyGenerator()
611
- const block4Key = keyGenerator()
612
- const oneMoreLineKey = keyGenerator()
613
- const value = [
614
- {
615
- _type: 'block',
616
- _key: block0Key,
617
- children: [
618
- {
619
- _type: 'span',
620
- _key: keyGenerator(),
621
- text: 'foo ',
622
- marks: [],
623
- },
624
- {
625
- _type: 'span',
626
- _key: keyGenerator(),
627
- text: 'bar',
628
- marks: [linkAKey],
629
- },
630
- {
631
- _type: 'span',
632
- _key: bazKey,
633
- text: ' baz',
634
- marks: [],
635
- },
636
- ],
637
- markDefs: [
638
- {
639
- _type: 'link',
640
- _key: linkAKey,
641
- href: 'https://example.com',
642
- },
643
- ],
644
- style: 'normal',
645
- },
646
- {
647
- _key: keyGenerator(),
648
- _type: 'image',
649
- },
650
- {
651
- _key: keyGenerator(),
652
- _type: 'block',
653
- children: [
654
- {
655
- _type: 'span',
656
- _key: keyGenerator(),
657
- text: 'fizz',
658
- marks: ['strong'],
659
- },
660
- {
661
- _type: 'span',
662
- _key: keyGenerator(),
663
- text: ' buzz',
664
- marks: [linkBKey],
665
- },
666
- ],
667
- markDefs: [
668
- {
669
- _type: 'link',
670
- _key: linkBKey,
671
- href: 'https://example.com',
672
- },
673
- ],
674
- style: 'normal',
675
- },
676
- {
677
- _key: keyGenerator(),
678
- _type: 'break',
679
- },
680
- {
681
- _key: block4Key,
682
- _type: 'block',
683
- children: [
684
- {
685
- _type: 'span',
686
- _key: oneMoreLineKey,
687
- text: 'one more line',
688
- },
689
- ],
690
- style: 'normal',
691
- markDefs: [],
692
- },
693
- ]
694
-
695
- const snapshot = createTestSnapshot({
696
- context: {
697
- value,
698
- keyGenerator,
699
- schema: compileSchema(
700
- defineSchema({
701
- annotations: [
702
- {name: 'link', fields: [{name: 'href', type: 'string'}]},
703
- ],
704
- decorators: [{name: 'strong'}],
705
- }),
706
- ),
707
- selection: {
708
- anchor: {
709
- path: [{_key: block0Key}, 'children', {_key: bazKey}],
710
- offset: 0,
711
- },
712
- focus: {
713
- path: [{_key: block4Key}, 'children', {_key: oneMoreLineKey}],
714
- offset: 3,
715
- },
716
- },
717
- },
718
- })
719
-
720
- expect(getSelectedValue(snapshot)).toEqual([
721
- {
722
- ...value[0],
723
- children: [
724
- {
725
- _type: 'span',
726
- _key: bazKey,
727
- text: ' baz',
728
- marks: [],
729
- },
730
- ],
731
- markDefs: [],
732
- },
733
- value[1],
734
- value[2],
735
- value[3],
736
- {
737
- ...value[4],
738
- children: [
739
- {
740
- _type: 'span',
741
- _key: oneMoreLineKey,
742
- text: 'one',
743
- marks: [],
744
- },
745
- ],
746
- },
747
- ])
748
- })
749
-
750
- test('starts and ends in different blocks with same span _key', () => {
751
- const keyGenerator = createTestKeyGenerator()
752
- const blockKey = keyGenerator()
753
- const spanAKey = keyGenerator()
754
- const spanBKey = keyGenerator()
755
- const spanCKey = keyGenerator()
756
- const blockBKey = keyGenerator()
757
- const value = [
758
- {
759
- _type: 'block',
760
- _key: blockKey,
761
- children: [
762
- {
763
- _type: 'span',
764
- _key: spanAKey,
765
- text: 'foo ',
766
- marks: [],
767
- },
768
- {
769
- _type: 'span',
770
- _key: spanBKey,
771
- text: 'bar',
772
- marks: ['strong'],
773
- },
774
- {
775
- _type: 'span',
776
- _key: spanCKey,
777
- text: ' baz',
778
- marks: [],
779
- },
780
- ],
781
- markDefs: [],
782
- style: 'normal',
783
- },
784
- {
785
- _type: 'block',
786
- _key: blockBKey,
787
- children: [
788
- {_type: 'span', _key: spanAKey, text: 'fizz buzz', marks: []},
789
- ],
790
- markDefs: [],
791
- style: 'normal',
792
- },
793
- ]
794
- const selection = {
795
- anchor: {
796
- path: [
797
- {
798
- _key: blockBKey,
799
- },
800
- 'children',
801
- {
802
- _key: spanAKey,
803
- },
804
- ],
805
- offset: 9,
806
- },
807
- focus: {
808
- path: [
809
- {
810
- _key: blockKey,
811
- },
812
- 'children',
813
- {
814
- _key: spanAKey,
815
- },
816
- ],
817
- offset: 0,
818
- },
819
- backward: true,
820
- }
821
-
822
- expect(
823
- getSelectedValue(
824
- createTestSnapshot({
825
- context: {
826
- schema,
827
- value,
828
- selection,
829
- },
830
- }),
831
- ),
832
- ).toEqual(value)
833
- })
834
- })