Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "opencode",
"image": "oven/bun:1.3-debian",
"postCreateCommand": "apt-get update && apt-get install -y python3 make g++ && bun install",
"customizations": {
"vscode": {
"extensions": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
}
}
10 changes: 10 additions & 0 deletions packages/tui/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { DialogStatus } from "./component/dialog-status"
import { DialogDebug } from "./component/dialog-debug"
import { DialogThemeList } from "./component/dialog-theme-list"
import { DialogHelp } from "./ui/dialog-help"
import { DialogScotty } from "./ui/dialog-scotty"
import { DialogAgent } from "./component/dialog-agent"
import { DialogSessionList } from "./component/dialog-session-list"
import { DialogWorkspaceList } from "./component/dialog-workspace-list"
Expand Down Expand Up @@ -841,6 +842,15 @@ function App(props: { onSnapshot?: () => Promise<string[]>; pluginHost: TuiPlugi
dialog.clear()
},
},
{
name: "scotty.show",
title: "Show Scotty the Scottish Terrier",
slashName: "scotty",
run: () => {
dialog.replace(() => <DialogScotty />)
},
category: "System",
},
{
name: "app.console",
title: "Toggle console",
Expand Down
57 changes: 57 additions & 0 deletions packages/tui/src/ui/dialog-scotty.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { TextAttributes } from "@opentui/core"
import { For } from "solid-js"
import { useTheme } from "../context/theme"
import { useDialog } from "./dialog"
import { useBindings } from "../keymap"

const SCOTTY = [
" __",
" \\______/ \\",
" / o o \\",
" ( ^ )",
" \\ wwwww /",
" /| |\\",
" (_| \\__/ |_)",
" || ||",
" (_| |_)",
]

export function DialogScotty() {
const dialog = useDialog()
const { theme } = useTheme()

useBindings(() => ({
bindings: [
{ key: "return", desc: "Close Scotty", group: "Dialog", cmd: () => dialog.clear() },
{ key: "escape", desc: "Close Scotty", group: "Dialog", cmd: () => dialog.clear() },
],
}))

return (
<box paddingLeft={2} paddingRight={2} gap={1}>
<box flexDirection="row" justifyContent="space-between">
<text attributes={TextAttributes.BOLD} fg={theme.text}>
Scotty
</text>
<text fg={theme.textMuted} onMouseUp={() => dialog.clear()}>
esc/enter
</text>
</box>
<box paddingBottom={1}>
<For each={SCOTTY}>
{(line) => (
<text fg={theme.text} wrapMode="none">
{line}
</text>
)}
</For>
</box>
<text fg={theme.textMuted}>Let's go Tartans!</text>
<box flexDirection="row" justifyContent="flex-end" paddingBottom={1}>
<box paddingLeft={3} paddingRight={3} backgroundColor={theme.primary} onMouseUp={() => dialog.clear()}>
<text fg={theme.selectedListItemText}>ok</text>
</box>
</box>
</box>
)
}
19 changes: 19 additions & 0 deletions packages/ui/src/v2/components/tooltip-v2-behavior.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export function isFocusInside(container: { contains(node: Node): boolean } | undefined, active: Node | null) {
return !!container && !!active && container.contains(active)
}

export function shouldDropBlock(expand: boolean, hovered: boolean, focusInside: boolean) {
return !expand && !hovered && !focusInside
}

export function shouldArmFromKey(key: string) {
return key === "Enter" || key === " "
}

export function openChangePlan(input: { forceOpen: boolean; block: boolean; open: boolean; skipClick: boolean }) {
const blocked = input.forceOpen || (input.block && input.open)
return {
resetSkipClick: !blocked && input.skipClick,
applyOpen: !blocked && !input.skipClick,
}
}
89 changes: 89 additions & 0 deletions packages/ui/src/v2/components/tooltip-v2.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { describe, expect, test } from "bun:test"
import { isFocusInside, openChangePlan, shouldArmFromKey, shouldDropBlock } from "./tooltip-v2-behavior"

describe("isFocusInside", () => {
const child = {} as Node
const other = {} as Node
const container = { contains: (node: Node) => node === child }

test("is false when the trigger is missing", () => {
expect(isFocusInside(undefined, child)).toBe(false)
})

test("is false when nothing is focused", () => {
expect(isFocusInside(container, null)).toBe(false)
})

test("is true only when focus is inside the trigger", () => {
expect(isFocusInside(container, child)).toBe(true)
expect(isFocusInside(container, other)).toBe(false)
})
})

describe("shouldDropBlock", () => {
test("unblocks only when not expanded, not hovered, and focus is outside", () => {
expect(shouldDropBlock(false, false, false)).toBe(true)
})

test("keeps the block while a nested control is expanded", () => {
expect(shouldDropBlock(true, false, false)).toBe(false)
})

test("keeps the block while the trigger is hovered", () => {
expect(shouldDropBlock(false, true, false)).toBe(false)
})

test("keeps the block while focus is inside the trigger", () => {
expect(shouldDropBlock(false, false, true)).toBe(false)
})
})

describe("shouldArmFromKey", () => {
test("arms on Enter and Space", () => {
expect(shouldArmFromKey("Enter")).toBe(true)
expect(shouldArmFromKey(" ")).toBe(true)
})

test("ignores other keys", () => {
expect(shouldArmFromKey("Tab")).toBe(false)
expect(shouldArmFromKey("Escape")).toBe(false)
expect(shouldArmFromKey("a")).toBe(false)
})
})

describe("openChangePlan", () => {
test("applies the requested open state on a normal change", () => {
expect(openChangePlan({ forceOpen: false, block: false, open: true, skipClick: false })).toEqual({
resetSkipClick: false,
applyOpen: true,
})
})

test("ignores Kobalte while forceOpen is set, without consuming a trigger click", () => {
expect(openChangePlan({ forceOpen: true, block: false, open: false, skipClick: true })).toEqual({
resetSkipClick: false,
applyOpen: false,
})
})

test("does not open while blocked, without consuming a trigger click", () => {
expect(openChangePlan({ forceOpen: false, block: true, open: true, skipClick: true })).toEqual({
resetSkipClick: false,
applyOpen: false,
})
})

test("still allows a close while blocked", () => {
expect(openChangePlan({ forceOpen: false, block: true, open: false, skipClick: false })).toEqual({
resetSkipClick: false,
applyOpen: true,
})
})

test("consumes a click on the trigger and skips the open change", () => {
expect(openChangePlan({ forceOpen: false, block: false, open: false, skipClick: true })).toEqual({
resetSkipClick: true,
applyOpen: false,
})
})
})
54 changes: 25 additions & 29 deletions packages/ui/src/v2/components/tooltip-v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Tooltip as KobalteTooltip } from "@kobalte/core/tooltip"
import { createEffect, Match, onCleanup, splitProps, Switch, type JSX } from "solid-js"
import type { ComponentProps } from "solid-js"
import { createStore } from "solid-js/store"
import { isFocusInside, openChangePlan, shouldArmFromKey, shouldDropBlock } from "./tooltip-v2-behavior"
import "./tooltip-v2.css"

