@atlaskit/adf-schema 29.2.0 → 30.0.1

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 (59) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/steps.js +0 -21
  3. package/dist/es2019/steps.js +0 -3
  4. package/dist/esm/steps.js +0 -3
  5. package/dist/types/schema/nodes/tableNodes.d.ts +6 -2
  6. package/dist/types/steps.d.ts +0 -4
  7. package/package.json +1 -3
  8. package/dist/cjs/steps/table/add-column.js +0 -381
  9. package/dist/cjs/steps/table/constants.js +0 -12
  10. package/dist/cjs/steps/table/sort-column.js +0 -68
  11. package/dist/cjs/steps/table/types.js +0 -5
  12. package/dist/cjs/steps/table/utils/cell-step.js +0 -202
  13. package/dist/cjs/steps/table/utils/cells-at-column.js +0 -73
  14. package/dist/cjs/steps/table/utils/find-column.js +0 -90
  15. package/dist/cjs/steps/table/utils/get-table-rect-from-doc.js +0 -36
  16. package/dist/cjs/steps/table/utils/side-effects/rows.js +0 -315
  17. package/dist/cjs/steps/table/utils/side-effects/side-effects.js +0 -83
  18. package/dist/cjs/steps/table/utils/side-effects/table.js +0 -110
  19. package/dist/cjs/steps/table/utils/side-effects/types.js +0 -5
  20. package/dist/cjs/steps/table/utils/table-map.js +0 -30
  21. package/dist/es2019/steps/table/add-column.js +0 -306
  22. package/dist/es2019/steps/table/constants.js +0 -5
  23. package/dist/es2019/steps/table/sort-column.js +0 -34
  24. package/dist/es2019/steps/table/types.js +0 -1
  25. package/dist/es2019/steps/table/utils/cell-step.js +0 -187
  26. package/dist/es2019/steps/table/utils/cells-at-column.js +0 -52
  27. package/dist/es2019/steps/table/utils/find-column.js +0 -83
  28. package/dist/es2019/steps/table/utils/get-table-rect-from-doc.js +0 -31
  29. package/dist/es2019/steps/table/utils/side-effects/rows.js +0 -257
  30. package/dist/es2019/steps/table/utils/side-effects/side-effects.js +0 -60
  31. package/dist/es2019/steps/table/utils/side-effects/table.js +0 -82
  32. package/dist/es2019/steps/table/utils/side-effects/types.js +0 -1
  33. package/dist/es2019/steps/table/utils/table-map.js +0 -19
  34. package/dist/esm/steps/table/add-column.js +0 -373
  35. package/dist/esm/steps/table/constants.js +0 -5
  36. package/dist/esm/steps/table/sort-column.js +0 -60
  37. package/dist/esm/steps/table/types.js +0 -1
  38. package/dist/esm/steps/table/utils/cell-step.js +0 -192
  39. package/dist/esm/steps/table/utils/cells-at-column.js +0 -66
  40. package/dist/esm/steps/table/utils/find-column.js +0 -84
  41. package/dist/esm/steps/table/utils/get-table-rect-from-doc.js +0 -31
  42. package/dist/esm/steps/table/utils/side-effects/rows.js +0 -307
  43. package/dist/esm/steps/table/utils/side-effects/side-effects.js +0 -75
  44. package/dist/esm/steps/table/utils/side-effects/table.js +0 -102
  45. package/dist/esm/steps/table/utils/side-effects/types.js +0 -1
  46. package/dist/esm/steps/table/utils/table-map.js +0 -19
  47. package/dist/types/steps/table/add-column.d.ts +0 -88
  48. package/dist/types/steps/table/constants.d.ts +0 -4
  49. package/dist/types/steps/table/sort-column.d.ts +0 -18
  50. package/dist/types/steps/table/types.d.ts +0 -39
  51. package/dist/types/steps/table/utils/cell-step.d.ts +0 -47
  52. package/dist/types/steps/table/utils/cells-at-column.d.ts +0 -20
  53. package/dist/types/steps/table/utils/find-column.d.ts +0 -8
  54. package/dist/types/steps/table/utils/get-table-rect-from-doc.d.ts +0 -8
  55. package/dist/types/steps/table/utils/side-effects/rows.d.ts +0 -25
  56. package/dist/types/steps/table/utils/side-effects/side-effects.d.ts +0 -15
  57. package/dist/types/steps/table/utils/side-effects/table.d.ts +0 -16
  58. package/dist/types/steps/table/utils/side-effects/types.d.ts +0 -33
  59. package/dist/types/steps/table/utils/table-map.d.ts +0 -6
