publ-echo 0.0.72 → 0.0.74
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 +35 -23
- package/dist/lib/GridItem/types.d.ts +1 -0
- package/dist/lib/GridLayoutEditor/ReactGridLayout.js +3 -5
- package/dist/lib/Resizable/Resizable.js +28 -2
- package/dist/lib/Resizable/types.d.ts +1 -0
- package/dist/lib/hooks/useResizeobserver.d.ts +0 -2
- package/dist/lib/hooks/useResizeobserver.js +1 -4
- package/package.json +1 -1
|
@@ -21,7 +21,7 @@ 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, { useEffect, useRef, useState } from "react";
|
|
24
|
+
import React, { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
25
25
|
import { DraggableCore } from "../Draggable";
|
|
26
26
|
import classNames from "../../external-lib/classnames";
|
|
27
27
|
import { calcGridColWidth, calcGridItemPosition, calcGridItemWHPx, calcWH, calcXY, calculateCharacterWidthInDiv, clamp, resolveRowHeight, } from "./utils/calculateUtils";
|
|
@@ -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, activeResizeObserver = props.activeResizeObserver;
|
|
35
|
-
console.log(i, activeResizeObserver);
|
|
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, activeContentObserver = props.activeContentObserver;
|
|
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,11 +39,26 @@ 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([isDragging, isResizing]),
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
var _q = useResizeObserver([isDragging, isResizing]), gridItemHeight = _q.gridItemHeight, gridItemWidth = _q.gridItemWidth;
|
|
43
|
+
var _r = useState(false), isHovered = _r[0], setIsHovered = _r[1];
|
|
44
|
+
useLayoutEffect(function () {
|
|
45
|
+
var node = elementRef.current;
|
|
46
|
+
if (!node) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
var handleMouseEnter = function () { return setIsHovered(true); };
|
|
50
|
+
var handleMouseLeave = function () { return setIsHovered(false); };
|
|
51
|
+
node.addEventListener('mouseenter', handleMouseEnter);
|
|
52
|
+
node.addEventListener('mouseleave', handleMouseLeave);
|
|
53
|
+
return function () {
|
|
54
|
+
node.removeEventListener('mouseenter', handleMouseEnter);
|
|
55
|
+
node.removeEventListener('mouseleave', handleMouseLeave);
|
|
56
|
+
};
|
|
57
|
+
}, []);
|
|
47
58
|
useEffect(function () {
|
|
59
|
+
if (isHovered) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
48
62
|
if (isDragging || isResizing) {
|
|
49
63
|
return;
|
|
50
64
|
}
|
|
@@ -70,7 +84,7 @@ var GridItem = function (_a) {
|
|
|
70
84
|
return function () {
|
|
71
85
|
observer.disconnect();
|
|
72
86
|
};
|
|
73
|
-
}, [props.i, props.w, props.h, x, y, activeResizeObserver, isDragging, isResizing]);
|
|
87
|
+
}, [props.i, props.w, props.h, x, y, activeResizeObserver, isDragging, isResizing, isHovered]);
|
|
74
88
|
// const moveDroppingItem = (prevProps: GridItemProps) => {
|
|
75
89
|
// const { droppingPosition } = props;
|
|
76
90
|
// if (!droppingPosition) return;
|
|
@@ -163,7 +177,7 @@ var GridItem = function (_a) {
|
|
|
163
177
|
];
|
|
164
178
|
return (_jsx(Resizable, { draggableOpts: {
|
|
165
179
|
disabled: !isResizable,
|
|
166
|
-
}, className: isResizable ? undefined : "react-resizable-hide", width: position.width, height: position.height, top: position.top, left: position.left, minConstraints: minConstraints, maxConstraints: maxConstraints, onResizeStop: onResizeStop, onResizeStart: onResizeStart, onResize: onResize, transformScale: transformScale, resizeHandles: props.resizeHandles, handle: resizeHandle, children: child }));
|
|
180
|
+
}, className: isResizable ? undefined : "react-resizable-hide", width: position.width, height: position.height, top: position.top, left: position.left, minConstraints: minConstraints, maxConstraints: maxConstraints, onResizeStop: onResizeStop, onResizeStart: onResizeStart, onResize: onResize, transformScale: transformScale, resizeHandles: props.resizeHandles, handle: resizeHandle, placeholderObserver: activeResizeObserver, children: child }));
|
|
167
181
|
};
|
|
168
182
|
/**
|
|
169
183
|
* onDragStart event handler
|
|
@@ -299,23 +313,24 @@ var GridItem = function (_a) {
|
|
|
299
313
|
// NOTE: 확인필요
|
|
300
314
|
shouldAutoShrink.current.initialHeight = gridItemHeight;
|
|
301
315
|
};
|
|
302
|
-
var onResize = function (e, callbackData) {
|
|
303
|
-
var _a;
|
|
316
|
+
var onResize = function (e, callbackData, contentSize) {
|
|
317
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
318
|
+
console.log(contentSize);
|
|
304
319
|
setIsResizing(true);
|
|
305
|
-
var
|
|
320
|
+
var _j = getDirectionOfMouseEvent(e), dirX = _j.dirX, dirY = _j.dirY;
|
|
306
321
|
var oneLetterSize = (_a = calculateCharacterWidthInDiv()) !== null && _a !== void 0 ? _a : 0;
|
|
307
322
|
var shouldBlock = shouldBlockResize({
|
|
308
323
|
handle: callbackData.handle,
|
|
309
324
|
dirY: dirY,
|
|
310
325
|
dirX: dirX,
|
|
311
|
-
contentHeight:
|
|
326
|
+
contentHeight: (_b = contentSize === null || contentSize === void 0 ? void 0 : contentSize.height) !== null && _b !== void 0 ? _b : 0,
|
|
312
327
|
gridItemHeight: callbackData.size.height,
|
|
313
328
|
shouldAutoShrink: shouldAutoShrink.current.shouldAutoShrink,
|
|
314
329
|
initialHeight: shouldAutoShrink.current.initialHeight,
|
|
315
330
|
colHeight: rowHeight,
|
|
316
331
|
gridItemWidth: callbackData.size.width,
|
|
317
332
|
colWidth: colWidth,
|
|
318
|
-
contentWidth:
|
|
333
|
+
contentWidth: (_c = contentSize === null || contentSize === void 0 ? void 0 : contentSize.width) !== null && _c !== void 0 ? _c : 0,
|
|
319
334
|
oneLetterSize: oneLetterSize
|
|
320
335
|
});
|
|
321
336
|
if (resizing === null || resizing === void 0 ? void 0 : resizing.top) {
|
|
@@ -325,19 +340,19 @@ var GridItem = function (_a) {
|
|
|
325
340
|
handle: callbackData.handle,
|
|
326
341
|
dirX: dirX,
|
|
327
342
|
dirY: dirY,
|
|
328
|
-
contentHeight:
|
|
343
|
+
contentHeight: (_d = contentSize === null || contentSize === void 0 ? void 0 : contentSize.height) !== null && _d !== void 0 ? _d : 0,
|
|
329
344
|
gridItemHeight: callbackData.size.height,
|
|
330
345
|
shouldAutoShrink: shouldAutoShrink.current.shouldAutoShrink,
|
|
331
346
|
initialHeight: shouldAutoShrink.current.initialHeight
|
|
332
347
|
});
|
|
333
348
|
if (shouldResize !== 'EXPAND' && shouldBlock === 'BLOCK-HEIGHT') {
|
|
334
|
-
callbackData.size.height =
|
|
349
|
+
callbackData.size.height = (_e = contentSize === null || contentSize === void 0 ? void 0 : contentSize.height) !== null && _e !== void 0 ? _e : 0;
|
|
335
350
|
}
|
|
336
351
|
if (shouldResize !== 'EXPAND' && shouldBlock === 'BLOCK-WIDTH') {
|
|
337
|
-
callbackData.size.width =
|
|
352
|
+
callbackData.size.width = (_f = contentSize === null || contentSize === void 0 ? void 0 : contentSize.width) !== null && _f !== void 0 ? _f : 0;
|
|
338
353
|
}
|
|
339
354
|
if (shouldResize === 'EXPAND') {
|
|
340
|
-
callbackData.size.height =
|
|
355
|
+
callbackData.size.height = (_g = contentSize === null || contentSize === void 0 ? void 0 : contentSize.height) !== null && _g !== void 0 ? _g : 0;
|
|
341
356
|
shouldAutoShrink.current.shouldAutoShrink = true;
|
|
342
357
|
// NOTE: 배포전에 무조건 변경
|
|
343
358
|
if (callbackData.handle === 'nw') {
|
|
@@ -348,7 +363,7 @@ var GridItem = function (_a) {
|
|
|
348
363
|
}
|
|
349
364
|
}
|
|
350
365
|
if (shouldResize === 'SHRINK') {
|
|
351
|
-
callbackData.size.height = Math.max(shouldAutoShrink.current.initialHeight,
|
|
366
|
+
callbackData.size.height = Math.max(shouldAutoShrink.current.initialHeight, (_h = contentSize === null || contentSize === void 0 ? void 0 : contentSize.height) !== null && _h !== void 0 ? _h : 0);
|
|
352
367
|
// NOTE: 배포전에 무조건 변경
|
|
353
368
|
if (callbackData.handle === 'nw') {
|
|
354
369
|
callbackData.handle = 'sw';
|
|
@@ -357,10 +372,6 @@ var GridItem = function (_a) {
|
|
|
357
372
|
callbackData.handle = 'se';
|
|
358
373
|
}
|
|
359
374
|
}
|
|
360
|
-
if (activeResizeObserver) {
|
|
361
|
-
console.log('shouldResize', shouldResize);
|
|
362
|
-
console.log('shouldBlock', shouldBlock);
|
|
363
|
-
}
|
|
364
375
|
onResizeHandler(e, callbackData, "onResize");
|
|
365
376
|
};
|
|
366
377
|
/**
|
|
@@ -432,6 +443,7 @@ var GridItem = function (_a) {
|
|
|
432
443
|
if (className === 'placeholder') {
|
|
433
444
|
return newChild;
|
|
434
445
|
}
|
|
446
|
+
console.log(activeResizeObserver);
|
|
435
447
|
newChild = mixinResizable(newChild, pos, isResizable);
|
|
436
448
|
newChild = mixinDraggable(newChild, isDraggable);
|
|
437
449
|
return newChild;
|
|
@@ -370,7 +370,9 @@ var ReactGridLayout = function (_a) {
|
|
|
370
370
|
if (!item) {
|
|
371
371
|
return null;
|
|
372
372
|
}
|
|
373
|
-
return (_jsx(GridItem, { w: activeDrag.w, h: activeDrag.h, x: activeDrag.x, y: activeDrag.y, z: activeDrag.z || 0, i: activeDrag.i, className: "placeholder", containerWidth: width, cols: cols, margin: margin, containerPadding: containerPadding || margin, maxRows: maxRows, rowHeight: rowHeight, isDraggable: false, isResizable: false, isBounded: false, useCSSTransforms: useCSSTransforms, transformScale: transformScale,
|
|
373
|
+
return (_jsx(GridItem, { w: activeDrag.w, h: activeDrag.h, x: activeDrag.x, y: activeDrag.y, z: activeDrag.z || 0, i: activeDrag.i, className: "placeholder", containerWidth: width, cols: cols, margin: margin, containerPadding: containerPadding || margin, maxRows: maxRows, rowHeight: rowHeight, isDraggable: false, isResizable: false, isBounded: false, useCSSTransforms: useCSSTransforms, transformScale: transformScale,
|
|
374
|
+
// NOTE: text CB만
|
|
375
|
+
activeContentObserver: true, children: item && item }));
|
|
374
376
|
};
|
|
375
377
|
/**
|
|
376
378
|
* Given a grid item, set its style attributes & surround in a <Draggable>.
|
|
@@ -393,10 +395,6 @@ var ReactGridLayout = function (_a) {
|
|
|
393
395
|
: !l.static && isResizable;
|
|
394
396
|
var resizeHandlesOptions = l.resizeHandles || resizeHandles;
|
|
395
397
|
var bounded = draggable && isBounded && l.isBounded !== false;
|
|
396
|
-
console.log('------');
|
|
397
|
-
console.log('i', l.i);
|
|
398
|
-
console.log('child.props.className', child.props.className);
|
|
399
|
-
console.log('------');
|
|
400
398
|
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));
|
|
401
399
|
};
|
|
402
400
|
var onDragOverHandler = function (e) {
|
|
@@ -31,11 +31,12 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
31
31
|
};
|
|
32
32
|
import { createElement as _createElement } from "react";
|
|
33
33
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
34
|
-
import React, { useRef } from "react";
|
|
34
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
35
35
|
import DraggableCore from "../Draggable/DraggableCore";
|
|
36
36
|
import { cloneElement } from "./utils/cloneElement";
|
|
37
37
|
var Resizable = function (_a) {
|
|
38
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"]);
|
|
39
|
+
var placeholderObserver = props.placeholderObserver;
|
|
39
40
|
var handleRefs = useRef({
|
|
40
41
|
s: useRef(null),
|
|
41
42
|
n: useRef(null),
|
|
@@ -50,6 +51,31 @@ var Resizable = function (_a) {
|
|
|
50
51
|
var startSize = useRef(null);
|
|
51
52
|
var lastHandleRect = null;
|
|
52
53
|
var slack = null;
|
|
54
|
+
var _j = useState({ width: 0, height: 0 }), content = _j[0], setContent = _j[1];
|
|
55
|
+
var placeholder = document.querySelector('.placeholder');
|
|
56
|
+
useEffect(function () {
|
|
57
|
+
var _a;
|
|
58
|
+
if (!placeholderObserver) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (!placeholder) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
var content = (_a = placeholder.children[0].children[0]) === null || _a === void 0 ? void 0 : _a.children[0];
|
|
65
|
+
if (!content) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
var observer = new ResizeObserver(function (_a) {
|
|
69
|
+
var entry = _a[0];
|
|
70
|
+
var contentHeight = entry.target.clientHeight;
|
|
71
|
+
var contentWidth = entry.target.clientWidth;
|
|
72
|
+
setContent({ width: contentWidth, height: contentHeight });
|
|
73
|
+
});
|
|
74
|
+
observer.observe(content, { box: 'border-box' });
|
|
75
|
+
return function () {
|
|
76
|
+
observer.disconnect();
|
|
77
|
+
};
|
|
78
|
+
}, [placeholderObserver, placeholder]);
|
|
53
79
|
var className = props.className, draggableOpts = props.draggableOpts, width = props.width, height = props.height, handle = props.handle, onResize = props.onResize, onResizeStop = props.onResizeStop, onResizeStart = props.onResizeStart, restProps = __rest(props, ["className", "draggableOpts", "width", "height", "handle", "onResize", "onResizeStop", "onResizeStart"]);
|
|
54
80
|
var resetData = function () {
|
|
55
81
|
lastHandleRect = slack = null;
|
|
@@ -209,7 +235,7 @@ var Resizable = function (_a) {
|
|
|
209
235
|
React.Children.map(children.props.children, function (child) { return child; })
|
|
210
236
|
], resizeHandles.map(function (handleAxis) {
|
|
211
237
|
var ref = (handleRefs === null || handleRefs === void 0 ? void 0 : handleRefs.current) && handleRefs.current[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)));
|
|
238
|
+
return (_createElement(DraggableCore, __assign({}, draggableOpts, { nodeRef: ref, key: "resizableHandle-".concat(handleAxis), onStop: resizeHandler("onResizeStop", handleAxis), onStart: resizeHandler("onResizeStart", handleAxis), onDrag: resizeHandler("onResize", handleAxis, content) }), renderResizeHandle(handleAxis, ref)));
|
|
213
239
|
}), true) }));
|
|
214
240
|
};
|
|
215
241
|
export default Resizable;
|
|
@@ -62,5 +62,6 @@ export type ResizableProps = {
|
|
|
62
62
|
style?: CSSProperties;
|
|
63
63
|
width: number;
|
|
64
64
|
height: number;
|
|
65
|
+
placeholderObserver?: boolean;
|
|
65
66
|
};
|
|
66
67
|
export type ResizeHandleType = ReactElement<any> | ((resizeHandleAxis: ResizeHandleAxis, ref: Ref<HTMLElement>) => ReactElement<any>);
|
|
@@ -25,8 +25,6 @@ var initialSize = {
|
|
|
25
25
|
gridItemHeight: 0,
|
|
26
26
|
scrollHeight: 0,
|
|
27
27
|
clientHeight: 0,
|
|
28
|
-
contentHeight: 0,
|
|
29
|
-
contentWidth: 0,
|
|
30
28
|
};
|
|
31
29
|
export function useResizeObserver(deps) {
|
|
32
30
|
var previousSize = useRef(initialSize);
|
|
@@ -50,9 +48,8 @@ export function useResizeObserver(deps) {
|
|
|
50
48
|
var newClientHeight = entry.target.clientHeight;
|
|
51
49
|
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
50
|
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;
|
|
53
|
-
console.log('in observer effect', newContentHeight, newContentWidth);
|
|
54
51
|
refvalue.current.myHeight = newContentHeight;
|
|
55
|
-
var newSize = { gridItemWidth: newWidth, gridItemHeight: newHeight, scrollHeight: newScrollHeight, clientHeight: newClientHeight
|
|
52
|
+
var newSize = { gridItemWidth: newWidth, gridItemHeight: newHeight, scrollHeight: newScrollHeight, clientHeight: newClientHeight };
|
|
56
53
|
previousSize.current = newSize;
|
|
57
54
|
setSize(newSize);
|
|
58
55
|
});
|