@vertebr/react 0.2.0 → 0.4.0

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.
Files changed (89) hide show
  1. package/dist/components/admin/VertebrAdmin.d.ts.map +1 -1
  2. package/dist/components/admin/VertebrAdmin.js +26 -4
  3. package/dist/components/config/ConfigForm.d.ts +2 -18
  4. package/dist/components/config/ConfigForm.d.ts.map +1 -1
  5. package/dist/components/config/ConfigForm.js +1 -281
  6. package/dist/components/config/DescriptionInput.d.ts +18 -0
  7. package/dist/components/config/DescriptionInput.d.ts.map +1 -0
  8. package/dist/components/config/DescriptionInput.js +152 -0
  9. package/dist/components/config/EnumInput.d.ts +10 -0
  10. package/dist/components/config/EnumInput.d.ts.map +1 -0
  11. package/dist/components/config/EnumInput.js +19 -0
  12. package/dist/components/config/EnumListInput.d.ts +10 -0
  13. package/dist/components/config/EnumListInput.d.ts.map +1 -0
  14. package/dist/components/config/EnumListInput.js +46 -0
  15. package/dist/components/config/ImagePickerModal.d.ts +18 -0
  16. package/dist/components/config/ImagePickerModal.d.ts.map +1 -0
  17. package/dist/components/config/ImagePickerModal.js +120 -0
  18. package/dist/components/config/PriceInput.d.ts +12 -0
  19. package/dist/components/config/PriceInput.d.ts.map +1 -0
  20. package/dist/components/config/PriceInput.js +20 -0
  21. package/dist/components/config/VisibilityEye.d.ts +8 -0
  22. package/dist/components/config/VisibilityEye.d.ts.map +1 -0
  23. package/dist/components/config/VisibilityEye.js +18 -0
  24. package/dist/components/config/form/ConfigField.d.ts +22 -0
  25. package/dist/components/config/form/ConfigField.d.ts.map +1 -0
  26. package/dist/components/config/form/ConfigField.js +53 -0
  27. package/dist/components/config/form/ConfigForm.d.ts +4 -0
  28. package/dist/components/config/form/ConfigForm.d.ts.map +1 -0
  29. package/dist/components/config/form/ConfigForm.js +75 -0
  30. package/dist/components/config/form/ConfigFormActions.d.ts +11 -0
  31. package/dist/components/config/form/ConfigFormActions.d.ts.map +1 -0
  32. package/dist/components/config/form/ConfigFormActions.js +4 -0
  33. package/dist/components/config/form/RecordConfigForm.d.ts +22 -0
  34. package/dist/components/config/form/RecordConfigForm.d.ts.map +1 -0
  35. package/dist/components/config/form/RecordConfigForm.js +45 -0
  36. package/dist/components/config/form/SettingsConfigForm.d.ts +22 -0
  37. package/dist/components/config/form/SettingsConfigForm.d.ts.map +1 -0
  38. package/dist/components/config/form/SettingsConfigForm.js +7 -0
  39. package/dist/components/config/form/helpers/fields.d.ts +7 -0
  40. package/dist/components/config/form/helpers/fields.d.ts.map +1 -0
  41. package/dist/components/config/form/helpers/fields.js +31 -0
  42. package/dist/components/config/form/helpers/groups.d.ts +4 -0
  43. package/dist/components/config/form/helpers/groups.d.ts.map +1 -0
  44. package/dist/components/config/form/helpers/groups.js +107 -0
  45. package/dist/components/config/form/helpers/images.d.ts +4 -0
  46. package/dist/components/config/form/helpers/images.d.ts.map +1 -0
  47. package/dist/components/config/form/helpers/images.js +27 -0
  48. package/dist/components/config/form/helpers/index.d.ts +7 -0
  49. package/dist/components/config/form/helpers/index.d.ts.map +1 -0
  50. package/dist/components/config/form/helpers/index.js +6 -0
  51. package/dist/components/config/form/helpers/labels.d.ts +5 -0
  52. package/dist/components/config/form/helpers/labels.d.ts.map +1 -0
  53. package/dist/components/config/form/helpers/labels.js +28 -0
  54. package/dist/components/config/form/helpers/schema.d.ts +8 -0
  55. package/dist/components/config/form/helpers/schema.d.ts.map +1 -0
  56. package/dist/components/config/form/helpers/schema.js +30 -0
  57. package/dist/components/config/form/helpers/visibility.d.ts +13 -0
  58. package/dist/components/config/form/helpers/visibility.d.ts.map +1 -0
  59. package/dist/components/config/form/helpers/visibility.js +86 -0
  60. package/dist/components/config/form/types.d.ts +29 -0
  61. package/dist/components/config/form/types.d.ts.map +1 -0
  62. package/dist/components/config/form/types.js +1 -0
  63. package/dist/components/resources/ResourceCell.d.ts.map +1 -1
  64. package/dist/components/resources/ResourceCell.js +5 -19
  65. package/dist/components/resources/ResourceCreateModal.d.ts +18 -0
  66. package/dist/components/resources/ResourceCreateModal.d.ts.map +1 -0
  67. package/dist/components/resources/ResourceCreateModal.js +22 -0
  68. package/dist/components/resources/ResourceTable.d.ts +7 -2
  69. package/dist/components/resources/ResourceTable.d.ts.map +1 -1
  70. package/dist/components/resources/ResourceTable.js +92 -7
  71. package/dist/hooks/useVertebrControls.d.ts.map +1 -1
  72. package/dist/hooks/useVertebrControls.js +5 -4
  73. package/dist/index.d.ts +11 -2
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +6 -1
  76. package/dist/lib/description.d.ts +18 -0
  77. package/dist/lib/description.d.ts.map +1 -0
  78. package/dist/lib/description.js +85 -0
  79. package/dist/lib/images.d.ts +14 -0
  80. package/dist/lib/images.d.ts.map +1 -0
  81. package/dist/lib/images.js +63 -0
  82. package/dist/lib/price.d.ts +15 -0
  83. package/dist/lib/price.d.ts.map +1 -0
  84. package/dist/lib/price.js +50 -0
  85. package/dist/styles/form.css +420 -0
  86. package/dist/styles/modal.css +133 -0
  87. package/dist/styles/panel.css +18 -1
  88. package/dist/styles/table.css +10 -1
  89. package/package.json +10 -3
