@yamada-ui/reorder 0.0.0-dev-20230603042803
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/LICENSE +21 -0
- package/README.md +28 -0
- package/dist/chunk-6WVUHM4V.mjs +111 -0
- package/dist/chunk-CT62EC32.mjs +71 -0
- package/dist/chunk-UF5QTFGJ.mjs +90 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +281 -0
- package/dist/index.mjs +22 -0
- package/dist/reorder-item.d.ts +18 -0
- package/dist/reorder-item.js +172 -0
- package/dist/reorder-item.mjs +11 -0
- package/dist/reorder-trigger.d.ts +7 -0
- package/dist/reorder-trigger.js +269 -0
- package/dist/reorder-trigger.mjs +8 -0
- package/dist/reorder.d.ts +20 -0
- package/dist/reorder.js +112 -0
- package/dist/reorder.mjs +10 -0
- package/package.json +77 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Hirotomo Yamada
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @yamada-ui/reorder
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
$ pnpm add @yamada-ui/reorder
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
or
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
$ yarn add @yamada-ui/reorder
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
or
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
$ npm install @yamada-ui/reorder
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Contribution
|
|
22
|
+
|
|
23
|
+
Wouldn't you like to contribute? That's amazing! We have prepared a [contribution guide](https://github.com/hirotomoyamada/yamada-ui/blob/main/CONTRIBUTING.md) to assist you.
|
|
24
|
+
|
|
25
|
+
## Licence
|
|
26
|
+
|
|
27
|
+
This package is licensed under the terms of the
|
|
28
|
+
[MIT license](https://github.com/hirotomoyamada/yamada-ui/blob/main/LICENSE).
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useReorderItemContext
|
|
3
|
+
} from "./chunk-CT62EC32.mjs";
|
|
4
|
+
import {
|
|
5
|
+
useReorderContext
|
|
6
|
+
} from "./chunk-UF5QTFGJ.mjs";
|
|
7
|
+
|
|
8
|
+
// src/reorder-trigger.tsx
|
|
9
|
+
import { ui, forwardRef } from "@yamada-ui/core";
|
|
10
|
+
import { Icon } from "@yamada-ui/icon";
|
|
11
|
+
import { cx, handlerAll, mergeRefs, dataAttr } from "@yamada-ui/utils";
|
|
12
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
var ReorderTrigger = forwardRef(
|
|
14
|
+
({ className, children = /* @__PURE__ */ jsx(ReorderTriggerIcon, {}), ...rest }, ref) => {
|
|
15
|
+
const { styles } = useReorderContext();
|
|
16
|
+
const { register, isDrag, dragControls } = useReorderItemContext();
|
|
17
|
+
const css = {
|
|
18
|
+
display: "flex",
|
|
19
|
+
justifyContent: "center",
|
|
20
|
+
alignItems: "center",
|
|
21
|
+
cursor: "grab",
|
|
22
|
+
_selected: {
|
|
23
|
+
cursor: "grabbing"
|
|
24
|
+
},
|
|
25
|
+
...styles.trigger
|
|
26
|
+
};
|
|
27
|
+
return /* @__PURE__ */ jsx(
|
|
28
|
+
ui.div,
|
|
29
|
+
{
|
|
30
|
+
ref: mergeRefs(register, ref),
|
|
31
|
+
className: cx("ui-reorder-trigger", className),
|
|
32
|
+
__css: css,
|
|
33
|
+
...rest,
|
|
34
|
+
"data-selected": dataAttr(isDrag),
|
|
35
|
+
onPointerDown: handlerAll(rest.onPointerDown, (ev) => dragControls.start(ev)),
|
|
36
|
+
children
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
var ReorderTriggerIcon = (rest) => {
|
|
42
|
+
return /* @__PURE__ */ jsxs(Icon, { viewBox: "0 0 39 39", ...rest, children: [
|
|
43
|
+
/* @__PURE__ */ jsx(
|
|
44
|
+
"path",
|
|
45
|
+
{
|
|
46
|
+
d: "M 5 0 C 7.761 0 10 2.239 10 5 C 10 7.761 7.761 10 5 10 C 2.239 10 0 7.761 0 5 C 0 2.239 2.239 0 5 0 Z",
|
|
47
|
+
fill: "currentColor"
|
|
48
|
+
}
|
|
49
|
+
),
|
|
50
|
+
/* @__PURE__ */ jsx(
|
|
51
|
+
"path",
|
|
52
|
+
{
|
|
53
|
+
d: "M 19 0 C 21.761 0 24 2.239 24 5 C 24 7.761 21.761 10 19 10 C 16.239 10 14 7.761 14 5 C 14 2.239 16.239 0 19 0 Z",
|
|
54
|
+
fill: "currentColor"
|
|
55
|
+
}
|
|
56
|
+
),
|
|
57
|
+
/* @__PURE__ */ jsx(
|
|
58
|
+
"path",
|
|
59
|
+
{
|
|
60
|
+
d: "M 33 0 C 35.761 0 38 2.239 38 5 C 38 7.761 35.761 10 33 10 C 30.239 10 28 7.761 28 5 C 28 2.239 30.239 0 33 0 Z",
|
|
61
|
+
fill: "currentColor"
|
|
62
|
+
}
|
|
63
|
+
),
|
|
64
|
+
/* @__PURE__ */ jsx(
|
|
65
|
+
"path",
|
|
66
|
+
{
|
|
67
|
+
d: "M 33 14 C 35.761 14 38 16.239 38 19 C 38 21.761 35.761 24 33 24 C 30.239 24 28 21.761 28 19 C 28 16.239 30.239 14 33 14 Z",
|
|
68
|
+
fill: "currentColor"
|
|
69
|
+
}
|
|
70
|
+
),
|
|
71
|
+
/* @__PURE__ */ jsx(
|
|
72
|
+
"path",
|
|
73
|
+
{
|
|
74
|
+
d: "M 19 14 C 21.761 14 24 16.239 24 19 C 24 21.761 21.761 24 19 24 C 16.239 24 14 21.761 14 19 C 14 16.239 16.239 14 19 14 Z",
|
|
75
|
+
fill: "currentColor"
|
|
76
|
+
}
|
|
77
|
+
),
|
|
78
|
+
/* @__PURE__ */ jsx(
|
|
79
|
+
"path",
|
|
80
|
+
{
|
|
81
|
+
d: "M 5 14 C 7.761 14 10 16.239 10 19 C 10 21.761 7.761 24 5 24 C 2.239 24 0 21.761 0 19 C 0 16.239 2.239 14 5 14 Z",
|
|
82
|
+
fill: "currentColor"
|
|
83
|
+
}
|
|
84
|
+
),
|
|
85
|
+
/* @__PURE__ */ jsx(
|
|
86
|
+
"path",
|
|
87
|
+
{
|
|
88
|
+
d: "M 5 28 C 7.761 28 10 30.239 10 33 C 10 35.761 7.761 38 5 38 C 2.239 38 0 35.761 0 33 C 0 30.239 2.239 28 5 28 Z",
|
|
89
|
+
fill: "currentColor"
|
|
90
|
+
}
|
|
91
|
+
),
|
|
92
|
+
/* @__PURE__ */ jsx(
|
|
93
|
+
"path",
|
|
94
|
+
{
|
|
95
|
+
d: "M 19 28 C 21.761 28 24 30.239 24 33 C 24 35.761 21.761 38 19 38 C 16.239 38 14 35.761 14 33 C 14 30.239 16.239 28 19 28 Z",
|
|
96
|
+
fill: "currentColor"
|
|
97
|
+
}
|
|
98
|
+
),
|
|
99
|
+
/* @__PURE__ */ jsx(
|
|
100
|
+
"path",
|
|
101
|
+
{
|
|
102
|
+
d: "M 33 28 C 35.761 28 38 30.239 38 33 C 38 35.761 35.761 38 33 38 C 30.239 38 28 35.761 28 33 C 28 30.239 30.239 28 33 28 Z",
|
|
103
|
+
fill: "currentColor"
|
|
104
|
+
}
|
|
105
|
+
)
|
|
106
|
+
] });
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export {
|
|
110
|
+
ReorderTrigger
|
|
111
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useReorderContext
|
|
3
|
+
} from "./chunk-UF5QTFGJ.mjs";
|
|
4
|
+
|
|
5
|
+
// src/reorder-item.tsx
|
|
6
|
+
import { ui } from "@yamada-ui/core";
|
|
7
|
+
import {
|
|
8
|
+
MotionReorder,
|
|
9
|
+
useMotionValue,
|
|
10
|
+
useDragControls
|
|
11
|
+
} from "@yamada-ui/motion";
|
|
12
|
+
import { createContext, cx, dataAttr } from "@yamada-ui/utils";
|
|
13
|
+
import { forwardRef, useCallback, useEffect, useState } from "react";
|
|
14
|
+
import { jsx } from "react/jsx-runtime";
|
|
15
|
+
var [ReorderItemProvider, useReorderItemContext] = createContext({
|
|
16
|
+
name: "ReorderContext",
|
|
17
|
+
errorMessage: `useReorderItemContext returned is 'undefined'. Seems you forgot to wrap the components in "<ReorderItem />"`
|
|
18
|
+
});
|
|
19
|
+
var ReorderItem = forwardRef(
|
|
20
|
+
({ className, label, ...rest }, ref) => {
|
|
21
|
+
var _a;
|
|
22
|
+
const { orientation, styles } = useReorderContext();
|
|
23
|
+
const dragControls = useDragControls();
|
|
24
|
+
const [hasTrigger, setHasTrigger] = useState(false);
|
|
25
|
+
const [isDrag, setIsDrag] = useState(false);
|
|
26
|
+
const x = useMotionValue(0);
|
|
27
|
+
const y = useMotionValue(0);
|
|
28
|
+
const register = useCallback((node) => setHasTrigger(!!node), []);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
x.onChange((subscription) => {
|
|
31
|
+
if (orientation === "horizontal")
|
|
32
|
+
setIsDrag(subscription !== 0);
|
|
33
|
+
});
|
|
34
|
+
y.onChange((subscription) => {
|
|
35
|
+
if (orientation === "vertical")
|
|
36
|
+
setIsDrag(subscription !== 0);
|
|
37
|
+
});
|
|
38
|
+
return () => {
|
|
39
|
+
x.destroy();
|
|
40
|
+
y.destroy();
|
|
41
|
+
};
|
|
42
|
+
}, [orientation, x, y]);
|
|
43
|
+
const css = {
|
|
44
|
+
...!hasTrigger ? { cursor: "grab" } : { userSelect: "none" },
|
|
45
|
+
...styles.item,
|
|
46
|
+
...!hasTrigger ? { _selected: { ...(_a = styles.item) == null ? void 0 : _a._selected, cursor: "grabbing" } } : {}
|
|
47
|
+
};
|
|
48
|
+
return /* @__PURE__ */ jsx(ReorderItemProvider, { value: { register, isDrag, dragControls }, children: /* @__PURE__ */ jsx(
|
|
49
|
+
ui.li,
|
|
50
|
+
{
|
|
51
|
+
ref,
|
|
52
|
+
as: MotionReorder.Item,
|
|
53
|
+
className: cx("ui-reorder-item", className),
|
|
54
|
+
value: label,
|
|
55
|
+
__css: css,
|
|
56
|
+
...rest,
|
|
57
|
+
dragListener: !hasTrigger,
|
|
58
|
+
dragControls,
|
|
59
|
+
"data-selected": dataAttr(isDrag),
|
|
60
|
+
style: { ...rest.style, x, y }
|
|
61
|
+
}
|
|
62
|
+
) });
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
ReorderItem.displayName = "ReorderItem";
|
|
66
|
+
|
|
67
|
+
export {
|
|
68
|
+
ReorderItemProvider,
|
|
69
|
+
useReorderItemContext,
|
|
70
|
+
ReorderItem
|
|
71
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// src/reorder.tsx
|
|
2
|
+
import {
|
|
3
|
+
ui,
|
|
4
|
+
useMultiComponentStyle,
|
|
5
|
+
omitThemeProps
|
|
6
|
+
} from "@yamada-ui/core";
|
|
7
|
+
import { MotionReorder } from "@yamada-ui/motion";
|
|
8
|
+
import { createContext, cx, getValidChildren, handlerAll, useUpdateEffect } from "@yamada-ui/utils";
|
|
9
|
+
import { forwardRef, useCallback, useMemo, useState } from "react";
|
|
10
|
+
import { jsx } from "react/jsx-runtime";
|
|
11
|
+
var [ReorderProvider, useReorderContext] = createContext({
|
|
12
|
+
name: "ReorderContext",
|
|
13
|
+
errorMessage: `useReorderContext returned is 'undefined'. Seems you forgot to wrap the components in "<Reorder />"`
|
|
14
|
+
});
|
|
15
|
+
var omitDuplicated = (values) => Array.from(new Set(values));
|
|
16
|
+
var pickDuplicated = (values) => values.filter(
|
|
17
|
+
(value, index, self) => self.indexOf(value) === index && index !== self.lastIndexOf(value)
|
|
18
|
+
);
|
|
19
|
+
var Reorder = forwardRef((props, ref) => {
|
|
20
|
+
const [styles, mergedProps] = useMultiComponentStyle("Reorder", props);
|
|
21
|
+
const {
|
|
22
|
+
className,
|
|
23
|
+
orientation = "vertical",
|
|
24
|
+
gap = "md",
|
|
25
|
+
onChange,
|
|
26
|
+
onCompleteChange,
|
|
27
|
+
children,
|
|
28
|
+
...rest
|
|
29
|
+
} = omitThemeProps(mergedProps);
|
|
30
|
+
const axis = orientation === "vertical" ? "y" : "x";
|
|
31
|
+
const validChildren = getValidChildren(children);
|
|
32
|
+
const defaultValues = useMemo(() => {
|
|
33
|
+
const values2 = validChildren.map(({ props: props2 }) => props2.label);
|
|
34
|
+
const duplicatedValues = pickDuplicated(values2);
|
|
35
|
+
if (duplicatedValues.length)
|
|
36
|
+
console.warn(
|
|
37
|
+
`Reorder: 'label' of 'ReorderItem' must not be duplicated. duplicate 'label' is '${duplicatedValues.join(
|
|
38
|
+
`', '`
|
|
39
|
+
)}' `
|
|
40
|
+
);
|
|
41
|
+
return omitDuplicated(values2);
|
|
42
|
+
}, [validChildren]);
|
|
43
|
+
const [values, setValues] = useState(defaultValues);
|
|
44
|
+
const onReorder = useCallback(
|
|
45
|
+
(newValues) => {
|
|
46
|
+
setValues(newValues);
|
|
47
|
+
onChange == null ? void 0 : onChange(newValues);
|
|
48
|
+
},
|
|
49
|
+
[onChange]
|
|
50
|
+
);
|
|
51
|
+
useUpdateEffect(() => {
|
|
52
|
+
const isDone = defaultValues.every((defaultValue) => values.includes(defaultValue));
|
|
53
|
+
if (isDone)
|
|
54
|
+
return;
|
|
55
|
+
setValues(defaultValues);
|
|
56
|
+
}, [defaultValues]);
|
|
57
|
+
const cloneChildren = useMemo(
|
|
58
|
+
() => values.map((value) => validChildren.find(({ props: props2 }) => props2.label === value)),
|
|
59
|
+
[values, validChildren]
|
|
60
|
+
);
|
|
61
|
+
const css = {
|
|
62
|
+
display: "flex",
|
|
63
|
+
flexDirection: orientation === "vertical" ? "column" : "row",
|
|
64
|
+
gap,
|
|
65
|
+
...styles.container
|
|
66
|
+
};
|
|
67
|
+
return /* @__PURE__ */ jsx(ReorderProvider, { value: { orientation, styles }, children: /* @__PURE__ */ jsx(
|
|
68
|
+
ui.ul,
|
|
69
|
+
{
|
|
70
|
+
ref,
|
|
71
|
+
as: MotionReorder.Group,
|
|
72
|
+
className: cx("ui-reorder", className),
|
|
73
|
+
axis,
|
|
74
|
+
values,
|
|
75
|
+
onReorder,
|
|
76
|
+
__css: css,
|
|
77
|
+
...rest,
|
|
78
|
+
onMouseUp: handlerAll(rest.onMouseUp, () => onCompleteChange == null ? void 0 : onCompleteChange(values)),
|
|
79
|
+
onTouchEnd: handlerAll(rest.onTouchEnd, () => onCompleteChange == null ? void 0 : onCompleteChange(values)),
|
|
80
|
+
children: cloneChildren
|
|
81
|
+
}
|
|
82
|
+
) });
|
|
83
|
+
});
|
|
84
|
+
Reorder.displayName = "Reorder";
|
|
85
|
+
|
|
86
|
+
export {
|
|
87
|
+
ReorderProvider,
|
|
88
|
+
useReorderContext,
|
|
89
|
+
Reorder
|
|
90
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Reorder, ReorderProps, ReorderProvider, useReorderContext } from './reorder.js';
|
|
2
|
+
export { ReorderItem, ReorderItemProps, ReorderItemProvider, useReorderItemContext } from './reorder-item.js';
|
|
3
|
+
export { ReorderTrigger, ReorderTriggerProps } from './reorder-trigger.js';
|
|
4
|
+
import 'react';
|
|
5
|
+
import '@yamada-ui/core';
|
|
6
|
+
import '@yamada-ui/motion';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
Reorder: () => Reorder,
|
|
24
|
+
ReorderItem: () => ReorderItem,
|
|
25
|
+
ReorderItemProvider: () => ReorderItemProvider,
|
|
26
|
+
ReorderProvider: () => ReorderProvider,
|
|
27
|
+
ReorderTrigger: () => ReorderTrigger,
|
|
28
|
+
useReorderContext: () => useReorderContext,
|
|
29
|
+
useReorderItemContext: () => useReorderItemContext
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(src_exports);
|
|
32
|
+
|
|
33
|
+
// src/reorder.tsx
|
|
34
|
+
var import_core = require("@yamada-ui/core");
|
|
35
|
+
var import_motion = require("@yamada-ui/motion");
|
|
36
|
+
var import_utils = require("@yamada-ui/utils");
|
|
37
|
+
var import_react = require("react");
|
|
38
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
39
|
+
var [ReorderProvider, useReorderContext] = (0, import_utils.createContext)({
|
|
40
|
+
name: "ReorderContext",
|
|
41
|
+
errorMessage: `useReorderContext returned is 'undefined'. Seems you forgot to wrap the components in "<Reorder />"`
|
|
42
|
+
});
|
|
43
|
+
var omitDuplicated = (values) => Array.from(new Set(values));
|
|
44
|
+
var pickDuplicated = (values) => values.filter(
|
|
45
|
+
(value, index, self) => self.indexOf(value) === index && index !== self.lastIndexOf(value)
|
|
46
|
+
);
|
|
47
|
+
var Reorder = (0, import_react.forwardRef)((props, ref) => {
|
|
48
|
+
const [styles, mergedProps] = (0, import_core.useMultiComponentStyle)("Reorder", props);
|
|
49
|
+
const {
|
|
50
|
+
className,
|
|
51
|
+
orientation = "vertical",
|
|
52
|
+
gap = "md",
|
|
53
|
+
onChange,
|
|
54
|
+
onCompleteChange,
|
|
55
|
+
children,
|
|
56
|
+
...rest
|
|
57
|
+
} = (0, import_core.omitThemeProps)(mergedProps);
|
|
58
|
+
const axis = orientation === "vertical" ? "y" : "x";
|
|
59
|
+
const validChildren = (0, import_utils.getValidChildren)(children);
|
|
60
|
+
const defaultValues = (0, import_react.useMemo)(() => {
|
|
61
|
+
const values2 = validChildren.map(({ props: props2 }) => props2.label);
|
|
62
|
+
const duplicatedValues = pickDuplicated(values2);
|
|
63
|
+
if (duplicatedValues.length)
|
|
64
|
+
console.warn(
|
|
65
|
+
`Reorder: 'label' of 'ReorderItem' must not be duplicated. duplicate 'label' is '${duplicatedValues.join(
|
|
66
|
+
`', '`
|
|
67
|
+
)}' `
|
|
68
|
+
);
|
|
69
|
+
return omitDuplicated(values2);
|
|
70
|
+
}, [validChildren]);
|
|
71
|
+
const [values, setValues] = (0, import_react.useState)(defaultValues);
|
|
72
|
+
const onReorder = (0, import_react.useCallback)(
|
|
73
|
+
(newValues) => {
|
|
74
|
+
setValues(newValues);
|
|
75
|
+
onChange == null ? void 0 : onChange(newValues);
|
|
76
|
+
},
|
|
77
|
+
[onChange]
|
|
78
|
+
);
|
|
79
|
+
(0, import_utils.useUpdateEffect)(() => {
|
|
80
|
+
const isDone = defaultValues.every((defaultValue) => values.includes(defaultValue));
|
|
81
|
+
if (isDone)
|
|
82
|
+
return;
|
|
83
|
+
setValues(defaultValues);
|
|
84
|
+
}, [defaultValues]);
|
|
85
|
+
const cloneChildren = (0, import_react.useMemo)(
|
|
86
|
+
() => values.map((value) => validChildren.find(({ props: props2 }) => props2.label === value)),
|
|
87
|
+
[values, validChildren]
|
|
88
|
+
);
|
|
89
|
+
const css = {
|
|
90
|
+
display: "flex",
|
|
91
|
+
flexDirection: orientation === "vertical" ? "column" : "row",
|
|
92
|
+
gap,
|
|
93
|
+
...styles.container
|
|
94
|
+
};
|
|
95
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReorderProvider, { value: { orientation, styles }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
96
|
+
import_core.ui.ul,
|
|
97
|
+
{
|
|
98
|
+
ref,
|
|
99
|
+
as: import_motion.MotionReorder.Group,
|
|
100
|
+
className: (0, import_utils.cx)("ui-reorder", className),
|
|
101
|
+
axis,
|
|
102
|
+
values,
|
|
103
|
+
onReorder,
|
|
104
|
+
__css: css,
|
|
105
|
+
...rest,
|
|
106
|
+
onMouseUp: (0, import_utils.handlerAll)(rest.onMouseUp, () => onCompleteChange == null ? void 0 : onCompleteChange(values)),
|
|
107
|
+
onTouchEnd: (0, import_utils.handlerAll)(rest.onTouchEnd, () => onCompleteChange == null ? void 0 : onCompleteChange(values)),
|
|
108
|
+
children: cloneChildren
|
|
109
|
+
}
|
|
110
|
+
) });
|
|
111
|
+
});
|
|
112
|
+
Reorder.displayName = "Reorder";
|
|
113
|
+
|
|
114
|
+
// src/reorder-item.tsx
|
|
115
|
+
var import_core2 = require("@yamada-ui/core");
|
|
116
|
+
var import_motion2 = require("@yamada-ui/motion");
|
|
117
|
+
var import_utils2 = require("@yamada-ui/utils");
|
|
118
|
+
var import_react2 = require("react");
|
|
119
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
120
|
+
var [ReorderItemProvider, useReorderItemContext] = (0, import_utils2.createContext)({
|
|
121
|
+
name: "ReorderContext",
|
|
122
|
+
errorMessage: `useReorderItemContext returned is 'undefined'. Seems you forgot to wrap the components in "<ReorderItem />"`
|
|
123
|
+
});
|
|
124
|
+
var ReorderItem = (0, import_react2.forwardRef)(
|
|
125
|
+
({ className, label, ...rest }, ref) => {
|
|
126
|
+
var _a;
|
|
127
|
+
const { orientation, styles } = useReorderContext();
|
|
128
|
+
const dragControls = (0, import_motion2.useDragControls)();
|
|
129
|
+
const [hasTrigger, setHasTrigger] = (0, import_react2.useState)(false);
|
|
130
|
+
const [isDrag, setIsDrag] = (0, import_react2.useState)(false);
|
|
131
|
+
const x = (0, import_motion2.useMotionValue)(0);
|
|
132
|
+
const y = (0, import_motion2.useMotionValue)(0);
|
|
133
|
+
const register = (0, import_react2.useCallback)((node) => setHasTrigger(!!node), []);
|
|
134
|
+
(0, import_react2.useEffect)(() => {
|
|
135
|
+
x.onChange((subscription) => {
|
|
136
|
+
if (orientation === "horizontal")
|
|
137
|
+
setIsDrag(subscription !== 0);
|
|
138
|
+
});
|
|
139
|
+
y.onChange((subscription) => {
|
|
140
|
+
if (orientation === "vertical")
|
|
141
|
+
setIsDrag(subscription !== 0);
|
|
142
|
+
});
|
|
143
|
+
return () => {
|
|
144
|
+
x.destroy();
|
|
145
|
+
y.destroy();
|
|
146
|
+
};
|
|
147
|
+
}, [orientation, x, y]);
|
|
148
|
+
const css = {
|
|
149
|
+
...!hasTrigger ? { cursor: "grab" } : { userSelect: "none" },
|
|
150
|
+
...styles.item,
|
|
151
|
+
...!hasTrigger ? { _selected: { ...(_a = styles.item) == null ? void 0 : _a._selected, cursor: "grabbing" } } : {}
|
|
152
|
+
};
|
|
153
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ReorderItemProvider, { value: { register, isDrag, dragControls }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
154
|
+
import_core2.ui.li,
|
|
155
|
+
{
|
|
156
|
+
ref,
|
|
157
|
+
as: import_motion2.MotionReorder.Item,
|
|
158
|
+
className: (0, import_utils2.cx)("ui-reorder-item", className),
|
|
159
|
+
value: label,
|
|
160
|
+
__css: css,
|
|
161
|
+
...rest,
|
|
162
|
+
dragListener: !hasTrigger,
|
|
163
|
+
dragControls,
|
|
164
|
+
"data-selected": (0, import_utils2.dataAttr)(isDrag),
|
|
165
|
+
style: { ...rest.style, x, y }
|
|
166
|
+
}
|
|
167
|
+
) });
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
ReorderItem.displayName = "ReorderItem";
|
|
171
|
+
|
|
172
|
+
// src/reorder-trigger.tsx
|
|
173
|
+
var import_core3 = require("@yamada-ui/core");
|
|
174
|
+
var import_icon = require("@yamada-ui/icon");
|
|
175
|
+
var import_utils3 = require("@yamada-ui/utils");
|
|
176
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
177
|
+
var ReorderTrigger = (0, import_core3.forwardRef)(
|
|
178
|
+
({ className, children = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ReorderTriggerIcon, {}), ...rest }, ref) => {
|
|
179
|
+
const { styles } = useReorderContext();
|
|
180
|
+
const { register, isDrag, dragControls } = useReorderItemContext();
|
|
181
|
+
const css = {
|
|
182
|
+
display: "flex",
|
|
183
|
+
justifyContent: "center",
|
|
184
|
+
alignItems: "center",
|
|
185
|
+
cursor: "grab",
|
|
186
|
+
_selected: {
|
|
187
|
+
cursor: "grabbing"
|
|
188
|
+
},
|
|
189
|
+
...styles.trigger
|
|
190
|
+
};
|
|
191
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
192
|
+
import_core3.ui.div,
|
|
193
|
+
{
|
|
194
|
+
ref: (0, import_utils3.mergeRefs)(register, ref),
|
|
195
|
+
className: (0, import_utils3.cx)("ui-reorder-trigger", className),
|
|
196
|
+
__css: css,
|
|
197
|
+
...rest,
|
|
198
|
+
"data-selected": (0, import_utils3.dataAttr)(isDrag),
|
|
199
|
+
onPointerDown: (0, import_utils3.handlerAll)(rest.onPointerDown, (ev) => dragControls.start(ev)),
|
|
200
|
+
children
|
|
201
|
+
}
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
);
|
|
205
|
+
var ReorderTriggerIcon = (rest) => {
|
|
206
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_icon.Icon, { viewBox: "0 0 39 39", ...rest, children: [
|
|
207
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
208
|
+
"path",
|
|
209
|
+
{
|
|
210
|
+
d: "M 5 0 C 7.761 0 10 2.239 10 5 C 10 7.761 7.761 10 5 10 C 2.239 10 0 7.761 0 5 C 0 2.239 2.239 0 5 0 Z",
|
|
211
|
+
fill: "currentColor"
|
|
212
|
+
}
|
|
213
|
+
),
|
|
214
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
215
|
+
"path",
|
|
216
|
+
{
|
|
217
|
+
d: "M 19 0 C 21.761 0 24 2.239 24 5 C 24 7.761 21.761 10 19 10 C 16.239 10 14 7.761 14 5 C 14 2.239 16.239 0 19 0 Z",
|
|
218
|
+
fill: "currentColor"
|
|
219
|
+
}
|
|
220
|
+
),
|
|
221
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
222
|
+
"path",
|
|
223
|
+
{
|
|
224
|
+
d: "M 33 0 C 35.761 0 38 2.239 38 5 C 38 7.761 35.761 10 33 10 C 30.239 10 28 7.761 28 5 C 28 2.239 30.239 0 33 0 Z",
|
|
225
|
+
fill: "currentColor"
|
|
226
|
+
}
|
|
227
|
+
),
|
|
228
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
229
|
+
"path",
|
|
230
|
+
{
|
|
231
|
+
d: "M 33 14 C 35.761 14 38 16.239 38 19 C 38 21.761 35.761 24 33 24 C 30.239 24 28 21.761 28 19 C 28 16.239 30.239 14 33 14 Z",
|
|
232
|
+
fill: "currentColor"
|
|
233
|
+
}
|
|
234
|
+
),
|
|
235
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
236
|
+
"path",
|
|
237
|
+
{
|
|
238
|
+
d: "M 19 14 C 21.761 14 24 16.239 24 19 C 24 21.761 21.761 24 19 24 C 16.239 24 14 21.761 14 19 C 14 16.239 16.239 14 19 14 Z",
|
|
239
|
+
fill: "currentColor"
|
|
240
|
+
}
|
|
241
|
+
),
|
|
242
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
243
|
+
"path",
|
|
244
|
+
{
|
|
245
|
+
d: "M 5 14 C 7.761 14 10 16.239 10 19 C 10 21.761 7.761 24 5 24 C 2.239 24 0 21.761 0 19 C 0 16.239 2.239 14 5 14 Z",
|
|
246
|
+
fill: "currentColor"
|
|
247
|
+
}
|
|
248
|
+
),
|
|
249
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
250
|
+
"path",
|
|
251
|
+
{
|
|
252
|
+
d: "M 5 28 C 7.761 28 10 30.239 10 33 C 10 35.761 7.761 38 5 38 C 2.239 38 0 35.761 0 33 C 0 30.239 2.239 28 5 28 Z",
|
|
253
|
+
fill: "currentColor"
|
|
254
|
+
}
|
|
255
|
+
),
|
|
256
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
257
|
+
"path",
|
|
258
|
+
{
|
|
259
|
+
d: "M 19 28 C 21.761 28 24 30.239 24 33 C 24 35.761 21.761 38 19 38 C 16.239 38 14 35.761 14 33 C 14 30.239 16.239 28 19 28 Z",
|
|
260
|
+
fill: "currentColor"
|
|
261
|
+
}
|
|
262
|
+
),
|
|
263
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
264
|
+
"path",
|
|
265
|
+
{
|
|
266
|
+
d: "M 33 28 C 35.761 28 38 30.239 38 33 C 38 35.761 35.761 38 33 38 C 30.239 38 28 35.761 28 33 C 28 30.239 30.239 28 33 28 Z",
|
|
267
|
+
fill: "currentColor"
|
|
268
|
+
}
|
|
269
|
+
)
|
|
270
|
+
] });
|
|
271
|
+
};
|
|
272
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
273
|
+
0 && (module.exports = {
|
|
274
|
+
Reorder,
|
|
275
|
+
ReorderItem,
|
|
276
|
+
ReorderItemProvider,
|
|
277
|
+
ReorderProvider,
|
|
278
|
+
ReorderTrigger,
|
|
279
|
+
useReorderContext,
|
|
280
|
+
useReorderItemContext
|
|
281
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ReorderTrigger
|
|
3
|
+
} from "./chunk-6WVUHM4V.mjs";
|
|
4
|
+
import {
|
|
5
|
+
ReorderItem,
|
|
6
|
+
ReorderItemProvider,
|
|
7
|
+
useReorderItemContext
|
|
8
|
+
} from "./chunk-CT62EC32.mjs";
|
|
9
|
+
import {
|
|
10
|
+
Reorder,
|
|
11
|
+
ReorderProvider,
|
|
12
|
+
useReorderContext
|
|
13
|
+
} from "./chunk-UF5QTFGJ.mjs";
|
|
14
|
+
export {
|
|
15
|
+
Reorder,
|
|
16
|
+
ReorderItem,
|
|
17
|
+
ReorderItemProvider,
|
|
18
|
+
ReorderProvider,
|
|
19
|
+
ReorderTrigger,
|
|
20
|
+
useReorderContext,
|
|
21
|
+
useReorderItemContext
|
|
22
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { HTMLUIProps } from '@yamada-ui/core';
|
|
3
|
+
import { HTMLMotionProps, DragControls } from '@yamada-ui/motion';
|
|
4
|
+
|
|
5
|
+
type ReorderItemContext = {
|
|
6
|
+
register: (node: HTMLElement | null) => void;
|
|
7
|
+
isDrag: boolean;
|
|
8
|
+
dragControls: DragControls;
|
|
9
|
+
};
|
|
10
|
+
declare const ReorderItemProvider: react.Provider<ReorderItemContext>;
|
|
11
|
+
declare const useReorderItemContext: () => ReorderItemContext;
|
|
12
|
+
type ReorderItemOptions = {
|
|
13
|
+
label: string | number;
|
|
14
|
+
};
|
|
15
|
+
type ReorderItemProps = Omit<HTMLUIProps<'li'>, 'as'> & Omit<HTMLMotionProps<'li'>, 'as' | 'layout'> & ReorderItemOptions;
|
|
16
|
+
declare const ReorderItem: react.ForwardRefExoticComponent<Omit<HTMLUIProps<"li">, "as"> & Omit<HTMLMotionProps<"li">, "as" | "layout"> & ReorderItemOptions & react.RefAttributes<HTMLLIElement>>;
|
|
17
|
+
|
|
18
|
+
export { ReorderItem, ReorderItemProps, ReorderItemProvider, useReorderItemContext };
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/reorder-item.tsx
|
|
21
|
+
var reorder_item_exports = {};
|
|
22
|
+
__export(reorder_item_exports, {
|
|
23
|
+
ReorderItem: () => ReorderItem,
|
|
24
|
+
ReorderItemProvider: () => ReorderItemProvider,
|
|
25
|
+
useReorderItemContext: () => useReorderItemContext
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(reorder_item_exports);
|
|
28
|
+
var import_core2 = require("@yamada-ui/core");
|
|
29
|
+
var import_motion2 = require("@yamada-ui/motion");
|
|
30
|
+
var import_utils2 = require("@yamada-ui/utils");
|
|
31
|
+
var import_react2 = require("react");
|
|
32
|
+
|
|
33
|
+
// src/reorder.tsx
|
|
34
|
+
var import_core = require("@yamada-ui/core");
|
|
35
|
+
var import_motion = require("@yamada-ui/motion");
|
|
36
|
+
var import_utils = require("@yamada-ui/utils");
|
|
37
|
+
var import_react = require("react");
|
|
38
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
39
|
+
var [ReorderProvider, useReorderContext] = (0, import_utils.createContext)({
|
|
40
|
+
name: "ReorderContext",
|
|
41
|
+
errorMessage: `useReorderContext returned is 'undefined'. Seems you forgot to wrap the components in "<Reorder />"`
|
|
42
|
+
});
|
|
43
|
+
var omitDuplicated = (values) => Array.from(new Set(values));
|
|
44
|
+
var pickDuplicated = (values) => values.filter(
|
|
45
|
+
(value, index, self) => self.indexOf(value) === index && index !== self.lastIndexOf(value)
|
|
46
|
+
);
|
|
47
|
+
var Reorder = (0, import_react.forwardRef)((props, ref) => {
|
|
48
|
+
const [styles, mergedProps] = (0, import_core.useMultiComponentStyle)("Reorder", props);
|
|
49
|
+
const {
|
|
50
|
+
className,
|
|
51
|
+
orientation = "vertical",
|
|
52
|
+
gap = "md",
|
|
53
|
+
onChange,
|
|
54
|
+
onCompleteChange,
|
|
55
|
+
children,
|
|
56
|
+
...rest
|
|
57
|
+
} = (0, import_core.omitThemeProps)(mergedProps);
|
|
58
|
+
const axis = orientation === "vertical" ? "y" : "x";
|
|
59
|
+
const validChildren = (0, import_utils.getValidChildren)(children);
|
|
60
|
+
const defaultValues = (0, import_react.useMemo)(() => {
|
|
61
|
+
const values2 = validChildren.map(({ props: props2 }) => props2.label);
|
|
62
|
+
const duplicatedValues = pickDuplicated(values2);
|
|
63
|
+
if (duplicatedValues.length)
|
|
64
|
+
console.warn(
|
|
65
|
+
`Reorder: 'label' of 'ReorderItem' must not be duplicated. duplicate 'label' is '${duplicatedValues.join(
|
|
66
|
+
`', '`
|
|
67
|
+
)}' `
|
|
68
|
+
);
|
|
69
|
+
return omitDuplicated(values2);
|
|
70
|
+
}, [validChildren]);
|
|
71
|
+
const [values, setValues] = (0, import_react.useState)(defaultValues);
|
|
72
|
+
const onReorder = (0, import_react.useCallback)(
|
|
73
|
+
(newValues) => {
|
|
74
|
+
setValues(newValues);
|
|
75
|
+
onChange == null ? void 0 : onChange(newValues);
|
|
76
|
+
},
|
|
77
|
+
[onChange]
|
|
78
|
+
);
|
|
79
|
+
(0, import_utils.useUpdateEffect)(() => {
|
|
80
|
+
const isDone = defaultValues.every((defaultValue) => values.includes(defaultValue));
|
|
81
|
+
if (isDone)
|
|
82
|
+
return;
|
|
83
|
+
setValues(defaultValues);
|
|
84
|
+
}, [defaultValues]);
|
|
85
|
+
const cloneChildren = (0, import_react.useMemo)(
|
|
86
|
+
() => values.map((value) => validChildren.find(({ props: props2 }) => props2.label === value)),
|
|
87
|
+
[values, validChildren]
|
|
88
|
+
);
|
|
89
|
+
const css = {
|
|
90
|
+
display: "flex",
|
|
91
|
+
flexDirection: orientation === "vertical" ? "column" : "row",
|
|
92
|
+
gap,
|
|
93
|
+
...styles.container
|
|
94
|
+
};
|
|
95
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReorderProvider, { value: { orientation, styles }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
96
|
+
import_core.ui.ul,
|
|
97
|
+
{
|
|
98
|
+
ref,
|
|
99
|
+
as: import_motion.MotionReorder.Group,
|
|
100
|
+
className: (0, import_utils.cx)("ui-reorder", className),
|
|
101
|
+
axis,
|
|
102
|
+
values,
|
|
103
|
+
onReorder,
|
|
104
|
+
__css: css,
|
|
105
|
+
...rest,
|
|
106
|
+
onMouseUp: (0, import_utils.handlerAll)(rest.onMouseUp, () => onCompleteChange == null ? void 0 : onCompleteChange(values)),
|
|
107
|
+
onTouchEnd: (0, import_utils.handlerAll)(rest.onTouchEnd, () => onCompleteChange == null ? void 0 : onCompleteChange(values)),
|
|
108
|
+
children: cloneChildren
|
|
109
|
+
}
|
|
110
|
+
) });
|
|
111
|
+
});
|
|
112
|
+
Reorder.displayName = "Reorder";
|
|
113
|
+
|
|
114
|
+
// src/reorder-item.tsx
|
|
115
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
116
|
+
var [ReorderItemProvider, useReorderItemContext] = (0, import_utils2.createContext)({
|
|
117
|
+
name: "ReorderContext",
|
|
118
|
+
errorMessage: `useReorderItemContext returned is 'undefined'. Seems you forgot to wrap the components in "<ReorderItem />"`
|
|
119
|
+
});
|
|
120
|
+
var ReorderItem = (0, import_react2.forwardRef)(
|
|
121
|
+
({ className, label, ...rest }, ref) => {
|
|
122
|
+
var _a;
|
|
123
|
+
const { orientation, styles } = useReorderContext();
|
|
124
|
+
const dragControls = (0, import_motion2.useDragControls)();
|
|
125
|
+
const [hasTrigger, setHasTrigger] = (0, import_react2.useState)(false);
|
|
126
|
+
const [isDrag, setIsDrag] = (0, import_react2.useState)(false);
|
|
127
|
+
const x = (0, import_motion2.useMotionValue)(0);
|
|
128
|
+
const y = (0, import_motion2.useMotionValue)(0);
|
|
129
|
+
const register = (0, import_react2.useCallback)((node) => setHasTrigger(!!node), []);
|
|
130
|
+
(0, import_react2.useEffect)(() => {
|
|
131
|
+
x.onChange((subscription) => {
|
|
132
|
+
if (orientation === "horizontal")
|
|
133
|
+
setIsDrag(subscription !== 0);
|
|
134
|
+
});
|
|
135
|
+
y.onChange((subscription) => {
|
|
136
|
+
if (orientation === "vertical")
|
|
137
|
+
setIsDrag(subscription !== 0);
|
|
138
|
+
});
|
|
139
|
+
return () => {
|
|
140
|
+
x.destroy();
|
|
141
|
+
y.destroy();
|
|
142
|
+
};
|
|
143
|
+
}, [orientation, x, y]);
|
|
144
|
+
const css = {
|
|
145
|
+
...!hasTrigger ? { cursor: "grab" } : { userSelect: "none" },
|
|
146
|
+
...styles.item,
|
|
147
|
+
...!hasTrigger ? { _selected: { ...(_a = styles.item) == null ? void 0 : _a._selected, cursor: "grabbing" } } : {}
|
|
148
|
+
};
|
|
149
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ReorderItemProvider, { value: { register, isDrag, dragControls }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
150
|
+
import_core2.ui.li,
|
|
151
|
+
{
|
|
152
|
+
ref,
|
|
153
|
+
as: import_motion2.MotionReorder.Item,
|
|
154
|
+
className: (0, import_utils2.cx)("ui-reorder-item", className),
|
|
155
|
+
value: label,
|
|
156
|
+
__css: css,
|
|
157
|
+
...rest,
|
|
158
|
+
dragListener: !hasTrigger,
|
|
159
|
+
dragControls,
|
|
160
|
+
"data-selected": (0, import_utils2.dataAttr)(isDrag),
|
|
161
|
+
style: { ...rest.style, x, y }
|
|
162
|
+
}
|
|
163
|
+
) });
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
ReorderItem.displayName = "ReorderItem";
|
|
167
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
168
|
+
0 && (module.exports = {
|
|
169
|
+
ReorderItem,
|
|
170
|
+
ReorderItemProvider,
|
|
171
|
+
useReorderItemContext
|
|
172
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as _yamada_ui_core from '@yamada-ui/core';
|
|
2
|
+
import { HTMLUIProps } from '@yamada-ui/core';
|
|
3
|
+
|
|
4
|
+
type ReorderTriggerProps = HTMLUIProps<'div'>;
|
|
5
|
+
declare const ReorderTrigger: _yamada_ui_core.Component<"div", ReorderTriggerProps>;
|
|
6
|
+
|
|
7
|
+
export { ReorderTrigger, ReorderTriggerProps };
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/reorder-trigger.tsx
|
|
21
|
+
var reorder_trigger_exports = {};
|
|
22
|
+
__export(reorder_trigger_exports, {
|
|
23
|
+
ReorderTrigger: () => ReorderTrigger
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(reorder_trigger_exports);
|
|
26
|
+
var import_core3 = require("@yamada-ui/core");
|
|
27
|
+
var import_icon = require("@yamada-ui/icon");
|
|
28
|
+
var import_utils3 = require("@yamada-ui/utils");
|
|
29
|
+
|
|
30
|
+
// src/reorder.tsx
|
|
31
|
+
var import_core = require("@yamada-ui/core");
|
|
32
|
+
var import_motion = require("@yamada-ui/motion");
|
|
33
|
+
var import_utils = require("@yamada-ui/utils");
|
|
34
|
+
var import_react = require("react");
|
|
35
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
36
|
+
var [ReorderProvider, useReorderContext] = (0, import_utils.createContext)({
|
|
37
|
+
name: "ReorderContext",
|
|
38
|
+
errorMessage: `useReorderContext returned is 'undefined'. Seems you forgot to wrap the components in "<Reorder />"`
|
|
39
|
+
});
|
|
40
|
+
var omitDuplicated = (values) => Array.from(new Set(values));
|
|
41
|
+
var pickDuplicated = (values) => values.filter(
|
|
42
|
+
(value, index, self) => self.indexOf(value) === index && index !== self.lastIndexOf(value)
|
|
43
|
+
);
|
|
44
|
+
var Reorder = (0, import_react.forwardRef)((props, ref) => {
|
|
45
|
+
const [styles, mergedProps] = (0, import_core.useMultiComponentStyle)("Reorder", props);
|
|
46
|
+
const {
|
|
47
|
+
className,
|
|
48
|
+
orientation = "vertical",
|
|
49
|
+
gap = "md",
|
|
50
|
+
onChange,
|
|
51
|
+
onCompleteChange,
|
|
52
|
+
children,
|
|
53
|
+
...rest
|
|
54
|
+
} = (0, import_core.omitThemeProps)(mergedProps);
|
|
55
|
+
const axis = orientation === "vertical" ? "y" : "x";
|
|
56
|
+
const validChildren = (0, import_utils.getValidChildren)(children);
|
|
57
|
+
const defaultValues = (0, import_react.useMemo)(() => {
|
|
58
|
+
const values2 = validChildren.map(({ props: props2 }) => props2.label);
|
|
59
|
+
const duplicatedValues = pickDuplicated(values2);
|
|
60
|
+
if (duplicatedValues.length)
|
|
61
|
+
console.warn(
|
|
62
|
+
`Reorder: 'label' of 'ReorderItem' must not be duplicated. duplicate 'label' is '${duplicatedValues.join(
|
|
63
|
+
`', '`
|
|
64
|
+
)}' `
|
|
65
|
+
);
|
|
66
|
+
return omitDuplicated(values2);
|
|
67
|
+
}, [validChildren]);
|
|
68
|
+
const [values, setValues] = (0, import_react.useState)(defaultValues);
|
|
69
|
+
const onReorder = (0, import_react.useCallback)(
|
|
70
|
+
(newValues) => {
|
|
71
|
+
setValues(newValues);
|
|
72
|
+
onChange == null ? void 0 : onChange(newValues);
|
|
73
|
+
},
|
|
74
|
+
[onChange]
|
|
75
|
+
);
|
|
76
|
+
(0, import_utils.useUpdateEffect)(() => {
|
|
77
|
+
const isDone = defaultValues.every((defaultValue) => values.includes(defaultValue));
|
|
78
|
+
if (isDone)
|
|
79
|
+
return;
|
|
80
|
+
setValues(defaultValues);
|
|
81
|
+
}, [defaultValues]);
|
|
82
|
+
const cloneChildren = (0, import_react.useMemo)(
|
|
83
|
+
() => values.map((value) => validChildren.find(({ props: props2 }) => props2.label === value)),
|
|
84
|
+
[values, validChildren]
|
|
85
|
+
);
|
|
86
|
+
const css = {
|
|
87
|
+
display: "flex",
|
|
88
|
+
flexDirection: orientation === "vertical" ? "column" : "row",
|
|
89
|
+
gap,
|
|
90
|
+
...styles.container
|
|
91
|
+
};
|
|
92
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReorderProvider, { value: { orientation, styles }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
93
|
+
import_core.ui.ul,
|
|
94
|
+
{
|
|
95
|
+
ref,
|
|
96
|
+
as: import_motion.MotionReorder.Group,
|
|
97
|
+
className: (0, import_utils.cx)("ui-reorder", className),
|
|
98
|
+
axis,
|
|
99
|
+
values,
|
|
100
|
+
onReorder,
|
|
101
|
+
__css: css,
|
|
102
|
+
...rest,
|
|
103
|
+
onMouseUp: (0, import_utils.handlerAll)(rest.onMouseUp, () => onCompleteChange == null ? void 0 : onCompleteChange(values)),
|
|
104
|
+
onTouchEnd: (0, import_utils.handlerAll)(rest.onTouchEnd, () => onCompleteChange == null ? void 0 : onCompleteChange(values)),
|
|
105
|
+
children: cloneChildren
|
|
106
|
+
}
|
|
107
|
+
) });
|
|
108
|
+
});
|
|
109
|
+
Reorder.displayName = "Reorder";
|
|
110
|
+
|
|
111
|
+
// src/reorder-item.tsx
|
|
112
|
+
var import_core2 = require("@yamada-ui/core");
|
|
113
|
+
var import_motion2 = require("@yamada-ui/motion");
|
|
114
|
+
var import_utils2 = require("@yamada-ui/utils");
|
|
115
|
+
var import_react2 = require("react");
|
|
116
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
117
|
+
var [ReorderItemProvider, useReorderItemContext] = (0, import_utils2.createContext)({
|
|
118
|
+
name: "ReorderContext",
|
|
119
|
+
errorMessage: `useReorderItemContext returned is 'undefined'. Seems you forgot to wrap the components in "<ReorderItem />"`
|
|
120
|
+
});
|
|
121
|
+
var ReorderItem = (0, import_react2.forwardRef)(
|
|
122
|
+
({ className, label, ...rest }, ref) => {
|
|
123
|
+
var _a;
|
|
124
|
+
const { orientation, styles } = useReorderContext();
|
|
125
|
+
const dragControls = (0, import_motion2.useDragControls)();
|
|
126
|
+
const [hasTrigger, setHasTrigger] = (0, import_react2.useState)(false);
|
|
127
|
+
const [isDrag, setIsDrag] = (0, import_react2.useState)(false);
|
|
128
|
+
const x = (0, import_motion2.useMotionValue)(0);
|
|
129
|
+
const y = (0, import_motion2.useMotionValue)(0);
|
|
130
|
+
const register = (0, import_react2.useCallback)((node) => setHasTrigger(!!node), []);
|
|
131
|
+
(0, import_react2.useEffect)(() => {
|
|
132
|
+
x.onChange((subscription) => {
|
|
133
|
+
if (orientation === "horizontal")
|
|
134
|
+
setIsDrag(subscription !== 0);
|
|
135
|
+
});
|
|
136
|
+
y.onChange((subscription) => {
|
|
137
|
+
if (orientation === "vertical")
|
|
138
|
+
setIsDrag(subscription !== 0);
|
|
139
|
+
});
|
|
140
|
+
return () => {
|
|
141
|
+
x.destroy();
|
|
142
|
+
y.destroy();
|
|
143
|
+
};
|
|
144
|
+
}, [orientation, x, y]);
|
|
145
|
+
const css = {
|
|
146
|
+
...!hasTrigger ? { cursor: "grab" } : { userSelect: "none" },
|
|
147
|
+
...styles.item,
|
|
148
|
+
...!hasTrigger ? { _selected: { ...(_a = styles.item) == null ? void 0 : _a._selected, cursor: "grabbing" } } : {}
|
|
149
|
+
};
|
|
150
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ReorderItemProvider, { value: { register, isDrag, dragControls }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
151
|
+
import_core2.ui.li,
|
|
152
|
+
{
|
|
153
|
+
ref,
|
|
154
|
+
as: import_motion2.MotionReorder.Item,
|
|
155
|
+
className: (0, import_utils2.cx)("ui-reorder-item", className),
|
|
156
|
+
value: label,
|
|
157
|
+
__css: css,
|
|
158
|
+
...rest,
|
|
159
|
+
dragListener: !hasTrigger,
|
|
160
|
+
dragControls,
|
|
161
|
+
"data-selected": (0, import_utils2.dataAttr)(isDrag),
|
|
162
|
+
style: { ...rest.style, x, y }
|
|
163
|
+
}
|
|
164
|
+
) });
|
|
165
|
+
}
|
|
166
|
+
);
|
|
167
|
+
ReorderItem.displayName = "ReorderItem";
|
|
168
|
+
|
|
169
|
+
// src/reorder-trigger.tsx
|
|
170
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
171
|
+
var ReorderTrigger = (0, import_core3.forwardRef)(
|
|
172
|
+
({ className, children = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ReorderTriggerIcon, {}), ...rest }, ref) => {
|
|
173
|
+
const { styles } = useReorderContext();
|
|
174
|
+
const { register, isDrag, dragControls } = useReorderItemContext();
|
|
175
|
+
const css = {
|
|
176
|
+
display: "flex",
|
|
177
|
+
justifyContent: "center",
|
|
178
|
+
alignItems: "center",
|
|
179
|
+
cursor: "grab",
|
|
180
|
+
_selected: {
|
|
181
|
+
cursor: "grabbing"
|
|
182
|
+
},
|
|
183
|
+
...styles.trigger
|
|
184
|
+
};
|
|
185
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
186
|
+
import_core3.ui.div,
|
|
187
|
+
{
|
|
188
|
+
ref: (0, import_utils3.mergeRefs)(register, ref),
|
|
189
|
+
className: (0, import_utils3.cx)("ui-reorder-trigger", className),
|
|
190
|
+
__css: css,
|
|
191
|
+
...rest,
|
|
192
|
+
"data-selected": (0, import_utils3.dataAttr)(isDrag),
|
|
193
|
+
onPointerDown: (0, import_utils3.handlerAll)(rest.onPointerDown, (ev) => dragControls.start(ev)),
|
|
194
|
+
children
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
);
|
|
199
|
+
var ReorderTriggerIcon = (rest) => {
|
|
200
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_icon.Icon, { viewBox: "0 0 39 39", ...rest, children: [
|
|
201
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
202
|
+
"path",
|
|
203
|
+
{
|
|
204
|
+
d: "M 5 0 C 7.761 0 10 2.239 10 5 C 10 7.761 7.761 10 5 10 C 2.239 10 0 7.761 0 5 C 0 2.239 2.239 0 5 0 Z",
|
|
205
|
+
fill: "currentColor"
|
|
206
|
+
}
|
|
207
|
+
),
|
|
208
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
209
|
+
"path",
|
|
210
|
+
{
|
|
211
|
+
d: "M 19 0 C 21.761 0 24 2.239 24 5 C 24 7.761 21.761 10 19 10 C 16.239 10 14 7.761 14 5 C 14 2.239 16.239 0 19 0 Z",
|
|
212
|
+
fill: "currentColor"
|
|
213
|
+
}
|
|
214
|
+
),
|
|
215
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
216
|
+
"path",
|
|
217
|
+
{
|
|
218
|
+
d: "M 33 0 C 35.761 0 38 2.239 38 5 C 38 7.761 35.761 10 33 10 C 30.239 10 28 7.761 28 5 C 28 2.239 30.239 0 33 0 Z",
|
|
219
|
+
fill: "currentColor"
|
|
220
|
+
}
|
|
221
|
+
),
|
|
222
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
223
|
+
"path",
|
|
224
|
+
{
|
|
225
|
+
d: "M 33 14 C 35.761 14 38 16.239 38 19 C 38 21.761 35.761 24 33 24 C 30.239 24 28 21.761 28 19 C 28 16.239 30.239 14 33 14 Z",
|
|
226
|
+
fill: "currentColor"
|
|
227
|
+
}
|
|
228
|
+
),
|
|
229
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
230
|
+
"path",
|
|
231
|
+
{
|
|
232
|
+
d: "M 19 14 C 21.761 14 24 16.239 24 19 C 24 21.761 21.761 24 19 24 C 16.239 24 14 21.761 14 19 C 14 16.239 16.239 14 19 14 Z",
|
|
233
|
+
fill: "currentColor"
|
|
234
|
+
}
|
|
235
|
+
),
|
|
236
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
237
|
+
"path",
|
|
238
|
+
{
|
|
239
|
+
d: "M 5 14 C 7.761 14 10 16.239 10 19 C 10 21.761 7.761 24 5 24 C 2.239 24 0 21.761 0 19 C 0 16.239 2.239 14 5 14 Z",
|
|
240
|
+
fill: "currentColor"
|
|
241
|
+
}
|
|
242
|
+
),
|
|
243
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
244
|
+
"path",
|
|
245
|
+
{
|
|
246
|
+
d: "M 5 28 C 7.761 28 10 30.239 10 33 C 10 35.761 7.761 38 5 38 C 2.239 38 0 35.761 0 33 C 0 30.239 2.239 28 5 28 Z",
|
|
247
|
+
fill: "currentColor"
|
|
248
|
+
}
|
|
249
|
+
),
|
|
250
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
251
|
+
"path",
|
|
252
|
+
{
|
|
253
|
+
d: "M 19 28 C 21.761 28 24 30.239 24 33 C 24 35.761 21.761 38 19 38 C 16.239 38 14 35.761 14 33 C 14 30.239 16.239 28 19 28 Z",
|
|
254
|
+
fill: "currentColor"
|
|
255
|
+
}
|
|
256
|
+
),
|
|
257
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
258
|
+
"path",
|
|
259
|
+
{
|
|
260
|
+
d: "M 33 28 C 35.761 28 38 30.239 38 33 C 38 35.761 35.761 38 33 38 C 30.239 38 28 35.761 28 33 C 28 30.239 30.239 28 33 28 Z",
|
|
261
|
+
fill: "currentColor"
|
|
262
|
+
}
|
|
263
|
+
)
|
|
264
|
+
] });
|
|
265
|
+
};
|
|
266
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
267
|
+
0 && (module.exports = {
|
|
268
|
+
ReorderTrigger
|
|
269
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { HTMLUIProps, ThemeProps, CSSUIObject } from '@yamada-ui/core';
|
|
3
|
+
import { HTMLMotionProps } from '@yamada-ui/motion';
|
|
4
|
+
|
|
5
|
+
type Orientation = 'vertical' | 'horizontal';
|
|
6
|
+
type ReorderContext = {
|
|
7
|
+
orientation: Orientation;
|
|
8
|
+
styles: Record<string, CSSUIObject>;
|
|
9
|
+
};
|
|
10
|
+
declare const ReorderProvider: react.Provider<ReorderContext>;
|
|
11
|
+
declare const useReorderContext: () => ReorderContext;
|
|
12
|
+
type ReorderOptions = {
|
|
13
|
+
orientation?: Orientation;
|
|
14
|
+
onChange?: (labels: (string | number)[]) => void;
|
|
15
|
+
onCompleteChange?: (labels: (string | number)[]) => void;
|
|
16
|
+
};
|
|
17
|
+
type ReorderProps = Omit<HTMLUIProps<'ul'>, 'as' | 'onChange'> & Omit<HTMLMotionProps<'ul'>, 'as' | 'onChange'> & ThemeProps<'Reorder'> & ReorderOptions;
|
|
18
|
+
declare const Reorder: react.ForwardRefExoticComponent<Omit<HTMLUIProps<"ul">, "as" | "onChange"> & Omit<HTMLMotionProps<"ul">, "as" | "onChange"> & ThemeProps<"Reorder"> & ReorderOptions & react.RefAttributes<HTMLUListElement>>;
|
|
19
|
+
|
|
20
|
+
export { Reorder, ReorderProps, ReorderProvider, useReorderContext };
|
package/dist/reorder.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/reorder.tsx
|
|
21
|
+
var reorder_exports = {};
|
|
22
|
+
__export(reorder_exports, {
|
|
23
|
+
Reorder: () => Reorder,
|
|
24
|
+
ReorderProvider: () => ReorderProvider,
|
|
25
|
+
useReorderContext: () => useReorderContext
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(reorder_exports);
|
|
28
|
+
var import_core = require("@yamada-ui/core");
|
|
29
|
+
var import_motion = require("@yamada-ui/motion");
|
|
30
|
+
var import_utils = require("@yamada-ui/utils");
|
|
31
|
+
var import_react = require("react");
|
|
32
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
33
|
+
var [ReorderProvider, useReorderContext] = (0, import_utils.createContext)({
|
|
34
|
+
name: "ReorderContext",
|
|
35
|
+
errorMessage: `useReorderContext returned is 'undefined'. Seems you forgot to wrap the components in "<Reorder />"`
|
|
36
|
+
});
|
|
37
|
+
var omitDuplicated = (values) => Array.from(new Set(values));
|
|
38
|
+
var pickDuplicated = (values) => values.filter(
|
|
39
|
+
(value, index, self) => self.indexOf(value) === index && index !== self.lastIndexOf(value)
|
|
40
|
+
);
|
|
41
|
+
var Reorder = (0, import_react.forwardRef)((props, ref) => {
|
|
42
|
+
const [styles, mergedProps] = (0, import_core.useMultiComponentStyle)("Reorder", props);
|
|
43
|
+
const {
|
|
44
|
+
className,
|
|
45
|
+
orientation = "vertical",
|
|
46
|
+
gap = "md",
|
|
47
|
+
onChange,
|
|
48
|
+
onCompleteChange,
|
|
49
|
+
children,
|
|
50
|
+
...rest
|
|
51
|
+
} = (0, import_core.omitThemeProps)(mergedProps);
|
|
52
|
+
const axis = orientation === "vertical" ? "y" : "x";
|
|
53
|
+
const validChildren = (0, import_utils.getValidChildren)(children);
|
|
54
|
+
const defaultValues = (0, import_react.useMemo)(() => {
|
|
55
|
+
const values2 = validChildren.map(({ props: props2 }) => props2.label);
|
|
56
|
+
const duplicatedValues = pickDuplicated(values2);
|
|
57
|
+
if (duplicatedValues.length)
|
|
58
|
+
console.warn(
|
|
59
|
+
`Reorder: 'label' of 'ReorderItem' must not be duplicated. duplicate 'label' is '${duplicatedValues.join(
|
|
60
|
+
`', '`
|
|
61
|
+
)}' `
|
|
62
|
+
);
|
|
63
|
+
return omitDuplicated(values2);
|
|
64
|
+
}, [validChildren]);
|
|
65
|
+
const [values, setValues] = (0, import_react.useState)(defaultValues);
|
|
66
|
+
const onReorder = (0, import_react.useCallback)(
|
|
67
|
+
(newValues) => {
|
|
68
|
+
setValues(newValues);
|
|
69
|
+
onChange == null ? void 0 : onChange(newValues);
|
|
70
|
+
},
|
|
71
|
+
[onChange]
|
|
72
|
+
);
|
|
73
|
+
(0, import_utils.useUpdateEffect)(() => {
|
|
74
|
+
const isDone = defaultValues.every((defaultValue) => values.includes(defaultValue));
|
|
75
|
+
if (isDone)
|
|
76
|
+
return;
|
|
77
|
+
setValues(defaultValues);
|
|
78
|
+
}, [defaultValues]);
|
|
79
|
+
const cloneChildren = (0, import_react.useMemo)(
|
|
80
|
+
() => values.map((value) => validChildren.find(({ props: props2 }) => props2.label === value)),
|
|
81
|
+
[values, validChildren]
|
|
82
|
+
);
|
|
83
|
+
const css = {
|
|
84
|
+
display: "flex",
|
|
85
|
+
flexDirection: orientation === "vertical" ? "column" : "row",
|
|
86
|
+
gap,
|
|
87
|
+
...styles.container
|
|
88
|
+
};
|
|
89
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReorderProvider, { value: { orientation, styles }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
90
|
+
import_core.ui.ul,
|
|
91
|
+
{
|
|
92
|
+
ref,
|
|
93
|
+
as: import_motion.MotionReorder.Group,
|
|
94
|
+
className: (0, import_utils.cx)("ui-reorder", className),
|
|
95
|
+
axis,
|
|
96
|
+
values,
|
|
97
|
+
onReorder,
|
|
98
|
+
__css: css,
|
|
99
|
+
...rest,
|
|
100
|
+
onMouseUp: (0, import_utils.handlerAll)(rest.onMouseUp, () => onCompleteChange == null ? void 0 : onCompleteChange(values)),
|
|
101
|
+
onTouchEnd: (0, import_utils.handlerAll)(rest.onTouchEnd, () => onCompleteChange == null ? void 0 : onCompleteChange(values)),
|
|
102
|
+
children: cloneChildren
|
|
103
|
+
}
|
|
104
|
+
) });
|
|
105
|
+
});
|
|
106
|
+
Reorder.displayName = "Reorder";
|
|
107
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
+
0 && (module.exports = {
|
|
109
|
+
Reorder,
|
|
110
|
+
ReorderProvider,
|
|
111
|
+
useReorderContext
|
|
112
|
+
});
|
package/dist/reorder.mjs
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yamada-ui/reorder",
|
|
3
|
+
"version": "0.0.0-dev-20230603042803",
|
|
4
|
+
"description": "Yamada UI reorder component",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"yamada",
|
|
7
|
+
"yamada ui",
|
|
8
|
+
"react",
|
|
9
|
+
"emotion",
|
|
10
|
+
"component",
|
|
11
|
+
"reorder",
|
|
12
|
+
"ui",
|
|
13
|
+
"uikit",
|
|
14
|
+
"styled",
|
|
15
|
+
"style-props",
|
|
16
|
+
"styled-component",
|
|
17
|
+
"css-in-js"
|
|
18
|
+
],
|
|
19
|
+
"author": "Hirotomo Yamada <hirotomo.yamada@avap.co.jp>",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"main": "dist/index.js",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/hirotomoyamada/yamada-ui",
|
|
32
|
+
"directory": "packages/components/reorder"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/hirotomoyamada/yamada-ui/issues"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@yamada-ui/core": "0.0.0-dev-20230603042803",
|
|
39
|
+
"@yamada-ui/utils": "0.1.0",
|
|
40
|
+
"@yamada-ui/motion": "0.0.0-dev-20230603042803",
|
|
41
|
+
"@yamada-ui/icon": "0.0.0-dev-20230603042803"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"react": "^18.0.0",
|
|
45
|
+
"clean-package": "2.2.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"react": ">=18"
|
|
49
|
+
},
|
|
50
|
+
"clean-package": "../../../clean-package.config.json",
|
|
51
|
+
"tsup": {
|
|
52
|
+
"clean": true,
|
|
53
|
+
"target": "es2019",
|
|
54
|
+
"format": [
|
|
55
|
+
"cjs",
|
|
56
|
+
"esm"
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
"module": "dist/index.mjs",
|
|
60
|
+
"types": "dist/index.d.ts",
|
|
61
|
+
"exports": {
|
|
62
|
+
".": {
|
|
63
|
+
"types": "./dist/index.d.ts",
|
|
64
|
+
"import": "./dist/index.mjs",
|
|
65
|
+
"require": "./dist/index.js"
|
|
66
|
+
},
|
|
67
|
+
"./package.json": "./package.json"
|
|
68
|
+
},
|
|
69
|
+
"scripts": {
|
|
70
|
+
"dev": "pnpm build:fast -- --watch",
|
|
71
|
+
"build": "tsup src --dts",
|
|
72
|
+
"build:fast": "tsup src",
|
|
73
|
+
"clean": "rimraf dist .turbo",
|
|
74
|
+
"typecheck": "tsc --noEmit",
|
|
75
|
+
"gen:docs": "tsx ../../../scripts/generate-docs"
|
|
76
|
+
}
|
|
77
|
+
}
|