mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-07 16:03:21 +00:00
* feat: universal styled markdown code blocks with copy button and subtle scrollbar Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(sessions): use the shared DraggableTabs for the preview tab strip The session preview tabs were bespoke markup; converge them onto the same DraggableTabs component the raw-app editor uses, gaining drag-reorder and keyboard nav. The active tab keeps its breadcrumb/router picker via a new tabAccessory snippet, and tabs persist their new order. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(sessions): keep the new-tab + button right after the last tab Add an afterTabs snippet to DraggableTabs that renders inside the scroll row after the tabs (unlike trailing, which stays pinned outside it), and move the session preview "+" there so it sits next to the last tab. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(tabs): use the subtle ScrollableX scrollbar for Tabs/TabsV2 headers Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * style(sessions): use bg-surface for the preview tab strip Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * style(tabs): add subtle shadow-sm to the selected DraggableTabs tab Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * style(tabs): drop selected-tab shadow; session strip bg-surface-secondary/50 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * style(sessions): drop persistent bg on preview bar buttons, hover-only Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * refactor(scrollbar): share a .scrollbar-subtle utility across tabs and chat Extract ScrollableX's hover-revealed scrollbar styling into a global .scrollbar-subtle utility (both axes, size via --wm-scrollbar-size), have ScrollableX consume it, and apply it to the AI chat message list so the chat scrollbar matches the tabs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix: address review — scope HighlightCode copy button, plaintext unknown fences, Tailwind ScrollableX - HighlightCode: keep the subtle CopyButton + surface chip behind buttonsOnHover so the ~20 non-markdown callers keep the original light copy Button. - MarkdownCodeBlock: unlabeled/unknown fences render as plaintext instead of being mis-colored as TypeScript; added common language aliases (ts/js/py/...) so real languages still highlight. - ScrollableX: replace the custom <style> block with Tailwind overflow classes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * style: make chat and session-sidebar typing dots slightly smaller Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix: address auto-review — powershell fence to plaintext + reorder tests - MarkdownCodeBlock: drop 'powershell' from the sql group so it renders plaintext instead of SQL-colored (no powershell highlighter in the map). - sessionPreviewTabs.test.ts: cover reorder (reorders+persists, ignores unknown ids / keeps omitted at end, no-op when unchanged). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix: keep scrollbar-hidden on Tabs row as TroubleshootFlowTutorial selector hook codex-review: removing scrollbar-hidden broke the tutorial's '.border-b.flex .flex-row.whitespace-nowrap.scrollbar-hidden.mx-auto' selector. The class is inert on the non-scrolling row (ScrollableX owns the scroll) but is kept as the tutorial's stable hook. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix: preserve raw <pre> content in MarkdownCodeBlock (codex-review) As the universal pre renderer, MarkdownCodeBlock also handles sanitized raw HTML <pre>text</pre> from rehypeRaw, where the text is a direct child of <pre> (no <code>). Fall back to that text child so raw pre content isn't dropped to an empty block. Kitchen-sink sample gains a raw <pre> case. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
179 lines
4.7 KiB
Svelte
179 lines
4.7 KiB
Svelte
<script lang="ts">
|
|
import Highlight, { LineNumbers } from 'svelte-highlight'
|
|
import python from 'svelte-highlight/languages/python'
|
|
import typescript from 'svelte-highlight/languages/typescript'
|
|
import go from 'svelte-highlight/languages/go'
|
|
import shell from 'svelte-highlight/languages/shell'
|
|
import graphql from 'svelte-highlight/languages/graphql'
|
|
import javascript from 'svelte-highlight/languages/javascript'
|
|
import sql from 'svelte-highlight/languages/sql'
|
|
import powershell from 'svelte-highlight/languages/powershell'
|
|
import php from 'svelte-highlight/languages/php'
|
|
import rust from 'svelte-highlight/languages/rust'
|
|
import csharp from 'svelte-highlight/languages/csharp'
|
|
import yaml from 'svelte-highlight/languages/yaml'
|
|
import java from 'svelte-highlight/languages/java'
|
|
import ruby from 'svelte-highlight/languages/ruby'
|
|
import r from 'svelte-highlight/languages/r'
|
|
import type { Script } from '$lib/gen'
|
|
import { Button } from './common'
|
|
import CopyButton from './common/button/CopyButton.svelte'
|
|
import ScrollableX from './common/ScrollableX.svelte'
|
|
import { copyToClipboard } from '$lib/utils'
|
|
import { ClipboardCopy } from 'lucide-svelte'
|
|
import HighlightTheme from './HighlightTheme.svelte'
|
|
import { json, type LanguageType } from 'svelte-highlight/languages'
|
|
|
|
interface Props {
|
|
code?: string
|
|
language: Script['language'] | 'bunnative' | 'frontend' | 'json' | undefined
|
|
highlightLanguage?: LanguageType<string> | undefined
|
|
lines?: boolean
|
|
className?: string
|
|
onApplyCode?: () => void
|
|
showApplyButton?: boolean
|
|
applyButtonIcon?: typeof ClipboardCopy
|
|
/** Keep the copy/apply buttons hidden until the block is hovered, and render them subtly. */
|
|
buttonsOnHover?: boolean
|
|
/** Wrap the code in ScrollableX (native scroll, subtle hover-revealed scrollbar) for horizontal overflow. */
|
|
customScrollbarX?: boolean
|
|
}
|
|
|
|
let {
|
|
code = '',
|
|
language,
|
|
highlightLanguage = undefined,
|
|
lines = false,
|
|
className = '',
|
|
onApplyCode = undefined,
|
|
showApplyButton = false,
|
|
applyButtonIcon = undefined,
|
|
buttonsOnHover = false,
|
|
customScrollbarX = false
|
|
}: Props = $props()
|
|
|
|
const hoverButtonClasses = buttonsOnHover
|
|
? 'opacity-0 group-hover:opacity-100 focus-within:opacity-100 transition-opacity duration-150'
|
|
: ''
|
|
|
|
function getLang(lang: Script['language'] | 'bunnative' | 'frontend' | 'json' | undefined) {
|
|
switch (lang) {
|
|
case 'python3':
|
|
return python
|
|
case 'deno':
|
|
return typescript
|
|
case 'nativets':
|
|
return typescript
|
|
case 'bun':
|
|
return typescript
|
|
case 'bunnative':
|
|
return typescript
|
|
case 'go':
|
|
return go
|
|
case 'bash':
|
|
return shell
|
|
case 'frontend':
|
|
return javascript
|
|
case 'graphql':
|
|
return graphql
|
|
case 'mysql':
|
|
return sql
|
|
case 'postgresql':
|
|
return sql
|
|
case 'snowflake':
|
|
return sql
|
|
case 'bigquery':
|
|
return sql
|
|
case 'oracledb':
|
|
return sql
|
|
case 'duckdb':
|
|
return sql
|
|
case 'powershell':
|
|
return powershell
|
|
case 'php':
|
|
return php
|
|
case 'rust':
|
|
return rust
|
|
case 'csharp':
|
|
return csharp
|
|
case 'nu':
|
|
return python
|
|
case 'ansible':
|
|
return yaml
|
|
case 'java':
|
|
return java
|
|
case 'ruby':
|
|
return ruby
|
|
case 'rlang':
|
|
return r
|
|
case 'json':
|
|
return json
|
|
// for related places search: ADD_NEW_LANG
|
|
default:
|
|
return typescript
|
|
}
|
|
}
|
|
|
|
const lang = $derived(highlightLanguage ?? getLang(language))
|
|
</script>
|
|
|
|
<HighlightTheme />
|
|
|
|
<div class="relative group">
|
|
{#if buttonsOnHover}
|
|
<!-- Chat/markdown code blocks: subtle CopyButton on a surface chip. -->
|
|
<CopyButton
|
|
value={code}
|
|
class="absolute top-2 right-2 z-20 bg-surface rounded-md {hoverButtonClasses}"
|
|
/>
|
|
{:else}
|
|
<Button
|
|
wrapperClasses="absolute top-2 right-2 z-20"
|
|
onclick={() => copyToClipboard(code)}
|
|
color="light"
|
|
size="xs2"
|
|
startIcon={{ icon: ClipboardCopy }}
|
|
iconOnly
|
|
title="Copy to clipboard"
|
|
/>
|
|
{/if}
|
|
{#if showApplyButton}
|
|
<Button
|
|
wrapperClasses="absolute top-2 right-10 z-20 {hoverButtonClasses}"
|
|
onclick={onApplyCode}
|
|
color="light"
|
|
size="xs2"
|
|
startIcon={{
|
|
icon: applyButtonIcon
|
|
}}
|
|
iconOnly
|
|
title="Apply code"
|
|
/>
|
|
{/if}
|
|
{#if customScrollbarX}
|
|
<ScrollableX>
|
|
{@render codeBody()}
|
|
</ScrollableX>
|
|
{:else}
|
|
<div class="overflow-x-auto">
|
|
{@render codeBody()}
|
|
</div>
|
|
{/if}
|
|
</div>
|
|
|
|
{#snippet codeBody()}
|
|
{#if code?.length < 10000}
|
|
{#if !lines}
|
|
<Highlight class="nowrap {className}" language={lang} {code} />
|
|
{:else}
|
|
<Highlight class="nowrap {className}" language={lang} {code} let:highlighted>
|
|
<LineNumbers {highlighted} />
|
|
</Highlight>
|
|
{/if}
|
|
{:else}
|
|
<pre class="overflow-auto max-h-screen text-xs {className}"
|
|
><code class="language-{language}">{code}</code></pre
|
|
>
|
|
{/if}
|
|
{/snippet}
|