@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/src/nodeviews/table.tsx
CHANGED
|
@@ -102,7 +102,7 @@ export default class TableView extends ReactNodeView<Props> {
|
|
|
102
102
|
private resizeObserver?: ResizeObserver;
|
|
103
103
|
eventDispatcher?: EventDispatcher;
|
|
104
104
|
getPos: getPosHandlerNode;
|
|
105
|
-
|
|
105
|
+
options;
|
|
106
106
|
|
|
107
107
|
constructor(props: Props) {
|
|
108
108
|
super(
|
|
@@ -119,7 +119,7 @@ export default class TableView extends ReactNodeView<Props> {
|
|
|
119
119
|
);
|
|
120
120
|
this.getPos = props.getPos;
|
|
121
121
|
this.eventDispatcher = props.eventDispatcher;
|
|
122
|
-
this.
|
|
122
|
+
this.options = props.options;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
getContentDOM() {
|
|
@@ -133,9 +133,8 @@ export default class TableView extends ReactNodeView<Props> {
|
|
|
133
133
|
|
|
134
134
|
if (rendered.dom) {
|
|
135
135
|
this.table = rendered.dom;
|
|
136
|
-
const { tablePreserveWidth = false } = this.getEditorFeatureFlags();
|
|
137
136
|
// Preserve Table Width cannot have inline width set on the table
|
|
138
|
-
if (!
|
|
137
|
+
if (!this.options?.isTableScalingEnabled) {
|
|
139
138
|
const tableInlineWidth = getInlineWidth(
|
|
140
139
|
this.node,
|
|
141
140
|
this.reactComponentProps.options,
|
|
@@ -255,6 +254,7 @@ export default class TableView extends ReactNodeView<Props> {
|
|
|
255
254
|
isHeaderRowEnabled={pluginState!.isHeaderRowEnabled}
|
|
256
255
|
isHeaderColumnEnabled={pluginState!.isHeaderColumnEnabled}
|
|
257
256
|
isDragAndDropEnabled={pluginState!.isDragAndDropEnabled}
|
|
257
|
+
isTableScalingEnabled={pluginState!.isTableScalingEnabled}
|
|
258
258
|
tableActive={tableActive}
|
|
259
259
|
ordering={pluginState!.ordering as TableColumnOrdering}
|
|
260
260
|
isResizing={isResizing}
|
|
@@ -264,7 +264,6 @@ export default class TableView extends ReactNodeView<Props> {
|
|
|
264
264
|
getEditorFeatureFlags={props.getEditorFeatureFlags}
|
|
265
265
|
dispatchAnalyticsEvent={props.dispatchAnalyticsEvent}
|
|
266
266
|
pluginInjectionApi={props.pluginInjectionApi}
|
|
267
|
-
tableRef={this.table}
|
|
268
267
|
/>
|
|
269
268
|
);
|
|
270
269
|
}}
|
|
@@ -362,6 +361,7 @@ export const createTableView = (
|
|
|
362
361
|
wasFullWidthModeEnabled,
|
|
363
362
|
isTableResizingEnabled,
|
|
364
363
|
isDragAndDropEnabled,
|
|
364
|
+
isTableScalingEnabled,
|
|
365
365
|
} = getPluginState(view.state);
|
|
366
366
|
const { allowColumnResizing } = getPluginConfig(pluginConfig);
|
|
367
367
|
const hasIntlContext = true;
|
|
@@ -379,6 +379,7 @@ export const createTableView = (
|
|
|
379
379
|
wasFullWidthModeEnabled,
|
|
380
380
|
isTableResizingEnabled,
|
|
381
381
|
isDragAndDropEnabled,
|
|
382
|
+
isTableScalingEnabled,
|
|
382
383
|
},
|
|
383
384
|
getEditorContainerWidth,
|
|
384
385
|
getEditorFeatureFlags,
|
package/src/nodeviews/types.ts
CHANGED
package/src/plugin.tsx
CHANGED
|
@@ -52,6 +52,7 @@ import {
|
|
|
52
52
|
} from './pm-plugins/drag-and-drop';
|
|
53
53
|
import { keymapPlugin } from './pm-plugins/keymap';
|
|
54
54
|
import { createPlugin } from './pm-plugins/main';
|
|
55
|
+
import { getPluginState } from './pm-plugins/plugin-factory';
|
|
55
56
|
import { pluginKey } from './pm-plugins/plugin-key';
|
|
56
57
|
import { createPlugin as createTableSafariDeleteCompositionTextIssueWorkaroundPlugin } from './pm-plugins/safari-delete-composition-text-issue-workaround';
|
|
57
58
|
import {
|
|
@@ -92,6 +93,7 @@ export interface TablePluginOptions {
|
|
|
92
93
|
fullWidthEnabled?: boolean;
|
|
93
94
|
wasFullWidthEnabled?: boolean;
|
|
94
95
|
getEditorFeatureFlags?: GetEditorFeatureFlags;
|
|
96
|
+
isTableScalingEnabled?: boolean;
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
type InsertTableAction = (analyticsPayload: AnalyticsEventPayload) => Command;
|
|
@@ -133,10 +135,11 @@ export type TablePlugin = NextEditorPlugin<
|
|
|
133
135
|
const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
134
136
|
const editorViewRef: Record<'current', EditorView | null> = { current: null };
|
|
135
137
|
const defaultGetEditorContainerWidth: GetEditorContainerWidth = () => {
|
|
136
|
-
|
|
137
|
-
width
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
return (
|
|
139
|
+
api?.width?.sharedState.currentState() ?? {
|
|
140
|
+
width: document?.body?.offsetWidth ?? 500,
|
|
141
|
+
}
|
|
142
|
+
);
|
|
140
143
|
};
|
|
141
144
|
const editorAnalyticsAPI = api?.analytics?.actions;
|
|
142
145
|
|
|
@@ -157,8 +160,8 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
157
160
|
(analyticsPayload): Command =>
|
|
158
161
|
(state, dispatch) => {
|
|
159
162
|
const node = createTableWithWidth(
|
|
163
|
+
options?.isTableScalingEnabled,
|
|
160
164
|
options?.fullWidthEnabled,
|
|
161
|
-
options?.getEditorFeatureFlags,
|
|
162
165
|
)(state.schema);
|
|
163
166
|
|
|
164
167
|
return (
|
|
@@ -179,7 +182,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
179
182
|
commands: {
|
|
180
183
|
insertTableWithSize: insertTableWithSize(
|
|
181
184
|
options?.fullWidthEnabled,
|
|
182
|
-
options?.
|
|
185
|
+
options?.isTableScalingEnabled,
|
|
183
186
|
api?.analytics?.actions,
|
|
184
187
|
),
|
|
185
188
|
},
|
|
@@ -216,6 +219,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
216
219
|
tableOptions,
|
|
217
220
|
getEditorFeatureFlags,
|
|
218
221
|
dragAndDropEnabled,
|
|
222
|
+
isTableScalingEnabled,
|
|
219
223
|
} = options || ({} as TablePluginOptions);
|
|
220
224
|
return createPlugin(
|
|
221
225
|
dispatchAnalyticsEvent,
|
|
@@ -233,6 +237,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
233
237
|
dragAndDropEnabled,
|
|
234
238
|
editorAnalyticsAPI,
|
|
235
239
|
api,
|
|
240
|
+
isTableScalingEnabled,
|
|
236
241
|
);
|
|
237
242
|
},
|
|
238
243
|
},
|
|
@@ -261,14 +266,14 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
261
266
|
{
|
|
262
267
|
name: 'tableKeymap',
|
|
263
268
|
plugin: () => {
|
|
264
|
-
const { dragAndDropEnabled,
|
|
269
|
+
const { dragAndDropEnabled, isTableScalingEnabled = false } =
|
|
265
270
|
options || ({} as TablePluginOptions);
|
|
266
271
|
|
|
267
272
|
return keymapPlugin(
|
|
268
273
|
defaultGetEditorContainerWidth,
|
|
269
274
|
editorAnalyticsAPI,
|
|
270
|
-
getEditorFeatureFlags,
|
|
271
275
|
dragAndDropEnabled,
|
|
276
|
+
isTableScalingEnabled,
|
|
272
277
|
);
|
|
273
278
|
},
|
|
274
279
|
},
|
|
@@ -308,26 +313,14 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
308
313
|
name: 'tableStickyHeaders',
|
|
309
314
|
plugin: ({ dispatch, eventDispatcher }) =>
|
|
310
315
|
options && options.tableOptions.stickyHeaders
|
|
311
|
-
? createStickyHeadersPlugin(
|
|
312
|
-
dispatch,
|
|
313
|
-
eventDispatcher,
|
|
314
|
-
() => [],
|
|
315
|
-
options?.getEditorFeatureFlags ||
|
|
316
|
-
defaultGetEditorFeatureFlags,
|
|
317
|
-
)
|
|
316
|
+
? createStickyHeadersPlugin(dispatch, () => [])
|
|
318
317
|
: undefined,
|
|
319
318
|
},
|
|
320
319
|
{
|
|
321
320
|
name: 'tableDragAndDrop',
|
|
322
321
|
plugin: ({ dispatch }) => {
|
|
323
|
-
const { getEditorFeatureFlags } =
|
|
324
|
-
options || ({} as TablePluginOptions);
|
|
325
322
|
return options?.dragAndDropEnabled
|
|
326
|
-
? createDragAndDropPlugin(
|
|
327
|
-
dispatch,
|
|
328
|
-
getEditorFeatureFlags,
|
|
329
|
-
editorAnalyticsAPI,
|
|
330
|
-
)
|
|
323
|
+
? createDragAndDropPlugin(dispatch, editorAnalyticsAPI)
|
|
331
324
|
: undefined;
|
|
332
325
|
},
|
|
333
326
|
},
|
|
@@ -343,7 +336,6 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
343
336
|
dispatch,
|
|
344
337
|
dispatchAnalyticsEvent,
|
|
345
338
|
options?.fullWidthEnabled ?? false,
|
|
346
|
-
options?.getEditorFeatureFlags,
|
|
347
339
|
)
|
|
348
340
|
: undefined,
|
|
349
341
|
},
|
|
@@ -511,10 +503,6 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
511
503
|
dispatchAnalyticsEvent={dispatchAnalyticsEvent}
|
|
512
504
|
editorAnalyticsAPI={editorAnalyticsAPI}
|
|
513
505
|
getEditorContainerWidth={defaultGetEditorContainerWidth}
|
|
514
|
-
getEditorFeatureFlags={
|
|
515
|
-
options?.getEditorFeatureFlags ||
|
|
516
|
-
defaultGetEditorFeatureFlags
|
|
517
|
-
}
|
|
518
506
|
/>
|
|
519
507
|
)}
|
|
520
508
|
{options?.allowContextualMenu && (
|
|
@@ -548,10 +536,6 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
548
536
|
editorAnalyticsAPI={editorAnalyticsAPI}
|
|
549
537
|
stickyHeaders={stickyHeader}
|
|
550
538
|
pluginConfig={pluginConfig}
|
|
551
|
-
getEditorFeatureFlags={
|
|
552
|
-
options?.getEditorFeatureFlags ||
|
|
553
|
-
defaultGetEditorFeatureFlags
|
|
554
|
-
}
|
|
555
539
|
/>
|
|
556
540
|
)}
|
|
557
541
|
{allowControls && !isDragAndDropEnabled && !isResizing && (
|
|
@@ -591,11 +575,12 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
591
575
|
action(insert, state) {
|
|
592
576
|
// see comment on tablesPlugin.getSharedState on usage
|
|
593
577
|
const tableState = api?.table?.sharedState.currentState();
|
|
578
|
+
const { isTableScalingEnabled = false } = getPluginState(state);
|
|
594
579
|
|
|
595
580
|
const tr = insert(
|
|
596
581
|
createTableWithWidth(
|
|
582
|
+
isTableScalingEnabled,
|
|
597
583
|
tableState?.isFullWidthModeEnabled,
|
|
598
|
-
options?.getEditorFeatureFlags,
|
|
599
584
|
)(state.schema),
|
|
600
585
|
);
|
|
601
586
|
editorAnalyticsAPI?.attachAnalyticsEvent({
|
|
@@ -2,7 +2,6 @@ import { INPUT_METHOD, TABLE_STATUS } from '@atlaskit/editor-common/analytics';
|
|
|
2
2
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
4
4
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
|
-
import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
6
5
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
7
6
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
8
7
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
@@ -34,11 +33,7 @@ import { createPluginState, getPluginState } from './plugin-factory';
|
|
|
34
33
|
import { pluginKey } from './plugin-key';
|
|
35
34
|
import { getDraggableDataFromEvent } from './utils/monitor';
|
|
36
35
|
|
|
37
|
-
const destroyFn = (
|
|
38
|
-
editorView: EditorView,
|
|
39
|
-
editorAnalyticsAPI: any,
|
|
40
|
-
getEditorFeatureFlags?: GetEditorFeatureFlags,
|
|
41
|
-
) => {
|
|
36
|
+
const destroyFn = (editorView: EditorView, editorAnalyticsAPI: any) => {
|
|
42
37
|
const editorPageScrollContainer = document.querySelector(
|
|
43
38
|
'.fabric-editor-popup-scroll-parent',
|
|
44
39
|
);
|
|
@@ -223,9 +218,14 @@ const destroyFn = (
|
|
|
223
218
|
editorView.state,
|
|
224
219
|
);
|
|
225
220
|
if (tableRef && tableNode) {
|
|
226
|
-
const {
|
|
227
|
-
|
|
228
|
-
|
|
221
|
+
const { isTableScalingEnabled = false } = getTablePluginState(
|
|
222
|
+
editorView.state,
|
|
223
|
+
);
|
|
224
|
+
insertColgroupFromNode(
|
|
225
|
+
tableRef,
|
|
226
|
+
tableNode,
|
|
227
|
+
isTableScalingEnabled,
|
|
228
|
+
);
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
|
|
@@ -238,7 +238,6 @@ const destroyFn = (
|
|
|
238
238
|
|
|
239
239
|
export const createPlugin = (
|
|
240
240
|
dispatch: Dispatch,
|
|
241
|
-
getEditorFeatureFlags?: GetEditorFeatureFlags,
|
|
242
241
|
editorAnalyticsAPI?: EditorAnalyticsAPI,
|
|
243
242
|
) => {
|
|
244
243
|
return new SafePlugin({
|
|
@@ -311,11 +310,7 @@ export const createPlugin = (
|
|
|
311
310
|
},
|
|
312
311
|
view: (editorView: EditorView) => {
|
|
313
312
|
return {
|
|
314
|
-
destroy: destroyFn(
|
|
315
|
-
editorView,
|
|
316
|
-
editorAnalyticsAPI,
|
|
317
|
-
getEditorFeatureFlags,
|
|
318
|
-
),
|
|
313
|
+
destroy: destroyFn(editorView, editorAnalyticsAPI),
|
|
319
314
|
};
|
|
320
315
|
},
|
|
321
316
|
props: {
|
package/src/pm-plugins/keymap.ts
CHANGED
|
@@ -30,10 +30,7 @@ import {
|
|
|
30
30
|
toggleTable,
|
|
31
31
|
} from '@atlaskit/editor-common/keymaps';
|
|
32
32
|
import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
33
|
-
import type {
|
|
34
|
-
GetEditorContainerWidth,
|
|
35
|
-
GetEditorFeatureFlags,
|
|
36
|
-
} from '@atlaskit/editor-common/types';
|
|
33
|
+
import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
37
34
|
import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
|
|
38
35
|
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
39
36
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
@@ -72,8 +69,8 @@ const createTableWithAnalytics = (
|
|
|
72
69
|
export function keymapPlugin(
|
|
73
70
|
getEditorContainerWidth: GetEditorContainerWidth,
|
|
74
71
|
editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
|
|
75
|
-
getEditorFeatureFlags?: GetEditorFeatureFlags,
|
|
76
72
|
dragAndDropEnabled?: boolean,
|
|
73
|
+
isTableScalingEnabled = false,
|
|
77
74
|
): SafePlugin {
|
|
78
75
|
const list = {};
|
|
79
76
|
|
|
@@ -121,13 +118,13 @@ export function keymapPlugin(
|
|
|
121
118
|
|
|
122
119
|
bindKeymapWithCommand(
|
|
123
120
|
addColumnBefore.common!,
|
|
124
|
-
addColumnBeforeCommand(
|
|
121
|
+
addColumnBeforeCommand(isTableScalingEnabled),
|
|
125
122
|
list,
|
|
126
123
|
);
|
|
127
124
|
|
|
128
125
|
bindKeymapWithCommand(
|
|
129
126
|
addColumnAfter.common!,
|
|
130
|
-
addColumnAfterCommand(
|
|
127
|
+
addColumnAfterCommand(isTableScalingEnabled),
|
|
131
128
|
list,
|
|
132
129
|
);
|
|
133
130
|
|
|
@@ -182,10 +179,6 @@ export function keymapPlugin(
|
|
|
182
179
|
}
|
|
183
180
|
|
|
184
181
|
if (getBooleanFF('platform.editor.a11y-column-resizing_emcvz')) {
|
|
185
|
-
const { tablePreserveWidth = false } = getEditorFeatureFlags
|
|
186
|
-
? getEditorFeatureFlags()
|
|
187
|
-
: {};
|
|
188
|
-
|
|
189
182
|
bindKeymapWithCommand(
|
|
190
183
|
startColumnResizing.common!,
|
|
191
184
|
initiateKeyboardColumnResizing,
|
|
@@ -201,7 +194,7 @@ export function keymapPlugin(
|
|
|
201
194
|
changeColumnWidthByStepWithAnalytics(editorAnalyticsAPI)(
|
|
202
195
|
-10,
|
|
203
196
|
getEditorContainerWidth,
|
|
204
|
-
|
|
197
|
+
isTableScalingEnabled,
|
|
205
198
|
INPUT_METHOD.SHORTCUT,
|
|
206
199
|
),
|
|
207
200
|
list,
|
|
@@ -212,7 +205,7 @@ export function keymapPlugin(
|
|
|
212
205
|
changeColumnWidthByStepWithAnalytics(editorAnalyticsAPI)(
|
|
213
206
|
10,
|
|
214
207
|
getEditorContainerWidth,
|
|
215
|
-
|
|
208
|
+
isTableScalingEnabled,
|
|
216
209
|
INPUT_METHOD.SHORTCUT,
|
|
217
210
|
),
|
|
218
211
|
list,
|
package/src/pm-plugins/main.ts
CHANGED
|
@@ -77,7 +77,6 @@ import TableRow from '../nodeviews/TableRow';
|
|
|
77
77
|
import { pluginKey as decorationsPluginKey } from '../pm-plugins/decorations/plugin';
|
|
78
78
|
import { fixTables, replaceSelectedTable } from '../transforms';
|
|
79
79
|
import type {
|
|
80
|
-
ElementContentRects,
|
|
81
80
|
InvalidNodeAttr,
|
|
82
81
|
PluginConfig,
|
|
83
82
|
PluginInjectionAPI,
|
|
@@ -114,6 +113,7 @@ export const createPlugin = (
|
|
|
114
113
|
dragAndDropEnabled?: boolean,
|
|
115
114
|
editorAnalyticsAPI?: EditorAnalyticsAPI,
|
|
116
115
|
pluginInjectionApi?: PluginInjectionAPI,
|
|
116
|
+
isTableScalingEnabled?: boolean,
|
|
117
117
|
) => {
|
|
118
118
|
const state = createPluginState(dispatch, {
|
|
119
119
|
pluginConfig,
|
|
@@ -127,24 +127,12 @@ export const createPlugin = (
|
|
|
127
127
|
isHeaderRowEnabled: !!pluginConfig.allowHeaderRow,
|
|
128
128
|
isHeaderColumnEnabled: false,
|
|
129
129
|
isDragAndDropEnabled: dragAndDropEnabled,
|
|
130
|
+
isTableScalingEnabled: isTableScalingEnabled,
|
|
130
131
|
...defaultHoveredCell,
|
|
131
132
|
...defaultTableSelection,
|
|
132
133
|
getIntl,
|
|
133
134
|
});
|
|
134
135
|
|
|
135
|
-
let elementContentRects: ElementContentRects = {};
|
|
136
|
-
|
|
137
|
-
const observer = window?.ResizeObserver
|
|
138
|
-
? new ResizeObserver((entries) => {
|
|
139
|
-
entries.forEach((entry) => {
|
|
140
|
-
if (!entry.target.id) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
elementContentRects[entry.target.id] = entry.contentRect;
|
|
144
|
-
});
|
|
145
|
-
})
|
|
146
|
-
: undefined;
|
|
147
|
-
|
|
148
136
|
// Used to prevent invalid table cell spans being reported more than once per editor/document
|
|
149
137
|
const invalidTableIds: string[] = [];
|
|
150
138
|
let editorViewRef: EditorView | null = null;
|
|
@@ -188,8 +176,6 @@ export const createPlugin = (
|
|
|
188
176
|
});
|
|
189
177
|
}
|
|
190
178
|
|
|
191
|
-
const { tablePreserveWidth = false } = getEditorFeatureFlags();
|
|
192
|
-
|
|
193
179
|
if (tr) {
|
|
194
180
|
// "fixTables" removes empty rows as we don't allow that in schema
|
|
195
181
|
const updatedTr = handleCut(
|
|
@@ -198,7 +184,7 @@ export const createPlugin = (
|
|
|
198
184
|
newState,
|
|
199
185
|
editorAnalyticsAPI,
|
|
200
186
|
editorViewRef || undefined,
|
|
201
|
-
|
|
187
|
+
isTableScalingEnabled,
|
|
202
188
|
);
|
|
203
189
|
return fixTables(updatedTr) || updatedTr;
|
|
204
190
|
}
|
|
@@ -282,11 +268,6 @@ export const createPlugin = (
|
|
|
282
268
|
removeResizeHandleDecorations()(state, dispatch);
|
|
283
269
|
}
|
|
284
270
|
},
|
|
285
|
-
destroy: () => {
|
|
286
|
-
if (observer) {
|
|
287
|
-
observer.disconnect();
|
|
288
|
-
}
|
|
289
|
-
},
|
|
290
271
|
};
|
|
291
272
|
},
|
|
292
273
|
props: {
|
|
@@ -417,9 +398,9 @@ export const createPlugin = (
|
|
|
417
398
|
tableRow: (node, view, getPos) =>
|
|
418
399
|
new TableRow(node, view, getPos, eventDispatcher),
|
|
419
400
|
tableCell: (node, view, getPos) =>
|
|
420
|
-
new TableCell(node, view, getPos, eventDispatcher
|
|
401
|
+
new TableCell(node, view, getPos, eventDispatcher),
|
|
421
402
|
tableHeader: (node, view, getPos) =>
|
|
422
|
-
new TableCell(node, view, getPos, eventDispatcher
|
|
403
|
+
new TableCell(node, view, getPos, eventDispatcher),
|
|
423
404
|
},
|
|
424
405
|
handleDOMEvents: {
|
|
425
406
|
focus: handleFocus,
|
|
@@ -428,7 +409,7 @@ export const createPlugin = (
|
|
|
428
409
|
mouseover: withCellTracking(whenTableInFocus(handleMouseOver)),
|
|
429
410
|
mouseleave: handleMouseLeave,
|
|
430
411
|
mouseout: whenTableInFocus(handleMouseOut),
|
|
431
|
-
mousemove: whenTableInFocus(handleMouseMove
|
|
412
|
+
mousemove: whenTableInFocus(handleMouseMove),
|
|
432
413
|
mouseenter: handleMouseEnter,
|
|
433
414
|
mouseup: whenTableInFocus(handleMouseUp),
|
|
434
415
|
click: withCellTracking(whenTableInFocus(handleClick)),
|
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Dispatch,
|
|
3
|
-
EventDispatcher,
|
|
4
|
-
} from '@atlaskit/editor-common/event-dispatcher';
|
|
1
|
+
import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
5
2
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
6
|
-
import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
7
3
|
|
|
8
4
|
import { pluginKey } from './plugin-key';
|
|
9
5
|
import { createPluginState } from './plugin-state';
|
|
10
6
|
|
|
11
|
-
export const createPlugin = (
|
|
12
|
-
dispatch: Dispatch,
|
|
13
|
-
eventDispatcher: EventDispatcher,
|
|
14
|
-
initialState = () => [],
|
|
15
|
-
getEditorFeatureFlags: GetEditorFeatureFlags,
|
|
16
|
-
) => {
|
|
7
|
+
export const createPlugin = (dispatch: Dispatch, initialState = () => []) => {
|
|
17
8
|
return new SafePlugin({
|
|
18
9
|
state: createPluginState(dispatch, initialState),
|
|
19
10
|
key: pluginKey,
|
|
@@ -49,7 +49,7 @@ export const handleMouseDown = (
|
|
|
49
49
|
const { state, dispatch } = view;
|
|
50
50
|
const editorDisabled = !view.editable;
|
|
51
51
|
const domAtPos = view.domAtPos.bind(view);
|
|
52
|
-
const {
|
|
52
|
+
const { isTableScalingEnabled = false } = getTablePluginState(state);
|
|
53
53
|
|
|
54
54
|
if (
|
|
55
55
|
editorDisabled ||
|
|
@@ -119,7 +119,7 @@ export const handleMouseDown = (
|
|
|
119
119
|
tableRef: dom,
|
|
120
120
|
start,
|
|
121
121
|
domAtPos,
|
|
122
|
-
|
|
122
|
+
isTableScalingEnabled: isTableScalingEnabled,
|
|
123
123
|
});
|
|
124
124
|
|
|
125
125
|
if (
|
|
@@ -209,8 +209,9 @@ export const handleMouseDown = (
|
|
|
209
209
|
colIndex,
|
|
210
210
|
clientX - startX,
|
|
211
211
|
dom,
|
|
212
|
+
originalTable,
|
|
212
213
|
resizingSelectedColumns ? selectedColumns : undefined,
|
|
213
|
-
|
|
214
|
+
isTableScalingEnabled,
|
|
214
215
|
);
|
|
215
216
|
|
|
216
217
|
const resizedDelta = clientX - startX;
|
|
@@ -292,8 +293,9 @@ export const handleMouseDown = (
|
|
|
292
293
|
colIndex,
|
|
293
294
|
clientX - dragging.startX,
|
|
294
295
|
dom,
|
|
296
|
+
table,
|
|
295
297
|
undefined,
|
|
296
|
-
|
|
298
|
+
isTableScalingEnabled,
|
|
297
299
|
);
|
|
298
300
|
|
|
299
301
|
updateControls()(state);
|
|
@@ -95,7 +95,7 @@ export const generateColgroup = (table: PmNode, tableRef?: HTMLElement) => {
|
|
|
95
95
|
export const insertColgroupFromNode = (
|
|
96
96
|
tableRef: HTMLTableElement,
|
|
97
97
|
table: PmNode,
|
|
98
|
-
|
|
98
|
+
isTableScalingEnabled = false,
|
|
99
99
|
shouldRemove = true,
|
|
100
100
|
): HTMLCollection => {
|
|
101
101
|
let colgroup = tableRef.querySelector('colgroup') as HTMLElement;
|
|
@@ -105,7 +105,7 @@ export const insertColgroupFromNode = (
|
|
|
105
105
|
|
|
106
106
|
colgroup = renderColgroupFromNode(
|
|
107
107
|
table,
|
|
108
|
-
|
|
108
|
+
isTableScalingEnabled ? tableRef : undefined,
|
|
109
109
|
);
|
|
110
110
|
if (shouldRemove) {
|
|
111
111
|
tableRef.insertBefore(colgroup, tableRef.firstChild);
|
|
@@ -150,9 +150,9 @@ export const getTableElementWidth = (table: PMNode) => {
|
|
|
150
150
|
return calcTableColumnWidths(table).reduce((sum, width) => sum + width, 0);
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
return
|
|
153
|
+
return getTableContainerElementWidth(table);
|
|
154
154
|
};
|
|
155
155
|
|
|
156
|
-
export const
|
|
156
|
+
export const getTableContainerElementWidth = (table: PMNode) => {
|
|
157
157
|
return getTableContainerWidth(table);
|
|
158
158
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// Resize a given column by an amount from the current state
|
|
2
|
+
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
|
|
2
4
|
import { growColumn, shrinkColumn } from './resize-logic';
|
|
3
5
|
import { updateColgroup } from './resize-state';
|
|
4
6
|
import type { ResizeState } from './types';
|
|
@@ -8,8 +10,9 @@ export const resizeColumn = (
|
|
|
8
10
|
colIndex: number,
|
|
9
11
|
amount: number,
|
|
10
12
|
tableRef: HTMLElement,
|
|
13
|
+
tableNode: PmNode,
|
|
11
14
|
selectedColumns?: number[],
|
|
12
|
-
|
|
15
|
+
isTableScalingEnabled = false,
|
|
13
16
|
): ResizeState => {
|
|
14
17
|
const newState =
|
|
15
18
|
amount > 0
|
|
@@ -18,7 +21,7 @@ export const resizeColumn = (
|
|
|
18
21
|
? shrinkColumn(resizeState, colIndex, amount, selectedColumns)
|
|
19
22
|
: resizeState;
|
|
20
23
|
|
|
21
|
-
updateColgroup(newState, tableRef,
|
|
24
|
+
updateColgroup(newState, tableRef, tableNode, isTableScalingEnabled);
|
|
22
25
|
|
|
23
26
|
return newState;
|
|
24
27
|
};
|
|
@@ -20,10 +20,14 @@ import {
|
|
|
20
20
|
import type { ColumnState } from './column-state';
|
|
21
21
|
import { getCellsRefsInColumn, getColumnStateFromDOM } from './column-state';
|
|
22
22
|
import { syncStickyRowToTable } from './dom';
|
|
23
|
-
import { getTableMaxWidth } from './misc';
|
|
23
|
+
import { getTableContainerElementWidth, getTableMaxWidth } from './misc';
|
|
24
24
|
import type { ResizeState, ResizeStateWithAnalytics } from './types';
|
|
25
25
|
|
|
26
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
COLUMN_MIN_WIDTH,
|
|
28
|
+
MAX_SCALING_PERCENT,
|
|
29
|
+
TABLE_DEFAULT_WIDTH,
|
|
30
|
+
} from './index';
|
|
27
31
|
|
|
28
32
|
export const getResizeState = ({
|
|
29
33
|
minWidth,
|
|
@@ -32,7 +36,7 @@ export const getResizeState = ({
|
|
|
32
36
|
tableRef,
|
|
33
37
|
start,
|
|
34
38
|
domAtPos,
|
|
35
|
-
|
|
39
|
+
isTableScalingEnabled = false,
|
|
36
40
|
}: {
|
|
37
41
|
minWidth: number;
|
|
38
42
|
maxSize: number;
|
|
@@ -40,7 +44,7 @@ export const getResizeState = ({
|
|
|
40
44
|
tableRef: HTMLTableElement;
|
|
41
45
|
start: number;
|
|
42
46
|
domAtPos: (pos: number) => { node: Node; offset: number };
|
|
43
|
-
|
|
47
|
+
isTableScalingEnabled: boolean;
|
|
44
48
|
}): ResizeState => {
|
|
45
49
|
// If the table has been resized, we can use the column widths from the table node
|
|
46
50
|
if (hasTableBeenResized(table)) {
|
|
@@ -63,23 +67,23 @@ export const getResizeState = ({
|
|
|
63
67
|
};
|
|
64
68
|
}
|
|
65
69
|
|
|
66
|
-
const shouldReinsertColgroup = !
|
|
70
|
+
const shouldReinsertColgroup = !isTableScalingEnabled;
|
|
67
71
|
|
|
68
72
|
// Getting the resize state from DOM
|
|
69
73
|
const colgroupChildren = insertColgroupFromNode(
|
|
70
74
|
tableRef,
|
|
71
75
|
table,
|
|
72
|
-
|
|
76
|
+
isTableScalingEnabled,
|
|
73
77
|
shouldReinsertColgroup, // don't reinsert colgroup when preserving table width - this causes widths to jump
|
|
74
78
|
);
|
|
75
79
|
const cols = Array.from(colgroupChildren).map((_, index) => {
|
|
76
80
|
// If the table hasn't been resized and we have a table width attribute, we can use it
|
|
77
81
|
// to calculate the widths of the columns
|
|
78
|
-
if (
|
|
82
|
+
if (isTableScalingEnabled && table.attrs.width) {
|
|
79
83
|
return {
|
|
80
84
|
index,
|
|
81
85
|
width: table.attrs.width / colgroupChildren.length,
|
|
82
|
-
minWidth:
|
|
86
|
+
minWidth: COLUMN_MIN_WIDTH,
|
|
83
87
|
};
|
|
84
88
|
}
|
|
85
89
|
const cellsRefs = getCellsRefsInColumn(index, table, start, domAtPos);
|
|
@@ -104,14 +108,15 @@ export const getResizeState = ({
|
|
|
104
108
|
export const updateColgroup = (
|
|
105
109
|
state: ResizeState,
|
|
106
110
|
tableRef: HTMLElement,
|
|
107
|
-
|
|
111
|
+
tableNode?: PMNode,
|
|
112
|
+
isTableScalingEnabled?: boolean,
|
|
108
113
|
): void => {
|
|
109
114
|
const cols = tableRef.querySelectorAll('col');
|
|
110
115
|
|
|
111
116
|
if (getBooleanFF('platform.editor.custom-table-width')) {
|
|
112
117
|
const columnsCount = cols.length;
|
|
113
|
-
if (
|
|
114
|
-
const tableWidth =
|
|
118
|
+
if (isTableScalingEnabled && tableNode) {
|
|
119
|
+
const tableWidth = getTableContainerElementWidth(tableNode);
|
|
115
120
|
if (tableWidth) {
|
|
116
121
|
let renderWidth =
|
|
117
122
|
tableRef.parentElement?.clientWidth || TABLE_DEFAULT_WIDTH;
|
|
@@ -349,7 +354,7 @@ export const getNewResizeStateFromSelectedColumns = (
|
|
|
349
354
|
state: EditorState,
|
|
350
355
|
domAtPos: (pos: number) => { node: Node; offset: number },
|
|
351
356
|
getEditorContainerWidth: GetEditorContainerWidth,
|
|
352
|
-
|
|
357
|
+
isTableScalingEnabled = false,
|
|
353
358
|
): ResizeStateWithAnalytics | undefined => {
|
|
354
359
|
// Fail early so that we don't do complex calculations for no reason
|
|
355
360
|
const numColumnsSelected = rect.right - rect.left;
|
|
@@ -394,7 +399,7 @@ export const getNewResizeStateFromSelectedColumns = (
|
|
|
394
399
|
tableRef,
|
|
395
400
|
start: table.start,
|
|
396
401
|
domAtPos,
|
|
397
|
-
|
|
402
|
+
isTableScalingEnabled,
|
|
398
403
|
});
|
|
399
404
|
|
|
400
405
|
const newResizeState = evenSelectedColumnsWidths(resizeState, rect);
|