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