lit-intlayer 9.9.3 → 9.9.4
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 +93 -1
- package/dist/cjs/client/index.cjs +28 -1
- package/dist/cjs/client/installIntlayer.cjs +6 -1
- package/dist/cjs/client/useDictionary.cjs +24 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +47 -1
- package/dist/cjs/client/useIntlayer.cjs +30 -1
- package/dist/cjs/client/useLocale.cjs +90 -1
- package/dist/cjs/client/useLocaleStorage.cjs +56 -1
- package/dist/cjs/client/useRewriteURL.cjs +48 -1
- package/dist/cjs/editor/useEditor.cjs +3 -1
- package/dist/cjs/format/index.cjs +19 -1
- package/dist/cjs/format/useCompact.cjs +34 -1
- package/dist/cjs/format/useCurrency.cjs +34 -1
- package/dist/cjs/format/useDate.cjs +52 -1
- package/dist/cjs/format/useIntl.cjs +66 -1
- package/dist/cjs/format/useList.cjs +34 -1
- package/dist/cjs/format/useNumber.cjs +40 -1
- package/dist/cjs/format/usePercentage.cjs +34 -1
- package/dist/cjs/format/useRelativeTime.cjs +34 -1
- package/dist/cjs/format/useUnit.cjs +34 -1
- package/dist/cjs/getDictionary.cjs +14 -1
- package/dist/cjs/getIntlayer.cjs +14 -1
- package/dist/cjs/html/HTMLRenderer.cjs +53 -1
- package/dist/cjs/html/index.cjs +8 -1
- package/dist/cjs/html/installIntlayerHTML.cjs +90 -1
- package/dist/cjs/html/types.cjs +1 -1
- package/dist/cjs/index.cjs +41 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +97 -1
- package/dist/cjs/markdown/compiler.cjs +72 -1
- package/dist/cjs/markdown/index.cjs +12 -1
- package/dist/cjs/markdown/installIntlayerMarkdown.cjs +98 -1
- package/dist/cjs/markdown/runtime.cjs +86 -1
- package/dist/cjs/plugins.cjs +217 -3
- package/dist/cjs/renderIntlayerNode.cjs +29 -1
- package/dist/esm/client/IntlayerBinding.mjs +75 -33
- package/dist/esm/client/index.mjs +9 -9
- package/dist/esm/client/installIntlayer.mjs +1 -1
- package/dist/esm/client/useDictionary.mjs +22 -10
- package/dist/esm/client/useDictionaryDynamic.mjs +44 -11
- package/dist/esm/client/useIntlayer.mjs +28 -10
- package/dist/esm/client/useLocale.mjs +71 -19
- package/dist/esm/client/useLocaleStorage.mjs +45 -12
- package/dist/esm/client/useRewriteURL.mjs +36 -18
- package/dist/esm/editor/useEditor.mjs +1 -1
- package/dist/esm/format/index.mjs +10 -10
- package/dist/esm/format/useCompact.mjs +23 -19
- package/dist/esm/format/useCurrency.mjs +23 -19
- package/dist/esm/format/useDate.mjs +37 -27
- package/dist/esm/format/useIntl.mjs +54 -13
- package/dist/esm/format/useList.mjs +23 -19
- package/dist/esm/format/useNumber.mjs +29 -19
- package/dist/esm/format/usePercentage.mjs +23 -19
- package/dist/esm/format/useRelativeTime.mjs +23 -19
- package/dist/esm/format/useUnit.mjs +23 -19
- package/dist/esm/getDictionary.mjs +11 -6
- package/dist/esm/getIntlayer.mjs +11 -6
- package/dist/esm/html/HTMLRenderer.mjs +38 -13
- package/dist/esm/html/index.mjs +3 -3
- package/dist/esm/html/installIntlayerHTML.mjs +82 -13
- package/dist/esm/index.mjs +12 -12
- package/dist/esm/markdown/MarkdownRenderer.mjs +66 -26
- package/dist/esm/markdown/compiler.mjs +68 -22
- package/dist/esm/markdown/index.mjs +4 -4
- package/dist/esm/markdown/installIntlayerMarkdown.mjs +87 -23
- package/dist/esm/markdown/runtime.mjs +58 -28
- package/dist/esm/plugins.mjs +156 -106
- package/dist/esm/renderIntlayerNode.mjs +17 -17
- package/dist/installIntlayer-CCMOc1XT.mjs +174 -0
- package/dist/installIntlayer-HB8aIQ-i.js +203 -0
- package/package.json +7 -7
- package/dist/installIntlayer-CFvvijL7.js +0 -1
- package/dist/installIntlayer-CTpPd7yz.mjs +0 -82
|
@@ -1,49 +1,91 @@
|
|
|
1
|
-
import { loadingContentPlaceholder
|
|
2
|
-
import { r as
|
|
1
|
+
import { loadingContentPlaceholder } from "@intlayer/core/dictionaryManipulator";
|
|
2
|
+
import { r as getIntlayerClient } from "../../installIntlayer-CCMOc1XT.mjs";
|
|
3
3
|
// src/client/IntlayerBinding.ts
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* `ReactiveController` that keeps a Lit element in sync with Intlayer locale
|
|
6
|
+
* changes and, optionally, async dictionary load events.
|
|
7
|
+
*
|
|
8
|
+
* Registered automatically by `.observe(this)` — you should never need to
|
|
9
|
+
* instantiate it directly.
|
|
10
|
+
*
|
|
11
|
+
* @param host - The Lit element to update.
|
|
12
|
+
* @param onConnect - Called inside `hostConnected` (after locale subscription
|
|
13
|
+
* is set up). Useful for triggering an immediate update
|
|
14
|
+
* when the dictionary is already cached.
|
|
15
|
+
* @param onDisconnect - Called inside `hostDisconnected`. Useful for removing
|
|
16
|
+
* the host from a dictionary's update-host registry.
|
|
17
|
+
*/
|
|
18
|
+
var IntlayerBinding = class {
|
|
5
19
|
host;
|
|
6
20
|
unsubscribeLocale = null;
|
|
7
21
|
onConnect;
|
|
8
22
|
onDisconnect;
|
|
9
|
-
constructor(
|
|
10
|
-
this.host =
|
|
23
|
+
constructor(host, onConnect, onDisconnect) {
|
|
24
|
+
this.host = host;
|
|
25
|
+
this.onConnect = onConnect;
|
|
26
|
+
this.onDisconnect = onDisconnect;
|
|
27
|
+
this.host.addController(this);
|
|
11
28
|
}
|
|
12
29
|
hostConnected() {
|
|
13
|
-
|
|
14
|
-
this.unsubscribeLocale =
|
|
30
|
+
const client = getIntlayerClient();
|
|
31
|
+
this.unsubscribeLocale = client.subscribe(() => {
|
|
15
32
|
this.host.requestUpdate();
|
|
16
|
-
})
|
|
33
|
+
});
|
|
34
|
+
this.onConnect?.();
|
|
17
35
|
}
|
|
18
36
|
hostDisconnected() {
|
|
19
|
-
this.unsubscribeLocale?.()
|
|
37
|
+
this.unsubscribeLocale?.();
|
|
38
|
+
this.unsubscribeLocale = null;
|
|
39
|
+
this.onDisconnect?.();
|
|
20
40
|
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Wraps content read for the client's locale and variant (read again whenever
|
|
44
|
+
* either changes) in an {@link IntlayerLitProxy}. Chain `.observe(this)` so
|
|
45
|
+
* the host re-renders on locale changes and once loading content lands; while
|
|
46
|
+
* the first content loads, every access renders `''`. Shared by `useDictionary`,
|
|
47
|
+
* `useIntlayer` and `useDictionaryDynamic`.
|
|
48
|
+
*/
|
|
49
|
+
var createContentProxy = (readContent) => {
|
|
50
|
+
const client = getIntlayerClient();
|
|
51
|
+
const hosts = /* @__PURE__ */ new Set();
|
|
52
|
+
let current;
|
|
53
|
+
let readLocale;
|
|
54
|
+
let readVariant;
|
|
55
|
+
let hasRead = false;
|
|
56
|
+
const getContent = () => {
|
|
57
|
+
if (!hasRead || readLocale !== client.locale || readVariant !== client.variant) {
|
|
58
|
+
hasRead = true;
|
|
59
|
+
readLocale = client.locale;
|
|
60
|
+
readVariant = client.variant;
|
|
61
|
+
const settled = readContent({
|
|
62
|
+
contextLocale: client.locale,
|
|
63
|
+
contextVariant: client.variant
|
|
64
|
+
}, (content) => {
|
|
65
|
+
current = { content };
|
|
66
|
+
for (const host of hosts) host.requestUpdate();
|
|
31
67
|
});
|
|
32
|
-
|
|
68
|
+
if (settled) current = settled;
|
|
33
69
|
}
|
|
34
|
-
return
|
|
70
|
+
return current;
|
|
35
71
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
72
|
+
getContent();
|
|
73
|
+
const proxy = new Proxy({}, { get(_target, property) {
|
|
74
|
+
if (property === "observe") return (host) => {
|
|
75
|
+
hosts.add(host);
|
|
76
|
+
new IntlayerBinding(host, () => {
|
|
77
|
+
if (current) host.requestUpdate();
|
|
78
|
+
}, () => hosts.delete(host));
|
|
79
|
+
return proxy;
|
|
80
|
+
};
|
|
81
|
+
if (property === "then" || typeof property === "string" && property.startsWith("_$")) return;
|
|
82
|
+
const loaded = getContent();
|
|
83
|
+
if (!loaded) return loadingContentPlaceholder[property];
|
|
84
|
+
const content = loaded.content;
|
|
85
|
+
if (property === Symbol.toPrimitive) return () => content?.[Symbol.toPrimitive]?.() ?? "";
|
|
86
|
+
if (property === "toString") return () => String(content?.toString?.() ?? "");
|
|
87
|
+
return content?.[property];
|
|
46
88
|
} });
|
|
47
|
-
return
|
|
89
|
+
return proxy;
|
|
48
90
|
};
|
|
49
|
-
export {
|
|
91
|
+
export { IntlayerBinding, createContentProxy };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { IntlayerBinding
|
|
2
|
-
import { i as
|
|
3
|
-
import { useDictionary
|
|
4
|
-
import { useDictionaryDynamic
|
|
5
|
-
import { useIntlayer
|
|
6
|
-
import { LocaleController
|
|
7
|
-
import { getLocaleInStorage
|
|
8
|
-
import { useRewriteURL
|
|
9
|
-
export {
|
|
1
|
+
import { IntlayerBinding, createContentProxy } from "./IntlayerBinding.mjs";
|
|
2
|
+
import { i as installIntlayer, n as createIntlayerClient, r as getIntlayerClient, t as IntlayerClient } from "../../installIntlayer-CCMOc1XT.mjs";
|
|
3
|
+
import { useDictionary } from "./useDictionary.mjs";
|
|
4
|
+
import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
|
|
5
|
+
import { useIntlayer } from "./useIntlayer.mjs";
|
|
6
|
+
import { LocaleController, useLocale } from "./useLocale.mjs";
|
|
7
|
+
import { getLocaleInStorage, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage } from "./useLocaleStorage.mjs";
|
|
8
|
+
import { useRewriteURL } from "./useRewriteURL.mjs";
|
|
9
|
+
export { IntlayerBinding, IntlayerClient, LocaleController, createContentProxy, createIntlayerClient, getIntlayerClient, getLocaleInStorage, installIntlayer, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useDictionary, useDictionaryDynamic, useIntlayer, useLocale, useLocaleCookie, useLocaleStorage, useRewriteURL };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as IntlayerClient, n as createIntlayerClient, r as getIntlayerClient, i as installIntlayer } from "../../installIntlayer-
|
|
1
|
+
export { t as IntlayerClient, n as createIntlayerClient, r as getIntlayerClient, i as installIntlayer } from "../../installIntlayer-CCMOc1XT.mjs";
|
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
import { resolveDictionaryArgument
|
|
2
|
-
import { getDictionary
|
|
3
|
-
import { createContentProxy
|
|
1
|
+
import { resolveDictionaryArgument } from "@intlayer/core/dictionaryManipulator";
|
|
2
|
+
import { getDictionary } from "../getDictionary.mjs";
|
|
3
|
+
import { createContentProxy } from "./IntlayerBinding.mjs";
|
|
4
4
|
// src/client/useDictionary.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Returns the content for a raw dictionary (or qualified dictionary group),
|
|
7
|
+
* wrapped in an {@link IntlayerLitProxy} so the caller can subscribe to locale
|
|
8
|
+
* changes via a Lit `ReactiveController`.
|
|
9
|
+
*
|
|
10
|
+
* The second argument is either a locale or a selector object (`{ item }`,
|
|
11
|
+
* `{ variant }`, optionally combined with `locale`).
|
|
12
|
+
*
|
|
13
|
+
* @param dictionary - The raw dictionary (or qualified group) object.
|
|
14
|
+
* @param localeOrSelector - Optional locale or selector.
|
|
15
|
+
* @returns An {@link IntlayerLitProxy} with an `.observe()` registration method.
|
|
16
|
+
*/
|
|
17
|
+
var useDictionary = (dictionary, localeOrSelector) => createContentProxy(({ contextLocale, contextVariant }) => ({ content: process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" ? getDictionary(dictionary, resolveDictionaryArgument({
|
|
18
|
+
localeOrSelector,
|
|
19
|
+
contextLocale,
|
|
20
|
+
contextVariant,
|
|
21
|
+
dictionaryKey: dictionary.key
|
|
22
|
+
})) : getDictionary(dictionary, localeOrSelector ?? contextLocale) }));
|
|
23
|
+
export { useDictionary };
|
|
@@ -1,13 +1,46 @@
|
|
|
1
|
-
import { createDynamicContentStore
|
|
2
|
-
import { getDictionary
|
|
3
|
-
import { createContentProxy
|
|
1
|
+
import { createDynamicContentStore } from "@intlayer/core/dictionaryManipulator";
|
|
2
|
+
import { getDictionary } from "../getDictionary.mjs";
|
|
3
|
+
import { createContentProxy } from "./IntlayerBinding.mjs";
|
|
4
4
|
// src/client/useDictionaryDynamic.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
/** Content cache shared by every dynamic read of the page. */
|
|
6
|
+
var dynamicContentStore = createDynamicContentStore((dictionary, argument) => getDictionary(dictionary, argument));
|
|
7
|
+
/**
|
|
8
|
+
* Returns the translated content for a lazily-loaded dictionary, wrapped in an
|
|
9
|
+
* {@link IntlayerLitProxy} so the caller can register a Lit `ReactiveController`
|
|
10
|
+
* that keeps the element in sync with both the async bundle load and locale
|
|
11
|
+
* changes.
|
|
12
|
+
*
|
|
13
|
+
* This is the babel-optimized counterpart of `useIntlayer` when
|
|
14
|
+
* `importMode = 'dynamic'` — it accepts the locale-keyed loader map injected
|
|
15
|
+
* by the build plugin, matching the same signature as `react-intlayer` and
|
|
16
|
+
* other framework adapters.
|
|
17
|
+
*
|
|
18
|
+
* While loading, property accesses return the shared loading placeholder,
|
|
19
|
+
* which renders `''`. Chain `.observe(this)` so Lit triggers `requestUpdate()`
|
|
20
|
+
* once the bundle is ready and on every subsequent locale change.
|
|
21
|
+
*
|
|
22
|
+
* The `intlayerLitPlugin` Vite plugin automatically appends
|
|
23
|
+
* `.observe(this)` at build / serve time, so manual chaining is usually
|
|
24
|
+
* unnecessary.
|
|
25
|
+
*
|
|
26
|
+
* @param dictionaryPromise - Locale-keyed loader map, or a qualified loader map.
|
|
27
|
+
* @param key - The dictionary key (used for cache namespacing).
|
|
28
|
+
* @param localeOrSelector - Optional locale or selector.
|
|
29
|
+
* @returns An {@link IntlayerLitProxy} proxy with an `.observe()` method.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* // Typically injected by the babel/SWC optimization plugin:
|
|
34
|
+
* import _hash_dyn from '.intlayer/dynamic_dictionaries/app.mjs';
|
|
35
|
+
* private content = useDictionaryDynamic(_hash_dyn, 'app').observe(this);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
var useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector) => {
|
|
39
|
+
const readContent = dynamicContentStore.createReader(dictionaryPromise, String(key));
|
|
40
|
+
return createContentProxy(({ contextLocale, contextVariant }, onLoad) => readContent({
|
|
41
|
+
localeOrSelector,
|
|
42
|
+
contextLocale,
|
|
43
|
+
contextVariant
|
|
44
|
+
}, onLoad));
|
|
12
45
|
};
|
|
13
|
-
export {
|
|
46
|
+
export { useDictionaryDynamic };
|
|
@@ -1,11 +1,29 @@
|
|
|
1
|
-
import { resolveDictionaryArgument
|
|
2
|
-
import { getIntlayer
|
|
3
|
-
import { createContentProxy
|
|
1
|
+
import { resolveDictionaryArgument } from "@intlayer/core/dictionaryManipulator";
|
|
2
|
+
import { getIntlayer } from "../getIntlayer.mjs";
|
|
3
|
+
import { createContentProxy } from "./IntlayerBinding.mjs";
|
|
4
4
|
// src/client/useIntlayer.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Returns the translated content for the given dictionary key, wrapped in an
|
|
7
|
+
* {@link IntlayerLitProxy} so the caller can subscribe to locale changes via
|
|
8
|
+
* a Lit `ReactiveController`.
|
|
9
|
+
*
|
|
10
|
+
* Matches the same signature as `react-intlayer` and all other framework
|
|
11
|
+
* adapters:
|
|
12
|
+
* ```ts
|
|
13
|
+
* private content = useIntlayer('my-component').observe(this);
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* The babel/SWC optimization plugin transforms this at build time into either:
|
|
17
|
+
* - static mode: `useDictionary(_hash)` — synchronous JSON import
|
|
18
|
+
* - dynamic mode: `useDictionaryDynamic(_dyn, 'key')` — lazy locale split
|
|
19
|
+
*
|
|
20
|
+
* In non-optimized builds (dev without babel) the content is read from
|
|
21
|
+
* `getIntlayer`, again whenever the client locale or variant changes.
|
|
22
|
+
*/
|
|
23
|
+
var useIntlayer = (key, localeOrSelector) => createContentProxy(({ contextLocale, contextVariant }) => ({ content: process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" ? getIntlayer(key, resolveDictionaryArgument({
|
|
24
|
+
localeOrSelector,
|
|
25
|
+
contextLocale,
|
|
26
|
+
contextVariant,
|
|
27
|
+
dictionaryKey: key
|
|
28
|
+
})) : getIntlayer(key, localeOrSelector ?? contextLocale) }));
|
|
29
|
+
export { useIntlayer };
|
|
@@ -1,36 +1,88 @@
|
|
|
1
|
-
import { internationalization
|
|
2
|
-
import { r as
|
|
3
|
-
import { setLocaleInStorage
|
|
1
|
+
import { internationalization } from "@intlayer/config/built";
|
|
2
|
+
import { r as getIntlayerClient } from "../../installIntlayer-CCMOc1XT.mjs";
|
|
3
|
+
import { setLocaleInStorage } from "./useLocaleStorage.mjs";
|
|
4
4
|
// src/client/useLocale.ts
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* ReactiveController that exposes the current locale and a `setLocale` setter.
|
|
7
|
+
* The host element re-renders whenever the locale changes.
|
|
8
|
+
*/
|
|
9
|
+
var LocaleController = class {
|
|
6
10
|
host;
|
|
7
11
|
_isCookieEnabled;
|
|
8
12
|
_onLocaleChange;
|
|
9
13
|
_unsubscribe = null;
|
|
14
|
+
/** The currently active locale. */
|
|
10
15
|
locale;
|
|
16
|
+
/** The application's default locale (from config). */
|
|
11
17
|
defaultLocale;
|
|
18
|
+
/** All available locales (from config). */
|
|
12
19
|
availableLocales;
|
|
13
|
-
constructor(
|
|
14
|
-
this.host =
|
|
15
|
-
|
|
16
|
-
this.
|
|
20
|
+
constructor(host, props = {}) {
|
|
21
|
+
this.host = host;
|
|
22
|
+
this._isCookieEnabled = props.isCookieEnabled;
|
|
23
|
+
this._onLocaleChange = props.onLocaleChange;
|
|
24
|
+
const client = getIntlayerClient();
|
|
25
|
+
const { defaultLocale, locales: availableLocales } = internationalization ?? {};
|
|
26
|
+
this.locale = client.locale;
|
|
27
|
+
this.defaultLocale = defaultLocale;
|
|
28
|
+
this.availableLocales = availableLocales ?? [];
|
|
29
|
+
host.addController(this);
|
|
17
30
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Change the application locale.
|
|
33
|
+
* Validates against `availableLocales`, persists to storage, and triggers a re-render.
|
|
34
|
+
*/
|
|
35
|
+
setLocale = (newLocale) => {
|
|
36
|
+
if (!this.availableLocales.map(String).includes(newLocale)) {
|
|
37
|
+
console.error(`Locale "${newLocale}" is not available.`);
|
|
21
38
|
return;
|
|
22
39
|
}
|
|
23
|
-
|
|
24
|
-
|
|
40
|
+
const client = getIntlayerClient();
|
|
41
|
+
client.setLocale(newLocale);
|
|
42
|
+
setLocaleInStorage(newLocale, this._isCookieEnabled ?? client.isCookieEnabled ?? true);
|
|
43
|
+
this._onLocaleChange?.(newLocale);
|
|
25
44
|
};
|
|
26
45
|
hostConnected() {
|
|
27
|
-
|
|
28
|
-
this._unsubscribe =
|
|
29
|
-
this.locale =
|
|
46
|
+
const client = getIntlayerClient();
|
|
47
|
+
this._unsubscribe = client.subscribe((newLocale) => {
|
|
48
|
+
this.locale = newLocale;
|
|
49
|
+
this.host.requestUpdate();
|
|
30
50
|
});
|
|
31
51
|
}
|
|
32
52
|
hostDisconnected() {
|
|
33
|
-
this._unsubscribe?.()
|
|
53
|
+
this._unsubscribe?.();
|
|
54
|
+
this._unsubscribe = null;
|
|
34
55
|
}
|
|
35
|
-
}
|
|
36
|
-
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Reactive hook that provides locale management.
|
|
59
|
+
*
|
|
60
|
+
* Returns a `LocaleController` with:
|
|
61
|
+
* - `locale` — the current locale (updates the host on change)
|
|
62
|
+
* - `defaultLocale` — the config default locale
|
|
63
|
+
* - `availableLocales` — all configured locales
|
|
64
|
+
* - `setLocale(locale)` — switches the app locale
|
|
65
|
+
*
|
|
66
|
+
* @param host - The LitElement (or any ReactiveControllerHost).
|
|
67
|
+
* @param props - Optional configuration.
|
|
68
|
+
* @returns A `LocaleController`.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* class LocaleSwitcher extends LitElement {
|
|
73
|
+
* private locale = useLocale(this);
|
|
74
|
+
*
|
|
75
|
+
* render() {
|
|
76
|
+
* return html`
|
|
77
|
+
* <select @change=${(e: Event) => this.locale.setLocale((e.target as HTMLSelectElement).value as any)}>
|
|
78
|
+
* ${this.locale.availableLocales.map(
|
|
79
|
+
* (loc) => html`<option value=${loc} ?selected=${loc === this.locale.locale}>${loc}</option>`
|
|
80
|
+
* )}
|
|
81
|
+
* </select>
|
|
82
|
+
* `;
|
|
83
|
+
* }
|
|
84
|
+
* }
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
var useLocale = (host, props = {}) => new LocaleController(host, props);
|
|
88
|
+
export { LocaleController, useLocale };
|
|
@@ -1,16 +1,49 @@
|
|
|
1
|
-
import { LocaleStorageClient
|
|
1
|
+
import { LocaleStorageClient, getCachedLocaleFromStorageClient, getLocaleFromStorageClient, localeStorageOptions, setLocaleInStorageClient } from "@intlayer/core/utils";
|
|
2
2
|
// src/client/useLocaleStorage.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Reads the locale persisted in the browser storage (cookie, localStorage…).
|
|
5
|
+
*
|
|
6
|
+
* Unlike `localeInStorage`, read on first call rather than at import, then
|
|
7
|
+
* cached until the next `setLocaleInStorage`. Never cached on the server.
|
|
8
|
+
*/
|
|
9
|
+
var getLocaleInStorage = getCachedLocaleFromStorageClient;
|
|
10
|
+
/**
|
|
11
|
+
* Get the current locale from storage (cookie or localStorage).
|
|
12
|
+
*
|
|
13
|
+
* Read once at import time; marked pure so bundlers drop the read when nothing
|
|
14
|
+
* imports it.
|
|
15
|
+
*/
|
|
16
|
+
var localeInStorage = /* @__PURE__ */ getLocaleFromStorageClient(localeStorageOptions);
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Use localeInStorage instead.
|
|
19
|
+
*/
|
|
20
|
+
var localeCookie = localeInStorage;
|
|
21
|
+
/**
|
|
22
|
+
* Persist the locale to storage (cookie and/or localStorage).
|
|
23
|
+
*/
|
|
24
|
+
var setLocaleInStorage = (locale, isCookieEnabled) => setLocaleInStorageClient(locale, {
|
|
25
|
+
...localeStorageOptions,
|
|
26
|
+
isCookieEnabled
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated Use setLocaleInStorage instead.
|
|
30
|
+
*/
|
|
31
|
+
var setLocaleCookie = setLocaleInStorage;
|
|
32
|
+
/**
|
|
33
|
+
* Returns the current locale from storage and a setter.
|
|
34
|
+
*/
|
|
35
|
+
var useLocaleStorage = (isCookieEnabled) => {
|
|
36
|
+
const storage = LocaleStorageClient({
|
|
37
|
+
...localeStorageOptions,
|
|
38
|
+
isCookieEnabled
|
|
10
39
|
});
|
|
11
40
|
return {
|
|
12
|
-
localeStorage:
|
|
13
|
-
setLocaleStorage:
|
|
41
|
+
localeStorage: storage.getLocale(),
|
|
42
|
+
setLocaleStorage: storage.setLocale
|
|
14
43
|
};
|
|
15
|
-
}
|
|
16
|
-
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated Use useLocaleStorage instead.
|
|
47
|
+
*/
|
|
48
|
+
var useLocaleCookie = useLocaleStorage;
|
|
49
|
+
export { getLocaleInStorage, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage };
|
|
@@ -1,29 +1,47 @@
|
|
|
1
|
-
import { routing
|
|
2
|
-
import { getRewritePath
|
|
3
|
-
import { r as
|
|
1
|
+
import { routing } from "@intlayer/config/built";
|
|
2
|
+
import { getRewritePath } from "@intlayer/core/localization";
|
|
3
|
+
import { r as getIntlayerClient } from "../../installIntlayer-CCMOc1XT.mjs";
|
|
4
4
|
// src/client/useRewriteURL.ts
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* ReactiveController that keeps the browser URL in sync with the current locale.
|
|
7
|
+
*
|
|
8
|
+
* Uses `window.history.replaceState` to update the address bar without
|
|
9
|
+
* triggering a full navigation.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* class AppShell extends LitElement {
|
|
14
|
+
* private _rewrite = useRewriteURL(this);
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
var RewriteURLController = class {
|
|
6
19
|
_host;
|
|
7
20
|
_unsubscribe = null;
|
|
8
|
-
constructor(
|
|
9
|
-
this._host =
|
|
21
|
+
constructor(host) {
|
|
22
|
+
this._host = host;
|
|
23
|
+
host.addController(this);
|
|
10
24
|
}
|
|
11
|
-
_rewrite(
|
|
12
|
-
|
|
13
|
-
if (typeof window
|
|
14
|
-
|
|
15
|
-
|
|
25
|
+
_rewrite(locale) {
|
|
26
|
+
const rewrite = routing?.rewrite;
|
|
27
|
+
if (typeof window === "undefined" || !rewrite) return;
|
|
28
|
+
const pathname = window.location.pathname;
|
|
29
|
+
const targetPath = getRewritePath(pathname, locale, rewrite);
|
|
30
|
+
if (targetPath && targetPath !== pathname) window.history.replaceState(window.history.state, "", targetPath + window.location.search + window.location.hash);
|
|
16
31
|
}
|
|
17
32
|
hostConnected() {
|
|
18
|
-
|
|
19
|
-
this._rewrite(
|
|
20
|
-
|
|
33
|
+
const client = getIntlayerClient();
|
|
34
|
+
this._rewrite(client.locale);
|
|
35
|
+
this._unsubscribe = client.subscribe((newLocale) => {
|
|
36
|
+
this._rewrite(newLocale);
|
|
21
37
|
});
|
|
22
38
|
}
|
|
23
39
|
hostDisconnected() {
|
|
24
|
-
this._unsubscribe?.()
|
|
40
|
+
this._unsubscribe?.();
|
|
41
|
+
this._unsubscribe = null;
|
|
25
42
|
}
|
|
26
|
-
}, i = (e) => {
|
|
27
|
-
new r(e);
|
|
28
43
|
};
|
|
29
|
-
|
|
44
|
+
var useRewriteURL = (host) => {
|
|
45
|
+
new RewriteURLController(host);
|
|
46
|
+
};
|
|
47
|
+
export { useRewriteURL };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { a as useEditor } from "../../installIntlayer-
|
|
1
|
+
export { a as useEditor } from "../../installIntlayer-CCMOc1XT.mjs";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { useCompact
|
|
2
|
-
import { useCurrency
|
|
3
|
-
import { useDate
|
|
4
|
-
import { useIntl
|
|
5
|
-
import { useList
|
|
6
|
-
import { useNumber
|
|
7
|
-
import { usePercentage
|
|
8
|
-
import { useRelativeTime
|
|
9
|
-
import { useUnit
|
|
10
|
-
export {
|
|
1
|
+
import { useCompact } from "./useCompact.mjs";
|
|
2
|
+
import { useCurrency } from "./useCurrency.mjs";
|
|
3
|
+
import { useDate } from "./useDate.mjs";
|
|
4
|
+
import { useIntl } from "./useIntl.mjs";
|
|
5
|
+
import { useList } from "./useList.mjs";
|
|
6
|
+
import { useNumber } from "./useNumber.mjs";
|
|
7
|
+
import { usePercentage } from "./usePercentage.mjs";
|
|
8
|
+
import { useRelativeTime } from "./useRelativeTime.mjs";
|
|
9
|
+
import { useUnit } from "./useUnit.mjs";
|
|
10
|
+
export { useCompact, useCurrency, useDate, useIntl, useList, useNumber, usePercentage, useRelativeTime, useUnit };
|
|
@@ -1,29 +1,33 @@
|
|
|
1
|
-
import { compact
|
|
2
|
-
import { r as
|
|
1
|
+
import { compact } from "@intlayer/core/formatters";
|
|
2
|
+
import { r as getIntlayerClient } from "../../installIntlayer-CCMOc1XT.mjs";
|
|
3
3
|
// src/format/useCompact.ts
|
|
4
|
-
var
|
|
4
|
+
var CompactController = class {
|
|
5
5
|
host;
|
|
6
6
|
_unsubscribe = null;
|
|
7
7
|
value;
|
|
8
|
-
constructor(
|
|
9
|
-
this.host =
|
|
10
|
-
|
|
11
|
-
this.value = (...
|
|
12
|
-
...
|
|
13
|
-
locale:
|
|
14
|
-
})
|
|
8
|
+
constructor(host) {
|
|
9
|
+
this.host = host;
|
|
10
|
+
const client = getIntlayerClient();
|
|
11
|
+
this.value = (...args) => compact(args[0], {
|
|
12
|
+
...args[1],
|
|
13
|
+
locale: args[1]?.locale ?? client.locale
|
|
14
|
+
});
|
|
15
|
+
host.addController(this);
|
|
15
16
|
}
|
|
16
17
|
hostConnected() {
|
|
17
|
-
|
|
18
|
-
this._unsubscribe =
|
|
19
|
-
this.value = (...
|
|
20
|
-
...
|
|
21
|
-
locale:
|
|
22
|
-
})
|
|
18
|
+
const client = getIntlayerClient();
|
|
19
|
+
this._unsubscribe = client.subscribe((newLocale) => {
|
|
20
|
+
this.value = (...args) => compact(args[0], {
|
|
21
|
+
...args[1],
|
|
22
|
+
locale: args[1]?.locale ?? newLocale
|
|
23
|
+
});
|
|
24
|
+
this.host.requestUpdate();
|
|
23
25
|
});
|
|
24
26
|
}
|
|
25
27
|
hostDisconnected() {
|
|
26
|
-
this._unsubscribe?.()
|
|
28
|
+
this._unsubscribe?.();
|
|
29
|
+
this._unsubscribe = null;
|
|
27
30
|
}
|
|
28
|
-
}
|
|
29
|
-
|
|
31
|
+
};
|
|
32
|
+
var useCompact = (host) => new CompactController(host);
|
|
33
|
+
export { useCompact };
|