viewkitjs 0.24.0 → 0.25.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 (82) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/fields/dist/creatable.d.ts +9 -5
  3. package/fields/dist/creatable.js +8 -1
  4. package/fields/dist/messages.d.ts +19 -1
  5. package/fields/dist/messages.js +75 -0
  6. package/fields/dist/registry.js +4 -7
  7. package/fields/dist/types.d.ts +4 -2
  8. package/fields/dist/zod.d.ts +58 -0
  9. package/fields/dist/zod.js +430 -2
  10. package/fields/docs/guides/checking-definitions.md +6 -1
  11. package/fields/docs/guides/field-types.md +5 -1
  12. package/fields/docs/reference/definitions.md +1 -2
  13. package/fields/docs/reference/types.md +2 -1
  14. package/fields/skills/viewkit/SKILL.md +2 -2
  15. package/package.json +1 -1
  16. package/views/dist/controls/avatar/avatar.d.ts +58 -0
  17. package/views/dist/controls/avatar/avatar.js +54 -0
  18. package/views/dist/controls/avatar/looks.d.ts +4 -0
  19. package/views/dist/controls/avatar/looks.js +5 -0
  20. package/views/dist/controls/avatar/tokens.d.ts +131 -0
  21. package/views/dist/controls/avatar/tokens.js +35 -0
  22. package/views/dist/controls/avatar.css +163 -0
  23. package/views/dist/controls/controls.d.ts +2 -0
  24. package/views/dist/controls/controls.js +2 -0
  25. package/views/dist/controls/index.d.ts +12 -0
  26. package/views/dist/controls/index.js +12 -0
  27. package/views/dist/controls/internal/phone.d.ts +9 -0
  28. package/views/dist/controls/internal/phone.js +15 -0
  29. package/views/dist/controls/internal/read-token.d.ts +2 -1
  30. package/views/dist/controls/internal/read-token.js +1 -1
  31. package/views/dist/controls/internal/scroll.d.ts +38 -0
  32. package/views/dist/controls/internal/scroll.js +126 -0
  33. package/views/dist/controls/list/looks.d.ts +4 -0
  34. package/views/dist/controls/list/looks.js +12 -0
  35. package/views/dist/controls/list.css +17 -13
  36. package/views/dist/controls/menu/map-menu.d.ts +11 -0
  37. package/views/dist/controls/menu/map-menu.js +47 -0
  38. package/views/dist/controls/menu/menu.d.ts +75 -0
  39. package/views/dist/controls/menu/menu.js +105 -0
  40. package/views/dist/controls/menu/tokens.d.ts +23 -0
  41. package/views/dist/controls/menu/tokens.js +8 -0
  42. package/views/dist/controls/menu-list/looks.d.ts +5 -1
  43. package/views/dist/controls/menu-list/looks.js +6 -4
  44. package/views/dist/controls/menu-list/menu-list.js +3 -1
  45. package/views/dist/controls/menu-list.css +39 -31
  46. package/views/dist/controls/menu.css +25 -0
  47. package/views/dist/controls/picker/looks.d.ts +19 -0
  48. package/views/dist/controls/picker/looks.js +32 -0
  49. package/views/dist/controls/picker/picker.d.ts +153 -0
  50. package/views/dist/controls/picker/picker.js +773 -0
  51. package/views/dist/controls/picker/rows.d.ts +129 -0
  52. package/views/dist/controls/picker/rows.js +90 -0
  53. package/views/dist/controls/picker/tokens.d.ts +147 -0
  54. package/views/dist/controls/picker/tokens.js +39 -0
  55. package/views/dist/controls/picker.css +237 -0
  56. package/views/dist/controls/popup-line/tokens.d.ts +23 -0
  57. package/views/dist/controls/popup-line/tokens.js +8 -0
  58. package/views/dist/controls/popup-line.css +44 -0
  59. package/views/dist/controls/select/filled.d.ts +7 -0
  60. package/views/dist/controls/select/filled.js +5 -0
  61. package/views/dist/controls/select/fit.d.ts +9 -0
  62. package/views/dist/controls/select/fit.js +11 -0
  63. package/views/dist/controls/select/select.d.ts +131 -0
  64. package/views/dist/controls/select/select.js +227 -0
  65. package/views/dist/controls/select/side.d.ts +3 -0
  66. package/views/dist/controls/select/side.js +4 -0
  67. package/views/dist/controls/select/tokens.d.ts +27 -0
  68. package/views/dist/controls/select/tokens.js +9 -0
  69. package/views/dist/controls/select.css +91 -0
  70. package/views/dist/controls/tokens.js +10 -0
  71. package/views/dist/looks/index.d.ts +4 -0
  72. package/views/dist/looks/index.js +4 -0
  73. package/views/dist/looks/pieces.js +6 -0
  74. package/views/dist/styles.css +586 -62
  75. package/views/dist/styles.unlayered.css +586 -62
  76. package/views/docs/controls/avatar.md +38 -0
  77. package/views/docs/controls/menu.md +11 -0
  78. package/views/docs/controls/picker.md +42 -0
  79. package/views/docs/controls/popup-line.md +11 -0
  80. package/views/docs/controls/select.md +12 -0
  81. package/views/docs/reference/controls.md +86 -0
  82. package/views/docs/reference/looks.md +8 -0
