@atlaskit/editor-plugin-table 22.4.14 → 22.4.15

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 (69) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/nodeviews/TableComponent.js +2 -2
  3. package/dist/cjs/nodeviews/table.js +2 -2
  4. package/dist/cjs/nodeviews/toDOM.js +2 -2
  5. package/dist/cjs/pm-plugins/main.js +4 -3
  6. package/dist/cjs/pm-plugins/table-width.js +2 -2
  7. package/dist/cjs/pm-plugins/transforms/content-mode.js +3 -2
  8. package/dist/cjs/pm-plugins/utils/tableMode/apply-measured-width-to-all-tables.js +70 -0
  9. package/dist/cjs/pm-plugins/utils/tableMode/apply-measured-width-to-selected-table.js +41 -0
  10. package/dist/cjs/pm-plugins/utils/tableMode/is-content-mode-supported.js +12 -0
  11. package/dist/cjs/pm-plugins/utils/tableMode/measure-table-with-auto-layout.js +113 -0
  12. package/dist/cjs/pm-plugins/utils/tableMode/smart-adjust/constants.js +10 -0
  13. package/dist/cjs/pm-plugins/utils/tableMode/smart-adjust/distribute-column-widths.js +83 -0
  14. package/dist/cjs/pm-plugins/utils/tableMode/smart-adjust/run-smart-adjust.js +56 -0
  15. package/dist/cjs/ui/toolbar.js +4 -3
  16. package/dist/es2019/nodeviews/TableComponent.js +1 -1
  17. package/dist/es2019/nodeviews/table.js +1 -1
  18. package/dist/es2019/nodeviews/toDOM.js +1 -1
  19. package/dist/es2019/pm-plugins/main.js +2 -1
  20. package/dist/es2019/pm-plugins/table-width.js +1 -1
  21. package/dist/es2019/pm-plugins/transforms/content-mode.js +2 -1
  22. package/dist/es2019/pm-plugins/utils/tableMode/apply-measured-width-to-all-tables.js +70 -0
  23. package/dist/es2019/pm-plugins/utils/tableMode/apply-measured-width-to-selected-table.js +38 -0
  24. package/dist/es2019/pm-plugins/utils/tableMode/is-content-mode-supported.js +7 -0
  25. package/dist/es2019/pm-plugins/utils/tableMode/measure-table-with-auto-layout.js +97 -0
  26. package/dist/es2019/pm-plugins/utils/tableMode/smart-adjust/constants.js +4 -0
  27. package/dist/es2019/pm-plugins/utils/tableMode/smart-adjust/distribute-column-widths.js +63 -0
  28. package/dist/es2019/pm-plugins/utils/tableMode/smart-adjust/run-smart-adjust.js +47 -0
  29. package/dist/es2019/ui/toolbar.js +2 -1
  30. package/dist/esm/nodeviews/TableComponent.js +1 -1
  31. package/dist/esm/nodeviews/table.js +1 -1
  32. package/dist/esm/nodeviews/toDOM.js +1 -1
  33. package/dist/esm/pm-plugins/main.js +2 -1
  34. package/dist/esm/pm-plugins/table-width.js +1 -1
  35. package/dist/esm/pm-plugins/transforms/content-mode.js +2 -1
  36. package/dist/esm/pm-plugins/utils/tableMode/apply-measured-width-to-all-tables.js +65 -0
  37. package/dist/esm/pm-plugins/utils/tableMode/apply-measured-width-to-selected-table.js +36 -0
  38. package/dist/esm/pm-plugins/utils/tableMode/is-content-mode-supported.js +6 -0
  39. package/dist/esm/pm-plugins/utils/tableMode/measure-table-with-auto-layout.js +107 -0
  40. package/dist/esm/pm-plugins/utils/tableMode/smart-adjust/constants.js +4 -0
  41. package/dist/esm/pm-plugins/utils/tableMode/smart-adjust/distribute-column-widths.js +77 -0
  42. package/dist/esm/pm-plugins/utils/tableMode/smart-adjust/run-smart-adjust.js +49 -0
  43. package/dist/esm/ui/toolbar.js +2 -1
  44. package/dist/types/pm-plugins/transforms/content-mode.d.ts +1 -0
  45. package/dist/types/pm-plugins/utils/tableMode/apply-measured-width-to-all-tables.d.ts +8 -0
  46. package/dist/types/pm-plugins/utils/tableMode/apply-measured-width-to-selected-table.d.ts +6 -0
  47. package/dist/types/pm-plugins/utils/tableMode/is-content-mode-supported.d.ts +7 -0
  48. package/dist/types/pm-plugins/utils/tableMode/measure-table-with-auto-layout.d.ts +2 -0
  49. package/dist/types/pm-plugins/utils/tableMode/smart-adjust/constants.d.ts +4 -0
  50. package/dist/types/pm-plugins/utils/tableMode/smart-adjust/distribute-column-widths.d.ts +8 -0
  51. package/dist/types/pm-plugins/utils/tableMode/smart-adjust/run-smart-adjust.d.ts +7 -0
  52. package/dist/types/ui/TableMenu/column/getColumnMenuComponents.d.ts +1 -1
  53. package/dist/types/ui/TableMenu/column/items/DistributeColumnsItem.d.ts +1 -1
  54. package/dist/types-ts4.5/pm-plugins/transforms/content-mode.d.ts +1 -0
  55. package/dist/types-ts4.5/pm-plugins/utils/tableMode/apply-measured-width-to-all-tables.d.ts +8 -0
  56. package/dist/types-ts4.5/pm-plugins/utils/tableMode/apply-measured-width-to-selected-table.d.ts +6 -0
  57. package/dist/types-ts4.5/pm-plugins/utils/tableMode/is-content-mode-supported.d.ts +7 -0
  58. package/dist/types-ts4.5/pm-plugins/utils/tableMode/measure-table-with-auto-layout.d.ts +2 -0
  59. package/dist/types-ts4.5/pm-plugins/utils/tableMode/smart-adjust/constants.d.ts +4 -0
  60. package/dist/types-ts4.5/pm-plugins/utils/tableMode/smart-adjust/distribute-column-widths.d.ts +8 -0
  61. package/dist/types-ts4.5/pm-plugins/utils/tableMode/smart-adjust/run-smart-adjust.d.ts +7 -0
  62. package/dist/types-ts4.5/ui/TableMenu/column/getColumnMenuComponents.d.ts +1 -1
  63. package/dist/types-ts4.5/ui/TableMenu/column/items/DistributeColumnsItem.d.ts +1 -1
  64. package/package.json +10 -7
  65. package/dist/cjs/pm-plugins/utils/tableMode.js +0 -162
  66. package/dist/es2019/pm-plugins/utils/tableMode.js +0 -158
  67. package/dist/esm/pm-plugins/utils/tableMode.js +0 -156
  68. package/dist/types/pm-plugins/utils/tableMode.d.ts +0 -26
  69. package/dist/types-ts4.5/pm-plugins/utils/tableMode.d.ts +0 -26
