@eightshift/ui-components 1.4.4 → 1.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/style.css +1 -1
- package/dist/assets/wp-ui-enhancements.css +1 -1
- package/dist/components/animated-visibility/animated-visibility.js +132 -162
- package/dist/components/button/button.js +6 -2
- package/dist/components/input-field/input-field.js +3 -1
- package/dist/components/link-input/link-input.js +2 -2
- package/dist/components/menu/menu.js +1 -2
- package/dist/components/option-select/option-select.js +12 -6
- package/dist/components/popover/popover.js +8 -2
- package/dist/components/repeater/repeater.js +4 -8
- package/dist/components/select/async-multi-select.js +6 -3
- package/dist/components/select/async-single-select.js +4 -1
- package/dist/components/select/multi-select.js +11 -4
- package/dist/components/select/shared.js +7 -56
- package/dist/components/select/single-select.js +9 -2
- package/package.json +9 -9
- package/dist/hooks/use-cell-edit-mode.js +0 -35
|
@@ -92,8 +92,11 @@ const AsyncMultiSelect = (props) => {
|
|
|
92
92
|
const idBase = useId();
|
|
93
93
|
const value = rawValue.map((item, index) => ({
|
|
94
94
|
...item,
|
|
95
|
-
id: `${idBase}-${index}`
|
|
95
|
+
id: (item == null ? void 0 : item.value) ?? `${idBase}-${index}`
|
|
96
96
|
}));
|
|
97
|
+
const modifiedOnChange = (v) => {
|
|
98
|
+
onChange(v == null ? void 0 : v.map((item) => ({ ...item, id: void 0 })));
|
|
99
|
+
};
|
|
97
100
|
if (hidden) {
|
|
98
101
|
return null;
|
|
99
102
|
}
|
|
@@ -114,7 +117,7 @@ const AsyncMultiSelect = (props) => {
|
|
|
114
117
|
DndContext,
|
|
115
118
|
{
|
|
116
119
|
modifiers: [restrictToParentElement],
|
|
117
|
-
onDragEnd: getDragEndHandler(
|
|
120
|
+
onDragEnd: getDragEndHandler(modifiedOnChange, value),
|
|
118
121
|
children: /* @__PURE__ */ jsx(SortableContext, { items: value.map(({ id }) => id), children: /* @__PURE__ */ jsx(
|
|
119
122
|
AsyncSelect$1,
|
|
120
123
|
{
|
|
@@ -123,7 +126,7 @@ const AsyncMultiSelect = (props) => {
|
|
|
123
126
|
loadOptions: customLoadOptions,
|
|
124
127
|
defaultOptions: preloadOptions,
|
|
125
128
|
value,
|
|
126
|
-
onChange,
|
|
129
|
+
onChange: modifiedOnChange,
|
|
127
130
|
closeMenuOnSelect: !keepMenuOpenAfterSelect,
|
|
128
131
|
isClearable: clearable,
|
|
129
132
|
isSearchable: !noSearch,
|
|
@@ -105,7 +105,10 @@ const AsyncSelect = (props) => {
|
|
|
105
105
|
loadOptions: customLoadOptions,
|
|
106
106
|
defaultOptions: preloadOptions,
|
|
107
107
|
value,
|
|
108
|
-
onChange
|
|
108
|
+
onChange: (value2) => {
|
|
109
|
+
delete value2.id;
|
|
110
|
+
onChange(value2);
|
|
111
|
+
},
|
|
109
112
|
closeMenuOnSelect: !keepMenuOpenAfterSelect,
|
|
110
113
|
isClearable: clearable,
|
|
111
114
|
isSearchable: !noSearch,
|
|
@@ -4,7 +4,7 @@ import { S as StateManagedSelect$1 } from "../../react-select.esm-DkSeQzOP.js";
|
|
|
4
4
|
import { D as DndContext, g as getDragEndHandler, S as SortableContext, a as getMultiValue, b as getMultiValueRemove } from "../../multi-select-components-DTvEidE3.js";
|
|
5
5
|
import { r as restrictToParentElement } from "../../modifiers.esm-BuJQPI1X.js";
|
|
6
6
|
import { CustomSelectDefaultMultiValueRemove, CustomSelectDefaultDropdownIndicator, CustomSelectDefaultClearIndicator } from "./custom-select-default-components.js";
|
|
7
|
-
import { getValue
|
|
7
|
+
import { getValue } from "./shared.js";
|
|
8
8
|
import { BaseControl } from "../base-control/base-control.js";
|
|
9
9
|
import { eightshiftSelectClasses } from "./styles.js";
|
|
10
10
|
import { c as components } from "../../index-a301f526.esm-B9tWL9yi.js";
|
|
@@ -87,8 +87,15 @@ const MultiSelect = (props) => {
|
|
|
87
87
|
const idBase = useId();
|
|
88
88
|
const value = getValue(simpleValue, rawValue, options).map((item, index) => ({
|
|
89
89
|
...item,
|
|
90
|
-
id: `${idBase}-${index}`
|
|
90
|
+
id: (simpleValue ? item : item == null ? void 0 : item.value) ?? `${idBase}-${index}`
|
|
91
91
|
}));
|
|
92
|
+
const modifiedOnChange = (v) => {
|
|
93
|
+
if (simpleValue) {
|
|
94
|
+
onChange(v == null ? void 0 : v.map(({ value: value2 }) => value2));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
onChange(v == null ? void 0 : v.map((item) => ({ ...item, id: void 0 })));
|
|
98
|
+
};
|
|
92
99
|
if (hidden) {
|
|
93
100
|
return null;
|
|
94
101
|
}
|
|
@@ -105,7 +112,7 @@ const MultiSelect = (props) => {
|
|
|
105
112
|
DndContext,
|
|
106
113
|
{
|
|
107
114
|
modifiers: [restrictToParentElement],
|
|
108
|
-
onDragEnd: getDragEndHandler(
|
|
115
|
+
onDragEnd: getDragEndHandler(modifiedOnChange, value),
|
|
109
116
|
children: /* @__PURE__ */ jsx(SortableContext, { items: value.map(({ id }) => id), children: /* @__PURE__ */ jsx(
|
|
110
117
|
StateManagedSelect$1,
|
|
111
118
|
{
|
|
@@ -113,7 +120,7 @@ const MultiSelect = (props) => {
|
|
|
113
120
|
unstyled: true,
|
|
114
121
|
options: options.map((item) => ({ id: item.value, ...item })),
|
|
115
122
|
value,
|
|
116
|
-
onChange:
|
|
123
|
+
onChange: modifiedOnChange,
|
|
117
124
|
closeMenuOnSelect: !keepMenuOpenAfterSelect,
|
|
118
125
|
isClearable: clearable,
|
|
119
126
|
isSearchable: !noSearch,
|
|
@@ -10,66 +10,17 @@
|
|
|
10
10
|
* @preserve
|
|
11
11
|
*/
|
|
12
12
|
const getValue = (simpleValue, value, options) => {
|
|
13
|
-
if (!simpleValue) {
|
|
14
|
-
return value;
|
|
15
|
-
}
|
|
16
13
|
if (Array.isArray(value)) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Handles the `onChange` callback.
|
|
23
|
-
*
|
|
24
|
-
* @param {boolean} simpleValue - Whether `simpleValue` is set.
|
|
25
|
-
* @param {string|{label: string, value: string, metadata: Object<string, any>[]}} newValue - The new value to be set.
|
|
26
|
-
* @param {Function} onChange - The `onChange` callback passed to the component.
|
|
27
|
-
* @returns {void}
|
|
28
|
-
*
|
|
29
|
-
* @preserve
|
|
30
|
-
*/
|
|
31
|
-
const customOnChange = (simpleValue, newValue, onChange) => {
|
|
32
|
-
if (typeof newValue === "undefined" || newValue === null || newValue === "") {
|
|
33
|
-
onChange(void 0);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
delete newValue.id;
|
|
37
|
-
if (!simpleValue) {
|
|
38
|
-
onChange(newValue);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
if (Array.isArray(newValue)) {
|
|
42
|
-
onChange(newValue.map((item) => item == null ? void 0 : item.value));
|
|
43
|
-
return;
|
|
14
|
+
if (simpleValue) {
|
|
15
|
+
return value.map((value2) => options == null ? void 0 : options.find(({ value: itemValue }) => itemValue === value2));
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
44
18
|
}
|
|
45
|
-
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Handles the `onChange` callback.
|
|
49
|
-
*
|
|
50
|
-
* @param {object[]} items - Current items.
|
|
51
|
-
* @param {Function} onChange - The `onChange` callback passed to the component.
|
|
52
|
-
* @returns {void}
|
|
53
|
-
*
|
|
54
|
-
* @preserve
|
|
55
|
-
*/
|
|
56
|
-
const fixIds = (items, onChange) => {
|
|
57
|
-
const allIds = (items == null ? void 0 : items.map(({ id }) => id)) ?? [];
|
|
58
|
-
const hasDuplicates = (input) => {
|
|
59
|
-
var _a;
|
|
60
|
-
return ((_a = new Set(input)) == null ? void 0 : _a.size) !== (input == null ? void 0 : input.length);
|
|
61
|
-
};
|
|
62
|
-
const hasMissingIds = items == null ? void 0 : items.some(({ id }) => typeof id === "undefined" || id === null || id === "");
|
|
63
|
-
if (hasDuplicates(allIds) && (items == null ? void 0 : items.length) > 0 || hasMissingIds) {
|
|
64
|
-
const newItems = [...items].map((item, index) => ({
|
|
65
|
-
...item,
|
|
66
|
-
id: index + 1
|
|
67
|
-
}));
|
|
68
|
-
onChange(newItems);
|
|
19
|
+
if (simpleValue) {
|
|
20
|
+
return options == null ? void 0 : options.find(({ value: itemValue }) => itemValue === value);
|
|
69
21
|
}
|
|
22
|
+
return value;
|
|
70
23
|
};
|
|
71
24
|
export {
|
|
72
|
-
customOnChange,
|
|
73
|
-
fixIds,
|
|
74
25
|
getValue
|
|
75
26
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { S as StateManagedSelect$1 } from "../../react-select.esm-DkSeQzOP.js";
|
|
3
3
|
import { CustomSelectDefaultDropdownIndicator, CustomSelectDefaultClearIndicator } from "./custom-select-default-components.js";
|
|
4
|
-
import { getValue
|
|
4
|
+
import { getValue } from "./shared.js";
|
|
5
5
|
import { BaseControl } from "../base-control/base-control.js";
|
|
6
6
|
import { eightshiftSelectClasses } from "./styles.js";
|
|
7
7
|
import { c as components } from "../../index-a301f526.esm-B9tWL9yi.js";
|
|
@@ -95,7 +95,14 @@ const Select = (props) => {
|
|
|
95
95
|
unstyled: true,
|
|
96
96
|
options,
|
|
97
97
|
value: getValue(simpleValue, value, options),
|
|
98
|
-
onChange: (v) =>
|
|
98
|
+
onChange: (v) => {
|
|
99
|
+
if (simpleValue) {
|
|
100
|
+
onChange(v == null ? void 0 : v.value);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
delete v.id;
|
|
104
|
+
onChange(v);
|
|
105
|
+
},
|
|
99
106
|
closeMenuOnSelect: !keepMenuOpenAfterSelect,
|
|
100
107
|
isClearable: clearable,
|
|
101
108
|
isSearchable: !noSearch,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eightshift/ui-components",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -53,29 +53,29 @@
|
|
|
53
53
|
"@dnd-kit/utilities": "^3.2.2",
|
|
54
54
|
"@eslint/compat": "^1.1.1",
|
|
55
55
|
"@react-stately/collections": "^3.10.9",
|
|
56
|
-
"@stylistic/eslint-plugin-js": "^2.
|
|
56
|
+
"@stylistic/eslint-plugin-js": "^2.6.1",
|
|
57
57
|
"@types/react": "^18.3.3",
|
|
58
58
|
"@types/react-dom": "^18.3.0",
|
|
59
59
|
"@vitejs/plugin-react-swc": "^3.7.0",
|
|
60
60
|
"@wordpress/i18n": "^5.4.0",
|
|
61
|
-
"autoprefixer": "^10.4.
|
|
61
|
+
"autoprefixer": "^10.4.20",
|
|
62
62
|
"clsx": "^2.1.1",
|
|
63
63
|
"css-gradient-parser": "^0.0.16",
|
|
64
|
-
"eslint": "^9.
|
|
64
|
+
"eslint": "^9.8.0",
|
|
65
65
|
"eslint-config-prettier": "^9.1.0",
|
|
66
|
-
"eslint-plugin-jsdoc": "^
|
|
66
|
+
"eslint-plugin-jsdoc": "^50.0.0",
|
|
67
67
|
"eslint-plugin-prettier": "^5.2.1",
|
|
68
|
-
"framer-motion": "^11.3.
|
|
68
|
+
"framer-motion": "^11.3.22",
|
|
69
69
|
"glob": "^11.0.0",
|
|
70
|
-
"globals": "^15.
|
|
70
|
+
"globals": "^15.9.0",
|
|
71
71
|
"just-camel-case": "^6.2.0",
|
|
72
72
|
"just-debounce-it": "^3.2.0",
|
|
73
73
|
"just-has": "^2.3.0",
|
|
74
74
|
"just-is-empty": "^3.4.1",
|
|
75
75
|
"just-kebab-case": "^4.2.0",
|
|
76
76
|
"just-throttle": "^4.2.0",
|
|
77
|
-
"lightningcss": "^1.
|
|
78
|
-
"postcss": "^8.4.
|
|
77
|
+
"lightningcss": "^1.26.0",
|
|
78
|
+
"postcss": "^8.4.41",
|
|
79
79
|
"prettier": "^3.3.3",
|
|
80
80
|
"prettier-plugin-tailwindcss": "^0.6.5",
|
|
81
81
|
"react-aria": "^3.34.1",
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { useRef, useEffect } from "react";
|
|
2
|
-
function useCellEditMode() {
|
|
3
|
-
const isFocusedRef = useRef(false);
|
|
4
|
-
const isEditModeRef = useRef(false);
|
|
5
|
-
useEffect(() => {
|
|
6
|
-
const handler = (e) => {
|
|
7
|
-
if (isFocusedRef.current) {
|
|
8
|
-
if (e.code === "Enter") {
|
|
9
|
-
isEditModeRef.current = true;
|
|
10
|
-
} else if (e.code === "Escape" || e.code === "Tab") {
|
|
11
|
-
isEditModeRef.current = false;
|
|
12
|
-
}
|
|
13
|
-
if (isEditModeRef.current) {
|
|
14
|
-
e.stopPropagation();
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
window.addEventListener("keydown", handler, true);
|
|
19
|
-
return () => {
|
|
20
|
-
window.removeEventListener("keydown", handler, true);
|
|
21
|
-
};
|
|
22
|
-
}, []);
|
|
23
|
-
const setFocus = (should) => isFocusedRef.current = should;
|
|
24
|
-
const preventProps = {
|
|
25
|
-
onFocus: () => setFocus(true),
|
|
26
|
-
onBlur: () => setFocus(false),
|
|
27
|
-
onClick: () => {
|
|
28
|
-
isEditModeRef.current = true;
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
return preventProps;
|
|
32
|
-
}
|
|
33
|
-
export {
|
|
34
|
-
useCellEditMode
|
|
35
|
-
};
|