@atlaskit/editor-plugin-table 19.0.1 → 20.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/cjs/nodeviews/table.js +18 -2
  3. package/dist/cjs/nodeviews/toDOM.js +18 -4
  4. package/dist/cjs/pm-plugins/main.js +38 -4
  5. package/dist/cjs/pm-plugins/table-width.js +10 -0
  6. package/dist/cjs/pm-plugins/transforms/content-mode.js +48 -0
  7. package/dist/cjs/pm-plugins/transforms/fix-tables.js +4 -35
  8. package/dist/cjs/pm-plugins/transforms/table-transform-utils.js +62 -0
  9. package/dist/cjs/pm-plugins/utils/tableMode.js +149 -0
  10. package/dist/cjs/ui/event-handlers.js +3 -2
  11. package/dist/cjs/ui/toolbar.js +25 -2
  12. package/dist/es2019/nodeviews/table.js +18 -2
  13. package/dist/es2019/nodeviews/toDOM.js +18 -4
  14. package/dist/es2019/pm-plugins/main.js +38 -4
  15. package/dist/es2019/pm-plugins/table-width.js +10 -0
  16. package/dist/es2019/pm-plugins/transforms/content-mode.js +39 -0
  17. package/dist/es2019/pm-plugins/transforms/fix-tables.js +2 -33
  18. package/dist/es2019/pm-plugins/transforms/table-transform-utils.js +56 -0
  19. package/dist/es2019/pm-plugins/utils/tableMode.js +148 -0
  20. package/dist/es2019/ui/event-handlers.js +4 -3
  21. package/dist/es2019/ui/toolbar.js +23 -2
  22. package/dist/esm/nodeviews/table.js +18 -2
  23. package/dist/esm/nodeviews/toDOM.js +18 -4
  24. package/dist/esm/pm-plugins/main.js +38 -4
  25. package/dist/esm/pm-plugins/table-width.js +10 -0
  26. package/dist/esm/pm-plugins/transforms/content-mode.js +41 -0
  27. package/dist/esm/pm-plugins/transforms/fix-tables.js +2 -33
  28. package/dist/esm/pm-plugins/transforms/table-transform-utils.js +56 -0
  29. package/dist/esm/pm-plugins/utils/tableMode.js +143 -0
  30. package/dist/esm/ui/event-handlers.js +4 -3
  31. package/dist/esm/ui/toolbar.js +25 -2
  32. package/dist/types/pm-plugins/transforms/content-mode.d.ts +8 -0
  33. package/dist/types/pm-plugins/transforms/table-transform-utils.d.ts +11 -0
  34. package/dist/types/pm-plugins/utils/tableMode.d.ts +22 -0
  35. package/dist/types/types/index.d.ts +3 -0
  36. package/dist/types-ts4.5/pm-plugins/transforms/content-mode.d.ts +8 -0
  37. package/dist/types-ts4.5/pm-plugins/transforms/table-transform-utils.d.ts +11 -0
  38. package/dist/types-ts4.5/pm-plugins/utils/tableMode.d.ts +22 -0
  39. package/dist/types-ts4.5/types/index.d.ts +3 -0
  40. package/package.json +21 -20
@@ -32,6 +32,7 @@ import AlignImageLeftIcon from '@atlaskit/icon/core/align-image-left';
32
32
  import CopyIcon from '@atlaskit/icon/core/copy';
33
33
  import CustomizeIcon from '@atlaskit/icon/core/customize';
34
34
  import DeleteIcon from '@atlaskit/icon/core/delete';
35
+ import ShrinkHorizontalIcon from '@atlaskit/icon/core/shrink-horizontal';
35
36
  import TableColumnsDistributeIcon from '@atlaskit/icon/core/table-columns-distribute';
36
37
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
37
38
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
@@ -48,6 +49,7 @@ import { normaliseAlignment } from '../pm-plugins/utils/alignment';
48
49
  import { isTableNested } from '../pm-plugins/utils/nodes';
49
50
  import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../pm-plugins/utils/selection';
50
51
  import { getMergedCellsPositions } from '../pm-plugins/utils/table';
52
+ import { applyMeasuredWidthToSelectedTable, isContentModeSupported } from '../pm-plugins/utils/tableMode';
51
53
  import { TableCssClassName } from '../types';
