publ-echo 0.0.85 → 0.0.91

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.
@@ -21,21 +21,77 @@ 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
27
  import { calcGridColWidth, calcGridItemPosition, calcGridItemWHPx, calcWH, calcXY, clamp, resolveRowHeight, } from "./utils/calculateUtils";
28
28
  import { perc, setTopLeft, setTransform, } from "../GridLayoutEditor/utils/renderHelpers";
29
29
  import { Resizable } from "../Resizable";
30
30
  var GridItem = function (_a) {
31
+ var _b;
31
32
  var children = _a.children, props = __rest(_a, ["children"]);
32
- 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;
33
- var _k = useState(), resizing = _k[0], setResizing = _k[1];
34
- var _l = useState(), dragging = _l[0], setDragging = _l[1];
35
- var _m = useState(), dragStart = _m[0], setDragStart = _m[1];
36
- var _o = useState(false), isDragging = _o[0], setIsDragging = _o[1];
37
- var _p = useState(false), isResizing = _p[0], setIsResizing = _p[1];
33
+ var resizeHandle = props.resizeHandle, cols = props.cols, isDraggable = props.isDraggable, _c = props.transformScale, transformScale = _c === void 0 ? 1 : _c, isResizable = props.isResizable, useCSSTransforms = props.useCSSTransforms, className = props.className, _d = props.cancel, cancel = _d === void 0 ? "" : _d, _e = props.handle, handle = _e === void 0 ? "" : _e, x = props.x, y = props.y, z = props.z, w = props.w, h = props.h, _f = props.minH, minH = _f === void 0 ? 1 : _f, _g = props.minW, minW = _g === void 0 ? 1 : _g, _h = props.maxH, maxH = _h === void 0 ? Infinity : _h, _j = props.maxW, maxW = _j === void 0 ? Infinity : _j, i = props.i, _k = props.isHiddenVisibility, isHiddenVisibility = _k === void 0 ? false : _k, containerWidth = props.containerWidth, customColWidth = props.customColWidth, autoResize = props.autoResize;
34
+ var _l = useState(), resizing = _l[0], setResizing = _l[1];
35
+ var _m = useState(), dragging = _m[0], setDragging = _m[1];
36
+ var _o = useState(), dragStart = _o[0], setDragStart = _o[1];
37
+ var _p = useState(false), isDragging = _p[0], setIsDragging = _p[1];
38
+ var _q = useState(false), isResizing = _q[0], setIsResizing = _q[1];
38
39
  var elementRef = useRef(null);
40
+ var isSelected = (_b = elementRef.current) === null || _b === void 0 ? void 0 : _b.classList.contains('react-grid-item-selected');
41
+ useEffect(function () {
42
+ var _a;
43
+ if (!isSelected || !autoResize) {
44
+ return;
45
+ }
46
+ var targetNode = (_a = elementRef.current) === null || _a === void 0 ? void 0 : _a.children[0].children[0].children[0];
47
+ if (!targetNode || isDragging || isResizing) {
48
+ return;
49
+ }
50
+ // MutationObserver 콜백 함수
51
+ var callback = function (mutationsList) {
52
+ for (var _i = 0, mutationsList_1 = mutationsList; _i < mutationsList_1.length; _i++) {
53
+ var mutation = mutationsList_1[_i];
54
+ var isCharacterChanged = mutation.type === 'characterData';
55
+ var keepWidth = true;
56
+ var height = isCharacterChanged ? mutation.target.parentNode.clientHeight : mutation.target.clientHeight;
57
+ var width = targetNode.clientWidth;
58
+ if (!isCharacterChanged && mutation.target instanceof Element) {
59
+ var styles = getComputedStyle(mutation.target);
60
+ var minWidth = parseFloat(styles.minWidth);
61
+ if (minWidth > width) {
62
+ keepWidth = false;
63
+ }
64
+ }
65
+ var prevW = props.w;
66
+ var prevH = props.h;
67
+ var _a = calcWH(getPositionParams(), {
68
+ width: width,
69
+ height: height,
70
+ }, x, y, 'e', props.w, props.h, true), w_1 = _a.w, h_1 = _a.h;
71
+ if (keepWidth) {
72
+ w_1 = prevW;
73
+ }
74
+ if (prevH > h_1) {
75
+ h_1 = prevH;
76
+ }
77
+ var _b = getResizableXYPosition('e', w_1, h_1, prevW, prevH), newX = _b.newX, newY = _b.newY;
78
+ if (prevH === h_1 && prevW === w_1 && newX === x && newY === y) {
79
+ return;
80
+ }
81
+ props.onFitToContent && props.onFitToContent(i, w_1, h_1, newX, newY);
82
+ }
83
+ };
84
+ // MutationObserver 인스턴스 생성
85
+ var observer = new MutationObserver(callback);
86
+ // 관찰할 DOM 변이 설정
87
+ var config = { characterData: true, attributes: true, subtree: true };
88
+ // 대상 노드와 설정으로 관찰 시작
89
+ observer.observe(targetNode, config);
90
+ // 정리 함수에서 MutationObserver 해제
91
+ return function () {
92
+ observer.disconnect();
93
+ };
94
+ }, [autoResize, isSelected, isDragging, isResizing, props.w, props.h, x, y]);
39
95
  // const moveDroppingItem = (prevProps: GridItemProps) => {
40
96
  // const { droppingPosition } = props;
41
97
  // if (!droppingPosition) return;
@@ -128,7 +184,7 @@ var GridItem = function (_a) {
128
184
  ];
129
185
  return (_jsx(Resizable, { draggableOpts: {
130
186
  disabled: !isResizable,
131
- }, 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 }));
187
+ }, className: isResizable ? undefined : "react-resizable-hide", width: position.width, height: position.height, top: position.top, left: position.left, resizeHandles: props.resizeHandles, onResizeStop: onResizeStop, onResizeStart: onResizeStart, onResize: onResize, minConstraints: minConstraints, maxConstraints: maxConstraints, transformScale: transformScale, handle: resizeHandle, isResizing: isResizing, autoResize: autoResize, children: child }));
132
188
  };
