@atlaskit/editor-plugin-table 2.10.2 → 2.10.3

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.10.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`d6e4badd8c4`](https://bitbucket.org/atlassian/atlassian-frontend/commits/d6e4badd8c4) - Add explicit height to table when resizing width to increase performance
8
+
3
9
  ## 2.10.2
4
10
 
5
11
  ### Patch Changes
@@ -55,6 +55,23 @@ var ResizableTableContainer = function ResizableTableContainer(_ref2) {
55
55
  var containerRef = (0, _react.useRef)(null);
56
56
  var marginLeftRef = (0, _react.useRef)(0);
57
57
  var tableWidthRef = (0, _react.useRef)(_editorSharedStyles.akEditorDefaultLayoutWidth);
58
+ var updateContainerHeight = (0, _react.useCallback)(function (height) {
59
+ var _containerRef$current;
60
+ (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.style.setProperty('height', typeof height === 'number' ? "".concat(height + 29, "px") : 'auto');
61
+ }, []);
62
+ var resizeObserverRef = (0, _react.useRef)(new ResizeObserver(function (entries) {
63
+ updateContainerHeight(entries[entries.length - 1].contentRect.height);
64
+ }));
65
+ var onResizeStart = (0, _react.useCallback)(function () {
66
+ updateContainerHeight(tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientHeight);
67
+ if (tableRef) {
68
+ resizeObserverRef.current.observe(tableRef);
69
+ }
70
+ }, [tableRef, updateContainerHeight]);
71
+ var onResizeStop = (0, _react.useCallback)(function () {
72
+ updateContainerHeight('auto');
73
+ resizeObserverRef.current.disconnect();
74
+ }, [updateContainerHeight]);
58
75
  var updateWidth = (0, _react.useCallback)(function (width) {
59
76
  if (!containerRef.current) {
60
77
  return;
@@ -102,6 +119,8 @@ var ResizableTableContainer = function ResizableTableContainer(_ref2) {
102
119
  className: _types.TableCssClassName.TABLE_RESIZER_CONTAINER,
103
120
  ref: containerRef
104
121
  }, /*#__PURE__*/_react.default.createElement(_TableResizer.TableResizer, {
122
+ onResizeStart: onResizeStart,
123
+ onResizeStop: onResizeStop,
105
124
  width: width,
106
125
  maxWidth: maxResizerWidth,
107
126
  containerWidth: containerWidth,
@@ -33,6 +33,10 @@ var tableHandlePosition = 14;
33
33
  var getResizerHandleHeight = function getResizerHandleHeight(tableRef) {
34
34
  var tableHeight = tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientHeight;
35
35
  var handleHeightSize = 'small';
36
+ if (!tableHeight) {
37
+ return handleHeightSize;
38
+ }
39
+
36
40
  /*
37
41
  - One row table height (minimum possible table height) ~ 45px
38
42
  - Two row table height ~ 90px
@@ -41,9 +45,9 @@ var getResizerHandleHeight = function getResizerHandleHeight(tableRef) {
41
45
  - > 46 because the height of the table can be a float number like 45.44.
42
46
  - < 96 is the height of large resize handle.
43
47
  */
44
- if (tableHeight && tableHeight > 46 && tableHeight < 96) {
48
+ if (tableHeight > 46 && tableHeight < 96) {
45
49
  handleHeightSize = 'medium';
46
- } else if (tableHeight && tableHeight >= 96) {
50
+ } else if (tableHeight >= 96) {
47
51
  handleHeightSize = 'large';
48
52
  }
49
53
  return handleHeightSize;
@@ -74,6 +78,8 @@ var TableResizer = function TableResizer(_ref) {
74
78
  maxWidth = _ref.maxWidth,
75
79
  containerWidth = _ref.containerWidth,
76
80
  updateWidth = _ref.updateWidth,
81
+ onResizeStop = _ref.onResizeStop,
82
+ onResizeStart = _ref.onResizeStart,
77
83
  editorView = _ref.editorView,
78
84
  getPos = _ref.getPos,
79
85
  node = _ref.node,
@@ -116,7 +122,8 @@ var TableResizer = function TableResizer(_ref) {
116
122
  }));
117
123
  var visibleGuidelines = getVisibleGuidelines(_guidelines.defaultGuidelines, containerWidth);
118
124
  setSnappingEnabled(displayGuideline(visibleGuidelines));
119
- }, [displayGuideline, containerWidth, editorView, startMeasure]);
125
+ onResizeStart();
126
+ }, [displayGuideline, editorView, startMeasure, onResizeStart, containerWidth]);
120
127
  var handleResize = (0, _react.useCallback)(function (originalState, delta) {
121
128
  countFrames();
122
129
  var newWidth = originalState.width + delta.width;
@@ -181,8 +188,9 @@ var TableResizer = function TableResizer(_ref) {
181
188
  displayGuideline([]);
182
189
  updateWidth(newWidth);
183
190
  scheduleResize.cancel();
191
+ onResizeStop();
184
192
  return newWidth;
185
- }, [updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, attachAnalyticsEvent, endMeasure]);
193
+ }, [updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, attachAnalyticsEvent, endMeasure, onResizeStop]);
186
194
  var handleComponent = (0, _react.useMemo)(function () {
187
195
  return {
188
196
  left: /*#__PURE__*/_react.default.createElement("div", {
@@ -46,6 +46,23 @@ export const ResizableTableContainer = ({
46
46
  const containerRef = useRef(null);
47
47
  const marginLeftRef = useRef(0);
48
48
  const tableWidthRef = useRef(akEditorDefaultLayoutWidth);
49
+ const updateContainerHeight = useCallback(height => {
50
+ var _containerRef$current;
51
+ (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.style.setProperty('height', typeof height === 'number' ? `${height + 29}px` : 'auto');
52
+ }, []);
53
+ const resizeObserverRef = useRef(new ResizeObserver(entries => {
54
+ updateContainerHeight(entries[entries.length - 1].contentRect.height);
55
+ }));
56
+ const onResizeStart = useCallback(() => {
57
+ updateContainerHeight(tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientHeight);
58
+ if (tableRef) {
59
+ resizeObserverRef.current.observe(tableRef);
60
+ }
61
+ }, [tableRef, updateContainerHeight]);
62
+ const onResizeStop = useCallback(() => {
63
+ updateContainerHeight('auto');
64
+ resizeObserverRef.current.disconnect();
65
+ }, [updateContainerHeight]);
49
66
  const updateWidth = useCallback(width => {
50
67
  if (!containerRef.current) {
51
68
  return;
@@ -93,6 +110,8 @@ export const ResizableTableContainer = ({
93
110
  className: ClassName.TABLE_RESIZER_CONTAINER,
94
111
  ref: containerRef
95
112
  }, /*#__PURE__*/React.createElement(TableResizer, {
113
+ onResizeStart: onResizeStart,
114
+ onResizeStop: onResizeStop,
96
115
  width: width,
97
116
  maxWidth: maxResizerWidth,
98
117
  containerWidth: containerWidth,
@@ -19,6 +19,10 @@ const tableHandlePosition = 14;
19
19
  const getResizerHandleHeight = tableRef => {
20
20
  const tableHeight = tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientHeight;
21
21
  let handleHeightSize = 'small';
22
+ if (!tableHeight) {
23
+ return handleHeightSize;
24
+ }
25
+
22
26
  /*
23
27
  - One row table height (minimum possible table height) ~ 45px
24
28
  - Two row table height ~ 90px
@@ -27,9 +31,9 @@ const getResizerHandleHeight = tableRef => {
27
31
  - > 46 because the height of the table can be a float number like 45.44.
28
32
  - < 96 is the height of large resize handle.
29
33
  */
30
- if (tableHeight && tableHeight > 46 && tableHeight < 96) {
34
+ if (tableHeight > 46 && tableHeight < 96) {
31
35
  handleHeightSize = 'medium';
32
- } else if (tableHeight && tableHeight >= 96) {
36
+ } else if (tableHeight >= 96) {
33
37
  handleHeightSize = 'large';
34
38
  }
35
39
  return handleHeightSize;
@@ -59,6 +63,8 @@ export const TableResizer = ({
59
63
  maxWidth,
60
64
  containerWidth,
61
65
  updateWidth,
66
+ onResizeStop,
67
+ onResizeStart,
62
68
  editorView,
63
69
  getPos,
64
70
  node,
@@ -105,7 +111,8 @@ export const TableResizer = ({
105
111
  }));
106
112
  const visibleGuidelines = getVisibleGuidelines(defaultGuidelines, containerWidth);
107
113
  setSnappingEnabled(displayGuideline(visibleGuidelines));
108
- }, [displayGuideline, containerWidth, editorView, startMeasure]);
114
+ onResizeStart();
115
+ }, [displayGuideline, editorView, startMeasure, onResizeStart, containerWidth]);
109
116
  const handleResize = useCallback((originalState, delta) => {
110
117
  countFrames();
111
118
  const newWidth = originalState.width + delta.width;
@@ -171,8 +178,9 @@ export const TableResizer = ({
171
178
  displayGuideline([]);
172
179
  updateWidth(newWidth);
173
180
  scheduleResize.cancel();
181
+ onResizeStop();
174
182
  return newWidth;
175
- }, [updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, attachAnalyticsEvent, endMeasure]);
183
+ }, [updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, attachAnalyticsEvent, endMeasure, onResizeStop]);
176
184
  const handleComponent = useMemo(() => ({
177
185
  left: /*#__PURE__*/React.createElement("div", {
178
186
  className: resizerHandleShadowClassName,
@@ -44,6 +44,23 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
44
44
  var containerRef = useRef(null);
45
45
  var marginLeftRef = useRef(0);
46
46
  var tableWidthRef = useRef(akEditorDefaultLayoutWidth);
47
+ var updateContainerHeight = useCallback(function (height) {
48
+ var _containerRef$current;
49
+ (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.style.setProperty('height', typeof height === 'number' ? "".concat(height + 29, "px") : 'auto');
50
+ }, []);
51
+ var resizeObserverRef = useRef(new ResizeObserver(function (entries) {
52
+ updateContainerHeight(entries[entries.length - 1].contentRect.height);
53
+ }));
54
+ var onResizeStart = useCallback(function () {
55
+ updateContainerHeight(tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientHeight);
56
+ if (tableRef) {
57
+ resizeObserverRef.current.observe(tableRef);
58
+ }
59
+ }, [tableRef, updateContainerHeight]);
60
+ var onResizeStop = useCallback(function () {
61
+ updateContainerHeight('auto');
62
+ resizeObserverRef.current.disconnect();
63
+ }, [updateContainerHeight]);
47
64
  var updateWidth = useCallback(function (width) {
48
65
  if (!containerRef.current) {
49
66
  return;
@@ -91,6 +108,8 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
91
108
  className: ClassName.TABLE_RESIZER_CONTAINER,
92
109
  ref: containerRef
93
110
  }, /*#__PURE__*/React.createElement(TableResizer, {
111
+ onResizeStart: onResizeStart,
112
+ onResizeStop: onResizeStop,
94
113
  width: width,
95
114
  maxWidth: maxResizerWidth,
96
115
  containerWidth: containerWidth,
@@ -23,6 +23,10 @@ var tableHandlePosition = 14;
23
23
  var getResizerHandleHeight = function getResizerHandleHeight(tableRef) {
24
24
  var tableHeight = tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientHeight;
25
25
  var handleHeightSize = 'small';
26
+ if (!tableHeight) {
27
+ return handleHeightSize;
28
+ }
29
+
26
30
  /*
27
31
  - One row table height (minimum possible table height) ~ 45px
28
32
  - Two row table height ~ 90px
@@ -31,9 +35,9 @@ var getResizerHandleHeight = function getResizerHandleHeight(tableRef) {
31
35
  - > 46 because the height of the table can be a float number like 45.44.
32
36
  - < 96 is the height of large resize handle.
33
37
  */
34
- if (tableHeight && tableHeight > 46 && tableHeight < 96) {
38
+ if (tableHeight > 46 && tableHeight < 96) {
35
39
  handleHeightSize = 'medium';
36
- } else if (tableHeight && tableHeight >= 96) {
40
+ } else if (tableHeight >= 96) {
37
41
  handleHeightSize = 'large';
38
42
  }
39
43
  return handleHeightSize;
@@ -64,6 +68,8 @@ export var TableResizer = function TableResizer(_ref) {
64
68
  maxWidth = _ref.maxWidth,
65
69
  containerWidth = _ref.containerWidth,
66
70
  updateWidth = _ref.updateWidth,
71
+ onResizeStop = _ref.onResizeStop,
72
+ onResizeStart = _ref.onResizeStart,
67
73
  editorView = _ref.editorView,
68
74
  getPos = _ref.getPos,
69
75
  node = _ref.node,
@@ -106,7 +112,8 @@ export var TableResizer = function TableResizer(_ref) {
106
112
  }));
107
113
  var visibleGuidelines = getVisibleGuidelines(defaultGuidelines, containerWidth);
108
114
  setSnappingEnabled(displayGuideline(visibleGuidelines));
109
- }, [displayGuideline, containerWidth, editorView, startMeasure]);
115
+ onResizeStart();
116
+ }, [displayGuideline, editorView, startMeasure, onResizeStart, containerWidth]);
110
117
  var handleResize = useCallback(function (originalState, delta) {
111
118
  countFrames();
112
119
  var newWidth = originalState.width + delta.width;
@@ -171,8 +178,9 @@ export var TableResizer = function TableResizer(_ref) {
171
178
  displayGuideline([]);
172
179
  updateWidth(newWidth);
173
180
  scheduleResize.cancel();
181
+ onResizeStop();
174
182
  return newWidth;
175
- }, [updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, attachAnalyticsEvent, endMeasure]);
183
+ }, [updateWidth, editorView, getPos, node, tableRef, scheduleResize, displayGuideline, attachAnalyticsEvent, endMeasure, onResizeStop]);
176
184
  var handleComponent = useMemo(function () {
177
185
  return {
178
186
  left: /*#__PURE__*/React.createElement("div", {
@@ -9,6 +9,8 @@ interface TableResizerProps {
9
9
  maxWidth: number;
10
10
  containerWidth: number;
11
11
  updateWidth: (width: number) => void;
12
+ onResizeStop: () => void;
13
+ onResizeStart: () => void;
12
14
  editorView: EditorView;
13
15
  getPos: () => number | undefined;
14
16
  node: PMNode;
@@ -16,5 +18,5 @@ interface TableResizerProps {
16
18
  displayGuideline: (guideline: GuidelineConfig[]) => boolean;
17
19
  attachAnalyticsEvent: (payload: TableEventPayload) => ((tr: Transaction) => boolean) | undefined;
18
20
  }
19
- export declare const TableResizer: ({ children, width, maxWidth, containerWidth, updateWidth, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, }: PropsWithChildren<TableResizerProps>) => JSX.Element;
21
+ export declare const TableResizer: ({ children, width, maxWidth, containerWidth, updateWidth, onResizeStop, onResizeStart, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, }: PropsWithChildren<TableResizerProps>) => JSX.Element;
20
22
  export {};
@@ -9,6 +9,8 @@ interface TableResizerProps {
9
9
  maxWidth: number;
10
10
  containerWidth: number;
11
11
  updateWidth: (width: number) => void;
12
+ onResizeStop: () => void;
13
+ onResizeStart: () => void;
12
14
  editorView: EditorView;
13
15
  getPos: () => number | undefined;
14
16
  node: PMNode;
@@ -16,5 +18,5 @@ interface TableResizerProps {
16
18
  displayGuideline: (guideline: GuidelineConfig[]) => boolean;
17
19
  attachAnalyticsEvent: (payload: TableEventPayload) => ((tr: Transaction) => boolean) | undefined;
18
20
  }
19
- export declare const TableResizer: ({ children, width, maxWidth, containerWidth, updateWidth, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, }: PropsWithChildren<TableResizerProps>) => JSX.Element;
21
+ export declare const TableResizer: ({ children, width, maxWidth, containerWidth, updateWidth, onResizeStop, onResizeStart, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, }: PropsWithChildren<TableResizerProps>) => JSX.Element;
20
22
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "2.10.2",
3
+ "version": "2.10.3",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -89,6 +89,33 @@ export const ResizableTableContainer = ({
89
89
  const marginLeftRef = useRef<number | undefined>(0);
90
90
  const tableWidthRef = useRef<number>(akEditorDefaultLayoutWidth);
91
91
 
92
+ const updateContainerHeight = useCallback((height: number | 'auto') => {
93
+ containerRef.current?.style.setProperty(
94
+ 'height',
95
+ typeof height === 'number' ? `${height + 29}px` : 'auto',
96
+ );
97
+ }, []);
98
+
99
+ const resizeObserverRef = useRef(
100
+ new ResizeObserver((entries) => {
101
+ updateContainerHeight(entries[entries.length - 1].contentRect.height);
102
+ }),
103
+ );
104
+
105
+ const onResizeStart = useCallback(() => {
106
+ updateContainerHeight(tableRef?.clientHeight);
107
+
108
+ if (tableRef) {
109
+ resizeObserverRef.current.observe(tableRef);
110
+ }
111
+ }, [tableRef, updateContainerHeight]);
112
+
113
+ const onResizeStop = useCallback(() => {
114
+ updateContainerHeight('auto');
115
+
116
+ resizeObserverRef.current.disconnect();
117
+ }, [updateContainerHeight]);
118
+
92
119
  const updateWidth = useCallback(
93
120
  (width: number) => {
94
121
  if (!containerRef.current) {
@@ -157,6 +184,8 @@ export const ResizableTableContainer = ({
157
184
  ref={containerRef}
158
185
  >
159
186
  <TableResizer
187
+ onResizeStart={onResizeStart}
188
+ onResizeStop={onResizeStop}
160
189
  width={width}
161
190
  maxWidth={maxResizerWidth}
162
191
  containerWidth={containerWidth}
@@ -43,6 +43,8 @@ interface TableResizerProps {
43
43
  maxWidth: number;
44
44
  containerWidth: number;
45
45
  updateWidth: (width: number) => void;
46
+ onResizeStop: () => void;
47
+ onResizeStart: () => void;
46
48
  editorView: EditorView;
47
49
  getPos: () => number | undefined;
48
50
  node: PMNode;
@@ -57,9 +59,14 @@ const handles = { right: true };
57
59
  const tableHandleMarginTop = 12;
58
60
  const tableHandlePosition = 14;
59
61
 
60
- const getResizerHandleHeight = (tableRef: HTMLTableElement) => {
62
+ const getResizerHandleHeight = (tableRef: HTMLTableElement | undefined) => {
61
63
  const tableHeight = tableRef?.clientHeight;
62
64
  let handleHeightSize: HandleHeightSizeType | undefined = 'small';
65
+
66
+ if (!tableHeight) {
67
+ return handleHeightSize;
68
+ }
69
+
63
70
  /*
64
71
  - One row table height (minimum possible table height) ~ 45px
65
72
  - Two row table height ~ 90px
@@ -69,9 +76,9 @@ const getResizerHandleHeight = (tableRef: HTMLTableElement) => {
69
76
  - > 46 because the height of the table can be a float number like 45.44.
70
77
  - < 96 is the height of large resize handle.
71
78
  */
72
- if (tableHeight && tableHeight > 46 && tableHeight < 96) {
79
+ if (tableHeight > 46 && tableHeight < 96) {
73
80
  handleHeightSize = 'medium';
74
- } else if (tableHeight && tableHeight >= 96) {
81
+ } else if (tableHeight >= 96) {
75
82
  handleHeightSize = 'large';
76
83
  }
77
84
 
@@ -115,6 +122,8 @@ export const TableResizer = ({
115
122
  maxWidth,
116
123
  containerWidth,
117
124
  updateWidth,
125
+ onResizeStop,
126
+ onResizeStart,
118
127
  editorView,
119
128
  getPos,
120
129
  node,
@@ -177,7 +186,15 @@ export const TableResizer = ({
177
186
  containerWidth,
178
187
  );
179
188
  setSnappingEnabled(displayGuideline(visibleGuidelines));
180
- }, [displayGuideline, containerWidth, editorView, startMeasure]);
189
+
190
+ onResizeStart();
191
+ }, [
192
+ displayGuideline,
193
+ editorView,
194
+ startMeasure,
195
+ onResizeStart,
196
+ containerWidth,
197
+ ]);
181
198
 
182
199
  const handleResize = useCallback(
183
200
  (originalState, delta) => {
@@ -281,6 +298,8 @@ export const TableResizer = ({
281
298
  updateWidth(newWidth);
282
299
  scheduleResize.cancel();
283
300
 
301
+ onResizeStop();
302
+
284
303
  return newWidth;
285
304
  },
286
305
  [
@@ -293,6 +312,7 @@ export const TableResizer = ({
293
312
  displayGuideline,
294
313
  attachAnalyticsEvent,
295
314
  endMeasure,
315
+ onResizeStop,
296
316
  ],
297
317
  );
298
318