+ + {#if deviceStore.isMobile && showContextGauge.current && !uiStore.isComposerExpanded} +
+ +
+ {/if} + + + {#if deviceStore.isMobile && page.params.id && !uiStore.isComposerExpanded} +
+ chatScreenForm?.openWorkingDirectoryPicker()} + /> +
+ {/if} + {#if !isEmpty} - + @@ -280,12 +371,13 @@ {/if}
- {#if !stick.atBottom && page.url.hash.includes(ROUTES.CHAT) && page.params.id} + {#if stick.farFromBottom && page.url.hash.includes(ROUTES.CHAT) && page.params.id} stick.scrollToBottom('smooth')} /> {/if}
+ import { ArrowDown } from '@lucide/svelte'; + import GlassKey from '#lib/components/app/actions/GlassKey.svelte'; + import { ICON_CLASS_DEFAULT } from '#lib/constants/index.ts'; + + let { onclick }: { onclick: (e?: MouseEvent) => void } = $props(); + + + diff --git a/tools/ui/src/lib/components/app/chat/ChatScreen/ChatScreenDialogsAndAlerts.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreenDialogsAndAlerts.svelte similarity index 90% rename from tools/ui/src/lib/components/app/chat/ChatScreen/ChatScreenDialogsAndAlerts.svelte rename to ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreenDialogsAndAlerts.svelte index d8ff0d2eee8c..5dc6107a0dde 100644 --- a/tools/ui/src/lib/components/app/chat/ChatScreen/ChatScreenDialogsAndAlerts.svelte +++ b/ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreenDialogsAndAlerts.svelte @@ -4,8 +4,8 @@ DialogConversationDelete, DialogEmptyFileAlert, DialogFileUploadError - } from '$lib/components/app'; - import { ErrorDialogType } from '$lib/enums'; + } from '#lib/components/app/index.ts'; + import { ErrorDialogType } from '#lib/enums/index.ts'; let { activeErrorDialog, diff --git a/tools/ui/src/lib/components/app/chat/ChatScreen/ChatScreenDragOverlay.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreenDragOverlay.svelte similarity index 74% rename from tools/ui/src/lib/components/app/chat/ChatScreen/ChatScreenDragOverlay.svelte rename to ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreenDragOverlay.svelte index ab4adb2c2922..c3ae91a2f28f 100644 --- a/tools/ui/src/lib/components/app/chat/ChatScreen/ChatScreenDragOverlay.svelte +++ b/ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreenDragOverlay.svelte @@ -6,9 +6,9 @@ class="pointer-events-none fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm" >
- +

Attach a file

diff --git a/tools/ui/src/lib/components/app/chat/ChatScreen/ChatScreenForm.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreenForm.svelte similarity index 80% rename from tools/ui/src/lib/components/app/chat/ChatScreen/ChatScreenForm.svelte rename to ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreenForm.svelte index d1438434b298..309cb722289a 100644 --- a/tools/ui/src/lib/components/app/chat/ChatScreen/ChatScreenForm.svelte +++ b/ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreenForm.svelte @@ -1,10 +1,12 @@ + diff --git a/tools/ui/src/lib/components/app/chat/ChatTabs/ChatTabs.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatTabs/ChatTabs.svelte similarity index 93% rename from tools/ui/src/lib/components/app/chat/ChatTabs/ChatTabs.svelte rename to ui/apps/chat/src/lib/components/app/chat/ChatTabs/ChatTabs.svelte index 515bf4f78cf7..c4a68a2dbfc8 100644 --- a/tools/ui/src/lib/components/app/chat/ChatTabs/ChatTabs.svelte +++ b/ui/apps/chat/src/lib/components/app/chat/ChatTabs/ChatTabs.svelte @@ -2,8 +2,7 @@ import ChatTabsItem from './ChatTabsItem.svelte'; import ChatTabsNewChatButton from './ChatTabsNewChatButton.svelte'; import { ArrowRightToLine, ListX, Square, SquarePen, X } from '@lucide/svelte'; - import { page } from '$app/state'; - import { ContextMenuActions, ScrollCarousel } from '$lib/components/app'; + import { ContextMenuActions, ScrollCarousel } from '#lib/components/app/index.ts'; import { CHAT_TABS_MAX_WIDTH, NEW_CHAT_LABEL, @@ -11,11 +10,12 @@ SHORTCUT_CLOSE_TAB, UI_DATA_ATTRS, UNNAMED_CHAT_LABEL - } from '$lib/constants'; - import { useScrollCarousel } from '$lib/hooks/use-scroll-carousel.svelte'; - import { chatStore, conversationsStore, tabsStore, uiStore } from '$lib/stores'; - import type { MenuAction } from '$lib/types'; - import { resolveTabView } from '$lib/utils'; + } from '#lib/constants/index.ts'; + import { useScrollCarousel } from '#lib/hooks/use-scroll-carousel.svelte.ts'; + import { chatStore, conversationsStore, tabsStore, uiStore } from '#lib/stores/index.ts'; + import type { MenuAction } from '#lib/types/index.ts'; + import { resolveTabView } from '#lib/utils/index.ts'; + import { page } from '$app/state'; import { tick } from 'svelte'; const carousel = useScrollCarousel(); diff --git a/tools/ui/src/lib/components/app/chat/ChatTabs/ChatTabsItem.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatTabs/ChatTabsItem.svelte similarity index 86% rename from tools/ui/src/lib/components/app/chat/ChatTabs/ChatTabsItem.svelte rename to ui/apps/chat/src/lib/components/app/chat/ChatTabs/ChatTabsItem.svelte index 5435abcf9907..c01af20d6f4b 100644 --- a/tools/ui/src/lib/components/app/chat/ChatTabs/ChatTabsItem.svelte +++ b/ui/apps/chat/src/lib/components/app/chat/ChatTabs/ChatTabsItem.svelte @@ -1,7 +1,7 @@ - - -
{/if} {/if} -
+ - - diff --git a/ui/apps/chat/src/lib/components/app/content/MarkdownContent/MarkdownSurface.svelte b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/MarkdownSurface.svelte new file mode 100644 index 000000000000..e1c294dfc5b3 --- /dev/null +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/MarkdownSurface.svelte @@ -0,0 +1,22 @@ + + + +
+ {@render children?.()} +
+ + diff --git a/tools/ui/src/lib/components/app/content/MarkdownContent/markdown-content.css b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-content.css similarity index 88% rename from tools/ui/src/lib/components/app/content/MarkdownContent/markdown-content.css rename to ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-content.css index 0f156039819e..49aee0e04c72 100644 --- a/tools/ui/src/lib/components/app/content/MarkdownContent/markdown-content.css +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-content.css @@ -5,12 +5,12 @@ overflow-wrap: break-word; } -.markdown-block--unstable { +.markdown-content :global(.markdown-block--unstable) { display: contents; } /* Streaming code block uses .code-block-wrapper styles */ -.streaming-code-block .streaming-code-pre { +.markdown-content :global(.streaming-code-block .streaming-code-pre) { background: transparent; padding: 0.5rem; margin: 0; @@ -132,8 +132,10 @@ word-break: break-all; } -.markdown-content :global(a:hover) { - color: var(--primary); +@media (hover: hover) and (pointer: fine) { + .markdown-content :global(a:hover) { + color: var(--primary); + } } /* Lists */ @@ -259,11 +261,11 @@ div.markdown-user-content :global(.table-wrapper) { max-height: var(--max-message-height); } -.markdown-content .markdown-block:not(:first-child) :global(.code-block-wrapper) { +.markdown-content :global(.markdown-block:not(:first-child) .code-block-wrapper) { margin-top: 1rem; } -.markdown-content .markdown-block:not(:last-child) :global(.code-block-wrapper) { +.markdown-content :global(.markdown-block:not(:last-child) .code-block-wrapper) { margin-bottom: 1rem; } @@ -273,7 +275,7 @@ div.markdown-user-content :global(.table-wrapper) { /* Scroll container for code blocks (both streaming and completed) */ .markdown-content :global(.code-block-scroll-container), -.streaming-code-scroll-container { +.markdown-content :global(.streaming-code-scroll-container) { min-height: var(--min-message-height); max-height: var(--max-message-height); overflow-y: auto; @@ -287,7 +289,7 @@ div.markdown-user-content :global(.table-wrapper) { } .full-height-code-blocks :global(.code-block-scroll-container), -.full-height-code-blocks .streaming-code-scroll-container { +.full-height-code-blocks :global(.streaming-code-scroll-container) { max-height: none; overflow-y: visible; } @@ -307,9 +309,7 @@ div.markdown-user-content :global(.table-wrapper) { .markdown-content :global(.code-language) { color: var(--color-foreground); font-weight: 500; - font-family: - ui-monospace, SFMono-Regular, 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, - 'Liberation Mono', Menlo, monospace; + font-family: var(--font-mono); text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.05em; @@ -334,10 +334,12 @@ div.markdown-user-content :global(.table-wrapper) { transition: all 0.2s ease; } -.markdown-content :global(.copy-code-btn:hover), -.markdown-content :global(.preview-code-btn:hover), -.markdown-content :global(.toggle-source-btn:hover) { - transform: scale(1.05); +@media (hover: hover) and (pointer: fine) { + .markdown-content :global(.copy-code-btn:hover), + .markdown-content :global(.preview-code-btn:hover), + .markdown-content :global(.toggle-source-btn:hover) { + transform: scale(1.05); + } } .markdown-content :global(.copy-code-btn:active), @@ -366,8 +368,10 @@ div.markdown-user-content :global(.table-wrapper) { text-decoration: none; } -.markdown-content :global(.mention:hover) { - text-decoration: underline; +@media (hover: hover) and (pointer: fine) { + .markdown-content :global(.mention:hover) { + text-decoration: underline; + } } .markdown-content :global(.hashtag) { @@ -376,8 +380,10 @@ div.markdown-user-content :global(.table-wrapper) { text-decoration: none; } -.markdown-content :global(.hashtag:hover) { - text-decoration: underline; +@media (hover: hover) and (pointer: fine) { + .markdown-content :global(.hashtag:hover) { + text-decoration: underline; + } } /* Advanced table enhancements */ @@ -385,15 +391,17 @@ div.markdown-user-content :global(.table-wrapper) { transition: all 0.2s ease; } -.markdown-content :global(table:hover) { - box-shadow: - 0 4px 6px -1px rgb(0 0 0 / 0.1), - 0 2px 4px -2px rgb(0 0 0 / 0.1); -} +@media (hover: hover) and (pointer: fine) { + .markdown-content :global(table:hover) { + box-shadow: + 0 4px 6px -1px rgb(0 0 0 / 0.1), + 0 2px 4px -2px rgb(0 0 0 / 0.1); + } -.markdown-content :global(th:hover), -.markdown-content :global(td:hover) { - background: var(--muted); + .markdown-content :global(th:hover), + .markdown-content :global(td:hover) { + background: var(--muted); + } } /* Disable hover effects when rendering user messages */ @@ -417,10 +425,12 @@ div.markdown-user-content :global(.table-wrapper) { position: relative; } -.markdown-content :global(blockquote:hover) { - border-left-width: 6px; - background: var(--muted); - transform: translateX(2px); +@media (hover: hover) and (pointer: fine) { + .markdown-content :global(blockquote:hover) { + border-left-width: 6px; + background: var(--muted); + transform: translateX(2px); + } } .markdown-content :global(blockquote::before) { @@ -539,7 +549,7 @@ div.markdown-user-content :global(.table-wrapper) { } /* Dark mode adjustments */ -@media (prefers-color-scheme: dark) { +@media (prefers-color-scheme: dark) and (hover: hover) and (pointer: fine) { .markdown-content :global(blockquote:hover) { background: var(--muted); } @@ -589,9 +599,11 @@ div.markdown-user-content :global(.table-wrapper) { transition: all 0.2s ease; } -.markdown-content :global(.image-error-link:hover) { - background: var(--muted); - border-color: var(--primary); +@media (hover: hover) and (pointer: fine) { + .markdown-content :global(.image-error-link:hover) { + background: var(--muted); + border-color: var(--primary); + } } /* Mermaid and svg blocks share the same block styling */ @@ -624,9 +636,11 @@ div.markdown-user-content :global(.table-wrapper) { display: none; } -.markdown-content :global(pre.mermaid:hover), -.markdown-content :global(.svg-block:hover) { - opacity: 0.85; +@media (hover: hover) and (pointer: fine) { + .markdown-content :global(pre.mermaid:hover), + .markdown-content :global(.svg-block:hover) { + opacity: 0.85; + } } .markdown-content :global(pre.mermaid svg) { @@ -746,14 +760,14 @@ div.markdown-user-content :global(.table-wrapper) { } /* Streaming mermaid block - empty preview box */ -.mermaid-streaming-block { +.markdown-content :global(.mermaid-streaming-block) { min-height: 300px; display: flex; align-items: center; justify-content: center; } -.mermaid-loading-placeholder { +.markdown-content :global(.mermaid-loading-placeholder) { display: flex; align-items: center; justify-content: center; @@ -761,7 +775,7 @@ div.markdown-user-content :global(.table-wrapper) { color: var(--muted-foreground); } -.mermaid-loading-text { +.markdown-content :global(.mermaid-loading-text) { font-size: 0.875rem; font-style: italic; } diff --git a/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-diagrams.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-diagrams.ts new file mode 100644 index 000000000000..4bb7e44b3db9 --- /dev/null +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-diagrams.ts @@ -0,0 +1,144 @@ +// Diagram blocks (mermaid, svg) in rendered markdown: drawing them after the HTML is in +// the page, and the actions of their header buttons. Shared by MarkdownContent and the +// live preview of MarkdownEditor, so a diagram looks and behaves the same in both. + +import { + DIAGRAM_VIEW_MODE_ATTR, + DIAGRAM_VIEW_RENDERED, + DIAGRAM_VIEW_SOURCE, + MERMAID_BLOCK_CLASS, + MERMAID_RENDERED_ATTR, + MERMAID_SYNTAX_ATTR, + MERMAID_WRAPPER_CLASS, + SVG, + TOGGLE_SOURCE_BTN_CLASS +} from '#lib/constants/index.ts'; +import { BooleanString } from '#lib/enums/index.ts'; +import { sanitizeSvg } from '#lib/utils/sanitize-svg.ts'; +import { mountSvgShadow } from '#lib/utils/svg-shadow.ts'; + +export type DiagramAction = { copy: string } | { previewSvg: string }; + +/** + * Renders the mermaid diagrams in `container` that haven't been rendered yet. + * Marks nodes immediately to prevent duplicate renders during streaming. + */ +export async function renderMermaidDiagrams(container: HTMLElement, isDark: boolean) { + const nodes = container.querySelectorAll( + `pre.${MERMAID_BLOCK_CLASS}:not([${MERMAID_RENDERED_ATTR}])` + ); + + if (nodes.length === 0) return; + + // Mark nodes immediately to prevent duplicate renders if called again during streaming. + // This avoids needing a guard that would block node discovery. + nodes.forEach((node) => node.setAttribute(MERMAID_RENDERED_ATTR, BooleanString.TRUE)); + + // lazy load the mermaid dependecy only when needed to reduce bundle size. + const { default: mermaid } = await import('mermaid'); + + mermaid.initialize({ + flowchart: { + htmlLabels: true, + useMaxWidth: false + }, + gantt: { + useMaxWidth: false + }, + securityLevel: 'strict', + sequence: { + useMaxWidth: false + }, + startOnLoad: false, + theme: isDark ? 'dark' : 'default' + }); + + try { + await mermaid.run({ nodes: Array.from(nodes) as unknown as NodeListOf }); + } catch (error) { + console.error('Failed to render mermaid diagram:', error); + } +} + +/** + * Renders the svg diagrams in `container` that haven't been rendered yet. + * Sanitizes the source before injecting and marks each node so it renders once. + * An empty sanitize result keeps the raw source as escaped text. + */ +export function renderSvgDiagrams(container: HTMLElement) { + const nodes = container.querySelectorAll( + `pre.${SVG.BLOCK_CLASS}:not([${SVG.RENDERED_ATTR}])` + ); + + nodes.forEach((node) => { + node.setAttribute(SVG.RENDERED_ATTR, BooleanString.TRUE); + + const source = node.getAttribute(SVG.SOURCE_ATTR) ?? node.textContent ?? ''; + const clean = sanitizeSvg(source); + + if (clean) { + node.textContent = ''; + const host = document.createElement('div'); + + node.appendChild(host); + mountSvgShadow(host, clean, SVG.INLINE_SHADOW_STYLE); + } + }); +} + +/** + * Toggles a diagram block between its rendered view and its source view when `target` + * is its toggle button; css drives the visibility from the wrapper mode. + * Returns whether the target was a toggle button. + */ +export function toggleDiagramSource(target: HTMLElement): boolean { + const toggleBtn = target.closest(`.${TOGGLE_SOURCE_BTN_CLASS}`); + + if (!toggleBtn) return false; + + const wrapper = toggleBtn.closest(`.${MERMAID_WRAPPER_CLASS}, .${SVG.WRAPPER_CLASS}`); + + if (!wrapper) return true; + + const isSource = wrapper.getAttribute(DIAGRAM_VIEW_MODE_ATTR) === DIAGRAM_VIEW_SOURCE; + + wrapper.setAttribute( + DIAGRAM_VIEW_MODE_ATTR, + isSource ? DIAGRAM_VIEW_RENDERED : DIAGRAM_VIEW_SOURCE + ); + toggleBtn.setAttribute('aria-pressed', String(!isSource)); + + return true; +} + +/** + * What a click on a diagram block's copy or preview button asks for: the text to copy + * (mermaid syntax, svg source) or the svg to preview. Null when `target` is neither. + */ +export function getDiagramButtonAction(target: HTMLElement): DiagramAction | null { + const isCopy = Boolean(target.closest('.copy-code-btn')); + + if (!isCopy && !target.closest('.preview-code-btn')) return null; + + const mermaidPre = target + .closest(`.${MERMAID_WRAPPER_CLASS}`) + ?.querySelector(`pre.${MERMAID_BLOCK_CLASS}[${MERMAID_SYNTAX_ATTR}]`); + + if (mermaidPre) { + if (isCopy) return { copy: mermaidPre.getAttribute(MERMAID_SYNTAX_ATTR) ?? '' }; + + const svg = mermaidPre.querySelector('svg'); + + return svg ? { previewSvg: svg.outerHTML } : null; + } + + const svgPre = target + .closest(`.${SVG.WRAPPER_CLASS}`) + ?.querySelector(`pre.${SVG.BLOCK_CLASS}[${SVG.SOURCE_ATTR}]`); + + if (!svgPre) return null; + + const source = svgPre.getAttribute(SVG.SOURCE_ATTR) ?? ''; + + return isCopy ? { copy: source } : { previewSvg: sanitizeSvg(source) }; +} diff --git a/tools/ui/src/lib/components/app/content/MarkdownContent/markdown-handlers.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-handlers.ts similarity index 98% rename from tools/ui/src/lib/components/app/content/MarkdownContent/markdown-handlers.ts rename to ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-handlers.ts index 0a1db1909377..0abaa3d46049 100644 --- a/tools/ui/src/lib/components/app/content/MarkdownContent/markdown-handlers.ts +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-handlers.ts @@ -9,9 +9,9 @@ import { MERMAID_BLOCK_CLASS, MERMAID_SYNTAX_ATTR, MERMAID_WRAPPER_CLASS -} from '$lib/constants'; -import { BooleanString } from '$lib/enums'; -import { copyCodeToClipboard, copyToClipboard } from '$lib/utils'; +} from '#lib/constants/index.ts'; +import { BooleanString } from '#lib/enums/index.ts'; +import { copyCodeToClipboard, copyToClipboard } from '#lib/utils/index.ts'; export interface PreviewState { previewDialogOpen: boolean; diff --git a/tools/ui/src/lib/components/app/content/MarkdownContent/markdown-processor.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-processor.ts similarity index 97% rename from tools/ui/src/lib/components/app/content/MarkdownContent/markdown-processor.ts rename to ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-processor.ts index 26cae5b5c51b..d7c4feac6b86 100644 --- a/tools/ui/src/lib/components/app/content/MarkdownContent/markdown-processor.ts +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-processor.ts @@ -19,8 +19,8 @@ import { rehypeResolveAttachmentImages } from './plugins/rehype/resolve-attachme import { rehypeSvgPre } from './plugins/rehype/svg-pre'; import { rehypeRestoreTableHtml } from './plugins/rehype/table-html-restorer'; import { remarkLiteralHtml } from './plugins/remark/literal-html'; -import { FileTypeText } from '$lib/enums/files.enums'; -import type { DatabaseMessageExtra } from '$lib/types/database'; +import { FileTypeText } from '#lib/enums/files.enums.ts'; +import type { DatabaseMessageExtra } from '#lib/types/database.js'; import type { Root as HastRoot } from 'hast'; import { all as lowlightAll } from 'lowlight'; import type { Root as MdastRoot } from 'mdast'; diff --git a/tools/ui/src/lib/components/app/content/MarkdownContent/markdown-utils.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-utils.ts similarity index 97% rename from tools/ui/src/lib/components/app/content/MarkdownContent/markdown-utils.ts rename to ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-utils.ts index 9e2c0f4f8cc6..507346737059 100644 --- a/tools/ui/src/lib/components/app/content/MarkdownContent/markdown-utils.ts +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/markdown-utils.ts @@ -2,7 +2,7 @@ * Utility functions for markdown processing in MarkdownContent component. */ -import { MARKDOWN_DATA_ATTRS } from '$lib/constants'; +import { MARKDOWN_DATA_ATTRS } from '#lib/constants/index.ts'; import type { RootContent as HastRootContent } from 'hast'; /** diff --git a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/code-block-utils.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/code-block-utils.ts similarity index 99% rename from tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/code-block-utils.ts rename to ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/code-block-utils.ts index 4eb38e49fd01..771235089d87 100644 --- a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/code-block-utils.ts +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/code-block-utils.ts @@ -10,7 +10,7 @@ import { DIAGRAM_SOURCE_CLASS, PREVIEW_ICON_SVG, TOGGLE_SOURCE_BTN_CLASS -} from '$lib/constants'; +} from '#lib/constants/index.ts'; import type { Element, ElementContent } from 'hast'; export interface BlockIdGenerator { diff --git a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-code-blocks.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-code-blocks.ts similarity index 96% rename from tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-code-blocks.ts rename to ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-code-blocks.ts index f42ab1c07cae..5c1b2094f34b 100644 --- a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-code-blocks.ts +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-code-blocks.ts @@ -17,7 +17,7 @@ import { createWrapper, generateBlockId } from './code-block-utils'; -import { CODE_BLOCK_CLASS, MARKDOWN_DATA_ATTRS } from '$lib/constants'; +import { CODE_BLOCK_CLASS, MARKDOWN_DATA_ATTRS } from '#lib/constants/index.ts'; import type { Element, ElementContent, Root } from 'hast'; import type { Plugin } from 'unified'; import { visit } from 'unist-util-visit'; diff --git a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-links.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-links.ts similarity index 95% rename from tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-links.ts rename to ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-links.ts index 880a10cad6ed..d8162f24570c 100644 --- a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-links.ts +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-links.ts @@ -26,7 +26,7 @@ export const rehypeEnhanceLinks: Plugin<[], Root> = () => { if (!props.href) return; props.target = '_blank'; - props.rel = 'noopener noreferrer'; + props.rel = ['noopener', 'noreferrer']; node.properties = props; }); }; diff --git a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-mermaid-blocks.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-mermaid-blocks.ts similarity index 98% rename from tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-mermaid-blocks.ts rename to ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-mermaid-blocks.ts index d1f85b7166e2..60e9b7e02d93 100644 --- a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-mermaid-blocks.ts +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-mermaid-blocks.ts @@ -29,7 +29,7 @@ import { MERMAID_SCROLL_CONTAINER_CLASS, MERMAID_SYNTAX_ATTR, MERMAID_WRAPPER_CLASS -} from '$lib/constants'; +} from '#lib/constants/index.ts'; import type { Element, ElementContent, Root } from 'hast'; import type { Plugin } from 'unified'; import { visit } from 'unist-util-visit'; diff --git a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-svg-blocks.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-svg-blocks.ts similarity index 98% rename from tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-svg-blocks.ts rename to ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-svg-blocks.ts index e1ec4898e3f9..1fc0688de543 100644 --- a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-svg-blocks.ts +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-svg-blocks.ts @@ -19,7 +19,7 @@ import { generateBlockId } from './code-block-utils'; import type { DiagramPreData } from './pre-transform'; -import { DIAGRAM_VIEW_MODE_ATTR, DIAGRAM_VIEW_RENDERED, SVG } from '$lib/constants'; +import { DIAGRAM_VIEW_MODE_ATTR, DIAGRAM_VIEW_RENDERED, SVG } from '#lib/constants/index.ts'; import type { Element, ElementContent, Root } from 'hast'; import type { Plugin } from 'unified'; import { visit } from 'unist-util-visit'; diff --git a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-tables.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-tables.ts similarity index 100% rename from tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-tables.ts rename to ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-tables.ts diff --git a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/file-badge.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/file-badge.ts similarity index 91% rename from tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/file-badge.ts rename to ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/file-badge.ts index ab50d437caa8..713acdf45be4 100644 --- a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/file-badge.ts +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/file-badge.ts @@ -1,7 +1,7 @@ /** * Rehype plugin that rewrites `file://` markdown anchors into the inline * mention chip, sharing the class string with the ChatFormInputRich - * tokenizer via `$lib/constants`. + * tokenizer via `#lib/constants/index.ts`. * * The chip is presentational: `file://` navigation is blocked from * http(s) pages, so the anchor becomes a plain `` (no link role, @@ -15,9 +15,13 @@ import { MENTION_BADGE_SVG_ATTRIBUTES, PATH_SEPARATOR, SETTINGS_KEYS -} from '$lib/constants'; -import { settingsStore, toolsStore } from '$lib/stores'; -import { decodeFileLinkPath, getMentionBadgeIconPaths, getMentionBadgeLabel } from '$lib/utils'; +} from '#lib/constants/index.ts'; +import { settingsStore, toolsStore } from '#lib/stores/index.ts'; +import { + decodeFileLinkPath, + getMentionBadgeIconPaths, + getMentionBadgeLabel +} from '#lib/utils/index.ts'; import type { Element, Root } from 'hast'; import type { Plugin } from 'unified'; import { visit } from 'unist-util-visit'; diff --git a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/mermaid-pre.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/mermaid-pre.ts similarity index 74% rename from tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/mermaid-pre.ts rename to ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/mermaid-pre.ts index 61322f045cf1..b94d2bad10fc 100644 --- a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/mermaid-pre.ts +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/mermaid-pre.ts @@ -1,5 +1,5 @@ import { createPreTransform } from './pre-transform'; -import { MERMAID_BLOCK_CLASS, MERMAID_LANGUAGE } from '$lib/constants'; +import { MERMAID_BLOCK_CLASS, MERMAID_LANGUAGE } from '#lib/constants/index.ts'; /** * Converts mermaid code blocks to
 for client-side rendering.
diff --git a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/pre-transform.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/pre-transform.ts
similarity index 97%
rename from tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/pre-transform.ts
rename to ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/pre-transform.ts
index 755fa1ecdb88..af45ff0aa082 100644
--- a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/pre-transform.ts
+++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/pre-transform.ts
@@ -11,6 +11,12 @@ export interface DiagramPreData {
 	sourceCode: Element;
 }
 
+declare module 'hast' {
+	interface ElementData {
+		sourceCode?: Element;
+	}
+}
+
 /**
  * Recursively extracts all text content from a HAST node.
  * Handles nested elements (e.g., span wrappers from syntax highlighting).
diff --git a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/rehype-rtl-support.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/rehype-rtl-support.ts
similarity index 100%
rename from tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/rehype-rtl-support.ts
rename to ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/rehype-rtl-support.ts
diff --git a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/resolve-attachment-images.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/resolve-attachment-images.ts
similarity index 91%
rename from tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/resolve-attachment-images.ts
rename to ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/resolve-attachment-images.ts
index 5d3ade0f1486..5410b13d0597 100644
--- a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/resolve-attachment-images.ts
+++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/resolve-attachment-images.ts
@@ -1,5 +1,5 @@
-import { AttachmentType, UrlProtocol } from '$lib/enums';
-import type { DatabaseMessageExtra, DatabaseMessageExtraImageFile } from '$lib/types/database';
+import { AttachmentType, UrlProtocol } from '#lib/enums/index.ts';
+import type { DatabaseMessageExtra, DatabaseMessageExtraImageFile } from '#lib/types/database.js';
 import type { Root as HastRoot } from 'hast';
 import { visit } from 'unist-util-visit';
 
diff --git a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/svg-pre.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/svg-pre.ts
similarity index 89%
rename from tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/svg-pre.ts
rename to ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/svg-pre.ts
index 7baa95ca4180..cc720989636c 100644
--- a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/svg-pre.ts
+++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/svg-pre.ts
@@ -1,5 +1,5 @@
 import { createPreTransform } from './pre-transform';
-import { SVG } from '$lib/constants';
+import { SVG } from '#lib/constants/index.ts';
 
 /**
  * Converts svg code blocks to 
 for client-side rendering.
diff --git a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/table-html-restorer.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/table-html-restorer.ts
similarity index 98%
rename from tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/table-html-restorer.ts
rename to ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/table-html-restorer.ts
index 1dd0247fea17..7751d7f795eb 100644
--- a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/table-html-restorer.ts
+++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/rehype/table-html-restorer.ts
@@ -64,7 +64,7 @@
  * // With this plugin: 
becomes line break,
    becomes actual list */ -import { BR_PATTERN, LI_PATTERN, LIST_PATTERN } from '$lib/constants'; +import { BR_PATTERN, LI_PATTERN, LIST_PATTERN } from '#lib/constants/index.ts'; import type { Element, ElementContent, Root, Text } from 'hast'; import type { Plugin } from 'unified'; import { visit } from 'unist-util-visit'; diff --git a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/remark/literal-html.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/remark/literal-html.ts similarity index 94% rename from tools/ui/src/lib/components/app/content/MarkdownContent/plugins/remark/literal-html.ts rename to ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/remark/literal-html.ts index 5183fe531042..cbb59f0a2031 100644 --- a/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/remark/literal-html.ts +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/plugins/remark/literal-html.ts @@ -1,8 +1,15 @@ -import { LINE_BREAK, NBSP, PHRASE_PARENTS, TAB_AS_SPACES } from '$lib/constants'; +import { LINE_BREAK, NBSP, PHRASE_PARENTS, TAB_AS_SPACES } from '#lib/constants/index.ts'; import type { Break, Content, Paragraph, PhrasingContent, Root, Text } from 'mdast'; import type { Plugin } from 'unified'; import { visit } from 'unist-util-visit'; +// Marks a paragraph the plugin created around literal HTML, so adjacent ones merge +declare module 'mdast' { + interface ParagraphData { + literalHtml?: boolean; + } +} + /** * remark plugin that rewrites raw HTML nodes into plain-text equivalents. * diff --git a/tools/ui/src/lib/components/app/content/MarkdownContent/safe-html-config.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownContent/safe-html-config.ts similarity index 100% rename from tools/ui/src/lib/components/app/content/MarkdownContent/safe-html-config.ts rename to ui/apps/chat/src/lib/components/app/content/MarkdownContent/safe-html-config.ts diff --git a/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/MarkdownEditor.svelte b/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/MarkdownEditor.svelte new file mode 100644 index 000000000000..c0afb6119165 --- /dev/null +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/MarkdownEditor.svelte @@ -0,0 +1,414 @@ + + + + + +
    + +
    + + (previewOpen = open)} + open={previewOpen} +/> + + (diagramOpen = open)} + open={diagramOpen} + svgHtml={diagramSvg} +/> + + diff --git a/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/markdown-block-widget.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/markdown-block-widget.ts new file mode 100644 index 000000000000..6deae1d3c6a8 --- /dev/null +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/markdown-block-widget.ts @@ -0,0 +1,348 @@ +// A rendered block of the live preview: the HTML that MarkdownContent renders for its +// source (same pipeline, same code blocks and diagrams), its clicks, and selecting and +// copying its text. + +import { EditorView, ViewPlugin, WidgetType } from '@codemirror/view'; +import { + getDiagramButtonAction, + renderMermaidDiagrams, + renderSvgDiagrams, + toggleDiagramSource +} from '#lib/components/app/content/MarkdownContent/markdown-diagrams.ts'; +import { getMarkdownProcessor } from '#lib/components/app/content/MarkdownContent/markdown-processor.ts'; +import { getCodeInfoFromTarget } from '#lib/components/app/content/MarkdownContent/markdown-utils.ts'; +import { MERMAID_BLOCK_CLASS } from '#lib/constants/index.ts'; +import { ColorMode } from '#lib/enums/index.ts'; +import { + copyCodeToClipboard, + copyToClipboard, + preprocessLaTeX, + splitGluedClosingCodeFences +} from '#lib/utils/index.ts'; +import { mode } from 'mode-watcher'; + +export interface MarkdownBlockWidgetOptions { + onPreviewCode?: (code: string, language: string) => void; + onPreviewDiagram?: (svgHtml: string) => void; + /** + * Anything outside the source that the rendered HTML depends on (e.g. how mention + * badges label paths): blocks with a different key render again. + */ + renderKey?: string; +} + +interface Rendered { + html: string; + /** The block's height when it was last on screen. */ + height?: number; +} + +const BLOCK_CLASS = 'cm-md-block'; +const DRAG_THRESHOLD_PX = 4; +const RENDER_CACHE_LIMIT = 500; +// Height guesses for rendered blocks CodeMirror hasn't measured yet (off screen in a +// long document), which keep its scrollbar and scroll position steady +const ESTIMATED_ROW_PX = 24; +const ESTIMATED_ROW_CHARS = 80; +/** What each source rendered to, by render key and source; shared by every editor. */ +const rendered = new Map(); +/** The key of the render a block's DOM shows. */ +const shownKey = new WeakMap(); +/** The widget a block's DOM belongs to now; the DOM outlives the widget it was made for. */ +const widgetOfDom = new WeakMap(); + +async function renderMarkdownBlock(source: string, key: string): Promise { + const processor = getMarkdownProcessor({}); + const markdown = preprocessLaTeX(splitGluedClosingCodeFences(source)); + const html = processor.stringify(await processor.run(processor.parse(markdown))); + + // bounded: the oldest render goes when the cache is full + if (rendered.size >= RENDER_CACHE_LIMIT) rendered.delete(rendered.keys().next().value as string); + + rendered.set(key, { html }); + + return html; +} + +/** Rows `source` wraps to at a typical width: a cheap stand-in for its height. */ +function estimatedRows(source: string): number { + let rows = 0; + + for (const line of source.split('\n')) + rows += Math.max(1, Math.ceil(line.length / ESTIMATED_ROW_CHARS)); + + return rows; +} + +function caretAt(x: number, y: number): { node: Node; offset: number } | null { + if (typeof document.caretPositionFromPoint === 'function') { + const position = document.caretPositionFromPoint(x, y); + + return position && { node: position.offsetNode, offset: position.offset }; + } + + const range = document.caretRangeFromPoint?.(x, y); + + return range ? { node: range.startContainer, offset: range.startOffset } : null; +} + +/** The page's selection when it is a non-empty one that starts in a rendered block of `view`. */ +function renderedSelection(view: EditorView): Range | null { + const selection = document.getSelection(); + const anchor = selection?.anchorNode; + + if (!selection || selection.isCollapsed || !anchor || selection.rangeCount === 0) return null; + + const element = anchor instanceof Element ? anchor : anchor.parentElement; + const block = element?.closest(`.${BLOCK_CLASS}`); + + return block && view.dom.contains(block) ? selection.getRangeAt(0) : null; +} + +export class MarkdownBlockWidget extends WidgetType { + // For blocks off screen: the height this block had when last on screen, or a guess + // from its text before it ever was + get estimatedHeight(): number { + return rendered.get(this.key)?.height ?? estimatedRows(this.source) * ESTIMATED_ROW_PX; + } + + private get key(): string { + return `${this.options.renderKey ?? ''}\u0000${this.source}`; + } + + constructor( + readonly source: string, + readonly gapRem: number, + readonly options: MarkdownBlockWidgetOptions + ) { + super(); + } + + // An equal widget keeps its DOM as it is, so only the blocks an edit changes redraw + eq(other: MarkdownBlockWidget) { + return ( + other.source === this.source && + other.gapRem === this.gapRem && + other.options.renderKey === this.options.renderKey + ); + } + + // The editor leaves the rendered block alone (its own clicks, the reader's text + // selection in it), see onMouseDown and copyRenderedSelection + ignoreEvent() { + return true; + } + + toDOM(view: EditorView) { + const dom = document.createElement('div'); + + dom.className = `markdown-block ${BLOCK_CLASS}`; + dom.addEventListener('mousedown', (event) => + widgetOfDom.get(dom)?.onMouseDown(event, view, dom) + ); + dom.addEventListener('click', (event) => widgetOfDom.get(dom)?.onClick(event)); + this.fill(dom, view); + + return dom; + } + + // Reuse the DOM when only the source changed (e.g. streamed tokens), keeping the + // previous render on screen until the new one is ready + updateDOM(dom: HTMLElement, view: EditorView) { + this.fill(dom, view); + + return true; + } + + private fill(dom: HTMLElement, view: EditorView) { + const { key } = this; + + widgetOfDom.set(dom, this); + dom.style.paddingTop = `${this.gapRem}rem`; + + if (shownKey.get(dom) === key) return; + + const cached = rendered.get(key); + + if (cached) { + this.show(dom, view, cached.html, key); + + return; + } + + if (!dom.firstChild) { + const fallback = document.createElement('p'); + + fallback.textContent = this.source; + dom.replaceChildren(fallback); + } + + void renderMarkdownBlock(this.source, key).then((html) => { + // a newer source may have reached this DOM while rendering + if (widgetOfDom.get(dom)?.key === key) this.show(dom, view, html, key); + }); + } + + // Measures the block in the editor's measure cycle (no forced layout) for + // estimatedHeight; the measure also makes the editor take in the new height + private measure(dom: HTMLElement, view: EditorView, key: string) { + view.requestMeasure({ + key: dom, + read: () => dom.offsetHeight, + write: (height) => { + const entry = rendered.get(key); + + if (entry && height > 0) entry.height = height; + } + }); + } + + private onClick(event: MouseEvent) { + const target = event.target as HTMLElement; + + if (toggleDiagramSource(target)) { + event.preventDefault(); + event.stopPropagation(); + + return; + } + + const diagramAction = getDiagramButtonAction(target); + + if (diagramAction) { + event.preventDefault(); + event.stopPropagation(); + + if ('copy' in diagramAction) { + void copyToClipboard(diagramAction.copy); + } else { + this.options.onPreviewDiagram?.(diagramAction.previewSvg); + } + + return; + } + + const copyButton = target.closest('.copy-code-btn'); + const previewButton = target.closest('.preview-code-btn'); + const button = copyButton ?? previewButton; + + if (!button) return; + + event.preventDefault(); + event.stopPropagation(); + + const info = getCodeInfoFromTarget(button); + + if (!info) return; + + if (copyButton) { + void copyCodeToClipboard(info.rawCode); + } else { + this.options.onPreviewCode?.(info.rawCode, info.language); + } + } + + // A click on a rendered block opens it for editing; a drag selects its text, which + // the editor (ignoreEvent) and its copy keys (copyRenderedSelection) leave alone + private onMouseDown(event: MouseEvent, view: EditorView, dom: HTMLElement) { + if (event.button !== 0) return; + + if ((event.target as HTMLElement).closest('a, button, input, summary')) return; + + // no native handling: it would focus the editor and turn a block raw mid-drag + event.preventDefault(); + + const anchor = caretAt(event.clientX, event.clientY); + + let selecting = false; + + const onMove = (move: MouseEvent) => { + const distance = Math.hypot(move.clientX - event.clientX, move.clientY - event.clientY); + + if (!selecting && distance < DRAG_THRESHOLD_PX) return; + + selecting = true; + + const head = caretAt(move.clientX, move.clientY); + + if (anchor && head) { + document + .getSelection() + ?.setBaseAndExtent(anchor.node, anchor.offset, head.node, head.offset); + } + }; + const onUp = () => { + window.removeEventListener('mousemove', onMove); + window.removeEventListener('mouseup', onUp); + + if (!selecting) this.openForEditing(event, view, dom); + }; + + window.addEventListener('mousemove', onMove); + window.addEventListener('mouseup', onUp); + } + + // Shows the block's raw text with the cursor near the click + private openForEditing(event: MouseEvent, view: EditorView, dom: HTMLElement) { + const from = view.posAtDOM(dom); + const to = from + this.source.length; + + view.dispatch({ selection: { anchor: from } }); + view.focus(); + + // The raw block has a different layout: map the click once the editor has + // re-measured it (its height map settles over the next two frames) + requestAnimationFrame(() => + requestAnimationFrame(() => { + const pos = view.posAtCoords({ x: event.clientX, y: event.clientY }); + + if (pos !== null && pos >= from && pos <= to) { + view.dispatch({ selection: { anchor: pos } }); + } + }) + ); + } + + private show(dom: HTMLElement, view: EditorView, html: string, key: string) { + dom.innerHTML = html; + shownKey.set(dom, key); + renderSvgDiagrams(dom); + this.measure(dom, view, key); + + // mermaid draws asynchronously and changes the block's height when done + if (dom.querySelector(`pre.${MERMAID_BLOCK_CLASS}`)) { + void renderMermaidDiagrams(dom, mode.current === ColorMode.DARK).then(() => + this.measure(dom, view, key) + ); + } + } +} + +// Copies the text the reader selected in rendered blocks, as text and as HTML. The +// editor's own copy would act on its selection instead (the cursor's whole line when +// it is empty), and the browser's stops at the first block, so this runs before both. +export const copyRenderedSelection = ViewPlugin.define((view) => { + const onCopy = (event: ClipboardEvent) => { + const range = renderedSelection(view); + + if (!range || !event.clipboardData) return; + + const holder = document.createElement('div'); + + holder.append(range.cloneContents()); + event.clipboardData.setData('text/html', holder.innerHTML); + event.clipboardData.setData('text/plain', (holder.textContent ?? '').trim()); + event.preventDefault(); + event.stopPropagation(); + }; + + view.dom.addEventListener('copy', onCopy, true); + view.dom.addEventListener('cut', onCopy, true); + + return { + destroy() { + view.dom.removeEventListener('copy', onCopy, true); + view.dom.removeEventListener('cut', onCopy, true); + } + }; +}); diff --git a/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/markdown-blocks.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/markdown-blocks.ts new file mode 100644 index 000000000000..8c803abe9633 --- /dev/null +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/markdown-blocks.ts @@ -0,0 +1,145 @@ +// The top-level markdown blocks of the editor's document, read from its syntax tree: +// the units the live preview either renders or shows as raw text. + +import { syntaxTree, syntaxTreeAvailable } from '@codemirror/language'; +import type { EditorState } from '@codemirror/state'; + +export interface MarkdownBlock { + from: number; + /** End of the block's own text. */ + sourceTo: number; + /** End of the block's range, including the blank lines that follow it. */ + to: number; + name: string; + /** The collapsed margin between this block and the one before it, in rem. */ + gapRem: number; + /** The block's own text, from..sourceTo. */ + source: string; +} + +// [top, bottom] margins in rem of each block kind as a chat message renders it (each +// block in a .markdown-block of its own, so a heading is a first child). CodeMirror +// can not measure margins on block widgets, so the collapsed gap between two blocks is +// computed here and applied as padding. markdown-editor-margins.svelte.test.ts checks +// them against the stylesheet. +export const BLOCK_MARGINS_REM: Record = { + ATXHeading1: [0.5, 0.75], + ATXHeading2: [0.5, 0.5], + ATXHeading3: [0.5, 0.5], + ATXHeading4: [0.5, 0.25], + ATXHeading5: [0.5, 0.25], + ATXHeading6: [0.5, 0.25], + Blockquote: [1.5, 1.5], + BulletList: [1, 1], + CodeBlock: [1, 1], + FencedCode: [1, 1], + HorizontalRule: [2, 2], + OrderedList: [1, 1], + SetextHeading1: [0.5, 0.75], + SetextHeading2: [0.5, 0.5], + Table: [1, 1] +}; +export const PARAGRAPH_MARGINS_REM: [number, number] = [1, 1]; +export const CODE_BLOCK_NAMES = new Set(['CodeBlock', 'FencedCode']); +const MATH_FENCE = '$$'; + +function blockMargins(name: string): [number, number] { + return BLOCK_MARGINS_REM[name] ?? PARAGRAPH_MARGINS_REM; +} + +/** How many lines of `text` open or close a `$$` math block (`$$x$$` on one line does neither). */ +function mathFenceCount(text: string): number { + if (!text.includes(MATH_FENCE)) return 0; + + let count = 0; + + for (const line of text.split('\n')) { + const trimmed = line.trim(); + + if (!trimmed.startsWith(MATH_FENCE)) continue; + + if (trimmed.length > 2 * MATH_FENCE.length && trimmed.endsWith(MATH_FENCE)) continue; + + count++; + } + + return count; +} + +/** + * A `$$` math block may hold blank lines, which split it into several top-level nodes + * for the markdown parser; join them back into one block, as the renderer sees it. + */ +function joinMathBlocks( + blocks: MarkdownBlock[], + join: (first: MarkdownBlock, last: MarkdownBlock) => MarkdownBlock +): MarkdownBlock[] { + const opens = (block: MarkdownBlock) => + !CODE_BLOCK_NAMES.has(block.name) && mathFenceCount(block.source) % 2 === 1; + const joined: MarkdownBlock[] = []; + + for (let index = 0; index < blocks.length; index++) { + const block = blocks[index]; + + if (!opens(block)) { + joined.push(block); + + continue; + } + + let close = index + 1; + + while (close < blocks.length && !opens(blocks[close])) close++; + + // never closed: the block stays as the parser cut it + if (close === blocks.length) { + joined.push(block); + + continue; + } + + joined.push(join(block, blocks[close])); + index = close; + } + + return joined; +} + +export function collectBlocks(state: EditorState): MarkdownBlock[] { + const { doc } = state; + // A long document may not be parsed to its end yet: its last parsed node may be cut + // short, so it and the rest stay raw until the parser catches up (the tree change + // collects the blocks again) + const complete = syntaxTreeAvailable(state, doc.length); + // `to` and `gapRem` depend on the neighbours, so they are set once the blocks are known + const blockOf = (name: string, from: number, sourceTo: number): MarkdownBlock => ({ + from, + gapRem: 0, + name, + source: doc.sliceString(from, sourceTo), + sourceTo, + to: sourceTo + }); + + let blocks: MarkdownBlock[] = []; + + for (let node = syntaxTree(state).topNode.firstChild; node; node = node.nextSibling) { + blocks.push(blockOf(node.name, doc.lineAt(node.from).from, doc.lineAt(node.to).to)); + } + + if (!complete) blocks.pop(); + + blocks = joinMathBlocks(blocks, (first, last) => blockOf(first.name, first.from, last.sourceTo)); + + blocks.forEach((block, index) => { + const next = blocks[index + 1]; + const prev = blocks[index - 1]; + + if (next) block.to = next.from - 1; + else if (complete) block.to = doc.length; + + if (prev) block.gapRem = Math.max(blockMargins(prev.name)[1], blockMargins(block.name)[0]); + }); + + return blocks; +} diff --git a/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/markdown-live-preview.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/markdown-live-preview.ts new file mode 100644 index 000000000000..3fc646e225bc --- /dev/null +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/markdown-live-preview.ts @@ -0,0 +1,209 @@ +// Live preview for MarkdownEditor: every top-level block the cursor is not in is +// replaced by the HTML that MarkdownContent renders for it (same pipeline, same +// stylesheet, same code blocks and diagrams), and the block being edited shows its raw +// text. The document text itself is never touched, so the prompt stays byte-exact. + +import { + copyRenderedSelection, + MarkdownBlockWidget, + type MarkdownBlockWidgetOptions +} from './markdown-block-widget'; +import { CODE_BLOCK_NAMES, collectBlocks, type MarkdownBlock } from './markdown-blocks'; +import { syntaxTree } from '@codemirror/language'; +import { + type EditorState, + type Extension, + type Range, + StateEffect, + StateField +} from '@codemirror/state'; +import { Decoration, type DecorationSet, EditorView, WidgetType } from '@codemirror/view'; + +export interface MarkdownLivePreviewOptions extends MarkdownBlockWidgetOptions { + /** + * Inline widgets for the raw text of the block being edited (e.g. file mention + * badges), given the state and the block's [from, to) range. They are atomic: the + * cursor steps over them and a delete removes them whole. + */ + editingWidgets?: (state: EditorState, from: number, to: number) => Range[]; +} + +interface LivePreview { + atomic: DecorationSet; + /** The top-level blocks of the document, collected again only when its text changes. */ + blocks: MarkdownBlock[]; + decorations: DecorationSet; + /** Which blocks show their raw text; a cursor move within them changes nothing. */ + raw: boolean[]; +} + +// Blocks that stay raw: a link reference definition renders to nothing, and a setext +// heading would hide its underline (`---` under a line of text is easy to type by accident) +const ALWAYS_RAW_NAMES = new Set(['LinkReference', 'SetextHeading1', 'SetextHeading2']); +const setFocused = StateEffect.define(); +// Whether the editor has focus. One field for every preview, so a preview that replaces +// another (new options) starts from the focus the editor has. +const focusField = StateField.define({ + create: () => false, + update(focused, tr) { + for (const effect of tr.effects) { + if (effect.is(setFocused)) focused = effect.value; + } + + return focused; + } +}); +const focusTracking: Extension = [ + focusField, + EditorView.focusChangeEffect.of((_state, focusing) => setFocused.of(focusing)) +]; + +/** The gap above a raw block, which must stay outside the block's own background. */ +class SpacerWidget extends WidgetType { + constructor(readonly gapRem: number) { + super(); + } + + eq(other: SpacerWidget) { + return other.gapRem === this.gapRem; + } + + toDOM() { + const dom = document.createElement('div'); + + dom.className = 'cm-md-spacer'; + dom.style.height = `${this.gapRem}rem`; + + return dom; + } +} + +/** The blocks that show their raw text: the ones the selection of a focused editor touches. */ +function rawBlocks(state: EditorState, blocks: MarkdownBlock[]): boolean[] { + const focused = state.field(focusField); + const { ranges } = state.selection; + + return blocks.map( + (block) => + ALWAYS_RAW_NAMES.has(block.name) || + (focused && ranges.some((range) => range.from <= block.to && range.to >= block.from)) + ); +} + +// Every block gets new decorations on every build. A widget equal to the one it +// replaces keeps its DOM (see MarkdownBlockWidget.eq), so the page only changes where +// the text did. +function buildPreview( + state: EditorState, + blocks: MarkdownBlock[], + raw: boolean[], + options: MarkdownLivePreviewOptions +): LivePreview { + const decorations: Range[] = []; + const atomic: Range[] = []; + const { doc } = state; + + for (const [index, block] of blocks.entries()) { + const prev = blocks[index - 1]; + // the blank lines after a raw block show as text already, so they are the gap + const gapRem = prev && raw[index - 1] && prev.to > prev.sourceTo ? 0 : block.gapRem; + + if (!raw[index]) { + const widget = new MarkdownBlockWidget(block.source, gapRem, options); + + decorations.push(Decoration.replace({ block: true, widget }).range(block.from, block.to)); + + continue; + } + + if (options.editingWidgets) { + atomic.push(...options.editingWidgets(state, block.from, block.sourceTo)); + } + + if (gapRem > 0) { + decorations.push( + Decoration.widget({ block: true, side: -1, widget: new SpacerWidget(gapRem) }).range( + block.from + ) + ); + } + + const lineClass = CODE_BLOCK_NAMES.has(block.name) + ? 'cm-md-raw-code' + : block.name === 'LinkReference' + ? 'cm-md-raw-definition' + : null; + + if (!lineClass) continue; + + const first = doc.lineAt(block.from).number; + const last = doc.lineAt(block.sourceTo).number; + + for (let number = first; number <= last; number++) { + const classes = [lineClass]; + + if (number === first) classes.push(`${lineClass}-first`); + + if (number === last) classes.push(`${lineClass}-last`); + + decorations.push(Decoration.line({ class: classes.join(' ') }).range(doc.line(number).from)); + } + } + + return { + atomic: Decoration.set(atomic, true), + blocks, + decorations: Decoration.set(decorations, true), + raw + }; +} + +export function markdownLivePreview(options: MarkdownLivePreviewOptions = {}): Extension { + const field = StateField.define({ + create(state) { + const blocks = collectBlocks(state); + + return buildPreview(state, blocks, rawBlocks(state, blocks), options); + }, + provide: (f) => [ + EditorView.decorations.from(f, (value) => value.decorations), + EditorView.decorations.from(f, (value) => value.atomic), + EditorView.atomicRanges.from(f, (value) => () => value.atomic) + ], + update(value, tr) { + const reparsed = tr.docChanged || syntaxTree(tr.state) !== syntaxTree(tr.startState); + const blocks = reparsed ? collectBlocks(tr.state) : value.blocks; + const raw = rawBlocks(tr.state, blocks); + + // a cursor move or a focus change that keeps the same blocks raw changes nothing + if (!reparsed && raw.every((isRaw, index) => isRaw === value.raw[index])) return value; + + return buildPreview(tr.state, blocks, raw, options); + } + }); + + return [focusTracking, copyRenderedSelection, field]; +} + +/** + * The editor without the preview: every block shows its raw text, with the same inline + * widgets (see MarkdownLivePreviewOptions.editingWidgets) over the whole document. + */ +export function markdownPlainText( + editingWidgets?: MarkdownLivePreviewOptions['editingWidgets'] +): Extension { + if (!editingWidgets) return []; + + const widgetsOf = (state: EditorState) => + Decoration.set(editingWidgets(state, 0, state.doc.length), true); + const field = StateField.define({ + create: widgetsOf, + provide: (f) => [ + EditorView.decorations.from(f), + EditorView.atomicRanges.from(f, (value) => () => value) + ], + update: (value, tr) => (tr.docChanged ? widgetsOf(tr.state) : value) + }); + + return field; +} diff --git a/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/markdown-structure.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/markdown-structure.ts new file mode 100644 index 000000000000..b23dcd26acab --- /dev/null +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/markdown-structure.ts @@ -0,0 +1,16 @@ +import { markdownLanguage } from '@codemirror/lang-markdown'; + +/** + * Does `source` hold any markdown block other than plain paragraphs (a heading, + * list, quote, code block, table, rule, ...)? Inline markup inside a paragraph + * does not count. + */ +export function hasMarkdownStructure(source: string): boolean { + const tree = markdownLanguage.parser.parse(source); + + for (let node = tree.topNode.firstChild; node; node = node.nextSibling) { + if (node.name !== 'Paragraph') return true; + } + + return false; +} diff --git a/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/markdown-syntax.ts b/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/markdown-syntax.ts new file mode 100644 index 000000000000..4e8c94bb29c5 --- /dev/null +++ b/ui/apps/chat/src/lib/components/app/content/MarkdownEditor/markdown-syntax.ts @@ -0,0 +1,26 @@ +// Where the code is in the markdown, answered from the editor's syntax tree, so it agrees +// with what the live preview renders (``` and ~~~ fences, indented code, inline code). + +import { syntaxTree } from '@codemirror/language'; +import type { EditorState } from '@codemirror/state'; + +const CODE_NODE_NAMES = new Set(['CodeBlock', 'FencedCode', 'InlineCode']); + +/** The [from, to) ranges of code (blocks and inline) between `from` and `to`. */ +export function codeRanges(state: EditorState, from: number, to: number): [number, number][] { + const ranges: [number, number][] = []; + + syntaxTree(state).iterate({ + enter: (node) => { + if (!CODE_NODE_NAMES.has(node.name)) return; + + ranges.push([node.from, node.to]); + + return false; + }, + from, + to + }); + + return ranges; +} diff --git a/tools/ui/src/lib/components/app/content/MentionBadge.svelte b/ui/apps/chat/src/lib/components/app/content/MentionBadge.svelte similarity index 85% rename from tools/ui/src/lib/components/app/content/MentionBadge.svelte rename to ui/apps/chat/src/lib/components/app/content/MentionBadge.svelte index feda3aa43ac6..d64ff8ec16fc 100644 --- a/tools/ui/src/lib/components/app/content/MentionBadge.svelte +++ b/ui/apps/chat/src/lib/components/app/content/MentionBadge.svelte @@ -1,13 +1,13 @@ + + + !open && close()} open={options !== null}> + { + event.preventDefault(); + nameInput?.focus(); + nameInput?.select(); + }} + > + + + {#if group} + + {:else} + + {/if} + + {group ? 'Rename group' : 'New group'} + + + + {group ? 'Choose a new name for this group.' : 'Name a group to sort chats into.'} + + + +
    +
    + + + +
    + + + + Cancel + + + +
    +
    +
    diff --git a/ui/apps/chat/src/lib/components/app/dialogs/DialogGroupPicker.svelte b/ui/apps/chat/src/lib/components/app/dialogs/DialogGroupPicker.svelte new file mode 100644 index 000000000000..77f24269b658 --- /dev/null +++ b/ui/apps/chat/src/lib/components/app/dialogs/DialogGroupPicker.svelte @@ -0,0 +1,94 @@ + + + + !open && close()} open={options !== null}> + + Move to group + +
    + { + if (event.key === 'Enter' && newGroupName) void createAndSelect(); + }} + placeholder="Search or create a group" + size="sm" + /> +
    + +
    + + + {#if groups.length > 0} + + + {#each groups as group (group.id)} + + {/each} + {:else if newGroupName} +

    No matching groups

    + {/if} +
    +
    +
    diff --git a/tools/ui/src/lib/components/app/dialogs/DialogMcpResourcePreview.svelte b/ui/apps/chat/src/lib/components/app/dialogs/DialogMcpResourcePreview.svelte similarity index 87% rename from tools/ui/src/lib/components/app/dialogs/DialogMcpResourcePreview.svelte rename to ui/apps/chat/src/lib/components/app/dialogs/DialogMcpResourcePreview.svelte index e09a9aba0733..b6ad53a5155e 100644 --- a/tools/ui/src/lib/components/app/dialogs/DialogMcpResourcePreview.svelte +++ b/ui/apps/chat/src/lib/components/app/dialogs/DialogMcpResourcePreview.svelte @@ -1,18 +1,18 @@
    -
    diff --git a/tools/ui/src/lib/components/app/mcp/McpServerCard/McpServerCardCompact.svelte b/ui/apps/chat/src/lib/components/app/mcp/McpServerCard/McpServerCardCompact.svelte similarity index 87% rename from tools/ui/src/lib/components/app/mcp/McpServerCard/McpServerCardCompact.svelte rename to ui/apps/chat/src/lib/components/app/mcp/McpServerCard/McpServerCardCompact.svelte index da0ce1ffe75f..4abd93ed01b5 100644 --- a/tools/ui/src/lib/components/app/mcp/McpServerCard/McpServerCardCompact.svelte +++ b/ui/apps/chat/src/lib/components/app/mcp/McpServerCard/McpServerCardCompact.svelte @@ -1,6 +1,6 @@
    - + @@ -33,10 +33,10 @@
    - + - + - +
    diff --git a/tools/ui/src/lib/components/app/mcp/McpServerForm.svelte b/ui/apps/chat/src/lib/components/app/mcp/McpServerForm.svelte similarity index 94% rename from tools/ui/src/lib/components/app/mcp/McpServerForm.svelte rename to ui/apps/chat/src/lib/components/app/mcp/McpServerForm.svelte index f9f07ad63d9e..c0dd254e76a4 100644 --- a/tools/ui/src/lib/components/app/mcp/McpServerForm.svelte +++ b/ui/apps/chat/src/lib/components/app/mcp/McpServerForm.svelte @@ -1,12 +1,12 @@ + + + + + + diff --git a/tools/ui/src/lib/components/app/misc/ScrollCarousel.svelte b/ui/apps/chat/src/lib/components/app/misc/ScrollCarousel.svelte similarity index 87% rename from tools/ui/src/lib/components/app/misc/ScrollCarousel.svelte rename to ui/apps/chat/src/lib/components/app/misc/ScrollCarousel.svelte index 38f4d07b84cf..cec8cb4486b3 100644 --- a/tools/ui/src/lib/components/app/misc/ScrollCarousel.svelte +++ b/ui/apps/chat/src/lib/components/app/misc/ScrollCarousel.svelte @@ -1,9 +1,9 @@ - (isNearViewport = true)} class={className}> + (isNearViewport = true))} class={className}> - import { MODEL_ID } from '$lib/constants'; - import { HuggingFaceService } from '$lib/services'; - import type { ModelOption } from '$lib/types/models'; - import { nearViewport, repoOf } from '$lib/utils'; - import { formatContextLength } from '$lib/utils/formatters'; + import { MODEL_ID } from '#lib/constants/index.ts'; + import { HuggingFaceService } from '#lib/services/index.ts'; + import type { ModelOption } from '#lib/types/models.js'; + import { formatContextLength } from '#lib/utils/formatters.ts'; + import { nearViewport, repoOf } from '#lib/utils/index.ts'; interface Props { class?: string; @@ -51,7 +51,7 @@ (isNearViewport = true)} + {@attach nearViewport(() => (isNearViewport = true))} class={['text-sm text-muted-foreground', className]} > {formatContextLength(values)} diff --git a/tools/ui/src/lib/components/app/models/ModelDraftSubline.svelte b/ui/apps/chat/src/lib/components/app/models/ModelDraftSubline.svelte similarity index 88% rename from tools/ui/src/lib/components/app/models/ModelDraftSubline.svelte rename to ui/apps/chat/src/lib/components/app/models/ModelDraftSubline.svelte index 101215d11138..9d308c0bb44c 100644 --- a/tools/ui/src/lib/components/app/models/ModelDraftSubline.svelte +++ b/ui/apps/chat/src/lib/components/app/models/ModelDraftSubline.svelte @@ -1,7 +1,7 @@ + +{#if resolvedShowRaw} + +{:else} + !isAuxSidecar(badge.kind))} + name={parsed.modelName ?? modelId} + org={parsed.orgName ?? undefined} + params={hideParameters ? undefined : (parsed.params ?? undefined)} + quantization={resolvedHideQuantization ? undefined : (parsed.quantization ?? undefined)} + sidecar={parsed.sidecar ?? undefined} + tags={resolvedHideTags ? [] : [...(parsed.tags ?? []), ...(tags ?? [])]} + tooltip={showRawTooltip ? modelId : undefined} + /> +{/if} diff --git a/tools/ui/src/lib/components/app/models/ModelLoadControl.svelte b/ui/apps/chat/src/lib/components/app/models/ModelLoadControl.svelte similarity index 69% rename from tools/ui/src/lib/components/app/models/ModelLoadControl.svelte rename to ui/apps/chat/src/lib/components/app/models/ModelLoadControl.svelte index 6d1ea5a93e60..4c54d751cac4 100644 --- a/tools/ui/src/lib/components/app/models/ModelLoadControl.svelte +++ b/ui/apps/chat/src/lib/components/app/models/ModelLoadControl.svelte @@ -1,8 +1,8 @@ + +{#if hubEnabled} + +{/if} diff --git a/tools/ui/src/lib/components/app/models/ModelRowActions.svelte b/ui/apps/chat/src/lib/components/app/models/ModelRowActions.svelte similarity index 76% rename from tools/ui/src/lib/components/app/models/ModelRowActions.svelte rename to ui/apps/chat/src/lib/components/app/models/ModelRowActions.svelte index 5c2f321bd2df..33be4c624d35 100644 --- a/tools/ui/src/lib/components/app/models/ModelRowActions.svelte +++ b/ui/apps/chat/src/lib/components/app/models/ModelRowActions.svelte @@ -1,8 +1,8 @@ {#snippet selectorTriggerInner()} - + {#if selectedOption} @@ -154,9 +154,9 @@ ms.setSearchTerm(v)} {onSearchKeyDown} @@ -204,20 +205,21 @@ {@render pickerContent('px-1.5')} - - {#snippet footer()} - - - - - Manage models - - - {/snippet} + +{#snippet manageModelsFooter()} + + + + + Manage models + + +{/snippet} + {#snippet pickerContent(listClass: string)}
    {#if !ms.isCurrentModelInCache && currentModel} @@ -225,7 +227,7 @@
    diff --git a/tools/ui/src/lib/components/app/models/discover/ModelsDiscoverDetails/ModelsDiscoverDetailsDownloadOptions/ModelsDiscoverDetailsDownloadOptionsDraftDownloadButton.svelte b/ui/apps/chat/src/lib/components/app/models/discover/ModelsDiscoverDetails/ModelsDiscoverDetailsDownloadOptions/ModelsDiscoverDetailsDownloadOptionsDraftDownloadButton.svelte similarity index 73% rename from tools/ui/src/lib/components/app/models/discover/ModelsDiscoverDetails/ModelsDiscoverDetailsDownloadOptions/ModelsDiscoverDetailsDownloadOptionsDraftDownloadButton.svelte rename to ui/apps/chat/src/lib/components/app/models/discover/ModelsDiscoverDetails/ModelsDiscoverDetailsDownloadOptions/ModelsDiscoverDetailsDownloadOptionsDraftDownloadButton.svelte index d7cbd8becd84..2ba973c2cb92 100644 --- a/tools/ui/src/lib/components/app/models/discover/ModelsDiscoverDetails/ModelsDiscoverDetailsDownloadOptions/ModelsDiscoverDetailsDownloadOptionsDraftDownloadButton.svelte +++ b/ui/apps/chat/src/lib/components/app/models/discover/ModelsDiscoverDetails/ModelsDiscoverDetailsDownloadOptions/ModelsDiscoverDetailsDownloadOptionsDraftDownloadButton.svelte @@ -1,9 +1,9 @@ {#if readme} -
    +
    {/if} diff --git a/tools/ui/src/lib/components/app/models/discover/ModelsDiscoverDetails/ModelsDiscoverDetailsSkeleton.svelte b/ui/apps/chat/src/lib/components/app/models/discover/ModelsDiscoverDetails/ModelsDiscoverDetailsSkeleton.svelte similarity index 89% rename from tools/ui/src/lib/components/app/models/discover/ModelsDiscoverDetails/ModelsDiscoverDetailsSkeleton.svelte rename to ui/apps/chat/src/lib/components/app/models/discover/ModelsDiscoverDetails/ModelsDiscoverDetailsSkeleton.svelte index 8438a3c2b47d..1841495389d4 100644 --- a/tools/ui/src/lib/components/app/models/discover/ModelsDiscoverDetails/ModelsDiscoverDetailsSkeleton.svelte +++ b/ui/apps/chat/src/lib/components/app/models/discover/ModelsDiscoverDetails/ModelsDiscoverDetailsSkeleton.svelte @@ -1,5 +1,5 @@ @@ -8,7 +8,7 @@
    - +
    @@ -47,7 +47,7 @@
    -
    +
    {#each [0, 1, 2] as _, index (index)}
    -
    +
    diff --git a/tools/ui/src/lib/components/app/models/discover/ModelsDiscoverDetails/index.ts b/ui/apps/chat/src/lib/components/app/models/discover/ModelsDiscoverDetails/index.ts similarity index 100% rename from tools/ui/src/lib/components/app/models/discover/ModelsDiscoverDetails/index.ts rename to ui/apps/chat/src/lib/components/app/models/discover/ModelsDiscoverDetails/index.ts diff --git a/tools/ui/src/lib/components/app/models/discover/ModelsDiscoverList/ModelsDiscoverList.svelte b/ui/apps/chat/src/lib/components/app/models/discover/ModelsDiscoverList/ModelsDiscoverList.svelte similarity index 93% rename from tools/ui/src/lib/components/app/models/discover/ModelsDiscoverList/ModelsDiscoverList.svelte rename to ui/apps/chat/src/lib/components/app/models/discover/ModelsDiscoverList/ModelsDiscoverList.svelte index 5ebff7230d32..8f6c41345fe2 100644 --- a/tools/ui/src/lib/components/app/models/discover/ModelsDiscoverList/ModelsDiscoverList.svelte +++ b/ui/apps/chat/src/lib/components/app/models/discover/ModelsDiscoverList/ModelsDiscoverList.svelte @@ -1,7 +1,7 @@ {#snippet itemIcon(IconComponent: Component)} - + {/snippet} -
    + +
    {#each actions as item, i (item.tooltip)} {@const isActive = isItemActive(item)} {@const itemOnClick = itemClickHandler(item)} @@ -99,15 +105,20 @@ {#if showIcons}
    + + {/each} + + {#if items.length > SIDEBAR_SECTION_PREVIEW_COUNT} + +
  • + uiStore.toggleSidebarSectionExpanded(sectionId)} + /> +
  • + {/if} +
+ + + + (confirmDeleteOpen = false)} + onConfirm={handleDelete} + open={confirmDeleteOpen} + title="Delete {group.name}?" + variant="destructive" +/> diff --git a/ui/apps/chat/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationGroupSubmenu.svelte b/ui/apps/chat/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationGroupSubmenu.svelte new file mode 100644 index 000000000000..59c9d0b8caa7 --- /dev/null +++ b/ui/apps/chat/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationGroupSubmenu.svelte @@ -0,0 +1,123 @@ + + + void handleOpenChange(open)}> + + + + {label} + + + + event.preventDefault()} + > + + + + + + + {#if groups.length > 0} + + +
+ {#each groups as group (group.id)} + + {/each} +
+ {/if} +
+
diff --git a/tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationSearch.svelte b/ui/apps/chat/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationSearch.svelte similarity index 85% rename from tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationSearch.svelte rename to ui/apps/chat/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationSearch.svelte index 0e2767c73ae7..e9106ac28121 100644 --- a/tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationSearch.svelte +++ b/ui/apps/chat/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationSearch.svelte @@ -1,5 +1,5 @@ + + + +
+ + + {#if trailing} +
{@render trailing()}
+ {/if} +
diff --git a/tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationSelectionBar.svelte b/ui/apps/chat/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationSelectionBar.svelte similarity index 80% rename from tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationSelectionBar.svelte rename to ui/apps/chat/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationSelectionBar.svelte index e0e547d519c4..8bad1e4d480b 100644 --- a/tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationSelectionBar.svelte +++ b/ui/apps/chat/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationSelectionBar.svelte @@ -1,8 +1,8 @@ + + + diff --git a/tools/ui/src/lib/components/app/navigation/index.ts b/ui/apps/chat/src/lib/components/app/navigation/index.ts similarity index 93% rename from tools/ui/src/lib/components/app/navigation/index.ts rename to ui/apps/chat/src/lib/components/app/navigation/index.ts index 1ebf080267bb..a4dc758ad1e9 100644 --- a/tools/ui/src/lib/components/app/navigation/index.ts +++ b/ui/apps/chat/src/lib/components/app/navigation/index.ts @@ -49,6 +49,7 @@ export { default as DropdownMenuSearchable } from './DropdownMenuSearchable.svel * - Destructive variant styling * - Keyboard shortcut display * - Separator support between groups + * - A drawer on a phone, unless `anchor` pins the menu to an element (a held row) * * @example * ```svelte @@ -124,7 +125,8 @@ export { default as SidebarNavigation } from './SidebarNavigation/SidebarNavigat * Single conversation item in sidebar. Displays conversation title (truncated), * last message preview, and timestamp. Shows context menu on right-click with * rename and delete options. Highlights when active (matches current route). - * Handles click to navigate and keyboard accessibility. + * Handles click to navigate and keyboard accessibility. On a phone, holding the + * row opens its actions menu anchored below it, in place of the three-dot trigger. */ export { default as SidebarNavigationConversationItem } from './SidebarNavigation/SidebarNavigationConversationItem.svelte'; @@ -180,13 +182,16 @@ export { default as SidebarNavigationSelectionBar } from './SidebarNavigation/Si export { default as SidebarNavigationConversationList } from './SidebarNavigation/SidebarNavigationConversationList.svelte'; export { default as SidebarNavigationActions } from './SidebarNavigation/SidebarNavigationActions.svelte'; +/** The sidebar's footer: Models, MCP and Settings in a group inset in the sidebar. */ +export { default as SidebarNavigationFooter } from './SidebarNavigation/SidebarNavigationFooter.svelte'; + /** * **SidebarNavigationSearchResults** - Filtered conversation list for search. * * Pure-presentational rendering of the search-mode subtree: "Search results" * header, the matching items rendered through {@link SidebarNavigationConversationItem}, * and contextual empty-state messages. Used as the body of the mobile `/search` - * route; desktop search goes through {@link DialogSearch}. + * route; the sidebar's search opens {@link DialogSearch}. * * The caller is expected to provide an already-filtered list via * `filteredConversations` and a `searchQuery` for the empty-state messages. diff --git a/tools/ui/src/lib/components/app/server/ServerErrorSplash.svelte b/ui/apps/chat/src/lib/components/app/servers/ServerErrorSplash.svelte similarity index 93% rename from tools/ui/src/lib/components/app/server/ServerErrorSplash.svelte rename to ui/apps/chat/src/lib/components/app/servers/ServerErrorSplash.svelte index e8154e5ce22c..fab3edba4090 100644 --- a/tools/ui/src/lib/components/app/server/ServerErrorSplash.svelte +++ b/ui/apps/chat/src/lib/components/app/servers/ServerErrorSplash.svelte @@ -1,13 +1,13 @@ -
+
section.slug === activeSlug} @@ -161,6 +172,7 @@ section.slug === activeSlug} onSectionChange={handleSectionChange} sections={SETTINGS_CHAT_SECTIONS} @@ -187,7 +199,7 @@
diff --git a/tools/ui/src/lib/components/app/settings/SettingsChat/SettingsChatFields.svelte b/ui/apps/chat/src/lib/components/app/settings/SettingsChat/SettingsChatFields.svelte similarity index 82% rename from tools/ui/src/lib/components/app/settings/SettingsChat/SettingsChatFields.svelte rename to ui/apps/chat/src/lib/components/app/settings/SettingsChat/SettingsChatFields.svelte index 5dfba6bb374c..4dc97756d7fa 100644 --- a/tools/ui/src/lib/components/app/settings/SettingsChat/SettingsChatFields.svelte +++ b/ui/apps/chat/src/lib/components/app/settings/SettingsChat/SettingsChatFields.svelte @@ -1,16 +1,21 @@ -
+ + +
{#each sections as section (section.title)} diff --git a/tools/ui/src/lib/components/app/settings/SettingsFooter.svelte b/ui/apps/chat/src/lib/components/app/settings/SettingsFooter.svelte similarity index 86% rename from tools/ui/src/lib/components/app/settings/SettingsFooter.svelte rename to ui/apps/chat/src/lib/components/app/settings/SettingsFooter.svelte index f1a9b4ceb292..ffcc4c291672 100644 --- a/tools/ui/src/lib/components/app/settings/SettingsFooter.svelte +++ b/ui/apps/chat/src/lib/components/app/settings/SettingsFooter.svelte @@ -1,5 +1,5 @@ diff --git a/tools/ui/src/lib/components/pwa/PwaRefreshAlert.svelte b/ui/apps/chat/src/lib/components/pwa/PwaRefreshAlert.svelte similarity index 67% rename from tools/ui/src/lib/components/pwa/PwaRefreshAlert.svelte rename to ui/apps/chat/src/lib/components/pwa/PwaRefreshAlert.svelte index 56a71406ff6b..00cde3c6ba6e 100644 --- a/tools/ui/src/lib/components/pwa/PwaRefreshAlert.svelte +++ b/ui/apps/chat/src/lib/components/pwa/PwaRefreshAlert.svelte @@ -1,8 +1,8 @@ @@ -18,12 +18,7 @@ + + + Downloaded + + +
+
diff --git a/ui/lib/ui/src/svelte.config.js b/ui/lib/ui/src/svelte.config.js new file mode 100644 index 000000000000..e0d56086c001 --- /dev/null +++ b/ui/lib/ui/src/svelte.config.js @@ -0,0 +1,5 @@ +// Apps in ui/apps compile these sources themselves, so their svelte-check and editors read +// them too and look upwards from each file for a Svelte config. Without this one they would +// load vite.config.ts a level up, which needs this package's own dependencies installed. +// The package itself is configured in vite.config.ts. +export default {}; diff --git a/ui/lib/ui/static/favicon.ico b/ui/lib/ui/static/favicon.ico new file mode 100644 index 000000000000..4d5fa4cdddcf Binary files /dev/null and b/ui/lib/ui/static/favicon.ico differ diff --git a/ui/lib/ui/static/favicon.svg b/ui/lib/ui/static/favicon.svg new file mode 100644 index 000000000000..e15ac3d7675c --- /dev/null +++ b/ui/lib/ui/static/favicon.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/tools/ui/tests/stories/a11y/ActionIcon.a11y.stories.svelte b/ui/lib/ui/tests/stories/app/ActionIcon.a11y.stories.svelte similarity index 85% rename from tools/ui/tests/stories/a11y/ActionIcon.a11y.stories.svelte rename to ui/lib/ui/tests/stories/app/ActionIcon.a11y.stories.svelte index f94e7a792bea..2a0635015db2 100644 --- a/tools/ui/tests/stories/a11y/ActionIcon.a11y.stories.svelte +++ b/ui/lib/ui/tests/stories/app/ActionIcon.a11y.stories.svelte @@ -1,7 +1,7 @@ diff --git a/ui/lib/ui/tests/stories/app/ActionIcon.stories.svelte b/ui/lib/ui/tests/stories/app/ActionIcon.stories.svelte new file mode 100644 index 000000000000..ee3b1a62f6e4 --- /dev/null +++ b/ui/lib/ui/tests/stories/app/ActionIcon.stories.svelte @@ -0,0 +1,34 @@ + + + + + +
+ + + + + +
+
+ + + + +
+
diff --git a/ui/lib/ui/tests/stories/app/SearchInput.stories.svelte b/ui/lib/ui/tests/stories/app/SearchInput.stories.svelte new file mode 100644 index 000000000000..13db4d2be05c --- /dev/null +++ b/ui/lib/ui/tests/stories/app/SearchInput.stories.svelte @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + diff --git a/ui/lib/ui/tests/stories/app/SyntaxHighlightedCode.stories.svelte b/ui/lib/ui/tests/stories/app/SyntaxHighlightedCode.stories.svelte new file mode 100644 index 000000000000..e3bd6cc2abc2 --- /dev/null +++ b/ui/lib/ui/tests/stories/app/SyntaxHighlightedCode.stories.svelte @@ -0,0 +1,23 @@ + + + diff --git a/ui/lib/ui/tests/stories/components/actions/Button.stories.svelte b/ui/lib/ui/tests/stories/components/actions/Button.stories.svelte new file mode 100644 index 000000000000..bbabfd5a03e8 --- /dev/null +++ b/ui/lib/ui/tests/stories/components/actions/Button.stories.svelte @@ -0,0 +1,54 @@ + + + + + {#each variants as variant (variant)} + +
+ {#each sizes as size (size)} + + {/each} + + + + +
+
+ {/each} + + +
+ + + +
+
+
+
diff --git a/ui/lib/ui/tests/stories/components/actions/ButtonGroup.stories.svelte b/ui/lib/ui/tests/stories/components/actions/ButtonGroup.stories.svelte new file mode 100644 index 000000000000..9704b419c532 --- /dev/null +++ b/ui/lib/ui/tests/stories/components/actions/ButtonGroup.stories.svelte @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ui/lib/ui/tests/stories/components/actions/Toggle.stories.svelte b/ui/lib/ui/tests/stories/components/actions/Toggle.stories.svelte new file mode 100644 index 000000000000..15594608f33e --- /dev/null +++ b/ui/lib/ui/tests/stories/components/actions/Toggle.stories.svelte @@ -0,0 +1,66 @@ + + + + + + + + + + + + + +
+ + + +
+
+ + +
+ Wrap + + Wrap + + Wrap +
+
+ + + + + + +
+ + + Toggle + + + + Wrap + + + + +
+
+
+
diff --git a/ui/lib/ui/tests/stories/components/actions/ToggleGroup.stories.svelte b/ui/lib/ui/tests/stories/components/actions/ToggleGroup.stories.svelte new file mode 100644 index 000000000000..73eabcf47ffb --- /dev/null +++ b/ui/lib/ui/tests/stories/components/actions/ToggleGroup.stories.svelte @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + Tools + + Vision + + Audio + + + + + + Tools + + Vision + + Audio + + + + +
+ {#each sizes as size (size)} + + + + + + {/each} +
+
+ + + + + + + + +
+
diff --git a/ui/lib/ui/tests/stories/components/display/Alert.stories.svelte b/ui/lib/ui/tests/stories/components/display/Alert.stories.svelte new file mode 100644 index 000000000000..85e7ca7cb604 --- /dev/null +++ b/ui/lib/ui/tests/stories/components/display/Alert.stories.svelte @@ -0,0 +1,77 @@ + + + + + + + + + Model is loading + + The first reply can take a few seconds. + + + + + + + + Context is full + + Start a new chat or remove some attachments. + + + + + + + + Model loaded + + Qwen 2.5 7B is ready on port 9931. + + + + + + + + Low memory + + Gemma 2 27B needs 16.6 GB; 12 GB is free. + + + + + + + + Update available + + llama.cpp b9726 adds faster prompt processing. + + + + + + + + Saved to this browser + + + + diff --git a/ui/lib/ui/tests/stories/components/display/Badge.stories.svelte b/ui/lib/ui/tests/stories/components/display/Badge.stories.svelte new file mode 100644 index 000000000000..86862b0fa17d --- /dev/null +++ b/ui/lib/ui/tests/stories/components/display/Badge.stories.svelte @@ -0,0 +1,35 @@ + + + + + {#each variants as variant (variant)} + + Q4_K_M + + {/each} + + diff --git a/ui/lib/ui/tests/stories/components/display/Card.stories.svelte b/ui/lib/ui/tests/stories/components/display/Card.stories.svelte new file mode 100644 index 000000000000..3119820d4c18 --- /dev/null +++ b/ui/lib/ui/tests/stories/components/display/Card.stories.svelte @@ -0,0 +1,33 @@ + + + + + + Qwen3.8-27B + + 131k context, vision and tool use + + + + Loaded on the server and ready to answer. + + + + + + + + + diff --git a/ui/lib/ui/tests/stories/components/display/Collapsible.stories.svelte b/ui/lib/ui/tests/stories/components/display/Collapsible.stories.svelte new file mode 100644 index 000000000000..2546c3c2ad22 --- /dev/null +++ b/ui/lib/ui/tests/stories/components/display/Collapsible.stories.svelte @@ -0,0 +1,52 @@ + + +{#snippet section(open: boolean)} + +
+ Advanced sampling + + + {#snippet child({ props })} + + {/snippet} + +
+ +
temperature 0.8
+ + +
top_p 0.95
+ +
min_p 0.05
+
+
+{/snippet} + + + + + {@render section(false)} + + + + {@render section(true)} + + + diff --git a/ui/lib/ui/tests/stories/components/display/Empty.stories.svelte b/ui/lib/ui/tests/stories/components/display/Empty.stories.svelte new file mode 100644 index 000000000000..4e24b3fc82cd --- /dev/null +++ b/ui/lib/ui/tests/stories/components/display/Empty.stories.svelte @@ -0,0 +1,32 @@ + + + + + + + + + + No conversations yet + + Your chats are saved in this browser and show up here. + + + + + + + diff --git a/ui/lib/ui/tests/stories/components/display/ScrollArea.stories.svelte b/ui/lib/ui/tests/stories/components/display/ScrollArea.stories.svelte new file mode 100644 index 000000000000..5f352b904353 --- /dev/null +++ b/ui/lib/ui/tests/stories/components/display/ScrollArea.stories.svelte @@ -0,0 +1,29 @@ + + + + +
+

Conversations

+ + {#each chats as chat (chat)} +
{chat}
+ + + {/each} +
+
+
diff --git a/ui/lib/ui/tests/stories/components/display/Separator.stories.svelte b/ui/lib/ui/tests/stories/components/display/Separator.stories.svelte new file mode 100644 index 000000000000..8a659c0d9975 --- /dev/null +++ b/ui/lib/ui/tests/stories/components/display/Separator.stories.svelte @@ -0,0 +1,34 @@ + + + +
+

Qwen3.8-27B

+ +

Loaded, 131k context

+ + + +
+ Chat + + + + Models + + + + Settings +
+
+
diff --git a/ui/lib/ui/tests/stories/components/display/Skeleton.stories.svelte b/ui/lib/ui/tests/stories/components/display/Skeleton.stories.svelte new file mode 100644 index 000000000000..ae2dba5ffb2d --- /dev/null +++ b/ui/lib/ui/tests/stories/components/display/Skeleton.stories.svelte @@ -0,0 +1,40 @@ + + + + + +
+ + + + + +
+
+ + +
+ + +
+ + + +
+
+
+
+
diff --git a/ui/lib/ui/tests/stories/components/display/Table.stories.svelte b/ui/lib/ui/tests/stories/components/display/Table.stories.svelte new file mode 100644 index 000000000000..d253cc53a620 --- /dev/null +++ b/ui/lib/ui/tests/stories/components/display/Table.stories.svelte @@ -0,0 +1,60 @@ + + + +
+ + Models on this server + + + + Model + + Quant + + Context + + Size + + + + + {#each rows as row (row.model + row.quant)} + + {row.model} + + {row.quant} + + {row.context} + + {row.size} + + {/each} + + + + + Total + + 47.1 GB + + + +
+
diff --git a/ui/lib/ui/tests/stories/components/forms/Checkbox.stories.svelte b/ui/lib/ui/tests/stories/components/forms/Checkbox.stories.svelte new file mode 100644 index 000000000000..a091f067558d --- /dev/null +++ b/ui/lib/ui/tests/stories/components/forms/Checkbox.stories.svelte @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ui/lib/ui/tests/stories/components/forms/Input.stories.svelte b/ui/lib/ui/tests/stories/components/forms/Input.stories.svelte new file mode 100644 index 000000000000..14404c5a9930 --- /dev/null +++ b/ui/lib/ui/tests/stories/components/forms/Input.stories.svelte @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ui/lib/ui/tests/stories/components/forms/Label.stories.svelte b/ui/lib/ui/tests/stories/components/forms/Label.stories.svelte new file mode 100644 index 000000000000..dcf3a927d6ae --- /dev/null +++ b/ui/lib/ui/tests/stories/components/forms/Label.stories.svelte @@ -0,0 +1,21 @@ + + + +
+ + + +
+
diff --git a/ui/lib/ui/tests/stories/components/forms/RadioGroup.stories.svelte b/ui/lib/ui/tests/stories/components/forms/RadioGroup.stories.svelte new file mode 100644 index 000000000000..1e31f12689bd --- /dev/null +++ b/ui/lib/ui/tests/stories/components/forms/RadioGroup.stories.svelte @@ -0,0 +1,43 @@ + + + + + + + {#each options as option (option)} + + {/each} + + + + + + {#each options as option (option)} + + {/each} + + + + diff --git a/ui/lib/ui/tests/stories/components/forms/Select.stories.svelte b/ui/lib/ui/tests/stories/components/forms/Select.stories.svelte new file mode 100644 index 000000000000..bd3e1743263b --- /dev/null +++ b/ui/lib/ui/tests/stories/components/forms/Select.stories.svelte @@ -0,0 +1,60 @@ + + + + + + + Choose a theme + + + + + + Dark + + + + + + System + + + + +
+ + Light + + + + Theme + + {#each themes as theme (theme.value)} + + {/each} + + + +
+
+
+
diff --git a/ui/lib/ui/tests/stories/components/forms/Switch.stories.svelte b/ui/lib/ui/tests/stories/components/forms/Switch.stories.svelte new file mode 100644 index 000000000000..c9cb3453ff79 --- /dev/null +++ b/ui/lib/ui/tests/stories/components/forms/Switch.stories.svelte @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/ui/lib/ui/tests/stories/components/forms/Textarea.stories.svelte b/ui/lib/ui/tests/stories/components/forms/Textarea.stories.svelte new file mode 100644 index 000000000000..779c152223e8 --- /dev/null +++ b/ui/lib/ui/tests/stories/components/forms/Textarea.stories.svelte @@ -0,0 +1,34 @@ + + + + + +