@verbaly/react 0.68.0 → 0.69.1

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
@@ -35,6 +35,8 @@ function Inbox() {
35
35
  }
36
36
  ```
37
37
 
38
+ **Keys are typed.** `useT()` checks every key and its params against your source catalog, through the types Verbaly generates (`src/verbaly.d.ts` in a Vite app): a key no catalog has does not compile. A key that comes from data, like `t(item.key)`, passes as it is; declare it with `defineKeys` from `virtual:verbaly` when you want `check` to verify it exists.
39
+
38
40
  `useT()` hands out a new `t` whenever the language changes or a catalog arrives, so a `useMemo`, `useCallback` or effect keyed on `t` runs again in the new language. While nothing changes it stays the same function.
39
41
 
40
42
  ### ✨ Rich text: `<Trans>`
@@ -50,7 +52,7 @@ import { Trans } from '@verbaly/react';
50
52
  <Trans id="x7Ka9q2f" components={{ "a": <a href="/terms" /> }} />
51
53
  ```
52
54
 
53
- Runtime-first still works: pass `id` (+ `values`/`components`) yourself and nothing is touched. Whitelisted phrasing tags in a message (`<em>`, `<code>`…) render as real elements, same whitelist as `data-verbaly-rich` (`richTags` overrides it); unknown tags unwrap to inert text. JSX whitespace rules apply: a line break between an element and text renders no space (use `{' '}`).
55
+ Both forms type-check: children in your source, `id` at runtime. A `<Trans>` the compiler never saw (no plugin, or a file outside `include`) renders its children as written, like an uncompiled `` t`…` ``. Runtime-first still works: pass `id` (+ `values`/`components`) yourself and nothing is touched. Whitelisted phrasing tags in a message (`<em>`, `<code>`…) render as real elements, same whitelist as `data-verbaly-rich` (`richTags` overrides it); unknown tags unwrap to inert text. JSX whitespace rules apply: a line break between an element and text renders no space (use `{' '}`).
54
56
 
55
57
  Named links without custom components; hrefs come from your code, never from messages (`javascript:` blocked):
56
58
 
@@ -59,6 +61,18 @@ Named links without custom components; hrefs come from your code, never from mes
59
61
  <Trans id="cta" links={{ docs: { href: '/docs', target: '_blank', rel: 'noopener' } }} />
