@gemboss/ui 0.70.2 → 0.73.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.
- package/CHANGELOG.md +633 -3
- package/README.md +170 -11
- package/catalog/editor.html +1 -1
- package/catalog/index.html +48 -46
- package/gemboss-ui.css +4 -4
- package/package.json +32 -1
- package/parts/components.css +3 -3
- package/parts/core.css +1 -1
- package/parts/shell.css +2 -2
- package/src/app-nav.css +1 -1
- package/src/app-shell.css +1 -1
- package/src/assistant/chat-cards.tsx +118 -19
- package/src/assistant/chat.tsx +209 -22
- package/src/assistant/composer-menus.tsx +7 -2
- package/src/assistant/dock.ts +97 -10
- package/src/assistant/figures.tsx +119 -0
- package/src/assistant/gallery.tsx +67 -0
- package/src/assistant/hold.ts +51 -0
- package/src/assistant/host.tsx +258 -137
- package/src/assistant/ideas.tsx +90 -0
- package/src/assistant/index.ts +12 -3
- package/src/assistant/plus.tsx +61 -0
- package/src/assistant/provider.tsx +121 -24
- package/src/assistant/sessions.tsx +54 -20
- package/src/assistant/window-host.tsx +215 -0
- package/src/assistant/window.ts +120 -0
- package/src/assistant-chat.css +1 -1
- package/src/assistant-figures.css +1 -0
- package/src/assistant-hold.css +1 -0
- package/src/assistant-places.css +1 -0
- package/src/assistant-plain.js +1 -1
- package/src/assistant-plus.css +1 -0
- package/src/assistant-window-plain.js +1 -0
- package/src/assistant-window.css +1 -0
- package/src/assistant.css +1 -1
- package/src/auth-extras.css +1 -1
- package/src/auth-footer.css +1 -1
- package/src/auth-steps.css +1 -1
- package/src/auth.css +1 -1
- package/src/board-move.ts +2 -1
- package/src/chat-attachments.css +1 -1
- package/src/chat-cards-drawn.css +1 -0
- package/src/chat-cards-float.css +1 -0
- package/src/chat-cards.css +1 -1
- package/src/chat-composer-menus.css +1 -1
- package/src/chat-composer.css +1 -1
- package/src/chat-plain.js +6 -6
- package/src/chat-shortcuts.css +1 -0
- package/src/chat-voice.css +1 -1
- package/src/chat.css +1 -1
- package/src/chips-drawn.css +1 -0
- package/src/collections.css +1 -1
- package/src/collections.tsx +4 -2
- package/src/create-shell.css +1 -1
- package/src/dialog.css +1 -1
- package/src/editor/choice-cards.tsx +8 -5
- package/src/editor/controls.tsx +36 -9
- package/src/editor/field-control.tsx +17 -3
- package/src/editor/field-spec.ts +17 -4
- package/src/editor/index.ts +2 -0
- package/src/editor/media-words.ts +21 -0
- package/src/editor-color.css +1 -1
- package/src/editor-empty.css +1 -0
- package/src/editor-insert.css +1 -1
- package/src/editor-inspector-frame.css +1 -1
- package/src/editor-media.css +1 -1
- package/src/editor-picker-grid.css +1 -1
- package/src/editor-picker.css +1 -1
- package/src/editor-popover.css +1 -1
- package/src/editor-repeater.css +1 -1
- package/src/editor-tiles.css +1 -1
- package/src/editor.css +1 -1
- package/src/email-canvas.css +1 -0
- package/src/email-card.tsx +44 -0
- package/src/email-editor/canvas.tsx +109 -0
- package/src/email-editor/editor.tsx +45 -4
- package/src/email-editor/index.ts +2 -1
- package/src/email-editor/model.ts +9 -1
- package/src/email-editor.css +1 -1
- package/src/email-parts.css +1 -0
- package/src/email-parts.tsx +81 -0
- package/src/email-thumb.css +1 -0
- package/src/email-thumb.tsx +206 -0
- package/src/feedback-dialog.css +1 -0
- package/src/feedback-dialog.tsx +122 -0
- package/src/flow-strip.css +1 -0
- package/src/flow-strip.tsx +50 -0
- package/src/gemboss-field-drawn.css +1 -0
- package/src/gemboss-field.css +1 -1
- package/src/gems.css +1 -1
- package/src/icon-frame.tsx +31 -0
- package/src/icons.tsx +9 -9
- package/src/index.ts +12 -0
- package/src/job-card.css +1 -1
- package/src/kit-plain.css +1 -1
- package/src/kit-plain.js +1 -1
- package/src/language-switcher.css +1 -1
- package/src/list-page.css +1 -1
- package/src/list-page.tsx +6 -3
- package/src/list-toolbar.css +1 -1
- package/src/media-card.css +1 -0
- package/src/members.css +1 -1
- package/src/menu-extras.css +1 -1
- package/src/menu-layer.ts +2 -0
- package/src/menu-select.css +1 -1
- package/src/menu.css +1 -1
- package/src/menu.tsx +9 -4
- package/src/narration.css +1 -1
- package/src/pager-extras.css +1 -1
- package/src/pager.css +1 -1
- package/src/picture-actions.css +1 -0
- package/src/picture-actions.tsx +23 -0
- package/src/portal.css +1 -1
- package/src/question-card.css +1 -1
- package/src/rail-fold.css +1 -1
- package/src/reactions.css +1 -1
- package/src/reader-dialog.css +1 -1
- package/src/report-charts.css +1 -1
- package/src/segmented.tsx +6 -0
- package/src/service-switcher.css +1 -1
- package/src/session-rail-plain.js +1 -1
- package/src/settings-dialog.css +1 -1
- package/src/setup-guide.css +1 -1
- package/src/sheet.css +1 -1
- package/src/shell.css +1 -1
- package/src/shell.tsx +9 -2
- package/src/site.css +1 -1
- package/src/skill-card.css +1 -1
- package/src/skill-flow.css +1 -1
- package/src/skill-pages.css +1 -1
- package/src/skill-view.css +1 -1
- package/src/stage-path.css +1 -1
- package/src/stat-tile.css +1 -0
- package/src/stat-tile.tsx +39 -0
- package/src/status-list.css +1 -1
- package/src/team-chat.css +1 -1
- package/src/tray-plain.js +1 -0
- package/src/tray-search.tsx +116 -0
- package/src/tray.css +1 -0
- package/src/tray.tsx +250 -0
- package/src/ui.css +1 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* QUESTIONS TO TRY, ALWAYS ONE PRESS AWAY (13/11/2026, Chris: "có một button suggest cho tôi 5 câu hỏi khác, kiểu luôn có button đó để
|
|
5
|
+
* họ khám phá được nhiều câu hỏi và nhiều thông tin hơn"). On a phone a seller's admin is the chat, so what they can ask is how they
|
|
6
|
+
* find what is there; the starters show only while a chat is empty.
|
|
7
|
+
*
|
|
8
|
+
* ChatIdeasChip "Suggest questions", at the end of the conversation (under the last answer, or the starters). A press opens the
|
|
9
|
+
* tray in its place. Not in the composer's strip: on a phone it is full ("+", ✦, Research, the microphone and send
|
|
10
|
+
* take 299 of the box's 332px at 390; measured 13/11/2026, the chip there was cut under the microphone).
|
|
11
|
+
* ChatIdeasTray in the chip's place: what to try, as the chat's chips (a press sends the question), "5 more" for the next ones
|
|
12
|
+
* and a close. The surface owns the questions (its bank, what it has shown) and what a press sends.
|
|
13
|
+
*
|
|
14
|
+
* Both 44px under a finger (the chips are the chat's own, 44px always). Words are English by default and taken as props.
|
|
15
|
+
* Styles: chat-composer-menus.css, the composer's sheet, so no surface that draws a ChatComposer loads anything new for them.
|
|
16
|
+
*/
|
|
17
|
+
import "../chat-composer-menus.css";
|
|
18
|
+
import "../chat.css";
|
|
19
|
+
import React from "react";
|
|
20
|
+
import { Icon } from "../icons";
|
|
21
|
+
|
|
22
|
+
export interface ChatIdeasLabels {
|
|
23
|
+
/** The chip's word. */
|
|
24
|
+
chip: string;
|
|
25
|
+
/** The chip's tooltip and accessible description. */
|
|
26
|
+
chipTitle: string;
|
|
27
|
+
/** The tray's heading. */
|
|
28
|
+
heading: string;
|
|
29
|
+
/** The button for the next ones. */
|
|
30
|
+
more: string;
|
|
31
|
+
/** The close button's name. */
|
|
32
|
+
close: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const CHAT_IDEAS_LABELS: ChatIdeasLabels = {
|
|
36
|
+
chip: "Suggest questions",
|
|
37
|
+
chipTitle: "Suggest questions to ask Gem",
|
|
38
|
+
heading: "Try asking",
|
|
39
|
+
more: "5 more",
|
|
40
|
+
close: "Close ideas",
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export function ChatIdeasChip({ open, onPress, labels, disabled = false, controls, id }: {
|
|
44
|
+
open: boolean;
|
|
45
|
+
/** Its id, so the surface can hand focus back to it when the tray closes. */
|
|
46
|
+
id?: string;
|
|
47
|
+
onPress: () => void;
|
|
48
|
+
labels?: Partial<ChatIdeasLabels>;
|
|
49
|
+
disabled?: boolean;
|
|
50
|
+
/** The tray's id, when it is on the page. */
|
|
51
|
+
controls?: string;
|
|
52
|
+
}) {
|
|
53
|
+
const L = { ...CHAT_IDEAS_LABELS, ...labels };
|
|
54
|
+
return (
|
|
55
|
+
<button type="button" id={id} className="gb-chat-ideas" aria-expanded={open} aria-controls={open ? controls : undefined}
|
|
56
|
+
title={L.chipTitle} disabled={disabled} onClick={onPress}>
|
|
57
|
+
<Icon name="chat" size={14} />
|
|
58
|
+
<span>{L.chip}</span>
|
|
59
|
+
</button>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function ChatIdeasTray({ questions, onAsk, onMore, onClose, labels, id }: {
|
|
64
|
+
questions: readonly string[];
|
|
65
|
+
/** A question pressed: the surface sends it (and closes the tray, if it wants). */
|
|
66
|
+
onAsk: (question: string) => void;
|
|
67
|
+
/** The next ones. Left out: no "more" button. */
|
|
68
|
+
onMore?: () => void;
|
|
69
|
+
onClose: () => void;
|
|
70
|
+
labels?: Partial<ChatIdeasLabels>;
|
|
71
|
+
id?: string;
|
|
72
|
+
}) {
|
|
73
|
+
const L = { ...CHAT_IDEAS_LABELS, ...labels };
|
|
74
|
+
return (
|
|
75
|
+
<section className="gb-chat-ideas-tray" id={id} aria-label={L.heading}>
|
|
76
|
+
<div className="gb-chat-ideas-head">
|
|
77
|
+
<span>{L.heading}</span>
|
|
78
|
+
<button type="button" className="gb-chat-ideas-close" aria-label={L.close} title={L.close} onClick={onClose}>
|
|
79
|
+
<Icon name="close" size={16} />
|
|
80
|
+
</button>
|
|
81
|
+
</div>
|
|
82
|
+
<div className="gemboss-ec-chips">
|
|
83
|
+
{questions.map((q) => (
|
|
84
|
+
<button key={q} type="button" className="gemboss-ec-chip" onClick={() => onAsk(q)}>{q}</button>
|
|
85
|
+
))}
|
|
86
|
+
</div>
|
|
87
|
+
{onMore ? <button type="button" className="gb-chat-ideas-more" onClick={onMore}>{L.more}</button> : null}
|
|
88
|
+
</section>
|
|
89
|
+
);
|
|
90
|
+
}
|
package/src/assistant/index.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
// The assistant's frame: popup, status bar, full screen — and the rules for when each shows.
|
|
2
2
|
// A separate entry from the shell/auth barrel so a surface that never opens an assistant pays nothing for it.
|
|
3
3
|
export { AssistantHost, AssistantMenuItem, type AssistantHostLabels, type AssistantSecondTab } from "./host";
|
|
4
|
-
export { AssistantProvider, SIDE_WIDTH_VAR, useAssistant, useAssistantPageFacts, type AssistantDockApi, type AssistantOptions } from "./provider";
|
|
4
|
+
export { AssistantProvider, LEFT_WIDTH_VAR, SIDE_WIDTH_VAR, useAssistant, useAssistantPageFacts, useAssistantPresentation, type AssistantDockApi, type AssistantOptions } from "./provider";
|
|
5
5
|
export * from "./dock";
|
|
6
|
-
|
|
6
|
+
// The floating window's geometry (12/11/2026): fitted, moved, resized, docked. Its own module, which only the window's chrome loads.
|
|
7
|
+
export * from "./window";
|
|
8
|
+
export { AssistantWorkspaceLayout, OpenChatTabs, SessionRail, SESSION_RAIL_EN, SESSION_RAIL_SIZE, SESSION_RAIL_WIDTH_KEY, groupSessions, normalizeForSearch, relativeTime, type AssistantSession, type SessionGroup, type SessionRailIcons, type SessionRailLabels } from "./sessions";
|
|
7
9
|
export { BRIDGE_TONE, BridgeNotice, ENGINE_PICKER_EN, EnginePicker, bridgeStateWords, bridgeSuffix, engineChipName, engineMarkOf, useEnginePicker, type BridgeSetup, type BridgeState, type BridgeStatus, type Choice, type EngineChoice, type EnginePickerLabels, type EnginePickerProps, type EnginePickerTab } from "./engine";
|
|
8
10
|
// The engine in the surface's Settings ("AI & engines", 0.52.0; the only place since 0.53.0): the chip opens it
|
|
9
11
|
// (`onOpenSettings`), the section draws it.
|
|
10
12
|
export { EngineSettings, EngineSettingsSection, type EngineSettingsProps } from "./engine-settings";
|
|
11
13
|
// 0.29.0: the chat BODY as components (the surface hands in messages and actions), its markdown, and each engine's mark.
|
|
12
|
-
export { AssistantChat, ChatAttach, ChatBubble, ChatComposer, ChatError, ChatLabelsProvider, ChatMarkdown, ChatMessage, ChatMeta, ChatNote, ChatPending, ChatStarters, ChatStepMark, chatStepMarkIcon, ChatSteps, ChatThread, CHAT_EN, PaperclipIcon, firstBlank, selectBlank, useComposerDensity, useFullChromeRoom, type AssistantChatProps, type ChatComposerProps, type ChatComposerVoice, type ChatFix, type ChatLabels, type ChatMarkdownProps, type ChatMessageData, type ChatStarter, type ChatStep, type ChatStepMarkKind, type ComposerDensity } from "./chat";
|
|
14
|
+
export { AssistantChat, ChatAttach, ChatBubble, ChatComposer, ChatError, ChatLabelsProvider, ChatMarkdown, ChatMessage, ChatMeta, ChatNote, ChatPending, ChatStarters, ChatStepMark, chatStepMarkIcon, ChatSteps, ChatThread, CHAT_EN, PaperclipIcon, firstBlank, selectBlank, useComposerDensity, useFullChromeRoom, type AssistantChatProps, type ChatComposerProps, type ChatComposerVoice, type ChatFix, type ChatLabels, type ChatMarkdownProps, type ChatMessageData, type ChatStarter, type ChatStep, type ChatStepMarkKind, type ComposerDensity , shortcutMatches, type ChatShortcut } from "./chat";
|
|
13
15
|
// The composer's "+" and ✦ menus (0.70.0): what a host hands ChatComposer's `add` and `ai`, and the clipboard reader "+" uses.
|
|
14
16
|
export { aiButtonName, canReadClipboardImages, PASTE_EMPTY, PASTE_REFUSED, readClipboardImages, type ChatAddIcon, type ChatAddItem, type ChatAiChoice, type ChatComposerAdd, type ChatComposerAi } from "./composer-menus";
|
|
15
17
|
// Files in the chat (11/11/2026, canvas board ChatKit states 2–11): what is attached and its uploads, the panel as a drop target, the
|
|
@@ -18,6 +20,13 @@ export { attachmentProblem, ChatAttachments, ChatDropZone, ChatImages, ChatLight
|
|
|
18
20
|
// What can appear in the stream beside words (11/11/2026, canvas board ChatKit): the card a turn's result, job or change is drawn on,
|
|
19
21
|
// the choices (chips or a poll), the question waiting over the box, the words a turn rewrote, a page's bars, buttons that go
|
|
20
22
|
// elsewhere, the rating row. Its own module and stylesheet (`@gemboss/ui/chat-cards.css`).
|
|
23
|
+
// Gem Plus's switch in the composer (13/11/2026): `ChatPlusChip`; the panel's look is AssistantHost `plus`. Its own entry, assistant-plus.css.
|
|
24
|
+
export { ChatPlusChip, CHAT_PLUS_LABELS, type ChatPlusLabels, type ChatPlusState } from "./plus";
|
|
25
|
+
// Questions to try (13/11/2026): "Suggest questions" at the end of the conversation (not the composer's strip, full at 390), and the
|
|
26
|
+
// tray in its place. The surface owns the questions.
|
|
27
|
+
export { ChatIdeasChip, ChatIdeasTray, CHAT_IDEAS_LABELS, type ChatIdeasLabels } from "./ideas";
|
|
28
|
+
export { ChatFigures, CHAT_FIGURES_LABELS, figurePct, type ChatFigure, type ChatFigureRow, type ChatFiguresLabels } from "./figures";
|
|
29
|
+
export { ChatPageGallery, CHAT_GALLERY_LABELS, type ChatGalleryLabels, type ChatGalleryPage } from "./gallery";
|
|
21
30
|
export { ChatCard, ChatCardButton, ChatChoices, ChatCta, ChatDecide, ChatFeedback, ChatPageBands, ChatTextChanges, ChatThing, type ChatCardProps, type ChatCardTag, type ChatCardTone, type ChatChoiceItem, type ChatChoicesProps, type ChatCtaAction, type ChatPageBand, type ChatRating, type ChatTextChange } from "./chat-cards";
|
|
22
31
|
// Speaking instead of typing (B15-voice, 08/11/2026): the hook ChatComposer's `voice` runs on, for a box that is not a chat. Also
|
|
23
32
|
// its own entry, `@gemboss/ui/assistant/dictation` (no CSS on the way).
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GEM PLUS: the plan's chip in the composer (13/11/2026, Gem Plus boards, artifact DmPeQEJDAZXdiTxzmFv5UL). PLUS IS THE PLAN, NOT A MODE
|
|
5
|
+
* (14/11/2026, Chris: "giao diện vàng là được rồi còn ko cần phải bật tắt research mode, đổi cái label research đó thành Plus là được
|
|
6
|
+
* rồi, bấm vào nó thì ra cái popup nói rõ được sự khác biệt giữa bản plus và bản thường… với tài khoản thường thì nó vẫn có chữ plus ở
|
|
7
|
+
* đó nhưng không được bật và bấm vào nó vẫn ra popup nhưng kèm button upgrade"): it switches nothing.
|
|
8
|
+
*
|
|
9
|
+
* A chip of the composer's toolbar: on the right, in ChatComposer `tools`, beside the microphone and send (Chris 13/11/2026: "nó nên
|
|
10
|
+
* nằm về bên phải cạnh nút enter"). Two states, the surface's call:
|
|
11
|
+
* locked the plan does not have Gem Plus: a hairline chip with a lock; a press opens what Plus is, with the way up;
|
|
12
|
+
* on the plan has it: a gold chip; a press opens what Plus adds over the regular Gem (the panel wears the Plus look, AssistantHost
|
|
13
|
+
* `plus`, all the time).
|
|
14
|
+
* The chip only draws and reports the press: what Plus does, and whether the store has it, are the surface's (the admin's gem-plus
|
|
15
|
+
* gate). Its own ENTRY, assistant-plus.css (scripts/parts.mjs), with the panel's look (AssistantHost imports it too).
|
|
16
|
+
*/
|
|
17
|
+
import "../assistant-plus.css";
|
|
18
|
+
import React from "react";
|
|
19
|
+
import { Icon } from "../icons";
|
|
20
|
+
|
|
21
|
+
export type ChatPlusState = "locked" | "on";
|
|
22
|
+
|
|
23
|
+
export interface ChatPlusLabels {
|
|
24
|
+
/** The chip's word. */
|
|
25
|
+
name: string;
|
|
26
|
+
/** Its title (the hover line, and the screen reader's description) in each state. */
|
|
27
|
+
locked: string;
|
|
28
|
+
on: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const CHAT_PLUS_LABELS: ChatPlusLabels = {
|
|
32
|
+
name: "Plus",
|
|
33
|
+
locked: "Gem Plus: answers about your market, with numbers and real pages. See what it adds",
|
|
34
|
+
on: "Gem Plus is on: see what it adds",
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export function ChatPlusChip({ state, onPress, labels, disabled = false }: {
|
|
38
|
+
state: ChatPlusState;
|
|
39
|
+
/** Open what Plus is: with the way up while locked, what it adds while on. Nothing switches. */
|
|
40
|
+
onPress: () => void;
|
|
41
|
+
labels?: Partial<ChatPlusLabels>;
|
|
42
|
+
disabled?: boolean;
|
|
43
|
+
}) {
|
|
44
|
+
const L = { ...CHAT_PLUS_LABELS, ...labels };
|
|
45
|
+
return (
|
|
46
|
+
<button
|
|
47
|
+
type="button"
|
|
48
|
+
className="gb-chat-plus"
|
|
49
|
+
data-state={state}
|
|
50
|
+
// A door to a dialog in both states: it toggles nothing.
|
|
51
|
+
aria-haspopup="dialog"
|
|
52
|
+
title={L[state]}
|
|
53
|
+
disabled={disabled}
|
|
54
|
+
onClick={onPress}
|
|
55
|
+
>
|
|
56
|
+
<Icon name="sparkle" size={14} />
|
|
57
|
+
<span>{L.name}</span>
|
|
58
|
+
{state === "locked" ? <Icon name="lock" size={12} className="gb-chat-plus-lock" /> : null}
|
|
59
|
+
</button>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
* - `dockedEvent` — announced when a rail click opened the popup instead of the full screen, so the
|
|
12
12
|
* shell can close its mobile drawer
|
|
13
13
|
* - `bodyClassPrefix` — `<prefix>-busy` / `<prefix>-unread` on <body>, which the rail item reads
|
|
14
|
+
* - `defaultShape` — the place a person who never chose one gets (12/11/2026; the kit's default is the side panel). The admin
|
|
15
|
+
* passes "left": Chris, "ai chat mặc định mở, nằm ở bên trái"; there it also opens on load (below).
|
|
14
16
|
*/
|
|
15
17
|
import React, { createContext, startTransition, useCallback, useContext, useEffect, useMemo, useReducer, useRef, useState, type ReactNode } from "react";
|
|
16
18
|
import {
|
|
@@ -18,7 +20,10 @@ import {
|
|
|
18
20
|
initialAssistantDockState,
|
|
19
21
|
DOCK_DEFAULT_OFFSET_RIGHT,
|
|
20
22
|
openingDockHeight,
|
|
23
|
+
ASSISTANT_HOLD_ATTR,
|
|
24
|
+
SIDE_FITS_QUERY,
|
|
21
25
|
type AssistantFloatShape,
|
|
26
|
+
type AssistantPresentation,
|
|
22
27
|
SIDE_DEFAULT_WIDTH,
|
|
23
28
|
type AssistantDockState,
|
|
24
29
|
} from "./dock";
|
|
@@ -30,27 +35,40 @@ export interface AssistantOptions {
|
|
|
30
35
|
isOnFullPage?: () => boolean;
|
|
31
36
|
dockedEvent?: string;
|
|
32
37
|
bodyClassPrefix?: string;
|
|
38
|
+
defaultShape?: AssistantFloatShape;
|
|
33
39
|
}
|
|
34
40
|
|
|
35
|
-
/** Storage keys. `lastMode` is the last shape the seller actually used: "full", "dock" or "
|
|
41
|
+
/** Storage keys. `lastMode` is the last shape the seller actually used: "full", "dock", "side" or "left" — nothing
|
|
36
42
|
* else is worth reopening as. Module-level so the callbacks below stay identity-stable. */
|
|
37
|
-
// `
|
|
38
|
-
//
|
|
39
|
-
|
|
43
|
+
// `place` (12/11/2026), the person's chosen place, written only when they pick one in ⋯'s places. It replaces `shape`, which
|
|
44
|
+
// was not only a choice: Ask Gem and Draft with Gem wrote "side" (openSide) on a press that chose no place, so a stored "side" cannot
|
|
45
|
+
// be told from a seller who never chose, and reading it would keep them off a new default. Its "dock" was only ever "Float as a
|
|
46
|
+
// popup", a choice, and is carried over. (`shape` itself replaced `floatShape` on 04/10/2026, which recorded the default it was given.)
|
|
47
|
+
const storageKey = (prefix: string, k: "dockHeight" | "dockOffsetRight" | "lastMode" | "sideWidth" | "shape" | "place" | "presentation") => `${prefix}.${k}`;
|
|
40
48
|
|
|
41
49
|
/**
|
|
42
50
|
* The width of the content area the side panel sits in: the window minus the rail. Measured from `main`'s LEFT
|
|
43
51
|
* edge (where the rail ends), never from main's width — with the panel open, main is already narrower by the panel.
|
|
52
|
+
* `left` (12/11/2026): the left panel is open, so main starts after it; the rail's edge is where that panel stands,
|
|
53
|
+
* `--gb-rail-w` (240 where it is not set), the same value its CSS reads (assistant-places.css).
|
|
44
54
|
*/
|
|
45
|
-
export function sideAvailable(): number {
|
|
55
|
+
export function sideAvailable(left = false): number {
|
|
46
56
|
if (typeof window === "undefined") return 0;
|
|
47
|
-
const
|
|
48
|
-
|
|
57
|
+
const main = document.querySelector(".gemboss-platform-main");
|
|
58
|
+
const vw = document.documentElement.clientWidth || window.innerWidth;
|
|
59
|
+
if (left) {
|
|
60
|
+
const rail = main ? parseFloat(getComputedStyle(main).getPropertyValue("--gb-rail-w")) : NaN;
|
|
61
|
+
return vw - (Number.isFinite(rail) ? rail : 240);
|
|
62
|
+
}
|
|
63
|
+
return vw - (main?.getBoundingClientRect().left ?? 0);
|
|
49
64
|
}
|
|
50
65
|
|
|
51
66
|
/** The custom property the page reads to make room for the side panel (`.gemboss-platform-main` does it itself;
|
|
52
67
|
* a surface with its own layout reads the same variable). */
|
|
53
68
|
export const SIDE_WIDTH_VAR = "--gb-assistant-side-w";
|
|
69
|
+
/** The LEFT panel's width, for the page's left margin (12/11/2026). Its own name: a surface's right-anchored overlays read
|
|
70
|
+
* SIDE_WIDTH_VAR as "a panel on the right takes this much" (the admin's Search & AI sheet, the desktop invite). */
|
|
71
|
+
export const LEFT_WIDTH_VAR = "--gb-assistant-left-w";
|
|
54
72
|
|
|
55
73
|
const ADMIN_FULL_PATH = "/app/assistant";
|
|
56
74
|
const DEFAULTS: Required<AssistantOptions> = {
|
|
@@ -59,8 +77,13 @@ const DEFAULTS: Required<AssistantOptions> = {
|
|
|
59
77
|
isOnFullPage: () => window.location.pathname.startsWith(ADMIN_FULL_PATH),
|
|
60
78
|
dockedEvent: "gemboss:assistant-docked",
|
|
61
79
|
bodyClassPrefix: "gemboss-assistant",
|
|
80
|
+
defaultShape: initialAssistantDockState.floatShape,
|
|
62
81
|
};
|
|
63
82
|
|
|
83
|
+
/** Only WHERE the assistant is drawn, in its own context: a shell that lays itself out around the assistant (the admin folds its
|
|
84
|
+
* rail while the chat is on the left) reads this and is not drawn again on every busy flip, page fact or open. */
|
|
85
|
+
const PresentationCtx = createContext<AssistantPresentation>("hidden");
|
|
86
|
+
|
|
64
87
|
export interface AssistantDockApi extends AssistantDockState {
|
|
65
88
|
/** Specifics the CURRENT screen registered about itself, for the assistant to read. */
|
|
66
89
|
pageFacts: string[];
|
|
@@ -73,6 +96,8 @@ export interface AssistantDockApi extends AssistantDockState {
|
|
|
73
96
|
openDock: () => void;
|
|
74
97
|
/** Pin to the full-height side panel. Only a host that allows it (`allowSide`) offers the button. */
|
|
75
98
|
openSide: () => void;
|
|
99
|
+
/** Pin to the full-height panel on the LEFT of the page. Only a host that allows it (`allowLeft`) offers the button. */
|
|
100
|
+
openLeft: () => void;
|
|
76
101
|
/** Back on screen in the last working shape — popup or side panel (`floatShape`). */
|
|
77
102
|
reopen: () => void;
|
|
78
103
|
minimize: () => void;
|
|
@@ -86,6 +111,10 @@ export interface AssistantDockApi extends AssistantDockState {
|
|
|
86
111
|
setSideWidth: (width: number) => void;
|
|
87
112
|
/** The host registers whether it offers the side panel (`allowSide`). */
|
|
88
113
|
setSideAllowed: (allowed: boolean) => void;
|
|
114
|
+
/** The host registers whether it offers the left panel (`allowLeft`). */
|
|
115
|
+
setLeftAllowed: (allowed: boolean) => void;
|
|
116
|
+
/** The storage prefix (`options.storagePrefix`): the floating window's chrome keeps its place under `<prefix>.window` (12/11/2026). */
|
|
117
|
+
storagePrefix: string;
|
|
89
118
|
}
|
|
90
119
|
|
|
91
120
|
const Ctx = createContext<AssistantDockApi | null>(null);
|
|
@@ -95,7 +124,10 @@ const Ctx = createContext<AssistantDockApi | null>(null);
|
|
|
95
124
|
* See `./dock.ts` for the transition rules and why they exist.
|
|
96
125
|
*/
|
|
97
126
|
export function AssistantProvider({ options, children }: { options?: AssistantOptions; children: ReactNode }) {
|
|
98
|
-
|
|
127
|
+
// The place a person who never chose one gets is the surface's (`defaultShape`), from the first render: a press before the stored
|
|
128
|
+
// choice is read already opens it there.
|
|
129
|
+
const [state, dispatch] = useReducer(assistantDockReducer, options?.defaultShape,
|
|
130
|
+
(shape?: AssistantFloatShape) => (shape ? { ...initialAssistantDockState, floatShape: shape } : initialAssistantDockState));
|
|
99
131
|
// Read through a ref: the options object is usually built inline, and the effects below must not
|
|
100
132
|
// re-subscribe (or re-read storage) every render because of it.
|
|
101
133
|
const opts = useRef<Required<AssistantOptions>>({ ...DEFAULTS, ...options });
|
|
@@ -106,6 +138,8 @@ export function AssistantProvider({ options, children }: { options?: AssistantOp
|
|
|
106
138
|
// briefly alive, and a blind "clear on unmount" would leave the assistant reading an empty screen.
|
|
107
139
|
const factsOwner = useRef<string>("");
|
|
108
140
|
const [pageFacts, setPageFacts] = useState<string[]>([]);
|
|
141
|
+
/** The stored state has been read (the mount effect below): until then the load's open is not decided. */
|
|
142
|
+
const [restored, setRestored] = useState(false);
|
|
109
143
|
const publishPageFacts = useCallback((owner: string, facts: string[]) => {
|
|
110
144
|
factsOwner.current = owner;
|
|
111
145
|
setPageFacts(facts);
|
|
@@ -144,16 +178,36 @@ export function AssistantProvider({ options, children }: { options?: AssistantOp
|
|
|
144
178
|
restore({ type: "slide", offsetRight: rawOffset, ...offsetBounds() });
|
|
145
179
|
}
|
|
146
180
|
// The working shape outlives a reload: `lastMode` cannot stand in for it, since opening full screen overwrites it.
|
|
147
|
-
const
|
|
148
|
-
|
|
181
|
+
const placeKey = storageKey(opts.current.storagePrefix, "place");
|
|
182
|
+
let chosen = window.localStorage.getItem(placeKey);
|
|
183
|
+
if (chosen === null) {
|
|
184
|
+
// The key before `place` (see storageKey): its "dock" was a choice and is kept; its "side" may not have been, so it is not read.
|
|
185
|
+
const old = window.localStorage.getItem(storageKey(opts.current.storagePrefix, "shape"));
|
|
186
|
+
if (old === "dock") { chosen = old; window.localStorage.setItem(placeKey, old); }
|
|
187
|
+
}
|
|
188
|
+
window.localStorage.removeItem(storageKey(opts.current.storagePrefix, "shape"));
|
|
189
|
+
// `?? `: a surface may pass `defaultShape: undefined`, which the options spread lets through over the kit's default.
|
|
190
|
+
const shape = chosen === "side" || chosen === "dock" || chosen === "left" ? chosen : opts.current.defaultShape ?? initialAssistantDockState.floatShape;
|
|
191
|
+
restore({ type: "restore-float", shape });
|
|
149
192
|
// The pre-0.8.0 key: never read again (it holds the old default, not a choice) — drop it so storage has one answer.
|
|
150
193
|
window.localStorage.removeItem(`${opts.current.storagePrefix}.floatShape`);
|
|
151
194
|
const storedSide = Number(window.localStorage.getItem(storageKey(opts.current.storagePrefix, "sideWidth")));
|
|
152
195
|
if (Number.isFinite(storedSide) && storedSide > 0) {
|
|
153
196
|
requestedSide.current = storedSide;
|
|
154
|
-
|
|
197
|
+
// Against the room of the place it will open in: a left panel's beside the rail, not main's left edge, which the left panel's
|
|
198
|
+
// hold (hold.ts) has already moved over by the panel (600 stored at 1440 restored as 380, then 600 again: CLS 0.2).
|
|
199
|
+
restore({ type: "side-resize", width: storedSide, available: sideAvailable(shape === "left") });
|
|
155
200
|
}
|
|
201
|
+
// THE LEFT PANEL IS OPEN BY DEFAULT (12/11/2026, Chris: "ai chat mặc định mở, nằm ở bên trái"): a person whose place is the left
|
|
202
|
+
// panel, chosen or the surface's `defaultShape` (the admin's), finds it open when the app loads, beside the page, not folded away. Not on the assistant's own page (that is full
|
|
203
|
+
// screen), not when they closed or folded it earlier in this tab (`presentation` in sessionStorage, below), and only into the
|
|
204
|
+
// left panel itself: the host, mounted by this, says before its first paint whether it offers the panel here (the window, a page
|
|
205
|
+
// an editor covers), and the reducer opens it or leaves it closed, never a stand-in popup (dock.ts `opensLeft`).
|
|
206
|
+
const closedHere = window.sessionStorage.getItem(storageKey(opts.current.storagePrefix, "presentation"));
|
|
207
|
+
if (shape === "left" && window.matchMedia?.(SIDE_FITS_QUERY).matches && !opts.current.isOnFullPage()
|
|
208
|
+
&& closedHere !== "hidden" && closedHere !== "mini") restore({ type: "open-left-on-load" });
|
|
156
209
|
} catch { /* private mode — defaults are fine */ }
|
|
210
|
+
startTransition(() => setRestored(true));
|
|
157
211
|
}), []);
|
|
158
212
|
|
|
159
213
|
/**
|
|
@@ -168,6 +222,9 @@ export function AssistantProvider({ options, children }: { options?: AssistantOp
|
|
|
168
222
|
const requestedOffset = useRef(DOCK_DEFAULT_OFFSET_RIGHT);
|
|
169
223
|
/** …and the same for the side panel's width: a width chosen on a 27" screen comes back there. */
|
|
170
224
|
const requestedSide = useRef(SIDE_DEFAULT_WIDTH);
|
|
225
|
+
/** Whether the left panel is up, for the measures taken outside a render (the resize listener, a drag). */
|
|
226
|
+
const leftNow = useRef(false);
|
|
227
|
+
leftNow.current = state.presentation === "left";
|
|
171
228
|
|
|
172
229
|
/**
|
|
173
230
|
* How far the popup may travel in THIS window.
|
|
@@ -193,7 +250,7 @@ export function AssistantProvider({ options, children }: { options?: AssistantOp
|
|
|
193
250
|
// …and sideways too. `requestedOffset` was being written and never read, so a window that got
|
|
194
251
|
// narrower left the popup where a wider one had allowed it: on the rail, or past the edge.
|
|
195
252
|
dispatch({ type: "slide", offsetRight: requestedOffset.current, ...offsetBounds() });
|
|
196
|
-
dispatch({ type: "side-resize", width: requestedSide.current, available: sideAvailable() });
|
|
253
|
+
dispatch({ type: "side-resize", width: requestedSide.current, available: sideAvailable(leftNow.current) });
|
|
197
254
|
};
|
|
198
255
|
window.addEventListener("resize", onResize);
|
|
199
256
|
return () => window.removeEventListener("resize", onResize);
|
|
@@ -217,7 +274,7 @@ export function AssistantProvider({ options, children }: { options?: AssistantOp
|
|
|
217
274
|
|
|
218
275
|
const setSideWidth = useCallback((width: number) => {
|
|
219
276
|
requestedSide.current = Math.round(width);
|
|
220
|
-
dispatch({ type: "side-resize", width, available: sideAvailable() });
|
|
277
|
+
dispatch({ type: "side-resize", width, available: sideAvailable(leftNow.current) });
|
|
221
278
|
try { window.localStorage.setItem(storageKey(opts.current.storagePrefix, "sideWidth"), String(Math.round(width))); } catch { /* best-effort */ }
|
|
222
279
|
}, []);
|
|
223
280
|
|
|
@@ -243,14 +300,25 @@ export function AssistantProvider({ options, children }: { options?: AssistantOp
|
|
|
243
300
|
// write landed between two restores and turned a saved "dock" back into "side" on every reload (review #3744).
|
|
244
301
|
const sideAllowedNow = useRef(false);
|
|
245
302
|
sideAllowedNow.current = state.sideAllowed;
|
|
303
|
+
const leftAllowedNow = useRef(false);
|
|
304
|
+
leftAllowedNow.current = state.leftAllowed;
|
|
246
305
|
const saveShape = useCallback((shape: AssistantFloatShape) => {
|
|
247
|
-
try { window.localStorage.setItem(storageKey(opts.current.storagePrefix, "
|
|
306
|
+
try { window.localStorage.setItem(storageKey(opts.current.storagePrefix, "place"), shape); } catch { /* best-effort */ }
|
|
248
307
|
}, []);
|
|
249
308
|
|
|
250
309
|
useEffect(() => {
|
|
251
|
-
if (state.presentation !== "full" && state.presentation !== "dock" && state.presentation !== "side") return;
|
|
310
|
+
if (state.presentation !== "full" && state.presentation !== "dock" && state.presentation !== "side" && state.presentation !== "left") return;
|
|
252
311
|
try { window.localStorage.setItem(storageKey(opts.current.storagePrefix, "lastMode"), state.presentation); } catch { /* best-effort */ }
|
|
253
312
|
}, [state.presentation]);
|
|
313
|
+
// Where it is in THIS tab, once it has been on screen (the plain frame keeps the same key): the left panel's open-on-load above
|
|
314
|
+
// leaves it closed after the person closed or folded it here. Not written before it was first shown: a tab that never had it on
|
|
315
|
+
// screen has nothing to say (mounted is not enough: the load's wait for the left panel mounts it closed, `opensLeft`).
|
|
316
|
+
const shownOnce = useRef(false);
|
|
317
|
+
useEffect(() => {
|
|
318
|
+
if (state.presentation !== "hidden") shownOnce.current = true;
|
|
319
|
+
if (!shownOnce.current) return;
|
|
320
|
+
try { window.sessionStorage.setItem(storageKey(opts.current.storagePrefix, "presentation"), state.presentation); } catch { /* best-effort */ }
|
|
321
|
+
}, [state.presentation]);
|
|
254
322
|
|
|
255
323
|
/**
|
|
256
324
|
* Intercept the rail's Assistant link when the popup is what they last used.
|
|
@@ -277,7 +345,7 @@ export function AssistantProvider({ options, children }: { options?: AssistantOp
|
|
|
277
345
|
// Any OTHER link to the full chat ("Open in chat" in a page's content) keeps the old rule: it navigates unless
|
|
278
346
|
// the person last worked in the popup or the panel (review #3744: it was swallowed for every fresh browser).
|
|
279
347
|
const rail = !!anchor.closest(".gnav-assistant");
|
|
280
|
-
if (rail ? last === "full" : last !== "dock" && last !== "side") return;
|
|
348
|
+
if (rail ? last === "full" : last !== "dock" && last !== "side" && last !== "left") return;
|
|
281
349
|
e.preventDefault();
|
|
282
350
|
e.stopPropagation();
|
|
283
351
|
dispatch({ type: "reopen" });
|
|
@@ -308,21 +376,37 @@ export function AssistantProvider({ options, children }: { options?: AssistantOp
|
|
|
308
376
|
// was clamped against whatever window it was last drawn in (or never, on a first open), and a resize is the only
|
|
309
377
|
// other moment that re-clamps.
|
|
310
378
|
useEffect(() => {
|
|
311
|
-
if (state.presentation === "side"
|
|
379
|
+
if (state.presentation === "side" || state.presentation === "left") {
|
|
380
|
+
dispatch({ type: "side-resize", width: requestedSide.current, available: sideAvailable(state.presentation === "left") });
|
|
381
|
+
}
|
|
312
382
|
}, [state.presentation]);
|
|
313
383
|
|
|
384
|
+
// The left panel makes room the same way, on the other side: `<prefix>-left` and its own width variable (LEFT_WIDTH_VAR).
|
|
314
385
|
useEffect(() => {
|
|
315
386
|
const p = opts.current.bodyClassPrefix;
|
|
316
|
-
const
|
|
317
|
-
|
|
318
|
-
|
|
387
|
+
const side = state.presentation === "side";
|
|
388
|
+
const left = state.presentation === "left";
|
|
389
|
+
document.body.classList.toggle(`${p}-side`, side);
|
|
390
|
+
document.body.classList.toggle(`${p}-left`, left);
|
|
391
|
+
if (side) document.body.style.setProperty(SIDE_WIDTH_VAR, `${state.sideWidth}px`);
|
|
319
392
|
else document.body.style.removeProperty(SIDE_WIDTH_VAR);
|
|
393
|
+
if (left) document.body.style.setProperty(LEFT_WIDTH_VAR, `${state.sideWidth}px`);
|
|
394
|
+
else document.body.style.removeProperty(LEFT_WIDTH_VAR);
|
|
320
395
|
return () => {
|
|
321
|
-
document.body.classList.remove(`${p}-side`);
|
|
396
|
+
document.body.classList.remove(`${p}-side`, `${p}-left`);
|
|
322
397
|
document.body.style.removeProperty(SIDE_WIDTH_VAR);
|
|
398
|
+
document.body.style.removeProperty(LEFT_WIDTH_VAR);
|
|
323
399
|
};
|
|
324
400
|
}, [state.presentation, state.sideWidth]);
|
|
325
401
|
|
|
402
|
+
// The left panel's place held from the first paint (assistant/hold.ts) is given back once the load's open is decided: the stored state
|
|
403
|
+
// read, and the host's word heard (`opensLeft`). After the body-class effect above, so a panel that opened already has its room.
|
|
404
|
+
useEffect(() => {
|
|
405
|
+
if (!restored || state.opensLeft) return;
|
|
406
|
+
document.documentElement.removeAttribute(ASSISTANT_HOLD_ATTR);
|
|
407
|
+
document.documentElement.style.removeProperty(LEFT_WIDTH_VAR);
|
|
408
|
+
}, [restored, state.opensLeft, state.presentation]);
|
|
409
|
+
|
|
326
410
|
// Every action is identity-STABLE (dispatch is). Children register these as callbacks and one of
|
|
327
411
|
// them — the chat's busy reporter — is read in an unmount cleanup, where a changing identity would
|
|
328
412
|
// fire a spurious "the run ended" on every state change.
|
|
@@ -331,9 +415,11 @@ export function AssistantProvider({ options, children }: { options?: AssistantOp
|
|
|
331
415
|
const openDock = useCallback(() => { dispatch({ type: "dock" }); saveShape("dock"); }, [saveShape]);
|
|
332
416
|
// Not offered here (narrow window, host without the panel): the reducer gives the popup and nothing is recorded.
|
|
333
417
|
const openSide = useCallback(() => { dispatch({ type: "side" }); if (sideAllowedNow.current) saveShape("side"); }, [saveShape]);
|
|
418
|
+
const openLeft = useCallback(() => { dispatch({ type: "left" }); if (leftAllowedNow.current) saveShape("left"); }, [saveShape]);
|
|
334
419
|
const reopen = useCallback(() => dispatch({ type: "reopen" }), []);
|
|
335
420
|
// Urgent, not a transition like the restore above: the host registers it before paint on the first open (host.tsx).
|
|
336
421
|
const setSideAllowed = useCallback((allowed: boolean) => dispatch({ type: "side-allowed", allowed }), []);
|
|
422
|
+
const setLeftAllowed = useCallback((allowed: boolean) => dispatch({ type: "left-allowed", allowed }), []);
|
|
337
423
|
const minimize = useCallback(() => dispatch({ type: "minimize" }), []);
|
|
338
424
|
const dismiss = useCallback(() => dispatch({ type: "dismiss" }), []);
|
|
339
425
|
const setBusy = useCallback((busy: boolean) => dispatch({ type: "busy", busy }), []);
|
|
@@ -341,10 +427,21 @@ export function AssistantProvider({ options, children }: { options?: AssistantOp
|
|
|
341
427
|
const api = useMemo<AssistantDockApi>(() => ({
|
|
342
428
|
...state,
|
|
343
429
|
pageFacts, publishPageFacts, retractPageFacts,
|
|
344
|
-
enterFull, leaveFull, openDock, openSide, reopen, minimize, dismiss, setBusy, setDockHeight, setDockOffsetRight, setSideWidth,
|
|
345
|
-
|
|
430
|
+
enterFull, leaveFull, openDock, openSide, openLeft, reopen, minimize, dismiss, setBusy, setDockHeight, setDockOffsetRight, setSideWidth,
|
|
431
|
+
setSideAllowed, setLeftAllowed, storagePrefix: opts.current.storagePrefix,
|
|
432
|
+
}), [state, pageFacts, publishPageFacts, retractPageFacts, enterFull, leaveFull, openDock, openSide, openLeft, reopen, minimize, dismiss, setBusy,
|
|
433
|
+
setDockHeight, setDockOffsetRight, setSideWidth, setSideAllowed, setLeftAllowed]);
|
|
434
|
+
|
|
435
|
+
return <Ctx.Provider value={api}><PresentationCtx.Provider value={state.presentation}>{children}</PresentationCtx.Provider></Ctx.Provider>;
|
|
436
|
+
}
|
|
346
437
|
|
|
347
|
-
|
|
438
|
+
/**
|
|
439
|
+
* Where the assistant is drawn right now, and nothing else (12/11/2026). For a shell that lays itself out around it: the admin
|
|
440
|
+
* folds its rail to icons while the chat stands on the LEFT and opens it again when the chat closes or moves. Changes only when
|
|
441
|
+
* the shape does. Outside a provider: "hidden".
|
|
442
|
+
*/
|
|
443
|
+
export function useAssistantPresentation(): AssistantPresentation {
|
|
444
|
+
return useContext(PresentationCtx);
|
|
348
445
|
}
|
|
349
446
|
|
|
350
447
|
export function useAssistant(): AssistantDockApi {
|
|
@@ -13,8 +13,16 @@
|
|
|
13
13
|
* sessions themselves, and what opening, renaming, pinning, deleting or exporting one does. Those
|
|
14
14
|
* are the surface's, through callbacks. Collapse and keyboard shortcuts are the surface's too (the
|
|
15
15
|
* admin only lets its full-screen page own the keyboard).
|
|
16
|
+
*
|
|
17
|
+
* Its WIDTH is the rail's (13/11/2026, Chris: "cái chat ở full mode ko có resize cái panel bên trái danh sách chat ấy"): the rail is a
|
|
18
|
+
* tray (../tray.tsx), with the tray's seam on its right edge, dragged or moved by the keys, the width kept per browser (`widthKey`).
|
|
19
|
+
* tray.css places it, and only where the rail is a column of threads: not collapsed, not at phone width.
|
|
16
20
|
*/
|
|
17
|
-
|
|
21
|
+
// The rail's width and its seam are placed by the tray's sheet (tray.tsx imports it too; named here because the rail's rules are in it).
|
|
22
|
+
import "../tray.css";
|
|
23
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode } from "react";
|
|
24
|
+
import { TrayEdge, useTrayWidth, type TraySize } from "../tray";
|
|
25
|
+
import { TraySearch } from "../tray-search";
|
|
18
26
|
|
|
19
27
|
/** One conversation in the rail. `updatedAt` is epoch ms. */
|
|
20
28
|
export interface AssistantSession {
|
|
@@ -75,6 +83,8 @@ export interface SessionRailLabels {
|
|
|
75
83
|
/** Relative time, and the locale for dates older than a week. */
|
|
76
84
|
justNow: string; minutesAgo: (m: number) => string; hoursAgo: (h: number) => string; daysAgo: (d: number) => string;
|
|
77
85
|
dateLocale: string;
|
|
86
|
+
/** The seam on the rail's right edge. */
|
|
87
|
+
resize: string;
|
|
78
88
|
/** The popup's open-chat tabs. */
|
|
79
89
|
openChats: string; newChatN: (n: number) => string; tabWorking: (title: string) => string;
|
|
80
90
|
closeChat: string; closeChatRunning: string; closeChatSr: string; closeChatRunningSr: string;
|
|
@@ -87,12 +97,17 @@ export const SESSION_RAIL_EN: SessionRailLabels = {
|
|
|
87
97
|
working: "working", options: "Options", save: "Save", cancel: "Cancel",
|
|
88
98
|
pin: "Pin", unpin: "Unpin", rename: "Rename", exportMarkdown: "Export Markdown", remove: "Delete", confirmRemove: "Delete this chat?",
|
|
89
99
|
justNow: "just now", minutesAgo: (m) => `${m} min ago`, hoursAgo: (h) => `${h} hr ago`,
|
|
90
|
-
daysAgo: (d) => `${d} day${d > 1 ? "s" : ""} ago`, dateLocale: "en-US",
|
|
100
|
+
daysAgo: (d) => `${d} day${d > 1 ? "s" : ""} ago`, dateLocale: "en-US", resize: "Resize the list",
|
|
91
101
|
openChats: "Open chats", newChatN: (n) => `New chat ${n}`, tabWorking: (t) => `${t} — working`,
|
|
92
102
|
closeChat: "Close this chat", closeChatRunning: "Working — closing this stops it",
|
|
93
103
|
closeChatSr: "Close this chat", closeChatRunningSr: "Close and stop the run",
|
|
94
104
|
};
|
|
95
105
|
|
|
106
|
+
/** The rail's widths (a tray's, ../tray.tsx): the tray's range, and the 264px it has always opened at. session-rail-plain.js says the same. */
|
|
107
|
+
export const SESSION_RAIL_SIZE: TraySize = { min: 240, max: 480, initial: 264 };
|
|
108
|
+
/** Where the rail's width is kept unless the surface names its own key (`widthKey`). */
|
|
109
|
+
export const SESSION_RAIL_WIDTH_KEY = "gemboss.assistant.rail";
|
|
110
|
+
|
|
96
111
|
/** Short relative time for the thread list. */
|
|
97
112
|
export function relativeTime(ts: number, L: SessionRailLabels = SESSION_RAIL_EN, now = Date.now()): string {
|
|
98
113
|
const m = Math.floor((now - ts) / 60000);
|
|
@@ -142,8 +157,8 @@ export function groupSessions(sessions: AssistantSession[], L: SessionRailLabels
|
|
|
142
157
|
*/
|
|
143
158
|
export function SessionRail({
|
|
144
159
|
sessions, unlistedIds = [], activeId, pendingId, busyIds = [], collapsed, onToggleCollapsed,
|
|
145
|
-
onNewChat, newChatTitle, onOpen, onRename, onTogglePin, onDelete, onExport, head, top, footer, searchRef, searchShown = true, onSearchDone,
|
|
146
|
-
labels, icons, titleMaxLength = 200,
|
|
160
|
+
onNewChat, newChatTitle, onOpen, onRename, onTogglePin, onDelete, onExport, head, top, footer, searchRef, searchReturnTo, searchShown = true, onSearchDone,
|
|
161
|
+
labels, icons, titleMaxLength = 200, widthKey = SESSION_RAIL_WIDTH_KEY,
|
|
147
162
|
}: {
|
|
148
163
|
/** Pinned-first, newest-first — the order the rail shows them in. */
|
|
149
164
|
sessions: AssistantSession[];
|
|
@@ -185,6 +200,10 @@ export function SessionRail({
|
|
|
185
200
|
footer?: ReactNode;
|
|
186
201
|
/** The search input, so the surface can focus it from a shortcut. */
|
|
187
202
|
searchRef?: React.Ref<HTMLInputElement>;
|
|
203
|
+
/** Where Escape and the box's × put the focus: the surface's own search button (`head`), not the page (TraySearch `returnTo`). */
|
|
204
|
+
searchReturnTo?: React.RefObject<HTMLElement | null>;
|
|
205
|
+
/** Where the width a person sets is kept in this browser (default SESSION_RAIL_WIDTH_KEY). */
|
|
206
|
+
widthKey?: string;
|
|
188
207
|
labels?: Partial<SessionRailLabels>;
|
|
189
208
|
icons?: Partial<SessionRailIcons>;
|
|
190
209
|
}) {
|
|
@@ -344,7 +363,7 @@ export function SessionRail({
|
|
|
344
363
|
);
|
|
345
364
|
|
|
346
365
|
return (
|
|
347
|
-
<
|
|
366
|
+
<RailBox collapsed={collapsed} widthKey={widthKey} label={L.resize}>
|
|
348
367
|
<div className="gemboss-assistant-rail-top">
|
|
349
368
|
{head ?? <>
|
|
350
369
|
<button type="button" className="gemboss-assistant-newchat" onClick={onNewChat} title={newChatTitle ?? L.newChat}>
|
|
@@ -364,21 +383,20 @@ export function SessionRail({
|
|
|
364
383
|
</div>
|
|
365
384
|
|
|
366
385
|
{sessions.length > 0 && (searchShown || query) && (
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
{
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
</div>
|
|
386
|
+
// The kit's tray search (../tray-search): the same box the Inbox's list opens from its icon.
|
|
387
|
+
<TraySearch
|
|
388
|
+
value={query}
|
|
389
|
+
onChange={setQuery}
|
|
390
|
+
onDone={() => onSearchDone?.()}
|
|
391
|
+
inputRef={searchRef}
|
|
392
|
+
returnTo={searchReturnTo}
|
|
393
|
+
placeholder={L.searchPlaceholder}
|
|
394
|
+
label={L.searchLabel}
|
|
395
|
+
clearLabel={L.clearSearch}
|
|
396
|
+
hint="/"
|
|
397
|
+
icon={<I.search />}
|
|
398
|
+
closeIcon={<I.close />}
|
|
399
|
+
/>
|
|
382
400
|
)}
|
|
383
401
|
|
|
384
402
|
{top}
|
|
@@ -401,6 +419,22 @@ export function SessionRail({
|
|
|
401
419
|
</div>
|
|
402
420
|
|
|
403
421
|
{footer}
|
|
422
|
+
</RailBox>
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* The rail's box: the aside, its width (a tray's, useTrayWidth: its room is the layout it stands in, beside the page's floor) and the
|
|
428
|
+
* seam last, none on the 60px strip. Its own component so a drag frame or a new room re-renders this box and not the threads: the
|
|
429
|
+
* rail's content comes in as `children`, the same elements on each of these renders (review of #7378).
|
|
430
|
+
*/
|
|
431
|
+
function RailBox({ collapsed, widthKey, label, children }: { collapsed: boolean; widthKey: string; label: string; children: ReactNode }) {
|
|
432
|
+
const tray = useTrayWidth<HTMLElement>({ storageKey: widthKey, size: SESSION_RAIL_SIZE, inParent: true });
|
|
433
|
+
return (
|
|
434
|
+
<aside ref={tray.ref} className={`gemboss-assistant-rail${collapsed ? " is-collapsed" : ""}`}
|
|
435
|
+
style={{ "--gb-tray-w": `${tray.shown}px`, "--gb-tray-min": `${SESSION_RAIL_SIZE.min}px` } as CSSProperties}>
|
|
436
|
+
{children}
|
|
437
|
+
{collapsed ? null : <TrayEdge tray={tray} label={label} />}
|
|
404
438
|
</aside>
|
|
405
439
|
);
|
|
406
440
|
}
|