@atlaskit/editor-plugin-table 7.12.2 → 7.12.4

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 (34) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/nodeviews/TableComponent.js +3 -2
  3. package/dist/cjs/nodeviews/TableResizer.js +10 -4
  4. package/dist/cjs/plugin.js +15 -0
  5. package/dist/cjs/pm-plugins/table-width.js +16 -11
  6. package/dist/cjs/toolbar.js +9 -56
  7. package/dist/cjs/ui/FloatingToolbarLabel/FloatingToolbarLabel.js +28 -0
  8. package/dist/cjs/ui/TableFullWidthLabel/index.js +18 -5
  9. package/dist/es2019/nodeviews/TableComponent.js +3 -2
  10. package/dist/es2019/nodeviews/TableResizer.js +10 -4
  11. package/dist/es2019/plugin.js +15 -0
  12. package/dist/es2019/pm-plugins/table-width.js +16 -7
  13. package/dist/es2019/toolbar.js +0 -50
  14. package/dist/es2019/ui/FloatingToolbarLabel/FloatingToolbarLabel.js +23 -0
  15. package/dist/es2019/ui/TableFullWidthLabel/index.js +18 -5
  16. package/dist/esm/nodeviews/TableComponent.js +3 -2
  17. package/dist/esm/nodeviews/TableResizer.js +10 -4
  18. package/dist/esm/plugin.js +15 -0
  19. package/dist/esm/pm-plugins/table-width.js +14 -8
  20. package/dist/esm/toolbar.js +9 -56
  21. package/dist/esm/ui/FloatingToolbarLabel/FloatingToolbarLabel.js +21 -0
  22. package/dist/esm/ui/TableFullWidthLabel/index.js +18 -5
  23. package/dist/types/pm-plugins/table-width.d.ts +4 -0
  24. package/dist/types/ui/FloatingToolbarLabel/FloatingToolbarLabel.d.ts +12 -0
  25. package/dist/types-ts4.5/pm-plugins/table-width.d.ts +4 -0
  26. package/dist/types-ts4.5/ui/FloatingToolbarLabel/FloatingToolbarLabel.d.ts +15 -0
  27. package/package.json +2 -2
  28. package/src/nodeviews/TableComponent.tsx +11 -3
  29. package/src/nodeviews/TableResizer.tsx +18 -3
  30. package/src/plugin.tsx +23 -0
  31. package/src/pm-plugins/table-width.ts +15 -4
  32. package/src/toolbar.tsx +0 -57
  33. package/src/ui/FloatingToolbarLabel/FloatingToolbarLabel.tsx +36 -0
  34. package/src/ui/TableFullWidthLabel/index.tsx +19 -7
@@ -467,7 +467,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
467
467
  // Needed for undo / redo
468
468
  var isTableWidthChanged = tableNodeWidth !== this.tableNodeWidth;
469
469
  var isTableSquashed = tableRenderWidth < tableNodeWidth;
