@atlaskit/editor-plugin-table 7.16.0 → 7.16.2

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 (72) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/commands/insert.js +14 -2
  3. package/dist/cjs/commands/misc.js +15 -1
  4. package/dist/cjs/commands-with-analytics.js +25 -2
  5. package/dist/cjs/nodeviews/TableComponent.js +4 -2
  6. package/dist/cjs/nodeviews/TableComponentWithSharedState.js +1 -0
  7. package/dist/cjs/nodeviews/TableContainer.js +72 -34
  8. package/dist/cjs/nodeviews/table.js +7 -4
  9. package/dist/cjs/plugin.js +13 -5
  10. package/dist/cjs/pm-plugins/keymap.js +1 -13
  11. package/dist/cjs/pm-plugins/main.js +1 -1
  12. package/dist/cjs/toolbar.js +9 -26
  13. package/dist/cjs/utils/alignment.js +13 -0
  14. package/dist/es2019/commands/insert.js +15 -3
  15. package/dist/es2019/commands/misc.js +15 -1
  16. package/dist/es2019/commands-with-analytics.js +22 -2
  17. package/dist/es2019/nodeviews/TableComponent.js +5 -2
  18. package/dist/es2019/nodeviews/TableComponentWithSharedState.js +1 -0
  19. package/dist/es2019/nodeviews/TableContainer.js +51 -11
  20. package/dist/es2019/nodeviews/table.js +7 -4
  21. package/dist/es2019/plugin.js +13 -6
  22. package/dist/es2019/pm-plugins/keymap.js +4 -14
  23. package/dist/es2019/pm-plugins/main.js +1 -1
  24. package/dist/es2019/toolbar.js +8 -25
  25. package/dist/es2019/utils/alignment.js +5 -0
  26. package/dist/esm/commands/insert.js +15 -3
  27. package/dist/esm/commands/misc.js +14 -0
  28. package/dist/esm/commands-with-analytics.js +25 -2
  29. package/dist/esm/nodeviews/TableComponent.js +4 -2
  30. package/dist/esm/nodeviews/TableComponentWithSharedState.js +1 -0
  31. package/dist/esm/nodeviews/TableContainer.js +73 -35
  32. package/dist/esm/nodeviews/table.js +7 -4
  33. package/dist/esm/plugin.js +14 -6
  34. package/dist/esm/pm-plugins/keymap.js +4 -16
  35. package/dist/esm/pm-plugins/main.js +1 -1
  36. package/dist/esm/toolbar.js +8 -27
  37. package/dist/esm/utils/alignment.js +7 -0
  38. package/dist/types/commands/insert.d.ts +3 -2
  39. package/dist/types/commands/misc.d.ts +3 -1
  40. package/dist/types/commands-with-analytics.d.ts +3 -1
  41. package/dist/types/nodeviews/TableComponent.d.ts +1 -0
  42. package/dist/types/nodeviews/TableContainer.d.ts +7 -5
  43. package/dist/types/nodeviews/table.d.ts +1 -1
  44. package/dist/types/nodeviews/types.d.ts +1 -0
  45. package/dist/types/toolbar.d.ts +3 -4
  46. package/dist/types/types.d.ts +1 -0
  47. package/dist/types/utils/alignment.d.ts +7 -0
  48. package/dist/types-ts4.5/commands/insert.d.ts +3 -2
  49. package/dist/types-ts4.5/commands/misc.d.ts +3 -1
  50. package/dist/types-ts4.5/commands-with-analytics.d.ts +3 -1
  51. package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +1 -0
  52. package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +7 -5
  53. package/dist/types-ts4.5/nodeviews/table.d.ts +1 -1
  54. package/dist/types-ts4.5/nodeviews/types.d.ts +1 -0
  55. package/dist/types-ts4.5/toolbar.d.ts +3 -4
  56. package/dist/types-ts4.5/types.d.ts +1 -0
  57. package/dist/types-ts4.5/utils/alignment.d.ts +7 -0
  58. package/package.json +6 -6
  59. package/src/commands/insert.ts +26 -18
  60. package/src/commands/misc.ts +28 -6
  61. package/src/commands-with-analytics.ts +38 -1
  62. package/src/nodeviews/TableComponent.tsx +3 -0
  63. package/src/nodeviews/TableComponentWithSharedState.tsx +1 -0
  64. package/src/nodeviews/TableContainer.tsx +75 -13
  65. package/src/nodeviews/table.tsx +4 -1
  66. package/src/nodeviews/types.ts +1 -0
  67. package/src/plugin.tsx +20 -22
  68. package/src/pm-plugins/keymap.ts +4 -25
  69. package/src/pm-plugins/main.ts +1 -0
  70. package/src/toolbar.tsx +16 -37
  71. package/src/types.ts +2 -0
  72. package/src/utils/alignment.ts +10 -0
