@peers-app/peers-ui 0.33.18 → 0.33.19

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 (45) hide show
  1. package/dist/apps-home/app-tile.js +2 -1
  2. package/dist/apps-home/get-apps-sheet.js +2 -1
  3. package/dist/apps-home/remove-app-dialog.js +2 -1
  4. package/dist/command-palette/command-palette-ui.js +3 -2
  5. package/dist/components/color-picker.d.ts +28 -0
  6. package/dist/components/color-picker.js +97 -0
  7. package/dist/components/group-switcher.js +59 -99
  8. package/dist/components/icon-picker.d.ts +20 -0
  9. package/dist/components/icon-picker.js +98 -0
  10. package/dist/components/icon-search.d.ts +60 -0
  11. package/dist/components/icon-search.js +227 -0
  12. package/dist/components/icon.d.ts +35 -0
  13. package/dist/components/icon.js +34 -0
  14. package/dist/components/markdown-editor/mention-preview-card.js +2 -1
  15. package/dist/components/markdown-editor/mentions-plugin.js +2 -1
  16. package/dist/groups/group-appearance-dialog.d.ts +25 -0
  17. package/dist/groups/group-appearance-dialog.js +206 -0
  18. package/dist/groups/group-look.d.ts +45 -0
  19. package/dist/groups/group-look.js +47 -0
  20. package/dist/groups/groups-client.d.ts +29 -0
  21. package/dist/groups/groups-client.js +81 -0
  22. package/dist/groups/index.d.ts +3 -0
  23. package/dist/groups/index.js +15 -0
  24. package/dist/icon-index/bootstrap-icons.json +1 -0
  25. package/dist/icon-index/emoji.json +1 -0
  26. package/dist/index.d.ts +5 -0
  27. package/dist/index.js +8 -1
  28. package/dist/mentions/mention-chip.js +2 -1
  29. package/dist/mentions/mention-chooser.js +2 -1
  30. package/dist/root-layout/layouts/full-screen-layout.js +2 -1
  31. package/dist/screens/groups/group-details.js +16 -2
  32. package/dist/screens/groups/group-list.js +37 -43
  33. package/dist/screens/groups/groups-ipc.d.ts +15 -0
  34. package/dist/screens/groups/groups-ipc.js +28 -0
  35. package/dist/screens/packages/package-waiting.js +4 -3
  36. package/dist/screens/peer-types/peer-type-details.d.ts +9 -1
  37. package/dist/screens/peer-types/peer-type-details.js +16 -13
  38. package/dist/screens/peer-types/peer-type-list.d.ts +1 -0
  39. package/dist/screens/peer-types/peer-type-list.js +3 -1
  40. package/dist/screens/search/global-search.js +2 -1
  41. package/dist/tabs-layout/tabs-layout.js +4 -3
  42. package/dist/theme.css +221 -0
  43. package/dist/ui-defaults/list-screen.d.ts +1 -0
  44. package/dist/ui-defaults/list-screen.js +3 -1
  45. package/package.json +4 -4
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AppTile = AppTile;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
+ const icon_1 = require("../components/icon");
6
7
  const app_status_1 = require("./app-status");
7
8
  /** How long a press must last to open the menu on a touch screen. */
8
9
  const LONG_PRESS_MS = 500;
@@ -100,7 +101,7 @@ function AppTile({ entry, pkg, size, pinned, editing, failure, waiting, onOpen,
100
101
  failure ? "peers-app-tile-failed" : "",
101
102
  !failure && waiting ? "peers-app-tile-waiting" : "",
102
103
  status.dev ? "peers-app-tile-dev" : "",
103
- ].join(" "), "data-app-path": entry.path, children: [(0, jsx_runtime_1.jsxs)("button", { ref: buttonRef, type: "button", className: "peers-app-tile", title: entry.displayName, "aria-label": [entry.displayName, ...states].join(", "), "aria-haspopup": editing ? "menu" : undefined, onClick: onClick, onContextMenu: onContextMenu, onKeyDown: onKeyDown, onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: cancelPress, onPointerCancel: cancelPress, onPointerLeave: cancelPress, "data-testid": `app-tile-${entry.path}`, children: [(0, jsx_runtime_1.jsx)("span", { className: `peers-app-icon peers-app-color-${entry.color}`, "aria-hidden": "true", children: (0, jsx_runtime_1.jsx)("i", { className: entry.iconClassName }) }), (0, jsx_runtime_1.jsx)("span", { className: "peers-app-label", children: entry.displayName })] }), !editing && (0, jsx_runtime_1.jsx)(TileStatus, { status: status, failure: failure, waiting: waiting }), editing && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: `peers-app-edit-badge ${pinned ? "peers-app-edit-badge-unpin" : "peers-app-edit-badge-pin"}`, "aria-label": `${pinned ? "Unpin" : "Pin"} ${entry.displayName}`, title: pinned ? "Unpin" : "Pin", onClick: () => onTogglePin(entry), "data-testid": `app-${pinned ? "unpin" : "pin"}-${entry.path}`, children: pinned ? "−" : "+" }))] }));
104
+ ].join(" "), "data-app-path": entry.path, children: [(0, jsx_runtime_1.jsxs)("button", { ref: buttonRef, type: "button", className: "peers-app-tile", title: entry.displayName, "aria-label": [entry.displayName, ...states].join(", "), "aria-haspopup": editing ? "menu" : undefined, onClick: onClick, onContextMenu: onContextMenu, onKeyDown: onKeyDown, onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: cancelPress, onPointerCancel: cancelPress, onPointerLeave: cancelPress, "data-testid": `app-tile-${entry.path}`, children: [(0, jsx_runtime_1.jsx)("span", { className: `peers-app-icon peers-app-color-${entry.color}`, "aria-hidden": "true", children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: entry.iconClassName }) }), (0, jsx_runtime_1.jsx)("span", { className: "peers-app-label", children: entry.displayName })] }), !editing && (0, jsx_runtime_1.jsx)(TileStatus, { status: status, failure: failure, waiting: waiting }), editing && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: `peers-app-edit-badge ${pinned ? "peers-app-edit-badge-unpin" : "peers-app-edit-badge-pin"}`, "aria-label": `${pinned ? "Unpin" : "Pin"} ${entry.displayName}`, title: pinned ? "Unpin" : "Pin", onClick: () => onTogglePin(entry), "data-testid": `app-${pinned ? "unpin" : "pin"}-${entry.path}`, children: pinned ? "−" : "+" }))] }));
104
105
  }
