@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,398 +0,0 @@
1
- import { INPUT_METHOD, TABLE_STATUS } from '@atlaskit/editor-common/analytics';
2
- import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
3
- import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
4
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
6
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
- import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
8
- import { getCellsInRow, getSelectedCellInfo } from '@atlaskit/editor-tables/utils';
9
- import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element';
10
- import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
11
- import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
12
-
13
- import type { DraggableSourceData } from '../../types';
14
- import { getPluginState as getTablePluginState } from '../plugin-factory';
15
- import { pluginKey as tablePluginKey } from '../plugin-key';
16
- import { insertColgroupFromNode } from '../table-resizing/utils/colgroup';
17
- import { findNearestCellIndexToPoint } from '../utils/dom';
18
- import { hasMergedCellsInBetween } from '../utils/merged-cells';
19
-
20
- import { DragAndDropActionType } from './actions';
21
- import { clearDropTarget, setDropTarget, toggleDragMenu } from './commands';
22
- import {
23
- clearDropTargetWithAnalytics,
24
- cloneSourceWithAnalytics,
25
- moveSourceWithAnalytics,
26
- } from './commands-with-analytics';
27
- import { DropTargetType } from './consts';
28
- import { createPluginState, getPluginState } from './plugin-factory';
29
- import { pluginKey } from './plugin-key';
30
- import { getDraggableDataFromEvent } from './utils/monitor';
31
-
32
- const destroyFn = (
33
- editorView: EditorView,
34
- // Ignored via go/ees005
35
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
- editorAnalyticsAPI: any,
37
- isTableScalingEnabled: boolean,
38
- isTableFixedColumnWidthsOptionEnabled: boolean,
39
- isCommentEditor: boolean,
40
- ) => {
41
- const editorPageScrollContainer = document.querySelector('.fabric-editor-popup-scroll-parent');
42
-
43
- const rowAutoScrollers = editorPageScrollContainer
44
- ? [
45
- monitorForElements({
46
- canMonitor({ source }) {
47
- const { type } = source.data as Partial<DraggableSourceData>;
48
- return type === 'table-row';
49
- },
50
- onDragStart() {
51
- // auto scroller doesn't work when scroll-behavior: smooth is set, this monitor temporarily removes it via inline styles
52
- // Ignored via go/ees005
53
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
54
- (editorPageScrollContainer as HTMLElement).style.setProperty(
55
- 'scroll-behavior',
56
- 'unset',
57
- );
58
- },
59
- onDrop() {
60
- // 'null' will remove the inline style
61
- // Ignored via go/ees005
62
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
63
- (editorPageScrollContainer as HTMLElement).style.setProperty('scroll-behavior', null);
64
- },
65
- }),
66
- autoScrollForElements({
67
- // Ignored via go/ees005
68
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
69
- element: editorPageScrollContainer as HTMLElement,
70
- canScroll: ({ source }) => {
71
- const { type } = source.data as Partial<DraggableSourceData>;
72
- return type === 'table-row';
73
- },
74
- }),
75
- ]
76
- : [];
77
-
78
- return combine(
79
- ...rowAutoScrollers,
80
- monitorForElements({
81
- canMonitor({ source }) {
82
- const { type, localId, indexes } = source.data as Partial<DraggableSourceData>;
83
-
84
- // First; Perform any quick checks so we can abort early.
85
- if (!indexes || !localId || !(type === 'table-row' || type === 'table-column')) {
86
- return false;
87
- }
88
-
89
- const { tableNode } = getTablePluginState(editorView.state);
90
- // If the draggable localId is the same as the current selected table localId then we will allow the monitor
91
- // watch for changes
92
- return localId === tableNode?.attrs.localId;
93
- },
94
- onDragStart: ({ location }) => {
95
- toggleDragMenu(false)(editorView.state, editorView.dispatch);
96
- },
97
- onDrag(event) {
98
- const data = getDraggableDataFromEvent(event);
99
- // If no data can be found then it's most like we do not want to perform any drag actions
100
- if (!data) {
101
- clearDropTarget()(editorView.state, editorView.dispatch);
102
- return;
103
- }
104
-
105
- // TODO: ED-26961 - as we drag an element around we are going to want to update the state to acurately reflect the current
106
- // insert location as to where the draggable will most likely be go. For example;
107
- const { sourceType, targetAdjustedIndex } = data;
108
- const dropTargetType =
109
- sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN;
110
-
111
- const hasMergedCells = hasMergedCellsInBetween(
112
- [targetAdjustedIndex - 1, targetAdjustedIndex],
113
- dropTargetType,
114
- )(editorView.state.selection);
115
-
116
- setDropTarget(
117
- dropTargetType,
118
- targetAdjustedIndex,
119
- hasMergedCells,
120
- )(editorView.state, editorView.dispatch);
121
- },
122
- onDrop(event) {
123
- const data = getDraggableDataFromEvent(event);
124
-
125
- // On Drop we need to update the table main plugin hoveredCell value with the current row/col that the mouse is
126
- // over. This is so the drag handles update their positions to correctly align with the users mouse. Unfortunately
127
- // at this point in time and during the drag opertation, the drop targets are eating all the mouse events so
128
- // it's not possible to know what row/col the mouse is over (via mouse events). This attempts to locate the nearest cell and
129
- // then tries to update the main table hoveredCell value by piggy-backing the transaction onto the command
130
- // triggered by this on drop event.
131
- const { hoveredCell } = getTablePluginState(editorView.state);
132
-
133
- const cell = findNearestCellIndexToPoint(
134
- event.location.current.input.clientX,
135
- event.location.current.input.clientY,
136
- );
137
- const tr = editorView.state.tr;
138
- const action = {
139
- type: 'HOVER_CELL',
140
- data: {
141
- hoveredCell: {
142
- rowIndex: cell?.row ?? hoveredCell.rowIndex,
143
- colIndex: cell?.col ?? hoveredCell.colIndex,
144
- },
145
- },
146
- };
147
- tr.setMeta(tablePluginKey, action);
148
-
149
- // If no data can be found then it's most like we do not want to perform any drop action
150
- if (!data) {
151
- // If we're able to determine the source type of the dropped element then we should report to analytics that
152
- // the drop event was cancelled. Otherwise we will cancel silently.
153
- if (
154
- event?.source?.data?.type === 'table-row' ||
155
- event?.source?.data?.type === 'table-column'
156
- ) {
157
- return clearDropTargetWithAnalytics(editorAnalyticsAPI)(
158
- INPUT_METHOD.DRAG_AND_DROP,
159
- event.source.data.type,
160
- event.source.data?.indexes as number[] | undefined,
161
- TABLE_STATUS.CANCELLED,
162
- tr,
163
- )(editorView.state, editorView.dispatch);
164
- }
165
- return clearDropTarget(tr)(editorView.state, editorView.dispatch);
166
- }
167
-
168
- const {
169
- sourceType,
170
- sourceIndexes,
171
- targetIndex,
172
- targetAdjustedIndex,
173
- targetDirection,
174
- direction,
175
- behaviour,
176
- } = data;
177
-
178
- // When we drop on a target we will know the targets row/col index for certain,
179
- if (sourceType === 'table-row') {
180
- action.data.hoveredCell.rowIndex = targetIndex;
181
- } else {
182
- action.data.hoveredCell.colIndex = targetIndex;
183
- }
184
-
185
- // If the drop target index contains merged cells then we should not allow the drop to occur.
186
- if (
187
- hasMergedCellsInBetween(
188
- [targetAdjustedIndex - 1, targetAdjustedIndex],
189
- sourceType === 'table-row' ? DropTargetType.ROW : DropTargetType.COLUMN,
190
- )(editorView.state.selection)
191
- ) {
192
- clearDropTargetWithAnalytics(editorAnalyticsAPI)(
193
- INPUT_METHOD.DRAG_AND_DROP,
194
- sourceType,
195
- sourceIndexes,
196
- // This event is mrked as invalid because the user is attempting to drop an element in an area which has merged cells.
197
- TABLE_STATUS.INVALID,
198
- tr,
199
- )(editorView.state, editorView.dispatch);
200
- return;
201
- }
202
-
203
- requestAnimationFrame(() => {
204
- if (behaviour === 'clone') {
205
- cloneSourceWithAnalytics(editorAnalyticsAPI)(
206
- INPUT_METHOD.DRAG_AND_DROP,
207
- sourceType,
208
- sourceIndexes,
209
- targetIndex,
210
- targetDirection,
211
- tr,
212
- )(editorView.state, editorView.dispatch);
213
- } else {
214
- moveSourceWithAnalytics(editorAnalyticsAPI)(
215
- INPUT_METHOD.DRAG_AND_DROP,
216
- sourceType,
217
- sourceIndexes,
218
- targetAdjustedIndex + (direction === 1 ? -1 : 0),
219
- tr,
220
- )(editorView.state, editorView.dispatch);
221
- }
222
-
223
- // force a colgroup update here, otherwise dropped columns don't have
224
- // the correct width immediately after the drop
225
- if (sourceType === 'table-column') {
226
- const { tableRef, tableNode } = getTablePluginState(editorView.state);
227
- if (tableRef && tableNode) {
228
- let isTableScalingEnabledOnCurrentTable = isTableScalingEnabled;
229
- const isTableScalingWithFixedColumnWidthsOptionEnabled =
230
- isTableScalingEnabled && isTableFixedColumnWidthsOptionEnabled;
231
- if (isTableScalingWithFixedColumnWidthsOptionEnabled) {
232
- isTableScalingEnabledOnCurrentTable = tableNode.attrs.displayMode !== 'fixed';
233
- }
234
-
235
- if (isTableScalingEnabled && isCommentEditor) {
236
- isTableScalingEnabledOnCurrentTable = true;
237
- }
238
- const shouldUseIncreasedScalingPercent =
239
- isTableScalingWithFixedColumnWidthsOptionEnabled ||
240
- (isTableScalingEnabled && isCommentEditor);
241
-
242
- insertColgroupFromNode(
243
- tableRef,
244
- tableNode,
245
- isTableScalingEnabledOnCurrentTable,
246
- undefined,
247
- shouldUseIncreasedScalingPercent,
248
- isCommentEditor,
249
- );
250
- }
251
- }
252
-
253
- editorView.focus();
254
- });
255
- },
256
- }),
257
- );
258
- };
259
-
260
- export const createPlugin = (
261
- dispatch: Dispatch,
262
- editorAnalyticsAPI?: EditorAnalyticsAPI,
263
- isTableScalingEnabled = false,
264
- isTableFixedColumnWidthsOptionEnabled = false,
265
- isCommentEditor = false,
266
- ) => {
267
- return new SafePlugin({
268
- state: createPluginState(dispatch, (state) => ({
269
- decorationSet: DecorationSet.empty,
270
- dropTargetType: DropTargetType.NONE,
271
- dropTargetIndex: 0,
272
- isDragMenuOpen: false,
273
- dragMenuIndex: 0,
274
- isDragging: false,
275
- isKeyboardModeActive: false,
276
- })),
277
- key: pluginKey,
278
- appendTransaction: (transactions, oldState, newState) => {
279
- const { targetCellPosition: oldTargetCellPosition } = getTablePluginState(oldState);
280
- const { targetCellPosition: newTargetCellPosition } = getTablePluginState(newState);
281
- const { isDragMenuOpen = false, dragMenuIndex } = getPluginState(newState);
282
-
283
- transactions.forEach((transaction) => {
284
- if (transaction.getMeta('selectedRowViaKeyboard')) {
285
- const button = document.querySelector('#drag-handle-button-row');
286
- if (button) {
287
- (button as HTMLButtonElement).focus();
288
- }
289
- }
290
- if (transaction.getMeta('selectedColumnViaKeyboard')) {
291
- const button = document.querySelector('#drag-handle-button-column');
292
- if (button) {
293
- (button as HTMLButtonElement).focus();
294
- }
295
- }
296
- });
297
-
298
- // What's happening here? you asked... In a nutshell;
299
- // If the target cell position changes while the drag menu is open then we want to close the drag menu if it has been opened.
300
- // This will stop the drag menu from moving around the screen to different row/cols. Too achieve this we need
301
- // to check if the new target cell position is pointed at a different cell than what the drag menu was opened on.
302
- if (oldTargetCellPosition !== newTargetCellPosition) {
303
- if (isDragMenuOpen) {
304
- const tr = newState.tr;
305
- const action = {
306
- type: DragAndDropActionType.TOGGLE_DRAG_MENU,
307
- data: {
308
- isDragMenuOpen: false,
309
- direction: undefined,
310
- },
311
- };
312
-
313
- if (newTargetCellPosition !== undefined) {
314
- const cells = getCellsInRow(dragMenuIndex)(tr.selection);
315
- // TODO: ED-20673 - check if it is a cell selection,
316
- // when true, a drag handle is clicked and isDragMenuOpen is true here
317
- // should not close the drag menu.
318
- const isCellSelection = tr.selection instanceof CellSelection;
319
- if (
320
- cells &&
321
- cells.length &&
322
- cells[0].node !== tr.doc.nodeAt(newTargetCellPosition) &&
323
- !isCellSelection
324
- ) {
325
- return tr.setMeta(pluginKey, action);
326
- } // else NOP
327
- } else {
328
- return tr.setMeta(pluginKey, action);
329
- }
330
- }
331
- }
332
- },
333
- view: (editorView: EditorView) => {
334
- return {
335
- destroy: destroyFn(
336
- editorView,
337
- editorAnalyticsAPI,
338
- isTableScalingEnabled,
339
- isTableFixedColumnWidthsOptionEnabled,
340
- isCommentEditor,
341
- ),
342
- };
343
- },
344
- props: {
345
- decorations: (state) => {
346
- const { decorationSet } = getPluginState(state);
347
- return decorationSet;
348
- },
349
- handleKeyDown: (view, event) => {
350
- const {
351
- state: { tr },
352
- } = view;
353
-
354
- const keysToTrapWhen = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'];
355
-
356
- /** fix for NCS spam update where the user is holding down the move column / row keyboard shortcut
357
- * if the user is holding down shortcut (ctrl + shift + alt + arrowKey), we want to move the selection only once
358
- * See ticket ED-22154 https://product-fabric.atlassian.net/browse/ED-22154
359
- */
360
-
361
- // Do early check for the keys we want to trap here so we can abort early
362
- if (event.ctrlKey && event.shiftKey && event.altKey) {
363
- const { verticalCells, horizontalCells, totalRowCount, totalColumnCount } =
364
- getSelectedCellInfo(tr.selection);
365
-
366
- const isRowOrColumnSelected =
367
- horizontalCells === totalColumnCount || verticalCells === totalRowCount;
368
- if (isRowOrColumnSelected && keysToTrapWhen.includes(event.key) && event.repeat) {
369
- return true;
370
- }
371
- }
372
-
373
- const isDragHandleFocused = [
374
- 'drag-handle-button-row',
375
- 'drag-handle-button-column',
376
- // Ignored via go/ees005
377
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
378
- ].includes(((event.target as HTMLElement) || null)?.id);
379
- const keysToTrap = ['Enter', ' '];
380
-
381
- const { isDragMenuOpen = false } = getPluginState(view.state);
382
-
383
- // drag handle is focused, and user presses any key return them back to editing
384
- if (isDragHandleFocused && !isDragMenuOpen && !keysToTrap.includes(event.key)) {
385
- view.dom.focus();
386
- return true;
387
- }
388
-
389
- if (
390
- (isDragHandleFocused && keysToTrap.includes(event.key)) ||
391
- (isDragMenuOpen && keysToTrapWhen.includes(event.key))
392
- ) {
393
- return true;
394
- }
395
- },
396
- },
397
- });
398
- };
@@ -1,38 +0,0 @@
1
- import type { DragAndDropPluginAction } from './actions';
2
- import { DragAndDropActionType } from './actions';
3
- import { DropTargetType } from './consts';
4
- import type { DragAndDropPluginState } from './types';
5
-
6
- export default (
7
- pluginState: DragAndDropPluginState,
8
- action: DragAndDropPluginAction,
9
- ): DragAndDropPluginState => {
10
- switch (action.type) {
11
- case DragAndDropActionType.SET_DROP_TARGET:
12
- return {
13
- ...pluginState,
14
- decorationSet: action.data.decorationSet,
15
- dropTargetType: action.data.type,
16
- dropTargetIndex: action.data.index,
17
- isDragging: true,
18
- };
19
- case DragAndDropActionType.CLEAR_DROP_TARGET:
20
- return {
21
- ...pluginState,
22
- decorationSet: action.data.decorationSet,
23
- dropTargetType: DropTargetType.NONE,
24
- dropTargetIndex: 0,
25
- isDragging: false,
26
- };
27
- case DragAndDropActionType.TOGGLE_DRAG_MENU:
28
- return {
29
- ...pluginState,
30
- isDragMenuOpen: action.data.isDragMenuOpen,
31
- dragMenuDirection: action.data.direction,
32
- dragMenuIndex: action.data.index,
33
- isKeyboardModeActive: action.data.isKeyboardModeActive,
34
- };
35
- default:
36
- return pluginState;
37
- }
38
- };
@@ -1,18 +0,0 @@
1
- import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
-
3
- import type { TableDirection } from '../../types';
4
-
5
- import type { DropTargetType } from './consts';
6
-
7
- export interface DragAndDropPluginState {
8
- decorationSet: DecorationSet;
9
- dropTargetType: DropTargetType;
10
- dropTargetIndex: number;
11
- isDragMenuOpen: boolean;
12
- dragMenuDirection?: TableDirection;
13
- dragMenuIndex: number;
14
- isDragging: boolean;
15
- isKeyboardModeActive: boolean;
16
- }
17
-
18
- export type TriggerType = 'mouse' | 'keyboard';
@@ -1,49 +0,0 @@
1
- import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
2
- import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element';
3
- import { unsafeOverflowAutoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/unsafe-overflow/element';
4
-
5
- import type { DraggableSourceData } from '../../../types';
6
- import { dropTargetExtendedWidth } from '../../../ui/consts';
7
-
8
- type AutoScrollerFactory = {
9
- tableWrapper: HTMLElement;
10
- getNode: () => PmNode;
11
- };
12
-
13
- export const autoScrollerFactory = ({ tableWrapper, getNode }: AutoScrollerFactory) => {
14
- return [
15
- autoScrollForElements({
16
- element: tableWrapper,
17
- canScroll: ({ source }) => {
18
- const { localId, type } = source.data as Partial<DraggableSourceData>;
19
- const node = getNode();
20
- return localId === node?.attrs.localId && type === 'table-column';
21
- },
22
- }),
23
- unsafeOverflowAutoScrollForElements({
24
- element: tableWrapper,
25
- canScroll: ({ source }) => {
26
- const { localId, type } = source.data as Partial<DraggableSourceData>;
27
- const node = getNode();
28
- return localId === node?.attrs.localId && type === 'table-column';
29
- },
30
- getOverflow: () => ({
31
- forTopEdge: {
32
- top: dropTargetExtendedWidth,
33
- right: dropTargetExtendedWidth,
34
- left: dropTargetExtendedWidth,
35
- },
36
- forRightEdge: {
37
- right: dropTargetExtendedWidth,
38
- top: dropTargetExtendedWidth,
39
- bottom: dropTargetExtendedWidth,
40
- },
41
- forLeftEdge: {
42
- top: dropTargetExtendedWidth,
43
- left: dropTargetExtendedWidth,
44
- bottom: dropTargetExtendedWidth,
45
- },
46
- }),
47
- }),
48
- ];
49
- };
@@ -1,9 +0,0 @@
1
- import { browser } from '@atlaskit/editor-common/browser';
2
- import type { Input } from '@atlaskit/pragmatic-drag-and-drop/types';
3
-
4
- import type { DraggableBehaviour } from '../../../types';
5
-
6
- export const getDragBehaviour = ({ altKey, ctrlKey }: Input): DraggableBehaviour => {
7
- const isCloneModifierKeyPressed = browser.mac ? altKey : ctrlKey;
8
- return isCloneModifierKeyPressed ? 'clone' : 'move';
9
- };
@@ -1,73 +0,0 @@
1
- import { extractClosestEdge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
2
- import type { Edge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
3
- import type { ElementEventBasePayload } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
4
-
5
- import type { DraggableData, DraggableSourceData, DraggableTargetData } from '../../../types';
6
-
7
- import { getDragBehaviour } from './getDragBehaviour';
8
-
9
- export const getDraggableDataFromEvent = ({
10
- location,
11
- source,
12
- }: ElementEventBasePayload): DraggableData | undefined => {
13
- const destination = location.current.dropTargets.at(0);
14
- // If no target exists at the current location, then the current draggable is not over a target or the target doesn't support
15
- // the current draggable.
16
- if (!destination) {
17
- return undefined;
18
- }
19
-
20
- // This is the draggable elements data
21
- const {
22
- indexes: sourceIndexes,
23
- type: sourceType,
24
- localId: sourceLocalId,
25
- } = source.data as DraggableSourceData;
26
-
27
- // This is the drop target's data
28
- const {
29
- targetIndex,
30
- type: targetType,
31
- localId: targetLocalId,
32
- } = destination.data as DraggableTargetData;
33
-
34
- // Some basic check to abort early with...
35
- if (
36
- !sourceIndexes ||
37
- targetIndex < 0 ||
38
- // abort if the type of the draggable is different to the target, for eg. rows cannot be dropped onto column targets.
39
- sourceType !== targetType ||
40
- // abort if the draggable is coming from a different table that the target is on.
41
- sourceLocalId !== targetLocalId
42
- ) {
43
- return undefined;
44
- }
45
-
46
- const targetClosestEdge =
47
- extractClosestEdge(destination.data) ?? ((targetType === 'table-row' ? 'top' : 'left') as Edge);
48
- // NOTE: By default we always insert row/cols at the target index to the top/left (retrospectively of row/cols).
49
- // This introduces an offset in the event the drop occured closer to the bottom/right of the target. We want
50
- // the new target index to be 1 index higher.
51
- const targetOffset = targetClosestEdge === 'right' || targetClosestEdge === 'bottom' ? 1 : 0;
52
-
53
- // if the min index is greater then the target index, the then the direction of the DnD is decreasing
54
- // if the target is within the min/max index then we can assume that no direction exists so it will be 0.
55
- const srcMin = Math.min(...sourceIndexes);
56
- const srcMax = Math.max(...sourceIndexes);
57
- const direction =
58
- targetIndex >= srcMin && targetIndex <= srcMax ? 0 : srcMin >= targetIndex ? -1 : 1;
59
-
60
- return {
61
- sourceType,
62
- sourceLocalId,
63
- sourceIndexes,
64
- targetType,
65
- targetLocalId,
66
- targetIndex,
67
- targetAdjustedIndex: targetIndex + targetOffset,
68
- targetClosestEdge,
69
- targetDirection: targetClosestEdge === 'top' || targetClosestEdge === 'left' ? 'start' : 'end',
70
- direction,
71
- behaviour: getDragBehaviour(location.current.input),
72
- };
73
- };