@atlaskit/editor-plugin-table 12.1.15 → 12.2.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/afm-cc/tsconfig.json +3 -0
  3. package/afm-dev-agents/tsconfig.json +3 -0
  4. package/afm-jira/tsconfig.json +3 -0
  5. package/afm-passionfruit/tsconfig.json +3 -0
  6. package/afm-post-office/tsconfig.json +3 -0
  7. package/afm-rovo-extension/tsconfig.json +3 -0
  8. package/afm-townsquare/tsconfig.json +3 -0
  9. package/dist/cjs/nodeviews/TableComponent.js +73 -22
  10. package/dist/cjs/nodeviews/TableContainer.js +270 -10
  11. package/dist/cjs/nodeviews/TableResizer.js +9 -2
  12. package/dist/cjs/nodeviews/table.js +12 -2
  13. package/dist/cjs/nodeviews/toDOM.js +23 -7
  14. package/dist/cjs/pm-plugins/main.js +57 -23
  15. package/dist/cjs/pm-plugins/table-resizing/utils/colgroup.js +72 -1
  16. package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +70 -1
  17. package/dist/cjs/tablePlugin.js +17 -3
  18. package/dist/es2019/nodeviews/TableComponent.js +76 -22
  19. package/dist/es2019/nodeviews/TableContainer.js +256 -2
  20. package/dist/es2019/nodeviews/TableResizer.js +9 -2
  21. package/dist/es2019/nodeviews/table.js +12 -2
  22. package/dist/es2019/nodeviews/toDOM.js +24 -8
  23. package/dist/es2019/pm-plugins/main.js +57 -23
  24. package/dist/es2019/pm-plugins/table-resizing/utils/colgroup.js +72 -3
  25. package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +70 -1
  26. package/dist/es2019/tablePlugin.js +17 -3
  27. package/dist/esm/nodeviews/TableComponent.js +73 -22
  28. package/dist/esm/nodeviews/TableContainer.js +270 -10
  29. package/dist/esm/nodeviews/TableResizer.js +9 -2
  30. package/dist/esm/nodeviews/table.js +12 -2
  31. package/dist/esm/nodeviews/toDOM.js +24 -8
  32. package/dist/esm/pm-plugins/main.js +57 -23
  33. package/dist/esm/pm-plugins/table-resizing/utils/colgroup.js +74 -3
  34. package/dist/esm/pm-plugins/table-resizing/utils/misc.js +70 -1
  35. package/dist/esm/tablePlugin.js +17 -3
  36. package/dist/types/nodeviews/TableContainer.d.ts +7 -2
  37. package/dist/types/nodeviews/TableResizer.d.ts +1 -1
  38. package/dist/types/nodeviews/toDOM.d.ts +5 -0
  39. package/dist/types/nodeviews/types.d.ts +1 -0
  40. package/dist/types/pm-plugins/table-resizing/utils/colgroup.d.ts +1 -0
  41. package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +41 -0
  42. package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +7 -2
  43. package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +1 -1
  44. package/dist/types-ts4.5/nodeviews/toDOM.d.ts +5 -0
  45. package/dist/types-ts4.5/nodeviews/types.d.ts +1 -0
  46. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/colgroup.d.ts +1 -0
  47. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +41 -0
  48. package/package.json +8 -7
  49. package/src/nodeviews/TableComponent.tsx +105 -19
  50. package/src/nodeviews/TableContainer.tsx +331 -2
  51. package/src/nodeviews/TableResizer.tsx +10 -5
  52. package/src/nodeviews/table.tsx +14 -0
  53. package/src/nodeviews/toDOM.ts +75 -9
  54. package/src/nodeviews/types.ts +1 -0
  55. package/src/pm-plugins/main.ts +41 -18
  56. package/src/pm-plugins/table-resizing/utils/colgroup.ts +139 -6
  57. package/src/pm-plugins/table-resizing/utils/misc.ts +87 -0
  58. package/src/tablePlugin.tsx +21 -0
  59. package/tsconfig.app.json +3 -0
  60. package/types/package.json +1 -1
  61. package/ui/common-styles/package.json +1 -1
