lit-intlayer 8.4.10 → 8.5.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/IntlayerBinding.cjs +1 -0
- package/dist/cjs/client/index.cjs +1 -1
- package/dist/cjs/client/installIntlayer.cjs +1 -1
- package/dist/cjs/client/useDictionary.cjs +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +1 -0
- package/dist/cjs/client/useIntlayer.cjs +1 -1
- package/dist/cjs/client/useLocale.cjs +1 -1
- package/dist/cjs/client/useRewriteURL.cjs +1 -1
- package/dist/cjs/editor/useEditor.cjs +1 -1
- package/dist/cjs/format/useIntl.cjs +1 -1
- package/dist/cjs/html/HTMLRenderer.cjs +1 -1
- package/dist/cjs/html/index.cjs +1 -1
- package/dist/cjs/html/installIntlayerHTML.cjs +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +1 -1
- package/dist/cjs/markdown/index.cjs +1 -1
- package/dist/cjs/markdown/installIntlayerMarkdown.cjs +1 -1
- package/dist/cjs/markdown/runtime.cjs +1 -1
- package/dist/cjs/plugins.cjs +1 -1
- package/dist/cjs/renderIntlayerNode.cjs +1 -1
- package/dist/esm/client/IntlayerBinding.mjs +21 -0
- package/dist/esm/client/index.mjs +9 -7
- package/dist/esm/client/installIntlayer.mjs +2 -25
- package/dist/esm/client/useDictionary.mjs +15 -39
- package/dist/esm/client/useDictionaryDynamic.mjs +47 -0
- package/dist/esm/client/useIntlayer.mjs +13 -40
- package/dist/esm/client/useLocale.mjs +1 -1
- package/dist/esm/client/useRewriteURL.mjs +1 -1
- package/dist/esm/editor/useEditor.mjs +2 -33
- package/dist/esm/format/useIntl.mjs +1 -1
- package/dist/esm/html/HTMLRenderer.mjs +4 -4
- package/dist/esm/html/index.mjs +3 -3
- package/dist/esm/html/installIntlayerHTML.mjs +2 -2
- package/dist/esm/index.mjs +10 -17
- package/dist/esm/markdown/MarkdownRenderer.mjs +5 -5
- package/dist/esm/markdown/index.mjs +4 -5
- package/dist/esm/markdown/installIntlayerMarkdown.mjs +2 -2
- package/dist/esm/markdown/runtime.mjs +1 -1
- package/dist/esm/plugins.mjs +66 -57
- package/dist/esm/renderIntlayerNode.mjs +1 -0
- package/dist/installIntlayer-3Fpy-rFd.mjs +71 -0
- package/dist/installIntlayer-CkFmSJJA.js +1 -0
- package/dist/types/client/IntlayerBinding.d.ts +40 -0
- package/dist/types/{src/client → client}/index.d.ts +2 -0
- package/dist/types/{src/client → client}/installIntlayer.d.ts +17 -1
- package/dist/types/client/useDictionary.d.ts +31 -0
- package/dist/types/client/useDictionaryDynamic.d.ts +36 -0
- package/dist/types/client/useIntlayer.d.ts +22 -0
- package/dist/types/editor/useEditor.d.ts +34 -0
- package/dist/types/html/index.d.ts +3 -0
- package/dist/types/{src/html → html}/installIntlayerHTML.d.ts +25 -0
- package/dist/types/{src/index.d.ts → index.d.ts} +0 -2
- package/dist/types/markdown/index.d.ts +3 -0
- package/dist/types/{src/markdown → markdown}/installIntlayerMarkdown.d.ts +25 -1
- package/dist/types/{src/plugins.d.ts → plugins.d.ts} +7 -5
- package/package.json +22 -14
- package/dist/types/src/client/useDictionary.d.ts +0 -30
- package/dist/types/src/client/useIntlayer.d.ts +0 -29
- package/dist/types/src/editor/useEditor.d.ts +0 -22
- package/dist/types/src/html/index.d.ts +0 -3
- package/dist/types/src/markdown/index.d.ts +0 -4
- /package/dist/types/{src/client → client}/useLocale.d.ts +0 -0
- /package/dist/types/{src/client → client}/useLocaleStorage.d.ts +0 -0
- /package/dist/types/{src/client → client}/useRewriteURL.d.ts +0 -0
- /package/dist/types/{src/format → format}/index.d.ts +0 -0
- /package/dist/types/{src/format → format}/useIntl.d.ts +0 -0
- /package/dist/types/{src/getDictionary.d.ts → getDictionary.d.ts} +0 -0
- /package/dist/types/{src/getIntlayer.d.ts → getIntlayer.d.ts} +0 -0
- /package/dist/types/{src/html → html}/HTMLRenderer.d.ts +0 -0
- /package/dist/types/{src/html → html}/types.d.ts +0 -0
- /package/dist/types/{src/markdown → markdown}/MarkdownRenderer.d.ts +0 -0
- /package/dist/types/{src/markdown → markdown}/compiler.d.ts +0 -0
- /package/dist/types/{src/markdown → markdown}/runtime.d.ts +0 -0
- /package/dist/types/{src/renderIntlayerNode.d.ts → renderIntlayerNode.d.ts} +0 -0
|
@@ -14,7 +14,7 @@ var e = new Set([
|
|
|
14
14
|
"source",
|
|
15
15
|
"track",
|
|
16
16
|
"wbr"
|
|
17
|
-
]), t = (e) => e ? Object.entries(e).filter(([,
|
|
17
|
+
]), t = (e) => e ? Object.entries(e).filter(([e, t]) => t != null && e !== "key").map(([e, t]) => typeof t == "boolean" ? t ? e : "" : e === "_innerHTML" ? "" : `${e}="${String(t).replace(/&/g, "&").replace(/"/g, """)}"`).filter(Boolean).join(" ") : "", n = "__lit_fragment__", r = {
|
|
18
18
|
createElement: (r, i, ...a) => {
|
|
19
19
|
let o = a.flat(Infinity).join("");
|
|
20
20
|
if (r === n) return o;
|
package/dist/esm/plugins.mjs
CHANGED
|
@@ -1,22 +1,38 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import c from "@intlayer/
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import e from "./markdown/runtime.mjs";
|
|
2
|
+
import { renderIntlayerNode as t } from "./renderIntlayerNode.mjs";
|
|
3
|
+
import { conditionPlugin as n, enumerationPlugin as r, filePlugin as i, genderPlugin as a, nestedPlugin as o, splitInsertionTemplate as s, translationPlugin as c } from "@intlayer/core/interpreter";
|
|
4
|
+
import l from "@intlayer/config/built";
|
|
5
|
+
import { compileWithOptions as u, getMarkdownMetadata as d } from "@intlayer/core/markdown";
|
|
6
|
+
import { isEnabled as f } from "@intlayer/editor/isEnabled";
|
|
7
|
+
import * as p from "@intlayer/types/nodeType";
|
|
8
|
+
import { unsafeHTML as m } from "lit/directives/unsafe-html.js";
|
|
6
9
|
//#region src/plugins.ts
|
|
7
|
-
var
|
|
10
|
+
var h = (t = "", n = {}) => u(t, e, n), g = (e, t = e, n = {}) => {
|
|
11
|
+
let r = m(e);
|
|
12
|
+
return new Proxy(r, { get(e, r, i) {
|
|
13
|
+
if (r === "value" || r === "raw") return t;
|
|
14
|
+
if (r === "toString" || r === Symbol.toPrimitive) return () => t;
|
|
15
|
+
if (r !== Symbol.iterator) return r === "__update" ? () => {} : Object.hasOwn(n, r) ? n[r] : Reflect.get(e, r, i);
|
|
16
|
+
} });
|
|
17
|
+
}, _ = (e) => e.replace(/&/g, "&").replace(/"/g, """), v = (e) => e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"), y = {
|
|
8
18
|
id: "intlayer-node-plugin",
|
|
9
19
|
canHandle: (e) => typeof e == "bigint" || typeof e == "string" || typeof e == "number",
|
|
10
|
-
transform: (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
20
|
+
transform: (e, { children: n, keyPath: r, dictionaryKey: i, ...a }) => {
|
|
21
|
+
if (f) {
|
|
22
|
+
let e = String(n ?? "");
|
|
23
|
+
return g(`<intlayer-content-selector-wrapper key-path="${_(JSON.stringify(r ?? []))}" dictionary-key="${_(String(i ?? ""))}">${v(e)}</intlayer-content-selector-wrapper>`, e);
|
|
24
|
+
}
|
|
25
|
+
return t({
|
|
26
|
+
...a,
|
|
27
|
+
value: n,
|
|
28
|
+
children: n
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}, b = {
|
|
16
32
|
id: "insertion-plugin",
|
|
17
|
-
canHandle: (e) => typeof e == "object" && e?.nodeType ===
|
|
33
|
+
canHandle: (e) => typeof e == "object" && e?.nodeType === p.INSERTION,
|
|
18
34
|
transform: (e, t, n) => {
|
|
19
|
-
let r = [...t.keyPath, { type:
|
|
35
|
+
let r = [...t.keyPath, { type: p.INSERTION }], i = e[p.INSERTION], a = {
|
|
20
36
|
id: "insertion-string-plugin",
|
|
21
37
|
canHandle: (e) => typeof e == "string",
|
|
22
38
|
transform: (e, n, r) => {
|
|
@@ -26,84 +42,77 @@ var d = {
|
|
|
26
42
|
plugins: (t.plugins ?? []).filter((e) => e.id !== "intlayer-node-plugin")
|
|
27
43
|
});
|
|
28
44
|
return (e) => {
|
|
29
|
-
let a =
|
|
30
|
-
return r(
|
|
45
|
+
let a = s(i, e), o = a.isSimple ? a.parts : a.parts.join("");
|
|
46
|
+
return r(o, {
|
|
31
47
|
...n,
|
|
32
48
|
plugins: t.plugins,
|
|
33
|
-
children:
|
|
49
|
+
children: o
|
|
34
50
|
});
|
|
35
51
|
};
|
|
36
52
|
}
|
|
37
|
-
}
|
|
38
|
-
return n(i, {
|
|
53
|
+
}, o = n(i, {
|
|
39
54
|
...t,
|
|
40
55
|
children: i,
|
|
41
56
|
keyPath: r,
|
|
42
57
|
plugins: [a, ...t.plugins ?? []]
|
|
43
58
|
});
|
|
59
|
+
return typeof i == "object" && i && "nodeType" in i && [p.ENUMERATION, p.CONDITION].includes(i.nodeType) ? (e) => (t) => {
|
|
60
|
+
let n = o(t);
|
|
61
|
+
return typeof n == "function" ? n(e) : n;
|
|
62
|
+
} : o;
|
|
44
63
|
}
|
|
45
|
-
},
|
|
64
|
+
}, x = {
|
|
46
65
|
id: "markdown-string-plugin",
|
|
47
66
|
canHandle: (e) => typeof e == "string",
|
|
48
|
-
transform: (
|
|
49
|
-
let { plugins: i, ...a } = n, o = r(
|
|
67
|
+
transform: (e, n, r) => {
|
|
68
|
+
let { plugins: i, ...a } = n, o = r(d(e) ?? {}, {
|
|
50
69
|
plugins: [{
|
|
51
70
|
id: "markdown-metadata-plugin",
|
|
52
71
|
canHandle: (e) => typeof e == "string" || typeof e == "number" || typeof e == "boolean" || !e,
|
|
53
|
-
transform: (n, r) =>
|
|
72
|
+
transform: (n, r) => t({
|
|
54
73
|
...r,
|
|
55
74
|
value: n,
|
|
56
|
-
children:
|
|
75
|
+
children: e
|
|
57
76
|
})
|
|
58
77
|
}],
|
|
59
78
|
dictionaryKey: a.dictionaryKey,
|
|
60
79
|
keyPath: []
|
|
61
|
-
});
|
|
62
|
-
return e
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
children: t,
|
|
66
|
-
additionalProps: {
|
|
67
|
-
metadata: o,
|
|
68
|
-
use: (e) => t
|
|
69
|
-
}
|
|
80
|
+
}), s = h(e);
|
|
81
|
+
return g(s, e, {
|
|
82
|
+
metadata: o,
|
|
83
|
+
use: (e) => s
|
|
70
84
|
});
|
|
71
85
|
}
|
|
72
|
-
},
|
|
86
|
+
}, S = {
|
|
73
87
|
id: "markdown-plugin",
|
|
74
|
-
canHandle: (e) => typeof e == "object" && e?.nodeType ===
|
|
88
|
+
canHandle: (e) => typeof e == "object" && e?.nodeType === p.MARKDOWN,
|
|
75
89
|
transform: (e, t, n) => {
|
|
76
|
-
let r = [...t.keyPath, { type:
|
|
90
|
+
let r = [...t.keyPath, { type: p.MARKDOWN }], i = e[p.MARKDOWN];
|
|
77
91
|
return n(i, {
|
|
78
92
|
...t,
|
|
79
93
|
children: i,
|
|
80
94
|
keyPath: r,
|
|
81
|
-
plugins: [
|
|
95
|
+
plugins: [x, ...t.plugins ?? []]
|
|
82
96
|
});
|
|
83
97
|
}
|
|
84
|
-
},
|
|
98
|
+
}, C = {
|
|
85
99
|
id: "html-plugin",
|
|
86
|
-
canHandle: (e) => typeof e == "object" && e?.nodeType ===
|
|
87
|
-
transform: (
|
|
88
|
-
let
|
|
89
|
-
return
|
|
90
|
-
...n,
|
|
91
|
-
value: r,
|
|
92
|
-
children: r,
|
|
93
|
-
additionalProps: { use: (e) => r }
|
|
94
|
-
});
|
|
100
|
+
canHandle: (e) => typeof e == "object" && e?.nodeType === p.HTML,
|
|
101
|
+
transform: (e) => {
|
|
102
|
+
let t = e[p.HTML];
|
|
103
|
+
return g(t, t, { use: (e) => t });
|
|
95
104
|
}
|
|
96
|
-
},
|
|
97
|
-
|
|
98
|
-
n,
|
|
99
|
-
t,
|
|
100
|
-
a(e ?? c.internationalization.defaultLocale),
|
|
105
|
+
}, w = (e, t = !0) => [
|
|
106
|
+
c(e ?? l.internationalization.defaultLocale, t ? l.internationalization.defaultLocale : void 0),
|
|
101
107
|
r,
|
|
108
|
+
n,
|
|
109
|
+
o(e ?? l.internationalization.defaultLocale),
|
|
102
110
|
i,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
111
|
+
a,
|
|
112
|
+
y,
|
|
113
|
+
b,
|
|
114
|
+
S,
|
|
115
|
+
C
|
|
107
116
|
];
|
|
108
117
|
//#endregion
|
|
109
|
-
export {
|
|
118
|
+
export { w as getPlugins, C as htmlPlugin, b as insertionPlugin, y as intlayerNodePlugins, S as markdownPlugin, x as markdownStringPlugin };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import e from "@intlayer/config/built";
|
|
2
|
+
import { isEnabled as t } from "@intlayer/editor/isEnabled";
|
|
3
|
+
//#region src/editor/useEditor.ts
|
|
4
|
+
var n = class {
|
|
5
|
+
host;
|
|
6
|
+
_stopped = !1;
|
|
7
|
+
_unsubscribeLocale = null;
|
|
8
|
+
constructor(e) {
|
|
9
|
+
this.host = e, e.addController(this);
|
|
10
|
+
}
|
|
11
|
+
hostConnected() {
|
|
12
|
+
this._stopped = !1, t && import("@intlayer/editor").then(({ initEditorClient: e }) => {
|
|
13
|
+
if (this._stopped) return;
|
|
14
|
+
let t = e(), n = s();
|
|
15
|
+
t.currentLocale.set(n.locale), this._unsubscribeLocale = n.subscribe((e) => {
|
|
16
|
+
t.currentLocale.set(e);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
hostDisconnected() {
|
|
21
|
+
this._stopped = !0, this._unsubscribeLocale?.(), this._unsubscribeLocale = null, import("@intlayer/editor").then(({ stopEditorClient: e }) => {
|
|
22
|
+
e();
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
function r(e) {
|
|
27
|
+
if (!t) return e ? void 0 : () => {};
|
|
28
|
+
if (!e) {
|
|
29
|
+
let e = !1, t = null;
|
|
30
|
+
return import("@intlayer/editor").then(({ initEditorClient: n }) => {
|
|
31
|
+
if (e) return;
|
|
32
|
+
let r = n(), i = s();
|
|
33
|
+
r.currentLocale.set(i.locale), t = i.subscribe((e) => {
|
|
34
|
+
r.currentLocale.set(e);
|
|
35
|
+
});
|
|
36
|
+
}), () => {
|
|
37
|
+
e = !0, t?.(), import("@intlayer/editor").then(({ stopEditorClient: e }) => {
|
|
38
|
+
e();
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
new n(e);
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/client/installIntlayer.ts
|
|
46
|
+
var i = class {
|
|
47
|
+
_locale;
|
|
48
|
+
_listeners = /* @__PURE__ */ new Set();
|
|
49
|
+
isCookieEnabled;
|
|
50
|
+
constructor(t, n = !0) {
|
|
51
|
+
let { defaultLocale: r } = e.internationalization ?? {};
|
|
52
|
+
this._locale = t ?? r, this.isCookieEnabled = n;
|
|
53
|
+
}
|
|
54
|
+
get locale() {
|
|
55
|
+
return this._locale;
|
|
56
|
+
}
|
|
57
|
+
setLocale(e) {
|
|
58
|
+
this._locale = e;
|
|
59
|
+
for (let t of this._listeners) t(e);
|
|
60
|
+
}
|
|
61
|
+
subscribe(e) {
|
|
62
|
+
return this._listeners.add(e), () => {
|
|
63
|
+
this._listeners.delete(e);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}, a = null, o = (e, t = !0) => a || (a = new i(e, t), a), s = () => (a ||= new i(), a), c = ({ locale: e, isCookieEnabled: t } = {}) => {
|
|
67
|
+
let n = o(e, t);
|
|
68
|
+
return r(), n;
|
|
69
|
+
};
|
|
70
|
+
//#endregion
|
|
71
|
+
export { r as a, c as i, o as n, s as r, i as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./chunk-C91j1N6u.js`);let t=require(`@intlayer/config/built`);t=e.t(t);let n=require(`@intlayer/editor/isEnabled`);var r=class{host;_stopped=!1;_unsubscribeLocale=null;constructor(e){this.host=e,e.addController(this)}hostConnected(){this._stopped=!1,n.isEnabled&&import(`@intlayer/editor`).then(({initEditorClient:e})=>{if(this._stopped)return;let t=e(),n=c();t.currentLocale.set(n.locale),this._unsubscribeLocale=n.subscribe(e=>{t.currentLocale.set(e)})})}hostDisconnected(){this._stopped=!0,this._unsubscribeLocale?.(),this._unsubscribeLocale=null,import(`@intlayer/editor`).then(({stopEditorClient:e})=>{e()})}};function i(e){if(!n.isEnabled)return e?void 0:()=>{};if(!e){let e=!1,t=null;return import(`@intlayer/editor`).then(({initEditorClient:n})=>{if(e)return;let r=n(),i=c();r.currentLocale.set(i.locale),t=i.subscribe(e=>{r.currentLocale.set(e)})}),()=>{e=!0,t?.(),import(`@intlayer/editor`).then(({stopEditorClient:e})=>{e()})}}new r(e)}var a=class{_locale;_listeners=new Set;isCookieEnabled;constructor(e,n=!0){let{defaultLocale:r}=t.default.internationalization??{};this._locale=e??r,this.isCookieEnabled=n}get locale(){return this._locale}setLocale(e){this._locale=e;for(let t of this._listeners)t(e)}subscribe(e){return this._listeners.add(e),()=>{this._listeners.delete(e)}}},o=null,s=(e,t=!0)=>o||(o=new a(e,t),o),c=()=>(o||=new a,o),l=({locale:e,isCookieEnabled:t}={})=>{let n=s(e,t);return i(),n};Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return a}});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
/**
|
|
3
|
+
* Proxy type returned by every `use*` hook in `lit-intlayer`.
|
|
4
|
+
*
|
|
5
|
+
* Wraps the translated content object with a reactive `.observe()` method so
|
|
6
|
+
* Lit elements participate in the reactive update cycle via a
|
|
7
|
+
* {@link IntlayerBinding} `ReactiveController`.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* private content = useIntlayer('app').observe(this);
|
|
11
|
+
* private content = useDictionary(_hash).observe(this);
|
|
12
|
+
* private content = useDictionaryDynamic(_dyn, 'app').observe(this);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export type IntlayerLitProxy<T> = T & {
|
|
16
|
+
observe: (host: ReactiveControllerHost) => IntlayerLitProxy<T>;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* `ReactiveController` that keeps a Lit element in sync with Intlayer locale
|
|
20
|
+
* changes and, optionally, async dictionary load events.
|
|
21
|
+
*
|
|
22
|
+
* Registered automatically by `.observe(this)` — you should never need to
|
|
23
|
+
* instantiate it directly.
|
|
24
|
+
*
|
|
25
|
+
* @param host - The Lit element to update.
|
|
26
|
+
* @param onConnect - Called inside `hostConnected` (after locale subscription
|
|
27
|
+
* is set up). Useful for triggering an immediate update
|
|
28
|
+
* when the dictionary is already cached.
|
|
29
|
+
* @param onDisconnect - Called inside `hostDisconnected`. Useful for removing
|
|
30
|
+
* the host from a dictionary's update-host registry.
|
|
31
|
+
*/
|
|
32
|
+
export declare class IntlayerBinding implements ReactiveController {
|
|
33
|
+
private host;
|
|
34
|
+
private unsubscribeLocale;
|
|
35
|
+
private readonly onConnect?;
|
|
36
|
+
private readonly onDisconnect?;
|
|
37
|
+
constructor(host: ReactiveControllerHost, onConnect?: () => void, onDisconnect?: () => void);
|
|
38
|
+
hostConnected(): void;
|
|
39
|
+
hostDisconnected(): void;
|
|
40
|
+
}
|
|
@@ -22,16 +22,32 @@ export declare const getIntlayerClient: () => IntlayerClient;
|
|
|
22
22
|
*
|
|
23
23
|
* Call this once at application startup before any Lit elements are rendered.
|
|
24
24
|
*
|
|
25
|
+
* When called with a `config` argument, `window.INTLAYER_CONFIG` is set so
|
|
26
|
+
* that `@intlayer/config/built` resolves the correct values in the browser
|
|
27
|
+
* without requiring module aliasing in the bundler configuration.
|
|
28
|
+
*
|
|
25
29
|
* @param locale - Initial locale (defaults to config defaultLocale).
|
|
26
30
|
* @param isCookieEnabled - Whether to persist locale in cookies/localStorage.
|
|
31
|
+
* @param config - Optional Intlayer configuration. When provided, sets
|
|
32
|
+
* `window.INTLAYER_CONFIG` with the browser-safe subset of the config so
|
|
33
|
+
* the application works without a Vite/webpack plugin alias.
|
|
27
34
|
* @returns The IntlayerClient singleton.
|
|
28
35
|
*
|
|
29
36
|
* @example
|
|
30
37
|
* ```ts
|
|
31
38
|
* import { installIntlayer } from 'lit-intlayer';
|
|
32
39
|
*
|
|
40
|
+
* // With explicit config (no build plugin alias needed):
|
|
41
|
+
* installIntlayer('en', true, {
|
|
42
|
+
* internationalization: { locales: ['en', 'fr'], defaultLocale: 'en' },
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* // With build plugin (alias handles config automatically):
|
|
33
46
|
* installIntlayer('en');
|
|
34
47
|
* ```
|
|
35
48
|
*/
|
|
36
|
-
export declare const installIntlayer: (locale
|
|
49
|
+
export declare const installIntlayer: ({ locale, isCookieEnabled, }?: {
|
|
50
|
+
locale?: LocalesValues;
|
|
51
|
+
isCookieEnabled?: boolean;
|
|
52
|
+
}) => IntlayerClient;
|
|
37
53
|
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Dictionary } from '@intlayer/types/dictionary';
|
|
2
|
+
import { DeclaredLocales, LocalesValues } from '@intlayer/types/module_augmentation';
|
|
3
|
+
import { DeepTransformContent } from '../plugins';
|
|
4
|
+
import { IntlayerLitProxy } from './IntlayerBinding';
|
|
5
|
+
/**
|
|
6
|
+
* Returns the translated content for a raw dictionary object, wrapped in an
|
|
7
|
+
* {@link IntlayerLitProxy} so the caller can subscribe to locale changes via
|
|
8
|
+
* a Lit `ReactiveController`.
|
|
9
|
+
*
|
|
10
|
+
* This is the babel-optimized counterpart of `useIntlayer` — it accepts a
|
|
11
|
+
* pre-imported dictionary object directly instead of a string key, matching
|
|
12
|
+
* the same signature as `react-intlayer` and other framework adapters.
|
|
13
|
+
*
|
|
14
|
+
* The content is resolved synchronously on every property access via a proxy,
|
|
15
|
+
* so the first render always shows the correct locale without a loading phase.
|
|
16
|
+
* Chain `.observe(this)` to register a `ReactiveController` that triggers
|
|
17
|
+
* `requestUpdate()` on every subsequent locale change.
|
|
18
|
+
*
|
|
19
|
+
* @param dictionary - The raw dictionary object (pre-imported by the build plugin).
|
|
20
|
+
* @param locale - Optional locale override.
|
|
21
|
+
* @returns An {@link IntlayerLitProxy} that exposes the current locale's content
|
|
22
|
+
* together with an `.observe()` registration method.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* // Typically injected by the babel/SWC optimization plugin:
|
|
27
|
+
* import _hash from '.intlayer/dictionaries/app.json' with { type: 'json' };
|
|
28
|
+
* private content = useDictionary(_hash).observe(this);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare const useDictionary: <T extends Dictionary, L extends LocalesValues = DeclaredLocales>(dictionary: T, locale?: L) => IntlayerLitProxy<DeepTransformContent<T["content"], L>>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Dictionary } from '@intlayer/types/dictionary';
|
|
2
|
+
import { DictionaryKeys, LocalesValues, StrictModeLocaleMap } from '@intlayer/types/module_augmentation';
|
|
3
|
+
import { DeepTransformContent } from '../plugins';
|
|
4
|
+
import { IntlayerLitProxy } from './IntlayerBinding';
|
|
5
|
+
/**
|
|
6
|
+
* Returns the translated content for a lazily-loaded dictionary, wrapped in an
|
|
7
|
+
* {@link IntlayerLitProxy} so the caller can register a Lit `ReactiveController`
|
|
8
|
+
* that keeps the element in sync with both the async bundle load and locale
|
|
9
|
+
* changes.
|
|
10
|
+
*
|
|
11
|
+
* This is the babel-optimized counterpart of `useIntlayer` when
|
|
12
|
+
* `importMode = 'dynamic'` — it accepts the locale-keyed loader map injected
|
|
13
|
+
* by the build plugin, matching the same signature as `react-intlayer` and
|
|
14
|
+
* other framework adapters.
|
|
15
|
+
*
|
|
16
|
+
* While loading, property accesses return safe empty-string placeholders via
|
|
17
|
+
* a recursive proxy. Chain `.observe(this)` so Lit triggers `requestUpdate()`
|
|
18
|
+
* once the bundle is ready and on every subsequent locale change.
|
|
19
|
+
*
|
|
20
|
+
* The `intlayerLitPlugin` Vite plugin automatically appends
|
|
21
|
+
* `.observe(this)` at build / serve time, so manual chaining is usually
|
|
22
|
+
* unnecessary.
|
|
23
|
+
*
|
|
24
|
+
* @param dictionaryPromise - Locale-keyed map of `() => Promise<Dictionary>` loaders.
|
|
25
|
+
* @param key - The dictionary key (used for cache namespacing).
|
|
26
|
+
* @param locale - Optional locale override.
|
|
27
|
+
* @returns An {@link IntlayerLitProxy} proxy with an `.observe()` method.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* // Typically injected by the babel/SWC optimization plugin:
|
|
32
|
+
* import _hash_dyn from '.intlayer/dynamic_dictionaries/app.mjs';
|
|
33
|
+
* private content = useDictionaryDynamic(_hash_dyn, 'app').observe(this);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare const useDictionaryDynamic: <T extends Dictionary, K extends DictionaryKeys, L extends LocalesValues = LocalesValues>(dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>, key: K, locale?: L) => IntlayerLitProxy<DeepTransformContent<T["content"], L>>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DictionaryKeys, DictionaryRegistryContent, LocalesValues } from '@intlayer/types/module_augmentation';
|
|
2
|
+
import { DeepTransformContent } from '../plugins';
|
|
3
|
+
import { IntlayerLitProxy } from './IntlayerBinding';
|
|
4
|
+
/**
|
|
5
|
+
* Returns the translated content for the given dictionary key, wrapped in an
|
|
6
|
+
* {@link IntlayerLitProxy} so the caller can subscribe to locale changes via
|
|
7
|
+
* a Lit `ReactiveController`.
|
|
8
|
+
*
|
|
9
|
+
* Matches the same signature as `react-intlayer` and all other framework
|
|
10
|
+
* adapters:
|
|
11
|
+
* ```ts
|
|
12
|
+
* private content = useIntlayer('my-component').observe(this);
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* The babel/SWC optimization plugin transforms this at build time into either:
|
|
16
|
+
* - static mode: `useDictionary(_hash)` — synchronous JSON import
|
|
17
|
+
* - dynamic mode: `useDictionaryDynamic(_dyn, 'key')` — lazy locale split
|
|
18
|
+
*
|
|
19
|
+
* In non-optimized builds (dev without babel) the content is re-fetched from
|
|
20
|
+
* `getIntlayer` on every property access, caching by locale.
|
|
21
|
+
*/
|
|
22
|
+
export declare const useIntlayer: <T extends DictionaryKeys>(key: T, locale?: LocalesValues) => IntlayerLitProxy<DeepTransformContent<DictionaryRegistryContent<T>>>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ReactiveControllerHost } from 'lit';
|
|
2
|
+
/**
|
|
3
|
+
* Initialises the Intlayer visual editor client.
|
|
4
|
+
*
|
|
5
|
+
* Does nothing when `INTLAYER_EDITOR_ENABLED` is `"false"` or the editor
|
|
6
|
+
* package reports that it is disabled.
|
|
7
|
+
*
|
|
8
|
+
* **Without a host** — starts the editor globally (not tied to any element
|
|
9
|
+
* lifecycle). Returns a cleanup function. Called automatically by
|
|
10
|
+
* `installIntlayer`; you only need this when you want to manage cleanup
|
|
11
|
+
* manually.
|
|
12
|
+
*
|
|
13
|
+
* **With a host** — attaches an `EditorController` to the given
|
|
14
|
+
* `ReactiveControllerHost` so the editor lifecycle follows the element's
|
|
15
|
+
* connected/disconnected callbacks.
|
|
16
|
+
*
|
|
17
|
+
* @param host - Optional LitElement (or any ReactiveControllerHost).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* // Global (called automatically by installIntlayer)
|
|
22
|
+
* const stopEditor = useEditor();
|
|
23
|
+
*
|
|
24
|
+
* // Element-scoped
|
|
25
|
+
* class AppShell extends LitElement {
|
|
26
|
+
* constructor() {
|
|
27
|
+
* super();
|
|
28
|
+
* useEditor(this);
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function useEditor(): () => void;
|
|
34
|
+
export declare function useEditor(host: ReactiveControllerHost): void;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { type RenderHTMLProps, renderHTML, useHTMLRenderer, } from './HTMLRenderer';
|
|
2
|
+
export { type IntlayerHTMLPluginOptions, type IntlayerHTMLProvider, installIntlayerHTML, installIntlayerHTMLDynamic, type RenderHTMLFunction, type RenderHTMLOptions, useHTML, } from './installIntlayerHTML';
|
|
3
|
+
export type { HTMLComponents } from './types';
|
|
@@ -38,3 +38,28 @@ export declare const installIntlayerHTML: (pluginOptions?: IntlayerHTMLPluginOpt
|
|
|
38
38
|
* provider has been installed.
|
|
39
39
|
*/
|
|
40
40
|
export declare const useHTML: () => IntlayerHTMLProvider;
|
|
41
|
+
/**
|
|
42
|
+
* Asynchronously install an HTML renderer whose implementation is loaded
|
|
43
|
+
* via a dynamic `import()`.
|
|
44
|
+
*
|
|
45
|
+
* Use this to keep a heavy HTML sanitiser / component renderer out of the
|
|
46
|
+
* initial bundle — the loader is only called the first time this function
|
|
47
|
+
* is executed.
|
|
48
|
+
*
|
|
49
|
+
* The returned promise resolves once the provider is ready. Any calls to
|
|
50
|
+
* `useHTML()` before the promise resolves will use the fallback (identity)
|
|
51
|
+
* renderer.
|
|
52
|
+
*
|
|
53
|
+
* @param loader - A zero-argument async function that resolves to either a
|
|
54
|
+
* `RenderHTMLFunction` or an `IntlayerHTMLPluginOptions` object.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* // Load a custom HTML sanitiser only when needed
|
|
59
|
+
* await installIntlayerHTMLDynamic(async () => {
|
|
60
|
+
* const DOMPurify = await import('dompurify');
|
|
61
|
+
* return (html) => DOMPurify.sanitize(html);
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare const installIntlayerHTMLDynamic: (loader: () => Promise<IntlayerHTMLPluginOptions | RenderHTMLFunction>) => Promise<IntlayerHTMLProvider>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { compileMarkdown } from './compiler';
|
|
2
|
+
export { type IntlayerMarkdownPluginOptions, type IntlayerMarkdownProvider, installIntlayerMarkdown, installIntlayerMarkdownDynamic, type MarkdownProviderOptions, type RenderMarkdownFunction, useMarkdown, } from './installIntlayerMarkdown';
|
|
3
|
+
export { type RenderMarkdownProps, renderMarkdown, useMarkdownRenderer, } from './MarkdownRenderer';
|
|
@@ -13,7 +13,7 @@ export type RenderMarkdownOptions = MarkdownProviderOptions & {
|
|
|
13
13
|
components?: HTMLComponents<'permissive', {}>;
|
|
14
14
|
wrapper?: string;
|
|
15
15
|
};
|
|
16
|
-
export type RenderMarkdownFunction = (markdown: string, options?: MarkdownProviderOptions, components?: HTMLComponents<'permissive', {}>, wrapper?: string) => string
|
|
16
|
+
export type RenderMarkdownFunction = (markdown: string, options?: MarkdownProviderOptions, components?: HTMLComponents<'permissive', {}>, wrapper?: string) => string | Promise<string>;
|
|
17
17
|
export type IntlayerMarkdownProvider = {
|
|
18
18
|
components?: HTMLComponents<'permissive', {}>;
|
|
19
19
|
renderMarkdown: RenderMarkdownFunction;
|
|
@@ -48,3 +48,27 @@ export declare const installIntlayerMarkdown: (pluginOptions?: IntlayerMarkdownP
|
|
|
48
48
|
* provider has been installed.
|
|
49
49
|
*/
|
|
50
50
|
export declare const useMarkdown: () => IntlayerMarkdownProvider;
|
|
51
|
+
/**
|
|
52
|
+
* Asynchronously install a markdown renderer whose implementation is loaded
|
|
53
|
+
* via a dynamic `import()`.
|
|
54
|
+
*
|
|
55
|
+
* Use this to keep the markdown compiler out of the initial bundle — the
|
|
56
|
+
* loader is only called the first time this function is executed.
|
|
57
|
+
*
|
|
58
|
+
* The returned promise resolves once the provider is ready. Any calls to
|
|
59
|
+
* `useMarkdown()` before the promise resolves will use the fallback
|
|
60
|
+
* (raw-string) renderer.
|
|
61
|
+
*
|
|
62
|
+
* @param loader - A zero-argument async function that resolves to either a
|
|
63
|
+
* `RenderMarkdownFunction` or an `IntlayerMarkdownPluginOptions` object.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* // Load a custom markdown renderer (e.g. marked) only when needed
|
|
68
|
+
* await installIntlayerMarkdownDynamic(async () => {
|
|
69
|
+
* const { marked } = await import('marked');
|
|
70
|
+
* return (markdown) => marked(markdown) as string;
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare const installIntlayerMarkdownDynamic: (loader: () => Promise<IntlayerMarkdownPluginOptions | RenderMarkdownFunction>) => Promise<IntlayerMarkdownProvider>;
|
|
@@ -12,18 +12,20 @@ export type IntlayerNode<T, P = {}> = IntlayerNodeCore<T> & P;
|
|
|
12
12
|
/**
|
|
13
13
|
* Wraps string/number leaf values in an IntlayerNode so they carry
|
|
14
14
|
* `.value`, `.raw`, `toString()`, and `__update()`.
|
|
15
|
+
* When the editor is enabled, wraps the content with
|
|
16
|
+
* `<intlayer-content-selector-wrapper>` so the visual editor can highlight it.
|
|
15
17
|
*/
|
|
16
18
|
export declare const intlayerNodePlugins: Plugins;
|
|
17
19
|
/** ---------------------------------------------
|
|
18
20
|
* INSERTION PLUGIN
|
|
19
21
|
* --------------------------------------------- */
|
|
20
|
-
export type InsertionCond<T, _S,
|
|
22
|
+
export type InsertionCond<T, _S, L extends LocalesValues> = T extends {
|
|
21
23
|
nodeType: NodeType | string;
|
|
22
|
-
[NodeTypes.INSERTION]:
|
|
23
|
-
fields: readonly
|
|
24
|
+
[NodeTypes.INSERTION]: infer I;
|
|
25
|
+
fields: readonly (infer F)[];
|
|
24
26
|
} ? <V extends {
|
|
25
|
-
[K in
|
|
26
|
-
}>(values: V) => IntlayerNode<string> : never;
|
|
27
|
+
[K in Extract<F, string>]: string | number;
|
|
28
|
+
}>(values: V) => I extends string ? IntlayerNode<string> : DeepTransformContent<I, L> : never;
|
|
27
29
|
export declare const insertionPlugin: Plugins;
|
|
28
30
|
/** ---------------------------------------------
|
|
29
31
|
* MARKDOWN PLUGIN
|