publ-echo 0.0.83 → 0.0.85
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 +12 -155
- package/dist/lib/GridItem/types.d.ts +1 -3
- package/dist/lib/GridItem/utils/calculateUtils.d.ts +0 -1
- package/dist/lib/GridItem/utils/calculateUtils.js +0 -28
- package/dist/lib/GridLayoutEditor/ReactGridLayout.js +7 -25
- package/dist/lib/GridLayoutEditor/types.d.ts +2 -3
- package/dist/lib/Resizable/Resizable.js +5 -27
- package/dist/lib/Resizable/types.d.ts +1 -5
- package/dist/lib/components/WithFitToContent.d.ts +12 -0
- package/dist/lib/components/WithFitToContent.js +117 -0
- package/dist/lib/components/index.d.ts +1 -0
- package/dist/lib/components/index.js +1 -0
- package/package.json +5 -1
- package/dist/lib/FlexGridLayout/FlexGridLayout.d.ts +0 -2
- package/dist/lib/FlexGridLayout/FlexGridLayout.js +0 -5
- package/dist/lib/GridItem/utils/autoResizeUtils.d.ts +0 -29
- package/dist/lib/GridItem/utils/autoResizeUtils.js +0 -58
- package/dist/lib/hooks/useIsMounted.d.ts +0 -9
- package/dist/lib/hooks/useIsMounted.js +0 -19
- package/dist/lib/hooks/useResizeobserver.d.ts +0 -14
- package/dist/lib/hooks/useResizeobserver.js +0 -73
|
@@ -21,90 +21,21 @@ 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, {
|
|
24
|
+
import React, { 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,
|
|
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
|
-
import { useResizeObserver } from "../hooks/useResizeobserver";
|
|
31
|
-
import { shouldAutoResize, shouldBlockResize } from "./utils/autoResizeUtils";
|
|
32
30
|
var GridItem = function (_a) {
|
|
33
31
|
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
|
|
35
|
-
var shouldAutoShrink = useRef({ shouldAutoShrink: false, initialHeight: 0 });
|
|
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;
|
|
36
33
|
var _k = useState(), resizing = _k[0], setResizing = _k[1];
|
|
37
34
|
var _l = useState(), dragging = _l[0], setDragging = _l[1];
|
|
38
35
|
var _m = useState(), dragStart = _m[0], setDragStart = _m[1];
|
|
39
36
|
var _o = useState(false), isDragging = _o[0], setIsDragging = _o[1];
|
|
40
37
|
var _p = useState(false), isResizing = _p[0], setIsResizing = _p[1];
|
|
41
38
|
var elementRef = useRef(null);
|
|
42
|
-
var gridItemHeight = useResizeObserver([isDragging, isResizing]).gridItemHeight;
|
|
43
|
-
var _q = useState(false), isHovered = _q[0], setIsHovered = _q[1];
|
|
44
|
-
useEffect(function () {
|
|
45
|
-
var node = elementRef.current;
|
|
46
|
-
if (!node) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
var handleMouseEnter = function () {
|
|
50
|
-
setIsHovered(true);
|
|
51
|
-
};
|
|
52
|
-
var handleMouseLeave = function () {
|
|
53
|
-
setIsHovered(false);
|
|
54
|
-
};
|
|
55
|
-
node.addEventListener('mouseenter', handleMouseEnter);
|
|
56
|
-
node.addEventListener('mouseleave', handleMouseLeave);
|
|
57
|
-
return function () {
|
|
58
|
-
node.removeEventListener('mouseenter', handleMouseEnter);
|
|
59
|
-
node.removeEventListener('mouseleave', handleMouseLeave);
|
|
60
|
-
};
|
|
61
|
-
}, []);
|
|
62
|
-
useEffect(function () {
|
|
63
|
-
// NOTE: 표현길이 높이맞춤
|
|
64
|
-
if (isDragging || isResizing) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
if (!activeResizeObserver) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (!elementRef.current || !props.onContentSizeChange) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
if (isHovered) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
var target = elementRef.current.querySelector(".cb-text-content");
|
|
77
|
-
if (!target) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
var observer = new ResizeObserver(function (_a) {
|
|
81
|
-
var _b, _c;
|
|
82
|
-
var entry = _a[0];
|
|
83
|
-
var newClientHeight = entry.target.clientHeight;
|
|
84
|
-
var newClientWidth = entry.target.clientWidth;
|
|
85
|
-
var containerHeight = (_c = (_b = elementRef.current) === null || _b === void 0 ? void 0 : _b.clientHeight) !== null && _c !== void 0 ? _c : 0;
|
|
86
|
-
if (newClientHeight < containerHeight) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
if (isHovered) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
;
|
|
93
|
-
var _d = calcWH(getPositionParams(), { width: newClientWidth, height: newClientHeight }, x, y, 'se', props.w, props.h), w = _d.w, h = _d.h;
|
|
94
|
-
if (props.w === w && props.h === h) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
props.onContentSizeChange(props.i, { x: x, y: y, w: w, h: h });
|
|
98
|
-
});
|
|
99
|
-
observer.observe(target, { box: 'border-box' });
|
|
100
|
-
if (isHovered) {
|
|
101
|
-
observer.disconnect();
|
|
102
|
-
}
|
|
103
|
-
;
|
|
104
|
-
return function () {
|
|
105
|
-
observer.disconnect();
|
|
106
|
-
};
|
|
107
|
-
}, [props.i, props.w, props.h, x, y, activeResizeObserver, isDragging, isResizing, isHovered]);
|
|
108
39
|
// const moveDroppingItem = (prevProps: GridItemProps) => {
|
|
109
40
|
// const { droppingPosition } = props;
|
|
110
41
|
// if (!droppingPosition) return;
|
|
@@ -197,7 +128,7 @@ var GridItem = function (_a) {
|
|
|
197
128
|
];
|
|
198
129
|
return (_jsx(Resizable, { draggableOpts: {
|
|
199
130
|
disabled: !isResizable,
|
|
200
|
-
}, 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,
|
|
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 }));
|
|
201
132
|
};
|
|
202
133
|
/**
|
|
203
134
|
* onDragStart event handler
|
|
@@ -242,9 +173,9 @@ var GridItem = function (_a) {
|
|
|
242
173
|
if (isBounded) {
|
|
243
174
|
var offsetParent = node.offsetParent;
|
|
244
175
|
if (offsetParent) {
|
|
245
|
-
var margin = props.margin,
|
|
176
|
+
var margin = props.margin, rowHeight = props.rowHeight;
|
|
246
177
|
// const colWidth = calcGridColWidth(positionParams);
|
|
247
|
-
var rowHeightNumber = resolveRowHeight(
|
|
178
|
+
var rowHeightNumber = resolveRowHeight(rowHeight, colWidth);
|
|
248
179
|
var bottomBoundary = offsetParent.clientHeight -
|
|
249
180
|
calcGridItemWHPx(h, rowHeightNumber, margin[1]);
|
|
250
181
|
top = clamp(top, 0, bottomBoundary);
|
|
@@ -323,66 +254,14 @@ var GridItem = function (_a) {
|
|
|
323
254
|
*/
|
|
324
255
|
var onResizeStart = function (e, callbackData) {
|
|
325
256
|
onResizeHandler(e, callbackData, "onResizeStart");
|
|
326
|
-
shouldAutoShrink.current.initialHeight = gridItemHeight;
|
|
327
257
|
};
|
|
328
|
-
|
|
329
|
-
|
|
258
|
+
/**
|
|
259
|
+
* onResize event handler
|
|
260
|
+
* @param {ResizeEventType} e event data
|
|
261
|
+
* @param {Object} callbackData an object with node and size information
|
|
262
|
+
*/
|
|
263
|
+
var onResize = function (e, callbackData) {
|
|
330
264
|
setIsResizing(true);
|
|
331
|
-
var _j = getDirectionOfMouseEvent(e), dirX = _j.dirX, dirY = _j.dirY;
|
|
332
|
-
var oneLetterSize = (_a = calculateCharacterWidthInDiv()) !== null && _a !== void 0 ? _a : 0;
|
|
333
|
-
var shouldBlock = shouldBlockResize({
|
|
334
|
-
handle: callbackData.handle,
|
|
335
|
-
dirY: dirY,
|
|
336
|
-
dirX: dirX,
|
|
337
|
-
contentHeight: (_b = contentSize === null || contentSize === void 0 ? void 0 : contentSize.height) !== null && _b !== void 0 ? _b : 0,
|
|
338
|
-
gridItemHeight: callbackData.size.height,
|
|
339
|
-
shouldAutoShrink: shouldAutoShrink.current.shouldAutoShrink,
|
|
340
|
-
initialHeight: shouldAutoShrink.current.initialHeight,
|
|
341
|
-
colHeight: rowHeight,
|
|
342
|
-
gridItemWidth: callbackData.size.width,
|
|
343
|
-
colWidth: colWidth,
|
|
344
|
-
contentWidth: (_c = contentSize === null || contentSize === void 0 ? void 0 : contentSize.width) !== null && _c !== void 0 ? _c : 0,
|
|
345
|
-
oneLetterSize: oneLetterSize
|
|
346
|
-
});
|
|
347
|
-
if (resizing === null || resizing === void 0 ? void 0 : resizing.top) {
|
|
348
|
-
callbackData.size.top = resizing === null || resizing === void 0 ? void 0 : resizing.top;
|
|
349
|
-
}
|
|
350
|
-
var shouldResize = shouldAutoResize({
|
|
351
|
-
handle: callbackData.handle,
|
|
352
|
-
dirX: dirX,
|
|
353
|
-
dirY: dirY,
|
|
354
|
-
contentHeight: (_d = contentSize === null || contentSize === void 0 ? void 0 : contentSize.height) !== null && _d !== void 0 ? _d : 0,
|
|
355
|
-
gridItemHeight: callbackData.size.height,
|
|
356
|
-
shouldAutoShrink: shouldAutoShrink.current.shouldAutoShrink,
|
|
357
|
-
initialHeight: shouldAutoShrink.current.initialHeight
|
|
358
|
-
});
|
|
359
|
-
if (shouldResize !== 'EXPAND' && shouldBlock === 'BLOCK-HEIGHT') {
|
|
360
|
-
callbackData.size.height = (_e = contentSize === null || contentSize === void 0 ? void 0 : contentSize.height) !== null && _e !== void 0 ? _e : 0;
|
|
361
|
-
}
|
|
362
|
-
if (shouldResize !== 'EXPAND' && shouldBlock === 'BLOCK-WIDTH') {
|
|
363
|
-
callbackData.size.width = (_f = contentSize === null || contentSize === void 0 ? void 0 : contentSize.width) !== null && _f !== void 0 ? _f : 0;
|
|
364
|
-
}
|
|
365
|
-
if (shouldResize === 'EXPAND') {
|
|
366
|
-
callbackData.size.height = (_g = contentSize === null || contentSize === void 0 ? void 0 : contentSize.height) !== null && _g !== void 0 ? _g : 0;
|
|
367
|
-
shouldAutoShrink.current.shouldAutoShrink = true;
|
|
368
|
-
// NOTE: 배포전에 무조건 변경
|
|
369
|
-
if (callbackData.handle === 'nw') {
|
|
370
|
-
callbackData.handle = 'w';
|
|
371
|
-
}
|
|
372
|
-
if (callbackData.handle === 'ne') {
|
|
373
|
-
callbackData.handle = 'se';
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
if (shouldResize === 'SHRINK') {
|
|
377
|
-
callbackData.size.height = Math.max(shouldAutoShrink.current.initialHeight, (_h = contentSize === null || contentSize === void 0 ? void 0 : contentSize.height) !== null && _h !== void 0 ? _h : 0);
|
|
378
|
-
// NOTE: 배포전에 무조건 변경
|
|
379
|
-
if (callbackData.handle === 'nw') {
|
|
380
|
-
callbackData.handle = 'sw';
|
|
381
|
-
}
|
|
382
|
-
if (callbackData.handle === 'ne') {
|
|
383
|
-
callbackData.handle = 'se';
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
265
|
onResizeHandler(e, callbackData, "onResize");
|
|
387
266
|
};
|
|
388
267
|
/**
|
|
@@ -393,10 +272,6 @@ var GridItem = function (_a) {
|
|
|
393
272
|
var onResizeStop = function (e, callbackData) {
|
|
394
273
|
setIsResizing(false);
|
|
395
274
|
onResizeHandler(e, callbackData, "onResizeStop");
|
|
396
|
-
shouldAutoShrink.current = {
|
|
397
|
-
shouldAutoShrink: false,
|
|
398
|
-
initialHeight: 0,
|
|
399
|
-
};
|
|
400
275
|
};
|
|
401
276
|
/**
|
|
402
277
|
* Wrapper around drag events to provide more useful data.
|
|
@@ -422,11 +297,6 @@ var GridItem = function (_a) {
|
|
|
422
297
|
h = clamp(h, minH, maxH);
|
|
423
298
|
setResizing(handlerName === "onResizeStop" ? undefined : size);
|
|
424
299
|
var _c = getResizableXYPosition(handle, w, h, prevW, prevH), newX = _c.newX, newY = _c.newY;
|
|
425
|
-
if (newY !== y) {
|
|
426
|
-
// Y 변화가 있다면 자동줄이기는 하지않는다.
|
|
427
|
-
shouldAutoShrink.current.shouldAutoShrink = false;
|
|
428
|
-
shouldAutoShrink.current.initialHeight = 0;
|
|
429
|
-
}
|
|
430
300
|
handler(i, w, h, { e: e, node: node, size: size }, newX, newY);
|
|
431
301
|
};
|
|
432
302
|
var pos = calcGridItemPosition(getPositionParams(), x, y, z, w, h, {
|
|
@@ -450,21 +320,8 @@ var GridItem = function (_a) {
|
|
|
450
320
|
}),
|
|
451
321
|
style: __assign(__assign(__assign({}, props.style), child.props.style), createStyle(pos)),
|
|
452
322
|
});
|
|
453
|
-
// NOTE: 제외
|
|
454
|
-
if (className === 'placeholder') {
|
|
455
|
-
return newChild;
|
|
456
|
-
}
|
|
457
323
|
newChild = mixinResizable(newChild, pos, isResizable);
|
|
458
324
|
newChild = mixinDraggable(newChild, isDraggable);
|
|
459
325
|
return newChild;
|
|
460
326
|
};
|
|
461
327
|
export default GridItem;
|
|
462
|
-
// NOTE: 이동해야할 util
|
|
463
|
-
var getDirectionOfMouseEvent = function (e) {
|
|
464
|
-
var dirX = e.movementX > 0 ? 'right' : e.movementX < 0 ? 'left' : null;
|
|
465
|
-
var dirY = e.movementY > 0 ? 'down' : e.movementY < 0 ? 'up' : null;
|
|
466
|
-
return {
|
|
467
|
-
dirX: dirX,
|
|
468
|
-
dirY: dirY
|
|
469
|
-
};
|
|
470
|
-
};
|
|
@@ -75,11 +75,9 @@ export type GridItemProps = {
|
|
|
75
75
|
onResize?: ResizeGridItemCallback<GridResizeEvent>;
|
|
76
76
|
onResizeStart?: ResizeGridItemCallback<GridResizeEvent>;
|
|
77
77
|
onResizeStop?: ResizeGridItemCallback<GridResizeEvent>;
|
|
78
|
-
onContentSizeChange?: any;
|
|
79
78
|
isHiddenVisibility?: boolean;
|
|
80
79
|
customColWidth?: number;
|
|
81
|
-
|
|
82
|
-
activeContentObserver?: boolean;
|
|
80
|
+
fitToContent?: boolean;
|
|
83
81
|
};
|
|
84
82
|
export type GridItemDefaultProps = {
|
|
85
83
|
className: string;
|
|
@@ -28,4 +28,3 @@ 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,31 +106,3 @@ 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
|
-
}
|
|
@@ -37,7 +37,9 @@ 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";
|
|
40
41
|
var layoutClassName = "react-grid-layout";
|
|
42
|
+
var Placeholder = WithFitToContent(GridItem);
|
|
41
43
|
var ReactGridLayout = function (_a) {
|
|
42
44
|
var children = _a.children, props = __rest(_a, ["children"]);
|
|
43
45
|
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 ? {
|
|
@@ -266,27 +268,6 @@ var ReactGridLayout = function (_a) {
|
|
|
266
268
|
node: node,
|
|
267
269
|
});
|
|
268
270
|
};
|
|
269
|
-
// NOTE: 임시
|
|
270
|
-
var onContentSizeChange = function (i, pos) {
|
|
271
|
-
var targetLayoutItem = getLayoutItem(layout, i);
|
|
272
|
-
if ((targetLayoutItem === null || targetLayoutItem === void 0 ? void 0 : targetLayoutItem.h) === pos.h) {
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
console.log('og-h: ', targetLayoutItem === null || targetLayoutItem === void 0 ? void 0 : targetLayoutItem.h);
|
|
276
|
-
console.log('new-h: ', pos.h);
|
|
277
|
-
var _a = withLayoutItem(layout, i, function (l) {
|
|
278
|
-
l.w = pos.w;
|
|
279
|
-
l.h = pos.h;
|
|
280
|
-
l.x = pos.x;
|
|
281
|
-
l.y = pos.y;
|
|
282
|
-
return l;
|
|
283
|
-
}), newLayout = _a[0], l = _a[1];
|
|
284
|
-
if (!l) {
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
setLayout(newLayout);
|
|
288
|
-
props.onAutoResizedToFit && props.onAutoResizedToFit(newLayout);
|
|
289
|
-
};
|
|
290
271
|
var onResizeHandler = function (i, w, h, _a, x, y) {
|
|
291
272
|
var e = _a.e, node = _a.node;
|
|
292
273
|
var _b = withLayoutItem(layout, i, function (l) {
|
|
@@ -376,9 +357,7 @@ var ReactGridLayout = function (_a) {
|
|
|
376
357
|
if (!item) {
|
|
377
358
|
return null;
|
|
378
359
|
}
|
|
379
|
-
return (_jsx(
|
|
380
|
-
// NOTE: text CB만
|
|
381
|
-
activeContentObserver: true, children: item && item }));
|
|
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 }));
|
|
382
361
|
};
|
|
383
362
|
/**
|
|
384
363
|
* Given a grid item, set its style attributes & surround in a <Draggable>.
|
|
@@ -401,7 +380,10 @@ var ReactGridLayout = function (_a) {
|
|
|
401
380
|
: !l.static && isResizable;
|
|
402
381
|
var resizeHandlesOptions = l.resizeHandles || resizeHandles;
|
|
403
382
|
var bounded = draggable && isBounded && l.isBounded !== false;
|
|
404
|
-
|
|
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);
|
|
405
387
|
};
|
|
406
388
|
var onDragOverHandler = function (e) {
|
|
407
389
|
var _a;
|
|
@@ -19,9 +19,8 @@ export type LayoutItem = {
|
|
|
19
19
|
isResizable?: boolean;
|
|
20
20
|
resizeHandles?: ResizeHandleAxis[];
|
|
21
21
|
isBounded?: boolean;
|
|
22
|
-
autoExpandOnContentChanged?: boolean;
|
|
23
22
|
groupLayouts?: LayoutItem[];
|
|
24
|
-
|
|
23
|
+
fitToContent?: boolean;
|
|
25
24
|
};
|
|
26
25
|
export type Layout = LayoutItem[];
|
|
27
26
|
export type DroppedEvent = {
|
|
@@ -57,7 +56,6 @@ export type ReactGridLayoutProps = {
|
|
|
57
56
|
resizeHandle?: ResizeHandleType;
|
|
58
57
|
allowOverlap?: boolean;
|
|
59
58
|
onLayoutChange?: (layout: Layout) => void;
|
|
60
|
-
onAutoResizedToFit?: (layout: Layout) => void;
|
|
61
59
|
onDrag?: EventCallback;
|
|
62
60
|
onDragStart?: EventCallback;
|
|
63
61
|
onDragStop?: EventCallback;
|
|
@@ -69,6 +67,7 @@ export type ReactGridLayoutProps = {
|
|
|
69
67
|
h?: number;
|
|
70
68
|
} | false) | null;
|
|
71
69
|
onDrop?: (layout: Layout, item: LayoutItem | null, e: ResizeEventType) => void;
|
|
70
|
+
onFitToContent: (item: LayoutItem) => void;
|
|
72
71
|
isHiddenVisibility?: boolean;
|
|
73
72
|
innerRef?: RefObject<HTMLDivElement>;
|
|
74
73
|
minNbRow?: number;
|
|
@@ -31,13 +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, {
|
|
34
|
+
import React, { 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 _b;
|
|
39
|
-
var children = _a.children, _c = _a.axis, axis = _c === void 0 ? "both" : _c, _d = _a.handleSize, handleSize = _d === void 0 ? [20, 20] : _d, _e = _a.lockAspectRatio, lockAspectRatio = _e === void 0 ? false : _e, _f = _a.minConstraints, minConstraints = _f === void 0 ? [20, 20] : _f, _g = _a.maxConstraints, maxConstraints = _g === void 0 ? [Infinity, Infinity] : _g, _h = _a.resizeHandles, resizeHandles = _h === void 0 ? ["se"] : _h, _j = _a.transformScale, transformScale = _j === void 0 ? 1 : _j, props = __rest(_a, ["children", "axis", "handleSize", "lockAspectRatio", "minConstraints", "maxConstraints", "resizeHandles", "transformScale"]);
|
|
40
|
-
var placeholderObserver = props.placeholderObserver;
|
|
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"]);
|
|
41
39
|
var handleRefs = useRef({
|
|
42
40
|
s: useRef(null),
|
|
43
41
|
n: useRef(null),
|
|
@@ -52,26 +50,6 @@ var Resizable = function (_a) {
|
|
|
52
50
|
var startSize = useRef(null);
|
|
53
51
|
var lastHandleRect = null;
|
|
54
52
|
var slack = null;
|
|
55
|
-
var _k = useState({ width: 0, height: 0 }), content = _k[0], setContent = _k[1];
|
|
56
|
-
var target = (_b = document.querySelector('.placeholder')) === null || _b === void 0 ? void 0 : _b.querySelector('.cb-text-content');
|
|
57
|
-
useEffect(function () {
|
|
58
|
-
if (!placeholderObserver) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
if (!target) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
var observer = new ResizeObserver(function (_a) {
|
|
65
|
-
var entry = _a[0];
|
|
66
|
-
var contentHeight = entry.target.clientHeight;
|
|
67
|
-
var contentWidth = entry.target.clientWidth;
|
|
68
|
-
setContent({ width: contentWidth, height: contentHeight });
|
|
69
|
-
});
|
|
70
|
-
observer.observe(target, { box: 'border-box' });
|
|
71
|
-
return function () {
|
|
72
|
-
observer.disconnect();
|
|
73
|
-
};
|
|
74
|
-
}, [placeholderObserver, target]);
|
|
75
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"]);
|
|
76
54
|
var resetData = function () {
|
|
77
55
|
lastHandleRect = slack = null;
|
|
@@ -148,7 +126,7 @@ var Resizable = function (_a) {
|
|
|
148
126
|
}
|
|
149
127
|
return [newTop, newLeft];
|
|
150
128
|
};
|
|
151
|
-
var resizeHandler = function (handlerName, handleAxis
|
|
129
|
+
var resizeHandler = function (handlerName, handleAxis) {
|
|
152
130
|
return function (e, _a) {
|
|
153
131
|
var _b, _c;
|
|
154
132
|
var _d, _e, _f, _g, _h, _j;
|
|
@@ -206,7 +184,7 @@ var Resizable = function (_a) {
|
|
|
206
184
|
var cb = typeof props[handlerName] === "function" ? props[handlerName] : null;
|
|
207
185
|
var isCbSkipped = handlerName === "onResize" && !isDimensionsChanged;
|
|
208
186
|
if (cb && !isCbSkipped) {
|
|
209
|
-
cb(e, { node: node, size: { width: width, height: height, top: top, left: left }, handle: handleAxis }
|
|
187
|
+
cb(e, { node: node, size: { width: width, height: height, top: top, left: left }, handle: handleAxis });
|
|
210
188
|
}
|
|
211
189
|
if (handlerName === "onResizeStop") {
|
|
212
190
|
startPosition.current = null;
|
|
@@ -231,7 +209,7 @@ var Resizable = function (_a) {
|
|
|
231
209
|
React.Children.map(children.props.children, function (child) { return child; })
|
|
232
210
|
], resizeHandles.map(function (handleAxis) {
|
|
233
211
|
var ref = (handleRefs === null || handleRefs === void 0 ? void 0 : handleRefs.current) && handleRefs.current[handleAxis];
|
|
234
|
-
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)));
|
|
235
213
|
}), true) }));
|
|
236
214
|
};
|
|
237
215
|
export default Resizable;
|
|
@@ -49,10 +49,7 @@ 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
|
|
53
|
-
height: number;
|
|
54
|
-
width: number;
|
|
55
|
-
}) => any;
|
|
52
|
+
onResize?: (e: SyntheticEvent<any>, data: ResizeCallbackData) => any;
|
|
56
53
|
handleSize?: [number, number];
|
|
57
54
|
lockAspectRatio?: boolean;
|
|
58
55
|
minConstraints?: [number, number];
|
|
@@ -62,6 +59,5 @@ export type ResizableProps = {
|
|
|
62
59
|
style?: CSSProperties;
|
|
63
60
|
width: number;
|
|
64
61
|
height: number;
|
|
65
|
-
placeholderObserver?: boolean;
|
|
66
62
|
};
|
|
67
63
|
export type ResizeHandleType = ReactElement<any> | ((resizeHandleAxis: ResizeHandleAxis, ref: Ref<HTMLElement>) => ReactElement<any>);
|
|
@@ -0,0 +1,12 @@
|
|
|
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;
|
|
@@ -0,0 +1,117 @@
|
|
|
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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "publ-echo",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.85",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "dist/lib/index.js",
|
|
6
6
|
"types": "dist/lib/index.d.js",
|
|
@@ -42,6 +42,7 @@
|
|
|
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",
|
|
45
46
|
"@types/styled-components": "^5.1.26",
|
|
46
47
|
"commander": "^10.0.1",
|
|
47
48
|
"lodash": "^4.17.21",
|
|
@@ -52,5 +53,8 @@
|
|
|
52
53
|
"styled-components": "^5.3.10",
|
|
53
54
|
"typescript": "^5.1.6",
|
|
54
55
|
"web-vitals": "^2.1.4"
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"react-measure": "^2.5.2"
|
|
55
59
|
}
|
|
56
60
|
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export type Handle = 'n' | 's' | 'w' | 'e' | 'nw' | 'ne' | 'sw' | 'se';
|
|
2
|
-
export type DirectionX = 'right' | 'left';
|
|
3
|
-
export type DirectionY = 'up' | 'down';
|
|
4
|
-
type Props = {
|
|
5
|
-
handle: Handle;
|
|
6
|
-
dirX: DirectionX;
|
|
7
|
-
dirY: DirectionY;
|
|
8
|
-
contentHeight: number;
|
|
9
|
-
gridItemHeight: number;
|
|
10
|
-
shouldAutoShrink: boolean;
|
|
11
|
-
initialHeight: number;
|
|
12
|
-
};
|
|
13
|
-
export declare function shouldAutoResize({ handle, dirX, dirY, contentHeight, gridItemHeight, shouldAutoShrink, initialHeight }: Props): "SHRINK" | "EXPAND" | "NONE";
|
|
14
|
-
type BlockDetectProp = {
|
|
15
|
-
handle: Handle;
|
|
16
|
-
dirY: DirectionY;
|
|
17
|
-
dirX: DirectionX;
|
|
18
|
-
contentHeight: number;
|
|
19
|
-
gridItemHeight: number;
|
|
20
|
-
shouldAutoShrink: boolean;
|
|
21
|
-
initialHeight: number;
|
|
22
|
-
colHeight: number;
|
|
23
|
-
gridItemWidth: number;
|
|
24
|
-
colWidth: number;
|
|
25
|
-
contentWidth: number;
|
|
26
|
-
oneLetterSize: number;
|
|
27
|
-
};
|
|
28
|
-
export declare function shouldBlockResize({ handle, dirY, dirX, contentHeight, gridItemHeight, shouldAutoShrink, initialHeight, colHeight, gridItemWidth, colWidth, contentWidth, oneLetterSize }: BlockDetectProp): "NONE" | "BLOCK-HEIGHT" | "BLOCK-WIDTH";
|
|
29
|
-
export {};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
export function shouldAutoResize(_a) {
|
|
2
|
-
var handle = _a.handle, dirX = _a.dirX, dirY = _a.dirY, contentHeight = _a.contentHeight, gridItemHeight = _a.gridItemHeight, shouldAutoShrink = _a.shouldAutoShrink, initialHeight = _a.initialHeight;
|
|
3
|
-
var shouldExpand = contentHeight > gridItemHeight;
|
|
4
|
-
var shouldShrink = gridItemHeight > contentHeight;
|
|
5
|
-
if (handle === 'nw') {
|
|
6
|
-
// if (dirY === 'up' || dirY === 'down') {
|
|
7
|
-
// return 'NONE'
|
|
8
|
-
// }
|
|
9
|
-
if (dirX === 'left' && shouldShrink && shouldAutoShrink) {
|
|
10
|
-
return 'SHRINK';
|
|
11
|
-
}
|
|
12
|
-
if (dirX === 'right' && shouldExpand) {
|
|
13
|
-
return 'EXPAND';
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
if (handle.includes('e') && dirX === 'left' && shouldExpand) {
|
|
17
|
-
return 'EXPAND';
|
|
18
|
-
}
|
|
19
|
-
if (handle.includes('e') && dirX === 'right' && shouldShrink && shouldAutoShrink) {
|
|
20
|
-
return 'SHRINK';
|
|
21
|
-
}
|
|
22
|
-
if (handle.includes('w') && dirX === 'right' && shouldExpand) {
|
|
23
|
-
return 'EXPAND';
|
|
24
|
-
}
|
|
25
|
-
if (handle.includes('w') && dirX === 'left' && shouldShrink && shouldAutoShrink) {
|
|
26
|
-
return 'SHRINK';
|
|
27
|
-
}
|
|
28
|
-
return 'NONE';
|
|
29
|
-
}
|
|
30
|
-
export function shouldBlockResize(_a) {
|
|
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
|
-
var nextGridHeight = gridItemHeight - colHeight;
|
|
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';
|
|
44
|
-
}
|
|
45
|
-
if (handle.includes('w') && dirX === 'right' && shouldBlockWidth) {
|
|
46
|
-
return 'BLOCK-WIDTH';
|
|
47
|
-
}
|
|
48
|
-
// if (handle.includes('e') && direction === 'right' && shouldShrink && shouldAutoShrink) {
|
|
49
|
-
// return 'SHRINK';
|
|
50
|
-
// }
|
|
51
|
-
// if (handle.includes('w') && direction === 'right' && shouldExpand) {
|
|
52
|
-
// return 'EXPAND';
|
|
53
|
-
// }
|
|
54
|
-
// if (handle.includes('w') && direction === 'left' && shouldShrink && shouldAutoShrink) {
|
|
55
|
-
// return 'SHRINK';
|
|
56
|
-
// }
|
|
57
|
-
return 'NONE';
|
|
58
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom hook for determining if the component is currently mounted.
|
|
3
|
-
* @returns {() => boolean} A function that returns a boolean value indicating whether the component is mounted.
|
|
4
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-is-mounted)
|
|
5
|
-
* @example
|
|
6
|
-
* const isComponentMounted = useIsMounted();
|
|
7
|
-
* // Use isComponentMounted() to check if the component is currently mounted before performing certain actions.
|
|
8
|
-
*/
|
|
9
|
-
export declare function useIsMounted(): () => boolean;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Custom hook for determining if the component is currently mounted.
|
|
4
|
-
* @returns {() => boolean} A function that returns a boolean value indicating whether the component is mounted.
|
|
5
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-is-mounted)
|
|
6
|
-
* @example
|
|
7
|
-
* const isComponentMounted = useIsMounted();
|
|
8
|
-
* // Use isComponentMounted() to check if the component is currently mounted before performing certain actions.
|
|
9
|
-
*/
|
|
10
|
-
export function useIsMounted() {
|
|
11
|
-
var isMounted = useRef(false);
|
|
12
|
-
useEffect(function () {
|
|
13
|
-
isMounted.current = true;
|
|
14
|
-
return function () {
|
|
15
|
-
isMounted.current = false;
|
|
16
|
-
};
|
|
17
|
-
}, []);
|
|
18
|
-
return useCallback(function () { return isMounted.current; }, []);
|
|
19
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { RefObject } from 'react';
|
|
2
|
-
type Size = {
|
|
3
|
-
gridItemWidth: number;
|
|
4
|
-
gridItemHeight: number;
|
|
5
|
-
scrollHeight: number;
|
|
6
|
-
clientHeight: number;
|
|
7
|
-
};
|
|
8
|
-
type UseResizeObserverResult = Size & {
|
|
9
|
-
myHeightRef: RefObject<{
|
|
10
|
-
myHeight: number;
|
|
11
|
-
}>;
|
|
12
|
-
};
|
|
13
|
-
export declare function useResizeObserver(deps: any[]): UseResizeObserverResult;
|
|
14
|
-
export {};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
-
if (ar || !(i in from)) {
|
|
15
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
-
ar[i] = from[i];
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
-
};
|
|
21
|
-
import { useLayoutEffect, useRef, useState } from 'react';
|
|
22
|
-
import { useIsMounted } from './useIsMounted';
|
|
23
|
-
var initialSize = {
|
|
24
|
-
gridItemWidth: 0,
|
|
25
|
-
gridItemHeight: 0,
|
|
26
|
-
scrollHeight: 0,
|
|
27
|
-
clientHeight: 0,
|
|
28
|
-
};
|
|
29
|
-
export function useResizeObserver(deps) {
|
|
30
|
-
var previousSize = useRef(initialSize);
|
|
31
|
-
var _a = useState(initialSize), size = _a[0], setSize = _a[1];
|
|
32
|
-
var refvalue = useRef({ myHeight: 0 });
|
|
33
|
-
var isMounted = useIsMounted();
|
|
34
|
-
useLayoutEffect(function () {
|
|
35
|
-
var _a;
|
|
36
|
-
var target = (_a = document.querySelector('.placeholder')) === null || _a === void 0 ? void 0 : _a.querySelector('.cb-text-box');
|
|
37
|
-
if (!target) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (typeof window === 'undefined' || !('ResizeObserver' in window)) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
var observer = new ResizeObserver(function (_a) {
|
|
44
|
-
var _b;
|
|
45
|
-
var entry = _a[0];
|
|
46
|
-
var newWidth = extractSize(entry, 'contentBoxSize', 'inlineSize');
|
|
47
|
-
var newHeight = extractSize(entry, 'borderBoxSize', 'blockSize');
|
|
48
|
-
var newScrollHeight = entry.target.scrollHeight;
|
|
49
|
-
var newContentHeight = (_b = entry.target.children[0]) === null || _b === void 0 ? void 0 : _b.clientHeight;
|
|
50
|
-
refvalue.current.myHeight = newContentHeight;
|
|
51
|
-
var newSize = { gridItemWidth: newWidth, gridItemHeight: newHeight, scrollHeight: newScrollHeight, clientHeight: newContentHeight };
|
|
52
|
-
previousSize.current = newSize;
|
|
53
|
-
setSize(newSize);
|
|
54
|
-
});
|
|
55
|
-
observer.observe(target, { box: 'border-box' });
|
|
56
|
-
return function () {
|
|
57
|
-
observer.disconnect();
|
|
58
|
-
};
|
|
59
|
-
}, __spreadArray([isMounted], deps, true));
|
|
60
|
-
return __assign(__assign({}, size), { myHeightRef: refvalue });
|
|
61
|
-
}
|
|
62
|
-
function extractSize(entry, box, sizeType) {
|
|
63
|
-
if (!entry[box]) {
|
|
64
|
-
if (box === 'contentBoxSize') {
|
|
65
|
-
return entry.contentRect[sizeType === 'inlineSize' ? 'width' : 'height'];
|
|
66
|
-
}
|
|
67
|
-
return 0;
|
|
68
|
-
}
|
|
69
|
-
return Array.isArray(entry[box])
|
|
70
|
-
? entry[box][0][sizeType]
|
|
71
|
-
: // @ts-ignore Support Firefox's non-standard behavior
|
|
72
|
-
entry[box][sizeType];
|
|
73
|
-
}
|