52
54
  import { FloatingAlignmentButtons } from './FloatingAlignmentButtons/FloatingAlignmentButtons';
53
55
  export var getToolbarMenuConfig = function getToolbarMenuConfig(config, state, _ref, editorAnalyticsAPI) {
@@ -441,7 +443,7 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
441
443
  // We don't want to show floating toolbar while resizing the table
442
444
  var isWidthResizing = tableWidthState === null || tableWidthState === void 0 ? void 0 : tableWidthState.resizing;
443
445
  if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
444
- var _api$limitedMode$shar, _api$limitedMode, _api$extension, _api$extension2;
446
+ var _api$limitedMode$shar, _api$limitedMode, _api$editorViewMode2, _api$extension, _api$extension2;
445
447
  var isNested = pluginState.tablePos && isTableNested(state, pluginState.tablePos);
446
448
  var isTableScalingWithFixedColumnWidthsOptionShown = isTableScalingEnabled && isTableFixedColumnWidthsOptionEnabled && !isNested;
447
449
  var areTableColumWidthsFixed = tableObject.node.attrs.displayMode === 'fixed';
@@ -471,6 +473,27 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
471
473
  var cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, editorView, intl, getEditorContainerWidth, api, editorAnalyticsAPI, isTableScalingEnabled, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent, options === null || options === void 0 ? void 0 : options.isCommentEditor, isLimitedModeEnabled);
472
474
  var columnSettingsItems = pluginState.isDragAndDropEnabled ? getColumnSettingItems(state, editorView, intl, getEditorContainerWidth, api, editorAnalyticsAPI, isTableScalingEnabled, isTableFixedColumnWidthsOptionEnabled, options === null || options === void 0 ? void 0 : options.isCommentEditor, isLimitedModeEnabled) : [];
473
475
  var colorPicker = !areAnyNewToolbarFlagsEnabled ? getColorPicker(state, menu, intl, editorAnalyticsAPI, getEditorView) : [];
476
+ var fitToContentButton = isContentModeSupported({
477
+ allowColumnResizing: !!pluginState.pluginConfig.allowColumnResizing,
478
+ allowTableResizing: !!pluginState.pluginConfig.allowTableResizing,
479
+ isFullPageEditor: !pluginState.isChromelessEditor && !pluginState.isCommentEditor
480
+ }) && !isNested && (api === null || api === void 0 || (_api$editorViewMode2 = api.editorViewMode) === null || _api$editorViewMode2 === void 0 || (_api$editorViewMode2 = _api$editorViewMode2.sharedState.currentState()) === null || _api$editorViewMode2 === void 0 ? void 0 : _api$editorViewMode2.mode) !== 'view' && expValEquals('platform_editor_table_fit_to_content_on_demand', 'isEnabled', true) ? [{
481
+ id: 'editor.table.fitToContent',
482
+ type: 'button',
483
+ title: intl.formatMessage(messages.fitToContent),
484
+ icon: function icon() {
485
+ return jsx(ShrinkHorizontalIcon, {
486
+ spacing: 'spacious',
487
+ label: ''
488
+ });
489
+ },
490
+ onClick: function onClick(_state, _dispatch, view) {
491
+ if (view) {
492
+ applyMeasuredWidthToSelectedTable(view, api !== null && api !== void 0 ? api : undefined);
493
+ }
494
+ return true;
495
+ }
496
+ }] : [];
474
497
 
475
498
  // Check if we need to show confirm dialog for delete button
476
499
  var confirmDialog;
@@ -549,7 +572,7 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
549
572
  },
550
573
  zIndex: akEditorFloatingPanelZIndex + 1,
551
574
  // Place the context menu slightly above the others
