@atlaskit/adf-schema 28.1.12 → 28.1.13

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 (209) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/package.json +1 -1
  3. package/src/__tests__/unit/json-schema/v1.ts +0 -55
  4. package/src/__tests__/unit/schema/create-schema.ts +0 -214
  5. package/src/__tests__/unit/schema/default-schema.ts +0 -192
  6. package/src/__tests__/unit/schema/marks/annotation.ts +0 -46
  7. package/src/__tests__/unit/schema/marks/border.ts +0 -76
  8. package/src/__tests__/unit/schema/marks/breakout.ts +0 -24
  9. package/src/__tests__/unit/schema/marks/code.ts +0 -44
  10. package/src/__tests__/unit/schema/marks/confluence-inline-comment.ts +0 -25
  11. package/src/__tests__/unit/schema/marks/data-consumer.ts +0 -52
  12. package/src/__tests__/unit/schema/marks/em.ts +0 -37
  13. package/src/__tests__/unit/schema/marks/link.ts +0 -188
  14. package/src/__tests__/unit/schema/marks/strike.ts +0 -37
  15. package/src/__tests__/unit/schema/marks/strong.ts +0 -43
  16. package/src/__tests__/unit/schema/marks/subsup.ts +0 -50
  17. package/src/__tests__/unit/schema/marks/text-color.ts +0 -61
  18. package/src/__tests__/unit/schema/marks/underline.ts +0 -36
  19. package/src/__tests__/unit/schema/nodes/_consts.ts +0 -964
  20. package/src/__tests__/unit/schema/nodes/block-card.ts +0 -184
  21. package/src/__tests__/unit/schema/nodes/blockquote.ts +0 -44
  22. package/src/__tests__/unit/schema/nodes/bodied-extension.ts +0 -101
  23. package/src/__tests__/unit/schema/nodes/code-block.ts +0 -221
  24. package/src/__tests__/unit/schema/nodes/confluence-unsupported-block.ts +0 -32
  25. package/src/__tests__/unit/schema/nodes/confluence-unsupported-inline.ts +0 -35
  26. package/src/__tests__/unit/schema/nodes/date.ts +0 -51
  27. package/src/__tests__/unit/schema/nodes/decision-item.ts +0 -46
  28. package/src/__tests__/unit/schema/nodes/decision-list.ts +0 -52
  29. package/src/__tests__/unit/schema/nodes/embed-card.ts +0 -60
  30. package/src/__tests__/unit/schema/nodes/emoji.ts +0 -71
  31. package/src/__tests__/unit/schema/nodes/expand.ts +0 -51
  32. package/src/__tests__/unit/schema/nodes/extension.ts +0 -101
  33. package/src/__tests__/unit/schema/nodes/hard-break.ts +0 -24
  34. package/src/__tests__/unit/schema/nodes/heading.ts +0 -56
  35. package/src/__tests__/unit/schema/nodes/image.ts +0 -32
  36. package/src/__tests__/unit/schema/nodes/inline-card.ts +0 -106
  37. package/src/__tests__/unit/schema/nodes/inline-extension.ts +0 -79
  38. package/src/__tests__/unit/schema/nodes/layout-column.ts +0 -54
  39. package/src/__tests__/unit/schema/nodes/layout-section.ts +0 -95
  40. package/src/__tests__/unit/schema/nodes/list-item.ts +0 -49
  41. package/src/__tests__/unit/schema/nodes/media-group.ts +0 -67
  42. package/src/__tests__/unit/schema/nodes/media-single.ts +0 -171
  43. package/src/__tests__/unit/schema/nodes/media.ts +0 -384
  44. package/src/__tests__/unit/schema/nodes/mention.ts +0 -115
  45. package/src/__tests__/unit/schema/nodes/nestedExpand.ts +0 -72
  46. package/src/__tests__/unit/schema/nodes/ordered-list.ts +0 -49
  47. package/src/__tests__/unit/schema/nodes/panel.ts +0 -180
  48. package/src/__tests__/unit/schema/nodes/paragraph.ts +0 -25
  49. package/src/__tests__/unit/schema/nodes/placeholder.ts +0 -46
  50. package/src/__tests__/unit/schema/nodes/rule.ts +0 -24
  51. package/src/__tests__/unit/schema/nodes/status.ts +0 -120
  52. package/src/__tests__/unit/schema/nodes/tableNodes.ts +0 -555
  53. package/src/__tests__/unit/schema/nodes/task-item.ts +0 -39
  54. package/src/__tests__/unit/schema/nodes/task-list.ts +0 -45
  55. package/src/__tests__/unit/schema/nodes/unknown-block.ts +0 -42
  56. package/src/__tests__/unit/schema/nodes/unsupported-block.ts +0 -42
  57. package/src/__tests__/unit/schema/nodes/unsupported-inline.ts +0 -38
  58. package/src/__tests__/unit/utils/colors.ts +0 -42
  59. package/src/__tests__/unit/utils/url.ts +0 -209
  60. package/src/schema/bitbucket-schema.ts +0 -43
  61. package/src/schema/confluence-schema.ts +0 -76
  62. package/src/schema/create-schema.ts +0 -337
  63. package/src/schema/default-schema.ts +0 -180
  64. package/src/schema/groups.ts +0 -30
  65. package/src/schema/inline-nodes.ts +0 -9
  66. package/src/schema/jira-schema.ts +0 -158
  67. package/src/schema/marks/__tests__/unit/annotation.ts +0 -18
  68. package/src/schema/marks/alignment.ts +0 -48
  69. package/src/schema/marks/annotation.ts +0 -107
  70. package/src/schema/marks/border.ts +0 -74
  71. package/src/schema/marks/breakout.ts +0 -42
  72. package/src/schema/marks/code.ts +0 -45
  73. package/src/schema/marks/confluence-inline-comment.ts +0 -32
  74. package/src/schema/marks/data-consumer.ts +0 -100
  75. package/src/schema/marks/em.ts +0 -19
  76. package/src/schema/marks/fragment.ts +0 -77
  77. package/src/schema/marks/indentation.ts +0 -47
  78. package/src/schema/marks/link.ts +0 -139
  79. package/src/schema/marks/strike.ts +0 -26
  80. package/src/schema/marks/strong.ts +0 -45
  81. package/src/schema/marks/subsup.ts +0 -53
  82. package/src/schema/marks/text-color.ts +0 -172
  83. package/src/schema/marks/type-ahead-query.ts +0 -22
  84. package/src/schema/marks/underline.ts +0 -24
  85. package/src/schema/marks/unsupported-mark.ts +0 -9
  86. package/src/schema/marks/unsupported-node-attributes.ts +0 -8
  87. package/src/schema/nodes/block-card.ts +0 -121
  88. package/src/schema/nodes/blockquote.ts +0 -25
  89. package/src/schema/nodes/bodied-extension.ts +0 -75
  90. package/src/schema/nodes/bullet-list.ts +0 -17
  91. package/src/schema/nodes/caption.ts +0 -51
  92. package/src/schema/nodes/code-block.ts +0 -176
  93. package/src/schema/nodes/confluence-jira-issue.ts +0 -43
  94. package/src/schema/nodes/confluence-unsupported-block.ts +0 -29
  95. package/src/schema/nodes/confluence-unsupported-inline.ts +0 -30
  96. package/src/schema/nodes/date.ts +0 -38
  97. package/src/schema/nodes/decision-item.ts +0 -50
  98. package/src/schema/nodes/decision-list.ts +0 -56
  99. package/src/schema/nodes/doc.ts +0 -30
  100. package/src/schema/nodes/embed-card.ts +0 -62
  101. package/src/schema/nodes/emoji.ts +0 -89
  102. package/src/schema/nodes/expand.ts +0 -101
  103. package/src/schema/nodes/extension.ts +0 -60
  104. package/src/schema/nodes/hard-break.ts +0 -21
  105. package/src/schema/nodes/heading.ts +0 -64
  106. package/src/schema/nodes/image.ts +0 -32
  107. package/src/schema/nodes/inline-card.ts +0 -70
  108. package/src/schema/nodes/inline-extension.ts +0 -57
  109. package/src/schema/nodes/layout-column.ts +0 -68
  110. package/src/schema/nodes/layout-section.ts +0 -93
  111. package/src/schema/nodes/list-item.ts +0 -13
  112. package/src/schema/nodes/media-group.ts +0 -44
  113. package/src/schema/nodes/media-inline.ts +0 -19
  114. package/src/schema/nodes/media-single.ts +0 -179
  115. package/src/schema/nodes/media.ts +0 -253
  116. package/src/schema/nodes/mention.ts +0 -86
  117. package/src/schema/nodes/nested-expand.ts +0 -77
  118. package/src/schema/nodes/ordered-list.ts +0 -62
  119. package/src/schema/nodes/panel.ts +0 -133
  120. package/src/schema/nodes/paragraph.ts +0 -79
  121. package/src/schema/nodes/placeholder.ts +0 -40
  122. package/src/schema/nodes/rule.ts +0 -17
  123. package/src/schema/nodes/status.ts +0 -58
  124. package/src/schema/nodes/tableNodes.ts +0 -478
  125. package/src/schema/nodes/task-item.ts +0 -51
  126. package/src/schema/nodes/task-list.ts +0 -61
  127. package/src/schema/nodes/text.ts +0 -19
  128. package/src/schema/nodes/types/block-content.ts +0 -51
  129. package/src/schema/nodes/types/extensions.ts +0 -36
  130. package/src/schema/nodes/types/inline-content.ts +0 -56
  131. package/src/schema/nodes/types/list.ts +0 -54
  132. package/src/schema/nodes/types/mark.ts +0 -16
  133. package/src/schema/nodes/types/non-nestable-block-content.ts +0 -39
  134. package/src/schema/nodes/types/rich-media-common.ts +0 -51
  135. package/src/schema/nodes/unknown-block.ts +0 -13
  136. package/src/schema/nodes/unsupported-block.ts +0 -28
  137. package/src/schema/nodes/unsupported-inline.ts +0 -27
  138. package/src/schema/unsupported.ts +0 -4
  139. package/src/steps/__tests__/unit/analytics.ts +0 -72
  140. package/src/steps/__tests__/unit/link-meta-step.ts +0 -64
  141. package/src/steps/__tests__/unit/override-document-step.ts +0 -174
  142. package/src/steps/__tests__/unit/set-attrs.ts +0 -71
  143. package/src/steps/analytics.ts +0 -189
  144. package/src/steps/link-meta-step.ts +0 -105
  145. package/src/steps/override-document-step.ts +0 -97
  146. package/src/steps/set-attrs.tsx +0 -74
  147. package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-0.json +0 -15
  148. package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-1.json +0 -15
  149. package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-2.json +0 -15
  150. package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-3.json +0 -15
  151. package/src/steps/table/__tests__/__fixtures__/basic/remove-column-at-0.json +0 -9
  152. package/src/steps/table/__tests__/__fixtures__/basic/remove-column-at-1.json +0 -9
  153. package/src/steps/table/__tests__/__fixtures__/basic/remove-column-at-2.json +0 -9
  154. package/src/steps/table/__tests__/__fixtures__/basic/remove-table/remove-last-row-inverted.json +0 -98
  155. package/src/steps/table/__tests__/__fixtures__/basic/remove-table/remove-last-row.json +0 -71
  156. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-0-inverted.json +0 -19
  157. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-0.json +0 -19
  158. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-1-inverted.json +0 -21
  159. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-1.json +0 -21
  160. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-2-inverted.json +0 -21
  161. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-2.json +0 -21
  162. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-3-inverted.json +0 -19
  163. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-3.json +0 -19
  164. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-0-inverted.json +0 -63
  165. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-0.json +0 -21
  166. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-1-inverted.json +0 -64
  167. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-1.json +0 -22
  168. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-2-inverted.json +0 -63
  169. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-2.json +0 -21
  170. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-0-inverted.json +0 -19
  171. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-0.json +0 -19
  172. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-1-inverted.json +0 -19
  173. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-1.json +0 -19
  174. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-2-inverted.json +0 -19
  175. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-2.json +0 -19
  176. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-3-inverted.json +0 -19
  177. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-3.json +0 -19
  178. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-0-inverted.json +0 -52
  179. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-0.json +0 -38
  180. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-1-inverted.json +0 -52
  181. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-1.json +0 -38
  182. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-2-inverted.json +0 -25
  183. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-2.json +0 -11
  184. package/src/steps/table/__tests__/_utils.ts +0 -102
  185. package/src/steps/table/__tests__/add-column-merge-columns.ts +0 -509
  186. package/src/steps/table/__tests__/add-column-merge-rows.ts +0 -466
  187. package/src/steps/table/__tests__/add-column.ts +0 -638
  188. package/src/steps/table/add-column.ts +0 -443
  189. package/src/steps/table/constants.ts +0 -4
  190. package/src/steps/table/sort-column.ts +0 -57
  191. package/src/steps/table/types.ts +0 -48
  192. package/src/steps/table/utils/cell-step.ts +0 -239
  193. package/src/steps/table/utils/cells-at-column.ts +0 -75
  194. package/src/steps/table/utils/find-column.ts +0 -90
  195. package/src/steps/table/utils/get-table-rect-from-doc.ts +0 -37
  196. package/src/steps/table/utils/side-effects/rows.ts +0 -327
  197. package/src/steps/table/utils/side-effects/side-effects.ts +0 -90
  198. package/src/steps/table/utils/side-effects/table.ts +0 -112
  199. package/src/steps/table/utils/side-effects/types.ts +0 -34
  200. package/src/steps/table/utils/table-map.ts +0 -28
  201. package/src/steps/type-ahead.ts +0 -100
  202. package/src/steps.ts +0 -16
  203. package/src/utils/colors.ts +0 -171
  204. package/src/utils/confluence/emoji.ts +0 -99
  205. package/src/utils/extensions.ts +0 -32
  206. package/src/utils/parseDOM.ts +0 -2
  207. package/src/utils/url.ts +0 -173
  208. package/src/utils/uuid.ts +0 -19
  209. package/src/version.json +0 -6
