@kumix/ui 0.3.6 → 0.3.8
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/README.md +25 -24
- package/dist/cascader-types-BnH6wYD-.d.ts +183 -0
- package/dist/cascader-types-BnH6wYD-.d.ts.map +1 -0
- package/dist/components/agents/ai-sidebar.d.ts +17 -1
- package/dist/components/agents/ai-sidebar.d.ts.map +1 -1
- package/dist/components/agents/ai-sidebar.js +90 -14
- package/dist/components/agents/ai-sidebar.js.map +1 -1
- package/dist/components/agents/chat-app.d.ts +10 -5
- package/dist/components/agents/chat-app.d.ts.map +1 -1
- package/dist/components/agents/chat-app.js +54 -5
- package/dist/components/agents/chat-app.js.map +1 -1
- package/dist/components/agents/citations.d.ts.map +1 -1
- package/dist/components/agents/citations.js +5 -6
- package/dist/components/agents/citations.js.map +1 -1
- package/dist/components/agents/tool-approval.d.ts.map +1 -1
- package/dist/components/agents/tool-approval.js +1 -1
- package/dist/components/agents/tool-approval.js.map +1 -1
- package/dist/components/motion/action-swap.d.ts.map +1 -1
- package/dist/components/motion/action-swap.js +2 -2
- package/dist/components/motion/action-swap.js.map +1 -1
- package/dist/components/motion/animated-sidebar.d.ts.map +1 -1
- package/dist/components/motion/animated-sidebar.js +13 -3
- package/dist/components/motion/animated-sidebar.js.map +1 -1
- package/dist/components/motion/attachment-upload.d.ts.map +1 -1
- package/dist/components/motion/attachment-upload.js +9 -5
- package/dist/components/motion/attachment-upload.js.map +1 -1
- package/dist/components/motion/availability-scheduler/copy-menu.js +1 -1
- package/dist/components/motion/availability-scheduler/day-row.d.ts +5 -2
- package/dist/components/motion/availability-scheduler/day-row.d.ts.map +1 -1
- package/dist/components/motion/availability-scheduler/day-row.js +18 -8
- package/dist/components/motion/availability-scheduler/day-row.js.map +1 -1
- package/dist/components/motion/availability-scheduler/index.d.ts.map +1 -1
- package/dist/components/motion/availability-scheduler/index.js +27 -5
- package/dist/components/motion/availability-scheduler/index.js.map +1 -1
- package/dist/components/motion/availability-scheduler/time-select.d.ts +3 -1
- package/dist/components/motion/availability-scheduler/time-select.d.ts.map +1 -1
- package/dist/components/motion/availability-scheduler/time-select.js +3 -1
- package/dist/components/motion/availability-scheduler/time-select.js.map +1 -1
- package/dist/components/motion/bottom-sheet.d.ts.map +1 -1
- package/dist/components/motion/bottom-sheet.js +78 -74
- package/dist/components/motion/bottom-sheet.js.map +1 -1
- package/dist/components/motion/center-morph-modal.d.ts.map +1 -1
- package/dist/components/motion/center-morph-modal.js +82 -88
- package/dist/components/motion/center-morph-modal.js.map +1 -1
- package/dist/components/motion/command-palette.d.ts.map +1 -1
- package/dist/components/motion/command-palette.js +51 -27
- package/dist/components/motion/command-palette.js.map +1 -1
- package/dist/components/motion/context-menu.d.ts.map +1 -1
- package/dist/components/motion/context-menu.js +16 -6
- package/dist/components/motion/context-menu.js.map +1 -1
- package/dist/components/motion/cylinder-carousel.d.ts.map +1 -1
- package/dist/components/motion/cylinder-carousel.js +4 -3
- package/dist/components/motion/cylinder-carousel.js.map +1 -1
- package/dist/components/motion/drawer.d.ts.map +1 -1
- package/dist/components/motion/drawer.js +30 -30
- package/dist/components/motion/drawer.js.map +1 -1
- package/dist/components/motion/expandable-action-bar.d.ts +6 -0
- package/dist/components/motion/expandable-action-bar.d.ts.map +1 -1
- package/dist/components/motion/expandable-action-bar.js +38 -9
- package/dist/components/motion/expandable-action-bar.js.map +1 -1
- package/dist/components/motion/hold-action-button.d.ts +1 -1
- package/dist/components/motion/hold-action-button.d.ts.map +1 -1
- package/dist/components/motion/hold-action-button.js +64 -50
- package/dist/components/motion/hold-action-button.js.map +1 -1
- package/dist/components/motion/loader.js +20 -22
- package/dist/components/motion/loader.js.map +1 -1
- package/dist/components/motion/morphing-modal.d.ts.map +1 -1
- package/dist/components/motion/morphing-modal.js +83 -83
- package/dist/components/motion/morphing-modal.js.map +1 -1
- package/dist/components/motion/morphing-search.d.ts +28 -0
- package/dist/components/motion/morphing-search.d.ts.map +1 -0
- package/dist/components/motion/morphing-search.js +418 -0
- package/dist/components/motion/morphing-search.js.map +1 -0
- package/dist/components/motion/morphing-tabs.d.ts.map +1 -1
- package/dist/components/motion/morphing-tabs.js +59 -18
- package/dist/components/motion/morphing-tabs.js.map +1 -1
- package/dist/components/motion/notification-stack.d.ts.map +1 -1
- package/dist/components/motion/notification-stack.js +28 -11
- package/dist/components/motion/notification-stack.js.map +1 -1
- package/dist/components/motion/popover-morph.d.ts.map +1 -1
- package/dist/components/motion/popover-morph.js +26 -11
- package/dist/components/motion/popover-morph.js.map +1 -1
- package/dist/components/motion/popover.d.ts.map +1 -1
- package/dist/components/motion/popover.js +39 -28
- package/dist/components/motion/popover.js.map +1 -1
- package/dist/components/motion/preview-rail.d.ts.map +1 -1
- package/dist/components/motion/preview-rail.js +42 -13
- package/dist/components/motion/preview-rail.js.map +1 -1
- package/dist/components/motion/project-folder.js +20 -20
- package/dist/components/motion/project-folder.js.map +1 -1
- package/dist/components/motion/pull-to-refresh.d.ts.map +1 -1
- package/dist/components/motion/pull-to-refresh.js +8 -7
- package/dist/components/motion/pull-to-refresh.js.map +1 -1
- package/dist/components/motion/range-slider-bubble.d.ts.map +1 -1
- package/dist/components/motion/range-slider-bubble.js +2 -1
- package/dist/components/motion/range-slider-bubble.js.map +1 -1
- package/dist/components/motion/range-slider-fluid.d.ts.map +1 -1
- package/dist/components/motion/range-slider-fluid.js +2 -1
- package/dist/components/motion/range-slider-fluid.js.map +1 -1
- package/dist/components/motion/range-slider-ruler.d.ts.map +1 -1
- package/dist/components/motion/range-slider-ruler.js +2 -1
- package/dist/components/motion/range-slider-ruler.js.map +1 -1
- package/dist/components/motion/range-slider-wave.d.ts.map +1 -1
- package/dist/components/motion/range-slider-wave.js +2 -1
- package/dist/components/motion/range-slider-wave.js.map +1 -1
- package/dist/components/motion/range-slider.d.ts.map +1 -1
- package/dist/components/motion/range-slider.js +2 -1
- package/dist/components/motion/range-slider.js.map +1 -1
- package/dist/components/motion/select.d.ts +15 -1
- package/dist/components/motion/select.d.ts.map +1 -1
- package/dist/components/motion/select.js +15 -4
- package/dist/components/motion/select.js.map +1 -1
- package/dist/components/motion/slide-action-button.d.ts.map +1 -1
- package/dist/components/motion/slide-action-button.js +3 -2
- package/dist/components/motion/slide-action-button.js.map +1 -1
- package/dist/components/motion/swipeable-list.d.ts.map +1 -1
- package/dist/components/motion/swipeable-list.js +2 -1
- package/dist/components/motion/swipeable-list.js.map +1 -1
- package/dist/components/motion/table/index.d.ts.map +1 -1
- package/dist/components/motion/table/index.js +64 -6
- package/dist/components/motion/table/index.js.map +1 -1
- package/dist/components/motion/table/table-header.d.ts.map +1 -1
- package/dist/components/motion/table/table-header.js +3 -2
- package/dist/components/motion/table/table-header.js.map +1 -1
- package/dist/components/motion/text-reveal.d.ts.map +1 -1
- package/dist/components/motion/text-reveal.js +72 -48
- package/dist/components/motion/text-reveal.js.map +1 -1
- package/dist/components/motion/tooltip.d.ts.map +1 -1
- package/dist/components/motion/tooltip.js +35 -15
- package/dist/components/motion/tooltip.js.map +1 -1
- package/dist/components/motion/wheel-picker.d.ts.map +1 -1
- package/dist/components/motion/wheel-picker.js +4 -3
- package/dist/components/motion/wheel-picker.js.map +1 -1
- package/dist/components/reui/badge.d.ts +1 -1
- package/dist/components/reui/cascader/cascader-async.d.ts +90 -0
- package/dist/components/reui/cascader/cascader-async.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-async.js +549 -0
- package/dist/components/reui/cascader/cascader-async.js.map +1 -0
- package/dist/components/reui/cascader/cascader-columns.d.ts +29 -0
- package/dist/components/reui/cascader/cascader-columns.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-columns.js +135 -0
- package/dist/components/reui/cascader/cascader-columns.js.map +1 -0
- package/dist/components/reui/cascader/cascader-context.d.ts +193 -0
- package/dist/components/reui/cascader/cascader-context.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-context.js +59 -0
- package/dist/components/reui/cascader/cascader-context.js.map +1 -0
- package/dist/components/reui/cascader/cascader-footer.d.ts +85 -0
- package/dist/components/reui/cascader/cascader-footer.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-footer.js +456 -0
- package/dist/components/reui/cascader/cascader-footer.js.map +1 -0
- package/dist/components/reui/cascader/cascader-i18n.d.ts +17 -0
- package/dist/components/reui/cascader/cascader-i18n.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-i18n.js +68 -0
- package/dist/components/reui/cascader/cascader-i18n.js.map +1 -0
- package/dist/components/reui/cascader/cascader-item.d.ts +115 -0
- package/dist/components/reui/cascader/cascader-item.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-item.js +530 -0
- package/dist/components/reui/cascader/cascader-item.js.map +1 -0
- package/dist/components/reui/cascader/cascader-lib.d.ts +141 -0
- package/dist/components/reui/cascader/cascader-lib.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-lib.js +576 -0
- package/dist/components/reui/cascader/cascader-lib.js.map +1 -0
- package/dist/components/reui/cascader/cascader-nav.d.ts +59 -0
- package/dist/components/reui/cascader/cascader-nav.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-nav.js +312 -0
- package/dist/components/reui/cascader/cascader-nav.js.map +1 -0
- package/dist/components/reui/cascader/cascader-types.d.ts +2 -0
- package/dist/components/reui/cascader/cascader-types.js +2 -0
- package/dist/components/reui/cascader/cascader-virtual.d.ts +65 -0
- package/dist/components/reui/cascader/cascader-virtual.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader-virtual.js +240 -0
- package/dist/components/reui/cascader/cascader-virtual.js.map +1 -0
- package/dist/components/reui/cascader/cascader.d.ts +322 -0
- package/dist/components/reui/cascader/cascader.d.ts.map +1 -0
- package/dist/components/reui/cascader/cascader.js +1459 -0
- package/dist/components/reui/cascader/cascader.js.map +1 -0
- package/dist/components/reui/event-calendar/event-calendar-event.d.ts +28 -47
- package/dist/components/reui/event-calendar/event-calendar-event.d.ts.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-event.js +26 -44
- package/dist/components/reui/event-calendar/event-calendar-event.js.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-nav.js +1 -1
- package/dist/components/reui/event-calendar/event-calendar-types.d.ts +19 -57
- package/dist/components/reui/event-calendar/event-calendar-types.d.ts.map +1 -1
- package/dist/components/reui/filters/filters-advanced.d.ts +52 -0
- package/dist/components/reui/filters/filters-advanced.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-advanced.js +1191 -0
- package/dist/components/reui/filters/filters-advanced.js.map +1 -0
- package/dist/components/reui/filters/filters-builder.d.ts +43 -0
- package/dist/components/reui/filters/filters-builder.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-builder.js +152 -0
- package/dist/components/reui/filters/filters-builder.js.map +1 -0
- package/dist/components/reui/filters/filters-chip.d.ts +79 -0
- package/dist/components/reui/filters/filters-chip.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-chip.js +553 -0
- package/dist/components/reui/filters/filters-chip.js.map +1 -0
- package/dist/components/reui/filters/filters-context.d.ts +290 -0
- package/dist/components/reui/filters/filters-context.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-context.js +277 -0
- package/dist/components/reui/filters/filters-context.js.map +1 -0
- package/dist/components/reui/filters/filters-date.d.ts +43 -0
- package/dist/components/reui/filters/filters-date.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-date.js +143 -0
- package/dist/components/reui/filters/filters-date.js.map +1 -0
- package/dist/components/reui/filters/filters-dnd.d.ts +101 -0
- package/dist/components/reui/filters/filters-dnd.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-dnd.js +454 -0
- package/dist/components/reui/filters/filters-dnd.js.map +1 -0
- package/dist/components/reui/filters/filters-draft.d.ts +2 -0
- package/dist/components/reui/filters/filters-draft.js +128 -0
- package/dist/components/reui/filters/filters-draft.js.map +1 -0
- package/dist/components/reui/filters/filters-editors.d.ts +91 -0
- package/dist/components/reui/filters/filters-editors.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-editors.js +773 -0
- package/dist/components/reui/filters/filters-editors.js.map +1 -0
- package/dist/components/reui/filters/filters-i18n.d.ts +24 -0
- package/dist/components/reui/filters/filters-i18n.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-i18n.js +127 -0
- package/dist/components/reui/filters/filters-i18n.js.map +1 -0
- package/dist/components/reui/filters/filters-lib.d.ts +171 -0
- package/dist/components/reui/filters/filters-lib.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-lib.js +336 -0
- package/dist/components/reui/filters/filters-lib.js.map +1 -0
- package/dist/components/reui/filters/filters-operators.d.ts +49 -0
- package/dist/components/reui/filters/filters-operators.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-operators.js +300 -0
- package/dist/components/reui/filters/filters-operators.js.map +1 -0
- package/dist/components/reui/filters/filters-query.d.ts +132 -0
- package/dist/components/reui/filters/filters-query.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-query.js +476 -0
- package/dist/components/reui/filters/filters-query.js.map +1 -0
- package/dist/components/reui/filters/filters-types.d.ts +452 -0
- package/dist/components/reui/filters/filters-types.d.ts.map +1 -0
- package/dist/components/reui/filters/filters-types.js +2 -0
- package/dist/components/reui/filters/filters.d.ts +114 -0
- package/dist/components/reui/filters/filters.d.ts.map +1 -0
- package/dist/components/reui/filters/filters.js +638 -0
- package/dist/components/reui/filters/filters.js.map +1 -0
- package/dist/components/reui/frame.d.ts +1 -1
- package/dist/components/reui/gantt/gantt-bar.js +1 -1
- package/dist/components/reui/gantt/gantt-nav.js +1 -1
- package/dist/components/reui/gantt/gantt-types.d.ts +25 -71
- package/dist/components/reui/gantt/gantt-types.d.ts.map +1 -1
- package/dist/components/reui/gantt/gantt-view.js +1 -1
- package/dist/components/reui/icon-tile.d.ts +1 -1
- package/dist/components/ui/badge.d.ts +1 -1
- package/dist/components/ui/bubble.d.ts +1 -1
- package/dist/components/ui/button.d.ts +2 -2
- package/dist/components/ui/checkbox.js +1 -1
- package/dist/components/ui/checkbox.js.map +1 -1
- package/dist/components/ui/field.js +2 -2
- package/dist/components/ui/field.js.map +1 -1
- package/dist/components/ui/item.d.ts +2 -2
- package/dist/components/ui/marker.d.ts +1 -1
- package/dist/components/ui/radio-group.js +1 -1
- package/dist/components/ui/radio-group.js.map +1 -1
- package/dist/components/ui/sidebar.d.ts +1 -1
- package/dist/components/ui/sidebar.js +1 -1
- package/dist/components/ui/switch.js +1 -1
- package/dist/components/ui/switch.js.map +1 -1
- package/dist/components/ui/tabs.d.ts +1 -1
- package/dist/components/ui/toggle.d.ts +1 -1
- package/dist/{copy-menu-Bk5GP9Gp.js → copy-menu-1FKoMc9o.js} +9 -2
- package/dist/copy-menu-1FKoMc9o.js.map +1 -0
- package/dist/filters-draft-DEAl3TO-.d.ts +70 -0
- package/dist/filters-draft-DEAl3TO-.d.ts.map +1 -0
- package/dist/hooks/use-dismiss.d.ts +34 -0
- package/dist/hooks/use-dismiss.d.ts.map +1 -0
- package/dist/hooks/use-dismiss.js +78 -0
- package/dist/hooks/use-dismiss.js.map +1 -0
- package/dist/hooks/use-favicon.d.ts +17 -0
- package/dist/hooks/use-favicon.d.ts.map +1 -0
- package/dist/hooks/use-favicon.js +35 -0
- package/dist/hooks/use-favicon.js.map +1 -0
- package/dist/hooks/use-hover-gesture.d.ts +38 -0
- package/dist/hooks/use-hover-gesture.d.ts.map +1 -0
- package/dist/hooks/use-hover-gesture.js +46 -0
- package/dist/hooks/use-hover-gesture.js.map +1 -0
- package/dist/hooks/use-slider.d.ts.map +1 -1
- package/dist/hooks/use-slider.js +3 -2
- package/dist/hooks/use-slider.js.map +1 -1
- package/dist/hooks/use-tap-gesture.d.ts +47 -0
- package/dist/hooks/use-tap-gesture.d.ts.map +1 -0
- package/dist/hooks/use-tap-gesture.js +51 -0
- package/dist/hooks/use-tap-gesture.js.map +1 -0
- package/dist/hooks/use-touch-capable.d.ts +15 -0
- package/dist/hooks/use-touch-capable.d.ts.map +1 -0
- package/dist/hooks/use-touch-capable.js +29 -0
- package/dist/hooks/use-touch-capable.js.map +1 -0
- package/dist/lib/text-shimmer.d.ts +2 -2
- package/dist/lib/text-shimmer.d.ts.map +1 -1
- package/dist/lib/text-shimmer.js +2 -2
- package/dist/lib/text-shimmer.js.map +1 -1
- package/dist/lib/touch.d.ts +66 -0
- package/dist/lib/touch.d.ts.map +1 -0
- package/dist/lib/touch.js +79 -0
- package/dist/lib/touch.js.map +1 -0
- package/dist/presence-gate-BekdC4Bo.js +24 -0
- package/dist/presence-gate-BekdC4Bo.js.map +1 -0
- package/dist/types-smkWN_7x.d.ts.map +1 -1
- package/package.json +9 -9
- package/dist/components/reui/filters.d.ts +0 -176
- package/dist/components/reui/filters.d.ts.map +0 -1
- package/dist/components/reui/filters.js +0 -1223
- package/dist/components/reui/filters.js.map +0 -1
- package/dist/copy-menu-Bk5GP9Gp.js.map +0 -1
|
@@ -0,0 +1,773 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Button } from "../../ui/button.js";
|
|
3
|
+
import { Input } from "../../ui/input.js";
|
|
4
|
+
import { ButtonGroup } from "../../ui/button-group.js";
|
|
5
|
+
import { useCascaderActions, useCascaderHighlight } from "../cascader/cascader-context.js";
|
|
6
|
+
import { Cascader, CascaderEmpty, CascaderList, CascaderPanel, CascaderStatus } from "../cascader/cascader.js";
|
|
7
|
+
import { CascaderItems } from "../cascader/cascader-item.js";
|
|
8
|
+
import { CascaderFooter } from "../cascader/cascader-footer.js";
|
|
9
|
+
import { CascaderInput, CascaderNav } from "../cascader/cascader-nav.js";
|
|
10
|
+
import { FilterActionsContext, filterControlSizes } from "./filters-context.js";
|
|
11
|
+
import { applyFilterExclusiveSelection, filterFilterOptions, joinFilterPath, normalizeFilterQuery, warnFilterOnce } from "./filters-lib.js";
|
|
12
|
+
import * as React$1 from "react";
|
|
13
|
+
import { cn } from "@kumix/utils";
|
|
14
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
+
import { CheckIcon, XIcon } from "lucide-react";
|
|
16
|
+
//#region src/components/reui/filters/filters-editors.tsx
|
|
17
|
+
const IDLE = {
|
|
18
|
+
items: [],
|
|
19
|
+
loading: false,
|
|
20
|
+
error: false,
|
|
21
|
+
hasMore: false
|
|
22
|
+
};
|
|
23
|
+
/** Stable no-op subscription, for a hook running outside a `Filters` root. */
|
|
24
|
+
const emptySubscribe = () => () => {};
|
|
25
|
+
const zeroVersion = () => 0;
|
|
26
|
+
/**
|
|
27
|
+
* The joined path of a field, from the schema index. Keyed by PATH, not field
|
|
28
|
+
* identity, so labels survive a schema rebuild; an unknown field uses its id.
|
|
29
|
+
*/
|
|
30
|
+
function filterFieldKey(field, index) {
|
|
31
|
+
if (!field) return null;
|
|
32
|
+
if (index) {
|
|
33
|
+
for (const entry of index.all) if (entry.field === field) return joinFilterPath(entry.path);
|
|
34
|
+
}
|
|
35
|
+
return `#${field.id}`;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The shared option service every option-backed editor receives: debouncing,
|
|
39
|
+
* aborting, cursor paging and value-to-label resolution. A deliberate fork of
|
|
40
|
+
* the cascader's async machinery. Resolution is two-tier: a ref cache written
|
|
41
|
+
* in an EFFECT, plus the root's `FilterResolutionStore`, without which a
|
|
42
|
+
* `loadOptions`-only field showed its raw id once the menu closed.
|
|
43
|
+
*/
|
|
44
|
+
function useFilterOptions(field, enabled, debounceMs = 250) {
|
|
45
|
+
const [query, setQueryState] = React$1.useState("");
|
|
46
|
+
const [state, setState] = React$1.useState(IDLE);
|
|
47
|
+
const cache = React$1.useRef(/* @__PURE__ */ new Map());
|
|
48
|
+
const requestId = React$1.useRef(0);
|
|
49
|
+
const abortRef = React$1.useRef(null);
|
|
50
|
+
const actionsContext = React$1.useContext(FilterActionsContext);
|
|
51
|
+
const shared = actionsContext?.resolution ?? null;
|
|
52
|
+
const sharedKey = filterFieldKey(field, actionsContext?.index);
|
|
53
|
+
React$1.useSyncExternalStore(shared ? shared.subscribe : emptySubscribe, shared ? shared.getVersion : zeroVersion, shared ? shared.getVersion : zeroVersion);
|
|
54
|
+
const staticOptions = field?.options;
|
|
55
|
+
const loadOptions = field?.loadOptions;
|
|
56
|
+
const isAsync = Boolean(loadOptions);
|
|
57
|
+
React$1.useEffect(() => {
|
|
58
|
+
if (!staticOptions) return;
|
|
59
|
+
for (const option of staticOptions) cache.current.set(option.value, option);
|
|
60
|
+
if (shared && sharedKey) shared.set(sharedKey, staticOptions);
|
|
61
|
+
}, [
|
|
62
|
+
staticOptions,
|
|
63
|
+
shared,
|
|
64
|
+
sharedKey
|
|
65
|
+
]);
|
|
66
|
+
React$1.useEffect(() => {
|
|
67
|
+
for (const option of state.items) cache.current.set(option.value, option);
|
|
68
|
+
if (shared && sharedKey && state.items.length) shared.set(sharedKey, state.items);
|
|
69
|
+
}, [
|
|
70
|
+
state.items,
|
|
71
|
+
shared,
|
|
72
|
+
sharedKey
|
|
73
|
+
]);
|
|
74
|
+
const run = React$1.useCallback(async (nextQuery, cursor, append) => {
|
|
75
|
+
if (!loadOptions) return;
|
|
76
|
+
abortRef.current?.abort();
|
|
77
|
+
const controller = new AbortController();
|
|
78
|
+
abortRef.current = controller;
|
|
79
|
+
const id = ++requestId.current;
|
|
80
|
+
setState((previous) => ({
|
|
81
|
+
...previous,
|
|
82
|
+
loading: true,
|
|
83
|
+
error: false,
|
|
84
|
+
items: append ? previous.items : []
|
|
85
|
+
}));
|
|
86
|
+
try {
|
|
87
|
+
const result = await loadOptions(nextQuery, {
|
|
88
|
+
signal: controller.signal,
|
|
89
|
+
cursor
|
|
90
|
+
});
|
|
91
|
+
if (id !== requestId.current) return;
|
|
92
|
+
const normalized = Array.isArray(result) ? { items: result } : result;
|
|
93
|
+
setState((previous) => ({
|
|
94
|
+
items: append ? [...previous.items, ...normalized.items] : normalized.items,
|
|
95
|
+
loading: false,
|
|
96
|
+
error: false,
|
|
97
|
+
hasMore: normalized.hasMore ?? Boolean(normalized.nextCursor),
|
|
98
|
+
cursor: normalized.nextCursor
|
|
99
|
+
}));
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (id !== requestId.current) return;
|
|
102
|
+
if (error?.name === "AbortError") return;
|
|
103
|
+
setState((previous) => ({
|
|
104
|
+
...previous,
|
|
105
|
+
loading: false,
|
|
106
|
+
error: true,
|
|
107
|
+
hasMore: false
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
}, [loadOptions]);
|
|
111
|
+
React$1.useEffect(() => {
|
|
112
|
+
if (!enabled || !isAsync) return;
|
|
113
|
+
const timer = setTimeout(() => void run(query, void 0, false), debounceMs);
|
|
114
|
+
return () => clearTimeout(timer);
|
|
115
|
+
}, [
|
|
116
|
+
enabled,
|
|
117
|
+
isAsync,
|
|
118
|
+
query,
|
|
119
|
+
debounceMs,
|
|
120
|
+
run
|
|
121
|
+
]);
|
|
122
|
+
React$1.useEffect(() => {
|
|
123
|
+
return () => abortRef.current?.abort();
|
|
124
|
+
}, []);
|
|
125
|
+
const normalizedQuery = normalizeFilterQuery(query);
|
|
126
|
+
const items = React$1.useMemo(() => {
|
|
127
|
+
if (isAsync) return state.items;
|
|
128
|
+
return filterFilterOptions(staticOptions ?? [], normalizedQuery);
|
|
129
|
+
}, [
|
|
130
|
+
isAsync,
|
|
131
|
+
state.items,
|
|
132
|
+
staticOptions,
|
|
133
|
+
normalizedQuery
|
|
134
|
+
]);
|
|
135
|
+
const setQuery = React$1.useCallback((next) => setQueryState(next), []);
|
|
136
|
+
const loadMore = React$1.useCallback(() => {
|
|
137
|
+
if (!state.hasMore || state.loading) return;
|
|
138
|
+
run(query, state.cursor, true);
|
|
139
|
+
}, [
|
|
140
|
+
state.hasMore,
|
|
141
|
+
state.loading,
|
|
142
|
+
state.cursor,
|
|
143
|
+
query,
|
|
144
|
+
run
|
|
145
|
+
]);
|
|
146
|
+
const retry = React$1.useCallback(() => {
|
|
147
|
+
run(query, void 0, false);
|
|
148
|
+
}, [query, run]);
|
|
149
|
+
const resolve = React$1.useCallback((value) => {
|
|
150
|
+
const declared = staticOptions?.find((option) => option.value === value);
|
|
151
|
+
if (declared) return declared;
|
|
152
|
+
const fromShared = shared && sharedKey ? shared.get(sharedKey, value) : void 0;
|
|
153
|
+
if (fromShared) return fromShared;
|
|
154
|
+
return cache.current.get(value);
|
|
155
|
+
}, [
|
|
156
|
+
staticOptions,
|
|
157
|
+
shared,
|
|
158
|
+
sharedKey
|
|
159
|
+
]);
|
|
160
|
+
return {
|
|
161
|
+
items,
|
|
162
|
+
loading: state.loading,
|
|
163
|
+
error: state.error,
|
|
164
|
+
hasMore: state.hasMore,
|
|
165
|
+
query,
|
|
166
|
+
setQuery,
|
|
167
|
+
loadMore,
|
|
168
|
+
retry,
|
|
169
|
+
resolve
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Resolves committed values no loaded page covered, through `resolveValues`: a
|
|
174
|
+
* restored saved view holds ids the loader never returned. The claim set marks
|
|
175
|
+
* an omitted id asked, so only a REJECTED resolve lets a later mount retry.
|
|
176
|
+
*/
|
|
177
|
+
function useFilterValueResolution(field, values) {
|
|
178
|
+
const actionsContext = React$1.useContext(FilterActionsContext);
|
|
179
|
+
const shared = actionsContext?.resolution ?? null;
|
|
180
|
+
const sharedKey = filterFieldKey(field, actionsContext?.index);
|
|
181
|
+
const resolveValues = field?.resolveValues;
|
|
182
|
+
const staticOptions = field?.options;
|
|
183
|
+
const valuesKey = values.map((entry) => String(entry)).join("\0");
|
|
184
|
+
React$1.useEffect(() => {
|
|
185
|
+
if (!resolveValues || !shared || !sharedKey || valuesKey === "") return;
|
|
186
|
+
const missing = valuesKey.split("\0").filter((value) => {
|
|
187
|
+
if (staticOptions?.some((option) => option.value === value)) return false;
|
|
188
|
+
return shared.get(sharedKey, value) === void 0;
|
|
189
|
+
});
|
|
190
|
+
const wanted = shared.claim(sharedKey, missing);
|
|
191
|
+
if (wanted.length === 0) return;
|
|
192
|
+
Promise.resolve(resolveValues(wanted)).then((options) => shared.set(sharedKey, options), () => shared.release(sharedKey, wanted));
|
|
193
|
+
}, [
|
|
194
|
+
resolveValues,
|
|
195
|
+
shared,
|
|
196
|
+
sharedKey,
|
|
197
|
+
valuesKey,
|
|
198
|
+
staticOptions
|
|
199
|
+
]);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* The panel every editor renders into. A plain flex column, NOT a combobox: an
|
|
203
|
+
* editor inside a Base UI composite would inherit its `aria-activedescendant`
|
|
204
|
+
* and arrow keys, which is hostile to a colour picker or a slider.
|
|
205
|
+
*/
|
|
206
|
+
function EditorPanel({ children, className }) {
|
|
207
|
+
return /* @__PURE__ */ jsx("div", {
|
|
208
|
+
"data-slot": "filter-editor",
|
|
209
|
+
className: cn("flex w-full flex-col gap-2 p-2", "[--cascader-max-height:16rem]", className),
|
|
210
|
+
children
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
function EditorFooter({ onCancel, onCommit, labels, host }) {
|
|
214
|
+
const actions = React$1.useContext(FilterActionsContext);
|
|
215
|
+
const sizes = filterControlSizes({ size: actions?.size ?? "default" });
|
|
216
|
+
if (host === "create") return null;
|
|
217
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
218
|
+
className: "flex items-center justify-end gap-1.5 pt-1",
|
|
219
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
220
|
+
variant: "ghost",
|
|
221
|
+
size: sizes.button,
|
|
222
|
+
onClick: onCancel,
|
|
223
|
+
children: labels.discard
|
|
224
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
225
|
+
size: sizes.button,
|
|
226
|
+
onClick: onCommit,
|
|
227
|
+
children: labels.apply
|
|
228
|
+
})]
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* `w-full` because `ButtonGroup` is `w-fit`, which collapses inside this
|
|
233
|
+
* fixed-width panel. Sera is an underline style, so its direct children flatten
|
|
234
|
+
* to one bottom-only edge - `border-b-input`, not transparent, since the
|
|
235
|
+
* buttons are the trailing edge and the rule would stop mid-panel.
|
|
236
|
+
*/
|
|
237
|
+
const EDITOR_FIELD_GROUP = "w-full";
|
|
238
|
+
/**
|
|
239
|
+
* Confirm and cancel, an OUTLINE pair FUSED onto the field's trailing edge.
|
|
240
|
+
* Returns a FRAGMENT: `ButtonGroup` fuses with selectors matching DIRECT
|
|
241
|
+
* children only, so a wrapper div renders three separate boxes. `size="icon"`
|
|
242
|
+
* because every style's icon button at that size is exactly its input's height.
|
|
243
|
+
*/
|
|
244
|
+
function EditorCommitButtons({ onCancel, onCommit, labels }) {
|
|
245
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Button, {
|
|
246
|
+
type: "button",
|
|
247
|
+
variant: "outline",
|
|
248
|
+
size: "icon",
|
|
249
|
+
"aria-label": labels.apply,
|
|
250
|
+
onClick: onCommit,
|
|
251
|
+
children: /* @__PURE__ */ jsx(CheckIcon, { "aria-hidden": "true" })
|
|
252
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
253
|
+
type: "button",
|
|
254
|
+
variant: "outline",
|
|
255
|
+
size: "icon",
|
|
256
|
+
"aria-label": labels.discard,
|
|
257
|
+
onClick: onCancel,
|
|
258
|
+
children: /* @__PURE__ */ jsx(XIcon, { "aria-hidden": "true" })
|
|
259
|
+
})] });
|
|
260
|
+
}
|
|
261
|
+
function useCommitKeys(commit, cancel) {
|
|
262
|
+
return React$1.useCallback((event) => {
|
|
263
|
+
if (event.key === "Enter" && !event.nativeEvent.isComposing) {
|
|
264
|
+
event.preventDefault();
|
|
265
|
+
commit();
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (event.key === "Escape") {
|
|
269
|
+
event.preventDefault();
|
|
270
|
+
event.stopPropagation();
|
|
271
|
+
cancel();
|
|
272
|
+
}
|
|
273
|
+
}, [commit, cancel]);
|
|
274
|
+
}
|
|
275
|
+
function FilterTextEditor({ value, onValueChange, commit, cancel, autoFocusProps, labels, host, field }) {
|
|
276
|
+
const onKeyDown = useCommitKeys(() => commit(), cancel);
|
|
277
|
+
return /* @__PURE__ */ jsx(EditorPanel, {
|
|
278
|
+
className: cn("w-72 min-w-0 max-w-[calc(100vw-2rem)]", field.className),
|
|
279
|
+
children: /* @__PURE__ */ jsxs(ButtonGroup, {
|
|
280
|
+
className: EDITOR_FIELD_GROUP,
|
|
281
|
+
children: [/* @__PURE__ */ jsx(Input, {
|
|
282
|
+
...autoFocusProps,
|
|
283
|
+
value: value ?? "",
|
|
284
|
+
placeholder: field.placeholder ?? labels.valuePlaceholder,
|
|
285
|
+
"aria-label": field.label,
|
|
286
|
+
onChange: (event) => onValueChange(event.target.value),
|
|
287
|
+
onKeyDown
|
|
288
|
+
}), host === "create" ? null : /* @__PURE__ */ jsx(EditorCommitButtons, {
|
|
289
|
+
labels,
|
|
290
|
+
onCancel: cancel,
|
|
291
|
+
onCommit: () => commit()
|
|
292
|
+
})]
|
|
293
|
+
})
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
function FilterNumberEditor({ value, onValueChange, commit, cancel, autoFocusProps, labels, host, field }) {
|
|
297
|
+
const onKeyDown = useCommitKeys(() => commit(), cancel);
|
|
298
|
+
return /* @__PURE__ */ jsx(EditorPanel, {
|
|
299
|
+
className: cn("w-56 min-w-0", field.className),
|
|
300
|
+
children: /* @__PURE__ */ jsxs(ButtonGroup, {
|
|
301
|
+
className: EDITOR_FIELD_GROUP,
|
|
302
|
+
children: [/* @__PURE__ */ jsx(Input, {
|
|
303
|
+
...autoFocusProps,
|
|
304
|
+
type: "number",
|
|
305
|
+
value: value === void 0 || value === null ? "" : String(value),
|
|
306
|
+
placeholder: field.placeholder,
|
|
307
|
+
"aria-label": field.label,
|
|
308
|
+
onChange: (event) => {
|
|
309
|
+
const raw = event.target.value;
|
|
310
|
+
onValueChange(raw === "" ? void 0 : Number(raw));
|
|
311
|
+
},
|
|
312
|
+
onKeyDown
|
|
313
|
+
}), host === "create" ? null : /* @__PURE__ */ jsx(EditorCommitButtons, {
|
|
314
|
+
labels,
|
|
315
|
+
onCancel: cancel,
|
|
316
|
+
onCommit: () => commit()
|
|
317
|
+
})]
|
|
318
|
+
})
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
function FilterRangeEditor({ value, onValueChange, commit, cancel, autoFocusProps, labels, host, field }) {
|
|
322
|
+
const tuple = Array.isArray(value) ? value : [];
|
|
323
|
+
const onKeyDown = useCommitKeys(() => commit(), cancel);
|
|
324
|
+
const update = (index, raw) => {
|
|
325
|
+
const next = [tuple[0], tuple[1]];
|
|
326
|
+
next[index] = raw === "" ? void 0 : Number(raw);
|
|
327
|
+
onValueChange(next);
|
|
328
|
+
};
|
|
329
|
+
return /* @__PURE__ */ jsxs(EditorPanel, { children: [/* @__PURE__ */ jsxs("div", {
|
|
330
|
+
className: "flex items-center gap-1.5",
|
|
331
|
+
children: [
|
|
332
|
+
/* @__PURE__ */ jsx(Input, {
|
|
333
|
+
...autoFocusProps,
|
|
334
|
+
type: "number",
|
|
335
|
+
value: tuple[0] === void 0 ? "" : String(tuple[0]),
|
|
336
|
+
"aria-label": labels.rangeFrom(field.label),
|
|
337
|
+
onChange: (event) => update(0, event.target.value),
|
|
338
|
+
onKeyDown
|
|
339
|
+
}),
|
|
340
|
+
/* @__PURE__ */ jsx("span", {
|
|
341
|
+
className: "text-muted-foreground text-xs",
|
|
342
|
+
children: labels.rangeSeparator
|
|
343
|
+
}),
|
|
344
|
+
/* @__PURE__ */ jsx(Input, {
|
|
345
|
+
type: "number",
|
|
346
|
+
value: tuple[1] === void 0 ? "" : String(tuple[1]),
|
|
347
|
+
"aria-label": labels.rangeTo(field.label),
|
|
348
|
+
onChange: (event) => update(1, event.target.value),
|
|
349
|
+
onKeyDown
|
|
350
|
+
})
|
|
351
|
+
]
|
|
352
|
+
}), /* @__PURE__ */ jsx(EditorFooter, {
|
|
353
|
+
host,
|
|
354
|
+
labels,
|
|
355
|
+
onCancel: cancel,
|
|
356
|
+
onCommit: () => commit()
|
|
357
|
+
})] });
|
|
358
|
+
}
|
|
359
|
+
/** Joins a selection into one comparable key; NUL cannot occur in a value. */
|
|
360
|
+
const PIN_SEPARATOR = "\0";
|
|
361
|
+
/** A bound on a race: each attempt costs one task and stops on success. */
|
|
362
|
+
const MAX_PIN_RESTORE_ATTEMPTS = 4;
|
|
363
|
+
/**
|
|
364
|
+
* Carries the HIGHLIGHT across a live re-pin. Base UI holds it as an INDEX and
|
|
365
|
+
* a keyed reorder MOVES the DOM node rather than remounting it, so the index
|
|
366
|
+
* map only rebuilds when the `MutationObserver` fires: until then, ticking a
|
|
367
|
+
* row moves the highlight down one. So this ARMS in the layout effect, where
|
|
368
|
+
* the map still reads the OLD order, and fires on the signature (SAME index,
|
|
369
|
+
* DIFFERENT row) from a TASK, re-trying because the store event and the re-sort
|
|
370
|
+
* are unordered. A synthetic `mousemove`, since Base UI exposes no setter.
|
|
371
|
+
*/
|
|
372
|
+
function FilterMenuPinKeeper({ order, items }) {
|
|
373
|
+
const { baseId } = useCascaderActions();
|
|
374
|
+
const highlight = useCascaderHighlight();
|
|
375
|
+
const previousRef = React$1.useRef(null);
|
|
376
|
+
const pendingRef = React$1.useRef(null);
|
|
377
|
+
const timerRef = React$1.useRef(null);
|
|
378
|
+
const highlightedValue = highlight.value;
|
|
379
|
+
const highlightedIndex = highlight.index;
|
|
380
|
+
const stop = React$1.useCallback(() => {
|
|
381
|
+
pendingRef.current = null;
|
|
382
|
+
if (timerRef.current === null) return;
|
|
383
|
+
clearTimeout(timerRef.current);
|
|
384
|
+
timerRef.current = null;
|
|
385
|
+
}, []);
|
|
386
|
+
const startRestore = React$1.useCallback(() => {
|
|
387
|
+
const attempt = () => {
|
|
388
|
+
timerRef.current = null;
|
|
389
|
+
const pending = pendingRef.current;
|
|
390
|
+
if (!pending) return;
|
|
391
|
+
const target = pending.order.indexOf(pending.value);
|
|
392
|
+
const rows = document.getElementById(`${baseId}-column-0`)?.querySelectorAll("[data-slot=\"cascader-item\"]");
|
|
393
|
+
if (target < 0 || !rows || rows.length !== pending.order.length) {
|
|
394
|
+
stop();
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
rows[target]?.dispatchEvent(new MouseEvent("mousemove", { bubbles: true }));
|
|
398
|
+
pending.attempts += 1;
|
|
399
|
+
if (pending.attempts >= MAX_PIN_RESTORE_ATTEMPTS) {
|
|
400
|
+
stop();
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
timerRef.current = setTimeout(attempt, 0);
|
|
404
|
+
};
|
|
405
|
+
timerRef.current = setTimeout(attempt, 0);
|
|
406
|
+
}, [baseId, stop]);
|
|
407
|
+
React$1.useLayoutEffect(() => {
|
|
408
|
+
const previous = previousRef.current;
|
|
409
|
+
previousRef.current = {
|
|
410
|
+
order,
|
|
411
|
+
items
|
|
412
|
+
};
|
|
413
|
+
if (!previous || previous.order === order) return;
|
|
414
|
+
if (previous.items !== items) return;
|
|
415
|
+
if (!highlightedValue) return;
|
|
416
|
+
if (isSameOrder(previous.order, order)) return;
|
|
417
|
+
pendingRef.current = {
|
|
418
|
+
value: highlightedValue,
|
|
419
|
+
index: highlightedIndex,
|
|
420
|
+
order,
|
|
421
|
+
attempts: 0
|
|
422
|
+
};
|
|
423
|
+
});
|
|
424
|
+
React$1.useEffect(() => {
|
|
425
|
+
const pending = pendingRef.current;
|
|
426
|
+
if (!pending) return;
|
|
427
|
+
if (highlightedValue === pending.value || highlightedIndex !== pending.index) {
|
|
428
|
+
stop();
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
if (pending.attempts > 0 || timerRef.current !== null) return;
|
|
432
|
+
startRestore();
|
|
433
|
+
}, [
|
|
434
|
+
highlightedValue,
|
|
435
|
+
highlightedIndex,
|
|
436
|
+
startRestore,
|
|
437
|
+
stop
|
|
438
|
+
]);
|
|
439
|
+
React$1.useEffect(() => stop, [stop]);
|
|
440
|
+
return null;
|
|
441
|
+
}
|
|
442
|
+
/** Element-wise, because the arrays are rebuilt on every selection change. */
|
|
443
|
+
function isSameOrder(a, b) {
|
|
444
|
+
if (a.length !== b.length) return false;
|
|
445
|
+
for (let index = 0; index < a.length; index += 1) if (a[index] !== b[index]) return false;
|
|
446
|
+
return true;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* One accessible list, shared by the operator menu and every option editor. It
|
|
450
|
+
* is the CASCADER configured flat, not a list this file implements, which
|
|
451
|
+
* brings the typeahead, RTL handling and live region with it. Only the pinning
|
|
452
|
+
* and the paging affordance stay out here.
|
|
453
|
+
*/
|
|
454
|
+
function FilterMenu({ items, selected, multiple = false, onSelectionChange, labels, ariaLabel, searchPlaceholder, searchable = true, maxHeight, pinSelected = false, sortSelected = "none", preFiltered = false, autoFocusProps, query, onQueryChange, state }) {
|
|
455
|
+
/**
|
|
456
|
+
* The pin set as a KEY, not an array: `selected` is a fresh array on most
|
|
457
|
+
* renders, so a memo depending on it re-partitions every render.
|
|
458
|
+
*/
|
|
459
|
+
const liveKey = pinSelected ? selected.join(PIN_SEPARATOR) : "";
|
|
460
|
+
/**
|
|
461
|
+
* The same set, frozen at OPEN, for `sortSelected: "snapshot"`. LIVE is the
|
|
462
|
+
* default: "your picks, then the rest" is about the CURRENT selection, and
|
|
463
|
+
* `FilterMenuPinKeeper` pays for rows moving under the pointer.
|
|
464
|
+
*/
|
|
465
|
+
const [snapshotKey] = React$1.useState(() => liveKey);
|
|
466
|
+
const pinnedKey = !pinSelected ? "" : sortSelected === "snapshot" ? snapshotKey : liveKey;
|
|
467
|
+
const [ownQuery, setOwnQuery] = React$1.useState("");
|
|
468
|
+
const currentQuery = query ?? ownQuery;
|
|
469
|
+
const setQuery = onQueryChange ?? setOwnQuery;
|
|
470
|
+
/**
|
|
471
|
+
* Memoized on the SELECTION, not the query: folding the query in re-sorted
|
|
472
|
+
* 4,000 rows on every keystroke, for a one pixel rule.
|
|
473
|
+
*/
|
|
474
|
+
const partitioned = React$1.useMemo(() => {
|
|
475
|
+
const pinned = new Set(pinnedKey ? pinnedKey.split(PIN_SEPARATOR) : []);
|
|
476
|
+
const exclusive = items.filter((item) => item.exclusive);
|
|
477
|
+
const values = exclusive.length ? items.filter((item) => !item.exclusive) : items;
|
|
478
|
+
const chosen = pinned.size ? values.filter((item) => pinned.has(item.value)) : [];
|
|
479
|
+
const rest = pinned.size ? values.filter((item) => !pinned.has(item.value)) : values;
|
|
480
|
+
const ordered = sortSelected === "label" ? [
|
|
481
|
+
[...chosen].sort((a, b) => a.label.localeCompare(b.label)),
|
|
482
|
+
[...rest].sort((a, b) => a.label.localeCompare(b.label)),
|
|
483
|
+
[...exclusive].sort((a, b) => a.label.localeCompare(b.label))
|
|
484
|
+
] : [
|
|
485
|
+
chosen,
|
|
486
|
+
rest,
|
|
487
|
+
exclusive
|
|
488
|
+
];
|
|
489
|
+
const rows = [
|
|
490
|
+
...ordered[0],
|
|
491
|
+
...ordered[1],
|
|
492
|
+
...ordered[2]
|
|
493
|
+
];
|
|
494
|
+
return {
|
|
495
|
+
chosenCount: chosen.length,
|
|
496
|
+
/** Index of the first exclusive row, or -1 when the list has none. */
|
|
497
|
+
exclusiveAt: exclusive.length ? rows.length - exclusive.length : -1,
|
|
498
|
+
order: rows.map((item) => item.value),
|
|
499
|
+
nodes: rows.map((item) => ({
|
|
500
|
+
value: item.value,
|
|
501
|
+
label: item.label,
|
|
502
|
+
icon: item.icon,
|
|
503
|
+
description: item.description,
|
|
504
|
+
keywords: item.keywords,
|
|
505
|
+
disabled: item.disabled,
|
|
506
|
+
data: item.exclusive ? { exclusive: true } : void 0
|
|
507
|
+
}))
|
|
508
|
+
};
|
|
509
|
+
}, [
|
|
510
|
+
items,
|
|
511
|
+
pinnedKey,
|
|
512
|
+
sortSelected
|
|
513
|
+
]);
|
|
514
|
+
const dividerAt = partitioned.chosenCount && !currentQuery.trim() ? partitioned.chosenCount : -1;
|
|
515
|
+
const exclusiveDividerAt = partitioned.exclusiveAt;
|
|
516
|
+
const shared = {
|
|
517
|
+
inline: true,
|
|
518
|
+
open: true,
|
|
519
|
+
onOpenChange: () => {},
|
|
520
|
+
items: React$1.useMemo(() => {
|
|
521
|
+
const total = partitioned.nodes.length;
|
|
522
|
+
const marks = [dividerAt, exclusiveDividerAt].filter((index) => index > 0 && index < total);
|
|
523
|
+
if (marks.length === 0) return partitioned.nodes;
|
|
524
|
+
const next = partitioned.nodes.slice();
|
|
525
|
+
for (const index of marks) next[index] = {
|
|
526
|
+
...next[index],
|
|
527
|
+
data: {
|
|
528
|
+
...next[index].data,
|
|
529
|
+
divider: true
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
return next;
|
|
533
|
+
}, [
|
|
534
|
+
partitioned,
|
|
535
|
+
dividerAt,
|
|
536
|
+
exclusiveDividerAt
|
|
537
|
+
]),
|
|
538
|
+
inputValue: currentQuery,
|
|
539
|
+
onInputValueChange: setQuery,
|
|
540
|
+
maxHeight,
|
|
541
|
+
renderItem: React$1.useCallback((node, itemState) => /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
542
|
+
node.data?.divider ? /* @__PURE__ */ jsx("span", {
|
|
543
|
+
"data-slot": "filter-menu-divider",
|
|
544
|
+
"aria-hidden": "true",
|
|
545
|
+
className: "absolute inset-x-[calc(var(--cascader-list-pad,4px)*-1)] -top-1 h-px bg-border"
|
|
546
|
+
}) : null,
|
|
547
|
+
node.icon ? /* @__PURE__ */ jsx("span", {
|
|
548
|
+
"data-slot": "filter-menu-icon",
|
|
549
|
+
className: "flex shrink-0 items-center justify-center text-muted-foreground",
|
|
550
|
+
children: node.icon
|
|
551
|
+
}) : null,
|
|
552
|
+
/* @__PURE__ */ jsxs("span", {
|
|
553
|
+
className: "flex min-w-0 flex-1 flex-col items-start gap-0.5",
|
|
554
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
555
|
+
className: "w-full truncate text-start",
|
|
556
|
+
children: node.label
|
|
557
|
+
}), node.description ? /* @__PURE__ */ jsx("span", {
|
|
558
|
+
className: "w-full truncate text-start text-muted-foreground text-xs",
|
|
559
|
+
children: node.description
|
|
560
|
+
}) : null]
|
|
561
|
+
}),
|
|
562
|
+
node.data?.exclusive && labels.exclusiveHint ? /* @__PURE__ */ jsx("span", {
|
|
563
|
+
"data-slot": "filter-menu-exclusive-hint",
|
|
564
|
+
className: "sr-only",
|
|
565
|
+
children: `, ${labels.exclusiveHint}`
|
|
566
|
+
}) : null,
|
|
567
|
+
itemState.selected ? /* @__PURE__ */ jsx("span", {
|
|
568
|
+
"data-slot": "filter-menu-check",
|
|
569
|
+
className: "pointer-events-none absolute end-[var(--cascader-row-inset,8px)]! flex size-4 items-center justify-center rtl:right-auto!",
|
|
570
|
+
children: /* @__PURE__ */ jsx(CheckIcon, { className: "text-foreground! **:text-foreground!" })
|
|
571
|
+
}) : null
|
|
572
|
+
] }), [labels.exclusiveHint]),
|
|
573
|
+
labels: React$1.useMemo(() => ({
|
|
574
|
+
search: searchPlaceholder ?? labels.searchOptions,
|
|
575
|
+
empty: labels.empty,
|
|
576
|
+
loading: labels.loading,
|
|
577
|
+
loadingMore: labels.loadingMore,
|
|
578
|
+
loadMore: labels.loadMore,
|
|
579
|
+
error: labels.error,
|
|
580
|
+
retry: labels.retry,
|
|
581
|
+
rootLevel: ariaLabel,
|
|
582
|
+
panelLabel: ariaLabel,
|
|
583
|
+
keyboardHint: () => "",
|
|
584
|
+
resultsAnnouncement: labels.resultsAnnouncement,
|
|
585
|
+
actionsLabel: labels.actionsLabel
|
|
586
|
+
}), [
|
|
587
|
+
labels,
|
|
588
|
+
ariaLabel,
|
|
589
|
+
searchPlaceholder
|
|
590
|
+
]),
|
|
591
|
+
actions: React$1.useMemo(() => {
|
|
592
|
+
if (state?.error) return [{
|
|
593
|
+
value: "retry",
|
|
594
|
+
label: labels.retry,
|
|
595
|
+
onSelect: state.retry
|
|
596
|
+
}];
|
|
597
|
+
if (state?.hasMore) return [{
|
|
598
|
+
value: "load-more",
|
|
599
|
+
label: state.loading ? labels.loadingMore : labels.loadMore,
|
|
600
|
+
disabled: state.loading,
|
|
601
|
+
onSelect: state.loadMore
|
|
602
|
+
}];
|
|
603
|
+
return [];
|
|
604
|
+
}, [state, labels]),
|
|
605
|
+
...preFiltered ? { filter: () => true } : null
|
|
606
|
+
};
|
|
607
|
+
const cascaderProps = multiple ? {
|
|
608
|
+
...shared,
|
|
609
|
+
multiple: true,
|
|
610
|
+
value: selected,
|
|
611
|
+
onValueChange: (values) => onSelectionChange(values)
|
|
612
|
+
} : {
|
|
613
|
+
...shared,
|
|
614
|
+
value: selected[0] ?? "",
|
|
615
|
+
onValueChange: (value) => onSelectionChange(value ? [value] : [])
|
|
616
|
+
};
|
|
617
|
+
return /* @__PURE__ */ jsx(Cascader, {
|
|
618
|
+
...cascaderProps,
|
|
619
|
+
children: /* @__PURE__ */ jsxs(CascaderPanel, { children: [
|
|
620
|
+
/* @__PURE__ */ jsx(CascaderNav, {
|
|
621
|
+
className: cn("border-border", !searchable && "sr-only"),
|
|
622
|
+
children: /* @__PURE__ */ jsx(CascaderInput, {
|
|
623
|
+
...autoFocusProps ?? {},
|
|
624
|
+
placeholder: searchPlaceholder ?? labels.searchOptions,
|
|
625
|
+
"aria-label": ariaLabel
|
|
626
|
+
})
|
|
627
|
+
}),
|
|
628
|
+
/* @__PURE__ */ jsx(CascaderEmpty, { children: state?.error ? labels.error : state?.loading ? labels.loading : labels.empty }),
|
|
629
|
+
/* @__PURE__ */ jsx(CascaderList, {
|
|
630
|
+
/**
|
|
631
|
+
* Real layout space around the group rule, which is absolutely
|
|
632
|
+
* positioned and adds no height. `renderItem` cannot reach the row's
|
|
633
|
+
* own box, and a spacer NODE would join the option ring.
|
|
634
|
+
*
|
|
635
|
+
* `:has()` is affordable here: scoped to this one list, a compound
|
|
636
|
+
* whose descendant exists on at most ONE row, and these menus render
|
|
637
|
+
* tens of rows rather than thousands.
|
|
638
|
+
*/
|
|
639
|
+
className: "[&>[data-slot=cascader-item]:has([data-slot=filter-menu-divider])]:mt-2",
|
|
640
|
+
children: /* @__PURE__ */ jsx(CascaderItems, {})
|
|
641
|
+
}),
|
|
642
|
+
/* @__PURE__ */ jsx(CascaderFooter, {}),
|
|
643
|
+
/* @__PURE__ */ jsx(CascaderStatus, {}),
|
|
644
|
+
pinSelected && sortSelected !== "snapshot" ? /* @__PURE__ */ jsx(FilterMenuPinKeeper, {
|
|
645
|
+
order: partitioned.order,
|
|
646
|
+
items
|
|
647
|
+
}) : null
|
|
648
|
+
] })
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
function OptionEditor(props) {
|
|
652
|
+
const { multiple, options, labels, autoFocusProps, commit, cancel, onValueChange, value, field } = props;
|
|
653
|
+
const selected = React$1.useMemo(() => {
|
|
654
|
+
if (value === void 0 || value === null) return [];
|
|
655
|
+
return Array.isArray(value) ? value : [value];
|
|
656
|
+
}, [value]);
|
|
657
|
+
const announce = React$1.useContext(FilterActionsContext)?.announce;
|
|
658
|
+
return /* @__PURE__ */ jsx(EditorPanel, {
|
|
659
|
+
className: cn("w-48 min-w-0 gap-0 p-0", field.className),
|
|
660
|
+
children: /* @__PURE__ */ jsx(FilterMenu, {
|
|
661
|
+
items: options.items,
|
|
662
|
+
selected,
|
|
663
|
+
multiple,
|
|
664
|
+
onSelectionChange: (raw) => {
|
|
665
|
+
const values = applyFilterExclusiveSelection(raw, selected, (value) => Boolean(options.resolve(value)?.exclusive));
|
|
666
|
+
if (values !== raw && announce) {
|
|
667
|
+
const arrived = values.find((entry) => !selected.includes(entry));
|
|
668
|
+
const cleared = raw.length - values.length;
|
|
669
|
+
if (arrived !== void 0 && cleared > 0) announce(labels.exclusiveAnnouncement(options.resolve(arrived)?.label ?? arrived, cleared));
|
|
670
|
+
} else if (values === raw && raw.length > 1) {
|
|
671
|
+
const unresolved = options.items.some((item) => item.exclusive) || Boolean(field.options?.some((option) => option.exclusive)) ? raw.find((entry) => options.resolve(entry) === void 0) : void 0;
|
|
672
|
+
if (unresolved !== void 0) warnFilterOnce(`exclusive-unresolved:${field.id}`, `field "${field.id}" has an exclusive option, but the value "${unresolved}" resolves to no option, so the None rule cannot tell whether it is the exclusive one and has left it in place. Declare the exclusive option in the field's \`options\` even when the rest of the list is async, or cover stored values with \`resolveValues\`.`);
|
|
673
|
+
}
|
|
674
|
+
if (!multiple) {
|
|
675
|
+
const next = values[0];
|
|
676
|
+
if (next === void 0) {
|
|
677
|
+
cancel();
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
onValueChange(next);
|
|
681
|
+
commit(next);
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
onValueChange(values);
|
|
685
|
+
commit(values, { close: false });
|
|
686
|
+
},
|
|
687
|
+
labels,
|
|
688
|
+
ariaLabel: field.label,
|
|
689
|
+
searchable: field.searchable ?? true,
|
|
690
|
+
searchPlaceholder: field.placeholder,
|
|
691
|
+
pinSelected: field.pinSelected ?? false,
|
|
692
|
+
sortSelected: field.sortSelected,
|
|
693
|
+
preFiltered: true,
|
|
694
|
+
query: options.query,
|
|
695
|
+
onQueryChange: options.setQuery,
|
|
696
|
+
state: options,
|
|
697
|
+
autoFocusProps
|
|
698
|
+
})
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
function FilterSelectEditor(props) {
|
|
702
|
+
return /* @__PURE__ */ jsx(OptionEditor, {
|
|
703
|
+
...props,
|
|
704
|
+
multiple: false
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
function FilterMultiSelectEditor(props) {
|
|
708
|
+
return /* @__PURE__ */ jsx(OptionEditor, {
|
|
709
|
+
...props,
|
|
710
|
+
multiple: true
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Module level, so the menu's index is not rebuilt on every render. Not in
|
|
715
|
+
* `FilterLabels`: the chip's own display spells the same two words out.
|
|
716
|
+
*/
|
|
717
|
+
const BOOLEAN_ITEMS = [{
|
|
718
|
+
value: "true",
|
|
719
|
+
label: "True"
|
|
720
|
+
}, {
|
|
721
|
+
value: "false",
|
|
722
|
+
label: "False"
|
|
723
|
+
}];
|
|
724
|
+
function FilterBooleanEditor({ value, onValueChange, commit, labels, autoFocusProps, field }) {
|
|
725
|
+
return /* @__PURE__ */ jsx(EditorPanel, {
|
|
726
|
+
className: cn("w-40 min-w-0 gap-0 p-0", field.className),
|
|
727
|
+
children: /* @__PURE__ */ jsx(FilterMenu, {
|
|
728
|
+
items: BOOLEAN_ITEMS,
|
|
729
|
+
selected: value === true ? ["true"] : value === false ? ["false"] : [],
|
|
730
|
+
onSelectionChange: (values) => {
|
|
731
|
+
if (values.length === 0) return;
|
|
732
|
+
const next = values[0] === "true";
|
|
733
|
+
onValueChange(next);
|
|
734
|
+
commit(next);
|
|
735
|
+
},
|
|
736
|
+
labels,
|
|
737
|
+
ariaLabel: field.label,
|
|
738
|
+
searchable: false,
|
|
739
|
+
autoFocusProps
|
|
740
|
+
})
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
const DEFAULT_FILTER_EDITORS = {
|
|
744
|
+
text: FilterTextEditor,
|
|
745
|
+
number: FilterNumberEditor,
|
|
746
|
+
range: FilterRangeEditor,
|
|
747
|
+
select: FilterSelectEditor,
|
|
748
|
+
multiselect: FilterMultiSelectEditor,
|
|
749
|
+
boolean: FilterBooleanEditor
|
|
750
|
+
};
|
|
751
|
+
/**
|
|
752
|
+
* Picks the editor for a (field, operator) pair: the field's own `editor`, then
|
|
753
|
+
* the operator's ARITY, then the field's `type`. Arity outranks type because
|
|
754
|
+
* "between" wants two boxes whatever the field said.
|
|
755
|
+
*/
|
|
756
|
+
function resolveFilterEditor(field, operator, editors) {
|
|
757
|
+
if (typeof field.editor === "function") return field.editor;
|
|
758
|
+
if (typeof field.editor === "string") {
|
|
759
|
+
const named = editors[field.editor];
|
|
760
|
+
if (named) return named;
|
|
761
|
+
}
|
|
762
|
+
const arity = operator?.arity ?? "one";
|
|
763
|
+
if (arity === "none") return void 0;
|
|
764
|
+
if (arity === "range") return editors.range;
|
|
765
|
+
if (arity === "many") {
|
|
766
|
+
if (field.options || field.loadOptions) return editors.multiselect;
|
|
767
|
+
}
|
|
768
|
+
return editors[field.type ?? "text"] ?? editors.text;
|
|
769
|
+
}
|
|
770
|
+
//#endregion
|
|
771
|
+
export { DEFAULT_FILTER_EDITORS, FilterBooleanEditor, FilterMenu, FilterMultiSelectEditor, FilterNumberEditor, FilterRangeEditor, FilterSelectEditor, FilterTextEditor, resolveFilterEditor, useFilterOptions, useFilterValueResolution };
|
|
772
|
+
|
|
773
|
+
//# sourceMappingURL=filters-editors.js.map
|