@peers-app/peers-ui 0.33.18 → 0.33.20

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 (59) 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/command-palette/command-palette.d.ts +47 -0
  6. package/dist/command-palette/command-palette.js +42 -9
  7. package/dist/components/color-picker.d.ts +28 -0
  8. package/dist/components/color-picker.js +97 -0
  9. package/dist/components/group-switcher.d.ts +3 -2
  10. package/dist/components/group-switcher.js +74 -101
  11. package/dist/components/icon-picker.d.ts +20 -0
  12. package/dist/components/icon-picker.js +98 -0
  13. package/dist/components/icon-search.d.ts +60 -0
  14. package/dist/components/icon-search.js +227 -0
  15. package/dist/components/icon.d.ts +35 -0
  16. package/dist/components/icon.js +34 -0
  17. package/dist/components/markdown-editor/mention-preview-card.js +2 -1
  18. package/dist/components/markdown-editor/mentions-plugin.js +2 -1
  19. package/dist/groups/group-appearance-dialog.d.ts +45 -0
  20. package/dist/groups/group-appearance-dialog.js +239 -0
  21. package/dist/groups/group-look.d.ts +45 -0
  22. package/dist/groups/group-look.js +47 -0
  23. package/dist/groups/groups-client.d.ts +29 -0
  24. package/dist/groups/groups-client.js +81 -0
  25. package/dist/groups/index.d.ts +3 -0
  26. package/dist/groups/index.js +15 -0
  27. package/dist/icon-index/bootstrap-icons.json +1 -0
  28. package/dist/icon-index/emoji.json +1 -0
  29. package/dist/index.d.ts +5 -0
  30. package/dist/index.js +8 -1
  31. package/dist/mentions/mention-chip.js +2 -1
  32. package/dist/mentions/mention-chooser.js +2 -1
  33. package/dist/root-layout/layouts/full-screen-layout.js +2 -1
  34. package/dist/screens/groups/group-details.js +16 -2
  35. package/dist/screens/groups/group-list.js +37 -43
  36. package/dist/screens/groups/groups-ipc.d.ts +15 -0
  37. package/dist/screens/groups/groups-ipc.js +28 -0
  38. package/dist/screens/packages/package-waiting.js +4 -3
  39. package/dist/screens/peer-types/peer-type-details.d.ts +9 -1
  40. package/dist/screens/peer-types/peer-type-details.js +16 -13
  41. package/dist/screens/peer-types/peer-type-list.d.ts +1 -0
  42. package/dist/screens/peer-types/peer-type-list.js +3 -1
  43. package/dist/screens/search/global-search.js +2 -1
  44. package/dist/tabs-layout/tab-color.d.ts +9 -2
  45. package/dist/tabs-layout/tab-color.js +14 -4
  46. package/dist/tabs-layout/tab-order.d.ts +51 -0
  47. package/dist/tabs-layout/tab-order.js +70 -0
  48. package/dist/tabs-layout/tab-switcher-overlay.d.ts +16 -0
  49. package/dist/tabs-layout/tab-switcher-overlay.js +68 -0
  50. package/dist/tabs-layout/tab-switcher.d.ts +64 -0
  51. package/dist/tabs-layout/tab-switcher.js +150 -0
  52. package/dist/tabs-layout/tabs-layout.d.ts +3 -1
  53. package/dist/tabs-layout/tabs-layout.js +92 -47
  54. package/dist/tabs-layout/tabs-state.d.ts +34 -13
  55. package/dist/tabs-layout/tabs-state.js +104 -31
  56. package/dist/theme.css +327 -0
  57. package/dist/ui-defaults/list-screen.d.ts +1 -0
  58. package/dist/ui-defaults/list-screen.js +3 -1
  59. package/package.json +4 -4
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SUGGESTED_ICONS = void 0;
4
+ exports.configureIconSearchIndexes = configureIconSearchIndexes;
5
+ exports.loadIconChoices = loadIconChoices;
6
+ exports.searchIconChoices = searchIconChoices;
7
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
8
+ let sources = {};
9
+ let loading;
10
+ /**
11
+ * Say where the icon picker's search indexes are. Hosts call this once at startup (the PWA with
12
+ * Vite `?url` imports, Electron with its bundled copies). Without it the picker still works:
13
+ * icons are found by name, and an emoji typed or pasted into the search box can be picked.
14
+ *
15
+ * @param next - Index sources; each one given replaces the one before.
16
+ */
17
+ function configureIconSearchIndexes(next) {
18
+ sources = { ...sources, ...next };
19
+ loading = undefined;
20
+ }
21
+ async function loadIndex(source) {
22
+ if (!source)
23
+ return undefined;
24
+ if (typeof source === "function")
25
+ return source();
26
+ const response = await fetch(source);
27
+ if (!response.ok)
28
+ throw new Error(`${source}: ${response.status}`);
29
+ return response.json();
30
+ }
31
+ /** "house-fill" → "House fill". */
32
+ function labelForName(name) {
33
+ const words = name.replace(/-/g, " ");
34
+ return words.charAt(0).toUpperCase() + words.slice(1);
35
+ }
36
+ function bootstrapChoices(index) {
37
+ const data = index;
38
+ const categories = Array.isArray(data?.categories) ? data.categories : [];
39
+ const indexed = new Map();
40
+ if (Array.isArray(data?.icons)) {
41
+ for (const entry of data.icons) {
42
+ if (!Array.isArray(entry) || typeof entry[0] !== "string")
43
+ continue;
44
+ const [name, tags, category] = entry;
45
+ const categoryName = typeof category === "number" ? categories[category] : undefined;
46
+ indexed.set(name, [typeof tags === "string" ? tags : "", typeof categoryName === "string" ? categoryName : ""]
47
+ .join(" ")
48
+ .toLowerCase());
49
+ }
50
+ }
51
+ // The SDK's name list decides what's an icon; the index only adds words.
52
+ return (0, peers_sdk_1.listBootstrapIconNames)().map((name) => ({
53
+ ref: `bi:${name}`,
54
+ label: labelForName(name),
55
+ words: `${name.replace(/-/g, " ")} ${indexed.get(name) ?? ""}`.trim(),
56
+ section: "icons",
57
+ }));
58
+ }
59
+ function emojiChoices(index) {
60
+ const data = index;
61
+ if (!Array.isArray(data?.emoji))
62
+ return [];
63
+ const groups = Array.isArray(data.groups) ? data.groups : [];
64
+ const choices = [];
65
+ for (const entry of data.emoji) {
66
+ if (!Array.isArray(entry))
67
+ continue;
68
+ const [emoji, label, tags, group] = entry;
69
+ // An index entry is shown only if it parses as one emoji here too.
70
+ if (!(0, peers_sdk_1.isSingleEmoji)(emoji) || typeof label !== "string")
71
+ continue;
72
+ const groupName = typeof group === "number" ? groups[group] : undefined;
73
+ choices.push({
74
+ ref: emoji,
75
+ label,
76
+ words: [label, typeof tags === "string" ? tags : "", groupName ?? ""].join(" ").toLowerCase(),
77
+ section: "emoji",
78
+ });
79
+ }
80
+ return choices;
81
+ }
82
+ /**
83
+ * Load every choice the picker offers, once; later calls share the result. An index that fails
84
+ * to load is left out (and tried again next time) rather than failing the picker.
85
+ */
86
+ function loadIconChoices() {
87
+ loading ??= (async () => {
88
+ const [bootstrap, emoji] = await Promise.allSettled([
89
+ loadIndex(sources.bootstrap),
90
+ loadIndex(sources.emoji),
91
+ ]);
92
+ const complete = bootstrap.status === "fulfilled" &&
93
+ bootstrap.value !== undefined &&
94
+ emoji.status === "fulfilled" &&
95
+ emoji.value !== undefined;
96
+ if (!complete)
97
+ loading = undefined;
98
+ return {
99
+ icons: bootstrapChoices(bootstrap.status === "fulfilled" ? bootstrap.value : undefined),
100
+ emoji: emojiChoices(emoji.status === "fulfilled" ? emoji.value : undefined),
101
+ complete,
102
+ };
103
+ })();
104
+ return loading;
105
+ }
106
+ /** Icons offered before anything is typed: ones that suit a group or a place. */
107
+ exports.SUGGESTED_ICONS = [
108
+ "people-fill",
109
+ "person-fill",
110
+ "house-fill",
111
+ "house-heart-fill",
112
+ "briefcase-fill",
113
+ "building",
114
+ "shop",
115
+ "heart-fill",
116
+ "star-fill",
117
+ "lightning-charge-fill",
118
+ "rocket-takeoff-fill",
119
+ "globe2",
120
+ "tree-fill",
121
+ "flower1",
122
+ "sun-fill",
123
+ "moon-stars-fill",
124
+ "cup-hot-fill",
125
+ "egg-fried",
126
+ "cart-fill",
127
+ "basket-fill",
128
+ "book-fill",
129
+ "mortarboard-fill",
130
+ "lightbulb-fill",
131
+ "code-slash",
132
+ "terminal-fill",
133
+ "cpu-fill",
134
+ "controller",
135
+ "music-note-beamed",
136
+ "camera-fill",
137
+ "palette-fill",
138
+ "brush-fill",
139
+ "hammer",
140
+ "tools",
141
+ "wrench-adjustable",
142
+ "car-front-fill",
143
+ "bicycle",
144
+ "airplane-fill",
145
+ "train-front-fill",
146
+ "geo-alt-fill",
147
+ "map-fill",
148
+ "calendar-event-fill",
149
+ "chat-dots-fill",
150
+ "envelope-fill",
151
+ "bell-fill",
152
+ "shield-fill",
153
+ "trophy-fill",
154
+ "flag-fill",
155
+ "bookmark-fill",
156
+ "piggy-bank-fill",
157
+ "cash-coin",
158
+ "hospital-fill",
159
+ "heart-pulse-fill",
160
+ "bandaid-fill",
161
+ "balloon-heart-fill",
162
+ "gift-fill",
163
+ "emoji-smile-fill",
164
+ "bug-fill",
165
+ ];
166
+ /** How well one choice matches the query's words; 0 means it doesn't. */
167
+ function score(choice, terms, name, queryName) {
168
+ if (name === queryName)
169
+ return Number.POSITIVE_INFINITY;
170
+ let total = 0;
171
+ const words = choice.words.split(" ");
172
+ for (const term of terms) {
173
+ if (name.startsWith(term))
174
+ total += name === term ? 100 : 40;
175
+ else if (words.some((word) => word === term))
176
+ total += 25;
177
+ else if (words.some((word) => word.startsWith(term)))
178
+ total += 12;
179
+ else if (choice.words.includes(term))
180
+ total += 4;
181
+ else
182
+ return 0;
183
+ }
184
+ // Shorter names first among equals: "house" before "house-heart-fill".
185
+ return total - name.length / 100;
186
+ }
187
+ /**
188
+ * The choices matching a query, best first, each section up to `limit`. Every word of the query
189
+ * must match the start of one of the choice's words, or appear in them. A query that is itself
190
+ * an icon reference or one emoji (typed or pasted) is offered first.
191
+ *
192
+ * @param choices - From {@link loadIconChoices}.
193
+ * @param query - What the person typed.
194
+ * @param limit - Most results per section.
195
+ */
196
+ function searchIconChoices(choices, query, limit = 120) {
197
+ const text = query.trim();
198
+ const direct = (0, peers_sdk_1.parseDrawableIcon)(text);
199
+ if (direct?.kind === "emoji") {
200
+ const known = choices.emoji.find((choice) => choice.ref === direct.ref);
201
+ return {
202
+ icons: [],
203
+ emoji: [known ?? { ref: direct.ref, label: direct.ref, words: "", section: "emoji" }],
204
+ };
205
+ }
206
+ const terms = (direct?.kind === "bootstrap" ? direct.name : text.toLowerCase().replace(/^bi[:-]/, ""))
207
+ .split(/[\s-]+/)
208
+ .filter(Boolean);
209
+ if (!terms.length) {
210
+ const byRef = new Map(choices.icons.map((choice) => [choice.ref, choice]));
211
+ return {
212
+ icons: exports.SUGGESTED_ICONS.map((name) => byRef.get(`bi:${name}`)).filter((choice) => Boolean(choice)),
213
+ emoji: choices.emoji.slice(0, limit),
214
+ };
215
+ }
216
+ const queryName = terms.join(" ");
217
+ const rank = (list) => list
218
+ .map((choice) => ({
219
+ choice,
220
+ score: score(choice, terms, choice.section === "icons" ? choice.ref.slice(3).replace(/-/g, " ") : choice.label, queryName),
221
+ }))
222
+ .filter((entry) => entry.score > 0)
223
+ .sort((a, b) => b.score - a.score)
224
+ .slice(0, limit)
225
+ .map((entry) => entry.choice);
226
+ return { icons: rank(choices.icons), emoji: rank(choices.emoji) };
227
+ }
@@ -0,0 +1,35 @@
1
+ import type React from "react";
2
+ /** Props for {@link Icon}; other attributes (`title`, `data-*`) go on the element. */
3
+ export interface IIconProps extends Omit<React.HTMLAttributes<HTMLElement>, "children" | "className" | "style"> {
4
+ /**
5
+ * An icon reference (`bi:house-fill`, one emoji) or a legacy Bootstrap class string
6
+ * (`bi bi-house-fill`). Anything else, including another icon set's reference, draws
7
+ * {@link fallback}.
8
+ */
9
+ icon: string | undefined | null;
10
+ /** What to draw when `icon` isn't an icon this Peers can draw. Default `bi:app`. */
11
+ fallback?: string;
12
+ /**
13
+ * What a screen reader says. Without one the icon is hidden from screen readers, so a
14
+ * decorative icon beside a name isn't read out before it.
15
+ */
16
+ label?: string;
17
+ /** Layout classes from code (`me-2`, `fs-5`), never from stored data. */
18
+ className?: string;
19
+ /** Inline style from code, such as a color. */
20
+ style?: React.CSSProperties;
21
+ }
22
+ /**
23
+ * Draw an icon reference: a Bootstrap glyph, an emoji as text, or the fallback for anything else.
24
+ * Sized like the text around it. Use it for every icon that comes from data (a group's, an app
25
+ * nav's, a mention source's), so a stored value never becomes a class name or markup.
26
+ */
27
+ export declare function Icon({ icon, fallback, label, className, style, ...rest }: IIconProps): import("react/jsx-runtime").JSX.Element;
28
+ /**
29
+ * The CSS class string for an icon reference's Bootstrap glyph, for the few places that need a
30
+ * class rather than an element. Emoji and unknown icons give the fallback's class.
31
+ *
32
+ * @param icon - An icon reference or legacy class string.
33
+ * @param fallback - Drawn instead of anything that isn't a Bootstrap icon. Default `bi:app`.
34
+ */
35
+ export declare function iconClassFor(icon: string | undefined | null, fallback?: string): string;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Icon = Icon;
4
+ exports.iconClassFor = iconClassFor;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
7
+ /**
8
+ * Draw an icon reference: a Bootstrap glyph, an emoji as text, or the fallback for anything else.
9
+ * Sized like the text around it. Use it for every icon that comes from data (a group's, an app
10
+ * nav's, a mention source's), so a stored value never becomes a class name or markup.
11
+ */
12
+ function Icon({ icon, fallback = "bi:app", label, className, style, ...rest }) {
13
+ const parsed = (0, peers_sdk_1.parseDrawableIcon)(icon) ?? (0, peers_sdk_1.parseDrawableIcon)(fallback);
14
+ const a11y = label ? { role: "img", "aria-label": label } : { "aria-hidden": true };
15
+ if (parsed?.kind === "emoji") {
16
+ return ((0, jsx_runtime_1.jsx)("span", { className: ["peers-icon-emoji", className].filter(Boolean).join(" "), style: style, ...rest, ...a11y, children: parsed.ref }));
17
+ }
18
+ const name = parsed?.kind === "bootstrap" ? parsed.name : "app";
19
+ return ((0, jsx_runtime_1.jsx)("i", { className: ["bi", `bi-${name}`, className].filter(Boolean).join(" "), style: style, ...rest, ...a11y }));
20
+ }
21
+ /**
22
+ * The CSS class string for an icon reference's Bootstrap glyph, for the few places that need a
23
+ * class rather than an element. Emoji and unknown icons give the fallback's class.
24
+ *
25
+ * @param icon - An icon reference or legacy class string.
26
+ * @param fallback - Drawn instead of anything that isn't a Bootstrap icon. Default `bi:app`.
27
+ */
28
+ function iconClassFor(icon, fallback = "bi:app") {
29
+ const parsed = (0, peers_sdk_1.parseDrawableIcon)(icon);
30
+ if (parsed?.kind === "bootstrap")
31
+ return `bi bi-${parsed.name}`;
32
+ const backup = (0, peers_sdk_1.parseDrawableIcon)(fallback);
33
+ return backup?.kind === "bootstrap" ? `bi bi-${backup.name}` : "bi bi-app";
34
+ }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MentionPreviewCard = MentionPreviewCard;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const icon_1 = require("../icon");
5
6
  /**
6
7
  * The picker's card for the highlighted result, so the user can tell similar titles apart: what
7
8
  * it is, its title and status, its group, and the start of its text when its source declares a
@@ -26,5 +27,5 @@ function MentionPreviewCard({ result, showPackage, }) {
26
27
  ]
27
28
  .filter(Boolean)
28
29
  .join(" · ");
29
- return ((0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-preview", "aria-live": "polite", children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-preview-kind", children: [result.kind === "user" ? ((0, jsx_runtime_1.jsx)("span", { "aria-hidden": true, children: "@" })) : ((0, jsx_runtime_1.jsx)("i", { className: result.iconClassName ?? "bi bi-link-45deg", "aria-hidden": true })), (0, jsx_runtime_1.jsx)("span", { children: what })] }), (0, jsx_runtime_1.jsx)("div", { className: `peers-mention-preview-title${result.done ? " peers-mention-done" : ""}`, children: result.title || result.kindLabel }), where ? (0, jsx_runtime_1.jsx)("div", { className: "peers-mention-preview-where", children: where }) : null, result.preview ? (0, jsx_runtime_1.jsx)("p", { className: "peers-mention-preview-text", children: result.preview }) : null, unknown ? ((0, jsx_runtime_1.jsx)("p", { className: "peers-mention-preview-text", children: "It's linked by id, and shows as a dotted chip until a record with this id turns up in a group you're in." })) : null] }));
30
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-preview", "aria-live": "polite", children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-preview-kind", children: [result.kind === "user" ? ((0, jsx_runtime_1.jsx)("span", { "aria-hidden": true, children: "@" })) : ((0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: result.iconClassName, fallback: "bi:link-45deg" })), (0, jsx_runtime_1.jsx)("span", { children: what })] }), (0, jsx_runtime_1.jsx)("div", { className: `peers-mention-preview-title${result.done ? " peers-mention-done" : ""}`, children: result.title || result.kindLabel }), where ? (0, jsx_runtime_1.jsx)("div", { className: "peers-mention-preview-where", children: where }) : null, result.preview ? (0, jsx_runtime_1.jsx)("p", { className: "peers-mention-preview-text", children: result.preview }) : null, unknown ? ((0, jsx_runtime_1.jsx)("p", { className: "peers-mention-preview-text", children: "It's linked by id, and shows as a dotted chip until a record with this id turns up in a group you're in." })) : null] }));
30
31
  }
@@ -50,6 +50,7 @@ const react_1 = require("react");
50
50
  const ReactDOM = __importStar(require("react-dom"));
51
51
  const use_observable_1 = require("../../hooks/use-observable");
52
52
  const mentions_client_1 = require("../../mentions/mentions-client");
53
+ const icon_1 = require("../icon");
53
54
  const mention_node_1 = require("./mention-node");
54
55
  const mention_preview_card_1 = require("./mention-preview-card");
55
56
  // ---- Finding a query: a trigger, at the start of a word, then what's typed up to the caret. ----
@@ -253,7 +254,7 @@ function MentionsTypeaheadMenuItem({ index, isSelected, onClick, onMouseEnter, o
253
254
  const { result } = option;
254
255
  const otherGroup = !!result.groupId && result.groupId !== docGroup;
255
256
  const detail = details(option, docGroup);
256
- return ((0, jsx_runtime_1.jsxs)("li", { tabIndex: -1, className: `peers-mention-menu-item${isSelected ? " is-selected" : ""}${otherGroup ? " is-other-group" : ""}`, ref: option.setRefElement, "aria-selected": isSelected, id: `typeahead-item-${index}`, onMouseEnter: onMouseEnter, onClick: onClick, "data-kind": result.kind, "data-id": result.id, children: [(0, jsx_runtime_1.jsx)("span", { className: "peers-mention-menu-icon", "aria-hidden": true, children: result.kind === "user" ? ("@") : ((0, jsx_runtime_1.jsx)("i", { className: result.iconClassName ?? "bi bi-link-45deg" })) }), (0, jsx_runtime_1.jsxs)("span", { className: "peers-mention-menu-text", children: [(0, jsx_runtime_1.jsx)("span", { className: `peers-mention-menu-title${result.done ? " peers-mention-done" : ""}`, children: result.title || result.kindLabel }), detail && (0, jsx_runtime_1.jsx)("span", { className: "peers-mention-menu-detail", children: detail })] })] }, option.key));
257
+ return ((0, jsx_runtime_1.jsxs)("li", { tabIndex: -1, className: `peers-mention-menu-item${isSelected ? " is-selected" : ""}${otherGroup ? " is-other-group" : ""}`, ref: option.setRefElement, "aria-selected": isSelected, id: `typeahead-item-${index}`, onMouseEnter: onMouseEnter, onClick: onClick, "data-kind": result.kind, "data-id": result.id, children: [(0, jsx_runtime_1.jsx)("span", { className: "peers-mention-menu-icon", "aria-hidden": true, children: result.kind === "user" ? ("@") : ((0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: result.iconClassName, fallback: "bi:link-45deg" })) }), (0, jsx_runtime_1.jsxs)("span", { className: "peers-mention-menu-text", children: [(0, jsx_runtime_1.jsx)("span", { className: `peers-mention-menu-title${result.done ? " peers-mention-done" : ""}`, children: result.title || result.kindLabel }), detail && (0, jsx_runtime_1.jsx)("span", { className: "peers-mention-menu-detail", children: detail })] })] }, option.key));
257
258
  }
258
259
  /** Takes a result as soon as it's shown: a pasted id that found one record, or none. */
