@fuf-stack/megapixels 0.8.0 → 0.9.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.
@@ -1,737 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
-
21
- // src/Filter/Filter.tsx
22
- import createDebug from "debug";
23
- import { tv, variantsToClassNames } from "@fuf-stack/pixel-utils";
24
- import Form from "@fuf-stack/uniform/Form";
25
-
26
- // src/Filter/hooks/useFilterValidation.ts
27
- import { useMemo } from "react";
28
- import { object, string, stringToJSON, veto } from "@fuf-stack/veto";
29
- var useFilterValidation = (filters2, withSearch) => {
30
- return useMemo(() => {
31
- let filterSchema = {};
32
- filters2.forEach((f) => {
33
- filterSchema = __spreadProps(__spreadValues({}, filterSchema), {
34
- [f.name]: f.validation(f.config)
35
- });
36
- });
37
- const validationSchema = __spreadValues({
38
- // filter validation
39
- filter: stringToJSON().pipe(object(filterSchema)).or(object(filterSchema)).optional().nullable().transform((val) => {
40
- return val != null ? val : void 0;
41
- })
42
- }, withSearch ? { search: string({ min: 0 }).nullable().optional() } : {});
43
- return veto(validationSchema);
44
- }, [filters2, withSearch]);
45
- };
46
-
47
- // src/Filter/Subcomponents/ActiveFilters.tsx
48
- import Label from "@fuf-stack/pixels/Label";
49
-
50
- // src/Filter/Subcomponents/FiltersContext.tsx
51
- import {
52
- createContext,
53
- useCallback,
54
- useContext,
55
- useEffect,
56
- useMemo as useMemo2,
57
- useRef,
58
- useState
59
- } from "react";
60
- import { useFormContext } from "@fuf-stack/uniform/hooks/useFormContext";
61
- import { jsx } from "react/jsx-runtime";
62
- var FiltersContext = createContext(
63
- void 0
64
- );
65
- var FiltersContextProvider = ({
66
- children,
67
- config: config3
68
- }) => {
69
- const {
70
- formState,
71
- getFieldState,
72
- setValue,
73
- triggerSubmit,
74
- unregister,
75
- watch
76
- } = useFormContext();
77
- const [currentModalFilter, setCurrentModalFilter] = useState(null);
78
- const filterValue = watch("filter", {});
79
- const getFilterFormFieldName = useCallback((name) => {
80
- return `filter.${name}`;
81
- }, []);
82
- const getFilterValueByName = useCallback(
83
- (name) => {
84
- return filterValue[name];
85
- },
86
- [filterValue]
87
- );
88
- const showFilterModal = useCallback(
89
- (name) => {
90
- const prev = getFilterValueByName(name);
91
- setCurrentModalFilter({
92
- name,
93
- hadValue: typeof prev !== "undefined",
94
- previousValue: prev
95
- });
96
- },
97
- [getFilterValueByName]
98
- );
99
- const closeFilterModal = useCallback(() => {
100
- if (currentModalFilter == null ? void 0 : currentModalFilter.name) {
101
- const fieldName = getFilterFormFieldName(currentModalFilter.name);
102
- if (currentModalFilter.hadValue) {
103
- setValue(fieldName, currentModalFilter.previousValue);
104
- } else {
105
- unregister(fieldName);
106
- }
107
- }
108
- setCurrentModalFilter(null);
109
- }, [getFilterFormFieldName, currentModalFilter, setValue, unregister]);
110
- const lastSubmitCountRef = useRef(0);
111
- useEffect(() => {
112
- if (formState.submitCount !== lastSubmitCountRef.current && formState.isSubmitSuccessful) {
113
- setCurrentModalFilter(null);
114
- }
115
- lastSubmitCountRef.current = formState.submitCount;
116
- }, [
117
- formState.submitCount,
118
- formState.isSubmitSuccessful,
119
- setCurrentModalFilter
120
- ]);
121
- const activeFilters = useMemo2(() => {
122
- return config3.filter((f) => {
123
- return Object.hasOwn(filterValue != null ? filterValue : {}, f.name);
124
- }).map((f) => {
125
- return f.name;
126
- });
127
- }, [config3, filterValue]);
128
- const unusedFilters = useMemo2(() => {
129
- return config3.filter((f) => {
130
- return !Object.hasOwn(filterValue != null ? filterValue : {}, f.name);
131
- }).map((f) => {
132
- return f.name;
133
- });
134
- }, [config3, filterValue]);
135
- const getFilterInstanceByName = useCallback(
136
- (name) => {
137
- return config3.find((f) => {
138
- return f.name === name;
139
- });
140
- },
141
- [config3]
142
- );
143
- const addFilter = useCallback(
144
- (name) => {
145
- const inst = getFilterInstanceByName(name);
146
- showFilterModal(name);
147
- setValue(getFilterFormFieldName(name), inst.defaultValue);
148
- },
149
- [
150
- getFilterFormFieldName,
151
- getFilterInstanceByName,
152
- setValue,
153
- showFilterModal
154
- ]
155
- );
156
- const removeFilter = useCallback(
157
- (name) => {
158
- unregister(getFilterFormFieldName(name));
159
- if ((currentModalFilter == null ? void 0 : currentModalFilter.name) === name) {
160
- setCurrentModalFilter(null);
161
- }
162
- triggerSubmit();
163
- },
164
- [
165
- getFilterFormFieldName,
166
- currentModalFilter,
167
- setCurrentModalFilter,
168
- triggerSubmit,
169
- unregister
170
- ]
171
- );
172
- const hasError = useCallback(
173
- (name) => {
174
- return getFieldState(getFilterFormFieldName(name)).invalid;
175
- },
176
- [getFieldState, getFilterFormFieldName]
177
- );
178
- const contextValue = useMemo2(() => {
179
- return {
180
- activeFilters,
181
- addFilter,
182
- closeFilterModal,
183
- getFilterFormFieldName,
184
- getFilterValueByName,
185
- getFilterInstanceByName,
186
- hasError,
187
- modalFilterName: currentModalFilter == null ? void 0 : currentModalFilter.name,
188
- removeFilter,
189
- showFilterModal,
190
- unusedFilters
191
- };
192
- }, [
193
- activeFilters,
194
- addFilter,
195
- closeFilterModal,
196
- getFilterFormFieldName,
197
- getFilterValueByName,
198
- getFilterInstanceByName,
199
- hasError,
200
- currentModalFilter,
201
- removeFilter,
202
- showFilterModal,
203
- unusedFilters
204
- ]);
205
- return /* @__PURE__ */ jsx(FiltersContext.Provider, { value: contextValue, children });
206
- };
207
- var useFilters = () => {
208
- const ctx = useContext(FiltersContext);
209
- if (!ctx) {
210
- throw new Error("useFilters must be used within FiltersContextProvider");
211
- }
212
- return ctx;
213
- };
214
-
215
- // src/Filter/Subcomponents/ActiveFilters.tsx
216
- import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
217
- var ActiveFilters = ({ className = void 0 }) => {
218
- const {
219
- activeFilters,
220
- getFilterValueByName,
221
- getFilterInstanceByName,
222
- hasError,
223
- removeFilter,
224
- showFilterModal
225
- } = useFilters();
226
- return /* @__PURE__ */ jsx2(Fragment, { children: activeFilters.map((name) => {
227
- const instance = getFilterInstanceByName(name);
228
- const value = getFilterValueByName(name);
229
- const DisplayComponent = instance.components.Display;
230
- return /* @__PURE__ */ jsx2(
231
- "button",
232
- {
233
- "aria-label": `Open ${name} filter`,
234
- type: "button",
235
- onClick: () => {
236
- showFilterModal(name);
237
- },
238
- children: /* @__PURE__ */ jsxs(
239
- Label,
240
- {
241
- className,
242
- color: hasError(name) ? "danger" : "primary",
243
- variant: "flat",
244
- onClose: () => {
245
- removeFilter(name);
246
- },
247
- children: [
248
- instance.icon,
249
- /* @__PURE__ */ jsx2(DisplayComponent, { config: instance.config, value })
250
- ]
251
- }
252
- )
253
- },
254
- name
255
- );
256
- }) });
257
- };
258
- var ActiveFilters_default = ActiveFilters;
259
-
260
- // src/Filter/Subcomponents/AddFilterMenu.tsx
261
- import { FaSliders } from "react-icons/fa6";
262
- import Menu from "@fuf-stack/pixels/Menu";
263
- import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
264
- var AddFilterMenu = ({ classNames = {} }) => {
265
- const { unusedFilters, addFilter, getFilterInstanceByName } = useFilters();
266
- const menuItems = unusedFilters.map((name) => {
267
- var _a;
268
- const instance = getFilterInstanceByName(name);
269
- const config3 = instance.config;
270
- const label = (_a = config3 == null ? void 0 : config3.text) != null ? _a : name;
271
- return {
272
- key: name,
273
- icon: instance.icon,
274
- label,
275
- onClick: () => {
276
- addFilter(name);
277
- }
278
- };
279
- });
280
- return /* @__PURE__ */ jsxs2(
281
- Menu,
282
- {
283
- isDisabled: !menuItems.length,
284
- items: menuItems,
285
- placement: "bottom-start",
286
- className: {
287
- item: classNames.addFilterMenuItem,
288
- trigger: classNames.addFilterMenuButton
289
- },
290
- triggerButtonProps: {
291
- "aria-label": "Add Filter",
292
- "data-testid": "add_filter_button",
293
- disableRipple: true,
294
- size: "sm",
295
- variant: "bordered"
296
- },
297
- children: [
298
- /* @__PURE__ */ jsx3(FaSliders, {}),
299
- "Filter"
300
- ]
301
- }
302
- );
303
- };
304
- var AddFilterMenu_default = AddFilterMenu;
305
-
306
- // src/Filter/Subcomponents/FilterModal.tsx
307
- import { Suspense } from "react";
308
- import { PiSlidersHorizontalBold } from "react-icons/pi";
309
- import Button from "@fuf-stack/pixels/Button";
310
- import Modal from "@fuf-stack/pixels/Modal";
311
- import SubmitButton from "@fuf-stack/uniform/SubmitButton";
312
- import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
313
- var FilterModal = ({ classNames = {} }) => {
314
- var _a, _b;
315
- const {
316
- closeFilterModal,
317
- getFilterFormFieldName,
318
- getFilterInstanceByName,
319
- modalFilterName,
320
- removeFilter
321
- } = useFilters();
322
- if (!modalFilterName) {
323
- return null;
324
- }
325
- const instance = getFilterInstanceByName(modalFilterName);
326
- const config3 = instance.config;
327
- const FormComponent = instance.components.Form;
328
- return /* @__PURE__ */ jsx4(
329
- Modal,
330
- {
331
- isOpen: true,
332
- onClose: closeFilterModal,
333
- className: {
334
- body: classNames.body,
335
- footer: classNames.footer,
336
- header: classNames.header
337
- },
338
- footer: /* @__PURE__ */ jsxs3(Fragment2, { children: [
339
- /* @__PURE__ */ jsx4(
340
- Button,
341
- {
342
- ariaLabel: "Remove filter",
343
- color: "danger",
344
- testId: "remove_filter_button",
345
- variant: "flat",
346
- onClick: () => {
347
- removeFilter(modalFilterName);
348
- },
349
- children: "Remove"
350
- }
351
- ),
352
- /* @__PURE__ */ jsx4(SubmitButton, { ariaLabel: "Apply filter", testId: "apply_filter_button", children: "Apply Filter" })
353
- ] }),
354
- header: /* @__PURE__ */ jsxs3(Fragment2, { children: [
355
- (_a = instance.icon) != null ? _a : /* @__PURE__ */ jsx4(PiSlidersHorizontalBold, {}),
356
- /* @__PURE__ */ jsx4("div", { children: `${(_b = config3 == null ? void 0 : config3.text) != null ? _b : modalFilterName} Filter` })
357
- ] }),
358
- children: /* @__PURE__ */ jsx4(Suspense, { children: /* @__PURE__ */ jsx4(
359
- FormComponent,
360
- {
361
- config: config3,
362
- fieldName: getFilterFormFieldName(modalFilterName)
363
- }
364
- ) })
365
- }
366
- );
367
- };
368
- var FilterModal_default = FilterModal;
369
-
370
- // src/Filter/Subcomponents/SearchInput.tsx
371
- import { useState as useState2 } from "react";
372
- import { FaSearch } from "react-icons/fa";
373
- import { motion } from "@fuf-stack/pixel-motion";
374
- import Button2 from "@fuf-stack/pixels/Button";
375
- import { useFormContext as useFormContext2 } from "@fuf-stack/uniform/hooks/useFormContext";
376
- import Input from "@fuf-stack/uniform/Input";
377
- import SubmitButton2 from "@fuf-stack/uniform/SubmitButton";
378
- import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
379
- var SearchInput = ({ classNames = {}, config: config3 }) => {
380
- var _a;
381
- const { formState, setFocus, triggerSubmit } = useFormContext2();
382
- const isInitiallyVisible = !!((_a = formState == null ? void 0 : formState.defaultValues) == null ? void 0 : _a.search);
383
- const [isVisible, setIsVisible] = useState2(isInitiallyVisible);
384
- const placeholder = typeof config3 === "object" ? config3.placeholder : void 0;
385
- return /* @__PURE__ */ jsxs4("div", { className: classNames.searchWrapper, children: [
386
- !isVisible && /* @__PURE__ */ jsx5(
387
- Button2,
388
- {
389
- ariaLabel: "Show search input",
390
- className: classNames.searchShowButton,
391
- icon: /* @__PURE__ */ jsx5(FaSearch, {}),
392
- size: "sm",
393
- testId: "show_search_input_button",
394
- variant: "bordered",
395
- onClick: () => {
396
- setIsVisible(true);
397
- }
398
- }
399
- ),
400
- isVisible ? /* @__PURE__ */ jsxs4(
401
- motion.div,
402
- {
403
- animate: { opacity: 1 },
404
- className: classNames.searchMotionDiv,
405
- initial: !isInitiallyVisible ? { opacity: 0.5 } : false,
406
- onAnimationComplete: () => {
407
- if (!isInitiallyVisible) {
408
- setFocus("search");
409
- }
410
- },
411
- transition: {
412
- duration: 0.3,
413
- ease: "circOut"
414
- },
415
- children: [
416
- /* @__PURE__ */ jsx5(
417
- Input,
418
- {
419
- clearable: true,
420
- debounceDelay: 0,
421
- name: "search",
422
- placeholder,
423
- size: "sm",
424
- className: {
425
- input: classNames.searchInput,
426
- inputWrapper: classNames.searchInputWrapper
427
- },
428
- onClear: () => {
429
- triggerSubmit();
430
- }
431
- }
432
- ),
433
- /* @__PURE__ */ jsx5(
434
- SubmitButton2,
435
- {
436
- ariaLabel: "Submit search",
437
- children: null,
438
- className: classNames.searchSubmitButton,
439
- color: "primary",
440
- icon: /* @__PURE__ */ jsx5(FaSearch, {}),
441
- size: "sm",
442
- testId: "submit_search_button"
443
- }
444
- )
445
- ]
446
- },
447
- "search-input"
448
- ) : null
449
- ] });
450
- };
451
- var SearchInput_default = SearchInput;
452
-
453
- // src/Filter/Filter.tsx
454
- import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
455
- var debug = createDebug("megapixels:Filter");
456
- var filterVariants = tv({
457
- slots: {
458
- // outer wrapper
459
- base: "flex flex-auto flex-col",
460
- // add filter menu trigger button
461
- addFilterMenuButton: "",
462
- // add filter menu item
463
- addFilterMenuItem: "",
464
- // active filter label
465
- activeFilterLabel: "h-8 cursor-pointer rounded-md dark:text-foreground",
466
- // filter modal body
467
- filterModalBody: "",
468
- // filter modal header
469
- filterModalHeader: "flex items-center gap-3 text-default-700",
470
- // filter modal footer
471
- filterModalFooter: "justify-between",
472
- // form element
473
- form: "mb-3 flex flex-wrap gap-3",
474
- // search input field
475
- searchInput: "",
476
- // search input wrapper (inner control)
477
- searchInputWrapper: "",
478
- // search motion container
479
- searchMotionDiv: "flex w-72 gap-2",
480
- // search show button
481
- searchShowButton: "",
482
- // search submit button
483
- searchSubmitButton: "",
484
- // search wrapper
485
- searchWrapper: "flex items-center"
486
- }
487
- });
488
- var Filter = ({
489
- children = void 0,
490
- className = void 0,
491
- config: config3,
492
- formName = "filterComponentForm",
493
- onChange,
494
- values
495
- }) => {
496
- const handleSubmit = (nextValues) => {
497
- debug("handleSubmit", { nextValues });
498
- onChange(nextValues);
499
- };
500
- const validation = useFilterValidation(
501
- config3.filters,
502
- Boolean(config3.search)
503
- );
504
- const {
505
- data: valuesValidated,
506
- errors,
507
- success
508
- } = validation.validate(values);
509
- const variants = filterVariants();
510
- const classNames = variantsToClassNames(variants, className, "base");
511
- debug("render", {
512
- props: { config: config3, values },
513
- validation: { errors, success, valuesValidated }
514
- });
515
- return /* @__PURE__ */ jsxs5("div", { className: classNames.base, children: [
516
- /* @__PURE__ */ jsxs5(
517
- Form,
518
- {
519
- className: classNames.form,
520
- debug: { disable: true },
521
- initialValues: valuesValidated != null ? valuesValidated : {},
522
- name: formName,
523
- onSubmit: handleSubmit,
524
- validation,
525
- children: [
526
- config3.search ? /* @__PURE__ */ jsx6(
527
- SearchInput_default,
528
- {
529
- config: config3.search,
530
- classNames: {
531
- searchInput: classNames.searchInput,
532
- searchInputWrapper: classNames.searchInputWrapper,
533
- searchMotionDiv: classNames.searchMotionDiv,
534
- searchShowButton: classNames.searchShowButton,
535
- searchSubmitButton: classNames.searchSubmitButton,
536
- searchWrapper: classNames.searchWrapper
537
- }
538
- }
539
- ) : null,
540
- /* @__PURE__ */ jsxs5(FiltersContextProvider, { config: config3.filters, children: [
541
- /* @__PURE__ */ jsx6(ActiveFilters_default, { className: classNames.activeFilterLabel }),
542
- /* @__PURE__ */ jsx6(
543
- AddFilterMenu_default,
544
- {
545
- classNames: {
546
- addFilterMenuButton: classNames.addFilterMenuButton,
547
- addFilterMenuItem: classNames.addFilterMenuItem
548
- }
549
- }
550
- ),
551
- /* @__PURE__ */ jsx6(
552
- FilterModal_default,
553
- {
554
- classNames: {
555
- body: classNames.filterModalBody,
556
- footer: classNames.filterModalFooter,
557
- header: classNames.filterModalHeader
558
- }
559
- }
560
- )
561
- ] })
562
- ]
563
- }
564
- ),
565
- children == null ? void 0 : children(valuesValidated != null ? valuesValidated : {})
566
- ] });
567
- };
568
- var Filter_default = Filter;
569
-
570
- // src/Filter/filters/createFilter.ts
571
- var createFilter = (definition) => {
572
- return ({ name, icon, config: config3 }) => {
573
- return {
574
- components: definition.components,
575
- config: __spreadValues(__spreadValues({}, definition.defaults.config), config3 != null ? config3 : {}),
576
- defaultValue: definition.defaults.value,
577
- icon,
578
- name,
579
- validation: definition.validation
580
- };
581
- };
582
- };
583
- var createFilter_default = createFilter;
584
-
585
- // src/Filter/filters/boolean/Display.tsx
586
- import { Fragment as Fragment3, jsx as jsx7 } from "react/jsx-runtime";
587
- var Display = ({
588
- value,
589
- config: { text, textPrefix, textNoWord }
590
- }) => {
591
- if (typeof value === "boolean") {
592
- return /* @__PURE__ */ jsx7(Fragment3, { children: `${value ? textPrefix : `${textPrefix} ${textNoWord != null ? textNoWord : "no"}`} ${text}` });
593
- }
594
- return /* @__PURE__ */ jsx7(Fragment3, { children: `${text}...` });
595
- };
596
- var Display_default = Display;
597
-
598
- // src/Filter/filters/boolean/Form.tsx
599
- import Switch from "@fuf-stack/uniform/Switch";
600
- import { jsx as jsx8 } from "react/jsx-runtime";
601
- var Form2 = ({
602
- fieldName,
603
- config: { text, textPrefix }
604
- }) => {
605
- return /* @__PURE__ */ jsx8(Switch, { label: `${textPrefix} ${text}`, name: fieldName });
606
- };
607
- var Form_default = Form2;
608
-
609
- // src/Filter/filters/boolean/schema.ts
610
- import { boolean, object as object2, string as string2 } from "@fuf-stack/veto";
611
- var config = object2({
612
- /**
613
- * Human‑readable label used in the UI (e.g. in the chip and modal header).
614
- * Examples: "Magical", "Haunted"
615
- */
616
- text: string2(),
617
- /**
618
- * Optional word shown before the label when building sentence‑like chips.
619
- * Examples: "is" → "is Magical"
620
- */
621
- textPrefix: string2().optional(),
622
- /**
623
- * Optional negation word used when a boolean value is false.
624
- * Examples: "not" → "is not Magical"
625
- */
626
- textNoWord: string2().optional()
627
- });
628
- var validate = (_config) => {
629
- return boolean().optional();
630
- };
631
-
632
- // src/Filter/filters/boolean/boolean.ts
633
- var boolean2 = createFilter_default({
634
- components: { Display: Display_default, Form: Form_default },
635
- defaults: {
636
- value: true,
637
- config: { text: "Active", textPrefix: "is", textNoWord: "no" }
638
- },
639
- validation: validate
640
- });
641
-
642
- // src/Filter/filters/checkboxes/Display.tsx
643
- import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
644
- var Display2 = ({
645
- value,
646
- config: { text, options }
647
- }) => {
648
- if (value && value.length > 0) {
649
- return /* @__PURE__ */ jsxs6("span", { className: "flex items-center gap-1", children: [
650
- text,
651
- " is",
652
- value.map((val) => {
653
- var _a;
654
- const option = options.find((op) => {
655
- return op.value === val;
656
- });
657
- const label = (_a = option == null ? void 0 : option.label) != null ? _a : val;
658
- const resolvedLabel = typeof label === "function" ? label("display") : label;
659
- return /* @__PURE__ */ jsx9("span", { children: resolvedLabel }, val);
660
- })
661
- ] });
662
- }
663
- return `${text} is ...`;
664
- };
665
- var Display_default2 = Display2;
666
-
667
- // src/Filter/filters/checkboxes/Form.tsx
668
- import Checkboxes from "@fuf-stack/uniform/Checkboxes";
669
- import { jsx as jsx10 } from "react/jsx-runtime";
670
- var Form3 = ({ fieldName, config: config3 }) => {
671
- const resolvedOptions = config3.options.map((option) => {
672
- return __spreadProps(__spreadValues({}, option), {
673
- label: typeof option.label === "function" ? option.label("form") : option.label
674
- });
675
- });
676
- return /* @__PURE__ */ jsx10(Checkboxes, { name: fieldName, options: resolvedOptions });
677
- };
678
- var Form_default2 = Form3;
679
-
680
- // src/Filter/filters/checkboxes/schema.ts
681
- import { any, array, object as object3, refineArray, string as string3 } from "@fuf-stack/veto";
682
- var config2 = object3({
683
- /**
684
- * Human‑readable label used in the UI (e.g. label and modal header).
685
- * Example: "Snacks", "Mood"
686
- */
687
- text: string3(),
688
- /**
689
- * Options rendered as multiple checkboxes. Each option needs a `label`
690
- * (what the user sees) and a `value` (what is written into the form state).
691
- * Label can be a string, React node, or a function that receives mode
692
- * ('form' or 'display') and returns a React node.
693
- */
694
- options: array(object3({ label: any(), value: string3() }))
695
- });
696
- var validate2 = (cfg) => {
697
- return refineArray(array(string3()).optional())({
698
- unique: true,
699
- custom: (values, ctx) => {
700
- if (!cfg) {
701
- return;
702
- }
703
- values.forEach((value) => {
704
- if (!cfg.options.find((option) => {
705
- return (option == null ? void 0 : option.value) === value;
706
- })) {
707
- ctx.addIssue({
708
- code: "custom",
709
- message: `Invalid value: ${value}`
710
- });
711
- }
712
- });
713
- }
714
- });
715
- };
716
-
717
- // src/Filter/filters/checkboxes/checkboxes.ts
718
- var checkboxes = createFilter_default({
719
- components: { Display: Display_default2, Form: Form_default2 },
720
- defaults: { value: [], config: { text: "Options", options: [] } },
721
- validation: validate2
722
- });
723
-
724
- // src/Filter/index.ts
725
- var filters = {
726
- boolean: boolean2,
727
- checkboxes
728
- };
729
- var Filter_default2 = Filter_default;
730
-
731
- export {
732
- filterVariants,
733
- createFilter_default,
734
- filters,
735
- Filter_default2 as Filter_default
736
- };
737
- //# sourceMappingURL=chunk-NQHJXFFH.js.map