publ-echo-test 0.0.172 → 0.0.174
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.
@@ -1,5 +1,5 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { GridItemProps } from './types';
|
3
3
|
import { PropsWithChildren } from '../types';
|
4
|
-
declare const
|
5
|
-
export default
|
4
|
+
declare const _default: React.MemoExoticComponent<({ children, ...props }: PropsWithChildren<GridItemProps>) => React.ReactElement<any, string | React.JSXElementConstructor<any>>>;
|
5
|
+
export default _default;
|
@@ -21,12 +21,23 @@ 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, useRef, useState, useCallback, useMemo, } 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
|
+
// throttle 함수 추가
|
31
|
+
var createThrottle = function (delay) {
|
32
|
+
var lastCall = 0;
|
33
|
+
return function () {
|
34
|
+
var now = Date.now();
|
35
|
+
if (now - lastCall < delay)
|
36
|
+
return false;
|
37
|
+
lastCall = now;
|
38
|
+
return true;
|
39
|
+
};
|
40
|
+
};
|
30
41
|
var GridItem = function (_a) {
|
31
42
|
var _b;
|
32
43
|
var children = _a.children, props = __rest(_a, ["children"]);
|
@@ -39,6 +50,8 @@ var GridItem = function (_a) {
|
|
39
50
|
var _r = useState(false), pointerEventsNone = _r[0], setPointerEventsNone = _r[1];
|
40
51
|
var elementRef = useRef(null);
|
41
52
|
var isSelected = (_b = elementRef.current) === null || _b === void 0 ? void 0 : _b.classList.contains('react-grid-item-selected');
|
53
|
+
// throttle 참조 추가
|
54
|
+
var throttleRef = useRef(createThrottle(16)); // 약 60fps
|
42
55
|
useEffect(function () {
|
43
56
|
var _a;
|
44
57
|
if (!isSelected || !autoResize) {
|
@@ -142,7 +155,8 @@ var GridItem = function (_a) {
|
|
142
155
|
// });
|
143
156
|
// }
|
144
157
|
// };
|
145
|
-
|
158
|
+
// 메모이제이션된 위치 계산 함수
|
159
|
+
var getPositionParams = useCallback(function (prop) {
|
146
160
|
if (prop === void 0) { prop = props; }
|
147
161
|
return {
|
148
162
|
cols: prop.cols,
|
@@ -152,9 +166,10 @@ var GridItem = function (_a) {
|
|
152
166
|
maxRows: prop.maxRows,
|
153
167
|
rowHeight: prop.rowHeight,
|
154
168
|
};
|
155
|
-
};
|
169
|
+
}, [props.cols, props.containerPadding, props.containerWidth, props.margin, props.maxRows, props.rowHeight]);
|
156
170
|
var colWidth = customColWidth !== null && customColWidth !== void 0 ? customColWidth : calcGridColWidth(getPositionParams());
|
157
|
-
|
171
|
+
// 스타일 메모이제이션
|
172
|
+
var createStyle = useCallback(function (pos) {
|
158
173
|
var usePercentages = props.usePercentages, containerWidth = props.containerWidth, useCSSTransforms = props.useCSSTransforms;
|
159
174
|
var style;
|
160
175
|
if (useCSSTransforms) {
|
@@ -170,8 +185,12 @@ var GridItem = function (_a) {
|
|
170
185
|
style.width = perc(pos.width / containerWidth);
|
171
186
|
}
|
172
187
|
}
|
188
|
+
// 드래그나 리사이즈 중일 때만 will-change 추가
|
189
|
+
if (isDragging || isResizing) {
|
190
|
+
style.willChange = 'transform';
|
191
|
+
}
|
173
192
|
return style;
|
174
|
-
};
|
193
|
+
}, [props.usePercentages, props.containerWidth, props.useCSSTransforms, isDragging, isResizing]);
|
175
194
|
/**
|
176
195
|
* Mix a Draggable instance into a child.
|
177
196
|
* @param {Element} child Child element.
|
@@ -239,6 +258,9 @@ var GridItem = function (_a) {
|
|
239
258
|
*/
|
240
259
|
var onDrag = function (e, _a) {
|
241
260
|
var node = _a.node, deltaX = _a.deltaX, deltaY = _a.deltaY;
|
261
|
+
// throttle 적용
|
262
|
+
if (!throttleRef.current())
|
263
|
+
return;
|
242
264
|
if (!dragging) {
|
243
265
|
throw new Error('onDrag called before onDragStart.');
|
244
266
|
}
|
@@ -251,7 +273,6 @@ var GridItem = function (_a) {
|
|
251
273
|
var offsetParent = node.offsetParent;
|
252
274
|
if (offsetParent) {
|
253
275
|
var margin = props.margin, rowHeight = props.rowHeight;
|
254
|
-
// const colWidth = calcGridColWidth(positionParams);
|
255
276
|
var rowHeightNumber = resolveRowHeight(rowHeight, colWidth);
|
256
277
|
var bottomBoundary = offsetParent.clientHeight -
|
257
278
|
calcGridItemWHPx(h, rowHeightNumber, margin[1]);
|
@@ -262,6 +283,7 @@ var GridItem = function (_a) {
|
|
262
283
|
}
|
263
284
|
var newPosition = { top: top, left: left };
|
264
285
|
setDragging(newPosition);
|
286
|
+
// 계산 최적화
|
265
287
|
var _b = calcXY(positionParams, top, left, w, h), x = _b.x, y = _b.y;
|
266
288
|
props.onDrag && props.onDrag(i, x, y, { e: e, node: node, newPosition: newPosition });
|
267
289
|
};
|
@@ -338,6 +360,9 @@ var GridItem = function (_a) {
|
|
338
360
|
* @param {Object} callbackData an object with node and size information
|
339
361
|
*/
|
340
362
|
var onResize = function (e, callbackData) {
|
363
|
+
// throttle 적용
|
364
|
+
if (!throttleRef.current())
|
365
|
+
return;
|
341
366
|
setIsResizing(true);
|
342
367
|
onResizeHandler(e, callbackData, 'onResize');
|
343
368
|
};
|
@@ -386,10 +411,13 @@ var GridItem = function (_a) {
|
|
386
411
|
var _d = getResizableXYPosition(handle, w, h, prevW, prevH), newX = _d.newX, newY = _d.newY;
|
387
412
|
handler(i, w, h, { e: e, node: node, size: size }, newX, newY);
|
388
413
|
};
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
414
|
+
// 렌더링 최적화
|
415
|
+
var pos = useMemo(function () {
|
416
|
+
return calcGridItemPosition(getPositionParams(), x, y, z, w, h, {
|
417
|
+
dragging: dragging,
|
418
|
+
resizing: resizing,
|
419
|
+
}, colWidth);
|
420
|
+
}, [x, y, z, w, h, dragging, resizing, colWidth, getPositionParams]);
|
393
421
|
var child = React.Children.only(children);
|
394
422
|
var newChild = React.cloneElement(child, {
|
395
423
|
key: i,
|
@@ -415,4 +443,12 @@ var GridItem = function (_a) {
|
|
415
443
|
newChild = mixinDraggable(newChild, isDraggable);
|
416
444
|
return newChild;
|
417
445
|
};
|
418
|
-
export default GridItem
|
446
|
+
export default React.memo(GridItem, function (prevProps, nextProps) {
|
447
|
+
// 필요한 속성만 비교하여 불필요한 리렌더링 방지
|
448
|
+
return (prevProps.x === nextProps.x &&
|
449
|
+
prevProps.y === nextProps.y &&
|
450
|
+
prevProps.w === nextProps.w &&
|
451
|
+
prevProps.h === nextProps.h &&
|
452
|
+
prevProps.isDraggable === nextProps.isDraggable &&
|
453
|
+
prevProps.isResizable === nextProps.isResizable);
|
454
|
+
});
|
@@ -34,7 +34,7 @@ import * as React from 'react';
|
|
34
34
|
import { useState, useRef, useLayoutEffect } from 'react';
|
35
35
|
import classNames from '../../external-lib/classnames';
|
36
36
|
import { bottom, cloneLayoutItem, compact, getAllCollisions, getBoundingArea, getLayoutItem, moveElement, noop, synchronizeLayoutWithChildren, withLayoutItem, } from './utils/renderHelpers';
|
37
|
-
import { calcGridColWidth, calcXY, resolveRowHeight, } from '../GridItem/utils/calculateUtils';
|
37
|
+
import { calcGridColWidth, calcGridItemPosition, calcXY, resolveRowHeight, } from '../GridItem/utils/calculateUtils';
|
38
38
|
import GridItem from '../GridItem/GridItem';
|
39
39
|
import isEqual from '../../external-lib/lodash.isEqual';
|
40
40
|
import { findAllChildrenCbIds, findBlockByBlockId, findDirectChildrenBlockIds, findDirectChildrenCbIds, findGroupBlocks, findParentGroupBlock, formatCbIdToBlockId, getBlockSpecificType, zIndexMap, } from './group';
|
@@ -227,6 +227,7 @@ var ReactGridLayout = function (_a) {
|
|
227
227
|
i: i,
|
228
228
|
};
|
229
229
|
var isUserAction = true;
|
230
|
+
// 레이아웃 계산 최적화
|
230
231
|
var newLayout = isGroup
|
231
232
|
? layout
|
232
233
|
: moveElement({
|
@@ -241,19 +242,21 @@ var ReactGridLayout = function (_a) {
|
|
241
242
|
allowOverlap: allowOverlap,
|
242
243
|
});
|
243
244
|
if (isGroup) {
|
245
|
+
// 그룹 이동 시 배치 최적화
|
246
|
+
var movedItems_1 = new Map();
|
244
247
|
oldGroupChildren.forEach(function (item) {
|
245
248
|
var layoutItem = getLayoutItem(layout, item.i);
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
249
|
+
if (!layoutItem)
|
250
|
+
return;
|
251
|
+
var newPos = __assign(__assign({}, layoutItem), { x: item.x + xgap, y: item.y + ygap });
|
252
|
+
movedItems_1.set(item.i, newPos);
|
253
|
+
});
|
254
|
+
// 한 번에 레이아웃 업데이트
|
255
|
+
newLayout = layout.map(function (item) {
|
256
|
+
if (movedItems_1.has(item.i)) {
|
257
|
+
return __assign(__assign({}, item), movedItems_1.get(item.i));
|
258
|
+
}
|
259
|
+
return item;
|
257
260
|
});
|
258
261
|
}
|
259
262
|
props.onDrag &&
|
@@ -739,7 +742,31 @@ var ReactGridLayout = function (_a) {
|
|
739
742
|
var currentGroupBlocks = blockStructure
|
740
743
|
? findGroupBlocks(blockStructure, editingGroupBlock)
|
741
744
|
: [];
|
742
|
-
|
745
|
+
// 화면에 보이는 아이템만 렌더링
|
746
|
+
var visibleItems = React.useMemo(function () {
|
747
|
+
if (!containerHeight)
|
748
|
+
return layout;
|
749
|
+
// 화면에 보이는 영역 계산
|
750
|
+
var visibleTop = window.scrollY;
|
751
|
+
var visibleBottom = visibleTop + window.innerHeight;
|
752
|
+
// 여유 공간 추가 (스크롤 시 부드러운 전환을 위해)
|
753
|
+
var buffer = resolveRowHeight(rowHeight, colWidth) * 2;
|
754
|
+
return layout.filter(function (item) {
|
755
|
+
var _a;
|
756
|
+
var itemPos = calcGridItemPosition(getPositionParams(), item.x, item.y, (_a = item.z) !== null && _a !== void 0 ? _a : 0, item.w, item.h);
|
757
|
+
return (itemPos.top < visibleBottom + buffer) && (itemPos.top + itemPos.height > visibleTop - buffer);
|
758
|
+
});
|
759
|
+
}, [layout, window.scrollY, window.innerHeight, rowHeight, colWidth]);
|
760
|
+
return (_jsxs("div", { ref: innerRef, className: mergedClassName, style: mergedStyle, onDrop: isDroppable ? onDropHandler : noop, onDragLeave: isDroppable ? onDragLeaveHandler : noop, onDragEnter: isDroppable ? onDragEnterHandler : noop, onDragOver: isDroppable ? onDragOverHandler : noop, children: [currentGroupBlocks.map(function (each) { return processGroup(each); }), React.Children.map(children, function (child) {
|
761
|
+
var _a;
|
762
|
+
var key = (_a = child.key) === null || _a === void 0 ? void 0 : _a.toString();
|
763
|
+
if (!key)
|
764
|
+
return null;
|
765
|
+
var item = visibleItems.find(function (item) { return item.i === key; });
|
766
|
+
if (!item)
|
767
|
+
return null;
|
768
|
+
return processGridItem(child);
|
769
|
+
}), placeholder(), activeDrag && _jsx("div", { className: 'grid-guide-line-center' }), activeDrag && (_jsx("div", { className: 'grid-placeholder', style: {
|
743
770
|
marginTop: margin[1] + 'px',
|
744
771
|
marginBottom: margin[1] + 'px',
|
745
772
|
marginLeft: margin[0] + 'px',
|