@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,222 +0,0 @@
1
- import { type IntlShape } from 'react-intl-next/src/types';
2
-
3
- import {
4
- ACTION_SUBJECT,
5
- EVENT_TYPE,
6
- INPUT_METHOD,
7
- TABLE_ACTION,
8
- TABLE_STATUS,
9
- } from '@atlaskit/editor-common/analytics';
10
- import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
11
- import { tableMessages as messages } from '@atlaskit/editor-common/messages';
12
- import type { Command } from '@atlaskit/editor-common/types';
13
- import type { AriaLiveElementAttributes } from '@atlaskit/editor-plugin-accessibility-utils';
14
- import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
15
- import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
16
- import { findCellRectClosestToPos, getSelectionRect } from '@atlaskit/editor-tables/utils';
17
-
18
- import type { DraggableData, DraggableType } from '../../types';
19
- import { getSelectedTableInfo, withEditorAnalyticsAPI } from '../utils/analytics';
20
- import { canMove, getTargetIndex } from '../utils/drag-menu';
21
- import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../utils/selection';
22
-
23
- import { clearDropTarget, cloneSource, moveSource } from './commands';
24
-
25
- export const clearDropTargetWithAnalytics =
26
- (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
27
- (
28
- inputMethod: INPUT_METHOD.TABLE_CONTEXT_MENU | INPUT_METHOD.DRAG_AND_DROP,
29
- sourceType: DraggableType,
30
- sourceIndexes: number[] | undefined,
31
- status: TABLE_STATUS.CANCELLED | TABLE_STATUS.INVALID,
32
- tr?: Transaction,
33
- ) => {
34
- return withEditorAnalyticsAPI(({ selection }: EditorState) => {
35
- const { totalRowCount, totalColumnCount } = getSelectedTableInfo(selection);
36
- return {
37
- action: sourceType === 'table-row' ? TABLE_ACTION.MOVED_ROW : TABLE_ACTION.MOVED_COLUMN,
38
- actionSubject: ACTION_SUBJECT.TABLE,
39
- actionSubjectId: null,
40
- attributes: {
41
- inputMethod,
42
- count: sourceIndexes?.length ?? 0,
43
- distance: 0,
44
- status,
45
- totalRowCount,
46
- totalColumnCount,
47
- },
48
- eventType: EVENT_TYPE.TRACK,
49
- };
50
- })(editorAnalyticsAPI)((state, dispatch) => {
51
- if (dispatch) {
52
- clearDropTarget(tr)(state, dispatch);
53
- }
54
- return true;
55
- });
56
- };
57
-
58
- export const moveSourceWithAnalytics =
59
- (
60
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
61
- ariaNotify?: (message: string, ariaLiveElementAttributes?: AriaLiveElementAttributes) => void,
62
- getIntl?: () => IntlShape,
63
- ) =>
64
- (
65
- inputMethod:
66
- | INPUT_METHOD.TABLE_CONTEXT_MENU
67
- | INPUT_METHOD.DRAG_AND_DROP
68
- | INPUT_METHOD.SHORTCUT,
69
- sourceType: DraggableType,
70
- sourceIndexes: number[],
71
- targetIndex: number,
72
- tr?: Transaction,
73
- ) => {
74
- return withEditorAnalyticsAPI(({ selection }: EditorState) => {
75
- const direction = sourceIndexes[0] > targetIndex ? -1 : 1;
76
- const { totalRowCount, totalColumnCount } = getSelectedTableInfo(selection);
77
- return {
78
- action: sourceType === 'table-row' ? TABLE_ACTION.MOVED_ROW : TABLE_ACTION.MOVED_COLUMN,
79
- actionSubject: ACTION_SUBJECT.TABLE,
80
- actionSubjectId: null,
81
- attributes: {
82
- inputMethod,
83
- count: sourceIndexes.length,
84
- // This identifies the total amount of row/cols the move operation covered. The distance covered should be a representaion
85
- // of the minimum distance. This will account for large selection being moved causing a large distance travelled value.
86
- distance: Math.min(...sourceIndexes.map((v) => Math.abs(targetIndex - v))) * direction,
87
- // If a drop doesn't actually change anything then we're going to mark the event as cancelled.
88
- status: sourceIndexes.includes(targetIndex)
89
- ? TABLE_STATUS.CANCELLED
90
- : TABLE_STATUS.SUCCESS,
91
- totalRowCount,
92
- totalColumnCount,
93
- },
94
- eventType: EVENT_TYPE.TRACK,
95
- };
96
- })(editorAnalyticsAPI)((state, dispatch) => {
97
- if (dispatch) {
98
- moveSource(sourceType, sourceIndexes, targetIndex, tr)(state, dispatch);
99
- // Only considering single row/column movement for screen reader as only single row/column selection is supported via keyboard atm.
100
- if (
101
- (inputMethod === INPUT_METHOD.TABLE_CONTEXT_MENU || INPUT_METHOD.SHORTCUT) &&
102
- sourceIndexes.length === 1 &&
103
- ariaNotify &&
104
- getIntl
105
- ) {
106
- const direction = sourceIndexes[0] > targetIndex ? -1 : 1; // -1 for left/up , 1 for right/down
107
- const { totalRowCount, totalColumnCount } = getSelectedTableInfo(state.selection);
108
- ariaNotify(
109
- getIntl().formatMessage(
110
- sourceType === 'table-row'
111
- ? direction > 0
112
- ? messages.rowMovedDown
113
- : messages.rowMovedUp
114
- : direction > 0
115
- ? messages.columnMovedRight
116
- : messages.columnMovedLeft,
117
- {
118
- index: targetIndex + 1,
119
- total: sourceType === 'table-row' ? totalRowCount : totalColumnCount,
120
- },
121
- ),
122
- {
123
- priority: 'important',
124
- },
125
- );
126
- }
127
- }
128
- return true;
129
- });
130
- };
131
-
132
- export const moveSourceWithAnalyticsViaShortcut =
133
- (
134
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
135
- ariaNotify?: (message: string, ariaLiveElementAttributes?: AriaLiveElementAttributes) => void,
136
- getIntl?: () => IntlShape,
137
- ) =>
138
- (sourceType: DraggableType, direction: DraggableData['direction']): Command =>
139
- (state, dispatch) => {
140
- const { selection } = state;
141
- const isCellSelection = selection instanceof CellSelection;
142
- const selectionRect = isCellSelection
143
- ? getSelectionRect(selection)
144
- : findCellRectClosestToPos(selection.$from);
145
-
146
- if (!selectionRect) {
147
- return false;
148
- }
149
-
150
- const isRow = sourceType === 'table-row';
151
- const selectedIndexes = isRow
152
- ? getSelectedRowIndexes(selectionRect)
153
- : getSelectedColumnIndexes(selectionRect);
154
- if (selectedIndexes.length === 0) {
155
- return false;
156
- }
157
-
158
- const { totalRowCount, totalColumnCount } = getSelectedTableInfo(selection);
159
- if (
160
- !canMove(
161
- sourceType,
162
- direction,
163
- isRow ? totalRowCount : totalColumnCount,
164
- selection,
165
- selectionRect,
166
- )
167
- ) {
168
- return false;
169
- }
170
-
171
- const targetIndex = getTargetIndex(selectedIndexes, direction);
172
-
173
- return moveSourceWithAnalytics(editorAnalyticsAPI, ariaNotify, getIntl)(
174
- INPUT_METHOD.SHORTCUT,
175
- sourceType,
176
- selectedIndexes,
177
- targetIndex,
178
- )(state, dispatch);
179
- };
180
-
181
- export const cloneSourceWithAnalytics =
182
- (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
183
- (
184
- inputMethod:
185
- | INPUT_METHOD.TABLE_CONTEXT_MENU
186
- | INPUT_METHOD.DRAG_AND_DROP
187
- | INPUT_METHOD.SHORTCUT,
188
- sourceType: DraggableType,
189
- sourceIndexes: number[],
190
- targetIndex: number,
191
- targetDirection: 'start' | 'end',
192
- tr?: Transaction,
193
- ) => {
194
- return withEditorAnalyticsAPI(({ selection }: EditorState) => {
195
- const direction = sourceIndexes[0] > targetIndex ? -1 : 1;
196
- const { totalRowCount, totalColumnCount } = getSelectedTableInfo(selection);
197
- return {
198
- action: sourceType === 'table-row' ? TABLE_ACTION.CLONED_ROW : TABLE_ACTION.CLONED_COLUMN,
199
- actionSubject: ACTION_SUBJECT.TABLE,
200
- actionSubjectId: null,
201
- attributes: {
202
- inputMethod,
203
- count: sourceIndexes.length,
204
- // This identifies the total amount of row/cols the move operation covered. The distance covered should be a representaion
205
- // of the minimum distance. This will account for large selection being moved causing a large distance travelled value.
206
- distance: Math.min(...sourceIndexes.map((v) => Math.abs(targetIndex - v))) * direction,
207
- // If a drop doesn't actually change anything then we're going to mark the event as cancelled.
208
- status: sourceIndexes.includes(targetIndex)
209
- ? TABLE_STATUS.CANCELLED
210
- : TABLE_STATUS.SUCCESS,
211
- totalRowCount,
212
- totalColumnCount,
213
- },
214
- eventType: EVENT_TYPE.TRACK,
215
- };
216
- })(editorAnalyticsAPI)((state, dispatch) => {
217
- if (dispatch) {
218
- cloneSource(sourceType, sourceIndexes, targetIndex, targetDirection, tr)(state, dispatch);
219
- }
220
- return true;
221
- });
222
- };
@@ -1,194 +0,0 @@
1
- import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
2
- import type { Decoration } from '@atlaskit/editor-prosemirror/view';
3
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
- import { cloneColumn, cloneRow, moveColumn, moveRow } from '@atlaskit/editor-tables/utils';
5
-
6
- import type { DraggableType, TableDirection } from '../../types';
7
- import { TableDecorations } from '../../types';
8
- import {
9
- createColumnInsertLine,
10
- createRowInsertLine,
11
- updateDecorations,
12
- } from '../utils/decoration';
13
-
14
- import { DragAndDropActionType } from './actions';
15
- import { DropTargetType } from './consts';
16
- import { createCommand, getPluginState } from './plugin-factory';
17
- import { pluginKey } from './plugin-key';
18
- import type { TriggerType } from './types';
19
-
20
- // TODO: ED-26961 - This command is a placeholder example. Please replace this if required.
21
- const getDecorations = (state: EditorState): DecorationSet => {
22
- return pluginKey.getState(state)?.decorationSet || DecorationSet.empty;
23
- };
24
-
25
- const updatePluginStateDecorations = (
26
- state: EditorState,
27
- decorations: Decoration[],
28
- key: TableDecorations,
29
- ): DecorationSet => updateDecorations(state.doc, getDecorations(state), decorations, key);
30
-
31
- export const setDropTarget = (
32
- type: DropTargetType,
33
- index: number,
34
- hasMergedCells: boolean,
35
- tr?: Transaction,
36
- ) =>
37
- createCommand(
38
- (state) => {
39
- const { dropTargetType, dropTargetIndex } = getPluginState(state);
40
- if (dropTargetType === type && dropTargetIndex === index) {
41
- return false;
42
- }
43
-
44
- let decorationSet = DecorationSet.empty;
45
- if (type === 'column') {
46
- decorationSet = updatePluginStateDecorations(
47
- state,
48
- createColumnInsertLine(index, state.selection, hasMergedCells),
49
- TableDecorations.COLUMN_INSERT_LINE,
50
- );
51
- } else if (type === 'row') {
52
- decorationSet = updatePluginStateDecorations(
53
- state,
54
- createRowInsertLine(index, state.selection, hasMergedCells),
55
- TableDecorations.ROW_INSERT_LINE,
56
- );
57
- }
58
- return {
59
- type: DragAndDropActionType.SET_DROP_TARGET,
60
- data: {
61
- decorationSet,
62
- type,
63
- index,
64
- },
65
- };
66
- },
67
- (originalTr: Transaction) => (tr || originalTr).setMeta('addToHistory', false),
68
- );
69
-
70
- export const clearDropTarget = (tr?: Transaction) =>
71
- createCommand(
72
- (state) => {
73
- const { dropTargetType, dropTargetIndex } = getPluginState(state);
74
- if (dropTargetType === DropTargetType.NONE && dropTargetIndex === 0) {
75
- return false;
76
- }
77
-
78
- return {
79
- type: DragAndDropActionType.CLEAR_DROP_TARGET,
80
- data: {
81
- decorationSet: DecorationSet.empty,
82
- },
83
- };
84
- },
85
- (originalTr: Transaction) => (tr || originalTr).setMeta('addToHistory', false),
86
- );
87
-
88
- export const moveSource = (
89
- sourceType: DraggableType,
90
- sourceIndexes: number[],
91
- targetIndex: number,
92
- tr?: Transaction,
93
- ) =>
94
- createCommand(
95
- (state) => {
96
- return {
97
- type: DragAndDropActionType.CLEAR_DROP_TARGET,
98
- data: {
99
- decorationSet: DecorationSet.empty,
100
- },
101
- };
102
- },
103
- (originalTr: Transaction, state) => {
104
- const nextTr = tr || originalTr;
105
- if (sourceIndexes.includes(targetIndex)) {
106
- return nextTr.setMeta('addToHistory', false);
107
- }
108
- const move = sourceType === 'table-row' ? moveRow : moveColumn;
109
- return move(state, sourceIndexes, targetIndex, {
110
- selectAfterMove: true,
111
- })(nextTr);
112
- },
113
- );
114
-
115
- export const toggleDragMenu = (
116
- isDragMenuOpen: boolean | undefined,
117
- direction?: TableDirection,
118
- index?: number,
119
- trigger: TriggerType = 'mouse',
120
- ) =>
121
- createCommand(
122
- (state) => {
123
- const {
124
- isDragMenuOpen: previousOpenState,
125
- dragMenuDirection: previousDragMenuDirection,
126
- dragMenuIndex: previousDragMenuIndex,
127
- } = getPluginState(state);
128
-
129
- if (
130
- previousOpenState === isDragMenuOpen &&
131
- previousDragMenuDirection === direction &&
132
- previousDragMenuIndex === index
133
- ) {
134
- return false;
135
- }
136
-
137
- let updatedMenuOpenState;
138
- if (isDragMenuOpen !== undefined) {
139
- updatedMenuOpenState = isDragMenuOpen;
140
- } else {
141
- // menu open but menu direction changed, means user clicked on drag handle of different row/column
142
- // menu open menu direction not changed, but index changed, means user clicked on drag handle of same row/column, different cells.
143
- // 2 scenarios above , menu should remain open.
144
- if (
145
- (previousOpenState === true && previousDragMenuDirection !== direction) ||
146
- (previousOpenState === true &&
147
- previousDragMenuDirection === direction &&
148
- previousDragMenuIndex !== index)
149
- ) {
150
- updatedMenuOpenState = true;
151
- } else {
152
- updatedMenuOpenState = !previousOpenState;
153
- }
154
- }
155
-
156
- return {
157
- type: DragAndDropActionType.TOGGLE_DRAG_MENU,
158
- data: {
159
- isDragMenuOpen: updatedMenuOpenState,
160
- direction: direction ?? previousDragMenuDirection,
161
- index: index ?? previousDragMenuIndex,
162
- isKeyboardModeActive: updatedMenuOpenState && trigger === 'keyboard',
163
- },
164
- };
165
- },
166
- (tr: Transaction) => {
167
- return tr.setMeta('addToHistory', false);
168
- },
169
- );
170
-
171
- export const cloneSource = (
172
- sourceType: DraggableType,
173
- sourceIndexes: number[],
174
- targetIndex: number,
175
- targetDirection: 'start' | 'end',
176
- tr?: Transaction,
177
- ) =>
178
- createCommand(
179
- (state) => {
180
- return {
181
- type: DragAndDropActionType.CLEAR_DROP_TARGET,
182
- data: {
183
- decorationSet: DecorationSet.empty,
184
- },
185
- };
186
- },
187
- (originalTr: Transaction, state) => {
188
- const nextTr = tr || originalTr;
189
- const clone = sourceType === 'table-row' ? cloneRow : cloneColumn;
190
- return clone(state, sourceIndexes, targetIndex, targetDirection, {
191
- selectAfterClone: true,
192
- })(nextTr);
193
- },
194
- );
@@ -1,7 +0,0 @@
1
- export const DropTargetType = {
2
- NONE: 'none',
3
- ROW: 'row',
4
- COLUMN: 'column',
5
- } as const;
6
-
7
- export type DropTargetType = (typeof DropTargetType)[keyof typeof DropTargetType];
@@ -1,33 +0,0 @@
1
- import { pluginFactory } from '@atlaskit/editor-common/utils';
2
-
3
- import { pluginKey as tablePluginKey } from '../plugin-key';
4
-
5
- import { pluginKey } from './plugin-key';
6
- import reducer from './reducer';
7
-
8
- export const { createPluginState, createCommand, getPluginState } = pluginFactory(
9
- pluginKey,
10
- reducer,
11
- {
12
- mapping: (tr, pluginState) => {
13
- if (tr.docChanged) {
14
- let decorationSet = pluginState.decorationSet;
15
-
16
- const meta = tr.getMeta(tablePluginKey);
17
- if (meta && meta.data && meta.data.decorationSet) {
18
- decorationSet = meta.data.decorationSet;
19
- }
20
-
21
- if (decorationSet) {
22
- decorationSet = decorationSet.map(tr.mapping, tr.doc);
23
- }
24
-
25
- return {
26
- ...pluginState,
27
- ...{ decorationSet },
28
- };
29
- }
30
- return pluginState;
31
- },
32
- },
33
- );
@@ -1,5 +0,0 @@
1
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
-
3
- import type { DragAndDropPluginState } from './types';
4
-
5
- export const pluginKey = new PluginKey<DragAndDropPluginState>('dragAndDropPlugin');