@peers-app/peers-ui 0.34.13 → 0.34.15

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 (126) hide show
  1. package/dist/apps-home/app-menu.d.ts +1 -2
  2. package/dist/apps-home/app-menu.js +29 -25
  3. package/dist/command-palette/command-palette-ui.js +13 -12
  4. package/dist/components/autocomplete-chips.d.ts +18 -0
  5. package/dist/components/autocomplete-chips.js +49 -0
  6. package/dist/components/autocomplete.d.ts +88 -0
  7. package/dist/components/autocomplete.js +346 -0
  8. package/dist/components/confirm-button.d.ts +26 -0
  9. package/dist/components/confirm-button.js +55 -0
  10. package/dist/components/data-grid/autocomplete.d.ts +1 -31
  11. package/dist/components/data-grid/autocomplete.js +5 -197
  12. package/dist/components/empty-state.d.ts +16 -0
  13. package/dist/components/empty-state.js +16 -0
  14. package/dist/components/group-switcher.d.ts +3 -3
  15. package/dist/components/group-switcher.js +22 -17
  16. package/dist/components/inline-create-form.d.ts +22 -0
  17. package/dist/components/inline-create-form.js +56 -0
  18. package/dist/components/list-row.d.ts +33 -0
  19. package/dist/components/list-row.js +30 -0
  20. package/dist/components/list-screen.d.ts +31 -3
  21. package/dist/components/list-screen.js +61 -28
  22. package/dist/components/markdown-editor/format-bar.js +15 -40
  23. package/dist/components/markdown-editor/link-plugin.js +38 -9
  24. package/dist/components/markdown-editor/selection-bar-place.d.ts +37 -0
  25. package/dist/components/markdown-editor/selection-bar-place.js +107 -0
  26. package/dist/components/menu-button.d.ts +34 -0
  27. package/dist/components/menu-button.js +66 -0
  28. package/dist/components/screen-header.d.ts +35 -0
  29. package/dist/components/screen-header.js +30 -0
  30. package/dist/components/search-field.d.ts +22 -0
  31. package/dist/components/search-field.js +22 -0
  32. package/dist/components/segmented-control.d.ts +25 -0
  33. package/dist/components/segmented-control.js +18 -0
  34. package/dist/components/typeahead.d.ts +9 -0
  35. package/dist/components/typeahead.js +7 -0
  36. package/dist/delegates/acts-for-you-panel.d.ts +2 -1
  37. package/dist/delegates/acts-for-you-panel.js +46 -17
  38. package/dist/delegates/delegate-request-dialog.d.ts +3 -1
  39. package/dist/delegates/delegate-request-dialog.js +6 -3
  40. package/dist/groups/groups-client.d.ts +23 -1
  41. package/dist/groups/groups-client.js +31 -0
  42. package/dist/index.d.ts +10 -0
  43. package/dist/index.js +14 -1
  44. package/dist/isolated-screens/config.js +1 -9
  45. package/dist/isolated-screens/folder-picker-control.d.ts +57 -0
  46. package/dist/isolated-screens/folder-picker-control.js +217 -0
  47. package/dist/isolated-screens/folder-picker-host.d.ts +57 -0
  48. package/dist/isolated-screens/folder-picker-host.js +178 -0
  49. package/dist/isolated-screens/folder-picker-protocol.d.ts +75 -0
  50. package/dist/isolated-screens/folder-picker-protocol.js +104 -0
  51. package/dist/isolated-screens/frame-bridge.js +8 -0
  52. package/dist/isolated-screens/frame-document.js +2 -1
  53. package/dist/isolated-screens/frame-microphone.d.ts +55 -0
  54. package/dist/isolated-screens/frame-microphone.js +265 -0
  55. package/dist/isolated-screens/frame-permissions.d.ts +19 -0
  56. package/dist/isolated-screens/frame-permissions.js +32 -0
  57. package/dist/isolated-screens/frame-protocol.d.ts +26 -0
  58. package/dist/isolated-screens/frame-protocol.js +9 -0
  59. package/dist/isolated-screens/frame-pvars.d.ts +27 -0
  60. package/dist/isolated-screens/frame-pvars.js +101 -14
  61. package/dist/isolated-screens/global-widgets.d.ts +1 -2
  62. package/dist/isolated-screens/index.d.ts +2 -0
  63. package/dist/isolated-screens/index.js +3 -1
  64. package/dist/isolated-screens/isolated-screen.d.ts +21 -0
  65. package/dist/isolated-screens/isolated-screen.js +88 -5
  66. package/dist/isolated-screens/local-folder-picker.d.ts +55 -0
  67. package/dist/isolated-screens/local-folder-picker.js +143 -0
  68. package/dist/isolated-screens/microphone-host.d.ts +110 -0
  69. package/dist/isolated-screens/microphone-host.js +397 -0
  70. package/dist/isolated-screens/microphone-prompt.d.ts +20 -0
  71. package/dist/isolated-screens/microphone-prompt.js +60 -0
  72. package/dist/isolated-screens/piece-frames.js +5 -94
  73. package/dist/isolated-screens/piece-reach.d.ts +1 -0
  74. package/dist/isolated-screens/port-channel.d.ts +21 -11
  75. package/dist/isolated-screens/port-channel.js +15 -5
  76. package/dist/isolated-screens/slot-rect.d.ts +38 -0
  77. package/dist/isolated-screens/slot-rect.js +121 -0
  78. package/dist/isolated-screens/test-ports.d.ts +17 -0
  79. package/dist/isolated-screens/test-ports.js +25 -3
  80. package/dist/mentions/mention-chooser.js +1 -1
  81. package/dist/notifications/notifications-screen.js +1 -1
  82. package/dist/screens/data-explorer/data-explorer.d.ts +1 -0
  83. package/dist/screens/data-explorer/data-explorer.js +28 -10
  84. package/dist/screens/data-explorer/query-executor.d.ts +1 -0
  85. package/dist/screens/data-explorer/query-executor.js +3 -1
  86. package/dist/screens/groups/group-list.d.ts +13 -3
  87. package/dist/screens/groups/group-list.js +88 -11
  88. package/dist/screens/identity/identity-routes.d.ts +16 -0
  89. package/dist/screens/identity/identity-routes.js +27 -10
  90. package/dist/screens/identity/identity-screen.js +4 -1
  91. package/dist/screens/invites/activity-view.d.ts +3 -1
  92. package/dist/screens/invites/activity-view.js +7 -3
  93. package/dist/screens/invites/pending-invites-list.d.ts +8 -4
  94. package/dist/screens/invites/pending-invites-list.js +44 -45
  95. package/dist/screens/network-viewer/graph/network-graph-controls.js +3 -3
  96. package/dist/screens/packages/local-folder-grants-panel.d.ts +2 -0
  97. package/dist/screens/packages/local-folder-grants-panel.js +1 -1
  98. package/dist/screens/packages/package-info.js +2 -1
  99. package/dist/screens/packages/package-list.d.ts +2 -2
  100. package/dist/screens/packages/package-list.js +89 -105
  101. package/dist/screens/packages/package-microphone-panel.d.ts +14 -0
  102. package/dist/screens/packages/package-microphone-panel.js +62 -0
  103. package/dist/screens/packages/package-runtime-status.d.ts +10 -2
  104. package/dist/screens/packages/package-runtime-status.js +17 -4
  105. package/dist/screens/peer-types/peer-type-details.js +3 -2
  106. package/dist/screens/peer-types/peer-type-list.d.ts +1 -1
  107. package/dist/screens/peer-types/peer-type-list.js +4 -4
  108. package/dist/screens/settings/settings-page.js +1 -4
  109. package/dist/screens/tools/tool-details.js +2 -1
  110. package/dist/screens/tools/tool-list.d.ts +1 -1
  111. package/dist/screens/tools/tool-list.js +22 -60
  112. package/dist/screens/variables/variable-details.js +5 -4
  113. package/dist/screens/variables/variable-list.d.ts +17 -0
  114. package/dist/screens/variables/variable-list.js +72 -28
  115. package/dist/tabs-layout/network-status-details.d.ts +4 -4
  116. package/dist/tabs-layout/network-status-details.js +6 -5
  117. package/dist/tabs-layout/network-status-indicator.d.ts +1 -0
  118. package/dist/tabs-layout/network-status-indicator.js +1 -0
  119. package/dist/tabs-layout/tab-bar-shortcuts.d.ts +46 -0
  120. package/dist/tabs-layout/tab-bar-shortcuts.js +140 -0
  121. package/dist/tabs-layout/tabs-layout.js +11 -9
  122. package/dist/theme.css +326 -6
  123. package/dist/ui-contracts/popover-surface.d.ts +3 -0
  124. package/dist/ui-contracts/popover-surface.js +6 -3
  125. package/dist/ui-defaults/list-screen.js +10 -4
  126. package/package.json +3 -3