@@ -0,0 +1,77 @@
1
+ import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
2
+ import { akEditorGutterPaddingDynamic } from '@atlaskit/editor-shared-styles';
3
+ import { EVEN_SHARE_RATIO } from './constants';
4
+ export var sumWidths = function sumWidths(widths) {
5
+ return widths.reduce(function (sum, width) {
6
+ return sum + width;
7
+ }, 0);
8
+ };
9
+
10
+ // 2px absorbs sub-pixel rounding in `getRenderedColgroupColumnWidths`.
11
+ var SUB_PIXEL_ROUNDING_ALLOWANCE = 2;
12
+
13
+ /**
14
+ * Clamps each desired width to `[tableCellMinWidth, MAX × evenShare]`. Greedy
15
+ * columns (paragraphs) hit the ceiling and wrap; small columns stay at their
16
+ * natural width. Leftover canvas budget grows ceiling-hitters up to their
17
+ * desired; overflow reclaims from ceiling-hitters only.
18
+ */
19
+ export var distributeByEvenShareRatio = function distributeByEvenShareRatio(desiredWidths, editorContainerWidth) {
20
+ if (desiredWidths.length === 0 || !isFinite(editorContainerWidth) || editorContainerWidth <= 0) {
21
+ return desiredWidths;
22
+ }
23
+ var usableWidth = Math.max(editorContainerWidth - akEditorGutterPaddingDynamic() * 2, tableCellMinWidth * desiredWidths.length);
24
+ var evenShare = usableWidth / desiredWidths.length;
25
+ var ceiling = EVEN_SHARE_RATIO.MAX * evenShare;
26
+ var isCompactColumn = function isCompactColumn(width) {
27
+ return width <= ceiling;
28
+ };
29
+ var desiredCeil = desiredWidths.map(function (desired) {
30
+ return Math.max(tableCellMinWidth, Math.ceil(desired) + SUB_PIXEL_ROUNDING_ALLOWANCE);
31
+ });
32
+ var capped = desiredCeil.map(function (desired) {
33
+ return isCompactColumn(desired) ? desired : Math.min(ceiling, desired);
34
+ });
35
+ var sum = sumWidths(capped);
36
+
37
+ // Underflow: grow non-protected ceiling-hitters into the leftover, up to their desired.
38
+ if (sum < usableWidth) {
39
+ var leftover = usableWidth - sum;
40
+ var growthHeadroom = capped.map(function (width, index) {
41
+ return !isCompactColumn(desiredCeil[index]) && width >= ceiling ? Math.max(desiredCeil[index] - width, 0) : 0;
42
+ });
43
+ var totalHeadroom = sumWidths(growthHeadroom);
44
+ if (totalHeadroom > 0) {
45
+ var totalGrowth = Math.min(leftover, totalHeadroom);
46
+ return capped.map(function (width, index) {
47
+ var headroom = growthHeadroom[index];
48
+ if (headroom <= 0) {
49
+ return width;
50
+ }
51
+ return width + headroom / totalHeadroom * totalGrowth;
52
+ });
53
+ }
54
+ return capped;
55
+ }
56
+ if (sum === usableWidth) {
57
+ return capped;
58
+ }
59
+
60
+ // Overflow: reclaim from non-protected ceiling-hitters only.
61
+ var overage = sum - usableWidth;
62
+ var slacks = capped.map(function (width, index) {
63
+ return !isCompactColumn(desiredCeil[index]) && width >= ceiling ? Math.max(width - tableCellMinWidth, 0) : 0;
64
+ });
65
+ var totalSlack = sumWidths(slacks);
66
+ if (totalSlack <= 0) {
67
+ return capped;
68
+ }
69
+ return capped.map(function (width, index) {
70
+ var slack = slacks[index];
71
+ if (slack <= 0) {
72
+ return width;
73
+ }
74
+ var share = slack / totalSlack * Math.min(overage, totalSlack);
75
+ return Math.max(width - share, tableCellMinWidth);
76
+ });
77
+ };
@@ -0,0 +1,49 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ import { getTableMeasurement } from '../../../transforms/content-mode';
5
+ import { distributeByEvenShareRatio, sumWidths } from './distribute-column-widths';
6
+ var measureWithIntrinsicWidth = function measureWithIntrinsicWidth(tableRef, resizerContainer, resizerItem) {
7
+ if (resizerContainer) {
8
+ resizerContainer.style.width = 'var(--ak-editor-table-width)';
9
+ resizerContainer.style.setProperty('--ak-editor-table-width', 'max-content');
10
+ }
11
+ if (resizerItem) {
12
+ resizerItem.style.width = 'max-content';
13
+ }
14
+ var prevTableWidth = tableRef.style.width;
15
+ var prevTableMaxWidth = tableRef.style.maxWidth;
16
+ var prevTableMinWidth = tableRef.style.minWidth;
17
+ tableRef.style.setProperty('width', 'max-content', 'important');
18
+ tableRef.style.setProperty('max-width', 'none', 'important');
19
+ tableRef.style.setProperty('min-width', '0', 'important');
20
+ try {
21
+ return getTableMeasurement(tableRef);
22
+ } finally {
23
+ tableRef.style.width = prevTableWidth;
24
+ tableRef.style.maxWidth = prevTableMaxWidth;
25
+ tableRef.style.minWidth = prevTableMinWidth;
26
+ }
27
+ };
28
+ export var restoreResizerContainer = function restoreResizerContainer(resizerContainer) {
29
+ if (!resizerContainer) {
30
+ return;
31
+ }
32
+ resizerContainer.style.width = 'var(--ak-editor-table-width)';
33
+ resizerContainer.style.removeProperty('--ak-editor-table-width');
34
+ };
35
+
36
+ /**
37
+ * Smart-adjust: measure unconstrained max-content per column, then clamp via
38
+ * `distributeByEvenShareRatio`.
39
+ */
40
+ export var runSmartAdjust = function runSmartAdjust(tableRef, resizerContainer, resizerItem, editorContainerWidthFromApi) {
41
+ var preferredMeasurement = measureWithIntrinsicWidth(tableRef, resizerContainer, resizerItem);
42
+ var desiredWidths = preferredMeasurement.colWidths;
43
+ var editorContainerWidth = editorContainerWidthFromApi !== null && editorContainerWidthFromApi !== void 0 ? editorContainerWidthFromApi : sumWidths(desiredWidths);
44
+ var colWidths = distributeByEvenShareRatio(desiredWidths, editorContainerWidth);
45
+ return _objectSpread(_objectSpread({}, preferredMeasurement), {}, {
46
+ colWidths: colWidths,
47
+ tableWidth: sumWidths(colWidths)
48
+ });
49
+ };
@@ -49,7 +49,8 @@ import { normaliseAlignment } from '../pm-plugins/utils/alignment';
49
49
  import { isTableNested } from '../pm-plugins/utils/nodes';
