@atlaskit/adf-schema 28.1.11 → 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 (218) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/package.json +1 -1
  3. package/build/tsconfig.json +0 -18
  4. package/index.ts +0 -275
  5. package/src/__tests__/unit/json-schema/v1.ts +0 -55
  6. package/src/__tests__/unit/schema/create-schema.ts +0 -214
  7. package/src/__tests__/unit/schema/default-schema.ts +0 -192
  8. package/src/__tests__/unit/schema/marks/annotation.ts +0 -46
  9. package/src/__tests__/unit/schema/marks/border.ts +0 -76
  10. package/src/__tests__/unit/schema/marks/breakout.ts +0 -24
  11. package/src/__tests__/unit/schema/marks/code.ts +0 -44
  12. package/src/__tests__/unit/schema/marks/confluence-inline-comment.ts +0 -25
  13. package/src/__tests__/unit/schema/marks/data-consumer.ts +0 -52
  14. package/src/__tests__/unit/schema/marks/em.ts +0 -37
  15. package/src/__tests__/unit/schema/marks/link.ts +0 -188
  16. package/src/__tests__/unit/schema/marks/strike.ts +0 -37
  17. package/src/__tests__/unit/schema/marks/strong.ts +0 -43
  18. package/src/__tests__/unit/schema/marks/subsup.ts +0 -50
  19. package/src/__tests__/unit/schema/marks/text-color.ts +0 -61
  20. package/src/__tests__/unit/schema/marks/underline.ts +0 -36
  21. package/src/__tests__/unit/schema/nodes/_consts.ts +0 -964
  22. package/src/__tests__/unit/schema/nodes/block-card.ts +0 -184
  23. package/src/__tests__/unit/schema/nodes/blockquote.ts +0 -44
  24. package/src/__tests__/unit/schema/nodes/bodied-extension.ts +0 -101
  25. package/src/__tests__/unit/schema/nodes/code-block.ts +0 -221
  26. package/src/__tests__/unit/schema/nodes/confluence-unsupported-block.ts +0 -32
  27. package/src/__tests__/unit/schema/nodes/confluence-unsupported-inline.ts +0 -35
  28. package/src/__tests__/unit/schema/nodes/date.ts +0 -51
  29. package/src/__tests__/unit/schema/nodes/decision-item.ts +0 -46
  30. package/src/__tests__/unit/schema/nodes/decision-list.ts +0 -52
  31. package/src/__tests__/unit/schema/nodes/embed-card.ts +0 -60
  32. package/src/__tests__/unit/schema/nodes/emoji.ts +0 -71
  33. package/src/__tests__/unit/schema/nodes/expand.ts +0 -51
  34. package/src/__tests__/unit/schema/nodes/extension.ts +0 -101
  35. package/src/__tests__/unit/schema/nodes/hard-break.ts +0 -24
  36. package/src/__tests__/unit/schema/nodes/heading.ts +0 -56
  37. package/src/__tests__/unit/schema/nodes/image.ts +0 -32
  38. package/src/__tests__/unit/schema/nodes/inline-card.ts +0 -106
  39. package/src/__tests__/unit/schema/nodes/inline-extension.ts +0 -79
  40. package/src/__tests__/unit/schema/nodes/layout-column.ts +0 -54
  41. package/src/__tests__/unit/schema/nodes/layout-section.ts +0 -95
  42. package/src/__tests__/unit/schema/nodes/list-item.ts +0 -49
  43. package/src/__tests__/unit/schema/nodes/media-group.ts +0 -67
  44. package/src/__tests__/unit/schema/nodes/media-single.ts +0 -171
  45. package/src/__tests__/unit/schema/nodes/media.ts +0 -384
  46. package/src/__tests__/unit/schema/nodes/mention.ts +0 -115
  47. package/src/__tests__/unit/schema/nodes/nestedExpand.ts +0 -72
  48. package/src/__tests__/unit/schema/nodes/ordered-list.ts +0 -49
  49. package/src/__tests__/unit/schema/nodes/panel.ts +0 -180
  50. package/src/__tests__/unit/schema/nodes/paragraph.ts +0 -25
  51. package/src/__tests__/unit/schema/nodes/placeholder.ts +0 -46
  52. package/src/__tests__/unit/schema/nodes/rule.ts +0 -24
  53. package/src/__tests__/unit/schema/nodes/status.ts +0 -120
  54. package/src/__tests__/unit/schema/nodes/tableNodes.ts +0 -555
  55. package/src/__tests__/unit/schema/nodes/task-item.ts +0 -39
  56. package/src/__tests__/unit/schema/nodes/task-list.ts +0 -45
  57. package/src/__tests__/unit/schema/nodes/unknown-block.ts +0 -42
  58. package/src/__tests__/unit/schema/nodes/unsupported-block.ts +0 -42
  59. package/src/__tests__/unit/schema/nodes/unsupported-inline.ts +0 -38
  60. package/src/__tests__/unit/utils/colors.ts +0 -42
  61. package/src/__tests__/unit/utils/url.ts +0 -209
  62. package/src/index.ts +0 -297
  63. package/src/json-schema/index.ts +0 -2
  64. package/src/schema/bitbucket-schema.ts +0 -43
  65. package/src/schema/confluence-schema.ts +0 -76
  66. package/src/schema/create-schema.ts +0 -337
  67. package/src/schema/default-schema.ts +0 -180
  68. package/src/schema/groups.ts +0 -30
  69. package/src/schema/index.ts +0 -238
  70. package/src/schema/inline-nodes.ts +0 -9
  71. package/src/schema/jira-schema.ts +0 -158
  72. package/src/schema/marks/__tests__/unit/annotation.ts +0 -18
  73. package/src/schema/marks/alignment.ts +0 -48
  74. package/src/schema/marks/annotation.ts +0 -107
  75. package/src/schema/marks/border.ts +0 -74
  76. package/src/schema/marks/breakout.ts +0 -42
  77. package/src/schema/marks/code.ts +0 -45
  78. package/src/schema/marks/confluence-inline-comment.ts +0 -32
  79. package/src/schema/marks/data-consumer.ts +0 -100
  80. package/src/schema/marks/em.ts +0 -19
  81. package/src/schema/marks/fragment.ts +0 -77
  82. package/src/schema/marks/indentation.ts +0 -47
  83. package/src/schema/marks/index.ts +0 -61
  84. package/src/schema/marks/link.ts +0 -139
  85. package/src/schema/marks/strike.ts +0 -26
  86. package/src/schema/marks/strong.ts +0 -45
  87. package/src/schema/marks/subsup.ts +0 -53
  88. package/src/schema/marks/text-color.ts +0 -172
  89. package/src/schema/marks/type-ahead-query.ts +0 -22
  90. package/src/schema/marks/underline.ts +0 -24
  91. package/src/schema/marks/unsupported-mark.ts +0 -9
  92. package/src/schema/marks/unsupported-node-attributes.ts +0 -8
  93. package/src/schema/nodes/block-card.ts +0 -121
  94. package/src/schema/nodes/blockquote.ts +0 -25
  95. package/src/schema/nodes/bodied-extension.ts +0 -75
  96. package/src/schema/nodes/bullet-list.ts +0 -17
  97. package/src/schema/nodes/caption.ts +0 -51
  98. package/src/schema/nodes/code-block.ts +0 -176
  99. package/src/schema/nodes/confluence-jira-issue.ts +0 -43
  100. package/src/schema/nodes/confluence-unsupported-block.ts +0 -29
  101. package/src/schema/nodes/confluence-unsupported-inline.ts +0 -30
  102. package/src/schema/nodes/date.ts +0 -38
  103. package/src/schema/nodes/decision-item.ts +0 -50
  104. package/src/schema/nodes/decision-list.ts +0 -56
  105. package/src/schema/nodes/doc.ts +0 -30
  106. package/src/schema/nodes/embed-card.ts +0 -62
  107. package/src/schema/nodes/emoji.ts +0 -89
  108. package/src/schema/nodes/expand.ts +0 -101
  109. package/src/schema/nodes/extension.ts +0 -60
  110. package/src/schema/nodes/hard-break.ts +0 -21
  111. package/src/schema/nodes/heading.ts +0 -64
  112. package/src/schema/nodes/image.ts +0 -32
  113. package/src/schema/nodes/index.ts +0 -184
  114. package/src/schema/nodes/inline-card.ts +0 -70
  115. package/src/schema/nodes/inline-extension.ts +0 -57
  116. package/src/schema/nodes/layout-column.ts +0 -68
  117. package/src/schema/nodes/layout-section.ts +0 -93
  118. package/src/schema/nodes/list-item.ts +0 -13
  119. package/src/schema/nodes/media-group.ts +0 -44
  120. package/src/schema/nodes/media-inline.ts +0 -19
  121. package/src/schema/nodes/media-single.ts +0 -179
  122. package/src/schema/nodes/media.ts +0 -253
  123. package/src/schema/nodes/mention.ts +0 -86
  124. package/src/schema/nodes/nested-expand.ts +0 -77
  125. package/src/schema/nodes/ordered-list.ts +0 -62
  126. package/src/schema/nodes/panel.ts +0 -133
  127. package/src/schema/nodes/paragraph.ts +0 -79
  128. package/src/schema/nodes/placeholder.ts +0 -40
  129. package/src/schema/nodes/rule.ts +0 -17
  130. package/src/schema/nodes/status.ts +0 -58
  131. package/src/schema/nodes/tableNodes.ts +0 -478
  132. package/src/schema/nodes/task-item.ts +0 -51
  133. package/src/schema/nodes/task-list.ts +0 -61
  134. package/src/schema/nodes/text.ts +0 -19
  135. package/src/schema/nodes/types/block-content.ts +0 -51
  136. package/src/schema/nodes/types/extensions.ts +0 -36
  137. package/src/schema/nodes/types/inline-content.ts +0 -56
  138. package/src/schema/nodes/types/list.ts +0 -54
  139. package/src/schema/nodes/types/mark.ts +0 -16
  140. package/src/schema/nodes/types/non-nestable-block-content.ts +0 -39
  141. package/src/schema/nodes/types/rich-media-common.ts +0 -51
  142. package/src/schema/nodes/unknown-block.ts +0 -13
  143. package/src/schema/nodes/unsupported-block.ts +0 -28
  144. package/src/schema/nodes/unsupported-inline.ts +0 -27
  145. package/src/schema/unsupported.ts +0 -4
  146. package/src/steps/__tests__/unit/analytics.ts +0 -72
  147. package/src/steps/__tests__/unit/link-meta-step.ts +0 -64
  148. package/src/steps/__tests__/unit/override-document-step.ts +0 -174
  149. package/src/steps/__tests__/unit/set-attrs.ts +0 -71
  150. package/src/steps/analytics.ts +0 -189
  151. package/src/steps/link-meta-step.ts +0 -105
  152. package/src/steps/override-document-step.ts +0 -97
  153. package/src/steps/set-attrs.tsx +0 -74
  154. package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-0.json +0 -15
  155. package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-1.json +0 -15
  156. package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-2.json +0 -15
  157. package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-3.json +0 -15
  158. package/src/steps/table/__tests__/__fixtures__/basic/remove-column-at-0.json +0 -9
  159. package/src/steps/table/__tests__/__fixtures__/basic/remove-column-at-1.json +0 -9
  160. package/src/steps/table/__tests__/__fixtures__/basic/remove-column-at-2.json +0 -9
  161. package/src/steps/table/__tests__/__fixtures__/basic/remove-table/remove-last-row-inverted.json +0 -98
  162. package/src/steps/table/__tests__/__fixtures__/basic/remove-table/remove-last-row.json +0 -71
  163. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-0-inverted.json +0 -19
  164. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-0.json +0 -19
  165. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-1-inverted.json +0 -21
  166. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-1.json +0 -21
  167. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-2-inverted.json +0 -21
  168. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-2.json +0 -21
  169. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-3-inverted.json +0 -19
  170. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-3.json +0 -19
  171. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-0-inverted.json +0 -63
  172. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-0.json +0 -21
  173. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-1-inverted.json +0 -64
  174. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-1.json +0 -22
  175. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-2-inverted.json +0 -63
  176. package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-2.json +0 -21
  177. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-0-inverted.json +0 -19
  178. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-0.json +0 -19
  179. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-1-inverted.json +0 -19
  180. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-1.json +0 -19
  181. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-2-inverted.json +0 -19
  182. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-2.json +0 -19
  183. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-3-inverted.json +0 -19
  184. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-3.json +0 -19
  185. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-0-inverted.json +0 -52
  186. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-0.json +0 -38
  187. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-1-inverted.json +0 -52
  188. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-1.json +0 -38
  189. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-2-inverted.json +0 -25
  190. package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-2.json +0 -11
  191. package/src/steps/table/__tests__/_utils.ts +0 -102
  192. package/src/steps/table/__tests__/add-column-merge-columns.ts +0 -509
  193. package/src/steps/table/__tests__/add-column-merge-rows.ts +0 -466
  194. package/src/steps/table/__tests__/add-column.ts +0 -638
  195. package/src/steps/table/add-column.ts +0 -443
  196. package/src/steps/table/constants.ts +0 -4
  197. package/src/steps/table/sort-column.ts +0 -57
  198. package/src/steps/table/types.ts +0 -48
  199. package/src/steps/table/utils/cell-step.ts +0 -239
  200. package/src/steps/table/utils/cells-at-column.ts +0 -75
  201. package/src/steps/table/utils/find-column.ts +0 -90
  202. package/src/steps/table/utils/get-table-rect-from-doc.ts +0 -37
  203. package/src/steps/table/utils/side-effects/rows.ts +0 -327
  204. package/src/steps/table/utils/side-effects/side-effects.ts +0 -90
  205. package/src/steps/table/utils/side-effects/table.ts +0 -112
  206. package/src/steps/table/utils/side-effects/types.ts +0 -34
  207. package/src/steps/table/utils/table-map.ts +0 -28
  208. package/src/steps/type-ahead.ts +0 -100
  209. package/src/steps.ts +0 -16
  210. package/src/utils/colors.ts +0 -171
  211. package/src/utils/confluence/emoji.ts +0 -99
  212. package/src/utils/extensions.ts +0 -32
  213. package/src/utils/index.ts +0 -69
  214. package/src/utils/parseDOM.ts +0 -2
  215. package/src/utils/url.ts +0 -173
  216. package/src/utils/uuid.ts +0 -19
  217. package/src/version.json +0 -6
  218. package/tsconfig.json +0 -13
