@ciridae/ui 2.79.0 → 2.80.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -60,9 +60,9 @@ export type AppNavigationProps = Omit<ComponentProps<"aside">, "children"> & {
60
60
  };
61
61
  /**
62
62
  * Whether the sidebar has room to unfold every section: the free space between its navigation and
63
- * its footer covers the `hiddenRows` its folds hide, less the More rows unfolding removes. Once it
64
- * has, it loses it only when the navigation runs out of room, so it does not flicker at the
65
- * threshold.
63
+ * its footer, less the gap the navigation cannot grow into, covers the `hiddenRows` its folds hide,
64
+ * less the More rows unfolding removes. Once it has, it loses it only when the navigation runs out
65
+ * of room, so it does not flicker at the threshold.
66
66
  */
67
67
  export declare function useSidebarRoom(hiddenRows: number): {
68
68
  navRef: import("react").RefObject<HTMLDivElement | null>;
@@ -44,9 +44,9 @@ const expandButtonRail = css({
44
44
  });
45
45
  /**
46
46
  * Whether the sidebar has room to unfold every section: the free space between its navigation and
47
- * its footer covers the `hiddenRows` its folds hide, less the More rows unfolding removes. Once it
48
- * has, it loses it only when the navigation runs out of room, so it does not flicker at the
49
- * threshold.
47
+ * its footer, less the gap the navigation cannot grow into, covers the `hiddenRows` its folds hide,
48
+ * less the More rows unfolding removes. Once it has, it loses it only when the navigation runs out
49
+ * of room, so it does not flicker at the threshold.
50
50
  */
51
51
  export function useSidebarRoom(hiddenRows) {
52
52
  const navRef = useRef(null);
@@ -55,13 +55,17 @@ export function useSidebarRoom(hiddenRows) {
55
55
  useLayoutEffect(() => {
56
56
  const nav = navRef.current;
57
57
  const footer = footerRef.current;
58
- if (!nav || !footer)
58
+ const sidebar = footer?.parentElement;
59
+ if (!nav || !footer || !sidebar)
59
60
  return;
60
61
  const measure = () => {
61
62
  const free = footer.getBoundingClientRect().top - nav.getBoundingClientRect().bottom;
63
+ // The sidebar keeps its gap between the navigation and the footer, so an unfolded
64
+ // navigation overflows and scrolls while that much free space is left.
65
+ const footerGap = parseFloat(getComputedStyle(sidebar).rowGap);
62
66
  setRoomy((current) => current
63
67
  ? free >= 0 && nav.scrollHeight <= nav.clientHeight + 1
64
- : free >= measureHeightUnfoldingAdds(nav, hiddenRows));
68
+ : free - footerGap >= measureHeightUnfoldingAdds(nav, hiddenRows));
65
69
  };
66
70
  measure();
67
71
  const observer = new ResizeObserver(measure);
@@ -1,4 +1,5 @@
1
1
  import { type QueryKey } from "@tanstack/react-query";
2
+ import { type ReactNode } from "react";
2
3
  import { type ChatParticipant } from "./chat-participant.js";
3
4
  import { type OpenChatProps } from "./open-chat.js";
4
5
  import type { OpenChatSource, ChatOutgoingMessage } from "../chat/open-chat-source.js";
@@ -6,8 +7,10 @@ import type { OpenChatSource, ChatOutgoingMessage } from "../chat/open-chat-sour
6
7
  * Someone a new chat's first message goes to: a chip in its To: line and a row of its suggestions.
7
8
  * A `participant` is a person or an agent already here, drawn as every picker draws them. An
8
9
  * `app_defined` recipient is the app's own agent, made as the message goes, such as New assistant,
9
- * which it knows by its `key` and the kit draws by its `label` and optional `secondary` line, its
10
- * face an agent's with no picture yet: the app's agent mark (`AgentAvatarFallbackProvider`).
10
+ * which it knows by its `key` and the kit draws by its `label` and optional `secondary` line. Its
11
+ * face is an agent's rounded square: its own `icon`, such as a plus for an agent not made yet, so
12
+ * it reads apart from the agents already here, or without one the app's agent mark
13
+ * (`AgentAvatarFallbackProvider`).
11
14
  */
12
15
  export type ChatDraftRecipient = {
13
16
  kind: "participant";
@@ -17,11 +20,48 @@ export type ChatDraftRecipient = {
17
20
  key: string;
18
21
  label: string;
19
22
  secondary?: string;
23
+ icon?: ReactNode;
20
24
  };
21
- /** Suggestions under one heading, such as the person's agents or the people they chat with most. */
25
+ /**
26
+ * Something New chat starts that is not a first message to whom To: holds, such as New group, which
27
+ * picks its members on a page of its own and is made before any message. A row over the
28
+ * suggestions, drawn by its `icon` and `label`: picking it closes the suggestions, leaves To: as it
29
+ * was and calls `onSelect`, where the app goes on.
30
+ */
31
+ export type ChatDraftAction = {
32
+ key: string;
33
+ label: string;
34
+ icon: ReactNode;
35
+ onSelect: () => void;
36
+ };
37
+ /**
38
+ * A chat already made, listed where a new one starts, such as one of the person's groups by its
39
+ * name: a new chat to the same people would be a second group, so its row opens the one there is.
40
+ * Picking it closes the suggestions, leaves To: as it was and calls `onSelect`, where the app shows
41
+ * the chat in the draft's place. `mark` is the chat's own, as its chat list row draws it, and
42
+ * fills a picker's 24 slot: an avatar or a stack of `menu` size. `secondary` is a line under its
43
+ * name, such as how many are in it.
44
+ */
45
+ export type ChatDraftExistingChat = {
46
+ kind: "existing_chat";
47
+ key: string;
48
+ name: string;
49
+ mark: ReactNode;
50
+ secondary?: string;
51
+ onSelect: () => void;
52
+ };
53
+ /** A row of a new chat's suggestions: someone To: takes, or a chat already made, which opens. */
54
+ export type ChatDraftSuggestion = ChatDraftRecipient | ChatDraftExistingChat;
55
+ /**
56
+ * Suggestions under one heading: whom To: takes, such as the person's agents or the people they
57
+ * chat with most, or the chats already made, such as their groups.
58
+ */
22
59
  export type ChatDraftSuggestionSection = {
23
60
  heading: string;
24
61
  recipients: readonly ChatDraftRecipient[];
62
+ } | {
63
+ heading: string;
64
+ existingChats: readonly ChatDraftExistingChat[];
25
65
  };
26
66
  /**
27
67
  * Whether the app can make a chat with the people in To: as they stand: `editable`, or
@@ -50,14 +90,21 @@ export type ChatDraftSource = Pick<OpenChatSource, "items" | "files" | "resolveA
50
90
  recipients: readonly ChatDraftRecipient[];
51
91
  setRecipients: (recipients: readonly ChatDraftRecipient[]) => void;
52
92
  toLine: ChatDraftToLineState;
53
- /** The suggestions while nothing is typed, section by section, each recipient in one section. */
93
+ /** The suggestions while nothing is typed, section by section, each row in one section. */
54
94
  suggestionSections: readonly ChatDraftSuggestionSection[];
95
+ /**
96
+ * The rows over the suggestions while nothing is typed, such as New group; an app with none
97
+ * leaves it out. Typing lists only what the search finds, so Enter never takes an action whose
98
+ * label happens to hold the letters.
99
+ */
100
+ actionsAboveSuggestions?: readonly ChatDraftAction[];
55
101
  /**
56
102
  * Once typing starts, the app's search over everyone the person can message, asked once typing
57
103
  * pauses, best match first, such as recent people first. It can offer the app's own recipients
58
- * too, such as New assistant for "assist".
104
+ * too, such as New assistant for "assist", and the chats already made whose name matches, such
105
+ * as a group, which Enter opens when it is the best match.
59
106
  */
60
- search: (query: string, signal: AbortSignal) => Promise<readonly ChatDraftRecipient[]>;
107
+ search: (query: string, signal: AbortSignal) => Promise<readonly ChatDraftSuggestion[]>;
61
108
  /**
62
109
  * The React Query key the app invalidates when what `search` reads changes, such as the people
63
110
  * the person can message. The To: search keys its answers under it
@@ -9,7 +9,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
9
9
  * chip back, Tab moves on to the message, and Escape closes the suggestions, then drops the draft.
10
10
  * Each chip is its recipient's face and name. Send stays off until someone is in To:, and while
11
11
  * the app says who is there cannot be sent to yet. Sending hands the message and its recipients to
12
- * the source, which makes the chat and sends it: the kit makes no chat itself.
12
+ * the source, which makes the chat and sends it: the kit makes no chat itself. Over the suggestions
13
+ * the app can list what a new chat starts some other way, as WhatsApp's New chat lists New group
14
+ * over its contacts (`actionsAboveSuggestions`), and among them the chats already made, such as the
15
+ * person's groups, which open instead of going into To: (`ChatDraftExistingChat`).
13
16
  */
14
17
  import { Combobox } from "@base-ui/react/combobox";
15
18
  import { NotePencilIcon } from "@phosphor-icons/react";
@@ -60,6 +63,13 @@ const draftMark = css({
60
63
  color: "fg.secondary",
61
64
  "& > svg": { width: "[40%]", height: "[40%]" },
62
65
  });
66
+ /* The slot an existing chat's mark fills, a picker's 24, as a chat list row gives its mark one. */
67
+ const existingChatMark = css({
68
+ display: "grid",
69
+ width: "avatar.menu",
70
+ height: "avatar.menu",
71
+ "& > *": { width: "full", height: "full" },
72
+ });
63
73
  /** A new chat's mark until its first message makes it, such as its chat list row's and header's. */
64
74
  export function ChatDraftMark() {
65
75
  return (_jsx("span", { className: draftMark, "aria-hidden": "true", children: _jsx(NotePencilIcon, {}) }));
@@ -114,13 +124,23 @@ function ChatDraftToLine({ source, placeholder, onDiscard, inputRef, }) {
114
124
  query: typed === "" ? null : typed,
115
125
  search: source.search,
116
126
  });
117
- const matches = (found.found ?? []).map(rowOf);
127
+ const matches = (found.found ?? []).map(rowOfSuggestion);
118
128
  const groups = (typed === ""
119
- ? source.suggestionSections.map(({ heading, recipients }) => ({
120
- value: heading,
121
- items: recipients.map(rowOf),
122
- }))
123
- : [{ value: "", items: matches }]).filter((group) => group.items.length > 0);
129
+ ? [
130
+ {
131
+ key: "actions",
132
+ heading: null,
133
+ items: (source.actionsAboveSuggestions ?? []).map(rowOfAction),
134
+ },
135
+ ...source.suggestionSections.map((section) => ({
136
+ key: `section:${section.heading}`,
137
+ heading: section.heading,
138
+ items: "recipients" in section
139
+ ? section.recipients.map(rowOf)
140
+ : section.existingChats.map(rowOfSuggestion),
141
+ })),
142
+ ]
143
+ : [{ key: "matches", heading: null, items: matches }]).filter((group) => group.items.length > 0);
124
144
  // Under a heading that is the plural noun ("Flints"), the reader's own agents are named once: the
125
145
  // noun phrase after each would repeat the heading. Other people's agents keep their owner's words.
126
146
  const isTheReadersOwnAgentUnderItsPluralNoun = (participant, heading) => participant.kind === "agent" &&
@@ -129,8 +149,17 @@ function ChatDraftToLine({ source, placeholder, onDiscard, inputRef, }) {
129
149
  const suggestionsShown = open && (typed !== "" || groups.length > 0);
130
150
  const picked = source.recipients.map(rowOf);
131
151
  // A pick clears the field for the next name and closes the suggestions; typing opens them again.
152
+ // An action or a chat already made is never held in To:: it closes the suggestions and the app
153
+ // goes on from there.
132
154
  const choose = (next) => {
133
- source.setRecipients(next.map((row) => row.recipient));
155
+ const opened = next.find((row) => row.kind === "opens");
156
+ if (opened !== undefined) {
157
+ changeQuery("");
158
+ setOpen(false);
159
+ opened.onSelect();
160
+ return;
161
+ }
162
+ source.setRecipients(next.flatMap((row) => (row.kind === "recipient" ? [row.recipient] : [])));
134
163
  if (next.length <= picked.length)
135
164
  return;
136
165
  changeQuery("");
@@ -139,12 +168,12 @@ function ChatDraftToLine({ source, placeholder, onDiscard, inputRef, }) {
139
168
  // The row Enter takes on an answer: its first match not already in To:.
140
169
  const chooseTheBestMatch = (searched) => {
141
170
  const best = (searched ?? [])
142
- .map(rowOf)
171
+ .map(rowOfSuggestion)
143
172
  .find((row) => !picked.some(({ key }) => key === row.key));
144
173
  if (best)
145
174
  choose([...picked, best]);
146
175
  };
147
- return (_jsxs(Combobox.Root, { multiple: true, open: suggestionsShown, onOpenChange: setOpen, ...(typed === "" ? { autoHighlight: false } : autoHighlightFirstRowProps), items: groups, filter: null, value: picked, onValueChange: choose, inputValue: query, onInputValueChange: (next) => changeQuery(next), onItemHighlighted: (_row, details) => setHighlightIsTheirs(details.reason !== "none"), isItemEqualToValue: (row, value) => row.key === value.key, itemToStringLabel: (row) => labelOf(row.recipient, locale), children: [_jsx(PeoplePickerToField, { className: toLine, chips: picked.map((row) => ({
176
+ return (_jsxs(Combobox.Root, { multiple: true, open: suggestionsShown, onOpenChange: setOpen, ...(typed === "" ? { autoHighlight: false } : autoHighlightFirstRowProps), items: groups, filter: null, value: picked, onValueChange: choose, inputValue: query, onInputValueChange: (next) => changeQuery(next), onItemHighlighted: (_row, details) => setHighlightIsTheirs(details.reason !== "none"), isItemEqualToValue: (row, value) => row.key === value.key, itemToStringLabel: (row) => row.kind === "recipient" ? labelOf(row.recipient, locale) : row.label, children: [_jsx(PeoplePickerToField, { className: toLine, chips: picked.map((row) => ({
148
177
  key: row.key,
149
178
  mark: markOf(row.recipient, "small"),
150
179
  label: labelOf(row.recipient, locale),
@@ -177,18 +206,43 @@ function ChatDraftToLine({ source, placeholder, onDiscard, inputRef, }) {
177
206
  "aria-label": labels.peoplePicker.to,
178
207
  placeholder: picked.length === 0 ? placeholder : undefined,
179
208
  ref: inputRef,
180
- } }), _jsx(Combobox.Portal, { children: _jsx(HotkeyLayer, { children: _jsx(Combobox.Positioner, { className: positioner, sideOffset: glassMenuOffsetFromTrigger, align: "start", alignOffset: SUGGESTIONS_INSET_FROM_THE_LINE, children: _jsxs(Combobox.Popup, { className: suggestionsPopup, "data-ciridae-ui": "", children: [_jsx(Combobox.List, { children: (group) => (_jsxs(Combobox.Group, { items: group.items, children: [group.value && (_jsx(Combobox.GroupLabel, { className: peoplePickerGroupLabel, children: group.value })), _jsx(Combobox.Collection, { children: (row) => (_jsx(PeoplePickerRow, { value: row, mark: markOf(row.recipient, "menu"), label: row.recipient.kind === "participant"
181
- ? describeChatParticipantName(row.recipient.participant, locale).name
209
+ } }), _jsx(Combobox.Portal, { children: _jsx(HotkeyLayer, { children: _jsx(Combobox.Positioner, { className: positioner, sideOffset: glassMenuOffsetFromTrigger, align: "start", alignOffset: SUGGESTIONS_INSET_FROM_THE_LINE, children: _jsxs(Combobox.Popup, { className: suggestionsPopup, "data-ciridae-ui": "", children: [_jsx(Combobox.List, { children: (group) => (_jsxs(Combobox.Group, { items: group.items, children: [group.heading !== null && (_jsx(Combobox.GroupLabel, { className: peoplePickerGroupLabel, children: group.heading })), _jsx(Combobox.Collection, { children: (row) => row.kind === "opens" ? (_jsx(PeoplePickerRow, { value: row, mark: row.mark, label: row.label, secondary: row.secondary, query: query }, row.key)) : (_jsx(PeoplePickerRow, { value: row, mark: markOf(row.recipient, "menu"), label: row.recipient.kind === "participant"
210
+ ? describeChatParticipantName(row.recipient.participant, locale)
211
+ .name
182
212
  : row.recipient.label, labelSuffix: row.recipient.kind === "participant" &&
183
- !isTheReadersOwnAgentUnderItsPluralNoun(row.recipient.participant, group.value)
213
+ !(group.heading !== null &&
214
+ isTheReadersOwnAgentUnderItsPluralNoun(row.recipient.participant, group.heading))
184
215
  ? (describeChatParticipantName(row.recipient.participant, locale)
185
216
  .agentNounPhrase ?? undefined)
186
217
  : undefined, secondary: row.recipient.kind === "app_defined"
187
218
  ? row.recipient.secondary
188
- : undefined, query: query }, row.key)) })] }, group.value || "matches")) }), typed !== "" && matches.length === 0 && (_jsx("div", { className: peoplePickerStatus, children: found.searching ? (_jsx(Spinner, { size: "compact" })) : found.failed ? (labels.common.searchFailed) : (labels.common.noMatches) }))] }) }) }) })] }));
219
+ : undefined, query: query }, row.key)) })] }, group.key)) }), typed !== "" && matches.length === 0 && (_jsx("div", { className: peoplePickerStatus, children: found.searching ? (_jsx(Spinner, { size: "compact" })) : found.failed ? (labels.common.searchFailed) : (labels.common.noMatches) }))] }) }) }) })] }));
220
+ }
221
+ function rowOfAction(action) {
222
+ return {
223
+ kind: "opens",
224
+ key: `action:${action.key}`,
225
+ label: action.label,
226
+ secondary: undefined,
227
+ mark: _jsx(Avatar, { label: action.label, size: "menu", gradientSeed: action.key, icon: action.icon }),
228
+ onSelect: action.onSelect,
229
+ };
230
+ }
231
+ function rowOfSuggestion(suggestion) {
232
+ return suggestion.kind === "existing_chat"
233
+ ? {
234
+ kind: "opens",
235
+ key: `existing_chat:${suggestion.key}`,
236
+ label: suggestion.name,
237
+ secondary: suggestion.secondary,
238
+ mark: _jsx("span", { className: existingChatMark, children: suggestion.mark }),
239
+ onSelect: suggestion.onSelect,
240
+ }
241
+ : rowOf(suggestion);
189
242
  }
190
243
  function rowOf(recipient) {
191
244
  return {
245
+ kind: "recipient",
192
246
  key: recipient.kind === "participant"
193
247
  ? buildChatParticipantKey(recipient.participant)
194
248
  : `app_defined:${recipient.key}`,
@@ -203,11 +257,11 @@ function labelOf(recipient, locale) {
203
257
  }
204
258
  /**
205
259
  * A recipient's face, a suggestion's at a picker's 24 (`menu`) or a chip's at 20 (`small`): a
206
- * participant's, or for the app's own an agent's face with no picture yet, which shows the app's
260
+ * participant's, or for the app's own an agent's face with its `icon`, or without one the app's
207
261
  * agent mark.
208
262
  */
209
263
  function markOf(recipient, size) {
210
- return recipient.kind === "participant" ? (_jsx(ChatParticipantMark, { participant: recipient.participant, size: size })) : (_jsx(Avatar, { label: recipient.label, size: size, kind: "agent" }));
264
+ return recipient.kind === "participant" ? (_jsx(ChatParticipantMark, { participant: recipient.participant, size: size })) : (_jsx(Avatar, { label: recipient.label, size: size, kind: "agent", icon: recipient.icon }));
211
265
  }
212
266
  /** The line under To:: why To: cannot be sent to yet, as a warning. */
213
267
  function describeNoteUnderToLine(toLine) {
@@ -3913,6 +3913,14 @@
3913
3913
  max-height: min(var(--sizes-overlay\.tray-list), var(--available-height));
3914
3914
  }
3915
3915
 
3916
+ .w_avatar\.menu {
3917
+ width: var(--sizes-avatar\.menu);
3918
+ }
3919
+
3920
+ .h_avatar\.menu {
3921
+ height: var(--sizes-avatar\.menu);
3922
+ }
3923
+
3916
3924
  .w_chat\.imageBubbleMaxWidth {
3917
3925
  width: var(--sizes-chat\.image-bubble-max-width);
3918
3926
  }
@@ -4360,14 +4368,6 @@
4360
4368
  top: 50%;
4361
4369
  }
4362
4370
 
4363
- .w_avatar\.menu {
4364
- width: var(--sizes-avatar\.menu);
4365
- }
4366
-
4367
- .h_avatar\.menu {
4368
- height: var(--sizes-avatar\.menu);
4369
- }
4370
-
4371
4371
  .pt_panel\.comfortable {
4372
4372
  padding-top: var(--spacing-panel\.comfortable);
4373
4373
  }
@@ -10549,6 +10549,14 @@
10549
10549
  height: 40%;
10550
10550
  }
10551
10551
 
10552
+ .\[\&_\>_\*\]\:w_full > * {
10553
+ width: var(--sizes-full);
10554
+ }
10555
+
10556
+ .\[\&_\>_\*\]\:h_full > * {
10557
+ height: var(--sizes-full);
10558
+ }
10559
+
10552
10560
  .\[\&_\[data-first-page-picture\]\]\:w_\[calc\(100\%_\+_token\(spacing\.control\.compactInline\)_\+_token\(spacing\.control\.iconInline\)_-_2_\*_token\(spacing\.control\.compactBlock\)\)\] [data-first-page-picture] {
10553
10561
  width: calc(100% + var(--spacing-control\.compact-inline) + var(--spacing-control\.icon-inline) - 2 * var(--spacing-control\.compact-block));
10554
10562
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ciridae/ui",
3
- "version": "2.79.0",
3
+ "version": "2.80.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",