preact-intlayer 8.1.2 → 8.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/IntlayerNode.cjs +1 -16
- package/dist/cjs/IntlayerNode.cjs.map +1 -1
- package/dist/cjs/UI/ContentSelector.cjs +1 -98
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -29
- package/dist/cjs/client/IntlayerProvider.cjs +1 -91
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/format/index.cjs +1 -18
- package/dist/cjs/client/format/useCompact.cjs +1 -29
- package/dist/cjs/client/format/useCompact.cjs.map +1 -1
- package/dist/cjs/client/format/useCurrency.cjs +1 -43
- package/dist/cjs/client/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/client/format/useDate.cjs +1 -45
- package/dist/cjs/client/format/useDate.cjs.map +1 -1
- package/dist/cjs/client/format/useIntl.cjs +1 -33
- package/dist/cjs/client/format/useIntl.cjs.map +1 -1
- package/dist/cjs/client/format/useList.cjs +1 -40
- package/dist/cjs/client/format/useList.cjs.map +1 -1
- package/dist/cjs/client/format/useNumber.cjs +1 -41
- package/dist/cjs/client/format/useNumber.cjs.map +1 -1
- package/dist/cjs/client/format/usePercentage.cjs +1 -37
- package/dist/cjs/client/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/client/format/useRelativeTime.cjs +1 -37
- package/dist/cjs/client/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/client/format/useUnit.cjs +1 -36
- package/dist/cjs/client/format/useUnit.cjs.map +1 -1
- package/dist/cjs/client/index.cjs +1 -32
- package/dist/cjs/client/t.cjs +1 -21
- package/dist/cjs/client/t.cjs.map +1 -1
- package/dist/cjs/client/useContent.cjs +1 -19
- package/dist/cjs/client/useContent.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +1 -27
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +1 -24
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +1 -23
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +1 -42
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLoadDynamic.cjs +1 -27
- package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +1 -56
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleBase.cjs +1 -26
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +1 -58
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.cjs +1 -35
- package/dist/cjs/client/useTraduction.cjs.map +1 -1
- package/dist/cjs/editor/CommunicatorContext.cjs +1 -39
- package/dist/cjs/editor/CommunicatorContext.cjs.map +1 -1
- package/dist/cjs/editor/ConfigurationContext.cjs +1 -26
- package/dist/cjs/editor/ConfigurationContext.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelectorWrapper.cjs +1 -58
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/editor/DictionariesRecordContext.cjs +1 -48
- package/dist/cjs/editor/DictionariesRecordContext.cjs.map +1 -1
- package/dist/cjs/editor/EditedContentContext.cjs +1 -163
- package/dist/cjs/editor/EditedContentContext.cjs.map +1 -1
- package/dist/cjs/editor/EditorEnabledContext.cjs +1 -34
- package/dist/cjs/editor/EditorEnabledContext.cjs.map +1 -1
- package/dist/cjs/editor/EditorProvider.cjs +1 -64
- package/dist/cjs/editor/EditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/FocusDictionaryContext.cjs +1 -54
- package/dist/cjs/editor/FocusDictionaryContext.cjs.map +1 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs +1 -63
- package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/index.cjs +1 -4
- package/dist/cjs/editor/useCrossFrameMessageListener.cjs +1 -78
- package/dist/cjs/editor/useCrossFrameMessageListener.cjs.map +1 -1
- package/dist/cjs/editor/useCrossFrameState.cjs +1 -108
- package/dist/cjs/editor/useCrossFrameState.cjs.map +1 -1
- package/dist/cjs/editor/useCrossURLPathState.cjs +1 -67
- package/dist/cjs/editor/useCrossURLPathState.cjs.map +1 -1
- package/dist/cjs/editor/useEditedContentRenderer.cjs +1 -29
- package/dist/cjs/editor/useEditedContentRenderer.cjs.map +1 -1
- package/dist/cjs/editor/useIframeClickInterceptor.cjs +1 -24
- package/dist/cjs/editor/useIframeClickInterceptor.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs +1 -19
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +1 -19
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/html/HTMLProvider.cjs +1 -19
- package/dist/cjs/html/HTMLProvider.cjs.map +1 -1
- package/dist/cjs/html/HTMLRenderer.cjs +1 -61
- package/dist/cjs/html/HTMLRenderer.cjs.map +1 -1
- package/dist/cjs/html/index.cjs +1 -10
- package/dist/cjs/index.cjs +1 -57
- package/dist/cjs/markdown/MarkdownProvider.cjs +1 -49
- package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +1 -77
- package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs +1 -31
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs.map +1 -1
- package/dist/cjs/markdown/compiler.cjs +1 -24
- package/dist/cjs/markdown/compiler.cjs.map +1 -1
- package/dist/cjs/markdown/index.cjs +1 -23
- package/dist/cjs/markdown/runtime.cjs +1 -18
- package/dist/cjs/markdown/runtime.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +1 -197
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/preactElement/renderPreactElement.cjs +1 -42
- package/dist/cjs/preactElement/renderPreactElement.cjs.map +1 -1
- package/dist/esm/IntlayerNode.mjs +1 -14
- package/dist/esm/IntlayerNode.mjs.map +1 -1
- package/dist/esm/UI/ContentSelector.mjs +1 -96
- package/dist/esm/UI/ContentSelector.mjs.map +1 -1
- package/dist/esm/client/IntlayerProvider.mjs +1 -85
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/format/index.mjs +1 -10
- package/dist/esm/client/format/useCompact.mjs +1 -27
- package/dist/esm/client/format/useCompact.mjs.map +1 -1
- package/dist/esm/client/format/useCurrency.mjs +1 -41
- package/dist/esm/client/format/useCurrency.mjs.map +1 -1
- package/dist/esm/client/format/useDate.mjs +1 -43
- package/dist/esm/client/format/useDate.mjs.map +1 -1
- package/dist/esm/client/format/useIntl.mjs +1 -31
- package/dist/esm/client/format/useIntl.mjs.map +1 -1
- package/dist/esm/client/format/useList.mjs +1 -38
- package/dist/esm/client/format/useList.mjs.map +1 -1
- package/dist/esm/client/format/useNumber.mjs +1 -39
- package/dist/esm/client/format/useNumber.mjs.map +1 -1
- package/dist/esm/client/format/usePercentage.mjs +1 -35
- package/dist/esm/client/format/usePercentage.mjs.map +1 -1
- package/dist/esm/client/format/useRelativeTime.mjs +1 -35
- package/dist/esm/client/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/client/format/useUnit.mjs +1 -34
- package/dist/esm/client/format/useUnit.mjs.map +1 -1
- package/dist/esm/client/index.mjs +1 -13
- package/dist/esm/client/t.mjs +1 -19
- package/dist/esm/client/t.mjs.map +1 -1
- package/dist/esm/client/useContent.mjs +1 -18
- package/dist/esm/client/useContent.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +1 -25
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +1 -21
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +1 -21
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +1 -40
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLoadDynamic.mjs +1 -25
- package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +1 -53
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.mjs +1 -23
- package/dist/esm/client/useLocaleBase.mjs.map +1 -1
- package/dist/esm/client/useLocaleStorage.mjs +1 -51
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
- package/dist/esm/client/useTraduction.mjs +1 -33
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/editor/CommunicatorContext.mjs +1 -35
- package/dist/esm/editor/CommunicatorContext.mjs.map +1 -1
- package/dist/esm/editor/ConfigurationContext.mjs +1 -22
- package/dist/esm/editor/ConfigurationContext.mjs.map +1 -1
- package/dist/esm/editor/ContentSelectorWrapper.mjs +1 -56
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/editor/DictionariesRecordContext.mjs +1 -44
- package/dist/esm/editor/DictionariesRecordContext.mjs.map +1 -1
- package/dist/esm/editor/EditedContentContext.mjs +1 -157
- package/dist/esm/editor/EditedContentContext.mjs.map +1 -1
- package/dist/esm/editor/EditorEnabledContext.mjs +1 -28
- package/dist/esm/editor/EditorEnabledContext.mjs.map +1 -1
- package/dist/esm/editor/EditorProvider.mjs +1 -62
- package/dist/esm/editor/EditorProvider.mjs.map +1 -1
- package/dist/esm/editor/FocusDictionaryContext.mjs +1 -50
- package/dist/esm/editor/FocusDictionaryContext.mjs.map +1 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs +1 -60
- package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
- package/dist/esm/editor/index.mjs +1 -3
- package/dist/esm/editor/useCrossFrameMessageListener.mjs +1 -76
- package/dist/esm/editor/useCrossFrameMessageListener.mjs.map +1 -1
- package/dist/esm/editor/useCrossFrameState.mjs +1 -106
- package/dist/esm/editor/useCrossFrameState.mjs.map +1 -1
- package/dist/esm/editor/useCrossURLPathState.mjs +1 -64
- package/dist/esm/editor/useCrossURLPathState.mjs.map +1 -1
- package/dist/esm/editor/useEditedContentRenderer.mjs +1 -26
- package/dist/esm/editor/useEditedContentRenderer.mjs.map +1 -1
- package/dist/esm/editor/useIframeClickInterceptor.mjs +1 -21
- package/dist/esm/editor/useIframeClickInterceptor.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs +1 -17
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs +1 -17
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/html/HTMLProvider.mjs +1 -16
- package/dist/esm/html/HTMLProvider.mjs.map +1 -1
- package/dist/esm/html/HTMLRenderer.mjs +1 -56
- package/dist/esm/html/HTMLRenderer.mjs.map +1 -1
- package/dist/esm/html/index.mjs +1 -4
- package/dist/esm/index.mjs +1 -22
- package/dist/esm/markdown/MarkdownProvider.mjs +1 -46
- package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRenderer.mjs +1 -73
- package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs +1 -28
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs.map +1 -1
- package/dist/esm/markdown/compiler.mjs +1 -17
- package/dist/esm/markdown/compiler.mjs.map +1 -1
- package/dist/esm/markdown/index.mjs +1 -7
- package/dist/esm/markdown/runtime.mjs +1 -15
- package/dist/esm/markdown/runtime.mjs.map +1 -1
- package/dist/esm/plugins.mjs +1 -190
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/preactElement/renderPreactElement.mjs +1 -40
- package/dist/esm/preactElement/renderPreactElement.mjs.map +1 -1
- package/dist/types/IntlayerNode.d.ts +1 -1
- package/dist/types/client/format/useDate.d.ts +1 -1
- package/dist/types/client/useDictionary.d.ts +2 -2
- package/dist/types/client/useDictionary.d.ts.map +1 -1
- package/dist/types/client/useDictionaryDynamic.d.ts +2 -2
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts +1 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
- package/dist/types/editor/EditedContentContext.d.ts.map +1 -1
- package/dist/types/getDictionary.d.ts +1 -1
- package/dist/types/getIntlayer.d.ts +1 -1
- package/dist/types/getIntlayer.d.ts.map +1 -1
- package/dist/types/html/HTMLRenderer.d.ts.map +1 -1
- package/dist/types/html/types.d.ts +1 -1
- package/dist/types/html/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/markdown/MarkdownRendererPlugin.d.ts.map +1 -1
- package/dist/types/markdown/compiler.d.ts +1 -1
- package/dist/types/markdown/runtime.d.ts +1 -1
- package/dist/types/plugins.d.ts +2 -2
- package/dist/types/plugins.d.ts.map +1 -1
- package/package.json +8 -8
|
@@ -1,27 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
6
|
-
let preact_hooks = require("preact/hooks");
|
|
7
|
-
let _intlayer_config_built = require("@intlayer/config/built");
|
|
8
|
-
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
9
|
-
|
|
10
|
-
//#region src/client/useLocaleBase.ts
|
|
11
|
-
const { defaultLocale, locales: availableLocales } = _intlayer_config_built.default.internationalization;
|
|
12
|
-
/**
|
|
13
|
-
* On the client side, hook to get the current locale and all related fields
|
|
14
|
-
*/
|
|
15
|
-
const useLocaleBase = () => {
|
|
16
|
-
const { locale, setLocale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
17
|
-
return {
|
|
18
|
-
locale,
|
|
19
|
-
defaultLocale,
|
|
20
|
-
availableLocales,
|
|
21
|
-
setLocale
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
|
-
exports.useLocaleBase = useLocaleBase;
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`./IntlayerProvider.cjs`);let n=require(`preact/hooks`),r=require(`@intlayer/config/built`);r=e.__toESM(r);const{defaultLocale:i,locales:a}=r.default.internationalization,o=()=>{let{locale:e,setLocale:r}=(0,n.useContext)(t.IntlayerClientContext);return{locale:e,defaultLocale:i,availableLocales:a,setLocale:r}};exports.useLocaleBase=o;
|
|
27
2
|
//# sourceMappingURL=useLocaleBase.cjs.map
|
|
@@ -1 +1 @@
|
|
|
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":"
|
|
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":"0PAMA,KAAM,CAAE,gBAAe,QAAS,GAC9BA,EAAAA,QAAc,qBAKH,MAAsB,CACjC,GAAM,CAAE,SAAQ,cAAA,EAAA,EAAA,YAAyBC,EAAAA,sBAAsB,CAE/D,MAAO,CACL,SACA,gBACA,mBACA,YACD"}
|
|
@@ -1,59 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
let _intlayer_core = require("@intlayer/core");
|
|
4
|
-
let preact_hooks = require("preact/hooks");
|
|
5
|
-
|
|
6
|
-
//#region src/client/useLocaleStorage.ts
|
|
7
|
-
/**
|
|
8
|
-
* Get the locale cookie
|
|
9
|
-
*/
|
|
10
|
-
const localeInStorage = (0, _intlayer_core.getLocaleFromStorage)(_intlayer_core.localeStorageOptions);
|
|
11
|
-
/**
|
|
12
|
-
* @deprecated Use localeInStorage instead
|
|
13
|
-
*
|
|
14
|
-
* Get the locale cookie
|
|
15
|
-
*/
|
|
16
|
-
const localeCookie = localeInStorage;
|
|
17
|
-
/**
|
|
18
|
-
* Set the locale cookie
|
|
19
|
-
*/
|
|
20
|
-
const setLocaleInStorage = (locale, isCookieEnabled) => (0, _intlayer_core.setLocaleInStorage)(locale, {
|
|
21
|
-
..._intlayer_core.localeStorageOptions,
|
|
22
|
-
isCookieEnabled
|
|
23
|
-
});
|
|
24
|
-
/**
|
|
25
|
-
* @deprecated Use setLocaleInStorage instead
|
|
26
|
-
*
|
|
27
|
-
* Set the locale cookie
|
|
28
|
-
*/
|
|
29
|
-
const setLocaleCookie = setLocaleInStorage;
|
|
30
|
-
/**
|
|
31
|
-
* Hook that provides the locale storage and a function to set it
|
|
32
|
-
*/
|
|
33
|
-
const useLocaleStorage = (isCookieEnabled) => (0, preact_hooks.useMemo)(() => (0, _intlayer_core.LocaleStorage)({
|
|
34
|
-
..._intlayer_core.localeStorageOptions,
|
|
35
|
-
isCookieEnabled
|
|
36
|
-
}), [isCookieEnabled]);
|
|
37
|
-
/**
|
|
38
|
-
* @deprecated Use useLocaleStorage instead
|
|
39
|
-
*
|
|
40
|
-
* For GDPR compliance, use useLocaleStorage instead
|
|
41
|
-
*
|
|
42
|
-
* Hook that provides the locale cookie and a function to set it
|
|
43
|
-
*/
|
|
44
|
-
const useLocaleCookie = (isCookieEnabled) => {
|
|
45
|
-
const storage = useLocaleStorage(isCookieEnabled);
|
|
46
|
-
return {
|
|
47
|
-
localeCookie: storage.getLocale(),
|
|
48
|
-
setLocaleCookie: storage.setLocale
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
//#endregion
|
|
53
|
-
exports.localeCookie = localeCookie;
|
|
54
|
-
exports.localeInStorage = localeInStorage;
|
|
55
|
-
exports.setLocaleCookie = setLocaleCookie;
|
|
56
|
-
exports.setLocaleInStorage = setLocaleInStorage;
|
|
57
|
-
exports.useLocaleCookie = useLocaleCookie;
|
|
58
|
-
exports.useLocaleStorage = useLocaleStorage;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`@intlayer/core/utils`),t=require(`preact/hooks`),n=require(`@intlayer/core/localization`);const r=(0,e.getLocaleFromStorage)(n.localeStorageOptions),i=r,a=(t,r)=>(0,e.setLocaleInStorage)(t,{...n.localeStorageOptions,isCookieEnabled:r}),o=a,s=r=>(0,t.useMemo)(()=>(0,e.LocaleStorage)({...n.localeStorageOptions,isCookieEnabled:r}),[r]),c=e=>{let t=s(e);return{localeCookie:t.getLocale(),setLocaleCookie:t.setLocale}};exports.localeCookie=i,exports.localeInStorage=r,exports.setLocaleCookie=o,exports.setLocaleInStorage=a,exports.useLocaleCookie=c,exports.useLocaleStorage=s;
|
|
59
2
|
//# sourceMappingURL=useLocaleStorage.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleStorage.cjs","names":["localeStorageOptions"],"sources":["../../../src/client/useLocaleStorage.ts"],"sourcesContent":["import {\n getLocaleFromStorage,\n LocaleStorage,\n
|
|
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';\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":"yNAYA,MAAa,GAAA,EAAA,EAAA,sBAAuCA,EAAAA,qBAAqB,CAM5D,EAAe,EAKf,GACX,EACA,KAAA,EAAA,EAAA,oBAEuB,EAAQ,CAC7B,GAAGA,EAAAA,qBACH,kBACD,CAAC,CAOS,EAAkB,EAKlB,EAAoB,IAAA,EAAA,EAAA,cAAA,EAAA,EAAA,eAGb,CACZ,GAAGA,EAAAA,qBACH,kBACD,CAAC,CACJ,CAAC,EAAgB,CAClB,CASU,EAAmB,GAA8B,CAC5D,IAAM,EAAU,EAAiB,EAAgB,CACjD,MAAO,CACL,aAAc,EAAQ,WAAW,CACjC,gBAAiB,EAAQ,UAC1B"}
|
|
@@ -1,36 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
4
|
-
let _intlayer_core = require("@intlayer/core");
|
|
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.getTranslation)(languageContent, locale), [languageContent, locale]);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
//#endregion
|
|
35
|
-
exports.useTranslation = useTranslation;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./IntlayerProvider.cjs`);let t=require(`@intlayer/core/interpreter`),n=require(`preact/hooks`);const r=r=>{let{locale:i}=(0,n.useContext)(e.IntlayerClientContext);return(0,n.useMemo)(()=>(0,t.getTranslation)(r,i),[r,i])};exports.useTranslation=r;
|
|
36
2
|
//# 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';\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":"
|
|
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';\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":"gOA0BA,MAAa,EACX,GACY,CACZ,GAAM,CAAE,WAAA,EAAA,EAAA,YAAsBA,EAAAA,sBAAsB,CAEpD,OAAA,EAAA,EAAA,cAAA,EAAA,EAAA,gBACuB,EAAiB,EAAO,CAC7C,CAAC,EAAiB,EAAO,CAC1B"}
|
|
@@ -1,40 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
let preact = require("preact");
|
|
6
|
-
let preact_hooks = require("preact/hooks");
|
|
7
|
-
let _intlayer_config_built = require("@intlayer/config/built");
|
|
8
|
-
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
9
|
-
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
10
|
-
|
|
11
|
-
//#region src/editor/CommunicatorContext.tsx
|
|
12
|
-
const randomUUID = () => Math.random().toString(36).slice(2);
|
|
13
|
-
const { editor } = _intlayer_config_built.default;
|
|
14
|
-
const CommunicatorContext = (0, preact.createContext)({
|
|
15
|
-
postMessage: () => null,
|
|
16
|
-
allowedOrigins: [
|
|
17
|
-
editor?.applicationURL,
|
|
18
|
-
editor?.editorURL,
|
|
19
|
-
editor?.cmsURL
|
|
20
|
-
],
|
|
21
|
-
senderId: ""
|
|
22
|
-
});
|
|
23
|
-
const CommunicatorProvider = ({ children, allowedOrigins, postMessage }) => {
|
|
24
|
-
const senderIdRef = (0, preact_hooks.useRef)(randomUUID());
|
|
25
|
-
const value = (0, preact_hooks.useMemo)(() => ({
|
|
26
|
-
postMessage,
|
|
27
|
-
allowedOrigins,
|
|
28
|
-
senderId: senderIdRef.current
|
|
29
|
-
}), [postMessage, allowedOrigins]);
|
|
30
|
-
return /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(CommunicatorContext.Provider, {
|
|
31
|
-
value,
|
|
32
|
-
children
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
const useCommunicator = () => (0, preact_hooks.useContext)(CommunicatorContext);
|
|
36
|
-
|
|
37
|
-
//#endregion
|
|
38
|
-
exports.CommunicatorProvider = CommunicatorProvider;
|
|
39
|
-
exports.useCommunicator = useCommunicator;
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`);let t=require(`preact`),n=require(`preact/hooks`),r=require(`@intlayer/config/built`);r=e.__toESM(r);let i=require(`preact/jsx-runtime`);const a=()=>Math.random().toString(36).slice(2),{editor:o}=r.default,s=(0,t.createContext)({postMessage:()=>null,allowedOrigins:[o?.applicationURL,o?.editorURL,o?.cmsURL],senderId:``}),c=({children:e,allowedOrigins:t,postMessage:r})=>{let o=(0,n.useRef)(a()),c=(0,n.useMemo)(()=>({postMessage:r,allowedOrigins:t,senderId:o.current}),[r,t]);return(0,i.jsx)(s.Provider,{value:c,children:e})},l=()=>(0,n.useContext)(s);exports.CommunicatorProvider=c,exports.useCommunicator=l;
|
|
40
2
|
//# sourceMappingURL=CommunicatorContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommunicatorContext.cjs","names":["configuration"],"sources":["../../../src/editor/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport {\n type ComponentChildren,\n createContext,\n type FunctionComponent,\n} from 'preact';\nimport { useContext, useMemo, useRef } from 'preact/hooks';\n\nconst randomUUID = () => Math.random().toString(36).slice(2);\n\nexport type UseCrossPlatformStateProps = {\n postMessage: typeof window.postMessage;\n allowedOrigins?: string[];\n senderId: string;\n};\n\nconst { editor } = configuration;\n\nconst CommunicatorContext = createContext<UseCrossPlatformStateProps>({\n postMessage: () => null,\n allowedOrigins: [\n editor?.applicationURL,\n editor?.editorURL,\n editor?.cmsURL,\n ] as string[],\n senderId: '',\n});\n\nexport type CommunicatorProviderProps = {\n children?: ComponentChildren;\n postMessage: typeof window.postMessage;\n allowedOrigins?: string[];\n};\n\nexport const CommunicatorProvider: FunctionComponent<\n CommunicatorProviderProps\n> = ({ children, allowedOrigins, postMessage }) => {\n // Create a stable, unique ID for the lifetime of this app/iframe instance.\n const senderIdRef = useRef(randomUUID());\n\n const value = useMemo(\n () => ({ postMessage, allowedOrigins, senderId: senderIdRef.current }),\n [postMessage, allowedOrigins] // senderIdRef.current is stable\n );\n\n return (\n <CommunicatorContext.Provider value={value}>\n {children}\n </CommunicatorContext.Provider>\n );\n};\n\nexport const useCommunicator = () => useContext(CommunicatorContext);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"CommunicatorContext.cjs","names":["configuration"],"sources":["../../../src/editor/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport {\n type ComponentChildren,\n createContext,\n type FunctionComponent,\n} from 'preact';\nimport { useContext, useMemo, useRef } from 'preact/hooks';\n\nconst randomUUID = () => Math.random().toString(36).slice(2);\n\nexport type UseCrossPlatformStateProps = {\n postMessage: typeof window.postMessage;\n allowedOrigins?: string[];\n senderId: string;\n};\n\nconst { editor } = configuration;\n\nconst CommunicatorContext = createContext<UseCrossPlatformStateProps>({\n postMessage: () => null,\n allowedOrigins: [\n editor?.applicationURL,\n editor?.editorURL,\n editor?.cmsURL,\n ] as string[],\n senderId: '',\n});\n\nexport type CommunicatorProviderProps = {\n children?: ComponentChildren;\n postMessage: typeof window.postMessage;\n allowedOrigins?: string[];\n};\n\nexport const CommunicatorProvider: FunctionComponent<\n CommunicatorProviderProps\n> = ({ children, allowedOrigins, postMessage }) => {\n // Create a stable, unique ID for the lifetime of this app/iframe instance.\n const senderIdRef = useRef(randomUUID());\n\n const value = useMemo(\n () => ({ postMessage, allowedOrigins, senderId: senderIdRef.current }),\n [postMessage, allowedOrigins] // senderIdRef.current is stable\n );\n\n return (\n <CommunicatorContext.Provider value={value}>\n {children}\n </CommunicatorContext.Provider>\n );\n};\n\nexport const useCommunicator = () => useContext(CommunicatorContext);\n"],"mappings":"8QAUA,MAAM,MAAmB,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,MAAM,EAAE,CAQtD,CAAE,UAAWA,EAAAA,QAEb,GAAA,EAAA,EAAA,eAAgE,CACpE,gBAAmB,KACnB,eAAgB,CACd,GAAQ,eACR,GAAQ,UACR,GAAQ,OACT,CACD,SAAU,GACX,CAAC,CAQW,GAER,CAAE,WAAU,iBAAgB,iBAAkB,CAEjD,IAAM,GAAA,EAAA,EAAA,QAAqB,GAAY,CAAC,CAElC,GAAA,EAAA,EAAA,cACG,CAAE,cAAa,iBAAgB,SAAU,EAAY,QAAS,EACrE,CAAC,EAAa,EAAe,CAC9B,CAED,OACE,EAAA,EAAA,KAAC,EAAoB,SAAA,CAAgB,QAClC,YAC4B,EAItB,OAAA,EAAA,EAAA,YAAmC,EAAoB"}
|
|
@@ -1,27 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_editor_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
6
|
-
let preact = require("preact");
|
|
7
|
-
let _intlayer_editor = require("@intlayer/editor");
|
|
8
|
-
let preact_hooks = require("preact/hooks");
|
|
9
|
-
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
10
|
-
|
|
11
|
-
//#region src/editor/ConfigurationContext.tsx
|
|
12
|
-
const ConfigurationStatesContext = (0, preact.createContext)(void 0);
|
|
13
|
-
const useConfigurationState = () => require_editor_useCrossFrameState.useCrossFrameState(_intlayer_editor.MessageKey.INTLAYER_CONFIGURATION, void 0, {
|
|
14
|
-
receive: false,
|
|
15
|
-
emit: true
|
|
16
|
-
});
|
|
17
|
-
const ConfigurationProvider = ({ children, configuration }) => /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(ConfigurationStatesContext.Provider, {
|
|
18
|
-
value: configuration,
|
|
19
|
-
children
|
|
20
|
-
});
|
|
21
|
-
const useConfiguration = () => (0, preact_hooks.useContext)(ConfigurationStatesContext);
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
exports.ConfigurationProvider = ConfigurationProvider;
|
|
25
|
-
exports.useConfiguration = useConfiguration;
|
|
26
|
-
exports.useConfigurationState = useConfigurationState;
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./useCrossFrameState.cjs`);let t=require(`preact`),n=require(`@intlayer/editor`),r=require(`preact/hooks`),i=require(`preact/jsx-runtime`);const a=(0,t.createContext)(void 0),o=()=>e.useCrossFrameState(n.MessageKey.INTLAYER_CONFIGURATION,void 0,{receive:!1,emit:!0}),s=({children:e,configuration:t})=>(0,i.jsx)(a.Provider,{value:t,children:e}),c=()=>(0,r.useContext)(a);exports.ConfigurationProvider=s,exports.useConfiguration=c,exports.useConfigurationState=o;
|
|
27
2
|
//# sourceMappingURL=ConfigurationContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigurationContext.cjs","names":["useCrossFrameState","MessageKey"],"sources":["../../../src/editor/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport {\n createContext,\n type FunctionalComponent,\n type RenderableProps,\n} from 'preact';\nimport { useContext } from 'preact/hooks';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nconst ConfigurationStatesContext = createContext<IntlayerConfig | undefined>(\n undefined\n);\n\nexport const useConfigurationState = () =>\n useCrossFrameState<IntlayerConfig>(\n MessageKey.INTLAYER_CONFIGURATION,\n undefined,\n {\n receive: false,\n emit: true,\n }\n );\n\nexport type ConfigurationProviderProps = {\n configuration?: IntlayerConfig;\n};\n\nexport const ConfigurationProvider: FunctionalComponent<\n RenderableProps<ConfigurationProviderProps>\n> = ({ children, configuration }) => (\n <ConfigurationStatesContext.Provider value={configuration}>\n {children}\n </ConfigurationStatesContext.Provider>\n);\n\nexport const useConfiguration = () => useContext(ConfigurationStatesContext);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ConfigurationContext.cjs","names":["useCrossFrameState","MessageKey"],"sources":["../../../src/editor/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport {\n createContext,\n type FunctionalComponent,\n type RenderableProps,\n} from 'preact';\nimport { useContext } from 'preact/hooks';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nconst ConfigurationStatesContext = createContext<IntlayerConfig | undefined>(\n undefined\n);\n\nexport const useConfigurationState = () =>\n useCrossFrameState<IntlayerConfig>(\n MessageKey.INTLAYER_CONFIGURATION,\n undefined,\n {\n receive: false,\n emit: true,\n }\n );\n\nexport type ConfigurationProviderProps = {\n configuration?: IntlayerConfig;\n};\n\nexport const ConfigurationProvider: FunctionalComponent<\n RenderableProps<ConfigurationProviderProps>\n> = ({ children, configuration }) => (\n <ConfigurationStatesContext.Provider value={configuration}>\n {children}\n </ConfigurationStatesContext.Provider>\n);\n\nexport const useConfiguration = () => useContext(ConfigurationStatesContext);\n"],"mappings":"yRAYA,MAAM,GAAA,EAAA,EAAA,eACJ,IAAA,GACD,CAEY,MACXA,EAAAA,mBACEC,EAAAA,WAAW,uBACX,IAAA,GACA,CACE,QAAS,GACT,KAAM,GACP,CACF,CAMU,GAER,CAAE,WAAU,oBACf,EAAA,EAAA,KAAC,EAA2B,SAAA,CAAS,MAAO,EACzC,YACmC,CAG3B,OAAA,EAAA,EAAA,YAAoC,EAA2B"}
|
|
@@ -1,59 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_editor_CommunicatorContext = require('./CommunicatorContext.cjs');
|
|
6
|
-
const require_editor_EditorEnabledContext = require('./EditorEnabledContext.cjs');
|
|
7
|
-
const require_editor_FocusDictionaryContext = require('./FocusDictionaryContext.cjs');
|
|
8
|
-
const require_client_IntlayerProvider = require('../client/IntlayerProvider.cjs');
|
|
9
|
-
const require_UI_ContentSelector = require('../UI/ContentSelector.cjs');
|
|
10
|
-
let _intlayer_core = require("@intlayer/core");
|
|
11
|
-
let _intlayer_types = require("@intlayer/types");
|
|
12
|
-
let _intlayer_editor = require("@intlayer/editor");
|
|
13
|
-
let preact_hooks = require("preact/hooks");
|
|
14
|
-
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
15
|
-
|
|
16
|
-
//#region src/editor/ContentSelectorWrapper.tsx
|
|
17
|
-
const ContentSelectorWrapperContent = ({ children, dictionaryKey, keyPath }) => {
|
|
18
|
-
const { focusedContent, setFocusedContent } = require_editor_FocusDictionaryContext.useFocusDictionary();
|
|
19
|
-
const { postMessage, senderId } = require_editor_CommunicatorContext.useCommunicator();
|
|
20
|
-
const filteredKeyPath = (0, preact_hooks.useMemo)(() => keyPath.filter((key) => key.type !== _intlayer_types.NodeType.Translation), [keyPath]);
|
|
21
|
-
return /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(require_UI_ContentSelector.ContentSelector, {
|
|
22
|
-
onPress: (0, preact_hooks.useCallback)(() => setFocusedContent({
|
|
23
|
-
dictionaryKey,
|
|
24
|
-
keyPath: filteredKeyPath
|
|
25
|
-
}), [dictionaryKey, filteredKeyPath]),
|
|
26
|
-
onHover: (0, preact_hooks.useCallback)(() => postMessage({
|
|
27
|
-
type: `${_intlayer_editor.MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,
|
|
28
|
-
data: {
|
|
29
|
-
dictionaryKey,
|
|
30
|
-
keyPath: filteredKeyPath
|
|
31
|
-
},
|
|
32
|
-
senderId
|
|
33
|
-
}), [dictionaryKey, filteredKeyPath]),
|
|
34
|
-
onUnhover: (0, preact_hooks.useCallback)(() => postMessage({
|
|
35
|
-
type: `${_intlayer_editor.MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,
|
|
36
|
-
data: null,
|
|
37
|
-
senderId
|
|
38
|
-
}), [senderId]),
|
|
39
|
-
isSelecting: (0, preact_hooks.useMemo)(() => (focusedContent?.dictionaryKey === dictionaryKey && (focusedContent?.keyPath?.length ?? 0) > 0 && (0, _intlayer_core.isSameKeyPath)(focusedContent?.keyPath ?? [], filteredKeyPath)) ?? false, [
|
|
40
|
-
focusedContent,
|
|
41
|
-
filteredKeyPath,
|
|
42
|
-
dictionaryKey
|
|
43
|
-
]),
|
|
44
|
-
children
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
const ContentSelectorRenderer = ({ children, ...props }) => {
|
|
48
|
-
const { enabled } = require_editor_EditorEnabledContext.useEditorEnabled();
|
|
49
|
-
const { disableEditor } = require_client_IntlayerProvider.useIntlayerContext();
|
|
50
|
-
if (enabled && !disableEditor) return /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(ContentSelectorWrapperContent, {
|
|
51
|
-
...props,
|
|
52
|
-
children
|
|
53
|
-
});
|
|
54
|
-
return children;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
//#endregion
|
|
58
|
-
exports.ContentSelectorRenderer = ContentSelectorRenderer;
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./CommunicatorContext.cjs`),t=require(`./EditorEnabledContext.cjs`),n=require(`./FocusDictionaryContext.cjs`),r=require(`../client/IntlayerProvider.cjs`),i=require(`../UI/ContentSelector.cjs`);let a=require(`@intlayer/types`),o=require(`@intlayer/core/utils`),s=require(`@intlayer/editor`),c=require(`preact/hooks`),l=require(`preact/jsx-runtime`);const u=({children:t,dictionaryKey:r,keyPath:u})=>{let{focusedContent:d,setFocusedContent:f}=n.useFocusDictionary(),{postMessage:p,senderId:m}=e.useCommunicator(),h=(0,c.useMemo)(()=>u.filter(e=>e.type!==a.NodeType.Translation),[u]);return(0,l.jsx)(i.ContentSelector,{onPress:(0,c.useCallback)(()=>f({dictionaryKey:r,keyPath:h}),[r,h]),onHover:(0,c.useCallback)(()=>p({type:`${s.MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,data:{dictionaryKey:r,keyPath:h},senderId:m}),[r,h]),onUnhover:(0,c.useCallback)(()=>p({type:`${s.MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,data:null,senderId:m}),[m]),isSelecting:(0,c.useMemo)(()=>(d?.dictionaryKey===r&&(d?.keyPath?.length??0)>0&&(0,o.isSameKeyPath)(d?.keyPath??[],h))??!1,[d,h,r]),children:t})},d=({children:e,...n})=>{let{enabled:i}=t.useEditorEnabled(),{disableEditor:a}=r.useIntlayerContext();return i&&!a?(0,l.jsx)(u,{...n,children:e}):e};exports.ContentSelectorRenderer=d;
|
|
59
2
|
//# sourceMappingURL=ContentSelectorWrapper.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSelectorWrapper.cjs","names":["useFocusDictionary","useCommunicator","NodeType","ContentSelector","MessageKey","useEditorEnabled","useIntlayerContext"],"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"file":"ContentSelectorWrapper.cjs","names":["useFocusDictionary","useCommunicator","NodeType","ContentSelector","MessageKey","useEditorEnabled","useIntlayerContext"],"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport type { NodeProps } from '@intlayer/core/interpreter';\nimport { isSameKeyPath } from '@intlayer/core/utils';\nimport { MessageKey } from '@intlayer/editor';\nimport { NodeType } from '@intlayer/types';\nimport type { FunctionalComponent, JSX } from 'preact';\nimport { useCallback, useMemo } from 'preact/hooks';\nimport { useIntlayerContext } from '../client';\nimport { ContentSelector } from '../UI/ContentSelector';\nimport { useCommunicator } from './CommunicatorContext';\nimport { useEditorEnabled } from './EditorEnabledContext';\nimport { useFocusDictionary } from './FocusDictionaryContext';\n\nexport type ContentSelectorWrapperProps = NodeProps &\n Omit<JSX.HTMLAttributes<HTMLDivElement>, 'children'>;\n\nconst ContentSelectorWrapperContent: FunctionalComponent<\n ContentSelectorWrapperProps\n> = ({ children, dictionaryKey, keyPath }) => {\n const { focusedContent, setFocusedContent } = useFocusDictionary();\n const { postMessage, senderId } = useCommunicator();\n\n // Filter out translation nodes for more flexibility with the editor that can have different format\n const filteredKeyPath = useMemo(\n () => keyPath.filter((key) => key.type !== NodeType.Translation),\n [keyPath]\n );\n\n const handleSelect = useCallback(\n () =>\n setFocusedContent({\n dictionaryKey,\n keyPath: filteredKeyPath,\n }),\n [dictionaryKey, filteredKeyPath]\n );\n\n const handleHover = useCallback(\n () =>\n postMessage({\n type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n data: {\n dictionaryKey,\n keyPath: filteredKeyPath,\n },\n senderId,\n }),\n [dictionaryKey, filteredKeyPath]\n );\n\n const handleUnhover = useCallback(\n () =>\n postMessage({\n type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n data: null,\n senderId,\n }),\n [senderId]\n );\n\n const isSelected = useMemo(\n () =>\n (focusedContent?.dictionaryKey === dictionaryKey &&\n (focusedContent?.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent?.keyPath ?? [], filteredKeyPath)) ??\n false,\n [focusedContent, filteredKeyPath, dictionaryKey]\n );\n\n return (\n <ContentSelector\n onPress={handleSelect}\n onHover={handleHover}\n onUnhover={handleUnhover}\n isSelecting={isSelected}\n >\n {children}\n </ContentSelector>\n );\n};\n\nexport const ContentSelectorRenderer: FunctionalComponent<\n ContentSelectorWrapperProps\n> = ({ children, ...props }) => {\n const { enabled } = useEditorEnabled();\n const { disableEditor } = useIntlayerContext();\n\n if (enabled && !disableEditor) {\n return (\n <ContentSelectorWrapperContent {...props}>\n {children}\n </ContentSelectorWrapperContent>\n );\n }\n\n return children;\n};\n"],"mappings":"0eAiBA,MAAM,GAED,CAAE,WAAU,gBAAe,aAAc,CAC5C,GAAM,CAAE,iBAAgB,qBAAsBA,EAAAA,oBAAoB,CAC5D,CAAE,cAAa,YAAaC,EAAAA,iBAAiB,CAG7C,GAAA,EAAA,EAAA,aACE,EAAQ,OAAQ,GAAQ,EAAI,OAASC,EAAAA,SAAS,YAAY,CAChE,CAAC,EAAQ,CACV,CA2CD,OACE,EAAA,EAAA,KAACC,EAAAA,gBAAAA,CACC,SAAA,EAAA,EAAA,iBAzCA,EAAkB,CAChB,gBACA,QAAS,EACV,CAAC,CACJ,CAAC,EAAe,EAAgB,CACjC,CAqCG,SAAA,EAAA,EAAA,iBAjCA,EAAY,CACV,KAAM,GAAGC,EAAAA,WAAW,iCAAiC,OACrD,KAAM,CACJ,gBACA,QAAS,EACV,CACD,WACD,CAAC,CACJ,CAAC,EAAe,EAAgB,CACjC,CAyBG,WAAA,EAAA,EAAA,iBArBA,EAAY,CACV,KAAM,GAAGA,EAAAA,WAAW,iCAAiC,OACrD,KAAM,KACN,WACD,CAAC,CACJ,CAAC,EAAS,CACX,CAgBG,aAAA,EAAA,EAAA,cAZC,GAAgB,gBAAkB,IAChC,GAAgB,SAAS,QAAU,GAAK,IAAA,EAAA,EAAA,eAC3B,GAAgB,SAAW,EAAE,CAAE,EAAgB,GAC/D,GACF,CAAC,EAAgB,EAAiB,EAAc,CACjD,CASI,YACe,EAIT,GAER,CAAE,WAAU,GAAG,KAAY,CAC9B,GAAM,CAAE,WAAYC,EAAAA,kBAAkB,CAChC,CAAE,iBAAkBC,EAAAA,oBAAoB,CAU9C,OARI,GAAW,CAAC,GAEZ,EAAA,EAAA,KAAC,EAAA,CAA8B,GAAI,EAChC,YAC6B,CAI7B"}
|
|
@@ -1,49 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_editor_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
6
|
-
let preact = require("preact");
|
|
7
|
-
let _intlayer_editor = require("@intlayer/editor");
|
|
8
|
-
let preact_hooks = require("preact/hooks");
|
|
9
|
-
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
10
|
-
|
|
11
|
-
//#region src/editor/DictionariesRecordContext.tsx
|
|
12
|
-
const DictionariesRecordStatesContext = (0, preact.createContext)(void 0);
|
|
13
|
-
const DictionariesRecordActionsContext = (0, preact.createContext)(void 0);
|
|
14
|
-
const DictionariesRecordProvider = ({ children }) => {
|
|
15
|
-
const [localeDictionaries, setLocaleDictionaries] = require_editor_useCrossFrameState.useCrossFrameState(_intlayer_editor.MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED, void 0);
|
|
16
|
-
const stateValue = (0, preact_hooks.useMemo)(() => ({ localeDictionaries: localeDictionaries ?? {} }), [localeDictionaries]);
|
|
17
|
-
const actionValue = (0, preact_hooks.useMemo)(() => ({
|
|
18
|
-
setLocaleDictionaries,
|
|
19
|
-
setLocaleDictionary: (dictionary) => {
|
|
20
|
-
setLocaleDictionaries((dictionaries) => ({
|
|
21
|
-
...dictionaries,
|
|
22
|
-
[String(dictionary.localId)]: dictionary
|
|
23
|
-
}));
|
|
24
|
-
}
|
|
25
|
-
}), [setLocaleDictionaries]);
|
|
26
|
-
return /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(DictionariesRecordStatesContext.Provider, {
|
|
27
|
-
value: stateValue,
|
|
28
|
-
children: /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(DictionariesRecordActionsContext.Provider, {
|
|
29
|
-
value: actionValue,
|
|
30
|
-
children
|
|
31
|
-
})
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
const useDictionariesRecordActions = () => (0, preact_hooks.useContext)(DictionariesRecordActionsContext);
|
|
35
|
-
const useDictionariesRecord = () => {
|
|
36
|
-
const actionsContext = useDictionariesRecordActions();
|
|
37
|
-
const statesContext = (0, preact_hooks.useContext)(DictionariesRecordStatesContext);
|
|
38
|
-
if (!statesContext) throw new Error("useDictionariesRecordStates must be used within a DictionariesRecordProvider");
|
|
39
|
-
return {
|
|
40
|
-
...statesContext,
|
|
41
|
-
...actionsContext
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
//#endregion
|
|
46
|
-
exports.DictionariesRecordProvider = DictionariesRecordProvider;
|
|
47
|
-
exports.useDictionariesRecord = useDictionariesRecord;
|
|
48
|
-
exports.useDictionariesRecordActions = useDictionariesRecordActions;
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./useCrossFrameState.cjs`);let t=require(`preact`),n=require(`@intlayer/editor`),r=require(`preact/hooks`),i=require(`preact/jsx-runtime`);const a=(0,t.createContext)(void 0),o=(0,t.createContext)(void 0),s=({children:t})=>{let[s,c]=e.useCrossFrameState(n.MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED,void 0),l=(0,r.useMemo)(()=>({localeDictionaries:s??{}}),[s]),u=(0,r.useMemo)(()=>({setLocaleDictionaries:c,setLocaleDictionary:e=>{c(t=>({...t,[String(e.localId)]:e}))}}),[c]);return(0,i.jsx)(a.Provider,{value:l,children:(0,i.jsx)(o.Provider,{value:u,children:t})})},c=()=>(0,r.useContext)(o),l=()=>{let e=c(),t=(0,r.useContext)(a);if(!t)throw Error(`useDictionariesRecordStates must be used within a DictionariesRecordProvider`);return{...t,...e}};exports.DictionariesRecordProvider=s,exports.useDictionariesRecord=l,exports.useDictionariesRecordActions=c;
|
|
49
2
|
//# sourceMappingURL=DictionariesRecordContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DictionariesRecordContext.cjs","names":["useCrossFrameState","MessageKey"],"sources":["../../../src/editor/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { Dictionary } from '@intlayer/types';\nimport {\n createContext,\n type FunctionalComponent,\n type RenderableProps,\n} from 'preact';\nimport { useContext, useMemo } from 'preact/hooks';\nimport {\n type CrossFrameStateUpdater,\n useCrossFrameState,\n} from './useCrossFrameState';\n\nexport type DictionaryContent = Record<Dictionary['key'], Dictionary>;\n\ntype DictionariesRecordStatesContextType = {\n localeDictionaries: DictionaryContent;\n};\ntype DictionariesRecordActionsContextType = {\n setLocaleDictionaries: CrossFrameStateUpdater<DictionaryContent>;\n setLocaleDictionary: (dictionary: Dictionary) => void;\n};\n\nconst DictionariesRecordStatesContext = createContext<\n DictionariesRecordStatesContextType | undefined\n>(undefined);\nconst DictionariesRecordActionsContext = createContext<\n DictionariesRecordActionsContextType | undefined\n>(undefined);\n\nexport const DictionariesRecordProvider: FunctionalComponent<\n RenderableProps<{}>\n> = ({ children }) => {\n const [localeDictionaries, setLocaleDictionaries] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED,\n undefined\n );\n\n const stateValue = useMemo(\n () => ({\n localeDictionaries: localeDictionaries ?? {},\n }),\n [localeDictionaries]\n );\n\n const actionValue = useMemo(\n () => ({\n setLocaleDictionaries,\n setLocaleDictionary: (dictionary: Dictionary) => {\n setLocaleDictionaries((dictionaries) => ({\n ...dictionaries,\n [String(dictionary.localId)]: dictionary,\n }));\n },\n }),\n [setLocaleDictionaries]\n );\n\n return (\n <DictionariesRecordStatesContext.Provider value={stateValue}>\n <DictionariesRecordActionsContext.Provider value={actionValue}>\n {children}\n </DictionariesRecordActionsContext.Provider>\n </DictionariesRecordStatesContext.Provider>\n );\n};\n\nexport const useDictionariesRecordActions = () =>\n useContext(DictionariesRecordActionsContext);\n\nexport const useDictionariesRecord = () => {\n const actionsContext = useDictionariesRecordActions();\n const statesContext = useContext(DictionariesRecordStatesContext);\n\n if (!statesContext) {\n throw new Error(\n 'useDictionariesRecordStates must be used within a DictionariesRecordProvider'\n );\n }\n\n return { ...statesContext, ...actionsContext };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"DictionariesRecordContext.cjs","names":["useCrossFrameState","MessageKey"],"sources":["../../../src/editor/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { Dictionary } from '@intlayer/types';\nimport {\n createContext,\n type FunctionalComponent,\n type RenderableProps,\n} from 'preact';\nimport { useContext, useMemo } from 'preact/hooks';\nimport {\n type CrossFrameStateUpdater,\n useCrossFrameState,\n} from './useCrossFrameState';\n\nexport type DictionaryContent = Record<Dictionary['key'], Dictionary>;\n\ntype DictionariesRecordStatesContextType = {\n localeDictionaries: DictionaryContent;\n};\ntype DictionariesRecordActionsContextType = {\n setLocaleDictionaries: CrossFrameStateUpdater<DictionaryContent>;\n setLocaleDictionary: (dictionary: Dictionary) => void;\n};\n\nconst DictionariesRecordStatesContext = createContext<\n DictionariesRecordStatesContextType | undefined\n>(undefined);\nconst DictionariesRecordActionsContext = createContext<\n DictionariesRecordActionsContextType | undefined\n>(undefined);\n\nexport const DictionariesRecordProvider: FunctionalComponent<\n RenderableProps<{}>\n> = ({ children }) => {\n const [localeDictionaries, setLocaleDictionaries] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED,\n undefined\n );\n\n const stateValue = useMemo(\n () => ({\n localeDictionaries: localeDictionaries ?? {},\n }),\n [localeDictionaries]\n );\n\n const actionValue = useMemo(\n () => ({\n setLocaleDictionaries,\n setLocaleDictionary: (dictionary: Dictionary) => {\n setLocaleDictionaries((dictionaries) => ({\n ...dictionaries,\n [String(dictionary.localId)]: dictionary,\n }));\n },\n }),\n [setLocaleDictionaries]\n );\n\n return (\n <DictionariesRecordStatesContext.Provider value={stateValue}>\n <DictionariesRecordActionsContext.Provider value={actionValue}>\n {children}\n </DictionariesRecordActionsContext.Provider>\n </DictionariesRecordStatesContext.Provider>\n );\n};\n\nexport const useDictionariesRecordActions = () =>\n useContext(DictionariesRecordActionsContext);\n\nexport const useDictionariesRecord = () => {\n const actionsContext = useDictionariesRecordActions();\n const statesContext = useContext(DictionariesRecordStatesContext);\n\n if (!statesContext) {\n throw new Error(\n 'useDictionariesRecordStates must be used within a DictionariesRecordProvider'\n );\n }\n\n return { ...statesContext, ...actionsContext };\n};\n"],"mappings":"yRAyBA,MAAM,GAAA,EAAA,EAAA,eAEJ,IAAA,GAAU,CACN,GAAA,EAAA,EAAA,eAEJ,IAAA,GAAU,CAEC,GAER,CAAE,cAAe,CACpB,GAAM,CAAC,EAAoB,GACzBA,EAAAA,mBACEC,EAAAA,WAAW,qCACX,IAAA,GACD,CAEG,GAAA,EAAA,EAAA,cACG,CACL,mBAAoB,GAAsB,EAAE,CAC7C,EACD,CAAC,EAAmB,CACrB,CAEK,GAAA,EAAA,EAAA,cACG,CACL,wBACA,oBAAsB,GAA2B,CAC/C,EAAuB,IAAkB,CACvC,GAAG,GACF,OAAO,EAAW,QAAQ,EAAG,EAC/B,EAAE,EAEN,EACD,CAAC,EAAsB,CACxB,CAED,OACE,EAAA,EAAA,KAAC,EAAgC,SAAA,CAAS,MAAO,YAC/C,EAAA,EAAA,KAAC,EAAiC,SAAA,CAAS,MAAO,EAC/C,YACyC,EACH,EAIlC,OAAA,EAAA,EAAA,YACA,EAAiC,CAEjC,MAA8B,CACzC,IAAM,EAAiB,GAA8B,CAC/C,GAAA,EAAA,EAAA,YAA2B,EAAgC,CAEjE,GAAI,CAAC,EACH,MAAU,MACR,+EACD,CAGH,MAAO,CAAE,GAAG,EAAe,GAAG,EAAgB"}
|
|
@@ -1,164 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_editor_useCrossFrameMessageListener = require('./useCrossFrameMessageListener.cjs');
|
|
6
|
-
const require_editor_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
7
|
-
const require_editor_DictionariesRecordContext = require('./DictionariesRecordContext.cjs');
|
|
8
|
-
let preact = require("preact");
|
|
9
|
-
let _intlayer_core = require("@intlayer/core");
|
|
10
|
-
let _intlayer_types = require("@intlayer/types");
|
|
11
|
-
let _intlayer_editor = require("@intlayer/editor");
|
|
12
|
-
let preact_hooks = require("preact/hooks");
|
|
13
|
-
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
14
|
-
|
|
15
|
-
//#region src/editor/EditedContentContext.tsx
|
|
16
|
-
const EditedContentStateContext = (0, preact.createContext)(void 0);
|
|
17
|
-
const usePostEditedContentState = (onEventTriggered) => require_editor_useCrossFrameMessageListener.useCrossFrameMessageListener(`${_intlayer_editor.MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/post`, onEventTriggered);
|
|
18
|
-
const useGetEditedContentState = (onEventTriggered) => require_editor_useCrossFrameMessageListener.useCrossFrameMessageListener(`${_intlayer_editor.MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/get`, onEventTriggered);
|
|
19
|
-
const EditedContentActionsContext = (0, preact.createContext)(void 0);
|
|
20
|
-
const resolveState = (state, prevState) => typeof state === "function" ? state(prevState) : state;
|
|
21
|
-
const EditedContentProvider = ({ children }) => {
|
|
22
|
-
const { localeDictionaries } = require_editor_DictionariesRecordContext.useDictionariesRecord();
|
|
23
|
-
const [editedContent, setEditedContentState] = require_editor_useCrossFrameState.useCrossFrameState(_intlayer_editor.MessageKey.INTLAYER_EDITED_CONTENT_CHANGED);
|
|
24
|
-
const setEditedDictionary = (newValue) => {
|
|
25
|
-
let updatedDictionaries = resolveState(newValue);
|
|
26
|
-
setEditedContentState((prev) => {
|
|
27
|
-
updatedDictionaries = resolveState(newValue, prev?.[updatedDictionaries.key]);
|
|
28
|
-
return {
|
|
29
|
-
...prev,
|
|
30
|
-
[updatedDictionaries.key]: updatedDictionaries
|
|
31
|
-
};
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
const setEditedContent = (dictionaryLocalId, newValue) => {
|
|
35
|
-
setEditedContentState((prev) => ({
|
|
36
|
-
...prev,
|
|
37
|
-
[dictionaryLocalId]: {
|
|
38
|
-
...prev?.[dictionaryLocalId],
|
|
39
|
-
content: newValue
|
|
40
|
-
}
|
|
41
|
-
}));
|
|
42
|
-
};
|
|
43
|
-
const addEditedContent = (dictionaryLocalId, newValue, keyPath = [], overwrite = true) => {
|
|
44
|
-
setEditedContentState((prev) => {
|
|
45
|
-
const originalContent = localeDictionaries[dictionaryLocalId]?.content;
|
|
46
|
-
const currentContent = structuredClone(prev?.[dictionaryLocalId]?.content ?? originalContent);
|
|
47
|
-
let newKeyPath = keyPath;
|
|
48
|
-
if (!overwrite) {
|
|
49
|
-
let index = 0;
|
|
50
|
-
const otherKeyPath = keyPath.slice(0, -1);
|
|
51
|
-
const lastKeyPath = keyPath[keyPath.length - 1];
|
|
52
|
-
let finalKey = lastKeyPath.key;
|
|
53
|
-
while (typeof (0, _intlayer_core.getContentNodeByKeyPath)(currentContent, newKeyPath) !== "undefined") {
|
|
54
|
-
index++;
|
|
55
|
-
finalKey = index === 0 ? lastKeyPath.key : `${lastKeyPath.key} (${index})`;
|
|
56
|
-
newKeyPath = [...otherKeyPath, {
|
|
57
|
-
...lastKeyPath,
|
|
58
|
-
key: finalKey
|
|
59
|
-
}];
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
const updatedContent = (0, _intlayer_core.editDictionaryByKeyPath)(currentContent, newKeyPath, newValue);
|
|
63
|
-
return {
|
|
64
|
-
...prev,
|
|
65
|
-
[dictionaryLocalId]: {
|
|
66
|
-
...prev?.[dictionaryLocalId],
|
|
67
|
-
content: updatedContent
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
const renameEditedContent = (dictionaryLocalId, newKey, keyPath = []) => {
|
|
73
|
-
setEditedContentState((prev) => {
|
|
74
|
-
const originalContent = localeDictionaries[dictionaryLocalId]?.content;
|
|
75
|
-
const contentWithNewField = (0, _intlayer_core.renameContentNodeByKeyPath)(structuredClone(prev?.[dictionaryLocalId]?.content ?? originalContent), newKey, keyPath);
|
|
76
|
-
return {
|
|
77
|
-
...prev,
|
|
78
|
-
[dictionaryLocalId]: {
|
|
79
|
-
...prev?.[dictionaryLocalId],
|
|
80
|
-
content: contentWithNewField
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
const removeEditedContent = (dictionaryLocalId, keyPath) => {
|
|
86
|
-
setEditedContentState((prev) => {
|
|
87
|
-
const originalContent = localeDictionaries[dictionaryLocalId]?.content;
|
|
88
|
-
const restoredContent = (0, _intlayer_core.editDictionaryByKeyPath)(structuredClone(prev?.[dictionaryLocalId]?.content ?? originalContent), keyPath, (0, _intlayer_core.getContentNodeByKeyPath)(originalContent, keyPath));
|
|
89
|
-
return {
|
|
90
|
-
...prev,
|
|
91
|
-
[dictionaryLocalId]: {
|
|
92
|
-
...prev?.[dictionaryLocalId],
|
|
93
|
-
content: restoredContent
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
const restoreEditedContent = (dictionaryLocalId) => {
|
|
99
|
-
setEditedContentState((prev) => {
|
|
100
|
-
const updated = { ...prev };
|
|
101
|
-
delete updated[dictionaryLocalId];
|
|
102
|
-
return updated;
|
|
103
|
-
});
|
|
104
|
-
};
|
|
105
|
-
const clearEditedDictionaryContent = (dictionaryLocalId) => {
|
|
106
|
-
setEditedContentState((prev) => {
|
|
107
|
-
return Object.entries(prev).reduce((acc, [key, value]) => {
|
|
108
|
-
if (key === dictionaryLocalId) return acc;
|
|
109
|
-
return {
|
|
110
|
-
...acc,
|
|
111
|
-
[key]: value
|
|
112
|
-
};
|
|
113
|
-
}, {});
|
|
114
|
-
});
|
|
115
|
-
};
|
|
116
|
-
const clearEditedContent = () => {
|
|
117
|
-
setEditedContentState({});
|
|
118
|
-
};
|
|
119
|
-
const getEditedContentValue = (localDictionaryIdOrKey, keyPath) => {
|
|
120
|
-
if (!editedContent) return void 0;
|
|
121
|
-
const filteredKeyPath = keyPath.filter((key) => key.type !== _intlayer_types.NodeType.Translation);
|
|
122
|
-
if (localDictionaryIdOrKey.includes(":local:") || localDictionaryIdOrKey.includes(":remote:")) return (0, _intlayer_core.getContentNodeByKeyPath)(editedContent?.[localDictionaryIdOrKey]?.content ?? {}, filteredKeyPath);
|
|
123
|
-
const filteredDictionariesLocalId = Object.keys(editedContent).filter((key) => key.startsWith(`${localDictionaryIdOrKey}:`));
|
|
124
|
-
for (const localDictionaryId of filteredDictionariesLocalId) {
|
|
125
|
-
const contentNode = (0, _intlayer_core.getContentNodeByKeyPath)(editedContent?.[localDictionaryId]?.content ?? {}, filteredKeyPath);
|
|
126
|
-
if (contentNode) return contentNode;
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
return /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(EditedContentStateContext.Provider, {
|
|
130
|
-
value: { editedContent },
|
|
131
|
-
children: /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(EditedContentActionsContext.Provider, {
|
|
132
|
-
value: {
|
|
133
|
-
setEditedContentState,
|
|
134
|
-
setEditedDictionary,
|
|
135
|
-
setEditedContent,
|
|
136
|
-
addEditedContent,
|
|
137
|
-
renameEditedContent,
|
|
138
|
-
removeEditedContent,
|
|
139
|
-
restoreEditedContent,
|
|
140
|
-
clearEditedDictionaryContent,
|
|
141
|
-
clearEditedContent,
|
|
142
|
-
getEditedContentValue
|
|
143
|
-
},
|
|
144
|
-
children
|
|
145
|
-
})
|
|
146
|
-
});
|
|
147
|
-
};
|
|
148
|
-
const useEditedContentActions = () => (0, preact_hooks.useContext)(EditedContentActionsContext);
|
|
149
|
-
const useEditedContent = () => {
|
|
150
|
-
const stateContext = (0, preact_hooks.useContext)(EditedContentStateContext);
|
|
151
|
-
const actionContext = useEditedContentActions();
|
|
152
|
-
return {
|
|
153
|
-
...stateContext,
|
|
154
|
-
...actionContext
|
|
155
|
-
};
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
//#endregion
|
|
159
|
-
exports.EditedContentProvider = EditedContentProvider;
|
|
160
|
-
exports.useEditedContent = useEditedContent;
|
|
161
|
-
exports.useEditedContentActions = useEditedContentActions;
|
|
162
|
-
exports.useGetEditedContentState = useGetEditedContentState;
|
|
163
|
-
exports.usePostEditedContentState = usePostEditedContentState;
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./useCrossFrameMessageListener.cjs`),t=require(`./useCrossFrameState.cjs`),n=require(`./DictionariesRecordContext.cjs`);let r=require(`preact`),i=require(`@intlayer/types`),a=require(`@intlayer/editor`),o=require(`preact/hooks`),s=require(`preact/jsx-runtime`),c=require(`@intlayer/core/dictionaryManipulator`);const l=(0,r.createContext)(void 0),u=t=>e.useCrossFrameMessageListener(`${a.MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/post`,t),d=t=>e.useCrossFrameMessageListener(`${a.MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/get`,t),f=(0,r.createContext)(void 0),p=(e,t)=>typeof e==`function`?e(t):e,m=({children:e})=>{let{localeDictionaries:r}=n.useDictionariesRecord(),[o,u]=t.useCrossFrameState(a.MessageKey.INTLAYER_EDITED_CONTENT_CHANGED);return(0,s.jsx)(l.Provider,{value:{editedContent:o},children:(0,s.jsx)(f.Provider,{value:{setEditedContentState:u,setEditedDictionary:e=>{let t=p(e);u(n=>(t=p(e,n?.[t.key]),{...n,[t.key]:t}))},setEditedContent:(e,t)=>{u(n=>({...n,[e]:{...n?.[e],content:t}}))},addEditedContent:(e,t,n=[],i=!0)=>{u(a=>{let o=r[e]?.content,s=structuredClone(a?.[e]?.content??o),l=n;if(!i){let e=0,t=n.slice(0,-1),r=n[n.length-1],i=r.key;for(;(0,c.getContentNodeByKeyPath)(s,l)!==void 0;)e++,i=e===0?r.key:`${r.key} (${e})`,l=[...t,{...r,key:i}]}let u=(0,c.editDictionaryByKeyPath)(s,l,t);return{...a,[e]:{...a?.[e],content:u}}})},renameEditedContent:(e,t,n=[])=>{u(i=>{let a=r[e]?.content,o=(0,c.renameContentNodeByKeyPath)(structuredClone(i?.[e]?.content??a),t,n);return{...i,[e]:{...i?.[e],content:o}}})},removeEditedContent:(e,t)=>{u(n=>{let i=r[e]?.content,a=(0,c.editDictionaryByKeyPath)(structuredClone(n?.[e]?.content??i),t,(0,c.getContentNodeByKeyPath)(i,t));return{...n,[e]:{...n?.[e],content:a}}})},restoreEditedContent:e=>{u(t=>{let n={...t};return delete n[e],n})},clearEditedDictionaryContent:e=>{u(t=>{let n={...t};return delete n[e],n})},clearEditedContent:()=>{u({})},getEditedContentValue:(e,t)=>{if(!o)return;let n=t.filter(e=>e.type!==i.NodeType.Translation);if(e.includes(`:local:`)||e.includes(`:remote:`))return(0,c.getContentNodeByKeyPath)(o?.[e]?.content??{},n);let r=Object.keys(o).filter(t=>t.startsWith(`${e}:`));for(let e of r){let t=(0,c.getContentNodeByKeyPath)(o?.[e]?.content??{},n);if(t)return t}}},children:e})})},h=()=>(0,o.useContext)(f),g=()=>{let e=(0,o.useContext)(l),t=h();return{...e,...t}};exports.EditedContentProvider=m,exports.useEditedContent=g,exports.useEditedContentActions=h,exports.useGetEditedContentState=d,exports.usePostEditedContentState=u;
|
|
164
2
|
//# sourceMappingURL=EditedContentContext.cjs.map
|