@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,93 +0,0 @@
|
|
|
1
|
-
import type { NodeType } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
import { NodeRange } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
// @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
|
|
4
|
-
import type { ReadonlyTransaction, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
-
import { findWrapping } from '@atlaskit/editor-prosemirror/transform';
|
|
6
|
-
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
7
|
-
|
|
8
|
-
interface IsTableCollapsibleResult {
|
|
9
|
-
tableIsCollapsible: boolean;
|
|
10
|
-
range?: NodeRange;
|
|
11
|
-
findWrappingRes?: // Ignored via go/ees005
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
-
Array<{ type: NodeType; attrs?: { [key: string]: any } | null }> | null | undefined;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const bail = () => ({
|
|
17
|
-
tableIsCollapsible: false,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Checks whether we can wrap the selected table into an expand via
|
|
22
|
-
* prosemirror-transform's `findWrapping` helper
|
|
23
|
-
*/
|
|
24
|
-
export const isTableCollapsible = (
|
|
25
|
-
tr: Transaction | ReadonlyTransaction,
|
|
26
|
-
): IsTableCollapsibleResult => {
|
|
27
|
-
const selection = tr.selection;
|
|
28
|
-
const schema = tr.doc.type.schema;
|
|
29
|
-
const nodePos = findTable(selection);
|
|
30
|
-
|
|
31
|
-
if (!nodePos) {
|
|
32
|
-
return bail();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const expand = schema.nodes.expand as NodeType;
|
|
36
|
-
const { node, pos } = nodePos;
|
|
37
|
-
const $pos = tr.doc.resolve(pos);
|
|
38
|
-
const range = new NodeRange($pos, tr.doc.resolve(pos + node.nodeSize), $pos.depth);
|
|
39
|
-
|
|
40
|
-
if (!range) {
|
|
41
|
-
return bail();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const canWrap = findWrapping(range, expand);
|
|
45
|
-
if (canWrap === null) {
|
|
46
|
-
return bail();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
tableIsCollapsible: true,
|
|
51
|
-
range,
|
|
52
|
-
/**
|
|
53
|
-
* Do we ever want to deal with the result of `findWrapping`? Probably not,
|
|
54
|
-
* but we have it anyway.
|
|
55
|
-
*/
|
|
56
|
-
findWrappingRes: canWrap,
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Collapses the selected table into an expand given a transaction via
|
|
62
|
-
* `Transform.wrap`.
|
|
63
|
-
*
|
|
64
|
-
* Will return undefined if it cannot determine the relevant table from a
|
|
65
|
-
* selection, or if the table itself isn't collapsible.
|
|
66
|
-
*
|
|
67
|
-
* @param tr
|
|
68
|
-
* @returns Transaction | undefined
|
|
69
|
-
*/
|
|
70
|
-
export const collapseSelectedTable = (tr: Transaction): Transaction | undefined => {
|
|
71
|
-
const canCollapse = isTableCollapsible(tr);
|
|
72
|
-
const expand = tr.doc.type.schema.nodes.expand as NodeType;
|
|
73
|
-
|
|
74
|
-
if (!canCollapse.range || !canCollapse.tableIsCollapsible) {
|
|
75
|
-
return undefined;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* TODO: add attrs: { __expanded: false } when
|
|
80
|
-
* - it is working with new collab (CEMS-1204)
|
|
81
|
-
* - synchrony is no longer used
|
|
82
|
-
*
|
|
83
|
-
* (via confluence-frontend, "this feature" referencing allowInteractiveExpand)
|
|
84
|
-
* `we can NEVER allow this feature to be enabled for the synchrony-powered editor
|
|
85
|
-
*/
|
|
86
|
-
tr.wrap(canCollapse.range, [
|
|
87
|
-
{
|
|
88
|
-
type: expand,
|
|
89
|
-
},
|
|
90
|
-
]).setMeta('scrollIntoView', true);
|
|
91
|
-
|
|
92
|
-
return tr;
|
|
93
|
-
};
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
import { maphElem } from '@atlaskit/editor-common/utils';
|
|
2
|
-
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
-
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
4
|
-
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
5
|
-
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
6
|
-
import { findTable, getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
7
|
-
|
|
8
|
-
import { tableDeleteButtonSize } from '../../ui/consts';
|
|
9
|
-
|
|
10
|
-
interface CellWidthInfo {
|
|
11
|
-
width: number;
|
|
12
|
-
colspan: number;
|
|
13
|
-
colwidth: string | undefined;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const getColumnsWidths = (view: EditorView): Array<number | undefined> => {
|
|
17
|
-
const { selection } = view.state;
|
|
18
|
-
let widths: Array<number | undefined> = [];
|
|
19
|
-
const table = findTable(selection);
|
|
20
|
-
if (table) {
|
|
21
|
-
const map = TableMap.get(table.node);
|
|
22
|
-
const domAtPos = view.domAtPos.bind(view);
|
|
23
|
-
|
|
24
|
-
// When there is no cell we need to fill it with undefined
|
|
25
|
-
widths = Array.from({ length: map.width });
|
|
26
|
-
for (let i = 0; i < map.width; i++) {
|
|
27
|
-
if (!map.isCellMergedTopLeft(0, i)) {
|
|
28
|
-
// Ignored via go/ees005
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
30
|
-
const node = table.node.nodeAt(map.map[i])!;
|
|
31
|
-
const pos = map.map[i] + table.start;
|
|
32
|
-
// Ignored via go/ees005
|
|
33
|
-
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
34
|
-
const cellRef = findDomRefAtPos(pos, domAtPos) as HTMLElement;
|
|
35
|
-
const rect = cellRef.getBoundingClientRect();
|
|
36
|
-
widths[i] = (rect ? rect.width : cellRef.offsetWidth) + 1;
|
|
37
|
-
i += node.attrs.colspan - 1;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return widths;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const getColumnDeleteButtonParams = (
|
|
45
|
-
columnsWidths: Array<number | undefined>,
|
|
46
|
-
selection: Selection,
|
|
47
|
-
): { left: number; indexes: number[] } | null => {
|
|
48
|
-
const rect = getSelectionRect(selection);
|
|
49
|
-
if (!rect) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
let width = 0;
|
|
53
|
-
let offset = 0;
|
|
54
|
-
// find the columns before the selection
|
|
55
|
-
for (let i = 0; i < rect.left; i++) {
|
|
56
|
-
const colWidth = columnsWidths[i];
|
|
57
|
-
if (colWidth) {
|
|
58
|
-
offset += colWidth - 1;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
// these are the selected columns widths
|
|
62
|
-
const indexes: number[] = [];
|
|
63
|
-
for (let i = rect.left; i < rect.right; i++) {
|
|
64
|
-
const colWidth = columnsWidths[i];
|
|
65
|
-
if (colWidth) {
|
|
66
|
-
width += colWidth;
|
|
67
|
-
indexes.push(i);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const left = offset + width / 2 - tableDeleteButtonSize / 2;
|
|
72
|
-
return { left, indexes };
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
// give a row colspan and a colwidths
|
|
76
|
-
// and map to a row's colwidths
|
|
77
|
-
const mapTableColwidthsToRow = (rowColSpans: number[], tableColWidths: number[]) => {
|
|
78
|
-
let curColIdx = 0;
|
|
79
|
-
const colWidths: number[] = [];
|
|
80
|
-
|
|
81
|
-
rowColSpans.forEach((cellColSpan) => {
|
|
82
|
-
const colWidth = tableColWidths
|
|
83
|
-
.slice(curColIdx, curColIdx + cellColSpan)
|
|
84
|
-
.reduce((acc, val) => acc + val, 0);
|
|
85
|
-
|
|
86
|
-
curColIdx += cellColSpan;
|
|
87
|
-
colWidths.push(colWidth);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
return colWidths;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const getRelativeDomCellWidths = ({ width, colspan, colwidth }: CellWidthInfo) => {
|
|
94
|
-
// For cells with colSpan 1
|
|
95
|
-
// or
|
|
96
|
-
// for cells in a table with unchanged column widths,
|
|
97
|
-
// these are identified by the lack of colwidth data attribute,
|
|
98
|
-
// return equally partitioned total cell width in DOM for each cell.
|
|
99
|
-
if (colspan === 1 || !colwidth) {
|
|
100
|
-
return new Array(colspan).fill(width / colspan);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// For cells that have colSpan > 1 and
|
|
104
|
-
// are part of a table with resized columns
|
|
105
|
-
// return the current total DOM width of the cell multiplied
|
|
106
|
-
// by the percentage of the each individual cell's size.
|
|
107
|
-
// The cell size percentage is calculated using individual colwidth of the cell,
|
|
108
|
-
// from data-colwidth attribute on the cell,
|
|
109
|
-
// divided by the total width of the cells from colwidths for merged cells.
|
|
110
|
-
|
|
111
|
-
// Ex:
|
|
112
|
-
// colwidth = ‘201,102’
|
|
113
|
-
// Total colWidth = 303
|
|
114
|
-
// returned cellWidths = [303 * (201/303), 303 * (102/303)]
|
|
115
|
-
|
|
116
|
-
// For merged cells we get back colwidth as `201,102`
|
|
117
|
-
const cellColWidths = colwidth.split(',').map((colwidth) => Number(colwidth));
|
|
118
|
-
const totalCalculatedCellWidth = cellColWidths.reduce(
|
|
119
|
-
(acc, cellColWidth) => acc + cellColWidth,
|
|
120
|
-
0,
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
return cellColWidths.map((cellColWidth) => width * (cellColWidth / totalCalculatedCellWidth));
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
export const colWidthsForRow = (tr: HTMLTableRowElement) => {
|
|
127
|
-
// get the colspans
|
|
128
|
-
const rowColSpans = maphElem(tr, (cell) =>
|
|
129
|
-
Number(cell.getAttribute('colspan') || 1 /* default to span of 1 */),
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
// Chrome has trouble aligning borders with auto tables
|
|
133
|
-
// and the rest of the page grid. tables with defined
|
|
134
|
-
// column widths align fine.
|
|
135
|
-
//
|
|
136
|
-
// eg a 4x25% table might end up as 189px 190px 190px 190px
|
|
137
|
-
//
|
|
138
|
-
// prefer copying the widths via the DOM
|
|
139
|
-
// or inferring from the next row if one exists
|
|
140
|
-
const copyTarget = (tr.nextElementSibling as HTMLTableRowElement | null) || tr;
|
|
141
|
-
|
|
142
|
-
if (copyTarget) {
|
|
143
|
-
// either from the first row while it's still in the table
|
|
144
|
-
const cellInfos = maphElem(copyTarget, (cell) => ({
|
|
145
|
-
width: cell.getBoundingClientRect().width,
|
|
146
|
-
colspan: Number(cell.getAttribute('colspan') || 1),
|
|
147
|
-
colwidth: cell.dataset.colwidth,
|
|
148
|
-
}));
|
|
149
|
-
|
|
150
|
-
// reverse engineer cell widths from table widths
|
|
151
|
-
const domBasedCellWidths: number[] = [];
|
|
152
|
-
cellInfos.map((cell) => {
|
|
153
|
-
domBasedCellWidths.push(...getRelativeDomCellWidths(cell));
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
if (cellInfos.reduce((acc, cell) => acc + cell.width, 0) !== 0) {
|
|
157
|
-
const newWidths = mapTableColwidthsToRow(rowColSpans, domBasedCellWidths);
|
|
158
|
-
return newWidths.map((px) => `${px}px`).join(' ');
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// as a fallback, just calculate a %, and hope that
|
|
163
|
-
// it aligns perfectly in the user's browser
|
|
164
|
-
const visualColCount = rowColSpans.reduce((acc, val) => acc + val, 0);
|
|
165
|
-
|
|
166
|
-
const pctWidths = rowColSpans.map((cellColSpan) => (cellColSpan / visualColCount) * 100);
|
|
167
|
-
|
|
168
|
-
return pctWidths.map((pct) => `${pct}%`).join(' ');
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
export const convertHTMLCellIndexToColumnIndex = (
|
|
172
|
-
htmlColIndex: number,
|
|
173
|
-
htmlRowIndex: number,
|
|
174
|
-
tableMap: TableMap,
|
|
175
|
-
): number => {
|
|
176
|
-
// Same numbers (positions) in tableMap.map array mean that there are merged cells.
|
|
177
|
-
// Cells can be merged across columns. So we need to check if the cell on the left and current cell have the same value.
|
|
178
|
-
// Cells can be merged acroll rows. So we need to check if the cell above has the same value as current cell.
|
|
179
|
-
// When cell has the same value as the cell above it or the cell to the left of it, html cellIndex won't count it a separete column.
|
|
180
|
-
const width = tableMap.width;
|
|
181
|
-
const map = tableMap.map;
|
|
182
|
-
let htmlColCount = 0;
|
|
183
|
-
|
|
184
|
-
if (htmlRowIndex === 0) {
|
|
185
|
-
for (let colIndex = 0; colIndex < width; colIndex++) {
|
|
186
|
-
if (colIndex === 0 || map[colIndex] !== map[colIndex - 1]) {
|
|
187
|
-
htmlColCount++;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (htmlColCount - 1 === htmlColIndex) {
|
|
191
|
-
return colIndex;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
} else {
|
|
195
|
-
for (let colIndex = 0; colIndex < width; colIndex++) {
|
|
196
|
-
const currentCellMapIndex = htmlRowIndex * width + colIndex;
|
|
197
|
-
const cellAboveMapIndex = (htmlRowIndex - 1) * width + colIndex;
|
|
198
|
-
if (colIndex > 0) {
|
|
199
|
-
if (
|
|
200
|
-
map[currentCellMapIndex] !== map[currentCellMapIndex - 1] &&
|
|
201
|
-
map[currentCellMapIndex] !== map[cellAboveMapIndex]
|
|
202
|
-
) {
|
|
203
|
-
htmlColCount++;
|
|
204
|
-
}
|
|
205
|
-
} else {
|
|
206
|
-
if (map[currentCellMapIndex] !== map[cellAboveMapIndex]) {
|
|
207
|
-
htmlColCount++;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (htmlColCount - 1 === htmlColIndex) {
|
|
212
|
-
return colIndex;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return 0;
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
// When first row has merged cells, our converted column index needs to be mapped.
|
|
221
|
-
export const getColumnIndexMappedToColumnIndexInFirstRow = (
|
|
222
|
-
convertedColIndex: number,
|
|
223
|
-
htmlRowIndex: number,
|
|
224
|
-
tableMap: TableMap,
|
|
225
|
-
): number => {
|
|
226
|
-
const width = tableMap.width;
|
|
227
|
-
const map = tableMap.map;
|
|
228
|
-
const mapColIndexToFistRowColIndex = [];
|
|
229
|
-
let htmlColCounFirstRow = 0;
|
|
230
|
-
let colSpan = 0;
|
|
231
|
-
|
|
232
|
-
if (htmlRowIndex === 0) {
|
|
233
|
-
return convertedColIndex;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
for (let colIndex = 0; colIndex < width; colIndex++) {
|
|
237
|
-
if (colIndex === 0 || map[colIndex] !== map[colIndex - 1]) {
|
|
238
|
-
if (colSpan > 0) {
|
|
239
|
-
htmlColCounFirstRow += colSpan;
|
|
240
|
-
colSpan = 0;
|
|
241
|
-
}
|
|
242
|
-
htmlColCounFirstRow++;
|
|
243
|
-
} else if (map[colIndex] === map[colIndex - 1]) {
|
|
244
|
-
colSpan++;
|
|
245
|
-
}
|
|
246
|
-
mapColIndexToFistRowColIndex[colIndex] = htmlColCounFirstRow - 1;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
return mapColIndexToFistRowColIndex[convertedColIndex];
|
|
250
|
-
};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { TableAttributes } from '@atlaskit/adf-schema';
|
|
2
|
-
import type { Schema } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
import { createTable } from '@atlaskit/editor-tables/utils';
|
|
4
|
-
|
|
5
|
-
import { TABLE_MAX_WIDTH } from '../table-resizing/utils/consts';
|
|
6
|
-
const NESTED_TABLE_DEFAULT_ROWS = 2;
|
|
7
|
-
const NESTED_TABLE_DEFAULT_COLS = 2;
|
|
8
|
-
|
|
9
|
-
type CreateTableOverrides = {
|
|
10
|
-
tableWidth?: TableAttributes['width'] | 'inherit';
|
|
11
|
-
layout?: TableAttributes['layout'];
|
|
12
|
-
rowsCount?: number;
|
|
13
|
-
colsCount?: number;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const createTableWithWidth =
|
|
17
|
-
({
|
|
18
|
-
isTableScalingEnabled,
|
|
19
|
-
isTableAlignmentEnabled,
|
|
20
|
-
isFullWidthModeEnabled,
|
|
21
|
-
isCommentEditor,
|
|
22
|
-
isChromelessEditor,
|
|
23
|
-
isTableResizingEnabled,
|
|
24
|
-
isNestedTable,
|
|
25
|
-
createTableProps,
|
|
26
|
-
}: {
|
|
27
|
-
isTableScalingEnabled?: boolean;
|
|
28
|
-
isTableAlignmentEnabled?: boolean;
|
|
29
|
-
isFullWidthModeEnabled?: boolean;
|
|
30
|
-
isCommentEditor?: boolean;
|
|
31
|
-
isChromelessEditor?: boolean;
|
|
32
|
-
isTableResizingEnabled?: boolean;
|
|
33
|
-
isNestedTable?: boolean;
|
|
34
|
-
createTableProps?: {
|
|
35
|
-
rowsCount?: number;
|
|
36
|
-
colsCount?: number;
|
|
37
|
-
};
|
|
38
|
-
}) =>
|
|
39
|
-
(schema: Schema) => {
|
|
40
|
-
const attrsOverrides: CreateTableOverrides = {};
|
|
41
|
-
if (isNestedTable) {
|
|
42
|
-
attrsOverrides.rowsCount = createTableProps?.rowsCount
|
|
43
|
-
? createTableProps?.rowsCount
|
|
44
|
-
: NESTED_TABLE_DEFAULT_ROWS;
|
|
45
|
-
attrsOverrides.colsCount = createTableProps?.colsCount
|
|
46
|
-
? createTableProps?.colsCount
|
|
47
|
-
: NESTED_TABLE_DEFAULT_COLS;
|
|
48
|
-
}
|
|
49
|
-
if (isTableScalingEnabled && isFullWidthModeEnabled && !isCommentEditor) {
|
|
50
|
-
attrsOverrides.tableWidth = TABLE_MAX_WIDTH;
|
|
51
|
-
}
|
|
52
|
-
if (isTableAlignmentEnabled && (isFullWidthModeEnabled || isCommentEditor)) {
|
|
53
|
-
attrsOverrides.layout = 'align-start';
|
|
54
|
-
}
|
|
55
|
-
if ((isCommentEditor && isTableResizingEnabled) || isChromelessEditor) {
|
|
56
|
-
attrsOverrides.tableWidth = 'inherit';
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return createTable({
|
|
60
|
-
schema,
|
|
61
|
-
...createTableProps,
|
|
62
|
-
...attrsOverrides,
|
|
63
|
-
});
|
|
64
|
-
};
|