Skip to content

Commit

Permalink
feat(template): svelte (#182)
Browse files Browse the repository at this point in the history
* fix: svelte syntax highlighting

* feat: add svelte template

* fix(svelte): update template

* fix(svelte): update story

Co-authored-by: Danilo Woznica <[email protected]>
  • Loading branch information
paolotiu and danilowoz authored Nov 25, 2021
1 parent c8b5cdf commit 2d0c85c
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions sandpack-react/src/components/CodeEditor/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export const getCodeMirrorLanguage = (
return javascript({ jsx: true, typescript: true });
case "vue":
case "html":
case "svelte":
return html();
case "css":
case "scss":
Expand Down
4 changes: 4 additions & 0 deletions sandpack-react/src/presets/Sandpack.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ export const Vue3Editor: Story<SandpackProps> = (args) => (
<Sandpack {...args} template="vue3" />
);

export const Svelte: Story<SandpackProps> = (args) => (
<Sandpack {...args} template="svelte" />
);

export const DarkTheme: Story<SandpackProps> = (args) => (
<Sandpack
{...args}
Expand Down
2 changes: 2 additions & 0 deletions sandpack-react/src/templates/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { SandpackPredefinedTemplate, SandboxTemplate } from "../types";
import { ANGULAR_TEMPLATE } from "./angular";
import { REACT_TEMPLATE } from "./react";
import { REACT_TYPESCRIPT_TEMPLATE } from "./react-typescript";
import { SVELTE_TEMPLATE } from "./svelte";
import { VANILLA_TEMPLATE } from "./vanilla";
import { VANILLA_TYPESCRIPT_TEMPLATE } from "./vanilla-typescript";
import { VUE_TEMPLATE } from "./vue";
Expand All @@ -19,4 +20,5 @@ export const SANDBOX_TEMPLATES: Record<
"vanilla-ts": VANILLA_TYPESCRIPT_TEMPLATE,
vue3: VUE_TEMPLATE_3,
angular: ANGULAR_TEMPLATE,
svelte: SVELTE_TEMPLATE,
};
56 changes: 56 additions & 0 deletions sandpack-react/src/templates/svelte.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import type { SandboxTemplate } from "../types";

export const SVELTE_TEMPLATE: SandboxTemplate = {
environment: "svelte",
main: "/index.js",
entry: "/index.js",

files: {
"/App.svelte": {
code: `<style>
main {
font-family: sans-serif;
text-align: center;
}
</style>
<script>
let name = 'world';
</script>
<main>
<h1>Hello {name}!</h1>
</main>`,
},
"/index.js": {
code: `import App from "./App.svelte";
const app = new App({
target: document.body
});
export default app;
`,
},
"/public/index.html": {
code: `<!DOCTYPE html>
<html>
<head>
<meta charset="utf8" />
<meta name="viewport" content="width=device-width" />
<title>Svelte app</title>
<link rel="stylesheet" href="public/bundle.css" />
</head>
<body>
<script src="bundle.js"></script>
</body>
</html>`,
},
},
dependencies: {
svelte: "^3.0.0",
},
};
3 changes: 2 additions & 1 deletion sandpack-react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ export type SandpackPredefinedTemplate =
| "vanilla"
| "vanilla-ts"
| "vue"
| "vue3";
| "vue3"
| "svelte";

export type SandpackPredefinedTheme =
| "light"
Expand Down

0 comments on commit 2d0c85c

Please sign in to comment.