Просмотр исходного кода

fix(enterprise): custom element defs

Adam 2 месяцев назад
Родитель
Сommit
995f551e80
2 измененных файлов с 19 добавлено и 39 удалено
  1. 1 0
      packages/enterprise/src/custom-elements.d.ts
  2. 18 39
      packages/ui/src/components/diff.tsx

+ 1 - 0
packages/enterprise/src/custom-elements.d.ts

@@ -0,0 +1 @@
+../../ui/src/custom-elements.d.ts

+ 18 - 39
packages/ui/src/components/diff.tsx

@@ -24,41 +24,32 @@ export function Diff<T>(props: DiffProps<T>) {
   let fileDiffInstance: FileDiff<T> | undefined
   let fileDiffInstance: FileDiff<T> | undefined
   const cleanupFunctions: Array<() => void> = []
   const cleanupFunctions: Array<() => void> = []
 
 
+  const defaultOptions: FileDiffOptions<T> = {
+    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(() => {
   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
     if (props.preloadedDiff) return
     container.innerHTML = ""
     container.innerHTML = ""
     if (!fileDiffInstance) {
     if (!fileDiffInstance) {
       fileDiffInstance = new FileDiff<T>({
       fileDiffInstance = new FileDiff<T>({
-        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<T>): 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,
         ...others,
         ...(props.preloadedDiff ?? {}),
         ...(props.preloadedDiff ?? {}),
       })
       })
     }
     }
-    fileDiffInstance?.render({
+    fileDiffInstance.render({
       oldFile: local.before,
       oldFile: local.before,
       newFile: local.after,
       newFile: local.after,
       lineAnnotations: local.annotations,
       lineAnnotations: local.annotations,
@@ -68,20 +59,8 @@ export function Diff<T>(props: DiffProps<T>) {
 
 
   onMount(() => {
   onMount(() => {
     if (isServer) return
     if (isServer) return
-
     fileDiffInstance = new FileDiff<T>({
     fileDiffInstance = new FileDiff<T>({
-      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
       // You can optionally pass a render function for rendering out line
       // annotations.  Just return the dom node to render
       // annotations.  Just return the dom node to render
       // renderAnnotation(annotation: DiffLineAnnotation<T>): HTMLElement {
       // renderAnnotation(annotation: DiffLineAnnotation<T>): HTMLElement {