@atlaskit/adf-schema 28.1.12 → 28.2.0

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 (210) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/types/index.d.ts +1 -1
  3. package/package.json +1 -1
  4. package/src/__tests__/unit/json-schema/v1.ts +0 -55
  5. package/src/__tests__/unit/schema/create-schema.ts +0 -214
  6. package/src/__tests__/unit/schema/default-schema.ts +0 -192
  7. package/src/__tests__/unit/schema/marks/annotation.ts +0 -46
  8. package/src/__tests__/unit/schema/marks/border.ts +0 -76
  9. package/src/__tests__/unit/schema/marks/breakout.ts +0 -24
  10. package/src/__tests__/unit/schema/marks/code.ts +0 -44
  11. package/src/__tests__/unit/schema/marks/confluence-inline-comment.ts +0 -25
  12. package/src/__tests__/unit/schema/marks/data-consumer.ts +0 -52
  13. package/src/__tests__/unit/schema/marks/em.ts +0 -37
  14. package/src/__tests__/unit/schema/marks/link.ts +0 -188
  15. package/src/__tests__/unit/schema/marks/strike.ts +0 -37
  16. package/src/__tests__/unit/schema/marks/strong.ts +0 -43
  17. package/src/__tests__/unit/schema/marks/subsup.ts +0 -50
  18. package/src/__tests__/unit/schema/marks/text-color.ts +0 -61
  19. package/src/__tests__/unit/schema/marks/underline.ts +0 -36
  20. package/src/__tests__/unit/schema/nodes/_consts.ts +0 -964
  21. package/src/__tests__/unit/schema/nodes/block-card.ts +0 -184
  22. package/src/__tests__/unit/schema/nodes/blockquote.ts +0 -44
  23. package/src/__tests__/unit/schema/nodes/bodied-extension.ts +0 -101
  24. package/src/__tests__/unit/schema/nodes/code-block.ts +0 -221
  25. package/src/__tests__/unit/schema/nodes/confluence-unsupported-block.ts +0 -32
  26. package/src/__tests__/unit/schema/nodes/confluence-unsupported-inline.ts +0 -35
  27. package/src/__tests__/unit/schema/nodes/date.ts +0 -51
  28. package/src/__tests__/unit/schema/nodes/decision-item.ts +0 -46
  29. package/src/__tests__/unit/schema/nodes/decision-list.ts +0 -52
  30. package/src/__tests__/unit/schema/nodes/embed-card.ts +0 -60
  31. package/src/__tests__/unit/schema/nodes/emoji.ts +0 -71
  32. package/src/__tests__/unit/schema/nodes/expand.ts +0 -51
  33. package/src/__tests__/unit/schema/nodes/extension.ts +0 -101
  34. package/src/__tests__/unit/schema/nodes/hard-break.ts +0 -24
  35. package/src/__tests__/unit/schema/nodes/heading.ts +0 -56
  36. package/src/__tests__/unit/schema/nodes/image.ts +0 -32
  37. package/src/__tests__/unit/schema/nodes/inline-card.ts +0 -106
  38. package/src/__tests__/unit/schema/nodes/inline-extension.ts +0 -79
  39. package/src/__tests__/unit/schema/nodes/layout-column.ts +0 -54
  40. package/src/__tests__/unit/schema/nodes/layout-section.ts +0 -95
  41. package/src/__tests__/unit/schema/nodes/list-item.ts +0 -49
  42. package/src/__tests__/unit/schema/nodes/media-group.ts +0 -67
  43. package/src/__tests__/unit/schema/nodes/media-single.ts +0 -171
  44. package/src/__tests__/unit/schema/nodes/media.ts +0 -384
  45. package/src/__tests__/unit/schema/nodes/mention.ts +0 -115
  46. package/src/__tests__/unit/schema/nodes/nestedExpand.ts +0 -72
  47. package/src/__tests__/unit/schema/nodes/ordered-list.ts +0 -49
  48. package/src/__tests__/unit/schema/nodes/panel.ts +0 -180
  49. package/src/__tests__/unit/schema/nodes/paragraph.ts +0 -25
  50. package/src/__tests__/unit/schema/nodes/placeholder.ts +0 -46
  51. package/src/__tests__/unit/schema/nodes/rule.ts +0 -24
  52. package/src/__tests__/unit/schema/nodes/status.ts +0 -120
  53. package/src/__tests__/unit/schema/nodes/tableNodes.ts +0 -555
  54. package/src/__tests__/unit/schema/nodes/task-item.ts +0 -39
  55. package/src/__tests__/unit/schema/nodes/task-list.ts +0 -45
  56. package/src/__tests__/unit/schema/nodes/unknown-block.ts +0 -42
  57. package/src/__tests__/unit/schema/nodes/unsupported-block.ts +0 -42
  58. package/src/__tests__/unit/schema/nodes/unsupported-inline.ts +0 -38
  59. package/src/__tests__/unit/utils/colors.ts +0 -42
  60. package/src/__tests__/unit/utils/url.ts +0 -209
  61. package/src/schema/bitbucket-schema.ts +0 -43
  62. package/src/schema/confluence-schema.ts +0 -76
  63. package/src/schema/create-schema.ts +0 -337
  64. package/src/schema/default-schema.ts +0 -180
  65. package/src/schema/groups.ts +0 -30
  66. package/src/schema/inline-nodes.ts +0 -9
  67. package/src/schema/jira-schema.ts +0 -158
  68. package/src/schema/marks/__tests__/unit/annotation.ts +0 -18
  69. package/src/schema/marks/alignment.ts +0 -48
  70. package/src/schema/marks/annotation.ts +0 -107
  71. package/src/schema/marks/border.ts +0 -74
  72. package/src/schema/marks/breakout.ts +0 -42
  73. package/src/schema/marks/code.ts +0 -45
  74. package/src/schema/marks/confluence-inline-comment.ts +0 -32
  75. package/src/schema/marks/data-consumer.ts +0 -100
  76. package/src/schema/marks/em.ts +0 -19
  77. package/src/schema/marks/fragment.ts +0 -77
  78. package/src/schema/marks/indentation.ts +0 -47
  79. package/src/schema/marks/link.ts +0 -139
  80. package/src/schema/marks/strike.ts +0 -26
  81. package/src/schema/marks/strong.ts +0 -45
  82. package/src/schema/marks/subsup.ts +0 -53
  83. package/src/schema/marks/text-color.ts +0 -172
  84. package/src/schema/marks/type-ahead-query.ts +0 -22
  85. package/src/schema/marks/underline.ts +0 -24
  86. package/src/schema/marks/unsupported-mark.ts +0 -9
  87. package/src/schema/marks/unsupported-node-attributes.ts +0 -8
  88. package/src/schema/nodes/block-card.ts +0 -121
  89. package/src/schema/nodes/blockquote.ts +0 -25
  90. package/src/schema/nodes/bodied-extension.ts +0 -75
  91. package/src/schema/nodes/bullet-list.ts +0 -17
  92. package/src/schema/nodes/caption.ts +0 -51
  93. package/src/schema/nodes/code-block.ts +0 -176
  94. package/src/schema/nodes/confluence-jira-issue.ts +0 -43
  95. package/src/schema/nodes/confluence-unsupported-block.ts +0 -29
  96. package/src/schema/nodes/confluence-unsupported-inline.ts +0 -30
  97. package/src/schema/nodes/date.ts +0 -38
  98. package/src/schema/nodes/decision-item.ts +0 -50
  99. package/src/schema/nodes/decision-list.ts +0 -56
  100. package/src/schema/nodes/doc.ts +0 -30
  101. package/src/schema/nodes/embed-card.ts +0 -62
  102. package/src/schema/nodes/emoji.ts +0 -89
  103. package/src/schema/nodes/expand.ts +0 -101
  104. package/src/schema/nodes/extension.ts +0 -60
  105. package/src/schema/nodes/hard-break.ts +0 -21
  106. package/src/schema/nodes/heading.ts +0 -64
  107. package/src/schema/nodes/image.ts +0 -32
  108. package/src/schema/nodes/inline-card.ts +0 -70
  109. package/src/schema/nodes/inline-extension.ts +0 -57
  110. package/src/schema/nodes/layout-column.ts +0 -68
  111. package/src/schema/nodes/layout-section.ts +0 -93
  112. package/src/schema/nodes/list-item.ts +0 -13
  113. package/src/schema/nodes/media-group.ts +0 -44
  114. package/src/schema/nodes/media-inline.ts +0 -19
  115. package/src/schema/nodes/media-single.ts +0 -179
  116. package/src/schema/nodes/media.ts +0 -253
  117. package/src/schema/nodes/mention.ts +0 -86
  118. package/src/schema/nodes/nested-expand.ts +0 -77
  119. package/src/schema/nodes/ordered-list.ts +0 -62
  120. package/src/schema/nodes/panel.ts +0 -133
  121. package/src/schema/nodes/paragraph.ts +0 -79
  122. package/src/schema/nodes/placeholder.ts +0 -40
  123. package/src/schema/nodes/rule.ts +0 -17
  124. package/src/schema/nodes/status.ts +0 -58
  125. package/src/schema/nodes/tableNodes.ts +0 -478
  126. package/src/schema/nodes/task-item.ts +0 -51
  127. package/src/schema/nodes/task-list.ts +0 -61
  128. package/src/schema/nodes/text.ts +0 -19
  129. package/src/schema/nodes/types/block-content.ts +0 -51
  130. package/src/schema/nodes/types/extensions.ts +0 -36
  131. package/src/schema/nodes/types/inline-content.ts +0 -56
  132. package/src/schema/nodes/types/list.ts +0 -54
  133. package/src/schema/nodes/types/mark.ts +0 -16
  134. package/src/schema/nodes/types/non-nestable-block-content.ts +0 -39
  135. package/src/schema/nodes/types/rich-media-common.ts +0 -51
  136. package/src/schema/nodes/unknown-block.ts +0 -13
  137. package/src/schema/nodes/unsupported-block.ts +0 -28
  138. package/src/schema/nodes/unsupported-inline.ts +0 -27
  139. package/src/schema/unsupported.ts +0 -4
  140. package/src/steps/__tests__/unit/analytics.ts +0 -72
  141. package/src/steps/__tests__/unit/link-meta-step.ts +0 -64
  142. package/src/steps/__tests__/unit/override-document-step.ts +0 -174
  143. package/src/steps/__tests__/unit/set-attrs.ts +0 -71
  144. package/src/steps/analytics.ts +0 -189
  145. package/src/steps/link-meta-step.ts +0 -105
  146. package/src/steps/override-document-step.ts +0 -97
  147. package/src/steps/set-attrs.tsx +0 -74
  148. package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-0.json +0 -15
  149. package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-1.json +0 -15
  150. package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-2.json +0 -15
  151. package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-3.json +0 -15
  152. package/src/steps/table/__tests__/__fixtures__/basic/remove-column-at-0.json +0 -9
  153. package/src/steps/table/__tests__/__fixtures__/basic/remove-column-at-1.json +0 -9
  154. package/src/steps/table/__tests__/__fixtures__/basic/remove-column-at-2.json +0 -9
  155. package/src/steps/table/__tests__/__fixtures__/basic/remove-table/remove-last-row-inverted.json +0 -98
  156. package/src/steps/table/__tests__/__fixtures__/basic/remove-table/remove-last-row.json +0 -71
  157. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-0-inverted.json +0 -19
  158. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-0.json +0 -19
  159. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-1-inverted.json +0 -21
  160. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-1.json +0 -21
  161. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-2-inverted.json +0 -21
  162. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-2.json +0 -21
  163. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-3-inverted.json +0 -19
  164. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-3.json +0 -19
  165. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-0-inverted.json +0 -63
  166. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-0.json +0 -21
  167. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-1-inverted.json +0 -64
  168. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-1.json +0 -22
  169. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-2-inverted.json +0 -63
  170. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-2.json +0 -21
  171. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-0-inverted.json +0 -19
  172. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-0.json +0 -19
  173. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-1-inverted.json +0 -19
  174. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-1.json +0 -19
  175. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-2-inverted.json +0 -19
  176. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-2.json +0 -19
  177. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-3-inverted.json +0 -19
  178. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-3.json +0 -19
  179. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-0-inverted.json +0 -52
  180. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-0.json +0 -38
  181. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-1-inverted.json +0 -52
  182. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-1.json +0 -38
  183. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-2-inverted.json +0 -25
  184. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-2.json +0 -11
  185. package/src/steps/table/__tests__/_utils.ts +0 -102
  186. package/src/steps/table/__tests__/add-column-merge-columns.ts +0 -509
  187. package/src/steps/table/__tests__/add-column-merge-rows.ts +0 -466
  188. package/src/steps/table/__tests__/add-column.ts +0 -638
  189. package/src/steps/table/add-column.ts +0 -443
  190. package/src/steps/table/constants.ts +0 -4
  191. package/src/steps/table/sort-column.ts +0 -57
  192. package/src/steps/table/types.ts +0 -48
  193. package/src/steps/table/utils/cell-step.ts +0 -239
  194. package/src/steps/table/utils/cells-at-column.ts +0 -75
  195. package/src/steps/table/utils/find-column.ts +0 -90
  196. package/src/steps/table/utils/get-table-rect-from-doc.ts +0 -37
  197. package/src/steps/table/utils/side-effects/rows.ts +0 -327
  198. package/src/steps/table/utils/side-effects/side-effects.ts +0 -90
  199. package/src/steps/table/utils/side-effects/table.ts +0 -112
  200. package/src/steps/table/utils/side-effects/types.ts +0 -34
  201. package/src/steps/table/utils/table-map.ts +0 -28
  202. package/src/steps/type-ahead.ts +0 -100
  203. package/src/steps.ts +0 -16
  204. package/src/utils/colors.ts +0 -171
  205. package/src/utils/confluence/emoji.ts +0 -99
  206. package/src/utils/extensions.ts +0 -32
  207. package/src/utils/parseDOM.ts +0 -2
  208. package/src/utils/url.ts +0 -173
  209. package/src/utils/uuid.ts +0 -19
  210. package/src/version.json +0 -6