105
106
  /**
106
107
  * The badge at a tile's corner: not running beats waiting to start, which beats an update; a dev
@@ -7,6 +7,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
7
7
  const peers_sdk_1 = require("@peers-app/peers-sdk");
8
8
  const react_1 = require("react");
9
9
  const react_dom_1 = require("react-dom");
10
+ const icon_1 = require("../components/icon");
10
11
  /**
11
12
  * Group packages by the context they come from, keeping the listing's order of contexts, and
12
13
  * sort each group by the name its rows show (a one-app package shows its app's name).
@@ -126,5 +127,5 @@ function GetAppsSheet({ groupName, packages, loadError, canAdd, isMobile, onAdd,
126
127
  }
127
128
  function PackageRow({ entry, state, canAdd, onAdd, }) {
128
129
  const display = packageToAddDisplay(entry);
129
- return ((0, jsx_runtime_1.jsxs)("div", { className: "peers-get-apps-row", "data-testid": `get-apps-row-${entry.packageId}`, children: [(0, jsx_runtime_1.jsx)("span", { className: `peers-app-icon peers-app-color-${display.color}`, "aria-hidden": "true", children: (0, jsx_runtime_1.jsx)("i", { className: display.iconClassName }) }), (0, jsx_runtime_1.jsxs)("div", { className: "peers-get-apps-text", children: [(0, jsx_runtime_1.jsx)("div", { className: "peers-get-apps-name", children: display.title }), (0, jsx_runtime_1.jsxs)("div", { className: "peers-get-apps-desc", children: [display.noScreen ? (0, jsx_runtime_1.jsx)("span", { className: "peers-get-apps-tag", children: "No screen" }) : null, entry.description] }), state?.status === "failed" && ((0, jsx_runtime_1.jsx)("div", { className: "small text-danger mt-1", role: "alert", children: state.error }))] }), (0, jsx_runtime_1.jsx)("div", { className: "peers-get-apps-action", "aria-live": "polite", children: state?.status === "added" ? ((0, jsx_runtime_1.jsxs)("span", { className: "peers-get-apps-done", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-check-lg", "aria-hidden": "true" }), "Installed"] })) : entry.unsupportedHere ? ((0, jsx_runtime_1.jsx)("span", { className: "peers-get-apps-note", children: "Not on this device" })) : canAdd ? ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn peers-get-apps-add", onClick: onAdd, disabled: state?.status === "adding", "aria-label": `Add ${display.title}`, "data-package-id": entry.packageId, "data-testid": `get-apps-add-${entry.packageId}`, children: state?.status === "adding" ? "Adding…" : "Add" })) : null })] }));
130
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "peers-get-apps-row", "data-testid": `get-apps-row-${entry.packageId}`, children: [(0, jsx_runtime_1.jsx)("span", { className: `peers-app-icon peers-app-color-${display.color}`, "aria-hidden": "true", children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: display.iconClassName }) }), (0, jsx_runtime_1.jsxs)("div", { className: "peers-get-apps-text", children: [(0, jsx_runtime_1.jsx)("div", { className: "peers-get-apps-name", children: display.title }), (0, jsx_runtime_1.jsxs)("div", { className: "peers-get-apps-desc", children: [display.noScreen ? (0, jsx_runtime_1.jsx)("span", { className: "peers-get-apps-tag", children: "No screen" }) : null, entry.description] }), state?.status === "failed" && ((0, jsx_runtime_1.jsx)("div", { className: "small text-danger mt-1", role: "alert", children: state.error }))] }), (0, jsx_runtime_1.jsx)("div", { className: "peers-get-apps-action", "aria-live": "polite", children: state?.status === "added" ? ((0, jsx_runtime_1.jsxs)("span", { className: "peers-get-apps-done", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-check-lg", "aria-hidden": "true" }), "Installed"] })) : entry.unsupportedHere ? ((0, jsx_runtime_1.jsx)("span", { className: "peers-get-apps-note", children: "Not on this device" })) : canAdd ? ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn peers-get-apps-add", onClick: onAdd, disabled: state?.status === "adding", "aria-label": `Add ${display.title}`, "data-package-id": entry.packageId, "data-testid": `get-apps-add-${entry.packageId}`, children: state?.status === "adding" ? "Adding…" : "Add" })) : null })] }));
130
131
  }
@@ -4,6 +4,7 @@ exports.RemoveAppDialog = RemoveAppDialog;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
6
  const react_dom_1 = require("react-dom");
7
+ const icon_1 = require("../components/icon");
7
8
  /**
8
9
  * Asks before removing an app's package from the group, since that removes it for every device
9
10
  * there. A modal dialog: focus starts on Cancel and stays inside, and Escape cancels.
@@ -55,7 +56,7 @@ function RemoveAppDialog({ entry, otherApps, groupName, onConfirm, onCancel, })
55
56
  (0, jsx_runtime_1.jsx)("div", { className: "peers-apps-dialog-backdrop", onMouseDown: (event) => {
56
57
  if (event.target === event.currentTarget && !removing)
57
58
  onCancel();
58
- }, children: (0, jsx_runtime_1.jsxs)("div", { ref: dialogRef, className: "peers-apps-dialog text-body", role: "dialog", "aria-modal": "true", "aria-labelledby": "peers-remove-app-title", "aria-describedby": "peers-remove-app-text", onKeyDown: onKeyDown, "data-testid": "remove-app-dialog", children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-apps-dialog-head", children: [(0, jsx_runtime_1.jsx)("span", { className: `peers-app-icon peers-app-color-${entry.color}`, "aria-hidden": "true", children: (0, jsx_runtime_1.jsx)("i", { className: entry.iconClassName }) }), (0, jsx_runtime_1.jsxs)("h3", { id: "peers-remove-app-title", children: ["Remove ", name, " from ", groupName, "?"] })] }), (0, jsx_runtime_1.jsxs)("p", { id: "peers-remove-app-text", children: [name, " is removed for every device in ", groupName, ".", otherApps.length > 0 &&
59
+ }, children: (0, jsx_runtime_1.jsxs)("div", { ref: dialogRef, className: "peers-apps-dialog text-body", role: "dialog", "aria-modal": "true", "aria-labelledby": "peers-remove-app-title", "aria-describedby": "peers-remove-app-text", onKeyDown: onKeyDown, "data-testid": "remove-app-dialog", children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-apps-dialog-head", children: [(0, jsx_runtime_1.jsx)("span", { className: `peers-app-icon peers-app-color-${entry.color}`, "aria-hidden": "true", children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: entry.iconClassName }) }), (0, jsx_runtime_1.jsxs)("h3", { id: "peers-remove-app-title", children: ["Remove ", name, " from ", groupName, "?"] })] }), (0, jsx_runtime_1.jsxs)("p", { id: "peers-remove-app-text", children: [name, " is removed for every device in ", groupName, ".", otherApps.length > 0 &&
59
60
  ` Its other ${otherApps.length === 1 ? "app" : "apps"}, ${otherApps
60
61
  .map((app) => app.displayName)
61
62
  .join(", ")}, ${otherApps.length === 1 ? "goes" : "go"} with it.`, " ", "You can install it again from Get apps."] }), error && ((0, jsx_runtime_1.jsx)("div", { className: "alert alert-danger py-2 px-3 small", role: "alert", children: error })), (0, jsx_runtime_1.jsxs)("div", { className: "peers-apps-dialog-actions", children: [(0, jsx_runtime_1.jsx)("button", { ref: cancelRef, type: "button", className: "btn peers-apps-ghost", onClick: onCancel, disabled: removing, children: "Cancel" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-danger", onClick: remove, disabled: removing, "data-testid": "remove-app-confirm", children: removing ? "Removing…" : "Remove" })] })] }) }), document.body);
@@ -4,6 +4,7 @@ exports.CommandPaletteOverlay = CommandPaletteOverlay;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  // biome-ignore lint/correctness/noUnusedImports: classic JSX (`jsx: react`) needs React in scope for emit
6
6
  const react_1 = require("react");
7
+ const icon_1 = require("../components/icon");
7
8
  const hooks_1 = require("../hooks");
8
9
  const color_mode_dropdown_1 = require("../screens/settings/color-mode-dropdown");
9
10
  const tabs_state_1 = require("../tabs-layout/tabs-state");
@@ -182,7 +183,7 @@ function CommandPaletteOverlay() {
182
183
  }, onClick: () => {
183
184
  (0, command_palette_1.closeCommandPalette)();
184
185
  (0, tabs_state_1.goToTabPath)(app.path);
185
- }, onMouseEnter: () => setSelectedIndex(globalIndex), children: (0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center", children: [(0, jsx_runtime_1.jsx)("i", { className: `${app.iconClassName} me-3`, style: {
186
+ }, onMouseEnter: () => setSelectedIndex(globalIndex), children: (0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center", children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: app.iconClassName, className: "me-3", style: {
186
187
  fontSize: "16px",
187
188
  color: isSelected ? (isDark ? "#ffffff" : "#0d6efd") : "#6c757d",
188
189
  minWidth: "16px",
@@ -205,7 +206,7 @@ function CommandPaletteOverlay() {
205
206
  : ""}`, style: {
206
207
  cursor: "pointer",
207
208
  transition: "background-color 0.1s ease",
208
- }, onClick: () => (0, command_palette_1.executeCommand)(command.id), onMouseEnter: () => setSelectedIndex(globalIndex), children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center", children: [command.iconClassName && ((0, jsx_runtime_1.jsx)("i", { className: `${command.iconClassName} me-3`, style: {
209
+ }, onClick: () => (0, command_palette_1.executeCommand)(command.id), onMouseEnter: () => setSelectedIndex(globalIndex), children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center", children: [command.iconClassName && ((0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: command.iconClassName, className: "me-3", style: {
209
210
  fontSize: "16px",
210
211
  color: isSelected ? (isDark ? "#ffffff" : "#0d6efd") : "#6c757d",
211
212
  minWidth: "16px",
@@ -0,0 +1,28 @@
1
+ /** Props for {@link ColorPicker}. */
2
+ export interface IColorPickerProps {
3
+ /** The chosen color: a palette name or `#rrggbb`, or `undefined` for none. */
4
+ value: string | undefined;
5
+ /**
6
+ * Called when a color is picked: a palette name, a lowercase `#rrggbb`, or `undefined` for the
7
+ * "none" choice. A custom color is reported when the system picker closes or the hex field is
8
+ * committed, not while dragging.
9
+ */
10
+ onChange: (value: string | undefined) => void;
11
+ /**
12
+ * Offer a "none" swatch first, labelled with this ("Group's color"), for a layer that can
13
+ * leave the color to the layer below. Left out, there's no "none" choice.
14
+ */
15
+ noneLabel?: string;
16
+ /** The color "none" falls back to, drawn on its swatch. */
17
+ noneColor?: string;
18
+ /** Labels the swatch group for screen readers. Default "Color". */
19
+ label?: string;
20
+ /** Disable every control (a layer the person can't edit). */
21
+ disabled?: boolean;
22
+ }
23
+ /**
24
+ * Pick a color: the Peers palette as named swatches, then a custom color through the system
25
+ * color picker or a hex field. The swatches are a radio group: arrow keys move, and the chosen
26
+ * one shows a check, not just a border.
27
+ */
28
+ export declare function ColorPicker({ value, onChange, noneLabel, noneColor, label, disabled, }: IColorPickerProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ColorPicker = ColorPicker;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
6
+ const react_1 = require("react");
7
+ const group_look_1 = require("../groups/group-look");
8
+ /**
9
+ * Pick a color: the Peers palette as named swatches, then a custom color through the system
10
+ * color picker or a hex field. The swatches are a radio group: arrow keys move, and the chosen
11
+ * one shows a check, not just a border.
12
+ */
13
+ function ColorPicker({ value, onChange, noneLabel, noneColor, label = "Color", disabled, }) {
14
+ const theme = (0, group_look_1.useColorTheme)();
15
+ const current = (0, peers_sdk_1.parseColor)(value);
16
+ const choices = [
17
+ ...(noneLabel ? [{ key: "none", value: undefined, label: noneLabel }] : []),
18
+ ...peers_sdk_1.APP_COLORS.map((name) => ({ key: name, value: name, label: peers_sdk_1.APP_COLOR_LABELS[name] })),
19
+ ];
20
+ const selectedKey = current?.kind === "palette" ? current.value : !current ? "none" : "custom";
21
+ const refs = (0, react_1.useRef)([]);
22
+ const focusIndex = Math.max(0, choices.findIndex((choice) => choice.key === selectedKey));
23
+ const onKeyDown = (event, index) => {
24
+ const step = event.key === "ArrowRight" || event.key === "ArrowDown"
25
+ ? 1
26
+ : event.key === "ArrowLeft" || event.key === "ArrowUp"
27
+ ? -1
28
+ : 0;
29
+ if (!step)
30
+ return;
31
+ event.preventDefault();
32
+ const next = (index + step + choices.length) % choices.length;
33
+ refs.current[next]?.focus();
34
+ onChange(choices[next].value);
35
+ };
36
+ return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("div", { className: "peers-color-swatches", role: "radiogroup", "aria-label": label, children: choices.map((choice, index) => {
37
+ const checked = choice.key === selectedKey;
38
+ const shades = (0, peers_sdk_1.resolveColor)(choice.value ?? noneColor, theme);
39
+ return ((0, jsx_runtime_1.jsx)("button", { ref: (element) => {
40
+ refs.current[index] = element;
41
+ }, type: "button", role: "radio", "aria-checked": checked, "aria-label": choice.label, title: choice.label, tabIndex: index === focusIndex ? 0 : -1, disabled: disabled, className: `peers-color-swatch${choice.key === "none" ? " peers-color-swatch-none" : ""}`, onClick: () => onChange(choice.value), onKeyDown: (event) => onKeyDown(event, index), children: (0, jsx_runtime_1.jsx)("span", { style: { backgroundColor: shades?.fill, color: shades?.onFill }, children: checked ? (0, jsx_runtime_1.jsx)("i", { className: "bi bi-check-lg", "aria-hidden": true }) : null }) }, choice.key));
42
+ }) }), (0, jsx_runtime_1.jsx)(CustomColor, { value: current?.value, onChange: onChange, disabled: disabled })] }));
43
+ }
44
+ /** The system color picker and a hex field, committed on close, Enter or blur. */
45
+ function CustomColor({ value, onChange, disabled, }) {
46
+ const id = (0, react_1.useId)();
47
+ const custom = value?.startsWith("#") ? value : undefined;
48
+ const [draft, setDraft] = (0, react_1.useState)(custom ?? "");
49
+ const [pickerValue, setPickerValue] = (0, react_1.useState)(custom ?? "#808080");
50
+ const [invalid, setInvalid] = (0, react_1.useState)(false);
51
+ const pickerRef = (0, react_1.useRef)(null);
52
+ (0, react_1.useEffect)(() => {
53
+ const hex = value?.startsWith("#") ? value : undefined;
54
+ setDraft(hex ?? "");
55
+ setPickerValue(hex ?? "#808080");
56
+ setInvalid(false);
57
+ }, [value]);
58
+ // React's onChange on a color input fires while dragging; the native change event fires once,
59
+ // when the system picker closes.
60
+ (0, react_1.useEffect)(() => {
61
+ const input = pickerRef.current;
62
+ if (!input)
63
+ return;
64
+ const commit = () => {
65
+ const color = (0, peers_sdk_1.parseColor)(input.value);
66
+ if (color)
67
+ onChange(color.value);
68
+ };
69
+ input.addEventListener("change", commit);
70
+ return () => input.removeEventListener("change", commit);
71
+ }, [onChange]);
72
+ const commitDraft = () => {
73
+ if (!draft.trim()) {
74
+ setDraft(custom ?? "");
75
+ setInvalid(false);
76
+ return;
77
+ }
78
+ const text = draft.trim().startsWith("#") ? draft.trim() : `#${draft.trim()}`;
79
+ const color = (0, peers_sdk_1.parseColor)(text);
80
+ if (color?.kind !== "hex") {
81
+ setInvalid(true);
82
+ return;
83
+ }
84
+ setInvalid(false);
85
+ if (color.value !== value)
86
+ onChange(color.value);
87
+ };
88
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "peers-color-custom", children: [(0, jsx_runtime_1.jsxs)("label", { htmlFor: `${id}-hex`, className: "small text-body-secondary mb-0", children: ["Custom", custom && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-check-lg ms-1", "aria-hidden": true }), (0, jsx_runtime_1.jsx)("span", { className: "visually-hidden", children: " (selected)" })] }))] }), (0, jsx_runtime_1.jsx)("input", { ref: pickerRef, type: "color", "aria-label": "Pick a custom color", value: pickerValue, disabled: disabled, onChange: (event) => {
89
+ setPickerValue(event.target.value);
90
+ setDraft(event.target.value);
91
+ } }), (0, jsx_runtime_1.jsx)("input", { id: `${id}-hex`, type: "text", className: `form-control form-control-sm${invalid ? " is-invalid" : ""}`, placeholder: "#rrggbb", value: draft, disabled: disabled, "aria-invalid": invalid, "aria-describedby": invalid ? `${id}-error` : undefined, onChange: (event) => setDraft(event.target.value), onBlur: commitDraft, onKeyDown: (event) => {
92
+ if (event.key === "Enter") {
93
+ event.preventDefault();
94
+ commitDraft();
95
+ }
96
+ } }), invalid ? ((0, jsx_runtime_1.jsx)("span", { id: `${id}-error`, className: "small text-danger", children: "Use six hex digits, like #3a7bd5" })) : null] }));
97
+ }
@@ -1,44 +1,17 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
3
  exports.GroupSwitcher = GroupSwitcher;
