derive-dashboards 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/README.md +5 -3
  2. package/dist/cli/add.mjs +130 -0
  3. package/dist/cli/cli.mjs +14 -12
  4. package/dist/cli/config.mjs +12 -1
  5. package/dist/cli/doctor.mjs +147 -0
  6. package/dist/cli/init.mjs +3 -2
  7. package/dist/cli/json.mjs +21 -0
  8. package/dist/cli/layers.mjs +33 -0
  9. package/dist/core/document/layout.mjs +1 -1
  10. package/dist/core/document/view-layout.d.mts +14 -0
  11. package/dist/core/document/view-layout.mjs +157 -0
  12. package/dist/core/engine/filter.mjs +2 -2
  13. package/dist/core/engine/leaf.mjs +9 -4
  14. package/dist/core/engine/members.mjs +1 -1
  15. package/dist/core/engine/version.d.mts +1 -1
  16. package/dist/core/engine/version.mjs +1 -1
  17. package/dist/core/error/codes.d.mts +2 -1
  18. package/dist/core/error/codes.mjs +2 -1
  19. package/dist/core/index.d.mts +5 -3
  20. package/dist/core/index.mjs +5 -3
  21. package/dist/core/model/member.mjs +5 -2
  22. package/dist/core/model/types.d.mts +13 -13
  23. package/dist/core/model/validate/members.mjs +7 -4
  24. package/dist/core/policy/bind-query.d.mts +12 -0
  25. package/dist/core/policy/bind-query.mjs +53 -0
  26. package/dist/core/query/filter.d.mts +6 -0
  27. package/dist/core/query/picks.d.mts +8 -2
  28. package/dist/core/query/picks.mjs +11 -4
  29. package/dist/core/query/segments.mjs +2 -1
  30. package/dist/core/result/columns.mjs +6 -3
  31. package/dist/core/schema/aliases.d.mts +7 -0
  32. package/dist/core/schema/aliases.mjs +77 -0
  33. package/dist/core/schema/answers.d.mts +1 -0
  34. package/dist/core/schema/answers.mjs +1 -0
  35. package/dist/core/schema/index.d.mts +3 -2
  36. package/dist/core/schema/index.mjs +3 -2
  37. package/dist/core/schema/query.d.mts +81 -0
  38. package/dist/core/schema/query.mjs +9 -5
  39. package/dist/core/types/api.d.mts +7 -1
  40. package/dist/core/types/api.mjs +1 -1
  41. package/dist/dashboards.mjs +4 -0
  42. package/dist/editing.mjs +2 -2
  43. package/dist/endpoints/dashboards.mjs +17 -2
  44. package/dist/endpoints/index.d.mts +12 -2
  45. package/dist/endpoints/meta.mjs +10 -1
  46. package/dist/execute.mjs +20 -11
  47. package/dist/handler.mjs +5 -1
  48. package/dist/llms.txt +22 -0
  49. package/dist/mcp/format.mjs +42 -8
  50. package/dist/mcp/query.mjs +34 -4
  51. package/dist/postgres-store.mjs +1 -0
  52. package/dist/react/Canvas.mjs +28 -5
  53. package/dist/react/Cell.mjs +2 -1
  54. package/dist/react/Dashboard.mjs +15 -3
  55. package/dist/react/DashboardList.mjs +22 -22
  56. package/dist/react/DashboardListRow.mjs +49 -0
  57. package/dist/react/Discard.mjs +5 -2
  58. package/dist/react/Editing.mjs +19 -5
  59. package/dist/react/FilterBar.d.mts +7 -9
  60. package/dist/react/Grid.mjs +7 -19
  61. package/dist/react/Header.mjs +1 -1
  62. package/dist/react/History.mjs +5 -0
  63. package/dist/react/ReadFailed.mjs +23 -0
  64. package/dist/react/Spaces.mjs +15 -1
  65. package/dist/react/Tile.d.mts +2 -0
  66. package/dist/react/Tile.mjs +35 -7
  67. package/dist/react/_virtual/_rolldown/runtime.mjs +12 -0
  68. package/dist/react/arrange-steps.mjs +16 -13
  69. package/dist/react/arrange.mjs +10 -3
  70. package/dist/react/builder/Calcs.mjs +35 -11
  71. package/dist/react/builder/FilterEditor.mjs +196 -0
  72. package/dist/react/builder/Filters.mjs +172 -116
  73. package/dist/react/builder/Formula.mjs +82 -0
  74. package/dist/react/builder/Groups.mjs +1 -0
  75. package/dist/react/builder/Preview.mjs +1 -1
  76. package/dist/react/builder/RangeEditor.mjs +184 -0
  77. package/dist/react/builder/Sections.mjs +41 -6
  78. package/dist/react/builder/Time.mjs +138 -60
  79. package/dist/react/builder/Values.mjs +85 -0
  80. package/dist/react/builder/WidgetBuilder.mjs +50 -49
  81. package/dist/react/builder/base.d.mts +5 -0
  82. package/dist/react/builder/base.mjs +33 -8
  83. package/dist/react/builder/calc.mjs +15 -1
  84. package/dist/react/builder/escape.d.mts +1 -0
  85. package/dist/react/builder/escape.mjs +62 -0
  86. package/dist/react/builder/filter-tree.d.mts +9 -0
  87. package/dist/react/builder/filter-tree.mjs +186 -0
  88. package/dist/react/builder/formula-parse.d.mts +18 -0
  89. package/dist/react/builder/formula-parse.mjs +136 -0
  90. package/dist/react/builder/labels.d.mts +1 -1
  91. package/dist/react/builder/state.d.mts +2 -1
  92. package/dist/react/builder/state.mjs +23 -37
  93. package/dist/react/builder/useBuilder.d.mts +12 -1
  94. package/dist/react/builder/useBuilder.mjs +6 -3
  95. package/dist/react/builder/words.d.mts +59 -0
  96. package/dist/react/builder/words.mjs +73 -0
  97. package/dist/react/context.d.mts +13 -0
  98. package/dist/react/context.mjs +9 -3
  99. package/dist/react/drill/useDrill.d.mts +1 -1
  100. package/dist/react/drill/words.d.mts +3 -0
  101. package/dist/react/drill/words.mjs +2 -0
  102. package/dist/react/english.mjs +20 -5
  103. package/dist/react/filters/bar.d.mts +12 -0
  104. package/dist/react/filters/bar.mjs +135 -0
  105. package/dist/react/filters/calendar.mjs +193 -0
  106. package/dist/react/filters/chip.mjs +174 -0
  107. package/dist/react/filters/context.d.mts +22 -0
  108. package/dist/react/filters/context.mjs +78 -0
  109. package/dist/react/filters/dates.mjs +89 -0
  110. package/dist/react/filters/days.d.mts +36 -0
  111. package/dist/react/filters/days.mjs +87 -0
  112. package/dist/react/filters/field-step.mjs +81 -0
  113. package/dist/react/filters/hooks.d.mts +34 -0
  114. package/dist/react/filters/hooks.mjs +94 -0
  115. package/dist/react/filters/listbox.mjs +131 -0
  116. package/dist/react/filters/logic.d.mts +59 -0
  117. package/dist/react/filters/logic.mjs +109 -0
  118. package/dist/react/filters/menu-search.mjs +211 -0
  119. package/dist/react/filters/menu.mjs +85 -0
  120. package/dist/react/filters/number.mjs +127 -0
  121. package/dist/react/filters/numbers.d.mts +47 -0
  122. package/dist/react/filters/numbers.mjs +151 -0
  123. package/dist/react/filters/operator.mjs +104 -0
  124. package/dist/react/filters/phone.mjs +104 -0
  125. package/dist/react/filters/popover.d.mts +19 -0
  126. package/dist/react/filters/popover.mjs +153 -0
  127. package/dist/react/filters/rules.d.mts +8 -0
  128. package/dist/react/filters/rules.mjs +55 -0
  129. package/dist/react/filters/sheet.mjs +196 -0
  130. package/dist/react/filters/state.mjs +132 -0
  131. package/dist/react/filters/suggest.d.mts +47 -0
  132. package/dist/react/filters/suggest.mjs +97 -0
  133. package/dist/react/filters/values.mjs +166 -0
  134. package/dist/react/filters/words.d.mts +81 -0
  135. package/dist/react/filters/words.mjs +73 -0
  136. package/dist/react/format.mjs +11 -4
  137. package/dist/react/index.d.mts +11 -5
  138. package/dist/react/index.mjs +8 -4
  139. package/dist/react/messages.d.mts +34 -2
  140. package/dist/react/place.mjs +7 -3
  141. package/dist/react/renderers/index.mjs +65 -3
  142. package/dist/react/renderers/list.mjs +6 -6
  143. package/dist/react/series.d.mts +25 -8
  144. package/dist/react/series.mjs +135 -39
  145. package/dist/react/theme.css +930 -19
  146. package/dist/react/useBoard.d.mts +2 -0
  147. package/dist/react/useDashboard.d.mts +3 -0
  148. package/dist/react/useDashboard.mjs +6 -0
  149. package/dist/react/view-grid.mjs +16 -0
  150. package/dist/recharts/axes.mjs +28 -0
  151. package/dist/recharts/axis.mjs +84 -0
  152. package/dist/recharts/bar.d.mts +7 -0
  153. package/dist/recharts/bar.mjs +140 -0
  154. package/dist/recharts/charts.d.mts +4 -5
  155. package/dist/recharts/charts.mjs +2 -208
  156. package/dist/recharts/index.d.mts +3 -1
  157. package/dist/recharts/index.mjs +4 -1
  158. package/dist/recharts/line.d.mts +2 -0
  159. package/dist/recharts/line.mjs +111 -0
  160. package/dist/recharts/marks.mjs +47 -18
  161. package/dist/recharts/parts.mjs +88 -0
  162. package/dist/recharts/table.mjs +71 -0
  163. package/dist/records-read.mjs +1 -1
  164. package/dist/registry/filter-bar.json +26 -0
  165. package/dist/skills/derive-dashboards/SKILL.md +69 -0
  166. package/package.json +6 -2
  167. package/dist/react/FilterBar.mjs +0 -119
