@algodomain/smart-forms 0.1.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.
- package/README.md +313 -0
- package/dist/SmartFormProvider-B-BTl4wO.d.cts +94 -0
- package/dist/SmartFormProvider-B-BTl4wO.d.ts +94 -0
- package/dist/SmartTags-HmvmCJPT.d.cts +111 -0
- package/dist/SmartTags-HmvmCJPT.d.ts +111 -0
- package/dist/chunk-6WAEAWTD.js +949 -0
- package/dist/chunk-6WAEAWTD.js.map +1 -0
- package/dist/chunk-IG4XDQMV.js +604 -0
- package/dist/chunk-IG4XDQMV.js.map +1 -0
- package/dist/chunk-Y6NGPMDH.cjs +982 -0
- package/dist/chunk-Y6NGPMDH.cjs.map +1 -0
- package/dist/chunk-YV7RVYMD.cjs +639 -0
- package/dist/chunk-YV7RVYMD.cjs.map +1 -0
- package/dist/fields.cjs +1445 -0
- package/dist/fields.cjs.map +1 -0
- package/dist/fields.d.cts +119 -0
- package/dist/fields.d.ts +119 -0
- package/dist/fields.js +1384 -0
- package/dist/fields.js.map +1 -0
- package/dist/index.cjs +906 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +165 -0
- package/dist/index.d.ts +165 -0
- package/dist/index.js +821 -0
- package/dist/index.js.map +1 -0
- package/dist/opinionated.cjs +408 -0
- package/dist/opinionated.cjs.map +1 -0
- package/dist/opinionated.d.cts +274 -0
- package/dist/opinionated.d.ts +274 -0
- package/dist/opinionated.js +382 -0
- package/dist/opinionated.js.map +1 -0
- package/dist/style.css +114 -0
- package/package.json +90 -0
package/dist/fields.cjs
ADDED
|
@@ -0,0 +1,1445 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkY6NGPMDH_cjs = require('./chunk-Y6NGPMDH.cjs');
|
|
4
|
+
var chunkYV7RVYMD_cjs = require('./chunk-YV7RVYMD.cjs');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var lucideReact = require('lucide-react');
|
|
7
|
+
var cmdk = require('cmdk');
|
|
8
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
9
|
+
var reactSlot = require('@radix-ui/react-slot');
|
|
10
|
+
var classVarianceAuthority = require('class-variance-authority');
|
|
11
|
+
var SliderPrimitive = require('@radix-ui/react-slider');
|
|
12
|
+
|
|
13
|
+
function _interopNamespace(e) {
|
|
14
|
+
if (e && e.__esModule) return e;
|
|
15
|
+
var n = Object.create(null);
|
|
16
|
+
if (e) {
|
|
17
|
+
Object.keys(e).forEach(function (k) {
|
|
18
|
+
if (k !== 'default') {
|
|
19
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
20
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return e[k]; }
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
n.default = e;
|
|
28
|
+
return Object.freeze(n);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
32
|
+
var SliderPrimitive__namespace = /*#__PURE__*/_interopNamespace(SliderPrimitive);
|
|
33
|
+
|
|
34
|
+
function Command({
|
|
35
|
+
className,
|
|
36
|
+
...props
|
|
37
|
+
}) {
|
|
38
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
39
|
+
cmdk.Command,
|
|
40
|
+
{
|
|
41
|
+
"data-slot": "command",
|
|
42
|
+
className: chunkYV7RVYMD_cjs.cn(
|
|
43
|
+
"bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md",
|
|
44
|
+
className
|
|
45
|
+
),
|
|
46
|
+
...props
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
function CommandInput({
|
|
51
|
+
className,
|
|
52
|
+
...props
|
|
53
|
+
}) {
|
|
54
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
55
|
+
"div",
|
|
56
|
+
{
|
|
57
|
+
"data-slot": "command-input-wrapper",
|
|
58
|
+
className: "flex h-9 items-center gap-2 border-b px-3",
|
|
59
|
+
children: [
|
|
60
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.SearchIcon, { className: "size-4 shrink-0 opacity-50" }),
|
|
61
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
62
|
+
cmdk.Command.Input,
|
|
63
|
+
{
|
|
64
|
+
"data-slot": "command-input",
|
|
65
|
+
className: chunkYV7RVYMD_cjs.cn(
|
|
66
|
+
"placeholder:text-muted-foreground flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50",
|
|
67
|
+
className
|
|
68
|
+
),
|
|
69
|
+
...props
|
|
70
|
+
}
|
|
71
|
+
)
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
function CommandList({
|
|
77
|
+
className,
|
|
78
|
+
...props
|
|
79
|
+
}) {
|
|
80
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
81
|
+
cmdk.Command.List,
|
|
82
|
+
{
|
|
83
|
+
"data-slot": "command-list",
|
|
84
|
+
className: chunkYV7RVYMD_cjs.cn(
|
|
85
|
+
"max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",
|
|
86
|
+
className
|
|
87
|
+
),
|
|
88
|
+
...props
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
function CommandEmpty({
|
|
93
|
+
...props
|
|
94
|
+
}) {
|
|
95
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
96
|
+
cmdk.Command.Empty,
|
|
97
|
+
{
|
|
98
|
+
"data-slot": "command-empty",
|
|
99
|
+
className: "py-6 text-center text-sm",
|
|
100
|
+
...props
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
function CommandGroup({
|
|
105
|
+
className,
|
|
106
|
+
...props
|
|
107
|
+
}) {
|
|
108
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
109
|
+
cmdk.Command.Group,
|
|
110
|
+
{
|
|
111
|
+
"data-slot": "command-group",
|
|
112
|
+
className: chunkYV7RVYMD_cjs.cn(
|
|
113
|
+
"text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium",
|
|
114
|
+
className
|
|
115
|
+
),
|
|
116
|
+
...props
|
|
117
|
+
}
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
function CommandItem({
|
|
121
|
+
className,
|
|
122
|
+
...props
|
|
123
|
+
}) {
|
|
124
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
125
|
+
cmdk.Command.Item,
|
|
126
|
+
{
|
|
127
|
+
"data-slot": "command-item",
|
|
128
|
+
className: chunkYV7RVYMD_cjs.cn(
|
|
129
|
+
"data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
130
|
+
className
|
|
131
|
+
),
|
|
132
|
+
...props
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
var badgeVariants = classVarianceAuthority.cva(
|
|
137
|
+
"inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
|
|
138
|
+
{
|
|
139
|
+
variants: {
|
|
140
|
+
variant: {
|
|
141
|
+
default: "border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
|
|
142
|
+
secondary: "border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
|
|
143
|
+
destructive: "border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
144
|
+
outline: "text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground"
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
defaultVariants: {
|
|
148
|
+
variant: "default"
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
function Badge({
|
|
153
|
+
className,
|
|
154
|
+
variant,
|
|
155
|
+
asChild = false,
|
|
156
|
+
...props
|
|
157
|
+
}) {
|
|
158
|
+
const Comp = asChild ? reactSlot.Slot : "span";
|
|
159
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
160
|
+
Comp,
|
|
161
|
+
{
|
|
162
|
+
"data-slot": "badge",
|
|
163
|
+
className: chunkYV7RVYMD_cjs.cn(badgeVariants({ variant }), className),
|
|
164
|
+
...props
|
|
165
|
+
}
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
function Combobox({
|
|
169
|
+
options,
|
|
170
|
+
value = "",
|
|
171
|
+
onChange,
|
|
172
|
+
placeholder = "Select option...",
|
|
173
|
+
searchPlaceholder = "Search...",
|
|
174
|
+
noResultsText = "No results found.",
|
|
175
|
+
width = "100%",
|
|
176
|
+
isDisabled = false,
|
|
177
|
+
allowCustom = false
|
|
178
|
+
}) {
|
|
179
|
+
const [open, setOpen] = React__namespace.default.useState(false);
|
|
180
|
+
const [searchValue, setSearchValue] = React.useState("");
|
|
181
|
+
const containerStyles = {
|
|
182
|
+
width
|
|
183
|
+
};
|
|
184
|
+
const combinedOptions = allowCustom ? [
|
|
185
|
+
...options,
|
|
186
|
+
...searchValue && !options.some(
|
|
187
|
+
(opt) => opt.label.toLowerCase() === searchValue.toLowerCase()
|
|
188
|
+
) ? [
|
|
189
|
+
{
|
|
190
|
+
value: searchValue.toLowerCase().replace(/\s+/g, "-"),
|
|
191
|
+
label: searchValue
|
|
192
|
+
}
|
|
193
|
+
] : []
|
|
194
|
+
] : options;
|
|
195
|
+
const filteredOptions = combinedOptions.filter(
|
|
196
|
+
(option) => option.label.toLowerCase().includes(searchValue.toLowerCase())
|
|
197
|
+
);
|
|
198
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: containerStyles, children: /* @__PURE__ */ jsxRuntime.jsxs(chunkY6NGPMDH_cjs.Popover, { open, onOpenChange: setOpen, children: [
|
|
199
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkY6NGPMDH_cjs.PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
200
|
+
chunkY6NGPMDH_cjs.Button,
|
|
201
|
+
{
|
|
202
|
+
variant: "outline",
|
|
203
|
+
role: "combobox",
|
|
204
|
+
"aria-expanded": open,
|
|
205
|
+
style: containerStyles,
|
|
206
|
+
className: `flex items-center justify-between relative ${isDisabled ? "cursor-not-allowed opacity-50" : ""}`,
|
|
207
|
+
disabled: isDisabled,
|
|
208
|
+
children: [
|
|
209
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 min-w-0 text-left", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "truncate", children: value ? combinedOptions.find((option) => option.value === value)?.label || value : placeholder }) }),
|
|
210
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronsUpDown, { className: "ml-2 h-4 w-4 flex-shrink-0 opacity-50" })
|
|
211
|
+
]
|
|
212
|
+
}
|
|
213
|
+
) }),
|
|
214
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkY6NGPMDH_cjs.PopoverContent, { className: "w-[var(--radix-popover-trigger-width)] p-0", children: /* @__PURE__ */ jsxRuntime.jsxs(Command, { className: "w-full", children: [
|
|
215
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
216
|
+
CommandInput,
|
|
217
|
+
{
|
|
218
|
+
value: searchValue,
|
|
219
|
+
onValueChange: setSearchValue,
|
|
220
|
+
placeholder: searchPlaceholder,
|
|
221
|
+
className: "h-9"
|
|
222
|
+
}
|
|
223
|
+
),
|
|
224
|
+
/* @__PURE__ */ jsxRuntime.jsx(CommandList, { children: filteredOptions.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(CommandGroup, { className: "max-h-[200px] overflow-y-auto", children: filteredOptions.map((option) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
225
|
+
CommandItem,
|
|
226
|
+
{
|
|
227
|
+
value: option.value,
|
|
228
|
+
onSelect: (currentValue) => {
|
|
229
|
+
onChange(currentValue === value ? "" : currentValue);
|
|
230
|
+
setOpen(false);
|
|
231
|
+
setSearchValue("");
|
|
232
|
+
},
|
|
233
|
+
className: "flex items-center",
|
|
234
|
+
style: { width: "100%" },
|
|
235
|
+
children: [
|
|
236
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center w-full min-w-0", children: [
|
|
237
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
238
|
+
lucideReact.Check,
|
|
239
|
+
{
|
|
240
|
+
className: `mr-2 h-4 w-4 flex-shrink-0 ${value === option.value ? "opacity-100" : "opacity-0"}`
|
|
241
|
+
}
|
|
242
|
+
),
|
|
243
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate flex-1", children: option.label })
|
|
244
|
+
] }),
|
|
245
|
+
option.badge && /* @__PURE__ */ jsxRuntime.jsx(
|
|
246
|
+
Badge,
|
|
247
|
+
{
|
|
248
|
+
variant: "outline",
|
|
249
|
+
className: "ml-2 text-[10px] px-2 py-0 h-5 font-normal",
|
|
250
|
+
children: option.badge
|
|
251
|
+
}
|
|
252
|
+
)
|
|
253
|
+
]
|
|
254
|
+
},
|
|
255
|
+
option.value
|
|
256
|
+
)) }) : /* @__PURE__ */ jsxRuntime.jsxs(CommandEmpty, { children: [
|
|
257
|
+
allowCustom && searchValue && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
258
|
+
chunkY6NGPMDH_cjs.Button,
|
|
259
|
+
{
|
|
260
|
+
variant: "ghost",
|
|
261
|
+
className: "w-full justify-start",
|
|
262
|
+
onClick: () => {
|
|
263
|
+
const newOption = {
|
|
264
|
+
value: searchValue.toLowerCase().replace(/\s+/g, "-")};
|
|
265
|
+
onChange(newOption.value);
|
|
266
|
+
setOpen(false);
|
|
267
|
+
setSearchValue("");
|
|
268
|
+
},
|
|
269
|
+
children: [
|
|
270
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Plus, { className: "mr-2 h-4 w-4" }),
|
|
271
|
+
'Add "',
|
|
272
|
+
searchValue,
|
|
273
|
+
'" as a new option'
|
|
274
|
+
]
|
|
275
|
+
}
|
|
276
|
+
),
|
|
277
|
+
!searchValue && noResultsText
|
|
278
|
+
] }) })
|
|
279
|
+
] }) })
|
|
280
|
+
] }) });
|
|
281
|
+
}
|
|
282
|
+
var SmartCombobox = ({
|
|
283
|
+
field,
|
|
284
|
+
label,
|
|
285
|
+
options,
|
|
286
|
+
className = "",
|
|
287
|
+
placeholder,
|
|
288
|
+
allowCustom = false,
|
|
289
|
+
validation,
|
|
290
|
+
required = false,
|
|
291
|
+
defaultValue,
|
|
292
|
+
info,
|
|
293
|
+
subLabel
|
|
294
|
+
}) => {
|
|
295
|
+
const { value, error, onChange, fieldRef, registerValidation } = chunkYV7RVYMD_cjs.useFormField(field);
|
|
296
|
+
const fieldDetection = chunkYV7RVYMD_cjs.useFieldDetection();
|
|
297
|
+
const hasRegistered = React.useRef(false);
|
|
298
|
+
const hasSetDefault = React.useRef(false);
|
|
299
|
+
React.useEffect(() => {
|
|
300
|
+
if (validation && !hasRegistered.current) {
|
|
301
|
+
hasRegistered.current = true;
|
|
302
|
+
registerValidation(field, validation);
|
|
303
|
+
}
|
|
304
|
+
}, [validation, field, registerValidation]);
|
|
305
|
+
React.useEffect(() => {
|
|
306
|
+
if (fieldDetection?.registerField) {
|
|
307
|
+
fieldDetection.registerField(field);
|
|
308
|
+
}
|
|
309
|
+
}, [field, fieldDetection]);
|
|
310
|
+
React.useEffect(() => {
|
|
311
|
+
if (defaultValue !== void 0 && !hasSetDefault.current && (value === void 0 || value === null || value === "")) {
|
|
312
|
+
onChange(defaultValue);
|
|
313
|
+
hasSetDefault.current = true;
|
|
314
|
+
}
|
|
315
|
+
}, [defaultValue, value, onChange]);
|
|
316
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex-1 min-w-0 ${className}`, children: [
|
|
317
|
+
label && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-2", children: [
|
|
318
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-2", children: [
|
|
319
|
+
/* @__PURE__ */ jsxRuntime.jsxs(chunkYV7RVYMD_cjs.Label, { className: "text-sm font-medium text-foreground", children: [
|
|
320
|
+
label,
|
|
321
|
+
" ",
|
|
322
|
+
required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-destructive", children: "*" })
|
|
323
|
+
] }),
|
|
324
|
+
info && /* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(chunkYV7RVYMD_cjs.Tooltip, { children: [
|
|
325
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.InfoIcon, { className: "h-4 w-4 text-muted-foreground cursor-pointer mr-2" }) }),
|
|
326
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipContent, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { className: "max-w-xs", children: info }) })
|
|
327
|
+
] }) })
|
|
328
|
+
] }),
|
|
329
|
+
subLabel && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground mt-1", children: subLabel })
|
|
330
|
+
] }),
|
|
331
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { ref: fieldRef, "data-field": field, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
332
|
+
Combobox,
|
|
333
|
+
{
|
|
334
|
+
options: (options || []).map((o) => ({ value: o.value, label: o.label })),
|
|
335
|
+
value: value || "",
|
|
336
|
+
onChange: (newValue) => onChange(newValue),
|
|
337
|
+
placeholder: placeholder || (label ? `Select ${label.toLowerCase()}` : `Select ${field}`),
|
|
338
|
+
allowCustom
|
|
339
|
+
}
|
|
340
|
+
) }),
|
|
341
|
+
error && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-destructive text-sm mt-1", children: error })
|
|
342
|
+
] });
|
|
343
|
+
};
|
|
344
|
+
var SmartFileUpload = ({
|
|
345
|
+
field,
|
|
346
|
+
label,
|
|
347
|
+
className = "",
|
|
348
|
+
validation,
|
|
349
|
+
required = false,
|
|
350
|
+
multiple = false,
|
|
351
|
+
accept,
|
|
352
|
+
maxFiles,
|
|
353
|
+
maxSizeBytes,
|
|
354
|
+
uploadApi,
|
|
355
|
+
uploadOnSelect = false,
|
|
356
|
+
onSuccess,
|
|
357
|
+
onError,
|
|
358
|
+
defaultValue,
|
|
359
|
+
info,
|
|
360
|
+
subLabel
|
|
361
|
+
}) => {
|
|
362
|
+
const { value, error, onChange, fieldRef, registerValidation } = chunkYV7RVYMD_cjs.useFormField(field);
|
|
363
|
+
const { registerSubmitHook, unregisterSubmitHook } = chunkYV7RVYMD_cjs.useSmartForm();
|
|
364
|
+
const fieldDetection = chunkYV7RVYMD_cjs.useFieldDetection();
|
|
365
|
+
const hasRegistered = React.useRef(false);
|
|
366
|
+
const hasSetDefault = React.useRef(false);
|
|
367
|
+
const inputRef = React.useRef(null);
|
|
368
|
+
React.useEffect(() => {
|
|
369
|
+
if (validation && !hasRegistered.current) {
|
|
370
|
+
hasRegistered.current = true;
|
|
371
|
+
registerValidation(field, validation);
|
|
372
|
+
}
|
|
373
|
+
}, [validation, field, registerValidation]);
|
|
374
|
+
React.useEffect(() => {
|
|
375
|
+
if (fieldDetection?.registerField) {
|
|
376
|
+
fieldDetection.registerField(field);
|
|
377
|
+
}
|
|
378
|
+
}, [field, fieldDetection]);
|
|
379
|
+
React.useEffect(() => {
|
|
380
|
+
if (defaultValue !== void 0 && !hasSetDefault.current && (value === void 0 || value === null || value === "")) {
|
|
381
|
+
onChange(defaultValue);
|
|
382
|
+
hasSetDefault.current = true;
|
|
383
|
+
}
|
|
384
|
+
}, [defaultValue, value, onChange]);
|
|
385
|
+
const normalizedFiles = React.useMemo(() => {
|
|
386
|
+
const filesAny = Array.isArray(value) ? value : value ? [value] : [];
|
|
387
|
+
return filesAny.filter((f) => f instanceof File);
|
|
388
|
+
}, [value]);
|
|
389
|
+
const [previewUrls, setPreviewUrls] = React.useState(/* @__PURE__ */ new Map());
|
|
390
|
+
React.useEffect(() => {
|
|
391
|
+
const newUrls = /* @__PURE__ */ new Map();
|
|
392
|
+
normalizedFiles.forEach((file) => {
|
|
393
|
+
if (file.type.startsWith("image/")) {
|
|
394
|
+
const key = `${file.name}-${file.size}-${file.lastModified}`;
|
|
395
|
+
if (!previewUrls.has(key)) {
|
|
396
|
+
newUrls.set(key, URL.createObjectURL(file));
|
|
397
|
+
} else {
|
|
398
|
+
newUrls.set(key, previewUrls.get(key));
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
previewUrls.forEach((url, key) => {
|
|
403
|
+
if (!newUrls.has(key)) {
|
|
404
|
+
URL.revokeObjectURL(url);
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
setPreviewUrls(newUrls);
|
|
408
|
+
}, [normalizedFiles]);
|
|
409
|
+
React.useEffect(() => {
|
|
410
|
+
return () => {
|
|
411
|
+
previewUrls.forEach((url) => URL.revokeObjectURL(url));
|
|
412
|
+
};
|
|
413
|
+
}, []);
|
|
414
|
+
const removeFileAt = (index) => {
|
|
415
|
+
if (!multiple) {
|
|
416
|
+
onChange(null);
|
|
417
|
+
if (inputRef.current) inputRef.current.value = "";
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
const next = normalizedFiles.filter((_, i) => i !== index);
|
|
421
|
+
onChange(next);
|
|
422
|
+
if (next.length === 0 && inputRef.current) inputRef.current.value = "";
|
|
423
|
+
};
|
|
424
|
+
const handleFiles = (filesList) => {
|
|
425
|
+
if (!filesList) return;
|
|
426
|
+
let files = Array.from(filesList);
|
|
427
|
+
if (maxFiles && files.length > maxFiles) {
|
|
428
|
+
files = files.slice(0, maxFiles);
|
|
429
|
+
}
|
|
430
|
+
if (maxSizeBytes) {
|
|
431
|
+
files = files.filter((f) => f.size <= maxSizeBytes);
|
|
432
|
+
}
|
|
433
|
+
if (multiple) {
|
|
434
|
+
onChange(files);
|
|
435
|
+
} else {
|
|
436
|
+
onChange(files[0] || null);
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
const onInputChange = (e) => {
|
|
440
|
+
handleFiles(e.target.files);
|
|
441
|
+
};
|
|
442
|
+
const clearSelection = () => {
|
|
443
|
+
onChange(multiple ? [] : null);
|
|
444
|
+
if (inputRef.current) {
|
|
445
|
+
inputRef.current.value = "";
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
const performUpload = async () => {
|
|
449
|
+
if (!uploadApi) return;
|
|
450
|
+
const filesAny = Array.isArray(value) ? value : value ? [value] : [];
|
|
451
|
+
const files = filesAny.filter((f) => f instanceof File);
|
|
452
|
+
if (files.length === 0) return;
|
|
453
|
+
const fd = new FormData();
|
|
454
|
+
if (multiple) {
|
|
455
|
+
for (const f of files) fd.append(`${field}[]`, f);
|
|
456
|
+
} else if (files[0]) {
|
|
457
|
+
fd.append(field, files[0]);
|
|
458
|
+
}
|
|
459
|
+
try {
|
|
460
|
+
const response = await fetch(uploadApi, {
|
|
461
|
+
method: "POST",
|
|
462
|
+
body: fd
|
|
463
|
+
});
|
|
464
|
+
const maybeJson = (() => {
|
|
465
|
+
try {
|
|
466
|
+
return response.headers.get("content-type")?.includes("application/json") ? true : false;
|
|
467
|
+
} catch {
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
})();
|
|
471
|
+
const result = maybeJson ? await response.json() : await response.text();
|
|
472
|
+
if (!response.ok) {
|
|
473
|
+
if (onError) onError(result);
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
if (onSuccess) onSuccess(result);
|
|
477
|
+
} catch (err) {
|
|
478
|
+
if (onError) onError(err);
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
React.useEffect(() => {
|
|
482
|
+
if (!uploadOnSelect || !uploadApi) return;
|
|
483
|
+
const filesAny = Array.isArray(value) ? value : value ? [value] : [];
|
|
484
|
+
const files = filesAny.filter((f) => f instanceof File);
|
|
485
|
+
if (files.length > 0) {
|
|
486
|
+
void performUpload();
|
|
487
|
+
}
|
|
488
|
+
}, [value, uploadOnSelect, uploadApi]);
|
|
489
|
+
React.useEffect(() => {
|
|
490
|
+
const key = `smart-file-upload:${field}`;
|
|
491
|
+
if (uploadApi && !uploadOnSelect) {
|
|
492
|
+
registerSubmitHook(key, performUpload);
|
|
493
|
+
return () => unregisterSubmitHook(key);
|
|
494
|
+
}
|
|
495
|
+
return () => unregisterSubmitHook(key);
|
|
496
|
+
}, [field, uploadApi, uploadOnSelect, registerSubmitHook, unregisterSubmitHook, value, multiple]);
|
|
497
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: chunkYV7RVYMD_cjs.cn("flex-1 min-w-0", className), children: [
|
|
498
|
+
label && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-2", children: [
|
|
499
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-2", children: [
|
|
500
|
+
/* @__PURE__ */ jsxRuntime.jsxs(chunkYV7RVYMD_cjs.Label, { className: "text-sm font-medium text-foreground", children: [
|
|
501
|
+
label,
|
|
502
|
+
" ",
|
|
503
|
+
required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-destructive", children: "*" })
|
|
504
|
+
] }),
|
|
505
|
+
info && /* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(chunkYV7RVYMD_cjs.Tooltip, { children: [
|
|
506
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.InfoIcon, { className: "h-4 w-4 text-muted-foreground cursor-pointer mr-2" }) }),
|
|
507
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipContent, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { className: "max-w-xs", children: info }) })
|
|
508
|
+
] }) })
|
|
509
|
+
] }),
|
|
510
|
+
subLabel && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground mt-1", children: subLabel })
|
|
511
|
+
] }),
|
|
512
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: chunkYV7RVYMD_cjs.cn("flex items-center gap-2", error && "text-destructive"), children: [
|
|
513
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
514
|
+
chunkYV7RVYMD_cjs.Input,
|
|
515
|
+
{
|
|
516
|
+
ref: (el) => {
|
|
517
|
+
inputRef.current = el;
|
|
518
|
+
if (typeof fieldRef === "function") fieldRef(el);
|
|
519
|
+
},
|
|
520
|
+
type: "file",
|
|
521
|
+
accept,
|
|
522
|
+
multiple,
|
|
523
|
+
onChange: onInputChange,
|
|
524
|
+
className: chunkYV7RVYMD_cjs.cn(error && "border-destructive"),
|
|
525
|
+
"data-field": field
|
|
526
|
+
}
|
|
527
|
+
),
|
|
528
|
+
(Array.isArray(value) ? value.length > 0 : !!value) && /* @__PURE__ */ jsxRuntime.jsx(chunkY6NGPMDH_cjs.Button, { type: "button", variant: "secondary", onClick: clearSelection, children: "Clear" })
|
|
529
|
+
] }),
|
|
530
|
+
normalizedFiles.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-2 text-sm text-muted-foreground", children: "No file selected" }) : /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "mt-2 space-y-1", children: normalizedFiles.map((f, idx) => {
|
|
531
|
+
const isImage = f.type.startsWith("image/");
|
|
532
|
+
const key = `${f.name}-${f.size}-${f.lastModified}`;
|
|
533
|
+
const previewUrl = isImage ? previewUrls.get(key) : null;
|
|
534
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "flex items-center justify-between rounded border px-2 py-1", children: [
|
|
535
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center min-w-0 mr-2", children: [
|
|
536
|
+
isImage && previewUrl ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative group mr-2", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
537
|
+
"img",
|
|
538
|
+
{
|
|
539
|
+
src: previewUrl,
|
|
540
|
+
alt: `Preview of ${f.name}`,
|
|
541
|
+
className: "w-8 h-8 object-cover rounded border"
|
|
542
|
+
}
|
|
543
|
+
) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-8 h-8 mr-2 flex items-center justify-center bg-gray-100 rounded border", children: "\u{1F4C4}" }),
|
|
544
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0", children: [
|
|
545
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "truncate text-sm font-medium", children: f.name }),
|
|
546
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-xs text-muted-foreground", children: [
|
|
547
|
+
(f.size / 1024).toFixed(1),
|
|
548
|
+
" KB"
|
|
549
|
+
] })
|
|
550
|
+
] })
|
|
551
|
+
] }),
|
|
552
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
553
|
+
chunkY6NGPMDH_cjs.Button,
|
|
554
|
+
{
|
|
555
|
+
type: "button",
|
|
556
|
+
variant: "ghost",
|
|
557
|
+
size: "sm",
|
|
558
|
+
onClick: () => removeFileAt(idx),
|
|
559
|
+
"aria-label": `Remove ${f.name}`,
|
|
560
|
+
children: "\u2715"
|
|
561
|
+
}
|
|
562
|
+
)
|
|
563
|
+
] }, `${f.name}-${idx}`);
|
|
564
|
+
}) }),
|
|
565
|
+
error && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-destructive text-sm mt-1", children: error })
|
|
566
|
+
] });
|
|
567
|
+
};
|
|
568
|
+
function Slider({
|
|
569
|
+
className,
|
|
570
|
+
defaultValue,
|
|
571
|
+
value,
|
|
572
|
+
min = 0,
|
|
573
|
+
max = 100,
|
|
574
|
+
...props
|
|
575
|
+
}) {
|
|
576
|
+
const _values = React__namespace.useMemo(
|
|
577
|
+
() => Array.isArray(value) ? value : Array.isArray(defaultValue) ? defaultValue : [min, max],
|
|
578
|
+
[value, defaultValue, min, max]
|
|
579
|
+
);
|
|
580
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
581
|
+
SliderPrimitive__namespace.Root,
|
|
582
|
+
{
|
|
583
|
+
"data-slot": "slider",
|
|
584
|
+
defaultValue,
|
|
585
|
+
value,
|
|
586
|
+
min,
|
|
587
|
+
max,
|
|
588
|
+
className: chunkYV7RVYMD_cjs.cn(
|
|
589
|
+
"relative flex w-full touch-none items-center select-none data-[disabled]:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col",
|
|
590
|
+
className
|
|
591
|
+
),
|
|
592
|
+
...props,
|
|
593
|
+
children: [
|
|
594
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
595
|
+
SliderPrimitive__namespace.Track,
|
|
596
|
+
{
|
|
597
|
+
"data-slot": "slider-track",
|
|
598
|
+
className: chunkYV7RVYMD_cjs.cn(
|
|
599
|
+
"bg-muted relative grow overflow-hidden rounded-full data-[orientation=horizontal]:h-1.5 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5"
|
|
600
|
+
),
|
|
601
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
602
|
+
SliderPrimitive__namespace.Range,
|
|
603
|
+
{
|
|
604
|
+
"data-slot": "slider-range",
|
|
605
|
+
className: chunkYV7RVYMD_cjs.cn(
|
|
606
|
+
"bg-primary absolute data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full"
|
|
607
|
+
)
|
|
608
|
+
}
|
|
609
|
+
)
|
|
610
|
+
}
|
|
611
|
+
),
|
|
612
|
+
Array.from({ length: _values.length }, (_, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
613
|
+
SliderPrimitive__namespace.Thumb,
|
|
614
|
+
{
|
|
615
|
+
"data-slot": "slider-thumb",
|
|
616
|
+
className: "border-primary bg-background ring-ring/50 block size-4 shrink-0 rounded-full border shadow-sm transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50"
|
|
617
|
+
},
|
|
618
|
+
index
|
|
619
|
+
))
|
|
620
|
+
]
|
|
621
|
+
}
|
|
622
|
+
);
|
|
623
|
+
}
|
|
624
|
+
var SmartSlider = ({
|
|
625
|
+
field,
|
|
626
|
+
label,
|
|
627
|
+
min = 0,
|
|
628
|
+
max = 100,
|
|
629
|
+
step = 1,
|
|
630
|
+
className = "",
|
|
631
|
+
validation,
|
|
632
|
+
required = false,
|
|
633
|
+
showValue = true,
|
|
634
|
+
valueFormatter = (value) => value.toString(),
|
|
635
|
+
defaultValue,
|
|
636
|
+
info,
|
|
637
|
+
subLabel
|
|
638
|
+
}) => {
|
|
639
|
+
const { value, error, onChange, fieldRef, registerValidation } = chunkYV7RVYMD_cjs.useFormField(field);
|
|
640
|
+
const fieldDetection = chunkYV7RVYMD_cjs.useFieldDetection();
|
|
641
|
+
const hasRegistered = React.useRef(false);
|
|
642
|
+
const hasSetDefault = React.useRef(false);
|
|
643
|
+
React.useEffect(() => {
|
|
644
|
+
if (validation && !hasRegistered.current) {
|
|
645
|
+
hasRegistered.current = true;
|
|
646
|
+
registerValidation(field, validation);
|
|
647
|
+
}
|
|
648
|
+
}, [validation, field, registerValidation]);
|
|
649
|
+
React.useEffect(() => {
|
|
650
|
+
if (fieldDetection?.registerField) {
|
|
651
|
+
fieldDetection.registerField(field);
|
|
652
|
+
}
|
|
653
|
+
}, [field, fieldDetection]);
|
|
654
|
+
React.useEffect(() => {
|
|
655
|
+
if (defaultValue !== void 0 && !hasSetDefault.current && (value === void 0 || value === null || value === "")) {
|
|
656
|
+
onChange(defaultValue);
|
|
657
|
+
hasSetDefault.current = true;
|
|
658
|
+
}
|
|
659
|
+
}, [defaultValue, value, onChange]);
|
|
660
|
+
const handleValueChange = (values) => {
|
|
661
|
+
const newValue = values[0];
|
|
662
|
+
onChange(newValue);
|
|
663
|
+
};
|
|
664
|
+
const currentValue = value !== void 0 ? value : min;
|
|
665
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex-1 min-w-0 ${className}`, children: [
|
|
666
|
+
label && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-2", children: [
|
|
667
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-2", children: [
|
|
668
|
+
/* @__PURE__ */ jsxRuntime.jsxs(chunkYV7RVYMD_cjs.Label, { className: "text-sm font-medium text-foreground", children: [
|
|
669
|
+
label,
|
|
670
|
+
" ",
|
|
671
|
+
required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-destructive", children: "*" }),
|
|
672
|
+
showValue && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "ml-2 text-muted-foreground", children: [
|
|
673
|
+
"(",
|
|
674
|
+
valueFormatter(currentValue),
|
|
675
|
+
")"
|
|
676
|
+
] })
|
|
677
|
+
] }),
|
|
678
|
+
info && /* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(chunkYV7RVYMD_cjs.Tooltip, { children: [
|
|
679
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.InfoIcon, { className: "h-4 w-4 text-muted-foreground cursor-pointer mr-2" }) }),
|
|
680
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipContent, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { className: "max-w-xs", children: info }) })
|
|
681
|
+
] }) })
|
|
682
|
+
] }),
|
|
683
|
+
subLabel && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground mt-1", children: subLabel })
|
|
684
|
+
] }),
|
|
685
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
686
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
687
|
+
Slider,
|
|
688
|
+
{
|
|
689
|
+
ref: fieldRef,
|
|
690
|
+
value: [currentValue],
|
|
691
|
+
onValueChange: handleValueChange,
|
|
692
|
+
min,
|
|
693
|
+
max,
|
|
694
|
+
step,
|
|
695
|
+
className: `w-full ${error ? "border-destructive" : ""}`,
|
|
696
|
+
"data-field": field
|
|
697
|
+
}
|
|
698
|
+
),
|
|
699
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-between text-sm text-muted-foreground", children: [
|
|
700
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: valueFormatter(min) }),
|
|
701
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: valueFormatter(max) })
|
|
702
|
+
] })
|
|
703
|
+
] }),
|
|
704
|
+
error && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-destructive text-sm mt-1", children: error })
|
|
705
|
+
] });
|
|
706
|
+
};
|
|
707
|
+
var SmartDualRangeSlider = ({
|
|
708
|
+
minField,
|
|
709
|
+
maxField,
|
|
710
|
+
label,
|
|
711
|
+
min = 0,
|
|
712
|
+
max = 100,
|
|
713
|
+
step = 1,
|
|
714
|
+
className = "",
|
|
715
|
+
minValidation,
|
|
716
|
+
maxValidation,
|
|
717
|
+
required = false,
|
|
718
|
+
showValues = true,
|
|
719
|
+
valueFormatter = (value) => value.toString(),
|
|
720
|
+
minLabel = "Min",
|
|
721
|
+
maxLabel = "Max",
|
|
722
|
+
defaultMinValue,
|
|
723
|
+
defaultMaxValue,
|
|
724
|
+
info,
|
|
725
|
+
subLabel
|
|
726
|
+
}) => {
|
|
727
|
+
const minFormField = chunkYV7RVYMD_cjs.useFormField(minField);
|
|
728
|
+
const maxFormField = chunkYV7RVYMD_cjs.useFormField(maxField);
|
|
729
|
+
const fieldDetection = chunkYV7RVYMD_cjs.useFieldDetection();
|
|
730
|
+
const hasRegisteredMin = React.useRef(false);
|
|
731
|
+
const hasRegisteredMax = React.useRef(false);
|
|
732
|
+
const hasSetDefaultMin = React.useRef(false);
|
|
733
|
+
const hasSetDefaultMax = React.useRef(false);
|
|
734
|
+
React.useEffect(() => {
|
|
735
|
+
if (minValidation && !hasRegisteredMin.current) {
|
|
736
|
+
hasRegisteredMin.current = true;
|
|
737
|
+
minFormField.registerValidation(minField, minValidation);
|
|
738
|
+
}
|
|
739
|
+
}, [minValidation, minField, minFormField]);
|
|
740
|
+
React.useEffect(() => {
|
|
741
|
+
if (maxValidation && !hasRegisteredMax.current) {
|
|
742
|
+
hasRegisteredMax.current = true;
|
|
743
|
+
maxFormField.registerValidation(maxField, maxValidation);
|
|
744
|
+
}
|
|
745
|
+
}, [maxValidation, maxField, maxFormField]);
|
|
746
|
+
React.useEffect(() => {
|
|
747
|
+
if (fieldDetection?.registerField) {
|
|
748
|
+
fieldDetection.registerField(minField);
|
|
749
|
+
fieldDetection.registerField(maxField);
|
|
750
|
+
}
|
|
751
|
+
}, [minField, maxField, fieldDetection]);
|
|
752
|
+
React.useEffect(() => {
|
|
753
|
+
if (defaultMinValue !== void 0 && !hasSetDefaultMin.current && (minFormField.value === void 0 || minFormField.value === null || minFormField.value === "")) {
|
|
754
|
+
minFormField.onChange(defaultMinValue);
|
|
755
|
+
hasSetDefaultMin.current = true;
|
|
756
|
+
}
|
|
757
|
+
}, [defaultMinValue, minFormField.value]);
|
|
758
|
+
React.useEffect(() => {
|
|
759
|
+
if (defaultMaxValue !== void 0 && !hasSetDefaultMax.current && (maxFormField.value === void 0 || maxFormField.value === null || maxFormField.value === "")) {
|
|
760
|
+
maxFormField.onChange(defaultMaxValue);
|
|
761
|
+
hasSetDefaultMax.current = true;
|
|
762
|
+
}
|
|
763
|
+
}, [defaultMaxValue, maxFormField.value]);
|
|
764
|
+
const handleValueChange = (values) => {
|
|
765
|
+
const [minValue, maxValue] = values;
|
|
766
|
+
minFormField.onChange(minValue);
|
|
767
|
+
maxFormField.onChange(maxValue);
|
|
768
|
+
};
|
|
769
|
+
const currentMin = minFormField.value !== void 0 ? minFormField.value : min;
|
|
770
|
+
const currentMax = maxFormField.value !== void 0 ? maxFormField.value : max;
|
|
771
|
+
const combinedError = minFormField.error || maxFormField.error;
|
|
772
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex-1 min-w-0 ${className}`, children: [
|
|
773
|
+
label && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-2", children: [
|
|
774
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-2", children: [
|
|
775
|
+
/* @__PURE__ */ jsxRuntime.jsxs(chunkYV7RVYMD_cjs.Label, { className: "text-sm font-medium text-foreground", children: [
|
|
776
|
+
label,
|
|
777
|
+
" ",
|
|
778
|
+
required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-destructive", children: "*" })
|
|
779
|
+
] }),
|
|
780
|
+
info && /* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(chunkYV7RVYMD_cjs.Tooltip, { children: [
|
|
781
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.InfoIcon, { className: "h-4 w-4 text-muted-foreground cursor-pointer mr-2" }) }),
|
|
782
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipContent, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { className: "max-w-xs", children: info }) })
|
|
783
|
+
] }) })
|
|
784
|
+
] }),
|
|
785
|
+
subLabel && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground mt-1", children: subLabel })
|
|
786
|
+
] }),
|
|
787
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4", children: [
|
|
788
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
789
|
+
Slider,
|
|
790
|
+
{
|
|
791
|
+
ref: minFormField.fieldRef,
|
|
792
|
+
value: [currentMin, currentMax],
|
|
793
|
+
onValueChange: handleValueChange,
|
|
794
|
+
min,
|
|
795
|
+
max,
|
|
796
|
+
step,
|
|
797
|
+
className: `w-full ${combinedError ? "border-destructive" : ""}`,
|
|
798
|
+
"data-min-field": minField,
|
|
799
|
+
"data-max-field": maxField
|
|
800
|
+
}
|
|
801
|
+
),
|
|
802
|
+
showValues && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-between items-center text-sm", children: [
|
|
803
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col items-center", children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-muted-foreground", children: [
|
|
804
|
+
minLabel,
|
|
805
|
+
": ",
|
|
806
|
+
valueFormatter(currentMin)
|
|
807
|
+
] }) }),
|
|
808
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col items-center", children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-muted-foreground", children: [
|
|
809
|
+
maxLabel,
|
|
810
|
+
": ",
|
|
811
|
+
valueFormatter(currentMax)
|
|
812
|
+
] }) })
|
|
813
|
+
] })
|
|
814
|
+
] }),
|
|
815
|
+
combinedError && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-destructive text-sm mt-1", children: combinedError })
|
|
816
|
+
] });
|
|
817
|
+
};
|
|
818
|
+
var TagsContext = React.createContext({
|
|
819
|
+
value: void 0,
|
|
820
|
+
setValue: void 0,
|
|
821
|
+
open: false,
|
|
822
|
+
onOpenChange: () => {
|
|
823
|
+
},
|
|
824
|
+
width: void 0,
|
|
825
|
+
setWidth: void 0
|
|
826
|
+
});
|
|
827
|
+
var useTagsContext = () => {
|
|
828
|
+
const context = React.useContext(TagsContext);
|
|
829
|
+
if (!context) {
|
|
830
|
+
throw new Error("useTagsContext must be used within a TagsProvider");
|
|
831
|
+
}
|
|
832
|
+
return context;
|
|
833
|
+
};
|
|
834
|
+
var Tags = ({
|
|
835
|
+
value,
|
|
836
|
+
setValue,
|
|
837
|
+
open: controlledOpen,
|
|
838
|
+
onOpenChange: controlledOnOpenChange,
|
|
839
|
+
children,
|
|
840
|
+
className
|
|
841
|
+
}) => {
|
|
842
|
+
const [uncontrolledOpen, setUncontrolledOpen] = React.useState(false);
|
|
843
|
+
const [width, setWidth] = React.useState();
|
|
844
|
+
const ref = React.useRef(null);
|
|
845
|
+
const open = controlledOpen ?? uncontrolledOpen;
|
|
846
|
+
const onOpenChange = controlledOnOpenChange ?? setUncontrolledOpen;
|
|
847
|
+
React.useEffect(() => {
|
|
848
|
+
if (!ref.current) {
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
852
|
+
setWidth(entries[0].contentRect.width);
|
|
853
|
+
});
|
|
854
|
+
resizeObserver.observe(ref.current);
|
|
855
|
+
return () => {
|
|
856
|
+
resizeObserver.disconnect();
|
|
857
|
+
};
|
|
858
|
+
}, []);
|
|
859
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
860
|
+
TagsContext.Provider,
|
|
861
|
+
{
|
|
862
|
+
value: { value, setValue, open, onOpenChange, width, setWidth },
|
|
863
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(chunkY6NGPMDH_cjs.Popover, { onOpenChange, open, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: chunkYV7RVYMD_cjs.cn("relative w-full", className), ref, children }) })
|
|
864
|
+
}
|
|
865
|
+
);
|
|
866
|
+
};
|
|
867
|
+
var TagsTrigger = ({
|
|
868
|
+
className,
|
|
869
|
+
children,
|
|
870
|
+
...props
|
|
871
|
+
}) => /* @__PURE__ */ jsxRuntime.jsx(chunkY6NGPMDH_cjs.PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
872
|
+
chunkY6NGPMDH_cjs.Button,
|
|
873
|
+
{
|
|
874
|
+
className: chunkYV7RVYMD_cjs.cn("h-auto w-full justify-between p-2", className),
|
|
875
|
+
role: "combobox",
|
|
876
|
+
variant: "outline",
|
|
877
|
+
...props,
|
|
878
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-1", children: [
|
|
879
|
+
children,
|
|
880
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "px-2 py-px text-muted-foreground" })
|
|
881
|
+
] })
|
|
882
|
+
}
|
|
883
|
+
) });
|
|
884
|
+
var TagsValue = ({
|
|
885
|
+
className,
|
|
886
|
+
children,
|
|
887
|
+
onRemove,
|
|
888
|
+
...props
|
|
889
|
+
}) => {
|
|
890
|
+
const handleRemove = (event) => {
|
|
891
|
+
event.preventDefault();
|
|
892
|
+
event.stopPropagation();
|
|
893
|
+
onRemove?.();
|
|
894
|
+
};
|
|
895
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Badge, { className: chunkYV7RVYMD_cjs.cn("flex items-center gap-2", className), ...props, children: [
|
|
896
|
+
children,
|
|
897
|
+
onRemove && // biome-ignore lint/a11y/noStaticElementInteractions: "This is a clickable badge"
|
|
898
|
+
// biome-ignore lint/a11y/useKeyWithClickEvents: "This is a clickable badge"
|
|
899
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
900
|
+
"div",
|
|
901
|
+
{
|
|
902
|
+
className: "size-auto cursor-pointer hover:text-muted-foreground",
|
|
903
|
+
onClick: handleRemove,
|
|
904
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.XIcon, { size: 12 })
|
|
905
|
+
}
|
|
906
|
+
)
|
|
907
|
+
] });
|
|
908
|
+
};
|
|
909
|
+
var TagsContent = ({
|
|
910
|
+
className,
|
|
911
|
+
children,
|
|
912
|
+
...props
|
|
913
|
+
}) => {
|
|
914
|
+
const { width } = useTagsContext();
|
|
915
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
916
|
+
chunkY6NGPMDH_cjs.PopoverContent,
|
|
917
|
+
{
|
|
918
|
+
className: chunkYV7RVYMD_cjs.cn("p-0", className),
|
|
919
|
+
style: { width },
|
|
920
|
+
...props,
|
|
921
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Command, { children })
|
|
922
|
+
}
|
|
923
|
+
);
|
|
924
|
+
};
|
|
925
|
+
var TagsInput = ({ className, ...props }) => /* @__PURE__ */ jsxRuntime.jsx(CommandInput, { className: chunkYV7RVYMD_cjs.cn("h-9", className), ...props });
|
|
926
|
+
var TagsList = ({ className, ...props }) => /* @__PURE__ */ jsxRuntime.jsx(CommandList, { className: chunkYV7RVYMD_cjs.cn("max-h-[200px]", className), ...props });
|
|
927
|
+
var TagsEmpty = ({
|
|
928
|
+
children,
|
|
929
|
+
className,
|
|
930
|
+
...props
|
|
931
|
+
}) => /* @__PURE__ */ jsxRuntime.jsx(CommandEmpty, { ...props, children: children ?? "No tags found." });
|
|
932
|
+
var TagsGroup = CommandGroup;
|
|
933
|
+
var TagsItem = ({ className, ...props }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
934
|
+
CommandItem,
|
|
935
|
+
{
|
|
936
|
+
className: chunkYV7RVYMD_cjs.cn("cursor-pointer items-center justify-between", className),
|
|
937
|
+
...props
|
|
938
|
+
}
|
|
939
|
+
);
|
|
940
|
+
var SmartAutoSuggestTags = ({
|
|
941
|
+
field,
|
|
942
|
+
label,
|
|
943
|
+
options: initialOptions,
|
|
944
|
+
className = "",
|
|
945
|
+
placeholder = "Select tags...",
|
|
946
|
+
validation,
|
|
947
|
+
required = false,
|
|
948
|
+
allowCreate = true,
|
|
949
|
+
maxTags,
|
|
950
|
+
defaultValue,
|
|
951
|
+
onTagCreate,
|
|
952
|
+
info,
|
|
953
|
+
subLabel
|
|
954
|
+
}) => {
|
|
955
|
+
const { value, error, onChange, fieldRef, registerValidation } = chunkYV7RVYMD_cjs.useFormField(field);
|
|
956
|
+
const fieldDetection = chunkYV7RVYMD_cjs.useFieldDetection();
|
|
957
|
+
const hasRegistered = React.useRef(false);
|
|
958
|
+
const hasSetDefault = React.useRef(false);
|
|
959
|
+
const [tags, setTags] = React.useState(initialOptions);
|
|
960
|
+
const [newTag, setNewTag] = React.useState("");
|
|
961
|
+
const selected = Array.isArray(value) ? value : [];
|
|
962
|
+
React.useEffect(() => {
|
|
963
|
+
if (validation && !hasRegistered.current) {
|
|
964
|
+
hasRegistered.current = true;
|
|
965
|
+
registerValidation(field, validation);
|
|
966
|
+
}
|
|
967
|
+
}, [validation, field, registerValidation]);
|
|
968
|
+
React.useEffect(() => {
|
|
969
|
+
if (fieldDetection?.registerField) {
|
|
970
|
+
fieldDetection.registerField(field);
|
|
971
|
+
}
|
|
972
|
+
}, [field, fieldDetection]);
|
|
973
|
+
React.useEffect(() => {
|
|
974
|
+
if (defaultValue !== void 0 && !hasSetDefault.current && (!value || Array.isArray(value) && value.length === 0)) {
|
|
975
|
+
onChange(defaultValue);
|
|
976
|
+
hasSetDefault.current = true;
|
|
977
|
+
}
|
|
978
|
+
}, [defaultValue, value, onChange]);
|
|
979
|
+
React.useEffect(() => {
|
|
980
|
+
setTags(initialOptions);
|
|
981
|
+
}, [initialOptions]);
|
|
982
|
+
const handleRemove = (tagId) => {
|
|
983
|
+
if (!selected.includes(tagId)) {
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
const newSelected = selected.filter((v) => v !== tagId);
|
|
987
|
+
onChange(newSelected);
|
|
988
|
+
};
|
|
989
|
+
const handleSelect = (tagId) => {
|
|
990
|
+
if (selected.includes(tagId)) {
|
|
991
|
+
handleRemove(tagId);
|
|
992
|
+
return;
|
|
993
|
+
}
|
|
994
|
+
if (maxTags && selected.length >= maxTags) {
|
|
995
|
+
return;
|
|
996
|
+
}
|
|
997
|
+
const newSelected = [...selected, tagId];
|
|
998
|
+
onChange(newSelected);
|
|
999
|
+
};
|
|
1000
|
+
const handleCreateTag = () => {
|
|
1001
|
+
if (!newTag.trim()) return;
|
|
1002
|
+
if (!allowCreate) return;
|
|
1003
|
+
const tagId = newTag.toLowerCase().replace(/\s+/g, "-");
|
|
1004
|
+
const newTagOption = {
|
|
1005
|
+
id: tagId,
|
|
1006
|
+
label: newTag
|
|
1007
|
+
};
|
|
1008
|
+
setTags((prev) => [...prev, newTagOption]);
|
|
1009
|
+
const newSelected = [...selected, tagId];
|
|
1010
|
+
onChange(newSelected);
|
|
1011
|
+
if (onTagCreate) {
|
|
1012
|
+
onTagCreate(newTagOption);
|
|
1013
|
+
}
|
|
1014
|
+
setNewTag("");
|
|
1015
|
+
};
|
|
1016
|
+
const filteredTags = tags.filter(
|
|
1017
|
+
(tag) => tag.label.toLowerCase().includes(newTag.toLowerCase())
|
|
1018
|
+
);
|
|
1019
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex-1 min-w-0 ${className}`, children: [
|
|
1020
|
+
label && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-2", children: [
|
|
1021
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-2", children: [
|
|
1022
|
+
/* @__PURE__ */ jsxRuntime.jsxs(chunkYV7RVYMD_cjs.Label, { className: "text-sm font-medium text-foreground", children: [
|
|
1023
|
+
label,
|
|
1024
|
+
" ",
|
|
1025
|
+
required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-destructive", children: "*" }),
|
|
1026
|
+
maxTags && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "ml-2 text-xs text-muted-foreground", children: [
|
|
1027
|
+
"(",
|
|
1028
|
+
selected.length,
|
|
1029
|
+
"/",
|
|
1030
|
+
maxTags,
|
|
1031
|
+
")"
|
|
1032
|
+
] })
|
|
1033
|
+
] }),
|
|
1034
|
+
info && /* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(chunkYV7RVYMD_cjs.Tooltip, { children: [
|
|
1035
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.InfoIcon, { className: "h-4 w-4 text-muted-foreground cursor-pointer mr-2" }) }),
|
|
1036
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipContent, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { className: "max-w-xs", children: info }) })
|
|
1037
|
+
] }) })
|
|
1038
|
+
] }),
|
|
1039
|
+
subLabel && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground mt-1", children: subLabel })
|
|
1040
|
+
] }),
|
|
1041
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { ref: fieldRef, "data-field": field, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: chunkYV7RVYMD_cjs.cn(
|
|
1042
|
+
"w-full rounded-md border border-input bg-background text-sm ring-offset-background",
|
|
1043
|
+
"focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",
|
|
1044
|
+
error && "border-destructive focus-within:ring-destructive"
|
|
1045
|
+
), children: /* @__PURE__ */ jsxRuntime.jsxs(Tags, { className: "w-full", children: [
|
|
1046
|
+
/* @__PURE__ */ jsxRuntime.jsxs(TagsTrigger, { className: "w-full px-3 py-2 border-0 bg-transparent", children: [
|
|
1047
|
+
selected.length === 0 && placeholder && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground text-sm", children: placeholder }),
|
|
1048
|
+
selected.map((tagId) => {
|
|
1049
|
+
const tag = tags.find((t) => t.id === tagId);
|
|
1050
|
+
return tag ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1051
|
+
TagsValue,
|
|
1052
|
+
{
|
|
1053
|
+
onRemove: () => handleRemove(tagId),
|
|
1054
|
+
className: "px-2 py-1 text-sm gap-1",
|
|
1055
|
+
children: tag.label
|
|
1056
|
+
},
|
|
1057
|
+
tagId
|
|
1058
|
+
) : null;
|
|
1059
|
+
})
|
|
1060
|
+
] }),
|
|
1061
|
+
/* @__PURE__ */ jsxRuntime.jsxs(TagsContent, { children: [
|
|
1062
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1063
|
+
TagsInput,
|
|
1064
|
+
{
|
|
1065
|
+
onValueChange: setNewTag,
|
|
1066
|
+
placeholder: `Search ${placeholder.toLowerCase()}...`,
|
|
1067
|
+
value: newTag
|
|
1068
|
+
}
|
|
1069
|
+
),
|
|
1070
|
+
/* @__PURE__ */ jsxRuntime.jsxs(TagsList, { children: [
|
|
1071
|
+
filteredTags.length === 0 && allowCreate && newTag.trim() && /* @__PURE__ */ jsxRuntime.jsx(TagsEmpty, { children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1072
|
+
"button",
|
|
1073
|
+
{
|
|
1074
|
+
className: "mx-auto flex cursor-pointer items-center gap-2 text-sm",
|
|
1075
|
+
onClick: handleCreateTag,
|
|
1076
|
+
type: "button",
|
|
1077
|
+
children: [
|
|
1078
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.PlusIcon, { className: "text-muted-foreground", size: 14 }),
|
|
1079
|
+
"Create new tag: ",
|
|
1080
|
+
newTag
|
|
1081
|
+
]
|
|
1082
|
+
}
|
|
1083
|
+
) }),
|
|
1084
|
+
filteredTags.length === 0 && (!allowCreate || !newTag.trim()) && /* @__PURE__ */ jsxRuntime.jsx(TagsEmpty, { children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-muted-foreground", children: "No tags found" }) }),
|
|
1085
|
+
/* @__PURE__ */ jsxRuntime.jsx(TagsGroup, { children: filteredTags.map((tag) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1086
|
+
TagsItem,
|
|
1087
|
+
{
|
|
1088
|
+
onSelect: handleSelect,
|
|
1089
|
+
value: tag.id,
|
|
1090
|
+
disabled: maxTags ? selected.length >= maxTags && !selected.includes(tag.id) : false,
|
|
1091
|
+
children: [
|
|
1092
|
+
tag.label,
|
|
1093
|
+
selected.includes(tag.id) && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CheckIcon, { className: "text-muted-foreground", size: 14 })
|
|
1094
|
+
]
|
|
1095
|
+
},
|
|
1096
|
+
tag.id
|
|
1097
|
+
)) })
|
|
1098
|
+
] })
|
|
1099
|
+
] })
|
|
1100
|
+
] }) }) }),
|
|
1101
|
+
error && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-destructive text-sm mt-1", children: error })
|
|
1102
|
+
] });
|
|
1103
|
+
};
|
|
1104
|
+
var sanitizeHtml = (html) => {
|
|
1105
|
+
const tempDiv = document.createElement("div");
|
|
1106
|
+
tempDiv.innerHTML = html;
|
|
1107
|
+
const allowedTags = ["P", "STRONG", "B", "EM", "I", "U", "UL", "OL", "LI", "BR", "DIV"];
|
|
1108
|
+
const cleanNode = (node) => {
|
|
1109
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
1110
|
+
return node.cloneNode(false);
|
|
1111
|
+
}
|
|
1112
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
1113
|
+
const element = node;
|
|
1114
|
+
const tagName = element.tagName.toUpperCase();
|
|
1115
|
+
if (tagName === "DIV") {
|
|
1116
|
+
const p = document.createElement("p");
|
|
1117
|
+
Array.from(element.childNodes).forEach((child) => {
|
|
1118
|
+
const cleanedChild = cleanNode(child);
|
|
1119
|
+
if (cleanedChild) p.appendChild(cleanedChild);
|
|
1120
|
+
});
|
|
1121
|
+
return p;
|
|
1122
|
+
}
|
|
1123
|
+
if (!allowedTags.includes(tagName)) {
|
|
1124
|
+
const fragment = document.createDocumentFragment();
|
|
1125
|
+
Array.from(element.childNodes).forEach((child) => {
|
|
1126
|
+
const cleanedChild = cleanNode(child);
|
|
1127
|
+
if (cleanedChild) fragment.appendChild(cleanedChild);
|
|
1128
|
+
});
|
|
1129
|
+
return fragment;
|
|
1130
|
+
}
|
|
1131
|
+
const cleanElement = document.createElement(tagName.toLowerCase());
|
|
1132
|
+
Array.from(element.childNodes).forEach((child) => {
|
|
1133
|
+
const cleanedChild = cleanNode(child);
|
|
1134
|
+
if (cleanedChild) cleanElement.appendChild(cleanedChild);
|
|
1135
|
+
});
|
|
1136
|
+
return cleanElement;
|
|
1137
|
+
}
|
|
1138
|
+
return null;
|
|
1139
|
+
};
|
|
1140
|
+
const cleanedDiv = document.createElement("div");
|
|
1141
|
+
Array.from(tempDiv.childNodes).forEach((child) => {
|
|
1142
|
+
const cleanedChild = cleanNode(child);
|
|
1143
|
+
if (cleanedChild) cleanedDiv.appendChild(cleanedChild);
|
|
1144
|
+
});
|
|
1145
|
+
return cleanedDiv.innerHTML;
|
|
1146
|
+
};
|
|
1147
|
+
var SmartBasicRichTextbox = ({
|
|
1148
|
+
field,
|
|
1149
|
+
label,
|
|
1150
|
+
placeholder = "Enter text...",
|
|
1151
|
+
validation,
|
|
1152
|
+
className = "",
|
|
1153
|
+
required = false,
|
|
1154
|
+
defaultValue,
|
|
1155
|
+
minHeight = "150px",
|
|
1156
|
+
maxHeight = "400px",
|
|
1157
|
+
info,
|
|
1158
|
+
subLabel
|
|
1159
|
+
}) => {
|
|
1160
|
+
const { value, error, onChange, fieldRef, registerValidation } = chunkYV7RVYMD_cjs.useFormField(field);
|
|
1161
|
+
const fieldDetection = chunkYV7RVYMD_cjs.useFieldDetection();
|
|
1162
|
+
const hasRegistered = React.useRef(false);
|
|
1163
|
+
const hasSetDefault = React.useRef(false);
|
|
1164
|
+
const editorRef = React.useRef(null);
|
|
1165
|
+
const [isFocused, setIsFocused] = React.useState(false);
|
|
1166
|
+
React.useEffect(() => {
|
|
1167
|
+
if (validation && !hasRegistered.current) {
|
|
1168
|
+
hasRegistered.current = true;
|
|
1169
|
+
registerValidation(field, validation);
|
|
1170
|
+
}
|
|
1171
|
+
}, [validation, field, registerValidation]);
|
|
1172
|
+
React.useEffect(() => {
|
|
1173
|
+
if (fieldDetection?.registerField) {
|
|
1174
|
+
fieldDetection.registerField(field);
|
|
1175
|
+
}
|
|
1176
|
+
}, [field, fieldDetection]);
|
|
1177
|
+
React.useEffect(() => {
|
|
1178
|
+
if (defaultValue !== void 0 && !hasSetDefault.current && (value === void 0 || value === null || value === "")) {
|
|
1179
|
+
onChange(defaultValue);
|
|
1180
|
+
hasSetDefault.current = true;
|
|
1181
|
+
}
|
|
1182
|
+
}, [defaultValue, value, onChange]);
|
|
1183
|
+
React.useEffect(() => {
|
|
1184
|
+
if (editorRef.current && value !== void 0) {
|
|
1185
|
+
const sanitized = sanitizeHtml(value || "");
|
|
1186
|
+
if (editorRef.current.innerHTML !== sanitized) {
|
|
1187
|
+
editorRef.current.innerHTML = sanitized;
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
}, [value]);
|
|
1191
|
+
const handleInput = React.useCallback(() => {
|
|
1192
|
+
if (editorRef.current) {
|
|
1193
|
+
const html = editorRef.current.innerHTML;
|
|
1194
|
+
const sanitized = sanitizeHtml(html);
|
|
1195
|
+
onChange(sanitized);
|
|
1196
|
+
}
|
|
1197
|
+
}, [onChange]);
|
|
1198
|
+
const handleKeyDown = React.useCallback((e) => {
|
|
1199
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
1200
|
+
e.preventDefault();
|
|
1201
|
+
document.execCommand("insertParagraph", false);
|
|
1202
|
+
return;
|
|
1203
|
+
}
|
|
1204
|
+
}, []);
|
|
1205
|
+
const execCommand = React.useCallback((command, value2) => {
|
|
1206
|
+
document.execCommand(command, false, value2);
|
|
1207
|
+
editorRef.current?.focus();
|
|
1208
|
+
handleInput();
|
|
1209
|
+
}, [handleInput]);
|
|
1210
|
+
const toggleBold = () => execCommand("bold");
|
|
1211
|
+
const toggleItalic = () => execCommand("italic");
|
|
1212
|
+
const toggleUnderline = () => execCommand("underline");
|
|
1213
|
+
const toggleBulletList = () => execCommand("insertUnorderedList");
|
|
1214
|
+
const toggleNumberedList = () => execCommand("insertOrderedList");
|
|
1215
|
+
const isFormatActive = React.useCallback((format) => {
|
|
1216
|
+
return document.queryCommandState(format);
|
|
1217
|
+
}, []);
|
|
1218
|
+
const [activeFormats, setActiveFormats] = React.useState({
|
|
1219
|
+
bold: false,
|
|
1220
|
+
italic: false,
|
|
1221
|
+
underline: false,
|
|
1222
|
+
bulletList: false,
|
|
1223
|
+
numberedList: false
|
|
1224
|
+
});
|
|
1225
|
+
const updateActiveFormats = React.useCallback(() => {
|
|
1226
|
+
if (isFocused) {
|
|
1227
|
+
setActiveFormats({
|
|
1228
|
+
bold: isFormatActive("bold"),
|
|
1229
|
+
italic: isFormatActive("italic"),
|
|
1230
|
+
underline: isFormatActive("underline"),
|
|
1231
|
+
bulletList: isFormatActive("insertUnorderedList"),
|
|
1232
|
+
numberedList: isFormatActive("insertOrderedList")
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1235
|
+
}, [isFocused, isFormatActive]);
|
|
1236
|
+
React.useEffect(() => {
|
|
1237
|
+
if (isFocused) {
|
|
1238
|
+
document.addEventListener("selectionchange", updateActiveFormats);
|
|
1239
|
+
return () => document.removeEventListener("selectionchange", updateActiveFormats);
|
|
1240
|
+
}
|
|
1241
|
+
}, [isFocused, updateActiveFormats]);
|
|
1242
|
+
const handleFocus = () => {
|
|
1243
|
+
setIsFocused(true);
|
|
1244
|
+
updateActiveFormats();
|
|
1245
|
+
};
|
|
1246
|
+
const handleBlur = () => {
|
|
1247
|
+
setIsFocused(false);
|
|
1248
|
+
};
|
|
1249
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: chunkYV7RVYMD_cjs.cn("flex-1 min-w-0", className), children: [
|
|
1250
|
+
label && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-2", children: [
|
|
1251
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-2", children: [
|
|
1252
|
+
/* @__PURE__ */ jsxRuntime.jsxs(chunkYV7RVYMD_cjs.Label, { className: "text-sm font-medium text-foreground", children: [
|
|
1253
|
+
label,
|
|
1254
|
+
" ",
|
|
1255
|
+
required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-destructive", children: "*" })
|
|
1256
|
+
] }),
|
|
1257
|
+
info && /* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(chunkYV7RVYMD_cjs.Tooltip, { children: [
|
|
1258
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.InfoIcon, { className: "h-4 w-4 text-muted-foreground cursor-pointer mr-2" }) }),
|
|
1259
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipContent, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { className: "max-w-xs", children: info }) })
|
|
1260
|
+
] }) })
|
|
1261
|
+
] }),
|
|
1262
|
+
subLabel && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground mt-1", children: subLabel })
|
|
1263
|
+
] }),
|
|
1264
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1265
|
+
"div",
|
|
1266
|
+
{
|
|
1267
|
+
ref: fieldRef,
|
|
1268
|
+
"data-field": field,
|
|
1269
|
+
className: chunkYV7RVYMD_cjs.cn(
|
|
1270
|
+
"w-full rounded-md border border-input bg-background",
|
|
1271
|
+
"focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",
|
|
1272
|
+
error && "border-destructive focus-within:ring-destructive"
|
|
1273
|
+
),
|
|
1274
|
+
children: [
|
|
1275
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-0.5 p-1.5 border-b border-border bg-muted/30", children: [
|
|
1276
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(chunkYV7RVYMD_cjs.Tooltip, { children: [
|
|
1277
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1278
|
+
chunkY6NGPMDH_cjs.Button,
|
|
1279
|
+
{
|
|
1280
|
+
type: "button",
|
|
1281
|
+
variant: "ghost",
|
|
1282
|
+
size: "sm",
|
|
1283
|
+
className: chunkYV7RVYMD_cjs.cn(
|
|
1284
|
+
"h-8 w-8 p-0 hover:bg-accent hover:text-accent-foreground",
|
|
1285
|
+
activeFormats.bold && "bg-primary text-primary-foreground hover:bg-primary/90"
|
|
1286
|
+
),
|
|
1287
|
+
onClick: toggleBold,
|
|
1288
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Bold, { className: "h-4 w-4" })
|
|
1289
|
+
}
|
|
1290
|
+
) }),
|
|
1291
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipContent, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Bold (Ctrl+B)" }) })
|
|
1292
|
+
] }) }),
|
|
1293
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(chunkYV7RVYMD_cjs.Tooltip, { children: [
|
|
1294
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1295
|
+
chunkY6NGPMDH_cjs.Button,
|
|
1296
|
+
{
|
|
1297
|
+
type: "button",
|
|
1298
|
+
variant: "ghost",
|
|
1299
|
+
size: "sm",
|
|
1300
|
+
className: chunkYV7RVYMD_cjs.cn(
|
|
1301
|
+
"h-8 w-8 p-0 hover:bg-accent hover:text-accent-foreground",
|
|
1302
|
+
activeFormats.italic && "bg-primary text-primary-foreground hover:bg-primary/90"
|
|
1303
|
+
),
|
|
1304
|
+
onClick: toggleItalic,
|
|
1305
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Italic, { className: "h-4 w-4" })
|
|
1306
|
+
}
|
|
1307
|
+
) }),
|
|
1308
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipContent, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Italic (Ctrl+I)" }) })
|
|
1309
|
+
] }) }),
|
|
1310
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(chunkYV7RVYMD_cjs.Tooltip, { children: [
|
|
1311
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1312
|
+
chunkY6NGPMDH_cjs.Button,
|
|
1313
|
+
{
|
|
1314
|
+
type: "button",
|
|
1315
|
+
variant: "ghost",
|
|
1316
|
+
size: "sm",
|
|
1317
|
+
className: chunkYV7RVYMD_cjs.cn(
|
|
1318
|
+
"h-8 w-8 p-0 hover:bg-accent hover:text-accent-foreground",
|
|
1319
|
+
activeFormats.underline && "bg-primary text-primary-foreground hover:bg-primary/90"
|
|
1320
|
+
),
|
|
1321
|
+
onClick: toggleUnderline,
|
|
1322
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Underline, { className: "h-4 w-4" })
|
|
1323
|
+
}
|
|
1324
|
+
) }),
|
|
1325
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipContent, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Underline (Ctrl+U)" }) })
|
|
1326
|
+
] }) }),
|
|
1327
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-px h-5 bg-border mx-1" }),
|
|
1328
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(chunkYV7RVYMD_cjs.Tooltip, { children: [
|
|
1329
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1330
|
+
chunkY6NGPMDH_cjs.Button,
|
|
1331
|
+
{
|
|
1332
|
+
type: "button",
|
|
1333
|
+
variant: "ghost",
|
|
1334
|
+
size: "sm",
|
|
1335
|
+
className: chunkYV7RVYMD_cjs.cn(
|
|
1336
|
+
"h-8 w-8 p-0 hover:bg-accent hover:text-accent-foreground",
|
|
1337
|
+
activeFormats.bulletList && "bg-primary text-primary-foreground hover:bg-primary/90"
|
|
1338
|
+
),
|
|
1339
|
+
onClick: toggleBulletList,
|
|
1340
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.List, { className: "h-4 w-4" })
|
|
1341
|
+
}
|
|
1342
|
+
) }),
|
|
1343
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipContent, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Bullet List" }) })
|
|
1344
|
+
] }) }),
|
|
1345
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(chunkYV7RVYMD_cjs.Tooltip, { children: [
|
|
1346
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1347
|
+
chunkY6NGPMDH_cjs.Button,
|
|
1348
|
+
{
|
|
1349
|
+
type: "button",
|
|
1350
|
+
variant: "ghost",
|
|
1351
|
+
size: "sm",
|
|
1352
|
+
className: chunkYV7RVYMD_cjs.cn(
|
|
1353
|
+
"h-8 w-8 p-0 hover:bg-accent hover:text-accent-foreground",
|
|
1354
|
+
activeFormats.numberedList && "bg-primary text-primary-foreground hover:bg-primary/90"
|
|
1355
|
+
),
|
|
1356
|
+
onClick: toggleNumberedList,
|
|
1357
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ListOrdered, { className: "h-4 w-4" })
|
|
1358
|
+
}
|
|
1359
|
+
) }),
|
|
1360
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYV7RVYMD_cjs.TooltipContent, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Numbered List" }) })
|
|
1361
|
+
] }) })
|
|
1362
|
+
] }),
|
|
1363
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1364
|
+
"div",
|
|
1365
|
+
{
|
|
1366
|
+
ref: editorRef,
|
|
1367
|
+
contentEditable: true,
|
|
1368
|
+
onInput: handleInput,
|
|
1369
|
+
onKeyDown: handleKeyDown,
|
|
1370
|
+
onFocus: handleFocus,
|
|
1371
|
+
onBlur: handleBlur,
|
|
1372
|
+
className: chunkYV7RVYMD_cjs.cn(
|
|
1373
|
+
"w-full px-3 py-2 text-sm text-foreground",
|
|
1374
|
+
"bg-background",
|
|
1375
|
+
"focus:outline-none",
|
|
1376
|
+
"overflow-y-auto",
|
|
1377
|
+
"[&>p]:my-2 [&>p]:leading-relaxed",
|
|
1378
|
+
"[&>ul]:my-2 [&>ul]:ml-6 [&>ul]:list-disc [&>ul]:list-inside",
|
|
1379
|
+
"[&_ul]:my-2 [&_ul]:ml-6 [&_ul]:list-disc [&_ul]:list-inside",
|
|
1380
|
+
"[&>ol]:my-2 [&>ol]:ml-6 [&>ol]:list-decimal [&>ol]:list-inside",
|
|
1381
|
+
"[&_ol]:my-2 [&_ol]:ml-6 [&_ol]:list-decimal [&_ol]:list-inside",
|
|
1382
|
+
"[&>li]:my-1 [&_li]:my-1",
|
|
1383
|
+
"[&_strong]:font-semibold [&_b]:font-semibold",
|
|
1384
|
+
"[&_em]:italic [&_i]:italic",
|
|
1385
|
+
"[&_u]:underline",
|
|
1386
|
+
!value && "empty:before:content-[attr(data-placeholder)] empty:before:text-muted-foreground empty:before:pointer-events-none"
|
|
1387
|
+
),
|
|
1388
|
+
style: {
|
|
1389
|
+
minHeight,
|
|
1390
|
+
maxHeight
|
|
1391
|
+
},
|
|
1392
|
+
"data-placeholder": placeholder
|
|
1393
|
+
}
|
|
1394
|
+
)
|
|
1395
|
+
]
|
|
1396
|
+
}
|
|
1397
|
+
),
|
|
1398
|
+
error && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-destructive text-sm mt-1", children: error })
|
|
1399
|
+
] });
|
|
1400
|
+
};
|
|
1401
|
+
|
|
1402
|
+
Object.defineProperty(exports, "SmartCheckbox", {
|
|
1403
|
+
enumerable: true,
|
|
1404
|
+
get: function () { return chunkY6NGPMDH_cjs.SmartCheckbox; }
|
|
1405
|
+
});
|
|
1406
|
+
Object.defineProperty(exports, "SmartDatePicker", {
|
|
1407
|
+
enumerable: true,
|
|
1408
|
+
get: function () { return chunkY6NGPMDH_cjs.SmartDatePicker; }
|
|
1409
|
+
});
|
|
1410
|
+
Object.defineProperty(exports, "SmartRadioGroup", {
|
|
1411
|
+
enumerable: true,
|
|
1412
|
+
get: function () { return chunkY6NGPMDH_cjs.SmartRadioGroup; }
|
|
1413
|
+
});
|
|
1414
|
+
Object.defineProperty(exports, "SmartSelect", {
|
|
1415
|
+
enumerable: true,
|
|
1416
|
+
get: function () { return chunkY6NGPMDH_cjs.SmartSelect; }
|
|
1417
|
+
});
|
|
1418
|
+
Object.defineProperty(exports, "SmartTags", {
|
|
1419
|
+
enumerable: true,
|
|
1420
|
+
get: function () { return chunkY6NGPMDH_cjs.SmartTags; }
|
|
1421
|
+
});
|
|
1422
|
+
Object.defineProperty(exports, "SmartFormProvider", {
|
|
1423
|
+
enumerable: true,
|
|
1424
|
+
get: function () { return chunkYV7RVYMD_cjs.SmartFormProvider; }
|
|
1425
|
+
});
|
|
1426
|
+
Object.defineProperty(exports, "SmartInput", {
|
|
1427
|
+
enumerable: true,
|
|
1428
|
+
get: function () { return chunkYV7RVYMD_cjs.SmartInput; }
|
|
1429
|
+
});
|
|
1430
|
+
Object.defineProperty(exports, "useFormField", {
|
|
1431
|
+
enumerable: true,
|
|
1432
|
+
get: function () { return chunkYV7RVYMD_cjs.useFormField; }
|
|
1433
|
+
});
|
|
1434
|
+
Object.defineProperty(exports, "useSmartForm", {
|
|
1435
|
+
enumerable: true,
|
|
1436
|
+
get: function () { return chunkYV7RVYMD_cjs.useSmartForm; }
|
|
1437
|
+
});
|
|
1438
|
+
exports.SmartAutoSuggestTags = SmartAutoSuggestTags;
|
|
1439
|
+
exports.SmartBasicRichTextbox = SmartBasicRichTextbox;
|
|
1440
|
+
exports.SmartCombobox = SmartCombobox;
|
|
1441
|
+
exports.SmartDualRangeSlider = SmartDualRangeSlider;
|
|
1442
|
+
exports.SmartFileUpload = SmartFileUpload;
|
|
1443
|
+
exports.SmartSlider = SmartSlider;
|
|
1444
|
+
//# sourceMappingURL=fields.cjs.map
|
|
1445
|
+
//# sourceMappingURL=fields.cjs.map
|