60
62
  ```
61
63
 
64
+ ### React Server Components: `@verbaly/react/server`
65
+
66
+ A Server Component has no provider to read and no hooks to call, so this entry renders `<Trans>` from an instance you pass, with the same contract as the client one:
67
+
68
+ ```tsx
69
+ import { Trans } from '@verbaly/react/server';
70
+
71
+ <Trans id="agree" instance={verbaly} components={{ terms: <a href="/terms" /> }} />;
72
+ ```
73
+
74
+ In Next.js, `@verbaly/next/server` exports a `<Trans>` that finds the request's instance itself.
75
+
62
76
  📖 Docs: **https://verbaly-web.vercel.app/docs/frameworks/react**
63
77
 
64
78
  > ⚠️ Early development (`0.x`): API not stable yet.
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_render = require("./render-CY-uLpA6.cjs");
2
3
  let react = require("react");
3
- let verbaly = require("verbaly");
4
4
  //#region src/index.ts
5
5
  const VerbalyContext = (0, react.createContext)(null);
6
6
  function VerbalyProvider(props) {
@@ -35,30 +35,7 @@ function Trans(props) {
35
35
  const instance = props.instance ?? ctx;
36
36
  if (!instance) throw new Error("[verbaly] <Trans> requires an instance prop or a <VerbalyProvider>");
37
37
  useVersion(instance);
38
- const text = instance.t(props.id, props.values);
39
- return (0, react.createElement)(react.Fragment, null, ...toNodes((0, verbaly.parseTags)(text), props.components ?? {}, props.links ?? {}, new Set(props.richTags ?? verbaly.RICH_TAGS)));
40
- }
41
- const VOID = new Set(verbaly.VOID_TAGS);
42
- function own(map, name) {
43
- return Object.prototype.hasOwnProperty.call(map, name) ? map[name] : void 0;
44
- }
45
- function toNodes(nodes, components, links, richTags) {
46
- return nodes.map((node, i) => {
47
- if (typeof node === "string") return node;
48
- const children = toNodes(node.children, components, links, richTags);
49
- const el = own(components, node.name);
50
- if (el) return (0, react.cloneElement)(el, { key: i }, ...children);
51
- const link = own(links, node.name);
52
- if (link !== void 0) return (0, react.createElement)("a", {
53
- key: i,
54
- ...(0, verbaly.normalizeLink)(link)
55
- }, ...children);
56
- if (richTags.has(node.name)) {
57
- if (VOID.has(node.name)) return (0, react.createElement)(node.name, { key: i });
58
- return (0, react.createElement)(node.name, { key: i }, ...children);
59
- }
60
- return (0, react.createElement)(react.Fragment, { key: i }, ...children);
61
- });
38
+ return require_render.renderTrans(instance, props);
62
39
  }
63
40
  //#endregion
64
41
  exports.Trans = Trans;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["createContext","createElement","useContext","useMemo","useSyncExternalStore","Fragment","parseTags","RICH_TAGS","VOID_TAGS","cloneElement","normalizeLink"],"sources":["../src/index.ts"],"sourcesContent":["import {\n cloneElement,\n createContext,\n createElement,\n Fragment,\n useContext,\n useMemo,\n useSyncExternalStore,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport {\n normalizeLink,\n parseTags,\n RICH_TAGS,\n VOID_TAGS,\n type DictionaryInput,\n type Params,\n type RichLink,\n type TagNode,\n type TFunction,\n type Verbaly,\n} from 'verbaly';\n\nconst VerbalyContext = createContext<Verbaly | null>(null);\n\nexport interface VerbalyProviderProps<D extends DictionaryInput> {\n instance: Verbaly<D>;\n children?: ReactNode;\n}\n\nexport function VerbalyProvider<D extends DictionaryInput>(\n props: VerbalyProviderProps<D>,\n): ReactElement {\n return createElement(\n VerbalyContext.Provider,\n { value: props.instance as unknown as Verbaly },\n props.children,\n );\n}\n\nexport function useVerbaly<D extends DictionaryInput = DictionaryInput>(): Verbaly<D> {\n const instance = useContext(VerbalyContext);\n if (!instance) {\n throw new Error('[verbaly] useVerbaly requires a <VerbalyProvider>');\n }\n return instance as unknown as Verbaly<D>;\n}\n\nexport function useT<D extends DictionaryInput = DictionaryInput>(): TFunction<D> {\n const instance = useVerbaly<D>();\n const version = useVersion(instance);\n // a new t per locale or catalog: a memo or an effect keyed on t would keep the old language\n return useMemo(() => bound(instance.t), [instance, version]);\n}\n\nfunction bound<D extends DictionaryInput>(t: TFunction<D>): TFunction<D> {\n const call = t as unknown as (...args: unknown[]) => string;\n const fresh = ((...args: unknown[]) => call(...args)) as unknown as TFunction<D>;\n fresh.id = t.id;\n return fresh;\n}\n\nexport function useLocale(): [string, (locale: string) => void] {\n const instance = useVerbaly();\n useVersion(instance);\n return [instance.locale, instance.setLocale];\n}\n\nfunction useVersion<D extends DictionaryInput>(instance: Verbaly<D>): number {\n return useSyncExternalStore(\n instance.subscribe,\n () => instance.version,\n () => instance.version,\n );\n}\n\nexport interface TransProps {\n id: string;\n values?: Params;\n instance?: Verbaly;\n components?: Record<string, ReactElement>;\n richTags?: string[];\n links?: Record<string, RichLink>;\n}\n\n// translated message + element interpolation\nexport function Trans(props: TransProps): ReactElement {\n const ctx = useContext(VerbalyContext);\n const instance = props.instance ?? ctx;\n if (!instance) {\n throw new Error('[verbaly] <Trans> requires an instance prop or a <VerbalyProvider>');\n }\n useVersion(instance);\n const text = (instance.t as unknown as (id: string, values?: Params) => string)(\n props.id,\n props.values,\n );\n return createElement(\n Fragment,\n null,\n ...toNodes(\n parseTags(text),\n props.components ?? {},\n props.links ?? {},\n new Set(props.richTags ?? RICH_TAGS),\n ),\n );\n}\n\nconst VOID = new Set(VOID_TAGS);\n\n// own entries only: a tag named constructor in a message must never find the one on Object\nfunction own<T>(map: Record<string, T>, name: string): T | undefined {\n return Object.prototype.hasOwnProperty.call(map, name) ? map[name] : undefined;\n}\n\nfunction toNodes(\n nodes: TagNode[],\n components: Record<string, ReactElement>,\n links: Record<string, RichLink>,\n richTags: Set<string>,\n): ReactNode[] {\n return nodes.map((node, i) => {\n if (typeof node === 'string') return node;\n const children = toNodes(node.children, components, links, richTags);\n const el = own(components, node.name);\n if (el) return cloneElement(el, { key: i }, ...children);\n const link = own(links, node.name);\n if (link !== undefined) {\n return createElement('a', { key: i, ...normalizeLink(link) }, ...children);\n }\n if (richTags.has(node.name)) {\n if (VOID.has(node.name)) return createElement(node.name, { key: i });\n return createElement(node.name, { key: i }, ...children);\n }\n return createElement(Fragment, { key: i }, ...children);\n });\n}\n\nexport type { Params, TFunction, Verbaly };\n"],"mappings":";;;;AAwBA,MAAM,kBAAA,GAAiBA,MAAAA,cAAAA,CAA8B,IAAI;AAOzD,SAAgB,gBACd,OACc;CACd,QAAA,GAAOC,MAAAA,cAAAA,CACL,eAAe,UACf,EAAE,OAAO,MAAM,SAA+B,GAC9C,MAAM,QACR;AACF;AAEA,SAAgB,aAAsE;CACpF,MAAM,YAAA,GAAWC,MAAAA,WAAAA,CAAW,cAAc;CAC1C,IAAI,CAAC,UACH,MAAM,IAAI,MAAM,mDAAmD;CAErE,OAAO;AACT;AAEA,SAAgB,OAAkE;CAChF,MAAM,WAAW,WAAc;CAC/B,MAAM,UAAU,WAAW,QAAQ;CAEnC,QAAA,GAAOC,MAAAA,QAAAA,OAAc,MAAM,SAAS,CAAC,GAAG,CAAC,UAAU,OAAO,CAAC;AAC7D;AAEA,SAAS,MAAiC,GAA+B;CACvE,MAAM,OAAO;CACb,MAAM,UAAU,GAAG,SAAoB,KAAK,GAAG,IAAI;CACnD,MAAM,KAAK,EAAE;CACb,OAAO;AACT;AAEA,SAAgB,YAAgD;CAC9D,MAAM,WAAW,WAAW;CAC5B,WAAW,QAAQ;CACnB,OAAO,CAAC,SAAS,QAAQ,SAAS,SAAS;AAC7C;AAEA,SAAS,WAAsC,UAA8B;CAC3E,QAAA,GAAOC,MAAAA,qBAAAA,CACL,SAAS,iBACH,SAAS,eACT,SAAS,OACjB;AACF;AAYA,SAAgB,MAAM,OAAiC;CACrD,MAAM,OAAA,GAAMF,MAAAA,WAAAA,CAAW,cAAc;CACrC,MAAM,WAAW,MAAM,YAAY;CACnC,IAAI,CAAC,UACH,MAAM,IAAI,MAAM,oEAAoE;CAEtF,WAAW,QAAQ;CACnB,MAAM,OAAQ,SAAS,EACrB,MAAM,IACN,MAAM,MACR;CACA,QAAA,GAAOD,MAAAA,cAAAA,CACLI,MAAAA,UACA,MACA,GAAG,SAAA,GACDC,QAAAA,UAAAA,CAAU,IAAI,GACd,MAAM,cAAc,CAAC,GACrB,MAAM,SAAS,CAAC,GAChB,IAAI,IAAI,MAAM,YAAYC,QAAAA,SAAS,CACrC,CACF;AACF;AAEA,MAAM,OAAO,IAAI,IAAIC,QAAAA,SAAS;AAG9B,SAAS,IAAO,KAAwB,MAA6B;CACnE,OAAO,OAAO,UAAU,eAAe,KAAK,KAAK,IAAI,IAAI,IAAI,QAAQ,KAAA;AACvE;AAEA,SAAS,QACP,OACA,YACA,OACA,UACa;CACb,OAAO,MAAM,KAAK,MAAM,MAAM;EAC5B,IAAI,OAAO,SAAS,UAAU,OAAO;EACrC,MAAM,WAAW,QAAQ,KAAK,UAAU,YAAY,OAAO,QAAQ;EACnE,MAAM,KAAK,IAAI,YAAY,KAAK,IAAI;EACpC,IAAI,IAAI,QAAA,GAAOC,MAAAA,aAAAA,CAAa,IAAI,EAAE,KAAK,EAAE,GAAG,GAAG,QAAQ;EACvD,MAAM,OAAO,IAAI,OAAO,KAAK,IAAI;EACjC,IAAI,SAAS,KAAA,GACX,QAAA,GAAOR,MAAAA,cAAAA,CAAc,KAAK;GAAE,KAAK;GAAG,IAAA,GAAGS,QAAAA,cAAAA,CAAc,IAAI;EAAE,GAAG,GAAG,QAAQ;EAE3E,IAAI,SAAS,IAAI,KAAK,IAAI,GAAG;GAC3B,IAAI,KAAK,IAAI,KAAK,IAAI,GAAG,QAAA,GAAOT,MAAAA,cAAAA,CAAc,KAAK,MAAM,EAAE,KAAK,EAAE,CAAC;GACnE,QAAA,GAAOA,MAAAA,cAAAA,CAAc,KAAK,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,QAAQ;EACzD;EACA,QAAA,GAAOA,MAAAA,cAAAA,CAAcI,MAAAA,UAAU,EAAE,KAAK,EAAE,GAAG,GAAG,QAAQ;CACxD,CAAC;AACH"}
1
+ {"version":3,"file":"index.cjs","names":["createContext","createElement","useContext","useMemo","useSyncExternalStore","renderTrans"],"sources":["../src/index.ts"],"sourcesContent":["import {\n createContext,\n createElement,\n useContext,\n useMemo,\n useSyncExternalStore,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport type { DictionaryInput, Params, TFunction, Verbaly } from 'verbaly';\nimport { renderTrans, type TransProps } from './render';\n\nexport type { TransOptions, TransProps } from './render';\n\nconst VerbalyContext = createContext<Verbaly | null>(null);\n\nexport interface VerbalyProviderProps<D extends DictionaryInput> {\n instance: Verbaly<D>;\n children?: ReactNode;\n}\n\nexport function VerbalyProvider<D extends DictionaryInput>(\n props: VerbalyProviderProps<D>,\n): ReactElement {\n return createElement(\n VerbalyContext.Provider,\n { value: props.instance as unknown as Verbaly },\n props.children,\n );\n}\n\nexport function useVerbaly<D extends DictionaryInput = DictionaryInput>(): Verbaly<D> {\n const instance = useContext(VerbalyContext);\n if (!instance) {\n throw new Error('[verbaly] useVerbaly requires a <VerbalyProvider>');\n }\n return instance as unknown as Verbaly<D>;\n}\n\n// typed by the project's catalog once verbaly.d.ts exists, by a dictionary when one is named\nexport function useT<D extends DictionaryInput = DictionaryInput>(): Verbaly<D>['t'] {\n const instance = useVerbaly<D>();\n const version = useVersion(instance);\n // a new t per locale or catalog: a memo or an effect keyed on t would keep the old language\n return useMemo(() => bound(instance.t), [instance, version]);\n}\n\nfunction bound<T extends Pick<TFunction, 'id'>>(t: T): T {\n const call = t as unknown as (...args: unknown[]) => string;\n const fresh = ((...args: unknown[]) => call(...args)) as unknown as T;\n fresh.id = t.id;\n return fresh;\n}\n\nexport function useLocale(): [string, (locale: string) => void] {\n const instance = useVerbaly();\n useVersion(instance);\n return [instance.locale, instance.setLocale];\n}\n\nfunction useVersion<D extends DictionaryInput>(instance: Verbaly<D>): number {\n return useSyncExternalStore(\n instance.subscribe,\n () => instance.version,\n () => instance.version,\n );\n}\n\n// translated message + element interpolation\nexport function Trans(props: TransProps): ReactElement {\n const ctx = useContext(VerbalyContext);\n const instance = props.instance ?? ctx;\n if (!instance) {\n throw new Error('[verbaly] <Trans> requires an instance prop or a <VerbalyProvider>');\n }\n useVersion(instance);\n return renderTrans(instance, props);\n}\n\nexport type { Params, TFunction, Verbaly };\n"],"mappings":";;;;AAcA,MAAM,kBAAA,GAAiBA,MAAAA,cAAAA,CAA8B,IAAI;AAOzD,SAAgB,gBACd,OACc;CACd,QAAA,GAAOC,MAAAA,cAAAA,CACL,eAAe,UACf,EAAE,OAAO,MAAM,SAA+B,GAC9C,MAAM,QACR;AACF;AAEA,SAAgB,aAAsE;CACpF,MAAM,YAAA,GAAWC,MAAAA,WAAAA,CAAW,cAAc;CAC1C,IAAI,CAAC,UACH,MAAM,IAAI,MAAM,mDAAmD;CAErE,OAAO;AACT;AAGA,SAAgB,OAAqE;CACnF,MAAM,WAAW,WAAc;CAC/B,MAAM,UAAU,WAAW,QAAQ;CAEnC,QAAA,GAAOC,MAAAA,QAAAA,OAAc,MAAM,SAAS,CAAC,GAAG,CAAC,UAAU,OAAO,CAAC;AAC7D;AAEA,SAAS,MAAuC,GAAS;CACvD,MAAM,OAAO;CACb,MAAM,UAAU,GAAG,SAAoB,KAAK,GAAG,IAAI;CACnD,MAAM,KAAK,EAAE;CACb,OAAO;AACT;AAEA,SAAgB,YAAgD;CAC9D,MAAM,WAAW,WAAW;CAC5B,WAAW,QAAQ;CACnB,OAAO,CAAC,SAAS,QAAQ,SAAS,SAAS;AAC7C;AAEA,SAAS,WAAsC,UAA8B;CAC3E,QAAA,GAAOC,MAAAA,qBAAAA,CACL,SAAS,iBACH,SAAS,eACT,SAAS,OACjB;AACF;AAGA,SAAgB,MAAM,OAAiC;CACrD,MAAM,OAAA,GAAMF,MAAAA,WAAAA,CAAW,cAAc;CACrC,MAAM,WAAW,MAAM,YAAY;CACnC,IAAI,CAAC,UACH,MAAM,IAAI,MAAM,oEAAoE;CAEtF,WAAW,QAAQ;CACnB,OAAOG,eAAAA,YAAY,UAAU,KAAK;AACpC"}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
+ import { n as TransProps, t as TransOptions } from "./render-D1J3Qbqg.cjs";
1
2
  import { ReactElement, ReactNode } from "react";
2
- import { DictionaryInput, Params, RichLink, TFunction, Verbaly } from "verbaly";
3
+ import { DictionaryInput, Params, TFunction, Verbaly } from "verbaly";
3
4
  //#region src/index.d.ts
4
5
  export interface VerbalyProviderProps<D extends DictionaryInput> {
5
6
  instance: Verbaly<D>;
@@ -7,17 +8,9 @@ export interface VerbalyProviderProps<D extends DictionaryInput> {
7
8
  }
8
9
  export declare function VerbalyProvider<D extends DictionaryInput>(props: VerbalyProviderProps<D>): ReactElement;
9
10
  export declare function useVerbaly<D extends DictionaryInput = DictionaryInput>(): Verbaly<D>;
10
- export declare function useT<D extends DictionaryInput = DictionaryInput>(): TFunction<D>;
11
+ export declare function useT<D extends DictionaryInput = DictionaryInput>(): Verbaly<D>['t'];
11
12
  export declare function useLocale(): [string, (locale: string) => void];
12
- export interface TransProps {
13
- id: string;
14
- values?: Params;
15
- instance?: Verbaly;
16
- components?: Record<string, ReactElement>;
17
- richTags?: string[];
18
- links?: Record<string, RichLink>;
19
- }
20
13
  export declare function Trans(props: TransProps): ReactElement;
21
14
  //#endregion
22
- export type { Params, TFunction, Verbaly };
15
+ export type { Params, TFunction, TransOptions, TransProps, Verbaly };
23
16
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
+ import { n as TransProps, t as TransOptions } from "./render-D1J3Qbqg.js";
1
2
  import { ReactElement, ReactNode } from "react";
2
- import { DictionaryInput, Params, RichLink, TFunction, Verbaly } from "verbaly";
3
+ import { DictionaryInput, Params, TFunction, Verbaly } from "verbaly";
3
4
  //#region src/index.d.ts
4
5
  export interface VerbalyProviderProps<D extends DictionaryInput> {
5
6
  instance: Verbaly<D>;
@@ -7,17 +8,9 @@ export interface VerbalyProviderProps<D extends DictionaryInput> {
7
8
  }
8
9
  export declare function VerbalyProvider<D extends DictionaryInput>(props: VerbalyProviderProps<D>): ReactElement;
9
10
  export declare function useVerbaly<D extends DictionaryInput = DictionaryInput>(): Verbaly<D>;
10
- export declare function useT<D extends DictionaryInput = DictionaryInput>(): TFunction<D>;
11
+ export declare function useT<D extends DictionaryInput = DictionaryInput>(): Verbaly<D>['t'];
11
12
  export declare function useLocale(): [string, (locale: string) => void];
12
- export interface TransProps {
13
- id: string;
14
- values?: Params;
15
- instance?: Verbaly;
16
- components?: Record<string, ReactElement>;
17
- richTags?: string[];
18
- links?: Record<string, RichLink>;
19
- }
20
13
  export declare function Trans(props: TransProps): ReactElement;
21
14
  //#endregion
22
- export type { Params, TFunction, Verbaly };
15
+ export type { Params, TFunction, TransOptions, TransProps, Verbaly };
23
16
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { Fragment, cloneElement, createContext, createElement, useContext, useMemo, useSyncExternalStore } from "react";
2
- import { RICH_TAGS, VOID_TAGS, normalizeLink, parseTags } from "verbaly";
1
+ import { t as renderTrans } from "./render-CyRz_srQ.js";
2
+ import { createContext, createElement, useContext, useMemo, useSyncExternalStore } from "react";
3
3
  //#region src/index.ts
4
4
  const VerbalyContext = createContext(null);
5
5
  function VerbalyProvider(props) {
@@ -34,30 +34,7 @@ function Trans(props) {
34
34
  const instance = props.instance ?? ctx;
35
35
  if (!instance) throw new Error("[verbaly] <Trans> requires an instance prop or a <VerbalyProvider>");
36
36
  useVersion(instance);
37
- const text = instance.t(props.id, props.values);
38
- return createElement(Fragment, null, ...toNodes(parseTags(text), props.components ?? {}, props.links ?? {}, new Set(props.richTags ?? RICH_TAGS)));
39
- }
40
- const VOID = new Set(VOID_TAGS);
41
- function own(map, name) {
42
- return Object.prototype.hasOwnProperty.call(map, name) ? map[name] : void 0;
43
- }
44
- function toNodes(nodes, components, links, richTags) {
45
- return nodes.map((node, i) => {
46
- if (typeof node === "string") return node;
47
- const children = toNodes(node.children, components, links, richTags);
48
- const el = own(components, node.name);
49
- if (el) return cloneElement(el, { key: i }, ...children);
50
- const link = own(links, node.name);
51
- if (link !== void 0) return createElement("a", {
52
- key: i,
53
- ...normalizeLink(link)
54
- }, ...children);
55
- if (richTags.has(node.name)) {
56
- if (VOID.has(node.name)) return createElement(node.name, { key: i });
57
- return createElement(node.name, { key: i }, ...children);
58
- }
59
- return createElement(Fragment, { key: i }, ...children);
60
- });
37
+ return renderTrans(instance, props);
61
38
  }
62
39
  //#endregion
63
40
  export { Trans, VerbalyProvider, useLocale, useT, useVerbaly };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n cloneElement,\n createContext,\n createElement,\n Fragment,\n useContext,\n useMemo,\n useSyncExternalStore,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport {\n normalizeLink,\n parseTags,\n RICH_TAGS,\n VOID_TAGS,\n type DictionaryInput,\n type Params,\n type RichLink,\n type TagNode,\n type TFunction,\n type Verbaly,\n} from 'verbaly';\n\nconst VerbalyContext = createContext<Verbaly | null>(null);\n\nexport interface VerbalyProviderProps<D extends DictionaryInput> {\n instance: Verbaly<D>;\n children?: ReactNode;\n}\n\nexport function VerbalyProvider<D extends DictionaryInput>(\n props: VerbalyProviderProps<D>,\n): ReactElement {\n return createElement(\n VerbalyContext.Provider,\n { value: props.instance as unknown as Verbaly },\n props.children,\n );\n}\n\nexport function useVerbaly<D extends DictionaryInput = DictionaryInput>(): Verbaly<D> {\n const instance = useContext(VerbalyContext);\n if (!instance) {\n throw new Error('[verbaly] useVerbaly requires a <VerbalyProvider>');\n }\n return instance as unknown as Verbaly<D>;\n}\n\nexport function useT<D extends DictionaryInput = DictionaryInput>(): TFunction<D> {\n const instance = useVerbaly<D>();\n const version = useVersion(instance);\n // a new t per locale or catalog: a memo or an effect keyed on t would keep the old language\n return useMemo(() => bound(instance.t), [instance, version]);\n}\n\nfunction bound<D extends DictionaryInput>(t: TFunction<D>): TFunction<D> {\n const call = t as unknown as (...args: unknown[]) => string;\n const fresh = ((...args: unknown[]) => call(...args)) as unknown as TFunction<D>;\n fresh.id = t.id;\n return fresh;\n}\n\nexport function useLocale(): [string, (locale: string) => void] {\n const instance = useVerbaly();\n useVersion(instance);\n return [instance.locale, instance.setLocale];\n}\n\nfunction useVersion<D extends DictionaryInput>(instance: Verbaly<D>): number {\n return useSyncExternalStore(\n instance.subscribe,\n () => instance.version,\n () => instance.version,\n );\n}\n\nexport interface TransProps {\n id: string;\n values?: Params;\n instance?: Verbaly;\n components?: Record<string, ReactElement>;\n richTags?: string[];\n links?: Record<string, RichLink>;\n}\n\n// translated message + element interpolation\nexport function Trans(props: TransProps): ReactElement {\n const ctx = useContext(VerbalyContext);\n const instance = props.instance ?? ctx;\n if (!instance) {\n throw new Error('[verbaly] <Trans> requires an instance prop or a <VerbalyProvider>');\n }\n useVersion(instance);\n const text = (instance.t as unknown as (id: string, values?: Params) => string)(\n props.id,\n props.values,\n );\n return createElement(\n Fragment,\n null,\n ...toNodes(\n parseTags(text),\n props.components ?? {},\n props.links ?? {},\n new Set(props.richTags ?? RICH_TAGS),\n ),\n );\n}\n\nconst VOID = new Set(VOID_TAGS);\n\n// own entries only: a tag named constructor in a message must never find the one on Object\nfunction own<T>(map: Record<string, T>, name: string): T | undefined {\n return Object.prototype.hasOwnProperty.call(map, name) ? map[name] : undefined;\n}\n\nfunction toNodes(\n nodes: TagNode[],\n components: Record<string, ReactElement>,\n links: Record<string, RichLink>,\n richTags: Set<string>,\n): ReactNode[] {\n return nodes.map((node, i) => {\n if (typeof node === 'string') return node;\n const children = toNodes(node.children, components, links, richTags);\n const el = own(components, node.name);\n if (el) return cloneElement(el, { key: i }, ...children);\n const link = own(links, node.name);\n if (link !== undefined) {\n return createElement('a', { key: i, ...normalizeLink(link) }, ...children);\n }\n if (richTags.has(node.name)) {\n if (VOID.has(node.name)) return createElement(node.name, { key: i });\n return createElement(node.name, { key: i }, ...children);\n }\n return createElement(Fragment, { key: i }, ...children);\n });\n}\n\nexport type { Params, TFunction, Verbaly };\n"],"mappings":";;;AAwBA,MAAM,iBAAiB,cAA8B,IAAI;AAOzD,SAAgB,gBACd,OACc;CACd,OAAO,cACL,eAAe,UACf,EAAE,OAAO,MAAM,SAA+B,GAC9C,MAAM,QACR;AACF;AAEA,SAAgB,aAAsE;CACpF,MAAM,WAAW,WAAW,cAAc;CAC1C,IAAI,CAAC,UACH,MAAM,IAAI,MAAM,mDAAmD;CAErE,OAAO;AACT;AAEA,SAAgB,OAAkE;CAChF,MAAM,WAAW,WAAc;CAC/B,MAAM,UAAU,WAAW,QAAQ;CAEnC,OAAO,cAAc,MAAM,SAAS,CAAC,GAAG,CAAC,UAAU,OAAO,CAAC;AAC7D;AAEA,SAAS,MAAiC,GAA+B;CACvE,MAAM,OAAO;CACb,MAAM,UAAU,GAAG,SAAoB,KAAK,GAAG,IAAI;CACnD,MAAM,KAAK,EAAE;CACb,OAAO;AACT;AAEA,SAAgB,YAAgD;CAC9D,MAAM,WAAW,WAAW;CAC5B,WAAW,QAAQ;CACnB,OAAO,CAAC,SAAS,QAAQ,SAAS,SAAS;AAC7C;AAEA,SAAS,WAAsC,UAA8B;CAC3E,OAAO,qBACL,SAAS,iBACH,SAAS,eACT,SAAS,OACjB;AACF;AAYA,SAAgB,MAAM,OAAiC;CACrD,MAAM,MAAM,WAAW,cAAc;CACrC,MAAM,WAAW,MAAM,YAAY;CACnC,IAAI,CAAC,UACH,MAAM,IAAI,MAAM,oEAAoE;CAEtF,WAAW,QAAQ;CACnB,MAAM,OAAQ,SAAS,EACrB,MAAM,IACN,MAAM,MACR;CACA,OAAO,cACL,UACA,MACA,GAAG,QACD,UAAU,IAAI,GACd,MAAM,cAAc,CAAC,GACrB,MAAM,SAAS,CAAC,GAChB,IAAI,IAAI,MAAM,YAAY,SAAS,CACrC,CACF;AACF;AAEA,MAAM,OAAO,IAAI,IAAI,SAAS;AAG9B,SAAS,IAAO,KAAwB,MAA6B;CACnE,OAAO,OAAO,UAAU,eAAe,KAAK,KAAK,IAAI,IAAI,IAAI,QAAQ,KAAA;AACvE;AAEA,SAAS,QACP,OACA,YACA,OACA,UACa;CACb,OAAO,MAAM,KAAK,MAAM,MAAM;EAC5B,IAAI,OAAO,SAAS,UAAU,OAAO;EACrC,MAAM,WAAW,QAAQ,KAAK,UAAU,YAAY,OAAO,QAAQ;EACnE,MAAM,KAAK,IAAI,YAAY,KAAK,IAAI;EACpC,IAAI,IAAI,OAAO,aAAa,IAAI,EAAE,KAAK,EAAE,GAAG,GAAG,QAAQ;EACvD,MAAM,OAAO,IAAI,OAAO,KAAK,IAAI;EACjC,IAAI,SAAS,KAAA,GACX,OAAO,cAAc,KAAK;GAAE,KAAK;GAAG,GAAG,cAAc,IAAI;EAAE,GAAG,GAAG,QAAQ;EAE3E,IAAI,SAAS,IAAI,KAAK,IAAI,GAAG;GAC3B,IAAI,KAAK,IAAI,KAAK,IAAI,GAAG,OAAO,cAAc,KAAK,MAAM,EAAE,KAAK,EAAE,CAAC;GACnE,OAAO,cAAc,KAAK,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,QAAQ;EACzD;EACA,OAAO,cAAc,UAAU,EAAE,KAAK,EAAE,GAAG,GAAG,QAAQ;CACxD,CAAC;AACH"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n createContext,\n createElement,\n useContext,\n useMemo,\n useSyncExternalStore,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport type { DictionaryInput, Params, TFunction, Verbaly } from 'verbaly';\nimport { renderTrans, type TransProps } from './render';\n\nexport type { TransOptions, TransProps } from './render';\n\nconst VerbalyContext = createContext<Verbaly | null>(null);\n\nexport interface VerbalyProviderProps<D extends DictionaryInput> {\n instance: Verbaly<D>;\n children?: ReactNode;\n}\n\nexport function VerbalyProvider<D extends DictionaryInput>(\n props: VerbalyProviderProps<D>,\n): ReactElement {\n return createElement(\n VerbalyContext.Provider,\n { value: props.instance as unknown as Verbaly },\n props.children,\n );\n}\n\nexport function useVerbaly<D extends DictionaryInput = DictionaryInput>(): Verbaly<D> {\n const instance = useContext(VerbalyContext);\n if (!instance) {\n throw new Error('[verbaly] useVerbaly requires a <VerbalyProvider>');\n }\n return instance as unknown as Verbaly<D>;\n}\n\n// typed by the project's catalog once verbaly.d.ts exists, by a dictionary when one is named\nexport function useT<D extends DictionaryInput = DictionaryInput>(): Verbaly<D>['t'] {\n const instance = useVerbaly<D>();\n const version = useVersion(instance);\n // a new t per locale or catalog: a memo or an effect keyed on t would keep the old language\n return useMemo(() => bound(instance.t), [instance, version]);\n}\n\nfunction bound<T extends Pick<TFunction, 'id'>>(t: T): T {\n const call = t as unknown as (...args: unknown[]) => string;\n const fresh = ((...args: unknown[]) => call(...args)) as unknown as T;\n fresh.id = t.id;\n return fresh;\n}\n\nexport function useLocale(): [string, (locale: string) => void] {\n const instance = useVerbaly();\n useVersion(instance);\n return [instance.locale, instance.setLocale];\n}\n\nfunction useVersion<D extends DictionaryInput>(instance: Verbaly<D>): number {\n return useSyncExternalStore(\n instance.subscribe,\n () => instance.version,\n () => instance.version,\n );\n}\n\n// translated message + element interpolation\nexport function Trans(props: TransProps): ReactElement {\n const ctx = useContext(VerbalyContext);\n const instance = props.instance ?? ctx;\n if (!instance) {\n throw new Error('[verbaly] <Trans> requires an instance prop or a <VerbalyProvider>');\n }\n useVersion(instance);\n return renderTrans(instance, props);\n}\n\nexport type { Params, TFunction, Verbaly };\n"],"mappings":";;;AAcA,MAAM,iBAAiB,cAA8B,IAAI;AAOzD,SAAgB,gBACd,OACc;CACd,OAAO,cACL,eAAe,UACf,EAAE,OAAO,MAAM,SAA+B,GAC9C,MAAM,QACR;AACF;AAEA,SAAgB,aAAsE;CACpF,MAAM,WAAW,WAAW,cAAc;CAC1C,IAAI,CAAC,UACH,MAAM,IAAI,MAAM,mDAAmD;CAErE,OAAO;AACT;AAGA,SAAgB,OAAqE;CACnF,MAAM,WAAW,WAAc;CAC/B,MAAM,UAAU,WAAW,QAAQ;CAEnC,OAAO,cAAc,MAAM,SAAS,CAAC,GAAG,CAAC,UAAU,OAAO,CAAC;AAC7D;AAEA,SAAS,MAAuC,GAAS;CACvD,MAAM,OAAO;CACb,MAAM,UAAU,GAAG,SAAoB,KAAK,GAAG,IAAI;CACnD,MAAM,KAAK,EAAE;CACb,OAAO;AACT;AAEA,SAAgB,YAAgD;CAC9D,MAAM,WAAW,WAAW;CAC5B,WAAW,QAAQ;CACnB,OAAO,CAAC,SAAS,QAAQ,SAAS,SAAS;AAC7C;AAEA,SAAS,WAAsC,UAA8B;CAC3E,OAAO,qBACL,SAAS,iBACH,SAAS,eACT,SAAS,OACjB;AACF;AAGA,SAAgB,MAAM,OAAiC;CACrD,MAAM,MAAM,WAAW,cAAc;CACrC,MAAM,WAAW,MAAM,YAAY;CACnC,IAAI,CAAC,UACH,MAAM,IAAI,MAAM,oEAAoE;CAEtF,WAAW,QAAQ;CACnB,OAAO,YAAY,UAAU,KAAK;AACpC"}
@@ -0,0 +1,39 @@
1
+ let react = require("react");
2
+ let verbaly = require("verbaly");
3
+ //#region src/render.ts
4
+ function renderTrans(instance, props) {
5
+ if (props.id === void 0) return (0, react.createElement)(react.Fragment, null, props.children);
6
+ const text = instance.t(props.id, props.values);
7
+ return (0, react.createElement)(react.Fragment, null, ...toNodes((0, verbaly.parseTags)(text), props.components ?? {}, props.links ?? {}, new Set(props.richTags ?? verbaly.RICH_TAGS)));
8
+ }
9
+ const VOID = new Set(verbaly.VOID_TAGS);
10
+ function own(map, name) {
11
+ return Object.prototype.hasOwnProperty.call(map, name) ? map[name] : void 0;
12
+ }
13
+ function toNodes(nodes, components, links, richTags) {
14
+ return nodes.map((node, i) => {
15
+ if (typeof node === "string") return node;
16
+ const children = toNodes(node.children, components, links, richTags);
17
+ const el = own(components, node.name);
18
+ if (el) return (0, react.cloneElement)(el, { key: i }, ...children);
19
+ const link = own(links, node.name);
20
+ if (link !== void 0) return (0, react.createElement)("a", {
21
+ key: i,
22
+ ...(0, verbaly.normalizeLink)(link)
23
+ }, ...children);
24
+ if (richTags.has(node.name)) {
25
+ if (VOID.has(node.name)) return (0, react.createElement)(node.name, { key: i });
26
+ return (0, react.createElement)(node.name, { key: i }, ...children);
27
+ }
28
+ return (0, react.createElement)(react.Fragment, { key: i }, ...children);
29
+ });
30
+ }
31
+ //#endregion
32
+ Object.defineProperty(exports, "renderTrans", {
33
+ enumerable: true,
34
+ get: function() {
35
+ return renderTrans;
36
+ }
37
+ });
38
+
39
+ //# sourceMappingURL=render-CY-uLpA6.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-CY-uLpA6.cjs","names":["createElement","Fragment","parseTags","RICH_TAGS","VOID_TAGS","cloneElement","normalizeLink"],"sources":["../src/render.ts"],"sourcesContent":["import { cloneElement, createElement, Fragment, type ReactElement, type ReactNode } from 'react';\nimport {\n normalizeLink,\n parseTags,\n RICH_TAGS,\n VOID_TAGS,\n type Params,\n type RichLink,\n type TagNode,\n type Verbaly,\n} from 'verbaly';\n\n// everything a <Trans> takes besides its message: one contract for the client and the server\nexport interface TransOptions {\n values?: Params;\n instance?: Verbaly;\n components?: Record<string, ReactElement>;\n richTags?: string[];\n links?: Record<string, RichLink>;\n}\n\n// an id at runtime; children in the source, which the compiler turns into an id and its props\nexport type TransProps = TransOptions &\n ({ id: string; children?: undefined } | { id?: undefined; children: ReactNode });\n\n// no hook and no context in here, so a Server Component renders it as well as a client one\nexport function renderTrans(instance: Verbaly, props: TransProps): ReactElement {\n // never compiled (no plugin, or a file outside include): the source text, like an uncompiled t`…`\n if (props.id === undefined) return createElement(Fragment, null, props.children);\n const text = (instance.t as unknown as (id: string, values?: Params) => string)(\n props.id,\n props.values,\n );\n return createElement(\n Fragment,\n null,\n ...toNodes(\n parseTags(text),\n props.components ?? {},\n props.links ?? {},\n new Set(props.richTags ?? RICH_TAGS),\n ),\n );\n}\n\nconst VOID = new Set(VOID_TAGS);\n\n// own entries only: a tag named constructor in a message must never find the one on Object\nfunction own<T>(map: Record<string, T>, name: string): T | undefined {\n return Object.prototype.hasOwnProperty.call(map, name) ? map[name] : undefined;\n}\n\nfunction toNodes(\n nodes: TagNode[],\n components: Record<string, ReactElement>,\n links: Record<string, RichLink>,\n richTags: Set<string>,\n): ReactNode[] {\n return nodes.map((node, i) => {\n if (typeof node === 'string') return node;\n const children = toNodes(node.children, components, links, richTags);\n const el = own(components, node.name);\n if (el) return cloneElement(el, { key: i }, ...children);\n const link = own(links, node.name);\n if (link !== undefined) {\n return createElement('a', { key: i, ...normalizeLink(link) }, ...children);\n }\n if (richTags.has(node.name)) {\n if (VOID.has(node.name)) return createElement(node.name, { key: i });\n return createElement(node.name, { key: i }, ...children);\n }\n return createElement(Fragment, { key: i }, ...children);\n });\n}\n"],"mappings":";;;AA0BA,SAAgB,YAAY,UAAmB,OAAiC;CAE9E,IAAI,MAAM,OAAO,KAAA,GAAW,QAAA,GAAOA,MAAAA,cAAAA,CAAcC,MAAAA,UAAU,MAAM,MAAM,QAAQ;CAC/E,MAAM,OAAQ,SAAS,EACrB,MAAM,IACN,MAAM,MACR;CACA,QAAA,GAAOD,MAAAA,cAAAA,CACLC,MAAAA,UACA,MACA,GAAG,SAAA,GACDC,QAAAA,UAAAA,CAAU,IAAI,GACd,MAAM,cAAc,CAAC,GACrB,MAAM,SAAS,CAAC,GAChB,IAAI,IAAI,MAAM,YAAYC,QAAAA,SAAS,CACrC,CACF;AACF;AAEA,MAAM,OAAO,IAAI,IAAIC,QAAAA,SAAS;AAG9B,SAAS,IAAO,KAAwB,MAA6B;CACnE,OAAO,OAAO,UAAU,eAAe,KAAK,KAAK,IAAI,IAAI,IAAI,QAAQ,KAAA;AACvE;AAEA,SAAS,QACP,OACA,YACA,OACA,UACa;CACb,OAAO,MAAM,KAAK,MAAM,MAAM;EAC5B,IAAI,OAAO,SAAS,UAAU,OAAO;EACrC,MAAM,WAAW,QAAQ,KAAK,UAAU,YAAY,OAAO,QAAQ;EACnE,MAAM,KAAK,IAAI,YAAY,KAAK,IAAI;EACpC,IAAI,IAAI,QAAA,GAAOC,MAAAA,aAAAA,CAAa,IAAI,EAAE,KAAK,EAAE,GAAG,GAAG,QAAQ;EACvD,MAAM,OAAO,IAAI,OAAO,KAAK,IAAI;EACjC,IAAI,SAAS,KAAA,GACX,QAAA,GAAOL,MAAAA,cAAAA,CAAc,KAAK;GAAE,KAAK;GAAG,IAAA,GAAGM,QAAAA,cAAAA,CAAc,IAAI;EAAE,GAAG,GAAG,QAAQ;EAE3E,IAAI,SAAS,IAAI,KAAK,IAAI,GAAG;GAC3B,IAAI,KAAK,IAAI,KAAK,IAAI,GAAG,QAAA,GAAON,MAAAA,cAAAA,CAAc,KAAK,MAAM,EAAE,KAAK,EAAE,CAAC;GACnE,QAAA,GAAOA,MAAAA,cAAAA,CAAc,KAAK,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,QAAQ;EACzD;EACA,QAAA,GAAOA,MAAAA,cAAAA,CAAcC,MAAAA,UAAU,EAAE,KAAK,EAAE,GAAG,GAAG,QAAQ;CACxD,CAAC;AACH"}
@@ -0,0 +1,34 @@
1
+ import { Fragment, cloneElement, createElement } from "react";
2
+ import { RICH_TAGS, VOID_TAGS, normalizeLink, parseTags } from "verbaly";
3
+ //#region src/render.ts
4
+ function renderTrans(instance, props) {
5
+ if (props.id === void 0) return createElement(Fragment, null, props.children);
6
+ const text = instance.t(props.id, props.values);
7
+ return createElement(Fragment, null, ...toNodes(parseTags(text), props.components ?? {}, props.links ?? {}, new Set(props.richTags ?? RICH_TAGS)));
8
+ }
9
+ const VOID = new Set(VOID_TAGS);
10
+ function own(map, name) {
11
+ return Object.prototype.hasOwnProperty.call(map, name) ? map[name] : void 0;
12
+ }
13
+ function toNodes(nodes, components, links, richTags) {
14
+ return nodes.map((node, i) => {
15
+ if (typeof node === "string") return node;
16
+ const children = toNodes(node.children, components, links, richTags);
17
+ const el = own(components, node.name);
18
+ if (el) return cloneElement(el, { key: i }, ...children);
19
+ const link = own(links, node.name);
20
+ if (link !== void 0) return createElement("a", {
21
+ key: i,
22
+ ...normalizeLink(link)
23
+ }, ...children);
24
+ if (richTags.has(node.name)) {
25
+ if (VOID.has(node.name)) return createElement(node.name, { key: i });
26
+ return createElement(node.name, { key: i }, ...children);
27
+ }
28
+ return createElement(Fragment, { key: i }, ...children);
29
+ });
30
+ }
31
+ //#endregion
32
+ export { renderTrans as t };
33
+
34
+ //# sourceMappingURL=render-CyRz_srQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-CyRz_srQ.js","names":[],"sources":["../src/render.ts"],"sourcesContent":["import { cloneElement, createElement, Fragment, type ReactElement, type ReactNode } from 'react';\nimport {\n normalizeLink,\n parseTags,\n RICH_TAGS,\n VOID_TAGS,\n type Params,\n type RichLink,\n type TagNode,\n type Verbaly,\n} from 'verbaly';\n\n// everything a <Trans> takes besides its message: one contract for the client and the server\nexport interface TransOptions {\n values?: Params;\n instance?: Verbaly;\n components?: Record<string, ReactElement>;\n richTags?: string[];\n links?: Record<string, RichLink>;\n}\n\n// an id at runtime; children in the source, which the compiler turns into an id and its props\nexport type TransProps = TransOptions &\n ({ id: string; children?: undefined } | { id?: undefined; children: ReactNode });\n\n// no hook and no context in here, so a Server Component renders it as well as a client one\nexport function renderTrans(instance: Verbaly, props: TransProps): ReactElement {\n // never compiled (no plugin, or a file outside include): the source text, like an uncompiled t`…`\n if (props.id === undefined) return createElement(Fragment, null, props.children);\n const text = (instance.t as unknown as (id: string, values?: Params) => string)(\n props.id,\n props.values,\n );\n return createElement(\n Fragment,\n null,\n ...toNodes(\n parseTags(text),\n props.components ?? {},\n props.links ?? {},\n new Set(props.richTags ?? RICH_TAGS),\n ),\n );\n}\n\nconst VOID = new Set(VOID_TAGS);\n\n// own entries only: a tag named constructor in a message must never find the one on Object\nfunction own<T>(map: Record<string, T>, name: string): T | undefined {\n return Object.prototype.hasOwnProperty.call(map, name) ? map[name] : undefined;\n}\n\nfunction toNodes(\n nodes: TagNode[],\n components: Record<string, ReactElement>,\n links: Record<string, RichLink>,\n richTags: Set<string>,\n): ReactNode[] {\n return nodes.map((node, i) => {\n if (typeof node === 'string') return node;\n const children = toNodes(node.children, components, links, richTags);\n const el = own(components, node.name);\n if (el) return cloneElement(el, { key: i }, ...children);\n const link = own(links, node.name);\n if (link !== undefined) {\n return createElement('a', { key: i, ...normalizeLink(link) }, ...children);\n }\n if (richTags.has(node.name)) {\n if (VOID.has(node.name)) return createElement(node.name, { key: i });\n return createElement(node.name, { key: i }, ...children);\n }\n return createElement(Fragment, { key: i }, ...children);\n });\n}\n"],"mappings":";;;AA0BA,SAAgB,YAAY,UAAmB,OAAiC;CAE9E,IAAI,MAAM,OAAO,KAAA,GAAW,OAAO,cAAc,UAAU,MAAM,MAAM,QAAQ;CAC/E,MAAM,OAAQ,SAAS,EACrB,MAAM,IACN,MAAM,MACR;CACA,OAAO,cACL,UACA,MACA,GAAG,QACD,UAAU,IAAI,GACd,MAAM,cAAc,CAAC,GACrB,MAAM,SAAS,CAAC,GAChB,IAAI,IAAI,MAAM,YAAY,SAAS,CACrC,CACF;AACF;AAEA,MAAM,OAAO,IAAI,IAAI,SAAS;AAG9B,SAAS,IAAO,KAAwB,MAA6B;CACnE,OAAO,OAAO,UAAU,eAAe,KAAK,KAAK,IAAI,IAAI,IAAI,QAAQ,KAAA;AACvE;AAEA,SAAS,QACP,OACA,YACA,OACA,UACa;CACb,OAAO,MAAM,KAAK,MAAM,MAAM;EAC5B,IAAI,OAAO,SAAS,UAAU,OAAO;EACrC,MAAM,WAAW,QAAQ,KAAK,UAAU,YAAY,OAAO,QAAQ;EACnE,MAAM,KAAK,IAAI,YAAY,KAAK,IAAI;EACpC,IAAI,IAAI,OAAO,aAAa,IAAI,EAAE,KAAK,EAAE,GAAG,GAAG,QAAQ;EACvD,MAAM,OAAO,IAAI,OAAO,KAAK,IAAI;EACjC,IAAI,SAAS,KAAA,GACX,OAAO,cAAc,KAAK;GAAE,KAAK;GAAG,GAAG,cAAc,IAAI;EAAE,GAAG,GAAG,QAAQ;EAE3E,IAAI,SAAS,IAAI,KAAK,IAAI,GAAG;GAC3B,IAAI,KAAK,IAAI,KAAK,IAAI,GAAG,OAAO,cAAc,KAAK,MAAM,EAAE,KAAK,EAAE,CAAC;GACnE,OAAO,cAAc,KAAK,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,QAAQ;EACzD;EACA,OAAO,cAAc,UAAU,EAAE,KAAK,EAAE,GAAG,GAAG,QAAQ;CACxD,CAAC;AACH"}
@@ -0,0 +1,21 @@
1
+ import { ReactElement, ReactNode } from "react";
2
+ import { Params, RichLink, Verbaly } from "verbaly";
3
+ //#region src/render.d.ts
4
+ interface TransOptions {
5
+ values?: Params;
6
+ instance?: Verbaly;
7
+ components?: Record<string, ReactElement>;
8
+ richTags?: string[];
9
+ links?: Record<string, RichLink>;
10
+ }
11
+ type TransProps = TransOptions & ({
12
+ id: string;
13
+ children?: undefined;
14
+ } | {
15
+ id?: undefined;
16
+ children: ReactNode;
17
+ });
18
+ declare function renderTrans(instance: Verbaly, props: TransProps): ReactElement;
19
+ //#endregion
20
+ export { TransProps as n, renderTrans as r, TransOptions as t };
21
+ //# sourceMappingURL=render-D1J3Qbqg.d.cts.map
@@ -0,0 +1,21 @@
1
+ import { ReactElement, ReactNode } from "react";
2
+ import { Params, RichLink, Verbaly } from "verbaly";
3
+ //#region src/render.d.ts
4
+ interface TransOptions {
5
+ values?: Params;
6
+ instance?: Verbaly;
7
+ components?: Record<string, ReactElement>;
8
+ richTags?: string[];
9
+ links?: Record<string, RichLink>;
10
+ }
11
+ type TransProps = TransOptions & ({
12
+ id: string;
13
+ children?: undefined;
14
+ } | {
15
+ id?: undefined;
16
+ children: ReactNode;
17
+ });
18
+ declare function renderTrans(instance: Verbaly, props: TransProps): ReactElement;
19
+ //#endregion
20
+ export { TransProps as n, renderTrans as r, TransOptions as t };
21
+ //# sourceMappingURL=render-D1J3Qbqg.d.ts.map
@@ -0,0 +1,11 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_render = require("./render-CY-uLpA6.cjs");
3
+ //#region src/server.ts
4
+ function Trans(props) {
5
+ return require_render.renderTrans(props.instance, props);
6
+ }
7
+ //#endregion
8
+ exports.Trans = Trans;
9
+ exports.renderTrans = require_render.renderTrans;
10
+
11
+ //# sourceMappingURL=server.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.cjs","names":["renderTrans"],"sources":["../src/server.ts"],"sourcesContent":["import type { ReactElement } from 'react';\nimport type { Verbaly } from 'verbaly';\nimport { renderTrans, type TransProps } from './render';\n\nexport { renderTrans } from './render';\nexport type { TransOptions, TransProps } from './render';\n\n// a Server Component has no provider to read and no hooks to call, so the instance is a prop\nexport function Trans(props: TransProps & { instance: Verbaly }): ReactElement {\n return renderTrans(props.instance, props);\n}\n"],"mappings":";;;AAQA,SAAgB,MAAM,OAAyD;CAC7E,OAAOA,eAAAA,YAAY,MAAM,UAAU,KAAK;AAC1C"}
@@ -0,0 +1,10 @@
1
+ import { n as TransProps, r as renderTrans, t as TransOptions } from "./render-D1J3Qbqg.cjs";
2
+ import { ReactElement } from "react";
3
+ import { Verbaly } from "verbaly";
4
+ //#region src/server.d.ts
5
+ export declare function Trans(props: TransProps & {
6
+ instance: Verbaly;
7
+ }): ReactElement;
8
+ //#endregion
9
+ export { type TransOptions, type TransProps, renderTrans };
10
+ //# sourceMappingURL=server.d.cts.map
@@ -0,0 +1,10 @@
1
+ import { n as TransProps, r as renderTrans, t as TransOptions } from "./render-D1J3Qbqg.js";
2
+ import { ReactElement } from "react";
3
+ import { Verbaly } from "verbaly";
4
+ //#region src/server.d.ts
5
+ export declare function Trans(props: TransProps & {
6
+ instance: Verbaly;
7
+ }): ReactElement;
8
+ //#endregion
9
+ export { type TransOptions, type TransProps, renderTrans };
10
+ //# sourceMappingURL=server.d.ts.map
package/dist/server.js ADDED
@@ -0,0 +1,9 @@
1
+ import { t as renderTrans } from "./render-CyRz_srQ.js";
2
+ //#region src/server.ts
3
+ function Trans(props) {
4
+ return renderTrans(props.instance, props);
5
+ }
6
+ //#endregion
7
+ export { Trans, renderTrans };
8
+
9
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","names":[],"sources":["../src/server.ts"],"sourcesContent":["import type { ReactElement } from 'react';\nimport type { Verbaly } from 'verbaly';\nimport { renderTrans, type TransProps } from './render';\n\nexport { renderTrans } from './render';\nexport type { TransOptions, TransProps } from './render';\n\n// a Server Component has no provider to read and no hooks to call, so the instance is a prop\nexport function Trans(props: TransProps & { instance: Verbaly }): ReactElement {\n return renderTrans(props.instance, props);\n}\n"],"mappings":";;AAQA,SAAgB,MAAM,OAAyD;CAC7E,OAAO,YAAY,MAAM,UAAU,KAAK;AAC1C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verbaly/react",
3
- "version": "0.68.0",
3
+ "version": "0.69.1",
4
4
  "description": "React bindings for Verbaly: hooks over the reactive core.",
5
5
  "keywords": [
6
6
  "i18n",
@@ -33,6 +33,16 @@
33
33
  "types": "./dist/index.d.cts",
34
34
  "default": "./dist/index.cjs"
35
35
  }
36
+ },
37
+ "./server": {
38
+ "import": {
39
+ "types": "./dist/server.d.ts",
40
+ "default": "./dist/server.js"
41
+ },
42
+ "require": {
43
+ "types": "./dist/server.d.cts",
44
+ "default": "./dist/server.cjs"
45
+ }
36
46
  }
37
47
  },
38
48
  "files": [
@@ -48,7 +58,7 @@
48
58
  },
49
59
  "peerDependencies": {
50
60
  "react": "^18.0.0 || ^19.0.0",
51
- "verbaly": "^0.68.0"
61
+ "verbaly": "^0.69.1"
52
62
  },
53
63
  "devDependencies": {
54
64
  "@types/react": "^19.3.0",
@@ -58,12 +68,12 @@
58
68
  "preact-render-to-string": "^6.8.0",
59
69
  "react": "^19.3.0",
60
70
  "react-dom": "^19.3.0",
61
- "verbaly": "^0.68.0"
71
+ "verbaly": "^0.69.1"
62
72
  },
63
73
  "scripts": {
64
74
  "build": "tsdown",
65
75
  "dev": "tsdown --watch",
66
- "test": "vitest run --passWithNoTests && vitest run --config vitest.preact.config.ts",
76
+ "test": "vitest run --passWithNoTests && vitest run --config vitest.preact.config.ts && vitest run --config vitest.rsc.config.ts",
67
77
  "typecheck": "tsc --noEmit"
68
78
  }
69
79
  }