@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.
- package/dist/apps-home/app-menu.d.ts +1 -2
- package/dist/apps-home/app-menu.js +29 -25
- package/dist/command-palette/command-palette-ui.js +13 -12
- package/dist/components/autocomplete-chips.d.ts +18 -0
- package/dist/components/autocomplete-chips.js +49 -0
- package/dist/components/autocomplete.d.ts +88 -0
- package/dist/components/autocomplete.js +346 -0
- package/dist/components/confirm-button.d.ts +26 -0
- package/dist/components/confirm-button.js +55 -0
- package/dist/components/data-grid/autocomplete.d.ts +1 -31
- package/dist/components/data-grid/autocomplete.js +5 -197
- package/dist/components/empty-state.d.ts +16 -0
- package/dist/components/empty-state.js +16 -0
- package/dist/components/group-switcher.d.ts +3 -3
- package/dist/components/group-switcher.js +22 -17
- package/dist/components/inline-create-form.d.ts +22 -0
- package/dist/components/inline-create-form.js +56 -0
- package/dist/components/list-row.d.ts +33 -0
- package/dist/components/list-row.js +30 -0
- package/dist/components/list-screen.d.ts +31 -3
- package/dist/components/list-screen.js +61 -28
- package/dist/components/markdown-editor/format-bar.js +15 -40
- package/dist/components/markdown-editor/link-plugin.js +38 -9
- package/dist/components/markdown-editor/selection-bar-place.d.ts +37 -0
- package/dist/components/markdown-editor/selection-bar-place.js +107 -0
- package/dist/components/menu-button.d.ts +34 -0
- package/dist/components/menu-button.js +66 -0
- package/dist/components/screen-header.d.ts +35 -0
- package/dist/components/screen-header.js +30 -0
- package/dist/components/search-field.d.ts +22 -0
- package/dist/components/search-field.js +22 -0
- package/dist/components/segmented-control.d.ts +25 -0
- package/dist/components/segmented-control.js +18 -0
- package/dist/components/typeahead.d.ts +9 -0
- package/dist/components/typeahead.js +7 -0
- package/dist/delegates/acts-for-you-panel.d.ts +2 -1
- package/dist/delegates/acts-for-you-panel.js +46 -17
- package/dist/delegates/delegate-request-dialog.d.ts +3 -1
- package/dist/delegates/delegate-request-dialog.js +6 -3
- package/dist/groups/groups-client.d.ts +23 -1
- package/dist/groups/groups-client.js +31 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +14 -1
- package/dist/isolated-screens/config.js +1 -9
- package/dist/isolated-screens/folder-picker-control.d.ts +57 -0
- package/dist/isolated-screens/folder-picker-control.js +217 -0
- package/dist/isolated-screens/folder-picker-host.d.ts +57 -0
- package/dist/isolated-screens/folder-picker-host.js +178 -0
- package/dist/isolated-screens/folder-picker-protocol.d.ts +75 -0
- package/dist/isolated-screens/folder-picker-protocol.js +104 -0
- package/dist/isolated-screens/frame-bridge.js +8 -0
- package/dist/isolated-screens/frame-document.js +2 -1
- package/dist/isolated-screens/frame-microphone.d.ts +55 -0
- package/dist/isolated-screens/frame-microphone.js +265 -0
- package/dist/isolated-screens/frame-permissions.d.ts +19 -0
- package/dist/isolated-screens/frame-permissions.js +32 -0
- package/dist/isolated-screens/frame-protocol.d.ts +26 -0
- package/dist/isolated-screens/frame-protocol.js +9 -0
- package/dist/isolated-screens/frame-pvars.d.ts +27 -0
- package/dist/isolated-screens/frame-pvars.js +101 -14
- package/dist/isolated-screens/global-widgets.d.ts +1 -2
- package/dist/isolated-screens/index.d.ts +2 -0
- package/dist/isolated-screens/index.js +3 -1
- package/dist/isolated-screens/isolated-screen.d.ts +21 -0
- package/dist/isolated-screens/isolated-screen.js +88 -5
- package/dist/isolated-screens/local-folder-picker.d.ts +55 -0
- package/dist/isolated-screens/local-folder-picker.js +143 -0
- package/dist/isolated-screens/microphone-host.d.ts +110 -0
- package/dist/isolated-screens/microphone-host.js +397 -0
- package/dist/isolated-screens/microphone-prompt.d.ts +20 -0
- package/dist/isolated-screens/microphone-prompt.js +60 -0
- package/dist/isolated-screens/piece-frames.js +5 -94
- package/dist/isolated-screens/piece-reach.d.ts +1 -0
- package/dist/isolated-screens/port-channel.d.ts +21 -11
- package/dist/isolated-screens/port-channel.js +15 -5
- package/dist/isolated-screens/slot-rect.d.ts +38 -0
- package/dist/isolated-screens/slot-rect.js +121 -0
- package/dist/isolated-screens/test-ports.d.ts +17 -0
- package/dist/isolated-screens/test-ports.js +25 -3
- package/dist/mentions/mention-chooser.js +1 -1
- package/dist/notifications/notifications-screen.js +1 -1
- package/dist/screens/data-explorer/data-explorer.d.ts +1 -0
- package/dist/screens/data-explorer/data-explorer.js +28 -10
- package/dist/screens/data-explorer/query-executor.d.ts +1 -0
- package/dist/screens/data-explorer/query-executor.js +3 -1
- package/dist/screens/groups/group-list.d.ts +13 -3
- package/dist/screens/groups/group-list.js +88 -11
- package/dist/screens/identity/identity-routes.d.ts +16 -0
- package/dist/screens/identity/identity-routes.js +27 -10
- package/dist/screens/identity/identity-screen.js +4 -1
- package/dist/screens/invites/activity-view.d.ts +3 -1
- package/dist/screens/invites/activity-view.js +7 -3
- package/dist/screens/invites/pending-invites-list.d.ts +8 -4
- package/dist/screens/invites/pending-invites-list.js +44 -45
- package/dist/screens/network-viewer/graph/network-graph-controls.js +3 -3
- package/dist/screens/packages/local-folder-grants-panel.d.ts +2 -0
- package/dist/screens/packages/local-folder-grants-panel.js +1 -1
- package/dist/screens/packages/package-info.js +2 -1
- package/dist/screens/packages/package-list.d.ts +2 -2
- package/dist/screens/packages/package-list.js +89 -105
- package/dist/screens/packages/package-microphone-panel.d.ts +14 -0
- package/dist/screens/packages/package-microphone-panel.js +62 -0
- package/dist/screens/packages/package-runtime-status.d.ts +10 -2
- package/dist/screens/packages/package-runtime-status.js +17 -4
- package/dist/screens/peer-types/peer-type-details.js +3 -2
- package/dist/screens/peer-types/peer-type-list.d.ts +1 -1
- package/dist/screens/peer-types/peer-type-list.js +4 -4
- package/dist/screens/settings/settings-page.js +1 -4
- package/dist/screens/tools/tool-details.js +2 -1
- package/dist/screens/tools/tool-list.d.ts +1 -1
- package/dist/screens/tools/tool-list.js +22 -60
- package/dist/screens/variables/variable-details.js +5 -4
- package/dist/screens/variables/variable-list.d.ts +17 -0
- package/dist/screens/variables/variable-list.js +72 -28
- package/dist/tabs-layout/network-status-details.d.ts +4 -4
- package/dist/tabs-layout/network-status-details.js +6 -5
- package/dist/tabs-layout/network-status-indicator.d.ts +1 -0
- package/dist/tabs-layout/network-status-indicator.js +1 -0
- package/dist/tabs-layout/tab-bar-shortcuts.d.ts +46 -0
- package/dist/tabs-layout/tab-bar-shortcuts.js +140 -0
- package/dist/tabs-layout/tabs-layout.js +11 -9
- package/dist/theme.css +326 -6
- package/dist/ui-contracts/popover-surface.d.ts +3 -0
- package/dist/ui-contracts/popover-surface.js +6 -3
- package/dist/ui-defaults/list-screen.js +10 -4
- package/package.json +3 -3
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type React from "react";
|
|
2
1
|
import type { IAppEntry } from "../ui-router/app-catalog";
|
|
3
2
|
import type { IAppPackageStatus } from "./app-status";
|
|
4
3
|
/** Where the menu opens: at a point (a right-click), or beside an element (the keyboard). */
|
|
@@ -53,5 +52,5 @@ export declare function appMenuSubtitle(entry: IAppEntry, status?: IAppPackageSt
|
|
|
53
52
|
* actions. Arrow keys move between items, Escape or a click outside closes it, and choosing an
|
|
54
53
|
* item closes it before running the action.
|
|
55
54
|
*/
|
|
56
|
-
export declare function AppMenu({ entry, status, failure, waiting, actions, anchor, colorMode, onClose, }: IAppMenuProps):
|
|
55
|
+
export declare function AppMenu({ entry, status, failure, waiting, actions, anchor, colorMode, onClose, }: IAppMenuProps): import("react").ReactPortal;
|
|
57
56
|
export {};
|
|
@@ -76,36 +76,40 @@ function AppMenu({ entry, status, failure, waiting, actions, anchor, colorMode,
|
|
|
76
76
|
return () => document.removeEventListener("keydown", onKey);
|
|
77
77
|
}, [onClose]);
|
|
78
78
|
const items = () => Array.from(menuRef.current?.querySelectorAll('[role="menuitem"]') ?? []);
|
|
79
|
+
// The menu takes its keys from the window, before anything else sees them: Bootstrap's
|
|
80
|
+
// JavaScript (the desktop app and the PWA load it) handles keys in any `.dropdown-menu` from the
|
|
81
|
+
// document, and throws for a menu without a Bootstrap toggle.
|
|
79
82
|
const onKeyDown = (event) => {
|
|
83
|
+
const menu = menuRef.current;
|
|
84
|
+
if (!menu || !(event.target instanceof Node) || !menu.contains(event.target))
|
|
85
|
+
return;
|
|
80
86
|
const list = items();
|
|
81
87
|
const index = list.indexOf(document.activeElement);
|
|
82
88
|
const focus = (next) => list[(next + list.length) % list.length]?.focus();
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
focus(list.length - 1);
|
|
99
|
-
break;
|
|
100
|
-
case "Escape":
|
|
101
|
-
case "Tab":
|
|
102
|
-
event.preventDefault();
|
|
103
|
-
event.stopPropagation();
|
|
104
|
-
event.nativeEvent.stopImmediatePropagation();
|
|
105
|
-
onClose();
|
|
106
|
-
break;
|
|
89
|
+
const moves = {
|
|
90
|
+
ArrowDown: index + 1,
|
|
91
|
+
ArrowUp: index - 1,
|
|
92
|
+
Home: 0,
|
|
93
|
+
End: list.length - 1,
|
|
94
|
+
};
|
|
95
|
+
if (event.key in moves) {
|
|
96
|
+
event.preventDefault();
|
|
97
|
+
event.stopPropagation();
|
|
98
|
+
focus(moves[event.key]);
|
|
99
|
+
}
|
|
100
|
+
else if (event.key === "Escape" || event.key === "Tab") {
|
|
101
|
+
event.preventDefault();
|
|
102
|
+
event.stopPropagation();
|
|
103
|
+
onClose();
|
|
107
104
|
}
|
|
108
105
|
};
|
|
106
|
+
const handleKey = (0, react_1.useRef)(onKeyDown);
|
|
107
|
+
handleKey.current = onKeyDown;
|
|
108
|
+
(0, react_1.useEffect)(() => {
|
|
109
|
+
const onKey = (event) => handleKey.current(event);
|
|
110
|
+
window.addEventListener("keydown", onKey, true);
|
|
111
|
+
return () => window.removeEventListener("keydown", onKey, true);
|
|
112
|
+
}, []);
|
|
109
113
|
const subtitle = appMenuSubtitle(entry, status);
|
|
110
114
|
const safeActions = actions.filter((action) => !action.danger);
|
|
111
115
|
const dangerActions = actions.filter((action) => action.danger);
|
|
@@ -116,7 +120,7 @@ function AppMenu({ entry, status, failure, waiting, actions, anchor, colorMode,
|
|
|
116
120
|
left: position?.left ?? 0,
|
|
117
121
|
top: position?.top ?? 0,
|
|
118
122
|
visibility: position ? "visible" : "hidden",
|
|
119
|
-
},
|
|
123
|
+
}, "data-testid": "app-menu", children: [(0, jsx_runtime_1.jsxs)("div", { className: "px-3 pt-1 pb-2 mb-1 border-bottom", children: [(0, jsx_runtime_1.jsx)("div", { className: "fw-semibold text-truncate", children: entry.displayName }), subtitle && (0, jsx_runtime_1.jsx)("div", { className: "peers-app-menu-detail text-truncate", children: subtitle }), failure && ((0, jsx_runtime_1.jsxs)("div", { className: "small text-danger mt-1", style: { maxWidth: 260 }, children: ["Not running here: ", failure] })), !failure && waiting && ((0, jsx_runtime_1.jsx)("div", { className: "small peers-app-menu-waiting mt-1", style: { maxWidth: 260 }, children: waiting }))] }), safeActions.map((action) => ((0, jsx_runtime_1.jsx)(MenuItem, { action: action, onClose: onClose }, action.key))), dangerActions.length > 0 && (0, jsx_runtime_1.jsx)("div", { className: "dropdown-divider" }), dangerActions.map((action) => ((0, jsx_runtime_1.jsx)(MenuItem, { action: action, onClose: onClose }, action.key)))] })] }), document.body);
|
|
120
124
|
}
|
|
121
125
|
function MenuItem({ action, onClose }) {
|
|
122
126
|
return ((0, jsx_runtime_1.jsxs)("button", { type: "button", role: "menuitem", className: `dropdown-item ${action.emphasis ? "active" : ""} ${action.danger ? "text-danger" : ""}`, "data-testid": `app-menu-${action.key}`, onClick: () => {
|
|
@@ -93,10 +93,13 @@ function CommandPaletteOverlay() {
|
|
|
93
93
|
inputRef.current.focus();
|
|
94
94
|
}
|
|
95
95
|
}, [isOpen]);
|
|
96
|
-
//
|
|
96
|
+
// Back to the first row whenever the search changes: a row a resting pointer selected
|
|
97
|
+
// (onMouseEnter) may be filtered away, and Enter would then pick nothing.
|
|
97
98
|
(0, react_1.useEffect)(() => {
|
|
98
99
|
setSelectedIndex(0);
|
|
99
|
-
}, []);
|
|
100
|
+
}, [searchQuery]);
|
|
101
|
+
// The row Enter picks and the list highlights, kept inside the list as it shrinks.
|
|
102
|
+
const activeIndex = Math.max(0, Math.min(selectedIndex, allItems.length - 1));
|
|
100
103
|
// Keyboard navigation
|
|
101
104
|
(0, react_1.useEffect)(() => {
|
|
102
105
|
if (!isOpen)
|
|
@@ -104,15 +107,15 @@ function CommandPaletteOverlay() {
|
|
|
104
107
|
const handleKeyDown = (e) => {
|
|
105
108
|
if (e.key === "ArrowDown") {
|
|
106
109
|
e.preventDefault();
|
|
107
|
-
setSelectedIndex(
|
|
110
|
+
setSelectedIndex(Math.min(activeIndex + 1, allItems.length - 1));
|
|
108
111
|
}
|
|
109
112
|
else if (e.key === "ArrowUp") {
|
|
110
113
|
e.preventDefault();
|
|
111
|
-
setSelectedIndex(
|
|
114
|
+
setSelectedIndex(Math.max(activeIndex - 1, 0));
|
|
112
115
|
}
|
|
113
116
|
else if (e.key === "Enter") {
|
|
114
117
|
e.preventDefault();
|
|
115
|
-
const selectedItem = allItems[
|
|
118
|
+
const selectedItem = allItems[activeIndex];
|
|
116
119
|
if (selectedItem?.type === "app" && selectedItem.app) {
|
|
117
120
|
(0, command_palette_1.closeCommandPalette)();
|
|
118
121
|
(0, tabs_state_1.goToTabPath)(selectedItem.app.path);
|
|
@@ -124,7 +127,7 @@ function CommandPaletteOverlay() {
|
|
|
124
127
|
};
|
|
125
128
|
document.addEventListener("keydown", handleKeyDown);
|
|
126
129
|
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
127
|
-
}, [isOpen,
|
|
130
|
+
}, [isOpen, activeIndex, allItems]);
|
|
128
131
|
if (!isOpen)
|
|
129
132
|
return null;
|
|
130
133
|
const isDark = _colorMode === "dark";
|
|
@@ -175,10 +178,8 @@ function CommandPaletteOverlay() {
|
|
|
175
178
|
} })] }) }), (0, jsx_runtime_1.jsx)("div", { style: {
|
|
176
179
|
maxHeight: "400px",
|
|
177
180
|
overflowY: "auto",
|
|
178
|
-
}, children: allItems.length === 0 && !searchQuery.trim() ? ((0, jsx_runtime_1.jsxs)("div", { className: "p-4 text-center text-muted", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-search mb-2 d-block", style: { fontSize: "24px" } }), "No results found"] })) : ((0, jsx_runtime_1.jsxs)("div", { className: "py-2", children: [allItems.length === 0 && searchQuery.trim() && ((0, jsx_runtime_1.jsx)("div", { className: "px-3 py-2 text-muted small text-center", children: "No matching results" })), filteredApps.length > 0 && ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("div", { className: "px-3 py-1 small text-muted fw-bold text-uppercase", style: { fontSize: "11px", letterSpacing: "0.5px" }, children: "Apps" }), filteredApps.map((app) => {
|
|
179
|
-
const
|
|
180
|
-
const globalIndex = allItems.findIndex((item) => item.id === appId);
|
|
181
|
-
const isSelected = globalIndex === selectedIndex;
|
|
181
|
+
}, children: allItems.length === 0 && !searchQuery.trim() ? ((0, jsx_runtime_1.jsxs)("div", { className: "p-4 text-center text-muted", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-search mb-2 d-block", style: { fontSize: "24px" } }), "No results found"] })) : ((0, jsx_runtime_1.jsxs)("div", { className: "py-2", children: [allItems.length === 0 && searchQuery.trim() && ((0, jsx_runtime_1.jsx)("div", { className: "px-3 py-2 text-muted small text-center", children: "No matching results" })), filteredApps.length > 0 && ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("div", { className: "px-3 py-1 small text-muted fw-bold text-uppercase", style: { fontSize: "11px", letterSpacing: "0.5px" }, children: "Apps" }), filteredApps.map((app, globalIndex) => {
|
|
182
|
+
const isSelected = globalIndex === activeIndex;
|
|
182
183
|
return ((0, jsx_runtime_1.jsx)("div", { className: `px-3 py-2 d-flex align-items-center justify-content-between ${isSelected
|
|
183
184
|
? isDark
|
|
184
185
|
? "bg-primary bg-opacity-25"
|
|
@@ -193,12 +194,12 @@ function CommandPaletteOverlay() {
|
|
|
193
194
|
fontSize: "16px",
|
|
194
195
|
color: isSelected ? (isDark ? "#ffffff" : "#0d6efd") : "#6c757d",
|
|
195
196
|
minWidth: "16px",
|
|
196
|
-
} }), (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("div", { className: "fw-medium", children: app.displayName }), (0, jsx_runtime_1.jsx)("div", { className: "small text-muted", style: { fontSize: "12px" }, children: app.packageId === "system-apps" ? "System App" : app.packageName })] })] }) }, `${app.packageId}-${app.
|
|
197
|
+
} }), (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("div", { className: "fw-medium", children: app.displayName }), (0, jsx_runtime_1.jsx)("div", { className: "small text-muted", style: { fontSize: "12px" }, children: app.packageId === "system-apps" ? "System App" : app.packageName })] })] }) }, `${app.packageId}-${app.navItem.navigationPath}-${app.name}`));
|
|
197
198
|
})] })), filteredCommands.length > 0 &&
|
|
198
199
|
groupedCommands.map(([category, commands]) => ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("div", { className: "px-3 py-1 small text-muted fw-bold text-uppercase", style: { fontSize: "11px", letterSpacing: "0.5px" }, children: category }), commands.map((command) => {
|
|
199
200
|
const commandId = `command-${command.id}`;
|
|
200
201
|
const globalIndex = allItems.findIndex((item) => item.id === commandId);
|
|
201
|
-
const isSelected = globalIndex ===
|
|
202
|
+
const isSelected = globalIndex === activeIndex;
|
|
202
203
|
return ((0, jsx_runtime_1.jsxs)("div", { className: `px-3 py-2 d-flex align-items-center justify-content-between ${isSelected
|
|
203
204
|
? isDark
|
|
204
205
|
? "bg-primary bg-opacity-25"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
import { type AutocompleteProps } from "./autocomplete";
|
|
3
|
+
/** The props of {@link AutocompleteChips}: {@link AutocompleteProps}, with a list for a value. */
|
|
4
|
+
export type AutocompleteChipsProps<T> = Omit<AutocompleteProps<T>, "value" | "onChange" | "clearable" | "required" | "variant"> & {
|
|
5
|
+
/** The picked items, in the order they were picked. */
|
|
6
|
+
value: readonly T[];
|
|
7
|
+
/** Called with the new list when one is picked or removed. */
|
|
8
|
+
onChange: (value: T[]) => void;
|
|
9
|
+
/** Draws a chip's content; the item's label by default. */
|
|
10
|
+
renderChip?: (option: T) => React.ReactNode;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Several items picked from a list by typing, such as people, tags or groups: each picked item
|
|
14
|
+
* is a chip inside the box, with × to remove it, and typing finds more with {@link Autocomplete}
|
|
15
|
+
* (its keys, sections and remote search included). Items already picked aren't offered again.
|
|
16
|
+
* Backspace in an empty box removes the last chip.
|
|
17
|
+
*/
|
|
18
|
+
export declare function AutocompleteChips<T>(props: AutocompleteChipsProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AutocompleteChips = AutocompleteChips;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const autocomplete_1 = require("./autocomplete");
|
|
7
|
+
const reactive_1 = require("./data-grid/reactive");
|
|
8
|
+
/**
|
|
9
|
+
* Several items picked from a list by typing, such as people, tags or groups: each picked item
|
|
10
|
+
* is a chip inside the box, with × to remove it, and typing finds more with {@link Autocomplete}
|
|
11
|
+
* (its keys, sections and remote search included). Items already picked aren't offered again.
|
|
12
|
+
* Backspace in an empty box removes the last chip.
|
|
13
|
+
*/
|
|
14
|
+
function AutocompleteChips(props) {
|
|
15
|
+
const { value, onChange, renderChip, options, loadOptions, ...rest } = props;
|
|
16
|
+
// Follows the picked keys, not the array's or the key function's identity: a form that draws
|
|
17
|
+
// again with the same picks (a new array, an inline getOptionKey) keeps the same remote loader,
|
|
18
|
+
// so a search the user is waiting on isn't restarted by each redraw.
|
|
19
|
+
const pickedKeys = value.map(rest.getOptionKey);
|
|
20
|
+
const pickedId = JSON.stringify(pickedKeys);
|
|
21
|
+
const picked = (0, react_1.useMemo)(() => new Set(pickedKeys), [pickedId]);
|
|
22
|
+
const allOptions = (0, reactive_1.useGridValue)(options);
|
|
23
|
+
const remaining = (0, react_1.useMemo)(() => allOptions?.filter((option) => !picked.has(rest.getOptionKey(option))), [allOptions, picked, rest.getOptionKey]);
|
|
24
|
+
const loadRemaining = (0, react_1.useCallback)(async (query, signal) => ((await loadOptions?.(query, signal)) ?? []).filter((option) => !picked.has(rest.getOptionKey(option))), [loadOptions, picked]);
|
|
25
|
+
const remove = (0, react_1.useCallback)((key) => onChange(value.filter((option) => rest.getOptionKey(option) !== key)), [onChange, value, rest.getOptionKey]);
|
|
26
|
+
return (
|
|
27
|
+
// A press on the box's empty space focuses its field, as a text box's would.
|
|
28
|
+
(0, jsx_runtime_1.jsxs)("div", { className: `peers-chips-field form-control${rest.disabled ? " is-disabled" : ""}`, onMouseDown: (event) => {
|
|
29
|
+
if (event.target === event.currentTarget) {
|
|
30
|
+
event.preventDefault();
|
|
31
|
+
event.currentTarget.querySelector(".peers-chips-input input")?.focus();
|
|
32
|
+
}
|
|
33
|
+
}, children: [value.map((option) => {
|
|
34
|
+
const key = rest.getOptionKey(option);
|
|
35
|
+
const label = rest.getOptionLabel(option);
|
|
36
|
+
return ((0, jsx_runtime_1.jsxs)("span", { className: "peers-chip", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-truncate", children: renderChip ? renderChip(option) : label }), !rest.disabled && ((0, jsx_runtime_1.jsx)("button", { type: "button", "aria-label": `Remove ${label}`, onClick: () => remove(key), children: (0, jsx_runtime_1.jsx)("i", { className: "bi-x", "aria-hidden": "true" }) }))] }, key));
|
|
37
|
+
}), (0, jsx_runtime_1.jsx)("div", { className: "peers-chips-input", onKeyDown: (event) => {
|
|
38
|
+
if (event.key === "Backspace" &&
|
|
39
|
+
event.target instanceof HTMLInputElement &&
|
|
40
|
+
!event.target.value &&
|
|
41
|
+
value.length &&
|
|
42
|
+
event.currentTarget.contains(event.target)) {
|
|
43
|
+
remove(rest.getOptionKey(value[value.length - 1]));
|
|
44
|
+
}
|
|
45
|
+
}, children: (0, jsx_runtime_1.jsx)(autocomplete_1.Autocomplete, { ...rest, value: null, clearable: false, options: options ? remaining : undefined, loadOptions: loadOptions ? loadRemaining : undefined, onChange: (option) => {
|
|
46
|
+
if (option !== null && !picked.has(rest.getOptionKey(option)))
|
|
47
|
+
onChange([...value, option]);
|
|
48
|
+
} }) })] }));
|
|
49
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { type ReactNode, type Ref } from "react";
|
|
2
|
+
import { type GridValue } from "./data-grid/reactive";
|
|
3
|
+
/** What {@link AutocompleteProps.renderOption} knows about the row it draws. */
|
|
4
|
+
export interface AutocompleteOptionState {
|
|
5
|
+
/** The row the keyboard or pointer is on: Enter picks it. */
|
|
6
|
+
active: boolean;
|
|
7
|
+
/** The row is the current value. */
|
|
8
|
+
selected: boolean;
|
|
9
|
+
/** What was typed, for {@link HighlightMatch}. */
|
|
10
|
+
query: string;
|
|
11
|
+
}
|
|
12
|
+
/** Single-selection lookup, independent of any table, ORM, or contract. */
|
|
13
|
+
export interface AutocompleteProps<T> {
|
|
14
|
+
/** Current selection; observable updates are reflected without recreating the control. */
|
|
15
|
+
value: GridValue<T | null>;
|
|
16
|
+
/** Local choices in display order, optionally supplied by a Peers observable. */
|
|
17
|
+
options?: GridValue<readonly T[]>;
|
|
18
|
+
/** Remote search. Stale responses are ignored and the signal is aborted on replacement. */
|
|
19
|
+
loadOptions?: (query: string, signal: AbortSignal) => Promise<readonly T[]>;
|
|
20
|
+
/** A stable key for each choice. */
|
|
21
|
+
getOptionKey: (option: T) => string;
|
|
22
|
+
/** The choice's text: shown in the box once picked, and matched by local filtering. */
|
|
23
|
+
getOptionLabel: (option: T) => string;
|
|
24
|
+
/** Explicit write boundary; a writable local observable can be passed directly. */
|
|
25
|
+
onChange: (value: T | null) => void;
|
|
26
|
+
/** The field's accessible name. */
|
|
27
|
+
label: string;
|
|
28
|
+
/** Shown while the box is empty. */
|
|
29
|
+
placeholder?: string;
|
|
30
|
+
/** Read-only and dimmed. */
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
/** A value is required; also hides the clear button unless `clearable` says otherwise. */
|
|
33
|
+
required?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Shows × to clear the value (the default for optional fields). In an optional field this
|
|
36
|
+
* also allows Enter or Tab to clear an erased label when no choice is highlighted.
|
|
37
|
+
*/
|
|
38
|
+
clearable?: boolean;
|
|
39
|
+
/** Characters to type before choices show (default 0). */
|
|
40
|
+
minLength?: number;
|
|
41
|
+
/** Wait after typing before `loadOptions` runs, in milliseconds (default 150). */
|
|
42
|
+
debounceMs?: number;
|
|
43
|
+
/** The most choices shown (default 100). */
|
|
44
|
+
maxResults?: number;
|
|
45
|
+
/** The input element, for focusing it from outside. */
|
|
46
|
+
inputRef?: Ref<HTMLInputElement>;
|
|
47
|
+
/** Draws the field as invalid (Bootstrap's `is-invalid`). */
|
|
48
|
+
invalid?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* `select` (the default) is a dropdown field with a chevron. `search` is a search field: a
|
|
51
|
+
* magnifier at the left and no chevron, for picking from a long list by typing.
|
|
52
|
+
*/
|
|
53
|
+
variant?: "select" | "search";
|
|
54
|
+
/** Draws a choice's row; the default is its label with the typed words in bold. */
|
|
55
|
+
renderOption?: (option: T, state: AutocompleteOptionState) => ReactNode;
|
|
56
|
+
/**
|
|
57
|
+
* Puts choices under headings: the section each choice belongs to, or undefined for none.
|
|
58
|
+
* Sections show in the order their first choice comes, and choices keep their order in them.
|
|
59
|
+
*/
|
|
60
|
+
getOptionSection?: (option: T) => string | undefined;
|
|
61
|
+
/** What shows when nothing matches; the default is "No matches". Gets what was typed. */
|
|
62
|
+
renderEmpty?: (query: string) => ReactNode;
|
|
63
|
+
/** The app's own actions, under the choices (such as "Remove parent"). */
|
|
64
|
+
footer?: ReactNode;
|
|
65
|
+
/** Shows the keys (↑ ↓, Enter, Esc) under the choices. */
|
|
66
|
+
keyHints?: boolean;
|
|
67
|
+
/** The tallest the choices get, in pixels (default 240; less when the window is short). */
|
|
68
|
+
maxHeight?: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Text with the words of `query` in bold, as autocomplete rows show what matched. Matching
|
|
72
|
+
* ignores case; an empty query leaves the text as it is.
|
|
73
|
+
*/
|
|
74
|
+
export declare function HighlightMatch(props: {
|
|
75
|
+
text: string;
|
|
76
|
+
query: string;
|
|
77
|
+
}): JSX.Element;
|
|
78
|
+
/**
|
|
79
|
+
* Peers' standard autocomplete: a searchable, clearable Bootstrap combobox for picking one
|
|
80
|
+
* item from a list, local (`options`) or searched (`loadOptions`). Arrow keys and Enter belong
|
|
81
|
+
* to the popup while open; Tab picks the highlighted choice and moves on; Escape closes it.
|
|
82
|
+
* The list opens over a scrolling grid or an enclosing Peers popover in the same document.
|
|
83
|
+
*
|
|
84
|
+
* Rows can be drawn by the app (`renderOption`), grouped under headings
|
|
85
|
+
* (`getOptionSection`), followed by the app's own actions (`footer`) and the keys
|
|
86
|
+
* (`keyHints`), and the empty state can offer to create what was typed (`renderEmpty`).
|
|
87
|
+
*/
|
|
88
|
+
export declare function Autocomplete<T>(props: AutocompleteProps<T>): import("react/jsx-runtime").JSX.Element;
|