@@ -1,509 +0,0 @@
1
- import {
2
- DocBuilder,
3
- doc,
4
- tdEmpty,
5
- table,
6
- tr,
7
- p,
8
- Refs,
9
- } from 'adf-test-helpers/src/doc-builder';
10
- import { EditorState } from '@atlaskit/editor-prosemirror/state';
11
- import { Node as ProseMirrorNode } from '@atlaskit/editor-prosemirror/model';
12
- import { Step } from '@atlaskit/editor-prosemirror/transform';
13
- import {
14
- tdColorA,
15
- tdColorC,
16
- createCellColorA,
17
- createCellColorB,
18
- createCellColorC,
19
- setup,
20
- applyAndInvertTransaction,
21
- addColumnAtFactory,
22
- removeColumnAtFactory,
23
- CreateTransaction,
24
- testHistory,
25
- } from './_utils';
26
- import { AddColumnStep } from '../add-column';
27
- import { defaultSchema } from '../../../schema/default-schema';
28
-
29
- import * as addColumnAtZeroJson from './__fixtures__/merge-cells/columns/add-column-at-0.json';
30
- import * as addColumnAtOneJson from './__fixtures__/merge-cells/columns/add-column-at-1.json';
31
- import * as addColumnAtTwoJson from './__fixtures__/merge-cells/columns/add-column-at-2.json';
32
- import * as addColumnAtThreeJson from './__fixtures__/merge-cells/columns/add-column-at-3.json';
33
- import * as removeColumnAtZeroJson from './__fixtures__/merge-cells/columns/remove-column-at-0.json';
34
- import * as removeColumnAtOneJson from './__fixtures__/merge-cells/columns/remove-column-at-1.json';
35
- import * as removeColumnAtTwoJson from './__fixtures__/merge-cells/columns/remove-column-at-2.json';
36
-
37
- // inverted
38
- import * as addColumnAtZeroInvertedJson from './__fixtures__/merge-cells/columns/add-column-at-0-inverted.json';
39
- import * as addColumnAtOneInvertedJson from './__fixtures__/merge-cells/columns/add-column-at-1-inverted.json';
40
- import * as addColumnAtTwoInvertedJson from './__fixtures__/merge-cells/columns/add-column-at-2-inverted.json';
41
- import * as addColumnAtThreeInvertedJson from './__fixtures__/merge-cells/columns/add-column-at-3-inverted.json';
42
- import * as removeColumnAtZeroInvertedJson from './__fixtures__/merge-cells/columns/remove-column-at-0-inverted.json';
43
- import * as removeColumnAtOneInvertedJson from './__fixtures__/merge-cells/columns/remove-column-at-1-inverted.json';
44
- import * as removeColumnAtTwoInvertedJson from './__fixtures__/merge-cells/columns/remove-column-at-2-inverted.json';
45
-
46
- // Possible documents
47
- const originalDoc = doc(
48
- '{table}',
49
- table()(
50
- tr(tdColorA, createCellColorB(2)),
51
- tr(createCellColorA(2), tdColorC),
52
- tr(createCellColorC(3)),
53
- ),
54
- );
55
- const docAfterAddColumnAtZero = doc(
56
- table()(
57
- tr(tdEmpty, tdColorA, createCellColorB(2)),
58
- tr(tdEmpty, createCellColorA(2), tdColorC),
59
- tr(tdEmpty, createCellColorC(3)),
60
- ),
61
- );
62
-
63
- const docAfterAddColumnAtOne = doc(
64
- table()(
65
- tr(tdColorA, tdEmpty, createCellColorB(2)),
66
- tr(createCellColorA(3), tdColorC),
67
- tr(createCellColorC(4)),
68
- ),
69
- );
70
-
71
- const docAfterAddColumnAtTwo = doc(
72
- table()(
73
- tr(tdColorA, createCellColorB(3)),
74
- tr(createCellColorA(2), tdEmpty, tdColorC),
75
- tr(createCellColorC(4)),
76
- ),
77
- );
78
-
79
- const docAfterAddColumnAtThree = doc(
80
- table()(
81
- tr(tdColorA, createCellColorB(2), tdEmpty),
82
- tr(createCellColorA(2), tdColorC, tdEmpty),
83
- tr(createCellColorC(3), tdEmpty),
84
- ),
85
- );
86
-
87
- const docAfterRemoveColumnOne = doc(
88
- table()(
89
- tr(tdColorA, createCellColorB(1)),
90
- tr(createCellColorA(1), tdColorC),
91
- tr(createCellColorC(2)),
92
- ),
93
- );
94
-
95
- const docAfterRemoveColumnZero = doc(
96
- table()(
97
- tr(createCellColorB(2)),
98
- tr(createCellColorA(1), tdColorC),
99
- tr(createCellColorC(2)),
100
- ),
101
- );
102
-
103
- const docAfterRemoveColumnTwo = doc(
104
- table()(
105
- tr(tdColorA, createCellColorB(1)),
106
- tr(createCellColorA(2)),
107
- tr(createCellColorC(2)),
108
- ),
109
- );
110
-
111
- /**
112
- * Index for adding a column works like this
113
- * | colorA | colorB | colorC |
114
- * | colorA | colorB | colorC |
115
- * 0 1 2 3
116
- *
117
- * Index for remove a column works like this
118
- * | colorA | colorB | colorC |
119
- * | colorA | colorB | colorC |
120
- * 0 1 2
121
- */
122
- describe('AddColumnStep', () => {
123
- describe(`
124
- table 3x3 with merged columns
125
- | a | b |
126
- | a | c |
127
- | c |
128
- `, () => {
129
- let editorState: EditorState;
130
- let refs: Refs;
131
-
132
- beforeEach(() => {
133
- ({ editorState, refs } = setup(originalDoc));
134
- });
135
-
136
- describe('add a column', () => {
137
- it.each`
138
- column | expectedDoc
139
- ${0} | ${docAfterAddColumnAtZero}
140
- ${1} | ${docAfterAddColumnAtOne}
141
- ${2} | ${docAfterAddColumnAtTwo}
142
- ${3} | ${docAfterAddColumnAtThree}
143
- `(
144
- 'should add a column at $column of the table',
145
- ({ column, expectedDoc }) => {
146
- editorState = editorState.apply(
147
- addColumnAtFactory('table', column)(editorState, refs),
148
- );
149
-
150
- expect(editorState.doc.toJSON()).toEqual(
151
- expectedDoc(defaultSchema).toJSON(),
152
- );
153
- },
154
- );
155
- });
156
-
157
- describe('remove a column', () => {
158
- it.each`
159
- column | expectedDoc
160
- ${0} | ${docAfterRemoveColumnZero}
161
- ${1} | ${docAfterRemoveColumnOne}
162
- ${2} | ${docAfterRemoveColumnTwo}
163
- `(
164
- 'should remove a column at $column of the table',
165
- ({ column, expectedDoc }) => {
166
- editorState = editorState.apply(
167
- removeColumnAtFactory('table', column)(editorState, refs),
168
- );
169
-
170
- expect(editorState.doc.toJSON()).toEqual(
171
- expectedDoc(defaultSchema).toJSON(),
172
- );
173
- },
174
- );
175
- });
176
-
177
- describe('invert', () => {
178
- let editorState: EditorState;
179
- let refs: Refs;
180
- let originalDocNode: ProseMirrorNode;
181
-
182
- beforeEach(() => {
183
- ({ editorState, refs } = setup(originalDoc));
184
- originalDocNode = editorState.doc;
185
- });
186
-
187
- it.each`
188
- description | setup
189
- ${'add column that was removed at the end with the same content'} | ${removeColumnAtFactory('table', 2)}
190
- ${'add column that was removed at the beginning with the same content'} | ${removeColumnAtFactory('table', 0)}
191
- ${'add column that was removed in the middle with the same content'} | ${removeColumnAtFactory('table', 1)}
192
- ${'remove a column that was added at the beginning'} | ${addColumnAtFactory('table', 0)}
193
- ${'remove a column that was added at the middle'} | ${addColumnAtFactory('table', 1)}
194
- ${'remove a column that was added at the almost end'} | ${addColumnAtFactory('table', 2)}
195
- ${'remove a column that was added at the end'} | ${addColumnAtFactory('table', 3)}
196
- `('should be able to $description', ({ setup }) => {
197
- const transaction = setup(editorState, refs);
198
- editorState = applyAndInvertTransaction(originalDocNode)(
199
- transaction,
200
- editorState,
201
- );
202
- expect(editorState.doc.toJSON()).toEqual(
203
- originalDoc(defaultSchema).toJSON(),
204
- );
205
- });
206
- });
207
-
208
- describe('mapping', () => {
209
- it.each<
210
- [string, DocBuilder, CreateTransaction, CreateTransaction, DocBuilder]
211
- >([
212
- [
213
- 'add the column in the correct position after adding text at the beginning',
214
- doc(
215
- '{table}',
216
- table()(
217
- tr(tdColorA, createCellColorB(2)),
218
- tr(createCellColorA(2), tdColorC),
219
- tr(createCellColorC(3)),
220
- ),
221
- ),
222
- (editorState) => editorState.tr.insertText('foo', 0),
223
- addColumnAtFactory('table', 3),
224
- doc(
225
- p('foo'),
226
- table()(
227
- tr(tdColorA, createCellColorB(2), tdEmpty),
228
- tr(createCellColorA(2), tdColorC, tdEmpty),
229
- tr(createCellColorC(3), tdEmpty),
230
- ),
231
- ),
232
- ],
233
- [
234
- 'add the column in the correct position after adding a column at the beginning',
235
- doc(
236
- '{table}',
237
- table()(
238
- tr(tdColorA, createCellColorB(2)),
239
- tr(createCellColorA(2), tdColorC),
240
- tr(createCellColorC(3)),
241
- ),
242
- ),
243
- addColumnAtFactory('table', 0),
244
- addColumnAtFactory('table', 3),
245
- doc(
246
- table()(
247
- tr(tdEmpty, tdColorA, createCellColorB(2), tdEmpty),
248
- tr(tdEmpty, createCellColorA(2), tdColorC, tdEmpty),
249
- tr(tdEmpty, createCellColorC(3), tdEmpty),
250
- ),
251
- ),
252
- ],
253
- [
254
- 'add the column in the correct position after adding a column in the same position',
255
- doc(
256
- '{table}',
257
- table()(
258
- tr(tdColorA, createCellColorB(2)),
259
- tr(createCellColorA(2), tdColorC),
260
- tr(createCellColorC(3)),
261
- ),
262
- ),
263
- addColumnAtFactory('table', 2),
264
- addColumnAtFactory('table', 2),
265
- doc(
266
- table()(
267
- tr(tdColorA, createCellColorB(4)),
268
- tr(createCellColorA(2), tdEmpty, tdEmpty, tdColorC),
269
- tr(createCellColorC(5)),
270
- ),
271
- ),
272
- ],
273
- ])(
274
- 'should %s',
275
- (_, originalDoc, firstTransaction, secondTransaction, expectedDoc) => {
276
- let { editorState, refs } = setup(originalDoc);
277
-
278
- const transaction = firstTransaction(editorState, refs);
279
- let addColumnStep: Step | null | undefined = secondTransaction(
280
- editorState,
281
- refs,
282
- ).steps[0];
283
-
284
- editorState = editorState.apply(transaction);
285
-
286
- // Map the step with the transaction
287
- addColumnStep = addColumnStep.map(transaction.mapping);
288
-
289
- // It should exist
290
- expect(addColumnStep).toBeTruthy();
291
-
292
- editorState = editorState.apply(editorState.tr.step(addColumnStep!));
293
-
294
- expect(editorState.doc.toJSON()).toEqual(
295
- expectedDoc(defaultSchema).toJSON(),
296
- );
297
- },
298
- );
299
- });
300
-
301
- describe('history plugin', () => {
302
- const testCases: [
303
- string,
304
- CreateTransaction,
305
- CreateTransaction[],
306
- DocBuilder,
307
- ][] = [
308
- [
309
- 'be able to undo an add column step after adding new columns',
310
- addColumnAtFactory('table', 2),
311
- [addColumnAtFactory('table', 1), addColumnAtFactory('table', 1)],
312
- doc(
313
- table()(
314
- tr(tdColorA, tdEmpty, tdEmpty, createCellColorB(2)),
315
- tr(createCellColorA(4), tdColorC),
316
- tr(createCellColorC(5)),
317
- ),
318
- ),
319
- ],
320
- [
321
- 'be able to undo an remove column step after adding new columns',
322
- removeColumnAtFactory('table', 2),
323
- [addColumnAtFactory('table', 1), addColumnAtFactory('table', 1)],
324
- doc(
325
- table()(
326
- tr(tdColorA, tdEmpty, tdEmpty, createCellColorB(2)),
327
- tr(createCellColorA(4), tdColorC),
328
- tr(createCellColorC(5)),
329
- ),
330
- ),
331
- ],
332
- [
333
- 'be able to undo an add column step after removing columns',
334
- addColumnAtFactory('table', 2),
335
- [
336
- removeColumnAtFactory('table', 0),
337
- removeColumnAtFactory('table', 0),
338
- ],
339
- doc(
340
- table()(
341
- tr(createCellColorB(1)),
342
- tr(tdColorC),
343
- tr(createCellColorC(1)),
344
- ),
345
- ),
346
- ],
347
- [
348
- 'be able to undo a remove column step after removing a column',
349
- removeColumnAtFactory('table', 2),
350
- [removeColumnAtFactory('table', 0)],
351
- doc(
352
- table()(
353
- tr(createCellColorB(2)),
354
- tr(createCellColorA(1), tdColorC),
355
- tr(createCellColorC(2)),
356
- ),
357
- ),
358
- ],
359
- ];
360
-
361
- testCases.forEach(
362
- ([description, transaction, historyTransactions, expectDoc]) => {
363
- it(`should ${description}`, () => {
364
- const editorState = testHistory(
365
- originalDoc,
366
- transaction,
367
- historyTransactions,
368
- );
369
-
370
- expect(editorState.doc.toJSON()).toEqual(
371
- expectDoc(defaultSchema).toJSON(),
372
- );
373
- });
374
- },
375
- );
376
- });
377
-
378
- describe('fromJson()', () => {
379
- it.each`
380
- column | startDoc | jsonStep | expectedDoc
381
- ${0} | ${originalDoc} | ${addColumnAtZeroJson} | ${docAfterAddColumnAtZero}
382
- ${1} | ${originalDoc} | ${addColumnAtOneJson} | ${docAfterAddColumnAtOne}
383
- ${2} | ${originalDoc} | ${addColumnAtTwoJson} | ${docAfterAddColumnAtTwo}
384
- ${3} | ${originalDoc} | ${addColumnAtThreeJson} | ${docAfterAddColumnAtThree}
385
- `(
386
- 'should parse JSON and add a column at $column column',
387
- ({ startDoc, jsonStep, expectedDoc }) => {
388
- ({ editorState } = setup(startDoc));
389
-
390
- const addColumnStep = Step.fromJSON(defaultSchema, jsonStep);
391
- editorState = editorState.apply(editorState.tr.step(addColumnStep));
392
-
393
- expect(editorState.doc.toJSON()).toEqual(
394
- expectedDoc(defaultSchema).toJSON(),
395
- );
396
- },
397
- );
398
-
399
- it.each`
400
- column | startDoc | jsonStep | expectedDoc
401
- ${0} | ${docAfterAddColumnAtZero} | ${addColumnAtZeroInvertedJson} | ${originalDoc}
402
- ${1} | ${docAfterAddColumnAtOne} | ${addColumnAtOneInvertedJson} | ${originalDoc}
403
- ${2} | ${docAfterAddColumnAtTwo} | ${addColumnAtTwoInvertedJson} | ${originalDoc}
404
- ${3} | ${docAfterAddColumnAtThree} | ${addColumnAtThreeInvertedJson} | ${originalDoc}
405
- `(
406
- 'should parse JSON and remove a column that was added at $column column',
407
- ({ startDoc, jsonStep, expectedDoc }) => {
408
- ({ editorState } = setup(startDoc));
409
-
410
- const addColumnStep = Step.fromJSON(defaultSchema, jsonStep);
411
- editorState = editorState.apply(editorState.tr.step(addColumnStep));
412
-
413
- expect(editorState.doc.toJSON()).toEqual(
414
- expectedDoc(defaultSchema).toJSON(),
415
- );
416
- },
417
- );
418
-
419
- it.each`
420
- column | jsonStep | expectedDoc
421
- ${0} | ${removeColumnAtZeroJson} | ${docAfterRemoveColumnZero}
422
- ${1} | ${removeColumnAtOneJson} | ${docAfterRemoveColumnOne}
423
- ${2} | ${removeColumnAtTwoJson} | ${docAfterRemoveColumnTwo}
424
- `(
425
- 'should parse JSON and remove a column at $column column',
426
- ({ jsonStep, expectedDoc }) => {
427
- const addColumnStep = Step.fromJSON(defaultSchema, jsonStep);
428
- editorState = editorState.apply(editorState.tr.step(addColumnStep));
429
-
430
- expect(editorState.doc.toJSON()).toEqual(
431
- expectedDoc(defaultSchema).toJSON(),
432
- );
433
- },
434
- );
435
-
436
- it.each`
437
- column | startDoc | jsonStep | expectedDoc
438
- ${0} | ${docAfterRemoveColumnZero} | ${removeColumnAtZeroInvertedJson} | ${originalDoc}
439
- ${1} | ${docAfterRemoveColumnOne} | ${removeColumnAtOneInvertedJson} | ${originalDoc}
440
- ${2} | ${docAfterRemoveColumnTwo} | ${removeColumnAtTwoInvertedJson} | ${originalDoc}
441
- `(
442
- 'should parse JSON and add a column that was removed at $column column',
443
- ({ startDoc, jsonStep, expectedDoc }) => {
444
- ({ editorState } = setup(startDoc));
445
-
446
- const addColumnStep = Step.fromJSON(defaultSchema, jsonStep);
447
- editorState = editorState.apply(editorState.tr.step(addColumnStep));
448
-
449
- expect(editorState.doc.toJSON()).toEqual(
450
- expectedDoc(defaultSchema).toJSON(),
451
- );
452
- },
453
- );
454
- });
455
-
456
- // Sanity check of the serialization process
457
- describe('serialize/deserialize', () => {
458
- it.each`
459
- column
460
- ${0}
461
- ${1}
462
- ${2}
463
- ${3}
464
- `(
465
- 'should serialize/deserialize a new column at $column',
466
- ({ column }) => {
467
- const { editorState, refs } = setup(originalDoc);
468
- const addColumnStep = AddColumnStep.create(
469
- editorState.doc,
470
- refs['table'],
471
- column,
472
- false,
473
- );
474
-
475
- const json = addColumnStep.toJSON();
476
- const stepFromJson = Step.fromJSON(defaultSchema, json);
477
- expect(
478
- editorState.apply(editorState.tr.step(addColumnStep)).doc,
479
- ).toEqual(editorState.apply(editorState.tr.step(stepFromJson)).doc);
480
- },
481
- );
482
-
483
- it.each`
484
- column
485
- ${0}
486
- ${1}
487
- ${2}
488
- `(
489
- 'should serialize/deserialize remove a column at $column',
490
- ({ column }) => {
491
- const { editorState, refs } = setup(originalDoc);
492
- const addColumnStep = AddColumnStep.create(
493
- editorState.doc,
494
- refs['table'],
495
- column,
496
- true,
497
- );
498
-
499
- const json = addColumnStep.toJSON();
500
- const stepFromJson = Step.fromJSON(defaultSchema, json);
501
-
502
- expect(
503
- editorState.apply(editorState.tr.step(addColumnStep)).doc,
504
- ).toEqual(editorState.apply(editorState.tr.step(stepFromJson)).doc);
505
- },
506
- );
507
- });
508
- });
509
- });