@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,530 +0,0 @@
1
- import React from 'react';
2
-
3
- import type { TableColumnOrdering } from '@atlaskit/custom-steps';
4
- import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
5
- import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
6
- import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
7
- import { type PortalProviderAPI } from '@atlaskit/editor-common/portal';
8
- import ReactNodeView from '@atlaskit/editor-common/react-node-view';
9
- import type {
10
- GetEditorContainerWidth,
11
- GetEditorFeatureFlags,
12
- getPosHandler,
13
- getPosHandlerNode,
14
- } from '@atlaskit/editor-common/types';
15
- import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
16
- import type { LimitedModePluginState } from '@atlaskit/editor-plugin-limited-mode';
17
- import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
18
- import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
19
- import {
20
- type EditorState,
21
- type PluginKey,
22
- type SelectionBookmark,
23
- } from '@atlaskit/editor-prosemirror/state';
24
- import type { EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
25
- import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
26
- import { TableMap } from '@atlaskit/editor-tables/table-map';
27
- import { fg } from '@atlaskit/platform-feature-flags';
28
-
29
- import { pluginConfig as getPluginConfig } from '../pm-plugins/create-plugin-config';
30
- import { pluginKey as tableDragAndDropPluginKey } from '../pm-plugins/drag-and-drop/plugin-key';
31
- import { getPluginState } from '../pm-plugins/plugin-factory';
32
- import { pluginKey } from '../pm-plugins/plugin-key';
33
- import { pluginKey as tableResizingPluginKey } from '../pm-plugins/table-resizing/plugin-key';
34
- import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
35
- import { isTableNested } from '../pm-plugins/utils/nodes';
36
- import type { PluginInjectionAPI } from '../types';
37
-
38
- import TableComponent from './TableComponent';
39
- import { TableComponentWithSharedState } from './TableComponentWithSharedState';
40
- import { tableNodeSpecWithFixedToDOM } from './toDOM';
41
- import type { Props } from './types';
42
-
43
- type ForwardRef = (node: HTMLElement | null) => void;
44
-
45
- const tableAttributes = (node: PmNode) => {
46
- return {
47
- 'data-number-column': node.attrs.isNumberColumnEnabled,
48
- 'data-layout': node.attrs.layout,
49
- 'data-autosize': node.attrs.__autoSize,
50
- 'data-table-local-id': node.attrs.localId || '',
51
- 'data-table-width': node.attrs.width || 'inherit',
52
- 'data-table-display-mode': node.attrs.displayMode,
53
- };
54
- };
55
-
56
- const getInlineWidth = (
57
- node: PmNode,
58
- options: Props['options'],
59
- state: EditorState,
60
- pos: number | undefined,
61
- allowTableResizing?: boolean,
62
- ): number | undefined => {
63
- if (
64
- (!node.attrs.width && options?.isChromelessEditor) ||
65
- (!node.attrs.width && options?.isCommentEditor && allowTableResizing)
66
- ) {
67
- return;
68
- }
69
-
70
- // provide a width for tables when custom table width is supported
71
- // this is to ensure 'responsive' tables (colgroup widths are undefined) become fixed to
72
- // support screen size adjustments
73
- const shouldHaveInlineWidth = allowTableResizing && !isTableNested(state, pos);
74
-
75
- let widthValue = getTableContainerWidth(node);
76
-
77
- if (node.attrs.isNumberColumnEnabled) {
78
- widthValue -= akEditorTableNumberColumnWidth;
79
- }
80
-
81
- return shouldHaveInlineWidth ? widthValue : undefined;
82
- };
83
-
84
- const handleInlineTableWidth = (table: HTMLElement, width: number | undefined) => {
85
- if (!table || !width) {
86
- return;
87
- }
88
- table.style.setProperty('width', `${width}px`);
89
- };
90
-
91
- export default class TableView extends ReactNodeView<Props> {
92
- private table: HTMLElement | undefined;
93
- private renderedDOM?: HTMLElement;
94
- private resizeObserver?: ResizeObserver;
95
- eventDispatcher?: EventDispatcher;
96
- getPos: getPosHandlerNode;
97
- options;
98
- getEditorFeatureFlags;
99
-
100
- constructor(props: Props) {
101
- super(
102
- props.node,
103
- props.view,
104
- props.getPos,
105
- props.portalProviderAPI,
106
- props.eventDispatcher,
107
- props,
108
- undefined,
109
- undefined,
110
- // @portal-render-immediately
111
- true,
112
- );
113
- this.getPos = props.getPos;
114
- this.eventDispatcher = props.eventDispatcher;
115
- this.options = props.options;
116
- this.getEditorFeatureFlags = props.getEditorFeatureFlags;
117
-
118
- this.handleRef = (node: HTMLElement | null) => this._handleTableRef(node);
119
- }
120
-
121
- getContentDOM() {
122
- const isNested = isTableNested(this.view.state, this.getPos());
123
- const tableDOMStructure = tableNodeSpecWithFixedToDOM({
124
- allowColumnResizing: !!this.reactComponentProps.allowColumnResizing,
125
- tableResizingEnabled: !!this.reactComponentProps.allowTableResizing,
126
- getEditorContainerWidth: this.reactComponentProps.getEditorContainerWidth,
127
- isTableScalingEnabled: this.reactComponentProps.options?.isTableScalingEnabled,
128
- shouldUseIncreasedScalingPercent:
129
- this.reactComponentProps.options?.shouldUseIncreasedScalingPercent,
130
- isCommentEditor: this.reactComponentProps.options?.isCommentEditor,
131
- isChromelessEditor: this.reactComponentProps.options?.isChromelessEditor,
132
- isNested,
133
- }).toDOM(this.node);
134
-
135
- const rendered = DOMSerializer.renderSpec(document, tableDOMStructure) as {
136
- dom: HTMLElement;
137
- contentDOM?: HTMLElement;
138
- };
139
-
140
- if (rendered.dom) {
141
- const tableElement = rendered.dom.querySelector('table');
142
- this.table = tableElement ? tableElement : rendered.dom;
143
- this.renderedDOM = rendered.dom;
144
-
145
- if (
146
- !this.options?.isTableScalingEnabled ||
147
- (this.options?.isTableScalingEnabled &&
148
- this.getEditorFeatureFlags?.().tableWithFixedColumnWidthsOption &&
149
- this.node.attrs.displayMode === 'fixed')
150
- ) {
151
- const tableInlineWidth = getInlineWidth(
152
- this.node,
153
- this.reactComponentProps.options,
154
- this.reactComponentProps.view.state,
155
- this.reactComponentProps.getPos(),
156
- this.reactComponentProps.allowTableResizing,
157
- );
158
- if (tableInlineWidth) {
159
- handleInlineTableWidth(this.table, tableInlineWidth);
160
- }
161
- }
162
- }
163
-
164
- return rendered;
165
- }
166
-
167
- /**
168
- * Handles moving the table from ProseMirror's DOM structure into a React-rendered table node.
169
- * Temporarily disables mutation observers (except for selection changes) during the move,
170
- * preserves selection state, and restores it afterwards if mutations occurred and cursor
171
- * wasn't at start of node. This prevents duplicate tables and maintains editor state during
172
- * the DOM manipulation.
173
- */
174
- private _handleTableRef(node: HTMLElement | null) {
175
- let oldIgnoreMutation: (mutation: MutationRecord) => boolean;
176
-
177
- let selectionBookmark: SelectionBookmark;
178
- let mutationsIgnored = false;
179
-
180
- // Only proceed if we have both a node and table, and the table isn't already inside the node
181
- if (node && this.table && !node.contains(this.table)) {
182
- // Store the current ignoreMutation handler so we can restore it later
183
- oldIgnoreMutation = this.ignoreMutation;
184
-
185
- // Set up a temporary mutation handler that:
186
- // - Ignores all DOM mutations except selection changes
187
- // - Tracks when mutations have been ignored via mutationsIgnored flag
188
- this.ignoreMutation = (m: MutationRecord | { type: string; target: Node }) => {
189
- const isSelectionMutation = m.type === 'selection';
190
- if (!isSelectionMutation) {
191
- mutationsIgnored = true;
192
- }
193
- return !isSelectionMutation;
194
- };
195
-
196
- // Store the current selection state if there is a visible selection
197
- // This lets us restore it after DOM changes
198
- if (this.view.state.selection.visible) {
199
- selectionBookmark = this.view.state.selection.getBookmark();
200
- }
201
-
202
- // Remove the ProseMirror table DOM structure to avoid duplication, as it's replaced with the React table node.
203
- if (this.dom && this.renderedDOM) {
204
- this.dom.removeChild(this.renderedDOM);
205
- }
206
- // Move the table from the ProseMirror table structure into the React rendered table node.
207
- node.appendChild(this.table);
208
-
209
- // After the next frame:
210
- requestAnimationFrame(() => {
211
- // Restore the original mutation handler
212
- this.ignoreMutation = oldIgnoreMutation;
213
-
214
- // Restore the selection only if:
215
- // - We have a selection bookmark
216
- // - Mutations were ignored during the table move
217
- // - The bookmarked selection is different from the current selection.
218
- if (selectionBookmark && mutationsIgnored) {
219
- const resolvedSelection = selectionBookmark.resolve(this.view.state.tr.doc);
220
- // Don't set the selection if it's the same as the current selection.
221
- if (!resolvedSelection.eq(this.view.state.selection)) {
222
- const tr = this.view.state.tr.setSelection(resolvedSelection);
223
- tr.setMeta('source', 'TableNodeView:_handleTableRef:selection-resync');
224
- this.view.dispatch(tr);
225
- }
226
- }
227
- });
228
- }
229
- }
230
-
231
- setDomAttrs(node: PmNode) {
232
- if (!this.table) {
233
- return;
234
- }
235
- const attrs = tableAttributes(node);
236
- (Object.keys(attrs) as Array<keyof typeof attrs>).forEach((attr) => {
237
- // Ignored via go/ees005
238
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
239
- this.table!.setAttribute(attr, attrs[attr]);
240
- });
241
-
242
- // Preserve Table Width cannot have inline width set on the table
243
- if (
244
- !this.options?.isTableScalingEnabled ||
245
- (this.options?.isTableScalingEnabled &&
246
- this.getEditorFeatureFlags?.().tableWithFixedColumnWidthsOption &&
247
- node.attrs.displayMode === 'fixed')
248
- ) {
249
- // handle inline style when table been resized
250
- const tableInlineWidth = getInlineWidth(
251
- node,
252
- (this.reactComponentProps as Props).options,
253
- this.view.state,
254
- this.getPos(),
255
- this.reactComponentProps.allowTableResizing,
256
- );
257
-
258
- const isTableResizing = tableWidthPluginKey.getState(this.view.state)?.resizing;
259
-
260
- if (!isTableResizing && tableInlineWidth) {
261
- handleInlineTableWidth(this.table, tableInlineWidth);
262
- }
263
- }
264
- }
265
-
266
- getNode = () => {
267
- return this.node;
268
- };
269
-
270
- render(props: Props, forwardRef: ForwardRef) {
271
- if (fg('platform_editor_table_use_shared_state_hook_fg')) {
272
- return (
273
- <TableComponentWithSharedState
274
- forwardRef={forwardRef}
275
- getNode={this.getNode}
276
- view={props.view}
277
- options={props.options}
278
- eventDispatcher={props.eventDispatcher}
279
- api={props.pluginInjectionApi}
280
- allowColumnResizing={props.allowColumnResizing}
281
- allowTableAlignment={props.allowTableAlignment}
282
- allowTableResizing={props.allowTableResizing}
283
- allowControls={props.allowControls}
284
- getPos={props.getPos}
285
- getEditorFeatureFlags={props.getEditorFeatureFlags}
286
- dispatchAnalyticsEvent={props.dispatchAnalyticsEvent}
287
- />
288
- );
289
- }
290
- // Please, do not copy or use this kind of code below
291
- // @ts-ignore
292
- const fakePluginKey = {
293
- key: 'widthPlugin$',
294
- getState: (state: EditorState) => {
295
- // Ignored via go/ees005
296
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
297
- return (state as any)['widthPlugin$'];
298
- },
299
- } as PluginKey;
300
-
301
- // Please, do not copy or use this kind of code below
302
- // @ts-ignore
303
- const fakeMediaPluginKey = {
304
- key: 'mediaPlugin$',
305
- getState: (state: EditorState) => {
306
- // Ignored via go/ees005
307
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
308
- return (state as any)['mediaPlugin$'];
309
- },
310
- } as PluginKey;
311
-
312
- return (
313
- <WithPluginState
314
- plugins={{
315
- pluginState: pluginKey,
316
- tableResizingPluginState: tableResizingPluginKey,
317
- tableWidthPluginState: tableWidthPluginKey,
318
- widthPlugin: fakePluginKey,
319
- mediaState: fakeMediaPluginKey,
320
- tableDragAndDropState: tableDragAndDropPluginKey,
321
-
322
- limitedModePlugin: props.pluginInjectionApi?.limitedMode?.sharedState.currentState()
323
- ?.limitedModePluginKey as PluginKey<LimitedModePluginState>,
324
- }}
325
- editorView={props.view}
326
- render={(pluginStates) => {
327
- const { tableResizingPluginState, tableWidthPluginState, pluginState, mediaState } =
328
- pluginStates;
329
- const containerWidth = props.getEditorContainerWidth();
330
-
331
- const isTableResizing = tableWidthPluginState?.resizing;
332
- const isResizing = Boolean(tableResizingPluginState?.dragging || isTableResizing);
333
-
334
- /**
335
- * ED-19810
336
- * There is a getPos issue coming from this code. We need to apply this workaround for now and apply a patch
337
- * directly to confluence since this bug is now in production.
338
- */
339
- let tablePos: number | undefined;
340
- try {
341
- tablePos = props.getPos ? props.getPos() : undefined;
342
- } catch (e) {
343
- tablePos = undefined;
344
- }
345
-
346
- // Ignored via go/ees005
347
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
348
- const tableActive = tablePos === pluginState!.tablePos && !isTableResizing;
349
-
350
- return (
351
- <TableComponent
352
- view={props.view}
353
- allowColumnResizing={props.allowColumnResizing}
354
- eventDispatcher={props.eventDispatcher}
355
- getPos={props.getPos}
356
- isMediaFullscreen={mediaState?.isFullscreen}
357
- options={props.options}
358
- // Ignored via go/ees005
359
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
360
- // Ignored via go/ees005
361
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
362
- allowControls={pluginState!.pluginConfig.allowControls!}
363
- // Ignored via go/ees005
364
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
365
- isHeaderRowEnabled={pluginState!.isHeaderRowEnabled}
366
- // Ignored via go/ees005
367
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
368
- isHeaderColumnEnabled={pluginState!.isHeaderColumnEnabled}
369
- // Ignored via go/ees005
370
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
371
- isDragAndDropEnabled={pluginState!.isDragAndDropEnabled}
372
- isTableScalingEnabled={props.options?.isTableScalingEnabled} // this.options?.isTableScalingEnabled same as TableOptions.isTableScalingEnabled same as pluginState.isTableScalingEnabled
373
- allowTableAlignment={props.allowTableAlignment}
374
- allowTableResizing={props.allowTableResizing}
375
- tableActive={tableActive}
376
- // Ignored via go/ees005
377
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
378
- ordering={pluginState!.ordering as TableColumnOrdering}
379
- isResizing={isResizing}
380
- getNode={this.getNode}
381
- // Ignored via go/ees005
382
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
383
- containerWidth={containerWidth!}
384
- contentDOM={forwardRef}
385
- getEditorFeatureFlags={props.getEditorFeatureFlags}
386
- dispatchAnalyticsEvent={props.dispatchAnalyticsEvent}
387
- pluginInjectionApi={props.pluginInjectionApi}
388
- limitedMode={pluginStates.limitedModePlugin?.documentSizeBreachesThreshold ?? false}
389
- />
390
- );
391
- }}
392
- />
393
- );
394
- }
395
-
396
- private hasHoveredRows = false;
397
- viewShouldUpdate(nextNode: PmNode) {
398
- const { hoveredRows } = getPluginState(this.view.state);
399
- const hoveredRowsChanged = !!hoveredRows?.length !== this.hasHoveredRows;
400
- if (nextNode.attrs.isNumberColumnEnabled && hoveredRowsChanged) {
401
- this.hasHoveredRows = !!hoveredRows?.length;
402
- return true;
403
- }
404
-
405
- const node = this.getNode();
406
- if (typeof node.attrs !== typeof nextNode.attrs) {
407
- return true;
408
- }
409
- const attrKeys = Object.keys(node.attrs);
410
- const nextAttrKeys = Object.keys(nextNode.attrs);
411
- if (attrKeys.length !== nextAttrKeys.length) {
412
- return true;
413
- }
414
-
415
- const tableMap = TableMap.get(node);
416
- const nextTableMap = TableMap.get(nextNode);
417
-
418
- if (tableMap.width !== nextTableMap.width) {
419
- return true;
420
- }
421
-
422
- return attrKeys.some((key) => {
423
- return node.attrs[key] !== nextNode.attrs[key];
424
- });
425
- }
426
-
427
- ignoreMutation(mutation: MutationRecord | { type: 'selection'; target: Node }) {
428
- const {
429
- type,
430
- target: { nodeName, firstChild },
431
- } = mutation;
432
-
433
- if (
434
- type === 'selection' &&
435
- nodeName?.toUpperCase() === 'DIV' &&
436
- firstChild?.nodeName.toUpperCase() === 'TABLE'
437
- ) {
438
- return false;
439
- }
440
-
441
- // ED-16668
442
- // Do not remove this fixes an issue with windows firefox that relates to
443
- // the addition of the shadow sentinels
444
- if (
445
- type === 'selection' &&
446
- nodeName?.toUpperCase() === 'TABLE' &&
447
- (firstChild?.nodeName.toUpperCase() === 'COLGROUP' ||
448
- firstChild?.nodeName.toUpperCase() === 'SPAN')
449
- ) {
450
- return false;
451
- }
452
-
453
- if (!this.contentDOM) {
454
- return true;
455
- }
456
- return !this.contentDOM.contains(mutation.target) && mutation.type !== 'selection';
457
- }
458
-
459
- destroy() {
460
- if (this.resizeObserver) {
461
- this.resizeObserver.disconnect();
462
- }
463
-
464
- this.eventDispatcher?.emit('TABLE_DELETED', this.node);
465
- super.destroy();
466
- }
467
- }
468
-
469
- export const createTableView = (
470
- node: PmNode,
471
- view: EditorView,
472
- getPos: getPosHandler,
473
- portalProviderAPI: PortalProviderAPI,
474
- eventDispatcher: EventDispatcher,
475
- getEditorContainerWidth: GetEditorContainerWidth,
476
- getEditorFeatureFlags: GetEditorFeatureFlags,
477
- dispatchAnalyticsEvent: DispatchAnalyticsEvent,
478
- pluginInjectionApi?: PluginInjectionAPI,
479
- isCommentEditor?: boolean,
480
- isChromelessEditor?: boolean,
481
- ): NodeView => {
482
- const {
483
- pluginConfig,
484
- isFullWidthModeEnabled,
485
- wasFullWidthModeEnabled,
486
- isDragAndDropEnabled,
487
- isTableScalingEnabled, // same as options.isTableScalingEnabled
488
- } = getPluginState(view.state);
489
-
490
- // Use shared state for isFullWidthModeEnabled and wasFullWidthModeEnabled for most up-to-date values
491
- const tableState = pluginInjectionApi?.table?.sharedState.currentState();
492
-
493
- const { allowColumnResizing, allowControls, allowTableResizing, allowTableAlignment } =
494
- getPluginConfig(pluginConfig);
495
-
496
- const isTableFixedColumnWidthsOptionEnabled =
497
- getEditorFeatureFlags?.().tableWithFixedColumnWidthsOption || false;
498
-
499
- const shouldUseIncreasedScalingPercent =
500
- isTableScalingEnabled && (isTableFixedColumnWidthsOptionEnabled || isCommentEditor);
501
-
502
- return new TableView({
503
- node,
504
- view,
505
- allowColumnResizing,
506
- allowTableResizing,
507
- allowTableAlignment,
508
- allowControls,
509
- portalProviderAPI,
510
- eventDispatcher,
511
- getPos: getPos as getPosHandlerNode,
512
- options: {
513
- isFullWidthModeEnabled: fg('platform_editor_table_overflow_in_full_width_fix')
514
- ? tableState?.isFullWidthModeEnabled
515
- : isFullWidthModeEnabled,
516
- wasFullWidthModeEnabled: fg('platform_editor_table_overflow_in_full_width_fix')
517
- ? tableState?.wasFullWidthModeEnabled
518
- : wasFullWidthModeEnabled,
519
- isDragAndDropEnabled,
520
- isTableScalingEnabled, // same as options.isTableScalingEnabled
521
- isCommentEditor,
522
- isChromelessEditor,
523
- shouldUseIncreasedScalingPercent,
524
- },
525
- getEditorContainerWidth,
526
- getEditorFeatureFlags,
527
- dispatchAnalyticsEvent,
528
- pluginInjectionApi,
529
- }).init();
530
- };