Skip to content

Commit 76c7514

Browse files
committed
It works except I can't bind a class properly to the editor
1 parent 4d19fba commit 76c7514

File tree

9 files changed

+4010
-5937
lines changed

9 files changed

+4010
-5937
lines changed

package-lock.json

Lines changed: 3950 additions & 5892 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,32 @@
1111
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch"
1212
},
1313
"devDependencies": {
14-
"@sveltejs/adapter-netlify": "next",
15-
"@sveltejs/kit": "next",
16-
"@testing-library/svelte": "^3.2.2",
17-
"@types/cookie": "^0.5.1",
18-
"autoprefixer": "^10.4.13",
19-
"chai-dom": "^1.11.0",
20-
"cssnano": "^5.1.0",
21-
"jsdom": "^20.0.2",
22-
"postcss": "^8.4.19",
23-
"postcss-load-config": "^4.0.0",
24-
"svelte": "^3.55.0",
25-
"svelte-check": "^2.9.2",
26-
"svelte-preprocess": "^5.0.0",
27-
"tailwindcss": "^3.2.4",
28-
"tslib": "^2.5.0",
29-
"typescript": "^4.9.5",
30-
"vite": "^4.1.1",
31-
"vitest": "^0.28.0"
14+
"@sveltejs/adapter-netlify": "^4.0.0",
15+
"@sveltejs/kit": "^2.6.0",
16+
"@testing-library/svelte": "^5.2.4",
17+
"autoprefixer": "^10.4.20",
18+
"chai-dom": "^1.12.0",
19+
"cssnano": "^7.0.0",
20+
"jsdom": "^25.0.0",
21+
"postcss": "^8.4.47",
22+
"postcss-load-config": "^6.0.0",
23+
"svelte": "^5.0.0",
24+
"svelte-check": "^4.0.0",
25+
"svelte-preprocess": "^6.0.0",
26+
"tailwindcss": "^3.4.0",
27+
"tslib": "^2.8.0",
28+
"typescript": "^5.6.0",
29+
"vite": "^5.4.0",
30+
"vitest": "^2.1.0"
3231
},
3332
"type": "module",
3433
"dependencies": {
35-
"cookie": "^0.5.0",
36-
"svelte-intl-precompile": "^0.12.1",
37-
"terser": "^5.16.0"
34+
"cookie": "^1.0.1",
35+
"svelte-intl-precompile": "^0.12.3",
36+
"terser": "^5.36.0"
3837
},
3938
"volta": {
40-
"node": "16.14.0",
41-
"npm": "8.1.2"
39+
"node": "22.11.0",
40+
"npm": "10.9.0"
4241
}
4342
}

src/lib/Codeblock.svelte

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
<script>
2-
export let lang;
3-
export let editable = false;
2+
/**
3+
* @typedef {Object} Props
4+
* @property {string} lang
5+
* @property {boolean} [editable]
6+
* @property {import('svelte').Snippet} [children]
7+
*/
8+
9+
/** @type {Props} */
10+
let { lang = "", editable = false, children } = $props();
11+
412
function highlight(node) {
513
// @ts-ignore
614
window.Prism.highlightElement(node);
715
}
816
function autofocus(node) {
917
if (editable) node.focus();
1018
}
11-
1219
</script>
1320
<pre
1421
contenteditable={editable}
1522
use:autofocus
16-
on:change
23+
{onchange}
1724
class="p-4 m-12 rounded bg-code overflow-x-auto">
18-
<code use:highlight class="language-{lang}"><div><slot/></div></code>
25+
<code use:highlight>
26+
<div>{@render children?.()}</div>
27+
</code>
1928
</pre>