50
50
  import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../pm-plugins/utils/selection';
51
51
  import { getMergedCellsPositions } from '../pm-plugins/utils/table';
52
- import { applyMeasuredWidthToSelectedTable, isContentModeSupported } from '../pm-plugins/utils/tableMode';
52
+ import { applyMeasuredWidthToSelectedTable } from '../pm-plugins/utils/tableMode/apply-measured-width-to-selected-table';
53
+ import { isContentModeSupported } from '../pm-plugins/utils/tableMode/is-content-mode-supported';
53
54
  import { TableCssClassName } from '../types';
54
55
  import { FloatingAlignmentButtons } from './FloatingAlignmentButtons/FloatingAlignmentButtons';
55
56
  export var getToolbarMenuConfig = function getToolbarMenuConfig(config, state, _ref, editorAnalyticsAPI) {
@@ -4,5 +4,6 @@ export type TableMeasurement = {
4
4
  colWidths: Array<number>;
5
5
  tableWidth: number;
6
6
  };
7
+ export declare const clampToEditorMaxWidth: (contentWidth: number) => number;
7
8
  export declare const getTableMeasurement: (tableRef: HTMLTableElement) => TableMeasurement;
8
9
  export declare const applyTableMeasurement: (tr: Transaction, tableNode: PMNode, { colWidths, tableWidth }: TableMeasurement, tablePos: number) => Transaction;
@@ -0,0 +1,8 @@
1
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
2
+ import type { PluginInjectionAPI } from '../../../types';
3
+ /**
4
+ * Iterates all top-level tables in the document, and for those in content mode,
5
+ * measures rendered column widths and sets colwidth + table width attributes
6
+ * in a single batched transaction.
7
+ */
8
+ export declare const applyMeasuredWidthToAllTables: (view: EditorView, pluginInjectionApi?: PluginInjectionAPI) => void;
@@ -0,0 +1,6 @@
1
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
2
+ import type { PluginInjectionAPI } from '../../../types';
3
+ /**
4
+ * Used to measure a selected table width with it's content being laid out natively by the browser
5
+ */
6
+ export declare const applyMeasuredWidthToSelectedTable: (view: EditorView, api?: PluginInjectionAPI) => void;
@@ -0,0 +1,7 @@
1
+ type ContentModePluginOptions = {
2
+ allowColumnResizing: boolean;
3
+ allowTableResizing: boolean;
4
+ isFullPageEditor: boolean;
5
+ };
6
+ export declare const isContentModeSupported: ({ allowColumnResizing, allowTableResizing, isFullPageEditor, }: ContentModePluginOptions) => boolean;
7
+ export {};
@@ -0,0 +1,2 @@
1
+ import { type TableMeasurement } from '../../transforms/content-mode';
2
+ export declare const measureTableWithAutoLayout: (tableRef: HTMLTableElement, editorContainerWidth?: number) => TableMeasurement;
@@ -0,0 +1,4 @@
1
+ /** Each column's max width is `MAX × (usableWidth / numCols)`. */
2
+ export declare const EVEN_SHARE_RATIO: {
3
+ readonly MAX: 2;
4
+ };
@@ -0,0 +1,8 @@
1
+ export declare const sumWidths: (widths: Array<number>) => number;
2
+ /**
3
+ * Clamps each desired width to `[tableCellMinWidth, MAX × evenShare]`. Greedy
4
+ * columns (paragraphs) hit the ceiling and wrap; small columns stay at their
5
+ * natural width. Leftover canvas budget grows ceiling-hitters up to their
6
+ * desired; overflow reclaims from ceiling-hitters only.
7
+ */
8
+ export declare const distributeByEvenShareRatio: (desiredWidths: Array<number>, editorContainerWidth: number) => Array<number>;
@@ -0,0 +1,7 @@
1
+ import { type TableMeasurement } from '../../../transforms/content-mode';
2
+ export declare const restoreResizerContainer: (resizerContainer: HTMLElement | undefined | null) => void;
3
+ /**
4
+ * Smart-adjust: measure unconstrained max-content per column, then clamp via
5
+ * `distributeByEvenShareRatio`.
6
+ */
7
+ export declare const runSmartAdjust: (tableRef: HTMLTableElement, resizerContainer: HTMLElement | undefined | null, resizerItem: HTMLElement | undefined | null, editorContainerWidthFromApi: number | undefined) => TableMeasurement;
@@ -1,3 +1,3 @@
1
1
  import type { RegisterComponent } from '@atlaskit/editor-ui-control-model';
2
2
  import type { TableMenuComponentsParams } from '../shared/types';
3
- export declare const getColumnMenuComponents: ({ api }: TableMenuComponentsParams) => RegisterComponent[];
3
+ export declare const getColumnMenuComponents: ({ api, }: TableMenuComponentsParams) => RegisterComponent[];
@@ -1,3 +1,3 @@
1
1
  import React from 'react';
2
2
  import type { TableMenuComponentsParams } from '../../shared/types';
3
- export declare const DistributeColumnsItem: ({ api }: TableMenuComponentsParams) => React.JSX.Element | null;
3
+ export declare const DistributeColumnsItem: ({ api, }: TableMenuComponentsParams) => React.JSX.Element | null;
@@ -4,5 +4,6 @@ export type TableMeasurement = {
4
4
  colWidths: Array<number>;
5
5
  tableWidth: number;
6
6
  };
7
+ export declare const clampToEditorMaxWidth: (contentWidth: number) => number;
7
8
  export declare const getTableMeasurement: (tableRef: HTMLTableElement) => TableMeasurement;
8
9
  export declare const applyTableMeasurement: (tr: Transaction, tableNode: PMNode, { colWidths, tableWidth }: TableMeasurement, tablePos: number) => Transaction;
@@ -0,0 +1,8 @@
1
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
2
+ import type { PluginInjectionAPI } from '../../../types';
3
+ /**
4
+ * Iterates all top-level tables in the document, and for those in content mode,
5
+ * measures rendered column widths and sets colwidth + table width attributes
6
+ * in a single batched transaction.
7
+ */
8
+ export declare const applyMeasuredWidthToAllTables: (view: EditorView, pluginInjectionApi?: PluginInjectionAPI) => void;
@@ -0,0 +1,6 @@
1
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
2
+ import type { PluginInjectionAPI } from '../../../types';
3
+ /**
4
+ * Used to measure a selected table width with it's content being laid out natively by the browser
5
+ */
6
+ export declare const applyMeasuredWidthToSelectedTable: (view: EditorView, api?: PluginInjectionAPI) => void;
@@ -0,0 +1,7 @@
1
+ type ContentModePluginOptions = {
2
+ allowColumnResizing: boolean;
3
+ allowTableResizing: boolean;
4
+ isFullPageEditor: boolean;
5
+ };
6
+ export declare const isContentModeSupported: ({ allowColumnResizing, allowTableResizing, isFullPageEditor, }: ContentModePluginOptions) => boolean;
7
+ export {};
@@ -0,0 +1,2 @@
1
+ import { type TableMeasurement } from '../../transforms/content-mode';
2
+ export declare const measureTableWithAutoLayout: (tableRef: HTMLTableElement, editorContainerWidth?: number) => TableMeasurement;
@@ -0,0 +1,4 @@
1
+ /** Each column's max width is `MAX × (usableWidth / numCols)`. */
2
+ export declare const EVEN_SHARE_RATIO: {
3
+ readonly MAX: 2;
4
+ };
@@ -0,0 +1,8 @@
1
+ export declare const sumWidths: (widths: Array<number>) => number;
2
+ /**
3
+ * Clamps each desired width to `[tableCellMinWidth, MAX × evenShare]`. Greedy
4
+ * columns (paragraphs) hit the ceiling and wrap; small columns stay at their
5
+ * natural width. Leftover canvas budget grows ceiling-hitters up to their
6
+ * desired; overflow reclaims from ceiling-hitters only.
7
+ */
8
+ export declare const distributeByEvenShareRatio: (desiredWidths: Array<number>, editorContainerWidth: number) => Array<number>;
@@ -0,0 +1,7 @@
1
+ import { type TableMeasurement } from '../../../transforms/content-mode';
2
+ export declare const restoreResizerContainer: (resizerContainer: HTMLElement | undefined | null) => void;
3
+ /**
4
+ * Smart-adjust: measure unconstrained max-content per column, then clamp via
5
+ * `distributeByEvenShareRatio`.
6
+ */
7
+ export declare const runSmartAdjust: (tableRef: HTMLTableElement, resizerContainer: HTMLElement | undefined | null, resizerItem: HTMLElement | undefined | null, editorContainerWidthFromApi: number | undefined) => TableMeasurement;
@@ -1,3 +1,3 @@
1
1
  import type { RegisterComponent } from '@atlaskit/editor-ui-control-model';
2
2
  import type { TableMenuComponentsParams } from '../shared/types';
3
- export declare const getColumnMenuComponents: ({ api }: TableMenuComponentsParams) => RegisterComponent[];
3
+ export declare const getColumnMenuComponents: ({ api, }: TableMenuComponentsParams) => RegisterComponent[];
@@ -1,3 +1,3 @@
1
1
  import React from 'react';
2
2
  import type { TableMenuComponentsParams } from '../../shared/types';
3
- export declare const DistributeColumnsItem: ({ api }: TableMenuComponentsParams) => React.JSX.Element | null;
3
+ export declare const DistributeColumnsItem: ({ api, }: TableMenuComponentsParams) => React.JSX.Element | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "22.4.14",
3
+ "version": "22.4.15",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -28,7 +28,7 @@
28
28
  "singleton": true
29
29
  },