37
4
  const jsx_runtime_1 = require("react/jsx-runtime");
38
5
  const peers_sdk_1 = require("@peers-app/peers-sdk");
39
- const react_1 = __importStar(require("react"));
6
+ const react_1 = require("react");
7
+ const group_appearance_dialog_1 = require("../groups/group-appearance-dialog");
8
+ const group_look_1 = require("../groups/group-look");
9
+ const groups_client_1 = require("../groups/groups-client");
40
10
  const hooks_1 = require("../hooks");
41
- const packages_ipc_1 = require("../screens/packages/packages-ipc");
11
+ const groups_ipc_1 = require("../screens/groups/groups-ipc");
12
+ const color_picker_1 = require("./color-picker");
13
+ const icon_1 = require("./icon");
14
+ const icon_picker_1 = require("./icon-picker");
42
15
  /**
43
16
  * Header dropdown for switching the active group (or the personal context) and creating a
44
17
  * new group, which also installs the default packages into it.
@@ -67,13 +40,12 @@ function GroupSwitcher({ colorMode, isMobile = false }) {
67
40
  subscription.unsubscribe();
68
41
  };
69
42
  }, [userContext]);
70
- // Use useMemo to recompute currentGroup when either currentGroupId or allGroups changes
71
- const currentGroup = react_1.default.useMemo(() => {
72
- const currentGroupId = userContext?.currentlyActiveGroupId();
73
- if (!currentGroupId)
74
- return null;
75
- return allGroups.find((g) => g.groupId === currentGroupId) || null;
76
- }, [allGroups, userContext?.currentlyActiveGroupId]);
43
+ // Both choosers change the active id when they close. Read it then, or when the list changes.
44
+ const choosingGroup = showDropdown || showCreateModal;
45
+ const currentGroup = (0, react_1.useMemo)(() => {
46
+ const groupId = userContext?.currentlyActiveGroupId();
47
+ return groupId ? allGroups.find((group) => group.groupId === groupId) : null;
48
+ }, [allGroups, userContext, choosingGroup]);
77
49
  const handleGroupSelect = (group) => {
78
50
  if (!userContext)
79
51
  return;
@@ -85,10 +57,20 @@ function GroupSwitcher({ colorMode, isMobile = false }) {
85
57
  setShowDropdown(false);
86
58
  setShowCreateModal(true);
87
59
  };
88
- const getGroupIcon = (group) => {
89
- if (!group)
90
- return "bi-person-fill"; // Personal group icon
91
- return group.iconClassName || "bi-people-fill";
60
+ const looks = (0, groups_client_1.useGroups)();
61
+ /**
62
+ * A group's icon in its color; Personal when `group` is null. An emoji keeps its own colors,
63
+ * so its group's color goes in a small dot beside it.
64
+ */
65
+ const groupIcon = (group, className) => {
66
+ const groupId = group ? group.groupId : userContext?.userId;
67
+ const look = looks?.find((entry) => entry.groupId === groupId);
68
+ const icon = look?.icon ?? (group ? group.iconClassName : "bi:person-fill");
69
+ const accent = (0, peers_sdk_1.resolveColor)(look?.color, isDark ? "dark" : "light")?.accent;
70
+ if (accent && (0, peers_sdk_1.parseDrawableIcon)(icon)?.kind === "emoji") {
71
+ return ((0, jsx_runtime_1.jsxs)("span", { className: ["d-inline-flex align-items-center", className].filter(Boolean).join(" "), children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: icon, fallback: "bi:people-fill" }), (0, jsx_runtime_1.jsx)("span", { className: "peers-color-dot peers-switcher-dot", style: { backgroundColor: accent }, "aria-hidden": true })] }));
72
+ }
73
+ return ((0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: icon, fallback: "bi:people-fill", style: { color: accent }, className: className }));
92
74
  };
