@atlaskit/editor-plugin-table 12.2.5 → 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.
Files changed (207) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/ui/TableFloatingControls/NumberColumn/index.js +24 -2
  3. package/dist/es2019/ui/TableFloatingControls/NumberColumn/index.js +23 -1
  4. package/dist/esm/ui/TableFloatingControls/NumberColumn/index.js +24 -2
  5. package/package.json +4 -4
  6. package/afm-cc/tsconfig.json +0 -123
  7. package/afm-dev-agents/tsconfig.json +0 -123
  8. package/afm-jira/tsconfig.json +0 -123
  9. package/afm-passionfruit/tsconfig.json +0 -123
  10. package/afm-post-office/tsconfig.json +0 -123
  11. package/afm-rovo-extension/tsconfig.json +0 -123
  12. package/afm-townsquare/tsconfig.json +0 -123
  13. package/afm-volt/tsconfig.json +0 -114
  14. package/build/tsconfig.json +0 -23
  15. package/docs/0-intro.tsx +0 -57
  16. package/src/index.ts +0 -21
  17. package/src/nodeviews/ExternalDropTargets.tsx +0 -91
  18. package/src/nodeviews/OverflowShadowsObserver.ts +0 -156
  19. package/src/nodeviews/TableCell.ts +0 -134
  20. package/src/nodeviews/TableComponent.tsx +0 -1590
  21. package/src/nodeviews/TableComponentWithSharedState.tsx +0 -278
  22. package/src/nodeviews/TableContainer.tsx +0 -926
  23. package/src/nodeviews/TableNodeViewBase.ts +0 -29
  24. package/src/nodeviews/TableResizer.tsx +0 -884
  25. package/src/nodeviews/TableRow.ts +0 -830
  26. package/src/nodeviews/TableStickyScrollbar.ts +0 -211
  27. package/src/nodeviews/__mocks__/OverflowShadowsObserver.ts +0 -15
  28. package/src/nodeviews/__mocks__/OverridableMock.ts +0 -26
  29. package/src/nodeviews/table-container-styles.ts +0 -9
  30. package/src/nodeviews/table-node-views.ts +0 -76
  31. package/src/nodeviews/table.tsx +0 -530
  32. package/src/nodeviews/toDOM.ts +0 -244
  33. package/src/nodeviews/types.ts +0 -36
  34. package/src/nodeviews/update-overflow-shadows.ts +0 -11
  35. package/src/pm-plugins/analytics/actions.ts +0 -21
  36. package/src/pm-plugins/analytics/commands.ts +0 -47
  37. package/src/pm-plugins/analytics/plugin-factory.ts +0 -9
  38. package/src/pm-plugins/analytics/plugin-key.ts +0 -5
  39. package/src/pm-plugins/analytics/plugin.ts +0 -80
  40. package/src/pm-plugins/analytics/reducer.ts +0 -27
  41. package/src/pm-plugins/analytics/types.ts +0 -20
  42. package/src/pm-plugins/analytics/utils/moved-event.ts +0 -51
  43. package/src/pm-plugins/commands/clear.ts +0 -43
  44. package/src/pm-plugins/commands/collapse.ts +0 -17
  45. package/src/pm-plugins/commands/column-resize.ts +0 -478
  46. package/src/pm-plugins/commands/commands-with-analytics.ts +0 -715
  47. package/src/pm-plugins/commands/delete.ts +0 -42
  48. package/src/pm-plugins/commands/display-mode.ts +0 -18
  49. package/src/pm-plugins/commands/go-to-next-cell.ts +0 -198
  50. package/src/pm-plugins/commands/hover.ts +0 -242
  51. package/src/pm-plugins/commands/index.ts +0 -51
  52. package/src/pm-plugins/commands/insert.ts +0 -438
  53. package/src/pm-plugins/commands/misc.ts +0 -811
  54. package/src/pm-plugins/commands/referentiality.ts +0 -15
  55. package/src/pm-plugins/commands/selection.ts +0 -537
  56. package/src/pm-plugins/commands/sort.ts +0 -102
  57. package/src/pm-plugins/commands/split-cell.ts +0 -28
  58. package/src/pm-plugins/commands/toggle.ts +0 -109
  59. package/src/pm-plugins/create-plugin-config.ts +0 -17
  60. package/src/pm-plugins/decorations/plugin.ts +0 -107
  61. package/src/pm-plugins/decorations/utils/column-controls.ts +0 -91
  62. package/src/pm-plugins/decorations/utils/column-resizing.ts +0 -71
  63. package/src/pm-plugins/decorations/utils/compose-decorations.ts +0 -9
  64. package/src/pm-plugins/decorations/utils/types.ts +0 -16
  65. package/src/pm-plugins/default-table-selection.ts +0 -14
  66. package/src/pm-plugins/drag-and-drop/actions.ts +0 -48
  67. package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +0 -222
  68. package/src/pm-plugins/drag-and-drop/commands.ts +0 -194
  69. package/src/pm-plugins/drag-and-drop/consts.ts +0 -7
  70. package/src/pm-plugins/drag-and-drop/plugin-factory.ts +0 -33
  71. package/src/pm-plugins/drag-and-drop/plugin-key.ts +0 -5
  72. package/src/pm-plugins/drag-and-drop/plugin.ts +0 -398
  73. package/src/pm-plugins/drag-and-drop/reducer.ts +0 -38
  74. package/src/pm-plugins/drag-and-drop/types.ts +0 -18
  75. package/src/pm-plugins/drag-and-drop/utils/autoscrollers.ts +0 -49
  76. package/src/pm-plugins/drag-and-drop/utils/getDragBehaviour.ts +0 -9
  77. package/src/pm-plugins/drag-and-drop/utils/monitor.ts +0 -73
  78. package/src/pm-plugins/handlers.ts +0 -161
  79. package/src/pm-plugins/keymap.ts +0 -436
  80. package/src/pm-plugins/main.ts +0 -433
  81. package/src/pm-plugins/plugin-factory.ts +0 -42
  82. package/src/pm-plugins/plugin-key.ts +0 -8
  83. package/src/pm-plugins/reducer.ts +0 -145
  84. package/src/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -102
  85. package/src/pm-plugins/sticky-headers/commands.ts +0 -8
  86. package/src/pm-plugins/sticky-headers/plugin-key.ts +0 -5
  87. package/src/pm-plugins/sticky-headers/plugin-state.ts +0 -52
  88. package/src/pm-plugins/sticky-headers/plugin.ts +0 -12
  89. package/src/pm-plugins/sticky-headers/types.ts +0 -20
  90. package/src/pm-plugins/sticky-headers/util.ts +0 -18
  91. package/src/pm-plugins/table-analytics.ts +0 -100
  92. package/src/pm-plugins/table-local-id.ts +0 -213
  93. package/src/pm-plugins/table-resizing/commands.ts +0 -116
  94. package/src/pm-plugins/table-resizing/event-handlers.ts +0 -352
  95. package/src/pm-plugins/table-resizing/plugin-factory.ts +0 -29
  96. package/src/pm-plugins/table-resizing/plugin-key.ts +0 -5
  97. package/src/pm-plugins/table-resizing/plugin.ts +0 -94
  98. package/src/pm-plugins/table-resizing/reducer.ts +0 -37
  99. package/src/pm-plugins/table-resizing/utils/colgroup.ts +0 -306
  100. package/src/pm-plugins/table-resizing/utils/column-state.ts +0 -120
  101. package/src/pm-plugins/table-resizing/utils/consts.ts +0 -11
  102. package/src/pm-plugins/table-resizing/utils/content-width.ts +0 -118
  103. package/src/pm-plugins/table-resizing/utils/dom.ts +0 -132
  104. package/src/pm-plugins/table-resizing/utils/misc.ts +0 -282
  105. package/src/pm-plugins/table-resizing/utils/resize-column.ts +0 -34
  106. package/src/pm-plugins/table-resizing/utils/resize-logic.ts +0 -289
  107. package/src/pm-plugins/table-resizing/utils/resize-state.ts +0 -417
  108. package/src/pm-plugins/table-resizing/utils/scale-table.ts +0 -290
  109. package/src/pm-plugins/table-resizing/utils/types.ts +0 -25
  110. package/src/pm-plugins/table-resizing/utils/unit-to-number.ts +0 -1
  111. package/src/pm-plugins/table-selection-keymap.ts +0 -64
  112. package/src/pm-plugins/table-size-selector.ts +0 -39
  113. package/src/pm-plugins/table-width-in-comment-fix.ts +0 -113
  114. package/src/pm-plugins/table-width.ts +0 -153
  115. package/src/pm-plugins/transforms/column-width.ts +0 -249
  116. package/src/pm-plugins/transforms/delete-columns.ts +0 -281
  117. package/src/pm-plugins/transforms/delete-rows.ts +0 -154
  118. package/src/pm-plugins/transforms/fix-tables.ts +0 -249
  119. package/src/pm-plugins/transforms/merge.ts +0 -301
  120. package/src/pm-plugins/transforms/replace-table.ts +0 -38
  121. package/src/pm-plugins/transforms/split.ts +0 -90
  122. package/src/pm-plugins/utils/alignment.ts +0 -33
  123. package/src/pm-plugins/utils/analytics.ts +0 -238
  124. package/src/pm-plugins/utils/collapse.ts +0 -93
  125. package/src/pm-plugins/utils/column-controls.ts +0 -250
  126. package/src/pm-plugins/utils/create.ts +0 -64
  127. package/src/pm-plugins/utils/decoration.ts +0 -672
  128. package/src/pm-plugins/utils/dom.ts +0 -251
  129. package/src/pm-plugins/utils/drag-menu.tsx +0 -491
  130. package/src/pm-plugins/utils/get-allow-add-column-custom-step.ts +0 -10
  131. package/src/pm-plugins/utils/guidelines.ts +0 -30
  132. package/src/pm-plugins/utils/merged-cells.ts +0 -239
  133. package/src/pm-plugins/utils/nodes.ts +0 -162
  134. package/src/pm-plugins/utils/paste.ts +0 -386
  135. package/src/pm-plugins/utils/row-controls.ts +0 -211
  136. package/src/pm-plugins/utils/selection.ts +0 -17
  137. package/src/pm-plugins/utils/snapping.ts +0 -136
  138. package/src/pm-plugins/utils/table.ts +0 -60
  139. package/src/pm-plugins/utils/update-plugin-state-decorations.ts +0 -13
  140. package/src/pm-plugins/view-mode-sort/consts.ts +0 -3
  141. package/src/pm-plugins/view-mode-sort/index.ts +0 -291
  142. package/src/pm-plugins/view-mode-sort/plugin-key.ts +0 -7
  143. package/src/pm-plugins/view-mode-sort/types.ts +0 -23
  144. package/src/pm-plugins/view-mode-sort/utils.ts +0 -136
  145. package/src/tablePlugin.tsx +0 -971
  146. package/src/tablePluginType.ts +0 -102
  147. package/src/types/index.ts +0 -592
  148. package/src/ui/ColumnResizeWidget/index.tsx +0 -61
  149. package/src/ui/ContentComponent.tsx +0 -311
  150. package/src/ui/DragHandle/HandleIconComponent.tsx +0 -21
  151. package/src/ui/DragHandle/index.tsx +0 -391
  152. package/src/ui/DragPreview/index.tsx +0 -51
  153. package/src/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.tsx +0 -59
  154. package/src/ui/FloatingContextualButton/FixedButton.tsx +0 -203
  155. package/src/ui/FloatingContextualButton/index.tsx +0 -168
  156. package/src/ui/FloatingContextualButton/styles.ts +0 -69
  157. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +0 -931
  158. package/src/ui/FloatingContextualMenu/index.tsx +0 -141
  159. package/src/ui/FloatingContextualMenu/styles.ts +0 -77
  160. package/src/ui/FloatingDeleteButton/DeleteButton.tsx +0 -54
  161. package/src/ui/FloatingDeleteButton/getPopUpOptions.ts +0 -65
  162. package/src/ui/FloatingDeleteButton/index.tsx +0 -383
  163. package/src/ui/FloatingDeleteButton/types.ts +0 -3
  164. package/src/ui/FloatingDragMenu/DragMenu.tsx +0 -668
  165. package/src/ui/FloatingDragMenu/DropdownMenu.tsx +0 -221
  166. package/src/ui/FloatingDragMenu/index.tsx +0 -136
  167. package/src/ui/FloatingDragMenu/styles.ts +0 -83
  168. package/src/ui/FloatingInsertButton/InsertButton.tsx +0 -263
  169. package/src/ui/FloatingInsertButton/getPopupOptions.ts +0 -131
  170. package/src/ui/FloatingInsertButton/index.tsx +0 -314
  171. package/src/ui/FloatingToolbarLabel/FloatingToolbarLabel.tsx +0 -31
  172. package/src/ui/SizeSelector/index.tsx +0 -74
  173. package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +0 -397
  174. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +0 -105
  175. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +0 -63
  176. package/src/ui/TableFloatingColumnControls/index.tsx +0 -151
  177. package/src/ui/TableFloatingControls/CornerControls/ClassicCornerControls.tsx +0 -106
  178. package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +0 -143
  179. package/src/ui/TableFloatingControls/CornerControls/types.ts +0 -12
  180. package/src/ui/TableFloatingControls/FloatingControlsWithSelection.tsx +0 -88
  181. package/src/ui/TableFloatingControls/NumberColumn/index.tsx +0 -150
  182. package/src/ui/TableFloatingControls/RowControls/ClassicControls.tsx +0 -131
  183. package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +0 -429
  184. package/src/ui/TableFloatingControls/RowDropTarget/index.tsx +0 -96
  185. package/src/ui/TableFloatingControls/index.tsx +0 -275
  186. package/src/ui/TableFullWidthLabel/index.tsx +0 -38
  187. package/src/ui/common-styles.ts +0 -1218
  188. package/src/ui/consts.ts +0 -109
  189. package/src/ui/event-handlers.ts +0 -662
  190. package/src/ui/global-styles.tsx +0 -55
  191. package/src/ui/hooks/useInternalTablePluginStateSelector.ts +0 -38
  192. package/src/ui/icons/AddColLeftIcon.tsx +0 -37
  193. package/src/ui/icons/AddColRightIcon.tsx +0 -37
  194. package/src/ui/icons/AddRowAboveIcon.tsx +0 -22
  195. package/src/ui/icons/AddRowBelowIcon.tsx +0 -39
  196. package/src/ui/icons/DragHandleDisabledIcon.tsx +0 -25
  197. package/src/ui/icons/DragHandleIcon.tsx +0 -16
  198. package/src/ui/icons/DragInMotionIcon.tsx +0 -54
  199. package/src/ui/icons/MergeCellsIcon.tsx +0 -26
  200. package/src/ui/icons/MinimisedHandle.tsx +0 -15
  201. package/src/ui/icons/SortingIconWrapper.tsx +0 -43
  202. package/src/ui/icons/SplitCellIcon.tsx +0 -34
  203. package/src/ui/toolbar.tsx +0 -1153
  204. package/src/ui/ui-styles.ts +0 -960
  205. package/tsconfig.app.json +0 -135
  206. package/tsconfig.dev.json +0 -54
  207. package/tsconfig.json +0 -18
