@djangocfg/ui-tools 2.1.109 → 2.1.111

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 (159) hide show
  1. package/README.md +242 -49
  2. package/dist/JsonSchemaForm-65NLLK56.mjs +4 -0
  3. package/dist/JsonSchemaForm-65NLLK56.mjs.map +1 -0
  4. package/dist/JsonSchemaForm-PY6DH3HE.cjs +13 -0
  5. package/dist/JsonSchemaForm-PY6DH3HE.cjs.map +1 -0
  6. package/dist/JsonTree-6RYAOPSS.mjs +4 -0
  7. package/dist/JsonTree-6RYAOPSS.mjs.map +1 -0
  8. package/dist/JsonTree-7OH6CIHT.cjs +10 -0
  9. package/dist/JsonTree-7OH6CIHT.cjs.map +1 -0
  10. package/dist/MapContainer-GXQLP5WY.mjs +214 -0
  11. package/dist/MapContainer-GXQLP5WY.mjs.map +1 -0
  12. package/dist/MapContainer-RYG4HPH4.cjs +221 -0
  13. package/dist/MapContainer-RYG4HPH4.cjs.map +1 -0
  14. package/dist/{Mermaid.client-4OCKJ6QD.mjs → Mermaid.client-OKACITCW.mjs} +16 -7
  15. package/dist/Mermaid.client-OKACITCW.mjs.map +1 -0
  16. package/dist/{Mermaid.client-ZP6OE46Z.cjs → Mermaid.client-PNXEC6YL.cjs} +16 -7
  17. package/dist/Mermaid.client-PNXEC6YL.cjs.map +1 -0
  18. package/dist/{PlaygroundLayout-XXVBU4WZ.cjs → PlaygroundLayout-SYMEAG3J.cjs} +25 -24
  19. package/dist/PlaygroundLayout-SYMEAG3J.cjs.map +1 -0
  20. package/dist/{PlaygroundLayout-LMQTVXSP.mjs → PlaygroundLayout-UQRBU5RH.mjs} +4 -3
  21. package/dist/PlaygroundLayout-UQRBU5RH.mjs.map +1 -0
  22. package/dist/{PrettyCode.client-2CLSV2VD.cjs → PrettyCode.client-DANYYQYO.cjs} +11 -4
  23. package/dist/PrettyCode.client-DANYYQYO.cjs.map +1 -0
  24. package/dist/{PrettyCode.client-Y2BVON7R.mjs → PrettyCode.client-RS5ZTNBT.mjs} +11 -4
  25. package/dist/PrettyCode.client-RS5ZTNBT.mjs.map +1 -0
  26. package/dist/chunk-2DSR7V2L.mjs +561 -0
  27. package/dist/chunk-2DSR7V2L.mjs.map +1 -0
  28. package/dist/chunk-47T5ECYV.cjs +1357 -0
  29. package/dist/chunk-47T5ECYV.cjs.map +1 -0
  30. package/dist/chunk-5QT3QYFZ.cjs +189 -0
  31. package/dist/chunk-5QT3QYFZ.cjs.map +1 -0
  32. package/dist/chunk-7IIRYG4S.mjs +1057 -0
  33. package/dist/chunk-7IIRYG4S.mjs.map +1 -0
  34. package/dist/{chunk-FB5QBSI3.cjs → chunk-DI3HUXHK.cjs} +15 -195
  35. package/dist/chunk-DI3HUXHK.cjs.map +1 -0
  36. package/dist/chunk-EVGWYASL.cjs +1528 -0
  37. package/dist/chunk-EVGWYASL.cjs.map +1 -0
  38. package/dist/chunk-F2N7P5XU.cjs +30 -0
  39. package/dist/chunk-F2N7P5XU.cjs.map +1 -0
  40. package/dist/{chunk-L6UHASYQ.mjs → chunk-G6PRZP5I.mjs} +7 -186
  41. package/dist/chunk-G6PRZP5I.mjs.map +1 -0
  42. package/dist/chunk-JWB2EWQO.mjs +5 -0
  43. package/dist/chunk-JWB2EWQO.mjs.map +1 -0
  44. package/dist/chunk-LTJX2JXE.mjs +338 -0
  45. package/dist/chunk-LTJX2JXE.mjs.map +1 -0
  46. package/dist/chunk-OVNC4KW6.mjs +1494 -0
  47. package/dist/chunk-OVNC4KW6.mjs.map +1 -0
  48. package/dist/chunk-PNZSJN6T.cjs +1086 -0
  49. package/dist/chunk-PNZSJN6T.cjs.map +1 -0
  50. package/dist/chunk-TEFRA7GW.cjs +565 -0
  51. package/dist/chunk-TEFRA7GW.cjs.map +1 -0
  52. package/dist/chunk-UOMPPIED.mjs +1343 -0
  53. package/dist/chunk-UOMPPIED.mjs.map +1 -0
  54. package/dist/chunk-W6YHQI4F.mjs +187 -0
  55. package/dist/chunk-W6YHQI4F.mjs.map +1 -0
  56. package/dist/chunk-XTBRWVIV.cjs +346 -0
  57. package/dist/chunk-XTBRWVIV.cjs.map +1 -0
  58. package/dist/components-C7ZL7OMY.mjs +5 -0
  59. package/dist/components-C7ZL7OMY.mjs.map +1 -0
  60. package/dist/components-CJ2IB65O.cjs +27 -0
  61. package/dist/components-CJ2IB65O.cjs.map +1 -0
  62. package/dist/components-EASJYK45.mjs +6 -0
  63. package/dist/components-EASJYK45.mjs.map +1 -0
  64. package/dist/components-LDRFDV4A.cjs +22 -0
  65. package/dist/components-LDRFDV4A.cjs.map +1 -0
  66. package/dist/components-VZKUTDJK.mjs +5 -0
  67. package/dist/components-VZKUTDJK.mjs.map +1 -0
  68. package/dist/components-Y64GTIMQ.cjs +42 -0
  69. package/dist/components-Y64GTIMQ.cjs.map +1 -0
  70. package/dist/index.cjs +701 -4813
  71. package/dist/index.cjs.map +1 -1
  72. package/dist/index.d.cts +1274 -1026
  73. package/dist/index.d.ts +1274 -1026
  74. package/dist/index.mjs +358 -4730
  75. package/dist/index.mjs.map +1 -1
  76. package/package.json +27 -4
  77. package/src/components/index.ts +17 -0
  78. package/src/components/lazy-wrapper.tsx +281 -0
  79. package/src/index.ts +92 -7
  80. package/src/tools/AudioPlayer/components/HybridAudioPlayer.tsx +14 -5
  81. package/src/tools/AudioPlayer/lazy.tsx +85 -0
  82. package/src/tools/Gallery/components/Gallery.tsx +182 -0
  83. package/src/tools/Gallery/components/GalleryCarousel.tsx +251 -0
  84. package/src/tools/Gallery/components/GalleryCompact.tsx +173 -0
  85. package/src/tools/Gallery/components/GalleryGrid.tsx +493 -0
  86. package/src/tools/Gallery/components/GalleryImage.tsx +66 -0
  87. package/src/tools/Gallery/components/GalleryLightbox.tsx +331 -0
  88. package/src/tools/Gallery/components/GalleryMedia.tsx +66 -0
  89. package/src/tools/Gallery/components/GalleryThumbnails.tsx +173 -0
  90. package/src/tools/Gallery/components/GalleryThumbnailsVirtual.tsx +138 -0
  91. package/src/tools/Gallery/components/GalleryVideo.tsx +222 -0
  92. package/src/tools/Gallery/components/index.ts +13 -0
  93. package/src/tools/Gallery/hooks/index.ts +23 -0
  94. package/src/tools/Gallery/hooks/useGallery.ts +137 -0
  95. package/src/tools/Gallery/hooks/useImageDimensions.ts +223 -0
  96. package/src/tools/Gallery/hooks/usePinchZoom.ts +234 -0
  97. package/src/tools/Gallery/hooks/usePreloadImages.ts +71 -0
  98. package/src/tools/Gallery/hooks/useSwipe.ts +86 -0
  99. package/src/tools/Gallery/hooks/useVirtualList.ts +129 -0
  100. package/src/tools/Gallery/hooks/useZoom.ts +316 -0
  101. package/src/tools/Gallery/index.ts +66 -0
  102. package/src/tools/Gallery/types.ts +183 -0
  103. package/src/tools/Gallery/utils/imageAnalysis.ts +52 -0
  104. package/src/tools/Gallery/utils/index.ts +11 -0
  105. package/src/tools/ImageViewer/components/ImageToolbar.tsx +20 -8
  106. package/src/tools/ImageViewer/components/ImageViewer.tsx +12 -4
  107. package/src/tools/ImageViewer/lazy.tsx +37 -0
  108. package/src/tools/JsonForm/lazy.tsx +43 -0
  109. package/src/tools/JsonForm/widgets/ColorWidget.tsx +4 -1
  110. package/src/tools/JsonTree/lazy.tsx +45 -0
  111. package/src/tools/LottiePlayer/lazy.tsx +57 -0
  112. package/src/tools/Map/components/CustomOverlay.tsx +54 -0
  113. package/src/tools/Map/components/DrawControl.tsx +36 -0
  114. package/src/tools/Map/components/GeocoderControl.tsx +70 -0
  115. package/src/tools/Map/components/LayerSwitcher.tsx +225 -0
  116. package/src/tools/Map/components/MapCluster.tsx +273 -0
  117. package/src/tools/Map/components/MapContainer.tsx +191 -0
  118. package/src/tools/Map/components/MapControls.tsx +44 -0
  119. package/src/tools/Map/components/MapLegend.tsx +161 -0
  120. package/src/tools/Map/components/MapMarker.tsx +102 -0
  121. package/src/tools/Map/components/MapPopup.tsx +46 -0
  122. package/src/tools/Map/components/MapSource.tsx +30 -0
  123. package/src/tools/Map/components/index.ts +20 -0
  124. package/src/tools/Map/context/MapContext.tsx +89 -0
  125. package/src/tools/Map/context/index.ts +2 -0
  126. package/src/tools/Map/hooks/index.ts +9 -0
  127. package/src/tools/Map/hooks/useMap.ts +11 -0
  128. package/src/tools/Map/hooks/useMapControl.ts +99 -0
  129. package/src/tools/Map/hooks/useMapEvents.ts +147 -0
  130. package/src/tools/Map/hooks/useMapLayers.ts +83 -0
  131. package/src/tools/Map/hooks/useMapViewport.ts +62 -0
  132. package/src/tools/Map/hooks/useMarkers.ts +85 -0
  133. package/src/tools/Map/index.ts +116 -0
  134. package/src/tools/Map/layers/cluster.ts +94 -0
  135. package/src/tools/Map/layers/index.ts +15 -0
  136. package/src/tools/Map/layers/line.ts +93 -0
  137. package/src/tools/Map/layers/point.ts +61 -0
  138. package/src/tools/Map/layers/polygon.ts +73 -0
  139. package/src/tools/Map/lazy.tsx +56 -0
  140. package/src/tools/Map/styles/index.ts +15 -0
  141. package/src/tools/Map/types.ts +259 -0
  142. package/src/tools/Map/utils/geo.ts +88 -0
  143. package/src/tools/Map/utils/index.ts +16 -0
  144. package/src/tools/Map/utils/transform.ts +107 -0
  145. package/src/tools/Mermaid/Mermaid.client.tsx +12 -4
  146. package/src/tools/Mermaid/components/MermaidFullscreenModal.tsx +6 -2
  147. package/src/tools/Mermaid/lazy.tsx +46 -0
  148. package/src/tools/OpenapiViewer/lazy.tsx +72 -0
  149. package/src/tools/PrettyCode/PrettyCode.client.tsx +10 -3
  150. package/src/tools/PrettyCode/lazy.tsx +64 -0
  151. package/src/tools/VideoPlayer/lazy.tsx +63 -0
  152. package/dist/Mermaid.client-4OCKJ6QD.mjs.map +0 -1
  153. package/dist/Mermaid.client-ZP6OE46Z.cjs.map +0 -1
  154. package/dist/PlaygroundLayout-LMQTVXSP.mjs.map +0 -1
  155. package/dist/PlaygroundLayout-XXVBU4WZ.cjs.map +0 -1
  156. package/dist/PrettyCode.client-2CLSV2VD.cjs.map +0 -1
  157. package/dist/PrettyCode.client-Y2BVON7R.mjs.map +0 -1
  158. package/dist/chunk-FB5QBSI3.cjs.map +0 -1
  159. package/dist/chunk-L6UHASYQ.mjs.map +0 -1
