@verbaly/svelte 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -58,7 +58,20 @@ export const t = tStore(verbaly);
58
58
  export const locale = localeStore(verbaly);
59
59
  ```
60
60
 
61
- Rich text: the core's DOM interpreter works in any Svelte app mark elements with `data-verbaly`/`data-verbaly-rich` and call `bindDom` (whitelist-based, XSS-safe).
61
+ ## `<Trans>` — rich text
62
+
63
+ Messages with tags (`'The <em>build</em> gate'`) render as real elements — same phrasing-tag whitelist as `data-verbaly-rich`, unknown tags unwrap to inert text, XSS-safe:
64
+
65
+ ```svelte
66
+ <script>
67
+ import Trans from '@verbaly/svelte/Trans.svelte';
68
+ </script>
69
+
70
+ <Trans id="home.title" />
71
+ <Trans id="greet" values={{ name: 'Aron' }} />
72
+ ```
73
+
74
+ Uses the instance from `provideVerbaly` (or pass `instance={verbaly}` explicitly; `richTags` overrides the whitelist). Alternatively the core's DOM interpreter works in any Svelte app — mark elements with `data-verbaly`/`data-verbaly-rich` and call `bindDom`.
62
75
 
63
76
  📖 Docs: **https://verbaly-web.vercel.app/docs/frameworks**
64
77
 
@@ -0,0 +1,22 @@
1
+ <script>
2
+ import { onDestroy } from 'svelte';
3
+ import { parseTags, RICH_TAGS } from 'verbaly';
4
+ import { useVerbaly } from '@verbaly/svelte';
5
+ import TransNodes from './TransNodes.svelte';
6
+
7
+ export let id;
8
+ export let values = undefined;
9
+ export let instance = undefined;
10
+ export let richTags = undefined;
11
+
12
+ const v = instance ?? useVerbaly();
13
+ let version = v.version;
14
+ const unsubscribe = v.subscribe(() => (version = v.version));
15
+ onDestroy(unsubscribe);
16
+
17
+ $: allowed = new Set(richTags ?? RICH_TAGS);
18
+ // version keeps this reactive to locale/catalog changes
19
+ $: nodes = (version, parseTags(v.t(id, values)));
20
+ </script>
21
+
22
+ <TransNodes {nodes} {allowed} />
@@ -0,0 +1,11 @@
1
+ import { SvelteComponent } from 'svelte';
2
+ import type { Params, Verbaly } from 'verbaly';
3
+
4
+ export interface TransProps {
5
+ id: string;
6
+ values?: Params;
7
+ instance?: Verbaly;
8
+ richTags?: string[];
9
+ }
10
+
11
+ export default class Trans extends SvelteComponent<TransProps> {}
@@ -0,0 +1,8 @@
1
+ <script>
2
+ import TransNodes from './TransNodes.svelte';
3
+
4
+ export let nodes = [];
5
+ export let allowed;
6
+ </script>
7
+
8
+ {#each nodes as node}{#if typeof node === 'string'}{node}{:else if allowed.has(node.name)}<svelte:element this={node.name}><TransNodes nodes={node.children} {allowed} /></svelte:element>{:else}<TransNodes nodes={node.children} {allowed} />{/if}{/each}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verbaly/svelte",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Svelte bindings for Verbaly — stores over the reactive core.",
5
5
  "keywords": [
6
6
  "i18n",
@@ -25,6 +25,11 @@
25
25
  ".": {
26
26
  "types": "./dist/index.d.ts",
27
27
  "import": "./dist/index.js"
28
+ },
29
+ "./Trans.svelte": {
30
+ "types": "./dist/Trans.svelte.d.ts",
31
+ "svelte": "./dist/Trans.svelte",
32
+ "default": "./dist/Trans.svelte"
28
33
  }
29
34
  },
30
35
  "files": [
@@ -40,14 +45,16 @@
40
45
  },
41
46
  "peerDependencies": {
42
47
  "svelte": "^4.0.0 || ^5.0.0",
43
- "verbaly": "^0.9.0"
48
+ "verbaly": "^0.10.0"
44
49
  },
45
50
  "devDependencies": {
51
+ "@sveltejs/vite-plugin-svelte": "^7.2.0",
52
+ "happy-dom": "^20.10.6",
46
53
  "svelte": "^5.56.4",
47
- "verbaly": "0.9.0"
54
+ "verbaly": "0.10.0"
48
55
  },
49
56
  "scripts": {
50
- "build": "tsup",
57
+ "build": "tsup && node scripts/copy-svelte.mjs",
51
58
  "dev": "tsup --watch",
52
59
  "test": "vitest run --passWithNoTests",
53
60
  "typecheck": "tsc --noEmit"