@@ -1,14 +1,12 @@
1
1
  // #region Imports
2
2
  import { AddColumnStep } from '@atlaskit/custom-steps';
3
- import type {
4
- EditorAnalyticsAPI,
5
- INPUT_METHOD,
6
- } from '@atlaskit/editor-common/analytics';
3
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
7
4
  import {
8
5
  ACTION,
9
6
  ACTION_SUBJECT,
10
7
  ACTION_SUBJECT_ID,
11
8
  EVENT_TYPE,
9
+ INPUT_METHOD,
12
10
  TABLE_OVERFLOW_CHANGE_TRIGGER,
13
11
  } from '@atlaskit/editor-common/analytics';
14
12
  import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
@@ -203,22 +201,32 @@ export const insertRow =
203
201
  return true;
204
202
  };
205
203
 
206
- export const createTable =
207
- (
208
- isTableScalingEnabled?: boolean,
209
- isFullWidthModeEnabled?: boolean,
210
- ): Command =>
211
- (state, dispatch) => {
212
- const table = createTableWithWidth(
213
- isTableScalingEnabled,
214
- isFullWidthModeEnabled,
215
- )(state.schema);
204
+ export const createTable = (
205
+ isTableScalingEnabled?: boolean,
206
+ isFullWidthModeEnabled?: boolean,
207
+ editorAnalyticsAPI?: EditorAnalyticsAPI | undefined | null,
208
+ ): Command => (state, dispatch) => {
209
+ const table = createTableWithWidth(
210
+ isTableScalingEnabled,
211
+ isFullWidthModeEnabled,
212
+ )(state.schema);
216
213
 
217
- if (dispatch) {
218
- dispatch(safeInsert(table)(state.tr).scrollIntoView());
214
+ if (dispatch) {
215
+ const tr = safeInsert(table)(state.tr).scrollIntoView();
216
+ if (editorAnalyticsAPI) {
217
+ editorAnalyticsAPI?.attachAnalyticsEvent({
218
+ action: ACTION.INSERTED,
219
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
220
+ actionSubjectId: ACTION_SUBJECT_ID.TABLE,
221
+ attributes: { inputMethod: INPUT_METHOD.SHORTCUT },
222
+ eventType: EVENT_TYPE.TRACK,
223
+ })(tr);
219
224
  }
220
- return true;
221
- };
225
+ dispatch(tr);
226
+ }
227
+
228
+ return true;
229
+ }
222
230
 
223
231
  export const insertTableWithSize =
224
232
  (
@@ -1,7 +1,7 @@
1
1
  import isEqual from 'lodash/isEqual';
2
2
 
3
- import type { CellAttributes } from '@atlaskit/adf-schema';
4
- import type { Command } from '@atlaskit/editor-common/types';
3
+ import type { CellAttributes, TableLayout } from '@atlaskit/adf-schema';
4
+ import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
5
5
  import {
6
6
  closestElement,
7
7
  isParagraph,
@@ -270,8 +270,8 @@ export const getTableSelectionType = (selection: Selection) => {
270
270
  return selection.isRowSelection()
271
271
  ? 'row'
272
272
  : selection.isColSelection()
273
- ? 'column'
274
- : undefined;
273
+ ? 'column'
274
+ : undefined;
275
275
  }
276
276
  };
277
277
 
@@ -313,8 +313,8 @@ export const getTableElementMoveTypeBySlice = (
313
313
  return map.width === slicedMap.width
314
314
  ? 'row'
315
315
  : map.height === slicedMap.height
316
- ? 'column'
317
- : undefined;
316
+ ? 'column'
317
+ : undefined;
318
318
  } catch (e) {
319
319
  return undefined;
320
320
  }
@@ -809,3 +809,25 @@ export const updateWidthToWidest = (widthToWidest: WidthToWidest) =>
809
809
  },
810
810
  };