@@ -0,0 +1,773 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import * as React from "react";
3
+ import { Combobox as BaseCombobox } from "@base-ui/react/combobox";
4
+ import { Avatar } from "../avatar/avatar.js";
5
+ import { Button } from "../button/button.js";
6
+ import { CheckboxMark } from "../checkbox/checkbox.js";
7
+ import { GlassButton } from "../glass-button/glass-button.js";
8
+ import { Input, InputGroup, InputGroupAddon } from "../input/input.js";
9
+ import { Kbd } from "../kbd/kbd.js";
10
+ import { Menu, MenuDots } from "../menu/menu.js";
11
+ import { Option } from "../option/option.js";
12
+ import { Spinner } from "../spinner/spinner.js";
13
+ import { StatusGlyph } from "../status/status.js";
14
+ import { SheetButton } from "../sheet/bottom-sheet.js";
15
+ import { PhoneHost, usePhone } from "../internal/phone.js";
16
+ import { cx } from "../../internal/cx.js";
17
+ import { Icon } from "../internal/icons.js";
18
+ import { focusesInPlace, focusWhereItStands, keepsToItsList, scrollInList, staysInView } from "../internal/scroll.js";
19
+ import { useReorder } from "../internal/reorder.js";
20
+ import { Scrollbar } from "../scrollbar/scrollbar.js";
21
+ import { useHoldDrag } from "../internal/hold.js";
22
+ import { msOf, spacingPx } from "../internal/read-token.js";
23
+ import { exactMatch, findItem, fold, itemLabel, openLevels, orderMoved, pickerRows, searchShown } from "./rows.js";
24
+ import { pickerRead, pickerWornOf } from "./looks.js";
25
+ export { openLevels } from "./rows.js";
26
+ function phoneGroups(items) {
27
+ const out = [];
28
+ for (const i of items) {
29
+ const name = i.group ?? "";
30
+ let g = out.find((x) => x.name === name);
31
+ if (!g)
32
+ out.push((g = { name, items: [] }));
33
+ g.items.push(i);
34
+ }
35
+ return out;
36
+ }
37
+ function LeadMark({ lead, value }) {
38
+ if (lead.value === value)
39
+ return _jsx("span", { className: "o-picker-lead", children: lead.label });
40
+ const stop = (e) => e.stopPropagation();
41
+ return (_jsx(Button, { kind: "text", size: "2xs", className: "o-picker-lead-make", onMouseDown: (e) => { e.preventDefault(); e.stopPropagation(); }, onPointerDown: stop, onClick: (e) => { e.preventDefault(); e.stopPropagation(); lead.onLead(value); }, children: lead.makeLabel }));
42
+ }
43
+ const glyph = (paths, className, strokeWidth = 2) => (_jsx("svg", { className: className, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: strokeWidth, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: paths.map((d) => _jsx("path", { d: d }, d)) }));
44
+ const TICK = ["M5 12l5 5l10 -10"], PLUS = ["M12 5v14", "M5 12h14"], SEARCH = ["M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0", "M21 21l-6 -6"];
45
+ const BACK = ["M15 6l-6 6l6 6"], MORE = ["M9 6l6 6l-6 6"];
46
+ const DOTS_V = ["M12 4a1 1 0 1 0 0 2a1 1 0 1 0 0 -2", "M12 11a1 1 0 1 0 0 2a1 1 0 1 0 0 -2", "M12 18a1 1 0 1 0 0 2a1 1 0 1 0 0 -2"];
47
+ const Opens = ({ count }) => _jsxs("span", { className: "o-picker-opens", children: [_jsx("span", { className: "o-picker-opens-n", children: count }), glyph(MORE)] });
48
+ const RowCount = ({ item }) => (item.count === undefined ? null : _jsx("span", { className: "o-picker-row-count", children: item.count.toLocaleString("en-GB") }));
49
+ const itemEntry = (item) => ({ key: `item:${item.value}`, kind: "item", item });
50
+ const entryLabel = (e) => (e.kind === "item" || e.kind === "unpick" ? e.item.label : e.kind === "empty" ? e.label : e.kind === "create" ? e.typed : e.action.label);
51
+ function pressed(keys, e) {
52
+ if (!keys.some((k) => k === "⌘" || k === "⌥" || k === "⌃"))
53
+ return false;
54
+ const mods = { "⌘": e.metaKey, "⇧": e.shiftKey, "⌥": e.altKey, "⌃": e.ctrlKey };
55
+ const last = keys[keys.length - 1]?.toLowerCase();
56
+ if (!last || e.key.toLowerCase() !== last)
57
+ return false;
58
+ return Object.entries(mods).every(([k, down]) => keys.includes(k) === down);
59
+ }
60
+ function Name({ item, phone }) {
61
+ const as = item.as;
62
+ if (as && "option" in as)
63
+ return _jsx(Option, { size: phone ? "lg" : undefined, children: item.label });
64
+ if (as && "status" in as)
65
+ return _jsxs(_Fragment, { children: [_jsx("span", { className: "o-picker-mark", children: _jsx(StatusGlyph, { place: as.status, quarters: as.quarters }) }), item.label] });
66
+ if (as && "sign" in as)
67
+ return _jsxs(_Fragment, { children: [_jsx("span", { className: "o-picker-sign", children: as.sign }), item.label] });
68
+ if (as && "mark" in as)
69
+ return _jsxs(_Fragment, { children: [_jsx("span", { className: "o-picker-mark", children: as.mark }), item.label] });
70
+ return _jsx(_Fragment, { children: item.label });
71
+ }
72
+ function Face({ item, phone, size = 20 }) {
73
+ const as = item.as;
74
+ if (!as || !("avatar" in as))
75
+ return null;
76
+ return _jsx(Avatar, { name: item.label, kind: as.avatar === "company" ? "thing" : "person", id: as.id, src: as.src, size: phone ? 40 : size });
77
+ }
78
+ const After = ({ item }) => (item.after == null ? null : _jsx("span", { className: "o-picker-after", children: item.after }));
79
+ const lineOf = (item, kind) => kind === "line" && item.kind ? (item.line ? `${item.kind} · ${item.line}` : item.kind) : item.line;
80
+ function KindMark({ item, kind }) {
81
+ if (!item.kind)
82
+ return null;
83
+ if (kind === "end")
84
+ return _jsx("span", { className: "o-picker-kind", children: item.kind });
85
+ if (kind !== "badge")
86
+ return null;
87
+ const of = item.as && "avatar" in item.as ? item.as.avatar : "other";
88
+ return _jsx("span", { className: "o-picker-badge", "data-of": of, role: "img", "aria-label": item.kind, children: of === "other" ? item.kind.slice(0, 1) : _jsx(Icon, { name: of === "company" ? "company" : "user" }) });
89
+ }
90
+ function ItemBody({ item, multiple, worn, lead, count, menu }) {
91
+ const mark = worn.mark, line = lineOf(item, worn.kind), opens = count !== undefined;
92
+ return (_jsxs(_Fragment, { children: [multiple && mark === "tick" && !opens && _jsx(CheckboxMark, {}), _jsx(Face, { item: item, size: line && worn.line === "below" ? Number(worn.face) : 20 }), _jsxs("span", { className: "o-list-text", children: [_jsxs("span", { className: "o-list-main", children: [_jsx(Name, { item: item }), item.you && _jsx("span", { className: "o-list-you", children: "you" }), _jsx(After, { item: item })] }), line && _jsx("span", { className: "o-list-line", children: line })] }), _jsx(KindMark, { item: item, kind: worn.kind }), lead, opens ? _jsx(Opens, { count: count }) : _jsxs(_Fragment, { children: [_jsx(RowCount, { item: item }), multiple && mark === "check" && _jsx(CheckboxMark, {}), !multiple && (mark === "check" ? _jsx("span", { className: "o-picker-check", children: glyph(TICK, undefined, 3) }) : glyph(TICK, "o-list-tick", 2.25))] }), menu] }));
93
+ }
94
+ function grouped(rows, apart) {
95
+ const out = [{ rows: [] }];
96
+ const last = () => out[out.length - 1];
97
+ for (const r of rows) {
98
+ if (r.kind === "more")
99
+ continue;
100
+ if (r.kind === "line")
101
+ out.push({ line: true, rows: [] });
102
+ else if (r.kind === "heading") {
103
+ if (last().line && !last().rows.length && !last().heading)
104
+ last().heading = r.label;
105
+ else
106
+ out.push({ heading: r.label, rows: [] });
107
+ }
108
+ else if (r.kind === "create" && apart && out.some((g) => g.heading || g.rows.length))
109
+ out.push({ line: true, rows: [r] });
110
+ else if (r.kind === "create" && !apart && out.length > 1)
111
+ out.push({ rows: [r] });
112
+ else
113
+ last().rows.push(r);
114
+ }
115
+ return out.filter((g) => g.heading || g.rows.length);
116
+ }
117
+ const REFRESH = ["M20 11a8.1 8.1 0 0 0 -15.5 -2m-.5 -4v4h4", "M4 13a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4"];
118
+ const DOTS = ["M4 12a1 1 0 1 0 2 0a1 1 0 1 0 -2 0", "M11 12a1 1 0 1 0 2 0a1 1 0 1 0 -2 0", "M18 12a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"];
119
+ function PhoneRow({ item, circle, box, lead, kind, count, menu }) {
120
+ const line = lineOf(item, kind);
121
+ if (count !== undefined) {
122
+ circle = null;
123
+ box = false;
124
+ }
125
+ return (_jsxs(_Fragment, { children: [_jsx(Face, { item: item, phone: true }), _jsxs("span", { className: "o-list-text", children: [_jsxs("span", { className: "o-list-main", children: [_jsx(Name, { item: item, phone: true }), item.you && _jsx("span", { className: "o-list-you", children: "you" }), _jsx(After, { item: item })] }), line && _jsx("span", { className: "o-list-line", children: line })] }), _jsx(KindMark, { item: item, kind: kind }), lead, count !== undefined && _jsx(Opens, { count: count }), count === undefined && _jsx(RowCount, { item: item }), box && _jsx(CheckboxMark, {}), !box && circle && _jsx("span", { className: cx("o-picker-circle", circle === "off" && "o-picker-circle-off", circle === "fixed" && "o-picker-circle-fixed"), children: circle !== "off" && glyph(TICK, undefined, 3) }), menu] }));
126
+ }
127
+ function usePillTap(input) {
128
+ const start = React.useRef(null);
129
+ return {
130
+ onTouchStart: (e) => { const t = e.touches[0]; start.current = t && e.touches.length === 1 ? { x: t.clientX, y: t.clientY } : null; },
131
+ onTouchMove: (e) => {
132
+ const t = e.touches[0], s = start.current;
133
+ if (s && t && (Math.abs(t.clientX - s.x) > 10 || Math.abs(t.clientY - s.y) > 10))
134
+ start.current = null;
135
+ },
136
+ onTouchEnd: (e) => {
137
+ const box = input.current, tapped = start.current;
138
+ start.current = null;
139
+ if (!tapped || !box || box.disabled || box.ownerDocument.activeElement === box)
140
+ return;
141
+ if (Math.abs((window.visualViewport?.scale ?? 1) - 1) > 0.01)
142
+ return;
143
+ e.preventDefault();
144
+ focusWhereItStands(box);
145
+ },
146
+ onTouchCancel: () => { start.current = null; },
147
+ };
148
+ }
149
+ const HOLD = { delay: (row) => msOf(row, "--picker-hold"), swipe: (row) => spacingPx(2, row) };
150
+ export function usePicker(props) {
151
+ return usePickerAt(props);
152
+ }
153
+ function usePickerAt(props, under) {
154
+ const { label, items, multiple, value, onDone, empty, search, onSearch, doing, onRetry, onMore, nothingYet, actions = [], readOnly, none: noneWords } = props;
155
+ const onValueChange = readOnly ? () => { } : props.onValueChange, onCreate = readOnly ? undefined : props.onCreate;
156
+ const host = React.useContext(PhoneHost), small = usePhone();
157
+ const form = props.form ?? (host || small ? "phone" : "computer");
158
+ const inBox = under?.searchIn === "box", inBoxNow = React.useRef(inBox);
159
+ inBoxNow.current = inBox;
160
+ const [query, setQuery] = React.useState(() => {
161
+ const one = inBox && !multiple && value != null && !Array.isArray(value) ? value : null;
162
+ return one != null ? items.find((i) => i.value === one)?.label ?? one : props.typed ?? "";
163
+ });
164
+ const root = React.useRef(null), input = React.useRef(null), lit = React.useRef(-1);
165
+ const litRow = React.useRef(undefined), litByPerson = React.useRef(false);
166
+ const [listLit, setListLit] = React.useState(false), keyedOpen = React.useRef(false), atRestNow = React.useRef(false);
167
+ const pillInput = React.useRef(null), pillTap = usePillTap(pillInput);
168
+ const focusOnce = React.useRef(!!props.autoFocus);
169
+ React.useLayoutEffect(() => {
170
+ if (!focusOnce.current)
171
+ return;
172
+ focusOnce.current = false;
173
+ (pillInput.current ?? input.current)?.focus({ preventScroll: true });
174
+ }, []);
175
+ const holding = multiple && Array.isArray(value) ? value : [];
176
+ const holdingNow = React.useRef(holding);
177
+ holdingNow.current = holding;
178
+ const [draft, setDraft] = React.useState(holding);
179
+ const [room, setRoom] = React.useState(null);
180
+ const [placed, setPlaced] = React.useState(null);
181
+ const opening = React.useRef(props.typed ?? "");
182
+ opening.current = props.typed ?? "";
183
+ const typedNow = React.useRef(""), askServer = React.useRef(props.onSearch);
184
+ askServer.current = props.onSearch;
185
+ const levelsAt = (v) => { const f = v ? findItem(props.items, v) : undefined; return f?.item.level ? [...f.path, f.item] : []; };
186
+ const startNow = React.useRef([]);
187
+ startNow.current = levelsAt(props.defaultLevel);
188
+ const [ownOpened, setOwnOpened] = React.useState(() => startNow.current.map((i) => i.value));
189
+ const byHolder = props.onLevelsChange !== undefined, byHolderNow = React.useRef(byHolder);
190
+ byHolderNow.current = byHolder;
191
+ const opened = byHolder ? props.levels ?? [] : ownOpened;
192
+ const setOpened = (next) => (byHolder ? props.onLevelsChange(next) : setOwnOpened(next));
193
+ const startOver = React.useCallback(() => {
194
+ if (byHolderNow.current)
195
+ return;
196
+ const values = startNow.current.map((i) => i.value);
197
+ setOwnOpened((o) => (o.join("\u0000") === values.join("\u0000") ? o : values));
198
+ }, []);
199
+ const placeRoot = React.useCallback((el) => {
200
+ root.current = el;
201
+ setPlaced(el);
202
+ if (el)
203
+ setDraft(holdingNow.current);
204
+ else if (!inBoxNow.current) {
205
+ setQuery(opening.current);
206
+ if (typedNow.current !== opening.current)
207
+ askServer.current?.(opening.current);
208
+ }
209
+ if (!el)
210
+ startOver();
211
+ }, [startOver]);
212
+ React.useLayoutEffect(() => {
213
+ const scroller = placed?.parentElement?.closest(".o-sheet-body");
214
+ if (!scroller || placed?.closest(".o-sheet")?.getAttribute("data-sheet-form") !== "full") {
215
+ setRoom(null);
216
+ return;
217
+ }
218
+ const read = () => {
219
+ const c = getComputedStyle(scroller), top = parseFloat(c.paddingTop), under = parseFloat(c.paddingBottom);
220
+ setRoom((now) => { const height = Math.max(0, scroller.clientHeight - top - under); return now && now.height === height && now.under === under ? now : { height, under }; });
221
+ };
222
+ read();
223
+ const watch = new ResizeObserver(read);
224
+ watch.observe(scroller);
225
+ return () => watch.disconnect();
226
+ }, [placed]);
227
+ const shownIn = React.useRef(null);
228
+ React.useLayoutEffect(() => {
229
+ if (!props.heldInPlace || multiple || form !== "phone" || !placed || !room || shownIn.current === placed)
230
+ return;
231
+ shownIn.current = placed;
232
+ const scroller = placed.parentElement?.closest(".o-sheet-body"), row = placed.querySelector('[role="option"][aria-selected="true"]');
233
+ if (!scroller || !row)
234
+ return;
235
+ const bar = placed.querySelector(".o-picker-bar");
236
+ const foot = bar ? bar.getBoundingClientRect().top : scroller.getBoundingClientRect().bottom - room.under;
237
+ const past = row.getBoundingClientRect().bottom - foot;
238
+ if (past > 0)
239
+ scroller.scrollTop += Math.ceil(past);
240
+ }, [placed, room]);
241
+ const [worn, setWorn] = React.useState(() => pickerWornOf(null));
242
+ const mark = React.useRef(null);
243
+ React.useLayoutEffect(() => {
244
+ const read = () => setWorn((now) => { const next = pickerWornOf(mark.current ?? root.current); return Object.keys(next).every((k) => now[k] === next[k]) ? now : next; });
245
+ read();
246
+ const watch = new MutationObserver(read);
247
+ watch.observe(document.documentElement, { attributes: true, subtree: true, attributeFilter: pickerRead });
248
+ return () => watch.disconnect();
249
+ }, [placed]);
250
+ const asked = React.useRef(onMore);
251
+ asked.current = onMore;
252
+ const seenRef = React.useRef(null);
253
+ const more = React.useCallback((el) => {
254
+ seenRef.current?.disconnect();
255
+ seenRef.current = null;
256
+ if (!el || typeof IntersectionObserver === "undefined")
257
+ return;
258
+ let was = false;
259
+ seenRef.current = new IntersectionObserver((seen) => { const now = seen.some((x) => x.isIntersecting); if (now && !was)
260
+ asked.current?.(); was = now; });
261
+ seenRef.current.observe(el);
262
+ }, []);
263
+ const held = multiple ? (Array.isArray(value) ? value : []) : value != null && !Array.isArray(value) ? [value] : [];
264
+ const known = React.useRef(new Map());
265
+ for (const i of items)
266
+ known.current.set(i.value, i);
267
+ const inLevel = (v) => { const f = findItem(items, v); return f?.path.length ? { ...f.item, label: itemLabel(items, v) } : undefined; };
268
+ const itemOf = (v) => items.find((i) => i.value === v) ?? inLevel(v) ?? known.current.get(v) ?? { value: v, label: v };
269
+ const heldName = inBox && !multiple && held[0] != null ? itemOf(held[0]).label : "";
270
+ const find = inBox && !multiple && held[0] != null && query === heldName ? "" : query;
271
+ React.useLayoutEffect(() => { if (inBox && !under?.open)
272
+ setQuery(heldName); }, [inBox, under?.open, heldName]);
273
+ const chips = !!multiple && worn.picked === "chips" && form === "computer";
274
+ const atRest = listLit && !find.trim() && form === "computer";
275
+ atRestNow.current = atRest;
276
+ const restAttrs = atRest ? { "aria-activedescendant": undefined } : {};
277
+ const listed = chips ? items.filter((i) => !held.includes(i.value)) : items;
278
+ const heldNow = React.useRef(held);
279
+ heldNow.current = held;
280
+ const [ahead, setAhead] = React.useState(held);
281
+ React.useLayoutEffect(() => { setAhead(heldNow.current); }, [find, worn.picked]);
282
+ const heldKey = held.join("\u0000");
283
+ React.useLayoutEffect(() => { if (props.firstFollows)
284
+ setAhead(heldNow.current); }, [props.firstFollows, heldKey]);
285
+ const listFirst = !!multiple && worn.picked === "first" && form === "computer";
286
+ const firstOnes = new Set(listFirst && !find.trim() ? ahead : []);
287
+ const server = !!onSearch, create = !!onCreate, own = (props.draft ?? "own") === "own";
288
+ const openPath = openLevels(items, opened);
289
+ const level = openPath[openPath.length - 1];
290
+ const rows = doing ? [] : pickerRows({ items: listed, known: items, query: find, picked: held, empty: multiple ? undefined : empty, create, server, more: !!onMore, first: listFirst ? ahead : undefined, open: level ? openPath : undefined, levelRow: !byHolder });
291
+ const shown = inBox || !!level || (props.searchShown ?? (worn.search === "always" || searchShown({ count: items.length, create, server, query })));
292
+ const none = !items.length && !find && !!nothingYet;
293
+ typedNow.current = query;
294
+ const ask = (q) => { if (!inBox && !level && props.searchShown === false && !chips && q)
295
+ return; setQuery(q); onSearch?.(inBox && !multiple && held[0] != null && q === heldName ? "" : q); };
296
+ React.useEffect(() => { onSearch?.(props.typed ?? ""); }, []);
297
+ const heldEntries = held.map((v) => itemEntry(itemOf(v)));
298
+ const make = (typed) => { const v = onCreate(typed); ask(""); return v; };
299
+ const lightAfter = React.useRef(null);
300
+ const openLevel = (item, byKeys = false) => { lightAfter.current = byKeys || form === "phone" ? "" : null; setOpened([...openPath.map((i) => i.value), item.value]); ask(""); };
301
+ const back = (byKeys = false) => {
302
+ if (!level)
303
+ return;
304
+ lightAfter.current = byKeys || form === "phone" ? level.label : null;
305
+ setOpened(openPath.slice(0, -1).map((i) => i.value));
306
+ ask("");
307
+ if (!inBox)
308
+ input.current?.focus({ preventScroll: true });
309
+ };
310
+ const leads = (e) => (e?.kind === "item" && e.item.level ? e.item : undefined);
311
+ const take = (next, d) => {
312
+ const byKeys = d?.event instanceof KeyboardEvent;
313
+ if (Array.isArray(next)) {
314
+ const before = new Set(heldEntries.map((e) => e.key)), added = next.find((e) => !before.has(e.key));
315
+ const opens = leads(added);
316
+ if (opens) {
317
+ d?.cancel();
318
+ return openLevel(opens, byKeys);
319
+ }
320
+ if (added?.kind === "action")
321
+ return added.action.onSelect();
322
+ if (added?.kind === "create")
323
+ return onValueChange([...held, make(added.typed)]);
324
+ onValueChange(next.filter((e) => e.kind === "item").map((e) => e.item.value));
325
+ if (inBox)
326
+ ask("");
327
+ return;
328
+ }
329
+ if (!next) {
330
+ if (inBox)
331
+ onValueChange(null);
332
+ return;
333
+ }
334
+ const opens = leads(next);
335
+ if (opens) {
336
+ d?.cancel();
337
+ return openLevel(opens, byKeys);
338
+ }
339
+ if (next.kind === "action")
340
+ return next.action.onSelect();
341
+ if (next.kind === "item" && next.item.disabled)
342
+ return;
343
+ onValueChange(next.kind === "item" ? next.item.value : next.kind === "create" ? make(next.typed) : null);
344
+ onDone?.();
345
+ };
346
+ const keys = (e) => {
347
+ const a = actions.find((x) => x.keys?.length && pressed(x.keys, e));
348
+ if (a) {
349
+ e.preventDefault();
350
+ a.onSelect();
351
+ }
352
+ };
353
+ const guard = (e) => {
354
+ const row = litRow.current;
355
+ if (e.key !== "Enter" || !multiple || query.trim() || litByPerson.current || row?.kind !== "item" || !held.includes(row.item.value))
356
+ return;
357
+ e.preventDefault();
358
+ e.preventBaseUIHandler?.();
359
+ };
360
+ const lightRow = (row) => {
361
+ atRestNow.current = false;
362
+ setListLit(false);
363
+ litByPerson.current = true;
364
+ row.dispatchEvent(new MouseEvent("mousemove", { bubbles: true, movementX: 1, movementY: 1 }));
365
+ if (row.closest(".o-picker-rows"))
366
+ scrollInList(row, { block: "nearest" });
367
+ };
368
+ const optionRows = () => [...(root.current?.querySelectorAll('[role="option"]') ?? [])];
369
+ const run = React.useRef({ text: "", at: 0 });
370
+ const jump = (e) => {
371
+ if (shown || chips || e.key.length !== 1 || e.ctrlKey || e.metaKey || e.altKey)
372
+ return;
373
+ e.preventDefault();
374
+ e.preventBaseUIHandler?.();
375
+ const r = run.current, fresh = e.timeStamp - r.at > 750;
376
+ r.at = e.timeStamp;
377
+ if (e.key === " " && (fresh || !r.text)) {
378
+ r.text = "";
379
+ const box = e.currentTarget;
380
+ queueMicrotask(() => box.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true, cancelable: true })));
381
+ return;
382
+ }
383
+ r.text = fresh ? e.key : r.text + e.key;
384
+ const same = [...r.text].every((c) => c === r.text[0]), word = fold(same ? r.text[0] : r.text);
385
+ const rows = optionRows(), from = atRestNow.current ? 0 : same ? lit.current + 1 : Math.max(0, lit.current);
386
+ for (let k = 0; k < rows.length; k++) {
387
+ const row = rows[(from + k) % rows.length], name = row.dataset.name;
388
+ if (name != null && !row.hasAttribute("data-disabled") && fold(name).startsWith(word))
389
+ return lightRow(row);
390
+ }
391
+ r.text = "";
392
+ };
393
+ const menuKey = (e) => {
394
+ const row = litRow.current;
395
+ if (!(e.key === "ContextMenu" || (e.key === "F10" && e.shiftKey)) || row?.kind !== "item" || !row.item.menu?.length)
396
+ return false;
397
+ const dots = root.current?.querySelector('[role="option"][data-highlighted] .o-picker-row-menu');
398
+ if (!dots)
399
+ return false;
400
+ e.preventDefault();
401
+ e.preventBaseUIHandler?.();
402
+ setRowMenu({ value: row.item.value, anchor: dots });
403
+ return true;
404
+ };
405
+ const backKey = (e) => {
406
+ if (e.key !== "Backspace" || !level || e.currentTarget.value !== "")
407
+ return false;
408
+ e.preventDefault();
409
+ e.preventBaseUIHandler?.();
410
+ back(true);
411
+ return true;
412
+ };
413
+ const restKey = (e) => {
414
+ if (!atRestNow.current || e.altKey || e.metaKey || e.ctrlKey || e.shiftKey || !["Enter", "ArrowDown", "ArrowUp"].includes(e.key))
415
+ return false;
416
+ e.preventDefault();
417
+ e.preventBaseUIHandler?.();
418
+ if (e.key === "Enter")
419
+ return true;
420
+ const open = optionRows().filter((r) => !r.hasAttribute("data-disabled"));
421
+ if (open.length)
422
+ lightRow(e.key === "ArrowDown" ? open[0] : open[open.length - 1]);
423
+ return true;
424
+ };
425
+ const ends = (e) => {
426
+ if (backKey(e))
427
+ return;
428
+ if (restKey(e))
429
+ return;
430
+ if (menuKey(e))
431
+ return;
432
+ if (orderKey(e))
433
+ return;
434
+ guard(e);
435
+ jump(e);
436
+ if ((e.key !== "Home" && e.key !== "End") || e.shiftKey || e.metaKey || e.ctrlKey || e.altKey)
437
+ return;
438
+ e.preventDefault();
439
+ e.preventBaseUIHandler?.();
440
+ const open = optionRows().filter((r) => !r.hasAttribute("data-disabled"));
441
+ if (open.length)
442
+ lightRow(e.key === "Home" ? open[0] : open[open.length - 1]);
443
+ };
444
+ const searchBox = React.useCallback((el) => { input.current = el; focusesInPlace(el); }, []);
445
+ const answer = items.map((i) => i.value).join("\u0000");
446
+ React.useEffect(() => {
447
+ if (!server || form === "phone" || !find.trim() || doing)
448
+ return;
449
+ const rows = optionRows();
450
+ if (rows.some((r) => r.hasAttribute("data-highlighted")))
451
+ return;
452
+ const first = rows.find((r) => r.dataset.name != null && !r.hasAttribute("data-disabled"));
453
+ if (first)
454
+ lightRow(first);
455
+ }, [answer, doing]);
456
+ const openKey = openPath.map((i) => i.value).join("\u0000");
457
+ const openWas = React.useRef(openKey);
458
+ React.useLayoutEffect(() => { if (openWas.current === openKey)
459
+ return; openWas.current = openKey; if (typedNow.current)
460
+ ask(""); }, [openKey]);
461
+ React.useEffect(() => {
462
+ const want = lightAfter.current;
463
+ if (want === null)
464
+ return;
465
+ lightAfter.current = null;
466
+ if (form === "phone") {
467
+ const to = want ? [...(root.current?.querySelectorAll("[data-opens]") ?? [])].find((r) => r.dataset.name === want) : root.current?.querySelector("[data-parent]");
468
+ if (to)
469
+ scrollInList(to, { block: "nearest" });
470
+ return;
471
+ }
472
+ const frame = requestAnimationFrame(() => {
473
+ const open = optionRows().filter((r) => !r.hasAttribute("data-disabled"));
474
+ const to = want ? open.find((r) => r.hasAttribute("data-opens") && r.dataset.name === want) : open[0];
475
+ if (to)
476
+ lightRow(to);
477
+ });
478
+ return () => cancelAnimationFrame(frame);
479
+ }, [openKey]);
480
+ const row = (r, i, foot = false) => {
481
+ if (r.kind === "item") {
482
+ const withMenu = hasMenu(r.item), item = r.item;
483
+ const more = withMenu ? {
484
+ "data-menu-open": menuOpenFor(item.value) ? "" : undefined,
485
+ onContextMenu: (e) => { e.preventDefault(); lightRow(e.currentTarget); setRowMenu({ value: item.value, anchor: { x: e.clientX, y: e.clientY } }); },
486
+ } : {};
487
+ return (_jsx(BaseCombobox.Item, { ref: keepsToItsList, value: itemEntry(r.item), disabled: r.item.disabled, className: "o-list-row o-smooth o-smooth-ease", "data-first": firstOnes.has(r.item.value) ? "" : undefined, "data-held": held.includes(r.item.value) ? "" : undefined, "data-indent": r.indent ? "" : undefined, "data-opens": r.opens ? "" : undefined, "data-name": r.item.label, ...more, ...orderProps(item.value), children: _jsx(ItemBody, { item: r.item, multiple: multiple, worn: worn, count: r.opens ? r.count : undefined, lead: multiple && !chips && props.lead && held.includes(r.item.value) ? _jsx(LeadMark, { lead: props.lead, value: r.item.value }) : undefined, menu: withMenu ? rowTrigger(item) : undefined }) }, r.item.value));
488
+ }
489
+ if (r.kind === "parent")
490
+ return (_jsxs("div", { className: "o-list-row o-smooth o-smooth-ease o-picker-parent", "data-parent": "", "aria-hidden": "true", children: [_jsx(Face, { item: r.item }), _jsx("span", { className: "o-list-text", children: _jsx("span", { className: "o-list-main", children: _jsx(Name, { item: r.item }) }) })] }, "parent"));
491
+ if (r.kind === "empty")
492
+ return (_jsx(BaseCombobox.Item, { ref: keepsToItsList, value: { key: "empty", kind: "empty", label: r.label }, className: "o-list-row o-smooth o-smooth-ease o-list-clear o-picker-empty", "data-name": r.label, children: _jsx("span", { className: "o-list-text", children: _jsx("span", { className: "o-list-main", children: r.label }) }) }, "empty"));
493
+ if (r.kind === "create")
494
+ return (_jsxs(BaseCombobox.Item, { ref: foot ? staysInView : keepsToItsList, value: { key: "create", kind: "create", typed: r.typed }, className: cx("o-list-row o-smooth o-smooth-ease o-list-clear o-picker-create", worn.create === "apart" && "o-picker-create-apart"), children: [glyph(PLUS, "o-list-plus"), _jsx("span", { className: "o-list-text", children: _jsxs("span", { className: "o-list-main", children: ["Create \u201C", r.typed, "\u201D"] }) })] }, "create"));
495
+ return _jsx(React.Fragment, {}, i);
496
+ };
497
+ const action = (a, foot = false) => (_jsxs(BaseCombobox.Item, { ref: foot ? staysInView : keepsToItsList, value: { key: `action:${a.id}`, kind: "action", action: a }, className: "o-list-row o-smooth o-smooth-ease o-picker-action", children: [_jsx("span", { className: "o-picker-icon", children: a.icon }), _jsx("span", { className: "o-list-text", children: _jsx("span", { className: "o-list-main", children: a.label }) }), a.keys?.length ? _jsx(Kbd, { keys: a.keys }) : null] }, a.id));
498
+ const typed = find.trim();
499
+ const matches = rows.some((r) => r.kind === "item");
500
+ const message = doing === "searching" ? _jsxs("div", { className: "o-picker-message", children: [_jsx(Spinner, { size: 16, label: "" }), _jsx("span", { className: "o-picker-message-text", children: "Searching\u2026" })] })
501
+ : doing === "failed" ? _jsxs("div", { className: "o-picker-message", children: [_jsx("span", { className: "o-picker-message-text", children: "Couldn't search." }), onRetry && _jsx(Button, { kind: "text", size: "2xs", onClick: onRetry, children: "Try again" })] })
502
+ : typed && !matches ? _jsx("div", { className: "o-picker-message", children: _jsx("span", { className: "o-picker-message-text", children: noneWords ?? "Nothing matches." }) })
503
+ : none ? _jsx("div", { className: "o-picker-message", children: _jsx("span", { className: "o-picker-message-text", children: nothingYet.text }) })
504
+ : server && !typed && !items.length ? _jsx("div", { className: "o-picker-message", children: _jsx("span", { className: "o-picker-message-text", children: "Type to look one up." }) })
505
+ : null;
506
+ const first = none ? { id: "first", label: nothingYet.action, icon: glyph(PLUS), onSelect: nothingYet.onAction } : null;
507
+ const [rowMenu, setMenuAt] = React.useState(null);
508
+ const setRowMenu = (at) => setMenuAt({ ...at, open: true });
509
+ const menuOpenFor = (value) => !!rowMenu?.open && rowMenu.value === value;
510
+ const stopKeys = (e) => { if (e.key === "Enter" || e.key === " ")
511
+ e.stopPropagation(); };
512
+ const rowTrigger = (item) => {
513
+ const open = (e) => { e.stopPropagation(); setRowMenu({ value: item.value, anchor: e.currentTarget }); };
514
+ return form === "phone"
515
+ ? _jsx(MenuDots, { label: `Actions for ${item.label}`, className: "o-picker-row-menu", onClick: open, onKeyDown: stopKeys })
516
+ : _jsx(Button, { kind: "quiet", shape: "icon", size: "20", tabIndex: -1, className: "o-picker-row-menu", "data-shown": props.rowMenus ?? "always", "aria-label": `Actions for ${item.label}`, icon: glyph(DOTS_V), onClick: open, onKeyDown: stopKeys });
517
+ };
518
+ const hasMenu = (item) => !!item.menu?.length;
519
+ const menuItem = rowMenu ? itemOf(rowMenu.value) : undefined;
520
+ const rowMenuEl = items.some(hasMenu)
521
+ ? _jsx(Menu, { label: menuItem?.label ?? label, entries: menuItem?.menu ?? [], anchor: rowMenu?.anchor ?? null, align: rowMenu?.anchor instanceof HTMLElement ? "end" : "start", open: !!rowMenu?.open, onOpenChange: (o) => { if (!o)
522
+ setMenuAt((m) => m && { ...m, open: false }); }, frame: props.menuFrame })
523
+ : null;
524
+ const ordering = !!props.onOrderChange && !find.trim() && !level;
525
+ const keptNow = multiple && own ? draft : held;
526
+ const orderBlocks = !ordering ? []
527
+ : form === "phone" ? (props.heldInPlace ? phoneGroups(items).map((g) => g.items.map((i) => i.value)) : [items.filter((i) => !keptNow.includes(i.value)).map((i) => i.value)])
528
+ : grouped(rows, worn.create === "apart").map((g) => g.rows.flatMap((r) => (r.kind === "item" ? [r.item.value] : []))).filter((b) => b.length);
529
+ const placeOf = new Map(orderBlocks.flatMap((b, bi) => b.map((v, at) => [v, { block: bi, at }])));
530
+ const [heldBlock, setHeldBlock] = React.useState(0);
531
+ const press = React.useRef(null);
532
+ const [carried, setCarried] = React.useState(false);
533
+ const toOrder = (value, target) => { if (value !== target)
534
+ props.onOrderChange?.(orderMoved(items, value, target)); };
535
+ const { gripProps, lift, dragging } = useReorder({ count: orderBlocks[heldBlock]?.length ?? 0, grip: "[data-row]",
536
+ onMove: (_from, to) => { const p = press.current, target = orderBlocks[heldBlock]?.[to]; if (p && target)
537
+ toOrder(p.value, target); } });
538
+ const holdDrag = useHoldDrag(root, gripProps, HOLD, ordering && form === "phone" && !!placed);
539
+ const onControl = (e) => !!e.target.closest("button");
540
+ const forgetSoon = () => { const q = press.current; window.setTimeout(() => { if (press.current === q)
541
+ press.current = null; }); };
542
+ const isDragging = dragging !== null, wasDragging = React.useRef(false);
543
+ React.useEffect(() => {
544
+ if (isDragging) {
545
+ wasDragging.current = true;
546
+ return;
547
+ }
548
+ if (!wasDragging.current)
549
+ return;
550
+ wasDragging.current = false;
551
+ setCarried(false);
552
+ forgetSoon();
553
+ }, [isDragging]);
554
+ const orderProps = (value) => {
555
+ const p = placeOf.get(value);
556
+ if (!p)
557
+ return {};
558
+ const mine = p.block === heldBlock && dragging === p.at;
559
+ const at = { "data-row": p.at, style: p.block === heldBlock ? lift(p.at) : undefined };
560
+ if (form === "phone") {
561
+ const h = holdDrag(p.at);
562
+ return { ...at, ...h, "data-lifted": mine ? "" : undefined,
563
+ onPointerDown: (e) => { if (onControl(e))
564
+ return; press.current = { value, y: e.clientY, carried: false, id: e.pointerId }; setHeldBlock(p.block); h.onPointerDown(e); },
565
+ onClickCapture: (e) => { if (!e.target.closest("button"))
566
+ h.onClickCapture(e); } };
567
+ }
568
+ const g = gripProps(p.at);
569
+ return { ...at, "data-lifted": mine && carried ? "" : undefined,
570
+ onPointerDown: (e) => { if (e.button !== 0 || onControl(e))
571
+ return; press.current = { value, y: e.clientY, carried: false, id: e.pointerId }; setHeldBlock(p.block); g.onPointerDown(e); },
572
+ onPointerMove: (e) => {
573
+ const q = press.current;
574
+ if (isDragging && e.pointerType === "mouse" && e.buttons === 0) {
575
+ g.onPointerUp();
576
+ return;
577
+ }
578
+ if (q && !q.carried && Math.abs(e.clientY - q.y) > spacingPx(2, e.currentTarget)) {
579
+ q.carried = true;
580
+ setCarried(true);
581
+ }
582
+ g.onPointerMove(e);
583
+ },
584
+ onPointerUp: g.onPointerUp, onPointerCancel: g.onPointerCancel,
585
+ onClick: (e) => {
586
+ if (press.current?.carried) {
587
+ e.preventBaseUIHandler?.();
588
+ e.preventDefault();
589
+ e.stopPropagation();
590
+ }
591
+ press.current = null;
592
+ },
593
+ };
594
+ };
595
+ const relight = React.useRef(null);
596
+ const orderKey = (e) => {
597
+ if (!ordering || !e.altKey || (e.key !== "ArrowUp" && e.key !== "ArrowDown"))
598
+ return false;
599
+ const row = litRow.current, p = row?.kind === "item" ? placeOf.get(row.item.value) : undefined;
600
+ if (!row || row.kind !== "item" || !p)
601
+ return false;
602
+ e.preventDefault();
603
+ e.preventBaseUIHandler?.();
604
+ const target = orderBlocks[p.block][p.at + (e.key === "ArrowUp" ? -1 : 1)];
605
+ if (target) {
606
+ relight.current = row.item.label;
607
+ toOrder(row.item.value, target);
608
+ }
609
+ return true;
610
+ };
611
+ const orderNow = items.map((i) => i.value).join("\u0000");
612
+ React.useLayoutEffect(() => {
613
+ const name = relight.current;
614
+ if (name == null)
615
+ return;
616
+ relight.current = null;
617
+ const frame = requestAnimationFrame(() => { const to = optionRows().find((r) => r.dataset.name === name); if (to)
618
+ lightRow(to); });
619
+ return () => cancelAnimationFrame(frame);
620
+ }, [orderNow]);
621
+ if (form === "phone")
622
+ return phoneParts();
623
+ function phoneParts() {
624
+ const changing = !!multiple, boxes = changing && worn.mark === "check";
625
+ const fixed = !multiple && empty === undefined;
626
+ const kept = changing && own ? draft : held;
627
+ const inPlace = !!props.heldInPlace, isKept = (v) => !inPlace && kept.includes(v);
628
+ const keptItems = inPlace ? [] : kept.map(itemOf);
629
+ const listRows = doing ? [] : pickerRows({ items: items.filter((i) => !isKept(i.value)), query, picked: [], create: false, server, more: false, open: level ? openPath : undefined, levelRow: !byHolder });
630
+ const parent = listRows[0]?.kind === "parent" ? listRows[0] : undefined;
631
+ const rest = listRows.filter((r) => r.kind === "item" && !isKept(r.item.value));
632
+ const creatable = create && !!typed && !exactMatch(level?.level ?? items, query);
633
+ const leave = () => { setDraft(holdingNow.current); ask(""); onDone?.(); };
634
+ const createTyped = () => {
635
+ const v = make(typed);
636
+ if (changing && own)
637
+ setDraft([...draft, v]);
638
+ else if (changing)
639
+ onValueChange([...held, v]);
640
+ else {
641
+ onValueChange(v);
642
+ onDone?.();
643
+ }
644
+ };
645
+ const tap = (next, d) => {
646
+ if (Array.isArray(next)) {
647
+ const opening = next.map(leads).find(Boolean);
648
+ if (opening) {
649
+ d?.cancel();
650
+ return openLevel(opening);
651
+ }
652
+ const list = next.filter((e) => e.kind === "item").map((e) => e.item.value);
653
+ if (readOnly)
654
+ return;
655
+ return own ? setDraft(list) : onValueChange(list);
656
+ }
657
+ if (!next) {
658
+ if (inPlace && !changing)
659
+ onDone?.();
660
+ return;
661
+ }
662
+ const opening = leads(next);
663
+ if (opening) {
664
+ d?.cancel();
665
+ return openLevel(opening);
666
+ }
667
+ if (next.kind === "unpick") {
668
+ if (!fixed) {
669
+ onValueChange(null);
670
+ onDone?.();
671
+ }
672
+ else if (inPlace)
673
+ onDone?.();
674
+ return;
675
+ }
676
+ if (next.kind === "item" && !next.item.disabled) {
677
+ onValueChange(next.item.value);
678
+ onDone?.();
679
+ }
680
+ };
681
+ const label_ = changing ? `Selected · ${kept.length}` : fixed ? "Selected · can't be empty" : "Selected";
682
+ const note = doing === "searching" ? _jsxs("div", { className: "o-picker-note", children: [_jsx(Spinner, { size: 20, label: "" }), "Searching\u2026"] })
683
+ : doing === "failed" ? _jsxs("div", { className: "o-picker-note", children: [_jsxs("span", { children: [_jsx("b", { children: "Couldn't search." }), _jsx("br", {}), "Check the connection and try again."] }), onRetry && _jsx(Button, { kind: "soft", size: "lg", icon: glyph(REFRESH), onClick: onRetry, children: "Try again" })] })
684
+ : typed && !rest.length ? _jsx("div", { className: "o-picker-note", children: noneWords ?? _jsxs(_Fragment, { children: ["Nothing matches \u201C", typed, "\u201D."] }) })
685
+ : null;
686
+ const pill = props.searchShown ?? (worn.search === "always" || searchShown({ count: items.length, create, server, query }));
687
+ const at = (i, matching) => (typed ? (matching ? i : rest.length + i) : (matching ? keptItems.length + i : i));
688
+ const enter = (e) => {
689
+ if (e.key !== "Enter" || !typed || rest.length)
690
+ return;
691
+ e.preventDefault();
692
+ e.preventBaseUIHandler?.();
693
+ };
694
+ const under = !!props.actionsUnder && !none;
695
+ const menu = under ? [] : actions.map((a) => ({ icon: a.icon, label: a.label, onSelect: a.onSelect }));
696
+ const underActions = under && !typed && actions.length > 0 && (_jsx("div", { className: "o-picker-under", children: actions.map((a) => _jsx(Button, { kind: "outline", size: "44", icon: a.icon, onClick: a.onSelect, children: a.label }, a.id)) }));
697
+ const showBar = !none && (pill || creatable || menu.length > 0 || (!!level && !byHolder));
698
+ const bar = showBar && (_jsxs("div", { className: "o-picker-bar", children: [level && !byHolder && _jsx(GlassButton, { "aria-label": `Back to ${level.label}`, icon: glyph(BACK), className: "o-picker-round", "data-back": "", onMouseDown: (e) => e.preventDefault(), onClick: () => back() }), pill && (_jsxs(InputGroup, { size: "lg", className: "o-picker-pill", ...pillTap, children: [_jsx(InputGroupAddon, { side: "start", children: glyph(SEARCH) }), _jsx(Input, { combobox: true, autofill: false, ref: pillInput, placeholder: search, "aria-label": search ?? label, onKeyDown: (e) => { if (!backKey(e))
699
+ enter(e); } })] })), creatable ? _jsx(Button, { kind: "primary", size: "lg", icon: glyph(PLUS), className: "o-picker-create-button", onClick: createTyped, children: "Create" })
700
+ : menu.length > 0 && _jsx(Menu, { label: label, entries: menu, trigger: _jsx(GlassButton, { "aria-label": "Actions", icon: glyph(DOTS), className: "o-picker-round" }) })] }));
701
+ const menuOpen = (item) => (menuOpenFor(item.value) ? { "data-menu-open": "" } : {});
702
+ const heldHere = (v) => inPlace && kept.includes(v);
703
+ const rowValue = (item) => (heldHere(item.value) && !changing ? { key: `unpick:${item.value}`, kind: "unpick", item } : itemEntry(item));
704
+ const circleOf = (v) => (changing ? (heldHere(v) ? "on" : "off") : heldHere(v) ? "on" : null);
705
+ const rowOf = (r, i) => _jsx(BaseCombobox.Item, { ref: keepsToItsList, index: at(i, true), value: rowValue(r.item), disabled: r.item.disabled, className: "o-picker-row", "data-indent": r.indent ? "" : undefined, "data-opens": r.opens ? "" : undefined, "data-name": r.item.label, ...menuOpen(r.item), ...orderProps(r.item.value), children: _jsx(PhoneRow, { item: r.item, kind: worn.kind, circle: circleOf(r.item.value), box: boxes, count: r.opens ? r.count : undefined, menu: hasMenu(r.item) ? rowTrigger(r.item) : undefined }) }, r.item.value);
706
+ const listed = rest.map(rowOf);
707
+ const headed = inPlace && !parent && !typed && rest.some((r) => r.item.group);
708
+ const cards = headed ? (() => {
709
+ let k = 0;
710
+ return phoneGroups(rest.map((r) => r.item)).map((g) => {
711
+ const rows = g.items.map(() => { const r = rest[k]; return rowOf(r, k++); });
712
+ return (_jsxs(BaseCombobox.Group, { className: "o-picker-group", children: [g.name && _jsx(BaseCombobox.GroupLabel, { className: "o-picker-label", children: g.name }), _jsx("div", { className: "o-picker-card o-picker-list", "data-heading": g.name || undefined, children: rows })] }, g.name || "-"));
713
+ });
714
+ })() : null;
715
+ const body = (_jsxs(BaseCombobox.Root, { inline: true, open: true, multiple: changing, value: (changing ? kept.map((v) => itemEntry(itemOf(v))) : held[0] != null ? { key: `unpick:${held[0]}`, kind: "unpick", item: itemOf(held[0]) } : null), onValueChange: (v, d) => tap(v, d), inputValue: query, onInputValueChange: ask, autoHighlight: true, itemToStringValue: (e) => e.key, itemToStringLabel: (e) => entryLabel(e), isItemEqualToValue: (a, b) => a.key === b.key, children: [_jsxs("div", { ref: placeRoot, className: "o-picker", "data-kit": "picker", "data-picker-form": "phone", "data-typed": typed ? "" : undefined, style: room ? { "--picker-room": `${room.height}px`, "--picker-under": `${room.under}px` } : undefined, children: [none ? (_jsxs("div", { className: "o-picker-note o-picker-first", children: [_jsxs("span", { children: [_jsx("b", { children: nothingYet.text }), nothingYet.line && _jsxs(_Fragment, { children: [_jsx("br", {}), nothingYet.line] })] }), _jsx(Button, { kind: "primary", size: "lg", icon: glyph(PLUS), onClick: nothingYet.onAction, children: nothingYet.action })] })) : (_jsxs(_Fragment, { children: [_jsxs(BaseCombobox.List, { className: "o-picker-phone", "aria-label": label, children: [keptItems.length > 0 && (_jsxs(BaseCombobox.Group, { className: "o-picker-group", children: [_jsx(BaseCombobox.GroupLabel, { className: "o-picker-label", children: label_ }), _jsx("div", { className: "o-picker-card o-picker-selected", children: keptItems.map((item, i) => (_jsx(BaseCombobox.Item, { ref: keepsToItsList, index: at(i, false), value: changing ? itemEntry(item) : { key: `unpick:${item.value}`, kind: "unpick", item }, className: "o-picker-row", ...menuOpen(item), children: _jsx(PhoneRow, { item: item, kind: worn.kind, circle: fixed ? "fixed" : "on", box: boxes, lead: changing && !own && props.lead ? _jsx(LeadMark, { lead: props.lead, value: item.value }) : undefined, menu: hasMenu(item) ? rowTrigger(item) : undefined }) }, item.value))) })] })), headed && !note && cards, !headed && (parent || (!note && rest.length > 0)) && (_jsxs("div", { className: "o-picker-card o-picker-list", children: [parent && _jsx("div", { className: "o-picker-row o-picker-parent", "data-parent": "", "aria-hidden": "true", children: _jsx(PhoneRow, { item: parent.item, kind: worn.kind, circle: null }) }), !note && rest.length > 0 && (parent ? _jsx("div", { className: "o-picker-level", children: listed }) : listed)] }))] }), note, underActions, onMore && !doing && _jsxs("div", { ref: more, className: "o-picker-more", children: [_jsx(Spinner, { size: 16, label: "" }), "Loading more\u2026"] })] })), bar] }), rowMenuEl] }));
716
+ const head = changing && own ? { left: _jsx(SheetButton, { onClick: leave, children: "Cancel" }), right: _jsx(SheetButton, { kind: "primary", "aria-label": "Save", icon: glyph(TICK), onClick: () => { onValueChange(draft); ask(""); onDone?.(); } }) }
717
+ : {};
718
+ return { body, head, step: changing && own ? "change" : null };
719
+ }
720
+ const footCreate = worn.create === "apart" ? rows.find((r) => r.kind === "create") : undefined;
721
+ const actionsShown = actions.length > 0 && !none && (!own || !(typed && !rows.some((r) => r.kind === "item" || r.kind === "create")));
722
+ const parent = rows[0]?.kind === "parent" ? rows[0] : undefined;
723
+ const groups = grouped((parent ? rows.slice(1) : rows).filter((r) => r !== footCreate), worn.create === "apart").map((g, gi) => {
724
+ const line = g.line && _jsx(BaseCombobox.Separator, { className: "o-list-sep" });
725
+ return g.heading
726
+ ? _jsxs(BaseCombobox.Group, { children: [line, _jsx(BaseCombobox.GroupLabel, { className: "o-list-heading", children: g.heading }), g.rows.map((r, i) => row(r, i))] }, `g${gi}`)
727
+ : _jsxs(React.Fragment, { children: [line, g.rows.map((r, i) => row(r, i))] }, `g${gi}`);
728
+ });
729
+ const soft = props.searchLook === "soft" && !chips;
730
+ const backButton = level && !byHolder && _jsx(Button, { kind: "quiet", shape: "icon", size: "2xs", className: "o-picker-back", "aria-label": `Back to ${level.label}`, icon: glyph(BACK), onMouseDown: (e) => e.preventDefault(), onClick: (e) => back(e.detail === 0), children: null });
731
+ const list = (_jsxs("div", { ref: under ? placeRoot : root, className: "o-picker o-smooth o-smooth-ease", "data-kit": "picker", "data-picker-form": form, "data-standing": props.standing ? "" : undefined, "data-rest": atRest ? "" : undefined, onKeyDown: keys, children: [inBox && level && _jsx("div", { className: "o-picker-search o-popup-line", children: backButton }), !inBox && soft && (_jsx("div", { className: cx("o-picker-search o-picker-search-soft", !shown && "sr-only"), "data-hidden": shown ? undefined : "", children: _jsxs(InputGroup, { size: "sm", chrome: "soft", children: [_jsx(InputGroupAddon, { children: backButton || glyph(SEARCH) }), _jsx(Input, { combobox: true, autofill: false, ref: searchBox, className: "o-picker-input", placeholder: search, "aria-label": search ?? label, onKeyDown: ends, ...restAttrs })] }) })), !inBox && !soft && (_jsxs("div", { className: cx("o-picker-search o-popup-line", !shown && !chips && "sr-only"), "data-hidden": shown || chips ? undefined : "", children: [backButton || glyph(SEARCH), chips ? (_jsxs(BaseCombobox.Chips, { className: "o-picker-chips", onMouseDown: (e) => { if (e.target.closest(".o-tag-remove")) {
732
+ e.preventDefault();
733
+ input.current?.focus();
734
+ } }, children: [heldEntries.map((e) => _jsx(BaseCombobox.Chip, { render: _jsx(Option, { onRemove: () => onValueChange(held.filter((v) => `item:${v}` !== e.key)) }), children: entryLabel(e) }, e.key)), _jsx(Input, { combobox: true, chrome: "bare", autofill: false, ref: searchBox, className: "o-picker-input", placeholder: held.length ? undefined : search, "aria-label": search ?? label, onKeyDown: ends, ...restAttrs })] })) : _jsx(Input, { combobox: true, chrome: "bare", autofill: false, ref: searchBox, className: "o-picker-input", placeholder: search, "aria-label": search ?? label, onKeyDown: ends, ...restAttrs })] })), multiple && worn.picked === "count" && held.length > 0 && _jsxs("div", { className: "o-picker-count", children: [_jsxs("span", { children: [held.length, " chosen"] }), _jsx(Button, { ref: focusesInPlace, kind: "text", size: "2xs", onClick: () => onValueChange([]), children: "Clear all" })] }), message, _jsxs(BaseCombobox.List, { className: "o-picker-listbox", "aria-label": label, children: [_jsxs("div", { className: "o-picker-rows", children: [parent ? _jsxs(_Fragment, { children: [row(parent, -1), _jsx("div", { className: "o-picker-level", children: groups })] }) : groups, rows.some((r) => r.kind === "more") && _jsxs("div", { ref: more, className: "o-picker-more", children: [_jsx(Spinner, { size: 14, label: "" }), "Loading more\u2026"] }), first && action(first)] }), _jsx(Scrollbar, {}), (footCreate || actionsShown) && (_jsxs("div", { className: "o-picker-foot o-popup-line", "data-at": "foot", children: [footCreate && row(footCreate, -1, true), actionsShown && (_jsxs(BaseCombobox.Group, { children: [worn.heading === "shown" && _jsx(BaseCombobox.GroupLabel, { className: "o-list-heading", children: "Actions" }), actions.map((a) => action(a, true))] }))] }))] })] }));
735
+ const value_ = (multiple ? heldEntries : heldEntries[0] ?? null);
736
+ const highlighted = (v, d) => {
737
+ lit.current = d.index;
738
+ litRow.current = v;
739
+ litByPerson.current = d.reason !== "none";
740
+ const byList = d.index >= 0 && d.reason === "none" && !keyedOpen.current;
741
+ if (d.index >= 0)
742
+ keyedOpen.current = false;
743
+ setListLit(byList);
744
+ };
745
+ const body = under ? (_jsxs(BaseCombobox.Root, { open: under.open, onOpenChange: (o, d) => {
746
+ if (!o && d.reason === "item-press" && litRow.current?.kind === "action") {
747
+ d.cancel();
748
+ return;
749
+ }
750
+ if (o)
751
+ setAhead(heldNow.current);
752
+ if (o)
753
+ keyedOpen.current = d.event instanceof KeyboardEvent;
754
+ if (o)
755
+ startOver();
756
+ if (o && !inBox && typedNow.current !== opening.current) {
757
+ setQuery(opening.current);
758
+ askServer.current?.(opening.current);
759
+ }
760
+ under.onOpenChange(o);
761
+ }, modal: true, disabled: under.disabled, multiple: multiple, value: value_, onValueChange: (v, d) => {
762
+ if (d.reason !== "escape-key")
763
+ take(v, d);
764
+ }, inputValue: query, onInputValueChange: (q, d) => (d.reason === "escape-key" && heldName ? setQuery(heldName) : ask(q)), autoHighlight: true, onItemHighlighted: highlighted, itemToStringValue: (e) => e.key, itemToStringLabel: (e) => entryLabel(e), isItemEqualToValue: (a, b) => a.key === b.key, children: [typeof under.box === "function" ? under.box({ onKeyDown: (e) => { if (!backKey(e) && !restKey(e) && !menuKey(e) && !orderKey(e))
765
+ guard(e); }, typed: query, attrs: restAttrs }) : under.box, under.panel(list), _jsx("span", { ref: mark, hidden: true }), rowMenuEl] })) : (_jsxs(BaseCombobox.Root, { inline: true, open: true, multiple: multiple, value: value_, onValueChange: (v, d) => take(v, d), inputValue: query, onInputValueChange: ask, autoHighlight: true, onItemHighlighted: highlighted, itemToStringValue: (e) => e.key, itemToStringLabel: (e) => entryLabel(e), isItemEqualToValue: (a, b) => a.key === b.key, children: [list, rowMenuEl] }));
766
+ return { body, head: {}, step: null };
767
+ }
768
+ export function Picker(props) {
769
+ return _jsx(_Fragment, { children: usePicker(props).body });
770
+ }
771
+ export function PickerUnder({ open, onOpenChange, box, panel, disabled, searchIn, ...props }) {
772
+ return _jsx(_Fragment, { children: usePickerAt({ ...props, form: "computer" }, { open, onOpenChange, box, panel, disabled, searchIn }).body });
773
+ }