publ-echo-test 0.0.173 → 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.
@@ -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, useCallback, } 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,8 +166,9 @@ 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());
|
171
|
+
// 스타일 메모이제이션
|
157
172
|
var createStyle = useCallback(function (pos) {
|
158
173
|
var usePercentages = props.usePercentages, containerWidth = props.containerWidth, useCSSTransforms = props.useCSSTransforms;
|
159
174
|
var style;
|
@@ -243,6 +258,9 @@ var GridItem = function (_a) {
|
|
243
258
|
*/
|
244
259
|
var onDrag = function (e, _a) {
|
245
260
|
var node = _a.node, deltaX = _a.deltaX, deltaY = _a.deltaY;
|
261
|
+
// throttle 적용
|
262
|
+
if (!throttleRef.current())
|
263
|
+
return;
|
246
264
|
if (!dragging) {
|
247
265
|
throw new Error('onDrag called before onDragStart.');
|
248
266
|
}
|
@@ -255,7 +273,6 @@ var GridItem = function (_a) {
|
|
255
273
|
var offsetParent = node.offsetParent;
|
256
274
|
if (offsetParent) {
|
257
275
|
var margin = props.margin, rowHeight = props.rowHeight;
|
258
|
-
// const colWidth = calcGridColWidth(positionParams);
|
259
276
|
var rowHeightNumber = resolveRowHeight(rowHeight, colWidth);
|
260
277
|
var bottomBoundary = offsetParent.clientHeight -
|
261
278
|
calcGridItemWHPx(h, rowHeightNumber, margin[1]);
|
@@ -266,6 +283,7 @@ var GridItem = function (_a) {
|
|
266
283
|
}
|
267
284
|
var newPosition = { top: top, left: left };
|
268
285
|
setDragging(newPosition);
|
286
|
+
// 계산 최적화
|
269
287
|
var _b = calcXY(positionParams, top, left, w, h), x = _b.x, y = _b.y;
|
270
288
|
props.onDrag && props.onDrag(i, x, y, { e: e, node: node, newPosition: newPosition });
|
271
289
|
};
|
@@ -342,6 +360,9 @@ var GridItem = function (_a) {
|
|
342
360
|
* @param {Object} callbackData an object with node and size information
|
343
361
|
*/
|
344
362
|
var onResize = function (e, callbackData) {
|
363
|
+
// throttle 적용
|
364
|
+
if (!throttleRef.current())
|
365
|
+
return;
|
345
366
|
setIsResizing(true);
|
346
367
|
onResizeHandler(e, callbackData, 'onResize');
|
347
368
|
};
|
@@ -390,10 +411,13 @@ var GridItem = function (_a) {
|
|
390
411
|
var _d = getResizableXYPosition(handle, w, h, prevW, prevH), newX = _d.newX, newY = _d.newY;
|
391
412
|
handler(i, w, h, { e: e, node: node, size: size }, newX, newY);
|
392
413
|
};
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
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]);
|
397
421
|
var child = React.Children.only(children);
|
398
422
|
var newChild = React.cloneElement(child, {
|
399
423
|
key: i,
|
@@ -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 &&
|