@atlaskit/editor-plugin-table 7.11.3 → 7.11.5

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 (78) hide show
  1. package/CHANGELOG.md +1734 -700
  2. package/dist/cjs/commands/column-resize.js +5 -1
  3. package/dist/cjs/nodeviews/TableComponent.js +28 -6
  4. package/dist/cjs/nodeviews/table.js +17 -11
  5. package/dist/cjs/plugin.js +8 -9
  6. package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +6 -1
  7. package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +16 -10
  8. package/dist/cjs/pm-plugins/table-resizing/plugin.js +2 -2
  9. package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +7 -2
  10. package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +16 -11
  11. package/dist/cjs/pm-plugins/table-width.js +1 -5
  12. package/dist/cjs/pm-plugins/view-mode-sort/utils.js +37 -20
  13. package/dist/cjs/toolbar.js +12 -21
  14. package/dist/cjs/transforms/column-width.js +3 -0
  15. package/dist/cjs/ui/FloatingDragMenu/index.js +2 -5
  16. package/dist/cjs/ui/common-styles.js +8 -16
  17. package/dist/cjs/ui/ui-styles.js +18 -36
  18. package/dist/es2019/commands/column-resize.js +6 -2
  19. package/dist/es2019/nodeviews/TableComponent.js +30 -7
  20. package/dist/es2019/nodeviews/table.js +17 -12
  21. package/dist/es2019/plugin.js +8 -9
  22. package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +6 -1
  23. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +13 -7
  24. package/dist/es2019/pm-plugins/table-resizing/plugin.js +2 -2
  25. package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +7 -2
  26. package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +16 -11
  27. package/dist/es2019/pm-plugins/table-width.js +1 -5
  28. package/dist/es2019/pm-plugins/view-mode-sort/utils.js +36 -21
  29. package/dist/es2019/toolbar.js +7 -16
  30. package/dist/es2019/transforms/column-width.js +4 -1
  31. package/dist/es2019/ui/FloatingDragMenu/index.js +2 -5
  32. package/dist/es2019/ui/common-styles.js +18 -30
  33. package/dist/es2019/ui/ui-styles.js +88 -174
  34. package/dist/esm/commands/column-resize.js +5 -1
  35. package/dist/esm/nodeviews/TableComponent.js +28 -6
  36. package/dist/esm/nodeviews/table.js +17 -11
  37. package/dist/esm/plugin.js +8 -9
  38. package/dist/esm/pm-plugins/drag-and-drop/plugin.js +6 -1
  39. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +16 -10
  40. package/dist/esm/pm-plugins/table-resizing/plugin.js +2 -2
  41. package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +7 -2
  42. package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +16 -11
  43. package/dist/esm/pm-plugins/table-width.js +1 -5
  44. package/dist/esm/pm-plugins/view-mode-sort/utils.js +37 -20
  45. package/dist/esm/toolbar.js +12 -21
  46. package/dist/esm/transforms/column-width.js +3 -0
  47. package/dist/esm/ui/FloatingDragMenu/index.js +2 -5
  48. package/dist/esm/ui/common-styles.js +8 -16
  49. package/dist/esm/ui/ui-styles.js +18 -36
  50. package/dist/types/pm-plugins/table-resizing/event-handlers.d.ts +1 -1
  51. package/dist/types/pm-plugins/table-resizing/plugin.d.ts +1 -1
  52. package/dist/types/pm-plugins/table-resizing/utils/scale-table.d.ts +3 -3
  53. package/dist/types/pm-plugins/table-width.d.ts +1 -1
  54. package/dist/types/pm-plugins/view-mode-sort/utils.d.ts +3 -1
  55. package/dist/types/ui/FloatingDragMenu/index.d.ts +2 -1
  56. package/dist/types-ts4.5/pm-plugins/table-resizing/event-handlers.d.ts +1 -1
  57. package/dist/types-ts4.5/pm-plugins/table-resizing/plugin.d.ts +1 -1
  58. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/scale-table.d.ts +3 -3
  59. package/dist/types-ts4.5/pm-plugins/table-width.d.ts +1 -1
  60. package/dist/types-ts4.5/pm-plugins/view-mode-sort/utils.d.ts +3 -1
  61. package/dist/types-ts4.5/ui/FloatingDragMenu/index.d.ts +2 -1
  62. package/package.json +3 -6
  63. package/src/commands/column-resize.ts +11 -2
  64. package/src/nodeviews/TableComponent.tsx +71 -9
  65. package/src/nodeviews/table.tsx +34 -18
  66. package/src/plugin.tsx +10 -4
  67. package/src/pm-plugins/drag-and-drop/plugin.ts +14 -1
  68. package/src/pm-plugins/table-resizing/event-handlers.ts +26 -4
  69. package/src/pm-plugins/table-resizing/plugin.ts +2 -0
  70. package/src/pm-plugins/table-resizing/utils/resize-state.ts +13 -2
  71. package/src/pm-plugins/table-resizing/utils/scale-table.ts +24 -10
  72. package/src/pm-plugins/table-width.ts +1 -3
  73. package/src/pm-plugins/view-mode-sort/utils.ts +49 -23
  74. package/src/toolbar.tsx +7 -11
  75. package/src/transforms/column-width.ts +8 -1
  76. package/src/ui/FloatingDragMenu/index.tsx +2 -3
  77. package/src/ui/common-styles.ts +18 -30
  78. package/src/ui/ui-styles.ts +92 -183
