@fuf-stack/megapixels 0.0.0 → 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 +12 -6
|
@@ -0,0 +1,620 @@
|
|
|
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 || {}, 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 = () => {
|
|
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
|
+
return void showFilterModal(name);
|
|
234
|
+
},
|
|
235
|
+
children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
236
|
+
_Label2.default,
|
|
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__ */ _jsxruntime.jsx.call(void 0, 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
|
+
var _fa6 = require('react-icons/fa6');
|
|
259
|
+
|
|
260
|
+
var _Menu = require('@fuf-stack/pixels/Menu'); var _Menu2 = _interopRequireDefault(_Menu);
|
|
261
|
+
|
|
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__ */ _jsxruntime.jsxs.call(void 0,
|
|
279
|
+
_Menu2.default,
|
|
280
|
+
{
|
|
281
|
+
className: _pixelutils.cn.call(void 0, 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__ */ _jsxruntime.jsx.call(void 0, _fa6.FaSliders, {}),
|
|
292
|
+
"Filter"
|
|
293
|
+
]
|
|
294
|
+
}
|
|
295
|
+
);
|
|
296
|
+
};
|
|
297
|
+
var AddFilterMenu_default = AddFilterMenu;
|
|
298
|
+
|
|
299
|
+
// src/Filter/Subcomponents/FilterModal.tsx
|
|
300
|
+
|
|
301
|
+
var _pi = require('react-icons/pi');
|
|
302
|
+
var _Button = require('@fuf-stack/pixels/Button'); var _Button2 = _interopRequireDefault(_Button);
|
|
303
|
+
var _Modal = require('@fuf-stack/pixels/Modal'); var _Modal2 = _interopRequireDefault(_Modal);
|
|
304
|
+
var _SubmitButton = require('@fuf-stack/uniform/SubmitButton'); var _SubmitButton2 = _interopRequireDefault(_SubmitButton);
|
|
305
|
+
|
|
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__ */ _jsxruntime.jsx.call(void 0,
|
|
322
|
+
_Modal2.default,
|
|
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__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
331
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
332
|
+
_Button2.default,
|
|
333
|
+
{
|
|
334
|
+
color: "danger",
|
|
335
|
+
variant: "flat",
|
|
336
|
+
onClick: () => {
|
|
337
|
+
removeFilter(modalFilterName);
|
|
338
|
+
},
|
|
339
|
+
children: "Remove"
|
|
340
|
+
}
|
|
341
|
+
),
|
|
342
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _SubmitButton2.default, { children: "Apply Filter" })
|
|
343
|
+
] }),
|
|
344
|
+
header: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
345
|
+
(_a = instance.icon) != null ? _a : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _pi.PiSlidersHorizontalBold, {}),
|
|
346
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { children: `${(_b = config3 == null ? void 0 : config3.text) != null ? _b : modalFilterName} Filter` })
|
|
347
|
+
] }),
|
|
348
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Suspense, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
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
|
+
|
|
362
|
+
var _fa = require('react-icons/fa');
|
|
363
|
+
var _pixelmotion = require('@fuf-stack/pixel-motion');
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
var _Input = require('@fuf-stack/uniform/Input'); var _Input2 = _interopRequireDefault(_Input);
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
var SearchInput = ({ className = void 0, config: config3 }) => {
|
|
371
|
+
var _a;
|
|
372
|
+
const { formState, setFocus, triggerSubmit } = _hooks.useFormContext.call(void 0, );
|
|
373
|
+
const isInitiallyVisible = !!((_a = formState == null ? void 0 : formState.defaultValues) == null ? void 0 : _a.search);
|
|
374
|
+
const [isVisible, setIsVisible] = _react.useState.call(void 0, isInitiallyVisible);
|
|
375
|
+
const placeholder = typeof config3 === "object" ? config3.placeholder : void 0;
|
|
376
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: _pixelutils.cn.call(void 0, "flex items-center", className), children: [
|
|
377
|
+
!isVisible && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
378
|
+
_Button2.default,
|
|
379
|
+
{
|
|
380
|
+
"aria-label": "Show search input",
|
|
381
|
+
icon: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _fa.FaSearch, {}),
|
|
382
|
+
size: "sm",
|
|
383
|
+
variant: "bordered",
|
|
384
|
+
onClick: () => {
|
|
385
|
+
setIsVisible(true);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
),
|
|
389
|
+
isVisible ? /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
390
|
+
_pixelmotion.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__ */ _jsxruntime.jsx.call(void 0,
|
|
407
|
+
_Input2.default,
|
|
408
|
+
{
|
|
409
|
+
clearable: true,
|
|
410
|
+
debounceDelay: 0,
|
|
411
|
+
name: "search",
|
|
412
|
+
placeholder,
|
|
413
|
+
size: "sm",
|
|
414
|
+
onClear: () => {
|
|
415
|
+
triggerSubmit();
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
),
|
|
419
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
420
|
+
_SubmitButton2.default,
|
|
421
|
+
{
|
|
422
|
+
children: null,
|
|
423
|
+
color: "primary",
|
|
424
|
+
icon: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _fa.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
|
+
|
|
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__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
455
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
456
|
+
_Form2.default,
|
|
457
|
+
{
|
|
458
|
+
className: _pixelutils.cn.call(void 0, "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__ */ _jsxruntime.jsx.call(void 0, SearchInput_default, { config: config3.search }) : null,
|
|
466
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, FiltersContextProvider, { config: config3.filters, children: [
|
|
467
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, ActiveFilters_default, {}),
|
|
468
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, AddFilterMenu_default, {}),
|
|
469
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, 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
|
+
|
|
496
|
+
var Display = ({
|
|
497
|
+
value,
|
|
498
|
+
config: { text, textPrefix, textNoWord }
|
|
499
|
+
}) => {
|
|
500
|
+
if (typeof value === "boolean") {
|
|
501
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
502
|
+
value ? textPrefix : `${textPrefix} ${textNoWord != null ? textNoWord : "no"}`,
|
|
503
|
+
" ",
|
|
504
|
+
text
|
|
505
|
+
] });
|
|
506
|
+
}
|
|
507
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children: `${text}...` });
|
|
508
|
+
};
|
|
509
|
+
var Display_default = Display;
|
|
510
|
+
|
|
511
|
+
// src/Filter/filters/boolean/Form.tsx
|
|
512
|
+
var _Switch = require('@fuf-stack/uniform/Switch'); var _Switch2 = _interopRequireDefault(_Switch);
|
|
513
|
+
|
|
514
|
+
var Form2 = ({
|
|
515
|
+
fieldName,
|
|
516
|
+
config: { text, textPrefix }
|
|
517
|
+
}) => {
|
|
518
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _Switch2.default, { label: `${textPrefix} ${text}`, name: fieldName });
|
|
519
|
+
};
|
|
520
|
+
var Form_default = Form2;
|
|
521
|
+
|
|
522
|
+
// src/Filter/filters/boolean/schema.ts
|
|
523
|
+
|
|
524
|
+
var config = _veto.object.call(void 0, {
|
|
525
|
+
/** TODO... */
|
|
526
|
+
text: _veto.string.call(void 0, ),
|
|
527
|
+
/** TODO... */
|
|
528
|
+
textPrefix: _veto.string.call(void 0, ).optional(),
|
|
529
|
+
/** TODO... */
|
|
530
|
+
textNoWord: _veto.string.call(void 0, ).optional()
|
|
531
|
+
});
|
|
532
|
+
var validate = (_config) => {
|
|
533
|
+
return _veto.boolean.call(void 0, ).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
|
+
var _CheckboxGroup = require('@fuf-stack/uniform/CheckboxGroup'); var _CheckboxGroup2 = _interopRequireDefault(_CheckboxGroup);
|
|
566
|
+
|
|
567
|
+
var Form3 = ({ fieldName, config: config3 }) => {
|
|
568
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _CheckboxGroup2.default, { name: fieldName, options: config3.options });
|
|
569
|
+
};
|
|
570
|
+
var Form_default2 = Form3;
|
|
571
|
+
|
|
572
|
+
// src/Filter/filters/checkboxgroup/schema.ts
|
|
573
|
+
|
|
574
|
+
var config2 = _veto.object.call(void 0, {
|
|
575
|
+
/** TODO... */
|
|
576
|
+
text: _veto.string.call(void 0, ),
|
|
577
|
+
/** options... */
|
|
578
|
+
options: _veto.array.call(void 0, _veto.object.call(void 0, { label: _veto.string.call(void 0, ), value: _veto.string.call(void 0, ) }))
|
|
579
|
+
});
|
|
580
|
+
var validate2 = (cfg) => {
|
|
581
|
+
return _veto.refineArray.call(void 0, _veto.array.call(void 0, _veto.string.call(void 0, )).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
|
+
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
exports.createFilter_default = createFilter_default; exports.filters = filters; exports.Filter_default = Filter_default2;
|
|
620
|
+
//# sourceMappingURL=chunk-XMMMIB2C.cjs.map
|