solid-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/IntlayerNode.cjs +11 -1
- package/dist/cjs/LoadingBoundary.cjs +26 -1
- package/dist/cjs/analytics/AnalyticsProvider.cjs +12 -1
- package/dist/cjs/analytics/exposureSink.cjs +23 -1
- package/dist/cjs/analytics/index.cjs +9 -1
- package/dist/cjs/analytics/useAnalytics.cjs +59 -1
- package/dist/cjs/analytics/useConversion.cjs +25 -1
- package/dist/cjs/analytics/useExperiment.cjs +59 -1
- package/dist/cjs/client/IntlayerProvider.cjs +91 -1
- package/dist/cjs/client/contentProxy.cjs +32 -1
- package/dist/cjs/client/getBrowserLocale.cjs +115 -1
- package/dist/cjs/client/index.cjs +35 -1
- package/dist/cjs/client/t.cjs +16 -1
- package/dist/cjs/client/useContent.cjs +16 -1
- package/dist/cjs/client/useDictionary.cjs +51 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +19 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +82 -1
- package/dist/cjs/client/useIntlayer.cjs +50 -1
- package/dist/cjs/client/useLoadDynamic.cjs +140 -1
- package/dist/cjs/client/useLocale.cjs +52 -1
- package/dist/cjs/client/useLocaleBase.cjs +19 -1
- package/dist/cjs/client/useLocaleStorage.cjs +59 -1
- package/dist/cjs/client/usePathname.cjs +41 -1
- package/dist/cjs/client/useRewriteURL.cjs +21 -1
- package/dist/cjs/client/useTraduction.cjs +32 -1
- package/dist/cjs/editor/ContentSelector.cjs +20 -1
- package/dist/cjs/editor/EditorProvider.cjs +8 -1
- package/dist/cjs/editor/createEditedContentSource.cjs +32 -1
- package/dist/cjs/editor/useEditor.cjs +38 -1
- package/dist/cjs/format/index.cjs +19 -1
- package/dist/cjs/format/useCompact.cjs +15 -1
- package/dist/cjs/format/useCurrency.cjs +16 -1
- package/dist/cjs/format/useDate.cjs +25 -1
- package/dist/cjs/format/useIntl.cjs +31 -1
- package/dist/cjs/format/useList.cjs +15 -1
- package/dist/cjs/format/useNumber.cjs +19 -1
- package/dist/cjs/format/usePercentage.cjs +16 -1
- package/dist/cjs/format/useRelativeTime.cjs +16 -1
- package/dist/cjs/format/useUnit.cjs +15 -1
- package/dist/cjs/getDictionary.cjs +17 -1
- package/dist/cjs/getIntlayer.cjs +14 -1
- package/dist/cjs/html/HTMLProvider.cjs +24 -1
- package/dist/cjs/html/HTMLRenderer.cjs +49 -1
- package/dist/cjs/html/index.cjs +8 -1
- package/dist/cjs/html/types.cjs +1 -1
- package/dist/cjs/index.cjs +48 -1
- package/dist/cjs/markdown/MarkdownProvider.cjs +47 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +56 -1
- package/dist/cjs/markdown/compiler.cjs +64 -1
- package/dist/cjs/markdown/index.cjs +13 -1
- package/dist/cjs/markdown/runtime.cjs +48 -1
- package/dist/cjs/plugins.cjs +266 -1
- package/dist/cjs/proxyKeys.cjs +14 -1
- package/dist/cjs/server/index.cjs +3 -1
- package/dist/cjs/server/useDictionary.cjs +30 -1
- package/dist/cjs/solidCompat.cjs +167 -1
- package/dist/cjs/solidElement/renderSolidElement.cjs +34 -1
- package/dist/cjs/solidTypes.cjs +1 -1
- package/dist/esm/IntlayerNode.mjs +8 -6
- package/dist/esm/LoadingBoundary.mjs +19 -6
- package/dist/esm/analytics/AnalyticsProvider.mjs +10 -3
- package/dist/esm/analytics/exposureSink.mjs +19 -5
- package/dist/esm/analytics/index.mjs +5 -5
- package/dist/esm/analytics/useAnalytics.mjs +52 -25
- package/dist/esm/analytics/useConversion.mjs +22 -6
- package/dist/esm/analytics/useExperiment.mjs +50 -22
- package/dist/esm/client/IntlayerProvider.mjs +75 -28
- package/dist/esm/client/contentProxy.mjs +26 -12
- package/dist/esm/client/getBrowserLocale.mjs +106 -71
- package/dist/esm/client/index.mjs +14 -14
- package/dist/esm/client/t.mjs +13 -7
- package/dist/esm/client/useContent.mjs +11 -8
- package/dist/esm/client/useDictionary.mjs +47 -25
- package/dist/esm/client/useDictionaryAsync.mjs +16 -9
- package/dist/esm/client/useDictionaryDynamic.mjs +72 -43
- package/dist/esm/client/useIntlayer.mjs +45 -15
- package/dist/esm/client/useLoadDynamic.mjs +128 -49
- package/dist/esm/client/useLocale.mjs +47 -16
- package/dist/esm/client/useLocaleBase.mjs +14 -10
- package/dist/esm/client/useLocaleStorage.mjs +51 -10
- package/dist/esm/client/usePathname.mjs +37 -12
- package/dist/esm/client/useRewriteURL.mjs +17 -11
- package/dist/esm/client/useTraduction.mjs +29 -8
- package/dist/esm/editor/ContentSelector.mjs +18 -15
- package/dist/esm/editor/EditorProvider.mjs +6 -3
- package/dist/esm/editor/createEditedContentSource.mjs +28 -17
- package/dist/esm/editor/useEditor.mjs +32 -22
- package/dist/esm/format/index.mjs +10 -10
- package/dist/esm/format/useCompact.mjs +11 -8
- package/dist/esm/format/useCurrency.mjs +12 -9
- package/dist/esm/format/useDate.mjs +19 -13
- package/dist/esm/format/useIntl.mjs +27 -9
- package/dist/esm/format/useList.mjs +11 -8
- package/dist/esm/format/useNumber.mjs +15 -9
- package/dist/esm/format/usePercentage.mjs +12 -9
- package/dist/esm/format/useRelativeTime.mjs +12 -9
- package/dist/esm/format/useUnit.mjs +11 -8
- package/dist/esm/getDictionary.mjs +14 -6
- package/dist/esm/getIntlayer.mjs +11 -6
- package/dist/esm/html/HTMLProvider.mjs +21 -12
- package/dist/esm/html/HTMLRenderer.mjs +44 -17
- package/dist/esm/html/index.mjs +3 -3
- package/dist/esm/index.mjs +20 -20
- package/dist/esm/markdown/MarkdownProvider.mjs +31 -24
- package/dist/esm/markdown/MarkdownRenderer.mjs +48 -37
- package/dist/esm/markdown/compiler.mjs +59 -23
- package/dist/esm/markdown/index.mjs +4 -4
- package/dist/esm/markdown/runtime.mjs +40 -13
- package/dist/esm/plugins.mjs +205 -156
- package/dist/esm/proxyKeys.mjs +7 -2
- package/dist/esm/server/useDictionary.mjs +25 -7
- package/dist/esm/solidCompat.mjs +146 -39
- package/dist/esm/solidElement/renderSolidElement.mjs +22 -19
- package/dist/rolldown-runtime-CmQyd0Gu.js +27 -0
- package/dist/solid/analytics/useAnalytics.jsx +3 -3
- package/dist/solid/analytics/useConversion.js +2 -2
- package/dist/solid/analytics/useExperiment.js +3 -3
- package/package.json +7 -7
- package/dist/esm-YGODKOLP.js +0 -1
- package/dist/esm-bdKnuomJ.mjs +0 -256
- package/dist/isEnabled-CuTKz0YA.js +0 -1
- package/dist/isEnabled-DVKEZ2He.mjs +0 -18
- package/dist/rolldown-runtime-BocRIvOZ.js +0 -1
- package/dist/solid/esm-1cHk4dPd.js +0 -644
- package/dist/solid/isEnabled-C5NUhdhZ.js +0 -100
|
@@ -1,11 +1,52 @@
|
|
|
1
|
-
import { LocaleStorageClient
|
|
2
|
-
import { createMemo
|
|
1
|
+
import { LocaleStorageClient, getCachedLocaleFromStorageClient, getLocaleFromStorageClient, localeStorageOptions, setLocaleInStorageClient } from "@intlayer/core/utils";
|
|
2
|
+
import { createMemo } from "solid-js";
|
|
3
3
|
// src/client/useLocaleStorage.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Reads the locale persisted in the browser storage (cookie, localStorage…).
|
|
6
|
+
*
|
|
7
|
+
* Unlike `localeInStorage`, read on first call rather than at import, then
|
|
8
|
+
* cached until the next `setLocaleInStorage`. Never cached on the server.
|
|
9
|
+
*/
|
|
10
|
+
var getLocaleInStorage = getCachedLocaleFromStorageClient;
|
|
11
|
+
/**
|
|
12
|
+
* Get the locale cookie
|
|
13
|
+
*
|
|
14
|
+
* Read once at import time; marked pure so bundlers drop the read when nothing
|
|
15
|
+
* imports it.
|
|
16
|
+
*/
|
|
17
|
+
var localeInStorage = /* @__PURE__ */ getLocaleFromStorageClient(localeStorageOptions);
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Use localeInStorage instead
|
|
20
|
+
*
|
|
21
|
+
* Get the locale cookie
|
|
22
|
+
*/
|
|
23
|
+
var localeCookie = localeInStorage;
|
|
24
|
+
/**
|
|
25
|
+
* Set the locale cookie
|
|
26
|
+
*/
|
|
27
|
+
var setLocaleInStorage = (locale, isCookieEnabled) => setLocaleInStorageClient(locale, {
|
|
28
|
+
...localeStorageOptions,
|
|
29
|
+
isCookieEnabled
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Use setLocaleInStorage instead
|
|
33
|
+
*
|
|
34
|
+
* Set the locale cookie
|
|
35
|
+
*/
|
|
36
|
+
var setLocaleCookie = setLocaleInStorage;
|
|
37
|
+
/**
|
|
38
|
+
* Hook that provides the locale storage and a function to set it
|
|
39
|
+
*/
|
|
40
|
+
var useLocaleStorage = (isCookieEnabled) => createMemo(() => LocaleStorageClient({
|
|
41
|
+
...localeStorageOptions,
|
|
42
|
+
isCookieEnabled
|
|
43
|
+
}));
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated Use useLocaleStorage instead
|
|
46
|
+
*
|
|
47
|
+
* For GDPR compliance, use useLocaleStorage instead
|
|
48
|
+
*
|
|
49
|
+
* Hook that provides the locale cookie and a function to set it
|
|
50
|
+
*/
|
|
51
|
+
var useLocaleCookie = useLocaleStorage;
|
|
52
|
+
export { getLocaleInStorage, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage };
|
|
@@ -1,15 +1,40 @@
|
|
|
1
|
-
import { getPathWithoutLocale
|
|
2
|
-
import { createSignal
|
|
3
|
-
import { onMounted
|
|
1
|
+
import { getPathWithoutLocale } from "@intlayer/core/localization";
|
|
2
|
+
import { createSignal } from "solid-js";
|
|
3
|
+
import { onMounted } from "../solidCompat.mjs";
|
|
4
4
|
// src/client/usePathname.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Solid hook that returns an accessor containing the current pathname with
|
|
7
|
+
* the locale segment removed.
|
|
8
|
+
*
|
|
9
|
+
* Reacts to browser back/forward navigation via the `popstate` event.
|
|
10
|
+
* Falls back to an empty string during server-side rendering.
|
|
11
|
+
*
|
|
12
|
+
* @returns An accessor containing the current pathname without the locale prefix.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* import { usePathname } from 'solid-intlayer';
|
|
17
|
+
*
|
|
18
|
+
* const NavItem = ({ href }: { href: string }) => {
|
|
19
|
+
* const pathname = usePathname();
|
|
20
|
+
* return (
|
|
21
|
+
* <a class={pathname() === href ? 'active' : ''} href={href}>
|
|
22
|
+
* {href}
|
|
23
|
+
* </a>
|
|
24
|
+
* );
|
|
25
|
+
* };
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
var usePathname = () => {
|
|
29
|
+
const [rawPathname, setRawPathname] = createSignal(typeof window !== "undefined" ? window.location.pathname : "");
|
|
30
|
+
onMounted(() => {
|
|
31
|
+
if (typeof window === "undefined") return;
|
|
32
|
+
const handleLocationChange = () => {
|
|
33
|
+
setRawPathname(window.location.pathname);
|
|
11
34
|
};
|
|
12
|
-
|
|
13
|
-
|
|
35
|
+
window.addEventListener("popstate", handleLocationChange);
|
|
36
|
+
return () => window.removeEventListener("popstate", handleLocationChange);
|
|
37
|
+
});
|
|
38
|
+
return () => getPathWithoutLocale(rawPathname());
|
|
14
39
|
};
|
|
15
|
-
export {
|
|
40
|
+
export { usePathname };
|
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
import { routing
|
|
2
|
-
import { getRewritePath
|
|
3
|
-
import { createWatchEffect
|
|
4
|
-
import { useLocale
|
|
1
|
+
import { routing } from "@intlayer/config/built";
|
|
2
|
+
import { getRewritePath } from "@intlayer/core/localization";
|
|
3
|
+
import { createWatchEffect } from "../solidCompat.mjs";
|
|
4
|
+
import { useLocale } from "./useLocale.mjs";
|
|
5
5
|
// src/client/useRewriteURL.ts
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Client-side hook to manage URL rewrites in Solid without triggering a router navigation.
|
|
8
|
+
* It uses `window.history.replaceState` to update the URL in the address bar.
|
|
9
|
+
*/
|
|
10
|
+
var useRewriteURL = () => {
|
|
11
|
+
const { locale } = useLocale();
|
|
12
|
+
const rewrite = routing?.rewrite;
|
|
13
|
+
createWatchEffect(locale, (loc) => {
|
|
14
|
+
if (typeof window === "undefined" || !rewrite) return;
|
|
15
|
+
const pathname = window.location.pathname;
|
|
16
|
+
const targetPath = getRewritePath(pathname, loc, rewrite);
|
|
17
|
+
if (targetPath && targetPath !== pathname) window.history.replaceState(window.history.state, "", targetPath + window.location.search + window.location.hash);
|
|
12
18
|
});
|
|
13
19
|
};
|
|
14
|
-
export {
|
|
20
|
+
export { useRewriteURL };
|
|
@@ -1,10 +1,31 @@
|
|
|
1
|
-
import { internationalization
|
|
2
|
-
import { getTranslation
|
|
3
|
-
import { useContext
|
|
4
|
-
import { IntlayerClientContext
|
|
1
|
+
import { internationalization } from "@intlayer/config/built";
|
|
2
|
+
import { getTranslation } from "@intlayer/core/interpreter";
|
|
3
|
+
import { useContext } from "solid-js";
|
|
4
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
5
5
|
// src/client/useTraduction.ts
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
/**
|
|
7
|
+
* On the client side, Hook that picking one dictionary by its id and return the content.
|
|
8
|
+
*
|
|
9
|
+
* If not locale found, it will return the content related to the default locale.
|
|
10
|
+
*
|
|
11
|
+
* Return either the content editor, or the content itself depending on the configuration.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
*
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const content = useTranslation<string>({
|
|
17
|
+
* en: 'Hello',
|
|
18
|
+
* fr: 'Bonjour',
|
|
19
|
+
* }, 'fr');
|
|
20
|
+
* // 'Bonjour'
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Using TypeScript:
|
|
24
|
+
* - this function will require each locale to be defined if defined in the project configuration.
|
|
25
|
+
* - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
|
|
26
|
+
*/
|
|
27
|
+
var useTranslation = (languageContent) => {
|
|
28
|
+
const { locale } = useContext(IntlayerClientContext) ?? {};
|
|
29
|
+
return getTranslation(languageContent, locale?.() ?? internationalization.defaultLocale);
|
|
9
30
|
};
|
|
10
|
-
export {
|
|
31
|
+
export { useTranslation };
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import { Dynamic
|
|
2
|
-
import { isEnabled
|
|
1
|
+
import { Dynamic, createComponent } from "solid-js/web";
|
|
2
|
+
import { isEnabled } from "@intlayer/editor/isEnabled";
|
|
3
3
|
// src/editor/ContentSelector.tsx
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
4
|
+
var ContentSelector = (props) => {
|
|
5
|
+
if (process.env.INTLAYER_EDITOR_ENABLED === "false" || !isEnabled) return props.children;
|
|
6
|
+
return createComponent(Dynamic, {
|
|
7
|
+
component: "intlayer-content-selector-wrapper",
|
|
8
|
+
get ["attr:key-path"]() {
|
|
9
|
+
return JSON.stringify(props.keyPath);
|
|
10
|
+
},
|
|
11
|
+
get ["attr:dictionary-key"]() {
|
|
12
|
+
return props.dictionaryKey;
|
|
13
|
+
},
|
|
14
|
+
get children() {
|
|
15
|
+
return props.children;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
export { ContentSelector };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { useEditor
|
|
1
|
+
import { useEditor } from "./useEditor.mjs";
|
|
2
2
|
// src/editor/EditorProvider.tsx
|
|
3
|
-
var
|
|
4
|
-
|
|
3
|
+
var EditorProvider = ({ children }) => {
|
|
4
|
+
useEditor();
|
|
5
|
+
return children;
|
|
6
|
+
};
|
|
7
|
+
export { EditorProvider };
|
|
@@ -1,20 +1,31 @@
|
|
|
1
|
-
import { isEnabled
|
|
2
|
-
import { createSignal
|
|
3
|
-
import { createWatchEffect
|
|
1
|
+
import { isEnabled } from "@intlayer/editor/isEnabled";
|
|
2
|
+
import { createSignal } from "solid-js";
|
|
3
|
+
import { createWatchEffect } from "../solidCompat.mjs";
|
|
4
4
|
// src/editor/createEditedContentSource.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Tracks the source string edited in the visual editor for a markdown / html
|
|
7
|
+
* node. The accessor returns `undefined` when the node is not edited (or the
|
|
8
|
+
* editor is off).
|
|
9
|
+
*/
|
|
10
|
+
var createEditedContentSource = (dictionaryKey, keyPath) => {
|
|
11
|
+
const [editedSource, setEditedSource] = createSignal();
|
|
12
|
+
if (process.env.INTLAYER_EDITOR_ENABLED === "false" || !isEnabled) return editedSource;
|
|
13
|
+
createWatchEffect(() => ({
|
|
14
|
+
currentDictionaryKey: dictionaryKey(),
|
|
15
|
+
keyPathJson: JSON.stringify(keyPath() ?? [])
|
|
16
|
+
}), ({ currentDictionaryKey, keyPathJson }) => {
|
|
17
|
+
if (!currentDictionaryKey) return;
|
|
18
|
+
let isStopped = false;
|
|
19
|
+
let unsubscribe = null;
|
|
20
|
+
import("@intlayer/editor").then(({ subscribeToEditedContentSource }) => {
|
|
21
|
+
if (isStopped) return;
|
|
22
|
+
unsubscribe = subscribeToEditedContentSource(currentDictionaryKey, JSON.parse(keyPathJson), (source) => setEditedSource(() => source));
|
|
23
|
+
}).catch(() => {});
|
|
24
|
+
return () => {
|
|
25
|
+
isStopped = true;
|
|
26
|
+
unsubscribe?.();
|
|
17
27
|
};
|
|
18
|
-
})
|
|
28
|
+
});
|
|
29
|
+
return editedSource;
|
|
19
30
|
};
|
|
20
|
-
export {
|
|
31
|
+
export { createEditedContentSource };
|
|
@@ -1,27 +1,37 @@
|
|
|
1
|
-
import { isEnabled
|
|
2
|
-
import { createSignal
|
|
3
|
-
import { useIntlayerContext
|
|
4
|
-
import { createWatchEffect
|
|
1
|
+
import { isEnabled } from "@intlayer/editor/isEnabled";
|
|
2
|
+
import { createSignal, onCleanup } from "solid-js";
|
|
3
|
+
import { useIntlayerContext } from "../client/IntlayerProvider.mjs";
|
|
4
|
+
import { createWatchEffect, onMounted } from "../solidCompat.mjs";
|
|
5
5
|
// src/editor/useEditor.tsx
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Initialises the Intlayer editor client singleton when the editor is enabled.
|
|
8
|
+
* Syncs the current locale from the Intlayer context into the editor manager so
|
|
9
|
+
* the editor always knows which locale the app is displaying.
|
|
10
|
+
*/
|
|
11
|
+
var useEditor = () => {
|
|
12
|
+
if (process.env.INTLAYER_EDITOR_ENABLED === "false" || !isEnabled) return;
|
|
13
|
+
const { locale, setLocale } = useIntlayerContext();
|
|
14
|
+
const [manager, setManager] = createSignal(null);
|
|
15
|
+
onMounted(() => {
|
|
16
|
+
import("@intlayer/editor").then(({ initEditorClient }) => {
|
|
17
|
+
const managerInstance = initEditorClient();
|
|
18
|
+
setManager(managerInstance);
|
|
13
19
|
}).catch(() => {});
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
managerInstance
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
});
|
|
21
|
+
createWatchEffect(manager, (managerInstance) => {
|
|
22
|
+
if (!managerInstance) return;
|
|
23
|
+
return managerInstance.onLocaleChangeRequested(setLocale);
|
|
24
|
+
});
|
|
25
|
+
createWatchEffect(() => ({
|
|
26
|
+
managerInstance: manager(),
|
|
27
|
+
currentLocale: locale()
|
|
28
|
+
}), ({ managerInstance, currentLocale }) => {
|
|
29
|
+
if (managerInstance && currentLocale) managerInstance.currentLocale.set(currentLocale);
|
|
30
|
+
});
|
|
31
|
+
onCleanup(() => {
|
|
32
|
+
import("@intlayer/editor").then(({ stopEditorClient }) => {
|
|
33
|
+
stopEditorClient();
|
|
24
34
|
}).catch(() => {});
|
|
25
35
|
});
|
|
26
36
|
};
|
|
27
|
-
export {
|
|
37
|
+
export { useEditor };
|
|
@@ -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,11 +1,14 @@
|
|
|
1
|
-
import { compact
|
|
2
|
-
import { useIntlayerContext
|
|
1
|
+
import { compact } from "@intlayer/core/formatters";
|
|
2
|
+
import { useIntlayerContext } from "../client/IntlayerProvider.mjs";
|
|
3
3
|
// src/format/useCompact.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Solid client hook that provides a localized compact number formatter.
|
|
6
|
+
*/
|
|
7
|
+
var useCompact = () => {
|
|
8
|
+
const { locale } = useIntlayerContext();
|
|
9
|
+
return (...args) => compact(args[0], {
|
|
10
|
+
...args[1],
|
|
11
|
+
locale: args[1]?.locale ?? locale()
|
|
9
12
|
});
|
|
10
13
|
};
|
|
11
|
-
export {
|
|
14
|
+
export { useCompact };
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { currency
|
|
2
|
-
import { useContext
|
|
3
|
-
import { IntlayerClientContext
|
|
1
|
+
import { currency } from "@intlayer/core/formatters";
|
|
2
|
+
import { useContext } from "solid-js";
|
|
3
|
+
import { IntlayerClientContext } from "../client/IntlayerProvider.mjs";
|
|
4
4
|
// src/format/useCurrency.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Solid client hook that provides a localized currency formatter.
|
|
7
|
+
*/
|
|
8
|
+
var useCurrency = () => {
|
|
9
|
+
const { locale } = useContext(IntlayerClientContext);
|
|
10
|
+
return (...args) => currency(args[0], {
|
|
11
|
+
...args[1],
|
|
12
|
+
locale: args[1]?.locale ?? locale()
|
|
10
13
|
});
|
|
11
14
|
};
|
|
12
|
-
export {
|
|
15
|
+
export { useCurrency };
|
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
import { date
|
|
2
|
-
import { useContext
|
|
3
|
-
import { IntlayerClientContext
|
|
1
|
+
import { date, presets } from "@intlayer/core/formatters";
|
|
2
|
+
import { useContext } from "solid-js";
|
|
3
|
+
import { IntlayerClientContext } from "../client/IntlayerProvider.mjs";
|
|
4
4
|
// src/format/useDate.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Solid client hook that provides a localized date/time formatter.
|
|
7
|
+
*
|
|
8
|
+
* @returns {(date: Date | string | number, options?: DateProps) => string}
|
|
9
|
+
* A function to format dates into localized strings.
|
|
10
|
+
*/
|
|
11
|
+
var useDate = () => {
|
|
12
|
+
const { locale } = useContext(IntlayerClientContext);
|
|
13
|
+
return (...args) => {
|
|
14
|
+
const options = typeof args[1] === "string" ? {
|
|
15
|
+
...presets[args[1]],
|
|
16
|
+
locale: locale()
|
|
11
17
|
} : {
|
|
12
|
-
...
|
|
13
|
-
locale:
|
|
18
|
+
...args[1],
|
|
19
|
+
locale: args[1]?.locale ?? locale()
|
|
14
20
|
};
|
|
15
|
-
return
|
|
21
|
+
return date(args[0], options);
|
|
16
22
|
};
|
|
17
23
|
};
|
|
18
|
-
export {
|
|
24
|
+
export { useDate };
|
|
@@ -1,12 +1,30 @@
|
|
|
1
|
-
import { bindIntl
|
|
2
|
-
import { createMemo
|
|
3
|
-
import { IntlayerClientContext
|
|
1
|
+
import { bindIntl } from "@intlayer/core/formatters";
|
|
2
|
+
import { createMemo, useContext } from "solid-js";
|
|
3
|
+
import { IntlayerClientContext } from "../client/IntlayerProvider.mjs";
|
|
4
4
|
// src/format/useIntl.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Solid client hook that provides a locale-bound `Intl` object.
|
|
7
|
+
*
|
|
8
|
+
* It acts exactly like the native `Intl` object, but acts as a proxy to:
|
|
9
|
+
* 1. Inject the current locale automatically if none is provided.
|
|
10
|
+
* 2. Use the performance-optimized `CachedIntl` under the hood.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const intl = useIntl(); // uses context locale
|
|
15
|
+
*
|
|
16
|
+
* // Standard API, but no need to pass locale as the first argument
|
|
17
|
+
* const formatted = new (intl().NumberFormat)({
|
|
18
|
+
* style: 'currency',
|
|
19
|
+
* currency: 'USD'
|
|
20
|
+
* }).format(123.45);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
var useIntl = (locale) => {
|
|
24
|
+
const context = useContext(IntlayerClientContext);
|
|
25
|
+
return createMemo(() => {
|
|
26
|
+
const currentLocale = locale ?? context.locale();
|
|
27
|
+
return bindIntl(currentLocale);
|
|
10
28
|
});
|
|
11
29
|
};
|
|
12
|
-
export {
|
|
30
|
+
export { useIntl };
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { list
|
|
2
|
-
import { useIntlayerContext
|
|
1
|
+
import { list } from "@intlayer/core/formatters";
|
|
2
|
+
import { useIntlayerContext } from "../client/IntlayerProvider.mjs";
|
|
3
3
|
// src/format/useList.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Solid client hook that provides a localized list formatter.
|
|
6
|
+
*/
|
|
7
|
+
var useList = () => {
|
|
8
|
+
const { locale } = useIntlayerContext();
|
|
9
|
+
return (...args) => list(args[0], {
|
|
10
|
+
...args[1],
|
|
11
|
+
locale: args[1]?.locale ?? locale()
|
|
9
12
|
});
|
|
10
13
|
};
|
|
11
|
-
export {
|
|
14
|
+
export { useList };
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import { number
|
|
2
|
-
import { useContext
|
|
3
|
-
import { IntlayerClientContext
|
|
1
|
+
import { number } from "@intlayer/core/formatters";
|
|
2
|
+
import { useContext } from "solid-js";
|
|
3
|
+
import { IntlayerClientContext } from "../client/IntlayerProvider.mjs";
|
|
4
4
|
// src/format/useNumber.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Solid client hook that provides a localized number formatter.
|
|
7
|
+
*
|
|
8
|
+
* @returns {(value: string | number, options?: import("@intlayer/core/formatters").NumberProps) => string}
|
|
9
|
+
* A function to format numbers into localized strings.
|
|
10
|
+
*/
|
|
11
|
+
var useNumber = () => {
|
|
12
|
+
const { locale } = useContext(IntlayerClientContext);
|
|
13
|
+
return (...args) => number(args[0], {
|
|
14
|
+
...args[1],
|
|
15
|
+
locale: args[1]?.locale ?? locale()
|
|
10
16
|
});
|
|
11
17
|
};
|
|
12
|
-
export {
|
|
18
|
+
export { useNumber };
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { percentage
|
|
2
|
-
import { useContext
|
|
3
|
-
import { IntlayerClientContext
|
|
1
|
+
import { percentage } from "@intlayer/core/formatters";
|
|
2
|
+
import { useContext } from "solid-js";
|
|
3
|
+
import { IntlayerClientContext } from "../client/IntlayerProvider.mjs";
|
|
4
4
|
// src/format/usePercentage.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Solid client hook that provides a localized percentage formatter.
|
|
7
|
+
*/
|
|
8
|
+
var usePercentage = () => {
|
|
9
|
+
const { locale } = useContext(IntlayerClientContext);
|
|
10
|
+
return (...args) => percentage(args[0], {
|
|
11
|
+
...args[1],
|
|
12
|
+
locale: args[1]?.locale ?? locale()
|
|
10
13
|
});
|
|
11
14
|
};
|
|
12
|
-
export {
|
|
15
|
+
export { usePercentage };
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { relativeTime
|
|
2
|
-
import { useContext
|
|
3
|
-
import { IntlayerClientContext
|
|
1
|
+
import { relativeTime } from "@intlayer/core/formatters";
|
|
2
|
+
import { useContext } from "solid-js";
|
|
3
|
+
import { IntlayerClientContext } from "../client/IntlayerProvider.mjs";
|
|
4
4
|
// src/format/useRelativeTime.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Solid client hook that provides a localized relative time formatter.
|
|
7
|
+
*/
|
|
8
|
+
var useRelativeTime = () => {
|
|
9
|
+
const { locale } = useContext(IntlayerClientContext);
|
|
10
|
+
return (...args) => relativeTime(args[0], args[1], {
|
|
11
|
+
...args[2],
|
|
12
|
+
locale: args[2]?.locale ?? locale()
|
|
10
13
|
});
|
|
11
14
|
};
|
|
12
|
-
export {
|
|
15
|
+
export { useRelativeTime };
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { units
|
|
2
|
-
import { useIntlayerContext
|
|
1
|
+
import { units } from "@intlayer/core/formatters";
|
|
2
|
+
import { useIntlayerContext } from "../client/IntlayerProvider.mjs";
|
|
3
3
|
// src/format/useUnit.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Solid client hook that provides a localized unit formatter.
|
|
6
|
+
*/
|
|
7
|
+
var useUnit = () => {
|
|
8
|
+
const { locale } = useIntlayerContext();
|
|
9
|
+
return (...args) => units(args[0], {
|
|
10
|
+
...args[1],
|
|
11
|
+
locale: args[1]?.locale ?? locale()
|
|
9
12
|
});
|
|
10
13
|
};
|
|
11
|
-
export {
|
|
14
|
+
export { useUnit };
|