Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/plugin-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -3341,6 +3341,15 @@ The tab workspace belongs to Channels, which supplies it with
slot. `ui.Tabs` is undefined while no enabled plugin provides it, so a page reads
it at render and falls back to its own layout.

`conversation.ui.Workspace` comes from the same provider. Its optional props
grow over time, so `conversation.workspaceSlots` names each one this host
renders as `true`. An older host lacks the flag, or the whole object, and
ignores the prop.
With `workspaceSlots.aside`, `aside` renders after the main tab's reader,
between the transcript and the side pane. The host gives it no width, frame or
scrolling. Its offset parent is the row of the reader and the aside, so a page
can watch that row's size to choose its own layout.

`open({ channelId, messageId })` opens the conversation at that message. The
shared `useMessageOpening` reader waits for verified history (cached rows
decide nothing), reads older pages until the message loads (at most 25 pages
Expand Down
6 changes: 5 additions & 1 deletion docs/plugin-authoring-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ Add `"host"` to `inject`, then:
Check that it exists before use. Channels supplies it through
`registerWorkspace`, with the same provider lifetime as `ui.Tabs`.
Set the page's `layout` to `"workspace"`. Pass
`{ id, session, scope, target, label, intro?, actions?, detail?, latestRequest? }`.
`{ id, session, scope, target, label, intro?, aside?, actions?, detail?, latestRequest? }`.
Set `target` to `{ channelId, threadId?, subthreadId?, messageId? }`. Omit
`threadId` for the channel timeline. Supply a thread ID to show the thread.
Add `subthreadId` to show and compose within a branch of that thread.
Expand All @@ -327,6 +327,10 @@ Add `"host"` to `inject`, then:
the signal to that opening. Omit it on Back or Forward. An aborted signal is
ignored, and an explicit `target.messageId` takes precedence.
`intro` supplies content at the start of history. It scrolls with the messages.
`aside` renders after the main tab's reader, before the side pane, when
`ctx.conversation.workspaceSlots?.aside === true`; an older host ignores it.
It sets its own width. Its offset parent is the row of the reader and the
aside.
`actions` supplies
entries in the header's three-dot menu and the tab's context menu, with
`{ label, run() }`. `detail: { target, rootId? }` initially selects a panel
Expand Down
9 changes: 9 additions & 0 deletions src/bundled/channels/Channels.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@
.soloConversation {
container: solo-conversation / inline-size;
}
/* A workspace's main reader and the page's aside, which this row positions. */
.workspaceRow {
position: relative;
display: flex;
height: 100%;
min-width: 0;
min-height: 0;
overflow: hidden;
}
.workspaceReader {
flex: 1;
min-height: 0;
Expand Down
20 changes: 20 additions & 0 deletions src/bundled/channels/PageTabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,26 @@ it("a workspace owns its main reader, intro, menu, and no initial detail", async
expect(source).toHaveBeenCalledOnce();
});

it("a workspace places its aside after the main reader, in the reader's row", () => {
const f = fixture();
cleanup();
render(
<ConversationWorkspace
id="task"
session={f.session}
scope="origin:viewer"
target={{ channelId: "alpha" }}
label="Task"
host={f.host}
aside={<aside aria-label="Task dashboard" />}
/>,
);
const reader = screen.getByText("conversation in alpha", { exact: false });
const aside = screen.getByRole("complementary", { name: "Task dashboard" });
expect(reader.parentElement?.nextElementSibling).toBe(aside);
expect(screen.getByRole("tabpanel")).toContainElement(aside);
});

it.each([false, true])(
"a workspace requests composer focus unless another editor owns it (editing=%s)",
(editing) => {
Expand Down
3 changes: 2 additions & 1 deletion src/bundled/channels/PageTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ export function PageTabs({
),
actions: workspace?.actions,
content: workspace ? (
<div className={styles.conversation}>
<div className={styles.workspaceRow}>
<div className={styles.workspaceReader}>
{primaryTab &&
primaryChannel &&
Expand Down Expand Up @@ -573,6 +573,7 @@ export function PageTabs({
</p>
)}
</div>
{workspace.aside}
</div>
) : (
children(open, close, isOpen)
Expand Down
3 changes: 3 additions & 0 deletions src/features/conversation/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ export type ConversationWorkspaceProps = {
label: string;
/** Content at the start of history. It scrolls with the messages. */
intro?: ReactNode;
/** Content after the main tab's reader, before the side pane. It sets its
* own width; its offset parent is the row of the reader and the aside. */
aside?: ReactNode;
/** Actions in the pane's menu and the main tab's context menu. */
actions?: readonly { label: string; run(): void }[];
/** Select this panel on entry. Closing it keeps the main conversation. */
Expand Down
11 changes: 11 additions & 0 deletions src/features/conversation/service.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ it("provides ui.Tabs only while a plugin supplies the tab workspace", async () =
h.runtime.reconcile([]);
await vi.waitFor(() => expect(h.service.ui.Tabs).toBeUndefined());
});
it("tells plugins that ui.Workspace renders an aside", async () => {
let slots: unknown;
const h = harness({
inject: ["conversation"],
apply(ctx) {
slots = ctx.conversation.workspaceSlots;
},
});
h.runtime.reconcile([h.plugin]);
await vi.waitFor(() => expect(slots).toHaveProperty("aside", true));
});
it("bundled Emoji really registers a picker and a renderer, including reaction metadata", async () => {
const h = harness(emoji);
h.runtime.reconcile([h.plugin]);
Expand Down
8 changes: 8 additions & 0 deletions src/features/conversation/service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ export type Conversation = {
registerTabs(component: ComponentType<PageTabsProps>): void;
/** Provides `ui.Workspace` while the plugin runs; the first one wins. */
registerWorkspace(component: ComponentType<ConversationWorkspaceProps>): void;
/** The optional `ui.Workspace` props this host renders. An older host lacks
* a slot's flag, or the whole object, and ignores that prop. */
readonly workspaceSlots?: Readonly<{
aside?: true;
}>;
/** Solo chat icons; the sidebar shows the first one. */
chatIcons: ContributionReader<ChatIcon>;
/** Shows `component` as each Solo chat's sidebar icon while the providing
Expand Down Expand Up @@ -216,6 +221,9 @@ export class ConversationService extends Service implements Conversation {
readonly chatIcons;
private readonly chatIconEntries;
readonly ui: Conversation["ui"];
readonly workspaceSlots = Object.freeze({
aside: true,
});
constructor(ctx: Context) {
super(ctx, "conversation");
const attachments = createContributions<AttachmentRenderer>(ctx);
Expand Down
38 changes: 38 additions & 0 deletions tests/browser/conversation-workspace.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,44 @@ test("reselect uncovers the transcript and keeps the narrow reply dock available
await expect(side).toBeVisible();
});

test("an aside sits between the transcript and the side pane, positioned by their row", async ({
page,
app,
}) => {
await open(page, app);
const region = history(page);
await select(page, { channelId: "alpha" });
await expectBottom(page, region);
const replyTab = await openReplyTab(app, region);
const dock = page.locator("[data-panel-workspace]");
await expect(dock.getByRole("tab", { name: replyTab })).toBeVisible();

const aside = page.getByRole("complementary", { name: "Reader aside" });
// The page's content sets the aside's width.
await aside.evaluate((element) => {
element.style.width = "160px";
});
const layout = await aside.evaluate((element) => {
const box = (node) => node.getBoundingClientRect();
const row = element.offsetParent;
const history = document.querySelector(
'[aria-label="Channel message history"]',
);
return {
inRow: row === element.parentElement && row.contains(history),
aside: box(element),
row: box(row),
history: box(history),
dock: box(document.querySelector("[data-panel-workspace]")),
};
});
expect(layout.inRow).toBe(true);
expect(layout.aside.width).toBe(160);
expect(layout.history.right).toBeLessThanOrEqual(layout.aside.left);
expect(layout.aside.right).toBe(layout.row.right);
expect(layout.aside.right).toBeLessThanOrEqual(layout.dock.left);
});

test("a gesture retires a queued latest request before new messages arrive", async ({
page,
app,
Expand Down
4 changes: 4 additions & 0 deletions tests/browser/plugin-fixtures.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@ export const fixturePlugins: readonly BundledPlugin[] = [
scope={connection.scope}
label="Transcript fixture"
target={target}
// Zero width, so only the aside test changes the layout.
aside={
<aside aria-label="Reader aside" style={{ width: 0 }} />
}
latestRequest={
request && request.opening === opening
? request.signal
Expand Down
Loading