From 995f551e8013ff4a267d8d551870cc87f5aaf84d Mon Sep 17 00:00:00 2001 From: Adam <2363879+adamdotdevin@users.noreply.github.com> Date: Tue, 25 Nov 2025 07:47:25 -0600 Subject: [PATCH] fix(enterprise): custom element defs --- packages/enterprise/src/custom-elements.d.ts | 1 + packages/ui/src/components/diff.tsx | 57 +++++++------------- 2 files changed, 19 insertions(+), 39 deletions(-) create mode 120000 packages/enterprise/src/custom-elements.d.ts diff --git a/packages/enterprise/src/custom-elements.d.ts b/packages/enterprise/src/custom-elements.d.ts new file mode 120000 index 000000000..e4ea0d6ce --- /dev/null +++ b/packages/enterprise/src/custom-elements.d.ts @@ -0,0 +1 @@ +../../ui/src/custom-elements.d.ts \ No newline at end of file diff --git a/packages/ui/src/components/diff.tsx b/packages/ui/src/components/diff.tsx index af89b5c1e..e9747f25d 100644 --- a/packages/ui/src/components/diff.tsx +++ b/packages/ui/src/components/diff.tsx @@ -24,41 +24,32 @@ 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: "word-alt", + maxLineDiffLength: 1000, + maxLineLengthForHighlighting: 1000, + disableFileHeader: true, + } + createEffect(() => { - // Create FileDiff instance and connect to existing server-rendered DOM. - // Don't call hydrate() - that would re-render content and cause duplication. - // Instead, just set the fileContainer reference to attach event handlers. if (props.preloadedDiff) return container.innerHTML = "" if (!fileDiffInstance) { fileDiffInstance = new FileDiff({ - theme: "OpenCode", - themeType: "system", - disableLineNumbers: false, - overflow: "wrap", - diffStyle: "unified", - diffIndicators: "bars", - disableBackground: false, - expansionLineCount: 20, - lineDiffType: "word-alt", - maxLineDiffLength: 1000, - maxLineLengthForHighlighting: 1000, - disableFileHeader: true, - // 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 - // }, + ...defaultOptions, ...others, ...(props.preloadedDiff ?? {}), }) } - fileDiffInstance?.render({ + fileDiffInstance.render({ oldFile: local.before, newFile: local.after, lineAnnotations: local.annotations, @@ -68,20 +59,8 @@ export function Diff(props: DiffProps) { onMount(() => { if (isServer) return - fileDiffInstance = new FileDiff({ - theme: "OpenCode", - themeType: "system", - disableLineNumbers: false, - overflow: "wrap", - diffStyle: "unified", - diffIndicators: "bars", - disableBackground: false, - expansionLineCount: 20, - lineDiffType: "word-alt", - maxLineDiffLength: 1000, - maxLineLengthForHighlighting: 1000, - disableFileHeader: true, + ...defaultOptions, // You can optionally pass a render function for rendering out line // annotations. Just return the dom node to render // renderAnnotation(annotation: DiffLineAnnotation): HTMLElement {