133
189
  /**
134
190
  * onDragStart event handler
@@ -282,21 +338,31 @@ var GridItem = function (_a) {
282
338
  * @return {Function} Handler function.
283
339
  */
284
340
  var onResizeHandler = function (e, _a, handlerName) {
285
- var node = _a.node, size = _a.size, handle = _a.handle;
341
+ var node = _a.node, size = _a.size, handle = _a.handle, minWidth = _a.minWidth, minHeight = _a.minHeight;
286
342
  var handler = props[handlerName];
287
343
  if (!handler)
288
344
  return;
289
345
  var prevW = props.w, prevH = props.h;
290
346
  // Get new XY
291
- var _b = calcWH(getPositionParams(), size, x, y, handle, prevW, prevH), w = _b.w, h = _b.h;
347
+ var _b = calcWH(getPositionParams(), size, x, y, handle, prevW, prevH, false), w = _b.w, h = _b.h;
348
+ var tempMinH = minH;
349
+ if (minWidth) {
350
+ var _c = calcWH(getPositionParams(), __assign(__assign({}, size), { width: minWidth, height: minHeight !== null && minHeight !== void 0 ? minHeight : 0 }), x, y, handle, prevW, prevH, true), minW_1 = _c.w, newMinH = _c.h;
351
+ if (minW_1 > w) {
352
+ w = minW_1;
353
+ }
354
+ if (minH > 1) {
355
+ tempMinH = Math.max(1, newMinH);
356
+ }
357
+ }
292
358
  // minW should be at least 1
293
359
  // minW = Math.max(minW, 1);
294
360
  // maxW should be at most (cols - x)
295
361
  // maxW = Math.min(maxW, cols - x);
296
362
  w = clamp(w, minW, maxW);
297
- h = clamp(h, minH, maxH);
363
+ h = clamp(h, tempMinH, maxH);
298
364
  setResizing(handlerName === "onResizeStop" ? undefined : size);
299
- var _c = getResizableXYPosition(handle, w, h, prevW, prevH), newX = _c.newX, newY = _c.newY;
365
+ var _d = getResizableXYPosition(handle, w, h, prevW, prevH), newX = _d.newX, newY = _d.newY;
300
366
  handler(i, w, h, { e: e, node: node, size: size }, newX, newY);
301
367
  };
