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
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();
|
||||
|
||||
Reference in new issue
Block a user