@atlaskit/editor-plugin-table 12.2.6 → 12.3.0

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 +19 -0
  2. package/dist/cjs/pm-plugins/view-mode-sort/index.js +1 -3
  3. package/dist/es2019/pm-plugins/view-mode-sort/index.js +1 -3
  4. package/dist/esm/pm-plugins/view-mode-sort/index.js +1 -3
  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 -175
  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,433 +0,0 @@
1
- import type { IntlShape } from 'react-intl-next';
2
-
3
- import {
4
- ACTION,
5
- ACTION_SUBJECT,
6
- EVENT_TYPE,
7
- INPUT_METHOD,
8
- } from '@atlaskit/editor-common/analytics';
9
- import type { DispatchAnalyticsEvent, EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
10
- import { insideTable, isSSR } from '@atlaskit/editor-common/core-utils';
11
- import type { Dispatch, EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
12
- import { type PortalProviderAPI } from '@atlaskit/editor-common/portal';
13
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
14
- import {
15
- transformSliceToRemoveOpenBodiedExtension,
16
- transformSliceToRemoveOpenExpand,
17
- transformSliceToRemoveOpenLayoutNodes,
18
- transformSliceToRemoveOpenMultiBodiedExtension,
19
- transformSliceToRemoveOpenNestedExpand,
20
- } from '@atlaskit/editor-common/transforms';
21
- import type { GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
22
- import { browser, closestElement } from '@atlaskit/editor-common/utils';
23
- import type { EditorState, TextSelection, Transaction } from '@atlaskit/editor-prosemirror/state';
24
- import { findParentDomRefOfType, findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
25
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
26
- import { TableMap } from '@atlaskit/editor-tables';
27
- import { findTable } from '@atlaskit/editor-tables/utils';
28
- import { fg } from '@atlaskit/platform-feature-flags';
29
- import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
30
-
31
- import {
32
- tableCellView,
33
- tableHeaderView,
34
- tableRowView,
35
- tableView,
36
- } from '../nodeviews/table-node-views';
37
- import { pluginKey as decorationsPluginKey } from '../pm-plugins/decorations/plugin';
38
- import type {
39
- InvalidNodeAttr,
40
- PluginConfig,
41
- PluginInjectionAPI,
42
- PluginInjectionAPIWithA11y,
43
- } from '../types';
44
- import { TableCssClassName as ClassName } from '../types';
45
- import {
46
- handleBlur,
47
- handleClick,
48
- handleCut,
49
- handleFocus,
50
- handleMouseDown,
51
- handleMouseEnter,
52
- handleMouseLeave,
53
- handleMouseMove,
54
- handleMouseUp,
55
- handleTripleClick,
56
- whenTableInFocus,
57
- withCellTracking,
58
- } from '../ui/event-handlers';
59
-
60
- import { addBoldInEmptyHeaderCells, clearHoverSelection, setTableRef } from './commands';
61
- import { stopKeyboardColumnResizing } from './commands/column-resize';
62
- import {
63
- removeResizeHandleDecorations,
64
- transformSliceRemoveCellBackgroundColor,
65
- transformSliceToAddTableHeaders,
66
- transformSliceToRemoveColumnsWidths,
67
- } from './commands/misc';
68
- import { defaultHoveredCell, defaultTableSelection } from './default-table-selection';
69
- import { createPluginState, getPluginState } from './plugin-factory';
70
- import { pluginKey } from './plugin-key';
71
- import { fixTables } from './transforms/fix-tables';
72
- import { replaceSelectedTable } from './transforms/replace-table';
73
- import { findControlsHoverDecoration } from './utils/decoration';
74
- import {
75
- transformSliceToCorrectEmptyTableCells,
76
- transformSliceToFixHardBreakProblemOnCopyFromCell,
77
- transformSliceToRemoveOpenTable,
78
- transformSliceToRemoveNestedTables,
79
- isHeaderRowRequired,
80
- transformSliceTableLayoutDefaultToCenter,
81
- } from './utils/paste';
82
-
83
- export const createPlugin = (
84
- dispatchAnalyticsEvent: DispatchAnalyticsEvent,
85
- dispatch: Dispatch,
86
- portalProviderAPI: PortalProviderAPI,
87
- nodeViewPortalProviderAPI: PortalProviderAPI,
88
- eventDispatcher: EventDispatcher,
89
- pluginConfig: PluginConfig,
90
- getEditorContainerWidth: GetEditorContainerWidth,
91
- getEditorFeatureFlags: GetEditorFeatureFlags,
92
- getIntl: () => IntlShape,
93
- fullWidthModeEnabled?: boolean,
94
- previousFullWidthModeEnabled?: boolean,
95
- dragAndDropEnabled?: boolean,
96
- editorAnalyticsAPI?: EditorAnalyticsAPI,
97
- pluginInjectionApi?: PluginInjectionAPI,
98
- isTableScalingEnabled?: boolean,
99
- shouldUseIncreasedScalingPercent?: boolean,
100
- isCommentEditor?: boolean,
101
- isChromelessEditor?: boolean,
102
- ) => {
103
- const state = createPluginState(dispatch, {
104
- pluginConfig,
105
- isTableHovered: false,
106
- insertColumnButtonIndex: undefined,
107
- insertRowButtonIndex: undefined,
108
- isFullWidthModeEnabled: fullWidthModeEnabled,
109
- wasFullWidthModeEnabled: previousFullWidthModeEnabled,
110
- isHeaderRowEnabled: !!pluginConfig.allowHeaderRow,
111
- isHeaderColumnEnabled: false,
112
- isDragAndDropEnabled: dragAndDropEnabled,
113
- isTableScalingEnabled: isTableScalingEnabled,
114
- ...defaultHoveredCell,
115
- ...defaultTableSelection,
116
- getIntl,
117
- });
118
-
119
- // Used to prevent invalid table cell spans being reported more than once per editor/document
120
- const invalidTableIds: string[] = [];
121
- let editorViewRef: EditorView | null = null;
122
-
123
- const ariaNotifyPlugin = (pluginInjectionApi as PluginInjectionAPIWithA11y)?.accessibilityUtils
124
- ?.actions.ariaNotify;
125
-
126
- const getCurrentEditorState = (): EditorState | null => {
127
- const editorView = editorViewRef;
128
- if (!editorView) {
129
- return null;
130
- }
131
-
132
- return editorView.state;
133
- };
134
-
135
- const getNodeView = () => {
136
- // Because the layout shift issues has been fixed under experiment platform_editor_tables_scaling_css, so still want to load nodeview on SSR if experiment is enabled
137
- if (expValEquals('platform_editor_tables_scaling_css', 'isEnabled', true)) {
138
- return {
139
- table: tableView({
140
- portalProviderAPI,
141
- eventDispatcher,
142
- getEditorContainerWidth,
143
- getEditorFeatureFlags,
144
- dispatchAnalyticsEvent,
145
- pluginInjectionApi,
146
- isCommentEditor,
147
- isChromelessEditor,
148
- }),
149
- tableRow: tableRowView({ eventDispatcher, pluginInjectionApi }),
150
- tableCell: tableCellView({ eventDispatcher, pluginInjectionApi }),
151
- tableHeader: tableHeaderView({ eventDispatcher, pluginInjectionApi }),
152
- };
153
- }
154
- if (isSSR() && fg('platform_editor_table_fallback_to_dom_on_ssr')) {
155
- return undefined;
156
- }
157
- return {
158
- table: tableView({
159
- portalProviderAPI,
160
- eventDispatcher,
161
- getEditorContainerWidth,
162
- getEditorFeatureFlags,
163
- dispatchAnalyticsEvent,
164
- pluginInjectionApi,
165
- isCommentEditor,
166
- isChromelessEditor,
167
- }),
168
- tableRow: tableRowView({ eventDispatcher, pluginInjectionApi }),
169
- tableCell: tableCellView({ eventDispatcher, pluginInjectionApi }),
170
- tableHeader: tableHeaderView({ eventDispatcher, pluginInjectionApi }),
171
- };
172
- };
173
-
174
- const nodeViews = getNodeView();
175
- return new SafePlugin({
176
- state: state,
177
- key: pluginKey,
178
- appendTransaction: (
179
- transactions: readonly Transaction[],
180
- oldState: EditorState,
181
- newState: EditorState,
182
- ) => {
183
- const tr = transactions.find((tr) => tr.getMeta('uiEvent') === 'cut');
184
-
185
- function reportInvalidTableCellSpanAttrs(invalidNodeAttr: InvalidNodeAttr) {
186
- if (invalidTableIds.find((id) => id === invalidNodeAttr.tableLocalId)) {
187
- return;
188
- }
189
-
190
- invalidTableIds.push(invalidNodeAttr.tableLocalId);
191
-
192
- dispatchAnalyticsEvent({
193
- action: ACTION.INVALID_DOCUMENT_ENCOUNTERED,
194
- actionSubject: ACTION_SUBJECT.EDITOR,
195
- eventType: EVENT_TYPE.OPERATIONAL,
196
- attributes: {
197
- nodeType: invalidNodeAttr.nodeType,
198
- reason: `${invalidNodeAttr.attribute}: ${invalidNodeAttr.reason}`,
199
- tableLocalId: invalidNodeAttr.tableLocalId,
200
- spanValue: invalidNodeAttr.spanValue,
201
- },
202
- });
203
- }
204
-
205
- if (tr) {
206
- const { tableWithFixedColumnWidthsOption = false } = getEditorFeatureFlags();
207
- // "fixTables" removes empty rows as we don't allow that in schema
208
- const updatedTr = handleCut(
209
- tr,
210
- oldState,
211
- newState,
212
- pluginInjectionApi,
213
- editorAnalyticsAPI,
214
- editorViewRef || undefined,
215
- isTableScalingEnabled,
216
- tableWithFixedColumnWidthsOption,
217
- shouldUseIncreasedScalingPercent,
218
- );
219
- return fixTables(updatedTr) || updatedTr;
220
- }
221
- if (transactions.find((tr) => tr.docChanged)) {
222
- return fixTables(newState.tr, reportInvalidTableCellSpanAttrs);
223
- }
224
- },
225
- view: (editorView: EditorView) => {
226
- const domAtPos = editorView.domAtPos.bind(editorView);
227
- editorViewRef = editorView;
228
-
229
- return {
230
- update: (view: EditorView, prevState: EditorState) => {
231
- const { state, dispatch } = view;
232
- const { selection } = state;
233
- const pluginState = getPluginState(state);
234
- let tableRef: HTMLTableElement | undefined;
235
- if (pluginState.editorHasFocus) {
236
- const parent = findParentDomRefOfType(state.schema.nodes.table, domAtPos)(selection);
237
- if (parent) {
238
- tableRef =
239
- // Ignored via go/ees005
240
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
241
- (parent as HTMLElement).querySelector<HTMLTableElement>('table') || undefined;
242
- }
243
- const tableNode = findTable(state.selection);
244
- // when keyboard cursor leaves the table we need to stop column resizing
245
- const pluginPrevState = getPluginState(prevState);
246
- const isStopKeyboardColumResizing =
247
- pluginPrevState.isResizeHandleWidgetAdded && pluginPrevState.isKeyboardResize;
248
- if (isStopKeyboardColumResizing) {
249
- const isTableNodesDifferent = pluginPrevState?.tableNode !== tableNode?.node;
250
- if (pluginPrevState?.tableNode && tableNode && isTableNodesDifferent) {
251
- const oldRowsNumber = TableMap.get(pluginPrevState.tableNode).height;
252
- const newRowsNumber = TableMap.get(tableNode.node).height;
253
- if (
254
- oldRowsNumber !== newRowsNumber || // Add/delete row
255
- tableNode.node.attrs.localId !== pluginPrevState.tableNode.attrs.localId
256
- ) {
257
- // Jump to another table
258
- stopKeyboardColumnResizing({
259
- ariaNotify: ariaNotifyPlugin,
260
- getIntl: getIntl,
261
- })(state, dispatch);
262
- }
263
- } else if (!tableNode) {
264
- // selection outside of table
265
- stopKeyboardColumnResizing({
266
- ariaNotify: ariaNotifyPlugin,
267
- getIntl: getIntl,
268
- })(state, dispatch);
269
- }
270
- }
271
- }
272
-
273
- if (pluginState.tableRef !== tableRef) {
274
- setTableRef(tableRef)(state, dispatch);
275
- }
276
-
277
- if (pluginState.editorHasFocus && pluginState.tableRef) {
278
- const { $cursor } = state.selection as TextSelection;
279
- if ($cursor) {
280
- // Only update bold when it's a cursor
281
- const tableCellHeader = findParentNodeOfType(state.schema.nodes.tableHeader)(
282
- state.selection,
283
- );
284
-
285
- if (tableCellHeader) {
286
- addBoldInEmptyHeaderCells(tableCellHeader)(state, dispatch);
287
- }
288
- }
289
- } else if (pluginState.isResizeHandleWidgetAdded) {
290
- removeResizeHandleDecorations()(state, dispatch);
291
- }
292
- },
293
- };
294
- },
295
- props: {
296
- transformPasted(slice) {
297
- const editorState = getCurrentEditorState();
298
- if (!editorState) {
299
- return slice;
300
- }
301
-
302
- const { schema } = editorState;
303
-
304
- // if we're pasting to outside a table or outside a table
305
- // header, ensure that we apply any table headers to the first
306
- // row of content we see, if required
307
- if (!insideTable(editorState) && isHeaderRowRequired(editorState)) {
308
- slice = transformSliceToAddTableHeaders(slice, schema);
309
- }
310
-
311
- // This fixes pasting a table with default layout into comment editor
312
- // table lose width and expand to full width
313
- if (
314
- !insideTable(editorState) &&
315
- isCommentEditor &&
316
- pluginConfig.allowTableAlignment &&
317
- isTableScalingEnabled
318
- ) {
319
- slice = transformSliceTableLayoutDefaultToCenter(slice, schema);
320
- }
321
-
322
- slice = transformSliceToFixHardBreakProblemOnCopyFromCell(slice, schema);
323
-
324
- // We do this separately, so it also applies to drag/drop events
325
- // This needs to go before `transformSliceToRemoveOpenExpand`
326
- slice = transformSliceToRemoveOpenLayoutNodes(slice, schema);
327
-
328
- // If a partial paste of expand, paste only the content
329
- // This needs to go before `transformSliceToRemoveOpenTable`
330
- slice = transformSliceToRemoveOpenExpand(slice, schema);
331
-
332
- // transformSliceToRemoveOpenTable() transforms based on the depth of the root node, assuming that the tables will be at the root
333
- // Bodied extensions will contribute to the depth of the table selection so we need to remove them first
334
- /** If a partial paste of bodied extension, paste only text */
335
- slice = transformSliceToRemoveOpenBodiedExtension(slice, schema);
336
-
337
- /** If a partial paste of table, paste only table's content */
338
- slice = transformSliceToRemoveOpenTable(slice, schema);
339
-
340
- /** If a partial paste of multi bodied extension, paste only children */
341
- slice = transformSliceToRemoveOpenMultiBodiedExtension(slice, schema);
342
-
343
- slice = transformSliceToCorrectEmptyTableCells(slice, schema);
344
-
345
- if (!pluginConfig.allowColumnResizing) {
346
- slice = transformSliceToRemoveColumnsWidths(slice, schema);
347
- }
348
-
349
- // If we don't allow background on cells, we need to remove it
350
- // from the paste slice
351
- if (!pluginConfig.allowBackgroundColor) {
352
- slice = transformSliceRemoveCellBackgroundColor(slice, schema);
353
- }
354
-
355
- slice = transformSliceToRemoveOpenNestedExpand(slice, schema);
356
-
357
- if (fg('platform_editor_use_nested_table_pm_nodes')) {
358
- slice = transformSliceToRemoveNestedTables(slice, schema, editorState.selection);
359
- }
360
-
361
- return slice;
362
- },
363
- handleClick: ({ state, dispatch }, _pos, event: MouseEvent) => {
364
- const decorationSet = decorationsPluginKey.getState(state);
365
- if (findControlsHoverDecoration(decorationSet).length) {
366
- clearHoverSelection()(state, dispatch);
367
- }
368
-
369
- // ED-6069: workaround for Chrome given a regression introduced in prosemirror-view@1.6.8
370
- // Returning true prevents that updateSelection() is getting called in the commit below:
371
- // @see https://github.com/ProseMirror/prosemirror-view/commit/33fe4a8b01584f6b4103c279033dcd33e8047b95
372
- if (browser.chrome && event.target) {
373
- // Ignored via go/ees005
374
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
375
- const targetClassList = (event.target as HTMLElement).classList;
376
-
377
- if (
378
- targetClassList.contains(ClassName.CONTROLS_BUTTON) ||
379
- targetClassList.contains(ClassName.CONTEXTUAL_MENU_BUTTON) ||
380
- targetClassList.contains(ClassName.DRAG_HANDLE_BUTTON_CLICKABLE_ZONE) ||
381
- targetClassList.contains(ClassName.DRAG_HANDLE_BUTTON_CONTAINER)
382
- ) {
383
- return true;
384
- }
385
- }
386
-
387
- return false;
388
- },
389
- handleScrollToSelection: (view: EditorView) => {
390
- // when typing into a sticky header cell, we don't want to scroll
391
- // back to the top of the table if the user has already scrolled down
392
- const { tableHeader } = view.state.schema.nodes;
393
- const domRef = findParentDomRefOfType(
394
- tableHeader,
395
- view.domAtPos.bind(view),
396
- )(view.state.selection);
397
-
398
- const maybeTr = closestElement(domRef as HTMLElement | undefined, 'tr');
399
- return maybeTr ? maybeTr.classList.contains('sticky') : false;
400
- },
401
- handleTextInput: (view, _from, _to, text) => {
402
- const { state, dispatch } = view;
403
- const { isKeyboardResize } = getPluginState(state);
404
- if (isKeyboardResize) {
405
- stopKeyboardColumnResizing({
406
- ariaNotify: ariaNotifyPlugin,
407
- getIntl: getIntl,
408
- })(state, dispatch);
409
- return false;
410
- }
411
- const tr = replaceSelectedTable(state, text, INPUT_METHOD.KEYBOARD, editorAnalyticsAPI);
412
- if (tr.selectionSet) {
413
- dispatch(tr);
414
- return true;
415
- }
416
- return false;
417
- },
418
- nodeViews,
419
- handleDOMEvents: {
420
- focus: handleFocus,
421
- blur: handleBlur,
422
- mousedown: withCellTracking(handleMouseDown),
423
- mouseleave: handleMouseLeave,
424
- mousemove: whenTableInFocus(handleMouseMove(nodeViewPortalProviderAPI), pluginInjectionApi),
425
- mouseenter: handleMouseEnter,
426
- mouseup: whenTableInFocus(handleMouseUp),
427
- click: withCellTracking(whenTableInFocus(handleClick)),
428
- },
429
-
430
- handleTripleClick,
431
- },
432
- });
433
- };
@@ -1,42 +0,0 @@
1
- import { pluginFactory } from '@atlaskit/editor-common/utils';
2
-
3
- import { handleDocOrSelectionChanged } from './handlers';
4
- import { pluginKey } from './plugin-key';
5
- import reducer from './reducer';
6
-
7
- export const { createPluginState, createCommand, getPluginState } = pluginFactory(
8
- pluginKey,
9
- reducer,
10
- {
11
- mapping: (tr, pluginState) => {
12
- if (tr.docChanged) {
13
- let updatedTargetCell = {};
14
- if (pluginState.targetCellPosition) {
15
- const { pos, deleted } = tr.mapping.mapResult(pluginState.targetCellPosition);
16
-
17
- updatedTargetCell = {
18
- targetCellPosition: deleted ? undefined : pos,
19
- };
20
- }
21
-
22
- let updatedTablePos = {};
23
- if (pluginState.tablePos) {
24
- const { pos, deleted } = tr.mapping.mapResult(pluginState.tablePos, -1);
25
-
26
- updatedTablePos = {
27
- tablePos: deleted ? undefined : pos,
28
- };
29
- }
30
-
31
- return {
32
- ...pluginState,
33
- ...updatedTargetCell,
34
- ...updatedTablePos,
35
- };
36
- }
37
- return pluginState;
38
- },
39
- onDocChanged: handleDocOrSelectionChanged,
40
- onSelectionChanged: handleDocOrSelectionChanged,
41
- },
42
- );
@@ -1,8 +0,0 @@
1
- /* eslint-disable @atlaskit/editor/no-re-export */
2
- // Entry file in package.json
3
-
4
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
5
-
6
- import type { TablePluginState } from '../types';
7
-
8
- export const pluginKey = new PluginKey<TablePluginState>('tablePlugin');
@@ -1,145 +0,0 @@
1
- import type { TablePluginAction, TablePluginState } from '../types';
2
-
3
- import { defaultTableSelection } from './default-table-selection';
4
-
5
- export default (pluginState: TablePluginState, action: TablePluginAction): TablePluginState => {
6
- switch (action.type) {
7
- case 'TOGGLE_HEADER_COLUMN':
8
- return {
9
- ...pluginState,
10
- isHeaderColumnEnabled: !pluginState.isHeaderColumnEnabled,
11
- };
12
-
13
- case 'TOGGLE_HEADER_ROW':
14
- return {
15
- ...pluginState,
16
- isHeaderRowEnabled: !pluginState.isHeaderRowEnabled,
17
- };
18
-
19
- case 'CLEAR_HOVER_SELECTION':
20
- return { ...pluginState, ...action.data, ...defaultTableSelection };
21
-
22
- case 'SELECT_COLUMN':
23
- return { ...pluginState, ...action.data, isContextualMenuOpen: false };
24
-
25
- case 'SET_TARGET_CELL_POSITION':
26
- return { ...pluginState, ...action.data, isContextualMenuOpen: false };
27
-
28
- case 'TOGGLE_CONTEXTUAL_MENU':
29
- return {
30
- ...pluginState,
31
- isContextualMenuOpen: !pluginState.isContextualMenuOpen,
32
- };
33
-
34
- case 'SHOW_INSERT_ROW_BUTTON':
35
- if (action.data.insertRowButtonIndex === pluginState.insertRowButtonIndex) {
36
- return pluginState;
37
- }
38
-
39
- return {
40
- ...pluginState,
41
- ...action.data,
42
- insertColumnButtonIndex: undefined, // We need to assure that column is not shown
43
- };
44
-
45
- case 'SHOW_INSERT_COLUMN_BUTTON':
46
- if (action.data.insertColumnButtonIndex === pluginState.insertColumnButtonIndex) {
47
- return pluginState;
48
- }
49
- return {
50
- ...pluginState,
51
- ...action.data,
52
- insertRowButtonIndex: undefined, // We need to assure that row is not shown
53
- };
54
-
55
- case 'HIDE_INSERT_COLUMN_OR_ROW_BUTTON':
56
- if (
57
- pluginState.insertRowButtonIndex !== undefined ||
58
- pluginState.insertColumnButtonIndex !== undefined
59
- ) {
60
- return {
61
- ...pluginState,
62
- insertRowButtonIndex: undefined,
63
- insertColumnButtonIndex: undefined,
64
- };
65
- }
66
- return pluginState;
67
-
68
- case 'HIDE_RESIZE_HANDLE_LINE':
69
- return {
70
- ...pluginState,
71
- ...action.data,
72
- resizeHandleColumnIndex: undefined,
73
- resizeHandleRowIndex: undefined,
74
- };
75
- case 'START_KEYBOARD_COLUMN_RESIZE':
76
- case 'ADD_RESIZE_HANDLE_DECORATIONS':
77
- if (
78
- action.data.resizeHandleColumnIndex === pluginState.resizeHandleColumnIndex &&
79
- action.data.resizeHandleRowIndex === pluginState.resizeHandleRowIndex &&
80
- action.data.resizeHandleIncludeTooltip === pluginState.resizeHandleIncludeTooltip &&
81
- action.data.isKeyboardResize === pluginState.isKeyboardResize
82
- ) {
83
- return pluginState;
84
- }
85
- return {
86
- ...pluginState,
87
- ...action.data,
88
- isResizeHandleWidgetAdded: true,
89
- };
90
-
91
- case 'UPDATE_RESIZE_HANDLE_DECORATIONS':
92
- const { resizeHandleColumnIndex, resizeHandleRowIndex, resizeHandleIncludeTooltip } =
93
- action.data;
94
-
95
- if (
96
- (resizeHandleColumnIndex === pluginState.resizeHandleColumnIndex ||
97
- !Number.isFinite(resizeHandleColumnIndex)) &&
98
- (resizeHandleRowIndex === pluginState.resizeHandleRowIndex ||
99
- !Number.isFinite(resizeHandleRowIndex)) &&
100
- (resizeHandleIncludeTooltip === pluginState.resizeHandleIncludeTooltip ||
101
- resizeHandleIncludeTooltip === undefined)
102
- ) {
103
- return pluginState;
104
- }
105
-
106
- return {
107
- ...pluginState,
108
- resizeHandleColumnIndex: resizeHandleColumnIndex ?? pluginState.resizeHandleColumnIndex,
109
- resizeHandleRowIndex: resizeHandleRowIndex ?? pluginState.resizeHandleRowIndex,
110
- resizeHandleIncludeTooltip:
111
- resizeHandleIncludeTooltip ?? pluginState.resizeHandleIncludeTooltip,
112
- };
113
-
114
- case 'STOP_KEYBOARD_COLUMN_RESIZE':
115
- case 'REMOVE_RESIZE_HANDLE_DECORATIONS':
116
- if (!pluginState.isResizeHandleWidgetAdded) {
117
- return pluginState;
118
- }
119
-
120
- return {
121
- ...pluginState,
122
- ...action.data,
123
- resizeHandleColumnIndex: undefined,
124
- resizeHandleRowIndex: undefined,
125
- isResizeHandleWidgetAdded: false,
126
- isKeyboardResize: undefined,
127
- };
128
-
129
- case 'UPDATE_TABLE_WIDTH_TO_WIDEST':
130
- case 'SET_TABLE_REF':
131
- case 'HOVER_ROWS':
132
- case 'HOVER_COLUMNS':
133
- case 'HOVER_TABLE':
134
- case 'TABLE_HOVERED':
135
- case 'HOVER_MERGED_CELLS':
136
- case 'HOVER_CELL':
137
- case 'SHOW_RESIZE_HANDLE_LINE':
138
- case 'SET_EDITOR_FOCUS':
139
- case 'SET_CELL_MENU_OPEN':
140
- return { ...pluginState, ...action.data };
141
-
142
- default:
143
- return pluginState;
144
- }
145
- };