forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.tsx
More file actions
60 lines (54 loc) · 1.64 KB
/
code.tsx
File metadata and controls
60 lines (54 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { type FileContents, File, FileOptions, LineAnnotation } from "@pierre/precision-diffs"
import { ComponentProps, createEffect, splitProps } from "solid-js"
import { createDefaultOptions, styleVariables } from "../pierre"
import { getOrCreateWorkerPoolSingleton } from "@pierre/precision-diffs/worker"
import { workerFactory } from "../pierre/worker"
const workerPool = getOrCreateWorkerPoolSingleton({
poolOptions: {
workerFactory,
// poolSize defaults to 8. More workers = more parallelism but
// also more memory. Too many can actually slow things down.
// poolSize: 8,
},
highlighterOptions: {
theme: "OpenCode",
// Optionally preload languages to avoid lazy-loading delays
// langs: ["typescript", "javascript", "css", "html"],
},
})
export type CodeProps<T = {}> = FileOptions<T> & {
file: FileContents
annotations?: LineAnnotation<T>[]
class?: string
classList?: ComponentProps<"div">["classList"]
}
export function Code<T>(props: CodeProps<T>) {
let container!: HTMLDivElement
const [local, others] = splitProps(props, ["file", "class", "classList", "annotations"])
createEffect(() => {
const instance = new File<T>(
{
...createDefaultOptions<T>("unified"),
...others,
},
workerPool,
)
container.innerHTML = ""
instance.render({
file: local.file,
lineAnnotations: local.annotations,
containerWrapper: container,
})
})
return (
<div
data-component="code"
style={styleVariables}
classList={{
...(local.classList || {}),
[local.class ?? ""]: !!local.class,
}}
ref={container}
/>
)
}