@eightshift/ui-components 6.0.6 → 6.0.8
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-admin.css +13 -2
- package/dist/assets/style-editor.css +13 -2
- package/dist/assets/style.css +13 -2
- package/dist/components/draggable/draggable.js +35 -36
- package/dist/components/draggable-list/draggable-list.js +10 -15
- package/dist/components/expandable/expandable.js +1 -1
- package/dist/components/repeater/repeater-item.js +3 -2
- package/dist/components/repeater/repeater.js +22 -22
- package/package.json +1 -1
|
@@ -2501,8 +2501,8 @@ input[data-rac]::-webkit-search-cancel-button {
|
|
|
2501
2501
|
translate: var(--tw-translate-x) var(--tw-translate-y);
|
|
2502
2502
|
}
|
|
2503
2503
|
|
|
2504
|
-
:is(body, body #wpwrap) .es\:translate-y-
|
|
2505
|
-
--tw-translate-y: calc(var(--es-spacing) *
|
|
2504
|
+
:is(body, body #wpwrap) .es\:translate-y-1 {
|
|
2505
|
+
--tw-translate-y: calc(var(--es-spacing) * 1);
|
|
2506
2506
|
translate: var(--tw-translate-x) var(--tw-translate-y);
|
|
2507
2507
|
}
|
|
2508
2508
|
|
|
@@ -7859,6 +7859,17 @@ input[data-rac]::-webkit-search-cancel-button {
|
|
|
7859
7859
|
grid-row-end: 1;
|
|
7860
7860
|
}
|
|
7861
7861
|
|
|
7862
|
+
:is(:is(body, body #wpwrap) .es\:\*\:motion-preset-fade-sm > *) {
|
|
7863
|
+
--motion-origin-opacity: 0;
|
|
7864
|
+
--motion-duration: .3s;
|
|
7865
|
+
--motion-opacity-in-animation: motion-opacity-in calc(var(--motion-opacity-duration, var(--motion-duration)) * var(--motion-opacity-perceptual-duration-multiplier, var(--motion-perceptual-duration-multiplier))) var(--motion-opacity-timing, var(--motion-timing)) var(--motion-opacity-delay, var(--motion-delay)) both;
|
|
7866
|
+
animation: var(--motion-scale-in-animation), var(--motion-translate-in-animation), var(--motion-rotate-in-animation), var(--motion-filter-in-animation), var(--motion-opacity-in-animation), var(--motion-background-color-in-animation), var(--motion-text-color-in-animation), var(--motion-scale-loop-animation), var(--motion-translate-loop-animation), var(--motion-rotate-loop-animation), var(--motion-filter-loop-animation), var(--motion-opacity-loop-animation), var(--motion-background-color-loop-animation), var(--motion-text-color-loop-animation);
|
|
7867
|
+
}
|
|
7868
|
+
|
|
7869
|
+
:is(:is(body, body #wpwrap) .es\:\*\:motion-delay-75 > *) {
|
|
7870
|
+
--motion-delay: 75ms;
|
|
7871
|
+
}
|
|
7872
|
+
|
|
7862
7873
|
:is(body, body #wpwrap) .es\:not-group-first\:not-group-before-current\:rounded-t-md:not(:is(:where(.es\:group):first-child *)):not(:is(:where(.es\:group):has( + :where(:pressed, :active, [data-selected="true"], [data-focus-visible="true"], [data-hovered="true"], [aria-expanded="true"], [data-expanded="true"])) *)) {
|
|
7863
7874
|
border-top-left-radius: var(--es-radius-md);
|
|
7864
7875
|
border-top-right-radius: var(--es-radius-md);
|
|
@@ -2469,8 +2469,8 @@ button, input:where([type="button"], [type="reset"], [type="submit"]) {
|
|
|
2469
2469
|
translate: var(--tw-translate-x) var(--tw-translate-y);
|
|
2470
2470
|
}
|
|
2471
2471
|
|
|
2472
|
-
:is(body, #wpwrap #editor) .es\:translate-y-
|
|
2473
|
-
--tw-translate-y: calc(var(--es-spacing) *
|
|
2472
|
+
:is(body, #wpwrap #editor) .es\:translate-y-1 {
|
|
2473
|
+
--tw-translate-y: calc(var(--es-spacing) * 1);
|
|
2474
2474
|
translate: var(--tw-translate-x) var(--tw-translate-y);
|
|
2475
2475
|
}
|
|
2476
2476
|
|
|
@@ -7827,6 +7827,17 @@ button, input:where([type="button"], [type="reset"], [type="submit"]) {
|
|
|
7827
7827
|
grid-row-end: 1;
|
|
7828
7828
|
}
|
|
7829
7829
|
|
|
7830
|
+
:is(:is(body, #wpwrap #editor) .es\:\*\:motion-preset-fade-sm > *) {
|
|
7831
|
+
--motion-origin-opacity: 0;
|
|
7832
|
+
--motion-duration: .3s;
|
|
7833
|
+
--motion-opacity-in-animation: motion-opacity-in calc(var(--motion-opacity-duration, var(--motion-duration)) * var(--motion-opacity-perceptual-duration-multiplier, var(--motion-perceptual-duration-multiplier))) var(--motion-opacity-timing, var(--motion-timing)) var(--motion-opacity-delay, var(--motion-delay)) both;
|
|
7834
|
+
animation: var(--motion-scale-in-animation), var(--motion-translate-in-animation), var(--motion-rotate-in-animation), var(--motion-filter-in-animation), var(--motion-opacity-in-animation), var(--motion-background-color-in-animation), var(--motion-text-color-in-animation), var(--motion-scale-loop-animation), var(--motion-translate-loop-animation), var(--motion-rotate-loop-animation), var(--motion-filter-loop-animation), var(--motion-opacity-loop-animation), var(--motion-background-color-loop-animation), var(--motion-text-color-loop-animation);
|
|
7835
|
+
}
|
|
7836
|
+
|
|
7837
|
+
:is(:is(body, #wpwrap #editor) .es\:\*\:motion-delay-75 > *) {
|
|
7838
|
+
--motion-delay: 75ms;
|
|
7839
|
+
}
|
|
7840
|
+
|
|
7830
7841
|
:is(body, #wpwrap #editor) .es\:not-group-first\:not-group-before-current\:rounded-t-md:not(:is(:where(.es\:group):first-child *)):not(:is(:where(.es\:group):has( + :where(:pressed, :active, [data-selected="true"], [data-focus-visible="true"], [data-hovered="true"], [aria-expanded="true"], [data-expanded="true"])) *)) {
|
|
7831
7842
|
border-top-left-radius: var(--es-radius-md);
|
|
7832
7843
|
border-top-right-radius: var(--es-radius-md);
|
package/dist/assets/style.css
CHANGED
|
@@ -2954,8 +2954,8 @@ input[data-rac]::-webkit-search-cancel-button {
|
|
|
2954
2954
|
translate: var(--tw-translate-x) var(--tw-translate-y);
|
|
2955
2955
|
}
|
|
2956
2956
|
|
|
2957
|
-
.es\:translate-y-
|
|
2958
|
-
--tw-translate-y: calc(var(--es-spacing) *
|
|
2957
|
+
.es\:translate-y-1 {
|
|
2958
|
+
--tw-translate-y: calc(var(--es-spacing) * 1);
|
|
2959
2959
|
translate: var(--tw-translate-x) var(--tw-translate-y);
|
|
2960
2960
|
}
|
|
2961
2961
|
|
|
@@ -8312,6 +8312,17 @@ input[data-rac]::-webkit-search-cancel-button {
|
|
|
8312
8312
|
grid-row-end: 1;
|
|
8313
8313
|
}
|
|
8314
8314
|
|
|
8315
|
+
:is(.es\:\*\:motion-preset-fade-sm > *) {
|
|
8316
|
+
--motion-origin-opacity: 0;
|
|
8317
|
+
--motion-duration: .3s;
|
|
8318
|
+
--motion-opacity-in-animation: motion-opacity-in calc(var(--motion-opacity-duration, var(--motion-duration)) * var(--motion-opacity-perceptual-duration-multiplier, var(--motion-perceptual-duration-multiplier))) var(--motion-opacity-timing, var(--motion-timing)) var(--motion-opacity-delay, var(--motion-delay)) both;
|
|
8319
|
+
animation: var(--motion-scale-in-animation), var(--motion-translate-in-animation), var(--motion-rotate-in-animation), var(--motion-filter-in-animation), var(--motion-opacity-in-animation), var(--motion-background-color-in-animation), var(--motion-text-color-in-animation), var(--motion-scale-loop-animation), var(--motion-translate-loop-animation), var(--motion-rotate-loop-animation), var(--motion-filter-loop-animation), var(--motion-opacity-loop-animation), var(--motion-background-color-loop-animation), var(--motion-text-color-loop-animation);
|
|
8320
|
+
}
|
|
8321
|
+
|
|
8322
|
+
:is(.es\:\*\:motion-delay-75 > *) {
|
|
8323
|
+
--motion-delay: 75ms;
|
|
8324
|
+
}
|
|
8325
|
+
|
|
8315
8326
|
.es\:not-group-first\:not-group-before-current\:rounded-t-md:not(:is(:where(.es\:group):first-child *)):not(:is(:where(.es\:group):has( + :where(:pressed, :active, [data-selected="true"], [data-focus-visible="true"], [data-hovered="true"], [aria-expanded="true"], [data-expanded="true"])) *)) {
|
|
8316
8327
|
border-top-left-radius: var(--es-radius-md);
|
|
8317
8328
|
border-top-right-radius: var(--es-radius-md);
|
|
@@ -3,6 +3,7 @@ import { useEffect, useRef, useLayoutEffect, useMemo, useState, useCallback, sta
|
|
|
3
3
|
import { _ as __ } from "../../default-i18n-CnQeC5Pl.js";
|
|
4
4
|
import { DraggableContext } from "./draggable-context.js";
|
|
5
5
|
import { r as reactDomExports } from "../../index-oFgxU4zs.js";
|
|
6
|
+
import { randomId } from "../../utilities/hash.js";
|
|
6
7
|
var i = Symbol.for("preact-signals");
|
|
7
8
|
function t() {
|
|
8
9
|
if (!(s > 1)) {
|
|
@@ -7005,11 +7006,11 @@ var _AxisModifier = class _AxisModifier2 extends Modifier {
|
|
|
7005
7006
|
};
|
|
7006
7007
|
_AxisModifier.configure = configurator(_AxisModifier);
|
|
7007
7008
|
var AxisModifier = _AxisModifier;
|
|
7008
|
-
AxisModifier.configure({
|
|
7009
|
+
var RestrictToVerticalAxis = AxisModifier.configure({
|
|
7009
7010
|
axis: "x",
|
|
7010
7011
|
value: 0
|
|
7011
7012
|
});
|
|
7012
|
-
AxisModifier.configure({
|
|
7013
|
+
var RestrictToHorizontalAxis = AxisModifier.configure({
|
|
7013
7014
|
axis: "y",
|
|
7014
7015
|
value: 0
|
|
7015
7016
|
});
|
|
@@ -7222,21 +7223,22 @@ function mutate(items, event, mutation) {
|
|
|
7222
7223
|
function move(items, event) {
|
|
7223
7224
|
return mutate(items, event, arrayMove);
|
|
7224
7225
|
}
|
|
7225
|
-
const fixIds = (items, itemIdBase) => {
|
|
7226
|
-
return items?.map((item, i2) => ({
|
|
7227
|
-
...item,
|
|
7228
|
-
id: item?.id ?? `${itemIdBase}-${i2}`
|
|
7229
|
-
})) ?? [];
|
|
7230
|
-
};
|
|
7231
7226
|
const SortableItem = ({ id, index, disabled, children, axis }) => {
|
|
7232
7227
|
const [element, setElement] = useState(null);
|
|
7233
7228
|
const handleRef = useRef(null);
|
|
7229
|
+
let modifiers = [RestrictToElement];
|
|
7230
|
+
if (axis === "horizontal") {
|
|
7231
|
+
modifiers.push(RestrictToHorizontalAxis);
|
|
7232
|
+
}
|
|
7233
|
+
if (axis === "vertical") {
|
|
7234
|
+
modifiers.push(RestrictToVerticalAxis);
|
|
7235
|
+
}
|
|
7234
7236
|
const { isDragSource, status } = useSortable({
|
|
7235
7237
|
id,
|
|
7236
7238
|
index,
|
|
7237
7239
|
element,
|
|
7238
7240
|
type: "item",
|
|
7239
|
-
modifiers
|
|
7241
|
+
modifiers,
|
|
7240
7242
|
transition: { idle: true, duration: 400, easing: "cubic-bezier(0, 0.55, 0.45, 1)" },
|
|
7241
7243
|
// 'easeOutCirc'
|
|
7242
7244
|
handle: handleRef,
|
|
@@ -7280,7 +7282,7 @@ const SortableItem = ({ id, index, disabled, children, axis }) => {
|
|
|
7280
7282
|
* @preserve
|
|
7281
7283
|
*/
|
|
7282
7284
|
const Draggable3 = (props) => {
|
|
7283
|
-
|
|
7285
|
+
useId("draggable-list-item-");
|
|
7284
7286
|
const {
|
|
7285
7287
|
children,
|
|
7286
7288
|
items: rawItems,
|
|
@@ -7295,9 +7297,9 @@ const Draggable3 = (props) => {
|
|
|
7295
7297
|
if (typeof rawItems === "undefined" || rawItems === null || !Array.isArray(rawItems)) {
|
|
7296
7298
|
console.warn(__("Draggable: 'items' are not an array or are undefined!", "eightshift-ui-components"));
|
|
7297
7299
|
}
|
|
7298
|
-
const [items, setItems] = useState(
|
|
7300
|
+
const [items, setItems] = useState(rawItems);
|
|
7299
7301
|
useEffect(() => {
|
|
7300
|
-
setItems(
|
|
7302
|
+
setItems(rawItems);
|
|
7301
7303
|
}, [rawItems]);
|
|
7302
7304
|
if (hidden) {
|
|
7303
7305
|
return null;
|
|
@@ -7321,36 +7323,33 @@ const Draggable3 = (props) => {
|
|
|
7321
7323
|
children: items.map((item, index) => /* @__PURE__ */ jsx(
|
|
7322
7324
|
SortableItem,
|
|
7323
7325
|
{
|
|
7324
|
-
id:
|
|
7326
|
+
id: randomId(6),
|
|
7325
7327
|
index,
|
|
7326
7328
|
item,
|
|
7327
7329
|
disabled: noReorder,
|
|
7328
7330
|
axis,
|
|
7329
|
-
children: (handleRef, isDragSource, status) => /* @__PURE__ */ jsx(
|
|
7330
|
-
|
|
7331
|
-
{
|
|
7332
|
-
|
|
7333
|
-
|
|
7334
|
-
...
|
|
7335
|
-
|
|
7336
|
-
|
|
7337
|
-
|
|
7338
|
-
|
|
7339
|
-
},
|
|
7340
|
-
itemIndex: index,
|
|
7341
|
-
deleteItem: () => {
|
|
7342
|
-
setItems([...items].filter((i2) => i2.id !== item.id));
|
|
7343
|
-
onChange([...items].filter((i2) => i2.id !== item.id));
|
|
7344
|
-
if (onAfterItemRemove) {
|
|
7345
|
-
onAfterItemRemove(item);
|
|
7346
|
-
}
|
|
7347
|
-
}
|
|
7348
|
-
})
|
|
7331
|
+
children: (handleRef, isDragSource, status) => /* @__PURE__ */ jsx(DraggableContext.Provider, { value: { isDragSource, handleRef, status }, children: children({
|
|
7332
|
+
...item,
|
|
7333
|
+
updateData: (newValue) => {
|
|
7334
|
+
const updated = [...items];
|
|
7335
|
+
updated[index] = {
|
|
7336
|
+
...updated[index],
|
|
7337
|
+
...newValue
|
|
7338
|
+
};
|
|
7339
|
+
onChange(updated);
|
|
7340
|
+
setItems(updated);
|
|
7349
7341
|
},
|
|
7350
|
-
|
|
7351
|
-
|
|
7342
|
+
itemIndex: index,
|
|
7343
|
+
deleteItem: () => {
|
|
7344
|
+
setItems([...items].filter((_2, i2) => i2 !== index));
|
|
7345
|
+
onChange([...items].filter((_2, i2) => i2 !== index));
|
|
7346
|
+
if (onAfterItemRemove) {
|
|
7347
|
+
onAfterItemRemove(item);
|
|
7348
|
+
}
|
|
7349
|
+
}
|
|
7350
|
+
}) })
|
|
7352
7351
|
},
|
|
7353
|
-
|
|
7352
|
+
index
|
|
7354
7353
|
))
|
|
7355
7354
|
}
|
|
7356
7355
|
)
|
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useId } from "react";
|
|
3
2
|
import { _ as __ } from "../../default-i18n-CnQeC5Pl.js";
|
|
4
3
|
import { BaseControl } from "../base-control/base-control.js";
|
|
5
4
|
import { c as clsx } from "../../clsx-DgYk2OaC.js";
|
|
6
5
|
import { L as List, a as arrayRemove, b as arrayMove } from "../../List-BGHOoFf0.js";
|
|
7
6
|
import { Container, ContainerGroup } from "../base-control/container.js";
|
|
8
|
-
const fixIds = (items, itemIdBase) => {
|
|
9
|
-
return items?.map((item, i) => ({
|
|
10
|
-
...item,
|
|
11
|
-
id: item?.id ?? `${itemIdBase}-${i}`
|
|
12
|
-
}));
|
|
13
|
-
};
|
|
14
7
|
/**
|
|
15
8
|
* A component that allows re-ordering a list of items.
|
|
16
9
|
*
|
|
@@ -58,10 +51,9 @@ const fixIds = (items, itemIdBase) => {
|
|
|
58
51
|
* @preserve
|
|
59
52
|
*/
|
|
60
53
|
const DraggableList = (props) => {
|
|
61
|
-
const itemIdBase = useId("draggable-list-item-");
|
|
62
54
|
const {
|
|
63
55
|
children,
|
|
64
|
-
items
|
|
56
|
+
items,
|
|
65
57
|
onChange,
|
|
66
58
|
icon,
|
|
67
59
|
label,
|
|
@@ -77,10 +69,9 @@ const DraggableList = (props) => {
|
|
|
77
69
|
hidden,
|
|
78
70
|
...rest
|
|
79
71
|
} = props;
|
|
80
|
-
if (typeof
|
|
72
|
+
if (typeof items === "undefined" || items === null || !Array.isArray(items)) {
|
|
81
73
|
console.warn(__("DraggableList: 'items' are not an array or are undefined!", "eightshift-ui-components"));
|
|
82
74
|
}
|
|
83
|
-
const items = fixIds(rawItems ?? [], itemIdBase);
|
|
84
75
|
if (hidden || !items?.length) {
|
|
85
76
|
return null;
|
|
86
77
|
}
|
|
@@ -109,8 +100,7 @@ const DraggableList = (props) => {
|
|
|
109
100
|
className: clsx("es:w-full es:list-none es:m-0!", itemContainerClassName),
|
|
110
101
|
...rest2,
|
|
111
102
|
children: children2
|
|
112
|
-
}
|
|
113
|
-
key
|
|
103
|
+
}
|
|
114
104
|
);
|
|
115
105
|
},
|
|
116
106
|
renderItem: ({ value, index, isDragged, isSelected, props: props2 }) => {
|
|
@@ -127,11 +117,16 @@ const DraggableList = (props) => {
|
|
|
127
117
|
children: children({
|
|
128
118
|
...value,
|
|
129
119
|
updateData: (newValue) => {
|
|
130
|
-
|
|
120
|
+
const updated = [...items];
|
|
121
|
+
updated[index] = {
|
|
122
|
+
...updated[index],
|
|
123
|
+
...newValue
|
|
124
|
+
};
|
|
125
|
+
onChange(updated);
|
|
131
126
|
},
|
|
132
127
|
itemIndex: index,
|
|
133
128
|
deleteItem: () => {
|
|
134
|
-
onChange(items.filter((i) => i
|
|
129
|
+
onChange(items.filter((_, i) => i !== index));
|
|
135
130
|
if (onAfterItemRemove) {
|
|
136
131
|
onAfterItemRemove(value);
|
|
137
132
|
}
|
|
@@ -387,7 +387,7 @@ const Expandable = (props) => {
|
|
|
387
387
|
"es:h-(--disclosure-panel-height)",
|
|
388
388
|
"es:opacity-0 es:blur-[1px] es:-translate-y-2",
|
|
389
389
|
!isOpen && "es:rounded-t-xl",
|
|
390
|
-
isOpen && "es:rounded-t-
|
|
390
|
+
isOpen && "es:rounded-t-md es:opacity-100 es:*:motion-preset-fade-sm es:*:motion-delay-75 es:blur-none es:translate-y-1 es:mb-1",
|
|
391
391
|
"es:origin-top",
|
|
392
392
|
"es:bg-white es:rounded-b-xl es:inset-ring es:inset-ring-surface-200",
|
|
393
393
|
"es:inset-shadow-sm es:inset-shadow-accent-600/5",
|
|
@@ -30,7 +30,7 @@ import { RepeaterContext } from "./repeater-context.js";
|
|
|
30
30
|
*/
|
|
31
31
|
const RepeaterItem = (props) => {
|
|
32
32
|
const { children, icon, label, subtitle, "aria-label": ariaLabel, className, actions, textValue, expandDisabled, menuOptions, noMenuButton, ...rest } = props;
|
|
33
|
-
const { deleteItem, duplicateItem, isDragged, isOutOfBounds,
|
|
33
|
+
const { deleteItem, duplicateItem, isDragged, isOutOfBounds, canDelete, canAdd, allOpen, setAllOpen, setOpenItems, isItemOpen, index, noDuplicateButton } = useContext(RepeaterContext);
|
|
34
34
|
return /* @__PURE__ */ jsx(
|
|
35
35
|
Expandable,
|
|
36
36
|
{
|
|
@@ -49,7 +49,7 @@ const RepeaterItem = (props) => {
|
|
|
49
49
|
if (allOpen && !open) {
|
|
50
50
|
setAllOpen(false);
|
|
51
51
|
}
|
|
52
|
-
setOpenItems((prev) => ({ ...prev, [
|
|
52
|
+
setOpenItems((prev) => ({ ...prev, [index]: open }));
|
|
53
53
|
},
|
|
54
54
|
customOpenButton: ({ open, toggleOpen, tooltip, disabled }) => {
|
|
55
55
|
return /* @__PURE__ */ jsxs("div", { className: "es:flex es:items-center es:gap-px", children: [
|
|
@@ -82,6 +82,7 @@ const RepeaterItem = (props) => {
|
|
|
82
82
|
disabled: !canDelete,
|
|
83
83
|
icon: icons.trash,
|
|
84
84
|
onPress: () => deleteItem(),
|
|
85
|
+
danger: true,
|
|
85
86
|
children: __("Remove", "eightshift-ui-components")
|
|
86
87
|
}
|
|
87
88
|
)
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useState } from "react";
|
|
3
3
|
import { _ as __ } from "../../default-i18n-CnQeC5Pl.js";
|
|
4
4
|
import { Button } from "../button/button.js";
|
|
5
5
|
import { icons } from "../../icons/icons.js";
|
|
6
6
|
import { BaseControl } from "../base-control/base-control.js";
|
|
7
7
|
import { AnimatedVisibility } from "../animated-visibility/animated-visibility.js";
|
|
8
8
|
import { RepeaterContext } from "./repeater-context.js";
|
|
9
|
-
import { c as clsx } from "../../clsx-DgYk2OaC.js";
|
|
10
9
|
import { L as List, a as arrayRemove, b as arrayMove } from "../../List-BGHOoFf0.js";
|
|
11
10
|
import { Menu, MenuItem, MenuSeparator } from "../menu/menu.js";
|
|
11
|
+
import { c as clsx } from "../../clsx-DgYk2OaC.js";
|
|
12
12
|
/**
|
|
13
13
|
* A component that allows re-ordering a list of items with additional sub-options.
|
|
14
14
|
*
|
|
@@ -67,7 +67,6 @@ import { Menu, MenuItem, MenuSeparator } from "../menu/menu.js";
|
|
|
67
67
|
* @preserve
|
|
68
68
|
*/
|
|
69
69
|
const Repeater = (props) => {
|
|
70
|
-
const itemIdBase = `item-${useId().replaceAll(":", "")}`;
|
|
71
70
|
const {
|
|
72
71
|
children,
|
|
73
72
|
onChange,
|
|
@@ -95,7 +94,7 @@ const Repeater = (props) => {
|
|
|
95
94
|
} = props;
|
|
96
95
|
const [allOpen, setAllOpen] = useState(false);
|
|
97
96
|
const [openItems, setOpenItems] = useState({});
|
|
98
|
-
if (typeof
|
|
97
|
+
if (typeof items === "undefined" || items === null || !Array.isArray(items)) {
|
|
99
98
|
console.warn(__("Repeater: 'items' are not an array or are undefined!", "eightshift-ui-components"));
|
|
100
99
|
}
|
|
101
100
|
const canDelete = items.length > (minItems ?? 0);
|
|
@@ -137,7 +136,7 @@ const Repeater = (props) => {
|
|
|
137
136
|
Button,
|
|
138
137
|
{
|
|
139
138
|
onPress: () => {
|
|
140
|
-
const newItem = {
|
|
139
|
+
const newItem = { ...addDefaultItem };
|
|
141
140
|
onChange([...items, newItem]);
|
|
142
141
|
if (onAfterItemAdd) {
|
|
143
142
|
onAfterItemAdd(newItem);
|
|
@@ -145,15 +144,14 @@ const Repeater = (props) => {
|
|
|
145
144
|
},
|
|
146
145
|
size: "small",
|
|
147
146
|
icon: icons.add,
|
|
148
|
-
className:
|
|
147
|
+
className: !hideEmptyState && items.length < 1 && "es:invisible",
|
|
149
148
|
tooltip: __("Add item", "eightshift-ui-components"),
|
|
150
|
-
disabled: addDisabled || !canAdd
|
|
151
|
-
type: "simple"
|
|
149
|
+
disabled: addDisabled || !canAdd
|
|
152
150
|
}
|
|
153
151
|
),
|
|
154
152
|
addButton && /* @__PURE__ */ jsx("div", { className: clsx(!hideEmptyState && items.length < 1 && "es:invisible"), children: addButton({
|
|
155
153
|
addItem: (additional = {}) => {
|
|
156
|
-
const newItem = {
|
|
154
|
+
const newItem = { ...addDefaultItem, ...additional };
|
|
157
155
|
onChange([...items, newItem]);
|
|
158
156
|
if (onAfterItemAdd) {
|
|
159
157
|
onAfterItemAdd(newItem);
|
|
@@ -167,18 +165,16 @@ const Repeater = (props) => {
|
|
|
167
165
|
/* @__PURE__ */ jsx(
|
|
168
166
|
List,
|
|
169
167
|
{
|
|
170
|
-
values: items.map((item) => ({ ...item, disabled: openItems?.[
|
|
168
|
+
values: items.map((item, index) => ({ ...item, disabled: openItems?.[index] })),
|
|
171
169
|
onChange: ({ oldIndex, newIndex }) => onChange(newIndex === -1 ? arrayRemove(items, oldIndex) : arrayMove(items, oldIndex, newIndex)),
|
|
172
170
|
renderList: ({ children: children2, props: props2 }) => {
|
|
173
|
-
const { key, ...rest } = props2;
|
|
174
171
|
return /* @__PURE__ */ jsx(
|
|
175
172
|
"ul",
|
|
176
173
|
{
|
|
177
|
-
className: clsx("es:w-full es:list-none es:m-0! es:flex es:flex-col es:gap-
|
|
178
|
-
...
|
|
174
|
+
className: clsx("es:w-full es:list-none es:m-0! es:flex es:flex-col es:gap-0.75", className),
|
|
175
|
+
...props2,
|
|
179
176
|
children: children2
|
|
180
|
-
}
|
|
181
|
-
key
|
|
177
|
+
}
|
|
182
178
|
);
|
|
183
179
|
},
|
|
184
180
|
renderItem: ({ value: item, index, isDragged, isSelected, isOutOfBounds, props: props2 }) => {
|
|
@@ -195,13 +191,13 @@ const Repeater = (props) => {
|
|
|
195
191
|
...item,
|
|
196
192
|
index,
|
|
197
193
|
deleteItem: () => {
|
|
198
|
-
onChange([...items].filter((i) => i
|
|
194
|
+
onChange([...items].filter((_, i) => i !== index));
|
|
199
195
|
if (onAfterItemRemove) {
|
|
200
196
|
onAfterItemRemove(item);
|
|
201
197
|
}
|
|
202
198
|
},
|
|
203
199
|
duplicateItem: () => {
|
|
204
|
-
const newItem = { ...item
|
|
200
|
+
const newItem = { ...item };
|
|
205
201
|
onChange([...items, newItem]);
|
|
206
202
|
if (onAfterItemAdd) {
|
|
207
203
|
onAfterItemAdd(newItem);
|
|
@@ -215,18 +211,22 @@ const Repeater = (props) => {
|
|
|
215
211
|
allOpen,
|
|
216
212
|
setAllOpen,
|
|
217
213
|
setOpenItems,
|
|
218
|
-
isItemOpen: openItems?.[
|
|
214
|
+
isItemOpen: openItems?.[index] ?? allOpen,
|
|
219
215
|
noDuplicateButton
|
|
220
216
|
},
|
|
221
217
|
children: children({
|
|
222
218
|
...item,
|
|
223
219
|
updateData: (newValue) => {
|
|
224
|
-
const updated = [...items]
|
|
220
|
+
const updated = [...items];
|
|
221
|
+
updated[index] = {
|
|
222
|
+
...updated[index],
|
|
223
|
+
...newValue
|
|
224
|
+
};
|
|
225
225
|
onChange(updated);
|
|
226
226
|
},
|
|
227
227
|
itemIndex: index,
|
|
228
228
|
deleteItem: () => {
|
|
229
|
-
onChange([...items].filter((i) => i
|
|
229
|
+
onChange([...items].filter((_, i) => i !== index));
|
|
230
230
|
if (onAfterItemRemove) {
|
|
231
231
|
onAfterItemRemove(item);
|
|
232
232
|
}
|
|
@@ -248,7 +248,7 @@ const Repeater = (props) => {
|
|
|
248
248
|
Button,
|
|
249
249
|
{
|
|
250
250
|
onPress: () => {
|
|
251
|
-
const newItem = {
|
|
251
|
+
const newItem = { ...addDefaultItem };
|
|
252
252
|
onChange([...items, newItem]);
|
|
253
253
|
if (onAfterItemAdd) {
|
|
254
254
|
onAfterItemAdd(newItem);
|
|
@@ -263,7 +263,7 @@ const Repeater = (props) => {
|
|
|
263
263
|
),
|
|
264
264
|
addButton && !hideEmptyState && addButton({
|
|
265
265
|
addItem: (additional = {}) => {
|
|
266
|
-
const newItem = {
|
|
266
|
+
const newItem = { ...addDefaultItem, ...additional };
|
|
267
267
|
onChange([...items, newItem]);
|
|
268
268
|
if (onAfterItemAdd) {
|
|
269
269
|
onAfterItemAdd(newItem);
|