@rnaga/wp-next-ui 1.0.9 → 1.0.11
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/Input.d.ts +1 -0
- package/Input.d.ts.map +1 -1
- package/Input.js +6 -1
- package/InputColor.d.ts.map +1 -1
- package/InputColor.js +4 -1
- package/InputMultiple.js +1 -1
- package/ListBase.d.ts +1 -0
- package/ListBase.d.ts.map +1 -1
- package/ListBase.js +8 -3
- package/SelectFreeSoloAutocomplete.d.ts +16 -0
- package/SelectFreeSoloAutocomplete.d.ts.map +1 -0
- package/SelectFreeSoloAutocomplete.js +70 -0
- package/SortableList.d.ts.map +1 -1
- package/SortableList.js +109 -81
- package/package.json +1 -1
package/Input.d.ts
CHANGED
|
@@ -10,5 +10,6 @@ export declare const Input: (props: {
|
|
|
10
10
|
clearable?: boolean;
|
|
11
11
|
readOnly?: boolean;
|
|
12
12
|
removeBorderOnFocus?: boolean;
|
|
13
|
+
isEmpty?: boolean;
|
|
13
14
|
} & Omit<Parameters<typeof MuiInput>[0], "onChange" | "value" | "onBlur" | "size" | "readOnly">) => import("react/jsx-runtime").JSX.Element;
|
|
14
15
|
//# sourceMappingURL=Input.d.ts.map
|
package/Input.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.d.ts","sourceRoot":"","sources":["../src/Input.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AAKnE,eAAO,MAAM,KAAK,GAChB,OAAO;IACL,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IAC5E,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,I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AsIF,CAAC"}
|
package/Input.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Box, IconButton, Input as MuiInput } from "@mui/material";
|
|
|
3
3
|
import { useEffect, useState } from "react";
|
|
4
4
|
import ClearIcon from "@mui/icons-material/Clear";
|
|
5
5
|
export const Input = (props) => {
|
|
6
|
-
const { onChange, onBlur, onClear, canClear, size, disableBorder, sx, readOnly = false, clearable = false, removeBorderOnFocus = false, multiline, value: _value, ...rest } = props;
|
|
6
|
+
const { onChange, onBlur, onClear, canClear, size, disableBorder, sx, readOnly = false, clearable = false, removeBorderOnFocus = false, multiline, value: _value, isEmpty, ...rest } = props;
|
|
7
7
|
const [value, setValue] = useState(_value ?? "");
|
|
8
8
|
const handleChange = (e) => {
|
|
9
9
|
const value = e.target.value;
|
|
@@ -26,6 +26,11 @@ export const Input = (props) => {
|
|
|
26
26
|
return;
|
|
27
27
|
setValue(_value);
|
|
28
28
|
}, [_value]);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (isEmpty === true) {
|
|
31
|
+
setValue("");
|
|
32
|
+
}
|
|
33
|
+
}, [isEmpty]);
|
|
29
34
|
return (_jsx(MuiInput, { disableUnderline: true, readOnly: readOnly, onBlur: handleBlur, value: value, onChange: handleChange, multiline: multiline,
|
|
30
35
|
// onFocus={(e) => e.target.select?.()}
|
|
31
36
|
sx: {
|
package/InputColor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InputColor.d.ts","sourceRoot":"","sources":["../src/InputColor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"InputColor.d.ts","sourceRoot":"","sources":["../src/InputColor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA+B,MAAM,OAAO,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAO,OAAO,EAAE,MAAM,eAAe,CAAC;AAK7C,eAAO,MAAM,aAAa,GAAI,KAAK,MAAM,KAAG,OAUzC,CAAC;AA2IJ,eAAO,MAAM,UAAU,GACrB,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG;IAC/C,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,WAAW,CAAC,EAAE;QACZ,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,KAAK,CAAC,EAAE,aAAa,CAAC;KACvB,CAAC;CACH,4CAiEF,CAAC"}
|
package/InputColor.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useRef, useState } from "react";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
3
|
import { Input } from "./Input";
|
|
4
4
|
import { Box } from "@mui/material";
|
|
5
5
|
export const isColorString = (src) => /^#([\da-f]{3}|[\da-f]{6})$/i.test(src) ||
|
|
@@ -117,6 +117,9 @@ export const InputColor = (props) => {
|
|
|
117
117
|
setValue(value);
|
|
118
118
|
onBlur(value);
|
|
119
119
|
};
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
setValue(`${props.value ?? ""}`);
|
|
122
|
+
}, [props.value]);
|
|
120
123
|
return (_jsxs(Box, { sx: { display: "flex", gap: 1, alignItems: "center", ...sx }, children: [_jsx(Input, { size: size, onChange: (value) => {
|
|
121
124
|
handleChange(value);
|
|
122
125
|
}, onBlur: (value) => {
|
package/InputMultiple.js
CHANGED
package/ListBase.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export type ListBaseProps<T = string> = {
|
|
|
40
40
|
onMouseDown?: (item: ListItemType<T>, event: React.MouseEvent) => void;
|
|
41
41
|
itemEventHandlers?: ListItemEventHandlers<T>;
|
|
42
42
|
getItemSx?: (item: ListItemType<T>, index: number) => SxProps;
|
|
43
|
+
getItemDataAttributes?: (item: ListItemType<T>, index: number) => Record<string, string | number>;
|
|
43
44
|
dataAttributes?: Record<string, string | number>;
|
|
44
45
|
slotSxProps?: {
|
|
45
46
|
listItem?: SxProps;
|
package/ListBase.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListBase.d.ts","sourceRoot":"","sources":["../src/ListBase.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKL,OAAO,EACR,MAAM,eAAe,CAAC;AAEvB,OAAO,EAEL,GAAG,EACH,SAAS,EAIV,MAAM,OAAO,CAAC;AAKf,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,MAAM,IAAI;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,CAAC,CAAC;IACT,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;CACrC,CAAC;AAEF,KAAK,WAAW,GAAG,UAAU,GAAG,YAAY,GAAG,MAAM,GAAG,gBAAgB,CAAC;AAEzE,KAAK,qBAAqB,CAAC,CAAC,GAAG,MAAM,IAAI;IACvC,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC;IACnE,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC;IACvE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC;IACrE,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC;IACxE,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CA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ref = useRef(null);
|
|
12
12
|
const [isHovered, setIsHovered] = useState(false);
|
|
13
|
-
const { displayType, renderItem, onDelete, onEdit, itemEventHandlers, getItemSx, slotSxProps, editable, } = useContext(ListContext);
|
|
13
|
+
const { displayType, renderItem, onDelete, onEdit, itemEventHandlers, getItemSx, getItemDataAttributes, slotSxProps, editable, } = useContext(ListContext);
|
|
14
14
|
const { wpTheme } = useWPTheme();
|
|
15
15
|
const handleEvent = (handler) => {
|
|
16
16
|
return handler
|
|
@@ -30,7 +30,11 @@ export const ListItem = (props) => {
|
|
|
30
30
|
...(slotSxProps?.listItem || {}),
|
|
31
31
|
...sx,
|
|
32
32
|
};
|
|
33
|
-
|
|
33
|
+
const itemDataAttributes = {
|
|
34
|
+
...(dataAttributes || {}),
|
|
35
|
+
...(getItemDataAttributes ? getItemDataAttributes(item, index) : {}),
|
|
36
|
+
};
|
|
37
|
+
return (_jsxs(MuiListItem, { ref: ref, value: item.value, onClick: handleEvent(itemEventHandlers?.onClick), onMouseDown: handleEvent(itemEventHandlers?.onMouseDown), onMouseUp: handleEvent(itemEventHandlers?.onMouseUp), onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, onDoubleClick: handleEvent(itemEventHandlers?.onDoubleClick), onContextMenu: handleEvent(itemEventHandlers?.onContextMenu), onMouseOver: handleEvent(itemEventHandlers?.onMouseOver), ...itemDataAttributes, sx: {
|
|
34
38
|
position: "relative",
|
|
35
39
|
"&:hover": {
|
|
36
40
|
backgroundColor: wpTheme.background.hoverColor,
|
|
@@ -60,7 +64,7 @@ export const ListItem = (props) => {
|
|
|
60
64
|
} }) }))] }));
|
|
61
65
|
};
|
|
62
66
|
export const ListBase = (props) => {
|
|
63
|
-
const { items, size = "small", displayType = "vertical", renderItem, onDelete, onEdit, onClick, onMouseDown, itemEventHandlers, getItemSx, dataAttributes, slotSxProps, editable = false, } = props;
|
|
67
|
+
const { items, size = "small", displayType = "vertical", renderItem, onDelete, onEdit, onClick, onMouseDown, itemEventHandlers, getItemSx, getItemDataAttributes, dataAttributes, slotSxProps, editable = false, } = props;
|
|
64
68
|
const listItems = items.map((item, index) => ({
|
|
65
69
|
index,
|
|
66
70
|
value: item.value,
|
|
@@ -100,6 +104,7 @@ export const ListBase = (props) => {
|
|
|
100
104
|
onEdit,
|
|
101
105
|
itemEventHandlers: mergedEventHandlers,
|
|
102
106
|
getItemSx: getItemSx,
|
|
107
|
+
getItemDataAttributes: getItemDataAttributes,
|
|
103
108
|
slotSxProps,
|
|
104
109
|
editable,
|
|
105
110
|
}, children: _jsx(MuiList, { sx: { ...sx, ...props.sx }, children: listItems.map((item, index) => (_jsx(ListItem, { item: item, index: index, size: size, dataAttributes: dataAttributes, sx: slotSxProps?.listItem }, item.index))) }) }));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SxProps } from "@mui/material";
|
|
2
|
+
import { type SlotSxProps } from "./SelectAutocomplete";
|
|
3
|
+
type Item = {
|
|
4
|
+
label: string;
|
|
5
|
+
value: string | number;
|
|
6
|
+
};
|
|
7
|
+
export declare const SelectFreeSoloAutocomplete: (props: {
|
|
8
|
+
onChange: (value: string, item: Item) => void;
|
|
9
|
+
size?: "small" | "medium";
|
|
10
|
+
slotSxProps?: SlotSxProps;
|
|
11
|
+
items: Item[];
|
|
12
|
+
value?: string;
|
|
13
|
+
sx?: SxProps;
|
|
14
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=SelectFreeSoloAutocomplete.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectFreeSoloAutocomplete.d.ts","sourceRoot":"","sources":["../src/SelectFreeSoloAutocomplete.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA0B,OAAO,EAAE,MAAM,eAAe,CAAC;AAGhE,OAAO,EAAsB,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAO5E,KAAK,IAAI,GAAG;IACV,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,0BAA0B,GAAI,OAAO;IAChD,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IAC9C,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IAC1B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,OAAO,CAAC;CACd,4CAuGA,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Autocomplete, ListItem } from "@mui/material";
|
|
3
|
+
import { useMemo, useState } from "react";
|
|
4
|
+
import { SelectAutocomplete } from "./SelectAutocomplete";
|
|
5
|
+
import { Typography } from "./Typography";
|
|
6
|
+
const sxSelectAutocomplete = SelectAutocomplete.sx;
|
|
7
|
+
const SelectAutocompleteTextField = SelectAutocomplete.TextField;
|
|
8
|
+
const Wrapper = SelectAutocomplete.Wrapper;
|
|
9
|
+
export const SelectFreeSoloAutocomplete = (props) => {
|
|
10
|
+
const { onChange, size, items, value, slotSxProps, sx } = props;
|
|
11
|
+
const [inputValue, setInputValue] = useState("");
|
|
12
|
+
const currentValue = useMemo(() => {
|
|
13
|
+
if (!value) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const item = items.find((item) => item.value == value);
|
|
17
|
+
return item
|
|
18
|
+
? { label: item.label, id: `${item.value}` }
|
|
19
|
+
: { label: `${value}`, id: `${value}` };
|
|
20
|
+
}, [value, items]);
|
|
21
|
+
return (_jsx(Wrapper, { size: size, slotSxProps: slotSxProps, children: _jsx(Autocomplete, { size: "small", freeSolo: true, value: currentValue ?? { label: "", id: "" }, inputValue: inputValue !== "" ? inputValue : currentValue?.label ?? "", options: items.map((item) => ({
|
|
22
|
+
label: item.label,
|
|
23
|
+
id: `${item.value}`,
|
|
24
|
+
})), onInputChange: (_, newInputValue, reason) => {
|
|
25
|
+
if (reason === "input") {
|
|
26
|
+
setInputValue(newInputValue);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
setInputValue("");
|
|
30
|
+
}
|
|
31
|
+
}, onChange: (_, newValue, reason) => {
|
|
32
|
+
if (reason === "createOption" && typeof newValue === "string") {
|
|
33
|
+
const item = { label: newValue, value: newValue };
|
|
34
|
+
onChange(newValue, item);
|
|
35
|
+
setInputValue("");
|
|
36
|
+
}
|
|
37
|
+
else if (reason === "selectOption" &&
|
|
38
|
+
typeof newValue === "object" &&
|
|
39
|
+
newValue !== null) {
|
|
40
|
+
const item = {
|
|
41
|
+
label: newValue.label,
|
|
42
|
+
value: newValue.id,
|
|
43
|
+
};
|
|
44
|
+
onChange(newValue.id, item);
|
|
45
|
+
setInputValue("");
|
|
46
|
+
}
|
|
47
|
+
}, getOptionLabel: (option) => {
|
|
48
|
+
if (typeof option === "string") {
|
|
49
|
+
return option;
|
|
50
|
+
}
|
|
51
|
+
return option.label;
|
|
52
|
+
}, renderInput: (params) => (_jsx(SelectAutocompleteTextField, { params: params, size: size, sx: slotSxProps?.textField })), sx: sxSelectAutocomplete({
|
|
53
|
+
size: size ?? "small",
|
|
54
|
+
sx: slotSxProps?.input ?? sx,
|
|
55
|
+
}), renderOption: (props, option, state) => {
|
|
56
|
+
const { key, ...restProps } = props;
|
|
57
|
+
if (state.selected) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
return (_jsx(ListItem, { ...restProps, onClick: (e) => {
|
|
61
|
+
const item = {
|
|
62
|
+
label: option.label,
|
|
63
|
+
value: option.id,
|
|
64
|
+
};
|
|
65
|
+
onChange(option.id, item);
|
|
66
|
+
setInputValue("");
|
|
67
|
+
restProps?.onClick && restProps.onClick(e);
|
|
68
|
+
}, children: _jsx(Typography, { size: size, sx: slotSxProps?.options, children: option.label }) }, key));
|
|
69
|
+
}, disableClearable: true }) }));
|
|
70
|
+
};
|
package/SortableList.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SortableList.d.ts","sourceRoot":"","sources":["../src/SortableList.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"SortableList.d.ts","sourceRoot":"","sources":["../src/SortableList.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,EAEL,GAAG,EAKJ,MAAM,OAAO,CAAC;AAGf,MAAM,MAAM,oBAAoB,CAAC,CAAC,GAAG,MAAM,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC;AAE/D,KAAK,WAAW,GAAG,UAAU,GAAG,YAAY,GAAG,MAAM,GAAG,gBAAgB,CAAC;AAczE,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;AAEnE,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,GAAG,GAAG,MAAM,EAAE,OAAO;IAC1D,IAAI,EAAE;QAAE,KAAK,EAAE,CAAC,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACpC,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IAC1B,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,WAAW,CAAC,EAAE;QACZ,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB,CAAC;IACF,WAAW,EAAE,WAAW,CAAC;IACzB,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC;IAC5D,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC;CACvD,4CAgPA,CAAC"}
|
package/SortableList.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Box } from "@mui/material";
|
|
3
2
|
import { useMouseMove } from "./hooks/use-mouse-move";
|
|
4
3
|
import { createContext, useEffect, useRef, useState, } from "react";
|
|
5
4
|
import { ListBase } from "./ListBase";
|
|
@@ -9,18 +8,23 @@ export const SortableList = (props) => {
|
|
|
9
8
|
const [items, setItems] = useState([]);
|
|
10
9
|
const targetRef = useRef(null);
|
|
11
10
|
const refPos = useRef({ x: 0, y: 0 });
|
|
11
|
+
const itemRefs = useRef(new Map());
|
|
12
|
+
const draggedItemRef = useRef(null);
|
|
13
|
+
const itemsRef = useRef(items);
|
|
14
|
+
itemsRef.current = items;
|
|
12
15
|
const findItem = (index) => {
|
|
13
16
|
return items.find((item) => item.index === index);
|
|
14
17
|
};
|
|
15
18
|
const swapItems = (_e, fromIndex, toIndex) => {
|
|
16
19
|
console.log("Swapping items", fromIndex, toIndex);
|
|
20
|
+
const currentItems = itemsRef.current;
|
|
17
21
|
if (fromIndex < 0 ||
|
|
18
22
|
toIndex < 0 ||
|
|
19
|
-
fromIndex >=
|
|
20
|
-
toIndex >=
|
|
23
|
+
fromIndex >= currentItems.length ||
|
|
24
|
+
toIndex >= currentItems.length) {
|
|
21
25
|
return;
|
|
22
26
|
}
|
|
23
|
-
const newItems = [...
|
|
27
|
+
const newItems = [...currentItems];
|
|
24
28
|
const temp = newItems[fromIndex];
|
|
25
29
|
newItems[fromIndex] = newItems[toIndex];
|
|
26
30
|
newItems[toIndex] = temp;
|
|
@@ -29,6 +33,90 @@ export const SortableList = (props) => {
|
|
|
29
33
|
setItems(newItems);
|
|
30
34
|
onChange?.(newItems);
|
|
31
35
|
};
|
|
36
|
+
const handleDeltaChange = (e, delta) => {
|
|
37
|
+
const dragged = draggedItemRef.current;
|
|
38
|
+
if (!dragged)
|
|
39
|
+
return;
|
|
40
|
+
const { element, index } = dragged;
|
|
41
|
+
const rect = element.getBoundingClientRect();
|
|
42
|
+
if (!rect)
|
|
43
|
+
return;
|
|
44
|
+
let newY;
|
|
45
|
+
let newX;
|
|
46
|
+
const transformValues = [];
|
|
47
|
+
if (["horizontal", "horizontal-fit", "grid"].includes(displayType)) {
|
|
48
|
+
newX = refPos.current.x + delta.x;
|
|
49
|
+
transformValues.push(`translateX(${newX}px)`);
|
|
50
|
+
refPos.current.x = newX;
|
|
51
|
+
}
|
|
52
|
+
if (displayType === "vertical" || displayType === "grid") {
|
|
53
|
+
newY = refPos.current.y + delta.y;
|
|
54
|
+
transformValues.push(`translateY(${newY}px)`);
|
|
55
|
+
refPos.current.y = newY;
|
|
56
|
+
}
|
|
57
|
+
element.style.transform = transformValues.join(" ");
|
|
58
|
+
const elementsAtPoint = document.elementsFromPoint(e.clientX, e.clientY);
|
|
59
|
+
let foundTarget = null;
|
|
60
|
+
for (const el of elementsAtPoint) {
|
|
61
|
+
// Find the sortable item container (could be the element itself or an ancestor)
|
|
62
|
+
const sortableItem = el.closest("[data-sortable-item-index]");
|
|
63
|
+
if (!sortableItem)
|
|
64
|
+
continue;
|
|
65
|
+
const itemIndex = sortableItem.getAttribute("data-sortable-item-index");
|
|
66
|
+
if (!itemIndex || itemIndex === String(index))
|
|
67
|
+
continue;
|
|
68
|
+
const itemIndexNumber = parseInt(itemIndex);
|
|
69
|
+
if (itemIndexNumber < 0 || itemIndexNumber >= itemsRef.current.length)
|
|
70
|
+
continue;
|
|
71
|
+
foundTarget = sortableItem;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
if (targetRef.current && targetRef.current !== foundTarget) {
|
|
75
|
+
targetRef.current.style.removeProperty("border");
|
|
76
|
+
}
|
|
77
|
+
if (foundTarget && foundTarget !== targetRef.current) {
|
|
78
|
+
foundTarget.style.border = "1px solid red";
|
|
79
|
+
}
|
|
80
|
+
targetRef.current = foundTarget;
|
|
81
|
+
};
|
|
82
|
+
const handleMouseDown = (e) => {
|
|
83
|
+
const dragged = draggedItemRef.current;
|
|
84
|
+
if (!dragged)
|
|
85
|
+
return;
|
|
86
|
+
const { element, index } = dragged;
|
|
87
|
+
console.log("Mouse down on item", index);
|
|
88
|
+
const rect = element.getBoundingClientRect();
|
|
89
|
+
if (rect) {
|
|
90
|
+
refPos.current.y = e.clientY - rect.top - rect.height / 2;
|
|
91
|
+
refPos.current.x = 0;
|
|
92
|
+
element.style.zIndex = "100000";
|
|
93
|
+
element.style.transform = `translate(${refPos.current.x}px, ${refPos.current.y}px)`;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const handleMouseUp = (e) => {
|
|
97
|
+
const dragged = draggedItemRef.current;
|
|
98
|
+
if (!dragged)
|
|
99
|
+
return;
|
|
100
|
+
const { element, index } = dragged;
|
|
101
|
+
refPos.current.y = 0;
|
|
102
|
+
refPos.current.x = 0;
|
|
103
|
+
element.style.removeProperty("transform");
|
|
104
|
+
element.style.removeProperty("z-index");
|
|
105
|
+
if (targetRef.current) {
|
|
106
|
+
const toItemIndex = targetRef.current.getAttribute("data-sortable-item-index");
|
|
107
|
+
swapItems(e, index, toItemIndex ? parseInt(toItemIndex) : -1);
|
|
108
|
+
targetRef.current?.style.removeProperty("border");
|
|
109
|
+
targetRef.current = null;
|
|
110
|
+
}
|
|
111
|
+
draggedItemRef.current = null;
|
|
112
|
+
};
|
|
113
|
+
const { initMouseMove } = useMouseMove({
|
|
114
|
+
onDeltaChange: handleDeltaChange,
|
|
115
|
+
onMouseUp: handleMouseUp,
|
|
116
|
+
onMouseDown: handleMouseDown,
|
|
117
|
+
cursor: "grabbing",
|
|
118
|
+
threshold: 1,
|
|
119
|
+
});
|
|
32
120
|
useEffect(() => {
|
|
33
121
|
const initialItems = props.enum.map((item, index) => ({
|
|
34
122
|
index,
|
|
@@ -58,83 +146,17 @@ export const SortableList = (props) => {
|
|
|
58
146
|
gap: 1,
|
|
59
147
|
};
|
|
60
148
|
}
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
149
|
+
const handleItemMouseDown = (item, e) => {
|
|
150
|
+
// Find the MuiListItem parent element
|
|
151
|
+
const listItemElement = e.target.closest("[data-sortable-item-index]");
|
|
152
|
+
if (listItemElement) {
|
|
153
|
+
itemRefs.current.set(item.index, listItemElement);
|
|
154
|
+
draggedItemRef.current = { index: item.index, element: listItemElement };
|
|
155
|
+
initMouseMove(listItemElement)(e);
|
|
156
|
+
}
|
|
65
157
|
};
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
if (!ref)
|
|
69
|
-
return () => { };
|
|
70
|
-
const handleDeltaChange = (e, delta) => {
|
|
71
|
-
const rect = ref.current?.getBoundingClientRect();
|
|
72
|
-
if (!rect)
|
|
73
|
-
return;
|
|
74
|
-
let newY;
|
|
75
|
-
let newX;
|
|
76
|
-
const transformValues = [];
|
|
77
|
-
if (["horizontal", "horizontal-fit", "grid"].includes(displayType)) {
|
|
78
|
-
newX = refPos.current.x + delta.x;
|
|
79
|
-
transformValues.push(`translateX(${newX}px)`);
|
|
80
|
-
refPos.current.x = newX;
|
|
81
|
-
}
|
|
82
|
-
if (displayType === "vertical" || displayType === "grid") {
|
|
83
|
-
newY = refPos.current.y + delta.y;
|
|
84
|
-
transformValues.push(`translateY(${newY}px)`);
|
|
85
|
-
refPos.current.y = newY;
|
|
86
|
-
}
|
|
87
|
-
ref.current.style.transform = transformValues.join(" ");
|
|
88
|
-
const elementsAtPoint = document.elementsFromPoint(e.clientX, e.clientY);
|
|
89
|
-
for (const element of elementsAtPoint) {
|
|
90
|
-
const itemIndex = element.getAttribute("data-sortable-item-index");
|
|
91
|
-
if (!itemIndex || itemIndex === String(item.index)) {
|
|
92
|
-
if (targetRef.current) {
|
|
93
|
-
targetRef.current.style.removeProperty("border");
|
|
94
|
-
targetRef.current = null;
|
|
95
|
-
}
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
const itemIndexNumber = parseInt(itemIndex);
|
|
99
|
-
if (itemIndexNumber < 0 || itemIndexNumber >= items.length)
|
|
100
|
-
continue;
|
|
101
|
-
if (targetRef.current) {
|
|
102
|
-
targetRef.current.style.removeProperty("border");
|
|
103
|
-
}
|
|
104
|
-
targetRef.current = element;
|
|
105
|
-
targetRef.current.style.border = "1px solid red";
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
const handleMouseDown = (e) => {
|
|
110
|
-
const rect = ref.current?.getBoundingClientRect();
|
|
111
|
-
if (rect) {
|
|
112
|
-
refPos.current.y = e.clientY - rect.top - rect.height / 2;
|
|
113
|
-
refPos.current.x = 0;
|
|
114
|
-
ref.current.style.zIndex = "100000";
|
|
115
|
-
ref.current.style.transform = `translate(${refPos.current.x}px, ${refPos.current.y}px)`;
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
const handleMouseUp = (e) => {
|
|
119
|
-
refPos.current.y = 0;
|
|
120
|
-
refPos.current.x = 0;
|
|
121
|
-
ref.current?.style.removeProperty("transform");
|
|
122
|
-
ref.current?.style.removeProperty("z-index");
|
|
123
|
-
if (targetRef.current) {
|
|
124
|
-
const toItemIndex = targetRef.current.getAttribute("data-sortable-item-index");
|
|
125
|
-
swapItems(e, item.index, toItemIndex ? parseInt(toItemIndex) : -1);
|
|
126
|
-
targetRef.current?.style.removeProperty("border");
|
|
127
|
-
targetRef.current = null;
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
const { initMouseMove } = useMouseMove({
|
|
131
|
-
onDeltaChange: handleDeltaChange,
|
|
132
|
-
onMouseUp: handleMouseUp,
|
|
133
|
-
onMouseDown: handleMouseDown,
|
|
134
|
-
cursor: "grabbing",
|
|
135
|
-
threshold: 1,
|
|
136
|
-
});
|
|
137
|
-
return initMouseMove(ref);
|
|
158
|
+
const renderSortableItem = (item) => {
|
|
159
|
+
return renderItem ? renderItem(item) : item.label;
|
|
138
160
|
};
|
|
139
161
|
return (_jsx(SortableContext.Provider, { value: {
|
|
140
162
|
items,
|
|
@@ -143,5 +165,11 @@ export const SortableList = (props) => {
|
|
|
143
165
|
refPos,
|
|
144
166
|
targetRef,
|
|
145
167
|
displayType,
|
|
146
|
-
}, children: _jsx(ListBase, { items: items, size: size, sx: { ...sx, ...props.sx }, displayType: displayType, renderItem: renderSortableItem, onDelete: onDelete, onEdit: onEdit
|
|
168
|
+
}, children: _jsx(ListBase, { items: items, size: size, sx: { ...sx, ...props.sx }, displayType: displayType, renderItem: renderSortableItem, onDelete: onDelete, onEdit: onEdit, onMouseDown: handleItemMouseDown, getItemDataAttributes: (item) => ({
|
|
169
|
+
"data-sortable-item-index": item.index,
|
|
170
|
+
}), slotSxProps: {
|
|
171
|
+
listItem: {
|
|
172
|
+
cursor: "move",
|
|
173
|
+
},
|
|
174
|
+
} }) }));
|
|
147
175
|
};
|