export interface TooltipV2Props extends ComponentProps<typeof KobalteTooltip> {
Expand Down Expand Up @@ -33,17 +34,12 @@ export function TooltipV2(props: TooltipV2Props) {

const close = () => setState("open", false)

const inside = () => {
const active = document.activeElement
if (!ref || !active) return false
return ref.contains(active)
}
const inside = () => isFocusInside(ref, document.activeElement)

const drop = (expand = state.expand) => {
if (expand) return
if (ref?.matches(":hover")) return
if (inside()) return
setState("block", false)
if (shouldDropBlock(expand, !!ref?.matches(":hover"), inside())) {
setState("block", false)
}
}

const sync = () => {
Expand All @@ -52,7 +48,6 @@ export function TooltipV2(props: TooltipV2Props) {
if (expand) {
setState("block", true)
close()
return
}
drop(expand)
}
Expand All @@ -68,16 +63,17 @@ export function TooltipV2(props: TooltipV2Props) {
}

createEffect(() => {
if (!ref) return
sync()
const obs = new MutationObserver(sync)
obs.observe(ref, {
subtree: true,
childList: true,
attributes: true,
attributeFilter: ["aria-expanded", "data-expanded"],
})
onCleanup(() => obs.disconnect())
if (ref) {
sync()
const obs = new MutationObserver(sync)
obs.observe(ref, {
subtree: true,
childList: true,
attributes: true,
attributeFilter: ["aria-expanded", "data-expanded"],
})
onCleanup(() => obs.disconnect())
}
})

let justClickedTrigger = false
Expand All @@ -95,13 +91,14 @@ export function TooltipV2(props: TooltipV2Props) {
ignoreSafeArea={local.ignoreSafeArea ?? true}
open={local.forceOpen || state.open}
onOpenChange={(open) => {
if (local.forceOpen) return
if (state.block && open) return
if (justClickedTrigger) {
justClickedTrigger = false
return
}
setState("open", open)
const plan = openChangePlan({
forceOpen: !!local.forceOpen,
block: state.block,
open,
skipClick: justClickedTrigger,
})
if (plan.resetSkipClick) justClickedTrigger = false
if (plan.applyOpen) setState("open", open)
}}
>
<KobalteTooltip.Trigger
Expand All @@ -111,8 +108,7 @@ export function TooltipV2(props: TooltipV2Props) {
class={local.class}
onPointerDownCapture={arm}
onKeyDownCapture={(event: KeyboardEvent) => {
if (event.key !== "Enter" && event.key !== " ") return
arm()
if (shouldArmFromKey(event.key)) arm()
}}
onPointerLeave={leave}
onFocusOut={() => requestAnimationFrame(() => drop())}
Expand Down
Loading