@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,251 +0,0 @@
|
|
|
1
|
-
import { closestElement, containsClassName } from '@atlaskit/editor-common/utils';
|
|
2
|
-
|
|
3
|
-
import { TableCssClassName as ClassName } from '../../types';
|
|
4
|
-
|
|
5
|
-
export const isCell = (node: HTMLElement | null): boolean => {
|
|
6
|
-
return Boolean(
|
|
7
|
-
node &&
|
|
8
|
-
(['TH', 'TD'].indexOf(node.tagName) > -1 ||
|
|
9
|
-
!!closestElement(node, `.${ClassName.TABLE_HEADER_CELL}`) ||
|
|
10
|
-
!!closestElement(node, `.${ClassName.TABLE_CELL}`)),
|
|
11
|
-
);
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const isCornerButton = (node: HTMLElement | null): boolean =>
|
|
15
|
-
containsClassName(node, ClassName.CONTROLS_CORNER_BUTTON);
|
|
16
|
-
|
|
17
|
-
export const isInsertRowButton = (node: HTMLElement | null) =>
|
|
18
|
-
containsClassName(node, ClassName.CONTROLS_INSERT_ROW) ||
|
|
19
|
-
closestElement(node, `.${ClassName.CONTROLS_INSERT_ROW}`) ||
|
|
20
|
-
(containsClassName(node, ClassName.CONTROLS_BUTTON_OVERLAY) &&
|
|
21
|
-
closestElement(node, `.${ClassName.ROW_CONTROLS}`));
|
|
22
|
-
|
|
23
|
-
export const getColumnOrRowIndex = (target: HTMLElement): [number, number] => [
|
|
24
|
-
parseInt(target.getAttribute('data-start-index') || '-1', 10),
|
|
25
|
-
parseInt(target.getAttribute('data-end-index') || '-1', 10),
|
|
26
|
-
];
|
|
27
|
-
|
|
28
|
-
export const isColumnControlsDecorations = (node: HTMLElement | null): boolean =>
|
|
29
|
-
containsClassName(node, ClassName.COLUMN_CONTROLS_DECORATIONS);
|
|
30
|
-
|
|
31
|
-
export const isRowControlsButton = (node: HTMLElement | null): boolean =>
|
|
32
|
-
containsClassName(node, ClassName.ROW_CONTROLS_BUTTON) ||
|
|
33
|
-
containsClassName(node, ClassName.NUMBERED_COLUMN_BUTTON);
|
|
34
|
-
|
|
35
|
-
export const isResizeHandleDecoration = (node: HTMLElement | null): boolean =>
|
|
36
|
-
containsClassName(node, ClassName.RESIZE_HANDLE_DECORATION);
|
|
37
|
-
|
|
38
|
-
export const isTableControlsButton = (node: HTMLElement | null): boolean =>
|
|
39
|
-
containsClassName(node, ClassName.CONTROLS_BUTTON) ||
|
|
40
|
-
containsClassName(node, ClassName.ROW_CONTROLS_BUTTON_WRAP);
|
|
41
|
-
|
|
42
|
-
export const isTableContainerOrWrapper = (node: HTMLElement | null): boolean =>
|
|
43
|
-
containsClassName(node, ClassName.TABLE_CONTAINER) ||
|
|
44
|
-
containsClassName(node, ClassName.TABLE_NODE_WRAPPER);
|
|
45
|
-
|
|
46
|
-
/** drag-and-drop classes */
|
|
47
|
-
export const isDragRowFloatingInsertDot = (node: HTMLElement | null) =>
|
|
48
|
-
containsClassName(node, ClassName.DRAG_ROW_FLOATING_INSERT_DOT_WRAPPER);
|
|
49
|
-
|
|
50
|
-
export const isDragColumnFloatingInsertDot = (node: HTMLElement | null) =>
|
|
51
|
-
containsClassName(node, ClassName.DRAG_COLUMN_FLOATING_INSERT_DOT_WRAPPER);
|
|
52
|
-
|
|
53
|
-
export const isDragCornerButton = (node: HTMLElement | null) =>
|
|
54
|
-
containsClassName(node, ClassName.DRAG_CORNER_BUTTON) ||
|
|
55
|
-
containsClassName(node, ClassName.DRAG_CORNER_BUTTON_INNER);
|
|
56
|
-
|
|
57
|
-
/*
|
|
58
|
-
* This function returns which side of a given element the mouse cursor is,
|
|
59
|
-
* using as a base the half of the width by default, for example:
|
|
60
|
-
*
|
|
61
|
-
* legend
|
|
62
|
-
* ⌖ = mouse pointer
|
|
63
|
-
* ▒ = gap
|
|
64
|
-
*
|
|
65
|
-
* given this box:
|
|
66
|
-
* ┏━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
|
|
67
|
-
* ┃ ┊ ┃
|
|
68
|
-
* ┃ left ┊ right ┃
|
|
69
|
-
* ┃ ┊ ┃
|
|
70
|
-
* ┗━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━┛
|
|
71
|
-
*
|
|
72
|
-
* if the mouse is on the left, it will return `left`,
|
|
73
|
-
* if it is on the right it will return `right`.
|
|
74
|
-
*
|
|
75
|
-
* You can extend this behavior using the parameter `gapInPixels`
|
|
76
|
-
* to determinate if the mouse is inside of a gap for each side,
|
|
77
|
-
* for example:
|
|
78
|
-
*
|
|
79
|
-
* given `gapInPixels` is `5`
|
|
80
|
-
* and given this box:
|
|
81
|
-
* ┏━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
|
|
82
|
-
* ┃▒▒▒▒▒ ┊ ▒▒▒▒▒┃
|
|
83
|
-
* ┃▒▒▒▒▒ left ┊ right ▒▒▒▒▒┃
|
|
84
|
-
* ┃▒▒▒▒▒ ┊ ▒▒▒▒▒┃
|
|
85
|
-
* ┗━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━┛
|
|
86
|
-
*
|
|
87
|
-
* if the mouse cursor is inside of the gap like that:
|
|
88
|
-
*
|
|
89
|
-
* ┏━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
|
|
90
|
-
* ┃▒▒▒▒▒ ┊ ▒▒▒▒▒┃
|
|
91
|
-
* ┃▒▒⌖▒▒ left ┊ right ▒▒▒▒▒┃
|
|
92
|
-
* ┃▒▒▒▒▒ ┊ ▒▒▒▒▒┃
|
|
93
|
-
* ┗━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━┛
|
|
94
|
-
*
|
|
95
|
-
* the function will return `left` because the mouse is inside of the gap on the left side.
|
|
96
|
-
*
|
|
97
|
-
* if the mouse cursor is outside of the gap like that:
|
|
98
|
-
*
|
|
99
|
-
* ┏━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
|
|
100
|
-
* ┃▒▒▒▒▒ ┊ ▒▒▒▒▒┃
|
|
101
|
-
* ┃▒▒▒▒▒ left ⌖ ┊ right ▒▒▒▒▒┃
|
|
102
|
-
* ┃▒▒▒▒▒ ┊ ▒▒▒▒▒┃
|
|
103
|
-
* ┗━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━┛
|
|
104
|
-
*
|
|
105
|
-
* the function will return `null` because the mouse is inside of left
|
|
106
|
-
* but is outside of the gap.
|
|
107
|
-
*
|
|
108
|
-
* the same is valid to the right side.
|
|
109
|
-
*/
|
|
110
|
-
/**
|
|
111
|
-
* This can be used with mouse events to determine the left/right side of the target the pointer is closest too.
|
|
112
|
-
*
|
|
113
|
-
* WARNING: This metod reads properties which can trigger a reflow; use this wisely.
|
|
114
|
-
*
|
|
115
|
-
* @param mouseEvent
|
|
116
|
-
* @param gapInPixels
|
|
117
|
-
* @returns
|
|
118
|
-
*/
|
|
119
|
-
export const getMousePositionHorizontalRelativeByElement = (
|
|
120
|
-
mouseEvent: MouseEvent,
|
|
121
|
-
offsetX: number,
|
|
122
|
-
gapInPixels?: number,
|
|
123
|
-
): 'left' | 'right' | null => {
|
|
124
|
-
const element = mouseEvent.target;
|
|
125
|
-
|
|
126
|
-
if (element instanceof HTMLElement) {
|
|
127
|
-
const width = element.clientWidth; // reflow
|
|
128
|
-
const x = !Number.isNaN(offsetX) ? offsetX : mouseEvent.offsetX; // reflow
|
|
129
|
-
|
|
130
|
-
if (width <= 0) {
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (!gapInPixels) {
|
|
135
|
-
return x / width > 0.5 ? 'right' : 'left';
|
|
136
|
-
} else {
|
|
137
|
-
if (x <= gapInPixels) {
|
|
138
|
-
return 'left';
|
|
139
|
-
} else if (x >= width - gapInPixels) {
|
|
140
|
-
return 'right';
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return null;
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
export const getMousePositionVerticalRelativeByElement = (
|
|
149
|
-
mouseEvent: MouseEvent,
|
|
150
|
-
): 'top' | 'bottom' | null => {
|
|
151
|
-
const element = mouseEvent.target;
|
|
152
|
-
if (element instanceof HTMLElement) {
|
|
153
|
-
const elementRect = element.getBoundingClientRect();
|
|
154
|
-
if (elementRect.height <= 0) {
|
|
155
|
-
return null;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const y = mouseEvent.clientY - elementRect.top;
|
|
159
|
-
return y / elementRect.height > 0.5 ? 'bottom' : 'top';
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return null;
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
export const hasResizeHandler = ({
|
|
166
|
-
columnEndIndexTarget,
|
|
167
|
-
target,
|
|
168
|
-
}: {
|
|
169
|
-
columnEndIndexTarget: number;
|
|
170
|
-
target: HTMLElement;
|
|
171
|
-
}): boolean => {
|
|
172
|
-
const tableElement = closestElement(target, 'table');
|
|
173
|
-
|
|
174
|
-
if (!tableElement) {
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const query = [
|
|
179
|
-
`.${ClassName.RESIZE_HANDLE_DECORATION}`,
|
|
180
|
-
`[data-end-index="${columnEndIndexTarget}"]`,
|
|
181
|
-
];
|
|
182
|
-
|
|
183
|
-
const decorationElement = tableElement.querySelectorAll(query.join(''));
|
|
184
|
-
|
|
185
|
-
if (!decorationElement || decorationElement.length === 0) {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
return true;
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
export type TableDOMElements = {
|
|
193
|
-
wrapper: HTMLDivElement;
|
|
194
|
-
table: HTMLTableElement;
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
export const getTree = (tr: HTMLTableRowElement): TableDOMElements | null => {
|
|
198
|
-
// pm renders into tbody, owned by react
|
|
199
|
-
const tbody = tr.parentElement;
|
|
200
|
-
if (!tbody) {
|
|
201
|
-
return null;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// rendered by react
|
|
205
|
-
const table = tbody.parentElement;
|
|
206
|
-
if (!table) {
|
|
207
|
-
return null;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// rendered by react
|
|
211
|
-
const wrapper = table.parentElement;
|
|
212
|
-
if (!wrapper) {
|
|
213
|
-
return null;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return {
|
|
217
|
-
wrapper: wrapper as HTMLDivElement,
|
|
218
|
-
table: table as HTMLTableElement,
|
|
219
|
-
};
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
export const getTop = (element: HTMLElement | Window | undefined): number => {
|
|
223
|
-
if (!element || element instanceof Window) {
|
|
224
|
-
return 0;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
return element?.getBoundingClientRect?.()?.top ?? 0;
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
export const findNearestCellIndexToPoint = (
|
|
231
|
-
x: number,
|
|
232
|
-
y: number,
|
|
233
|
-
): { row: number; col: number } | undefined => {
|
|
234
|
-
const elements = document.elementsFromPoint(x, y);
|
|
235
|
-
const cell = elements.find(
|
|
236
|
-
(el) => el.nodeName.toUpperCase() === 'TD' || el.nodeName.toUpperCase() === 'TH',
|
|
237
|
-
) as HTMLTableCellElement | undefined;
|
|
238
|
-
const row = (cell?.parentElement ?? undefined) as HTMLTableRowElement | undefined;
|
|
239
|
-
|
|
240
|
-
if (!Number.isFinite(row?.rowIndex) || !Number.isFinite(cell?.cellIndex)) {
|
|
241
|
-
return undefined;
|
|
242
|
-
}
|
|
243
|
-
return {
|
|
244
|
-
// Ignored via go/ees005
|
|
245
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
246
|
-
row: row!.rowIndex,
|
|
247
|
-
// Ignored via go/ees005
|
|
248
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
249
|
-
col: cell!.cellIndex,
|
|
250
|
-
};
|
|
251
|
-
};
|