@verbaly/react 0.16.0 → 0.18.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/dist/index.cjs +4 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -10
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -34,15 +34,10 @@ function toNodes(nodes, components, links) {
|
|
|
34
34
|
const el = components[node.name];
|
|
35
35
|
if (el) return (0, react.cloneElement)(el, { key: i }, ...children);
|
|
36
36
|
const link = links[node.name];
|
|
37
|
-
if (link !== void 0) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
href: (0, verbaly.safeHref)(def.href),
|
|
42
|
-
target: def.target,
|
|
43
|
-
rel: def.rel
|
|
44
|
-
}, ...children);
|
|
45
|
-
}
|
|
37
|
+
if (link !== void 0) return (0, react.createElement)("a", {
|
|
38
|
+
key: i,
|
|
39
|
+
...(0, verbaly.normalizeLink)(link)
|
|
40
|
+
}, ...children);
|
|
46
41
|
return (0, react.createElement)(react.Fragment, { key: i }, ...children);
|
|
47
42
|
});
|
|
48
43
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["Fragment"],"sources":["../src/index.ts"],"sourcesContent":["import {\n cloneElement,\n createContext,\n createElement,\n Fragment,\n useContext,\n useSyncExternalStore,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport {\n
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["Fragment"],"sources":["../src/index.ts"],"sourcesContent":["import {\n cloneElement,\n createContext,\n createElement,\n Fragment,\n useContext,\n useSyncExternalStore,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport {\n normalizeLink,\n parseTags,\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 useVersion(instance);\n return instance.t;\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>): void {\n useSyncExternalStore(\n instance.subscribe,\n () => instance.version,\n () => instance.version,\n );\n}\n\nexport interface TransProps {\n id: string;\n values?: Params;\n components?: Record<string, ReactElement>;\n links?: Record<string, RichLink>;\n}\n\n// translated message + element interpolation\nexport function Trans(props: TransProps): ReactElement {\n const t = useT();\n const text = (t as unknown as (id: string, values?: Params) => string)(props.id, props.values);\n return createElement(\n Fragment,\n null,\n ...toNodes(parseTags(text), props.components ?? {}, props.links ?? {}),\n );\n}\n\nfunction toNodes(\n nodes: TagNode[],\n components: Record<string, ReactElement>,\n links: Record<string, RichLink>,\n): ReactNode[] {\n return nodes.map((node, i) => {\n if (typeof node === 'string') return node;\n const children = toNodes(node.children, components, links);\n const el = components[node.name];\n if (el) return cloneElement(el, { key: i }, ...children);\n const link = links[node.name];\n if (link !== undefined) {\n return createElement('a', { key: i, ...normalizeLink(link) }, ...children);\n }\n return createElement(Fragment, { key: i }, ...children);\n });\n}\n\nexport type { Params, TFunction, Verbaly };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;GAAE,KAAK;GAAG,IAAA,GAAA,QAAA,cAAA,CAAiB,IAAI;EAAE,GAAG,GAAG,QAAQ;EAE3E,QAAA,GAAA,MAAA,cAAA,CAAqBA,MAAAA,UAAU,EAAE,KAAK,EAAE,GAAG,GAAG,QAAQ;CACxD,CAAC;AACH"}
|
package/dist/index.d.cts
CHANGED
|
@@ -17,5 +17,5 @@ interface TransProps {
|
|
|
17
17
|
}
|
|
18
18
|
declare function Trans(props: TransProps): ReactElement;
|
|
19
19
|
//#endregion
|
|
20
|
-
export { Trans, TransProps, VerbalyProvider, VerbalyProviderProps, useLocale, useT, useVerbaly };
|
|
20
|
+
export { type Params, type TFunction, Trans, TransProps, type Verbaly, VerbalyProvider, VerbalyProviderProps, useLocale, useT, useVerbaly };
|
|
21
21
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -17,5 +17,5 @@ interface TransProps {
|
|
|
17
17
|
}
|
|
18
18
|
declare function Trans(props: TransProps): ReactElement;
|
|
19
19
|
//#endregion
|
|
20
|
-
export { Trans, TransProps, VerbalyProvider, VerbalyProviderProps, useLocale, useT, useVerbaly };
|
|
20
|
+
export { type Params, type TFunction, Trans, TransProps, type Verbaly, VerbalyProvider, VerbalyProviderProps, useLocale, useT, useVerbaly };
|
|
21
21
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment, cloneElement, createContext, createElement, useContext, useSyncExternalStore } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { normalizeLink, parseTags } from "verbaly";
|
|
3
3
|
//#region src/index.ts
|
|
4
4
|
const VerbalyContext = createContext(null);
|
|
5
5
|
function VerbalyProvider(props) {
|
|
@@ -33,15 +33,10 @@ function toNodes(nodes, components, links) {
|
|
|
33
33
|
const el = components[node.name];
|
|
34
34
|
if (el) return cloneElement(el, { key: i }, ...children);
|
|
35
35
|
const link = links[node.name];
|
|
36
|
-
if (link !== void 0) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
href: safeHref(def.href),
|
|
41
|
-
target: def.target,
|
|
42
|
-
rel: def.rel
|
|
43
|
-
}, ...children);
|
|
44
|
-
}
|
|
36
|
+
if (link !== void 0) return createElement("a", {
|
|
37
|
+
key: i,
|
|
38
|
+
...normalizeLink(link)
|
|
39
|
+
}, ...children);
|
|
45
40
|
return createElement(Fragment, { key: i }, ...children);
|
|
46
41
|
});
|
|
47
42
|
}
|
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 useSyncExternalStore,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport {\n
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n cloneElement,\n createContext,\n createElement,\n Fragment,\n useContext,\n useSyncExternalStore,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport {\n normalizeLink,\n parseTags,\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 useVersion(instance);\n return instance.t;\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>): void {\n useSyncExternalStore(\n instance.subscribe,\n () => instance.version,\n () => instance.version,\n );\n}\n\nexport interface TransProps {\n id: string;\n values?: Params;\n components?: Record<string, ReactElement>;\n links?: Record<string, RichLink>;\n}\n\n// translated message + element interpolation\nexport function Trans(props: TransProps): ReactElement {\n const t = useT();\n const text = (t as unknown as (id: string, values?: Params) => string)(props.id, props.values);\n return createElement(\n Fragment,\n null,\n ...toNodes(parseTags(text), props.components ?? {}, props.links ?? {}),\n );\n}\n\nfunction toNodes(\n nodes: TagNode[],\n components: Record<string, ReactElement>,\n links: Record<string, RichLink>,\n): ReactNode[] {\n return nodes.map((node, i) => {\n if (typeof node === 'string') return node;\n const children = toNodes(node.children, components, links);\n const el = components[node.name];\n if (el) return cloneElement(el, { key: i }, ...children);\n const link = links[node.name];\n if (link !== undefined) {\n return createElement('a', { key: i, ...normalizeLink(link) }, ...children);\n }\n return createElement(Fragment, { key: i }, ...children);\n });\n}\n\nexport type { Params, TFunction, Verbaly };\n"],"mappings":";;;AAqBA,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,WAAW,QAAQ;CACnB,OAAO,SAAS;AAClB;AAEA,SAAgB,YAAgD;CAC9D,MAAM,WAAW,WAAW;CAC5B,WAAW,QAAQ;CACnB,OAAO,CAAC,SAAS,QAAQ,SAAS,SAAS;AAC7C;AAEA,SAAS,WAAsC,UAA4B;CACzE,qBACE,SAAS,iBACH,SAAS,eACT,SAAS,OACjB;AACF;AAUA,SAAgB,MAAM,OAAiC;CAGrD,OAAO,cACL,UACA,MACA,GAAG,QAAQ,UALH,KACI,CAAC,CAAwD,MAAM,IAAI,MAAM,MAI7D,CAAC,GAAG,MAAM,cAAc,CAAC,GAAG,MAAM,SAAS,CAAC,CAAC,CACvE;AACF;AAEA,SAAS,QACP,OACA,YACA,OACa;CACb,OAAO,MAAM,KAAK,MAAM,MAAM;EAC5B,IAAI,OAAO,SAAS,UAAU,OAAO;EACrC,MAAM,WAAW,QAAQ,KAAK,UAAU,YAAY,KAAK;EACzD,MAAM,KAAK,WAAW,KAAK;EAC3B,IAAI,IAAI,OAAO,aAAa,IAAI,EAAE,KAAK,EAAE,GAAG,GAAG,QAAQ;EACvD,MAAM,OAAO,MAAM,KAAK;EACxB,IAAI,SAAS,KAAA,GACX,OAAO,cAAc,KAAK;GAAE,KAAK;GAAG,GAAG,cAAc,IAAI;EAAE,GAAG,GAAG,QAAQ;EAE3E,OAAO,cAAc,UAAU,EAAE,KAAK,EAAE,GAAG,GAAG,QAAQ;CACxD,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verbaly/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "React bindings for Verbaly — hooks over the reactive core.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"react": "^18.0.0 || ^19.0.0",
|
|
51
|
-
"verbaly": "^0.
|
|
51
|
+
"verbaly": "^0.18.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@types/react": "^19.2.17",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"happy-dom": "^20.10.6",
|
|
57
57
|
"react": "^19.2.7",
|
|
58
58
|
"react-dom": "^19.2.7",
|
|
59
|
-
"verbaly": "0.
|
|
59
|
+
"verbaly": "0.18.0"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "tsdown",
|