@questpie/admin 0.0.1
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/.turbo/turbo-build.log +108 -0
- package/CHANGELOG.md +10 -0
- package/README.md +556 -0
- package/STATUS.md +917 -0
- package/VALIDATION.md +602 -0
- package/components.json +24 -0
- package/dist/__tests__/setup.mjs +38 -0
- package/dist/__tests__/test-utils.mjs +45 -0
- package/dist/__tests__/vitest.d.mjs +3 -0
- package/dist/components/admin-app.mjs +69 -0
- package/dist/components/fields/array-field.mjs +190 -0
- package/dist/components/fields/checkbox-field.mjs +34 -0
- package/dist/components/fields/custom-field.mjs +32 -0
- package/dist/components/fields/date-field.mjs +41 -0
- package/dist/components/fields/datetime-field.mjs +42 -0
- package/dist/components/fields/email-field.mjs +37 -0
- package/dist/components/fields/embedded-collection.mjs +253 -0
- package/dist/components/fields/field-types.mjs +1 -0
- package/dist/components/fields/field-utils.mjs +10 -0
- package/dist/components/fields/field-wrapper.mjs +34 -0
- package/dist/components/fields/index.mjs +23 -0
- package/dist/components/fields/json-field.mjs +243 -0
- package/dist/components/fields/locale-badge.mjs +16 -0
- package/dist/components/fields/number-field.mjs +39 -0
- package/dist/components/fields/password-field.mjs +37 -0
- package/dist/components/fields/relation-field.mjs +104 -0
- package/dist/components/fields/relation-picker.mjs +229 -0
- package/dist/components/fields/relation-select.mjs +188 -0
- package/dist/components/fields/rich-text-editor/index.mjs +897 -0
- package/dist/components/fields/select-field.mjs +41 -0
- package/dist/components/fields/switch-field.mjs +34 -0
- package/dist/components/fields/text-field.mjs +38 -0
- package/dist/components/fields/textarea-field.mjs +38 -0
- package/dist/components/index.mjs +59 -0
- package/dist/components/primitives/checkbox-input.mjs +127 -0
- package/dist/components/primitives/date-input.mjs +303 -0
- package/dist/components/primitives/index.mjs +12 -0
- package/dist/components/primitives/number-input.mjs +104 -0
- package/dist/components/primitives/select-input.mjs +177 -0
- package/dist/components/primitives/tag-input.mjs +135 -0
- package/dist/components/primitives/text-input.mjs +39 -0
- package/dist/components/primitives/textarea-input.mjs +37 -0
- package/dist/components/primitives/toggle-input.mjs +31 -0
- package/dist/components/primitives/types.mjs +12 -0
- package/dist/components/ui/accordion.mjs +55 -0
- package/dist/components/ui/avatar.mjs +54 -0
- package/dist/components/ui/badge.mjs +34 -0
- package/dist/components/ui/button.mjs +48 -0
- package/dist/components/ui/card.mjs +58 -0
- package/dist/components/ui/checkbox.mjs +21 -0
- package/dist/components/ui/combobox.mjs +163 -0
- package/dist/components/ui/dialog.mjs +95 -0
- package/dist/components/ui/dropdown-menu.mjs +138 -0
- package/dist/components/ui/field.mjs +113 -0
- package/dist/components/ui/input-group.mjs +82 -0
- package/dist/components/ui/input.mjs +17 -0
- package/dist/components/ui/label.mjs +15 -0
- package/dist/components/ui/popover.mjs +56 -0
- package/dist/components/ui/scroll-area.mjs +38 -0
- package/dist/components/ui/select.mjs +100 -0
- package/dist/components/ui/separator.mjs +16 -0
- package/dist/components/ui/sheet.mjs +90 -0
- package/dist/components/ui/sidebar.mjs +387 -0
- package/dist/components/ui/skeleton.mjs +14 -0
- package/dist/components/ui/spinner.mjs +16 -0
- package/dist/components/ui/switch.mjs +22 -0
- package/dist/components/ui/table.mjs +68 -0
- package/dist/components/ui/tabs.mjs +48 -0
- package/dist/components/ui/textarea.mjs +15 -0
- package/dist/components/ui/tooltip.mjs +44 -0
- package/dist/config/component-registry.mjs +38 -0
- package/dist/config/index.mjs +129 -0
- package/dist/hooks/admin-provider.mjs +70 -0
- package/dist/hooks/index.mjs +7 -0
- package/dist/hooks/store.mjs +178 -0
- package/dist/hooks/use-auth.mjs +76 -0
- package/dist/hooks/use-collection-db.mjs +146 -0
- package/dist/hooks/use-collection.mjs +112 -0
- package/dist/hooks/use-global.mjs +46 -0
- package/dist/hooks/use-mobile.mjs +20 -0
- package/dist/lib/utils.mjs +10 -0
- package/dist/styles/index.css +336 -0
- package/dist/styles/index.mjs +1 -0
- package/dist/utils/index.mjs +9 -0
- package/dist/views/auth/auth-layout.mjs +52 -0
- package/dist/views/auth/forgot-password-form.mjs +148 -0
- package/dist/views/auth/index.mjs +6 -0
- package/dist/views/auth/login-form.mjs +156 -0
- package/dist/views/auth/reset-password-form.mjs +184 -0
- package/dist/views/collection/auto-form-fields.mjs +525 -0
- package/dist/views/collection/collection-form.mjs +91 -0
- package/dist/views/collection/collection-list.mjs +76 -0
- package/dist/views/collection/form-field.mjs +42 -0
- package/dist/views/collection/index.mjs +6 -0
- package/dist/views/common/index.mjs +4 -0
- package/dist/views/common/locale-switcher.mjs +39 -0
- package/dist/views/common/version-history.mjs +272 -0
- package/dist/views/index.mjs +9 -0
- package/dist/views/layout/admin-layout.mjs +40 -0
- package/dist/views/layout/admin-router.mjs +95 -0
- package/dist/views/layout/admin-sidebar.mjs +63 -0
- package/dist/views/layout/index.mjs +5 -0
- package/package.json +276 -0
- package/src/__tests__/setup.ts +44 -0
- package/src/__tests__/test-utils.tsx +49 -0
- package/src/__tests__/vitest.d.ts +9 -0
- package/src/components/admin-app.tsx +221 -0
- package/src/components/fields/array-field.tsx +237 -0
- package/src/components/fields/checkbox-field.tsx +47 -0
- package/src/components/fields/custom-field.tsx +50 -0
- package/src/components/fields/date-field.tsx +65 -0
- package/src/components/fields/datetime-field.tsx +67 -0
- package/src/components/fields/email-field.tsx +51 -0
- package/src/components/fields/embedded-collection.tsx +315 -0
- package/src/components/fields/field-types.ts +162 -0
- package/src/components/fields/field-utils.ts +6 -0
- package/src/components/fields/field-wrapper.tsx +52 -0
- package/src/components/fields/index.ts +66 -0
- package/src/components/fields/json-field.tsx +440 -0
- package/src/components/fields/locale-badge.tsx +15 -0
- package/src/components/fields/number-field.tsx +57 -0
- package/src/components/fields/password-field.tsx +51 -0
- package/src/components/fields/relation-field.tsx +243 -0
- package/src/components/fields/relation-picker.tsx +402 -0
- package/src/components/fields/relation-select.tsx +327 -0
- package/src/components/fields/rich-text-editor/index.tsx +1337 -0
- package/src/components/fields/select-field.tsx +61 -0
- package/src/components/fields/switch-field.tsx +47 -0
- package/src/components/fields/text-field.tsx +55 -0
- package/src/components/fields/textarea-field.tsx +55 -0
- package/src/components/index.ts +40 -0
- package/src/components/primitives/checkbox-input.tsx +193 -0
- package/src/components/primitives/date-input.tsx +401 -0
- package/src/components/primitives/index.ts +24 -0
- package/src/components/primitives/number-input.tsx +132 -0
- package/src/components/primitives/select-input.tsx +296 -0
- package/src/components/primitives/tag-input.tsx +200 -0
- package/src/components/primitives/text-input.tsx +49 -0
- package/src/components/primitives/textarea-input.tsx +46 -0
- package/src/components/primitives/toggle-input.tsx +36 -0
- package/src/components/primitives/types.ts +235 -0
- package/src/components/ui/accordion.tsx +72 -0
- package/src/components/ui/avatar.tsx +106 -0
- package/src/components/ui/badge.tsx +48 -0
- package/src/components/ui/button.tsx +53 -0
- package/src/components/ui/card.tsx +94 -0
- package/src/components/ui/checkbox.tsx +27 -0
- package/src/components/ui/combobox.tsx +290 -0
- package/src/components/ui/dialog.tsx +151 -0
- package/src/components/ui/dropdown-menu.tsx +254 -0
- package/src/components/ui/field.tsx +227 -0
- package/src/components/ui/input-group.tsx +149 -0
- package/src/components/ui/input.tsx +20 -0
- package/src/components/ui/label.tsx +18 -0
- package/src/components/ui/popover.tsx +88 -0
- package/src/components/ui/scroll-area.tsx +53 -0
- package/src/components/ui/select.tsx +192 -0
- package/src/components/ui/separator.tsx +23 -0
- package/src/components/ui/sheet.tsx +127 -0
- package/src/components/ui/sidebar.tsx +723 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/spinner.tsx +10 -0
- package/src/components/ui/switch.tsx +32 -0
- package/src/components/ui/table.tsx +99 -0
- package/src/components/ui/tabs.tsx +82 -0
- package/src/components/ui/textarea.tsx +18 -0
- package/src/components/ui/tooltip.tsx +70 -0
- package/src/config/component-registry.ts +190 -0
- package/src/config/index.ts +1099 -0
- package/src/hooks/README.md +269 -0
- package/src/hooks/admin-provider.tsx +110 -0
- package/src/hooks/index.ts +41 -0
- package/src/hooks/store.ts +248 -0
- package/src/hooks/use-auth.ts +168 -0
- package/src/hooks/use-collection-db.ts +209 -0
- package/src/hooks/use-collection.ts +156 -0
- package/src/hooks/use-global.ts +69 -0
- package/src/hooks/use-mobile.ts +21 -0
- package/src/lib/utils.ts +6 -0
- package/src/styles/index.css +340 -0
- package/src/utils/index.ts +6 -0
- package/src/views/auth/auth-layout.tsx +77 -0
- package/src/views/auth/forgot-password-form.tsx +192 -0
- package/src/views/auth/index.ts +21 -0
- package/src/views/auth/login-form.tsx +229 -0
- package/src/views/auth/reset-password-form.tsx +232 -0
- package/src/views/collection/auto-form-fields.tsx +982 -0
- package/src/views/collection/collection-form.tsx +186 -0
- package/src/views/collection/collection-list.tsx +223 -0
- package/src/views/collection/form-field.tsx +52 -0
- package/src/views/collection/index.ts +15 -0
- package/src/views/common/index.ts +8 -0
- package/src/views/common/locale-switcher.tsx +45 -0
- package/src/views/common/version-history.tsx +406 -0
- package/src/views/index.ts +25 -0
- package/src/views/layout/admin-layout.tsx +117 -0
- package/src/views/layout/admin-router.tsx +206 -0
- package/src/views/layout/admin-sidebar.tsx +185 -0
- package/src/views/layout/index.ts +12 -0
- package/tsconfig.json +13 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsdown.config.ts +13 -0
- package/vitest.config.ts +29 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as React$1 from "react";
|
|
2
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { AdminProvider } from "../hooks/admin-provider";
|
|
5
|
+
import { AdminLayout } from "../views/layout/admin-layout";
|
|
6
|
+
import { AdminRouter } from "../views/layout/admin-router";
|
|
7
|
+
import { mergeComponentRegistry } from "../config/component-registry";
|
|
8
|
+
|
|
9
|
+
//#region src/components/admin-app.tsx
|
|
10
|
+
/**
|
|
11
|
+
* AdminApp Component
|
|
12
|
+
*
|
|
13
|
+
* MAIN ENTRY POINT - Mount this and you have a complete admin!
|
|
14
|
+
*
|
|
15
|
+
* Minimal usage:
|
|
16
|
+
* <AdminApp client={cmsClient} />
|
|
17
|
+
*
|
|
18
|
+
* Everything else is OPTIONAL customization.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Default QueryClient configuration
|
|
22
|
+
*/
|
|
23
|
+
function createDefaultQueryClient() {
|
|
24
|
+
return new QueryClient({ defaultOptions: { queries: {
|
|
25
|
+
staleTime: 60 * 1e3,
|
|
26
|
+
refetchOnWindowFocus: false
|
|
27
|
+
} } });
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* AdminApp Component
|
|
31
|
+
*
|
|
32
|
+
* ONE COMPONENT TO RULE THEM ALL!
|
|
33
|
+
*/
|
|
34
|
+
function AdminApp({ client, config, registry, queryClient, router, basePath = "/admin", DashboardComponent, collectionComponents, renderFormFields }) {
|
|
35
|
+
const [defaultQueryClient] = React$1.useState(() => queryClient ?? createDefaultQueryClient());
|
|
36
|
+
const mergedRegistry = React$1.useMemo(() => mergeComponentRegistry(registry), [registry]);
|
|
37
|
+
const finalConfig = React$1.useMemo(() => {
|
|
38
|
+
if (config) return config;
|
|
39
|
+
return {
|
|
40
|
+
app: { brand: { name: "Admin" } },
|
|
41
|
+
collections: {}
|
|
42
|
+
};
|
|
43
|
+
}, [config]);
|
|
44
|
+
return /* @__PURE__ */ jsxs(QueryClientProvider, {
|
|
45
|
+
client: defaultQueryClient,
|
|
46
|
+
children: [/* @__PURE__ */ jsx(AdminProvider, {
|
|
47
|
+
client,
|
|
48
|
+
queryClient: defaultQueryClient,
|
|
49
|
+
locales: finalConfig.app?.locales,
|
|
50
|
+
children: /* @__PURE__ */ jsx(AdminLayout, {
|
|
51
|
+
config: finalConfig,
|
|
52
|
+
activeRoute: router.currentPath,
|
|
53
|
+
LinkComponent: router.LinkComponent,
|
|
54
|
+
children: /* @__PURE__ */ jsx(AdminRouter, {
|
|
55
|
+
config: finalConfig,
|
|
56
|
+
segments: router.segments,
|
|
57
|
+
navigate: router.navigate,
|
|
58
|
+
DashboardComponent,
|
|
59
|
+
collectionComponents,
|
|
60
|
+
renderFormFields,
|
|
61
|
+
registry: mergedRegistry
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
}), config?.app?.debug?.showQueryDevtools && /* @__PURE__ */ jsx("div", {})]
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
export { AdminApp };
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import * as React$1 from "react";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Button } from "../ui/button";
|
|
4
|
+
import { Input } from "../ui/input";
|
|
5
|
+
import { Select, SelectContent, SelectItem, SelectTrigger } from "../ui/select";
|
|
6
|
+
import { Textarea } from "../ui/textarea";
|
|
7
|
+
import { CaretDown, CaretUp, Plus, Trash } from "@phosphor-icons/react";
|
|
8
|
+
import { useFieldArray, useFormContext, useWatch } from "react-hook-form";
|
|
9
|
+
import { LocaleBadge } from "./locale-badge";
|
|
10
|
+
|
|
11
|
+
//#region src/components/fields/array-field.tsx
|
|
12
|
+
/**
|
|
13
|
+
* ArrayField Component
|
|
14
|
+
*
|
|
15
|
+
* Handles arrays of primitive values with optional ordering.
|
|
16
|
+
*/
|
|
17
|
+
function ArrayField({ name, value, label, description, placeholder, required, disabled, readOnly, error, localized, locale, itemType = "text", options, orderable = false, minItems, maxItems }) {
|
|
18
|
+
const form = useFormContext();
|
|
19
|
+
const { control } = form;
|
|
20
|
+
const { fields, append, remove, move } = useFieldArray({
|
|
21
|
+
control,
|
|
22
|
+
name
|
|
23
|
+
});
|
|
24
|
+
const values = useWatch({
|
|
25
|
+
control,
|
|
26
|
+
name
|
|
27
|
+
}) ?? value;
|
|
28
|
+
const canAddMore = !maxItems || fields.length < maxItems;
|
|
29
|
+
const canRemove = !readOnly && (!minItems || fields.length > minItems);
|
|
30
|
+
const createEmptyItem = React$1.useCallback(() => {
|
|
31
|
+
if (itemType === "number") return void 0;
|
|
32
|
+
if (itemType === "select") return options?.[0]?.value ?? "";
|
|
33
|
+
return "";
|
|
34
|
+
}, [itemType, options]);
|
|
35
|
+
const handleAdd = () => {
|
|
36
|
+
if (disabled || readOnly || !canAddMore) return;
|
|
37
|
+
append(createEmptyItem());
|
|
38
|
+
};
|
|
39
|
+
const handleRemove = (index) => {
|
|
40
|
+
if (!canRemove) return;
|
|
41
|
+
remove(index);
|
|
42
|
+
};
|
|
43
|
+
const handleMove = (from, to) => {
|
|
44
|
+
if (to < 0 || to >= fields.length) return;
|
|
45
|
+
move(from, to);
|
|
46
|
+
};
|
|
47
|
+
const renderItemInput = (index) => {
|
|
48
|
+
const itemName = `${name}.${index}`;
|
|
49
|
+
const itemValue = values?.[index];
|
|
50
|
+
const itemPlaceholder = placeholder || `Item ${index + 1}`;
|
|
51
|
+
if (itemType === "textarea") return /* @__PURE__ */ jsx(Textarea, {
|
|
52
|
+
id: itemName,
|
|
53
|
+
placeholder: itemPlaceholder,
|
|
54
|
+
disabled: disabled || readOnly,
|
|
55
|
+
defaultValue: itemValue ?? "",
|
|
56
|
+
...form.register(itemName)
|
|
57
|
+
});
|
|
58
|
+
if (itemType === "select") return /* @__PURE__ */ jsxs(Select, {
|
|
59
|
+
value: itemValue ?? "",
|
|
60
|
+
onValueChange: (value$1) => form.setValue(itemName, value$1, {
|
|
61
|
+
shouldDirty: true,
|
|
62
|
+
shouldTouch: true
|
|
63
|
+
}),
|
|
64
|
+
disabled: disabled || readOnly,
|
|
65
|
+
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
66
|
+
id: itemName,
|
|
67
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
68
|
+
className: "truncate",
|
|
69
|
+
children: options?.find((o) => o.value === itemValue)?.label || itemPlaceholder
|
|
70
|
+
})
|
|
71
|
+
}), /* @__PURE__ */ jsx(SelectContent, { children: options?.map((option) => /* @__PURE__ */ jsx(SelectItem, {
|
|
72
|
+
value: option.value,
|
|
73
|
+
children: option.label
|
|
74
|
+
}, option.value)) })]
|
|
75
|
+
});
|
|
76
|
+
return /* @__PURE__ */ jsx(Input, {
|
|
77
|
+
id: itemName,
|
|
78
|
+
type: itemType === "email" ? "email" : itemType,
|
|
79
|
+
placeholder: itemPlaceholder,
|
|
80
|
+
disabled: disabled || readOnly,
|
|
81
|
+
defaultValue: itemValue ?? "",
|
|
82
|
+
...form.register(itemName, itemType === "number" ? { valueAsNumber: true } : void 0)
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
86
|
+
className: "space-y-2",
|
|
87
|
+
children: [
|
|
88
|
+
label && /* @__PURE__ */ jsxs("div", {
|
|
89
|
+
className: "flex items-center gap-2",
|
|
90
|
+
children: [/* @__PURE__ */ jsxs("label", {
|
|
91
|
+
htmlFor: name,
|
|
92
|
+
className: "text-sm font-medium",
|
|
93
|
+
children: [
|
|
94
|
+
label,
|
|
95
|
+
required && /* @__PURE__ */ jsx("span", {
|
|
96
|
+
className: "text-destructive",
|
|
97
|
+
children: "*"
|
|
98
|
+
}),
|
|
99
|
+
maxItems && /* @__PURE__ */ jsxs("span", {
|
|
100
|
+
className: "ml-2 text-xs text-muted-foreground",
|
|
101
|
+
children: [
|
|
102
|
+
"(",
|
|
103
|
+
fields.length,
|
|
104
|
+
"/",
|
|
105
|
+
maxItems,
|
|
106
|
+
")"
|
|
107
|
+
]
|
|
108
|
+
})
|
|
109
|
+
]
|
|
110
|
+
}), localized && /* @__PURE__ */ jsx(LocaleBadge, { locale: locale || "i18n" })]
|
|
111
|
+
}),
|
|
112
|
+
description && /* @__PURE__ */ jsx("p", {
|
|
113
|
+
className: "text-sm text-muted-foreground",
|
|
114
|
+
children: description
|
|
115
|
+
}),
|
|
116
|
+
/* @__PURE__ */ jsx("div", {
|
|
117
|
+
className: "space-y-2",
|
|
118
|
+
children: fields.length === 0 ? /* @__PURE__ */ jsx("div", {
|
|
119
|
+
className: "rounded-lg border border-dashed p-4 text-center",
|
|
120
|
+
children: /* @__PURE__ */ jsx("p", {
|
|
121
|
+
className: "text-sm text-muted-foreground",
|
|
122
|
+
children: placeholder || `No ${label || "items"} added yet`
|
|
123
|
+
})
|
|
124
|
+
}) : fields.map((field, index) => {
|
|
125
|
+
const canMoveUp = orderable && index > 0;
|
|
126
|
+
const canMoveDown = orderable && index < fields.length - 1;
|
|
127
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
128
|
+
className: "flex items-start gap-2",
|
|
129
|
+
children: [
|
|
130
|
+
/* @__PURE__ */ jsx("div", {
|
|
131
|
+
className: "flex-1",
|
|
132
|
+
children: renderItemInput(index)
|
|
133
|
+
}),
|
|
134
|
+
orderable && !readOnly && /* @__PURE__ */ jsxs("div", {
|
|
135
|
+
className: "flex flex-col gap-1",
|
|
136
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
137
|
+
type: "button",
|
|
138
|
+
variant: "ghost",
|
|
139
|
+
size: "icon",
|
|
140
|
+
className: "h-6 w-6",
|
|
141
|
+
onClick: () => handleMove(index, index - 1),
|
|
142
|
+
disabled: !canMoveUp || disabled,
|
|
143
|
+
title: "Move up",
|
|
144
|
+
children: /* @__PURE__ */ jsx(CaretUp, { className: "h-3 w-3" })
|
|
145
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
146
|
+
type: "button",
|
|
147
|
+
variant: "ghost",
|
|
148
|
+
size: "icon",
|
|
149
|
+
className: "h-6 w-6",
|
|
150
|
+
onClick: () => handleMove(index, index + 1),
|
|
151
|
+
disabled: !canMoveDown || disabled,
|
|
152
|
+
title: "Move down",
|
|
153
|
+
children: /* @__PURE__ */ jsx(CaretDown, { className: "h-3 w-3" })
|
|
154
|
+
})]
|
|
155
|
+
}),
|
|
156
|
+
!readOnly && canRemove && /* @__PURE__ */ jsx(Button, {
|
|
157
|
+
type: "button",
|
|
158
|
+
variant: "ghost",
|
|
159
|
+
size: "icon",
|
|
160
|
+
className: "h-6 w-6",
|
|
161
|
+
onClick: () => handleRemove(index),
|
|
162
|
+
disabled,
|
|
163
|
+
title: "Remove",
|
|
164
|
+
children: /* @__PURE__ */ jsx(Trash, { className: "h-3 w-3" })
|
|
165
|
+
})
|
|
166
|
+
]
|
|
167
|
+
}, field.id);
|
|
168
|
+
})
|
|
169
|
+
}),
|
|
170
|
+
!readOnly && canAddMore && /* @__PURE__ */ jsxs(Button, {
|
|
171
|
+
type: "button",
|
|
172
|
+
variant: "outline",
|
|
173
|
+
onClick: handleAdd,
|
|
174
|
+
disabled,
|
|
175
|
+
children: [
|
|
176
|
+
/* @__PURE__ */ jsx(Plus, { className: "h-4 w-4" }),
|
|
177
|
+
"Add ",
|
|
178
|
+
label || "item"
|
|
179
|
+
]
|
|
180
|
+
}),
|
|
181
|
+
error && /* @__PURE__ */ jsx("p", {
|
|
182
|
+
className: "text-sm text-destructive",
|
|
183
|
+
children: error
|
|
184
|
+
})
|
|
185
|
+
]
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
//#endregion
|
|
190
|
+
export { ArrayField };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { CheckboxInput } from "../primitives/checkbox-input";
|
|
3
|
+
import { Controller } from "react-hook-form";
|
|
4
|
+
import { FieldWrapper } from "./field-wrapper";
|
|
5
|
+
import { useResolvedControl } from "./field-utils";
|
|
6
|
+
|
|
7
|
+
//#region src/components/fields/checkbox-field.tsx
|
|
8
|
+
function CheckboxField({ name, label, description, required, disabled, localized, locale, control, className }) {
|
|
9
|
+
return /* @__PURE__ */ jsx(Controller, {
|
|
10
|
+
name,
|
|
11
|
+
control: useResolvedControl(control),
|
|
12
|
+
render: ({ field, fieldState }) => /* @__PURE__ */ jsx(FieldWrapper, {
|
|
13
|
+
name,
|
|
14
|
+
label,
|
|
15
|
+
description,
|
|
16
|
+
required,
|
|
17
|
+
disabled,
|
|
18
|
+
localized,
|
|
19
|
+
locale,
|
|
20
|
+
error: fieldState.error?.message,
|
|
21
|
+
children: /* @__PURE__ */ jsx(CheckboxInput, {
|
|
22
|
+
id: name,
|
|
23
|
+
value: !!field.value,
|
|
24
|
+
onChange: field.onChange,
|
|
25
|
+
disabled,
|
|
26
|
+
"aria-invalid": !!fieldState.error,
|
|
27
|
+
className
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { CheckboxField };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Controller } from "react-hook-form";
|
|
4
|
+
import { FieldWrapper } from "./field-wrapper";
|
|
5
|
+
import { useResolvedControl } from "./field-utils";
|
|
6
|
+
|
|
7
|
+
//#region src/components/fields/custom-field.tsx
|
|
8
|
+
function CustomField({ name, label, description, placeholder, required, disabled, localized, locale, control, component: Component }) {
|
|
9
|
+
return /* @__PURE__ */ jsx(Controller, {
|
|
10
|
+
name,
|
|
11
|
+
control: useResolvedControl(control),
|
|
12
|
+
render: ({ field, fieldState }) => /* @__PURE__ */ jsx(FieldWrapper, {
|
|
13
|
+
name,
|
|
14
|
+
label,
|
|
15
|
+
description,
|
|
16
|
+
required,
|
|
17
|
+
disabled,
|
|
18
|
+
localized,
|
|
19
|
+
locale,
|
|
20
|
+
error: fieldState.error?.message,
|
|
21
|
+
children: /* @__PURE__ */ jsx(Component, {
|
|
22
|
+
...field,
|
|
23
|
+
id: name,
|
|
24
|
+
disabled,
|
|
25
|
+
placeholder
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { CustomField };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { DateInput } from "../primitives/date-input";
|
|
3
|
+
import { Controller } from "react-hook-form";
|
|
4
|
+
import { FieldWrapper } from "./field-wrapper";
|
|
5
|
+
import { useResolvedControl } from "./field-utils";
|
|
6
|
+
|
|
7
|
+
//#region src/components/fields/date-field.tsx
|
|
8
|
+
function DateField({ name, label, description, placeholder, required, disabled, localized, locale, control, className, minDate, maxDate, format }) {
|
|
9
|
+
return /* @__PURE__ */ jsx(Controller, {
|
|
10
|
+
name,
|
|
11
|
+
control: useResolvedControl(control),
|
|
12
|
+
render: ({ field, fieldState }) => {
|
|
13
|
+
const dateValue = field.value instanceof Date ? field.value : field.value ? new Date(field.value) : null;
|
|
14
|
+
return /* @__PURE__ */ jsx(FieldWrapper, {
|
|
15
|
+
name,
|
|
16
|
+
label,
|
|
17
|
+
description,
|
|
18
|
+
required,
|
|
19
|
+
disabled,
|
|
20
|
+
localized,
|
|
21
|
+
locale,
|
|
22
|
+
error: fieldState.error?.message,
|
|
23
|
+
children: /* @__PURE__ */ jsx(DateInput, {
|
|
24
|
+
id: name,
|
|
25
|
+
value: dateValue,
|
|
26
|
+
onChange: field.onChange,
|
|
27
|
+
minDate,
|
|
28
|
+
maxDate,
|
|
29
|
+
format,
|
|
30
|
+
placeholder,
|
|
31
|
+
disabled,
|
|
32
|
+
"aria-invalid": !!fieldState.error,
|
|
33
|
+
className
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { DateField };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { DateTimeInput } from "../primitives/date-input";
|
|
3
|
+
import { Controller } from "react-hook-form";
|
|
4
|
+
import { FieldWrapper } from "./field-wrapper";
|
|
5
|
+
import { useResolvedControl } from "./field-utils";
|
|
6
|
+
|
|
7
|
+
//#region src/components/fields/datetime-field.tsx
|
|
8
|
+
function DatetimeField({ name, label, description, placeholder, required, disabled, localized, locale, control, className, minDate, maxDate, format, precision }) {
|
|
9
|
+
return /* @__PURE__ */ jsx(Controller, {
|
|
10
|
+
name,
|
|
11
|
+
control: useResolvedControl(control),
|
|
12
|
+
render: ({ field, fieldState }) => {
|
|
13
|
+
const dateValue = field.value instanceof Date ? field.value : field.value ? new Date(field.value) : null;
|
|
14
|
+
return /* @__PURE__ */ jsx(FieldWrapper, {
|
|
15
|
+
name,
|
|
16
|
+
label,
|
|
17
|
+
description,
|
|
18
|
+
required,
|
|
19
|
+
disabled,
|
|
20
|
+
localized,
|
|
21
|
+
locale,
|
|
22
|
+
error: fieldState.error?.message,
|
|
23
|
+
children: /* @__PURE__ */ jsx(DateTimeInput, {
|
|
24
|
+
id: name,
|
|
25
|
+
value: dateValue,
|
|
26
|
+
onChange: field.onChange,
|
|
27
|
+
minDate,
|
|
28
|
+
maxDate,
|
|
29
|
+
format,
|
|
30
|
+
precision,
|
|
31
|
+
placeholder,
|
|
32
|
+
disabled,
|
|
33
|
+
"aria-invalid": !!fieldState.error,
|
|
34
|
+
className
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { DatetimeField };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { TextInput } from "../primitives/text-input";
|
|
3
|
+
import { Controller } from "react-hook-form";
|
|
4
|
+
import { FieldWrapper } from "./field-wrapper";
|
|
5
|
+
import { useResolvedControl } from "./field-utils";
|
|
6
|
+
|
|
7
|
+
//#region src/components/fields/email-field.tsx
|
|
8
|
+
function EmailField({ name, label, description, placeholder, required, disabled, localized, locale, control, className }) {
|
|
9
|
+
return /* @__PURE__ */ jsx(Controller, {
|
|
10
|
+
name,
|
|
11
|
+
control: useResolvedControl(control),
|
|
12
|
+
render: ({ field, fieldState }) => /* @__PURE__ */ jsx(FieldWrapper, {
|
|
13
|
+
name,
|
|
14
|
+
label,
|
|
15
|
+
description,
|
|
16
|
+
required,
|
|
17
|
+
disabled,
|
|
18
|
+
localized,
|
|
19
|
+
locale,
|
|
20
|
+
error: fieldState.error?.message,
|
|
21
|
+
children: /* @__PURE__ */ jsx(TextInput, {
|
|
22
|
+
id: name,
|
|
23
|
+
value: field.value ?? "",
|
|
24
|
+
onChange: field.onChange,
|
|
25
|
+
type: "email",
|
|
26
|
+
placeholder,
|
|
27
|
+
disabled,
|
|
28
|
+
autoComplete: "email",
|
|
29
|
+
"aria-invalid": !!fieldState.error,
|
|
30
|
+
className
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { EmailField };
|