wip(app): file tree mode
This commit is contained in:
@@ -2,7 +2,16 @@ import { useFile } from "@/context/file"
|
||||
import { Collapsible } from "@opencode-ai/ui/collapsible"
|
||||
import { FileIcon } from "@opencode-ai/ui/file-icon"
|
||||
import { Tooltip } from "@opencode-ai/ui/tooltip"
|
||||
import { createEffect, For, Match, splitProps, Switch, type ComponentProps, type ParentProps } from "solid-js"
|
||||
import {
|
||||
createEffect,
|
||||
createMemo,
|
||||
For,
|
||||
Match,
|
||||
splitProps,
|
||||
Switch,
|
||||
type ComponentProps,
|
||||
type ParentProps,
|
||||
} from "solid-js"
|
||||
import { Dynamic } from "solid-js/web"
|
||||
import type { FileNode } from "@opencode-ai/sdk/v2"
|
||||
|
||||
@@ -11,15 +20,45 @@ export default function FileTree(props: {
|
||||
class?: string
|
||||
nodeClass?: string
|
||||
level?: number
|
||||
allowed?: readonly string[]
|
||||
onFileClick?: (file: FileNode) => void
|
||||
}) {
|
||||
const file = useFile()
|
||||
const level = props.level ?? 0
|
||||
|
||||
const filter = createMemo(() => {
|
||||
const allowed = props.allowed
|
||||
if (!allowed) return
|
||||
|
||||
const files = new Set(allowed)
|
||||
const dirs = new Set<string>()
|
||||
|
||||
for (const item of allowed) {
|
||||
const parts = item.split("/")
|
||||
const parents = parts.slice(0, -1)
|
||||
for (const [idx] of parents.entries()) {
|
||||
const dir = parents.slice(0, idx + 1).join("/")
|
||||
if (dir) dirs.add(dir)
|
||||
}
|
||||
}
|
||||
|
||||
return { files, dirs }
|
||||
})
|
||||
|
||||
createEffect(() => {
|
||||
void file.tree.list(props.path)
|
||||
})
|
||||
|
||||
const nodes = createMemo(() => {
|
||||
const nodes = file.tree.children(props.path)
|
||||
const current = filter()
|
||||
if (!current) return nodes
|
||||
return nodes.filter((node) => {
|
||||
if (node.type === "file") return current.files.has(node.path)
|
||||
return current.dirs.has(node.path)
|
||||
})
|
||||
})
|
||||
|
||||
const Node = (
|
||||
p: ParentProps &
|
||||
ComponentProps<"div"> &
|
||||
@@ -81,7 +120,7 @@ export default function FileTree(props: {
|
||||
|
||||
return (
|
||||
<div class={`flex flex-col ${props.class ?? ""}`}>
|
||||
<For each={file.tree.children(props.path)}>
|
||||
<For each={nodes()}>
|
||||
{(node) => {
|
||||
const expanded = () => file.tree.state(node.path)?.expanded ?? false
|
||||
return (
|
||||
@@ -102,7 +141,12 @@ export default function FileTree(props: {
|
||||
</Node>
|
||||
</Collapsible.Trigger>
|
||||
<Collapsible.Content>
|
||||
<FileTree path={node.path} level={level + 1} onFileClick={props.onFileClick} />
|
||||
<FileTree
|
||||
path={node.path}
|
||||
level={level + 1}
|
||||
allowed={props.allowed}
|
||||
onFileClick={props.onFileClick}
|
||||
/>
|
||||
</Collapsible.Content>
|
||||
</Collapsible>
|
||||
</Match>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -21,6 +21,12 @@
|
||||
transform: translateX(50%);
|
||||
cursor: col-resize;
|
||||
|
||||
&[data-edge="start"] {
|
||||
inset-inline-start: 0;
|
||||
inset-inline-end: auto;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
&::after {
|
||||
width: 3px;
|
||||
inset-block: 0;
|
||||
@@ -36,6 +42,12 @@
|
||||
transform: translateY(-50%);
|
||||
cursor: row-resize;
|
||||
|
||||
&[data-edge="end"] {
|
||||
inset-block-start: auto;
|
||||
inset-block-end: 0;
|
||||
transform: translateY(50%);
|
||||
}
|
||||
|
||||
&::after {
|
||||
height: 3px;
|
||||
inset-inline: 0;
|
||||
|
||||
@@ -2,6 +2,7 @@ import { splitProps, type JSX } from "solid-js"
|
||||
|
||||
export interface ResizeHandleProps extends Omit<JSX.HTMLAttributes<HTMLDivElement>, "onResize"> {
|
||||
direction: "horizontal" | "vertical"
|
||||
edge?: "start" | "end"
|
||||
size: number
|
||||
min: number
|
||||
max: number
|
||||
@@ -13,6 +14,7 @@ export interface ResizeHandleProps extends Omit<JSX.HTMLAttributes<HTMLDivElemen
|
||||
export function ResizeHandle(props: ResizeHandleProps) {
|
||||
const [local, rest] = splitProps(props, [
|
||||
"direction",
|
||||
"edge",
|
||||
"size",
|
||||
"min",
|
||||
"max",
|
||||
@@ -25,6 +27,7 @@ export function ResizeHandle(props: ResizeHandleProps) {
|
||||
|
||||
const handleMouseDown = (e: MouseEvent) => {
|
||||
e.preventDefault()
|
||||
const edge = local.edge ?? (local.direction === "vertical" ? "start" : "end")
|
||||
const start = local.direction === "horizontal" ? e.clientX : e.clientY
|
||||
const startSize = local.size
|
||||
let current = startSize
|
||||
@@ -34,7 +37,14 @@ export function ResizeHandle(props: ResizeHandleProps) {
|
||||
|
||||
const onMouseMove = (moveEvent: MouseEvent) => {
|
||||
const pos = local.direction === "horizontal" ? moveEvent.clientX : moveEvent.clientY
|
||||
const delta = local.direction === "vertical" ? start - pos : pos - start
|
||||
const delta =
|
||||
local.direction === "vertical"
|
||||
? edge === "end"
|
||||
? pos - start
|
||||
: start - pos
|
||||
: edge === "start"
|
||||
? start - pos
|
||||
: pos - start
|
||||
current = startSize + delta
|
||||
const clamped = Math.min(local.max, Math.max(local.min, current))
|
||||
local.onResize(clamped)
|
||||
@@ -61,6 +71,7 @@ export function ResizeHandle(props: ResizeHandleProps) {
|
||||
{...rest}
|
||||
data-component="resize-handle"
|
||||
data-direction={local.direction}
|
||||
data-edge={local.edge ?? (local.direction === "vertical" ? "start" : "end")}
|
||||
classList={{
|
||||
...(local.classList ?? {}),
|
||||
[local.class ?? ""]: !!local.class,
|
||||
|
||||
@@ -9,6 +9,7 @@ import { StickyAccordionHeader } from "./sticky-accordion-header"
|
||||
import { useDiffComponent } from "../context/diff"
|
||||
import { useI18n } from "../context/i18n"
|
||||
import { getDirectory, getFilename } from "@opencode-ai/util/path"
|
||||
import { checksum } from "@opencode-ai/util/encode"
|
||||
import { createEffect, createMemo, createSignal, For, Match, Show, Switch, type JSX } from "solid-js"
|
||||
import { createStore } from "solid-js/store"
|
||||
import { type FileContent, type FileDiff } from "@opencode-ai/sdk/v2"
|
||||
@@ -118,6 +119,12 @@ function dataUrlFromValue(value: unknown): string | undefined {
|
||||
return `data:${mime};base64,${content}`
|
||||
}
|
||||
|
||||
function diffId(file: string): string | undefined {
|
||||
const sum = checksum(file)
|
||||
if (!sum) return
|
||||
return `session-review-diff-${sum}`
|
||||
}
|
||||
|
||||
type SessionReviewSelection = {
|
||||
file: string
|
||||
range: SelectedLineRange
|
||||
@@ -489,7 +496,12 @@ export const SessionReview = (props: SessionReviewProps) => {
|
||||
}
|
||||
|
||||
return (
|
||||
<Accordion.Item value={diff.file} data-slot="session-review-accordion-item">
|
||||
<Accordion.Item
|
||||
value={diff.file}
|
||||
id={diffId(diff.file)}
|
||||
data-file={diff.file}
|
||||
data-slot="session-review-accordion-item"
|
||||
>
|
||||
<StickyAccordionHeader>
|
||||
<Accordion.Trigger>
|
||||
<div data-slot="session-review-trigger-content">
|
||||
|
||||
Reference in New Issue
Block a user