@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,836 +0,0 @@
1
- import {compileSchema, defineSchema} from '@portabletext/schema'
2
- import {createTestKeyGenerator} from '@portabletext/test'
3
- import {describe, expect, test} from 'vitest'
4
- import {
5
- parseBlock,
6
- parseChild,
7
- parseInlineObject,
8
- parseSpan,
9
- } from './parse-blocks'
10
-
11
- describe(parseBlock.name, () => {
12
- test('null', () => {
13
- expect(
14
- parseBlock({
15
- block: null,
16
- context: {
17
- keyGenerator: createTestKeyGenerator(),
18
- schema: compileSchema(defineSchema({})),
19
- },
20
- options: {
21
- normalize: false,
22
- removeUnusedMarkDefs: true,
23
- validateFields: true,
24
- },
25
- }),
26
- ).toBe(undefined)
27
- })
28
-
29
- test('undefined', () => {
30
- expect(
31
- parseBlock({
32
- block: undefined,
33
- context: {
34
- keyGenerator: createTestKeyGenerator(),
35
- schema: compileSchema(defineSchema({})),
36
- },
37
- options: {
38
- normalize: false,
39
- removeUnusedMarkDefs: true,
40
- validateFields: true,
41
- },
42
- }),
43
- ).toBe(undefined)
44
- })
45
-
46
- describe('block object', () => {
47
- test('empty', () => {
48
- expect(
49
- parseBlock({
50
- block: {},
51
- context: {
52
- keyGenerator: createTestKeyGenerator(),
53
- schema: compileSchema(defineSchema({})),
54
- },
55
- options: {
56
- normalize: false,
57
- removeUnusedMarkDefs: true,
58
- validateFields: true,
59
- },
60
- }),
61
- ).toBe(undefined)
62
- })
63
-
64
- test('missing _type', () => {
65
- expect(
66
- parseBlock({
67
- block: {_key: 'k0'},
68
- context: {
69
- keyGenerator: createTestKeyGenerator(),
70
- schema: compileSchema(
71
- defineSchema({blockObjects: [{name: 'image'}]}),
72
- ),
73
- },
74
- options: {
75
- normalize: false,
76
- removeUnusedMarkDefs: true,
77
- validateFields: true,
78
- },
79
- }),
80
- ).toBe(undefined)
81
- })
82
-
83
- test('missing _key', () => {
84
- expect(
85
- parseBlock({
86
- block: {_type: 'image'},
87
- context: {
88
- keyGenerator: createTestKeyGenerator(),
89
- schema: compileSchema(
90
- defineSchema({blockObjects: [{name: 'image'}]}),
91
- ),
92
- },
93
- options: {
94
- normalize: false,
95
- removeUnusedMarkDefs: true,
96
- validateFields: true,
97
- },
98
- }),
99
- ).toEqual({
100
- _key: 'k0',
101
- _type: 'image',
102
- })
103
- })
104
- })
105
-
106
- describe('text block', () => {
107
- test('only _type', () => {
108
- expect(
109
- parseBlock({
110
- block: {_type: 'block'},
111
- context: {
112
- keyGenerator: createTestKeyGenerator(),
113
- schema: compileSchema(defineSchema({})),
114
- },
115
- options: {
116
- normalize: false,
117
- removeUnusedMarkDefs: true,
118
- validateFields: true,
119
- },
120
- }),
121
- ).toEqual({
122
- _key: 'k0',
123
- _type: 'block',
124
- children: [
125
- {
126
- _key: 'k1',
127
- _type: 'span',
128
- text: '',
129
- marks: [],
130
- },
131
- ],
132
- })
133
- })
134
-
135
- test('custom _type', () => {
136
- const schema = compileSchema(defineSchema({}))
137
- expect(
138
- parseBlock({
139
- block: {_type: 'text'},
140
- context: {
141
- keyGenerator: createTestKeyGenerator(),
142
- schema: {...schema, block: {...schema.block, name: 'text'}},
143
- },
144
- options: {
145
- normalize: false,
146
- removeUnusedMarkDefs: true,
147
- validateFields: true,
148
- },
149
- }),
150
- ).toEqual({
151
- _key: 'k0',
152
- _type: 'text',
153
- children: [
154
- {
155
- _key: 'k1',
156
- _type: 'span',
157
- text: '',
158
- marks: [],
159
- },
160
- ],
161
- })
162
- })
163
-
164
- test('only children', () => {
165
- expect(
166
- parseBlock({
167
- block: {
168
- children: [
169
- {
170
- _key: 'k1',
171
- _type: 'span',
172
- text: 'foo',
173
- marks: [],
174
- },
175
- ],
176
- },
177
- context: {
178
- keyGenerator: createTestKeyGenerator(),
179
- schema: compileSchema(defineSchema({})),
180
- },
181
- options: {
182
- normalize: false,
183
- removeUnusedMarkDefs: true,
184
- validateFields: true,
185
- },
186
- }),
187
- ).toBe(undefined)
188
- })
189
-
190
- test('invalid children', () => {
191
- expect(
192
- parseBlock({
193
- block: {
194
- _type: 'block',
195
- children: [
196
- undefined,
197
- null,
198
- 'foo',
199
- 42,
200
- {foo: 'bar'},
201
- {
202
- _key: 'some key',
203
- text: 'foo',
204
- marks: [],
205
- },
206
- {
207
- _type: 'stock-ticker',
208
- },
209
- {_type: 'span'},
210
- {_type: 'span', text: 'foo'},
211
- {_type: 'span', marks: ['strong']},
212
- {_type: 'span', marks: ['em']},
213
- {_type: 'image', text: 'inline object or span?'},
214
- ],
215
- },
216
- context: {
217
- keyGenerator: createTestKeyGenerator(),
218
- schema: compileSchema(
219
- defineSchema({
220
- inlineObjects: [{name: 'stock-ticker'}],
221
- decorators: [{name: 'em'}],
222
- }),
223
- ),
224
- },
225
- options: {
226
- normalize: false,
227
- removeUnusedMarkDefs: true,
228
- validateFields: true,
229
- },
230
- }),
231
- ).toEqual({
232
- _key: 'k0',
233
- _type: 'block',
234
- children: [
235
- {
236
- _key: 'some key',
237
- _type: 'span',
238
- text: 'foo',
239
- marks: [],
240
- },
241
- {
242
- _key: 'k1',
243
- _type: 'stock-ticker',
244
- },
245
- {
246
- _key: 'k2',
247
- _type: 'span',
248
- text: '',
249
- marks: [],
250
- },
251
- {
252
- _key: 'k3',
253
- _type: 'span',
254
- text: 'foo',
255
- marks: [],
256
- },
257
- {
258
- _key: 'k4',
259
- _type: 'span',
260
- text: '',
261
- marks: [],
262
- },
263
- {
264
- _key: 'k5',
265
- _type: 'span',
266
- text: '',
267
- marks: ['em'],
268
- },
269
- ],
270
- })
271
- })
272
-
273
- test('only (known) listItem', () => {
274
- expect(
275
- parseBlock({
276
- block: {_type: 'block', listItem: 'bullet'},
277
- context: {
278
- keyGenerator: createTestKeyGenerator(),
279
- schema: compileSchema(defineSchema({lists: [{name: 'bullet'}]})),
280
- },
281
- options: {
282
- normalize: false,
283
- removeUnusedMarkDefs: true,
284
- validateFields: true,
285
- },
286
- }),
287
- ).toEqual({
288
- _key: 'k0',
289
- _type: 'block',
290
- children: [
291
- {
292
- _key: 'k1',
293
- _type: 'span',
294
- text: '',
295
- marks: [],
296
- },
297
- ],
298
- listItem: 'bullet',
299
- })
300
- })
301
-
302
- test('only (unknown) listItem', () => {
303
- expect(
304
- parseBlock({
305
- block: {_type: 'block', listItem: 'number'},
306
- context: {
307
- keyGenerator: createTestKeyGenerator(),
308
- schema: compileSchema(defineSchema({lists: [{name: 'bullet'}]})),
309
- },
310
- options: {
311
- normalize: false,
312
- removeUnusedMarkDefs: true,
313
- validateFields: true,
314
- },
315
- }),
316
- ).toEqual({
317
- _key: 'k0',
318
- _type: 'block',
319
- children: [
320
- {
321
- _key: 'k1',
322
- _type: 'span',
323
- text: '',
324
- marks: [],
325
- },
326
- ],
327
- })
328
- })
329
-
330
- describe('validating custom fields', () => {
331
- test('none defined', () => {
332
- expect(
333
- parseBlock({
334
- block: {_type: 'block', map: {}},
335
- context: {
336
- keyGenerator: createTestKeyGenerator(),
337
- schema: compileSchema(defineSchema({})),
338
- },
339
- options: {
340
- normalize: false,
341
- removeUnusedMarkDefs: true,
342
- validateFields: true,
343
- },
344
- }),
345
- ).toEqual({
346
- _type: 'block',
347
- _key: 'k0',
348
- children: [
349
- {
350
- _key: 'k1',
351
- _type: 'span',
352
- text: '',
353
- marks: [],
354
- },
355
- ],
356
- })
357
- })
358
-
359
- test('field defined', () => {
360
- expect(
361
- parseBlock({
362
- block: {_type: 'block', map: {}},
363
- context: {
364
- keyGenerator: createTestKeyGenerator(),
365
- schema: compileSchema(
366
- defineSchema({
367
- block: {fields: [{name: 'map', type: 'object'}]},
368
- }),
369
- ),
370
- },
371
- options: {
372
- normalize: false,
373
- removeUnusedMarkDefs: true,
374
- validateFields: true,
375
- },
376
- }),
377
- ).toEqual({
378
- _type: 'block',
379
- _key: 'k0',
380
- map: {},
381
- children: [
382
- {
383
- _key: 'k1',
384
- _type: 'span',
385
- text: '',
386
- marks: [],
387
- },
388
- ],
389
- })
390
- })
391
-
392
- test('different field defined', () => {
393
- expect(
394
- parseBlock({
395
- block: {_type: 'block', foo: {}},
396
- context: {
397
- keyGenerator: createTestKeyGenerator(),
398
- schema: compileSchema(
399
- defineSchema({
400
- block: {fields: [{name: 'map', type: 'object'}]},
401
- }),
402
- ),
403
- },
404
- options: {
405
- normalize: false,
406
- removeUnusedMarkDefs: true,
407
- validateFields: true,
408
- },
409
- }),
410
- ).toEqual({
411
- _type: 'block',
412
- _key: 'k0',
413
- children: [
414
- {
415
- _key: 'k1',
416
- _type: 'span',
417
- text: '',
418
- marks: [],
419
- },
420
- ],
421
- })
422
- })
423
- })
424
- })
425
- })
426
-
427
- describe(parseSpan.name, () => {
428
- test('undefined', () => {
429
- expect(
430
- parseSpan({
431
- span: undefined,
432
- context: {
433
- keyGenerator: createTestKeyGenerator(),
434
- schema: compileSchema(defineSchema({})),
435
- },
436
- markDefKeyMap: new Map(),
437
- options: {validateFields: true},
438
- }),
439
- ).toBe(undefined)
440
- })
441
-
442
- test('null', () => {
443
- expect(
444
- parseSpan({
445
- span: null,
446
- context: {
447
- keyGenerator: createTestKeyGenerator(),
448
- schema: compileSchema(defineSchema({})),
449
- },
450
- markDefKeyMap: new Map(),
451
- options: {validateFields: true},
452
- }),
453
- ).toBe(undefined)
454
- })
455
-
456
- test('empty object', () => {
457
- expect(
458
- parseSpan({
459
- span: {},
460
- context: {
461
- keyGenerator: createTestKeyGenerator(),
462
- schema: compileSchema(defineSchema({})),
463
- },
464
- markDefKeyMap: new Map(),
465
- options: {validateFields: true},
466
- }),
467
- ).toBe(undefined)
468
- })
469
-
470
- test('invalid _type', () => {
471
- expect(
472
- parseSpan({
473
- span: {_type: 'stock-ticker'},
474
- context: {
475
- keyGenerator: createTestKeyGenerator(),
476
- schema: compileSchema(defineSchema({})),
477
- },
478
- markDefKeyMap: new Map(),
479
- options: {validateFields: true},
480
- }),
481
- ).toBe(undefined)
482
- })
483
-
484
- test('only _type', () => {
485
- expect(
486
- parseSpan({
487
- span: {_type: 'span'},
488
- context: {
489
- keyGenerator: createTestKeyGenerator(),
490
- schema: compileSchema(defineSchema({})),
491
- },
492
- markDefKeyMap: new Map(),
493
- options: {validateFields: true},
494
- }),
495
- ).toEqual({
496
- _key: 'k0',
497
- _type: 'span',
498
- text: '',
499
- marks: [],
500
- })
501
- })
502
-
503
- test('custom props', () => {
504
- expect(
505
- parseSpan({
506
- span: {_type: 'span', foo: 'bar'},
507
- context: {
508
- keyGenerator: createTestKeyGenerator(),
509
- schema: compileSchema(defineSchema({})),
510
- },
511
- markDefKeyMap: new Map(),
512
- options: {validateFields: true},
513
- }),
514
- ).toEqual({
515
- _key: 'k0',
516
- _type: 'span',
517
- text: '',
518
- marks: [],
519
- })
520
- })
521
-
522
- test('invalid marks array', () => {
523
- expect(
524
- parseSpan({
525
- span: {
526
- _type: 'span',
527
- marks: 42,
528
- },
529
- context: {
530
- keyGenerator: createTestKeyGenerator(),
531
- schema: compileSchema(defineSchema({})),
532
- },
533
- markDefKeyMap: new Map(),
534
- options: {validateFields: true},
535
- }),
536
- ).toEqual({
537
- _key: 'k0',
538
- _type: 'span',
539
- text: '',
540
- marks: [],
541
- })
542
- })
543
-
544
- test('invalid marks', () => {
545
- expect(
546
- parseSpan({
547
- span: {
548
- _type: 'span',
549
- marks: [null, undefined, 'foo', 42, {foo: 'bar'}, 'strong'],
550
- },
551
- context: {
552
- keyGenerator: createTestKeyGenerator(),
553
- schema: compileSchema(defineSchema({decorators: [{name: 'strong'}]})),
554
- },
555
- markDefKeyMap: new Map(),
556
- options: {validateFields: true},
557
- }),
558
- ).toEqual({
559
- _key: 'k0',
560
- _type: 'span',
561
- text: '',
562
- marks: ['strong'],
563
- })
564
- })
565
-
566
- test('unknown decorator', () => {
567
- expect(
568
- parseSpan({
569
- span: {
570
- _type: 'span',
571
- marks: ['strong', 'em'],
572
- },
573
- context: {
574
- keyGenerator: createTestKeyGenerator(),
575
- schema: compileSchema(defineSchema({decorators: [{name: 'strong'}]})),
576
- },
577
- markDefKeyMap: new Map(),
578
- options: {validateFields: true},
579
- }),
580
- ).toEqual({
581
- _key: 'k0',
582
- _type: 'span',
583
- text: '',
584
- marks: ['strong'],
585
- })
586
- })
587
- })
588
-
589
- describe(parseInlineObject.name, () => {
590
- test('undefined', () => {
591
- expect(
592
- parseInlineObject({
593
- inlineObject: undefined,
594
- context: {
595
- keyGenerator: createTestKeyGenerator(),
596
- schema: compileSchema(
597
- defineSchema({inlineObjects: [{name: 'stock-ticker'}]}),
598
- ),
599
- },
600
- options: {validateFields: true},
601
- }),
602
- ).toBe(undefined)
603
- })
604
-
605
- test('null', () => {
606
- expect(
607
- parseInlineObject({
608
- inlineObject: null,
609
- context: {
610
- keyGenerator: createTestKeyGenerator(),
611
- schema: compileSchema(
612
- defineSchema({inlineObjects: [{name: 'stock-ticker'}]}),
613
- ),
614
- },
615
- options: {validateFields: true},
616
- }),
617
- ).toBe(undefined)
618
- })
619
-
620
- test('empty object', () => {
621
- expect(
622
- parseInlineObject({
623
- inlineObject: {},
624
- context: {
625
- keyGenerator: createTestKeyGenerator(),
626
- schema: compileSchema(
627
- defineSchema({inlineObjects: [{name: 'stock-ticker'}]}),
628
- ),
629
- },
630
- options: {validateFields: true},
631
- }),
632
- ).toBe(undefined)
633
- })
634
-
635
- test('invalid _type', () => {
636
- expect(
637
- parseInlineObject({
638
- inlineObject: {_type: 'image'},
639
- context: {
640
- keyGenerator: createTestKeyGenerator(),
641
- schema: compileSchema(
642
- defineSchema({inlineObjects: [{name: 'stock-ticker'}]}),
643
- ),
644
- },
645
- options: {validateFields: true},
646
- }),
647
- ).toBe(undefined)
648
- })
649
-
650
- test('only _type', () => {
651
- expect(
652
- parseInlineObject({
653
- inlineObject: {_type: 'stock-ticker'},
654
- context: {
655
- keyGenerator: createTestKeyGenerator(),
656
- schema: compileSchema(
657
- defineSchema({inlineObjects: [{name: 'stock-ticker'}]}),
658
- ),
659
- },
660
- options: {validateFields: true},
661
- }),
662
- ).toEqual({
663
- _key: 'k0',
664
- _type: 'stock-ticker',
665
- })
666
- })
667
-
668
- describe('looks like text node', () => {
669
- test('known inline object _type', () => {
670
- expect(
671
- parseInlineObject({
672
- inlineObject: {_type: 'stock-ticker', text: 'foo'},
673
- context: {
674
- keyGenerator: createTestKeyGenerator(),
675
- schema: compileSchema(
676
- defineSchema({inlineObjects: [{name: 'stock-ticker'}]}),
677
- ),
678
- },
679
- options: {validateFields: true},
680
- }),
681
- ).toEqual({_key: 'k0', _type: 'stock-ticker'})
682
- })
683
-
684
- test('unknown inline object _type', () => {
685
- expect(
686
- parseInlineObject({
687
- inlineObject: {_type: 'image', text: 'foo'},
688
- context: {
689
- keyGenerator: createTestKeyGenerator(),
690
- schema: compileSchema(
691
- defineSchema({inlineObjects: [{name: 'stock-ticker'}]}),
692
- ),
693
- },
694
- options: {validateFields: true},
695
- }),
696
- ).toBe(undefined)
697
- })
698
- })
699
-
700
- describe('custom props', () => {
701
- describe('unknown prop', () => {
702
- test('validateFields: true', () => {
703
- expect(
704
- parseInlineObject({
705
- inlineObject: {_type: 'stock-ticker', foo: 'bar'},
706
- context: {
707
- keyGenerator: createTestKeyGenerator(),
708
- schema: compileSchema(
709
- defineSchema({
710
- inlineObjects: [{name: 'stock-ticker'}],
711
- }),
712
- ),
713
- },
714
- options: {validateFields: true},
715
- }),
716
- ).toEqual({
717
- _key: 'k0',
718
- _type: 'stock-ticker',
719
- })
720
- })
721
-
722
- test('validateFields: false', () => {
723
- expect(
724
- parseInlineObject({
725
- inlineObject: {_type: 'stock-ticker', foo: 'bar'},
726
- context: {
727
- keyGenerator: createTestKeyGenerator(),
728
- schema: compileSchema(
729
- defineSchema({
730
- inlineObjects: [{name: 'stock-ticker'}],
731
- }),
732
- ),
733
- },
734
- options: {validateFields: false},
735
- }),
736
- ).toEqual({
737
- _key: 'k0',
738
- _type: 'stock-ticker',
739
- foo: 'bar',
740
- })
741
- })
742
- })
743
-
744
- describe('known prop', () => {
745
- test('validateFields: true', () => {
746
- expect(
747
- parseInlineObject({
748
- inlineObject: {_type: 'stock-ticker', foo: 'bar'},
749
- context: {
750
- keyGenerator: createTestKeyGenerator(),
751
- schema: compileSchema(
752
- defineSchema({
753
- inlineObjects: [
754
- {
755
- name: 'stock-ticker',
756
- fields: [{name: 'foo', type: 'string'}],
757
- },
758
- ],
759
- }),
760
- ),
761
- },
762
- options: {validateFields: true},
763
- }),
764
- ).toEqual({
765
- _key: 'k0',
766
- _type: 'stock-ticker',
767
- foo: 'bar',
768
- })
769
- })
770
- })
771
-
772
- test('validateFields: false', () => {
773
- expect(
774
- parseInlineObject({
775
- inlineObject: {_type: 'stock-ticker', foo: 'bar'},
776
- context: {
777
- keyGenerator: createTestKeyGenerator(),
778
- schema: compileSchema(
779
- defineSchema({
780
- inlineObjects: [
781
- {
782
- name: 'stock-ticker',
783
- fields: [{name: 'foo', type: 'string'}],
784
- },
785
- ],
786
- }),
787
- ),
788
- },
789
- options: {validateFields: false},
790
- }),
791
- ).toEqual({
792
- _key: 'k0',
793
- _type: 'stock-ticker',
794
- foo: 'bar',
795
- })
796
- })
797
- })
798
- })
799
-
800
- describe(parseChild.name, () => {
801
- describe('inline object', () => {
802
- describe('looks like text node', () => {
803
- test('known inline object _type', () => {
804
- expect(
805
- parseChild({
806
- context: {
807
- keyGenerator: createTestKeyGenerator(),
808
- schema: compileSchema(
809
- defineSchema({inlineObjects: [{name: 'stock-ticker'}]}),
810
- ),
811
- },
812
- markDefKeyMap: new Map(),
813
- options: {validateFields: true},
814
- child: {_type: 'stock-ticker', text: 'foo'},
815
- }),
816
- ).toEqual({_key: 'k0', _type: 'stock-ticker'})
817
- })
818
-
819
- test('unknown inline object _type', () => {
820
- expect(
821
- parseChild({
822
- context: {
823
- keyGenerator: createTestKeyGenerator(),
824
- schema: compileSchema(
825
- defineSchema({inlineObjects: [{name: 'stock-ticker'}]}),
826
- ),
827
- },
828
- markDefKeyMap: new Map(),
829
- options: {validateFields: true},
830
- child: {_type: 'image', text: 'foo'},
831
- }),
832
- ).toBe(undefined)
833
- })
834
- })
835
- })
836
- })