@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,139 +0,0 @@
1
- import {getFocusSpan} from '../selectors/selector.get-focus-span'
2
- import {isSelectionCollapsed} from '../selectors/selector.is-selection-collapsed'
3
- import {isSelectionExpanded} from '../selectors/selector.is-selection-expanded'
4
- import {abstractAnnotationBehaviors} from './behavior.abstract.annotation'
5
- import {abstractDecoratorBehaviors} from './behavior.abstract.decorator'
6
- import {abstractDeleteBehaviors} from './behavior.abstract.delete'
7
- import {abstractDeserializeBehaviors} from './behavior.abstract.deserialize'
8
- import {abstractInsertBehaviors} from './behavior.abstract.insert'
9
- import {abstractKeyboardBehaviors} from './behavior.abstract.keyboard'
10
- import {abstractListItemBehaviors} from './behavior.abstract.list-item'
11
- import {abstractMoveBehaviors} from './behavior.abstract.move'
12
- import {abstractSelectBehaviors} from './behavior.abstract.select'
13
- import {abstractSerializeBehaviors} from './behavior.abstract.serialize'
14
- import {abstractSplitBehaviors} from './behavior.abstract.split'
15
- import {abstractStyleBehaviors} from './behavior.abstract.style'
16
- import {raise} from './behavior.types.action'
17
- import {defineBehavior} from './behavior.types.behavior'
18
-
19
- export const abstractBehaviors = [
20
- defineBehavior({
21
- on: 'clipboard.copy',
22
- guard: ({snapshot}) => {
23
- const focusSpan = getFocusSpan(snapshot)
24
- const selectionCollapsed = isSelectionCollapsed(snapshot)
25
-
26
- return focusSpan && selectionCollapsed
27
- },
28
- actions: [],
29
- }),
30
- defineBehavior({
31
- on: 'clipboard.copy',
32
- actions: [
33
- ({event}) => [
34
- raise({
35
- type: 'serialize',
36
- originEvent: event,
37
- }),
38
- ],
39
- ],
40
- }),
41
- defineBehavior({
42
- on: 'clipboard.cut',
43
- guard: ({snapshot}) => {
44
- const focusSpan = getFocusSpan(snapshot)
45
- const selectionCollapsed = isSelectionCollapsed(snapshot)
46
-
47
- return focusSpan && selectionCollapsed
48
- },
49
- actions: [],
50
- }),
51
- defineBehavior({
52
- on: 'clipboard.cut',
53
- guard: ({snapshot}) => {
54
- return snapshot.context.selection
55
- ? {
56
- selection: snapshot.context.selection,
57
- }
58
- : false
59
- },
60
- actions: [
61
- ({event}, {selection}) => [
62
- raise({
63
- type: 'serialize',
64
- originEvent: event,
65
- }),
66
- raise({
67
- type: 'delete',
68
- at: selection,
69
- }),
70
- ],
71
- ],
72
- }),
73
- defineBehavior({
74
- on: 'drag.dragstart',
75
- actions: [
76
- ({event}) => [
77
- raise({
78
- type: 'serialize',
79
- originEvent: event,
80
- }),
81
- ],
82
- ],
83
- }),
84
-
85
- defineBehavior({
86
- on: 'clipboard.paste',
87
- guard: ({snapshot}) => {
88
- return snapshot.context.selection && isSelectionExpanded(snapshot)
89
- ? {selection: snapshot.context.selection}
90
- : false
91
- },
92
- actions: [
93
- ({event}, {selection}) => [
94
- raise({
95
- type: 'delete',
96
- at: selection,
97
- }),
98
- raise({
99
- type: 'deserialize',
100
- originEvent: event,
101
- }),
102
- ],
103
- ],
104
- }),
105
- defineBehavior({
106
- on: 'clipboard.paste',
107
- actions: [
108
- ({event}) => [
109
- raise({
110
- type: 'deserialize',
111
- originEvent: event,
112
- }),
113
- ],
114
- ],
115
- }),
116
- defineBehavior({
117
- on: 'input.*',
118
- actions: [
119
- ({event}) => [
120
- raise({
121
- type: 'deserialize',
122
- originEvent: event,
123
- }),
124
- ],
125
- ],
126
- }),
127
- ...abstractAnnotationBehaviors,
128
- ...abstractDecoratorBehaviors,
129
- ...abstractDeleteBehaviors,
130
- ...abstractDeserializeBehaviors,
131
- ...abstractInsertBehaviors,
132
- ...abstractKeyboardBehaviors,
133
- ...abstractListItemBehaviors,
134
- ...abstractMoveBehaviors,
135
- ...abstractStyleBehaviors,
136
- ...abstractSelectBehaviors,
137
- ...abstractSerializeBehaviors,
138
- ...abstractSplitBehaviors,
139
- ]
@@ -1,7 +0,0 @@
1
- import type {EditorPriority} from '../priority/priority.types'
2
- import type {Behavior} from './behavior.types.behavior'
3
-
4
- export type BehaviorConfig = {
5
- behavior: Behavior
6
- priority: EditorPriority
7
- }
@@ -1,62 +0,0 @@
1
- import {getCaretWordSelection} from '../selectors/selector.get-caret-word-selection'
2
- import {isActiveAnnotation} from '../selectors/selector.is-active-annotation'
3
- import {isSelectionCollapsed} from '../selectors/selector.is-selection-collapsed'
4
- import {isSelectionExpanded} from '../selectors/selector.is-selection-expanded'
5
- import {raise} from './behavior.types.action'
6
- import {defineBehavior} from './behavior.types.behavior'
7
-
8
- const addAnnotationOnCollapsedSelection = defineBehavior({
9
- on: 'annotation.add',
10
- guard: ({snapshot}) => {
11
- if (!isSelectionCollapsed(snapshot)) {
12
- return false
13
- }
14
-
15
- const caretWordSelection = getCaretWordSelection(snapshot)
16
-
17
- if (
18
- !caretWordSelection ||
19
- !isSelectionExpanded({
20
- ...snapshot,
21
- context: {
22
- ...snapshot.context,
23
- selection: caretWordSelection,
24
- },
25
- })
26
- ) {
27
- return false
28
- }
29
-
30
- return {caretWordSelection}
31
- },
32
- actions: [
33
- ({event}, {caretWordSelection}) => [
34
- raise({type: 'select', at: caretWordSelection}),
35
- raise({type: 'annotation.add', annotation: event.annotation}),
36
- ],
37
- ],
38
- })
39
-
40
- /**
41
- * By default, same-type annotations can overlap. This Core Behavior ensures
42
- * that annotations of the same type are mutually exclusive.
43
- */
44
- const preventOverlappingAnnotations = defineBehavior({
45
- // Given an `annotation.add` event
46
- on: 'annotation.add',
47
- // When the annotation is active in the selection
48
- guard: ({snapshot, event}) =>
49
- isActiveAnnotation(event.annotation.name, {mode: 'partial'})(snapshot),
50
- // Then the existing annotation is removed
51
- actions: [
52
- ({event}) => [
53
- raise({type: 'annotation.remove', annotation: event.annotation}),
54
- raise(event),
55
- ],
56
- ],
57
- })
58
-
59
- export const coreAnnotationBehaviors = [
60
- addAnnotationOnCollapsedSelection,
61
- preventOverlappingAnnotations,
62
- ]
@@ -1,116 +0,0 @@
1
- import type {EventPositionBlock} from '../internal-utils/event-position'
2
- import {corePriority} from '../priority/priority.core'
3
- import {createEditorPriority} from '../priority/priority.types'
4
- import {getDragSelection} from '../selectors/drag-selection'
5
- import {getFocusBlock} from '../selectors/selector.get-focus-block'
6
- import {getSelectedBlocks} from '../selectors/selector.get-selected-blocks'
7
- import {isSelectingEntireBlocks} from '../selectors/selector.is-selecting-entire-blocks'
8
- import {forward} from './behavior.types.action'
9
- import {defineBehavior} from './behavior.types.behavior'
10
-
11
- export function createCoreBlockElementBehaviorsConfig({
12
- key,
13
- onSetDragPositionBlock,
14
- }: {
15
- key: string
16
- onSetDragPositionBlock: (
17
- eventPositionBlock: EventPositionBlock | undefined,
18
- ) => void
19
- }) {
20
- return [
21
- {
22
- behavior: defineBehavior({
23
- on: 'drag.dragover',
24
- guard: ({snapshot, event}) => {
25
- const dropFocusBlock = getFocusBlock({
26
- ...snapshot,
27
- context: {
28
- ...snapshot.context,
29
- selection: event.position.selection,
30
- },
31
- })
32
-
33
- if (!dropFocusBlock || dropFocusBlock.node._key !== key) {
34
- return false
35
- }
36
-
37
- const dragOrigin = event.dragOrigin
38
-
39
- if (!dragOrigin) {
40
- return false
41
- }
42
-
43
- const dragSelection = getDragSelection({
44
- eventSelection: dragOrigin.selection,
45
- snapshot,
46
- })
47
-
48
- const draggedBlocks = getSelectedBlocks({
49
- ...snapshot,
50
- context: {
51
- ...snapshot.context,
52
- selection: dragSelection,
53
- },
54
- })
55
-
56
- if (
57
- draggedBlocks.some((draggedBlock) => draggedBlock.node._key === key)
58
- ) {
59
- return false
60
- }
61
-
62
- const draggingEntireBlocks = isSelectingEntireBlocks({
63
- ...snapshot,
64
- context: {
65
- ...snapshot.context,
66
- selection: dragSelection,
67
- },
68
- })
69
-
70
- return draggingEntireBlocks
71
- },
72
- actions: [
73
- ({event}) => [
74
- {
75
- type: 'effect',
76
- effect: () => {
77
- onSetDragPositionBlock(event.position.block)
78
- },
79
- },
80
- ],
81
- ],
82
- }),
83
- priority: createEditorPriority({
84
- reference: {
85
- priority: corePriority,
86
- importance: 'lower',
87
- },
88
- }),
89
- },
90
- {
91
- behavior: defineBehavior({
92
- on: 'drag.*',
93
- guard: ({event}) => {
94
- return event.type !== 'drag.dragover'
95
- },
96
- actions: [
97
- ({event}) => [
98
- {
99
- type: 'effect',
100
- effect: () => {
101
- onSetDragPositionBlock(undefined)
102
- },
103
- },
104
- forward(event),
105
- ],
106
- ],
107
- }),
108
- priority: createEditorPriority({
109
- reference: {
110
- priority: corePriority,
111
- importance: 'lower',
112
- },
113
- }),
114
- },
115
- ]
116
- }
@@ -1,285 +0,0 @@
1
- import {isTextBlock} from '@portabletext/schema'
2
- import {defaultKeyboardShortcuts} from '../keyboard-shortcuts/default-keyboard-shortcuts'
3
- import {getFocusBlockObject} from '../selectors/selector.get-focus-block-object'
4
- import {getFocusTextBlock} from '../selectors/selector.get-focus-text-block'
5
- import {getNextBlock} from '../selectors/selector.get-next-block'
6
- import {getPreviousBlock} from '../selectors/selector.get-previous-block'
7
- import {isSelectionCollapsed} from '../selectors/selector.is-selection-collapsed'
8
- import {isEmptyTextBlock} from '../utils/util.is-empty-text-block'
9
- import {raise} from './behavior.types.action'
10
- import {defineBehavior} from './behavior.types.behavior'
11
-
12
- const arrowDownOnLonelyBlockObject = defineBehavior({
13
- on: 'keyboard.keydown',
14
- guard: ({snapshot, event}) => {
15
- const isArrowDown = defaultKeyboardShortcuts.arrowDown.guard(
16
- event.originEvent,
17
- )
18
-
19
- if (!isArrowDown) {
20
- return false
21
- }
22
-
23
- const collapsedSelection = isSelectionCollapsed(snapshot)
24
-
25
- if (!collapsedSelection) {
26
- return false
27
- }
28
-
29
- const focusBlockObject = getFocusBlockObject(snapshot)
30
- const nextBlock = getNextBlock(snapshot)
31
-
32
- return focusBlockObject && !nextBlock
33
- },
34
- actions: [
35
- ({snapshot}) => [
36
- raise({
37
- type: 'insert.block',
38
- block: {
39
- _type: snapshot.context.schema.block.name,
40
- },
41
- placement: 'after',
42
- }),
43
- ],
44
- ],
45
- })
46
-
47
- const arrowUpOnLonelyBlockObject = defineBehavior({
48
- on: 'keyboard.keydown',
49
- guard: ({snapshot, event}) => {
50
- const isArrowUp = defaultKeyboardShortcuts.arrowUp.guard(event.originEvent)
51
-
52
- if (!isArrowUp) {
53
- return false
54
- }
55
-
56
- const collapsedSelection = isSelectionCollapsed(snapshot)
57
-
58
- if (!collapsedSelection) {
59
- return false
60
- }
61
-
62
- const focusBlockObject = getFocusBlockObject(snapshot)
63
- const previousBlock = getPreviousBlock(snapshot)
64
-
65
- return focusBlockObject && !previousBlock
66
- },
67
- actions: [
68
- ({snapshot}) => [
69
- raise({
70
- type: 'insert.block',
71
- block: {
72
- _type: snapshot.context.schema.block.name,
73
- },
74
- placement: 'before',
75
- }),
76
- ],
77
- ],
78
- })
79
-
80
- const breakingBlockObject = defineBehavior({
81
- on: 'insert.break',
82
- guard: ({snapshot}) => {
83
- const focusBlockObject = getFocusBlockObject(snapshot)
84
- const collapsedSelection = isSelectionCollapsed(snapshot)
85
-
86
- return collapsedSelection && focusBlockObject !== undefined
87
- },
88
- actions: [
89
- ({snapshot}) => [
90
- raise({
91
- type: 'insert.block',
92
- block: {
93
- _type: snapshot.context.schema.block.name,
94
- },
95
- placement: 'after',
96
- }),
97
- ],
98
- ],
99
- })
100
-
101
- const clickingAboveLonelyBlockObject = defineBehavior({
102
- on: 'mouse.click',
103
- guard: ({snapshot, event}) => {
104
- if (snapshot.context.readOnly) {
105
- return false
106
- }
107
-
108
- if (snapshot.context.selection && !isSelectionCollapsed(snapshot)) {
109
- return false
110
- }
111
-
112
- const focusBlockObject = getFocusBlockObject({
113
- ...snapshot,
114
- context: {
115
- ...snapshot.context,
116
- selection: event.position.selection,
117
- },
118
- })
119
- const previousBlock = getPreviousBlock({
120
- ...snapshot,
121
- context: {
122
- ...snapshot.context,
123
- selection: event.position.selection,
124
- },
125
- })
126
-
127
- return (
128
- event.position.isEditor &&
129
- event.position.block === 'start' &&
130
- focusBlockObject &&
131
- !previousBlock
132
- )
133
- },
134
- actions: [
135
- ({snapshot, event}) => [
136
- raise({
137
- type: 'select',
138
- at: event.position.selection,
139
- }),
140
- raise({
141
- type: 'insert.block',
142
- block: {
143
- _type: snapshot.context.schema.block.name,
144
- },
145
- placement: 'before',
146
- select: 'start',
147
- }),
148
- ],
149
- ],
150
- })
151
-
152
- const clickingBelowLonelyBlockObject = defineBehavior({
153
- on: 'mouse.click',
154
- guard: ({snapshot, event}) => {
155
- if (snapshot.context.readOnly) {
156
- return false
157
- }
158
-
159
- if (snapshot.context.selection && !isSelectionCollapsed(snapshot)) {
160
- return false
161
- }
162
-
163
- const focusBlockObject = getFocusBlockObject({
164
- ...snapshot,
165
- context: {
166
- ...snapshot.context,
167
- selection: event.position.selection,
168
- },
169
- })
170
- const nextBlock = getNextBlock({
171
- ...snapshot,
172
- context: {
173
- ...snapshot.context,
174
- selection: event.position.selection,
175
- },
176
- })
177
-
178
- return (
179
- event.position.isEditor &&
180
- event.position.block === 'end' &&
181
- focusBlockObject &&
182
- !nextBlock
183
- )
184
- },
185
- actions: [
186
- ({snapshot, event}) => [
187
- raise({
188
- type: 'select',
189
- at: event.position.selection,
190
- }),
191
- raise({
192
- type: 'insert.block',
193
- block: {
194
- _type: snapshot.context.schema.block.name,
195
- },
196
- placement: 'after',
197
- select: 'start',
198
- }),
199
- ],
200
- ],
201
- })
202
-
203
- const deletingEmptyTextBlockAfterBlockObject = defineBehavior({
204
- on: 'delete.backward',
205
- guard: ({snapshot}) => {
206
- const focusTextBlock = getFocusTextBlock(snapshot)
207
- const selectionCollapsed = isSelectionCollapsed(snapshot)
208
- const previousBlock = getPreviousBlock(snapshot)
209
-
210
- if (!focusTextBlock || !selectionCollapsed || !previousBlock) {
211
- return false
212
- }
213
-
214
- if (
215
- isEmptyTextBlock(snapshot.context, focusTextBlock.node) &&
216
- !isTextBlock(snapshot.context, previousBlock.node)
217
- ) {
218
- return {focusTextBlock, previousBlock}
219
- }
220
-
221
- return false
222
- },
223
- actions: [
224
- (_, {focusTextBlock, previousBlock}) => [
225
- raise({
226
- type: 'delete.block',
227
- at: focusTextBlock.path,
228
- }),
229
- raise({
230
- type: 'select',
231
- at: {
232
- anchor: {path: previousBlock.path, offset: 0},
233
- focus: {path: previousBlock.path, offset: 0},
234
- },
235
- }),
236
- ],
237
- ],
238
- })
239
-
240
- const deletingEmptyTextBlockBeforeBlockObject = defineBehavior({
241
- on: 'delete.forward',
242
- guard: ({snapshot}) => {
243
- const focusTextBlock = getFocusTextBlock(snapshot)
244
- const selectionCollapsed = isSelectionCollapsed(snapshot)
245
- const nextBlock = getNextBlock(snapshot)
246
-
247
- if (!focusTextBlock || !selectionCollapsed || !nextBlock) {
248
- return false
249
- }
250
-
251
- if (
252
- isEmptyTextBlock(snapshot.context, focusTextBlock.node) &&
253
- !isTextBlock(snapshot.context, nextBlock.node)
254
- ) {
255
- return {focusTextBlock, nextBlock}
256
- }
257
-
258
- return false
259
- },
260
- actions: [
261
- (_, {focusTextBlock, nextBlock}) => [
262
- raise({
263
- type: 'delete.block',
264
- at: focusTextBlock.path,
265
- }),
266
- raise({
267
- type: 'select',
268
- at: {
269
- anchor: {path: nextBlock.path, offset: 0},
270
- focus: {path: nextBlock.path, offset: 0},
271
- },
272
- }),
273
- ],
274
- ],
275
- })
276
-
277
- export const coreBlockObjectBehaviors = {
278
- arrowDownOnLonelyBlockObject,
279
- arrowUpOnLonelyBlockObject,
280
- breakingBlockObject,
281
- clickingAboveLonelyBlockObject,
282
- clickingBelowLonelyBlockObject,
283
- deletingEmptyTextBlockAfterBlockObject,
284
- deletingEmptyTextBlockBeforeBlockObject,
285
- }
@@ -1,44 +0,0 @@
1
- import {defaultKeyboardShortcuts} from '../keyboard-shortcuts/default-keyboard-shortcuts'
2
- import {raise} from './behavior.types.action'
3
- import {defineBehavior} from './behavior.types.behavior'
4
-
5
- export const coreDecoratorBehaviors = {
6
- strongShortcut: defineBehavior({
7
- on: 'keyboard.keydown',
8
- guard: ({snapshot, event}) =>
9
- defaultKeyboardShortcuts.decorators.strong.guard(event.originEvent) &&
10
- snapshot.context.schema.decorators.some(
11
- (decorator) => decorator.name === 'strong',
12
- ),
13
- actions: [() => [raise({type: 'decorator.toggle', decorator: 'strong'})]],
14
- }),
15
- emShortcut: defineBehavior({
16
- on: 'keyboard.keydown',
17
- guard: ({snapshot, event}) =>
18
- defaultKeyboardShortcuts.decorators.em.guard(event.originEvent) &&
19
- snapshot.context.schema.decorators.some(
20
- (decorator) => decorator.name === 'em',
21
- ),
22
- actions: [() => [raise({type: 'decorator.toggle', decorator: 'em'})]],
23
- }),
24
- underlineShortcut: defineBehavior({
25
- on: 'keyboard.keydown',
26
- guard: ({snapshot, event}) =>
27
- defaultKeyboardShortcuts.decorators.underline.guard(event.originEvent) &&
28
- snapshot.context.schema.decorators.some(
29
- (decorator) => decorator.name === 'underline',
30
- ),
31
- actions: [
32
- () => [raise({type: 'decorator.toggle', decorator: 'underline'})],
33
- ],
34
- }),
35
- codeShortcut: defineBehavior({
36
- on: 'keyboard.keydown',
37
- guard: ({snapshot, event}) =>
38
- defaultKeyboardShortcuts.decorators.code.guard(event.originEvent) &&
39
- snapshot.context.schema.decorators.some(
40
- (decorator) => decorator.name === 'code',
41
- ),
42
- actions: [() => [raise({type: 'decorator.toggle', decorator: 'code'})]],
43
- }),
44
- }