@@ -0,0 +1,346 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HighlightMatch = HighlightMatch;
4
+ exports.Autocomplete = Autocomplete;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const react_1 = require("react");
7
+ const react_dom_1 = require("react-dom");
8
+ const reactive_1 = require("./data-grid/reactive");
9
+ const emptyOptions = [];
10
+ // Bootstrap button states remain available without drawing separate button boxes.
11
+ const indicatorStyle = {
12
+ width: "2rem",
13
+ height: "100%",
14
+ padding: 0,
15
+ border: 0,
16
+ "--bs-btn-color": "var(--bs-tertiary-color)",
17
+ "--bs-btn-hover-color": "var(--bs-secondary-color)",
18
+ "--bs-btn-active-color": "var(--bs-body-color)",
19
+ "--bs-btn-disabled-color": "var(--bs-tertiary-color)",
20
+ "--bs-btn-bg": "transparent",
21
+ "--bs-btn-hover-bg": "transparent",
22
+ "--bs-btn-active-bg": "transparent",
23
+ "--bs-btn-disabled-bg": "transparent",
24
+ };
25
+ /** Escapes a string for use inside a regular expression. */
26
+ function escapeRegExp(text) {
27
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
28
+ }
29
+ /**
30
+ * Text with the words of `query` in bold, as autocomplete rows show what matched. Matching
31
+ * ignores case; an empty query leaves the text as it is.
32
+ */
33
+ function HighlightMatch(props) {
34
+ // Longer words first, so typing "job jobs" bolds all of "jobs", not just its "job".
35
+ const words = props.query
36
+ .trim()
37
+ .split(/\s+/)
38
+ .filter(Boolean)
39
+ .sort((a, b) => b.length - a.length)
40
+ .map(escapeRegExp);
41
+ if (!words.length)
42
+ return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: props.text });
43
+ const parts = props.text.split(new RegExp(`(${words.join("|")})`, "gi"));
44
+ return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: parts.map((part, index) => index % 2 === 1 ? (
45
+ // biome-ignore lint/suspicious/noArrayIndexKey: the parts of one string never reorder
46
+ (0, jsx_runtime_1.jsx)("mark", { className: "peers-match", children: part }, index)) : (
47
+ // biome-ignore lint/suspicious/noArrayIndexKey: the parts of one string never reorder
48
+ (0, jsx_runtime_1.jsx)(react_1.Fragment, { children: part }, index))) }));
49
+ }
50
+ /** Orders choices by section, sections in the order their first choice comes. */
51
+ function bySection(rows, sectionOf) {
52
+ const headings = new Map();
53
+ if (!sectionOf)
54
+ return { rows, headings };
55
+ const groups = new Map();
56
+ for (const row of rows) {
57
+ const section = sectionOf(row) ?? "";
58
+ const group = groups.get(section);
59
+ if (group)
60
+ group.push(row);
61
+ else
62
+ groups.set(section, [row]);
63
+ }
64
+ const ordered = [];
65
+ for (const [section, group] of groups) {
66
+ if (section)
67
+ headings.set(ordered.length, section);
68
+ ordered.push(...group);
69
+ }
70
+ return { rows: ordered, headings };
71
+ }
72
+ /**
73
+ * Peers' standard autocomplete: a searchable, clearable Bootstrap combobox for picking one
74
+ * item from a list, local (`options`) or searched (`loadOptions`). Arrow keys and Enter belong
75
+ * to the popup while open; Tab picks the highlighted choice and moves on; Escape closes it.
76
+ * The list opens over a scrolling grid or an enclosing Peers popover in the same document.
77
+ *
78
+ * Rows can be drawn by the app (`renderOption`), grouped under headings
79
+ * (`getOptionSection`), followed by the app's own actions (`footer`) and the keys
80
+ * (`keyHints`), and the empty state can offer to create what was typed (`renderEmpty`).
81
+ */
82
+ function Autocomplete(props) {
83
+ const value = (0, reactive_1.useGridValue)(props.value);
84
+ const options = (0, reactive_1.useGridValue)(props.options ?? emptyOptions);
85
+ const id = (0, react_1.useId)();
86
+ const input = (0, react_1.useRef)(null);
87
+ // The open list belongs to its containing popover or the page. Null closes it.
88
+ const [popupParent, setPopupParent] = (0, react_1.useState)(null);
89
+ const [query, setQuery] = (0, react_1.useState)(null);
90
+ const [active, setActive] = (0, react_1.useState)(-1);
91
+ const [remote, setRemote] = (0, react_1.useState)(emptyOptions);
92
+ const [loading, setLoading] = (0, react_1.useState)(false);
93
+ const [error, setError] = (0, react_1.useState)("");
94
+ const [position, setPosition] = (0, react_1.useState)({ left: 0, top: 0, width: 0, maxHeight: 240 });
95
+ const search = query ?? "";
96
+ const eligible = search.length >= (props.minLength ?? 0);
97
+ const { rows: results, headings } = bySection((props.loadOptions
98
+ ? remote
99
+ : options.filter((option) => props.getOptionLabel(option).toLocaleLowerCase().includes(search.toLocaleLowerCase()))).slice(0, props.maxResults ?? 100), props.getOptionSection);
100
+ const searchLook = props.variant === "search";
101
+ const remoteQuery = props.loadOptions && popupParent && !props.disabled && eligible ? search : null;
102
+ (0, react_1.useEffect)(() => {
103
+ setError("");
104
+ if (remoteQuery === null || !props.loadOptions) {
105
+ setLoading(false);
106
+ setRemote(emptyOptions);
107
+ return;
108
+ }
109
+ const controller = new AbortController();
110
+ let current = true;
111
+ setLoading(true);
112
+ setRemote(emptyOptions);
113
+ const timer = setTimeout(async () => {
114
+ try {
115
+ const rows = await props.loadOptions?.(remoteQuery, controller.signal);
116
+ if (current)
117
+ setRemote(rows ?? emptyOptions);
118
+ }
119
+ catch (cause) {
120
+ if (current)
121
+ setError(cause instanceof Error && cause.message ? cause.message : "Could not load choices");
122
+ }
123
+ finally {
124
+ if (current)
125
+ setLoading(false);
126
+ }
127
+ }, props.debounceMs ?? 150);
128
+ return () => {
129
+ current = false;
130
+ controller.abort();
131
+ clearTimeout(timer);
132
+ };
133
+ }, [remoteQuery, props.loadOptions, props.debounceMs]);
134
+ (0, react_1.useLayoutEffect)(() => {
135
+ if (!popupParent)
136
+ return;
137
+ const cap = props.maxHeight ?? 240;
138
+ const place = () => {
139
+ const rect = input.current?.parentElement?.getBoundingClientRect();
140
+ if (!rect)
141
+ return;
142
+ // The room below, or above: 8 px from the window's edge and 2 from the field.
143
+ const below = window.innerHeight - rect.bottom - 8;
144
+ const height = Math.min(cap, Math.max(100, below >= 140 ? below : rect.top - 10));
145
+ setPosition({
146
+ left: rect.left,
147
+ width: rect.width,
148
+ maxHeight: height,
149
+ // Anchor an upward list by its bottom edge. If it won't fit above, use the space
150
+ // below for a capped list before falling back to the top of a very short window.
151
+ ...(below < 140 && rect.top - height - 2 >= 8
152
+ ? { bottom: window.innerHeight - rect.top + 2 }
153
+ : { top: below >= Math.min(140, height + 2) ? rect.bottom + 2 : 8 }),
154
+ });
155
+ };
156
+ place();
157
+ let frame = 0;
158
+ const followNextFrame = () => {
159
+ frame = requestAnimationFrame(() => {
160
+ frame = 0;
161
+ (0, react_dom_1.flushSync)(place);
162
+ });
163
+ };
164
+ const moved = (event) => {
165
+ // Scrolling the choices leaves the field where it was.
166
+ if (event.target instanceof Element && event.target.id === id)
167
+ return;
168
+ if (popupParent === document.body) {
169
+ place();
170
+ return;
171
+ }
172
+ // React can commit the popover's move between paints. A second scroll before the
173
+ // follow-up still needs to draw that previous move in this frame.
174
+ if (frame) {
175
+ cancelAnimationFrame(frame);
176
+ frame = requestAnimationFrame(() => {
177
+ (0, react_dom_1.flushSync)(place);
178
+ followNextFrame();
179
+ });
180
+ }
181
+ else {
182
+ place();
183
+ frame = requestAnimationFrame(followNextFrame);
184
+ }
185
+ };
186
+ window.addEventListener("resize", moved);
187
+ window.addEventListener("scroll", moved, true);
188
+ // The field can change size while the list is open (AutocompleteChips' typing area moves and
189
+ // grows when a chip goes); the list follows it without measuring on every keystroke. When a
190
+ // chip's whole row goes, the typing area moves up at the same size and only the chips' box
191
+ // changes, so the list follows that box too.
192
+ const field = input.current?.parentElement;
193
+ const resized = field && typeof ResizeObserver !== "undefined" ? new ResizeObserver(place) : null;
194
+ for (const target of [field, field?.closest(".peers-chips-field")]) {
195
+ if (target)
196
+ resized?.observe(target);
197
+ }
198
+ return () => {
199
+ cancelAnimationFrame(frame);
200
+ window.removeEventListener("resize", moved);
201
+ window.removeEventListener("scroll", moved, true);
202
+ resized?.disconnect();
203
+ };
204
+ }, [popupParent, props.maxHeight, id]);
205
+ (0, react_1.useEffect)(() => {
206
+ if (popupParent && active >= 0)
207
+ document.getElementById(`${id}-${active}`)?.scrollIntoView?.({ block: "nearest" });
208
+ }, [popupParent, active, id]);
209
+ const open = () => {
210
+ if (!popupParent)
211
+ setPopupParent(input.current?.closest(".peers-piece-popover") ?? document.body);
212
+ };
213
+ const close = () => {
214
+ setPopupParent(null);
215
+ setQuery(null);
216
+ setActive(-1);
217
+ };
218
+ const choose = (option) => {
219
+ props.onChange(option);
220
+ close();
221
+ };
222
+ const setRef = (node) => {
223
+ input.current = node;
224
+ if (typeof props.inputRef === "function")
225
+ props.inputRef(node);
226
+ else if (props.inputRef)
227
+ props.inputRef.current = node;
228
+ };
229
+ const show = popupParent !== null && !props.disabled;
230
+ const clearable = props.clearable ?? !props.required;
231
+ const showClear = clearable && (value !== null || !!query);
232
+ // An optional pick whose text the user erased: Enter or Tab clears it, the keyboard's way to
233
+ // the × (which stays out of the tab order, so Tab in a grid goes on to the next cell).
234
+ const erased = query === "" && value !== null && !props.required && clearable;
235
+ const selectedLabel = value === null ? "" : props.getOptionLabel(value);
236
+ const rightPadding = (searchLook ? 0.5 : 2.75) + (showClear ? 2 : 0) + (props.invalid ? 1.5 : 0);
237
+ const selectedKey = value === null ? undefined : props.getOptionKey(value);
238
+ const showBody = loading || error || !eligible || !results.length;
239
+ const footer = props.keyHints || props.footer ? ((0, jsx_runtime_1.jsxs)("div", { className: "peers-autocomplete-footer", children: [props.keyHints ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("span", { children: [(0, jsx_runtime_1.jsx)("kbd", { children: "\u2191" }), " ", (0, jsx_runtime_1.jsx)("kbd", { children: "\u2193" }), " move"] }), (0, jsx_runtime_1.jsxs)("span", { children: [(0, jsx_runtime_1.jsx)("kbd", { children: "Enter" }), " pick"] }), (0, jsx_runtime_1.jsxs)("span", { children: [(0, jsx_runtime_1.jsx)("kbd", { children: "Esc" }), " close"] })] })) : null, props.footer ? (0, jsx_runtime_1.jsx)("span", { className: "ms-auto", children: props.footer }) : null] })) : null;
240
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "peers-autocomplete position-relative", style: { minWidth: 0, width: "100%" }, children: [searchLook ? ((0, jsx_runtime_1.jsx)("i", { className: "bi bi-search position-absolute text-body-secondary", style: {
241
+ left: "0.75rem",
242
+ top: "50%",
243
+ transform: "translateY(-50%)",
244
+ zIndex: 5,
245
+ pointerEvents: "none",
246
+ }, "aria-hidden": "true" })) : null, (0, jsx_runtime_1.jsx)("input", { ref: setRef, className: `form-control ${props.invalid ? "is-invalid" : ""}`, style: {
247
+ minWidth: 0,
248
+ paddingLeft: searchLook ? "2.25rem" : undefined,
249
+ paddingRight: `${rightPadding}rem`,
250
+ backgroundPosition: props.invalid ? `right ${rightPadding - 1.5}rem center` : undefined,
251
+ }, role: "combobox", "aria-label": props.label, "aria-autocomplete": "list", "aria-expanded": show, "aria-controls": show ? id : undefined, "aria-activedescendant": show && !showBody && active >= 0 && active < results.length
252
+ ? `${id}-${active}`
253
+ : undefined, "aria-invalid": props.invalid || undefined, autoComplete: "off", value: query ?? selectedLabel, placeholder: props.placeholder, disabled: props.disabled, required: props.required, onFocus: (event) => {
254
+ event.target.select();
255
+ }, onBlur: close, onChange: ({ target: { value: nextQuery } }) => {
256
+ setQuery(nextQuery);
257
+ // Erasing the selected label in an open list can leave the remote query at "".
258
+ // Its choices (or error) still belong to the field until a different search starts.
259
+ if (props.loadOptions && nextQuery !== remoteQuery) {
260
+ setRemote(emptyOptions);
261
+ setLoading(true);
262
+ setError("");
263
+ }
264
+ open();
265
+ setActive(-1);
266
+ }, onKeyDown: (event) => {
267
+ if (event.nativeEvent.isComposing || event.ctrlKey || event.metaKey || event.altKey)
268
+ return;
269
+ if (event.key === "ArrowDown" || (event.key === "ArrowUp" && show)) {
270
+ event.preventDefault();
271
+ event.stopPropagation();
272
+ open();
273
+ setActive((prior) => event.key === "ArrowDown"
274
+ ? Math.min(prior + 1, results.length - 1)
275
+ : prior <= 0
276
+ ? results.length - 1
277
+ : Math.min(prior - 1, results.length - 1));
278
+ }
279
+ else if (event.key === "Enter" && show) {
280
+ event.preventDefault();
281
+ event.stopPropagation();
282
+ const highlighted = !showBody && active >= 0 && active < results.length;
283
+ if (erased && !highlighted)
284
+ choose(null);
285
+ else if (!showBody)
286
+ choose(results[highlighted ? active : 0]);
287
+ }
288
+ else if (event.key === "Escape" && (show || query !== null)) {
289
+ event.preventDefault();
290
+ event.stopPropagation();
291
+ close();
292
+ }
293
+ else if (event.key === "Tab" && show) {
294
+ const finish = () => {
295
+ if (!showBody && active >= 0 && active < results.length)
296
+ choose(results[active]);
297
+ else if (erased)
298
+ choose(null);
299
+ else
300
+ close();
301
+ };
302
+ // A popover counts its tab stops as this key bubbles. Remove the footer before then.
303
+ if (popupParent === document.body)
304
+ finish();
305
+ else
306
+ (0, react_dom_1.flushSync)(finish);
307
+ }
308
+ } }), (0, jsx_runtime_1.jsxs)("span", { className: "position-absolute top-0 end-0 h-100 d-flex align-items-center", style: { paddingRight: "0.25rem" }, children: [showClear && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn d-inline-flex align-items-center justify-content-center", style: indicatorStyle, tabIndex: -1, "aria-label": `Clear ${props.label}`, disabled: props.disabled, onMouseDown: (event) => event.preventDefault(), onClick: () => {
309
+ if (value === null) {
310
+ setQuery("");
311
+ setActive(-1);
312
+ }
313
+ else
314
+ choose(null);
315
+ input.current?.focus();
316
+ }, children: (0, jsx_runtime_1.jsx)("svg", { width: "14", height: "14", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", focusable: "false", children: (0, jsx_runtime_1.jsx)("path", { d: "m4 4 8 8M12 4l-8 8", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }) }) })), searchLook ? null : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("span", { "aria-hidden": "true", style: {
317
+ height: "55%",
318
+ borderLeft: "1px solid var(--bs-border-color)",
319
+ marginInline: "0.125rem",
320
+ } }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn d-inline-flex align-items-center justify-content-center", style: indicatorStyle, tabIndex: -1, "aria-label": `Show ${props.label} choices`, disabled: props.disabled, onMouseDown: (event) => event.preventDefault(), onClick: () => {
321
+ input.current?.focus();
322
+ setQuery(null);
323
+ setActive(-1);
324
+ if (popupParent)
325
+ setPopupParent(null);
326
+ else
327
+ open();
328
+ }, children: (0, jsx_runtime_1.jsx)("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", focusable: "false", children: (0, jsx_runtime_1.jsx)("path", { d: "m4 6 4 4 4-4", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }) })] }))] }), show &&
329
+ (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsxs)("div", { className: "peers-autocomplete-popup border rounded bg-body text-body shadow d-flex flex-column", style: { position: "fixed", ...position, zIndex: 1080 },
330
+ // A press anywhere in the popup (a heading, the footer's actions) keeps the input
331
+ // focused, so the popup stays open until the click lands.
332
+ onMouseDown: (event) => event.preventDefault(), children: [(0, jsx_runtime_1.jsx)("div", { id: id, role: "listbox", "aria-label": `${props.label} choices`, style: { overflowY: "auto", minHeight: 0 }, children: showBody ? ((0, jsx_runtime_1.jsx)("div", { className: `p-2 ${eligible && error ? "text-danger" : "text-body-secondary"}`, role: "status", children: !eligible
333
+ ? `Type at least ${props.minLength} characters`
334
+ : loading
335
+ ? "Loading…"
336
+ : error || (props.renderEmpty?.(search) ?? "No matches") })) : (results.map((option, index) => {
337
+ const key = props.getOptionKey(option);
338
+ const heading = headings.get(index);
339
+ const state = {
340
+ active: active === index,
341
+ selected: key === selectedKey,
342
+ query: search,
343
+ };
344
+ return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [heading ? ((0, jsx_runtime_1.jsx)("div", { className: "peers-autocomplete-section", role: "presentation", children: heading })) : null, (0, jsx_runtime_1.jsx)("div", { id: `${id}-${index}`, role: "option", "aria-selected": state.selected, className: `peers-autocomplete-option${state.active ? " is-active" : ""}`, onMouseEnter: () => setActive(index), onClick: () => choose(option), children: props.renderOption ? (props.renderOption(option, state)) : ((0, jsx_runtime_1.jsx)(HighlightMatch, { text: props.getOptionLabel(option), query: search })) })] }, key));
345
+ })) }), footer] }), popupParent)] }));
346
+ }
@@ -0,0 +1,26 @@
1
+ import type React from "react";
2
+ /**
3
+ * A button for an action that can't be undone, asked in two steps without a dialog: the first
4
+ * click turns it into "Sure?" (in red), and a second click within a few seconds does it.
5
+ * Escape, leaving the button, or waiting puts it back. Use it instead of `window.confirm`, which
6
+ * an isolated screen can't show.
7
+ *
8
+ * @param props.children - The button's label, such as "Delete".
9
+ * @param props.confirmLabel - What it says while waiting for the second click; "Sure?" by default.
10
+ * @param props.onConfirm - The action. The button is disabled until a returned promise settles.
11
+ * @param props.className - Its classes; a small outlined red button by default.
12
+ * @param props.confirmClassName - Its classes while waiting; a small red button by default.
13
+ * @param props.disabled - Turns the button off.
14
+ * @param props.title - Its tooltip.
15
+ * @param props.timeoutMs - How long it waits for the second click; 4 seconds by default.
16
+ */
17
+ export declare function ConfirmButton(props: {
18
+ children: React.ReactNode;
19
+ confirmLabel?: React.ReactNode;
20
+ onConfirm: () => unknown;
21
+ className?: string;
22
+ confirmClassName?: string;
23
+ disabled?: boolean;
24
+ title?: string;
25
+ timeoutMs?: number;
26
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfirmButton = ConfirmButton;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ /**
7
+ * A button for an action that can't be undone, asked in two steps without a dialog: the first
8
+ * click turns it into "Sure?" (in red), and a second click within a few seconds does it.
9
+ * Escape, leaving the button, or waiting puts it back. Use it instead of `window.confirm`, which
10
+ * an isolated screen can't show.
11
+ *
12
+ * @param props.children - The button's label, such as "Delete".
13
+ * @param props.confirmLabel - What it says while waiting for the second click; "Sure?" by default.
14
+ * @param props.onConfirm - The action. The button is disabled until a returned promise settles.
15
+ * @param props.className - Its classes; a small outlined red button by default.
16
+ * @param props.confirmClassName - Its classes while waiting; a small red button by default.
17
+ * @param props.disabled - Turns the button off.
18
+ * @param props.title - Its tooltip.
19
+ * @param props.timeoutMs - How long it waits for the second click; 4 seconds by default.
20
+ */
21
+ function ConfirmButton(props) {
22
+ const [armed, setArmed] = (0, react_1.useState)(false);
23
+ const [busy, setBusy] = (0, react_1.useState)(false);
24
+ (0, react_1.useEffect)(() => {
25
+ if (!armed)
26
+ return;
27
+ const timer = setTimeout(() => setArmed(false), props.timeoutMs ?? 4000);
28
+ return () => clearTimeout(timer);
29
+ }, [armed, props.timeoutMs]);
30
+ async function click(event) {
31
+ if (!armed) {
32
+ event.currentTarget.focus();
33
+ setArmed(true);
34
+ return;
35
+ }
36
+ setArmed(false);
37
+ setBusy(true);
38
+ try {
39
+ await props.onConfirm();
40
+ }
41
+ finally {
42
+ setBusy(false);
43
+ }
44
+ }
45
+ return ((0, jsx_runtime_1.jsx)("button", { type: "button", className: armed
46
+ ? (props.confirmClassName ?? "btn btn-danger btn-sm")
47
+ : (props.className ?? "btn btn-outline-danger btn-sm"), title: props.title, disabled: props.disabled || busy, "aria-live": "polite", onClick: click, onBlur: () => setArmed(false), onKeyDown: (event) => {
48
+ if (event.key === "Enter" && event.repeat)
49
+ event.preventDefault();
50
+ if (event.key === "Escape" && armed) {
51
+ event.stopPropagation();
52
+ setArmed(false);
53
+ }
54
+ }, children: armed ? (props.confirmLabel ?? "Sure?") : props.children }));
55
+ }
@@ -1,31 +1 @@
1
- import { type Ref } from "react";
2
- import { type GridValue } from "./reactive";
3
- /** Single-selection lookup, independent of any table, ORM, or contract. */
4
- export interface AutocompleteProps<T> {
5
- /** Current selection; observable updates are reflected without recreating the control. */
6
- value: GridValue<T | null>;
7
- /** Local choices in display order, optionally supplied by a Peers observable. */
8
- options?: GridValue<readonly T[]>;
9
- /** Remote search. Stale responses are ignored and the signal is aborted on replacement. */
10
- loadOptions?: (query: string, signal: AbortSignal) => Promise<readonly T[]>;
11
- getOptionKey: (option: T) => string;
12
- getOptionLabel: (option: T) => string;
13
- /** Explicit write boundary; a writable local observable can be passed directly. */
14
- onChange: (value: T | null) => void;
15
- label: string;
16
- placeholder?: string;
17
- disabled?: boolean;
18
- required?: boolean;
19
- clearable?: boolean;
20
- minLength?: number;
21
- debounceMs?: number;
22
- maxResults?: number;
23
- inputRef?: Ref<HTMLInputElement>;
24
- invalid?: boolean;
25
- }
26
- /**
27
- * Searchable, clearable Bootstrap combobox inspired by JobTrak's Typeahead/FK controls.
28
- * Arrow keys and Enter belong to the popup while open; Tab selects a highlighted result
29
- * and continues naturally. The popup is portaled so a scrolling grid cannot clip it.
30
- */
31
- export declare function Autocomplete<T>(props: AutocompleteProps<T>): import("react/jsx-runtime").JSX.Element;
1
+ export { Autocomplete, type AutocompleteProps } from "../autocomplete";