derive-dashboards 0.1.1 → 0.3.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 (202) hide show
  1. package/README.md +5 -3
  2. package/dist/cache.mjs +2 -1
  3. package/dist/cli/add.mjs +130 -0
  4. package/dist/cli/cli.mjs +14 -12
  5. package/dist/cli/config.mjs +12 -1
  6. package/dist/cli/doctor.mjs +162 -0
  7. package/dist/cli/init.mjs +3 -2
  8. package/dist/cli/json.mjs +21 -0
  9. package/dist/cli/layers.mjs +33 -0
  10. package/dist/core/document/display.d.mts +63 -0
  11. package/dist/core/document/display.mjs +139 -0
  12. package/dist/core/document/layout.mjs +1 -1
  13. package/dist/core/document/view-layout.d.mts +14 -0
  14. package/dist/core/document/view-layout.mjs +157 -0
  15. package/dist/core/engine/filter.mjs +2 -2
  16. package/dist/core/engine/leaf.mjs +9 -4
  17. package/dist/core/engine/members.mjs +1 -1
  18. package/dist/core/engine/version.d.mts +5 -4
  19. package/dist/core/engine/version.mjs +5 -4
  20. package/dist/core/error/codes.d.mts +4 -1
  21. package/dist/core/error/codes.mjs +4 -1
  22. package/dist/core/index.d.mts +12 -8
  23. package/dist/core/index.mjs +11 -7
  24. package/dist/core/model/member.mjs +5 -2
  25. package/dist/core/model/types.d.mts +13 -13
  26. package/dist/core/model/validate/drill.mjs +6 -15
  27. package/dist/core/model/validate/fields.mjs +130 -0
  28. package/dist/core/model/validate/index.mjs +11 -3
  29. package/dist/core/model/validate/known-members.mjs +133 -0
  30. package/dist/core/model/validate/known-nested.mjs +85 -0
  31. package/dist/core/model/validate/known.mjs +94 -0
  32. package/dist/core/model/validate/members.mjs +7 -4
  33. package/dist/core/model/validate/source.mjs +8 -1
  34. package/dist/core/policy/bind-query.d.mts +12 -0
  35. package/dist/core/policy/bind-query.mjs +53 -0
  36. package/dist/core/query/alias.mjs +11 -1
  37. package/dist/core/query/drill/selection.d.mts +7 -2
  38. package/dist/core/query/drill/selection.mjs +18 -15
  39. package/dist/core/query/filter.d.mts +6 -0
  40. package/dist/core/query/picks.d.mts +8 -2
  41. package/dist/core/query/picks.mjs +11 -4
  42. package/dist/core/query/segments.mjs +2 -1
  43. package/dist/core/result/columns.d.mts +10 -1
  44. package/dist/core/result/columns.mjs +27 -5
  45. package/dist/core/result/time-axis.d.mts +23 -0
  46. package/dist/core/result/time-axis.mjs +72 -0
  47. package/dist/core/result/types.d.mts +36 -1
  48. package/dist/core/schema/aliases.d.mts +7 -0
  49. package/dist/core/schema/aliases.mjs +77 -0
  50. package/dist/core/schema/answer-parts.mjs +23 -1
  51. package/dist/core/schema/answers.d.mts +204 -0
  52. package/dist/core/schema/answers.mjs +2 -0
  53. package/dist/core/schema/index.d.mts +3 -2
  54. package/dist/core/schema/index.mjs +3 -2
  55. package/dist/core/schema/query.d.mts +81 -0
  56. package/dist/core/schema/query.mjs +9 -5
  57. package/dist/core/schema/tools.d.mts +2 -0
  58. package/dist/core/schema/tools.mjs +27 -1
  59. package/dist/core/time/bucket.mjs +8 -2
  60. package/dist/core/types/api.d.mts +7 -1
  61. package/dist/core/types/api.mjs +1 -1
  62. package/dist/dashboards.mjs +4 -0
  63. package/dist/drill-change.mjs +1 -1
  64. package/dist/drill-seal.mjs +1 -0
  65. package/dist/editing.mjs +2 -2
  66. package/dist/endpoints/dashboards.mjs +17 -2
  67. package/dist/endpoints/index.d.mts +15 -2
  68. package/dist/endpoints/meta.mjs +10 -1
  69. package/dist/execute.mjs +32 -17
  70. package/dist/handler.mjs +5 -1
  71. package/dist/index.mjs +6 -1
  72. package/dist/llms.txt +22 -0
  73. package/dist/mcp/format.mjs +42 -8
  74. package/dist/mcp/query.mjs +34 -4
  75. package/dist/postgres-store.mjs +1 -0
  76. package/dist/react/Canvas.mjs +28 -5
  77. package/dist/react/Cell.mjs +2 -1
  78. package/dist/react/Dashboard.d.mts +4 -0
  79. package/dist/react/Dashboard.mjs +27 -4
  80. package/dist/react/DashboardList.mjs +22 -22
  81. package/dist/react/DashboardListRow.mjs +49 -0
  82. package/dist/react/Discard.mjs +5 -2
  83. package/dist/react/Editing.mjs +19 -5
  84. package/dist/react/FilterBar.d.mts +7 -9
  85. package/dist/react/Grid.mjs +7 -19
  86. package/dist/react/Header.mjs +1 -1
  87. package/dist/react/History.mjs +5 -0
  88. package/dist/react/ReadFailed.mjs +23 -0
  89. package/dist/react/Spaces.mjs +15 -1
  90. package/dist/react/Tile.d.mts +2 -0
  91. package/dist/react/Tile.mjs +45 -10
  92. package/dist/react/_virtual/_rolldown/runtime.mjs +12 -0
  93. package/dist/react/arrange-steps.mjs +16 -13
  94. package/dist/react/arrange.mjs +10 -3
  95. package/dist/react/builder/Calcs.mjs +35 -11
  96. package/dist/react/builder/FilterEditor.mjs +196 -0
  97. package/dist/react/builder/Filters.mjs +172 -116
  98. package/dist/react/builder/Formula.mjs +82 -0
  99. package/dist/react/builder/Groups.mjs +1 -0
  100. package/dist/react/builder/Preview.mjs +1 -1
  101. package/dist/react/builder/RangeEditor.mjs +184 -0
  102. package/dist/react/builder/Sections.mjs +41 -6
  103. package/dist/react/builder/Time.mjs +138 -60
  104. package/dist/react/builder/Values.mjs +85 -0
  105. package/dist/react/builder/WidgetBuilder.mjs +50 -49
  106. package/dist/react/builder/base.d.mts +5 -0
  107. package/dist/react/builder/base.mjs +33 -8
  108. package/dist/react/builder/calc.mjs +15 -1
  109. package/dist/react/builder/escape.d.mts +1 -0
  110. package/dist/react/builder/escape.mjs +62 -0
  111. package/dist/react/builder/filter-tree.d.mts +9 -0
  112. package/dist/react/builder/filter-tree.mjs +186 -0
  113. package/dist/react/builder/formula-parse.d.mts +18 -0
  114. package/dist/react/builder/formula-parse.mjs +136 -0
  115. package/dist/react/builder/labels.d.mts +1 -1
  116. package/dist/react/builder/state.d.mts +2 -1
  117. package/dist/react/builder/state.mjs +23 -37
  118. package/dist/react/builder/useBuilder.d.mts +12 -1
  119. package/dist/react/builder/useBuilder.mjs +6 -3
  120. package/dist/react/builder/words.d.mts +59 -0
  121. package/dist/react/builder/words.mjs +73 -0
  122. package/dist/react/context.d.mts +15 -1
  123. package/dist/react/context.mjs +9 -3
  124. package/dist/react/drill/Bars.mjs +2 -2
  125. package/dist/react/drill/props.mjs +2 -1
  126. package/dist/react/drill/useDrill.d.mts +1 -1
  127. package/dist/react/drill/words.d.mts +3 -0
  128. package/dist/react/drill/words.mjs +2 -0
  129. package/dist/react/english.mjs +20 -5
  130. package/dist/react/filters/bar.d.mts +12 -0
  131. package/dist/react/filters/bar.mjs +135 -0
  132. package/dist/react/filters/calendar.mjs +193 -0
  133. package/dist/react/filters/chip.mjs +174 -0
  134. package/dist/react/filters/context.d.mts +22 -0
  135. package/dist/react/filters/context.mjs +78 -0
  136. package/dist/react/filters/dates.mjs +89 -0
  137. package/dist/react/filters/days.d.mts +36 -0
  138. package/dist/react/filters/days.mjs +87 -0
  139. package/dist/react/filters/field-step.mjs +81 -0
  140. package/dist/react/filters/hooks.d.mts +34 -0
  141. package/dist/react/filters/hooks.mjs +94 -0
  142. package/dist/react/filters/listbox.mjs +131 -0
  143. package/dist/react/filters/logic.d.mts +59 -0
  144. package/dist/react/filters/logic.mjs +109 -0
  145. package/dist/react/filters/menu-search.mjs +211 -0
  146. package/dist/react/filters/menu.mjs +85 -0
  147. package/dist/react/filters/number.mjs +127 -0
  148. package/dist/react/filters/numbers.d.mts +47 -0
  149. package/dist/react/filters/numbers.mjs +151 -0
  150. package/dist/react/filters/operator.mjs +104 -0
  151. package/dist/react/filters/phone.mjs +104 -0
  152. package/dist/react/filters/popover.d.mts +19 -0
  153. package/dist/react/filters/popover.mjs +153 -0
  154. package/dist/react/filters/rules.d.mts +8 -0
  155. package/dist/react/filters/rules.mjs +55 -0
  156. package/dist/react/filters/sheet.mjs +196 -0
  157. package/dist/react/filters/state.mjs +132 -0
  158. package/dist/react/filters/suggest.d.mts +47 -0
  159. package/dist/react/filters/suggest.mjs +97 -0
  160. package/dist/react/filters/values.mjs +166 -0
  161. package/dist/react/filters/words.d.mts +81 -0
  162. package/dist/react/filters/words.mjs +73 -0
  163. package/dist/react/format.mjs +11 -4
  164. package/dist/react/index.d.mts +15 -6
  165. package/dist/react/index.mjs +10 -4
  166. package/dist/react/messages.d.mts +34 -2
  167. package/dist/react/place.mjs +7 -3
  168. package/dist/react/renderers/index.d.mts +3 -21
  169. package/dist/react/renderers/index.mjs +68 -6
  170. package/dist/react/renderers/list.d.mts +2 -1
  171. package/dist/react/renderers/list.mjs +9 -12
  172. package/dist/react/renderers/props.d.mts +26 -0
  173. package/dist/react/scope.d.mts +4 -0
  174. package/dist/react/scope.mjs +19 -2
  175. package/dist/react/series-slots.d.mts +37 -0
  176. package/dist/react/series-slots.mjs +71 -0
  177. package/dist/react/series.d.mts +39 -9
  178. package/dist/react/series.mjs +144 -47
  179. package/dist/react/theme.css +930 -19
  180. package/dist/react/useBoard.d.mts +2 -0
  181. package/dist/react/useDashboard.d.mts +3 -0
  182. package/dist/react/useDashboard.mjs +6 -0
  183. package/dist/react/view-grid.mjs +16 -0
  184. package/dist/recharts/axes.mjs +28 -0
  185. package/dist/recharts/axis.mjs +84 -0
  186. package/dist/recharts/bar.d.mts +7 -0
  187. package/dist/recharts/bar.mjs +141 -0
  188. package/dist/recharts/charts.d.mts +4 -5
  189. package/dist/recharts/charts.mjs +2 -208
  190. package/dist/recharts/index.d.mts +3 -1
  191. package/dist/recharts/index.mjs +4 -1
  192. package/dist/recharts/line.d.mts +2 -0
  193. package/dist/recharts/line.mjs +112 -0
  194. package/dist/recharts/marks.mjs +47 -18
  195. package/dist/recharts/parts.mjs +103 -0
  196. package/dist/recharts/table.mjs +71 -0
  197. package/dist/records-read.mjs +1 -1
  198. package/dist/registry/filter-bar.json +26 -0
  199. package/dist/skills/derive-dashboards/SKILL.md +69 -0
  200. package/dist/store/apply.mjs +3 -1
  201. package/package.json +6 -2
  202. package/dist/react/FilterBar.mjs +0 -119
