2025-12-15 16:56:03 +00:00
|
|
|
import { FileDiff } from "@pierre/diffs"
|
2025-12-08 12:24:19 +00:00
|
|
|
import { createEffect, createMemo, onCleanup, splitProps } from "solid-js"
|
2025-12-02 12:50:16 +00:00
|
|
|
import { createDefaultOptions, type DiffProps, styleVariables } from "../pierre"
|
2025-12-31 15:23:24 +00:00
|
|
|
import { getWorkerPool } from "../pierre/worker"
|
2025-10-24 13:26:17 +00:00
|
|
|
|
2025-10-24 16:23:32 +00:00
|
|
|
// interface ThreadMetadata {
|
|
|
|
|
// threadId: string
|
|
|
|
|
// }
|
2025-11-26 01:59:37 +00:00
|
|
|
//
|
|
|
|
|
//
|
2025-10-24 13:26:17 +00:00
|
|
|
|
2025-10-24 16:23:32 +00:00
|
|
|
export function Diff<T>(props: DiffProps<T>) {
|
|
|
|
|
let container!: HTMLDivElement
|
2025-11-08 01:59:02 +00:00
|
|
|
const [local, others] = splitProps(props, ["before", "after", "class", "classList", "annotations"])
|
2025-10-24 13:26:17 +00:00
|
|
|
|
2025-12-08 12:24:19 +00:00
|
|
|
const fileDiff = createMemo(
|
|
|
|
|
() =>
|
|
|
|
|
new FileDiff<T>(
|
2025-12-02 12:50:16 +00:00
|
|
|
{
|
|
|
|
|
...createDefaultOptions(props.diffStyle),
|
|
|
|
|
...others,
|
|
|
|
|
},
|
2025-12-31 15:23:24 +00:00
|
|
|
getWorkerPool(props.diffStyle),
|
2025-12-08 12:24:19 +00:00
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
createEffect(() => {
|
2025-12-31 15:23:24 +00:00
|
|
|
const diff = fileDiff()
|
2025-12-08 12:24:19 +00:00
|
|
|
container.innerHTML = ""
|
2025-12-31 15:23:24 +00:00
|
|
|
diff.render({
|
2025-11-25 13:40:11 +00:00
|
|
|
oldFile: local.before,
|
|
|
|
|
newFile: local.after,
|
|
|
|
|
lineAnnotations: local.annotations,
|
|
|
|
|
containerWrapper: container,
|
|
|
|
|
})
|
|
|
|
|
|
2025-12-31 15:23:24 +00:00
|
|
|
onCleanup(() => {
|
|
|
|
|
diff.cleanUp()
|
|
|
|
|
})
|
2025-10-24 13:26:17 +00:00
|
|
|
})
|
|
|
|
|
|
2025-12-02 12:50:16 +00:00
|
|
|
return <div data-component="diff" style={styleVariables} ref={container} />
|
2025-10-24 13:26:17 +00:00
|
|
|
}
|