@atlaskit/adf-schema 29.1.2 → 30.0.0

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