@@ -1,239 +0,0 @@
1
- import { Node as ProseMirrorNode } from '@atlaskit/editor-prosemirror/model';
2
- import { Cell } from './cells-at-column';
3
- import { CellStep } from '../types';
4
- import { Transform, StepMap } from '@atlaskit/editor-prosemirror/transform';
5
- import { TableRect } from '@atlaskit/editor-tables/table-map';
6
- import { addColSpan, removeColSpan } from '@atlaskit/editor-tables/utils';
7
- import { CellAttributesWithColSpan } from '@atlaskit/editor-tables/types';
8
- import { CellAttributes } from '../../../schema/nodes/tableNodes';
9
-
10
- const EmptyCellNodeSize = 4;
11
-
12
- function calculateRowsToSkip(attrs?: CellAttributes) {
13
- if (attrs && attrs.rowspan) {
14
- return attrs.rowspan - 1;
15
- }
16
-
17
- return 0;
18
- }
19
-
20
- /**
21
- * Given a cell step, this function has to do the specific transformation to executed that step.
22
- * It returns the applied cellStep and rows that needs to skip (because it was already handled).
23
- * @param tr
24
- * @param tableRect
25
- * @param cell
26
- * @param cellStep
27
- * @param isDelete
28
- * @param column
29
- */
30
- export function applyCellStep(
31
- tr: Transform,
32
- tableRect: TableRect,
33
- cell: Cell,
34
- cellStep: CellStep,
35
- isDelete: boolean,
36
- column: number,
37
- ): { tr: Transform; skipRows: number; cellStep: CellStep } {
38
- // Apply the merge actions,
39
- if (cellStep.mergeWith !== undefined) {
40
- let cellNode: ProseMirrorNode = tr.doc.nodeAt(
41
- tr.mapping.map(cellStep.mergeWith),
42
- )!;
43
-
44
- const columns =
45
- column -
46
- tableRect.map.colCount(cellStep.mergeWith - tableRect.tableStart);
47
- const cellAttrs = isDelete
48
- ? removeColSpan(cellNode.attrs as CellAttributesWithColSpan, columns)
49
- : addColSpan(cellNode.attrs as CellAttributesWithColSpan, columns);
50
-
51
- if (cellAttrs.colspan! > 0) {
52
- // When colspan is 0 should remove the cell
53
- tr.setNodeMarkup(
54
- tr.mapping.map(cellStep.mergeWith),
55
- undefined,
56
- cellAttrs,
57
- );
58
- return { tr, skipRows: calculateRowsToSkip(cellAttrs), cellStep };
59
- }
60
-
61
- // When the new colspan is 0, I need to change the operation to a delete operation
62
- // Update cellStep with the proper data
63
- cellStep.from = cellStep.mergeWith;
64
- cellStep.to = cellStep.from + cellNode.nodeSize;
65
- cellStep.mergeWith = undefined;
66
- }
67
-
68
- let skipRows = 0;
69
- // Modify temporary document
70
- if (isDelete) {
71
- let cellNode: ProseMirrorNode = tr.doc.nodeAt(
72
- tr.mapping.map(cellStep.from),
73
- )!;
74
- skipRows = calculateRowsToSkip(cellNode.attrs);
75
- tr.delete(tr.mapping.map(cellStep.from), tr.mapping.map(cellStep.to));
76
- } else {
77
- if (cellStep.newCell) {
78
- tr.insert(tr.mapping.map(cellStep.from), cellStep.newCell);
79
- skipRows = calculateRowsToSkip(cellStep.newCell.attrs);
80
- } else {
81
- tr.insert(tr.mapping.map(cellStep.from), cell.type!.createAndFill()!);
82
- }
83
- }
84
- return { tr, skipRows, cellStep };
85
- }
86
-
87
- /**
88
- * Given a cell step, this functions return un StepMap representing this action.
89
- * [position, oldSize, newSize]
90
- * @param cellStep
91
- * @param isDelete
92
- */
93
- export function getMapFromCellStep(
94
- cellStep: CellStep,
95
- isDelete: boolean,
96
- ): [number, number, number] {
97
- if (cellStep.mergeWith !== undefined) {
98
- return [cellStep.mergeWith, 1, 1];
99
- }
100
-
101
- if (isDelete) {
102
- return [cellStep.from, cellStep.to - cellStep.from, 0];
103
- } else {
104
- if (cellStep.newCell) {
105
- return [cellStep.from, 0, cellStep.newCell.nodeSize];
106
- }
107
- return [cellStep.from, 0, EmptyCellNodeSize];
108
- }
109
- }
110
-
111
- /**
112
- * Helper to calculate the offset of the inverted cells.
113
- * When you delete consecutive rows in a single step, the position in the generated document
114
- * are skipped by the all the changes except your own. (StepMap.map is not valid)
115
- * @param map
116
- * @param cellStep
117
- * @param isDelete
118
- */
119
- function getOffset(
120
- map: StepMap,
121
- cellStep: CellStep,
122
- isDelete: boolean,
123
- ): number {
124
- if (isDelete) {
125
- return map.map(cellStep.from) - cellStep.from;
126
- }
127
- const [, oldSize, newSize] = getMapFromCellStep(cellStep, isDelete);
128
- return map.map(cellStep.from) - cellStep.from - (newSize - oldSize);
129
- }
130
-
131
- /**
132
- * Given a cell step, this function invert that step.
133
- * @param doc
134
- * @param getTableRectAndColumn
135
- * @param cellStep
136
- * @param isDelete
137
- * @param stepMap
138
- */
139
- export function invertCellStep(
140
- doc: ProseMirrorNode,
141
- getTableRectAndColumn: () => { rect: TableRect; column: number },
142
- cellStep: CellStep,
143
- isDelete: boolean,
144
- stepMap: StepMap,
145
- ): CellStep {
146
- /**
147
- * We need a correct map when a cell is added
148
- * We need the normal map position minus the size of the cell you added it. Why?
149
- * Having a table 3x3 and we add a new column at 2 creates this ranges
150
- * [
151
- * 10, 0, 4,
152
- * 20, 0, 4,
153
- * 30, 0, 4,
154
- * ]
155
- * Where:
156
- * * [10, 20, 30] are the original cell positions where we add the cells
157
- * * [0, 0, 0] are the old size. We are adding new cells, so it's always zero
158
- * * [4, 4, 4] are the new size. In this case, we are adding empty cell and has size 4, this will be different for prefill cells.
159
- * In the document generated the cells that I want to delete (if I invert this step) are [10, 24, 38]
160
- * this is calculated in the given way
161
- * * Map the position using this step mapping function, this will return the cell in the next column
162
- * * Remove the diff (4 - 0 in this case) of the current position.
163
- * For a delete action this not happen, it will always return the right value
164
- */
165
- const offset = getOffset(stepMap, cellStep, isDelete);
166
- const newCellStepInfo: CellStep = {
167
- ...cellStep,
168
-
169
- // Map the position to position of the generated document
170
- from: cellStep.from + offset,
171
- to: cellStep.to + offset,
172
- };
173
-
174
- if (cellStep.mergeWith !== undefined) {
175
- newCellStepInfo.mergeWith = cellStep.mergeWith + offset;
176
- }
177
-
178
- if (isDelete) {
179
- // Add the removed cell as the new cell of the inverted step
180
- const removedCell = doc.nodeAt(cellStep.from)!;
181
- newCellStepInfo.newCell = removedCell.copy(removedCell.content);
182
-
183
- // When we delete a column we can end in a position that doesnt represent the right column.
184
- // This only happens on merged cell that ends in the deleted column.
185
- // We need to remap this position to the "next" cell (AKA cellStep.to)
186
- const { column, rect } = getTableRectAndColumn();
187
- if (column < rect.map.width) {
188
- const isAtTheEnd =
189
- rect.map.colCount(cellStep.from - rect.tableStart) +
190
- removedCell.attrs.colspan -
191
- 1 ===
192
- column;
193
- if (cellStep.mergeWith !== undefined && isAtTheEnd) {
194
- newCellStepInfo.mergeWith = newCellStepInfo.from;
195
- newCellStepInfo.from = newCellStepInfo.to;
196
- }
197
- }
198
- }
199
-
200
- return newCellStepInfo;
201
- }
202
-
203
- /**
204
- * Create a cell step based on the current cell and operation (add/delete)
205
- * @param cell
206
- * @param column
207
- * @param isDelete
208
- * @param previousCellStep
209
- */
210
- export function createCellStep(
211
- cell: Cell,
212
- column: number,
213
- isDelete: boolean,
214
- previousCellStep?: CellStep,
215
- ): CellStep {
216
- const newCellStepInfo: CellStep = {
217
- from: cell.from,
218
- to: cell.to,
219
- };
220
-
221
- if (cell.hasMergedCells) {
222
- // Check what column has to merge
223
- if (column !== cell.col || isDelete) {
224
- newCellStepInfo.mergeWith = cell.from;
225
- }
226
- }
227
-
228
- if (previousCellStep) {
229
- if (previousCellStep.mergeWith !== undefined) {
230
- newCellStepInfo.mergeWith = previousCellStep.mergeWith;
231
- }
232
-
233
- if (previousCellStep.newCell) {
234
- newCellStepInfo.newCell = previousCellStep.newCell;
235
- }
236
- }
237
-
238
- return newCellStepInfo;
239
- }
@@ -1,75 +0,0 @@
1
- import { TableRect } from '@atlaskit/editor-tables/table-map';
2
- import { columnIsHeader, tableNodeTypes } from '@atlaskit/editor-tables/utils';
3
- import { NodeType, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
- import { CellAttributes } from '../../../schema/nodes/tableNodes';
5
- import { getCellIndex, hasMergedColumns, isRootRow } from './table-map';
6
-
7
- export interface Cell {
8
- from: number;
9
- to: number;
10
- row: number;
11
- col: number;
12
- attrs?: CellAttributes;
13
- hasMergedCells: boolean;
14
- type: NodeType;
15
- }
16
-
17
- /**
18
- * Helper to have a consistent way to iterate for all the cells in a column.
19
- * You can skip rows by passing the rows to skipped in the next arguments.
20
- * For example: `iter.next(1)` to skip the next row
21
- * @param rect
22
- * @param col
23
- */
24
- export function* cellsAtColumn(
25
- rect: TableRect,
26
- col: number,
27
- ): Generator<Cell, void, number | undefined> {
28
- const { map, tableStart, table } = rect;
29
-
30
- let refColumn: number | null = col > 0 ? -1 : 0;
31
- if (columnIsHeader(map, table, col + refColumn)) {
32
- refColumn = col === 0 || col === map.width ? null : 0;
33
- }
34
-
35
- for (let row = 0; row < map.height; row++) {
36
- let index = getCellIndex(rect.map, row, col);
37
- let pos = map.map[index];
38
-
39
- // We only consider to has merged cell to the first cell in a rowspan.
40
- const hasMergedCells =
41
- hasMergedColumns(rect.map, row, col) && isRootRow(rect.map, row, col);
42
-
43
- // If this position falls inside a col-spanning cell
44
- let type =
45
- refColumn == null
46
- ? tableNodeTypes(table.type.schema).cell
47
- : table.nodeAt(map.map[index + refColumn])!.type;
48
-
49
- if (!hasMergedCells) {
50
- pos = map.positionAt(row, col, table);
51
- }
52
- let cell = table.nodeAt(pos) as PMNode;
53
-
54
- const cellInfo: Cell = {
55
- from: tableStart + pos,
56
- to: tableStart + pos,
57
- row,
58
- col: hasMergedCells ? map.colCount(pos) : col,
59
- type,
60
- hasMergedCells,
61
- };
62
-
63
- if (cell) {
64
- cellInfo.attrs = cell.attrs as CellAttributes;
65
- cellInfo.to = tableStart + pos + cell!.nodeSize;
66
- }
67
-
68
- // We let the consumer to pass the rows that we want to skip
69
- const skippedRows: number | undefined = yield cellInfo;
70
-
71
- if (skippedRows && skippedRows > 0) {
72
- row += skippedRows;
73
- }
74
- }
75
- }
@@ -1,90 +0,0 @@
1
- import { TableRect } from '@atlaskit/editor-tables/table-map';
2
- import { CellStep, ColumnInfo } from '../types';
3
-
4
- /**
5
- * Try to find the right column based on the cell steps in column info..
6
- * @param columnInfo - Map of cell positions sorted from lower to greather
7
- * @param rect - map rect
8
- */
9
- export function findColumn(
10
- columnInfo: ColumnInfo,
11
- rect: TableRect,
12
- ): number | null {
13
- /**
14
- * Algorithm explained
15
- * Given a table like this:
16
- * | 5 | 10 |
17
- * | 15 | 20 |
18
- * | 25 | 30 | 35 |
19
- * Represented by a table map like this:
20
- * rect.map = [5, 10, 10,
21
- * 15, 15, 20,
22
- * 25, 30, 35]
23
- * And a have this inputs:
24
- * columnInfo[].from = [10, 15, 30]
25
- *
26
- * Algorithm:
27
- * * Initial state
28
- * start = 0;
29
- * end = 2 (rect.width - 1 === 3 - 1)
30
- * * Iterate until find first cell position
31
- * start = 1
32
- * end = 2 (min(start column + colspan - 1, start column + end column))
33
- * * Iterate until find second cell position
34
- * start = 1
35
- * end = 1
36
- * * Start === end return 1
37
- */
38
-
39
- // Initial range (start and end column) to search for each row
40
- let [start, end] = [0, rect.map.width - 1];
41
-
42
- const iter = columnInfo.values();
43
- let next = iter.next();
44
-
45
- // Iterate for each row
46
- for (let row = 0; row < rect.map.height; row++) {
47
- if (next.done) {
48
- break;
49
- }
50
- // Iterate for the column. Starting with the current start range
51
- for (let col = start; col <= end; col++) {
52
- const i = row * rect.map.width + col;
53
- const cell = rect.map.map[i];
54
- const cellInfo = (next.value as CellStep).from - rect.tableStart;
55
-
56
- // When cell is found update range with the new values
57
- if (cell === cellInfo) {
58
- start = col; // Start column will be the current column
59
- // Try to find the end column. End column will be different that start when has merged cells.
60
- const endIndex = end - start + i;
61
- for (let j = i; j <= endIndex; j++) {
62
- if (rect.map.map[j] !== cell) {
63
- break;
64
- }
65
-
66
- // merged columns
67
- end = start + j - i; // Update the end column with the new position
68
- }
69
- if (start === end) {
70
- // We found the right column only when start and end columns are the same.
71
- return start;
72
- }
73
- next = iter.next();
74
- break;
75
- }
76
-
77
- // Sometimes I want to find a column at the end of the table (It doesn't exist, but we can add a new cell there).
78
- // This is represented by the end position of the last cell in the column.
79
- // In this case return, table width
80
- if (col === rect.map.width - 1) {
81
- const cellNode = rect.table.nodeAt(cell)!;
82
- if (cell + cellNode.nodeSize === cellInfo) {
83
- return rect.map.width;
84
- }
85
- }
86
- }
87
- }
88
-
89
- return null;
90
- }
@@ -1,37 +0,0 @@
1
- import { Node as ProseMirrorNode } from '@atlaskit/editor-prosemirror/model';
2
- import { TableRect, TableMap } from '@atlaskit/editor-tables/table-map';
3
-
4
- /**
5
- * Util to get the table rect from the docs
6
- * @param doc
7
- * @param tablePos
8
- */
9
- export function getTableRectFromDoc(
10
- doc: ProseMirrorNode,
11
- tablePos: number,
12
- ): TableRect {
13
- const table = doc.nodeAt(tablePos);
14
-
15
- // Check for table existence
16
- if (!table || table.type.name !== 'table') {
17
- throw new Error(`No table at position "${tablePos}".`);
18
- }
19
-
20
- // Create transform base on the doc
21
- const map = TableMap.get(table);
22
- const $table = doc.resolve(tablePos);
23
- // Nested tables start position might differ from the original position
24
- const start = $table.start($table.depth + 1);
25
-
26
- return {
27
- map,
28
- table: table,
29
- tableStart: start,
30
-
31
- // Default to zero
32
- bottom: 0,
33
- left: 0,
34
- right: 0,
35
- top: 0,
36
- };
37
- }