259
260
  function AutoPick({ pick }) {
@@ -0,0 +1,45 @@
1
+ import { type GroupAppearanceLayer } from "@peers-app/peers-sdk";
2
+ /** Props for {@link GroupAppearanceDialog}. */
3
+ export interface IGroupAppearanceDialogProps {
4
+ /** The group, or the person's user id for Personal. */
5
+ groupId: string;
6
+ /** Called when the dialog closes. */
7
+ onClose: () => void;
8
+ /** A warning to show when it opens, such as why a new group's look wasn't saved. */
9
+ notice?: string;
10
+ /**
11
+ * The layer it opens on. `everyone` opens there only for the group's admins; anyone else,
12
+ * and Personal, get `mine`. Default `mine`, so a pick changes only the person's own look
13
+ * unless they choose For everyone.
14
+ */
15
+ layer?: GroupAppearanceLayer;
16
+ }
17
+ /**
18
+ * Edit a group's color and icon. "For everyone" is the group's default: its admins edit it,
19
+ * everyone else sees it read-only. "Just for me" is the person's own override, seen only on
20
+ * their devices, with a reset. Personal has only "Just for me". It opens on "Just for me"
21
+ * unless `layer` asks for "For everyone" and the person is an admin. The header previews the
22
+ * chosen layer, and "For everyone" says when the person's own look hides it. Each pick saves at
23
+ * once, and picks made while a save is running are kept. Escape closes; focus starts in the
24
+ * dialog and stays there.
25
+ */
26
+ export declare function GroupAppearanceDialog(props: IGroupAppearanceDialogProps): import("react/jsx-runtime").JSX.Element;
27
+ /** Options for {@link openGroupAppearanceDialog}. */
28
+ export interface IOpenGroupAppearanceOptions {
29
+ /** A warning to show in the dialog, such as why a new group's look wasn't saved. */
30
+ notice?: string;
31
+ /**
32
+ * The layer to open on: `mine` (default) or, for the group's admins, `everyone`. Peers' group
33
+ * details and new-group flows open on `everyone`; everywhere else opens on `mine`.
34
+ */
35
+ layer?: GroupAppearanceLayer;
36
+ }
37
+ /**
38
+ * Open the color-and-icon dialog for a group, above every screen. Peers opens it from the group
39
+ * switcher and group details; a package can too, instead of saving a look itself. Focus returns
40
+ * to the element that had it.
41
+ *
42
+ * @param groupId - The group, or the person's user id for Personal.
43
+ * @param options - A notice to show, and the layer to open on (Just for me by default).
44
+ */
45
+ export declare function openGroupAppearanceDialog(groupId: string, options?: IOpenGroupAppearanceOptions): void;
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GroupAppearanceDialog = GroupAppearanceDialog;
4
+ exports.openGroupAppearanceDialog = openGroupAppearanceDialog;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
7
+ const react_1 = require("react");
8
+ const react_dom_1 = require("react-dom");
9
+ const color_picker_1 = require("../components/color-picker");
10
+ const icon_picker_1 = require("../components/icon-picker");
11
+ const global_overlays_1 = require("../root-layout/global-overlays");
12
+ const group_look_1 = require("./group-look");
13
+ const groups_client_1 = require("./groups-client");
14
+ /** The look a layer shows with nothing set in it: the layer below, then the fallback. */
15
+ function inherited(details, layer) {
16
+ if (layer === "everyone" || details.personal) {
17
+ return (0, peers_sdk_1.fallbackGroupAppearance)(details.groupId, details.personal);
18
+ }
19
+ return (0, peers_sdk_1.resolveGroupAppearance)({
20
+ groupId: details.groupId,
21
+ personal: false,
22
+ everyone: details.everyone,
23
+ });
24
+ }
25
+ /**
26
+ * The look the header previews for a layer: what everyone sees on For everyone (the group's
27
+ * look without anyone's own), and what the person sees on Just for me. Kept current with picks
28
+ * that are still saving.
29
+ */
30
+ function previewed(details, layer) {
31
+ return (0, peers_sdk_1.resolveGroupAppearance)({
32
+ groupId: details.groupId,
33
+ personal: details.personal,
34
+ everyone: details.everyone,
35
+ mine: layer === "mine" ? details.mine : undefined,
36
+ });
37
+ }
38
+ /** What the person's own look hides on For everyone, as a sentence, or "" when it hides nothing. */
39
+ function hiddenByMine(mine) {
40
+ if (mine.color && mine.icon) {
41
+ return "You've set your own color and icon for this group, so you see them instead of these.";
42
+ }
43
+ if (mine.color)
44
+ return "You've set your own color for this group, so you see it instead.";
45
+ if (mine.icon)
46
+ return "You've set your own icon for this group, so you see it instead.";
47
+ return "";
48
+ }
49
+ /**
50
+ * Edit a group's color and icon. "For everyone" is the group's default: its admins edit it,
51
+ * everyone else sees it read-only. "Just for me" is the person's own override, seen only on
52
+ * their devices, with a reset. Personal has only "Just for me". It opens on "Just for me"
53
+ * unless `layer` asks for "For everyone" and the person is an admin. The header previews the
54
+ * chosen layer, and "For everyone" says when the person's own look hides it. Each pick saves at
55
+ * once, and picks made while a save is running are kept. Escape closes; focus starts in the
56
+ * dialog and stays there.
57
+ */
58
+ function GroupAppearanceDialog(props) {
59
+ return (0, jsx_runtime_1.jsx)(GroupAppearanceEditor, { ...props }, props.groupId);
60
+ }
61
+ function GroupAppearanceEditor({ groupId, onClose, notice, layer: requested = "mine", }) {
62
+ const group = (0, groups_client_1.useGroup)(groupId);
63
+ const [details, setDetails] = (0, react_1.useState)();
64
+ const [layer, setLayer] = (0, react_1.useState)("mine");
65
+ const [error, setError] = (0, react_1.useState)("");
66
+ const [warning, setWarning] = (0, react_1.useState)(notice ?? "");
67
+ const [saving, setSaving] = (0, react_1.useState)(false);
68
+ const queue = (0, react_1.useRef)(Promise.resolve());
69
+ /** The latest save's number, and the first failure since the last settled save. */
70
+ const burst = (0, react_1.useRef)({ latest: 0, failed: "" });
71
+ const dialogRef = (0, react_1.useRef)(null);
72
+ (0, react_1.useEffect)(() => {
73
+ let cancelled = false;
74
+ void (0, groups_client_1.groupsTools)()
75
+ .then((tools) => tools.getGroupAppearance({ groupId }))
76
+ .then((loaded) => {
77
+ if (cancelled)
78
+ return;
79
+ setDetails(loaded);
80
+ setLayer(requested === "everyone" && !loaded.personal && loaded.canEditEveryone
81
+ ? "everyone"
82
+ : "mine");
83
+ }, (cause) => {
84
+ if (!cancelled)
85
+ setError(cause?.message ?? String(cause));
86
+ });
87
+ return () => {
88
+ cancelled = true;
89
+ };
90
+ }, [groupId, requested]);
91
+ (0, react_1.useEffect)(() => {
92
+ const opener = document.activeElement;
93
+ const dialog = dialogRef.current;
94
+ dialog?.focus();
95
+ return () => {
96
+ if (opener instanceof HTMLElement &&
97
+ (document.activeElement === document.body || dialog?.contains(document.activeElement))) {
98
+ opener.focus();
99
+ }
100
+ };
101
+ }, []);
102
+ const editable = Boolean(details && (layer === "mine" || details.canEditEveryone));
103
+ /**
104
+ * Save the whole layer, one save at a time, showing the pick at once. Only the last save's
105
+ * answer is shown: an earlier one would put back a layer without the picks made since.
106
+ */
107
+ const save = (0, react_1.useCallback)((nextLayer, look) => {
108
+ setError("");
109
+ setWarning("");
110
+ setDetails((current) => (current ? { ...current, [nextLayer]: look ?? {} } : current));
111
+ setSaving(true);
112
+ const number = ++burst.current.latest;
113
+ const run = queue.current.then(async () => {
114
+ let saved;
115
+ try {
116
+ saved = await (await (0, groups_client_1.groupsTools)()).setGroupAppearance({
117
+ groupId,
118
+ layer: nextLayer,
119
+ look,
120
+ });
121
+ }
122
+ catch (cause) {
123
+ burst.current.failed ||= cause?.message ?? String(cause);
124
+ }
125
+ if (number !== burst.current.latest)
126
+ return;
127
+ const failed = burst.current.failed;
128
+ burst.current.failed = "";
129
+ if (saved && !failed) {
130
+ setDetails(saved);
131
+ if (saved.warning)
132
+ setWarning(saved.warning);
133
+ return;
134
+ }
135
+ // Show what was saved, in both layers: a failed save may be in the other one.
136
+ setError(failed);
137
+ try {
138
+ const stored = await (await (0, groups_client_1.groupsTools)()).getGroupAppearance({ groupId });
139
+ if (number === burst.current.latest)
140
+ setDetails(stored);
141
+ }
142
+ catch {
143
+ // Keep what's shown; the error says the save failed.
144
+ }
145
+ });
146
+ queue.current = run;
147
+ void run.finally(() => {
148
+ if (queue.current === run)
149
+ setSaving(false);
150
+ });
151
+ }, [groupId]);
152
+ const look = details?.[layer] ?? {};
153
+ const below = details ? inherited(details, layer) : undefined;
154
+ const setField = (field, value) => {
155
+ const next = { ...look };
156
+ if (value)
157
+ next[field] = value;
158
+ else
159
+ delete next[field];
160
+ save(layer, next.color || next.icon ? next : null);
161
+ };
162
+ const onKeyDown = (event) => {
163
+ if (event.key === "Escape") {
164
+ event.preventDefault();
165
+ event.stopPropagation();
166
+ onClose();
167
+ return;
168
+ }
169
+ if (event.key !== "Tab")
170
+ return;
171
+ const focusable = Array.from(event.currentTarget.querySelectorAll('button:not(:disabled), input:not(:disabled), [tabindex="0"]'));
172
+ const first = focusable[0];
173
+ const last = focusable[focusable.length - 1];
174
+ if (event.shiftKey &&
175
+ (document.activeElement === first || document.activeElement === event.currentTarget)) {
176
+ event.preventDefault();
177
+ last?.focus();
178
+ }
179
+ else if (!event.shiftKey && document.activeElement === last) {
180
+ event.preventDefault();
181
+ first?.focus();
182
+ }
183
+ };
184
+ const name = group?.name ?? (details?.personal ? "Personal" : "this group");
185
+ const shown = details ? previewed(details, layer) : group;
186
+ const hidden = details && layer === "everyone" ? hiddenByMine(details.mine) : "";
187
+ return (0, react_dom_1.createPortal)(
188
+ // biome-ignore lint/a11y/noStaticElementInteractions: a pointer-only backdrop; Escape closes
189
+ (0, jsx_runtime_1.jsx)("div", { className: "peers-apps-dialog-backdrop", onMouseDown: (event) => {
190
+ if (event.target === event.currentTarget)
191
+ onClose();
192
+ }, children: (0, jsx_runtime_1.jsxs)("div", { ref: dialogRef, className: "peers-apps-dialog peers-look-dialog text-body", role: "dialog", tabIndex: -1, "aria-modal": "true", "aria-labelledby": "peers-look-dialog-title", onKeyDown: onKeyDown, "data-testid": "group-appearance-dialog", children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-apps-dialog-head", children: [(0, jsx_runtime_1.jsx)(group_look_1.GroupIcon, { icon: shown?.icon, color: shown?.color, variant: "tile", size: "40px" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex-grow-1", children: [(0, jsx_runtime_1.jsxs)("h3", { id: "peers-look-dialog-title", children: ["Color and icon for ", name] }), (0, jsx_runtime_1.jsxs)("span", { className: "peers-look-chip mt-1", children: [(0, jsx_runtime_1.jsx)(group_look_1.ColorDot, { color: shown?.color }), name] }), details && !details.personal ? ((0, jsx_runtime_1.jsx)("span", { className: "small text-body-secondary ms-2", children: layer === "everyone" ? "As everyone sees it" : "As you see it" })) : null] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn-close", "aria-label": "Close", onClick: onClose })] }), details && !details.personal ? ((0, jsx_runtime_1.jsxs)("div", { className: "peers-look-layers", role: "tablist", "aria-label": "Who sees it", children: [(0, jsx_runtime_1.jsx)(LayerTab, { label: "For everyone", selected: layer === "everyone", onSelect: () => setLayer("everyone") }), (0, jsx_runtime_1.jsx)(LayerTab, { label: "Just for me", selected: layer === "mine", onSelect: () => setLayer("mine") })] })) : null, !details && !error ? (0, jsx_runtime_1.jsx)("p", { children: "Loading\u2026" }) : null, details ? ((0, jsx_runtime_1.jsxs)("div", { role: "tabpanel", "aria-label": layer === "mine" ? "Just for me" : "For everyone", children: [(0, jsx_runtime_1.jsx)("p", { className: "mb-2 small text-body-secondary", children: layer === "mine"
193
+ ? details.personal
194
+ ? "Only you see Personal. This is synced to all your devices."
195
+ : "Only you see this, on all your devices. Anything you don't set uses the group's."
196
+ : details.canEditEveryone
197
+ ? `Everyone in ${name} sees this, unless they set their own.`
198
+ : "The group's admins set this. Use Just for me to change it for yourself." }), hidden ? ((0, jsx_runtime_1.jsxs)("div", { className: "alert alert-secondary py-2 px-2 small mb-2 d-flex align-items-baseline gap-2", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-info-circle", "aria-hidden": true }), (0, jsx_runtime_1.jsx)("span", { className: "flex-grow-1", children: hidden }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-link btn-sm p-0 text-nowrap", onClick: () => {
199
+ dialogRef.current?.focus({ preventScroll: true });
200
+ save("mine", null);
201
+ }, children: "Reset mine" })] })) : null, (0, jsx_runtime_1.jsx)("div", { className: "peers-look-section-title", children: "Color" }), (0, jsx_runtime_1.jsx)(color_picker_1.ColorPicker, { value: look.color, onChange: (value) => setField("color", value), noneLabel: layer === "mine" && !details.personal ? "The group's color" : "Automatic", noneColor: below?.color, disabled: !editable }, layer), (0, jsx_runtime_1.jsxs)("div", { className: "peers-look-section-title d-flex align-items-center", children: [(0, jsx_runtime_1.jsx)("span", { className: "flex-grow-1", children: "Icon" }), look.icon ? ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-link btn-sm p-0 text-decoration-none", disabled: !editable, onClick: () => {
202
+ dialogRef.current?.focus({ preventScroll: true });
203
+ setField("icon", undefined);
204
+ }, children: layer === "mine" && !details.personal
205
+ ? "Use the group's icon"
206
+ : "Use the default icon" })) : null] }), (0, jsx_runtime_1.jsx)(icon_picker_1.IconPicker, { value: look.icon, onChange: (ref) => setField("icon", ref), disabled: !editable })] })) : null, error ? ((0, jsx_runtime_1.jsx)("div", { role: "alert", className: "alert alert-danger py-2 small mt-3 mb-0", children: error })) : null, warning ? ((0, jsx_runtime_1.jsx)("div", { role: "alert", className: "alert alert-warning py-2 small mt-3 mb-0", children: warning })) : null, (0, jsx_runtime_1.jsxs)("div", { className: "peers-apps-dialog-actions mt-3", children: [details && layer === "mine" && (details.mine.color || details.mine.icon) ? ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-outline-secondary btn-sm", onClick: () => {
207
+ dialogRef.current?.focus({ preventScroll: true });
208
+ save("mine", null);
209
+ }, children: details.personal ? "Reset" : "Reset mine" })) : null, (0, jsx_runtime_1.jsx)("span", { className: "small text-body-secondary align-self-center me-auto", "aria-live": "polite", children: saving ? "Saving…" : "" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-primary btn-sm", onClick: onClose, children: "Done" })] })] }) }), document.body);
210
+ }
211
+ function LayerTab({ label, selected, onSelect, }) {
212
+ return ((0, jsx_runtime_1.jsx)("button", { type: "button", role: "tab", "aria-selected": selected, className: `btn btn-sm ${selected ? "btn-primary" : "btn-outline-primary"}`, onClick: onSelect, children: label }));
213
+ }
214
+ const overlayId = "system-group-appearance";
215
+ let openDialog;
216
+ /**
217
+ * Open the color-and-icon dialog for a group, above every screen. Peers opens it from the group
218
+ * switcher and group details; a package can too, instead of saving a look itself. Focus returns
219
+ * to the element that had it.
220
+ *
221
+ * @param groupId - The group, or the person's user id for Personal.
222
+ * @param options - A notice to show, and the layer to open on (Just for me by default).
223
+ */
224
+ function openGroupAppearanceDialog(groupId, options = {}) {
225
+ const opener = typeof document !== "undefined" ? document.activeElement : null;
226
+ openDialog = { groupId, opener, ...options };
227
+ (0, global_overlays_1.registerGlobalOverlay)(overlayId, GroupAppearanceDialogHost);
228
+ }
229
+ /** Mounted as a global overlay: shows the dialog {@link openGroupAppearanceDialog} opened. */
230
+ function GroupAppearanceDialogHost() {
231
+ const open = openDialog;
232
+ if (!open)
233
+ return null;
234
+ return ((0, jsx_runtime_1.jsx)(GroupAppearanceDialog, { groupId: open.groupId, notice: open.notice, layer: open.layer, onClose: () => {
235
+ openDialog = undefined;
236
+ (0, global_overlays_1.unregisterGlobalOverlay)(overlayId);
237
+ open.opener?.focus?.();
238
+ } }));
239
+ }