preact-intlayer 8.4.4 → 8.4.5
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 +16 -1
- package/dist/cjs/IntlayerNode.cjs.map +1 -1
- package/dist/cjs/UI/ContentSelector.cjs +96 -1
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/cjs/client/IntlayerProvider.cjs +88 -1
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -0
- package/dist/cjs/client/format/index.cjs +18 -1
- package/dist/cjs/client/format/useCompact.cjs +27 -1
- package/dist/cjs/client/format/useCompact.cjs.map +1 -1
- package/dist/cjs/client/format/useCurrency.cjs +41 -1
- package/dist/cjs/client/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/client/format/useDate.cjs +43 -1
- package/dist/cjs/client/format/useDate.cjs.map +1 -1
- package/dist/cjs/client/format/useIntl.cjs +33 -1
- package/dist/cjs/client/format/useIntl.cjs.map +1 -1
- package/dist/cjs/client/format/useList.cjs +38 -1
- package/dist/cjs/client/format/useList.cjs.map +1 -1
- package/dist/cjs/client/format/useNumber.cjs +39 -1
- package/dist/cjs/client/format/useNumber.cjs.map +1 -1
- package/dist/cjs/client/format/usePercentage.cjs +35 -1
- package/dist/cjs/client/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/client/format/useRelativeTime.cjs +35 -1
- package/dist/cjs/client/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/client/format/useUnit.cjs +34 -1
- package/dist/cjs/client/format/useUnit.cjs.map +1 -1
- package/dist/cjs/client/index.cjs +32 -1
- package/dist/cjs/client/t.cjs +19 -1
- package/dist/cjs/client/t.cjs.map +1 -1
- package/dist/cjs/client/useContent.cjs +19 -1
- package/dist/cjs/client/useContent.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +25 -1
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +22 -1
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +21 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +40 -1
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLoadDynamic.cjs +27 -1
- package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +54 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleBase.cjs +24 -1
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +59 -1
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.cjs +35 -1
- package/dist/cjs/client/useTraduction.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelector.cjs +24 -1
- package/dist/cjs/editor/ContentSelector.cjs.map +1 -1
- package/dist/cjs/editor/EditorProvider.cjs +12 -1
- package/dist/cjs/editor/EditorProvider.cjs.map +1 -0
- package/dist/cjs/editor/useEditor.cjs +38 -1
- package/dist/cjs/editor/useEditor.cjs.map +1 -0
- package/dist/cjs/getDictionary.cjs +10 -1
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +10 -1
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/html/HTMLProvider.cjs +17 -1
- package/dist/cjs/html/HTMLProvider.cjs.map +1 -1
- package/dist/cjs/html/HTMLRenderer.cjs +54 -1
- package/dist/cjs/html/HTMLRenderer.cjs.map +1 -1
- package/dist/cjs/html/index.cjs +10 -1
- package/dist/cjs/index.cjs +57 -1
- package/dist/cjs/markdown/MarkdownProvider.cjs +54 -1
- package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +77 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs +26 -1
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs.map +1 -1
- package/dist/cjs/markdown/compiler.cjs +24 -1
- package/dist/cjs/markdown/compiler.cjs.map +1 -1
- package/dist/cjs/markdown/index.cjs +23 -1
- package/dist/cjs/markdown/runtime.cjs +18 -1
- package/dist/cjs/markdown/runtime.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +222 -1
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/preactElement/renderPreactElement.cjs +42 -1
- package/dist/cjs/preactElement/renderPreactElement.cjs.map +1 -1
- package/dist/esm/IntlayerNode.mjs +14 -1
- package/dist/esm/IntlayerNode.mjs.map +1 -1
- package/dist/esm/UI/ContentSelector.mjs +94 -1
- package/dist/esm/UI/ContentSelector.mjs.map +1 -1
- package/dist/esm/client/IntlayerProvider.mjs +82 -1
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -0
- package/dist/esm/client/format/index.mjs +10 -1
- package/dist/esm/client/format/useCompact.mjs +25 -1
- package/dist/esm/client/format/useCompact.mjs.map +1 -1
- package/dist/esm/client/format/useCurrency.mjs +39 -1
- package/dist/esm/client/format/useCurrency.mjs.map +1 -1
- package/dist/esm/client/format/useDate.mjs +41 -1
- package/dist/esm/client/format/useDate.mjs.map +1 -1
- package/dist/esm/client/format/useIntl.mjs +31 -1
- package/dist/esm/client/format/useIntl.mjs.map +1 -1
- package/dist/esm/client/format/useList.mjs +36 -1
- package/dist/esm/client/format/useList.mjs.map +1 -1
- package/dist/esm/client/format/useNumber.mjs +37 -1
- package/dist/esm/client/format/useNumber.mjs.map +1 -1
- package/dist/esm/client/format/usePercentage.mjs +33 -1
- package/dist/esm/client/format/usePercentage.mjs.map +1 -1
- package/dist/esm/client/format/useRelativeTime.mjs +33 -1
- package/dist/esm/client/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/client/format/useUnit.mjs +32 -1
- package/dist/esm/client/format/useUnit.mjs.map +1 -1
- package/dist/esm/client/index.mjs +13 -1
- package/dist/esm/client/t.mjs +17 -1
- package/dist/esm/client/t.mjs.map +1 -1
- package/dist/esm/client/useContent.mjs +18 -1
- package/dist/esm/client/useContent.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +23 -1
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +19 -1
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +19 -1
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +38 -1
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLoadDynamic.mjs +25 -1
- package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +51 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.mjs +21 -1
- package/dist/esm/client/useLocaleBase.mjs.map +1 -1
- package/dist/esm/client/useLocaleStorage.mjs +52 -1
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
- package/dist/esm/client/useTraduction.mjs +33 -1
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/editor/ContentSelector.mjs +22 -1
- package/dist/esm/editor/ContentSelector.mjs.map +1 -1
- package/dist/esm/editor/EditorProvider.mjs +11 -1
- package/dist/esm/editor/EditorProvider.mjs.map +1 -0
- package/dist/esm/editor/useEditor.mjs +36 -1
- package/dist/esm/editor/useEditor.mjs.map +1 -0
- package/dist/esm/getDictionary.mjs +8 -1
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs +8 -1
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/html/HTMLProvider.mjs +14 -1
- package/dist/esm/html/HTMLProvider.mjs.map +1 -1
- package/dist/esm/html/HTMLRenderer.mjs +49 -1
- package/dist/esm/html/HTMLRenderer.mjs.map +1 -1
- package/dist/esm/html/index.mjs +4 -1
- package/dist/esm/index.mjs +22 -1
- package/dist/esm/markdown/MarkdownProvider.mjs +51 -1
- package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRenderer.mjs +73 -1
- package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs +23 -1
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs.map +1 -1
- package/dist/esm/markdown/compiler.mjs +17 -1
- package/dist/esm/markdown/compiler.mjs.map +1 -1
- package/dist/esm/markdown/index.mjs +7 -1
- package/dist/esm/markdown/runtime.mjs +15 -1
- package/dist/esm/markdown/runtime.mjs.map +1 -1
- package/dist/esm/plugins.mjs +212 -1
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/preactElement/renderPreactElement.mjs +40 -1
- package/dist/esm/preactElement/renderPreactElement.mjs.map +1 -1
- package/dist/types/IntlayerNode.d.ts +23 -2
- package/dist/types/IntlayerNode.d.ts.map +1 -0
- package/dist/types/client/IntlayerProvider.d.ts +53 -2
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -0
- package/dist/types/client/format/useIntl.d.ts +26 -2
- package/dist/types/client/format/useIntl.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +11 -11
- package/dist/types/client/t.d.ts +13 -2
- package/dist/types/client/t.d.ts.map +1 -0
- package/dist/types/client/useDictionary.d.ts +16 -2
- package/dist/types/client/useDictionary.d.ts.map +1 -0
- package/dist/types/client/useDictionaryAsync.d.ts +13 -2
- package/dist/types/client/useDictionaryAsync.d.ts.map +1 -0
- package/dist/types/client/useDictionaryDynamic.d.ts +16 -2
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -0
- package/dist/types/client/useIntlayer.d.ts +28 -2
- package/dist/types/client/useIntlayer.d.ts.map +1 -0
- package/dist/types/client/useLoadDynamic.d.ts +5 -2
- package/dist/types/client/useLoadDynamic.d.ts.map +1 -0
- package/dist/types/client/useLocale.d.ts +43 -2
- package/dist/types/client/useLocale.d.ts.map +1 -0
- package/dist/types/client/useLocaleBase.d.ts +16 -2
- package/dist/types/client/useLocaleBase.d.ts.map +1 -0
- package/dist/types/client/useLocaleStorage.d.ts +45 -2
- package/dist/types/client/useLocaleStorage.d.ts.map +1 -0
- package/dist/types/getDictionary.d.ts +1 -1
- package/dist/types/getIntlayer.d.ts +1 -1
- package/dist/types/html/HTMLProvider.d.ts +18 -2
- package/dist/types/html/HTMLProvider.d.ts.map +1 -0
- package/dist/types/html/HTMLRenderer.d.ts +61 -2
- package/dist/types/html/HTMLRenderer.d.ts.map +1 -0
- package/dist/types/html/index.d.ts +2 -2
- package/dist/types/html/types.d.ts +38 -2
- package/dist/types/html/types.d.ts.map +1 -0
- package/dist/types/index.d.ts +19 -19
- package/dist/types/markdown/MarkdownProvider.d.ts +52 -2
- package/dist/types/markdown/MarkdownProvider.d.ts.map +1 -0
- package/dist/types/markdown/MarkdownRenderer.d.ts +61 -2
- package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -0
- package/dist/types/markdown/MarkdownRendererPlugin.d.ts +23 -2
- package/dist/types/markdown/MarkdownRendererPlugin.d.ts.map +1 -0
- package/dist/types/markdown/compiler.d.ts +14 -2
- package/dist/types/markdown/compiler.d.ts.map +1 -0
- package/dist/types/markdown/index.d.ts +5 -5
- package/dist/types/markdown/runtime.d.ts +10 -2
- package/dist/types/markdown/runtime.d.ts.map +1 -0
- package/dist/types/plugins.d.ts +96 -2
- package/dist/types/plugins.d.ts.map +1 -0
- package/package.json +7 -7
- package/dist/cjs/IntlayerProvider-sM1gzsx7.cjs +0 -2
- package/dist/cjs/IntlayerProvider-sM1gzsx7.cjs.map +0 -1
- package/dist/esm/IntlayerProvider-ClOcEK3A.mjs +0 -2
- package/dist/esm/IntlayerProvider-ClOcEK3A.mjs.map +0 -1
- package/dist/types/HTMLProvider-8sO8DU8H.d.ts +0 -18
- package/dist/types/HTMLProvider-8sO8DU8H.d.ts.map +0 -1
- package/dist/types/HTMLRenderer-NNa_9oMD.d.ts +0 -61
- package/dist/types/HTMLRenderer-NNa_9oMD.d.ts.map +0 -1
- package/dist/types/IntlayerNode-CIzFHYnC.d.ts +0 -23
- package/dist/types/IntlayerNode-CIzFHYnC.d.ts.map +0 -1
- package/dist/types/IntlayerProvider-aV596OL4.d.ts +0 -53
- package/dist/types/IntlayerProvider-aV596OL4.d.ts.map +0 -1
- package/dist/types/MarkdownProvider-chUIO05u.d.ts +0 -52
- package/dist/types/MarkdownProvider-chUIO05u.d.ts.map +0 -1
- package/dist/types/MarkdownRenderer-BMhuurZW.d.ts +0 -61
- package/dist/types/MarkdownRenderer-BMhuurZW.d.ts.map +0 -1
- package/dist/types/MarkdownRendererPlugin-DFRVdHCA.d.ts +0 -23
- package/dist/types/MarkdownRendererPlugin-DFRVdHCA.d.ts.map +0 -1
- package/dist/types/compiler-BB0gAVbe.d.ts +0 -14
- package/dist/types/compiler-BB0gAVbe.d.ts.map +0 -1
- package/dist/types/plugins-D6OB94dO.d.ts +0 -95
- package/dist/types/plugins-D6OB94dO.d.ts.map +0 -1
- package/dist/types/runtime-BMHAtT-R.d.ts +0 -10
- package/dist/types/runtime-BMHAtT-R.d.ts.map +0 -1
- package/dist/types/t-CalXqnSB.d.ts +0 -13
- package/dist/types/t-CalXqnSB.d.ts.map +0 -1
- package/dist/types/types-B3Kzdco6.d.ts +0 -38
- package/dist/types/types-B3Kzdco6.d.ts.map +0 -1
- package/dist/types/useDictionary-cjQAc1l1.d.ts +0 -16
- package/dist/types/useDictionary-cjQAc1l1.d.ts.map +0 -1
- package/dist/types/useDictionaryAsync-CDCcBnXn.d.ts +0 -13
- package/dist/types/useDictionaryAsync-CDCcBnXn.d.ts.map +0 -1
- package/dist/types/useDictionaryDynamic-BQgaM0vp.d.ts +0 -16
- package/dist/types/useDictionaryDynamic-BQgaM0vp.d.ts.map +0 -1
- package/dist/types/useIntl-DfzrSGu4.d.ts +0 -26
- package/dist/types/useIntl-DfzrSGu4.d.ts.map +0 -1
- package/dist/types/useIntlayer-BINmW9T1.d.ts +0 -28
- package/dist/types/useIntlayer-BINmW9T1.d.ts.map +0 -1
- package/dist/types/useLoadDynamic-DFXHehpF.d.ts +0 -5
- package/dist/types/useLoadDynamic-DFXHehpF.d.ts.map +0 -1
- package/dist/types/useLocale-BDQ4yLc5.d.ts +0 -43
- package/dist/types/useLocale-BDQ4yLc5.d.ts.map +0 -1
- package/dist/types/useLocaleBase-1L1RLyXD.d.ts +0 -16
- package/dist/types/useLocaleBase-1L1RLyXD.d.ts.map +0 -1
- package/dist/types/useLocaleStorage-BwH9gqN5.d.ts +0 -45
- package/dist/types/useLocaleStorage-BwH9gqN5.d.ts.map +0 -1
|
@@ -1,2 +1,60 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let preact_hooks = require("preact/hooks");
|
|
4
|
+
let _intlayer_core_localization = require("@intlayer/core/localization");
|
|
5
|
+
let _intlayer_core_utils = require("@intlayer/core/utils");
|
|
6
|
+
|
|
7
|
+
//#region src/client/useLocaleStorage.ts
|
|
8
|
+
/**
|
|
9
|
+
* Get the locale cookie
|
|
10
|
+
*/
|
|
11
|
+
const localeInStorage = (0, _intlayer_core_utils.getLocaleFromStorage)(_intlayer_core_localization.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_utils.setLocaleInStorage)(locale, {
|
|
22
|
+
..._intlayer_core_localization.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_utils.LocaleStorage)({
|
|
35
|
+
..._intlayer_core_localization.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;
|
|
2
60
|
//# sourceMappingURL=useLocaleStorage.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleStorage.cjs","names":["localeStorageOptions"],"sources":["../../../src/client/useLocaleStorage.ts"],"sourcesContent":["import { localeStorageOptions } from '@intlayer/core/localization';\nimport {\n getLocaleFromStorage,\n LocaleStorage,\n setLocaleInStorage as setLocaleInStorageCore,\n} from '@intlayer/core/utils';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\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":"
|
|
1
|
+
{"version":3,"file":"useLocaleStorage.cjs","names":["localeStorageOptions"],"sources":["../../../src/client/useLocaleStorage.ts"],"sourcesContent":["import { localeStorageOptions } from '@intlayer/core/localization';\nimport {\n getLocaleFromStorage,\n LocaleStorage,\n setLocaleInStorage as setLocaleInStorageCore,\n} from '@intlayer/core/utils';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\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,iEAAuCA,iDAAqB;;;;;;AAMzE,MAAa,eAAe;;;;AAK5B,MAAa,sBACX,QACA,iEAEuB,QAAQ;CAC7B,GAAGA;CACH;CACD,CAAC;;;;;;AAOJ,MAAa,kBAAkB;;;;AAK/B,MAAa,oBAAoB,4FAGb;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,2 +1,36 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
4
|
+
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
5
|
+
let preact_hooks = require("preact/hooks");
|
|
6
|
+
|
|
7
|
+
//#region src/client/useTraduction.ts
|
|
8
|
+
/**
|
|
9
|
+
* On the client side, Hook that picking one dictionary by its id and return the content.
|
|
10
|
+
*
|
|
11
|
+
* If not locale found, it will return the content related to the default locale.
|
|
12
|
+
*
|
|
13
|
+
* Return either the content editor, or the content itself depending on the configuration.
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
*
|
|
17
|
+
* ```tsx
|
|
18
|
+
* const content = useTranslation<string>({
|
|
19
|
+
* en: 'Hello',
|
|
20
|
+
* fr: 'Bonjour',
|
|
21
|
+
* }, 'fr');
|
|
22
|
+
* // 'Bonjour'
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* Using TypeScript:
|
|
26
|
+
* - this function will require each locale to be defined if defined in the project configuration.
|
|
27
|
+
* - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
|
|
28
|
+
*/
|
|
29
|
+
const useTranslation = (languageContent) => {
|
|
30
|
+
const { locale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
31
|
+
return (0, preact_hooks.useMemo)(() => (0, _intlayer_core_interpreter.getTranslation)(languageContent, locale), [languageContent, locale]);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
exports.useTranslation = useTranslation;
|
|
2
36
|
//# sourceMappingURL=useTraduction.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTraduction.cjs","names":["IntlayerClientContext"],"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import { getTranslation } from '@intlayer/core/interpreter';\nimport type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\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":"
|
|
1
|
+
{"version":3,"file":"useTraduction.cjs","names":["IntlayerClientContext"],"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import { getTranslation } from '@intlayer/core/interpreter';\nimport type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\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,uFACuB,iBAAiB,OAAO,EAC7C,CAAC,iBAAiB,OAAO,CAC1B"}
|
|
@@ -1,2 +1,25 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let _intlayer_editor_isEnabled = require("@intlayer/editor/isEnabled");
|
|
4
|
+
let preact_hooks = require("preact/hooks");
|
|
5
|
+
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
6
|
+
|
|
7
|
+
//#region src/editor/ContentSelector.tsx
|
|
8
|
+
const ContentSelector = ({ children, dictionaryKey, keyPath }) => {
|
|
9
|
+
(0, preact_hooks.useEffect)(() => {
|
|
10
|
+
if (process.env.INTLAYER_EDITOR_ENABLED === "false" || !_intlayer_editor_isEnabled.isEnabled || typeof window === "undefined") return;
|
|
11
|
+
import("@intlayer/editor").then(({ defineIntlayerElements }) => {
|
|
12
|
+
defineIntlayerElements();
|
|
13
|
+
});
|
|
14
|
+
}, [_intlayer_editor_isEnabled.isEnabled]);
|
|
15
|
+
if (!_intlayer_editor_isEnabled.isEnabled) return children;
|
|
16
|
+
return /* @__PURE__ */ (0, preact_jsx_runtime.jsx)("intlayer-content-selector-wrapper", {
|
|
17
|
+
"key-path": JSON.stringify(keyPath),
|
|
18
|
+
"dictionary-key": dictionaryKey,
|
|
19
|
+
children
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.ContentSelector = ContentSelector;
|
|
2
25
|
//# sourceMappingURL=ContentSelector.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSelector.cjs","names":["isEnabled"],"sources":["../../../src/editor/ContentSelector.tsx"],"sourcesContent":["import type { NodeProps } from '@intlayer/core/interpreter';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { FunctionalComponent, HTMLAttributes } from 'preact';\nimport { useEffect } from 'preact/hooks';\n\n// JSX declaration for the Lit web component in Preact\ndeclare module 'preact' {\n namespace JSX {\n interface IntrinsicElements {\n 'intlayer-content-selector-wrapper': HTMLAttributes<HTMLElement> & {\n 'key-path'?: string;\n 'dictionary-key'?: string;\n };\n }\n }\n}\n\nexport type ContentSelectorWrapperProps = NodeProps &\n Omit<HTMLAttributes<HTMLDivElement>, 'children'>;\n\nexport const ContentSelector: FunctionalComponent<\n ContentSelectorWrapperProps\n> = ({ children, dictionaryKey, keyPath }) => {\n useEffect(() => {\n if (\n process.env.INTLAYER_EDITOR_ENABLED === 'false' ||\n !isEnabled ||\n typeof window === 'undefined'\n )\n return;\n import('@intlayer/editor').then(({ defineIntlayerElements }) => {\n defineIntlayerElements();\n });\n }, [isEnabled]);\n\n if (!isEnabled) {\n return children;\n }\n\n return (\n <intlayer-content-selector-wrapper\n key-path={JSON.stringify(keyPath)}\n dictionary-key={dictionaryKey}\n >\n {children}\n </intlayer-content-selector-wrapper>\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ContentSelector.cjs","names":["isEnabled"],"sources":["../../../src/editor/ContentSelector.tsx"],"sourcesContent":["import type { NodeProps } from '@intlayer/core/interpreter';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { FunctionalComponent, HTMLAttributes } from 'preact';\nimport { useEffect } from 'preact/hooks';\n\n// JSX declaration for the Lit web component in Preact\ndeclare module 'preact' {\n namespace JSX {\n interface IntrinsicElements {\n 'intlayer-content-selector-wrapper': HTMLAttributes<HTMLElement> & {\n 'key-path'?: string;\n 'dictionary-key'?: string;\n };\n }\n }\n}\n\nexport type ContentSelectorWrapperProps = NodeProps &\n Omit<HTMLAttributes<HTMLDivElement>, 'children'>;\n\nexport const ContentSelector: FunctionalComponent<\n ContentSelectorWrapperProps\n> = ({ children, dictionaryKey, keyPath }) => {\n useEffect(() => {\n if (\n process.env.INTLAYER_EDITOR_ENABLED === 'false' ||\n !isEnabled ||\n typeof window === 'undefined'\n )\n return;\n import('@intlayer/editor').then(({ defineIntlayerElements }) => {\n defineIntlayerElements();\n });\n }, [isEnabled]);\n\n if (!isEnabled) {\n return children;\n }\n\n return (\n <intlayer-content-selector-wrapper\n key-path={JSON.stringify(keyPath)}\n dictionary-key={dictionaryKey}\n >\n {children}\n </intlayer-content-selector-wrapper>\n );\n};\n"],"mappings":";;;;;;;AAoBA,MAAa,mBAER,EAAE,UAAU,eAAe,cAAc;AAC5C,mCAAgB;AACd,MACE,QAAQ,IAAI,4BAA4B,WACxC,CAACA,wCACD,OAAO,WAAW,YAElB;AACF,SAAO,oBAAoB,MAAM,EAAE,6BAA6B;AAC9D,2BAAwB;IACxB;IACD,CAACA,qCAAU,CAAC;AAEf,KAAI,CAACA,qCACH,QAAO;AAGT,QACE,4CAAC,qCAAD;EACE,YAAU,KAAK,UAAU,QAAQ;EACjC,kBAAgB;EAEf;EACiC"}
|
|
@@ -1 +1,12 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_editor_useEditor = require('./useEditor.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/editor/EditorProvider.tsx
|
|
5
|
+
const EditorProvider = ({ children }) => {
|
|
6
|
+
require_editor_useEditor.useEditor();
|
|
7
|
+
return children;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
exports.EditorProvider = EditorProvider;
|
|
12
|
+
//# sourceMappingURL=EditorProvider.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EditorProvider.cjs","names":[],"sources":["../../../src/editor/EditorProvider.tsx"],"sourcesContent":["import type { ComponentChild, FunctionComponent } from 'preact';\nimport { useEditor } from './useEditor';\n\nexport const EditorProvider: FunctionComponent<{\n children?: ComponentChild;\n}> = ({ children }) => {\n useEditor();\n\n return children;\n};\n"],"mappings":";;;;AAGA,MAAa,kBAEP,EAAE,eAAe;AACrB,qCAAW;AAEX,QAAO"}
|
|
@@ -1 +1,38 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_client_IntlayerProvider = require('../client/IntlayerProvider.cjs');
|
|
4
|
+
let _intlayer_editor_isEnabled = require("@intlayer/editor/isEnabled");
|
|
5
|
+
let preact_hooks = require("preact/hooks");
|
|
6
|
+
|
|
7
|
+
//#region src/editor/useEditor.tsx
|
|
8
|
+
/**
|
|
9
|
+
* Initialises the Intlayer editor client singleton when the editor is enabled.
|
|
10
|
+
* Syncs the current locale from the Intlayer context into the editor manager so
|
|
11
|
+
* the editor always knows which locale the app is displaying.
|
|
12
|
+
*/
|
|
13
|
+
const useEditor = () => {
|
|
14
|
+
const { locale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
15
|
+
const managerRef = (0, preact_hooks.useRef)(null);
|
|
16
|
+
(0, preact_hooks.useEffect)(() => {
|
|
17
|
+
if (process.env.INTLAYER_EDITOR_ENABLED === "false" || !_intlayer_editor_isEnabled.isEnabled) return;
|
|
18
|
+
import("@intlayer/editor").then(({ initEditorClient }) => {
|
|
19
|
+
const manager = initEditorClient();
|
|
20
|
+
managerRef.current = manager;
|
|
21
|
+
if (locale) manager.currentLocale.set(locale);
|
|
22
|
+
});
|
|
23
|
+
return () => {
|
|
24
|
+
managerRef.current = null;
|
|
25
|
+
import("@intlayer/editor").then(({ stopEditorClient }) => {
|
|
26
|
+
stopEditorClient();
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}, []);
|
|
30
|
+
(0, preact_hooks.useEffect)(() => {
|
|
31
|
+
if (!locale || !managerRef.current) return;
|
|
32
|
+
managerRef.current.currentLocale.set(locale);
|
|
33
|
+
}, [locale]);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
exports.useEditor = useEditor;
|
|
38
|
+
//# sourceMappingURL=useEditor.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEditor.cjs","names":["IntlayerClientContext","isEnabled"],"sources":["../../../src/editor/useEditor.tsx"],"sourcesContent":["import type { EditorStateManager } from '@intlayer/editor';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useContext, useEffect, useRef } from 'preact/hooks';\nimport { IntlayerClientContext } from '../client/IntlayerProvider';\n\n/**\n * Initialises the Intlayer editor client singleton when the editor is enabled.\n * Syncs the current locale from the Intlayer context into the editor manager so\n * the editor always knows which locale the app is displaying.\n */\nexport const useEditor = () => {\n const { locale } = useContext(IntlayerClientContext);\n const managerRef = useRef<EditorStateManager | null>(null);\n\n useEffect(() => {\n if (process.env.INTLAYER_EDITOR_ENABLED === 'false' || !isEnabled) return;\n\n import('@intlayer/editor').then(({ initEditorClient }) => {\n const manager = initEditorClient();\n managerRef.current = manager;\n\n if (locale) manager.currentLocale.set(locale as Locale);\n });\n\n return () => {\n managerRef.current = null;\n import('@intlayer/editor').then(({ stopEditorClient }) => {\n stopEditorClient();\n });\n };\n }, []);\n\n useEffect(() => {\n if (!locale || !managerRef.current) return;\n\n managerRef.current.currentLocale.set(locale as Locale);\n }, [locale]);\n};\n"],"mappings":";;;;;;;;;;;;AAWA,MAAa,kBAAkB;CAC7B,MAAM,EAAE,wCAAsBA,sDAAsB;CACpD,MAAM,sCAA+C,KAAK;AAE1D,mCAAgB;AACd,MAAI,QAAQ,IAAI,4BAA4B,WAAW,CAACC,qCAAW;AAEnE,SAAO,oBAAoB,MAAM,EAAE,uBAAuB;GACxD,MAAM,UAAU,kBAAkB;AAClC,cAAW,UAAU;AAErB,OAAI,OAAQ,SAAQ,cAAc,IAAI,OAAiB;IACvD;AAEF,eAAa;AACX,cAAW,UAAU;AACrB,UAAO,oBAAoB,MAAM,EAAE,uBAAuB;AACxD,sBAAkB;KAClB;;IAEH,EAAE,CAAC;AAEN,mCAAgB;AACd,MAAI,CAAC,UAAU,CAAC,WAAW,QAAS;AAEpC,aAAW,QAAQ,cAAc,IAAI,OAAiB;IACrD,CAAC,OAAO,CAAC"}
|
|
@@ -1,2 +1,11 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_plugins = require('./plugins.cjs');
|
|
4
|
+
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
5
|
+
|
|
6
|
+
//#region src/getDictionary.ts
|
|
7
|
+
const getDictionary = (dictionary, locale) => (0, _intlayer_core_interpreter.getDictionary)(dictionary, locale, require_plugins.getPlugins(locale));
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
exports.getDictionary = getDictionary;
|
|
2
11
|
//# sourceMappingURL=getDictionary.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDictionary.cjs","names":["getPlugins"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import { getDictionary as getDictionaryCore } from '@intlayer/core/interpreter';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\nexport const getDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n): DeepTransformContent<T['content']> =>\n getDictionaryCore<T, L>(dictionary, locale, getPlugins(locale)) as any;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getDictionary.cjs","names":["getPlugins"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import { getDictionary as getDictionaryCore } from '@intlayer/core/interpreter';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\nexport const getDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n): DeepTransformContent<T['content']> =>\n getDictionaryCore<T, L>(dictionary, locale, getPlugins(locale)) as any;\n"],"mappings":";;;;;;AAQA,MAAa,iBAIX,YACA,yDAEwB,YAAY,QAAQA,2BAAW,OAAO,CAAC"}
|
package/dist/cjs/getIntlayer.cjs
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_plugins = require('./plugins.cjs');
|
|
4
|
+
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
5
|
+
|
|
6
|
+
//#region src/getIntlayer.ts
|
|
7
|
+
const getIntlayer = (key, locale) => (0, _intlayer_core_interpreter.getIntlayer)(key, locale, require_plugins.getPlugins(locale));
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
exports.getIntlayer = getIntlayer;
|
|
2
11
|
//# sourceMappingURL=getIntlayer.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIntlayer.cjs","names":["getPlugins"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore } from '@intlayer/core/interpreter';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\nexport const getIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L\n) =>\n getIntlayerCore<T, L>(\n key,\n locale,\n getPlugins(locale)\n ) as DeepTransformContent<DictionaryRegistryContent<T>>;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getIntlayer.cjs","names":["getPlugins"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore } from '@intlayer/core/interpreter';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\nexport const getIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L\n) =>\n getIntlayerCore<T, L>(\n key,\n locale,\n getPlugins(locale)\n ) as DeepTransformContent<DictionaryRegistryContent<T>>;\n"],"mappings":";;;;;;AASA,MAAa,eAIX,KACA,uDAGE,KACA,QACAA,2BAAW,OAAO,CACnB"}
|
|
@@ -1,2 +1,18 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let preact = require("preact");
|
|
4
|
+
let preact_hooks = require("preact/hooks");
|
|
5
|
+
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
6
|
+
|
|
7
|
+
//#region src/html/HTMLProvider.tsx
|
|
8
|
+
const HTMLContext = (0, preact.createContext)(void 0);
|
|
9
|
+
const useHTMLContext = () => (0, preact_hooks.useContext)(HTMLContext);
|
|
10
|
+
const HTMLProvider = ({ children, components }) => /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(HTMLContext.Provider, {
|
|
11
|
+
value: { components },
|
|
12
|
+
children
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.HTMLProvider = HTMLProvider;
|
|
17
|
+
exports.useHTMLContext = useHTMLContext;
|
|
2
18
|
//# sourceMappingURL=HTMLProvider.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HTMLProvider.cjs","names":[],"sources":["../../../src/html/HTMLProvider.tsx"],"sourcesContent":["import {\n createContext,\n type FunctionalComponent,\n type RenderableProps,\n} from 'preact';\nimport { useContext } from 'preact/hooks';\nimport type { HTMLComponents } from './types';\n\ntype HTMLContextValue = {\n components?: HTMLComponents<'permissive', {}>;\n};\n\ntype HTMLProviderProps = RenderableProps<{\n /**\n * Component overrides for HTML tags.\n */\n components?: HTMLComponents<'permissive', {}>;\n}>;\n\nconst HTMLContext = createContext<HTMLContextValue | undefined>(undefined);\n\nexport const useHTMLContext = () => useContext(HTMLContext);\n\nexport const HTMLProvider: FunctionalComponent<HTMLProviderProps> = ({\n children,\n components,\n}) => (\n <HTMLContext.Provider value={{ components }}>{children}</HTMLContext.Provider>\n);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"HTMLProvider.cjs","names":[],"sources":["../../../src/html/HTMLProvider.tsx"],"sourcesContent":["import {\n createContext,\n type FunctionalComponent,\n type RenderableProps,\n} from 'preact';\nimport { useContext } from 'preact/hooks';\nimport type { HTMLComponents } from './types';\n\ntype HTMLContextValue = {\n components?: HTMLComponents<'permissive', {}>;\n};\n\ntype HTMLProviderProps = RenderableProps<{\n /**\n * Component overrides for HTML tags.\n */\n components?: HTMLComponents<'permissive', {}>;\n}>;\n\nconst HTMLContext = createContext<HTMLContextValue | undefined>(undefined);\n\nexport const useHTMLContext = () => useContext(HTMLContext);\n\nexport const HTMLProvider: FunctionalComponent<HTMLProviderProps> = ({\n children,\n components,\n}) => (\n <HTMLContext.Provider value={{ components }}>{children}</HTMLContext.Provider>\n);\n"],"mappings":";;;;;;;AAmBA,MAAM,wCAA0D,OAAU;AAE1E,MAAa,oDAAkC,YAAY;AAE3D,MAAa,gBAAwD,EACnE,UACA,iBAEA,4CAAC,YAAY,UAAb;CAAsB,OAAO,EAAE,YAAY;CAAG;CAAgC"}
|
|
@@ -1,2 +1,55 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_html_HTMLProvider = require('./HTMLProvider.cjs');
|
|
4
|
+
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
5
|
+
let preact = require("preact");
|
|
6
|
+
let _intlayer_core_transpiler = require("@intlayer/core/transpiler");
|
|
7
|
+
|
|
8
|
+
//#region src/html/HTMLRenderer.tsx
|
|
9
|
+
const createDefaultHTMLComponents = () => {
|
|
10
|
+
const components = {};
|
|
11
|
+
for (const tag of _intlayer_core_transpiler.HTML_TAGS) components[tag] = ({ children, ...props }) => (0, preact.h)(tag, props, children);
|
|
12
|
+
return components;
|
|
13
|
+
};
|
|
14
|
+
const defaultHTMLComponents = createDefaultHTMLComponents();
|
|
15
|
+
/**
|
|
16
|
+
* Renders HTML-like content to JSX with the provided components.
|
|
17
|
+
*
|
|
18
|
+
* This function does not use context from HTMLProvider. Use `useHTMLRenderer`
|
|
19
|
+
* hook if you want to leverage provider context.
|
|
20
|
+
*/
|
|
21
|
+
const renderHTML = (content, { components } = {}) => {
|
|
22
|
+
const mergedComponents = {
|
|
23
|
+
...defaultHTMLComponents,
|
|
24
|
+
...components
|
|
25
|
+
};
|
|
26
|
+
return (0, preact.h)(preact.Fragment, null, (0, _intlayer_core_interpreter.getHTML)(content, Object.fromEntries(Object.entries(mergedComponents).filter(([, Component]) => Component).map(([key, Component]) => [key, (props) => (0, preact.h)(Component, props)]))));
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Hook that returns a function to render HTML content.
|
|
30
|
+
*
|
|
31
|
+
* This hook considers the configuration from the `HTMLProvider` context if available,
|
|
32
|
+
* falling back to the provided components.
|
|
33
|
+
*/
|
|
34
|
+
const useHTMLRenderer = ({ components } = {}) => {
|
|
35
|
+
const context = require_html_HTMLProvider.useHTMLContext();
|
|
36
|
+
return (content) => {
|
|
37
|
+
return renderHTML(content, { components: {
|
|
38
|
+
...context?.components,
|
|
39
|
+
...components
|
|
40
|
+
} });
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Preact component that renders HTML-like content to JSX.
|
|
45
|
+
*/
|
|
46
|
+
const HTMLRenderer = ({ children = "", html, components }) => {
|
|
47
|
+
return useHTMLRenderer({ components })(children || html || "");
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
exports.HTMLRenderer = HTMLRenderer;
|
|
52
|
+
exports.defaultHTMLComponents = defaultHTMLComponents;
|
|
53
|
+
exports.renderHTML = renderHTML;
|
|
54
|
+
exports.useHTMLRenderer = useHTMLRenderer;
|
|
2
55
|
//# sourceMappingURL=HTMLRenderer.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HTMLRenderer.cjs","names":["HTML_TAGS","Fragment","useHTMLContext"],"sources":["../../../src/html/HTMLRenderer.tsx"],"sourcesContent":["import { getHTML } from '@intlayer/core/interpreter';\nimport { HTML_TAGS } from '@intlayer/core/transpiler';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { Fragment, type FunctionComponent, h, type JSX } from 'preact';\nimport { useHTMLContext } from './HTMLProvider';\nimport type { HTMLComponents } from './types';\n\n/**\n * Type for Preact HTML tag components.\n */\ntype HTMLTagComponent = (props: {\n children?: any;\n [key: string]: any;\n}) => JSX.Element;\n\nconst createDefaultHTMLComponents = (): Record<string, HTMLTagComponent> => {\n const components: Record<string, HTMLTagComponent> = {};\n\n for (const tag of HTML_TAGS) {\n components[tag] = ({ children, ...props }) =>\n h(tag as any, props, children);\n }\n\n return components;\n};\n\nexport const defaultHTMLComponents = createDefaultHTMLComponents();\n\nexport type RenderHTMLProps = {\n /**\n * Component overrides for HTML tags.\n * Allows you to customize how specific HTML elements are rendered.\n */\n components?: HTMLComponents<'permissive', {}>;\n};\n\n/**\n * Renders HTML-like content to JSX with the provided components.\n *\n * This function does not use context from HTMLProvider. Use `useHTMLRenderer`\n * hook if you want to leverage provider context.\n */\nexport const renderHTML = (\n content: string,\n { components }: RenderHTMLProps = {}\n): JSX.Element => {\n const mergedComponents = {\n ...defaultHTMLComponents,\n ...components,\n };\n\n // Wrap all components to ensure they are rendered via Preact's h\n const wrappedComponents = Object.fromEntries(\n Object.entries(mergedComponents)\n .filter(([, Component]) => Component)\n .map(([key, Component]) => [\n key,\n (props: any) => h(Component as any, props),\n ])\n );\n\n return h(Fragment, null, getHTML(content, wrappedComponents));\n};\n\n/**\n * Hook that returns a function to render HTML content.\n *\n * This hook considers the configuration from the `HTMLProvider` context if available,\n * falling back to the provided components.\n */\nexport const useHTMLRenderer = ({ components }: RenderHTMLProps = {}) => {\n const context = useHTMLContext();\n\n return (content: string) => {\n return renderHTML(content, {\n components: {\n ...context?.components,\n ...components,\n },\n });\n };\n};\n\nexport type HTMLRendererProps = RenderHTMLProps & {\n /**\n * The HTML content to render as a string.\n */\n children?: string;\n /**\n * Alias for children, used by the plugin.\n */\n html?: string;\n /**\n * Alias for components, used by the plugin.\n */\n components?: HTMLComponents<'permissive', {}>;\n dictionaryKey?: string;\n keyPath?: KeyPath[];\n};\n\n/**\n * Preact component that renders HTML-like content to JSX.\n */\nexport const HTMLRenderer: FunctionComponent<HTMLRendererProps> = ({\n children = '',\n html,\n components,\n}) => {\n const render = useHTMLRenderer({ components: components });\n const content = children || html || '';\n\n return render(content);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"HTMLRenderer.cjs","names":["HTML_TAGS","Fragment","useHTMLContext"],"sources":["../../../src/html/HTMLRenderer.tsx"],"sourcesContent":["import { getHTML } from '@intlayer/core/interpreter';\nimport { HTML_TAGS } from '@intlayer/core/transpiler';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { Fragment, type FunctionComponent, h, type JSX } from 'preact';\nimport { useHTMLContext } from './HTMLProvider';\nimport type { HTMLComponents } from './types';\n\n/**\n * Type for Preact HTML tag components.\n */\ntype HTMLTagComponent = (props: {\n children?: any;\n [key: string]: any;\n}) => JSX.Element;\n\nconst createDefaultHTMLComponents = (): Record<string, HTMLTagComponent> => {\n const components: Record<string, HTMLTagComponent> = {};\n\n for (const tag of HTML_TAGS) {\n components[tag] = ({ children, ...props }) =>\n h(tag as any, props, children);\n }\n\n return components;\n};\n\nexport const defaultHTMLComponents = createDefaultHTMLComponents();\n\nexport type RenderHTMLProps = {\n /**\n * Component overrides for HTML tags.\n * Allows you to customize how specific HTML elements are rendered.\n */\n components?: HTMLComponents<'permissive', {}>;\n};\n\n/**\n * Renders HTML-like content to JSX with the provided components.\n *\n * This function does not use context from HTMLProvider. Use `useHTMLRenderer`\n * hook if you want to leverage provider context.\n */\nexport const renderHTML = (\n content: string,\n { components }: RenderHTMLProps = {}\n): JSX.Element => {\n const mergedComponents = {\n ...defaultHTMLComponents,\n ...components,\n };\n\n // Wrap all components to ensure they are rendered via Preact's h\n const wrappedComponents = Object.fromEntries(\n Object.entries(mergedComponents)\n .filter(([, Component]) => Component)\n .map(([key, Component]) => [\n key,\n (props: any) => h(Component as any, props),\n ])\n );\n\n return h(Fragment, null, getHTML(content, wrappedComponents));\n};\n\n/**\n * Hook that returns a function to render HTML content.\n *\n * This hook considers the configuration from the `HTMLProvider` context if available,\n * falling back to the provided components.\n */\nexport const useHTMLRenderer = ({ components }: RenderHTMLProps = {}) => {\n const context = useHTMLContext();\n\n return (content: string) => {\n return renderHTML(content, {\n components: {\n ...context?.components,\n ...components,\n },\n });\n };\n};\n\nexport type HTMLRendererProps = RenderHTMLProps & {\n /**\n * The HTML content to render as a string.\n */\n children?: string;\n /**\n * Alias for children, used by the plugin.\n */\n html?: string;\n /**\n * Alias for components, used by the plugin.\n */\n components?: HTMLComponents<'permissive', {}>;\n dictionaryKey?: string;\n keyPath?: KeyPath[];\n};\n\n/**\n * Preact component that renders HTML-like content to JSX.\n */\nexport const HTMLRenderer: FunctionComponent<HTMLRendererProps> = ({\n children = '',\n html,\n components,\n}) => {\n const render = useHTMLRenderer({ components: components });\n const content = children || html || '';\n\n return render(content);\n};\n"],"mappings":";;;;;;;;AAeA,MAAM,oCAAsE;CAC1E,MAAM,aAA+C,EAAE;AAEvD,MAAK,MAAM,OAAOA,oCAChB,YAAW,QAAQ,EAAE,UAAU,GAAG,0BAC9B,KAAY,OAAO,SAAS;AAGlC,QAAO;;AAGT,MAAa,wBAAwB,6BAA6B;;;;;;;AAgBlE,MAAa,cACX,SACA,EAAE,eAAgC,EAAE,KACpB;CAChB,MAAM,mBAAmB;EACvB,GAAG;EACH,GAAG;EACJ;AAYD,sBAASC,iBAAU,8CAAc,SATP,OAAO,YAC/B,OAAO,QAAQ,iBAAiB,CAC7B,QAAQ,GAAG,eAAe,UAAU,CACpC,KAAK,CAAC,KAAK,eAAe,CACzB,MACC,wBAAiB,WAAkB,MAAM,CAC3C,CAAC,CACL,CAE2D,CAAC;;;;;;;;AAS/D,MAAa,mBAAmB,EAAE,eAAgC,EAAE,KAAK;CACvE,MAAM,UAAUC,0CAAgB;AAEhC,SAAQ,YAAoB;AAC1B,SAAO,WAAW,SAAS,EACzB,YAAY;GACV,GAAG,SAAS;GACZ,GAAG;GACJ,EACF,CAAC;;;;;;AAwBN,MAAa,gBAAsD,EACjE,WAAW,IACX,MACA,iBACI;AAIJ,QAHe,gBAAgB,EAAc,YAAY,CAAC,CAC1C,YAAY,QAAQ,GAEd"}
|
package/dist/cjs/html/index.cjs
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_html_HTMLProvider = require('./HTMLProvider.cjs');
|
|
3
|
+
const require_html_HTMLRenderer = require('./HTMLRenderer.cjs');
|
|
4
|
+
|
|
5
|
+
exports.HTMLProvider = require_html_HTMLProvider.HTMLProvider;
|
|
6
|
+
exports.HTMLRenderer = require_html_HTMLRenderer.HTMLRenderer;
|
|
7
|
+
exports.defaultHTMLComponents = require_html_HTMLRenderer.defaultHTMLComponents;
|
|
8
|
+
exports.renderHTML = require_html_HTMLRenderer.renderHTML;
|
|
9
|
+
exports.useHTMLContext = require_html_HTMLProvider.useHTMLContext;
|
|
10
|
+
exports.useHTMLRenderer = require_html_HTMLRenderer.useHTMLRenderer;
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1 +1,57 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_html_HTMLProvider = require('./html/HTMLProvider.cjs');
|
|
3
|
+
const require_html_HTMLRenderer = require('./html/HTMLRenderer.cjs');
|
|
4
|
+
const require_markdown_runtime = require('./markdown/runtime.cjs');
|
|
5
|
+
const require_markdown_compiler = require('./markdown/compiler.cjs');
|
|
6
|
+
const require_markdown_MarkdownProvider = require('./markdown/MarkdownProvider.cjs');
|
|
7
|
+
const require_markdown_MarkdownRenderer = require('./markdown/MarkdownRenderer.cjs');
|
|
8
|
+
const require_client_useLocaleStorage = require('./client/useLocaleStorage.cjs');
|
|
9
|
+
const require_client_IntlayerProvider = require('./client/IntlayerProvider.cjs');
|
|
10
|
+
const require_client_useLocale = require('./client/useLocale.cjs');
|
|
11
|
+
const require_plugins = require('./plugins.cjs');
|
|
12
|
+
const require_getIntlayer = require('./getIntlayer.cjs');
|
|
13
|
+
const require_getDictionary = require('./getDictionary.cjs');
|
|
14
|
+
const require_client_format_useIntl = require('./client/format/useIntl.cjs');
|
|
15
|
+
const require_client_t = require('./client/t.cjs');
|
|
16
|
+
const require_client_useDictionary = require('./client/useDictionary.cjs');
|
|
17
|
+
const require_client_useDictionaryAsync = require('./client/useDictionaryAsync.cjs');
|
|
18
|
+
const require_client_useLoadDynamic = require('./client/useLoadDynamic.cjs');
|
|
19
|
+
const require_client_useDictionaryDynamic = require('./client/useDictionaryDynamic.cjs');
|
|
20
|
+
const require_client_useIntlayer = require('./client/useIntlayer.cjs');
|
|
21
|
+
const require_client_useLocaleBase = require('./client/useLocaleBase.cjs');
|
|
22
|
+
|
|
23
|
+
exports.HTMLProvider = require_html_HTMLProvider.HTMLProvider;
|
|
24
|
+
exports.HTMLRenderer = require_html_HTMLRenderer.HTMLRenderer;
|
|
25
|
+
exports.IntlayerClientContext = require_client_IntlayerProvider.IntlayerClientContext;
|
|
26
|
+
exports.IntlayerProvider = require_client_IntlayerProvider.IntlayerProvider;
|
|
27
|
+
exports.IntlayerProviderContent = require_client_IntlayerProvider.IntlayerProviderContent;
|
|
28
|
+
exports.MarkdownProvider = require_markdown_MarkdownProvider.MarkdownProvider;
|
|
29
|
+
exports.MarkdownRenderer = require_markdown_MarkdownRenderer.MarkdownRenderer;
|
|
30
|
+
exports.compileMarkdown = require_markdown_compiler.compileMarkdown;
|
|
31
|
+
exports.getDictionary = require_getDictionary.getDictionary;
|
|
32
|
+
exports.getIntlayer = require_getIntlayer.getIntlayer;
|
|
33
|
+
exports.htmlPlugin = require_plugins.htmlPlugin;
|
|
34
|
+
exports.intlayerNodePlugins = require_plugins.intlayerNodePlugins;
|
|
35
|
+
exports.localeCookie = require_client_useLocaleStorage.localeCookie;
|
|
36
|
+
exports.markdownPlugin = require_plugins.markdownPlugin;
|
|
37
|
+
exports.markdownStringPlugin = require_plugins.markdownStringPlugin;
|
|
38
|
+
exports.preactNodePlugins = require_plugins.preactNodePlugins;
|
|
39
|
+
exports.preactRuntime = require_markdown_runtime;
|
|
40
|
+
exports.renderHTML = require_html_HTMLRenderer.renderHTML;
|
|
41
|
+
exports.renderMarkdown = require_markdown_MarkdownRenderer.renderMarkdown;
|
|
42
|
+
exports.setLocaleCookie = require_client_useLocaleStorage.setLocaleCookie;
|
|
43
|
+
exports.setLocaleInStorage = require_client_useLocaleStorage.setLocaleInStorage;
|
|
44
|
+
exports.t = require_client_t.t;
|
|
45
|
+
exports.useDictionary = require_client_useDictionary.useDictionary;
|
|
46
|
+
exports.useDictionaryAsync = require_client_useDictionaryAsync.useDictionaryAsync;
|
|
47
|
+
exports.useDictionaryDynamic = require_client_useDictionaryDynamic.useDictionaryDynamic;
|
|
48
|
+
exports.useHTMLRenderer = require_html_HTMLRenderer.useHTMLRenderer;
|
|
49
|
+
exports.useIntl = require_client_format_useIntl.useIntl;
|
|
50
|
+
exports.useIntlayer = require_client_useIntlayer.useIntlayer;
|
|
51
|
+
exports.useIntlayerContext = require_client_IntlayerProvider.useIntlayerContext;
|
|
52
|
+
exports.useLoadDynamic = require_client_useLoadDynamic.useLoadDynamic;
|
|
53
|
+
exports.useLocale = require_client_useLocale.useLocale;
|
|
54
|
+
exports.useLocaleBase = require_client_useLocaleBase.useLocaleBase;
|
|
55
|
+
exports.useLocaleCookie = require_client_useLocaleStorage.useLocaleCookie;
|
|
56
|
+
exports.useLocaleStorage = require_client_useLocaleStorage.useLocaleStorage;
|
|
57
|
+
exports.useMarkdownRenderer = require_markdown_MarkdownRenderer.useMarkdownRenderer;
|
|
@@ -1,2 +1,55 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_markdown_compiler = require('./compiler.cjs');
|
|
4
|
+
let preact = require("preact");
|
|
5
|
+
let preact_hooks = require("preact/hooks");
|
|
6
|
+
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
7
|
+
|
|
8
|
+
//#region src/markdown/MarkdownProvider.tsx
|
|
9
|
+
const MarkdownContext = (0, preact.createContext)(void 0);
|
|
10
|
+
const useMarkdownContext = () => (0, preact_hooks.useContext)(MarkdownContext);
|
|
11
|
+
const mergeOptions = (baseComponents, baseOptions, options = {}, components = {}, wrapper) => {
|
|
12
|
+
return {
|
|
13
|
+
...baseOptions,
|
|
14
|
+
...options,
|
|
15
|
+
forceBlock: options.forceBlock ?? baseOptions.forceBlock,
|
|
16
|
+
forceInline: options.forceInline ?? baseOptions.forceInline,
|
|
17
|
+
preserveFrontmatter: options.preserveFrontmatter ?? baseOptions.preserveFrontmatter,
|
|
18
|
+
tagfilter: options.tagfilter ?? baseOptions.tagfilter,
|
|
19
|
+
wrapper: wrapper || baseOptions.wrapper,
|
|
20
|
+
forceWrapper: !!(wrapper || baseOptions.wrapper),
|
|
21
|
+
components: {
|
|
22
|
+
...baseComponents,
|
|
23
|
+
...components
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const MarkdownProvider = ({ children, components, wrapper, forceBlock, forceInline, preserveFrontmatter, tagfilter, renderMarkdown: customRenderFn }) => {
|
|
28
|
+
const baseOptions = {
|
|
29
|
+
forceBlock,
|
|
30
|
+
forceInline,
|
|
31
|
+
wrapper,
|
|
32
|
+
forceWrapper: !!wrapper,
|
|
33
|
+
preserveFrontmatter,
|
|
34
|
+
tagfilter
|
|
35
|
+
};
|
|
36
|
+
const defaultRenderMarkdown = (markdown, options, componentsOverride, wrapperOverride) => {
|
|
37
|
+
return require_markdown_compiler.compileMarkdown(markdown, mergeOptions(components, baseOptions, options, componentsOverride ?? {}, wrapperOverride));
|
|
38
|
+
};
|
|
39
|
+
const customRenderMarkdownWrapper = (markdown, options, componentsOverride, wrapperOverride) => /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(MarkdownContext.Provider, {
|
|
40
|
+
value: void 0,
|
|
41
|
+
children: customRenderFn?.(markdown, options, componentsOverride, wrapperOverride)
|
|
42
|
+
});
|
|
43
|
+
return /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(MarkdownContext.Provider, {
|
|
44
|
+
value: {
|
|
45
|
+
components,
|
|
46
|
+
renderMarkdown: customRenderFn ? customRenderMarkdownWrapper : defaultRenderMarkdown
|
|
47
|
+
},
|
|
48
|
+
children
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
exports.MarkdownProvider = MarkdownProvider;
|
|
54
|
+
exports.useMarkdownContext = useMarkdownContext;
|
|
2
55
|
//# sourceMappingURL=MarkdownProvider.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownProvider.cjs","names":["compileMarkdown"],"sources":["../../../src/markdown/MarkdownProvider.tsx"],"sourcesContent":["import {\n type ComponentChildren,\n createContext,\n type FunctionComponent,\n} from 'preact';\nimport { useContext } from 'preact/hooks';\nimport type { HTMLComponents } from '../html/types';\nimport { compileMarkdown } from './compiler';\n\ntype PropsWithChildren<P = {}> = P & { children?: ComponentChildren };\n\n/**\n * Refined options for the MarkdownProvider.\n */\nexport type MarkdownProviderOptions = {\n /**\n * Forces the compiler to always output content with a block-level wrapper.\n */\n forceBlock?: boolean;\n /**\n * Forces the compiler to always output content with an inline wrapper.\n */\n forceInline?: boolean;\n /**\n * Whether to preserve frontmatter in the markdown content.\n */\n preserveFrontmatter?: boolean;\n /**\n * Whether to use the GitHub Tag Filter.\n */\n tagfilter?: boolean;\n};\n\ntype RenderMarkdownOptions = MarkdownProviderOptions & {\n components?: HTMLComponents<'permissive', {}>;\n wrapper?: any;\n};\n\ntype MarkdownContextValue = {\n components?: HTMLComponents<'permissive', {}>;\n renderMarkdown: (\n markdown: string,\n options?: MarkdownProviderOptions,\n components?: HTMLComponents<'permissive', {}>,\n wrapper?: any\n ) => ComponentChildren;\n};\n\ntype MarkdownProviderProps = PropsWithChildren<\n MarkdownProviderOptions & {\n /**\n * Component overrides for HTML tags.\n */\n components?: HTMLComponents<'permissive', {}>;\n /**\n * Wrapper element or component to be used when there are multiple children.\n */\n wrapper?: any;\n /**\n * Custom render function for markdown.\n * If provided, it will overwrite all rules and default rendering.\n */\n renderMarkdown?: (\n markdown: string,\n options?: MarkdownProviderOptions,\n components?: HTMLComponents<'permissive', {}>,\n wrapper?: any\n ) => ComponentChildren;\n }\n>;\n\nconst MarkdownContext = createContext<MarkdownContextValue | undefined>(\n undefined\n);\n\nexport const useMarkdownContext = () => useContext(MarkdownContext);\n\nconst mergeOptions = (\n baseComponents: HTMLComponents<'permissive', {}> | undefined,\n baseOptions: Omit<RenderMarkdownOptions, 'components'>,\n options: MarkdownProviderOptions = {},\n components: HTMLComponents<'permissive', {}> = {},\n wrapper?: any\n): RenderMarkdownOptions => {\n return {\n ...baseOptions,\n ...options,\n forceBlock: options.forceBlock ?? baseOptions.forceBlock,\n forceInline: options.forceInline ?? baseOptions.forceInline,\n preserveFrontmatter:\n options.preserveFrontmatter ?? baseOptions.preserveFrontmatter,\n tagfilter: options.tagfilter ?? baseOptions.tagfilter,\n wrapper: wrapper || baseOptions.wrapper,\n forceWrapper: !!(wrapper || baseOptions.wrapper),\n components: { ...baseComponents, ...components },\n };\n};\n\nexport const MarkdownProvider: FunctionComponent<MarkdownProviderProps> = ({\n children,\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n renderMarkdown: customRenderFn,\n}) => {\n const baseOptions: Omit<RenderMarkdownOptions, 'components'> = {\n forceBlock,\n forceInline,\n wrapper,\n forceWrapper: !!wrapper,\n preserveFrontmatter,\n tagfilter,\n };\n\n // Standard internal renderer\n const defaultRenderMarkdown = (\n markdown: string,\n options?: MarkdownProviderOptions,\n componentsOverride?: HTMLComponents<'permissive', {}>,\n wrapperOverride?: any\n ): ComponentChildren => {\n const mergedOptions = mergeOptions(\n components,\n baseOptions,\n options,\n componentsOverride ?? {},\n wrapperOverride\n );\n return compileMarkdown(markdown, mergedOptions) as ComponentChildren;\n };\n\n // Wrapper for user-provided custom renderer\n // Note: We wrap in a clean Provider to prevent infinite recursion\n const customRenderMarkdownWrapper = (\n markdown: string,\n options?: MarkdownProviderOptions,\n componentsOverride?: HTMLComponents<'permissive', {}>,\n wrapperOverride?: any\n ): ComponentChildren => (\n <MarkdownContext.Provider value={undefined}>\n {customRenderFn?.(markdown, options, componentsOverride, wrapperOverride)}\n </MarkdownContext.Provider>\n );\n\n return (\n <MarkdownContext.Provider\n value={{\n components,\n renderMarkdown: customRenderFn\n ? customRenderMarkdownWrapper\n : defaultRenderMarkdown,\n }}\n >\n {children}\n </MarkdownContext.Provider>\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"MarkdownProvider.cjs","names":["compileMarkdown"],"sources":["../../../src/markdown/MarkdownProvider.tsx"],"sourcesContent":["import {\n type ComponentChildren,\n createContext,\n type FunctionComponent,\n} from 'preact';\nimport { useContext } from 'preact/hooks';\nimport type { HTMLComponents } from '../html/types';\nimport { compileMarkdown } from './compiler';\n\ntype PropsWithChildren<P = {}> = P & { children?: ComponentChildren };\n\n/**\n * Refined options for the MarkdownProvider.\n */\nexport type MarkdownProviderOptions = {\n /**\n * Forces the compiler to always output content with a block-level wrapper.\n */\n forceBlock?: boolean;\n /**\n * Forces the compiler to always output content with an inline wrapper.\n */\n forceInline?: boolean;\n /**\n * Whether to preserve frontmatter in the markdown content.\n */\n preserveFrontmatter?: boolean;\n /**\n * Whether to use the GitHub Tag Filter.\n */\n tagfilter?: boolean;\n};\n\ntype RenderMarkdownOptions = MarkdownProviderOptions & {\n components?: HTMLComponents<'permissive', {}>;\n wrapper?: any;\n};\n\ntype MarkdownContextValue = {\n components?: HTMLComponents<'permissive', {}>;\n renderMarkdown: (\n markdown: string,\n options?: MarkdownProviderOptions,\n components?: HTMLComponents<'permissive', {}>,\n wrapper?: any\n ) => ComponentChildren;\n};\n\ntype MarkdownProviderProps = PropsWithChildren<\n MarkdownProviderOptions & {\n /**\n * Component overrides for HTML tags.\n */\n components?: HTMLComponents<'permissive', {}>;\n /**\n * Wrapper element or component to be used when there are multiple children.\n */\n wrapper?: any;\n /**\n * Custom render function for markdown.\n * If provided, it will overwrite all rules and default rendering.\n */\n renderMarkdown?: (\n markdown: string,\n options?: MarkdownProviderOptions,\n components?: HTMLComponents<'permissive', {}>,\n wrapper?: any\n ) => ComponentChildren;\n }\n>;\n\nconst MarkdownContext = createContext<MarkdownContextValue | undefined>(\n undefined\n);\n\nexport const useMarkdownContext = () => useContext(MarkdownContext);\n\nconst mergeOptions = (\n baseComponents: HTMLComponents<'permissive', {}> | undefined,\n baseOptions: Omit<RenderMarkdownOptions, 'components'>,\n options: MarkdownProviderOptions = {},\n components: HTMLComponents<'permissive', {}> = {},\n wrapper?: any\n): RenderMarkdownOptions => {\n return {\n ...baseOptions,\n ...options,\n forceBlock: options.forceBlock ?? baseOptions.forceBlock,\n forceInline: options.forceInline ?? baseOptions.forceInline,\n preserveFrontmatter:\n options.preserveFrontmatter ?? baseOptions.preserveFrontmatter,\n tagfilter: options.tagfilter ?? baseOptions.tagfilter,\n wrapper: wrapper || baseOptions.wrapper,\n forceWrapper: !!(wrapper || baseOptions.wrapper),\n components: { ...baseComponents, ...components },\n };\n};\n\nexport const MarkdownProvider: FunctionComponent<MarkdownProviderProps> = ({\n children,\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n renderMarkdown: customRenderFn,\n}) => {\n const baseOptions: Omit<RenderMarkdownOptions, 'components'> = {\n forceBlock,\n forceInline,\n wrapper,\n forceWrapper: !!wrapper,\n preserveFrontmatter,\n tagfilter,\n };\n\n // Standard internal renderer\n const defaultRenderMarkdown = (\n markdown: string,\n options?: MarkdownProviderOptions,\n componentsOverride?: HTMLComponents<'permissive', {}>,\n wrapperOverride?: any\n ): ComponentChildren => {\n const mergedOptions = mergeOptions(\n components,\n baseOptions,\n options,\n componentsOverride ?? {},\n wrapperOverride\n );\n return compileMarkdown(markdown, mergedOptions) as ComponentChildren;\n };\n\n // Wrapper for user-provided custom renderer\n // Note: We wrap in a clean Provider to prevent infinite recursion\n const customRenderMarkdownWrapper = (\n markdown: string,\n options?: MarkdownProviderOptions,\n componentsOverride?: HTMLComponents<'permissive', {}>,\n wrapperOverride?: any\n ): ComponentChildren => (\n <MarkdownContext.Provider value={undefined}>\n {customRenderFn?.(markdown, options, componentsOverride, wrapperOverride)}\n </MarkdownContext.Provider>\n );\n\n return (\n <MarkdownContext.Provider\n value={{\n components,\n renderMarkdown: customRenderFn\n ? customRenderMarkdownWrapper\n : defaultRenderMarkdown,\n }}\n >\n {children}\n </MarkdownContext.Provider>\n );\n};\n"],"mappings":";;;;;;;;AAuEA,MAAM,4CACJ,OACD;AAED,MAAa,wDAAsC,gBAAgB;AAEnE,MAAM,gBACJ,gBACA,aACA,UAAmC,EAAE,EACrC,aAA+C,EAAE,EACjD,YAC0B;AAC1B,QAAO;EACL,GAAG;EACH,GAAG;EACH,YAAY,QAAQ,cAAc,YAAY;EAC9C,aAAa,QAAQ,eAAe,YAAY;EAChD,qBACE,QAAQ,uBAAuB,YAAY;EAC7C,WAAW,QAAQ,aAAa,YAAY;EAC5C,SAAS,WAAW,YAAY;EAChC,cAAc,CAAC,EAAE,WAAW,YAAY;EACxC,YAAY;GAAE,GAAG;GAAgB,GAAG;GAAY;EACjD;;AAGH,MAAa,oBAA8D,EACzE,UACA,YACA,SACA,YACA,aACA,qBACA,WACA,gBAAgB,qBACZ;CACJ,MAAM,cAAyD;EAC7D;EACA;EACA;EACA,cAAc,CAAC,CAAC;EAChB;EACA;EACD;CAGD,MAAM,yBACJ,UACA,SACA,oBACA,oBACsB;AAQtB,SAAOA,0CAAgB,UAPD,aACpB,YACA,aACA,SACA,sBAAsB,EAAE,EACxB,gBACD,CAC8C;;CAKjD,MAAM,+BACJ,UACA,SACA,oBACA,oBAEA,4CAAC,gBAAgB,UAAjB;EAA0B,OAAO;YAC9B,iBAAiB,UAAU,SAAS,oBAAoB,gBAAgB;EAChD;AAG7B,QACE,4CAAC,gBAAgB,UAAjB;EACE,OAAO;GACL;GACA,gBAAgB,iBACZ,8BACA;GACL;EAEA;EACwB"}
|