@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,466 +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
- createCellColorA,
15
- createCellColorB,
16
- createCellColorC,
17
- setup,
18
- applyAndInvertTransaction,
19
- addColumnAtFactory,
20
- removeColumnAtFactory,
21
- CreateTransaction,
22
- } from './_utils';
23
- import { defaultSchema } from '../../../schema/default-schema';
24
-
25
- import * as addColumnAtZeroJson from './__fixtures__/merge-cells/rows/add-column-at-0.json';
26
- import * as addColumnAtOneJson from './__fixtures__/merge-cells/rows/add-column-at-1.json';
27
- import * as addColumnAtTwoJson from './__fixtures__/merge-cells/rows/add-column-at-2.json';
28
- import * as addColumnAtThreeJson from './__fixtures__/merge-cells/rows/add-column-at-3.json';
29
- import * as removeColumnAtZeroJson from './__fixtures__/merge-cells/rows/remove-column-at-0.json';
30
- import * as removeColumnAtOneJson from './__fixtures__/merge-cells/rows/remove-column-at-1.json';
31
- import * as removeColumnAtTwoJson from './__fixtures__/merge-cells/rows/remove-column-at-2.json';
32
-
33
- // inverted
34
- import * as addColumnAtZeroInvertedJson from './__fixtures__/merge-cells/rows/add-column-at-0-inverted.json';
35
- import * as addColumnAtOneInvertedJson from './__fixtures__/merge-cells/rows/add-column-at-1-inverted.json';
36
- import * as addColumnAtTwoInvertedJson from './__fixtures__/merge-cells/rows/add-column-at-2-inverted.json';
37
- import * as addColumnAtThreeInvertedJson from './__fixtures__/merge-cells/rows/add-column-at-3-inverted.json';
38
- import * as removeColumnAtZeroInvertedJson from './__fixtures__/merge-cells/rows/remove-column-at-0-inverted.json';
39
- import * as removeColumnAtOneInvertedJson from './__fixtures__/merge-cells/rows/remove-column-at-1-inverted.json';
40
- import * as removeColumnAtTwoInvertedJson from './__fixtures__/merge-cells/rows/remove-column-at-2-inverted.json';
41
-
42
- // Possible documents
43
- const originalDoc = doc(
44
- '{table}',
45
- table()(
46
- tr(
47
- createCellColorA(undefined, 2),
48
- createCellColorB(),
49
- createCellColorC(undefined, 3),
50
- ),
51
- tr(createCellColorB(undefined, 2)),
52
- tr(createCellColorA()),
53
- ),
54
- );
55
- const docAfterAddColumnAtZero = doc(
56
- '{table}',
57
- table()(
58
- tr(
59
- tdEmpty,
60
- createCellColorA(undefined, 2),
61
- createCellColorB(),
62
- createCellColorC(undefined, 3),
63
- ),
64
- tr(tdEmpty, createCellColorB(undefined, 2)),
65
- tr(tdEmpty, createCellColorA()),
66
- ),
67
- );
68
- const docAfterAddColumnAtOne = doc(
69
- '{table}',
70
- table()(
71
- tr(
72
- createCellColorA(undefined, 2),
73
- tdEmpty,
74
- createCellColorB(),
75
- createCellColorC(undefined, 3),
76
- ),
77
- tr(tdEmpty, createCellColorB(undefined, 2)),
78
- tr(createCellColorA(), tdEmpty),
79
- ),
80
- );
81
- const docAfterAddColumnAtTwo = doc(
82
- '{table}',
83
- table()(
84
- tr(
85
- createCellColorA(undefined, 2),
86
- createCellColorB(),
87
- tdEmpty,
88
- createCellColorC(undefined, 3),
89
- ),
90
- tr(createCellColorB(undefined, 2), tdEmpty),
91
- tr(createCellColorA(), tdEmpty),
92
- ),
93
- );
94
- const docAfterAddColumnAtThree = doc(
95
- '{table}',
96
- table()(
97
- tr(
98
- createCellColorA(undefined, 2),
99
- createCellColorB(),
100
- createCellColorC(undefined, 3),
101
- tdEmpty,
102
- ),
103
- tr(createCellColorB(undefined, 2), tdEmpty),
104
- tr(createCellColorA(), tdEmpty),
105
- ),
106
- );
107
- const docAfterRemoveColumnAtZero = doc(
108
- '{table}',
109
- table()(
110
- tr(createCellColorB(), createCellColorC(undefined, 2)),
111
- tr(createCellColorB(undefined, 1)),
112
- ),
113
- );
114
- const docAfterRemoveColumnAtOne = doc(
115
- '{table}',
116
- table()(
117
- tr(createCellColorA(undefined, 1), createCellColorC(undefined, 2)),
118
- tr(createCellColorA()),
119
- ),
120
- );
121
- const docAfterRemoveColumnAtTwo = doc(
122
- '{table}',
123
- table()(
124
- tr(createCellColorA(undefined, 2), createCellColorB()),
125
- tr(createCellColorB(undefined, 2)),
126
- tr(createCellColorA()),
127
- ),
128
- );
129
-
130
- /**
131
- * Index for adding a column works like this
132
- * | colorA | colorB | colorC |
133
- * | colorA | colorB | colorC |
134
- * 0 1 2 3
135
- *
136
- * Index for remove a column works like this
137
- * | colorA | colorB | colorC |
138
- * | colorA | colorB | colorC |
139
- * 0 1 2
140
- */
141
- describe('AddColumnStep', () => {
142
- describe(`
143
- Table 3x3 with merge rows
144
- | a | b | c |
145
- | _ | b | |
146
- | a | _ | _ |
147
- `, () => {
148
- let editorState: EditorState;
149
- let refs: Refs;
150
-
151
- beforeEach(() => {
152
- ({ editorState, refs } = setup(originalDoc));
153
- });
154
-
155
- describe('add a column', () => {
156
- it.each`
157
- column | expectedDoc
158
- ${0} | ${docAfterAddColumnAtZero}
159
- ${1} | ${docAfterAddColumnAtOne}
160
- ${2} | ${docAfterAddColumnAtTwo}
161
- ${3} | ${docAfterAddColumnAtThree}
162
- `(
163
- 'should add a column at $column of the table',
164
- ({ column, expectedDoc }) => {
165
- editorState = editorState.apply(
166
- addColumnAtFactory('table', column)(editorState, refs),
167
- );
168
-
169
- expect(editorState.doc.toJSON()).toEqual(
170
- expectedDoc(defaultSchema).toJSON(),
171
- );
172
- },
173
- );
174
- });
175
-
176
- describe('remove a column', () => {
177
- it.each`
178
- column | expectedDoc
179
- ${0} | ${docAfterRemoveColumnAtZero}
180
- ${1} | ${docAfterRemoveColumnAtOne}
181
- ${2} | ${docAfterRemoveColumnAtTwo}
182
- `(
183
- 'should remove a column at $column of the table',
184
- ({ column, expectedDoc }) => {
185
- editorState = editorState.apply(
186
- removeColumnAtFactory('table', column)(editorState, refs),
187
- );
188
-
189
- expect(editorState.doc.toJSON()).toEqual(
190
- expectedDoc(defaultSchema).toJSON(),
191
- );
192
- },
193
- );
194
- });
195
-
196
- describe('invert', () => {
197
- let editorState: EditorState;
198
- let refs: Refs;
199
- let originalDocNode: ProseMirrorNode;
200
-
201
- beforeEach(() => {
202
- ({ editorState, refs } = setup(originalDoc));
203
- originalDocNode = editorState.doc;
204
- });
205
-
206
- it.each`
207
- description | setup
208
- ${'add column that was removed at the end with the same content'} | ${removeColumnAtFactory('table', 2)}
209
- ${'add column that was removed at the beginning with the same content'} | ${removeColumnAtFactory('table', 0)}
210
- ${'add column that was removed in the middle with the same content'} | ${removeColumnAtFactory('table', 1)}
211
- ${'remove a column that was added at the beginning'} | ${addColumnAtFactory('table', 0)}
212
- ${'remove a column that was added at the middle'} | ${addColumnAtFactory('table', 1)}
213
- ${'remove a column that was added at the almost end'} | ${addColumnAtFactory('table', 2)}
214
- ${'remove a column that was added at the end'} | ${addColumnAtFactory('table', 3)}
215
- `('should be able to $description', ({ setup }) => {
216
- const transaction = setup(editorState, refs);
217
- editorState = applyAndInvertTransaction(originalDocNode)(
218
- transaction,
219
- editorState,
220
- );
221
- expect(editorState.doc.toJSON()).toEqual(
222
- originalDoc(defaultSchema).toJSON(),
223
- );
224
- });
225
- });
226
-
227
- describe('mapping', () => {
228
- it.each<
229
- [string, DocBuilder, CreateTransaction, CreateTransaction, DocBuilder]
230
- >([
231
- [
232
- 'add the column in the correct position after adding text at the beginning',
233
- originalDoc,
234
- (editorState) => editorState.tr.insertText('foo', 0),
235
- addColumnAtFactory('table', 3),
236
- doc(
237
- p('foo'),
238
- table()(
239
- tr(
240
- createCellColorA(undefined, 2),
241
- createCellColorB(),
242
- createCellColorC(undefined, 3),
243
- tdEmpty,
244
- ),
245
- tr(createCellColorB(undefined, 2), tdEmpty),
246
- tr(createCellColorA(), tdEmpty),
247
- ),
248
- ),
249
- ],
250
- [
251
- 'add the column in the correct position after adding a column at the beginning',
252
- originalDoc,
253
- addColumnAtFactory('table', 0),
254
- addColumnAtFactory('table', 3),
255
- doc(
256
- table()(
257
- tr(
258
- tdEmpty,
259
- createCellColorA(undefined, 2),
260
- createCellColorB(),
261
- createCellColorC(undefined, 3),
262
- tdEmpty,
263
- ),
264
- tr(tdEmpty, createCellColorB(undefined, 2), tdEmpty),
265
- tr(tdEmpty, createCellColorA(), tdEmpty),
266
- ),
267
- ),
268
- ],
269
- [
270
- 'add the column in the correct position after adding a column in the same position',
271
- originalDoc,
272
- addColumnAtFactory('table', 2),
273
- addColumnAtFactory('table', 2),
274
- doc(
275
- table()(
276
- tr(
277
- createCellColorA(undefined, 2),
278
- createCellColorB(),
279
- tdEmpty,
280
- tdEmpty,
281
- createCellColorC(undefined, 3),
282
- ),
283
- tr(createCellColorB(undefined, 2), tdEmpty, tdEmpty),
284
- tr(createCellColorA(), tdEmpty, tdEmpty),
285
- ),
286
- ),
287
- ],
288
- [
289
- 'add the column in the correct position after removing a column a previous position',
290
- originalDoc,
291
- removeColumnAtFactory('table', 1),
292
- addColumnAtFactory('table', 2),
293
- doc(
294
- table()(
295
- tr(
296
- createCellColorA(undefined, 1),
297
- tdEmpty,
298
- createCellColorC(undefined, 2),
299
- ),
300
- tr(createCellColorA(), tdEmpty),
301
- ),
302
- ),
303
- ],
304
- [
305
- 'remove the column in the correct position after removing a column in a previous position',
306
- originalDoc,
307
- removeColumnAtFactory('table', 1),
308
- removeColumnAtFactory('table', 2),
309
- doc(table()(tr(createCellColorA()), tr(createCellColorA()))),
310
- ],
311
- ])(
312
- 'should %s',
313
- (_, originalDoc, firstTransaction, secondTransaction, expectedDoc) => {
314
- let { editorState, refs } = setup(originalDoc);
315
-
316
- const transaction = firstTransaction(editorState, refs);
317
- let addColumnStep: Step | null | undefined = secondTransaction(
318
- editorState,
319
- refs,
320
- ).steps[0];
321
-
322
- editorState = editorState.apply(transaction);
323
-
324
- // Map the step with the transaction
325
- addColumnStep = addColumnStep.map(transaction.mapping);
326
-
327
- // It should exist
328
- expect(addColumnStep).toBeTruthy();
329
-
330
- editorState = editorState.apply(editorState.tr.step(addColumnStep!));
331
-
332
- expect(editorState.doc.toJSON()).toEqual(
333
- expectedDoc(defaultSchema).toJSON(),
334
- );
335
- },
336
- );
337
- });
338
-
339
- describe('fromJson()', () => {
340
- it.each`
341
- column | startDoc | jsonStep | expectedDoc
342
- ${0} | ${originalDoc} | ${addColumnAtZeroJson} | ${docAfterAddColumnAtZero}
343
- ${1} | ${originalDoc} | ${addColumnAtOneJson} | ${docAfterAddColumnAtOne}
344
- ${2} | ${originalDoc} | ${addColumnAtTwoJson} | ${docAfterAddColumnAtTwo}
345
- ${3} | ${originalDoc} | ${addColumnAtThreeJson} | ${docAfterAddColumnAtThree}
346
- `(
347
- 'should parse JSON and add a column at $column column',
348
- ({ startDoc, jsonStep, expectedDoc }) => {
349
- ({ editorState } = setup(startDoc));
350
-
351
- const addColumnStep = Step.fromJSON(defaultSchema, jsonStep);
352
- editorState = editorState.apply(editorState.tr.step(addColumnStep));
353
-
354
- expect(editorState.doc.toJSON()).toEqual(
355
- expectedDoc(defaultSchema).toJSON(),
356
- );
357
- },
358
- );
359
-
360
- it.each`
361
- column | startDoc | jsonStep | expectedDoc
362
- ${0} | ${docAfterAddColumnAtZero} | ${addColumnAtZeroInvertedJson} | ${originalDoc}
363
- ${1} | ${docAfterAddColumnAtOne} | ${addColumnAtOneInvertedJson} | ${originalDoc}
364
- ${2} | ${docAfterAddColumnAtTwo} | ${addColumnAtTwoInvertedJson} | ${originalDoc}
365
- ${3} | ${docAfterAddColumnAtThree} | ${addColumnAtThreeInvertedJson} | ${originalDoc}
366
- `(
367
- 'should parse JSON and remove a column that was added at $column column',
368
- ({ startDoc, jsonStep, expectedDoc }) => {
369
- ({ editorState } = setup(startDoc));
370
-
371
- const addColumnStep = Step.fromJSON(defaultSchema, jsonStep);
372
- editorState = editorState.apply(editorState.tr.step(addColumnStep));
373
-
374
- expect(editorState.doc.toJSON()).toEqual(
375
- expectedDoc(defaultSchema).toJSON(),
376
- );
377
- },
378
- );
379
-
380
- it.each`
381
- column | jsonStep | expectedDoc
382
- ${0} | ${removeColumnAtZeroJson} | ${docAfterRemoveColumnAtZero}
383
- ${1} | ${removeColumnAtOneJson} | ${docAfterRemoveColumnAtOne}
384
- ${2} | ${removeColumnAtTwoJson} | ${docAfterRemoveColumnAtTwo}
385
- `(
386
- 'should parse JSON and remove a column at $column column',
387
- ({ jsonStep, expectedDoc }) => {
388
- const addColumnStep = Step.fromJSON(defaultSchema, jsonStep);
389
- editorState = editorState.apply(editorState.tr.step(addColumnStep));
390
-
391
- expect(editorState.doc.toJSON()).toEqual(
392
- expectedDoc(defaultSchema).toJSON(),
393
- );
394
- },
395
- );
396
-
397
- it.each`
398
- column | startDoc | jsonStep | expectedDoc
399
- ${0} | ${docAfterRemoveColumnAtZero} | ${removeColumnAtZeroInvertedJson} | ${originalDoc}
400
- ${1} | ${docAfterRemoveColumnAtOne} | ${removeColumnAtOneInvertedJson} | ${originalDoc}
401
- ${2} | ${docAfterRemoveColumnAtTwo} | ${removeColumnAtTwoInvertedJson} | ${originalDoc}
402
- `(
403
- 'should parse JSON and add a column that was removed at $column column',
404
- ({ startDoc, jsonStep, expectedDoc }) => {
405
- ({ editorState } = setup(startDoc));
406
-
407
- const addColumnStep = Step.fromJSON(defaultSchema, jsonStep);
408
- editorState = editorState.apply(editorState.tr.step(addColumnStep));
409
-
410
- expect(editorState.doc.toJSON()).toEqual(
411
- expectedDoc(defaultSchema).toJSON(),
412
- );
413
- },
414
- );
415
- });
416
-
417
- // Sanity check of the serialization process
418
- describe('serialize/deserialize', () => {
419
- it.each`
420
- column
421
- ${0}
422
- ${1}
423
- ${2}
424
- ${3}
425
- `(
426
- 'should serialize/deserialize a new column at $column',
427
- ({ column }) => {
428
- const { editorState, refs } = setup(originalDoc);
429
- const addColumnStep = addColumnAtFactory('table', column)(
430
- editorState,
431
- refs,
432
- ).steps[0];
433
-
434
- const json = addColumnStep.toJSON();
435
- const stepFromJson = Step.fromJSON(defaultSchema, json);
436
- expect(
437
- editorState.apply(editorState.tr.step(addColumnStep)).doc,
438
- ).toEqual(editorState.apply(editorState.tr.step(stepFromJson)).doc);
439
- },
440
- );
441
-
442
- it.each`
443
- column
444
- ${0}
445
- ${1}
446
- ${2}
447
- `(
448
- 'should serialize/deserialize remove a column at $column',
449
- ({ column }) => {
450
- const { editorState, refs } = setup(originalDoc);
451
- const addColumnStep = removeColumnAtFactory('table', column)(
452
- editorState,
453
- refs,
454
- ).steps[0];
455
-
456
- const json = addColumnStep.toJSON();
457
- const stepFromJson = Step.fromJSON(defaultSchema, json);
458
-
459
- expect(
460
- editorState.apply(editorState.tr.step(addColumnStep)).doc,
461
- ).toEqual(editorState.apply(editorState.tr.step(stepFromJson)).doc);
462
- },
463
- );
464
- });
465
- });
466
- });