@dragonmastery/zinia-forms-core 0.3.6 → 0.3.7
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/index.d.ts +11 -0
- package/dist/index.js +298 -87
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -108,6 +108,10 @@ interface ArrayFieldProps<FormType, ItemType> {
|
|
|
108
108
|
itemsSource?: () => ItemType[];
|
|
109
109
|
itemRenderer?: (item: ItemType, index: number) => any;
|
|
110
110
|
availableItemRenderer?: (item: ItemType, index: number) => any;
|
|
111
|
+
itemPreview?: (item: ItemType, index: number) => string;
|
|
112
|
+
showItemNumber?: boolean;
|
|
113
|
+
itemPreviewMaxLength?: number;
|
|
114
|
+
fieldSummary?: (items: ItemType[]) => string;
|
|
111
115
|
createItem?: () => ItemType;
|
|
112
116
|
onAddItem?: (item: ItemType) => void;
|
|
113
117
|
onRemoveItem?: (index: number) => void;
|
|
@@ -123,6 +127,8 @@ interface ArrayFieldProps<FormType, ItemType> {
|
|
|
123
127
|
moveDownButton?: string;
|
|
124
128
|
item?: string;
|
|
125
129
|
};
|
|
130
|
+
collapseAllButton?: boolean;
|
|
131
|
+
defaultCollapsed?: boolean;
|
|
126
132
|
}
|
|
127
133
|
|
|
128
134
|
interface CheckboxFieldProps<FormType> {
|
|
@@ -1275,6 +1281,11 @@ declare function useForm<T extends z.ZodObject<any>, CalcType = (values: z.infer
|
|
|
1275
1281
|
readonly errors: Record<string, string>;
|
|
1276
1282
|
readonly touched: Record<string, boolean>;
|
|
1277
1283
|
readonly dirty: Record<string, boolean>;
|
|
1284
|
+
readonly collapsedFields: Record<string, {
|
|
1285
|
+
isFieldCollapsed: boolean;
|
|
1286
|
+
collapsedItems: number[];
|
|
1287
|
+
defaultCollapsedInitialized: boolean;
|
|
1288
|
+
}>;
|
|
1278
1289
|
fieldsMetadata: Record<string, FieldMetadata>;
|
|
1279
1290
|
validate: (options?: {
|
|
1280
1291
|
markErrorsAsTouched: boolean;
|
package/dist/index.js
CHANGED
|
@@ -79,14 +79,44 @@ function createTypedArrayField(baseArrayField, fieldPath, metadata) {
|
|
|
79
79
|
// Add other metadata fields as needed
|
|
80
80
|
} : {};
|
|
81
81
|
const TypedArrayField = (props, context) => {
|
|
82
|
-
const
|
|
82
|
+
const allProps = {
|
|
83
83
|
...metadataProps,
|
|
84
84
|
...props,
|
|
85
|
+
...context?.attrs || {},
|
|
85
86
|
name: fieldPath
|
|
86
87
|
};
|
|
87
88
|
const contextWithSlots = context || { attrs: {}, slots: {} };
|
|
88
|
-
return baseArrayField(
|
|
89
|
+
return baseArrayField(allProps, contextWithSlots);
|
|
89
90
|
};
|
|
91
|
+
TypedArrayField.props = [
|
|
92
|
+
"label",
|
|
93
|
+
"hideLabel",
|
|
94
|
+
"description",
|
|
95
|
+
"required",
|
|
96
|
+
"disabled",
|
|
97
|
+
"readonly",
|
|
98
|
+
"class",
|
|
99
|
+
"availableItems",
|
|
100
|
+
"itemRenderer",
|
|
101
|
+
"availableItemRenderer",
|
|
102
|
+
"itemPreview",
|
|
103
|
+
"showItemNumber",
|
|
104
|
+
"itemPreviewMaxLength",
|
|
105
|
+
"fieldSummary",
|
|
106
|
+
"createItem",
|
|
107
|
+
// This is the key prop we need
|
|
108
|
+
"onAddItem",
|
|
109
|
+
"onRemoveItem",
|
|
110
|
+
"onUpdateItem",
|
|
111
|
+
"onSwapItems",
|
|
112
|
+
"minItems",
|
|
113
|
+
"maxItems",
|
|
114
|
+
"allowReordering",
|
|
115
|
+
"ariaLabels",
|
|
116
|
+
"itemsSource",
|
|
117
|
+
"collapseAllButton",
|
|
118
|
+
"defaultCollapsed"
|
|
119
|
+
];
|
|
90
120
|
return TypedArrayField;
|
|
91
121
|
}
|
|
92
122
|
|
|
@@ -1423,6 +1453,7 @@ function useFormState(initialData, options) {
|
|
|
1423
1453
|
focused: {},
|
|
1424
1454
|
displayText: {},
|
|
1425
1455
|
selectedIndex: {},
|
|
1456
|
+
collapsedFields: {},
|
|
1426
1457
|
// Form status
|
|
1427
1458
|
isSubmitting: false,
|
|
1428
1459
|
hasAttemptedSubmit: false,
|
|
@@ -1856,6 +1887,9 @@ function useForm(schema, options) {
|
|
|
1856
1887
|
get dirty() {
|
|
1857
1888
|
return formState.state.dirty;
|
|
1858
1889
|
},
|
|
1890
|
+
get collapsedFields() {
|
|
1891
|
+
return formState.state.collapsedFields;
|
|
1892
|
+
},
|
|
1859
1893
|
fieldsMetadata,
|
|
1860
1894
|
// Form methods
|
|
1861
1895
|
validate: validation.validate,
|
|
@@ -3611,6 +3645,51 @@ function createDaisyUIArrayField() {
|
|
|
3611
3645
|
}
|
|
3612
3646
|
const fieldMetadata = formState.fieldsMetadata[props.name] || {};
|
|
3613
3647
|
const arrayValue = formState.getValue(props.name) || [];
|
|
3648
|
+
const fieldName = String(props.name);
|
|
3649
|
+
if (!formState.collapsedFields[fieldName]) {
|
|
3650
|
+
formState.collapsedFields[fieldName] = {
|
|
3651
|
+
isFieldCollapsed: false,
|
|
3652
|
+
collapsedItems: [],
|
|
3653
|
+
defaultCollapsedInitialized: false
|
|
3654
|
+
};
|
|
3655
|
+
}
|
|
3656
|
+
const collapseState = formState.collapsedFields[fieldName];
|
|
3657
|
+
if (props.defaultCollapsed && !collapseState.defaultCollapsedInitialized && arrayValue.length > 0) {
|
|
3658
|
+
collapseState.collapsedItems = arrayValue.map((_, index) => index);
|
|
3659
|
+
collapseState.defaultCollapsedInitialized = true;
|
|
3660
|
+
}
|
|
3661
|
+
const toggleFieldCollapse = () => {
|
|
3662
|
+
collapseState.isFieldCollapsed = !collapseState.isFieldCollapsed;
|
|
3663
|
+
};
|
|
3664
|
+
const toggleItemCollapse = (index) => {
|
|
3665
|
+
const itemIndex = collapseState.collapsedItems.indexOf(index);
|
|
3666
|
+
if (itemIndex > -1) {
|
|
3667
|
+
collapseState.collapsedItems.splice(itemIndex, 1);
|
|
3668
|
+
} else {
|
|
3669
|
+
collapseState.collapsedItems.push(index);
|
|
3670
|
+
}
|
|
3671
|
+
};
|
|
3672
|
+
const collapseAllItems = () => {
|
|
3673
|
+
collapseState.collapsedItems = arrayValue.map((_, index) => index);
|
|
3674
|
+
};
|
|
3675
|
+
const expandAllItems = () => {
|
|
3676
|
+
collapseState.collapsedItems = [];
|
|
3677
|
+
};
|
|
3678
|
+
const areAllItemsCollapsed = () => {
|
|
3679
|
+
return arrayValue.length > 0 && collapseState.collapsedItems.length === arrayValue.length;
|
|
3680
|
+
};
|
|
3681
|
+
const getItemPreview = (item, index) => {
|
|
3682
|
+
if (props.itemPreview) {
|
|
3683
|
+
const preview = props.itemPreview(item, index);
|
|
3684
|
+
const maxLength = props.itemPreviewMaxLength ?? 125;
|
|
3685
|
+
if (preview.length > maxLength) {
|
|
3686
|
+
return preview.substring(0, maxLength - 3) + "...";
|
|
3687
|
+
}
|
|
3688
|
+
return preview;
|
|
3689
|
+
}
|
|
3690
|
+
return "";
|
|
3691
|
+
};
|
|
3692
|
+
const showItemNumber = props.showItemNumber === true;
|
|
3614
3693
|
const getFieldName = (fieldPath, index) => {
|
|
3615
3694
|
return `${props.name}.${index}.${fieldPath}`;
|
|
3616
3695
|
};
|
|
@@ -3621,7 +3700,9 @@ function createDaisyUIArrayField() {
|
|
|
3621
3700
|
}
|
|
3622
3701
|
});
|
|
3623
3702
|
};
|
|
3624
|
-
|
|
3703
|
+
if (process.env.NODE_ENV === "development") {
|
|
3704
|
+
console.log("[ArrayFieldDaisy] createItem prop:", !!props.createItem, "for field:", props.name);
|
|
3705
|
+
}
|
|
3625
3706
|
const addItem = (item) => {
|
|
3626
3707
|
const currentArray = [...arrayValue];
|
|
3627
3708
|
if (maxItems !== void 0 && currentArray.length >= maxItems) {
|
|
@@ -3634,6 +3715,7 @@ function createDaisyUIArrayField() {
|
|
|
3634
3715
|
if (props.onAddItem) {
|
|
3635
3716
|
props.onAddItem(itemCopy);
|
|
3636
3717
|
}
|
|
3718
|
+
const instance = getCurrentInstance();
|
|
3637
3719
|
if (instance) {
|
|
3638
3720
|
instance.emit("item-added", itemCopy);
|
|
3639
3721
|
}
|
|
@@ -3650,6 +3732,7 @@ function createDaisyUIArrayField() {
|
|
|
3650
3732
|
if (props.onRemoveItem) {
|
|
3651
3733
|
props.onRemoveItem(index);
|
|
3652
3734
|
}
|
|
3735
|
+
const instance = getCurrentInstance();
|
|
3653
3736
|
if (instance) {
|
|
3654
3737
|
instance.emit("item-removed", removedItem, index);
|
|
3655
3738
|
}
|
|
@@ -3667,6 +3750,7 @@ function createDaisyUIArrayField() {
|
|
|
3667
3750
|
if (props.onSwapItems) {
|
|
3668
3751
|
props.onSwapItems(indexA, indexB);
|
|
3669
3752
|
}
|
|
3753
|
+
const instance = getCurrentInstance();
|
|
3670
3754
|
if (instance) {
|
|
3671
3755
|
instance.emit("items-swapped", indexA, indexB, currentArray[indexA], currentArray[indexB]);
|
|
3672
3756
|
}
|
|
@@ -3722,19 +3806,19 @@ function createDaisyUIArrayField() {
|
|
|
3722
3806
|
if (!availableItems || availableItems.length === 0) {
|
|
3723
3807
|
return null;
|
|
3724
3808
|
}
|
|
3725
|
-
return /* @__PURE__ */ jsxs("div", { class: "mt-4", children: [
|
|
3726
|
-
/* @__PURE__ */ jsx("h3", { class: "font-semibold mb-
|
|
3727
|
-
/* @__PURE__ */ jsx("div", { class: "grid grid-cols-1
|
|
3809
|
+
return /* @__PURE__ */ jsxs("div", { class: "mt-4 sm:mt-6", children: [
|
|
3810
|
+
/* @__PURE__ */ jsx("h3", { class: "text-base sm:text-lg font-semibold mb-3 sm:mb-4", children: "Available Items" }),
|
|
3811
|
+
/* @__PURE__ */ jsx("div", { class: "grid grid-cols-1 sm:grid-cols-2 gap-3 sm:gap-4", children: availableItems.map((item, index) => /* @__PURE__ */ jsxs(
|
|
3728
3812
|
"div",
|
|
3729
3813
|
{
|
|
3730
|
-
class: "flex items-center
|
|
3814
|
+
class: "flex flex-col sm:flex-row sm:items-center gap-3 sm:gap-2 p-4 sm:p-3 border border-base-300 rounded-lg bg-base-100 hover:bg-base-200 transition-colors",
|
|
3731
3815
|
children: [
|
|
3732
|
-
/* @__PURE__ */ jsx("div", { class: "flex-1", children: slots.availableItemRenderer?.({ item, index }) || (props.availableItemRenderer ? props.availableItemRenderer(item, index) : JSON.stringify(item)) }),
|
|
3816
|
+
/* @__PURE__ */ jsx("div", { class: "flex-1 min-w-0", children: slots.availableItemRenderer?.({ item, index }) || (props.availableItemRenderer ? props.availableItemRenderer(item, index) : JSON.stringify(item)) }),
|
|
3733
3817
|
/* @__PURE__ */ jsx(
|
|
3734
3818
|
"button",
|
|
3735
3819
|
{
|
|
3736
3820
|
type: "button",
|
|
3737
|
-
class: "btn btn-
|
|
3821
|
+
class: "btn btn-primary btn-md sm:btn-sm w-full sm:w-auto min-h-[44px] sm:min-h-0 flex-shrink-0",
|
|
3738
3822
|
onClick: () => addItem(item),
|
|
3739
3823
|
disabled: isAddButtonDisabled,
|
|
3740
3824
|
"aria-label": ariaLabels.addButton,
|
|
@@ -3750,89 +3834,210 @@ function createDaisyUIArrayField() {
|
|
|
3750
3834
|
};
|
|
3751
3835
|
const renderSelectedItems = () => {
|
|
3752
3836
|
if (arrayValue.length === 0) {
|
|
3753
|
-
return
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
"
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3837
|
+
return /* @__PURE__ */ jsx("div", { class: "mt-4 sm:mt-6", children: /* @__PURE__ */ jsx("div", { class: "text-center py-8 sm:py-12 px-4 border border-dashed border-base-300 rounded-lg bg-base-50", children: /* @__PURE__ */ jsxs("p", { class: "text-sm sm:text-base text-base-content/60", children: [
|
|
3838
|
+
"No items added yet. ",
|
|
3839
|
+
props.createItem ? 'Click "Add New Item" below to get started.' : availableItems && availableItems.length > 0 ? "Select an item from above to add it." : ""
|
|
3840
|
+
] }) }) });
|
|
3841
|
+
}
|
|
3842
|
+
return /* @__PURE__ */ jsxs("div", { class: "mt-4 sm:mt-6", children: [
|
|
3843
|
+
/* @__PURE__ */ jsx("div", { class: "flex items-center justify-between mb-3 sm:mb-4", children: /* @__PURE__ */ jsxs("h4", { class: "text-base sm:text-lg font-semibold", children: [
|
|
3844
|
+
"Selected Items",
|
|
3845
|
+
arrayValue.length > 0 && /* @__PURE__ */ jsxs("span", { class: "ml-2 text-sm font-normal text-base-content/60", children: [
|
|
3846
|
+
"(",
|
|
3847
|
+
arrayValue.length,
|
|
3848
|
+
maxItems !== void 0 ? ` / ${maxItems}` : "",
|
|
3849
|
+
")"
|
|
3850
|
+
] })
|
|
3851
|
+
] }) }),
|
|
3852
|
+
/* @__PURE__ */ jsx("div", { class: "space-y-3 sm:space-y-4", children: arrayValue.map((item, index) => {
|
|
3853
|
+
const isItemCollapsed = collapseState.collapsedItems.includes(index);
|
|
3854
|
+
return /* @__PURE__ */ jsxs(
|
|
3855
|
+
"div",
|
|
3856
|
+
{
|
|
3857
|
+
class: "border border-base-300 rounded-lg bg-base-100 shadow-sm hover:shadow-md transition-shadow",
|
|
3858
|
+
children: [
|
|
3859
|
+
/* @__PURE__ */ jsxs("div", { class: "border-b border-base-200 bg-base-50 rounded-t-lg", children: [
|
|
3860
|
+
/* @__PURE__ */ jsxs("div", { class: "flex items-center justify-between p-1 sm:p-3 sm:px-4", children: [
|
|
3861
|
+
/* @__PURE__ */ jsx(
|
|
3862
|
+
"button",
|
|
3863
|
+
{
|
|
3864
|
+
type: "button",
|
|
3865
|
+
class: "btn btn-ghost btn-square btn-xs sm:btn-sm min-h-[32px] sm:min-h-[36px] min-w-[32px] sm:min-w-[36px] p-0",
|
|
3866
|
+
onClick: () => toggleItemCollapse(index),
|
|
3867
|
+
"aria-label": isItemCollapsed ? "Expand item" : "Collapse item",
|
|
3868
|
+
"aria-expanded": !isItemCollapsed,
|
|
3869
|
+
children: /* @__PURE__ */ jsx(
|
|
3870
|
+
"svg",
|
|
3871
|
+
{
|
|
3872
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
3873
|
+
class: `h-4 w-4 sm:h-5 sm:w-5 transition-transform ${isItemCollapsed ? "" : "rotate-90"}`,
|
|
3874
|
+
fill: "none",
|
|
3875
|
+
viewBox: "0 0 24 24",
|
|
3876
|
+
stroke: "currentColor",
|
|
3877
|
+
children: /* @__PURE__ */ jsx("path", { "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", d: "M9 5l7 7-7 7" })
|
|
3878
|
+
}
|
|
3879
|
+
)
|
|
3880
|
+
}
|
|
3881
|
+
),
|
|
3882
|
+
/* @__PURE__ */ jsxs(
|
|
3883
|
+
"button",
|
|
3884
|
+
{
|
|
3885
|
+
type: "button",
|
|
3886
|
+
class: "btn btn-error btn-xs sm:btn-sm min-h-[32px] sm:min-h-[36px] px-2 sm:px-3 text-xs sm:text-sm",
|
|
3887
|
+
onClick: () => removeItem(index),
|
|
3888
|
+
disabled: isRemoveButtonDisabled(),
|
|
3889
|
+
"aria-label": ariaLabels.removeButton,
|
|
3890
|
+
"data-testid": `${formState.storeName}-array-field-${String(props.name)}-remove-${index}`,
|
|
3891
|
+
children: [
|
|
3892
|
+
/* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", class: "h-3.5 w-3.5 sm:h-4 sm:w-4", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ jsx("path", { "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", d: "M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" }) }),
|
|
3893
|
+
/* @__PURE__ */ jsx("span", { class: "hidden sm:inline ml-1", children: "Remove" })
|
|
3894
|
+
]
|
|
3895
|
+
}
|
|
3896
|
+
)
|
|
3897
|
+
] }),
|
|
3898
|
+
isItemCollapsed && /* @__PURE__ */ jsxs("div", { class: "px-1 sm:px-4 pb-2 sm:pb-3 border-t border-base-200/50", children: [
|
|
3899
|
+
showItemNumber && /* @__PURE__ */ jsxs("div", { class: "text-xs text-base-content/60 font-medium mb-1", children: [
|
|
3900
|
+
"#",
|
|
3901
|
+
index + 1
|
|
3902
|
+
] }),
|
|
3903
|
+
getItemPreview(item, index) && /* @__PURE__ */ jsx("div", { class: "font-semibold text-sm sm:text-base break-words leading-tight", children: getItemPreview(item, index) })
|
|
3904
|
+
] }),
|
|
3905
|
+
props.allowReordering && /* @__PURE__ */ jsxs("div", { class: "flex items-center justify-end gap-1 sm:gap-2 p-1 sm:p-3 sm:px-4 border-t border-base-200/50", children: [
|
|
3906
|
+
/* @__PURE__ */ jsx(
|
|
3907
|
+
"button",
|
|
3908
|
+
{
|
|
3909
|
+
type: "button",
|
|
3910
|
+
class: "btn btn-ghost btn-square btn-xs sm:btn-sm min-h-[32px] sm:min-h-[36px] min-w-[32px] sm:min-w-[36px] p-0",
|
|
3911
|
+
onClick: () => moveItemUp(index),
|
|
3912
|
+
disabled: index === 0 || props.disabled || props.readonly,
|
|
3913
|
+
"aria-label": ariaLabels.moveUpButton,
|
|
3914
|
+
"data-testid": `${formState.storeName}-array-field-${String(props.name)}-move-up-${index}`,
|
|
3915
|
+
children: /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", class: "h-3.5 w-3.5 sm:h-4 sm:w-4", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ jsx("path", { "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", d: "M5 15l7-7 7 7" }) })
|
|
3916
|
+
}
|
|
3917
|
+
),
|
|
3918
|
+
/* @__PURE__ */ jsx(
|
|
3919
|
+
"button",
|
|
3920
|
+
{
|
|
3921
|
+
type: "button",
|
|
3922
|
+
class: "btn btn-ghost btn-square btn-xs sm:btn-sm min-h-[32px] sm:min-h-[36px] min-w-[32px] sm:min-w-[36px] p-0",
|
|
3923
|
+
onClick: () => moveItemDown(index),
|
|
3924
|
+
disabled: index === arrayValue.length - 1 || props.disabled || props.readonly,
|
|
3925
|
+
"aria-label": ariaLabels.moveDownButton,
|
|
3926
|
+
"data-testid": `${formState.storeName}-array-field-${String(props.name)}-move-down-${index}`,
|
|
3927
|
+
children: /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", class: "h-3.5 w-3.5 sm:h-4 sm:w-4", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ jsx("path", { "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", d: "M19 9l-7 7-7-7" }) })
|
|
3928
|
+
}
|
|
3929
|
+
)
|
|
3930
|
+
] })
|
|
3794
3931
|
] }),
|
|
3932
|
+
!isItemCollapsed && /* @__PURE__ */ jsx("div", { class: "p-3 sm:p-5", children: slots.itemRenderer?.({
|
|
3933
|
+
item,
|
|
3934
|
+
index,
|
|
3935
|
+
// Type-safe fields object with autocomplete
|
|
3936
|
+
fields: generateFieldsProxy(index)
|
|
3937
|
+
}) || (props.itemRenderer ? props.itemRenderer(item, index) : JSON.stringify(item)) })
|
|
3938
|
+
]
|
|
3939
|
+
},
|
|
3940
|
+
index
|
|
3941
|
+
);
|
|
3942
|
+
}) })
|
|
3943
|
+
] });
|
|
3944
|
+
};
|
|
3945
|
+
return /* @__PURE__ */ jsxs("div", { class: `form-control w-full ${props.class || ""}`, children: [
|
|
3946
|
+
!props.hideLabel && /* @__PURE__ */ jsx("div", { class: "label pb-2 sm:pb-3", children: /* @__PURE__ */ jsxs("div", { class: "flex items-center justify-between w-full", children: [
|
|
3947
|
+
/* @__PURE__ */ jsxs("span", { class: "label-text text-base sm:text-lg font-semibold", children: [
|
|
3948
|
+
props.label || fieldMetadata?.label,
|
|
3949
|
+
fieldMetadata?.isRequired && /* @__PURE__ */ jsx("span", { class: "text-error ml-1", children: "*" }),
|
|
3950
|
+
arrayValue.length > 0 && /* @__PURE__ */ jsxs("span", { class: "ml-2 text-sm font-normal text-base-content/60", children: [
|
|
3951
|
+
"(",
|
|
3952
|
+
arrayValue.length,
|
|
3953
|
+
maxItems !== void 0 ? ` / ${maxItems}` : "",
|
|
3954
|
+
")"
|
|
3955
|
+
] })
|
|
3956
|
+
] }),
|
|
3957
|
+
/* @__PURE__ */ jsxs("div", { class: "flex items-center gap-2", children: [
|
|
3958
|
+
arrayValue.length > 0 && /* @__PURE__ */ jsxs(
|
|
3959
|
+
"button",
|
|
3960
|
+
{
|
|
3961
|
+
type: "button",
|
|
3962
|
+
class: "btn btn-ghost btn-sm min-h-[36px] sm:min-h-[44px] px-2 sm:px-3",
|
|
3963
|
+
onClick: toggleFieldCollapse,
|
|
3964
|
+
"aria-label": collapseState.isFieldCollapsed ? "Expand all items" : "Collapse all items",
|
|
3965
|
+
"aria-expanded": !collapseState.isFieldCollapsed,
|
|
3966
|
+
children: [
|
|
3795
3967
|
/* @__PURE__ */ jsx(
|
|
3796
|
-
"
|
|
3968
|
+
"svg",
|
|
3797
3969
|
{
|
|
3798
|
-
|
|
3799
|
-
class:
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
"
|
|
3803
|
-
"
|
|
3804
|
-
children: "Remove"
|
|
3970
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
3971
|
+
class: `h-4 w-4 sm:h-5 sm:w-5 transition-transform ${collapseState.isFieldCollapsed ? "" : "rotate-180"}`,
|
|
3972
|
+
fill: "none",
|
|
3973
|
+
viewBox: "0 0 24 24",
|
|
3974
|
+
stroke: "currentColor",
|
|
3975
|
+
children: /* @__PURE__ */ jsx("path", { "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", d: "M19 9l-7 7-7-7" })
|
|
3805
3976
|
}
|
|
3806
|
-
)
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3977
|
+
),
|
|
3978
|
+
/* @__PURE__ */ jsx("span", { class: "hidden sm:inline ml-1 text-xs", children: collapseState.isFieldCollapsed ? "Expand" : "Collapse" })
|
|
3979
|
+
]
|
|
3980
|
+
}
|
|
3981
|
+
),
|
|
3982
|
+
props.collapseAllButton && arrayValue.length > 0 && /* @__PURE__ */ jsxs(
|
|
3983
|
+
"button",
|
|
3984
|
+
{
|
|
3985
|
+
type: "button",
|
|
3986
|
+
class: "btn btn-ghost btn-sm min-h-[36px] sm:min-h-[44px] px-2 sm:px-3",
|
|
3987
|
+
onClick: areAllItemsCollapsed() ? expandAllItems : collapseAllItems,
|
|
3988
|
+
"aria-label": areAllItemsCollapsed() ? "Expand all items" : "Collapse all items",
|
|
3989
|
+
children: [
|
|
3990
|
+
/* @__PURE__ */ jsx(
|
|
3991
|
+
"svg",
|
|
3992
|
+
{
|
|
3993
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
3994
|
+
class: "h-4 w-4 sm:h-5 sm:w-5",
|
|
3995
|
+
fill: "none",
|
|
3996
|
+
viewBox: "0 0 24 24",
|
|
3997
|
+
stroke: "currentColor",
|
|
3998
|
+
children: /* @__PURE__ */ jsx("path", { "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", d: "M4 6h16M4 12h16M4 18h16" })
|
|
3999
|
+
}
|
|
4000
|
+
),
|
|
4001
|
+
/* @__PURE__ */ jsx("span", { class: "hidden sm:inline ml-1 text-xs", children: areAllItemsCollapsed() ? "Expand All" : "Collapse All" })
|
|
4002
|
+
]
|
|
4003
|
+
}
|
|
4004
|
+
)
|
|
4005
|
+
] })
|
|
3818
4006
|
] }) }),
|
|
3819
4007
|
slots.default?.(),
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
4008
|
+
!collapseState.isFieldCollapsed && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4009
|
+
renderAvailableItems(),
|
|
4010
|
+
renderSelectedItems()
|
|
4011
|
+
] }),
|
|
4012
|
+
collapseState.isFieldCollapsed && arrayValue.length > 0 && /* @__PURE__ */ jsx("div", { class: "mt-4 sm:mt-6 p-4 border border-base-300 rounded-lg bg-base-50", children: /* @__PURE__ */ jsx("p", { class: "text-sm sm:text-base text-base-content/70", children: props.fieldSummary ? props.fieldSummary(arrayValue) : `${arrayValue.length} item${arrayValue.length !== 1 ? "s" : ""} added. Click "Expand" above to view and edit.` }) }),
|
|
4013
|
+
props.description && /* @__PURE__ */ jsx("p", { class: "text-sm sm:text-base text-base-content/70 mt-2 sm:mt-3 px-1", children: props.description }),
|
|
4014
|
+
props.createItem && /* @__PURE__ */ jsxs("div", { class: `mt-3 sm:mt-6 ${arrayValue.length > 0 ? "pt-3 sm:pt-6 border-t border-base-300" : ""}`, children: [
|
|
4015
|
+
/* @__PURE__ */ jsxs(
|
|
4016
|
+
"button",
|
|
4017
|
+
{
|
|
4018
|
+
type: "button",
|
|
4019
|
+
class: "btn btn-outline btn-accent btn-sm w-full sm:w-auto min-h-[36px] sm:min-h-0",
|
|
4020
|
+
onClick: () => addItem(createNewItem()),
|
|
4021
|
+
disabled: isAddButtonDisabled,
|
|
4022
|
+
"aria-label": ariaLabels.addButton,
|
|
4023
|
+
"data-testid": `${formState.storeName}-array-field-${String(props.name)}-add-button`,
|
|
4024
|
+
children: [
|
|
4025
|
+
/* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", class: "h-4 w-4 mr-1.5", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ jsx("path", { "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", d: "M12 4v16m8-8H4" }) }),
|
|
4026
|
+
/* @__PURE__ */ jsx("span", { class: "text-sm", children: "Add New Item" })
|
|
4027
|
+
]
|
|
4028
|
+
}
|
|
4029
|
+
),
|
|
4030
|
+
maxItems !== void 0 && /* @__PURE__ */ jsxs("p", { class: "text-xs sm:text-sm text-base-content/60 mt-2 text-center sm:text-left", children: [
|
|
4031
|
+
arrayValue.length,
|
|
4032
|
+
" of ",
|
|
4033
|
+
maxItems,
|
|
4034
|
+
" items"
|
|
4035
|
+
] })
|
|
4036
|
+
] }),
|
|
4037
|
+
isTouched2 && hasErrors && /* @__PURE__ */ jsx("div", { class: "mt-2 sm:mt-3 p-3 sm:p-4 bg-error/10 border border-error/20 rounded-lg", children: /* @__PURE__ */ jsxs("p", { class: "text-sm sm:text-base text-error font-medium flex items-start gap-2", children: [
|
|
4038
|
+
/* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", class: "h-5 w-5 flex-shrink-0 mt-0.5", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ jsx("path", { "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", d: "M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" }) }),
|
|
4039
|
+
/* @__PURE__ */ jsx("span", { children: formState.getError(props.name) })
|
|
4040
|
+
] }) })
|
|
3836
4041
|
] });
|
|
3837
4042
|
};
|
|
3838
4043
|
DaisyUIArrayField.props = [
|
|
@@ -3847,6 +4052,10 @@ function createDaisyUIArrayField() {
|
|
|
3847
4052
|
"availableItems",
|
|
3848
4053
|
"itemRenderer",
|
|
3849
4054
|
"availableItemRenderer",
|
|
4055
|
+
"itemPreview",
|
|
4056
|
+
"showItemNumber",
|
|
4057
|
+
"itemPreviewMaxLength",
|
|
4058
|
+
"fieldSummary",
|
|
3850
4059
|
"createItem",
|
|
3851
4060
|
"onAddItem",
|
|
3852
4061
|
"onRemoveItem",
|
|
@@ -3855,7 +4064,9 @@ function createDaisyUIArrayField() {
|
|
|
3855
4064
|
"minItems",
|
|
3856
4065
|
"maxItems",
|
|
3857
4066
|
"allowReordering",
|
|
3858
|
-
"ariaLabels"
|
|
4067
|
+
"ariaLabels",
|
|
4068
|
+
"collapseAllButton",
|
|
4069
|
+
"defaultCollapsed"
|
|
3859
4070
|
];
|
|
3860
4071
|
return DaisyUIArrayField;
|
|
3861
4072
|
}
|