@atlaskit/editor-plugin-table 4.1.0 → 4.1.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,12 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 4.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#41220](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41220) [`9e66f4b0610`](https://bitbucket.org/atlassian/atlassian-frontend/commits/9e66f4b0610) - Add a new feature flag (platform.editor.table.update-table-resizer-styles) that uses display: flex; to center resizable tables in full page editor. This replaces the current method which uses margin to calculate an offset
8
+ - Updated dependencies
9
+
3
10
  ## 4.1.0
4
11
 
5
12
  ### Minor Changes
@@ -44,7 +44,7 @@ var InnerContainer = exports.InnerContainer = /*#__PURE__*/(0, _react.forwardRef
44
44
  "data-test-id": "table-container"
45
45
  }, children);
46
46
  });
47
- var ResizableTableContainer = exports.ResizableTableContainer = function ResizableTableContainer(_ref2) {
47
+ var ResizableTableContainer = exports.ResizableTableContainer = /*#__PURE__*/_react.default.memo(function (_ref2) {
48
48
  var children = _ref2.children,
49
49
  className = _ref2.className,
50
50
  node = _ref2.node,
@@ -94,7 +94,6 @@ var ResizableTableContainer = exports.ResizableTableContainer = function Resizab
94
94
  if (!containerRef.current) {
95
95
  return;
96
96
  }
97
- var marginLeft = getMarginLeft(lineLength, width);
98
97
 
99
98
  // make sure during resizing
100
99
  // the pm-table-resizer-container width is the same as its child div resizer-item
@@ -103,10 +102,13 @@ var ResizableTableContainer = exports.ResizableTableContainer = function Resizab
103
102
  if (containerRef.current.style.width !== "".concat(width, "px")) {
104
103
  containerRef.current.style.width = "".concat(width, "px");
105
104
  }
106
- if (marginLeftRef.current !== marginLeft) {
107
- marginLeftRef.current = marginLeft;
108
- if (Number.isFinite(marginLeft)) {
109
- containerRef.current.style.marginLeft = "".concat(marginLeft, "px");
105
+ if (!(0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.update-table-resizer-styles')) {
106
+ var marginLeft = getMarginLeft(lineLength, width);
107
+ if (marginLeftRef.current !== marginLeft) {
108
+ marginLeftRef.current = marginLeft;
109
+ if (Number.isFinite(marginLeft)) {
110
+ containerRef.current.style.marginLeft = "".concat(marginLeft, "px");
111
+ }
110
112
  }
111
113
  }
112
114
  }, [lineLength]);
@@ -130,7 +132,9 @@ var ResizableTableContainer = exports.ResizableTableContainer = function Resizab
130
132
  var width = Math.min(tableWidth, responsiveContainerWidth);
131
133
  if (!isResizing) {
132
134
  tableWidthRef.current = width;
133
- marginLeftRef.current = getMarginLeft(lineLength, width);
135
+ if (!(0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.update-table-resizer-styles')) {
136
+ marginLeftRef.current = getMarginLeft(lineLength, width);
137
+ }
134
138
  }
135
139
  var maxResizerWidth = Math.min(responsiveContainerWidth, _utils.TABLE_MAX_WIDTH);
136
140
  var tableResizerProps = {
@@ -152,7 +156,21 @@ var ResizableTableContainer = exports.ResizableTableContainer = function Resizab
152
156
  onResizeStop: onResizeStop
153
157
  });
154
158
  }
155
- return /*#__PURE__*/_react.default.createElement("div", {
159
+ return (0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.update-table-resizer-styles') ? /*#__PURE__*/_react.default.createElement("div", {
160
+ style: {
161
+ display: 'flex',
162
+ justifyContent: 'center'
163
+ }
164
+ }, /*#__PURE__*/_react.default.createElement("div", {
165
+ style: {
166
+ width: tableWidthRef.current
167
+ },
168
+ className: _types.TableCssClassName.TABLE_RESIZER_CONTAINER,
169
+ ref: containerRef
170
+ }, /*#__PURE__*/_react.default.createElement(_TableResizer.TableResizer, tableResizerProps, /*#__PURE__*/_react.default.createElement(InnerContainer, {
171
+ className: className,
172
+ node: node
173
+ }, children)))) : /*#__PURE__*/_react.default.createElement("div", {
156
174
  style: {
157
175
  marginLeft: marginLeftRef.current,
158
176
  width: tableWidthRef.current
@@ -163,7 +181,7 @@ var ResizableTableContainer = exports.ResizableTableContainer = function Resizab
163
181
  className: className,
164
182
  node: node
165
183
  }, children)));
166
- };
184
+ });
167
185
  var TableContainer = exports.TableContainer = function TableContainer(_ref3) {
168
186
  var children = _ref3.children,
169
187
  node = _ref3.node,
@@ -32,7 +32,7 @@ export const InnerContainer = /*#__PURE__*/forwardRef(({
32
32
  "data-test-id": "table-container"
33
33
  }, children);
34
34
  });
