@atlaskit/editor-plugin-table 22.4.14 → 22.4.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/cjs/nodeviews/TableComponent.js +2 -2
- package/dist/cjs/nodeviews/table.js +2 -2
- package/dist/cjs/nodeviews/toDOM.js +2 -2
- package/dist/cjs/pm-plugins/commands/active-table-menu.js +51 -0
- package/dist/cjs/pm-plugins/commands/commands-with-analytics.js +42 -10
- package/dist/cjs/pm-plugins/commands/index.js +13 -0
- package/dist/cjs/pm-plugins/drag-and-drop/commands-with-analytics.js +2 -0
- package/dist/cjs/pm-plugins/drag-and-drop/plugin.js +4 -0
- package/dist/cjs/pm-plugins/handlers.js +8 -1
- package/dist/cjs/pm-plugins/main.js +4 -3
- package/dist/cjs/pm-plugins/reducer.js +2 -0
- package/dist/cjs/pm-plugins/table-width.js +2 -2
- package/dist/cjs/pm-plugins/transforms/content-mode.js +3 -2
- package/dist/cjs/pm-plugins/utils/tableMode/apply-measured-width-to-all-tables.js +70 -0
- package/dist/cjs/pm-plugins/utils/tableMode/apply-measured-width-to-selected-table.js +41 -0
- package/dist/cjs/pm-plugins/utils/tableMode/is-content-mode-supported.js +12 -0
- package/dist/cjs/pm-plugins/utils/tableMode/measure-table-with-auto-layout.js +113 -0
- package/dist/cjs/pm-plugins/utils/tableMode/smart-adjust/constants.js +10 -0
- package/dist/cjs/pm-plugins/utils/tableMode/smart-adjust/distribute-column-widths.js +83 -0
- package/dist/cjs/pm-plugins/utils/tableMode/smart-adjust/run-smart-adjust.js +56 -0
- package/dist/cjs/tablePlugin.js +1 -0
- package/dist/cjs/ui/ContentComponent.js +1 -1
- package/dist/cjs/ui/FloatingContextualButton/index.js +28 -9
- package/dist/cjs/ui/FloatingContextualMenu/CellMenuPopup.js +58 -73
- package/dist/cjs/ui/FloatingContextualMenu/index.js +26 -12
- package/dist/cjs/ui/FloatingDragMenu/index.js +21 -8
- package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +13 -5
- package/dist/cjs/ui/TableFloatingControls/RowControls/DragControls.js +14 -5
- package/dist/cjs/ui/TableMenu/cell/getCellMenuComponents.js +8 -3
- package/dist/cjs/ui/TableMenu/cell/items/MergeCellsItem.js +16 -1
- package/dist/cjs/ui/TableMenu/cell/items/SplitCellItem.js +16 -1
- package/dist/cjs/ui/TableMenu/column/items/AddColumnLeftItem.js +4 -4
- package/dist/cjs/ui/TableMenu/column/items/AddColumnRightItem.js +4 -4
- package/dist/cjs/ui/TableMenu/column/items/DeleteColumnItem.js +2 -3
- package/dist/cjs/ui/TableMenu/column/items/DistributeColumnsItem.js +2 -3
- package/dist/cjs/ui/TableMenu/column/items/HeaderColumnToggleItem.js +2 -3
- package/dist/cjs/ui/TableMenu/column/items/MoveColumnLeftItem.js +2 -3
- package/dist/cjs/ui/TableMenu/column/items/MoveColumnRightItem.js +2 -3
- package/dist/cjs/ui/TableMenu/column/items/SortDecreasingItem.js +2 -3
- package/dist/cjs/ui/TableMenu/column/items/SortIncreasingItem.js +2 -3
- package/dist/cjs/ui/TableMenu/row/items/AddRowAboveItem.js +4 -4
- package/dist/cjs/ui/TableMenu/row/items/AddRowBelowItem.js +4 -4
- package/dist/cjs/ui/TableMenu/row/items/DeleteRowItem.js +2 -3
- package/dist/cjs/ui/TableMenu/row/items/HeaderRowToggleItem.js +2 -3
- package/dist/cjs/ui/TableMenu/row/items/MoveRowDownItem.js +2 -3
- package/dist/cjs/ui/TableMenu/row/items/MoveRowUpItem.js +2 -3
- package/dist/cjs/ui/TableMenu/row/items/NumberedRowsToggleItem.js +4 -3
- package/dist/cjs/ui/TableMenu/shared/TableMenu.compiled.css +0 -2
- package/dist/cjs/ui/TableMenu/shared/TableMenu.js +8 -9
- package/dist/cjs/ui/TableMenu/shared/getSharedItems.js +3 -1
- package/dist/cjs/ui/TableMenu/shared/getTableMenuComponents.js +1 -1
- package/dist/cjs/ui/TableMenu/shared/items/BackgroundColorItem.js +30 -4
- package/dist/cjs/ui/TableMenu/shared/items/ClearCellsItem.js +4 -3
- package/dist/cjs/ui/toolbar.js +4 -3
- package/dist/es2019/nodeviews/TableComponent.js +1 -1
- package/dist/es2019/nodeviews/table.js +1 -1
- package/dist/es2019/nodeviews/toDOM.js +1 -1
- package/dist/es2019/pm-plugins/commands/active-table-menu.js +39 -0
- package/dist/es2019/pm-plugins/commands/commands-with-analytics.js +31 -2
- package/dist/es2019/pm-plugins/commands/index.js +1 -0
- package/dist/es2019/pm-plugins/drag-and-drop/commands-with-analytics.js +2 -0
- package/dist/es2019/pm-plugins/drag-and-drop/plugin.js +4 -0
- package/dist/es2019/pm-plugins/handlers.js +8 -1
- package/dist/es2019/pm-plugins/main.js +2 -1
- package/dist/es2019/pm-plugins/reducer.js +5 -0
- package/dist/es2019/pm-plugins/table-width.js +1 -1
- package/dist/es2019/pm-plugins/transforms/content-mode.js +2 -1
- package/dist/es2019/pm-plugins/utils/tableMode/apply-measured-width-to-all-tables.js +70 -0
- package/dist/es2019/pm-plugins/utils/tableMode/apply-measured-width-to-selected-table.js +38 -0
- package/dist/es2019/pm-plugins/utils/tableMode/is-content-mode-supported.js +7 -0
- package/dist/es2019/pm-plugins/utils/tableMode/measure-table-with-auto-layout.js +97 -0
- package/dist/es2019/pm-plugins/utils/tableMode/smart-adjust/constants.js +4 -0
- package/dist/es2019/pm-plugins/utils/tableMode/smart-adjust/distribute-column-widths.js +63 -0
- package/dist/es2019/pm-plugins/utils/tableMode/smart-adjust/run-smart-adjust.js +47 -0
- package/dist/es2019/tablePlugin.js +1 -0
- package/dist/es2019/ui/ContentComponent.js +1 -1
- package/dist/es2019/ui/FloatingContextualButton/index.js +29 -9
- package/dist/es2019/ui/FloatingContextualMenu/CellMenuPopup.js +60 -77
- package/dist/es2019/ui/FloatingContextualMenu/index.js +27 -12
- package/dist/es2019/ui/FloatingDragMenu/index.js +22 -8
- package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +12 -4
- package/dist/es2019/ui/TableFloatingControls/RowControls/DragControls.js +13 -4
- package/dist/es2019/ui/TableMenu/cell/getCellMenuComponents.js +9 -3
- package/dist/es2019/ui/TableMenu/cell/items/MergeCellsItem.js +18 -2
- package/dist/es2019/ui/TableMenu/cell/items/SplitCellItem.js +18 -2
- package/dist/es2019/ui/TableMenu/column/items/AddColumnLeftItem.js +3 -3
- package/dist/es2019/ui/TableMenu/column/items/AddColumnRightItem.js +3 -3
- package/dist/es2019/ui/TableMenu/column/items/DeleteColumnItem.js +2 -3
- package/dist/es2019/ui/TableMenu/column/items/DistributeColumnsItem.js +2 -3
- package/dist/es2019/ui/TableMenu/column/items/HeaderColumnToggleItem.js +2 -3
- package/dist/es2019/ui/TableMenu/column/items/MoveColumnLeftItem.js +2 -3
- package/dist/es2019/ui/TableMenu/column/items/MoveColumnRightItem.js +2 -3
- package/dist/es2019/ui/TableMenu/column/items/SortDecreasingItem.js +2 -3
- package/dist/es2019/ui/TableMenu/column/items/SortIncreasingItem.js +2 -3
- package/dist/es2019/ui/TableMenu/row/items/AddRowAboveItem.js +3 -3
- package/dist/es2019/ui/TableMenu/row/items/AddRowBelowItem.js +3 -3
- package/dist/es2019/ui/TableMenu/row/items/DeleteRowItem.js +2 -3
- package/dist/es2019/ui/TableMenu/row/items/HeaderRowToggleItem.js +2 -3
- package/dist/es2019/ui/TableMenu/row/items/MoveRowDownItem.js +2 -3
- package/dist/es2019/ui/TableMenu/row/items/MoveRowUpItem.js +2 -3
- package/dist/es2019/ui/TableMenu/row/items/NumberedRowsToggleItem.js +3 -2
- package/dist/es2019/ui/TableMenu/shared/TableMenu.compiled.css +0 -2
- package/dist/es2019/ui/TableMenu/shared/TableMenu.js +8 -9
- package/dist/es2019/ui/TableMenu/shared/getSharedItems.js +3 -1
- package/dist/es2019/ui/TableMenu/shared/getTableMenuComponents.js +1 -1
- package/dist/es2019/ui/TableMenu/shared/items/BackgroundColorItem.js +33 -4
- package/dist/es2019/ui/TableMenu/shared/items/ClearCellsItem.js +4 -3
- package/dist/es2019/ui/toolbar.js +2 -1
- package/dist/esm/nodeviews/TableComponent.js +1 -1
- package/dist/esm/nodeviews/table.js +1 -1
- package/dist/esm/nodeviews/toDOM.js +1 -1
- package/dist/esm/pm-plugins/commands/active-table-menu.js +45 -0
- package/dist/esm/pm-plugins/commands/commands-with-analytics.js +41 -10
- package/dist/esm/pm-plugins/commands/index.js +1 -0
- package/dist/esm/pm-plugins/drag-and-drop/commands-with-analytics.js +2 -0
- package/dist/esm/pm-plugins/drag-and-drop/plugin.js +4 -0
- package/dist/esm/pm-plugins/handlers.js +8 -1
- package/dist/esm/pm-plugins/main.js +2 -1
- package/dist/esm/pm-plugins/reducer.js +2 -0
- package/dist/esm/pm-plugins/table-width.js +1 -1
- package/dist/esm/pm-plugins/transforms/content-mode.js +2 -1
- package/dist/esm/pm-plugins/utils/tableMode/apply-measured-width-to-all-tables.js +65 -0
- package/dist/esm/pm-plugins/utils/tableMode/apply-measured-width-to-selected-table.js +36 -0
- package/dist/esm/pm-plugins/utils/tableMode/is-content-mode-supported.js +6 -0
- package/dist/esm/pm-plugins/utils/tableMode/measure-table-with-auto-layout.js +107 -0
- package/dist/esm/pm-plugins/utils/tableMode/smart-adjust/constants.js +4 -0
- package/dist/esm/pm-plugins/utils/tableMode/smart-adjust/distribute-column-widths.js +77 -0
- package/dist/esm/pm-plugins/utils/tableMode/smart-adjust/run-smart-adjust.js +49 -0
- package/dist/esm/tablePlugin.js +1 -0
- package/dist/esm/ui/ContentComponent.js +1 -1
- package/dist/esm/ui/FloatingContextualButton/index.js +29 -10
- package/dist/esm/ui/FloatingContextualMenu/CellMenuPopup.js +60 -75
- package/dist/esm/ui/FloatingContextualMenu/index.js +26 -12
- package/dist/esm/ui/FloatingDragMenu/index.js +21 -8
- package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +12 -4
- package/dist/esm/ui/TableFloatingControls/RowControls/DragControls.js +13 -4
- package/dist/esm/ui/TableMenu/cell/getCellMenuComponents.js +8 -3
- package/dist/esm/ui/TableMenu/cell/items/MergeCellsItem.js +16 -2
- package/dist/esm/ui/TableMenu/cell/items/SplitCellItem.js +16 -2
- package/dist/esm/ui/TableMenu/column/items/AddColumnLeftItem.js +4 -4
- package/dist/esm/ui/TableMenu/column/items/AddColumnRightItem.js +4 -4
- package/dist/esm/ui/TableMenu/column/items/DeleteColumnItem.js +2 -3
- package/dist/esm/ui/TableMenu/column/items/DistributeColumnsItem.js +2 -3
- package/dist/esm/ui/TableMenu/column/items/HeaderColumnToggleItem.js +2 -3
- package/dist/esm/ui/TableMenu/column/items/MoveColumnLeftItem.js +2 -3
- package/dist/esm/ui/TableMenu/column/items/MoveColumnRightItem.js +2 -3
- package/dist/esm/ui/TableMenu/column/items/SortDecreasingItem.js +2 -3
- package/dist/esm/ui/TableMenu/column/items/SortIncreasingItem.js +2 -3
- package/dist/esm/ui/TableMenu/row/items/AddRowAboveItem.js +4 -4
- package/dist/esm/ui/TableMenu/row/items/AddRowBelowItem.js +4 -4
- package/dist/esm/ui/TableMenu/row/items/DeleteRowItem.js +2 -3
- package/dist/esm/ui/TableMenu/row/items/HeaderRowToggleItem.js +2 -3
- package/dist/esm/ui/TableMenu/row/items/MoveRowDownItem.js +2 -3
- package/dist/esm/ui/TableMenu/row/items/MoveRowUpItem.js +2 -3
- package/dist/esm/ui/TableMenu/row/items/NumberedRowsToggleItem.js +4 -3
- package/dist/esm/ui/TableMenu/shared/TableMenu.compiled.css +0 -2
- package/dist/esm/ui/TableMenu/shared/TableMenu.js +8 -9
- package/dist/esm/ui/TableMenu/shared/getSharedItems.js +3 -1
- package/dist/esm/ui/TableMenu/shared/getTableMenuComponents.js +1 -1
- package/dist/esm/ui/TableMenu/shared/items/BackgroundColorItem.js +30 -4
- package/dist/esm/ui/TableMenu/shared/items/ClearCellsItem.js +4 -3
- package/dist/esm/ui/toolbar.js +2 -1
- package/dist/types/entry-points/types.d.ts +1 -1
- package/dist/types/pm-plugins/commands/active-table-menu.d.ts +6 -0
- package/dist/types/pm-plugins/commands/commands-with-analytics.d.ts +3 -1
- package/dist/types/pm-plugins/commands/index.d.ts +1 -0
- package/dist/types/pm-plugins/transforms/content-mode.d.ts +1 -0
- package/dist/types/pm-plugins/utils/tableMode/apply-measured-width-to-all-tables.d.ts +8 -0
- package/dist/types/pm-plugins/utils/tableMode/apply-measured-width-to-selected-table.d.ts +6 -0
- package/dist/types/pm-plugins/utils/tableMode/is-content-mode-supported.d.ts +7 -0
- package/dist/types/pm-plugins/utils/tableMode/measure-table-with-auto-layout.d.ts +2 -0
- package/dist/types/pm-plugins/utils/tableMode/smart-adjust/constants.d.ts +4 -0
- package/dist/types/pm-plugins/utils/tableMode/smart-adjust/distribute-column-widths.d.ts +8 -0
- package/dist/types/pm-plugins/utils/tableMode/smart-adjust/run-smart-adjust.d.ts +7 -0
- package/dist/types/types/index.d.ts +21 -1
- package/dist/types/ui/FloatingContextualButton/index.d.ts +2 -0
- package/dist/types/ui/FloatingContextualMenu/CellMenuPopup.d.ts +7 -5
- package/dist/types/ui/FloatingContextualMenu/index.d.ts +0 -1
- package/dist/types/ui/TableMenu/cell/getCellMenuComponents.d.ts +2 -1
- package/dist/types/ui/TableMenu/cell/items/MergeCellsItem.d.ts +2 -1
- package/dist/types/ui/TableMenu/cell/items/SplitCellItem.d.ts +2 -1
- package/dist/types/ui/TableMenu/column/getColumnMenuComponents.d.ts +1 -1
- package/dist/types/ui/TableMenu/shared/TableMenuContext.d.ts +2 -0
- package/dist/types/ui/TableMenu/shared/items/BackgroundColorItem.d.ts +2 -1
- package/dist/types-ts4.5/entry-points/types.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/commands/active-table-menu.d.ts +6 -0
- package/dist/types-ts4.5/pm-plugins/commands/commands-with-analytics.d.ts +3 -1
- package/dist/types-ts4.5/pm-plugins/commands/index.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/transforms/content-mode.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/utils/tableMode/apply-measured-width-to-all-tables.d.ts +8 -0
- package/dist/types-ts4.5/pm-plugins/utils/tableMode/apply-measured-width-to-selected-table.d.ts +6 -0
- package/dist/types-ts4.5/pm-plugins/utils/tableMode/is-content-mode-supported.d.ts +7 -0
- package/dist/types-ts4.5/pm-plugins/utils/tableMode/measure-table-with-auto-layout.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/utils/tableMode/smart-adjust/constants.d.ts +4 -0
- package/dist/types-ts4.5/pm-plugins/utils/tableMode/smart-adjust/distribute-column-widths.d.ts +8 -0
- package/dist/types-ts4.5/pm-plugins/utils/tableMode/smart-adjust/run-smart-adjust.d.ts +7 -0
- package/dist/types-ts4.5/types/index.d.ts +21 -1
- package/dist/types-ts4.5/ui/FloatingContextualButton/index.d.ts +2 -0
- package/dist/types-ts4.5/ui/FloatingContextualMenu/CellMenuPopup.d.ts +7 -5
- package/dist/types-ts4.5/ui/FloatingContextualMenu/index.d.ts +0 -1
- package/dist/types-ts4.5/ui/TableMenu/cell/getCellMenuComponents.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/cell/items/MergeCellsItem.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/cell/items/SplitCellItem.d.ts +2 -1
- package/dist/types-ts4.5/ui/TableMenu/column/getColumnMenuComponents.d.ts +1 -1
- package/dist/types-ts4.5/ui/TableMenu/shared/TableMenuContext.d.ts +2 -0
- package/dist/types-ts4.5/ui/TableMenu/shared/items/BackgroundColorItem.d.ts +2 -1
- package/package.json +10 -7
- package/dist/cjs/pm-plugins/utils/tableMode.js +0 -162
- package/dist/es2019/pm-plugins/utils/tableMode.js +0 -158
- package/dist/esm/pm-plugins/utils/tableMode.js +0 -156
- package/dist/types/pm-plugins/utils/tableMode.d.ts +0 -26
- package/dist/types-ts4.5/pm-plugins/utils/tableMode.d.ts +0 -26
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { TableSharedCssClassName } from '@atlaskit/editor-common/styles';
|
|
2
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
|
+
import { getTableMeasurement } from '../../transforms/content-mode';
|
|
4
|
+
import { restoreResizerContainer, runSmartAdjust } from './smart-adjust/run-smart-adjust';
|
|
5
|
+
export const measureTableWithAutoLayout = (tableRef, editorContainerWidth) => {
|
|
6
|
+
const cols = Array.from(tableRef.querySelectorAll(':scope > colgroup > col'));
|
|
7
|
+
const contentWrap = tableRef.closest(`.${TableSharedCssClassName.TABLE_VIEW_CONTENT_WRAP}`);
|
|
8
|
+
const resizerContainer = contentWrap === null || contentWrap === void 0 ? void 0 : contentWrap.querySelector(`.${TableSharedCssClassName.TABLE_RESIZER_CONTAINER}`);
|
|
9
|
+
const resizerItem = resizerContainer === null || resizerContainer === void 0 ? void 0 : resizerContainer.querySelector('.resizer-item.display-handle');
|
|
10
|
+
const prevTableWidth = tableRef.style.width;
|
|
11
|
+
const prevTableLayout = tableRef.style.tableLayout;
|
|
12
|
+
const prevColWidths = cols.map(col => col.style.width);
|
|
13
|
+
const prevResizerItemWidth = resizerItem === null || resizerItem === void 0 ? void 0 : resizerItem.style.width;
|
|
14
|
+
tableRef.style.width = '';
|
|
15
|
+
tableRef.style.tableLayout = 'auto';
|
|
16
|
+
cols.forEach(col => col.style.width = '');
|
|
17
|
+
if (fg('platform_editor_table_fit_to_content_smart_adjust')) {
|
|
18
|
+
const hadTableSticky = tableRef.classList.contains(TableSharedCssClassName.TABLE_STICKY);
|
|
19
|
+
const prevTableMarginTop = tableRef.style.marginTop;
|
|
20
|
+
if (hadTableSticky) {
|
|
21
|
+
tableRef.classList.remove(TableSharedCssClassName.TABLE_NATIVE_STICKY);
|
|
22
|
+
}
|
|
23
|
+
if (prevTableMarginTop) {
|
|
24
|
+
tableRef.style.marginTop = '';
|
|
25
|
+
}
|
|
26
|
+
const stickyRows = Array.from(tableRef.querySelectorAll(`tr.sticky, tr.${TableSharedCssClassName.TABLE_NATIVE_STICKY}`));
|
|
27
|
+
const prevStickyRowState = stickyRows.map(row => ({
|
|
28
|
+
row,
|
|
29
|
+
hadSticky: row.classList.contains('sticky'),
|
|
30
|
+
hadNative: row.classList.contains(TableSharedCssClassName.TABLE_NATIVE_STICKY),
|
|
31
|
+
width: row.style.width,
|
|
32
|
+
top: row.style.top,
|
|
33
|
+
position: row.style.position,
|
|
34
|
+
gridTemplateColumns: row.style.gridTemplateColumns
|
|
35
|
+
}));
|
|
36
|
+
stickyRows.forEach(row => {
|
|
37
|
+
row.classList.remove('sticky');
|
|
38
|
+
row.classList.remove(TableSharedCssClassName.TABLE_NATIVE_STICKY);
|
|
39
|
+
row.style.width = '';
|
|
40
|
+
row.style.top = '';
|
|
41
|
+
row.style.position = '';
|
|
42
|
+
row.style.gridTemplateColumns = '';
|
|
43
|
+
});
|
|
44
|
+
try {
|
|
45
|
+
return runSmartAdjust(tableRef, resizerContainer, resizerItem, editorContainerWidth);
|
|
46
|
+
} finally {
|
|
47
|
+
tableRef.style.width = prevTableWidth;
|
|
48
|
+
tableRef.style.tableLayout = prevTableLayout;
|
|
49
|
+
cols.forEach((col, i) => col.style.width = prevColWidths[i]);
|
|
50
|
+
if (hadTableSticky) {
|
|
51
|
+
tableRef.classList.add(TableSharedCssClassName.TABLE_STICKY);
|
|
52
|
+
}
|
|
53
|
+
if (prevTableMarginTop) {
|
|
54
|
+
tableRef.style.marginTop = prevTableMarginTop;
|
|
55
|
+
}
|
|
56
|
+
prevStickyRowState.forEach(state => {
|
|
57
|
+
if (state.hadSticky) {
|
|
58
|
+
state.row.classList.add('sticky');
|
|
59
|
+
}
|
|
60
|
+
if (state.hadNative) {
|
|
61
|
+
state.row.classList.add(TableSharedCssClassName.TABLE_NATIVE_STICKY);
|
|
62
|
+
}
|
|
63
|
+
if (state.width) {
|
|
64
|
+
state.row.style.width = state.width;
|
|
65
|
+
}
|
|
66
|
+
if (state.top) {
|
|
67
|
+
state.row.style.top = state.top;
|
|
68
|
+
}
|
|
69
|
+
if (state.position) {
|
|
70
|
+
state.row.style.position = state.position;
|
|
71
|
+
}
|
|
72
|
+
if (state.gridTemplateColumns) {
|
|
73
|
+
state.row.style.gridTemplateColumns = state.gridTemplateColumns;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
restoreResizerContainer(resizerContainer);
|
|
77
|
+
if (resizerItem) {
|
|
78
|
+
resizerItem.style.width = prevResizerItemWidth !== null && prevResizerItemWidth !== void 0 ? prevResizerItemWidth : '';
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (resizerContainer) {
|
|
83
|
+
resizerContainer.style.width = 'var(--ak-editor-table-width)';
|
|
84
|
+
resizerContainer.style.setProperty('--ak-editor-table-width', 'max-content');
|
|
85
|
+
}
|
|
86
|
+
if (resizerItem) {
|
|
87
|
+
resizerItem.style.width = 'max-content';
|
|
88
|
+
}
|
|
89
|
+
const measurement = getTableMeasurement(tableRef);
|
|
90
|
+
tableRef.style.width = prevTableWidth;
|
|
91
|
+
tableRef.style.tableLayout = prevTableLayout;
|
|
92
|
+
cols.forEach((col, i) => col.style.width = prevColWidths[i]);
|
|
93
|
+
if (resizerItem) {
|
|
94
|
+
resizerItem.style.width = prevResizerItemWidth !== null && prevResizerItemWidth !== void 0 ? prevResizerItemWidth : '';
|
|
95
|
+
}
|
|
96
|
+
return measurement;
|
|
97
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
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 const sumWidths = widths => widths.reduce((sum, width) => sum + width, 0);
|
|
5
|
+
|
|
6
|
+
// 2px absorbs sub-pixel rounding in `getRenderedColgroupColumnWidths`.
|
|
7
|
+
const SUB_PIXEL_ROUNDING_ALLOWANCE = 2;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Clamps each desired width to `[tableCellMinWidth, MAX × evenShare]`. Greedy
|
|
11
|
+
* columns (paragraphs) hit the ceiling and wrap; small columns stay at their
|
|
12
|
+
* natural width. Leftover canvas budget grows ceiling-hitters up to their
|
|
13
|
+
* desired; overflow reclaims from ceiling-hitters only.
|
|
14
|
+
*/
|
|
15
|
+
export const distributeByEvenShareRatio = (desiredWidths, editorContainerWidth) => {
|
|
16
|
+
if (desiredWidths.length === 0 || !isFinite(editorContainerWidth) || editorContainerWidth <= 0) {
|
|
17
|
+
return desiredWidths;
|
|
18
|
+
}
|
|
19
|
+
const usableWidth = Math.max(editorContainerWidth - akEditorGutterPaddingDynamic() * 2, tableCellMinWidth * desiredWidths.length);
|
|
20
|
+
const evenShare = usableWidth / desiredWidths.length;
|
|
21
|
+
const ceiling = EVEN_SHARE_RATIO.MAX * evenShare;
|
|
22
|
+
const isCompactColumn = width => width <= ceiling;
|
|
23
|
+
const desiredCeil = desiredWidths.map(desired => Math.max(tableCellMinWidth, Math.ceil(desired) + SUB_PIXEL_ROUNDING_ALLOWANCE));
|
|
24
|
+
const capped = desiredCeil.map(desired => isCompactColumn(desired) ? desired : Math.min(ceiling, desired));
|
|
25
|
+
const sum = sumWidths(capped);
|
|
26
|
+
|
|
27
|
+
// Underflow: grow non-protected ceiling-hitters into the leftover, up to their desired.
|
|
28
|
+
if (sum < usableWidth) {
|
|
29
|
+
const leftover = usableWidth - sum;
|
|
30
|
+
const growthHeadroom = capped.map((width, index) => !isCompactColumn(desiredCeil[index]) && width >= ceiling ? Math.max(desiredCeil[index] - width, 0) : 0);
|
|
31
|
+
const totalHeadroom = sumWidths(growthHeadroom);
|
|
32
|
+
if (totalHeadroom > 0) {
|
|
33
|
+
const totalGrowth = Math.min(leftover, totalHeadroom);
|
|
34
|
+
return capped.map((width, index) => {
|
|
35
|
+
const headroom = growthHeadroom[index];
|
|
36
|
+
if (headroom <= 0) {
|
|
37
|
+
return width;
|
|
38
|
+
}
|
|
39
|
+
return width + headroom / totalHeadroom * totalGrowth;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return capped;
|
|
43
|
+
}
|
|
44
|
+
if (sum === usableWidth) {
|
|
45
|
+
return capped;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Overflow: reclaim from non-protected ceiling-hitters only.
|
|
49
|
+
const overage = sum - usableWidth;
|
|
50
|
+
const slacks = capped.map((width, index) => !isCompactColumn(desiredCeil[index]) && width >= ceiling ? Math.max(width - tableCellMinWidth, 0) : 0);
|
|
51
|
+
const totalSlack = sumWidths(slacks);
|
|
52
|
+
if (totalSlack <= 0) {
|
|
53
|
+
return capped;
|
|
54
|
+
}
|
|
55
|
+
return capped.map((width, index) => {
|
|
56
|
+
const slack = slacks[index];
|
|
57
|
+
if (slack <= 0) {
|
|
58
|
+
return width;
|
|
59
|
+
}
|
|
60
|
+
const share = slack / totalSlack * Math.min(overage, totalSlack);
|
|
61
|
+
return Math.max(width - share, tableCellMinWidth);
|
|
62
|
+
});
|
|
63
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { getTableMeasurement } from '../../../transforms/content-mode';
|
|
2
|
+
import { distributeByEvenShareRatio, sumWidths } from './distribute-column-widths';
|
|
3
|
+
const measureWithIntrinsicWidth = (tableRef, resizerContainer, resizerItem) => {
|
|
4
|
+
if (resizerContainer) {
|
|
5
|
+
resizerContainer.style.width = 'var(--ak-editor-table-width)';
|
|
6
|
+
resizerContainer.style.setProperty('--ak-editor-table-width', 'max-content');
|
|
7
|
+
}
|
|
8
|
+
if (resizerItem) {
|
|
9
|
+
resizerItem.style.width = 'max-content';
|
|
10
|
+
}
|
|
11
|
+
const prevTableWidth = tableRef.style.width;
|
|
12
|
+
const prevTableMaxWidth = tableRef.style.maxWidth;
|
|
13
|
+
const prevTableMinWidth = tableRef.style.minWidth;
|
|
14
|
+
tableRef.style.setProperty('width', 'max-content', 'important');
|
|
15
|
+
tableRef.style.setProperty('max-width', 'none', 'important');
|
|
16
|
+
tableRef.style.setProperty('min-width', '0', 'important');
|
|
17
|
+
try {
|
|
18
|
+
return getTableMeasurement(tableRef);
|
|
19
|
+
} finally {
|
|
20
|
+
tableRef.style.width = prevTableWidth;
|
|
21
|
+
tableRef.style.maxWidth = prevTableMaxWidth;
|
|
22
|
+
tableRef.style.minWidth = prevTableMinWidth;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export const restoreResizerContainer = resizerContainer => {
|
|
26
|
+
if (!resizerContainer) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
resizerContainer.style.width = 'var(--ak-editor-table-width)';
|
|
30
|
+
resizerContainer.style.removeProperty('--ak-editor-table-width');
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Smart-adjust: measure unconstrained max-content per column, then clamp via
|
|
35
|
+
* `distributeByEvenShareRatio`.
|
|
36
|
+
*/
|
|
37
|
+
export const runSmartAdjust = (tableRef, resizerContainer, resizerItem, editorContainerWidthFromApi) => {
|
|
38
|
+
const preferredMeasurement = measureWithIntrinsicWidth(tableRef, resizerContainer, resizerItem);
|
|
39
|
+
const desiredWidths = preferredMeasurement.colWidths;
|
|
40
|
+
const editorContainerWidth = editorContainerWidthFromApi !== null && editorContainerWidthFromApi !== void 0 ? editorContainerWidthFromApi : sumWidths(desiredWidths);
|
|
41
|
+
const colWidths = distributeByEvenShareRatio(desiredWidths, editorContainerWidth);
|
|
42
|
+
return {
|
|
43
|
+
...preferredMeasurement,
|
|
44
|
+
colWidths,
|
|
45
|
+
tableWidth: sumWidths(colWidths)
|
|
46
|
+
};
|
|
47
|
+
};
|
|
@@ -140,6 +140,7 @@ const tablePlugin = ({
|
|
|
140
140
|
insertRowButtonIndex: tablePluginState.insertRowButtonIndex,
|
|
141
141
|
tableWrapperTarget: tablePluginState.tableWrapperTarget,
|
|
142
142
|
isCellMenuOpenByKeyboard: tablePluginState.isCellMenuOpenByKeyboard,
|
|
143
|
+
activeTableMenu: tablePluginState.activeTableMenu,
|
|
143
144
|
stickyHeader,
|
|
144
145
|
dragMenuDirection: dragAndDropState === null || dragAndDropState === void 0 ? void 0 : dragAndDropState.dragMenuDirection,
|
|
145
146
|
dragMenuIndex: dragAndDropState === null || dragAndDropState === void 0 ? void 0 : dragAndDropState.dragMenuIndex,
|
|
@@ -93,6 +93,7 @@ const ContentComponentInternal = ({
|
|
|
93
93
|
return null;
|
|
94
94
|
}
|
|
95
95
|
return /*#__PURE__*/React.createElement(React.Fragment, null, targetCellPosition && (tableRef || isCellMenuOpenByKeyboard) && !isResizing && options && options.allowContextualMenu && /*#__PURE__*/React.createElement(FloatingContextualButton, {
|
|
96
|
+
api: api,
|
|
96
97
|
isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
|
|
97
98
|
editorView: editorView,
|
|
98
99
|
tableNode: tableNode,
|
|
@@ -128,7 +129,6 @@ const ContentComponentInternal = ({
|
|
|
128
129
|
editorView: editorView,
|
|
129
130
|
mountPoint: popupsMountPoint,
|
|
130
131
|
boundariesElement: popupsBoundariesElement,
|
|
131
|
-
targetCellPosition: targetCellPosition,
|
|
132
132
|
isOpen: Boolean(isContextualMenuOpen) && !isResizing,
|
|
133
133
|
pluginConfig: pluginConfig,
|
|
134
134
|
editorAnalyticsAPI: editorAnalyticsAPI,
|
|
@@ -8,6 +8,7 @@ import { css, jsx } from '@emotion/react';
|
|
|
8
8
|
import { injectIntl } from 'react-intl';
|
|
9
9
|
import { ACTION_SUBJECT } from '@atlaskit/editor-common/analytics';
|
|
10
10
|
import { ErrorBoundary } from '@atlaskit/editor-common/error-boundary';
|
|
11
|
+
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
11
12
|
import { focusToContextMenuTrigger } from '@atlaskit/editor-common/keymaps';
|
|
12
13
|
import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
13
14
|
import { Popup } from '@atlaskit/editor-common/ui';
|
|
@@ -17,7 +18,7 @@ import { akEditorSmallZIndex } from '@atlaskit/editor-shared-styles';
|
|
|
17
18
|
import ExpandIcon from '@atlaskit/icon/core/chevron-down';
|
|
18
19
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
19
20
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
20
|
-
import { toggleContextualMenu } from '../../pm-plugins/commands';
|
|
21
|
+
import { toggleActiveTableMenu, toggleContextualMenu } from '../../pm-plugins/commands';
|
|
21
22
|
import { isNativeStickySupported } from '../../pm-plugins/utils/sticky-header';
|
|
22
23
|
import { TableCssClassName as ClassName } from '../../types';
|
|
23
24
|
|
|
@@ -34,6 +35,7 @@ const anchorStyles = css({
|
|
|
34
35
|
});
|
|
35
36
|
const FloatingContextualButtonInner = /*#__PURE__*/React.memo(props => {
|
|
36
37
|
const {
|
|
38
|
+
api,
|
|
37
39
|
editorView,
|
|
38
40
|
isContextualMenuOpen,
|
|
39
41
|
mountPoint,
|
|
@@ -46,14 +48,25 @@ const FloatingContextualButtonInner = /*#__PURE__*/React.memo(props => {
|
|
|
46
48
|
formatMessage
|
|
47
49
|
}
|
|
48
50
|
} = props; // : Props & WrappedComponentProps
|
|
49
|
-
|
|
51
|
+
const {
|
|
52
|
+
activeTableMenu
|
|
53
|
+
} = useSharedPluginStateWithSelector(api, ['table'], states => {
|
|
54
|
+
var _states$tableState;
|
|
55
|
+
return {
|
|
56
|
+
activeTableMenu: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : _states$tableState.activeTableMenu
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
const isCellMenuOpen = expValEquals('platform_editor_table_menu_updates', 'isEnabled', true) ? (activeTableMenu === null || activeTableMenu === void 0 ? void 0 : activeTableMenu.type) === 'cell' : isContextualMenuOpen;
|
|
50
60
|
const handleClick = () => {
|
|
51
61
|
const {
|
|
52
62
|
state,
|
|
53
63
|
dispatch
|
|
54
64
|
} = editorView;
|
|
55
65
|
if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
|
|
56
|
-
|
|
66
|
+
toggleActiveTableMenu({
|
|
67
|
+
type: 'cell',
|
|
68
|
+
openedBy: 'mouse'
|
|
69
|
+
})(state, dispatch);
|
|
57
70
|
return;
|
|
58
71
|
}
|
|
59
72
|
|
|
@@ -69,15 +82,22 @@ const FloatingContextualButtonInner = /*#__PURE__*/React.memo(props => {
|
|
|
69
82
|
const domAtPos = editorView.domAtPos.bind(editorView);
|
|
70
83
|
const targetCellRef = findDomRefAtPos(targetCellPosition, domAtPos);
|
|
71
84
|
useEffect(() => {
|
|
72
|
-
if (isCellMenuOpenByKeyboard && !
|
|
85
|
+
if (isCellMenuOpenByKeyboard && !isCellMenuOpen) {
|
|
73
86
|
const {
|
|
74
87
|
state,
|
|
75
88
|
dispatch
|
|
76
89
|
} = editorView;
|
|
77
90
|
// open the menu when the keyboard shortcut is pressed
|
|
91
|
+
if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
|
|
92
|
+
toggleActiveTableMenu({
|
|
93
|
+
type: 'cell',
|
|
94
|
+
openedBy: 'keyboard'
|
|
95
|
+
})(state, dispatch);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
78
98
|
toggleContextualMenu()(state, dispatch);
|
|
79
99
|
}
|
|
80
|
-
}, [isCellMenuOpenByKeyboard,
|
|
100
|
+
}, [isCellMenuOpenByKeyboard, isCellMenuOpen, editorView]);
|
|
81
101
|
if (!targetCellRef || !(targetCellRef instanceof HTMLElement)) {
|
|
82
102
|
return null;
|
|
83
103
|
}
|
|
@@ -87,12 +107,12 @@ const FloatingContextualButtonInner = /*#__PURE__*/React.memo(props => {
|
|
|
87
107
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
88
108
|
tableFloatingCellButtonStyles(),
|
|
89
109
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
90
|
-
|
|
110
|
+
isCellMenuOpen && tableFloatingCellButtonSelectedStyles()]
|
|
91
111
|
}, jsx(ToolbarButton
|
|
92
112
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
93
113
|
, {
|
|
94
114
|
className: ClassName.CONTEXTUAL_MENU_BUTTON,
|
|
95
|
-
selected:
|
|
115
|
+
selected: isCellMenuOpen,
|
|
96
116
|
title: labelCellOptions,
|
|
97
117
|
keymap: focusToContextMenuTrigger,
|
|
98
118
|
onClick: handleClick,
|
|
@@ -102,7 +122,7 @@ const FloatingContextualButtonInner = /*#__PURE__*/React.memo(props => {
|
|
|
102
122
|
size: "small"
|
|
103
123
|
}),
|
|
104
124
|
"aria-label": labelCellOptions,
|
|
105
|
-
"aria-expanded":
|
|
125
|
+
"aria-expanded": isCellMenuOpen
|
|
106
126
|
}));
|
|
107
127
|
const parentSticky = targetCellRef.parentElement && targetCellRef.parentElement.className.indexOf('sticky') > -1;
|
|
108
128
|
const parentStickyNative = targetCellRef.parentElement && (fg('platform_editor_table_sticky_header_patch_4') ? tableWrapper === null || tableWrapper === void 0 ? void 0 : tableWrapper.classList.contains(ClassName.TABLE_NODE_WRAPPER_NO_OVERFLOW) : targetCellRef.parentElement.classList.contains(ClassName.NATIVE_STICKY));
|
|
@@ -157,7 +177,7 @@ const FloatingContextualButtonInner = /*#__PURE__*/React.memo(props => {
|
|
|
157
177
|
targetCellPosition: targetCellPosition,
|
|
158
178
|
targetCellRef: targetCellRef,
|
|
159
179
|
mountTo: tableWrapper,
|
|
160
|
-
isContextualMenuOpen:
|
|
180
|
+
isContextualMenuOpen: isCellMenuOpen
|
|
161
181
|
}, button);
|
|
162
182
|
}
|
|
163
183
|
return jsx(Popup, {
|
|
@@ -1,100 +1,83 @@
|
|
|
1
|
-
import React, { useCallback,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import React, { useCallback, useContext, useRef } from 'react';
|
|
2
|
+
import { Popup } from '@atlaskit/editor-common/ui';
|
|
3
|
+
import { OutsideClickTargetRefContext, withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-react';
|
|
4
4
|
import { UserIntentPopupWrapper } from '@atlaskit/editor-common/user-intent';
|
|
5
|
-
import {
|
|
5
|
+
import { closeActiveTableMenu, setFocusToCellMenu } from '../../pm-plugins/commands';
|
|
6
|
+
import { getPluginState } from '../../pm-plugins/plugin-factory';
|
|
6
7
|
import { TableCssClassName as ClassName } from '../../types';
|
|
8
|
+
import { tablePopupMenuFitHeight } from '../consts';
|
|
7
9
|
import { CELL_MENU } from '../TableMenu/cell/keys';
|
|
10
|
+
import { TABLE_MENU_WIDTH } from '../TableMenu/shared/consts';
|
|
8
11
|
import { TableMenu } from '../TableMenu/shared/TableMenu';
|
|
12
|
+
const PopupWithListeners = withReactEditorViewOuterListeners(Popup);
|
|
13
|
+
const NESTED_DROPDOWN_SELECTOR = '[data-toolbar-nested-dropdown-menu]';
|
|
14
|
+
const CELL_MENU_TRIGGER_SELECTOR = `.${ClassName.CONTEXTUAL_MENU_BUTTON}`;
|
|
9
15
|
export const CellMenuPopup = ({
|
|
10
16
|
api,
|
|
17
|
+
boundariesElement,
|
|
11
18
|
editorView,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
targetCellRef
|
|
19
|
+
mountPoint,
|
|
20
|
+
scrollableElement,
|
|
21
|
+
targetCellRef,
|
|
22
|
+
zIndex
|
|
15
23
|
}) => {
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
currentUserIntent: (_states$userIntentSta = states.userIntentState) === null || _states$userIntentSta === void 0 ? void 0 : _states$userIntentSta.currentUserIntent
|
|
23
|
-
};
|
|
24
|
-
});
|
|
24
|
+
const popupContentRef = useRef(null);
|
|
25
|
+
const setOutsideClickTargetRef = useContext(OutsideClickTargetRefContext);
|
|
26
|
+
const handlePopupRef = useCallback(el => {
|
|
27
|
+
popupContentRef.current = el;
|
|
28
|
+
setOutsideClickTargetRef === null || setOutsideClickTargetRef === void 0 ? void 0 : setOutsideClickTargetRef(el);
|
|
29
|
+
}, [setOutsideClickTargetRef]);
|
|
25
30
|
const closeCellMenu = useCallback(() => {
|
|
26
31
|
const {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} = editorView;
|
|
31
|
-
toggleContextualMenu()(state, dispatch);
|
|
32
|
+
isCellMenuOpenByKeyboard
|
|
33
|
+
} = getPluginState(editorView.state);
|
|
34
|
+
closeActiveTableMenu()(editorView.state, editorView.dispatch);
|
|
32
35
|
if (isCellMenuOpenByKeyboard) {
|
|
33
|
-
setFocusToCellMenu(false)(state, dispatch);
|
|
34
|
-
dom.focus();
|
|
36
|
+
setFocusToCellMenu(false)(editorView.state, editorView.dispatch);
|
|
35
37
|
}
|
|
36
|
-
}, [editorView
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
}, [editorView]);
|
|
39
|
+
const isEventInsideCellMenu = useCallback(event => {
|
|
40
|
+
var _popupContentRef$curr;
|
|
41
|
+
const target = event.target;
|
|
42
|
+
if (!(target instanceof Node)) {
|
|
43
|
+
return false;
|
|
40
44
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
if (!isOpen) {
|
|
45
|
-
return;
|
|
45
|
+
if ((_popupContentRef$curr = popupContentRef.current) !== null && _popupContentRef$curr !== void 0 && _popupContentRef$curr.contains(target)) {
|
|
46
|
+
return true;
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
+
return target instanceof Element && Boolean(target.closest(NESTED_DROPDOWN_SELECTOR) || target.closest(CELL_MENU_TRIGGER_SELECTOR));
|
|
49
|
+
}, []);
|
|
50
|
+
const handleCellMenuClickOutside = useCallback(event => {
|
|
51
|
+
if (isEventInsideCellMenu(event)) {
|
|
48
52
|
return;
|
|
49
53
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
type: 'pointerdown',
|
|
73
|
-
listener: handlePointerDown,
|
|
74
|
-
options: {
|
|
75
|
-
capture: true
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
const unbindKeyDown = bind(ownerDocument, {
|
|
79
|
-
type: 'keydown',
|
|
80
|
-
listener: handleKeyDown,
|
|
81
|
-
options: {
|
|
82
|
-
capture: true
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
return () => {
|
|
86
|
-
unbindPointerDown();
|
|
87
|
-
unbindKeyDown();
|
|
88
|
-
};
|
|
89
|
-
}, [closeCellMenu, isOpen, targetCellRef]);
|
|
90
|
-
return /*#__PURE__*/React.createElement(UserIntentPopupWrapper, {
|
|
54
|
+
closeCellMenu();
|
|
55
|
+
}, [closeCellMenu, isEventInsideCellMenu]);
|
|
56
|
+
return /*#__PURE__*/React.createElement(PopupWithListeners, {
|
|
57
|
+
alignX: "right",
|
|
58
|
+
alignY: "top",
|
|
59
|
+
target: targetCellRef,
|
|
60
|
+
mountTo: mountPoint,
|
|
61
|
+
boundariesElement: boundariesElement,
|
|
62
|
+
scrollableElement: scrollableElement,
|
|
63
|
+
fitHeight: tablePopupMenuFitHeight,
|
|
64
|
+
fitWidth: TABLE_MENU_WIDTH,
|
|
65
|
+
zIndex: zIndex,
|
|
66
|
+
forcePlacement: true
|
|
67
|
+
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
|
|
68
|
+
,
|
|
69
|
+
offset: [-7, 0],
|
|
70
|
+
stick: true,
|
|
71
|
+
handleClickOutside: handleCellMenuClickOutside,
|
|
72
|
+
handleEscapeKeydown: closeCellMenu
|
|
73
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
74
|
+
ref: handlePopupRef
|
|
75
|
+
}, /*#__PURE__*/React.createElement(UserIntentPopupWrapper, {
|
|
91
76
|
api: api,
|
|
92
77
|
userIntent: "tableContextualMenuPopupOpen"
|
|
93
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
94
|
-
ref: tableMenuRef
|
|
95
78
|
}, /*#__PURE__*/React.createElement(TableMenu, {
|
|
96
79
|
api: api,
|
|
97
80
|
editorView: editorView,
|
|
98
81
|
surface: CELL_MENU
|
|
99
|
-
})));
|
|
82
|
+
}))));
|
|
100
83
|
};
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
6
6
|
import { jsx } from '@emotion/react';
|
|
7
|
+
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
7
8
|
import { Popup } from '@atlaskit/editor-common/ui';
|
|
8
9
|
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
9
10
|
import { akEditorFloatingDialogZIndex, akEditorFloatingOverlapPanelZIndex } from '@atlaskit/editor-shared-styles';
|
|
@@ -11,7 +12,6 @@ import { findCellRectClosestToPos, getSelectionRect, isSelectionType } from '@at
|
|
|
11
12
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
12
13
|
import { getPluginState } from '../../pm-plugins/plugin-factory';
|
|
13
14
|
import { contextualMenuDropdownWidthDnD, contextualMenuTriggerSize, tablePopupMenuFitHeight } from '../consts';
|
|
14
|
-
import { TABLE_MENU_WIDTH } from '../TableMenu/shared/consts';
|
|
15
15
|
import { CellMenuPopup } from './CellMenuPopup';
|
|
16
16
|
// Ignored via go/ees005
|
|
17
17
|
// eslint-disable-next-line import/no-named-as-default
|
|
@@ -32,6 +32,15 @@ const FloatingContextualMenu = ({
|
|
|
32
32
|
api,
|
|
33
33
|
isDragMenuOpen
|
|
34
34
|
}) => {
|
|
35
|
+
const {
|
|
36
|
+
activeTableMenu
|
|
37
|
+
} = useSharedPluginStateWithSelector(api, ['table'], states => {
|
|
38
|
+
var _states$tableState;
|
|
39
|
+
return {
|
|
40
|
+
activeTableMenu: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : _states$tableState.activeTableMenu
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
const isCellMenuOpen = expValEquals('platform_editor_table_menu_updates', 'isEnabled', true) ? (activeTableMenu === null || activeTableMenu === void 0 ? void 0 : activeTableMenu.type) === 'cell' : isOpen;
|
|
35
44
|
if (!editorView) {
|
|
36
45
|
return null;
|
|
37
46
|
}
|
|
@@ -40,7 +49,7 @@ const FloatingContextualMenu = ({
|
|
|
40
49
|
const {
|
|
41
50
|
targetCellPosition
|
|
42
51
|
} = getPluginState(editorView.state);
|
|
43
|
-
if (!
|
|
52
|
+
if (!isCellMenuOpen || !targetCellPosition || editorView.state.doc.nodeSize <= targetCellPosition) {
|
|
44
53
|
return null;
|
|
45
54
|
}
|
|
46
55
|
const {
|
|
@@ -59,6 +68,20 @@ const FloatingContextualMenu = ({
|
|
|
59
68
|
return null;
|
|
60
69
|
}
|
|
61
70
|
const parentSticky = targetCellRef.parentElement && targetCellRef.parentElement.className.indexOf('sticky') > -1;
|
|
71
|
+
if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
|
|
72
|
+
return jsx(CellMenuPopup, {
|
|
73
|
+
api: api,
|
|
74
|
+
boundariesElement: boundariesElement,
|
|
75
|
+
editorView: editorView,
|
|
76
|
+
mountPoint: mountPoint,
|
|
77
|
+
scrollableElement: scrollableElement
|
|
78
|
+
// Ignored via go/ees005
|
|
79
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
80
|
+
,
|
|
81
|
+
targetCellRef: targetCellRef,
|
|
82
|
+
zIndex: parentSticky ? akEditorFloatingDialogZIndex : akEditorFloatingOverlapPanelZIndex
|
|
83
|
+
});
|
|
84
|
+
}
|
|
62
85
|
return jsx(Popup, {
|
|
63
86
|
alignX: "right",
|
|
64
87
|
alignY: "top"
|
|
@@ -70,7 +93,7 @@ const FloatingContextualMenu = ({
|
|
|
70
93
|
boundariesElement: boundariesElement,
|
|
71
94
|
scrollableElement: scrollableElement,
|
|
72
95
|
fitHeight: tablePopupMenuFitHeight,
|
|
73
|
-
fitWidth:
|
|
96
|
+
fitWidth: contextualMenuDropdownWidthDnD
|
|
74
97
|
// z-index value below is to ensure that this menu is above other floating menu
|
|
75
98
|
// in table, but below floating dialogs like typeaheads, pickers, etc.
|
|
76
99
|
,
|
|
@@ -80,15 +103,7 @@ const FloatingContextualMenu = ({
|
|
|
80
103
|
,
|
|
81
104
|
offset: [-7, 0],
|
|
82
105
|
stick: true
|
|
83
|
-
},
|
|
84
|
-
api: api,
|
|
85
|
-
editorView: editorView,
|
|
86
|
-
isCellMenuOpenByKeyboard: isCellMenuOpenByKeyboard,
|
|
87
|
-
isOpen: isOpen,
|
|
88
|
-
targetCellRef: targetCellRef
|
|
89
|
-
}) :
|
|
90
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
91
|
-
jsx("div", {
|
|
106
|
+
}, jsx("div", {
|
|
92
107
|
css: tablePopupStyles()
|
|
93
108
|
}, jsx(ContextualMenu, {
|
|
94
109
|
editorView: editorView
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
2
3
|
import { Popup } from '@atlaskit/editor-common/ui';
|
|
3
4
|
import { UserIntentPopupWrapper } from '@atlaskit/editor-common/user-intent';
|
|
4
5
|
import { akEditorFloatingDialogZIndex, akEditorFloatingOverlapPanelZIndex } from '@atlaskit/editor-shared-styles';
|
|
@@ -35,11 +36,24 @@ const FloatingDragMenu = ({
|
|
|
35
36
|
tableWrapper
|
|
36
37
|
}) => {
|
|
37
38
|
var _getEditorFeatureFlag;
|
|
38
|
-
|
|
39
|
+
const {
|
|
40
|
+
activeTableMenu
|
|
41
|
+
} = useSharedPluginStateWithSelector(api, ['table'], states => {
|
|
42
|
+
var _states$tableState;
|
|
43
|
+
return {
|
|
44
|
+
activeTableMenu: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : _states$tableState.activeTableMenu
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
const isActiveTableMenuDragMenu = (activeTableMenu === null || activeTableMenu === void 0 ? void 0 : activeTableMenu.type) === 'row' || (activeTableMenu === null || activeTableMenu === void 0 ? void 0 : activeTableMenu.type) === 'column';
|
|
48
|
+
const hasActiveTableMenuState = activeTableMenu !== undefined;
|
|
49
|
+
const isDragMenuOpen = expValEquals('platform_editor_table_menu_updates', 'isEnabled', true) && hasActiveTableMenuState ? isActiveTableMenuDragMenu : isOpen;
|
|
50
|
+
const dragMenuDirection = expValEquals('platform_editor_table_menu_updates', 'isEnabled', true) && hasActiveTableMenuState ? isActiveTableMenuDragMenu ? activeTableMenu.type : undefined : direction;
|
|
51
|
+
const dragMenuIndex = expValEquals('platform_editor_table_menu_updates', 'isEnabled', true) && hasActiveTableMenuState ? isActiveTableMenuDragMenu ? activeTableMenu.index : undefined : index;
|
|
52
|
+
if (!isDragMenuOpen || !targetCellPosition || editorView.state.doc.nodeSize <= targetCellPosition) {
|
|
39
53
|
return null;
|
|
40
54
|
}
|
|
41
55
|
const inStickyMode = (stickyHeaders === null || stickyHeaders === void 0 ? void 0 : stickyHeaders.sticky) || (tableWrapper === null || tableWrapper === void 0 ? void 0 : tableWrapper.classList.contains(ClassName.TABLE_NODE_WRAPPER_NO_OVERFLOW)) && fg('platform_editor_table_sticky_header_patch_7');
|
|
42
|
-
const targetHandleRef =
|
|
56
|
+
const targetHandleRef = dragMenuDirection === 'row' ? document.querySelector('#drag-handle-button-row') : document.querySelector('#drag-handle-button-column');
|
|
43
57
|
if (!targetHandleRef || !(editorView.state.selection instanceof CellSelection)) {
|
|
44
58
|
return null;
|
|
45
59
|
}
|
|
@@ -48,8 +62,8 @@ const FloatingDragMenu = ({
|
|
|
48
62
|
} = (_getEditorFeatureFlag = getEditorFeatureFlags === null || getEditorFeatureFlags === void 0 ? void 0 : getEditorFeatureFlags()) !== null && _getEditorFeatureFlag !== void 0 ? _getEditorFeatureFlag : {};
|
|
49
63
|
const shouldUseIncreasedScalingPercent = isTableScalingEnabled && (tableWithFixedColumnWidthsOption || isCommentEditor);
|
|
50
64
|
return /*#__PURE__*/React.createElement(Popup, {
|
|
51
|
-
alignX:
|
|
52
|
-
alignY:
|
|
65
|
+
alignX: dragMenuDirection === 'row' ? 'right' : undefined,
|
|
66
|
+
alignY: dragMenuDirection === 'row' ? 'start' : undefined
|
|
53
67
|
// Ignored via go/ees005
|
|
54
68
|
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
55
69
|
,
|
|
@@ -73,13 +87,13 @@ const FloatingDragMenu = ({
|
|
|
73
87
|
}, /*#__PURE__*/React.createElement(TableMenu, {
|
|
74
88
|
api: api,
|
|
75
89
|
editorView: editorView,
|
|
76
|
-
surface:
|
|
90
|
+
surface: dragMenuDirection === 'row' ? ROW_MENU : COLUMN_MENU
|
|
77
91
|
})) : /*#__PURE__*/React.createElement(DragMenu, {
|
|
78
92
|
editorView: editorView,
|
|
79
|
-
isOpen:
|
|
93
|
+
isOpen: isDragMenuOpen,
|
|
80
94
|
tableNode: tableNode,
|
|
81
|
-
direction:
|
|
82
|
-
index:
|
|
95
|
+
direction: dragMenuDirection,
|
|
96
|
+
index: dragMenuIndex,
|
|
83
97
|
target: targetHandleRef || undefined,
|
|
84
98
|
targetCellPosition: targetCellPosition,
|
|
85
99
|
getEditorContainerWidth: getEditorContainerWidth,
|