93
75
  const getGroupName = (group) => {
94
76
  if (!group)
@@ -112,7 +94,7 @@ function GroupSwitcher({ colorMode, isMobile = false }) {
112
94
  }, onMouseLeave: (e) => {
113
95
  e.currentTarget.style.backgroundColor = "transparent";
114
96
  e.currentTarget.style.color = isDark ? "#adb5bd" : "var(--peers-tab-strip-color)";
115
- }, children: [(0, jsx_runtime_1.jsx)("i", { className: `${getGroupIcon(currentGroup)} ${isMobile ? "" : "me-1"}`, style: { fontSize: "14px" } }), !isMobile && ((0, jsx_runtime_1.jsx)("span", { className: "text-truncate", style: { maxWidth: "80px" }, children: getGroupName(currentGroup) })), (0, jsx_runtime_1.jsx)("i", { className: "bi-chevron-down ms-1", style: { fontSize: "10px" } })] }), showDropdown && ((0, jsx_runtime_1.jsxs)("div", { className: `dropdown-menu show position-absolute ${isDark ? "dropdown-menu-dark" : ""}`, style: {
97
+ }, children: [(0, jsx_runtime_1.jsx)("span", { style: { fontSize: "14px" }, children: groupIcon(currentGroup, isMobile ? undefined : "me-1") }), !isMobile && ((0, jsx_runtime_1.jsx)("span", { className: "text-truncate", style: { maxWidth: "80px" }, children: getGroupName(currentGroup) })), (0, jsx_runtime_1.jsx)("i", { className: "bi-chevron-down ms-1", style: { fontSize: "10px" } })] }), showDropdown && ((0, jsx_runtime_1.jsxs)("div", { className: `dropdown-menu show position-absolute ${isDark ? "dropdown-menu-dark" : ""}`, style: {
116
98
  left: 0,
117
99
  top: "100%",
118
100
  zIndex: 1000,
@@ -125,7 +107,7 @@ function GroupSwitcher({ colorMode, isMobile = false }) {
125
107
  background: "none",
126
108
  width: "100%",
127
109
  textAlign: "left",
128
- }, onClick: () => handleGroupSelect(null), children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-person-fill me-2" }), (0, jsx_runtime_1.jsx)("span", { children: "Personal" })] }), allGroups.length > 0 && (0, jsx_runtime_1.jsx)("div", { className: "dropdown-divider" }), allGroups
110
+ }, onClick: () => handleGroupSelect(null), children: [groupIcon(null, "me-2"), (0, jsx_runtime_1.jsx)("span", { children: "Personal" })] }), allGroups.length > 0 && (0, jsx_runtime_1.jsx)("div", { className: "dropdown-divider" }), allGroups
129
111
  .filter((g) => !g.disabled)
130
112
  .map((group) => ((0, jsx_runtime_1.jsxs)("button", { className: `dropdown-item d-flex align-items-center ${currentGroup?.groupId === group.groupId ? "active" : ""}`, style: {
131
113
  cursor: "pointer",
@@ -133,25 +115,25 @@ function GroupSwitcher({ colorMode, isMobile = false }) {
133
115
  background: "none",
134
116
  width: "100%",
135
117
  textAlign: "left",
136
- }, onClick: () => handleGroupSelect(group), children: [(0, jsx_runtime_1.jsx)("i", { className: `${getGroupIcon(group)} me-2` }), (0, jsx_runtime_1.jsx)("span", { className: "text-truncate", children: group.name })] }, group.groupId))), (0, jsx_runtime_1.jsx)("div", { className: "dropdown-divider" }), (0, jsx_runtime_1.jsxs)("button", { className: "dropdown-item d-flex align-items-center", style: {
118
+ }, onClick: () => handleGroupSelect(group), children: [groupIcon(group, "me-2"), (0, jsx_runtime_1.jsx)("span", { className: "text-truncate", children: group.name })] }, group.groupId))), (0, jsx_runtime_1.jsx)("div", { className: "dropdown-divider" }), (0, jsx_runtime_1.jsxs)("button", { className: "dropdown-item d-flex align-items-center", style: {
137
119
  cursor: "pointer",
138
120
  border: "none",
139
121
  background: "none",
140
122
  width: "100%",
141
123
  textAlign: "left",
142
- }, onClick: handleCreateClick, children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-plus-circle me-2" }), (0, jsx_runtime_1.jsx)("span", { children: "Create Group" })] })] })), showDropdown && ((0, jsx_runtime_1.jsx)("div", { className: "position-fixed w-100 h-100", style: { top: 0, left: 0, zIndex: 999 }, onClick: () => setShowDropdown(false) }))] }), showCreateModal && userContext && ((0, jsx_runtime_1.jsx)(CreateGroupModal, { colorMode: colorMode, userContext: userContext, onClose: () => setShowCreateModal(false), onGroupCreated: async (groupId) => {
143
- // Refresh groups list
144
- const groupsTable = (0, peers_sdk_1.Groups)(userContext.userDataContext);
145
- const groupsList = await groupsTable.list({ disabled: { $ne: true } });
146
- setAllGroups(groupsList);
147
- // Switch to new group
124
+ }, onClick: handleCreateClick, children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-plus-circle me-2" }), (0, jsx_runtime_1.jsx)("span", { children: "Create Group" })] })] })), showDropdown && ((0, jsx_runtime_1.jsx)("div", { className: "position-fixed w-100 h-100", style: { top: 0, left: 0, zIndex: 999 }, onClick: () => setShowDropdown(false) }))] }), showCreateModal && userContext && ((0, jsx_runtime_1.jsx)(CreateGroupModal, { colorMode: colorMode, onClose: () => setShowCreateModal(false), onGroupCreated: (groupId) => {
148
125
  userContext.currentlyActiveGroupId(groupId);
149
126
  setShowCreateModal(false);
150
127
  } }))] }));
