preact-intlayer 6.1.6 → 7.0.0-canary.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 +15 -45
- package/dist/cjs/IntlayerNode.cjs.map +1 -1
- package/dist/cjs/UI/ContentSelector.cjs +98 -130
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
- package/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/cjs/client/IntlayerProvider.cjs +67 -95
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/format/index.cjs +17 -50
- package/dist/cjs/client/format/useCompact.cjs +29 -39
- package/dist/cjs/client/format/useCompact.cjs.map +1 -1
- package/dist/cjs/client/format/useCurrency.cjs +43 -39
- package/dist/cjs/client/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/client/format/useDate.cjs +45 -36
- package/dist/cjs/client/format/useDate.cjs.map +1 -1
- package/dist/cjs/client/format/useList.cjs +40 -39
- package/dist/cjs/client/format/useList.cjs.map +1 -1
- package/dist/cjs/client/format/useNumber.cjs +41 -39
- package/dist/cjs/client/format/useNumber.cjs.map +1 -1
- package/dist/cjs/client/format/usePercentage.cjs +37 -39
- package/dist/cjs/client/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/client/format/useRelativeTime.cjs +37 -39
- package/dist/cjs/client/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/client/format/useUnit.cjs +36 -39
- package/dist/cjs/client/format/useUnit.cjs.map +1 -1
- package/dist/cjs/client/index.cjs +29 -69
- package/dist/cjs/client/t.cjs +21 -34
- package/dist/cjs/client/t.cjs.map +1 -1
- package/dist/cjs/client/useContent.cjs +16 -36
- package/dist/cjs/client/useContent.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +26 -36
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +23 -52
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +22 -42
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +26 -36
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLoadDynamic.cjs +21 -50
- package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +36 -67
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleBase.cjs +25 -53
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +60 -0
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -0
- package/dist/cjs/client/useTraduction.cjs +34 -35
- package/dist/cjs/client/useTraduction.cjs.map +1 -1
- package/dist/cjs/editor/CommunicatorContext.cjs +40 -62
- package/dist/cjs/editor/CommunicatorContext.cjs.map +1 -1
- package/dist/cjs/editor/ConfigurationContext.cjs +26 -47
- package/dist/cjs/editor/ConfigurationContext.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelectorWrapper.cjs +58 -94
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/editor/DictionariesRecordContext.cjs +47 -73
- package/dist/cjs/editor/DictionariesRecordContext.cjs.map +1 -1
- package/dist/cjs/editor/EditedContentContext.cjs +160 -211
- package/dist/cjs/editor/EditedContentContext.cjs.map +1 -1
- package/dist/cjs/editor/EditorEnabledContext.cjs +34 -59
- package/dist/cjs/editor/EditorEnabledContext.cjs.map +1 -1
- package/dist/cjs/editor/EditorProvider.cjs +62 -66
- package/dist/cjs/editor/EditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/FocusDictionaryContext.cjs +51 -75
- package/dist/cjs/editor/FocusDictionaryContext.cjs.map +1 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs +45 -94
- package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/index.cjs +3 -23
- package/dist/cjs/editor/useCrossFrameMessageListener.cjs +73 -50
- package/dist/cjs/editor/useCrossFrameMessageListener.cjs.map +1 -1
- package/dist/cjs/editor/useCrossFrameState.cjs +106 -73
- package/dist/cjs/editor/useCrossFrameState.cjs.map +1 -1
- package/dist/cjs/editor/useCrossURLPathState.cjs +67 -66
- package/dist/cjs/editor/useCrossURLPathState.cjs.map +1 -1
- package/dist/cjs/editor/useEditedContentRenderer.cjs +27 -59
- package/dist/cjs/editor/useEditedContentRenderer.cjs.map +1 -1
- package/dist/cjs/editor/useIframeClickInterceptor.cjs +24 -47
- package/dist/cjs/editor/useIframeClickInterceptor.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs +15 -40
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +15 -36
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/index.cjs +30 -62
- package/dist/cjs/markdown/MarkdownProvider.cjs +19 -39
- package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +39 -80
- package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
- package/dist/cjs/markdown/index.cjs +7 -25
- package/dist/cjs/plugins.cjs +97 -119
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/preactElement/renderPreactElement.cjs +34 -59
- package/dist/cjs/preactElement/renderPreactElement.cjs.map +1 -1
- package/dist/esm/IntlayerNode.mjs +13 -25
- package/dist/esm/IntlayerNode.mjs.map +1 -1
- package/dist/esm/UI/ContentSelector.mjs +94 -105
- package/dist/esm/UI/ContentSelector.mjs.map +1 -1
- package/dist/esm/client/IntlayerProvider.mjs +51 -54
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/format/index.mjs +2 -11
- package/dist/esm/client/format/useCompact.mjs +24 -13
- package/dist/esm/client/format/useCompact.mjs.map +1 -1
- package/dist/esm/client/format/useCurrency.mjs +38 -13
- package/dist/esm/client/format/useCurrency.mjs.map +1 -1
- package/dist/esm/client/format/useDate.mjs +40 -10
- package/dist/esm/client/format/useDate.mjs.map +1 -1
- package/dist/esm/client/format/useList.mjs +35 -13
- package/dist/esm/client/format/useList.mjs.map +1 -1
- package/dist/esm/client/format/useNumber.mjs +36 -13
- package/dist/esm/client/format/useNumber.mjs.map +1 -1
- package/dist/esm/client/format/usePercentage.mjs +32 -13
- package/dist/esm/client/format/usePercentage.mjs.map +1 -1
- package/dist/esm/client/format/useRelativeTime.mjs +32 -13
- package/dist/esm/client/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/client/format/useUnit.mjs +31 -13
- package/dist/esm/client/format/useUnit.mjs.map +1 -1
- package/dist/esm/client/index.mjs +5 -32
- package/dist/esm/client/t.mjs +16 -8
- package/dist/esm/client/t.mjs.map +1 -1
- package/dist/esm/client/useContent.mjs +14 -10
- package/dist/esm/client/useContent.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +23 -11
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +18 -16
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +17 -15
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +23 -11
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLoadDynamic.mjs +20 -26
- package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +31 -31
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.mjs +19 -16
- package/dist/esm/client/useLocaleBase.mjs.map +1 -1
- package/dist/esm/client/useLocaleStorage.mjs +52 -0
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -0
- package/dist/esm/client/useTraduction.mjs +29 -9
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/editor/CommunicatorContext.mjs +28 -24
- package/dist/esm/editor/CommunicatorContext.mjs.map +1 -1
- package/dist/esm/editor/ConfigurationContext.mjs +20 -24
- package/dist/esm/editor/ConfigurationContext.mjs.map +1 -1
- package/dist/esm/editor/ContentSelectorWrapper.mjs +50 -70
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/editor/DictionariesRecordContext.mjs +37 -47
- package/dist/esm/editor/DictionariesRecordContext.mjs.map +1 -1
- package/dist/esm/editor/EditedContentContext.mjs +146 -187
- package/dist/esm/editor/EditedContentContext.mjs.map +1 -1
- package/dist/esm/editor/EditorEnabledContext.mjs +23 -33
- package/dist/esm/editor/EditorEnabledContext.mjs.map +1 -1
- package/dist/esm/editor/EditorProvider.mjs +57 -54
- package/dist/esm/editor/EditorProvider.mjs.map +1 -1
- package/dist/esm/editor/FocusDictionaryContext.mjs +42 -49
- package/dist/esm/editor/FocusDictionaryContext.mjs.map +1 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs +37 -55
- package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
- package/dist/esm/editor/index.mjs +3 -2
- package/dist/esm/editor/useCrossFrameMessageListener.mjs +68 -24
- package/dist/esm/editor/useCrossFrameMessageListener.mjs.map +1 -1
- package/dist/esm/editor/useCrossFrameState.mjs +102 -47
- package/dist/esm/editor/useCrossFrameState.mjs.map +1 -1
- package/dist/esm/editor/useCrossURLPathState.mjs +60 -40
- package/dist/esm/editor/useCrossURLPathState.mjs.map +1 -1
- package/dist/esm/editor/useEditedContentRenderer.mjs +23 -33
- package/dist/esm/editor/useEditedContentRenderer.mjs.map +1 -1
- package/dist/esm/editor/useIframeClickInterceptor.mjs +18 -20
- package/dist/esm/editor/useIframeClickInterceptor.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs +13 -22
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs +13 -18
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/index.mjs +13 -39
- package/dist/esm/markdown/MarkdownProvider.mjs +14 -16
- package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRenderer.mjs +34 -57
- package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -1
- package/dist/esm/markdown/index.mjs +4 -3
- package/dist/esm/plugins.mjs +86 -92
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/preactElement/renderPreactElement.mjs +31 -34
- package/dist/esm/preactElement/renderPreactElement.mjs.map +1 -1
- package/dist/types/IntlayerNode.d.ts +19 -12
- package/dist/types/IntlayerNode.d.ts.map +1 -1
- package/dist/types/UI/ContentSelector.d.ts +12 -9
- package/dist/types/UI/ContentSelector.d.ts.map +1 -1
- package/dist/types/client/IntlayerProvider.d.ts +22 -16
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -1
- package/dist/types/client/format/index.d.ts +9 -9
- package/dist/types/client/format/useCompact.d.ts +8 -2
- package/dist/types/client/format/useCompact.d.ts.map +1 -1
- package/dist/types/client/format/useCurrency.d.ts +8 -2
- package/dist/types/client/format/useCurrency.d.ts.map +1 -1
- package/dist/types/client/format/useDate.d.ts +7 -2
- package/dist/types/client/format/useDate.d.ts.map +1 -1
- package/dist/types/client/format/useList.d.ts +8 -2
- package/dist/types/client/format/useList.d.ts.map +1 -1
- package/dist/types/client/format/useNumber.d.ts +8 -2
- package/dist/types/client/format/useNumber.d.ts.map +1 -1
- package/dist/types/client/format/usePercentage.d.ts +8 -2
- package/dist/types/client/format/usePercentage.d.ts.map +1 -1
- package/dist/types/client/format/useRelativeTime.d.ts +9 -3
- package/dist/types/client/format/useRelativeTime.d.ts.map +1 -1
- package/dist/types/client/format/useUnit.d.ts +8 -2
- package/dist/types/client/format/useUnit.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +11 -12
- package/dist/types/client/t.d.ts +7 -3
- package/dist/types/client/t.d.ts.map +1 -1
- package/dist/types/client/useContent.d.ts +10 -5
- package/dist/types/client/useContent.d.ts.map +1 -1
- package/dist/types/client/useDictionary.d.ts +9 -3
- package/dist/types/client/useDictionary.d.ts.map +1 -1
- package/dist/types/client/useDictionaryAsync.d.ts +7 -3
- package/dist/types/client/useDictionaryAsync.d.ts.map +1 -1
- package/dist/types/client/useDictionaryDynamic.d.ts +9 -3
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/client/useIntlayer.d.ts +8 -5
- package/dist/types/client/useIntlayer.d.ts.map +1 -1
- package/dist/types/client/useLoadDynamic.d.ts +4 -1
- package/dist/types/client/useLoadDynamic.d.ts.map +1 -1
- package/dist/types/client/useLocale.d.ts +16 -8
- package/dist/types/client/useLocale.d.ts.map +1 -1
- package/dist/types/client/useLocaleBase.d.ts +10 -5
- package/dist/types/client/useLocaleBase.d.ts.map +1 -1
- package/dist/types/client/useLocaleStorage.d.ts +45 -0
- package/dist/types/client/useLocaleStorage.d.ts.map +1 -0
- package/dist/types/client/useTraduction.d.ts +7 -2
- package/dist/types/client/useTraduction.d.ts.map +1 -1
- package/dist/types/editor/CommunicatorContext.d.ts +15 -11
- package/dist/types/editor/CommunicatorContext.d.ts.map +1 -1
- package/dist/types/editor/ConfigurationContext.d.ts +12 -7
- package/dist/types/editor/ConfigurationContext.d.ts.map +1 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts +8 -4
- package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
- package/dist/types/editor/DictionariesRecordContext.d.ts +15 -12
- package/dist/types/editor/DictionariesRecordContext.d.ts.map +1 -1
- package/dist/types/editor/EditedContentContext.d.ts +32 -29
- package/dist/types/editor/EditedContentContext.d.ts.map +1 -1
- package/dist/types/editor/EditorEnabledContext.d.ts +14 -9
- package/dist/types/editor/EditorEnabledContext.d.ts.map +1 -1
- package/dist/types/editor/EditorProvider.d.ts +9 -5
- package/dist/types/editor/EditorProvider.d.ts.map +1 -1
- package/dist/types/editor/FocusDictionaryContext.d.ts +18 -15
- package/dist/types/editor/FocusDictionaryContext.d.ts.map +1 -1
- package/dist/types/editor/IntlayerEditorProvider.d.ts +7 -3
- package/dist/types/editor/IntlayerEditorProvider.d.ts.map +1 -1
- package/dist/types/editor/index.d.ts +2 -2
- package/dist/types/editor/useCrossFrameMessageListener.d.ts +7 -2
- package/dist/types/editor/useCrossFrameMessageListener.d.ts.map +1 -1
- package/dist/types/editor/useCrossFrameState.d.ts +11 -7
- package/dist/types/editor/useCrossFrameState.d.ts.map +1 -1
- package/dist/types/editor/useCrossURLPathState.d.ts +8 -3
- package/dist/types/editor/useCrossURLPathState.d.ts.map +1 -1
- package/dist/types/editor/useEditedContentRenderer.d.ts +16 -10
- package/dist/types/editor/useEditedContentRenderer.d.ts.map +1 -1
- package/dist/types/editor/useIframeClickInterceptor.d.ts +5 -2
- package/dist/types/editor/useIframeClickInterceptor.d.ts.map +1 -1
- package/dist/types/getDictionary.d.ts +8 -4
- package/dist/types/getDictionary.d.ts.map +1 -1
- package/dist/types/getIntlayer.d.ts +8 -4
- package/dist/types/getIntlayer.d.ts.map +1 -1
- package/dist/types/index.d.ts +18 -6
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/markdown/MarkdownProvider.d.ts +8 -5
- package/dist/types/markdown/MarkdownProvider.d.ts.map +1 -1
- package/dist/types/markdown/MarkdownRenderer.d.ts +13 -11
- package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -1
- package/dist/types/markdown/index.d.ts +3 -3
- package/dist/types/plugins.d.ts +33 -27
- package/dist/types/plugins.d.ts.map +1 -1
- package/dist/types/preactElement/renderPreactElement.d.ts +7 -3
- package/dist/types/preactElement/renderPreactElement.d.ts.map +1 -1
- package/package.json +40 -46
- package/LICENSE +0 -202
- package/dist/cjs/client/format/index.cjs.map +0 -1
- package/dist/cjs/client/getBrowserLocale.cjs +0 -173
- package/dist/cjs/client/getBrowserLocale.cjs.map +0 -1
- package/dist/cjs/client/index.cjs.map +0 -1
- package/dist/cjs/client/useLocaleCookie.cjs +0 -60
- package/dist/cjs/client/useLocaleCookie.cjs.map +0 -1
- package/dist/cjs/editor/index.cjs.map +0 -1
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/markdown/index.cjs.map +0 -1
- package/dist/esm/client/format/index.mjs.map +0 -1
- package/dist/esm/client/getBrowserLocale.mjs +0 -138
- package/dist/esm/client/getBrowserLocale.mjs.map +0 -1
- package/dist/esm/client/index.mjs.map +0 -1
- package/dist/esm/client/useLocaleCookie.mjs +0 -24
- package/dist/esm/client/useLocaleCookie.mjs.map +0 -1
- package/dist/esm/editor/index.mjs.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/markdown/index.mjs.map +0 -1
- package/dist/types/client/format/index.d.ts.map +0 -1
- package/dist/types/client/getBrowserLocale.d.ts +0 -25
- package/dist/types/client/getBrowserLocale.d.ts.map +0 -1
- package/dist/types/client/index.d.ts.map +0 -1
- package/dist/types/client/useLocaleCookie.d.ts +0 -17
- package/dist/types/client/useLocaleCookie.d.ts.map +0 -1
- package/dist/types/editor/index.d.ts.map +0 -1
- package/dist/types/markdown/index.d.ts.map +0 -1
|
@@ -1,45 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var useDictionaryDynamic_exports = {};
|
|
21
|
-
__export(useDictionaryDynamic_exports, {
|
|
22
|
-
useDictionaryDynamic: () => useDictionaryDynamic
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(useDictionaryDynamic_exports);
|
|
25
|
-
var import_hooks = require("preact/hooks");
|
|
26
|
-
var import_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
27
|
-
var import_useDictionary = require('./useDictionary.cjs');
|
|
28
|
-
var import_useLoadDynamic = require('./useLoadDynamic.cjs');
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const require_rolldown_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
|
+
preact_hooks = require_rolldown_runtime.__toESM(preact_hooks);
|
|
10
|
+
|
|
11
|
+
//#region src/client/useDictionaryDynamic.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
|
+
*/
|
|
29
17
|
const useDictionaryDynamic = (dictionaryPromise, key, locale) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
[currentLocale, locale]
|
|
34
|
-
);
|
|
35
|
-
const dictionary = (0, import_useLoadDynamic.useLoadDynamic)(
|
|
36
|
-
`${String(key)}.${localeTarget}`,
|
|
37
|
-
dictionaryPromise[localeTarget]()
|
|
38
|
-
);
|
|
39
|
-
return (0, import_useDictionary.useDictionary)(dictionary, localeTarget);
|
|
18
|
+
const { locale: currentLocale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
19
|
+
const localeTarget = (0, preact_hooks.useMemo)(() => locale ?? currentLocale, [currentLocale, locale]);
|
|
20
|
+
return require_client_useDictionary.useDictionary(require_client_useLoadDynamic.useLoadDynamic(`${String(key)}.${localeTarget}`, dictionaryPromise[localeTarget]?.()), localeTarget);
|
|
40
21
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.useDictionaryDynamic = useDictionaryDynamic;
|
|
45
25
|
//# sourceMappingURL=useDictionaryDynamic.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport type {
|
|
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":";;;;;;;;;;;;;;;;AAkBA,MAAa,wBAIX,mBACA,KACA,WACG;CACH,MAAM,EAAE,QAAQ,+CAA6BA,sDAAsB;CACnE,MAAM,+CACE,UAAU,eAChB,CAAC,eAAe,OAAO,CACxB;AAOD,QAAOC,2CALYC,6CACjB,GAAG,OAAO,IAAI,CAAC,GAAG,gBACjB,kBAA0B,iBAAiB,CAC7C,EAEgC,aAAa"}
|
|
@@ -1,39 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var useIntlayer_exports = {};
|
|
21
|
-
__export(useIntlayer_exports, {
|
|
22
|
-
useIntlayer: () => useIntlayer
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(useIntlayer_exports);
|
|
25
|
-
var import_hooks = require("preact/hooks");
|
|
26
|
-
var import_getIntlayer = require('../getIntlayer.cjs');
|
|
27
|
-
var import_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const require_rolldown_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
|
+
preact_hooks = require_rolldown_runtime.__toESM(preact_hooks);
|
|
9
|
+
|
|
10
|
+
//#region src/client/useIntlayer.ts
|
|
11
|
+
/**
|
|
12
|
+
* On the client side, Hook that picking one dictionary by its key and return the content
|
|
13
|
+
*
|
|
14
|
+
* If the locale is not provided, it will use the locale from the client context
|
|
15
|
+
*/
|
|
28
16
|
const useIntlayer = (key, locale) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
17
|
+
const { locale: currentLocale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
18
|
+
return (0, preact_hooks.useMemo)(() => {
|
|
19
|
+
return require_getIntlayer.getIntlayer(key, locale ?? currentLocale);
|
|
20
|
+
}, [
|
|
21
|
+
key,
|
|
22
|
+
currentLocale,
|
|
23
|
+
locale
|
|
24
|
+
]);
|
|
34
25
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.useIntlayer = useIntlayer;
|
|
39
29
|
//# sourceMappingURL=useIntlayer.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type {
|
|
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 * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\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":";;;;;;;;;;;;;;;AAiBA,MAAa,eACX,KACA,WACG;CACH,MAAM,EAAE,QAAQ,+CAA6BA,sDAAsB;AAEnE,wCAAqB;AAInB,SAAOC,gCAAkB,KAHJ,UAAU,cAGiB;IAG/C;EAAC;EAAK;EAAe;EAAO,CAAC"}
|
|
@@ -1,56 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var useLoadDynamic_exports = {};
|
|
20
|
-
__export(useLoadDynamic_exports, {
|
|
21
|
-
useLoadDynamic: () => useLoadDynamic
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(useLoadDynamic_exports);
|
|
1
|
+
|
|
2
|
+
//#region src/client/useLoadDynamic.ts
|
|
24
3
|
const createSuspender = (promise) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (status === "pending") throw suspender;
|
|
40
|
-
if (status === "error") throw result;
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
4
|
+
let status = "pending";
|
|
5
|
+
let result;
|
|
6
|
+
const suspender = promise.then((r) => {
|
|
7
|
+
status = "success";
|
|
8
|
+
result = r;
|
|
9
|
+
}, (e) => {
|
|
10
|
+
status = "error";
|
|
11
|
+
result = e;
|
|
12
|
+
});
|
|
13
|
+
return { read() {
|
|
14
|
+
if (status === "pending") throw suspender;
|
|
15
|
+
if (status === "error") throw result;
|
|
16
|
+
return result;
|
|
17
|
+
} };
|
|
44
18
|
};
|
|
45
19
|
const cache = /* @__PURE__ */ new Map();
|
|
46
20
|
const useLoadDynamic = (key, promise) => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
return cache.get(key).read();
|
|
21
|
+
if (!cache.has(key)) cache.set(key, createSuspender(promise));
|
|
22
|
+
return cache.get(key).read();
|
|
51
23
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.useLoadDynamic = useLoadDynamic;
|
|
56
27
|
//# sourceMappingURL=useLoadDynamic.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"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":["status: Status","result: T"],"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":";;AAEA,MAAM,mBAAsB,YAAwB;CAClD,IAAIA,SAAiB;CACrB,IAAIC;CACJ,MAAM,YAAY,QAAQ,MACvB,MAAM;AACL,WAAS;AACT,WAAS;KAEV,MAAM;AACL,WAAS;AACT,WAAS;GAEZ;AAED,QAAO,EACL,OAAO;AACL,MAAI,WAAW,UAAW,OAAM;AAChC,MAAI,WAAW,QAAS,OAAM;AAC9B,SAAO;IAEV;;AAGH,MAAM,wBAAQ,IAAI,KAAiD;AAEnE,MAAa,kBAAqB,KAAa,YAA2B;AACxE,KAAI,CAAC,MAAM,IAAI,IAAI,CACjB,OAAM,IAAI,KAAK,gBAAgB,QAAQ,CAAC;AAG1C,QAAQ,MAAM,IAAI,IAAI,CAAyC,MAAM"}
|
|
@@ -1,69 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
5
|
+
const require_client_useLocaleStorage = require('./useLocaleStorage.cjs');
|
|
6
|
+
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
7
|
+
let __intlayer_config_built = require("@intlayer/config/built");
|
|
8
|
+
__intlayer_config_built = require_rolldown_runtime.__toESM(__intlayer_config_built);
|
|
9
|
+
let preact_hooks = require("preact/hooks");
|
|
10
|
+
preact_hooks = require_rolldown_runtime.__toESM(preact_hooks);
|
|
11
|
+
|
|
12
|
+
//#region src/client/useLocale.ts
|
|
13
|
+
/**
|
|
14
|
+
* On the client side, hook to get the current locale and all related fields
|
|
15
|
+
*/
|
|
16
|
+
const useLocale = ({ isCookieEnabled, onLocaleChange } = {}) => {
|
|
17
|
+
const { defaultLocale, locales: availableLocales } = __intlayer_config_built.default?.internationalization ?? {};
|
|
18
|
+
const { locale, setLocale: setLocaleState, isCookieEnabled: isCookieEnabledContext } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
19
|
+
const setLocale = (locale$1) => {
|
|
20
|
+
if (!availableLocales?.map(String).includes(locale$1)) {
|
|
21
|
+
console.error(`Locale ${locale$1} is not available`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
setLocaleState(locale$1);
|
|
25
|
+
require_client_useLocaleStorage.setLocaleInStorage(locale$1, isCookieEnabled ?? isCookieEnabledContext ?? true);
|
|
26
|
+
onLocaleChange?.(locale$1);
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
locale,
|
|
30
|
+
defaultLocale,
|
|
31
|
+
availableLocales,
|
|
32
|
+
setLocale
|
|
33
|
+
};
|
|
12
34
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
var useLocale_exports = {};
|
|
31
|
-
__export(useLocale_exports, {
|
|
32
|
-
useLocale: () => useLocale
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(useLocale_exports);
|
|
35
|
-
var import_built = __toESM(require("@intlayer/config/built"));
|
|
36
|
-
var import_hooks = require("preact/hooks");
|
|
37
|
-
var import_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
38
|
-
var import_useLocaleCookie = require('./useLocaleCookie.cjs');
|
|
39
|
-
const useLocale = ({ onLocaleChange } = {}) => {
|
|
40
|
-
const { defaultLocale, locales: availableLocales } = import_built.default?.internationalization ?? {};
|
|
41
|
-
const { locale, setLocale: setLocaleState } = (0, import_hooks.useContext)(
|
|
42
|
-
import_IntlayerProvider.IntlayerClientContext
|
|
43
|
-
);
|
|
44
|
-
const { setLocaleCookie } = (0, import_useLocaleCookie.useLocaleCookie)();
|
|
45
|
-
const setLocale = (locale2) => {
|
|
46
|
-
if (!availableLocales?.map(String).includes(locale2)) {
|
|
47
|
-
console.error(`Locale ${locale2} is not available`);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
setLocaleState(locale2);
|
|
51
|
-
setLocaleCookie(locale2);
|
|
52
|
-
onLocaleChange?.(locale2);
|
|
53
|
-
};
|
|
54
|
-
return {
|
|
55
|
-
locale,
|
|
56
|
-
// Current locale
|
|
57
|
-
defaultLocale,
|
|
58
|
-
// Principal locale defined in config
|
|
59
|
-
availableLocales,
|
|
60
|
-
// List of the available locales defined in config
|
|
61
|
-
setLocale
|
|
62
|
-
// Function to set the locale
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
-
0 && (module.exports = {
|
|
67
|
-
useLocale
|
|
68
|
-
});
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
exports.useLocale = useLocale;
|
|
69
38
|
//# sourceMappingURL=useLocale.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/
|
|
1
|
+
{"version":3,"file":"useLocale.cjs","names":["configuration","IntlayerClientContext","locale"],"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 * On the client side, hook to get the current locale and all related fields\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":";;;;;;;;;;;;;;;AAgBA,MAAa,aAAa,EACxB,iBACA,mBACkB,EAAE,KAAK;CACzB,MAAM,EAAE,eAAe,SAAS,qBAC9BA,iCAAe,wBAAwB,EAAE;CAE3C,MAAM,EACJ,QACA,WAAW,gBACX,iBAAiB,wDACJC,sDAAsB;CAErC,MAAM,aAAa,aAA0B;AAC3C,MAAI,CAAC,kBAAkB,IAAI,OAAO,CAAC,SAASC,SAAO,EAAE;AACnD,WAAQ,MAAM,UAAUA,SAAO,mBAAmB;AAClD;;AAGF,iBAAeA,SAAO;AAEtB,qDACEA,UACA,mBAAmB,0BAA0B,KAC9C;AAED,mBAAiBA,SAAO;;AAG1B,QAAO;EACL;EACA;EACA;EACA;EACD"}
|
|
@@ -1,56 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
var useLocaleBase_exports = {};
|
|
31
|
-
__export(useLocaleBase_exports, {
|
|
32
|
-
useLocaleBase: () => useLocaleBase
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(useLocaleBase_exports);
|
|
35
|
-
var import_built = __toESM(require("@intlayer/config/built"));
|
|
36
|
-
var import_hooks = require("preact/hooks");
|
|
37
|
-
var import_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
38
|
-
const { defaultLocale, locales: availableLocales } = import_built.default.internationalization;
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
5
|
+
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
6
|
+
let __intlayer_config_built = require("@intlayer/config/built");
|
|
7
|
+
__intlayer_config_built = require_rolldown_runtime.__toESM(__intlayer_config_built);
|
|
8
|
+
let preact_hooks = require("preact/hooks");
|
|
9
|
+
preact_hooks = require_rolldown_runtime.__toESM(preact_hooks);
|
|
10
|
+
|
|
11
|
+
//#region src/client/useLocaleBase.ts
|
|
12
|
+
const { defaultLocale, locales: availableLocales } = __intlayer_config_built.default.internationalization;
|
|
13
|
+
/**
|
|
14
|
+
* On the client side, hook to get the current locale and all related fields
|
|
15
|
+
*/
|
|
39
16
|
const useLocaleBase = () => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
// List of the available locales defined in config
|
|
48
|
-
setLocale
|
|
49
|
-
// Function to set the locale
|
|
50
|
-
};
|
|
17
|
+
const { locale, setLocale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
18
|
+
return {
|
|
19
|
+
locale,
|
|
20
|
+
defaultLocale,
|
|
21
|
+
availableLocales,
|
|
22
|
+
setLocale
|
|
23
|
+
};
|
|
51
24
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
exports.useLocaleBase = useLocaleBase;
|
|
56
28
|
//# sourceMappingURL=useLocaleBase.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\nconst { defaultLocale, locales: availableLocales } =\n configuration.internationalization;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocaleBase = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext);\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":"useLocaleBase.cjs","names":["configuration","IntlayerClientContext"],"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\nconst { defaultLocale, locales: availableLocales } =\n configuration.internationalization;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocaleBase = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext);\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":";;;;;;;;;;;AAMA,MAAM,EAAE,eAAe,SAAS,qBAC9BA,gCAAc;;;;AAKhB,MAAa,sBAAsB;CACjC,MAAM,EAAE,QAAQ,2CAAyBC,sDAAsB;AAE/D,QAAO;EACL;EACA;EACA;EACA;EACD"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let __intlayer_core = require("@intlayer/core");
|
|
3
|
+
__intlayer_core = require_rolldown_runtime.__toESM(__intlayer_core);
|
|
4
|
+
let preact_hooks = require("preact/hooks");
|
|
5
|
+
preact_hooks = require_rolldown_runtime.__toESM(preact_hooks);
|
|
6
|
+
|
|
7
|
+
//#region src/client/useLocaleStorage.ts
|
|
8
|
+
/**
|
|
9
|
+
* Get the locale cookie
|
|
10
|
+
*/
|
|
11
|
+
const localeInStorage = (0, __intlayer_core.getLocaleFromStorage)(__intlayer_core.localeStorageOptions);
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use localeInStorage instead
|
|
14
|
+
*
|
|
15
|
+
* Get the locale cookie
|
|
16
|
+
*/
|
|
17
|
+
const localeCookie = localeInStorage;
|
|
18
|
+
/**
|
|
19
|
+
* Set the locale cookie
|
|
20
|
+
*/
|
|
21
|
+
const setLocaleInStorage = (locale, isCookieEnabled) => (0, __intlayer_core.setLocaleInStorage)(locale, {
|
|
22
|
+
...__intlayer_core.localeStorageOptions,
|
|
23
|
+
isCookieEnabled
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated Use setLocaleInStorage instead
|
|
27
|
+
*
|
|
28
|
+
* Set the locale cookie
|
|
29
|
+
*/
|
|
30
|
+
const setLocaleCookie = setLocaleInStorage;
|
|
31
|
+
/**
|
|
32
|
+
* Hook that provides the locale storage and a function to set it
|
|
33
|
+
*/
|
|
34
|
+
const useLocaleStorage = (isCookieEnabled) => (0, preact_hooks.useMemo)(() => (0, __intlayer_core.LocaleStorage)({
|
|
35
|
+
...__intlayer_core.localeStorageOptions,
|
|
36
|
+
isCookieEnabled
|
|
37
|
+
}), [isCookieEnabled]);
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated Use useLocaleStorage instead
|
|
40
|
+
*
|
|
41
|
+
* For GDPR compliance, use useLocaleStorage instead
|
|
42
|
+
*
|
|
43
|
+
* Hook that provides the locale cookie and a function to set it
|
|
44
|
+
*/
|
|
45
|
+
const useLocaleCookie = (isCookieEnabled) => {
|
|
46
|
+
const storage = useLocaleStorage(isCookieEnabled);
|
|
47
|
+
return {
|
|
48
|
+
localeCookie: storage.getLocale(),
|
|
49
|
+
setLocaleCookie: storage.setLocale
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
exports.localeCookie = localeCookie;
|
|
55
|
+
exports.localeInStorage = localeInStorage;
|
|
56
|
+
exports.setLocaleCookie = setLocaleCookie;
|
|
57
|
+
exports.setLocaleInStorage = setLocaleInStorage;
|
|
58
|
+
exports.useLocaleCookie = useLocaleCookie;
|
|
59
|
+
exports.useLocaleStorage = useLocaleStorage;
|
|
60
|
+
//# sourceMappingURL=useLocaleStorage.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLocaleStorage.cjs","names":["localeStorageOptions"],"sources":["../../../src/client/useLocaleStorage.ts"],"sourcesContent":["import {\n getLocaleFromStorage,\n LocaleStorage,\n localeStorageOptions,\n setLocaleInStorage as setLocaleInStorageCore,\n} from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport { useMemo } from 'preact/hooks';\n\n/**\n * Get the locale cookie\n */\nexport const localeInStorage = getLocaleFromStorage(localeStorageOptions);\n/**\n * @deprecated Use localeInStorage instead\n *\n * Get the locale cookie\n */\nexport const localeCookie = localeInStorage;\n\n/**\n * Set the locale cookie\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n isCookieEnabled: boolean\n) =>\n setLocaleInStorageCore(locale, {\n ...localeStorageOptions,\n isCookieEnabled,\n });\n\n/**\n * @deprecated Use setLocaleInStorage instead\n *\n * Set the locale cookie\n */\nexport const setLocaleCookie = setLocaleInStorage;\n\n/**\n * Hook that provides the locale storage and a function to set it\n */\nexport const useLocaleStorage = (isCookieEnabled?: boolean) =>\n useMemo(\n () =>\n LocaleStorage({\n ...localeStorageOptions,\n isCookieEnabled,\n }),\n [isCookieEnabled]\n );\n\n/**\n * @deprecated Use useLocaleStorage instead\n *\n * For GDPR compliance, use useLocaleStorage instead\n *\n * Hook that provides the locale cookie and a function to set it\n */\nexport const useLocaleCookie = (isCookieEnabled?: boolean) => {\n const storage = useLocaleStorage(isCookieEnabled);\n return {\n localeCookie: storage.getLocale(),\n setLocaleCookie: storage.setLocale,\n };\n};\n"],"mappings":";;;;;;;;;;AAYA,MAAa,4DAAuCA,qCAAqB;;;;;;AAMzE,MAAa,eAAe;;;;AAK5B,MAAa,sBACX,QACA,4DAEuB,QAAQ;CAC7B,GAAGA;CACH;CACD,CAAC;;;;;;AAOJ,MAAa,kBAAkB;;;;AAK/B,MAAa,oBAAoB,uFAGb;CACZ,GAAGA;CACH;CACD,CAAC,EACJ,CAAC,gBAAgB,CAClB;;;;;;;;AASH,MAAa,mBAAmB,oBAA8B;CAC5D,MAAM,UAAU,iBAAiB,gBAAgB;AACjD,QAAO;EACL,cAAc,QAAQ,WAAW;EACjC,iBAAiB,QAAQ;EAC1B"}
|
|
@@ -1,38 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
3
|
+
let __intlayer_core = require("@intlayer/core");
|
|
4
|
+
__intlayer_core = require_rolldown_runtime.__toESM(__intlayer_core);
|
|
5
|
+
let preact_hooks = require("preact/hooks");
|
|
6
|
+
preact_hooks = require_rolldown_runtime.__toESM(preact_hooks);
|
|
7
|
+
|
|
8
|
+
//#region src/client/useTraduction.ts
|
|
9
|
+
/**
|
|
10
|
+
* On the client side, Hook that picking one dictionary by its id and return the content.
|
|
11
|
+
*
|
|
12
|
+
* If not locale found, it will return the content related to the default locale.
|
|
13
|
+
*
|
|
14
|
+
* Return either the content editor, or the content itself depending on the configuration.
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
*
|
|
18
|
+
* ```tsx
|
|
19
|
+
* const content = useTranslation<string>({
|
|
20
|
+
* en: 'Hello',
|
|
21
|
+
* fr: 'Bonjour',
|
|
22
|
+
* }, 'fr');
|
|
23
|
+
* // 'Bonjour'
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* Using TypeScript:
|
|
27
|
+
* - this function will require each locale to be defined if defined in the project configuration.
|
|
28
|
+
* - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
|
|
29
|
+
*/
|
|
27
30
|
const useTranslation = (languageContent) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
() => (0, import_core.getTranslation)(languageContent, locale),
|
|
31
|
-
[languageContent, locale]
|
|
32
|
-
);
|
|
31
|
+
const { locale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
32
|
+
return (0, preact_hooks.useMemo)(() => (0, __intlayer_core.getTranslation)(languageContent, locale), [languageContent, locale]);
|
|
33
33
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
});
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
exports.useTranslation = useTranslation;
|
|
38
37
|
//# sourceMappingURL=useTraduction.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import { getTranslation
|
|
1
|
+
{"version":3,"file":"useTraduction.cjs","names":["IntlayerClientContext"],"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import { getTranslation } from '@intlayer/core';\nimport type { StrictModeLocaleMap } from '@intlayer/types';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```tsx\n * const content = useTranslation<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const useTranslation = <Content = string>(\n languageContent: StrictModeLocaleMap<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useMemo(\n () => getTranslation(languageContent, locale),\n [languageContent, locale]\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,kBACX,oBACY;CACZ,MAAM,EAAE,wCAAsBA,sDAAsB;AAEpD,4EACuB,iBAAiB,OAAO,EAC7C,CAAC,iBAAiB,OAAO,CAC1B"}
|