@atlaskit/editor-plugin-table 7.5.5 → 7.5.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 +6 -0
- package/dist/cjs/event-handlers.js +25 -9
- package/dist/cjs/nodeviews/OverflowShadowsObserver.js +24 -15
- package/dist/cjs/nodeviews/TableCell.js +5 -30
- package/dist/cjs/nodeviews/TableComponent.js +74 -24
- package/dist/cjs/nodeviews/TableContainer.js +19 -17
- package/dist/cjs/nodeviews/TableResizer.js +1 -1
- package/dist/cjs/plugin.js +2 -3
- package/dist/cjs/pm-plugins/main.js +3 -18
- package/dist/cjs/ui/TableFloatingColumnControls/index.js +8 -48
- package/dist/cjs/ui/TableFloatingControls/index.js +113 -223
- package/dist/cjs/utils/column-controls.js +5 -5
- package/dist/cjs/utils/dom.js +13 -15
- package/dist/es2019/event-handlers.js +25 -9
- package/dist/es2019/nodeviews/OverflowShadowsObserver.js +24 -15
- package/dist/es2019/nodeviews/TableCell.js +1 -24
- package/dist/es2019/nodeviews/TableComponent.js +63 -27
- package/dist/es2019/nodeviews/TableContainer.js +16 -18
- package/dist/es2019/nodeviews/TableResizer.js +1 -1
- package/dist/es2019/plugin.js +2 -3
- package/dist/es2019/pm-plugins/main.js +3 -18
- package/dist/es2019/ui/TableFloatingColumnControls/index.js +5 -27
- package/dist/es2019/ui/TableFloatingControls/index.js +119 -193
- package/dist/es2019/utils/column-controls.js +6 -6
- package/dist/es2019/utils/dom.js +13 -15
- package/dist/esm/event-handlers.js +25 -9
- package/dist/esm/nodeviews/OverflowShadowsObserver.js +24 -15
- package/dist/esm/nodeviews/TableCell.js +5 -30
- package/dist/esm/nodeviews/TableComponent.js +74 -24
- package/dist/esm/nodeviews/TableContainer.js +20 -18
- package/dist/esm/nodeviews/TableResizer.js +1 -1
- package/dist/esm/plugin.js +2 -3
- package/dist/esm/pm-plugins/main.js +3 -18
- package/dist/esm/ui/TableFloatingColumnControls/index.js +8 -48
- package/dist/esm/ui/TableFloatingControls/index.js +113 -224
- package/dist/esm/utils/column-controls.js +6 -6
- package/dist/esm/utils/dom.js +13 -15
- package/dist/types/event-handlers.d.ts +3 -4
- package/dist/types/nodeviews/OverflowShadowsObserver.d.ts +3 -1
- package/dist/types/nodeviews/TableCell.d.ts +1 -5
- package/dist/types/nodeviews/TableComponent.d.ts +4 -0
- package/dist/types/nodeviews/TableContainer.d.ts +4 -2
- package/dist/types/types.d.ts +0 -3
- package/dist/types/ui/TableFloatingColumnControls/index.d.ts +2 -1
- package/dist/types/ui/TableFloatingControls/index.d.ts +5 -22
- package/dist/types/utils/dom.d.ts +10 -2
- package/dist/types-ts4.5/event-handlers.d.ts +3 -4
- package/dist/types-ts4.5/nodeviews/OverflowShadowsObserver.d.ts +3 -1
- package/dist/types-ts4.5/nodeviews/TableCell.d.ts +1 -5
- package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +4 -0
- package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +4 -2
- package/dist/types-ts4.5/types.d.ts +0 -3
- package/dist/types-ts4.5/ui/TableFloatingColumnControls/index.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableFloatingControls/index.d.ts +5 -22
- package/dist/types-ts4.5/utils/dom.d.ts +10 -2
- package/package.json +3 -4
- package/src/event-handlers.ts +105 -103
- package/src/nodeviews/OverflowShadowsObserver.ts +32 -21
- package/src/nodeviews/TableCell.ts +0 -26
- package/src/nodeviews/TableComponent.tsx +76 -32
- package/src/nodeviews/TableContainer.tsx +19 -25
- package/src/nodeviews/TableResizer.tsx +1 -4
- package/src/plugin.tsx +5 -4
- package/src/pm-plugins/main.ts +3 -22
- package/src/types.ts +0 -4
- package/src/ui/TableFloatingColumnControls/index.tsx +5 -29
- package/src/ui/TableFloatingControls/index.tsx +155 -241
- package/src/utils/column-controls.ts +5 -6
- package/src/utils/dom.ts +12 -19
|
@@ -15,9 +15,6 @@ var _ColumnControls = require("./ColumnControls");
|
|
|
15
15
|
var _ColumnDropTargets = require("./ColumnDropTargets");
|
|
16
16
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
17
17
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
18
|
-
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; } } }; }
|
|
19
|
-
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); }
|
|
20
|
-
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; }
|
|
21
18
|
var TableFloatingColumnControls = exports.TableFloatingColumnControls = function TableFloatingColumnControls(_ref) {
|
|
22
19
|
var editorView = _ref.editorView,
|
|
23
20
|
tableRef = _ref.tableRef,
|
|
@@ -32,54 +29,17 @@ var TableFloatingColumnControls = exports.TableFloatingColumnControls = function
|
|
|
32
29
|
isTableHovered = _ref.isTableHovered,
|
|
33
30
|
tableContainerWidth = _ref.tableContainerWidth,
|
|
34
31
|
isNumberColumnEnabled = _ref.isNumberColumnEnabled,
|
|
35
|
-
getScrollOffset = _ref.getScrollOffset
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
height: 0
|
|
39
|
-
}),
|
|
32
|
+
getScrollOffset = _ref.getScrollOffset,
|
|
33
|
+
tableWrapperHeight = _ref.tableWrapperHeight;
|
|
34
|
+
var _useState = (0, _react.useState)(false),
|
|
40
35
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var _useState3 = (0, _react.useState)(false),
|
|
44
|
-
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
45
|
-
isDragging = _useState4[0],
|
|
46
|
-
setIsDragging = _useState4[1];
|
|
36
|
+
isDragging = _useState2[0],
|
|
37
|
+
setIsDragging = _useState2[1];
|
|
47
38
|
var containerRef = (0, _react.useRef)(null);
|
|
48
39
|
var node = getNode();
|
|
49
40
|
var currentNodeLocalId = node === null || node === void 0 ? void 0 : node.attrs.localId;
|
|
50
41
|
var hasHeaderColumn = (0, _utils.containsHeaderColumn)(node);
|
|
51
42
|
var stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
|
|
52
|
-
(0, _react.useEffect)(function () {
|
|
53
|
-
var _window;
|
|
54
|
-
if (tableRef && (_window = window) !== null && _window !== void 0 && _window.ResizeObserver) {
|
|
55
|
-
var resizeObserver = new ResizeObserver(function (entries) {
|
|
56
|
-
var _iterator = _createForOfIteratorHelper(entries),
|
|
57
|
-
_step;
|
|
58
|
-
try {
|
|
59
|
-
var _loop = function _loop() {
|
|
60
|
-
var entry = _step.value;
|
|
61
|
-
setTableRect(function (prev) {
|
|
62
|
-
if (prev.width !== entry.contentRect.width || prev.height !== entry.contentRect.height) {
|
|
63
|
-
return entry.contentRect;
|
|
64
|
-
}
|
|
65
|
-
return prev;
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
69
|
-
_loop();
|
|
70
|
-
}
|
|
71
|
-
} catch (err) {
|
|
72
|
-
_iterator.e(err);
|
|
73
|
-
} finally {
|
|
74
|
-
_iterator.f();
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
resizeObserver.observe(tableRef);
|
|
78
|
-
return function () {
|
|
79
|
-
resizeObserver.disconnect();
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
}, [tableRef]);
|
|
83
43
|
(0, _react.useEffect)(function () {
|
|
84
44
|
return (0, _adapter.monitorForElements)({
|
|
85
45
|
canMonitor: function canMonitor(_ref2) {
|
|
@@ -100,11 +60,11 @@ var TableFloatingColumnControls = exports.TableFloatingColumnControls = function
|
|
|
100
60
|
}, [editorView, currentNodeLocalId]);
|
|
101
61
|
var rowHeights = (0, _react.useMemo)(function () {
|
|
102
62
|
// NOTE: we don't care so much as to what tableHeight is, we only care that it changed and is a sane value.
|
|
103
|
-
if (tableRef && !!
|
|
63
|
+
if (tableRef && !!tableWrapperHeight) {
|
|
104
64
|
return (0, _utils.getRowHeights)(tableRef);
|
|
105
65
|
}
|
|
106
66
|
return [0];
|
|
107
|
-
}, [tableRef,
|
|
67
|
+
}, [tableRef, tableWrapperHeight]);
|
|
108
68
|
if (!tableRef || !tableActive || isResizing) {
|
|
109
69
|
return null;
|
|
110
70
|
}
|
|
@@ -141,7 +101,7 @@ var TableFloatingColumnControls = exports.TableFloatingColumnControls = function
|
|
|
141
101
|
}), isDragging && /*#__PURE__*/_react.default.createElement(_ColumnDropTargets.ColumnDropTargets, {
|
|
142
102
|
tableRef: tableRef,
|
|
143
103
|
isHeaderSticky: (stickyHeader === null || stickyHeader === void 0 ? void 0 : stickyHeader.sticky) && hasHeaderRow,
|
|
144
|
-
tableHeight:
|
|
104
|
+
tableHeight: tableWrapperHeight,
|
|
145
105
|
localId: currentNodeLocalId,
|
|
146
106
|
colWidths: colWidths,
|
|
147
107
|
getScrollOffset: getScrollOffset
|
|
@@ -5,240 +5,130 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
12
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
13
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
14
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
15
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
8
|
+
exports.default = exports.TableFloatingControls = void 0;
|
|
16
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
17
10
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
18
11
|
var _commands = require("../../commands");
|
|
19
12
|
var _types = require("../../types");
|
|
20
|
-
var _utils2 = require("../../utils");
|
|
21
13
|
var _CornerControls = require("./CornerControls");
|
|
22
14
|
var _NumberColumn = _interopRequireDefault(require("./NumberColumn"));
|
|
23
15
|
var _RowControls = require("./RowControls");
|
|
24
16
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
25
17
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
var editorView = _this.props.editorView;
|
|
50
|
-
var state = editorView.state,
|
|
51
|
-
dispatch = editorView.dispatch;
|
|
52
|
-
// fix for issue ED-4665
|
|
53
|
-
if (_utils.browser.ie_version === 11) {
|
|
54
|
-
editorView.dom.blur();
|
|
55
|
-
}
|
|
56
|
-
(0, _commands.selectRows)(rowIndexes)(state, dispatch);
|
|
57
|
-
});
|
|
58
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "hoverRows", function (rows, danger) {
|
|
59
|
-
var _this$props$editorVie = _this.props.editorView,
|
|
60
|
-
state = _this$props$editorVie.state,
|
|
61
|
-
dispatch = _this$props$editorVie.dispatch;
|
|
62
|
-
(0, _commands.hoverRows)(rows, danger)(state, dispatch);
|
|
63
|
-
});
|
|
64
|
-
// re-use across numbered columns and row controls
|
|
65
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "updateCellHoverLocation", function (rowIndex) {
|
|
66
|
-
var _this$props = _this.props,
|
|
67
|
-
editorView = _this$props.editorView,
|
|
68
|
-
tableActive = _this$props.tableActive;
|
|
69
|
-
var state = editorView.state,
|
|
70
|
-
dispatch = editorView.dispatch;
|
|
71
|
-
if (tableActive) {
|
|
72
|
-
// For context: Whenever we mouse over a column or row drag handle, we will ALWAYS be hovering over the 0 index
|
|
73
|
-
// of the opposite dimension. For example; here when we mouse over the row drag handle then we're technically
|
|
74
|
-
// also hovering over column 0 index. And vice-versa with columns. This means we don't need to worry about knowing the
|
|
75
|
-
// current column index. We can just force it to 0.
|
|
76
|
-
(0, _commands.hoverCell)(rowIndex, 0)(state, dispatch);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
_this.state = {
|
|
80
|
-
tableWrapperWidth: 0,
|
|
81
|
-
/** Height needs to be tracked to re-render decorations correctly, do not remove */
|
|
82
|
-
tableWrapperHeight: 0
|
|
83
|
-
};
|
|
84
|
-
return _this;
|
|
85
|
-
}
|
|
86
|
-
(0, _createClass2.default)(TableFloatingControls, [{
|
|
87
|
-
key: "componentDidMount",
|
|
88
|
-
value: function componentDidMount() {
|
|
89
|
-
this.tryInitResizeObserver();
|
|
18
|
+
var TableFloatingControls = exports.TableFloatingControls = function TableFloatingControls(_ref) {
|
|
19
|
+
var editorView = _ref.editorView,
|
|
20
|
+
tableRef = _ref.tableRef,
|
|
21
|
+
tableNode = _ref.tableNode,
|
|
22
|
+
isInDanger = _ref.isInDanger,
|
|
23
|
+
isResizing = _ref.isResizing,
|
|
24
|
+
isNumberColumnEnabled = _ref.isNumberColumnEnabled,
|
|
25
|
+
isHeaderRowEnabled = _ref.isHeaderRowEnabled,
|
|
26
|
+
isHeaderColumnEnabled = _ref.isHeaderColumnEnabled,
|
|
27
|
+
tableActive = _ref.tableActive,
|
|
28
|
+
hasHeaderRow = _ref.hasHeaderRow,
|
|
29
|
+
hoveredRows = _ref.hoveredRows,
|
|
30
|
+
stickyHeader = _ref.stickyHeader,
|
|
31
|
+
isDragAndDropEnabled = _ref.isDragAndDropEnabled,
|
|
32
|
+
hoveredCell = _ref.hoveredCell,
|
|
33
|
+
isTableHovered = _ref.isTableHovered,
|
|
34
|
+
tableWrapperWidth = _ref.tableWrapperWidth;
|
|
35
|
+
var _selectRow = (0, _react.useCallback)(function (row, expand) {
|
|
36
|
+
var state = editorView.state,
|
|
37
|
+
dispatch = editorView.dispatch;
|
|
38
|
+
// fix for issue ED-4665
|
|
39
|
+
if (_utils.browser.ie_version === 11) {
|
|
40
|
+
editorView.dom.blur();
|
|
90
41
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
42
|
+
(0, _commands.selectRow)(row, expand)(state, dispatch);
|
|
43
|
+
}, [editorView]);
|
|
44
|
+
var _selectRows = (0, _react.useCallback)(function (rowIndexes) {
|
|
45
|
+
var state = editorView.state,
|
|
46
|
+
dispatch = editorView.dispatch;
|
|
47
|
+
// fix for issue ED-4665
|
|
48
|
+
if (_utils.browser.ie_version === 11) {
|
|
49
|
+
editorView.dom.blur();
|
|
96
50
|
}
|
|
51
|
+
(0, _commands.selectRows)(rowIndexes)(state, dispatch);
|
|
52
|
+
}, [editorView]);
|
|
53
|
+
var _hoverRows = (0, _react.useCallback)(function (rows, danger) {
|
|
54
|
+
var state = editorView.state,
|
|
55
|
+
dispatch = editorView.dispatch;
|
|
56
|
+
(0, _commands.hoverRows)(rows, danger)(state, dispatch);
|
|
57
|
+
}, [editorView]);
|
|
97
58
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
var _iterator = _createForOfIteratorHelper(entries),
|
|
109
|
-
_step;
|
|
110
|
-
try {
|
|
111
|
-
var _loop = function _loop() {
|
|
112
|
-
var entry = _step.value;
|
|
113
|
-
_this2.setState(function (prev) {
|
|
114
|
-
return (prev === null || prev === void 0 ? void 0 : prev.tableWrapperWidth) === entry.contentRect.width && prev.tableWrapperHeight === entry.contentRect.height ? prev : {
|
|
115
|
-
tableWrapperWidth: entry.contentRect.width,
|
|
116
|
-
tableWrapperHeight: entry.contentRect.height
|
|
117
|
-
};
|
|
118
|
-
});
|
|
119
|
-
};
|
|
120
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
121
|
-
_loop();
|
|
122
|
-
}
|
|
123
|
-
} catch (err) {
|
|
124
|
-
_iterator.e(err);
|
|
125
|
-
} finally {
|
|
126
|
-
_iterator.f();
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
this.resizeObserver.observe(tableWrapper);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}, {
|
|
133
|
-
key: "shouldComponentUpdate",
|
|
134
|
-
value: function shouldComponentUpdate(nextProps, nextState) {
|
|
135
|
-
var _this$props2 = this.props,
|
|
136
|
-
tableRef = _this$props2.tableRef,
|
|
137
|
-
isInDanger = _this$props2.isInDanger,
|
|
138
|
-
isResizing = _this$props2.isResizing,
|
|
139
|
-
isHeaderRowEnabled = _this$props2.isHeaderRowEnabled,
|
|
140
|
-
isNumberColumnEnabled = _this$props2.isNumberColumnEnabled,
|
|
141
|
-
hoveredRows = _this$props2.hoveredRows,
|
|
142
|
-
selection = _this$props2.selection,
|
|
143
|
-
tableActive = _this$props2.tableActive,
|
|
144
|
-
isHeaderColumnEnabled = _this$props2.isHeaderColumnEnabled,
|
|
145
|
-
ordering = _this$props2.ordering,
|
|
146
|
-
headerRowHeight = _this$props2.headerRowHeight,
|
|
147
|
-
stickyHeader = _this$props2.stickyHeader,
|
|
148
|
-
hoveredCell = _this$props2.hoveredCell,
|
|
149
|
-
isTableHovered = _this$props2.isTableHovered;
|
|
150
|
-
return this.state.tableWrapperWidth !== nextState.tableWrapperWidth || this.state.tableWrapperHeight !== nextState.tableWrapperHeight || ordering !== nextProps.ordering || tableRef !== nextProps.tableRef || tableActive !== nextProps.tableActive || isInDanger !== nextProps.isInDanger || isResizing !== nextProps.isResizing || hoveredRows !== nextProps.hoveredRows || isHeaderRowEnabled !== nextProps.isHeaderRowEnabled || isHeaderColumnEnabled !== nextProps.isHeaderColumnEnabled || isNumberColumnEnabled !== nextProps.isNumberColumnEnabled || (0, _utils2.isSelectionUpdated)(selection, nextProps.selection) || headerRowHeight !== nextProps.headerRowHeight || stickyHeader !== nextProps.stickyHeader || hoveredCell !== nextProps.hoveredCell || isTableHovered !== nextProps.isTableHovered;
|
|
59
|
+
// re-use across numbered columns and row controls
|
|
60
|
+
var updateCellHoverLocation = (0, _react.useCallback)(function (rowIndex) {
|
|
61
|
+
var state = editorView.state,
|
|
62
|
+
dispatch = editorView.dispatch;
|
|
63
|
+
if (tableActive) {
|
|
64
|
+
// For context: Whenever we mouse over a column or row drag handle, we will ALWAYS be hovering over the 0 index
|
|
65
|
+
// of the opposite dimension. For example; here when we mouse over the row drag handle then we're technically
|
|
66
|
+
// also hovering over column 0 index. And vice-versa with columns. This means we don't need to worry about knowing the
|
|
67
|
+
// current column index. We can just force it to 0.
|
|
68
|
+
(0, _commands.hoverCell)(rowIndex, 0)(state, dispatch);
|
|
151
69
|
}
|
|
152
|
-
},
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
editorView = _this$props3.editorView,
|
|
164
|
-
tableRef = _this$props3.tableRef,
|
|
165
|
-
tableNode = _this$props3.tableNode,
|
|
166
|
-
isInDanger = _this$props3.isInDanger,
|
|
167
|
-
isResizing = _this$props3.isResizing,
|
|
168
|
-
isNumberColumnEnabled = _this$props3.isNumberColumnEnabled,
|
|
169
|
-
isHeaderRowEnabled = _this$props3.isHeaderRowEnabled,
|
|
170
|
-
isHeaderColumnEnabled = _this$props3.isHeaderColumnEnabled,
|
|
171
|
-
tableActive = _this$props3.tableActive,
|
|
172
|
-
hasHeaderRow = _this$props3.hasHeaderRow,
|
|
173
|
-
hoveredRows = _this$props3.hoveredRows,
|
|
174
|
-
stickyHeader = _this$props3.stickyHeader,
|
|
175
|
-
isDragAndDropEnabled = _this$props3.isDragAndDropEnabled,
|
|
176
|
-
hoveredCell = _this$props3.hoveredCell,
|
|
177
|
-
isTableHovered = _this$props3.isTableHovered;
|
|
178
|
-
if (!tableRef) {
|
|
179
|
-
return null;
|
|
180
|
-
}
|
|
181
|
-
var stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
|
|
182
|
-
var wrapperClassName = isDragAndDropEnabled ? _types.TableCssClassName.DRAG_ROW_CONTROLS_WRAPPER : _types.TableCssClassName.ROW_CONTROLS_WRAPPER;
|
|
183
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
184
|
-
className: wrapperClassName
|
|
185
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
186
|
-
onMouseDown: function onMouseDown(e) {
|
|
187
|
-
return !isDragAndDropEnabled && e.preventDefault();
|
|
188
|
-
}
|
|
189
|
-
}, isNumberColumnEnabled ? /*#__PURE__*/_react.default.createElement(_NumberColumn.default, {
|
|
190
|
-
editorView: editorView,
|
|
191
|
-
hoverRows: this.hoverRows,
|
|
192
|
-
tableRef: tableRef,
|
|
193
|
-
tableActive: tableActive,
|
|
194
|
-
hoveredRows: hoveredRows,
|
|
195
|
-
hasHeaderRow: hasHeaderRow,
|
|
196
|
-
isInDanger: isInDanger,
|
|
197
|
-
isResizing: isResizing,
|
|
198
|
-
selectRow: this.selectRow,
|
|
199
|
-
updateCellHoverLocation: this.updateCellHoverLocation,
|
|
200
|
-
stickyTop: stickyTop,
|
|
201
|
-
isDragAndDropEnabled: isDragAndDropEnabled
|
|
202
|
-
}) : null, tableActive && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isDragAndDropEnabled ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_CornerControls.DragCornerControls, {
|
|
203
|
-
editorView: editorView,
|
|
204
|
-
tableRef: tableRef,
|
|
205
|
-
isInDanger: isInDanger,
|
|
206
|
-
isResizing: isResizing
|
|
207
|
-
}), /*#__PURE__*/_react.default.createElement(_RowControls.DragControls, {
|
|
208
|
-
tableRef: tableRef,
|
|
209
|
-
tableNode: tableNode,
|
|
210
|
-
hoveredCell: hoveredCell,
|
|
211
|
-
isTableHovered: isTableHovered,
|
|
212
|
-
editorView: editorView,
|
|
213
|
-
tableActive: tableActive,
|
|
214
|
-
isInDanger: isInDanger,
|
|
215
|
-
isResizing: isResizing,
|
|
216
|
-
tableWidth: this.state.tableWrapperWidth,
|
|
217
|
-
hoverRows: this.hoverRows,
|
|
218
|
-
selectRow: this.selectRow,
|
|
219
|
-
selectRows: this.selectRows,
|
|
220
|
-
updateCellHoverLocation: this.updateCellHoverLocation
|
|
221
|
-
})) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_CornerControls.CornerControls, {
|
|
222
|
-
editorView: editorView,
|
|
223
|
-
tableRef: tableRef,
|
|
224
|
-
isInDanger: isInDanger,
|
|
225
|
-
isResizing: isResizing,
|
|
226
|
-
isHeaderRowEnabled: isHeaderRowEnabled,
|
|
227
|
-
isHeaderColumnEnabled: isHeaderColumnEnabled,
|
|
228
|
-
hoveredRows: hoveredRows,
|
|
229
|
-
stickyTop: tableActive ? stickyTop : undefined
|
|
230
|
-
}), /*#__PURE__*/_react.default.createElement(_RowControls.RowControls, {
|
|
231
|
-
editorView: editorView,
|
|
232
|
-
tableRef: tableRef,
|
|
233
|
-
hoverRows: this.hoverRows,
|
|
234
|
-
hoveredRows: hoveredRows,
|
|
235
|
-
isInDanger: isInDanger,
|
|
236
|
-
isResizing: isResizing,
|
|
237
|
-
selectRow: this.selectRow,
|
|
238
|
-
stickyTop: tableActive ? stickyTop : undefined
|
|
239
|
-
})))));
|
|
70
|
+
}, [editorView, tableActive]);
|
|
71
|
+
if (!tableRef) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
var stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
|
|
75
|
+
var wrapperClassName = isDragAndDropEnabled ? _types.TableCssClassName.DRAG_ROW_CONTROLS_WRAPPER : _types.TableCssClassName.ROW_CONTROLS_WRAPPER;
|
|
76
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
77
|
+
className: wrapperClassName
|
|
78
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
79
|
+
onMouseDown: function onMouseDown(e) {
|
|
80
|
+
return !isDragAndDropEnabled && e.preventDefault();
|
|
240
81
|
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
82
|
+
}, isNumberColumnEnabled ? /*#__PURE__*/_react.default.createElement(_NumberColumn.default, {
|
|
83
|
+
editorView: editorView,
|
|
84
|
+
hoverRows: _hoverRows,
|
|
85
|
+
tableRef: tableRef,
|
|
86
|
+
tableActive: tableActive,
|
|
87
|
+
hoveredRows: hoveredRows,
|
|
88
|
+
hasHeaderRow: hasHeaderRow,
|
|
89
|
+
isInDanger: isInDanger,
|
|
90
|
+
isResizing: isResizing,
|
|
91
|
+
selectRow: _selectRow,
|
|
92
|
+
updateCellHoverLocation: updateCellHoverLocation,
|
|
93
|
+
stickyTop: stickyTop,
|
|
94
|
+
isDragAndDropEnabled: isDragAndDropEnabled
|
|
95
|
+
}) : null, tableActive && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isDragAndDropEnabled ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_CornerControls.DragCornerControls, {
|
|
96
|
+
editorView: editorView,
|
|
97
|
+
tableRef: tableRef,
|
|
98
|
+
isInDanger: isInDanger,
|
|
99
|
+
isResizing: isResizing
|
|
100
|
+
}), /*#__PURE__*/_react.default.createElement(_RowControls.DragControls, {
|
|
101
|
+
tableRef: tableRef,
|
|
102
|
+
tableNode: tableNode,
|
|
103
|
+
hoveredCell: hoveredCell,
|
|
104
|
+
isTableHovered: isTableHovered,
|
|
105
|
+
editorView: editorView,
|
|
106
|
+
tableActive: tableActive,
|
|
107
|
+
isInDanger: isInDanger,
|
|
108
|
+
isResizing: isResizing,
|
|
109
|
+
tableWidth: tableWrapperWidth,
|
|
110
|
+
hoverRows: _hoverRows,
|
|
111
|
+
selectRow: _selectRow,
|
|
112
|
+
selectRows: _selectRows,
|
|
113
|
+
updateCellHoverLocation: updateCellHoverLocation
|
|
114
|
+
})) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_CornerControls.CornerControls, {
|
|
115
|
+
editorView: editorView,
|
|
116
|
+
tableRef: tableRef,
|
|
117
|
+
isInDanger: isInDanger,
|
|
118
|
+
isResizing: isResizing,
|
|
119
|
+
isHeaderRowEnabled: isHeaderRowEnabled,
|
|
120
|
+
isHeaderColumnEnabled: isHeaderColumnEnabled,
|
|
121
|
+
hoveredRows: hoveredRows,
|
|
122
|
+
stickyTop: tableActive ? stickyTop : undefined
|
|
123
|
+
}), /*#__PURE__*/_react.default.createElement(_RowControls.RowControls, {
|
|
124
|
+
editorView: editorView,
|
|
125
|
+
tableRef: tableRef,
|
|
126
|
+
hoverRows: _hoverRows,
|
|
127
|
+
hoveredRows: hoveredRows,
|
|
128
|
+
isInDanger: isInDanger,
|
|
129
|
+
isResizing: isResizing,
|
|
130
|
+
selectRow: _selectRow,
|
|
131
|
+
stickyTop: tableActive ? stickyTop : undefined
|
|
132
|
+
})))));
|
|
133
|
+
};
|
|
134
|
+
var _default = exports.default = TableFloatingControls;
|
|
@@ -26,13 +26,13 @@ var getColumnsWidths = exports.getColumnsWidths = function getColumnsWidths(view
|
|
|
26
26
|
length: map.width
|
|
27
27
|
});
|
|
28
28
|
for (var i = 0; i < map.width; i++) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
var cellRef = (0, _utils2.findDomRefAtPos)(
|
|
29
|
+
if (!map.isCellMergedTopLeft(0, i)) {
|
|
30
|
+
var node = table.node.nodeAt(map.map[i]);
|
|
31
|
+
var pos = map.map[i] + table.start;
|
|
32
|
+
var cellRef = (0, _utils2.findDomRefAtPos)(pos, domAtPos);
|
|
33
33
|
var rect = cellRef.getBoundingClientRect();
|
|
34
34
|
widths[i] = (rect ? rect.width : cellRef.offsetWidth) + 1;
|
|
35
|
-
i +=
|
|
35
|
+
i += node.attrs.colspan - 1;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
}
|
package/dist/cjs/utils/dom.js
CHANGED
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.isTableControlsButton = exports.isTableContainerOrWrapper = exports.isRowControlsButton = exports.isResizeHandleDecoration = exports.isInsertRowButton = exports.isDragRowFloatingInsertDot = exports.isDragRowControlsButton = exports.isDragCornerButton = exports.isDragColumnFloatingInsertDot = exports.isCornerButton = exports.isColumnControlsDecorations = exports.isCell = exports.hasResizeHandler = exports.getTree = exports.getTop = exports.getMousePositionVerticalRelativeByElement = exports.getMousePositionHorizontalRelativeByElement = exports.getColumnOrRowIndex = exports.findNearestCellIndexToPoint = void 0;
|
|
7
7
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
8
8
|
var _types = require("../types");
|
|
9
|
-
var SELECTOR_TABLE_LEAFS = ".".concat(_types.TableCssClassName.TABLE_CELL, ", .").concat(_types.TableCssClassName.TABLE_HEADER_CELL);
|
|
10
9
|
var isCell = exports.isCell = function isCell(node) {
|
|
11
10
|
return Boolean(node && (['TH', 'TD'].indexOf(node.tagName) > -1 || !!(0, _utils.closestElement)(node, ".".concat(_types.TableCssClassName.TABLE_HEADER_CELL)) || !!(0, _utils.closestElement)(node, ".".concat(_types.TableCssClassName.TABLE_CELL))));
|
|
12
11
|
};
|
|
@@ -102,22 +101,21 @@ var isDragCornerButton = exports.isDragCornerButton = function isDragCornerButto
|
|
|
102
101
|
*
|
|
103
102
|
* the same is valid to the right side.
|
|
104
103
|
*/
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
/**
|
|
105
|
+
* This can be used with mouse events to determine the left/right side of the target the pointer is closest too.
|
|
106
|
+
*
|
|
107
|
+
* WARNING: This metod reads properties which can trigger a reflow; use this wisely.
|
|
108
|
+
*
|
|
109
|
+
* @param mouseEvent
|
|
110
|
+
* @param gapInPixels
|
|
111
|
+
* @returns
|
|
112
|
+
*/
|
|
113
|
+
var getMousePositionHorizontalRelativeByElement = exports.getMousePositionHorizontalRelativeByElement = function getMousePositionHorizontalRelativeByElement(mouseEvent, offsetX, gapInPixels) {
|
|
107
114
|
var element = mouseEvent.target;
|
|
108
115
|
if (element instanceof HTMLElement) {
|
|
109
|
-
var width
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
// directly from element that will be .pm-table-drag-columns-floating-insert-dot-wrapper
|
|
113
|
-
width = element.clientWidth;
|
|
114
|
-
} else {
|
|
115
|
-
var _closestCell$id, _elementContentRects$, _elementContentRects$2;
|
|
116
|
-
var closestCell = element.closest(SELECTOR_TABLE_LEAFS);
|
|
117
|
-
var id = (_closestCell$id = closestCell === null || closestCell === void 0 ? void 0 : closestCell.id) !== null && _closestCell$id !== void 0 ? _closestCell$id : '';
|
|
118
|
-
width = (_elementContentRects$ = elementContentRects === null || elementContentRects === void 0 || (_elementContentRects$2 = elementContentRects[id]) === null || _elementContentRects$2 === void 0 ? void 0 : _elementContentRects$2.width) !== null && _elementContentRects$ !== void 0 ? _elementContentRects$ : 0;
|
|
119
|
-
}
|
|
120
|
-
x = mouseEvent.offsetX;
|
|
116
|
+
var width = element.clientWidth; // reflow
|
|
117
|
+
var x = !Number.isNaN(offsetX) ? offsetX : mouseEvent.offsetX; // reflow
|
|
118
|
+
|
|
121
119
|
if (width <= 0) {
|
|
122
120
|
return null;
|
|
123
121
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import rafSchedule from 'raf-schd';
|
|
1
2
|
import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
|
|
2
3
|
import { browser, closestElement, isElementInTableCell, isLastItemMediaGroup, setNodeSelection } from '@atlaskit/editor-common/utils';
|
|
3
4
|
import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
@@ -261,7 +262,10 @@ export const handleMouseLeave = (view, event) => {
|
|
|
261
262
|
}
|
|
262
263
|
return false;
|
|
263
264
|
};
|
|
264
|
-
|
|
265
|
+
|
|
266
|
+
// IMPORTANT: The mouse move handler has been setup with RAF schedule to avoid Reflows which will occur as some methods
|
|
267
|
+
// need to access the mouse event offset position and also the target clientWidth vallue.
|
|
268
|
+
const handleMouseMoveDebounce = rafSchedule((view, event, offsetX) => {
|
|
265
269
|
if (!(event.target instanceof HTMLElement)) {
|
|
266
270
|
return false;
|
|
267
271
|
}
|
|
@@ -272,11 +276,10 @@ export const handleMouseMove = (view, event, elementContentRects) => {
|
|
|
272
276
|
dispatch
|
|
273
277
|
} = view;
|
|
274
278
|
const {
|
|
275
|
-
insertColumnButtonIndex
|
|
276
|
-
isDragAndDropEnabled
|
|
279
|
+
insertColumnButtonIndex
|
|
277
280
|
} = getPluginState(state);
|
|
278
281
|
const [startIndex, endIndex] = getColumnOrRowIndex(element);
|
|
279
|
-
const positionColumn = getMousePositionHorizontalRelativeByElement(event,
|
|
282
|
+
const positionColumn = getMousePositionHorizontalRelativeByElement(event, offsetX, undefined) === 'right' ? endIndex : startIndex;
|
|
280
283
|
if (positionColumn !== insertColumnButtonIndex) {
|
|
281
284
|
return showInsertColumnButton(positionColumn)(state, dispatch);
|
|
282
285
|
}
|
|
@@ -296,7 +299,7 @@ export const handleMouseMove = (view, event, elementContentRects) => {
|
|
|
296
299
|
}
|
|
297
300
|
}
|
|
298
301
|
if (!isResizeHandleDecoration(element) && isCell(element)) {
|
|
299
|
-
const positionColumn = getMousePositionHorizontalRelativeByElement(event,
|
|
302
|
+
const positionColumn = getMousePositionHorizontalRelativeByElement(event, offsetX, RESIZE_HANDLE_AREA_DECORATION_GAP);
|
|
300
303
|
if (positionColumn !== null) {
|
|
301
304
|
const {
|
|
302
305
|
state,
|
|
@@ -324,6 +327,19 @@ export const handleMouseMove = (view, event, elementContentRects) => {
|
|
|
324
327
|
}
|
|
325
328
|
}
|
|
326
329
|
return false;
|
|
330
|
+
});
|
|
331
|
+
export const handleMouseMove = (view, event) => {
|
|
332
|
+
if (!(event.target instanceof HTMLElement)) {
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// NOTE: When accessing offsetX in gecko from a deferred callback, it will return 0. However it will be non-zero if accessed
|
|
337
|
+
// within the scope of it's initial mouse move handler. Also Chrome does return the correct value, however it could trigger
|
|
338
|
+
// a reflow. So for now this will just grab the offsetX value immediately for gecko and chrome will calculate later
|
|
339
|
+
// in the deferred callback handler.
|
|
340
|
+
// Bug Tracking: https://bugzilla.mozilla.org/show_bug.cgi?id=1882903
|
|
341
|
+
handleMouseMoveDebounce(view, event, browser.gecko ? event.offsetX : NaN);
|
|
342
|
+
return false;
|
|
327
343
|
};
|
|
328
344
|
export function handleTripleClick(view, pos) {
|
|
329
345
|
const {
|
|
@@ -406,11 +422,11 @@ export const isTableInFocus = view => {
|
|
|
406
422
|
var _getPluginState, _getResizePluginState;
|
|
407
423
|
return !!((_getPluginState = getPluginState(view.state)) !== null && _getPluginState !== void 0 && _getPluginState.tableNode) && !((_getResizePluginState = getResizePluginState(view.state)) !== null && _getResizePluginState !== void 0 && _getResizePluginState.dragging);
|
|
408
424
|
};
|
|
409
|
-
export const whenTableInFocus =
|
|
425
|
+
export const whenTableInFocus = eventHandler => (view, mouseEvent) => {
|
|
410
426
|
if (!isTableInFocus(view)) {
|
|
411
427
|
return false;
|
|
412
428
|
}
|
|
413
|
-
return eventHandler(view, mouseEvent
|
|
429
|
+
return eventHandler(view, mouseEvent);
|
|
414
430
|
};
|
|
415
431
|
const trackCellLocation = (view, mouseEvent) => {
|
|
416
432
|
var _tableElement$dataset;
|
|
@@ -440,9 +456,9 @@ const trackCellLocation = (view, mouseEvent) => {
|
|
|
440
456
|
}
|
|
441
457
|
hoverCell(htmlRowIndex, colIndex)(view.state, view.dispatch);
|
|
442
458
|
};
|
|
443
|
-
export const withCellTracking =
|
|
459
|
+
export const withCellTracking = eventHandler => (view, mouseEvent) => {
|
|
444
460
|
if (getPluginState(view.state).isDragAndDropEnabled && !getDragDropPluginState(view.state).isDragging) {
|
|
445
461
|
trackCellLocation(view, mouseEvent);
|
|
446
462
|
}
|
|
447
|
-
return eventHandler(view, mouseEvent
|
|
463
|
+
return eventHandler(view, mouseEvent);
|
|
448
464
|
};
|