publ-echo 0.0.62 → 0.0.64
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/dist/lib/GridItem/GridItem.js +48 -14
- package/dist/lib/GridItem/types.d.ts +1 -0
- package/dist/lib/GridItem/utils/autoResizeUtils.d.ts +7 -2
- package/dist/lib/GridItem/utils/autoResizeUtils.js +14 -7
- package/dist/lib/GridItem/utils/calculateUtils.d.ts +1 -0
- package/dist/lib/GridItem/utils/calculateUtils.js +28 -0
- package/dist/lib/GridLayoutEditor/ReactGridLayout.js +15 -1
- package/dist/lib/Resizable/Resizable.js +5 -6
- package/dist/lib/Resizable/types.d.ts +4 -1
- package/dist/lib/hooks/useResizeobserver.d.ts +2 -1
- package/dist/lib/hooks/useResizeobserver.js +8 -7
- package/package.json +1 -1
|
@@ -21,10 +21,10 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
return t;
|
|
22
22
|
};
|
|
23
23
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
|
-
import React, { useRef, useState } from "react";
|
|
24
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
25
25
|
import { DraggableCore } from "../Draggable";
|
|
26
26
|
import classNames from "../../external-lib/classnames";
|
|
27
|
-
import { calcGridColWidth, calcGridItemPosition, calcGridItemWHPx, calcWH, calcXY, clamp, resolveRowHeight, } from "./utils/calculateUtils";
|
|
27
|
+
import { calcGridColWidth, calcGridItemPosition, calcGridItemWHPx, calcWH, calcXY, calculateCharacterWidthInDiv, clamp, resolveRowHeight, } from "./utils/calculateUtils";
|
|
28
28
|
import { perc, setTopLeft, setTransform, } from "../GridLayoutEditor/utils/renderHelpers";
|
|
29
29
|
import { Resizable } from "../Resizable";
|
|
30
30
|
import { useResizeObserver } from "../hooks/useResizeobserver";
|
|
@@ -42,7 +42,31 @@ var GridItem = function (_a) {
|
|
|
42
42
|
var _q = useResizeObserver({
|
|
43
43
|
ref: elementRef,
|
|
44
44
|
box: 'border-box',
|
|
45
|
-
}, [isDragging, isResizing]), _r = _q.width, width = _r === void 0 ? 0 : _r, _s = _q.height, height = _s === void 0 ? 0 : _s, _t = _q.clientHeight, clientHeight = _t === void 0 ? 0 : _t, _u = _q.scrollHeight, scrollHeight = _u === void 0 ? 0 : _u, textContentHeight = _q.
|
|
45
|
+
}, [isDragging, isResizing]), _r = _q.width, width = _r === void 0 ? 0 : _r, _s = _q.height, height = _s === void 0 ? 0 : _s, _t = _q.clientHeight, clientHeight = _t === void 0 ? 0 : _t, _u = _q.scrollHeight, scrollHeight = _u === void 0 ? 0 : _u, textContentHeight = _q.contentHeight;
|
|
46
|
+
useEffect(function () {
|
|
47
|
+
if (!elementRef.current || !props.onContentSizeChange) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
var observer = new ResizeObserver(function (_a) {
|
|
51
|
+
var _b, _c, _d, _e;
|
|
52
|
+
var entry = _a[0];
|
|
53
|
+
var newClientHeight = entry.target.clientHeight;
|
|
54
|
+
var newClientWidth = entry.target.clientWidth;
|
|
55
|
+
var _f = entry.target, clientTop = _f.clientTop, clientLeft = _f.clientLeft;
|
|
56
|
+
var containerHeight = (_c = (_b = elementRef.current) === null || _b === void 0 ? void 0 : _b.clientHeight) !== null && _c !== void 0 ? _c : 0;
|
|
57
|
+
var containerWidth = (_e = (_d = elementRef.current) === null || _d === void 0 ? void 0 : _d.clientWidth) !== null && _e !== void 0 ? _e : 0;
|
|
58
|
+
if (newClientHeight < containerHeight && newClientWidth < containerWidth) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
var _g = calcWH(getPositionParams(), { width: newClientWidth, height: newClientHeight }, x, y, 'se', props.w, props.h), w = _g.w, h = _g.h;
|
|
62
|
+
props.onContentSizeChange(props.i, { x: x, y: y, w: w, h: h });
|
|
63
|
+
});
|
|
64
|
+
observer.observe(elementRef.current.children[0].children[0].children[0], { box: 'border-box' });
|
|
65
|
+
return function () {
|
|
66
|
+
observer.disconnect();
|
|
67
|
+
};
|
|
68
|
+
}, [scrollHeight, props]);
|
|
69
|
+
console.log(textContentHeight);
|
|
46
70
|
// const moveDroppingItem = (prevProps: GridItemProps) => {
|
|
47
71
|
// const { droppingPosition } = props;
|
|
48
72
|
// if (!droppingPosition) return;
|
|
@@ -331,17 +355,24 @@ var GridItem = function (_a) {
|
|
|
331
355
|
// }
|
|
332
356
|
// onResizeHandler(e, callbackData, "onResize");
|
|
333
357
|
// }, [textContentHeight])
|
|
334
|
-
var onResize = function (e, callbackData,
|
|
358
|
+
var onResize = function (e, callbackData, contentSize) {
|
|
359
|
+
var _a;
|
|
335
360
|
setIsResizing(true);
|
|
336
|
-
var
|
|
361
|
+
var _b = getDirectionOfMouseEvent(e), dirX = _b.dirX, dirY = _b.dirY;
|
|
362
|
+
var oneLetterSize = (_a = calculateCharacterWidthInDiv()) !== null && _a !== void 0 ? _a : 0;
|
|
337
363
|
var shouldBlock = shouldBlockResize({
|
|
338
364
|
handle: callbackData.handle,
|
|
339
|
-
|
|
340
|
-
|
|
365
|
+
dirY: dirY,
|
|
366
|
+
dirX: dirX,
|
|
367
|
+
contentHeight: contentSize === null || contentSize === void 0 ? void 0 : contentSize.height,
|
|
341
368
|
gridItemHeight: callbackData.size.height,
|
|
342
369
|
shouldAutoShrink: shouldAutoShrink.current.shouldAutoShrink,
|
|
343
370
|
initialHeight: shouldAutoShrink.current.initialHeight,
|
|
344
|
-
colHeight: rowHeight
|
|
371
|
+
colHeight: rowHeight,
|
|
372
|
+
gridItemWidth: callbackData.size.width,
|
|
373
|
+
colWidth: colWidth,
|
|
374
|
+
contentWidth: contentSize === null || contentSize === void 0 ? void 0 : contentSize.width,
|
|
375
|
+
oneLetterSize: oneLetterSize
|
|
345
376
|
});
|
|
346
377
|
if (resizing === null || resizing === void 0 ? void 0 : resizing.top) {
|
|
347
378
|
callbackData.size.top = resizing === null || resizing === void 0 ? void 0 : resizing.top;
|
|
@@ -350,17 +381,19 @@ var GridItem = function (_a) {
|
|
|
350
381
|
handle: callbackData.handle,
|
|
351
382
|
dirX: dirX,
|
|
352
383
|
dirY: dirY,
|
|
353
|
-
contentHeight:
|
|
384
|
+
contentHeight: contentSize === null || contentSize === void 0 ? void 0 : contentSize.height,
|
|
354
385
|
gridItemHeight: callbackData.size.height,
|
|
355
386
|
shouldAutoShrink: shouldAutoShrink.current.shouldAutoShrink,
|
|
356
387
|
initialHeight: shouldAutoShrink.current.initialHeight
|
|
357
388
|
});
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
389
|
+
if (shouldResize !== 'EXPAND' && shouldBlock === 'BLOCK-HEIGHT') {
|
|
390
|
+
callbackData.size.height = contentSize === null || contentSize === void 0 ? void 0 : contentSize.height;
|
|
391
|
+
}
|
|
392
|
+
if (shouldResize !== 'EXPAND' && shouldBlock === 'BLOCK-WIDTH') {
|
|
393
|
+
callbackData.size.width = contentSize === null || contentSize === void 0 ? void 0 : contentSize.width;
|
|
361
394
|
}
|
|
362
395
|
if (shouldResize === 'EXPAND') {
|
|
363
|
-
callbackData.size.height =
|
|
396
|
+
callbackData.size.height = contentSize === null || contentSize === void 0 ? void 0 : contentSize.height;
|
|
364
397
|
shouldAutoShrink.current.shouldAutoShrink = true;
|
|
365
398
|
// NOTE: 배포전에 무조건 변경
|
|
366
399
|
if (callbackData.handle === 'nw') {
|
|
@@ -371,7 +404,7 @@ var GridItem = function (_a) {
|
|
|
371
404
|
}
|
|
372
405
|
}
|
|
373
406
|
if (shouldResize === 'SHRINK') {
|
|
374
|
-
callbackData.size.height = Math.max(shouldAutoShrink.current.initialHeight,
|
|
407
|
+
callbackData.size.height = Math.max(shouldAutoShrink.current.initialHeight, contentSize === null || contentSize === void 0 ? void 0 : contentSize.height);
|
|
375
408
|
// NOTE: 배포전에 무조건 변경
|
|
376
409
|
if (callbackData.handle === 'nw') {
|
|
377
410
|
callbackData.handle = 'sw';
|
|
@@ -447,6 +480,7 @@ var GridItem = function (_a) {
|
|
|
447
480
|
}),
|
|
448
481
|
style: __assign(__assign(__assign({}, props.style), child.props.style), createStyle(pos)),
|
|
449
482
|
});
|
|
483
|
+
// NOTE: 제외
|
|
450
484
|
if (className === 'placeholder') {
|
|
451
485
|
return newChild;
|
|
452
486
|
}
|
|
@@ -75,6 +75,7 @@ export type GridItemProps = {
|
|
|
75
75
|
onResize?: ResizeGridItemCallback<GridResizeEvent>;
|
|
76
76
|
onResizeStart?: ResizeGridItemCallback<GridResizeEvent>;
|
|
77
77
|
onResizeStop?: ResizeGridItemCallback<GridResizeEvent>;
|
|
78
|
+
onContentSizeChange?: any;
|
|
78
79
|
isHiddenVisibility?: boolean;
|
|
79
80
|
customColWidth?: number;
|
|
80
81
|
};
|
|
@@ -13,12 +13,17 @@ type Props = {
|
|
|
13
13
|
export declare function shouldAutoResize({ handle, dirX, dirY, contentHeight, gridItemHeight, shouldAutoShrink, initialHeight }: Props): "SHRINK" | "EXPAND" | "NONE";
|
|
14
14
|
type BlockDetectProp = {
|
|
15
15
|
handle: Handle;
|
|
16
|
-
|
|
16
|
+
dirY: DirectionY;
|
|
17
|
+
dirX: DirectionX;
|
|
17
18
|
contentHeight: number;
|
|
18
19
|
gridItemHeight: number;
|
|
19
20
|
shouldAutoShrink: boolean;
|
|
20
21
|
initialHeight: number;
|
|
21
22
|
colHeight: number;
|
|
23
|
+
gridItemWidth: number;
|
|
24
|
+
colWidth: number;
|
|
25
|
+
contentWidth: number;
|
|
26
|
+
oneLetterSize: number;
|
|
22
27
|
};
|
|
23
|
-
export declare function shouldBlockResize({ handle,
|
|
28
|
+
export declare function shouldBlockResize({ handle, dirY, dirX, contentHeight, gridItemHeight, shouldAutoShrink, initialHeight, colHeight, gridItemWidth, colWidth, contentWidth, oneLetterSize }: BlockDetectProp): "NONE" | "BLOCK-HEIGHT" | "BLOCK-WIDTH";
|
|
24
29
|
export {};
|
|
@@ -28,15 +28,22 @@ export function shouldAutoResize(_a) {
|
|
|
28
28
|
return 'NONE';
|
|
29
29
|
}
|
|
30
30
|
export function shouldBlockResize(_a) {
|
|
31
|
-
var handle = _a.handle,
|
|
31
|
+
var handle = _a.handle, dirY = _a.dirY, dirX = _a.dirX, contentHeight = _a.contentHeight, gridItemHeight = _a.gridItemHeight, shouldAutoShrink = _a.shouldAutoShrink, initialHeight = _a.initialHeight, colHeight = _a.colHeight, gridItemWidth = _a.gridItemWidth, colWidth = _a.colWidth, contentWidth = _a.contentWidth, oneLetterSize = _a.oneLetterSize;
|
|
32
32
|
var nextGridHeight = gridItemHeight - colHeight;
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
var shouldBlockHeight = contentHeight > nextGridHeight;
|
|
34
|
+
var nextGridWidth = gridItemWidth - colWidth;
|
|
35
|
+
var shouldBlockWidth = oneLetterSize > nextGridWidth;
|
|
36
|
+
if (handle.includes('n') && dirY === 'down' && shouldBlockHeight) {
|
|
37
|
+
return 'BLOCK-HEIGHT';
|
|
38
|
+
}
|
|
39
|
+
if (handle.includes('s') && dirY === 'up' && shouldBlockHeight) {
|
|
40
|
+
return 'BLOCK-HEIGHT';
|
|
41
|
+
}
|
|
42
|
+
if (handle.includes('e') && dirX === 'left' && shouldBlockWidth) {
|
|
43
|
+
return 'BLOCK-WIDTH';
|
|
37
44
|
}
|
|
38
|
-
if (handle.includes('
|
|
39
|
-
return 'BLOCK';
|
|
45
|
+
if (handle.includes('w') && dirX === 'right' && shouldBlockWidth) {
|
|
46
|
+
return 'BLOCK-WIDTH';
|
|
40
47
|
}
|
|
41
48
|
// if (handle.includes('e') && direction === 'right' && shouldShrink && shouldAutoShrink) {
|
|
42
49
|
// return 'SHRINK';
|
|
@@ -28,3 +28,4 @@ export declare function calcWH(positionParams: PositionParams, { width, height }
|
|
|
28
28
|
h: number;
|
|
29
29
|
};
|
|
30
30
|
export declare function clamp(num: number, lowerBound: number, upperBound: number): number;
|
|
31
|
+
export declare function calculateCharacterWidthInDiv(): number | undefined;
|
|
@@ -106,3 +106,31 @@ export function calcWH(positionParams, _a, x, y, handleAxis, prevW, prevH) {
|
|
|
106
106
|
export function clamp(num, lowerBound, upperBound) {
|
|
107
107
|
return Math.max(Math.min(num, upperBound), lowerBound);
|
|
108
108
|
}
|
|
109
|
+
export function calculateCharacterWidthInDiv() {
|
|
110
|
+
var _a, _b, _c, _d;
|
|
111
|
+
var div = document.querySelector('.react-grid-item.isResizing');
|
|
112
|
+
if (!div)
|
|
113
|
+
return;
|
|
114
|
+
var contentDiv = (_b = (_a = div.children[0]) === null || _a === void 0 ? void 0 : _a.children[0]) === null || _b === void 0 ? void 0 : _b.children[0];
|
|
115
|
+
if (!contentDiv)
|
|
116
|
+
return;
|
|
117
|
+
// Clone the contentDiv for measurement
|
|
118
|
+
var span = document.createElement('span');
|
|
119
|
+
document.body.appendChild(span);
|
|
120
|
+
// Use a sample character for measurement
|
|
121
|
+
span.textContent = (_d = (_c = contentDiv.textContent) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : 'M';
|
|
122
|
+
// Apply necessary styles to mimic the original environment
|
|
123
|
+
// Note: Add any other styles that affect text size and rendering
|
|
124
|
+
var computedStyle = window.getComputedStyle(contentDiv);
|
|
125
|
+
span.style.fontFamily = computedStyle.fontFamily;
|
|
126
|
+
span.style.fontSize = computedStyle.fontSize;
|
|
127
|
+
span.style.fontWeight = computedStyle.fontWeight;
|
|
128
|
+
span.style.letterSpacing = computedStyle.letterSpacing;
|
|
129
|
+
span.style.padding = computedStyle.padding;
|
|
130
|
+
span.style.border = computedStyle.border;
|
|
131
|
+
span.style.position = 'absolute';
|
|
132
|
+
span.style.visibility = 'hidden';
|
|
133
|
+
var spanWidth = span.getBoundingClientRect().width;
|
|
134
|
+
document.body.removeChild(span);
|
|
135
|
+
return spanWidth;
|
|
136
|
+
}
|
|
@@ -266,6 +266,20 @@ var ReactGridLayout = function (_a) {
|
|
|
266
266
|
node: node,
|
|
267
267
|
});
|
|
268
268
|
};
|
|
269
|
+
// NOTE: 임시
|
|
270
|
+
var onContentSizeChange = function (i, pos) {
|
|
271
|
+
var _a = withLayoutItem(layout, i, function (l) {
|
|
272
|
+
l.w = pos.w;
|
|
273
|
+
l.h = pos.h;
|
|
274
|
+
l.x = pos.x;
|
|
275
|
+
l.y = pos.y;
|
|
276
|
+
return l;
|
|
277
|
+
}), newLayout = _a[0], l = _a[1];
|
|
278
|
+
if (!l) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
setLayout(newLayout);
|
|
282
|
+
};
|
|
269
283
|
var onResizeHandler = function (i, w, h, _a, x, y) {
|
|
270
284
|
var e = _a.e, node = _a.node;
|
|
271
285
|
var _b = withLayoutItem(layout, i, function (l) {
|
|
@@ -378,7 +392,7 @@ var ReactGridLayout = function (_a) {
|
|
|
378
392
|
: !l.static && isResizable;
|
|
379
393
|
var resizeHandlesOptions = l.resizeHandles || resizeHandles;
|
|
380
394
|
var bounded = draggable && isBounded && l.isBounded !== false;
|
|
381
|
-
return (_jsx(GridItem, { className: "i-am-grid-item", containerWidth: width, cols: cols, margin: margin, containerPadding: containerPadding || margin, maxRows: maxRows, rowHeight: rowHeight, cancel: draggableCancel, handle: draggableHandle, onDragStop: onDragStopHandler, onDragStart: onDragStartHandler, onDrag: onDragHandler, onResizeStart: onResizeStartHandler, onResize: onResizeHandler, onResizeStop: onResizeStopHandler, isDraggable: draggable, isResizable: resizable, isBounded: bounded, useCSSTransforms: useCSSTransforms && isMounted, usePercentages: !isMounted, transformScale: transformScale, w: l.w, h: l.h, x: l.x, y: l.y, z: l.z || 0, i: l.i, minH: l.minH, minW: l.minW, maxH: l.maxH, maxW: l.maxW, static: l.static, droppingPosition: isDroppingItem ? droppingPosition : undefined, resizeHandles: resizeHandlesOptions, resizeHandle: resizeHandle, isHiddenVisibility: isHiddenVisibility, customColWidth: colWidth, children: child }, l.i));
|
|
395
|
+
return (_jsx(GridItem, { className: "i-am-grid-item", containerWidth: width, cols: cols, margin: margin, containerPadding: containerPadding || margin, maxRows: maxRows, rowHeight: rowHeight, cancel: draggableCancel, handle: draggableHandle, onDragStop: onDragStopHandler, onDragStart: onDragStartHandler, onDrag: onDragHandler, onResizeStart: onResizeStartHandler, onResize: onResizeHandler, onResizeStop: onResizeStopHandler, onContentSizeChange: onContentSizeChange, isDraggable: draggable, isResizable: resizable, isBounded: bounded, useCSSTransforms: useCSSTransforms && isMounted, usePercentages: !isMounted, transformScale: transformScale, w: l.w, h: l.h, x: l.x, y: l.y, z: l.z || 0, i: l.i, minH: l.minH, minW: l.minW, maxH: l.maxH, maxW: l.maxW, static: l.static, droppingPosition: isDroppingItem ? droppingPosition : undefined, resizeHandles: resizeHandlesOptions, resizeHandle: resizeHandle, isHiddenVisibility: isHiddenVisibility, customColWidth: colWidth, children: child }, l.i));
|
|
382
396
|
};
|
|
383
397
|
var onDragOverHandler = function (e) {
|
|
384
398
|
var _a;
|
|
@@ -51,8 +51,7 @@ var Resizable = function (_a) {
|
|
|
51
51
|
var _j = useResizeObserver({
|
|
52
52
|
ref: elementRef,
|
|
53
53
|
box: 'border-box',
|
|
54
|
-
}, [props.onResize]),
|
|
55
|
-
console.log("%c ".concat(textContentHeight), 'background: #ff0000; color: #ffffff');
|
|
54
|
+
}, [props.onResize]), contentHeight = _j.contentHeight, contentWidth = _j.contentWidth;
|
|
56
55
|
var startPosition = useRef(null);
|
|
57
56
|
var startSize = useRef(null);
|
|
58
57
|
var lastHandleRect = null;
|
|
@@ -133,8 +132,8 @@ var Resizable = function (_a) {
|
|
|
133
132
|
}
|
|
134
133
|
return [newTop, newLeft];
|
|
135
134
|
};
|
|
136
|
-
var resizeHandler = function (handlerName, handleAxis,
|
|
137
|
-
return function (e, _a
|
|
135
|
+
var resizeHandler = function (handlerName, handleAxis, contentSize) {
|
|
136
|
+
return function (e, _a) {
|
|
138
137
|
var _b, _c;
|
|
139
138
|
var _d, _e, _f, _g, _h, _j;
|
|
140
139
|
var node = _a.node, deltaX = _a.deltaX, deltaY = _a.deltaY;
|
|
@@ -191,7 +190,7 @@ var Resizable = function (_a) {
|
|
|
191
190
|
var cb = typeof props[handlerName] === "function" ? props[handlerName] : null;
|
|
192
191
|
var isCbSkipped = handlerName === "onResize" && !isDimensionsChanged;
|
|
193
192
|
if (cb && !isCbSkipped) {
|
|
194
|
-
cb(e, { node: node, size: { width: width, height: height, top: top, left: left }, handle: handleAxis },
|
|
193
|
+
cb(e, { node: node, size: { width: width, height: height, top: top, left: left }, handle: handleAxis }, contentSize);
|
|
195
194
|
}
|
|
196
195
|
if (handlerName === "onResizeStop") {
|
|
197
196
|
startPosition.current = null;
|
|
@@ -216,7 +215,7 @@ var Resizable = function (_a) {
|
|
|
216
215
|
React.Children.map(children.props.children, function (child) { return child; })
|
|
217
216
|
], resizeHandles.map(function (handleAxis) {
|
|
218
217
|
var ref = (handleRefs === null || handleRefs === void 0 ? void 0 : handleRefs.current) && handleRefs.current[handleAxis];
|
|
219
|
-
return (_createElement(DraggableCore, __assign({}, draggableOpts, { nodeRef: ref, key: "resizableHandle-".concat(handleAxis), onStop: resizeHandler("onResizeStop", handleAxis), onStart: resizeHandler("onResizeStart", handleAxis), onDrag: resizeHandler("onResize", handleAxis,
|
|
218
|
+
return (_createElement(DraggableCore, __assign({}, draggableOpts, { nodeRef: ref, key: "resizableHandle-".concat(handleAxis), onStop: resizeHandler("onResizeStop", handleAxis), onStart: resizeHandler("onResizeStart", handleAxis), onDrag: resizeHandler("onResize", handleAxis, { height: contentHeight !== null && contentHeight !== void 0 ? contentHeight : 0, width: contentWidth !== null && contentWidth !== void 0 ? contentWidth : 0 }) }), renderResizeHandle(handleAxis, ref)));
|
|
220
219
|
}), true) }));
|
|
221
220
|
};
|
|
222
221
|
export default Resizable;
|
|
@@ -49,7 +49,10 @@ export type ResizableProps = {
|
|
|
49
49
|
handle?: ResizeHandleType;
|
|
50
50
|
onResizeStop?: (e: SyntheticEvent<any>, data: ResizeCallbackData) => any;
|
|
51
51
|
onResizeStart?: (e: SyntheticEvent<any>, data: ResizeCallbackData) => any;
|
|
52
|
-
onResize?: (e: SyntheticEvent<any>, data: ResizeCallbackData,
|
|
52
|
+
onResize?: (e: SyntheticEvent<any>, data: ResizeCallbackData, contentSize?: {
|
|
53
|
+
height: number;
|
|
54
|
+
width: number;
|
|
55
|
+
}) => any;
|
|
53
56
|
handleSize?: [number, number];
|
|
54
57
|
lockAspectRatio?: boolean;
|
|
55
58
|
minConstraints?: [number, number];
|
|
@@ -4,7 +4,8 @@ type Size = {
|
|
|
4
4
|
height: number | undefined;
|
|
5
5
|
scrollHeight: number | undefined;
|
|
6
6
|
clientHeight: number | undefined;
|
|
7
|
-
|
|
7
|
+
contentHeight: number | undefined;
|
|
8
|
+
contentWidth: number | undefined;
|
|
8
9
|
};
|
|
9
10
|
type ResizeHandler = (size: Size) => void;
|
|
10
11
|
type BoxOptions = 'border-box' | 'content-box' | 'device-pixel-content-box';
|
|
@@ -25,7 +25,8 @@ var initialSize = {
|
|
|
25
25
|
height: undefined,
|
|
26
26
|
scrollHeight: undefined,
|
|
27
27
|
clientHeight: undefined,
|
|
28
|
-
|
|
28
|
+
contentHeight: undefined,
|
|
29
|
+
contentWidth: undefined,
|
|
29
30
|
};
|
|
30
31
|
/**
|
|
31
32
|
* Custom hook for observing the size of an element using the ResizeObserver API.
|
|
@@ -49,10 +50,10 @@ var initialSize = {
|
|
|
49
50
|
*/
|
|
50
51
|
export function useResizeObserver(options, deps) {
|
|
51
52
|
var ref = options.ref, _a = options.box, box = _a === void 0 ? 'content-box' : _a;
|
|
53
|
+
var previousSize = useRef(initialSize);
|
|
52
54
|
var _b = useState(initialSize), size = _b[0], setSize = _b[1];
|
|
53
55
|
var refvalue = useRef({ myHeight: 0 });
|
|
54
56
|
var isMounted = useIsMounted();
|
|
55
|
-
var previousSize = useRef(__assign({}, initialSize));
|
|
56
57
|
var onResize = useRef(undefined);
|
|
57
58
|
onResize.current = options === null || options === void 0 ? void 0 : options.onResize;
|
|
58
59
|
useLayoutEffect(function () {
|
|
@@ -66,7 +67,7 @@ export function useResizeObserver(options, deps) {
|
|
|
66
67
|
return;
|
|
67
68
|
}
|
|
68
69
|
var observer = new ResizeObserver(function (_a) {
|
|
69
|
-
var _b, _c, _d;
|
|
70
|
+
var _b, _c, _d, _e, _f, _g;
|
|
70
71
|
var entry = _a[0];
|
|
71
72
|
var boxProp = box === 'border-box'
|
|
72
73
|
? 'borderBoxSize'
|
|
@@ -77,15 +78,16 @@ export function useResizeObserver(options, deps) {
|
|
|
77
78
|
var newHeight = extractSize(entry, boxProp, 'blockSize');
|
|
78
79
|
var newScrollHeight = entry.target.scrollHeight;
|
|
79
80
|
var newClientHeight = entry.target.clientHeight;
|
|
80
|
-
var
|
|
81
|
-
|
|
81
|
+
var newContentHeight = (_d = (_c = (_b = entry.target.children[0]) === null || _b === void 0 ? void 0 : _b.children[0]) === null || _c === void 0 ? void 0 : _c.clientHeight) !== null && _d !== void 0 ? _d : 0;
|
|
82
|
+
var newContentWidth = (_g = (_f = (_e = entry.target.children[0]) === null || _e === void 0 ? void 0 : _e.children[0]) === null || _f === void 0 ? void 0 : _f.clientWidth) !== null && _g !== void 0 ? _g : 0;
|
|
83
|
+
refvalue.current.myHeight = newContentHeight;
|
|
82
84
|
// const hasChanged =
|
|
83
85
|
// previousSize.current.width !== newWidth ||
|
|
84
86
|
// previousSize.current.height !== newHeight ||
|
|
85
87
|
// previousSize.current.scrollHeight !== newScrollHeight ||
|
|
86
88
|
// previousSize.current.clientHeight !== newClientHeight ||
|
|
87
89
|
// previousSize.current.textContentHeight !== newTextContentHeight
|
|
88
|
-
var newSize = { width: newWidth, height: newHeight, scrollHeight: newScrollHeight, clientHeight: newClientHeight,
|
|
90
|
+
var newSize = { width: newWidth, height: newHeight, scrollHeight: newScrollHeight, clientHeight: newClientHeight, contentHeight: newContentHeight, contentWidth: newContentWidth };
|
|
89
91
|
previousSize.current = newSize;
|
|
90
92
|
setSize(newSize);
|
|
91
93
|
// if (hasChanged) {
|
|
@@ -106,7 +108,6 @@ export function useResizeObserver(options, deps) {
|
|
|
106
108
|
observer.disconnect();
|
|
107
109
|
};
|
|
108
110
|
}, __spreadArray([box, ref, isMounted], deps, true));
|
|
109
|
-
console.log('--SIZE FROM OBSERVER--', size.textContentHeight);
|
|
110
111
|
return __assign(__assign({}, size), { myHeightRef: refvalue });
|
|
111
112
|
}
|
|
112
113
|
function extractSize(entry, box, sizeType) {
|