302
368
  var pos = calcGridItemPosition(getPositionParams(), x, y, z, w, h, {
@@ -75,9 +75,10 @@ export type GridItemProps = {
75
75
  onResize?: ResizeGridItemCallback<GridResizeEvent>;
76
76
  onResizeStart?: ResizeGridItemCallback<GridResizeEvent>;
77
77
  onResizeStop?: ResizeGridItemCallback<GridResizeEvent>;
78
+ onFitToContent?: (i: string, w: number, h: number, x: number, y: number) => void;
78
79
  isHiddenVisibility?: boolean;
79
80
  customColWidth?: number;
80
- fitToContent?: boolean;
81
+ autoResize: boolean;
81
82
  };
82
83
  export type GridItemDefaultProps = {
83
84
  className: string;
@@ -23,7 +23,7 @@ export declare function calcXY(positionParams: PositionParams, top: number, left
23
23
  export declare function calcWH(positionParams: PositionParams, { width, height }: {
24
24
  width: number;
25
25
  height: number;
26
- }, x: number, y: number, handleAxis?: ResizeHandleAxis, prevW?: number, prevH?: number): {
26
+ }, x: number, y: number, handleAxis?: ResizeHandleAxis, prevW?: number, prevH?: number, shouldCeil?: boolean): {
27
27
  w: number;
28
28
  h: number;
29
29
  };
@@ -52,13 +52,14 @@ export function calcXY(positionParams, top, left, w, h) {
52
52
  y = clamp(y, 0, maxRows - h);
53
53
  return { x: x, y: y };
54
54
  }
55
- export function calcWH(positionParams, _a, x, y, handleAxis, prevW, prevH) {
55
+ export function calcWH(positionParams, _a, x, y, handleAxis, prevW, prevH, shouldCeil) {
56
56
  var width = _a.width, height = _a.height;
57
57
  var margin = positionParams.margin, maxRows = positionParams.maxRows, cols = positionParams.cols, rowHeight = positionParams.rowHeight;
58
58
  var colWidth = calcGridColWidth(positionParams);
59
59
  var rowHeightNumber = resolveRowHeight(rowHeight, colWidth);
60
- var w = Math.round((width + margin[0]) / (colWidth + margin[0]));
61
- var h = Math.round((height + margin[1]) / (rowHeightNumber + margin[1]));
60
+ var roundOrCeil = shouldCeil ? Math.ceil : Math.round;
61
+ var w = roundOrCeil((width + margin[0]) / (colWidth + margin[0]));
62
+ var h = roundOrCeil((height + margin[1]) / (rowHeightNumber + margin[1]));
62
63
  // // Capping
63
64
  // w = clamp(w, 0, cols - x);
64
65
  // h = clamp(h, 0, maxRows - y);
@@ -37,9 +37,7 @@ import { bottom, cloneLayoutItem, compact, getAllCollisions, getLayoutItem, move
37
37
  import { calcGridColWidth, calcXY, resolveRowHeight, } from "../GridItem/utils/calculateUtils";
38
38
  import GridItem from "../GridItem/GridItem";
39
39
  import isEqual from "../../external-lib/lodash.isEqual";
40
- import { WithFitToContent } from "../components";
41
40
  var layoutClassName = "react-grid-layout";
42
- var Placeholder = WithFitToContent(GridItem);
43
41
  var ReactGridLayout = function (_a) {
44
42
  var children = _a.children, props = __rest(_a, ["children"]);
45
43
  var _b = props.autoSize, autoSize = _b === void 0 ? true : _b, _c = props.cols, cols = _c === void 0 ? 12 : _c, _d = props.className, className = _d === void 0 ? "" : _d, _e = props.style, style = _e === void 0 ? {} : _e, _f = props.draggableHandle, draggableHandle = _f === void 0 ? "" : _f, _g = props.draggableCancel, draggableCancel = _g === void 0 ? "" : _g, _h = props.containerPadding, containerPadding = _h === void 0 ? undefined : _h, _j = props.rowHeight, rowHeight = _j === void 0 ? 150 : _j, _k = props.maxRows, maxRows = _k === void 0 ? Infinity : _k, _l = props.margin, margin = _l === void 0 ? [10, 10] : _l, _m = props.isBounded, isBounded = _m === void 0 ? false : _m, _o = props.isDraggable, isDraggable = _o === void 0 ? true : _o, _p = props.isResizable, isResizable = _p === void 0 ? true : _p, _q = props.allowOverlap, allowOverlap = _q === void 0 ? false : _q, _r = props.isDroppable, isDroppable = _r === void 0 ? false : _r, _s = props.useCSSTransforms, useCSSTransforms = _s === void 0 ? true : _s, _t = props.transformScale, transformScale = _t === void 0 ? 1 : _t, _u = props.compactType, compactType = _u === void 0 ? "vertical" : _u, _v = props.preventCollision, preventCollision = _v === void 0 ? false : _v, _w = props.droppingItem, droppingItem = _w === void 0 ? {
@@ -335,6 +333,46 @@ var ReactGridLayout = function (_a) {
335
333
  setOldLayout(undefined);
336
334
  onLayoutMaybeChanged(newLayout, oldLayout);
337
335
  };
336
+ var onFitToContentHandler = function (i, w, h, x, y) {
337
+ var _a = withLayoutItem(layout, i, function (l) {
338
+ var hasCollisions;
339
+ if (preventCollision && !allowOverlap) {
340
+ var collisions = getAllCollisions(layout, __assign(__assign({}, l), { w: x, h: y })).filter(function (layoutItem) { return layoutItem.i !== l.i; });
341
+ hasCollisions = collisions.length > 0;
342
+ if (hasCollisions) {
343
+ var leastX_2 = Infinity, leastY_2 = Infinity;
344
+ collisions.forEach(function (layoutItem) {
345
+ if (layoutItem.x > l.x)
346
+ leastX_2 = Math.min(leastX_2, layoutItem.x);
347
+ if (layoutItem.y > l.y)
348
+ leastY_2 = Math.min(leastY_2, layoutItem.y);
349
+ });
350
+ if (Number.isFinite(leastX_2))
351
+ l.w = leastX_2 - l.x;
352
+ if (Number.isFinite(leastY_2))
353
+ l.h = leastY_2 - l.y;
354
+ }
355
+ }
356
+ if (!hasCollisions) {
357
+ // NOTE - 여기서 x, y를 추가적으로 세팅해줘야 nw, w, n, sw 방향에서 placeholder가 반대로 resize되지 않고 해당 element와 똑같이 resize
358
+ l.w = w;
359
+ l.h = h;
360
+ l.x = x;
361
+ l.y = y;
362
+ l.minH = h;
363
+ }
364
+ return l;
365
+ }), newLayout = _a[0], l = _a[1];
366
+ if (!l)
367
+ return;
368
+ props.onFitToContent &&
369
+ props.onFitToContent({
370
+ layout: newLayout,
371
+ prev: oldResizeItem,
372
+ item: l,
373
+ });
374
+ setLayout(allowOverlap ? newLayout : compact(newLayout, compactType, cols));
375
+ };
338
376
  /**
339
377
  * Create a placeholder object.
340
378
  * @return {Element} Placeholder div.
@@ -357,7 +395,7 @@ var ReactGridLayout = function (_a) {
357
395
  if (!item) {
358
396
  return null;
359
397
  }
360
- return (_jsx(Placeholder, { setLayout: setLayout, 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, children: item && item }));
398
+ 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, autoResize: !!l.autoResize, children: item && item }));
361
399
  };
362
400
  /**
363
401
  * Given a grid item, set its style attributes & surround in a <Draggable>.
@@ -380,10 +418,7 @@ var ReactGridLayout = function (_a) {
380
418
  : !l.static && isResizable;
381
419
  var resizeHandlesOptions = l.resizeHandles || resizeHandles;
382
420
  var bounded = draggable && isBounded && l.isBounded !== false;
383
- if (l.fitToContent) {
384
- return (_jsx(Placeholder, { setLayout: setLayout, 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, onFitToContent: props.onFitToContent, 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 }));
385
- }
386
- return _jsx(GridItem, { 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);
421
+ return (_jsx(GridItem, { 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, onFitToContent: onFitToContentHandler, 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, autoResize: !!l.autoResize, children: child }, l.i));
387
422
  };
388
423
  var onDragOverHandler = function (e) {
389
424
  var _a;
@@ -20,7 +20,7 @@ export type LayoutItem = {
20
20
  resizeHandles?: ResizeHandleAxis[];
21
21
  isBounded?: boolean;
22
22
  groupLayouts?: LayoutItem[];
23
- fitToContent?: boolean;
23
+ autoResize?: boolean;
24
24
  };
25
25
  export type Layout = LayoutItem[];
26
26
  export type DroppedEvent = {
@@ -67,11 +67,11 @@ export type ReactGridLayoutProps = {
67
67
  h?: number;
68
68
  } | false) | null;
69
69
  onDrop?: (layout: Layout, item: LayoutItem | null, e: ResizeEventType) => void;
70
- onFitToContent: (item: LayoutItem) => void;
71
70
  isHiddenVisibility?: boolean;
72
71
  innerRef?: RefObject<HTMLDivElement>;
73
72
  minNbRow?: number;
74
73
  customColWidth?: number;
74
+ onFitToContent?: EventCallback;
75
75
  };
76
76
  export type DragOverEvent = MouseEvent & {
77
77
  nativeEvent: {
@@ -2,5 +2,5 @@ import React from "react";
2
2
  import { PropsWithChildren } from "../Draggable/types";
3
3
  import { ResizableProps } from "./types";
4
4
  type Props = ResizableProps;
5
- declare const Resizable: ({ children, axis, handleSize, lockAspectRatio, minConstraints, maxConstraints, resizeHandles, transformScale, ...props }: PropsWithChildren<Props>) => React.ReactElement<any, string | React.JSXElementConstructor<any>>;
5
+ declare const Resizable: ({ children, axis, handleSize, lockAspectRatio, minConstraints, maxConstraints, resizeHandles, transformScale, isResizing, autoResize, ...props }: PropsWithChildren<Props>) => React.ReactElement<any, string | React.JSXElementConstructor<any>>;
6
6
  export default Resizable;
@@ -31,11 +31,11 @@ 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 } from "react";
35
35
  import DraggableCore from "../Draggable/DraggableCore";
36
36
  import { cloneElement } from "./utils/cloneElement";
37
37
  var Resizable = function (_a) {
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"]);
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, isResizing = _a.isResizing, autoResize = _a.autoResize, props = __rest(_a, ["children", "axis", "handleSize", "lockAspectRatio", "minConstraints", "maxConstraints", "resizeHandles", "transformScale", "isResizing", "autoResize"]);
39
39
  var handleRefs = useRef({
40
40
  s: useRef(null),
41
41
  n: useRef(null),
@@ -51,6 +51,38 @@ var Resizable = function (_a) {
51
51
  var lastHandleRect = null;
52
52
  var slack = null;
53
53
  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
+ var elementRef = children.ref;
55
+ var extendedHeightRef = useRef(null);
56
+ var minWidth = useRef(0);
57
+ useEffect(function () {
58
+ var _a;
59
+ if (!autoResize) {
60
+ return;
61
+ }
62
+ if (!isResizing) {
63
+ extendedHeightRef.current = null;
64
+ minWidth.current = 0;
65
+ return;
66
+ }
67
+ if (!elementRef.current) {
68
+ return;
69
+ }
70
+ var placeholder = document.querySelector('.placeholder');
71
+ if (!placeholder) {
72
+ return;
73
+ }
74
+ var target = (_a = placeholder.children[0].children[0].children[0]) !== null && _a !== void 0 ? _a : placeholder.children[0].children[0];
75
+ if (target.clientHeight > elementRef.current.clientHeight) {
76
+ extendedHeightRef.current = target.clientHeight;
77
+ }
78
+ else {
79
+ extendedHeightRef.current = null;
80
+ }
81
+ var minWidthStyle = target.computedStyleMap().get('min-width');
82
+ if (typeof minWidthStyle.value === 'number') {
83
+ minWidth.current = minWidthStyle.value;
84
+ }
85
+ }, [isResizing, autoResize, children, elementRef]);
54
86
  var resetData = function () {
55
87
  lastHandleRect = slack = null;
56
88
  };
@@ -129,7 +161,7 @@ var Resizable = function (_a) {
129
161
  var resizeHandler = function (handlerName, handleAxis) {
130
162
  return function (e, _a) {
131
163
  var _b, _c;
132
- var _d, _e, _f, _g, _h, _j;
164
+ var _d, _e, _f, _g, _h, _j, _k;
133
165
  var node = _a.node, deltaX = _a.deltaX, deltaY = _a.deltaY;
134
166
  if (handlerName === "onResizeStart") {
135
167
  var position = { top: (_d = props.top) !== null && _d !== void 0 ? _d : 0, left: (_e = props.left) !== null && _e !== void 0 ? _e : 0 };
@@ -178,13 +210,19 @@ var Resizable = function (_a) {
178
210
  if (axisH === "w") {
179
211
  left = left - deltaX;
180
212
  }
213
+ // width = Math.max(width, minWidth.current);
214
+ // const isOverMin = calcWH()
215
+ if (extendedHeightRef.current) {
216
+ height = extendedHeightRef.current;
217
+ handleAxis = removeNorthHandle(handleAxis);
218
+ }
181
219
  _b = checkConstraints(width, height), width = _b[0], height = _b[1];
182
220
  _c = checkTopLeft(deltaX, deltaY, top, left, width, height, handleAxis), top = _c[0], left = _c[1];
183
221
  var isDimensionsChanged = width !== props.width || height !== props.height;
184
222
  var cb = typeof props[handlerName] === "function" ? props[handlerName] : null;
185
223
  var isCbSkipped = handlerName === "onResize" && !isDimensionsChanged;
186
224
  if (cb && !isCbSkipped) {
187
- cb(e, { node: node, size: { width: width, height: height, top: top, left: left }, handle: handleAxis });
225
+ cb(e, { node: node, size: { width: width, height: height, top: top, left: left }, handle: handleAxis, minWidth: minWidth.current, minHeight: (_k = extendedHeightRef.current) !== null && _k !== void 0 ? _k : 0 });
188
226
  }
189
227
  if (handlerName === "onResizeStop") {
190
228
  startPosition.current = null;
@@ -212,4 +250,14 @@ var Resizable = function (_a) {
212
250
  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)));
213
251
  }), true) }));
214
252
  };
253
+ function removeNorthHandle(axis) {
254
+ switch (axis) {
255
+ case 'ne':
256
+ return 'e';
257
+ case 'nw':
258
+ return 'w';
259
+ default:
260
+ return axis;
261
+ }
262
+ }
215
263
  export default Resizable;
@@ -29,6 +29,8 @@ export type ResizeCallbackData = {
29
29
  left: number;
30
30
  };
31
31
  handle: ResizeHandleAxis;
32
+ minWidth?: number;
33
+ minHeight?: number;
32
34
  };
33
35
  export type ResizableDefaultProps = {
34
36
  axis: Axis;
@@ -59,5 +61,7 @@ export type ResizableProps = {
59
61
  style?: CSSProperties;
60
62
  width: number;
61
63
  height: number;
64
+ isResizing?: boolean;
65
+ autoResize?: boolean;
62
66
  };
63
67
  export type ResizeHandleType = ReactElement<any> | ((resizeHandleAxis: ResizeHandleAxis, ref: Ref<HTMLElement>) => ReactElement<any>);
@@ -1,2 +1 @@
1
1
  export { default as WidthProvider } from "./WidthProvider";
2
- export { default as WithFitToContent } from "./WithFitToContent";
@@ -1,2 +1 @@
1
1
  export { default as WidthProvider } from "./WidthProvider";
2
- export { default as WithFitToContent } from "./WithFitToContent";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "publ-echo",
3
- "version": "0.0.85",
3
+ "version": "0.0.91",
4
4
  "private": false,
5
5
  "main": "dist/lib/index.js",
6
6
  "types": "dist/lib/index.d.js",
@@ -42,7 +42,6 @@
42
42
  "@types/node": "^16.18.32",
43
43
  "@types/react": "^18.2.6",
44
44
  "@types/react-dom": "^18.2.4",
45
- "@types/react-measure": "^2.0.12",
46
45
  "@types/styled-components": "^5.1.26",
47
46
  "commander": "^10.0.1",
48
47
  "lodash": "^4.17.21",
@@ -53,8 +52,5 @@
53
52
  "styled-components": "^5.3.10",
54
53
  "typescript": "^5.1.6",
55
54
  "web-vitals": "^2.1.4"
56
- },
57
- "dependencies": {
58
- "react-measure": "^2.5.2"
59
55
  }
60
56
  }
@@ -1,12 +0,0 @@
1
- import React from "react";
2
- import { GridItemProps } from "../GridItem/types";
3
- import { PropsWithChildren } from "../types";
4
- import { Layout } from "../GridLayoutEditor";
5
- import { LayoutItem } from "../GridLayoutEditor/types";
6
- type ComposedProps<Config> = {
7
- h: number;
8
- setLayout: React.Dispatch<React.SetStateAction<Layout>>;
9
- onFitToContent?: (layoutitem: LayoutItem) => void;
10
- } & Config;
11
- declare const WithFitToContent: (ComposedComponent: React.ComponentType<PropsWithChildren<GridItemProps>>) => (props: ComposedProps<PropsWithChildren<GridItemProps>>) => React.ReactElement;
12
- export default WithFitToContent;
@@ -1,117 +0,0 @@
1
- var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
- if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
- return cooked;
4
- };
5
- var __assign = (this && this.__assign) || function () {
6
- __assign = Object.assign || function(t) {
7
- for (var s, i = 1, n = arguments.length; i < n; i++) {
8
- s = arguments[i];
9
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
10
- t[p] = s[p];
11
- }
12
- return t;
13
- };
14
- return __assign.apply(this, arguments);
15
- };
16
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
17
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
18
- if (ar || !(i in from)) {
19
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
20
- ar[i] = from[i];
21
- }
22
- }
23
- return to.concat(ar || Array.prototype.slice.call(from));
24
- };
25
- import { jsx as _jsx } from "react/jsx-runtime";
26
- /* eslint-disable react-hooks/rules-of-hooks */
27
- import { useRef, useState, useEffect } from "react";
28
- import Measure from 'react-measure';
29
- import styled from "styled-components";
30
- import { calcGridItemPosition } from "../GridItem/utils/calculateUtils";
31
- var layoutClassName = "react-grid-item";
32
- /*
33
- * A simple HOC that provides facility for listening to container resizes.
34
- */
35
- var WithFitToContent = function (ComposedComponent) {
36
- return function (props) {
37
- var _a, _b;
38
- var elementRef = useRef(null);
39
- var mounted = useRef(false);
40
- var _c = useState({
41
- h: props.h,
42
- }), state = _c[0], setState = _c[1];
43
- // const { measureBeforeMount = false } = props;
44
- useEffect(function () {
45
- if (mounted.current) {
46
- return;
47
- }
48
- mounted.current = true;
49
- }, []);
50
- // NOTE: 임시
51
- useEffect(function () {
52
- setState({ h: props.h });
53
- }, [props.h]);
54
- // useEffect(() => {
55
- // if (!elementRef.current) return;
56
- // const resizeObserver = new ResizeObserver((callback) => {
57
- // const [object] = callback;
58
- // const { width } = object.contentRect;
59
- // setState({ width });
60
- // });
61
- // resizeObserver.observe(elementRef.current);
62
- // return () => resizeObserver.disconnect();
63
- // }, [elementRef]);
64
- // const onWindowResize = () => {
65
- // if (!mounted.current) return;
66
- // const node = elementRef.current;
67
- // if (node instanceof HTMLElement && node.offsetWidth) {
68
- // setState({ width: node.offsetWidth });
69
- // }
70
- // };
71
- function onResize(contentRect) {
72
- var _a, _b;
73
- if (!mounted.current) {
74
- return;
75
- }
76
- var contentHeight = Math.round((_b = (_a = contentRect.bounds) === null || _a === void 0 ? void 0 : _a.height) !== null && _b !== void 0 ? _b : 0);
77
- var scrollHeight = Math.round((props.rowHeight * props.h) + (10 * (props.h - 1)));
78
- if (contentHeight <= scrollHeight || props.rowHeight === 0) {
79
- return;
80
- }
81
- var gap = contentHeight - scrollHeight;
82
- var additionalColumns = Math.ceil(gap / props.rowHeight);
83
- props.setLayout(function (layout) {
84
- var targetIdx = layout.findIndex(function (layout) { return layout.i === props.i; });
85
- if (targetIdx !== -1) {
86
- // layout을 복사하여 불변성을 유지
87
- var newLayout = __spreadArray([], layout, true);
88
- newLayout[targetIdx] = __assign(__assign({}, newLayout[targetIdx]), { h: props.h + additionalColumns, minH: props.h + additionalColumns });
89
- return newLayout;
90
- }
91
- return layout;
92
- });
93
- setState({ h: props.h + additionalColumns });
94
- (props === null || props === void 0 ? void 0 : props.onFitToContent) && props.onFitToContent(__assign(__assign({}, props), { h: props.h + additionalColumns }));
95
- }
96
- var getPositionParams = function (prop) {
97
- if (prop === void 0) { prop = props; }
98
- return {
99
- cols: prop.cols,
100
- containerPadding: prop.containerPadding,
101
- containerWidth: prop.containerWidth,
102
- margin: prop.margin,
103
- maxRows: prop.maxRows,
104
- rowHeight: prop.rowHeight,
105
- };
106
- };
107
- var pos = calcGridItemPosition(getPositionParams(), props.x, props.y, props.z, (_a = props === null || props === void 0 ? void 0 : props.minW) !== null && _a !== void 0 ? _a : 0, (_b = props === null || props === void 0 ? void 0 : props.minH) !== null && _b !== void 0 ? _b : 0);
108
- var height = pos.height;
109
- return _jsx(ComposedComponent, __assign({}, props, state, { className: "react-grid-item-selected", children: _jsx("div", { ref: elementRef, children: _jsx(Measure, { bounds: true, onResize: onResize, children: function (_a) {
110
- var measureRef = _a.measureRef;
111
- return (_jsx(S_MeasureDiv, { ref: measureRef, children: props.children }));
112
- } }) }) }));
113
- };
114
- };
115
- var S_MeasureDiv = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n /* max-height: fit-content;\n height: inherit;\n\n & > div {\n max-height: fit-content;\n height: inherit;\n }\n\n & > div > div{\n max-height: fit-content;\n height: inherit;\n overflow: visible;\n } */\n min-height: 100%; \n display: flex; \n width: 100%;\n\n & > div {\n height: unset;\n width: 100%;\n min-height: 100%; \n display: flex; \n }\n /* display: flex;\n flex-direction: column;\n height: ;\n width: 100%;\n\n & > div {\n height: 100%;\n width: 100%;\n }\n\n & > div > div {\n height: 100%;\n width: 100%;\n } */\n\n .grid-box {\n height: unset;\n min-height: 100%; \n display: flex; \n width: 100%;\n }\n"], ["\n /* max-height: fit-content;\n height: inherit;\n\n & > div {\n max-height: fit-content;\n height: inherit;\n }\n\n & > div > div{\n max-height: fit-content;\n height: inherit;\n overflow: visible;\n } */\n min-height: 100%; \n display: flex; \n width: 100%;\n\n & > div {\n height: unset;\n width: 100%;\n min-height: 100%; \n display: flex; \n }\n /* display: flex;\n flex-direction: column;\n height: ;\n width: 100%;\n\n & > div {\n height: 100%;\n width: 100%;\n }\n\n & > div > div {\n height: 100%;\n width: 100%;\n } */\n\n .grid-box {\n height: unset;\n min-height: 100%; \n display: flex; \n width: 100%;\n }\n"])));
116
- export default WithFitToContent;
117
- var templateObject_1;