@@ -340,7 +340,10 @@ class TableComponent extends React.Component {
340
340
  this === null || this === void 0 ? void 0 : (_this$table = this.table) === null || _this$table === void 0 ? void 0 : _this$table.addEventListener('mouseenter', this.handleMouseEnter);
341
341
  }
342
342
  }
343
- if (isTableScalingEnabled) {
343
+ if (isTableScalingEnabled && !getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')) {
344
+ this.handleColgroupUpdates(true);
345
+ }
346
+ if (isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button') && getNode().attrs.displayMode !== 'fixed') {
344
347
  this.handleColgroupUpdates(true);
345
348
  }
346
349
  if (allowColumnResizing && this.wrapper && !isIE11) {
@@ -464,8 +467,10 @@ class TableComponent extends React.Component {
464
467
  const wasTableResized = hasTableBeenResized(this.node);
465
468
  const isTableResized = hasTableBeenResized(tableNode);
466
469
  const isColumnsDistributed = wasTableResized && !isTableResized;
467
- const shouldScale = isWidthChanged || isColumnsDistributed || isTableResizedFullWidth || isTableWidthChanged;
468
- if (force || !isResizing && shouldScale) {
470
+ const isTableDisplayModeChanged = this.node.attrs.displayMode !== tableNode.attrs.displayMode;
471
+ const shouldUpdateColgroup = isWidthChanged || isColumnsDistributed || isTableResizedFullWidth || isTableWidthChanged || isTableDisplayModeChanged;
472
+ if (force || !isResizing && shouldUpdateColgroup) {
473
+ var _this$props$options, _this$props$options2;
469
474
  const resizeState = getResizeState({
470
475
  minWidth: COLUMN_MIN_WIDTH,
471
476
  maxSize: tableRenderWidth,
@@ -475,10 +480,17 @@ class TableComponent extends React.Component {
475
480
  domAtPos: view.domAtPos,
476
481
  isTableScalingEnabled: true
477
482
  });
483
+ let shouldScaleOnColgroupUpdate = false;
484
+ if ((_this$props$options = this.props.options) !== null && _this$props$options !== void 0 && _this$props$options.isTableScalingEnabled && !getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')) {
485
+ shouldScaleOnColgroupUpdate = true;
486
+ }
487
+ if ((_this$props$options2 = this.props.options) !== null && _this$props$options2 !== void 0 && _this$props$options2.isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button') && tableNode.attrs.displayMode !== 'fixed') {
488
+ shouldScaleOnColgroupUpdate = true;
489
+ }
478
490
 
479
491
  // Request animation frame required for Firefox
480
492
  requestAnimationFrame(() => {
481
- updateColgroup(resizeState, this.table, tableNode, true);
493
+ updateColgroup(resizeState, this.table, tableNode, shouldScaleOnColgroupUpdate);
482
494
  });
483
495
  }
484
496
  }
@@ -496,6 +508,7 @@ class TableComponent extends React.Component {
496
508
  isResizing,
497
509
  options,
498
510
  isTableScalingEnabled,
511
+ // we could use options.isTableScalingEnabled here
499
512
  getPos
500
513
  } = this.props;
501
514
  let {
@@ -506,7 +519,17 @@ class TableComponent extends React.Component {
506
519
  const pluginState = getPluginState(view.state);
507
520
  isInDanger = pluginState.isInDanger;
508
521
  }
509
- if (isTableScalingEnabled) {
522
+ let shouldScale = false;
523
+ let shouldHandleColgroupUpdates = false;
524
+ if (isTableScalingEnabled && !getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')) {
525
+ shouldScale = true;
526
+ shouldHandleColgroupUpdates = true;
527
+ }
528
+ if (isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button') && getNode().attrs.displayMode !== 'fixed') {
529
+ shouldScale = true;
530
+ shouldHandleColgroupUpdates = true;
531
+ }
532
+ if (shouldHandleColgroupUpdates) {
510
533
  this.handleColgroupUpdates();
511
534
  }
512
535
  if (isInDanger && !table) {
@@ -555,7 +578,7 @@ class TableComponent extends React.Component {
555
578
  if (shouldRecreateResizeCols) {
556
579
  const start = getPos() || 0;
557
580
  const depth = view.state.doc.resolve(start).depth;
558
- const shouldScale = depth === 0 && isTableScalingEnabled;
581
+ shouldScale = depth === 0 && shouldScale;
559
582
  insertColgroupFromNode(this.table, currentTable, shouldScale);
560
583
  }
561
584
  updateControls()(view.state);
@@ -611,7 +634,7 @@ class TableComponent extends React.Component {
611
634
  pluginInjectionApi,
612
635
  isDragAndDropEnabled,
613
636
  getEditorFeatureFlags,
614
- isTableScalingEnabled
637
+ isTableScalingEnabled // here we can use options.isTableScalingEnabled
615
638
  } = this.props;
616
639
  let {
617
640
  isInDanger,
@@ -65,10 +65,9 @@ export default class TableView extends ReactNodeView {
65
65
  getContentDOM() {
66
66
  const rendered = DOMSerializer.renderSpec(document, toDOM(this.node, this.reactComponentProps));
67
67
  if (rendered.dom) {
68
- var _this$options;
68
+ var _this$options, _this$options2;
69
69
  this.table = rendered.dom;
70
- // Preserve Table Width cannot have inline width set on the table
71
- if (!((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.isTableScalingEnabled)) {
70
+ if (!((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.isTableScalingEnabled) || (_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button') && this.node.attrs.displayMode === 'fixed') {
72
71
  const tableInlineWidth = getInlineWidth(this.node, this.reactComponentProps.options, this.reactComponentProps.view.state, this.reactComponentProps.getPos());
73
72
  if (tableInlineWidth) {
74
73
  handleInlineTableWidth(this.table, tableInlineWidth);
@@ -78,7 +77,7 @@ export default class TableView extends ReactNodeView {
78
77
  return rendered;
79
78
  }
80
79
  setDomAttrs(node) {
81
- var _tableWidthPluginKey$;
80
+ var _this$options3, _this$options4;
82
81
  if (!this.table) {
83
82
  return;
84
83
  }
@@ -87,11 +86,15 @@ export default class TableView extends ReactNodeView {
87
86
  this.table.setAttribute(attr, attrs[attr]);
88
87
  });
89
88
 
90
- // handle inline style when table been resized
91
- const tableInlineWidth = getInlineWidth(node, this.reactComponentProps.options, this.view.state, this.getPos());
92
- const isTableResizing = (_tableWidthPluginKey$ = tableWidthPluginKey.getState(this.view.state)) === null || _tableWidthPluginKey$ === void 0 ? void 0 : _tableWidthPluginKey$.resizing;
93
- if (!isTableResizing && tableInlineWidth) {
94
- handleInlineTableWidth(this.table, tableInlineWidth);
89
+ // Preserve Table Width cannot have inline width set on the table
90
+ if (!((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.isTableScalingEnabled) || (_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button') && node.attrs.displayMode === 'fixed') {
91
+ var _tableWidthPluginKey$;
92
+ // handle inline style when table been resized
93
+ const tableInlineWidth = getInlineWidth(node, this.reactComponentProps.options, this.view.state, this.getPos());
94
+ const isTableResizing = (_tableWidthPluginKey$ = tableWidthPluginKey.getState(this.view.state)) === null || _tableWidthPluginKey$ === void 0 ? void 0 : _tableWidthPluginKey$.resizing;
95
+ if (!isTableResizing && tableInlineWidth) {
96
+ handleInlineTableWidth(this.table, tableInlineWidth);
97
+ }
95
98
  }
96
99
  }
97
100
  render(props, forwardRef) {
@@ -141,6 +144,7 @@ export default class TableView extends ReactNodeView {
141
144
  },
142
145
  editorView: props.view,
143
146
  render: pluginStates => {
147
+ var _props$options;
144
148
  const {
145
149
  tableResizingPluginState,
146
150
  tableWidthPluginState,
@@ -174,7 +178,8 @@ export default class TableView extends ReactNodeView {
174
178
  isHeaderRowEnabled: pluginState.isHeaderRowEnabled,
175
179
  isHeaderColumnEnabled: pluginState.isHeaderColumnEnabled,
176
180
  isDragAndDropEnabled: pluginState.isDragAndDropEnabled,
177
- isTableScalingEnabled: pluginState.isTableScalingEnabled,
181
+ isTableScalingEnabled: (_props$options = props.options) === null || _props$options === void 0 ? void 0 : _props$options.isTableScalingEnabled // this.options?.isTableScalingEnabled sams as TableOptions.isTableScalingEnabled same as pluginState.isTableScalingEnabled
182
+ ,
178
183
  tableActive: tableActive,
179
184
  ordering: pluginState.ordering,
180
185
  isResizing: isResizing,
@@ -251,7 +256,7 @@ export const createTableView = (node, view, getPos, portalProviderAPI, eventDisp
251
256
  wasFullWidthModeEnabled,
252
257
  isTableResizingEnabled,
253
258
  isDragAndDropEnabled,
254
- isTableScalingEnabled
259
+ isTableScalingEnabled // same as options.isTableScalingEnabled
255
260
  } = getPluginState(view.state);
256
261
  const {
257
262
  allowColumnResizing,
@@ -271,7 +276,7 @@ export const createTableView = (node, view, getPos, portalProviderAPI, eventDisp
271
276
  wasFullWidthModeEnabled,
272
277
  isTableResizingEnabled,
273
278
  isDragAndDropEnabled,
274
- isTableScalingEnabled
279
+ isTableScalingEnabled // same as options.isTableScalingEnabled
275
280
  },
276
281
  getEditorContainerWidth,
277
282
  getEditorFeatureFlags,
@@ -151,14 +151,15 @@ const tablesPlugin = ({
151
151
  const {
152
152
  fullWidthEnabled,
153
153
  tableOptions,
154
- getEditorFeatureFlags
154
+ getEditorFeatureFlags,
155
+ isTableScalingEnabled
155
156
  } = options || {};
156
157
  const {
157
158
  allowColumnResizing
158
159
  } = pluginConfig(tableOptions);
159
160
  return allowColumnResizing ? createFlexiResizingPlugin(dispatch, {
160
161
  lastColumnResizable: !fullWidthEnabled
161
- }, defaultGetEditorContainerWidth, getEditorFeatureFlags || defaultGetEditorFeatureFlags, editorAnalyticsAPI) : undefined;
162
+ }, defaultGetEditorContainerWidth, getEditorFeatureFlags || defaultGetEditorFeatureFlags, editorAnalyticsAPI, isTableScalingEnabled || false) : undefined;
162
163
  }
163
164
  }, {
164
165
  name: 'tableEditing',
@@ -234,8 +235,8 @@ const tablesPlugin = ({
234
235
  dispatchAnalyticsEvent,
235
236
  dispatch
236
237
  }) => {
237
- var _options$fullWidthEna;
238
- return options !== null && options !== void 0 && options.tableResizingEnabled ? createTableWidthPlugin(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false) : undefined;
238
+ var _options$fullWidthEna, _options$isTableScali;
239
+ return options !== null && options !== void 0 && options.tableResizingEnabled ? createTableWidthPlugin(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false, (_options$isTableScali = options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) !== null && _options$isTableScali !== void 0 ? _options$isTableScali : false) : undefined;
239
240
  }
240
241
  },
241
242
  // TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
@@ -380,7 +381,8 @@ const tablesPlugin = ({
380
381
  getEditorContainerWidth: defaultGetEditorContainerWidth,
381
382
  editorAnalyticsAPI: editorAnalyticsAPI,
382
383
  stickyHeaders: stickyHeader,
383
- pluginConfig: pluginConfig
384
+ pluginConfig: pluginConfig,
385
+ isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled
384
386
  }), allowControls && !isDragAndDropEnabled && !isResizing && /*#__PURE__*/React.createElement(FloatingDeleteButton, {
385
387
  editorView: editorView,
386
388
  selection: editorView.state.selection,
@@ -410,10 +412,7 @@ const tablesPlugin = ({
410
412
  var _api$table;
411
413
  // see comment on tablesPlugin.getSharedState on usage
412
414
  const tableState = api === null || api === void 0 ? void 0 : (_api$table = api.table) === null || _api$table === void 0 ? void 0 : _api$table.sharedState.currentState();
413
- const {
414
- isTableScalingEnabled = false
415
- } = getPluginState(state);
416
- const tr = insert(createTableWithWidth(isTableScalingEnabled, tableState === null || tableState === void 0 ? void 0 : tableState.isFullWidthModeEnabled)(state.schema));
415
+ const tr = insert(createTableWithWidth(options === null || options === void 0 ? void 0 : options.isTableScalingEnabled, tableState === null || tableState === void 0 ? void 0 : tableState.isFullWidthModeEnabled)(state.schema));
417
416
  editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
418
417
  action: ACTION.INSERTED,
419
418
  actionSubject: ACTION_SUBJECT.DOCUMENT,
@@ -3,6 +3,7 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
4
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
5
5
  import { getCellsInRow, getSelectedCellInfo } from '@atlaskit/editor-tables/utils';
6
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
6
7
  import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element';
7
8
  import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
8
9
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
@@ -170,7 +171,11 @@ const destroyFn = (editorView, editorAnalyticsAPI) => {
170
171
  const {
171
172
  isTableScalingEnabled = false
172
173
  } = getTablePluginState(editorView.state);
173
- insertColgroupFromNode(tableRef, tableNode, isTableScalingEnabled);
174
+ let isTableScalingEnabledOnCurrentTable = isTableScalingEnabled;
175
+ if (isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')) {
176
+ isTableScalingEnabledOnCurrentTable = tableNode.attrs.displayMode !== 'fixed';
177
+ }
178
+ insertColgroupFromNode(tableRef, tableNode, isTableScalingEnabledOnCurrentTable);
174
179
  }
175
180
  }
176
181
  editorView.focus();
@@ -12,16 +12,13 @@ import { META_KEYS } from '../table-analytics';
12
12
  import { evenColumns, setDragging, stopResizing } from './commands';
13
13
  import { getPluginState } from './plugin-factory';
14
14
  import { currentColWidth, getResizeState, getTableMaxWidth, pointsAtCell, resizeColumn, updateControls } from './utils';
15
- export const handleMouseDown = (view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, editorAnalyticsAPI) => {
15
+ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled, editorAnalyticsAPI) => {
16
16
  const {
17
17
  state,
18
18
  dispatch
19
19
  } = view;
20
20
  const editorDisabled = !view.editable;
21
21
  const domAtPos = view.domAtPos.bind(view);
22
- const {
23
- isTableScalingEnabled = false
24
- } = getTablePluginState(state);
25
22
  if (editorDisabled || localResizeHandlePos === null || !pointsAtCell(state.doc.resolve(localResizeHandlePos))) {
26
23
  return false;
27
24
  }
@@ -52,7 +49,10 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
52
49
  layout: originalTable.attrs.layout,
53
50
  getEditorContainerWidth
54
51
  });
55
- const shouldScale = tableDepth === 0 && isTableScalingEnabled;
52
+ let shouldScale = tableDepth === 0 && isTableScalingEnabled;
53
+ if (isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')) {
54
+ shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
55
+ }
56
56
  const resizeState = getResizeState({
57
57
  minWidth: tableCellMinWidth,
58
58
  maxSize,
@@ -144,7 +144,10 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
144
144
  const selectedColumns = selectionRect ? getSelectedColumnIndexes(selectionRect) : [];
145
145
  // only selected (or selected - 1) columns should be distributed
146
146
  const resizingSelectedColumns = selectedColumns.indexOf(colIndex) > -1 || selectedColumns.indexOf(colIndex + 1) > -1;
147
- const shouldScale = tableDepth === 0 && isTableScalingEnabled;
147
+ let shouldScale = tableDepth === 0 && isTableScalingEnabled;
148
+ if (isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')) {
149
+ shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
150
+ }
148
151
  const newResizeState = resizeColumn(resizeState, colIndex, clientX - startX, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, shouldScale);
149
152
  const resizedDelta = clientX - startX;
150
153
  tr = updateColumnWidths(newResizeState, table, start)(tr);
@@ -221,7 +224,10 @@ export const handleMouseDown = (view, event, localResizeHandlePos, getEditorCont
221
224
  const tableDepth = state.doc.resolve(tablePos).depth;
222
225
  const map = TableMap.get(table);
223
226
  const colIndex = map.colCount($cell.pos - $cell.start(-1)) + $cell.nodeAfter.attrs.colspan - 1;
224
- const shouldScale = tableDepth === 0 && isTableScalingEnabled;
227
+ let shouldScale = tableDepth === 0 && isTableScalingEnabled;
228
+ if (isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')) {
229
+ shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
230
+ }
225
231
  resizeColumn(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale);
226
232
  updateControls()(state);
227
233
  }
@@ -10,7 +10,7 @@ import { pluginKey } from './plugin-key';
10
10
  import { getResizeCellPos } from './utils';
11
11
  export function createPlugin(dispatch, {
12
12
  lastColumnResizable = true
13
- }, getEditorContainerWidth, getEditorFeatureFlags, editorAnalyticsAPI) {
13
+ }, getEditorContainerWidth, getEditorFeatureFlags, editorAnalyticsAPI, isTableScalingEnabled) {
14
14
  return new SafePlugin({
15
15
  key: pluginKey,
16
16
  state: createPluginState(dispatch, {
@@ -54,7 +54,7 @@ export function createPlugin(dispatch, {
54
54
  }
55
55
  }
56
56
  if (resizeHandlePos !== null && (!dragging || isColumnKeyboardResizeStarted)) {
57
- if (handleMouseDown(view, event, resizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, editorAnalyticsAPI)) {
57
+ if (handleMouseDown(view, event, resizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled || false, editorAnalyticsAPI)) {
58
58
  const {
59
59
  state,
60
60
  dispatch
@@ -304,14 +304,19 @@ export const getNewResizeStateFromSelectedColumns = (rect, state, domAtPos, getE
304
304
  layout,
305
305
  getEditorContainerWidth
306
306
  });
307
- const resizeState = getResizeState({
307
+ let resizeState;
308
+ let isTableScalingEnabledOnCurrentTable = isTableScalingEnabled;
309
+ if (isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')) {
310
+ isTableScalingEnabledOnCurrentTable = table.node.attrs.displayMode !== 'fixed';
311
+ }
312
+ resizeState = getResizeState({
308
313
  minWidth: tableCellMinWidth,
309
314
  maxSize,
310
315
  table: table.node,
311
316
  tableRef,
312
317
  start: table.start,
313
318
  domAtPos,
314
- isTableScalingEnabled
319
+ isTableScalingEnabled: isTableScalingEnabledOnCurrentTable
315
320
  });
316
321
  const newResizeState = evenSelectedColumnsWidths(resizeState, rect);
317
322
  const widthsBefore = resizeState.widths;
@@ -1,6 +1,7 @@
1
1
  import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
2
2
  import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
3
3
  import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
4
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
4
5
  import { updateColumnWidths } from '../../../transforms';
5
6
  import { getTableWidth } from '../../../utils';
6
7
  import { getLayoutSize } from '../utils/misc';
@@ -10,7 +11,7 @@ import { hasTableBeenResized, insertColgroupFromNode } from './colgroup';
10
11
  import { syncStickyRowToTable } from './dom';
11
12
  // Base function to trigger the actual scale on a table node.
12
13
  // Will only resize/scale if a table has been previously resized.
13
- export const scale = (tableRef, options, domAtPos, isTableScalingEnabled = false) => {
14
+ export const scale = (tableRef, options, domAtPos, isTableScalingEnabledOnCurrentTable = false) => {
14
15
  const {
15
16
  node,
16
17
  containerWidth,
@@ -48,11 +49,11 @@ export const scale = (tableRef, options, domAtPos, isTableScalingEnabled = false
48
49
  tableRef,
49
50
  start,
50
51
  domAtPos,
51
- isTableScalingEnabled
52
+ isTableScalingEnabled: isTableScalingEnabledOnCurrentTable
52
53
  });
53
54
  return scaleTableTo(resizeState, newWidth);
54
55
  };
55
- export const scaleWithParent = (tableRef, parentWidth, table, start, domAtPos, isTableScalingEnabled = false) => {
56
+ export const scaleWithParent = (tableRef, parentWidth, table, start, domAtPos, isTableScalingEnabledOnCurrentTable = false) => {
56
57
  const resizeState = getResizeState({
57
58
  minWidth: tableCellMinWidth,
58
59
  maxSize: parentWidth,
@@ -60,7 +61,7 @@ export const scaleWithParent = (tableRef, parentWidth, table, start, domAtPos, i
60
61
  tableRef,
61
62
  start,
62
63
  domAtPos,
63
- isTableScalingEnabled
64
+ isTableScalingEnabled: isTableScalingEnabledOnCurrentTable
64
65
  });
65
66
  if (table.attrs.isNumberColumnEnabled) {
66
67
  parentWidth -= akEditorTableNumberColumnWidth;
@@ -109,21 +110,25 @@ export const previewScaleTable = (tableRef, options, domAtPos, isTableScalingEna
109
110
  const width = isNumberColumnEnabled ? parentWidth - akEditorTableNumberColumnWidth : parentWidth;
110
111
  tableRef.style.width = `${width}px`;
111
112
  }
112
-
113
+ let isTableScalingEnabledOnCurrentTable = isTableScalingEnabled;
114
+ if (isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')) {
115
+ isTableScalingEnabledOnCurrentTable = isTableScalingEnabled && node.attrs.displayMode !== 'fixed';
116
+ }
113
117
  // If the table hasn't been resize, the colgroup 48px width values will gracefully scale down.
114
118
  // If we are scaling the table down with isTableScalingEnabled, the colgroup widths may be scaled to a value that is not 48px.
115
- if (!hasTableBeenResized(node) && !isTableScalingEnabled) {
119
+ if (!hasTableBeenResized(node) && !isTableScalingEnabledOnCurrentTable) {
116
120
  syncStickyRowToTable(tableRef);
117
121
  return;
118
122
  }
119
- const resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos, false) : scale(tableRef, options, domAtPos, false);
123
+ const resizeState = parentWidth ? scaleWithParent(tableRef, parentWidth, node, start, domAtPos, false) // Here last value is isTableScalingEnabled = false
124
+ : scale(tableRef, options, domAtPos, false);
120
125
  if (resizeState) {
121
126
  updateColgroup(resizeState, tableRef, node, false);
122
127
  }
123
128
  };
124
129
 
125
130
  // Scale the table to meet new requirements (col, layout change etc)
126
- export const scaleTable = (tableRef, options, domAtPos, isTableScalingEnabled = false) => tr => {
131
+ export const scaleTable = (tableRef, options, domAtPos, isTableScalingEnabledOnCurrentTable = false) => tr => {
127
132
  if (!tableRef) {
128
133
  return tr;
129
134
  }
@@ -137,7 +142,7 @@ export const scaleTable = (tableRef, options, domAtPos, isTableScalingEnabled =
137
142
  if (hasTableBeenResized(node) === false) {
138
143
  // If its not a re-sized table, we still want to re-create cols
139
144
  // To force reflow of columns upon delete.
140
- if (!isTableScalingEnabled) {
145
+ if (!isTableScalingEnabledOnCurrentTable) {
141
146
  insertColgroupFromNode(tableRef, node);
142
147
  }
143
148
  tr.setMeta('scrollIntoView', false);
@@ -145,9 +150,9 @@ export const scaleTable = (tableRef, options, domAtPos, isTableScalingEnabled =
145
150
  }
146
151
  let resizeState;
147
152
  if (parentWidth) {
148
- resizeState = scaleWithParent(tableRef, parentWidth, node, start, domAtPos, isTableScalingEnabled);
153
+ resizeState = scaleWithParent(tableRef, parentWidth, node, start, domAtPos, isTableScalingEnabledOnCurrentTable);
149
154
  } else {
150
- resizeState = scale(tableRef, options, domAtPos, isTableScalingEnabled);
155
+ resizeState = scale(tableRef, options, domAtPos, isTableScalingEnabledOnCurrentTable);
151
156
  }
152
157
  if (resizeState) {
153
158
  tr = updateColumnWidths(resizeState, node, start)(tr);
@@ -11,10 +11,9 @@ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
11
11
  import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
12
12
  import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorWideLayoutWidth } from '@atlaskit/editor-shared-styles';
13
13
  import { findTable } from '@atlaskit/editor-tables/utils';
14
- import { getPluginState } from './plugin-factory';
15
14
  import { TABLE_MAX_WIDTH } from './table-resizing/utils';
16
15
  export const pluginKey = new PluginKey('tableWidthPlugin');
17
- const createPlugin = (dispatch, dispatchAnalyticsEvent, fullWidthEnabled) => {
16
+ const createPlugin = (dispatch, dispatchAnalyticsEvent, fullWidthEnabled, isTableScalingEnabled) => {
18
17
  return new SafePlugin({
19
18
  key: pluginKey,
20
19
  state: {
@@ -79,9 +78,6 @@ const createPlugin = (dispatch, dispatchAnalyticsEvent, fullWidthEnabled) => {
79
78
  return hasStepReplacingEntireDocument;
80
79
  });
81
80
  const referentialityTr = transactions.find(tr => tr.getMeta('referentialityTableInserted'));
82
- const {
83
- isTableScalingEnabled = false
84
- } = getPluginState(newState);
85
81
  const shouldPatchTable = fullWidthEnabled && isTableScalingEnabled;
86
82
  if (!isReplaceDocumentOperation && (!shouldPatchTable || !referentialityTr)) {
87
83
  return null;
@@ -1,4 +1,5 @@
1
1
  import { SortOrder } from '@atlaskit/editor-common/types';
2
+ import { convertProsemirrorTableNodeToArrayOfRows, createCompareNodes } from '@atlaskit/editor-common/utils';
2
3
  import { IS_DISABLED_CLASS_NAME, SORT_INDEX_DATA_ATTRIBUTE, SORTING_ICON_CLASS_NAME } from './consts';
3
4
  export const unsort = (oldOrder, tableElement) => {
4
5
  const rows = tableElement.querySelectorAll('tr');
@@ -8,42 +9,56 @@ export const unsort = (oldOrder, tableElement) => {
8
9
  tbody === null || tbody === void 0 ? void 0 : tbody.appendChild(rows[item.index + 1]);
9
10
  });
10
11
  };
12
+ export const getSortOrderFromTable = (tableNode, sortIndex, direction) => {
13
+ const tableArray = convertProsemirrorTableNodeToArrayOfRows(tableNode);
14
+ tableArray.shift(); // remove header row
11
15
 
12
- // TODO - reuse sort logic from the Renderer and support switching between ASC, DESC and NO_ORDER
13
- export const getSortOrderFromTable = (tableElement, sortIndex, direction) => {
14
- const sortOrder = direction === SortOrder.DESC ? -1 : 1;
15
- const strings = [];
16
- tableElement.querySelectorAll('tr:not([data-header-row="true"])').forEach(tr => {
17
- var _tr$querySelectorAll$;
18
- strings.push(((_tr$querySelectorAll$ = tr.querySelectorAll('td')[sortIndex]) === null || _tr$querySelectorAll$ === void 0 ? void 0 : _tr$querySelectorAll$.textContent) || '');
19
- });
20
- const order = Array.from(strings.keys()).sort((a, b) => {
21
- const string = strings[a] || '';
22
- return string.localeCompare(strings[b] || '') * sortOrder;
23
- }).map((value, index) => ({
24
- value,
16
+ // Keep track of the origin row index
17
+ const tableArrayWithIndex = tableArray.map((node, index) => ({
18
+ node,
19
+ originalIndex: index
20
+ }));
21
+ const compareNodesInOrder = createCompareNodes({
22
+ // TODO - add inline card support
23
+ getInlineCardTextFromStore() {
24
+ return null;
25
+ }
26
+ }, direction);
27
+ const order = tableArrayWithIndex.sort((a, b) => {
28
+ return compareNodesInOrder(a.node[sortIndex], b.node[sortIndex]);
29
+ }).map((tableRow, index) => ({
30
+ value: tableRow.originalIndex,
25
31
  index
26
32
  }));
27
- // TODO - improve this. right now this is a workaround to ensure the first tr is always first in the order
28
- return [{
33
+ return [
34
+ // Ensures the first tr is always first in the order
35
+ {
29
36
  value: -1,
30
37
  index: -1
31
38
  }, ...order];
32
39
  };
33
40
  export const toggleSort = (view, event, pluginState) => {
34
- var _target$closest;
41
+ var _target$closest, _tableNode$type;
35
42
  const target = event.target;
43
+ if (!(target instanceof HTMLElement)) {
44
+ return;
45
+ }
36
46
  const widget = target.closest(`.${SORTING_ICON_CLASS_NAME}`);
37
47
  if (widget !== null && widget !== void 0 && widget.classList.contains(IS_DISABLED_CLASS_NAME) || !widget) {
38
48
  return;
39
49
  }
40
- let datasetortIndex = target === null || target === void 0 ? void 0 : (_target$closest = target.closest('.ProseMirror-widget')) === null || _target$closest === void 0 ? void 0 : _target$closest.getAttribute(SORT_INDEX_DATA_ATTRIBUTE);
50
+ let dataSortIndex = target === null || target === void 0 ? void 0 : (_target$closest = target.closest('.ProseMirror-widget')) === null || _target$closest === void 0 ? void 0 : _target$closest.getAttribute(SORT_INDEX_DATA_ATTRIBUTE);
41
51
  const tr = view.state.tr;
42
52
  const tableElement = target.closest('table');
43
- if (!tableElement || !datasetortIndex) {
53
+ if (!tableElement || !dataSortIndex) {
54
+ return;
55
+ }
56
+ const tablePos = view.posAtDOM(tableElement, 0);
57
+ const tableNode = view.state.doc.nodeAt(tablePos - 1);
58
+ const tableId = tableNode === null || tableNode === void 0 ? void 0 : tableNode.attrs.localId;
59
+ if (!tableId || !tableNode || (tableNode === null || tableNode === void 0 ? void 0 : (_tableNode$type = tableNode.type) === null || _tableNode$type === void 0 ? void 0 : _tableNode$type.name) !== 'table') {
44
60
  return;
45
61
  }
46
- const tableId = tableElement.getAttribute('data-table-local-id') || '';
47
62
  let {
48
63
  index,
49
64
  direction,
@@ -54,7 +69,7 @@ export const toggleSort = (view, event, pluginState) => {
54
69
  if (direction !== SortOrder.NO_ORDER && oldOrder !== undefined) {
55
70
  unsort(oldOrder, tableElement);
56
71
  }
57
- const sortIndex = parseInt(datasetortIndex);
72
+ const sortIndex = parseInt(dataSortIndex);
58
73
  if (sortIndex === index) {
59
74
  switch (direction) {
60
75
  case SortOrder.NO_ORDER:
@@ -70,7 +85,7 @@ export const toggleSort = (view, event, pluginState) => {
70
85
  } else {
71
86
  direction = SortOrder.ASC; // default direction when a new index is clicked
72
87
  }
73
- const order = getSortOrderFromTable(tableElement, sortIndex, direction);
88
+ const order = getSortOrderFromTable(tableNode, sortIndex, direction);
74
89
  if (direction === SortOrder.NO_ORDER) {
75
90
  tr.setMeta('tableSortMeta', {
76
91
  [tableId]: {}
@@ -311,13 +311,10 @@ export const getToolbarConfig = (getEditorContainerWidth, editorAnalyticsAPI, ge
311
311
  // We don't want to show floating toolbar while resizing the table
312
312
  const isWidthResizing = tableWidthState === null || tableWidthState === void 0 ? void 0 : tableWidthState.resizing;
313
313
  const {
314
- isTableScalingEnabled,
315
314
  widthToWidest
316
315
  } = pluginState;
317
316
  const currentTableNodeLocalId = (_tableObject$node$att = tableObject === null || tableObject === void 0 ? void 0 : (_tableObject$node = tableObject.node) === null || _tableObject$node === void 0 ? void 0 : (_tableObject$node$att2 = _tableObject$node.attrs) === null || _tableObject$node$att2 === void 0 ? void 0 : _tableObject$node$att2.localId) !== null && _tableObject$node$att !== void 0 ? _tableObject$node$att : '';
318
- if (isTableScalingEnabled &&
319
- // TODO ED-21670: check if need options.isTableScalingEnabled
320
- isWidthResizing && widthToWidest && currentTableNodeLocalId && widthToWidest[currentTableNodeLocalId]) {
317
+ if (options !== null && options !== void 0 && options.isTableScalingEnabled && isWidthResizing && widthToWidest && currentTableNodeLocalId && widthToWidest[currentTableNodeLocalId]) {
321
318
  const {
322
319
  stickyScrollbar
323
320
  } = getEditorFeatureFlags();
@@ -364,14 +361,10 @@ export const getToolbarConfig = (getEditorContainerWidth, editorAnalyticsAPI, ge
364
361
  if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
365
362
  const nodeType = state.schema.nodes.table;
366
363
  const menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
367
- const {
368
- isTableScalingEnabled = false
369
- } = getPluginState(state); // TODO ED-21670: check if we need options.isTableScalingEnabled and not an acutual state of displayNode attr on the table
370
-
371
364
  let cellItems;
372
- cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, isTableScalingEnabled);
365
+ cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled);
373
366
  let columnSettingsItems;
374
- columnSettingsItems = pluginState.isDragAndDropEnabled ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, options, isTableScalingEnabled) : [];
367
+ columnSettingsItems = pluginState.isDragAndDropEnabled ? getColumnSettingItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) : [];
375
368
  const colorPicker = getColorPicker(state, menu, intl, editorAnalyticsAPI, getEditorView);
376
369
 
377
370
  // Check if we need to show confirm dialog for delete button
@@ -489,18 +482,17 @@ export const getDistributeConfig = (getEditorContainerWidth, editorAnalyticsAPI,
489
482
  // fixed column button should be in this function call in the future
490
483
  const getColumnSettingItems = (editorState, editorView, {
491
484
  formatMessage
492
- }, getEditorContainerWidth, editorAnalyticsAPI, options, isTableScalingEnabled = false) => {
485
+ }, getEditorContainerWidth, editorAnalyticsAPI, isTableScalingEnabled = false) => {
493
486
  var _newResizeStateWithAn2, _pluginState$pluginCo3;
494
487
  const pluginState = getPluginState(editorState);
495
488
  const selectionOrTableRect = getClosestSelectionOrTableRect(editorState);
496
489
  if (!selectionOrTableRect || !editorView) {
497
490
  return [];
498
491
  }
499
- const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth, isTableScalingEnabled // TODO ED-21670: Here should be actual state of tableNode's displayMode attr
500
- );
492
+ const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(selectionOrTableRect, editorState, editorView.domAtPos.bind(editorView), getEditorContainerWidth, isTableScalingEnabled);
501
493
  const wouldChange = (_newResizeStateWithAn2 = newResizeStateWithAnalytics === null || newResizeStateWithAnalytics === void 0 ? void 0 : newResizeStateWithAnalytics.changed) !== null && _newResizeStateWithAn2 !== void 0 ? _newResizeStateWithAn2 : false;
502
494
  const items = [];
503
- const isTableScalingLockBtnEnabled = (options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button');
495
+ const isTableScalingLockBtnEnabled = isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button');
504
496
  if (isTableScalingLockBtnEnabled) {
505
497
  var _pluginState$tableNod;
506
498
  const areColumnWidthsLocked = (pluginState === null || pluginState === void 0 ? void 0 : (_pluginState$tableNod = pluginState.tableNode) === null || _pluginState$tableNod === void 0 ? void 0 : _pluginState$tableNod.attrs.displayMode) === 'fixed';
@@ -524,8 +516,7 @@ const getColumnSettingItems = (editorState, editorView, {
524
516
  type: 'button',
525
517
  title: formatMessage(messages.distributeColumns),
526
518
  icon: DistributeColumnIcon,
527
- onClick: (state, dispatch, view) => getDistributeConfig(getEditorContainerWidth, editorAnalyticsAPI, isTableScalingEnabled // TODO ED-21670: Maybe here too we an actual state of tableNode's displayMode attr
528
- )(state, dispatch, view),
519
+ onClick: (state, dispatch, view) => getDistributeConfig(getEditorContainerWidth, editorAnalyticsAPI, isTableScalingEnabled)(state, dispatch, view),
529
520
  disabled: !wouldChange
530
521
  });
531
522
  }
@@ -107,7 +107,10 @@ export const rescaleColumns = (isTableScalingEnabled = false) => (table, view) =
107
107
  isResized
108
108
  };
109
109
  const tableDepth = view.state.doc.resolve(table.pos).depth;
110
- const shouldScale = isTableScalingEnabled && tableDepth === 0;
110
+ let shouldScale = isTableScalingEnabled && tableDepth === 0;
111
+ if (shouldScale && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')) {
112
+ shouldScale = newTable.attrs.displayMode !== 'fixed';
113
+ }
111
114
  if (shouldScale) {
112
115
  previousTableInfo = {
113
116
  width: getTableElementWidth(table.node),