-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Corbin Crutchley <[email protected]> Co-authored-by: Anthony Fu <[email protected]>
- Loading branch information
1 parent
fd3bd4b
commit 76b464d
Showing
15 changed files
with
1,459 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** @jsxImportSource solid-js */ | ||
|
||
import type { RendererFactory, RendererFactoryResult } from './types' | ||
import { createEffect, createSignal } from 'solid-js' | ||
import { render } from 'solid-js/web' | ||
import { shallowReactive, watch } from 'vue' | ||
import { ShikiMagicMove } from '../../../src/solid' | ||
|
||
export const createRendererSolid: RendererFactory = (options): RendererFactoryResult => { | ||
const props = shallowReactive<any>({ | ||
onStart: options.onStart, | ||
onEnd: options.onEnd, | ||
}) | ||
|
||
function App() { | ||
const [code, setCode] = createSignal(props.code as string) | ||
const [highlighter, setHighlighter] = createSignal(props.highlighter) | ||
const [lang, setLang] = createSignal(props.lang) | ||
const [theme, setTheme] = createSignal(props.theme) | ||
const [className, setClassName] = createSignal(props.class) | ||
|
||
createEffect(() => { | ||
watch(props, () => { | ||
// Force Solid to re-render | ||
setCode(props.code) | ||
setHighlighter(props.highlighter) | ||
setLang(props.lang) | ||
setTheme(props.theme) | ||
setClassName(props.class) | ||
}) | ||
}) | ||
|
||
return ( | ||
<> | ||
<ShikiMagicMove | ||
highlighter={highlighter()} | ||
code={code()} | ||
class={className()} | ||
lang={lang()} | ||
theme={theme()} | ||
options={props.options} | ||
/> | ||
</> | ||
) | ||
} | ||
|
||
let dispose = () => {} | ||
|
||
return { | ||
mount: (element, payload) => { | ||
Object.assign(props, payload) | ||
dispose = render( | ||
() => <App />, | ||
element, | ||
) | ||
}, | ||
|
||
update: (payload) => { | ||
Object.assign(props, payload) | ||
}, | ||
dispose: () => { | ||
dispose?.() | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"jsx": "preserve", | ||
"lib": ["ESNext", "DOM"], | ||
"module": "ESNext", | ||
"moduleResolution": "Bundler", | ||
"resolveJsonModule": true, | ||
"strict": true, | ||
"strictNullChecks": true, | ||
"esModuleInterop": true, | ||
"skipDefaultLibCheck": true, | ||
"skipLibCheck": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.