forked from code-hike/codehike
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinner.tsx
More file actions
62 lines (57 loc) · 1.7 KB
/
Copy pathinner.tsx
File metadata and controls
62 lines (57 loc) · 1.7 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
61
62
import { mergeProps } from "./merge-props.js"
import { CustomLineProps, CustomPreProps, CustomTokenProps } from "./types.js"
export const InnerPre = ({
merge,
...rest
}: { merge: CustomPreProps } & Partial<CustomPreProps>) => {
const { _stack, ...result } = mergeProps(merge, rest)
const [Next, ...stack] = _stack
if (Next) {
return <Next _stack={stack} {...result} />
} else {
const { _ref, data, children, ...props } = result
return (
<pre {...props} ref={_ref} data-ch={true}>
<div style={{ minWidth: "fit-content" }}>{children}</div>
</pre>
)
}
}
export function getPreRef(
props: CustomPreProps,
): React.RefObject<HTMLPreElement> {
const p = props
if (!p?._ref) {
throw new Error("`getPreRef` can only be used inside `PreWithRef`")
}
return p?._ref
}
export const InnerLine = ({
merge,
...rest
}: { merge: CustomLineProps } & Partial<CustomLineProps>) => {
const { _stack, ...result } = mergeProps(merge, rest)
const [next, ...stack] = _stack
if (next) {
const { Component, annotation } = next
return <Component _stack={stack} {...result} annotation={annotation!} />
} else {
const { lineNumber, totalLines, indentation, data, annotation, ...props } =
result
return <div {...props} />
}
}
export const InnerToken = ({
merge,
...rest
}: { merge: CustomTokenProps } & Partial<CustomTokenProps>) => {
const { _stack, ...result } = mergeProps(merge, rest)
const [next, ...stack] = _stack
if (next) {
const { Component, annotation } = next
return <Component _stack={stack} {...result} annotation={annotation!} />
} else {
const { value, data, ...props } = result
return <span {...props}>{value}</span>
}
}