811
811
  });
812
+
813
+ export const setTableAlignment =
814
+ (newAlignment: TableLayout): EditorCommand =>
815
+ ({ tr }) => {
816
+ const tableObject = findTable(tr.selection);
817
+
818
+ if (!tableObject) {
819
+ return null;
820
+ }
821
+
822
+ const nextTableAttrs = {
823
+ ...tableObject.node.attrs,
824
+ layout: newAlignment,
825
+ };
826
+
827
+ tr.setNodeMarkup(tableObject.pos, undefined, nextTableAttrs).setMeta(
828
+ 'scrollIntoView',
829
+ false,
830
+ );
831
+
832
+ return tr;
833
+ };
@@ -1,5 +1,6 @@
1
1
  import type { IntlShape } from 'react-intl-next/src/types';
2
2
 
3
+ import type { TableLayout } from '@atlaskit/adf-schema';
3
4
  import { tableBackgroundColorPalette } from '@atlaskit/adf-schema';
4
5
  import type { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
5
6
  import {
@@ -40,6 +41,7 @@ import {
40
41
  deleteTableIfSelected,
41
42
  getTableSelectionType,
42
43
  setMultipleCellAttrs,
44
+ setTableAlignment,
43
45
  } from './commands/misc';
44
46
  import { sortByColumn } from './commands/sort';
45
47
  import { splitCell } from './commands/split-cell';
@@ -55,6 +57,7 @@ import { distributeColumnsWidths } from './pm-plugins/table-resizing/commands';
55
57
  import type { ResizeStateWithAnalytics } from './pm-plugins/table-resizing/utils';
56
58
  import { deleteRows, mergeCells } from './transforms';
57
59
  import type {
60
+ AlignmentOptions,
58
61
  InsertRowMethods,
59
62
  InsertRowOptions,
60
63
  RowInsertPosition,
@@ -691,4 +694,38 @@ export const toggleTableLockWithAnalytics =
691
694
  eventType: EVENT_TYPE.TRACK,
692
695
  };
693
696
  })(editorAnalyticsAPI)(editorCommandToPMCommand(setTableDisplayMode));