@@ -1,352 +0,0 @@
1
- import type { CellAttributes } from '@atlaskit/adf-schema';
2
- import {
3
- ACTION_SUBJECT,
4
- EVENT_TYPE,
5
- INPUT_METHOD,
6
- TABLE_ACTION,
7
- TABLE_OVERFLOW_CHANGE_TRIGGER,
8
- } from '@atlaskit/editor-common/analytics';
9
- import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
10
- import { type PortalProviderAPI } from '@atlaskit/editor-common/portal';
11
- import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
12
- import type { GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
13
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
14
- import { TableMap } from '@atlaskit/editor-tables/table-map';
15
- import { getSelectionRect } from '@atlaskit/editor-tables/utils';
16
-
17
- import type { PluginInjectionAPI } from '../../types';
18
- import { stopKeyboardColumnResizing } from '../commands/column-resize';
19
- import { updateResizeHandleDecorations } from '../commands/misc';
20
- import { getPluginState as getTablePluginState } from '../plugin-factory';
21
- import { META_KEYS } from '../table-analytics';
22
- import { updateColumnWidths } from '../transforms/column-width';
23
- import { tablesHaveDifferentNoOfColumns } from '../utils/nodes';
24
- import { getSelectedColumnIndexes } from '../utils/selection';
25
-
26
- import { evenColumns, setDragging, stopResizing } from './commands';
27
- import { getPluginState } from './plugin-factory';
28
- import { TABLE_OFFSET_IN_COMMENT_EDITOR } from './utils/consts';
29
- import { updateControls } from './utils/dom';
30
- import {
31
- currentColWidth,
32
- getTableMaxWidth,
33
- pointsAtCell,
34
- getScalingPercentForTableWithoutWidth,
35
- getTableScalingPercent,
36
- } from './utils/misc';
37
- import { resizeColumn } from './utils/resize-column';
38
- import { getResizeState } from './utils/resize-state';
39
-
40
- export const handleMouseDown = (
41
- view: EditorView,
42
- event: MouseEvent,
43
- localResizeHandlePos: number,
44
- getEditorContainerWidth: GetEditorContainerWidth,
45
- getEditorFeatureFlags: GetEditorFeatureFlags,
46
- isTableScalingEnabled: boolean,
47
- api: PluginInjectionAPI | undefined | null,
48
- nodeViewPortalProviderAPI: PortalProviderAPI,
49
- editorAnalyticsAPI?: EditorAnalyticsAPI,
50
- isCommentEditor?: boolean,
51
- ): boolean => {
52
- const { state, dispatch } = view;
53
- const editorDisabled = !view.editable;
54
- const domAtPos = view.domAtPos.bind(view);
55
- const { width: editorWidth } = getEditorContainerWidth();
56
-
57
- if (
58
- editorDisabled ||
59
- localResizeHandlePos === null ||
60
- !pointsAtCell(state.doc.resolve(localResizeHandlePos))
61
- ) {
62
- return false;
63
- }
64
- const { isKeyboardResize } = getTablePluginState(state);
65
- event.preventDefault();
66
-
67
- const tr = view.state.tr;
68
- tr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
69
- name: TABLE_OVERFLOW_CHANGE_TRIGGER.RESIZED_COLUMN,
70
- });
71
- dispatch(tr);
72
-
73
- const mouseDownTime = event.timeStamp;
74
- const cell = state.doc.nodeAt(localResizeHandlePos);
75
- const $cell = state.doc.resolve(localResizeHandlePos);
76
- const originalTable = $cell.node(-1);
77
- const start = $cell.start(-1);
78
- const tablePos = state.doc.resolve(start).start(-1);
79
- const tableDepth = state.doc.resolve(tablePos).depth;
80
-
81
- let dom: HTMLTableElement = domAtPos(start).node as HTMLTableElement;
82
- if (dom && dom.nodeName !== 'TABLE') {
83
- dom = dom.closest('table') as HTMLTableElement;
84
- }
85
-
86
- let maxSize = 0;
87
- if (isTableScalingEnabled && isCommentEditor && !originalTable.attrs?.width) {
88
- maxSize = editorWidth - TABLE_OFFSET_IN_COMMENT_EDITOR;
89
- } else {
90
- maxSize = getTableMaxWidth({
91
- table: originalTable,
92
- tableStart: start,
93
- state,
94
- layout: originalTable.attrs.layout,
95
- getEditorContainerWidth,
96
- });
97
- }
98
-
99
- let shouldScale = tableDepth === 0 && isTableScalingEnabled;
100
- const { tableWithFixedColumnWidthsOption = false } = getEditorFeatureFlags();
101
-
102
- const isTableScalingWithFixedColumnWidthsOptionEnabled =
103
- isTableScalingEnabled && tableWithFixedColumnWidthsOption;
104
-
105
- if (isTableScalingWithFixedColumnWidthsOptionEnabled) {
106
- shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
107
- }
108
-
109
- let shouldUseIncreasedScalingPercent = isTableScalingWithFixedColumnWidthsOptionEnabled;
110
-
111
- if (isTableScalingEnabled && isCommentEditor) {
112
- shouldScale = tableDepth === 0;
113
- shouldUseIncreasedScalingPercent = true;
114
- }
115
-
116
- const resizeState = getResizeState({
117
- minWidth: tableCellMinWidth,
118
- maxSize,
119
- table: originalTable,
120
- tableRef: dom,
121
- start,
122
- domAtPos,
123
- isTableScalingEnabled: shouldScale,
124
- shouldUseIncreasedScalingPercent,
125
- isCommentEditor: isCommentEditor || false,
126
- });
127
-
128
- if (
129
- evenColumns({
130
- resizeState,
131
- table: originalTable,
132
- start,
133
- event,
134
- api,
135
- })(state, dispatch)
136
- ) {
137
- finish(event);
138
- return true;
139
- }
140
-
141
- // Ignored via go/ees005
142
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
143
- const width = currentColWidth(view, localResizeHandlePos, cell!.attrs as CellAttributes);
144
-
145
- setDragging({ startX: event.clientX, startWidth: width })(state, dispatch);
146
-
147
- // When we start resizing a column we need to ensure the underlying tooltip is removed from the decoration to avoid
148
- // unnecessary tooltips being displayed during drag.
149
- updateResizeHandleDecorations(
150
- nodeViewPortalProviderAPI,
151
- undefined,
152
- undefined,
153
- false,
154
- )(state, dispatch);
155
-
156
- function finish(event: MouseEvent) {
157
- // Ignored via go/ees005
158
- // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
159
- window.removeEventListener('mouseup', finish);
160
- // Ignored via go/ees005
161
- // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
162
- window.removeEventListener('mousemove', move);
163
-
164
- const { clientX } = event;
165
- const { state, dispatch } = view;
166
- const { dragging, resizeHandlePos } = getPluginState(state);
167
- const { isTableHovered } = getTablePluginState(state);
168
- if (resizeHandlePos === null) {
169
- return stopResizing()(state, dispatch);
170
- }
171
-
172
- if (!pointsAtCell(state.doc.resolve(resizeHandlePos))) {
173
- return;
174
- }
175
- // resizeHandlePos could be remapped via a collab change.
176
- // Fetch a fresh reference of the table.
177
- const $cell = state.doc.resolve(resizeHandlePos);
178
- const start = $cell.start(-1);
179
- const table = $cell.node(-1);
180
- const tablePos = state.doc.resolve(start).start(-1);
181
- const tableDepth = state.doc.resolve(tablePos).depth;
182
-
183
- // If we let go in the same place we started, don't need to do anything.
184
- if (dragging && clientX === dragging.startX) {
185
- if (isKeyboardResize || !isTableHovered) {
186
- /** if column resize had started via keyboard but continued by mouse
187
- * or mouse pointer leaves the table but mouse button still pressed
188
- */
189
- return stopKeyboardColumnResizing({})(state, dispatch, view);
190
- } else {
191
- return stopResizing()(state, dispatch);
192
- }
193
- }
194
-
195
- let { tr } = state;
196
- if (dragging) {
197
- const { startX } = dragging;
198
-
199
- // If the dimensions of the table have changed through a remote modification by another
200
- // person for example don't persist the new column widths as we couldn't reliably remap them
201
- // For example, if a table col is deleted
202
- // There may be a more elegant solution to this, to avoid a jarring experience. This used to
203
- // be an equality check but that caused issues when a nested table would change (eg. when it
204
- // dynamically updates its width on resize)
205
- if (!tablesHaveDifferentNoOfColumns(originalTable, table)) {
206
- const map = TableMap.get(table);
207
- const colIndex =
208
- map.colCount($cell.pos - start) +
209
- ($cell.nodeAfter ? $cell.nodeAfter.attrs.colspan : 1) -
210
- 1;
211
- const selectionRect = getSelectionRect(state.selection);
212
- const selectedColumns = selectionRect ? getSelectedColumnIndexes(selectionRect) : [];
213
- // only selected (or selected - 1) columns should be distributed
214
- const resizingSelectedColumns =
215
- selectedColumns.indexOf(colIndex) > -1 || selectedColumns.indexOf(colIndex + 1) > -1;
216
-
217
- let shouldScale = tableDepth === 0 && isTableScalingEnabled;
218
-
219
- if (isTableScalingWithFixedColumnWidthsOptionEnabled) {
220
- shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
221
- }
222
-
223
- const resizedDelta = clientX - startX;
224
- const shouldUseIncreasedScalingPercent =
225
- isTableScalingWithFixedColumnWidthsOptionEnabled ||
226
- (isTableScalingEnabled && !!isCommentEditor);
227
-
228
- const scalePercent =
229
- isTableScalingEnabled && isCommentEditor && !table.attrs?.width
230
- ? getScalingPercentForTableWithoutWidth(originalTable, dom)
231
- : getTableScalingPercent(originalTable, dom, shouldUseIncreasedScalingPercent);
232
-
233
- const newResizeState = resizeColumn(
234
- resizeState,
235
- colIndex,
236
- resizedDelta,
237
- dom,
238
- originalTable,
239
- resizingSelectedColumns ? selectedColumns : undefined,
240
- shouldScale,
241
- scalePercent,
242
- );
243
- tr = updateColumnWidths(newResizeState, table, start, api)(tr);
244
-
245
- if (colIndex === map.width - 1) {
246
- const mouseUpTime = event.timeStamp;
247
-
248
- editorAnalyticsAPI?.attachAnalyticsEvent({
249
- action: TABLE_ACTION.ATTEMPTED_TABLE_WIDTH_CHANGE,
250
- actionSubject: ACTION_SUBJECT.TABLE,
251
- actionSubjectId: null,
252
- attributes: {
253
- type: 'table-border',
254
- position: 'right',
255
- duration: mouseUpTime - mouseDownTime,
256
- delta: Math.abs(resizedDelta),
257
- },
258
- eventType: EVENT_TYPE.UI,
259
- })(tr);
260
- }
261
-
262
- editorAnalyticsAPI?.attachAnalyticsEvent({
263
- action: TABLE_ACTION.COLUMN_RESIZED,
264
- actionSubject: ACTION_SUBJECT.TABLE,
265
- eventType: EVENT_TYPE.TRACK,
266
- attributes: {
267
- colIndex: colIndex,
268
- resizedDelta,
269
- isLastColumn: colIndex === map.width - 1,
270
- tableWidth: table.attrs.width,
271
- inputMethod: INPUT_METHOD.MOUSE,
272
- totalRowCount: map.height,
273
- totalColumnCount: map.width,
274
- },
275
- })(tr);
276
- }
277
- if (isKeyboardResize || !isTableHovered) {
278
- /** if column resize had started via keyboard but continued by mouse
279
- * or mouse pointer leaves the table but mouse button still pressed
280
- */
281
- return stopKeyboardColumnResizing({ originalTr: tr })(state, dispatch, view);
282
- } else {
283
- return stopResizing(tr)(state, dispatch);
284
- }
285
- }
286
- }
287
-
288
- function move(event: MouseEvent) {
289
- const { clientX, which } = event;
290
- const { state } = view;
291
- const { dragging, resizeHandlePos } = getPluginState(state);
292
- const { isTableHovered } = getTablePluginState(state);
293
- const tablePos = state.doc.resolve(start).start(-1);
294
-
295
- if (
296
- !which ||
297
- !dragging ||
298
- resizeHandlePos === null ||
299
- !pointsAtCell(state.doc.resolve(resizeHandlePos)) ||
300
- !isTableHovered
301
- ) {
302
- return finish(event);
303
- }
304
-
305
- const $cell = state.doc.resolve(resizeHandlePos);
306
- const table = $cell.node(-1);
307
- const tableDepth = state.doc.resolve(tablePos).depth;
308
- const map = TableMap.get(table);
309
- // Ignored via go/ees005
310
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
311
- const colIndex = map.colCount($cell.pos - $cell.start(-1)) + $cell.nodeAfter!.attrs.colspan - 1;
312
-
313
- let shouldScale = tableDepth === 0 && isTableScalingEnabled;
314
-
315
- const shouldUseIncreasedScalingPercent =
316
- isTableScalingWithFixedColumnWidthsOptionEnabled ||
317
- (isTableScalingEnabled && isCommentEditor);
318
-
319
- if (isTableScalingWithFixedColumnWidthsOptionEnabled) {
320
- shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
321
- }
322
-
323
- const resizedDelta = clientX - dragging.startX;
324
-
325
- const scalePercent =
326
- isTableScalingEnabled && isCommentEditor && !table.attrs?.width
327
- ? getScalingPercentForTableWithoutWidth(table, dom)
328
- : getTableScalingPercent(originalTable, dom, shouldUseIncreasedScalingPercent);
329
-
330
- resizeColumn(
331
- resizeState,
332
- colIndex,
333
- resizedDelta,
334
- dom,
335
- table,
336
- undefined,
337
- shouldScale,
338
- scalePercent,
339
- );
340
-
341
- updateControls()(state);
342
- }
343
-
344
- // Ignored via go/ees005
345
- // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
346
- window.addEventListener('mouseup', finish);
347
- // Ignored via go/ees005
348
- // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
349
- window.addEventListener('mousemove', move);
350
-
351
- return true;
352
- };
@@ -1,29 +0,0 @@
1
- // @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
2
- import { pluginFactory } from '@atlaskit/editor-common/utils';
3
- import type { ReadonlyTransaction } from '@atlaskit/editor-prosemirror/state';
4
-
5
- import type { ColumnResizingPluginState } from '../../types';
6
-
7
- import { pluginKey } from './plugin-key';
8
- import reducer from './reducer';
9
-
10
- function mapping(
11
- tr: ReadonlyTransaction,
12
- pluginState: ColumnResizingPluginState,
13
- ): ColumnResizingPluginState {
14
- if (pluginState && pluginState.resizeHandlePos !== null) {
15
- return {
16
- ...pluginState,
17
- resizeHandlePos: tr.mapping.map(pluginState.resizeHandlePos),
18
- };
19
- }
20
- return pluginState;
21
- }
22
-
23
- const factory = pluginFactory(pluginKey, reducer, {
24
- mapping,
25
- });
26
-
27
- export const createCommand = factory.createCommand;
28
- export const createPluginState = factory.createPluginState;
29
- export const getPluginState = factory.getPluginState;
@@ -1,5 +0,0 @@
1
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
-
3
- import type { ColumnResizingPluginState } from '../../types';
4
-
5
- export const pluginKey = new PluginKey<ColumnResizingPluginState>('tableFlexiColumnResizing');
@@ -1,94 +0,0 @@
1
- import classnames from 'classnames';
2
-
3
- import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
4
- import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
5
- import { type PortalProviderAPI } from '@atlaskit/editor-common/portal';
6
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
- import type { GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
8
-
9
- import { TableCssClassName as ClassName } from '../../types';
10
- import type { ColumnResizingPluginState, PluginInjectionAPI } from '../../types';
11
- import { getPluginState as getTablePluginState } from '../plugin-factory';
12
-
13
- import { setResizeHandlePos } from './commands';
14
- import { handleMouseDown } from './event-handlers';
15
- import { createPluginState, getPluginState } from './plugin-factory';
16
- import { pluginKey } from './plugin-key';
17
- import { getResizeCellPos } from './utils/dom';
18
-
19
- export function createPlugin(
20
- dispatch: Dispatch<ColumnResizingPluginState>,
21
- { lastColumnResizable = true }: ColumnResizingPluginState,
22
- getEditorContainerWidth: GetEditorContainerWidth,
23
- getEditorFeatureFlags: GetEditorFeatureFlags,
24
- api: PluginInjectionAPI | undefined | null,
25
- nodeViewPortalProviderAPI: PortalProviderAPI,
26
- editorAnalyticsAPI?: EditorAnalyticsAPI,
27
- isTableScalingEnabled?: boolean,
28
- isCommentEditor?: boolean,
29
- ) {
30
- return new SafePlugin({
31
- key: pluginKey,
32
- state: createPluginState(dispatch, {
33
- lastColumnResizable,
34
- resizeHandlePos: null,
35
- dragging: null,
36
- lastClick: null,
37
- }),
38
-
39
- props: {
40
- attributes(state) {
41
- const pluginState = getPluginState(state);
42
-
43
- return {
44
- class: classnames({
45
- [ClassName.RESIZE_CURSOR]: pluginState.resizeHandlePos !== null,
46
- [ClassName.IS_RESIZING]: !!pluginState.dragging,
47
- }),
48
- };
49
- },
50
-
51
- handleDOMEvents: {
52
- mousedown(view, event) {
53
- const { state } = view;
54
- const resizeHandlePos =
55
- // we're setting `resizeHandlePos` via command in unit tests
56
- getPluginState(state).resizeHandlePos || getResizeCellPos(view, event as MouseEvent);
57
-
58
- const { dragging } = getPluginState(state);
59
- let isColumnKeyboardResizeStarted = false;
60
- /*
61
- We need to start listening mouse events if column resize started from keyboard.
62
- This will allow continue resizing via mouse
63
- */
64
- const { isKeyboardResize } = getTablePluginState(state);
65
- if (isKeyboardResize) {
66
- isColumnKeyboardResizeStarted = isKeyboardResize;
67
- }
68
-
69
- if (resizeHandlePos !== null && (!dragging || isColumnKeyboardResizeStarted)) {
70
- if (
71
- handleMouseDown(
72
- view,
73
- event as MouseEvent,
74
- resizeHandlePos,
75
- getEditorContainerWidth,
76
- getEditorFeatureFlags,
77
- isTableScalingEnabled || false,
78
- api,
79
- nodeViewPortalProviderAPI,
80
- editorAnalyticsAPI,
81
- isCommentEditor,
82
- )
83
- ) {
84
- const { state, dispatch } = view;
85
- return setResizeHandlePos(resizeHandlePos)(state, dispatch);
86
- }
87
- }
88
-
89
- return false;
90
- },
91
- },
92
- },
93
- });
94
- }
@@ -1,37 +0,0 @@
1
- import type { ColumnResizingPluginAction, ColumnResizingPluginState } from '../../types';
2
-
3
- export default (
4
- pluginState: ColumnResizingPluginState,
5
- action: ColumnResizingPluginAction,
6
- ): ColumnResizingPluginState => {
7
- switch (action.type) {
8
- case 'STOP_RESIZING':
9
- return {
10
- ...pluginState,
11
- resizeHandlePos: null,
12
- dragging: null,
13
- };
14
-
15
- case 'SET_RESIZE_HANDLE_POSITION':
16
- return {
17
- ...pluginState,
18
- resizeHandlePos: action.data.resizeHandlePos,
19
- };
20
-
21
- case 'SET_DRAGGING':
22
- return {
23
- ...pluginState,
24
- dragging: action.data.dragging,
25
- };
26
-
27
- case 'SET_LAST_CLICK':
28
- const { lastClick } = action.data;
29
- return {
30
- ...pluginState,
31
- lastClick,
32
- resizeHandlePos: lastClick ? pluginState.resizeHandlePos : null,
33
- };
34
- default:
35
- return pluginState;
36
- }
37
- };