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.
Files changed (131) hide show
  1. package/dist/App.d.ts +2 -0
  2. package/dist/App.js +18 -0
  3. package/dist/examples/ReactGridLayout/ReactGridLayoutShowcase01.d.ts +2 -0
  4. package/dist/examples/ReactGridLayout/ReactGridLayoutShowcase01.js +57 -0
  5. package/dist/examples/ReactGridLayout/index.js +1 -0
  6. package/dist/examples/ResponsiveGridLayout/ResponsiveGridLayoutShowcase01.d.ts +2 -0
  7. package/dist/examples/ResponsiveGridLayout/ResponsiveGridLayoutShowcase01.js +69 -0
  8. package/dist/examples/ResponsiveGridLayout/index.js +1 -0
  9. package/dist/examples/index.js +2 -0
  10. package/dist/examples/utils.d.ts +8 -0
  11. package/dist/examples/utils.js +14 -0
  12. package/dist/index.d.ts +1 -0
  13. package/{src/index.tsx → dist/index.js} +3 -12
  14. package/dist/lib/Draggable/Draggable.d.ts +17 -0
  15. package/dist/lib/Draggable/Draggable.js +192 -0
  16. package/dist/lib/Draggable/DraggableCore.d.ts +5 -0
  17. package/dist/lib/Draggable/DraggableCore.js +266 -0
  18. package/dist/lib/Draggable/constants.d.ts +12 -0
  19. package/dist/lib/Draggable/constants.js +12 -0
  20. package/dist/lib/Draggable/index.js +2 -0
  21. package/dist/lib/Draggable/types.d.ts +55 -0
  22. package/dist/lib/Draggable/types.js +1 -0
  23. package/dist/lib/Draggable/utils/domHelpers.d.ts +22 -0
  24. package/dist/lib/Draggable/utils/domHelpers.js +222 -0
  25. package/dist/lib/Draggable/utils/getPrefix.d.ts +5 -0
  26. package/dist/lib/Draggable/utils/getPrefix.js +41 -0
  27. package/dist/lib/Draggable/utils/positionHelpers.d.ts +7 -0
  28. package/dist/lib/Draggable/utils/positionHelpers.js +32 -0
  29. package/dist/lib/Draggable/utils/types.d.ts +30 -0
  30. package/dist/lib/Draggable/utils/types.js +1 -0
  31. package/dist/lib/Draggable/utils/validationHelpers.d.ts +4 -0
  32. package/dist/lib/Draggable/utils/validationHelpers.js +16 -0
  33. package/dist/lib/GridItem/GridItem.d.ts +5 -0
  34. package/dist/lib/GridItem/GridItem.js +324 -0
  35. package/dist/lib/GridItem/index.js +1 -0
  36. package/dist/lib/GridItem/types.d.ts +105 -0
  37. package/dist/lib/GridItem/types.js +1 -0
  38. package/dist/lib/GridItem/utils/calculateUtils.d.ts +30 -0
  39. package/dist/lib/GridItem/utils/calculateUtils.js +108 -0
  40. package/dist/lib/GridLayoutEditor/ReactGridLayout.d.ts +5 -0
  41. package/dist/lib/GridLayoutEditor/ReactGridLayout.js +423 -0
  42. package/dist/lib/GridLayoutEditor/ResponsiveGridLayout.d.ts +4 -0
  43. package/dist/lib/GridLayoutEditor/ResponsiveGridLayout.js +117 -0
  44. package/dist/lib/GridLayoutEditor/index.d.ts +3 -0
  45. package/dist/lib/GridLayoutEditor/index.js +2 -0
  46. package/dist/lib/GridLayoutEditor/types.d.ts +129 -0
  47. package/dist/lib/GridLayoutEditor/types.js +1 -0
  48. package/dist/lib/GridLayoutEditor/utils/renderHelpers.d.ts +164 -0
  49. package/dist/lib/GridLayoutEditor/utils/renderHelpers.js +591 -0
  50. package/dist/lib/GridLayoutEditor/utils/responsiveUtils.d.ts +26 -0
  51. package/dist/lib/GridLayoutEditor/utils/responsiveUtils.js +77 -0
  52. package/dist/lib/PreviewGLE/ReactGridLayoutPreview.d.ts +7 -0
  53. package/dist/lib/PreviewGLE/ReactGridLayoutPreview.js +35 -0
  54. package/dist/lib/PreviewGLE/ResponsiveGridLayoutPreview.d.ts +9 -0
  55. package/dist/lib/PreviewGLE/ResponsiveGridLayoutPreview.js +38 -0
  56. package/dist/lib/PreviewGLE/index.js +2 -0
  57. package/dist/lib/Resizable/Resizable.d.ts +7 -0
  58. package/dist/lib/Resizable/Resizable.js +216 -0
  59. package/dist/lib/Resizable/ResizableBox.d.ts +7 -0
  60. package/dist/lib/Resizable/ResizableBox.js +57 -0
  61. package/dist/lib/Resizable/index.js +1 -0
  62. package/dist/lib/Resizable/types.d.ts +63 -0
  63. package/dist/lib/Resizable/types.js +1 -0
  64. package/dist/lib/Resizable/utils/cloneElement.d.ts +2 -0
  65. package/dist/lib/Resizable/utils/cloneElement.js +21 -0
  66. package/dist/lib/components/WidthProvider.d.ts +9 -0
  67. package/dist/lib/components/WidthProvider.js +55 -0
  68. package/dist/lib/components/index.js +1 -0
  69. package/dist/lib/components/types.d.ts +13 -0
  70. package/dist/lib/components/types.js +1 -0
  71. package/dist/lib/index.js +5 -0
  72. package/dist/reportWebVitals.d.ts +3 -0
  73. package/dist/reportWebVitals.js +13 -0
  74. package/dist/setupTests.d.ts +1 -0
  75. package/dist/utils/types.d.ts +4 -0
  76. package/dist/utils/types.js +1 -0
  77. package/package.json +5 -5
  78. package/bin/cli.js +0 -8
  79. package/bitbucket-pipelines.yml +0 -35
  80. package/public/favicon.ico +0 -0
  81. package/public/index.html +0 -43
  82. package/public/logo192.png +0 -0
  83. package/public/logo512.png +0 -0
  84. package/public/manifest.json +0 -25
  85. package/public/robots.txt +0 -3
  86. package/src/App.tsx +0 -28
  87. package/src/examples/ReactGridLayout/ReactGridLayoutShowcase01.tsx +0 -80
  88. package/src/examples/ResponsiveGridLayout/ResponsiveGridLayoutShowcase01.tsx +0 -114
  89. package/src/examples/utils.ts +0 -15
  90. package/src/lib/Draggable/Draggable.tsx +0 -303
  91. package/src/lib/Draggable/DraggableCore.tsx +0 -352
  92. package/src/lib/Draggable/constants.ts +0 -12
  93. package/src/lib/Draggable/types.ts +0 -74
  94. package/src/lib/Draggable/utils/domHelpers.ts +0 -284
  95. package/src/lib/Draggable/utils/getPrefix.ts +0 -42
  96. package/src/lib/Draggable/utils/positionHelpers.ts +0 -49
  97. package/src/lib/Draggable/utils/types.ts +0 -41
  98. package/src/lib/Draggable/utils/validationHelpers.ts +0 -23
  99. package/src/lib/GridItem/GridItem.tsx +0 -493
  100. package/src/lib/GridItem/types.ts +0 -121
  101. package/src/lib/GridItem/utils/calculateUtils.ts +0 -173
  102. package/src/lib/GridLayoutEditor/ReactGridLayout.tsx +0 -662
  103. package/src/lib/GridLayoutEditor/ResponsiveGridLayout.tsx +0 -204
  104. package/src/lib/GridLayoutEditor/index.ts +0 -11
  105. package/src/lib/GridLayoutEditor/styles/styles.css +0 -133
  106. package/src/lib/GridLayoutEditor/types.ts +0 -199
  107. package/src/lib/GridLayoutEditor/utils/renderHelpers.ts +0 -737
  108. package/src/lib/GridLayoutEditor/utils/responsiveUtils.ts +0 -111
  109. package/src/lib/PreviewGLE/ReactGridLayoutPreview.tsx +0 -46
  110. package/src/lib/PreviewGLE/ResponsiveGridLayoutPreview.tsx +0 -54
  111. package/src/lib/Resizable/Resizable.tsx +0 -323
  112. package/src/lib/Resizable/ResizableBox.tsx +0 -109
  113. package/src/lib/Resizable/styles/styles.css +0 -76
  114. package/src/lib/Resizable/types.ts +0 -96
  115. package/src/lib/Resizable/utils/cloneElement.ts +0 -15
  116. package/src/lib/components/WidthProvider.tsx +0 -71
  117. package/src/lib/components/types.ts +0 -19
  118. package/src/react-app-env.d.ts +0 -1
  119. package/src/reportWebVitals.ts +0 -15
  120. package/src/utils/types.ts +0 -3
  121. package/tsconfig.json +0 -22
  122. /package/{src/examples/ReactGridLayout/index.ts → dist/examples/ReactGridLayout/index.d.ts} +0 -0
  123. /package/{src/examples/ResponsiveGridLayout/index.ts → dist/examples/ResponsiveGridLayout/index.d.ts} +0 -0
  124. /package/{src/examples/index.ts → dist/examples/index.d.ts} +0 -0
  125. /package/{src/lib/Draggable/index.ts → dist/lib/Draggable/index.d.ts} +0 -0
  126. /package/{src/lib/GridItem/index.ts → dist/lib/GridItem/index.d.ts} +0 -0
  127. /package/{src/lib/PreviewGLE/index.ts → dist/lib/PreviewGLE/index.d.ts} +0 -0
  128. /package/{src/lib/Resizable/index.ts → dist/lib/Resizable/index.d.ts} +0 -0
  129. /package/{src/lib/components/index.ts → dist/lib/components/index.d.ts} +0 -0
  130. /package/{src/lib/index.ts → dist/lib/index.d.ts} +0 -0
  131. /package/{src/setupTests.ts → dist/setupTests.js} +0 -0
package/dist/App.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare function App(): import("react/jsx-runtime").JSX.Element;
2
+ export default App;
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,2 @@
1
+ declare function ReactGridLayoutShowcase01(): import("react/jsx-runtime").JSX.Element;
2
+ export default ReactGridLayoutShowcase01;
@@ -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,2 @@
1
+ declare function ResponsiveGridLayoutShowcase01(): import("react/jsx-runtime").JSX.Element;
2
+ export default ResponsiveGridLayoutShowcase01;
@@ -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,2 @@
1
+ export { default as ResponsiveGridLayoutShowcase01 } from "./ResponsiveGridLayout/ResponsiveGridLayoutShowcase01";
2
+ export { default as ReactGridLayoutShowcase01 } from "./ReactGridLayout/ReactGridLayoutShowcase01";
@@ -0,0 +1,8 @@
1
+ export declare function generateLayout(): {
2
+ x: number;
3
+ y: number;
4
+ w: number;
5
+ h: number;
6
+ i: string;
7
+ static: boolean;
8
+ }[];
@@ -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
+ }
@@ -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
- const root = ReactDOM.createRoot(
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;