@mistriwork/kit 1.0.0-rc.14 → 1.0.0-rc.16

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 (79) hide show
  1. package/dist/client/app.js +2 -1
  2. package/dist/client/components/AppList.js +12 -1
  3. package/dist/client/components/ChartFigure.d.ts +3 -2
  4. package/dist/client/components/ChartFigure.js +7 -5
  5. package/dist/client/components/Dressed.js +3 -0
  6. package/dist/client/components/Editable.js +3 -2
  7. package/dist/client/components/ErrorBoundary.js +1 -1
  8. package/dist/client/components/Grid.d.ts +15 -1
  9. package/dist/client/components/Grid.js +44 -7
  10. package/dist/client/components/JsonView.d.ts +2 -1
  11. package/dist/client/components/JsonView.js +2 -2
  12. package/dist/client/components/NewRecord.d.ts +3 -1
  13. package/dist/client/components/NewRecord.js +16 -5
  14. package/dist/client/components/PageCurrent.d.ts +10 -1
  15. package/dist/client/components/PageCurrent.js +10 -6
  16. package/dist/client/components/PageFields.js +14 -3
  17. package/dist/client/components/PageFlowDiagram.css +1 -1
  18. package/dist/client/components/PageHead.js +10 -9
  19. package/dist/client/components/PageHeadline.d.ts +3 -1
  20. package/dist/client/components/PageHeadline.js +3 -2
  21. package/dist/client/components/PageMetrics.js +13 -4
  22. package/dist/client/components/PageRelated.js +17 -2
  23. package/dist/client/components/PageSectionBox.js +6 -3
  24. package/dist/client/components/PageSections.js +1 -1
  25. package/dist/client/components/PageTimeline.js +44 -17
  26. package/dist/client/components/RecordSummaries.d.ts +5 -3
  27. package/dist/client/components/RecordSummaries.js +11 -2
  28. package/dist/client/components/TableRoom.d.ts +4 -1
  29. package/dist/client/components/TableRoom.js +10 -5
  30. package/dist/client/components/TableView.d.ts +4 -2
  31. package/dist/client/components/TableView.js +3 -3
  32. package/dist/client/components/TimelineReactions.css +49 -0
  33. package/dist/client/components/TimelineReactions.d.ts +18 -0
  34. package/dist/client/components/TimelineReactions.js +58 -0
  35. package/dist/client/components/TreePicker.css +25 -0
  36. package/dist/client/components/TreePicker.d.ts +59 -0
  37. package/dist/client/components/TreePicker.js +407 -0
  38. package/dist/client/components/Value.d.ts +2 -0
  39. package/dist/client/components/Value.js +67 -7
  40. package/dist/client/components/appListModel.d.ts +2 -0
  41. package/dist/client/components/chromeIcons.d.ts +1 -0
  42. package/dist/client/components/chromeIcons.js +1 -0
  43. package/dist/client/components/dashboardModel.d.ts +2 -2
  44. package/dist/client/components/inputRenderers.d.ts +7 -1
  45. package/dist/client/components/inputRenderers.js +2 -0
  46. package/dist/client/components/jsonModel.d.ts +3 -0
  47. package/dist/client/components/jsonModel.js +8 -0
  48. package/dist/client/components/pageContext.js +2 -1
  49. package/dist/client/components/pageModel.d.ts +14 -5
  50. package/dist/client/components/reactionTally.d.ts +20 -0
  51. package/dist/client/components/reactionTally.js +46 -0
  52. package/dist/client/components/useGridGroups.d.ts +11 -0
  53. package/dist/client/components/useGridGroups.js +70 -0
  54. package/dist/client/components/useGridKeyboard.d.ts +2 -0
  55. package/dist/client/components/useGridKeyboard.js +18 -1
  56. package/dist/client/components/valueModel.d.ts +10 -3
  57. package/dist/client/components/valueModel.js +21 -1
  58. package/dist/client/copy/forms/components/TreePicker.d.ts +9 -0
  59. package/dist/client/copy/forms/components/TreePicker.js +11 -0
  60. package/dist/client/copy/lists/components/Grid.d.ts +1 -1
  61. package/dist/client/copy/lists/components/Grid.js +1 -1
  62. package/dist/client/copy/lists/components/useGridGroups.d.ts +3 -0
  63. package/dist/client/copy/lists/components/useGridGroups.js +5 -0
  64. package/dist/client/copy/record/components/PageTimeline.d.ts +1 -0
  65. package/dist/client/copy/record/components/PageTimeline.js +1 -0
  66. package/dist/client/copy/record/components/TimelineReactions.d.ts +7 -0
  67. package/dist/client/copy/record/components/TimelineReactions.js +6 -0
  68. package/dist/client/copy/record/components/Value.d.ts +3 -0
  69. package/dist/client/copy/record/components/Value.js +3 -0
  70. package/dist/client/copy/shell/components/ErrorBoundary.d.ts +1 -1
  71. package/dist/client/copy/shell/components/ErrorBoundary.js +1 -1
  72. package/dist/client/features.css +37 -1
  73. package/dist/client/index.html +1 -1
  74. package/dist/client/page.css +33 -4
  75. package/dist/client/shellHost.d.ts +1 -1
  76. package/dist/client/shellHost.js +1 -1
  77. package/dist/client/structure.css +18 -3
  78. package/dist/client/style.css +11 -2
  79. package/package.json +4 -4