30
30
  "dependencies": {
31
- "@atlaskit/adf-schema": "^52.13.0",
31
+ "@atlaskit/adf-schema": "^52.14.0",
32
32
  "@atlaskit/button": "^23.11.0",
33
33
  "@atlaskit/custom-steps": "^0.17.0",
34
34
  "@atlaskit/editor-palette": "^2.2.0",
@@ -37,7 +37,7 @@
37
37
  "@atlaskit/editor-plugin-batch-attribute-updates": "^10.1.0",
38
38
  "@atlaskit/editor-plugin-content-insertion": "^10.1.0",
39
39
  "@atlaskit/editor-plugin-editor-viewmode": "^12.1.0",
40
- "@atlaskit/editor-plugin-extension": "13.5.5",
40
+ "@atlaskit/editor-plugin-extension": "13.5.6",
41
41
  "@atlaskit/editor-plugin-guideline": "^10.1.0",
42
42
  "@atlaskit/editor-plugin-interaction": "^19.1.0",
43
43
  "@atlaskit/editor-plugin-limited-mode": "^7.2.0",
@@ -51,7 +51,7 @@
51
51
  "@atlaskit/editor-tables": "^2.10.0",
52
52
  "@atlaskit/editor-toolbar": "^1.7.0",
53
53
  "@atlaskit/editor-ui-control-model": "^1.2.0",
54
- "@atlaskit/icon": "^35.0.0",
54
+ "@atlaskit/icon": "^35.1.0",
55
55
  "@atlaskit/insm": "^0.4.0",
56
56
  "@atlaskit/menu": "^8.5.0",
57
57
  "@atlaskit/platform-feature-flags": "^1.1.0",
@@ -59,10 +59,10 @@
59
59
  "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^2.1.0",
60
60
  "@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.1.0",
61
61
  "@atlaskit/primitives": "^19.0.0",
62
- "@atlaskit/tmp-editor-statsig": "^82.3.0",
62
+ "@atlaskit/tmp-editor-statsig": "^83.0.0",
63
63
  "@atlaskit/toggle": "^15.6.0",
64
64
  "@atlaskit/tokens": "^13.0.0",
65
- "@atlaskit/tooltip": "^22.2.0",
65
+ "@atlaskit/tooltip": "^22.3.0",
66
66
  "@babel/runtime": "^7.0.0",
67
67
  "@compiled/react": "^0.20.0",
68
68
  "@emotion/react": "^11.7.1",
@@ -74,7 +74,7 @@
74
74
  "uuid": "^3.1.0"
75
75
  },
