mirror of
https://github.com/sst/opencode.git
synced 2025-07-08 00:25:00 +00:00
This commit is contained in:
parent
85214d7c59
commit
107363b1d9
2 changed files with 62 additions and 107 deletions
|
@ -243,6 +243,44 @@ function getStatusText(status: [Status, string?]): string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkOverflow(getEl: () => HTMLElement | undefined, watch?: () => any) {
|
||||||
|
const [needsToggle, setNeedsToggle] = createSignal(false)
|
||||||
|
|
||||||
|
function measure() {
|
||||||
|
const el = getEl()
|
||||||
|
if (!el) return
|
||||||
|
setNeedsToggle(el.scrollHeight > el.clientHeight + 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
let raf = 0
|
||||||
|
|
||||||
|
function probe() {
|
||||||
|
const el = getEl()
|
||||||
|
if (el && el.offsetParent !== null && el.getBoundingClientRect().height) {
|
||||||
|
measure()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
raf = requestAnimationFrame(probe)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
raf = requestAnimationFrame(probe)
|
||||||
|
|
||||||
|
const ro = new ResizeObserver(measure)
|
||||||
|
const el = getEl()
|
||||||
|
if (el) ro.observe(el)
|
||||||
|
|
||||||
|
onCleanup(() => {
|
||||||
|
cancelAnimationFrame(raf)
|
||||||
|
ro.disconnect()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
if (watch) createEffect(measure)
|
||||||
|
|
||||||
|
return needsToggle
|
||||||
|
}
|
||||||
|
|
||||||
function ProviderIcon(props: { provider: string; size?: number }) {
|
function ProviderIcon(props: { provider: string; size?: number }) {
|
||||||
const size = props.size || 16
|
const size = props.size || 16
|
||||||
return (
|
return (
|
||||||
|
@ -296,34 +334,11 @@ interface TextPartProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
||||||
expand?: boolean
|
expand?: boolean
|
||||||
}
|
}
|
||||||
function TextPart(props: TextPartProps) {
|
function TextPart(props: TextPartProps) {
|
||||||
const [local, rest] = splitProps(props, [
|
|
||||||
"text",
|
|
||||||
"expand",
|
|
||||||
])
|
|
||||||
const [expanded, setExpanded] = createSignal(false)
|
|
||||||
const [overflowed, setOverflowed] = createSignal(false)
|
|
||||||
let preEl: HTMLPreElement | undefined
|
let preEl: HTMLPreElement | undefined
|
||||||
|
|
||||||
function checkOverflow() {
|
const [local, rest] = splitProps(props, ["text", "expand"])
|
||||||
if (preEl && !local.expand) {
|
const [expanded, setExpanded] = createSignal(false)
|
||||||
setOverflowed(preEl.scrollHeight > preEl.clientHeight + 1)
|
const overflowed = checkOverflow(() => preEl, () => local.expand)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
checkOverflow()
|
|
||||||
window.addEventListener("resize", checkOverflow)
|
|
||||||
})
|
|
||||||
|
|
||||||
createEffect(() => {
|
|
||||||
local.text
|
|
||||||
local.expand
|
|
||||||
setTimeout(checkOverflow, 0)
|
|
||||||
})
|
|
||||||
|
|
||||||
onCleanup(() => {
|
|
||||||
window.removeEventListener("resize", checkOverflow)
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
@ -331,7 +346,7 @@ function TextPart(props: TextPartProps) {
|
||||||
data-expanded={expanded() || local.expand === true}
|
data-expanded={expanded() || local.expand === true}
|
||||||
{...rest}
|
{...rest}
|
||||||
>
|
>
|
||||||
<pre ref={(el) => (preEl = el)}>{local.text}</pre>
|
<pre ref={preEl}>{local.text}</pre>
|
||||||
{((!local.expand && overflowed()) || expanded()) && (
|
{((!local.expand && overflowed()) || expanded()) && (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
@ -349,31 +364,11 @@ interface ErrorPartProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
||||||
expand?: boolean
|
expand?: boolean
|
||||||
}
|
}
|
||||||
function ErrorPart(props: ErrorPartProps) {
|
function ErrorPart(props: ErrorPartProps) {
|
||||||
|
let preEl: HTMLDivElement | undefined
|
||||||
|
|
||||||
const [local, rest] = splitProps(props, ["expand", "children"])
|
const [local, rest] = splitProps(props, ["expand", "children"])
|
||||||
const [expanded, setExpanded] = createSignal(false)
|
const [expanded, setExpanded] = createSignal(false)
|
||||||
const [overflowed, setOverflowed] = createSignal(false)
|
const overflowed = checkOverflow(() => preEl, () => local.expand)
|
||||||
let preEl: HTMLElement | undefined
|
|
||||||
|
|
||||||
function checkOverflow() {
|
|
||||||
if (preEl && !local.expand) {
|
|
||||||
setOverflowed(preEl.scrollHeight > preEl.clientHeight + 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
checkOverflow()
|
|
||||||
window.addEventListener("resize", checkOverflow)
|
|
||||||
})
|
|
||||||
|
|
||||||
createEffect(() => {
|
|
||||||
local.children
|
|
||||||
local.expand
|
|
||||||
setTimeout(checkOverflow, 0)
|
|
||||||
})
|
|
||||||
|
|
||||||
onCleanup(() => {
|
|
||||||
window.removeEventListener("resize", checkOverflow)
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
@ -381,7 +376,7 @@ function ErrorPart(props: ErrorPartProps) {
|
||||||
data-expanded={expanded() || local.expand === true}
|
data-expanded={expanded() || local.expand === true}
|
||||||
{...rest}
|
{...rest}
|
||||||
>
|
>
|
||||||
<div data-section="content" ref={(el) => (preEl = el)}>
|
<div data-section="content" ref={preEl}>
|
||||||
{local.children}
|
{local.children}
|
||||||
</div>
|
</div>
|
||||||
{((!local.expand && overflowed()) || expanded()) && (
|
{((!local.expand && overflowed()) || expanded()) && (
|
||||||
|
@ -403,31 +398,11 @@ interface MarkdownPartProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
||||||
highlight?: boolean
|
highlight?: boolean
|
||||||
}
|
}
|
||||||
function MarkdownPart(props: MarkdownPartProps) {
|
function MarkdownPart(props: MarkdownPartProps) {
|
||||||
const [local, rest] = splitProps(props, ["text", "expand", "highlight"])
|
|
||||||
const [expanded, setExpanded] = createSignal(false)
|
|
||||||
const [overflowed, setOverflowed] = createSignal(false)
|
|
||||||
let divEl: HTMLDivElement | undefined
|
let divEl: HTMLDivElement | undefined
|
||||||
|
|
||||||
function checkOverflow() {
|
const [local, rest] = splitProps(props, ["text", "expand", "highlight"])
|
||||||
if (divEl && !local.expand) {
|
const [expanded, setExpanded] = createSignal(false)
|
||||||
setOverflowed(divEl.scrollHeight > divEl.clientHeight + 1)
|
const overflowed = checkOverflow(() => divEl, () => local.expand)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
checkOverflow()
|
|
||||||
window.addEventListener("resize", checkOverflow)
|
|
||||||
})
|
|
||||||
|
|
||||||
createEffect(() => {
|
|
||||||
local.text
|
|
||||||
local.expand
|
|
||||||
setTimeout(checkOverflow, 0)
|
|
||||||
})
|
|
||||||
|
|
||||||
onCleanup(() => {
|
|
||||||
window.removeEventListener("resize", checkOverflow)
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
@ -469,36 +444,16 @@ function TerminalPart(props: TerminalPartProps) {
|
||||||
"desc",
|
"desc",
|
||||||
"expand",
|
"expand",
|
||||||
])
|
])
|
||||||
|
let preEl: HTMLDivElement | undefined
|
||||||
|
|
||||||
const [expanded, setExpanded] = createSignal(false)
|
const [expanded, setExpanded] = createSignal(false)
|
||||||
const [overflowed, setOverflowed] = createSignal(false)
|
const overflowed = checkOverflow(
|
||||||
let preEl: HTMLElement | undefined
|
() => {
|
||||||
|
if (!preEl) return
|
||||||
function checkOverflow() {
|
return preEl.getElementsByTagName("pre")[0]
|
||||||
if (!preEl) return
|
},
|
||||||
|
() => local.expand
|
||||||
const code = preEl.getElementsByTagName("code")[0]
|
)
|
||||||
|
|
||||||
if (code && !local.expand) {
|
|
||||||
setOverflowed(preEl.clientHeight < code.offsetHeight)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
createEffect(() => {
|
|
||||||
local.command
|
|
||||||
local.result
|
|
||||||
local.error
|
|
||||||
local.expand
|
|
||||||
setTimeout(checkOverflow, 0)
|
|
||||||
})
|
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
checkOverflow()
|
|
||||||
window.addEventListener("resize", checkOverflow)
|
|
||||||
})
|
|
||||||
|
|
||||||
onCleanup(() => {
|
|
||||||
window.removeEventListener("resize", checkOverflow)
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
@ -515,16 +470,16 @@ function TerminalPart(props: TerminalPartProps) {
|
||||||
<Switch>
|
<Switch>
|
||||||
<Match when={local.error}>
|
<Match when={local.error}>
|
||||||
<CodeBlock
|
<CodeBlock
|
||||||
data-section="error"
|
ref={preEl}
|
||||||
lang="text"
|
lang="text"
|
||||||
ref={(el) => (preEl = el)}
|
data-section="error"
|
||||||
code={local.error || ""}
|
code={local.error || ""}
|
||||||
/>
|
/>
|
||||||
</Match>
|
</Match>
|
||||||
<Match when={local.result}>
|
<Match when={local.result}>
|
||||||
<CodeBlock
|
<CodeBlock
|
||||||
|
ref={preEl}
|
||||||
lang="console"
|
lang="console"
|
||||||
ref={(el) => (preEl = el)}
|
|
||||||
code={local.result || ""}
|
code={local.result || ""}
|
||||||
/>
|
/>
|
||||||
</Match>
|
</Match>
|
||||||
|
|
|
@ -253,7 +253,7 @@
|
||||||
line-height: 18px;
|
line-height: 18px;
|
||||||
font-size: 0.875rem;
|
font-size: 0.875rem;
|
||||||
color: var(--sl-color-text-secondary);
|
color: var(--sl-color-text-secondary);
|
||||||
max-width: var(--sm-tool-width);
|
max-width: var(--md-tool-width);
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue