@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,195 +0,0 @@
1
- import {Before} from 'racejar'
2
- import {Feature} from 'racejar/vitest'
3
- import {defineSchema} from '..'
4
- import {defineBehavior, forward, raise} from '../behaviors'
5
- import {BehaviorPlugin} from '../plugins/plugin.behavior'
6
- import {getFocusTextBlock, isSelectionExpanded} from '../selectors'
7
- import {parameterTypes} from '../test'
8
- import {createTestEditor, stepDefinitions, type Context} from '../test/vitest'
9
- import undoRedoFeature from './undo-redo.feature?raw'
10
-
11
- Feature({
12
- featureText: undoRedoFeature,
13
- stepDefinitions,
14
- parameterTypes,
15
- hooks: [
16
- Before(async (context: Context) => {
17
- const {editor, locator} = await createTestEditor({
18
- schemaDefinition: defineSchema({
19
- annotations: [{name: 'link'}, {name: 'comment'}],
20
- }),
21
- children: (
22
- <>
23
- <ArrowTransformPlugin />
24
- <CopyrightTransformPlugin />
25
- </>
26
- ),
27
- })
28
-
29
- context.locator = locator
30
- context.editor = editor
31
- }),
32
- ],
33
- })
34
-
35
- /**
36
- * Native behavior to transform `>` into `→`.
37
- * Ony for testing purposes.
38
- */
39
- function ArrowTransformPlugin() {
40
- return (
41
- <BehaviorPlugin
42
- behaviors={[
43
- defineBehavior({
44
- on: 'insert.text',
45
- guard: ({snapshot, event}) => {
46
- if (event.text !== '>' || isSelectionExpanded(snapshot)) {
47
- return false
48
- }
49
-
50
- const focusTextBlock = getFocusTextBlock(snapshot)
51
-
52
- if (!focusTextBlock) {
53
- return false
54
- }
55
-
56
- return {focusTextBlock}
57
- },
58
- actions: [
59
- ({event}) => [forward(event)],
60
- ({snapshot}, {focusTextBlock}) => [
61
- raise({
62
- type: 'select',
63
- at: {
64
- anchor: {
65
- path: focusTextBlock.path,
66
- offset: 0,
67
- },
68
- focus: {
69
- path: focusTextBlock.path,
70
- offset: 2,
71
- },
72
- },
73
- }),
74
- raise({
75
- type: 'delete',
76
- at: {
77
- anchor: {
78
- path: focusTextBlock.path,
79
- offset: 0,
80
- },
81
- focus: {
82
- path: focusTextBlock.path,
83
- offset: 2,
84
- },
85
- },
86
- }),
87
- raise({
88
- type: 'insert.child',
89
- child: {
90
- _type: snapshot.context.schema.span.name,
91
- text: '→',
92
- marks: [],
93
- },
94
- }),
95
- raise({
96
- type: 'select',
97
- at: {
98
- anchor: {
99
- path: focusTextBlock.path,
100
- offset: 2,
101
- },
102
- focus: {
103
- path: focusTextBlock.path,
104
- offset: 2,
105
- },
106
- },
107
- }),
108
- ],
109
- ],
110
- }),
111
- ]}
112
- />
113
- )
114
- }
115
-
116
- /**
117
- * Native behavior to transform `(c)` into `©`.
118
- * Ony for testing purposes.
119
- */
120
- function CopyrightTransformPlugin() {
121
- return (
122
- <BehaviorPlugin
123
- behaviors={[
124
- defineBehavior({
125
- on: 'insert.text',
126
- guard: ({snapshot, event}) => {
127
- if (event.text !== ')' || isSelectionExpanded(snapshot)) {
128
- return false
129
- }
130
-
131
- const focusTextBlock = getFocusTextBlock(snapshot)
132
-
133
- if (!focusTextBlock) {
134
- return false
135
- }
136
-
137
- return {focusTextBlock}
138
- },
139
- actions: [
140
- ({event}) => [forward(event)],
141
- ({snapshot}, {focusTextBlock}) => [
142
- raise({
143
- type: 'select',
144
- at: {
145
- anchor: {
146
- path: focusTextBlock.path,
147
- offset: 0,
148
- },
149
- focus: {
150
- path: focusTextBlock.path,
151
- offset: 3,
152
- },
153
- },
154
- }),
155
- raise({
156
- type: 'delete',
157
- at: {
158
- anchor: {
159
- path: focusTextBlock.path,
160
- offset: 0,
161
- },
162
- focus: {
163
- path: focusTextBlock.path,
164
- offset: 3,
165
- },
166
- },
167
- }),
168
- raise({
169
- type: 'insert.child',
170
- child: {
171
- _type: snapshot.context.schema.span.name,
172
- text: '©',
173
- marks: [],
174
- },
175
- }),
176
- raise({
177
- type: 'select',
178
- at: {
179
- anchor: {
180
- path: focusTextBlock.path,
181
- offset: 3,
182
- },
183
- focus: {
184
- path: focusTextBlock.path,
185
- offset: 3,
186
- },
187
- },
188
- }),
189
- ],
190
- ],
191
- }),
192
- ]}
193
- />
194
- )
195
- }
@@ -1,148 +0,0 @@
1
- import {Path, type Editor, type Operation} from 'slate'
2
- import {isNormalizingNode} from '../editor/with-normalizing-node'
3
- import {defaultKeyGenerator} from '../utils/key-generator'
4
-
5
- const CURRENT_UNDO_STEP_ID: WeakMap<Editor, {undoStepId: string} | undefined> =
6
- new WeakMap()
7
-
8
- export function getCurrentUndoStepId(editor: Editor) {
9
- return CURRENT_UNDO_STEP_ID.get(editor)?.undoStepId
10
- }
11
-
12
- export function createUndoStepId(editor: Editor) {
13
- CURRENT_UNDO_STEP_ID.set(editor, {
14
- undoStepId: defaultKeyGenerator(),
15
- })
16
- }
17
-
18
- export function clearUndoStepId(editor: Editor) {
19
- CURRENT_UNDO_STEP_ID.set(editor, undefined)
20
- }
21
-
22
- type UndoStep = {
23
- operations: Array<Operation>
24
- timestamp: Date
25
- }
26
-
27
- export function createUndoSteps({
28
- steps,
29
- op,
30
- editor,
31
- currentUndoStepId,
32
- previousUndoStepId,
33
- }: {
34
- steps: Array<UndoStep>
35
- op: Operation
36
- editor: Editor
37
- currentUndoStepId: string | undefined
38
- previousUndoStepId: string | undefined
39
- }): Array<UndoStep> {
40
- const lastStep = steps.at(-1)
41
-
42
- if (!lastStep) {
43
- return createNewStep(steps, op, editor)
44
- }
45
-
46
- if (editor.operations.length > 0) {
47
- // The editor has operations in progress
48
-
49
- if (currentUndoStepId === previousUndoStepId || isNormalizingNode(editor)) {
50
- return mergeIntoLastStep(steps, lastStep, op)
51
- }
52
-
53
- return createNewStep(steps, op, editor)
54
- }
55
-
56
- if (
57
- op.type === 'set_selection' &&
58
- currentUndoStepId === undefined &&
59
- previousUndoStepId !== undefined
60
- ) {
61
- // Selecting without undo step ID
62
- return mergeIntoLastStep(steps, lastStep, op)
63
- }
64
-
65
- if (
66
- op.type === 'set_selection' &&
67
- currentUndoStepId !== undefined &&
68
- previousUndoStepId !== undefined &&
69
- previousUndoStepId !== currentUndoStepId
70
- ) {
71
- // Selecting with different undo step ID
72
- return mergeIntoLastStep(steps, lastStep, op)
73
- }
74
-
75
- // Handle case when both IDs are undefined
76
- if (currentUndoStepId === undefined && previousUndoStepId === undefined) {
77
- if (op.type === 'set_selection') {
78
- return mergeIntoLastStep(steps, lastStep, op)
79
- }
80
-
81
- const lastOp = lastStep.operations.at(-1)
82
-
83
- if (
84
- lastOp &&
85
- op.type === 'insert_text' &&
86
- lastOp.type === 'insert_text' &&
87
- op.offset === lastOp.offset + lastOp.text.length &&
88
- Path.equals(op.path, lastOp.path) &&
89
- op.text !== ' '
90
- ) {
91
- return mergeIntoLastStep(steps, lastStep, op)
92
- }
93
-
94
- if (
95
- lastOp &&
96
- op.type === 'remove_text' &&
97
- lastOp.type === 'remove_text' &&
98
- op.offset + op.text.length === lastOp.offset &&
99
- Path.equals(op.path, lastOp.path)
100
- ) {
101
- return mergeIntoLastStep(steps, lastStep, op)
102
- }
103
-
104
- return createNewStep(steps, op, editor)
105
- }
106
-
107
- return createNewStep(steps, op, editor)
108
- }
109
-
110
- function createNewStep(
111
- steps: Array<UndoStep>,
112
- op: Operation,
113
- editor: Editor,
114
- ): Array<UndoStep> {
115
- const operations =
116
- editor.selection === null
117
- ? [op]
118
- : [
119
- {
120
- type: 'set_selection' as const,
121
- properties: {...editor.selection},
122
- newProperties: {...editor.selection},
123
- },
124
- op,
125
- ]
126
-
127
- return [
128
- ...steps,
129
- {
130
- operations,
131
- timestamp: new Date(),
132
- },
133
- ]
134
- }
135
-
136
- function mergeIntoLastStep(
137
- steps: Array<UndoStep>,
138
- lastStep: UndoStep,
139
- op: Operation,
140
- ): Array<UndoStep> {
141
- return [
142
- ...steps.slice(0, -1),
143
- {
144
- timestamp: lastStep.timestamp,
145
- operations: [...lastStep.operations, op],
146
- },
147
- ]
148
- }
package/src/index.ts DELETED
@@ -1,98 +0,0 @@
1
- export type {Patch} from '@portabletext/patches'
2
- export type {
3
- PortableTextBlock,
4
- PortableTextTextBlock,
5
- PortableTextChild,
6
- PortableTextObject,
7
- PortableTextSpan,
8
- } from '@sanity/types'
9
- export type {Editor, EditorConfig, EditorEvent} from './editor'
10
- export {PortableTextEditable} from './editor/Editable'
11
- export type {PortableTextEditableProps} from './editor/Editable'
12
- export type {PatchesEvent} from './editor/editor-machine'
13
- export {
14
- EditorProvider,
15
- type EditorProviderProps,
16
- } from './editor/editor-provider'
17
- export type {
18
- AnnotationSchemaType,
19
- BlockObjectSchemaType,
20
- DecoratorSchemaType,
21
- InlineObjectSchemaType,
22
- ListSchemaType,
23
- StyleSchemaType,
24
- } from '@portabletext/schema'
25
- export type {EditorSchema} from './editor/editor-schema'
26
- export {
27
- defineSchema,
28
- type AnnotationDefinition,
29
- type BaseDefinition,
30
- type BlockObjectDefinition,
31
- type DecoratorDefinition,
32
- type FieldDefinition,
33
- type InlineObjectDefinition,
34
- type ListDefinition,
35
- type SchemaDefinition,
36
- type StyleDefinition,
37
- } from '@portabletext/schema'
38
- export {useEditorSelector, type EditorSelector} from './editor/editor-selector'
39
- export type {EditorContext, EditorSnapshot} from './editor/editor-snapshot'
40
- export {usePortableTextEditor} from './editor/hooks/usePortableTextEditor'
41
- export {usePortableTextEditorSelection} from './editor/hooks/usePortableTextEditorSelection'
42
- export {defaultKeyGenerator as keyGenerator} from './utils/key-generator'
43
- export {PortableTextEditor} from './editor/PortableTextEditor'
44
- export type {PortableTextEditorProps} from './editor/PortableTextEditor'
45
- export type {EditorEmittedEvent, MutationEvent} from './editor/relay-machine'
46
- export {useEditor} from './editor/use-editor'
47
- export type {AddedAnnotationPaths} from './types/editor'
48
- export type {BlockOffset} from './types/block-offset'
49
- export type {
50
- BlockAnnotationRenderProps,
51
- BlockChildRenderProps,
52
- BlockDecoratorRenderProps,
53
- BlockListItemRenderProps,
54
- BlockRenderProps,
55
- BlockStyleRenderProps,
56
- BlurChange,
57
- ConnectionChange,
58
- EditableAPI,
59
- EditableAPIDeleteOptions,
60
- EditorChange,
61
- EditorChanges,
62
- EditorSelection,
63
- EditorSelectionPoint,
64
- ErrorChange,
65
- FocusChange,
66
- InvalidValue,
67
- InvalidValueResolution,
68
- LoadingChange,
69
- MutationChange,
70
- OnBeforeInputFn,
71
- OnCopyFn,
72
- OnPasteFn,
73
- OnPasteResult,
74
- OnPasteResultOrPromise,
75
- PasteData,
76
- PatchChange,
77
- PatchObservable,
78
- PortableTextMemberSchemaTypes,
79
- RangeDecoration,
80
- RangeDecorationOnMovedDetails,
81
- ReadyChange,
82
- RedoChange,
83
- RenderAnnotationFunction,
84
- RenderBlockFunction,
85
- RenderChildFunction,
86
- RenderDecoratorFunction,
87
- RenderEditableFunction,
88
- RenderListItemFunction,
89
- RenderPlaceholderFunction,
90
- RenderStyleFunction,
91
- ScrollSelectionIntoViewFunction,
92
- SelectionChange,
93
- UndoChange,
94
- UnsetChange,
95
- ValueChange,
96
- } from './types/editor'
97
- export type {HotkeyOptions} from './types/options'
98
- export type {AnnotationPath, BlockPath, ChildPath} from './types/paths'
@@ -1,23 +0,0 @@
1
- import type {InsertTextOperation, Range} from 'slate'
2
- import {describe, expect, it} from 'vitest'
3
- import {moveRangeByOperation} from '../move-range-by-operation'
4
-
5
- describe('moveRangeByOperation', () => {
6
- it('should move range when inserting text in front of it', () => {
7
- const range: Range = {
8
- anchor: {path: [0, 0], offset: 1},
9
- focus: {path: [0, 0], offset: 3},
10
- }
11
- const operation: InsertTextOperation = {
12
- type: 'insert_text',
13
- path: [0, 0],
14
- offset: 0,
15
- text: 'foo',
16
- }
17
- const newRange = moveRangeByOperation(range, operation)
18
- expect(newRange).toEqual({
19
- anchor: {path: [0, 0], offset: 4},
20
- focus: {path: [0, 0], offset: 6},
21
- })
22
- })
23
- })
@@ -1,110 +0,0 @@
1
- import {compileSchema, defineSchema} from '@portabletext/schema'
2
- import {describe, expect, it} from 'vitest'
3
- import {toSlateBlock} from '../values'
4
-
5
- const schemaTypes = compileSchema(defineSchema({}))
6
-
7
- describe(toSlateBlock.name, () => {
8
- it('given type is custom with no custom properties, should include an empty text property in children and an empty value', () => {
9
- const result = toSlateBlock(
10
- {
11
- _type: 'image',
12
- _key: '123',
13
- },
14
- {schemaTypes},
15
- )
16
-
17
- expect(result).toMatchObject({
18
- _key: '123',
19
- _type: 'image',
20
- children: [
21
- {
22
- text: '',
23
- },
24
- ],
25
- value: {},
26
- })
27
- })
28
-
29
- it('given type is block', () => {
30
- const result = toSlateBlock(
31
- {
32
- _type: schemaTypes.block.name,
33
- _key: '123',
34
- children: [
35
- {
36
- _type: 'span',
37
- _key: '1231',
38
- text: '123',
39
- },
40
- ],
41
- },
42
- {schemaTypes},
43
- )
44
- expect(result).toEqual({
45
- _key: '123',
46
- _type: 'block',
47
- children: [
48
- {
49
- _key: '1231',
50
- _type: 'span',
51
- text: '123',
52
- },
53
- ],
54
- })
55
- })
56
-
57
- it('given type is block and has custom in children', () => {
58
- const result = toSlateBlock(
59
- {
60
- _type: schemaTypes.block.name,
61
- _key: '123',
62
- children: [
63
- {
64
- _type: 'span',
65
- _key: '1231',
66
- text: '123',
67
- },
68
- {
69
- _type: 'image',
70
- _key: '1232',
71
- asset: {
72
- _ref: 'ref-123',
73
- },
74
- },
75
- ],
76
- },
77
- {schemaTypes},
78
- )
79
-
80
- expect(result).toEqual({
81
- _key: '123',
82
- _type: 'block',
83
- children: [
84
- {
85
- _key: '1231',
86
- _type: 'span',
87
- text: '123',
88
- },
89
- {
90
- __inline: true,
91
- _key: '1232',
92
- _type: 'image',
93
- children: [
94
- {
95
- _key: 'void-child',
96
- _type: 'span',
97
- marks: [],
98
- text: '',
99
- },
100
- ],
101
- value: {
102
- asset: {
103
- _ref: 'ref-123',
104
- },
105
- },
106
- },
107
- ],
108
- })
109
- })
110
- })