@atlaskit/editor-plugin-table 7.5.4 → 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 +13 -0
- package/dist/cjs/commands/column-resize.js +3 -3
- package/dist/cjs/commands/delete.js +2 -2
- package/dist/cjs/commands/insert.js +15 -15
- package/dist/cjs/commands-with-analytics.js +7 -7
- package/dist/cjs/event-handlers.js +27 -11
- package/dist/cjs/nodeviews/OverflowShadowsObserver.js +24 -15
- package/dist/cjs/nodeviews/TableCell.js +5 -30
- package/dist/cjs/nodeviews/TableComponent.js +120 -83
- package/dist/cjs/nodeviews/TableContainer.js +23 -21
- package/dist/cjs/nodeviews/TableResizer.js +13 -13
- package/dist/cjs/nodeviews/table.js +9 -9
- package/dist/cjs/plugin.js +60 -59
- package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +13 -13
- package/dist/cjs/pm-plugins/keymap.js +6 -8
- package/dist/cjs/pm-plugins/main.js +7 -24
- package/dist/cjs/pm-plugins/sticky-headers/plugin.js +2 -3
- package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +12 -12
- package/dist/cjs/pm-plugins/table-resizing/utils/colgroup.js +2 -2
- package/dist/cjs/pm-plugins/table-resizing/utils/consts.js +4 -2
- package/dist/cjs/pm-plugins/table-resizing/utils/index.js +2 -2
- package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +3 -3
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +3 -3
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +11 -12
- package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +13 -13
- package/dist/cjs/pm-plugins/table-width.js +6 -2
- package/dist/cjs/toolbar.js +21 -21
- package/dist/cjs/transforms/column-width.js +4 -4
- package/dist/cjs/transforms/delete-columns.js +2 -2
- package/dist/cjs/ui/FloatingContextualMenu/ContextualMenu.js +53 -55
- package/dist/cjs/ui/FloatingContextualMenu/index.js +2 -4
- package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +2 -2
- package/dist/cjs/ui/FloatingDragMenu/index.js +6 -6
- package/dist/cjs/ui/FloatingInsertButton/index.js +6 -7
- 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/create.js +2 -5
- package/dist/cjs/utils/dom.js +13 -15
- package/dist/cjs/utils/drag-menu.js +4 -4
- package/dist/es2019/commands/column-resize.js +3 -3
- package/dist/es2019/commands/delete.js +2 -2
- package/dist/es2019/commands/insert.js +12 -12
- package/dist/es2019/commands-with-analytics.js +6 -6
- package/dist/es2019/event-handlers.js +27 -11
- package/dist/es2019/nodeviews/OverflowShadowsObserver.js +24 -15
- package/dist/es2019/nodeviews/TableCell.js +1 -24
- package/dist/es2019/nodeviews/TableComponent.js +88 -63
- package/dist/es2019/nodeviews/TableContainer.js +20 -22
- package/dist/es2019/nodeviews/TableResizer.js +13 -13
- package/dist/es2019/nodeviews/table.js +9 -9
- package/dist/es2019/plugin.js +19 -20
- package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +6 -6
- package/dist/es2019/pm-plugins/keymap.js +5 -8
- package/dist/es2019/pm-plugins/main.js +6 -23
- package/dist/es2019/pm-plugins/sticky-headers/plugin.js +1 -1
- package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +5 -5
- package/dist/es2019/pm-plugins/table-resizing/utils/colgroup.js +2 -2
- package/dist/es2019/pm-plugins/table-resizing/utils/consts.js +3 -1
- package/dist/es2019/pm-plugins/table-resizing/utils/index.js +1 -1
- package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +2 -2
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +3 -2
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +12 -13
- package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +13 -13
- package/dist/es2019/pm-plugins/table-width.js +6 -2
- package/dist/es2019/toolbar.js +15 -15
- package/dist/es2019/transforms/column-width.js +5 -5
- package/dist/es2019/transforms/delete-columns.js +2 -2
- package/dist/es2019/ui/FloatingContextualMenu/ContextualMenu.js +9 -12
- package/dist/es2019/ui/FloatingContextualMenu/index.js +2 -4
- package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +2 -2
- package/dist/es2019/ui/FloatingDragMenu/index.js +5 -5
- package/dist/es2019/ui/FloatingInsertButton/index.js +5 -6
- 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/create.js +2 -5
- package/dist/es2019/utils/dom.js +13 -15
- package/dist/es2019/utils/drag-menu.js +4 -4
- package/dist/esm/commands/column-resize.js +3 -3
- package/dist/esm/commands/delete.js +2 -2
- package/dist/esm/commands/insert.js +15 -15
- package/dist/esm/commands-with-analytics.js +7 -7
- package/dist/esm/event-handlers.js +27 -11
- package/dist/esm/nodeviews/OverflowShadowsObserver.js +24 -15
- package/dist/esm/nodeviews/TableCell.js +5 -30
- package/dist/esm/nodeviews/TableComponent.js +119 -82
- package/dist/esm/nodeviews/TableContainer.js +24 -22
- package/dist/esm/nodeviews/TableResizer.js +13 -13
- package/dist/esm/nodeviews/table.js +9 -9
- package/dist/esm/plugin.js +60 -59
- package/dist/esm/pm-plugins/drag-and-drop/plugin.js +13 -13
- package/dist/esm/pm-plugins/keymap.js +6 -8
- package/dist/esm/pm-plugins/main.js +7 -24
- package/dist/esm/pm-plugins/sticky-headers/plugin.js +2 -3
- package/dist/esm/pm-plugins/table-resizing/event-handlers.js +12 -12
- package/dist/esm/pm-plugins/table-resizing/utils/colgroup.js +2 -2
- package/dist/esm/pm-plugins/table-resizing/utils/consts.js +3 -1
- package/dist/esm/pm-plugins/table-resizing/utils/index.js +1 -1
- package/dist/esm/pm-plugins/table-resizing/utils/misc.js +2 -2
- package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +4 -3
- package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +13 -14
- package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +13 -13
- package/dist/esm/pm-plugins/table-width.js +6 -2
- package/dist/esm/toolbar.js +21 -21
- package/dist/esm/transforms/column-width.js +5 -5
- package/dist/esm/transforms/delete-columns.js +2 -2
- package/dist/esm/ui/FloatingContextualMenu/ContextualMenu.js +53 -55
- package/dist/esm/ui/FloatingContextualMenu/index.js +2 -4
- package/dist/esm/ui/FloatingDragMenu/DragMenu.js +2 -2
- package/dist/esm/ui/FloatingDragMenu/index.js +6 -6
- package/dist/esm/ui/FloatingInsertButton/index.js +6 -7
- 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/create.js +2 -5
- package/dist/esm/utils/dom.js +13 -15
- package/dist/esm/utils/drag-menu.js +4 -4
- package/dist/types/commands/column-resize.d.ts +1 -1
- package/dist/types/commands/delete.d.ts +1 -1
- package/dist/types/commands/insert.d.ts +7 -7
- package/dist/types/commands-with-analytics.d.ts +3 -3
- package/dist/types/event-handlers.d.ts +4 -5
- 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 +6 -3
- package/dist/types/nodeviews/TableContainer.d.ts +6 -4
- package/dist/types/nodeviews/TableResizer.d.ts +2 -2
- package/dist/types/nodeviews/table.d.ts +1 -1
- package/dist/types/nodeviews/types.d.ts +1 -0
- package/dist/types/plugin.d.ts +1 -0
- package/dist/types/pm-plugins/drag-and-drop/plugin.d.ts +1 -2
- package/dist/types/pm-plugins/keymap.d.ts +2 -2
- package/dist/types/pm-plugins/main.d.ts +1 -1
- package/dist/types/pm-plugins/sticky-headers/plugin.d.ts +2 -3
- package/dist/types/pm-plugins/table-resizing/utils/colgroup.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/utils/consts.d.ts +1 -0
- package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +2 -1
- package/dist/types/pm-plugins/table-resizing/utils/resize-state.d.ts +4 -4
- package/dist/types/pm-plugins/table-resizing/utils/scale-table.d.ts +4 -4
- package/dist/types/pm-plugins/table-width.d.ts +1 -2
- package/dist/types/toolbar.d.ts +2 -2
- package/dist/types/transforms/column-width.d.ts +1 -1
- package/dist/types/transforms/delete-columns.d.ts +1 -1
- package/dist/types/types.d.ts +1 -3
- package/dist/types/ui/FloatingContextualMenu/index.d.ts +1 -1
- package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +2 -2
- package/dist/types/ui/FloatingDragMenu/index.d.ts +2 -3
- package/dist/types/ui/FloatingInsertButton/index.d.ts +1 -2
- package/dist/types/ui/TableFloatingColumnControls/index.d.ts +2 -1
- package/dist/types/ui/TableFloatingControls/index.d.ts +5 -22
- package/dist/types/utils/create.d.ts +1 -2
- package/dist/types/utils/dom.d.ts +10 -2
- package/dist/types/utils/drag-menu.d.ts +1 -1
- package/dist/types-ts4.5/commands/column-resize.d.ts +1 -1
- package/dist/types-ts4.5/commands/delete.d.ts +1 -1
- package/dist/types-ts4.5/commands/insert.d.ts +7 -7
- package/dist/types-ts4.5/commands-with-analytics.d.ts +3 -3
- package/dist/types-ts4.5/event-handlers.d.ts +4 -5
- 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 +6 -3
- package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +6 -4
- package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +2 -2
- package/dist/types-ts4.5/nodeviews/table.d.ts +1 -1
- package/dist/types-ts4.5/nodeviews/types.d.ts +1 -0
- package/dist/types-ts4.5/plugin.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/drag-and-drop/plugin.d.ts +1 -2
- package/dist/types-ts4.5/pm-plugins/keymap.d.ts +2 -2
- package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/sticky-headers/plugin.d.ts +2 -3
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/colgroup.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/consts.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-state.d.ts +4 -4
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/scale-table.d.ts +4 -4
- package/dist/types-ts4.5/pm-plugins/table-width.d.ts +1 -2
- package/dist/types-ts4.5/toolbar.d.ts +2 -2
- package/dist/types-ts4.5/transforms/column-width.d.ts +1 -1
- package/dist/types-ts4.5/transforms/delete-columns.d.ts +1 -1
- package/dist/types-ts4.5/types.d.ts +1 -3
- package/dist/types-ts4.5/ui/FloatingContextualMenu/index.d.ts +1 -1
- package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +2 -2
- package/dist/types-ts4.5/ui/FloatingDragMenu/index.d.ts +2 -3
- package/dist/types-ts4.5/ui/FloatingInsertButton/index.d.ts +1 -2
- 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/create.d.ts +1 -2
- package/dist/types-ts4.5/utils/dom.d.ts +10 -2
- package/dist/types-ts4.5/utils/drag-menu.d.ts +1 -1
- package/package.json +3 -4
- package/src/commands/column-resize.ts +4 -3
- package/src/commands/delete.ts +2 -2
- package/src/commands/insert.ts +15 -27
- package/src/commands-with-analytics.ts +6 -9
- package/src/event-handlers.ts +107 -105
- package/src/nodeviews/OverflowShadowsObserver.ts +32 -21
- package/src/nodeviews/TableCell.ts +0 -26
- package/src/nodeviews/TableComponent.tsx +107 -78
- package/src/nodeviews/TableContainer.tsx +26 -32
- package/src/nodeviews/TableResizer.tsx +15 -18
- package/src/nodeviews/table.tsx +6 -5
- package/src/nodeviews/types.ts +1 -0
- package/src/plugin.tsx +17 -32
- package/src/pm-plugins/drag-and-drop/plugin.ts +10 -15
- package/src/pm-plugins/keymap.ts +6 -13
- package/src/pm-plugins/main.ts +6 -25
- package/src/pm-plugins/sticky-headers/plugin.ts +2 -11
- package/src/pm-plugins/table-resizing/event-handlers.ts +6 -4
- package/src/pm-plugins/table-resizing/utils/colgroup.ts +2 -2
- package/src/pm-plugins/table-resizing/utils/consts.ts +2 -0
- package/src/pm-plugins/table-resizing/utils/index.ts +1 -1
- package/src/pm-plugins/table-resizing/utils/misc.ts +2 -2
- package/src/pm-plugins/table-resizing/utils/resize-column.ts +5 -2
- package/src/pm-plugins/table-resizing/utils/resize-state.ts +18 -13
- package/src/pm-plugins/table-resizing/utils/scale-table.ts +14 -14
- package/src/pm-plugins/table-width.ts +4 -6
- package/src/toolbar.tsx +16 -19
- package/src/transforms/column-width.ts +7 -6
- package/src/transforms/delete-columns.ts +2 -2
- package/src/types.ts +1 -4
- package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +11 -16
- package/src/ui/FloatingContextualMenu/index.tsx +0 -2
- package/src/ui/FloatingDragMenu/DragMenu.tsx +3 -3
- package/src/ui/FloatingDragMenu/index.tsx +4 -8
- package/src/ui/FloatingInsertButton/index.tsx +11 -22
- 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/create.ts +2 -5
- package/src/utils/dom.ts +12 -19
- package/src/utils/drag-menu.ts +7 -12
package/dist/es2019/plugin.js
CHANGED
|
@@ -18,6 +18,7 @@ import { createPlugin as createDecorationsPlugin } from './pm-plugins/decoration
|
|
|
18
18
|
import { createPlugin as createDragAndDropPlugin, pluginKey as dragAndDropPluginKey } from './pm-plugins/drag-and-drop';
|
|
19
19
|
import { keymapPlugin } from './pm-plugins/keymap';
|
|
20
20
|
import { createPlugin } from './pm-plugins/main';
|
|
21
|
+
import { getPluginState } from './pm-plugins/plugin-factory';
|
|
21
22
|
import { pluginKey } from './pm-plugins/plugin-key';
|
|
22
23
|
import { createPlugin as createTableSafariDeleteCompositionTextIssueWorkaroundPlugin } from './pm-plugins/safari-delete-composition-text-issue-workaround';
|
|
23
24
|
import { createPlugin as createStickyHeadersPlugin, findStickyHeaderForTable, pluginKey as stickyHeadersPluginKey } from './pm-plugins/sticky-headers';
|
|
@@ -48,11 +49,10 @@ const tablesPlugin = ({
|
|
|
48
49
|
current: null
|
|
49
50
|
};
|
|
50
51
|
const defaultGetEditorContainerWidth = () => {
|
|
51
|
-
var
|
|
52
|
-
|
|
52
|
+
var _api$width$sharedStat, _api$width, _document$body$offset, _document, _document$body;
|
|
53
|
+
return (_api$width$sharedStat = api === null || api === void 0 ? void 0 : (_api$width = api.width) === null || _api$width === void 0 ? void 0 : _api$width.sharedState.currentState()) !== null && _api$width$sharedStat !== void 0 ? _api$width$sharedStat : {
|
|
53
54
|
width: (_document$body$offset = (_document = document) === null || _document === void 0 ? void 0 : (_document$body = _document.body) === null || _document$body === void 0 ? void 0 : _document$body.offsetWidth) !== null && _document$body$offset !== void 0 ? _document$body$offset : 500
|
|
54
55
|
};
|
|
55
|
-
return (_api$width$sharedStat = api === null || api === void 0 ? void 0 : (_api$width = api.width) === null || _api$width === void 0 ? void 0 : _api$width.sharedState.currentState()) !== null && _api$width$sharedStat !== void 0 ? _api$width$sharedStat : defaultState;
|
|
56
56
|
};
|
|
57
57
|
const editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
|
|
58
58
|
return {
|
|
@@ -68,7 +68,7 @@ const tablesPlugin = ({
|
|
|
68
68
|
actions: {
|
|
69
69
|
insertTable: analyticsPayload => (state, dispatch) => {
|
|
70
70
|
var _api$contentInsertion, _api$contentInsertion2, _api$contentInsertion3;
|
|
71
|
-
const node = createTableWithWidth(options === null || options === void 0 ? void 0 : options.
|
|
71
|
+
const node = createTableWithWidth(options === null || options === void 0 ? void 0 : options.isTableScalingEnabled, options === null || options === void 0 ? void 0 : options.fullWidthEnabled)(state.schema);
|
|
72
72
|
return (_api$contentInsertion = api === null || api === void 0 ? void 0 : (_api$contentInsertion2 = api.contentInsertion) === null || _api$contentInsertion2 === void 0 ? void 0 : (_api$contentInsertion3 = _api$contentInsertion2.actions) === null || _api$contentInsertion3 === void 0 ? void 0 : _api$contentInsertion3.insert({
|
|
73
73
|
state,
|
|
74
74
|
dispatch,
|
|
@@ -81,7 +81,7 @@ const tablesPlugin = ({
|
|
|
81
81
|
}
|
|
82
82
|
},
|
|
83
83
|
commands: {
|
|
84
|
-
insertTableWithSize: insertTableWithSize(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.
|
|
84
|
+
insertTableWithSize: insertTableWithSize(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
|
|
85
85
|
},
|
|
86
86
|
nodes() {
|
|
87
87
|
const tableNode = options !== null && options !== void 0 && options.tableResizingEnabled ? tableWithCustomWidth : table;
|
|
@@ -116,9 +116,10 @@ const tablesPlugin = ({
|
|
|
116
116
|
breakoutEnabled,
|
|
117
117
|
tableOptions,
|
|
118
118
|
getEditorFeatureFlags,
|
|
119
|
-
dragAndDropEnabled
|
|
119
|
+
dragAndDropEnabled,
|
|
120
|
+
isTableScalingEnabled
|
|
120
121
|
} = options || {};
|
|
121
|
-
return createPlugin(dispatchAnalyticsEvent, dispatch, portalProviderAPI, eventDispatcher, pluginConfig(tableOptions), defaultGetEditorContainerWidth, getEditorFeatureFlags || defaultGetEditorFeatureFlags, getIntl, breakoutEnabled, tableResizingEnabled, fullWidthEnabled, wasFullWidthEnabled, dragAndDropEnabled, editorAnalyticsAPI, api);
|
|
122
|
+
return createPlugin(dispatchAnalyticsEvent, dispatch, portalProviderAPI, eventDispatcher, pluginConfig(tableOptions), defaultGetEditorContainerWidth, getEditorFeatureFlags || defaultGetEditorFeatureFlags, getIntl, breakoutEnabled, tableResizingEnabled, fullWidthEnabled, wasFullWidthEnabled, dragAndDropEnabled, editorAnalyticsAPI, api, isTableScalingEnabled);
|
|
122
123
|
}
|
|
123
124
|
}, {
|
|
124
125
|
name: 'tablePMColResizing',
|
|
@@ -148,9 +149,9 @@ const tablesPlugin = ({
|
|
|
148
149
|
plugin: () => {
|
|
149
150
|
const {
|
|
150
151
|
dragAndDropEnabled,
|
|
151
|
-
|
|
152
|
+
isTableScalingEnabled = false
|
|
152
153
|
} = options || {};
|
|
153
|
-
return keymapPlugin(defaultGetEditorContainerWidth, editorAnalyticsAPI,
|
|
154
|
+
return keymapPlugin(defaultGetEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled, isTableScalingEnabled);
|
|
154
155
|
}
|
|
155
156
|
}, {
|
|
156
157
|
name: 'tableSelectionKeymap',
|
|
@@ -184,16 +185,13 @@ const tablesPlugin = ({
|
|
|
184
185
|
plugin: ({
|
|
185
186
|
dispatch,
|
|
186
187
|
eventDispatcher
|
|
187
|
-
}) => options && options.tableOptions.stickyHeaders ? createStickyHeadersPlugin(dispatch,
|
|
188
|
+
}) => options && options.tableOptions.stickyHeaders ? createStickyHeadersPlugin(dispatch, () => []) : undefined
|
|
188
189
|
}, {
|
|
189
190
|
name: 'tableDragAndDrop',
|
|
190
191
|
plugin: ({
|
|
191
192
|
dispatch
|
|
192
193
|
}) => {
|
|
193
|
-
|
|
194
|
-
getEditorFeatureFlags
|
|
195
|
-
} = options || {};
|
|
196
|
-
return options !== null && options !== void 0 && options.dragAndDropEnabled ? createDragAndDropPlugin(dispatch, getEditorFeatureFlags, editorAnalyticsAPI) : undefined;
|
|
194
|
+
return options !== null && options !== void 0 && options.dragAndDropEnabled ? createDragAndDropPlugin(dispatch, editorAnalyticsAPI) : undefined;
|
|
197
195
|
}
|
|
198
196
|
}, {
|
|
199
197
|
name: 'tableLocalId',
|
|
@@ -207,7 +205,7 @@ const tablesPlugin = ({
|
|
|
207
205
|
dispatch
|
|
208
206
|
}) => {
|
|
209
207
|
var _options$fullWidthEna;
|
|
210
|
-
return options !== null && options !== void 0 && options.tableResizingEnabled ? createTableWidthPlugin(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false
|
|
208
|
+
return options !== null && options !== void 0 && options.tableResizingEnabled ? createTableWidthPlugin(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false) : undefined;
|
|
211
209
|
}
|
|
212
210
|
},
|
|
213
211
|
// TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
|
|
@@ -344,8 +342,7 @@ const tablesPlugin = ({
|
|
|
344
342
|
hasStickyHeaders: stickyHeader && stickyHeader.sticky,
|
|
345
343
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
346
344
|
editorAnalyticsAPI: editorAnalyticsAPI,
|
|
347
|
-
getEditorContainerWidth: defaultGetEditorContainerWidth
|
|
348
|
-
getEditorFeatureFlags: (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags
|
|
345
|
+
getEditorContainerWidth: defaultGetEditorContainerWidth
|
|
349
346
|
}), (options === null || options === void 0 ? void 0 : options.allowContextualMenu) && /*#__PURE__*/React.createElement(FloatingContextualMenu, {
|
|
350
347
|
editorView: editorView,
|
|
351
348
|
mountPoint: popupsMountPoint,
|
|
@@ -369,8 +366,7 @@ const tablesPlugin = ({
|
|
|
369
366
|
getEditorContainerWidth: defaultGetEditorContainerWidth,
|
|
370
367
|
editorAnalyticsAPI: editorAnalyticsAPI,
|
|
371
368
|
stickyHeaders: stickyHeader,
|
|
372
|
-
pluginConfig: pluginConfig
|
|
373
|
-
getEditorFeatureFlags: (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags
|
|
369
|
+
pluginConfig: pluginConfig
|
|
374
370
|
}), allowControls && !isDragAndDropEnabled && !isResizing && /*#__PURE__*/React.createElement(FloatingDeleteButton, {
|
|
375
371
|
editorView: editorView,
|
|
376
372
|
selection: editorView.state.selection,
|
|
@@ -400,7 +396,10 @@ const tablesPlugin = ({
|
|
|
400
396
|
var _api$table;
|
|
401
397
|
// see comment on tablesPlugin.getSharedState on usage
|
|
402
398
|
const tableState = api === null || api === void 0 ? void 0 : (_api$table = api.table) === null || _api$table === void 0 ? void 0 : _api$table.sharedState.currentState();
|
|
403
|
-
const
|
|
399
|
+
const {
|
|
400
|
+
isTableScalingEnabled = false
|
|
401
|
+
} = getPluginState(state);
|
|
402
|
+
const tr = insert(createTableWithWidth(isTableScalingEnabled, tableState === null || tableState === void 0 ? void 0 : tableState.isFullWidthModeEnabled)(state.schema));
|
|
404
403
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
405
404
|
action: ACTION.INSERTED,
|
|
406
405
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
@@ -17,7 +17,7 @@ import { DropTargetType } from './consts';
|
|
|
17
17
|
import { createPluginState, getPluginState } from './plugin-factory';
|
|
18
18
|
import { pluginKey } from './plugin-key';
|
|
19
19
|
import { getDraggableDataFromEvent } from './utils/monitor';
|
|
20
|
-
const destroyFn = (editorView, editorAnalyticsAPI
|
|
20
|
+
const destroyFn = (editorView, editorAnalyticsAPI) => {
|
|
21
21
|
const editorPageScrollContainer = document.querySelector('.fabric-editor-popup-scroll-parent');
|
|
22
22
|
const rowAutoScrollers = editorPageScrollContainer ? [monitorForElements({
|
|
23
23
|
canMonitor({
|
|
@@ -162,9 +162,9 @@ const destroyFn = (editorView, editorAnalyticsAPI, getEditorFeatureFlags) => {
|
|
|
162
162
|
} = getTablePluginState(editorView.state);
|
|
163
163
|
if (tableRef && tableNode) {
|
|
164
164
|
const {
|
|
165
|
-
|
|
166
|
-
} = (
|
|
167
|
-
insertColgroupFromNode(tableRef, tableNode,
|
|
165
|
+
isTableScalingEnabled = false
|
|
166
|
+
} = getTablePluginState(editorView.state);
|
|
167
|
+
insertColgroupFromNode(tableRef, tableNode, isTableScalingEnabled);
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
editorView.focus();
|
|
@@ -172,7 +172,7 @@ const destroyFn = (editorView, editorAnalyticsAPI, getEditorFeatureFlags) => {
|
|
|
172
172
|
}
|
|
173
173
|
}));
|
|
174
174
|
};
|
|
175
|
-
export const createPlugin = (dispatch,
|
|
175
|
+
export const createPlugin = (dispatch, editorAnalyticsAPI) => {
|
|
176
176
|
return new SafePlugin({
|
|
177
177
|
state: createPluginState(dispatch, state => ({
|
|
178
178
|
decorationSet: DecorationSet.empty,
|
|
@@ -241,7 +241,7 @@ export const createPlugin = (dispatch, getEditorFeatureFlags, editorAnalyticsAPI
|
|
|
241
241
|
},
|
|
242
242
|
view: editorView => {
|
|
243
243
|
return {
|
|
244
|
-
destroy: destroyFn(editorView, editorAnalyticsAPI
|
|
244
|
+
destroy: destroyFn(editorView, editorAnalyticsAPI)
|
|
245
245
|
};
|
|
246
246
|
},
|
|
247
247
|
props: {
|
|
@@ -18,7 +18,7 @@ const createTableWithAnalytics = editorAnalyticsAPI => withEditorAnalyticsAPI({
|
|
|
18
18
|
},
|
|
19
19
|
eventType: EVENT_TYPE.TRACK
|
|
20
20
|
})(editorAnalyticsAPI)(createTable());
|
|
21
|
-
export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI,
|
|
21
|
+
export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled, isTableScalingEnabled = false) {
|
|
22
22
|
const list = {};
|
|
23
23
|
bindKeymapWithCommand(nextCell.common, goToNextCell(editorAnalyticsAPI)(1), list);
|
|
24
24
|
bindKeymapWithCommand(previousCell.common, goToNextCell(editorAnalyticsAPI)(-1), list);
|
|
@@ -29,8 +29,8 @@ export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, getEdi
|
|
|
29
29
|
// Add row/column shortcuts
|
|
30
30
|
bindKeymapWithCommand(addRowBefore.common, addRowAroundSelection(editorAnalyticsAPI)('TOP'), list);
|
|
31
31
|
bindKeymapWithCommand(addRowAfter.common, addRowAroundSelection(editorAnalyticsAPI)('BOTTOM'), list);
|
|
32
|
-
bindKeymapWithCommand(addColumnBefore.common, addColumnBeforeCommand(
|
|
33
|
-
bindKeymapWithCommand(addColumnAfter.common, addColumnAfterCommand(
|
|
32
|
+
bindKeymapWithCommand(addColumnBefore.common, addColumnBeforeCommand(isTableScalingEnabled), list);
|
|
33
|
+
bindKeymapWithCommand(addColumnAfter.common, addColumnAfterCommand(isTableScalingEnabled), list);
|
|
34
34
|
if (dragAndDropEnabled) {
|
|
35
35
|
// Move row/column shortcuts
|
|
36
36
|
/**
|
|
@@ -50,14 +50,11 @@ export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, getEdi
|
|
|
50
50
|
bindKeymapWithCommand(deleteRow.common, deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut(editorAnalyticsAPI), list);
|
|
51
51
|
}
|
|
52
52
|
if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
53
|
-
const {
|
|
54
|
-
tablePreserveWidth = false
|
|
55
|
-
} = getEditorFeatureFlags ? getEditorFeatureFlags() : {};
|
|
56
53
|
bindKeymapWithCommand(startColumnResizing.common, initiateKeyboardColumnResizing, list);
|
|
57
54
|
bindKeymapWithCommand(moveRight.common, activateNextResizeArea(1), list);
|
|
58
55
|
bindKeymapWithCommand(moveLeft.common, activateNextResizeArea(-1), list);
|
|
59
|
-
bindKeymapWithCommand(decreaseMediaSize.common, changeColumnWidthByStepWithAnalytics(editorAnalyticsAPI)(-10, getEditorContainerWidth,
|
|
60
|
-
bindKeymapWithCommand(increaseMediaSize.common, changeColumnWidthByStepWithAnalytics(editorAnalyticsAPI)(10, getEditorContainerWidth,
|
|
56
|
+
bindKeymapWithCommand(decreaseMediaSize.common, changeColumnWidthByStepWithAnalytics(editorAnalyticsAPI)(-10, getEditorContainerWidth, isTableScalingEnabled, INPUT_METHOD.SHORTCUT), list);
|
|
57
|
+
bindKeymapWithCommand(increaseMediaSize.common, changeColumnWidthByStepWithAnalytics(editorAnalyticsAPI)(10, getEditorContainerWidth, isTableScalingEnabled, INPUT_METHOD.SHORTCUT), list);
|
|
61
58
|
bindKeymapWithCommand(escape.common, stopKeyboardColumnResizing(), list);
|
|
62
59
|
}
|
|
63
60
|
return keymap(list);
|
|
@@ -22,8 +22,7 @@ import { isHeaderRowRequired } from '../utils/paste';
|
|
|
22
22
|
import { defaultHoveredCell, defaultTableSelection } from './default-table-selection';
|
|
23
23
|
import { createPluginState, getPluginState } from './plugin-factory';
|
|
24
24
|
import { pluginKey } from './plugin-key';
|
|
25
|
-
export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI, eventDispatcher, pluginConfig, getEditorContainerWidth, getEditorFeatureFlags, getIntl, breakoutEnabled, tableResizingEnabled, fullWidthModeEnabled, previousFullWidthModeEnabled, dragAndDropEnabled, editorAnalyticsAPI, pluginInjectionApi) => {
|
|
26
|
-
var _window;
|
|
25
|
+
export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI, eventDispatcher, pluginConfig, getEditorContainerWidth, getEditorFeatureFlags, getIntl, breakoutEnabled, tableResizingEnabled, fullWidthModeEnabled, previousFullWidthModeEnabled, dragAndDropEnabled, editorAnalyticsAPI, pluginInjectionApi, isTableScalingEnabled) => {
|
|
27
26
|
const state = createPluginState(dispatch, {
|
|
28
27
|
pluginConfig,
|
|
29
28
|
isTableHovered: false,
|
|
@@ -36,19 +35,11 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
|
|
|
36
35
|
isHeaderRowEnabled: !!pluginConfig.allowHeaderRow,
|
|
37
36
|
isHeaderColumnEnabled: false,
|
|
38
37
|
isDragAndDropEnabled: dragAndDropEnabled,
|
|
38
|
+
isTableScalingEnabled: isTableScalingEnabled,
|
|
39
39
|
...defaultHoveredCell,
|
|
40
40
|
...defaultTableSelection,
|
|
41
41
|
getIntl
|
|
42
42
|
});
|
|
43
|
-
let elementContentRects = {};
|
|
44
|
-
const observer = (_window = window) !== null && _window !== void 0 && _window.ResizeObserver ? new ResizeObserver(entries => {
|
|
45
|
-
entries.forEach(entry => {
|
|
46
|
-
if (!entry.target.id) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
elementContentRects[entry.target.id] = entry.contentRect;
|
|
50
|
-
});
|
|
51
|
-
}) : undefined;
|
|
52
43
|
|
|
53
44
|
// Used to prevent invalid table cell spans being reported more than once per editor/document
|
|
54
45
|
const invalidTableIds = [];
|
|
@@ -82,12 +73,9 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
|
|
|
82
73
|
}
|
|
83
74
|
});
|
|
84
75
|
}
|
|
85
|
-
const {
|
|
86
|
-
tablePreserveWidth = false
|
|
87
|
-
} = getEditorFeatureFlags();
|
|
88
76
|
if (tr) {
|
|
89
77
|
// "fixTables" removes empty rows as we don't allow that in schema
|
|
90
|
-
const updatedTr = handleCut(tr, oldState, newState, editorAnalyticsAPI, editorViewRef || undefined,
|
|
78
|
+
const updatedTr = handleCut(tr, oldState, newState, editorAnalyticsAPI, editorViewRef || undefined, isTableScalingEnabled);
|
|
91
79
|
return fixTables(updatedTr) || updatedTr;
|
|
92
80
|
}
|
|
93
81
|
if (transactions.find(tr => tr.docChanged)) {
|
|
@@ -153,11 +141,6 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
|
|
|
153
141
|
} else if (pluginState.isResizeHandleWidgetAdded) {
|
|
154
142
|
removeResizeHandleDecorations()(state, dispatch);
|
|
155
143
|
}
|
|
156
|
-
},
|
|
157
|
-
destroy: () => {
|
|
158
|
-
if (observer) {
|
|
159
|
-
observer.disconnect();
|
|
160
|
-
}
|
|
161
144
|
}
|
|
162
145
|
};
|
|
163
146
|
},
|
|
@@ -266,8 +249,8 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
|
|
|
266
249
|
nodeViews: {
|
|
267
250
|
table: (node, view, getPos) => createTableView(node, view, getPos, portalProviderAPI, eventDispatcher, getEditorContainerWidth, getEditorFeatureFlags, dispatchAnalyticsEvent, pluginInjectionApi),
|
|
268
251
|
tableRow: (node, view, getPos) => new TableRow(node, view, getPos, eventDispatcher),
|
|
269
|
-
tableCell: (node, view, getPos) => new TableCell(node, view, getPos, eventDispatcher
|
|
270
|
-
tableHeader: (node, view, getPos) => new TableCell(node, view, getPos, eventDispatcher
|
|
252
|
+
tableCell: (node, view, getPos) => new TableCell(node, view, getPos, eventDispatcher),
|
|
253
|
+
tableHeader: (node, view, getPos) => new TableCell(node, view, getPos, eventDispatcher)
|
|
271
254
|
},
|
|
272
255
|
handleDOMEvents: {
|
|
273
256
|
focus: handleFocus,
|
|
@@ -276,7 +259,7 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
|
|
|
276
259
|
mouseover: withCellTracking(whenTableInFocus(handleMouseOver)),
|
|
277
260
|
mouseleave: handleMouseLeave,
|
|
278
261
|
mouseout: whenTableInFocus(handleMouseOut),
|
|
279
|
-
mousemove: whenTableInFocus(handleMouseMove
|
|
262
|
+
mousemove: whenTableInFocus(handleMouseMove),
|
|
280
263
|
mouseenter: handleMouseEnter,
|
|
281
264
|
mouseup: whenTableInFocus(handleMouseUp),
|
|
282
265
|
click: withCellTracking(whenTableInFocus(handleClick))
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import { pluginKey } from './plugin-key';
|
|
3
3
|
import { createPluginState } from './plugin-state';
|
|
4
|
-
export const createPlugin = (dispatch,
|
|
4
|
+
export const createPlugin = (dispatch, initialState = () => []) => {
|
|
5
5
|
return new SafePlugin({
|
|
6
6
|
state: createPluginState(dispatch, initialState),
|
|
7
7
|
key: pluginKey
|
|
@@ -22,8 +22,8 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
22
22
|
const editorDisabled = !view.editable;
|
|
23
23
|
const domAtPos = view.domAtPos.bind(view);
|
|
24
24
|
const {
|
|
25
|
-
|
|
26
|
-
} =
|
|
25
|
+
isTableScalingEnabled = false
|
|
26
|
+
} = getTablePluginState(state);
|
|
27
27
|
if (editorDisabled || localResizeHandlePos === null || !pointsAtCell(state.doc.resolve(localResizeHandlePos))) {
|
|
28
28
|
return false;
|
|
29
29
|
}
|
|
@@ -71,7 +71,7 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
71
71
|
tableRef: dom,
|
|
72
72
|
start,
|
|
73
73
|
domAtPos,
|
|
74
|
-
|
|
74
|
+
isTableScalingEnabled: isTableScalingEnabled
|
|
75
75
|
});
|
|
76
76
|
if (evenColumns({
|
|
77
77
|
resizeState,
|
|
@@ -153,7 +153,7 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
153
153
|
const selectedColumns = selectionRect ? getSelectedColumnIndexes(selectionRect) : [];
|
|
154
154
|
// only selected (or selected - 1) columns should be distributed
|
|
155
155
|
const resizingSelectedColumns = selectedColumns.indexOf(colIndex) > -1 || selectedColumns.indexOf(colIndex + 1) > -1;
|
|
156
|
-
const newResizeState = resizeColumn(resizeState, colIndex, clientX - startX, dom, resizingSelectedColumns ? selectedColumns : undefined,
|
|
156
|
+
const newResizeState = resizeColumn(resizeState, colIndex, clientX - startX, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, isTableScalingEnabled);
|
|
157
157
|
const resizedDelta = clientX - startX;
|
|
158
158
|
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
159
159
|
if (colIndex === map.width - 1) {
|
|
@@ -222,7 +222,7 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
|
|
|
222
222
|
const table = $cell.node(-1);
|
|
223
223
|
const map = TableMap.get(table);
|
|
224
224
|
const colIndex = map.colCount($cell.pos - $cell.start(-1)) + $cell.nodeAfter.attrs.colspan - 1;
|
|
225
|
-
resizeColumn(resizeState, colIndex, clientX - dragging.startX, dom, undefined,
|
|
225
|
+
resizeColumn(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, isTableScalingEnabled);
|
|
226
226
|
updateControls()(state);
|
|
227
227
|
}
|
|
228
228
|
window.addEventListener('mouseup', finish);
|
|
@@ -75,12 +75,12 @@ export const generateColgroup = (table, tableRef) => {
|
|
|
75
75
|
}
|
|
76
76
|
return cols;
|
|
77
77
|
};
|
|
78
|
-
export const insertColgroupFromNode = (tableRef, table,
|
|
78
|
+
export const insertColgroupFromNode = (tableRef, table, isTableScalingEnabled = false, shouldRemove = true) => {
|
|
79
79
|
let colgroup = tableRef.querySelector('colgroup');
|
|
80
80
|
if (colgroup && shouldRemove) {
|
|
81
81
|
tableRef.removeChild(colgroup);
|
|
82
82
|
}
|
|
83
|
-
colgroup = renderColgroupFromNode(table,
|
|
83
|
+
colgroup = renderColgroupFromNode(table, isTableScalingEnabled ? tableRef : undefined);
|
|
84
84
|
if (shouldRemove) {
|
|
85
85
|
tableRef.insertBefore(colgroup, tableRef.firstChild);
|
|
86
86
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export const COLUMN_MIN_WIDTH = 48;
|
|
2
2
|
export const TABLE_DEFAULT_WIDTH = 760;
|
|
3
3
|
export const TABLE_MAX_WIDTH = 1800;
|
|
4
|
-
export const MAX_SCALING_PERCENT = 0.3;
|
|
4
|
+
export const MAX_SCALING_PERCENT = 0.3;
|
|
5
|
+
// Used to calculate the width of a table using the Editor width
|
|
6
|
+
export const TABLE_EDITOR_MARGIN = 76;
|
|
@@ -3,7 +3,7 @@ export { contentWidth } from './content-width';
|
|
|
3
3
|
export { getColumnStateFromDOM, getFreeSpace, getCellsRefsInColumn, calculateColumnWidth, addContainerLeftRightPadding } from './column-state';
|
|
4
4
|
export { growColumn, shrinkColumn, reduceSpace } from './resize-logic';
|
|
5
5
|
export { getResizeState, updateColgroup, getTotalWidth, evenAllColumnsWidths, bulkColumnsResize, areColumnsEven, adjustColumnsWidths } from './resize-state';
|
|
6
|
-
export { getLayoutSize, getDefaultLayoutMaxWidth, pointsAtCell, currentColWidth, domCellAround, getTableMaxWidth, getTableElementWidth,
|
|
6
|
+
export { getLayoutSize, getDefaultLayoutMaxWidth, pointsAtCell, currentColWidth, domCellAround, getTableMaxWidth, getTableElementWidth, getTableContainerElementWidth } from './misc';
|
|
7
7
|
export { updateControls, isClickNear, getResizeCellPos } from './dom';
|
|
8
8
|
export { scale, scaleWithParent, scaleTable, previewScaleTable } from './scale-table';
|
|
9
9
|
export { resizeColumn } from './resize-column';
|
|
@@ -85,8 +85,8 @@ export const getTableElementWidth = table => {
|
|
|
85
85
|
// TODO: is there a scenario where ADF columns are SMALLER than container width?
|
|
86
86
|
return calcTableColumnWidths(table).reduce((sum, width) => sum + width, 0);
|
|
87
87
|
}
|
|
88
|
-
return
|
|
88
|
+
return getTableContainerElementWidth(table);
|
|
89
89
|
};
|
|
90
|
-
export const
|
|
90
|
+
export const getTableContainerElementWidth = table => {
|
|
91
91
|
return getTableContainerWidth(table);
|
|
92
92
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Resize a given column by an amount from the current state
|
|
2
|
+
|
|
2
3
|
import { growColumn, shrinkColumn } from './resize-logic';
|
|
3
4
|
import { updateColgroup } from './resize-state';
|
|
4
|
-
export const resizeColumn = (resizeState, colIndex, amount, tableRef, selectedColumns,
|
|
5
|
+
export const resizeColumn = (resizeState, colIndex, amount, tableRef, tableNode, selectedColumns, isTableScalingEnabled = false) => {
|
|
5
6
|
const newState = amount > 0 ? growColumn(resizeState, colIndex, amount, selectedColumns) : amount < 0 ? shrinkColumn(resizeState, colIndex, amount, selectedColumns) : resizeState;
|
|
6
|
-
updateColgroup(newState, tableRef,
|
|
7
|
+
updateColgroup(newState, tableRef, tableNode, isTableScalingEnabled);
|
|
7
8
|
return newState;
|
|
8
9
|
};
|
|
@@ -5,8 +5,8 @@ import { getSelectedTableInfo } from '../../../utils';
|
|
|
5
5
|
import { getColWidthFix, hasTableBeenResized, insertColgroupFromNode } from './colgroup';
|
|
6
6
|
import { getCellsRefsInColumn, getColumnStateFromDOM } from './column-state';
|
|
7
7
|
import { syncStickyRowToTable } from './dom';
|
|
8
|
-
import { getTableMaxWidth } from './misc';
|
|
9
|
-
import { MAX_SCALING_PERCENT, TABLE_DEFAULT_WIDTH } from './index';
|
|
8
|
+
import { getTableContainerElementWidth, getTableMaxWidth } from './misc';
|
|
9
|
+
import { COLUMN_MIN_WIDTH, MAX_SCALING_PERCENT, TABLE_DEFAULT_WIDTH } from './index';
|
|
10
10
|
export const getResizeState = ({
|
|
11
11
|
minWidth,
|
|
12
12
|
maxSize,
|
|
@@ -14,7 +14,7 @@ export const getResizeState = ({
|
|
|
14
14
|
tableRef,
|
|
15
15
|
start,
|
|
16
16
|
domAtPos,
|
|
17
|
-
|
|
17
|
+
isTableScalingEnabled = false
|
|
18
18
|
}) => {
|
|
19
19
|
// If the table has been resized, we can use the column widths from the table node
|
|
20
20
|
if (hasTableBeenResized(table)) {
|
|
@@ -34,19 +34,19 @@ export const getResizeState = ({
|
|
|
34
34
|
overflow
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
-
const shouldReinsertColgroup = !
|
|
37
|
+
const shouldReinsertColgroup = !isTableScalingEnabled;
|
|
38
38
|
|
|
39
39
|
// Getting the resize state from DOM
|
|
40
|
-
const colgroupChildren = insertColgroupFromNode(tableRef, table,
|
|
40
|
+
const colgroupChildren = insertColgroupFromNode(tableRef, table, isTableScalingEnabled, shouldReinsertColgroup // don't reinsert colgroup when preserving table width - this causes widths to jump
|
|
41
41
|
);
|
|
42
42
|
const cols = Array.from(colgroupChildren).map((_, index) => {
|
|
43
43
|
// If the table hasn't been resized and we have a table width attribute, we can use it
|
|
44
44
|
// to calculate the widths of the columns
|
|
45
|
-
if (
|
|
45
|
+
if (isTableScalingEnabled && table.attrs.width) {
|
|
46
46
|
return {
|
|
47
47
|
index,
|
|
48
48
|
width: table.attrs.width / colgroupChildren.length,
|
|
49
|
-
minWidth:
|
|
49
|
+
minWidth: COLUMN_MIN_WIDTH
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
const cellsRefs = getCellsRefsInColumn(index, table, start, domAtPos);
|
|
@@ -65,13 +65,12 @@ export const getResizeState = ({
|
|
|
65
65
|
};
|
|
66
66
|
|
|
67
67
|
// updates Colgroup DOM node with new widths
|
|
68
|
-
export const updateColgroup = (state, tableRef,
|
|
68
|
+
export const updateColgroup = (state, tableRef, tableNode, isTableScalingEnabled) => {
|
|
69
69
|
const cols = tableRef.querySelectorAll('col');
|
|
70
70
|
if (getBooleanFF('platform.editor.custom-table-width')) {
|
|
71
71
|
const columnsCount = cols.length;
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
const tableWidth = parseInt(((_tableRef$dataset = tableRef.dataset) === null || _tableRef$dataset === void 0 ? void 0 : _tableRef$dataset.tableWidth) || ''); // TODO - get this value from the table node, not the dom
|
|
72
|
+
if (isTableScalingEnabled && tableNode) {
|
|
73
|
+
const tableWidth = getTableContainerElementWidth(tableNode);
|
|
75
74
|
if (tableWidth) {
|
|
76
75
|
var _tableRef$parentEleme;
|
|
77
76
|
let renderWidth = ((_tableRef$parentEleme = tableRef.parentElement) === null || _tableRef$parentEleme === void 0 ? void 0 : _tableRef$parentEleme.clientWidth) || TABLE_DEFAULT_WIDTH;
|
|
@@ -275,7 +274,7 @@ export const normaliseTableLayout = input => {
|
|
|
275
274
|
return 'default';
|
|
276
275
|
}
|
|
277
276
|
};
|
|
278
|
-
export const getNewResizeStateFromSelectedColumns = (rect, state, domAtPos, getEditorContainerWidth,
|
|
277
|
+
export const getNewResizeStateFromSelectedColumns = (rect, state, domAtPos, getEditorContainerWidth, isTableScalingEnabled = false) => {
|
|
279
278
|
// Fail early so that we don't do complex calculations for no reason
|
|
280
279
|
const numColumnsSelected = rect.right - rect.left;
|
|
281
280
|
if (numColumnsSelected <= 1) {
|
|
@@ -314,7 +313,7 @@ export const getNewResizeStateFromSelectedColumns = (rect, state, domAtPos, getE
|
|
|
314
313
|
tableRef,
|
|
315
314
|
start: table.start,
|
|
316
315
|
domAtPos,
|
|
317
|
-
|
|
316
|
+
isTableScalingEnabled
|
|
318
317
|
});
|
|
319
318
|
const newResizeState = evenSelectedColumnsWidths(resizeState, rect);
|
|
320
319
|
const widthsBefore = resizeState.widths;
|
|
@@ -10,7 +10,7 @@ import { hasTableBeenResized, insertColgroupFromNode } from './colgroup';
|
|
|
10
10
|
import { syncStickyRowToTable } from './dom';
|
|
11
11
|
// Base function to trigger the actual scale on a table node.
|
|
12
12
|
// Will only resize/scale if a table has been previously resized.
|
|
13
|
-
export const scale = (tableRef, options, domAtPos,
|
|
13
|
+
export const scale = (tableRef, options, domAtPos, isTableScalingEnabled = false) => {
|
|
14
14
|
/**
|
|
15
15
|
* isBreakoutEnabled === true -> default center aligned
|
|
16
16
|
* isBreakoutEnabled === false -> full width mode
|
|
@@ -58,11 +58,11 @@ export const scale = (tableRef, options, domAtPos, tablePreserveWidth = false) =
|
|
|
58
58
|
tableRef,
|
|
59
59
|
start,
|
|
60
60
|
domAtPos,
|
|
61
|
-
|
|
61
|
+
isTableScalingEnabled
|
|
62
62
|
});
|
|
63
63
|
return scaleTableTo(resizeState, newWidth);
|
|
64
64
|
};
|
|
65
|
-
export const scaleWithParent = (tableRef, parentWidth, table, start, domAtPos,
|
|
65
|
+
export const scaleWithParent = (tableRef, parentWidth, table, start, domAtPos, isTableScalingEnabled = false) => {
|
|
66
66
|
const resizeState = getResizeState({
|
|
67
67
|
minWidth: tableCellMinWidth,
|
|
68
68
|
maxSize: parentWidth,
|
|
@@ -70,7 +70,7 @@ export const scaleWithParent = (tableRef, parentWidth, table, start, domAtPos, t
|
|
|
70
70
|
tableRef,
|
|
71
71
|
start,
|
|
72
72
|
domAtPos,
|
|
73
|
-
|
|
73
|
+
isTableScalingEnabled
|
|
74
74
|
});
|
|
75
75
|
if (table.attrs.isNumberColumnEnabled) {
|
|
76
76
|
parentWidth -= akEditorTableNumberColumnWidth;
|
|
@@ -105,7 +105,7 @@ export function scaleTableTo(state, maxSize) {
|
|
|
105
105
|
}
|
|
106
106
|
return adjustColumnsWidths(newState, maxSize);
|
|
107
107
|
}
|
|
108
|
-
export const previewScaleTable = (tableRef, options, domAtPos,
|
|
108
|
+
export const previewScaleTable = (tableRef, options, domAtPos, isTableScalingEnabled = false) => {
|
|
109
109
|
const {
|
|
110
110
|
node,
|
|
111
111
|
start,
|
|
@@ -121,19 +121,19 @@ export const previewScaleTable = (tableRef, options, domAtPos, tablePreserveWidt
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
// If the table hasn't been resize, the colgroup 48px width values will gracefully scale down.
|
|
124
|
-
// If we are scaling the table down with
|
|
125
|
-
if (!hasTableBeenResized(node) && !
|
|
124
|
+
// If we are scaling the table down with isTableScalingEnabled, the colgroup widths may be scaled to a value that is not 48px.
|
|
125
|
+
if (!hasTableBeenResized(node) && !isTableScalingEnabled) {
|
|
126
126
|
syncStickyRowToTable(tableRef);
|
|
127
127
|
return;
|
|
128
128
|
}
|
|
129
|
-
const resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos,
|
|
129
|
+
const resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos, isTableScalingEnabled) : scale(tableRef, options, domAtPos, isTableScalingEnabled);
|
|
130
130
|
if (resizeState) {
|
|
131
|
-
updateColgroup(resizeState, tableRef,
|
|
131
|
+
updateColgroup(resizeState, tableRef, node, isTableScalingEnabled);
|
|
132
132
|
}
|
|
133
133
|
};
|
|
134
134
|
|
|
135
135
|
// Scale the table to meet new requirements (col, layout change etc)
|
|
136
|
-
export const scaleTable = (tableRef, options, domAtPos,
|
|
136
|
+
export const scaleTable = (tableRef, options, domAtPos, isTableScalingEnabled = false) => tr => {
|
|
137
137
|
if (!tableRef) {
|
|
138
138
|
return tr;
|
|
139
139
|
}
|
|
@@ -147,7 +147,7 @@ export const scaleTable = (tableRef, options, domAtPos, tablePreserveWidth = fal
|
|
|
147
147
|
if (hasTableBeenResized(node) === false) {
|
|
148
148
|
// If its not a re-sized table, we still want to re-create cols
|
|
149
149
|
// To force reflow of columns upon delete.
|
|
150
|
-
if (!
|
|
150
|
+
if (!isTableScalingEnabled) {
|
|
151
151
|
insertColgroupFromNode(tableRef, node);
|
|
152
152
|
}
|
|
153
153
|
tr.setMeta('scrollIntoView', false);
|
|
@@ -155,9 +155,9 @@ export const scaleTable = (tableRef, options, domAtPos, tablePreserveWidth = fal
|
|
|
155
155
|
}
|
|
156
156
|
let resizeState;
|
|
157
157
|
if (parentWidth) {
|
|
158
|
-
resizeState = scaleWithParent(tableRef, parentWidth, node, start, domAtPos,
|
|
158
|
+
resizeState = scaleWithParent(tableRef, parentWidth, node, start, domAtPos, isTableScalingEnabled);
|
|
159
159
|
} else {
|
|
160
|
-
resizeState = scale(tableRef, options, domAtPos,
|
|
160
|
+
resizeState = scale(tableRef, options, domAtPos, isTableScalingEnabled);
|
|
161
161
|
}
|
|
162
162
|
if (resizeState) {
|
|
163
163
|
tr = updateColumnWidths(resizeState, node, start)(tr);
|
|
@@ -11,9 +11,10 @@ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
|
11
11
|
import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
12
12
|
import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorWideLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
13
13
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
14
|
+
import { getPluginState } from './plugin-factory';
|
|
14
15
|
import { TABLE_MAX_WIDTH } from './table-resizing/utils';
|
|
15
16
|
export const pluginKey = new PluginKey('tableWidthPlugin');
|
|
16
|
-
const createPlugin = (dispatch, dispatchAnalyticsEvent, fullWidthEnabled
|
|
17
|
+
const createPlugin = (dispatch, dispatchAnalyticsEvent, fullWidthEnabled) => {
|
|
17
18
|
return new SafePlugin({
|
|
18
19
|
key: pluginKey,
|
|
19
20
|
state: {
|
|
@@ -78,7 +79,10 @@ const createPlugin = (dispatch, dispatchAnalyticsEvent, fullWidthEnabled, getEdi
|
|
|
78
79
|
return hasStepReplacingEntireDocument;
|
|
79
80
|
});
|
|
80
81
|
const referentialityTr = transactions.find(tr => tr.getMeta('referentialityTableInserted'));
|
|
81
|
-
const
|
|
82
|
+
const {
|
|
83
|
+
isTableScalingEnabled = false
|
|
84
|
+
} = getPluginState(newState);
|
|
85
|
+
const shouldPatchTable = fullWidthEnabled && isTableScalingEnabled;
|
|
82
86
|
if (!isReplaceDocumentOperation && (!shouldPatchTable || !referentialityTr)) {
|
|
83
87
|
return null;
|
|
84
88
|
}
|