470
- var maybeScale = isTableSquashed || isTableWidthChanged || isTableResizedFullWidth;
470
+ var isNumberColumnChanged = tableNode.attrs.isNumberColumnEnabled !== this.node.attrs.isNumberColumnEnabled;
471
+ var maybeScale = isTableSquashed || isTableWidthChanged || isTableResizedFullWidth || isNumberColumnChanged;
471
472
  if (force || maybeScale) {
472
473
  var _this$containerWidth;
473
474
  var containerWidthValue = containerWidth.width;
@@ -476,7 +477,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
476
477
  var isTableResized = hasTableBeenResized(tableNode);
477
478
  var isColumnsDistributed = wasTableResized && !isTableResized;
478
479
  var isTableDisplayModeChanged = this.node.attrs.displayMode !== tableNode.attrs.displayMode;
479
- var shouldUpdateColgroup = isWidthChanged || isColumnsDistributed || isTableResizedFullWidth || isTableWidthChanged || isTableDisplayModeChanged;
480
+ var shouldUpdateColgroup = isWidthChanged || isColumnsDistributed || isTableResizedFullWidth || isTableWidthChanged || isTableDisplayModeChanged || isNumberColumnChanged;
480
481
  if (force || !isResizing && shouldUpdateColgroup) {
481
482
  var _this$props$options, _this$props$options2;
482
483
  var resizeState = getResizeState({
@@ -139,7 +139,9 @@ export var TableResizer = function TableResizer(_ref) {
139
139
  displayGapCursor(true);
140
140
  displayGuideline([]);
141
141
  _tr.setMeta(tableWidthPluginKey, {
142
- resizing: false
142
+ resizing: false,
143
+ tableLocalId: '',
144
+ tableRef: null
143
145
  });
144
146
  dispatch(_tr);
145
147
  }
@@ -152,7 +154,9 @@ export var TableResizer = function TableResizer(_ref) {
152
154
  tr = editorView.state.tr;
153
155
  displayGapCursor(false);
154
156
  tr.setMeta(tableWidthPluginKey, {
155
- resizing: true
157
+ resizing: true,
158
+ tableLocalId: node.attrs.localId,
159
+ tableRef: tableRef
156
160
  });
157
161
  tr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
158
162
  name: TABLE_OVERFLOW_CHANGE_TRIGGER.RESIZED
@@ -163,7 +167,7 @@ export var TableResizer = function TableResizer(_ref) {
163
167
  if (onResizeStart) {
164
168
  onResizeStart();
165
169
  }
166
- }, [startMeasure, editorView, displayGapCursor, isTableScalingEnabled, containerWidth, displayGuideline, onResizeStart]);
170
+ }, [startMeasure, editorView, displayGapCursor, node.attrs.localId, tableRef, isTableScalingEnabled, containerWidth, displayGuideline, onResizeStart]);
167
171
  var handleResize = useCallback(function (originalState, delta) {
168
172
  var _node$attrs$localId, _node$attrs;
169
173
  countFrames();
@@ -212,7 +216,9 @@ export var TableResizer = function TableResizer(_ref) {
212
216
  var currentTableNodeLocalId = (_node$attrs$localId2 = node === null || node === void 0 || (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.localId) !== null && _node$attrs$localId2 !== void 0 ? _node$attrs$localId2 : '';
213
217
  newWidth = widthToWidest && currentTableNodeLocalId && widthToWidest[currentTableNodeLocalId] ? TABLE_MAX_WIDTH : newWidth;
214
218
  var tr = state.tr.setMeta(tableWidthPluginKey, {
215
- resizing: false
219
+ resizing: false,
220
+ tableLocalId: '',
221
+ tableRef: null
216
222
  });
217
223
  var frameRateSamples = endMeasure();
218
224
  if (frameRateSamples.length > 0) {
@@ -8,6 +8,7 @@ import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/
8
8
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
9
9
  import { browser } from '@atlaskit/editor-common/utils';
10
10
  import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
11
+ import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
11
12
  import { tableEditing } from '@atlaskit/editor-tables/pm-plugins';
12
13
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
13
14
  import { insertTableWithSize } from './commands/insert';
@@ -34,6 +35,8 @@ import FloatingContextualMenu from './ui/FloatingContextualMenu';
34
35
  import FloatingDeleteButton from './ui/FloatingDeleteButton';
35
36
  import FloatingDragMenu from './ui/FloatingDragMenu';
36
37
  import FloatingInsertButton from './ui/FloatingInsertButton';
38
+ import { FloatingToolbarLabel } from './ui/FloatingToolbarLabel/FloatingToolbarLabel';
39
+ import { FullWidthDisplay } from './ui/TableFullWidthLabel';
37
40
  import { createTableWithWidth } from './utils';
38
41
  var defaultGetEditorFeatureFlags = function defaultGetEditorFeatureFlags() {
39
42
  return {};
@@ -312,7 +315,10 @@ var tablesPlugin = function tablesPlugin(_ref) {
312
315
  dragAndDropState = _ref17.dragAndDropState;
313
316
  var isColumnResizing = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
314
317
  var isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
318
+ var resizingTableLocalId = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableLocalId;
319
+ var resizingTableRef = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableRef;
315
320
  var isResizing = isColumnResizing || isTableResizing;
321
+ var widthToWidest = tablePluginState === null || tablePluginState === void 0 ? void 0 : tablePluginState.widthToWidest;
316
322
  var _ref18 = tablePluginState,
317
323
  tableNode = _ref18.tableNode,
318
324
  tablePos = _ref18.tablePos,
@@ -390,6 +396,15 @@ var tablesPlugin = function tablesPlugin(_ref) {
390
396
  stickyHeaders: stickyHeader,
391
397
  isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
392
398
  editorAnalyticsAPI: editorAnalyticsAPI
399
+ }), (options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) && isTableResizing && widthToWidest && resizingTableLocalId && resizingTableRef && widthToWidest[resizingTableLocalId] && /*#__PURE__*/React.createElement(FloatingToolbarLabel, {
400
+ target: resizingTableRef,
401
+ content: /*#__PURE__*/React.createElement(FullWidthDisplay, null),
402
+ alignX: 'center',
403
+ alignY: 'bottom',
404
+ stick: true,
405
+ forcePlacement: true,
406
+ zIndex: akEditorFloatingPanelZIndex,
407
+ offset: [0, 10]
393
408
  }));
394
409
  }
395
410
  }));
@@ -1,5 +1,5 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
1
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  var _excluded = ["width"];
4
4
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
5
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -24,17 +24,23 @@ var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullW
24
24
  state: {
25
25
  init: function init() {
26
26
  return {
27
- resizing: false
27
+ resizing: false,
28
+ tableLocalId: '',
29
+ tableRef: null
28
30
  };
29
31
  },
30
32
  apply: function apply(tr, pluginState) {
31
33
  var meta = tr.getMeta(pluginKey);
32
- if (meta && meta.resizing !== pluginState.resizing) {
33
- var newState = {
34
- resizing: meta.resizing
35
- };
36
- dispatch(pluginKey, newState);
37
- return newState;
34
+ if (meta) {
35
+ var keys = Object.keys(meta);
36
+ var changed = keys.some(function (key) {
37
+ return pluginState[key] !== meta[key];
38
+ });
39
+ if (changed) {
40
+ var newState = _objectSpread(_objectSpread({}, pluginState), meta);
41
+ dispatch(pluginKey, newState);
42
+ return newState;
43
+ }
38
44
  }
39
45
  return pluginState;
40
46
  }
@@ -26,7 +26,6 @@ import { pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
26
26
  import { canMergeCells } from './transforms';
27
27
  import { TableCssClassName } from './types';
28
28
  import { DisplayModeIcon } from './ui/icons';
29
- import { FullWidthDisplay } from './ui/TableFullWidthLabel';
30
29
  import { getMergedCellsPositions, getSelectedColumnIndexes, getSelectedRowIndexes, isTableNested } from './utils';
31
30
  export var getToolbarMenuConfig = function getToolbarMenuConfig(config, state, _ref, editorAnalyticsAPI) {
32
31
  var formatMessage = _ref.formatMessage;
@@ -305,7 +304,6 @@ export var getClosestSelectionOrTableRect = function getClosestSelectionOrTableR
305
304
  export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth, editorAnalyticsAPI, getEditorFeatureFlags, getEditorView, options) {
306
305
  return function (config) {
307
306
  return function (state, intl) {
308
- var _tableObject$node$att, _tableObject$node;
309
307
  var tableObject = findTable(state.selection);
310
308
  var pluginState = getPluginState(state);
311
309
  var resizeState = tableResizingPluginKey.getState(state);
@@ -313,53 +311,8 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
313
311
 
314
312
  // We don't want to show floating toolbar while resizing the table
315
313
  var isWidthResizing = tableWidthState === null || tableWidthState === void 0 ? void 0 : tableWidthState.resizing;
316
- var widthToWidest = pluginState.widthToWidest;
317
- var currentTableNodeLocalId = (_tableObject$node$att = tableObject === null || tableObject === void 0 || (_tableObject$node = tableObject.node) === null || _tableObject$node === void 0 || (_tableObject$node = _tableObject$node.attrs) === null || _tableObject$node === void 0 ? void 0 : _tableObject$node.localId) !== null && _tableObject$node$att !== void 0 ? _tableObject$node$att : '';
318
- if (options !== null && options !== void 0 && options.isTableScalingEnabled && isWidthResizing && widthToWidest && currentTableNodeLocalId && widthToWidest[currentTableNodeLocalId]) {
319
- var _getEditorFeatureFlag = getEditorFeatureFlags(),
320
- stickyScrollbar = _getEditorFeatureFlag.stickyScrollbar;
321
- var nodeType = state.schema.nodes.table;
322
- var getDomRef = function getDomRef(editorView) {
323
- var element;
324
- var domAtPos = editorView.domAtPos.bind(editorView);
325
- var parent = findParentDomRefOfType(nodeType, domAtPos)(state.selection);
326
- if (parent) {
327
- var tableRef = parent.querySelector('table') || undefined;
328
- if (tableRef) {
329
- element = closestElement(tableRef, ".".concat(TableCssClassName.TABLE_NODE_WRAPPER)) || undefined;
330
- }
331
- }
332
- return element;
333
- };
334
- var fullWidthLabel = {
335
- id: 'editor.table.fullWidthLabel',
336
- type: 'custom',
337
- fallback: [],
338
- render: function render() {
339
- return jsx(FullWidthDisplay, {
340
- key: 'full-width-label'
341
- });
342
- }
343
- };
344
- return {
345
- title: 'Table floating label',
346
- getDomRef: getDomRef,
347
- nodeType: nodeType,
348
- key: 'full-width-label',
349
- offset: [0, 18],
350
- absoluteOffset: stickyScrollbar ? {
351
- top: -6
352
- } : {
353
- top: 0
354
- },
355
- zIndex: akEditorFloatingPanelZIndex + 1,
356
- // Place the context menu slightly above the others
357
- items: [fullWidthLabel],
358
- scrollable: true
359
- };
360
- }
361
314
  if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
362
- var _nodeType = state.schema.nodes.table;
315
+ var nodeType = state.schema.nodes.table;
363
316
  var menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
364
317
  var cellItems;
365
318
  cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled);
@@ -391,10 +344,10 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
391
344
  };
392
345
  };
393
346
  }
394
- var _getDomRef = function _getDomRef(editorView) {
347
+ var getDomRef = function getDomRef(editorView) {
395
348
  var element;
396
349
  var domAtPos = editorView.domAtPos.bind(editorView);
397
- var parent = findParentDomRefOfType(_nodeType, domAtPos)(state.selection);
350
+ var parent = findParentDomRefOfType(nodeType, domAtPos)(state.selection);
398
351
  if (parent) {
399
352
  var tableRef = parent.querySelector('table') || undefined;
400
353
  if (tableRef) {
@@ -403,14 +356,14 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
403
356
  }
404
357
  return element;
405
358
  };
406
- var _getEditorFeatureFlag2 = getEditorFeatureFlags(),
407
- _stickyScrollbar = _getEditorFeatureFlag2.stickyScrollbar;
359
+ var _getEditorFeatureFlag = getEditorFeatureFlags(),
360
+ stickyScrollbar = _getEditorFeatureFlag.stickyScrollbar;
408
361
  return {
409
362
  title: 'Table floating controls',
410
- getDomRef: _getDomRef,
411
- nodeType: _nodeType,
363
+ getDomRef: getDomRef,
364
+ nodeType: nodeType,
412
365
  offset: [0, 18],
413
- absoluteOffset: _stickyScrollbar ? {
366
+ absoluteOffset: stickyScrollbar ? {
414
367
  top: -6
415
368
  } : {
416
369
  top: 0
@@ -425,7 +378,7 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
425
378
  items: [{
426
379
  state: state,
427
380
  formatMessage: intl.formatMessage,
428
- nodeType: _nodeType,
381
+ nodeType: nodeType,
429
382
  onMouseEnter: hoverTable(false, true),
430
383
  onMouseLeave: clearHoverSelection(),
431
384
  onFocus: hoverTable(false, true),
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import { Popup } from '@atlaskit/editor-common/ui';
3
+ export var FloatingToolbarLabel = /*#__PURE__*/React.memo(function (props) {
4
+ var target = props.target,
5
+ content = props.content,
6
+ alignX = props.alignX,
7
+ alignY = props.alignY,
8
+ zIndex = props.zIndex,
9
+ forcePlacement = props.forcePlacement,
10
+ stick = props.stick,
11
+ offset = props.offset;
12
+ return /*#__PURE__*/React.createElement(Popup, {
13
+ target: target,
14
+ alignX: alignX,
15
+ alignY: alignY,
16
+ zIndex: zIndex,
17
+ stick: stick,
18
+ forcePlacement: forcePlacement,
19
+ offset: offset
20
+ }, content);
21
+ });
@@ -2,17 +2,30 @@ import React from 'react';
2
2
  import { useIntl } from 'react-intl-next';
3
3
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
4
4
  import { Box, Inline, xcss } from '@atlaskit/primitives';
5
- var tableFullWidthLabelStyles = xcss({
6
- minWidth: '120px',
7
- height: "var(--ds-space-300, 24px)",
5
+ var tableFullWidthLabelWrapperStyles = xcss({
6
+ height: "var(--ds-space-400, 32px)",
8
7
  display: 'flex',
9
- justifyContent: 'center',
8
+ backgroundColor: 'elevation.surface.overlay',
9
+ borderRadius: 'border.radius',
10
+ boxShadow: 'elevation.shadow.overlay',
11
+ lineHeight: 1,
12
+ boxSizing: 'border-box',
10
13
  alignItems: 'center'
11
14
  });
15
+ var tableFullWidthLabelStyles = xcss({
16
+ marginLeft: 'space.100',
17
+ marginRight: 'space.100',
18
+ paddingLeft: 'space.075',
19
+ paddingRight: 'space.075',
20
+ paddingTop: 'space.050',
21
+ paddingBottom: 'space.050'
22
+ });
12
23
  export var FullWidthDisplay = function FullWidthDisplay() {
13
24
  var _useIntl = useIntl(),
14
25
  formatMessage = _useIntl.formatMessage;
15
26
  return /*#__PURE__*/React.createElement(Box, {
27
+ xcss: tableFullWidthLabelWrapperStyles
28
+ }, /*#__PURE__*/React.createElement(Inline, {
16
29
  xcss: tableFullWidthLabelStyles
17
- }, /*#__PURE__*/React.createElement(Inline, null, formatMessage(messages.fullWidthLabel)));
30
+ }, formatMessage(messages.fullWidthLabel)));
18
31
  };
@@ -9,9 +9,13 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
9
9
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
10
10
  type TableWidthPluginState = {
11
11
  resizing: boolean;
12
+ tableLocalId: string;
13
+ tableRef: HTMLTableElement | null;
12
14
  };
13
15
  export declare const pluginKey: PluginKey<TableWidthPluginState>;
14
16
  declare const createPlugin: (dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, fullWidthEnabled: boolean, isTableScalingEnabled: boolean) => SafePlugin<{
15
17
  resizing: boolean;
18
+ tableLocalId: string;
19
+ tableRef: null;
16
20
  }>;
17
21
  export { createPlugin };
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ export interface Props {
3
+ target: HTMLElement;
4
+ content: React.ReactNode;
5
+ alignX?: 'left' | 'center' | 'right';
6
+ alignY?: "top" | "bottom" | "start";
7
+ zIndex?: number;
8
+ forcePlacement?: boolean;
9
+ stick?: boolean;
10
+ offset?: [number, number];
11
+ }
12
+ export declare const FloatingToolbarLabel: React.MemoExoticComponent<(props: Props) => JSX.Element>;
@@ -9,9 +9,13 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
9
9
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
10
10
  type TableWidthPluginState = {
11
11
  resizing: boolean;
12
+ tableLocalId: string;
13
+ tableRef: HTMLTableElement | null;
12
14
  };
13
15
  export declare const pluginKey: PluginKey<TableWidthPluginState>;
14
16
  declare const createPlugin: (dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, fullWidthEnabled: boolean, isTableScalingEnabled: boolean) => SafePlugin<{
15
17
  resizing: boolean;
18
+ tableLocalId: string;
19
+ tableRef: null;
16
20
  }>;
17
21
  export { createPlugin };
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ export interface Props {
3
+ target: HTMLElement;
4
+ content: React.ReactNode;
5
+ alignX?: 'left' | 'center' | 'right';
6
+ alignY?: "top" | "bottom" | "start";
7
+ zIndex?: number;
8
+ forcePlacement?: boolean;
9
+ stick?: boolean;
10
+ offset?: [
11
+ number,
12
+ number
13
+ ];
14
+ }
15
+ export declare const FloatingToolbarLabel: React.MemoExoticComponent<(props: Props) => JSX.Element>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "7.12.2",
3
+ "version": "7.12.4",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -30,7 +30,7 @@
30
30
  "dependencies": {
31
31
  "@atlaskit/adf-schema": "^35.12.2",
32
32
  "@atlaskit/custom-steps": "^0.1.0",
33
- "@atlaskit/editor-common": "^79.1.0",
33
+ "@atlaskit/editor-common": "^79.2.0",
34
34
  "@atlaskit/editor-palette": "1.6.0",
35
35
  "@atlaskit/editor-plugin-accessibility-utils": "^1.1.0",
36
36
  "@atlaskit/editor-plugin-analytics": "^1.1.0",
@@ -384,9 +384,16 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
384
384
  // Needed for undo / redo
385
385
  const isTableWidthChanged = tableNodeWidth !== this.tableNodeWidth;
386
386
  const isTableSquashed = tableRenderWidth < tableNodeWidth;
387
+ const isNumberColumnChanged =
388
+ tableNode.attrs.isNumberColumnEnabled !==
389
+ this.node.attrs.isNumberColumnEnabled;
387
390
 
388
391
  const maybeScale =
389
- isTableSquashed || isTableWidthChanged || isTableResizedFullWidth;
392
+ isTableSquashed ||
393
+ isTableWidthChanged ||
394
+ isTableResizedFullWidth ||
395
+ isNumberColumnChanged;
396
+
390
397
  if (force || maybeScale) {
391
398
  const { width: containerWidthValue } = containerWidth;
392
399
  const isWidthChanged = this.containerWidth?.width !== containerWidthValue;
@@ -401,7 +408,8 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
401
408
  isColumnsDistributed ||
402
409
  isTableResizedFullWidth ||
403
410
  isTableWidthChanged ||
404
- isTableDisplayModeChanged;
411
+ isTableDisplayModeChanged ||
412
+ isNumberColumnChanged;
405
413
 
406
414
  if (force || (!isResizing && shouldUpdateColgroup)) {
407
415
  const resizeState = getResizeState({
@@ -758,7 +766,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
758
766
 
759
767
  const shadowStyle = memoizeOne(
760
768
  (visible) =>
761
- ({ visibility: visible ? 'visible' : 'hidden' } as CSSProperties),
769
+ ({ visibility: visible ? 'visible' : 'hidden' }) as CSSProperties,
762
770
  );
763
771
 
764
772
  /**
@@ -241,7 +241,11 @@ export const TableResizer = ({
241
241
  } = editorView;
242
242
  displayGapCursor(true);
243
243
  displayGuideline([]);
244
- tr.setMeta(tableWidthPluginKey, { resizing: false });
244
+ tr.setMeta(tableWidthPluginKey, {
245
+ resizing: false,
246
+ tableLocalId: '',
247
+ tableRef: null,
248
+ });
245
249
  dispatch(tr);
246
250
  }
247
251
  };
@@ -255,7 +259,12 @@ export const TableResizer = ({
255
259
  state: { tr },
256
260
  } = editorView;
257
261
  displayGapCursor(false);
258
- tr.setMeta(tableWidthPluginKey, { resizing: true });
262
+
263
+ tr.setMeta(tableWidthPluginKey, {
264
+ resizing: true,
265
+ tableLocalId: node.attrs.localId,
266
+ tableRef: tableRef,
267
+ });
259
268
  tr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
260
269
  name: TABLE_OVERFLOW_CHANGE_TRIGGER.RESIZED,
261
270
  });
@@ -277,6 +286,8 @@ export const TableResizer = ({
277
286
  startMeasure,
278
287
  editorView,
279
288
  displayGapCursor,
289
+ node.attrs.localId,
290
+ tableRef,
280
291
  isTableScalingEnabled,
281
292
  containerWidth,
282
293
  displayGuideline,
@@ -374,7 +385,11 @@ export const TableResizer = ({
374
385
  ? TABLE_MAX_WIDTH
375
386
  : newWidth;
376
387
 
377
- let tr = state.tr.setMeta(tableWidthPluginKey, { resizing: false });
388
+ let tr = state.tr.setMeta(tableWidthPluginKey, {
389
+ resizing: false,
390
+ tableLocalId: '',
391
+ tableRef: null,
392
+ });
378
393
  const frameRateSamples = endMeasure();
379
394
 
380
395
  if (frameRateSamples.length > 0) {
package/src/plugin.tsx CHANGED
@@ -41,6 +41,7 @@ import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
41
41
  import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
42
42
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
43
43
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
44
+ import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
44
45
  import { tableEditing } from '@atlaskit/editor-tables/pm-plugins';
45
46
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
46
47
 
@@ -87,6 +88,8 @@ import FloatingContextualMenu from './ui/FloatingContextualMenu';
87
88
  import FloatingDeleteButton from './ui/FloatingDeleteButton';
88
89
  import FloatingDragMenu from './ui/FloatingDragMenu';
89
90
  import FloatingInsertButton from './ui/FloatingInsertButton';
91
+ import { FloatingToolbarLabel } from './ui/FloatingToolbarLabel/FloatingToolbarLabel';
92
+ import { FullWidthDisplay } from './ui/TableFullWidthLabel';
90
93
  import { createTableWithWidth } from './utils';
91
94
 
92
95
  export interface TablePluginOptions {
@@ -480,7 +483,10 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
480
483
  }) => {
481
484
  const isColumnResizing = resizingPluginState?.dragging;
482
485
  const isTableResizing = tableWidthPluginState?.resizing;
486
+ const resizingTableLocalId = tableWidthPluginState?.tableLocalId;
487
+ const resizingTableRef = tableWidthPluginState?.tableRef;
483
488
  const isResizing = isColumnResizing || isTableResizing;
489
+ const widthToWidest = tablePluginState?.widthToWidest;
484
490
 
485
491
  const {
486
492
  tableNode,
@@ -593,6 +599,23 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
593
599
  editorAnalyticsAPI={editorAnalyticsAPI}
594
600
  />
595
601
  )}
602
+ {options?.isTableScalingEnabled &&
603
+ isTableResizing &&
604
+ widthToWidest &&
605
+ resizingTableLocalId &&
606
+ resizingTableRef &&
607
+ widthToWidest[resizingTableLocalId] && (
608
+ <FloatingToolbarLabel
609
+ target={resizingTableRef}
610
+ content={<FullWidthDisplay />}
611
+ alignX={'center'}
612
+ alignY={'bottom'}
613
+ stick={true}
614
+ forcePlacement={true}
615
+ zIndex={akEditorFloatingPanelZIndex}
616
+ offset={[0, 10]}
617
+ />
618
+ )}
596
619
  </>
597
620
  );
598
621
  }}
@@ -33,6 +33,8 @@ type __ReplaceStep = ReplaceStep & {
33
33
 
34
34
  type TableWidthPluginState = {
35
35
  resizing: boolean;
36
+ tableLocalId: string;
37
+ tableRef: HTMLTableElement | null;
36
38
  };
37
39
 
38
40
  export const pluginKey = new PluginKey<TableWidthPluginState>(
@@ -51,15 +53,24 @@ const createPlugin = (
51
53
  init() {
52
54
  return {
53
55
  resizing: false,
56
+ tableLocalId: '',
57
+ tableRef: null,
54
58
  };
55
59
  },
56
60
  apply(tr, pluginState) {
57
61
  const meta = tr.getMeta(pluginKey);
58
- if (meta && meta.resizing !== pluginState.resizing) {
59
- const newState = { resizing: meta.resizing };
62
+ if (meta) {
63
+ const keys = Object.keys(meta) as Array<keyof TableWidthPluginState>;
64
+ const changed = keys.some((key) => {
65
+ return pluginState[key] !== meta[key];
66
+ });
67
+
68
+ if (changed) {
69
+ const newState = { ...pluginState, ...meta };
60
70
 
61
- dispatch(pluginKey, newState);
62
- return newState;
71
+ dispatch(pluginKey, newState);
72
+ return newState;
73
+ }
63
74
  }
64
75
 
65
76
  return pluginState;
package/src/toolbar.tsx CHANGED
@@ -95,7 +95,6 @@ import type {
95
95
  } from './types';
96
96
  import { TableCssClassName } from './types';
97
97
  import { DisplayModeIcon } from './ui/icons';
98
- import { FullWidthDisplay } from './ui/TableFullWidthLabel';
99
98
  import {
100
99
  getMergedCellsPositions,
101
100
  getSelectedColumnIndexes,
@@ -467,62 +466,6 @@ export const getToolbarConfig =
467
466
  // We don't want to show floating toolbar while resizing the table
468
467
  const isWidthResizing = tableWidthState?.resizing;
469
468
 
470
- const { widthToWidest } = pluginState;
471
- const currentTableNodeLocalId = tableObject?.node?.attrs?.localId ?? '';
472
-
473
- if (
474
- options?.isTableScalingEnabled &&
475
- isWidthResizing &&
476
- widthToWidest &&
477
- currentTableNodeLocalId &&
478
- widthToWidest[currentTableNodeLocalId]
479
- ) {
480
- const { stickyScrollbar } = getEditorFeatureFlags();
481
-
482
- const nodeType = state.schema.nodes.table;
483
- const getDomRef = (editorView: EditorView) => {
484
- let element: HTMLElement | undefined;
485
- const domAtPos = editorView.domAtPos.bind(editorView);
486
- const parent = findParentDomRefOfType(
487
- nodeType,
488
- domAtPos,
489
- )(state.selection);
490
- if (parent) {
491
- const tableRef =
492
- (parent as HTMLElement).querySelector<HTMLTableElement>('table') ||
493
- undefined;
494
- if (tableRef) {
495
- element =
496
- closestElement(
497
- tableRef,
498
- `.${TableCssClassName.TABLE_NODE_WRAPPER}`,
499
- ) || undefined;
500
- }
501
- }
502
- return element;
503
- };
504
- const fullWidthLabel = {
505
- id: 'editor.table.fullWidthLabel',
506
- type: 'custom',
507
- fallback: [],
508
- render: () => {
509
- return <FullWidthDisplay key={'full-width-label'} />;
510
- },
511
- } as FloatingToolbarItem<Command>;
512
-
513
- return {
514
- title: 'Table floating label',
515
- getDomRef,
516
- nodeType,
517
- key: 'full-width-label',
518
- offset: [0, 18],
519
- absoluteOffset: stickyScrollbar ? { top: -6 } : { top: 0 },
520
- zIndex: akEditorFloatingPanelZIndex + 1, // Place the context menu slightly above the others
521
- items: [fullWidthLabel],
522
- scrollable: true,
523
- };
524
- }
525
-
526
469
  if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
527
470
  const nodeType = state.schema.nodes.table;
528
471
  const menu = getToolbarMenuConfig(