-
Notifications
You must be signed in to change notification settings - Fork 200
feat(examples): add SvelteKit getting-started starter #3858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MeritonPylla
wants to merge
1
commit into
superdoc:main
Choose a base branch
from
MeritonPylla:feat/sveltekit-getting-started-example
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,17 @@ | ||
| node_modules | ||
|
|
||
| # SvelteKit | ||
| /.svelte-kit | ||
| /build | ||
| /dist | ||
|
|
||
| # Logs | ||
| *.log | ||
|
|
||
| # Env | ||
| .env | ||
| .env.* | ||
| !.env.example | ||
|
|
||
| # Misc | ||
| .DS_Store |
This file contains hidden or 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,32 @@ | ||
| # SuperDoc — SvelteKit | ||
|
|
||
| Minimal SvelteKit + TypeScript example. | ||
|
|
||
| ## Run | ||
|
|
||
| ```bash | ||
| npm install | ||
| npm run dev | ||
| ``` | ||
|
|
||
| Then open the dev server URL and pick a `.docx` file. | ||
|
|
||
| ## SSR | ||
|
|
||
| SuperDoc is browser-only: instantiating it during SSR throws | ||
| `ReferenceError: document is not defined`. Rather than turn SSR off for the | ||
| whole app, this example scopes it to the one route that mounts the editor: | ||
|
|
||
| ```ts | ||
| // src/routes/+page.ts | ||
| export const ssr = false; | ||
| ``` | ||
|
|
||
| The rest of a real SvelteKit app keeps server-side rendering. The editor is | ||
| created inside a `$effect` (client-only) once a file is chosen, and destroyed | ||
| in the effect's cleanup. | ||
|
|
||
| ## Learn more | ||
|
|
||
| - [SvelteKit page options](https://svelte.dev/docs/kit/page-options#ssr) | ||
| - [Configuration Reference](https://docs.superdoc.dev/editor/superdoc/configuration) |
This file contains hidden or 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,25 @@ | ||
| { | ||
| "name": "superdoc-sveltekit-example", | ||
| "type": "module", | ||
| "private": true, | ||
| "scripts": { | ||
| "dev": "vite dev", | ||
| "build": "vite build", | ||
| "preview": "vite preview", | ||
| "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", | ||
| "prepare": "svelte-kit sync || echo ''" | ||
| }, | ||
| "dependencies": { | ||
| "@superdoc-dev/fonts": "workspace:*", | ||
|
MeritonPylla marked this conversation as resolved.
|
||
| "superdoc": "latest" | ||
|
MeritonPylla marked this conversation as resolved.
|
||
| }, | ||
| "devDependencies": { | ||
| "@sveltejs/adapter-auto": "^3.3.1", | ||
| "@sveltejs/kit": "^2.22.0", | ||
| "@sveltejs/vite-plugin-svelte": "^5.0.3", | ||
| "svelte": "^5.25.0", | ||
| "svelte-check": "^4.1.0", | ||
| "typescript": "^5.7.0", | ||
| "vite": "^6.3.0" | ||
| } | ||
| } | ||
This file contains hidden or 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,5 @@ | ||
| declare global { | ||
| namespace App {} | ||
| } | ||
|
|
||
| export {}; |
This file contains hidden or 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,11 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
| %sveltekit.head% | ||
| </head> | ||
| <body data-sveltekit-preload-data="hover"> | ||
| <div style="display: contents">%sveltekit.body%</div> | ||
| </body> | ||
| </html> |
40 changes: 40 additions & 0 deletions
40
examples/getting-started/sveltekit/src/routes/+page.svelte
This file contains hidden or 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,40 @@ | ||
| <script lang="ts"> | ||
| import { SuperDoc } from 'superdoc'; | ||
| import { superdocFonts } from '@superdoc-dev/fonts'; | ||
| import 'superdoc/style.css'; | ||
|
|
||
| let editor = $state<HTMLDivElement | null>(null); | ||
| let file = $state<File | null>(null); | ||
| let superdoc: SuperDoc | null = null; | ||
|
|
||
| function handleFile(event: Event) { | ||
| const input = event.target as HTMLInputElement; | ||
| file = input.files?.[0] ?? null; | ||
| } | ||
|
|
||
| $effect(() => { | ||
| if (!editor || !file) return; | ||
| superdoc = new SuperDoc({ | ||
| selector: editor, | ||
| document: file, | ||
| fonts: superdocFonts, | ||
| }); | ||
| return () => superdoc?.destroy(); | ||
| }); | ||
| </script> | ||
|
|
||
| <div class="toolbar"> | ||
| <input type="file" accept=".docx" onchange={handleFile} /> | ||
| </div> | ||
| <div class="editor" bind:this={editor}></div> | ||
|
|
||
| <style> | ||
| .toolbar { | ||
| padding: 1rem; | ||
| background: #f5f5f5; | ||
| } | ||
|
|
||
| .editor { | ||
| height: calc(100vh - 60px); | ||
| } | ||
| </style> |
This file contains hidden or 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,3 @@ | ||
| // SuperDoc renders in the browser only. Scope SSR off to THIS route so the | ||
| // rest of a SvelteKit app keeps server-side rendering. | ||
| export const ssr = false; |
This file contains hidden or 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 @@ | ||
| import adapter from '@sveltejs/adapter-auto'; | ||
| import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; | ||
|
|
||
| /** @type {import('@sveltejs/kit').Config} */ | ||
| const config = { | ||
| preprocess: vitePreprocess(), | ||
| kit: { | ||
| adapter: adapter(), | ||
| }, | ||
| }; | ||
|
|
||
| export default config; |
This file contains hidden or 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,14 @@ | ||
| { | ||
| "extends": "./.svelte-kit/tsconfig.json", | ||
| "compilerOptions": { | ||
| "allowJs": true, | ||
| "checkJs": true, | ||
| "esModuleInterop": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "resolveJsonModule": true, | ||
| "skipLibCheck": true, | ||
| "sourceMap": true, | ||
| "strict": true, | ||
| "moduleResolution": "bundler" | ||
| } | ||
| } |
This file contains hidden or 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,6 @@ | ||
| import { sveltekit } from '@sveltejs/kit/vite'; | ||
| import { defineConfig } from 'vite'; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [sveltekit()], | ||
| }); |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| "nuxt", | ||
| "react", | ||
| "solid", | ||
| "sveltekit", | ||
| "template-builder", | ||
| "theming", | ||
| "toolbar", | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.