552
- items: [menu].concat(_toConsumableArray(!areAnyNewToolbarFlagsEnabled ? [separator(menu.hidden)] : []), _toConsumableArray(alignmentMenu), _toConsumableArray(!areAnyNewToolbarFlagsEnabled ? [separator(alignmentMenu.length === 0)] : []), _toConsumableArray(cellItems), _toConsumableArray(columnSettingsItems), _toConsumableArray(colorPicker), _toConsumableArray(!areAnyNewToolbarFlagsEnabled ? [{
575
+ items: [menu].concat(_toConsumableArray(!areAnyNewToolbarFlagsEnabled ? [separator(menu.hidden)] : []), _toConsumableArray(alignmentMenu), _toConsumableArray(!areAnyNewToolbarFlagsEnabled ? [separator(alignmentMenu.length === 0)] : []), _toConsumableArray(cellItems), _toConsumableArray(columnSettingsItems), fitToContentButton, _toConsumableArray(colorPicker), _toConsumableArray(!areAnyNewToolbarFlagsEnabled ? [{
553
576
  type: 'extensions-placeholder',
554
577
  separator: 'end'
555
578
  }, copyButton, {
@@ -0,0 +1,8 @@
1
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
3
+ export type TableMeasurement = {
4
+ colWidths: Array<number>;
5
+ tableWidth: number;
6
+ };
7
+ export declare const getTableMeasurement: (tableRef: HTMLTableElement) => TableMeasurement;
8
+ export declare const applyTableMeasurement: (tr: Transaction, tableNode: PMNode, { colWidths, tableWidth }: TableMeasurement, tablePos: number) => Transaction;
@@ -0,0 +1,11 @@
1
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
3
+ export declare const replaceCells: (tr: Transaction, table: PMNode, tablePos: number, modifyCell: (cell: PMNode, rowIndex: number, colIndex: number) => PMNode) => Transaction;
4
+ /**
5
+ * Position-preserving alternative to `replaceCells`.
6
+ *
7
+ * Uses `setNodeMarkup` per cell instead of rebuilding the whole table with
8
+ * `replaceWith`, so document positions inside cells are never invalidated.
9
+ * This preserves any existing selection through `tr.mapping`.
10
+ */
11
+ export declare const updateCellsMarkup: (tr: Transaction, table: PMNode, tablePos: number, modifyCell: (cell: PMNode, rowIndex: number, colIndex: number) => PMNode) => Transaction;
@@ -0,0 +1,22 @@
1
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
+ import type { PluginInjectionAPI } from '../../types';
4
+ type ContentModePluginOptions = {
5
+ allowColumnResizing: boolean;
6
+ allowTableResizing: boolean;
7
+ isFullPageEditor: boolean;
8
+ };
9
+ export declare const isTableInContentMode: ({ allowColumnResizing, allowTableResizing, isFullPageEditor, isTableNested, node, }: ContentModePluginOptions & {
10
+ isTableNested?: boolean;
11
+ node?: PMNode;
12
+ }) => boolean;
13
+ export declare const isContentModeSupported: ({ allowColumnResizing, allowTableResizing, isFullPageEditor, }: ContentModePluginOptions) => boolean;
14
+ export declare const hasTableBeenResized: (node: PMNode) => boolean;
15
+ /**
16
+ * Iterates all top-level tables in the document, and for those in content mode,
17
+ * measures rendered column widths and sets colwidth + table width attributes
18
+ * in a single batched transaction.
19
+ */
20
+ export declare const applyMeasuredWidthToAllTables: (view: EditorView, pluginInjectionApi?: PluginInjectionAPI) => void;
21
+ export declare const applyMeasuredWidthToSelectedTable: (view: EditorView, api?: PluginInjectionAPI) => void;
22
+ export {};
@@ -95,6 +95,8 @@ export interface TablePluginState {
95
95
  insertColumnButtonIndex?: number;
96
96
  insertRowButtonIndex?: number;
97
97
  isCellMenuOpenByKeyboard?: boolean;
98
+ isChromelessEditor?: boolean;
99
+ isCommentEditor?: boolean;
98
100
  isContextualMenuOpen?: boolean;
99
101
  isDragAndDropEnabled?: boolean;
100
102
  isFullWidthModeEnabled?: boolean;
@@ -448,6 +450,7 @@ export declare const TableCssClassName: {
448
450
  TABLE_STICKY_SENTINEL_TOP: "pm-table-sticky-sentinel-top";
449
451
  TABLE_STICKY_SHADOW: "pm-table-sticky-shadow";
450
452
  TABLE_STICKY_WRAPPER: "pm-table-sticky-wrapper";
453
+ TABLE_VIEW_CONTENT_WRAP: "tableView-content-wrap";
451
454
  };
452
455
  export interface ToolbarMenuConfig {
453
456
  allowCollapse?: boolean;
@@ -0,0 +1,8 @@
1
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
3
+ export type TableMeasurement = {
4
+ colWidths: Array<number>;
5
+ tableWidth: number;
6
+ };
7
+ export declare const getTableMeasurement: (tableRef: HTMLTableElement) => TableMeasurement;
8
+ export declare const applyTableMeasurement: (tr: Transaction, tableNode: PMNode, { colWidths, tableWidth }: TableMeasurement, tablePos: number) => Transaction;
@@ -0,0 +1,11 @@
1
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
3
+ export declare const replaceCells: (tr: Transaction, table: PMNode, tablePos: number, modifyCell: (cell: PMNode, rowIndex: number, colIndex: number) => PMNode) => Transaction;
4
+ /**
5
+ * Position-preserving alternative to `replaceCells`.
6
+ *
7
+ * Uses `setNodeMarkup` per cell instead of rebuilding the whole table with
8
+ * `replaceWith`, so document positions inside cells are never invalidated.
9
+ * This preserves any existing selection through `tr.mapping`.
10
+ */
11
+ export declare const updateCellsMarkup: (tr: Transaction, table: PMNode, tablePos: number, modifyCell: (cell: PMNode, rowIndex: number, colIndex: number) => PMNode) => Transaction;
@@ -0,0 +1,22 @@
1
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
+ import type { PluginInjectionAPI } from '../../types';
4
+ type ContentModePluginOptions = {
5
+ allowColumnResizing: boolean;
6
+ allowTableResizing: boolean;
7
+ isFullPageEditor: boolean;
8
+ };
9
+ export declare const isTableInContentMode: ({ allowColumnResizing, allowTableResizing, isFullPageEditor, isTableNested, node, }: ContentModePluginOptions & {
10
+ isTableNested?: boolean;
11
+ node?: PMNode;
12
+ }) => boolean;
13
+ export declare const isContentModeSupported: ({ allowColumnResizing, allowTableResizing, isFullPageEditor, }: ContentModePluginOptions) => boolean;
14
+ export declare const hasTableBeenResized: (node: PMNode) => boolean;
15
+ /**
16
+ * Iterates all top-level tables in the document, and for those in content mode,
17
+ * measures rendered column widths and sets colwidth + table width attributes
18
+ * in a single batched transaction.
19
+ */
20
+ export declare const applyMeasuredWidthToAllTables: (view: EditorView, pluginInjectionApi?: PluginInjectionAPI) => void;
21
+ export declare const applyMeasuredWidthToSelectedTable: (view: EditorView, api?: PluginInjectionAPI) => void;
22
+ export {};
@@ -95,6 +95,8 @@ export interface TablePluginState {
95
95
  insertColumnButtonIndex?: number;
96
96
  insertRowButtonIndex?: number;
97
97
  isCellMenuOpenByKeyboard?: boolean;
98
+ isChromelessEditor?: boolean;
99
+ isCommentEditor?: boolean;
98
100
  isContextualMenuOpen?: boolean;
99
101
  isDragAndDropEnabled?: boolean;
100
102
  isFullWidthModeEnabled?: boolean;
@@ -448,6 +450,7 @@ export declare const TableCssClassName: {
448
450
  TABLE_STICKY_SENTINEL_TOP: "pm-table-sticky-sentinel-top";
449
451
  TABLE_STICKY_SHADOW: "pm-table-sticky-shadow";
450
452
  TABLE_STICKY_WRAPPER: "pm-table-sticky-wrapper";
453
+ TABLE_VIEW_CONTENT_WRAP: "tableView-content-wrap";
451
454
  };
452
455
  export interface ToolbarMenuConfig {
453
456
  allowCollapse?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "19.0.1",
3
+ "version": "20.0.0",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -28,40 +28,41 @@
28
28
  "singleton": true
29
29
  },
30
30
  "dependencies": {
31
- "@atlaskit/adf-schema": "^52.4.0",
31
+ "@atlaskit/adf-schema": "^52.5.0",
32
32
  "@atlaskit/button": "^23.11.0",
33
33
  "@atlaskit/custom-steps": "^0.16.0",
34
34
  "@atlaskit/editor-palette": "^2.1.0",
35
- "@atlaskit/editor-plugin-accessibility-utils": "^8.0.0",
36
- "@atlaskit/editor-plugin-analytics": "^8.0.0",
37
- "@atlaskit/editor-plugin-batch-attribute-updates": "^8.0.0",
38
- "@atlaskit/editor-plugin-content-insertion": "^8.0.0",
39
- "@atlaskit/editor-plugin-editor-viewmode": "^10.0.0",
40
- "@atlaskit/editor-plugin-extension": "11.0.35",
41
- "@atlaskit/editor-plugin-guideline": "^8.0.0",
42
- "@atlaskit/editor-plugin-interaction": "^17.0.0",
43
- "@atlaskit/editor-plugin-limited-mode": "^5.0.0",
44
- "@atlaskit/editor-plugin-selection": "^8.0.0",
45
- "@atlaskit/editor-plugin-toolbar": "^5.1.0",
46
- "@atlaskit/editor-plugin-user-intent": "^6.0.0",
47
- "@atlaskit/editor-plugin-width": "^9.0.0",
35
+ "@atlaskit/editor-plugin-accessibility-utils": "^9.0.0",
36
+ "@atlaskit/editor-plugin-analytics": "^9.0.0",
37
+ "@atlaskit/editor-plugin-batch-attribute-updates": "^9.0.0",
38
+ "@atlaskit/editor-plugin-content-insertion": "^9.0.0",
39
+ "@atlaskit/editor-plugin-editor-viewmode": "^11.0.0",
40
+ "@atlaskit/editor-plugin-extension": "12.0.0",
41
+ "@atlaskit/editor-plugin-guideline": "^9.0.0",
42
+ "@atlaskit/editor-plugin-interaction": "^18.0.0",
43
+ "@atlaskit/editor-plugin-limited-mode": "^6.0.0",
44
+ "@atlaskit/editor-plugin-selection": "^9.0.0",
45
+ "@atlaskit/editor-plugin-toolbar": "^6.0.0",
46
+ "@atlaskit/editor-plugin-user-intent": "^7.0.0",
47
+ "@atlaskit/editor-plugin-width": "^10.0.0",
48
48
  "@atlaskit/editor-prosemirror": "^7.3.0",
49
49
  "@atlaskit/editor-shared-styles": "^3.10.0",
50
50
  "@atlaskit/editor-tables": "^2.9.0",
51
- "@atlaskit/icon": "^34.1.0",
51
+ "@atlaskit/icon": "^34.2.0",
52
52
  "@atlaskit/insm": "^0.4.0",
53
- "@atlaskit/menu": "^8.4.0",
53
+ "@atlaskit/menu": "^8.5.0",
54
54
  "@atlaskit/platform-feature-flags": "^1.1.0",
55
55
  "@atlaskit/pragmatic-drag-and-drop": "^1.7.0",
56
56
  "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^2.1.0",
57
57
  "@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.1.0",
58
58
  "@atlaskit/primitives": "^19.0.0",
59
- "@atlaskit/tmp-editor-statsig": "^62.3.0",
60
- "@atlaskit/toggle": "^15.5.0",
59
+ "@atlaskit/tmp-editor-statsig": "^62.4.0",
60
+ "@atlaskit/toggle": "^15.6.0",
61
61
  "@atlaskit/tokens": "^13.0.0",
62
62
  "@atlaskit/tooltip": "^21.1.0",
63
63
  "@babel/runtime": "^7.0.0",
64
64
  "@emotion/react": "^11.7.1",
65
+ "bind-event-listener": "^3.0.0",
65
66
  "classnames": "^2.2.5",
66
67
  "lodash": "^4.17.21",
67
68
  "memoize-one": "^6.0.0",
@@ -69,7 +70,7 @@
69
70
  "uuid": "^3.1.0"
70
71
  },
71
72
  "peerDependencies": {
72
- "@atlaskit/editor-common": "^112.22.0",
73
+ "@atlaskit/editor-common": "^113.0.0",
73
74
  "react": "^18.2.0",
74
75
  "react-dom": "^18.2.0",
75
76
  "react-intl-next": "npm:react-intl@^5.18.1"