@fuf-stack/megapixels 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Filter/index.cjs +11 -0
- package/dist/Filter/index.cjs.map +1 -0
- package/dist/Filter/index.d.cts +219 -0
- package/dist/Filter/index.d.ts +219 -0
- package/dist/Filter/index.js +11 -0
- package/dist/Filter/index.js.map +1 -0
- package/dist/chunk-X574WZ6N.js +620 -0
- package/dist/chunk-X574WZ6N.js.map +1 -0
- package/dist/chunk-XMMMIB2C.cjs +620 -0
- package/dist/chunk-XMMMIB2C.cjs.map +1 -0
- package/dist/index.cjs +9 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +8 -0
- package/package.json +10 -4
|
@@ -0,0 +1,620 @@
|
|
|
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 { cn as cn3 } from "@fuf-stack/pixel-utils";
|
|
23
|
+
import Form from "@fuf-stack/uniform/Form";
|
|
24
|
+
|
|
25
|
+
// src/Filter/hooks/useFilterValidation.ts
|
|
26
|
+
import { useMemo } from "react";
|
|
27
|
+
import { object, string, stringToJSON, veto } from "@fuf-stack/veto";
|
|
28
|
+
var useFilterValidation = (filters2, withSearch) => {
|
|
29
|
+
return useMemo(() => {
|
|
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: stringToJSON().pipe(object(filterValidation)).or(object(filterValidation)).optional()
|
|
39
|
+
}, withSearch ? { search: string({ min: 0 }).nullable().optional() } : {});
|
|
40
|
+
return veto(validationObject);
|
|
41
|
+
}, [filters2, withSearch]);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// src/Filter/Subcomponents/ActiveFilters.tsx
|
|
45
|
+
import Label from "@fuf-stack/pixels/Label";
|
|
46
|
+
|
|
47
|
+
// src/Filter/Subcomponents/FiltersContext.tsx
|
|
48
|
+
import {
|
|
49
|
+
createContext,
|
|
50
|
+
useCallback,
|
|
51
|
+
useContext,
|
|
52
|
+
useEffect,
|
|
53
|
+
useMemo as useMemo2,
|
|
54
|
+
useRef,
|
|
55
|
+
useState
|
|
56
|
+
} from "react";
|
|
57
|
+
import { useFormContext } from "@fuf-stack/uniform/hooks";
|
|
58
|
+
import { jsx } from "react/jsx-runtime";
|
|
59
|
+
var FiltersContext = createContext(
|
|
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
|
+
} = useFormContext();
|
|
74
|
+
const [currentModalFilter, setCurrentModalFilter] = useState(null);
|
|
75
|
+
const filterValue = watch("filter", {});
|
|
76
|
+
const getFilterFormFieldName = useCallback((name) => {
|
|
77
|
+
return `filter.${name}`;
|
|
78
|
+
}, []);
|
|
79
|
+
const getFilterValueByName = useCallback(
|
|
80
|
+
(name) => {
|
|
81
|
+
return filterValue[name];
|
|
82
|
+
},
|
|
83
|
+
[filterValue]
|
|
84
|
+
);
|
|
85
|
+
const showFilterModal = useCallback(
|
|
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 = useCallback(() => {
|
|
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 = useRef(0);
|
|
108
|
+
useEffect(() => {
|
|
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 = useMemo2(() => {
|
|
119
|
+
return config3.filter((f) => {
|
|
120
|
+
return Object.hasOwn(filterValue || {}, f.name);
|
|
121
|
+
}).map((f) => {
|
|
122
|
+
return f.name;
|
|
123
|
+
});
|
|
124
|
+
}, [config3, filterValue]);
|
|
125
|
+
const unusedFilters = useMemo2(() => {
|
|
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 = useCallback(
|
|
133
|
+
(name) => {
|
|
134
|
+
return config3.find((f) => {
|
|
135
|
+
return f.name === name;
|
|
136
|
+
});
|
|
137
|
+
},
|
|
138
|
+
[config3]
|
|
139
|
+
);
|
|
140
|
+
const addFilter = useCallback(
|
|
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 = useCallback(
|
|
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 = useCallback(
|
|
170
|
+
(name) => {
|
|
171
|
+
return getFieldState(getFilterFormFieldName(name)).invalid;
|
|
172
|
+
},
|
|
173
|
+
[getFieldState, getFilterFormFieldName]
|
|
174
|
+
);
|
|
175
|
+
const contextValue = useMemo2(() => {
|
|
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__ */ jsx(FiltersContext.Provider, { value: contextValue, children });
|
|
203
|
+
};
|
|
204
|
+
var useFilters = () => {
|
|
205
|
+
const ctx = useContext(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
|
+
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
214
|
+
var ActiveFilters = () => {
|
|
215
|
+
const {
|
|
216
|
+
activeFilters,
|
|
217
|
+
getFilterValueByName,
|
|
218
|
+
getFilterInstanceByName,
|
|
219
|
+
hasError,
|
|
220
|
+
removeFilter,
|
|
221
|
+
showFilterModal
|
|
222
|
+
} = useFilters();
|
|
223
|
+
return /* @__PURE__ */ jsx2(Fragment, { children: activeFilters.map((name) => {
|
|
224
|
+
const instance = getFilterInstanceByName(name);
|
|
225
|
+
const value = getFilterValueByName(name);
|
|
226
|
+
const DisplayComponent = instance.components.Display;
|
|
227
|
+
return /* @__PURE__ */ jsx2(
|
|
228
|
+
"button",
|
|
229
|
+
{
|
|
230
|
+
"aria-label": `Open ${name} filter`,
|
|
231
|
+
type: "button",
|
|
232
|
+
onClick: () => {
|
|
233
|
+
return void showFilterModal(name);
|
|
234
|
+
},
|
|
235
|
+
children: /* @__PURE__ */ jsxs(
|
|
236
|
+
Label,
|
|
237
|
+
{
|
|
238
|
+
className: "dark:text-foreground h-8 cursor-pointer",
|
|
239
|
+
color: hasError(name) ? "danger" : "primary",
|
|
240
|
+
variant: "flat",
|
|
241
|
+
onClose: () => {
|
|
242
|
+
removeFilter(name);
|
|
243
|
+
},
|
|
244
|
+
children: [
|
|
245
|
+
instance.icon,
|
|
246
|
+
DisplayComponent ? /* @__PURE__ */ jsx2(DisplayComponent, { config: instance.config, value }) : null
|
|
247
|
+
]
|
|
248
|
+
}
|
|
249
|
+
)
|
|
250
|
+
},
|
|
251
|
+
name
|
|
252
|
+
);
|
|
253
|
+
}) });
|
|
254
|
+
};
|
|
255
|
+
var ActiveFilters_default = ActiveFilters;
|
|
256
|
+
|
|
257
|
+
// src/Filter/Subcomponents/AddFilterMenu.tsx
|
|
258
|
+
import { FaSliders } from "react-icons/fa6";
|
|
259
|
+
import { cn } from "@fuf-stack/pixel-utils";
|
|
260
|
+
import Menu from "@fuf-stack/pixels/Menu";
|
|
261
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
262
|
+
var AddFilterMenu = ({ className = void 0 }) => {
|
|
263
|
+
const { unusedFilters, addFilter, getFilterInstanceByName } = useFilters();
|
|
264
|
+
const menuItems = unusedFilters.map((name) => {
|
|
265
|
+
var _a;
|
|
266
|
+
const instance = getFilterInstanceByName(name);
|
|
267
|
+
const config3 = instance.config;
|
|
268
|
+
const label = (_a = config3 == null ? void 0 : config3.text) != null ? _a : name;
|
|
269
|
+
return {
|
|
270
|
+
key: name,
|
|
271
|
+
icon: instance.icon,
|
|
272
|
+
label,
|
|
273
|
+
onClick: () => {
|
|
274
|
+
addFilter(name);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
});
|
|
278
|
+
return /* @__PURE__ */ jsxs2(
|
|
279
|
+
Menu,
|
|
280
|
+
{
|
|
281
|
+
className: cn(className),
|
|
282
|
+
isDisabled: !menuItems.length,
|
|
283
|
+
items: menuItems,
|
|
284
|
+
placement: "bottom-start",
|
|
285
|
+
triggerButtonProps: {
|
|
286
|
+
"aria-label": "Add Filter",
|
|
287
|
+
size: "sm",
|
|
288
|
+
variant: "bordered"
|
|
289
|
+
},
|
|
290
|
+
children: [
|
|
291
|
+
/* @__PURE__ */ jsx3(FaSliders, {}),
|
|
292
|
+
"Filter"
|
|
293
|
+
]
|
|
294
|
+
}
|
|
295
|
+
);
|
|
296
|
+
};
|
|
297
|
+
var AddFilterMenu_default = AddFilterMenu;
|
|
298
|
+
|
|
299
|
+
// src/Filter/Subcomponents/FilterModal.tsx
|
|
300
|
+
import { Suspense } from "react";
|
|
301
|
+
import { PiSlidersHorizontalBold } from "react-icons/pi";
|
|
302
|
+
import Button from "@fuf-stack/pixels/Button";
|
|
303
|
+
import Modal from "@fuf-stack/pixels/Modal";
|
|
304
|
+
import SubmitButton from "@fuf-stack/uniform/SubmitButton";
|
|
305
|
+
import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
306
|
+
var FilterModal = () => {
|
|
307
|
+
var _a, _b;
|
|
308
|
+
const {
|
|
309
|
+
closeFilterModal,
|
|
310
|
+
getFilterFormFieldName,
|
|
311
|
+
getFilterInstanceByName,
|
|
312
|
+
modalFilterName,
|
|
313
|
+
removeFilter
|
|
314
|
+
} = useFilters();
|
|
315
|
+
if (!modalFilterName) {
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
const instance = getFilterInstanceByName(modalFilterName);
|
|
319
|
+
const config3 = instance.config;
|
|
320
|
+
const FormComponent = instance.components.Form;
|
|
321
|
+
return /* @__PURE__ */ jsx4(
|
|
322
|
+
Modal,
|
|
323
|
+
{
|
|
324
|
+
isOpen: true,
|
|
325
|
+
onClose: closeFilterModal,
|
|
326
|
+
className: {
|
|
327
|
+
footer: "justify-between",
|
|
328
|
+
header: "text-default-700 flex items-center gap-3"
|
|
329
|
+
},
|
|
330
|
+
footer: /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
331
|
+
/* @__PURE__ */ jsx4(
|
|
332
|
+
Button,
|
|
333
|
+
{
|
|
334
|
+
color: "danger",
|
|
335
|
+
variant: "flat",
|
|
336
|
+
onClick: () => {
|
|
337
|
+
removeFilter(modalFilterName);
|
|
338
|
+
},
|
|
339
|
+
children: "Remove"
|
|
340
|
+
}
|
|
341
|
+
),
|
|
342
|
+
/* @__PURE__ */ jsx4(SubmitButton, { children: "Apply Filter" })
|
|
343
|
+
] }),
|
|
344
|
+
header: /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
345
|
+
(_a = instance.icon) != null ? _a : /* @__PURE__ */ jsx4(PiSlidersHorizontalBold, {}),
|
|
346
|
+
/* @__PURE__ */ jsx4("div", { children: `${(_b = config3 == null ? void 0 : config3.text) != null ? _b : modalFilterName} Filter` })
|
|
347
|
+
] }),
|
|
348
|
+
children: /* @__PURE__ */ jsx4(Suspense, { children: /* @__PURE__ */ jsx4(
|
|
349
|
+
FormComponent,
|
|
350
|
+
{
|
|
351
|
+
config: config3,
|
|
352
|
+
fieldName: getFilterFormFieldName(modalFilterName)
|
|
353
|
+
}
|
|
354
|
+
) })
|
|
355
|
+
}
|
|
356
|
+
);
|
|
357
|
+
};
|
|
358
|
+
var FilterModal_default = FilterModal;
|
|
359
|
+
|
|
360
|
+
// src/Filter/Subcomponents/SearchInput.tsx
|
|
361
|
+
import { useState as useState2 } from "react";
|
|
362
|
+
import { FaSearch } from "react-icons/fa";
|
|
363
|
+
import { motion } from "@fuf-stack/pixel-motion";
|
|
364
|
+
import { cn as cn2 } from "@fuf-stack/pixel-utils";
|
|
365
|
+
import Button2 from "@fuf-stack/pixels/Button";
|
|
366
|
+
import { useFormContext as useFormContext2 } from "@fuf-stack/uniform/hooks";
|
|
367
|
+
import Input from "@fuf-stack/uniform/Input";
|
|
368
|
+
import SubmitButton2 from "@fuf-stack/uniform/SubmitButton";
|
|
369
|
+
import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
370
|
+
var SearchInput = ({ className = void 0, config: config3 }) => {
|
|
371
|
+
var _a;
|
|
372
|
+
const { formState, setFocus, triggerSubmit } = useFormContext2();
|
|
373
|
+
const isInitiallyVisible = !!((_a = formState == null ? void 0 : formState.defaultValues) == null ? void 0 : _a.search);
|
|
374
|
+
const [isVisible, setIsVisible] = useState2(isInitiallyVisible);
|
|
375
|
+
const placeholder = typeof config3 === "object" ? config3.placeholder : void 0;
|
|
376
|
+
return /* @__PURE__ */ jsxs4("div", { className: cn2("flex items-center", className), children: [
|
|
377
|
+
!isVisible && /* @__PURE__ */ jsx5(
|
|
378
|
+
Button2,
|
|
379
|
+
{
|
|
380
|
+
"aria-label": "Show search input",
|
|
381
|
+
icon: /* @__PURE__ */ jsx5(FaSearch, {}),
|
|
382
|
+
size: "sm",
|
|
383
|
+
variant: "bordered",
|
|
384
|
+
onClick: () => {
|
|
385
|
+
setIsVisible(true);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
),
|
|
389
|
+
isVisible ? /* @__PURE__ */ jsxs4(
|
|
390
|
+
motion.div,
|
|
391
|
+
{
|
|
392
|
+
animate: { opacity: 1 },
|
|
393
|
+
className: "flex w-72 gap-2",
|
|
394
|
+
initial: { opacity: 0.5 },
|
|
395
|
+
onAnimationComplete: () => {
|
|
396
|
+
if (!isInitiallyVisible) {
|
|
397
|
+
setFocus("search");
|
|
398
|
+
}
|
|
399
|
+
},
|
|
400
|
+
transition: {
|
|
401
|
+
// if the input was not initially visible, animate in
|
|
402
|
+
duration: isInitiallyVisible ? 0 : 0.3,
|
|
403
|
+
ease: "circOut"
|
|
404
|
+
},
|
|
405
|
+
children: [
|
|
406
|
+
/* @__PURE__ */ jsx5(
|
|
407
|
+
Input,
|
|
408
|
+
{
|
|
409
|
+
clearable: true,
|
|
410
|
+
debounceDelay: 0,
|
|
411
|
+
name: "search",
|
|
412
|
+
placeholder,
|
|
413
|
+
size: "sm",
|
|
414
|
+
onClear: () => {
|
|
415
|
+
triggerSubmit();
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
),
|
|
419
|
+
/* @__PURE__ */ jsx5(
|
|
420
|
+
SubmitButton2,
|
|
421
|
+
{
|
|
422
|
+
children: null,
|
|
423
|
+
color: "primary",
|
|
424
|
+
icon: /* @__PURE__ */ jsx5(FaSearch, {}),
|
|
425
|
+
size: "sm"
|
|
426
|
+
}
|
|
427
|
+
)
|
|
428
|
+
]
|
|
429
|
+
},
|
|
430
|
+
"search-input"
|
|
431
|
+
) : null
|
|
432
|
+
] });
|
|
433
|
+
};
|
|
434
|
+
var SearchInput_default = SearchInput;
|
|
435
|
+
|
|
436
|
+
// src/Filter/Filter.tsx
|
|
437
|
+
import { Fragment as Fragment3, jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
438
|
+
var Filter = ({
|
|
439
|
+
children = void 0,
|
|
440
|
+
className = void 0,
|
|
441
|
+
config: config3,
|
|
442
|
+
formName = "filterComponentForm",
|
|
443
|
+
onChange,
|
|
444
|
+
values
|
|
445
|
+
}) => {
|
|
446
|
+
const handleSubmit = (nextValues) => {
|
|
447
|
+
onChange(nextValues);
|
|
448
|
+
};
|
|
449
|
+
const validation = useFilterValidation(
|
|
450
|
+
config3.filters,
|
|
451
|
+
Boolean(config3.search)
|
|
452
|
+
);
|
|
453
|
+
const { data: valuesValidated } = validation.validate(values);
|
|
454
|
+
return /* @__PURE__ */ jsxs5(Fragment3, { children: [
|
|
455
|
+
/* @__PURE__ */ jsxs5(
|
|
456
|
+
Form,
|
|
457
|
+
{
|
|
458
|
+
className: cn3("mb-3 flex flex-wrap gap-3", className),
|
|
459
|
+
debug: { disable: true },
|
|
460
|
+
initialValues: valuesValidated != null ? valuesValidated : {},
|
|
461
|
+
name: formName,
|
|
462
|
+
onSubmit: handleSubmit,
|
|
463
|
+
validation,
|
|
464
|
+
children: [
|
|
465
|
+
config3.search ? /* @__PURE__ */ jsx6(SearchInput_default, { config: config3.search }) : null,
|
|
466
|
+
/* @__PURE__ */ jsxs5(FiltersContextProvider, { config: config3.filters, children: [
|
|
467
|
+
/* @__PURE__ */ jsx6(ActiveFilters_default, {}),
|
|
468
|
+
/* @__PURE__ */ jsx6(AddFilterMenu_default, {}),
|
|
469
|
+
/* @__PURE__ */ jsx6(FilterModal_default, {})
|
|
470
|
+
] })
|
|
471
|
+
]
|
|
472
|
+
}
|
|
473
|
+
),
|
|
474
|
+
children == null ? void 0 : children(valuesValidated != null ? valuesValidated : {})
|
|
475
|
+
] });
|
|
476
|
+
};
|
|
477
|
+
var Filter_default = Filter;
|
|
478
|
+
|
|
479
|
+
// src/Filter/filters/createFilter.ts
|
|
480
|
+
var createFilter = (definition) => {
|
|
481
|
+
return ({ name, icon, config: config3 }) => {
|
|
482
|
+
return {
|
|
483
|
+
components: definition.components,
|
|
484
|
+
config: __spreadValues(__spreadValues({}, definition.defaults.config), config3 != null ? config3 : {}),
|
|
485
|
+
defaultValue: definition.defaults.value,
|
|
486
|
+
icon,
|
|
487
|
+
name,
|
|
488
|
+
validation: definition.validation
|
|
489
|
+
};
|
|
490
|
+
};
|
|
491
|
+
};
|
|
492
|
+
var createFilter_default = createFilter;
|
|
493
|
+
|
|
494
|
+
// src/Filter/filters/boolean/Display.tsx
|
|
495
|
+
import { Fragment as Fragment4, jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
496
|
+
var Display = ({
|
|
497
|
+
value,
|
|
498
|
+
config: { text, textPrefix, textNoWord }
|
|
499
|
+
}) => {
|
|
500
|
+
if (typeof value === "boolean") {
|
|
501
|
+
return /* @__PURE__ */ jsxs6(Fragment4, { children: [
|
|
502
|
+
value ? textPrefix : `${textPrefix} ${textNoWord != null ? textNoWord : "no"}`,
|
|
503
|
+
" ",
|
|
504
|
+
text
|
|
505
|
+
] });
|
|
506
|
+
}
|
|
507
|
+
return /* @__PURE__ */ jsx7(Fragment4, { children: `${text}...` });
|
|
508
|
+
};
|
|
509
|
+
var Display_default = Display;
|
|
510
|
+
|
|
511
|
+
// src/Filter/filters/boolean/Form.tsx
|
|
512
|
+
import Switch from "@fuf-stack/uniform/Switch";
|
|
513
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
514
|
+
var Form2 = ({
|
|
515
|
+
fieldName,
|
|
516
|
+
config: { text, textPrefix }
|
|
517
|
+
}) => {
|
|
518
|
+
return /* @__PURE__ */ jsx8(Switch, { label: `${textPrefix} ${text}`, name: fieldName });
|
|
519
|
+
};
|
|
520
|
+
var Form_default = Form2;
|
|
521
|
+
|
|
522
|
+
// src/Filter/filters/boolean/schema.ts
|
|
523
|
+
import { boolean, object as object2, string as string2 } from "@fuf-stack/veto";
|
|
524
|
+
var config = object2({
|
|
525
|
+
/** TODO... */
|
|
526
|
+
text: string2(),
|
|
527
|
+
/** TODO... */
|
|
528
|
+
textPrefix: string2().optional(),
|
|
529
|
+
/** TODO... */
|
|
530
|
+
textNoWord: string2().optional()
|
|
531
|
+
});
|
|
532
|
+
var validate = (_config) => {
|
|
533
|
+
return boolean().optional();
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
// src/Filter/filters/boolean/boolean.ts
|
|
537
|
+
var boolean2 = createFilter_default({
|
|
538
|
+
components: { Display: Display_default, Form: Form_default },
|
|
539
|
+
defaults: {
|
|
540
|
+
value: true,
|
|
541
|
+
config: { text: "Active", textPrefix: "is", textNoWord: "no" }
|
|
542
|
+
},
|
|
543
|
+
validation: validate
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
// src/Filter/filters/checkboxgroup/Display.tsx
|
|
547
|
+
var Display2 = ({
|
|
548
|
+
value,
|
|
549
|
+
config: { text, options }
|
|
550
|
+
}) => {
|
|
551
|
+
if (value && value.length > 0) {
|
|
552
|
+
const labels = value.map((val) => {
|
|
553
|
+
var _a, _b;
|
|
554
|
+
return (_b = (_a = options.find((op) => {
|
|
555
|
+
return op.value === val;
|
|
556
|
+
})) == null ? void 0 : _a.label) != null ? _b : val;
|
|
557
|
+
}).join(", ");
|
|
558
|
+
return `${text} is ${labels}`;
|
|
559
|
+
}
|
|
560
|
+
return `${text} is ...`;
|
|
561
|
+
};
|
|
562
|
+
var Display_default2 = Display2;
|
|
563
|
+
|
|
564
|
+
// src/Filter/filters/checkboxgroup/Form.tsx
|
|
565
|
+
import CheckboxGroup from "@fuf-stack/uniform/CheckboxGroup";
|
|
566
|
+
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
567
|
+
var Form3 = ({ fieldName, config: config3 }) => {
|
|
568
|
+
return /* @__PURE__ */ jsx9(CheckboxGroup, { name: fieldName, options: config3.options });
|
|
569
|
+
};
|
|
570
|
+
var Form_default2 = Form3;
|
|
571
|
+
|
|
572
|
+
// src/Filter/filters/checkboxgroup/schema.ts
|
|
573
|
+
import { array, object as object3, refineArray, string as string3 } from "@fuf-stack/veto";
|
|
574
|
+
var config2 = object3({
|
|
575
|
+
/** TODO... */
|
|
576
|
+
text: string3(),
|
|
577
|
+
/** options... */
|
|
578
|
+
options: array(object3({ label: string3(), value: string3() }))
|
|
579
|
+
});
|
|
580
|
+
var validate2 = (cfg) => {
|
|
581
|
+
return refineArray(array(string3()).optional())({
|
|
582
|
+
unique: true,
|
|
583
|
+
custom: (values, ctx) => {
|
|
584
|
+
if (!cfg) {
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
values.forEach((value) => {
|
|
588
|
+
if (!cfg.options.find((option) => {
|
|
589
|
+
return (option == null ? void 0 : option.value) === value;
|
|
590
|
+
})) {
|
|
591
|
+
ctx.addIssue({
|
|
592
|
+
code: "custom",
|
|
593
|
+
message: `Invalid value: ${value}`
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
// src/Filter/filters/checkboxgroup/checkboxgroup.ts
|
|
602
|
+
var checkboxgroup = createFilter_default({
|
|
603
|
+
components: { Display: Display_default2, Form: Form_default2 },
|
|
604
|
+
defaults: { value: [], config: { text: "Options", options: [] } },
|
|
605
|
+
validation: validate2
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
// src/Filter/index.ts
|
|
609
|
+
var filters = {
|
|
610
|
+
boolean: boolean2,
|
|
611
|
+
checkboxgroup
|
|
612
|
+
};
|
|
613
|
+
var Filter_default2 = Filter_default;
|
|
614
|
+
|
|
615
|
+
export {
|
|
616
|
+
createFilter_default,
|
|
617
|
+
filters,
|
|
618
|
+
Filter_default2 as Filter_default
|
|
619
|
+
};
|
|
620
|
+
//# sourceMappingURL=chunk-X574WZ6N.js.map
|