@atlaskit/editor-plugin-table 7.16.1 → 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 (45) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/commands/insert.js +14 -2
  3. package/dist/cjs/nodeviews/TableComponent.js +4 -2
  4. package/dist/cjs/nodeviews/TableComponentWithSharedState.js +1 -0
  5. package/dist/cjs/nodeviews/TableContainer.js +72 -34
  6. package/dist/cjs/nodeviews/table.js +7 -4
  7. package/dist/cjs/plugin.js +12 -3
  8. package/dist/cjs/pm-plugins/keymap.js +1 -13
  9. package/dist/cjs/pm-plugins/main.js +1 -1
  10. package/dist/es2019/commands/insert.js +15 -3
  11. package/dist/es2019/nodeviews/TableComponent.js +5 -2
  12. package/dist/es2019/nodeviews/TableComponentWithSharedState.js +1 -0
  13. package/dist/es2019/nodeviews/TableContainer.js +51 -11
  14. package/dist/es2019/nodeviews/table.js +7 -4
  15. package/dist/es2019/plugin.js +11 -3
  16. package/dist/es2019/pm-plugins/keymap.js +4 -14
  17. package/dist/es2019/pm-plugins/main.js +1 -1
  18. package/dist/esm/commands/insert.js +15 -3
  19. package/dist/esm/nodeviews/TableComponent.js +4 -2
  20. package/dist/esm/nodeviews/TableComponentWithSharedState.js +1 -0
  21. package/dist/esm/nodeviews/TableContainer.js +73 -35
  22. package/dist/esm/nodeviews/table.js +7 -4
  23. package/dist/esm/plugin.js +12 -3
  24. package/dist/esm/pm-plugins/keymap.js +4 -16
  25. package/dist/esm/pm-plugins/main.js +1 -1
  26. package/dist/types/commands/insert.d.ts +3 -2
  27. package/dist/types/nodeviews/TableComponent.d.ts +1 -0
  28. package/dist/types/nodeviews/TableContainer.d.ts +7 -5
  29. package/dist/types/nodeviews/table.d.ts +1 -1
  30. package/dist/types/nodeviews/types.d.ts +1 -0
  31. package/dist/types-ts4.5/commands/insert.d.ts +3 -2
  32. package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +1 -0
  33. package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +7 -5
  34. package/dist/types-ts4.5/nodeviews/table.d.ts +1 -1
  35. package/dist/types-ts4.5/nodeviews/types.d.ts +1 -0
  36. package/package.json +5 -5
  37. package/src/commands/insert.ts +26 -18
  38. package/src/nodeviews/TableComponent.tsx +3 -0
  39. package/src/nodeviews/TableComponentWithSharedState.tsx +1 -0
  40. package/src/nodeviews/TableContainer.tsx +75 -13
  41. package/src/nodeviews/table.tsx +4 -1
  42. package/src/nodeviews/types.ts +1 -0
  43. package/src/plugin.tsx +18 -8
  44. package/src/pm-plugins/keymap.ts +4 -25
  45. package/src/pm-plugins/main.ts +1 -0
@@ -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
@@ -212,7 +212,13 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
212
212
 
213
213
  options: {
214
214
  selectNodeInserted: false,
215
- analyticsPayload,
215
+ analyticsPayload: {
216
+ ...analyticsPayload,
217
+ attributes: {
218
+ ...analyticsPayload.attributes,
219
+ localId: node.attrs.localId,
220
+ },
221
+ },
216
222
  },
217
223
  }) ?? false
218
224
  );
@@ -638,17 +644,21 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
638
644
  // see comment on tablesPlugin.getSharedState on usage
639
645
  const tableState = api?.table?.sharedState.currentState();
640
646
 
641
- const tr = insert(
642
- createTableWithWidth(
643
- options?.isTableScalingEnabled,
644
- tableState?.isFullWidthModeEnabled,
645
- )(state.schema),
646
- );
647
+ const tableNode = createTableWithWidth(
648
+ options?.isTableScalingEnabled,
649
+ tableState?.isFullWidthModeEnabled,
650
+ )(state.schema);
651
+
652
+ const tr = insert(tableNode);
653
+
647
654
  editorAnalyticsAPI?.attachAnalyticsEvent({
648
655
  action: ACTION.INSERTED,
649
656
  actionSubject: ACTION_SUBJECT.DOCUMENT,
650
657
  actionSubjectId: ACTION_SUBJECT_ID.TABLE,
651
- attributes: { inputMethod: INPUT_METHOD.QUICK_INSERT },
658
+ attributes: {
659
+ inputMethod: INPUT_METHOD.QUICK_INSERT,
660
+ localId: tableNode.attrs.localId,
661
+ },
652
662
  eventType: EVENT_TYPE.TRACK,
653
663
  })(tr);
654
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),