@@ -0,0 +1,1057 @@
1
+ import { __name } from './chunk-CGILA3WO.mjs';
2
+ import consola from 'consola';
3
+ import { ChevronDown, Plus, AlertCircle } from 'lucide-react';
4
+ import { useState, useMemo, useCallback, useRef } from 'react';
5
+ import { Label, Collapsible, CollapsibleTrigger, CollapsibleContent, Button, Alert, AlertTitle, AlertDescription, Input, Checkbox, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, Switch, Slider } from '@djangocfg/ui-core/components';
6
+ import Form from '@rjsf/core';
7
+ import validator from '@rjsf/validator-ajv8';
8
+ import { cn } from '@djangocfg/ui-core/lib';
9
+ import { jsx, jsxs } from 'react/jsx-runtime';
10
+ import { getUiOptions, getTemplate, getInputProps } from '@rjsf/utils';
11
+ import { useTypedT } from '@djangocfg/i18n';
12
+
13
+ function FieldTemplate(props) {
14
+ const {
15
+ id,
16
+ classNames,
17
+ style,
18
+ label,
19
+ help,
20
+ required,
21
+ description,
22
+ errors,
23
+ children,
24
+ displayLabel,
25
+ hidden,
26
+ rawErrors
27
+ } = props;
28
+ if (hidden) {
29
+ return /* @__PURE__ */ jsx("div", { className: "hidden", children });
30
+ }
31
+ const hasError = rawErrors && rawErrors.length > 0;
32
+ return /* @__PURE__ */ jsxs(
33
+ "div",
34
+ {
35
+ className: cn("space-y-2", classNames),
36
+ style,
37
+ children: [
38
+ displayLabel && label && /* @__PURE__ */ jsxs(Label, { htmlFor: id, className: cn(hasError && "text-destructive"), children: [
39
+ label,
40
+ required && /* @__PURE__ */ jsx("span", { className: "text-destructive ml-1", children: "*" })
41
+ ] }),
42
+ description && /* @__PURE__ */ jsx("div", { className: "text-sm text-muted-foreground", children: description }),
43
+ /* @__PURE__ */ jsx("div", { children }),
44
+ errors && /* @__PURE__ */ jsx("div", { className: "text-sm text-destructive", children: errors }),
45
+ help && /* @__PURE__ */ jsx("div", { className: "text-sm text-muted-foreground", children: help })
46
+ ]
47
+ }
48
+ );
49
+ }
50
+ __name(FieldTemplate, "FieldTemplate");
51
+ function ObjectFieldTemplate(props) {
52
+ const {
53
+ title,
54
+ description,
55
+ properties,
56
+ required,
57
+ uiSchema
58
+ } = props;
59
+ const isCollapsible = uiSchema?.["ui:collapsible"] === true;
60
+ const defaultCollapsed = uiSchema?.["ui:collapsed"] === true;
61
+ const gridCols = uiSchema?.["ui:grid"];
62
+ const className = uiSchema?.["ui:className"];
63
+ const [isOpen, setIsOpen] = useState(!defaultCollapsed);
64
+ const isRoot = !title;
65
+ const gridClass = gridCols ? `grid gap-4 grid-cols-${gridCols}` : "space-y-4";
66
+ const content = /* @__PURE__ */ jsx("div", { className: cn(gridClass, className), children: properties.map((element) => /* @__PURE__ */ jsx("div", { className: "property-wrapper", children: element.content }, element.name)) });
67
+ if (isRoot) {
68
+ return /* @__PURE__ */ jsx("div", { className: "space-y-6", children: content });
69
+ }
70
+ if (isCollapsible) {
71
+ return /* @__PURE__ */ jsxs(Collapsible, { open: isOpen, onOpenChange: setIsOpen, className: "space-y-2", children: [
72
+ /* @__PURE__ */ jsxs(CollapsibleTrigger, { className: "flex w-full items-center justify-between rounded-lg border bg-muted/50 px-4 py-3 text-left hover:bg-muted transition-colors", children: [
73
+ /* @__PURE__ */ jsxs("div", { children: [
74
+ /* @__PURE__ */ jsxs("h3", { className: "text-sm font-semibold", children: [
75
+ title,
76
+ required && /* @__PURE__ */ jsx("span", { className: "text-destructive ml-1", children: "*" })
77
+ ] }),
78
+ description && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-0.5", children: description })
79
+ ] }),
80
+ /* @__PURE__ */ jsx(
81
+ ChevronDown,
82
+ {
83
+ className: cn(
84
+ "h-4 w-4 text-muted-foreground transition-transform duration-200",
85
+ isOpen && "rotate-180"
86
+ )
87
+ }
88
+ )
89
+ ] }),
90
+ /* @__PURE__ */ jsx(CollapsibleContent, { className: "pl-1 pr-1 pt-2", children: content })
91
+ ] });
92
+ }
93
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
94
+ title && /* @__PURE__ */ jsxs("div", { className: "border-b pb-2", children: [
95
+ /* @__PURE__ */ jsxs("h3", { className: "text-sm font-semibold", children: [
96
+ title,
97
+ required && /* @__PURE__ */ jsx("span", { className: "text-destructive ml-1", children: "*" })
98
+ ] }),
99
+ description && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-1", children: description })
100
+ ] }),
101
+ content
102
+ ] });
103
+ }
104
+ __name(ObjectFieldTemplate, "ObjectFieldTemplate");
105
+ function ArrayFieldTemplate(props) {
106
+ const {
107
+ title,
108
+ items,
109
+ canAdd,
110
+ onAddClick,
111
+ required
112
+ } = props;
113
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
114
+ title && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
115
+ /* @__PURE__ */ jsxs("h3", { className: "text-lg font-semibold", children: [
116
+ title,
117
+ required && /* @__PURE__ */ jsx("span", { className: "text-destructive ml-1", children: "*" })
118
+ ] }),
119
+ canAdd && /* @__PURE__ */ jsxs(
120
+ Button,
121
+ {
122
+ type: "button",
123
+ variant: "outline",
124
+ size: "sm",
125
+ onClick: onAddClick,
126
+ className: "gap-2",
127
+ children: [
128
+ /* @__PURE__ */ jsx(Plus, { className: "h-4 w-4" }),
129
+ "Add Item"
130
+ ]
131
+ }
132
+ )
133
+ ] }),
134
+ /* @__PURE__ */ jsx("div", { className: "space-y-3", children: items }),
135
+ items.length === 0 && /* @__PURE__ */ jsxs("div", { className: "text-center py-8 text-muted-foreground border-2 border-dashed rounded-md", children: [
136
+ "No items added yet.",
137
+ canAdd && /* @__PURE__ */ jsxs(
138
+ Button,
139
+ {
140
+ type: "button",
141
+ variant: "ghost",
142
+ size: "sm",
143
+ onClick: onAddClick,
144
+ className: "mt-2 gap-2",
145
+ children: [
146
+ /* @__PURE__ */ jsx(Plus, { className: "h-4 w-4" }),
147
+ "Add First Item"
148
+ ]
149
+ }
150
+ )
151
+ ] })
152
+ ] });
153
+ }
154
+ __name(ArrayFieldTemplate, "ArrayFieldTemplate");
155
+ function ArrayFieldItemTemplate(props) {
156
+ const {
157
+ children,
158
+ className,
159
+ buttonsProps,
160
+ hasToolbar,
161
+ registry,
162
+ uiSchema
163
+ } = props;
164
+ const uiOptions = getUiOptions(uiSchema);
165
+ const ArrayFieldItemButtonsTemplate = getTemplate(
166
+ "ArrayFieldItemButtonsTemplate",
167
+ registry,
168
+ uiOptions
169
+ );
170
+ return /* @__PURE__ */ jsxs(
171
+ "div",
172
+ {
173
+ className: cn(
174
+ "flex gap-2 items-start p-4 rounded-md border bg-card",
175
+ className
176
+ ),
177
+ children: [
178
+ /* @__PURE__ */ jsx("div", { className: "flex-1", children }),
179
+ hasToolbar && /* @__PURE__ */ jsx("div", { className: "flex items-center gap-1", children: /* @__PURE__ */ jsx(ArrayFieldItemButtonsTemplate, { ...buttonsProps }) })
180
+ ]
181
+ }
182
+ );
183
+ }
184
+ __name(ArrayFieldItemTemplate, "ArrayFieldItemTemplate");
185
+ function ErrorListTemplate(props) {
186
+ const { errors } = props;
187
+ if (!errors || errors.length === 0) {
188
+ return null;
189
+ }
190
+ return /* @__PURE__ */ jsxs(Alert, { variant: "destructive", className: "mb-6", children: [
191
+ /* @__PURE__ */ jsx(AlertCircle, { className: "h-4 w-4" }),
192
+ /* @__PURE__ */ jsx(AlertTitle, { children: "Validation Errors" }),
193
+ /* @__PURE__ */ jsx(AlertDescription, { children: /* @__PURE__ */ jsx("ul", { className: "list-disc list-inside space-y-1 mt-2", children: errors.map((error, index) => /* @__PURE__ */ jsx("li", { className: "text-sm", children: error.stack }, index)) }) })
194
+ ] });
195
+ }
196
+ __name(ErrorListTemplate, "ErrorListTemplate");
197
+ function BaseInputTemplate(props) {
198
+ const {
199
+ id,
200
+ type,
201
+ value,
202
+ readonly,
203
+ disabled,
204
+ autofocus,
205
+ onBlur,
206
+ onFocus,
207
+ onChange,
208
+ options,
209
+ schema,
210
+ rawErrors,
211
+ placeholder
212
+ } = props;
213
+ const inputProps = useMemo(() => {
214
+ return getInputProps(schema, type, options);
215
+ }, [schema, type, options]);
216
+ const safeValue = useMemo(() => {
217
+ if (value === null || value === void 0) return "";
218
+ return String(value);
219
+ }, [value]);
220
+ const hasError = useMemo(() => {
221
+ return rawErrors && rawErrors.length > 0;
222
+ }, [rawErrors]);
223
+ const handleChange = useCallback((event) => {
224
+ const val = event.target.value;
225
+ if (val === "") {
226
+ onChange(options?.emptyValue ?? "");
227
+ return;
228
+ }
229
+ if (inputProps.type === "number" || schema.type === "number" || schema.type === "integer") {
230
+ const num = Number(val);
231
+ onChange(isNaN(num) ? val : num);
232
+ return;
233
+ }
234
+ onChange(val);
235
+ }, [onChange, inputProps.type, schema.type, options?.emptyValue]);
236
+ const handleBlur = useCallback((event) => {
237
+ onBlur(id, event.target.value);
238
+ }, [id, onBlur]);
239
+ const handleFocus = useCallback((event) => {
240
+ onFocus(id, event.target.value);
241
+ }, [id, onFocus]);
242
+ const inputType = useMemo(() => {
243
+ if (inputProps.type) return inputProps.type;
244
+ if (schema.type === "number" || schema.type === "integer") return "number";
245
+ return "text";
246
+ }, [inputProps.type, schema.type]);
247
+ return /* @__PURE__ */ jsx(
248
+ Input,
249
+ {
250
+ id,
251
+ type: inputType,
252
+ value: safeValue,
253
+ disabled,
254
+ readOnly: readonly,
255
+ autoFocus: autofocus,
256
+ onChange: handleChange,
257
+ onBlur: handleBlur,
258
+ onFocus: handleFocus,
259
+ placeholder,
260
+ className: hasError ? "border-destructive" : "",
261
+ step: inputProps.step,
262
+ min: inputProps.min,
263
+ max: inputProps.max
264
+ }
265
+ );
266
+ }
267
+ __name(BaseInputTemplate, "BaseInputTemplate");
268
+ function validateSchema(schema) {
269
+ if (!schema || typeof schema !== "object") {
270
+ {
271
+ consola.error("[JsonSchemaForm] Invalid schema: must be an object", schema);
272
+ }
273
+ return null;
274
+ }
275
+ const hasValidStructure = schema.type || schema.properties || schema.$ref || schema.$schema;
276
+ if (!hasValidStructure) {
277
+ {
278
+ consola.error("[JsonSchemaForm] Invalid schema: missing type, properties, $ref, or $schema", schema);
279
+ }
280
+ return null;
281
+ }
282
+ {
283
+ consola.success("[JsonSchemaForm] Schema validated successfully:", {
284
+ type: schema.type,
285
+ title: schema.title,
286
+ hasProperties: !!schema.properties,
287
+ hasRequired: !!schema.required
288
+ });
289
+ }
290
+ return schema;
291
+ }
292
+ __name(validateSchema, "validateSchema");
293
+ function normalizeFormData(formData, schema) {
294
+ if (formData === null || formData === void 0) {
295
+ return schema.type === "object" ? {} : schema.type === "array" ? [] : null;
296
+ }
297
+ const normalized = JSON.parse(JSON.stringify(formData));
298
+ return removeUndefined(normalized);
299
+ }
300
+ __name(normalizeFormData, "normalizeFormData");
301
+ function removeUndefined(obj) {
302
+ if (obj === null || obj === void 0) {
303
+ return obj;
304
+ }
305
+ if (Array.isArray(obj)) {
306
+ return obj.map(removeUndefined).filter((item) => item !== void 0);
307
+ }
308
+ if (typeof obj === "object") {
309
+ const cleaned = {};
310
+ for (const key in obj) {
311
+ if (obj[key] !== void 0) {
312
+ cleaned[key] = removeUndefined(obj[key]);
313
+ }
314
+ }
315
+ return cleaned;
316
+ }
317
+ return obj;
318
+ }
319
+ __name(removeUndefined, "removeUndefined");
320
+ function mergeDefaults(formData, schema) {
321
+ if (!schema) return formData;
322
+ const result = { ...formData };
323
+ if (schema.type === "object" && schema.properties) {
324
+ for (const [key, propSchema] of Object.entries(schema.properties)) {
325
+ const prop = propSchema;
326
+ if (result[key] === void 0 && prop.default !== void 0) {
327
+ result[key] = prop.default;
328
+ }
329
+ if (prop.type === "object" && result[key]) {
330
+ result[key] = mergeDefaults(result[key], prop);
331
+ }
332
+ }
333
+ }
334
+ return result;
335
+ }
336
+ __name(mergeDefaults, "mergeDefaults");
337
+ function safeJsonParse(jsonString, fallback) {
338
+ try {
339
+ return JSON.parse(jsonString);
340
+ } catch (error) {
341
+ consola.error("[JsonSchemaForm] JSON parse error:", error);
342
+ return fallback;
343
+ }
344
+ }
345
+ __name(safeJsonParse, "safeJsonParse");
346
+ function safeJsonStringify(obj, pretty = true) {
347
+ try {
348
+ return JSON.stringify(obj, null, pretty ? 2 : 0);
349
+ } catch (error) {
350
+ consola.error("[JsonSchemaForm] JSON stringify error:", error);
351
+ return "{}";
352
+ }
353
+ }
354
+ __name(safeJsonStringify, "safeJsonStringify");
355
+ function hasRequiredFields(schema) {
356
+ return Array.isArray(schema.required) && schema.required.length > 0;
357
+ }
358
+ __name(hasRequiredFields, "hasRequiredFields");
359
+ function getRequiredFields(schema, prefix = "") {
360
+ const required = [];
361
+ if (schema.required && Array.isArray(schema.required)) {
362
+ required.push(...schema.required.map(
363
+ (field) => prefix ? `${prefix}.${field}` : field
364
+ ));
365
+ }
366
+ if (schema.type === "object" && schema.properties) {
367
+ for (const [key, propSchema] of Object.entries(schema.properties)) {
368
+ const prop = propSchema;
369
+ const fieldPath = prefix ? `${prefix}.${key}` : key;
370
+ required.push(...getRequiredFields(prop, fieldPath));
371
+ }
372
+ }
373
+ return required;
374
+ }
375
+ __name(getRequiredFields, "getRequiredFields");
376
+ function validateRequiredFields(formData, schema) {
377
+ const requiredFields = getRequiredFields(schema);
378
+ const missing = [];
379
+ for (const field of requiredFields) {
380
+ const value = getNestedValue(formData, field);
381
+ if (value === void 0 || value === null || value === "") {
382
+ missing.push(field);
383
+ }
384
+ }
385
+ return {
386
+ valid: missing.length === 0,
387
+ missing
388
+ };
389
+ }
390
+ __name(validateRequiredFields, "validateRequiredFields");
391
+ function getNestedValue(obj, path) {
392
+ return path.split(".").reduce((current, key) => current?.[key], obj);
393
+ }
394
+ __name(getNestedValue, "getNestedValue");
395
+ function TextWidget(props) {
396
+ const {
397
+ id,
398
+ placeholder,
399
+ required,
400
+ disabled,
401
+ readonly,
402
+ autofocus,
403
+ value,
404
+ onChange,
405
+ onBlur,
406
+ onFocus,
407
+ options,
408
+ schema,
409
+ rawErrors
410
+ } = props;
411
+ const config = useMemo(() => ({
412
+ isTextarea: options?.widget === "textarea",
413
+ rows: options?.rows || 3,
414
+ emptyValue: options?.emptyValue
415
+ }), [options]);
416
+ const safeValue = useMemo(() => {
417
+ if (value === null || value === void 0) return "";
418
+ return String(value);
419
+ }, [value]);
420
+ const hasError = useMemo(() => {
421
+ return rawErrors && rawErrors.length > 0;
422
+ }, [rawErrors]);
423
+ const handleChange = useCallback((event) => {
424
+ const newValue = event.target.value;
425
+ onChange(newValue === "" ? config.emptyValue : newValue);
426
+ }, [onChange, config.emptyValue]);
427
+ const handleBlur = useCallback((event) => {
428
+ onBlur(id, event.target.value);
429
+ }, [id, onBlur]);
430
+ const handleFocus = useCallback((event) => {
431
+ onFocus(id, event.target.value);
432
+ }, [id, onFocus]);
433
+ if (config.isTextarea) {
434
+ return /* @__PURE__ */ jsx(
435
+ "textarea",
436
+ {
437
+ id,
438
+ className: `flex min-h-[80px] w-full rounded-md border ${hasError ? "border-destructive" : "border-input"} bg-transparent px-3 py-2 text-base shadow-sm transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm`,
439
+ placeholder,
440
+ disabled: disabled || readonly,
441
+ readOnly: readonly,
442
+ autoFocus: autofocus,
443
+ value: safeValue,
444
+ required,
445
+ onChange: handleChange,
446
+ onBlur: handleBlur,
447
+ onFocus: handleFocus,
448
+ rows: config.rows
449
+ }
450
+ );
451
+ }
452
+ return /* @__PURE__ */ jsx(
453
+ Input,
454
+ {
455
+ id,
456
+ type: "text",
457
+ placeholder,
458
+ disabled,
459
+ readOnly: readonly,
460
+ autoFocus: autofocus,
461
+ value: safeValue,
462
+ required,
463
+ onChange: handleChange,
464
+ onBlur: handleBlur,
465
+ onFocus: handleFocus,
466
+ className: hasError ? "border-destructive" : ""
467
+ }
468
+ );
469
+ }
470
+ __name(TextWidget, "TextWidget");
471
+ function NumberWidget(props) {
472
+ const {
473
+ id,
474
+ placeholder,
475
+ required,
476
+ disabled,
477
+ readonly,
478
+ autofocus,
479
+ value,
480
+ onChange,
481
+ onBlur,
482
+ onFocus,
483
+ options,
484
+ schema,
485
+ rawErrors
486
+ } = props;
487
+ const config = useMemo(() => ({
488
+ isInteger: schema.type === "integer",
489
+ step: schema.type === "integer" ? "1" : "any",
490
+ min: schema.minimum,
491
+ max: schema.maximum,
492
+ emptyValue: options?.emptyValue
493
+ }), [schema, options]);
494
+ const safeValue = useMemo(() => {
495
+ if (value === null || value === void 0 || value === "") return "";
496
+ if (typeof value === "number" && !isNaN(value)) return value;
497
+ return "";
498
+ }, [value]);
499
+ const hasError = useMemo(() => {
500
+ return rawErrors && rawErrors.length > 0;
501
+ }, [rawErrors]);
502
+ const handleChange = useCallback((event) => {
503
+ const newValue = event.target.value;
504
+ if (newValue === "") {
505
+ onChange(config.emptyValue);
506
+ } else {
507
+ const parsedValue = config.isInteger ? parseInt(newValue, 10) : parseFloat(newValue);
508
+ onChange(isNaN(parsedValue) ? config.emptyValue : parsedValue);
509
+ }
510
+ }, [onChange, config]);
511
+ const handleBlur = useCallback((event) => {
512
+ onBlur(id, event.target.value);
513
+ }, [id, onBlur]);
514
+ const handleFocus = useCallback((event) => {
515
+ onFocus(id, event.target.value);
516
+ }, [id, onFocus]);
517
+ return /* @__PURE__ */ jsx(
518
+ Input,
519
+ {
520
+ id,
521
+ type: "number",
522
+ placeholder,
523
+ disabled,
524
+ readOnly: readonly,
525
+ autoFocus: autofocus,
526
+ value: safeValue,
527
+ required,
528
+ onChange: handleChange,
529
+ onBlur: handleBlur,
530
+ onFocus: handleFocus,
531
+ step: config.step,
532
+ min: config.min,
533
+ max: config.max,
534
+ className: hasError ? "border-destructive" : ""
535
+ }
536
+ );
537
+ }
538
+ __name(NumberWidget, "NumberWidget");
539
+ function CheckboxWidget(props) {
540
+ const {
541
+ id,
542
+ value,
543
+ disabled,
544
+ readonly,
545
+ autofocus,
546
+ onChange,
547
+ onBlur,
548
+ onFocus
549
+ } = props;
550
+ const handleChange = /* @__PURE__ */ __name((checked) => {
551
+ onChange(checked);
552
+ }, "handleChange");
553
+ return /* @__PURE__ */ jsx(
554
+ Checkbox,
555
+ {
556
+ id,
557
+ checked: value || false,
558
+ disabled: disabled || readonly,
559
+ autoFocus: autofocus,
560
+ onCheckedChange: handleChange,
561
+ onBlur: () => onBlur(id, value),
562
+ onFocus: () => onFocus(id, value)
563
+ }
564
+ );
565
+ }
566
+ __name(CheckboxWidget, "CheckboxWidget");
567
+ function SelectWidget(props) {
568
+ const {
569
+ id,
570
+ options,
571
+ value,
572
+ required,
573
+ disabled,
574
+ readonly,
575
+ autofocus,
576
+ onChange,
577
+ onBlur,
578
+ onFocus,
579
+ placeholder,
580
+ rawErrors
581
+ } = props;
582
+ const enumOptions = useMemo(() => {
583
+ const opts = options?.enumOptions;
584
+ if (!Array.isArray(opts)) return [];
585
+ return opts.filter((opt) => opt && opt.value !== void 0);
586
+ }, [options]);
587
+ const hasError = useMemo(() => {
588
+ return rawErrors && rawErrors.length > 0;
589
+ }, [rawErrors]);
590
+ const safeValue = useMemo(() => {
591
+ if (value === null || value === void 0) return "";
592
+ return String(value);
593
+ }, [value]);
594
+ const handleChange = useCallback((newValue) => {
595
+ onChange(newValue);
596
+ onBlur(id, newValue);
597
+ }, [onChange, onBlur, id]);
598
+ if (enumOptions.length === 0) {
599
+ return /* @__PURE__ */ jsx(
600
+ "input",
601
+ {
602
+ id,
603
+ type: "text",
604
+ value: safeValue,
605
+ onChange: (e) => onChange(e.target.value),
606
+ onBlur: (e) => onBlur(id, e.target.value),
607
+ onFocus: (e) => onFocus(id, e.target.value),
608
+ disabled: disabled || readonly,
609
+ readOnly: readonly,
610
+ className: `flex h-10 w-full rounded-md border ${hasError ? "border-destructive" : "border-input"} bg-transparent px-3 py-2 text-base shadow-sm transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm`,
611
+ placeholder
612
+ }
613
+ );
614
+ }
615
+ return /* @__PURE__ */ jsxs(
616
+ Select,
617
+ {
618
+ value: safeValue,
619
+ onValueChange: handleChange,
620
+ disabled: disabled || readonly,
621
+ required,
622
+ children: [
623
+ /* @__PURE__ */ jsx(
624
+ SelectTrigger,
625
+ {
626
+ id,
627
+ className: hasError ? "border-destructive" : "",
628
+ autoFocus: autofocus,
629
+ onFocus: () => onFocus(id, value),
630
+ children: /* @__PURE__ */ jsx(SelectValue, { placeholder: placeholder || "Select an option" })
631
+ }
632
+ ),
633
+ /* @__PURE__ */ jsx(SelectContent, { children: enumOptions.map((option) => /* @__PURE__ */ jsx(SelectItem, { value: String(option.value), children: option.label || String(option.value) }, String(option.value))) })
634
+ ]
635
+ }
636
+ );
637
+ }
638
+ __name(SelectWidget, "SelectWidget");
639
+ function SwitchWidget(props) {
640
+ const {
641
+ id,
642
+ value,
643
+ disabled,
644
+ readonly,
645
+ onChange,
646
+ onBlur,
647
+ onFocus
648
+ } = props;
649
+ const handleChange = /* @__PURE__ */ __name((checked) => {
650
+ onChange(checked);
651
+ }, "handleChange");
652
+ return /* @__PURE__ */ jsx(
653
+ Switch,
654
+ {
655
+ id,
656
+ checked: value || false,
657
+ disabled: disabled || readonly,
658
+ onCheckedChange: handleChange,
659
+ onBlur: () => onBlur(id, value),
660
+ onFocus: () => onFocus(id, value)
661
+ }
662
+ );
663
+ }
664
+ __name(SwitchWidget, "SwitchWidget");
665
+ function ColorWidget(props) {
666
+ const {
667
+ id,
668
+ placeholder,
669
+ required,
670
+ disabled,
671
+ readonly,
672
+ autofocus,
673
+ value,
674
+ onChange,
675
+ onBlur,
676
+ onFocus,
677
+ options,
678
+ rawErrors
679
+ } = props;
680
+ const t = useTypedT();
681
+ const pickColorLabel = useMemo(() => t("tools.color.pick"), [t]);
682
+ const colorInputRef = useRef(null);
683
+ const format = useMemo(() => {
684
+ if (options?.format) return options.format;
685
+ if (typeof value === "string" && value.startsWith("#")) return "hex";
686
+ return "hsl";
687
+ }, [options?.format, value]);
688
+ const safeValue = useMemo(() => {
689
+ if (value === null || value === void 0) return "";
690
+ return String(value);
691
+ }, [value]);
692
+ const hslToCss = useCallback((hslValue) => {
693
+ if (!hslValue) return "transparent";
694
+ if (hslValue.startsWith("#")) return hslValue;
695
+ if (hslValue.startsWith("hsl")) return hslValue;
696
+ const parts = hslValue.split(" ");
697
+ if (parts.length === 3) {
698
+ return `hsl(${parts[0]}, ${parts[1]}, ${parts[2]})`;
699
+ }
700
+ return "transparent";
701
+ }, []);
702
+ const previewColor = useMemo(() => {
703
+ return hslToCss(safeValue);
704
+ }, [safeValue, hslToCss]);
705
+ const hexToHsl = useCallback((hex) => {
706
+ hex = hex.replace("#", "");
707
+ const r = parseInt(hex.substring(0, 2), 16) / 255;
708
+ const g = parseInt(hex.substring(2, 4), 16) / 255;
709
+ const b = parseInt(hex.substring(4, 6), 16) / 255;
710
+ const max = Math.max(r, g, b);
711
+ const min = Math.min(r, g, b);
712
+ let h = 0;
713
+ let s = 0;
714
+ const l = (max + min) / 2;
715
+ if (max !== min) {
716
+ const d = max - min;
717
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
718
+ switch (max) {
719
+ case r:
720
+ h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
721
+ break;
722
+ case g:
723
+ h = ((b - r) / d + 2) / 6;
724
+ break;
725
+ case b:
726
+ h = ((r - g) / d + 4) / 6;
727
+ break;
728
+ }
729
+ }
730
+ return `${Math.round(h * 360)} ${Math.round(s * 100)}% ${Math.round(l * 100)}%`;
731
+ }, []);
732
+ const hslToHex = useCallback((hslValue) => {
733
+ if (!hslValue || hslValue.startsWith("#")) return hslValue || "#000000";
734
+ const parts = hslValue.split(" ");
735
+ if (parts.length !== 3) return "#000000";
736
+ const h = parseInt(parts[0]) / 360;
737
+ const s = parseInt(parts[1].replace("%", "")) / 100;
738
+ const l = parseInt(parts[2].replace("%", "")) / 100;
739
+ const hue2rgb = /* @__PURE__ */ __name((p, q, t2) => {
740
+ if (t2 < 0) t2 += 1;
741
+ if (t2 > 1) t2 -= 1;
742
+ if (t2 < 1 / 6) return p + (q - p) * 6 * t2;
743
+ if (t2 < 1 / 2) return q;
744
+ if (t2 < 2 / 3) return p + (q - p) * (2 / 3 - t2) * 6;
745
+ return p;
746
+ }, "hue2rgb");
747
+ let r, g, b;
748
+ if (s === 0) {
749
+ r = g = b = l;
750
+ } else {
751
+ const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
752
+ const p = 2 * l - q;
753
+ r = hue2rgb(p, q, h + 1 / 3);
754
+ g = hue2rgb(p, q, h);
755
+ b = hue2rgb(p, q, h - 1 / 3);
756
+ }
757
+ const toHex = /* @__PURE__ */ __name((x) => {
758
+ const hex = Math.round(x * 255).toString(16);
759
+ return hex.length === 1 ? "0" + hex : hex;
760
+ }, "toHex");
761
+ return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
762
+ }, []);
763
+ const hasError = useMemo(() => {
764
+ return rawErrors && rawErrors.length > 0;
765
+ }, [rawErrors]);
766
+ const handleChange = useCallback((event) => {
767
+ const newValue = event.target.value;
768
+ onChange(newValue);
769
+ }, [onChange]);
770
+ const handleColorPickerChange = useCallback((event) => {
771
+ const hexValue2 = event.target.value;
772
+ if (format === "hsl") {
773
+ onChange(hexToHsl(hexValue2));
774
+ } else {
775
+ onChange(hexValue2);
776
+ }
777
+ }, [onChange, format, hexToHsl]);
778
+ const handleBlur = useCallback((event) => {
779
+ onBlur(id, event.target.value);
780
+ }, [id, onBlur]);
781
+ const handleFocus = useCallback((event) => {
782
+ onFocus(id, event.target.value);
783
+ }, [id, onFocus]);
784
+ const hexValue = useMemo(() => {
785
+ if (format === "hex" || safeValue.startsWith("#")) {
786
+ return safeValue || "#000000";
787
+ }
788
+ return hslToHex(safeValue);
789
+ }, [safeValue, format, hslToHex]);
790
+ const handleColorBoxClick = useCallback(() => {
791
+ if (!disabled && !readonly) {
792
+ colorInputRef.current?.click();
793
+ }
794
+ }, [disabled, readonly]);
795
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
796
+ /* @__PURE__ */ jsxs("div", { className: "relative", children: [
797
+ /* @__PURE__ */ jsx(
798
+ "button",
799
+ {
800
+ type: "button",
801
+ onClick: handleColorBoxClick,
802
+ disabled: disabled || readonly,
803
+ className: "h-10 w-10 shrink-0 rounded-md border-2 border-input cursor-pointer hover:border-ring focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
804
+ style: { backgroundColor: previewColor },
805
+ "aria-label": pickColorLabel
806
+ }
807
+ ),
808
+ /* @__PURE__ */ jsx(
809
+ "input",
810
+ {
811
+ ref: colorInputRef,
812
+ type: "color",
813
+ value: hexValue,
814
+ onChange: handleColorPickerChange,
815
+ className: "absolute inset-0 opacity-0 w-full h-full cursor-pointer",
816
+ disabled: disabled || readonly,
817
+ tabIndex: -1
818
+ }
819
+ )
820
+ ] }),
821
+ /* @__PURE__ */ jsx(
822
+ Input,
823
+ {
824
+ id,
825
+ type: "text",
826
+ placeholder: placeholder || (format === "hsl" ? "217 91% 60%" : "#3b82f6"),
827
+ disabled,
828
+ readOnly: readonly,
829
+ autoFocus: autofocus,
830
+ value: safeValue,
831
+ required,
832
+ onChange: handleChange,
833
+ onBlur: handleBlur,
834
+ onFocus: handleFocus,
835
+ className: `flex-1 font-mono text-sm ${hasError ? "border-destructive" : ""}`
836
+ }
837
+ )
838
+ ] });
839
+ }
840
+ __name(ColorWidget, "ColorWidget");
841
+ function SliderWidget(props) {
842
+ const {
843
+ id,
844
+ disabled,
845
+ readonly,
846
+ value,
847
+ onChange,
848
+ schema,
849
+ options,
850
+ rawErrors
851
+ } = props;
852
+ const config = useMemo(() => {
853
+ const min = schema.minimum ?? options?.min ?? 0;
854
+ const max = schema.maximum ?? options?.max ?? 100;
855
+ const step = options?.step ?? (schema.type === "integer" ? 1 : 0.1);
856
+ const unit = options?.unit;
857
+ const showInput = options?.showInput !== false;
858
+ return { min, max, step, unit, showInput };
859
+ }, [schema, options]);
860
+ const numericValue = useMemo(() => {
861
+ if (value === null || value === void 0 || value === "") {
862
+ return config.min;
863
+ }
864
+ if (typeof value === "number") {
865
+ return value;
866
+ }
867
+ if (typeof value === "string") {
868
+ const parsed = parseFloat(value);
869
+ return isNaN(parsed) ? config.min : parsed;
870
+ }
871
+ return config.min;
872
+ }, [value, config.min]);
873
+ const hasError = useMemo(() => {
874
+ return rawErrors && rawErrors.length > 0;
875
+ }, [rawErrors]);
876
+ const handleSliderChange = useCallback((values) => {
877
+ const newValue = values[0];
878
+ if (config.unit) {
879
+ onChange(`${newValue}${config.unit}`);
880
+ } else {
881
+ onChange(newValue);
882
+ }
883
+ }, [onChange, config.unit]);
884
+ const handleInputChange = useCallback((event) => {
885
+ const inputValue = event.target.value;
886
+ if (config.unit) {
887
+ const cleanValue = inputValue.replace(config.unit, "").trim();
888
+ const parsed = parseFloat(cleanValue);
889
+ if (!isNaN(parsed)) {
890
+ onChange(`${parsed}${config.unit}`);
891
+ } else if (inputValue === "") {
892
+ onChange(`${config.min}${config.unit}`);
893
+ }
894
+ } else {
895
+ const parsed = parseFloat(inputValue);
896
+ onChange(isNaN(parsed) ? config.min : parsed);
897
+ }
898
+ }, [onChange, config.unit, config.min]);
899
+ const displayValue = useMemo(() => {
900
+ if (config.unit) {
901
+ return `${numericValue}${config.unit}`;
902
+ }
903
+ return String(numericValue);
904
+ }, [numericValue, config.unit]);
905
+ return /* @__PURE__ */ jsxs("div", { className: cn("flex items-center gap-3", hasError && "text-destructive"), children: [
906
+ /* @__PURE__ */ jsx(
907
+ Slider,
908
+ {
909
+ id,
910
+ disabled: disabled || readonly,
911
+ value: [numericValue],
912
+ onValueChange: handleSliderChange,
913
+ min: config.min,
914
+ max: config.max,
915
+ step: config.step,
916
+ className: "flex-1"
917
+ }
918
+ ),
919
+ config.showInput ? /* @__PURE__ */ jsx(
920
+ Input,
921
+ {
922
+ type: "text",
923
+ value: displayValue,
924
+ onChange: handleInputChange,
925
+ disabled,
926
+ readOnly: readonly,
927
+ className: cn(
928
+ "w-20 text-center font-mono text-sm",
929
+ hasError && "border-destructive"
930
+ )
931
+ }
932
+ ) : /* @__PURE__ */ jsx("span", { className: "w-16 text-right font-mono text-sm text-muted-foreground", children: displayValue })
933
+ ] });
934
+ }
935
+ __name(SliderWidget, "SliderWidget");
936
+ function JsonSchemaForm(props) {
937
+ const {
938
+ schema,
939
+ uiSchema,
940
+ formData,
941
+ onSubmit,
942
+ onChange,
943
+ onError,
944
+ showErrorList = "top",
945
+ liveValidate = false,
946
+ disabled = false,
947
+ readonly = false,
948
+ className,
949
+ showSubmitButton = true,
950
+ submitButtonText = "Submit",
951
+ ...restProps
952
+ } = props;
953
+ const validatedSchema = useMemo(() => {
954
+ {
955
+ consola.info("[JsonSchemaForm] Validating schema...", schema);
956
+ }
957
+ const result = validateSchema(schema);
958
+ if (!result && true) {
959
+ consola.error("[JsonSchemaForm] Schema validation failed");
960
+ }
961
+ return result;
962
+ }, [schema]);
963
+ const normalizedFormData = useMemo(() => {
964
+ if (!validatedSchema) {
965
+ {
966
+ consola.warn("[JsonSchemaForm] Cannot normalize formData - invalid schema");
967
+ }
968
+ return null;
969
+ }
970
+ {
971
+ consola.info("[JsonSchemaForm] Normalizing formData...", formData);
972
+ }
973
+ const normalized = normalizeFormData(formData, validatedSchema);
974
+ {
975
+ consola.info("[JsonSchemaForm] Normalized formData:", normalized);
976
+ }
977
+ return normalized;
978
+ }, [formData, validatedSchema]);
979
+ const widgets = useMemo(() => ({
980
+ // Standard widget names (PascalCase) - used by RJSF internally
981
+ TextWidget,
982
+ NumberWidget,
983
+ CheckboxWidget,
984
+ SelectWidget,
985
+ SwitchWidget,
986
+ ColorWidget,
987
+ SliderWidget,
988
+ // Lowercase aliases - for uiSchema 'ui:widget' references
989
+ text: TextWidget,
990
+ number: NumberWidget,
991
+ checkbox: CheckboxWidget,
992
+ select: SelectWidget,
993
+ switch: SwitchWidget,
994
+ color: ColorWidget,
995
+ slider: SliderWidget,
996
+ range: SliderWidget
997
+ // alias
998
+ }), []);
999
+ const templates = useMemo(() => ({
1000
+ FieldTemplate,
1001
+ ObjectFieldTemplate,
1002
+ ArrayFieldTemplate,
1003
+ ArrayFieldItemTemplate,
1004
+ ErrorListTemplate,
1005
+ BaseInputTemplate
1006
+ }), []);
1007
+ const handleSubmit = useCallback((data) => {
1008
+ if (onSubmit) {
1009
+ const cleanData = {
1010
+ ...data,
1011
+ formData: normalizeFormData(data.formData, validatedSchema)
1012
+ };
1013
+ onSubmit(cleanData);
1014
+ }
1015
+ }, [onSubmit, validatedSchema]);
1016
+ const handleChange = useCallback((data) => {
1017
+ if (onChange) {
1018
+ onChange(data);
1019
+ }
1020
+ }, [onChange]);
1021
+ const handleError = useCallback((errors) => {
1022
+ if (onError) {
1023
+ onError(errors);
1024
+ }
1025
+ }, [onError]);
1026
+ if (!validatedSchema) {
1027
+ return /* @__PURE__ */ jsx("div", { className, children: /* @__PURE__ */ jsxs(Alert, { variant: "destructive", children: [
1028
+ /* @__PURE__ */ jsx(AlertCircle, { className: "h-4 w-4" }),
1029
+ /* @__PURE__ */ jsx(AlertDescription, { children: "Invalid schema provided. Please check the schema format." })
1030
+ ] }) });
1031
+ }
1032
+ return /* @__PURE__ */ jsx("div", { className, children: /* @__PURE__ */ jsx(
1033
+ Form,
1034
+ {
1035
+ schema: validatedSchema,
1036
+ uiSchema,
1037
+ formData: normalizedFormData,
1038
+ validator,
1039
+ widgets,
1040
+ templates,
1041
+ onSubmit: handleSubmit,
1042
+ onChange: handleChange,
1043
+ onError: handleError,
1044
+ showErrorList,
1045
+ liveValidate,
1046
+ disabled,
1047
+ readonly,
1048
+ ...restProps,
1049
+ children: showSubmitButton && /* @__PURE__ */ jsx("div", { className: "mt-6 flex gap-2", children: /* @__PURE__ */ jsx(Button, { type: "submit", disabled, children: submitButtonText }) })
1050
+ }
1051
+ ) });
1052
+ }
1053
+ __name(JsonSchemaForm, "JsonSchemaForm");
1054
+
1055
+ export { ArrayFieldItemTemplate, ArrayFieldTemplate, BaseInputTemplate, CheckboxWidget, ColorWidget, ErrorListTemplate, FieldTemplate, JsonSchemaForm, NumberWidget, ObjectFieldTemplate, SelectWidget, SliderWidget, SwitchWidget, TextWidget, getRequiredFields, hasRequiredFields, mergeDefaults, normalizeFormData, safeJsonParse, safeJsonStringify, validateRequiredFields, validateSchema };
1056
+ //# sourceMappingURL=chunk-7IIRYG4S.mjs.map
1057
+ //# sourceMappingURL=chunk-7IIRYG4S.mjs.map