solid-intlayer 9.8.5 → 9.9.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/cjs/client/contentProxy.cjs +1 -0
- package/dist/cjs/client/useDictionary.cjs +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +1 -1
- package/dist/cjs/client/useIntlayer.cjs +1 -1
- package/dist/esm/client/contentProxy.mjs +17 -0
- package/dist/esm/client/useDictionary.mjs +22 -28
- package/dist/esm/client/useDictionaryAsync.mjs +5 -4
- package/dist/esm/client/useDictionaryDynamic.mjs +44 -67
- package/dist/esm/client/useIntlayer.mjs +13 -19
- package/dist/solid/client/contentProxy.js +31 -0
- package/dist/solid/client/useDictionary.js +2 -8
- package/dist/solid/client/useDictionaryAsync.js +2 -1
- package/dist/solid/client/useDictionaryDynamic.js +56 -80
- package/dist/solid/client/useIntlayer.js +2 -8
- package/dist/types/client/contentProxy.d.ts +15 -0
- package/dist/types/client/useDictionaryDynamic.d.ts +4 -5
- package/package.json +7 -7
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=e=>new Proxy(e,{get(e,t){let n=e();if(n==null)return;let r=Reflect.get(Object(n),t);return typeof r==`function`&&!Object.hasOwn(n,t)?r.bind(n):r},has(e,t){let n=e();return typeof n==`object`&&!!n&&t in n},apply(e){return e()}});exports.createContentProxy=e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../getDictionary.cjs"),t=require("../plugins.cjs"),n=require("./
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../getDictionary.cjs"),t=require("../plugins.cjs"),n=require("./contentProxy.cjs"),r=require("./IntlayerProvider.cjs"),i=require("./useLoadDynamic.cjs");let a=require("@intlayer/core/interpreter"),o=require("solid-js"),s=require("@intlayer/core/dictionaryManipulator");var c=(c,l)=>{let u=(0,o.useContext)(r.IntlayerClientContext)??{},d=new Map,f=e=>{let n=t.getPlugins(e),r=d.get(n);return r||(r=[...n],d.set(n,r)),r},p=()=>{let t=u?.locale?.(),n=i.unwrapLoadable(c)??c;return process.env.INTLAYER_DICTIONARY_SELECTOR===`false`?e.getDictionary(n,l??t,f):e.getDictionary(n,(0,s.resolveDictionaryArgument)({localeOrSelector:l,contextLocale:t,contextVariant:u?.variant?.(),dictionaryKey:c.key}),f)},m=(0,o.createMemo)(()=>{let{result:e,writes:t}=(0,a.collectTransformCacheWrites)(p);return t.length>0&&(0,o.onCleanup)(()=>(0,a.deleteTransformCacheWrites)(t)),e});return n.createContentProxy(m)};exports.useDictionary=c;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./IntlayerProvider.cjs"),t=require("./useDictionary.cjs");let n=require("@intlayer/core/interpreter"),r=require("solid-js");var
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./IntlayerProvider.cjs"),t=require("./useDictionary.cjs");let n=require("@intlayer/core/interpreter"),r=require("solid-js"),i=require("@intlayer/core/dictionaryManipulator");var a=async(a,o)=>{let{locale:s}=(0,r.useContext)(e.IntlayerClientContext)??{},c=o??s()??(0,n.resolveInterpreterLocale)(),l=await(0,i.loadDynamicDictionary)(a,c);return t.useDictionary(l,c)};exports.useDictionaryAsync=a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../getDictionary.cjs"),t=require("../solidCompat.cjs"),n=require("./
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../getDictionary.cjs"),t=require("../solidCompat.cjs"),n=require("./contentProxy.cjs"),r=require("./IntlayerProvider.cjs"),i=require("./useDictionary.cjs"),a=require("./useLoadDynamic.cjs");let o=require("solid-js"),s=require("@intlayer/core/dictionaryManipulator");var c=e=>e,l=(t,n)=>e.getDictionary(t,n),u=(u,d,f)=>{let p=(0,o.useContext)(r.IntlayerClientContext)??{},m=String(d),h=u,{locale:g,selector:_}=process.env.INTLAYER_DICTIONARY_SELECTOR===`false`?{locale:f,selector:void 0}:(0,s.parseDictionarySelector)(f),v=()=>(0,s.resolveDictionaryRead)({localeOrSelector:f,contextLocale:p.locale?.(),contextVariant:p.variant?.(),dictionaryKey:m}),y=()=>{let e=v(),t=process.env.INTLAYER_DICTIONARY_SELECTOR===`false`?``:(0,s.getDictionarySelectorCacheKey)({...e.selector,metadataOnly:void 0});return{...e,cacheKey:t?`${m}.${e.locale}.${t}`:`${m}.${e.locale}`}},b=(e,t)=>(0,s.resolveDynamicContentAsync)({loaderMap:h,key:m,...e,transform:t}),x=(0,s.getDynamicChunkArgument)(g,_);if(process.env.INTLAYER_DICTIONARY_SELECTOR!==`false`&&(0,s.isQualifiedDynamicLoaderMap)(h)&&h[s.QUALIFIER_DYNAMIC_TYPES_KEY].includes(`item`)&&_?.item===void 0){let r=t.createAsyncValue(v,e=>b(e,_?.metadataOnly?l:c)),i=(0,o.createMemo)(()=>{let t=r();if(!Array.isArray(t))return[];if(_?.metadataOnly)return t;let{locale:n}=v();return t.map(t=>e.getDictionary(t,n))});return t.trackAsyncValue(r),n.createContentProxy(i)}let S=y(),C=(0,s.getPreloadedDictionary)(h,S.locale);C&&a.seedDynamicValue(S,C);let w=a.useLoadDynamic(y,e=>b(e,c).then(t=>{if(t===null)throw Error(`No dynamic dictionary chunk found for key "${m}" and locale "${e.locale}".`);return t}));return i.useDictionary(w,x)};exports.useDictionaryDynamic=u;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../getIntlayer.cjs"),t=require("./IntlayerProvider.cjs");let
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../getIntlayer.cjs"),t=require("./contentProxy.cjs"),n=require("./IntlayerProvider.cjs");let r=require("solid-js"),i=require("@intlayer/core/dictionaryManipulator");var a=(a,o)=>{let s=(0,r.useContext)(n.IntlayerClientContext)??{},c=(0,r.createMemo)(()=>{let t=s?.locale?.();return process.env.INTLAYER_DICTIONARY_SELECTOR===`false`?e.getIntlayer(a,o??t):e.getIntlayer(a,(0,i.resolveDictionaryArgument)({localeOrSelector:o,contextLocale:t,contextVariant:s?.variant?.(),dictionaryKey:a}))});return t.createContentProxy(c)};exports.useIntlayer=a;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/client/contentProxy.ts
|
|
2
|
+
var e = (e) => new Proxy(e, {
|
|
3
|
+
get(e, t) {
|
|
4
|
+
let n = e();
|
|
5
|
+
if (n == null) return;
|
|
6
|
+
let r = Reflect.get(Object(n), t);
|
|
7
|
+
return typeof r == "function" && !Object.hasOwn(n, t) ? r.bind(n) : r;
|
|
8
|
+
},
|
|
9
|
+
has(e, t) {
|
|
10
|
+
let n = e();
|
|
11
|
+
return typeof n == "object" && !!n && t in n;
|
|
12
|
+
},
|
|
13
|
+
apply(e) {
|
|
14
|
+
return e();
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
export { e as createContentProxy };
|
|
@@ -1,34 +1,28 @@
|
|
|
1
1
|
import { getDictionary as e } from "../getDictionary.mjs";
|
|
2
2
|
import { getPlugins as t } from "../plugins.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import { createContentProxy as n } from "./contentProxy.mjs";
|
|
4
|
+
import { IntlayerClientContext as r } from "./IntlayerProvider.mjs";
|
|
5
|
+
import { unwrapLoadable as i } from "./useLoadDynamic.mjs";
|
|
6
|
+
import { collectTransformCacheWrites as a, deleteTransformCacheWrites as o } from "@intlayer/core/interpreter";
|
|
7
|
+
import { createMemo as s, onCleanup as c, useContext as l } from "solid-js";
|
|
8
|
+
import { resolveDictionaryArgument as u } from "@intlayer/core/dictionaryManipulator";
|
|
8
9
|
// src/client/useDictionary.ts
|
|
9
|
-
var
|
|
10
|
-
let
|
|
11
|
-
let n = t(e), r =
|
|
12
|
-
return r || (r = [...n],
|
|
13
|
-
},
|
|
14
|
-
let t =
|
|
15
|
-
return process.env.INTLAYER_DICTIONARY_SELECTOR === "false" ? e(n,
|
|
16
|
-
localeOrSelector:
|
|
10
|
+
var d = (d, f) => {
|
|
11
|
+
let p = l(r) ?? {}, m = /* @__PURE__ */ new Map(), h = (e) => {
|
|
12
|
+
let n = t(e), r = m.get(n);
|
|
13
|
+
return r || (r = [...n], m.set(n, r)), r;
|
|
14
|
+
}, g = () => {
|
|
15
|
+
let t = p?.locale?.(), n = i(d) ?? d;
|
|
16
|
+
return process.env.INTLAYER_DICTIONARY_SELECTOR === "false" ? e(n, f ?? t, h) : e(n, u({
|
|
17
|
+
localeOrSelector: f,
|
|
17
18
|
contextLocale: t,
|
|
18
|
-
contextVariant:
|
|
19
|
-
dictionaryKey:
|
|
20
|
-
}),
|
|
21
|
-
},
|
|
22
|
-
let { result: e, writes: t } =
|
|
23
|
-
return t.length > 0 &&
|
|
24
|
-
});
|
|
25
|
-
return new Proxy(g, {
|
|
26
|
-
get(e, t) {
|
|
27
|
-
return e()?.[t];
|
|
28
|
-
},
|
|
29
|
-
apply(e, t, n) {
|
|
30
|
-
return Reflect.apply(e, t, n);
|
|
31
|
-
}
|
|
19
|
+
contextVariant: p?.variant?.(),
|
|
20
|
+
dictionaryKey: d.key
|
|
21
|
+
}), h);
|
|
22
|
+
}, _ = s(() => {
|
|
23
|
+
let { result: e, writes: t } = a(g);
|
|
24
|
+
return t.length > 0 && c(() => o(t)), e;
|
|
32
25
|
});
|
|
26
|
+
return n(_);
|
|
33
27
|
};
|
|
34
|
-
export {
|
|
28
|
+
export { d as useDictionary };
|
|
@@ -2,9 +2,10 @@ import { IntlayerClientContext as e } from "./IntlayerProvider.mjs";
|
|
|
2
2
|
import { useDictionary as t } from "./useDictionary.mjs";
|
|
3
3
|
import { resolveInterpreterLocale as n } from "@intlayer/core/interpreter";
|
|
4
4
|
import { useContext as r } from "solid-js";
|
|
5
|
+
import { loadDynamicDictionary as i } from "@intlayer/core/dictionaryManipulator";
|
|
5
6
|
// src/client/useDictionaryAsync.ts
|
|
6
|
-
var
|
|
7
|
-
let { locale:
|
|
8
|
-
return t(
|
|
7
|
+
var a = async (a, o) => {
|
|
8
|
+
let { locale: s } = r(e) ?? {}, c = o ?? s() ?? n(), l = await i(a, c);
|
|
9
|
+
return t(l, c);
|
|
9
10
|
};
|
|
10
|
-
export {
|
|
11
|
+
export { a as useDictionaryAsync };
|
|
@@ -1,75 +1,52 @@
|
|
|
1
1
|
import { getDictionary as e } from "../getDictionary.mjs";
|
|
2
2
|
import { createAsyncValue as t, trackAsyncValue as n } from "../solidCompat.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import { createContentProxy as r } from "./contentProxy.mjs";
|
|
4
|
+
import { IntlayerClientContext as i } from "./IntlayerProvider.mjs";
|
|
5
|
+
import { useDictionary as a } from "./useDictionary.mjs";
|
|
6
|
+
import { seedDynamicValue as o, useLoadDynamic as s } from "./useLoadDynamic.mjs";
|
|
7
7
|
import { createMemo as c, useContext as l } from "solid-js";
|
|
8
|
-
import { QUALIFIER_DYNAMIC_TYPES_KEY as u, getDictionarySelectorCacheKey as d,
|
|
8
|
+
import { QUALIFIER_DYNAMIC_TYPES_KEY as u, getDictionarySelectorCacheKey as d, getDynamicChunkArgument as f, getPreloadedDictionary as p, isQualifiedDynamicLoaderMap as m, parseDictionarySelector as h, resolveDictionaryRead as g, resolveDynamicContentAsync as _ } from "@intlayer/core/dictionaryManipulator";
|
|
9
9
|
// src/client/useDictionaryDynamic.ts
|
|
10
|
-
var
|
|
11
|
-
let
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
cacheKey: `${S}.${e}.${d(l())}`,
|
|
24
|
-
locale: e
|
|
25
|
-
};
|
|
26
|
-
}, ({ locale: e }) => g({
|
|
27
|
-
loaderMap: _,
|
|
28
|
-
key: S,
|
|
29
|
-
locale: e,
|
|
30
|
-
selector: l(),
|
|
31
|
-
transform: (e) => e
|
|
32
|
-
}).then((e) => Array.isArray(e) ? e[0] : e));
|
|
33
|
-
return i(e, r);
|
|
34
|
-
}
|
|
35
|
-
let v = t(() => ({
|
|
36
|
-
locale: p(),
|
|
37
|
-
selector: l()
|
|
38
|
-
}), ({ locale: e, selector: t }) => g({
|
|
39
|
-
loaderMap: _,
|
|
40
|
-
key: S,
|
|
41
|
-
locale: e,
|
|
42
|
-
selector: t,
|
|
43
|
-
transform: (e) => e
|
|
44
|
-
})), C = c(() => {
|
|
45
|
-
let t = v(), n = p();
|
|
46
|
-
return Array.isArray(t) ? t.map((t) => e(t, n)) : [];
|
|
10
|
+
var v = (e) => e, y = (t, n) => e(t, n), b = (b, x, S) => {
|
|
11
|
+
let C = l(i) ?? {}, w = String(x), T = b, { locale: E, selector: D } = process.env.INTLAYER_DICTIONARY_SELECTOR === "false" ? {
|
|
12
|
+
locale: S,
|
|
13
|
+
selector: void 0
|
|
14
|
+
} : h(S), O = () => g({
|
|
15
|
+
localeOrSelector: S,
|
|
16
|
+
contextLocale: C.locale?.(),
|
|
17
|
+
contextVariant: C.variant?.(),
|
|
18
|
+
dictionaryKey: w
|
|
19
|
+
}), k = () => {
|
|
20
|
+
let e = O(), t = process.env.INTLAYER_DICTIONARY_SELECTOR === "false" ? "" : d({
|
|
21
|
+
...e.selector,
|
|
22
|
+
metadataOnly: void 0
|
|
47
23
|
});
|
|
48
|
-
return n(v), new Proxy(C, {
|
|
49
|
-
get(e, t) {
|
|
50
|
-
let n = e(), r = n?.[t];
|
|
51
|
-
return typeof r == "function" ? r.bind(n) : r;
|
|
52
|
-
},
|
|
53
|
-
has(e, t) {
|
|
54
|
-
return t in e();
|
|
55
|
-
},
|
|
56
|
-
apply(e) {
|
|
57
|
-
return e();
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
let C = _, w = y, T = () => w ?? x?.() ?? s(), E = () => {
|
|
62
|
-
let e = T();
|
|
63
24
|
return {
|
|
64
|
-
|
|
65
|
-
locale: e
|
|
25
|
+
...e,
|
|
26
|
+
cacheKey: t ? `${w}.${e.locale}.${t}` : `${w}.${e.locale}`
|
|
66
27
|
};
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
28
|
+
}, A = (e, t) => _({
|
|
29
|
+
loaderMap: T,
|
|
30
|
+
key: w,
|
|
31
|
+
...e,
|
|
32
|
+
transform: t
|
|
33
|
+
}), j = f(E, D);
|
|
34
|
+
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && m(T) && T[u].includes("item") && D?.item === void 0) {
|
|
35
|
+
let i = t(O, (e) => A(e, D?.metadataOnly ? y : v)), a = c(() => {
|
|
36
|
+
let t = i();
|
|
37
|
+
if (!Array.isArray(t)) return [];
|
|
38
|
+
if (D?.metadataOnly) return t;
|
|
39
|
+
let { locale: n } = O();
|
|
40
|
+
return t.map((t) => e(t, n));
|
|
41
|
+
});
|
|
42
|
+
return n(i), r(a);
|
|
43
|
+
}
|
|
44
|
+
let M = k(), N = p(T, M.locale);
|
|
45
|
+
N && o(M, N);
|
|
46
|
+
let P = s(k, (e) => A(e, v).then((t) => {
|
|
47
|
+
if (t === null) throw Error(`No dynamic dictionary chunk found for key "${w}" and locale "${e.locale}".`);
|
|
48
|
+
return t;
|
|
49
|
+
}));
|
|
50
|
+
return a(P, j);
|
|
74
51
|
};
|
|
75
|
-
export {
|
|
52
|
+
export { b as useDictionaryDynamic };
|
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
import { getIntlayer as e } from "../getIntlayer.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { createContentProxy as t } from "./contentProxy.mjs";
|
|
3
|
+
import { IntlayerClientContext as n } from "./IntlayerProvider.mjs";
|
|
4
|
+
import { createMemo as r, useContext as i } from "solid-js";
|
|
5
|
+
import { resolveDictionaryArgument as a } from "@intlayer/core/dictionaryManipulator";
|
|
5
6
|
// src/client/useIntlayer.ts
|
|
6
|
-
var
|
|
7
|
-
let
|
|
8
|
-
let t =
|
|
9
|
-
return process.env.INTLAYER_DICTIONARY_SELECTOR === "false" ? e(
|
|
10
|
-
localeOrSelector:
|
|
7
|
+
var o = (o, s) => {
|
|
8
|
+
let c = i(n) ?? {}, l = r(() => {
|
|
9
|
+
let t = c?.locale?.();
|
|
10
|
+
return process.env.INTLAYER_DICTIONARY_SELECTOR === "false" ? e(o, s ?? t) : e(o, a({
|
|
11
|
+
localeOrSelector: s,
|
|
11
12
|
contextLocale: t,
|
|
12
|
-
contextVariant:
|
|
13
|
-
dictionaryKey:
|
|
13
|
+
contextVariant: c?.variant?.(),
|
|
14
|
+
dictionaryKey: o
|
|
14
15
|
}));
|
|
15
16
|
});
|
|
16
|
-
return
|
|
17
|
-
get(e, t) {
|
|
18
|
-
return e()?.[t];
|
|
19
|
-
},
|
|
20
|
-
apply(e, t, n) {
|
|
21
|
-
return Reflect.apply(e, t, n);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
17
|
+
return t(l);
|
|
24
18
|
};
|
|
25
|
-
export {
|
|
19
|
+
export { o as useIntlayer };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// src/client/contentProxy.ts
|
|
2
|
+
/**
|
|
3
|
+
* Exposes reactive content through a proxy that reads `accessor` on every
|
|
4
|
+
* access, so each field read stays tracked — shared by `useDictionary`,
|
|
5
|
+
* `useIntlayer` and the dynamic collection read.
|
|
6
|
+
*
|
|
7
|
+
* Collections must behave like real arrays: Solid 2's `<For>` copies its list
|
|
8
|
+
* with `list.slice(0)`, which checks every index with `in`. Answering those
|
|
9
|
+
* checks for the function target would yield holes (`undefined` rows), so `in`
|
|
10
|
+
* is answered for the content, and inherited methods (`slice`, `map`…) run
|
|
11
|
+
* against it. Own fields are returned untouched: content nodes carry their
|
|
12
|
+
* own properties (`.value`, `.raw`) that a bound copy would lose.
|
|
13
|
+
*
|
|
14
|
+
* @param accessor - Returns the current content (a memo).
|
|
15
|
+
*/
|
|
16
|
+
var createContentProxy = (accessor) => new Proxy(accessor, {
|
|
17
|
+
get(target, property) {
|
|
18
|
+
const content = target();
|
|
19
|
+
if (content == null) return void 0;
|
|
20
|
+
const value = Reflect.get(Object(content), property);
|
|
21
|
+
return typeof value === "function" && !Object.hasOwn(content, property) ? value.bind(content) : value;
|
|
22
|
+
},
|
|
23
|
+
has(target, property) {
|
|
24
|
+
const content = target();
|
|
25
|
+
return content != null && typeof content === "object" && property in content;
|
|
26
|
+
},
|
|
27
|
+
apply(target) {
|
|
28
|
+
return target();
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
export { createContentProxy };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getDictionary as getDictionary$1 } from "../getDictionary.js";
|
|
2
2
|
import { getPlugins } from "../plugins.jsx";
|
|
3
|
+
import { createContentProxy } from "./contentProxy.js";
|
|
3
4
|
import { IntlayerClientContext } from "./IntlayerProvider.jsx";
|
|
4
5
|
import { unwrapLoadable } from "./useLoadDynamic.js";
|
|
5
6
|
import { collectTransformCacheWrites, deleteTransformCacheWrites } from "@intlayer/core/interpreter";
|
|
@@ -44,13 +45,6 @@ var useDictionary = (dictionary, localeOrSelector) => {
|
|
|
44
45
|
if (writes.length > 0) onCleanup(() => deleteTransformCacheWrites(writes));
|
|
45
46
|
return result;
|
|
46
47
|
});
|
|
47
|
-
return
|
|
48
|
-
get(target, prop) {
|
|
49
|
-
return target()?.[prop];
|
|
50
|
-
},
|
|
51
|
-
apply(target, thisArg, args) {
|
|
52
|
-
return Reflect.apply(target, thisArg, args);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
48
|
+
return createContentProxy(accessor);
|
|
55
49
|
};
|
|
56
50
|
export { useDictionary };
|
|
@@ -2,6 +2,7 @@ import { IntlayerClientContext } from "./IntlayerProvider.jsx";
|
|
|
2
2
|
import { useDictionary } from "./useDictionary.js";
|
|
3
3
|
import { resolveInterpreterLocale } from "@intlayer/core/interpreter";
|
|
4
4
|
import { useContext } from "solid-js";
|
|
5
|
+
import { loadDynamicDictionary } from "@intlayer/core/dictionaryManipulator";
|
|
5
6
|
// src/client/useDictionaryAsync.ts
|
|
6
7
|
/**
|
|
7
8
|
* On the server side, Hook that transform a dictionary and return the content
|
|
@@ -11,7 +12,7 @@ import { useContext } from "solid-js";
|
|
|
11
12
|
var useDictionaryAsync = async (dictionaryPromise, locale) => {
|
|
12
13
|
const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};
|
|
13
14
|
const localeTarget = locale ?? currentLocale() ?? resolveInterpreterLocale();
|
|
14
|
-
const dictionary = await dictionaryPromise
|
|
15
|
+
const dictionary = await loadDynamicDictionary(dictionaryPromise, localeTarget);
|
|
15
16
|
return useDictionary(dictionary, localeTarget);
|
|
16
17
|
};
|
|
17
18
|
export { useDictionaryAsync };
|
|
@@ -1,105 +1,81 @@
|
|
|
1
|
-
import { getDictionary
|
|
1
|
+
import { getDictionary } from "../getDictionary.js";
|
|
2
2
|
import { createAsyncValue, trackAsyncValue } from "../solidCompat.js";
|
|
3
|
+
import { createContentProxy } from "./contentProxy.js";
|
|
3
4
|
import { IntlayerClientContext } from "./IntlayerProvider.jsx";
|
|
4
5
|
import { useDictionary } from "./useDictionary.js";
|
|
5
6
|
import { seedDynamicValue, useLoadDynamic } from "./useLoadDynamic.js";
|
|
6
|
-
import { resolveInterpreterLocale } from "@intlayer/core/interpreter";
|
|
7
7
|
import { createMemo, useContext } from "solid-js";
|
|
8
|
-
import { QUALIFIER_DYNAMIC_TYPES_KEY, getDictionarySelectorCacheKey, getPreloadedDictionary, isQualifiedDynamicLoaderMap, parseDictionarySelector,
|
|
8
|
+
import { QUALIFIER_DYNAMIC_TYPES_KEY, getDictionarySelectorCacheKey, getDynamicChunkArgument, getPreloadedDictionary, isQualifiedDynamicLoaderMap, parseDictionarySelector, resolveDictionaryRead, resolveDynamicContentAsync } from "@intlayer/core/dictionaryManipulator";
|
|
9
9
|
// src/client/useDictionaryDynamic.ts
|
|
10
10
|
/**
|
|
11
|
+
* Loaded chunks stay raw (serializable for hydration) and are interpreted
|
|
12
|
+
* inside the component owner. A collection's metadata is plain data, resolved
|
|
13
|
+
* right away — its index holds no dictionary to interpret anyway.
|
|
14
|
+
*/
|
|
15
|
+
var keepRawChunk = (dictionary) => dictionary;
|
|
16
|
+
var readChunkMetadata = (dictionary, argument) => getDictionary(dictionary, argument);
|
|
17
|
+
/**
|
|
11
18
|
* On the client side, Hook that lazily loads a dictionary and returns its
|
|
12
19
|
* reactive content.
|
|
13
20
|
*
|
|
14
|
-
* The
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* targets are loaded; the resolution mirrors static mode.
|
|
21
|
+
* The locale, selector and chunk selection are resolved by the shared
|
|
22
|
+
* `resolveDictionaryRead` / `resolveDynamicContentAsync`; this hook only adds
|
|
23
|
+
* Solid's resources and owner-scoped interpretation.
|
|
18
24
|
*
|
|
19
25
|
* If the locale is not provided (directly or through the selector), it will
|
|
20
26
|
* use the locale from the client context.
|
|
21
27
|
*/
|
|
22
28
|
var useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector) => {
|
|
23
29
|
const context = useContext(IntlayerClientContext) ?? {};
|
|
24
|
-
const { locale: currentLocale } = context;
|
|
25
30
|
const dictionaryKey = String(key);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}), ({ locale: localeTarget, selector }) => resolveQualifiedDynamicContentAsync({
|
|
58
|
-
loaderMap: dictionaryPromise,
|
|
59
|
-
key: dictionaryKey,
|
|
60
|
-
locale: localeTarget,
|
|
61
|
-
selector,
|
|
62
|
-
transform: (dictionary) => dictionary
|
|
63
|
-
}));
|
|
31
|
+
const loaderMap = dictionaryPromise;
|
|
32
|
+
const { locale: callLocale, selector: callSelector } = process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" ? parseDictionarySelector(localeOrSelector) : {
|
|
33
|
+
locale: localeOrSelector,
|
|
34
|
+
selector: void 0
|
|
35
|
+
};
|
|
36
|
+
const readAccessor = () => resolveDictionaryRead({
|
|
37
|
+
localeOrSelector,
|
|
38
|
+
contextLocale: context.locale?.(),
|
|
39
|
+
contextVariant: context.variant?.(),
|
|
40
|
+
dictionaryKey
|
|
41
|
+
});
|
|
42
|
+
const sourceAccessor = () => {
|
|
43
|
+
const read = readAccessor();
|
|
44
|
+
const chunkSelectorId = process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" ? getDictionarySelectorCacheKey({
|
|
45
|
+
...read.selector,
|
|
46
|
+
metadataOnly: void 0
|
|
47
|
+
}) : "";
|
|
48
|
+
return {
|
|
49
|
+
...read,
|
|
50
|
+
cacheKey: chunkSelectorId ? `${dictionaryKey}.${read.locale}.${chunkSelectorId}` : `${dictionaryKey}.${read.locale}`
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
const loadContent = (read, transform) => resolveDynamicContentAsync({
|
|
54
|
+
loaderMap,
|
|
55
|
+
key: dictionaryKey,
|
|
56
|
+
...read,
|
|
57
|
+
transform
|
|
58
|
+
});
|
|
59
|
+
const chunkArgument = getDynamicChunkArgument(callLocale, callSelector);
|
|
60
|
+
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && isQualifiedDynamicLoaderMap(loaderMap) && loaderMap[QUALIFIER_DYNAMIC_TYPES_KEY].includes("item") && callSelector?.item === void 0) {
|
|
61
|
+
const resolvedEntries = createAsyncValue(readAccessor, (read) => loadContent(read, callSelector?.metadataOnly ? readChunkMetadata : keepRawChunk));
|
|
64
62
|
const accessor = createMemo(() => {
|
|
65
63
|
const resolved = resolvedEntries();
|
|
66
|
-
const localeTarget = localeAccessor();
|
|
67
64
|
if (!Array.isArray(resolved)) return [];
|
|
68
|
-
|
|
65
|
+
if (callSelector?.metadataOnly) return resolved;
|
|
66
|
+
const { locale } = readAccessor();
|
|
67
|
+
return resolved.map((dictionary) => getDictionary(dictionary, locale));
|
|
69
68
|
});
|
|
70
69
|
trackAsyncValue(resolvedEntries);
|
|
71
|
-
return
|
|
72
|
-
get(target, prop) {
|
|
73
|
-
const content = target();
|
|
74
|
-
const value = content?.[prop];
|
|
75
|
-
return typeof value === "function" ? value.bind(content) : value;
|
|
76
|
-
},
|
|
77
|
-
has(target, prop) {
|
|
78
|
-
return prop in target();
|
|
79
|
-
},
|
|
80
|
-
apply(target) {
|
|
81
|
-
return target();
|
|
82
|
-
}
|
|
83
|
-
});
|
|
70
|
+
return createContentProxy(accessor);
|
|
84
71
|
}
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
const loadDictionary = ({ locale: localeTarget }) => {
|
|
96
|
-
const dictionaryLoader = dictionaryLoaders[localeTarget];
|
|
97
|
-
if (!dictionaryLoader) return Promise.reject(/* @__PURE__ */ new Error(`No dynamic dictionary loader found for key "${dictionaryKey}" and locale "${localeTarget}".`));
|
|
98
|
-
return dictionaryLoader();
|
|
99
|
-
};
|
|
100
|
-
const preloadedDictionary = getPreloadedDictionary(dictionaryLoaders, localeAccessor());
|
|
101
|
-
if (preloadedDictionary) seedDynamicValue(dictionarySourceAccessor(), preloadedDictionary);
|
|
102
|
-
const dictionary = useLoadDynamic(dictionarySourceAccessor, loadDictionary);
|
|
103
|
-
return useDictionary(dictionary, locale);
|
|
72
|
+
const initialSource = sourceAccessor();
|
|
73
|
+
const preloadedDictionary = getPreloadedDictionary(loaderMap, initialSource.locale);
|
|
74
|
+
if (preloadedDictionary) seedDynamicValue(initialSource, preloadedDictionary);
|
|
75
|
+
const dictionary = useLoadDynamic(sourceAccessor, (source) => loadContent(source, keepRawChunk).then((resolved) => {
|
|
76
|
+
if (resolved === null) throw new Error(`No dynamic dictionary chunk found for key "${dictionaryKey}" and locale "${source.locale}".`);
|
|
77
|
+
return resolved;
|
|
78
|
+
}));
|
|
79
|
+
return useDictionary(dictionary, chunkArgument);
|
|
104
80
|
};
|
|
105
81
|
export { useDictionaryDynamic };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getIntlayer } from "../getIntlayer.js";
|
|
2
|
+
import { createContentProxy } from "./contentProxy.js";
|
|
2
3
|
import { IntlayerClientContext } from "./IntlayerProvider.jsx";
|
|
3
4
|
import { createMemo, useContext } from "solid-js";
|
|
4
5
|
import { resolveDictionaryArgument } from "@intlayer/core/dictionaryManipulator";
|
|
@@ -43,13 +44,6 @@ var useIntlayer = (key, localeOrSelector) => {
|
|
|
43
44
|
}));
|
|
44
45
|
return getIntlayer(key, localeOrSelector ?? currentLocale);
|
|
45
46
|
});
|
|
46
|
-
return
|
|
47
|
-
get(target, prop) {
|
|
48
|
-
return target()?.[prop];
|
|
49
|
-
},
|
|
50
|
-
apply(target, thisArg, args) {
|
|
51
|
-
return Reflect.apply(target, thisArg, args);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
47
|
+
return createContentProxy(accessor);
|
|
54
48
|
};
|
|
55
49
|
export { useIntlayer };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exposes reactive content through a proxy that reads `accessor` on every
|
|
3
|
+
* access, so each field read stays tracked — shared by `useDictionary`,
|
|
4
|
+
* `useIntlayer` and the dynamic collection read.
|
|
5
|
+
*
|
|
6
|
+
* Collections must behave like real arrays: Solid 2's `<For>` copies its list
|
|
7
|
+
* with `list.slice(0)`, which checks every index with `in`. Answering those
|
|
8
|
+
* checks for the function target would yield holes (`undefined` rows), so `in`
|
|
9
|
+
* is answered for the content, and inherited methods (`slice`, `map`…) run
|
|
10
|
+
* against it. Own fields are returned untouched: content nodes carry their
|
|
11
|
+
* own properties (`.value`, `.raw`) that a bound copy would lose.
|
|
12
|
+
*
|
|
13
|
+
* @param accessor - Returns the current content (a memo).
|
|
14
|
+
*/
|
|
15
|
+
export declare const createContentProxy: <Content>(accessor: () => Content) => Content;
|
|
@@ -6,12 +6,11 @@ import { DeepTransformContent } from '../plugins';
|
|
|
6
6
|
* On the client side, Hook that lazily loads a dictionary and returns its
|
|
7
7
|
* reactive content.
|
|
8
8
|
*
|
|
9
|
-
* The
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* targets are loaded; the resolution mirrors static mode.
|
|
9
|
+
* The locale, selector and chunk selection are resolved by the shared
|
|
10
|
+
* `resolveDictionaryRead` / `resolveDynamicContentAsync`; this hook only adds
|
|
11
|
+
* Solid's resources and owner-scoped interpretation.
|
|
13
12
|
*
|
|
14
13
|
* If the locale is not provided (directly or through the selector), it will
|
|
15
14
|
* use the locale from the client context.
|
|
16
15
|
*/
|
|
17
|
-
export declare const useDictionaryDynamic: <const T extends Dictionary, const K extends DictionaryKeys, const A extends LocalesValues | DictionarySelectorForKey<K> = DeclaredLocales>(dictionaryPromise: StrictModeLocaleMap<() => Promise<T>> | QualifiedDynamicLoaderMap, key: K, localeOrSelector?: A) => DeepTransformContent<T["content"]
|
|
16
|
+
export declare const useDictionaryDynamic: <const T extends Dictionary, const K extends DictionaryKeys, const A extends LocalesValues | DictionarySelectorForKey<K> = DeclaredLocales>(dictionaryPromise: StrictModeLocaleMap<() => Promise<T>> | QualifiedDynamicLoaderMap, key: K, localeOrSelector?: A) => DeepTransformContent<T["content"]>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solid-intlayer",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.9.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Easily internationalize i18n your Solid applications with type-safe multilingual content management.",
|
|
6
6
|
"keywords": [
|
|
@@ -114,11 +114,11 @@
|
|
|
114
114
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
115
115
|
},
|
|
116
116
|
"dependencies": {
|
|
117
|
-
"@intlayer/api": "9.
|
|
118
|
-
"@intlayer/config": "9.
|
|
119
|
-
"@intlayer/core": "9.
|
|
120
|
-
"@intlayer/editor": "9.
|
|
121
|
-
"@intlayer/types": "9.
|
|
117
|
+
"@intlayer/api": "9.9.0",
|
|
118
|
+
"@intlayer/config": "9.9.0",
|
|
119
|
+
"@intlayer/core": "9.9.0",
|
|
120
|
+
"@intlayer/editor": "9.9.0",
|
|
121
|
+
"@intlayer/types": "9.9.0"
|
|
122
122
|
},
|
|
123
123
|
"devDependencies": {
|
|
124
124
|
"@solidjs/testing-library": "0.8.10",
|
|
@@ -149,7 +149,7 @@
|
|
|
149
149
|
}
|
|
150
150
|
},
|
|
151
151
|
"optionalDependencies": {
|
|
152
|
-
"@intlayer/analytics": "9.
|
|
152
|
+
"@intlayer/analytics": "9.9.0"
|
|
153
153
|
},
|
|
154
154
|
"engines": {
|
|
155
155
|
"node": ">=14.18"
|