@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
@@ -636,7 +636,9 @@ class TableComponent extends React.Component {
636
636
  pluginInjectionApi,
637
637
  isDragAndDropEnabled,
638
638
  getEditorFeatureFlags,
639
- isTableScalingEnabled // here we can use options.isTableScalingEnabled
639
+ isTableScalingEnabled,
640
+ // here we can use options.isTableScalingEnabled
641
+ isTableAlignmentEnabled
640
642
  } = this.props;
641
643
  let {
642
644
  isInDanger,
@@ -752,7 +754,8 @@ class TableComponent extends React.Component {
752
754
  isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled,
753
755
  isResizing: isResizing,
754
756
  isTableScalingEnabled: isTableScalingEnabled,
755
- isWholeTableInDanger: isWholeTableInDanger
757
+ isWholeTableInDanger: isWholeTableInDanger,
758
+ isTableAlignmentEnabled: isTableAlignmentEnabled
756
759
  }, /*#__PURE__*/React.createElement("div", {
757
760
  className: ClassName.TABLE_STICKY_SENTINEL_TOP,
758
761
  "data-testid": "sticky-sentinel-top"
@@ -65,6 +65,7 @@ export const TableComponentWithSharedState = ({
65
65
  isHeaderColumnEnabled: isHeaderColumnEnabled,
66
66
  isDragAndDropEnabled: options === null || options === void 0 ? void 0 : options.isDragAndDropEnabled,
67
67
  isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled,
68
+ isTableAlignmentEnabled: options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled,
68
69
  tableActive: tableActive,
69
70
  ordering: ordering,
70
71
  isResizing: isResizing,
@@ -1,4 +1,4 @@
1
- import React, { forwardRef, useCallback, useRef, useState } from 'react';
1
+ import React, { forwardRef, useCallback, useMemo, useRef, useState } from 'react';
2
2
  import classNames from 'classnames';
3
3
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
4
4
  import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
@@ -21,6 +21,45 @@ export const InnerContainer = /*#__PURE__*/forwardRef(({
21
21
  "data-testid": "table-container"
22
22
  }, children);
23
23
  });
24
+ const centerAlignStyle = {
25
+ display: 'flex',
26
+ justifyContent: 'center'
27
+ };
28
+ const leftAlignStyle = {
29
+ display: 'flex',
30
+ justifyContent: 'flex-start'
31
+ };
32
+ const AlignmentTableContainer = ({
33
+ node,
34
+ children
35
+ }) => {
36
+ const alignment = node.attrs.layout;
37
+ const style = useMemo(() => {
38
+ return alignment === 'align-start' ? leftAlignStyle : centerAlignStyle;
39
+ }, [alignment]);
40
+ return /*#__PURE__*/React.createElement("div", {
41
+ "data-testid": "table-alignment-container",
42
+ style: style
43
+ }, children);
44
+ };
45
+ const AlignmentTableContainerWrapper = ({
46
+ isTableAlignmentEnabled,
47
+ node,
48
+ children
49
+ }) => {
50
+ if (!isTableAlignmentEnabled) {
51
+ return /*#__PURE__*/React.createElement("div", {
52
+ "data-testid": "table-alignment-container",
53
+ style: {
54
+ display: 'flex',
55
+ justifyContent: 'center'
56
+ }
57
+ }, children);
58
+ }
59
+ return /*#__PURE__*/React.createElement(AlignmentTableContainer, {
60
+ node: node
61
+ }, children);
62
+ };
24
63
  export const ResizableTableContainer = /*#__PURE__*/React.memo(({
25
64
  children,
26
65
  className,
@@ -31,9 +70,10 @@ export const ResizableTableContainer = /*#__PURE__*/React.memo(({
31
70
  tableRef,
32
71
  isResizing,
33
72
  pluginInjectionApi,
34
- isTableScalingEnabled,
35
73
  tableWrapperHeight,
36
- isWholeTableInDanger
74
+ isWholeTableInDanger,
75
+ isTableScalingEnabled,
76
+ isTableAlignmentEnabled
37
77
  }) => {
38
78
  const containerRef = useRef(null);
39
79
  const tableWidthRef = useRef(akEditorDefaultLayoutWidth);
@@ -121,11 +161,9 @@ export const ResizableTableContainer = /*#__PURE__*/React.memo(({
121
161
  onResizeStop
122
162
  };
123
163
  const isLivePageViewMode = (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view';
124
- return /*#__PURE__*/React.createElement("div", {
125
- style: {
126
- display: 'flex',
127
- justifyContent: 'center'
128
- }
164
+ return /*#__PURE__*/React.createElement(AlignmentTableContainerWrapper, {
165
+ isTableAlignmentEnabled: isTableAlignmentEnabled,
166
+ node: node
129
167
  }, /*#__PURE__*/React.createElement("div", {
130
168
  style: {
131
169
  width: tableWidthRef.current,
@@ -152,7 +190,6 @@ export const TableContainer = ({
152
190
  containerWidth: {
153
191
  width: editorWidth
154
192
  },
155
- isTableResizingEnabled,
156
193
  editorView,
157
194
  getPos,
158
195
  tableRef,
@@ -160,8 +197,10 @@ export const TableContainer = ({
160
197
  tableWrapperHeight,
161
198
  isResizing,
162
199
  pluginInjectionApi,
200
+ isWholeTableInDanger,
201
+ isTableResizingEnabled,
163
202
  isTableScalingEnabled,
164
- isWholeTableInDanger
203
+ isTableAlignmentEnabled
165
204
  }) => {
166
205
  if (isTableResizingEnabled && !isNested) {
167
206
  return /*#__PURE__*/React.createElement(ResizableTableContainer, {
@@ -175,7 +214,8 @@ export const TableContainer = ({
175
214
  isResizing: isResizing,
176
215
  pluginInjectionApi: pluginInjectionApi,
177
216
  isTableScalingEnabled: isTableScalingEnabled,
178
- isWholeTableInDanger: isWholeTableInDanger
217
+ isWholeTableInDanger: isWholeTableInDanger,
218
+ isTableAlignmentEnabled: isTableAlignmentEnabled
179
219
  }, children);
180
220
  }
181
221
  return /*#__PURE__*/React.createElement(InnerContainer, {
@@ -144,7 +144,7 @@ export default class TableView extends ReactNodeView {
144
144
  },
145
145
  editorView: props.view,
146
146
  render: pluginStates => {
147
- var _props$options;
147
+ var _props$options, _props$options2;
148
148
  const {
149
149
  tableResizingPluginState,
150
150
  tableWidthPluginState,
@@ -178,8 +178,9 @@ export default class TableView extends ReactNodeView {
178
178
  isHeaderRowEnabled: pluginState.isHeaderRowEnabled,
179
179
  isHeaderColumnEnabled: pluginState.isHeaderColumnEnabled,
180
180
  isDragAndDropEnabled: pluginState.isDragAndDropEnabled,
181
- isTableScalingEnabled: (_props$options = props.options) === null || _props$options === void 0 ? void 0 : _props$options.isTableScalingEnabled // this.options?.isTableScalingEnabled sams as TableOptions.isTableScalingEnabled same as pluginState.isTableScalingEnabled
181
+ isTableScalingEnabled: (_props$options = props.options) === null || _props$options === void 0 ? void 0 : _props$options.isTableScalingEnabled // this.options?.isTableScalingEnabled same as TableOptions.isTableScalingEnabled same as pluginState.isTableScalingEnabled
182
182
  ,
183
+ isTableAlignmentEnabled: (_props$options2 = props.options) === null || _props$options2 === void 0 ? void 0 : _props$options2.isTableAlignmentEnabled,
183
184
  tableActive: tableActive,
184
185
  ordering: pluginState.ordering,
185
186
  isResizing: isResizing,
@@ -249,7 +250,7 @@ export default class TableView extends ReactNodeView {
249
250
  super.destroy();
250
251
  }
251
252
  }
252
- export const createTableView = (node, view, getPos, portalProviderAPI, eventDispatcher, getEditorContainerWidth, getEditorFeatureFlags, dispatchAnalyticsEvent, pluginInjectionApi) => {
253
+ export const createTableView = (node, view, getPos, portalProviderAPI, eventDispatcher, getEditorContainerWidth, getEditorFeatureFlags, dispatchAnalyticsEvent, pluginInjectionApi, isTableAlignmentEnabled) => {
253
254
  const {
254
255
  pluginConfig,
255
256
  isFullWidthModeEnabled,
@@ -276,7 +277,9 @@ export const createTableView = (node, view, getPos, portalProviderAPI, eventDisp
276
277
  wasFullWidthModeEnabled,
277
278
  isTableResizingEnabled,
278
279
  isDragAndDropEnabled,
279
- isTableScalingEnabled // same as options.isTableScalingEnabled
280
+ isTableScalingEnabled,
281
+ // same as options.isTableScalingEnabled
282
+ isTableAlignmentEnabled
280
283
  },
281
284
  getEditorContainerWidth,
282
285
  getEditorFeatureFlags,
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { table, tableCell, tableHeader, tableRow, tableStage0 } from '@atlaskit/adf-schema';
2
+ import { table, tableCell, tableHeader, tableRow } from '@atlaskit/adf-schema';
3
3
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
4
4
  import { ErrorBoundary } from '@atlaskit/editor-common/error-boundary';
5
5
  import { IconTable } from '@atlaskit/editor-common/icons';
@@ -101,7 +101,13 @@ const tablesPlugin = ({
101
101
  node,
102
102
  options: {
103
103
  selectNodeInserted: false,
104
- analyticsPayload
104
+ analyticsPayload: {
105
+ ...analyticsPayload,
106
+ attributes: {
107
+ ...analyticsPayload.attributes,
108
+ localId: node.attrs.localId
109
+ }
110
+ }
105
111
  }
106
112
  })) !== null && _api$contentInsertion !== void 0 ? _api$contentInsertion : false;
107
113
  }
@@ -110,10 +116,9 @@ const tablesPlugin = ({
110
116
  insertTableWithSize: insertTableWithSize(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
111
117
  },
112
118
  nodes() {
113
- const tableNode = options !== null && options !== void 0 && options.isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button') ? tableStage0 : table;
114
119
  return [{
115
120
  name: 'table',
116
- node: tableNode
121
+ node: table
117
122
  }, {
118
123
  name: 'tableHeader',
119
124
  node: tableHeader
@@ -430,13 +435,15 @@ const tablesPlugin = ({
430
435
  var _api$table;
431
436
  // see comment on tablesPlugin.getSharedState on usage
432
437
  const tableState = api === null || api === void 0 ? void 0 : (_api$table = api.table) === null || _api$table === void 0 ? void 0 : _api$table.sharedState.currentState();
433
- const tr = insert(createTableWithWidth(options === null || options === void 0 ? void 0 : options.isTableScalingEnabled, tableState === null || tableState === void 0 ? void 0 : tableState.isFullWidthModeEnabled)(state.schema));
438
+ const tableNode = createTableWithWidth(options === null || options === void 0 ? void 0 : options.isTableScalingEnabled, tableState === null || tableState === void 0 ? void 0 : tableState.isFullWidthModeEnabled)(state.schema);
439
+ const tr = insert(tableNode);
434
440
  editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
435
441
  action: ACTION.INSERTED,
436
442
  actionSubject: ACTION_SUBJECT.DOCUMENT,
437
443
  actionSubjectId: ACTION_SUBJECT_ID.TABLE,
438
444
  attributes: {
439
- inputMethod: INPUT_METHOD.QUICK_INSERT
445
+ inputMethod: INPUT_METHOD.QUICK_INSERT,
446
+ localId: tableNode.attrs.localId
440
447
  },
441
448
  eventType: EVENT_TYPE.TRACK
442
449
  })(tr);
@@ -1,30 +1,20 @@
1
- import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
1
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
2
  import { addColumnAfter, addColumnBefore, addRowAfter, addRowBefore, backspace, bindKeymapWithCommand, decreaseMediaSize, deleteColumn, deleteRow, escape, increaseMediaSize, moveColumnLeft, moveColumnRight, moveLeft, moveRight, moveRowDown, moveRowUp, nextCell, previousCell, startColumnResizing, toggleTable } from '@atlaskit/editor-common/keymaps';
3
3
  import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
4
4
  import { keymap } from '@atlaskit/editor-prosemirror/keymap';
5
5
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
6
- import { createTable, goToNextCell, moveCursorBackward } from '../commands';
6
+ import { goToNextCell, moveCursorBackward } from '../commands';
7
7
  import { addRowAroundSelection, changeColumnWidthByStepWithAnalytics, deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut, deleteTableIfSelectedWithAnalytics, emptyMultipleCellsWithAnalytics } from '../commands-with-analytics';
8
8
  import { activateNextResizeArea, initiateKeyboardColumnResizing, stopKeyboardColumnResizing } from '../commands/column-resize';
9
- import { addColumnAfter as addColumnAfterCommand, addColumnBefore as addColumnBeforeCommand } from '../commands/insert';
9
+ import { addColumnAfter as addColumnAfterCommand, addColumnBefore as addColumnBeforeCommand, createTable } from '../commands/insert';
10
10
  import { moveSourceWithAnalyticsViaShortcut } from '../pm-plugins/drag-and-drop/commands-with-analytics';
11
- import { withEditorAnalyticsAPI } from '../utils/analytics';
12
- const createTableWithAnalytics = (isTableScalingEnabled, isFullWidthModeEnabled, editorAnalyticsAPI) => withEditorAnalyticsAPI({
13
- action: ACTION.INSERTED,
14
- actionSubject: ACTION_SUBJECT.DOCUMENT,
15
- actionSubjectId: ACTION_SUBJECT_ID.TABLE,
16
- attributes: {
17
- inputMethod: INPUT_METHOD.SHORTCUT
18
- },
19
- eventType: EVENT_TYPE.TRACK
20
- })(editorAnalyticsAPI)(createTable(isTableScalingEnabled, isFullWidthModeEnabled));
21
11
  export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled, isTableScalingEnabled = false, isFullWidthEnabled, pluginInjectionApi, getIntl) {
22
12
  var _pluginInjectionApi$a;
23
13
  const list = {};
24
14
  const ariaNotifyPlugin = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a = pluginInjectionApi.accessibilityUtils) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions.ariaNotify;
25
15
  bindKeymapWithCommand(nextCell.common, goToNextCell(editorAnalyticsAPI, ariaNotifyPlugin, getIntl)(1), list);
26
16
  bindKeymapWithCommand(previousCell.common, goToNextCell(editorAnalyticsAPI, ariaNotifyPlugin, getIntl)(-1), list);
27
- bindKeymapWithCommand(toggleTable.common, createTableWithAnalytics(isTableScalingEnabled, !!isFullWidthEnabled, editorAnalyticsAPI), list);
17
+ bindKeymapWithCommand(toggleTable.common, createTable(isTableScalingEnabled, !!isFullWidthEnabled, editorAnalyticsAPI), list);
28
18
  bindKeymapWithCommand(backspace.common, chainCommands(deleteTableIfSelectedWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD), emptyMultipleCellsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD)), list);
29
19
  bindKeymapWithCommand(backspace.common, moveCursorBackward, list);
30
20
 
@@ -257,7 +257,7 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
257
257
  return false;
258
258
  },
259
259
  nodeViews: {
260
- table: (node, view, getPos) => createTableView(node, view, getPos, portalProviderAPI, eventDispatcher, getEditorContainerWidth, getEditorFeatureFlags, dispatchAnalyticsEvent, pluginInjectionApi),
260
+ table: (node, view, getPos) => createTableView(node, view, getPos, portalProviderAPI, eventDispatcher, getEditorContainerWidth, getEditorFeatureFlags, dispatchAnalyticsEvent, pluginInjectionApi, isTableAlignmentEnabled),
261
261
  tableRow: (node, view, getPos) => new TableRow(node, view, getPos, eventDispatcher),
262
262
  tableCell: (node, view, getPos) => new TableCell(node, view, getPos, eventDispatcher),
263
263
  tableHeader: (node, view, getPos) => new TableCell(node, view, getPos, eventDispatcher)
@@ -19,7 +19,7 @@ import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
19
19
  import TableOptionsIcon from '@atlaskit/icon/glyph/preferences';
20
20
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
21
21
  import { clearHoverSelection, hoverColumns, hoverMergedCells, hoverRows, hoverTable, removeDescendantNodes } from './commands';
22
- import { deleteColumnsWithAnalytics, deleteRowsWithAnalytics, deleteTableWithAnalytics, distributeColumnsWidthsWithAnalytics, emptyMultipleCellsWithAnalytics, insertColumnWithAnalytics, insertRowWithAnalytics, mergeCellsWithAnalytics, setColorWithAnalytics, sortColumnWithAnalytics, splitCellWithAnalytics, toggleHeaderColumnWithAnalytics, toggleHeaderRowWithAnalytics, toggleNumberColumnWithAnalytics, toggleTableLockWithAnalytics, wrapTableInExpandWithAnalytics } from './commands-with-analytics';
22
+ import { deleteColumnsWithAnalytics, deleteRowsWithAnalytics, deleteTableWithAnalytics, distributeColumnsWidthsWithAnalytics, emptyMultipleCellsWithAnalytics, insertColumnWithAnalytics, insertRowWithAnalytics, mergeCellsWithAnalytics, setColorWithAnalytics, setTableAlignmentWithAnalytics, sortColumnWithAnalytics, splitCellWithAnalytics, toggleHeaderColumnWithAnalytics, toggleHeaderRowWithAnalytics, toggleNumberColumnWithAnalytics, toggleTableLockWithAnalytics, wrapTableInExpandWithAnalytics } from './commands-with-analytics';
23
23
  import { getPluginState } from './pm-plugins/plugin-factory';
24
24
  import { pluginKey as tableResizingPluginKey } from './pm-plugins/table-resizing';
25
25
  import { getNewResizeStateFromSelectedColumns } from './pm-plugins/table-resizing/utils/resize-state';
@@ -29,6 +29,7 @@ import { TableCssClassName } from './types';
29
29
  import { FloatingAlignmentButtons } from './ui/FloatingAlignmentButtons/FloatingAlignmentButtons';
30
30
  import { DisplayModeIcon } from './ui/icons';
31
31
  import { getMergedCellsPositions, getSelectedColumnIndexes, getSelectedRowIndexes, isTableNested } from './utils';
32
+ import { normaliseAlignment } from './utils/alignment';
32
33
  export const getToolbarMenuConfig = (config, state, {
33
34
  formatMessage
34
35
  }, editorAnalyticsAPI) => {
@@ -316,7 +317,7 @@ export const getToolbarConfig = (getEditorContainerWidth, editorAnalyticsAPI, ge
316
317
  const menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
317
318
  let alignmentMenu;
318
319
  const isNested = pluginState.tablePos && isTableNested(state, pluginState.tablePos);
319
- alignmentMenu = options !== null && options !== void 0 && options.isTableAlignmentEnabled && !isNested ? getAlignmentOptionsConfig(state, intl) : [];
320
+ alignmentMenu = options !== null && options !== void 0 && options.isTableAlignmentEnabled && !isNested ? getAlignmentOptionsConfig(state, intl, editorAnalyticsAPI) : [];
320
321
  let cellItems;
321
322
  cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled);
322
323
  let columnSettingsItems;
@@ -563,7 +564,7 @@ const highlightColumnsHandler = (state, dispatch) => {
563
564
  };
564
565
  export const getAlignmentOptionsConfig = (editorState, {
565
566
  formatMessage
566
- }) => {
567
+ }, editorAnalyticsAPI) => {
567
568
  const tableObject = findTable(editorState.selection);
568
569
  if (!tableObject) {
569
570
  return [];
@@ -589,13 +590,14 @@ export const getAlignmentOptionsConfig = (editorState, {
589
590
  value,
590
591
  icon
591
592
  } = alignmentIcon;
593
+ const currentLayout = tableObject.node.attrs.layout;
592
594
  return {
593
595
  id: id,
594
596
  type: 'button',
595
597
  icon: icon,
596
598
  title: formatMessage(layoutToMessages[value]),
597
- selected: tableObject.node.attrs.layout === value,
598
- onClick: alignTable(value)
599
+ selected: normaliseAlignment(currentLayout) === value,
600
+ onClick: setTableAlignmentWithAnalytics(editorAnalyticsAPI)(value, currentLayout, INPUT_METHOD.FLOATING_TB)
599
601
  };
600
602
  });
601
603
  const alignmentItemOptions = {
@@ -618,26 +620,7 @@ export const getAlignmentOptionsConfig = (editorState, {
618
620
  }];
619
621
  return alignmentToolbarItem;
620
622
  };
621
- const alignTable = nextLayoutValue => {
622
- return (state, dispatch) => {
623
- const tableObject = findTable(state.selection);
624
- if (!tableObject || !dispatch) {
625
- return false;
626
- }
627
- const nextTableAttrs = {
628
- ...tableObject.node.attrs,
629
- layout: nextLayoutValue
630
- };
631
- const tr = state.tr.setNodeMarkup(tableObject.pos, undefined, nextTableAttrs);
632
- tr.setMeta('scrollIntoView', false);
633
-
634
- // TODO - insert analytics here for layout selection
635
-
636
- dispatch(tr);
637
- return true;
638
- };
639
- };
640
623
  export const getSelectedAlignmentIcon = (alignmentIcons, selectedNode) => {
641
624
  const selectedAlignment = selectedNode.attrs.layout;
642
- return alignmentIcons.find(icon => icon.value === (selectedNode.attrs.layout === 'default' ? 'center' : selectedAlignment));
625
+ return alignmentIcons.find(icon => icon.value === normaliseAlignment(selectedAlignment));
643
626
  };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Normalise table layout attribute an alignment value ('center' or 'align-start'), returns
3
+ * center if layout equals a breakout value (e.g. 'default', 'wide', 'full-width')
4
+ */
5
+ export const normaliseAlignment = layout => layout === 'center' || layout === 'align-start' ? layout : 'center';
@@ -1,6 +1,6 @@
1
1
  // #region Imports
2
2
  import { AddColumnStep } from '@atlaskit/custom-steps';
3
- import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, TABLE_OVERFLOW_CHANGE_TRIGGER } from '@atlaskit/editor-common/analytics';
3
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD, TABLE_OVERFLOW_CHANGE_TRIGGER } from '@atlaskit/editor-common/analytics';
4
4
  import { Selection } from '@atlaskit/editor-prosemirror/state';
5
5
  import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
6
6
  import { TableMap } from '@atlaskit/editor-tables/table-map';
@@ -134,11 +134,23 @@ export var insertRow = function insertRow(row, moveCursorToTheNewRow, isCellBack
134
134
  return true;
135
135
  };
136
136
  };
137
- export var createTable = function createTable(isTableScalingEnabled, isFullWidthModeEnabled) {
137
+ export var createTable = function createTable(isTableScalingEnabled, isFullWidthModeEnabled, editorAnalyticsAPI) {
138
138
  return function (state, dispatch) {
139
139
  var table = createTableWithWidth(isTableScalingEnabled, isFullWidthModeEnabled)(state.schema);
140
140
  if (dispatch) {
141
- dispatch(safeInsert(table)(state.tr).scrollIntoView());
141
+ var tr = safeInsert(table)(state.tr).scrollIntoView();
142
+ if (editorAnalyticsAPI) {
143
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
144
+ action: ACTION.INSERTED,
145
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
146
+ actionSubjectId: ACTION_SUBJECT_ID.TABLE,
147
+ attributes: {
148
+ inputMethod: INPUT_METHOD.SHORTCUT
149
+ },
150
+ eventType: EVENT_TYPE.TRACK
151
+ })(tr);
152
+ }
153
+ dispatch(tr);
142
154
  }
143
155
  return true;
144
156
  };
@@ -579,4 +579,18 @@ export var updateWidthToWidest = function updateWidthToWidest(widthToWidest) {
579
579
  }
580
580
  };
581
581
  });
582
+ };
583
+ export var setTableAlignment = function setTableAlignment(newAlignment) {
584
+ return function (_ref2) {
585
+ var tr = _ref2.tr;
586
+ var tableObject = findTable(tr.selection);
587
+ if (!tableObject) {
588
+ return null;
589
+ }
590
+ var nextTableAttrs = _objectSpread(_objectSpread({}, tableObject.node.attrs), {}, {
591
+ layout: newAlignment
592
+ });
593
+ tr.setNodeMarkup(tableObject.pos, undefined, nextTableAttrs).setMeta('scrollIntoView', false);
594
+ return tr;
595
+ };
582
596
  };
@@ -12,7 +12,7 @@ import { changeColumnWidthByStep } from './commands/column-resize';
12
12
  import { deleteColumnsCommand } from './commands/delete';
13
13
  import { setTableDisplayMode } from './commands/display-mode';
14
14
  import { insertColumn, insertRow } from './commands/insert';
15
- import { deleteTable, deleteTableIfSelected, getTableSelectionType, setMultipleCellAttrs } from './commands/misc';
15
+ import { deleteTable, deleteTableIfSelected, getTableSelectionType, setMultipleCellAttrs, setTableAlignment } from './commands/misc';
16
16
  import { sortByColumn } from './commands/sort';
17
17
  import { splitCell } from './commands/split-cell';
18
18
  import { getNextLayout, toggleHeaderColumn, toggleHeaderRow, toggleNumberColumn, toggleTableLayout } from './commands/toggle';
@@ -530,4 +530,27 @@ export var toggleTableLockWithAnalytics = function toggleTableLockWithAnalytics(
530
530
  })(editorAnalyticsAPI)(editorCommandToPMCommand(setTableDisplayMode));
531
531
  };
532
532
  };
533
- // #endregion
533
+ export var setTableAlignmentWithAnalytics = function setTableAlignmentWithAnalytics(editorAnalyticsAPI) {
534
+ return function (newAlignment, previousAlignment, inputMethod) {
535
+ return withEditorAnalyticsAPI(function (state) {
536
+ var _getSelectedTableInfo14 = getSelectedTableInfo(state.selection),
537
+ table = _getSelectedTableInfo14.table,
538
+ totalRowCount = _getSelectedTableInfo14.totalRowCount,
539
+ totalColumnCount = _getSelectedTableInfo14.totalColumnCount;
540
+ return {
541
+ action: TABLE_ACTION.CHANGED_ALIGNMENT,
542
+ actionSubject: ACTION_SUBJECT.TABLE,
543
+ actionSubjectId: null,
544
+ eventType: EVENT_TYPE.TRACK,
545
+ attributes: {
546
+ tableWidth: table === null || table === void 0 ? void 0 : table.node.attrs.width,
547
+ newAlignment: newAlignment,
548
+ previousAlignment: previousAlignment === 'center' || previousAlignment === 'align-start' ? previousAlignment : null,
549
+ totalRowCount: totalRowCount,
550
+ totalColumnCount: totalColumnCount,
551
+ inputMethod: inputMethod
552
+ }
553
+ };
554
+ })(editorAnalyticsAPI)(editorCommandToPMCommand(setTableAlignment(newAlignment)));
555
+ };
556
+ };
@@ -645,7 +645,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
645
645
  pluginInjectionApi = _this$props11.pluginInjectionApi,
646
646
  isDragAndDropEnabled = _this$props11.isDragAndDropEnabled,
647
647
  getEditorFeatureFlags = _this$props11.getEditorFeatureFlags,
648
- isTableScalingEnabled = _this$props11.isTableScalingEnabled;
648
+ isTableScalingEnabled = _this$props11.isTableScalingEnabled,
649
+ isTableAlignmentEnabled = _this$props11.isTableAlignmentEnabled;
649
650
  var _this$props12 = this.props,
650
651
  isInDanger = _this$props12.isInDanger,
651
652
  hoveredRows = _this$props12.hoveredRows,
@@ -754,7 +755,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
754
755
  isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.isTableResizingEnabled,
755
756
  isResizing: isResizing,
756
757
  isTableScalingEnabled: isTableScalingEnabled,
757
- isWholeTableInDanger: isWholeTableInDanger
758
+ isWholeTableInDanger: isWholeTableInDanger,
759
+ isTableAlignmentEnabled: isTableAlignmentEnabled
758
760
  }, /*#__PURE__*/React.createElement("div", {
759
761
  className: ClassName.TABLE_STICKY_SENTINEL_TOP,
760
762
  "data-testid": "sticky-sentinel-top"
@@ -62,6 +62,7 @@ export var TableComponentWithSharedState = function TableComponentWithSharedStat
62
62
  isHeaderColumnEnabled: isHeaderColumnEnabled,
63
63
  isDragAndDropEnabled: options === null || options === void 0 ? void 0 : options.isDragAndDropEnabled,
64
64
  isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled,
65
+ isTableAlignmentEnabled: options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled,
65
66
  tableActive: tableActive,
66
67
  ordering: ordering,
67
68
  isResizing: isResizing,
@@ -1,5 +1,5 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import React, { forwardRef, useCallback, useRef, useState } from 'react';
2
+ import React, { forwardRef, useCallback, useMemo, useRef, useState } from 'react';
3
3
  import classNames from 'classnames';
4
4
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
5
5
  import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
@@ -21,19 +21,57 @@ export var InnerContainer = /*#__PURE__*/forwardRef(function (_ref, ref) {
21
21
  "data-testid": "table-container"
22
22
  }, children);
23
23
  });
24
- export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref2) {
25
- var children = _ref2.children,
26
- className = _ref2.className,
27
- node = _ref2.node,
28
- containerWidth = _ref2.containerWidth,
29
- editorView = _ref2.editorView,
30
- getPos = _ref2.getPos,
31
- tableRef = _ref2.tableRef,
32
- isResizing = _ref2.isResizing,
33
- pluginInjectionApi = _ref2.pluginInjectionApi,
34
- isTableScalingEnabled = _ref2.isTableScalingEnabled,
35
- tableWrapperHeight = _ref2.tableWrapperHeight,
36
- isWholeTableInDanger = _ref2.isWholeTableInDanger;
24
+ var centerAlignStyle = {
25
+ display: 'flex',
26
+ justifyContent: 'center'
27
+ };
28
+ var leftAlignStyle = {
29
+ display: 'flex',
30
+ justifyContent: 'flex-start'
31
+ };
32
+ var AlignmentTableContainer = function AlignmentTableContainer(_ref2) {
33
+ var node = _ref2.node,
34
+ children = _ref2.children;
35
+ var alignment = node.attrs.layout;
36
+ var style = useMemo(function () {
37
+ return alignment === 'align-start' ? leftAlignStyle : centerAlignStyle;
38
+ }, [alignment]);
39
+ return /*#__PURE__*/React.createElement("div", {
40
+ "data-testid": "table-alignment-container",
41
+ style: style
42
+ }, children);
43
+ };
44
+ var AlignmentTableContainerWrapper = function AlignmentTableContainerWrapper(_ref3) {
45
+ var isTableAlignmentEnabled = _ref3.isTableAlignmentEnabled,
46
+ node = _ref3.node,
47
+ children = _ref3.children;
48
+ if (!isTableAlignmentEnabled) {
49
+ return /*#__PURE__*/React.createElement("div", {
50
+ "data-testid": "table-alignment-container",
51
+ style: {
52
+ display: 'flex',
53
+ justifyContent: 'center'
54
+ }
55
+ }, children);
56
+ }
57
+ return /*#__PURE__*/React.createElement(AlignmentTableContainer, {
58
+ node: node
59
+ }, children);
60
+ };
61
+ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref4) {
62
+ var children = _ref4.children,
63
+ className = _ref4.className,
64
+ node = _ref4.node,
65
+ containerWidth = _ref4.containerWidth,
66
+ editorView = _ref4.editorView,
67
+ getPos = _ref4.getPos,
68
+ tableRef = _ref4.tableRef,
69
+ isResizing = _ref4.isResizing,
70
+ pluginInjectionApi = _ref4.pluginInjectionApi,
71
+ tableWrapperHeight = _ref4.tableWrapperHeight,
72
+ isWholeTableInDanger = _ref4.isWholeTableInDanger,
73
+ isTableScalingEnabled = _ref4.isTableScalingEnabled,
74
+ isTableAlignmentEnabled = _ref4.isTableAlignmentEnabled;
37
75
  var containerRef = useRef(null);
38
76
  var tableWidthRef = useRef(akEditorDefaultLayoutWidth);
39
77
  var _useState = useState(false),
@@ -122,11 +160,9 @@ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref2) {
122
160
  onResizeStop: onResizeStop
123
161
  };
124
162
  var isLivePageViewMode = (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view';
125
- return /*#__PURE__*/React.createElement("div", {
126
- style: {
127
- display: 'flex',
128
- justifyContent: 'center'
129
- }
163
+ return /*#__PURE__*/React.createElement(AlignmentTableContainerWrapper, {
164
+ isTableAlignmentEnabled: isTableAlignmentEnabled,
165
+ node: node
130
166
  }, /*#__PURE__*/React.createElement("div", {
131
167
  style: {
132
168
  width: tableWidthRef.current,
@@ -146,21 +182,22 @@ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref2) {
146
182
  node: node
147
183
  }, children))));
148
184
  });
149
- export var TableContainer = function TableContainer(_ref3) {
150
- var children = _ref3.children,
151
- node = _ref3.node,
152
- className = _ref3.className,
153
- editorWidth = _ref3.containerWidth.width,
154
- isTableResizingEnabled = _ref3.isTableResizingEnabled,
155
- editorView = _ref3.editorView,
156
- getPos = _ref3.getPos,
157
- tableRef = _ref3.tableRef,
158
- isNested = _ref3.isNested,
159
- tableWrapperHeight = _ref3.tableWrapperHeight,
160
- isResizing = _ref3.isResizing,
161
- pluginInjectionApi = _ref3.pluginInjectionApi,
162
- isTableScalingEnabled = _ref3.isTableScalingEnabled,
163
- isWholeTableInDanger = _ref3.isWholeTableInDanger;
185
+ export var TableContainer = function TableContainer(_ref5) {
186
+ var children = _ref5.children,
187
+ node = _ref5.node,
188
+ className = _ref5.className,
189
+ editorWidth = _ref5.containerWidth.width,
190
+ editorView = _ref5.editorView,
191
+ getPos = _ref5.getPos,
192
+ tableRef = _ref5.tableRef,
193
+ isNested = _ref5.isNested,
194
+ tableWrapperHeight = _ref5.tableWrapperHeight,
195
+ isResizing = _ref5.isResizing,
196
+ pluginInjectionApi = _ref5.pluginInjectionApi,
197
+ isWholeTableInDanger = _ref5.isWholeTableInDanger,
198
+ isTableResizingEnabled = _ref5.isTableResizingEnabled,
199
+ isTableScalingEnabled = _ref5.isTableScalingEnabled,
200
+ isTableAlignmentEnabled = _ref5.isTableAlignmentEnabled;
164
201
  if (isTableResizingEnabled && !isNested) {
165
202
  return /*#__PURE__*/React.createElement(ResizableTableContainer, {
166
203
  className: className,
@@ -173,7 +210,8 @@ export var TableContainer = function TableContainer(_ref3) {
173
210
  isResizing: isResizing,
174
211
  pluginInjectionApi: pluginInjectionApi,
175
212
  isTableScalingEnabled: isTableScalingEnabled,
176
- isWholeTableInDanger: isWholeTableInDanger
213
+ isWholeTableInDanger: isWholeTableInDanger,
214
+ isTableAlignmentEnabled: isTableAlignmentEnabled
177
215
  }, children);
178
216
  }
179
217
  return /*#__PURE__*/React.createElement(InnerContainer, {