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