publ-echo 0.0.5 → 0.0.7
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/App.d.ts +2 -0
- package/dist/App.js +18 -0
- package/dist/examples/ReactGridLayout/ReactGridLayoutShowcase01.d.ts +2 -0
- package/dist/examples/ReactGridLayout/ReactGridLayoutShowcase01.js +57 -0
- package/dist/examples/ReactGridLayout/index.d.ts +1 -0
- package/dist/examples/ReactGridLayout/index.js +1 -0
- package/dist/examples/ResponsiveGridLayout/ResponsiveGridLayoutShowcase01.d.ts +2 -0
- package/dist/examples/ResponsiveGridLayout/ResponsiveGridLayoutShowcase01.js +69 -0
- package/dist/examples/ResponsiveGridLayout/index.d.ts +1 -0
- package/dist/examples/ResponsiveGridLayout/index.js +1 -0
- package/dist/examples/index.d.ts +2 -0
- package/dist/examples/index.js +2 -0
- package/dist/examples/utils.d.ts +8 -0
- package/dist/examples/utils.js +14 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +12 -0
- package/dist/lib/Draggable/Draggable.d.ts +17 -0
- package/dist/lib/Draggable/Draggable.js +192 -0
- package/dist/lib/Draggable/DraggableCore.d.ts +5 -0
- package/dist/lib/Draggable/DraggableCore.js +266 -0
- package/dist/lib/Draggable/constants.d.ts +12 -0
- package/dist/lib/Draggable/constants.js +12 -0
- package/dist/lib/Draggable/index.d.ts +2 -0
- package/dist/lib/Draggable/index.js +2 -0
- package/dist/lib/Draggable/types.d.ts +55 -0
- package/dist/lib/Draggable/types.js +1 -0
- package/dist/lib/Draggable/utils/domHelpers.d.ts +22 -0
- package/dist/lib/Draggable/utils/domHelpers.js +222 -0
- package/dist/lib/Draggable/utils/getPrefix.d.ts +5 -0
- package/dist/lib/Draggable/utils/getPrefix.js +41 -0
- package/dist/lib/Draggable/utils/positionHelpers.d.ts +7 -0
- package/dist/lib/Draggable/utils/positionHelpers.js +32 -0
- package/dist/lib/Draggable/utils/types.d.ts +30 -0
- package/dist/lib/Draggable/utils/types.js +1 -0
- package/dist/lib/Draggable/utils/validationHelpers.d.ts +4 -0
- package/dist/lib/Draggable/utils/validationHelpers.js +16 -0
- package/dist/lib/GridItem/GridItem.d.ts +5 -0
- package/dist/lib/GridItem/GridItem.js +324 -0
- package/dist/lib/GridItem/index.d.ts +1 -0
- package/dist/lib/GridItem/index.js +1 -0
- package/dist/lib/GridItem/types.d.ts +105 -0
- package/dist/lib/GridItem/types.js +1 -0
- package/dist/lib/GridItem/utils/calculateUtils.d.ts +30 -0
- package/dist/lib/GridItem/utils/calculateUtils.js +108 -0
- package/dist/lib/GridLayoutEditor/ReactGridLayout.d.ts +4 -0
- package/dist/lib/GridLayoutEditor/ReactGridLayout.js +423 -0
- package/dist/lib/GridLayoutEditor/ResponsiveGridLayout.d.ts +4 -0
- package/dist/lib/GridLayoutEditor/ResponsiveGridLayout.js +117 -0
- package/dist/lib/GridLayoutEditor/index.d.ts +3 -0
- package/dist/lib/GridLayoutEditor/index.js +2 -0
- package/dist/lib/GridLayoutEditor/types.d.ts +129 -0
- package/dist/lib/GridLayoutEditor/types.js +1 -0
- package/dist/lib/GridLayoutEditor/utils/renderHelpers.d.ts +164 -0
- package/dist/lib/GridLayoutEditor/utils/renderHelpers.js +591 -0
- package/dist/lib/GridLayoutEditor/utils/responsiveUtils.d.ts +26 -0
- package/dist/lib/GridLayoutEditor/utils/responsiveUtils.js +77 -0
- package/dist/lib/PreviewGLE/ReactGridLayoutPreview.d.ts +7 -0
- package/dist/lib/PreviewGLE/ReactGridLayoutPreview.js +35 -0
- package/dist/lib/PreviewGLE/ResponsiveGridLayoutPreview.d.ts +9 -0
- package/dist/lib/PreviewGLE/ResponsiveGridLayoutPreview.js +38 -0
- package/dist/lib/PreviewGLE/index.d.ts +2 -0
- package/dist/lib/PreviewGLE/index.js +2 -0
- package/dist/lib/Resizable/Resizable.d.ts +6 -0
- package/dist/lib/Resizable/Resizable.js +215 -0
- package/dist/lib/Resizable/ResizableBox.d.ts +7 -0
- package/dist/lib/Resizable/ResizableBox.js +57 -0
- package/dist/lib/Resizable/index.d.ts +1 -0
- package/dist/lib/Resizable/index.js +1 -0
- package/dist/lib/Resizable/types.d.ts +63 -0
- package/dist/lib/Resizable/types.js +1 -0
- package/dist/lib/Resizable/utils/cloneElement.d.ts +2 -0
- package/dist/lib/Resizable/utils/cloneElement.js +21 -0
- package/dist/lib/components/WidthProvider.d.ts +9 -0
- package/dist/lib/components/WidthProvider.js +55 -0
- package/dist/lib/components/index.d.ts +1 -0
- package/dist/lib/components/index.js +1 -0
- package/dist/lib/components/types.d.ts +13 -0
- package/dist/lib/components/types.js +1 -0
- package/dist/lib/index.d.ts +5 -0
- package/dist/lib/index.js +5 -0
- package/dist/reportWebVitals.d.ts +3 -0
- package/dist/reportWebVitals.js +13 -0
- package/dist/setupTests.d.ts +1 -0
- package/dist/setupTests.js +5 -0
- package/dist/utils/types.d.ts +4 -0
- package/dist/utils/types.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,266 @@
|
|
|
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 __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
24
|
+
import { addEvent, addUserSelectStyles, getTouch, getTouchIdentifier, matchSelectorAndParentsTo, offsetXYFromParent, removeEvent, removeUserSelectStyles, } from "./utils/domHelpers";
|
|
25
|
+
import { isNum } from "./utils/validationHelpers";
|
|
26
|
+
import { snapToGrid } from "./utils/positionHelpers";
|
|
27
|
+
import { EVENTS } from "./constants";
|
|
28
|
+
var DraggableCore = function (_a) {
|
|
29
|
+
var _b;
|
|
30
|
+
var _c = _a.allowAnyClick, allowAnyClick = _c === void 0 ? false : _c, _d = _a.disabled, disabled = _d === void 0 ? false : _d, _e = _a.enableUserSelectHack, enableUserSelectHack = _e === void 0 ? true : _e, _f = _a.onStart, onStart = _f === void 0 ? function () { } : _f, _g = _a.onDrag, onDrag = _g === void 0 ? function () { } : _g, _h = _a.onStop, onStop = _h === void 0 ? function () { } : _h, _j = _a.onMouseDown, onMouseDown = _j === void 0 ? function () { } : _j, _k = _a.scale, scale = _k === void 0 ? 1 : _k, children = _a.children, props = __rest(_a, ["allowAnyClick", "disabled", "enableUserSelectHack", "onStart", "onDrag", "onStop", "onMouseDown", "scale", "children"]);
|
|
31
|
+
var draggableCoreRef = useRef(null);
|
|
32
|
+
var isMounted = useRef(false);
|
|
33
|
+
var _l = useState({
|
|
34
|
+
dragging: false,
|
|
35
|
+
lastX: NaN,
|
|
36
|
+
lastY: NaN,
|
|
37
|
+
touchIdentifier: null,
|
|
38
|
+
}), draggableCoreState = _l[0], setDraggableCoreState = _l[1];
|
|
39
|
+
/**
|
|
40
|
+
* @when DraggableCore가 랜더링 했을 때
|
|
41
|
+
* @expected 해당 DOMNode에서 Drag가 동작할 수 있도록 event를 추가합니다.
|
|
42
|
+
* @clear 등록된 모든 EventListener들을 remove합니다.
|
|
43
|
+
*/
|
|
44
|
+
useEffect(function () {
|
|
45
|
+
var thisNode = findDOMNode();
|
|
46
|
+
if (thisNode) {
|
|
47
|
+
addEvent(thisNode, EVENTS.TOUCH.START, handleTouchStart, {
|
|
48
|
+
passive: false,
|
|
49
|
+
});
|
|
50
|
+
if (draggableCoreState.dragging) {
|
|
51
|
+
addEvent(thisNode.ownerDocument, dragEventFor.MOVE, handleDrag);
|
|
52
|
+
addEvent(thisNode.ownerDocument, dragEventFor.STOP, handleDragStop);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
removeEvent(thisNode.ownerDocument, dragEventFor.MOVE, handleDrag);
|
|
56
|
+
removeEvent(thisNode.ownerDocument, dragEventFor.STOP, handleDragStop);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return function () {
|
|
60
|
+
if (thisNode) {
|
|
61
|
+
var ownerDocument = thisNode.ownerDocument;
|
|
62
|
+
removeEvent(ownerDocument, EVENTS.MOUSE.MOVE, handleDrag);
|
|
63
|
+
removeEvent(ownerDocument, EVENTS.MOUSE.STOP, handleDragStop);
|
|
64
|
+
removeEvent(ownerDocument, EVENTS.TOUCH.MOVE, handleDrag);
|
|
65
|
+
removeEvent(ownerDocument, EVENTS.TOUCH.STOP, handleDragStop);
|
|
66
|
+
removeEvent(thisNode, EVENTS.TOUCH.START, handleTouchStart, {
|
|
67
|
+
passive: false,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}, [handleDragStart, handleDrag, handleDragStop]);
|
|
72
|
+
/**
|
|
73
|
+
* @when DraggableCore가 랜더링 했을 때
|
|
74
|
+
* @expected mount된 상태를 true로 변경합니다.
|
|
75
|
+
* @clear mount된 상태를 false로 변경하고, 등록된 styles을 제거합니다.
|
|
76
|
+
*/
|
|
77
|
+
useEffect(function () {
|
|
78
|
+
isMounted.current = true;
|
|
79
|
+
return function () {
|
|
80
|
+
isMounted.current = false;
|
|
81
|
+
var thisNode = findDOMNode();
|
|
82
|
+
if (thisNode) {
|
|
83
|
+
var ownerDocument = thisNode.ownerDocument;
|
|
84
|
+
if (enableUserSelectHack)
|
|
85
|
+
removeUserSelectStyles(ownerDocument);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
// NOTE - react-draggable과 동일하게 동작하게 하기 위해서 dependency를 제거하였습니다.
|
|
89
|
+
}, []);
|
|
90
|
+
var dragEventFor = EVENTS.MOUSE;
|
|
91
|
+
// NOTE - draggable할 node element를 찾는 함수
|
|
92
|
+
var findDOMNode = function () {
|
|
93
|
+
var _a, _b;
|
|
94
|
+
return (_b = (_a = props === null || props === void 0 ? void 0 : props.nodeRef) === null || _a === void 0 ? void 0 : _a.current) !== null && _b !== void 0 ? _b : draggableCoreRef === null || draggableCoreRef === void 0 ? void 0 : draggableCoreRef.current;
|
|
95
|
+
};
|
|
96
|
+
// NOTE - event 발생 시 {x, y} position을 가져오는 함수
|
|
97
|
+
var getControlPosition = function (e, touchIdentifier) {
|
|
98
|
+
var _a;
|
|
99
|
+
var touchObj = typeof touchIdentifier === "number" ? getTouch(e, touchIdentifier) : null;
|
|
100
|
+
// NOTE - 올바르게 touch를 하지 않은 경우
|
|
101
|
+
if (typeof touchIdentifier === "number" && !touchObj)
|
|
102
|
+
return null;
|
|
103
|
+
var thisNode = findDOMNode();
|
|
104
|
+
var offsetParent = (props === null || props === void 0 ? void 0 : props.offsetParent) ||
|
|
105
|
+
(thisNode === null || thisNode === void 0 ? void 0 : thisNode.offsetParent) ||
|
|
106
|
+
((_a = thisNode === null || thisNode === void 0 ? void 0 : thisNode.ownerDocument) === null || _a === void 0 ? void 0 : _a.body);
|
|
107
|
+
if (!offsetParent)
|
|
108
|
+
return null;
|
|
109
|
+
return offsetXYFromParent(touchObj || e, offsetParent, scale);
|
|
110
|
+
};
|
|
111
|
+
var createCoreData = function (x, y) {
|
|
112
|
+
var isStart = !isNum(draggableCoreState.lastX);
|
|
113
|
+
var node = findDOMNode();
|
|
114
|
+
if (!node)
|
|
115
|
+
return;
|
|
116
|
+
if (isStart) {
|
|
117
|
+
return {
|
|
118
|
+
node: node,
|
|
119
|
+
deltaX: 0,
|
|
120
|
+
deltaY: 0,
|
|
121
|
+
lastX: x,
|
|
122
|
+
lastY: y,
|
|
123
|
+
x: x,
|
|
124
|
+
y: y,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
return {
|
|
129
|
+
node: node,
|
|
130
|
+
deltaX: x - draggableCoreState.lastX,
|
|
131
|
+
deltaY: y - draggableCoreState.lastY,
|
|
132
|
+
lastX: draggableCoreState.lastX,
|
|
133
|
+
lastY: draggableCoreState.lastY,
|
|
134
|
+
x: x,
|
|
135
|
+
y: y,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
function handleDragStart(e) {
|
|
140
|
+
onMouseDown && onMouseDown(e);
|
|
141
|
+
// NOTE - left clicks만 가능
|
|
142
|
+
if (!allowAnyClick && typeof e.button === "number" && e.button !== 0) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
var thisNode = findDOMNode();
|
|
146
|
+
if (!thisNode || !thisNode.ownerDocument || !thisNode.ownerDocument.body) {
|
|
147
|
+
throw new Error("<DraggableCore> not mounted on DragStart!");
|
|
148
|
+
}
|
|
149
|
+
var ownerDocument = thisNode.ownerDocument;
|
|
150
|
+
// NOTE - handle || cancel prop이 제공되었을 때 selector와 match되는지를 확인
|
|
151
|
+
// handle prop이 존재할 때, matchSelectorAndParentsTo 메소드를 통해 thisNode와 일치하는 element만 Drag 가능
|
|
152
|
+
// cancel prop이 존재할 때, matchSelectorAndParentsTo 메소드를 통해 thisNode와 일치하는 element는 Drag 불가능
|
|
153
|
+
if (disabled ||
|
|
154
|
+
!(ownerDocument.defaultView &&
|
|
155
|
+
e.target instanceof ownerDocument.defaultView.Node) ||
|
|
156
|
+
(props.handle &&
|
|
157
|
+
!matchSelectorAndParentsTo(e.target, props.handle, thisNode)) ||
|
|
158
|
+
(props.cancel &&
|
|
159
|
+
matchSelectorAndParentsTo(e.target, props.cancel, thisNode))) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
// NOTE - ipad || iphone과 같은 mobile 기기에서 scroll 방지
|
|
163
|
+
if (e.type === "touchstart")
|
|
164
|
+
e.preventDefault();
|
|
165
|
+
// NOTE - touch event가 발생했을 때 multi touch 상황에서 각각의 터치를 구분하고 다른 처리를 할 수 있게 하기 위함입니다.
|
|
166
|
+
var touchIdentifier = getTouchIdentifier(e);
|
|
167
|
+
if (touchIdentifier) {
|
|
168
|
+
setDraggableCoreState(__assign(__assign({}, draggableCoreState), { touchIdentifier: touchIdentifier }));
|
|
169
|
+
}
|
|
170
|
+
var position = getControlPosition(e, touchIdentifier);
|
|
171
|
+
if (!position)
|
|
172
|
+
return;
|
|
173
|
+
var x = position.x, y = position.y;
|
|
174
|
+
var coreEvent = createCoreData(x, y);
|
|
175
|
+
if (!coreEvent)
|
|
176
|
+
return;
|
|
177
|
+
var shouldUpdate = onStart(e, coreEvent);
|
|
178
|
+
if (shouldUpdate === false || isMounted.current === false)
|
|
179
|
+
return;
|
|
180
|
+
if (enableUserSelectHack)
|
|
181
|
+
addUserSelectStyles(ownerDocument);
|
|
182
|
+
setDraggableCoreState(function (prev) { return (__assign(__assign({}, prev), { dragging: true, lastX: x, lastY: y })); });
|
|
183
|
+
}
|
|
184
|
+
function handleDrag(e) {
|
|
185
|
+
var _a;
|
|
186
|
+
var position = getControlPosition(e, draggableCoreState.touchIdentifier);
|
|
187
|
+
if (!position)
|
|
188
|
+
return;
|
|
189
|
+
var x = position.x, y = position.y;
|
|
190
|
+
if (Array.isArray(props.grid)) {
|
|
191
|
+
var deltaX = x - draggableCoreState.lastX;
|
|
192
|
+
var deltaY = y - draggableCoreState.lastY;
|
|
193
|
+
_a = snapToGrid(props.grid, deltaX, deltaY), deltaX = _a[0], deltaY = _a[1];
|
|
194
|
+
if (!deltaX && !deltaY)
|
|
195
|
+
return;
|
|
196
|
+
x = draggableCoreState.lastX + deltaX;
|
|
197
|
+
y = draggableCoreState.lastY + deltaY;
|
|
198
|
+
}
|
|
199
|
+
var coreEvent = createCoreData(x, y);
|
|
200
|
+
var thisNode = findDOMNode();
|
|
201
|
+
if (!coreEvent || !thisNode)
|
|
202
|
+
return;
|
|
203
|
+
var shouldUpdate = onDrag(e, coreEvent, thisNode);
|
|
204
|
+
if (shouldUpdate === false || isMounted.current === false) {
|
|
205
|
+
handleDragStop(e);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
setDraggableCoreState(function (prevState) { return (__assign(__assign({}, prevState), { lastX: x, lastY: y })); });
|
|
209
|
+
}
|
|
210
|
+
function handleDragStop(e) {
|
|
211
|
+
var _a;
|
|
212
|
+
if (!draggableCoreState.dragging)
|
|
213
|
+
return;
|
|
214
|
+
var position = getControlPosition(e, draggableCoreState.touchIdentifier);
|
|
215
|
+
if (!position)
|
|
216
|
+
return;
|
|
217
|
+
var x = position.x, y = position.y;
|
|
218
|
+
if (Array.isArray(props === null || props === void 0 ? void 0 : props.grid)) {
|
|
219
|
+
var deltaX = x - draggableCoreState.lastX || 0;
|
|
220
|
+
var deltaY = y - draggableCoreState.lastY || 0;
|
|
221
|
+
_a = snapToGrid(props === null || props === void 0 ? void 0 : props.grid, deltaX, deltaY), deltaX = _a[0], deltaY = _a[1];
|
|
222
|
+
x = draggableCoreState.lastX + deltaX;
|
|
223
|
+
y = draggableCoreState.lastY + deltaY;
|
|
224
|
+
}
|
|
225
|
+
var coreEvent = createCoreData(x, y);
|
|
226
|
+
if (!coreEvent)
|
|
227
|
+
return;
|
|
228
|
+
var shouldContinue = onStop(e, coreEvent);
|
|
229
|
+
if (shouldContinue === false || isMounted.current === false)
|
|
230
|
+
return false;
|
|
231
|
+
var thisNode = findDOMNode();
|
|
232
|
+
if (thisNode) {
|
|
233
|
+
if (enableUserSelectHack)
|
|
234
|
+
removeUserSelectStyles(thisNode.ownerDocument);
|
|
235
|
+
}
|
|
236
|
+
setDraggableCoreState(function (prev) { return (__assign(__assign({}, prev), { dragging: false, lastX: NaN, lastY: NaN })); });
|
|
237
|
+
if (thisNode) {
|
|
238
|
+
removeEvent(thisNode.ownerDocument, dragEventFor.MOVE, handleDrag);
|
|
239
|
+
removeEvent(thisNode.ownerDocument, dragEventFor.STOP, handleDragStop);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
var handleMouseDown = function (e) {
|
|
243
|
+
dragEventFor = EVENTS.MOUSE;
|
|
244
|
+
return handleDragStart(e);
|
|
245
|
+
};
|
|
246
|
+
var handleMouseUp = function (e) {
|
|
247
|
+
dragEventFor = EVENTS.MOUSE;
|
|
248
|
+
return handleDragStop(e);
|
|
249
|
+
};
|
|
250
|
+
// NOTE - handleMouseDown(start drag)과 동일하지만 touch device에 대응
|
|
251
|
+
var handleTouchStart = function (e) {
|
|
252
|
+
dragEventFor = EVENTS.TOUCH;
|
|
253
|
+
return handleDragStart(e);
|
|
254
|
+
};
|
|
255
|
+
var handleTouchEnd = function (e) {
|
|
256
|
+
dragEventFor = EVENTS.TOUCH;
|
|
257
|
+
return handleDragStop(e);
|
|
258
|
+
};
|
|
259
|
+
return React.cloneElement(children, {
|
|
260
|
+
onMouseDown: handleMouseDown,
|
|
261
|
+
onMouseUp: handleMouseUp,
|
|
262
|
+
onTouchEnd: handleTouchEnd,
|
|
263
|
+
ref: (_b = props.nodeRef) !== null && _b !== void 0 ? _b : draggableCoreRef,
|
|
264
|
+
});
|
|
265
|
+
};
|
|
266
|
+
export default DraggableCore;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ReactElement, RefObject } from "react";
|
|
2
|
+
import { ControlPosition, DraggableEventHandler, PositionOffsetControlPosition } from "./utils/types";
|
|
3
|
+
export type DraggableCoreState = {
|
|
4
|
+
dragging: boolean;
|
|
5
|
+
lastX: number;
|
|
6
|
+
lastY: number;
|
|
7
|
+
touchIdentifier?: number | null;
|
|
8
|
+
};
|
|
9
|
+
export type DraggableData = {
|
|
10
|
+
node: HTMLElement;
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
deltaX: number;
|
|
14
|
+
deltaY: number;
|
|
15
|
+
lastX: number;
|
|
16
|
+
lastY: number;
|
|
17
|
+
};
|
|
18
|
+
export type DraggableCoreDefaultProps = {
|
|
19
|
+
allowAnyClick?: boolean;
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
enableUserSelectHack?: boolean;
|
|
22
|
+
onStart?: DraggableEventHandler | Function;
|
|
23
|
+
onDrag?: DraggableEventHandler | Function;
|
|
24
|
+
onStop?: DraggableEventHandler | Function;
|
|
25
|
+
onMouseDown?: (e: MouseEvent) => void;
|
|
26
|
+
scale?: number;
|
|
27
|
+
cancel?: string;
|
|
28
|
+
children: ReactElement<any>;
|
|
29
|
+
offsetParent?: HTMLElement;
|
|
30
|
+
grid?: [number, number];
|
|
31
|
+
handle?: string;
|
|
32
|
+
nodeRef?: RefObject<HTMLElement>;
|
|
33
|
+
className?: string;
|
|
34
|
+
style?: Object;
|
|
35
|
+
};
|
|
36
|
+
export type DraggableState = {
|
|
37
|
+
dragging: boolean;
|
|
38
|
+
dragged: boolean;
|
|
39
|
+
x: number;
|
|
40
|
+
y: number;
|
|
41
|
+
slackX: number;
|
|
42
|
+
slackY: number;
|
|
43
|
+
isElementSVG: boolean;
|
|
44
|
+
prevPropsPosition?: ControlPosition;
|
|
45
|
+
};
|
|
46
|
+
export type DraggablePositionType = {
|
|
47
|
+
positionOffset?: PositionOffsetControlPosition;
|
|
48
|
+
position?: ControlPosition;
|
|
49
|
+
};
|
|
50
|
+
export type DraggableProps = DraggablePositionType & DraggableCoreDefaultProps;
|
|
51
|
+
export type PropsWithChildren<P> = P & {
|
|
52
|
+
children: ReactElement<any>;
|
|
53
|
+
};
|
|
54
|
+
export type AxisType = "both" | "x" | "y" | "none";
|
|
55
|
+
export type DraggableEvent = React.MouseEvent<HTMLElement | SVGElement> | React.TouchEvent<HTMLElement | SVGElement> | MouseEvent | TouchEvent;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ControlPosition, PositionOffsetControlPosition, MouseTouchEvent, EventWithOffset, EventHandler } from "./types";
|
|
2
|
+
export declare const matchSelector: (el: Node, selector: string) => boolean;
|
|
3
|
+
export declare const matchSelectorAndParentsTo: (el: Node, selector: string, baseNode: Node) => boolean;
|
|
4
|
+
export declare const addEvent: (el: Node, eventType: string, handler: EventHandler<any>, inputOptions?: Object) => void;
|
|
5
|
+
export declare const removeEvent: (el: Node, eventType: string, handler: EventHandler<any>, inputOptions?: Object) => void;
|
|
6
|
+
export declare const outerHeight: (node: HTMLElement) => number;
|
|
7
|
+
export declare const outerWidth: (node: HTMLElement) => number;
|
|
8
|
+
export declare const innerHeight: (node: HTMLElement) => number;
|
|
9
|
+
export declare const innerWidth: (node: HTMLElement) => number;
|
|
10
|
+
export declare const offsetXYFromParent: (evt: EventWithOffset, offsetParent: Element, scale: number) => ControlPosition;
|
|
11
|
+
export declare const createCSSTransform: (controlPos: ControlPosition, positionOffset?: PositionOffsetControlPosition) => Object;
|
|
12
|
+
export declare const createSVGTransform: (controlPos: ControlPosition, positionOffset?: PositionOffsetControlPosition) => string;
|
|
13
|
+
export declare const getTranslation: ({ x, y }: ControlPosition, unitSuffix: string, positionOffset?: PositionOffsetControlPosition) => string;
|
|
14
|
+
export declare const getTouch: (e: MouseTouchEvent, identifier: number) => {
|
|
15
|
+
clientX: number;
|
|
16
|
+
clientY: number;
|
|
17
|
+
};
|
|
18
|
+
export declare const getTouchIdentifier: (e: MouseTouchEvent) => number | undefined;
|
|
19
|
+
export declare const addUserSelectStyles: (doc?: Document) => void;
|
|
20
|
+
export declare const removeUserSelectStyles: (doc?: Document) => void;
|
|
21
|
+
export declare const addClassName: (el: HTMLElement, className: string) => void;
|
|
22
|
+
export declare const removeClassName: (el: HTMLElement, className: string) => void;
|
|
@@ -0,0 +1,222 @@
|
|
|
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
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
13
|
+
import browserPrefix, { browserPrefixToKey } from "./getPrefix";
|
|
14
|
+
import { findInArray, int, isFunction } from "./validationHelpers";
|
|
15
|
+
export var matchSelector = function (el, selector) {
|
|
16
|
+
var matchedSelector = "";
|
|
17
|
+
var selectors = [
|
|
18
|
+
"matches",
|
|
19
|
+
"webkitMatchesSelector",
|
|
20
|
+
// "mozMatchesSelector",
|
|
21
|
+
// "msMatchesSelector",
|
|
22
|
+
// "oMatchesSelector",
|
|
23
|
+
];
|
|
24
|
+
var callback = function (method) {
|
|
25
|
+
return isFunction(el[method]);
|
|
26
|
+
};
|
|
27
|
+
if (!matchedSelector) {
|
|
28
|
+
matchedSelector = findInArray(selectors, callback);
|
|
29
|
+
if (matchedSelector === "matches" ||
|
|
30
|
+
matchedSelector === "webkitMatchesSelector") {
|
|
31
|
+
return el[matchedSelector](selector);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
};
|
|
36
|
+
export var matchSelectorAndParentsTo = function (el, selector, baseNode) {
|
|
37
|
+
var node = el;
|
|
38
|
+
do {
|
|
39
|
+
if (matchSelector(node, selector))
|
|
40
|
+
return true;
|
|
41
|
+
if (node === baseNode)
|
|
42
|
+
return false;
|
|
43
|
+
if (node.parentNode)
|
|
44
|
+
node = node.parentNode;
|
|
45
|
+
} while (node);
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
48
|
+
export var addEvent = function (el, eventType, handler, inputOptions) {
|
|
49
|
+
if (!el)
|
|
50
|
+
return;
|
|
51
|
+
var options = __assign({ capture: true }, inputOptions);
|
|
52
|
+
if (el.addEventListener) {
|
|
53
|
+
el.addEventListener(eventType, handler, options);
|
|
54
|
+
}
|
|
55
|
+
// if (el.addEventListener) {
|
|
56
|
+
// el.addEventListener(eventType, handler, options);
|
|
57
|
+
// } else {
|
|
58
|
+
// (el as { [key: string]: any })['on' + eventType] = handler;
|
|
59
|
+
// }
|
|
60
|
+
};
|
|
61
|
+
export var removeEvent = function (el, eventType, handler, inputOptions) {
|
|
62
|
+
if (!el)
|
|
63
|
+
return;
|
|
64
|
+
var options = __assign({ capture: true }, inputOptions);
|
|
65
|
+
if (el.removeEventListener) {
|
|
66
|
+
el.removeEventListener(eventType, handler, options);
|
|
67
|
+
}
|
|
68
|
+
// if (el.removeEventListener) {
|
|
69
|
+
// el.removeEventListener(eventType, handler, options);
|
|
70
|
+
// } else {
|
|
71
|
+
// (el as { [key: string]: any })['on' + eventType] = null;
|
|
72
|
+
// }
|
|
73
|
+
};
|
|
74
|
+
export var outerHeight = function (node) {
|
|
75
|
+
var _a;
|
|
76
|
+
var height = node.clientHeight;
|
|
77
|
+
var computedStyle = (_a = node.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.getComputedStyle(node);
|
|
78
|
+
if (computedStyle) {
|
|
79
|
+
height += int(computedStyle.borderTopWidth);
|
|
80
|
+
height += int(computedStyle.borderBottomWidth);
|
|
81
|
+
return height;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
return height;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
export var outerWidth = function (node) {
|
|
88
|
+
var _a;
|
|
89
|
+
var width = node.clientWidth;
|
|
90
|
+
var computedStyle = (_a = node.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.getComputedStyle(node);
|
|
91
|
+
if (computedStyle) {
|
|
92
|
+
width += int(computedStyle.borderLeftWidth);
|
|
93
|
+
width += int(computedStyle.borderRightWidth);
|
|
94
|
+
return width;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
return width;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
export var innerHeight = function (node) {
|
|
101
|
+
var _a;
|
|
102
|
+
var height = node.clientHeight;
|
|
103
|
+
var computedStyle = (_a = node.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.getComputedStyle(node);
|
|
104
|
+
if (computedStyle) {
|
|
105
|
+
height -= int(computedStyle.paddingTop);
|
|
106
|
+
height -= int(computedStyle.paddingBottom);
|
|
107
|
+
return height;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
return height;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
export var innerWidth = function (node) {
|
|
114
|
+
var _a;
|
|
115
|
+
var width = node.clientWidth;
|
|
116
|
+
var computedStyle = (_a = node.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.getComputedStyle(node);
|
|
117
|
+
if (computedStyle) {
|
|
118
|
+
width -= int(computedStyle.paddingLeft);
|
|
119
|
+
width -= int(computedStyle.paddingRight);
|
|
120
|
+
return width;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
return width;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
export var offsetXYFromParent = function (evt, offsetParent, scale) {
|
|
127
|
+
var isBody = offsetParent.ownerDocument.body;
|
|
128
|
+
var offsetParentRect = isBody
|
|
129
|
+
? { left: 0, top: 0 }
|
|
130
|
+
: offsetParent.getBoundingClientRect();
|
|
131
|
+
var x = (evt.clientX + offsetParent.scrollLeft - offsetParentRect.left) / scale;
|
|
132
|
+
var y = (evt.clientY + offsetParent.scrollTop - offsetParentRect.top) / scale;
|
|
133
|
+
return { x: x, y: y };
|
|
134
|
+
};
|
|
135
|
+
export var createCSSTransform = function (controlPos, positionOffset) {
|
|
136
|
+
var _a;
|
|
137
|
+
var translation = getTranslation(controlPos, "px", positionOffset);
|
|
138
|
+
return _a = {}, _a[browserPrefixToKey("transform", browserPrefix)] = translation, _a;
|
|
139
|
+
};
|
|
140
|
+
export var createSVGTransform = function (controlPos, positionOffset) {
|
|
141
|
+
var translation = getTranslation(controlPos, "", positionOffset);
|
|
142
|
+
return translation;
|
|
143
|
+
};
|
|
144
|
+
export var getTranslation = function (_a, unitSuffix, positionOffset) {
|
|
145
|
+
var x = _a.x, y = _a.y;
|
|
146
|
+
var translation = "translate(".concat(x).concat(unitSuffix, ",").concat(y).concat(unitSuffix, ")");
|
|
147
|
+
if (positionOffset) {
|
|
148
|
+
var defaultX = "".concat(typeof positionOffset.x === "string"
|
|
149
|
+
? positionOffset.x
|
|
150
|
+
: positionOffset.x + unitSuffix);
|
|
151
|
+
var defaultY = "".concat(typeof positionOffset.y === "string"
|
|
152
|
+
? positionOffset.y
|
|
153
|
+
: positionOffset.y + unitSuffix);
|
|
154
|
+
translation = "translate(".concat(defaultX, ", ").concat(defaultY, ")") + translation;
|
|
155
|
+
}
|
|
156
|
+
return translation;
|
|
157
|
+
};
|
|
158
|
+
export var getTouch = function (e, identifier) {
|
|
159
|
+
return ((e.targetTouches &&
|
|
160
|
+
findInArray(e.targetTouches, function (t) { return identifier === t.identifier; })) ||
|
|
161
|
+
(e.changedTouches &&
|
|
162
|
+
findInArray(e.changedTouches, function (t) { return identifier === t.identifier; })));
|
|
163
|
+
};
|
|
164
|
+
export var getTouchIdentifier = function (e) {
|
|
165
|
+
if (e.targetTouches && e.targetTouches[0]) {
|
|
166
|
+
return e.targetTouches[0].identifier;
|
|
167
|
+
}
|
|
168
|
+
if (e.changedTouches && e.changedTouches[0]) {
|
|
169
|
+
return e.changedTouches[0].identifier;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
export var addUserSelectStyles = function (doc) {
|
|
173
|
+
if (!doc)
|
|
174
|
+
return;
|
|
175
|
+
var styleEl = doc.getElementById("react-draggable-style-el");
|
|
176
|
+
if (!styleEl) {
|
|
177
|
+
styleEl = doc.createElement("style");
|
|
178
|
+
styleEl.id = "react-draggable-style-el";
|
|
179
|
+
styleEl.innerHTML =
|
|
180
|
+
".react-draggable-transparent-selection *::-moz-selection {all: inherit;}\n";
|
|
181
|
+
styleEl.innerHTML +=
|
|
182
|
+
".react-draggable-transparent-selection *::selection {all: inherit;}\n";
|
|
183
|
+
doc.getElementsByTagName("head")[0].appendChild(styleEl);
|
|
184
|
+
}
|
|
185
|
+
if (doc.body)
|
|
186
|
+
addClassName(doc.body, "react-draggable-transparent-selection");
|
|
187
|
+
};
|
|
188
|
+
export var removeUserSelectStyles = function (doc) {
|
|
189
|
+
var _a;
|
|
190
|
+
if (!doc)
|
|
191
|
+
return;
|
|
192
|
+
if (doc.body) {
|
|
193
|
+
removeClassName(doc.body, "react-draggable-transparent-selection");
|
|
194
|
+
}
|
|
195
|
+
if (doc.getSelection()) {
|
|
196
|
+
(_a = doc.getSelection()) === null || _a === void 0 ? void 0 : _a.empty();
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
var selection = (doc.defaultView || window).getSelection();
|
|
200
|
+
if (selection && selection.type !== "Caret") {
|
|
201
|
+
selection.removeAllRanges();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
export var addClassName = function (el, className) {
|
|
206
|
+
if (el.classList) {
|
|
207
|
+
el.classList.add(className);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
if (!el.className.match(new RegExp("(?:^|\\s)".concat(className, "(?!\\S)")))) {
|
|
211
|
+
el.className += " ".concat(className);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
export var removeClassName = function (el, className) {
|
|
216
|
+
if (el.classList) {
|
|
217
|
+
el.classList.remove(className);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
el.className = el.className.replace(new RegExp("(?:^|\\s)".concat(className, "(?!\\S)"), "g"), "");
|
|
221
|
+
}
|
|
222
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function getPrefix(prop?: string): string;
|
|
2
|
+
export declare function browserPrefixToKey(prop: string, prefix: string): string;
|
|
3
|
+
export declare function browserPrefixToStyle(prop: string, prefix: string): string;
|
|
4
|
+
declare const _default: string;
|
|
5
|
+
export default _default;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var prefixes = ["Moz", "Webkit", "O", "ms"];
|
|
2
|
+
export function getPrefix(prop) {
|
|
3
|
+
var _a, _b;
|
|
4
|
+
if (prop === void 0) { prop = "transform"; }
|
|
5
|
+
if (typeof window === "undefined")
|
|
6
|
+
return "";
|
|
7
|
+
var style = (_b = (_a = window.document) === null || _a === void 0 ? void 0 : _a.documentElement) === null || _b === void 0 ? void 0 : _b.style;
|
|
8
|
+
if (!style)
|
|
9
|
+
return "";
|
|
10
|
+
if (prop in style)
|
|
11
|
+
return "";
|
|
12
|
+
for (var i = 0; i < prefixes.length; i++) {
|
|
13
|
+
if (browserPrefixToKey(prop, prefixes[i]) in style)
|
|
14
|
+
return prefixes[i];
|
|
15
|
+
}
|
|
16
|
+
return "";
|
|
17
|
+
}
|
|
18
|
+
export function browserPrefixToKey(prop, prefix) {
|
|
19
|
+
return prefix ? "".concat(prefix).concat(kebabToTitleCase(prop)) : prop;
|
|
20
|
+
}
|
|
21
|
+
export function browserPrefixToStyle(prop, prefix) {
|
|
22
|
+
return prefix ? "-".concat(prefix.toLowerCase(), "-").concat(prop) : prop;
|
|
23
|
+
}
|
|
24
|
+
function kebabToTitleCase(str) {
|
|
25
|
+
var out = "";
|
|
26
|
+
var shouldCapitalize = true;
|
|
27
|
+
for (var i = 0; i < str.length; i++) {
|
|
28
|
+
if (shouldCapitalize) {
|
|
29
|
+
out += str[i].toUpperCase();
|
|
30
|
+
shouldCapitalize = false;
|
|
31
|
+
}
|
|
32
|
+
else if (str[i] === "-") {
|
|
33
|
+
shouldCapitalize = true;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
out += str[i];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
export default getPrefix();
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AxisType, DraggableData, DraggableState } from "./../types";
|
|
2
|
+
import type { Bounds } from "./types";
|
|
3
|
+
export declare function snapToGrid(grid: [number, number], pendingX: number, pendingY: number): [number, number];
|
|
4
|
+
export declare function canDragX(axis: AxisType): boolean;
|
|
5
|
+
export declare function canDragY(axis: AxisType): boolean;
|
|
6
|
+
export declare const cloneBounds: (bounds: Bounds) => Bounds;
|
|
7
|
+
export declare const createDraggableData: (draggableState: DraggableState, scale: number, coreData: DraggableData) => DraggableData;
|