publ-echo 0.0.4 → 0.0.6
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.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.js +1 -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/{src/index.tsx → dist/index.js} +3 -12
- 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.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.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 +5 -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.js +2 -0
- package/dist/lib/Resizable/Resizable.d.ts +7 -0
- package/dist/lib/Resizable/Resizable.js +216 -0
- package/dist/lib/Resizable/ResizableBox.d.ts +7 -0
- package/dist/lib/Resizable/ResizableBox.js +57 -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.js +1 -0
- package/dist/lib/components/types.d.ts +13 -0
- package/dist/lib/components/types.js +1 -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/utils/types.d.ts +4 -0
- package/dist/utils/types.js +1 -0
- package/package.json +5 -5
- package/bin/cli.js +0 -8
- package/bitbucket-pipelines.yml +0 -35
- package/public/favicon.ico +0 -0
- package/public/index.html +0 -43
- package/public/logo192.png +0 -0
- package/public/logo512.png +0 -0
- package/public/manifest.json +0 -25
- package/public/robots.txt +0 -3
- package/src/App.tsx +0 -28
- package/src/examples/ReactGridLayout/ReactGridLayoutShowcase01.tsx +0 -80
- package/src/examples/ResponsiveGridLayout/ResponsiveGridLayoutShowcase01.tsx +0 -114
- package/src/examples/utils.ts +0 -15
- package/src/lib/Draggable/Draggable.tsx +0 -303
- package/src/lib/Draggable/DraggableCore.tsx +0 -352
- package/src/lib/Draggable/constants.ts +0 -12
- package/src/lib/Draggable/types.ts +0 -74
- package/src/lib/Draggable/utils/domHelpers.ts +0 -284
- package/src/lib/Draggable/utils/getPrefix.ts +0 -42
- package/src/lib/Draggable/utils/positionHelpers.ts +0 -49
- package/src/lib/Draggable/utils/types.ts +0 -41
- package/src/lib/Draggable/utils/validationHelpers.ts +0 -23
- package/src/lib/GridItem/GridItem.tsx +0 -493
- package/src/lib/GridItem/types.ts +0 -121
- package/src/lib/GridItem/utils/calculateUtils.ts +0 -173
- package/src/lib/GridLayoutEditor/ReactGridLayout.tsx +0 -662
- package/src/lib/GridLayoutEditor/ResponsiveGridLayout.tsx +0 -204
- package/src/lib/GridLayoutEditor/index.ts +0 -11
- package/src/lib/GridLayoutEditor/styles/styles.css +0 -133
- package/src/lib/GridLayoutEditor/types.ts +0 -199
- package/src/lib/GridLayoutEditor/utils/renderHelpers.ts +0 -737
- package/src/lib/GridLayoutEditor/utils/responsiveUtils.ts +0 -111
- package/src/lib/PreviewGLE/ReactGridLayoutPreview.tsx +0 -46
- package/src/lib/PreviewGLE/ResponsiveGridLayoutPreview.tsx +0 -54
- package/src/lib/Resizable/Resizable.tsx +0 -323
- package/src/lib/Resizable/ResizableBox.tsx +0 -109
- package/src/lib/Resizable/styles/styles.css +0 -76
- package/src/lib/Resizable/types.ts +0 -96
- package/src/lib/Resizable/utils/cloneElement.ts +0 -15
- package/src/lib/components/WidthProvider.tsx +0 -71
- package/src/lib/components/types.ts +0 -19
- package/src/react-app-env.d.ts +0 -1
- package/src/reportWebVitals.ts +0 -15
- package/src/utils/types.ts +0 -3
- package/tsconfig.json +0 -22
- /package/{src/examples/ReactGridLayout/index.ts → dist/examples/ReactGridLayout/index.d.ts} +0 -0
- /package/{src/examples/ResponsiveGridLayout/index.ts → dist/examples/ResponsiveGridLayout/index.d.ts} +0 -0
- /package/{src/examples/index.ts → dist/examples/index.d.ts} +0 -0
- /package/{src/lib/Draggable/index.ts → dist/lib/Draggable/index.d.ts} +0 -0
- /package/{src/lib/GridItem/index.ts → dist/lib/GridItem/index.d.ts} +0 -0
- /package/{src/lib/PreviewGLE/index.ts → dist/lib/PreviewGLE/index.d.ts} +0 -0
- /package/{src/lib/Resizable/index.ts → dist/lib/Resizable/index.d.ts} +0 -0
- /package/{src/lib/components/index.ts → dist/lib/components/index.d.ts} +0 -0
- /package/{src/lib/index.ts → dist/lib/index.d.ts} +0 -0
- /package/{src/setupTests.ts → dist/setupTests.js} +0 -0
package/dist/App.d.ts
ADDED
package/dist/App.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
import styled from "styled-components";
|
|
7
|
+
import { ReactGridLayoutShowcase01, } from "./examples";
|
|
8
|
+
function App() {
|
|
9
|
+
// return (
|
|
10
|
+
// <S_GridLayoutWrapper>
|
|
11
|
+
// <ResponsiveGridLayoutShowcase01 />
|
|
12
|
+
// </S_GridLayoutWrapper>
|
|
13
|
+
// );
|
|
14
|
+
return (_jsx(S_GridLayoutWrapper, { children: _jsx(ReactGridLayoutShowcase01, {}) }));
|
|
15
|
+
}
|
|
16
|
+
var S_GridLayoutWrapper = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n background-color: yellow;\n\n & > div {\n background-color: lightgreen;\n }\n"], ["\n background-color: yellow;\n\n & > div {\n background-color: lightgreen;\n }\n"])));
|
|
17
|
+
export default App;
|
|
18
|
+
var templateObject_1;
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
import { useState } from "react";
|
|
18
|
+
import { generateLayout } from "../utils";
|
|
19
|
+
import styled from "styled-components";
|
|
20
|
+
import { ReactGridLayoutPreview } from "../../lib/PreviewGLE";
|
|
21
|
+
import ReactGridLayout from "../../lib/GridLayoutEditor/ReactGridLayout";
|
|
22
|
+
var lay = generateLayout().slice(0, 2);
|
|
23
|
+
// NOTE - windowSize viewport에 맞게 Resize시키기 위한 Provider
|
|
24
|
+
// const Responsive = WidthProvider(ReactGridLayout);
|
|
25
|
+
function ReactGridLayoutShowcase01() {
|
|
26
|
+
var _a = useState(lay), layout = _a[0], setLayout = _a[1];
|
|
27
|
+
var _b = useState(false), isOpenPreview = _b[0], setIsOpenPreview = _b[1];
|
|
28
|
+
var defaultProps = {
|
|
29
|
+
width: 1280,
|
|
30
|
+
// className: "layout",
|
|
31
|
+
items: 50,
|
|
32
|
+
cols: 12,
|
|
33
|
+
rowHeight: 50,
|
|
34
|
+
allowOverlap: true,
|
|
35
|
+
margin: [10, 10],
|
|
36
|
+
};
|
|
37
|
+
function onLayoutChange(newLayout) {
|
|
38
|
+
setLayout(newLayout);
|
|
39
|
+
}
|
|
40
|
+
var onResizeStartTemp = function (e,
|
|
41
|
+
// { node, size }: { node: HTMLElement; size: Position }
|
|
42
|
+
_a) {
|
|
43
|
+
var node = _a.node, size = _a.size;
|
|
44
|
+
// Get new XY
|
|
45
|
+
return;
|
|
46
|
+
};
|
|
47
|
+
var onResizeTemp = function (e,
|
|
48
|
+
// { node, size }: { node: HTMLElement; size: Position }
|
|
49
|
+
_a) {
|
|
50
|
+
var node = _a.node, size = _a.size;
|
|
51
|
+
return;
|
|
52
|
+
};
|
|
53
|
+
return (_jsxs(_Fragment, { children: [_jsx("button", { onClick: function () { return setIsOpenPreview(true); }, children: "previewButton" }), !isOpenPreview && (_jsx(ReactGridLayout, __assign({}, defaultProps, { layout: layout, onLayoutChange: onLayoutChange, resizeHandles: ["nw", "e", "n", "ne", "s", "se", "sw", "w"], isHiddenVisibility: true, children: layout.map(function (each) { return (_jsx(S_SampleBox, { children: each.i }, each.i)); }) }))), isOpenPreview && (_jsx(ReactGridLayoutPreview, { layout: layout, props: defaultProps }))] }));
|
|
54
|
+
}
|
|
55
|
+
var S_SampleBox = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n width: 100px;\n height: 100px;\n background-color: lightgray;\n border: dodgerblue 1px solid;\n"], ["\n width: 100px;\n height: 100px;\n background-color: lightgray;\n border: dodgerblue 1px solid;\n"])));
|
|
56
|
+
export default ReactGridLayoutShowcase01;
|
|
57
|
+
var templateObject_1;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as ReactGridLayoutShowcase01 } from "./ReactGridLayoutShowcase01";
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
17
|
+
import { useState } from "react";
|
|
18
|
+
import { generateLayout } from "../utils";
|
|
19
|
+
import _ from "lodash";
|
|
20
|
+
import styled from "styled-components";
|
|
21
|
+
import { WidthProvider } from "../../lib/components";
|
|
22
|
+
import { ResponsiveGridLayoutPreview } from "../../lib/PreviewGLE";
|
|
23
|
+
import ResponsiveGridLayout from "../../lib/GridLayoutEditor/ResponsiveGridLayout";
|
|
24
|
+
// NOTE - windowSize viewport에 맞게 Resize시키기 위한 Provider
|
|
25
|
+
var Responsive = WidthProvider(ResponsiveGridLayout);
|
|
26
|
+
function ResponsiveGridLayoutShowcase01() {
|
|
27
|
+
var _a = useState("lg"), currentBreakpoint = _a[0], setCurrentBreakpoint = _a[1];
|
|
28
|
+
var _b = useState("vertical"), currentCompactType = _b[0], setCurrentCompactType = _b[1];
|
|
29
|
+
var _c = useState(false), mounted = _c[0], setMounted = _c[1];
|
|
30
|
+
var _d = useState({
|
|
31
|
+
lg: generateLayout().slice(0, 1),
|
|
32
|
+
}), layouts = _d[0], setLayouts = _d[1];
|
|
33
|
+
var _e = useState(false), isOpenPreview = _e[0], setIsOpenPreview = _e[1];
|
|
34
|
+
var defaultProps = {
|
|
35
|
+
// className: "layout",
|
|
36
|
+
cols: { lg: 12, md: 10, sm: 6, xs: 4, xxs: 2 },
|
|
37
|
+
rowHeight: 50,
|
|
38
|
+
allowOverlap: true,
|
|
39
|
+
margin: [10, 10],
|
|
40
|
+
};
|
|
41
|
+
var onLayoutChange = function (_a) {
|
|
42
|
+
var layout = _a.layout, layouts = _a.layouts;
|
|
43
|
+
setLayouts(__assign({}, layouts));
|
|
44
|
+
};
|
|
45
|
+
var onBreakpointChange = function (breakpoint) {
|
|
46
|
+
setCurrentBreakpoint(breakpoint);
|
|
47
|
+
};
|
|
48
|
+
var onCompactTypeChange = function () {
|
|
49
|
+
var compactType = currentCompactType === "horizontal"
|
|
50
|
+
? "vertical"
|
|
51
|
+
: currentCompactType === "vertical"
|
|
52
|
+
? null
|
|
53
|
+
: "horizontal";
|
|
54
|
+
setCurrentCompactType(compactType);
|
|
55
|
+
};
|
|
56
|
+
var onWidthChange = function (containerWidth, margin, cols, containerPadding) {
|
|
57
|
+
return;
|
|
58
|
+
};
|
|
59
|
+
function generateDOM() {
|
|
60
|
+
return _.map(layouts.lg, function (l, i) {
|
|
61
|
+
return (_jsx(S_SampleBox, { className: l.static ? "static" : "", children: l.static ? (_jsxs("span", { className: "text", title: "This item is static and cannot be removed or resized.", children: ["Static - ", i] })) : (_jsx("span", { className: "text", children: i })) }, i));
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
// NOTE - window resize 적용된 Responsive
|
|
65
|
+
return (_jsxs(_Fragment, { children: [_jsx("button", { onClick: function () { return setIsOpenPreview(true); }, children: "previewButton" }), !isOpenPreview && (_jsx(Responsive, __assign({}, defaultProps, { layouts: layouts, onLayoutChange: onLayoutChange, resizeHandles: ["nw", "e", "n", "ne", "s", "se", "sw", "w"], children: generateDOM() }))), isOpenPreview && (_jsx(ResponsiveGridLayoutPreview, { layouts: layouts, props: defaultProps }))] }));
|
|
66
|
+
}
|
|
67
|
+
var S_SampleBox = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n width: 100px;\n height: 100px;\n background-color: lightgray;\n border: dodgerblue 1px solid;\n"], ["\n width: 100px;\n height: 100px;\n background-color: lightgray;\n border: dodgerblue 1px solid;\n"])));
|
|
68
|
+
export default ResponsiveGridLayoutShowcase01;
|
|
69
|
+
var templateObject_1;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as ResponsiveGridLayoutShowcase01 } from "./ResponsiveGridLayoutShowcase01";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import _ from "lodash";
|
|
2
|
+
export function generateLayout() {
|
|
3
|
+
return _.map(_.range(0, 25), function (item, i) {
|
|
4
|
+
var y = Math.ceil(Math.random() * 4) + 1;
|
|
5
|
+
return {
|
|
6
|
+
x: Math.round(Math.random() * 5) * 2,
|
|
7
|
+
y: Math.floor(i / 6) * y,
|
|
8
|
+
w: 2,
|
|
9
|
+
h: y,
|
|
10
|
+
i: i.toString(),
|
|
11
|
+
static: Math.random() < 0.05,
|
|
12
|
+
};
|
|
13
|
+
});
|
|
14
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./lib";
|
|
@@ -1,21 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
2
|
import React from "react";
|
|
2
3
|
import ReactDOM from "react-dom/client";
|
|
3
4
|
import reportWebVitals from "./reportWebVitals";
|
|
4
5
|
import App from "./App";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
document.getElementById("root") as HTMLElement
|
|
8
|
-
);
|
|
9
|
-
|
|
10
|
-
root.render(
|
|
11
|
-
<React.StrictMode>
|
|
12
|
-
<App />
|
|
13
|
-
</React.StrictMode>
|
|
14
|
-
);
|
|
15
|
-
|
|
6
|
+
var root = ReactDOM.createRoot(document.getElementById("root"));
|
|
7
|
+
root.render(_jsx(React.StrictMode, { children: _jsx(App, {}) }));
|
|
16
8
|
// If you want to start measuring performance in your app, pass a function
|
|
17
9
|
// to log results (for example: reportWebVitals(console.log))
|
|
18
10
|
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
|
19
11
|
reportWebVitals();
|
|
20
|
-
|
|
21
12
|
export * from "./lib";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Bounds, ControlPosition } from "./utils/types";
|
|
3
|
+
import { AxisType, DraggableCoreDefaultProps, DraggablePositionType, PropsWithChildren } from "./types";
|
|
4
|
+
export type DraggableDefaultProps = {
|
|
5
|
+
axis?: AxisType;
|
|
6
|
+
bounds?: Bounds | string | false;
|
|
7
|
+
defaultClassName?: string;
|
|
8
|
+
defaultClassNameDragging?: string;
|
|
9
|
+
defaultClassNameDragged?: string;
|
|
10
|
+
defaultPosition?: ControlPosition;
|
|
11
|
+
scale?: number;
|
|
12
|
+
nodeRef?: React.RefObject<HTMLElement>;
|
|
13
|
+
className?: string;
|
|
14
|
+
style?: Object;
|
|
15
|
+
} & DraggableCoreDefaultProps & DraggablePositionType;
|
|
16
|
+
declare const Draggable: ({ children, axis, bounds, defaultClassName, defaultClassNameDragging, defaultClassNameDragged, defaultPosition, scale, ...props }: PropsWithChildren<DraggableDefaultProps>) => import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export default Draggable;
|
|
@@ -0,0 +1,192 @@
|
|
|
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 { jsx as _jsx } from "react/jsx-runtime";
|
|
24
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
25
|
+
import DraggableCore from "./DraggableCore";
|
|
26
|
+
import { canDragX, canDragY, cloneBounds, createDraggableData, } from "./utils/positionHelpers";
|
|
27
|
+
import { int, isNum } from "./utils/validationHelpers";
|
|
28
|
+
import { createCSSTransform, createSVGTransform, innerHeight, innerWidth, outerHeight, outerWidth, } from "./utils/domHelpers";
|
|
29
|
+
import classNames from "classnames";
|
|
30
|
+
var Draggable = function (_a) {
|
|
31
|
+
var _b, _c;
|
|
32
|
+
var children = _a.children, _d = _a.axis, axis = _d === void 0 ? "both" : _d, _e = _a.bounds, bounds = _e === void 0 ? false : _e, _f = _a.defaultClassName, defaultClassName = _f === void 0 ? "react-draggable" : _f, _g = _a.defaultClassNameDragging, defaultClassNameDragging = _g === void 0 ? "react-draggable-dragging" : _g, _h = _a.defaultClassNameDragged, defaultClassNameDragged = _h === void 0 ? "react-draggable-dragged" : _h, _j = _a.defaultPosition, defaultPosition = _j === void 0 ? { x: 0, y: 0 } : _j, _k = _a.scale, scale = _k === void 0 ? 1 : _k, props = __rest(_a, ["children", "axis", "bounds", "defaultClassName", "defaultClassNameDragging", "defaultClassNameDragged", "defaultPosition", "scale"]);
|
|
33
|
+
var position = props.position, positionOffset = props.positionOffset, draggableCoreProps = __rest(props, ["position", "positionOffset"]);
|
|
34
|
+
var draggableRef = useRef(null);
|
|
35
|
+
var _l = useState({
|
|
36
|
+
dragged: false,
|
|
37
|
+
dragging: false,
|
|
38
|
+
x: position ? position === null || position === void 0 ? void 0 : position.x : defaultPosition.x,
|
|
39
|
+
y: position ? position === null || position === void 0 ? void 0 : position.y : defaultPosition.y,
|
|
40
|
+
slackX: 0,
|
|
41
|
+
slackY: 0,
|
|
42
|
+
isElementSVG: false,
|
|
43
|
+
prevPropsPosition: position,
|
|
44
|
+
}), draggableState = _l[0], setDraggableState = _l[1];
|
|
45
|
+
/**
|
|
46
|
+
* @when Draggable이 화면에 그려질 때
|
|
47
|
+
* @expected 해당 DOMNode가 SVGElement인지를 확인
|
|
48
|
+
* @clear 페이지를 나갔을 때 dragging을 false로 변경하여 drag되지 않도록 설정
|
|
49
|
+
*/
|
|
50
|
+
useEffect(function () {
|
|
51
|
+
if (typeof window.SVGElement !== "undefined" &&
|
|
52
|
+
findDOMNode() instanceof window.SVGElement) {
|
|
53
|
+
setDraggableState(function (prevState) { return (__assign(__assign({}, prevState), { isElementSVG: true })); });
|
|
54
|
+
}
|
|
55
|
+
return function () {
|
|
56
|
+
setDraggableState(function (prevState) { return (__assign(__assign({}, prevState), { dragging: false })); });
|
|
57
|
+
};
|
|
58
|
+
}, []);
|
|
59
|
+
var style = {};
|
|
60
|
+
var svgTransform = null;
|
|
61
|
+
var findDOMNode = function () {
|
|
62
|
+
var _a, _b;
|
|
63
|
+
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 : draggableRef === null || draggableRef === void 0 ? void 0 : draggableRef.current;
|
|
64
|
+
};
|
|
65
|
+
var getBoundPosition = function (x, y, node) {
|
|
66
|
+
var _a;
|
|
67
|
+
if (!bounds)
|
|
68
|
+
return [x, y];
|
|
69
|
+
var newBounds = bounds;
|
|
70
|
+
newBounds = typeof bounds === "string" ? bounds : cloneBounds(bounds);
|
|
71
|
+
if (typeof newBounds === "string") {
|
|
72
|
+
var ownerWindow = (_a = node === null || node === void 0 ? void 0 : node.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView;
|
|
73
|
+
var boundNode = void 0;
|
|
74
|
+
if (newBounds === "parent") {
|
|
75
|
+
boundNode = node === null || node === void 0 ? void 0 : node.parentNode;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
boundNode = node === null || node === void 0 ? void 0 : node.ownerDocument.querySelector(newBounds);
|
|
79
|
+
}
|
|
80
|
+
if (!(ownerWindow && boundNode instanceof ownerWindow.HTMLElement)) {
|
|
81
|
+
throw new Error('Bounds selector "' + newBounds + '" could not find an element');
|
|
82
|
+
}
|
|
83
|
+
var boundNodeElement = boundNode;
|
|
84
|
+
var nodeStyle = ownerWindow.getComputedStyle(node);
|
|
85
|
+
var boundNodeStyle = ownerWindow.getComputedStyle(boundNodeElement);
|
|
86
|
+
newBounds = {
|
|
87
|
+
left: -node.offsetLeft +
|
|
88
|
+
int(boundNodeStyle.paddingLeft) +
|
|
89
|
+
int(nodeStyle.marginLeft),
|
|
90
|
+
top: -node.offsetTop +
|
|
91
|
+
int(boundNodeStyle.paddingTop) +
|
|
92
|
+
int(nodeStyle.marginTop),
|
|
93
|
+
right: innerWidth(boundNodeElement) -
|
|
94
|
+
outerWidth(node) -
|
|
95
|
+
node.offsetLeft +
|
|
96
|
+
int(boundNodeStyle.paddingRight) -
|
|
97
|
+
int(nodeStyle.marginRight),
|
|
98
|
+
bottom: innerHeight(boundNodeElement) -
|
|
99
|
+
outerHeight(node) -
|
|
100
|
+
node.offsetTop +
|
|
101
|
+
int(boundNodeStyle.paddingBottom) -
|
|
102
|
+
int(nodeStyle.marginBottom),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (isNum(newBounds.right))
|
|
106
|
+
x = Math.min(x, newBounds.right);
|
|
107
|
+
if (isNum(newBounds.bottom))
|
|
108
|
+
y = Math.min(y, newBounds.bottom);
|
|
109
|
+
if (isNum(newBounds.left))
|
|
110
|
+
x = Math.max(x, newBounds.left);
|
|
111
|
+
if (isNum(newBounds.top))
|
|
112
|
+
y = Math.max(y, newBounds.top);
|
|
113
|
+
return [x, y];
|
|
114
|
+
};
|
|
115
|
+
var handleDragStart = function (e, coreData) {
|
|
116
|
+
if (props.onStart) {
|
|
117
|
+
var shouldStart = props.onStart(e, createDraggableData(draggableState, scale, coreData));
|
|
118
|
+
if (shouldStart === false)
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
setDraggableState(function (prev) { return (__assign(__assign({}, prev), { dragged: true, dragging: true })); });
|
|
122
|
+
};
|
|
123
|
+
var handleDrag = function (e, coreData, node) {
|
|
124
|
+
if (!draggableState.dragging)
|
|
125
|
+
return false;
|
|
126
|
+
var uiData = createDraggableData(draggableState, scale, coreData);
|
|
127
|
+
var newState = __assign(__assign({}, draggableState), { x: uiData.x, y: uiData.y });
|
|
128
|
+
if (bounds) {
|
|
129
|
+
var x = newState.x, y = newState.y;
|
|
130
|
+
newState.x += draggableState.slackX;
|
|
131
|
+
newState.y += draggableState.slackY;
|
|
132
|
+
var _a = getBoundPosition(newState.x, newState.y, node), newBoundPositionX = _a[0], newBoundPositionY = _a[1];
|
|
133
|
+
newState.x = newBoundPositionX;
|
|
134
|
+
newState.y = newBoundPositionY;
|
|
135
|
+
newState.slackX = draggableState.slackX + (x - newState.x);
|
|
136
|
+
newState.slackY = draggableState.slackY + (y - newState.y);
|
|
137
|
+
uiData.x = newState.x;
|
|
138
|
+
uiData.y = newState.y;
|
|
139
|
+
uiData.deltaX = newState.x - draggableState.x;
|
|
140
|
+
uiData.deltaY = newState.y - draggableState.y;
|
|
141
|
+
}
|
|
142
|
+
if (props.onDrag) {
|
|
143
|
+
var shouldUpdate = props.onDrag(e, uiData);
|
|
144
|
+
if (shouldUpdate === false)
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
setDraggableState(function (prevState) { return (__assign(__assign({}, prevState), { x: newState.x, y: newState.y })); });
|
|
148
|
+
};
|
|
149
|
+
var handleDragStop = function (e, coreData) {
|
|
150
|
+
if (!draggableState.dragging)
|
|
151
|
+
return false;
|
|
152
|
+
if (props.onStop) {
|
|
153
|
+
var shouldContinue = props.onStop(e, createDraggableData(draggableState, scale, coreData));
|
|
154
|
+
if (shouldContinue === false)
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
if (position && Boolean(position)) {
|
|
158
|
+
var x_1 = position.x, y_1 = position.y;
|
|
159
|
+
setDraggableState(function (prevState) { return (__assign(__assign({}, prevState), { x: x_1, y: y_1, dragging: false, slackX: 0, slackY: 0 })); });
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
setDraggableState(function (prevState) { return (__assign(__assign({}, prevState), { dragging: false, slackX: 0, slackY: 0 })); });
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
var controlled = Boolean(position);
|
|
166
|
+
var draggable = !controlled || draggableState.dragging;
|
|
167
|
+
var validPosition = position || defaultPosition;
|
|
168
|
+
var transformOptions = {
|
|
169
|
+
x: canDragX(axis) && draggable ? draggableState.x : validPosition.x,
|
|
170
|
+
y: canDragY(axis) && draggable ? draggableState.y : validPosition.y,
|
|
171
|
+
};
|
|
172
|
+
if (draggableState.isElementSVG) {
|
|
173
|
+
svgTransform = createSVGTransform(transformOptions, positionOffset);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
style = createCSSTransform(transformOptions, positionOffset);
|
|
177
|
+
}
|
|
178
|
+
var className = classNames(props.className || "", defaultClassName, (_b = {}, _b[defaultClassNameDragging] = draggableState.dragging, _b), (_c = {}, _c[defaultClassNameDragged] = draggableState.dragged, _c));
|
|
179
|
+
// NOTE - class형 컴포넌트에서 사용되는 getDerivedStateFromProps에 대응하기 위한 조건문입니다.
|
|
180
|
+
if (position &&
|
|
181
|
+
(!draggableState.prevPropsPosition ||
|
|
182
|
+
position.x !== draggableState.prevPropsPosition.x ||
|
|
183
|
+
position.y !== draggableState.prevPropsPosition.y)) {
|
|
184
|
+
setDraggableState(function (prevState) { return (__assign(__assign({}, prevState), { x: position.x, y: position.y, prevPropsPosition: __assign({}, position) })); });
|
|
185
|
+
}
|
|
186
|
+
return (_jsx(DraggableCore, __assign({}, draggableCoreProps, { onStart: handleDragStart, onDrag: handleDrag, onStop: handleDragStop, children: React.cloneElement(children, {
|
|
187
|
+
className: className,
|
|
188
|
+
style: __assign(__assign({}, props.style), style),
|
|
189
|
+
transform: svgTransform,
|
|
190
|
+
}) })));
|
|
191
|
+
};
|
|
192
|
+
export default Draggable;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { DraggableCoreDefaultProps, PropsWithChildren } from "./types";
|
|
3
|
+
type Props = DraggableCoreDefaultProps;
|
|
4
|
+
declare const DraggableCore: ({ allowAnyClick, disabled, enableUserSelectHack, onStart, onDrag, onStop, onMouseDown, scale, children, ...props }: PropsWithChildren<Props>) => React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
5
|
+
export default DraggableCore;
|