694
- // #endregion
697
+
698
+ export const setTableAlignmentWithAnalytics =
699
+ (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
700
+ (
701
+ newAlignment: AlignmentOptions,
702
+ // previous alignment could be a breakout value, if so use 'null' to indicate alignment was not previously set
703
+ previousAlignment: TableLayout,
704
+ inputMethod: INPUT_METHOD.FLOATING_TB,
705
+ ) =>
706
+ withEditorAnalyticsAPI((state) => {
707
+ const { table, totalRowCount, totalColumnCount } = getSelectedTableInfo(
708
+ state.selection,
709
+ );
710
+
711
+ return {
712
+ action: TABLE_ACTION.CHANGED_ALIGNMENT,
713
+ actionSubject: ACTION_SUBJECT.TABLE,
714
+ actionSubjectId: null,
715
+ eventType: EVENT_TYPE.TRACK,
716
+ attributes: {
717
+ tableWidth: table?.node.attrs.width,
718
+ newAlignment,
719
+ previousAlignment:
720
+ previousAlignment === 'center' ||
721
+ previousAlignment === 'align-start'
722
+ ? previousAlignment
723
+ : null,
724
+ totalRowCount,
725
+ totalColumnCount,
726
+ inputMethod,
727
+ },
728
+ };
729
+ })(editorAnalyticsAPI)(
730
+ editorCommandToPMCommand(setTableAlignment(newAlignment)),
731
+ );
@@ -104,6 +104,7 @@ export interface ComponentProps {
104
104
  isMediaFullscreen?: boolean;
105
105
  isDragAndDropEnabled?: boolean;
106
106
  isTableScalingEnabled?: boolean;
107
+ isTableAlignmentEnabled?: boolean;
107
108
  tableActive: boolean;
108
109
  ordering?: TableColumnOrdering;
109
110
  isResizing?: boolean;
@@ -687,6 +688,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
687
688
  isDragAndDropEnabled,
688
689
  getEditorFeatureFlags,
689
690
  isTableScalingEnabled, // here we can use options.isTableScalingEnabled
691
+ isTableAlignmentEnabled
690
692
  } = this.props;
691
693
 
692
694
  let {
@@ -820,6 +822,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
820
822
  isResizing={isResizing}
821
823
  isTableScalingEnabled={isTableScalingEnabled}
822
824
  isWholeTableInDanger={isWholeTableInDanger}
825
+ isTableAlignmentEnabled={isTableAlignmentEnabled}
823
826
  >
824
827
  <div
825
828
  className={ClassName.TABLE_STICKY_SENTINEL_TOP}
@@ -106,6 +106,7 @@ export const TableComponentWithSharedState = ({
106
106
  isHeaderColumnEnabled={isHeaderColumnEnabled}
107
107
  isDragAndDropEnabled={options?.isDragAndDropEnabled}
108
108
  isTableScalingEnabled={options?.isTableScalingEnabled}
109
+ isTableAlignmentEnabled={options?.isTableAlignmentEnabled}
109
110
  tableActive={tableActive}
110
111
  ordering={ordering}
111
112
  isResizing={isResizing}
@@ -1,5 +1,11 @@
1
1
  import type { PropsWithChildren } from 'react';
2
- import React, { forwardRef, useCallback, useRef, useState } from 'react';
2
+ import React, {
3
+ forwardRef,
4
+ useCallback,
5
+ useMemo,
6
+ useRef,
7
+ useState,
8
+ } from 'react';
3
9
 
4
10
  import classNames from 'classnames';
5
11
 
@@ -50,6 +56,57 @@ export const InnerContainer = forwardRef<
50
56
  );
51
57
  });
52
58
 
59
+ const centerAlignStyle = { display: 'flex', justifyContent: 'center' };
60
+
61
+ const leftAlignStyle = { display: 'flex', justifyContent: 'flex-start' };
62
+
63
+ type AlignmentTableContainerProps = {
64
+ node: PMNode;
65
+ };
66
+
67
+ const AlignmentTableContainer = ({
68
+ node,
69
+ children,
70
+ }: PropsWithChildren<AlignmentTableContainerProps>) => {
71
+ const alignment = node.attrs.layout;
72
+
73
+ const style = useMemo(() => {
74
+ return alignment === 'align-start' ? leftAlignStyle : centerAlignStyle;
75
+ }, [alignment]);
76
+
77
+ return (
78
+ <div data-testid="table-alignment-container" style={style}>
79
+ {children}
80
+ </div>
81
+ );
82
+ };
83
+
84
+ const AlignmentTableContainerWrapper = ({
85
+ isTableAlignmentEnabled,
86
+ node,
87
+ children,
88
+ }: PropsWithChildren<
89
+ AlignmentTableContainerProps & { isTableAlignmentEnabled?: boolean }
90
+ >) => {
91
+ if (!isTableAlignmentEnabled) {
92
+ return (
93
+ <div
94
+ data-testid="table-alignment-container"
95
+ style={{
96
+ display: 'flex',
97
+ justifyContent: 'center',
98
+ }}
99
+ >
100
+ {children}
101
+ </div>
102
+ );
103
+ }
104
+
105
+ return (
106
+ <AlignmentTableContainer node={node}>{children}</AlignmentTableContainer>
107
+ );
108
+ };
109
+
53
110
  type ResizableTableContainerProps = {
54
111
  containerWidth: number;
55
112
  node: PMNode;
@@ -59,9 +116,11 @@ type ResizableTableContainerProps = {
59
116
  tableRef: HTMLTableElement;
60
117
  isResizing?: boolean;
61
118
  pluginInjectionApi?: PluginInjectionAPI;
62
- isTableScalingEnabled?: boolean;
63
119
  tableWrapperHeight?: number;
64
120
  isWholeTableInDanger?: boolean;
121
+
122
+ isTableScalingEnabled?: boolean;
123
+ isTableAlignmentEnabled?: boolean;
65
124
  };
66
125
 
67
126
  export const ResizableTableContainer = React.memo(
@@ -75,9 +134,10 @@ export const ResizableTableContainer = React.memo(
75
134
  tableRef,
76
135
  isResizing,
77
136
  pluginInjectionApi,
78
- isTableScalingEnabled,
79
137
  tableWrapperHeight,
80
138
  isWholeTableInDanger,
139
+ isTableScalingEnabled,
140
+ isTableAlignmentEnabled,
81
141
  }: PropsWithChildren<ResizableTableContainerProps>) => {
82
142
  const containerRef = useRef<HTMLDivElement | null>(null);
83
143
  const tableWidthRef = useRef<number>(akEditorDefaultLayoutWidth);
@@ -204,11 +264,9 @@ export const ResizableTableContainer = React.memo(
204
264
  const isLivePageViewMode = editorViewModeState?.mode === 'view';
205
265
 
206
266
  return (
207
- <div
208
- style={{
209
- display: 'flex',
210
- justifyContent: 'center',
211
- }}
267
+ <AlignmentTableContainerWrapper
268
+ isTableAlignmentEnabled={isTableAlignmentEnabled}
269
+ node={node}
212
270
  >
213
271
  <div
214
272
  style={{
@@ -237,7 +295,7 @@ export const ResizableTableContainer = React.memo(
237
295
  </TableResizer>
238
296
  )}
239
297
  </div>
240
- </div>
298
+ </AlignmentTableContainerWrapper>
241
299
  );
242
300
  },
243
301
  );
@@ -246,16 +304,18 @@ type TableContainerProps = {
246
304
  node: PMNode;
247
305
  className: string;
248
306
  containerWidth: EditorContainerWidth;
249
- isTableResizingEnabled: boolean | undefined;
250
307
  editorView: EditorView;
251
308
  getPos: () => number | undefined;
252
309
  tableRef: HTMLTableElement;
253
310
  isNested: boolean;
254
311
  isResizing?: boolean;
255
312
  pluginInjectionApi?: PluginInjectionAPI;
256
- isTableScalingEnabled?: boolean;
257
313
  tableWrapperHeight?: number;
258
314
  isWholeTableInDanger?: boolean;
315
+
316
+ isTableResizingEnabled: boolean | undefined;
317
+ isTableScalingEnabled?: boolean;
318
+ isTableAlignmentEnabled?: boolean;
259
319
  };
260
320
 
261
321
  export const TableContainer = ({
@@ -263,7 +323,6 @@ export const TableContainer = ({
263
323
  node,
264
324
  className,
265
325
  containerWidth: { width: editorWidth },
266
- isTableResizingEnabled,
267
326
  editorView,
268
327
  getPos,
269
328
  tableRef,
@@ -271,8 +330,10 @@ export const TableContainer = ({
271
330
  tableWrapperHeight,
272
331
  isResizing,
273
332
  pluginInjectionApi,
274
- isTableScalingEnabled,
275
333
  isWholeTableInDanger,
334
+ isTableResizingEnabled,
335
+ isTableScalingEnabled,
336
+ isTableAlignmentEnabled,
276
337
  }: PropsWithChildren<TableContainerProps>) => {
277
338
  if (isTableResizingEnabled && !isNested) {
278
339
  return (
@@ -288,6 +349,7 @@ export const TableContainer = ({
288
349
  pluginInjectionApi={pluginInjectionApi}
289
350
  isTableScalingEnabled={isTableScalingEnabled}
290
351
  isWholeTableInDanger={isWholeTableInDanger}
352
+ isTableAlignmentEnabled={isTableAlignmentEnabled}
291
353
  >
292
354
  {children}
293
355
  </ResizableTableContainer>
@@ -292,7 +292,8 @@ export default class TableView extends ReactNodeView<Props> {
292
292
  isHeaderRowEnabled={pluginState!.isHeaderRowEnabled}
293
293
  isHeaderColumnEnabled={pluginState!.isHeaderColumnEnabled}
294
294
  isDragAndDropEnabled={pluginState!.isDragAndDropEnabled}
295
- isTableScalingEnabled={props.options?.isTableScalingEnabled} // this.options?.isTableScalingEnabled sams as TableOptions.isTableScalingEnabled same as pluginState.isTableScalingEnabled
295
+ isTableScalingEnabled={props.options?.isTableScalingEnabled} // this.options?.isTableScalingEnabled same as TableOptions.isTableScalingEnabled same as pluginState.isTableScalingEnabled
296
+ isTableAlignmentEnabled={props.options?.isTableAlignmentEnabled}
296
297
  tableActive={tableActive}
297
298
  ordering={pluginState!.ordering as TableColumnOrdering}
298
299
  isResizing={isResizing}
@@ -391,6 +392,7 @@ export const createTableView = (
391
392
  getEditorFeatureFlags: GetEditorFeatureFlags,
392
393
  dispatchAnalyticsEvent: DispatchAnalyticsEvent,
393
394
  pluginInjectionApi?: PluginInjectionAPI,
395
+ isTableAlignmentEnabled?: boolean,
394
396
  ): NodeView => {
395
397
  const {
396
398
  pluginConfig,
@@ -417,6 +419,7 @@ export const createTableView = (
417
419
  isTableResizingEnabled,
418
420
  isDragAndDropEnabled,
419
421
  isTableScalingEnabled, // same as options.isTableScalingEnabled
422
+ isTableAlignmentEnabled
420
423
  },
421
424
  getEditorContainerWidth,
422
425
  getEditorFeatureFlags,
@@ -17,6 +17,7 @@ export type TableOptions = {
17
17
  isTableResizingEnabled?: boolean;
18
18
  isDragAndDropEnabled?: boolean;
19
19
  isTableScalingEnabled?: boolean;
20
+ isTableAlignmentEnabled?: boolean;
20
21
  };
21
22
 
22
23
  export interface Props {
package/src/plugin.tsx CHANGED
@@ -1,12 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- import {
4
- table,
5
- tableCell,
6
- tableHeader,
7
- tableRow,
8
- tableStage0,
9
- } from '@atlaskit/adf-schema';
3
+ import { table, tableCell, tableHeader, tableRow } from '@atlaskit/adf-schema';
10
4
  import type { AnalyticsEventPayload } from '@atlaskit/editor-common/analytics';
11
5
  import {
12
6
  ACTION,
@@ -218,7 +212,13 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
218
212
 
219
213
  options: {
220
214
  selectNodeInserted: false,
221
- analyticsPayload,
215
+ analyticsPayload: {
216
+ ...analyticsPayload,
217
+ attributes: {
218
+ ...analyticsPayload.attributes,
219
+ localId: node.attrs.localId,
220
+ },
221
+ },
222
222
  },
223
223
  }) ?? false
224
224
  );
@@ -234,14 +234,8 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
234
234
  },
235
235
 
236
236
  nodes() {
237
- const tableNode =
238
- options?.isTableScalingEnabled &&
239
- getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')
240
- ? tableStage0
241
- : table;
242
-
243
237
  return [
244
- { name: 'table', node: tableNode },
238
+ { name: 'table', node: table },
245
239
  { name: 'tableHeader', node: tableHeader },
246
240
  { name: 'tableRow', node: tableRow },
247
241
  { name: 'tableCell', node: tableCell },
@@ -650,17 +644,21 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
650
644
  // see comment on tablesPlugin.getSharedState on usage
651
645
  const tableState = api?.table?.sharedState.currentState();
652
646
 
653
- const tr = insert(
654
- createTableWithWidth(
655
- options?.isTableScalingEnabled,
656
- tableState?.isFullWidthModeEnabled,
657
- )(state.schema),
658
- );
647
+ const tableNode = createTableWithWidth(
648
+ options?.isTableScalingEnabled,
649
+ tableState?.isFullWidthModeEnabled,
650
+ )(state.schema);
651
+
652
+ const tr = insert(tableNode);
653
+
659
654
  editorAnalyticsAPI?.attachAnalyticsEvent({
660
655
  action: ACTION.INSERTED,
661
656
  actionSubject: ACTION_SUBJECT.DOCUMENT,
662
657
  actionSubjectId: ACTION_SUBJECT_ID.TABLE,
663
- attributes: { inputMethod: INPUT_METHOD.QUICK_INSERT },
658
+ attributes: {
659
+ inputMethod: INPUT_METHOD.QUICK_INSERT,
660
+ localId: tableNode.attrs.localId,
661
+ },
664
662
  eventType: EVENT_TYPE.TRACK,
665
663
  })(tr);
666
664
  return tr;
@@ -1,13 +1,7 @@
1
1
  import type { IntlShape } from 'react-intl-next/src/types';
2
2
 
3
3
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
4
- import {
5
- ACTION,
6
- ACTION_SUBJECT,
7
- ACTION_SUBJECT_ID,
8
- EVENT_TYPE,
9
- INPUT_METHOD,
10
- } from '@atlaskit/editor-common/analytics';
4
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
11
5
  import {
12
6
  addColumnAfter,
13
7
  addColumnBefore,
@@ -37,7 +31,7 @@ import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
37
31
  import { keymap } from '@atlaskit/editor-prosemirror/keymap';
38
32
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
39
33
 
40
- import { createTable, goToNextCell, moveCursorBackward } from '../commands';
34
+ import { goToNextCell, moveCursorBackward } from '../commands';
41
35
  import {
42
36
  addRowAroundSelection,
43
37
  changeColumnWidthByStepWithAnalytics,
@@ -53,25 +47,10 @@ import {
53
47
  import {
54
48
  addColumnAfter as addColumnAfterCommand,
55
49
  addColumnBefore as addColumnBeforeCommand,
50
+ createTable,
56
51
  } from '../commands/insert';
57
52
  import { moveSourceWithAnalyticsViaShortcut } from '../pm-plugins/drag-and-drop/commands-with-analytics';
58
53
  import type { PluginInjectionAPIWithA11y } from '../types';
59
- import { withEditorAnalyticsAPI } from '../utils/analytics';
60
-
61
- const createTableWithAnalytics = (
62
- isTableScalingEnabled: boolean,
63
- isFullWidthModeEnabled: boolean,
64
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
65
- ) =>
66
- withEditorAnalyticsAPI({
67
- action: ACTION.INSERTED,
68
- actionSubject: ACTION_SUBJECT.DOCUMENT,
69
- actionSubjectId: ACTION_SUBJECT_ID.TABLE,
70
- attributes: { inputMethod: INPUT_METHOD.SHORTCUT },
71
- eventType: EVENT_TYPE.TRACK,
72
- })(editorAnalyticsAPI)(
73
- createTable(isTableScalingEnabled, isFullWidthModeEnabled),
74
- );
75
54
 
76
55
  export function keymapPlugin(
77
56
  getEditorContainerWidth: GetEditorContainerWidth,
@@ -99,7 +78,7 @@ export function keymapPlugin(
99
78
  );
100
79
  bindKeymapWithCommand(
101
80
  toggleTable.common!,
102
- createTableWithAnalytics(
81
+ createTable(
103
82
  isTableScalingEnabled,
104
83
  !!isFullWidthEnabled,
105
84
  editorAnalyticsAPI,
@@ -411,6 +411,7 @@ export const createPlugin = (
411
411
  getEditorFeatureFlags,
412
412
  dispatchAnalyticsEvent,
413
413
  pluginInjectionApi,
414
+ isTableAlignmentEnabled,
414
415
  ),
415
416
  tableRow: (node, view, getPos) =>
416
417
  new TableRow(node, view, getPos, eventDispatcher),
package/src/toolbar.tsx CHANGED
@@ -1,7 +1,6 @@
1
1
  /** @jsx jsx */
2
2
  import { jsx } from '@emotion/react';
3
3
 
4
- import type { TableLayout } from '@atlaskit/adf-schema';
5
4
  import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
6
5
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
7
6
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
@@ -76,6 +75,7 @@ import {
76
75
  insertRowWithAnalytics,
77
76
  mergeCellsWithAnalytics,
78
77
  setColorWithAnalytics,
78
+ setTableAlignmentWithAnalytics,
79
79
  sortColumnWithAnalytics,
80
80
  splitCellWithAnalytics,
81
81
  toggleHeaderColumnWithAnalytics,
@@ -91,6 +91,7 @@ import { getNewResizeStateFromSelectedColumns } from './pm-plugins/table-resizin
91
91
  import { pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
92
92
  import { canMergeCells } from './transforms';
93
93
  import type {
94
+ AlignmentOptions,
94
95
  PluginConfig,
95
96
  ToolbarMenuConfig,
96
97
  ToolbarMenuContext,
@@ -105,6 +106,7 @@ import {
105
106
  getSelectedRowIndexes,
106
107
  isTableNested,
107
108
  } from './utils';
109
+ import { normaliseAlignment } from './utils/alignment';
108
110
 
109
111
  export const getToolbarMenuConfig = (
110
112
  config: ToolbarMenuConfig,
@@ -485,7 +487,7 @@ export const getToolbarConfig =
485
487
 
486
488
  alignmentMenu =
487
489
  options?.isTableAlignmentEnabled && !isNested
488
- ? getAlignmentOptionsConfig(state, intl)
490
+ ? getAlignmentOptionsConfig(state, intl, editorAnalyticsAPI)
489
491
  : [];
490
492
 
491
493
  let cellItems: Array<FloatingToolbarItem<Command>>;
@@ -890,13 +892,14 @@ const highlightColumnsHandler = (
890
892
 
891
893
  type AlignmentIcon = {
892
894
  id?: string;
893
- value: TableLayout;
895
+ value: AlignmentOptions;
894
896
  icon: React.ComponentClass<any>;
895
897
  };
896
898
 
897
899
  export const getAlignmentOptionsConfig = (
898
900
  editorState: EditorState,
899
901
  { formatMessage }: ToolbarMenuContext,
902
+ editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
900
903
  ): Array<FloatingToolbarDropdown<Command>> => {
901
904
  const tableObject = findTable(editorState.selection);
902
905
 
@@ -918,7 +921,7 @@ export const getAlignmentOptionsConfig = (
918
921
  ];
919
922
 
920
923
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
921
- const layoutToMessages: Record<string, any> = {
924
+ const layoutToMessages: Record<AlignmentOptions, any> = {
922
925
  center: messages.alignTableCenter,
923
926
  'align-start': messages.alignTableLeft,
924
927
  };
@@ -926,13 +929,19 @@ export const getAlignmentOptionsConfig = (
926
929
  const alignmentButtons = alignmentIcons.map<FloatingToolbarItem<Command>>(
927
930
  (alignmentIcon) => {
928
931
  const { id, value, icon } = alignmentIcon;
932
+ const currentLayout = tableObject.node.attrs.layout;
933
+
929
934
  return {
930
935
  id: id,
931
936
  type: 'button',
932
937
  icon: icon,
933
938
  title: formatMessage(layoutToMessages[value]),
934
- selected: tableObject.node.attrs.layout === value,
935
- onClick: alignTable(value),
939
+ selected: normaliseAlignment(currentLayout) === value,
940
+ onClick: setTableAlignmentWithAnalytics(editorAnalyticsAPI)(
941
+ value,
942
+ currentLayout,
943
+ INPUT_METHOD.FLOATING_TB
944
+ ),
936
945
  };
937
946
  },
938
947
  );
@@ -969,34 +978,6 @@ export const getAlignmentOptionsConfig = (
969
978
  return alignmentToolbarItem;
970
979
  };
971
980
 
972
- const alignTable = (nextLayoutValue: TableLayout): Command => {
973
- return (state, dispatch) => {
974
- const tableObject = findTable(state.selection);
975
-
976
- if (!tableObject || !dispatch) {
977
- return false;
978
- }
979
-
980
- const nextTableAttrs = {
981
- ...tableObject.node.attrs,
982
- layout: nextLayoutValue,
983
- };
984
-
985
- const tr = state.tr.setNodeMarkup(
986
- tableObject.pos,
987
- undefined,
988
- nextTableAttrs,
989
- );
990
-
991
- tr.setMeta('scrollIntoView', false);
992
-
993
- // TODO - insert analytics here for layout selection
994
-
995
- dispatch(tr);
996
- return true;
997
- };
998
- };
999
-
1000
981
  export const getSelectedAlignmentIcon = (
1001
982
  alignmentIcons: AlignmentIcon[],
1002
983
  selectedNode: PMNode,
@@ -1004,8 +985,6 @@ export const getSelectedAlignmentIcon = (
1004
985
  const selectedAlignment = selectedNode.attrs.layout;
1005
986
 
1006
987
  return alignmentIcons.find(
1007
- (icon) =>
1008
- icon.value ===
1009
- (selectedNode.attrs.layout === 'default' ? 'center' : selectedAlignment),
988
+ (icon) => icon.value === normaliseAlignment(selectedAlignment),
1010
989
  );
1011
990
  };