76
76
  "peerDependencies": {
77
- "@atlaskit/editor-common": "^114.41.0",
77
+ "@atlaskit/editor-common": "^114.46.0",
78
78
  "react": "^18.2.0",
79
79
  "react-dom": "^18.2.0",
80
80
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
@@ -122,6 +122,9 @@
122
122
  "platform_editor_content_mode_button_mvp": {
123
123
  "type": "boolean"
124
124
  },
125
+ "platform_editor_table_fit_to_content_smart_adjust": {
126
+ "type": "boolean"
127
+ },
125
128
  "platform_editor_table_height_analytics": {
126
129
  "type": "boolean"
127
130
  },
@@ -1,162 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.measureTableWithAutoLayout = exports.isContentModeSupported = exports.applyMeasuredWidthToSelectedTable = exports.applyMeasuredWidthToAllTables = void 0;
7
- var _analytics = require("@atlaskit/editor-common/analytics");
8
- var _styles = require("@atlaskit/editor-common/styles");
9
- var _table = require("@atlaskit/editor-common/table");
10
- var _utils = require("@atlaskit/editor-tables/utils");
11
- var _contentMode = require("../transforms/content-mode");
12
- var isContentModeSupported = exports.isContentModeSupported = function isContentModeSupported(_ref) {
13
- var allowColumnResizing = _ref.allowColumnResizing,
14
- allowTableResizing = _ref.allowTableResizing,
15
- isFullPageEditor = _ref.isFullPageEditor;
16
- return allowColumnResizing && allowTableResizing && isFullPageEditor;
17
- };
18
-
19
- /**
20
- * Iterates all top-level tables in the document, and for those in content mode,
21
- * measures rendered column widths and sets colwidth + table width attributes
22
- * in a single batched transaction.
23
- */
24
- var applyMeasuredWidthToAllTables = exports.applyMeasuredWidthToAllTables = function applyMeasuredWidthToAllTables(view, pluginInjectionApi) {
25
- var _view$state = view.state,
26
- doc = _view$state.doc,
27
- schema = _view$state.schema;
28
- var tr = view.state.tr;
29
- var table = schema.nodes.table;
30
- var modified = false;
31
- var measuredTables = [];
32
-
33
- // modify only top-level tables
34
- doc.forEach(function (node, offset) {
35
- if (node.type !== table || (0, _table.hasTableBeenResized)(node) && node.attrs.layout !== 'align-start') {
36
- return;
37
- }
38
- var domNode = view.domAtPos(offset + 1).node;
39
- var tableWrapper = domNode instanceof HTMLElement ? domNode.closest(".".concat(_styles.TableSharedCssClassName.TABLE_VIEW_CONTENT_WRAP)) : null;
40
- var tableRef = tableWrapper === null || tableWrapper === void 0 ? void 0 : tableWrapper.querySelector('table');
41
- if (!tableRef) {
42
- return;
43
- }
44
- measuredTables.push({
45
- node: node,
46
- offset: offset,
47
- measurement: (0, _contentMode.getTableMeasurement)(tableRef)
48
- });
49
- });
50
- measuredTables.forEach(function (_ref2) {
51
- var node = _ref2.node,
52
- offset = _ref2.offset,
53
- measurement = _ref2.measurement;
54
- tr = (0, _contentMode.applyTableMeasurement)(tr, node, measurement, offset);
55
- modified = true;
56
- });
57
- if (modified) {
58
- var _pluginInjectionApi$a, _pluginInjectionApi$w, _pluginInjectionApi$w2;
59
- pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 || (_pluginInjectionApi$a = _pluginInjectionApi$a.actions) === null || _pluginInjectionApi$a === void 0 || _pluginInjectionApi$a.attachAnalyticsEvent({
60
- action: _analytics.TABLE_ACTION.FIT_TO_CONTENT_AUTO_CONVERTED,
61
- actionSubject: _analytics.ACTION_SUBJECT.TABLE,
62
- actionSubjectId: null,
63
- eventType: _analytics.EVENT_TYPE.TRACK,
64
- attributes: {
65
- editorContainerWidth: (_pluginInjectionApi$w = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$w2 = pluginInjectionApi.width) === null || _pluginInjectionApi$w2 === void 0 || (_pluginInjectionApi$w2 = _pluginInjectionApi$w2.sharedState.currentState()) === null || _pluginInjectionApi$w2 === void 0 ? void 0 : _pluginInjectionApi$w2.width) !== null && _pluginInjectionApi$w !== void 0 ? _pluginInjectionApi$w : 0,
66
- totalTablesResized: measuredTables.length,
67
- measurements: measuredTables.map(function (_ref3) {
68
- var measurement = _ref3.measurement;
69
- return {
70
- tableWidth: measurement.tableWidth,
71
- totalColumnCount: measurement.colWidths.length
72
- };
73
- })
74
- }
75
- })(tr);
76
- view.dispatch(tr.setMeta('addToHistory', false));
77
- }
78
- };
79
-
80
- /**
81
- * Temporarily overrides inline styles on the table and its surrounding containers so the browser
82
- * lays columns out with `table-layout: auto`, takes a content-width measurement, and then
83
- * **resets every modified style** so no temporary overrides leak into the rendered output.
84
- */
85
- var measureTableWithAutoLayout = exports.measureTableWithAutoLayout = function measureTableWithAutoLayout(tableRef) {
86
- var cols = Array.from(tableRef.querySelectorAll(':scope > colgroup > col'));
87
- var contentWrap = tableRef.closest(".".concat(_styles.TableSharedCssClassName.TABLE_VIEW_CONTENT_WRAP));
88
- var resizerContainer = contentWrap === null || contentWrap === void 0 ? void 0 : contentWrap.querySelector(".".concat(_styles.TableSharedCssClassName.TABLE_RESIZER_CONTAINER));
89
- var resizerItem = resizerContainer === null || resizerContainer === void 0 ? void 0 : resizerContainer.querySelector('.resizer-item.display-handle');
90
-
91
- // Capture current inline styles so we can restore them after measurement
92
- var prevTableWidth = tableRef.style.width;
93
- var prevTableLayout = tableRef.style.tableLayout;
94
- var prevColWidths = cols.map(function (col) {
95
- return col.style.width;
96
- });
97
- var prevResizerItemWidth = resizerItem === null || resizerItem === void 0 ? void 0 : resizerItem.style.width;
98
-
99
- // Apply temporary styles for content-based measurement
100
- tableRef.style.width = '';
101
- tableRef.style.tableLayout = 'auto';
102
- cols.forEach(function (col) {
103
- return col.style.width = '';
104
- });
105
- if (resizerContainer) {
106
- // favour CSS var to align with the table first render state, which gets reset
107
- // once resized by user. By doing this we avoid the need to any 'reset' work after
108
- // measurement and ensures it works if the table has been resized or not in the session.
109
- resizerContainer.style.width = 'var(--ak-editor-table-width)';
110
- resizerContainer.style.setProperty('--ak-editor-table-width', 'max-content');
111
- }
112
- if (resizerItem) {
113
- resizerItem.style.width = 'max-content';
114
- }
115
- var measurement = (0, _contentMode.getTableMeasurement)(tableRef);
116
-
117
- // Reset all inline styles back to their previous values
118
- tableRef.style.width = prevTableWidth;
119
- tableRef.style.tableLayout = prevTableLayout;
120
- cols.forEach(function (col, i) {
121
- return col.style.width = prevColWidths[i];
122
- });
123
- if (resizerItem) {
124
- resizerItem.style.width = prevResizerItemWidth !== null && prevResizerItemWidth !== void 0 ? prevResizerItemWidth : '';
125
- }
126
- return measurement;
127
- };
128
-
129
- /**
130
- * Used to measure a selected table width with it's content being laid out natively by the browser
131
- */
132
- var applyMeasuredWidthToSelectedTable = exports.applyMeasuredWidthToSelectedTable = function applyMeasuredWidthToSelectedTable(view, api) {
133
- var _api$analytics, _api$width$sharedStat, _api$width;
134
- var tableObject = (0, _utils.findTable)(view.state.selection);
135
- if (!tableObject) {
136
- return;
137
- }
138
- var node = tableObject.node,
139
- pos = tableObject.pos;
140
- var tableState = api === null || api === void 0 ? void 0 : api.table.sharedState.currentState();
141
- if (!(tableState !== null && tableState !== void 0 && tableState.tableRef)) {
142
- return;
143
- }
144
-
145
- // Instead of dispatching a transaction to "strip widths" and then waiting
146
- // for a rAF to measure natural column widths, directly update the DOM elements,
147
- // take a measurement, and reset styles so no temporary overrides persist.
148
- var measurement = measureTableWithAutoLayout(tableState.tableRef);
149
- var tr = (0, _contentMode.applyTableMeasurement)(view.state.tr, node, measurement, pos);
150
- api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || (_api$analytics = _api$analytics.actions) === null || _api$analytics === void 0 || _api$analytics.attachAnalyticsEvent({
151
- action: _analytics.TABLE_ACTION.FIT_TO_CONTENT_ON_DEMAND,
152
- actionSubject: _analytics.ACTION_SUBJECT.TABLE,
153
- actionSubjectId: null,
154
- eventType: _analytics.EVENT_TYPE.TRACK,
155
- attributes: {
156
- editorContainerWidth: (_api$width$sharedStat = api === null || api === void 0 || (_api$width = api.width) === null || _api$width === void 0 || (_api$width = _api$width.sharedState.currentState()) === null || _api$width === void 0 ? void 0 : _api$width.width) !== null && _api$width$sharedStat !== void 0 ? _api$width$sharedStat : 0,
157
- tableWidth: measurement.tableWidth,
158
- totalColumnCount: measurement.colWidths.length
159
- }
160
- })(tr);
161
- view.dispatch(tr);
162
- };