151
128
  }
152
- function CreateGroupModal({ colorMode, userContext, onClose, onGroupCreated, }) {
129
+ function CreateGroupModal({ colorMode, onClose, onGroupCreated }) {
153
130
  const [groupName, setGroupName] = (0, react_1.useState)("");
154
- const [iconClassName, setIconClassName] = (0, react_1.useState)("bi-people-fill");
131
+ const [icon, setIcon] = (0, react_1.useState)();
132
+ const looks = (0, groups_client_1.useGroups)();
133
+ // A new group starts in the palette color its creator uses least.
134
+ const suggestedColor = (0, react_1.useMemo)(() => looks && (0, peers_sdk_1.leastUsedPaletteColor)(looks.map((look) => look.color)), [looks]);
135
+ const [pickedColor, setPickedColor] = (0, react_1.useState)();
136
+ const color = pickedColor ?? suggestedColor;
155
137
  const [description, setDescription] = (0, react_1.useState)("");
156
138
  const [isCreating, setIsCreating] = (0, react_1.useState)(false);
157
139
  const [error, setError] = (0, react_1.useState)(null);
@@ -170,41 +152,16 @@ function CreateGroupModal({ colorMode, userContext, onClose, onGroupCreated, })
170
152
  setIsCreating(true);
171
153
  setError(null);
172
154
  try {
173
- const groupId = (0, peers_sdk_1.newid)();
174
- const me = await (0, peers_sdk_1.getMe)();
175
- // Generate cryptographic keys for the group
176
- const groupKeys = (0, peers_sdk_1.newKeys)();
177
- // Create group data context
178
- const groupDataContext = userContext.getDataContext(groupId);
179
- // Store the validated secret under its deterministic persistent-variable ID.
180
- await (0, peers_sdk_1.saveGroupSecretKey)(userContext.userDataContext, groupId, groupKeys.secretKey, groupKeys);
181
- // Add current user to the group's users table
182
- await (0, peers_sdk_1.Users)(groupDataContext).save(me);
183
- // Set trust level for current user in the group context
184
- await (0, peers_sdk_1.setUserTrustLevel)(me.userId, peers_sdk_1.TrustLevel.Trusted, groupDataContext);
185
- // Create group in both user's and group's context
186
- const groupsTable = (0, peers_sdk_1.Groups)(userContext.userDataContext);
187
- const newGroup = await groupsTable.signAndSave({
188
- groupId,
155
+ const { groupId, warning } = await (0, groups_ipc_1.createGroupOnHost)({
189
156
  name: trimmedName,
190
157
  description: description.trim(),
191
- iconClassName: iconClassName.trim() || "bi-people-fill",
192
- founderUserId: me.userId,
193
- disabled: false,
194
- publicKey: groupKeys.publicKey,
195
- publicBoxKey: groupKeys.publicBoxKey,
196
- signature: "", // Will be set by signAndSave()
158
+ ...(color ? { color } : {}),
159
+ ...(icon ? { iconClassName: icon } : {}),
197
160
  });
198
- await (0, peers_sdk_1.Groups)(groupDataContext).signAndSave(newGroup);
199
- // Auto-install peers-core for the new group (copy from another context that
200
- // already has it, else fall back to the remote updateUrl).
201
- await (0, packages_ipc_1.packagesTools)(groupId)
202
- .then((tools) => tools.installDefaultPackages())
203
- .catch((err) => {
204
- console.error("Error auto-installing peers-core for group:", err);
205
- });
206
- // Notify parent
207
- onGroupCreated(newGroup.groupId);
161
+ onGroupCreated(groupId);
162
+ // The group exists, but its look didn't save: say so where it can be picked again.
163
+ if (warning)
164
+ (0, group_appearance_dialog_1.openGroupAppearanceDialog)(groupId, warning);
208
165
  }
209
166
  catch (err) {
210
167
  console.error("Failed to create group:", err);
@@ -217,9 +174,6 @@ function CreateGroupModal({ colorMode, userContext, onClose, onGroupCreated, })
217
174
  e.preventDefault();
218
175
  handleCreate();
219
176
  }
220
- else if (e.key === "Escape") {
221
- onClose();
222
- }
223
177
  };
224
178
  return ((0, jsx_runtime_1.jsx)("div", { className: "position-fixed w-100 h-100 d-flex align-items-start justify-content-center", style: {
225
179
  top: 0,
@@ -232,13 +186,20 @@ function CreateGroupModal({ colorMode, userContext, onClose, onGroupCreated, })
232
186
  if (e.target === e.currentTarget) {
233
187
  onClose();
234
188
  }
235
- }, children: (0, jsx_runtime_1.jsxs)("div", { className: `${isDark ? "bg-dark text-light" : "peers-surface text-body"}`, style: {
189
+ }, onKeyDown: (e) => {
190
+ if (e.key === "Escape") {
191
+ e.preventDefault();
192
+ e.stopPropagation();
193
+ onClose();
194
+ }
195
+ }, children: (0, jsx_runtime_1.jsxs)("div", {
196
+ // Scrolls when taller than the screen (theme.css), which also clips the rounded corners.
197
+ className: `peers-create-group-panel ${isDark ? "bg-dark text-light" : "peers-surface text-body"}`, "data-testid": "create-group-panel", style: {
236
198
  width: "90%",
237
199
  maxWidth: "500px",
238
200
  borderRadius: "12px",
239
201
  boxShadow: isDark ? "0 20px 40px rgba(0, 0, 0, 0.5)" : "0 20px 40px rgba(0, 0, 0, 0.1)",
240
202
  border: isDark ? "1px solid #495057" : "1px solid var(--peers-surface-border)",
241
- overflow: "hidden",
242
203
  }, children: [(0, jsx_runtime_1.jsxs)("div", { className: "p-3 border-bottom d-flex align-items-center justify-content-between", style: {
243
204
  borderBottomColor: isDark ? "#495057" : "var(--peers-surface-border)",
244
205
  }, children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-people-fill me-2", style: { fontSize: "20px" } }), (0, jsx_runtime_1.jsx)("h6", { className: "mb-0", children: "Create New Group" })] }), (0, jsx_runtime_1.jsx)("button", { className: "btn btn-sm p-0", style: {
@@ -251,16 +212,15 @@ function CreateGroupModal({ colorMode, userContext, onClose, onGroupCreated, })
251
212
  e.currentTarget.style.opacity = "1";
252
213
  }, onMouseLeave: (e) => {
253
214
  e.currentTarget.style.opacity = "0.6";
254
- }, children: (0, jsx_runtime_1.jsx)("i", { className: "bi-x" }) })] }), (0, jsx_runtime_1.jsxs)("div", { className: "p-3", children: [error && ((0, jsx_runtime_1.jsxs)("div", { className: "alert alert-danger py-2 px-3 mb-3", style: { fontSize: "14px" }, children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-exclamation-triangle me-2" }), error] })), (0, jsx_runtime_1.jsxs)("div", { className: "mb-3", children: [(0, jsx_runtime_1.jsxs)("label", { className: "form-label small mb-1", children: ["Group Name ", (0, jsx_runtime_1.jsx)("span", { className: "text-danger", children: "*" })] }), (0, jsx_runtime_1.jsx)("input", { type: "text", className: `form-control ${isDark ? "bg-dark text-light border-secondary" : ""}`, placeholder: "Enter group name", value: groupName, onChange: (e) => {
215
+ }, children: (0, jsx_runtime_1.jsx)("i", { className: "bi-x" }) })] }), (0, jsx_runtime_1.jsxs)("div", { className: "p-3", children: [error && ((0, jsx_runtime_1.jsxs)("div", { className: "alert alert-danger py-2 px-3 mb-3", style: { fontSize: "14px" }, children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-exclamation-triangle me-2" }), error] })), (0, jsx_runtime_1.jsxs)("div", { className: "mb-3", children: [(0, jsx_runtime_1.jsxs)("label", { className: "form-label small mb-1", children: ["Group Name ", (0, jsx_runtime_1.jsx)("span", { className: "text-danger", children: "*" })] }), (0, jsx_runtime_1.jsx)("input", { type: "text", className: `form-control ${isDark ? "bg-dark text-light border-secondary" : ""}`, placeholder: "Enter group name",
216
+ // biome-ignore lint/a11y/noAutofocus: the menu item that opened this modal has unmounted
217
+ autoFocus: true, value: groupName, onChange: (e) => {
255
218
  setGroupName(e.target.value);
256
219
  setError(null);
257
220
  }, onKeyDown: handleKeyDown, disabled: isCreating, maxLength: 100, style: {
258
221
  fontSize: "14px",
259
222
  backgroundColor: isDark ? "#343a40" : "var(--peers-surface-bg)",
260
- } }), (0, jsx_runtime_1.jsxs)("small", { className: "text-muted", style: { fontSize: "11px" }, children: [groupName.length, "/100 characters"] })] }), (0, jsx_runtime_1.jsxs)("div", { className: "mb-3", children: [(0, jsx_runtime_1.jsx)("label", { className: "form-label small mb-1", children: "Icon" }), (0, jsx_runtime_1.jsxs)("div", { className: "input-group", children: [(0, jsx_runtime_1.jsx)("span", { className: `input-group-text ${isDark ? "bg-dark text-light border-secondary" : ""}`, style: { backgroundColor: isDark ? "#343a40" : undefined }, children: (0, jsx_runtime_1.jsx)("i", { className: iconClassName || "bi-people-fill" }) }), (0, jsx_runtime_1.jsx)("input", { type: "text", className: `form-control ${isDark ? "bg-dark text-light border-secondary" : ""}`, placeholder: "bi-people-fill", value: iconClassName, onChange: (e) => setIconClassName(e.target.value), onKeyDown: handleKeyDown, disabled: isCreating, style: {
261
- fontSize: "14px",
262
- backgroundColor: isDark ? "#343a40" : "var(--peers-surface-bg)",
263
- } })] }), (0, jsx_runtime_1.jsx)("small", { className: "text-muted", style: { fontSize: "11px" }, children: "Bootstrap icon class name (e.g., bi-star-fill, bi-house-fill)" })] }), (0, jsx_runtime_1.jsxs)("div", { className: "mb-3", children: [(0, jsx_runtime_1.jsx)("label", { className: "form-label small mb-1", children: "Description (optional)" }), (0, jsx_runtime_1.jsx)("textarea", { className: `form-control ${isDark ? "bg-dark text-light border-secondary" : ""}`, placeholder: "Enter group description", value: description, onChange: (e) => setDescription(e.target.value), disabled: isCreating, rows: 3, maxLength: 500, style: {
223
+ } }), (0, jsx_runtime_1.jsxs)("small", { className: "text-muted", style: { fontSize: "11px" }, children: [groupName.length, "/100 characters"] })] }), (0, jsx_runtime_1.jsxs)("div", { className: "mb-3", children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center gap-2 mb-1", children: [(0, jsx_runtime_1.jsx)("span", { className: "form-label small mb-0", children: "Color and icon" }), (0, jsx_runtime_1.jsx)(group_look_1.GroupIcon, { icon: icon ?? "bi:people-fill", color: color, variant: "tile", size: "24px" })] }), (0, jsx_runtime_1.jsx)(color_picker_1.ColorPicker, { value: color, onChange: setPickedColor, label: "New group's color", disabled: isCreating }), (0, jsx_runtime_1.jsx)("div", { className: "mt-2", children: (0, jsx_runtime_1.jsx)(icon_picker_1.IconPicker, { value: icon, onChange: setIcon, disabled: isCreating }) })] }), (0, jsx_runtime_1.jsxs)("div", { className: "mb-3", children: [(0, jsx_runtime_1.jsx)("label", { className: "form-label small mb-1", children: "Description (optional)" }), (0, jsx_runtime_1.jsx)("textarea", { className: `form-control ${isDark ? "bg-dark text-light border-secondary" : ""}`, placeholder: "Enter group description", value: description, onChange: (e) => setDescription(e.target.value), disabled: isCreating, rows: 3, maxLength: 500, style: {
264
224
  fontSize: "14px",
265
225
  backgroundColor: isDark ? "#343a40" : "var(--peers-surface-bg)",
266
226
  resize: "none",
@@ -0,0 +1,20 @@
1
+ /** Props for {@link IconPicker}. */
2
+ export interface IIconPickerProps {
3
+ /** The chosen icon reference, if any. */
4
+ value: string | undefined;
5
+ /** Called with the picked icon reference (`bi:<name>` or one emoji). */
6
+ onChange: (ref: string) => void;
7
+ /** Which sections to offer. Default both. */
8
+ kinds?: ("icons" | "emoji")[];
9
+ /** Disable picking (a layer the person can't edit). */
10
+ disabled?: boolean;
11
+ /** Focus the search box when the picker mounts. */
12
+ autoFocus?: boolean;
13
+ }
14
+ /**
15
+ * Pick an icon: a search box, then results in two sections, Icons (Bootstrap) and Emoji.
16
+ * Search uses names and keywords; an emoji typed or pasted into the box can be picked as is.
17
+ * Keyboard: ↓ from the search box goes to the results, arrow keys move through them, Enter or
18
+ * Space picks. The chosen icon shows a check, not just a highlight.
19
+ */
20
+ export declare function IconPicker({ value, onChange, kinds, disabled, autoFocus, }: IIconPickerProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IconPicker = IconPicker;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
6
+ const react_1 = require("react");
7
+ const icon_1 = require("./icon");
8
+ const icon_search_1 = require("./icon-search");
9
+ /**
10
+ * Pick an icon: a search box, then results in two sections, Icons (Bootstrap) and Emoji.
11
+ * Search uses names and keywords; an emoji typed or pasted into the box can be picked as is.
12
+ * Keyboard: ↓ from the search box goes to the results, arrow keys move through them, Enter or
13
+ * Space picks. The chosen icon shows a check, not just a highlight.
14
+ */
15
+ function IconPicker({ value, onChange, kinds = ["icons", "emoji"], disabled, autoFocus, }) {
16
+ const id = (0, react_1.useId)();
17
+ const [search, setSearch] = (0, react_1.useState)("");
18
+ const [choices, setChoices] = (0, react_1.useState)();
19
+ const searchRef = (0, react_1.useRef)(null);
20
+ const resultsRef = (0, react_1.useRef)(null);
21
+ (0, react_1.useEffect)(() => {
22
+ let cancelled = false;
23
+ void (0, icon_search_1.loadIconChoices)().then((loaded) => {
24
+ if (!cancelled)
25
+ setChoices(loaded);
26
+ });
27
+ return () => {
28
+ cancelled = true;
29
+ };
30
+ }, []);
31
+ (0, react_1.useEffect)(() => {
32
+ if (autoFocus)
33
+ searchRef.current?.focus();
34
+ }, [autoFocus]);
35
+ const selected = (0, peers_sdk_1.parseDrawableIcon)(value);
36
+ // A disabled search can't be edited to reveal a selection outside the suggested icons.
37
+ const query = disabled
38
+ ? selected?.kind === "bootstrap"
39
+ ? selected.name
40
+ : (selected?.ref ?? "")
41
+ : search;
42
+ const results = (0, react_1.useMemo)(() => (0, icon_search_1.searchIconChoices)(choices ?? { icons: [], emoji: [] }, query), [choices, query]);
43
+ const sections = [
44
+ { key: "icons", title: "Icons", list: results.icons },
45
+ { key: "emoji", title: "Emoji", list: results.emoji },
46
+ ].filter((section) => kinds.includes(section.key));
47
+ const shown = sections.flatMap((section) => section.list);
48
+ const buttons = () => Array.from(resultsRef.current?.querySelectorAll("button.peers-icon-choice") ?? []);
49
+ const onResultKeyDown = (event) => {
50
+ const vertical = event.key === "ArrowDown" || event.key === "ArrowUp";
51
+ if (!vertical && event.key !== "ArrowRight" && event.key !== "ArrowLeft")
52
+ return;
53
+ event.preventDefault();
54
+ const all = buttons();
55
+ const current = event.currentTarget;
56
+ const step = event.key === "ArrowUp" || event.key === "ArrowLeft" ? -1 : 1;
57
+ let next = all.indexOf(current) + step;
58
+ if (vertical) {
59
+ // Each section starts a fresh row, even when the previous section ended mid-row.
60
+ const top = current.offsetTop;
61
+ while (all[next]?.offsetTop === top)
62
+ next += step;
63
+ const adjacent = all[next];
64
+ if (adjacent) {
65
+ const row = adjacent.offsetTop;
66
+ const left = current.offsetLeft;
67
+ while (all[next + step]?.offsetTop === row &&
68
+ Math.abs(all[next + step].offsetLeft - left) < Math.abs(all[next].offsetLeft - left)) {
69
+ next += step;
70
+ }
71
+ }
72
+ }
73
+ if (next < 0) {
74
+ searchRef.current?.focus();
75
+ return;
76
+ }
77
+ all[Math.min(next, all.length - 1)]?.focus();
78
+ };
79
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "peers-icon-picker", children: [(0, jsx_runtime_1.jsx)("input", { ref: searchRef, type: "search", className: "form-control form-control-sm mb-2", placeholder: kinds.includes("emoji") ? "Search icons and emoji" : "Search icons", "aria-label": kinds.includes("emoji") ? "Search icons and emoji" : "Search icons", "aria-controls": `${id}-results`, value: query, disabled: disabled, onChange: (event) => setSearch(event.target.value), onKeyDown: (event) => {
80
+ if (event.key === "ArrowDown") {
81
+ event.preventDefault();
82
+ buttons()[0]?.focus();
83
+ }
84
+ else if (event.key === "Enter") {
85
+ event.preventDefault();
86
+ const first = shown[0];
87
+ if (first && !disabled)
88
+ onChange(first.ref);
89
+ }
90
+ } }), (0, jsx_runtime_1.jsxs)("div", { id: `${id}-results`, ref: resultsRef, className: "peers-icon-results", children: [!choices ? (0, jsx_runtime_1.jsx)("div", { className: "peers-icon-empty", children: "Loading\u2026" }) : null, choices && !shown.length ? ((0, jsx_runtime_1.jsxs)("div", { className: "peers-icon-empty", children: ["No icons match \u201C", query.trim(), "\u201D.", " ", kinds.includes("emoji") ? "Try another word, or paste an emoji." : "Try another word."] })) : null, sections.map((section) => section.list.length ? ((0, jsx_runtime_1.jsxs)("section", { "aria-labelledby": `${id}-${section.key}`, children: [(0, jsx_runtime_1.jsx)("div", { id: `${id}-${section.key}`, className: "peers-look-section-title", children: section.title }), (0, jsx_runtime_1.jsx)("div", { className: "peers-icon-grid", role: "listbox", "aria-labelledby": `${id}-${section.key}`, children: section.list.map((choice) => ((0, jsx_runtime_1.jsx)(IconChoice, { choice: choice, selected: choice.ref === selected?.ref, disabled: disabled, onPick: () => onChange(choice.ref), onKeyDown: onResultKeyDown }, choice.ref))) })] }, section.key)) : null), choices &&
91
+ !choices.complete &&
92
+ !choices.emoji.length &&
93
+ kinds.includes("emoji") &&
94
+ !results.emoji.length ? ((0, jsx_runtime_1.jsx)("div", { className: "peers-icon-empty", children: "Emoji search isn't available; paste an emoji above." })) : null] })] }));
95
+ }
96
+ function IconChoice({ choice, selected, disabled, onPick, onKeyDown, }) {
97
+ return ((0, jsx_runtime_1.jsxs)("button", { type: "button", role: "option", "aria-selected": selected, "aria-label": choice.label, title: choice.label, className: "peers-icon-choice", disabled: disabled, onClick: onPick, onKeyDown: onKeyDown, children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: choice.ref }), selected ? ((0, jsx_runtime_1.jsx)("span", { className: "peers-icon-choice-check", "aria-hidden": true, children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-check" }) })) : null] }));
98
+ }