@@ -7,8 +7,17 @@ import type { DOMOutputSpec, NodeSpec, Node as PMNode } from '@atlaskit/editor-p
7
7
  import { akEditorGutterPaddingDynamic } from '@atlaskit/editor-shared-styles';
8
8
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
9
9
 
10
- import { generateColgroup, getResizerMinWidth } from '../pm-plugins/table-resizing/utils/colgroup';
10
+ import {
11
+ generateColgroup,
12
+ generateColgroupFromNode,
13
+ getResizerMinWidth,
14
+ } from '../pm-plugins/table-resizing/utils/colgroup';
11
15
  import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils/consts';
16
+ import {
17
+ getTableResizerContainerMaxWidthInCSS,
18
+ getTableResizerContainerForFullPageWidthInCSS,
19
+ getTableResizerItemWidthInCSS,
20
+ } from '../pm-plugins/table-resizing/utils/misc';
12
21
 
13
22
  import { getAlignmentStyle } from './table-container-styles';
14
23
 
@@ -17,6 +26,11 @@ type Config = {
17
26
  tableResizingEnabled: boolean;
18
27
  getEditorContainerWidth: GetEditorContainerWidth;
19
28
  isNestingSupported?: boolean;
29
+ isTableScalingEnabled?: boolean;
30
+ shouldUseIncreasedScalingPercent?: boolean;
31
+ isCommentEditor?: boolean;
32
+ isChromelessEditor?: boolean;
33
+ isNested?: boolean;
20
34
  };