@@ -0,0 +1,104 @@
1
+ import { useOpText, useWords } from "./context.mjs";
2
+ import { canFlip, isNegative } from "./logic.mjs";
3
+ import { Popover } from "./popover.mjs";
4
+ import { useRef, useState } from "react";
5
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
+ // src/filters/operator.tsx
7
+ const CHOICES = [false, true];
8
+ /** Arrow keys, Home and End move between a menu's items, as the ARIA menu pattern asks. */
9
+ function moveInMenu(e) {
10
+ const items = [...e.currentTarget.querySelectorAll("[role=menuitemradio]")];
11
+ const at = items.findIndex((i) => i === document.activeElement);
12
+ const last = items.length - 1;
13
+ const next = {
14
+ ArrowDown: at >= last ? 0 : at + 1,
15
+ ArrowUp: at <= 0 ? last : at - 1,
16
+ Home: 0,
17
+ End: last
18
+ }[e.key];
19
+ if (next === void 0) return;
20
+ e.preventDefault();
21
+ items[next]?.focus();
22
+ }
23
+ function Choices({ label, pick, onChange }) {
24
+ const opText = useOpText();
25
+ const negative = isNegative(pick.op);
26
+ return /* @__PURE__ */ jsx("div", {
27
+ role: "menu",
28
+ "aria-label": label,
29
+ className: "dd-fb-menu",
30
+ onKeyDown: moveInMenu,
31
+ children: CHOICES.map((neg) => /* @__PURE__ */ jsx("button", {
32
+ type: "button",
33
+ role: "menuitemradio",
34
+ "aria-checked": neg === negative,
35
+ tabIndex: neg === negative ? 0 : -1,
36
+ className: "dd-fb-preset",
37
+ onClick: () => {
38
+ onChange(neg);
39
+ },
40
+ children: opText(pick, neg)
41
+ }, String(neg)))
42
+ });
43
+ }
44
+ /**
45
+ * The operator as its own small menu: what it is now, and the other choice beside it. Where the
46
+ * control cannot say "is not", it is plain text.
47
+ */
48
+ function OperatorMenu({ control, pick, onChange }) {
49
+ const words = useWords();
50
+ const opText = useOpText();
51
+ const [open, setOpen] = useState(false);
52
+ const button = useRef(null);
53
+ if (!canFlip(control, pick)) return /* @__PURE__ */ jsx("span", {
54
+ className: "dd-fb-seg dd-fb-op",
55
+ children: opText(pick)
56
+ });
57
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("button", {
58
+ ref: button,
59
+ type: "button",
60
+ className: "dd-fb-seg dd-fb-op",
61
+ "aria-haspopup": "menu",
62
+ "aria-expanded": open,
63
+ "aria-label": words.operator(control.label, opText(pick)),
64
+ onClick: () => {
65
+ setOpen(!open);
66
+ },
67
+ children: opText(pick)
68
+ }), /* @__PURE__ */ jsx(Popover, {
69
+ anchor: button,
70
+ open,
71
+ onClose: () => {
72
+ setOpen(false);
73
+ },
74
+ label: control.label,
75
+ role: "none",
76
+ children: /* @__PURE__ */ jsx(Choices, {
77
+ label: control.label,
78
+ pick,
79
+ onChange: (neg) => {
80
+ onChange(neg);
81
+ setOpen(false);
82
+ }
83
+ })
84
+ })] });
85
+ }
86
+ /** The same choice as two buttons, for the phone sheet, where nothing opens on top. */
87
+ function OperatorToggle({ control, pick, onChange }) {
88
+ const opText = useOpText();
89
+ if (!canFlip(control, pick)) return null;
90
+ return /* @__PURE__ */ jsx("fieldset", {
91
+ className: "dd-fb-seg-row",
92
+ "aria-label": control.label,
93
+ children: CHOICES.map((neg) => /* @__PURE__ */ jsx("button", {
94
+ type: "button",
95
+ "aria-pressed": isNegative(pick.op) === neg,
96
+ className: "dd-fb-preset",
97
+ onClick: () => {
98
+ onChange(neg);
99
+ },
100
+ children: opText(pick, neg)
101
+ }, String(neg)))
102
+ });
103
+ }
104
+ export { OperatorMenu, OperatorToggle };
@@ -0,0 +1,104 @@
1
+ import { rangeOf, useBar, useRangeText, useSummary, useWords, valuePickOf } from "./context.mjs";
2
+ import { chosenOf, isNegative, isNumber } from "./logic.mjs";
3
+ import { numberText } from "./numbers.mjs";
4
+ import { Sheet } from "./sheet.mjs";
5
+ import { useShortcuts } from "./state.mjs";
6
+ import { ValuesSummary } from "./values.mjs";
7
+ import { useState } from "react";
8
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
+ // src/filters/phone.tsx
10
+ /** A date range or a number filter's pick, said short. */
11
+ function PickText({ control }) {
12
+ const { fields, picks } = useBar();
13
+ const rangeText = useRangeText();
14
+ if (control.kind === "date_range") {
15
+ const range = rangeOf(picks, control.id);
16
+ return /* @__PURE__ */ jsx("span", { children: range === void 0 ? null : rangeText(range) });
17
+ }
18
+ const pick = valuePickOf(picks, control.id);
19
+ return /* @__PURE__ */ jsx("span", { children: pick === void 0 ? null : numberText(pick, fields[control.id]?.unit ?? "") });
20
+ }
21
+ /** A filter in use on the phone row: its label and its pick, which opens it in the sheet. */
22
+ function Pill({ control, onOpen }) {
23
+ const { fields, picks } = useBar();
24
+ const words = useWords();
25
+ const said = useSummary()(control);
26
+ const pick = valuePickOf(picks, control.id);
27
+ const values = control.kind === "filter" && pick !== void 0 && !isNumber(control, fields);
28
+ return /* @__PURE__ */ jsxs("button", {
29
+ type: "button",
30
+ className: "dd-fb-pill",
31
+ "aria-label": `${control.label} ${said ?? ""}`,
32
+ onClick: onOpen,
33
+ children: [
34
+ /* @__PURE__ */ jsx("span", {
35
+ className: "dd-fb-quiet",
36
+ children: control.label
37
+ }),
38
+ values && isNegative(pick.op) ? /* @__PURE__ */ jsx("span", {
39
+ className: "dd-fb-quiet",
40
+ children: words.isNotWord
41
+ }) : null,
42
+ values ? /* @__PURE__ */ jsx(ValuesSummary, {
43
+ control,
44
+ values: chosenOf(pick)
45
+ }) : /* @__PURE__ */ jsx(PickText, { control })
46
+ ]
47
+ });
48
+ }
49
+ /** The phone row: Filters with how many are set, then a pill per filter in use. */
50
+ function PhoneRow({ inUse, sheetOpen, onOpen }) {
51
+ const words = useWords();
52
+ return /* @__PURE__ */ jsxs("div", {
53
+ className: "dd-fb dd-fb-bar",
54
+ "data-narrow": true,
55
+ role: "toolbar",
56
+ "aria-label": words.filters(inUse.length),
57
+ children: [/* @__PURE__ */ jsx("button", {
58
+ type: "button",
59
+ className: "dd-fb-add",
60
+ "aria-haspopup": "dialog",
61
+ "aria-expanded": sheetOpen,
62
+ onClick: () => {
63
+ onOpen(null);
64
+ },
65
+ children: words.filters(inUse.length)
66
+ }), /* @__PURE__ */ jsx("div", {
67
+ className: "dd-fb-scroll",
68
+ children: inUse.map((c) => /* @__PURE__ */ jsx(Pill, {
69
+ control: c,
70
+ onOpen: () => {
71
+ onOpen(c.id);
72
+ }
73
+ }, c.id))
74
+ })]
75
+ });
76
+ }
77
+ /** On a phone: the filters in use in one row, and Filters, which opens the sheet of every filter. */
78
+ function PhoneBar({ controls, removeLast, onReset }) {
79
+ const { picks } = useBar();
80
+ const [sheet, setSheet] = useState(false);
81
+ const [expanded, setExpanded] = useState(null);
82
+ const open = (id) => {
83
+ setExpanded(id);
84
+ setSheet(true);
85
+ };
86
+ useShortcuts(() => {
87
+ open(null);
88
+ }, removeLast);
89
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(PhoneRow, {
90
+ inUse: controls.filter((c) => picks[c.id] !== void 0),
91
+ sheetOpen: sheet,
92
+ onOpen: open
93
+ }), /* @__PURE__ */ jsx(Sheet, {
94
+ controls,
95
+ open: sheet,
96
+ onClose: () => {
97
+ setSheet(false);
98
+ },
99
+ expanded,
100
+ setExpanded,
101
+ onReset
102
+ })] });
103
+ }
104
+ export { PhoneBar };
@@ -0,0 +1,19 @@
1
+ import { ReactNode, RefObject } from "react";
2
+ type Anchor = RefObject<HTMLElement | null>;
3
+ /**
4
+ * A panel under its anchor, drawn at the end of <body> so no overflow or stacking context of the
5
+ * host clips it. It flips above when there is no room below, stays inside the viewport, follows
6
+ * scrolling, closes on Escape or a press outside, and gives focus back on close.
7
+ * The panel carries `dd-fb-pop`; style it like anything else.
8
+ */
9
+ export declare function Popover({ anchor, open, onClose, label, className, role, children }: {
10
+ anchor: Anchor;
11
+ open: boolean;
12
+ onClose: () => void;
13
+ label: string;
14
+ className?: string;
15
+ /** "dialog" (the default) labels the panel; "none" when its content carries the role, as a menu does. */
16
+ role?: "dialog" | "none";
17
+ children: ReactNode;
18
+ }): import("react").ReactPortal | null;
19
+ export {};
@@ -0,0 +1,153 @@
1
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
2
+ import { createPortal } from "react-dom";
3
+ import { jsx } from "react/jsx-runtime";
4
+ // src/filters/popover.tsx
5
+ const GAP = 6;
6
+ const MARGIN = 8;
7
+ /** Where the panel goes: under its anchor, above when there is no room, inside the viewport. */
8
+ function placeOf(a, p) {
9
+ const below = window.innerHeight - a.bottom - GAP;
10
+ const up = below < p.height + MARGIN && a.top > below;
11
+ const top = up ? Math.max(MARGIN, a.top - GAP - p.height) : a.bottom + GAP;
12
+ const left = Math.min(Math.max(MARGIN, a.left), window.innerWidth - p.width - MARGIN);
13
+ return {
14
+ top,
15
+ left: Math.max(MARGIN, left),
16
+ up
17
+ };
18
+ }
19
+ /** The panel's place while open, kept up to date as it resizes and the page scrolls. */
20
+ function usePlace(open, anchor, panel) {
21
+ const [place, setPlace] = useState(null);
22
+ const measure = useCallback(() => {
23
+ const a = anchor.current?.getBoundingClientRect();
24
+ const p = panel.current?.getBoundingClientRect();
25
+ if (a !== void 0 && p !== void 0) setPlace(placeOf(a, p));
26
+ }, [anchor, panel]);
27
+ useLayoutEffect(() => {
28
+ if (!open) {
29
+ setPlace(null);
30
+ return;
31
+ }
32
+ measure();
33
+ const observer = new ResizeObserver(measure);
34
+ if (panel.current !== null) observer.observe(panel.current);
35
+ window.addEventListener("resize", measure);
36
+ window.addEventListener("scroll", measure, true);
37
+ return () => {
38
+ observer.disconnect();
39
+ window.removeEventListener("resize", measure);
40
+ window.removeEventListener("scroll", measure, true);
41
+ };
42
+ }, [
43
+ open,
44
+ measure,
45
+ panel
46
+ ]);
47
+ return place;
48
+ }
49
+ const lostFocus = () => document.activeElement === null || document.activeElement === document.body;
50
+ /** Closes on Escape (from inside, its anchor, or nowhere) and on a press outside both. */
51
+ function useDismiss(open, anchor, panel, onClose) {
52
+ useEffect(() => {
53
+ if (!open) return;
54
+ const inside = (t) => panel.current?.contains(t) === true || anchor.current?.contains(t) === true;
55
+ const onDown = (e) => {
56
+ const t = e.target instanceof Element ? e.target : null;
57
+ if (!inside(t) && (t?.closest(".dd-fb-pop") ?? null) === null) onClose();
58
+ };
59
+ const onKey = (e) => {
60
+ if (e.key !== "Escape" || !(lostFocus() || inside(document.activeElement))) return;
61
+ e.stopPropagation();
62
+ onClose();
63
+ };
64
+ document.addEventListener("pointerdown", onDown, true);
65
+ document.addEventListener("keydown", onKey, true);
66
+ return () => {
67
+ document.removeEventListener("pointerdown", onDown, true);
68
+ document.removeEventListener("keydown", onKey, true);
69
+ };
70
+ }, [
71
+ open,
72
+ onClose,
73
+ anchor,
74
+ panel
75
+ ]);
76
+ }
77
+ /**
78
+ * When it closes with focus inside (or lost with the panel), focus goes back to what opened it,
79
+ * or, when a pick redrew the chip, to the chip's value.
80
+ */
81
+ function useFocusBack(open, anchor, panel) {
82
+ useEffect(() => {
83
+ if (!open) return;
84
+ const at = document.activeElement;
85
+ const opener = at instanceof HTMLElement && anchor.current?.contains(at) === true ? at : null;
86
+ const box = panel.current;
87
+ return () => {
88
+ if (!lostFocus() && box?.contains(document.activeElement) !== true) return;
89
+ requestAnimationFrame(() => {
90
+ if (!lostFocus()) return;
91
+ (opener?.isConnected === true ? opener : anchor.current?.querySelector(".dd-fb-value, [aria-haspopup]"))?.focus({ preventScroll: true });
92
+ });
93
+ };
94
+ }, [
95
+ open,
96
+ anchor,
97
+ panel
98
+ ]);
99
+ }
100
+ /** Focuses the first field, or the first button, once the panel is placed (hidden takes none). */
101
+ function useFocusFirst(open, placed, panel) {
102
+ const focused = useRef(false);
103
+ useEffect(() => {
104
+ if (!open) {
105
+ focused.current = false;
106
+ return;
107
+ }
108
+ if (!placed || focused.current) return;
109
+ focused.current = true;
110
+ if (panel.current?.contains(document.activeElement) === true) return;
111
+ const box = panel.current;
112
+ (box?.querySelector("[aria-checked=true]") ?? box?.querySelector("input, [role=option], button:not([disabled])"))?.focus({ preventScroll: true });
113
+ }, [
114
+ open,
115
+ placed,
116
+ panel
117
+ ]);
118
+ }
119
+ /** The panel's side and position; hidden off screen until it is measured. */
120
+ const placed = (place) => ({
121
+ "data-side": place?.up === true ? "top" : "bottom",
122
+ style: {
123
+ position: "fixed",
124
+ top: place?.top ?? -9999,
125
+ left: place?.left ?? -9999,
126
+ visibility: place === null ? "hidden" : "visible"
127
+ }
128
+ });
129
+ /**
130
+ * A panel under its anchor, drawn at the end of <body> so no overflow or stacking context of the
131
+ * host clips it. It flips above when there is no room below, stays inside the viewport, follows
132
+ * scrolling, closes on Escape or a press outside, and gives focus back on close.
133
+ * The panel carries `dd-fb-pop`; style it like anything else.
134
+ */
135
+ function Popover({ anchor, open, onClose, label, className, role = "dialog", children }) {
136
+ const panel = useRef(null);
137
+ const place = usePlace(open, anchor, panel);
138
+ useDismiss(open, anchor, panel, onClose);
139
+ useFocusBack(open, anchor, panel);
140
+ useFocusFirst(open, place !== null, panel);
141
+ if (!open) return null;
142
+ return createPortal(/* @__PURE__ */ jsx("div", {
143
+ ref: panel,
144
+ ...role === "dialog" ? {
145
+ role,
146
+ "aria-label": label
147
+ } : { role },
148
+ className: className === void 0 ? "dd-fb dd-fb-pop" : `dd-fb dd-fb-pop ${className}`,
149
+ ...placed(place),
150
+ children
151
+ }), document.body);
152
+ }
153
+ export { Popover };
@@ -0,0 +1,8 @@
1
+ import { DAY_ONLY, addDays, dateFormat, daysLabel, daysPick, explicitDays, fromIsoDay, isoDay, monthEnd, monthStart, pickedDays, rangeLabel, relativeLabel, sameDay, todayIn, weekday } from "./days.mjs";
2
+ import { DateControl, Fields, FilterControl, OpWord, RelativeRange, ValuePick, canFlip, changeText, chosenOf, defaultFormat, flipped, isNegative, isNone, isNumber, listText, nonePick, offersNone, opWord, pickOpWord, removedOf, takesMany, toggled, valueOp, valuePick } from "./logic.mjs";
3
+ import { NumberPreset, NumberProblem, numberBounds, numberDraft, numberPresets, numberSides, numberText, unitText } from "./numbers.mjs";
4
+ import { DATE_WORDS, ENGLISH_GRAMMAR, Grammar, SuggestInput, Suggestion, fieldMatches, matchingFields, suggest, suggestionPick } from "./suggest.mjs";
5
+ declare namespace rules_d_exports {
6
+ export { DATE_WORDS, DAY_ONLY, DateControl, ENGLISH_GRAMMAR, Fields, FilterControl, Grammar, NumberPreset, NumberProblem, OpWord, RelativeRange, SuggestInput, Suggestion, ValuePick, addDays, canFlip, changeText, chosenOf, dateFormat, daysLabel, daysPick, defaultFormat, explicitDays, fieldMatches, flipped, fromIsoDay, isNegative, isNone, isNumber, isoDay, listText, matchingFields, monthEnd, monthStart, nonePick, numberBounds, numberDraft, numberPresets, numberSides, numberText, offersNone, opWord, pickOpWord, pickedDays, rangeLabel, relativeLabel, removedOf, sameDay, suggest, suggestionPick, takesMany, todayIn, toggled, unitText, valueOp, valuePick, weekday };
7
+ }
8
+ export { DATE_WORDS, DAY_ONLY, DateControl, ENGLISH_GRAMMAR, Fields, FilterControl, Grammar, NumberPreset, NumberProblem, OpWord, RelativeRange, SuggestInput, Suggestion, ValuePick, addDays, canFlip, changeText, chosenOf, dateFormat, daysLabel, daysPick, defaultFormat, explicitDays, fieldMatches, flipped, fromIsoDay, isNegative, isNone, isNumber, isoDay, listText, matchingFields, monthEnd, monthStart, nonePick, numberBounds, numberDraft, numberPresets, numberSides, numberText, offersNone, opWord, pickOpWord, pickedDays, rangeLabel, relativeLabel, removedOf, rules_d_exports, sameDay, suggest, suggestionPick, takesMany, todayIn, toggled, unitText, valueOp, valuePick, weekday };
@@ -0,0 +1,55 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
2
+ import { DAY_ONLY, addDays, dateFormat, daysLabel, daysPick, explicitDays, fromIsoDay, isoDay, monthEnd, monthStart, pickedDays, rangeLabel, relativeLabel, sameDay, todayIn, weekday } from "./days.mjs";
3
+ import { canFlip, changeText, chosenOf, defaultFormat, flipped, isNegative, isNone, isNumber, listText, nonePick, offersNone, opWord, pickOpWord, removedOf, takesMany, toggled, valueOp, valuePick } from "./logic.mjs";
4
+ import { numberBounds, numberDraft, numberPresets, numberSides, numberText, unitText } from "./numbers.mjs";
5
+ import { DATE_WORDS, ENGLISH_GRAMMAR, fieldMatches, matchingFields, suggest, suggestionPick } from "./suggest.mjs";
6
+ // src/filters/rules.ts
7
+ var rules_exports = /* @__PURE__ */ __exportAll({
8
+ DATE_WORDS: () => DATE_WORDS,
9
+ DAY_ONLY: () => DAY_ONLY,
10
+ ENGLISH_GRAMMAR: () => ENGLISH_GRAMMAR,
11
+ addDays: () => addDays,
12
+ canFlip: () => canFlip,
13
+ changeText: () => changeText,
14
+ chosenOf: () => chosenOf,
15
+ dateFormat: () => dateFormat,
16
+ daysLabel: () => daysLabel,
17
+ daysPick: () => daysPick,
18
+ defaultFormat: () => defaultFormat,
19
+ explicitDays: () => explicitDays,
20
+ fieldMatches: () => fieldMatches,
21
+ flipped: () => flipped,
22
+ fromIsoDay: () => fromIsoDay,
23
+ isNegative: () => isNegative,
24
+ isNone: () => isNone,
25
+ isNumber: () => isNumber,
26
+ isoDay: () => isoDay,
27
+ listText: () => listText,
28
+ matchingFields: () => matchingFields,
29
+ monthEnd: () => monthEnd,
30
+ monthStart: () => monthStart,
31
+ nonePick: () => nonePick,
32
+ numberBounds: () => numberBounds,
33
+ numberDraft: () => numberDraft,
34
+ numberPresets: () => numberPresets,
35
+ numberSides: () => numberSides,
36
+ numberText: () => numberText,
37
+ offersNone: () => offersNone,
38
+ opWord: () => opWord,
39
+ pickOpWord: () => pickOpWord,
40
+ pickedDays: () => pickedDays,
41
+ rangeLabel: () => rangeLabel,
42
+ relativeLabel: () => relativeLabel,
43
+ removedOf: () => removedOf,
44
+ sameDay: () => sameDay,
45
+ suggest: () => suggest,
46
+ suggestionPick: () => suggestionPick,
47
+ takesMany: () => takesMany,
48
+ todayIn: () => todayIn,
49
+ toggled: () => toggled,
50
+ unitText: () => unitText,
51
+ valueOp: () => valueOp,
52
+ valuePick: () => valuePick,
53
+ weekday: () => weekday
54
+ });
55
+ export { DATE_WORDS, DAY_ONLY, ENGLISH_GRAMMAR, addDays, canFlip, changeText, chosenOf, dateFormat, daysLabel, daysPick, defaultFormat, explicitDays, fieldMatches, flipped, fromIsoDay, isNegative, isNone, isNumber, isoDay, listText, matchingFields, monthEnd, monthStart, nonePick, numberBounds, numberDraft, numberPresets, numberSides, numberText, offersNone, opWord, pickOpWord, pickedDays, rangeLabel, relativeLabel, removedOf, rules_exports, sameDay, suggest, suggestionPick, takesMany, todayIn, toggled, unitText, valueOp, valuePick, weekday };
@@ -0,0 +1,196 @@
1
+ import { useDashboards } from "../context.mjs";
2
+ import { Icon, Picker } from "./chip.mjs";
3
+ import { useBar, useSummary, useWords, valuePickOf } from "./context.mjs";
4
+ import { flipped, isNumber } from "./logic.mjs";
5
+ import { OperatorToggle } from "./operator.mjs";
6
+ import { useEffect, useId, useRef } from "react";
7
+ import { createPortal } from "react-dom";
8
+ import { jsx, jsxs } from "react/jsx-runtime";
9
+ // src/filters/sheet.tsx
10
+ const FOCUSABLE = "button:not([disabled]), input:not([disabled]), [tabindex='0']";
11
+ /** Keeps Tab and Shift+Tab inside the panel: past the last field comes the first, and back. */
12
+ function trapTab(e, panel) {
13
+ const all = [...panel?.querySelectorAll(FOCUSABLE) ?? []];
14
+ const first = all.at(0);
15
+ const last = all.at(-1);
16
+ if (first === void 0 || last === void 0) return;
17
+ const at = document.activeElement;
18
+ if (e.shiftKey ? at === first || panel?.contains(at) !== true : at === last) {
19
+ e.preventDefault();
20
+ (e.shiftKey ? last : first).focus();
21
+ }
22
+ }
23
+ /** Everything on the page but the sheet stops taking focus and pointer, until it closes. */
24
+ function inertBehind(layer) {
25
+ const behind = [...document.body.children].filter((e) => e !== layer && !e.hasAttribute("inert"));
26
+ for (const e of behind) e.setAttribute("inert", "");
27
+ return () => {
28
+ for (const e of behind) e.removeAttribute("inert");
29
+ };
30
+ }
31
+ /**
32
+ * While the sheet is open it is modal: the page behind is inert and does not scroll, Tab stays
33
+ * inside, Escape closes, and focus goes back to what opened it. Picks inside it do not move focus.
34
+ */
35
+ function useModal(open, panel, onClose) {
36
+ const close = useRef(onClose);
37
+ useEffect(() => {
38
+ close.current = onClose;
39
+ }, [onClose]);
40
+ useEffect(() => {
41
+ if (!open) return;
42
+ const previous = document.activeElement instanceof HTMLElement ? document.activeElement : null;
43
+ const overflow = document.body.style.overflow;
44
+ document.body.style.overflow = "hidden";
45
+ const restore = inertBehind(panel.current?.closest(".dd-fb-sheet-layer"));
46
+ panel.current?.querySelector("button")?.focus();
47
+ const onKey = (e) => {
48
+ if (e.key === "Escape") close.current();
49
+ else if (e.key === "Tab") trapTab(e, panel.current);
50
+ };
51
+ document.addEventListener("keydown", onKey);
52
+ return () => {
53
+ document.body.style.overflow = overflow;
54
+ document.removeEventListener("keydown", onKey);
55
+ restore();
56
+ previous?.focus();
57
+ };
58
+ }, [open, panel]);
59
+ }
60
+ /** A filter's picker inside the sheet: is or is not as two buttons, the picker, and Remove. */
61
+ function SheetPicker({ control, set, close }) {
62
+ const words = useWords();
63
+ const { fields, picks, setPick } = useBar();
64
+ const pick = valuePickOf(picks, control.id);
65
+ const operator = control.kind === "filter" && pick !== void 0 && !isNumber(control, fields);
66
+ return /* @__PURE__ */ jsxs("div", {
67
+ className: "dd-fb-sheet-picker",
68
+ children: [
69
+ operator ? /* @__PURE__ */ jsx(OperatorToggle, {
70
+ control,
71
+ pick,
72
+ onChange: (neg) => {
73
+ setPick(control.id, flipped(control, pick, neg));
74
+ }
75
+ }) : null,
76
+ /* @__PURE__ */ jsx(Picker, {
77
+ control,
78
+ narrow: true,
79
+ close
80
+ }),
81
+ set ? /* @__PURE__ */ jsx("button", {
82
+ type: "button",
83
+ className: "dd-fb-link",
84
+ onClick: () => {
85
+ setPick(control.id, void 0);
86
+ },
87
+ children: words.remove(control.label)
88
+ }) : null
89
+ ]
90
+ });
91
+ }
92
+ /** The sheet's title, Reset while anything is set, and Done. */
93
+ function SheetHead({ titleId, onReset, onClose }) {
94
+ const words = useWords();
95
+ const { messages } = useDashboards();
96
+ const { picks } = useBar();
97
+ return /* @__PURE__ */ jsxs("div", {
98
+ className: "dd-fb-sheet-head",
99
+ children: [
100
+ /* @__PURE__ */ jsx("span", {
101
+ id: titleId,
102
+ className: "dd-fb-sheet-title",
103
+ children: words.filters(0)
104
+ }),
105
+ Object.keys(picks).length === 0 ? null : /* @__PURE__ */ jsx("button", {
106
+ type: "button",
107
+ className: "dd-fb-link",
108
+ onClick: onReset,
109
+ children: messages.reset
110
+ }),
111
+ /* @__PURE__ */ jsx("button", {
112
+ type: "button",
113
+ className: "dd-fb-primary",
114
+ onClick: onClose,
115
+ children: words.done
116
+ })
117
+ ]
118
+ });
119
+ }
120
+ /** One filter in the sheet: a row that says its pick, and its picker inline when open. */
121
+ function SheetItem({ control, open, setOpen }) {
122
+ const words = useWords();
123
+ const said = useSummary()(control);
124
+ const unset = control.kind === "date_range" ? words.widgetDates : words.anyValue;
125
+ return /* @__PURE__ */ jsxs("div", {
126
+ className: "dd-fb-sheet-item",
127
+ "data-open": open || void 0,
128
+ children: [/* @__PURE__ */ jsxs("button", {
129
+ type: "button",
130
+ className: "dd-fb-sheet-row",
131
+ "aria-expanded": open,
132
+ onClick: () => {
133
+ setOpen(!open);
134
+ },
135
+ children: [
136
+ /* @__PURE__ */ jsx(Icon, { control }),
137
+ /* @__PURE__ */ jsx("span", {
138
+ className: "dd-fb-sheet-label",
139
+ children: control.label
140
+ }),
141
+ /* @__PURE__ */ jsx("span", {
142
+ className: "dd-fb-sheet-said",
143
+ "data-unset": said === void 0 || void 0,
144
+ children: said ?? unset
145
+ })
146
+ ]
147
+ }), open ? /* @__PURE__ */ jsx(SheetPicker, {
148
+ control,
149
+ set: said !== void 0,
150
+ close: () => {
151
+ setOpen(false);
152
+ }
153
+ }) : null]
154
+ });
155
+ }
156
+ /**
157
+ * On a phone, every filter in one sheet from the bottom. A filter's picker opens inside it, one
158
+ * at a time, never on top of it.
159
+ */
160
+ function Sheet({ controls, open, onClose, expanded, setExpanded, onReset }) {
161
+ const words = useWords();
162
+ const panel = useRef(null);
163
+ const titleId = useId();
164
+ useModal(open, panel, onClose);
165
+ if (!open) return null;
166
+ return createPortal(/* @__PURE__ */ jsxs("div", {
167
+ className: "dd-fb dd-fb-sheet-layer",
168
+ children: [/* @__PURE__ */ jsx("button", {
169
+ type: "button",
170
+ className: "dd-fb-backdrop",
171
+ "aria-label": words.done,
172
+ onClick: onClose
173
+ }), /* @__PURE__ */ jsxs("div", {
174
+ ref: panel,
175
+ role: "dialog",
176
+ "aria-modal": "true",
177
+ "aria-labelledby": titleId,
178
+ className: "dd-fb-sheet",
179
+ children: [/* @__PURE__ */ jsx(SheetHead, {
180
+ titleId,
181
+ onReset,
182
+ onClose
183
+ }), /* @__PURE__ */ jsx("div", {
184
+ className: "dd-fb-sheet-list",
185
+ children: controls.map((c) => /* @__PURE__ */ jsx(SheetItem, {
186
+ control: c,
187
+ open: expanded === c.id,
188
+ setOpen: (o) => {
189
+ setExpanded(o ? c.id : null);
190
+ }
191
+ }, c.id))
192
+ })]
193
+ })]
194
+ }), document.body);
195
+ }
196
+ export { Sheet };