@@ -0,0 +1,49 @@
1
+ /* A timeline's reactions (its `reactions`), fetched with TimelineReactions.tsx the first time a section with reactions
2
+ draws, so a first page carries none of it. In the base layer, beside the rest of the timeline in page.css. */
3
+ @layer base {
4
+ /* Reactions under a message: a quiet row of outlined kinds in the column of its words, the reader's own on the accent's
5
+ wash. A press changes the count and the ground, and nothing moves or springs (docs/design.md, motion). */
6
+ .timeline-reactions {
7
+ grid-column: 2;
8
+ display: flex;
9
+ flex-wrap: wrap;
10
+ gap: var(--space-2);
11
+ margin-top: var(--space-1);
12
+ }
13
+ .timeline-reaction {
14
+ position: relative;
15
+ display: inline-flex;
16
+ align-items: center;
17
+ gap: var(--space-2);
18
+ min-height: 24px;
19
+ padding: 0 var(--space-3);
20
+ border: 1px solid var(--line);
21
+ border-radius: var(--radius);
22
+ background: none;
23
+ font-size: var(--text-sm);
24
+ color: var(--ink-muted);
25
+ }
26
+ .timeline-reaction:is([aria-pressed='true'], [data-pressed='true']) {
27
+ border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
28
+ background: color-mix(in srgb, var(--accent) 8%, transparent);
29
+ color: var(--ink);
30
+ }
31
+ .timeline-reaction-count {
32
+ font-variant-numeric: tabular-nums;
33
+ color: var(--ink-subtle);
34
+ }
35
+ @media (hover: hover) and (pointer: fine) {
36
+ button.timeline-reaction:hover:not(:disabled) {
37
+ border-color: var(--line-strong);
38
+ color: var(--ink);
39
+ }
40
+ }
41
+ /* On a touch screen a kind's 24px takes a 44px hit area, as the chrome's small controls do (structure.css). */
42
+ @media (pointer: coarse) {
43
+ button.timeline-reaction::after {
44
+ content: '';
45
+ position: absolute;
46
+ inset: -10px 0;
47
+ }
48
+ }
49
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * A timeline entry's reactions: a quiet row of the kinds the section offers, each said through the column's display
3
+ * rule with its count, the reader's own pressed. The counts of every entry on the page are one breakdown, and the
4
+ * reader's own one more read beside it (`<by> = me`), asked together; pressing a kind runs the App's own command on
5
+ * the entry — found through the action of the entry's resource that offers it, as a composer's is — with the kind as
6
+ * its input, so the command decides what a press means (give one, or take it back) under the reader's grants. A reader
7
+ * not granted it reads the counts and presses nothing; a kind no one gave is not drawn for them. A part of its own,
8
+ * with its stylesheet: a page whose timelines carry no reactions never fetches it (PageTimeline.tsx).
9
+ */
10
+ import './TimelineReactions.css';
11
+ import type { TimelineReactions as Reactions } from '@mistriwork/engine/shared/pageModel.js';
12
+ import { type ReactionEntry, type ReactionTally } from './reactionTally.js';
13
+ /** One entry's row of reactions. */
14
+ export declare function ReactionRow({ reactions, entry, tally }: {
15
+ reactions: Reactions;
16
+ entry: ReactionEntry;
17
+ tally: ReactionTally;
18
+ }): import("react").JSX.Element;
@@ -0,0 +1,58 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * A timeline entry's reactions: a quiet row of the kinds the section offers, each said through the column's display
4
+ * rule with its count, the reader's own pressed. The counts of every entry on the page are one breakdown, and the
5
+ * reader's own one more read beside it (`<by> = me`), asked together; pressing a kind runs the App's own command on
6
+ * the entry — found through the action of the entry's resource that offers it, as a composer's is — with the kind as
7
+ * its input, so the command decides what a press means (give one, or take it back) under the reader's grants. A reader
8
+ * not granted it reads the counts and presses nothing; a kind no one gave is not drawn for them. A part of its own,
9
+ * with its stylesheet: a page whose timelines carry no reactions never fetches it (PageTimeline.tsx).
10
+ */
11
+ import './TimelineReactions.css';
12
+ import { useState } from 'react';
13
+ import { useQueryClient } from '@tanstack/react-query';
14
+ import { columnDisplay, findTable } from '../core.js';
15
+ import { pageBridge } from '../uiBridge.js';
16
+ import { entryKey } from './reactionTally.js';
17
+ import { choiceWord } from './valueModel.js';
18
+ import { Icon } from './Icon.js';
19
+ import { say } from '../copy/record/components/TimelineReactions.js';
20
+ /** One entry's row of reactions. */
21
+ export function ReactionRow({ reactions, entry, tally }) {
22
+ const queries = useQueryClient();
23
+ const [busy, setBusy] = useState(false);
24
+ const handle = pageBridge.commands?.command(reactions.command);
25
+ const pressable = Boolean(handle?.granted);
26
+ const table = findTable(reactions.from);
27
+ const rule = columnDisplay(table?.id ?? reactions.from, reactions.column);
28
+ const kinds = reactions.kinds.map((kind) => {
29
+ const icon = rule?.icons && Object.hasOwn(rule.icons, kind) ? rule.icons[kind] : undefined;
30
+ return {
31
+ kind,
32
+ word: choiceWord(rule, kind),
33
+ icon,
34
+ count: tally.counts.get(entryKey(entry.value, kind)) ?? 0,
35
+ pressed: tally.mine.has(entryKey(entry.value, kind)),
36
+ };
37
+ });
38
+ const shown = pressable ? kinds : kinds.filter((each) => each.count > 0);
39
+ if (!shown.length)
40
+ return null;
41
+ const press = async (kind, word) => {
42
+ if (!handle || busy)
43
+ return;
44
+ setBusy(true);
45
+ try {
46
+ const outcome = await handle.run({ [entry.column]: entry.value }, { [reactions.column]: kind }, { label: word });
47
+ if (outcome.status === 'applied')
48
+ await queries.invalidateQueries({ queryKey: ['page-reactions'] });
49
+ }
50
+ finally {
51
+ setBusy(false);
52
+ }
53
+ };
54
+ return (_jsx("div", { className: "timeline-reactions", role: "group", "aria-label": say('reactions'), children: shown.map(({ kind, word, icon, count, pressed }) => {
55
+ const said = (_jsxs(_Fragment, { children: [icon && _jsx(Icon, { name: icon, size: 14, className: "timeline-reaction-icon" }), _jsx("span", { children: word }), count > 0 && _jsx("span", { className: "timeline-reaction-count", children: count })] }));
56
+ return pressable ? (_jsx("button", { type: "button", className: "timeline-reaction", "aria-pressed": pressed, "aria-label": say('reactionCount', { kind: word, count }), disabled: busy, onClick: () => void press(kind, word), children: said }, kind)) : (_jsx("span", { className: "timeline-reaction", "data-pressed": pressed ? 'true' : undefined, children: said }, kind));
57
+ }) }));
58
+ }
@@ -0,0 +1,25 @@
1
+ /* Brought by a tree picker (TreePicker.tsx), loaded only where a reference is drawn as one. Tokens only. The box,
2
+ the popup and its rows are the record picker's own (features.css); this is what a tree adds to them. */
3
+ @layer components {
4
+ .tree-picker { display: grid; gap: var(--space-1h); min-width: 0; }
5
+ /* The record picker's list measures its room from Base UI's --available-height, as this one does. */
6
+ .tree-picker-popup { width: 100%; }
7
+ .tree-picker-option { justify-content: flex-start; align-items: center; gap: var(--space-2); }
8
+ .tree-picker-option .picker-option-label { flex: 0 1 auto; }
9
+ .tree-picker-caret {
10
+ display: inline-grid; place-items: center; flex: none; width: 20px; height: 20px;
11
+ color: var(--ink-muted); border-radius: min(4px, var(--radius));
12
+ }
13
+ .tree-picker-caret.is-leaf { cursor: inherit; }
14
+ @media (hover: hover) {
15
+ .tree-picker-caret:not(.is-leaf):hover { color: var(--ink); }
16
+ }
17
+ /* A match's path, after its name and pushed to the row's end, as a choice's second line is said. */
18
+ .tree-picker-path { margin-inline-start: auto; text-align: end; }
19
+ /* The chosen record's path under the box: quiet, one line, its separators lighter than its names. */
20
+ .tree-picker-trail {
21
+ display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1) var(--space-1h); margin: 0;
22
+ font: var(--text-xs) var(--sans); color: var(--ink-muted);
23
+ }
24
+ .tree-picker-sep { color: var(--ink-subtle); }
25
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * A reference picker over a hierarchy: a reference whose records hang from one another by a parent column
3
+ * (`tree: 'parent_id'`, on a command's reference and on a New form's field). A category three levels down is found
4
+ * by walking to it, not by remembering its exact name, and once chosen it is said with its path — Hardware ›
5
+ * Laptops › Batteries — so two records of one name under different parents are told apart.
6
+ *
7
+ * The box is a combobox (APG) whose popup is the tree: focus stays in the box, the lit row is its active
8
+ * descendant. Up and Down move through what is open, Right opens a branch or steps into it, Left folds it or steps
9
+ * out to its parent, Home and End go to the ends, Enter chooses, Escape closes. Typing searches every level at once,
10
+ * the popup a list of matches each said with its path; clearing the box goes back to the tree.
11
+ *
12
+ * Read lazily, a level at a time: the records with no parent when the box opens, a branch's children when it is
13
+ * opened, and for each level one breakdown says which of its records have children, so a leaf draws no caret and
14
+ * nothing is read per record. A record whose parent the field's own filter leaves out is not under any branch; a
15
+ * search finds it. A path is read upward a level per request, bounded, and a loop in the data ends it.
16
+ *
17
+ * Every read is the reader's own (`ask`): the reader's connection, or a public form's visitor read, so the tree
18
+ * offers only the records its reader may read, as a flat picker does. Nothing slides open (motion rule 8).
19
+ */
20
+ import './TreePicker.css';
21
+ import { type Ref } from 'react';
22
+ export type TreeValue = string | number;
23
+ /** One read, as the reader may make it: `/api/run` for rows, `/api/breakdown` for which rows have children. */
24
+ export type TreeAsk = (path: '/api/run' | '/api/breakdown', body: Record<string, unknown>) => Promise<{
25
+ rows?: unknown;
26
+ errors?: unknown[];
27
+ }>;
28
+ interface TreePickerProps {
29
+ /** The table (or resource) the records are read from, as query text starts. */
30
+ from: string;
31
+ /** Its key column: the value kept. */
32
+ by: string;
33
+ /** The column each record is said by. */
34
+ labelColumn: string;
35
+ /** The column naming each record's parent, by `by`. */
36
+ parent: string;
37
+ /** Only the records this condition admits (the field's own filter). */
38
+ where?: string;
39
+ ask: TreeAsk;
40
+ /** Who reads, for the answers kept between opens: a reader's answers are never another's. */
41
+ scope: string;
42
+ value: TreeValue | '' | undefined;
43
+ onChange: (value: TreeValue | '', label?: string) => void;
44
+ /** The chosen record's name where the caller has it already. */
45
+ known?: string;
46
+ id?: string;
47
+ /** The box's name where no `<label for>` gives it one. */
48
+ ariaLabel?: string;
49
+ /** What the popup is called where the box is named by its `<label>`: the field's caption. */
50
+ listLabel?: string;
51
+ describedBy?: string;
52
+ invalid?: boolean;
53
+ required?: boolean;
54
+ disabled?: boolean;
55
+ placeholder?: string;
56
+ inputRef?: Ref<HTMLInputElement>;
57
+ }
58
+ export declare function TreePicker({ from, by, labelColumn, parent, where, ask, scope, value, onChange, known, id, ariaLabel, listLabel, describedBy, invalid, required, disabled, placeholder, inputRef, }: TreePickerProps): import("react").JSX.Element;
59
+ export {};
@@ -0,0 +1,407 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * A reference picker over a hierarchy: a reference whose records hang from one another by a parent column
4
+ * (`tree: 'parent_id'`, on a command's reference and on a New form's field). A category three levels down is found
5
+ * by walking to it, not by remembering its exact name, and once chosen it is said with its path — Hardware ›
6
+ * Laptops › Batteries — so two records of one name under different parents are told apart.
7
+ *
8
+ * The box is a combobox (APG) whose popup is the tree: focus stays in the box, the lit row is its active
9
+ * descendant. Up and Down move through what is open, Right opens a branch or steps into it, Left folds it or steps
10
+ * out to its parent, Home and End go to the ends, Enter chooses, Escape closes. Typing searches every level at once,
11
+ * the popup a list of matches each said with its path; clearing the box goes back to the tree.
12
+ *
13
+ * Read lazily, a level at a time: the records with no parent when the box opens, a branch's children when it is
14
+ * opened, and for each level one breakdown says which of its records have children, so a leaf draws no caret and
15
+ * nothing is read per record. A record whose parent the field's own filter leaves out is not under any branch; a
16
+ * search finds it. A path is read upward a level per request, bounded, and a loop in the data ends it.
17
+ *
18
+ * Every read is the reader's own (`ask`): the reader's connection, or a public form's visitor read, so the tree
19
+ * offers only the records its reader may read, as a flat picker does. Nothing slides open (motion rule 8).
20
+ */
21
+ import './TreePicker.css';
22
+ import { Fragment, useEffect, useId, useLayoutEffect, useRef, useState } from 'react';
23
+ import { useQueryClient } from '@tanstack/react-query';
24
+ import { Popover } from '@base-ui/react/popover';
25
+ import { layoutViewport, zoomAnchor } from '@mistriwork/ui/internal/anchor.js';
26
+ import { viewportBox } from '@mistriwork/ui/internal/ruler.js';
27
+ import { popupContainer, shellById } from '../shellHost.js';
28
+ import { andQuery, quoteValue } from '@mistriwork/engine/shared/query.js';
29
+ import { Icon } from './Icon.js';
30
+ import { formatNumber } from '../locale.js';
31
+ import { say } from '../copy/forms/components/TreePicker.js';
32
+ /** A level's records read at once; past it the level says so, and a search finds the rest. */
33
+ const LEVEL = 200;
34
+ /** A search's matches. */
35
+ const MATCHES = 20;
36
+ /** How far up a path is read. */
37
+ const DEPTH = 12;
38
+ const blank = (value) => value === null || value === undefined || value === '';
39
+ export function TreePicker({ from, by, labelColumn, parent, where, ask, scope, value, onChange, known, id, ariaLabel, listLabel, describedBy, invalid, required, disabled, placeholder, inputRef, }) {
40
+ const client = useQueryClient();
41
+ const base = useId();
42
+ const listId = `${base}-tree`;
43
+ const trailId = `${base}-trail`;
44
+ const [nodes, setNodes] = useState(new Map());
45
+ const [kids, setKids] = useState(new Map());
46
+ const [cut, setCut] = useState(new Set());
47
+ const [branches, setBranches] = useState(new Map());
48
+ const [opened, setOpened] = useState(new Set());
49
+ const [open, setOpen] = useState(false);
50
+ const [text, setText] = useState('');
51
+ const [typed, setTyped] = useState(false);
52
+ const [asked, setAsked] = useState('');
53
+ const [matches, setMatches] = useState();
54
+ const [active, setActive] = useState();
55
+ const known$ = useRef(nodes);
56
+ known$.current = nodes;
57
+ const requested = useRef(new Set());
58
+ /* The answers belong to their reader and their question: a new one starts the tree again. */
59
+ const question = JSON.stringify([scope, from, by, labelColumn, parent, where ?? '']);
60
+ const [held, setHeld] = useState(question);
61
+ if (held !== question) {
62
+ setHeld(question);
63
+ setNodes(new Map());
64
+ setKids(new Map());
65
+ setCut(new Set());
66
+ setBranches(new Map());
67
+ setOpened(new Set());
68
+ setMatches(undefined);
69
+ requested.current = new Set();
70
+ }
71
+ const shown = `show ${[...new Set([by, labelColumn, parent])].join(', ')}`;
72
+ const nodeOf = (row) => {
73
+ const key = row?.[by];
74
+ if (!(typeof key === 'string' || (typeof key === 'number' && Number.isSafeInteger(key))))
75
+ return null;
76
+ const up = row[parent];
77
+ return { key: String(key), value: key, label: String(row[labelColumn] ?? key), parent: blank(up) ? null : String(up) };
78
+ };
79
+ const learn = (found) => {
80
+ if (!found.length)
81
+ return;
82
+ const next = new Map(known$.current);
83
+ for (const node of found)
84
+ next.set(node.key, node);
85
+ known$.current = next;
86
+ setNodes(next);
87
+ };
88
+ const rowsOf = (q, limit) => client.fetchQuery({
89
+ queryKey: ['tree-picker', scope, q, limit],
90
+ staleTime: 30_000,
91
+ queryFn: async () => {
92
+ const data = await ask('/api/run', { q, limit, offset: 0, count: 'none' });
93
+ if (data.errors?.length || !Array.isArray(data.rows))
94
+ throw new Error(say('couldNotLoad'));
95
+ return data.rows;
96
+ },
97
+ });
98
+ /* Which of a level's records have children: one breakdown of the parent column over them, never a read each. */
99
+ const parentsAmong = (values) => client.fetchQuery({
100
+ queryKey: ['tree-picker', scope, 'branches', from, parent, where ?? '', values],
101
+ staleTime: 30_000,
102
+ queryFn: async () => {
103
+ const text = `${from} ${andQuery(where, `${parent} in (${values.map(quoteValue).join(', ')})`)} count as children by ${parent}`;
104
+ const data = await ask('/api/breakdown', { text, limit: values.length });
105
+ if (data.errors?.length || !Array.isArray(data.rows))
106
+ throw new Error(say('couldNotLoad'));
107
+ return new Set(data.rows.filter((row) => Number(row.children) > 0).map((row) => String(row[parent])));
108
+ },
109
+ });
110
+ const level = async (key) => {
111
+ if (requested.current.has(key))
112
+ return;
113
+ requested.current.add(key);
114
+ setKids((was) => new Map(was).set(key, 'loading'));
115
+ const above = known$.current.get(key);
116
+ const condition = key === '' ? `${parent} is empty` : `${parent} = ${quoteValue(above ? above.value : key)}`;
117
+ try {
118
+ const rows = await rowsOf(`${from} ${andQuery(where, condition)} ${shown} sort ${labelColumn}`, LEVEL + 1);
119
+ const found = rows
120
+ .slice(0, LEVEL)
121
+ .map(nodeOf)
122
+ .filter((node) => node !== null);
123
+ learn(found);
124
+ setKids((was) => new Map(was).set(key, found.map((node) => node.key)));
125
+ if (rows.length > LEVEL)
126
+ setCut((was) => new Set(was).add(key));
127
+ if (key !== '')
128
+ setBranches((was) => new Map(was).set(key, found.length > 0));
129
+ if (!found.length)
130
+ return;
131
+ /* Unknown where the breakdown cannot be read: such a record draws its caret and is settled when opened. */
132
+ const has = await parentsAmong(found.map((node) => node.value)).catch(() => undefined);
133
+ if (has)
134
+ setBranches((was) => {
135
+ const next = new Map(was);
136
+ for (const node of found)
137
+ if (!next.has(node.key) || next.get(node.key) !== false)
138
+ next.set(node.key, has.has(node.key));
139
+ return next;
140
+ });
141
+ }
142
+ catch {
143
+ requested.current.delete(key);
144
+ setKids((was) => new Map(was).set(key, 'error'));
145
+ }
146
+ };
147
+ /* A record's path, its root first, from what has been read: a loop in the data ends it rather than spinning. */
148
+ const pathOf = (key, map = nodes) => {
149
+ const out = [];
150
+ const seen = new Set();
151
+ for (let at = map.get(key); at && !seen.has(at.key) && out.length <= DEPTH; at = at.parent === null ? undefined : map.get(at.parent)) {
152
+ seen.add(at.key);
153
+ out.unshift(at);
154
+ }
155
+ return out;
156
+ };
157
+ /* The parents above these records that are not read yet, a level per request, bounded. */
158
+ const climb = async (start) => {
159
+ const missing = (list) => [
160
+ ...new Set(list.flatMap((node) => (node.parent === null || known$.current.has(node.parent) ? [] : [node.parent]))),
161
+ ];
162
+ let wanted = missing(start);
163
+ for (let step = 0; step < DEPTH && wanted.length; step++) {
164
+ const rows = await rowsOf(`${from} ${by} in (${wanted.map(quoteValue).join(', ')}) ${shown}`, wanted.length);
165
+ const found = rows.map(nodeOf).filter((node) => node !== null);
166
+ learn(found);
167
+ wanted = missing(found);
168
+ }
169
+ };
170
+ /* The chosen record, read by its key under the field's own filter, and its path above it. */
171
+ const chosen = blank(value) ? undefined : String(value);
172
+ useEffect(() => {
173
+ if (value === undefined || value === '')
174
+ return;
175
+ let live = true;
176
+ const have = known$.current.get(String(value));
177
+ const read = have
178
+ ? Promise.resolve(have)
179
+ : rowsOf(`${from} ${andQuery(where, `${by} = ${quoteValue(value)}`)} ${shown}`, 1).then((rows) => {
180
+ const node = nodeOf(rows[0]);
181
+ if (node && live)
182
+ learn([node]);
183
+ return node;
184
+ });
185
+ void read.then((node) => (node && live ? climb([node]) : undefined)).catch(() => { });
186
+ return () => {
187
+ live = false;
188
+ };
189
+ }, [value, question]);
190
+ const searching = typed && text.trim() !== '';
191
+ useEffect(() => {
192
+ const timer = setTimeout(() => setAsked(text.trim()), 150);
193
+ return () => clearTimeout(timer);
194
+ }, [text]);
195
+ useEffect(() => {
196
+ if (!open || !searching || !asked)
197
+ return;
198
+ let live = true;
199
+ const condition = `${labelColumn} contains ${JSON.stringify(asked)}`;
200
+ rowsOf(`${from} ${andQuery(where, condition)} ${shown} sort ${labelColumn}`, MATCHES)
201
+ .then(async (rows) => {
202
+ const found = rows.map(nodeOf).filter((node) => node !== null);
203
+ learn(found);
204
+ /* A path that cannot be read leaves the match said alone, not the search failed. */
205
+ await climb(found).catch(() => { });
206
+ if (live)
207
+ setMatches({ for: asked, keys: found.map((node) => node.key) });
208
+ })
209
+ .catch(() => live && setMatches({ for: asked, error: true }));
210
+ return () => {
211
+ live = false;
212
+ };
213
+ }, [open, searching, asked, question]);
214
+ /* Opened on the tree, it reads its tops and opens the way down to the chosen record, which is lit. */
215
+ const revealed = useRef(false);
216
+ useEffect(() => {
217
+ if (!open || searching) {
218
+ if (!open)
219
+ revealed.current = false;
220
+ return;
221
+ }
222
+ void level('');
223
+ if (revealed.current || !chosen)
224
+ return;
225
+ const path = pathOf(chosen);
226
+ if (!path.length || path[0].parent !== null)
227
+ return;
228
+ revealed.current = true;
229
+ const above = path.slice(0, -1);
230
+ setOpened((was) => new Set([...was, ...above.map((node) => node.key)]));
231
+ for (const node of above)
232
+ void level(node.key);
233
+ setActive(chosen);
234
+ }, [open, searching, chosen, nodes]);
235
+ const branch = (key) => branches.get(key) !== false;
236
+ const lines = [];
237
+ if (searching) {
238
+ const answer = matches?.for === text.trim() ? matches : undefined;
239
+ if (!answer)
240
+ lines.push({ key: 'note:', depth: 1, note: say('loading') });
241
+ else if ('error' in answer)
242
+ lines.push({ key: 'note:', depth: 1, note: say('couldNotLoad') });
243
+ else if (!answer.keys.length)
244
+ lines.push({ key: 'note:', depth: 1, note: say('noMatches') });
245
+ else
246
+ for (const key of answer.keys) {
247
+ const node = nodes.get(key);
248
+ if (node)
249
+ lines.push({
250
+ key,
251
+ depth: 1,
252
+ node,
253
+ path: pathOf(key)
254
+ .slice(0, -1)
255
+ .map((above) => above.label),
256
+ });
257
+ }
258
+ }
259
+ else {
260
+ const walk = (key, depth, seen) => {
261
+ const here = kids.get(key);
262
+ if (here === undefined || here === 'loading')
263
+ return void lines.push({ key: `note:${key}`, depth, note: say('loading') });
264
+ if (here === 'error')
265
+ return void lines.push({ key: `note:${key}`, depth, note: say('couldNotLoad') });
266
+ if (!here.length && key === '')
267
+ lines.push({ key: 'note:', depth, note: say('nothingToChoose') });
268
+ for (const child of here) {
269
+ const node = nodes.get(child);
270
+ if (!node || seen.has(child))
271
+ continue;
272
+ lines.push({ key: child, depth, node });
273
+ if (opened.has(child) && branch(child))
274
+ walk(child, depth + 1, new Set(seen).add(child));
275
+ }
276
+ if (cut.has(key))
277
+ lines.push({ key: `more:${key}`, depth, note: say('firstOnly', { count: formatNumber(LEVEL) }) });
278
+ };
279
+ if (open)
280
+ walk('', 1, new Set());
281
+ }
282
+ const choosable = lines.filter((line) => line.node);
283
+ const current = choosable.find((line) => line.key === active) ?? (searching ? choosable[0] : undefined);
284
+ const lineId = (line) => `${base}-${lines.indexOf(line)}`;
285
+ useEffect(() => {
286
+ if (open && current)
287
+ shellById(lineId(current))?.scrollIntoView?.({ block: 'nearest' });
288
+ }, [open, current?.key]);
289
+ const expand = (key) => {
290
+ setOpened((was) => new Set(was).add(key));
291
+ void level(key);
292
+ };
293
+ const fold = (key) => setOpened((was) => {
294
+ const next = new Set(was);
295
+ next.delete(key);
296
+ return next;
297
+ });
298
+ const close = () => {
299
+ setOpen(false);
300
+ /* Left with a record still chosen, the box says its name again rather than the half-typed search. */
301
+ if (chosen !== undefined) {
302
+ setTyped(false);
303
+ setText('');
304
+ }
305
+ };
306
+ const pick = (node) => {
307
+ onChange(node.value, node.label);
308
+ setTyped(false);
309
+ setText('');
310
+ setActive(node.key);
311
+ setOpen(false);
312
+ };
313
+ const onKeyDown = (event) => {
314
+ const at = current ? choosable.indexOf(current) : -1;
315
+ const light = (line) => line && setActive(line.key);
316
+ const tree = open && !searching && current?.node;
317
+ const keys = {
318
+ ArrowDown: () => (open ? light(choosable[Math.min(at + 1, choosable.length - 1)]) : setOpen(true)),
319
+ ArrowUp: () => (open ? light(choosable[Math.max(at - 1, 0)]) : setOpen(true)),
320
+ Home: open && !searching ? () => light(choosable[0]) : undefined,
321
+ End: open && !searching ? () => light(choosable[choosable.length - 1]) : undefined,
322
+ ArrowRight: tree
323
+ ? () => {
324
+ const key = current.key;
325
+ const below = kids.get(key);
326
+ if (!opened.has(key)) {
327
+ if (branch(key))
328
+ expand(key);
329
+ }
330
+ else if (Array.isArray(below) && below.length)
331
+ setActive(below[0]);
332
+ }
333
+ : undefined,
334
+ ArrowLeft: tree
335
+ ? () => {
336
+ const node = current.node;
337
+ if (opened.has(node.key) && branch(node.key))
338
+ fold(node.key);
339
+ else if (node.parent !== null && choosable.some((line) => line.key === node.parent))
340
+ setActive(node.parent);
341
+ }
342
+ : undefined,
343
+ Enter: open && current?.node ? () => pick(current.node) : undefined,
344
+ Escape: open
345
+ ? () => {
346
+ event.stopPropagation();
347
+ close();
348
+ }
349
+ : undefined,
350
+ };
351
+ const run = keys[event.key];
352
+ if (!run)
353
+ return;
354
+ event.preventDefault();
355
+ run();
356
+ };
357
+ /* The popup is as wide as the box, measured on the house ruler when it opens and again only when the box resizes:
358
+ Base UI's own anchor width is recomputed as the rows arrive (Typeahead.tsx says why that loops). */
359
+ const frame = useRef(null);
360
+ const [width, setWidth] = useState(null);
361
+ const [container, setContainer] = useState(null);
362
+ useLayoutEffect(() => {
363
+ if (!open || !frame.current)
364
+ return;
365
+ const anchor = frame.current;
366
+ setContainer(anchor.closest('dialog, [role="dialog"]'));
367
+ const measure = () => {
368
+ const measured = viewportBox(anchor).width;
369
+ setWidth(measured > 0 ? measured : null);
370
+ };
371
+ measure();
372
+ if (typeof ResizeObserver === 'undefined')
373
+ return;
374
+ const observer = new ResizeObserver(measure);
375
+ observer.observe(anchor);
376
+ return () => observer.disconnect();
377
+ }, [open]);
378
+ const box = typed ? text : chosen === undefined ? '' : (nodes.get(chosen)?.label ?? known ?? chosen);
379
+ const trail = chosen === undefined || typed ? [] : pathOf(chosen);
380
+ const said = trail.length > 1;
381
+ return (_jsxs("div", { className: "tree-picker", children: [_jsxs("div", { className: "picker", ref: frame, children: [_jsx("input", { ref: inputRef, id: id, className: "picker-input", role: "combobox", "aria-label": ariaLabel, "aria-expanded": open, "aria-controls": listId, "aria-haspopup": searching ? 'listbox' : 'tree', "aria-autocomplete": "list", "aria-activedescendant": open && current ? lineId(current) : undefined, "aria-describedby": [describedBy, said ? trailId : undefined].filter(Boolean).join(' ') || undefined, "aria-invalid": invalid || undefined, required: required, disabled: disabled, placeholder: placeholder ?? say('choose'), autoComplete: "off", value: box, onChange: (event) => {
382
+ setText(event.target.value);
383
+ setTyped(true);
384
+ setActive(undefined);
385
+ setOpen(true);
386
+ if (chosen !== undefined)
387
+ onChange('');
388
+ }, onClick: () => !disabled && setOpen(true), onBlur: close, onKeyDown: onKeyDown }), _jsx(Popover.Root, { open: open && !disabled, modal: false, onOpenChange: () => { }, children: _jsx(Popover.Portal, { container: container ?? popupContainer(), children: _jsx(Popover.Positioner, { anchor: () => (frame.current ? zoomAnchor(frame.current) : null), positionMethod: "fixed", side: "bottom", align: "start", sideOffset: 4, collisionBoundary: layoutViewport(), collisionPadding: 8, style: { zIndex: 40, width: width === null ? 'var(--anchor-width)' : `${width}px`, maxWidth: 'var(--available-width)' }, children: _jsx(Popover.Popup, { role: "presentation", initialFocus: false, finalFocus: false, className: "picker-popup tree-picker-popup", onMouseDown: (event) => event.preventDefault(), children: _jsx("ul", { id: listId, role: searching ? 'listbox' : 'tree', "aria-label": ariaLabel ?? listLabel, className: "picker-list", children: lines.map((line) => {
389
+ const node = line.node;
390
+ if (!node)
391
+ return (_jsx("li", { role: "presentation", className: "picker-empty", style: { paddingInlineStart: indent(line.depth) }, children: line.note }, line.key));
392
+ const lit = line === current;
393
+ const opens = !searching && branch(node.key);
394
+ return (_jsxs("li", { id: lineId(line), role: searching ? 'option' : 'treeitem', "aria-level": searching ? undefined : line.depth, "aria-expanded": opens ? opened.has(node.key) : undefined, "aria-selected": lit, className: `picker-option tree-picker-option${lit ? ' active' : ''}${node.key === chosen ? ' chosen' : ''}`, style: searching ? undefined : { paddingInlineStart: indent(line.depth) }, onClick: () => pick(node), children: [!searching && (_jsx("span", { className: `tree-picker-caret${opens ? '' : ' is-leaf'}`, "aria-hidden": "true", onClick: (event) => {
395
+ event.stopPropagation();
396
+ setActive(node.key);
397
+ if (!opens)
398
+ return;
399
+ if (opened.has(node.key))
400
+ fold(node.key);
401
+ else
402
+ expand(node.key);
403
+ }, children: opens && _jsx(Icon, { name: opened.has(node.key) ? 'caret-down' : 'caret-right', size: 12 }) })), _jsx("span", { className: "picker-option-label", children: node.label }), line.path && line.path.length > 0 && (_jsx("span", { className: "picker-option-detail tree-picker-path", children: line.path.join(' › ') }))] }, line.key));
404
+ }) }) }) }) }) })] }), said && (_jsx("p", { id: trailId, className: "tree-picker-trail", "aria-label": say('path'), children: trail.map((node, index) => (_jsxs(Fragment, { children: [index > 0 && (_jsx("span", { className: "tree-picker-sep", "aria-hidden": "true", children: "\u203A" })), _jsx("span", { children: node.label })] }, node.key))) }))] }));
405
+ }
406
+ /* A level's inset: the caret column stands under its parent's name. */
407
+ const indent = (depth) => `calc(var(--space-2) + ${(depth - 1) * 18}px)`;
@@ -17,6 +17,8 @@ interface ValueProps {
17
17
  wholeText?: boolean;
18
18
  /** The record the value is of, where a money rule reads its currency from another of its columns (money.ts). */
19
19
  row?: Readonly<Record<string, unknown>>;
20
+ /** Draw the rule's `subtitle` (a column of the same record) as a second line under the value, as a list's cell does. */
21
+ subtitled?: boolean;
20
22
  }
21
23
  /** A value as the record and the page show it: dressed when the app says, plain otherwise. */
22
24
  export declare function Value(props: ValueProps): import("react").JSX.Element;