@algodomain/smart-forms 0.1.3 → 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/dist/fields.d.ts CHANGED
@@ -1,27 +1,7 @@
1
1
  export { S as SmartFormProvider, a as useFormField, u as useSmartForm } from './SmartFormProvider-BdyRQakk.js';
2
- export { a as SmartCheckbox, d as SmartDatePicker, S as SmartInput, f as SmartInputProps, b as SmartRadioGroup, c as SmartSelect, e as SmartTags, g as SmartTagsProps } from './SmartTags-DPqw9PG1.js';
2
+ export { a as SmartCheckbox, d as SmartCombobox, e as SmartDatePicker, i as SmartDatePickerProps, S as SmartInput, g as SmartInputProps, b as SmartRadioGroup, c as SmartSelect, f as SmartTags, h as SmartTagsProps } from './SmartTags-DEpmTDF5.js';
3
3
  import React__default from 'react';
4
-
5
- interface SmartComboboxOption {
6
- value: string;
7
- label: string;
8
- }
9
- interface SmartComboboxProps {
10
- field: string;
11
- label?: string;
12
- options: SmartComboboxOption[];
13
- className?: string;
14
- placeholder?: string;
15
- allowCustom?: boolean;
16
- validation?: any;
17
- required?: boolean;
18
- defaultValue?: string;
19
- info?: string;
20
- subLabel?: string;
21
- disabled?: boolean | ((formData: any) => boolean);
22
- hidden?: boolean | ((formData: any) => boolean);
23
- }
24
- declare const SmartCombobox: React__default.FC<SmartComboboxProps>;
4
+ import 'react/jsx-runtime';
25
5
 
26
6
  interface SmartFileUploadProps {
27
7
  field: string;
@@ -128,4 +108,4 @@ interface SmartBasicRichTextboxProps {
128
108
  }
129
109
  declare const SmartBasicRichTextbox: React__default.FC<SmartBasicRichTextboxProps>;
130
110
 
131
- export { SmartAutoSuggestTags, type SmartAutoSuggestTagsProps, SmartBasicRichTextbox, type SmartBasicRichTextboxProps, SmartCombobox, SmartDualRangeSlider, type SmartDualRangeSliderProps, SmartFileUpload, SmartSlider, type SmartSliderProps, type TagOption };
111
+ export { SmartAutoSuggestTags, type SmartAutoSuggestTagsProps, SmartBasicRichTextbox, type SmartBasicRichTextboxProps, SmartDualRangeSlider, type SmartDualRangeSliderProps, SmartFileUpload, SmartSlider, type SmartSliderProps, type TagOption };
package/dist/fields.js CHANGED
@@ -1,333 +1,13 @@
1
- import { Button, Popover, PopoverTrigger, PopoverContent } from './chunk-CT6GW6PK.js';
2
- export { SmartCheckbox, SmartDatePicker, SmartRadioGroup, SmartSelect, SmartTags } from './chunk-CT6GW6PK.js';
3
- import { useSmartForm, useFormField, useFieldDetection, Label, TooltipProvider, Tooltip, TooltipTrigger, TooltipContent, cn, Input } from './chunk-3L7TKJIB.js';
4
- export { SmartFormProvider, SmartInput, useFormField, useSmartForm } from './chunk-3L7TKJIB.js';
5
- import * as React from 'react';
6
- import React__default, { createContext, useRef, useEffect, useMemo, useState, useCallback, useContext } from 'react';
7
- import { InfoIcon, PlusIcon, CheckIcon, Bold, Italic, Underline, List, ListOrdered, ChevronsUpDown, Check, Plus, XIcon, SearchIcon } from 'lucide-react';
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
- disabled,
275
- hidden
276
- }) => {
277
- const { formData } = useSmartForm();
278
- const { value, error, onChange, fieldRef, registerValidation } = useFormField(field);
279
- const fieldDetection = useFieldDetection();
280
- const hasRegistered = useRef(false);
281
- const hasSetDefault = useRef(false);
282
- const isDisabled = typeof disabled === "function" ? disabled(formData) : disabled || false;
283
- const isHidden = typeof hidden === "function" ? hidden(formData) : hidden || false;
284
- if (isHidden) return null;
285
- useEffect(() => {
286
- if (validation && !hasRegistered.current) {
287
- hasRegistered.current = true;
288
- registerValidation(field, validation);
289
- }
290
- }, [validation, field, registerValidation]);
291
- useEffect(() => {
292
- if (fieldDetection?.registerField) {
293
- fieldDetection.registerField(field);
294
- }
295
- }, [field, fieldDetection]);
296
- useEffect(() => {
297
- if (defaultValue !== void 0 && !hasSetDefault.current && (value === void 0 || value === null || value === "")) {
298
- onChange(defaultValue);
299
- hasSetDefault.current = true;
300
- }
301
- }, [defaultValue, value, onChange]);
302
- return /* @__PURE__ */ jsxs("div", { className: `flex-1 min-w-0 ${className}`, children: [
303
- label && /* @__PURE__ */ jsxs("div", { className: "mb-2", children: [
304
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
305
- /* @__PURE__ */ jsxs(Label, { className: "text-sm font-medium text-foreground", children: [
306
- label,
307
- " ",
308
- required && /* @__PURE__ */ jsx("span", { className: "text-destructive", children: "*" })
309
- ] }),
310
- info && /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsxs(Tooltip, { children: [
311
- /* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(InfoIcon, { className: "h-4 w-4 text-muted-foreground cursor-pointer mr-2" }) }),
312
- /* @__PURE__ */ jsx(TooltipContent, { children: /* @__PURE__ */ jsx("p", { className: "max-w-xs", children: info }) })
313
- ] }) })
314
- ] }),
315
- subLabel && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-1", children: subLabel })
316
- ] }),
317
- /* @__PURE__ */ jsx("div", { ref: fieldRef, "data-field": field, children: /* @__PURE__ */ jsx(
318
- Combobox,
319
- {
320
- options: (options || []).map((o) => ({ value: o.value, label: o.label })),
321
- value: value || "",
322
- onChange: (newValue) => onChange(newValue),
323
- placeholder: placeholder || (label ? `Select ${label.toLowerCase()}` : `Select ${field}`),
324
- allowCustom,
325
- isDisabled
326
- }
327
- ) }),
328
- error && /* @__PURE__ */ jsx("p", { className: "text-destructive text-sm mt-1", children: error })
329
- ] });
330
- };
331
11
  var SmartFileUpload = ({
332
12
  field,
333
13
  label,
@@ -567,7 +247,7 @@ function Slider({
567
247
  max = 100,
568
248
  ...props
569
249
  }) {
570
- const _values = React.useMemo(
250
+ const _values = React2.useMemo(
571
251
  () => Array.isArray(value) ? value : Array.isArray(defaultValue) ? defaultValue : [min, max],
572
252
  [value, defaultValue, min, max]
573
253
  );
@@ -1427,6 +1107,6 @@ var SmartBasicRichTextbox = ({
1427
1107
  ] });
1428
1108
  };
1429
1109
 
1430
- export { SmartAutoSuggestTags, SmartBasicRichTextbox, SmartCombobox, SmartDualRangeSlider, SmartFileUpload, SmartSlider };
1110
+ export { SmartAutoSuggestTags, SmartBasicRichTextbox, SmartDualRangeSlider, SmartFileUpload, SmartSlider };
1431
1111
  //# sourceMappingURL=fields.js.map
1432
1112
  //# sourceMappingURL=fields.js.map