@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,373 +0,0 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
- import _createClass from "@babel/runtime/helpers/createClass";
5
- import _inherits from "@babel/runtime/helpers/inherits";
6
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
7
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
8
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
9
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
11
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
12
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
13
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
14
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
15
- import { Step, StepMap, StepResult, Transform } from '@atlaskit/editor-prosemirror/transform';
16
- import { cellsAtColumn } from './utils/cells-at-column';
17
- import { findColumn } from './utils/find-column';
18
- import { getTableRectFromDoc } from './utils/get-table-rect-from-doc';
19
- import { applyCellStep, createCellStep, getMapFromCellStep, invertCellStep } from './utils/cell-step';
20
- import { SideEffectsHandler } from './utils/side-effects/side-effects';
21
- import memoizeOne from 'memoize-one';
22
- var ADD_COLUMN_STEP = 'ak-add-column';
23
- function printColumnInfo(columnInfo) {
24
- var cellsFrom = [];
25
- var _iterator = _createForOfIteratorHelper(columnInfo.values()),
26
- _step;
27
- try {
28
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
29
- var cellInfo = _step.value;
30
- cellsFrom.push(cellInfo.from);
31
- }
32
- } catch (err) {
33
- _iterator.e(err);
34
- } finally {
35
- _iterator.f();
36
- }
37
- return "[".concat(cellsFrom.join(','), "]");
38
- }
39
- function createColumnInfo(cellsInfo) {
40
- return new Map(cellsInfo.map(function (cellInfo) {
41
- return [cellInfo.from, cellInfo];
42
- }));
43
- }
44
- var getTableRectAndColumnFactory = function getTableRectAndColumnFactory(doc, pos, columnInfo) {
45
- return memoizeOne(function () {
46
- var rect = getTableRectFromDoc(doc, pos);
47
- var column = findColumn(columnInfo, rect);
48
- if (column === null) {
49
- throw new Error('no column');
50
- }
51
- return {
52
- rect: rect,
53
- column: column
54
- };
55
- });
56
- };
57
-
58
- /**
59
- * Index and positions looks like
60
- * 0 1 2 3 -> Add Column Index
61
- * | 5 | 10 | 15 | -> Table with Positions
62
- * | 20 | 25 | 30 |
63
- * 0 1 2 x -> Remove Column Index
64
- *
65
- */
66
- export var AddColumnStep = /*#__PURE__*/function (_Step) {
67
- _inherits(AddColumnStep, _Step);
68
- var _super = _createSuper(AddColumnStep);
69
- function AddColumnStep(tablePos, addColumnStepInfo) {
70
- var _this;
71
- var isDelete = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
72
- _classCallCheck(this, AddColumnStep);
73
- _this = _super.call(this);
74
- _this.tablePos = tablePos;
75
- _this.isDelete = isDelete;
76
- _this.sideEffectsHandler = new SideEffectsHandler(addColumnStepInfo.sideEffects);
77
- _this.columnInfo = createColumnInfo(addColumnStepInfo.cells);
78
- return _this;
79
- }
80
-
81
- /**
82
- * Detect the column based on all the cells step in column info.
83
- * Recreate columnInfo based on the current document. We might need to add new cells added by insert row or unmerge cells.
84
- * If isDelete
85
- * Decrease colspan if one row has merged cell
86
- * Remove all the cells using columnInfo.cellStep[].from
87
- * else
88
- * Increase colspan if one row had merged cell
89
- * Add all new cells at columnInfo.cellStep[].from,
90
- * if there is columnInfo.cellStep[].newCell use it
91
- * else create an empty cell
92
- *
93
- * @param doc Current document
94
- */
95
- _createClass(AddColumnStep, [{
96
- key: "apply",
97
- value: function apply(doc) {
98
- var tablePos = this.tablePos;
99
- // Create transform base on the doc
100
- var tr = new Transform(doc);
101
- if (this.sideEffectsHandler.table.handleAddTable(tr, this.isDelete)) {
102
- return StepResult.ok(tr.doc);
103
- }
104
- var tableRect;
105
- try {
106
- tableRect = getTableRectFromDoc(doc, tablePos);
107
- } catch (e) {
108
- return StepResult.fail(e.message);
109
- }
110
- var column = findColumn(this.columnInfo, tableRect);
111
- if (column === null) {
112
- return StepResult.fail("No column for this cells \"".concat(printColumnInfo(this.columnInfo), "\" in table at position \"").concat(tablePos, "\"."));
113
- }
114
- if (this.sideEffectsHandler.table.handleRemoveTable(tr, this.tablePos, tableRect, column, this.isDelete)) {
115
- return StepResult.ok(tr.doc);
116
- }
117
- this.columnInfo = this.applyCellSteps(tr, tableRect, column, this.isDelete);
118
-
119
- // Return the document modified.
120
- return StepResult.ok(tr.doc);
121
- }
122
-
123
- /**
124
- * Update tablePos with the new position. If tablePos doesnt exist any more remove the step
125
- * Update all the cellStep inside columnInfo. If cellStep.from position gets deleted removed it from column info
126
- * if cellStep.length === 0 remove the step
127
- * Create a new step with all the position updated
128
- * @param mapping
129
- */
130
- }, {
131
- key: "map",
132
- value: function map(mapping) {
133
- var tablePosResult = mapping.mapResult(this.tablePos);
134
- if (tablePosResult.deleted) {
135
- // If table was deleted remove the step
136
- return null;
137
- }
138
- var cellSteps = [];
139
- var _iterator2 = _createForOfIteratorHelper(this.columnInfo.values()),
140
- _step2;
141
- try {
142
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
143
- var oldCellStep = _step2.value;
144
- var fromResult = mapping.mapResult(oldCellStep.from);
145
- var toResult = mapping.mapResult(oldCellStep.to);
146
- if (fromResult.deleted && toResult.deleted) {
147
- continue;
148
- }
149
- var cellStep = _objectSpread(_objectSpread({}, oldCellStep), {}, {
150
- from: fromResult.pos,
151
- to: toResult.pos
152
- });
153
- if (oldCellStep.mergeWith !== undefined) {
154
- cellStep.mergeWith = mapping.map(oldCellStep.mergeWith);
155
- }
156
- cellSteps.push(cellStep);
157
- }
158
- } catch (err) {
159
- _iterator2.e(err);
160
- } finally {
161
- _iterator2.f();
162
- }
163
- if (cellSteps.length === 0) {
164
- return null;
165
- }
166
- var sideEffects = this.sideEffectsHandler.map(mapping);
167
- return new AddColumnStep(tablePosResult.pos, {
168
- cells: cellSteps,
169
- sideEffects: sideEffects
170
- }, this.isDelete);
171
- }
172
-
173
- /**
174
- * if isDelete
175
- * Get the original cell node at columnInfo.cellStep[].from to columnInfo.cellStep[].to
176
- * Create a copy of the node
177
- * Create a new cellStep with the same positions but with the clone node as a content
178
- * return new step inverted
179
- * else
180
- * Remove the content from each columnInfo.cellStep[].content
181
- * return new step inverted
182
- * @param originalDoc
183
- */
184
- }, {
185
- key: "invert",
186
- value: function invert(originalDoc) {
187
- var _this2 = this;
188
- var stepMap = this.getMap();
189
-
190
- // Memoize function to be called only on delete scenarios
191
- var getTableRectAndColumn = getTableRectAndColumnFactory(originalDoc, this.tablePos, this.columnInfo);
192
- // This is needed because the real pos of the cell in the generated document is affected by the previous operations.
193
- var newCellSteps = Array.from(this.columnInfo.values(), function (oldCellStep) {
194
- var newCellStep = invertCellStep(originalDoc, getTableRectAndColumn, oldCellStep, _this2.isDelete, stepMap);
195
- return newCellStep;
196
- });
197
- var sideEffects = this.sideEffectsHandler.invert(originalDoc, this.isDelete, stepMap);
198
- return new AddColumnStep(this.tablePos, {
199
- cells: newCellSteps,
200
- sideEffects: sideEffects
201
- }, !this.isDelete);
202
- }
203
-
204
- /**
205
- * StepMap is created based on columnInfo.
206
- * ColumnInfo is created on constructor and once is applied (the document could have new cells that weren't part of the original set)
207
- * if isDelete
208
- * Create range array based on cell info where each range is [cellStep.from, cellStep.from - cellStep.to, 0]
209
- * else
210
- * Create range array base on cell info where each range is [cellStep.from, 0, cellStep.content ? cellStep.content.nodeSize : defaultEmptyCellNodeSize]
211
- *
212
- * Ranges in ProseMirror are represented by each 3 elements in an array.
213
- * As [pos, currentSize, newSize, pos2, currentSize2, newSize2] where:
214
- * pos: Position in the document
215
- * currentSize: Represent the affected range, this will be pos + currentSize
216
- * newSize: Represent the new values, pos + newSize
217
- */
218
- }, {
219
- key: "getMap",
220
- value: function getMap() {
221
- var tableMap = this.sideEffectsHandler.getTableMap(this.isDelete);
222
- if (tableMap) {
223
- return tableMap;
224
- }
225
- var ranges = [];
226
- var _iterator3 = _createForOfIteratorHelper(this.columnInfo.values()),
227
- _step3;
228
- try {
229
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
230
- var _ranges;
231
- var cellStep = _step3.value;
232
- (_ranges = ranges).push.apply(_ranges, _toConsumableArray(getMapFromCellStep(cellStep, this.isDelete)));
233
- }
234
- } catch (err) {
235
- _iterator3.e(err);
236
- } finally {
237
- _iterator3.f();
238
- }
239
- ranges = this.sideEffectsHandler.rows.addRowRanges(ranges, this.isDelete);
240
-
241
- // If no steps, I create am empty stepMap
242
- return new StepMap(ranges);
243
- }
244
-
245
- /**
246
- * Try to merge this step with another one, to be applied directly
247
- * after it. Returns the merged step when possible, null if the
248
- * steps can't be merged.
249
- */
250
- }, {
251
- key: "merge",
252
- value: function merge(other) {
253
- // We cannot merge add column step at the moment
254
- return null;
255
- }
256
-
257
- /**
258
- * Create a JSON-serializeable representation of this step. When
259
- * defining this for a custom subclass, make sure the result object
260
- * includes the step type's [JSON id](#transform.Step^jsonID) under
261
- * the `stepType` property.
262
- */
263
- }, {
264
- key: "toJSON",
265
- value: function toJSON() {
266
- var addColumnStepJson = {
267
- stepType: ADD_COLUMN_STEP,
268
- tablePos: this.tablePos,
269
- cells: Array.from(this.columnInfo.values(), function (cellStep) {
270
- var cellStepJson = {
271
- from: cellStep.from,
272
- to: cellStep.to
273
- };
274
- if (cellStep.mergeWith !== undefined) {
275
- cellStepJson.mergeWith = cellStep.mergeWith;
276
- }
277
- if (cellStep.newCell !== undefined) {
278
- cellStepJson.newCell = cellStep.newCell.toJSON();
279
- }
280
- return cellStepJson;
281
- }),
282
- isDelete: this.isDelete
283
- };
284
- var sideEffectsJSON = this.sideEffectsHandler.toJSON();
285
- if (sideEffectsJSON) {
286
- addColumnStepJson.sideEffects = sideEffectsJSON;
287
- }
288
- return addColumnStepJson;
289
- }
290
-
291
- /**
292
- * Deserialize a step from its JSON representation. Will call
293
- * through to the step class' own implementation of this method.
294
- */
295
- }, {
296
- key: "applyCellSteps",
297
- value: function applyCellSteps(tr, tableRect, column, isDelete) {
298
- var newColumnInfo = new Map();
299
- var rowsHandler = this.sideEffectsHandler.rows.start(this.isDelete);
300
- var iter = cellsAtColumn(tableRect, column);
301
- var next = iter.next();
302
- // Iterate for all the cells in the current document
303
- while (!next.done) {
304
- var cell = next.value;
305
- var previousCellStep = this.columnInfo.get(cell.from);
306
- var newCellStep = createCellStep(cell, column, isDelete, previousCellStep);
307
-
308
- // If is the last cell in the row and doesnt have colspan I need to remove the whole row.
309
- var removeRowResult = rowsHandler.handle(tr, tableRect, cell.row, column, cell);
310
- if (removeRowResult.handled) {
311
- next = iter.next(removeRowResult.skipRows);
312
- continue;
313
- }
314
-
315
- // Apply the step, to the pseudo document, get rows to skip, and the cellstep (might be modified, for example, a merge cell that remove the cell instead)
316
- var _applyCellStep = applyCellStep(tr, tableRect, cell, newCellStep, isDelete, column),
317
- skipRows = _applyCellStep.skipRows,
318
- cellStep = _applyCellStep.cellStep;
319
-
320
- // Store the new cell step. This could be an existing one or a new cell.
321
- newColumnInfo.set(newCellStep.from, cellStep);
322
- next = iter.next(skipRows);
323
- }
324
- rowsHandler.end(tr, tableRect, column);
325
- return newColumnInfo;
326
- }
327
- }], [{
328
- key: "fromJSON",
329
- value: function fromJSON(schema, json) {
330
- // TODO: Add validation. Return null if it is invalid. Check in review if this is necessary
331
- var cells = json.cells.map(function (cellsJson) {
332
- var cell = _objectSpread(_objectSpread({}, cellsJson), {}, {
333
- newCell: cellsJson.newCell ? schema.nodeFromJSON(cellsJson.newCell) : undefined
334
- });
335
- return cell;
336
- });
337
- var sideEffects;
338
- if (json.sideEffects) {
339
- sideEffects = SideEffectsHandler.fromJSON(schema, json.sideEffects);
340
- }
341
- return new AddColumnStep(json.tablePos, {
342
- cells: cells,
343
- sideEffects: sideEffects
344
- }, json.isDelete);
345
- }
346
- }, {
347
- key: "create",
348
- value: function create(doc, tablePos, column) {
349
- var isDelete = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
350
- var tableRect = getTableRectFromDoc(doc, tablePos);
351
-
352
- // By default add column will rely on default behaviour (add empty cell).
353
- // There is no need to add content
354
- var cells = [];
355
- var iter = cellsAtColumn(tableRect, column);
356
- var next = iter.next();
357
- while (!next.done) {
358
- var cell = next.value;
359
- cells.push(createCellStep(cell, column, isDelete));
360
- var skipRows = 0;
361
- if (cell.attrs && cell.attrs.rowspan) {
362
- skipRows = cell.attrs.rowspan - 1;
363
- }
364
- next = iter.next(skipRows);
365
- }
366
- return new AddColumnStep(tablePos, {
367
- cells: cells
368
- }, isDelete);
369
- }
370
- }]);
371
- return AddColumnStep;
372
- }(Step);
373
- Step.jsonID(ADD_COLUMN_STEP, AddColumnStep);
@@ -1,5 +0,0 @@
1
- export var SortOrder = /*#__PURE__*/function (SortOrder) {
2
- SortOrder["ASC"] = "asc";
3
- SortOrder["DESC"] = "desc";
4
- return SortOrder;
5
- }({});
@@ -1,60 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _inherits from "@babel/runtime/helpers/inherits";
4
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
7
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
8
- import { Slice } from '@atlaskit/editor-prosemirror/model';
9
- import { ReplaceStep, Step, StepMap, StepResult } from '@atlaskit/editor-prosemirror/transform';
10
- export var tableSortingStepType = 'atlaskit-table-sorting-ordering';
11
- export var TableSortStep = /*#__PURE__*/function (_Step) {
12
- _inherits(TableSortStep, _Step);
13
- var _super = _createSuper(TableSortStep);
14
- function TableSortStep(pos, prev, next) {
15
- var _this;
16
- _classCallCheck(this, TableSortStep);
17
- _this = _super.call(this);
18
- _this.prev = prev;
19
- _this.next = next;
20
- _this.pos = pos;
21
- return _this;
22
- }
23
- _createClass(TableSortStep, [{
24
- key: "invert",
25
- value: function invert() {
26
- return new TableSortStep(this.pos, this.next, this.prev);
27
- }
28
- }, {
29
- key: "apply",
30
- value: function apply(doc) {
31
- return StepResult.ok(doc);
32
- }
33
- }, {
34
- key: "map",
35
- value: function map() {
36
- return null;
37
- }
38
- }, {
39
- key: "getMap",
40
- value: function getMap() {
41
- return new StepMap([0, 0, 0]);
42
- }
43
- }, {
44
- key: "toJSON",
45
- value: function toJSON() {
46
- return {
47
- stepType: tableSortingStepType
48
- };
49
- }
50
- }], [{
51
- key: "fromJSON",
52
- value: function fromJSON() {
53
- return new ReplaceStep(0, 0, Slice.empty);
54
- }
55
- }]);
56
- return TableSortStep;
57
- }(Step);
58
-
59
- /** Register this step with Prosemirror */
60
- Step.jsonID(tableSortingStepType, TableSortStep);
@@ -1 +0,0 @@
1
- export {};
@@ -1,192 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
- import { addColSpan, removeColSpan } from '@atlaskit/editor-tables/utils';
6
- var EmptyCellNodeSize = 4;
7
- function calculateRowsToSkip(attrs) {
8
- if (attrs && attrs.rowspan) {
9
- return attrs.rowspan - 1;
10
- }
11
- return 0;
12
- }
13
-
14
- /**
15
- * Given a cell step, this function has to do the specific transformation to executed that step.
16
- * It returns the applied cellStep and rows that needs to skip (because it was already handled).
17
- * @param tr
18
- * @param tableRect
19
- * @param cell
20
- * @param cellStep
21
- * @param isDelete
22
- * @param column
23
- */
24
- export function applyCellStep(tr, tableRect, cell, cellStep, isDelete, column) {
25
- // Apply the merge actions,
26
- if (cellStep.mergeWith !== undefined) {
27
- var cellNode = tr.doc.nodeAt(tr.mapping.map(cellStep.mergeWith));
28
- var columns = column - tableRect.map.colCount(cellStep.mergeWith - tableRect.tableStart);
29
- var cellAttrs = isDelete ? removeColSpan(cellNode.attrs, columns) : addColSpan(cellNode.attrs, columns);
30
- if (cellAttrs.colspan > 0) {
31
- // When colspan is 0 should remove the cell
32
- tr.setNodeMarkup(tr.mapping.map(cellStep.mergeWith), undefined, cellAttrs);
33
- return {
34
- tr: tr,
35
- skipRows: calculateRowsToSkip(cellAttrs),
36
- cellStep: cellStep
37
- };
38
- }
39
-
40
- // When the new colspan is 0, I need to change the operation to a delete operation
41
- // Update cellStep with the proper data
42
- cellStep.from = cellStep.mergeWith;
43
- cellStep.to = cellStep.from + cellNode.nodeSize;
44
- cellStep.mergeWith = undefined;
45
- }
46
- var skipRows = 0;
47
- // Modify temporary document
48
- if (isDelete) {
49
- var _cellNode = tr.doc.nodeAt(tr.mapping.map(cellStep.from));
50
- skipRows = calculateRowsToSkip(_cellNode.attrs);
51
- tr.delete(tr.mapping.map(cellStep.from), tr.mapping.map(cellStep.to));
52
- } else {
53
- if (cellStep.newCell) {
54
- tr.insert(tr.mapping.map(cellStep.from), cellStep.newCell);
55
- skipRows = calculateRowsToSkip(cellStep.newCell.attrs);
56
- } else {
57
- tr.insert(tr.mapping.map(cellStep.from), cell.type.createAndFill());
58
- }
59
- }
60
- return {
61
- tr: tr,
62
- skipRows: skipRows,
63
- cellStep: cellStep
64
- };
65
- }
66
-
67
- /**
68
- * Given a cell step, this functions return un StepMap representing this action.
69
- * [position, oldSize, newSize]
70
- * @param cellStep
71
- * @param isDelete
72
- */
73
- export function getMapFromCellStep(cellStep, isDelete) {
74
- if (cellStep.mergeWith !== undefined) {
75
- return [cellStep.mergeWith, 1, 1];
76
- }
77
- if (isDelete) {
78
- return [cellStep.from, cellStep.to - cellStep.from, 0];
79
- } else {
80
- if (cellStep.newCell) {
81
- return [cellStep.from, 0, cellStep.newCell.nodeSize];
82
- }
83
- return [cellStep.from, 0, EmptyCellNodeSize];
84
- }
85
- }
86
-
87
- /**
88
- * Helper to calculate the offset of the inverted cells.
89
- * When you delete consecutive rows in a single step, the position in the generated document
90
- * are skipped by the all the changes except your own. (StepMap.map is not valid)
91
- * @param map
92
- * @param cellStep
93
- * @param isDelete
94
- */
95
- function getOffset(map, cellStep, isDelete) {
96
- if (isDelete) {
97
- return map.map(cellStep.from) - cellStep.from;
98
- }
99
- var _getMapFromCellStep = getMapFromCellStep(cellStep, isDelete),
100
- _getMapFromCellStep2 = _slicedToArray(_getMapFromCellStep, 3),
101
- oldSize = _getMapFromCellStep2[1],
102
- newSize = _getMapFromCellStep2[2];
103
- return map.map(cellStep.from) - cellStep.from - (newSize - oldSize);
104
- }
105
-
106
- /**
107
- * Given a cell step, this function invert that step.
108
- * @param doc
109
- * @param getTableRectAndColumn
110
- * @param cellStep
111
- * @param isDelete
112
- * @param stepMap
113
- */
114
- export function invertCellStep(doc, getTableRectAndColumn, cellStep, isDelete, stepMap) {
115
- /**
116
- * We need a correct map when a cell is added
117
- * We need the normal map position minus the size of the cell you added it. Why?
118
- * Having a table 3x3 and we add a new column at 2 creates this ranges
119
- * [
120
- * 10, 0, 4,
121
- * 20, 0, 4,
122
- * 30, 0, 4,
123
- * ]
124
- * Where:
125
- * * [10, 20, 30] are the original cell positions where we add the cells
126
- * * [0, 0, 0] are the old size. We are adding new cells, so it's always zero
127
- * * [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.
128
- * In the document generated the cells that I want to delete (if I invert this step) are [10, 24, 38]
129
- * this is calculated in the given way
130
- * * Map the position using this step mapping function, this will return the cell in the next column
131
- * * Remove the diff (4 - 0 in this case) of the current position.
132
- * For a delete action this not happen, it will always return the right value
133
- */
134
- var offset = getOffset(stepMap, cellStep, isDelete);
135
- var newCellStepInfo = _objectSpread(_objectSpread({}, cellStep), {}, {
136
- // Map the position to position of the generated document
137
- from: cellStep.from + offset,
138
- to: cellStep.to + offset
139
- });
140
- if (cellStep.mergeWith !== undefined) {
141
- newCellStepInfo.mergeWith = cellStep.mergeWith + offset;
142
- }
143
- if (isDelete) {
144
- // Add the removed cell as the new cell of the inverted step
145
- var removedCell = doc.nodeAt(cellStep.from);
146
- newCellStepInfo.newCell = removedCell.copy(removedCell.content);
147
-
148
- // When we delete a column we can end in a position that doesnt represent the right column.
149
- // This only happens on merged cell that ends in the deleted column.
150
- // We need to remap this position to the "next" cell (AKA cellStep.to)
151
- var _getTableRectAndColum = getTableRectAndColumn(),
152
- column = _getTableRectAndColum.column,
153
- rect = _getTableRectAndColum.rect;
154
- if (column < rect.map.width) {
155
- var isAtTheEnd = rect.map.colCount(cellStep.from - rect.tableStart) + removedCell.attrs.colspan - 1 === column;
156
- if (cellStep.mergeWith !== undefined && isAtTheEnd) {
157
- newCellStepInfo.mergeWith = newCellStepInfo.from;
158
- newCellStepInfo.from = newCellStepInfo.to;
159
- }
160
- }
161
- }
162
- return newCellStepInfo;
163
- }
164
-
165
- /**
166
- * Create a cell step based on the current cell and operation (add/delete)
167
- * @param cell
168
- * @param column
169
- * @param isDelete
170
- * @param previousCellStep
171
- */
172
- export function createCellStep(cell, column, isDelete, previousCellStep) {
173
- var newCellStepInfo = {
174
- from: cell.from,
175
- to: cell.to
176
- };
177
- if (cell.hasMergedCells) {
178
- // Check what column has to merge
179
- if (column !== cell.col || isDelete) {
180
- newCellStepInfo.mergeWith = cell.from;
181
- }
182
- }
183
- if (previousCellStep) {
184
- if (previousCellStep.mergeWith !== undefined) {
185
- newCellStepInfo.mergeWith = previousCellStep.mergeWith;
186
- }
187
- if (previousCellStep.newCell) {
188
- newCellStepInfo.newCell = previousCellStep.newCell;
189
- }
190
- }
191
- return newCellStepInfo;
192
- }