@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
|
@@ -1,205 +1,131 @@
|
|
|
1
|
-
import
|
|
2
|
-
import React, { Component } from 'react';
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
3
2
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
4
3
|
import { hoverCell, hoverRows, selectRow, selectRows } from '../../commands';
|
|
5
4
|
import { TableCssClassName as ClassName } from '../../types';
|
|
6
|
-
import { isSelectionUpdated } from '../../utils';
|
|
7
5
|
import { CornerControls, DragCornerControls } from './CornerControls';
|
|
8
6
|
import NumberColumn from './NumberColumn';
|
|
9
7
|
import { DragControls, RowControls } from './RowControls';
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (browser.ie_version === 11) {
|
|
37
|
-
editorView.dom.blur();
|
|
38
|
-
}
|
|
39
|
-
selectRows(rowIndexes)(state, dispatch);
|
|
40
|
-
});
|
|
41
|
-
_defineProperty(this, "hoverRows", (rows, danger) => {
|
|
42
|
-
const {
|
|
43
|
-
state,
|
|
44
|
-
dispatch
|
|
45
|
-
} = this.props.editorView;
|
|
46
|
-
hoverRows(rows, danger)(state, dispatch);
|
|
47
|
-
});
|
|
48
|
-
// re-use across numbered columns and row controls
|
|
49
|
-
_defineProperty(this, "updateCellHoverLocation", rowIndex => {
|
|
50
|
-
const {
|
|
51
|
-
editorView,
|
|
52
|
-
tableActive
|
|
53
|
-
} = this.props;
|
|
54
|
-
const {
|
|
55
|
-
state,
|
|
56
|
-
dispatch
|
|
57
|
-
} = editorView;
|
|
58
|
-
if (tableActive) {
|
|
59
|
-
// For context: Whenever we mouse over a column or row drag handle, we will ALWAYS be hovering over the 0 index
|
|
60
|
-
// of the opposite dimension. For example; here when we mouse over the row drag handle then we're technically
|
|
61
|
-
// also hovering over column 0 index. And vice-versa with columns. This means we don't need to worry about knowing the
|
|
62
|
-
// current column index. We can just force it to 0.
|
|
63
|
-
hoverCell(rowIndex, 0)(state, dispatch);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
this.state = {
|
|
67
|
-
tableWrapperWidth: 0,
|
|
68
|
-
/** Height needs to be tracked to re-render decorations correctly, do not remove */
|
|
69
|
-
tableWrapperHeight: 0
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
componentDidMount() {
|
|
73
|
-
this.tryInitResizeObserver();
|
|
74
|
-
}
|
|
75
|
-
componentDidUpdate() {
|
|
76
|
-
// tableRef prop is not guaranteed to be defined after componentDidMount, so retry to init resize observer on update
|
|
77
|
-
this.tryInitResizeObserver();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// tracking the table height changes to update floating controls
|
|
81
|
-
tryInitResizeObserver() {
|
|
82
|
-
var _window;
|
|
83
|
-
let {
|
|
84
|
-
tableRef
|
|
85
|
-
} = this.props;
|
|
86
|
-
if (tableRef && !this.resizeObserver && (_window = window) !== null && _window !== void 0 && _window.ResizeObserver) {
|
|
87
|
-
const tableWrapper = tableRef.closest(`.${ClassName.TABLE_NODE_WRAPPER}`);
|
|
88
|
-
this.resizeObserver = new ResizeObserver(entries => {
|
|
89
|
-
for (let entry of entries) {
|
|
90
|
-
this.setState(prev => {
|
|
91
|
-
return (prev === null || prev === void 0 ? void 0 : prev.tableWrapperWidth) === entry.contentRect.width && prev.tableWrapperHeight === entry.contentRect.height ? prev : {
|
|
92
|
-
tableWrapperWidth: entry.contentRect.width,
|
|
93
|
-
tableWrapperHeight: entry.contentRect.height
|
|
94
|
-
};
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
this.resizeObserver.observe(tableWrapper);
|
|
8
|
+
export const TableFloatingControls = ({
|
|
9
|
+
editorView,
|
|
10
|
+
tableRef,
|
|
11
|
+
tableNode,
|
|
12
|
+
isInDanger,
|
|
13
|
+
isResizing,
|
|
14
|
+
isNumberColumnEnabled,
|
|
15
|
+
isHeaderRowEnabled,
|
|
16
|
+
isHeaderColumnEnabled,
|
|
17
|
+
tableActive,
|
|
18
|
+
hasHeaderRow,
|
|
19
|
+
hoveredRows,
|
|
20
|
+
stickyHeader,
|
|
21
|
+
isDragAndDropEnabled,
|
|
22
|
+
hoveredCell,
|
|
23
|
+
isTableHovered,
|
|
24
|
+
tableWrapperWidth
|
|
25
|
+
}) => {
|
|
26
|
+
const _selectRow = useCallback((row, expand) => {
|
|
27
|
+
const {
|
|
28
|
+
state,
|
|
29
|
+
dispatch
|
|
30
|
+
} = editorView;
|
|
31
|
+
// fix for issue ED-4665
|
|
32
|
+
if (browser.ie_version === 11) {
|
|
33
|
+
editorView.dom.blur();
|
|
99
34
|
}
|
|
100
|
-
|
|
101
|
-
|
|
35
|
+
selectRow(row, expand)(state, dispatch);
|
|
36
|
+
}, [editorView]);
|
|
37
|
+
const _selectRows = useCallback(rowIndexes => {
|
|
102
38
|
const {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
selection,
|
|
110
|
-
tableActive,
|
|
111
|
-
isHeaderColumnEnabled,
|
|
112
|
-
ordering,
|
|
113
|
-
headerRowHeight,
|
|
114
|
-
stickyHeader,
|
|
115
|
-
hoveredCell,
|
|
116
|
-
isTableHovered
|
|
117
|
-
} = this.props;
|
|
118
|
-
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 || isSelectionUpdated(selection, nextProps.selection) || headerRowHeight !== nextProps.headerRowHeight || stickyHeader !== nextProps.stickyHeader || hoveredCell !== nextProps.hoveredCell || isTableHovered !== nextProps.isTableHovered;
|
|
119
|
-
}
|
|
120
|
-
componentWillUnmount() {
|
|
121
|
-
if (this.resizeObserver) {
|
|
122
|
-
this.resizeObserver.disconnect();
|
|
39
|
+
state,
|
|
40
|
+
dispatch
|
|
41
|
+
} = editorView;
|
|
42
|
+
// fix for issue ED-4665
|
|
43
|
+
if (browser.ie_version === 11) {
|
|
44
|
+
editorView.dom.blur();
|
|
123
45
|
}
|
|
124
|
-
|
|
125
|
-
|
|
46
|
+
selectRows(rowIndexes)(state, dispatch);
|
|
47
|
+
}, [editorView]);
|
|
48
|
+
const _hoverRows = useCallback((rows, danger) => {
|
|
49
|
+
const {
|
|
50
|
+
state,
|
|
51
|
+
dispatch
|
|
52
|
+
} = editorView;
|
|
53
|
+
hoverRows(rows, danger)(state, dispatch);
|
|
54
|
+
}, [editorView]);
|
|
55
|
+
|
|
56
|
+
// re-use across numbered columns and row controls
|
|
57
|
+
const updateCellHoverLocation = useCallback(rowIndex => {
|
|
126
58
|
const {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
hasHeaderRow,
|
|
137
|
-
hoveredRows,
|
|
138
|
-
stickyHeader,
|
|
139
|
-
isDragAndDropEnabled,
|
|
140
|
-
hoveredCell,
|
|
141
|
-
isTableHovered
|
|
142
|
-
} = this.props;
|
|
143
|
-
if (!tableRef) {
|
|
144
|
-
return null;
|
|
59
|
+
state,
|
|
60
|
+
dispatch
|
|
61
|
+
} = editorView;
|
|
62
|
+
if (tableActive) {
|
|
63
|
+
// For context: Whenever we mouse over a column or row drag handle, we will ALWAYS be hovering over the 0 index
|
|
64
|
+
// of the opposite dimension. For example; here when we mouse over the row drag handle then we're technically
|
|
65
|
+
// also hovering over column 0 index. And vice-versa with columns. This means we don't need to worry about knowing the
|
|
66
|
+
// current column index. We can just force it to 0.
|
|
67
|
+
hoverCell(rowIndex, 0)(state, dispatch);
|
|
145
68
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return
|
|
149
|
-
className: wrapperClassName
|
|
150
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
151
|
-
onMouseDown: e => !isDragAndDropEnabled && e.preventDefault()
|
|
152
|
-
}, isNumberColumnEnabled ? /*#__PURE__*/React.createElement(NumberColumn, {
|
|
153
|
-
editorView: editorView,
|
|
154
|
-
hoverRows: this.hoverRows,
|
|
155
|
-
tableRef: tableRef,
|
|
156
|
-
tableActive: tableActive,
|
|
157
|
-
hoveredRows: hoveredRows,
|
|
158
|
-
hasHeaderRow: hasHeaderRow,
|
|
159
|
-
isInDanger: isInDanger,
|
|
160
|
-
isResizing: isResizing,
|
|
161
|
-
selectRow: this.selectRow,
|
|
162
|
-
updateCellHoverLocation: this.updateCellHoverLocation,
|
|
163
|
-
stickyTop: stickyTop,
|
|
164
|
-
isDragAndDropEnabled: isDragAndDropEnabled
|
|
165
|
-
}) : null, tableActive && /*#__PURE__*/React.createElement(React.Fragment, null, isDragAndDropEnabled ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DragCornerControls, {
|
|
166
|
-
editorView: editorView,
|
|
167
|
-
tableRef: tableRef,
|
|
168
|
-
isInDanger: isInDanger,
|
|
169
|
-
isResizing: isResizing
|
|
170
|
-
}), /*#__PURE__*/React.createElement(DragControls, {
|
|
171
|
-
tableRef: tableRef,
|
|
172
|
-
tableNode: tableNode,
|
|
173
|
-
hoveredCell: hoveredCell,
|
|
174
|
-
isTableHovered: isTableHovered,
|
|
175
|
-
editorView: editorView,
|
|
176
|
-
tableActive: tableActive,
|
|
177
|
-
isInDanger: isInDanger,
|
|
178
|
-
isResizing: isResizing,
|
|
179
|
-
tableWidth: this.state.tableWrapperWidth,
|
|
180
|
-
hoverRows: this.hoverRows,
|
|
181
|
-
selectRow: this.selectRow,
|
|
182
|
-
selectRows: this.selectRows,
|
|
183
|
-
updateCellHoverLocation: this.updateCellHoverLocation
|
|
184
|
-
})) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CornerControls, {
|
|
185
|
-
editorView: editorView,
|
|
186
|
-
tableRef: tableRef,
|
|
187
|
-
isInDanger: isInDanger,
|
|
188
|
-
isResizing: isResizing,
|
|
189
|
-
isHeaderRowEnabled: isHeaderRowEnabled,
|
|
190
|
-
isHeaderColumnEnabled: isHeaderColumnEnabled,
|
|
191
|
-
hoveredRows: hoveredRows,
|
|
192
|
-
stickyTop: tableActive ? stickyTop : undefined
|
|
193
|
-
}), /*#__PURE__*/React.createElement(RowControls, {
|
|
194
|
-
editorView: editorView,
|
|
195
|
-
tableRef: tableRef,
|
|
196
|
-
hoverRows: this.hoverRows,
|
|
197
|
-
hoveredRows: hoveredRows,
|
|
198
|
-
isInDanger: isInDanger,
|
|
199
|
-
isResizing: isResizing,
|
|
200
|
-
selectRow: this.selectRow,
|
|
201
|
-
stickyTop: tableActive ? stickyTop : undefined
|
|
202
|
-
})))));
|
|
69
|
+
}, [editorView, tableActive]);
|
|
70
|
+
if (!tableRef) {
|
|
71
|
+
return null;
|
|
203
72
|
}
|
|
204
|
-
|
|
205
|
-
|
|
73
|
+
const stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
|
|
74
|
+
const wrapperClassName = isDragAndDropEnabled ? ClassName.DRAG_ROW_CONTROLS_WRAPPER : ClassName.ROW_CONTROLS_WRAPPER;
|
|
75
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
76
|
+
className: wrapperClassName
|
|
77
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
78
|
+
onMouseDown: e => !isDragAndDropEnabled && e.preventDefault()
|
|
79
|
+
}, isNumberColumnEnabled ? /*#__PURE__*/React.createElement(NumberColumn, {
|
|
80
|
+
editorView: editorView,
|
|
81
|
+
hoverRows: _hoverRows,
|
|
82
|
+
tableRef: tableRef,
|
|
83
|
+
tableActive: tableActive,
|
|
84
|
+
hoveredRows: hoveredRows,
|
|
85
|
+
hasHeaderRow: hasHeaderRow,
|
|
86
|
+
isInDanger: isInDanger,
|
|
87
|
+
isResizing: isResizing,
|
|
88
|
+
selectRow: _selectRow,
|
|
89
|
+
updateCellHoverLocation: updateCellHoverLocation,
|
|
90
|
+
stickyTop: stickyTop,
|
|
91
|
+
isDragAndDropEnabled: isDragAndDropEnabled
|
|
92
|
+
}) : null, tableActive && /*#__PURE__*/React.createElement(React.Fragment, null, isDragAndDropEnabled ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DragCornerControls, {
|
|
93
|
+
editorView: editorView,
|
|
94
|
+
tableRef: tableRef,
|
|
95
|
+
isInDanger: isInDanger,
|
|
96
|
+
isResizing: isResizing
|
|
97
|
+
}), /*#__PURE__*/React.createElement(DragControls, {
|
|
98
|
+
tableRef: tableRef,
|
|
99
|
+
tableNode: tableNode,
|
|
100
|
+
hoveredCell: hoveredCell,
|
|
101
|
+
isTableHovered: isTableHovered,
|
|
102
|
+
editorView: editorView,
|
|
103
|
+
tableActive: tableActive,
|
|
104
|
+
isInDanger: isInDanger,
|
|
105
|
+
isResizing: isResizing,
|
|
106
|
+
tableWidth: tableWrapperWidth,
|
|
107
|
+
hoverRows: _hoverRows,
|
|
108
|
+
selectRow: _selectRow,
|
|
109
|
+
selectRows: _selectRows,
|
|
110
|
+
updateCellHoverLocation: updateCellHoverLocation
|
|
111
|
+
})) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CornerControls, {
|
|
112
|
+
editorView: editorView,
|
|
113
|
+
tableRef: tableRef,
|
|
114
|
+
isInDanger: isInDanger,
|
|
115
|
+
isResizing: isResizing,
|
|
116
|
+
isHeaderRowEnabled: isHeaderRowEnabled,
|
|
117
|
+
isHeaderColumnEnabled: isHeaderColumnEnabled,
|
|
118
|
+
hoveredRows: hoveredRows,
|
|
119
|
+
stickyTop: tableActive ? stickyTop : undefined
|
|
120
|
+
}), /*#__PURE__*/React.createElement(RowControls, {
|
|
121
|
+
editorView: editorView,
|
|
122
|
+
tableRef: tableRef,
|
|
123
|
+
hoverRows: _hoverRows,
|
|
124
|
+
hoveredRows: hoveredRows,
|
|
125
|
+
isInDanger: isInDanger,
|
|
126
|
+
isResizing: isResizing,
|
|
127
|
+
selectRow: _selectRow,
|
|
128
|
+
stickyTop: tableActive ? stickyTop : undefined
|
|
129
|
+
})))));
|
|
130
|
+
};
|
|
131
|
+
export default TableFloatingControls;
|
|
@@ -2,7 +2,7 @@ import { maphElem } from '@atlaskit/editor-common/utils';
|
|
|
2
2
|
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
3
3
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
4
4
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
5
|
-
import { findTable,
|
|
5
|
+
import { findTable, getSelectionRect, isColumnSelected, isTableSelected } from '@atlaskit/editor-tables/utils';
|
|
6
6
|
import { TableCssClassName as ClassName } from '../types';
|
|
7
7
|
import { tableDeleteButtonSize } from '../ui/consts';
|
|
8
8
|
export const getColumnsWidths = view => {
|
|
@@ -20,13 +20,13 @@ export const getColumnsWidths = view => {
|
|
|
20
20
|
length: map.width
|
|
21
21
|
});
|
|
22
22
|
for (let i = 0; i < map.width; i++) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const cellRef = findDomRefAtPos(
|
|
23
|
+
if (!map.isCellMergedTopLeft(0, i)) {
|
|
24
|
+
const node = table.node.nodeAt(map.map[i]);
|
|
25
|
+
const pos = map.map[i] + table.start;
|
|
26
|
+
const cellRef = findDomRefAtPos(pos, domAtPos);
|
|
27
27
|
const rect = cellRef.getBoundingClientRect();
|
|
28
28
|
widths[i] = (rect ? rect.width : cellRef.offsetWidth) + 1;
|
|
29
|
-
i +=
|
|
29
|
+
i += node.attrs.colspan - 1;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
}
|
package/dist/es2019/utils/dom.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { closestElement, containsClassName } from '@atlaskit/editor-common/utils';
|
|
2
2
|
import { TableCssClassName as ClassName } from '../types';
|
|
3
|
-
const SELECTOR_TABLE_LEAFS = `.${ClassName.TABLE_CELL}, .${ClassName.TABLE_HEADER_CELL}`;
|
|
4
3
|
export const isCell = node => {
|
|
5
4
|
return Boolean(node && (['TH', 'TD'].indexOf(node.tagName) > -1 || !!closestElement(node, `.${ClassName.TABLE_HEADER_CELL}`) || !!closestElement(node, `.${ClassName.TABLE_CELL}`)));
|
|
6
5
|
};
|
|
@@ -72,22 +71,21 @@ export const isDragCornerButton = node => containsClassName(node, ClassName.DRAG
|
|
|
72
71
|
*
|
|
73
72
|
* the same is valid to the right side.
|
|
74
73
|
*/
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
/**
|
|
75
|
+
* This can be used with mouse events to determine the left/right side of the target the pointer is closest too.
|
|
76
|
+
*
|
|
77
|
+
* WARNING: This metod reads properties which can trigger a reflow; use this wisely.
|
|
78
|
+
*
|
|
79
|
+
* @param mouseEvent
|
|
80
|
+
* @param gapInPixels
|
|
81
|
+
* @returns
|
|
82
|
+
*/
|
|
83
|
+
export const getMousePositionHorizontalRelativeByElement = (mouseEvent, offsetX, gapInPixels) => {
|
|
77
84
|
const element = mouseEvent.target;
|
|
78
85
|
if (element instanceof HTMLElement) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
// directly from element that will be .pm-table-drag-columns-floating-insert-dot-wrapper
|
|
83
|
-
width = element.clientWidth;
|
|
84
|
-
} else {
|
|
85
|
-
var _closestCell$id, _elementContentRects$, _elementContentRects$2;
|
|
86
|
-
const closestCell = element.closest(SELECTOR_TABLE_LEAFS);
|
|
87
|
-
const id = (_closestCell$id = closestCell === null || closestCell === void 0 ? void 0 : closestCell.id) !== null && _closestCell$id !== void 0 ? _closestCell$id : '';
|
|
88
|
-
width = (_elementContentRects$ = elementContentRects === null || elementContentRects === void 0 ? void 0 : (_elementContentRects$2 = elementContentRects[id]) === null || _elementContentRects$2 === void 0 ? void 0 : _elementContentRects$2.width) !== null && _elementContentRects$ !== void 0 ? _elementContentRects$ : 0;
|
|
89
|
-
}
|
|
90
|
-
x = mouseEvent.offsetX;
|
|
86
|
+
const width = element.clientWidth; // reflow
|
|
87
|
+
const x = !Number.isNaN(offsetX) ? offsetX : mouseEvent.offsetX; // reflow
|
|
88
|
+
|
|
91
89
|
if (width <= 0) {
|
|
92
90
|
return null;
|
|
93
91
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import rafSchedule from 'raf-schd';
|
|
2
3
|
import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
|
|
3
4
|
import { browser, closestElement, isElementInTableCell, isLastItemMediaGroup, setNodeSelection } from '@atlaskit/editor-common/utils';
|
|
4
5
|
import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
@@ -248,7 +249,10 @@ export var handleMouseLeave = function handleMouseLeave(view, event) {
|
|
|
248
249
|
}
|
|
249
250
|
return false;
|
|
250
251
|
};
|
|
251
|
-
|
|
252
|
+
|
|
253
|
+
// IMPORTANT: The mouse move handler has been setup with RAF schedule to avoid Reflows which will occur as some methods
|
|
254
|
+
// need to access the mouse event offset position and also the target clientWidth vallue.
|
|
255
|
+
var handleMouseMoveDebounce = rafSchedule(function (view, event, offsetX) {
|
|
252
256
|
if (!(event.target instanceof HTMLElement)) {
|
|
253
257
|
return false;
|
|
254
258
|
}
|
|
@@ -257,13 +261,12 @@ export var handleMouseMove = function handleMouseMove(view, event, elementConten
|
|
|
257
261
|
var state = view.state,
|
|
258
262
|
dispatch = view.dispatch;
|
|
259
263
|
var _getPluginState6 = getPluginState(state),
|
|
260
|
-
insertColumnButtonIndex = _getPluginState6.insertColumnButtonIndex
|
|
261
|
-
isDragAndDropEnabled = _getPluginState6.isDragAndDropEnabled;
|
|
264
|
+
insertColumnButtonIndex = _getPluginState6.insertColumnButtonIndex;
|
|
262
265
|
var _getColumnOrRowIndex9 = getColumnOrRowIndex(element),
|
|
263
266
|
_getColumnOrRowIndex10 = _slicedToArray(_getColumnOrRowIndex9, 2),
|
|
264
267
|
startIndex = _getColumnOrRowIndex10[0],
|
|
265
268
|
endIndex = _getColumnOrRowIndex10[1];
|
|
266
|
-
var positionColumn = getMousePositionHorizontalRelativeByElement(event,
|
|
269
|
+
var positionColumn = getMousePositionHorizontalRelativeByElement(event, offsetX, undefined) === 'right' ? endIndex : startIndex;
|
|
267
270
|
if (positionColumn !== insertColumnButtonIndex) {
|
|
268
271
|
return showInsertColumnButton(positionColumn)(state, dispatch);
|
|
269
272
|
}
|
|
@@ -283,7 +286,7 @@ export var handleMouseMove = function handleMouseMove(view, event, elementConten
|
|
|
283
286
|
}
|
|
284
287
|
}
|
|
285
288
|
if (!isResizeHandleDecoration(element) && isCell(element)) {
|
|
286
|
-
var _positionColumn = getMousePositionHorizontalRelativeByElement(event,
|
|
289
|
+
var _positionColumn = getMousePositionHorizontalRelativeByElement(event, offsetX, RESIZE_HANDLE_AREA_DECORATION_GAP);
|
|
287
290
|
if (_positionColumn !== null) {
|
|
288
291
|
var _state4 = view.state,
|
|
289
292
|
_dispatch5 = view.dispatch;
|
|
@@ -308,6 +311,19 @@ export var handleMouseMove = function handleMouseMove(view, event, elementConten
|
|
|
308
311
|
}
|
|
309
312
|
}
|
|
310
313
|
return false;
|
|
314
|
+
});
|
|
315
|
+
export var handleMouseMove = function handleMouseMove(view, event) {
|
|
316
|
+
if (!(event.target instanceof HTMLElement)) {
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// NOTE: When accessing offsetX in gecko from a deferred callback, it will return 0. However it will be non-zero if accessed
|
|
321
|
+
// within the scope of it's initial mouse move handler. Also Chrome does return the correct value, however it could trigger
|
|
322
|
+
// a reflow. So for now this will just grab the offsetX value immediately for gecko and chrome will calculate later
|
|
323
|
+
// in the deferred callback handler.
|
|
324
|
+
// Bug Tracking: https://bugzilla.mozilla.org/show_bug.cgi?id=1882903
|
|
325
|
+
handleMouseMoveDebounce(view, event, browser.gecko ? event.offsetX : NaN);
|
|
326
|
+
return false;
|
|
311
327
|
};
|
|
312
328
|
export function handleTripleClick(view, pos) {
|
|
313
329
|
var state = view.state,
|
|
@@ -383,12 +399,12 @@ export var isTableInFocus = function isTableInFocus(view) {
|
|
|
383
399
|
var _getPluginState10, _getResizePluginState;
|
|
384
400
|
return !!((_getPluginState10 = getPluginState(view.state)) !== null && _getPluginState10 !== void 0 && _getPluginState10.tableNode) && !((_getResizePluginState = getResizePluginState(view.state)) !== null && _getResizePluginState !== void 0 && _getResizePluginState.dragging);
|
|
385
401
|
};
|
|
386
|
-
export var whenTableInFocus = function whenTableInFocus(eventHandler
|
|
402
|
+
export var whenTableInFocus = function whenTableInFocus(eventHandler) {
|
|
387
403
|
return function (view, mouseEvent) {
|
|
388
404
|
if (!isTableInFocus(view)) {
|
|
389
405
|
return false;
|
|
390
406
|
}
|
|
391
|
-
return eventHandler(view, mouseEvent
|
|
407
|
+
return eventHandler(view, mouseEvent);
|
|
392
408
|
};
|
|
393
409
|
};
|
|
394
410
|
var trackCellLocation = function trackCellLocation(view, mouseEvent) {
|
|
@@ -418,11 +434,11 @@ var trackCellLocation = function trackCellLocation(view, mouseEvent) {
|
|
|
418
434
|
}
|
|
419
435
|
hoverCell(htmlRowIndex, colIndex)(view.state, view.dispatch);
|
|
420
436
|
};
|
|
421
|
-
export var withCellTracking = function withCellTracking(eventHandler
|
|
437
|
+
export var withCellTracking = function withCellTracking(eventHandler) {
|
|
422
438
|
return function (view, mouseEvent) {
|
|
423
439
|
if (getPluginState(view.state).isDragAndDropEnabled && !getDragDropPluginState(view.state).isDragging) {
|
|
424
440
|
trackCellLocation(view, mouseEvent);
|
|
425
441
|
}
|
|
426
|
-
return eventHandler(view, mouseEvent
|
|
442
|
+
return eventHandler(view, mouseEvent);
|
|
427
443
|
};
|
|
428
444
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
2
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
3
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
+
import rafSchedule from 'raf-schd';
|
|
4
5
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
5
6
|
import { TableCssClassName as ClassName, ShadowEvent } from '../types';
|
|
6
7
|
import { tableInsertColumnButtonSize } from '../ui/consts';
|
|
@@ -42,8 +43,13 @@ export var OverflowShadowsObserver = /*#__PURE__*/function () {
|
|
|
42
43
|
});
|
|
43
44
|
_defineProperty(this, "observeShadowSentinels", function (isSticky) {
|
|
44
45
|
var _this$table, _this$table2;
|
|
46
|
+
if (_this.isSticky === isSticky) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
45
49
|
_this.isSticky = !!isSticky;
|
|
46
50
|
|
|
51
|
+
// reset height
|
|
52
|
+
_this.stickyRowHeight = 0;
|
|
47
53
|
// update sticky shadows
|
|
48
54
|
_this.updateStickyShadowsHeightIfChanged();
|
|
49
55
|
_this.leftShadowSentinel = (_this$table = _this.table) === null || _this$table === void 0 ? void 0 : _this$table.querySelector(".".concat(ClassName.TABLE_SHADOW_SENTINEL_LEFT));
|
|
@@ -60,8 +66,8 @@ export var OverflowShadowsObserver = /*#__PURE__*/function () {
|
|
|
60
66
|
* e.g. bounds on an IntersectionObserverEntry, otherwise proceed with
|
|
61
67
|
* reading it from sticky cell
|
|
62
68
|
*/
|
|
63
|
-
_defineProperty(this, "updateStickyShadows", function (stickyRowHeight) {
|
|
64
|
-
var _this$wrapper
|
|
69
|
+
_defineProperty(this, "updateStickyShadows", rafSchedule(function (stickyRowHeight) {
|
|
70
|
+
var _this$wrapper;
|
|
65
71
|
if (!_this.isSticky) {
|
|
66
72
|
return;
|
|
67
73
|
}
|
|
@@ -69,14 +75,21 @@ export var OverflowShadowsObserver = /*#__PURE__*/function () {
|
|
|
69
75
|
if (!stickyCell || !((_this$wrapper = _this.wrapper) !== null && _this$wrapper !== void 0 && _this$wrapper.parentElement)) {
|
|
70
76
|
return;
|
|
71
77
|
}
|
|
72
|
-
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
|
|
79
|
+
// Reflow Warning! - stickyCell.clientHeight
|
|
80
|
+
var newStickyRowHeight = stickyRowHeight || stickyCell.clientHeight + 1;
|
|
81
|
+
if (newStickyRowHeight !== _this.stickyRowHeight) {
|
|
82
|
+
var _this$wrapper2, _this$wrapper3;
|
|
83
|
+
_this.stickyRowHeight = newStickyRowHeight;
|
|
84
|
+
var heightStyleOrCompute = "".concat(newStickyRowHeight, "px");
|
|
85
|
+
// Use getElementsByClassName here for a live node list to capture
|
|
86
|
+
// sticky shadows
|
|
87
|
+
var liveRightShadows = (_this$wrapper2 = _this.wrapper) === null || _this$wrapper2 === void 0 || (_this$wrapper2 = _this$wrapper2.parentElement) === null || _this$wrapper2 === void 0 ? void 0 : _this$wrapper2.getElementsByClassName("".concat(ClassName.TABLE_RIGHT_SHADOW));
|
|
88
|
+
var liveLeftShadows = (_this$wrapper3 = _this.wrapper) === null || _this$wrapper3 === void 0 || (_this$wrapper3 = _this$wrapper3.parentElement) === null || _this$wrapper3 === void 0 ? void 0 : _this$wrapper3.getElementsByClassName("".concat(ClassName.TABLE_LEFT_SHADOW));
|
|
89
|
+
updateShadowListForStickyStyles(heightStyleOrCompute, liveLeftShadows);
|
|
90
|
+
updateShadowListForStickyStyles(heightStyleOrCompute, liveRightShadows);
|
|
91
|
+
}
|
|
92
|
+
}));
|
|
80
93
|
this.updateShadowState = updateShadowState;
|
|
81
94
|
this.table = _table;
|
|
82
95
|
this.wrapper = wrapper;
|
|
@@ -92,11 +105,7 @@ export var OverflowShadowsObserver = /*#__PURE__*/function () {
|
|
|
92
105
|
if (!stickyCell) {
|
|
93
106
|
return;
|
|
94
107
|
}
|
|
95
|
-
|
|
96
|
-
if (newStickyRowHeight === this.stickyRowHeight) {
|
|
97
|
-
this.stickyRowHeight = newStickyRowHeight;
|
|
98
|
-
this.updateStickyShadows(this.stickyRowHeight);
|
|
99
|
-
}
|
|
108
|
+
this.updateStickyShadows();
|
|
100
109
|
}
|
|
101
110
|
}, {
|
|
102
111
|
key: "getStickyCell",
|
|
@@ -6,35 +6,17 @@ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstruct
|
|
|
6
6
|
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
7
7
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
8
8
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
9
|
-
import uuid from 'uuid';
|
|
10
9
|
import { getCellAttrs, getCellDomAttrs } from '@atlaskit/adf-schema';
|
|
11
|
-
import { getPluginState } from '../pm-plugins/plugin-factory';
|
|
12
10
|
import TableNodeView from './TableNodeViewBase';
|
|
13
11
|
var DEFAULT_COL_SPAN = 1;
|
|
14
12
|
var DEFAULT_ROW_SPAN = 1;
|
|
15
13
|
var TableCell = /*#__PURE__*/function (_ref) {
|
|
16
14
|
_inherits(TableCell, _ref);
|
|
17
15
|
var _super = _createSuper(TableCell);
|
|
18
|
-
function TableCell(node, view, getPos, eventDispatcher
|
|
19
|
-
var _this;
|
|
16
|
+
function TableCell(node, view, getPos, eventDispatcher) {
|
|
20
17
|
_classCallCheck(this, TableCell);
|
|
21
|
-
|
|
22
|
-
_this.observer = observer;
|
|
23
|
-
var _getPluginState = getPluginState(view.state),
|
|
24
|
-
pluginConfig = _getPluginState.pluginConfig,
|
|
25
|
-
isDragAndDropEnabled = _getPluginState.isDragAndDropEnabled;
|
|
26
|
-
_this.isStickyHeaderEnabled = !!pluginConfig.stickyHeaders;
|
|
27
|
-
_this.isDragAndDropEnabled = !!isDragAndDropEnabled;
|
|
28
|
-
if (observer) {
|
|
29
|
-
_this.contentDOM.id = uuid();
|
|
30
|
-
observer.observe(_this.contentDOM);
|
|
31
|
-
}
|
|
32
|
-
return _this;
|
|
18
|
+
return _super.call(this, node, view, getPos, eventDispatcher);
|
|
33
19
|
}
|
|
34
|
-
|
|
35
|
-
// @ts-ignore
|
|
36
|
-
|
|
37
|
-
// @ts-ignore
|
|
38
20
|
_createClass(TableCell, [{
|
|
39
21
|
key: "update",
|
|
40
22
|
value: function update(node) {
|
|
@@ -44,17 +26,10 @@ var TableCell = /*#__PURE__*/function (_ref) {
|
|
|
44
26
|
}
|
|
45
27
|
return didUpdate;
|
|
46
28
|
}
|
|
47
|
-
}, {
|
|
48
|
-
key: "destroy",
|
|
49
|
-
value: function destroy() {
|
|
50
|
-
if (this.observer) {
|
|
51
|
-
this.observer.unobserve(this.contentDOM);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
29
|
}, {
|
|
55
30
|
key: "updateNodeView",
|
|
56
31
|
value: function updateNodeView(node) {
|
|
57
|
-
var
|
|
32
|
+
var _this = this;
|
|
58
33
|
if (this.node.type !== node.type) {
|
|
59
34
|
return false;
|
|
60
35
|
}
|
|
@@ -85,10 +60,10 @@ var TableCell = /*#__PURE__*/function (_ref) {
|
|
|
85
60
|
var _ref5 = _slicedToArray(_ref4, 2),
|
|
86
61
|
key = _ref5[0],
|
|
87
62
|
value = _ref5[1];
|
|
88
|
-
return
|
|
63
|
+
return _this.dom.setAttribute(key, value || '');
|
|
89
64
|
});
|
|
90
65
|
removedAttrs.forEach(function (key) {
|
|
91
|
-
return
|
|
66
|
+
return _this.dom.removeAttribute(key);
|
|
92
67
|
});
|
|
93
68
|
return true;
|
|
94
69
|
}
|