src/lib/Playground.svelte

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<script lang="ts">
2-
let translations = JSON.stringify({
2+
let translations = $state(JSON.stringify({
33
"header": "Svelte Intl Precompile is {adjective}",
44
"posted-on": "Posted on {postDate, date, long}",
55
"invite-friend": "{name} has joined Svelte! Give {gender, select, male {him} female {her} other {your friend}} a warm welcome!",
66
"friends-msg": "You have {count, plural, zero {no friend} one {just # friend} other {# friends}}",
77
"show-friend-profile": "Click to show {gender, select, male {his profile} female {her profile} other {the profile}}"
8-
}, null, 2);
9-
let transformedTranslations = "";
10-
let minifiedTranslations = "";
11-
let showMinified = false;
12-
$: output = showMinified ? minifiedTranslations : transformedTranslations;
8+
}, null, 2));
9+
let transformedTranslations = $state("");
10+
let minifiedTranslations = $state("");
11+
let showMinified = $state(false);
12+
let output = $derived(showMinified ? minifiedTranslations : transformedTranslations);
1313
let timer;
14+
1415
function transform(code) {
1516
fetch('/playground', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: code })
1617
.then(r => {
@@ -32,16 +33,17 @@
3233
timer = setTimeout(() => transform(code), 750);
3334
}
3435
35-
$: transformedTranslations === "" ? transform(translations) : debouncedTransform(translations)
36-
$: sizeChange = Math.round(output.length / translations.length * 100, 0) - 100;
36+
$effect(() => {
37+
transformedTranslations === "" ? transform(translations) : debouncedTransform(translations)
38+
})
39+
let sizeChange = $derived(Math.round(output.length / translations.length * 100) - 100);
3740
</script>
3841
<div>
3942
<label for="email" class="text-sm block mb-2">Translations</label>
4043
<pre
4144
contenteditable
42-
bind:textContent={translations}
45+
bind:innerText={translations}
4346
class="p-4 m-2 rounded bg-code overflow-x-auto text-sm border ">
44-
<code><div>{translations}</div></code>
4547
</pre>
4648
{translations.length} bytes
4749
</div>
@@ -59,5 +61,6 @@
5961
<pre class="p-4 mt-2 rounded bg-code overflow-x-auto text-sm">
6062
<code><div>{output}</div></code>
6163
</pre>
62-
{output.length} bytes ({Math.abs(sizeChange)}% {sizeChange > 0 ? 'bigger' : 'smaller' } than the source translations)
64+
{output.length} bytes ({Math.abs(sizeChange)}% {sizeChange > 0 ? 'bigger' : 'smaller' } than the source translations)
6365
</div>
66+

src/routes/+layout.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<script lang="ts">
22
import "../app.css";
3+
interface Props {
4+
children?: import('svelte').Snippet;
5+
}
6+
7+
let { children }: Props = $props();
38
</script>
4-
<slot />
9+
{@render children?.()}

src/routes/[...lang]/docs/getting-started/+page.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script lang="ts">
22
import { t } from 'svelte-intl-precompile';
33
import Codeblock from '$lib/Codeblock.svelte';
4-
import CodeInline from '$lib/CodeInline.svelte';
54
import scrollToHash from '$lib/scroll-to-hash';;
65
scrollToHash();
76
</script>
@@ -16,7 +15,7 @@
1615

1716
<p>{$t('getting-started.paragraph.installation-1')}</p>
1817

19-
<Codeblock>npm install svelte-intl-precompile</Codeblock>
18+
<Codeblock lang="sh">npm install svelte-intl-precompile</Codeblock>
2019

2120
<h2 class="text-2xl font-semibold">{$t('getting-started.subsection.create-translations')}</h2>
2221
<p>

src/routes/[...lang]/docs/introduction/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import Playground from "$lib/Playground.svelte";
3-
import { t } from "precompile-intl-runtime";
3+
import { t } from "svelte-intl-precompile";
44
</script>
55

66
<svelte:head>

src/routes/[...lang]/docs/playground/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { t } from "precompile-intl-runtime";
2+
import { t } from "svelte-intl-precompile";
33
import Playground from "$lib/Playground.svelte";
44
</script>
55

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript
1010
to enforce using \`import type\` instead of \`import\` for Types.
1111
*/
12-
"importsNotUsedAsValues": "error",
1312
"isolatedModules": true,
1413
"resolveJsonModule": true,
14+
"verbatimModuleSyntax": true,
1515
/**
1616
To have warnings/errors of the Svelte compiler at the correct position,
1717
enable source maps by default.

0 commit comments

Comments
 (0)