From ef441d5cffb279727d9dfa17693f0effe30c22f2 Mon Sep 17 00:00:00 2001 From: Adam <2363879+adamdotdevin@users.noreply.github.com> Date: Tue, 25 Nov 2025 19:59:37 -0600 Subject: chore: cleanup pierre stuff --- packages/ui/src/components/diff.tsx | 76 +++++++++---------------------------- 1 file changed, 17 insertions(+), 59 deletions(-) (limited to 'packages/ui/src/components/diff.tsx') diff --git a/packages/ui/src/components/diff.tsx b/packages/ui/src/components/diff.tsx index 344ce3c8e..c895a6e29 100644 --- a/packages/ui/src/components/diff.tsx +++ b/packages/ui/src/components/diff.tsx @@ -1,7 +1,8 @@ import { type FileContents, FileDiff, type DiffLineAnnotation, FileDiffOptions } from "@pierre/precision-diffs" import { PreloadMultiFileDiffResult } from "@pierre/precision-diffs/ssr" -import { ComponentProps, createEffect, onCleanup, onMount, splitProps } from "solid-js" +import { ComponentProps, createEffect, onCleanup, onMount, Show, splitProps } from "solid-js" import { isServer } from "solid-js/web" +import { createDefaultOptions, styleVariables } from "./pierre" export type DiffProps = FileDiffOptions & { preloadedDiff?: PreloadMultiFileDiffResult @@ -15,6 +16,8 @@ export type DiffProps = FileDiffOptions & { // interface ThreadMetadata { // threadId: string // } +// +// export function Diff(props: DiffProps) { let container!: HTMLDivElement @@ -24,27 +27,12 @@ export function Diff(props: DiffProps) { let fileDiffInstance: FileDiff | undefined const cleanupFunctions: Array<() => void> = [] - const defaultOptions: FileDiffOptions = { - theme: "OpenCode", - themeType: "system", - disableLineNumbers: false, - overflow: "wrap", - diffStyle: "unified", - diffIndicators: "bars", - disableBackground: false, - expansionLineCount: 20, - lineDiffType: props.diffStyle === "split" ? "word-alt" : "none", - maxLineDiffLength: 1000, - maxLineLengthForHighlighting: 1000, - disableFileHeader: true, - } - createEffect(() => { if (props.preloadedDiff) return container.innerHTML = "" if (!fileDiffInstance) { fileDiffInstance = new FileDiff({ - ...defaultOptions, + ...createDefaultOptions(props.diffStyle), ...others, ...(props.preloadedDiff ?? {}), }) @@ -60,22 +48,19 @@ export function Diff(props: DiffProps) { onMount(() => { if (isServer) return fileDiffInstance = new FileDiff({ - ...defaultOptions, - // You can optionally pass a render function for rendering out line - // annotations. Just return the dom node to render - // renderAnnotation(annotation: DiffLineAnnotation): HTMLElement { - // // Despite the diff itself being rendered in the shadow dom, - // // annotations are inserted via the web components 'slots' api and you - // // can use all your normal normal css and styling for them - // const element = document.createElement("div") - // element.innerText = annotation.metadata.threadId - // return element - // }, + ...createDefaultOptions(props.diffStyle), ...others, ...(props.preloadedDiff ?? {}), }) // @ts-expect-error - fileContainer is private but needed for SSR hydration fileDiffInstance.fileContainer = fileDiffRef + fileDiffInstance.hydrate({ + oldFile: local.before, + newFile: local.after, + lineAnnotations: local.annotations, + fileContainer: fileDiffRef, + containerWrapper: container, + }) // Hydrate annotation slots with interactive SolidJS components // if (props.annotations.length > 0 && props.renderAnnotation != null) { @@ -108,38 +93,11 @@ export function Diff(props: DiffProps) { }) return ( -
+
- {/* Only render on server - client hydrates the existing content */} - {isServer && props.preloadedDiff && ( - <> - {/* Declarative Shadow DOM - browsers parse this and create a shadow root */} - - {/* Render static annotation slots on server. - Client will clear these and mount interactive components. */} - {/* */} - {/* {(annotation) => { */} - {/* const slotName = `annotation-${annotation.side}-${annotation.lineNumber}` */} - {/* return
{props.renderAnnotation?.(annotation)}
*/} - {/* }} */} - {/*
*/} - - )} + + {(preloadedDiff) =>