@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,438 +0,0 @@
1
- // #region Imports
2
- import { AddColumnStep } from '@atlaskit/custom-steps';
3
- import type { AnalyticsEventPayload, EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
4
- import {
5
- ACTION,
6
- ACTION_SUBJECT,
7
- ACTION_SUBJECT_ID,
8
- EVENT_TYPE,
9
- INPUT_METHOD,
10
- TABLE_OVERFLOW_CHANGE_TRIGGER,
11
- } from '@atlaskit/editor-common/analytics';
12
- import {
13
- getParentOfTypeCount,
14
- getPositionAfterTopParentNodeOfType,
15
- } from '@atlaskit/editor-common/nesting';
16
- import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
17
- import type { Transaction } from '@atlaskit/editor-prosemirror/state';
18
- import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
19
- import { hasParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
20
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
21
- import { TableMap } from '@atlaskit/editor-tables/table-map';
22
- import {
23
- addColumnAt as addColumnAtPMUtils,
24
- addRowAt,
25
- findTable,
26
- selectedRect,
27
- } from '@atlaskit/editor-tables/utils';
28
- import { fg } from '@atlaskit/platform-feature-flags';
29
- import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
30
-
31
- import type { PluginInjectionAPI } from '../../types';
32
- import { updateRowOrColumnMovedTransform } from '../analytics/commands';
33
- import { META_KEYS } from '../table-analytics';
34
- import { rescaleColumns } from '../transforms/column-width';
35
- import { createTableWithWidth } from '../utils/create';
36
- import { getAllowAddColumnCustomStep } from '../utils/get-allow-add-column-custom-step';
37
- import { checkIfHeaderRowEnabled } from '../utils/nodes';
38
- import { copyPreviousRow } from '../utils/row-controls';
39
-
40
- type InsertTableWithNestingSupportCommand = (
41
- options: {
42
- isTableScalingEnabled?: boolean;
43
- isTableAlignmentEnabled?: boolean;
44
- isFullWidthModeEnabled?: boolean;
45
- isCommentEditor?: boolean;
46
- isChromelessEditor?: boolean;
47
- isTableResizingEnabled?: boolean;
48
- createTableProps?: {
49
- rowsCount?: number;
50
- colsCount?: number;
51
- };
52
- },
53
- api: PluginInjectionAPI | undefined | null,
54
- analyticsPayload?: AnalyticsEventPayload,
55
- ) => EditorCommand;
56
-
57
- function addColumnAtCustomStep(column: number) {
58
- return (tr: Transaction) => {
59
- const table = findTable(tr.selection);
60
- if (table) {
61
- return tr.step(AddColumnStep.create(tr.doc, table.pos, column));
62
- }
63
- return tr;
64
- };
65
- }
66
-
67
- export function addColumnAt(
68
- api: PluginInjectionAPI | undefined | null,
69
- isTableScalingEnabled = false,
70
- isTableFixedColumnWidthsOptionEnabled?: boolean,
71
- shouldUseIncreasedScalingPercent?: boolean,
72
- isCommentEditor?: boolean,
73
- ) {
74
- return (
75
- column: number,
76
- allowAddColumnCustomStep: boolean = false,
77
- view: EditorView | undefined,
78
- ) => {
79
- return (tr: Transaction) => {
80
- let updatedTr = tr;
81
- if (allowAddColumnCustomStep) {
82
- updatedTr = addColumnAtCustomStep(column)(updatedTr);
83
- } else {
84
- updatedTr = addColumnAtPMUtils(column)(updatedTr);
85
- }
86
- const table = findTable(updatedTr.selection);
87
- if (table) {
88
- // [ED-8288] Update colwidths manually to avoid multiple dispatch in TableComponent
89
- updatedTr = rescaleColumns(
90
- isTableScalingEnabled,
91
- isTableFixedColumnWidthsOptionEnabled,
92
- shouldUseIncreasedScalingPercent,
93
- api,
94
- isCommentEditor,
95
- )(
96
- table,
97
- view,
98
- )(updatedTr);
99
- }
100
-
101
- if (view) {
102
- updatedTr = updateRowOrColumnMovedTransform({ type: 'column' }, 'addRowOrColumn')(
103
- view.state,
104
- updatedTr,
105
- );
106
- }
107
-
108
- updatedTr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
109
- name: TABLE_OVERFLOW_CHANGE_TRIGGER.ADDED_COLUMN,
110
- });
111
-
112
- return updatedTr;
113
- };
114
- };
115
- }
116
-
117
- // :: (EditorState, dispatch: ?(tr: Transaction)) → bool
118
- // Command to add a column before the column with the selection.
119
- export const addColumnBefore =
120
- (
121
- api: PluginInjectionAPI | undefined | null,
122
- isTableScalingEnabled = false,
123
- isTableFixedColumnWidthsOptionEnabled = false,
124
- shouldUseIncreasedScalingPercent = false,
125
- isCommentEditor = false,
126
- ): Command =>
127
- (state, dispatch, view) => {
128
- const table = findTable(state.selection);
129
- if (!table) {
130
- return false;
131
- }
132
- if (dispatch) {
133
- const rect = selectedRect(state);
134
- dispatch(
135
- addColumnAt(
136
- api,
137
- isTableScalingEnabled,
138
- isTableFixedColumnWidthsOptionEnabled,
139
- shouldUseIncreasedScalingPercent,
140
- isCommentEditor,
141
- )(
142
- rect.left,
143
- getAllowAddColumnCustomStep(state),
144
- view,
145
- )(state.tr),
146
- );
147
- }
148
- return true;
149
- };
150
-
151
- // :: (EditorState, dispatch: ?(tr: Transaction)) → bool
152
- // Command to add a column after the column with the selection.
153
- export const addColumnAfter =
154
- (
155
- api: PluginInjectionAPI | undefined | null,
156
- isTableScalingEnabled?: boolean,
157
- isTableFixedColumnWidthsOptionEnabled?: boolean,
158
- shouldUseIncreasedScalingPercent?: boolean,
159
- isCommentEditor?: boolean,
160
- ): Command =>
161
- (state, dispatch, view) => {
162
- const table = findTable(state.selection);
163
- if (!table) {
164
- return false;
165
- }
166
-
167
- if (dispatch) {
168
- const rect = selectedRect(state);
169
- dispatch(
170
- addColumnAt(
171
- api,
172
- isTableScalingEnabled,
173
- isTableFixedColumnWidthsOptionEnabled,
174
- shouldUseIncreasedScalingPercent,
175
- isCommentEditor,
176
- )(
177
- rect.right,
178
- getAllowAddColumnCustomStep(state),
179
- view,
180
- )(state.tr),
181
- );
182
- }
183
- return true;
184
- };
185
-
186
- export const insertColumn =
187
- (
188
- api: PluginInjectionAPI | undefined | null,
189
- isTableScalingEnabled = false,
190
- isTableFixedColumnWidthsOptionEnabled?: boolean,
191
- shouldUseIncreasedScalingPercent?: boolean,
192
- isCommentEditor?: boolean,
193
- ) =>
194
- (column: number): Command =>
195
- (state, dispatch, view) => {
196
- const tr = addColumnAt(
197
- api,
198
- isTableScalingEnabled,
199
- isTableFixedColumnWidthsOptionEnabled,
200
- shouldUseIncreasedScalingPercent,
201
- isCommentEditor,
202
- )(
203
- column,
204
- getAllowAddColumnCustomStep(state),
205
- view,
206
- )(state.tr);
207
- const table = findTable(tr.selection);
208
- if (!table) {
209
- return false;
210
- }
211
- // move the cursor to the newly created column
212
- const pos = TableMap.get(table.node).positionAt(0, column, table.node);
213
-
214
- if (dispatch) {
215
- dispatch(tr.setSelection(Selection.near(tr.doc.resolve(table.start + pos))));
216
- }
217
- return true;
218
- };
219
-
220
- export const insertRow =
221
- (row: number, moveCursorToTheNewRow: boolean): Command =>
222
- (state, dispatch) => {
223
- // Don't clone the header row
224
- const headerRowEnabled = checkIfHeaderRowEnabled(state.selection);
225
- const clonePreviousRow = (headerRowEnabled && row > 1) || (!headerRowEnabled && row > 0);
226
-
227
- // When the table have header row
228
- // we should not add row on the position zero
229
- if (row === 0 && headerRowEnabled) {
230
- return false;
231
- }
232
-
233
- const tr = clonePreviousRow
234
- ? copyPreviousRow(state.schema)(row)(state.tr)
235
- : addRowAt(row, undefined)(state.tr);
236
-
237
- const table = findTable(tr.selection);
238
- if (!table) {
239
- return false;
240
- }
241
- if (dispatch) {
242
- const { selection } = state;
243
- if (moveCursorToTheNewRow) {
244
- // move the cursor to the newly created row
245
- const pos = TableMap.get(table.node).positionAt(row, 0, table.node);
246
- tr.setSelection(Selection.near(tr.doc.resolve(table.start + pos)));
247
- } else {
248
- tr.setSelection(selection.map(tr.doc, tr.mapping));
249
- }
250
-
251
- updateRowOrColumnMovedTransform(
252
- {
253
- type: 'row',
254
- },
255
- 'addRowOrColumn',
256
- )(state, tr);
257
-
258
- dispatch(tr);
259
- }
260
- return true;
261
- };
262
-
263
- /**
264
- * @private
265
- * @deprecated This function is deprecated - please use insertTableWithNestingSupport instead.
266
- * (To be removed with feature gate: `platform_editor_use_nested_table_pm_nodes`)
267
- */
268
- export const createTable =
269
- (
270
- isTableScalingEnabled?: boolean,
271
- isTableAlignmentEnabled?: boolean,
272
- isFullWidthModeEnabled?: boolean,
273
- editorAnalyticsAPI?: EditorAnalyticsAPI | undefined | null,
274
- isCommentEditor?: boolean,
275
- isChromelessEditor?: boolean,
276
- isTableResizingEnabled?: boolean,
277
- ): Command =>
278
- (state, dispatch) => {
279
- const table = createTableWithWidth({
280
- isTableScalingEnabled,
281
- isTableAlignmentEnabled,
282
- isFullWidthModeEnabled,
283
- isCommentEditor,
284
- isChromelessEditor,
285
- isTableResizingEnabled,
286
- })(state.schema);
287
-
288
- if (dispatch) {
289
- const tr = safeInsert(table)(state.tr).scrollIntoView();
290
- if (editorAnalyticsAPI) {
291
- editorAnalyticsAPI?.attachAnalyticsEvent({
292
- action: ACTION.INSERTED,
293
- actionSubject: ACTION_SUBJECT.DOCUMENT,
294
- actionSubjectId: ACTION_SUBJECT_ID.TABLE,
295
- attributes: { inputMethod: INPUT_METHOD.SHORTCUT },
296
- eventType: EVENT_TYPE.TRACK,
297
- })(tr);
298
- }
299
- dispatch(tr);
300
- }
301
-
302
- return true;
303
- };
304
-
305
- /**
306
- * @private
307
- * @deprecated This function is deprecated - please use insertTableWithNestingSupport instead.
308
- * (To be removed with feature gate: `platform_editor_use_nested_table_pm_nodes`)
309
- */
310
- export const insertTableWithSize =
311
- (
312
- isFullWidthModeEnabled?: boolean,
313
- isTableScalingEnabled?: boolean,
314
- isTableAlignmentEnabled?: boolean,
315
- editorAnalyticsAPI?: EditorAnalyticsAPI,
316
- isCommentEditor?: boolean,
317
- isChromelessEditor?: boolean,
318
- ) =>
319
- (rowsCount: number, colsCount: number, inputMethod?: INPUT_METHOD.PICKER): EditorCommand => {
320
- return ({ tr }) => {
321
- const tableNode = createTableWithWidth({
322
- isTableScalingEnabled,
323
- isFullWidthModeEnabled,
324
- isTableAlignmentEnabled,
325
- isCommentEditor,
326
- isChromelessEditor,
327
- createTableProps: {
328
- rowsCount: rowsCount,
329
- colsCount: colsCount,
330
- },
331
- })(tr.doc.type.schema);
332
-
333
- const newTr = safeInsert(tableNode)(tr).scrollIntoView();
334
- if (inputMethod) {
335
- editorAnalyticsAPI?.attachAnalyticsEvent({
336
- action: ACTION.INSERTED,
337
- actionSubject: ACTION_SUBJECT.DOCUMENT,
338
- actionSubjectId: ACTION_SUBJECT_ID.TABLE,
339
- attributes: {
340
- inputMethod: inputMethod,
341
- totalRowCount: rowsCount,
342
- totalColumnCount: colsCount,
343
- },
344
- eventType: EVENT_TYPE.TRACK,
345
- })(newTr);
346
- }
347
- return newTr;
348
- };
349
- };
350
-
351
- /**
352
- * Unified command to insert a new table into the editor.
353
- *
354
- * @param {Object} options - Configuration options for table insertion.
355
- * @param {boolean} [options.isTableScalingEnabled=false] - Flag to enable table scaling.
356
- * @param {boolean} [options.isTableAlignmentEnabled=false] - Flag to enable table alignment.
357
- * @param {boolean} [options.isFullWidthModeEnabled=false] - Flag to enable full-width mode for the table.
358
- * @param {boolean} [options.isCommentEditor=false] - Flag to indicate if the editor is in comment mode.
359
- * @param {boolean} [options.isChromelessEditor=false] - Flag to indicate if the editor is chromeless.
360
- * @param {boolean} [options.isTableResizingEnabled=false] - Flag to enable table resizing.
361
- * @param {Object} [options.createTableProps={}] - Additional properties for table creation, including table size.
362
- * @param {Object} api - PluginInjectinoApi object for content insertion commands.
363
- * @param {Object} analyticsPayload - Payload for analytics tracking.
364
- *
365
- * @returns {Function} A function that takes a transaction and inserts a table.
366
- */
367
- export const insertTableWithNestingSupport: InsertTableWithNestingSupportCommand =
368
- (
369
- {
370
- isTableScalingEnabled = false,
371
- isTableAlignmentEnabled = false,
372
- isFullWidthModeEnabled = false,
373
- isCommentEditor = false,
374
- isChromelessEditor = false,
375
- isTableResizingEnabled = false,
376
- createTableProps = {},
377
- },
378
- api,
379
- analyticsPayload,
380
- ) =>
381
- ({ tr }) => {
382
- const { schema } = tr.doc.type;
383
-
384
- // If the cursor is inside a table
385
- let insertAt: Selection | undefined;
386
- let isNestedTable = false;
387
- if (
388
- hasParentNodeOfType(schema.nodes.table)(tr.selection) &&
389
- fg('platform_editor_use_nested_table_pm_nodes')
390
- ) {
391
- // If the experiment is disabled, or we're trying to nest deeper than one level, we insert the table after the top table
392
- if (
393
- editorExperiment('nested-tables-in-tables', false, { exposure: true }) ||
394
- getParentOfTypeCount(schema.nodes.table)(tr.selection.$from) > 1
395
- ) {
396
- const positionAfterTopTable = getPositionAfterTopParentNodeOfType(schema.nodes.table)(
397
- tr.selection.$from,
398
- );
399
- if (!positionAfterTopTable) {
400
- return tr;
401
- }
402
- insertAt = TextSelection.create(tr.doc, positionAfterTopTable);
403
- } else {
404
- // Table can be nested in parent table
405
- isNestedTable = true;
406
- }
407
- }
408
-
409
- const node = createTableWithWidth({
410
- isTableScalingEnabled,
411
- isTableAlignmentEnabled,
412
- isFullWidthModeEnabled,
413
- isCommentEditor,
414
- isChromelessEditor,
415
- isTableResizingEnabled,
416
- isNestedTable,
417
- createTableProps,
418
- })(schema);
419
-
420
- api?.contentInsertion?.commands?.insert({
421
- node,
422
- options: {
423
- selectNodeInserted: false,
424
- analyticsPayload: analyticsPayload
425
- ? {
426
- ...analyticsPayload,
427
- attributes: {
428
- ...analyticsPayload.attributes,
429
- localId: node.attrs.localId,
430
- },
431
- }
432
- : undefined,
433
- insertAt,
434
- },
435
- })({ tr });
436
-
437
- return tr;
438
- };