@atlaskit/editor-plugin-table 1.5.5 → 1.6.1

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 (65) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/plugins/table/index.js +14 -12
  3. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +37 -78
  4. package/dist/cjs/plugins/table/nodeviews/TableContainer.js +131 -0
  5. package/dist/cjs/plugins/table/nodeviews/TableResizer.js +65 -0
  6. package/dist/cjs/plugins/table/pm-plugins/table-resizing/commands.js +4 -49
  7. package/dist/cjs/plugins/table/pm-plugins/table-resizing/index.js +0 -7
  8. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/index.js +12 -6
  9. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/misc.js +3 -11
  10. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +61 -2
  11. package/dist/cjs/version.json +1 -1
  12. package/dist/es2019/plugins/table/index.js +14 -12
  13. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +17 -64
  14. package/dist/es2019/plugins/table/nodeviews/TableContainer.js +124 -0
  15. package/dist/es2019/plugins/table/nodeviews/TableResizer.js +56 -0
  16. package/dist/es2019/plugins/table/pm-plugins/table-resizing/commands.js +2 -48
  17. package/dist/es2019/plugins/table/pm-plugins/table-resizing/index.js +0 -1
  18. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/index.js +2 -2
  19. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/misc.js +5 -10
  20. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +61 -2
  21. package/dist/es2019/version.json +1 -1
  22. package/dist/esm/plugins/table/index.js +14 -12
  23. package/dist/esm/plugins/table/nodeviews/TableComponent.js +39 -81
  24. package/dist/esm/plugins/table/nodeviews/TableContainer.js +119 -0
  25. package/dist/esm/plugins/table/nodeviews/TableResizer.js +57 -0
  26. package/dist/esm/plugins/table/pm-plugins/table-resizing/commands.js +4 -48
  27. package/dist/esm/plugins/table/pm-plugins/table-resizing/index.js +0 -1
  28. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/index.js +2 -2
  29. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/misc.js +5 -10
  30. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +59 -2
  31. package/dist/esm/version.json +1 -1
  32. package/dist/types/plugins/table/nodeviews/TableComponent.d.ts +0 -3
  33. package/dist/types/plugins/table/nodeviews/TableContainer.d.ts +35 -0
  34. package/dist/types/plugins/table/nodeviews/TableResizer.d.ts +13 -0
  35. package/dist/types/plugins/table/pm-plugins/table-resizing/commands.d.ts +2 -4
  36. package/dist/types/plugins/table/pm-plugins/table-resizing/index.d.ts +0 -1
  37. package/dist/types/plugins/table/pm-plugins/table-resizing/utils/index.d.ts +2 -2
  38. package/dist/types/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +0 -1
  39. package/dist/types/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +3 -0
  40. package/dist/types/plugins/table/types.d.ts +1 -0
  41. package/dist/types-ts4.5/plugins/table/nodeviews/TableComponent.d.ts +0 -3
  42. package/dist/types-ts4.5/plugins/table/nodeviews/TableContainer.d.ts +35 -0
  43. package/dist/types-ts4.5/plugins/table/nodeviews/TableResizer.d.ts +13 -0
  44. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/commands.d.ts +2 -4
  45. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/index.d.ts +0 -1
  46. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/index.d.ts +2 -2
  47. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +0 -1
  48. package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +3 -0
  49. package/dist/types-ts4.5/plugins/table/types.d.ts +1 -0
  50. package/package.json +3 -3
  51. package/src/__tests__/integration/sticky-header.ts +4 -1
  52. package/src/__tests__/unit/commands.ts +3 -0
  53. package/src/__tests__/unit/event-handlers.ts +2 -0
  54. package/src/__tests__/unit/index.ts +2 -0
  55. package/src/__tests__/unit/keymap.ts +2 -0
  56. package/src/__tests__/unit/nodeviews/TableContainer.tsx +164 -0
  57. package/src/plugins/table/index.tsx +22 -19
  58. package/src/plugins/table/nodeviews/TableComponent.tsx +21 -78
  59. package/src/plugins/table/nodeviews/TableContainer.tsx +200 -0
  60. package/src/plugins/table/nodeviews/TableResizer.tsx +88 -0
  61. package/src/plugins/table/pm-plugins/table-resizing/commands.ts +3 -72
  62. package/src/plugins/table/pm-plugins/table-resizing/index.ts +0 -1
  63. package/src/plugins/table/pm-plugins/table-resizing/utils/index.ts +6 -2
  64. package/src/plugins/table/pm-plugins/table-resizing/utils/misc.ts +7 -12
  65. package/src/plugins/table/pm-plugins/table-resizing/utils/scale-table.ts +79 -0
