@algodomain/smart-forms 0.1.2 → 0.1.4
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/LICENSE +3 -0
- package/README.md +243 -0
- package/dist/{SmartFormProvider-DyJoDBjQ.d.cts → SmartFormProvider-BdyRQakk.d.cts} +1 -0
- package/dist/{SmartFormProvider-DyJoDBjQ.d.ts → SmartFormProvider-BdyRQakk.d.ts} +1 -0
- package/dist/{SmartTags-HmvmCJPT.d.cts → SmartTags-DEpmTDF5.d.cts} +42 -18
- package/dist/{SmartTags-HmvmCJPT.d.ts → SmartTags-DEpmTDF5.d.ts} +42 -18
- package/dist/{chunk-KDPN4CHW.js → chunk-BNQNL7GF.js} +658 -145
- package/dist/chunk-BNQNL7GF.js.map +1 -0
- package/dist/{chunk-5LRBJEZW.js → chunk-RHECLW3K.js} +80 -7
- package/dist/chunk-RHECLW3K.js.map +1 -0
- package/dist/{chunk-CJ55WKPC.cjs → chunk-VGP3HY5Y.cjs} +758 -235
- package/dist/chunk-VGP3HY5Y.cjs.map +1 -0
- package/dist/{chunk-4H5U5IHH.cjs → chunk-WIBCOQPP.cjs} +80 -7
- package/dist/chunk-WIBCOQPP.cjs.map +1 -0
- package/dist/fields.cjs +212 -481
- package/dist/fields.cjs.map +1 -1
- package/dist/fields.d.cts +14 -22
- package/dist/fields.d.ts +14 -22
- package/dist/fields.js +66 -338
- package/dist/fields.js.map +1 -1
- package/dist/index.cjs +42 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +17 -9
- package/dist/index.js.map +1 -1
- package/dist/opinionated.cjs +18 -18
- package/dist/opinionated.d.cts +1 -1
- package/dist/opinionated.d.ts +1 -1
- package/dist/opinionated.js +2 -2
- package/package.json +4 -2
- package/dist/chunk-4H5U5IHH.cjs.map +0 -1
- package/dist/chunk-5LRBJEZW.js.map +0 -1
- package/dist/chunk-CJ55WKPC.cjs.map +0 -1
- package/dist/chunk-KDPN4CHW.js.map +0 -1
package/dist/fields.js
CHANGED
|
@@ -1,326 +1,13 @@
|
|
|
1
|
-
import { Button, Popover, PopoverTrigger, PopoverContent } from './chunk-
|
|
2
|
-
export { SmartCheckbox, SmartDatePicker, SmartRadioGroup, SmartSelect, SmartTags } from './chunk-
|
|
3
|
-
import { useFormField, useFieldDetection, Label, TooltipProvider, Tooltip, TooltipTrigger, TooltipContent,
|
|
4
|
-
export { SmartFormProvider, SmartInput, useFormField, useSmartForm } from './chunk-
|
|
5
|
-
import * as
|
|
6
|
-
import
|
|
7
|
-
import { InfoIcon, PlusIcon, CheckIcon, Bold, Italic, Underline, List, ListOrdered,
|
|
8
|
-
import { Command as Command$1 } from 'cmdk';
|
|
1
|
+
import { Button, CommandGroup, Popover, PopoverTrigger, Badge, PopoverContent, Command, CommandInput, CommandList, CommandEmpty, CommandItem } from './chunk-BNQNL7GF.js';
|
|
2
|
+
export { SmartCheckbox, SmartCombobox, SmartDatePicker, SmartRadioGroup, SmartSelect, SmartTags } from './chunk-BNQNL7GF.js';
|
|
3
|
+
import { useSmartForm, useFormField, useFieldDetection, cn, Label, TooltipProvider, Tooltip, TooltipTrigger, TooltipContent, Input } from './chunk-RHECLW3K.js';
|
|
4
|
+
export { SmartFormProvider, SmartInput, useFormField, useSmartForm } from './chunk-RHECLW3K.js';
|
|
5
|
+
import * as React2 from 'react';
|
|
6
|
+
import { createContext, useRef, useEffect, useMemo, useState, useCallback, useContext } from 'react';
|
|
7
|
+
import { InfoIcon, PlusIcon, CheckIcon, Bold, Italic, Underline, List, ListOrdered, XIcon } from 'lucide-react';
|
|
9
8
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
10
|
-
import { Slot } from '@radix-ui/react-slot';
|
|
11
|
-
import { cva } from 'class-variance-authority';
|
|
12
9
|
import * as SliderPrimitive from '@radix-ui/react-slider';
|
|
13
10
|
|
|
14
|
-
function Command({
|
|
15
|
-
className,
|
|
16
|
-
...props
|
|
17
|
-
}) {
|
|
18
|
-
return /* @__PURE__ */ jsx(
|
|
19
|
-
Command$1,
|
|
20
|
-
{
|
|
21
|
-
"data-slot": "command",
|
|
22
|
-
className: cn(
|
|
23
|
-
"bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md",
|
|
24
|
-
className
|
|
25
|
-
),
|
|
26
|
-
...props
|
|
27
|
-
}
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
function CommandInput({
|
|
31
|
-
className,
|
|
32
|
-
...props
|
|
33
|
-
}) {
|
|
34
|
-
return /* @__PURE__ */ jsxs(
|
|
35
|
-
"div",
|
|
36
|
-
{
|
|
37
|
-
"data-slot": "command-input-wrapper",
|
|
38
|
-
className: "flex h-9 items-center gap-2 border-b px-3",
|
|
39
|
-
children: [
|
|
40
|
-
/* @__PURE__ */ jsx(SearchIcon, { className: "size-4 shrink-0 opacity-50" }),
|
|
41
|
-
/* @__PURE__ */ jsx(
|
|
42
|
-
Command$1.Input,
|
|
43
|
-
{
|
|
44
|
-
"data-slot": "command-input",
|
|
45
|
-
className: cn(
|
|
46
|
-
"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",
|
|
47
|
-
className
|
|
48
|
-
),
|
|
49
|
-
...props
|
|
50
|
-
}
|
|
51
|
-
)
|
|
52
|
-
]
|
|
53
|
-
}
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
function CommandList({
|
|
57
|
-
className,
|
|
58
|
-
...props
|
|
59
|
-
}) {
|
|
60
|
-
return /* @__PURE__ */ jsx(
|
|
61
|
-
Command$1.List,
|
|
62
|
-
{
|
|
63
|
-
"data-slot": "command-list",
|
|
64
|
-
className: cn(
|
|
65
|
-
"max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",
|
|
66
|
-
className
|
|
67
|
-
),
|
|
68
|
-
...props
|
|
69
|
-
}
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
function CommandEmpty({
|
|
73
|
-
...props
|
|
74
|
-
}) {
|
|
75
|
-
return /* @__PURE__ */ jsx(
|
|
76
|
-
Command$1.Empty,
|
|
77
|
-
{
|
|
78
|
-
"data-slot": "command-empty",
|
|
79
|
-
className: "py-6 text-center text-sm",
|
|
80
|
-
...props
|
|
81
|
-
}
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
function CommandGroup({
|
|
85
|
-
className,
|
|
86
|
-
...props
|
|
87
|
-
}) {
|
|
88
|
-
return /* @__PURE__ */ jsx(
|
|
89
|
-
Command$1.Group,
|
|
90
|
-
{
|
|
91
|
-
"data-slot": "command-group",
|
|
92
|
-
className: cn(
|
|
93
|
-
"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",
|
|
94
|
-
className
|
|
95
|
-
),
|
|
96
|
-
...props
|
|
97
|
-
}
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
function CommandItem({
|
|
101
|
-
className,
|
|
102
|
-
...props
|
|
103
|
-
}) {
|
|
104
|
-
return /* @__PURE__ */ jsx(
|
|
105
|
-
Command$1.Item,
|
|
106
|
-
{
|
|
107
|
-
"data-slot": "command-item",
|
|
108
|
-
className: cn(
|
|
109
|
-
"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",
|
|
110
|
-
className
|
|
111
|
-
),
|
|
112
|
-
...props
|
|
113
|
-
}
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
var badgeVariants = cva(
|
|
117
|
-
"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",
|
|
118
|
-
{
|
|
119
|
-
variants: {
|
|
120
|
-
variant: {
|
|
121
|
-
default: "border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
|
|
122
|
-
secondary: "border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
|
|
123
|
-
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",
|
|
124
|
-
outline: "text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground"
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
defaultVariants: {
|
|
128
|
-
variant: "default"
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
);
|
|
132
|
-
function Badge({
|
|
133
|
-
className,
|
|
134
|
-
variant,
|
|
135
|
-
asChild = false,
|
|
136
|
-
...props
|
|
137
|
-
}) {
|
|
138
|
-
const Comp = asChild ? Slot : "span";
|
|
139
|
-
return /* @__PURE__ */ jsx(
|
|
140
|
-
Comp,
|
|
141
|
-
{
|
|
142
|
-
"data-slot": "badge",
|
|
143
|
-
className: cn(badgeVariants({ variant }), className),
|
|
144
|
-
...props
|
|
145
|
-
}
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
function Combobox({
|
|
149
|
-
options,
|
|
150
|
-
value = "",
|
|
151
|
-
onChange,
|
|
152
|
-
placeholder = "Select option...",
|
|
153
|
-
searchPlaceholder = "Search...",
|
|
154
|
-
noResultsText = "No results found.",
|
|
155
|
-
width = "100%",
|
|
156
|
-
isDisabled = false,
|
|
157
|
-
allowCustom = false
|
|
158
|
-
}) {
|
|
159
|
-
const [open, setOpen] = React__default.useState(false);
|
|
160
|
-
const [searchValue, setSearchValue] = useState("");
|
|
161
|
-
const containerStyles = {
|
|
162
|
-
width
|
|
163
|
-
};
|
|
164
|
-
const combinedOptions = allowCustom ? [
|
|
165
|
-
...options,
|
|
166
|
-
...searchValue && !options.some(
|
|
167
|
-
(opt) => opt.label.toLowerCase() === searchValue.toLowerCase()
|
|
168
|
-
) ? [
|
|
169
|
-
{
|
|
170
|
-
value: searchValue.toLowerCase().replace(/\s+/g, "-"),
|
|
171
|
-
label: searchValue
|
|
172
|
-
}
|
|
173
|
-
] : []
|
|
174
|
-
] : options;
|
|
175
|
-
const filteredOptions = combinedOptions.filter(
|
|
176
|
-
(option) => option.label.toLowerCase().includes(searchValue.toLowerCase())
|
|
177
|
-
);
|
|
178
|
-
return /* @__PURE__ */ jsx("div", { style: containerStyles, children: /* @__PURE__ */ jsxs(Popover, { open, onOpenChange: setOpen, children: [
|
|
179
|
-
/* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
|
|
180
|
-
Button,
|
|
181
|
-
{
|
|
182
|
-
variant: "outline",
|
|
183
|
-
role: "combobox",
|
|
184
|
-
"aria-expanded": open,
|
|
185
|
-
style: containerStyles,
|
|
186
|
-
className: `flex items-center justify-between relative ${isDisabled ? "cursor-not-allowed opacity-50" : ""}`,
|
|
187
|
-
disabled: isDisabled,
|
|
188
|
-
children: [
|
|
189
|
-
/* @__PURE__ */ jsx("div", { className: "flex-1 min-w-0 text-left", children: /* @__PURE__ */ jsx("div", { className: "truncate", children: value ? combinedOptions.find((option) => option.value === value)?.label || value : placeholder }) }),
|
|
190
|
-
/* @__PURE__ */ jsx(ChevronsUpDown, { className: "ml-2 h-4 w-4 flex-shrink-0 opacity-50" })
|
|
191
|
-
]
|
|
192
|
-
}
|
|
193
|
-
) }),
|
|
194
|
-
/* @__PURE__ */ jsx(PopoverContent, { className: "w-[var(--radix-popover-trigger-width)] p-0", children: /* @__PURE__ */ jsxs(Command, { className: "w-full", children: [
|
|
195
|
-
/* @__PURE__ */ jsx(
|
|
196
|
-
CommandInput,
|
|
197
|
-
{
|
|
198
|
-
value: searchValue,
|
|
199
|
-
onValueChange: setSearchValue,
|
|
200
|
-
placeholder: searchPlaceholder,
|
|
201
|
-
className: "h-9"
|
|
202
|
-
}
|
|
203
|
-
),
|
|
204
|
-
/* @__PURE__ */ jsx(CommandList, { children: filteredOptions.length > 0 ? /* @__PURE__ */ jsx(CommandGroup, { className: "max-h-[200px] overflow-y-auto", children: filteredOptions.map((option) => /* @__PURE__ */ jsxs(
|
|
205
|
-
CommandItem,
|
|
206
|
-
{
|
|
207
|
-
value: option.value,
|
|
208
|
-
onSelect: (currentValue) => {
|
|
209
|
-
onChange(currentValue === value ? "" : currentValue);
|
|
210
|
-
setOpen(false);
|
|
211
|
-
setSearchValue("");
|
|
212
|
-
},
|
|
213
|
-
className: "flex items-center",
|
|
214
|
-
style: { width: "100%" },
|
|
215
|
-
children: [
|
|
216
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center w-full min-w-0", children: [
|
|
217
|
-
/* @__PURE__ */ jsx(
|
|
218
|
-
Check,
|
|
219
|
-
{
|
|
220
|
-
className: `mr-2 h-4 w-4 flex-shrink-0 ${value === option.value ? "opacity-100" : "opacity-0"}`
|
|
221
|
-
}
|
|
222
|
-
),
|
|
223
|
-
/* @__PURE__ */ jsx("span", { className: "truncate flex-1", children: option.label })
|
|
224
|
-
] }),
|
|
225
|
-
option.badge && /* @__PURE__ */ jsx(
|
|
226
|
-
Badge,
|
|
227
|
-
{
|
|
228
|
-
variant: "outline",
|
|
229
|
-
className: "ml-2 text-[10px] px-2 py-0 h-5 font-normal",
|
|
230
|
-
children: option.badge
|
|
231
|
-
}
|
|
232
|
-
)
|
|
233
|
-
]
|
|
234
|
-
},
|
|
235
|
-
option.value
|
|
236
|
-
)) }) : /* @__PURE__ */ jsxs(CommandEmpty, { children: [
|
|
237
|
-
allowCustom && searchValue && /* @__PURE__ */ jsxs(
|
|
238
|
-
Button,
|
|
239
|
-
{
|
|
240
|
-
variant: "ghost",
|
|
241
|
-
className: "w-full justify-start",
|
|
242
|
-
onClick: () => {
|
|
243
|
-
const newOption = {
|
|
244
|
-
value: searchValue.toLowerCase().replace(/\s+/g, "-")};
|
|
245
|
-
onChange(newOption.value);
|
|
246
|
-
setOpen(false);
|
|
247
|
-
setSearchValue("");
|
|
248
|
-
},
|
|
249
|
-
children: [
|
|
250
|
-
/* @__PURE__ */ jsx(Plus, { className: "mr-2 h-4 w-4" }),
|
|
251
|
-
'Add "',
|
|
252
|
-
searchValue,
|
|
253
|
-
'" as a new option'
|
|
254
|
-
]
|
|
255
|
-
}
|
|
256
|
-
),
|
|
257
|
-
!searchValue && noResultsText
|
|
258
|
-
] }) })
|
|
259
|
-
] }) })
|
|
260
|
-
] }) });
|
|
261
|
-
}
|
|
262
|
-
var SmartCombobox = ({
|
|
263
|
-
field,
|
|
264
|
-
label,
|
|
265
|
-
options,
|
|
266
|
-
className = "",
|
|
267
|
-
placeholder,
|
|
268
|
-
allowCustom = false,
|
|
269
|
-
validation,
|
|
270
|
-
required = false,
|
|
271
|
-
defaultValue,
|
|
272
|
-
info,
|
|
273
|
-
subLabel
|
|
274
|
-
}) => {
|
|
275
|
-
const { value, error, onChange, fieldRef, registerValidation } = useFormField(field);
|
|
276
|
-
const fieldDetection = useFieldDetection();
|
|
277
|
-
const hasRegistered = useRef(false);
|
|
278
|
-
const hasSetDefault = useRef(false);
|
|
279
|
-
useEffect(() => {
|
|
280
|
-
if (validation && !hasRegistered.current) {
|
|
281
|
-
hasRegistered.current = true;
|
|
282
|
-
registerValidation(field, validation);
|
|
283
|
-
}
|
|
284
|
-
}, [validation, field, registerValidation]);
|
|
285
|
-
useEffect(() => {
|
|
286
|
-
if (fieldDetection?.registerField) {
|
|
287
|
-
fieldDetection.registerField(field);
|
|
288
|
-
}
|
|
289
|
-
}, [field, fieldDetection]);
|
|
290
|
-
useEffect(() => {
|
|
291
|
-
if (defaultValue !== void 0 && !hasSetDefault.current && (value === void 0 || value === null || value === "")) {
|
|
292
|
-
onChange(defaultValue);
|
|
293
|
-
hasSetDefault.current = true;
|
|
294
|
-
}
|
|
295
|
-
}, [defaultValue, value, onChange]);
|
|
296
|
-
return /* @__PURE__ */ jsxs("div", { className: `flex-1 min-w-0 ${className}`, children: [
|
|
297
|
-
label && /* @__PURE__ */ jsxs("div", { className: "mb-2", children: [
|
|
298
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
|
|
299
|
-
/* @__PURE__ */ jsxs(Label, { className: "text-sm font-medium text-foreground", children: [
|
|
300
|
-
label,
|
|
301
|
-
" ",
|
|
302
|
-
required && /* @__PURE__ */ jsx("span", { className: "text-destructive", children: "*" })
|
|
303
|
-
] }),
|
|
304
|
-
info && /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
305
|
-
/* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(InfoIcon, { className: "h-4 w-4 text-muted-foreground cursor-pointer mr-2" }) }),
|
|
306
|
-
/* @__PURE__ */ jsx(TooltipContent, { children: /* @__PURE__ */ jsx("p", { className: "max-w-xs", children: info }) })
|
|
307
|
-
] }) })
|
|
308
|
-
] }),
|
|
309
|
-
subLabel && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-1", children: subLabel })
|
|
310
|
-
] }),
|
|
311
|
-
/* @__PURE__ */ jsx("div", { ref: fieldRef, "data-field": field, children: /* @__PURE__ */ jsx(
|
|
312
|
-
Combobox,
|
|
313
|
-
{
|
|
314
|
-
options: (options || []).map((o) => ({ value: o.value, label: o.label })),
|
|
315
|
-
value: value || "",
|
|
316
|
-
onChange: (newValue) => onChange(newValue),
|
|
317
|
-
placeholder: placeholder || (label ? `Select ${label.toLowerCase()}` : `Select ${field}`),
|
|
318
|
-
allowCustom
|
|
319
|
-
}
|
|
320
|
-
) }),
|
|
321
|
-
error && /* @__PURE__ */ jsx("p", { className: "text-destructive text-sm mt-1", children: error })
|
|
322
|
-
] });
|
|
323
|
-
};
|
|
324
11
|
var SmartFileUpload = ({
|
|
325
12
|
field,
|
|
326
13
|
label,
|
|
@@ -337,14 +24,19 @@ var SmartFileUpload = ({
|
|
|
337
24
|
onError,
|
|
338
25
|
defaultValue,
|
|
339
26
|
info,
|
|
340
|
-
subLabel
|
|
27
|
+
subLabel,
|
|
28
|
+
disabled,
|
|
29
|
+
hidden
|
|
341
30
|
}) => {
|
|
31
|
+
const { formData, registerSubmitHook, unregisterSubmitHook } = useSmartForm();
|
|
342
32
|
const { value, error, onChange, fieldRef, registerValidation } = useFormField(field);
|
|
343
|
-
const { registerSubmitHook, unregisterSubmitHook } = useSmartForm();
|
|
344
33
|
const fieldDetection = useFieldDetection();
|
|
345
34
|
const hasRegistered = useRef(false);
|
|
346
35
|
const hasSetDefault = useRef(false);
|
|
347
36
|
const inputRef = useRef(null);
|
|
37
|
+
const isDisabled = typeof disabled === "function" ? disabled(formData) : disabled || false;
|
|
38
|
+
const isHidden = typeof hidden === "function" ? hidden(formData) : hidden || false;
|
|
39
|
+
if (isHidden) return null;
|
|
348
40
|
useEffect(() => {
|
|
349
41
|
if (validation && !hasRegistered.current) {
|
|
350
42
|
hasRegistered.current = true;
|
|
@@ -502,10 +194,11 @@ var SmartFileUpload = ({
|
|
|
502
194
|
multiple,
|
|
503
195
|
onChange: onInputChange,
|
|
504
196
|
className: cn(error && "border-destructive"),
|
|
505
|
-
"data-field": field
|
|
197
|
+
"data-field": field,
|
|
198
|
+
disabled: isDisabled
|
|
506
199
|
}
|
|
507
200
|
),
|
|
508
|
-
(Array.isArray(value) ? value.length > 0 : !!value) && /* @__PURE__ */ jsx(Button, { type: "button", variant: "secondary", onClick: clearSelection, children: "Clear" })
|
|
201
|
+
(Array.isArray(value) ? value.length > 0 : !!value) && /* @__PURE__ */ jsx(Button, { type: "button", variant: "secondary", onClick: clearSelection, disabled: isDisabled, children: "Clear" })
|
|
509
202
|
] }),
|
|
510
203
|
normalizedFiles.length === 0 ? /* @__PURE__ */ jsx("div", { className: "mt-2 text-sm text-muted-foreground", children: "No file selected" }) : /* @__PURE__ */ jsx("ul", { className: "mt-2 space-y-1", children: normalizedFiles.map((f, idx) => {
|
|
511
204
|
const isImage = f.type.startsWith("image/");
|
|
@@ -537,6 +230,7 @@ var SmartFileUpload = ({
|
|
|
537
230
|
size: "sm",
|
|
538
231
|
onClick: () => removeFileAt(idx),
|
|
539
232
|
"aria-label": `Remove ${f.name}`,
|
|
233
|
+
disabled: isDisabled,
|
|
540
234
|
children: "\u2715"
|
|
541
235
|
}
|
|
542
236
|
)
|
|
@@ -553,7 +247,7 @@ function Slider({
|
|
|
553
247
|
max = 100,
|
|
554
248
|
...props
|
|
555
249
|
}) {
|
|
556
|
-
const _values =
|
|
250
|
+
const _values = React2.useMemo(
|
|
557
251
|
() => Array.isArray(value) ? value : Array.isArray(defaultValue) ? defaultValue : [min, max],
|
|
558
252
|
[value, defaultValue, min, max]
|
|
559
253
|
);
|
|
@@ -614,12 +308,18 @@ var SmartSlider = ({
|
|
|
614
308
|
valueFormatter = (value) => value.toString(),
|
|
615
309
|
defaultValue,
|
|
616
310
|
info,
|
|
617
|
-
subLabel
|
|
311
|
+
subLabel,
|
|
312
|
+
disabled,
|
|
313
|
+
hidden
|
|
618
314
|
}) => {
|
|
315
|
+
const { formData } = useSmartForm();
|
|
619
316
|
const { value, error, onChange, fieldRef, registerValidation } = useFormField(field);
|
|
620
317
|
const fieldDetection = useFieldDetection();
|
|
621
318
|
const hasRegistered = useRef(false);
|
|
622
319
|
const hasSetDefault = useRef(false);
|
|
320
|
+
const isDisabled = typeof disabled === "function" ? disabled(formData) : disabled || false;
|
|
321
|
+
const isHidden = typeof hidden === "function" ? hidden(formData) : hidden || false;
|
|
322
|
+
if (isHidden) return null;
|
|
623
323
|
useEffect(() => {
|
|
624
324
|
if (validation && !hasRegistered.current) {
|
|
625
325
|
hasRegistered.current = true;
|
|
@@ -673,7 +373,8 @@ var SmartSlider = ({
|
|
|
673
373
|
max,
|
|
674
374
|
step,
|
|
675
375
|
className: `w-full ${error ? "border-destructive" : ""}`,
|
|
676
|
-
"data-field": field
|
|
376
|
+
"data-field": field,
|
|
377
|
+
disabled: isDisabled
|
|
677
378
|
}
|
|
678
379
|
),
|
|
679
380
|
/* @__PURE__ */ jsxs("div", { className: "flex justify-between text-sm text-muted-foreground", children: [
|
|
@@ -702,8 +403,11 @@ var SmartDualRangeSlider = ({
|
|
|
702
403
|
defaultMinValue,
|
|
703
404
|
defaultMaxValue,
|
|
704
405
|
info,
|
|
705
|
-
subLabel
|
|
406
|
+
subLabel,
|
|
407
|
+
disabled,
|
|
408
|
+
hidden
|
|
706
409
|
}) => {
|
|
410
|
+
const { formData } = useSmartForm();
|
|
707
411
|
const minFormField = useFormField(minField);
|
|
708
412
|
const maxFormField = useFormField(maxField);
|
|
709
413
|
const fieldDetection = useFieldDetection();
|
|
@@ -711,6 +415,9 @@ var SmartDualRangeSlider = ({
|
|
|
711
415
|
const hasRegisteredMax = useRef(false);
|
|
712
416
|
const hasSetDefaultMin = useRef(false);
|
|
713
417
|
const hasSetDefaultMax = useRef(false);
|
|
418
|
+
const isDisabled = typeof disabled === "function" ? disabled(formData) : disabled || false;
|
|
419
|
+
const isHidden = typeof hidden === "function" ? hidden(formData) : hidden || false;
|
|
420
|
+
if (isHidden) return null;
|
|
714
421
|
useEffect(() => {
|
|
715
422
|
if (minValidation && !hasRegisteredMin.current) {
|
|
716
423
|
hasRegisteredMin.current = true;
|
|
@@ -776,7 +483,8 @@ var SmartDualRangeSlider = ({
|
|
|
776
483
|
step,
|
|
777
484
|
className: `w-full ${combinedError ? "border-destructive" : ""}`,
|
|
778
485
|
"data-min-field": minField,
|
|
779
|
-
"data-max-field": maxField
|
|
486
|
+
"data-max-field": maxField,
|
|
487
|
+
disabled: isDisabled
|
|
780
488
|
}
|
|
781
489
|
),
|
|
782
490
|
showValues && /* @__PURE__ */ jsxs("div", { className: "flex justify-between items-center text-sm", children: [
|
|
@@ -930,12 +638,18 @@ var SmartAutoSuggestTags = ({
|
|
|
930
638
|
defaultValue,
|
|
931
639
|
onTagCreate,
|
|
932
640
|
info,
|
|
933
|
-
subLabel
|
|
641
|
+
subLabel,
|
|
642
|
+
disabled,
|
|
643
|
+
hidden
|
|
934
644
|
}) => {
|
|
645
|
+
const { formData } = useSmartForm();
|
|
935
646
|
const { value, error, onChange, fieldRef, registerValidation } = useFormField(field);
|
|
936
647
|
const fieldDetection = useFieldDetection();
|
|
937
648
|
const hasRegistered = useRef(false);
|
|
938
649
|
const hasSetDefault = useRef(false);
|
|
650
|
+
const isDisabled = typeof disabled === "function" ? disabled(formData) : disabled || false;
|
|
651
|
+
const isHidden = typeof hidden === "function" ? hidden(formData) : hidden || false;
|
|
652
|
+
if (isHidden) return null;
|
|
939
653
|
const [tags, setTags] = useState(initialOptions);
|
|
940
654
|
const [newTag, setNewTag] = useState("");
|
|
941
655
|
const selected = Array.isArray(value) ? value : [];
|
|
@@ -1021,9 +735,10 @@ var SmartAutoSuggestTags = ({
|
|
|
1021
735
|
/* @__PURE__ */ jsx("div", { ref: fieldRef, "data-field": field, children: /* @__PURE__ */ jsx("div", { className: cn(
|
|
1022
736
|
"w-full rounded-md border border-input bg-background text-sm ring-offset-background",
|
|
1023
737
|
"focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",
|
|
1024
|
-
error && "border-destructive focus-within:ring-destructive"
|
|
738
|
+
error && "border-destructive focus-within:ring-destructive",
|
|
739
|
+
isDisabled && "cursor-not-allowed opacity-50"
|
|
1025
740
|
), children: /* @__PURE__ */ jsxs(Tags, { className: "w-full", children: [
|
|
1026
|
-
/* @__PURE__ */ jsxs(TagsTrigger, { className: "w-full px-3 py-2 border-0 bg-transparent", children: [
|
|
741
|
+
/* @__PURE__ */ jsxs(TagsTrigger, { className: "w-full px-3 py-2 border-0 bg-transparent", disabled: isDisabled, children: [
|
|
1027
742
|
selected.length === 0 && placeholder && /* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-sm", children: placeholder }),
|
|
1028
743
|
selected.map((tagId) => {
|
|
1029
744
|
const tag = tags.find((t) => t.id === tagId);
|
|
@@ -1044,7 +759,8 @@ var SmartAutoSuggestTags = ({
|
|
|
1044
759
|
{
|
|
1045
760
|
onValueChange: setNewTag,
|
|
1046
761
|
placeholder: `Search ${placeholder.toLowerCase()}...`,
|
|
1047
|
-
value: newTag
|
|
762
|
+
value: newTag,
|
|
763
|
+
disabled: isDisabled
|
|
1048
764
|
}
|
|
1049
765
|
),
|
|
1050
766
|
/* @__PURE__ */ jsxs(TagsList, { children: [
|
|
@@ -1135,14 +851,20 @@ var SmartBasicRichTextbox = ({
|
|
|
1135
851
|
minHeight = "150px",
|
|
1136
852
|
maxHeight = "400px",
|
|
1137
853
|
info,
|
|
1138
|
-
subLabel
|
|
854
|
+
subLabel,
|
|
855
|
+
disabled,
|
|
856
|
+
hidden
|
|
1139
857
|
}) => {
|
|
858
|
+
const { formData } = useSmartForm();
|
|
1140
859
|
const { value, error, onChange, fieldRef, registerValidation } = useFormField(field);
|
|
1141
860
|
const fieldDetection = useFieldDetection();
|
|
1142
861
|
const hasRegistered = useRef(false);
|
|
1143
862
|
const hasSetDefault = useRef(false);
|
|
1144
863
|
const editorRef = useRef(null);
|
|
1145
864
|
const [isFocused, setIsFocused] = useState(false);
|
|
865
|
+
const isDisabled = typeof disabled === "function" ? disabled(formData) : disabled || false;
|
|
866
|
+
const isHidden = typeof hidden === "function" ? hidden(formData) : hidden || false;
|
|
867
|
+
if (isHidden) return null;
|
|
1146
868
|
useEffect(() => {
|
|
1147
869
|
if (validation && !hasRegistered.current) {
|
|
1148
870
|
hasRegistered.current = true;
|
|
@@ -1249,10 +971,11 @@ var SmartBasicRichTextbox = ({
|
|
|
1249
971
|
className: cn(
|
|
1250
972
|
"w-full rounded-md border border-input bg-background",
|
|
1251
973
|
"focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",
|
|
1252
|
-
error && "border-destructive focus-within:ring-destructive"
|
|
974
|
+
error && "border-destructive focus-within:ring-destructive",
|
|
975
|
+
isDisabled && "cursor-not-allowed opacity-50"
|
|
1253
976
|
),
|
|
1254
977
|
children: [
|
|
1255
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-0.5 p-1.5 border-b border-border bg-muted/30", children: [
|
|
978
|
+
/* @__PURE__ */ jsxs("div", { className: cn("flex items-center gap-0.5 p-1.5 border-b border-border bg-muted/30", isDisabled && "pointer-events-none"), children: [
|
|
1256
979
|
/* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
1257
980
|
/* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
1258
981
|
Button,
|
|
@@ -1265,6 +988,7 @@ var SmartBasicRichTextbox = ({
|
|
|
1265
988
|
activeFormats.bold && "bg-primary text-primary-foreground hover:bg-primary/90"
|
|
1266
989
|
),
|
|
1267
990
|
onClick: toggleBold,
|
|
991
|
+
disabled: isDisabled,
|
|
1268
992
|
children: /* @__PURE__ */ jsx(Bold, { className: "h-4 w-4" })
|
|
1269
993
|
}
|
|
1270
994
|
) }),
|
|
@@ -1282,6 +1006,7 @@ var SmartBasicRichTextbox = ({
|
|
|
1282
1006
|
activeFormats.italic && "bg-primary text-primary-foreground hover:bg-primary/90"
|
|
1283
1007
|
),
|
|
1284
1008
|
onClick: toggleItalic,
|
|
1009
|
+
disabled: isDisabled,
|
|
1285
1010
|
children: /* @__PURE__ */ jsx(Italic, { className: "h-4 w-4" })
|
|
1286
1011
|
}
|
|
1287
1012
|
) }),
|
|
@@ -1299,6 +1024,7 @@ var SmartBasicRichTextbox = ({
|
|
|
1299
1024
|
activeFormats.underline && "bg-primary text-primary-foreground hover:bg-primary/90"
|
|
1300
1025
|
),
|
|
1301
1026
|
onClick: toggleUnderline,
|
|
1027
|
+
disabled: isDisabled,
|
|
1302
1028
|
children: /* @__PURE__ */ jsx(Underline, { className: "h-4 w-4" })
|
|
1303
1029
|
}
|
|
1304
1030
|
) }),
|
|
@@ -1317,6 +1043,7 @@ var SmartBasicRichTextbox = ({
|
|
|
1317
1043
|
activeFormats.bulletList && "bg-primary text-primary-foreground hover:bg-primary/90"
|
|
1318
1044
|
),
|
|
1319
1045
|
onClick: toggleBulletList,
|
|
1046
|
+
disabled: isDisabled,
|
|
1320
1047
|
children: /* @__PURE__ */ jsx(List, { className: "h-4 w-4" })
|
|
1321
1048
|
}
|
|
1322
1049
|
) }),
|
|
@@ -1334,6 +1061,7 @@ var SmartBasicRichTextbox = ({
|
|
|
1334
1061
|
activeFormats.numberedList && "bg-primary text-primary-foreground hover:bg-primary/90"
|
|
1335
1062
|
),
|
|
1336
1063
|
onClick: toggleNumberedList,
|
|
1064
|
+
disabled: isDisabled,
|
|
1337
1065
|
children: /* @__PURE__ */ jsx(ListOrdered, { className: "h-4 w-4" })
|
|
1338
1066
|
}
|
|
1339
1067
|
) }),
|
|
@@ -1344,7 +1072,7 @@ var SmartBasicRichTextbox = ({
|
|
|
1344
1072
|
"div",
|
|
1345
1073
|
{
|
|
1346
1074
|
ref: editorRef,
|
|
1347
|
-
contentEditable:
|
|
1075
|
+
contentEditable: !isDisabled,
|
|
1348
1076
|
onInput: handleInput,
|
|
1349
1077
|
onKeyDown: handleKeyDown,
|
|
1350
1078
|
onFocus: handleFocus,
|
|
@@ -1379,6 +1107,6 @@ var SmartBasicRichTextbox = ({
|
|
|
1379
1107
|
] });
|
|
1380
1108
|
};
|
|
1381
1109
|
|
|
1382
|
-
export { SmartAutoSuggestTags, SmartBasicRichTextbox,
|
|
1110
|
+
export { SmartAutoSuggestTags, SmartBasicRichTextbox, SmartDualRangeSlider, SmartFileUpload, SmartSlider };
|
|
1383
1111
|
//# sourceMappingURL=fields.js.map
|
|
1384
1112
|
//# sourceMappingURL=fields.js.map
|