@atlaskit/editor-plugin-table 1.2.5 → 1.2.6
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 +8 -0
- package/dist/cjs/plugins/table/commands/selection.js +4 -4
- package/dist/cjs/plugins/table/event-handlers.js +3 -3
- package/dist/cjs/plugins/table/nodeviews/OverflowShadowsObserver.js +5 -6
- package/dist/cjs/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +9 -16
- package/dist/cjs/plugins/table/pm-plugins/table-local-id.js +65 -37
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +4 -4
- package/dist/cjs/plugins/table/transforms/delete-rows.js +2 -2
- package/dist/cjs/plugins/table/types.js +8 -8
- package/dist/cjs/plugins/table/ui/FloatingDeleteButton/index.js +6 -7
- package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/commands/selection.js +3 -3
- package/dist/es2019/plugins/table/nodeviews/OverflowShadowsObserver.js +5 -7
- package/dist/es2019/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +8 -14
- package/dist/es2019/plugins/table/pm-plugins/table-local-id.js +47 -38
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +4 -4
- package/dist/es2019/plugins/table/types.js +6 -6
- package/dist/es2019/plugins/table/ui/FloatingDeleteButton/index.js +6 -8
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/commands/selection.js +3 -3
- package/dist/esm/plugins/table/event-handlers.js +3 -3
- package/dist/esm/plugins/table/nodeviews/OverflowShadowsObserver.js +5 -6
- package/dist/esm/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +9 -16
- package/dist/esm/plugins/table/pm-plugins/table-local-id.js +66 -38
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +4 -4
- package/dist/esm/plugins/table/transforms/delete-rows.js +2 -2
- package/dist/esm/plugins/table/types.js +6 -6
- package/dist/esm/plugins/table/ui/FloatingDeleteButton/index.js +6 -7
- package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +1 -1
- package/dist/esm/version.json +1 -1
- package/package.json +4 -4
- package/src/__tests__/unit/pm-plugins/table-local-id.ts +2 -14
- package/src/plugins/table/pm-plugins/table-local-id.ts +57 -41
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 1.2.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`0ffb55018c9`](https://bitbucket.org/atlassian/atlassian-frontend/commits/0ffb55018c9) - Revert "[ED-17172] Bumped prosemirror-view from 1.23.2 to 1.23.7 and removed work-around for fixed issues"
|
|
8
|
+
- [`888cd482b98`](https://bitbucket.org/atlassian/atlassian-frontend/commits/888cd482b98) - Fix logic of generated new duplicated localIds when pasting a copied node above the copied node
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
3
11
|
## 1.2.5
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -9,12 +9,12 @@ var _tableMap = require("@atlaskit/editor-tables/table-map");
|
|
|
9
9
|
var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
|
|
10
10
|
var _utils = require("@atlaskit/editor-tables/utils");
|
|
11
11
|
var _selection = require("@atlaskit/editor-common/selection");
|
|
12
|
-
var TableSelectionDirection
|
|
13
|
-
exports.TableSelectionDirection = TableSelectionDirection;
|
|
14
|
-
(function (TableSelectionDirection) {
|
|
12
|
+
var TableSelectionDirection = /*#__PURE__*/function (TableSelectionDirection) {
|
|
15
13
|
TableSelectionDirection["TopToBottom"] = "TopToBottom";
|
|
16
14
|
TableSelectionDirection["BottomToTop"] = "BottomToTop";
|
|
17
|
-
|
|
15
|
+
return TableSelectionDirection;
|
|
16
|
+
}({});
|
|
17
|
+
exports.TableSelectionDirection = TableSelectionDirection;
|
|
18
18
|
var arrowLeftFromTable = function arrowLeftFromTable(editorSelectionAPI) {
|
|
19
19
|
return function () {
|
|
20
20
|
return function (state, dispatch) {
|
|
@@ -227,8 +227,8 @@ var handleMouseMove = function handleMouseMove(getEditorFeatureFlags) {
|
|
|
227
227
|
var _getEditorFeatureFlag = getEditorFeatureFlags(),
|
|
228
228
|
mouseMoveOptimization = _getEditorFeatureFlag.mouseMoveOptimization;
|
|
229
229
|
if (!(0, _utils3.isResizeHandleDecoration)(element) && (0, _utils3.isCell)(element)) {
|
|
230
|
-
var
|
|
231
|
-
if (
|
|
230
|
+
var _positionColumn = (0, _utils3.getMousePositionHorizontalRelativeByElement)(event, mouseMoveOptimization, elementContentRects, _types.RESIZE_HANDLE_AREA_DECORATION_GAP);
|
|
231
|
+
if (_positionColumn !== null) {
|
|
232
232
|
var _state4 = view.state,
|
|
233
233
|
_dispatch5 = view.dispatch;
|
|
234
234
|
var _getPluginState5 = (0, _pluginFactory.getPluginState)(_state4),
|
|
@@ -238,7 +238,7 @@ var handleMouseMove = function handleMouseMove(getEditorFeatureFlags) {
|
|
|
238
238
|
var cellStartPosition = view.posAtDOM(tableCell, 0);
|
|
239
239
|
var rect = (0, _utils.findCellRectClosestToPos)(_state4.doc.resolve(cellStartPosition));
|
|
240
240
|
if (rect) {
|
|
241
|
-
var columnEndIndexTarget =
|
|
241
|
+
var columnEndIndexTarget = _positionColumn === 'left' ? rect.left : rect.right;
|
|
242
242
|
var rowIndexTarget = rect.top;
|
|
243
243
|
if (columnEndIndexTarget !== resizeHandleColumnIndex || rowIndexTarget !== resizeHandleRowIndex || !(0, _utils3.hasResizeHandler)({
|
|
244
244
|
target: element,
|
|
@@ -76,6 +76,11 @@ var OverflowShadowsObserver = /*#__PURE__*/function () {
|
|
|
76
76
|
_this.shadowsObserved = true;
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
|
+
/**
|
|
80
|
+
* Takes a heightStyle if it can be computed in a less expensive manner,
|
|
81
|
+
* e.g. bounds on an IntersectionObserverEntry, otherwise proceed with
|
|
82
|
+
* reading it from sticky cell
|
|
83
|
+
*/
|
|
79
84
|
(0, _defineProperty2.default)(this, "updateStickyShadows", function (stickyRowHeight) {
|
|
80
85
|
var _this$wrapper, _this$wrapper2, _this$wrapper2$parent, _this$wrapper3, _this$wrapper3$parent;
|
|
81
86
|
if (!_this.isSticky) {
|
|
@@ -122,12 +127,6 @@ var OverflowShadowsObserver = /*#__PURE__*/function () {
|
|
|
122
127
|
var stickyCell = stickyRow && stickyRow.firstElementChild;
|
|
123
128
|
return stickyCell;
|
|
124
129
|
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Takes a heightStyle if it can be computed in a less expensive manner,
|
|
128
|
-
* e.g. bounds on an IntersectionObserverEntry, otherwise proceed with
|
|
129
|
-
* reading it from sticky cell
|
|
130
|
-
*/
|
|
131
130
|
}, {
|
|
132
131
|
key: "dispose",
|
|
133
132
|
value: function dispose() {
|
|
@@ -68,15 +68,20 @@ var TableRowNodeView = /*#__PURE__*/function () {
|
|
|
68
68
|
function TableRowNodeView(node, view, getPos, eventDispatcher, getEditorFeatureFlags) {
|
|
69
69
|
var _this = this;
|
|
70
70
|
(0, _classCallCheck2.default)(this, TableRowNodeView);
|
|
71
|
+
// this is the sticky header table row
|
|
71
72
|
(0, _defineProperty2.default)(this, "colControlsOffset", 0);
|
|
72
73
|
(0, _defineProperty2.default)(this, "focused", false);
|
|
73
74
|
(0, _defineProperty2.default)(this, "topPosEditorElement", 0);
|
|
74
75
|
(0, _defineProperty2.default)(this, "stickyHeadersOptimization", false);
|
|
75
76
|
(0, _defineProperty2.default)(this, "sentinels", {});
|
|
77
|
+
/* external events */
|
|
76
78
|
(0, _defineProperty2.default)(this, "listening", false);
|
|
77
79
|
(0, _defineProperty2.default)(this, "headerRowMouseScrollEnd", (0, _debounce.default)(function () {
|
|
78
80
|
_this.dom.classList.remove('no-pointer-events');
|
|
79
81
|
}, HEADER_ROW_SCROLL_RESET_DEBOUNCE_TIMEOUT));
|
|
82
|
+
// When the header is sticky, the header row is set to position: fixed
|
|
83
|
+
// This prevents mouse wheel scrolling on the scroll-parent div when user's mouse is hovering the header row.
|
|
84
|
+
// This fix sets pointer-events: none on the header row briefly to avoid this behaviour
|
|
80
85
|
(0, _defineProperty2.default)(this, "headerRowMouseScroll", (0, _throttle.default)(function () {
|
|
81
86
|
if (_this.isSticky) {
|
|
82
87
|
_this.dom.classList.add('no-pointer-events');
|
|
@@ -135,6 +140,7 @@ var TableRowNodeView = /*#__PURE__*/function () {
|
|
|
135
140
|
_this.dom.scrollLeft = wrapper.scrollLeft;
|
|
136
141
|
_this.lastTimePainted = performance.now();
|
|
137
142
|
});
|
|
143
|
+
/* receive external events */
|
|
138
144
|
(0, _defineProperty2.default)(this, "onTablePluginState", function (state) {
|
|
139
145
|
var tableRef = state.tableRef;
|
|
140
146
|
var focusChanged = false;
|
|
@@ -270,12 +276,14 @@ var TableRowNodeView = /*#__PURE__*/function () {
|
|
|
270
276
|
(0, _defineProperty2.default)(this, "getWrapperRefTop", function (wrapper) {
|
|
271
277
|
return Math.round((0, _dom2.getTop)(wrapper)) + _this.getWrapperoffset();
|
|
272
278
|
});
|
|
279
|
+
// TODO: rename!
|
|
273
280
|
(0, _defineProperty2.default)(this, "getScrolledTableTop", function (wrapper) {
|
|
274
281
|
return _this.getWrapperRefTop(wrapper) - _this.topPosEditorElement;
|
|
275
282
|
});
|
|
276
283
|
(0, _defineProperty2.default)(this, "getCurrentTableTop", function (tree) {
|
|
277
284
|
return _this.getScrolledTableTop(tree.wrapper) + tree.table.clientHeight;
|
|
278
285
|
});
|
|
286
|
+
/* emit external events */
|
|
279
287
|
(0, _defineProperty2.default)(this, "padding", 0);
|
|
280
288
|
(0, _defineProperty2.default)(this, "top", 0);
|
|
281
289
|
(0, _defineProperty2.default)(this, "emitOn", function (top, padding) {
|
|
@@ -323,18 +331,9 @@ var TableRowNodeView = /*#__PURE__*/function () {
|
|
|
323
331
|
this.subscribe();
|
|
324
332
|
}
|
|
325
333
|
}
|
|
326
|
-
|
|
327
|
-
/* external events */
|
|
328
|
-
|
|
329
|
-
// When the header is sticky, the header row is set to position: fixed
|
|
330
|
-
// This prevents mouse wheel scrolling on the scroll-parent div when user's mouse is hovering the header row.
|
|
331
|
-
// This fix sets pointer-events: none on the header row briefly to avoid this behaviour
|
|
332
334
|
(0, _createClass2.default)(TableRowNodeView, [{
|
|
333
335
|
key: "tree",
|
|
334
|
-
get:
|
|
335
|
-
// this is the sticky header table row
|
|
336
|
-
|
|
337
|
-
function get() {
|
|
336
|
+
get: function get() {
|
|
338
337
|
return (0, _dom2.getTree)(this.dom);
|
|
339
338
|
}
|
|
340
339
|
}, {
|
|
@@ -563,12 +562,6 @@ var TableRowNodeView = /*#__PURE__*/function () {
|
|
|
563
562
|
}
|
|
564
563
|
return true;
|
|
565
564
|
}
|
|
566
|
-
|
|
567
|
-
/* receive external events */
|
|
568
|
-
|
|
569
|
-
// TODO: rename!
|
|
570
|
-
|
|
571
|
-
/* emit external events */
|
|
572
565
|
}]);
|
|
573
566
|
return TableRowNodeView;
|
|
574
567
|
}();
|
|
@@ -11,6 +11,9 @@ var _prosemirrorState = require("prosemirror-state");
|
|
|
11
11
|
var _rafSchd = _interopRequireDefault(require("raf-schd"));
|
|
12
12
|
var _adfSchema = require("@atlaskit/adf-schema");
|
|
13
13
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
14
|
+
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; } } }; }
|
|
15
|
+
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); }
|
|
16
|
+
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; }
|
|
14
17
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
18
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } /**
|
|
16
19
|
* A plugin for ensuring tables always have unique local IDs, and to
|
|
@@ -29,15 +32,6 @@ var getPluginState = function getPluginState(state) {
|
|
|
29
32
|
return state && pluginKey.getState(state);
|
|
30
33
|
};
|
|
31
34
|
|
|
32
|
-
/**
|
|
33
|
-
* Traverses a transaction's steps to see if we're inserting any tables
|
|
34
|
-
*/
|
|
35
|
-
var checkIsAddingTable = function checkIsAddingTable(transaction, nodeType) {
|
|
36
|
-
return transaction.steps.some(function (step) {
|
|
37
|
-
return (0, _utils.stepAddsOneOf)(step, new Set([nodeType]));
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
|
|
41
35
|
/**
|
|
42
36
|
* Ensures uniqueness of `localId`s on tables being created or edited
|
|
43
37
|
*/
|
|
@@ -130,7 +124,9 @@ var createPlugin = function createPlugin(dispatch) {
|
|
|
130
124
|
var modified = false;
|
|
131
125
|
var tr = newState.tr;
|
|
132
126
|
var table = newState.schema.nodes.table;
|
|
133
|
-
var
|
|
127
|
+
var addedTableNodes = new Set();
|
|
128
|
+
var addedTableNodePos = new Map();
|
|
129
|
+
var localIds = new Set();
|
|
134
130
|
transactions.forEach(function (transaction) {
|
|
135
131
|
if (!transaction.docChanged) {
|
|
136
132
|
return;
|
|
@@ -143,38 +139,70 @@ var createPlugin = function createPlugin(dispatch) {
|
|
|
143
139
|
return;
|
|
144
140
|
}
|
|
145
141
|
|
|
146
|
-
/**
|
|
147
|
-
var
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
var isTable = node.type === table;
|
|
155
|
-
var localId = node.attrs.localId;
|
|
156
|
-
|
|
157
|
-
// Dealing with a table - make sure it's a unique ID
|
|
158
|
-
if (isTable) {
|
|
159
|
-
if (localId && !idsObserved.has(localId)) {
|
|
160
|
-
idsObserved.add(localId);
|
|
161
|
-
// Also add a localId if it happens to not have one,
|
|
162
|
-
} else if (!localId || idsObserved.has(localId)) {
|
|
163
|
-
modified = true;
|
|
164
|
-
tr.setNodeMarkup(pos, undefined, _objectSpread(_objectSpread({}, node.attrs), {}, {
|
|
165
|
-
localId: _adfSchema.uuid.generate()
|
|
166
|
-
}));
|
|
142
|
+
/** Get the tables we are adding and their position */
|
|
143
|
+
var _iterator = _createForOfIteratorHelper(transaction.steps),
|
|
144
|
+
_step;
|
|
145
|
+
try {
|
|
146
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
147
|
+
var step = _step.value;
|
|
148
|
+
if (!(0, _utils.stepHasSlice)(step)) {
|
|
149
|
+
continue;
|
|
167
150
|
}
|
|
168
|
-
|
|
151
|
+
step.slice.content.descendants(function (node, pos) {
|
|
152
|
+
if (node.type === table) {
|
|
153
|
+
addedTableNodes.add(node);
|
|
154
|
+
}
|
|
155
|
+
return true;
|
|
156
|
+
});
|
|
169
157
|
}
|
|
158
|
+
} catch (err) {
|
|
159
|
+
_iterator.e(err);
|
|
160
|
+
} finally {
|
|
161
|
+
_iterator.f();
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
if (!addedTableNodes.size) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
170
167
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
168
|
+
// Get the existing localIds on the page
|
|
169
|
+
newState.doc.descendants(function (node, pos) {
|
|
170
|
+
// Skip if this is position of added table
|
|
171
|
+
if (addedTableNodes.has(node)) {
|
|
172
|
+
addedTableNodePos.set(node, pos);
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
if (node.type !== table) {
|
|
175
176
|
return true;
|
|
176
|
-
}
|
|
177
|
+
}
|
|
178
|
+
localIds.add(node.attrs.localId);
|
|
179
|
+
|
|
180
|
+
// can't have table within a table
|
|
181
|
+
return false;
|
|
177
182
|
});
|
|
183
|
+
|
|
184
|
+
// If the added nodes have duplicate id, generate a new one
|
|
185
|
+
var _iterator2 = _createForOfIteratorHelper(addedTableNodes),
|
|
186
|
+
_step2;
|
|
187
|
+
try {
|
|
188
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
189
|
+
var node = _step2.value;
|
|
190
|
+
if (!node.attrs.localId || localIds.has(node.attrs.localId)) {
|
|
191
|
+
var pos = addedTableNodePos.get(node);
|
|
192
|
+
if (pos === undefined) {
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
tr.setNodeMarkup(pos, undefined, _objectSpread(_objectSpread({}, node.attrs), {}, {
|
|
196
|
+
localId: _adfSchema.uuid.generate()
|
|
197
|
+
}));
|
|
198
|
+
modified = true;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
} catch (err) {
|
|
202
|
+
_iterator2.e(err);
|
|
203
|
+
} finally {
|
|
204
|
+
_iterator2.f();
|
|
205
|
+
}
|
|
178
206
|
if (modified) {
|
|
179
207
|
return tr;
|
|
180
208
|
}
|
|
@@ -98,12 +98,12 @@ function reduceSpace(state, amount) {
|
|
|
98
98
|
}
|
|
99
99
|
return state;
|
|
100
100
|
}
|
|
101
|
-
var ColType
|
|
102
|
-
// - is beyond the range, and then not give it back
|
|
103
|
-
(function (ColType) {
|
|
101
|
+
var ColType = /*#__PURE__*/function (ColType) {
|
|
104
102
|
ColType["SOURCE"] = "src";
|
|
105
103
|
ColType["DEST"] = "dest";
|
|
106
|
-
|
|
104
|
+
return ColType;
|
|
105
|
+
}(ColType || {}); // TODO: should handle when destIdx:
|
|
106
|
+
// - is beyond the range, and then not give it back
|
|
107
107
|
function moveSpaceFrom(state, srcIdx, destIdx, amount) {
|
|
108
108
|
var useFreeSpace = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
109
109
|
var srcCol = state.cols[srcIdx];
|
|
@@ -43,7 +43,7 @@ var deleteRows = function deleteRows(rect) {
|
|
|
43
43
|
var _loop = function _loop(rowIndex) {
|
|
44
44
|
var rowCells = [];
|
|
45
45
|
var row = table.node.child(rowIndex);
|
|
46
|
-
var _loop2 = function _loop2(
|
|
46
|
+
var _loop2 = function _loop2() {
|
|
47
47
|
var cellPos = map.map[rowIndex * map.width + colIndex];
|
|
48
48
|
var cell = table.node.nodeAt(cellPos);
|
|
49
49
|
if (!cell) {
|
|
@@ -97,7 +97,7 @@ var deleteRows = function deleteRows(rect) {
|
|
|
97
97
|
}
|
|
98
98
|
};
|
|
99
99
|
for (var colIndex = 0; colIndex < map.width; colIndex++) {
|
|
100
|
-
var _ret = _loop2(
|
|
100
|
+
var _ret = _loop2();
|
|
101
101
|
if (_ret === "continue") continue;
|
|
102
102
|
}
|
|
103
103
|
if (rowCells.length) {
|
|
@@ -37,9 +37,7 @@ var RESIZE_HANDLE_AREA_DECORATION_GAP = 30;
|
|
|
37
37
|
*
|
|
38
38
|
*/
|
|
39
39
|
exports.RESIZE_HANDLE_AREA_DECORATION_GAP = RESIZE_HANDLE_AREA_DECORATION_GAP;
|
|
40
|
-
var TableDecorations
|
|
41
|
-
exports.TableDecorations = TableDecorations;
|
|
42
|
-
(function (TableDecorations) {
|
|
40
|
+
var TableDecorations = /*#__PURE__*/function (TableDecorations) {
|
|
43
41
|
TableDecorations["ALL_CONTROLS_HOVER"] = "CONTROLS_HOVER";
|
|
44
42
|
TableDecorations["ROW_CONTROLS_HOVER"] = "ROW_CONTROLS_HOVER";
|
|
45
43
|
TableDecorations["COLUMN_CONTROLS_HOVER"] = "COLUMN_CONTROLS_HOVER";
|
|
@@ -50,7 +48,9 @@ exports.TableDecorations = TableDecorations;
|
|
|
50
48
|
TableDecorations["COLUMN_RESIZING_HANDLE"] = "COLUMN_RESIZING_HANDLE";
|
|
51
49
|
TableDecorations["COLUMN_RESIZING_HANDLE_LINE"] = "COLUMN_RESIZING_HANDLE_LINE";
|
|
52
50
|
TableDecorations["LAST_CELL_ELEMENT"] = "LAST_CELL_ELEMENT";
|
|
53
|
-
|
|
51
|
+
return TableDecorations;
|
|
52
|
+
}({});
|
|
53
|
+
exports.TableDecorations = TableDecorations;
|
|
54
54
|
var TableCssClassName = _objectSpread(_objectSpread({}, _styles.TableSharedCssClassName), {}, {
|
|
55
55
|
COLUMN_CONTROLS: "".concat(_adfSchema.tablePrefixSelector, "-column-controls"),
|
|
56
56
|
COLUMN_CONTROLS_DECORATIONS: "".concat(_adfSchema.tablePrefixSelector, "-column-controls-decoration"),
|
|
@@ -113,9 +113,9 @@ var TableCssClassName = _objectSpread(_objectSpread({}, _styles.TableSharedCssCl
|
|
|
113
113
|
WITH_RESIZE_LINE_LAST_COLUMN: "".concat(_adfSchema.tablePrefixSelector, "-column-resize-line-last-column")
|
|
114
114
|
});
|
|
115
115
|
exports.TableCssClassName = TableCssClassName;
|
|
116
|
-
var ShadowEvent
|
|
117
|
-
exports.ShadowEvent = ShadowEvent;
|
|
118
|
-
(function (ShadowEvent) {
|
|
116
|
+
var ShadowEvent = /*#__PURE__*/function (ShadowEvent) {
|
|
119
117
|
ShadowEvent["SHOW_BEFORE_SHADOW"] = "showBeforeShadow";
|
|
120
118
|
ShadowEvent["SHOW_AFTER_SHADOW"] = "showAfterShadow";
|
|
121
|
-
|
|
119
|
+
return ShadowEvent;
|
|
120
|
+
}({});
|
|
121
|
+
exports.ShadowEvent = ShadowEvent;
|
|
@@ -106,6 +106,12 @@ var FloatingDeleteButton = /*#__PURE__*/function (_Component) {
|
|
|
106
106
|
dispatch = _this$props$editorVie2.dispatch;
|
|
107
107
|
return (0, _commands.clearHoverSelection)()(state, dispatch);
|
|
108
108
|
});
|
|
109
|
+
/**
|
|
110
|
+
*
|
|
111
|
+
*
|
|
112
|
+
* @private
|
|
113
|
+
* @memberof FloatingDeleteButton
|
|
114
|
+
*/
|
|
109
115
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleClick", function (event) {
|
|
110
116
|
event.preventDefault();
|
|
111
117
|
var editorAnalyticsAPI = _this.props.editorAnalyticsAPI;
|
|
@@ -288,13 +294,6 @@ var FloatingDeleteButton = /*#__PURE__*/function (_Component) {
|
|
|
288
294
|
// Do nothing if doesn't change anything
|
|
289
295
|
return null;
|
|
290
296
|
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
* @private
|
|
296
|
-
* @memberof FloatingDeleteButton
|
|
297
|
-
*/
|
|
298
297
|
}]);
|
|
299
298
|
return FloatingDeleteButton;
|
|
300
299
|
}(_react.Component);
|
|
@@ -24,7 +24,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
24
24
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
25
|
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; } } }; }
|
|
26
26
|
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); }
|
|
27
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
27
|
+
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; }
|
|
28
28
|
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); }; }
|
|
29
29
|
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; } }
|
|
30
30
|
var TableFloatingControls = /*#__PURE__*/function (_Component) {
|
package/dist/cjs/version.json
CHANGED
|
@@ -3,11 +3,11 @@ import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
|
3
3
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
4
4
|
import { findTable, isTableSelected } from '@atlaskit/editor-tables/utils';
|
|
5
5
|
import { RelativeSelectionPos, GapCursorSelection, Side, isSelectionAtStartOfNode, isSelectionAtEndOfNode } from '@atlaskit/editor-common/selection';
|
|
6
|
-
export let TableSelectionDirection
|
|
7
|
-
(function (TableSelectionDirection) {
|
|
6
|
+
export let TableSelectionDirection = /*#__PURE__*/function (TableSelectionDirection) {
|
|
8
7
|
TableSelectionDirection["TopToBottom"] = "TopToBottom";
|
|
9
8
|
TableSelectionDirection["BottomToTop"] = "BottomToTop";
|
|
10
|
-
|
|
9
|
+
return TableSelectionDirection;
|
|
10
|
+
}({});
|
|
11
11
|
export const arrowLeftFromTable = editorSelectionAPI => () => (state, dispatch) => {
|
|
12
12
|
const {
|
|
13
13
|
selection
|
|
@@ -63,6 +63,11 @@ export class OverflowShadowsObserver {
|
|
|
63
63
|
this.shadowsObserved = true;
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
|
+
/**
|
|
67
|
+
* Takes a heightStyle if it can be computed in a less expensive manner,
|
|
68
|
+
* e.g. bounds on an IntersectionObserverEntry, otherwise proceed with
|
|
69
|
+
* reading it from sticky cell
|
|
70
|
+
*/
|
|
66
71
|
_defineProperty(this, "updateStickyShadows", stickyRowHeight => {
|
|
67
72
|
var _this$wrapper, _this$wrapper2, _this$wrapper2$parent, _this$wrapper3, _this$wrapper3$parent;
|
|
68
73
|
if (!this.isSticky) {
|
|
@@ -105,13 +110,6 @@ export class OverflowShadowsObserver {
|
|
|
105
110
|
const stickyCell = stickyRow && stickyRow.firstElementChild;
|
|
106
111
|
return stickyCell;
|
|
107
112
|
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Takes a heightStyle if it can be computed in a less expensive manner,
|
|
111
|
-
* e.g. bounds on an IntersectionObserverEntry, otherwise proceed with
|
|
112
|
-
* reading it from sticky cell
|
|
113
|
-
*/
|
|
114
|
-
|
|
115
113
|
dispose() {
|
|
116
114
|
if (this.tableIntersectionObserver) {
|
|
117
115
|
this.tableIntersectionObserver.disconnect();
|
|
@@ -42,21 +42,24 @@ export const supportedHeaderRow = node => {
|
|
|
42
42
|
return allHeaders && !someMerged;
|
|
43
43
|
};
|
|
44
44
|
export class TableRowNodeView {
|
|
45
|
-
// this is the sticky header table row
|
|
46
|
-
|
|
47
45
|
get tree() {
|
|
48
46
|
return getTree(this.dom);
|
|
49
47
|
}
|
|
50
48
|
constructor(node, view, getPos, eventDispatcher, getEditorFeatureFlags) {
|
|
49
|
+
// this is the sticky header table row
|
|
51
50
|
_defineProperty(this, "colControlsOffset", 0);
|
|
52
51
|
_defineProperty(this, "focused", false);
|
|
53
52
|
_defineProperty(this, "topPosEditorElement", 0);
|
|
54
53
|
_defineProperty(this, "stickyHeadersOptimization", false);
|
|
55
54
|
_defineProperty(this, "sentinels", {});
|
|
55
|
+
/* external events */
|
|
56
56
|
_defineProperty(this, "listening", false);
|
|
57
57
|
_defineProperty(this, "headerRowMouseScrollEnd", debounce(() => {
|
|
58
58
|
this.dom.classList.remove('no-pointer-events');
|
|
59
59
|
}, HEADER_ROW_SCROLL_RESET_DEBOUNCE_TIMEOUT));
|
|
60
|
+
// When the header is sticky, the header row is set to position: fixed
|
|
61
|
+
// This prevents mouse wheel scrolling on the scroll-parent div when user's mouse is hovering the header row.
|
|
62
|
+
// This fix sets pointer-events: none on the header row briefly to avoid this behaviour
|
|
60
63
|
_defineProperty(this, "headerRowMouseScroll", throttle(() => {
|
|
61
64
|
if (this.isSticky) {
|
|
62
65
|
this.dom.classList.add('no-pointer-events');
|
|
@@ -117,6 +120,7 @@ export class TableRowNodeView {
|
|
|
117
120
|
this.dom.scrollLeft = wrapper.scrollLeft;
|
|
118
121
|
this.lastTimePainted = performance.now();
|
|
119
122
|
});
|
|
123
|
+
/* receive external events */
|
|
120
124
|
_defineProperty(this, "onTablePluginState", state => {
|
|
121
125
|
const tableRef = state.tableRef;
|
|
122
126
|
let focusChanged = false;
|
|
@@ -254,8 +258,10 @@ export class TableRowNodeView {
|
|
|
254
258
|
return focusValue ? 0 : tableControlsSpacing;
|
|
255
259
|
});
|
|
256
260
|
_defineProperty(this, "getWrapperRefTop", wrapper => Math.round(getTop(wrapper)) + this.getWrapperoffset());
|
|
261
|
+
// TODO: rename!
|
|
257
262
|
_defineProperty(this, "getScrolledTableTop", wrapper => this.getWrapperRefTop(wrapper) - this.topPosEditorElement);
|
|
258
263
|
_defineProperty(this, "getCurrentTableTop", tree => this.getScrolledTableTop(tree.wrapper) + tree.table.clientHeight);
|
|
264
|
+
/* emit external events */
|
|
259
265
|
_defineProperty(this, "padding", 0);
|
|
260
266
|
_defineProperty(this, "top", 0);
|
|
261
267
|
_defineProperty(this, "emitOn", (top, padding) => {
|
|
@@ -305,12 +311,6 @@ export class TableRowNodeView {
|
|
|
305
311
|
this.subscribe();
|
|
306
312
|
}
|
|
307
313
|
}
|
|
308
|
-
|
|
309
|
-
/* external events */
|
|
310
|
-
|
|
311
|
-
// When the header is sticky, the header row is set to position: fixed
|
|
312
|
-
// This prevents mouse wheel scrolling on the scroll-parent div when user's mouse is hovering the header row.
|
|
313
|
-
// This fix sets pointer-events: none on the header row briefly to avoid this behaviour
|
|
314
314
|
subscribe() {
|
|
315
315
|
this.editorScrollableElement = findOverflowScrollParent(this.view.dom) || window;
|
|
316
316
|
if (this.editorScrollableElement) {
|
|
@@ -523,10 +523,4 @@ export class TableRowNodeView {
|
|
|
523
523
|
}
|
|
524
524
|
return true;
|
|
525
525
|
}
|
|
526
|
-
|
|
527
|
-
/* receive external events */
|
|
528
|
-
|
|
529
|
-
// TODO: rename!
|
|
530
|
-
|
|
531
|
-
/* emit external events */
|
|
532
526
|
}
|
|
@@ -15,17 +15,10 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
|
15
15
|
import { PluginKey } from 'prosemirror-state';
|
|
16
16
|
import rafSchedule from 'raf-schd';
|
|
17
17
|
import { uuid } from '@atlaskit/adf-schema';
|
|
18
|
-
import {
|
|
18
|
+
import { stepHasSlice } from '@atlaskit/editor-common/utils';
|
|
19
19
|
const pluginKey = new PluginKey('tableLocalIdPlugin');
|
|
20
20
|
const getPluginState = state => state && pluginKey.getState(state);
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
* Traverses a transaction's steps to see if we're inserting any tables
|
|
24
|
-
*/
|
|
25
|
-
const checkIsAddingTable = (transaction, nodeType) => {
|
|
26
|
-
return transaction.steps.some(step => stepAddsOneOf(step, new Set([nodeType])));
|
|
27
|
-
};
|
|
28
|
-
|
|
29
22
|
/**
|
|
30
23
|
* Ensures uniqueness of `localId`s on tables being created or edited
|
|
31
24
|
*/
|
|
@@ -127,7 +120,9 @@ const createPlugin = dispatch => new SafePlugin({
|
|
|
127
120
|
const {
|
|
128
121
|
table
|
|
129
122
|
} = newState.schema.nodes;
|
|
130
|
-
const
|
|
123
|
+
const addedTableNodes = new Set();
|
|
124
|
+
const addedTableNodePos = new Map();
|
|
125
|
+
const localIds = new Set();
|
|
131
126
|
transactions.forEach(transaction => {
|
|
132
127
|
if (!transaction.docChanged) {
|
|
133
128
|
return;
|
|
@@ -140,39 +135,53 @@ const createPlugin = dispatch => new SafePlugin({
|
|
|
140
135
|
return;
|
|
141
136
|
}
|
|
142
137
|
|
|
143
|
-
/**
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Can't simply look at changed nodes, as we could be adding a table
|
|
150
|
-
newState.doc.descendants((node, pos) => {
|
|
151
|
-
const isTable = node.type === table;
|
|
152
|
-
const localId = node.attrs.localId;
|
|
153
|
-
|
|
154
|
-
// Dealing with a table - make sure it's a unique ID
|
|
155
|
-
if (isTable) {
|
|
156
|
-
if (localId && !idsObserved.has(localId)) {
|
|
157
|
-
idsObserved.add(localId);
|
|
158
|
-
// Also add a localId if it happens to not have one,
|
|
159
|
-
} else if (!localId || idsObserved.has(localId)) {
|
|
160
|
-
modified = true;
|
|
161
|
-
tr.setNodeMarkup(pos, undefined, {
|
|
162
|
-
...node.attrs,
|
|
163
|
-
localId: uuid.generate()
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
return false;
|
|
138
|
+
/** Get the tables we are adding and their position */
|
|
139
|
+
for (const step of transaction.steps) {
|
|
140
|
+
if (!stepHasSlice(step)) {
|
|
141
|
+
continue;
|
|
167
142
|
}
|
|
143
|
+
step.slice.content.descendants((node, pos) => {
|
|
144
|
+
if (node.type === table) {
|
|
145
|
+
addedTableNodes.add(node);
|
|
146
|
+
}
|
|
147
|
+
return true;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
if (!addedTableNodes.size) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
168
154
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
155
|
+
// Get the existing localIds on the page
|
|
156
|
+
newState.doc.descendants((node, pos) => {
|
|
157
|
+
// Skip if this is position of added table
|
|
158
|
+
if (addedTableNodes.has(node)) {
|
|
159
|
+
addedTableNodePos.set(node, pos);
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
if (node.type !== table) {
|
|
173
163
|
return true;
|
|
174
|
-
}
|
|
164
|
+
}
|
|
165
|
+
localIds.add(node.attrs.localId);
|
|
166
|
+
|
|
167
|
+
// can't have table within a table
|
|
168
|
+
return false;
|
|
175
169
|
});
|
|
170
|
+
|
|
171
|
+
// If the added nodes have duplicate id, generate a new one
|
|
172
|
+
for (const node of addedTableNodes) {
|
|
173
|
+
if (!node.attrs.localId || localIds.has(node.attrs.localId)) {
|
|
174
|
+
const pos = addedTableNodePos.get(node);
|
|
175
|
+
if (pos === undefined) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
tr.setNodeMarkup(pos, undefined, {
|
|
179
|
+
...node.attrs,
|
|
180
|
+
localId: uuid.generate()
|
|
181
|
+
});
|
|
182
|
+
modified = true;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
176
185
|
if (modified) {
|
|
177
186
|
return tr;
|
|
178
187
|
}
|
|
@@ -79,12 +79,12 @@ export function reduceSpace(state, amount, ignoreCols = []) {
|
|
|
79
79
|
}
|
|
80
80
|
return state;
|
|
81
81
|
}
|
|
82
|
-
var ColType
|
|
83
|
-
// - is beyond the range, and then not give it back
|
|
84
|
-
(function (ColType) {
|
|
82
|
+
var ColType = /*#__PURE__*/function (ColType) {
|
|
85
83
|
ColType["SOURCE"] = "src";
|
|
86
84
|
ColType["DEST"] = "dest";
|
|
87
|
-
|
|
85
|
+
return ColType;
|
|
86
|
+
}(ColType || {}); // TODO: should handle when destIdx:
|
|
87
|
+
// - is beyond the range, and then not give it back
|
|
88
88
|
function moveSpaceFrom(state, srcIdx, destIdx, amount, useFreeSpace = true) {
|
|
89
89
|
const srcCol = state.cols[srcIdx];
|
|
90
90
|
const destCol = state.cols[destIdx];
|