@@ -0,0 +1,46 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { optionLabel } from "./form/helpers/labels";
3
+ function asStringList(value) {
4
+ if (!Array.isArray(value))
5
+ return [];
6
+ return value.map((item) => String(item).trim()).filter(Boolean);
7
+ }
8
+ function orderedRows(options, selected) {
9
+ const known = new Set(options);
10
+ const picked = selected.filter((id) => known.has(id));
11
+ const rest = options.filter((id) => !picked.includes(id));
12
+ return [
13
+ ...picked.map((id) => ({ id, on: true })),
14
+ ...rest.map((id) => ({ id, on: false })),
15
+ ];
16
+ }
17
+ export function EnumListInput({ id, value, field, readOnly, onChange, }) {
18
+ const options = field.options?.filter(Boolean) ?? [];
19
+ const selected = asStringList(value);
20
+ const rows = orderedRows(options, selected);
21
+ const commit = (nextRows) => {
22
+ onChange(nextRows.filter((row) => row.on).map((row) => row.id));
23
+ };
24
+ return (_jsx("ul", { id: id, className: "vertebr-enum-list", children: rows.map((row, index) => (_jsxs("li", { className: "vertebr-enum-list-row", "data-on": row.on, children: [_jsxs("label", { className: "vertebr-enum-list-label", children: [_jsx("input", { type: "checkbox", checked: row.on, disabled: readOnly, onChange: (event) => {
25
+ const next = rows.map((item) => item.id === row.id
26
+ ? { ...item, on: event.target.checked }
27
+ : item);
28
+ commit(next);
29
+ } }), _jsx("span", { children: optionLabel(row.id, field) })] }), _jsxs("div", { className: "vertebr-enum-list-move", children: [_jsx("button", { type: "button", "aria-label": `Move ${optionLabel(row.id, field)} up`, disabled: readOnly || index === 0, onClick: () => {
30
+ if (index === 0)
31
+ return;
32
+ const next = [...rows];
33
+ const current = next[index];
34
+ next[index] = next[index - 1];
35
+ next[index - 1] = current;
36
+ commit(next);
37
+ }, children: "\u2191" }), _jsx("button", { type: "button", "aria-label": `Move ${optionLabel(row.id, field)} down`, disabled: readOnly || index === rows.length - 1, onClick: () => {
38
+ if (index >= rows.length - 1)
39
+ return;
40
+ const next = [...rows];
41
+ const current = next[index];
42
+ next[index] = next[index + 1];
43
+ next[index + 1] = current;
44
+ commit(next);
45
+ }, children: "\u2193" })] })] }, row.id))) }));
46
+ }
@@ -0,0 +1,18 @@
1
+ import type { GalleryItem, ResourceUploadMeta } from "@vertebr/client";
2
+ import type { RecordImage } from "../../lib/images";
3
+ export type PickerImage = {
4
+ id: string;
5
+ url: string;
6
+ name: string;
7
+ source: "record" | "gallery" | "url";
8
+ };
9
+ export type ImagePickerModalProps = {
10
+ recordImages?: RecordImage[];
11
+ galleryUpload?: Pick<ResourceUploadMeta, "accept" | "maxBytes">;
12
+ onListGallery?: () => Promise<GalleryItem[]>;
13
+ onUploadGallery?: (files: File[]) => Promise<GalleryItem[]>;
14
+ onClose: () => void;
15
+ onInsert: (images: PickerImage[]) => void;
16
+ };
17
+ export declare function ImagePickerModal({ recordImages, galleryUpload, onListGallery, onUploadGallery, onClose, onInsert, }: ImagePickerModalProps): import("react").JSX.Element;
18
+ //# sourceMappingURL=ImagePickerModal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImagePickerModal.d.ts","sourceRoot":"","sources":["../../../src/components/config/ImagePickerModal.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAEvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,KAAK,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,YAAY,CAAC,EAAE,WAAW,EAAE,CAAC;IAC7B,aAAa,CAAC,EAAE,IAAI,CAAC,kBAAkB,EAAE,QAAQ,GAAG,UAAU,CAAC,CAAC;IAChE,aAAa,CAAC,EAAE,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAC7C,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAC5D,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,IAAI,CAAC;CAC3C,CAAC;AAIF,wBAAgB,gBAAgB,CAAC,EAC/B,YAAiB,EACjB,aAAa,EACb,aAAa,EACb,eAAe,EACf,OAAO,EACP,QAAQ,GACT,EAAE,qBAAqB,+BA4PvB"}
@@ -0,0 +1,120 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useMemo, useState } from "react";
3
+ import { ImageUploadControl } from "../resources/ImageUploadControl";
4
+ export function ImagePickerModal({ recordImages = [], galleryUpload, onListGallery, onUploadGallery, onClose, onInsert, }) {
5
+ const hasGallery = Boolean(onListGallery);
6
+ const [tab, setTab] = useState(recordImages.length ? "record" : "gallery");
7
+ const [gallery, setGallery] = useState([]);
8
+ const [loading, setLoading] = useState(false);
9
+ const [error, setError] = useState(null);
10
+ const [selected, setSelected] = useState({});
11
+ const [url, setUrl] = useState("");
12
+ useEffect(() => {
13
+ const onKeyDown = (event) => {
14
+ if (event.key === "Escape")
15
+ onClose();
16
+ };
17
+ window.addEventListener("keydown", onKeyDown);
18
+ const previous = document.body.style.overflow;
19
+ document.body.style.overflow = "hidden";
20
+ return () => {
21
+ window.removeEventListener("keydown", onKeyDown);
22
+ document.body.style.overflow = previous;
23
+ };
24
+ }, [onClose]);
25
+ useEffect(() => {
26
+ if (!hasGallery)
27
+ return;
28
+ let cancelled = false;
29
+ setLoading(true);
30
+ setError(null);
31
+ void onListGallery()
32
+ .then((items) => {
33
+ if (!cancelled)
34
+ setGallery(items);
35
+ })
36
+ .catch((err) => {
37
+ if (!cancelled) {
38
+ setError(err instanceof Error ? err.message : "Could not load gallery");
39
+ }
40
+ })
41
+ .finally(() => {
42
+ if (!cancelled)
43
+ setLoading(false);
44
+ });
45
+ return () => {
46
+ cancelled = true;
47
+ };
48
+ }, [hasGallery, onListGallery]);
49
+ const recordTiles = useMemo(() => recordImages.map((image) => ({
50
+ id: `record:${image.id}`,
51
+ url: image.url,
52
+ name: image.name,
53
+ source: "record",
54
+ })), [recordImages]);
55
+ const galleryTiles = useMemo(() => gallery.map((item) => ({
56
+ id: `gallery:${item.id}`,
57
+ url: item.url,
58
+ name: item.name ?? item.id,
59
+ source: "gallery",
60
+ })), [gallery]);
61
+ const tiles = tab === "record" ? recordTiles : galleryTiles;
62
+ const picked = Object.values(selected);
63
+ const canGalleryUpload = Boolean(galleryUpload && onUploadGallery);
64
+ const toggle = (image) => {
65
+ setSelected((current) => {
66
+ const next = { ...current };
67
+ if (next[image.id])
68
+ delete next[image.id];
69
+ else
70
+ next[image.id] = image;
71
+ return next;
72
+ });
73
+ };
74
+ const addUrl = () => {
75
+ const href = url.trim();
76
+ if (!href)
77
+ return;
78
+ const image = {
79
+ id: `url:${href}`,
80
+ url: href,
81
+ name: "Image",
82
+ source: "url",
83
+ };
84
+ setSelected((current) => ({ ...current, [image.id]: image }));
85
+ setUrl("");
86
+ };
87
+ return (_jsx("div", { className: "vertebr-modal-backdrop", role: "presentation", onClick: onClose, children: _jsxs("div", { className: "vertebr-modal", role: "dialog", "aria-modal": "true", "aria-label": "Insert images", onClick: (event) => event.stopPropagation(), children: [_jsxs("header", { className: "vertebr-modal-head", children: [_jsxs("div", { className: "vertebr-modal-heading", children: [_jsx("p", { className: "vertebr-modal-eyebrow", children: "Media" }), _jsx("h2", { children: "Insert images" })] }), _jsx("button", { type: "button", className: "vertebr-btn", onClick: onClose, children: "Close" })] }), _jsxs("div", { className: "vertebr-modal-body vertebr-picker-body", children: [recordImages.length > 0 && hasGallery ? (_jsxs("div", { className: "vertebr-picker-tabs", role: "tablist", children: [_jsxs("button", { type: "button", role: "tab", "aria-selected": tab === "record", "data-active": tab === "record" || undefined, onClick: () => setTab("record"), children: ["Product photos", _jsx("span", { children: recordTiles.length })] }), _jsxs("button", { type: "button", role: "tab", "aria-selected": tab === "gallery", "data-active": tab === "gallery" || undefined, onClick: () => setTab("gallery"), children: ["Gallery", _jsx("span", { children: loading ? "…" : galleryTiles.length })] })] })) : null, tab === "gallery" && canGalleryUpload ? (_jsx(ImageUploadControl, { meta: {
88
+ field: "gallery",
89
+ accept: galleryUpload.accept,
90
+ maxBytes: galleryUpload.maxBytes,
91
+ }, multiple: true, label: "Drop images to add them to the gallery", onUpload: async (files) => {
92
+ const items = await onUploadGallery(files);
93
+ setGallery((current) => [...items, ...current]);
94
+ setSelected((current) => {
95
+ const next = { ...current };
96
+ for (const item of items) {
97
+ const image = {
98
+ id: `gallery:${item.id}`,
99
+ url: item.url,
100
+ name: item.name ?? item.id,
101
+ source: "gallery",
102
+ };
103
+ next[image.id] = image;
104
+ }
105
+ return next;
106
+ });
107
+ } })) : null, _jsxs("label", { className: "vertebr-field", children: [_jsx("span", { children: "Or paste an image URL" }), _jsxs("div", { className: "vertebr-picker-url", children: [_jsx("input", { type: "url", value: url, placeholder: "https://", onChange: (event) => setUrl(event.target.value), onKeyDown: (event) => {
108
+ if (event.key === "Enter") {
109
+ event.preventDefault();
110
+ addUrl();
111
+ }
112
+ } }), _jsx("button", { type: "button", className: "vertebr-btn", disabled: !url.trim(), onClick: addUrl, children: "Add" })] })] }), error ? (_jsx("p", { className: "vertebr-status", "data-tone": "danger", children: error })) : null, loading && tab === "gallery" ? (_jsx("div", { className: "vertebr-empty", children: "Loading gallery\u2026" })) : tiles.length === 0 ? (_jsx("div", { className: "vertebr-empty", children: tab === "record"
113
+ ? "No product photos on this record yet."
114
+ : hasGallery
115
+ ? "No images in the gallery yet."
116
+ : "No gallery is configured. Paste a URL or add product photos." })) : (_jsx("div", { className: "vertebr-picker-grid", children: tiles.map((image) => {
117
+ const active = Boolean(selected[image.id]);
118
+ return (_jsxs("button", { type: "button", className: "vertebr-picker-tile", "data-selected": active || undefined, onClick: () => toggle(image), children: [_jsx("span", { className: "vertebr-picker-thumb", children: _jsx("img", { src: image.url, alt: "" }) }), _jsx("span", { className: "vertebr-picker-name", children: image.name })] }, image.id));
119
+ }) }))] }), _jsxs("footer", { className: "vertebr-picker-foot", children: [_jsxs("span", { className: "vertebr-picker-count", children: [picked.length, " selected"] }), _jsxs("button", { type: "button", className: "vertebr-btn vertebr-btn-primary", disabled: picked.length === 0, onClick: () => onInsert(picked), children: ["Insert ", picked.length || "", picked.length === 1 ? " image" : " images"] })] })] }) }));
120
+ }
@@ -0,0 +1,12 @@
1
+ export type PriceInputProps = {
2
+ id: string;
3
+ name?: string;
4
+ value: unknown;
5
+ asCents?: boolean;
6
+ readOnly?: boolean;
7
+ onBlur?: () => void;
8
+ onChange: (next: number | undefined) => void;
9
+ inputRef?: React.Ref<HTMLInputElement>;
10
+ };
11
+ export declare function PriceInput({ id, name, value, asCents, readOnly, onBlur, onChange, inputRef, }: PriceInputProps): import("react").JSX.Element;
12
+ //# sourceMappingURL=PriceInput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PriceInput.d.ts","sourceRoot":"","sources":["../../../src/components/config/PriceInput.tsx"],"names":[],"mappings":"AAOA,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;IAC7C,QAAQ,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;CACxC,CAAC;AAEF,wBAAgB,UAAU,CAAC,EACzB,EAAE,EACF,IAAI,EACJ,KAAK,EACL,OAAc,EACd,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,QAAQ,GACT,EAAE,eAAe,+BAwCjB"}
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useState } from "react";
3
+ import { formatPrice, formatPriceInput, parsePriceInput, } from "../../lib/price";
4
+ export function PriceInput({ id, name, value, asCents = true, readOnly, onBlur, onChange, inputRef, }) {
5
+ const [draft, setDraft] = useState(() => formatPriceInput(value, asCents));
6
+ useEffect(() => {
7
+ setDraft(formatPriceInput(value, asCents));
8
+ }, [value, asCents]);
9
+ const preview = typeof value === "number" && Number.isFinite(value)
10
+ ? formatPrice(value, { asCents })
11
+ : null;
12
+ return (_jsxs("div", { className: "vertebr-field-money", children: [_jsx("span", { className: "vertebr-field-money-prefix", "aria-hidden": "true", children: "$" }), _jsx("input", { id: id, name: name, ref: inputRef, type: "text", inputMode: "decimal", autoComplete: "off", readOnly: readOnly, value: draft, placeholder: "0.00", "aria-label": preview ? `Price ${preview}` : "Price", onChange: (event) => {
13
+ const next = event.target.value;
14
+ setDraft(next);
15
+ onChange(parsePriceInput(next, asCents));
16
+ }, onBlur: () => {
17
+ setDraft(formatPriceInput(value, asCents));
18
+ onBlur?.();
19
+ } })] }));
20
+ }
@@ -0,0 +1,8 @@
1
+ import type { UseFormReturn } from "react-hook-form";
2
+ export type VisibilityEyeButtonProps = {
3
+ name: string;
4
+ label: string;
5
+ form: UseFormReturn<Record<string, unknown>>;
6
+ };
7
+ export declare function VisibilityEyeButton({ name, label, form, }: VisibilityEyeButtonProps): import("react").JSX.Element;
8
+ //# sourceMappingURL=VisibilityEye.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VisibilityEye.d.ts","sourceRoot":"","sources":["../../../src/components/config/VisibilityEye.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC9C,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,EAClC,IAAI,EACJ,KAAK,EACL,IAAI,GACL,EAAE,wBAAwB,+BA0B1B"}
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect } from "react";
3
+ export function VisibilityEyeButton({ name, label, form, }) {
4
+ const visible = form.watch(name) !== false;
5
+ useEffect(() => {
6
+ form.register(name);
7
+ }, [form, name]);
8
+ return (_jsx("button", { type: "button", className: "vertebr-visibility-btn", "aria-pressed": visible, "aria-label": visible ? `Hide ${label} on storefront` : `Show ${label} on storefront`, title: visible ? "Visible on storefront" : "Hidden on storefront", onClick: () => form.setValue(name, !visible, {
9
+ shouldDirty: true,
10
+ shouldTouch: true,
11
+ }), children: visible ? _jsx(EyeIcon, {}) : _jsx(EyeOffIcon, {}) }));
12
+ }
13
+ function EyeIcon() {
14
+ return (_jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("path", { d: "M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0" }), _jsx("circle", { cx: "12", cy: "12", r: "3" })] }));
15
+ }
16
+ function EyeOffIcon() {
17
+ return (_jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("path", { d: "M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49" }), _jsx("path", { d: "M14.084 14.158a3 3 0 0 1-4.242-4.242" }), _jsx("path", { d: "M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143" }), _jsx("path", { d: "m2 2 20 20" })] }));
18
+ }
@@ -0,0 +1,22 @@
1
+ import { type UseFormReturn } from "react-hook-form";
2
+ import type { FieldSchema, ResourceUploadMeta } from "@vertebr/client";
3
+ import type { ConfigFormVariant, GalleryHandlers } from "./types";
4
+ export type ConfigFieldProps = GalleryHandlers & {
5
+ fieldKey: string;
6
+ field: FieldSchema;
7
+ groupLabel: string;
8
+ variant: ConfigFormVariant;
9
+ schema: Record<string, FieldSchema>;
10
+ watched: Record<string, unknown>;
11
+ form: UseFormReturn<Record<string, unknown>>;
12
+ uploads?: Record<string, ResourceUploadMeta>;
13
+ onUpload?: (field: string, files: File[]) => Promise<Array<{
14
+ url: string;
15
+ name?: string;
16
+ }>>;
17
+ hideImagePreview?: boolean;
18
+ hideUpload?: boolean;
19
+ visibilityGroup?: string;
20
+ };
21
+ export declare function ConfigField({ fieldKey, field, groupLabel, variant, schema, watched, form, uploads, onUpload, galleryUpload, onListGallery, onUploadGallery, hideImagePreview, hideUpload, visibilityGroup, }: ConfigFieldProps): import("react").JSX.Element;
22
+ //# sourceMappingURL=ConfigField.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigField.d.ts","sourceRoot":"","sources":["../../../../src/components/config/form/ConfigField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIjE,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAoBvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAElE,MAAM,MAAM,gBAAgB,GAAG,eAAe,GAAG;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,WAAW,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,iBAAiB,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC7C,QAAQ,CAAC,EAAE,CACT,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,IAAI,EAAE,KACV,OAAO,CAAC,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;IACpD,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,KAAK,EACL,UAAU,EACV,OAAO,EACP,MAAM,EACN,OAAO,EACP,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,aAAa,EACb,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,eAAe,GAChB,EAAE,gBAAgB,+BA8OlB"}
@@ -0,0 +1,53 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Controller } from "react-hook-form";
3
+ import * as Label from "@radix-ui/react-label";
4
+ import * as Switch from "@radix-ui/react-switch";
5
+ import { VisibilityEyeButton } from "../VisibilityEye";
6
+ import { isDescriptionField } from "../../../lib/description";
7
+ import { collectRecordImages, isImageField, urlsFromValue, } from "../../../lib/images";
8
+ import { isCentsField, isPriceField } from "../../../lib/price";
9
+ import { ImageUploadControl } from "../../resources/ImageUploadControl";
10
+ import { DescriptionInput } from "../DescriptionInput";
11
+ import { EnumInput } from "../EnumInput";
12
+ import { EnumListInput } from "../EnumListInput";
13
+ import { PriceInput } from "../PriceInput";
14
+ import { displayLabel, firstImageUrl, isMultilineField, fieldVisibilityKey, spanFor, } from "./helpers";
15
+ export function ConfigField({ fieldKey, field, groupLabel, variant, schema, watched, form, uploads, onUpload, galleryUpload, onListGallery, onUploadGallery, hideImagePreview, hideUpload, visibilityGroup, }) {
16
+ const label = displayLabel(fieldKey, field, groupLabel);
17
+ const visibilityKey = fieldVisibilityKey(fieldKey, schema, visibilityGroup ?? groupLabel);
18
+ const visibilityOn = !visibilityKey || watched?.[visibilityKey] !== false;
19
+ const showInlinePreview = !hideImagePreview &&
20
+ field.type !== "file[]" &&
21
+ isImageField(fieldKey, field) &&
22
+ Boolean(firstImageUrl(watched?.[fieldKey]));
23
+ if (field.type === "boolean") {
24
+ return (_jsxs("div", { className: "vertebr-switch-row", children: [_jsx(Label.Root, { htmlFor: fieldKey, children: label }), _jsx(Controller, { control: form.control, name: fieldKey, render: ({ field: controllerField }) => (_jsx(Switch.Root, { className: "vertebr-switch", id: fieldKey, checked: Boolean(controllerField.value), onCheckedChange: controllerField.onChange, children: _jsx(Switch.Thumb, { className: "vertebr-switch-thumb" }) })) })] }));
25
+ }
26
+ return (_jsxs("div", { className: "vertebr-field", "data-span": spanFor(fieldKey, field, variant), "data-kind": isImageField(fieldKey, field) ? "image" : undefined, "data-storefront": visibilityKey ? (visibilityOn ? "on" : "off") : undefined, children: [_jsxs("div", { className: "vertebr-field-head", children: [_jsx(Label.Root, { htmlFor: fieldKey, children: label }), visibilityKey ? (_jsx(VisibilityEyeButton, { name: visibilityKey, label: label, form: form })) : null] }), showInlinePreview ? (_jsxs("div", { className: "vertebr-field-media", children: [_jsx("img", { src: firstImageUrl(watched[fieldKey]) ?? "", alt: "" }), _jsx("input", { id: fieldKey, type: "text", readOnly: field.readOnly, ...form.register(fieldKey) })] })) : field.type === "richtext" || isDescriptionField(fieldKey, field) ? (_jsx(Controller, { control: form.control, name: fieldKey, render: ({ field: controllerField }) => (_jsx(DescriptionInput, { id: fieldKey, name: controllerField.name, inputRef: controllerField.ref, value: typeof controllerField.value === "string"
27
+ ? controllerField.value
28
+ : "", readOnly: field.readOnly, recordImages: collectRecordImages(schema, watched), galleryUpload: galleryUpload, onListGallery: onListGallery, onUploadGallery: onUploadGallery, onBlur: controllerField.onBlur, onChange: controllerField.onChange })) })) : field.type === "file[]" ? (_jsx(Controller, { control: form.control, name: fieldKey, render: ({ field: controllerField }) => {
29
+ const urls = urlsFromValue(controllerField.value);
30
+ return (_jsx("div", { className: "vertebr-field-files", children: urls.length > 0 ? (_jsx("ul", { className: "vertebr-field-files-list", children: urls.map((url) => (_jsxs("li", { children: [_jsx("img", { src: url, alt: "" }), _jsx("button", { type: "button", className: "vertebr-btn vertebr-btn-quiet", onClick: () => controllerField.onChange(urls.filter((item) => item !== url)), children: "Remove" })] }, url))) })) : (_jsx("p", { className: "vertebr-field-files-empty", children: "No photos yet" })) }));
31
+ } })) : field.type === "number" && isPriceField(fieldKey, field) ? (_jsx(Controller, { control: form.control, name: fieldKey, render: ({ field: controllerField }) => (_jsx(PriceInput, { id: fieldKey, name: controllerField.name, inputRef: controllerField.ref, value: controllerField.value, asCents: isCentsField(fieldKey, field) || /^pricing$/i.test(groupLabel), readOnly: field.readOnly, onBlur: controllerField.onBlur, onChange: controllerField.onChange })) })) : field.type === "number" ? (_jsx(Controller, { control: form.control, name: fieldKey, render: ({ field: controllerField }) => (_jsx("input", { id: fieldKey, type: "number", readOnly: field.readOnly, value: typeof controllerField.value === "number" &&
32
+ Number.isFinite(controllerField.value)
33
+ ? controllerField.value
34
+ : "", onBlur: controllerField.onBlur, onChange: (event) => {
35
+ const next = event.target.value;
36
+ controllerField.onChange(next === "" ? undefined : Number(next));
37
+ }, name: controllerField.name, ref: controllerField.ref })) })) : field.type === "enum" ? (_jsx(Controller, { control: form.control, name: fieldKey, render: ({ field: controllerField }) => (_jsx(EnumInput, { id: fieldKey, value: controllerField.value, field: field, readOnly: field.readOnly, onChange: controllerField.onChange })) })) : field.type === "enum[]" ? (_jsx(Controller, { control: form.control, name: fieldKey, render: ({ field: controllerField }) => (_jsx(EnumListInput, { id: fieldKey, value: controllerField.value, field: field, readOnly: field.readOnly, onChange: controllerField.onChange })) })) : isMultilineField(fieldKey, field) ? (_jsx("textarea", { id: fieldKey, rows: 5, readOnly: field.readOnly, ...form.register(fieldKey) })) : (_jsx("input", { id: fieldKey, type: "text", readOnly: field.readOnly, ...form.register(fieldKey) })), !hideUpload && uploads?.[fieldKey] && onUpload && !field.readOnly ? (_jsx(ImageUploadControl, { meta: uploads[fieldKey], multiple: field.type === "file[]", onUpload: async (files) => {
38
+ const uploaded = await onUpload(fieldKey, files);
39
+ const urls = uploaded
40
+ .map((item) => item.url)
41
+ .filter(Boolean);
42
+ if (!urls.length)
43
+ return;
44
+ if (field.type === "file[]") {
45
+ form.setValue(fieldKey, [...urlsFromValue(form.getValues(fieldKey)), ...urls], { shouldDirty: true, shouldTouch: true });
46
+ return;
47
+ }
48
+ form.setValue(fieldKey, urls[0], {
49
+ shouldDirty: true,
50
+ shouldTouch: true,
51
+ });
52
+ } })) : null] }));
53
+ }
@@ -0,0 +1,4 @@
1
+ import type { ConfigFormProps } from "./types";
2
+ export type { ConfigFormProps, ConfigFormVariant } from "./types";
3
+ export declare function ConfigForm({ schema, value, onSave, submitLabel, variant, uploads, onUpload, galleryUpload, onListGallery, onUploadGallery, }: ConfigFormProps): import("react").JSX.Element;
4
+ //# sourceMappingURL=ConfigForm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigForm.d.ts","sourceRoot":"","sources":["../../../../src/components/config/form/ConfigForm.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAElE,wBAAgB,UAAU,CAAC,EACzB,MAAM,EACN,KAAK,EACL,MAAM,EACN,WAAW,EACX,OAAkB,EAClB,OAAO,EACP,QAAQ,EACR,aAAa,EACb,aAAa,EACb,eAAe,GAChB,EAAE,eAAe,+BAyFjB"}
@@ -0,0 +1,75 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useMemo, useState } from "react";
3
+ import { useForm, useWatch } from "react-hook-form";
4
+ import { zodResolver } from "@hookform/resolvers/zod";
5
+ import { buildZodSchema, groupFields, withSpecVisibility, withSpecVisibilityValues, } from "./helpers";
6
+ import { RecordConfigForm } from "./RecordConfigForm";
7
+ import { SettingsConfigForm } from "./SettingsConfigForm";
8
+ export function ConfigForm({ schema, value, onSave, submitLabel, variant = "config", uploads, onUpload, galleryUpload, onListGallery, onUploadGallery, }) {
9
+ const editorSchema = useMemo(() => (variant === "record" ? withSpecVisibility(schema) : schema), [schema, variant]);
10
+ const editorValue = useMemo(() => variant === "record"
11
+ ? withSpecVisibilityValues(editorSchema, value)
12
+ : value, [editorSchema, value, variant]);
13
+ const zodSchema = useMemo(() => buildZodSchema(editorSchema), [editorSchema]);
14
+ const groups = useMemo(() => groupFields(editorSchema, variant), [editorSchema, variant]);
15
+ const [status, setStatus] = useState(null);
16
+ const [tone, setTone] = useState();
17
+ const form = useForm({
18
+ resolver: zodResolver(zodSchema),
19
+ defaultValues: editorValue,
20
+ });
21
+ const watched = useWatch({ control: form.control });
22
+ useEffect(() => {
23
+ form.reset(editorValue);
24
+ }, [editorValue, form]);
25
+ const onSubmit = form.handleSubmit(async (data) => {
26
+ setStatus("Saving…");
27
+ setTone(undefined);
28
+ try {
29
+ await onSave(data);
30
+ setStatus("Saved");
31
+ setTone("ok");
32
+ }
33
+ catch (error) {
34
+ setStatus(error instanceof Error ? error.message : "Save failed");
35
+ setTone("danger");
36
+ }
37
+ });
38
+ const isDirty = form.formState.isDirty;
39
+ useEffect(() => {
40
+ const onKeyDown = (event) => {
41
+ if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "s") {
42
+ event.preventDefault();
43
+ void onSubmit();
44
+ }
45
+ };
46
+ window.addEventListener("keydown", onKeyDown);
47
+ return () => window.removeEventListener("keydown", onKeyDown);
48
+ }, [onSubmit]);
49
+ const onDiscard = () => {
50
+ form.reset(editorValue);
51
+ setStatus(null);
52
+ setTone(undefined);
53
+ };
54
+ const shared = {
55
+ schema: editorSchema,
56
+ groups,
57
+ watched,
58
+ form,
59
+ uploads,
60
+ onUpload,
61
+ galleryUpload,
62
+ onListGallery,
63
+ onUploadGallery,
64
+ onSubmit,
65
+ isDirty,
66
+ status,
67
+ tone,
68
+ onDiscard,
69
+ submitLabel,
70
+ };
71
+ if (variant === "record") {
72
+ return _jsx(RecordConfigForm, { ...shared });
73
+ }
74
+ return _jsx(SettingsConfigForm, { ...shared });
75
+ }
@@ -0,0 +1,11 @@
1
+ import type { UseFormReturn } from "react-hook-form";
2
+ export type ConfigFormActionsProps = {
3
+ form: UseFormReturn<Record<string, unknown>>;
4
+ isDirty: boolean;
5
+ status: string | null;
6
+ tone?: "ok" | "danger";
7
+ onDiscard: () => void;
8
+ submitLabel?: string;
9
+ };
10
+ export declare function ConfigFormActions({ form, isDirty, status, tone, onDiscard, submitLabel, }: ConfigFormActionsProps): import("react").JSX.Element;
11
+ //# sourceMappingURL=ConfigFormActions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigFormActions.d.ts","sourceRoot":"","sources":["../../../../src/components/config/form/ConfigFormActions.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC7C,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,CAAC,EAAE,IAAI,GAAG,QAAQ,CAAC;IACvB,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,EAChC,IAAI,EACJ,OAAO,EACP,MAAM,EACN,IAAI,EACJ,SAAS,EACT,WAA4B,GAC7B,EAAE,sBAAsB,+BA0BxB"}
@@ -0,0 +1,4 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ export function ConfigFormActions({ form, isDirty, status, tone, onDiscard, submitLabel = "Save changes", }) {
3
+ return (_jsxs("div", { className: "vertebr-actions", children: [_jsx("button", { className: "vertebr-btn vertebr-btn-primary", type: "submit", disabled: form.formState.isSubmitting || !isDirty, children: form.formState.isSubmitting ? "Saving…" : submitLabel }), isDirty ? (_jsx("button", { className: "vertebr-btn", type: "button", onClick: onDiscard, children: "Discard" })) : null, isDirty ? (_jsx("span", { className: "vertebr-dirty", children: "Unsaved" })) : status ? (_jsx("span", { className: "vertebr-status", "data-tone": tone, children: status })) : null, _jsx("span", { className: "vertebr-actions-spacer" }), _jsx("span", { className: "vertebr-kbd", children: "\u2318S" })] }));
4
+ }
@@ -0,0 +1,22 @@
1
+ import type { UseFormReturn } from "react-hook-form";
2
+ import type { FieldSchema, ResourceUploadMeta } from "@vertebr/client";
3
+ import type { FieldGroup, GalleryHandlers } from "./types";
4
+ export type RecordConfigFormProps = GalleryHandlers & {
5
+ schema: Record<string, FieldSchema>;
6
+ groups: FieldGroup[];
7
+ watched: Record<string, unknown>;
8
+ form: UseFormReturn<Record<string, unknown>>;
9
+ uploads?: Record<string, ResourceUploadMeta>;
10
+ onUpload?: (field: string, files: File[]) => Promise<Array<{
11
+ url: string;
12
+ name?: string;
13
+ }>>;
14
+ onSubmit: (event: React.FormEvent<HTMLFormElement>) => void;
15
+ isDirty: boolean;
16
+ status: string | null;
17
+ tone?: "ok" | "danger";
18
+ onDiscard: () => void;
19
+ submitLabel?: string;
20
+ };
21
+ export declare function RecordConfigForm({ schema, groups, watched, form, uploads, onUpload, galleryUpload, onListGallery, onUploadGallery, onSubmit, isDirty, status, tone, onDiscard, submitLabel, }: RecordConfigFormProps): import("react").JSX.Element;
22
+ //# sourceMappingURL=RecordConfigForm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RecordConfigForm.d.ts","sourceRoot":"","sources":["../../../../src/components/config/form/RecordConfigForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAYvE,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE3D,MAAM,MAAM,qBAAqB,GAAG,eAAe,GAAG;IACpD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACpC,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC7C,QAAQ,CAAC,EAAE,CACT,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,IAAI,EAAE,KACV,OAAO,CAAC,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;IACpD,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,eAAe,CAAC,KAAK,IAAI,CAAC;IAC5D,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,CAAC,EAAE,IAAI,GAAG,QAAQ,CAAC;IACvB,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,EAC/B,MAAM,EACN,MAAM,EACN,OAAO,EACP,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,aAAa,EACb,aAAa,EACb,eAAe,EACf,QAAQ,EACR,OAAO,EACP,MAAM,EACN,IAAI,EACJ,SAAS,EACT,WAAW,GACZ,EAAE,qBAAqB,+BAoJvB"}
@@ -0,0 +1,45 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { looksLikeUrl } from "../../../lib/images";
3
+ import { ImageUploadControl } from "../../resources/ImageUploadControl";
4
+ import { ConfigField } from "./ConfigField";
5
+ import { ConfigFormActions } from "./ConfigFormActions";
6
+ import { VisibilityEyeButton } from "../VisibilityEye";
7
+ import { findPrimaryImageKey, firstImageUrl, groupVisibilityKey, isStockField, } from "./helpers";
8
+ export function RecordConfigForm({ schema, groups, watched, form, uploads, onUpload, galleryUpload, onListGallery, onUploadGallery, onSubmit, isDirty, status, tone, onDiscard, submitLabel, }) {
9
+ const imageKey = findPrimaryImageKey(schema, watched);
10
+ const imageValue = imageKey ? firstImageUrl(watched?.[imageKey]) ?? "" : "";
11
+ const asideGroups = groups.filter((group) => /^(Media|Display|Status)$/i.test(group.id));
12
+ const mainGroups = groups.filter((group) => !/^(Media|Display|Status)$/i.test(group.id));
13
+ const fieldProps = {
14
+ variant: "record",
15
+ schema,
16
+ watched,
17
+ form,
18
+ uploads,
19
+ onUpload,
20
+ galleryUpload,
21
+ onListGallery,
22
+ onUploadGallery,
23
+ };
24
+ return (_jsxs("form", { className: "vertebr-form", "data-variant": "record", onSubmit: onSubmit, children: [_jsx("div", { className: "vertebr-form-scroll", children: _jsxs("div", { className: "vertebr-record-layout", children: [_jsxs("aside", { className: "vertebr-record-aside", children: [_jsx("div", { className: "vertebr-record-preview", children: imageValue && looksLikeUrl(imageValue) ? (_jsx("img", { src: imageValue, alt: "" })) : (_jsx("div", { className: "vertebr-record-preview-empty", children: "No image" })) }), imageKey && uploads?.[imageKey] && onUpload ? (_jsx(ImageUploadControl, { meta: uploads[imageKey], label: "Drop a new image or browse", onUpload: async (files) => {
25
+ const [first] = await onUpload(imageKey, files);
26
+ if (first?.url) {
27
+ form.setValue(imageKey, first.url, {
28
+ shouldDirty: true,
29
+ shouldTouch: true,
30
+ });
31
+ }
32
+ } })) : null, asideGroups.map((group) => (_jsxs("div", { className: "vertebr-record-block", "data-layout": /^inventory$/i.test(group.id) ? "chips" : undefined, children: [_jsx(RecordBlockLabel, { groupId: group.id, label: group.label, schema: schema, form: form }), _jsx("div", { className: "vertebr-form-fields", "data-layout": isStockField(group.fields[0]?.[0] ?? "", group.fields[0]?.[1])
33
+ ? "chips"
34
+ : undefined, children: group.fields.map(([key, field]) => (_jsx(ConfigField, { fieldKey: key, field: field, groupLabel: group.label, visibilityGroup: group.id, hideImagePreview: true, hideUpload: key === imageKey, ...fieldProps }, key))) })] }, group.id)))] }), _jsx("div", { className: "vertebr-record-main", children: mainGroups.map((group) => {
35
+ const inventory = /^inventory$/i.test(group.id);
36
+ const specs = /^specs$/i.test(group.id);
37
+ const sectionKey = groupVisibilityKey(group.id, schema);
38
+ const sectionOn = !sectionKey || watched?.[sectionKey] !== false;
39
+ return (_jsxs("div", { className: "vertebr-record-block", "data-layout": inventory ? "chips" : specs ? "specs" : undefined, "data-storefront": sectionKey ? (sectionOn ? "on" : "off") : undefined, children: [_jsx(RecordBlockLabel, { groupId: group.id, label: group.label, schema: schema, form: form }), _jsx("div", { className: "vertebr-form-fields", "data-layout": inventory ? "chips" : specs ? "specs" : undefined, children: group.fields.map(([key, field]) => (_jsx(ConfigField, { fieldKey: key, field: field, groupLabel: group.label, visibilityGroup: group.id, ...fieldProps }, key))) })] }, group.id));
40
+ }) })] }) }), _jsx(ConfigFormActions, { form: form, isDirty: isDirty, status: status, tone: tone, onDiscard: onDiscard, submitLabel: submitLabel })] }));
41
+ }
42
+ function RecordBlockLabel({ groupId, label, schema, form, }) {
43
+ const visibilityKey = groupVisibilityKey(groupId, schema);
44
+ return (_jsxs("div", { className: "vertebr-record-block-label", children: [_jsx("span", { children: label }), visibilityKey ? (_jsx(VisibilityEyeButton, { name: visibilityKey, label: label, form: form })) : null] }));
45
+ }
@@ -0,0 +1,22 @@
1
+ import type { UseFormReturn } from "react-hook-form";
2
+ import type { FieldSchema, ResourceUploadMeta } from "@vertebr/client";
3
+ import type { FieldGroup, GalleryHandlers } from "./types";
4
+ export type SettingsConfigFormProps = GalleryHandlers & {
5
+ schema: Record<string, FieldSchema>;
6
+ groups: FieldGroup[];
7
+ watched: Record<string, unknown>;
8
+ form: UseFormReturn<Record<string, unknown>>;
9
+ uploads?: Record<string, ResourceUploadMeta>;
10
+ onUpload?: (field: string, files: File[]) => Promise<Array<{
11
+ url: string;
12
+ name?: string;
13
+ }>>;
14
+ onSubmit: (event: React.FormEvent<HTMLFormElement>) => void;
15
+ isDirty: boolean;
16
+ status: string | null;
17
+ tone?: "ok" | "danger";
18
+ onDiscard: () => void;
19
+ submitLabel?: string;
20
+ };
21
+ export declare function SettingsConfigForm({ schema, groups, watched, form, uploads, onUpload, galleryUpload, onListGallery, onUploadGallery, onSubmit, isDirty, status, tone, onDiscard, submitLabel, }: SettingsConfigFormProps): import("react").JSX.Element;
22
+ //# sourceMappingURL=SettingsConfigForm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SettingsConfigForm.d.ts","sourceRoot":"","sources":["../../../../src/components/config/form/SettingsConfigForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAGvE,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE3D,MAAM,MAAM,uBAAuB,GAAG,eAAe,GAAG;IACtD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACpC,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC7C,QAAQ,CAAC,EAAE,CACT,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,IAAI,EAAE,KACV,OAAO,CAAC,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;IACpD,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,eAAe,CAAC,KAAK,IAAI,CAAC;IAC5D,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,CAAC,EAAE,IAAI,GAAG,QAAQ,CAAC;IACvB,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,EACjC,MAAM,EACN,MAAM,EACN,OAAO,EACP,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,aAAa,EACb,aAAa,EACb,eAAe,EACf,QAAQ,EACR,OAAO,EACP,MAAM,EACN,IAAI,EACJ,SAAS,EACT,WAAW,GACZ,EAAE,uBAAuB,+BAoDzB"}
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ConfigField } from "./ConfigField";
3
+ import { ConfigFormActions } from "./ConfigFormActions";
4
+ export function SettingsConfigForm({ schema, groups, watched, form, uploads, onUpload, galleryUpload, onListGallery, onUploadGallery, onSubmit, isDirty, status, tone, onDiscard, submitLabel, }) {
5
+ const singleGroup = groups.length === 1;
6
+ return (_jsxs("form", { className: "vertebr-form", "data-variant": "config", onSubmit: onSubmit, children: [_jsx("div", { className: "vertebr-form-scroll", children: groups.map((group) => (_jsxs("div", { className: "vertebr-form-section", "data-plain": singleGroup ? "true" : undefined, children: [!singleGroup ? (_jsxs("div", { className: "vertebr-form-section-head", children: [_jsx("h3", { children: group.label }), _jsx("span", { className: "vertebr-form-section-count", children: group.fields.length })] })) : null, _jsx("div", { className: "vertebr-form-fields", children: group.fields.map(([key, field]) => (_jsx(ConfigField, { fieldKey: key, field: field, groupLabel: group.label, variant: "config", schema: schema, watched: watched, form: form, uploads: uploads, onUpload: onUpload, galleryUpload: galleryUpload, onListGallery: onListGallery, onUploadGallery: onUploadGallery }, key))) })] }, group.id))) }), _jsx(ConfigFormActions, { form: form, isDirty: isDirty, status: status, tone: tone, onDiscard: onDiscard, submitLabel: submitLabel })] }));
7
+ }
@@ -0,0 +1,7 @@
1
+ import type { FieldSchema } from "@vertebr/client";
2
+ import type { ConfigFormVariant } from "../types";
3
+ export declare function isStockField(key: string, field?: FieldSchema): boolean;
4
+ export declare function isSpecsField(key: string, field?: FieldSchema): boolean;
5
+ export declare function isMultilineField(key: string, field?: FieldSchema): boolean;
6
+ export declare function spanFor(key: string, field: FieldSchema, variant: ConfigFormVariant): "wide" | "full" | undefined;
7
+ //# sourceMappingURL=fields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../../../../src/components/config/form/helpers/fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,OAAO,CAGtE;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,OAAO,CAKtE;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,OAAO,CAG1E;AAED,wBAAgB,OAAO,CACrB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,iBAAiB,GACzB,MAAM,GAAG,MAAM,GAAG,SAAS,CAO7B"}