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
@@ -1,35 +0,0 @@
1
- # This is an example Starter pipeline configuration
2
- # Use a skeleton to build, test and deploy using manual and parallel steps
3
- # -----
4
- # You can specify a custom docker image from Docker Hub as your build environment.
5
-
6
- image: atlassian/default-image:3
7
-
8
- pipelines:
9
- default:
10
- - parallel:
11
- - step:
12
- name: 'Build and Test'
13
- script:
14
- - echo "Your build and test goes here..."
15
- - step:
16
- name: 'Lint'
17
- script:
18
- - echo "Your linting goes here..."
19
- - step:
20
- name: 'Security scan'
21
- script:
22
- - echo "Your security scan goes here..."
23
-
24
- # The following deployment steps will be executed for each pipeline run. To configure your steps and conditionally deploy see https://support.atlassian.com/bitbucket-cloud/docs/configure-bitbucket-pipelinesyml/
25
- - step:
26
- name: 'Deployment to Staging'
27
- deployment: staging
28
- script:
29
- - echo "Your deployment to staging script goes here..."
30
- - step:
31
- name: 'Deployment to Production'
32
- deployment: production
33
- trigger: 'manual'
34
- script:
35
- - echo "Your deployment to production script goes here..."
Binary file
package/public/index.html DELETED
@@ -1,43 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8" />
5
- <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1" />
7
- <meta name="theme-color" content="#000000" />
8
- <meta
9
- name="description"
10
- content="Web site created using create-react-app"
11
- />
12
- <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
13
- <!--
14
- manifest.json provides metadata used when your web app is installed on a
15
- user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
16
- -->
17
- <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
18
- <!--
19
- Notice the use of %PUBLIC_URL% in the tags above.
20
- It will be replaced with the URL of the `public` folder during the build.
21
- Only files inside the `public` folder can be referenced from the HTML.
22
-
23
- Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
24
- work correctly both with client-side routing and a non-root public URL.
25
- Learn how to configure a non-root public URL by running `npm run build`.
26
- -->
27
- <title>React App</title>
28
- </head>
29
- <body>
30
- <noscript>You need to enable JavaScript to run this app.</noscript>
31
- <div id="root"></div>
32
- <!--
33
- This HTML file is a template.
34
- If you open it directly in the browser, you will see an empty page.
35
-
36
- You can add webfonts, meta tags, or analytics to this file.
37
- The build step will place the bundled scripts into the <body> tag.
38
-
39
- To begin the development, run `npm start` or `yarn start`.
40
- To create a production bundle, use `npm run build` or `yarn build`.
41
- -->
42
- </body>
43
- </html>
Binary file
Binary file
@@ -1,25 +0,0 @@
1
- {
2
- "short_name": "React App",
3
- "name": "Create React App Sample",
4
- "icons": [
5
- {
6
- "src": "favicon.ico",
7
- "sizes": "64x64 32x32 24x24 16x16",
8
- "type": "image/x-icon"
9
- },
10
- {
11
- "src": "logo192.png",
12
- "type": "image/png",
13
- "sizes": "192x192"
14
- },
15
- {
16
- "src": "logo512.png",
17
- "type": "image/png",
18
- "sizes": "512x512"
19
- }
20
- ],
21
- "start_url": ".",
22
- "display": "standalone",
23
- "theme_color": "#000000",
24
- "background_color": "#ffffff"
25
- }
package/public/robots.txt DELETED
@@ -1,3 +0,0 @@
1
- # https://www.robotstxt.org/robotstxt.html
2
- User-agent: *
3
- Disallow:
package/src/App.tsx DELETED
@@ -1,28 +0,0 @@
1
- import styled from "styled-components";
2
- import {
3
- ReactGridLayoutShowcase01,
4
- ResponsiveGridLayoutShowcase01,
5
- } from "./examples";
6
-
7
- function App() {
8
- // return (
9
- // <S_GridLayoutWrapper>
10
- // <ResponsiveGridLayoutShowcase01 />
11
- // </S_GridLayoutWrapper>
12
- // );
13
- return (
14
- <S_GridLayoutWrapper>
15
- <ReactGridLayoutShowcase01 />
16
- </S_GridLayoutWrapper>
17
- );
18
- }
19
-
20
- const S_GridLayoutWrapper = styled.div`
21
- background-color: yellow;
22
-
23
- & > div {
24
- background-color: lightgreen;
25
- }
26
- `;
27
-
28
- export default App;
@@ -1,80 +0,0 @@
1
- import { SyntheticEvent, useState } from "react";
2
- import { generateLayout } from "../utils";
3
- import { Layout } from "../../lib/GridLayoutEditor/types";
4
-
5
- import styled from "styled-components";
6
- import { ReactGridLayoutPreview } from "../../lib/PreviewGLE";
7
- import ReactGridLayout from "../../lib/GridLayoutEditor/ReactGridLayout";
8
- import { ResizeCallbackData } from "../../lib/Resizable/types";
9
-
10
- const lay = generateLayout().slice(0, 2);
11
-
12
- // NOTE - windowSize viewport에 맞게 Resize시키기 위한 Provider
13
- // const Responsive = WidthProvider(ReactGridLayout);
14
-
15
- function ReactGridLayoutShowcase01() {
16
- const [layout, setLayout] = useState<Layout>(lay);
17
- const [isOpenPreview, setIsOpenPreview] = useState(false);
18
-
19
- const defaultProps = {
20
- width: 1280,
21
- // className: "layout",
22
- items: 50,
23
- cols: 12,
24
- rowHeight: 50,
25
- allowOverlap: true,
26
- margin: [10, 10] as [number, number],
27
- };
28
-
29
- function onLayoutChange(newLayout: Layout) {
30
- setLayout(newLayout);
31
- }
32
-
33
- const onResizeStartTemp = (
34
- e: SyntheticEvent,
35
- // { node, size }: { node: HTMLElement; size: Position }
36
- { node, size }: ResizeCallbackData
37
- ) => {
38
- // Get new XY
39
- return;
40
- };
41
-
42
- const onResizeTemp = (
43
- e: SyntheticEvent,
44
- // { node, size }: { node: HTMLElement; size: Position }
45
- { node, size }: ResizeCallbackData
46
- ) => {
47
- return;
48
- };
49
-
50
- return (
51
- <>
52
- <button onClick={() => setIsOpenPreview(true)}>previewButton</button>
53
- {!isOpenPreview && (
54
- <ReactGridLayout
55
- {...defaultProps}
56
- layout={layout}
57
- onLayoutChange={onLayoutChange}
58
- resizeHandles={["nw", "e", "n", "ne", "s", "se", "sw", "w"]}
59
- isHiddenVisibility
60
- >
61
- {layout.map((each) => (
62
- <S_SampleBox key={each.i}>{each.i}</S_SampleBox>
63
- ))}
64
- </ReactGridLayout>
65
- )}
66
- {isOpenPreview && (
67
- <ReactGridLayoutPreview layout={layout} props={defaultProps} />
68
- )}
69
- </>
70
- );
71
- }
72
-
73
- const S_SampleBox = styled.div`
74
- width: 100px;
75
- height: 100px;
76
- background-color: lightgray;
77
- border: dodgerblue 1px solid;
78
- `;
79
-
80
- export default ReactGridLayoutShowcase01;
@@ -1,114 +0,0 @@
1
- import { useState } from "react";
2
- import { generateLayout } from "../utils";
3
- import _ from "lodash";
4
- import {
5
- CompactType,
6
- Layout,
7
- OnBreakpointChangeCallback,
8
- OnLayoutChangeCallback,
9
- OnWidthChangeCallback,
10
- } from "../../lib/GridLayoutEditor/types";
11
- import styled from "styled-components";
12
- import { WidthProvider } from "../../lib/components";
13
-
14
- import { ResponsiveGridLayoutPreview } from "../../lib/PreviewGLE";
15
- import ResponsiveGridLayout from "../../lib/GridLayoutEditor/ResponsiveGridLayout";
16
-
17
- // NOTE - windowSize viewport에 맞게 Resize시키기 위한 Provider
18
- const Responsive = WidthProvider(ResponsiveGridLayout);
19
-
20
- function ResponsiveGridLayoutShowcase01() {
21
- const [currentBreakpoint, setCurrentBreakpoint] = useState("lg");
22
- const [currentCompactType, setCurrentCompactType] =
23
- useState<CompactType | null>("vertical");
24
- const [mounted, setMounted] = useState(false);
25
- const [layouts, setLayouts] = useState<{ [key: string]: Layout }>({
26
- lg: generateLayout().slice(0, 1),
27
- });
28
-
29
- const [isOpenPreview, setIsOpenPreview] = useState(false);
30
-
31
- const defaultProps = {
32
- // className: "layout",
33
- cols: { lg: 12, md: 10, sm: 6, xs: 4, xxs: 2 },
34
- rowHeight: 50,
35
- allowOverlap: true,
36
- margin: [10, 10] as [number, number],
37
- };
38
-
39
- const onLayoutChange: OnLayoutChangeCallback = ({ layout, layouts }) => {
40
- setLayouts({ ...layouts });
41
- };
42
-
43
- const onBreakpointChange: OnBreakpointChangeCallback = (breakpoint) => {
44
- setCurrentBreakpoint(breakpoint);
45
- };
46
-
47
- const onCompactTypeChange = () => {
48
- const compactType =
49
- currentCompactType === "horizontal"
50
- ? "vertical"
51
- : currentCompactType === "vertical"
52
- ? null
53
- : "horizontal";
54
-
55
- setCurrentCompactType(compactType);
56
- };
57
-
58
- const onWidthChange: OnWidthChangeCallback = (
59
- containerWidth,
60
- margin,
61
- cols,
62
- containerPadding
63
- ) => {
64
- return;
65
- };
66
-
67
- function generateDOM() {
68
- return _.map(layouts.lg, function (l, i) {
69
- return (
70
- <S_SampleBox key={i} className={l.static ? "static" : ""}>
71
- {l.static ? (
72
- <span
73
- className="text"
74
- title="This item is static and cannot be removed or resized."
75
- >
76
- Static - {i}
77
- </span>
78
- ) : (
79
- <span className="text">{i}</span>
80
- )}
81
- </S_SampleBox>
82
- );
83
- });
84
- }
85
-
86
- // NOTE - window resize 적용된 Responsive
87
- return (
88
- <>
89
- <button onClick={() => setIsOpenPreview(true)}>previewButton</button>
90
- {!isOpenPreview && (
91
- <Responsive
92
- {...defaultProps}
93
- layouts={layouts}
94
- onLayoutChange={onLayoutChange}
95
- resizeHandles={["nw", "e", "n", "ne", "s", "se", "sw", "w"]}
96
- >
97
- {generateDOM()}
98
- </Responsive>
99
- )}
100
- {isOpenPreview && (
101
- <ResponsiveGridLayoutPreview layouts={layouts} props={defaultProps} />
102
- )}
103
- </>
104
- );
105
- }
106
-
107
- const S_SampleBox = styled.div`
108
- width: 100px;
109
- height: 100px;
110
- background-color: lightgray;
111
- border: dodgerblue 1px solid;
112
- `;
113
-
114
- export default ResponsiveGridLayoutShowcase01;
@@ -1,15 +0,0 @@
1
- import _ from "lodash";
2
-
3
- export function generateLayout() {
4
- return _.map(_.range(0, 25), function (item, i) {
5
- var y = Math.ceil(Math.random() * 4) + 1;
6
- return {
7
- x: Math.round(Math.random() * 5) * 2,
8
- y: Math.floor(i / 6) * y,
9
- w: 2,
10
- h: y,
11
- i: i.toString(),
12
- static: Math.random() < 0.05,
13
- };
14
- });
15
- }
@@ -1,303 +0,0 @@
1
- import React, { useEffect, useRef, useState } from "react";
2
- import DraggableCore from "./DraggableCore";
3
- import { Bounds, ControlPosition, DraggableEventHandler } from "./utils/types";
4
- import {
5
- AxisType,
6
- DraggableCoreDefaultProps,
7
- DraggablePositionType,
8
- DraggableState,
9
- PropsWithChildren,
10
- } from "./types";
11
- import {
12
- canDragX,
13
- canDragY,
14
- cloneBounds,
15
- createDraggableData,
16
- } from "./utils/positionHelpers";
17
- import { int, isNum } from "./utils/validationHelpers";
18
- import {
19
- createCSSTransform,
20
- createSVGTransform,
21
- innerHeight,
22
- innerWidth,
23
- outerHeight,
24
- outerWidth,
25
- } from "./utils/domHelpers";
26
- import classNames from "classnames";
27
-
28
- export type DraggableDefaultProps = {
29
- axis?: AxisType;
30
- bounds?: Bounds | string | false;
31
- defaultClassName?: string;
32
- defaultClassNameDragging?: string;
33
- defaultClassNameDragged?: string;
34
- defaultPosition?: ControlPosition;
35
- scale?: number;
36
- nodeRef?: React.RefObject<HTMLElement>;
37
- className?: string;
38
- style?: Object;
39
- } & DraggableCoreDefaultProps &
40
- DraggablePositionType;
41
-
42
- const Draggable = ({
43
- children,
44
- axis = "both",
45
- bounds = false,
46
- defaultClassName = "react-draggable",
47
- defaultClassNameDragging = "react-draggable-dragging",
48
- defaultClassNameDragged = "react-draggable-dragged",
49
- defaultPosition = { x: 0, y: 0 },
50
- scale = 1,
51
- ...props
52
- }: PropsWithChildren<DraggableDefaultProps>) => {
53
- const { position, positionOffset, ...draggableCoreProps } = props;
54
-
55
- const draggableRef = useRef<HTMLElement>(null);
56
-
57
- const [draggableState, setDraggableState] = useState<DraggableState>({
58
- dragged: false,
59
- dragging: false,
60
- x: position ? position?.x : defaultPosition.x,
61
- y: position ? position?.y : defaultPosition.y,
62
- slackX: 0,
63
- slackY: 0,
64
- isElementSVG: false,
65
- prevPropsPosition: position,
66
- });
67
-
68
- /**
69
- * @when Draggable이 화면에 그려질 때
70
- * @expected 해당 DOMNode가 SVGElement인지를 확인
71
- * @clear 페이지를 나갔을 때 dragging을 false로 변경하여 drag되지 않도록 설정
72
- */
73
- useEffect(() => {
74
- if (
75
- typeof window.SVGElement !== "undefined" &&
76
- findDOMNode() instanceof window.SVGElement
77
- ) {
78
- setDraggableState((prevState) => ({ ...prevState, isElementSVG: true }));
79
- }
80
-
81
- return () => {
82
- setDraggableState((prevState) => ({ ...prevState, dragging: false }));
83
- };
84
- }, []);
85
-
86
- let style = {};
87
- let svgTransform = null;
88
-
89
- const findDOMNode = (): HTMLElement | null => {
90
- return props?.nodeRef?.current ?? draggableRef?.current;
91
- };
92
-
93
- const getBoundPosition = (
94
- x: number,
95
- y: number,
96
- node?: HTMLElement | null
97
- ): [number, number] => {
98
- if (!bounds) return [x, y];
99
-
100
- let newBounds = bounds;
101
- newBounds = typeof bounds === "string" ? bounds : cloneBounds(bounds);
102
-
103
- if (typeof newBounds === "string") {
104
- const ownerWindow = node?.ownerDocument?.defaultView;
105
-
106
- let boundNode;
107
-
108
- if (newBounds === "parent") {
109
- boundNode = node?.parentNode;
110
- } else {
111
- boundNode = node?.ownerDocument.querySelector(newBounds);
112
- }
113
-
114
- if (!(ownerWindow && boundNode instanceof ownerWindow.HTMLElement)) {
115
- throw new Error(
116
- 'Bounds selector "' + newBounds + '" could not find an element'
117
- );
118
- }
119
-
120
- const boundNodeElement: HTMLElement = boundNode;
121
- const nodeStyle = ownerWindow.getComputedStyle(node);
122
- const boundNodeStyle = ownerWindow.getComputedStyle(boundNodeElement);
123
-
124
- newBounds = {
125
- left:
126
- -node.offsetLeft +
127
- int(boundNodeStyle.paddingLeft) +
128
- int(nodeStyle.marginLeft),
129
- top:
130
- -node.offsetTop +
131
- int(boundNodeStyle.paddingTop) +
132
- int(nodeStyle.marginTop),
133
- right:
134
- innerWidth(boundNodeElement) -
135
- outerWidth(node) -
136
- node.offsetLeft +
137
- int(boundNodeStyle.paddingRight) -
138
- int(nodeStyle.marginRight),
139
- bottom:
140
- innerHeight(boundNodeElement) -
141
- outerHeight(node) -
142
- node.offsetTop +
143
- int(boundNodeStyle.paddingBottom) -
144
- int(nodeStyle.marginBottom),
145
- };
146
- }
147
-
148
- if (isNum(newBounds.right)) x = Math.min(x, newBounds.right);
149
- if (isNum(newBounds.bottom)) y = Math.min(y, newBounds.bottom);
150
-
151
- if (isNum(newBounds.left)) x = Math.max(x, newBounds.left);
152
- if (isNum(newBounds.top)) y = Math.max(y, newBounds.top);
153
-
154
- return [x, y];
155
- };
156
-
157
- const handleDragStart: DraggableEventHandler = (e, coreData) => {
158
- if (props.onStart) {
159
- const shouldStart = props.onStart(
160
- e,
161
- createDraggableData(draggableState, scale, coreData)
162
- );
163
-
164
- if (shouldStart === false) return false;
165
- }
166
-
167
- setDraggableState((prev) => ({ ...prev, dragged: true, dragging: true }));
168
- };
169
-
170
- const handleDrag: DraggableEventHandler = (e, coreData, node) => {
171
- if (!draggableState.dragging) return false;
172
-
173
- const uiData = createDraggableData(draggableState, scale, coreData);
174
- const newState: DraggableState = {
175
- ...draggableState,
176
- x: uiData.x,
177
- y: uiData.y,
178
- };
179
-
180
- if (bounds) {
181
- const { x, y } = newState;
182
-
183
- newState.x += draggableState.slackX;
184
- newState.y += draggableState.slackY;
185
-
186
- const [newBoundPositionX, newBoundPositionY] = getBoundPosition(
187
- newState.x,
188
- newState.y,
189
- node
190
- );
191
-
192
- newState.x = newBoundPositionX;
193
- newState.y = newBoundPositionY;
194
-
195
- newState.slackX = draggableState.slackX + (x - newState.x);
196
- newState.slackY = draggableState.slackY + (y - newState.y);
197
-
198
- uiData.x = newState.x;
199
- uiData.y = newState.y;
200
- uiData.deltaX = newState.x - draggableState.x;
201
- uiData.deltaY = newState.y - draggableState.y;
202
- }
203
-
204
- if (props.onDrag) {
205
- const shouldUpdate = props.onDrag(e, uiData);
206
-
207
- if (shouldUpdate === false) return false;
208
- }
209
-
210
- setDraggableState((prevState) => ({
211
- ...prevState,
212
- x: newState.x,
213
- y: newState.y,
214
- }));
215
- };
216
-
217
- const handleDragStop: DraggableEventHandler = (e, coreData) => {
218
- if (!draggableState.dragging) return false;
219
-
220
- if (props.onStop) {
221
- const shouldContinue = props.onStop(
222
- e,
223
- createDraggableData(draggableState, scale, coreData)
224
- );
225
-
226
- if (shouldContinue === false) return false;
227
- }
228
-
229
- if (position && Boolean(position)) {
230
- const { x, y } = position;
231
-
232
- setDraggableState((prevState) => ({
233
- ...prevState,
234
- x,
235
- y,
236
- dragging: false,
237
- slackX: 0,
238
- slackY: 0,
239
- }));
240
- } else {
241
- setDraggableState((prevState) => ({
242
- ...prevState,
243
- dragging: false,
244
- slackX: 0,
245
- slackY: 0,
246
- }));
247
- }
248
- };
249
-
250
- const controlled = Boolean(position);
251
- const draggable = !controlled || draggableState.dragging;
252
-
253
- const validPosition = position || defaultPosition;
254
- const transformOptions = {
255
- x: canDragX(axis) && draggable ? draggableState.x : validPosition.x,
256
- y: canDragY(axis) && draggable ? draggableState.y : validPosition.y,
257
- };
258
-
259
- if (draggableState.isElementSVG) {
260
- svgTransform = createSVGTransform(transformOptions, positionOffset);
261
- } else {
262
- style = createCSSTransform(transformOptions, positionOffset);
263
- }
264
-
265
- const className = classNames(
266
- props.className || "",
267
- defaultClassName,
268
- { [defaultClassNameDragging]: draggableState.dragging },
269
- { [defaultClassNameDragged]: draggableState.dragged }
270
- );
271
-
272
- // NOTE - class형 컴포넌트에서 사용되는 getDerivedStateFromProps에 대응하기 위한 조건문입니다.
273
- if (
274
- position &&
275
- (!draggableState.prevPropsPosition ||
276
- position.x !== draggableState.prevPropsPosition.x ||
277
- position.y !== draggableState.prevPropsPosition.y)
278
- ) {
279
- setDraggableState((prevState) => ({
280
- ...prevState,
281
- x: position.x,
282
- y: position.y,
283
- prevPropsPosition: { ...position },
284
- }));
285
- }
286
-
287
- return (
288
- <DraggableCore
289
- {...draggableCoreProps}
290
- onStart={handleDragStart}
291
- onDrag={handleDrag}
292
- onStop={handleDragStop}
293
- >
294
- {React.cloneElement(children, {
295
- className,
296
- style: { ...props.style, ...style },
297
- transform: svgTransform,
298
- })}
299
- </DraggableCore>
300
- );
301
- };
302
-
303
- export default Draggable;