@atlaskit/editor-plugin-table 7.31.3 → 8.1.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 +96 -0
- package/dist/cjs/commands/column-resize.js +3 -2
- package/dist/cjs/commands/hover.js +5 -3
- package/dist/cjs/event-handlers.js +12 -1
- package/dist/cjs/nodeviews/TableComponent.js +18 -15
- package/dist/cjs/nodeviews/TableComponentWithSharedState.js +5 -2
- package/dist/cjs/nodeviews/lazy-node-views.js +2 -3
- package/dist/cjs/nodeviews/table.js +16 -12
- package/dist/cjs/plugin.js +21 -26
- package/dist/cjs/pm-plugins/main.js +3 -5
- package/dist/cjs/toolbar.js +1 -1
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/ui/common-styles.js +2 -2
- package/dist/cjs/ui/ui-styles.js +6 -9
- package/dist/cjs/utils/decoration.js +2 -2
- package/dist/es2019/commands/column-resize.js +3 -2
- package/dist/es2019/commands/hover.js +11 -6
- package/dist/es2019/event-handlers.js +12 -1
- package/dist/es2019/nodeviews/TableComponent.js +18 -15
- package/dist/es2019/nodeviews/TableComponentWithSharedState.js +5 -2
- package/dist/es2019/nodeviews/lazy-node-views.js +2 -3
- package/dist/es2019/nodeviews/table.js +16 -12
- package/dist/es2019/plugin.js +21 -24
- package/dist/es2019/pm-plugins/main.js +3 -5
- package/dist/es2019/toolbar.js +1 -1
- package/dist/es2019/types.js +2 -0
- package/dist/es2019/ui/common-styles.js +4 -4
- package/dist/es2019/ui/ui-styles.js +36 -29
- package/dist/es2019/utils/decoration.js +2 -2
- package/dist/esm/commands/column-resize.js +3 -2
- package/dist/esm/commands/hover.js +5 -3
- package/dist/esm/event-handlers.js +12 -1
- package/dist/esm/nodeviews/TableComponent.js +18 -15
- package/dist/esm/nodeviews/TableComponentWithSharedState.js +5 -2
- package/dist/esm/nodeviews/lazy-node-views.js +2 -3
- package/dist/esm/nodeviews/table.js +16 -12
- package/dist/esm/plugin.js +21 -26
- package/dist/esm/pm-plugins/main.js +3 -5
- package/dist/esm/toolbar.js +1 -1
- package/dist/esm/types.js +2 -0
- package/dist/esm/ui/common-styles.js +2 -2
- package/dist/esm/ui/ui-styles.js +6 -9
- package/dist/esm/utils/decoration.js +2 -2
- package/dist/types/event-handlers.d.ts +1 -1
- package/dist/types/nodeviews/TableComponent.d.ts +2 -1
- package/dist/types/nodeviews/TableComponentWithSharedState.d.ts +3 -1
- package/dist/types/nodeviews/lazy-node-views.d.ts +0 -1
- package/dist/types/nodeviews/table.d.ts +1 -1
- package/dist/types/nodeviews/types.d.ts +2 -2
- package/dist/types/plugin.d.ts +1 -3
- package/dist/types/pm-plugins/main.d.ts +1 -1
- package/dist/types/types.d.ts +4 -1
- package/dist/types/ui/ui-styles.d.ts +1 -1
- package/dist/types/utils/decoration.d.ts +1 -1
- package/dist/types-ts4.5/event-handlers.d.ts +1 -1
- package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +2 -1
- package/dist/types-ts4.5/nodeviews/TableComponentWithSharedState.d.ts +3 -1
- package/dist/types-ts4.5/nodeviews/lazy-node-views.d.ts +0 -1
- package/dist/types-ts4.5/nodeviews/table.d.ts +1 -1
- package/dist/types-ts4.5/nodeviews/types.d.ts +2 -2
- package/dist/types-ts4.5/plugin.d.ts +1 -3
- package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -1
- package/dist/types-ts4.5/types.d.ts +4 -1
- package/dist/types-ts4.5/ui/ui-styles.d.ts +1 -1
- package/dist/types-ts4.5/utils/decoration.d.ts +1 -1
- package/package.json +5 -5
- package/src/commands/column-resize.ts +8 -3
- package/src/commands/hover.ts +14 -10
- package/src/event-handlers.ts +16 -1
- package/src/nodeviews/TableComponent.tsx +22 -16
- package/src/nodeviews/TableComponentWithSharedState.tsx +6 -1
- package/src/nodeviews/lazy-node-views.ts +0 -4
- package/src/nodeviews/table.tsx +13 -8
- package/src/nodeviews/types.ts +2 -2
- package/src/plugin.tsx +24 -31
- package/src/pm-plugins/main.ts +2 -6
- package/src/toolbar.tsx +1 -1
- package/src/types.ts +5 -1
- package/src/ui/common-styles.ts +1 -1
- package/src/ui/ui-styles.ts +36 -29
- package/src/utils/decoration.ts +8 -3
package/src/commands/hover.ts
CHANGED
|
@@ -171,16 +171,20 @@ export const clearHoverSelection = () =>
|
|
|
171
171
|
}));
|
|
172
172
|
|
|
173
173
|
export const showResizeHandleLine = (cellColumnPositioning: CellColumnPositioning) =>
|
|
174
|
-
createCommand((state) =>
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
174
|
+
createCommand((state) => {
|
|
175
|
+
const { isDragAndDropEnabled } = getPluginState(state);
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
type: 'SHOW_RESIZE_HANDLE_LINE',
|
|
179
|
+
data: {
|
|
180
|
+
decorationSet: updatePluginStateDecorations(
|
|
181
|
+
state,
|
|
182
|
+
createColumnLineResize(state.selection, cellColumnPositioning, isDragAndDropEnabled),
|
|
183
|
+
TableDecorations.COLUMN_RESIZING_HANDLE_LINE,
|
|
184
|
+
),
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
});
|
|
184
188
|
|
|
185
189
|
export const hideResizeHandleLine = () =>
|
|
186
190
|
createCommand((state) => ({
|
package/src/event-handlers.ts
CHANGED
|
@@ -537,12 +537,27 @@ export const isTableInFocus = (view: EditorView) => {
|
|
|
537
537
|
};
|
|
538
538
|
|
|
539
539
|
export const whenTableInFocus =
|
|
540
|
-
(
|
|
540
|
+
(
|
|
541
|
+
eventHandler: (view: EditorView, mouseEvent: Event) => boolean,
|
|
542
|
+
pluginInjectionApi?: PluginInjectionAPI,
|
|
543
|
+
) =>
|
|
541
544
|
(view: EditorView, mouseEvent: Event): boolean => {
|
|
542
545
|
if (!isTableInFocus(view)) {
|
|
543
546
|
return false;
|
|
544
547
|
}
|
|
545
548
|
|
|
549
|
+
const isViewMode =
|
|
550
|
+
pluginInjectionApi?.editorViewMode?.sharedState.currentState()?.mode === 'view';
|
|
551
|
+
/**
|
|
552
|
+
* Table cannot be in focus if we are in view mode.
|
|
553
|
+
* This will prevent an infinite flow of adding and removing
|
|
554
|
+
* resize handle decorations in view mode that causes unpredictable
|
|
555
|
+
* selections.
|
|
556
|
+
*/
|
|
557
|
+
if (isViewMode) {
|
|
558
|
+
return false;
|
|
559
|
+
}
|
|
560
|
+
|
|
546
561
|
return eventHandler(view, mouseEvent);
|
|
547
562
|
};
|
|
548
563
|
|
|
@@ -109,12 +109,15 @@ interface ComponentProps {
|
|
|
109
109
|
contentDOM: (node: HTMLElement | null) => void;
|
|
110
110
|
containerWidth: EditorContainerWidth;
|
|
111
111
|
allowControls: boolean;
|
|
112
|
+
|
|
113
|
+
allowTableResizing?: boolean;
|
|
114
|
+
allowTableAlignment?: boolean;
|
|
115
|
+
|
|
112
116
|
isHeaderRowEnabled: boolean;
|
|
113
117
|
isHeaderColumnEnabled: boolean;
|
|
114
118
|
isMediaFullscreen?: boolean;
|
|
115
119
|
isDragAndDropEnabled?: boolean;
|
|
116
120
|
isTableScalingEnabled?: boolean;
|
|
117
|
-
isTableAlignmentEnabled?: boolean;
|
|
118
121
|
tableActive: boolean;
|
|
119
122
|
ordering?: TableColumnOrdering;
|
|
120
123
|
isResizing?: boolean;
|
|
@@ -228,8 +231,8 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
228
231
|
componentDidMount() {
|
|
229
232
|
const {
|
|
230
233
|
allowColumnResizing,
|
|
234
|
+
allowTableResizing,
|
|
231
235
|
eventDispatcher,
|
|
232
|
-
options,
|
|
233
236
|
isDragAndDropEnabled,
|
|
234
237
|
getNode,
|
|
235
238
|
getEditorFeatureFlags,
|
|
@@ -290,7 +293,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
290
293
|
* We no longer use `containerWidth` as a variable to determine an update for table resizing (avoids unnecessary updates).
|
|
291
294
|
* Instead we use the resize event to only trigger updates when necessary.
|
|
292
295
|
*/
|
|
293
|
-
if (!
|
|
296
|
+
if (!allowTableResizing) {
|
|
294
297
|
window.addEventListener('resize', this.handleWindowResizeDebounced);
|
|
295
298
|
}
|
|
296
299
|
this.handleTableResizingDebounced();
|
|
@@ -313,7 +316,8 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
313
316
|
}
|
|
314
317
|
|
|
315
318
|
componentWillUnmount() {
|
|
316
|
-
const { allowColumnResizing,
|
|
319
|
+
const { allowColumnResizing, allowTableResizing, eventDispatcher, isDragAndDropEnabled } =
|
|
320
|
+
this.props;
|
|
317
321
|
if (this.wrapper && !isIE11) {
|
|
318
322
|
this.wrapper.removeEventListener('scroll', this.handleScrollDebounced);
|
|
319
323
|
}
|
|
@@ -333,11 +337,11 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
333
337
|
this.scaleTableDebounced.cancel();
|
|
334
338
|
this.handleTableResizingDebounced.cancel();
|
|
335
339
|
this.handleAutoSizeDebounced.cancel();
|
|
336
|
-
if (!
|
|
340
|
+
if (!allowTableResizing) {
|
|
337
341
|
this.handleWindowResizeDebounced.cancel();
|
|
338
342
|
}
|
|
339
343
|
|
|
340
|
-
if (!
|
|
344
|
+
if (!allowTableResizing && allowColumnResizing) {
|
|
341
345
|
window.removeEventListener('resize', this.handleWindowResizeDebounced);
|
|
342
346
|
}
|
|
343
347
|
|
|
@@ -530,6 +534,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
530
534
|
getNode,
|
|
531
535
|
isMediaFullscreen,
|
|
532
536
|
allowColumnResizing,
|
|
537
|
+
allowTableResizing,
|
|
533
538
|
isResizing,
|
|
534
539
|
options,
|
|
535
540
|
isTableScalingEnabled, // we could use options.isTableScalingEnabled here
|
|
@@ -578,7 +583,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
578
583
|
|
|
579
584
|
if (
|
|
580
585
|
this.props.options?.isCommentEditor &&
|
|
581
|
-
|
|
586
|
+
allowTableResizing &&
|
|
582
587
|
!options?.isTableScalingEnabled
|
|
583
588
|
) {
|
|
584
589
|
this.removeInlineTableWidth();
|
|
@@ -632,7 +637,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
632
637
|
if (tablesHaveDifferentColumnWidths(currentTable, previousTable) || isNoOfColumnsChanged) {
|
|
633
638
|
const { view } = this.props;
|
|
634
639
|
const shouldRecreateResizeCols =
|
|
635
|
-
!
|
|
640
|
+
!allowTableResizing || !isResizing || (isNoOfColumnsChanged && isResizing);
|
|
636
641
|
|
|
637
642
|
if (shouldRecreateResizeCols) {
|
|
638
643
|
const start = getPos() || 0;
|
|
@@ -745,7 +750,8 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
745
750
|
isDragAndDropEnabled,
|
|
746
751
|
getEditorFeatureFlags,
|
|
747
752
|
isTableScalingEnabled, // here we can use options.isTableScalingEnabled
|
|
748
|
-
|
|
753
|
+
allowTableResizing,
|
|
754
|
+
allowTableAlignment,
|
|
749
755
|
} = this.props;
|
|
750
756
|
|
|
751
757
|
let { isInDanger, hoveredRows, hoveredCell, isTableHovered, isWholeTableInDanger } = this.props;
|
|
@@ -873,12 +879,12 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
873
879
|
isNested={isNested}
|
|
874
880
|
pluginInjectionApi={pluginInjectionApi}
|
|
875
881
|
tableWrapperHeight={this.state.tableWrapperHeight}
|
|
876
|
-
isTableResizingEnabled={
|
|
882
|
+
isTableResizingEnabled={allowTableResizing}
|
|
877
883
|
isResizing={isResizing}
|
|
878
884
|
isTableScalingEnabled={isTableScalingEnabled}
|
|
879
885
|
isTableWithFixedColumnWidthsOptionEnabled={tableWithFixedColumnWidthsOption}
|
|
880
886
|
isWholeTableInDanger={isWholeTableInDanger}
|
|
881
|
-
isTableAlignmentEnabled={
|
|
887
|
+
isTableAlignmentEnabled={allowTableAlignment}
|
|
882
888
|
shouldUseIncreasedScalingPercent={shouldUseIncreasedScalingPercent}
|
|
883
889
|
isCommentEditor={options?.isCommentEditor}
|
|
884
890
|
isChromelessEditor={options?.isChromelessEditor}
|
|
@@ -1037,7 +1043,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
1037
1043
|
};
|
|
1038
1044
|
|
|
1039
1045
|
private handleTableResizing = () => {
|
|
1040
|
-
const { getNode, containerWidth, options } = this.props;
|
|
1046
|
+
const { getNode, containerWidth, options, allowTableResizing } = this.props;
|
|
1041
1047
|
const prevNode = this.node!;
|
|
1042
1048
|
const node = getNode();
|
|
1043
1049
|
const prevAttrs = prevNode.attrs;
|
|
@@ -1096,7 +1102,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
1096
1102
|
noOfColumnsChanged
|
|
1097
1103
|
) {
|
|
1098
1104
|
const shouldScaleTable =
|
|
1099
|
-
(!
|
|
1105
|
+
(!allowTableResizing || (allowTableResizing && isNested)) &&
|
|
1100
1106
|
!hasNumberedColumnChanged &&
|
|
1101
1107
|
!noOfColumnsChanged;
|
|
1102
1108
|
|
|
@@ -1111,7 +1117,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
1111
1117
|
}
|
|
1112
1118
|
|
|
1113
1119
|
// only when table resizing is enabled and toggle numbered column to run scaleTable
|
|
1114
|
-
if (
|
|
1120
|
+
if (allowTableResizing && hasNumberedColumnChanged) {
|
|
1115
1121
|
if (!hasTableBeenResized(prevNode)) {
|
|
1116
1122
|
this.scaleTable(
|
|
1117
1123
|
{
|
|
@@ -1170,7 +1176,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
1170
1176
|
};
|
|
1171
1177
|
|
|
1172
1178
|
private setTimerToSendInitialOverflowCaptured = (isOverflowing: boolean) => {
|
|
1173
|
-
const { dispatchAnalyticsEvent, containerWidth,
|
|
1179
|
+
const { dispatchAnalyticsEvent, containerWidth, allowTableResizing } = this.props;
|
|
1174
1180
|
const parentWidth = this.state?.parentWidth || 0;
|
|
1175
1181
|
|
|
1176
1182
|
this.initialOverflowCaptureTimerId = setTimeout(() => {
|
|
@@ -1182,7 +1188,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
1182
1188
|
attributes: {
|
|
1183
1189
|
editorWidth: containerWidth.width || 0,
|
|
1184
1190
|
isOverflowing,
|
|
1185
|
-
tableResizingEnabled:
|
|
1191
|
+
tableResizingEnabled: allowTableResizing || false,
|
|
1186
1192
|
width: this.node.attrs.width || 0,
|
|
1187
1193
|
parentWidth,
|
|
1188
1194
|
},
|
|
@@ -27,6 +27,8 @@ type TableComponentWithSharedStateProps = {
|
|
|
27
27
|
getPos: getPosHandlerNode;
|
|
28
28
|
allowColumnResizing?: boolean;
|
|
29
29
|
allowControls?: boolean;
|
|
30
|
+
allowTableAlignment?: boolean;
|
|
31
|
+
allowTableResizing?: boolean;
|
|
30
32
|
};
|
|
31
33
|
|
|
32
34
|
/**
|
|
@@ -44,6 +46,8 @@ export const TableComponentWithSharedState = ({
|
|
|
44
46
|
allowControls,
|
|
45
47
|
getPos,
|
|
46
48
|
forwardRef,
|
|
49
|
+
allowTableAlignment,
|
|
50
|
+
allowTableResizing,
|
|
47
51
|
}: TableComponentWithSharedStateProps) => {
|
|
48
52
|
const { widthState, tableState, mediaState } = useSharedPluginState(api, [
|
|
49
53
|
'width',
|
|
@@ -103,7 +107,8 @@ export const TableComponentWithSharedState = ({
|
|
|
103
107
|
isHeaderColumnEnabled={isHeaderColumnEnabled}
|
|
104
108
|
isDragAndDropEnabled={options?.isDragAndDropEnabled}
|
|
105
109
|
isTableScalingEnabled={options?.isTableScalingEnabled}
|
|
106
|
-
|
|
110
|
+
allowTableAlignment={allowTableAlignment}
|
|
111
|
+
allowTableResizing={allowTableResizing}
|
|
107
112
|
tableActive={tableActive}
|
|
108
113
|
ordering={ordering}
|
|
109
114
|
isResizing={isResizing}
|
|
@@ -21,7 +21,6 @@ type TableViewOptions = {
|
|
|
21
21
|
getEditorFeatureFlags: GetEditorFeatureFlags;
|
|
22
22
|
dispatchAnalyticsEvent: DispatchAnalyticsEvent;
|
|
23
23
|
pluginInjectionApi?: PluginInjectionAPI;
|
|
24
|
-
isTableAlignmentEnabled?: boolean;
|
|
25
24
|
isCommentEditor?: boolean;
|
|
26
25
|
isChromelessEditor?: boolean;
|
|
27
26
|
};
|
|
@@ -39,7 +38,6 @@ export const lazyTableView = (options: TableViewOptions) => {
|
|
|
39
38
|
options.getEditorFeatureFlags,
|
|
40
39
|
options.dispatchAnalyticsEvent,
|
|
41
40
|
options.pluginInjectionApi,
|
|
42
|
-
options.isTableAlignmentEnabled,
|
|
43
41
|
options.isCommentEditor,
|
|
44
42
|
options.isChromelessEditor,
|
|
45
43
|
);
|
|
@@ -65,7 +63,6 @@ export const lazyTableView = (options: TableViewOptions) => {
|
|
|
65
63
|
getEditorFeatureFlags,
|
|
66
64
|
dispatchAnalyticsEvent,
|
|
67
65
|
pluginInjectionApi,
|
|
68
|
-
isTableAlignmentEnabled,
|
|
69
66
|
isCommentEditor,
|
|
70
67
|
isChromelessEditor,
|
|
71
68
|
} = getNodeViewOptions();
|
|
@@ -80,7 +77,6 @@ export const lazyTableView = (options: TableViewOptions) => {
|
|
|
80
77
|
getEditorFeatureFlags,
|
|
81
78
|
dispatchAnalyticsEvent,
|
|
82
79
|
pluginInjectionApi,
|
|
83
|
-
isTableAlignmentEnabled,
|
|
84
80
|
isCommentEditor,
|
|
85
81
|
isChromelessEditor,
|
|
86
82
|
);
|
package/src/nodeviews/table.tsx
CHANGED
|
@@ -53,15 +53,16 @@ const getInlineWidth = (
|
|
|
53
53
|
options: Props['options'],
|
|
54
54
|
state: EditorState,
|
|
55
55
|
pos: number | undefined,
|
|
56
|
+
allowTableResizing?: boolean,
|
|
56
57
|
): number | undefined => {
|
|
57
|
-
if (!node.attrs.width && options?.isCommentEditor &&
|
|
58
|
+
if (!node.attrs.width && options?.isCommentEditor && allowTableResizing) {
|
|
58
59
|
return;
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
// provide a width for tables when custom table width is supported
|
|
62
63
|
// this is to ensure 'responsive' tables (colgroup widths are undefined) become fixed to
|
|
63
64
|
// support screen size adjustments
|
|
64
|
-
const shouldHaveInlineWidth =
|
|
65
|
+
const shouldHaveInlineWidth = allowTableResizing && !isTableNested(state, pos);
|
|
65
66
|
|
|
66
67
|
let widthValue = getTableContainerWidth(node);
|
|
67
68
|
|
|
@@ -135,6 +136,7 @@ export default class TableView extends ReactNodeView<Props> {
|
|
|
135
136
|
this.reactComponentProps.options,
|
|
136
137
|
this.reactComponentProps.view.state,
|
|
137
138
|
this.reactComponentProps.getPos(),
|
|
139
|
+
this.reactComponentProps.allowTableResizing,
|
|
138
140
|
);
|
|
139
141
|
if (tableInlineWidth) {
|
|
140
142
|
handleInlineTableWidth(this.table, tableInlineWidth);
|
|
@@ -167,6 +169,7 @@ export default class TableView extends ReactNodeView<Props> {
|
|
|
167
169
|
(this.reactComponentProps as Props).options,
|
|
168
170
|
this.view.state,
|
|
169
171
|
this.getPos(),
|
|
172
|
+
this.reactComponentProps.allowTableResizing,
|
|
170
173
|
);
|
|
171
174
|
|
|
172
175
|
const isTableResizing = tableWidthPluginKey.getState(this.view.state)?.resizing;
|
|
@@ -192,6 +195,8 @@ export default class TableView extends ReactNodeView<Props> {
|
|
|
192
195
|
eventDispatcher={props.eventDispatcher}
|
|
193
196
|
api={props.pluginInjectionApi}
|
|
194
197
|
allowColumnResizing={props.allowColumnResizing}
|
|
198
|
+
allowTableAlignment={props.allowTableAlignment}
|
|
199
|
+
allowTableResizing={props.allowTableResizing}
|
|
195
200
|
allowControls={props.allowControls}
|
|
196
201
|
getPos={props.getPos}
|
|
197
202
|
getEditorFeatureFlags={props.getEditorFeatureFlags}
|
|
@@ -266,7 +271,8 @@ export default class TableView extends ReactNodeView<Props> {
|
|
|
266
271
|
isHeaderColumnEnabled={pluginState!.isHeaderColumnEnabled}
|
|
267
272
|
isDragAndDropEnabled={pluginState!.isDragAndDropEnabled}
|
|
268
273
|
isTableScalingEnabled={props.options?.isTableScalingEnabled} // this.options?.isTableScalingEnabled same as TableOptions.isTableScalingEnabled same as pluginState.isTableScalingEnabled
|
|
269
|
-
|
|
274
|
+
allowTableAlignment={props.allowTableAlignment}
|
|
275
|
+
allowTableResizing={props.allowTableResizing}
|
|
270
276
|
tableActive={tableActive}
|
|
271
277
|
ordering={pluginState!.ordering as TableColumnOrdering}
|
|
272
278
|
isResizing={isResizing}
|
|
@@ -366,7 +372,6 @@ export const createTableView = (
|
|
|
366
372
|
getEditorFeatureFlags: GetEditorFeatureFlags,
|
|
367
373
|
dispatchAnalyticsEvent: DispatchAnalyticsEvent,
|
|
368
374
|
pluginInjectionApi?: PluginInjectionAPI,
|
|
369
|
-
isTableAlignmentEnabled?: boolean,
|
|
370
375
|
isCommentEditor?: boolean,
|
|
371
376
|
isChromelessEditor?: boolean,
|
|
372
377
|
): NodeView => {
|
|
@@ -374,16 +379,18 @@ export const createTableView = (
|
|
|
374
379
|
pluginConfig,
|
|
375
380
|
isFullWidthModeEnabled,
|
|
376
381
|
wasFullWidthModeEnabled,
|
|
377
|
-
isTableResizingEnabled,
|
|
378
382
|
isDragAndDropEnabled,
|
|
379
383
|
isTableScalingEnabled, // same as options.isTableScalingEnabled
|
|
380
384
|
} = getPluginState(view.state);
|
|
381
|
-
const { allowColumnResizing, allowControls } =
|
|
385
|
+
const { allowColumnResizing, allowControls, allowTableResizing, allowTableAlignment } =
|
|
386
|
+
getPluginConfig(pluginConfig);
|
|
382
387
|
|
|
383
388
|
return new TableView({
|
|
384
389
|
node,
|
|
385
390
|
view,
|
|
386
391
|
allowColumnResizing,
|
|
392
|
+
allowTableResizing,
|
|
393
|
+
allowTableAlignment,
|
|
387
394
|
allowControls,
|
|
388
395
|
portalProviderAPI,
|
|
389
396
|
eventDispatcher,
|
|
@@ -391,10 +398,8 @@ export const createTableView = (
|
|
|
391
398
|
options: {
|
|
392
399
|
isFullWidthModeEnabled,
|
|
393
400
|
wasFullWidthModeEnabled,
|
|
394
|
-
isTableResizingEnabled,
|
|
395
401
|
isDragAndDropEnabled,
|
|
396
402
|
isTableScalingEnabled, // same as options.isTableScalingEnabled
|
|
397
|
-
isTableAlignmentEnabled,
|
|
398
403
|
isCommentEditor,
|
|
399
404
|
isChromelessEditor,
|
|
400
405
|
},
|
package/src/nodeviews/types.ts
CHANGED
|
@@ -10,10 +10,8 @@ import type { PluginInjectionAPI } from '../types';
|
|
|
10
10
|
export type TableOptions = {
|
|
11
11
|
isFullWidthModeEnabled?: boolean;
|
|
12
12
|
wasFullWidthModeEnabled?: boolean;
|
|
13
|
-
isTableResizingEnabled?: boolean;
|
|
14
13
|
isDragAndDropEnabled?: boolean;
|
|
15
14
|
isTableScalingEnabled?: boolean;
|
|
16
|
-
isTableAlignmentEnabled?: boolean;
|
|
17
15
|
isCommentEditor?: boolean;
|
|
18
16
|
isChromelessEditor?: boolean;
|
|
19
17
|
};
|
|
@@ -22,6 +20,8 @@ export interface Props {
|
|
|
22
20
|
node: PmNode;
|
|
23
21
|
view: EditorView;
|
|
24
22
|
allowColumnResizing?: boolean;
|
|
23
|
+
allowTableResizing?: boolean;
|
|
24
|
+
allowTableAlignment?: boolean;
|
|
25
25
|
allowControls?: boolean;
|
|
26
26
|
cellMinWidth?: number;
|
|
27
27
|
portalProviderAPI: PortalProviderAPI;
|
package/src/plugin.tsx
CHANGED
|
@@ -103,15 +103,15 @@ import { createTableWithWidth } from './utils';
|
|
|
103
103
|
|
|
104
104
|
export interface TablePluginOptions {
|
|
105
105
|
tableOptions: PluginConfig;
|
|
106
|
-
|
|
106
|
+
// this option will eventually be removed, and enabled by default
|
|
107
107
|
dragAndDropEnabled?: boolean;
|
|
108
|
+
// this option will eventually be removed, and enabled by default
|
|
109
|
+
isTableScalingEnabled?: boolean;
|
|
108
110
|
allowContextualMenu?: boolean;
|
|
109
111
|
// TODO these two need to be rethought
|
|
110
112
|
fullWidthEnabled?: boolean;
|
|
111
113
|
wasFullWidthEnabled?: boolean;
|
|
112
114
|
getEditorFeatureFlags?: GetEditorFeatureFlags;
|
|
113
|
-
isTableScalingEnabled?: boolean;
|
|
114
|
-
isTableAlignmentEnabled?: boolean;
|
|
115
115
|
isNewColumnResizingEnabled?: boolean;
|
|
116
116
|
isCommentEditor?: boolean;
|
|
117
117
|
isChromelessEditor?: boolean;
|
|
@@ -230,11 +230,11 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
230
230
|
(state, dispatch) => {
|
|
231
231
|
const node = createTableWithWidth({
|
|
232
232
|
isTableScalingEnabled: options?.isTableScalingEnabled,
|
|
233
|
-
isTableAlignmentEnabled: options?.
|
|
233
|
+
isTableAlignmentEnabled: options?.tableOptions.allowTableAlignment,
|
|
234
234
|
isFullWidthModeEnabled: options?.fullWidthEnabled,
|
|
235
235
|
isCommentEditor: options?.isCommentEditor,
|
|
236
236
|
isChromelessEditor: options?.isChromelessEditor,
|
|
237
|
-
isTableResizingEnabled: options?.
|
|
237
|
+
isTableResizingEnabled: options?.tableOptions.allowTableResizing,
|
|
238
238
|
})(state.schema);
|
|
239
239
|
|
|
240
240
|
// If the cursor is inside a table
|
|
@@ -283,7 +283,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
283
283
|
insertTableWithSize: insertTableWithSize(
|
|
284
284
|
options?.fullWidthEnabled,
|
|
285
285
|
options?.isTableScalingEnabled,
|
|
286
|
-
options?.
|
|
286
|
+
options?.tableOptions.allowTableAlignment,
|
|
287
287
|
api?.analytics?.actions,
|
|
288
288
|
options?.isCommentEditor,
|
|
289
289
|
),
|
|
@@ -299,7 +299,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
299
299
|
name: 'table',
|
|
300
300
|
node: tableNodeSpecWithFixedToDOM({
|
|
301
301
|
allowColumnResizing: Boolean(allowColumnResizing),
|
|
302
|
-
tableResizingEnabled: Boolean(options?.
|
|
302
|
+
tableResizingEnabled: Boolean(options?.tableOptions.allowTableResizing),
|
|
303
303
|
getEditorContainerWidth: defaultGetEditorContainerWidth,
|
|
304
304
|
isNestingSupported,
|
|
305
305
|
}),
|
|
@@ -313,7 +313,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
313
313
|
name: 'table',
|
|
314
314
|
node: tableNodeSpecWithFixedToDOM({
|
|
315
315
|
allowColumnResizing: Boolean(allowColumnResizing),
|
|
316
|
-
tableResizingEnabled: Boolean(options?.
|
|
316
|
+
tableResizingEnabled: Boolean(options?.tableOptions.allowTableResizing),
|
|
317
317
|
getEditorContainerWidth: defaultGetEditorContainerWidth,
|
|
318
318
|
isNestingSupported,
|
|
319
319
|
}),
|
|
@@ -339,13 +339,10 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
339
339
|
const {
|
|
340
340
|
fullWidthEnabled,
|
|
341
341
|
wasFullWidthEnabled,
|
|
342
|
-
tableResizingEnabled,
|
|
343
|
-
|
|
344
342
|
tableOptions,
|
|
345
343
|
getEditorFeatureFlags,
|
|
346
344
|
dragAndDropEnabled,
|
|
347
345
|
isTableScalingEnabled,
|
|
348
|
-
isTableAlignmentEnabled,
|
|
349
346
|
isCommentEditor,
|
|
350
347
|
isChromelessEditor,
|
|
351
348
|
} = options || ({} as TablePluginOptions);
|
|
@@ -360,14 +357,12 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
360
357
|
defaultGetEditorContainerWidth,
|
|
361
358
|
getEditorFeatureFlags || defaultGetEditorFeatureFlags,
|
|
362
359
|
getIntl,
|
|
363
|
-
tableResizingEnabled,
|
|
364
360
|
fullWidthEnabled,
|
|
365
361
|
wasFullWidthEnabled,
|
|
366
362
|
dragAndDropEnabled,
|
|
367
363
|
editorAnalyticsAPI,
|
|
368
364
|
api,
|
|
369
365
|
isTableScalingEnabled,
|
|
370
|
-
isTableAlignmentEnabled,
|
|
371
366
|
shouldUseIncreasedScalingPercent,
|
|
372
367
|
isCommentEditor,
|
|
373
368
|
isChromelessEditor,
|
|
@@ -383,9 +378,8 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
383
378
|
getEditorFeatureFlags,
|
|
384
379
|
isTableScalingEnabled,
|
|
385
380
|
isNewColumnResizingEnabled,
|
|
386
|
-
isTableAlignmentEnabled,
|
|
387
381
|
} = options || ({} as TablePluginOptions);
|
|
388
|
-
const { allowColumnResizing } = pluginConfig(tableOptions);
|
|
382
|
+
const { allowColumnResizing, allowTableAlignment } = pluginConfig(tableOptions);
|
|
389
383
|
return allowColumnResizing
|
|
390
384
|
? createFlexiResizingPlugin(
|
|
391
385
|
dispatch,
|
|
@@ -399,7 +393,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
399
393
|
editorAnalyticsAPI,
|
|
400
394
|
isTableScalingEnabled || false,
|
|
401
395
|
isNewColumnResizingEnabled,
|
|
402
|
-
|
|
396
|
+
allowTableAlignment,
|
|
403
397
|
!!options?.isCommentEditor,
|
|
404
398
|
)
|
|
405
399
|
: undefined;
|
|
@@ -414,11 +408,10 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
414
408
|
const {
|
|
415
409
|
dragAndDropEnabled,
|
|
416
410
|
isTableScalingEnabled = false,
|
|
417
|
-
isTableAlignmentEnabled = false,
|
|
418
411
|
fullWidthEnabled = false,
|
|
419
412
|
isCommentEditor = false,
|
|
420
413
|
isChromelessEditor = false,
|
|
421
|
-
|
|
414
|
+
tableOptions,
|
|
422
415
|
} = options || ({} as TablePluginOptions);
|
|
423
416
|
|
|
424
417
|
return keymapPlugin(
|
|
@@ -428,7 +421,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
428
421
|
editorAnalyticsAPI,
|
|
429
422
|
dragAndDropEnabled,
|
|
430
423
|
isTableScalingEnabled,
|
|
431
|
-
|
|
424
|
+
tableOptions?.allowTableAlignment,
|
|
432
425
|
fullWidthEnabled,
|
|
433
426
|
api,
|
|
434
427
|
getIntl,
|
|
@@ -436,7 +429,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
436
429
|
shouldUseIncreasedScalingPercent,
|
|
437
430
|
isCommentEditor,
|
|
438
431
|
isChromelessEditor,
|
|
439
|
-
|
|
432
|
+
tableOptions?.allowTableResizing,
|
|
440
433
|
);
|
|
441
434
|
},
|
|
442
435
|
},
|
|
@@ -501,24 +494,24 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
501
494
|
{
|
|
502
495
|
name: 'tableWidth',
|
|
503
496
|
plugin: ({ dispatchAnalyticsEvent, dispatch }) =>
|
|
504
|
-
options?.
|
|
497
|
+
options?.tableOptions.allowTableResizing
|
|
505
498
|
? createTableWidthPlugin(
|
|
506
499
|
dispatch,
|
|
507
500
|
dispatchAnalyticsEvent,
|
|
508
|
-
options
|
|
509
|
-
options
|
|
510
|
-
options
|
|
511
|
-
options
|
|
501
|
+
options.fullWidthEnabled ?? false,
|
|
502
|
+
options.isTableScalingEnabled ?? false,
|
|
503
|
+
options.tableOptions.allowTableResizing ?? false,
|
|
504
|
+
options.isCommentEditor ?? false,
|
|
512
505
|
)
|
|
513
506
|
: undefined,
|
|
514
507
|
},
|
|
515
508
|
{
|
|
516
509
|
name: 'tableWidthInCommentFix',
|
|
517
510
|
plugin: ({ dispatch }) =>
|
|
518
|
-
options?.
|
|
511
|
+
options?.tableOptions.allowTableResizing && options?.isCommentEditor
|
|
519
512
|
? createTableWidthInCommentFixPlugin(
|
|
520
513
|
dispatch,
|
|
521
|
-
options
|
|
514
|
+
options.tableOptions.allowTableAlignment ?? false,
|
|
522
515
|
)
|
|
523
516
|
: undefined,
|
|
524
517
|
},
|
|
@@ -529,7 +522,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
529
522
|
createTableOverflowAnalyticsPlugin(
|
|
530
523
|
dispatch,
|
|
531
524
|
dispatchAnalyticsEvent,
|
|
532
|
-
options?.
|
|
525
|
+
options?.tableOptions.allowTableResizing ?? false,
|
|
533
526
|
),
|
|
534
527
|
},
|
|
535
528
|
{
|
|
@@ -731,7 +724,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
731
724
|
/>
|
|
732
725
|
)}
|
|
733
726
|
{(options?.isTableScalingEnabled ||
|
|
734
|
-
(options?.
|
|
727
|
+
(options?.tableOptions.allowTableResizing && options.isCommentEditor)) &&
|
|
735
728
|
isTableResizing &&
|
|
736
729
|
widthToWidest &&
|
|
737
730
|
resizingTableLocalId &&
|
|
@@ -772,11 +765,11 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
772
765
|
|
|
773
766
|
const tableNode = createTableWithWidth({
|
|
774
767
|
isTableScalingEnabled: options?.isTableScalingEnabled,
|
|
775
|
-
isTableAlignmentEnabled: options?.
|
|
768
|
+
isTableAlignmentEnabled: options?.tableOptions.allowTableAlignment,
|
|
776
769
|
isFullWidthModeEnabled: tableState?.isFullWidthModeEnabled,
|
|
777
770
|
isCommentEditor: options?.isCommentEditor,
|
|
778
771
|
isChromelessEditor: options?.isChromelessEditor,
|
|
779
|
-
isTableResizingEnabled: options?.
|
|
772
|
+
isTableResizingEnabled: options?.tableOptions.allowTableResizing,
|
|
780
773
|
})(state.schema);
|
|
781
774
|
|
|
782
775
|
let { tr } = state;
|
package/src/pm-plugins/main.ts
CHANGED
|
@@ -85,14 +85,12 @@ export const createPlugin = (
|
|
|
85
85
|
getEditorContainerWidth: GetEditorContainerWidth,
|
|
86
86
|
getEditorFeatureFlags: GetEditorFeatureFlags,
|
|
87
87
|
getIntl: () => IntlShape,
|
|
88
|
-
tableResizingEnabled?: boolean,
|
|
89
88
|
fullWidthModeEnabled?: boolean,
|
|
90
89
|
previousFullWidthModeEnabled?: boolean,
|
|
91
90
|
dragAndDropEnabled?: boolean,
|
|
92
91
|
editorAnalyticsAPI?: EditorAnalyticsAPI,
|
|
93
92
|
pluginInjectionApi?: PluginInjectionAPI,
|
|
94
93
|
isTableScalingEnabled?: boolean,
|
|
95
|
-
isTableAlignmentEnabled?: boolean,
|
|
96
94
|
shouldUseIncreasedScalingPercent?: boolean,
|
|
97
95
|
isCommentEditor?: boolean,
|
|
98
96
|
isChromelessEditor?: boolean,
|
|
@@ -104,7 +102,6 @@ export const createPlugin = (
|
|
|
104
102
|
insertRowButtonIndex: undefined,
|
|
105
103
|
isFullWidthModeEnabled: fullWidthModeEnabled,
|
|
106
104
|
wasFullWidthModeEnabled: previousFullWidthModeEnabled,
|
|
107
|
-
isTableResizingEnabled: tableResizingEnabled,
|
|
108
105
|
isHeaderRowEnabled: !!pluginConfig.allowHeaderRow,
|
|
109
106
|
isHeaderColumnEnabled: false,
|
|
110
107
|
isDragAndDropEnabled: dragAndDropEnabled,
|
|
@@ -268,7 +265,7 @@ export const createPlugin = (
|
|
|
268
265
|
if (
|
|
269
266
|
!insideTable(editorState) &&
|
|
270
267
|
isCommentEditor &&
|
|
271
|
-
|
|
268
|
+
pluginConfig.allowTableAlignment &&
|
|
272
269
|
isTableScalingEnabled
|
|
273
270
|
) {
|
|
274
271
|
slice = transformSliceTableLayoutDefaultToCenter(slice, schema);
|
|
@@ -369,7 +366,6 @@ export const createPlugin = (
|
|
|
369
366
|
getEditorFeatureFlags,
|
|
370
367
|
dispatchAnalyticsEvent,
|
|
371
368
|
pluginInjectionApi,
|
|
372
|
-
isTableAlignmentEnabled,
|
|
373
369
|
isCommentEditor,
|
|
374
370
|
isChromelessEditor,
|
|
375
371
|
}),
|
|
@@ -382,7 +378,7 @@ export const createPlugin = (
|
|
|
382
378
|
blur: handleBlur,
|
|
383
379
|
mousedown: withCellTracking(handleMouseDown),
|
|
384
380
|
mouseleave: handleMouseLeave,
|
|
385
|
-
mousemove: whenTableInFocus(handleMouseMove(nodeViewPortalProviderAPI)),
|
|
381
|
+
mousemove: whenTableInFocus(handleMouseMove(nodeViewPortalProviderAPI), pluginInjectionApi),
|
|
386
382
|
mouseenter: handleMouseEnter,
|
|
387
383
|
mouseup: whenTableInFocus(handleMouseUp),
|
|
388
384
|
click: withCellTracking(whenTableInFocus(handleClick)),
|
package/src/toolbar.tsx
CHANGED
package/src/types.ts
CHANGED
|
@@ -79,6 +79,8 @@ export interface PluginConfig {
|
|
|
79
79
|
advanced?: boolean;
|
|
80
80
|
allowBackgroundColor?: boolean;
|
|
81
81
|
allowColumnResizing?: boolean;
|
|
82
|
+
allowTableResizing?: boolean;
|
|
83
|
+
allowTableAlignment?: boolean;
|
|
82
84
|
allowHeaderColumn?: boolean;
|
|
83
85
|
allowHeaderRow?: boolean;
|
|
84
86
|
allowMergeCells?: boolean;
|
|
@@ -169,7 +171,6 @@ export interface TablePluginState {
|
|
|
169
171
|
getIntl: () => IntlShape;
|
|
170
172
|
|
|
171
173
|
wasFullWidthModeEnabled?: boolean;
|
|
172
|
-
isTableResizingEnabled?: boolean;
|
|
173
174
|
isDragAndDropEnabled?: boolean;
|
|
174
175
|
isTableHovered?: boolean;
|
|
175
176
|
|
|
@@ -469,6 +470,9 @@ export const TableCssClassName = {
|
|
|
469
470
|
WITH_RESIZE_LINE: `${tablePrefixSelector}-column-resize-line`,
|
|
470
471
|
WITH_RESIZE_LINE_LAST_COLUMN: `${tablePrefixSelector}-column-resize-line-last-column`,
|
|
471
472
|
|
|
473
|
+
WITH_DRAG_RESIZE_LINE: `${tablePrefixSelector}-drag-column--resize-line`,
|
|
474
|
+
WITH_DRAG_RESIZE_LINE_LAST_COLUMN: `${tablePrefixSelector}-drag-column-resize-line-last-column`,
|
|
475
|
+
|
|
472
476
|
WITH_ROW_INSERT_LINE: `${tablePrefixSelector}-row-insert-line`,
|
|
473
477
|
WITH_ROW_INSERT_LINE_INACTIVE: `${tablePrefixSelector}-row-insert-line__inactive`,
|
|
474
478
|
WITH_LAST_ROW_INSERT_LINE: `${tablePrefixSelector}-last-row-insert-line`,
|
package/src/ui/common-styles.ts
CHANGED
|
@@ -272,7 +272,7 @@ export const baseTableStyles = (props: { featureFlags?: FeatureFlags }) => css`
|
|
|
272
272
|
${hoveredCell()};
|
|
273
273
|
${hoveredWarningCell};
|
|
274
274
|
${insertLine()};
|
|
275
|
-
${resizeHandle(
|
|
275
|
+
${resizeHandle()};
|
|
276
276
|
${rangeSelectionStyles};
|
|
277
277
|
${viewModeSortStyles()};
|
|
278
278
|
|