-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
2,502 additions
and
308 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ jobs: | |
version: '0.4.27' | ||
- name: Package Test | ||
run: pnpm run package | ||
- name: Build playground | ||
run: pnpm run pg-build | ||
|
||
- name: Upload APKGs | ||
uses: actions/[email protected] | ||
|
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
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,12 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>ikkz Template Playground</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
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 @@ | ||
../../dist |
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 @@ | ||
../../release |
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,18 @@ | ||
import { GithubOutlined } from '@ant-design/icons'; | ||
import { Button } from 'antd'; | ||
import { FC } from 'react'; | ||
|
||
export const Header: FC = () => { | ||
return ( | ||
<h1 className="font-bold text-2xl mb-6"> | ||
ikkz Template | ||
<Button | ||
icon={<GithubOutlined />} | ||
type="text" | ||
target="_blank" | ||
className="text-xl ml-2" | ||
href="https://github.com/ikkz/anki-template" | ||
/> | ||
</h1> | ||
); | ||
}; |
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,78 @@ | ||
import { | ||
BuildJson, | ||
BUILTIN_FIELDS, | ||
} from '../../../build/plugins/generate-template'; | ||
import { renderTemplate } from '../../../build/utils'; | ||
import hostPage from '../../../e2e/index.html?raw'; | ||
import { useRequest } from 'ahooks'; | ||
import { Spin } from 'antd'; | ||
import { FC, useEffect, useRef } from 'react'; | ||
|
||
declare global { | ||
interface Window { | ||
e2eAnki: { | ||
clean(): void; | ||
flipToBack(): void; | ||
render(html: string): void; | ||
}; | ||
} | ||
} | ||
|
||
export const Previewer: FC<{ template: string }> = ({ template }) => { | ||
const { data, loading } = useRequest( | ||
() => | ||
Promise.all([ | ||
fetch(`/builds/${template}/front.html`).then((res) => res.text()), | ||
fetch(`/builds/${template}/back.html`).then((res) => res.text()), | ||
fetch(`/builds/${template}/build.json`).then( | ||
(res) => res.json() as Promise<BuildJson>, | ||
), | ||
]), | ||
{ | ||
refreshDeps: [template], | ||
}, | ||
); | ||
|
||
const iframe = useRef<HTMLIFrameElement>(null); | ||
|
||
useEffect(() => { | ||
const wind = iframe.current?.contentWindow; | ||
if (!data || !wind) { | ||
return; | ||
} | ||
setTimeout(() => { | ||
const [front, back, build] = data; | ||
const extraFields = {}; | ||
const fields = Object.assign( | ||
{}, | ||
Object.fromEntries( | ||
[...build.fields, ...BUILTIN_FIELDS].map((k) => [k, '']), | ||
), | ||
build.notes[0].fields, | ||
extraFields, | ||
); | ||
const frontHtml = renderTemplate(front, fields); | ||
const backHtml = renderTemplate(back, { | ||
...fields, | ||
FrontSide: frontHtml, | ||
}); | ||
wind.e2eAnki.render(frontHtml); | ||
wind.e2eAnki.flipToBack = () => { | ||
wind.e2eAnki.render(backHtml); | ||
}; | ||
}, 500); | ||
}, [data]); | ||
|
||
if (loading) { | ||
return <Spin className="h-full flex items-center justify-center" />; | ||
} | ||
|
||
return ( | ||
<iframe | ||
key={template} | ||
srcDoc={hostPage} | ||
className="border-none h-screen md:h-full w-full" | ||
ref={iframe} | ||
/> | ||
); | ||
}; |
Oops, something went wrong.