@@ -1,638 +0,0 @@
1
- import {
2
- DocBuilder,
3
- doc,
4
- p,
5
- Refs,
6
- table,
7
- td,
8
- tdEmpty,
9
- expand,
10
- tr,
11
- } from 'adf-test-helpers/src/doc-builder';
12
- import { EditorState } from '@atlaskit/editor-prosemirror/state';
13
- import { Node as ProseMirrorNode } from '@atlaskit/editor-prosemirror/model';
14
- import { Step } from '@atlaskit/editor-prosemirror/transform';
15
- import {
16
- addColumnAtFactory,
17
- applyAndInvertTransaction,
18
- createCellColorA,
19
- createCellColorB,
20
- createCellColorC,
21
- CreateTransaction,
22
- removeColumnAtFactory,
23
- setup,
24
- tdColorA,
25
- tdColorB,
26
- tdColorC,
27
- testHistory,
28
- } from './_utils';
29
- import { defaultSchema } from '../../../schema/default-schema';
30
- import { AddColumnStep } from '../add-column';
31
-
32
- import * as removeLastRowJson from './__fixtures__/basic/remove-table/remove-last-row.json';
33
- import * as removeLastRowInvertedJson from './__fixtures__/basic/remove-table/remove-last-row-inverted.json';
34
- import * as addColumnAtZeroJson from './__fixtures__/basic/add-column-at-0.json';
35
- import * as addColumnAtOneJson from './__fixtures__/basic/add-column-at-1.json';
36
- import * as addColumnAtTwoJson from './__fixtures__/basic/add-column-at-2.json';
37
- import * as addColumnAtThreeJson from './__fixtures__/basic/add-column-at-3.json';
38
- import * as removeColumnAtZeroJson from './__fixtures__/basic/remove-column-at-0.json';
39
- import * as removeColumnAtOneJson from './__fixtures__/basic/remove-column-at-1.json';
40
- import * as removeColumnAtTwoJson from './__fixtures__/basic/remove-column-at-2.json';
41
-
42
- // Possible documents
43
- const twoBythreeTable = doc(
44
- '{table}',
45
- table()(tr(tdColorA, tdColorB, tdColorC), tr(tdColorA, tdColorB, tdColorC)),
46
- );
47
-
48
- const docAfterAddColumnAtThree = doc(
49
- table()(
50
- tr(tdColorA, tdColorB, tdColorC, tdEmpty),
51
- tr(tdColorA, tdColorB, tdColorC, tdEmpty),
52
- ),
53
- );
54
-
55
- const docAfterAddColumnAtZero = doc(
56
- table()(
57
- tr(tdEmpty, tdColorA, tdColorB, tdColorC),
58
- tr(tdEmpty, tdColorA, tdColorB, tdColorC),
59
- ),
60
- );
61
-
62
- const docAfterAddColumnAtOne = doc(
63
- table()(
64
- tr(tdColorA, tdEmpty, tdColorB, tdColorC),
65
- tr(tdColorA, tdEmpty, tdColorB, tdColorC),
66
- ),
67
- );
68
-
69
- const docAfterAddColumnAtTwo = doc(
70
- table()(
71
- tr(tdColorA, tdColorB, tdEmpty, tdColorC),
72
- tr(tdColorA, tdColorB, tdEmpty, tdColorC),
73
- ),
74
- );
75
-
76
- const docAfterRemoveColumnAtZero = doc(
77
- table()(tr(tdColorB, tdColorC), tr(tdColorB, tdColorC)),
78
- );
79
- const docAfterRemoveColumnAtOne = doc(
80
- table()(tr(tdColorA, tdColorC), tr(tdColorA, tdColorC)),
81
- );
82
- const docAfterRemoveColumnAtTwo = doc(
83
- table()(tr(tdColorA, tdColorB), tr(tdColorA, tdColorB)),
84
- );
85
-
86
- /**
87
- * Index for adding a column works like this
88
- * | colorA | colorB | colorC |
89
- * | colorA | colorB | colorC |
90
- * 0 1 2 3
91
- *
92
- * Index for remove a column works like this
93
- * | colorA | colorB | colorC |
94
- * | colorA | colorB | colorC |
95
- * 0 1 2
96
- */
97
- describe('AddColumnStep', () => {
98
- describe(`
99
- table 3x1
100
- | a |
101
- | a |
102
- | a |
103
- `, () => {
104
- let editorState: EditorState;
105
- let refs: Refs;
106
-
107
- const threeByOne = doc(
108
- p(''),
109
- '{table}',
110
- table()(tr(tdColorA), tr(tdColorA), tr(tdColorA)),
111
- );
112
-
113
- beforeEach(() => {
114
- ({ editorState, refs } = setup(threeByOne));
115
- });
116
-
117
- it('should delete the table when I tried to remove the last column', function () {
118
- editorState = editorState.apply(
119
- removeColumnAtFactory('table', 0)(editorState, refs),
120
- );
121
-
122
- expect(editorState.doc.toJSON()).toEqual(
123
- doc(p(''))(defaultSchema).toJSON(),
124
- );
125
- });
126
-
127
- it('should add the table after been removed it for a remove column', () => {
128
- editorState = applyAndInvertTransaction(editorState.doc)(
129
- removeColumnAtFactory('table', 0)(editorState, refs),
130
- editorState,
131
- );
132
- expect(editorState.doc.toJSON()).toEqual(
133
- threeByOne(defaultSchema).toJSON(),
134
- );
135
- });
136
-
137
- it('should remove the table after undoing the last column ', function () {
138
- const editorState = testHistory(
139
- threeByOne,
140
- addColumnAtFactory('table', 0),
141
- [removeColumnAtFactory('table', 1)],
142
- );
143
-
144
- expect(editorState.doc.toJSON()).toEqual(
145
- doc(p(''))(defaultSchema).toJSON(),
146
- );
147
- });
148
-
149
- it('should drop add column step when I remove the column', function () {
150
- const firstTransaction = removeColumnAtFactory('table', 0)(
151
- editorState,
152
- refs,
153
- );
154
- let addColumnStep: Step | null | undefined = addColumnAtFactory(
155
- 'table',
156
- 0,
157
- )(editorState, refs).steps[0];
158
-
159
- editorState = editorState.apply(firstTransaction);
160
-
161
- // Map the step with the transaction
162
- addColumnStep = addColumnStep.map(firstTransaction.mapping);
163
-
164
- // It should exist
165
- expect(addColumnStep).toBe(null);
166
- });
167
-
168
- it('should remove the column instead of table when I add a column just before', function () {
169
- const firstTransaction = addColumnAtFactory('table', 0)(
170
- editorState,
171
- refs,
172
- );
173
- let addColumnStep: Step | null | undefined = removeColumnAtFactory(
174
- 'table',
175
- 0,
176
- )(editorState, refs).steps[0];
177
-
178
- editorState = editorState.apply(firstTransaction);
179
-
180
- // Map the step with the transaction
181
- addColumnStep = addColumnStep.map(firstTransaction.mapping)!;
182
-
183
- editorState = editorState.apply(editorState.tr.step(addColumnStep));
184
-
185
- const expectedDoc = doc(
186
- p(''),
187
- '{table}',
188
- table()(tr(tdEmpty), tr(tdEmpty), tr(tdEmpty)),
189
- )(defaultSchema).toJSON();
190
-
191
- // Should keep the new created single column and remove the old one
192
- expect(editorState.doc.toJSON()).toEqual(expectedDoc);
193
- });
194
-
195
- it('should parse a json that we just generate', function () {
196
- const firstTransaction = removeColumnAtFactory('table', 0)(
197
- editorState,
198
- refs,
199
- );
200
-
201
- // Side effect is created on apply
202
- editorState.apply(firstTransaction);
203
-
204
- const removeTableStep = firstTransaction.steps[0];
205
-
206
- const removeTableStepFromJson = Step.fromJSON(
207
- editorState.schema,
208
- removeTableStep.toJSON(),
209
- )!;
210
-
211
- // Should keep the new created single column and remove the old one
212
- expect(
213
- editorState.apply(editorState.tr.step(removeTableStep)).doc,
214
- ).toEqual(
215
- editorState.apply(editorState.tr.step(removeTableStepFromJson)).doc,
216
- );
217
- });
218
-
219
- it('should add the removing table when I received a JSON', () => {
220
- ({ editorState } = setup(doc(p(''))));
221
- const removeLastRowInverted = Step.fromJSON(
222
- defaultSchema,
223
- removeLastRowInvertedJson,
224
- );
225
- editorState = editorState.apply(
226
- editorState.tr.step(removeLastRowInverted),
227
- );
228
-
229
- expect(editorState.doc.toJSON()).toEqual(
230
- threeByOne(defaultSchema).toJSON(),
231
- );
232
- });
233
-
234
- it('should remove the table when I received a JSON', () => {
235
- ({ editorState } = setup(threeByOne));
236
- const removeLastRowInverted = Step.fromJSON(
237
- defaultSchema,
238
- removeLastRowJson,
239
- );
240
- editorState = editorState.apply(
241
- editorState.tr.step(removeLastRowInverted),
242
- );
243
-
244
- expect(editorState.doc.toJSON()).toEqual(
245
- doc(p(''))(defaultSchema).toJSON(),
246
- );
247
- });
248
- });
249
-
250
- describe(`
251
- expand(table 2x3)
252
- `, () => {
253
- let editorState: EditorState;
254
- let refs: Refs;
255
-
256
- const expandTwoBythreeTable = doc(
257
- expand()(
258
- '{table}',
259
- table()(
260
- tr(tdColorA, tdColorB, tdColorC),
261
- tr(tdColorA, tdColorB, tdColorC),
262
- ),
263
- ),
264
- );
265
-
266
- const expandDocAfterAddColumnAtThree = doc(
267
- expand()(
268
- table()(
269
- tr(tdColorA, tdColorB, tdColorC, tdEmpty),
270
- tr(tdColorA, tdColorB, tdColorC, tdEmpty),
271
- ),
272
- ),
273
- );
274
-
275
- const expandDocAfterAddColumnAtZero = doc(
276
- expand()(
277
- table()(
278
- tr(tdEmpty, tdColorA, tdColorB, tdColorC),
279
- tr(tdEmpty, tdColorA, tdColorB, tdColorC),
280
- ),
281
- ),
282
- );
283
-
284
- const expandDocAfterAddColumnAtOne = doc(
285
- expand()(
286
- table()(
287
- tr(tdColorA, tdEmpty, tdColorB, tdColorC),
288
- tr(tdColorA, tdEmpty, tdColorB, tdColorC),
289
- ),
290
- ),
291
- );
292
-
293
- const expandDocAfterAddColumnAtTwo = doc(
294
- expand()(
295
- table()(
296
- tr(tdColorA, tdColorB, tdEmpty, tdColorC),
297
- tr(tdColorA, tdColorB, tdEmpty, tdColorC),
298
- ),
299
- ),
300
- );
301
-
302
- const expandDocAfterRemoveColumnAtZero = doc(
303
- expand()(table()(tr(tdColorB, tdColorC), tr(tdColorB, tdColorC))),
304
- );
305
- const expandDocAfterRemoveColumnAtOne = doc(
306
- expand()(table()(tr(tdColorA, tdColorC), tr(tdColorA, tdColorC))),
307
- );
308
- const expandDocAfterRemoveColumnAtTwo = doc(
309
- expand()(table()(tr(tdColorA, tdColorB), tr(tdColorA, tdColorB))),
310
- );
311
-
312
- beforeEach(() => {
313
- ({ editorState, refs } = setup(expandTwoBythreeTable));
314
- });
315
-
316
- describe('add a column', () => {
317
- it.each`
318
- column | expectedDoc
319
- ${0} | ${expandDocAfterAddColumnAtZero}
320
- ${1} | ${expandDocAfterAddColumnAtOne}
321
- ${2} | ${expandDocAfterAddColumnAtTwo}
322
- ${3} | ${expandDocAfterAddColumnAtThree}
323
- `(
324
- 'should add a column at $column of the table',
325
- ({ column, expectedDoc }) => {
326
- editorState = editorState.apply(
327
- addColumnAtFactory('table', column)(editorState, refs),
328
- );
329
-
330
- expect(editorState.doc.toJSON()).toEqual(
331
- expectedDoc(defaultSchema).toJSON(),
332
- );
333
- },
334
- );
335
- });
336
-
337
- describe('remove a column', () => {
338
- it.each`
339
- column | expectedDoc
340
- ${0} | ${expandDocAfterRemoveColumnAtZero}
341
- ${1} | ${expandDocAfterRemoveColumnAtOne}
342
- ${2} | ${expandDocAfterRemoveColumnAtTwo}
343
- `(
344
- 'should remove a column at $column of the table',
345
- ({ column, expectedDoc }) => {
346
- editorState = editorState.apply(
347
- removeColumnAtFactory('table', column)(editorState, refs),
348
- );
349
-
350
- expect(editorState.doc.toJSON()).toEqual(
351
- expectedDoc(defaultSchema).toJSON(),
352
- );
353
- },
354
- );
355
- });
356
- });
357
-
358
- describe(`
359
- table 2x3
360
- | a | b | c |
361
- | a | b | c |
362
- `, () => {
363
- let editorState: EditorState;
364
- let refs: Refs;
365
-
366
- beforeEach(() => {
367
- ({ editorState, refs } = setup(twoBythreeTable));
368
- });
369
-
370
- describe('add a column', () => {
371
- it.each`
372
- column | expectedDoc
373
- ${0} | ${docAfterAddColumnAtZero}
374
- ${1} | ${docAfterAddColumnAtOne}
375
- ${2} | ${docAfterAddColumnAtTwo}
376
- ${3} | ${docAfterAddColumnAtThree}
377
- `(
378
- 'should add a column at $column of the table',
379
- ({ column, expectedDoc }) => {
380
- editorState = editorState.apply(
381
- addColumnAtFactory('table', column)(editorState, refs),
382
- );
383
-
384
- expect(editorState.doc.toJSON()).toEqual(
385
- expectedDoc(defaultSchema).toJSON(),
386
- );
387
- },
388
- );
389
- });
390
-
391
- describe('remove a column', () => {
392
- it.each`
393
- column | expectedDoc
394
- ${0} | ${docAfterRemoveColumnAtZero}
395
- ${1} | ${docAfterRemoveColumnAtOne}
396
- ${2} | ${docAfterRemoveColumnAtTwo}
397
- `(
398
- 'should remove a column at $column of the table',
399
- ({ column, expectedDoc }) => {
400
- editorState = editorState.apply(
401
- removeColumnAtFactory('table', column)(editorState, refs),
402
- );
403
-
404
- expect(editorState.doc.toJSON()).toEqual(
405
- expectedDoc(defaultSchema).toJSON(),
406
- );
407
- },
408
- );
409
- });
410
-
411
- describe('invert', () => {
412
- let editorState: EditorState;
413
- let refs: Refs;
414
- let originalDoc: ProseMirrorNode;
415
-
416
- beforeEach(() => {
417
- ({ editorState, refs } = setup(
418
- doc(
419
- '{table}',
420
- table()(
421
- tr(
422
- createCellColorA(undefined, undefined, 'foo'),
423
- createCellColorB(undefined, undefined, 'barr'),
424
- createCellColorC(undefined, undefined, 'bazzz'),
425
- ),
426
- tr(
427
- createCellColorA(undefined, undefined, 'hello'),
428
- createCellColorB(undefined, undefined, 'my'),
429
- createCellColorC(undefined, undefined, 'very'),
430
- ),
431
- tr(
432
- createCellColorA(undefined, undefined, 'little'),
433
- createCellColorB(undefined, undefined, 'blue'),
434
- createCellColorC(undefined, undefined, 'earth'),
435
- ),
436
- ),
437
- ),
438
- ));
439
- originalDoc = editorState.doc;
440
- });
441
-
442
- it.each`
443
- description | setup
444
- ${'add column that was removed at the beginning with the same content'} | ${removeColumnAtFactory('table', 0)}
445
- ${'add column that was removed in the middle with the same content'} | ${removeColumnAtFactory('table', 1)}
446
- ${'add column that was removed at the end with the same content'} | ${removeColumnAtFactory('table', 2)}
447
- ${'remove a column that was added at the beginning'} | ${addColumnAtFactory('table', 0)}
448
- ${'remove a column that was added at the middle'} | ${addColumnAtFactory('table', 1)}
449
- ${'remove a column that was added at the almost end'} | ${addColumnAtFactory('table', 2)}
450
- ${'remove a column that was added at the end'} | ${addColumnAtFactory('table', 3)}
451
- `('should be able to $description', ({ setup }) => {
452
- const transaction = setup(editorState, refs);
453
- editorState = applyAndInvertTransaction(originalDoc)(
454
- transaction,
455
- editorState,
456
- );
457
- expect(editorState.doc.toJSON()).toEqual(originalDoc.toJSON());
458
- });
459
- });
460
-
461
- describe('mapping', () => {
462
- it.each<
463
- [string, DocBuilder, CreateTransaction, CreateTransaction, DocBuilder]
464
- >([
465
- [
466
- 'add the column in the correct position after adding text at the beginning',
467
- doc('{table}', table()(tr(tdColorA, tdColorB, tdColorC))),
468
- (editorState) => editorState.tr.insertText('foo', 0),
469
- addColumnAtFactory('table', 3),
470
- doc(p('foo'), table()(tr(tdColorA, tdColorB, tdColorC, tdEmpty))),
471
- ],
472
- [
473
- 'add the column in the correct position after adding a column at the beginning',
474
- doc('{table}', table()(tr(tdColorA, tdColorB, tdColorC))),
475
- addColumnAtFactory('table', 0),
476
- addColumnAtFactory('table', 3),
477
- doc(table()(tr(tdEmpty, tdColorA, tdColorB, tdColorC, tdEmpty))),
478
- ],
479
- [
480
- ' add the column in the correct position after removing the reference column',
481
- doc('{table}', table()(tr(tdColorA, tdColorB, tdColorC))),
482
- removeColumnAtFactory('table', 2),
483
- addColumnAtFactory('table', 3),
484
- doc(table()(tr(tdColorA, tdColorB, tdEmpty))),
485
- ],
486
- [
487
- 'add the column in the correct position after adding a column in the same position',
488
- doc('{table}', table()(tr(tdColorA, tdColorB, tdColorC))),
489
- addColumnAtFactory('table', 2),
490
- addColumnAtFactory('table', 2),
491
- doc(table()(tr(tdColorA, tdColorB, tdEmpty, tdEmpty, tdColorC))),
492
- ],
493
- [
494
- 'add the column in the correct position after adding text inside one column',
495
- doc('{table}', table()(tr(td()(p('foo{<>}')), tdColorB, tdColorC))),
496
- (editorState) => editorState.tr.insertText('bar'),
497
- addColumnAtFactory('table', 2),
498
- doc(table()(tr(td()(p('foobar')), tdColorB, tdEmpty, tdColorC))),
499
- ],
500
- ])(
501
- 'should %s',
502
- (_, originalDoc, firstTransaction, secondTransaction, expectedDoc) => {
503
- let { editorState, refs } = setup(originalDoc);
504
-
505
- const transaction = firstTransaction(editorState, refs);
506
- let addColumnStep: Step | null | undefined = secondTransaction(
507
- editorState,
508
- refs,
509
- ).steps[0];
510
-
511
- editorState = editorState.apply(transaction);
512
-
513
- // Map the step with the transaction
514
- addColumnStep = addColumnStep.map(transaction.mapping);
515
-
516
- // It should exist
517
- expect(addColumnStep).toBeTruthy();
518
-
519
- editorState = editorState.apply(editorState.tr.step(addColumnStep!));
520
-
521
- expect(editorState.doc.toJSON()).toEqual(
522
- expectedDoc(defaultSchema).toJSON(),
523
- );
524
- },
525
- );
526
- });
527
-
528
- describe('history plugin', () => {
529
- it('should be able to undo the right column', function () {
530
- const editorState = testHistory(
531
- twoBythreeTable,
532
- addColumnAtFactory('table', 2),
533
- [addColumnAtFactory('table', 1), addColumnAtFactory('table', 1)],
534
- );
535
-
536
- expect(editorState.doc.toJSON()).toEqual(
537
- doc(
538
- table()(
539
- tr(tdColorA, tdEmpty, tdEmpty, tdColorB, tdColorC),
540
- tr(tdColorA, tdEmpty, tdEmpty, tdColorB, tdColorC),
541
- ),
542
- )(defaultSchema).toJSON(),
543
- );
544
- });
545
- });
546
-
547
- describe('fromJson()', () => {
548
- it.each`
549
- column | jsonStep | expectedDoc
550
- ${0} | ${addColumnAtZeroJson} | ${docAfterAddColumnAtZero}
551
- ${1} | ${addColumnAtOneJson} | ${docAfterAddColumnAtOne}
552
- ${2} | ${addColumnAtTwoJson} | ${docAfterAddColumnAtTwo}
553
- ${3} | ${addColumnAtThreeJson} | ${docAfterAddColumnAtThree}
554
- `(
555
- 'should add a column at $column of the table',
556
- ({ jsonStep, expectedDoc }) => {
557
- const addColumnStep = Step.fromJSON(defaultSchema, jsonStep);
558
- editorState = editorState.apply(editorState.tr.step(addColumnStep));
559
-
560
- expect(editorState.doc.toJSON()).toEqual(
561
- expectedDoc(defaultSchema).toJSON(),
562
- );
563
- },
564
- );
565
-
566
- it.each`
567
- column | jsonStep | expectedDoc
568
- ${0} | ${removeColumnAtZeroJson} | ${docAfterRemoveColumnAtZero}
569
- ${1} | ${removeColumnAtOneJson} | ${docAfterRemoveColumnAtOne}
570
- ${2} | ${removeColumnAtTwoJson} | ${docAfterRemoveColumnAtTwo}
571
- `(
572
- 'should remove a column at $column of the table',
573
- ({ jsonStep, expectedDoc }) => {
574
- const addColumnStep = Step.fromJSON(defaultSchema, jsonStep);
575
- editorState = editorState.apply(editorState.tr.step(addColumnStep));
576
-
577
- expect(editorState.doc.toJSON()).toEqual(
578
- expectedDoc(defaultSchema).toJSON(),
579
- );
580
- },
581
- );
582
- });
583
-
584
- // Sanity check of the serialization process
585
- describe('serialize/deserialize', () => {
586
- it.each`
587
- column
588
- ${0}
589
- ${1}
590
- ${2}
591
- ${3}
592
- `(
593
- 'should serialize/deserialize a new column at $column',
594
- ({ column }) => {
595
- const { editorState, refs } = setup(twoBythreeTable);
596
- const addColumnStep = AddColumnStep.create(
597
- editorState.doc,
598
- refs['table'],
599
- column,
600
- false,
601
- );
602
-
603
- const json = addColumnStep.toJSON();
604
- const stepFromJson = Step.fromJSON(defaultSchema, json);
605
-
606
- expect(
607
- editorState.apply(editorState.tr.step(addColumnStep)).doc,
608
- ).toEqual(editorState.apply(editorState.tr.step(stepFromJson)).doc);
609
- },
610
- );
611
-
612
- it.each`
613
- column
614
- ${0}
615
- ${1}
616
- ${2}
617
- `(
618
- 'should serialize/deserialize remove a column at $column',
619
- ({ column }) => {
620
- const { editorState, refs } = setup(twoBythreeTable);
621
- const addColumnStep = AddColumnStep.create(
622
- editorState.doc,
623
- refs['table'],
624
- column,
625
- true,
626
- );
627
-
628
- const json = addColumnStep.toJSON();
629
- const stepFromJson = Step.fromJSON(defaultSchema, json);
630
-
631
- expect(
632
- editorState.apply(editorState.tr.step(addColumnStep)).doc,
633
- ).toEqual(editorState.apply(editorState.tr.step(stepFromJson)).doc);
634
- },
635
- );
636
- });
637
- });
638
- });