@portabletext/editor 3.3.2 → 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 (307) hide show
  1. package/lib/_chunks-dts/index.d.ts +7 -1
  2. package/package.json +16 -19
  3. package/src/behaviors/_exports/index.ts +0 -1
  4. package/src/behaviors/behavior.abstract.annotation.ts +0 -77
  5. package/src/behaviors/behavior.abstract.decorator.ts +0 -39
  6. package/src/behaviors/behavior.abstract.delete.ts +0 -273
  7. package/src/behaviors/behavior.abstract.deserialize.ts +0 -232
  8. package/src/behaviors/behavior.abstract.insert.ts +0 -525
  9. package/src/behaviors/behavior.abstract.keyboard.ts +0 -189
  10. package/src/behaviors/behavior.abstract.list-item.ts +0 -70
  11. package/src/behaviors/behavior.abstract.move.ts +0 -79
  12. package/src/behaviors/behavior.abstract.select.ts +0 -118
  13. package/src/behaviors/behavior.abstract.serialize.ts +0 -96
  14. package/src/behaviors/behavior.abstract.split.ts +0 -170
  15. package/src/behaviors/behavior.abstract.style.ts +0 -55
  16. package/src/behaviors/behavior.abstract.ts +0 -139
  17. package/src/behaviors/behavior.config.ts +0 -7
  18. package/src/behaviors/behavior.core.annotations.ts +0 -62
  19. package/src/behaviors/behavior.core.block-element.ts +0 -116
  20. package/src/behaviors/behavior.core.block-objects.ts +0 -285
  21. package/src/behaviors/behavior.core.decorators.ts +0 -44
  22. package/src/behaviors/behavior.core.dnd.ts +0 -356
  23. package/src/behaviors/behavior.core.insert-break.ts +0 -266
  24. package/src/behaviors/behavior.core.insert.ts +0 -52
  25. package/src/behaviors/behavior.core.lists.ts +0 -691
  26. package/src/behaviors/behavior.core.ts +0 -44
  27. package/src/behaviors/behavior.perform-event.ts +0 -354
  28. package/src/behaviors/behavior.types.action.ts +0 -102
  29. package/src/behaviors/behavior.types.behavior.ts +0 -83
  30. package/src/behaviors/behavior.types.event.ts +0 -667
  31. package/src/behaviors/behavior.types.guard.ts +0 -11
  32. package/src/behaviors/index.ts +0 -17
  33. package/src/converters/converter.json.ts +0 -53
  34. package/src/converters/converter.portable-text.deserialize.test.ts +0 -680
  35. package/src/converters/converter.portable-text.ts +0 -75
  36. package/src/converters/converter.text-html.deserialize.test.ts +0 -406
  37. package/src/converters/converter.text-html.serialize.test.ts +0 -246
  38. package/src/converters/converter.text-html.ts +0 -87
  39. package/src/converters/converter.text-markdown.ts +0 -67
  40. package/src/converters/converter.text-plain.test.ts +0 -245
  41. package/src/converters/converter.text-plain.ts +0 -126
  42. package/src/converters/converter.types.ts +0 -72
  43. package/src/converters/converters.core.ts +0 -18
  44. package/src/editor/Editable.tsx +0 -1012
  45. package/src/editor/PortableTextEditor.tsx +0 -791
  46. package/src/editor/components/drop-indicator.tsx +0 -17
  47. package/src/editor/components/render-block-object.tsx +0 -121
  48. package/src/editor/components/render-default-object.tsx +0 -21
  49. package/src/editor/components/render-element.tsx +0 -88
  50. package/src/editor/components/render-inline-object.tsx +0 -129
  51. package/src/editor/components/render-leaf.tsx +0 -64
  52. package/src/editor/components/render-span.tsx +0 -303
  53. package/src/editor/components/render-text-block.tsx +0 -265
  54. package/src/editor/components/render-text.tsx +0 -18
  55. package/src/editor/components/use-core-block-element-behaviors.ts +0 -39
  56. package/src/editor/create-editor.ts +0 -323
  57. package/src/editor/create-slate-editor.tsx +0 -64
  58. package/src/editor/editor-actor-context.ts +0 -4
  59. package/src/editor/editor-context.tsx +0 -7
  60. package/src/editor/editor-dom.ts +0 -220
  61. package/src/editor/editor-machine.ts +0 -751
  62. package/src/editor/editor-provider.tsx +0 -111
  63. package/src/editor/editor-schema.ts +0 -6
  64. package/src/editor/editor-selector.ts +0 -89
  65. package/src/editor/editor-snapshot.ts +0 -68
  66. package/src/editor/event-to-change.tsx +0 -49
  67. package/src/editor/hooks/usePortableTextEditor.ts +0 -25
  68. package/src/editor/hooks/usePortableTextEditorSelection.tsx +0 -28
  69. package/src/editor/mutation-machine.ts +0 -322
  70. package/src/editor/plugins/create-with-event-listeners.ts +0 -271
  71. package/src/editor/plugins/createWithEditableAPI.ts +0 -529
  72. package/src/editor/plugins/createWithHotKeys.ts +0 -68
  73. package/src/editor/plugins/createWithObjectKeys.ts +0 -289
  74. package/src/editor/plugins/createWithPatches.ts +0 -272
  75. package/src/editor/plugins/createWithPortableTextMarkModel.ts +0 -559
  76. package/src/editor/plugins/createWithSchemaTypes.ts +0 -121
  77. package/src/editor/plugins/slate-plugin.update-selection.ts +0 -51
  78. package/src/editor/plugins/slate-plugin.update-value.ts +0 -46
  79. package/src/editor/plugins/with-plugins.ts +0 -69
  80. package/src/editor/range-decorations-machine.ts +0 -421
  81. package/src/editor/relay-actor-context.ts +0 -4
  82. package/src/editor/relay-machine.ts +0 -152
  83. package/src/editor/sync-machine.ts +0 -961
  84. package/src/editor/use-editor.ts +0 -27
  85. package/src/editor/validate-selection-machine.test.ts +0 -47
  86. package/src/editor/validate-selection-machine.ts +0 -149
  87. package/src/editor/weakMaps.ts +0 -15
  88. package/src/editor/with-normalizing-node.ts +0 -14
  89. package/src/editor/with-performing-behavior-operation.ts +0 -21
  90. package/src/editor/withChanges.ts +0 -13
  91. package/src/editor/without-normalizing-conditional.ts +0 -13
  92. package/src/editor/withoutPatching.ts +0 -14
  93. package/src/editor.ts +0 -59
  94. package/src/history/behavior.operation.history.redo.ts +0 -67
  95. package/src/history/behavior.operation.history.undo.ts +0 -71
  96. package/src/history/event.history.undo.test.tsx +0 -672
  97. package/src/history/history.preserving-keys.test.tsx +0 -112
  98. package/src/history/remote-patches.ts +0 -20
  99. package/src/history/slate-plugin.history.ts +0 -142
  100. package/src/history/slate-plugin.redoing.ts +0 -21
  101. package/src/history/slate-plugin.undoing.ts +0 -21
  102. package/src/history/slate-plugin.without-history.ts +0 -23
  103. package/src/history/transform-operation.ts +0 -245
  104. package/src/history/undo-redo-collaboration.test.tsx +0 -541
  105. package/src/history/undo-redo.feature +0 -125
  106. package/src/history/undo-redo.test.tsx +0 -195
  107. package/src/history/undo-step.ts +0 -148
  108. package/src/index.ts +0 -98
  109. package/src/internal-utils/__tests__/ranges.test.ts +0 -23
  110. package/src/internal-utils/__tests__/values.test.ts +0 -110
  111. package/src/internal-utils/apply-operation-to-portable-text.test.ts +0 -1861
  112. package/src/internal-utils/apply-operation-to-portable-text.ts +0 -615
  113. package/src/internal-utils/applyPatch.ts +0 -644
  114. package/src/internal-utils/block-keys.ts +0 -9
  115. package/src/internal-utils/build-index-maps.test.ts +0 -464
  116. package/src/internal-utils/build-index-maps.ts +0 -131
  117. package/src/internal-utils/collapse-selection.ts +0 -36
  118. package/src/internal-utils/compound-client-rect.ts +0 -28
  119. package/src/internal-utils/create-placeholder-block.ts +0 -21
  120. package/src/internal-utils/create-test-snapshot.ts +0 -28
  121. package/src/internal-utils/debug.ts +0 -12
  122. package/src/internal-utils/editor-selection.test.ts +0 -44
  123. package/src/internal-utils/editor-selection.ts +0 -56
  124. package/src/internal-utils/event-position.ts +0 -318
  125. package/src/internal-utils/global-scope.ts +0 -27
  126. package/src/internal-utils/globally-scoped-context.ts +0 -39
  127. package/src/internal-utils/is-hotkey.test.ts +0 -114
  128. package/src/internal-utils/is-hotkey.ts +0 -209
  129. package/src/internal-utils/mime-type.ts +0 -1
  130. package/src/internal-utils/move-range-by-operation.ts +0 -19
  131. package/src/internal-utils/operation-to-patches.test.ts +0 -522
  132. package/src/internal-utils/operation-to-patches.ts +0 -571
  133. package/src/internal-utils/portable-text-node.ts +0 -209
  134. package/src/internal-utils/schema.ts +0 -8
  135. package/src/internal-utils/selection-block-keys.ts +0 -20
  136. package/src/internal-utils/selection-focus-text.ts +0 -40
  137. package/src/internal-utils/selection-text.test.ts +0 -32
  138. package/src/internal-utils/selection-text.ts +0 -21
  139. package/src/internal-utils/selection.ts +0 -77
  140. package/src/internal-utils/sibling-utils.ts +0 -55
  141. package/src/internal-utils/slate-utils.test.tsx +0 -121
  142. package/src/internal-utils/slate-utils.ts +0 -417
  143. package/src/internal-utils/split-string.ts +0 -12
  144. package/src/internal-utils/stop-actor.ts +0 -43
  145. package/src/internal-utils/string-overlap.test.ts +0 -14
  146. package/src/internal-utils/string-overlap.ts +0 -28
  147. package/src/internal-utils/string-utils.ts +0 -7
  148. package/src/internal-utils/text-block-key.test.ts +0 -41
  149. package/src/internal-utils/text-block-key.ts +0 -26
  150. package/src/internal-utils/text-marks.test.ts +0 -41
  151. package/src/internal-utils/text-marks.ts +0 -22
  152. package/src/internal-utils/text-selection.test.ts +0 -211
  153. package/src/internal-utils/text-selection.ts +0 -121
  154. package/src/internal-utils/to-slate-range.test.ts +0 -278
  155. package/src/internal-utils/to-slate-range.ts +0 -171
  156. package/src/internal-utils/validateValue.ts +0 -443
  157. package/src/internal-utils/value-annotations.ts +0 -33
  158. package/src/internal-utils/values.test.ts +0 -282
  159. package/src/internal-utils/values.ts +0 -266
  160. package/src/keyboard-shortcuts/default-keyboard-shortcuts.ts +0 -146
  161. package/src/operations/behavior.operation.annotation.add.ts +0 -99
  162. package/src/operations/behavior.operation.annotation.remove.ts +0 -150
  163. package/src/operations/behavior.operation.block.set.ts +0 -104
  164. package/src/operations/behavior.operation.block.unset.ts +0 -54
  165. package/src/operations/behavior.operation.child.set.ts +0 -107
  166. package/src/operations/behavior.operation.child.unset.ts +0 -116
  167. package/src/operations/behavior.operation.decorator.add.ts +0 -131
  168. package/src/operations/behavior.operation.delete.ts +0 -294
  169. package/src/operations/behavior.operation.insert.block.ts +0 -495
  170. package/src/operations/behavior.operation.insert.child.ts +0 -129
  171. package/src/operations/behavior.operation.insert.text.ts +0 -8
  172. package/src/operations/behavior.operation.move.backward.ts +0 -12
  173. package/src/operations/behavior.operation.move.block.ts +0 -44
  174. package/src/operations/behavior.operation.move.forward.ts +0 -11
  175. package/src/operations/behavior.operation.select.ts +0 -27
  176. package/src/operations/behavior.operations.ts +0 -221
  177. package/src/plugins/_exports/index.ts +0 -1
  178. package/src/plugins/index.ts +0 -3
  179. package/src/plugins/plugin.behavior.tsx +0 -24
  180. package/src/plugins/plugin.editor-ref.tsx +0 -17
  181. package/src/plugins/plugin.event-listener.tsx +0 -68
  182. package/src/plugins/plugin.internal.auto-close-brackets.test.tsx +0 -71
  183. package/src/plugins/plugin.internal.auto-close-brackets.ts +0 -62
  184. package/src/plugins/plugin.internal.change-ref.tsx +0 -19
  185. package/src/plugins/plugin.internal.portable-text-editor-ref.tsx +0 -16
  186. package/src/plugins/plugin.internal.slate-editor-ref.tsx +0 -15
  187. package/src/priority/priority.core.ts +0 -3
  188. package/src/priority/priority.sort.test.ts +0 -319
  189. package/src/priority/priority.sort.ts +0 -123
  190. package/src/priority/priority.types.ts +0 -24
  191. package/src/selectors/_exports/index.ts +0 -1
  192. package/src/selectors/drag-selection.test.ts +0 -578
  193. package/src/selectors/drag-selection.ts +0 -118
  194. package/src/selectors/index.ts +0 -54
  195. package/src/selectors/selector.get-active-annotation-marks.ts +0 -12
  196. package/src/selectors/selector.get-active-annotations.ts +0 -36
  197. package/src/selectors/selector.get-active-decorators.ts +0 -29
  198. package/src/selectors/selector.get-active-list-item.ts +0 -38
  199. package/src/selectors/selector.get-active-style.ts +0 -38
  200. package/src/selectors/selector.get-anchor-block.ts +0 -22
  201. package/src/selectors/selector.get-anchor-child.ts +0 -36
  202. package/src/selectors/selector.get-anchor-span.ts +0 -17
  203. package/src/selectors/selector.get-anchor-text-block.ts +0 -18
  204. package/src/selectors/selector.get-block-offsets.ts +0 -34
  205. package/src/selectors/selector.get-caret-word-selection.test.ts +0 -284
  206. package/src/selectors/selector.get-caret-word-selection.ts +0 -134
  207. package/src/selectors/selector.get-first-block.ts +0 -14
  208. package/src/selectors/selector.get-focus-block-object.ts +0 -18
  209. package/src/selectors/selector.get-focus-block.ts +0 -23
  210. package/src/selectors/selector.get-focus-child.ts +0 -36
  211. package/src/selectors/selector.get-focus-inline-object.ts +0 -17
  212. package/src/selectors/selector.get-focus-list-block.ts +0 -18
  213. package/src/selectors/selector.get-focus-span.ts +0 -18
  214. package/src/selectors/selector.get-focus-text-block.ts +0 -18
  215. package/src/selectors/selector.get-last-block.ts +0 -16
  216. package/src/selectors/selector.get-mark-state.test.ts +0 -325
  217. package/src/selectors/selector.get-mark-state.ts +0 -263
  218. package/src/selectors/selector.get-next-block.ts +0 -29
  219. package/src/selectors/selector.get-next-inline-object.ts +0 -53
  220. package/src/selectors/selector.get-next-inline-objects.ts +0 -50
  221. package/src/selectors/selector.get-next-span.ts +0 -56
  222. package/src/selectors/selector.get-previous-block.ts +0 -29
  223. package/src/selectors/selector.get-previous-inline-object.ts +0 -50
  224. package/src/selectors/selector.get-previous-inline-objects.ts +0 -47
  225. package/src/selectors/selector.get-previous-span.ts +0 -53
  226. package/src/selectors/selector.get-selected-blocks.ts +0 -61
  227. package/src/selectors/selector.get-selected-spans.test.ts +0 -347
  228. package/src/selectors/selector.get-selected-spans.ts +0 -155
  229. package/src/selectors/selector.get-selected-text-blocks.ts +0 -73
  230. package/src/selectors/selector.get-selected-value.test.ts +0 -834
  231. package/src/selectors/selector.get-selected-value.ts +0 -66
  232. package/src/selectors/selector.get-selection-end-block.ts +0 -33
  233. package/src/selectors/selector.get-selection-end-child.ts +0 -33
  234. package/src/selectors/selector.get-selection-end-point.ts +0 -17
  235. package/src/selectors/selector.get-selection-start-block.ts +0 -33
  236. package/src/selectors/selector.get-selection-start-child.ts +0 -33
  237. package/src/selectors/selector.get-selection-start-point.ts +0 -17
  238. package/src/selectors/selector.get-selection-text.test.ts +0 -421
  239. package/src/selectors/selector.get-selection-text.ts +0 -27
  240. package/src/selectors/selector.get-selection.ts +0 -9
  241. package/src/selectors/selector.get-text-after.ts +0 -46
  242. package/src/selectors/selector.get-text-before.ts +0 -46
  243. package/src/selectors/selector.get-value.ts +0 -11
  244. package/src/selectors/selector.is-active-annotation.test.ts +0 -320
  245. package/src/selectors/selector.is-active-annotation.ts +0 -52
  246. package/src/selectors/selector.is-active-decorator.test.ts +0 -136
  247. package/src/selectors/selector.is-active-decorator.ts +0 -24
  248. package/src/selectors/selector.is-active-list-item.ts +0 -13
  249. package/src/selectors/selector.is-active-style.ts +0 -13
  250. package/src/selectors/selector.is-at-the-end-of-block.ts +0 -30
  251. package/src/selectors/selector.is-at-the-start-of-block.ts +0 -30
  252. package/src/selectors/selector.is-overlapping-selection.test.ts +0 -304
  253. package/src/selectors/selector.is-overlapping-selection.ts +0 -181
  254. package/src/selectors/selector.is-point-after-selection.ts +0 -97
  255. package/src/selectors/selector.is-point-before-selection.ts +0 -97
  256. package/src/selectors/selector.is-selecting-entire-blocks.ts +0 -43
  257. package/src/selectors/selector.is-selection-collapsed.ts +0 -17
  258. package/src/selectors/selector.is-selection-expanded.test.ts +0 -63
  259. package/src/selectors/selector.is-selection-expanded.ts +0 -9
  260. package/src/test/_exports/index.ts +0 -1
  261. package/src/test/gherkin-parameter-types.ts +0 -112
  262. package/src/test/index.ts +0 -1
  263. package/src/test/vitest/_exports/index.ts +0 -1
  264. package/src/test/vitest/index.ts +0 -3
  265. package/src/test/vitest/step-context.ts +0 -13
  266. package/src/test/vitest/step-definitions.tsx +0 -960
  267. package/src/test/vitest/test-editor.tsx +0 -198
  268. package/src/type-utils.ts +0 -29
  269. package/src/types/block-offset.ts +0 -9
  270. package/src/types/block-with-optional-key.ts +0 -25
  271. package/src/types/editor.ts +0 -509
  272. package/src/types/options.ts +0 -13
  273. package/src/types/paths.ts +0 -35
  274. package/src/types/slate-editor.ts +0 -50
  275. package/src/types/slate.ts +0 -27
  276. package/src/utils/_exports/index.ts +0 -1
  277. package/src/utils/asserters.ts +0 -9
  278. package/src/utils/index.ts +0 -24
  279. package/src/utils/key-generator.ts +0 -33
  280. package/src/utils/parse-blocks.test.ts +0 -836
  281. package/src/utils/parse-blocks.ts +0 -504
  282. package/src/utils/util.at-the-beginning-of-block.ts +0 -32
  283. package/src/utils/util.block-offset-to-block-selection-point.ts +0 -28
  284. package/src/utils/util.block-offset-to-selection-point.ts +0 -33
  285. package/src/utils/util.block-offset.test.ts +0 -375
  286. package/src/utils/util.block-offset.ts +0 -136
  287. package/src/utils/util.block-offsets-to-selection.ts +0 -38
  288. package/src/utils/util.child-selection-point-to-block-offset.ts +0 -51
  289. package/src/utils/util.get-block-end-point.ts +0 -35
  290. package/src/utils/util.get-block-start-point.ts +0 -31
  291. package/src/utils/util.get-selection-end-point.ts +0 -20
  292. package/src/utils/util.get-selection-start-point.ts +0 -20
  293. package/src/utils/util.get-text-block-text.ts +0 -8
  294. package/src/utils/util.is-empty-text-block.ts +0 -21
  295. package/src/utils/util.is-equal-selection-points.ts +0 -13
  296. package/src/utils/util.is-equal-selections.ts +0 -20
  297. package/src/utils/util.is-keyed-segment.ts +0 -8
  298. package/src/utils/util.is-selection-collapsed.ts +0 -16
  299. package/src/utils/util.is-selection-expanded.ts +0 -13
  300. package/src/utils/util.merge-text-blocks.ts +0 -40
  301. package/src/utils/util.reverse-selection.ts +0 -26
  302. package/src/utils/util.selection-point-to-block-offset.ts +0 -30
  303. package/src/utils/util.selection-point.ts +0 -22
  304. package/src/utils/util.slice-blocks.ts +0 -221
  305. package/src/utils/util.slice-text-block.test.ts +0 -190
  306. package/src/utils/util.slice-text-block.ts +0 -89
  307. package/src/utils/util.split-text-block.ts +0 -54
