@atlaskit/editor-tables 2.8.2 → 2.8.4
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.
- package/CHANGELOG.md +15 -0
- package/afm-cc/tsconfig.json +5 -1
- package/afm-jira/tsconfig.json +5 -1
- package/afm-post-office/tsconfig.json +5 -1
- package/dist/cjs/cell-bookmark.js +3 -2
- package/dist/cjs/cell-selection.js +17 -8
- package/dist/cjs/pm-plugins/input.js +23 -4
- package/dist/cjs/table-map.js +15 -8
- package/dist/cjs/utils/add-column.js +2 -0
- package/dist/cjs/utils/add-row.js +2 -0
- package/dist/cjs/utils/clone-column.js +4 -0
- package/dist/cjs/utils/copy-paste.js +15 -1
- package/dist/cjs/utils/find.js +5 -1
- package/dist/cjs/utils/fix-tables.js +4 -1
- package/dist/cjs/utils/get-cells-in-column.js +2 -0
- package/dist/cjs/utils/get-cells-in-row.js +2 -0
- package/dist/cjs/utils/move-column.js +6 -1
- package/dist/cjs/utils/normalize-selection.js +2 -0
- package/dist/cjs/utils/reorder-utils.js +4 -0
- package/dist/cjs/utils/split-cell-with-type.js +3 -3
- package/dist/cjs/utils/uuid.js +8 -4
- package/dist/es2019/cell-bookmark.js +3 -0
- package/dist/es2019/cell-selection.js +14 -1
- package/dist/es2019/index.js +3 -0
- package/dist/es2019/pm-plugins/input.js +23 -4
- package/dist/es2019/pm-plugins.js +3 -0
- package/dist/es2019/table-map.js +49 -41
- package/dist/es2019/utils/add-column.js +2 -0
- package/dist/es2019/utils/add-row-at.js +4 -4
- package/dist/es2019/utils/add-row.js +2 -0
- package/dist/es2019/utils/clone-column.js +4 -0
- package/dist/es2019/utils/clone-row.js +1 -1
- package/dist/es2019/utils/copy-paste.js +15 -1
- package/dist/es2019/utils/find.js +4 -1
- package/dist/es2019/utils/fix-tables.js +4 -1
- package/dist/es2019/utils/get-cells-in-column.js +2 -0
- package/dist/es2019/utils/get-cells-in-row.js +2 -0
- package/dist/es2019/utils/get-selection-range-in-column.js +2 -2
- package/dist/es2019/utils/get-selection-range-in-row.js +2 -2
- package/dist/es2019/utils/move-column.js +6 -1
- package/dist/es2019/utils/move-row.js +1 -1
- package/dist/es2019/utils/normalize-selection.js +2 -0
- package/dist/es2019/utils/remove-row.js +3 -3
- package/dist/es2019/utils/remove-table.js +1 -1
- package/dist/es2019/utils/reorder-utils.js +5 -1
- package/dist/es2019/utils/replace-table.js +1 -1
- package/dist/es2019/utils/split-cell-with-type.js +6 -6
- package/dist/es2019/utils/toggle-header.js +6 -6
- package/dist/es2019/utils/uuid.js +4 -1
- package/dist/es2019/utils.js +3 -0
- package/dist/esm/cell-bookmark.js +4 -2
- package/dist/esm/cell-selection.js +18 -7
- package/dist/esm/index.js +3 -0
- package/dist/esm/pm-plugins/input.js +23 -4
- package/dist/esm/pm-plugins.js +3 -0
- package/dist/esm/table-map.js +15 -8
- package/dist/esm/utils/add-column.js +2 -0
- package/dist/esm/utils/add-row.js +2 -0
- package/dist/esm/utils/clone-column.js +4 -0
- package/dist/esm/utils/copy-paste.js +15 -1
- package/dist/esm/utils/find.js +5 -1
- package/dist/esm/utils/fix-tables.js +4 -1
- package/dist/esm/utils/get-cells-in-column.js +2 -0
- package/dist/esm/utils/get-cells-in-row.js +2 -0
- package/dist/esm/utils/move-column.js +6 -1
- package/dist/esm/utils/normalize-selection.js +2 -0
- package/dist/esm/utils/reorder-utils.js +4 -0
- package/dist/esm/utils/split-cell-with-type.js +3 -3
- package/dist/esm/utils/uuid.js +8 -4
- package/dist/esm/utils.js +3 -0
- package/package.json +8 -2
- package/tsconfig.json +0 -1
|
@@ -16,7 +16,7 @@ export function cellWrapping($pos) {
|
|
|
16
16
|
// into smaller cells with the cell type (th, td) returned by getType function.
|
|
17
17
|
export function splitCellWithType(getCellType) {
|
|
18
18
|
return (state, dispatch) => {
|
|
19
|
-
|
|
19
|
+
const sel = state.selection;
|
|
20
20
|
let cellNode, cellPos;
|
|
21
21
|
if (!(sel instanceof CellSelection)) {
|
|
22
22
|
cellNode = cellWrapping(sel.$from);
|
|
@@ -36,9 +36,9 @@ export function splitCellWithType(getCellType) {
|
|
|
36
36
|
return false;
|
|
37
37
|
}
|
|
38
38
|
if (cellNode && dispatch) {
|
|
39
|
-
let cellAttrs = cellNode.attrs
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
let cellAttrs = cellNode.attrs;
|
|
40
|
+
const attrs = [];
|
|
41
|
+
const colwidth = cellAttrs.colwidth;
|
|
42
42
|
if (cellAttrs.rowspan && cellAttrs.rowspan > 1) {
|
|
43
43
|
cellAttrs = {
|
|
44
44
|
...cellAttrs,
|
|
@@ -51,8 +51,8 @@ export function splitCellWithType(getCellType) {
|
|
|
51
51
|
colspan: 1
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
const rect = selectedRect(state);
|
|
55
|
+
const tr = state.tr;
|
|
56
56
|
for (let i = 0; i < rect.right - rect.left; i++) {
|
|
57
57
|
attrs.push(colwidth ? {
|
|
58
58
|
...cellAttrs,
|
|
@@ -26,13 +26,13 @@ export function toggleHeader(type) {
|
|
|
26
26
|
return false;
|
|
27
27
|
}
|
|
28
28
|
if (dispatch) {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const types = tableNodeTypes(state.schema);
|
|
30
|
+
const rect = selectedRect(state),
|
|
31
31
|
tr = state.tr;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
const isHeaderRowEnabled = isHeaderEnabledByType('row', rect, types);
|
|
33
|
+
const isHeaderColumnEnabled = isHeaderEnabledByType('column', rect, types);
|
|
34
|
+
const isHeaderEnabled = type === 'column' ? isHeaderRowEnabled : type === 'row' ? isHeaderColumnEnabled : false;
|
|
35
|
+
const selectionStartsAt = isHeaderEnabled ? 1 : 0;
|
|
36
36
|
const cellsRect = type === 'column' ? new Rect(0, selectionStartsAt, 1, rect.map.height) : type === 'row' ? new Rect(selectionStartsAt, 0, rect.map.width, 1) : rect;
|
|
37
37
|
let newType;
|
|
38
38
|
if (type === 'column') {
|
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/* eslint-disable no-bitwise */
|
|
7
|
-
export const generateUuid = () =>
|
|
7
|
+
export const generateUuid = () =>
|
|
8
|
+
// Ignored via go/ees005
|
|
9
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
10
|
+
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
|
8
11
|
const r = Math.random() * 16 | 0;
|
|
9
12
|
return (c === 'x' ? r : r & 0x3 | 0x8).toString(16);
|
|
10
13
|
});
|
package/dist/es2019/utils.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
2
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
/* eslint-disable @atlaskit/editor/no-re-export */
|
|
4
|
+
// Entry file in package.json
|
|
5
|
+
|
|
3
6
|
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
4
7
|
import { inSameTable } from './utils/tables';
|
|
5
8
|
export var CellBookmark = /*#__PURE__*/function () {
|
|
@@ -8,7 +11,7 @@ export var CellBookmark = /*#__PURE__*/function () {
|
|
|
8
11
|
this.anchor = anchor;
|
|
9
12
|
this.head = head;
|
|
10
13
|
}
|
|
11
|
-
_createClass(CellBookmark, [{
|
|
14
|
+
return _createClass(CellBookmark, [{
|
|
12
15
|
key: "map",
|
|
13
16
|
value: function map(mapping) {
|
|
14
17
|
return new CellBookmark(mapping.map(this.anchor), mapping.map(this.head));
|
|
@@ -29,5 +32,4 @@ export var CellBookmark = /*#__PURE__*/function () {
|
|
|
29
32
|
return Selection.near($headCell, 1);
|
|
30
33
|
}
|
|
31
34
|
}]);
|
|
32
|
-
return CellBookmark;
|
|
33
35
|
}();
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
3
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
5
4
|
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
6
5
|
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
6
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
7
7
|
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; }
|
|
8
8
|
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; }
|
|
9
|
-
function
|
|
9
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
10
10
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
11
|
+
/* eslint-disable @atlaskit/editor/no-re-export */
|
|
12
|
+
// Entry file in package.json
|
|
13
|
+
|
|
11
14
|
// Was copied from https://github.com/ProseMirror/prosemirror-tables/blob/master/src/cellselection.js
|
|
12
15
|
|
|
13
16
|
// This file defines a ProseMirror selection subclass that models
|
|
@@ -30,8 +33,6 @@ import { inSameTable } from './utils/tables';
|
|
|
30
33
|
// selects across cells, and will be drawn by giving selected cells a
|
|
31
34
|
// `selectedCell` CSS class.
|
|
32
35
|
export var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
33
|
-
_inherits(CellSelection, _Selection);
|
|
34
|
-
var _super = _createSuper(CellSelection);
|
|
35
36
|
// :: (ResolvedPos, ?ResolvedPos)
|
|
36
37
|
// A table selection is identified by its anchor and head cells. The
|
|
37
38
|
// positions given to this constructor should point _before_ two
|
|
@@ -43,7 +44,7 @@ export var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
43
44
|
var $headCell = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : $anchorCell;
|
|
44
45
|
_classCallCheck(this, CellSelection);
|
|
45
46
|
var ranges = getCellSelectionRanges($anchorCell, $headCell);
|
|
46
|
-
_this =
|
|
47
|
+
_this = _callSuper(this, CellSelection, [ranges[0].$from, ranges[0].$to, ranges]);
|
|
47
48
|
// :: ResolvedPos
|
|
48
49
|
// A resolved position pointing _in front of_ the anchor cell (the one
|
|
49
50
|
// that doesn't move when extending the selection).
|
|
@@ -55,7 +56,8 @@ export var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
55
56
|
_this.visible = false;
|
|
56
57
|
return _this;
|
|
57
58
|
}
|
|
58
|
-
|
|
59
|
+
_inherits(CellSelection, _Selection);
|
|
60
|
+
return _createClass(CellSelection, [{
|
|
59
61
|
key: "map",
|
|
60
62
|
value: function map(doc, mapping) {
|
|
61
63
|
var $anchorCell = doc.resolve(mapping.map(this.$anchorCell.pos));
|
|
@@ -108,6 +110,8 @@ export var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
108
110
|
attrs = removeColSpan(attrs, 0, extraLeft);
|
|
109
111
|
}
|
|
110
112
|
if (extraRight > 0) {
|
|
113
|
+
// Ignored via go/ees005
|
|
114
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
111
115
|
attrs = removeColSpan(attrs, attrs.colspan - extraRight, extraRight);
|
|
112
116
|
}
|
|
113
117
|
if (cellRect.left < rect.left) {
|
|
@@ -193,7 +197,11 @@ export var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
193
197
|
if (Math.min(anchorTop, headTop) > 0) {
|
|
194
198
|
return false;
|
|
195
199
|
}
|
|
200
|
+
// Ignored via go/ees005
|
|
201
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
196
202
|
var anchorBot = anchorTop + this.$anchorCell.nodeAfter.attrs.rowspan;
|
|
203
|
+
// Ignored via go/ees005
|
|
204
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
197
205
|
var headBot = headTop + this.$headCell.nodeAfter.attrs.rowspan;
|
|
198
206
|
return Math.max(anchorBot, headBot) === this.$headCell.node(-1).childCount;
|
|
199
207
|
}
|
|
@@ -235,7 +243,11 @@ export var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
235
243
|
if (Math.min(anchorLeft, headLeft) > 0) {
|
|
236
244
|
return false;
|
|
237
245
|
}
|
|
246
|
+
// Ignored via go/ees005
|
|
247
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
238
248
|
var anchorRight = anchorLeft + this.$anchorCell.nodeAfter.attrs.colspan;
|
|
249
|
+
// Ignored via go/ees005
|
|
250
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
239
251
|
var headRight = headLeft + this.$headCell.nodeAfter.attrs.colspan;
|
|
240
252
|
return Math.max(anchorRight, headRight) === map.width;
|
|
241
253
|
}
|
|
@@ -332,6 +344,5 @@ export var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
332
344
|
return new CellSelection(doc.resolve(anchorCell), doc.resolve(headCell));
|
|
333
345
|
}
|
|
334
346
|
}]);
|
|
335
|
-
return CellSelection;
|
|
336
347
|
}(Selection);
|
|
337
348
|
Selection.jsonID('cell', CellSelection);
|
package/dist/esm/index.js
CHANGED
|
@@ -102,6 +102,8 @@ function deleteCellSelection(state, dispatch) {
|
|
|
102
102
|
}
|
|
103
103
|
if (dispatch) {
|
|
104
104
|
var tr = state.tr;
|
|
105
|
+
// Ignored via go/ees005
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
105
107
|
var baseContent = tableNodeTypes(state.schema).cell.createAndFill().content;
|
|
106
108
|
sel.forEachCell(function (cell, pos) {
|
|
107
109
|
if (!cell.content.eq(baseContent)) {
|
|
@@ -130,18 +132,23 @@ export function handleMouseDown(view, event, dragAndDropEnabled) {
|
|
|
130
132
|
) {
|
|
131
133
|
return false;
|
|
132
134
|
}
|
|
135
|
+
|
|
136
|
+
// Ignored via go/ees005
|
|
137
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
133
138
|
var startDOMCell = domInCell(view, startEvent.target);
|
|
134
139
|
var $anchor = cellAround(view.state.selection.$anchor);
|
|
135
140
|
if (startEvent.shiftKey && view.state.selection instanceof CellSelection) {
|
|
136
|
-
var isDragHandleElement;
|
|
137
141
|
var targetElement = event.target instanceof HTMLElement || event.target instanceof SVGElement ? event.target : null;
|
|
138
|
-
isDragHandleElement = !!targetElement && !!targetElement.closest('button.pm-table-drag-handle-button-container, button.pm-table-drag-handle-button-clickable-zone');
|
|
142
|
+
var isDragHandleElement = !!targetElement && !!targetElement.closest('button.pm-table-drag-handle-button-container, button.pm-table-drag-handle-button-clickable-zone');
|
|
139
143
|
if (dragAndDropEnabled && isDragHandleElement) {
|
|
140
144
|
return false;
|
|
141
145
|
}
|
|
142
146
|
setCellSelection(view.state.selection.$anchorCell, startEvent);
|
|
143
147
|
startEvent.preventDefault();
|
|
144
|
-
} else if (startEvent.shiftKey && startDOMCell && $anchor !== null &&
|
|
148
|
+
} else if (startEvent.shiftKey && startDOMCell && $anchor !== null &&
|
|
149
|
+
// Ignored via go/ees005
|
|
150
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
151
|
+
cellUnderMouse(view, startEvent).pos !== $anchor.pos) {
|
|
145
152
|
// Adding to a selection that starts in another cell (causing a
|
|
146
153
|
// cell selection to be created).
|
|
147
154
|
setCellSelection($anchor, startEvent);
|
|
@@ -175,8 +182,14 @@ export function handleMouseDown(view, event, dragAndDropEnabled) {
|
|
|
175
182
|
|
|
176
183
|
// Stop listening to mouse motion events.
|
|
177
184
|
function stop() {
|
|
185
|
+
// Ignored via go/ees005
|
|
186
|
+
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
|
|
178
187
|
view.root.removeEventListener('mouseup', stop);
|
|
188
|
+
// Ignored via go/ees005
|
|
189
|
+
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
|
|
179
190
|
view.root.removeEventListener('dragstart', stop);
|
|
191
|
+
// Ignored via go/ees005
|
|
192
|
+
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
|
|
180
193
|
view.root.removeEventListener('mousemove', move);
|
|
181
194
|
if (tableEditingKey.getState(view.state) != null) {
|
|
182
195
|
view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));
|
|
@@ -188,6 +201,8 @@ export function handleMouseDown(view, event, dragAndDropEnabled) {
|
|
|
188
201
|
if (anchor != null) {
|
|
189
202
|
// Continuing an existing cross-cell selection
|
|
190
203
|
$moveAnchor = view.state.doc.resolve(anchor);
|
|
204
|
+
// Ignored via go/ees005
|
|
205
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
191
206
|
} else if (domInCell(view, event.target) !== startDOMCell) {
|
|
192
207
|
// Moving out of the initial cell -- start a new cell selection
|
|
193
208
|
$moveAnchor = cellUnderMouse(view, startEvent);
|
|
@@ -200,9 +215,13 @@ export function handleMouseDown(view, event, dragAndDropEnabled) {
|
|
|
200
215
|
setCellSelection($moveAnchor, event);
|
|
201
216
|
}
|
|
202
217
|
}
|
|
218
|
+
// Ignored via go/ees005
|
|
219
|
+
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
|
|
203
220
|
view.root.addEventListener('mouseup', stop);
|
|
204
|
-
// eslint-disable-next-line @atlaskit/design-system/no-direct-use-of-web-platform-drag-and-drop
|
|
221
|
+
// eslint-disable-next-line @atlaskit/design-system/no-direct-use-of-web-platform-drag-and-drop, @repo/internal/dom-events/no-unsafe-event-listeners
|
|
205
222
|
view.root.addEventListener('dragstart', stop);
|
|
223
|
+
// Ignored via go/ees005
|
|
224
|
+
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
|
|
206
225
|
view.root.addEventListener('mousemove', move);
|
|
207
226
|
return false;
|
|
208
227
|
}
|
package/dist/esm/pm-plugins.js
CHANGED
package/dist/esm/table-map.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
3
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
4
|
+
/* eslint-disable @atlaskit/editor/no-re-export */
|
|
5
|
+
// Entry file in package.json
|
|
6
|
+
|
|
4
7
|
// Because working with row and column-spanning cells is not quite
|
|
5
8
|
// trivial, this code builds up a descriptive structure for a given
|
|
6
9
|
// table node. The structures are cached with the (persistent) table
|
|
@@ -25,6 +28,8 @@ if (typeof WeakMap !== 'undefined') {
|
|
|
25
28
|
return value;
|
|
26
29
|
};
|
|
27
30
|
} else {
|
|
31
|
+
// Ignored via go/ees005
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
33
|
var _cache = [];
|
|
29
34
|
var cacheSize = 10;
|
|
30
35
|
var cachePos = 0;
|
|
@@ -88,7 +93,7 @@ export var TableMap = /*#__PURE__*/function () {
|
|
|
88
93
|
|
|
89
94
|
// :: (number) → Rect
|
|
90
95
|
// Find the dimensions of the cell at the given position.
|
|
91
|
-
_createClass(TableMap, [{
|
|
96
|
+
return _createClass(TableMap, [{
|
|
92
97
|
key: "findCell",
|
|
93
98
|
value: function findCell(pos) {
|
|
94
99
|
for (var i = 0; i < this.map.length; i++) {
|
|
@@ -279,7 +284,6 @@ export var TableMap = /*#__PURE__*/function () {
|
|
|
279
284
|
return readFromCache(table) || addToCache(table, computeMap(table));
|
|
280
285
|
}
|
|
281
286
|
}]);
|
|
282
|
-
return TableMap;
|
|
283
287
|
}();
|
|
284
288
|
|
|
285
289
|
// Compute a table map.
|
|
@@ -289,10 +293,10 @@ function computeMap(table) {
|
|
|
289
293
|
}
|
|
290
294
|
var width = findWidth(table);
|
|
291
295
|
var height = table.childCount;
|
|
292
|
-
var map = []
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
+
var map = [];
|
|
297
|
+
var colWidths = [];
|
|
298
|
+
var mapPos = 0,
|
|
299
|
+
problems = null;
|
|
296
300
|
for (var i = 0, e = width * height; i < e; i++) {
|
|
297
301
|
map[i] = 0;
|
|
298
302
|
}
|
|
@@ -446,8 +450,8 @@ function findBadColWidths(map, colWidths, table) {
|
|
|
446
450
|
continue;
|
|
447
451
|
}
|
|
448
452
|
seen[pos] = true;
|
|
449
|
-
var node = table.nodeAt(pos)
|
|
450
|
-
|
|
453
|
+
var node = table.nodeAt(pos);
|
|
454
|
+
var updated = null;
|
|
451
455
|
for (var j = 0; j < node.attrs.colspan; j++) {
|
|
452
456
|
var col = (i + j) % map.width,
|
|
453
457
|
colWidth = colWidths[col * 2];
|
|
@@ -464,6 +468,9 @@ function findBadColWidths(map, colWidths, table) {
|
|
|
464
468
|
}
|
|
465
469
|
}
|
|
466
470
|
}
|
|
471
|
+
|
|
472
|
+
// Ignored via go/ees005
|
|
473
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
467
474
|
function freshColWidth(attrs) {
|
|
468
475
|
if (attrs.colwidth) {
|
|
469
476
|
return attrs.colwidth.slice();
|
|
@@ -54,6 +54,8 @@ export function addColumn(tr, _ref, col) {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
var _pos = map.positionAt(row, col, table);
|
|
57
|
+
// Ignored via go/ees005
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
57
59
|
tr.insert(tr.mapping.map(tableStart + _pos), type.createAndFill(attrs));
|
|
58
60
|
}
|
|
59
61
|
}
|
|
@@ -81,6 +81,8 @@ export var cloneColumn = function cloneColumn(state, originColumnIndex, targetCo
|
|
|
81
81
|
// The actual target index needs to be translated per row, this is because row/col spans can affect the amount of
|
|
82
82
|
// cells each row contains.
|
|
83
83
|
var rowTargetPosition = translateTargetPosition(y, actualTargetIndex, tableMap);
|
|
84
|
+
// Ignored via go/ees005
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
84
86
|
var node = table.node.nodeAt(rowTargetPosition);
|
|
85
87
|
var pos = table.start + rowTargetPosition;
|
|
86
88
|
var insertPos = direction === 'end' ? newTr.mapping.map(pos + node.nodeSize, 1) : newTr.mapping.map(pos, -1);
|
|
@@ -105,6 +107,8 @@ function normalizeCellNode(cellNode, rowHeaderEnabled, columnHeaderEnabled, type
|
|
|
105
107
|
}
|
|
106
108
|
function createContentNodeFactory(table) {
|
|
107
109
|
return function (nodePos) {
|
|
110
|
+
// Ignored via go/ees005
|
|
111
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
108
112
|
var node = table.node.nodeAt(nodePos);
|
|
109
113
|
var pos = nodePos + table.start;
|
|
110
114
|
return {
|
|
@@ -115,6 +115,8 @@ function ensureRectangular(schema, rowsFragment) {
|
|
|
115
115
|
rows.push(Fragment.empty);
|
|
116
116
|
}
|
|
117
117
|
if (widths[_r2] < width) {
|
|
118
|
+
// Ignored via go/ees005
|
|
119
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
118
120
|
var empty = tableNodeTypes(schema).cell.createAndFill();
|
|
119
121
|
var cells = [];
|
|
120
122
|
for (var _i = widths[_r2]; _i < width; _i++) {
|
|
@@ -211,8 +213,12 @@ function growTable(tr, map, table, start, width, height, mapFrom) {
|
|
|
211
213
|
var cells = [];
|
|
212
214
|
var add = void 0;
|
|
213
215
|
if (rowNode.lastChild == null || rowNode.lastChild.type === types.cell) {
|
|
216
|
+
// Ignored via go/ees005
|
|
217
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
214
218
|
add = empty || (empty = types.cell.createAndFill());
|
|
215
219
|
} else {
|
|
220
|
+
// Ignored via go/ees005
|
|
221
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
216
222
|
add = emptyHead || (emptyHead = types.header_cell.createAndFill());
|
|
217
223
|
}
|
|
218
224
|
for (var i = map.width; i < width; i++) {
|
|
@@ -235,7 +241,13 @@ function growTable(tr, map, table, start, width, height, mapFrom) {
|
|
|
235
241
|
}
|
|
236
242
|
header = node.type === types.header_cell;
|
|
237
243
|
}
|
|
238
|
-
_cells2.push(header ?
|
|
244
|
+
_cells2.push(header ?
|
|
245
|
+
// Ignored via go/ees005
|
|
246
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
247
|
+
emptyHead || (emptyHead = types.header_cell.createAndFill()) :
|
|
248
|
+
// Ignored via go/ees005
|
|
249
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
250
|
+
empty || (empty = types.cell.createAndFill()));
|
|
239
251
|
}
|
|
240
252
|
var emptyRow = types.row.create(null, Fragment.from(_cells2));
|
|
241
253
|
var rows = [];
|
|
@@ -363,6 +375,8 @@ export function insertCells(state, dispatch, tableStart, rect, cells) {
|
|
|
363
375
|
var tr = state.tr;
|
|
364
376
|
var mapFrom = 0;
|
|
365
377
|
function recomp() {
|
|
378
|
+
// Ignored via go/ees005
|
|
379
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
366
380
|
table = tableStart ? tr.doc.nodeAt(tableStart - 1) : tr.doc;
|
|
367
381
|
map = TableMap.get(table);
|
|
368
382
|
mapFrom = tr.mapping.maps.length;
|
package/dist/esm/utils/find.js
CHANGED
|
@@ -19,7 +19,11 @@ export var findTableClosestToPos = function findTableClosestToPos($pos) {
|
|
|
19
19
|
// Iterates over parent nodes, returning a table cell or a table header node closest to a given `$pos`.
|
|
20
20
|
export var findCellClosestToPos = function findCellClosestToPos($pos) {
|
|
21
21
|
var predicate = function predicate(node) {
|
|
22
|
-
return
|
|
22
|
+
return (
|
|
23
|
+
// Ignored via go/ees005
|
|
24
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
25
|
+
node.type.spec.tableRole && /cell/i.test(node.type.spec.tableRole)
|
|
26
|
+
);
|
|
23
27
|
};
|
|
24
28
|
return findParentNodeClosestToPos($pos, predicate);
|
|
25
29
|
};
|
|
@@ -12,13 +12,14 @@ function changedDescendants(old, cur, offsetStart, f) {
|
|
|
12
12
|
var offset = offsetStart;
|
|
13
13
|
var oldSize = old.childCount;
|
|
14
14
|
var curSize = cur.childCount;
|
|
15
|
+
// eslint-disable-next-line no-labels
|
|
15
16
|
outer: for (var i = 0, j = 0; i < curSize; i++) {
|
|
16
17
|
var child = cur.child(i);
|
|
17
18
|
for (var scan = j, e = Math.min(oldSize, i + 3); scan < e; scan++) {
|
|
18
19
|
if (old.child(scan) === child) {
|
|
19
20
|
j = scan + 1;
|
|
20
21
|
offset += child.nodeSize;
|
|
21
|
-
// eslint-disable-next-line no-continue
|
|
22
|
+
// eslint-disable-next-line no-continue, no-labels
|
|
22
23
|
continue outer;
|
|
23
24
|
}
|
|
24
25
|
}
|
|
@@ -138,6 +139,8 @@ export function fixTable(state, table, tablePos, transaction, reportFixedTable)
|
|
|
138
139
|
}
|
|
139
140
|
var nodes = [];
|
|
140
141
|
for (var _j = 0; _j < add; _j++) {
|
|
142
|
+
// Ignored via go/ees005
|
|
143
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
141
144
|
nodes.push(tableNodeTypes(state.schema)[tableNodeType].createAndFill());
|
|
142
145
|
}
|
|
143
146
|
var side = (_i3 === 0 || first === _i3 - 1) && last === _i3 ? pos + 1 : end - 1;
|
|
@@ -20,6 +20,8 @@ export var getCellsInColumn = function getCellsInColumn(columnIndexes) {
|
|
|
20
20
|
bottom: map.height
|
|
21
21
|
});
|
|
22
22
|
return acc.concat(cells.map(function (nodePos) {
|
|
23
|
+
// Ignored via go/ees005
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
23
25
|
var node = table.node.nodeAt(nodePos);
|
|
24
26
|
var pos = nodePos + table.start;
|
|
25
27
|
return {
|
|
@@ -20,6 +20,8 @@ export var getCellsInRow = function getCellsInRow(rowIndex) {
|
|
|
20
20
|
bottom: index + 1
|
|
21
21
|
});
|
|
22
22
|
return acc.concat(cells.map(function (nodePos) {
|
|
23
|
+
// Ignored via go/ees005
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
23
25
|
var node = table.node.nodeAt(nodePos);
|
|
24
26
|
var pos = nodePos + table.start;
|
|
25
27
|
return {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
2
3
|
import { CellSelection } from '../cell-selection';
|
|
3
4
|
import { TableMap } from '../table-map';
|
|
4
5
|
import { determineTableHeaderStateFromTableNode } from './analyse-table';
|
|
@@ -208,9 +209,11 @@ export var moveColumn = function moveColumn(state, originColumnIndex, targetColu
|
|
|
208
209
|
// The actual target index needs to be translated per row, this is because row/col spans can affect the amount of
|
|
209
210
|
// cells each row contains.
|
|
210
211
|
var rowTargetPosition = translateTargetPosition(y, actualTargetIndex, tableMap);
|
|
212
|
+
// Ignored via go/ees005
|
|
213
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
211
214
|
var node = table.node.nodeAt(rowTargetPosition);
|
|
212
215
|
var pos = table.start + rowTargetPosition;
|
|
213
|
-
var insertPos = direction === 'end' ? newTr.mapping.map(pos + node.nodeSize, 1) : newTr.mapping.map(pos, -1);
|
|
216
|
+
var insertPos = direction === 'end' || tableMap.isCellMergedTopLeft(y, actualTargetIndex) && fg('platform_editor_table_fix_move_column') ? newTr.mapping.map(pos + node.nodeSize, 1) : newTr.mapping.map(pos, -1);
|
|
214
217
|
newTr.insert(insertPos, row.map(function (_ref, x) {
|
|
215
218
|
var node = _ref.node;
|
|
216
219
|
return normalizeCellNode(node, rowHeaderEnabled && y === 0, columnHeaderEnabled && actualTargetIndex === 0 && x === 0, types);
|
|
@@ -238,6 +241,8 @@ function normalizeCellNode(cellNode, rowHeaderEnabled, columnHeaderEnabled, type
|
|
|
238
241
|
}
|
|
239
242
|
function createContentNodeFactory(table) {
|
|
240
243
|
return function (nodePos) {
|
|
244
|
+
// Ignored via go/ees005
|
|
245
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
241
246
|
var node = table.node.nodeAt(nodePos);
|
|
242
247
|
var pos = nodePos + table.start;
|
|
243
248
|
return {
|
|
@@ -52,6 +52,8 @@ function isCellBoundarySelection(_ref2) {
|
|
|
52
52
|
break;
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
+
// Ignored via go/ees005
|
|
56
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
55
57
|
return afterFrom === beforeTo && /row|table/.test($from.node(depth).type.spec.tableRole);
|
|
56
58
|
}
|
|
57
59
|
function isTextSelectionAcrossCells(_ref3) {
|
|
@@ -28,7 +28,11 @@ import { TableMap } from '../table-map';
|
|
|
28
28
|
// ['a3', 'b3', 'c3', 'd3'],
|
|
29
29
|
// ]
|
|
30
30
|
// ```
|
|
31
|
+
// Ignored via go/ees005
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
33
|
export var transpose = function transpose(array) {
|
|
34
|
+
// Ignored via go/ees005
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
36
|
return array[0].map(function (_, i) {
|
|
33
37
|
return array.map(function (column) {
|
|
34
38
|
return column[i];
|
|
@@ -39,9 +39,9 @@ export function splitCellWithType(getCellType) {
|
|
|
39
39
|
return false;
|
|
40
40
|
}
|
|
41
41
|
if (cellNode && dispatch) {
|
|
42
|
-
var cellAttrs = cellNode.attrs
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
var cellAttrs = cellNode.attrs;
|
|
43
|
+
var attrs = [];
|
|
44
|
+
var colwidth = cellAttrs.colwidth;
|
|
45
45
|
if (cellAttrs.rowspan && cellAttrs.rowspan > 1) {
|
|
46
46
|
cellAttrs = _objectSpread(_objectSpread({}, cellAttrs), {}, {
|
|
47
47
|
rowspan: 1
|
package/dist/esm/utils/uuid.js
CHANGED
|
@@ -5,10 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
/* eslint-disable no-bitwise */
|
|
7
7
|
export var generateUuid = function generateUuid() {
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
return (
|
|
9
|
+
// Ignored via go/ees005
|
|
10
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
11
|
+
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
12
|
+
var r = Math.random() * 16 | 0;
|
|
13
|
+
return (c === 'x' ? r : r & 0x3 | 0x8).toString(16);
|
|
14
|
+
})
|
|
15
|
+
);
|
|
12
16
|
};
|
|
13
17
|
/* eslint-enable no-bitwise */
|
|
14
18
|
|
package/dist/esm/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-tables",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.4",
|
|
4
4
|
"description": "A package that contains common classes and utility functions for editor tables",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"singleton": true
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@atlaskit/editor-prosemirror": "6.
|
|
30
|
+
"@atlaskit/editor-prosemirror": "6.2.1",
|
|
31
|
+
"@atlaskit/platform-feature-flags": "^1.0.0",
|
|
31
32
|
"@babel/runtime": "^7.0.0"
|
|
32
33
|
},
|
|
33
34
|
"techstack": {
|
|
@@ -47,6 +48,11 @@
|
|
|
47
48
|
]
|
|
48
49
|
}
|
|
49
50
|
},
|
|
51
|
+
"platform-feature-flags": {
|
|
52
|
+
"platform_editor_table_fix_move_column": {
|
|
53
|
+
"type": "boolean"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
50
56
|
"af:exports": {
|
|
51
57
|
".": "./src/index.ts",
|
|
52
58
|
"./cell-bookmark": "./src/cell-bookmark.ts",
|