@yamada-ui/reorder 2.0.9 → 2.0.10-dev-20240917033401

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.
@@ -0,0 +1,46 @@
1
+ "use client"
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/reorder-context.ts
22
+ var reorder_context_exports = {};
23
+ __export(reorder_context_exports, {
24
+ ReorderItemProvider: () => ReorderItemProvider,
25
+ ReorderProvider: () => ReorderProvider,
26
+ useReorderContext: () => useReorderContext,
27
+ useReorderItemContext: () => useReorderItemContext
28
+ });
29
+ module.exports = __toCommonJS(reorder_context_exports);
30
+ var import_utils = require("@yamada-ui/utils");
31
+ var [ReorderProvider, useReorderContext] = (0, import_utils.createContext)({
32
+ name: "ReorderContext",
33
+ errorMessage: `useReorderContext returned is 'undefined'. Seems you forgot to wrap the components in "<Reorder />"`
34
+ });
35
+ var [ReorderItemProvider, useReorderItemContext] = (0, import_utils.createContext)({
36
+ name: "ReorderContext",
37
+ errorMessage: `useReorderItemContext returned is 'undefined'. Seems you forgot to wrap the components in "<ReorderItem />"`
38
+ });
39
+ // Annotate the CommonJS export names for ESM import in node:
40
+ 0 && (module.exports = {
41
+ ReorderItemProvider,
42
+ ReorderProvider,
43
+ useReorderContext,
44
+ useReorderItemContext
45
+ });
46
+ //# sourceMappingURL=reorder-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/reorder-context.ts"],"sourcesContent":["import type { CSSUIObject } from \"@yamada-ui/core\"\nimport type { DragControls } from \"@yamada-ui/motion\"\nimport { createContext } from \"@yamada-ui/utils\"\n\ninterface ReorderContext {\n orientation: \"vertical\" | \"horizontal\"\n styles: { [key: string]: CSSUIObject }\n}\n\nexport const [ReorderProvider, useReorderContext] =\n createContext<ReorderContext>({\n name: \"ReorderContext\",\n errorMessage: `useReorderContext returned is 'undefined'. Seems you forgot to wrap the components in \"<Reorder />\"`,\n })\n\ninterface ReorderItemContext {\n register: (node: HTMLElement | null) => void\n isDrag: boolean\n dragControls: DragControls\n}\n\nexport const [ReorderItemProvider, useReorderItemContext] =\n createContext<ReorderItemContext>({\n name: \"ReorderContext\",\n errorMessage: `useReorderItemContext returned is 'undefined'. Seems you forgot to wrap the components in \"<ReorderItem />\"`,\n })\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA8B;AAOvB,IAAM,CAAC,iBAAiB,iBAAiB,QAC9C,4BAA8B;AAAA,EAC5B,MAAM;AAAA,EACN,cAAc;AAChB,CAAC;AAQI,IAAM,CAAC,qBAAqB,qBAAqB,QACtD,4BAAkC;AAAA,EAChC,MAAM;AAAA,EACN,cAAc;AAChB,CAAC;","names":[]}
@@ -0,0 +1,14 @@
1
+ "use client"
2
+ import {
3
+ ReorderItemProvider,
4
+ ReorderProvider,
5
+ useReorderContext,
6
+ useReorderItemContext
7
+ } from "./chunk-BBGHU5EB.mjs";
8
+ export {
9
+ ReorderItemProvider,
10
+ ReorderProvider,
11
+ useReorderContext,
12
+ useReorderItemContext
13
+ };
14
+ //# sourceMappingURL=reorder-context.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,17 +1,9 @@
1
- import * as react from 'react';
2
- import { PropsWithChildren, ForwardedRef, ReactNode } from 'react';
3
1
  import { HTMLUIProps, ComponentArgs } from '@yamada-ui/core';
4
- import { HTMLMotionProps, DragControls } from '@yamada-ui/motion';
2
+ import { HTMLMotionProps } from '@yamada-ui/motion';
5
3
  import { Merge } from '@yamada-ui/utils';
4
+ import { PropsWithChildren, RefAttributes, ReactNode } from 'react';
6
5
 