@@ -1,578 +0,0 @@
1
- import {compileSchema, defineSchema} from '@portabletext/schema'
2
- import {createTestKeyGenerator} from '@portabletext/test'
3
- import {describe, expect, test} from 'vitest'
4
- import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
5
- import type {EditorSelection} from '../types/editor'
6
- import {getDragSelection} from './drag-selection'
7
-
8
- describe(getDragSelection.name, () => {
9
- const keyGenerator = createTestKeyGenerator()
10
- const foo = {
11
- _key: keyGenerator(),
12
- _type: 'block',
13
- children: [
14
- {
15
- _key: keyGenerator(),
16
- _type: 'span',
17
- text: 'foo',
18
- },
19
- {
20
- _key: keyGenerator(),
21
- _type: 'stock-ticker',
22
- },
23
- {
24
- _key: keyGenerator(),
25
- _type: 'span',
26
- text: 'bar',
27
- },
28
- ],
29
- }
30
- const fooPath = [{_key: foo._key}, 'children', {_key: foo.children[0]._key}]
31
- const stockTickerPath = [
32
- {_key: foo._key},
33
- 'children',
34
- {_key: foo.children[1]._key},
35
- ]
36
- const barPath = [{_key: foo._key}, 'children', {_key: foo.children[2]._key}]
37
- const baz = {
38
- _key: keyGenerator(),
39
- _type: 'block',
40
- children: [
41
- {
42
- _key: keyGenerator(),
43
- _type: 'span',
44
- text: 'baz',
45
- },
46
- ],
47
- }
48
- const bazPath = [{_key: baz._key}, 'children', {_key: baz.children[0]._key}]
49
- const image = {
50
- _key: keyGenerator(),
51
- _type: 'image',
52
- }
53
- const imagePath = [{_key: image._key}]
54
-
55
- function snapshot(selection: EditorSelection) {
56
- return createTestSnapshot({
57
- context: {
58
- keyGenerator,
59
- schema: compileSchema(defineSchema({blockObjects: [{name: 'image'}]})),
60
- selection,
61
- value: [foo, baz, image],
62
- },
63
- })
64
- }
65
-
66
- test('dragging one text block', () => {
67
- expect(
68
- getDragSelection({
69
- eventSelection: {
70
- anchor: {
71
- path: fooPath,
72
- offset: 0,
73
- },
74
- focus: {
75
- path: fooPath,
76
- offset: 0,
77
- },
78
- },
79
- snapshot: snapshot(null),
80
- }),
81
- ).toEqual({
82
- anchor: {
83
- path: fooPath,
84
- offset: 0,
85
- },
86
- focus: {
87
- path: barPath,
88
- offset: 3,
89
- },
90
- })
91
- })
92
-
93
- test('dragging one text block with an existing selection', () => {
94
- expect(
95
- getDragSelection({
96
- eventSelection: {
97
- anchor: {
98
- path: fooPath,
99
- offset: 0,
100
- },
101
- focus: {
102
- path: fooPath,
103
- offset: 0,
104
- },
105
- },
106
- snapshot: snapshot({
107
- anchor: {
108
- path: fooPath,
109
- offset: 0,
110
- },
111
- focus: {
112
- path: fooPath,
113
- offset: 3,
114
- },
115
- }),
116
- }),
117
- )
118
- })
119
-
120
- test('dragging one text block with a selection elsewhere', () => {
121
- expect(
122
- getDragSelection({
123
- eventSelection: {
124
- anchor: {
125
- path: fooPath,
126
- offset: 0,
127
- },
128
- focus: {
129
- path: fooPath,
130
- offset: 0,
131
- },
132
- },
133
- snapshot: snapshot({
134
- anchor: {
135
- path: imagePath,
136
- offset: 0,
137
- },
138
- focus: {
139
- path: imagePath,
140
- offset: 0,
141
- },
142
- }),
143
- }),
144
- ).toEqual({
145
- anchor: {
146
- path: fooPath,
147
- offset: 0,
148
- },
149
- focus: {
150
- path: barPath,
151
- offset: 3,
152
- },
153
- })
154
- })
155
-
156
- test('dragging one block object with a selection elsewhere', () => {
157
- expect(
158
- getDragSelection({
159
- eventSelection: {
160
- anchor: {
161
- path: imagePath,
162
- offset: 0,
163
- },
164
- focus: {
165
- path: imagePath,
166
- offset: 0,
167
- },
168
- },
169
- snapshot: snapshot({
170
- anchor: {
171
- path: fooPath,
172
- offset: 0,
173
- },
174
- focus: {
175
- path: fooPath,
176
- offset: 0,
177
- },
178
- }),
179
- }),
180
- ).toEqual({
181
- anchor: {
182
- path: imagePath,
183
- offset: 0,
184
- },
185
- focus: {
186
- path: imagePath,
187
- offset: 0,
188
- },
189
- })
190
- })
191
-
192
- test('dragging one block object with an expanded selection elsewhere', () => {
193
- expect(
194
- getDragSelection({
195
- eventSelection: {
196
- anchor: {
197
- path: imagePath,
198
- offset: 0,
199
- },
200
- focus: {
201
- path: imagePath,
202
- offset: 0,
203
- },
204
- },
205
- snapshot: snapshot({
206
- anchor: {
207
- path: fooPath,
208
- offset: 1,
209
- },
210
- focus: {
211
- path: fooPath,
212
- offset: 2,
213
- },
214
- }),
215
- }),
216
- ).toEqual({
217
- anchor: {
218
- path: imagePath,
219
- offset: 0,
220
- },
221
- focus: {
222
- path: imagePath,
223
- offset: 0,
224
- },
225
- })
226
- })
227
-
228
- test('dragging a text block with an expanded selected', () => {
229
- expect(
230
- getDragSelection({
231
- eventSelection: {
232
- anchor: {
233
- path: fooPath,
234
- offset: 0,
235
- },
236
- focus: {
237
- path: fooPath,
238
- offset: 0,
239
- },
240
- },
241
- snapshot: snapshot({
242
- anchor: {
243
- path: fooPath,
244
- offset: 0,
245
- },
246
- focus: {
247
- path: imagePath,
248
- offset: 0,
249
- },
250
- }),
251
- }),
252
- ).toEqual({
253
- anchor: {
254
- path: fooPath,
255
- offset: 0,
256
- },
257
- focus: {
258
- path: imagePath,
259
- offset: 0,
260
- },
261
- })
262
- })
263
-
264
- test('dragging two text blocks with the top drag handle', () => {
265
- expect(
266
- getDragSelection({
267
- eventSelection: {
268
- anchor: {
269
- path: fooPath,
270
- offset: 0,
271
- },
272
- focus: {
273
- path: fooPath,
274
- offset: 0,
275
- },
276
- },
277
- snapshot: snapshot({
278
- anchor: {
279
- path: fooPath,
280
- offset: 1,
281
- },
282
- focus: {
283
- path: bazPath,
284
- offset: 3,
285
- },
286
- }),
287
- }),
288
- ).toEqual({
289
- anchor: {
290
- path: fooPath,
291
- offset: 0,
292
- },
293
- focus: {
294
- path: bazPath,
295
- offset: 3,
296
- },
297
- })
298
- })
299
-
300
- test('dragging two text blocks with the bottom drag handle', () => {
301
- expect(
302
- getDragSelection({
303
- eventSelection: {
304
- anchor: {
305
- path: bazPath,
306
- offset: 0,
307
- },
308
- focus: {
309
- path: bazPath,
310
- offset: 0,
311
- },
312
- },
313
- snapshot: snapshot({
314
- anchor: {
315
- path: fooPath,
316
- offset: 1,
317
- },
318
- focus: {
319
- path: bazPath,
320
- offset: 3,
321
- },
322
- }),
323
- }),
324
- ).toEqual({
325
- anchor: {
326
- path: fooPath,
327
- offset: 0,
328
- },
329
- focus: {
330
- path: bazPath,
331
- offset: 3,
332
- },
333
- })
334
- })
335
-
336
- test('dragging a block object with an expanded selected', () => {
337
- expect(
338
- getDragSelection({
339
- eventSelection: {
340
- anchor: {
341
- path: imagePath,
342
- offset: 0,
343
- },
344
- focus: {
345
- path: imagePath,
346
- offset: 0,
347
- },
348
- },
349
- snapshot: snapshot({
350
- anchor: {
351
- path: fooPath,
352
- offset: 0,
353
- },
354
- focus: {
355
- path: imagePath,
356
- offset: 0,
357
- },
358
- }),
359
- }),
360
- ).toEqual({
361
- anchor: {
362
- path: fooPath,
363
- offset: 0,
364
- },
365
- focus: {
366
- path: imagePath,
367
- offset: 0,
368
- },
369
- })
370
- })
371
-
372
- test('dragging inline object', () => {
373
- expect(
374
- getDragSelection({
375
- eventSelection: {
376
- anchor: {
377
- path: stockTickerPath,
378
- offset: 0,
379
- },
380
- focus: {
381
- path: stockTickerPath,
382
- offset: 0,
383
- },
384
- },
385
- snapshot: snapshot(null),
386
- }),
387
- ).toEqual({
388
- anchor: {
389
- path: stockTickerPath,
390
- offset: 0,
391
- },
392
- focus: {
393
- path: stockTickerPath,
394
- offset: 0,
395
- },
396
- })
397
- })
398
-
399
- test('dragging inline object already selected', () => {
400
- expect(
401
- getDragSelection({
402
- eventSelection: {
403
- anchor: {
404
- path: stockTickerPath,
405
- offset: 0,
406
- },
407
- focus: {
408
- path: stockTickerPath,
409
- offset: 0,
410
- },
411
- },
412
- snapshot: snapshot({
413
- anchor: {
414
- path: stockTickerPath,
415
- offset: 0,
416
- },
417
- focus: {
418
- path: stockTickerPath,
419
- offset: 0,
420
- },
421
- }),
422
- }),
423
- ).toEqual({
424
- anchor: {
425
- path: stockTickerPath,
426
- offset: 0,
427
- },
428
- focus: {
429
- path: stockTickerPath,
430
- offset: 0,
431
- },
432
- })
433
- })
434
-
435
- test('dragging inline object with selection elsewhere', () => {
436
- expect(
437
- getDragSelection({
438
- eventSelection: {
439
- anchor: {
440
- path: stockTickerPath,
441
- offset: 0,
442
- },
443
- focus: {
444
- path: stockTickerPath,
445
- offset: 0,
446
- },
447
- },
448
- snapshot: snapshot({
449
- anchor: {
450
- path: fooPath,
451
- offset: 0,
452
- },
453
- focus: {
454
- path: fooPath,
455
- offset: 0,
456
- },
457
- }),
458
- }),
459
- ).toEqual({
460
- anchor: {
461
- path: stockTickerPath,
462
- offset: 0,
463
- },
464
- focus: {
465
- path: stockTickerPath,
466
- offset: 0,
467
- },
468
- })
469
- })
470
-
471
- test('dragging inline object with expanded selection elsewhere', () => {
472
- expect(
473
- getDragSelection({
474
- eventSelection: {
475
- anchor: {
476
- path: stockTickerPath,
477
- offset: 0,
478
- },
479
- focus: {
480
- path: stockTickerPath,
481
- offset: 0,
482
- },
483
- },
484
- snapshot: snapshot({
485
- anchor: {
486
- path: fooPath,
487
- offset: 0,
488
- },
489
- focus: {
490
- path: fooPath,
491
- offset: 3,
492
- },
493
- }),
494
- }),
495
- ).toEqual({
496
- anchor: {
497
- path: stockTickerPath,
498
- offset: 0,
499
- },
500
- focus: {
501
- path: stockTickerPath,
502
- offset: 0,
503
- },
504
- })
505
- })
506
-
507
- test('dragging inline object in an expanded selection', () => {
508
- expect(
509
- getDragSelection({
510
- eventSelection: {
511
- anchor: {
512
- path: stockTickerPath,
513
- offset: 0,
514
- },
515
- focus: {
516
- path: stockTickerPath,
517
- offset: 0,
518
- },
519
- },
520
- snapshot: snapshot({
521
- anchor: {
522
- path: fooPath,
523
- offset: 2,
524
- },
525
- focus: {
526
- path: bazPath,
527
- offset: 2,
528
- },
529
- }),
530
- }),
531
- ).toEqual({
532
- anchor: {
533
- path: stockTickerPath,
534
- offset: 0,
535
- },
536
- focus: {
537
- path: stockTickerPath,
538
- offset: 0,
539
- },
540
- })
541
- })
542
-
543
- test('dragging text block with inline object selected', () => {
544
- expect(
545
- getDragSelection({
546
- eventSelection: {
547
- anchor: {
548
- path: fooPath,
549
- offset: 0,
550
- },
551
- focus: {
552
- path: fooPath,
553
- offset: 0,
554
- },
555
- },
556
- snapshot: snapshot({
557
- anchor: {
558
- path: stockTickerPath,
559
- offset: 0,
560
- },
561
- focus: {
562
- path: stockTickerPath,
563
- offset: 0,
564
- },
565
- }),
566
- }),
567
- ).toEqual({
568
- anchor: {
569
- path: fooPath,
570
- offset: 0,
571
- },
572
- focus: {
573
- path: barPath,
574
- offset: 3,
575
- },
576
- })
577
- })
578
- })
@@ -1,118 +0,0 @@
1
- import type {EditorSnapshot} from '../editor/editor-snapshot'
2
- import type {EventPosition} from '../internal-utils/event-position'
3
- import {getBlockEndPoint} from '../utils/util.get-block-end-point'
4
- import {getBlockStartPoint} from '../utils/util.get-block-start-point'
5
- import {getFocusInlineObject} from './selector.get-focus-inline-object'
6
- import {getFocusSpan} from './selector.get-focus-span'
7
- import {getFocusTextBlock} from './selector.get-focus-text-block'
8
- import {getSelectedBlocks} from './selector.get-selected-blocks'
9
- import {getSelectionEndBlock} from './selector.get-selection-end-block'
10
- import {getSelectionStartBlock} from './selector.get-selection-start-block'
11
- import {isOverlappingSelection} from './selector.is-overlapping-selection'
12
- import {isSelectionCollapsed} from './selector.is-selection-collapsed'
13
- import {isSelectionExpanded} from './selector.is-selection-expanded'
14
-
15
- /**
16
- * Given the current editor `snapshot` and an `eventSelection` representing
17
- * where the drag event origins from, this function calculates the selection
18
- * in the editor that should be dragged.
19
- */
20
- export function getDragSelection({
21
- eventSelection,
22
- snapshot,
23
- }: {
24
- eventSelection: EventPosition['selection']
25
- snapshot: EditorSnapshot
26
- }) {
27
- let dragSelection = eventSelection
28
-
29
- const draggedInlineObject = getFocusInlineObject({
30
- ...snapshot,
31
- context: {
32
- ...snapshot.context,
33
- selection: eventSelection,
34
- },
35
- })
36
-
37
- if (draggedInlineObject) {
38
- return dragSelection
39
- }
40
-
41
- const draggingCollapsedSelection = isSelectionCollapsed({
42
- ...snapshot,
43
- context: {
44
- ...snapshot.context,
45
- selection: eventSelection,
46
- },
47
- })
48
- const draggedTextBlock = getFocusTextBlock({
49
- ...snapshot,
50
- context: {
51
- ...snapshot.context,
52
- selection: eventSelection,
53
- },
54
- })
55
- const draggedSpan = getFocusSpan({
56
- ...snapshot,
57
- context: {
58
- ...snapshot.context,
59
- selection: eventSelection,
60
- },
61
- })
62
-
63
- if (draggingCollapsedSelection && draggedTextBlock && draggedSpan) {
64
- // Looks like we are dragging an empty span
65
- // Let's drag the entire block instead
66
- dragSelection = {
67
- anchor: getBlockStartPoint({
68
- context: snapshot.context,
69
- block: draggedTextBlock,
70
- }),
71
- focus: getBlockEndPoint({
72
- context: snapshot.context,
73
- block: draggedTextBlock,
74
- }),
75
- }
76
- }
77
-
78
- const selectedBlocks = getSelectedBlocks(snapshot)
79
-
80
- if (
81
- snapshot.context.selection &&
82
- isSelectionExpanded(snapshot) &&
83
- selectedBlocks.length > 1
84
- ) {
85
- const selectionStartBlock = getSelectionStartBlock(snapshot)
86
- const selectionEndBlock = getSelectionEndBlock(snapshot)
87
-
88
- if (!selectionStartBlock || !selectionEndBlock) {
89
- return dragSelection
90
- }
91
-
92
- const selectionStartPoint = getBlockStartPoint({
93
- context: snapshot.context,
94
- block: selectionStartBlock,
95
- })
96
- const selectionEndPoint = getBlockEndPoint({
97
- context: snapshot.context,
98
- block: selectionEndBlock,
99
- })
100
-
101
- const eventSelectionInsideBlocks = isOverlappingSelection(eventSelection)({
102
- ...snapshot,
103
- context: {
104
- ...snapshot.context,
105
- selection: {anchor: selectionStartPoint, focus: selectionEndPoint},
106
- },
107
- })
108
-
109
- if (eventSelectionInsideBlocks) {
110
- dragSelection = {
111
- anchor: selectionStartPoint,
112
- focus: selectionEndPoint,
113
- }
114
- }
115
- }
116
-
117
- return dragSelection
118
- }