@@ -0,0 +1,132 @@
1
+ import { removedOf } from "./logic.mjs";
2
+ import { useCallback, useEffect, useId, useRef, useState } from "react";
3
+ // src/filters/state.ts
4
+ const NARROW = "(max-width: 640px)";
5
+ const UNDO_MS = 8e3;
6
+ /** Whether the bar is on a phone-sized screen, where it becomes one row and a sheet. */
7
+ function useNarrow() {
8
+ const [narrow, setNarrow] = useState(() => globalThis.matchMedia?.(NARROW).matches ?? false);
9
+ useEffect(() => {
10
+ const media = globalThis.matchMedia?.(NARROW);
11
+ if (media === void 0) return;
12
+ const on = () => {
13
+ setNarrow(media.matches);
14
+ };
15
+ media.addEventListener("change", on);
16
+ return () => {
17
+ media.removeEventListener("change", on);
18
+ };
19
+ }, []);
20
+ return narrow;
21
+ }
22
+ /**
23
+ * The bar's picks: set one, reset all, remove the one set last, and undo a removal for a few
24
+ * seconds. Every change goes to the host through `onChange`.
25
+ */
26
+ /** The Undo line's state: it clears itself after a few seconds. */
27
+ function useUndo() {
28
+ const [undo, setUndo] = useState(null);
29
+ useEffect(() => {
30
+ if (undo === null) return;
31
+ const t = setTimeout(() => {
32
+ setUndo(null);
33
+ }, UNDO_MS);
34
+ return () => {
35
+ clearTimeout(t);
36
+ };
37
+ }, [undo]);
38
+ return [undo, setUndo];
39
+ }
40
+ function useBarPicks(controls, picks, onChange) {
41
+ const [undo, setUndo] = useUndo();
42
+ const order = useRef([]);
43
+ const change = useCallback((next) => {
44
+ const removed = removedOf(controls, picks, next);
45
+ setUndo(removed === void 0 ? null : {
46
+ ...removed,
47
+ picks
48
+ });
49
+ onChange(next);
50
+ }, [
51
+ controls,
52
+ picks,
53
+ onChange,
54
+ setUndo
55
+ ]);
56
+ const setPick = useCallback((id, pick) => {
57
+ const next = { ...picks };
58
+ if (pick === void 0) delete next[id];
59
+ else next[id] = pick;
60
+ order.current = [...order.current.filter((x) => x !== id), ...pick === void 0 ? [] : [id]];
61
+ change(next);
62
+ }, [picks, change]);
63
+ const removeLast = useCallback(() => {
64
+ const last = order.current.findLast((id) => picks[id] !== void 0) ?? Object.keys(picks).at(-1);
65
+ if (last !== void 0) setPick(last, void 0);
66
+ }, [picks, setPick]);
67
+ const reset = () => {
68
+ order.current = [];
69
+ change({});
70
+ };
71
+ const takeBack = (u) => {
72
+ onChange(u.picks);
73
+ setUndo(null);
74
+ };
75
+ return {
76
+ setPick,
77
+ removeLast,
78
+ reset,
79
+ undo,
80
+ takeBack
81
+ };
82
+ }
83
+ /** The bars on the page, in the order they mounted; the keys belong to the first. */
84
+ const keyed = [];
85
+ /**
86
+ * F opens the Filter menu and Shift+F removes the last filter, unless someone is typing. With
87
+ * several dashboards on a page, only the first bar answers.
88
+ */
89
+ function useShortcuts(onOpen, onRemoveLast) {
90
+ const id = useId();
91
+ useEffect(() => {
92
+ keyed.push(id);
93
+ const onKey = (e) => {
94
+ if (e.target instanceof Element && e.target.closest("input, textarea, select, [contenteditable], [role=dialog]") !== null || keyed[0] !== id) return;
95
+ if (e.metaKey || e.ctrlKey || e.altKey || e.key.toLowerCase() !== "f") return;
96
+ e.preventDefault();
97
+ if (e.shiftKey) onRemoveLast();
98
+ else onOpen();
99
+ };
100
+ globalThis.addEventListener("keydown", onKey);
101
+ return () => {
102
+ keyed.splice(keyed.indexOf(id), 1);
103
+ globalThis.removeEventListener("keydown", onKey);
104
+ };
105
+ }, [
106
+ id,
107
+ onOpen,
108
+ onRemoveLast
109
+ ]);
110
+ }
111
+ /**
112
+ * Which filters show as chips: the first `pinned` in the order the dashboard declares them, and
113
+ * any filter set during this visit, which stays after it is cleared so chips never jump. The rest
114
+ * wait in the Filter menu.
115
+ */
116
+ function useShown(controls, picks, pinned) {
117
+ const filters = controls.filter((c) => c.kind === "filter");
118
+ const setNow = filters.filter((f) => picks[f.id] !== void 0).map((f) => f.id);
119
+ const [used, setUsed] = useState(() => new Set(setNow));
120
+ if (setNow.some((id) => !used.has(id))) setUsed(/* @__PURE__ */ new Set([...used, ...setNow]));
121
+ const visible = filters.filter((c, i) => i < pinned || used.has(c.id) || picks[c.id] !== void 0);
122
+ return {
123
+ visible,
124
+ hidden: filters.length - visible.length
125
+ };
126
+ }
127
+ /** Whether the picks are still the ones the page opened with from a link. */
128
+ function useFromLink(picks) {
129
+ const [opened] = useState(() => Object.keys(picks).length === 0 ? null : JSON.stringify(picks));
130
+ return opened !== null && JSON.stringify(picks) === opened;
131
+ }
132
+ export { useBarPicks, useFromLink, useNarrow, useShortcuts, useShown };
@@ -0,0 +1,47 @@
1
+ import { DateControl, FilterControl, RelativeRange as RelativeRange$1 } from "./logic.mjs";
2
+ import { Control, Picks, Primitive } from "derive-dashboards/core";
3
+ /** Words that find the date control in the menu, besides its label. */
4
+ export declare const DATE_WORDS: string[];
5
+ export type Suggestion = {
6
+ kind: "value";
7
+ control: FilterControl;
8
+ value: Primitive;
9
+ negative: boolean;
10
+ } | {
11
+ kind: "date";
12
+ control: DateControl;
13
+ range: RelativeRange$1;
14
+ };
15
+ type Format = (c: Control, v: Primitive) => string;
16
+ export type SuggestInput = {
17
+ filters: readonly FilterControl[];
18
+ date?: DateControl | undefined;
19
+ /** The values the bar has seen for each control, by id. */
20
+ known: Readonly<Record<string, readonly Primitive[]>>;
21
+ query: string;
22
+ /** A value as words; defaults to the bar's. */
23
+ format?: Format;
24
+ /** A date preset as words, such as `messages.range`; defaults to English. */
25
+ dateText?: (r: RelativeRange$1) => string;
26
+ /** The words people type: "not" for is not, "is" to skip, and words that mean the date. */
27
+ grammar?: Grammar;
28
+ };
29
+ /** The typed words the menu understands, in the host's language. */
30
+ export type Grammar = {
31
+ not: readonly string[];
32
+ skip: readonly string[];
33
+ dates: readonly string[];
34
+ };
35
+ export declare const ENGLISH_GRAMMAR: Grammar;
36
+ /** What typed words could mean: "stat rev" → Status is Review, "last 90" → a date preset. */
37
+ export declare function suggest(input: SuggestInput): Suggestion[];
38
+ /**
39
+ * Whether every typed word is in a control's label ("proj team" finds Project team), or, for the
40
+ * date control, is a date word.
41
+ */
42
+ export declare function fieldMatches(control: Control, query: string, dates?: readonly string[]): boolean;
43
+ /** The fields the menu offers for a query, the closest label first, else in declared order. */
44
+ export declare function matchingFields<C extends Control>(controls: readonly C[], query: string, dates?: readonly string[]): C[];
45
+ /** The one pick the bar adds when a suggestion is chosen, merging into what is already picked. */
46
+ export declare function suggestionPick(s: Suggestion, picks: Picks): Picks[string] | undefined;
47
+ export {};
@@ -0,0 +1,97 @@
1
+ import { relativeLabel } from "./days.mjs";
2
+ import { defaultFormat, isNegative, isNone, nonePick, takesMany, valueOp, valuePick } from "./logic.mjs";
3
+ import { isValuePick } from "derive-dashboards/core";
4
+ // src/filters/suggest.ts
5
+ /** Words that find the date control in the menu, besides its label. */
6
+ const DATE_WORDS = [
7
+ "date",
8
+ "dates",
9
+ "when",
10
+ "time",
11
+ "range"
12
+ ];
13
+ const ENGLISH_GRAMMAR = {
14
+ not: ["not"],
15
+ skip: ["is"],
16
+ dates: DATE_WORDS
17
+ };
18
+ const wordsOf = (s) => s.trim().toLowerCase().split(/\s+/u).filter(Boolean);
19
+ function dateSuggestions(date, words, ask) {
20
+ const { dateText, grammar } = ask;
21
+ const label = date.label.toLowerCase();
22
+ const rest = words.filter((w) => !grammar.dates.includes(w) && !label.startsWith(w));
23
+ if (rest.length === 0) return [];
24
+ return date.presets.filter((r) => {
25
+ const text = dateText(r).toLowerCase();
26
+ return rest.every((w) => text.includes(w));
27
+ }).map((range) => ({
28
+ kind: "date",
29
+ control: date,
30
+ range
31
+ }));
32
+ }
33
+ function valueSuggestions(control, values, ask) {
34
+ const parts = wordsOf(control.label);
35
+ const inLabel = (w) => parts.some((p) => p.startsWith(w));
36
+ const valueWords = ask.words.some(inLabel) ? ask.words.filter((w) => !inLabel(w)) : ask.words;
37
+ if (valueWords.length === 0) return [];
38
+ if (valueOp(control, ask.negative, 1) === void 0) return [];
39
+ return values.filter((v) => v !== null || nonePick(control, ask.negative) !== void 0).filter((v) => {
40
+ const text = ask.format(control, v).toLowerCase();
41
+ return valueWords.every((w) => text.includes(w));
42
+ }).map((value) => ({
43
+ kind: "value",
44
+ control,
45
+ value,
46
+ negative: ask.negative
47
+ }));
48
+ }
49
+ /** What typed words could mean: "stat rev" → Status is Review, "last 90" → a date preset. */
50
+ function suggest(input) {
51
+ const { filters, date, known, query, format = defaultFormat } = input;
52
+ const grammar = input.grammar ?? ENGLISH_GRAMMAR;
53
+ const words = wordsOf(query);
54
+ if (words.length === 0) return [];
55
+ const ask = {
56
+ words: words.filter((w) => !grammar.not.includes(w) && !grammar.skip.includes(w)),
57
+ negative: words.some((w) => grammar.not.includes(w)),
58
+ format
59
+ };
60
+ const dateText = input.dateText ?? relativeLabel;
61
+ return [...date === void 0 ? [] : dateSuggestions(date, words, {
62
+ dateText,
63
+ grammar
64
+ }), ...filters.flatMap((c) => valueSuggestions(c, known[c.id] ?? [], ask))].slice(0, 6);
65
+ }
66
+ /**
67
+ * Whether every typed word is in a control's label ("proj team" finds Project team), or, for the
68
+ * date control, is a date word.
69
+ */
70
+ function fieldMatches(control, query, dates = DATE_WORDS) {
71
+ const label = control.label.toLowerCase();
72
+ const dateWord = (w) => control.kind === "date_range" && dates.some((d) => d.startsWith(w));
73
+ return wordsOf(query).every((w) => label.includes(w) || dateWord(w));
74
+ }
75
+ /** The fields the menu offers for a query, the closest label first, else in declared order. */
76
+ function matchingFields(controls, query, dates = DATE_WORDS) {
77
+ const q = query.trim().toLowerCase();
78
+ const rank = (c) => {
79
+ const label = c.label.toLowerCase();
80
+ return label === q ? 0 : label.startsWith(q) ? 1 : 2;
81
+ };
82
+ return controls.filter((c) => fieldMatches(c, query, dates)).map((c, i) => ({
83
+ c,
84
+ i,
85
+ r: rank(c)
86
+ })).toSorted((x, y) => x.r - y.r || x.i - y.i).map((x) => x.c);
87
+ }
88
+ /** The one pick the bar adds when a suggestion is chosen, merging into what is already picked. */
89
+ function suggestionPick(s, picks) {
90
+ if (s.kind === "date") return s.range;
91
+ const own = picks[s.control.id];
92
+ const had = isValuePick(own) ? own : void 0;
93
+ if (s.value === null) return nonePick(s.control, s.negative) ?? had;
94
+ const values = had !== void 0 && !isNone(had) && isNegative(had.op) === s.negative && takesMany(s.control, s.negative) ? [.../* @__PURE__ */ new Set([...had.values, s.value])] : [s.value];
95
+ return valuePick(s.control, s.negative, values) ?? had;
96
+ }
97
+ export { DATE_WORDS, ENGLISH_GRAMMAR, fieldMatches, matchingFields, suggest, suggestionPick };
@@ -0,0 +1,166 @@
1
+ import { useBar, useFormat, useWords } from "./context.mjs";
2
+ import { useControlValues, useDebounced } from "./hooks.mjs";
3
+ import { Combobox } from "./listbox.mjs";
4
+ import { chosenOf, isNegative, offersNone, takesMany } from "./logic.mjs";
5
+ import { useMemo, useState } from "react";
6
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
+ // src/filters/values.tsx
8
+ /** What sits before a value: the host's mark, else a dot in the value's tone from the model. */
9
+ function Mark({ control, value }) {
10
+ const { fields, options } = useBar();
11
+ const own = options.renderMark?.(control, value);
12
+ if (own !== void 0) return /* @__PURE__ */ jsx(Fragment, { children: own });
13
+ const tones = fields[control.id]?.tones;
14
+ if (tones === void 0 || value === null) return null;
15
+ return /* @__PURE__ */ jsx("span", {
16
+ "aria-hidden": true,
17
+ className: "dd-fb-dot",
18
+ "data-tone": tones[String(value)] ?? "neutral"
19
+ });
20
+ }
21
+ /** The first chosen value with its mark, and how many more: "● Review +1". */
22
+ function ValuesSummary({ control, values }) {
23
+ const format = useFormat();
24
+ const [first] = values;
25
+ if (first === void 0) return null;
26
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
27
+ /* @__PURE__ */ jsx("span", {
28
+ className: "dd-fb-marks",
29
+ children: values.slice(0, 3).map((v) => /* @__PURE__ */ jsx(Mark, {
30
+ control,
31
+ value: v
32
+ }, String(v)))
33
+ }),
34
+ /* @__PURE__ */ jsx("span", {
35
+ className: "dd-fb-value-text",
36
+ children: format(control, first)
37
+ }),
38
+ values.length > 1 ? /* @__PURE__ */ jsxs("span", {
39
+ className: "dd-fb-more",
40
+ children: ["+", String(values.length - 1)]
41
+ }) : null
42
+ ] });
43
+ }
44
+ /**
45
+ * The values to list for a search: those chosen when the list opened first (so nothing moves
46
+ * while it is open), then the rest, then None where the control offers it. Results that no longer
47
+ * match the typed words are never offered.
48
+ */
49
+ function useShownValues(control, chosen, query) {
50
+ const format = useFormat();
51
+ const searched = useDebounced(query, 150);
52
+ const own = typeof control.values === "object";
53
+ const read = useControlValues(control, {
54
+ search: own ? "" : searched,
55
+ limit: 50
56
+ });
57
+ const [pinned] = useState(() => chosen);
58
+ const needle = query.trim().toLowerCase();
59
+ return {
60
+ shown: useMemo(() => {
61
+ const none = offersNone(control);
62
+ const rest = read.values.filter((v) => !pinned.includes(v));
63
+ const tail = none && !pinned.includes(null) && !rest.includes(null) ? [null] : [];
64
+ const fits = (v) => format(control, v).toLowerCase().includes(needle) || !own && String(v).toLowerCase().includes(needle);
65
+ return [
66
+ ...pinned,
67
+ ...rest,
68
+ ...tail
69
+ ].filter((v) => (v !== null || none) && fits(v));
70
+ }, [
71
+ read.values,
72
+ pinned,
73
+ needle,
74
+ format,
75
+ control,
76
+ own
77
+ ]),
78
+ pending: query !== searched || read.loading,
79
+ read
80
+ };
81
+ }
82
+ function ValueFoot({ count, searching, onClear }) {
83
+ const words = useWords();
84
+ const said = searching ? words.searching : count === 0 ? words.anyValue : words.selected(count);
85
+ return /* @__PURE__ */ jsxs("div", {
86
+ className: "dd-fb-foot",
87
+ role: "status",
88
+ children: [/* @__PURE__ */ jsx("span", { children: said }), count === 0 ? null : /* @__PURE__ */ jsx("button", {
89
+ type: "button",
90
+ className: "dd-fb-link",
91
+ onClick: onClear,
92
+ children: words.clear
93
+ })]
94
+ });
95
+ }
96
+ /** An empty list: still searching, nothing matches, or the values could not be read (with Retry). */
97
+ /** The values could not be read: said beside whatever the list still shows, with Retry. */
98
+ function ValuesFailed({ retry }) {
99
+ const words = useWords();
100
+ return /* @__PURE__ */ jsxs("div", {
101
+ className: "dd-fb-foot dd-fb-error",
102
+ role: "alert",
103
+ children: [/* @__PURE__ */ jsx("span", { children: words.valuesFailed }), /* @__PURE__ */ jsx("button", {
104
+ type: "button",
105
+ className: "dd-fb-link",
106
+ onClick: retry,
107
+ children: words.retry
108
+ })]
109
+ });
110
+ }
111
+ function ValueRow({ control, value }) {
112
+ const format = useFormat();
113
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Mark, {
114
+ control,
115
+ value
116
+ }), /* @__PURE__ */ jsx("span", {
117
+ className: "dd-fb-option-text",
118
+ children: format(control, value)
119
+ })] });
120
+ }
121
+ /** The list's rows: each value with its mark, checked when chosen. */
122
+ function optionsOf(control, shown, chosen, onToggle) {
123
+ return shown.map((v) => ({
124
+ id: String(v),
125
+ selected: chosen.includes(v),
126
+ onPick: () => {
127
+ onToggle(v);
128
+ },
129
+ content: /* @__PURE__ */ jsx(ValueRow, {
130
+ control,
131
+ value: v
132
+ })
133
+ }));
134
+ }
135
+ /** A searchable checklist of a control's values: its own list, or values searched on the server. */
136
+ function ValueList({ control, pick, onToggle, onClear, onBack, before }) {
137
+ const words = useWords();
138
+ const chosen = chosenOf(pick);
139
+ const [query, setQuery] = useState("");
140
+ const { shown, pending, read } = useShownValues(control, chosen, query);
141
+ const options = optionsOf(control, shown, chosen, onToggle);
142
+ return /* @__PURE__ */ jsxs("div", {
143
+ className: "dd-fb-values",
144
+ children: [
145
+ /* @__PURE__ */ jsx(Combobox, {
146
+ label: words.search(control.label),
147
+ placeholder: words.search(control.label),
148
+ query,
149
+ onQuery: setQuery,
150
+ multiselect: takesMany(control, pick !== void 0 && isNegative(pick.op)),
151
+ busy: pending,
152
+ ...onBack === void 0 ? {} : { onBack },
153
+ before,
154
+ empty: pending ? words.searching : words.noMatch(control.label, query),
155
+ options
156
+ }),
157
+ read.failed ? /* @__PURE__ */ jsx(ValuesFailed, { retry: read.retry }) : null,
158
+ /* @__PURE__ */ jsx(ValueFoot, {
159
+ count: chosen.length,
160
+ searching: pending && shown.length > 0,
161
+ onClear
162
+ })
163
+ ]
164
+ });
165
+ }
166
+ export { Mark, ValueList, ValuesSummary };
@@ -0,0 +1,81 @@
1
+ /** Every word the filter bar shows. Pass any of them as `messages.filterBar` to the provider. */
2
+ export type FilterWords = {
3
+ /** The button that opens the menu of every filter. */
4
+ filter: string;
5
+ /** The phone button that opens the sheet of every filter, with how many are set. */
6
+ filters: (set: number) => string;
7
+ /** The menu's search box. */
8
+ menuPlaceholder: string;
9
+ menuNoMatch: string;
10
+ suggestions: string;
11
+ fields: string;
12
+ /** How many more filters the menu holds than the bar shows. */
13
+ more: (count: number) => string;
14
+ search: (label: string) => string;
15
+ searching: string;
16
+ noMatch: (label: string, query: string) => string;
17
+ anyValue: string;
18
+ selected: (count: number) => string;
19
+ clear: string;
20
+ isWord: string;
21
+ isNotWord: string;
22
+ isAnyOf: string;
23
+ isNoneOf: string;
24
+ operator: (label: string, now: string) => string;
25
+ changeValues: (label: string, values: string) => string;
26
+ remove: (label: string) => string;
27
+ filterBy: (label: string) => string;
28
+ /** No date picked: each widget keeps the range it was built with. */
29
+ widgetDates: string;
30
+ customRange: string;
31
+ pickDays: string;
32
+ previousMonth: string;
33
+ nextMonth: string;
34
+ daysIn: (zone: string) => string;
35
+ dashboardZone: string;
36
+ apply: string;
37
+ min: string;
38
+ max: string;
39
+ to: string;
40
+ notNumbers: string;
41
+ minOverMax: string;
42
+ yourView: string;
43
+ fromLink: string;
44
+ undo: string;
45
+ done: string;
46
+ set: string;
47
+ keys: {
48
+ pick: string;
49
+ removeLast: string;
50
+ close: string;
51
+ };
52
+ /** A chip's field segment, for screen readers. */
53
+ field: (label: string) => string;
54
+ /** Default words for empty and yes-or-no values (a host's `formatValue` comes first). */
55
+ none: string;
56
+ yes: string;
57
+ no: string;
58
+ /** The Undo line after a removal, and after Reset. */
59
+ removed: (labels: readonly string[]) => string;
60
+ cleared: string;
61
+ /** A number field's quick picks from its buckets; `unit` is "" or " h". */
62
+ under: (n: number, unit: string) => string;
63
+ between: (lo: number, hi: number, unit: string) => string;
64
+ orMore: (n: number, unit: string) => string;
65
+ /** The control takes a minimum or a maximum, not both. */
66
+ oneBound: string;
67
+ /** The control takes a range only: both bounds. */
68
+ bothBounds: string;
69
+ /** The one box of a number filter that takes an exact value. */
70
+ value: string;
71
+ /** Typed words the Filter menu understands: "not", words to skip, words for the date. */
72
+ grammar: {
73
+ not: readonly string[];
74
+ skip: readonly string[];
75
+ dates: readonly string[];
76
+ };
77
+ /** A list of values that could not be read. */
78
+ valuesFailed: string;
79
+ retry: string;
80
+ };
81
+ export declare const ENGLISH_FILTERS: FilterWords;
@@ -0,0 +1,73 @@
1
+ // src/filters/words.ts
2
+ const ENGLISH_FILTERS = {
3
+ filter: "Filter",
4
+ filters: (set) => set === 0 ? "Filters" : `Filters · ${String(set)}`,
5
+ menuPlaceholder: "Filter by…",
6
+ menuNoMatch: "No field or value matches.",
7
+ suggestions: "Suggestions",
8
+ fields: "Fields",
9
+ more: (count) => `+${String(count)}`,
10
+ search: (label) => `Search ${label.toLowerCase()}…`,
11
+ searching: "Searching…",
12
+ noMatch: (label, query) => `No ${label.toLowerCase()} matches “${query}”`,
13
+ anyValue: "Any value",
14
+ selected: (count) => `${String(count)} selected`,
15
+ clear: "Clear",
16
+ isWord: "is",
17
+ isNotWord: "is not",
18
+ isAnyOf: "is any of",
19
+ isNoneOf: "is none of",
20
+ operator: (label, now) => `${label} operator: ${now}. Change`,
21
+ changeValues: (label, values) => `Change ${label}: ${values}`,
22
+ remove: (label) => `Remove ${label} filter`,
23
+ filterBy: (label) => `Filter by ${label}`,
24
+ widgetDates: "Each widget's own",
25
+ customRange: "Custom range",
26
+ pickDays: "Pick a first and a last day",
27
+ previousMonth: "Previous month",
28
+ nextMonth: "Next month",
29
+ daysIn: (zone) => `Days in ${zone}`,
30
+ dashboardZone: "the dashboard's time zone",
31
+ apply: "Apply",
32
+ min: "Min",
33
+ max: "Max",
34
+ to: "to",
35
+ notNumbers: "Enter numbers only.",
36
+ minOverMax: "The minimum must be no more than the maximum.",
37
+ yourView: "Your view",
38
+ fromLink: "From a link",
39
+ undo: "Undo",
40
+ done: "Done",
41
+ set: "set",
42
+ keys: {
43
+ pick: "pick",
44
+ removeLast: "remove last",
45
+ close: "close"
46
+ },
47
+ field: (label) => `${label} filter`,
48
+ none: "None",
49
+ yes: "Yes",
50
+ no: "No",
51
+ removed: (labels) => `${labels.join(", ")} filter${labels.length > 1 ? "s" : ""} removed`,
52
+ cleared: "Filters cleared",
53
+ under: (n, unit) => `Under ${String(n)}${unit}`,
54
+ between: (lo, hi, unit) => `${String(lo)} to ${String(hi)}${unit}`,
55
+ orMore: (n, unit) => `${String(n)}${unit} or more`,
56
+ oneBound: "Enter a minimum or a maximum, not both.",
57
+ bothBounds: "Enter both a minimum and a maximum.",
58
+ value: "Value",
59
+ grammar: {
60
+ not: ["not"],
61
+ skip: ["is"],
62
+ dates: [
63
+ "date",
64
+ "dates",
65
+ "when",
66
+ "time",
67
+ "range"
68
+ ]
69
+ },
70
+ valuesFailed: "Could not load the values.",
71
+ retry: "Retry"
72
+ };
73
+ export { ENGLISH_FILTERS };
@@ -51,10 +51,12 @@ function numberText(cell, column, locale) {
51
51
  function percentText(cell, how, locale) {
52
52
  const { signed } = how;
53
53
  const shift = how.fraction ? "" : "E-2";
54
+ const share = (typeof cell === "number" ? cell : Number(cell.v)) / (how.fraction ? 1 : 100);
55
+ const places = Math.abs(share) >= .1 || share === 0 ? 0 : 1;
54
56
  const style = {
55
57
  style: "percent",
56
- minimumFractionDigits: 2,
57
- maximumFractionDigits: 2,
58
+ minimumFractionDigits: places,
59
+ maximumFractionDigits: places,
58
60
  signDisplay: signed ? "exceptZero" : "auto"
59
61
  };
60
62
  if (typeof cell === "number") return new Intl.NumberFormat(locale, style).format(how.fraction ? cell : cell / 100);
@@ -84,12 +86,12 @@ function formatText(text, column, locale, timeZone) {
84
86
  }
85
87
  /** Decimal text in the viewer's locale, exactly: Intl formats the digits, never a float. */
86
88
  function exactText(text, currency, locale) {
87
- const digits = text.split(".")[1]?.length ?? 0;
89
+ const cents = text.split(".")[1] ?? "";
88
90
  const style = currency === void 0 ? {} : {
89
91
  style: "currency",
90
92
  currency
91
93
  };
92
- const places = currency === void 0 ? Math.min(digits, 2) : 2;
94
+ const places = /^0*$/u.test(cents) ? 0 : currency === void 0 ? Math.min(cents.length, 2) : 2;
93
95
  const fraction = {
94
96
  minimumFractionDigits: places,
95
97
  maximumFractionDigits: places
@@ -101,6 +103,11 @@ function exactText(text, currency, locale) {
101
103
  }
102
104
  /** A short axis label: 12K, $1.2M. */
103
105
  function formatTick(value, column, locale) {
106
+ if (column?.format === "percent") return new Intl.NumberFormat(locale, {
107
+ style: "percent",
108
+ maximumFractionDigits: 1
109
+ }).format(column.fraction === true ? value : value / 100);
110
+ if (column?.format === "duration") return durationText(value, locale);
104
111
  const currency = currencyOf(column?.unit);
105
112
  const style = currency === void 0 ? {} : {
106
113
  style: "currency",