35
- export const ResizableTableContainer = ({
35
+ export const ResizableTableContainer = /*#__PURE__*/React.memo(({
36
36
  children,
37
37
  className,
38
38
  node,
@@ -83,7 +83,6 @@ export const ResizableTableContainer = ({
83
83
  if (!containerRef.current) {
84
84
  return;
85
85
  }
86
- const marginLeft = getMarginLeft(lineLength, width);
87
86
 
88
87
  // make sure during resizing
89
88
  // the pm-table-resizer-container width is the same as its child div resizer-item
@@ -92,10 +91,13 @@ export const ResizableTableContainer = ({
92
91
  if (containerRef.current.style.width !== `${width}px`) {
93
92
  containerRef.current.style.width = `${width}px`;
94
93
  }
95
- if (marginLeftRef.current !== marginLeft) {
96
- marginLeftRef.current = marginLeft;
97
- if (Number.isFinite(marginLeft)) {
98
- containerRef.current.style.marginLeft = `${marginLeft}px`;
94
+ if (!getBooleanFF('platform.editor.table.update-table-resizer-styles')) {
95
+ const marginLeft = getMarginLeft(lineLength, width);
96
+ if (marginLeftRef.current !== marginLeft) {
97
+ marginLeftRef.current = marginLeft;
98
+ if (Number.isFinite(marginLeft)) {
99
+ containerRef.current.style.marginLeft = `${marginLeft}px`;
100
+ }
99
101
  }
100
102
  }
101
103
  }, [lineLength]);
@@ -119,7 +121,9 @@ export const ResizableTableContainer = ({
119
121
  const width = Math.min(tableWidth, responsiveContainerWidth);
120
122
  if (!isResizing) {
121
123
  tableWidthRef.current = width;
122
- marginLeftRef.current = getMarginLeft(lineLength, width);
124
+ if (!getBooleanFF('platform.editor.table.update-table-resizer-styles')) {
125
+ marginLeftRef.current = getMarginLeft(lineLength, width);
126
+ }
123
127
  }
124
128
  const maxResizerWidth = Math.min(responsiveContainerWidth, TABLE_MAX_WIDTH);
125
129
  let tableResizerProps = {
@@ -142,7 +146,21 @@ export const ResizableTableContainer = ({
142
146
  onResizeStop: onResizeStop
143
147
  };
144
148
  }
145
- return /*#__PURE__*/React.createElement("div", {
149
+ return getBooleanFF('platform.editor.table.update-table-resizer-styles') ? /*#__PURE__*/React.createElement("div", {
150
+ style: {
151
+ display: 'flex',
152
+ justifyContent: 'center'
153
+ }
154
+ }, /*#__PURE__*/React.createElement("div", {
155
+ style: {
156
+ width: tableWidthRef.current
157
+ },
158
+ className: ClassName.TABLE_RESIZER_CONTAINER,
159
+ ref: containerRef
160
+ }, /*#__PURE__*/React.createElement(TableResizer, tableResizerProps, /*#__PURE__*/React.createElement(InnerContainer, {
161
+ className: className,
162
+ node: node
163
+ }, children)))) : /*#__PURE__*/React.createElement("div", {
146
164
  style: {
147
165
  marginLeft: marginLeftRef.current,
148
166
  width: tableWidthRef.current
@@ -153,7 +171,7 @@ export const ResizableTableContainer = ({
153
171
  className: className,
154
172
  node: node
155
173
  }, children)));
156
- };
174
+ });
157
175
  export const TableContainer = ({
158
176
  children,
159
177
  node,
@@ -34,7 +34,7 @@ export var InnerContainer = /*#__PURE__*/forwardRef(function (_ref, ref) {
34
34
  "data-test-id": "table-container"
35
35
  }, children);
36
36
  });
37
- export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
37
+ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref2) {
38
38
  var children = _ref2.children,
39
39
  className = _ref2.className,
40
40
  node = _ref2.node,
@@ -84,7 +84,6 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
84
84
  if (!containerRef.current) {
85
85
  return;
86
86
  }
87
- var marginLeft = getMarginLeft(lineLength, width);
88
87
 
89
88
  // make sure during resizing
90
89
  // the pm-table-resizer-container width is the same as its child div resizer-item
@@ -93,10 +92,13 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
93
92
  if (containerRef.current.style.width !== "".concat(width, "px")) {
94
93
  containerRef.current.style.width = "".concat(width, "px");
95
94
  }
96
- if (marginLeftRef.current !== marginLeft) {
97
- marginLeftRef.current = marginLeft;
98
- if (Number.isFinite(marginLeft)) {
99
- containerRef.current.style.marginLeft = "".concat(marginLeft, "px");
95
+ if (!getBooleanFF('platform.editor.table.update-table-resizer-styles')) {
96
+ var marginLeft = getMarginLeft(lineLength, width);
97
+ if (marginLeftRef.current !== marginLeft) {
98
+ marginLeftRef.current = marginLeft;
99
+ if (Number.isFinite(marginLeft)) {
100
+ containerRef.current.style.marginLeft = "".concat(marginLeft, "px");
101
+ }
100
102
  }
101
103
  }
102
104
  }, [lineLength]);
@@ -120,7 +122,9 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
120
122
  var width = Math.min(tableWidth, responsiveContainerWidth);
121
123
  if (!isResizing) {
122
124
  tableWidthRef.current = width;
123
- marginLeftRef.current = getMarginLeft(lineLength, width);
125
+ if (!getBooleanFF('platform.editor.table.update-table-resizer-styles')) {
126
+ marginLeftRef.current = getMarginLeft(lineLength, width);
127
+ }
124
128
  }
125
129
  var maxResizerWidth = Math.min(responsiveContainerWidth, TABLE_MAX_WIDTH);
126
130
  var tableResizerProps = {
@@ -142,7 +146,21 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
142
146
  onResizeStop: onResizeStop
143
147
  });
144
148
  }
145
- return /*#__PURE__*/React.createElement("div", {
149
+ return getBooleanFF('platform.editor.table.update-table-resizer-styles') ? /*#__PURE__*/React.createElement("div", {
150
+ style: {
151
+ display: 'flex',
152
+ justifyContent: 'center'
153
+ }
154
+ }, /*#__PURE__*/React.createElement("div", {
155
+ style: {
156
+ width: tableWidthRef.current
157
+ },
158
+ className: ClassName.TABLE_RESIZER_CONTAINER,
159
+ ref: containerRef
160
+ }, /*#__PURE__*/React.createElement(TableResizer, tableResizerProps, /*#__PURE__*/React.createElement(InnerContainer, {
161
+ className: className,
162
+ node: node
163
+ }, children)))) : /*#__PURE__*/React.createElement("div", {
146
164
  style: {
147
165
  marginLeft: marginLeftRef.current,
148
166
  width: tableWidthRef.current
@@ -153,7 +171,7 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
153
171
  className: className,
154
172
  node: node
155
173
  }, children)));
156
- };
174
+ });
157
175
  export var TableContainer = function TableContainer(_ref3) {
158
176
  var children = _ref3.children,
159
177
  node = _ref3.node,
@@ -8,7 +8,7 @@ type InnerContainerProps = {
8
8
  className: string;
9
9
  style?: {
10
10
  width: number | 'inherit';
11
- marginLeft: number | undefined;
11
+ marginLeft?: number;
12
12
  };
13
13
  node: PMNode;
14
14
  };
@@ -17,7 +17,7 @@ export declare const InnerContainer: React.ForwardRefExoticComponent<InnerContai
17
17
  } & React.RefAttributes<HTMLDivElement>>;
18
18
  type ResizableTableContainerProps = {
19
19
  containerWidth: number;
20
- lineLength: number;
20
+ lineLength?: number;
21
21
  node: PMNode;
22
22
  className: string;
23
23
  editorView: EditorView;
@@ -26,7 +26,7 @@ type ResizableTableContainerProps = {
26
26
  isResizing?: boolean;
27
27
  pluginInjectionApi?: PluginInjectionAPI;
28
28
  };
29
- export declare const ResizableTableContainer: ({ children, className, node, lineLength, containerWidth, editorView, getPos, tableRef, isResizing, pluginInjectionApi, }: PropsWithChildren<ResizableTableContainerProps>) => JSX.Element;
29
+ export declare const ResizableTableContainer: React.MemoExoticComponent<({ children, className, node, lineLength, containerWidth, editorView, getPos, tableRef, isResizing, pluginInjectionApi, }: PropsWithChildren<ResizableTableContainerProps>) => JSX.Element>;
30
30
  type TableContainerProps = {
31
31
  node: PMNode;
32
32
  className: string;
@@ -8,7 +8,7 @@ type InnerContainerProps = {
8
8
  className: string;
9
9
  style?: {
10
10
  width: number | 'inherit';
11
- marginLeft: number | undefined;
11
+ marginLeft?: number;
12
12
  };
13
13
  node: PMNode;
14
14
  };
@@ -17,7 +17,7 @@ export declare const InnerContainer: React.ForwardRefExoticComponent<InnerContai
17
17
  } & React.RefAttributes<HTMLDivElement>>;
18
18
  type ResizableTableContainerProps = {
19
19
  containerWidth: number;
20
- lineLength: number;
20
+ lineLength?: number;
21
21
  node: PMNode;
22
22
  className: string;
23
23
  editorView: EditorView;
@@ -26,7 +26,7 @@ type ResizableTableContainerProps = {
26
26
  isResizing?: boolean;
27
27
  pluginInjectionApi?: PluginInjectionAPI;
28
28
  };
29
- export declare const ResizableTableContainer: ({ children, className, node, lineLength, containerWidth, editorView, getPos, tableRef, isResizing, pluginInjectionApi, }: PropsWithChildren<ResizableTableContainerProps>) => JSX.Element;
29
+ export declare const ResizableTableContainer: React.MemoExoticComponent<({ children, className, node, lineLength, containerWidth, editorView, getPos, tableRef, isResizing, pluginInjectionApi, }: PropsWithChildren<ResizableTableContainerProps>) => JSX.Element>;
30
30
  type TableContainerProps = {
31
31
  node: PMNode;
32
32
  className: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "4.1.0",
3
+ "version": "4.1.1",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -29,7 +29,7 @@
29
29
  "dependencies": {
30
30
  "@atlaskit/adf-schema": "^32.0.0",
31
31
  "@atlaskit/custom-steps": "^0.0.2",
32
- "@atlaskit/editor-common": "^76.5.0",
32
+ "@atlaskit/editor-common": "^76.6.0",
33
33
  "@atlaskit/editor-palette": "1.5.1",
34
34
  "@atlaskit/editor-plugin-analytics": "^0.2.0",
35
35
  "@atlaskit/editor-plugin-content-insertion": "^0.1.0",
@@ -123,6 +123,9 @@
123
123
  },
124
124
  "platform.editor.table.increase-shadow-visibility_lh89r": {
125
125
  "type": "boolean"
126
+ },
127
+ "platform.editor.table.update-table-resizer-styles": {
128
+ "type": "boolean"
126
129
  }
127
130
  }
128
131
  }
@@ -23,7 +23,10 @@ import { TableCssClassName as ClassName } from '../types';
23
23
  import { TableResizer } from './TableResizer';
24
24
  import type { TableResizerImprovementProps } from './TableResizer';
25
25
 
26
- const getMarginLeft = (lineLength: number, tableWidth: number | 'inherit') => {
26
+ const getMarginLeft = (
27
+ lineLength: number | undefined,
28
+ tableWidth: number | 'inherit',
29
+ ) => {
27
30
  let marginLeft;
28
31
  if (tableWidth !== 'inherit' && lineLength) {
29
32
  const containerWidth = tableWidth;
@@ -40,7 +43,7 @@ type InnerContainerProps = {
40
43
  className: string;
41
44
  style?: {
42
45
  width: number | 'inherit';
43
- marginLeft: number | undefined;
46
+ marginLeft?: number;
44
47
  };
45
48
  node: PMNode;
46
49
  };
@@ -65,7 +68,7 @@ export const InnerContainer = forwardRef<
65
68
 
66
69
  type ResizableTableContainerProps = {
67
70
  containerWidth: number;
68
- lineLength: number;
71
+ lineLength?: number;
69
72
  node: PMNode;
70
73
  className: string;
71
74
  editorView: EditorView;
@@ -75,178 +78,205 @@ type ResizableTableContainerProps = {
75
78
  pluginInjectionApi?: PluginInjectionAPI;
76
79
  };
77
80
 
78
- export const ResizableTableContainer = ({
79
- children,
80
- className,
81
- node,
82
- lineLength,
83
- containerWidth,
84
- editorView,
85
- getPos,
86
- tableRef,
87
- isResizing,
88
- pluginInjectionApi,
89
- }: PropsWithChildren<ResizableTableContainerProps>) => {
90
- const containerRef = useRef<HTMLDivElement | null>(null);
91
- const marginLeftRef = useRef<number | undefined>(0);
92
- const tableWidthRef = useRef<number>(akEditorDefaultLayoutWidth);
93
-
94
- const updateContainerHeight = useCallback((height: number | 'auto') => {
95
- // current StickyHeader State is not stable to be fetch.
96
- // we need to update stickyHeader plugin to make sure state can be
97
- // consistently fetch and refactor below
98
- const stickyHeaders =
99
- containerRef.current?.getElementsByClassName('pm-table-sticky');
100
- if (!stickyHeaders || stickyHeaders.length < 1) {
101
- // when starting to drag, we need to keep the original space,
102
- // -- When sticky header not appear, margin top(24px) and margin bottom(16px), should be 40px,
103
- // 1px is border width but collapse make it 0.5.
104
- // -- When sticky header appear, we should add first row height but reduce
105
- // collapsed border
106
- containerRef.current?.style.setProperty(
107
- 'height',
108
- typeof height === 'number' ? `${height + 40.5}px` : 'auto',
109
- );
110
- } else {
111
- const stickyHeaderHeight =
112
- containerRef.current
113
- ?.getElementsByTagName('th')[0]
114
- .getBoundingClientRect().height || 0;
115
- containerRef.current?.style.setProperty(
116
- 'height',
117
- typeof height === 'number'
118
- ? `${height + stickyHeaderHeight + 39.5}px`
119
- : 'auto',
120
- );
121
- }
122
- }, []);
123
-
124
- const resizeObserverRef = useRef(
125
- new ResizeObserver((entries) => {
126
- updateContainerHeight(entries[entries.length - 1].contentRect.height);
127
- }),
128
- );
129
-
130
- const onResizeStart = useCallback(() => {
131
- if (tableRef) {
132
- resizeObserverRef.current.observe(tableRef);
133
- }
134
- }, [tableRef]);
135
-
136
- const onResizeStop = useCallback(() => {
137
- updateContainerHeight('auto');
138
-
139
- resizeObserverRef.current.disconnect();
140
- }, [updateContainerHeight]);
141
-
142
- const updateWidth = useCallback(
143
- (width: number) => {
144
- if (!containerRef.current) {
145
- return;
81
+ export const ResizableTableContainer = React.memo(
82
+ ({
83
+ children,
84
+ className,
85
+ node,
86
+ lineLength,
87
+ containerWidth,
88
+ editorView,
89
+ getPos,
90
+ tableRef,
91
+ isResizing,
92
+ pluginInjectionApi,
93
+ }: PropsWithChildren<ResizableTableContainerProps>) => {
94
+ const containerRef = useRef<HTMLDivElement | null>(null);
95
+ const marginLeftRef = useRef<number | undefined>(0);
96
+ const tableWidthRef = useRef<number>(akEditorDefaultLayoutWidth);
97
+
98
+ const updateContainerHeight = useCallback((height: number | 'auto') => {
99
+ // current StickyHeader State is not stable to be fetch.
100
+ // we need to update stickyHeader plugin to make sure state can be
101
+ // consistently fetch and refactor below
102
+ const stickyHeaders =
103
+ containerRef.current?.getElementsByClassName('pm-table-sticky');
104
+ if (!stickyHeaders || stickyHeaders.length < 1) {
105
+ // when starting to drag, we need to keep the original space,
106
+ // -- When sticky header not appear, margin top(24px) and margin bottom(16px), should be 40px,
107
+ // 1px is border width but collapse make it 0.5.
108
+ // -- When sticky header appear, we should add first row height but reduce
109
+ // collapsed border
110
+ containerRef.current?.style.setProperty(
111
+ 'height',
112
+ typeof height === 'number' ? `${height + 40.5}px` : 'auto',
113
+ );
114
+ } else {
115
+ const stickyHeaderHeight =
116
+ containerRef.current
117
+ ?.getElementsByTagName('th')[0]
118
+ .getBoundingClientRect().height || 0;
119
+ containerRef.current?.style.setProperty(
120
+ 'height',
121
+ typeof height === 'number'
122
+ ? `${height + stickyHeaderHeight + 39.5}px`
123
+ : 'auto',
124
+ );
146
125
  }
126
+ }, []);
147
127
 
148
- const marginLeft = getMarginLeft(lineLength, width);
128
+ const resizeObserverRef = useRef(
129
+ new ResizeObserver((entries) => {
130
+ updateContainerHeight(entries[entries.length - 1].contentRect.height);
131
+ }),
132
+ );
149
133
 
150
- // make sure during resizing
151
- // the pm-table-resizer-container width is the same as its child div resizer-item
152
- // otherwise when resize table from wider to narrower , pm-table-resizer-container stays wider
153
- // and cause the fabric-editor-popup-scroll-parent to overflow
154
- if (containerRef.current.style.width !== `${width}px`) {
155
- containerRef.current.style.width = `${width}px`;
134
+ const onResizeStart = useCallback(() => {
135
+ if (tableRef) {
136
+ resizeObserverRef.current.observe(tableRef);
156
137
  }
138
+ }, [tableRef]);
139
+
140
+ const onResizeStop = useCallback(() => {
141
+ updateContainerHeight('auto');
157
142
 
158
- if (marginLeftRef.current !== marginLeft) {
159
- marginLeftRef.current = marginLeft;
143
+ resizeObserverRef.current.disconnect();
144
+ }, [updateContainerHeight]);
160
145
 
161
- if (Number.isFinite(marginLeft)) {
162
- containerRef.current.style.marginLeft = `${marginLeft}px`;
146
+ const updateWidth = useCallback(
147
+ (width: number) => {
148
+ if (!containerRef.current) {
149
+ return;
163
150
  }
164
- }
165
- },
166
- [lineLength],
167
- );
168
151
 
169
- const displayGuideline = useCallback(
170
- (guidelines: GuidelineConfig[]) => {
171
- return (
172
- pluginInjectionApi?.guideline?.actions?.displayGuideline(editorView)({
173
- guidelines,
174
- }) ?? false
175
- );
176
- },
177
- [pluginInjectionApi, editorView],
178
- );
152
+ // make sure during resizing
153
+ // the pm-table-resizer-container width is the same as its child div resizer-item
154
+ // otherwise when resize table from wider to narrower , pm-table-resizer-container stays wider
155
+ // and cause the fabric-editor-popup-scroll-parent to overflow
156
+ if (containerRef.current.style.width !== `${width}px`) {
157
+ containerRef.current.style.width = `${width}px`;
158
+ }
179
159
 
180
- const attachAnalyticsEvent = useCallback(
181
- (payload: TableEventPayload) => {
182
- return pluginInjectionApi?.analytics?.actions.attachAnalyticsEvent(
183
- payload,
184
- );
185
- },
186
- [pluginInjectionApi],
187
- );
160
+ if (
161
+ !getBooleanFF('platform.editor.table.update-table-resizer-styles')
162
+ ) {
163
+ const marginLeft = getMarginLeft(lineLength, width);
164
+ if (marginLeftRef.current !== marginLeft) {
165
+ marginLeftRef.current = marginLeft;
166
+ if (Number.isFinite(marginLeft)) {
167
+ containerRef.current.style.marginLeft = `${marginLeft}px`;
168
+ }
169
+ }
170
+ }
171
+ },
172
+ [lineLength],
173
+ );
188
174
 
189
- const displayGapCursor = useCallback(
190
- (toggle) => {
191
- return (
192
- pluginInjectionApi?.core?.actions.execute(
193
- pluginInjectionApi?.selection?.commands.displayGapCursor(toggle),
194
- ) ?? false
195
- );
196
- },
197
- [pluginInjectionApi],
198
- );
175
+ const displayGuideline = useCallback(
176
+ (guidelines: GuidelineConfig[]) => {
177
+ return (
178
+ pluginInjectionApi?.guideline?.actions?.displayGuideline(editorView)({
179
+ guidelines,
180
+ }) ?? false
181
+ );
182
+ },
183
+ [pluginInjectionApi, editorView],
184
+ );
199
185
 
200
- const tableWidth = getTableContainerWidth(node);
201
- // 76 is currently an accepted padding value considering the spacing for resizer handle
202
- const responsiveContainerWidth = containerWidth - 76;
203
- const width = Math.min(tableWidth, responsiveContainerWidth);
186
+ const attachAnalyticsEvent = useCallback(
187
+ (payload: TableEventPayload) => {
188
+ return pluginInjectionApi?.analytics?.actions.attachAnalyticsEvent(
189
+ payload,
190
+ );
191
+ },
192
+ [pluginInjectionApi],
193
+ );
204
194
 
205
- if (!isResizing) {
206
- tableWidthRef.current = width;
207
- marginLeftRef.current = getMarginLeft(lineLength, width);
208
- }
209
- const maxResizerWidth = Math.min(responsiveContainerWidth, TABLE_MAX_WIDTH);
195
+ const displayGapCursor = useCallback(
196
+ (toggle) => {
197
+ return (
198
+ pluginInjectionApi?.core?.actions.execute(
199
+ pluginInjectionApi?.selection?.commands.displayGapCursor(toggle),
200
+ ) ?? false
201
+ );
202
+ },
203
+ [pluginInjectionApi],
204
+ );
210
205
 
211
- let tableResizerProps: TableResizerImprovementProps = {
212
- width,
213
- maxWidth: maxResizerWidth,
214
- containerWidth,
215
- updateWidth,
216
- editorView,
217
- getPos,
218
- node,
219
- tableRef,
220
- displayGuideline,
221
- attachAnalyticsEvent,
222
- displayGapCursor,
223
- };
206
+ const tableWidth = getTableContainerWidth(node);
207
+ // 76 is currently an accepted padding value considering the spacing for resizer handle
208
+ const responsiveContainerWidth = containerWidth - 76;
209
+ const width = Math.min(tableWidth, responsiveContainerWidth);
224
210
 
225
- if (getBooleanFF('platform.editor.resizing-table-height-improvement')) {
226
- tableResizerProps = {
227
- ...tableResizerProps,
228
- onResizeStart: onResizeStart,
229
- onResizeStop: onResizeStop,
211
+ if (!isResizing) {
212
+ tableWidthRef.current = width;
213
+ if (!getBooleanFF('platform.editor.table.update-table-resizer-styles')) {
214
+ marginLeftRef.current = getMarginLeft(lineLength, width);
215
+ }
216
+ }
217
+ const maxResizerWidth = Math.min(responsiveContainerWidth, TABLE_MAX_WIDTH);
218
+
219
+ let tableResizerProps: TableResizerImprovementProps = {
220
+ width,
221
+ maxWidth: maxResizerWidth,
222
+ containerWidth,
223
+ updateWidth,
224
+ editorView,
225
+ getPos,
226
+ node,
227
+ tableRef,
228
+ displayGuideline,
229
+ attachAnalyticsEvent,
230
+ displayGapCursor,
230
231
  };
231
- }
232
232
 
233
- return (
234
- <div
235
- style={{
236
- marginLeft: marginLeftRef.current,
237
- width: tableWidthRef.current,
238
- }}
239
- className={ClassName.TABLE_RESIZER_CONTAINER}
240
- ref={containerRef}
241
- >
242
- <TableResizer {...tableResizerProps}>
243
- <InnerContainer className={className} node={node}>
244
- {children}
245
- </InnerContainer>
246
- </TableResizer>
247
- </div>
248
- );
249
- };
233
+ if (getBooleanFF('platform.editor.resizing-table-height-improvement')) {
234
+ tableResizerProps = {
235
+ ...tableResizerProps,
236
+ onResizeStart: onResizeStart,
237
+ onResizeStop: onResizeStop,
238
+ };
239
+ }
240
+
241
+ return getBooleanFF('platform.editor.table.update-table-resizer-styles') ? (
242
+ <div
243
+ style={{
244
+ display: 'flex',
245
+ justifyContent: 'center',
246
+ }}
247
+ >
248
+ <div
249
+ style={{
250
+ width: tableWidthRef.current,
251
+ }}
252
+ className={ClassName.TABLE_RESIZER_CONTAINER}
253
+ ref={containerRef}
254
+ >
255
+ <TableResizer {...tableResizerProps}>
256
+ <InnerContainer className={className} node={node}>
257
+ {children}
258
+ </InnerContainer>
259
+ </TableResizer>
260
+ </div>
261
+ </div>
262
+ ) : (
263
+ <div
264
+ style={{
265
+ marginLeft: marginLeftRef.current,
266
+ width: tableWidthRef.current,
267
+ }}
268
+ className={ClassName.TABLE_RESIZER_CONTAINER}
269
+ ref={containerRef}
270
+ >
271
+ <TableResizer {...tableResizerProps}>
272
+ <InnerContainer className={className} node={node}>
273
+ {children}
274
+ </InnerContainer>
275
+ </TableResizer>
276
+ </div>
277
+ );
278
+ },
279
+ );
250
280
 
251
281
  type TableContainerProps = {
252
282
  node: PMNode;