@atlaskit/editor-plugin-table 12.2.6 → 12.2.7
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 +8 -0
- package/package.json +4 -4
- package/afm-cc/tsconfig.json +0 -123
- package/afm-dev-agents/tsconfig.json +0 -123
- package/afm-jira/tsconfig.json +0 -123
- package/afm-passionfruit/tsconfig.json +0 -123
- package/afm-post-office/tsconfig.json +0 -123
- package/afm-rovo-extension/tsconfig.json +0 -123
- package/afm-townsquare/tsconfig.json +0 -123
- package/afm-volt/tsconfig.json +0 -114
- package/build/tsconfig.json +0 -23
- package/docs/0-intro.tsx +0 -57
- package/src/index.ts +0 -21
- package/src/nodeviews/ExternalDropTargets.tsx +0 -91
- package/src/nodeviews/OverflowShadowsObserver.ts +0 -156
- package/src/nodeviews/TableCell.ts +0 -134
- package/src/nodeviews/TableComponent.tsx +0 -1590
- package/src/nodeviews/TableComponentWithSharedState.tsx +0 -278
- package/src/nodeviews/TableContainer.tsx +0 -926
- package/src/nodeviews/TableNodeViewBase.ts +0 -29
- package/src/nodeviews/TableResizer.tsx +0 -884
- package/src/nodeviews/TableRow.ts +0 -830
- package/src/nodeviews/TableStickyScrollbar.ts +0 -211
- package/src/nodeviews/__mocks__/OverflowShadowsObserver.ts +0 -15
- package/src/nodeviews/__mocks__/OverridableMock.ts +0 -26
- package/src/nodeviews/table-container-styles.ts +0 -9
- package/src/nodeviews/table-node-views.ts +0 -76
- package/src/nodeviews/table.tsx +0 -530
- package/src/nodeviews/toDOM.ts +0 -244
- package/src/nodeviews/types.ts +0 -36
- package/src/nodeviews/update-overflow-shadows.ts +0 -11
- package/src/pm-plugins/analytics/actions.ts +0 -21
- package/src/pm-plugins/analytics/commands.ts +0 -47
- package/src/pm-plugins/analytics/plugin-factory.ts +0 -9
- package/src/pm-plugins/analytics/plugin-key.ts +0 -5
- package/src/pm-plugins/analytics/plugin.ts +0 -80
- package/src/pm-plugins/analytics/reducer.ts +0 -27
- package/src/pm-plugins/analytics/types.ts +0 -20
- package/src/pm-plugins/analytics/utils/moved-event.ts +0 -51
- package/src/pm-plugins/commands/clear.ts +0 -43
- package/src/pm-plugins/commands/collapse.ts +0 -17
- package/src/pm-plugins/commands/column-resize.ts +0 -478
- package/src/pm-plugins/commands/commands-with-analytics.ts +0 -715
- package/src/pm-plugins/commands/delete.ts +0 -42
- package/src/pm-plugins/commands/display-mode.ts +0 -18
- package/src/pm-plugins/commands/go-to-next-cell.ts +0 -198
- package/src/pm-plugins/commands/hover.ts +0 -242
- package/src/pm-plugins/commands/index.ts +0 -51
- package/src/pm-plugins/commands/insert.ts +0 -438
- package/src/pm-plugins/commands/misc.ts +0 -811
- package/src/pm-plugins/commands/referentiality.ts +0 -15
- package/src/pm-plugins/commands/selection.ts +0 -537
- package/src/pm-plugins/commands/sort.ts +0 -102
- package/src/pm-plugins/commands/split-cell.ts +0 -28
- package/src/pm-plugins/commands/toggle.ts +0 -109
- package/src/pm-plugins/create-plugin-config.ts +0 -17
- package/src/pm-plugins/decorations/plugin.ts +0 -107
- package/src/pm-plugins/decorations/utils/column-controls.ts +0 -91
- package/src/pm-plugins/decorations/utils/column-resizing.ts +0 -71
- package/src/pm-plugins/decorations/utils/compose-decorations.ts +0 -9
- package/src/pm-plugins/decorations/utils/types.ts +0 -16
- package/src/pm-plugins/default-table-selection.ts +0 -14
- package/src/pm-plugins/drag-and-drop/actions.ts +0 -48
- package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +0 -222
- package/src/pm-plugins/drag-and-drop/commands.ts +0 -194
- package/src/pm-plugins/drag-and-drop/consts.ts +0 -7
- package/src/pm-plugins/drag-and-drop/plugin-factory.ts +0 -33
- package/src/pm-plugins/drag-and-drop/plugin-key.ts +0 -5
- package/src/pm-plugins/drag-and-drop/plugin.ts +0 -398
- package/src/pm-plugins/drag-and-drop/reducer.ts +0 -38
- package/src/pm-plugins/drag-and-drop/types.ts +0 -18
- package/src/pm-plugins/drag-and-drop/utils/autoscrollers.ts +0 -49
- package/src/pm-plugins/drag-and-drop/utils/getDragBehaviour.ts +0 -9
- package/src/pm-plugins/drag-and-drop/utils/monitor.ts +0 -73
- package/src/pm-plugins/handlers.ts +0 -161
- package/src/pm-plugins/keymap.ts +0 -436
- package/src/pm-plugins/main.ts +0 -433
- package/src/pm-plugins/plugin-factory.ts +0 -42
- package/src/pm-plugins/plugin-key.ts +0 -8
- package/src/pm-plugins/reducer.ts +0 -145
- package/src/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -102
- package/src/pm-plugins/sticky-headers/commands.ts +0 -8
- package/src/pm-plugins/sticky-headers/plugin-key.ts +0 -5
- package/src/pm-plugins/sticky-headers/plugin-state.ts +0 -52
- package/src/pm-plugins/sticky-headers/plugin.ts +0 -12
- package/src/pm-plugins/sticky-headers/types.ts +0 -20
- package/src/pm-plugins/sticky-headers/util.ts +0 -18
- package/src/pm-plugins/table-analytics.ts +0 -100
- package/src/pm-plugins/table-local-id.ts +0 -213
- package/src/pm-plugins/table-resizing/commands.ts +0 -116
- package/src/pm-plugins/table-resizing/event-handlers.ts +0 -352
- package/src/pm-plugins/table-resizing/plugin-factory.ts +0 -29
- package/src/pm-plugins/table-resizing/plugin-key.ts +0 -5
- package/src/pm-plugins/table-resizing/plugin.ts +0 -94
- package/src/pm-plugins/table-resizing/reducer.ts +0 -37
- package/src/pm-plugins/table-resizing/utils/colgroup.ts +0 -306
- package/src/pm-plugins/table-resizing/utils/column-state.ts +0 -120
- package/src/pm-plugins/table-resizing/utils/consts.ts +0 -11
- package/src/pm-plugins/table-resizing/utils/content-width.ts +0 -118
- package/src/pm-plugins/table-resizing/utils/dom.ts +0 -132
- package/src/pm-plugins/table-resizing/utils/misc.ts +0 -282
- package/src/pm-plugins/table-resizing/utils/resize-column.ts +0 -34
- package/src/pm-plugins/table-resizing/utils/resize-logic.ts +0 -289
- package/src/pm-plugins/table-resizing/utils/resize-state.ts +0 -417
- package/src/pm-plugins/table-resizing/utils/scale-table.ts +0 -290
- package/src/pm-plugins/table-resizing/utils/types.ts +0 -25
- package/src/pm-plugins/table-resizing/utils/unit-to-number.ts +0 -1
- package/src/pm-plugins/table-selection-keymap.ts +0 -64
- package/src/pm-plugins/table-size-selector.ts +0 -39
- package/src/pm-plugins/table-width-in-comment-fix.ts +0 -113
- package/src/pm-plugins/table-width.ts +0 -153
- package/src/pm-plugins/transforms/column-width.ts +0 -249
- package/src/pm-plugins/transforms/delete-columns.ts +0 -281
- package/src/pm-plugins/transforms/delete-rows.ts +0 -154
- package/src/pm-plugins/transforms/fix-tables.ts +0 -249
- package/src/pm-plugins/transforms/merge.ts +0 -301
- package/src/pm-plugins/transforms/replace-table.ts +0 -38
- package/src/pm-plugins/transforms/split.ts +0 -90
- package/src/pm-plugins/utils/alignment.ts +0 -33
- package/src/pm-plugins/utils/analytics.ts +0 -238
- package/src/pm-plugins/utils/collapse.ts +0 -93
- package/src/pm-plugins/utils/column-controls.ts +0 -250
- package/src/pm-plugins/utils/create.ts +0 -64
- package/src/pm-plugins/utils/decoration.ts +0 -672
- package/src/pm-plugins/utils/dom.ts +0 -251
- package/src/pm-plugins/utils/drag-menu.tsx +0 -491
- package/src/pm-plugins/utils/get-allow-add-column-custom-step.ts +0 -10
- package/src/pm-plugins/utils/guidelines.ts +0 -30
- package/src/pm-plugins/utils/merged-cells.ts +0 -239
- package/src/pm-plugins/utils/nodes.ts +0 -162
- package/src/pm-plugins/utils/paste.ts +0 -386
- package/src/pm-plugins/utils/row-controls.ts +0 -211
- package/src/pm-plugins/utils/selection.ts +0 -17
- package/src/pm-plugins/utils/snapping.ts +0 -136
- package/src/pm-plugins/utils/table.ts +0 -60
- package/src/pm-plugins/utils/update-plugin-state-decorations.ts +0 -13
- package/src/pm-plugins/view-mode-sort/consts.ts +0 -3
- package/src/pm-plugins/view-mode-sort/index.ts +0 -291
- package/src/pm-plugins/view-mode-sort/plugin-key.ts +0 -7
- package/src/pm-plugins/view-mode-sort/types.ts +0 -23
- package/src/pm-plugins/view-mode-sort/utils.ts +0 -136
- package/src/tablePlugin.tsx +0 -971
- package/src/tablePluginType.ts +0 -102
- package/src/types/index.ts +0 -592
- package/src/ui/ColumnResizeWidget/index.tsx +0 -61
- package/src/ui/ContentComponent.tsx +0 -311
- package/src/ui/DragHandle/HandleIconComponent.tsx +0 -21
- package/src/ui/DragHandle/index.tsx +0 -391
- package/src/ui/DragPreview/index.tsx +0 -51
- package/src/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.tsx +0 -59
- package/src/ui/FloatingContextualButton/FixedButton.tsx +0 -203
- package/src/ui/FloatingContextualButton/index.tsx +0 -168
- package/src/ui/FloatingContextualButton/styles.ts +0 -69
- package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +0 -931
- package/src/ui/FloatingContextualMenu/index.tsx +0 -141
- package/src/ui/FloatingContextualMenu/styles.ts +0 -77
- package/src/ui/FloatingDeleteButton/DeleteButton.tsx +0 -54
- package/src/ui/FloatingDeleteButton/getPopUpOptions.ts +0 -65
- package/src/ui/FloatingDeleteButton/index.tsx +0 -383
- package/src/ui/FloatingDeleteButton/types.ts +0 -3
- package/src/ui/FloatingDragMenu/DragMenu.tsx +0 -668
- package/src/ui/FloatingDragMenu/DropdownMenu.tsx +0 -221
- package/src/ui/FloatingDragMenu/index.tsx +0 -136
- package/src/ui/FloatingDragMenu/styles.ts +0 -83
- package/src/ui/FloatingInsertButton/InsertButton.tsx +0 -263
- package/src/ui/FloatingInsertButton/getPopupOptions.ts +0 -131
- package/src/ui/FloatingInsertButton/index.tsx +0 -314
- package/src/ui/FloatingToolbarLabel/FloatingToolbarLabel.tsx +0 -31
- package/src/ui/SizeSelector/index.tsx +0 -74
- package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +0 -397
- package/src/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +0 -105
- package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +0 -63
- package/src/ui/TableFloatingColumnControls/index.tsx +0 -151
- package/src/ui/TableFloatingControls/CornerControls/ClassicCornerControls.tsx +0 -106
- package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +0 -143
- package/src/ui/TableFloatingControls/CornerControls/types.ts +0 -12
- package/src/ui/TableFloatingControls/FloatingControlsWithSelection.tsx +0 -88
- package/src/ui/TableFloatingControls/NumberColumn/index.tsx +0 -175
- package/src/ui/TableFloatingControls/RowControls/ClassicControls.tsx +0 -131
- package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +0 -429
- package/src/ui/TableFloatingControls/RowDropTarget/index.tsx +0 -96
- package/src/ui/TableFloatingControls/index.tsx +0 -275
- package/src/ui/TableFullWidthLabel/index.tsx +0 -38
- package/src/ui/common-styles.ts +0 -1218
- package/src/ui/consts.ts +0 -109
- package/src/ui/event-handlers.ts +0 -662
- package/src/ui/global-styles.tsx +0 -55
- package/src/ui/hooks/useInternalTablePluginStateSelector.ts +0 -38
- package/src/ui/icons/AddColLeftIcon.tsx +0 -37
- package/src/ui/icons/AddColRightIcon.tsx +0 -37
- package/src/ui/icons/AddRowAboveIcon.tsx +0 -22
- package/src/ui/icons/AddRowBelowIcon.tsx +0 -39
- package/src/ui/icons/DragHandleDisabledIcon.tsx +0 -25
- package/src/ui/icons/DragHandleIcon.tsx +0 -16
- package/src/ui/icons/DragInMotionIcon.tsx +0 -54
- package/src/ui/icons/MergeCellsIcon.tsx +0 -26
- package/src/ui/icons/MinimisedHandle.tsx +0 -15
- package/src/ui/icons/SortingIconWrapper.tsx +0 -43
- package/src/ui/icons/SplitCellIcon.tsx +0 -34
- package/src/ui/toolbar.tsx +0 -1153
- package/src/ui/ui-styles.ts +0 -960
- package/tsconfig.app.json +0 -135
- package/tsconfig.dev.json +0 -54
- package/tsconfig.json +0 -18
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
2
|
-
import { calcTableColumnWidths, getFragmentBackingArray } from '@atlaskit/editor-common/utils';
|
|
3
|
-
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
4
|
-
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
5
|
-
import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
6
|
-
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
COLUMN_MIN_WIDTH,
|
|
10
|
-
MAX_SCALING_PERCENT,
|
|
11
|
-
MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION,
|
|
12
|
-
} from './consts';
|
|
13
|
-
import {
|
|
14
|
-
getScalingPercentForTableWithoutWidth,
|
|
15
|
-
getTableContainerElementWidth,
|
|
16
|
-
getTableScalingPercent,
|
|
17
|
-
} from './misc';
|
|
18
|
-
|
|
19
|
-
type Col = Array<string | { [name: string]: string }>;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* This ensures the combined width of the columns (and tbody) of table is always smaller or equal
|
|
23
|
-
* than the table and table wrapper elements. This is necessary as there is no longer
|
|
24
|
-
* padding on the .pm-table-wrapper, so all elements need to be the same width to avoid
|
|
25
|
-
* overflow.
|
|
26
|
-
*/
|
|
27
|
-
export const getColWidthFix = (colwidth: number, tableColumnCount: number) =>
|
|
28
|
-
colwidth - 1 / tableColumnCount;
|
|
29
|
-
|
|
30
|
-
const generateColStyle = (
|
|
31
|
-
fixedColWidth: number,
|
|
32
|
-
tableWidth: number,
|
|
33
|
-
isCommentEditor?: boolean,
|
|
34
|
-
isChromelessEditor?: boolean,
|
|
35
|
-
isNested?: boolean,
|
|
36
|
-
shouldUseIncreasedScalingPercent?: boolean,
|
|
37
|
-
isNumberColumnEnabled?: boolean,
|
|
38
|
-
isTableHasWidth?: boolean,
|
|
39
|
-
hasTableBeenResized?: boolean,
|
|
40
|
-
) => {
|
|
41
|
-
const maxScalingPercent = shouldUseIncreasedScalingPercent
|
|
42
|
-
? MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION
|
|
43
|
-
: MAX_SCALING_PERCENT;
|
|
44
|
-
const maxScaledRatio = 1 - maxScalingPercent;
|
|
45
|
-
|
|
46
|
-
const isFullPageEditor = !isChromelessEditor && !isCommentEditor;
|
|
47
|
-
|
|
48
|
-
// for nested tables, or chromeless editor, which used non resizable table container
|
|
49
|
-
if (isNested || isChromelessEditor) {
|
|
50
|
-
if (hasTableBeenResized) {
|
|
51
|
-
return `width: max(${fixedColWidth}px, ${tableCellMinWidth}px)`;
|
|
52
|
-
}
|
|
53
|
-
return `width: ${tableCellMinWidth}px)`;
|
|
54
|
-
}
|
|
55
|
-
if (isFullPageEditor || (!isFullPageEditor && isTableHasWidth)) {
|
|
56
|
-
const scaledPercent = isNumberColumnEnabled
|
|
57
|
-
? `calc(calc(var(--ak-editor-table-width) - ${akEditorTableNumberColumnWidth}px - 1px)/${tableWidth})`
|
|
58
|
-
: `calc(calc(var(--ak-editor-table-width) - 1px)/${tableWidth})`;
|
|
59
|
-
return `width: max(calc(${fixedColWidth}px * ${maxScaledRatio}), calc(${fixedColWidth} * ${scaledPercent}), ${tableCellMinWidth}px)`;
|
|
60
|
-
}
|
|
61
|
-
// table resized to full-width in comment editor
|
|
62
|
-
// it doesn't have a width attribute, and cols has been resized
|
|
63
|
-
if (hasTableBeenResized) {
|
|
64
|
-
const scaledPercent = isNumberColumnEnabled
|
|
65
|
-
? `calc(calc(var(--ak-editor-table-width) - ${akEditorTableNumberColumnWidth}px - 1px)/${tableWidth})`
|
|
66
|
-
: `calc(calc(var(--ak-editor-table-width) - 1px)/${tableWidth})`;
|
|
67
|
-
return `width: max(calc(${fixedColWidth} * ${scaledPercent}), ${tableCellMinWidth}px)`;
|
|
68
|
-
}
|
|
69
|
-
return `width: ${tableCellMinWidth}px`;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export const generateColgroupFromNode = (
|
|
73
|
-
table: PmNode,
|
|
74
|
-
isCommentEditor?: boolean,
|
|
75
|
-
isChromelessEditor?: boolean,
|
|
76
|
-
isNested?: boolean,
|
|
77
|
-
isTableScalingEnabled?: boolean,
|
|
78
|
-
shouldUseIncreasedScalingPercent?: boolean,
|
|
79
|
-
) => {
|
|
80
|
-
const cols: Col[] = [];
|
|
81
|
-
const map = TableMap.get(table);
|
|
82
|
-
const isTableHasWidth = !!table.attrs.width;
|
|
83
|
-
const isNumberColumnEnabled = table.attrs.isNumberColumnEnabled || false;
|
|
84
|
-
const isFullPageEditor = !isChromelessEditor && !isCommentEditor;
|
|
85
|
-
|
|
86
|
-
// Ignored via go/ees005
|
|
87
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
88
|
-
table.content.firstChild!.content.forEach((cell) => {
|
|
89
|
-
const colspan = cell.attrs.colspan || 1;
|
|
90
|
-
// if the table has been resized
|
|
91
|
-
if (Array.isArray(cell.attrs.colwidth)) {
|
|
92
|
-
cell.attrs.colwidth.slice(0, colspan).forEach((width) => {
|
|
93
|
-
// existing logic for calculating the width of the column
|
|
94
|
-
const fixedColWidth = getColWidthFix(width, map.width);
|
|
95
|
-
const tableWidth =
|
|
96
|
-
isFullPageEditor || (!isFullPageEditor && isTableHasWidth)
|
|
97
|
-
? getTableContainerElementWidth(table)
|
|
98
|
-
: calcTableColumnWidths(table).reduce((sum, width) => sum + width, 0);
|
|
99
|
-
if (isTableScalingEnabled) {
|
|
100
|
-
cols.push([
|
|
101
|
-
'col',
|
|
102
|
-
{
|
|
103
|
-
style: generateColStyle(
|
|
104
|
-
fixedColWidth,
|
|
105
|
-
tableWidth,
|
|
106
|
-
isCommentEditor,
|
|
107
|
-
isChromelessEditor,
|
|
108
|
-
isNested,
|
|
109
|
-
shouldUseIncreasedScalingPercent,
|
|
110
|
-
isNumberColumnEnabled,
|
|
111
|
-
isTableHasWidth,
|
|
112
|
-
true,
|
|
113
|
-
),
|
|
114
|
-
},
|
|
115
|
-
]);
|
|
116
|
-
} else {
|
|
117
|
-
cols.push([
|
|
118
|
-
'col',
|
|
119
|
-
{
|
|
120
|
-
style: `width: max(${fixedColWidth}px, ${tableCellMinWidth}px)`,
|
|
121
|
-
},
|
|
122
|
-
]);
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
} else {
|
|
126
|
-
// columns has not been resized, so distribute the width evenly
|
|
127
|
-
cols.push(
|
|
128
|
-
...Array.from({ length: colspan }, (_) => {
|
|
129
|
-
const tableWidth = getTableContainerElementWidth(table);
|
|
130
|
-
const columnWidth = tableWidth / map.width || 0;
|
|
131
|
-
const fixedColWidth = getColWidthFix(columnWidth, map.width || 0);
|
|
132
|
-
|
|
133
|
-
return [
|
|
134
|
-
'col',
|
|
135
|
-
{
|
|
136
|
-
style: generateColStyle(
|
|
137
|
-
fixedColWidth,
|
|
138
|
-
tableWidth,
|
|
139
|
-
isCommentEditor,
|
|
140
|
-
isChromelessEditor,
|
|
141
|
-
isNested,
|
|
142
|
-
shouldUseIncreasedScalingPercent,
|
|
143
|
-
isNumberColumnEnabled,
|
|
144
|
-
isTableHasWidth,
|
|
145
|
-
),
|
|
146
|
-
},
|
|
147
|
-
];
|
|
148
|
-
}),
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
return cols;
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
export const generateColgroup = (
|
|
156
|
-
table: PmNode,
|
|
157
|
-
tableRef?: HTMLElement,
|
|
158
|
-
shouldUseIncreasedScalingPercent?: boolean,
|
|
159
|
-
isCommentEditor?: boolean,
|
|
160
|
-
) => {
|
|
161
|
-
const cols: Col[] = [];
|
|
162
|
-
const map = TableMap.get(table);
|
|
163
|
-
|
|
164
|
-
// Ignored via go/ees005
|
|
165
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
166
|
-
table.content.firstChild!.content.forEach((cell) => {
|
|
167
|
-
const colspan = cell.attrs.colspan || 1;
|
|
168
|
-
if (Array.isArray(cell.attrs.colwidth)) {
|
|
169
|
-
// We slice here to guard against our colwidth array having more entries
|
|
170
|
-
// Than the we actually span. We'll patch the document at a later point.
|
|
171
|
-
if (tableRef) {
|
|
172
|
-
// if we have tableRef here, isTableScalingEnabled is true
|
|
173
|
-
let scalePercent = 1;
|
|
174
|
-
if (isCommentEditor && !table.attrs?.width) {
|
|
175
|
-
scalePercent = getScalingPercentForTableWithoutWidth(table, tableRef);
|
|
176
|
-
} else {
|
|
177
|
-
scalePercent = getTableScalingPercent(table, tableRef, shouldUseIncreasedScalingPercent);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
cell.attrs.colwidth.slice(0, colspan).forEach((width) => {
|
|
181
|
-
// existing logic for calculating the width of the column
|
|
182
|
-
const fixedColWidth = getColWidthFix(width, map.width);
|
|
183
|
-
const scaledWidth = fixedColWidth * scalePercent;
|
|
184
|
-
const finalWidth = Math.max(scaledWidth, tableCellMinWidth);
|
|
185
|
-
cols.push([
|
|
186
|
-
'col',
|
|
187
|
-
{
|
|
188
|
-
style: `width: ${finalWidth}px;`,
|
|
189
|
-
},
|
|
190
|
-
]);
|
|
191
|
-
});
|
|
192
|
-
} else {
|
|
193
|
-
cell.attrs.colwidth.slice(0, colspan).forEach((width) => {
|
|
194
|
-
cols.push([
|
|
195
|
-
'col',
|
|
196
|
-
{
|
|
197
|
-
style: `width: ${getColWidthFix(
|
|
198
|
-
width ? Math.max(width, tableCellMinWidth) : tableCellMinWidth,
|
|
199
|
-
map.width,
|
|
200
|
-
)}px;`,
|
|
201
|
-
},
|
|
202
|
-
]);
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
} else {
|
|
206
|
-
// When we have merged cells on the first row (firstChild),
|
|
207
|
-
// We want to ensure we're creating the appropriate amount of
|
|
208
|
-
// cols the table still has.
|
|
209
|
-
cols.push(
|
|
210
|
-
...Array.from({ length: colspan }, (_) => [
|
|
211
|
-
'col',
|
|
212
|
-
{ style: `width: ${tableCellMinWidth}px;` },
|
|
213
|
-
]),
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
return cols;
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
export const insertColgroupFromNode = (
|
|
221
|
-
tableRef: HTMLTableElement | null,
|
|
222
|
-
table: PmNode,
|
|
223
|
-
isTableScalingEnabled = false,
|
|
224
|
-
shouldRemove = true,
|
|
225
|
-
shouldUseIncreasedScalingPercent = false,
|
|
226
|
-
isCommentEditor = false,
|
|
227
|
-
): HTMLCollection => {
|
|
228
|
-
// Ignored via go/ees005
|
|
229
|
-
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
230
|
-
let colgroup = tableRef?.querySelector('colgroup') as HTMLElement;
|
|
231
|
-
if (colgroup && shouldRemove) {
|
|
232
|
-
tableRef?.removeChild(colgroup);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
colgroup = renderColgroupFromNode(
|
|
236
|
-
table,
|
|
237
|
-
isTableScalingEnabled ? tableRef ?? undefined : undefined,
|
|
238
|
-
shouldUseIncreasedScalingPercent,
|
|
239
|
-
isCommentEditor,
|
|
240
|
-
);
|
|
241
|
-
if (shouldRemove) {
|
|
242
|
-
tableRef?.insertBefore(colgroup, tableRef?.firstChild);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
return colgroup.children;
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
export const hasTableBeenResized = (table: PmNode) => {
|
|
249
|
-
// Ignored via go/ees005
|
|
250
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
251
|
-
return !!getFragmentBackingArray(table.content.firstChild!.content).find(
|
|
252
|
-
(cell) => cell.attrs.colwidth,
|
|
253
|
-
);
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
export const hasTableColumnBeenResized = hasTableBeenResized;
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Check if a table has all the column width set to tableCellMinWidth(48px) or null
|
|
260
|
-
*
|
|
261
|
-
* @param table
|
|
262
|
-
* @returns true if all column width is equal to tableCellMinWidth or null, false otherwise
|
|
263
|
-
*/
|
|
264
|
-
export const isMinCellWidthTable = (table: PmNode) => {
|
|
265
|
-
// Ignored via go/ees005
|
|
266
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
267
|
-
const cellArray = getFragmentBackingArray(table.content.firstChild!.content);
|
|
268
|
-
const isTableMinCellWidth = cellArray.every((cell) => {
|
|
269
|
-
return (
|
|
270
|
-
(cell.attrs.colwidth && cell.attrs.colwidth[0] === tableCellMinWidth) ||
|
|
271
|
-
cell.attrs.colwidth === null
|
|
272
|
-
);
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
return isTableMinCellWidth;
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
function renderColgroupFromNode(
|
|
279
|
-
table: PmNode,
|
|
280
|
-
maybeTableRef: HTMLElement | undefined,
|
|
281
|
-
shouldUseIncreasedScalingPercent: boolean,
|
|
282
|
-
isCommentEditor: boolean,
|
|
283
|
-
): HTMLElement {
|
|
284
|
-
const rendered = DOMSerializer.renderSpec(document, [
|
|
285
|
-
'colgroup',
|
|
286
|
-
{},
|
|
287
|
-
...generateColgroup(table, maybeTableRef, shouldUseIncreasedScalingPercent, isCommentEditor),
|
|
288
|
-
]);
|
|
289
|
-
|
|
290
|
-
// Ignored via go/ees005
|
|
291
|
-
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
292
|
-
return rendered.dom as HTMLElement;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
export const getColgroupChildrenLength = (table: PmNode): number => {
|
|
296
|
-
const map = TableMap.get(table);
|
|
297
|
-
return map.width;
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
export const getResizerMinWidth = (node: PmNode) => {
|
|
301
|
-
const currentColumnCount = getColgroupChildrenLength(node);
|
|
302
|
-
const minColumnWidth = Math.min(3, currentColumnCount) * COLUMN_MIN_WIDTH;
|
|
303
|
-
// add an extra pixel as the scale table logic will scale columns to be tableContainerWidth - 1
|
|
304
|
-
// the table can't scale past its min-width, so instead restrict table container min width to avoid that situation
|
|
305
|
-
return minColumnWidth + 1;
|
|
306
|
-
};
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { tableNewColumnMinWidth } from '@atlaskit/editor-common/styles';
|
|
2
|
-
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
4
|
-
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
5
|
-
|
|
6
|
-
import { contentWidth } from './content-width';
|
|
7
|
-
import { unitToNumber } from './unit-to-number';
|
|
8
|
-
|
|
9
|
-
export interface ColumnState {
|
|
10
|
-
index: number;
|
|
11
|
-
width: number;
|
|
12
|
-
minWidth: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Reads `width` and `minWidth` of each column from DOM and returns `ColumnState` containing those values
|
|
16
|
-
export const getColumnStateFromDOM = (
|
|
17
|
-
cells: HTMLElement[],
|
|
18
|
-
index: number,
|
|
19
|
-
minWidth: number,
|
|
20
|
-
): ColumnState => {
|
|
21
|
-
const width = calculateColumnWidth(cells, calculateColumnWidthCallback);
|
|
22
|
-
|
|
23
|
-
const minColumnWidth =
|
|
24
|
-
width < minWidth
|
|
25
|
-
? // for newly created column (where width < minWidth) we set minWidth = tableNewColumnMinWidth (140px atm)
|
|
26
|
-
tableNewColumnMinWidth
|
|
27
|
-
: calculateColumnWidth(cells, calculateColumnMinWidthCallback(minWidth));
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
index,
|
|
31
|
-
width: width < minWidth ? tableNewColumnMinWidth : width,
|
|
32
|
-
minWidth: minColumnWidth,
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export const getFreeSpace = (state: ColumnState) => {
|
|
37
|
-
return Math.max(state.width - state.minWidth, 0);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// Returns DOM refs of all cells in a column by `columnIndex`
|
|
41
|
-
export const getCellsRefsInColumn = (
|
|
42
|
-
columnIndex: number,
|
|
43
|
-
table: PMNode,
|
|
44
|
-
tableStart: number,
|
|
45
|
-
domAtPos: (pos: number) => { node: Node; offset: number },
|
|
46
|
-
): HTMLElement[] => {
|
|
47
|
-
const map = TableMap.get(table);
|
|
48
|
-
const cellsPositions = map.cellsInRect({
|
|
49
|
-
left: columnIndex,
|
|
50
|
-
right: columnIndex + 1,
|
|
51
|
-
top: 0,
|
|
52
|
-
bottom: map.height,
|
|
53
|
-
});
|
|
54
|
-
const cells: HTMLElement[] = [];
|
|
55
|
-
cellsPositions.forEach((pos) => {
|
|
56
|
-
// Ignored via go/ees005
|
|
57
|
-
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
58
|
-
const col = findDomRefAtPos(pos + tableStart, domAtPos) as HTMLElement;
|
|
59
|
-
if (col) {
|
|
60
|
-
cells.push(col);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
return cells;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
// calculates column widths based on `cells` DOM refs
|
|
67
|
-
export const calculateColumnWidth = (
|
|
68
|
-
cells: HTMLElement[],
|
|
69
|
-
calculateColumnWidthCb: (
|
|
70
|
-
css: CSSStyleDeclaration,
|
|
71
|
-
cellRef: HTMLElement,
|
|
72
|
-
colSpan: number,
|
|
73
|
-
) => number,
|
|
74
|
-
): number => {
|
|
75
|
-
let maxColWidth = 0;
|
|
76
|
-
let colSpanWidth = 0;
|
|
77
|
-
|
|
78
|
-
cells.forEach((cellRef) => {
|
|
79
|
-
const css = getComputedStyle(cellRef);
|
|
80
|
-
const colspan = Number(cellRef.getAttribute('colspan') || 1);
|
|
81
|
-
|
|
82
|
-
if (colspan > 1) {
|
|
83
|
-
colSpanWidth = calculateColumnWidthCb(css, cellRef, colspan);
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (css) {
|
|
88
|
-
const colWidth = calculateColumnWidthCb(css, cellRef, colspan);
|
|
89
|
-
maxColWidth = Math.max(colWidth, maxColWidth);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
return maxColWidth || colSpanWidth;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
export const addContainerLeftRightPadding = (amount: number, css: CSSStyleDeclaration): number =>
|
|
97
|
-
amount + unitToNumber(css.paddingLeft) + unitToNumber(css.paddingRight);
|
|
98
|
-
|
|
99
|
-
function calculateColumnWidthCallback(css: CSSStyleDeclaration): number {
|
|
100
|
-
return unitToNumber(css.width);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function calculateColumnMinWidthCallback(
|
|
104
|
-
minColumnWidth: number,
|
|
105
|
-
): (css: CSSStyleDeclaration, cellRef: HTMLElement, colSpan: number) => number {
|
|
106
|
-
return (css, cellRef, colSpan) => {
|
|
107
|
-
if (colSpan && colSpan > 1) {
|
|
108
|
-
return unitToNumber(css.width);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const { minWidth: minContentWidth } = contentWidth(cellRef, cellRef);
|
|
112
|
-
// Override the min width, if there is content that can't collapse
|
|
113
|
-
// Past a certain width.
|
|
114
|
-
return Math.max(
|
|
115
|
-
addContainerLeftRightPadding(minContentWidth, css),
|
|
116
|
-
minContentWidth,
|
|
117
|
-
minColumnWidth,
|
|
118
|
-
);
|
|
119
|
-
};
|
|
120
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export const COLUMN_MIN_WIDTH = 48;
|
|
2
|
-
export const TABLE_MAX_WIDTH = 1800;
|
|
3
|
-
export const FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
|
|
4
|
-
export const MAX_SCALING_PERCENT = 0.3;
|
|
5
|
-
export const MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION = 0.4;
|
|
6
|
-
// Used to calculate the width of a table using the Editor width
|
|
7
|
-
export const TABLE_EDITOR_MARGIN = 76;
|
|
8
|
-
const COMMENT_AK_EDITOR_CONTENT_AREA_PADDING = 20;
|
|
9
|
-
const COMMENT_PM_TABLE_RESIZING_PLUGIN_MARGIN = 12;
|
|
10
|
-
export const TABLE_OFFSET_IN_COMMENT_EDITOR =
|
|
11
|
-
2 * (COMMENT_AK_EDITOR_CONTENT_AREA_PADDING + COMMENT_PM_TABLE_RESIZING_PLUGIN_MARGIN);
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { unitToNumber } from './unit-to-number';
|
|
2
|
-
|
|
3
|
-
// calculates content width of a cell
|
|
4
|
-
export function contentWidth(
|
|
5
|
-
elem: HTMLElement,
|
|
6
|
-
container: HTMLElement,
|
|
7
|
-
colWidths: number[] = [],
|
|
8
|
-
canvas: HTMLCanvasElement = document.createElement('canvas'),
|
|
9
|
-
): { minWidth: number; width: number } {
|
|
10
|
-
return calcContentWidth(elem, container || elem, canvas, colWidths);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function calcContentWidth(
|
|
14
|
-
elem: HTMLElement,
|
|
15
|
-
container: HTMLElement,
|
|
16
|
-
canvas: HTMLCanvasElement,
|
|
17
|
-
colWidths: number[],
|
|
18
|
-
): { minWidth: number; width: number } {
|
|
19
|
-
const flowWidths = [] as number[];
|
|
20
|
-
let curWidth = 0;
|
|
21
|
-
|
|
22
|
-
for (let i = 0; i < elem.childNodes.length; i++) {
|
|
23
|
-
// Ignored via go/ees005
|
|
24
|
-
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
25
|
-
const child = elem.childNodes[i] as HTMLElement;
|
|
26
|
-
|
|
27
|
-
if (child.nodeType === Node.COMMENT_NODE) {
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (child.nodeType === Node.TEXT_NODE) {
|
|
32
|
-
// Ignored via go/ees005
|
|
33
|
-
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
34
|
-
const parent = child.parentNode as HTMLElement;
|
|
35
|
-
const parentStyle = getComputedStyle(parent);
|
|
36
|
-
let contentLength = 0;
|
|
37
|
-
|
|
38
|
-
if (parent.nodeName === 'CODE' || parent.nodeName === 'PRE') {
|
|
39
|
-
contentLength = handlePreText(canvas, parent, child.textContent, parentStyle.font);
|
|
40
|
-
} else {
|
|
41
|
-
contentLength = measureText(canvas, child.textContent, parentStyle.font);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const left = parent.offsetLeft - container.offsetLeft;
|
|
45
|
-
flowWidths.push(curWidth);
|
|
46
|
-
|
|
47
|
-
curWidth += contentLength + left;
|
|
48
|
-
|
|
49
|
-
// If the text isn't meant to wrap, we should set that as a hard limit.
|
|
50
|
-
if (parentStyle.whiteSpace === 'nowrap') {
|
|
51
|
-
// + 3 is for date offset plus cursor
|
|
52
|
-
// TODO: ED-26961 - There should be a programmatic way to get this.
|
|
53
|
-
colWidths.push(parent.offsetWidth + 3);
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
// TODO: ED-26961 - doesn't quite work right with spacing
|
|
57
|
-
const style = getComputedStyle(child);
|
|
58
|
-
|
|
59
|
-
if (style.minWidth && style.minWidth.endsWith('px') && style.minWidth !== '0px') {
|
|
60
|
-
colWidths.push(unitToNumber(style.minWidth));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const { width } = contentWidth(child, container, colWidths, canvas);
|
|
64
|
-
if (style.display && style.display.indexOf('inline') > -1) {
|
|
65
|
-
// is inline element, add to curWidth
|
|
66
|
-
curWidth += width;
|
|
67
|
-
} else {
|
|
68
|
-
// block element, reset curWidth
|
|
69
|
-
flowWidths.push(curWidth);
|
|
70
|
-
curWidth = width;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
flowWidths.push(curWidth);
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
minWidth: colWidths.reduce((oldMax, width) => Math.max(width, oldMax), 0),
|
|
79
|
-
width: flowWidths.reduce((oldMax, width) => Math.max(width, oldMax), 0),
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function measureText(canvas: HTMLCanvasElement, text: string | null, font: string | null): number {
|
|
84
|
-
const ctx = canvas.getContext('2d');
|
|
85
|
-
if (!ctx) {
|
|
86
|
-
return 0;
|
|
87
|
-
}
|
|
88
|
-
if (font) {
|
|
89
|
-
ctx.font = font;
|
|
90
|
-
}
|
|
91
|
-
return Math.round(ctx.measureText(text || '').width);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function handlePreText(
|
|
95
|
-
canvas: HTMLCanvasElement,
|
|
96
|
-
node: HTMLElement,
|
|
97
|
-
textContent: string | null,
|
|
98
|
-
font: string | null,
|
|
99
|
-
): number {
|
|
100
|
-
let parent = node;
|
|
101
|
-
if (node.nodeName === 'CODE') {
|
|
102
|
-
// Ignored via go/ees005
|
|
103
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @atlaskit/editor/no-as-casting
|
|
104
|
-
parent = node.parentNode! as HTMLElement;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Ignored via go/ees005
|
|
108
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
109
|
-
const computedStyle = getComputedStyle(parent!);
|
|
110
|
-
if (textContent && computedStyle.whiteSpace === 'pre') {
|
|
111
|
-
// If white space is pre grab the longest line in the block.
|
|
112
|
-
return textContent
|
|
113
|
-
.split('\n')
|
|
114
|
-
.reduce((acc, current) => Math.max(measureText(canvas, current, font), acc), 0);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return measureText(canvas, textContent, font);
|
|
118
|
-
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { tableCellBorderWidth, tableMarginTop } from '@atlaskit/editor-common/styles';
|
|
2
|
-
import { closestElement, containsClassName, parsePx } from '@atlaskit/editor-common/utils';
|
|
3
|
-
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
-
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
5
|
-
|
|
6
|
-
import { TableCssClassName as ClassName } from '../../../types';
|
|
7
|
-
import { getPluginState as getMainPluginState } from '../../plugin-factory';
|
|
8
|
-
import { colWidthsForRow } from '../../utils/column-controls';
|
|
9
|
-
import { getRowHeights } from '../../utils/row-controls';
|
|
10
|
-
|
|
11
|
-
export const updateControls = () => (state: EditorState) => {
|
|
12
|
-
const { tableRef } = getMainPluginState(state);
|
|
13
|
-
if (!tableRef) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
const tr = tableRef.querySelector('tr');
|
|
17
|
-
if (!tr) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const wrapper = tableRef.parentElement;
|
|
21
|
-
if (!(wrapper && wrapper.parentElement)) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const rowControls = wrapper.parentElement.querySelectorAll<HTMLElement>(
|
|
26
|
-
`.${ClassName.ROW_CONTROLS_BUTTON_WRAP}`,
|
|
27
|
-
);
|
|
28
|
-
const numberedRows = wrapper.parentElement.querySelectorAll<HTMLElement>(
|
|
29
|
-
ClassName.NUMBERED_COLUMN_BUTTON,
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
syncStickyRowToTable(tableRef);
|
|
33
|
-
|
|
34
|
-
const rowHeights = getRowHeights(tableRef);
|
|
35
|
-
|
|
36
|
-
// update rows controls height on resize
|
|
37
|
-
for (let i = 0, count = rowControls.length; i < count; i++) {
|
|
38
|
-
const height = rowHeights[i];
|
|
39
|
-
if (height) {
|
|
40
|
-
rowControls[i].style.height = `${height}px`;
|
|
41
|
-
|
|
42
|
-
if (numberedRows.length) {
|
|
43
|
-
numberedRows[i].style.height = `${height}px`;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export const isClickNear = (event: MouseEvent, click: { x: number; y: number }): boolean => {
|
|
50
|
-
const dx = click.x - event.clientX,
|
|
51
|
-
dy = click.y - event.clientY;
|
|
52
|
-
return dx * dx + dy * dy < 100;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const getResizeCellPos = (view: EditorView, event: MouseEvent): number | null => {
|
|
56
|
-
// Ignored via go/ees005
|
|
57
|
-
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
58
|
-
const target = event.target as HTMLElement;
|
|
59
|
-
|
|
60
|
-
if (!containsClassName(target, ClassName.RESIZE_HANDLE_DECORATION)) {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const tableCell = closestElement(target, 'td, th');
|
|
65
|
-
|
|
66
|
-
if (!tableCell) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const cellStartPosition = view.posAtDOM(tableCell, 0);
|
|
71
|
-
return cellStartPosition - 1;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export const updateStickyMargins = (table: HTMLElement) => {
|
|
75
|
-
const row = table.querySelector('tr.sticky');
|
|
76
|
-
if (!row) {
|
|
77
|
-
table.style.marginTop = '';
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const paddingTop = parsePx(window.getComputedStyle(row).paddingTop || '') || 0;
|
|
82
|
-
|
|
83
|
-
const firstRowHeight = row.getBoundingClientRect().height - paddingTop - tableCellBorderWidth;
|
|
84
|
-
|
|
85
|
-
table.style.marginTop = `${tableMarginTop + firstRowHeight}px`;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const applyColWidthsToStickyRow = (
|
|
89
|
-
// @ts-ignore - CCFE error TS6133: 'colGroup' is declared but its value is never read.
|
|
90
|
-
colGroup: HTMLTableColElement | null,
|
|
91
|
-
headerRow: HTMLTableRowElement,
|
|
92
|
-
) => {
|
|
93
|
-
// sync column widths for the sticky row
|
|
94
|
-
const newCols = colWidthsForRow(headerRow);
|
|
95
|
-
|
|
96
|
-
if (newCols) {
|
|
97
|
-
headerRow.style.gridTemplateColumns = newCols;
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
export const syncStickyRowToTable = (tableRef?: HTMLElement | null) => {
|
|
102
|
-
if (!tableRef) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const headerRow = tableRef.querySelector('tr[data-header-row]') as HTMLTableRowElement;
|
|
107
|
-
|
|
108
|
-
if (!headerRow) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
applyColWidthsToStickyRow(tableRef.querySelector('colgroup'), headerRow);
|
|
112
|
-
applyTableWidthToStickyRow(tableRef, headerRow);
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const applyTableWidthToStickyRow = (tableRef: HTMLElement, headerRow: HTMLTableRowElement) => {
|
|
116
|
-
// Ignored via go/ees005
|
|
117
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
118
|
-
const tbody = tableRef.querySelector('tbody')!;
|
|
119
|
-
const wrapper = tableRef.parentElement;
|
|
120
|
-
|
|
121
|
-
if (tbody && wrapper) {
|
|
122
|
-
// when resizing in Chrome, clientWidth will give us 759px
|
|
123
|
-
// but toggling the sticky class will reset it to 760px.
|
|
124
|
-
//
|
|
125
|
-
// both elements in the dom + inspector will
|
|
126
|
-
// be the same width but at layout will be different..
|
|
127
|
-
const newWidth = Math.min(tbody.offsetWidth + 1, wrapper.offsetWidth);
|
|
128
|
-
|
|
129
|
-
headerRow.style.width = `${newWidth}px`;
|
|
130
|
-
headerRow.scrollLeft = wrapper.scrollLeft;
|
|
131
|
-
}
|
|
132
|
-
};
|