@atlaskit/editor-plugin-table 2.2.0 → 2.3.0
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 +10 -0
- package/dist/cjs/plugins/table/index.js +40 -34
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +1 -2
- package/dist/cjs/plugins/table/nodeviews/TableResizer.js +21 -13
- package/dist/cjs/plugins/table/nodeviews/table.js +7 -2
- package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +14 -5
- package/dist/cjs/plugins/table/pm-plugins/{table-add-width.js → table-width.js} +27 -4
- package/dist/cjs/plugins/table/toolbar.js +6 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/index.js +18 -9
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +1 -2
- package/dist/es2019/plugins/table/nodeviews/TableResizer.js +26 -14
- package/dist/es2019/plugins/table/nodeviews/table.js +7 -2
- package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +14 -5
- package/dist/es2019/plugins/table/pm-plugins/{table-add-width.js → table-width.js} +25 -3
- package/dist/es2019/plugins/table/toolbar.js +6 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/index.js +40 -34
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +1 -2
- package/dist/esm/plugins/table/nodeviews/TableResizer.js +21 -13
- package/dist/esm/plugins/table/nodeviews/table.js +7 -2
- package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +14 -5
- package/dist/esm/plugins/table/pm-plugins/{table-add-width.js → table-width.js} +25 -3
- package/dist/esm/plugins/table/toolbar.js +6 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/plugins/table/nodeviews/TableComponent.d.ts +2 -2
- package/dist/types/plugins/table/pm-plugins/decorations/plugin.d.ts +1 -1
- package/dist/types/plugins/table/pm-plugins/table-width.d.ts +16 -0
- package/dist/types-ts4.5/plugins/table/nodeviews/TableComponent.d.ts +2 -2
- package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/plugin.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/table-width.d.ts +16 -0
- package/package.json +3 -3
- package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +66 -0
- package/src/plugins/table/index.tsx +35 -22
- package/src/plugins/table/nodeviews/TableComponent.tsx +3 -6
- package/src/plugins/table/nodeviews/TableResizer.tsx +27 -20
- package/src/plugins/table/nodeviews/table.tsx +12 -2
- package/src/plugins/table/pm-plugins/decorations/plugin.ts +26 -4
- package/src/plugins/table/pm-plugins/{table-add-width.ts → table-width.ts} +33 -3
- package/src/plugins/table/toolbar.tsx +7 -1
- package/dist/types/plugins/table/pm-plugins/table-add-width.d.ts +0 -7
- package/dist/types-ts4.5/plugins/table/pm-plugins/table-add-width.d.ts +0 -7
|
@@ -1,12 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A plugin for
|
|
3
|
-
*
|
|
2
|
+
* A plugin for handle table custom widths
|
|
3
|
+
* Has login to scan the document, add width value to table's width attribute when necessary
|
|
4
|
+
* Also holds resizing state to hide / show table controls
|
|
4
5
|
*/
|
|
5
6
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
6
7
|
import { akEditorFullWidthLayoutWidth, akEditorWideLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
7
8
|
import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
|
|
8
9
|
import { ReplaceStep } from 'prosemirror-transform';
|
|
9
|
-
|
|
10
|
+
import { PluginKey } from 'prosemirror-state';
|
|
11
|
+
export const pluginKey = new PluginKey('tableWidthPlugin');
|
|
12
|
+
const createPlugin = (dispatch, fullWidthEnabled) => new SafePlugin({
|
|
13
|
+
key: pluginKey,
|
|
14
|
+
state: {
|
|
15
|
+
init() {
|
|
16
|
+
return {
|
|
17
|
+
resizing: false
|
|
18
|
+
};
|
|
19
|
+
},
|
|
20
|
+
apply(tr, pluginState) {
|
|
21
|
+
const meta = tr.getMeta(pluginKey);
|
|
22
|
+
if (meta && meta.resizing !== pluginState.resizing) {
|
|
23
|
+
const newState = {
|
|
24
|
+
resizing: meta.resizing
|
|
25
|
+
};
|
|
26
|
+
dispatch(pluginKey, newState);
|
|
27
|
+
return newState;
|
|
28
|
+
}
|
|
29
|
+
return pluginState;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
10
32
|
appendTransaction: (transactions, _oldState, newState) => {
|
|
11
33
|
// When document first load in Confluence, initially it is an empty document
|
|
12
34
|
// and Collab service triggers a transaction to replace the empty document with the real document that should be rendered.
|
|
@@ -7,6 +7,7 @@ import { clearHoverSelection, hoverTable, hoverColumns, hoverRows, removeDescend
|
|
|
7
7
|
import { deleteTableWithAnalytics, toggleHeaderColumnWithAnalytics, toggleHeaderRowWithAnalytics, toggleNumberColumnWithAnalytics, insertRowWithAnalytics, deleteRowsWithAnalytics, mergeCellsWithAnalytics, splitCellWithAnalytics, deleteColumnsWithAnalytics, emptyMultipleCellsWithAnalytics, insertColumnWithAnalytics, wrapTableInExpandWithAnalytics, sortColumnWithAnalytics, setColorWithAnalytics, distributeColumnsWidthsWithAnalytics } from './commands-with-analytics';
|
|
8
8
|
import { getPluginState } from './pm-plugins/plugin-factory';
|
|
9
9
|
import { pluginKey as tableResizingPluginKey } from './pm-plugins/table-resizing';
|
|
10
|
+
import { pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
|
|
10
11
|
import { TableCssClassName } from './types';
|
|
11
12
|
import { getMergedCellsPositions, getSelectedColumnIndexes, getSelectedRowIndexes } from './utils';
|
|
12
13
|
import { isReferencedSource, getChildrenInfo, getNodeName } from '@atlaskit/editor-common/utils';
|
|
@@ -294,7 +295,11 @@ export const getToolbarConfig = (getEditorContainerWidth, editorAnalyticsAPI, ge
|
|
|
294
295
|
const tableObject = findTable(state.selection);
|
|
295
296
|
const pluginState = getPluginState(state);
|
|
296
297
|
const resizeState = tableResizingPluginKey.getState(state);
|
|
297
|
-
|
|
298
|
+
const tableWidthState = tableWidthPluginKey.getState(state);
|
|
299
|
+
|
|
300
|
+
// We don't want to show floating toolbar while resizing the table
|
|
301
|
+
const isWidthResizing = tableWidthState === null || tableWidthState === void 0 ? void 0 : tableWidthState.resizing;
|
|
302
|
+
if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
|
|
298
303
|
const nodeType = state.schema.nodes.table;
|
|
299
304
|
const menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
|
|
300
305
|
const {
|
package/dist/es2019/version.json
CHANGED
|
@@ -11,7 +11,7 @@ import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/
|
|
|
11
11
|
import { IconTable } from '@atlaskit/editor-common/icons';
|
|
12
12
|
import { pluginConfig } from './create-plugin-config';
|
|
13
13
|
import { createPlugin as createTableLocalIdPlugin } from './pm-plugins/table-local-id';
|
|
14
|
-
import { createPlugin as
|
|
14
|
+
import { pluginKey as tableWidthPluginKey, createPlugin as createTableWidthPlugin } from './pm-plugins/table-width';
|
|
15
15
|
import { createPlugin as createTableSafariDeleteCompositionTextIssueWorkaroundPlugin } from './pm-plugins/safari-delete-composition-text-issue-workaround';
|
|
16
16
|
import { createPlugin as createDecorationsPlugin } from './pm-plugins/decorations/plugin';
|
|
17
17
|
import { keymapPlugin } from './pm-plugins/keymap';
|
|
@@ -165,9 +165,11 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
165
165
|
return createTableLocalIdPlugin(dispatch);
|
|
166
166
|
}
|
|
167
167
|
}, {
|
|
168
|
-
name: '
|
|
169
|
-
plugin: function plugin() {
|
|
170
|
-
|
|
168
|
+
name: 'tableWidth',
|
|
169
|
+
plugin: function plugin(_ref8) {
|
|
170
|
+
var _options$fullWidthEna;
|
|
171
|
+
var dispatch = _ref8.dispatch;
|
|
172
|
+
return getBooleanFF('platform.editor.custom-table-width') ? createTableWidthPlugin(dispatch, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false) : undefined;
|
|
171
173
|
}
|
|
172
174
|
}, {
|
|
173
175
|
name: 'tableGetEditorViewReferencePlugin',
|
|
@@ -197,12 +199,12 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
197
199
|
}
|
|
198
200
|
return plugins;
|
|
199
201
|
},
|
|
200
|
-
contentComponent: function contentComponent(
|
|
201
|
-
var editorView =
|
|
202
|
-
popupsMountPoint =
|
|
203
|
-
popupsBoundariesElement =
|
|
204
|
-
popupsScrollableElement =
|
|
205
|
-
dispatchAnalyticsEvent =
|
|
202
|
+
contentComponent: function contentComponent(_ref9) {
|
|
203
|
+
var editorView = _ref9.editorView,
|
|
204
|
+
popupsMountPoint = _ref9.popupsMountPoint,
|
|
205
|
+
popupsBoundariesElement = _ref9.popupsBoundariesElement,
|
|
206
|
+
popupsScrollableElement = _ref9.popupsScrollableElement,
|
|
207
|
+
dispatchAnalyticsEvent = _ref9.dispatchAnalyticsEvent;
|
|
206
208
|
return /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
207
209
|
component: ACTION_SUBJECT.TABLES_PLUGIN,
|
|
208
210
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
@@ -210,28 +212,32 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
210
212
|
}, /*#__PURE__*/React.createElement(WithPluginState, {
|
|
211
213
|
plugins: {
|
|
212
214
|
tablePluginState: pluginKey,
|
|
215
|
+
tableWidthPluginState: tableWidthPluginKey,
|
|
213
216
|
tableResizingPluginState: tableResizingPluginKey,
|
|
214
217
|
stickyHeadersState: stickyHeadersPluginKey
|
|
215
218
|
},
|
|
216
|
-
render: function render(
|
|
217
|
-
var resizingPluginState =
|
|
218
|
-
stickyHeadersState =
|
|
219
|
-
tablePluginState =
|
|
219
|
+
render: function render(_ref10) {
|
|
220
|
+
var resizingPluginState = _ref10.tableResizingPluginState,
|
|
221
|
+
stickyHeadersState = _ref10.stickyHeadersState,
|
|
222
|
+
tablePluginState = _ref10.tablePluginState,
|
|
223
|
+
tableWidthPluginState = _ref10.tableWidthPluginState;
|
|
220
224
|
var state = editorView.state;
|
|
221
|
-
var
|
|
222
|
-
var
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
225
|
+
var isColumnResizing = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
|
|
226
|
+
var isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
|
|
227
|
+
var isResizing = isColumnResizing || isTableResizing;
|
|
228
|
+
var _ref11 = tablePluginState,
|
|
229
|
+
tableNode = _ref11.tableNode,
|
|
230
|
+
tablePos = _ref11.tablePos,
|
|
231
|
+
targetCellPosition = _ref11.targetCellPosition,
|
|
232
|
+
isContextualMenuOpen = _ref11.isContextualMenuOpen,
|
|
233
|
+
layout = _ref11.layout,
|
|
234
|
+
tableRef = _ref11.tableRef,
|
|
235
|
+
pluginConfig = _ref11.pluginConfig,
|
|
236
|
+
insertColumnButtonIndex = _ref11.insertColumnButtonIndex,
|
|
237
|
+
insertRowButtonIndex = _ref11.insertRowButtonIndex,
|
|
238
|
+
isHeaderColumnEnabled = _ref11.isHeaderColumnEnabled,
|
|
239
|
+
isHeaderRowEnabled = _ref11.isHeaderRowEnabled,
|
|
240
|
+
tableWrapperTarget = _ref11.tableWrapperTarget;
|
|
235
241
|
var allowControls = pluginConfig.allowControls;
|
|
236
242
|
var stickyHeader = stickyHeadersState ? findStickyHeaderForTable(stickyHeadersState, tablePos) : undefined;
|
|
237
243
|
var LayoutContent = getBooleanFF('platform.editor.custom-table-width') ? null : isLayoutSupported(state) && options && options.breakoutEnabled ? /*#__PURE__*/React.createElement(LayoutButton, {
|
|
@@ -245,7 +251,7 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
245
251
|
stickyHeader: stickyHeader,
|
|
246
252
|
editorAnalyticsAPI: editorAnalyticsAPI
|
|
247
253
|
}) : null;
|
|
248
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, targetCellPosition && tableRef && !
|
|
254
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, targetCellPosition && tableRef && !isResizing && options && options.allowContextualMenu && /*#__PURE__*/React.createElement(FloatingContextualButton, {
|
|
249
255
|
isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
|
|
250
256
|
editorView: editorView,
|
|
251
257
|
tableNode: tableNode,
|
|
@@ -272,17 +278,17 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
272
278
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
273
279
|
editorAnalyticsAPI: editorAnalyticsAPI,
|
|
274
280
|
getEditorContainerWidth: defaultGetEditorContainerWidth
|
|
275
|
-
}), /*#__PURE__*/React.createElement(FloatingContextualMenu, {
|
|
281
|
+
}), (options === null || options === void 0 ? void 0 : options.allowContextualMenu) && /*#__PURE__*/React.createElement(FloatingContextualMenu, {
|
|
276
282
|
editorView: editorView,
|
|
277
283
|
mountPoint: popupsMountPoint,
|
|
278
284
|
boundariesElement: popupsBoundariesElement,
|
|
279
285
|
targetCellPosition: targetCellPosition,
|
|
280
|
-
isOpen: Boolean(isContextualMenuOpen),
|
|
286
|
+
isOpen: Boolean(isContextualMenuOpen) && !isResizing,
|
|
281
287
|
pluginConfig: pluginConfig,
|
|
282
288
|
editorAnalyticsAPI: editorAnalyticsAPI,
|
|
283
289
|
getEditorContainerWidth: defaultGetEditorContainerWidth,
|
|
284
290
|
getEditorFeatureFlags: (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags
|
|
285
|
-
}), allowControls && /*#__PURE__*/React.createElement(FloatingDeleteButton, {
|
|
291
|
+
}), allowControls && !isResizing && /*#__PURE__*/React.createElement(FloatingDeleteButton, {
|
|
286
292
|
editorView: editorView,
|
|
287
293
|
selection: editorView.state.selection,
|
|
288
294
|
tableRef: tableRef,
|
|
@@ -297,8 +303,8 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
297
303
|
}));
|
|
298
304
|
},
|
|
299
305
|
pluginsOptions: {
|
|
300
|
-
quickInsert: function quickInsert(
|
|
301
|
-
var formatMessage =
|
|
306
|
+
quickInsert: function quickInsert(_ref12) {
|
|
307
|
+
var formatMessage = _ref12.formatMessage;
|
|
302
308
|
return [{
|
|
303
309
|
id: 'table',
|
|
304
310
|
title: formatMessage(messages.table),
|
|
@@ -378,7 +378,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
378
378
|
var _this$props8 = this.props,
|
|
379
379
|
view = _this$props8.view,
|
|
380
380
|
getNode = _this$props8.getNode,
|
|
381
|
-
|
|
381
|
+
isResizing = _this$props8.isResizing,
|
|
382
382
|
_this$props8$allowCon = _this$props8.allowControls,
|
|
383
383
|
allowControls = _this$props8$allowCon === void 0 ? true : _this$props8$allowCon,
|
|
384
384
|
isHeaderRowEnabled = _this$props8.isHeaderRowEnabled,
|
|
@@ -404,7 +404,6 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
404
404
|
tableRenderOptimization = _this$props$getEditor4.tableRenderOptimization,
|
|
405
405
|
tableOverflowShadowsOptimization = _this$props$getEditor4.tableOverflowShadowsOptimization;
|
|
406
406
|
var tableRef = this.table || undefined;
|
|
407
|
-
var isResizing = !!tableResizingPluginState && !!tableResizingPluginState.dragging;
|
|
408
407
|
var headerRow = tableRef ? tableRef.querySelector('tr[data-header-row]') : undefined;
|
|
409
408
|
|
|
410
409
|
//dont need to change tableHeight with tableRenderOptimization because it will be observed inside floating components
|
|
@@ -7,6 +7,7 @@ import rafSchd from 'raf-schd';
|
|
|
7
7
|
import { ResizerNext } from '@atlaskit/editor-common/resizer';
|
|
8
8
|
import { getGuidelinesWithHighlights } from '@atlaskit/editor-common/guideline';
|
|
9
9
|
import { scaleTable, previewScaleTable, getColgroupChildrenLength, COLUMN_MIN_WIDTH } from '../pm-plugins/table-resizing/utils';
|
|
10
|
+
import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
|
|
10
11
|
import { defaultGuidelines, defaultGuidelineWidths } from '../utils/guidelines';
|
|
11
12
|
import { findClosestSnap } from '../utils/snapping';
|
|
12
13
|
import { TABLE_SNAP_GAP, TABLE_HIGHLIGHT_GAP } from '../ui/consts';
|
|
@@ -60,27 +61,34 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
60
61
|
} : undefined;
|
|
61
62
|
}, [snappingEnabled]);
|
|
62
63
|
var handleResizeStart = useCallback(function () {
|
|
64
|
+
var dispatch = editorView.dispatch,
|
|
65
|
+
tr = editorView.state.tr;
|
|
66
|
+
dispatch(tr.setMeta(tableWidthPluginKey, {
|
|
67
|
+
resizing: true
|
|
68
|
+
}));
|
|
63
69
|
setSnappingEnabled(displayGuideline(defaultGuidelines));
|
|
64
70
|
return width;
|
|
65
|
-
}, [width, displayGuideline]);
|
|
71
|
+
}, [width, displayGuideline, editorView]);
|
|
66
72
|
var handleResizeStop = useCallback(function (originalState, delta) {
|
|
67
73
|
var newWidth = originalState.width + delta.width;
|
|
68
74
|
var state = editorView.state,
|
|
69
75
|
dispatch = editorView.dispatch;
|
|
70
76
|
var pos = getPos();
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
var tr = state.tr.setMeta(tableWidthPluginKey, {
|
|
78
|
+
resizing: false
|
|
79
|
+
});
|
|
80
|
+
if (typeof pos === 'number') {
|
|
81
|
+
tr = tr.setNodeMarkup(pos, undefined, _objectSpread(_objectSpread({}, node.attrs), {}, {
|
|
82
|
+
width: newWidth
|
|
83
|
+
}));
|
|
84
|
+
var newNode = tr.doc.nodeAt(pos);
|
|
85
|
+
tr = scaleTable(tableRef, {
|
|
86
|
+
node: newNode,
|
|
87
|
+
prevNode: node,
|
|
88
|
+
start: pos + 1,
|
|
89
|
+
parentWidth: newWidth
|
|
90
|
+
}, editorView.domAtPos.bind(editorView))(tr);
|
|
73
91
|
}
|
|
74
|
-
var tr = state.tr.setNodeMarkup(pos, undefined, _objectSpread(_objectSpread({}, node.attrs), {}, {
|
|
75
|
-
width: newWidth
|
|
76
|
-
}));
|
|
77
|
-
var newNode = tr.doc.nodeAt(pos);
|
|
78
|
-
tr = scaleTable(tableRef, {
|
|
79
|
-
node: newNode,
|
|
80
|
-
prevNode: node,
|
|
81
|
-
start: pos + 1,
|
|
82
|
-
parentWidth: newWidth
|
|
83
|
-
}, editorView.domAtPos.bind(editorView))(tr);
|
|
84
92
|
dispatch(tr);
|
|
85
93
|
|
|
86
94
|
// Hide guidelines when resizing stops
|
|
@@ -18,6 +18,7 @@ import { pluginConfig as getPluginConfig } from '../create-plugin-config';
|
|
|
18
18
|
import { getPluginState } from '../pm-plugins/plugin-factory';
|
|
19
19
|
import { pluginKey } from '../pm-plugins/plugin-key';
|
|
20
20
|
import { pluginKey as tableResizingPluginKey } from '../pm-plugins/table-resizing';
|
|
21
|
+
import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
|
|
21
22
|
import { generateColgroup } from '../pm-plugins/table-resizing/utils';
|
|
22
23
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
23
24
|
import TableComponent from './TableComponent';
|
|
@@ -107,16 +108,20 @@ var TableView = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
107
108
|
plugins: {
|
|
108
109
|
pluginState: pluginKey,
|
|
109
110
|
tableResizingPluginState: tableResizingPluginKey,
|
|
111
|
+
tableWidthPluginState: tableWidthPluginKey,
|
|
110
112
|
widthPlugin: fakePluginKey,
|
|
111
113
|
mediaState: fakeMediaPluginKey
|
|
112
114
|
},
|
|
113
115
|
editorView: props.view,
|
|
114
116
|
render: function render(pluginStates) {
|
|
115
117
|
var tableResizingPluginState = pluginStates.tableResizingPluginState,
|
|
118
|
+
tableWidthPluginState = pluginStates.tableWidthPluginState,
|
|
116
119
|
pluginState = pluginStates.pluginState,
|
|
117
120
|
mediaState = pluginStates.mediaState;
|
|
118
|
-
var tableActive = props.getPos() === pluginState.tablePos;
|
|
119
121
|
var containerWidth = props.getEditorContainerWidth();
|
|
122
|
+
var isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
|
|
123
|
+
var isResizing = Boolean((tableResizingPluginState === null || tableResizingPluginState === void 0 ? void 0 : tableResizingPluginState.dragging) || isTableResizing);
|
|
124
|
+
var tableActive = props.getPos() === pluginState.tablePos && !isTableResizing;
|
|
120
125
|
return /*#__PURE__*/React.createElement(TableComponent, {
|
|
121
126
|
view: props.view,
|
|
122
127
|
allowColumnResizing: props.allowColumnResizing,
|
|
@@ -129,7 +134,7 @@ var TableView = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
129
134
|
isHeaderColumnEnabled: pluginState.isHeaderColumnEnabled,
|
|
130
135
|
tableActive: tableActive,
|
|
131
136
|
ordering: pluginState.ordering,
|
|
132
|
-
|
|
137
|
+
isResizing: isResizing,
|
|
133
138
|
getNode: _this3.getNode,
|
|
134
139
|
containerWidth: containerWidth,
|
|
135
140
|
contentDOM: forwardRef,
|
|
@@ -6,13 +6,22 @@ import { PluginKey
|
|
|
6
6
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
7
7
|
import { DecorationSet } from 'prosemirror-view';
|
|
8
8
|
import { pluginKey as tablePluginKey } from '../plugin-key';
|
|
9
|
+
import { pluginKey as tableWidthPluginKey } from '../table-width';
|
|
9
10
|
import { buildColumnControlsDecorations, maybeUpdateColumnControlsSelectedDecoration } from './utils';
|
|
10
11
|
export var pluginKey = new PluginKey('tableDecorationsPlugin');
|
|
11
12
|
export var getDecorations = function getDecorations(state) {
|
|
12
13
|
return pluginKey.getState(state);
|
|
13
14
|
};
|
|
14
|
-
export var handleDocOrSelectionChanged = function handleDocOrSelectionChanged(tr, decorationSet, oldState) {
|
|
15
|
-
|
|
15
|
+
export var handleDocOrSelectionChanged = function handleDocOrSelectionChanged(tr, decorationSet, oldState, newState) {
|
|
16
|
+
var _tableWidthPluginKey$, _tableWidthPluginKey$2;
|
|
17
|
+
var isResizing = (_tableWidthPluginKey$ = tableWidthPluginKey.getState(newState)) === null || _tableWidthPluginKey$ === void 0 ? void 0 : _tableWidthPluginKey$.resizing;
|
|
18
|
+
var wasResizing = (_tableWidthPluginKey$2 = tableWidthPluginKey.getState(oldState)) === null || _tableWidthPluginKey$2 === void 0 ? void 0 : _tableWidthPluginKey$2.resizing;
|
|
19
|
+
var changedResizing = isResizing !== wasResizing;
|
|
20
|
+
|
|
21
|
+
// Remove column controls when resizing
|
|
22
|
+
if (isResizing) {
|
|
23
|
+
return DecorationSet.empty;
|
|
24
|
+
} else if (tr.docChanged || tr.selection instanceof CellSelection || changedResizing) {
|
|
16
25
|
return buildColumnControlsDecorations({
|
|
17
26
|
decorationSet: decorationSet,
|
|
18
27
|
tr: tr
|
|
@@ -34,15 +43,15 @@ export var createPlugin = function createPlugin() {
|
|
|
34
43
|
init: function init() {
|
|
35
44
|
return DecorationSet.empty;
|
|
36
45
|
},
|
|
37
|
-
apply: function apply(tr, decorationSet, oldState) {
|
|
46
|
+
apply: function apply(tr, decorationSet, oldState, newState) {
|
|
38
47
|
var pluginState = decorationSet;
|
|
39
48
|
var meta = tr.getMeta(tablePluginKey);
|
|
40
49
|
if (meta && meta.data && meta.data.decorationSet) {
|
|
41
50
|
pluginState = meta.data.decorationSet;
|
|
42
51
|
}
|
|
43
|
-
if (tr.docChanged || tr.selectionSet) {
|
|
52
|
+
if (tr.docChanged || tr.selectionSet || tr.getMeta(tableWidthPluginKey)) {
|
|
44
53
|
pluginState = pluginState.map(tr.mapping, tr.doc);
|
|
45
|
-
return handleDocOrSelectionChanged(tr, pluginState, oldState);
|
|
54
|
+
return handleDocOrSelectionChanged(tr, pluginState, oldState, newState);
|
|
46
55
|
}
|
|
47
56
|
return pluginState;
|
|
48
57
|
}
|
|
@@ -4,15 +4,37 @@ var _excluded = ["width"];
|
|
|
4
4
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
5
5
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
6
|
/**
|
|
7
|
-
* A plugin for
|
|
8
|
-
*
|
|
7
|
+
* A plugin for handle table custom widths
|
|
8
|
+
* Has login to scan the document, add width value to table's width attribute when necessary
|
|
9
|
+
* Also holds resizing state to hide / show table controls
|
|
9
10
|
*/
|
|
10
11
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
11
12
|
import { akEditorFullWidthLayoutWidth, akEditorWideLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
12
13
|
import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
|
|
13
14
|
import { ReplaceStep } from 'prosemirror-transform';
|
|
14
|
-
|
|
15
|
+
import { PluginKey } from 'prosemirror-state';
|
|
16
|
+
export var pluginKey = new PluginKey('tableWidthPlugin');
|
|
17
|
+
var createPlugin = function createPlugin(dispatch, fullWidthEnabled) {
|
|
15
18
|
return new SafePlugin({
|
|
19
|
+
key: pluginKey,
|
|
20
|
+
state: {
|
|
21
|
+
init: function init() {
|
|
22
|
+
return {
|
|
23
|
+
resizing: false
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
apply: function apply(tr, pluginState) {
|
|
27
|
+
var meta = tr.getMeta(pluginKey);
|
|
28
|
+
if (meta && meta.resizing !== pluginState.resizing) {
|
|
29
|
+
var newState = {
|
|
30
|
+
resizing: meta.resizing
|
|
31
|
+
};
|
|
32
|
+
dispatch(pluginKey, newState);
|
|
33
|
+
return newState;
|
|
34
|
+
}
|
|
35
|
+
return pluginState;
|
|
36
|
+
}
|
|
37
|
+
},
|
|
16
38
|
appendTransaction: function appendTransaction(transactions, _oldState, newState) {
|
|
17
39
|
// When document first load in Confluence, initially it is an empty document
|
|
18
40
|
// and Collab service triggers a transaction to replace the empty document with the real document that should be rendered.
|
|
@@ -7,6 +7,7 @@ import { clearHoverSelection, hoverTable, hoverColumns, hoverRows, removeDescend
|
|
|
7
7
|
import { deleteTableWithAnalytics, toggleHeaderColumnWithAnalytics, toggleHeaderRowWithAnalytics, toggleNumberColumnWithAnalytics, insertRowWithAnalytics, deleteRowsWithAnalytics, mergeCellsWithAnalytics, splitCellWithAnalytics, deleteColumnsWithAnalytics, emptyMultipleCellsWithAnalytics, insertColumnWithAnalytics, wrapTableInExpandWithAnalytics, sortColumnWithAnalytics, setColorWithAnalytics, distributeColumnsWidthsWithAnalytics } from './commands-with-analytics';
|
|
8
8
|
import { getPluginState } from './pm-plugins/plugin-factory';
|
|
9
9
|
import { pluginKey as tableResizingPluginKey } from './pm-plugins/table-resizing';
|
|
10
|
+
import { pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
|
|
10
11
|
import { TableCssClassName } from './types';
|
|
11
12
|
import { getMergedCellsPositions, getSelectedColumnIndexes, getSelectedRowIndexes } from './utils';
|
|
12
13
|
import { isReferencedSource, getChildrenInfo as _getChildrenInfo, getNodeName } from '@atlaskit/editor-common/utils';
|
|
@@ -293,7 +294,11 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
|
|
|
293
294
|
var tableObject = findTable(state.selection);
|
|
294
295
|
var pluginState = getPluginState(state);
|
|
295
296
|
var resizeState = tableResizingPluginKey.getState(state);
|
|
296
|
-
|
|
297
|
+
var tableWidthState = tableWidthPluginKey.getState(state);
|
|
298
|
+
|
|
299
|
+
// We don't want to show floating toolbar while resizing the table
|
|
300
|
+
var isWidthResizing = tableWidthState === null || tableWidthState === void 0 ? void 0 : tableWidthState.resizing;
|
|
301
|
+
if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
|
|
297
302
|
var nodeType = state.schema.nodes.table;
|
|
298
303
|
var menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
|
|
299
304
|
var _ref3 = getEditorFeatureFlags() || {},
|
package/dist/esm/version.json
CHANGED
|
@@ -4,7 +4,7 @@ import { EditorView } from 'prosemirror-view';
|
|
|
4
4
|
import type { EditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
5
5
|
import { RowStickyState, StickyPluginState } from '../pm-plugins/sticky-headers';
|
|
6
6
|
import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
7
|
-
import {
|
|
7
|
+
import { PluginInjectionAPI, ShadowEvent } from '../types';
|
|
8
8
|
import type { TableColumnOrdering } from '@atlaskit/adf-schema/steps';
|
|
9
9
|
import type { TableOptions } from './types';
|
|
10
10
|
import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
@@ -23,7 +23,7 @@ export interface ComponentProps {
|
|
|
23
23
|
isMediaFullscreen?: boolean;
|
|
24
24
|
tableActive: boolean;
|
|
25
25
|
ordering: TableColumnOrdering;
|
|
26
|
-
|
|
26
|
+
isResizing?: boolean;
|
|
27
27
|
getEditorFeatureFlags: GetEditorFeatureFlags;
|
|
28
28
|
pluginInjectionApi?: PluginInjectionAPI;
|
|
29
29
|
}
|
|
@@ -3,5 +3,5 @@ import { EditorState, PluginKey, Transaction, ReadonlyTransaction } from 'prosem
|
|
|
3
3
|
import { DecorationSet } from 'prosemirror-view';
|
|
4
4
|
export declare const pluginKey: PluginKey<any>;
|
|
5
5
|
export declare const getDecorations: (state: EditorState) => DecorationSet;
|
|
6
|
-
export declare const handleDocOrSelectionChanged: (tr: Transaction | ReadonlyTransaction, decorationSet: DecorationSet, oldState: EditorState) => DecorationSet;
|
|
6
|
+
export declare const handleDocOrSelectionChanged: (tr: Transaction | ReadonlyTransaction, decorationSet: DecorationSet, oldState: EditorState, newState: EditorState) => DecorationSet;
|
|
7
7
|
export declare const createPlugin: () => SafePlugin<any>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A plugin for handle table custom widths
|
|
3
|
+
* Has login to scan the document, add width value to table's width attribute when necessary
|
|
4
|
+
* Also holds resizing state to hide / show table controls
|
|
5
|
+
*/
|
|
6
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
7
|
+
import { PluginKey } from 'prosemirror-state';
|
|
8
|
+
import { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
9
|
+
type TableWidthPluginState = {
|
|
10
|
+
resizing: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare const pluginKey: PluginKey<TableWidthPluginState>;
|
|
13
|
+
declare const createPlugin: (dispatch: Dispatch, fullWidthEnabled: boolean) => SafePlugin<{
|
|
14
|
+
resizing: boolean;
|
|
15
|
+
}>;
|
|
16
|
+
export { createPlugin };
|
|
@@ -4,7 +4,7 @@ import { EditorView } from 'prosemirror-view';
|
|
|
4
4
|
import type { EditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
5
5
|
import { RowStickyState, StickyPluginState } from '../pm-plugins/sticky-headers';
|
|
6
6
|
import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
7
|
-
import {
|
|
7
|
+
import { PluginInjectionAPI, ShadowEvent } from '../types';
|
|
8
8
|
import type { TableColumnOrdering } from '@atlaskit/adf-schema/steps';
|
|
9
9
|
import type { TableOptions } from './types';
|
|
10
10
|
import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
@@ -23,7 +23,7 @@ export interface ComponentProps {
|
|
|
23
23
|
isMediaFullscreen?: boolean;
|
|
24
24
|
tableActive: boolean;
|
|
25
25
|
ordering: TableColumnOrdering;
|
|
26
|
-
|
|
26
|
+
isResizing?: boolean;
|
|
27
27
|
getEditorFeatureFlags: GetEditorFeatureFlags;
|
|
28
28
|
pluginInjectionApi?: PluginInjectionAPI;
|
|
29
29
|
}
|
|
@@ -3,5 +3,5 @@ import { EditorState, PluginKey, Transaction, ReadonlyTransaction } from 'prosem
|
|
|
3
3
|
import { DecorationSet } from 'prosemirror-view';
|
|
4
4
|
export declare const pluginKey: PluginKey<any>;
|
|
5
5
|
export declare const getDecorations: (state: EditorState) => DecorationSet;
|
|
6
|
-
export declare const handleDocOrSelectionChanged: (tr: Transaction | ReadonlyTransaction, decorationSet: DecorationSet, oldState: EditorState) => DecorationSet;
|
|
6
|
+
export declare const handleDocOrSelectionChanged: (tr: Transaction | ReadonlyTransaction, decorationSet: DecorationSet, oldState: EditorState, newState: EditorState) => DecorationSet;
|
|
7
7
|
export declare const createPlugin: () => SafePlugin<any>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A plugin for handle table custom widths
|
|
3
|
+
* Has login to scan the document, add width value to table's width attribute when necessary
|
|
4
|
+
* Also holds resizing state to hide / show table controls
|
|
5
|
+
*/
|
|
6
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
7
|
+
import { PluginKey } from 'prosemirror-state';
|
|
8
|
+
import { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
9
|
+
type TableWidthPluginState = {
|
|
10
|
+
resizing: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare const pluginKey: PluginKey<TableWidthPluginState>;
|
|
13
|
+
declare const createPlugin: (dispatch: Dispatch, fullWidthEnabled: boolean) => SafePlugin<{
|
|
14
|
+
resizing: boolean;
|
|
15
|
+
}>;
|
|
16
|
+
export { createPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@atlaskit/adf-schema": "^26.2.0",
|
|
31
|
-
"@atlaskit/editor-common": "^74.
|
|
31
|
+
"@atlaskit/editor-common": "^74.23.0",
|
|
32
32
|
"@atlaskit/editor-palette": "1.5.1",
|
|
33
33
|
"@atlaskit/editor-plugin-analytics": "^0.1.0",
|
|
34
34
|
"@atlaskit/editor-plugin-content-insertion": "^0.0.6",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"@atlaskit/editor-plugin-feature-flags": "^0.1.0",
|
|
66
66
|
"@atlaskit/editor-plugin-grid": "^0.1.0",
|
|
67
67
|
"@atlaskit/editor-plugin-guideline": "^0.3.4",
|
|
68
|
-
"@atlaskit/editor-plugin-hyperlink": "^0.
|
|
68
|
+
"@atlaskit/editor-plugin-hyperlink": "^0.2.0",
|
|
69
69
|
"@atlaskit/editor-plugin-width": "^0.1.0",
|
|
70
70
|
"@atlaskit/editor-test-helpers": "^18.10.0",
|
|
71
71
|
"@atlaskit/visual-regression": "*",
|