@@ -28,7 +28,6 @@ export interface ComponentProps {
28
28
  }
29
29
  interface TableState {
30
30
  scroll: number;
31
- tableContainerWidth: string;
32
31
  parentWidth?: number;
33
32
  isLoading: boolean;
34
33
  stickyHeader?: RowStickyState;
@@ -54,13 +53,11 @@ declare class TableComponent extends React.Component<ComponentProps, TableState>
54
53
  onStickyState: (state: StickyPluginState) => void;
55
54
  prevTableState: any;
56
55
  render(): JSX.Element;
57
- private getMarginLeft;
58
56
  private handleScroll;
59
57
  private handleTableResizing;
60
58
  private scaleTable;
61
59
  private handleAutoSize;
62
60
  private handleWindowResize;
63
- private updateTableContainerWidth;
64
61
  private getParentNodeWidth;
65
62
  private updateParentWidth;
66
63
  private tableNodeLayoutSize;
@@ -0,0 +1,35 @@
1
+ import React, { PropsWithChildren } from 'react';
2
+ import { Node as PMNode } from 'prosemirror-model';
3
+ import { EditorView } from 'prosemirror-view';
4
+ import { EditorContainerWidth } from '@atlaskit/editor-common/types';
5
+ type InnerContainerProps = {
6
+ className: string;
7
+ marginLeft: number | undefined;
8
+ width: number | 'inherit';
9
+ node: PMNode;
10
+ };
11
+ export declare const InnerContainer: React.ForwardRefExoticComponent<InnerContainerProps & {
12
+ children?: React.ReactNode;
13
+ } & React.RefAttributes<HTMLDivElement>>;
14
+ type ResizableTableContainerProps = {
15
+ containerWidth: number;
16
+ lineLength: number;
17
+ node: PMNode;
18
+ className: string;
19
+ editorView: EditorView;
20
+ getPos: () => number;
21
+ tableRef: HTMLTableElement;
22
+ };
23
+ export declare const ResizableTableContainer: ({ children, className, node, lineLength, editorView, getPos, tableRef, }: PropsWithChildren<ResizableTableContainerProps>) => JSX.Element;
24
+ type TableContainerProps = {
25
+ node: PMNode;
26
+ className: string;
27
+ containerWidth: EditorContainerWidth;
28
+ isFullWidthModeEnabled: boolean | undefined;
29
+ isBreakoutEnabled: boolean | undefined;
30
+ editorView: EditorView;
31
+ getPos: () => number;
32
+ tableRef: HTMLTableElement;
33
+ };
34
+ export declare const TableContainer: ({ children, node, className, containerWidth: { lineLength, width: editorWidth }, isFullWidthModeEnabled, isBreakoutEnabled, editorView, getPos, tableRef, }: PropsWithChildren<TableContainerProps>) => JSX.Element;
35
+ export {};
@@ -0,0 +1,13 @@
1
+ import { PropsWithChildren } from 'react';
2
+ import { EditorView } from 'prosemirror-view';
3
+ import { Node as PMNode } from 'prosemirror-model';
4
+ interface TableResizerProps {
5
+ width: number;
6
+ updateWidth: (width: number) => void;
7
+ editorView: EditorView;
8
+ getPos: () => number;
9
+ node: PMNode;
10
+ tableRef: HTMLTableElement;
11
+ }
12
+ export declare const TableResizer: ({ children, width, updateWidth, editorView, getPos, node, tableRef, }: PropsWithChildren<TableResizerProps>) => JSX.Element;
13
+ export {};
@@ -1,10 +1,8 @@
1
1
  import { Node as PMNode } from 'prosemirror-model';
2
2
  import { Transaction } from 'prosemirror-state';
3
- import type { Command } from '@atlaskit/editor-common/types';
4
- import type { DomAtPos } from 'prosemirror-utils';
5
- import { ResizeState, ScaleOptions } from './utils';
6
3
  import { ContentNodeWithPos } from 'prosemirror-utils';
7
- export declare const scaleTable: (tableRef: HTMLTableElement | null | undefined, options: ScaleOptions, domAtPos: DomAtPos) => Command;
4
+ import type { Command } from '@atlaskit/editor-common/types';
5
+ import { ResizeState } from './utils';
8
6
  export declare const evenColumns: ({ resizeState, table, start, event, }: {
9
7
  resizeState: ResizeState;
10
8
  table: PMNode;
@@ -1,4 +1,3 @@
1
1
  export { createPlugin } from './plugin';
2
- export { scaleTable } from './commands';
3
2
  export { pluginKey } from './plugin-key';
4
3
  export { getPluginState } from './plugin-factory';
@@ -4,9 +4,9 @@ export { getColumnStateFromDOM, getFreeSpace, getCellsRefsInColumn, calculateCol
4
4
  export type { ColumnState } from './column-state';
5
5
  export { growColumn, shrinkColumn, reduceSpace } from './resize-logic';
6
6
  export { getResizeState, updateColgroup, getTotalWidth, evenAllColumnsWidths, bulkColumnsResize, areColumnsEven, adjustColumnsWidths, } from './resize-state';
7
- export { tableLayoutToSize, getLayoutSize, getDefaultLayoutMaxWidth, pointsAtCell, currentColWidth, domCellAround, } from './misc';
7
+ export { getLayoutSize, getDefaultLayoutMaxWidth, pointsAtCell, currentColWidth, domCellAround, } from './misc';
8
8
  export { updateControls, isClickNear, getResizeCellPos } from './dom';
9
- export { scale, scaleWithParent } from './scale-table';
9
+ export { scale, scaleWithParent, scaleTable, previewScaleTable, } from './scale-table';
10
10
  export type { ScaleOptions } from './scale-table';
11
11
  export type { ResizeState, ResizeStateWithAnalytics } from './types';
12
12
  export { resizeColumn } from './resize-column';
@@ -5,7 +5,6 @@ import { TableOptions } from '../../../nodeviews/types';
5
5
  import { Node as PMNode } from 'prosemirror-model';
6
6
  import { EditorState } from 'prosemirror-state';
7
7
  import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
8
- export declare const tableLayoutToSize: Record<string, number>;
9
8
  export declare function getLayoutSize(tableLayout: TableLayout, containerWidth: number | undefined, options: TableOptions): number;
10
9
  export declare function getDefaultLayoutMaxWidth(containerWidth?: number): number;
11
10
  export declare function pointsAtCell($pos: ResolvedPos<any>): false | PMNode<any> | null | undefined;
@@ -1,4 +1,5 @@
1
1
  import { Node as PMNode } from 'prosemirror-model';
2
+ import { Transaction } from 'prosemirror-state';
2
3
  import type { DomAtPos } from 'prosemirror-utils';
3
4
  import { ResizeState } from '../utils/types';
4
5
  export interface ScaleOptions {
@@ -15,3 +16,5 @@ export interface ScaleOptions {
15
16
  export declare const scale: (tableRef: HTMLTableElement, options: ScaleOptions, domAtPos: DomAtPos) => ResizeState | undefined;
16
17
  export declare const scaleWithParent: (tableRef: HTMLTableElement, parentWidth: number, table: PMNode, start: number, domAtPos: DomAtPos) => ResizeState;
17
18
  export declare function scaleTableTo(state: ResizeState, maxSize: number): ResizeState;
19
+ export declare const previewScaleTable: (tableRef: HTMLTableElement | null | undefined, options: ScaleOptions, domAtPos: DomAtPos) => void;
20
+ export declare const scaleTable: (tableRef: HTMLTableElement | null | undefined, options: ScaleOptions, domAtPos: DomAtPos) => (tr: Transaction) => Transaction<any>;
@@ -298,6 +298,7 @@ export declare const TableCssClassName: {
298
298
  TABLE_HEADER_CELL_WRAPPER: string;
299
299
  TABLE_ROW_CONTROLS_WRAPPER: string;
300
300
  TABLE_COLUMN_CONTROLS_DECORATIONS: string;
301
+ TABLE_RESIZER_CONTAINER: string;
301
302
  };
302
303
  export interface ToolbarMenuConfig {
303
304
  allowHeaderRow?: boolean;
@@ -28,7 +28,6 @@ export interface ComponentProps {
28
28
  }
29
29
  interface TableState {
30
30
  scroll: number;
31
- tableContainerWidth: string;
32
31
  parentWidth?: number;
33
32
  isLoading: boolean;
34
33
  stickyHeader?: RowStickyState;
@@ -54,13 +53,11 @@ declare class TableComponent extends React.Component<ComponentProps, TableState>
54
53
  onStickyState: (state: StickyPluginState) => void;
55
54
  prevTableState: any;
56
55
  render(): JSX.Element;
57
- private getMarginLeft;
58
56
  private handleScroll;
59
57
  private handleTableResizing;
60
58
  private scaleTable;
61
59
  private handleAutoSize;
62
60
  private handleWindowResize;
63
- private updateTableContainerWidth;
64
61
  private getParentNodeWidth;
65
62
  private updateParentWidth;
66
63
  private tableNodeLayoutSize;
@@ -0,0 +1,35 @@
1
+ import React, { PropsWithChildren } from 'react';
2
+ import { Node as PMNode } from 'prosemirror-model';
3
+ import { EditorView } from 'prosemirror-view';
4
+ import { EditorContainerWidth } from '@atlaskit/editor-common/types';
5
+ type InnerContainerProps = {
6
+ className: string;
7
+ marginLeft: number | undefined;
8
+ width: number | 'inherit';
9
+ node: PMNode;
10
+ };
11
+ export declare const InnerContainer: React.ForwardRefExoticComponent<InnerContainerProps & {
12
+ children?: React.ReactNode;
13
+ } & React.RefAttributes<HTMLDivElement>>;
14
+ type ResizableTableContainerProps = {
15
+ containerWidth: number;
16
+ lineLength: number;
17
+ node: PMNode;
18
+ className: string;
19
+ editorView: EditorView;
20
+ getPos: () => number;
21
+ tableRef: HTMLTableElement;
22
+ };
23
+ export declare const ResizableTableContainer: ({ children, className, node, lineLength, editorView, getPos, tableRef, }: PropsWithChildren<ResizableTableContainerProps>) => JSX.Element;
24
+ type TableContainerProps = {
25
+ node: PMNode;
26
+ className: string;
27
+ containerWidth: EditorContainerWidth;
28
+ isFullWidthModeEnabled: boolean | undefined;
29
+ isBreakoutEnabled: boolean | undefined;
30
+ editorView: EditorView;
31
+ getPos: () => number;
32
+ tableRef: HTMLTableElement;
33
+ };
34
+ export declare const TableContainer: ({ children, node, className, containerWidth: { lineLength, width: editorWidth }, isFullWidthModeEnabled, isBreakoutEnabled, editorView, getPos, tableRef, }: PropsWithChildren<TableContainerProps>) => JSX.Element;
35
+ export {};
@@ -0,0 +1,13 @@
1
+ import { PropsWithChildren } from 'react';
2
+ import { EditorView } from 'prosemirror-view';
3
+ import { Node as PMNode } from 'prosemirror-model';
4
+ interface TableResizerProps {
5
+ width: number;
6
+ updateWidth: (width: number) => void;
7
+ editorView: EditorView;
8
+ getPos: () => number;
9
+ node: PMNode;
10
+ tableRef: HTMLTableElement;
11
+ }
12
+ export declare const TableResizer: ({ children, width, updateWidth, editorView, getPos, node, tableRef, }: PropsWithChildren<TableResizerProps>) => JSX.Element;
13
+ export {};
@@ -1,10 +1,8 @@
1
1
  import { Node as PMNode } from 'prosemirror-model';
2
2
  import { Transaction } from 'prosemirror-state';
3
- import type { Command } from '@atlaskit/editor-common/types';
4
- import type { DomAtPos } from 'prosemirror-utils';
5
- import { ResizeState, ScaleOptions } from './utils';
6
3
  import { ContentNodeWithPos } from 'prosemirror-utils';
7
- export declare const scaleTable: (tableRef: HTMLTableElement | null | undefined, options: ScaleOptions, domAtPos: DomAtPos) => Command;
4
+ import type { Command } from '@atlaskit/editor-common/types';
5
+ import { ResizeState } from './utils';
8
6
  export declare const evenColumns: ({ resizeState, table, start, event, }: {
9
7
  resizeState: ResizeState;
10
8
  table: PMNode;
@@ -1,4 +1,3 @@
1
1
  export { createPlugin } from './plugin';
2
- export { scaleTable } from './commands';
3
2
  export { pluginKey } from './plugin-key';
4
3
  export { getPluginState } from './plugin-factory';
@@ -4,9 +4,9 @@ export { getColumnStateFromDOM, getFreeSpace, getCellsRefsInColumn, calculateCol
4
4
  export type { ColumnState } from './column-state';
5
5
  export { growColumn, shrinkColumn, reduceSpace } from './resize-logic';
6
6
  export { getResizeState, updateColgroup, getTotalWidth, evenAllColumnsWidths, bulkColumnsResize, areColumnsEven, adjustColumnsWidths, } from './resize-state';
7
- export { tableLayoutToSize, getLayoutSize, getDefaultLayoutMaxWidth, pointsAtCell, currentColWidth, domCellAround, } from './misc';
7
+ export { getLayoutSize, getDefaultLayoutMaxWidth, pointsAtCell, currentColWidth, domCellAround, } from './misc';
8
8
  export { updateControls, isClickNear, getResizeCellPos } from './dom';
9
- export { scale, scaleWithParent } from './scale-table';
9
+ export { scale, scaleWithParent, scaleTable, previewScaleTable, } from './scale-table';
10
10
  export type { ScaleOptions } from './scale-table';
11
11
  export type { ResizeState, ResizeStateWithAnalytics } from './types';
12
12
  export { resizeColumn } from './resize-column';
@@ -5,7 +5,6 @@ import { TableOptions } from '../../../nodeviews/types';
5
5
  import { Node as PMNode } from 'prosemirror-model';
6
6
  import { EditorState } from 'prosemirror-state';
7
7
  import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
8
- export declare const tableLayoutToSize: Record<string, number>;
9
8
  export declare function getLayoutSize(tableLayout: TableLayout, containerWidth: number | undefined, options: TableOptions): number;
10
9
  export declare function getDefaultLayoutMaxWidth(containerWidth?: number): number;
11
10
  export declare function pointsAtCell($pos: ResolvedPos<any>): false | PMNode<any> | null | undefined;
@@ -1,4 +1,5 @@
1
1
  import { Node as PMNode } from 'prosemirror-model';
2
+ import { Transaction } from 'prosemirror-state';
2
3
  import type { DomAtPos } from 'prosemirror-utils';
3
4
  import { ResizeState } from '../utils/types';
4
5
  export interface ScaleOptions {
@@ -15,3 +16,5 @@ export interface ScaleOptions {
15
16
  export declare const scale: (tableRef: HTMLTableElement, options: ScaleOptions, domAtPos: DomAtPos) => ResizeState | undefined;
16
17
  export declare const scaleWithParent: (tableRef: HTMLTableElement, parentWidth: number, table: PMNode, start: number, domAtPos: DomAtPos) => ResizeState;
17
18
  export declare function scaleTableTo(state: ResizeState, maxSize: number): ResizeState;
19
+ export declare const previewScaleTable: (tableRef: HTMLTableElement | null | undefined, options: ScaleOptions, domAtPos: DomAtPos) => void;
20
+ export declare const scaleTable: (tableRef: HTMLTableElement | null | undefined, options: ScaleOptions, domAtPos: DomAtPos) => (tr: Transaction) => Transaction<any>;
@@ -298,6 +298,7 @@ export declare const TableCssClassName: {
298
298
  TABLE_HEADER_CELL_WRAPPER: string;
299
299
  TABLE_ROW_CONTROLS_WRAPPER: string;
300
300
  TABLE_COLUMN_CONTROLS_DECORATIONS: string;
301
+ TABLE_RESIZER_CONTAINER: string;
301
302
  };
302
303
  export interface ToolbarMenuConfig {
303
304
  allowHeaderRow?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "1.5.5",
3
+ "version": "1.6.1",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@atlaskit/adf-schema": "^25.8.0",
30
- "@atlaskit/editor-common": "^74.6.0",
30
+ "@atlaskit/editor-common": "^74.7.0",
31
31
  "@atlaskit/editor-palette": "1.4.3",
32
32
  "@atlaskit/editor-plugin-analytics": "^0.0.2",
33
33
  "@atlaskit/editor-plugin-content-insertion": "^0.0.2",
@@ -73,10 +73,10 @@
73
73
  "@atlaskit/logo": "^13.14.0",
74
74
  "@atlaskit/media-integration-test-helpers": "^3.0.0",
75
75
  "@atlaskit/synchrony-test-helpers": "^2.3.0",
76
- "@atlaskit/util-data-test": "^17.8.0",
77
76
  "@atlaskit/visual-regression": "*",
78
77
  "@atlaskit/webdriver-runner": "*",
79
78
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
79
+ "@atlassian/feature-flags-test-utils": "^0.1.2",
80
80
  "@testing-library/react": "^12.1.5",
81
81
  "@types/prosemirror-history": "^1.0.1",
82
82
  "prosemirror-history": "^1.1.3",
@@ -173,9 +173,12 @@ BrowserTestCase(
173
173
  },
174
174
  );
175
175
 
176
+ // FIXME: This test was automatically skipped due to failure on 10/06/2023: https://product-fabric.atlassian.net/browse/ED-18761
176
177
  BrowserTestCase(
177
178
  'Sticky header should resize when the width of parent scroll container changes',
178
- {},
179
+ {
180
+ skip: ['*'],
181
+ },
179
182
  async (client: any, testName: string) => {
180
183
  const page = await goToEditorTestingWDExample(
181
184
  client,
@@ -59,6 +59,8 @@ import panelPlugin from '@atlaskit/editor-core/src/plugins/panel';
59
59
  import expandPlugin from '@atlaskit/editor-core/src/plugins/expand';
60
60
  import extensionPlugin from '@atlaskit/editor-core/src/plugins/extension';
61
61
  import mediaPlugin from '@atlaskit/editor-core/src/plugins/media';
62
+ import floatingToolbarPlugin from '@atlaskit/editor-core/src/plugins/floating-toolbar';
63
+
62
64
  import { widthPlugin } from '@atlaskit/editor-plugin-width';
63
65
  import { gridPlugin } from '@atlaskit/editor-plugin-grid';
64
66
  import textFormattingPlugin from '@atlaskit/editor-core/src/plugins/text-formatting';
@@ -94,6 +96,7 @@ describe('table plugin: actions', () => {
94
96
  .add(panelPlugin)
95
97
  .add(textFormattingPlugin)
96
98
  .add(extensionPlugin)
99
+ .add(floatingToolbarPlugin)
97
100
  .add([mediaPlugin, { allowMediaSingle: true }])
98
101
  .add(expandPlugin),
99
102
  pluginKey,
@@ -35,6 +35,7 @@ import { pluginKey } from '../../plugins/table/pm-plugins/plugin-key';
35
35
  import { TableCssClassName as ClassName } from '../../plugins/table/types';
36
36
  import tablePlugin from '../../plugins/table-plugin';
37
37
  import mediaPlugin from '@atlaskit/editor-core/src/plugins/media';
38
+ import floatingToolbarPlugin from '@atlaskit/editor-core/src/plugins/floating-toolbar';
38
39
  import { widthPlugin } from '@atlaskit/editor-plugin-width';
39
40
  import { gridPlugin } from '@atlaskit/editor-plugin-grid';
40
41
  import featureFlagsPlugin from '@atlaskit/editor-plugin-feature-flags';
@@ -172,6 +173,7 @@ describe('table event handlers', () => {
172
173
  .add(widthPlugin)
173
174
  .add(gridPlugin)
174
175
  .add(tablePlugin)
176
+ .add(floatingToolbarPlugin)
175
177
  .add([
176
178
  mediaPlugin,
177
179
  {
@@ -57,6 +57,7 @@ import deprecatedAnalyticsPlugin from '@atlaskit/editor-core/src/plugins/analyti
57
57
  import { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
58
58
  import mediaPlugin from '@atlaskit/editor-core/src/plugins/media';
59
59
  import selectionPlugin from '@atlaskit/editor-core/src/plugins/selection';
60
+ import floatingToolbarPlugin from '@atlaskit/editor-core/src/plugins/floating-toolbar';
60
61
  import { widthPlugin } from '@atlaskit/editor-plugin-width';
61
62
  import { gridPlugin } from '@atlaskit/editor-plugin-grid';
62
63
  import { insertMediaAsMediaSingle } from '@atlaskit/editor-core/src/plugins/media/utils/media-single';
@@ -105,6 +106,7 @@ describe('table plugin', () => {
105
106
  .add(widthPlugin)
106
107
  .add(gridPlugin)
107
108
  .add([tablePlugin, { tableOptions }])
109
+ .add(floatingToolbarPlugin)
108
110
  .add([mediaPlugin, { allowMediaSingle: true }])
109
111
  .add(textFormattingPlugin)
110
112
  .add(listPlugin)
@@ -55,6 +55,7 @@ import extensionPlugin from '@atlaskit/editor-core/src/plugins/extension';
55
55
  import datePlugin from '@atlaskit/editor-core/src/plugins/date';
56
56
  import layoutPlugin from '@atlaskit/editor-core/src/plugins/layout';
57
57
  import statusPlugin from '@atlaskit/editor-core/src/plugins/status';
58
+ import floatingToolbarPlugin from '@atlaskit/editor-core/src/plugins/floating-toolbar';
58
59
  import tablePlugin from '../../plugins/table';
59
60
  import { TablePluginState } from '../../plugins/table/types';
60
61
  import { pluginKey } from '../../plugins/table/pm-plugins/plugin-key';
@@ -113,6 +114,7 @@ describe('table keymap', () => {
113
114
  .add(datePlugin)
114
115
  .add(layoutPlugin)
115
116
  .add([statusPlugin, { menuDisabled: false }])
117
+ .add(floatingToolbarPlugin)
116
118
  .add([mediaPlugin, { allowMediaSingle: true }]);
117
119
 
118
120
  const editor = (doc: DocBuilder) =>
@@ -0,0 +1,164 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+
4
+ import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
5
+ import { ffTest } from '@atlassian/feature-flags-test-utils';
6
+ import {
7
+ doc,
8
+ p,
9
+ table,
10
+ tr,
11
+ td,
12
+ tdEmpty,
13
+ DocBuilder,
14
+ } from '@atlaskit/editor-test-helpers/doc-builder';
15
+ import { findTable } from '@atlaskit/editor-tables/utils';
16
+
17
+ import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
18
+ import {
19
+ ResizableTableContainer,
20
+ TableContainer,
21
+ } from '../../../plugins/table/nodeviews/TableContainer';
22
+ import { TablePluginState } from '../../../plugins/table/types';
23
+ import tablePlugin from '../../../plugins/table-plugin';
24
+ import { TableAttributes } from '@atlaskit/adf-schema';
25
+ import { akEditorWideLayoutWidth } from '@atlaskit/editor-shared-styles';
26
+
27
+ describe('table -> nodeviews -> TableContainer.tsx', () => {
28
+ const createEditor = createEditorFactory<TablePluginState>();
29
+ const editor = (
30
+ doc: DocBuilder,
31
+ featureFlags?: { [featureFlag: string]: string | boolean },
32
+ ) => {
33
+ return createEditor({
34
+ doc,
35
+ editorProps: {
36
+ allowTables: false,
37
+ dangerouslyAppendPlugins: {
38
+ __plugins: [tablePlugin()],
39
+ },
40
+ featureFlags,
41
+ },
42
+ pluginKey,
43
+ });
44
+ };
45
+ const createNode = (attrs?: TableAttributes) => {
46
+ const { editorView: view } = editor(
47
+ doc(p('text'), table(attrs)(tr(td()(p('{<>}text')), tdEmpty, tdEmpty))),
48
+ );
49
+ const resolvedTable = findTable(view.state.selection);
50
+
51
+ return resolvedTable!.node;
52
+ };
53
+
54
+ describe('show correct container for FF and options', () => {
55
+ const buildContainer = (allowResizing: boolean) => {
56
+ const node = createNode();
57
+
58
+ const { container } = render(
59
+ <TableContainer
60
+ containerWidth={{
61
+ width: 1800,
62
+ lineLength: 720,
63
+ }}
64
+ node={node}
65
+ isFullWidthModeEnabled={allowResizing}
66
+ isBreakoutEnabled={allowResizing}
67
+ className={''}
68
+ editorView={{} as any}
69
+ getPos={() => 1}
70
+ tableRef={{} as any}
71
+ />,
72
+ );
73
+
74
+ return container;
75
+ };
76
+
77
+ const buildTest = (
78
+ allowResizing: boolean,
79
+ expected?: { ffTrue?: boolean; ffFalse?: boolean },
80
+ ) => {
81
+ ffTest(
82
+ 'platform.editor.custom-table-width',
83
+ async () => {
84
+ const container = buildContainer(allowResizing);
85
+
86
+ expect(!!container.querySelector('.resizer-item')).toBe(
87
+ expected?.ffTrue ?? true,
88
+ );
89
+ },
90
+ async () => {
91
+ const container = buildContainer(allowResizing);
92
+
93
+ expect(!!container.querySelector('.resizer-item')).toBe(
94
+ expected?.ffFalse ?? false,
95
+ );
96
+ },
97
+ );
98
+ };
99
+
100
+ describe('when allowResizing is true', () => {
101
+ buildTest(true);
102
+ });
103
+
104
+ describe('when allowResizing is false', () => {
105
+ buildTest(false, {
106
+ ffTrue: false,
107
+ });
108
+ });
109
+ });
110
+
111
+ describe('sets width and margin correctly for resizable container', () => {
112
+ const buildContainer = (attrs: TableAttributes) => {
113
+ const node = createNode(attrs);
114
+
115
+ const { container } = render(
116
+ <ResizableTableContainer
117
+ containerWidth={1800}
118
+ lineLength={720}
119
+ node={node}
120
+ className={''}
121
+ editorView={{} as any}
122
+ getPos={() => 1}
123
+ tableRef={{} as any}
124
+ />,
125
+ );
126
+
127
+ return container;
128
+ };
129
+
130
+ describe('when width attribute is not set', () => {
131
+ ffTest('platform.editor.custom-table-width', () => {
132
+ const container = buildContainer({ layout: 'wide' });
133
+
134
+ const style = window.getComputedStyle(container.firstChild as Element);
135
+ expect(style.width).toBe(`${akEditorWideLayoutWidth}px`);
136
+ expect(style.marginLeft).toBe('-120px');
137
+ });
138
+ });
139
+
140
+ describe('when width attribute is set', () => {
141
+ ffTest(
142
+ 'platform.editor.custom-table-width',
143
+ () => {
144
+ const container = buildContainer({ width: 860 });
145
+
146
+ const style = window.getComputedStyle(
147
+ container.firstChild as Element,
148
+ );
149
+ expect(style.width).toBe(`860px`);
150
+ expect(style.marginLeft).toBe('-70px');
151
+ }, // fallback to layout because width can't be an attribute in schema
152
+ () => {
153
+ const container = buildContainer({ width: 860 });
154
+
155
+ const style = window.getComputedStyle(
156
+ container.firstChild as Element,
157
+ );
158
+ expect(style.width).toBe(`760px`);
159
+ expect(style.marginLeft).toBe('-20px');
160
+ },
161
+ );
162
+ });
163
+ });
164
+ });
@@ -169,7 +169,7 @@ const tablesPlugin: NextEditorPlugin<
169
169
  } =
170
170
  options ||
171
171
  ({
172
- editorAnalyticsAPI: api?.dependencies.analytics.actions,
172
+ editorAnalyticsAPI: api?.dependencies.analytics?.actions,
173
173
  } as TablePluginOptions);
174
174
  return createPlugin(
175
175
  dispatchAnalyticsEvent,
@@ -347,6 +347,26 @@ const tablesPlugin: NextEditorPlugin<
347
347
  ? findStickyHeaderForTable(stickyHeadersState, tablePos)
348
348
  : undefined;
349
349
 
350
+ const LayoutContent = getBooleanFF(
351
+ 'platform.editor.custom-table-width',
352
+ ) ? null : isLayoutSupported(state) &&
353
+ options &&
354
+ options.breakoutEnabled ? (
355
+ <LayoutButton
356
+ editorView={editorView}
357
+ mountPoint={popupsMountPoint}
358
+ boundariesElement={popupsBoundariesElement}
359
+ scrollableElement={popupsScrollableElement}
360
+ targetRef={tableWrapperTarget!}
361
+ layout={layout}
362
+ isResizing={
363
+ !!resizingPluginState && !!resizingPluginState.dragging
364
+ }
365
+ stickyHeader={stickyHeader}
366
+ editorAnalyticsAPI={options?.editorAnalyticsAPI}
367
+ />
368
+ ) : null;
369
+
350
370
  return (
351
371
  <>
352
372
  {targetCellPosition &&
@@ -416,24 +436,7 @@ const tablesPlugin: NextEditorPlugin<
416
436
  editorAnalyticsAPI={options?.editorAnalyticsAPI}
417
437
  />
418
438
  )}
419
- {isLayoutSupported(state) &&
420
- options &&
421
- options.breakoutEnabled && (
422
- <LayoutButton
423
- editorView={editorView}
424
- mountPoint={popupsMountPoint}
425
- boundariesElement={popupsBoundariesElement}
426
- scrollableElement={popupsScrollableElement}
427
- targetRef={tableWrapperTarget!}
428
- layout={layout}
429
- isResizing={
430
- !!resizingPluginState &&
431
- !!resizingPluginState.dragging
432
- }
433
- stickyHeader={stickyHeader}
434
- editorAnalyticsAPI={options?.editorAnalyticsAPI}
435
- />
436
- )}
439
+ {LayoutContent}
437
440
  </>
438
441
  );
439
442
  }}