@atlaskit/editor-plugin-table 5.3.4 → 5.3.5
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 +6 -0
- package/dist/cjs/plugins/table/nodeviews/TableRow.js +53 -35
- package/dist/es2019/plugins/table/nodeviews/TableRow.js +22 -7
- package/dist/esm/plugins/table/nodeviews/TableRow.js +53 -35
- package/dist/types/plugins/table/nodeviews/TableRow.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/nodeviews/TableRow.d.ts +1 -0
- package/package.json +1 -1
- package/src/plugins/table/nodeviews/TableRow.ts +12 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 5.3.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#41864](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41864) [`34e85d7299e`](https://bitbucket.org/atlassian/atlassian-frontend/commits/34e85d7299e) - The table row nodeview needs to fetch the current live index and id when the canDrop and getData DnD methods are called. This is due to the fact that prosemirror reorders the tr elements efficently which causes the target indexes to be reordered and never updated.
|
|
8
|
+
|
|
3
9
|
## 5.3.4
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -168,6 +168,7 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
168
168
|
}, {
|
|
169
169
|
key: "addDropTarget",
|
|
170
170
|
value: function addDropTarget(element) {
|
|
171
|
+
var _this2 = this;
|
|
171
172
|
var pos = this.getPos();
|
|
172
173
|
if (!Number.isFinite(pos)) {
|
|
173
174
|
return;
|
|
@@ -175,15 +176,15 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
175
176
|
if (this.dropTargetCleanup) {
|
|
176
177
|
this.dropTargetCleanup();
|
|
177
178
|
}
|
|
178
|
-
var resolvedPos = this.view.state.doc.resolve(pos);
|
|
179
|
-
var targetIndex = resolvedPos.index();
|
|
180
|
-
var localId = resolvedPos.parent.attrs.localId;
|
|
181
179
|
this.dropTargetCleanup = (0, _element.dropTargetForElements)({
|
|
182
180
|
element: element,
|
|
183
181
|
canDrop: function canDrop(_ref2) {
|
|
184
182
|
var _data$indexes, _data$indexes2;
|
|
185
183
|
var source = _ref2.source;
|
|
186
184
|
var data = source.data;
|
|
185
|
+
var _this2$getCurrentData = _this2.getCurrentData(),
|
|
186
|
+
localId = _this2$getCurrentData.localId,
|
|
187
|
+
targetIndex = _this2$getCurrentData.targetIndex;
|
|
187
188
|
return (
|
|
188
189
|
// Only draggables of row type can be dropped on this target
|
|
189
190
|
data.type === 'table-row' &&
|
|
@@ -193,9 +194,15 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
193
194
|
!!((_data$indexes = data.indexes) !== null && _data$indexes !== void 0 && _data$indexes.length) && ((_data$indexes2 = data.indexes) === null || _data$indexes2 === void 0 ? void 0 : _data$indexes2.indexOf(targetIndex)) === -1
|
|
194
195
|
);
|
|
195
196
|
},
|
|
197
|
+
getIsSticky: function getIsSticky() {
|
|
198
|
+
return true;
|
|
199
|
+
},
|
|
196
200
|
getData: function getData(_ref3) {
|
|
197
201
|
var input = _ref3.input,
|
|
198
202
|
element = _ref3.element;
|
|
203
|
+
var _this2$getCurrentData2 = _this2.getCurrentData(),
|
|
204
|
+
localId = _this2$getCurrentData2.localId,
|
|
205
|
+
targetIndex = _this2$getCurrentData2.targetIndex;
|
|
199
206
|
var data = {
|
|
200
207
|
localId: localId,
|
|
201
208
|
type: 'table-row',
|
|
@@ -209,6 +216,17 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
209
216
|
}
|
|
210
217
|
});
|
|
211
218
|
}
|
|
219
|
+
}, {
|
|
220
|
+
key: "getCurrentData",
|
|
221
|
+
value: function getCurrentData() {
|
|
222
|
+
var resolvedPos = this.view.state.doc.resolve(this.getPos());
|
|
223
|
+
var targetIndex = resolvedPos.index();
|
|
224
|
+
var localId = resolvedPos.parent.attrs.localId;
|
|
225
|
+
return {
|
|
226
|
+
targetIndex: targetIndex,
|
|
227
|
+
localId: localId
|
|
228
|
+
};
|
|
229
|
+
}
|
|
212
230
|
}, {
|
|
213
231
|
key: "subscribe",
|
|
214
232
|
value: function subscribe() {
|
|
@@ -257,7 +275,7 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
257
275
|
}, {
|
|
258
276
|
key: "initObservers",
|
|
259
277
|
value: function initObservers() {
|
|
260
|
-
var
|
|
278
|
+
var _this3 = this;
|
|
261
279
|
if (!this.dom || this.dom.dataset.isObserved) {
|
|
262
280
|
return;
|
|
263
281
|
}
|
|
@@ -274,15 +292,15 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
274
292
|
window.requestAnimationFrame(function () {
|
|
275
293
|
var _getTree;
|
|
276
294
|
// we expect tree to be defined after animation frame
|
|
277
|
-
var tableContainer = (_getTree = (0, _dom2.getTree)(
|
|
295
|
+
var tableContainer = (_getTree = (0, _dom2.getTree)(_this3.dom)) === null || _getTree === void 0 ? void 0 : _getTree.wrapper.closest(".".concat(_types.TableCssClassName.NODEVIEW_WRAPPER));
|
|
278
296
|
if (tableContainer) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
[
|
|
297
|
+
_this3.sentinels.top = tableContainer.getElementsByClassName(_types.TableCssClassName.TABLE_STICKY_SENTINEL_TOP).item(0);
|
|
298
|
+
_this3.sentinels.bottom = tableContainer.getElementsByClassName(_types.TableCssClassName.TABLE_STICKY_SENTINEL_BOTTOM).item(0);
|
|
299
|
+
[_this3.sentinels.top, _this3.sentinels.bottom].forEach(function (el) {
|
|
282
300
|
// skip if already observed for another row on this table
|
|
283
301
|
if (el && !el.dataset.isObserved) {
|
|
284
302
|
el.dataset.isObserved = 'true';
|
|
285
|
-
|
|
303
|
+
_this3.intersectionObserver.observe(el);
|
|
286
304
|
}
|
|
287
305
|
});
|
|
288
306
|
}
|
|
@@ -294,27 +312,27 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
294
312
|
}, {
|
|
295
313
|
key: "createResizeObserver",
|
|
296
314
|
value: function createResizeObserver() {
|
|
297
|
-
var
|
|
315
|
+
var _this4 = this;
|
|
298
316
|
this.resizeObserver = new ResizeObserver(function (entries) {
|
|
299
|
-
var tree = (0, _dom2.getTree)(
|
|
317
|
+
var tree = (0, _dom2.getTree)(_this4.dom);
|
|
300
318
|
if (!tree) {
|
|
301
319
|
return;
|
|
302
320
|
}
|
|
303
321
|
var table = tree.table;
|
|
304
322
|
entries.forEach(function (entry) {
|
|
305
|
-
var
|
|
323
|
+
var _this4$editorScrollab;
|
|
306
324
|
// On resize of the parent scroll element we need to adjust the width
|
|
307
325
|
// of the sticky header
|
|
308
|
-
if (entry.target.className === ((
|
|
309
|
-
|
|
326
|
+
if (entry.target.className === ((_this4$editorScrollab = _this4.editorScrollableElement) === null || _this4$editorScrollab === void 0 ? void 0 : _this4$editorScrollab.className)) {
|
|
327
|
+
_this4.updateStickyHeaderWidth();
|
|
310
328
|
} else {
|
|
311
329
|
var newHeight = entry.contentRect ? entry.contentRect.height : entry.target.offsetHeight;
|
|
312
|
-
if (
|
|
330
|
+
if (_this4.sentinels.bottom &&
|
|
313
331
|
// When the table header is sticky, it would be taller by a 1px (border-bottom),
|
|
314
332
|
// So we adding this check to allow a 1px difference.
|
|
315
|
-
Math.abs(newHeight - (
|
|
316
|
-
|
|
317
|
-
|
|
333
|
+
Math.abs(newHeight - (_this4.stickyRowHeight || 0)) > _consts.stickyHeaderBorderBottomWidth) {
|
|
334
|
+
_this4.stickyRowHeight = newHeight;
|
|
335
|
+
_this4.sentinels.bottom.style.bottom = "".concat(_consts.tableScrollbarOffset + _consts.stickyRowOffsetTop + newHeight, "px");
|
|
318
336
|
(0, _dom.updateStickyMargins)(table);
|
|
319
337
|
}
|
|
320
338
|
}
|
|
@@ -324,9 +342,9 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
324
342
|
}, {
|
|
325
343
|
key: "createIntersectionObserver",
|
|
326
344
|
value: function createIntersectionObserver() {
|
|
327
|
-
var
|
|
345
|
+
var _this5 = this;
|
|
328
346
|
this.intersectionObserver = new IntersectionObserver(function (entries, _) {
|
|
329
|
-
var tree = (0, _dom2.getTree)(
|
|
347
|
+
var tree = (0, _dom2.getTree)(_this5.dom);
|
|
330
348
|
if (!tree) {
|
|
331
349
|
return;
|
|
332
350
|
}
|
|
@@ -349,28 +367,28 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
349
367
|
var sentinelIsBelowScrollArea = (((_entry$rootBounds2 = entry.rootBounds) === null || _entry$rootBounds2 === void 0 ? void 0 : _entry$rootBounds2.bottom) || 0) < entry.boundingClientRect.bottom;
|
|
350
368
|
if (!entry.isIntersecting && !sentinelIsBelowScrollArea) {
|
|
351
369
|
var _entry$rootBounds3;
|
|
352
|
-
tree &&
|
|
353
|
-
|
|
370
|
+
tree && _this5.makeHeaderRowSticky(tree, (_entry$rootBounds3 = entry.rootBounds) === null || _entry$rootBounds3 === void 0 ? void 0 : _entry$rootBounds3.top);
|
|
371
|
+
_this5.lastStickyTimestamp = Date.now();
|
|
354
372
|
} else {
|
|
355
|
-
table &&
|
|
373
|
+
table && _this5.makeRowHeaderNotSticky(table);
|
|
356
374
|
}
|
|
357
375
|
}
|
|
358
376
|
if (target.classList.contains(_types.TableCssClassName.TABLE_STICKY_SENTINEL_BOTTOM)) {
|
|
359
377
|
var _entry$rootBounds4;
|
|
360
|
-
var sentinelIsAboveScrollArea = entry.boundingClientRect.top -
|
|
378
|
+
var sentinelIsAboveScrollArea = entry.boundingClientRect.top - _this5.dom.offsetHeight < (((_entry$rootBounds4 = entry.rootBounds) === null || _entry$rootBounds4 === void 0 ? void 0 : _entry$rootBounds4.top) || 0);
|
|
361
379
|
if (table && !entry.isIntersecting && sentinelIsAboveScrollArea) {
|
|
362
380
|
// Not a perfect solution, but need to this code specific for FireFox ED-19177
|
|
363
381
|
if (_utils.browser.gecko) {
|
|
364
|
-
if (
|
|
365
|
-
|
|
382
|
+
if (_this5.lastStickyTimestamp && Date.now() - _this5.lastStickyTimestamp > _consts.STICKY_HEADER_TOGGLE_TOLERANCE_MS) {
|
|
383
|
+
_this5.makeRowHeaderNotSticky(table);
|
|
366
384
|
}
|
|
367
385
|
} else {
|
|
368
|
-
|
|
386
|
+
_this5.makeRowHeaderNotSticky(table);
|
|
369
387
|
}
|
|
370
388
|
} else if (entry.isIntersecting && sentinelIsAboveScrollArea) {
|
|
371
389
|
var _entry$rootBounds5;
|
|
372
|
-
tree &&
|
|
373
|
-
|
|
390
|
+
tree && _this5.makeHeaderRowSticky(tree, entry === null || entry === void 0 || (_entry$rootBounds5 = entry.rootBounds) === null || _entry$rootBounds5 === void 0 ? void 0 : _entry$rootBounds5.top);
|
|
391
|
+
_this5.lastStickyTimestamp = Date.now();
|
|
374
392
|
}
|
|
375
393
|
}
|
|
376
394
|
return;
|
|
@@ -445,12 +463,12 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
445
463
|
}, {
|
|
446
464
|
key: "refireIntersectionObservers",
|
|
447
465
|
value: function refireIntersectionObservers() {
|
|
448
|
-
var
|
|
466
|
+
var _this6 = this;
|
|
449
467
|
if (this.isSticky) {
|
|
450
468
|
[this.sentinels.top, this.sentinels.bottom].forEach(function (el) {
|
|
451
|
-
if (el &&
|
|
452
|
-
|
|
453
|
-
|
|
469
|
+
if (el && _this6.intersectionObserver) {
|
|
470
|
+
_this6.intersectionObserver.unobserve(el);
|
|
471
|
+
_this6.intersectionObserver.observe(el);
|
|
454
472
|
}
|
|
455
473
|
});
|
|
456
474
|
}
|
|
@@ -459,7 +477,7 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
459
477
|
key: "makeHeaderRowSticky",
|
|
460
478
|
value: function makeHeaderRowSticky(tree, scrollTop) {
|
|
461
479
|
var _tbody$firstChild,
|
|
462
|
-
|
|
480
|
+
_this7 = this;
|
|
463
481
|
// If header row height is more than 50% of viewport height don't do this
|
|
464
482
|
if (this.isSticky || this.stickyRowHeight && this.stickyRowHeight > window.innerHeight / 2) {
|
|
465
483
|
return;
|
|
@@ -496,7 +514,7 @@ var TableRow = exports.default = /*#__PURE__*/function (_ref) {
|
|
|
496
514
|
});
|
|
497
515
|
var fastScrollThresholdMs = 500;
|
|
498
516
|
setTimeout(function () {
|
|
499
|
-
|
|
517
|
+
_this7.refireIntersectionObservers();
|
|
500
518
|
}, fastScrollThresholdMs);
|
|
501
519
|
}
|
|
502
520
|
this.dom.style.top = "".concat(domTop, "px");
|
|
@@ -150,16 +150,17 @@ export default class TableRow extends TableNodeView {
|
|
|
150
150
|
if (this.dropTargetCleanup) {
|
|
151
151
|
this.dropTargetCleanup();
|
|
152
152
|
}
|
|
153
|
-
const resolvedPos = this.view.state.doc.resolve(pos);
|
|
154
|
-
const targetIndex = resolvedPos.index();
|
|
155
|
-
const localId = resolvedPos.parent.attrs.localId;
|
|
156
153
|
this.dropTargetCleanup = dropTargetForElements({
|
|
157
154
|
element: element,
|
|
158
|
-
canDrop({
|
|
155
|
+
canDrop: ({
|
|
159
156
|
source
|
|
160
|
-
}) {
|
|
157
|
+
}) => {
|
|
161
158
|
var _data$indexes, _data$indexes2;
|
|
162
159
|
const data = source.data;
|
|
160
|
+
const {
|
|
161
|
+
localId,
|
|
162
|
+
targetIndex
|
|
163
|
+
} = this.getCurrentData();
|
|
163
164
|
return (
|
|
164
165
|
// Only draggables of row type can be dropped on this target
|
|
165
166
|
data.type === 'table-row' &&
|
|
@@ -169,10 +170,15 @@ export default class TableRow extends TableNodeView {
|
|
|
169
170
|
!!((_data$indexes = data.indexes) !== null && _data$indexes !== void 0 && _data$indexes.length) && ((_data$indexes2 = data.indexes) === null || _data$indexes2 === void 0 ? void 0 : _data$indexes2.indexOf(targetIndex)) === -1
|
|
170
171
|
);
|
|
171
172
|
},
|
|
172
|
-
|
|
173
|
+
getIsSticky: () => true,
|
|
174
|
+
getData: ({
|
|
173
175
|
input,
|
|
174
176
|
element
|
|
175
|
-
}) {
|
|
177
|
+
}) => {
|
|
178
|
+
const {
|
|
179
|
+
localId,
|
|
180
|
+
targetIndex
|
|
181
|
+
} = this.getCurrentData();
|
|
176
182
|
const data = {
|
|
177
183
|
localId,
|
|
178
184
|
type: 'table-row',
|
|
@@ -186,6 +192,15 @@ export default class TableRow extends TableNodeView {
|
|
|
186
192
|
}
|
|
187
193
|
});
|
|
188
194
|
}
|
|
195
|
+
getCurrentData() {
|
|
196
|
+
const resolvedPos = this.view.state.doc.resolve(this.getPos());
|
|
197
|
+
const targetIndex = resolvedPos.index();
|
|
198
|
+
const localId = resolvedPos.parent.attrs.localId;
|
|
199
|
+
return {
|
|
200
|
+
targetIndex,
|
|
201
|
+
localId
|
|
202
|
+
};
|
|
203
|
+
}
|
|
189
204
|
subscribe() {
|
|
190
205
|
this.editorScrollableElement = findOverflowScrollParent(this.view.dom) || window;
|
|
191
206
|
if (this.editorScrollableElement) {
|
|
@@ -162,6 +162,7 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
162
162
|
}, {
|
|
163
163
|
key: "addDropTarget",
|
|
164
164
|
value: function addDropTarget(element) {
|
|
165
|
+
var _this2 = this;
|
|
165
166
|
var pos = this.getPos();
|
|
166
167
|
if (!Number.isFinite(pos)) {
|
|
167
168
|
return;
|
|
@@ -169,15 +170,15 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
169
170
|
if (this.dropTargetCleanup) {
|
|
170
171
|
this.dropTargetCleanup();
|
|
171
172
|
}
|
|
172
|
-
var resolvedPos = this.view.state.doc.resolve(pos);
|
|
173
|
-
var targetIndex = resolvedPos.index();
|
|
174
|
-
var localId = resolvedPos.parent.attrs.localId;
|
|
175
173
|
this.dropTargetCleanup = dropTargetForElements({
|
|
176
174
|
element: element,
|
|
177
175
|
canDrop: function canDrop(_ref2) {
|
|
178
176
|
var _data$indexes, _data$indexes2;
|
|
179
177
|
var source = _ref2.source;
|
|
180
178
|
var data = source.data;
|
|
179
|
+
var _this2$getCurrentData = _this2.getCurrentData(),
|
|
180
|
+
localId = _this2$getCurrentData.localId,
|
|
181
|
+
targetIndex = _this2$getCurrentData.targetIndex;
|
|
181
182
|
return (
|
|
182
183
|
// Only draggables of row type can be dropped on this target
|
|
183
184
|
data.type === 'table-row' &&
|
|
@@ -187,9 +188,15 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
187
188
|
!!((_data$indexes = data.indexes) !== null && _data$indexes !== void 0 && _data$indexes.length) && ((_data$indexes2 = data.indexes) === null || _data$indexes2 === void 0 ? void 0 : _data$indexes2.indexOf(targetIndex)) === -1
|
|
188
189
|
);
|
|
189
190
|
},
|
|
191
|
+
getIsSticky: function getIsSticky() {
|
|
192
|
+
return true;
|
|
193
|
+
},
|
|
190
194
|
getData: function getData(_ref3) {
|
|
191
195
|
var input = _ref3.input,
|
|
192
196
|
element = _ref3.element;
|
|
197
|
+
var _this2$getCurrentData2 = _this2.getCurrentData(),
|
|
198
|
+
localId = _this2$getCurrentData2.localId,
|
|
199
|
+
targetIndex = _this2$getCurrentData2.targetIndex;
|
|
193
200
|
var data = {
|
|
194
201
|
localId: localId,
|
|
195
202
|
type: 'table-row',
|
|
@@ -203,6 +210,17 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
203
210
|
}
|
|
204
211
|
});
|
|
205
212
|
}
|
|
213
|
+
}, {
|
|
214
|
+
key: "getCurrentData",
|
|
215
|
+
value: function getCurrentData() {
|
|
216
|
+
var resolvedPos = this.view.state.doc.resolve(this.getPos());
|
|
217
|
+
var targetIndex = resolvedPos.index();
|
|
218
|
+
var localId = resolvedPos.parent.attrs.localId;
|
|
219
|
+
return {
|
|
220
|
+
targetIndex: targetIndex,
|
|
221
|
+
localId: localId
|
|
222
|
+
};
|
|
223
|
+
}
|
|
206
224
|
}, {
|
|
207
225
|
key: "subscribe",
|
|
208
226
|
value: function subscribe() {
|
|
@@ -251,7 +269,7 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
251
269
|
}, {
|
|
252
270
|
key: "initObservers",
|
|
253
271
|
value: function initObservers() {
|
|
254
|
-
var
|
|
272
|
+
var _this3 = this;
|
|
255
273
|
if (!this.dom || this.dom.dataset.isObserved) {
|
|
256
274
|
return;
|
|
257
275
|
}
|
|
@@ -268,15 +286,15 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
268
286
|
window.requestAnimationFrame(function () {
|
|
269
287
|
var _getTree;
|
|
270
288
|
// we expect tree to be defined after animation frame
|
|
271
|
-
var tableContainer = (_getTree = getTree(
|
|
289
|
+
var tableContainer = (_getTree = getTree(_this3.dom)) === null || _getTree === void 0 ? void 0 : _getTree.wrapper.closest(".".concat(TableCssClassName.NODEVIEW_WRAPPER));
|
|
272
290
|
if (tableContainer) {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
[
|
|
291
|
+
_this3.sentinels.top = tableContainer.getElementsByClassName(ClassName.TABLE_STICKY_SENTINEL_TOP).item(0);
|
|
292
|
+
_this3.sentinels.bottom = tableContainer.getElementsByClassName(ClassName.TABLE_STICKY_SENTINEL_BOTTOM).item(0);
|
|
293
|
+
[_this3.sentinels.top, _this3.sentinels.bottom].forEach(function (el) {
|
|
276
294
|
// skip if already observed for another row on this table
|
|
277
295
|
if (el && !el.dataset.isObserved) {
|
|
278
296
|
el.dataset.isObserved = 'true';
|
|
279
|
-
|
|
297
|
+
_this3.intersectionObserver.observe(el);
|
|
280
298
|
}
|
|
281
299
|
});
|
|
282
300
|
}
|
|
@@ -288,27 +306,27 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
288
306
|
}, {
|
|
289
307
|
key: "createResizeObserver",
|
|
290
308
|
value: function createResizeObserver() {
|
|
291
|
-
var
|
|
309
|
+
var _this4 = this;
|
|
292
310
|
this.resizeObserver = new ResizeObserver(function (entries) {
|
|
293
|
-
var tree = getTree(
|
|
311
|
+
var tree = getTree(_this4.dom);
|
|
294
312
|
if (!tree) {
|
|
295
313
|
return;
|
|
296
314
|
}
|
|
297
315
|
var table = tree.table;
|
|
298
316
|
entries.forEach(function (entry) {
|
|
299
|
-
var
|
|
317
|
+
var _this4$editorScrollab;
|
|
300
318
|
// On resize of the parent scroll element we need to adjust the width
|
|
301
319
|
// of the sticky header
|
|
302
|
-
if (entry.target.className === ((
|
|
303
|
-
|
|
320
|
+
if (entry.target.className === ((_this4$editorScrollab = _this4.editorScrollableElement) === null || _this4$editorScrollab === void 0 ? void 0 : _this4$editorScrollab.className)) {
|
|
321
|
+
_this4.updateStickyHeaderWidth();
|
|
304
322
|
} else {
|
|
305
323
|
var newHeight = entry.contentRect ? entry.contentRect.height : entry.target.offsetHeight;
|
|
306
|
-
if (
|
|
324
|
+
if (_this4.sentinels.bottom &&
|
|
307
325
|
// When the table header is sticky, it would be taller by a 1px (border-bottom),
|
|
308
326
|
// So we adding this check to allow a 1px difference.
|
|
309
|
-
Math.abs(newHeight - (
|
|
310
|
-
|
|
311
|
-
|
|
327
|
+
Math.abs(newHeight - (_this4.stickyRowHeight || 0)) > stickyHeaderBorderBottomWidth) {
|
|
328
|
+
_this4.stickyRowHeight = newHeight;
|
|
329
|
+
_this4.sentinels.bottom.style.bottom = "".concat(tableScrollbarOffset + stickyRowOffsetTop + newHeight, "px");
|
|
312
330
|
updateTableMargin(table);
|
|
313
331
|
}
|
|
314
332
|
}
|
|
@@ -318,9 +336,9 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
318
336
|
}, {
|
|
319
337
|
key: "createIntersectionObserver",
|
|
320
338
|
value: function createIntersectionObserver() {
|
|
321
|
-
var
|
|
339
|
+
var _this5 = this;
|
|
322
340
|
this.intersectionObserver = new IntersectionObserver(function (entries, _) {
|
|
323
|
-
var tree = getTree(
|
|
341
|
+
var tree = getTree(_this5.dom);
|
|
324
342
|
if (!tree) {
|
|
325
343
|
return;
|
|
326
344
|
}
|
|
@@ -343,28 +361,28 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
343
361
|
var sentinelIsBelowScrollArea = (((_entry$rootBounds2 = entry.rootBounds) === null || _entry$rootBounds2 === void 0 ? void 0 : _entry$rootBounds2.bottom) || 0) < entry.boundingClientRect.bottom;
|
|
344
362
|
if (!entry.isIntersecting && !sentinelIsBelowScrollArea) {
|
|
345
363
|
var _entry$rootBounds3;
|
|
346
|
-
tree &&
|
|
347
|
-
|
|
364
|
+
tree && _this5.makeHeaderRowSticky(tree, (_entry$rootBounds3 = entry.rootBounds) === null || _entry$rootBounds3 === void 0 ? void 0 : _entry$rootBounds3.top);
|
|
365
|
+
_this5.lastStickyTimestamp = Date.now();
|
|
348
366
|
} else {
|
|
349
|
-
table &&
|
|
367
|
+
table && _this5.makeRowHeaderNotSticky(table);
|
|
350
368
|
}
|
|
351
369
|
}
|
|
352
370
|
if (target.classList.contains(ClassName.TABLE_STICKY_SENTINEL_BOTTOM)) {
|
|
353
371
|
var _entry$rootBounds4;
|
|
354
|
-
var sentinelIsAboveScrollArea = entry.boundingClientRect.top -
|
|
372
|
+
var sentinelIsAboveScrollArea = entry.boundingClientRect.top - _this5.dom.offsetHeight < (((_entry$rootBounds4 = entry.rootBounds) === null || _entry$rootBounds4 === void 0 ? void 0 : _entry$rootBounds4.top) || 0);
|
|
355
373
|
if (table && !entry.isIntersecting && sentinelIsAboveScrollArea) {
|
|
356
374
|
// Not a perfect solution, but need to this code specific for FireFox ED-19177
|
|
357
375
|
if (browser.gecko) {
|
|
358
|
-
if (
|
|
359
|
-
|
|
376
|
+
if (_this5.lastStickyTimestamp && Date.now() - _this5.lastStickyTimestamp > STICKY_HEADER_TOGGLE_TOLERANCE_MS) {
|
|
377
|
+
_this5.makeRowHeaderNotSticky(table);
|
|
360
378
|
}
|
|
361
379
|
} else {
|
|
362
|
-
|
|
380
|
+
_this5.makeRowHeaderNotSticky(table);
|
|
363
381
|
}
|
|
364
382
|
} else if (entry.isIntersecting && sentinelIsAboveScrollArea) {
|
|
365
383
|
var _entry$rootBounds5;
|
|
366
|
-
tree &&
|
|
367
|
-
|
|
384
|
+
tree && _this5.makeHeaderRowSticky(tree, entry === null || entry === void 0 || (_entry$rootBounds5 = entry.rootBounds) === null || _entry$rootBounds5 === void 0 ? void 0 : _entry$rootBounds5.top);
|
|
385
|
+
_this5.lastStickyTimestamp = Date.now();
|
|
368
386
|
}
|
|
369
387
|
}
|
|
370
388
|
return;
|
|
@@ -439,12 +457,12 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
439
457
|
}, {
|
|
440
458
|
key: "refireIntersectionObservers",
|
|
441
459
|
value: function refireIntersectionObservers() {
|
|
442
|
-
var
|
|
460
|
+
var _this6 = this;
|
|
443
461
|
if (this.isSticky) {
|
|
444
462
|
[this.sentinels.top, this.sentinels.bottom].forEach(function (el) {
|
|
445
|
-
if (el &&
|
|
446
|
-
|
|
447
|
-
|
|
463
|
+
if (el && _this6.intersectionObserver) {
|
|
464
|
+
_this6.intersectionObserver.unobserve(el);
|
|
465
|
+
_this6.intersectionObserver.observe(el);
|
|
448
466
|
}
|
|
449
467
|
});
|
|
450
468
|
}
|
|
@@ -453,7 +471,7 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
453
471
|
key: "makeHeaderRowSticky",
|
|
454
472
|
value: function makeHeaderRowSticky(tree, scrollTop) {
|
|
455
473
|
var _tbody$firstChild,
|
|
456
|
-
|
|
474
|
+
_this7 = this;
|
|
457
475
|
// If header row height is more than 50% of viewport height don't do this
|
|
458
476
|
if (this.isSticky || this.stickyRowHeight && this.stickyRowHeight > window.innerHeight / 2) {
|
|
459
477
|
return;
|
|
@@ -490,7 +508,7 @@ var TableRow = /*#__PURE__*/function (_ref) {
|
|
|
490
508
|
});
|
|
491
509
|
var fastScrollThresholdMs = 500;
|
|
492
510
|
setTimeout(function () {
|
|
493
|
-
|
|
511
|
+
_this7.refireIntersectionObservers();
|
|
494
512
|
}, fastScrollThresholdMs);
|
|
495
513
|
}
|
|
496
514
|
this.dom.style.top = "".concat(domTop, "px");
|
package/package.json
CHANGED
|
@@ -192,14 +192,11 @@ export default class TableRow
|
|
|
192
192
|
this.dropTargetCleanup();
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
const resolvedPos = this.view.state.doc.resolve(pos);
|
|
196
|
-
const targetIndex = resolvedPos.index();
|
|
197
|
-
const localId = resolvedPos.parent.attrs.localId;
|
|
198
|
-
|
|
199
195
|
this.dropTargetCleanup = dropTargetForElements({
|
|
200
196
|
element: element,
|
|
201
|
-
canDrop({ source }) {
|
|
197
|
+
canDrop: ({ source }) => {
|
|
202
198
|
const data = source.data as DraggableSourceData;
|
|
199
|
+
const { localId, targetIndex } = this.getCurrentData();
|
|
203
200
|
return (
|
|
204
201
|
// Only draggables of row type can be dropped on this target
|
|
205
202
|
data.type === 'table-row' &&
|
|
@@ -210,7 +207,9 @@ export default class TableRow
|
|
|
210
207
|
data.indexes?.indexOf(targetIndex) === -1
|
|
211
208
|
);
|
|
212
209
|
},
|
|
213
|
-
|
|
210
|
+
getIsSticky: () => true,
|
|
211
|
+
getData: ({ input, element }) => {
|
|
212
|
+
const { localId, targetIndex } = this.getCurrentData();
|
|
214
213
|
const data = {
|
|
215
214
|
localId,
|
|
216
215
|
type: 'table-row',
|
|
@@ -225,6 +224,13 @@ export default class TableRow
|
|
|
225
224
|
});
|
|
226
225
|
}
|
|
227
226
|
|
|
227
|
+
private getCurrentData() {
|
|
228
|
+
const resolvedPos = this.view.state.doc.resolve(this.getPos()!);
|
|
229
|
+
const targetIndex = resolvedPos.index();
|
|
230
|
+
const localId = resolvedPos.parent.attrs.localId;
|
|
231
|
+
return { targetIndex, localId };
|
|
232
|
+
}
|
|
233
|
+
|
|
228
234
|
private headerRowMouseScrollEnd = debounce(() => {
|
|
229
235
|
this.dom.classList.remove('no-pointer-events');
|
|
230
236
|
}, HEADER_ROW_SCROLL_RESET_DEBOUNCE_TIMEOUT);
|