21
35
  export const tableNodeSpecWithFixedToDOM = (
22
36
  config: Config,
@@ -40,6 +54,10 @@ export const tableNodeSpecWithFixedToDOM = (
40
54
 
41
55
  const tableMinWidth = getResizerMinWidth(node);
42
56
 
57
+ const tableWidthAttribute = node.attrs.width ? `${node.attrs.width}px` : `100%`;
58
+
59
+ const isFullPageEditor = !config.isChromelessEditor && !config.isCommentEditor;
60
+
43
61
  const attrs = {
44
62
  'data-number-column': node.attrs.isNumberColumnEnabled,
45
63
  'data-layout': node.attrs.layout,
@@ -48,12 +66,40 @@ export const tableNodeSpecWithFixedToDOM = (
48
66
  'data-table-width': node.attrs.width,
49
67
  };
50
68
 
69
+ // This would be used for table scaling in colgroup CSS
70
+ // cqw, or px is well supported
71
+ const resizableTableWidth = expValEquals(
72
+ 'platform_editor_tables_scaling_css',
73
+ 'isEnabled',
74
+ true,
75
+ )
76
+ ? isFullPageEditor
77
+ ? getTableResizerContainerForFullPageWidthInCSS(node, config.isTableScalingEnabled)
78
+ : `calc(100cqw - calc(var(--ak-editor--large-gutter-padding) * 2))`
79
+ : `min(calc(100cqw - calc(var(--ak-editor--large-gutter-padding) * 2)), ${node.attrs.width ?? '100%'})`;
80
+
51
81
  let colgroup: DOMOutputSpec = '';
52
82
 
53
83
  if (config.allowColumnResizing) {
54
- colgroup = ['colgroup', {}, ...generateColgroup(node)];
84
+ if (expValEquals('platform_editor_tables_scaling_css', 'isEnabled', true)) {
85
+ colgroup = [
86
+ 'colgroup',
87
+ {},
88
+ ...generateColgroupFromNode(
89
+ node,
90
+ config.isCommentEditor,
91
+ config.isChromelessEditor,
92
+ config.isNested,
93
+ config.isTableScalingEnabled,
94
+ config.shouldUseIncreasedScalingPercent,
95
+ ),
96
+ ];
97
+ } else {
98
+ colgroup = ['colgroup', {}, ...generateColgroup(node)];
99
+ }
55
100
  }
56
101
 
102
+ // For Chromeless editor, and nested tables in full page editor
57
103
  const tableContainerDiv = [
58
104
  'div',
59
105
  {
@@ -113,7 +159,10 @@ export const tableNodeSpecWithFixedToDOM = (
113
159
  ],
114
160
  ];
115
161
 
116
- if (!config.tableResizingEnabled) {
162
+ if (
163
+ !config.tableResizingEnabled ||
164
+ (expValEquals('platform_editor_tables_scaling_css', 'isEnabled', true) && config.isNested)
165
+ ) {
117
166
  return [
118
167
  'div',
119
168
  {
@@ -124,8 +173,6 @@ export const tableNodeSpecWithFixedToDOM = (
124
173
  ];
125
174
  }
126
175
 
127
- const tableWidthAttribute = node.attrs.width ? `${node.attrs.width}px` : `100%`;
128
-
129
176
  const tableResizingDiv = [
130
177
  'div',
131
178
  {
@@ -136,7 +183,15 @@ export const tableNodeSpecWithFixedToDOM = (
136
183
  'div',
137
184
  {
138
185
  class: 'pm-table-resizer-container',
139
- style: `width: min(calc(100cqw - ${gutterPadding()}), ${tableWidthAttribute});`,
186
+ style: convertToInlineCss({
187
+ '--ak-editor-table-gutter-padding': config.isTableScalingEnabled
188
+ ? 'calc(var(--ak-editor--large-gutter-padding) * 2)'
189
+ : 'calc(var(--ak-editor--large-gutter-padding) * 2 - var(--ak-editor-resizer-handle-spacing))',
190
+ '--ak-editor-table-width': resizableTableWidth,
191
+ width: expValEquals('platform_editor_tables_scaling_css', 'isEnabled', true)
192
+ ? `var(--ak-editor-table-width)`
193
+ : `min(calc(100cqw - ${gutterPadding()}), ${tableWidthAttribute})`,
194
+ }),
140
195
  },
141
196
  [
142
197
  'div',
@@ -146,12 +201,23 @@ export const tableNodeSpecWithFixedToDOM = (
146
201
  position: 'relative',
147
202
  userSelect: 'auto',
148
203
  boxSizing: 'border-box',
149
- '--ak-editor-table-gutter-padding': `${gutterPadding()}`,
150
204
  '--ak-editor-table-max-width': `${TABLE_MAX_WIDTH}px`,
151
205
  '--ak-editor-table-min-width': `${tableMinWidth}px`,
152
206
  minWidth: 'var(--ak-editor-table-min-width)',
153
- maxWidth: `min(calc(100cqw - var(--ak-editor-table-gutter-padding)), var(--ak-editor-table-max-width))`,
154
- width: `min(calc(100cqw - var(--ak-editor-table-gutter-padding)), ${tableWidthAttribute})`,
207
+ maxWidth: expValEquals('platform_editor_tables_scaling_css', 'isEnabled', true)
208
+ ? getTableResizerContainerMaxWidthInCSS(
209
+ config.isCommentEditor,
210
+ config.isChromelessEditor,
211
+ config.isTableScalingEnabled,
212
+ )
213
+ : `min(calc(100cqw - var(--ak-editor-table-gutter-padding)), var(--ak-editor-table-max-width))`,
214
+ width: expValEquals('platform_editor_tables_scaling_css', 'isEnabled', true)
215
+ ? getTableResizerItemWidthInCSS(
216
+ node,
217
+ config.isCommentEditor,
218
+ config.isChromelessEditor,
219
+ )
220
+ : `min(calc(100cqw - var(--ak-editor-table-gutter-padding)), ${tableWidthAttribute})`,
155
221
  }),
156
222
  },
157
223
  [
@@ -14,6 +14,7 @@ export type TableOptions = {
14
14
  isTableScalingEnabled?: boolean;
15
15
  isCommentEditor?: boolean;
16
16
  isChromelessEditor?: boolean;
17
+ shouldUseIncreasedScalingPercent?: boolean;
17
18
  };
18
19
 
19
20
  export interface Props {
@@ -26,6 +26,7 @@ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
26
26
  import { TableMap } from '@atlaskit/editor-tables';
27
27
  import { findTable } from '@atlaskit/editor-tables/utils';
28
28
  import { fg } from '@atlaskit/platform-feature-flags';
29
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
29
30
 
30
31
  import {
31
32
  tableCellView,
@@ -131,24 +132,46 @@ export const createPlugin = (
131
132
  return editorView.state;
132
133
  };
133
134
 
134
- const nodeViews =
135
- isSSR() && fg('platform_editor_table_fallback_to_dom_on_ssr')
136
- ? undefined
137
- : {
138
- table: tableView({
139
- portalProviderAPI,
140
- eventDispatcher,
141
- getEditorContainerWidth,
142
- getEditorFeatureFlags,
143
- dispatchAnalyticsEvent,
144
- pluginInjectionApi,
145
- isCommentEditor,
146
- isChromelessEditor,
147
- }),
148
- tableRow: tableRowView({ eventDispatcher, pluginInjectionApi }),
149
- tableCell: tableCellView({ eventDispatcher, pluginInjectionApi }),
150
- tableHeader: tableHeaderView({ eventDispatcher, pluginInjectionApi }),
151
- };
135
+ const getNodeView = () => {
136
+ // Because the layout shift issues has been fixed under experiment platform_editor_tables_scaling_css, so still want to load nodeview on SSR if experiment is enabled
137
+ if (expValEquals('platform_editor_tables_scaling_css', 'isEnabled', true)) {
138
+ return {
139
+ table: tableView({
140
+ portalProviderAPI,
141
+ eventDispatcher,
142
+ getEditorContainerWidth,
143
+ getEditorFeatureFlags,
144
+ dispatchAnalyticsEvent,
145
+ pluginInjectionApi,
146
+ isCommentEditor,
147
+ isChromelessEditor,
148
+ }),
149
+ tableRow: tableRowView({ eventDispatcher, pluginInjectionApi }),
150
+ tableCell: tableCellView({ eventDispatcher, pluginInjectionApi }),
151
+ tableHeader: tableHeaderView({ eventDispatcher, pluginInjectionApi }),
152
+ };
153
+ }
154
+ if (isSSR() && fg('platform_editor_table_fallback_to_dom_on_ssr')) {
155
+ return undefined;
156
+ }
157
+ return {
158
+ table: tableView({
159
+ portalProviderAPI,
160
+ eventDispatcher,
161
+ getEditorContainerWidth,
162
+ getEditorFeatureFlags,
163
+ dispatchAnalyticsEvent,
164
+ pluginInjectionApi,
165
+ isCommentEditor,
166
+ isChromelessEditor,
167
+ }),
168
+ tableRow: tableRowView({ eventDispatcher, pluginInjectionApi }),
169
+ tableCell: tableCellView({ eventDispatcher, pluginInjectionApi }),
170
+ tableHeader: tableHeaderView({ eventDispatcher, pluginInjectionApi }),
171
+ };
172
+ };
173
+
174
+ const nodeViews = getNodeView();
152
175
  return new SafePlugin({
153
176
  state: state,
154
177
  key: pluginKey,
@@ -1,11 +1,20 @@
1
1
  import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
2
- import { getFragmentBackingArray } from '@atlaskit/editor-common/utils';
2
+ import { calcTableColumnWidths, getFragmentBackingArray } from '@atlaskit/editor-common/utils';
3
3
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
4
4
  import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
5
+ import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
5
6
  import { TableMap } from '@atlaskit/editor-tables/table-map';
6
7
 
7
- import { COLUMN_MIN_WIDTH } from './consts';
8
- import { getScalingPercentForTableWithoutWidth, getTableScalingPercent } from './misc';
8
+ import {
9
+ COLUMN_MIN_WIDTH,
10
+ MAX_SCALING_PERCENT,
11
+ MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION,
12
+ } from './consts';
13
+ import {
14
+ getScalingPercentForTableWithoutWidth,
15
+ getTableContainerElementWidth,
16
+ getTableScalingPercent,
17
+ } from './misc';
9
18
 
10
19
  type Col = Array<string | { [name: string]: string }>;
11
20
 
@@ -18,6 +27,131 @@ type Col = Array<string | { [name: string]: string }>;
18
27
  export const getColWidthFix = (colwidth: number, tableColumnCount: number) =>
19
28
  colwidth - 1 / tableColumnCount;
20
29
 
30
+ const generateColStyle = (
31
+ fixedColWidth: number,
32
+ tableWidth: number,
33
+ isCommentEditor?: boolean,
34
+ isChromelessEditor?: boolean,
35
+ isNested?: boolean,
36
+ shouldUseIncreasedScalingPercent?: boolean,
37
+ isNumberColumnEnabled?: boolean,
38
+ isTableHasWidth?: boolean,
39
+ hasTableBeenResized?: boolean,
40
+ ) => {
41
+ const maxScalingPercent = shouldUseIncreasedScalingPercent
42
+ ? MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION
43
+ : MAX_SCALING_PERCENT;
44
+ const maxScaledRatio = 1 - maxScalingPercent;
45
+
46
+ const isFullPageEditor = !isChromelessEditor && !isCommentEditor;
47
+
48
+ // for nested tables, or chromeless editor, which used non resizable table container
49
+ if (isNested || isChromelessEditor) {
50
+ if (hasTableBeenResized) {
51
+ return `width: max(${fixedColWidth}px, ${tableCellMinWidth}px)`;
52
+ }
53
+ return `width: ${tableCellMinWidth}px)`;
54
+ }
55
+ if (isFullPageEditor || (!isFullPageEditor && isTableHasWidth)) {
56
+ const scaledPercent = isNumberColumnEnabled
57
+ ? `calc(calc(var(--ak-editor-table-width) - ${akEditorTableNumberColumnWidth}px - 1px)/${tableWidth})`
58
+ : `calc(calc(var(--ak-editor-table-width) - 1px)/${tableWidth})`;
59
+ return `width: max(calc(${fixedColWidth}px * ${maxScaledRatio}), calc(${fixedColWidth} * ${scaledPercent}), ${tableCellMinWidth}px)`;
60
+ }
61
+ // table resized to full-width in comment editor
62
+ // it doesn't have a width attribute, and cols has been resized
63
+ if (hasTableBeenResized) {
64
+ const scaledPercent = isNumberColumnEnabled
65
+ ? `calc(calc(var(--ak-editor-table-width) - ${akEditorTableNumberColumnWidth}px - 1px)/${tableWidth})`
66
+ : `calc(calc(var(--ak-editor-table-width) - 1px)/${tableWidth})`;
67
+ return `width: max(calc(${fixedColWidth} * ${scaledPercent}), ${tableCellMinWidth}px)`;
68
+ }
69
+ return `width: ${tableCellMinWidth}px`;
70
+ };
71
+
72
+ export const generateColgroupFromNode = (
73
+ table: PmNode,
74
+ isCommentEditor?: boolean,
75
+ isChromelessEditor?: boolean,
76
+ isNested?: boolean,
77
+ isTableScalingEnabled?: boolean,
78
+ shouldUseIncreasedScalingPercent?: boolean,
79
+ ) => {
80
+ const cols: Col[] = [];
81
+ const map = TableMap.get(table);
82
+ const isTableHasWidth = !!table.attrs.width;
83
+ const isNumberColumnEnabled = table.attrs.isNumberColumnEnabled || false;
84
+ const isFullPageEditor = !isChromelessEditor && !isCommentEditor;
85
+
86
+ // Ignored via go/ees005
87
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
88
+ table.content.firstChild!.content.forEach((cell) => {
89
+ const colspan = cell.attrs.colspan || 1;
90
+ // if the table has been resized
91
+ if (Array.isArray(cell.attrs.colwidth)) {
92
+ cell.attrs.colwidth.slice(0, colspan).forEach((width) => {
93
+ // existing logic for calculating the width of the column
94
+ const fixedColWidth = getColWidthFix(width, map.width);
95
+ const tableWidth =
96
+ isFullPageEditor || (!isFullPageEditor && isTableHasWidth)
97
+ ? getTableContainerElementWidth(table)
98
+ : calcTableColumnWidths(table).reduce((sum, width) => sum + width, 0);
99
+ if (isTableScalingEnabled) {
100
+ cols.push([
101
+ 'col',
102
+ {
103
+ style: generateColStyle(
104
+ fixedColWidth,
105
+ tableWidth,
106
+ isCommentEditor,
107
+ isChromelessEditor,
108
+ isNested,
109
+ shouldUseIncreasedScalingPercent,
110
+ isNumberColumnEnabled,
111
+ isTableHasWidth,
112
+ true,
113
+ ),
114
+ },
115
+ ]);
116
+ } else {
117
+ cols.push([
118
+ 'col',
119
+ {
120
+ style: `width: max(${fixedColWidth}px, ${tableCellMinWidth}px)`,
121
+ },
122
+ ]);
123
+ }
124
+ });
125
+ } else {
126
+ // columns has not been resized, so distribute the width evenly
127
+ cols.push(
128
+ ...Array.from({ length: colspan }, (_) => {
129
+ const tableWidth = getTableContainerElementWidth(table);
130
+ const columnWidth = tableWidth / map.width || 0;
131
+ const fixedColWidth = getColWidthFix(columnWidth, map.width || 0);
132
+
133
+ return [
134
+ 'col',
135
+ {
136
+ style: generateColStyle(
137
+ fixedColWidth,
138
+ tableWidth,
139
+ isCommentEditor,
140
+ isChromelessEditor,
141
+ isNested,
142
+ shouldUseIncreasedScalingPercent,
143
+ isNumberColumnEnabled,
144
+ isTableHasWidth,
145
+ ),
146
+ },
147
+ ];
148
+ }),
149
+ );
150
+ }
151
+ });
152
+ return cols;
153
+ };
154
+
21
155
  export const generateColgroup = (
22
156
  table: PmNode,
23
157
  tableRef?: HTMLElement,
@@ -37,7 +171,6 @@ export const generateColgroup = (
37
171
  if (tableRef) {
38
172
  // if we have tableRef here, isTableScalingEnabled is true
39
173
  let scalePercent = 1;
40
-
41
174
  if (isCommentEditor && !table.attrs?.width) {
42
175
  scalePercent = getScalingPercentForTableWithoutWidth(table, tableRef);
43
176
  } else {
@@ -45,6 +178,7 @@ export const generateColgroup = (
45
178
  }
46
179
 
47
180
  cell.attrs.colwidth.slice(0, colspan).forEach((width) => {
181
+ // existing logic for calculating the width of the column
48
182
  const fixedColWidth = getColWidthFix(width, map.width);
49
183
  const scaledWidth = fixedColWidth * scalePercent;
50
184
  const finalWidth = Math.max(scaledWidth, tableCellMinWidth);
@@ -80,7 +214,6 @@ export const generateColgroup = (
80
214
  );
81
215
  }
82
216
  });
83
-
84
217
  return cols;
85
218
  };
86
219
 
@@ -101,7 +234,7 @@ export const insertColgroupFromNode = (
101
234
 
102
235
  colgroup = renderColgroupFromNode(
103
236
  table,
104
- isTableScalingEnabled ? tableRef ?? undefined : undefined,
237
+ isTableScalingEnabled ? (tableRef ?? undefined) : undefined,
105
238
  shouldUseIncreasedScalingPercent,
106
239
  isCommentEditor,
107
240
  );
@@ -25,6 +25,7 @@ import { hasTableBeenResized, hasTableColumnBeenResized } from './colgroup';
25
25
  import {
26
26
  MAX_SCALING_PERCENT,
27
27
  MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION,
28
+ TABLE_MAX_WIDTH,
28
29
  } from './consts';
29
30
 
30
31
  // Translates named layouts in number values.
@@ -138,6 +139,92 @@ export const getTableContainerElementWidth = (table: PMNode) => {
138
139
  return getTableContainerWidth(table);
139
140
  };
140
141
 
142
+ // eslint-disable-next-line jsdoc/require-example
143
+ /**
144
+ * This function is used to set the max width for table resizer container.
145
+ * @param isCommentEditor Whether the editor is in comment mode.
146
+ * @param isChromelessEditor Whether the editor is chromeless.
147
+ * @param isTableScalingEnabled Whether table scaling is enabled.
148
+ * @returns The CSS max-width value
149
+ */
150
+ export const getTableResizerContainerMaxWidthInCSS = (
151
+ isCommentEditor?: boolean,
152
+ isChromelessEditor?: boolean,
153
+ isTableScalingEnabled?: boolean,
154
+ ): string => {
155
+ const maxResizerWidthForNonCommentEditor = isTableScalingEnabled
156
+ ? `min(calc(100cqw - calc(var(--ak-editor--large-gutter-padding) * 2)), ${TABLE_MAX_WIDTH}px)`
157
+ : `min(calc(100cqw - calc(var(--ak-editor--large-gutter-padding) * 2) - var(--ak-editor--resizer-handle-spacing)), ${TABLE_MAX_WIDTH}px)`;
158
+ return isCommentEditor || isChromelessEditor ? '100%' : maxResizerWidthForNonCommentEditor;
159
+ };
160
+
161
+ // eslint-disable-next-line jsdoc/require-example
162
+ /**
163
+ * This function is used in NodeView for TableResizer to set the max width for table resizer container
164
+ * @param node The ProseMirror node representing the table.
165
+ * @param isCommentEditor Whether the editor is in comment mode.
166
+ * @param isChromelessEditor Whether the editor is chromeless.
167
+ * @returns The CSS max-width value for the table resizer container.
168
+ */
169
+ export const getTableResizerItemWidth = (
170
+ node: PMNode,
171
+ isCommentEditor?: boolean,
172
+ isChromelessEditor?: boolean,
173
+ ): number | undefined => {
174
+ const tableWidthAttribute = getTableContainerWidth(node);
175
+ if (!node.attrs.width && (isCommentEditor || isChromelessEditor)) {
176
+ // width undefined would make .resizer-item width to be `auto`
177
+ return undefined;
178
+ }
179
+ return tableWidthAttribute;
180
+ };
181
+
182
+ // eslint-disable-next-line jsdoc/require-example
183
+ /**
184
+ * This function is used to set the CSS width value for the table resizer-item.
185
+ * Because comment and chromeless editors don't have container-type: inline-size set,
186
+ * we need to calculate the width based on the table node width.
187
+ * If the table node width is not set, it will return 'auto'.
188
+ * This is used in table toDOM
189
+ * @param node The ProseMirror node representing the table.
190
+ * @param isCommentEditor Whether the editor is in comment mode.
191
+ * @param isChromelessEditor Whether the editor is chromeless.
192
+ * @returns The CSS width value for the table container.
193
+ */
194
+ export const getTableResizerItemWidthInCSS = (
195
+ node: PMNode,
196
+ isCommentEditor?: boolean,
197
+ isChromelessEditor?: boolean,
198
+ ): string => {
199
+ const tableWidthAttribute = getTableResizerItemWidth(node, isCommentEditor, isChromelessEditor);
200
+ return tableWidthAttribute ? `${tableWidthAttribute}px` : 'auto';
201
+ };
202
+
203
+ // eslint-disable-next-line jsdoc/require-example
204
+ /**
205
+ * This function is used to set the table width --ak-editor-table-width CSS property for full page editor.
206
+ * Which is applied to the table resizer container.
207
+ * For Full page appearance, we don't need to use containerWidth from JS, as we can use cqw value.
208
+ * So we set dynamic containerWidth from JS to CSS property.
209
+ * @param node The ProseMirror node representing the table.
210
+ * @param isCommentEditor Whether the editor is in comment mode.
211
+ * @param isChromelessEditor Whether the editor is chromeless.
212
+ * @param isTableScalingEnabled Whether table scaling is enabled.
213
+ * @param tableWidthFromJS The width of the container element. In toDOM it'd be undefined, but will have a value from nodeView.
214
+ * @returns The CSS width value for the table.
215
+ */
216
+ export const getTableResizerContainerForFullPageWidthInCSS = (
217
+ node: PMNode,
218
+ isTableScalingEnabled?: boolean,
219
+ ): string => {
220
+ const tableWidth = getTableContainerElementWidth(node);
221
+ // for full page appearance
222
+ if (isTableScalingEnabled) {
223
+ return `min(calc(100cqw - calc(var(--ak-editor--large-gutter-padding) * 2)), ${tableWidth}px)`;
224
+ }
225
+ return `min(calc(100cqw - calc(var(--ak-editor--large-gutter-padding) * 2) - var(--ak-editor--resizer-handle-spacing)), ${tableWidth}px)`;
226
+ };
227
+
141
228
  export const getTableScalingPercent = (
142
229
  table: PMNode,
143
230
  tableRef: HTMLElement | null,
@@ -309,6 +309,19 @@ const tablePlugin: TablePlugin = ({ config: options, api }) => {
309
309
  // TODO: ED-25901 - We need to move this into a plugin config option so we don't accidentally enable nested nodes in Jira
310
310
  const isNestingSupported = Boolean(options?.tableOptions?.allowNestedTables);
311
311
 
312
+ const isTableFixedColumnWidthsOptionEnabled =
313
+ options?.getEditorFeatureFlags?.().tableWithFixedColumnWidthsOption || false;
314
+
315
+ const shouldUseIncreasedScalingPercent =
316
+ options?.isTableScalingEnabled &&
317
+ (isTableFixedColumnWidthsOptionEnabled ||
318
+ // When in comment editor, we need the scaling percent to be 40% while tableWithFixedColumnWidthsOption is not visible
319
+ options?.isCommentEditor);
320
+
321
+ const isTableScalingEnabled = options?.isTableScalingEnabled;
322
+ const isCommentEditor = options?.isCommentEditor;
323
+ const isChromelessEditor = options?.isChromelessEditor;
324
+
312
325
  return isNestingSupported
313
326
  ? [
314
327
  {
@@ -318,6 +331,10 @@ const tablePlugin: TablePlugin = ({ config: options, api }) => {
318
331
  tableResizingEnabled: Boolean(options?.tableOptions.allowTableResizing),
319
332
  getEditorContainerWidth: defaultGetEditorContainerWidth,
320
333
  isNestingSupported,
334
+ isTableScalingEnabled,
335
+ shouldUseIncreasedScalingPercent,
336
+ isCommentEditor,
337
+ isChromelessEditor,
321
338
  }),
322
339
  },
323
340
  { name: 'tableHeader', node: tableHeaderWithNestedTable },
@@ -332,6 +349,10 @@ const tablePlugin: TablePlugin = ({ config: options, api }) => {
332
349
  tableResizingEnabled: Boolean(options?.tableOptions.allowTableResizing),
333
350
  getEditorContainerWidth: defaultGetEditorContainerWidth,
334
351
  isNestingSupported,
352
+ isTableScalingEnabled,
353
+ shouldUseIncreasedScalingPercent,
354
+ isCommentEditor,
355
+ isChromelessEditor,
335
356
  }),
336
357
  },
337
358
  { name: 'tableHeader', node: tableHeader },
package/tsconfig.app.json CHANGED
@@ -95,6 +95,9 @@
95
95
  {
96
96
  "path": "../../platform/feature-flags/tsconfig.app.json"
97
97
  },
98
+ {
99
+ "path": "../../platform/feature-flags-react/tsconfig.app.json"
100
+ },
98
101
  {
99
102
  "path": "../../pragmatic-drag-and-drop/core/tsconfig.app.json"
100
103
  },
@@ -8,7 +8,7 @@
8
8
  ],
9
9
  "types": "../dist/types/types/index.d.ts",
10
10
  "typesVersions": {
11
- ">=4.5 <5.4": {
11
+ ">=4.5 <5.9": {
12
12
  "*": [
13
13
  "../dist/types-ts4.5/types/index.d.ts"
14
14
  ]
@@ -8,7 +8,7 @@
8
8
  ],
9
9
  "types": "../../dist/types/ui/common-styles.d.ts",
10
10
  "typesVersions": {
11
- ">=4.5 <5.4": {
11
+ ">=4.5 <5.9": {
12
12
  "*": [
13
13
  "../../dist/types-ts4.5/ui/common-styles.d.ts"
14
14
  ]