@atlaskit/editor-plugin-table 5.1.0 → 5.2.1
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 +12 -0
- package/dist/cjs/plugins/table/index.js +3 -2
- package/dist/cjs/plugins/table/nodeviews/TableCell.js +111 -0
- package/dist/cjs/plugins/table/nodeviews/TableNodeViewBase.js +30 -0
- package/dist/cjs/plugins/table/{pm-plugins/sticky-headers/nodeviews/tableRow.js → nodeviews/TableRow.js} +363 -303
- package/dist/cjs/plugins/table/pm-plugins/main.js +16 -13
- package/dist/cjs/plugins/table/pm-plugins/sticky-headers/index.js +1 -8
- package/dist/cjs/plugins/table/pm-plugins/sticky-headers/plugin.js +1 -9
- package/dist/cjs/plugins/table/types.js +4 -1
- package/dist/cjs/plugins/table/utils/dom.js +31 -1
- package/dist/cjs/plugins/table/utils/index.js +12 -0
- package/dist/cjs/plugins/table/utils/nodes.js +31 -7
- package/dist/es2019/plugins/table/index.js +3 -2
- package/dist/es2019/plugins/table/nodeviews/{tableCell.js → TableCell.js} +28 -24
- package/dist/es2019/plugins/table/nodeviews/TableNodeViewBase.js +22 -0
- package/dist/es2019/plugins/table/{pm-plugins/sticky-headers/nodeviews/tableRow.js → nodeviews/TableRow.js} +324 -280
- package/dist/es2019/plugins/table/pm-plugins/main.js +8 -8
- package/dist/es2019/plugins/table/pm-plugins/sticky-headers/index.js +1 -2
- package/dist/es2019/plugins/table/pm-plugins/sticky-headers/plugin.js +1 -9
- package/dist/es2019/plugins/table/types.js +5 -1
- package/dist/es2019/plugins/table/utils/dom.js +30 -0
- package/dist/es2019/plugins/table/utils/index.js +1 -1
- package/dist/es2019/plugins/table/utils/nodes.js +16 -0
- package/dist/esm/plugins/table/index.js +3 -2
- package/dist/esm/plugins/table/nodeviews/TableCell.js +105 -0
- package/dist/esm/plugins/table/nodeviews/TableNodeViewBase.js +24 -0
- package/dist/esm/plugins/table/{pm-plugins/sticky-headers/nodeviews/tableRow.js → nodeviews/TableRow.js} +364 -303
- package/dist/esm/plugins/table/pm-plugins/main.js +16 -13
- package/dist/esm/plugins/table/pm-plugins/sticky-headers/index.js +1 -2
- package/dist/esm/plugins/table/pm-plugins/sticky-headers/plugin.js +1 -9
- package/dist/esm/plugins/table/types.js +5 -1
- package/dist/esm/plugins/table/utils/dom.js +30 -0
- package/dist/esm/plugins/table/utils/index.js +1 -1
- package/dist/esm/plugins/table/utils/nodes.js +24 -0
- package/dist/types/plugins/table/nodeviews/TableCell.d.ts +13 -0
- package/dist/types/plugins/table/nodeviews/TableNodeViewBase.d.ts +18 -0
- package/dist/types/plugins/table/nodeviews/TableRow.d.ts +62 -0
- package/dist/types/plugins/table/pm-plugins/main.d.ts +1 -1
- package/dist/types/plugins/table/pm-plugins/sticky-headers/index.d.ts +0 -1
- package/dist/types/plugins/table/pm-plugins/sticky-headers/plugin.d.ts +1 -1
- package/dist/types/plugins/table/types.d.ts +15 -0
- package/dist/types/plugins/table/utils/dom.d.ts +6 -0
- package/dist/types/plugins/table/utils/index.d.ts +1 -1
- package/dist/types/plugins/table/utils/nodes.d.ts +12 -2
- package/dist/types-ts4.5/plugins/table/nodeviews/TableCell.d.ts +13 -0
- package/dist/types-ts4.5/plugins/table/nodeviews/TableNodeViewBase.d.ts +18 -0
- package/dist/types-ts4.5/plugins/table/nodeviews/TableRow.d.ts +62 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/main.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/index.d.ts +0 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/plugin.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/types.d.ts +15 -0
- package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +6 -0
- package/dist/types-ts4.5/plugins/table/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/utils/nodes.d.ts +12 -2
- package/package.json +4 -2
- package/src/__tests__/unit/nodeviews/cell.ts +2 -2
- package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +25 -148
- package/src/plugins/table/index.tsx +2 -0
- package/src/plugins/table/nodeviews/{tableCell.tsx → TableCell.ts} +41 -46
- package/src/plugins/table/nodeviews/TableNodeViewBase.ts +32 -0
- package/src/plugins/table/{pm-plugins/sticky-headers/nodeviews/tableRow.ts → nodeviews/TableRow.ts} +246 -246
- package/src/plugins/table/pm-plugins/main.ts +10 -19
- package/src/plugins/table/pm-plugins/sticky-headers/index.ts +0 -1
- package/src/plugins/table/pm-plugins/sticky-headers/plugin.ts +1 -9
- package/src/plugins/table/types.ts +18 -0
- package/src/plugins/table/utils/dom.ts +38 -0
- package/src/plugins/table/utils/index.ts +2 -0
- package/src/plugins/table/utils/nodes.ts +30 -2
- package/tsconfig.app.json +6 -0
- package/dist/cjs/plugins/table/nodeviews/tableCell.js +0 -99
- package/dist/cjs/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.js +0 -35
- package/dist/es2019/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.js +0 -29
- package/dist/esm/plugins/table/nodeviews/tableCell.js +0 -93
- package/dist/esm/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.js +0 -29
- package/dist/types/plugins/table/nodeviews/tableCell.d.ts +0 -17
- package/dist/types/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.d.ts +0 -6
- package/dist/types/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +0 -73
- package/dist/types-ts4.5/plugins/table/nodeviews/tableCell.d.ts +0 -17
- package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.d.ts +0 -6
- package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +0 -73
- package/src/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.ts +0 -37
|
@@ -10,7 +10,8 @@ import { addBoldInEmptyHeaderCells, clearHoverSelection, setTableRef } from '../
|
|
|
10
10
|
import { removeResizeHandleDecorations, transformSliceRemoveCellBackgroundColor, transformSliceToAddTableHeaders, transformSliceToRemoveColumnsWidths } from '../commands/misc';
|
|
11
11
|
import { handleBlur, handleClick, handleCut, handleFocus, handleMouseDown, handleMouseLeave, handleMouseMove, handleMouseOut, handleMouseOver, handleTripleClick, whenTableInFocus } from '../event-handlers';
|
|
12
12
|
import { createTableView } from '../nodeviews/table';
|
|
13
|
-
import
|
|
13
|
+
import TableCell from '../nodeviews/TableCell';
|
|
14
|
+
import TableRow from '../nodeviews/TableRow';
|
|
14
15
|
import { pluginKey as decorationsPluginKey } from '../pm-plugins/decorations/plugin';
|
|
15
16
|
import { fixTables, replaceSelectedTable } from '../transforms';
|
|
16
17
|
import { TableCssClassName as ClassName } from '../types';
|
|
@@ -19,7 +20,7 @@ import { isHeaderRowRequired } from '../utils/paste';
|
|
|
19
20
|
import { defaultTableSelection } from './default-table-selection';
|
|
20
21
|
import { createPluginState, getPluginState } from './plugin-factory';
|
|
21
22
|
import { pluginKey } from './plugin-key';
|
|
22
|
-
export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI, eventDispatcher, pluginConfig, getEditorContainerWidth, getEditorFeatureFlags, getIntl, breakoutEnabled, fullWidthModeEnabled, tableResizingEnabled, previousFullWidthModeEnabled, editorAnalyticsAPI, pluginInjectionApi) => {
|
|
23
|
+
export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI, eventDispatcher, pluginConfig, getEditorContainerWidth, getEditorFeatureFlags, getIntl, breakoutEnabled, fullWidthModeEnabled, tableResizingEnabled, previousFullWidthModeEnabled, dragAndDropEnabled, editorAnalyticsAPI, pluginInjectionApi) => {
|
|
23
24
|
var _window;
|
|
24
25
|
const state = createPluginState(dispatch, {
|
|
25
26
|
pluginConfig,
|
|
@@ -31,6 +32,7 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
|
|
|
31
32
|
isTableResizingEnabled: tableResizingEnabled,
|
|
32
33
|
isHeaderRowEnabled: !!pluginConfig.allowHeaderRow,
|
|
33
34
|
isHeaderColumnEnabled: false,
|
|
35
|
+
isDragAndDropEnabled: dragAndDropEnabled,
|
|
34
36
|
...defaultTableSelection,
|
|
35
37
|
getIntl
|
|
36
38
|
});
|
|
@@ -43,10 +45,6 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
|
|
|
43
45
|
elementContentRects[entry.target.id] = entry.contentRect;
|
|
44
46
|
});
|
|
45
47
|
}) : undefined;
|
|
46
|
-
const tableCellNodeview = {
|
|
47
|
-
tableCell: (node, view, getPos) => new TableCellNodeView(node, view, getPos, observer),
|
|
48
|
-
tableHeader: (node, view, getPos) => new TableCellNodeView(node, view, getPos, observer)
|
|
49
|
-
};
|
|
50
48
|
|
|
51
49
|
// Used to prevent invalid table cell spans being reported more than once per editor/document
|
|
52
50
|
const invalidTableIds = [];
|
|
@@ -228,8 +226,10 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
|
|
|
228
226
|
return false;
|
|
229
227
|
},
|
|
230
228
|
nodeViews: {
|
|
231
|
-
|
|
232
|
-
|
|
229
|
+
table: (node, view, getPos) => createTableView(node, view, getPos, portalProviderAPI, eventDispatcher, getEditorContainerWidth, getEditorFeatureFlags, pluginInjectionApi),
|
|
230
|
+
tableRow: (node, view, getPos) => new TableRow(node, view, getPos, eventDispatcher),
|
|
231
|
+
tableCell: (node, view, getPos) => new TableCell(node, view, getPos, eventDispatcher, observer),
|
|
232
|
+
tableHeader: (node, view, getPos) => new TableCell(node, view, getPos, eventDispatcher, observer)
|
|
233
233
|
},
|
|
234
234
|
handleDOMEvents: {
|
|
235
235
|
focus: handleFocus,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { createPlugin } from './plugin';
|
|
2
2
|
export { pluginKey } from './plugin-key';
|
|
3
3
|
export { findStickyHeaderForTable } from './util';
|
|
4
|
-
export { updateStickyState, removeStickyState } from './commands';
|
|
5
|
-
export { TableRowNodeView } from './nodeviews/tableRow';
|
|
4
|
+
export { updateStickyState, removeStickyState } from './commands';
|
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
-
import { TableRowNodeView } from './nodeviews/tableRow';
|
|
3
2
|
import { pluginKey } from './plugin-key';
|
|
4
3
|
import { createPluginState } from './plugin-state';
|
|
5
4
|
export const createPlugin = (dispatch, eventDispatcher, initialState = () => [], getEditorFeatureFlags) => {
|
|
6
5
|
return new SafePlugin({
|
|
7
6
|
state: createPluginState(dispatch, initialState),
|
|
8
|
-
key: pluginKey
|
|
9
|
-
props: {
|
|
10
|
-
nodeViews: {
|
|
11
|
-
tableRow: (node, view, getPos) => {
|
|
12
|
-
return new TableRowNodeView(node, view, getPos, eventDispatcher);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
7
|
+
key: pluginKey
|
|
16
8
|
});
|
|
17
9
|
};
|
|
@@ -109,4 +109,8 @@ export let ShadowEvent = /*#__PURE__*/function (ShadowEvent) {
|
|
|
109
109
|
ShadowEvent["SHOW_BEFORE_SHADOW"] = "showBeforeShadow";
|
|
110
110
|
ShadowEvent["SHOW_AFTER_SHADOW"] = "showAfterShadow";
|
|
111
111
|
return ShadowEvent;
|
|
112
|
-
}({});
|
|
112
|
+
}({});
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Drag and Drop interfaces
|
|
116
|
+
*/
|
|
@@ -135,4 +135,34 @@ export const hasResizeHandler = ({
|
|
|
135
135
|
return false;
|
|
136
136
|
}
|
|
137
137
|
return true;
|
|
138
|
+
};
|
|
139
|
+
export const getTree = tr => {
|
|
140
|
+
// pm renders into tbody, owned by react
|
|
141
|
+
const tbody = tr.parentElement;
|
|
142
|
+
if (!tbody) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// rendered by react
|
|
147
|
+
const table = tbody.parentElement;
|
|
148
|
+
if (!table) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// rendered by react
|
|
153
|
+
const wrapper = table.parentElement;
|
|
154
|
+
if (!wrapper) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
wrapper: wrapper,
|
|
159
|
+
table: table
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
export const getTop = element => {
|
|
163
|
+
var _element$getBoundingC, _element$getBoundingC2, _element$getBoundingC3;
|
|
164
|
+
if (!element || element instanceof Window) {
|
|
165
|
+
return 0;
|
|
166
|
+
}
|
|
167
|
+
return (_element$getBoundingC = element === null || element === void 0 ? void 0 : (_element$getBoundingC2 = element.getBoundingClientRect) === null || _element$getBoundingC2 === void 0 ? void 0 : (_element$getBoundingC3 = _element$getBoundingC2.call(element)) === null || _element$getBoundingC3 === void 0 ? void 0 : _element$getBoundingC3.top) !== null && _element$getBoundingC !== void 0 ? _element$getBoundingC : 0;
|
|
138
168
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { getSelectedColumnIndexes, getSelectedRowIndexes, normalizeSelection, isSelectionUpdated } from './selection';
|
|
2
2
|
export { findControlsHoverDecoration, createControlsHoverDecoration, createColumnControlsDecoration, createColumnSelectedDecoration, createCellHoverDecoration, updateDecorations, createResizeHandleDecoration, createColumnLineResize } from './decoration';
|
|
3
|
-
export { isIsolating, containsHeaderColumn, containsHeaderRow, checkIfHeaderColumnEnabled, checkIfHeaderRowEnabled, checkIfNumberColumnEnabled, isLayoutSupported, getTableWidth, tablesHaveDifferentColumnWidths, tablesHaveDifferentNoOfColumns, isTableNested } from './nodes';
|
|
3
|
+
export { isIsolating, containsHeaderColumn, containsHeaderRow, checkIfHeaderColumnEnabled, checkIfHeaderRowEnabled, checkIfNumberColumnEnabled, isLayoutSupported, getTableWidth, tablesHaveDifferentColumnWidths, tablesHaveDifferentNoOfColumns, isTableNested, anyChildCellMergedAcrossRow, supportedHeaderRow } from './nodes';
|
|
4
4
|
export { unwrapContentFromTable, removeTableFromFirstChild, removeTableFromLastChild, transformSliceToRemoveOpenTable, transformSliceToCorrectEmptyTableCells, transformSliceToFixHardBreakProblemOnCopyFromCell } from './paste';
|
|
5
5
|
export { isCell, isCornerButton, isInsertRowButton, isColumnControlsDecorations, isTableControlsButton, isTableContainerOrWrapper, isRowControlsButton, getColumnOrRowIndex, getMousePositionHorizontalRelativeByElement, getMousePositionVerticalRelativeByElement, updateResizeHandles, isResizeHandleDecoration, hasResizeHandler } from './dom';
|
|
6
6
|
export { getColumnsWidths, isColumnDeleteButtonVisible, getColumnDeleteButtonParams, getColumnClassNames } from './column-controls';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { mapChildren } from '@atlaskit/editor-common/utils';
|
|
1
2
|
import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
2
3
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
3
4
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
@@ -94,4 +95,19 @@ export const isTableNested = (state, tablePos = 0) => {
|
|
|
94
95
|
const parent = state.doc.resolve(tablePos).parent;
|
|
95
96
|
const nodeTypes = state.schema.nodes;
|
|
96
97
|
return parent.type === nodeTypes.layoutColumn || parent.type === nodeTypes.expand || parent.type === nodeTypes.bodiedExtension;
|
|
98
|
+
};
|
|
99
|
+
export const anyChildCellMergedAcrossRow = node => mapChildren(node, child => child.attrs.rowspan || 0).some(rowspan => rowspan > 1);
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Check if a given node is a header row with this definition:
|
|
103
|
+
* - all children are tableHeader cells
|
|
104
|
+
* - no table cells have been have merged with other table row cells
|
|
105
|
+
*
|
|
106
|
+
* @param node ProseMirror node
|
|
107
|
+
* @return boolean if it meets definition
|
|
108
|
+
*/
|
|
109
|
+
export const supportedHeaderRow = node => {
|
|
110
|
+
const allHeaders = mapChildren(node, child => child.type.name === 'tableHeader').every(Boolean);
|
|
111
|
+
const someMerged = anyChildCellMergedAcrossRow(node);
|
|
112
|
+
return allHeaders && !someMerged;
|
|
97
113
|
};
|
|
@@ -105,8 +105,9 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
105
105
|
tableResizingEnabled = _ref3.tableResizingEnabled,
|
|
106
106
|
breakoutEnabled = _ref3.breakoutEnabled,
|
|
107
107
|
tableOptions = _ref3.tableOptions,
|
|
108
|
-
getEditorFeatureFlags = _ref3.getEditorFeatureFlags
|
|
109
|
-
|
|
108
|
+
getEditorFeatureFlags = _ref3.getEditorFeatureFlags,
|
|
109
|
+
dragAndDropEnabled = _ref3.dragAndDropEnabled;
|
|
110
|
+
return createPlugin(dispatchAnalyticsEvent, dispatch, portalProviderAPI, eventDispatcher, pluginConfig(tableOptions), defaultGetEditorContainerWidth, getEditorFeatureFlags || defaultGetEditorFeatureFlags, getIntl, breakoutEnabled, fullWidthEnabled, tableResizingEnabled, wasFullWidthEnabled, dragAndDropEnabled, editorAnalyticsAPI, api);
|
|
110
111
|
}
|
|
111
112
|
}, {
|
|
112
113
|
name: 'tablePMColResizing',
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
5
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
6
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
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
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
9
|
+
import uuid from 'uuid';
|
|
10
|
+
import { getCellAttrs, getCellDomAttrs } from '@atlaskit/adf-schema';
|
|
11
|
+
import { getPluginState } from '../pm-plugins/plugin-factory';
|
|
12
|
+
import TableNodeView from './TableNodeViewBase';
|
|
13
|
+
var DEFAULT_COL_SPAN = 1;
|
|
14
|
+
var DEFAULT_ROW_SPAN = 1;
|
|
15
|
+
var TableCell = /*#__PURE__*/function (_ref) {
|
|
16
|
+
_inherits(TableCell, _ref);
|
|
17
|
+
var _super = _createSuper(TableCell);
|
|
18
|
+
function TableCell(node, view, getPos, eventDispatcher, observer) {
|
|
19
|
+
var _this;
|
|
20
|
+
_classCallCheck(this, TableCell);
|
|
21
|
+
_this = _super.call(this, node, view, getPos, eventDispatcher);
|
|
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;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
_createClass(TableCell, [{
|
|
39
|
+
key: "update",
|
|
40
|
+
value: function update(node) {
|
|
41
|
+
var didUpdate = this.updateNodeView(node);
|
|
42
|
+
if (didUpdate) {
|
|
43
|
+
this.node = node;
|
|
44
|
+
}
|
|
45
|
+
return didUpdate;
|
|
46
|
+
}
|
|
47
|
+
}, {
|
|
48
|
+
key: "destroy",
|
|
49
|
+
value: function destroy() {
|
|
50
|
+
if (this.observer) {
|
|
51
|
+
this.observer.unobserve(this.contentDOM);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}, {
|
|
55
|
+
key: "updateNodeView",
|
|
56
|
+
value: function updateNodeView(node) {
|
|
57
|
+
var _this2 = this;
|
|
58
|
+
if (this.node.type !== node.type) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
var attrs = getCellDomAttrs(this.node);
|
|
62
|
+
var nextAttrs = getCellDomAttrs(node);
|
|
63
|
+
var _getCellAttrs = getCellAttrs(this.dom),
|
|
64
|
+
colspan = _getCellAttrs.colspan,
|
|
65
|
+
rowspan = _getCellAttrs.rowspan;
|
|
66
|
+
|
|
67
|
+
// need to rerender when colspan/rowspan in dom are different from the node attrs
|
|
68
|
+
// this can happen when undoing merge cells
|
|
69
|
+
if (colspan !== (node.attrs.colspan || DEFAULT_COL_SPAN) || rowspan !== (node.attrs.rowspan || DEFAULT_ROW_SPAN)) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// added + changed attributes
|
|
74
|
+
var addedAttrs = Object.entries(nextAttrs).filter(function (_ref2) {
|
|
75
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
76
|
+
key = _ref3[0],
|
|
77
|
+
value = _ref3[1];
|
|
78
|
+
return attrs[key] !== value;
|
|
79
|
+
});
|
|
80
|
+
var removedAttrs = Object.keys(attrs).filter(function (key) {
|
|
81
|
+
return !nextAttrs.hasOwnProperty(key);
|
|
82
|
+
});
|
|
83
|
+
if (addedAttrs.length || removedAttrs.length) {
|
|
84
|
+
addedAttrs.forEach(function (_ref4) {
|
|
85
|
+
var _ref5 = _slicedToArray(_ref4, 2),
|
|
86
|
+
key = _ref5[0],
|
|
87
|
+
value = _ref5[1];
|
|
88
|
+
return _this2.dom.setAttribute(key, value || '');
|
|
89
|
+
});
|
|
90
|
+
removedAttrs.forEach(function (key) {
|
|
91
|
+
return _this2.dom.removeAttribute(key);
|
|
92
|
+
});
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Return true to not re-render this node view
|
|
97
|
+
if (this.node.sameMarkup(node)) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}]);
|
|
103
|
+
return TableCell;
|
|
104
|
+
}(TableNodeView);
|
|
105
|
+
export { TableCell as default };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
+
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
4
|
+
var TableNodeView = /*#__PURE__*/_createClass(
|
|
5
|
+
/**
|
|
6
|
+
* @constructor
|
|
7
|
+
*/
|
|
8
|
+
function TableNodeView(node, view, getPos, eventDispatcher) {
|
|
9
|
+
_classCallCheck(this, TableNodeView);
|
|
10
|
+
this.node = node;
|
|
11
|
+
this.view = view;
|
|
12
|
+
this.getPos = getPos;
|
|
13
|
+
this.eventDispatcher = eventDispatcher;
|
|
14
|
+
var _DOMSerializer$render = DOMSerializer.renderSpec(document, node.type.spec.toDOM(node)),
|
|
15
|
+
dom = _DOMSerializer$render.dom,
|
|
16
|
+
contentDOM = _DOMSerializer$render.contentDOM;
|
|
17
|
+
this.dom = dom;
|
|
18
|
+
this.contentDOM = contentDOM;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Variables
|
|
23
|
+
*/);
|
|
24
|
+
export { TableNodeView as default };
|