style(webui): refine Markdown reading typography (#6568)
* style(webui): refine Markdown reading typography * fix(webui): stabilize composer and typography checks
This commit is contained in:
1 parent
0c92d5bb03
commit
e6127aa324
17 files changed
+307
-100
No files matched your search
@@ -52,7 +52,7 @@ test("custom reading size previews, persists and survives preset changes", async
|
||||
await page.reload();
|
||||
await expect(input).toHaveValue("24");
|
||||
await page.getByRole("radio", { name: "Small reading text", exact: true }).click();
|
||||
await expect(paragraph).toHaveCSS("font-size", "16px");
|
||||
await expect(paragraph).toHaveCSS("font-size", "15px");
|
||||
await page.getByRole("spinbutton", { name: "Custom text size", exact: true }).click();
|
||||
await expect(input).toHaveValue("24");
|
||||
await expect(paragraph).toHaveCSS("font-size", "24px");
|
||||
|
||||
@@ -61,9 +61,7 @@ for (const width of [1440, 390]) {
|
||||
const bubble = page.locator("[data-user-text-bubble]");
|
||||
const text = bubble.locator("p");
|
||||
const trigger = page.locator("[data-message-block-menu-trigger]");
|
||||
const fontSize = width === 390
|
||||
? { small: 15, standard: 16, large: 18 }[size]
|
||||
: { small: 16, standard: 18, large: 20 }[size];
|
||||
const fontSize = { small: 15, standard: 16, large: 18 }[size];
|
||||
await expect(text).toHaveCSS("font-size", `${fontSize}px`);
|
||||
await bubble.hover();
|
||||
await expect(trigger).toBeVisible();
|
||||
|
||||
@@ -147,3 +147,56 @@ test("idle voice and ready send remain distinct from the composer in both themes
|
||||
}
|
||||
await test.info().attach("action-contrast", { body: JSON.stringify(measurements, null, 2), contentType: "application/json" });
|
||||
});
|
||||
|
||||
|
||||
test("a long mobile placeholder remains available without shifting the composer", async ({ browser, baseURL }) => {
|
||||
const context = await browser.newContext({ baseURL, viewport: { width: 314, height: 844 }, hasTouch: true, isMobile: true, reducedMotion: "reduce" });
|
||||
try {
|
||||
const page = await context.newPage();
|
||||
await page.addInitScript(() => localStorage.setItem("nanobot.locale", "fr"));
|
||||
await page.goto("/browser/fixture.html?case=composer-action&composerVariant=thread");
|
||||
await page.evaluate(() => document.fonts.ready);
|
||||
const input = page.locator(".thread-composer-input textarea");
|
||||
const action = page.locator(".composer-primary-action");
|
||||
await expect(input).toHaveAttribute("placeholder", /compétences/);
|
||||
const placeholder = (await input.getAttribute("placeholder"))!;
|
||||
await expect(input).toHaveAttribute("aria-description", placeholder);
|
||||
await expect(page.getByRole("tooltip")).toHaveCount(0);
|
||||
const before = (await action.boundingBox())!;
|
||||
const initialHeight = await input.evaluate(node => node.clientHeight);
|
||||
|
||||
await input.tap();
|
||||
const hint = page.getByRole("tooltip");
|
||||
await expect(hint).toHaveText(placeholder);
|
||||
const hintSurface = page.locator('[data-radix-popper-content-wrapper] [data-side]').first();
|
||||
const composer = page.locator(".thread-composer-form");
|
||||
await expect.poll(async () => {
|
||||
const [hintBox, composerBox] = await Promise.all([hintSurface.boundingBox(), composer.boundingBox()]);
|
||||
return !!hintBox && !!composerBox && (hintBox.y + hintBox.height <= composerBox.y || hintBox.y >= composerBox.y + composerBox.height);
|
||||
}).toBe(true);
|
||||
expect(await action.boundingBox()).toEqual(before);
|
||||
|
||||
await input.fill("Bonjour");
|
||||
await expect(hint).toHaveCount(0);
|
||||
expect(await action.boundingBox()).toEqual(before);
|
||||
await input.fill("Première ligne\nDeuxième ligne\nTroisième ligne");
|
||||
await expect.poll(() => input.evaluate(node => node.clientHeight)).toBeGreaterThan(initialHeight);
|
||||
await input.fill("");
|
||||
await expect(hint).toHaveText(placeholder);
|
||||
await expect.poll(() => input.evaluate(node => node.clientHeight)).toBe(initialHeight);
|
||||
expect(await action.boundingBox()).toEqual(before);
|
||||
await input.press("Escape");
|
||||
await expect(hint).toHaveCount(0);
|
||||
|
||||
await page.locator(".thread-composer-footer button").first().focus();
|
||||
await page.keyboard.press("Shift+Tab");
|
||||
await expect(input).toBeFocused();
|
||||
await expect(hint).toHaveText(placeholder);
|
||||
const box = (await input.boundingBox())!;
|
||||
await page.mouse.move(box.x + 5, box.y + 5);
|
||||
await page.mouse.move(1, 800);
|
||||
await expect(hint).toHaveCount(0);
|
||||
} finally {
|
||||
await context.close();
|
||||
}
|
||||
});
|
||||
@@ -117,9 +117,9 @@ test("multiline drafts resize after reading typography changes", async ({ page }
|
||||
await input.fill("First line\nSecond line\nThird line");
|
||||
const standardHeight = await input.evaluate(node => node.clientHeight);
|
||||
const sizes = [
|
||||
["large", "Large reading text", 20],
|
||||
["large", "Large reading text", 18],
|
||||
["small", "Small reading text", 16],
|
||||
["standard", "Standard reading text", 18],
|
||||
["standard", "Standard reading text", 16],
|
||||
] as const;
|
||||
for (const [size, label, fontSize] of sizes) {
|
||||
await page.getByRole("radio", { name: label, exact: true }).click();
|
||||
@@ -128,7 +128,6 @@ test("multiline drafts resize after reading typography changes", async ({ page }
|
||||
expect(await input.evaluate(node => node.scrollHeight <= node.clientHeight + 1)).toBe(true);
|
||||
const height = await input.evaluate(node => node.clientHeight);
|
||||
if (size === "large") expect(height).toBeGreaterThan(standardHeight);
|
||||
else if (size === "small") expect(height).toBeLessThan(standardHeight);
|
||||
else expect(height).toBe(standardHeight);
|
||||
}
|
||||
});
|
||||
@@ -5,7 +5,7 @@ import { MarkdownText } from "@/components/MarkdownText";
|
||||
export function DisplayMathFixture() {
|
||||
const [step, setStep] = useState(0);
|
||||
const [streaming, setStreaming] = useState(true);
|
||||
const terms = step === 0 ? "x + y" : Array.from({ length: 24 }, (_, index) => `x_{${index}}`).join(" + ");
|
||||
const terms = step === 0 ? "x + y" : Array.from({ length: 36 }, (_, index) => `x_{${index}}`).join(" + ");
|
||||
const tag = step < 2 ? "1" : "1000000";
|
||||
return <main className="mx-auto max-w-3xl p-6">
|
||||
<button onClick={() => setStep((value) => value + 1)}>Advance stream</button>
|
||||
|
||||
@@ -14,6 +14,7 @@ const createdAt = Date.now() / 1000;
|
||||
let streamLength = 0;
|
||||
let inputNumber = 0;
|
||||
const saveTasks = new URLSearchParams(location.search).has("saved");
|
||||
const historyParagraphs = new URLSearchParams(location.search).has("long-history") ? 20 : 12;
|
||||
const taskStorageKey = "fixture.subagent-dock.tasks";
|
||||
const taskLabels = new URLSearchParams(location.search).has("long-labels")
|
||||
? ["核对多轮任务完成后的归档位置、长标题换行与独立详情入口", "Review_the_responsive_subtask_panel_and_keyboard_focus_without_interrupting_running_work", "整理交互建议"]
|
||||
@@ -28,7 +29,7 @@ const tasks: SubagentTaskSnapshot[] = taskLabels.map((label, index) => ({
|
||||
const history: ThreadProjectionEvent[] = [
|
||||
{ event: "user_message", chat_id: chatId, projection_id: "preview-prompt", turn_id: turnId, text: "请让三个子任务分别检查实现、测试和交互。主对话继续讨论,不要等它们全部结束。", starts_turn: true },
|
||||
{ event: "message", chat_id: chatId, projection_id: "preview-answer", turn_id: turnId,
|
||||
text: "已经安排。你可以继续在这里交流,子任务会独立推进。\n\n**随时查看,不必回翻聊天**\n\n输入区上方的子任务入口会留在原位。点开可以查看每一路任务的状态、真实工具活动和最终结果。\n\n" + "主对话仍然可以正常输出和滚动。任务列表与消息区分别滚动,展开详情也不会取消正在执行的任务。\n\n".repeat(12) },
|
||||
text: "已经安排。你可以继续在这里交流,子任务会独立推进。\n\n**随时查看,不必回翻聊天**\n\n输入区上方的子任务入口会留在原位。点开可以查看每一路任务的状态、真实工具活动和最终结果。\n\n" + "主对话仍然可以正常输出和滚动。任务列表与消息区分别滚动,展开详情也不会取消正在执行的任务。\n\n".repeat(historyParagraphs) },
|
||||
];
|
||||
|
||||
function updateTask(index: number, patch: Partial<SubagentTaskSnapshot>) {
|
||||
|
||||
@@ -349,13 +349,12 @@ test("does not retire a completed list or detail while it is being read", async
|
||||
for (const width of [1440, 390]) {
|
||||
test(`keeps the reading position when results are archived and the live entry retires at ${width}px`, async ({ page }) => {
|
||||
await page.setViewportSize({ width, height: 900 });
|
||||
await page.goto("/browser/fixture.html?case=subagent-dock");
|
||||
await page.goto("/browser/fixture.html?case=subagent-dock&long-history");
|
||||
const body = page.getByTestId("thread-message-region");
|
||||
const paragraphs = body.getByText("主对话仍然可以正常输出和滚动。任务列表与消息区分别滚动,展开详情也不会取消正在执行的任务。", { exact: true });
|
||||
await expect(paragraphs).toHaveCount(12);
|
||||
await expect(paragraphs).toHaveCount(20);
|
||||
await settledMotion(body);
|
||||
const anchor = paragraphs.nth(6);
|
||||
await anchor.scrollIntoViewIfNeeded();
|
||||
const anchor = paragraphs.nth(13);
|
||||
await body.hover();
|
||||
await page.mouse.wheel(0, -160);
|
||||
await expect.poll(() => body.evaluate(node => node.scrollHeight - node.clientHeight - node.scrollTop)).toBeGreaterThan(100);
|
||||
|
||||
@@ -38,11 +38,12 @@ for (const narrow of [false, true]) {
|
||||
await expect(tables).toHaveCount(2);
|
||||
await expect(formulaTable.locator(".katex")).toHaveCount(7);
|
||||
await page.evaluate(() => document.fonts.ready);
|
||||
expect(await page.evaluate(() => Array.from(document.fonts).some((font) => font.family === "Open Sans" && font.status === "loaded"))).toBe(true);
|
||||
const observations = [];
|
||||
for (const [size, label, bodySize] of [
|
||||
["small", "阅读字号:小", narrow ? 15 : 16],
|
||||
["standard", "阅读字号:标准", narrow ? 16 : 18],
|
||||
["large", "阅读字号:大", narrow ? 18 : 20],
|
||||
["small", "阅读字号:小", 15],
|
||||
["standard", "阅读字号:标准", 16],
|
||||
["large", "阅读字号:大", 18],
|
||||
] as const) {
|
||||
await group.getByRole("radio", { name: label, exact: true }).click();
|
||||
await expect(page.locator("html")).toHaveAttribute("data-reading-text-size", size);
|
||||
@@ -50,13 +51,14 @@ for (const narrow of [false, true]) {
|
||||
await expect(paragraph).toHaveCSS("font-size", `${bodySize}px`);
|
||||
const body = await metrics(paragraph);
|
||||
expect(body.size).toBe(bodySize);
|
||||
expect(body.line).toBeCloseTo(bodySize * 1.8);
|
||||
expect(body.line).toBeCloseTo(bodySize * 1.6);
|
||||
expect(body.weight).toBe("400");
|
||||
expect(body.family).toContain("Open Sans");
|
||||
expect((await metrics(page.locator("[data-user-text-bubble] p"))).size).toBe(bodySize);
|
||||
for (const selector of ["blockquote", "ol > li", ".task-list-item"]) {
|
||||
expect((await metrics(page.locator(`.markdown-content ${selector}`).first())).size).toBe(bodySize);
|
||||
}
|
||||
for (const [selector, ratio] of [["h1", 1.5], ["h2", 1.25], ["h3", 1.125], ["h4", 1]] as const) {
|
||||
for (const [selector, ratio] of [["h1", 2], ["h2", 1.5], ["h3", 1.25], ["h4", 1.125]] as const) {
|
||||
const heading = await metrics(page.locator(`.markdown-content ${selector}`));
|
||||
expect(heading.size).toBeCloseTo(bodySize * ratio);
|
||||
expect(heading.weight).toBe("600");
|
||||
@@ -128,7 +130,7 @@ test("keyboard, tooltip, persistence and unchanged preferences", async ({ page }
|
||||
const large = page.getByRole("radio", { name: "Large reading text", exact: true });
|
||||
await expect(large).toBeFocused();
|
||||
await expect(large).toBeChecked();
|
||||
await expect(page.locator(".markdown-content p").first()).toHaveCSS("line-height", `${20 * 1.625}px`);
|
||||
await expect(page.locator(".markdown-content p").first()).toHaveCSS("line-height", `${18 * 1.6}px`);
|
||||
await page.reload();
|
||||
await expect(page.getByRole("radio", { name: "Large reading text", exact: true })).toBeChecked();
|
||||
expect(await page.evaluate(() => JSON.parse(localStorage.getItem("nanobot-webui.settings-preferences")!))).toMatchObject({
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
Copyright 2020 The Open Sans Project Authors (https://github.com/googlefonts/opensans)
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
https://scripts.sil.org/OFL
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font
|
||||
creation efforts of academic and linguistic communities, and to
|
||||
provide a free and open framework in which fonts may be shared and
|
||||
improved in partnership with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply to
|
||||
any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software
|
||||
components as distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to,
|
||||
deleting, or substituting -- in part or in whole -- any of the
|
||||
components of the Original Version, by changing formats or by porting
|
||||
the Font Software to a new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed,
|
||||
modify, redistribute, and sell modified and unmodified copies of the
|
||||
Font Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components, in
|
||||
Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the
|
||||
corresponding Copyright Holder. This restriction only applies to the
|
||||
primary font name as presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created using
|
||||
the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
Binary file not shown.
Binary file not shown.
@@ -29,10 +29,6 @@
|
||||
padding-inline: calc(var(--math-tag-width) + 1em);
|
||||
}
|
||||
|
||||
.markdown-content:has(.math-fit) {
|
||||
--cjk-line-height: 1.65;
|
||||
}
|
||||
|
||||
.markdown-content li .math-fit {
|
||||
margin-block: 0.3em 0.35em;
|
||||
}
|
||||
|
||||
@@ -831,9 +831,6 @@ export default function MarkdownTextRenderer({
|
||||
components={components}
|
||||
className={cn(
|
||||
"markdown-content prose max-w-none dark:prose-invert",
|
||||
"prose-headings:mt-4 prose-headings:mb-2 prose-headings:tracking-tight",
|
||||
"prose-p:my-2",
|
||||
"prose-ul:my-2 prose-ol:my-2 prose-li:my-0.5",
|
||||
"prose-blockquote:my-3 prose-blockquote:border-l-2 prose-blockquote:font-normal",
|
||||
"prose-blockquote:not-italic prose-blockquote:text-foreground/80",
|
||||
"prose-a:text-content-link prose-a:underline-offset-2 hover:prose-a:text-content-link-hover",
|
||||
|
||||
@@ -1119,6 +1119,9 @@ export function ThreadComposer({
|
||||
const [initialDraft] = useState(() => draftKey ? draftStore?.get(draftKey, persistDraft) : undefined);
|
||||
const [value, setValue] = useState(initialDraft?.text ?? "");
|
||||
const [composerFocused, setComposerFocused] = useState(false);
|
||||
const [placeholderHintRequested, setPlaceholderHintRequested] = useState(false);
|
||||
const [placeholderHintOpen, setPlaceholderHintOpen] = useState(false);
|
||||
const [placeholderHintBottomGap, setPlaceholderHintBottomGap] = useState(0);
|
||||
const blurFrame = useRef<number | null>(null);
|
||||
const [boundSessionMentions, setBoundSessionMentions] = useState<SessionMention[]>(
|
||||
initialDraft?.sessionMentions ?? [],
|
||||
@@ -1164,8 +1167,21 @@ export function ThreadComposer({
|
||||
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||
const mentionOverlayRef = useRef<HTMLDivElement>(null);
|
||||
const formRef = useRef<HTMLFormElement>(null);
|
||||
const tabFocusRequested = useRef(false);
|
||||
const [compactControls, setCompactControls] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
// Automatic session focus should not open the hint; keyboard navigation should.
|
||||
const onKeyDown = (event: KeyboardEvent) => { tabFocusRequested.current = event.key === "Tab"; };
|
||||
const onPointerDown = () => { tabFocusRequested.current = false; };
|
||||
document.addEventListener("keydown", onKeyDown, true);
|
||||
document.addEventListener("pointerdown", onPointerDown, true);
|
||||
return () => {
|
||||
document.removeEventListener("keydown", onKeyDown, true);
|
||||
document.removeEventListener("pointerdown", onPointerDown, true);
|
||||
};
|
||||
}, []);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const form = formRef.current;
|
||||
if (!form) return;
|
||||
@@ -1853,6 +1869,26 @@ export function ThreadComposer({
|
||||
if (input) autosizeTextarea(input);
|
||||
}, [readingTextSize, customReadingTextSize]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const input = textareaRef.current;
|
||||
if (!input || document.activeElement !== input || !placeholderHintRequested || input.value || !input.placeholder) {
|
||||
setPlaceholderHintOpen(false);
|
||||
return;
|
||||
}
|
||||
const form = formRef.current!;
|
||||
const measure = () => {
|
||||
setPlaceholderHintOpen(input.scrollWidth > input.clientWidth);
|
||||
setPlaceholderHintBottomGap(form.getBoundingClientRect().bottom - input.getBoundingClientRect().bottom);
|
||||
};
|
||||
measure();
|
||||
const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(measure);
|
||||
observer?.observe(input);
|
||||
observer?.observe(form);
|
||||
let active = true;
|
||||
void document.fonts?.ready.then(() => { if (active) measure(); });
|
||||
return () => { active = false; observer?.disconnect(); };
|
||||
}, [placeholderHintRequested, mentionInput.value, resolvedPlaceholder, sessionDragPreview, readingTextSize, customReadingTextSize]);
|
||||
|
||||
// Runs before paint so switching sessions never flashes stale draft text.
|
||||
useLayoutEffect(() => {
|
||||
if (previousPendingQueueKeyRef.current === pendingQueueKey) return;
|
||||
@@ -2739,38 +2775,65 @@ export function ThreadComposer({
|
||||
: null}
|
||||
/>
|
||||
) : null}
|
||||
<textarea
|
||||
ref={textareaRef}
|
||||
value={mentionInput.value}
|
||||
onFocus={() => {
|
||||
if (compactWhenIdle) setComposerFocused(true);
|
||||
}}
|
||||
onChange={mentionInput.onChange}
|
||||
onCompositionStart={mentionInput.onCompositionStart}
|
||||
onCompositionEnd={mentionInput.onCompositionEnd}
|
||||
onKeyDown={onKeyDown}
|
||||
onKeyUp={() => setCursorPosition(rawSelection().start)}
|
||||
onSelect={() => setCursorPosition(rawSelection().start)}
|
||||
onClick={() => setCursorPosition(rawSelection().start)}
|
||||
onCopy={mentionInput.onCopy}
|
||||
onCut={mentionInput.onCut}
|
||||
onScroll={(e) => {
|
||||
if (mentionOverlayRef.current) mentionOverlayRef.current.scrollTop = e.currentTarget.scrollTop;
|
||||
}}
|
||||
onPaste={onPaste}
|
||||
rows={1}
|
||||
enterKeyHint={hasCoarsePointer ? "enter" : undefined}
|
||||
placeholder={sessionDragPreview ? "" : resolvedPlaceholder}
|
||||
disabled={interactionDisabled}
|
||||
aria-label={inputAriaLabel ?? t("thread.composer.inputAria")}
|
||||
className={cn(
|
||||
inputTextClasses,
|
||||
"relative z-10 block caret-foreground placeholder:text-muted-foreground",
|
||||
"focus:outline-none focus-visible:outline-none",
|
||||
"disabled:cursor-not-allowed",
|
||||
hasInlineDecorations && "text-transparent selection:bg-primary/20",
|
||||
)}
|
||||
/>
|
||||
<TooltipProvider>
|
||||
<Tooltip open={placeholderHintOpen}>
|
||||
<TooltipTrigger asChild>
|
||||
<textarea
|
||||
ref={textareaRef}
|
||||
value={mentionInput.value}
|
||||
onFocus={(event) => {
|
||||
if (tabFocusRequested.current && !event.currentTarget.value) setPlaceholderHintRequested(true);
|
||||
tabFocusRequested.current = false;
|
||||
if (compactWhenIdle) setComposerFocused(true);
|
||||
}}
|
||||
onBlur={() => {
|
||||
if (placeholderHintRequested) setPlaceholderHintRequested(false);
|
||||
}}
|
||||
onPointerLeave={(event) => {
|
||||
if (event.pointerType === "mouse" && placeholderHintRequested) setPlaceholderHintRequested(false);
|
||||
}}
|
||||
onChange={mentionInput.onChange}
|
||||
onCompositionStart={mentionInput.onCompositionStart}
|
||||
onCompositionEnd={mentionInput.onCompositionEnd}
|
||||
onKeyDown={onKeyDown}
|
||||
onKeyUp={() => setCursorPosition(rawSelection().start)}
|
||||
onSelect={() => setCursorPosition(rawSelection().start)}
|
||||
onClick={(event) => {
|
||||
setCursorPosition(rawSelection().start);
|
||||
if (!event.currentTarget.value) setPlaceholderHintRequested(true);
|
||||
}}
|
||||
onCopy={mentionInput.onCopy}
|
||||
onCut={mentionInput.onCut}
|
||||
onScroll={(e) => {
|
||||
if (mentionOverlayRef.current) mentionOverlayRef.current.scrollTop = e.currentTarget.scrollTop;
|
||||
}}
|
||||
onPaste={onPaste}
|
||||
rows={1}
|
||||
enterKeyHint={hasCoarsePointer ? "enter" : undefined}
|
||||
placeholder={sessionDragPreview ? "" : resolvedPlaceholder}
|
||||
disabled={interactionDisabled}
|
||||
aria-label={inputAriaLabel ?? t("thread.composer.inputAria")}
|
||||
aria-description={sessionDragPreview ? undefined : resolvedPlaceholder}
|
||||
className={cn(
|
||||
inputTextClasses,
|
||||
"relative z-10 block caret-foreground placeholder:text-muted-foreground",
|
||||
"focus:outline-none focus-visible:outline-none",
|
||||
"disabled:cursor-not-allowed",
|
||||
hasInlineDecorations && "text-transparent selection:bg-primary/20",
|
||||
)}
|
||||
/>
|
||||
</TooltipTrigger>
|
||||
{placeholderHintOpen ? (
|
||||
<TooltipContent side="top" align="start" onEscapeKeyDown={() => {
|
||||
setPlaceholderHintOpen(false);
|
||||
setPlaceholderHintRequested(false);
|
||||
}} style={{ "--placeholder-hint-bottom-gap": `${placeholderHintBottomGap}px` } as CSSProperties}
|
||||
className="pointer-events-none max-w-[min(24rem,calc(100vw-2rem))] whitespace-normal break-words text-sm data-[side=bottom]:mt-[var(--placeholder-hint-bottom-gap)]">
|
||||
{resolvedPlaceholder}
|
||||
</TooltipContent>
|
||||
) : null}
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
</div>
|
||||
{inlineError ? (
|
||||
<div
|
||||
|
||||
+46
-40
@@ -2,6 +2,22 @@
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
@font-face {
|
||||
font-family: "Open Sans";
|
||||
src: url("./assets/fonts/open-sans-variable.woff2") format("woff2");
|
||||
font-style: normal;
|
||||
font-weight: 300 800;
|
||||
font-display: swap;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "Open Sans";
|
||||
src: url("./assets/fonts/open-sans-variable-italic.woff2") format("woff2");
|
||||
font-style: italic;
|
||||
font-weight: 300 800;
|
||||
font-display: swap;
|
||||
}
|
||||
|
||||
.thread-composer-stack {
|
||||
--composer-content-width: 49.5rem;
|
||||
}
|
||||
@@ -134,32 +150,22 @@
|
||||
}
|
||||
|
||||
:root, .reading-typography {
|
||||
--reading-size-wide: 18px;
|
||||
--reading-size-narrow: 16px;
|
||||
--text-reading-size: var(--reading-size-wide);
|
||||
--text-reading-size: 16px;
|
||||
--reading-line-height: 1.6;
|
||||
--text-code-size: calc(var(--text-reading-size) * 0.875);
|
||||
--text-code-dense-size: calc(var(--text-reading-size) * 0.75);
|
||||
}
|
||||
|
||||
:root[data-reading-text-size="small"], .reading-typography[data-reading-text-size="small"] {
|
||||
--reading-size-wide: 16px;
|
||||
--reading-size-narrow: 15px;
|
||||
--text-reading-size: 15px;
|
||||
}
|
||||
|
||||
:root[data-reading-text-size="large"], .reading-typography[data-reading-text-size="large"] {
|
||||
--reading-size-wide: 20px;
|
||||
--reading-size-narrow: 18px;
|
||||
--text-reading-size: 18px;
|
||||
}
|
||||
|
||||
:root[data-reading-text-size="custom"], .reading-typography[data-reading-text-size="custom"] {
|
||||
--reading-size-wide: var(--custom-reading-size, 18px);
|
||||
--reading-size-narrow: var(--custom-reading-size, 18px);
|
||||
}
|
||||
|
||||
@media (max-width: 639px) {
|
||||
:root, .reading-typography {
|
||||
--text-reading-size: var(--reading-size-narrow);
|
||||
}
|
||||
--text-reading-size: var(--custom-reading-size, 18px);
|
||||
}
|
||||
|
||||
.dark {
|
||||
@@ -239,6 +245,13 @@
|
||||
text-autospace: normal;
|
||||
}
|
||||
|
||||
.text-reading,
|
||||
.text-reading-small,
|
||||
.text-composer,
|
||||
.markdown-content {
|
||||
font-family: "Open Sans", sans-serif;
|
||||
}
|
||||
|
||||
/* Keep source text and editable values visually literal. */
|
||||
pre,
|
||||
code,
|
||||
@@ -480,25 +493,28 @@
|
||||
@apply mb-0;
|
||||
}
|
||||
|
||||
/* Override Tailwind Typography's built-in colors with our design tokens
|
||||
so assistant messages use the same --foreground as user messages. */
|
||||
.markdown-content {
|
||||
--tw-prose-body: hsl(var(--foreground));
|
||||
--tw-prose-headings: hsl(var(--foreground));
|
||||
--tw-prose-bold: hsl(var(--foreground));
|
||||
--tw-prose-lead: hsl(var(--foreground));
|
||||
--tw-prose-body: hsl(var(--foreground) / 0.9);
|
||||
--tw-prose-headings: hsl(var(--foreground) / 0.9);
|
||||
--tw-prose-bold: hsl(var(--foreground) / 0.9);
|
||||
--tw-prose-lead: hsl(var(--foreground) / 0.9);
|
||||
transition: var(--theme-ink-transition, color 0s);
|
||||
@apply text-reading;
|
||||
}
|
||||
|
||||
.markdown-content :is(h1, h2, h3, h4, h5, h6) {
|
||||
margin-block: 1.25em 0.5em;
|
||||
font-weight: 600;
|
||||
line-height: 1.4;
|
||||
line-height: 1.3;
|
||||
}
|
||||
.markdown-content h1 { font-size: 1.5em; }
|
||||
.markdown-content h2 { font-size: 1.25em; }
|
||||
.markdown-content h3 { font-size: 1.125em; }
|
||||
.markdown-content :is(h4, h5, h6) { font-size: 1em; }
|
||||
.markdown-content h1 { font-size: 2em; }
|
||||
.markdown-content h2 { font-size: 1.5em; }
|
||||
.markdown-content h3 { font-size: 1.25em; }
|
||||
.markdown-content h4 { font-size: 1.125em; }
|
||||
.markdown-content :is(h5, h6) { font-size: 1em; }
|
||||
.markdown-content :is(p, ul, ol) { margin-block: 0.8em; }
|
||||
.markdown-content li { margin-block: 0.25em; }
|
||||
.markdown-content :is(li > ul, li > ol) { margin-block: 0; }
|
||||
.markdown-content strong { font-weight: 600; }
|
||||
.markdown-content :is(th, td) {
|
||||
font-size: inherit;
|
||||
@@ -527,17 +543,6 @@
|
||||
@apply list-none pl-0;
|
||||
}
|
||||
|
||||
/* Set the default before locale overrides: html also matches :lang(). */
|
||||
:root {
|
||||
--cjk-line-height: 1.625;
|
||||
}
|
||||
|
||||
:lang(zh),
|
||||
:lang(ja),
|
||||
:lang(ko) {
|
||||
--cjk-line-height: 1.8;
|
||||
}
|
||||
|
||||
.markdown-content :is(h1, h2, h3, h4, h5, h6),
|
||||
.settings-section-title {
|
||||
text-wrap: balance;
|
||||
@@ -1006,11 +1011,11 @@
|
||||
}
|
||||
|
||||
[data-user-text-bubble] > .message-block-menu-trigger {
|
||||
top: calc((1rem + var(--text-reading-size) * var(--cjk-line-height) - var(--message-block-control-size)) / 2);
|
||||
top: calc((1rem + var(--text-reading-size) * var(--reading-line-height) - var(--message-block-control-size)) / 2);
|
||||
}
|
||||
|
||||
[data-user-text-bubble] > .message-block-hover-time {
|
||||
top: calc((1rem + var(--text-reading-size) * var(--cjk-line-height) + var(--message-block-control-size)) / 2);
|
||||
top: calc((1rem + var(--text-reading-size) * var(--reading-line-height) + var(--message-block-control-size)) / 2);
|
||||
}
|
||||
|
||||
[data-context-block-active] .message-block-menu-trigger,
|
||||
@@ -1493,7 +1498,8 @@
|
||||
.thread-composer-collapsible-layout {
|
||||
container: composer-layout / inline-size;
|
||||
}
|
||||
.thread-composer-collapsible .thread-composer-input textarea:placeholder-shown {
|
||||
/* A wrapped placeholder must not resize the empty composer. */
|
||||
.thread-composer-input textarea:placeholder-shown {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
@@ -4534,6 +4534,7 @@ describe("session composer drafts", () => {
|
||||
view.rerender(composer("unchanged-draft"));
|
||||
expect(screen.getByRole("textbox")).toHaveValue("send once");
|
||||
if (attachment) await screen.findByRole("img", { name: "draft.png" });
|
||||
fireEvent.click(screen.getByRole("textbox"));
|
||||
await act(async () => resolveSend(true));
|
||||
view.unmount();
|
||||
expect(new ComposerDraftStore().get("unchanged-draft", true)).toBeUndefined();
|
||||
|
||||
@@ -30,8 +30,8 @@ export default {
|
||||
"control-label": ["0.875rem", { lineHeight: "1.25rem", fontWeight: "500" }],
|
||||
caption: ["0.75rem", { lineHeight: "1.125rem", fontWeight: "400" }],
|
||||
title: ["1.25rem", { lineHeight: "1.75rem", fontWeight: "600" }],
|
||||
reading: ["var(--text-reading-size)", { lineHeight: "var(--cjk-line-height)", fontWeight: "400" }],
|
||||
"reading-small": ["calc(var(--text-reading-size) * 0.875)", { lineHeight: "var(--cjk-line-height)", fontWeight: "400" }],
|
||||
reading: ["var(--text-reading-size)", { lineHeight: "var(--reading-line-height)", fontWeight: "400" }],
|
||||
"reading-small": ["calc(var(--text-reading-size) * 0.875)", { lineHeight: "var(--reading-line-height)", fontWeight: "400" }],
|
||||
code: ["var(--text-code-size)", { lineHeight: "1.6", fontWeight: "400" }],
|
||||
"code-dense": ["var(--text-code-dense-size)", { lineHeight: "1.6", fontWeight: "400" }],
|
||||
composer: ["max(16px, var(--text-reading-size))", { lineHeight: "1.5", fontWeight: "400" }],
|
||||
|
||||
Reference in new issue
Block a user