publ-echo 0.0.97 → 0.0.99
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.
|
@@ -81,7 +81,7 @@ var GridItem = function (_a) {
|
|
|
81
81
|
var _a = calcWH(getPositionParams(), {
|
|
82
82
|
width: width,
|
|
83
83
|
height: height,
|
|
84
|
-
}, x, y, 'e', props.w, props.h,
|
|
84
|
+
}, x, y, 'e', props.w, props.h, false), w_1 = _a.w, h_1 = _a.h;
|
|
85
85
|
if (keepWidth) {
|
|
86
86
|
w_1 = prevW;
|
|
87
87
|
}
|
|
@@ -198,7 +198,7 @@ var GridItem = function (_a) {
|
|
|
198
198
|
];
|
|
199
199
|
return (_jsx(Resizable, { draggableOpts: {
|
|
200
200
|
disabled: !isResizable,
|
|
201
|
-
}, 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 }));
|
|
201
|
+
}, 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, colWidth: colWidth, margin: props.margin, children: child }));
|
|
202
202
|
};
|
|
203
203
|
/**
|
|
204
204
|
* onDragStart event handler
|
|
@@ -58,8 +58,8 @@ export function calcWH(positionParams, _a, x, y, handleAxis, prevW, prevH, shoul
|
|
|
58
58
|
var colWidth = calcGridColWidth(positionParams);
|
|
59
59
|
var rowHeightNumber = resolveRowHeight(rowHeight, colWidth);
|
|
60
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]));
|
|
61
|
+
var w = roundOrCeil(truncateToOneDecimal((width + margin[0]) / (colWidth + margin[0])));
|
|
62
|
+
var h = roundOrCeil(roundToOneDecimal((height + margin[1]) / (rowHeightNumber + margin[1])));
|
|
63
63
|
// // Capping
|
|
64
64
|
// w = clamp(w, 0, cols - x);
|
|
65
65
|
// h = clamp(h, 0, maxRows - y);
|
|
@@ -107,3 +107,9 @@ export function calcWH(positionParams, _a, x, y, handleAxis, prevW, prevH, shoul
|
|
|
107
107
|
export function clamp(num, lowerBound, upperBound) {
|
|
108
108
|
return Math.max(Math.min(num, upperBound), lowerBound);
|
|
109
109
|
}
|
|
110
|
+
function roundToOneDecimal(num) {
|
|
111
|
+
return Math.floor(num * 10) / 10;
|
|
112
|
+
}
|
|
113
|
+
function truncateToOneDecimal(num) {
|
|
114
|
+
return Math.floor(num * 10) / 10;
|
|
115
|
+
}
|
|
@@ -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, isResizing, autoResize, ...props }: PropsWithChildren<Props>) => React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
5
|
+
declare const Resizable: ({ children, axis, handleSize, lockAspectRatio, minConstraints, maxConstraints, resizeHandles, transformScale, isResizing, autoResize, colWidth, margin, ...props }: PropsWithChildren<Props>) => React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
6
6
|
export default Resizable;
|
|
@@ -32,10 +32,10 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
32
32
|
import { createElement as _createElement } from "react";
|
|
33
33
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
34
34
|
import React, { useEffect, useRef } from "react";
|
|
35
|
-
import DraggableCore from "../Draggable/DraggableCore";
|
|
36
35
|
import { cloneElement } from "./utils/cloneElement";
|
|
36
|
+
import { DraggableCore } from "../Draggable";
|
|
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, isResizing = _a.isResizing, autoResize = _a.autoResize, props = __rest(_a, ["children", "axis", "handleSize", "lockAspectRatio", "minConstraints", "maxConstraints", "resizeHandles", "transformScale", "isResizing", "autoResize"]);
|
|
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, colWidth = _a.colWidth, margin = _a.margin, props = __rest(_a, ["children", "axis", "handleSize", "lockAspectRatio", "minConstraints", "maxConstraints", "resizeHandles", "transformScale", "isResizing", "autoResize", "colWidth", "margin"]);
|
|
39
39
|
var handleRefs = useRef({
|
|
40
40
|
s: useRef(null),
|
|
41
41
|
n: useRef(null),
|
|
@@ -48,13 +48,14 @@ var Resizable = function (_a) {
|
|
|
48
48
|
});
|
|
49
49
|
var startPosition = useRef(null);
|
|
50
50
|
var startSize = useRef(null);
|
|
51
|
-
var
|
|
52
|
-
var slack = null;
|
|
51
|
+
var lastHandleRectRef = useRef(null);
|
|
52
|
+
var slack = useRef(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
54
|
var elementRef = children.ref;
|
|
55
55
|
var extendedHeightRef = useRef(null);
|
|
56
56
|
var shouldShrinkRef = useRef(false);
|
|
57
57
|
var minWidth = useRef(0);
|
|
58
|
+
var minHeight = useRef(0);
|
|
58
59
|
useEffect(function () {
|
|
59
60
|
var _a;
|
|
60
61
|
if (!autoResize) {
|
|
@@ -74,6 +75,10 @@ var Resizable = function (_a) {
|
|
|
74
75
|
return;
|
|
75
76
|
}
|
|
76
77
|
var target = (_a = placeholder.children[0].children[0].children[0]) !== null && _a !== void 0 ? _a : placeholder.children[0].children[0];
|
|
78
|
+
if (target.clientHeight) {
|
|
79
|
+
minHeight.current = target.clientHeight;
|
|
80
|
+
}
|
|
81
|
+
// target.clientHeight -> 실제 "노드"의 height. (gridItem아닌)
|
|
77
82
|
if (target.clientHeight > elementRef.current.clientHeight) {
|
|
78
83
|
extendedHeightRef.current = target.clientHeight;
|
|
79
84
|
shouldShrinkRef.current = true;
|
|
@@ -82,18 +87,24 @@ var Resizable = function (_a) {
|
|
|
82
87
|
extendedHeightRef.current = null;
|
|
83
88
|
}
|
|
84
89
|
if (shouldShrinkRef.current && (target.clientHeight < elementRef.current.clientHeight)) {
|
|
85
|
-
|
|
90
|
+
minHeight.current = target.clientHeight;
|
|
86
91
|
}
|
|
87
92
|
var minWidthStyle = target.computedStyleMap().get('min-width');
|
|
88
|
-
if (typeof minWidthStyle.value === 'number') {
|
|
89
|
-
|
|
93
|
+
if (typeof minWidthStyle.value === 'number' && margin && colWidth) {
|
|
94
|
+
var minWidthBase = minWidthStyle.value;
|
|
95
|
+
var minColWidth = (minWidthBase + margin[0]) / (colWidth + margin[0]);
|
|
96
|
+
var minW = Math.ceil(minColWidth);
|
|
97
|
+
var minWidthPx = (minW * colWidth) + ((minW - 1) * margin[0]);
|
|
98
|
+
minWidth.current = Math.round(minWidthPx);
|
|
90
99
|
}
|
|
91
100
|
}, [isResizing, autoResize, children, elementRef]);
|
|
92
101
|
var resetData = function () {
|
|
93
|
-
|
|
102
|
+
lastHandleRectRef.current = null;
|
|
103
|
+
slack.current = null;
|
|
94
104
|
};
|
|
95
105
|
// NOTE - 최소 또는 최대 제약 조건 width와 height 계산, 비율 고정 계산
|
|
96
106
|
var checkConstraints = function (width, height) {
|
|
107
|
+
var _a;
|
|
97
108
|
if (!minConstraints && !maxConstraints && !lockAspectRatio) {
|
|
98
109
|
return [width, height];
|
|
99
110
|
}
|
|
@@ -108,19 +119,30 @@ var Resizable = function (_a) {
|
|
|
108
119
|
width = height * ratio;
|
|
109
120
|
}
|
|
110
121
|
}
|
|
111
|
-
|
|
112
|
-
|
|
122
|
+
console.log('w: ', width);
|
|
123
|
+
console.log('minW: ', minWidth.current);
|
|
124
|
+
var _b = [width, height], oldW = _b[0], oldH = _b[1];
|
|
125
|
+
var _c = (_a = slack.current) !== null && _a !== void 0 ? _a : [0, 0], slackW = _c[0], slackH = _c[1];
|
|
113
126
|
width += slackW;
|
|
114
127
|
height += slackH;
|
|
115
|
-
if (
|
|
116
|
-
width = Math.max(
|
|
117
|
-
height = Math.max(
|
|
128
|
+
if (autoResize) {
|
|
129
|
+
width = Math.max(minWidth.current, width);
|
|
130
|
+
height = Math.max(minHeight.current, height);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
if (minConstraints) {
|
|
134
|
+
width = Math.max(minConstraints[0], width);
|
|
135
|
+
height = Math.max(minConstraints[1], height);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (shouldShrinkRef.current) {
|
|
139
|
+
height = minHeight.current;
|
|
118
140
|
}
|
|
119
141
|
if (maxConstraints) {
|
|
120
142
|
width = Math.min(maxConstraints[0], width);
|
|
121
143
|
height = Math.min(maxConstraints[1], height);
|
|
122
144
|
}
|
|
123
|
-
slack = [slackW + (oldW - width), slackH + (oldH - height)];
|
|
145
|
+
slack.current = [slackW + (oldW - width), slackH + (oldH - height)];
|
|
124
146
|
return [width, height];
|
|
125
147
|
};
|
|
126
148
|
var checkTopLeft = function (deltaX, deltaY, top, left, width, height, handleAxis) {
|
|
@@ -167,7 +189,7 @@ var Resizable = function (_a) {
|
|
|
167
189
|
var resizeHandler = function (handlerName, handleAxis) {
|
|
168
190
|
return function (e, _a) {
|
|
169
191
|
var _b, _c;
|
|
170
|
-
var _d, _e, _f, _g, _h, _j
|
|
192
|
+
var _d, _e, _f, _g, _h, _j;
|
|
171
193
|
var node = _a.node, deltaX = _a.deltaX, deltaY = _a.deltaY;
|
|
172
194
|
if (handlerName === "onResizeStart") {
|
|
173
195
|
var position = { top: (_d = props.top) !== null && _d !== void 0 ? _d : 0, left: (_e = props.left) !== null && _e !== void 0 ? _e : 0 };
|
|
@@ -189,23 +211,25 @@ var Resizable = function (_a) {
|
|
|
189
211
|
var axisV = handleAxis[0];
|
|
190
212
|
var axisH = handleAxis[handleAxis.length - 1];
|
|
191
213
|
var handleRect = node.getBoundingClientRect();
|
|
192
|
-
// if (
|
|
214
|
+
// if (lastHandleRectRef.current !== null) {
|
|
193
215
|
// if (axisH === "w") {
|
|
194
|
-
// const deltaLeftSinceLast = handleRect.left -
|
|
216
|
+
// const deltaLeftSinceLast = handleRect.left - lastHandleRectRef.current.left;
|
|
217
|
+
// console.log('delta, :', deltaLeftSinceLast);
|
|
195
218
|
// deltaX += deltaLeftSinceLast;
|
|
196
219
|
// }
|
|
197
220
|
// if (axisV === "n") {
|
|
198
|
-
// const deltaTopSinceLast = handleRect.top -
|
|
221
|
+
// const deltaTopSinceLast = handleRect.top - lastHandleRectRef.current.top;
|
|
199
222
|
// deltaY += deltaTopSinceLast;
|
|
200
223
|
// }
|
|
201
224
|
// }
|
|
202
|
-
|
|
225
|
+
lastHandleRectRef.current = handleRect;
|
|
203
226
|
if (axisH === "w") {
|
|
204
227
|
deltaX = -deltaX;
|
|
205
228
|
}
|
|
206
229
|
if (axisV === "n") {
|
|
207
230
|
deltaY = -deltaY;
|
|
208
231
|
}
|
|
232
|
+
console.log(deltaX);
|
|
209
233
|
var width = props.width + (canDragX ? deltaX / transformScale : 0);
|
|
210
234
|
var height = props.height + (canDragY ? deltaY / transformScale : 0);
|
|
211
235
|
var left = (_h = props === null || props === void 0 ? void 0 : props.left) !== null && _h !== void 0 ? _h : 0;
|
|
@@ -216,19 +240,16 @@ var Resizable = function (_a) {
|
|
|
216
240
|
if (axisH === "w") {
|
|
217
241
|
left = left - deltaX;
|
|
218
242
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (extendedHeightRef.current) {
|
|
222
|
-
height = extendedHeightRef.current;
|
|
243
|
+
_b = checkConstraints(width, height), width = _b[0], height = _b[1];
|
|
244
|
+
if (autoResize && minHeight.current === height) {
|
|
223
245
|
handleAxis = removeNorthHandle(handleAxis);
|
|
224
246
|
}
|
|
225
|
-
_b = checkConstraints(width, height), width = _b[0], height = _b[1];
|
|
226
247
|
_c = checkTopLeft(deltaX, deltaY, top, left, width, height, handleAxis), top = _c[0], left = _c[1];
|
|
227
248
|
var isDimensionsChanged = width !== props.width || height !== props.height;
|
|
228
249
|
var cb = typeof props[handlerName] === "function" ? props[handlerName] : null;
|
|
229
250
|
var isCbSkipped = handlerName === "onResize" && !isDimensionsChanged;
|
|
230
251
|
if (cb && !isCbSkipped) {
|
|
231
|
-
cb(e, { node: node, size: { width: width, height: height, top: top, left: left }, handle: handleAxis
|
|
252
|
+
cb(e, { node: node, size: { width: width, height: height, top: top, left: left }, handle: handleAxis });
|
|
232
253
|
}
|
|
233
254
|
if (handlerName === "onResizeStop") {
|
|
234
255
|
startPosition.current = null;
|
|
@@ -63,5 +63,7 @@ export type ResizableProps = {
|
|
|
63
63
|
height: number;
|
|
64
64
|
isResizing?: boolean;
|
|
65
65
|
autoResize?: boolean;
|
|
66
|
+
colWidth?: number;
|
|
67
|
+
margin?: [number, number];
|
|
66
68
|
};
|
|
67
69
|
export type ResizeHandleType = ReactElement<any> | ((resizeHandleAxis: ResizeHandleAxis, ref: Ref<HTMLElement>) => ReactElement<any>);
|