publ-echo 0.0.67 → 0.0.69
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 +34 -92
- package/dist/lib/GridItem/types.d.ts +1 -0
- package/dist/lib/GridLayoutEditor/ReactGridLayout.js +2 -1
- package/dist/lib/Resizable/Resizable.js +1 -7
- package/dist/lib/hooks/useResizeobserver.d.ts +7 -34
- package/dist/lib/hooks/useResizeobserver.js +17 -65
- package/package.json +1 -1
|
@@ -31,8 +31,7 @@ import { useResizeObserver } from "../hooks/useResizeobserver";
|
|
|
31
31
|
import { shouldAutoResize, shouldBlockResize } from "./utils/autoResizeUtils";
|
|
32
32
|
var GridItem = function (_a) {
|
|
33
33
|
var children = _a.children, props = __rest(_a, ["children"]);
|
|
34
|
-
var resizeHandle = props.resizeHandle, cols = props.cols, isDraggable = props.isDraggable, _b = props.transformScale, transformScale = _b === void 0 ? 1 : _b, isResizable = props.isResizable, useCSSTransforms = props.useCSSTransforms, className = props.className, _c = props.cancel, cancel = _c === void 0 ? "" : _c, _d = props.handle, handle = _d === void 0 ? "" : _d, x = props.x, y = props.y, z = props.z, w = props.w, h = props.h, _e = props.minH, minH = _e === void 0 ? 1 : _e, _f = props.minW, minW = _f === void 0 ? 1 : _f, _g = props.maxH, maxH = _g === void 0 ? Infinity : _g, _h = props.maxW, maxW = _h === void 0 ? Infinity : _h, i = props.i, _j = props.isHiddenVisibility, isHiddenVisibility = _j === void 0 ? false : _j, containerWidth = props.containerWidth, customColWidth = props.customColWidth, rowHeight = props.rowHeight;
|
|
35
|
-
var child = React.Children.only(children);
|
|
34
|
+
var resizeHandle = props.resizeHandle, cols = props.cols, isDraggable = props.isDraggable, _b = props.transformScale, transformScale = _b === void 0 ? 1 : _b, isResizable = props.isResizable, useCSSTransforms = props.useCSSTransforms, className = props.className, _c = props.cancel, cancel = _c === void 0 ? "" : _c, _d = props.handle, handle = _d === void 0 ? "" : _d, x = props.x, y = props.y, z = props.z, w = props.w, h = props.h, _e = props.minH, minH = _e === void 0 ? 1 : _e, _f = props.minW, minW = _f === void 0 ? 1 : _f, _g = props.maxH, maxH = _g === void 0 ? Infinity : _g, _h = props.maxW, maxW = _h === void 0 ? Infinity : _h, i = props.i, _j = props.isHiddenVisibility, isHiddenVisibility = _j === void 0 ? false : _j, containerWidth = props.containerWidth, customColWidth = props.customColWidth, rowHeight = props.rowHeight, activeResizeObserver = props.activeResizeObserver;
|
|
36
35
|
var shouldAutoShrink = useRef({ shouldAutoShrink: false, initialHeight: 0 });
|
|
37
36
|
var _k = useState(), resizing = _k[0], setResizing = _k[1];
|
|
38
37
|
var _l = useState(), dragging = _l[0], setDragging = _l[1];
|
|
@@ -40,43 +39,42 @@ var GridItem = function (_a) {
|
|
|
40
39
|
var _o = useState(false), isDragging = _o[0], setIsDragging = _o[1];
|
|
41
40
|
var _p = useState(false), isResizing = _p[0], setIsResizing = _p[1];
|
|
42
41
|
var elementRef = useRef(null);
|
|
43
|
-
var _q = useResizeObserver(
|
|
44
|
-
ref: elementRef,
|
|
45
|
-
box: 'border-box',
|
|
46
|
-
}, [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;
|
|
42
|
+
var _q = useResizeObserver([isDragging, isResizing]), contentHeight = _q.contentHeight, contentWidth = _q.contentWidth, gridItemHeight = _q.gridItemHeight, gridItemWidth = _q.gridItemWidth;
|
|
47
43
|
useEffect(function () {
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
if (isDragging || isResizing) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (!activeResizeObserver) {
|
|
50
48
|
return;
|
|
51
49
|
}
|
|
52
50
|
if (!elementRef.current || !props.onContentSizeChange) {
|
|
53
51
|
return;
|
|
54
52
|
}
|
|
55
|
-
console.log(elementRef.current);
|
|
56
53
|
var observer = new ResizeObserver(function (_a) {
|
|
57
|
-
var _b, _c
|
|
54
|
+
var _b, _c;
|
|
58
55
|
var entry = _a[0];
|
|
59
56
|
var newClientHeight = entry.target.clientHeight;
|
|
60
57
|
var newClientWidth = entry.target.clientWidth;
|
|
61
|
-
var _f = entry.target, clientTop = _f.clientTop, clientLeft = _f.clientLeft;
|
|
62
58
|
var containerHeight = (_c = (_b = elementRef.current) === null || _b === void 0 ? void 0 : _b.clientHeight) !== null && _c !== void 0 ? _c : 0;
|
|
63
|
-
var containerWidth = (_e = (_d = elementRef.current) === null || _d === void 0 ? void 0 : _d.clientWidth) !== null && _e !== void 0 ? _e : 0;
|
|
64
|
-
console.log('entry.target', entry.target);
|
|
65
|
-
console.log('entry.clientHeight', newClientHeight);
|
|
66
|
-
console.log('entry.clientWidth', newClientWidth);
|
|
67
|
-
console.log('container-height', containerHeight);
|
|
68
|
-
console.log('container-width', containerWidth);
|
|
69
59
|
if (newClientHeight < containerHeight) {
|
|
70
60
|
return;
|
|
71
61
|
}
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
// let { w, h } = calcWH(
|
|
63
|
+
// getPositionParams(),
|
|
64
|
+
// { width: newClientWidth, height: newClientHeight },
|
|
65
|
+
// x,
|
|
66
|
+
// y,
|
|
67
|
+
// 'se',
|
|
68
|
+
// props.w,
|
|
69
|
+
// props.h
|
|
70
|
+
// );
|
|
71
|
+
// props.onContentSizeChange(props.i, { x, y, w, h });
|
|
74
72
|
});
|
|
75
73
|
observer.observe(elementRef.current.children[0].children[0].children[0], { box: 'border-box' });
|
|
76
74
|
return function () {
|
|
77
75
|
observer.disconnect();
|
|
78
76
|
};
|
|
79
|
-
}, [
|
|
77
|
+
}, [props.i, props.w, props.h, x, y, activeResizeObserver, isDragging, isResizing]);
|
|
80
78
|
// const moveDroppingItem = (prevProps: GridItemProps) => {
|
|
81
79
|
// const { droppingPosition } = props;
|
|
82
80
|
// if (!droppingPosition) return;
|
|
@@ -150,7 +148,7 @@ var GridItem = function (_a) {
|
|
|
150
148
|
* @param {Object} position Position object (pixel values)
|
|
151
149
|
* @return {Element} Child wrapped in Resizable.
|
|
152
150
|
*/
|
|
153
|
-
var mixinResizable = function (child, position, isResizable
|
|
151
|
+
var mixinResizable = function (child, position, isResizable) {
|
|
154
152
|
var positionParams = getPositionParams();
|
|
155
153
|
// const maxWidth = calcGridItemPosition(
|
|
156
154
|
// positionParams,
|
|
@@ -294,76 +292,18 @@ var GridItem = function (_a) {
|
|
|
294
292
|
* @param {Object} callbackData an object with node and size information
|
|
295
293
|
*/
|
|
296
294
|
var onResizeStart = function (e, callbackData) {
|
|
297
|
-
|
|
298
|
-
|
|
295
|
+
// const isOverflowingVertically = scrollHeight > clientHeight;
|
|
296
|
+
// const isHandleVertical = callbackData.handle.includes('n') || callbackData.handle.includes('s')
|
|
299
297
|
// const isOverflowingHorizontally = scrollWidth > clientWidth;
|
|
300
298
|
// if (isOverflowingVertically && isHandleVertical) {
|
|
301
299
|
// elementRef.current?.classList.add(`resize-notallowed-${callbackData.handle}`)
|
|
302
300
|
// return;
|
|
303
301
|
// }
|
|
304
302
|
onResizeHandler(e, callbackData, "onResizeStart");
|
|
305
|
-
|
|
303
|
+
// NOTE: 확인필요
|
|
304
|
+
shouldAutoShrink.current.initialHeight = gridItemHeight;
|
|
306
305
|
};
|
|
307
|
-
|
|
308
|
-
* onResize event handler
|
|
309
|
-
* @param {ResizeEventType} e event data
|
|
310
|
-
* @param {Object} callbackData an object with node and size information
|
|
311
|
-
*/
|
|
312
|
-
// const onResizeCallback = useCallback((
|
|
313
|
-
// e:ResizeEventType,
|
|
314
|
-
// callbackData:ResizeCallbackData
|
|
315
|
-
// ) => {
|
|
316
|
-
// setIsResizing(true);
|
|
317
|
-
// const { dirX, dirY } = getDirectionOfMouseEvent(e as MouseEvent);
|
|
318
|
-
// const shouldBlock = shouldBlockResize({
|
|
319
|
-
// handle: callbackData.handle,
|
|
320
|
-
// direction: dirY!,
|
|
321
|
-
// contentHeight: textContentHeight!,
|
|
322
|
-
// gridItemHeight: callbackData.size.height,
|
|
323
|
-
// shouldAutoShrink: shouldAutoShrink.current.shouldAutoShrink,
|
|
324
|
-
// initialHeight: shouldAutoShrink.current.initialHeight,
|
|
325
|
-
// colHeight: rowHeight as number
|
|
326
|
-
// })
|
|
327
|
-
// if (resizing?.top) {
|
|
328
|
-
// callbackData.size.top = resizing?.top
|
|
329
|
-
// }
|
|
330
|
-
// const shouldResize = shouldAutoResize({
|
|
331
|
-
// handle: callbackData.handle,
|
|
332
|
-
// dirX: dirX!,
|
|
333
|
-
// dirY: dirY!,
|
|
334
|
-
// contentHeight: textContentHeight!,
|
|
335
|
-
// gridItemHeight: callbackData.size.height,
|
|
336
|
-
// shouldAutoShrink: shouldAutoShrink.current.shouldAutoShrink,
|
|
337
|
-
// initialHeight: shouldAutoShrink.current.initialHeight
|
|
338
|
-
// })
|
|
339
|
-
// console.log(shouldResize)
|
|
340
|
-
// if (shouldResize !== 'EXPAND' && shouldBlock === 'BLOCK') {
|
|
341
|
-
// callbackData.size.height = textContentHeight!;
|
|
342
|
-
// }
|
|
343
|
-
// if (shouldResize === 'EXPAND') {
|
|
344
|
-
// callbackData.size.height = textContentHeight!;
|
|
345
|
-
// shouldAutoShrink.current.shouldAutoShrink = true;
|
|
346
|
-
// // NOTE: 배포전에 무조건 변경
|
|
347
|
-
// if (callbackData.handle === 'nw') {
|
|
348
|
-
// callbackData.handle = 'w';
|
|
349
|
-
// }
|
|
350
|
-
// if (callbackData.handle === 'ne') {
|
|
351
|
-
// callbackData.handle = 'se';
|
|
352
|
-
// }
|
|
353
|
-
// }
|
|
354
|
-
// if (shouldResize === 'SHRINK') {
|
|
355
|
-
// callbackData.size.height = Math.max(shouldAutoShrink.current.initialHeight, textContentHeight!);
|
|
356
|
-
// // NOTE: 배포전에 무조건 변경
|
|
357
|
-
// if (callbackData.handle === 'nw') {
|
|
358
|
-
// callbackData.handle = 'sw'
|
|
359
|
-
// }
|
|
360
|
-
// if (callbackData.handle === 'ne') {
|
|
361
|
-
// callbackData.handle = 'se'
|
|
362
|
-
// }
|
|
363
|
-
// }
|
|
364
|
-
// onResizeHandler(e, callbackData, "onResize");
|
|
365
|
-
// }, [textContentHeight])
|
|
366
|
-
var onResize = function (e, callbackData, contentSize) {
|
|
306
|
+
var onResize = function (e, callbackData) {
|
|
367
307
|
var _a;
|
|
368
308
|
setIsResizing(true);
|
|
369
309
|
var _b = getDirectionOfMouseEvent(e), dirX = _b.dirX, dirY = _b.dirY;
|
|
@@ -372,14 +312,14 @@ var GridItem = function (_a) {
|
|
|
372
312
|
handle: callbackData.handle,
|
|
373
313
|
dirY: dirY,
|
|
374
314
|
dirX: dirX,
|
|
375
|
-
contentHeight:
|
|
315
|
+
contentHeight: contentHeight,
|
|
376
316
|
gridItemHeight: callbackData.size.height,
|
|
377
317
|
shouldAutoShrink: shouldAutoShrink.current.shouldAutoShrink,
|
|
378
318
|
initialHeight: shouldAutoShrink.current.initialHeight,
|
|
379
319
|
colHeight: rowHeight,
|
|
380
320
|
gridItemWidth: callbackData.size.width,
|
|
381
321
|
colWidth: colWidth,
|
|
382
|
-
contentWidth:
|
|
322
|
+
contentWidth: contentWidth,
|
|
383
323
|
oneLetterSize: oneLetterSize
|
|
384
324
|
});
|
|
385
325
|
if (resizing === null || resizing === void 0 ? void 0 : resizing.top) {
|
|
@@ -389,19 +329,20 @@ var GridItem = function (_a) {
|
|
|
389
329
|
handle: callbackData.handle,
|
|
390
330
|
dirX: dirX,
|
|
391
331
|
dirY: dirY,
|
|
392
|
-
contentHeight:
|
|
332
|
+
contentHeight: contentHeight,
|
|
393
333
|
gridItemHeight: callbackData.size.height,
|
|
394
334
|
shouldAutoShrink: shouldAutoShrink.current.shouldAutoShrink,
|
|
395
335
|
initialHeight: shouldAutoShrink.current.initialHeight
|
|
396
336
|
});
|
|
397
337
|
if (shouldResize !== 'EXPAND' && shouldBlock === 'BLOCK-HEIGHT') {
|
|
398
|
-
callbackData.size.height =
|
|
338
|
+
callbackData.size.height = contentHeight;
|
|
399
339
|
}
|
|
400
340
|
if (shouldResize !== 'EXPAND' && shouldBlock === 'BLOCK-WIDTH') {
|
|
401
|
-
|
|
341
|
+
// console.log('hold width', contentSize)
|
|
342
|
+
callbackData.size.width = contentWidth;
|
|
402
343
|
}
|
|
403
344
|
if (shouldResize === 'EXPAND') {
|
|
404
|
-
callbackData.size.height =
|
|
345
|
+
callbackData.size.height = contentHeight;
|
|
405
346
|
shouldAutoShrink.current.shouldAutoShrink = true;
|
|
406
347
|
// NOTE: 배포전에 무조건 변경
|
|
407
348
|
if (callbackData.handle === 'nw') {
|
|
@@ -412,7 +353,7 @@ var GridItem = function (_a) {
|
|
|
412
353
|
}
|
|
413
354
|
}
|
|
414
355
|
if (shouldResize === 'SHRINK') {
|
|
415
|
-
callbackData.size.height = Math.max(shouldAutoShrink.current.initialHeight,
|
|
356
|
+
callbackData.size.height = Math.max(shouldAutoShrink.current.initialHeight, contentHeight);
|
|
416
357
|
// NOTE: 배포전에 무조건 변경
|
|
417
358
|
if (callbackData.handle === 'nw') {
|
|
418
359
|
callbackData.handle = 'sw';
|
|
@@ -471,6 +412,7 @@ var GridItem = function (_a) {
|
|
|
471
412
|
dragging: dragging,
|
|
472
413
|
resizing: resizing,
|
|
473
414
|
}, colWidth);
|
|
415
|
+
var child = React.Children.only(children);
|
|
474
416
|
var newChild = React.cloneElement(child, {
|
|
475
417
|
key: i,
|
|
476
418
|
ref: elementRef,
|
|
@@ -491,7 +433,7 @@ var GridItem = function (_a) {
|
|
|
491
433
|
if (className === 'placeholder') {
|
|
492
434
|
return newChild;
|
|
493
435
|
}
|
|
494
|
-
newChild = mixinResizable(newChild, pos, isResizable
|
|
436
|
+
newChild = mixinResizable(newChild, pos, isResizable);
|
|
495
437
|
newChild = mixinDraggable(newChild, isDraggable);
|
|
496
438
|
return newChild;
|
|
497
439
|
};
|
|
@@ -279,6 +279,7 @@ var ReactGridLayout = function (_a) {
|
|
|
279
279
|
return;
|
|
280
280
|
}
|
|
281
281
|
setLayout(newLayout);
|
|
282
|
+
props.onLayoutChange && props.onLayoutChange(newLayout);
|
|
282
283
|
};
|
|
283
284
|
var onResizeHandler = function (i, w, h, _a, x, y) {
|
|
284
285
|
var e = _a.e, node = _a.node;
|
|
@@ -392,7 +393,7 @@ var ReactGridLayout = function (_a) {
|
|
|
392
393
|
: !l.static && isResizable;
|
|
393
394
|
var resizeHandlesOptions = l.resizeHandles || resizeHandles;
|
|
394
395
|
var bounded = draggable && isBounded && l.isBounded !== false;
|
|
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));
|
|
396
|
+
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, activeResizeObserver: child.props.className === 'react-grid-item-selected', children: child }, l.i));
|
|
396
397
|
};
|
|
397
398
|
var onDragOverHandler = function (e) {
|
|
398
399
|
var _a;
|
|
@@ -34,7 +34,6 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
34
34
|
import React, { useRef } from "react";
|
|
35
35
|
import DraggableCore from "../Draggable/DraggableCore";
|
|
36
36
|
import { cloneElement } from "./utils/cloneElement";
|
|
37
|
-
import { useResizeObserver } from "../hooks/useResizeobserver";
|
|
38
37
|
var Resizable = function (_a) {
|
|
39
38
|
var children = _a.children, _b = _a.axis, axis = _b === void 0 ? "both" : _b, _c = _a.handleSize, handleSize = _c === void 0 ? [20, 20] : _c, _d = _a.lockAspectRatio, lockAspectRatio = _d === void 0 ? false : _d, _e = _a.minConstraints, minConstraints = _e === void 0 ? [20, 20] : _e, _f = _a.maxConstraints, maxConstraints = _f === void 0 ? [Infinity, Infinity] : _f, _g = _a.resizeHandles, resizeHandles = _g === void 0 ? ["se"] : _g, _h = _a.transformScale, transformScale = _h === void 0 ? 1 : _h, props = __rest(_a, ["children", "axis", "handleSize", "lockAspectRatio", "minConstraints", "maxConstraints", "resizeHandles", "transformScale"]);
|
|
40
39
|
var handleRefs = useRef({
|
|
@@ -47,11 +46,6 @@ var Resizable = function (_a) {
|
|
|
47
46
|
ne: useRef(null),
|
|
48
47
|
nw: useRef(null),
|
|
49
48
|
});
|
|
50
|
-
var elementRef = useRef({ isOkay: true });
|
|
51
|
-
var _j = useResizeObserver({
|
|
52
|
-
ref: elementRef,
|
|
53
|
-
box: 'border-box',
|
|
54
|
-
}, [props.onResize]), contentHeight = _j.contentHeight, contentWidth = _j.contentWidth;
|
|
55
49
|
var startPosition = useRef(null);
|
|
56
50
|
var startSize = useRef(null);
|
|
57
51
|
var lastHandleRect = null;
|
|
@@ -215,7 +209,7 @@ var Resizable = function (_a) {
|
|
|
215
209
|
React.Children.map(children.props.children, function (child) { return child; })
|
|
216
210
|
], resizeHandles.map(function (handleAxis) {
|
|
217
211
|
var ref = (handleRefs === null || handleRefs === void 0 ? void 0 : handleRefs.current) && handleRefs.current[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
|
|
212
|
+
return (_createElement(DraggableCore, __assign({}, draggableOpts, { nodeRef: ref, key: "resizableHandle-".concat(handleAxis), onStop: resizeHandler("onResizeStop", handleAxis), onStart: resizeHandler("onResizeStart", handleAxis), onDrag: resizeHandler("onResize", handleAxis) }), renderResizeHandle(handleAxis, ref)));
|
|
219
213
|
}), true) }));
|
|
220
214
|
};
|
|
221
215
|
export default Resizable;
|
|
@@ -1,43 +1,16 @@
|
|
|
1
1
|
import type { RefObject } from 'react';
|
|
2
2
|
type Size = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
scrollHeight: number
|
|
6
|
-
clientHeight: number
|
|
7
|
-
contentHeight: number
|
|
8
|
-
contentWidth: number
|
|
9
|
-
};
|
|
10
|
-
type ResizeHandler = (size: Size) => void;
|
|
11
|
-
type BoxOptions = 'border-box' | 'content-box' | 'device-pixel-content-box';
|
|
12
|
-
type UseResizeObserverOptions<T extends HTMLElement = HTMLElement> = {
|
|
13
|
-
ref: RefObject<T>;
|
|
14
|
-
onResize?: ResizeHandler;
|
|
15
|
-
box?: BoxOptions;
|
|
3
|
+
gridItemWidth: number;
|
|
4
|
+
gridItemHeight: number;
|
|
5
|
+
scrollHeight: number;
|
|
6
|
+
clientHeight: number;
|
|
7
|
+
contentHeight: number;
|
|
8
|
+
contentWidth: number;
|
|
16
9
|
};
|
|
17
10
|
type UseResizeObserverResult = Size & {
|
|
18
11
|
myHeightRef: RefObject<{
|
|
19
12
|
myHeight: number;
|
|
20
13
|
}>;
|
|
21
14
|
};
|
|
22
|
-
|
|
23
|
-
* Custom hook for observing the size of an element using the ResizeObserver API.
|
|
24
|
-
*
|
|
25
|
-
* @template T - The type of the element to observe.
|
|
26
|
-
* @param {UseResizeObserverOptions<T>} options - The options for the ResizeObserver. (default is `{}`).
|
|
27
|
-
* @param {RefObject<T>} options.ref - The ref of the element to observe.
|
|
28
|
-
* @param {ResizeHandler} [options.onResize] - When using `onResize`, the hook doesn't re-render on element size changes; it delegates handling to the provided callback . (default is `undefined`).
|
|
29
|
-
* @param {string} [options.box] - The box model to use for the ResizeObserver. (default is `'content-box'`).
|
|
30
|
-
* @returns {UseResizeObserverResult} - The size of the observed element.
|
|
31
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-resize-observer)
|
|
32
|
-
* @see [MDN ResizeObserver API](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)
|
|
33
|
-
* @example
|
|
34
|
-
* const myRef = useRef(null);
|
|
35
|
-
* const { width = 0, height = 0 } = useResizeObserver({
|
|
36
|
-
* ref: myRef,
|
|
37
|
-
* box: 'content-box',
|
|
38
|
-
* });
|
|
39
|
-
*
|
|
40
|
-
* <div ref={myRef}>Hello, world!</div>
|
|
41
|
-
*/
|
|
42
|
-
export declare function useResizeObserver<T extends HTMLElement = HTMLElement>(options: UseResizeObserverOptions<T>, deps: any[]): UseResizeObserverResult;
|
|
15
|
+
export declare function useResizeObserver(deps: any[]): UseResizeObserverResult;
|
|
43
16
|
export {};
|
|
@@ -21,44 +21,19 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
21
21
|
import { useLayoutEffect, useRef, useState } from 'react';
|
|
22
22
|
import { useIsMounted } from './useIsMounted';
|
|
23
23
|
var initialSize = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
scrollHeight:
|
|
27
|
-
clientHeight:
|
|
28
|
-
contentHeight:
|
|
29
|
-
contentWidth:
|
|
24
|
+
gridItemWidth: 0,
|
|
25
|
+
gridItemHeight: 0,
|
|
26
|
+
scrollHeight: 0,
|
|
27
|
+
clientHeight: 0,
|
|
28
|
+
contentHeight: 0,
|
|
29
|
+
contentWidth: 0,
|
|
30
30
|
};
|
|
31
|
-
|
|
32
|
-
* Custom hook for observing the size of an element using the ResizeObserver API.
|
|
33
|
-
*
|
|
34
|
-
* @template T - The type of the element to observe.
|
|
35
|
-
* @param {UseResizeObserverOptions<T>} options - The options for the ResizeObserver. (default is `{}`).
|
|
36
|
-
* @param {RefObject<T>} options.ref - The ref of the element to observe.
|
|
37
|
-
* @param {ResizeHandler} [options.onResize] - When using `onResize`, the hook doesn't re-render on element size changes; it delegates handling to the provided callback . (default is `undefined`).
|
|
38
|
-
* @param {string} [options.box] - The box model to use for the ResizeObserver. (default is `'content-box'`).
|
|
39
|
-
* @returns {UseResizeObserverResult} - The size of the observed element.
|
|
40
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-resize-observer)
|
|
41
|
-
* @see [MDN ResizeObserver API](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)
|
|
42
|
-
* @example
|
|
43
|
-
* const myRef = useRef(null);
|
|
44
|
-
* const { width = 0, height = 0 } = useResizeObserver({
|
|
45
|
-
* ref: myRef,
|
|
46
|
-
* box: 'content-box',
|
|
47
|
-
* });
|
|
48
|
-
*
|
|
49
|
-
* <div ref={myRef}>Hello, world!</div>
|
|
50
|
-
*/
|
|
51
|
-
export function useResizeObserver(options, deps) {
|
|
52
|
-
var ref = options.ref, _a = options.box, box = _a === void 0 ? 'content-box' : _a;
|
|
31
|
+
export function useResizeObserver(deps) {
|
|
53
32
|
var previousSize = useRef(initialSize);
|
|
54
|
-
var
|
|
33
|
+
var _a = useState(initialSize), size = _a[0], setSize = _a[1];
|
|
55
34
|
var refvalue = useRef({ myHeight: 0 });
|
|
56
35
|
var isMounted = useIsMounted();
|
|
57
|
-
var onResize = useRef(undefined);
|
|
58
|
-
onResize.current = options === null || options === void 0 ? void 0 : options.onResize;
|
|
59
36
|
useLayoutEffect(function () {
|
|
60
|
-
if (!(ref === null || ref === void 0 ? void 0 : ref.current))
|
|
61
|
-
return;
|
|
62
37
|
var placeholder = document.querySelector('.placeholder');
|
|
63
38
|
if (!placeholder) {
|
|
64
39
|
return;
|
|
@@ -67,47 +42,24 @@ export function useResizeObserver(options, deps) {
|
|
|
67
42
|
return;
|
|
68
43
|
}
|
|
69
44
|
var observer = new ResizeObserver(function (_a) {
|
|
70
|
-
var _b, _c, _d, _e
|
|
45
|
+
var _b, _c, _d, _e;
|
|
71
46
|
var entry = _a[0];
|
|
72
|
-
var
|
|
73
|
-
|
|
74
|
-
: box === 'device-pixel-content-box'
|
|
75
|
-
? 'devicePixelContentBoxSize'
|
|
76
|
-
: 'contentBoxSize';
|
|
77
|
-
var newWidth = extractSize(entry, boxProp, 'inlineSize');
|
|
78
|
-
var newHeight = extractSize(entry, boxProp, 'blockSize');
|
|
47
|
+
var newWidth = extractSize(entry, 'contentBoxSize', 'inlineSize');
|
|
48
|
+
var newHeight = extractSize(entry, 'borderBoxSize', 'blockSize');
|
|
79
49
|
var newScrollHeight = entry.target.scrollHeight;
|
|
80
50
|
var newClientHeight = entry.target.clientHeight;
|
|
81
|
-
var newContentHeight = (
|
|
82
|
-
var newContentWidth = (
|
|
51
|
+
var newContentHeight = (_c = (_b = entry.target.children[0]) === null || _b === void 0 ? void 0 : _b.children[0]) === null || _c === void 0 ? void 0 : _c.clientHeight;
|
|
52
|
+
var newContentWidth = (_e = (_d = entry.target.children[0]) === null || _d === void 0 ? void 0 : _d.children[0]) === null || _e === void 0 ? void 0 : _e.clientWidth;
|
|
83
53
|
refvalue.current.myHeight = newContentHeight;
|
|
84
|
-
|
|
85
|
-
// previousSize.current.width !== newWidth ||
|
|
86
|
-
// previousSize.current.height !== newHeight ||
|
|
87
|
-
// previousSize.current.scrollHeight !== newScrollHeight ||
|
|
88
|
-
// previousSize.current.clientHeight !== newClientHeight ||
|
|
89
|
-
// previousSize.current.textContentHeight !== newTextContentHeight
|
|
90
|
-
var newSize = { width: newWidth, height: newHeight, scrollHeight: newScrollHeight, clientHeight: newClientHeight, contentHeight: newContentHeight, contentWidth: newContentWidth };
|
|
54
|
+
var newSize = { gridItemWidth: newWidth, gridItemHeight: newHeight, scrollHeight: newScrollHeight, clientHeight: newClientHeight, contentHeight: newContentHeight, contentWidth: newContentWidth };
|
|
91
55
|
previousSize.current = newSize;
|
|
92
56
|
setSize(newSize);
|
|
93
|
-
// if (hasChanged) {
|
|
94
|
-
// const newSize: Size = { width: newWidth, height: newHeight, scrollHeight: newScrollHeight, clientHeight: newClientHeight, textContentHeight: newTextContentHeight }
|
|
95
|
-
// previousSize.current = newSize;
|
|
96
|
-
// if (onResize?.current) {
|
|
97
|
-
// onResize.current(newSize)
|
|
98
|
-
// } else {
|
|
99
|
-
// if (isMounted()) {
|
|
100
|
-
// console.log('set- new -size')
|
|
101
|
-
// setSize(newSize)
|
|
102
|
-
// }
|
|
103
|
-
// }
|
|
104
|
-
// }
|
|
105
57
|
});
|
|
106
|
-
observer.observe(placeholder.children[0], { box: box });
|
|
58
|
+
observer.observe(placeholder.children[0], { box: 'border-box' });
|
|
107
59
|
return function () {
|
|
108
60
|
observer.disconnect();
|
|
109
61
|
};
|
|
110
|
-
}, __spreadArray([
|
|
62
|
+
}, __spreadArray([isMounted], deps, true));
|
|
111
63
|
return __assign(__assign({}, size), { myHeightRef: refvalue });
|
|
112
64
|
}
|
|
113
65
|
function extractSize(entry, box, sizeType) {
|
|
@@ -115,7 +67,7 @@ function extractSize(entry, box, sizeType) {
|
|
|
115
67
|
if (box === 'contentBoxSize') {
|
|
116
68
|
return entry.contentRect[sizeType === 'inlineSize' ? 'width' : 'height'];
|
|
117
69
|
}
|
|
118
|
-
return
|
|
70
|
+
return 0;
|
|
119
71
|
}
|
|
120
72
|
return Array.isArray(entry[box])
|
|
121
73
|
? entry[box][0][sizeType]
|