7
- type ReorderItemContext = {
8
- register: (node: HTMLElement | null) => void;
9
- isDrag: boolean;
10
- dragControls: DragControls;
11
- };
12
- declare const ReorderItemProvider: react.Provider<ReorderItemContext>;
13
- declare const useReorderItemContext: () => ReorderItemContext;
14
- type ReorderItemOptions<Y extends any = string> = {
6
+ interface ReorderItemOptions<Y extends any = string> {
15
7
  /**
16
8
  * The label of the reorder item.
17
9
  */
@@ -20,12 +12,11 @@ type ReorderItemOptions<Y extends any = string> = {
20
12
  * The value of the reorder item.
21
13
  */
22
14
  value: Y;
23
- };
24
- type ReorderItemProps<Y extends any = string> = Omit<Merge<HTMLUIProps<"li">, HTMLMotionProps<"li">>, "value" | "transition" | "children"> & PropsWithChildren & ReorderItemOptions<Y>;
15
+ }
16
+ interface ReorderItemProps<Y extends any = string> extends Omit<Merge<HTMLUIProps<"li">, HTMLMotionProps<"li">>, "value" | "transition" | "children">, PropsWithChildren, ReorderItemOptions<Y> {
17
+ }
25
18
  declare const ReorderItem: {
26
- <Y extends any = string>(props: ReorderItemProps<Y> & {
27
- ref?: ForwardedRef<HTMLLIElement>;
28
- }): JSX.Element;
19
+ <Y = string>(props: ReorderItemProps<Y> & RefAttributes<HTMLLIElement>): JSX.Element;
29
20
  } & ComponentArgs;
30
21
 
31
- export { ReorderItem, type ReorderItemProps, ReorderItemProvider, useReorderItemContext };
22
+ export { ReorderItem, type ReorderItemProps };
@@ -1,17 +1,9 @@
1
- import * as react from 'react';
2
- import { PropsWithChildren, ForwardedRef, ReactNode } from 'react';
3
1
  import { HTMLUIProps, ComponentArgs } from '@yamada-ui/core';
4
- import { HTMLMotionProps, DragControls } from '@yamada-ui/motion';
2
+ import { HTMLMotionProps } from '@yamada-ui/motion';
5
3
  import { Merge } from '@yamada-ui/utils';
4
+ import { PropsWithChildren, RefAttributes, ReactNode } from 'react';
6
5
 
7
- type ReorderItemContext = {
8
- register: (node: HTMLElement | null) => void;
9
- isDrag: boolean;
10
- dragControls: DragControls;
11
- };
12
- declare const ReorderItemProvider: react.Provider<ReorderItemContext>;
13
- declare const useReorderItemContext: () => ReorderItemContext;
14
- type ReorderItemOptions<Y extends any = string> = {
6
+ interface ReorderItemOptions<Y extends any = string> {
15
7
  /**
16
8
  * The label of the reorder item.
17
9
  */
@@ -20,12 +12,11 @@ type ReorderItemOptions<Y extends any = string> = {
20
12
  * The value of the reorder item.
21
13
  */
22
14
  value: Y;
23
- };
24
- type ReorderItemProps<Y extends any = string> = Omit<Merge<HTMLUIProps<"li">, HTMLMotionProps<"li">>, "value" | "transition" | "children"> & PropsWithChildren & ReorderItemOptions<Y>;
15
+ }
16
+ interface ReorderItemProps<Y extends any = string> extends Omit<Merge<HTMLUIProps<"li">, HTMLMotionProps<"li">>, "value" | "transition" | "children">, PropsWithChildren, ReorderItemOptions<Y> {
17
+ }
25
18
  declare const ReorderItem: {
26
- <Y extends any = string>(props: ReorderItemProps<Y> & {
27
- ref?: ForwardedRef<HTMLLIElement>;
28
- }): JSX.Element;
19
+ <Y = string>(props: ReorderItemProps<Y> & RefAttributes<HTMLLIElement>): JSX.Element;
29
20
  } & ComponentArgs;
30
21
 
31
- export { ReorderItem, type ReorderItemProps, ReorderItemProvider, useReorderItemContext };
22
+ export { ReorderItem, type ReorderItemProps };
@@ -21,137 +21,41 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  // src/reorder-item.tsx
22
22
  var reorder_item_exports = {};
23
23
  __export(reorder_item_exports, {
24
- ReorderItem: () => ReorderItem,
25
- ReorderItemProvider: () => ReorderItemProvider,
26
- useReorderItemContext: () => useReorderItemContext
24
+ ReorderItem: () => ReorderItem
27
25
  });
28
26
  module.exports = __toCommonJS(reorder_item_exports);
29
- var import_core2 = require("@yamada-ui/core");
30
- var import_motion2 = require("@yamada-ui/motion");
31
- var import_utils2 = require("@yamada-ui/utils");
32
- var import_react2 = require("react");
33
-
34
- // src/reorder.tsx
35
27
  var import_core = require("@yamada-ui/core");
36
28
  var import_motion = require("@yamada-ui/motion");
37
- var import_utils = require("@yamada-ui/utils");
29
+ var import_utils2 = require("@yamada-ui/utils");
38
30
  var import_react = require("react");
39
- var import_jsx_runtime = require("react/jsx-runtime");
31
+
32
+ // src/reorder-context.ts
33
+ var import_utils = require("@yamada-ui/utils");
40
34
  var [ReorderProvider, useReorderContext] = (0, import_utils.createContext)({
41
35
  name: "ReorderContext",
42
36
  errorMessage: `useReorderContext returned is 'undefined'. Seems you forgot to wrap the components in "<Reorder />"`
43
37
  });
44
- var omitDuplicated = (values) => Array.from(new Set(values));
45
- var pickDuplicated = (values) => values.filter(
46
- (value, index, self) => self.indexOf(value) === index && index !== self.lastIndexOf(value)
47
- );
48
- var Reorder = (0, import_react.forwardRef)(
49
- (props, ref) => {
50
- const [styles, mergedProps] = (0, import_core.useMultiComponentStyle)("Reorder", props);
51
- const {
52
- className,
53
- orientation = "vertical",
54
- gap = "fallback(4, 1rem)",
55
- items = [],
56
- onChange,
57
- onCompleteChange,
58
- children,
59
- ...rest
60
- } = (0, import_core.omitThemeProps)(mergedProps);
61
- const axis = orientation === "vertical" ? "y" : "x";
62
- const validChildren = (0, import_utils.getValidChildren)(children);
63
- const hasChildren = !!validChildren.length;
64
- const defaultValues = (0, import_react.useMemo)(() => {
65
- const values2 = hasChildren ? validChildren.map(({ props: props2 }) => props2.value) : items.map(({ value }) => value);
66
- const duplicatedValues = pickDuplicated(values2);
67
- if (duplicatedValues.length)
68
- console.warn(
69
- `Reorder: 'value' of 'ReorderItem' must not be duplicated. duplicate 'value' is '${duplicatedValues.join(
70
- `', '`
71
- )}' `
72
- );
73
- return omitDuplicated(values2);
74
- }, [hasChildren, validChildren, items]);
75
- const prevDefaultValues = (0, import_react.useRef)(defaultValues);
76
- const [values, setValues] = (0, import_react.useState)(defaultValues);
77
- const prevValues = (0, import_react.useRef)(defaultValues);
78
- const onReorder = (0, import_react.useCallback)(
79
- (newValues) => {
80
- setValues(newValues);
81
- onChange == null ? void 0 : onChange(newValues);
82
- },
83
- [onChange]
84
- );
85
- const onCompleteReorder = (0, import_react.useCallback)(() => {
86
- const isEqual = JSON.stringify(prevValues.current) === JSON.stringify(values);
87
- if (isEqual) return;
88
- prevValues.current = values;
89
- onCompleteChange == null ? void 0 : onCompleteChange(values);
90
- }, [onCompleteChange, values]);
91
- (0, import_utils.useUpdateEffect)(() => {
92
- const isEqual = JSON.stringify(defaultValues) === JSON.stringify(prevDefaultValues.current);
93
- if (isEqual) return;
94
- prevValues.current = defaultValues;
95
- prevDefaultValues.current = defaultValues;
96
- setValues(defaultValues);
97
- }, [defaultValues]);
98
- const cloneChildren = (0, import_react.useMemo)(
99
- () => values.map((value) => {
100
- if (hasChildren) {
101
- return validChildren.find(({ props: props2 }) => props2.value === value);
102
- } else {
103
- const props2 = items.find((item) => item.value === value);
104
- return props2 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReorderItem, { ...props2 }, props2.value) : null;
105
- }
106
- }),
107
- [values, hasChildren, validChildren, items]
108
- );
109
- const css = {
110
- display: "flex",
111
- flexDirection: orientation === "vertical" ? "column" : "row",
112
- gap,
113
- ...styles.container
114
- };
115
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReorderProvider, { value: { orientation, styles }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
116
- import_core.ui.ul,
117
- {
118
- ref,
119
- as: import_motion.MotionReorder.Group,
120
- className: (0, import_utils.cx)("ui-reorder", className),
121
- axis,
122
- values,
123
- onReorder,
124
- __css: css,
125
- ...rest,
126
- onMouseUp: (0, import_utils.handlerAll)(rest.onMouseUp, onCompleteReorder),
127
- onTouchEnd: (0, import_utils.handlerAll)(rest.onTouchEnd, onCompleteReorder),
128
- children: cloneChildren
129
- }
130
- ) });
131
- }
132
- );
133
- Reorder.displayName = "Reorder";
134
-
135
- // src/reorder-item.tsx
136
- var import_jsx_runtime2 = require("react/jsx-runtime");
137
- var [ReorderItemProvider, useReorderItemContext] = (0, import_utils2.createContext)({
38
+ var [ReorderItemProvider, useReorderItemContext] = (0, import_utils.createContext)({
138
39
  name: "ReorderContext",
139
40
  errorMessage: `useReorderItemContext returned is 'undefined'. Seems you forgot to wrap the components in "<ReorderItem />"`
140
41
  });
141
- var ReorderItem = (0, import_react2.forwardRef)(
42
+
43
+ // src/reorder-item.tsx
44
+ var import_jsx_runtime = require("react/jsx-runtime");
45
+ var ReorderItem = (0, import_react.forwardRef)(
142
46
  ({ className, label, value, children, ...rest }, ref) => {
143
47
  var _a;
144
48
  const { orientation, styles } = useReorderContext();
145
- const dragControls = (0, import_motion2.useDragControls)();
146
- const [hasTrigger, setHasTrigger] = (0, import_react2.useState)(false);
147
- const [isDrag, setIsDrag] = (0, import_react2.useState)(false);
148
- const x = (0, import_motion2.useMotionValue)(0);
149
- const y = (0, import_motion2.useMotionValue)(0);
150
- const register = (0, import_react2.useCallback)(
49
+ const dragControls = (0, import_motion.useDragControls)();
50
+ const [hasTrigger, setHasTrigger] = (0, import_react.useState)(false);
51
+ const [isDrag, setIsDrag] = (0, import_react.useState)(false);
52
+ const x = (0, import_motion.useMotionValue)(0);
53
+ const y = (0, import_motion.useMotionValue)(0);
54
+ const register = (0, import_react.useCallback)(
151
55
  (node) => setHasTrigger(!!node),
152
56
  []
153
57
  );
154
- (0, import_react2.useEffect)(() => {
58
+ (0, import_react.useEffect)(() => {
155
59
  const unsubscribeX = x.on("change", (x2) => {
156
60
  if (orientation === "horizontal") setIsDrag(x2 !== 0);
157
61
  });
@@ -176,11 +80,11 @@ var ReorderItem = (0, import_react2.forwardRef)(
176
80
  }
177
81
  } : {}
178
82
  };
179
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ReorderItemProvider, { value: { register, isDrag, dragControls }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
180
- import_core2.ui.li,
83
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReorderItemProvider, { value: { register, isDrag, dragControls }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
84
+ import_core.ui.li,
181
85
  {
182
86
  ref,
183
- as: import_motion2.MotionReorder.Item,
87
+ as: import_motion.MotionReorder.Item,
184
88
  className: (0, import_utils2.cx)("ui-reorder__item", className),
185
89
  value,
186
90
  __css: css,
@@ -197,8 +101,6 @@ var ReorderItem = (0, import_react2.forwardRef)(
197
101
  ReorderItem.displayName = "ReorderItem";
198
102
  // Annotate the CommonJS export names for ESM import in node:
199
103
  0 && (module.exports = {
200
- ReorderItem,
201
- ReorderItemProvider,
202
- useReorderItemContext
104
+ ReorderItem
203
105
  });
204
106
  //# sourceMappingURL=reorder-item.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/reorder-item.tsx","../src/reorder.tsx"],"sourcesContent":["import type { HTMLUIProps, CSSUIObject, ComponentArgs } from \"@yamada-ui/core\"\nimport { ui } from \"@yamada-ui/core\"\nimport type { HTMLMotionProps, DragControls } from \"@yamada-ui/motion\"\nimport {\n MotionReorder,\n useMotionValue,\n useDragControls,\n} from \"@yamada-ui/motion\"\nimport { createContext, cx, dataAttr } from \"@yamada-ui/utils\"\nimport type { Merge } from \"@yamada-ui/utils\"\nimport type { ForwardedRef, PropsWithChildren, ReactNode } from \"react\"\nimport { forwardRef, useCallback, useEffect, useState } from \"react\"\nimport { useReorderContext } from \"./reorder\"\n\ntype ReorderItemContext = {\n register: (node: HTMLElement | null) => void\n isDrag: boolean\n dragControls: DragControls\n}\n\nexport const [ReorderItemProvider, useReorderItemContext] =\n createContext<ReorderItemContext>({\n name: \"ReorderContext\",\n errorMessage: `useReorderItemContext returned is 'undefined'. Seems you forgot to wrap the components in \"<ReorderItem />\"`,\n })\n\ntype ReorderItemOptions<Y extends any = string> = {\n /**\n * The label of the reorder item.\n */\n label?: ReactNode\n /**\n * The value of the reorder item.\n */\n value: Y\n}\n\nexport type ReorderItemProps<Y extends any = string> = Omit<\n Merge<HTMLUIProps<\"li\">, HTMLMotionProps<\"li\">>,\n \"value\" | \"transition\" | \"children\"\n> &\n PropsWithChildren &\n ReorderItemOptions<Y>\n\nexport const ReorderItem = forwardRef(\n <Y extends any = string>(\n { className, label, value, children, ...rest }: ReorderItemProps<Y>,\n ref: ForwardedRef<HTMLLIElement>,\n ) => {\n const { orientation, styles } = useReorderContext()\n\n const dragControls = useDragControls()\n\n const [hasTrigger, setHasTrigger] = useState<boolean>(false)\n const [isDrag, setIsDrag] = useState<boolean>(false)\n\n const x = useMotionValue(0)\n const y = useMotionValue(0)\n\n const register = useCallback(\n (node: HTMLElement | null) => setHasTrigger(!!node),\n [],\n )\n\n useEffect(() => {\n const unsubscribeX = x.on(\"change\", (x) => {\n if (orientation === \"horizontal\") setIsDrag(x !== 0)\n })\n const unsubscribeY = y.on(\"change\", (y) => {\n if (orientation === \"vertical\") setIsDrag(y !== 0)\n })\n\n return () => {\n unsubscribeX()\n unsubscribeY()\n }\n }, [orientation, x, y])\n\n const css: CSSUIObject = {\n _selected: {\n cursor: \"grabbing\",\n },\n ...(!hasTrigger ? { cursor: \"grab\" } : { userSelect: \"none\" }),\n ...styles.item,\n ...(!hasTrigger\n ? {\n _selected: {\n ...styles.item?._selected,\n cursor: \"grabbing\",\n },\n }\n : {}),\n }\n\n return (\n <ReorderItemProvider value={{ register, isDrag, dragControls }}>\n <ui.li\n ref={ref}\n as={MotionReorder.Item}\n className={cx(\"ui-reorder__item\", className)}\n value={value}\n __css={css}\n {...rest}\n dragListener={!hasTrigger}\n dragControls={dragControls}\n data-selected={dataAttr(isDrag)}\n style={{ ...rest.style, x, y }}\n >\n {children ?? label}\n </ui.li>\n </ReorderItemProvider>\n )\n },\n) as {\n <Y extends any = string>(\n props: ReorderItemProps<Y> & { ref?: ForwardedRef<HTMLLIElement> },\n ): JSX.Element\n} & ComponentArgs\n\nReorderItem.displayName = \"ReorderItem\"\n","import type {\n CSSUIObject,\n ComponentArgs,\n HTMLUIProps,\n ThemeProps,\n} from \"@yamada-ui/core\"\nimport { ui, useMultiComponentStyle, omitThemeProps } from \"@yamada-ui/core\"\nimport type { HTMLMotionProps } from \"@yamada-ui/motion\"\nimport { MotionReorder } from \"@yamada-ui/motion\"\nimport type { Merge } from \"@yamada-ui/utils\"\nimport {\n createContext,\n cx,\n getValidChildren,\n handlerAll,\n useUpdateEffect,\n} from \"@yamada-ui/utils\"\nimport type { ForwardedRef, PropsWithChildren } from \"react\"\nimport { forwardRef, useCallback, useMemo, useRef, useState } from \"react\"\nimport { ReorderItem, type ReorderItemProps } from \"./reorder-item\"\n\ntype ReorderContext = {\n orientation: \"vertical\" | \"horizontal\"\n styles: Record<string, CSSUIObject>\n}\n\nexport const [ReorderProvider, useReorderContext] =\n createContext<ReorderContext>({\n name: \"ReorderContext\",\n errorMessage: `useReorderContext returned is 'undefined'. Seems you forgot to wrap the components in \"<Reorder />\"`,\n })\n\nexport type ReorderGenerateItem<Y extends any = string> = ReorderItemProps<Y>\n\ntype ReorderOptions<Y extends any = string> = {\n /**\n * The orientation of the reorder.\n *\n * @default 'vertical'\n */\n orientation?: \"vertical\" | \"horizontal\"\n /**\n * If provided, generate reorder items based on items.\n *\n */\n items?: ReorderGenerateItem[]\n /**\n * The callback invoked when reorder items are moved.\n */\n onChange?: (values: Y[]) => void\n /**\n * The callback invoked when the movement of reorder items is completed.\n */\n onCompleteChange?: (values: Y[]) => void\n}\n\nexport type ReorderProps<Y extends any = string> = Omit<\n Merge<HTMLUIProps<\"ul\">, HTMLMotionProps<\"ul\">>,\n \"onChange\" | \"transition\" | \"children\"\n> &\n PropsWithChildren &\n ThemeProps<\"Reorder\"> &\n ReorderOptions<Y>\n\nconst omitDuplicated = <Y extends any = string>(values: Y[]): Y[] =>\n Array.from(new Set(values))\n\nconst pickDuplicated = <Y extends any = string>(values: Y[]): Y[] =>\n values.filter(\n (value, index, self) =>\n self.indexOf(value) === index && index !== self.lastIndexOf(value),\n )\n\n/**\n * `Reorder` is a component that allows you to change the order of items using drag and drop.\n *\n * @see Docs https://yamada-ui.com/components/data-display/reorder\n */\nexport const Reorder = forwardRef(\n <Y extends any = string>(\n props: ReorderProps<Y>,\n ref: ForwardedRef<HTMLUListElement>,\n ) => {\n const [styles, mergedProps] = useMultiComponentStyle(\"Reorder\", props)\n const {\n className,\n orientation = \"vertical\",\n gap = \"fallback(4, 1rem)\",\n items = [],\n onChange,\n onCompleteChange,\n children,\n ...rest\n } = omitThemeProps(mergedProps)\n\n const axis = orientation === \"vertical\" ? \"y\" : \"x\"\n\n const validChildren = getValidChildren(children)\n const hasChildren = !!validChildren.length\n\n const defaultValues = useMemo(() => {\n const values = hasChildren\n ? validChildren.map(({ props }) => props.value)\n : items.map(({ value }) => value)\n\n const duplicatedValues = pickDuplicated(values)\n\n if (duplicatedValues.length)\n console.warn(\n `Reorder: 'value' of 'ReorderItem' must not be duplicated. duplicate 'value' is '${duplicatedValues.join(\n `', '`,\n )}' `,\n )\n\n return omitDuplicated(values)\n }, [hasChildren, validChildren, items])\n const prevDefaultValues = useRef<Y[]>(defaultValues)\n\n const [values, setValues] = useState<Y[]>(defaultValues)\n const prevValues = useRef<Y[]>(defaultValues)\n\n const onReorder = useCallback(\n (newValues: Y[]) => {\n setValues(newValues)\n\n onChange?.(newValues)\n },\n [onChange],\n )\n\n const onCompleteReorder = useCallback(() => {\n const isEqual =\n JSON.stringify(prevValues.current) === JSON.stringify(values)\n\n if (isEqual) return\n\n prevValues.current = values\n\n onCompleteChange?.(values)\n }, [onCompleteChange, values])\n\n useUpdateEffect(() => {\n const isEqual =\n JSON.stringify(defaultValues) ===\n JSON.stringify(prevDefaultValues.current)\n\n if (isEqual) return\n\n prevValues.current = defaultValues\n prevDefaultValues.current = defaultValues\n\n setValues(defaultValues)\n }, [defaultValues])\n\n const cloneChildren = useMemo(\n () =>\n values.map((value) => {\n if (hasChildren) {\n return validChildren.find(({ props }) => props.value === value)\n } else {\n const props = items.find((item) => item.value === value)\n\n return props ? <ReorderItem key={props.value} {...props} /> : null\n }\n }),\n [values, hasChildren, validChildren, items],\n )\n\n const css: CSSUIObject = {\n display: \"flex\",\n flexDirection: orientation === \"vertical\" ? \"column\" : \"row\",\n gap,\n ...styles.container,\n }\n\n return (\n <ReorderProvider value={{ orientation, styles }}>\n <ui.ul\n ref={ref}\n as={MotionReorder.Group<Y>}\n className={cx(\"ui-reorder\", className)}\n axis={axis}\n values={values}\n onReorder={onReorder}\n __css={css}\n {...rest}\n onMouseUp={handlerAll(rest.onMouseUp, onCompleteReorder)}\n onTouchEnd={handlerAll(rest.onTouchEnd, onCompleteReorder)}\n >\n {cloneChildren}\n </ui.ul>\n </ReorderProvider>\n )\n },\n) as {\n <Y extends any = string>(\n props: ReorderProps<Y> & { ref?: ForwardedRef<HTMLUListElement> },\n ): JSX.Element\n} & ComponentArgs\n\nReorder.displayName = \"Reorder\"\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,IAAAA,eAAmB;AAEnB,IAAAC,iBAIO;AACP,IAAAC,gBAA4C;AAG5C,IAAAC,gBAA6D;;;ACL7D,kBAA2D;AAE3D,oBAA8B;AAE9B,mBAMO;AAEP,mBAAmE;AAgJxC;AAxIpB,IAAM,CAAC,iBAAiB,iBAAiB,QAC9C,4BAA8B;AAAA,EAC5B,MAAM;AAAA,EACN,cAAc;AAChB,CAAC;AAkCH,IAAM,iBAAiB,CAAyB,WAC9C,MAAM,KAAK,IAAI,IAAI,MAAM,CAAC;AAE5B,IAAM,iBAAiB,CAAyB,WAC9C,OAAO;AAAA,EACL,CAAC,OAAO,OAAO,SACb,KAAK,QAAQ,K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QAClB,eAAW,kBAAG,oBAAoB,SAAS;AAAA,QAC3C;AAAA,QACA,OAAO;AAAA,QACN,GAAG;AAAA,QACJ,cAAc,CAAC;AAAA,QACf;AAAA,QACA,qBAAe,wBAAS,MAAM;AAAA,QAC9B,OAAO,EAAE,GAAG,KAAK,OAAO,GAAG,EAAE;AAAA,QAE5B,wCAAY;AAAA;AAAA,IACf,GACF;AAAA,EAEJ;AACF;AAMA,YAAY,cAAc;","names":["import_core","import_motion","import_utils","import_react","values","props","import_jsx_runtime","x","y"]}
1
+ {"version":3,"sources":["../src/reorder-item.tsx","../src/reorder-context.ts"],"sourcesContent":["import type { HTMLUIProps, CSSUIObject, ComponentArgs } from \"@yamada-ui/core\"\nimport { ui } from \"@yamada-ui/core\"\nimport type { HTMLMotionProps } from \"@yamada-ui/motion\"\nimport {\n MotionReorder,\n useMotionValue,\n useDragControls,\n} from \"@yamada-ui/motion\"\nimport { cx, dataAttr } from \"@yamada-ui/utils\"\nimport type { Merge } from \"@yamada-ui/utils\"\nimport type {\n ForwardedRef,\n PropsWithChildren,\n ReactNode,\n RefAttributes,\n} from \"react\"\nimport { forwardRef, useCallback, useEffect, useState } from \"react\"\nimport { ReorderItemProvider, useReorderContext } from \"./reorder-context\"\n\ninterface ReorderItemOptions<Y extends any = string> {\n /**\n * The label of the reorder item.\n */\n label?: ReactNode\n /**\n * The value of the reorder item.\n */\n value: Y\n}\n\nexport interface ReorderItemProps<Y extends any = string>\n extends Omit<\n Merge<HTMLUIProps<\"li\">, HTMLMotionProps<\"li\">>,\n \"value\" | \"transition\" | \"children\"\n >,\n PropsWithChildren,\n ReorderItemOptions<Y> {}\n\nexport const ReorderItem = forwardRef(\n <Y extends any = string>(\n { className, label, value, children, ...rest }: ReorderItemProps<Y>,\n ref: ForwardedRef<HTMLLIElement>,\n ) => {\n const { orientation, styles } = useReorderContext()\n\n const dragControls = useDragControls()\n\n const [hasTrigger, setHasTrigger] = useState<boolean>(false)\n const [isDrag, setIsDrag] = useState<boolean>(false)\n\n const x = useMotionValue(0)\n const y = useMotionValue(0)\n\n const register = useCallback(\n (node: HTMLElement | null) => setHasTrigger(!!node),\n [],\n )\n\n useEffect(() => {\n const unsubscribeX = x.on(\"change\", (x) => {\n if (orientation === \"horizontal\") setIsDrag(x !== 0)\n })\n const unsubscribeY = y.on(\"change\", (y) => {\n if (orientation === \"vertical\") setIsDrag(y !== 0)\n })\n\n return () => {\n unsubscribeX()\n unsubscribeY()\n }\n }, [orientation, x, y])\n\n const css: CSSUIObject = {\n _selected: {\n cursor: \"grabbing\",\n },\n ...(!hasTrigger ? { cursor: \"grab\" } : { userSelect: \"none\" }),\n ...styles.item,\n ...(!hasTrigger\n ? {\n _selected: {\n ...styles.item?._selected,\n cursor: \"grabbing\",\n },\n }\n : {}),\n }\n\n return (\n <ReorderItemProvider value={{ register, isDrag, dragControls }}>\n <ui.li\n ref={ref}\n as={MotionReorder.Item}\n className={cx(\"ui-reorder__item\", className)}\n value={value}\n __css={css}\n {...rest}\n dragListener={!hasTrigger}\n dragControls={dragControls}\n data-selected={dataAttr(isDrag)}\n style={{ ...rest.style, x, y }}\n >\n {children ?? label}\n </ui.li>\n </ReorderItemProvider>\n )\n },\n) as {\n <Y = string>(\n props: ReorderItemProps<Y> & RefAttributes<HTMLLIElement>,\n ): JSX.Element\n} & ComponentArgs\n\nReorderItem.displayName = \"ReorderItem\"\n","import type { CSSUIObject } from \"@yamada-ui/core\"\nimport type { DragControls } from \"@yamada-ui/motion\"\nimport { createContext } from \"@yamada-ui/utils\"\n\ninterface ReorderContext {\n orientation: \"vertical\" | \"horizontal\"\n styles: { [key: string]: CSSUIObject }\n}\n\nexport const [ReorderProvider, useReorderContext] =\n createContext<ReorderContext>({\n name: \"ReorderContext\",\n errorMessage: `useReorderContext returned is 'undefined'. Seems you forgot to wrap the components in \"<Reorder />\"`,\n })\n\ninterface ReorderItemContext {\n register: (node: HTMLElement | null) => void\n isDrag: boolean\n dragControls: DragControls\n}\n\nexport const [ReorderItemProvider, useReorderItemContext] =\n createContext<ReorderItemContext>({\n name: \"ReorderContext\",\n errorMessage: `useReorderItemContext returned is 'undefined'. Seems you forgot to wrap the components in \"<ReorderItem />\"`,\n })\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAmB;AAEnB,oBAIO;AACP,IAAAA,gBAA6B;AAQ7B,mBAA6D;;;ACd7D,mBAA8B;AAOvB,IAAM,CAAC,iBAAiB,iBAAiB,QAC9C,4BAA8B;AAAA,EAC5B,MAAM;AAAA,EACN,cAAc;AAChB,CAAC;AAQI,IAAM,CAAC,qBAAqB,qBAAqB,QACtD,4BAAkC;AAAA,EAChC,MAAM;AAAA,EACN,cAAc;AAChB,CAAC;;;ADiEK;AApDD,IAAM,kBAAc;AAAA,EACzB,CACE,EAAE,WAAW,OAAO,OAAO,UAAU,GAAG,KAAK,GAC7C,QACG;AA1CP;AA2CI,UAAM,EAAE,aAAa,OAAO,IAAI,kBAAkB;AAElD,UAAM,mBAAe,+BAAgB;AAErC,UAAM,CAAC,YAAY,aAAa,QAAI,uBAAkB,KAAK;AAC3D,UAAM,CAAC,QAAQ,SAAS,QAAI,uBAAkB,KAAK;AAEnD,UAAM,QAAI,8BAAe,CAAC;AAC1B,UAAM,QAAI,8BAAe,CAAC;AAE1B,UAAM,eAAW;AAAA,MACf,CAAC,SAA6B,cAAc,CAAC,CAAC,IAAI;AAAA,MAClD,CAAC;AAAA,IACH;AAEA,gCAAU,MAAM;AACd,YAAM,eAAe,EAAE,GAAG,UAAU,CAACC,OAAM;AACzC,YAAI,gBAAgB,aAAc,WAAUA,OAAM,CAAC;AAAA,MACrD,CAAC;AACD,YAAM,eAAe,EAAE,GAAG,UAAU,CAACC,OAAM;AACzC,YAAI,gBAAgB,WAAY,WAAUA,OAAM,CAAC;AAAA,MACnD,CAAC;AAED,aAAO,MAAM;AACX,qBAAa;AACb,qBAAa;AAAA,MACf;AAAA,IACF,GAAG,CAAC,aAAa,GAAG,CAAC,CAAC;AAEtB,UAAM,MAAmB;AAAA,MACvB,WAAW;AAAA,QACT,QAAQ;AAAA,MACV;AAAA,MACA,GAAI,CAAC,aAAa,EAAE,QAAQ,OAAO,IAAI,EAAE,YAAY,OAAO;AAAA,MAC5D,GAAG,OAAO;AAAA,MACV,GAAI,CAAC,aACD;AAAA,QACE,WAAW;AAAA,UACT,IAAG,YAAO,SAAP,mBAAa;AAAA,UAChB,QAAQ;AAAA,QACV;AAAA,MACF,IACA,CAAC;AAAA,IACP;AAEA,WACE,4CAAC,uBAAoB,OAAO,EAAE,UAAU,QAAQ,aAAa,GAC3D;AAAA,MAAC,eAAG;AAAA,MAAH;AAAA,QACC;AAAA,QACA,IAAI,4BAAc;AAAA,QAClB,eAAW,kBAAG,oBAAoB,SAAS;AAAA,QAC3C;AAAA,QACA,OAAO;AAAA,QACN,GAAG;AAAA,QACJ,cAAc,CAAC;AAAA,QACf;AAAA,QACA,qBAAe,wBAAS,MAAM;AAAA,QAC9B,OAAO,EAAE,GAAG,KAAK,OAAO,GAAG,EAAE;AAAA,QAE5B,wCAAY;AAAA;AAAA,IACf,GACF;AAAA,EAEJ;AACF;AAMA,YAAY,cAAc;","names":["import_utils","x","y"]}
@@ -1,12 +1,9 @@
1
1
  "use client"
2
2
  import {
3
- ReorderItem,
4
- ReorderItemProvider,
5
- useReorderItemContext
6
- } from "./chunk-LKWVADXG.mjs";
3
+ ReorderItem
4
+ } from "./chunk-XQS37PRX.mjs";
5
+ import "./chunk-BBGHU5EB.mjs";
7
6
  export {
8
- ReorderItem,
9
- ReorderItemProvider,
10
- useReorderItemContext
7
+ ReorderItem
11
8
  };
12
9
  //# sourceMappingURL=reorder-item.mjs.map
@@ -1,7 +1,8 @@
1
1
  import * as _yamada_ui_core from '@yamada-ui/core';
2
2
  import { HTMLUIProps } from '@yamada-ui/core';
3
3
 
4
- type ReorderTriggerProps = HTMLUIProps<"div">;
4
+ interface ReorderTriggerProps extends HTMLUIProps {
5
+ }
5
6
  declare const ReorderTrigger: _yamada_ui_core.Component<"div", ReorderTriggerProps>;
6
7
 
7
8
  export { ReorderTrigger, type ReorderTriggerProps };
@@ -1,7 +1,8 @@
1
1
  import * as _yamada_ui_core from '@yamada-ui/core';
2
2
  import { HTMLUIProps } from '@yamada-ui/core';
3
3
 
4
- type ReorderTriggerProps = HTMLUIProps<"div">;
4
+ interface ReorderTriggerProps extends HTMLUIProps {
5
+ }
5
6
  declare const ReorderTrigger: _yamada_ui_core.Component<"div", ReorderTriggerProps>;
6
7
 
7
8
  export { ReorderTrigger, type ReorderTriggerProps };