preact-intlayer 8.1.2 → 8.1.3
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 +1 -16
- package/dist/cjs/IntlayerNode.cjs.map +1 -1
- package/dist/cjs/UI/ContentSelector.cjs +1 -98
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -29
- package/dist/cjs/client/IntlayerProvider.cjs +1 -91
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/format/index.cjs +1 -18
- package/dist/cjs/client/format/useCompact.cjs +1 -29
- package/dist/cjs/client/format/useCompact.cjs.map +1 -1
- package/dist/cjs/client/format/useCurrency.cjs +1 -43
- package/dist/cjs/client/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/client/format/useDate.cjs +1 -45
- package/dist/cjs/client/format/useDate.cjs.map +1 -1
- package/dist/cjs/client/format/useIntl.cjs +1 -33
- package/dist/cjs/client/format/useIntl.cjs.map +1 -1
- package/dist/cjs/client/format/useList.cjs +1 -40
- package/dist/cjs/client/format/useList.cjs.map +1 -1
- package/dist/cjs/client/format/useNumber.cjs +1 -41
- package/dist/cjs/client/format/useNumber.cjs.map +1 -1
- package/dist/cjs/client/format/usePercentage.cjs +1 -37
- package/dist/cjs/client/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/client/format/useRelativeTime.cjs +1 -37
- package/dist/cjs/client/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/client/format/useUnit.cjs +1 -36
- package/dist/cjs/client/format/useUnit.cjs.map +1 -1
- package/dist/cjs/client/index.cjs +1 -32
- package/dist/cjs/client/t.cjs +1 -21
- package/dist/cjs/client/t.cjs.map +1 -1
- package/dist/cjs/client/useContent.cjs +1 -19
- package/dist/cjs/client/useContent.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +1 -27
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +1 -24
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +1 -23
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +1 -42
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLoadDynamic.cjs +1 -27
- package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +1 -56
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleBase.cjs +1 -26
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +1 -58
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.cjs +1 -35
- package/dist/cjs/client/useTraduction.cjs.map +1 -1
- package/dist/cjs/editor/CommunicatorContext.cjs +1 -39
- package/dist/cjs/editor/CommunicatorContext.cjs.map +1 -1
- package/dist/cjs/editor/ConfigurationContext.cjs +1 -26
- package/dist/cjs/editor/ConfigurationContext.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelectorWrapper.cjs +1 -58
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/editor/DictionariesRecordContext.cjs +1 -48
- package/dist/cjs/editor/DictionariesRecordContext.cjs.map +1 -1
- package/dist/cjs/editor/EditedContentContext.cjs +1 -163
- package/dist/cjs/editor/EditedContentContext.cjs.map +1 -1
- package/dist/cjs/editor/EditorEnabledContext.cjs +1 -34
- package/dist/cjs/editor/EditorEnabledContext.cjs.map +1 -1
- package/dist/cjs/editor/EditorProvider.cjs +1 -64
- package/dist/cjs/editor/EditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/FocusDictionaryContext.cjs +1 -54
- package/dist/cjs/editor/FocusDictionaryContext.cjs.map +1 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs +1 -63
- package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/index.cjs +1 -4
- package/dist/cjs/editor/useCrossFrameMessageListener.cjs +1 -78
- package/dist/cjs/editor/useCrossFrameMessageListener.cjs.map +1 -1
- package/dist/cjs/editor/useCrossFrameState.cjs +1 -108
- package/dist/cjs/editor/useCrossFrameState.cjs.map +1 -1
- package/dist/cjs/editor/useCrossURLPathState.cjs +1 -67
- package/dist/cjs/editor/useCrossURLPathState.cjs.map +1 -1
- package/dist/cjs/editor/useEditedContentRenderer.cjs +1 -29
- package/dist/cjs/editor/useEditedContentRenderer.cjs.map +1 -1
- package/dist/cjs/editor/useIframeClickInterceptor.cjs +1 -24
- package/dist/cjs/editor/useIframeClickInterceptor.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs +1 -19
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +1 -19
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/html/HTMLProvider.cjs +1 -19
- package/dist/cjs/html/HTMLProvider.cjs.map +1 -1
- package/dist/cjs/html/HTMLRenderer.cjs +1 -61
- package/dist/cjs/html/HTMLRenderer.cjs.map +1 -1
- package/dist/cjs/html/index.cjs +1 -10
- package/dist/cjs/index.cjs +1 -57
- package/dist/cjs/markdown/MarkdownProvider.cjs +1 -49
- package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +1 -77
- package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs +1 -31
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs.map +1 -1
- package/dist/cjs/markdown/compiler.cjs +1 -24
- package/dist/cjs/markdown/compiler.cjs.map +1 -1
- package/dist/cjs/markdown/index.cjs +1 -23
- package/dist/cjs/markdown/runtime.cjs +1 -18
- package/dist/cjs/markdown/runtime.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +1 -197
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/preactElement/renderPreactElement.cjs +1 -42
- package/dist/cjs/preactElement/renderPreactElement.cjs.map +1 -1
- package/dist/esm/IntlayerNode.mjs +1 -14
- package/dist/esm/IntlayerNode.mjs.map +1 -1
- package/dist/esm/UI/ContentSelector.mjs +1 -96
- package/dist/esm/UI/ContentSelector.mjs.map +1 -1
- package/dist/esm/client/IntlayerProvider.mjs +1 -85
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/format/index.mjs +1 -10
- package/dist/esm/client/format/useCompact.mjs +1 -27
- package/dist/esm/client/format/useCompact.mjs.map +1 -1
- package/dist/esm/client/format/useCurrency.mjs +1 -41
- package/dist/esm/client/format/useCurrency.mjs.map +1 -1
- package/dist/esm/client/format/useDate.mjs +1 -43
- package/dist/esm/client/format/useDate.mjs.map +1 -1
- package/dist/esm/client/format/useIntl.mjs +1 -31
- package/dist/esm/client/format/useIntl.mjs.map +1 -1
- package/dist/esm/client/format/useList.mjs +1 -38
- package/dist/esm/client/format/useList.mjs.map +1 -1
- package/dist/esm/client/format/useNumber.mjs +1 -39
- package/dist/esm/client/format/useNumber.mjs.map +1 -1
- package/dist/esm/client/format/usePercentage.mjs +1 -35
- package/dist/esm/client/format/usePercentage.mjs.map +1 -1
- package/dist/esm/client/format/useRelativeTime.mjs +1 -35
- package/dist/esm/client/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/client/format/useUnit.mjs +1 -34
- package/dist/esm/client/format/useUnit.mjs.map +1 -1
- package/dist/esm/client/index.mjs +1 -13
- package/dist/esm/client/t.mjs +1 -19
- package/dist/esm/client/t.mjs.map +1 -1
- package/dist/esm/client/useContent.mjs +1 -18
- package/dist/esm/client/useContent.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +1 -25
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +1 -21
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +1 -21
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +1 -40
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLoadDynamic.mjs +1 -25
- package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +1 -53
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.mjs +1 -23
- package/dist/esm/client/useLocaleBase.mjs.map +1 -1
- package/dist/esm/client/useLocaleStorage.mjs +1 -51
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
- package/dist/esm/client/useTraduction.mjs +1 -33
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/editor/CommunicatorContext.mjs +1 -35
- package/dist/esm/editor/CommunicatorContext.mjs.map +1 -1
- package/dist/esm/editor/ConfigurationContext.mjs +1 -22
- package/dist/esm/editor/ConfigurationContext.mjs.map +1 -1
- package/dist/esm/editor/ContentSelectorWrapper.mjs +1 -56
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/editor/DictionariesRecordContext.mjs +1 -44
- package/dist/esm/editor/DictionariesRecordContext.mjs.map +1 -1
- package/dist/esm/editor/EditedContentContext.mjs +1 -157
- package/dist/esm/editor/EditedContentContext.mjs.map +1 -1
- package/dist/esm/editor/EditorEnabledContext.mjs +1 -28
- package/dist/esm/editor/EditorEnabledContext.mjs.map +1 -1
- package/dist/esm/editor/EditorProvider.mjs +1 -62
- package/dist/esm/editor/EditorProvider.mjs.map +1 -1
- package/dist/esm/editor/FocusDictionaryContext.mjs +1 -50
- package/dist/esm/editor/FocusDictionaryContext.mjs.map +1 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs +1 -60
- package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
- package/dist/esm/editor/index.mjs +1 -3
- package/dist/esm/editor/useCrossFrameMessageListener.mjs +1 -76
- package/dist/esm/editor/useCrossFrameMessageListener.mjs.map +1 -1
- package/dist/esm/editor/useCrossFrameState.mjs +1 -106
- package/dist/esm/editor/useCrossFrameState.mjs.map +1 -1
- package/dist/esm/editor/useCrossURLPathState.mjs +1 -64
- package/dist/esm/editor/useCrossURLPathState.mjs.map +1 -1
- package/dist/esm/editor/useEditedContentRenderer.mjs +1 -26
- package/dist/esm/editor/useEditedContentRenderer.mjs.map +1 -1
- package/dist/esm/editor/useIframeClickInterceptor.mjs +1 -21
- package/dist/esm/editor/useIframeClickInterceptor.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs +1 -17
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs +1 -17
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/html/HTMLProvider.mjs +1 -16
- package/dist/esm/html/HTMLProvider.mjs.map +1 -1
- package/dist/esm/html/HTMLRenderer.mjs +1 -56
- package/dist/esm/html/HTMLRenderer.mjs.map +1 -1
- package/dist/esm/html/index.mjs +1 -4
- package/dist/esm/index.mjs +1 -22
- package/dist/esm/markdown/MarkdownProvider.mjs +1 -46
- package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRenderer.mjs +1 -73
- package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs +1 -28
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs.map +1 -1
- package/dist/esm/markdown/compiler.mjs +1 -17
- package/dist/esm/markdown/compiler.mjs.map +1 -1
- package/dist/esm/markdown/index.mjs +1 -7
- package/dist/esm/markdown/runtime.mjs +1 -15
- package/dist/esm/markdown/runtime.mjs.map +1 -1
- package/dist/esm/plugins.mjs +1 -190
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/preactElement/renderPreactElement.mjs +1 -40
- package/dist/esm/preactElement/renderPreactElement.mjs.map +1 -1
- package/dist/types/IntlayerNode.d.ts +1 -1
- package/dist/types/client/format/useDate.d.ts +1 -1
- package/dist/types/client/useDictionary.d.ts +2 -2
- package/dist/types/client/useDictionary.d.ts.map +1 -1
- package/dist/types/client/useDictionaryDynamic.d.ts +2 -2
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts +1 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
- package/dist/types/editor/EditedContentContext.d.ts.map +1 -1
- package/dist/types/getDictionary.d.ts +1 -1
- package/dist/types/getIntlayer.d.ts +1 -1
- package/dist/types/getIntlayer.d.ts.map +1 -1
- package/dist/types/html/HTMLRenderer.d.ts.map +1 -1
- package/dist/types/html/types.d.ts +1 -1
- package/dist/types/html/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/markdown/MarkdownRendererPlugin.d.ts.map +1 -1
- package/dist/types/markdown/compiler.d.ts +1 -1
- package/dist/types/markdown/runtime.d.ts +1 -1
- package/dist/types/plugins.d.ts +2 -2
- package/dist/types/plugins.d.ts.map +1 -1
- package/package.json +8 -8
|
@@ -1,42 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_client_IntlayerProvider = require('../IntlayerProvider.cjs');
|
|
6
|
-
let _intlayer_core = require("@intlayer/core");
|
|
7
|
-
let preact_hooks = require("preact/hooks");
|
|
8
|
-
|
|
9
|
-
//#region src/client/format/useNumber.ts
|
|
10
|
-
/**
|
|
11
|
-
* React client hook that provides a localized number formatter.
|
|
12
|
-
*
|
|
13
|
-
* Uses the current locale from {@link useLocaleBase} and returns
|
|
14
|
-
* a function that can be used to format numbers consistently
|
|
15
|
-
* according to the user's locale.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```tsx
|
|
19
|
-
* const formatNumber = useNumber();
|
|
20
|
-
*
|
|
21
|
-
* formatNumber(12345);
|
|
22
|
-
* // e.g. "12,345" (en-US)
|
|
23
|
-
* // e.g. "12 345" (fr-FR)
|
|
24
|
-
*
|
|
25
|
-
* formatNumber(0.75, { style: "percent" });
|
|
26
|
-
* // e.g. "75%"
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @returns {(value: string | number, options?: import("../createNumber").NumberProps) => string}
|
|
30
|
-
* A number formatting function bound to the active locale.
|
|
31
|
-
*/
|
|
32
|
-
const useNumber = () => {
|
|
33
|
-
const { locale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
34
|
-
return (0, preact_hooks.useCallback)((...args) => (0, _intlayer_core.number)(args[0], {
|
|
35
|
-
...args[1],
|
|
36
|
-
locale: args[1]?.locale ?? locale
|
|
37
|
-
}), [locale]);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
//#endregion
|
|
41
|
-
exports.useNumber = useNumber;
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../IntlayerProvider.cjs`);let t=require(`preact/hooks`),n=require(`@intlayer/core/formatters`);const r=()=>{let{locale:r}=(0,t.useContext)(e.IntlayerClientContext);return(0,t.useCallback)((...e)=>(0,n.number)(e[0],{...e[1],locale:e[1]?.locale??r}),[r])};exports.useNumber=r;
|
|
42
2
|
//# sourceMappingURL=useNumber.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNumber.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useNumber.ts"],"sourcesContent":["'use client';\n\nimport { number } from '@intlayer/core';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a localized number formatter.\n *\n * Uses the current locale from {@link useLocaleBase} and returns\n * a function that can be used to format numbers consistently\n * according to the user's locale.\n *\n * @example\n * ```tsx\n * const formatNumber = useNumber();\n *\n * formatNumber(12345);\n * // e.g. \"12,345\" (en-US)\n * // e.g. \"12 345\" (fr-FR)\n *\n * formatNumber(0.75, { style: \"percent\" });\n * // e.g. \"75%\"\n * ```\n *\n * @returns {(value: string | number, options?: import(\"../createNumber\").NumberProps) => string}\n * A number formatting function bound to the active locale.\n */\nexport const useNumber = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof number>) =>\n number(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useNumber.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useNumber.ts"],"sourcesContent":["'use client';\n\nimport { number } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a localized number formatter.\n *\n * Uses the current locale from {@link useLocaleBase} and returns\n * a function that can be used to format numbers consistently\n * according to the user's locale.\n *\n * @example\n * ```tsx\n * const formatNumber = useNumber();\n *\n * formatNumber(12345);\n * // e.g. \"12,345\" (en-US)\n * // e.g. \"12 345\" (fr-FR)\n *\n * formatNumber(0.75, { style: \"percent\" });\n * // e.g. \"75%\"\n * ```\n *\n * @returns {(value: string | number, options?: import(\"../createNumber\").NumberProps) => string}\n * A number formatting function bound to the active locale.\n */\nexport const useNumber = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof number>) =>\n number(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"gPA4BA,MAAa,MAAkB,CAC7B,GAAM,CAAE,WAAA,EAAA,EAAA,YAAsBA,EAAAA,sBAAsB,CAEpD,OAAA,EAAA,EAAA,cACG,GAAG,KAAA,EAAA,EAAA,QACK,EAAK,GAAI,CACd,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC,CACJ,CAAC,EAAO,CACT"}
|
|
@@ -1,38 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_client_IntlayerProvider = require('../IntlayerProvider.cjs');
|
|
6
|
-
let _intlayer_core = require("@intlayer/core");
|
|
7
|
-
let preact_hooks = require("preact/hooks");
|
|
8
|
-
|
|
9
|
-
//#region src/client/format/usePercentage.ts
|
|
10
|
-
/**
|
|
11
|
-
* React hook to provide a percentage formatter function
|
|
12
|
-
* based on the current application locale.
|
|
13
|
-
*
|
|
14
|
-
* This hook retrieves the active locale using {@link useLocaleBase}
|
|
15
|
-
* and memoizes a `createPercentage` instance for that locale.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```tsx
|
|
19
|
-
* const formatPercentage = usePercentage();
|
|
20
|
-
*
|
|
21
|
-
* const result = formatPercentage(0.875, { maximumFractionDigits: 1 });
|
|
22
|
-
* // "87.5%" (depending on locale)
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* @returns {(value: string | number, options?: Omit<PercentageOptions, "value">) => string}
|
|
26
|
-
* A function that formats numbers or numeric strings into localized percentages.
|
|
27
|
-
*/
|
|
28
|
-
const usePercentage = () => {
|
|
29
|
-
const { locale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
30
|
-
return (0, preact_hooks.useCallback)((...args) => (0, _intlayer_core.percentage)(args[0], {
|
|
31
|
-
...args[1],
|
|
32
|
-
locale: args[1]?.locale ?? locale
|
|
33
|
-
}), [locale]);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
//#endregion
|
|
37
|
-
exports.usePercentage = usePercentage;
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../IntlayerProvider.cjs`);let t=require(`preact/hooks`),n=require(`@intlayer/core/formatters`);const r=()=>{let{locale:r}=(0,t.useContext)(e.IntlayerClientContext);return(0,t.useCallback)((...e)=>(0,n.percentage)(e[0],{...e[1],locale:e[1]?.locale??r}),[r])};exports.usePercentage=r;
|
|
38
2
|
//# sourceMappingURL=usePercentage.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePercentage.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/usePercentage.ts"],"sourcesContent":["'use client';\n\nimport { percentage } from '@intlayer/core';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React hook to provide a percentage formatter function\n * based on the current application locale.\n *\n * This hook retrieves the active locale using {@link useLocaleBase}\n * and memoizes a `createPercentage` instance for that locale.\n *\n * @example\n * ```tsx\n * const formatPercentage = usePercentage();\n *\n * const result = formatPercentage(0.875, { maximumFractionDigits: 1 });\n * // \"87.5%\" (depending on locale)\n * ```\n *\n * @returns {(value: string | number, options?: Omit<PercentageOptions, \"value\">) => string}\n * A function that formats numbers or numeric strings into localized percentages.\n */\nexport const usePercentage = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof percentage>) =>\n percentage(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePercentage.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/usePercentage.ts"],"sourcesContent":["'use client';\n\nimport { percentage } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React hook to provide a percentage formatter function\n * based on the current application locale.\n *\n * This hook retrieves the active locale using {@link useLocaleBase}\n * and memoizes a `createPercentage` instance for that locale.\n *\n * @example\n * ```tsx\n * const formatPercentage = usePercentage();\n *\n * const result = formatPercentage(0.875, { maximumFractionDigits: 1 });\n * // \"87.5%\" (depending on locale)\n * ```\n *\n * @returns {(value: string | number, options?: Omit<PercentageOptions, \"value\">) => string}\n * A function that formats numbers or numeric strings into localized percentages.\n */\nexport const usePercentage = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof percentage>) =>\n percentage(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"gPAwBA,MAAa,MAAsB,CACjC,GAAM,CAAE,WAAA,EAAA,EAAA,YAAsBA,EAAAA,sBAAsB,CAEpD,OAAA,EAAA,EAAA,cACG,GAAG,KAAA,EAAA,EAAA,YACS,EAAK,GAAI,CAClB,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC,CACJ,CAAC,EAAO,CACT"}
|
|
@@ -1,38 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_client_IntlayerProvider = require('../IntlayerProvider.cjs');
|
|
6
|
-
let _intlayer_core = require("@intlayer/core");
|
|
7
|
-
let preact_hooks = require("preact/hooks");
|
|
8
|
-
|
|
9
|
-
//#region src/client/format/useRelativeTime.ts
|
|
10
|
-
/**
|
|
11
|
-
* Client-side React hook for accessing a localized relative time formatter.
|
|
12
|
-
*
|
|
13
|
-
* This hook:
|
|
14
|
-
* - Reads the current locale from {@link useLocaleBase}.
|
|
15
|
-
* - Creates a new relative time formatter with {@link createRelativeTime}.
|
|
16
|
-
* - Returns a function that can format time differences into localized strings.
|
|
17
|
-
*
|
|
18
|
-
* Example:
|
|
19
|
-
* ```tsx
|
|
20
|
-
* const relativeTime = useRelativeTime();
|
|
21
|
-
* const formatted = relativeTime(new Date("2024-08-01"), new Date());
|
|
22
|
-
* // e.g., "2 weeks ago"
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* @returns {ReturnType<typeof createRelativeTime>} A relative time formatting function
|
|
26
|
-
* bound to the current client locale.
|
|
27
|
-
*/
|
|
28
|
-
const useRelativeTime = () => {
|
|
29
|
-
const { locale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
30
|
-
return (0, preact_hooks.useCallback)((...args) => (0, _intlayer_core.relativeTime)(args[0], args[1], {
|
|
31
|
-
...args[2],
|
|
32
|
-
locale: args[2]?.locale ?? locale
|
|
33
|
-
}), [locale]);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
//#endregion
|
|
37
|
-
exports.useRelativeTime = useRelativeTime;
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../IntlayerProvider.cjs`);let t=require(`preact/hooks`),n=require(`@intlayer/core/formatters`);const r=()=>{let{locale:r}=(0,t.useContext)(e.IntlayerClientContext);return(0,t.useCallback)((...e)=>(0,n.relativeTime)(e[0],e[1],{...e[2],locale:e[2]?.locale??r}),[r])};exports.useRelativeTime=r;
|
|
38
2
|
//# sourceMappingURL=useRelativeTime.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRelativeTime.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useRelativeTime.ts"],"sourcesContent":["'use client';\n\nimport { relativeTime } from '@intlayer/core';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * Client-side React hook for accessing a localized relative time formatter.\n *\n * This hook:\n * - Reads the current locale from {@link useLocaleBase}.\n * - Creates a new relative time formatter with {@link createRelativeTime}.\n * - Returns a function that can format time differences into localized strings.\n *\n * Example:\n * ```tsx\n * const relativeTime = useRelativeTime();\n * const formatted = relativeTime(new Date(\"2024-08-01\"), new Date());\n * // e.g., \"2 weeks ago\"\n * ```\n *\n * @returns {ReturnType<typeof createRelativeTime>} A relative time formatting function\n * bound to the current client locale.\n */\nexport const useRelativeTime = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof relativeTime>) =>\n relativeTime(args[0], args[1], {\n ...args[2],\n locale: args[2]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRelativeTime.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useRelativeTime.ts"],"sourcesContent":["'use client';\n\nimport { relativeTime } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * Client-side React hook for accessing a localized relative time formatter.\n *\n * This hook:\n * - Reads the current locale from {@link useLocaleBase}.\n * - Creates a new relative time formatter with {@link createRelativeTime}.\n * - Returns a function that can format time differences into localized strings.\n *\n * Example:\n * ```tsx\n * const relativeTime = useRelativeTime();\n * const formatted = relativeTime(new Date(\"2024-08-01\"), new Date());\n * // e.g., \"2 weeks ago\"\n * ```\n *\n * @returns {ReturnType<typeof createRelativeTime>} A relative time formatting function\n * bound to the current client locale.\n */\nexport const useRelativeTime = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof relativeTime>) =>\n relativeTime(args[0], args[1], {\n ...args[2],\n locale: args[2]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"gPAwBA,MAAa,MAAwB,CACnC,GAAM,CAAE,WAAA,EAAA,EAAA,YAAsBA,EAAAA,sBAAsB,CAEpD,OAAA,EAAA,EAAA,cACG,GAAG,KAAA,EAAA,EAAA,cACW,EAAK,GAAI,EAAK,GAAI,CAC7B,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC,CACJ,CAAC,EAAO,CACT"}
|
|
@@ -1,37 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_client_IntlayerProvider = require('../IntlayerProvider.cjs');
|
|
6
|
-
let _intlayer_core = require("@intlayer/core");
|
|
7
|
-
let preact_hooks = require("preact/hooks");
|
|
8
|
-
|
|
9
|
-
//#region src/client/format/useUnit.ts
|
|
10
|
-
/**
|
|
11
|
-
* React hook that provides a unit formatting function
|
|
12
|
-
* based on the current locale from {@link useLocaleBase}.
|
|
13
|
-
*
|
|
14
|
-
* This hook wraps {@link createUnit} to return a formatter
|
|
15
|
-
* that can convert values into human-readable localized units
|
|
16
|
-
* (e.g., "10 km", "5 lbs").
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```tsx
|
|
20
|
-
* const formatUnit = useUnit();
|
|
21
|
-
* const distance = formatUnit(10, { unit: "kilometer" });
|
|
22
|
-
* // "10 km" (depending on locale)
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* @returns {Function} A unit formatting function that accepts a value and optional formatting options.
|
|
26
|
-
*/
|
|
27
|
-
const useUnit = () => {
|
|
28
|
-
const { locale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
29
|
-
return (0, preact_hooks.useCallback)((...args) => (0, _intlayer_core.units)(args[0], {
|
|
30
|
-
...args[1],
|
|
31
|
-
locale: args[1]?.locale ?? locale
|
|
32
|
-
}), [locale]);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
//#endregion
|
|
36
|
-
exports.useUnit = useUnit;
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../IntlayerProvider.cjs`);let t=require(`preact/hooks`),n=require(`@intlayer/core/formatters`);const r=()=>{let{locale:r}=(0,t.useContext)(e.IntlayerClientContext);return(0,t.useCallback)((...e)=>(0,n.units)(e[0],{...e[1],locale:e[1]?.locale??r}),[r])};exports.useUnit=r;
|
|
37
2
|
//# sourceMappingURL=useUnit.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUnit.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useUnit.ts"],"sourcesContent":["'use client';\n\nimport { units } from '@intlayer/core';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React hook that provides a unit formatting function\n * based on the current locale from {@link useLocaleBase}.\n *\n * This hook wraps {@link createUnit} to return a formatter\n * that can convert values into human-readable localized units\n * (e.g., \"10 km\", \"5 lbs\").\n *\n * @example\n * ```tsx\n * const formatUnit = useUnit();\n * const distance = formatUnit(10, { unit: \"kilometer\" });\n * // \"10 km\" (depending on locale)\n * ```\n *\n * @returns {Function} A unit formatting function that accepts a value and optional formatting options.\n */\nexport const useUnit = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof units>) =>\n units(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useUnit.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useUnit.ts"],"sourcesContent":["'use client';\n\nimport { units } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React hook that provides a unit formatting function\n * based on the current locale from {@link useLocaleBase}.\n *\n * This hook wraps {@link createUnit} to return a formatter\n * that can convert values into human-readable localized units\n * (e.g., \"10 km\", \"5 lbs\").\n *\n * @example\n * ```tsx\n * const formatUnit = useUnit();\n * const distance = formatUnit(10, { unit: \"kilometer\" });\n * // \"10 km\" (depending on locale)\n * ```\n *\n * @returns {Function} A unit formatting function that accepts a value and optional formatting options.\n */\nexport const useUnit = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof units>) =>\n units(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"gPAuBA,MAAa,MAAgB,CAC3B,GAAM,CAAE,WAAA,EAAA,EAAA,YAAsBA,EAAAA,sBAAsB,CAEpD,OAAA,EAAA,EAAA,cACG,GAAG,KAAA,EAAA,EAAA,OACI,EAAK,GAAI,CACb,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC,CACJ,CAAC,EAAO,CACT"}
|
|
@@ -1,32 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_client_useLocaleStorage = require('./useLocaleStorage.cjs');
|
|
3
|
-
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
4
|
-
const require_client_format_useIntl = require('./format/useIntl.cjs');
|
|
5
|
-
const require_client_t = require('./t.cjs');
|
|
6
|
-
const require_client_useDictionary = require('./useDictionary.cjs');
|
|
7
|
-
const require_client_useDictionaryAsync = require('./useDictionaryAsync.cjs');
|
|
8
|
-
const require_client_useLoadDynamic = require('./useLoadDynamic.cjs');
|
|
9
|
-
const require_client_useDictionaryDynamic = require('./useDictionaryDynamic.cjs');
|
|
10
|
-
const require_client_useIntlayer = require('./useIntlayer.cjs');
|
|
11
|
-
const require_client_useLocale = require('./useLocale.cjs');
|
|
12
|
-
const require_client_useLocaleBase = require('./useLocaleBase.cjs');
|
|
13
|
-
|
|
14
|
-
exports.IntlayerClientContext = require_client_IntlayerProvider.IntlayerClientContext;
|
|
15
|
-
exports.IntlayerProvider = require_client_IntlayerProvider.IntlayerProvider;
|
|
16
|
-
exports.IntlayerProviderContent = require_client_IntlayerProvider.IntlayerProviderContent;
|
|
17
|
-
exports.localeCookie = require_client_useLocaleStorage.localeCookie;
|
|
18
|
-
exports.localeInStorage = require_client_useLocaleStorage.localeInStorage;
|
|
19
|
-
exports.setLocaleCookie = require_client_useLocaleStorage.setLocaleCookie;
|
|
20
|
-
exports.setLocaleInStorage = require_client_useLocaleStorage.setLocaleInStorage;
|
|
21
|
-
exports.t = require_client_t.t;
|
|
22
|
-
exports.useDictionary = require_client_useDictionary.useDictionary;
|
|
23
|
-
exports.useDictionaryAsync = require_client_useDictionaryAsync.useDictionaryAsync;
|
|
24
|
-
exports.useDictionaryDynamic = require_client_useDictionaryDynamic.useDictionaryDynamic;
|
|
25
|
-
exports.useIntl = require_client_format_useIntl.useIntl;
|
|
26
|
-
exports.useIntlayer = require_client_useIntlayer.useIntlayer;
|
|
27
|
-
exports.useIntlayerContext = require_client_IntlayerProvider.useIntlayerContext;
|
|
28
|
-
exports.useLoadDynamic = require_client_useLoadDynamic.useLoadDynamic;
|
|
29
|
-
exports.useLocale = require_client_useLocale.useLocale;
|
|
30
|
-
exports.useLocaleBase = require_client_useLocaleBase.useLocaleBase;
|
|
31
|
-
exports.useLocaleCookie = require_client_useLocaleStorage.useLocaleCookie;
|
|
32
|
-
exports.useLocaleStorage = require_client_useLocaleStorage.useLocaleStorage;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./useLocaleStorage.cjs`),t=require(`./IntlayerProvider.cjs`),n=require(`./format/useIntl.cjs`),r=require(`./t.cjs`),i=require(`./useDictionary.cjs`),a=require(`./useDictionaryAsync.cjs`),o=require(`./useLoadDynamic.cjs`),s=require(`./useDictionaryDynamic.cjs`),c=require(`./useIntlayer.cjs`),l=require(`./useLocale.cjs`),u=require(`./useLocaleBase.cjs`);exports.IntlayerClientContext=t.IntlayerClientContext,exports.IntlayerProvider=t.IntlayerProvider,exports.IntlayerProviderContent=t.IntlayerProviderContent,exports.localeCookie=e.localeCookie,exports.localeInStorage=e.localeInStorage,exports.setLocaleCookie=e.setLocaleCookie,exports.setLocaleInStorage=e.setLocaleInStorage,exports.t=r.t,exports.useDictionary=i.useDictionary,exports.useDictionaryAsync=a.useDictionaryAsync,exports.useDictionaryDynamic=s.useDictionaryDynamic,exports.useIntl=n.useIntl,exports.useIntlayer=c.useIntlayer,exports.useIntlayerContext=t.useIntlayerContext,exports.useLoadDynamic=o.useLoadDynamic,exports.useLocale=l.useLocale,exports.useLocaleBase=u.useLocaleBase,exports.useLocaleCookie=e.useLocaleCookie,exports.useLocaleStorage=e.useLocaleStorage;
|
package/dist/cjs/client/t.cjs
CHANGED
|
@@ -1,22 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
6
|
-
let _intlayer_core = require("@intlayer/core");
|
|
7
|
-
let preact_hooks = require("preact/hooks");
|
|
8
|
-
|
|
9
|
-
//#region src/client/t.ts
|
|
10
|
-
/**
|
|
11
|
-
* On the client side, this function returns the translation of the provided multilang content.
|
|
12
|
-
*
|
|
13
|
-
* If the locale is not provided, it will use the locale from the client context
|
|
14
|
-
*/
|
|
15
|
-
const t = (multilangContent, locale) => {
|
|
16
|
-
const { locale: currentLocale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
17
|
-
return (0, _intlayer_core.getTranslation)(multilangContent, locale ?? currentLocale);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
//#endregion
|
|
21
|
-
exports.t = t;
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./IntlayerProvider.cjs`);let t=require(`@intlayer/core/interpreter`),n=require(`preact/hooks`);const r=(r,i)=>{let{locale:a}=(0,n.useContext)(e.IntlayerClientContext);return(0,t.getTranslation)(r,i??a)};exports.t=r;
|
|
22
2
|
//# sourceMappingURL=t.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"t.cjs","names":["IntlayerClientContext"],"sources":["../../../src/client/t.ts"],"sourcesContent":["'use client';\n\nimport { getTranslation } from '@intlayer/core';\nimport type { Locale, StrictModeLocaleMap } from '@intlayer/types';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, this function returns the translation of the provided multilang content.\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const t = <Content = string>(\n multilangContent: StrictModeLocaleMap<Content>,\n locale?: Locale\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getTranslation<Content>(multilangContent, localeTarget);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"t.cjs","names":["IntlayerClientContext"],"sources":["../../../src/client/t.ts"],"sourcesContent":["'use client';\n\nimport { getTranslation } from '@intlayer/core/interpreter';\nimport type { Locale, StrictModeLocaleMap } from '@intlayer/types';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, this function returns the translation of the provided multilang content.\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const t = <Content = string>(\n multilangContent: StrictModeLocaleMap<Content>,\n locale?: Locale\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getTranslation<Content>(multilangContent, localeTarget);\n};\n"],"mappings":"6OAYA,MAAa,GACX,EACA,IACG,CACH,GAAM,CAAE,OAAQ,IAAA,EAAA,EAAA,YAA6BA,EAAAA,sBAAsB,CAGnE,OAAA,EAAA,EAAA,gBAA+B,EAFV,GAAU,EAE+B"}
|
|
@@ -1,20 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_client_useLocaleBase = require('./useLocaleBase.cjs');
|
|
3
|
-
const require_client_useTraduction = require('./useTraduction.cjs');
|
|
4
|
-
|
|
5
|
-
//#region src/client/useContent.ts
|
|
6
|
-
/**
|
|
7
|
-
* On the client side, hook to get the translation content based on the locale
|
|
8
|
-
*/
|
|
9
|
-
const useContent = (languageContent) => {
|
|
10
|
-
const { locale } = require_client_useLocaleBase.useLocaleBase();
|
|
11
|
-
return {
|
|
12
|
-
locale,
|
|
13
|
-
content: require_client_useTraduction.useTranslation(languageContent),
|
|
14
|
-
t: require_client_useTraduction.useTranslation
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
|
-
exports.useContent = useContent;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./useLocaleBase.cjs`),t=require(`./useTraduction.cjs`),n=n=>{let{locale:r}=e.useLocaleBase();return{locale:r,content:t.useTranslation(n),t:t.useTranslation}};exports.useContent=n;
|
|
20
2
|
//# sourceMappingURL=useContent.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useContent.cjs","names":["useLocaleBase","useTranslation"],"sources":["../../../src/client/useContent.ts"],"sourcesContent":["import type { StrictModeLocaleMap } from '@intlayer/types';\nimport { useLocaleBase } from './useLocaleBase';\nimport { useTranslation } from './useTraduction';\n\n/**\n * On the client side, hook to get the translation content based on the locale\n */\nexport const useContent = <Content>(\n languageContent: StrictModeLocaleMap<Content>\n) => {\n const { locale } = useLocaleBase();\n\n const content = useTranslation(languageContent);\n\n return {\n locale,\n content,\n t: useTranslation,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useContent.cjs","names":["useLocaleBase","useTranslation"],"sources":["../../../src/client/useContent.ts"],"sourcesContent":["import type { StrictModeLocaleMap } from '@intlayer/types';\nimport { useLocaleBase } from './useLocaleBase';\nimport { useTranslation } from './useTraduction';\n\n/**\n * On the client side, hook to get the translation content based on the locale\n */\nexport const useContent = <Content>(\n languageContent: StrictModeLocaleMap<Content>\n) => {\n const { locale } = useLocaleBase();\n\n const content = useTranslation(languageContent);\n\n return {\n locale,\n content,\n t: useTranslation,\n };\n};\n"],"mappings":"2IAOa,EACX,GACG,CACH,GAAM,CAAE,UAAWA,EAAAA,eAAe,CAIlC,MAAO,CACL,SACA,QAJcC,EAAAA,eAAe,EAAgB,CAK7C,EAAGA,EAAAA,eACJ"}
|
|
@@ -1,28 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
6
|
-
const require_getDictionary = require('../getDictionary.cjs');
|
|
7
|
-
let preact_hooks = require("preact/hooks");
|
|
8
|
-
|
|
9
|
-
//#region src/client/useDictionary.ts
|
|
10
|
-
/**
|
|
11
|
-
* On the server side, Hook that transform a dictionary and return the content
|
|
12
|
-
*
|
|
13
|
-
* If the locale is not provided, it will use the locale from the client context
|
|
14
|
-
*/
|
|
15
|
-
const useDictionary = (dictionary, locale) => {
|
|
16
|
-
const { locale: currentLocale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
17
|
-
return (0, preact_hooks.useMemo)(() => {
|
|
18
|
-
return require_getDictionary.getDictionary(dictionary, locale ?? currentLocale);
|
|
19
|
-
}, [
|
|
20
|
-
dictionary,
|
|
21
|
-
currentLocale,
|
|
22
|
-
locale
|
|
23
|
-
]);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
//#endregion
|
|
27
|
-
exports.useDictionary = useDictionary;
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./IntlayerProvider.cjs`),t=require(`../getDictionary.cjs`);let n=require(`preact/hooks`);const r=(r,i)=>{let{locale:a}=(0,n.useContext)(e.IntlayerClientContext);return(0,n.useMemo)(()=>t.getDictionary(r,i??a),[r,a,i])};exports.useDictionary=r;
|
|
28
2
|
//# sourceMappingURL=useDictionary.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.cjs","names":["IntlayerClientContext","getDictionary"],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? currentLocale;\n\n return getDictionary<T, L>(dictionary, localeTarget as L);\n }, [dictionary, currentLocale, locale]);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDictionary.cjs","names":["IntlayerClientContext","getDictionary"],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? currentLocale;\n\n return getDictionary<T, L>(dictionary, localeTarget as L);\n }, [dictionary, currentLocale, locale]);\n};\n"],"mappings":"uOAgBA,MAAa,GAIX,EACA,IACG,CACH,GAAM,CAAE,OAAQ,IAAA,EAAA,EAAA,YAA6BA,EAAAA,sBAAsB,CAEnE,OAAA,EAAA,EAAA,aAGSC,EAAAA,cAAoB,EAFN,GAAU,EAE0B,CACxD,CAAC,EAAY,EAAe,EAAO,CAAC"}
|
|
@@ -1,25 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
6
|
-
const require_client_useDictionary = require('./useDictionary.cjs');
|
|
7
|
-
let preact_hooks = require("preact/hooks");
|
|
8
|
-
let _intlayer_config_built = require("@intlayer/config/built");
|
|
9
|
-
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
10
|
-
|
|
11
|
-
//#region src/client/useDictionaryAsync.ts
|
|
12
|
-
/**
|
|
13
|
-
* On the server side, Hook that transform a dictionary and return the content
|
|
14
|
-
*
|
|
15
|
-
* If the locale is not provided, it will use the locale from the client context
|
|
16
|
-
*/
|
|
17
|
-
const useDictionaryAsync = async (dictionaryPromise, locale) => {
|
|
18
|
-
const { locale: currentLocale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
19
|
-
const localeTarget = (0, preact_hooks.useMemo)(() => locale ?? currentLocale ?? _intlayer_config_built.default?.internationalization.defaultLocale, [currentLocale, locale]);
|
|
20
|
-
return require_client_useDictionary.useDictionary(await (0, preact_hooks.useMemo)(async () => await dictionaryPromise[localeTarget]?.(), [dictionaryPromise, localeTarget]), localeTarget);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
exports.useDictionaryAsync = useDictionaryAsync;
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`./IntlayerProvider.cjs`),n=require(`./useDictionary.cjs`);let r=require(`preact/hooks`),i=require(`@intlayer/config/built`);i=e.__toESM(i);const a=async(e,a)=>{let{locale:o}=(0,r.useContext)(t.IntlayerClientContext),s=(0,r.useMemo)(()=>a??o??i.default?.internationalization.defaultLocale,[o,a]);return n.useDictionary(await(0,r.useMemo)(async()=>await e[s]?.(),[e,s]),s)};exports.useDictionaryAsync=a;
|
|
25
2
|
//# sourceMappingURL=useDictionaryAsync.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryAsync.cjs","names":["IntlayerClientContext","configuration","useDictionary"],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type {\n Dictionary,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryAsync = async <T extends Dictionary>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: LocalesValues\n): Promise<T> => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n const localeTarget = useMemo(\n () =>\n locale ??\n currentLocale ??\n configuration?.internationalization.defaultLocale,\n [currentLocale, locale]\n );\n\n const dictionary = await useMemo(\n async () =>\n (await dictionaryPromise[\n localeTarget as keyof typeof dictionaryPromise\n ]?.()) as T,\n [dictionaryPromise, localeTarget]\n );\n\n return useDictionary(dictionary, localeTarget) as any;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.cjs","names":["IntlayerClientContext","configuration","useDictionary"],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type {\n Dictionary,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryAsync = async <T extends Dictionary>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: LocalesValues\n): Promise<T> => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n const localeTarget = useMemo(\n () =>\n locale ??\n currentLocale ??\n configuration?.internationalization.defaultLocale,\n [currentLocale, locale]\n );\n\n const dictionary = await useMemo(\n async () =>\n (await dictionaryPromise[\n localeTarget as keyof typeof dictionaryPromise\n ]?.()) as T,\n [dictionaryPromise, localeTarget]\n );\n\n return useDictionary(dictionary, localeTarget) as any;\n};\n"],"mappings":"2RAiBA,MAAa,EAAqB,MAChC,EACA,IACe,CACf,GAAM,CAAE,OAAQ,IAAA,EAAA,EAAA,YAA6BA,EAAAA,sBAAsB,CAE7D,GAAA,EAAA,EAAA,aAEF,GACA,GACAC,EAAAA,SAAe,qBAAqB,cACtC,CAAC,EAAe,EAAO,CACxB,CAUD,OAAOC,EAAAA,cARY,MAAA,EAAA,EAAA,SACjB,SACG,MAAM,EACL,MACG,CACP,CAAC,EAAmB,EAAa,CAClC,CAEgC,EAAa"}
|
|
@@ -1,24 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
6
|
-
const require_client_useDictionary = require('./useDictionary.cjs');
|
|
7
|
-
const require_client_useLoadDynamic = require('./useLoadDynamic.cjs');
|
|
8
|
-
let preact_hooks = require("preact/hooks");
|
|
9
|
-
|
|
10
|
-
//#region src/client/useDictionaryDynamic.ts
|
|
11
|
-
/**
|
|
12
|
-
* On the server side, Hook that transform a dictionary and return the content
|
|
13
|
-
*
|
|
14
|
-
* If the locale is not provided, it will use the locale from the client context
|
|
15
|
-
*/
|
|
16
|
-
const useDictionaryDynamic = (dictionaryPromise, key, locale) => {
|
|
17
|
-
const { locale: currentLocale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
18
|
-
const localeTarget = (0, preact_hooks.useMemo)(() => locale ?? currentLocale, [currentLocale, locale]);
|
|
19
|
-
return require_client_useDictionary.useDictionary(require_client_useLoadDynamic.useLoadDynamic(`${String(key)}.${localeTarget}`, dictionaryPromise[localeTarget]?.()), localeTarget);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
//#endregion
|
|
23
|
-
exports.useDictionaryDynamic = useDictionaryDynamic;
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./IntlayerProvider.cjs`),t=require(`./useDictionary.cjs`),n=require(`./useLoadDynamic.cjs`);let r=require(`preact/hooks`);const i=(i,a,o)=>{let{locale:s}=(0,r.useContext)(e.IntlayerClientContext),c=(0,r.useMemo)(()=>o??s,[s,o]);return t.useDictionary(n.useLoadDynamic(`${String(a)}.${c}`,i[c]?.()),c)};exports.useDictionaryDynamic=i;
|
|
24
2
|
//# sourceMappingURL=useDictionaryDynamic.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.cjs","names":["IntlayerClientContext","useDictionary","useLoadDynamic"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport type {\n Dictionary,\n DictionaryKeys,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n K extends DictionaryKeys,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = useMemo(\n () => locale ?? currentLocale,\n [currentLocale, locale]\n );\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget}`,\n (dictionaryPromise as any)[localeTarget]?.()\n ) as T;\n\n return useDictionary(dictionary, localeTarget);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.cjs","names":["IntlayerClientContext","useDictionary","useLoadDynamic"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport type {\n Dictionary,\n DictionaryKeys,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n K extends DictionaryKeys,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = useMemo(\n () => locale ?? currentLocale,\n [currentLocale, locale]\n );\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget}`,\n (dictionaryPromise as any)[localeTarget]?.()\n ) as T;\n\n return useDictionary(dictionary, localeTarget);\n};\n"],"mappings":"wQAkBA,MAAa,GAIX,EACA,EACA,IACG,CACH,GAAM,CAAE,OAAQ,IAAA,EAAA,EAAA,YAA6BA,EAAAA,sBAAsB,CAC7D,GAAA,EAAA,EAAA,aACE,GAAU,EAChB,CAAC,EAAe,EAAO,CACxB,CAOD,OAAOC,EAAAA,cALYC,EAAAA,eACjB,GAAG,OAAO,EAAI,CAAC,GAAG,IACjB,EAA0B,MAAiB,CAC7C,CAEgC,EAAa"}
|
|
@@ -1,43 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
6
|
-
const require_getIntlayer = require('../getIntlayer.cjs');
|
|
7
|
-
let preact_hooks = require("preact/hooks");
|
|
8
|
-
|
|
9
|
-
//#region src/client/useIntlayer.ts
|
|
10
|
-
/**
|
|
11
|
-
* Preact hook that picks one dictionary by its key and returns its content.
|
|
12
|
-
*
|
|
13
|
-
* If the locale is not provided, it will use the locale from the client context.
|
|
14
|
-
*
|
|
15
|
-
* @param key - The unique key of the dictionary to retrieve.
|
|
16
|
-
* @param locale - Optional locale to override the current context locale.
|
|
17
|
-
* @returns The transformed dictionary content.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```tsx
|
|
21
|
-
* import { useIntlayer } from 'preact-intlayer';
|
|
22
|
-
*
|
|
23
|
-
* const MyComponent = () => {
|
|
24
|
-
* const content = useIntlayer('my-dictionary-key');
|
|
25
|
-
*
|
|
26
|
-
* return <div>{content.myField.value}</div>;
|
|
27
|
-
* };
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
const useIntlayer = (key, locale) => {
|
|
31
|
-
const { locale: currentLocale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
32
|
-
return (0, preact_hooks.useMemo)(() => {
|
|
33
|
-
return require_getIntlayer.getIntlayer(key, locale ?? currentLocale);
|
|
34
|
-
}, [
|
|
35
|
-
key,
|
|
36
|
-
currentLocale,
|
|
37
|
-
locale
|
|
38
|
-
]);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
//#endregion
|
|
42
|
-
exports.useIntlayer = useIntlayer;
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./IntlayerProvider.cjs`),t=require(`../getIntlayer.cjs`);let n=require(`preact/hooks`);const r=(r,i)=>{let{locale:a}=(0,n.useContext)(e.IntlayerClientContext);return(0,n.useMemo)(()=>t.getIntlayer(r,i??a),[r,a,i])};exports.useIntlayer=r;
|
|
43
2
|
//# sourceMappingURL=useIntlayer.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.cjs","names":["IntlayerClientContext","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type {\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Preact hook that picks one dictionary by its key and returns its content.\n *\n * If the locale is not provided, it will use the locale from the client context.\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param locale - Optional locale to override the current context locale.\n * @returns The transformed dictionary content.\n *\n * @example\n * ```tsx\n * import { useIntlayer } from 'preact-intlayer';\n *\n * const MyComponent = () => {\n * const content = useIntlayer('my-dictionary-key');\n *\n * return <div>{content.myField.value}</div>;\n * };\n * ```\n */\nexport const useIntlayer = <T extends DictionaryKeys, L extends LocalesValues>(\n key: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? currentLocale;\n\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n return getIntlayer<T, L>(key, localeTarget as L) as DeepTransformContent<\n DictionaryRegistryContent<T>\n >;\n }, [key, currentLocale, locale]);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIntlayer.cjs","names":["IntlayerClientContext","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type {\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Preact hook that picks one dictionary by its key and returns its content.\n *\n * If the locale is not provided, it will use the locale from the client context.\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param locale - Optional locale to override the current context locale.\n * @returns The transformed dictionary content.\n *\n * @example\n * ```tsx\n * import { useIntlayer } from 'preact-intlayer';\n *\n * const MyComponent = () => {\n * const content = useIntlayer('my-dictionary-key');\n *\n * return <div>{content.myField.value}</div>;\n * };\n * ```\n */\nexport const useIntlayer = <T extends DictionaryKeys, L extends LocalesValues>(\n key: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? currentLocale;\n\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n return getIntlayer<T, L>(key, localeTarget as L) as DeepTransformContent<\n DictionaryRegistryContent<T>\n >;\n }, [key, currentLocale, locale]);\n};\n"],"mappings":"qOAgCA,MAAa,GACX,EACA,IACG,CACH,GAAM,CAAE,OAAQ,IAAA,EAAA,EAAA,YAA6BA,EAAAA,sBAAsB,CAEnE,OAAA,EAAA,EAAA,aAISC,EAAAA,YAAkB,EAHJ,GAAU,EAGiB,CAG/C,CAAC,EAAK,EAAe,EAAO,CAAC"}
|
|
@@ -1,28 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
|
|
3
|
-
//#region src/client/useLoadDynamic.ts
|
|
4
|
-
const createSuspender = (promise) => {
|
|
5
|
-
let status = "pending";
|
|
6
|
-
let result;
|
|
7
|
-
const suspender = promise.then((r) => {
|
|
8
|
-
status = "success";
|
|
9
|
-
result = r;
|
|
10
|
-
}, (e) => {
|
|
11
|
-
status = "error";
|
|
12
|
-
result = e;
|
|
13
|
-
});
|
|
14
|
-
return { read() {
|
|
15
|
-
if (status === "pending") throw suspender;
|
|
16
|
-
if (status === "error") throw result;
|
|
17
|
-
return result;
|
|
18
|
-
} };
|
|
19
|
-
};
|
|
20
|
-
const cache = /* @__PURE__ */ new Map();
|
|
21
|
-
const useLoadDynamic = (key, promise) => {
|
|
22
|
-
if (!cache.has(key)) cache.set(key, createSuspender(promise));
|
|
23
|
-
return cache.get(key).read();
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
//#endregion
|
|
27
|
-
exports.useLoadDynamic = useLoadDynamic;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=e=>{let t=`pending`,n,r=e.then(e=>{t=`success`,n=e},e=>{t=`error`,n=e});return{read(){if(t===`pending`)throw r;if(t===`error`)throw n;return n}}},t=new Map,n=(n,r)=>(t.has(n)||t.set(n,e(r)),t.get(n).read());exports.useLoadDynamic=n;
|
|
28
2
|
//# sourceMappingURL=useLoadDynamic.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLoadDynamic.cjs","names":[],"sources":["../../../src/client/useLoadDynamic.ts"],"sourcesContent":["type Status = 'pending' | 'success' | 'error';\n\nconst createSuspender = <T>(promise: Promise<T>) => {\n let status: Status = 'pending';\n let result: T;\n const suspender = promise.then(\n (r) => {\n status = 'success';\n result = r;\n },\n (e) => {\n status = 'error';\n result = e as any;\n }\n );\n\n return {\n read() {\n if (status === 'pending') throw suspender;\n if (status === 'error') throw result;\n return result!;\n },\n };\n};\n\nconst cache = new Map<string, ReturnType<typeof createSuspender>>();\n\nexport const useLoadDynamic = <T>(key: string, promise: Promise<T>): T => {\n if (!cache.has(key)) {\n cache.set(key, createSuspender(promise));\n }\n\n return (cache.get(key)! as ReturnType<typeof createSuspender>).read() as T;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLoadDynamic.cjs","names":[],"sources":["../../../src/client/useLoadDynamic.ts"],"sourcesContent":["type Status = 'pending' | 'success' | 'error';\n\nconst createSuspender = <T>(promise: Promise<T>) => {\n let status: Status = 'pending';\n let result: T;\n const suspender = promise.then(\n (r) => {\n status = 'success';\n result = r;\n },\n (e) => {\n status = 'error';\n result = e as any;\n }\n );\n\n return {\n read() {\n if (status === 'pending') throw suspender;\n if (status === 'error') throw result;\n return result!;\n },\n };\n};\n\nconst cache = new Map<string, ReturnType<typeof createSuspender>>();\n\nexport const useLoadDynamic = <T>(key: string, promise: Promise<T>): T => {\n if (!cache.has(key)) {\n cache.set(key, createSuspender(promise));\n }\n\n return (cache.get(key)! as ReturnType<typeof createSuspender>).read() as T;\n};\n"],"mappings":"mEAEA,MAAM,EAAsB,GAAwB,CAClD,IAAI,EAAiB,UACjB,EACE,EAAY,EAAQ,KACvB,GAAM,CACL,EAAS,UACT,EAAS,GAEV,GAAM,CACL,EAAS,QACT,EAAS,GAEZ,CAED,MAAO,CACL,MAAO,CACL,GAAI,IAAW,UAAW,MAAM,EAChC,GAAI,IAAW,QAAS,MAAM,EAC9B,OAAO,GAEV,EAGG,EAAQ,IAAI,IAEL,GAAqB,EAAa,KACxC,EAAM,IAAI,EAAI,EACjB,EAAM,IAAI,EAAK,EAAgB,EAAQ,CAAC,CAGlC,EAAM,IAAI,EAAI,CAAyC,MAAM"}
|
|
@@ -1,57 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_client_useLocaleStorage = require('./useLocaleStorage.cjs');
|
|
6
|
-
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
7
|
-
let preact_hooks = require("preact/hooks");
|
|
8
|
-
let _intlayer_config_built = require("@intlayer/config/built");
|
|
9
|
-
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
10
|
-
|
|
11
|
-
//#region src/client/useLocale.ts
|
|
12
|
-
/**
|
|
13
|
-
* Preact hook to get the current locale and related locale management functions.
|
|
14
|
-
*
|
|
15
|
-
* @param props - Optional properties for the hook.
|
|
16
|
-
* @returns An object containing the current locale, default locale, available locales, and a function to update the locale.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```tsx
|
|
20
|
-
* import { useLocale } from 'preact-intlayer';
|
|
21
|
-
*
|
|
22
|
-
* const LocaleSwitcher = () => {
|
|
23
|
-
* const { locale, setLocale, availableLocales } = useLocale();
|
|
24
|
-
*
|
|
25
|
-
* return (
|
|
26
|
-
* <select value={locale} onChange={(e) => setLocale(e.target.value)}>
|
|
27
|
-
* {availableLocales.map((loc) => (
|
|
28
|
-
* <option key={loc} value={loc}>{loc}</option>
|
|
29
|
-
* ))}
|
|
30
|
-
* </select>
|
|
31
|
-
* );
|
|
32
|
-
* };
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
const useLocale = ({ isCookieEnabled, onLocaleChange } = {}) => {
|
|
36
|
-
const { defaultLocale, locales: availableLocales } = _intlayer_config_built.default?.internationalization ?? {};
|
|
37
|
-
const { locale, setLocale: setLocaleState, isCookieEnabled: isCookieEnabledContext } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
38
|
-
const setLocale = (locale) => {
|
|
39
|
-
if (!availableLocales?.map(String).includes(locale)) {
|
|
40
|
-
console.error(`Locale ${locale} is not available`);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
setLocaleState(locale);
|
|
44
|
-
require_client_useLocaleStorage.setLocaleInStorage(locale, isCookieEnabled ?? isCookieEnabledContext ?? true);
|
|
45
|
-
onLocaleChange?.(locale);
|
|
46
|
-
};
|
|
47
|
-
return {
|
|
48
|
-
locale,
|
|
49
|
-
defaultLocale,
|
|
50
|
-
availableLocales,
|
|
51
|
-
setLocale
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
//#endregion
|
|
56
|
-
exports.useLocale = useLocale;
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`./useLocaleStorage.cjs`),n=require(`./IntlayerProvider.cjs`);let r=require(`preact/hooks`),i=require(`@intlayer/config/built`);i=e.__toESM(i);const a=({isCookieEnabled:e,onLocaleChange:a}={})=>{let{defaultLocale:o,locales:s}=i.default?.internationalization??{},{locale:c,setLocale:l,isCookieEnabled:u}=(0,r.useContext)(n.IntlayerClientContext);return{locale:c,defaultLocale:o,availableLocales:s,setLocale:n=>{if(!s?.map(String).includes(n)){console.error(`Locale ${n} is not available`);return}l(n),t.setLocaleInStorage(n,e??u??!0),a?.(n)}}};exports.useLocale=a;
|
|
57
2
|
//# sourceMappingURL=useLocale.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.cjs","names":["configuration","IntlayerClientContext"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype useLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: LocalesValues) => void;\n};\n\n/**\n * Preact hook to get the current locale and related locale management functions.\n *\n * @param props - Optional properties for the hook.\n * @returns An object containing the current locale, default locale, available locales, and a function to update the locale.\n *\n * @example\n * ```tsx\n * import { useLocale } from 'preact-intlayer';\n *\n * const LocaleSwitcher = () => {\n * const { locale, setLocale, availableLocales } = useLocale();\n *\n * return (\n * <select value={locale} onChange={(e) => setLocale(e.target.value)}>\n * {availableLocales.map((loc) => (\n * <option key={loc} value={loc}>{loc}</option>\n * ))}\n * </select>\n * );\n * };\n * ```\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: useLocaleProps = {}) => {\n const { defaultLocale, locales: availableLocales } =\n configuration?.internationalization ?? {};\n\n const {\n locale,\n setLocale: setLocaleState,\n isCookieEnabled: isCookieEnabledContext,\n } = useContext(IntlayerClientContext);\n\n const setLocale = (locale: LocalesValues) => {\n if (!availableLocales?.map(String).includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n\n setLocaleInStorage(\n locale,\n isCookieEnabled ?? isCookieEnabledContext ?? true\n );\n\n onLocaleChange?.(locale);\n };\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocale.cjs","names":["configuration","IntlayerClientContext"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype useLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: LocalesValues) => void;\n};\n\n/**\n * Preact hook to get the current locale and related locale management functions.\n *\n * @param props - Optional properties for the hook.\n * @returns An object containing the current locale, default locale, available locales, and a function to update the locale.\n *\n * @example\n * ```tsx\n * import { useLocale } from 'preact-intlayer';\n *\n * const LocaleSwitcher = () => {\n * const { locale, setLocale, availableLocales } = useLocale();\n *\n * return (\n * <select value={locale} onChange={(e) => setLocale(e.target.value)}>\n * {availableLocales.map((loc) => (\n * <option key={loc} value={loc}>{loc}</option>\n * ))}\n * </select>\n * );\n * };\n * ```\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: useLocaleProps = {}) => {\n const { defaultLocale, locales: availableLocales } =\n configuration?.internationalization ?? {};\n\n const {\n locale,\n setLocale: setLocaleState,\n isCookieEnabled: isCookieEnabledContext,\n } = useContext(IntlayerClientContext);\n\n const setLocale = (locale: LocalesValues) => {\n if (!availableLocales?.map(String).includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n\n setLocaleInStorage(\n locale,\n isCookieEnabled ?? isCookieEnabledContext ?? true\n );\n\n onLocaleChange?.(locale);\n };\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":"8RAoCA,MAAa,GAAa,CACxB,kBACA,kBACkB,EAAE,GAAK,CACzB,GAAM,CAAE,gBAAe,QAAS,GAC9BA,EAAAA,SAAe,sBAAwB,EAAE,CAErC,CACJ,SACA,UAAW,EACX,gBAAiB,IAAA,EAAA,EAAA,YACJC,EAAAA,sBAAsB,CAkBrC,MAAO,CACL,SACA,gBACA,mBACA,UApBiB,GAA0B,CAC3C,GAAI,CAAC,GAAkB,IAAI,OAAO,CAAC,SAAS,EAAO,CAAE,CACnD,QAAQ,MAAM,UAAU,EAAO,mBAAmB,CAClD,OAGF,EAAe,EAAO,CAEtB,EAAA,mBACE,EACA,GAAmB,GAA0B,GAC9C,CAED,IAAiB,EAAO,EAQzB"}
|