@atlaskit/editor-plugin-table 2.9.0 → 2.9.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 2.9.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`84cf99bc0f0`](https://bitbucket.org/atlassian/atlassian-frontend/commits/84cf99bc0f0) - ED-19153:Update table container width to be consistent with table resizer.
8
+
3
9
  ## 2.9.0
4
10
 
5
11
  ### Minor Changes
@@ -58,6 +58,14 @@ var ResizableTableContainer = function ResizableTableContainer(_ref2) {
58
58
  return;
59
59
  }
60
60
  var marginLeft = getMarginLeft(lineLength, width);
61
+
62
+ // make sure during resizing
63
+ // the pm-table-resizer-container width is the same as its child div resizer-item
64
+ // otherwise when resize table from wider to narrower , pm-table-resizer-container stays wider
65
+ // and cause the fabric-editor-popup-scroll-parent to overflow
66
+ if (containerRef.current.style.width !== "".concat(width, "px")) {
67
+ containerRef.current.style.width = "".concat(width, "px");
68
+ }
61
69
  if (marginLeftRef.current !== marginLeft) {
62
70
  marginLeftRef.current = marginLeft;
63
71
  if (Number.isFinite(marginLeft)) {
@@ -91,6 +99,7 @@ var ResizableTableContainer = function ResizableTableContainer(_ref2) {
91
99
  }, /*#__PURE__*/_react.default.createElement(_TableResizer.TableResizer, {
92
100
  width: width,
93
101
  maxWidth: maxResizerWidth,
102
+ containerWidth: containerWidth,
94
103
  updateWidth: updateWidth,
95
104
  editorView: editorView,
96
105
  getPos: getPos,
@@ -54,11 +54,24 @@ var getResizerMinWidth = function getResizerMinWidth(node) {
54
54
  // the table can't scale past its min-width, so instead restrict table container min width to avoid that situation
55
55
  return minColumnWidth + 1;
56
56
  };
57
+
58
+ /**
59
+ * When guidelines are outside the viewport, filter them out, do not show
60
+ * So the guideline container won't make the fabric-editor-popup-scroll-parent overflow
61
+ * @param guidelines
62
+ * @param containerWidth editorWidth
63
+ */
64
+ var getVisibleGuidelines = function getVisibleGuidelines(guidelines, containerWidth) {
65
+ return guidelines.filter(function (guideline) {
66
+ return guideline.position && guideline.position.x !== undefined && typeof guideline.position.x === 'number' && Math.abs(guideline.position.x * 2) < containerWidth;
67
+ });
68
+ };
57
69
  var TableResizer = function TableResizer(_ref) {
58
70
  var _findTable, _editorView$state;
59
71
  var children = _ref.children,
60
72
  width = _ref.width,
61
73
  maxWidth = _ref.maxWidth,
74
+ containerWidth = _ref.containerWidth,
62
75
  updateWidth = _ref.updateWidth,
63
76
  editorView = _ref.editorView,
64
77
  getPos = _ref.getPos,
@@ -82,9 +95,10 @@ var TableResizer = function TableResizer(_ref) {
82
95
  keys = _ref2.keys;
83
96
  if (gap !== currentGap.current) {
84
97
  currentGap.current = gap;
85
- displayGuideline((0, _guideline.getGuidelinesWithHighlights)(gap, _consts.TABLE_SNAP_GAP, keys, _guidelines.defaultGuidelines));
98
+ var visibleGuidelines = getVisibleGuidelines(_guidelines.defaultGuidelines, containerWidth);
99
+ displayGuideline((0, _guideline.getGuidelinesWithHighlights)(gap, _consts.TABLE_SNAP_GAP, keys, visibleGuidelines));
86
100
  }
87
- }, [displayGuideline]);
101
+ }, [displayGuideline, containerWidth]);
88
102
  var guidelineSnaps = (0, _react.useMemo)(function () {
89
103
  return snappingEnabled ? {
90
104
  x: _snapping.defaultSnappingWidths
@@ -97,8 +111,9 @@ var TableResizer = function TableResizer(_ref) {
97
111
  dispatch(tr.setMeta(_tableWidth.pluginKey, {
98
112
  resizing: true
99
113
  }));
100
- setSnappingEnabled(displayGuideline(_guidelines.defaultGuidelines));
101
- }, [displayGuideline, editorView, startMeasure]);
114
+ var visibleGuidelines = getVisibleGuidelines(_guidelines.defaultGuidelines, containerWidth);
115
+ setSnappingEnabled(displayGuideline(visibleGuidelines));
116
+ }, [displayGuideline, containerWidth, editorView, startMeasure]);
102
117
  var handleResize = (0, _react.useCallback)(function (originalState, delta) {
103
118
  countFrames();
104
119
  var newWidth = originalState.width + delta.width;
@@ -49,6 +49,14 @@ export const ResizableTableContainer = ({
49
49
  return;
50
50
  }
51
51
  const marginLeft = getMarginLeft(lineLength, width);
52
+
53
+ // make sure during resizing
54
+ // the pm-table-resizer-container width is the same as its child div resizer-item
55
+ // otherwise when resize table from wider to narrower , pm-table-resizer-container stays wider
56
+ // and cause the fabric-editor-popup-scroll-parent to overflow
57
+ if (containerRef.current.style.width !== `${width}px`) {
58
+ containerRef.current.style.width = `${width}px`;
59
+ }
52
60
  if (marginLeftRef.current !== marginLeft) {
53
61
  marginLeftRef.current = marginLeft;
54
62
  if (Number.isFinite(marginLeft)) {
@@ -82,6 +90,7 @@ export const ResizableTableContainer = ({
82
90
  }, /*#__PURE__*/React.createElement(TableResizer, {
83
91
  width: width,
84
92
  maxWidth: maxResizerWidth,
93
+ containerWidth: containerWidth,
85
94
  updateWidth: updateWidth,
86
95
  editorView: editorView,
87
96
  getPos: getPos,
@@ -40,10 +40,23 @@ const getResizerMinWidth = node => {
40
40
  // the table can't scale past its min-width, so instead restrict table container min width to avoid that situation
41
41
  return minColumnWidth + 1;
42
42
  };
43
+
44
+ /**
45
+ * When guidelines are outside the viewport, filter them out, do not show
46
+ * So the guideline container won't make the fabric-editor-popup-scroll-parent overflow
47
+ * @param guidelines
48
+ * @param containerWidth editorWidth
49
+ */
50
+ const getVisibleGuidelines = (guidelines, containerWidth) => {
51
+ return guidelines.filter(guideline => {
52
+ return guideline.position && guideline.position.x !== undefined && typeof guideline.position.x === 'number' && Math.abs(guideline.position.x * 2) < containerWidth;
53
+ });
54
+ };
43
55
  export const TableResizer = ({
44
56
  children,
45
57
  width,
46
58
  maxWidth,
59
+ containerWidth,
47
60
  updateWidth,
48
61
  editorView,
49
62
  getPos,
@@ -68,9 +81,10 @@ export const TableResizer = ({
68
81
  }) => {
69
82
  if (gap !== currentGap.current) {
70
83
  currentGap.current = gap;
71
- displayGuideline(getGuidelinesWithHighlights(gap, TABLE_SNAP_GAP, keys, defaultGuidelines));
84
+ const visibleGuidelines = getVisibleGuidelines(defaultGuidelines, containerWidth);
85
+ displayGuideline(getGuidelinesWithHighlights(gap, TABLE_SNAP_GAP, keys, visibleGuidelines));
72
86
  }
73
- }, [displayGuideline]);
87
+ }, [displayGuideline, containerWidth]);
74
88
  const guidelineSnaps = useMemo(() => snappingEnabled ? {
75
89
  x: defaultSnappingWidths
76
90
  } : undefined, [snappingEnabled]);
@@ -85,8 +99,9 @@ export const TableResizer = ({
85
99
  dispatch(tr.setMeta(tableWidthPluginKey, {
86
100
  resizing: true
87
101
  }));
88
- setSnappingEnabled(displayGuideline(defaultGuidelines));
89
- }, [displayGuideline, editorView, startMeasure]);
102
+ const visibleGuidelines = getVisibleGuidelines(defaultGuidelines, containerWidth);
103
+ setSnappingEnabled(displayGuideline(visibleGuidelines));
104
+ }, [displayGuideline, containerWidth, editorView, startMeasure]);
90
105
  const handleResize = useCallback((originalState, delta) => {
91
106
  countFrames();
92
107
  const newWidth = originalState.width + delta.width;
@@ -47,6 +47,14 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
47
47
  return;
48
48
  }
49
49
  var marginLeft = getMarginLeft(lineLength, width);
50
+
51
+ // make sure during resizing
52
+ // the pm-table-resizer-container width is the same as its child div resizer-item
53
+ // otherwise when resize table from wider to narrower , pm-table-resizer-container stays wider
54
+ // and cause the fabric-editor-popup-scroll-parent to overflow
55
+ if (containerRef.current.style.width !== "".concat(width, "px")) {
56
+ containerRef.current.style.width = "".concat(width, "px");
57
+ }
50
58
  if (marginLeftRef.current !== marginLeft) {
51
59
  marginLeftRef.current = marginLeft;
52
60
  if (Number.isFinite(marginLeft)) {
@@ -80,6 +88,7 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
80
88
  }, /*#__PURE__*/React.createElement(TableResizer, {
81
89
  width: width,
82
90
  maxWidth: maxResizerWidth,
91
+ containerWidth: containerWidth,
83
92
  updateWidth: updateWidth,
84
93
  editorView: editorView,
85
94
  getPos: getPos,
@@ -44,11 +44,24 @@ var getResizerMinWidth = function getResizerMinWidth(node) {
44
44
  // the table can't scale past its min-width, so instead restrict table container min width to avoid that situation
45
45
  return minColumnWidth + 1;
46
46
  };
47
+
48
+ /**
49
+ * When guidelines are outside the viewport, filter them out, do not show
50
+ * So the guideline container won't make the fabric-editor-popup-scroll-parent overflow
51
+ * @param guidelines
52
+ * @param containerWidth editorWidth
53
+ */
54
+ var getVisibleGuidelines = function getVisibleGuidelines(guidelines, containerWidth) {
55
+ return guidelines.filter(function (guideline) {
56
+ return guideline.position && guideline.position.x !== undefined && typeof guideline.position.x === 'number' && Math.abs(guideline.position.x * 2) < containerWidth;
57
+ });
58
+ };
47
59
  export var TableResizer = function TableResizer(_ref) {
48
60
  var _findTable, _editorView$state;
49
61
  var children = _ref.children,
50
62
  width = _ref.width,
51
63
  maxWidth = _ref.maxWidth,
64
+ containerWidth = _ref.containerWidth,
52
65
  updateWidth = _ref.updateWidth,
53
66
  editorView = _ref.editorView,
54
67
  getPos = _ref.getPos,
@@ -72,9 +85,10 @@ export var TableResizer = function TableResizer(_ref) {
72
85
  keys = _ref2.keys;
73
86
  if (gap !== currentGap.current) {
74
87
  currentGap.current = gap;
75
- displayGuideline(getGuidelinesWithHighlights(gap, TABLE_SNAP_GAP, keys, defaultGuidelines));
88
+ var visibleGuidelines = getVisibleGuidelines(defaultGuidelines, containerWidth);
89
+ displayGuideline(getGuidelinesWithHighlights(gap, TABLE_SNAP_GAP, keys, visibleGuidelines));
76
90
  }
77
- }, [displayGuideline]);
91
+ }, [displayGuideline, containerWidth]);
78
92
  var guidelineSnaps = useMemo(function () {
79
93
  return snappingEnabled ? {
80
94
  x: defaultSnappingWidths
@@ -87,8 +101,9 @@ export var TableResizer = function TableResizer(_ref) {
87
101
  dispatch(tr.setMeta(tableWidthPluginKey, {
88
102
  resizing: true
89
103
  }));
90
- setSnappingEnabled(displayGuideline(defaultGuidelines));
91
- }, [displayGuideline, editorView, startMeasure]);
104
+ var visibleGuidelines = getVisibleGuidelines(defaultGuidelines, containerWidth);
105
+ setSnappingEnabled(displayGuideline(visibleGuidelines));
106
+ }, [displayGuideline, containerWidth, editorView, startMeasure]);
92
107
  var handleResize = useCallback(function (originalState, delta) {
93
108
  countFrames();
94
109
  var newWidth = originalState.width + delta.width;
@@ -1,8 +1,9 @@
1
- import React, { PropsWithChildren } from 'react';
2
- import { EditorContainerWidth } from '@atlaskit/editor-common/types';
3
- import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
- import { EditorView } from '@atlaskit/editor-prosemirror/view';
5
- import { PluginInjectionAPI } from '../types';
1
+ import type { PropsWithChildren } from 'react';
2
+ import React from 'react';
3
+ import type { EditorContainerWidth } from '@atlaskit/editor-common/types';
4
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
5
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
6
+ import type { PluginInjectionAPI } from '../types';
6
7
  type InnerContainerProps = {
7
8
  className: string;
8
9
  style?: {
@@ -7,6 +7,7 @@ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
7
  interface TableResizerProps {
8
8
  width: number;
9
9
  maxWidth: number;
10
+ containerWidth: number;
10
11
  updateWidth: (width: number) => void;
11
12
  editorView: EditorView;
12
13
  getPos: () => number | undefined;
@@ -15,5 +16,5 @@ interface TableResizerProps {
15
16
  displayGuideline: (guideline: GuidelineConfig[]) => boolean;
16
17
  attachAnalyticsEvent: (payload: TableEventPayload) => ((tr: Transaction) => boolean) | undefined;
17
18
  }
18
- export declare const TableResizer: ({ children, width, maxWidth, updateWidth, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, }: PropsWithChildren<TableResizerProps>) => JSX.Element;
19
+ export declare const TableResizer: ({ children, width, maxWidth, containerWidth, updateWidth, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, }: PropsWithChildren<TableResizerProps>) => JSX.Element;
19
20
  export {};
@@ -1,8 +1,9 @@
1
- import React, { PropsWithChildren } from 'react';
2
- import { EditorContainerWidth } from '@atlaskit/editor-common/types';
3
- import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
- import { EditorView } from '@atlaskit/editor-prosemirror/view';
5
- import { PluginInjectionAPI } from '../types';
1
+ import type { PropsWithChildren } from 'react';
2
+ import React from 'react';
3
+ import type { EditorContainerWidth } from '@atlaskit/editor-common/types';
4
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
5
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
6
+ import type { PluginInjectionAPI } from '../types';
6
7
  type InnerContainerProps = {
7
8
  className: string;
8
9
  style?: {
@@ -7,6 +7,7 @@ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
7
  interface TableResizerProps {
8
8
  width: number;
9
9
  maxWidth: number;
10
+ containerWidth: number;
10
11
  updateWidth: (width: number) => void;
11
12
  editorView: EditorView;
12
13
  getPos: () => number | undefined;
@@ -15,5 +16,5 @@ interface TableResizerProps {
15
16
  displayGuideline: (guideline: GuidelineConfig[]) => boolean;
16
17
  attachAnalyticsEvent: (payload: TableEventPayload) => ((tr: Transaction) => boolean) | undefined;
17
18
  }
18
- export declare const TableResizer: ({ children, width, maxWidth, updateWidth, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, }: PropsWithChildren<TableResizerProps>) => JSX.Element;
19
+ export declare const TableResizer: ({ children, width, maxWidth, containerWidth, updateWidth, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, }: PropsWithChildren<TableResizerProps>) => JSX.Element;
19
20
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "2.9.0",
3
+ "version": "2.9.1",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -1,23 +1,20 @@
1
- import React, {
2
- forwardRef,
3
- PropsWithChildren,
4
- useCallback,
5
- useRef,
6
- } from 'react';
1
+ import type { PropsWithChildren } from 'react';
2
+ import React, { forwardRef, useCallback, useRef } from 'react';
7
3
 
8
4
  import classNames from 'classnames';
9
5
 
10
- import { TableEventPayload } from '@atlaskit/editor-common/analytics';
6
+ import type { TableEventPayload } from '@atlaskit/editor-common/analytics';
11
7
  import type { GuidelineConfig } from '@atlaskit/editor-common/guideline';
12
8
  import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
13
9
  import { calcTableWidth } from '@atlaskit/editor-common/styles';
14
- import { EditorContainerWidth } from '@atlaskit/editor-common/types';
15
- import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
16
- import { EditorView } from '@atlaskit/editor-prosemirror/view';
10
+ import type { EditorContainerWidth } from '@atlaskit/editor-common/types';
11
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
12
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
17
13
  import { akEditorMobileBreakoutPoint } from '@atlaskit/editor-shared-styles';
18
14
 
19
15
  import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
20
- import { TableCssClassName as ClassName, PluginInjectionAPI } from '../types';
16
+ import type { PluginInjectionAPI } from '../types';
17
+ import { TableCssClassName as ClassName } from '../types';
21
18
 
22
19
  import { TableResizer } from './TableResizer';
23
20
 
@@ -94,6 +91,14 @@ export const ResizableTableContainer = ({
94
91
 
95
92
  const marginLeft = getMarginLeft(lineLength, width);
96
93
 
94
+ // make sure during resizing
95
+ // the pm-table-resizer-container width is the same as its child div resizer-item
96
+ // otherwise when resize table from wider to narrower , pm-table-resizer-container stays wider
97
+ // and cause the fabric-editor-popup-scroll-parent to overflow
98
+ if (containerRef.current.style.width !== `${width}px`) {
99
+ containerRef.current.style.width = `${width}px`;
100
+ }
101
+
97
102
  if (marginLeftRef.current !== marginLeft) {
98
103
  marginLeftRef.current = marginLeft;
99
104
 
@@ -141,6 +146,7 @@ export const ResizableTableContainer = ({
141
146
  <TableResizer
142
147
  width={width}
143
148
  maxWidth={maxResizerWidth}
149
+ containerWidth={containerWidth}
144
150
  updateWidth={updateWidth}
145
151
  editorView={editorView}
146
152
  getPos={getPos}
@@ -40,6 +40,7 @@ import { defaultSnappingWidths, findClosestSnap } from '../utils/snapping';
40
40
  interface TableResizerProps {
41
41
  width: number;
42
42
  maxWidth: number;
43
+ containerWidth: number;
43
44
  updateWidth: (width: number) => void;
44
45
  editorView: EditorView;
45
46
  getPos: () => number | undefined;
@@ -87,10 +88,31 @@ const getResizerMinWidth = (node: PMNode) => {
87
88
  return minColumnWidth + 1;
88
89
  };
89
90
 
91
+ /**
92
+ * When guidelines are outside the viewport, filter them out, do not show
93
+ * So the guideline container won't make the fabric-editor-popup-scroll-parent overflow
94
+ * @param guidelines
95
+ * @param containerWidth editorWidth
96
+ */
97
+ const getVisibleGuidelines = (
98
+ guidelines: GuidelineConfig[],
99
+ containerWidth: number,
100
+ ) => {
101
+ return guidelines.filter((guideline) => {
102
+ return (
103
+ guideline.position &&
104
+ guideline.position.x !== undefined &&
105
+ typeof guideline.position.x === 'number' &&
106
+ Math.abs(guideline.position.x * 2) < containerWidth
107
+ );
108
+ });
109
+ };
110
+
90
111
  export const TableResizer = ({
91
112
  children,
92
113
  width,
93
114
  maxWidth,
115
+ containerWidth,
94
116
  updateWidth,
95
117
  editorView,
96
118
  getPos,
@@ -111,17 +133,21 @@ export const TableResizer = ({
111
133
  ({ gap, keys }: { gap: number; keys: string[] }) => {
112
134
  if (gap !== currentGap.current) {
113
135
  currentGap.current = gap;
136
+ const visibleGuidelines = getVisibleGuidelines(
137
+ defaultGuidelines,
138
+ containerWidth,
139
+ );
114
140
  displayGuideline(
115
141
  getGuidelinesWithHighlights(
116
142
  gap,
117
143
  TABLE_SNAP_GAP,
118
144
  keys,
119
- defaultGuidelines,
145
+ visibleGuidelines,
120
146
  ),
121
147
  );
122
148
  }
123
149
  },
124
- [displayGuideline],
150
+ [displayGuideline, containerWidth],
125
151
  );
126
152
 
127
153
  const guidelineSnaps = useMemo(
@@ -144,8 +170,12 @@ export const TableResizer = ({
144
170
 
145
171
  dispatch(tr.setMeta(tableWidthPluginKey, { resizing: true }));
146
172
 
147
- setSnappingEnabled(displayGuideline(defaultGuidelines));
148
- }, [displayGuideline, editorView, startMeasure]);
173
+ const visibleGuidelines = getVisibleGuidelines(
174
+ defaultGuidelines,
175
+ containerWidth,
176
+ );
177
+ setSnappingEnabled(displayGuideline(visibleGuidelines));
178
+ }, [displayGuideline, containerWidth, editorView, startMeasure]);
149
179
 
150
180
  const handleResize = useCallback(
151
181
  (originalState, delta) => {
@@ -1,5 +0,0 @@
1
- {
2
- "name": "@atlaskit/editor-plugin-table",
3
- "version": "2.9.0",
4
- "sideEffects": false
5
- }
@@ -1,5 +0,0 @@
1
- {
2
- "name": "@atlaskit/editor-plugin-table",
3
- "version": "2.9.0",
4
- "sideEffects": false
5
- }
@@ -1,5 +0,0 @@
1
- {
2
- "name": "@atlaskit/editor-plugin-table",
3
- "version": "2.9.0",
4
- "sideEffects": false
5
- }