@@ -1,31 +0,0 @@
1
- import { TableMap } from '@atlaskit/editor-tables/table-map';
2
-
3
- /**
4
- * Util to get the table rect from the docs
5
- * @param doc
6
- * @param tablePos
7
- */
8
- export function getTableRectFromDoc(doc, tablePos) {
9
- const table = doc.nodeAt(tablePos);
10
-
11
- // Check for table existence
12
- if (!table || table.type.name !== 'table') {
13
- throw new Error(`No table at position "${tablePos}".`);
14
- }
15
-
16
- // Create transform base on the doc
17
- const map = TableMap.get(table);
18
- const $table = doc.resolve(tablePos);
19
- // Nested tables start position might differ from the original position
20
- const start = $table.start($table.depth + 1);
21
- return {
22
- map,
23
- table: table,
24
- tableStart: start,
25
- // Default to zero
26
- bottom: 0,
27
- left: 0,
28
- right: 0,
29
- top: 0
30
- };
31
- }
@@ -1,257 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import { hasMergedColumns } from '../table-map';
3
- function mergedRanges(first, second) {
4
- const newRanges = [];
5
- const firstLength = first.length;
6
- const secondLength = second.length;
7
- let i = 0;
8
- let j = 0;
9
- while (i < firstLength && j < secondLength) {
10
- if (first[i] < second[j]) {
11
- newRanges.push(first[i], first[i + 1], first[i + 2]);
12
- i += 3;
13
- } else {
14
- newRanges.push(second[j], second[j + 1], second[j + 2]);
15
- j += 3;
16
- }
17
- }
18
- if (i < firstLength) {
19
- newRanges.push(...first.slice(i));
20
- }
21
- if (j < secondLength) {
22
- newRanges.push(...second.slice(i));
23
- }
24
- return newRanges;
25
- }
26
- function increaseRowSpan(tr, rect, row) {
27
- const {
28
- map,
29
- tableStart
30
- } = rect;
31
- for (let col = 0; col < map.width; col++) {
32
- let index = row * map.width + col;
33
- let pos = map.map[index];
34
- const mappedPos = tr.mapping.map(pos + tableStart);
35
- let attrs = tr.doc.nodeAt(mappedPos).attrs;
36
- tr.setNodeMarkup(mappedPos, undefined, {
37
- ...attrs,
38
- rowspan: attrs.rowspan + 1
39
- });
40
- col += attrs.colspan - 1;
41
- }
42
- }
43
- function decreaseRowspan(tr, rect, row, colToRemove) {
44
- let skipRows = 0;
45
- const {
46
- map,
47
- table,
48
- tableStart
49
- } = rect;
50
- for (let col = 0; col < map.width; col++) {
51
- let index = row * map.width + col;
52
- let pos = map.map[index];
53
- if (row > 0 && pos === map.map[index - map.width]) {
54
- // If this cell starts in the row above, simply reduce its rowspan
55
- const mappedPos = tr.mapping.map(pos + tableStart);
56
- let attrs = tr.doc.nodeAt(mappedPos).attrs;
57
- tr.setNodeMarkup(mappedPos, undefined, {
58
- ...attrs,
59
- rowspan: attrs.rowspan - 1
60
- });
61
- col += attrs.colspan - 1;
62
- } else if (col === colToRemove) {
63
- skipRows = table.nodeAt(pos).attrs.rowspan - 1;
64
- }
65
- }
66
- return skipRows;
67
- }
68
- function isLastCellInRow(rect, row, col) {
69
- const rowNode = rect.table.child(row);
70
- if (!rowNode) {
71
- return false;
72
- }
73
- return rowNode.childCount === 1 && !hasMergedColumns(rect.map, row, col);
74
- }
75
- function removeRowWithLastCell(tr, rect, row, _col) {
76
- // Get row pos
77
- let from = rect.tableStart;
78
- for (let i = 0; i < row; i++) {
79
- from += rect.table.child(i).nodeSize;
80
- }
81
- const rowNode = rect.table.child(row);
82
- let to = from + rowNode.nodeSize;
83
-
84
- // Create sideEffect and delete the row
85
- // We store original row position before modifications
86
- tr.delete(tr.mapping.map(from), tr.mapping.map(to));
87
-
88
- // Change rowspan of all cells except current col and get the rows to skip
89
- const skipRows = decreaseRowspan(tr, rect, row, _col);
90
- return {
91
- skipRows,
92
- row: {
93
- from,
94
- to,
95
- rowNode: rowNode.copy(rowNode.content)
96
- }
97
- };
98
- }
99
- function addRow(tr, rect, prevRow, rowSideEffect) {
100
- const cellNode = rowSideEffect.rowNode.child(0);
101
- tr.insert(tr.mapping.map(rowSideEffect.from), rowSideEffect.rowNode);
102
- increaseRowSpan(tr, rect, prevRow);
103
- return cellNode.attrs.rowspan - 1;
104
- }
105
- export class RowsSideEffectHandler {
106
- constructor(rowsSideEffect) {
107
- _defineProperty(this, "deleteHandler", () => {
108
- const newRows = [];
109
- return {
110
- handle: (tr, rect, row, col, cell) => {
111
- if (!isLastCellInRow(rect, row, col)) {
112
- return {
113
- handled: false
114
- };
115
- }
116
- const {
117
- row: rowSideEffect,
118
- skipRows
119
- } = removeRowWithLastCell(tr, rect, row, col);
120
- newRows.push(rowSideEffect);
121
- return {
122
- handled: true,
123
- skipRows: skipRows
124
- };
125
- },
126
- end: () => {
127
- if (newRows.length > 0) {
128
- this.rows = newRows;
129
- } else {
130
- this.rows = undefined;
131
- }
132
- }
133
- };
134
- });
135
- _defineProperty(this, "addHandler", () => {
136
- let lastCellFrom = 0;
137
- let i = 0;
138
- return {
139
- handle: (tr, rect, row, col, cell) => {
140
- // // If not sideEffects stored return;
141
- if (!this.rows || i >= this.rows.length) {
142
- return {
143
- handled: false
144
- };
145
- }
146
-
147
- // Next row to add;
148
- let skipRows;
149
- let nextRow;
150
- while ((nextRow = this.rows[i]) && nextRow.from > lastCellFrom && nextRow.from < cell.from) {
151
- // I am in between of the previous and next row in the table;
152
- skipRows = addRow(tr, rect, row - 1, nextRow);
153
- i++;
154
- }
155
- lastCellFrom = cell.from;
156
- if (!skipRows || skipRows === 0) {
157
- return {
158
- handled: false
159
- };
160
- }
161
- return {
162
- handled: true,
163
- skipRows: skipRows - 1
164
- };
165
- },
166
- end: (tr, rect, col) => {
167
- if (!this.rows || i >= this.rows.length) {
168
- return;
169
- }
170
-
171
- // Add rows at the end of the table
172
- let nextRow;
173
- while (nextRow = this.rows[i]) {
174
- addRow(tr, rect, rect.map.height - 1, nextRow);
175
- i++;
176
- }
177
- }
178
- };
179
- });
180
- this.rows = rowsSideEffect;
181
- }
182
- start(isDelete) {
183
- if (isDelete) {
184
- return this.deleteHandler();
185
- }
186
- return this.addHandler();
187
- }
188
- addRowRanges(ranges, isDelete) {
189
- if (!this.rows) {
190
- return ranges;
191
- }
192
- const rowRanges = [];
193
- for (const row of this.rows) {
194
- const {
195
- from,
196
- to
197
- } = row;
198
- if (isDelete) {
199
- rowRanges.push(from, to - from, 0);
200
- } else {
201
- rowRanges.push(from, 0, to - from);
202
- }
203
- }
204
-
205
- // Merged ranges
206
- return mergedRanges(ranges, rowRanges);
207
- }
208
- map(mapping) {
209
- return [];
210
- }
211
- invert(originalDoc, isDelete, map) {
212
- if (!this.rows) {
213
- return;
214
- }
215
- const invertedRows = [];
216
- for (const row of this.rows) {
217
- if (isDelete) {
218
- // Moving from delete to add keep the inverted rows + offset
219
- let offset = map.map(row.from) - row.from;
220
- invertedRows.push({
221
- ...row,
222
- from: row.from + offset,
223
- to: row.from + offset
224
- });
225
- } else {
226
- // Moving from add to delete keep
227
- // TODO: I think we need to add the respective cell into the cellSteps...... not sure....
228
- }
229
- }
230
- return invertedRows;
231
- }
232
- toJSON() {
233
- if (!this.rows) {
234
- return;
235
- }
236
- const rowsInJson = [];
237
- for (const row of this.rows) {
238
- rowsInJson.push({
239
- from: row.from,
240
- to: row.to,
241
- rowNode: row.rowNode.toJSON()
242
- });
243
- }
244
- return rowsInJson;
245
- }
246
- static fromJSON(schema, json) {
247
- const rowSideEffects = [];
248
- for (const row of json) {
249
- rowSideEffects.push({
250
- from: row.from,
251
- to: row.to,
252
- rowNode: schema.nodeFromJSON(row.rowNode)
253
- });
254
- }
255
- return rowSideEffects;
256
- }
257
- }
@@ -1,60 +0,0 @@
1
- import { TableSideEffectHandler } from './table';
2
- import { RowsSideEffectHandler } from './rows';
3
- export class SideEffectsHandler {
4
- constructor(sideEffects) {
5
- this.table = new TableSideEffectHandler(sideEffects && sideEffects.table);
6
- this.rows = new RowsSideEffectHandler(sideEffects && sideEffects.rows);
7
- }
8
- getTableMap(isDelete) {
9
- return this.table.getTableMap(isDelete);
10
- }
11
- map(mapping) {
12
- const sideEffects = {};
13
- const tableSideEffect = this.table.map(mapping);
14
- const rowsSideEffect = this.rows.map(mapping);
15
- if (tableSideEffect) {
16
- sideEffects.table = tableSideEffect;
17
- }
18
- if (rowsSideEffect) {
19
- sideEffects.rows = rowsSideEffect;
20
- }
21
- return sideEffects;
22
- }
23
- invert(originalDoc, isDelete, map) {
24
- const sideEffects = {};
25
- const tableSideEffect = this.table.invert(originalDoc);
26
- if (tableSideEffect) {
27
- sideEffects.table = tableSideEffect;
28
- }
29
- const rowsSideEffect = this.rows.invert(originalDoc, isDelete, map);
30
- if (rowsSideEffect) {
31
- sideEffects.rows = rowsSideEffect;
32
- }
33
- return sideEffects;
34
- }
35
- toJSON() {
36
- const tableSideEffectJson = this.table.toJSON();
37
- const rowsSideEffectJson = this.rows.toJSON();
38
- if (!tableSideEffectJson && !rowsSideEffectJson) {
39
- return;
40
- }
41
- const sideEffectsJSON = {};
42
- if (tableSideEffectJson) {
43
- sideEffectsJSON.table = tableSideEffectJson;
44
- }
45
- if (rowsSideEffectJson) {
46
- sideEffectsJSON.rows = rowsSideEffectJson;
47
- }
48
- return sideEffectsJSON;
49
- }
50
- static fromJSON(schema, json) {
51
- const sideEffects = {};
52
- if (json.table) {
53
- sideEffects.table = TableSideEffectHandler.fromJSON(schema, json.table);
54
- }
55
- if (json.rows) {
56
- sideEffects.rows = RowsSideEffectHandler.fromJSON(schema, json.rows);
57
- }
58
- return sideEffects;
59
- }
60
- }
@@ -1,82 +0,0 @@
1
- import { StepMap } from '@atlaskit/editor-prosemirror/transform';
2
- export class TableSideEffectHandler {
3
- constructor(tableSideEffect) {
4
- if (tableSideEffect) {
5
- this.table = tableSideEffect;
6
- }
7
- }
8
- addTableSideEffect(from, to, node) {
9
- this.table = {
10
- from,
11
- to,
12
- node
13
- };
14
- }
15
- handleAddTable(tr, isDelete) {
16
- if (isDelete || !this.table) {
17
- return false;
18
- }
19
- tr.insert(this.table.from, this.table.node);
20
- return true;
21
- }
22
- handleRemoveTable(tr, tablePos, tableRect, column, isDelete) {
23
- if (isDelete && tableRect.map.width === 1 && column === 0) {
24
- // Add side effect
25
- this.addTableSideEffect(tablePos, tablePos + tableRect.table.nodeSize, tableRect.table.copy(tableRect.table.content));
26
- tr.delete(tablePos, tablePos + tableRect.table.nodeSize);
27
- return true;
28
- }
29
- return false;
30
- }
31
- getTableMap(isDelete) {
32
- if (!this.table) {
33
- return;
34
- }
35
- const {
36
- from,
37
- to
38
- } = this.table;
39
- if (isDelete) {
40
- return new StepMap([from, to - from, 0]);
41
- }
42
- return new StepMap([from, 0, to - from]);
43
- }
44
- map(mapping) {
45
- if (!this.table) {
46
- return;
47
- }
48
- return {
49
- from: mapping.map(this.table.from),
50
- to: mapping.map(this.table.to),
51
- node: this.table.node
52
- };
53
- }
54
- invert(doc) {
55
- if (!this.table) {
56
- return;
57
- }
58
- const tableNode = doc.nodeAt(this.table.from);
59
- return {
60
- from: this.table.from,
61
- to: this.table.from + tableNode.nodeSize,
62
- node: tableNode.copy(tableNode.content)
63
- };
64
- }
65
- toJSON() {
66
- if (!this.table) {
67
- return;
68
- }
69
- return {
70
- from: this.table.from,
71
- to: this.table.to,
72
- node: this.table.node.toJSON()
73
- };
74
- }
75
- static fromJSON(schema, json) {
76
- return {
77
- from: json.from,
78
- to: json.to,
79
- node: schema.nodeFromJSON(json.node)
80
- };
81
- }
82
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,19 +0,0 @@
1
- export const getCellIndex = (map, row, col) => {
2
- return row * map.width + col;
3
- };
4
- export function hasMergedColumns(map, row, col) {
5
- const index = getCellIndex(map, row, col);
6
- return col > 0 && map.map[index - 1] === map.map[index] || col < map.width - 1 && map.map[index + 1] === map.map[index];
7
- }
8
- export function hasMergedRows(map, row, col) {
9
- const index = getCellIndex(map, row, col);
10
- return row > 0 && map.map[index - map.width] !== map.map[index] || row < map.height - 1 && map.map[index + map.width] === map.map[index];
11
- }
12
- export function isRootRow(map, row, col) {
13
- const index = getCellIndex(map, row, col);
14
- return row > 0 ? map.map[index - map.width] !== map.map[index] : true;
15
- }
16
- export function isRootCol(map, row, col) {
17
- const index = getCellIndex(map, row, col);
18
- return row > 0 ? map.map[index - 1] !== map.map[index] : true;
19
- }