preact-intlayer 5.5.5 → 5.5.6
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 +47 -0
- package/dist/cjs/IntlayerNode.cjs.map +1 -0
- package/dist/cjs/UI/ContentSelector.cjs +127 -0
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -0
- package/dist/cjs/client/IntlayerProvider.cjs +98 -0
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -0
- package/dist/cjs/client/getBrowserLocale.cjs +173 -0
- package/dist/cjs/client/getBrowserLocale.cjs.map +1 -0
- package/dist/cjs/client/index.cjs +69 -0
- package/dist/cjs/client/index.cjs.map +1 -0
- package/dist/cjs/client/t.cjs +37 -0
- package/dist/cjs/client/t.cjs.map +1 -0
- package/dist/cjs/client/useContent.cjs +39 -0
- package/dist/cjs/client/useContent.cjs.map +1 -0
- package/dist/cjs/client/useDictionary.cjs +42 -0
- package/dist/cjs/client/useDictionary.cjs.map +1 -0
- package/dist/cjs/client/useDictionaryDynamic.cjs +42 -0
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -0
- package/dist/cjs/client/useIntlayer.cjs +43 -0
- package/dist/cjs/client/useIntlayer.cjs.map +1 -0
- package/dist/cjs/client/useIntlayerAsync.cjs +54 -0
- package/dist/cjs/client/useIntlayerAsync.cjs.map +1 -0
- package/dist/cjs/client/useLoadDynamic.cjs +56 -0
- package/dist/cjs/client/useLoadDynamic.cjs.map +1 -0
- package/dist/cjs/client/useLocale.cjs +69 -0
- package/dist/cjs/client/useLocale.cjs.map +1 -0
- package/dist/cjs/client/useLocaleBase.cjs +56 -0
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -0
- package/dist/cjs/client/useLocaleCookie.cjs +60 -0
- package/dist/cjs/client/useLocaleCookie.cjs.map +1 -0
- package/dist/cjs/client/useTraduction.cjs +35 -0
- package/dist/cjs/client/useTraduction.cjs.map +1 -0
- package/dist/cjs/editor/ChangedContentContext.cjs +77 -0
- package/dist/cjs/editor/ChangedContentContext.cjs.map +1 -0
- package/dist/cjs/editor/CommunicatorContext.cjs +66 -0
- package/dist/cjs/editor/CommunicatorContext.cjs.map +1 -0
- package/dist/cjs/editor/ConfigurationContext.cjs +50 -0
- package/dist/cjs/editor/ConfigurationContext.cjs.map +1 -0
- package/dist/cjs/editor/ContentSelectorWrapper.cjs +66 -0
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -0
- package/dist/cjs/editor/DictionariesRecordContext.cjs +77 -0
- package/dist/cjs/editor/DictionariesRecordContext.cjs.map +1 -0
- package/dist/cjs/editor/EditedContentContext.cjs +217 -0
- package/dist/cjs/editor/EditedContentContext.cjs.map +1 -0
- package/dist/cjs/editor/EditorEnabledContext.cjs +62 -0
- package/dist/cjs/editor/EditorEnabledContext.cjs.map +1 -0
- package/dist/cjs/editor/EditorProvider.cjs +72 -0
- package/dist/cjs/editor/EditorProvider.cjs.map +1 -0
- package/dist/cjs/editor/FocusDictionaryContext.cjs +81 -0
- package/dist/cjs/editor/FocusDictionaryContext.cjs.map +1 -0
- package/dist/cjs/editor/IntlayerEditorProvider.cjs +122 -0
- package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -0
- package/dist/cjs/editor/index.cjs +23 -0
- package/dist/cjs/editor/index.cjs.map +1 -0
- package/dist/cjs/editor/useCrossFrameMessageListener.cjs +53 -0
- package/dist/cjs/editor/useCrossFrameMessageListener.cjs.map +1 -0
- package/dist/cjs/editor/useCrossFrameState.cjs +77 -0
- package/dist/cjs/editor/useCrossFrameState.cjs.map +1 -0
- package/dist/cjs/editor/useCrossURLPathState.cjs +69 -0
- package/dist/cjs/editor/useCrossURLPathState.cjs.map +1 -0
- package/dist/cjs/editor/useEditedContentRenderer.cjs +63 -0
- package/dist/cjs/editor/useEditedContentRenderer.cjs.map +1 -0
- package/dist/cjs/editor/useIframeClickInterceptor.cjs +50 -0
- package/dist/cjs/editor/useIframeClickInterceptor.cjs.map +1 -0
- package/dist/cjs/getDictionary.cjs +43 -0
- package/dist/cjs/getDictionary.cjs.map +1 -0
- package/dist/cjs/getIntlayer.cjs +39 -0
- package/dist/cjs/getIntlayer.cjs.map +1 -0
- package/dist/cjs/index.cjs +42 -5
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownProvider.cjs +41 -0
- package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -0
- package/dist/cjs/markdown/MarkdownRenderer.cjs +83 -0
- package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -0
- package/dist/cjs/markdown/index.cjs +25 -0
- package/dist/cjs/markdown/index.cjs.map +1 -0
- package/dist/cjs/plugins.cjs +128 -0
- package/dist/cjs/plugins.cjs.map +1 -0
- package/dist/cjs/preactElement/renderPreactElement.cjs +62 -0
- package/dist/cjs/preactElement/renderPreactElement.cjs.map +1 -0
- package/dist/esm/IntlayerNode.mjs +27 -0
- package/dist/esm/IntlayerNode.mjs.map +1 -0
- package/dist/esm/UI/ContentSelector.mjs +103 -0
- package/dist/esm/UI/ContentSelector.mjs.map +1 -0
- package/dist/esm/client/IntlayerProvider.mjs +63 -0
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -0
- package/dist/esm/client/getBrowserLocale.mjs +138 -0
- package/dist/esm/client/getBrowserLocale.mjs.map +1 -0
- package/dist/esm/client/index.mjs +39 -0
- package/dist/esm/client/index.mjs.map +1 -0
- package/dist/esm/client/t.mjs +13 -0
- package/dist/esm/client/t.mjs.map +1 -0
- package/dist/esm/client/useContent.mjs +15 -0
- package/dist/esm/client/useContent.mjs.map +1 -0
- package/dist/esm/client/useDictionary.mjs +18 -0
- package/dist/esm/client/useDictionary.mjs.map +1 -0
- package/dist/esm/client/useDictionaryDynamic.mjs +18 -0
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -0
- package/dist/esm/client/useIntlayer.mjs +19 -0
- package/dist/esm/client/useIntlayer.mjs.map +1 -0
- package/dist/esm/client/useIntlayerAsync.mjs +33 -0
- package/dist/esm/client/useIntlayerAsync.mjs.map +1 -0
- package/dist/esm/client/useLoadDynamic.mjs +32 -0
- package/dist/esm/client/useLoadDynamic.mjs.map +1 -0
- package/dist/esm/client/useLocale.mjs +35 -0
- package/dist/esm/client/useLocale.mjs.map +1 -0
- package/dist/esm/client/useLocaleBase.mjs +22 -0
- package/dist/esm/client/useLocaleBase.mjs.map +1 -0
- package/dist/esm/client/useLocaleCookie.mjs +24 -0
- package/dist/esm/client/useLocaleCookie.mjs.map +1 -0
- package/dist/esm/client/useTraduction.mjs +11 -0
- package/dist/esm/client/useTraduction.mjs.map +1 -0
- package/dist/esm/editor/ChangedContentContext.mjs +55 -0
- package/dist/esm/editor/ChangedContentContext.mjs.map +1 -0
- package/dist/esm/editor/CommunicatorContext.mjs +33 -0
- package/dist/esm/editor/CommunicatorContext.mjs.map +1 -0
- package/dist/esm/editor/ConfigurationContext.mjs +27 -0
- package/dist/esm/editor/ConfigurationContext.mjs.map +1 -0
- package/dist/esm/editor/ContentSelectorWrapper.mjs +45 -0
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -0
- package/dist/esm/editor/DictionariesRecordContext.mjs +55 -0
- package/dist/esm/editor/DictionariesRecordContext.mjs.map +1 -0
- package/dist/esm/editor/EditedContentContext.mjs +198 -0
- package/dist/esm/editor/EditedContentContext.mjs.map +1 -0
- package/dist/esm/editor/EditorEnabledContext.mjs +39 -0
- package/dist/esm/editor/EditorEnabledContext.mjs.map +1 -0
- package/dist/esm/editor/EditorProvider.mjs +62 -0
- package/dist/esm/editor/EditorProvider.mjs.map +1 -0
- package/dist/esm/editor/FocusDictionaryContext.mjs +58 -0
- package/dist/esm/editor/FocusDictionaryContext.mjs.map +1 -0
- package/dist/esm/editor/IntlayerEditorProvider.mjs +88 -0
- package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -0
- package/dist/esm/editor/index.mjs +2 -0
- package/dist/esm/editor/index.mjs.map +1 -0
- package/dist/esm/editor/useCrossFrameMessageListener.mjs +29 -0
- package/dist/esm/editor/useCrossFrameMessageListener.mjs.map +1 -0
- package/dist/esm/editor/useCrossFrameState.mjs +53 -0
- package/dist/esm/editor/useCrossFrameState.mjs.map +1 -0
- package/dist/esm/editor/useCrossURLPathState.mjs +46 -0
- package/dist/esm/editor/useCrossURLPathState.mjs.map +1 -0
- package/dist/esm/editor/useEditedContentRenderer.mjs +38 -0
- package/dist/esm/editor/useEditedContentRenderer.mjs.map +1 -0
- package/dist/esm/editor/useIframeClickInterceptor.mjs +25 -0
- package/dist/esm/editor/useIframeClickInterceptor.mjs.map +1 -0
- package/dist/esm/getDictionary.mjs +25 -0
- package/dist/esm/getDictionary.mjs.map +1 -0
- package/dist/esm/getIntlayer.mjs +21 -0
- package/dist/esm/getIntlayer.mjs.map +1 -0
- package/dist/esm/index.mjs +38 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownProvider.mjs +19 -0
- package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -0
- package/dist/esm/markdown/MarkdownRenderer.mjs +62 -0
- package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -0
- package/dist/esm/markdown/index.mjs +3 -0
- package/dist/esm/markdown/index.mjs.map +1 -0
- package/dist/esm/plugins.mjs +104 -0
- package/dist/esm/plugins.mjs.map +1 -0
- package/dist/esm/preactElement/renderPreactElement.mjs +38 -0
- package/dist/esm/preactElement/renderPreactElement.mjs.map +1 -0
- package/dist/types/IntlayerNode.d.ts +15 -0
- package/dist/types/IntlayerNode.d.ts.map +1 -0
- package/dist/types/UI/ContentSelector.d.ts +10 -0
- package/dist/types/UI/ContentSelector.d.ts.map +1 -0
- package/dist/types/client/IntlayerProvider.d.ts +29 -0
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -0
- package/dist/types/client/getBrowserLocale.d.ts +25 -0
- package/dist/types/client/getBrowserLocale.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +12 -0
- package/dist/types/client/index.d.ts.map +1 -0
- package/dist/types/client/t.d.ts +9 -0
- package/dist/types/client/t.d.ts.map +1 -0
- package/dist/types/client/useContent.d.ts +10 -0
- package/dist/types/client/useContent.d.ts.map +1 -0
- package/dist/types/client/useDictionary.d.ts +9 -0
- package/dist/types/client/useDictionary.d.ts.map +1 -0
- package/dist/types/client/useDictionaryDynamic.d.ts +9 -0
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -0
- package/dist/types/client/useIntlayer.d.ts +11 -0
- package/dist/types/client/useIntlayer.d.ts.map +1 -0
- package/dist/types/client/useIntlayerAsync.d.ts +14 -0
- package/dist/types/client/useIntlayerAsync.d.ts.map +1 -0
- package/dist/types/client/useLoadDynamic.d.ts +2 -0
- package/dist/types/client/useLoadDynamic.d.ts.map +1 -0
- package/dist/types/client/useLocale.d.ts +15 -0
- package/dist/types/client/useLocale.d.ts.map +1 -0
- package/dist/types/client/useLocaleBase.d.ts +10 -0
- package/dist/types/client/useLocaleBase.d.ts.map +1 -0
- package/dist/types/client/useLocaleCookie.d.ts +17 -0
- package/dist/types/client/useLocaleCookie.d.ts.map +1 -0
- package/dist/types/client/useTraduction.d.ts +24 -0
- package/dist/types/client/useTraduction.d.ts.map +1 -0
- package/dist/types/editor/ChangedContentContext.d.ts +13 -0
- package/dist/types/editor/ChangedContentContext.d.ts.map +1 -0
- package/dist/types/editor/CommunicatorContext.d.ts +14 -0
- package/dist/types/editor/CommunicatorContext.d.ts.map +1 -0
- package/dist/types/editor/ConfigurationContext.d.ts +9 -0
- package/dist/types/editor/ConfigurationContext.d.ts.map +1 -0
- package/dist/types/editor/ContentSelectorWrapper.d.ts +5 -0
- package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -0
- package/dist/types/editor/DictionariesRecordContext.d.ts +16 -0
- package/dist/types/editor/DictionariesRecordContext.d.ts.map +1 -0
- package/dist/types/editor/EditedContentContext.d.ts +33 -0
- package/dist/types/editor/EditedContentContext.d.ts.map +1 -0
- package/dist/types/editor/EditorEnabledContext.d.ts +11 -0
- package/dist/types/editor/EditorEnabledContext.d.ts.map +1 -0
- package/dist/types/editor/EditorProvider.d.ts +6 -0
- package/dist/types/editor/EditorProvider.d.ts.map +1 -0
- package/dist/types/editor/FocusDictionaryContext.d.ts +21 -0
- package/dist/types/editor/FocusDictionaryContext.d.ts.map +1 -0
- package/dist/types/editor/IntlayerEditorProvider.d.ts +5 -0
- package/dist/types/editor/IntlayerEditorProvider.d.ts.map +1 -0
- package/dist/types/editor/index.d.ts +2 -0
- package/dist/types/editor/index.d.ts.map +1 -0
- package/dist/types/editor/useCrossFrameMessageListener.d.ts +19 -0
- package/dist/types/editor/useCrossFrameMessageListener.d.ts.map +1 -0
- package/dist/types/editor/useCrossFrameState.d.ts +30 -0
- package/dist/types/editor/useCrossFrameState.d.ts.map +1 -0
- package/dist/types/editor/useCrossURLPathState.d.ts +4 -0
- package/dist/types/editor/useCrossURLPathState.d.ts.map +1 -0
- package/dist/types/editor/useEditedContentRenderer.d.ts +13 -0
- package/dist/types/editor/useEditedContentRenderer.d.ts.map +1 -0
- package/dist/types/editor/useIframeClickInterceptor.d.ts +3 -0
- package/dist/types/editor/useIframeClickInterceptor.d.ts.map +1 -0
- package/dist/types/getDictionary.d.ts +5 -0
- package/dist/types/getDictionary.d.ts.map +1 -0
- package/dist/types/getIntlayer.d.ts +5 -0
- package/dist/types/getIntlayer.d.ts.map +1 -0
- package/dist/types/index.d.ts +8 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/markdown/MarkdownProvider.d.ts +9 -0
- package/dist/types/markdown/MarkdownProvider.d.ts.map +1 -0
- package/dist/types/markdown/MarkdownRenderer.d.ts +16 -0
- package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -0
- package/dist/types/markdown/index.d.ts +3 -0
- package/dist/types/markdown/index.d.ts.map +1 -0
- package/dist/types/plugins.d.ts +54 -0
- package/dist/types/plugins.d.ts.map +1 -0
- package/dist/types/preactElement/renderPreactElement.d.ts +5 -0
- package/dist/types/preactElement/renderPreactElement.d.ts.map +1 -0
- package/package.json +15 -8
- package/dist/cjs/intlayerMiddlewarePlugin.cjs +0 -224
- package/dist/cjs/intlayerMiddlewarePlugin.cjs.map +0 -1
- package/dist/cjs/intlayerPlugin.cjs +0 -76
- package/dist/cjs/intlayerPlugin.cjs.map +0 -1
- package/dist/esm/intlayerMiddlewarePlugin.mjs +0 -200
- package/dist/esm/intlayerMiddlewarePlugin.mjs.map +0 -1
- package/dist/esm/intlayerPlugin.mjs +0 -52
- package/dist/esm/intlayerPlugin.mjs.map +0 -1
- package/dist/types/intlayerMiddlewarePlugin.d.ts +0 -6
- package/dist/types/intlayerMiddlewarePlugin.d.ts.map +0 -1
- package/dist/types/intlayerPlugin.d.ts +0 -16
- package/dist/types/intlayerPlugin.d.ts.map +0 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import configuration from "@intlayer/config/built";
|
|
3
|
+
import { useContext } from "preact/hooks";
|
|
4
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
5
|
+
const { defaultLocale, locales: availableLocales } = configuration.internationalization;
|
|
6
|
+
const useLocaleBase = () => {
|
|
7
|
+
const { locale, setLocale } = useContext(IntlayerClientContext);
|
|
8
|
+
return {
|
|
9
|
+
locale,
|
|
10
|
+
// Current locale
|
|
11
|
+
defaultLocale,
|
|
12
|
+
// Principal locale defined in config
|
|
13
|
+
availableLocales,
|
|
14
|
+
// List of the available locales defined in config
|
|
15
|
+
setLocale
|
|
16
|
+
// Function to set the locale
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
useLocaleBase
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=useLocaleBase.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\nconst { defaultLocale, locales: availableLocales } =\n configuration.internationalization;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocaleBase = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";AAEA,OAAO,mBAAmB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAEtC,MAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,cAAc;AAKT,MAAM,gBAAgB,MAAM;AACjC,QAAM,EAAE,QAAQ,UAAU,IAAI,WAAW,qBAAqB;AAE9D,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import configuration from "@intlayer/config/built";
|
|
2
|
+
import Cookies from "js-cookie";
|
|
3
|
+
const { cookieName } = configuration.middleware;
|
|
4
|
+
const cookieAttributes = {
|
|
5
|
+
path: "/",
|
|
6
|
+
expires: void 0,
|
|
7
|
+
domain: void 0,
|
|
8
|
+
secure: false,
|
|
9
|
+
sameSite: "strict"
|
|
10
|
+
};
|
|
11
|
+
const localeCookie = Cookies.get(cookieName);
|
|
12
|
+
const setLocaleCookie = (locale) => {
|
|
13
|
+
Cookies.set(cookieName, locale, cookieAttributes);
|
|
14
|
+
};
|
|
15
|
+
const useLocaleCookie = () => ({
|
|
16
|
+
localeCookie,
|
|
17
|
+
setLocaleCookie
|
|
18
|
+
});
|
|
19
|
+
export {
|
|
20
|
+
localeCookie,
|
|
21
|
+
setLocaleCookie,
|
|
22
|
+
useLocaleCookie
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=useLocaleCookie.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocaleCookie.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/config/client';\n\nimport Cookies from 'js-cookie';\n\nconst { cookieName } = configuration.middleware;\n\nconst cookieAttributes: Cookies.CookieAttributes = {\n path: '/',\n expires: undefined,\n domain: undefined,\n secure: false,\n sameSite: 'strict',\n};\n\n/**\n * Get the locale cookie\n */\nexport const localeCookie = Cookies.get(cookieName) as unknown as\n | LocalesValues\n | undefined;\n\n/**\n * Set the locale cookie\n */\nexport const setLocaleCookie = (locale: LocalesValues) => {\n Cookies.set(cookieName, locale, cookieAttributes);\n};\n\n/**\n * Hook that provides the locale cookie and a function to set it\n */\nexport const useLocaleCookie = () => ({\n localeCookie,\n setLocaleCookie,\n});\n"],"mappings":"AAAA,OAAO,mBAAmB;AAG1B,OAAO,aAAa;AAEpB,MAAM,EAAE,WAAW,IAAI,cAAc;AAErC,MAAM,mBAA6C;AAAA,EACjD,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AACZ;AAKO,MAAM,eAAe,QAAQ,IAAI,UAAU;AAO3C,MAAM,kBAAkB,CAAC,WAA0B;AACxD,UAAQ,IAAI,YAAY,QAAQ,gBAAgB;AAClD;AAKO,MAAM,kBAAkB,OAAO;AAAA,EACpC;AAAA,EACA;AACF;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getTranslation } from "@intlayer/core";
|
|
2
|
+
import { useContext } from "preact/hooks";
|
|
3
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
4
|
+
const useTranslation = (languageContent) => {
|
|
5
|
+
const { locale } = useContext(IntlayerClientContext);
|
|
6
|
+
return getTranslation(languageContent, locale);
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
useTranslation
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=useTraduction.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import { getTranslation, type LanguageContent } from '@intlayer/core';\nimport { useContext } 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: LanguageContent<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return getTranslation(languageContent, locale);\n};\n"],"mappings":"AAAA,SAAS,sBAA4C;AACrD,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAuB/B,MAAM,iBAAiB,CAC5B,oBACY;AACZ,QAAM,EAAE,OAAO,IAAI,WAAW,qBAAqB;AAEnD,SAAO,eAAe,iBAAiB,MAAM;AAC/C;","names":[]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "preact/jsx-runtime";
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
useContext,
|
|
6
|
+
useState
|
|
7
|
+
} from "preact/compat";
|
|
8
|
+
const ChangedContentStateContext = createContext(void 0);
|
|
9
|
+
const ChangedContentActionsContext = createContext(void 0);
|
|
10
|
+
const ChangedContentProvider = ({ children }) => {
|
|
11
|
+
const [changedContent, setChangedContentState] = useState(
|
|
12
|
+
{}
|
|
13
|
+
);
|
|
14
|
+
const setChangedContent = (dictionaryKey, newValue) => {
|
|
15
|
+
setChangedContentState((prev) => ({
|
|
16
|
+
...prev,
|
|
17
|
+
[dictionaryKey]: {
|
|
18
|
+
...prev?.[dictionaryKey],
|
|
19
|
+
content: newValue
|
|
20
|
+
}
|
|
21
|
+
}));
|
|
22
|
+
};
|
|
23
|
+
return /* @__PURE__ */ jsx(
|
|
24
|
+
ChangedContentStateContext.Provider,
|
|
25
|
+
{
|
|
26
|
+
value: {
|
|
27
|
+
changedContent
|
|
28
|
+
},
|
|
29
|
+
children: /* @__PURE__ */ jsx(
|
|
30
|
+
ChangedContentActionsContext.Provider,
|
|
31
|
+
{
|
|
32
|
+
value: {
|
|
33
|
+
setChangedContent
|
|
34
|
+
},
|
|
35
|
+
children
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
const useChangedContentActions = () => {
|
|
42
|
+
const context = useContext(ChangedContentActionsContext);
|
|
43
|
+
return context;
|
|
44
|
+
};
|
|
45
|
+
const useChangedContent = () => {
|
|
46
|
+
const stateContext = useContext(ChangedContentStateContext);
|
|
47
|
+
const actionContext = useChangedContentActions();
|
|
48
|
+
return { ...stateContext, ...actionContext };
|
|
49
|
+
};
|
|
50
|
+
export {
|
|
51
|
+
ChangedContentProvider,
|
|
52
|
+
useChangedContent,
|
|
53
|
+
useChangedContentActions
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=ChangedContentContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/ChangedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport type { Dictionary } from '@intlayer/core';\nimport {\n createContext,\n useContext,\n useState,\n type FC,\n type PropsWithChildren,\n} from 'preact/compat';\nimport type { DictionaryContent } from './DictionariesRecordContext';\n\ntype ChangedContentStateContextType = {\n changedContent: Record<Dictionary['key'], Dictionary> | undefined;\n};\n\nconst ChangedContentStateContext = createContext<\n ChangedContentStateContextType | undefined\n>(undefined);\n\ntype ChangedContentActionsContextType = {\n setChangedContent: (\n dictionaryKey: Dictionary['key'],\n newValue: Dictionary['content']\n ) => void;\n};\n\nconst ChangedContentActionsContext = createContext<\n ChangedContentActionsContextType | undefined\n>(undefined);\n\nexport const ChangedContentProvider: FC<PropsWithChildren> = ({ children }) => {\n const [changedContent, setChangedContentState] = useState<DictionaryContent>(\n {}\n );\n\n const setChangedContent = (\n dictionaryKey: Dictionary['key'],\n newValue: Dictionary['content']\n ) => {\n setChangedContentState((prev) => ({\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: newValue,\n },\n }));\n };\n\n return (\n <ChangedContentStateContext.Provider\n value={{\n changedContent,\n }}\n >\n <ChangedContentActionsContext.Provider\n value={{\n setChangedContent,\n }}\n >\n {children}\n </ChangedContentActionsContext.Provider>\n </ChangedContentStateContext.Provider>\n );\n};\n\nexport const useChangedContentActions = () => {\n const context = useContext(ChangedContentActionsContext);\n\n return context;\n};\n\nexport const useChangedContent = () => {\n const stateContext = useContext(ChangedContentStateContext);\n const actionContext = useChangedContentActions();\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":";AAuDM;AApDN;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAOP,MAAM,6BAA6B,cAEjC,MAAS;AASX,MAAM,+BAA+B,cAEnC,MAAS;AAEJ,MAAM,yBAAgD,CAAC,EAAE,SAAS,MAAM;AAC7E,QAAM,CAAC,gBAAgB,sBAAsB,IAAI;AAAA,IAC/C,CAAC;AAAA,EACH;AAEA,QAAM,oBAAoB,CACxB,eACA,aACG;AACH,2BAAuB,CAAC,UAAU;AAAA,MAChC,GAAG;AAAA,MACH,CAAC,aAAa,GAAG;AAAA,QACf,GAAG,OAAO,aAAa;AAAA,QACvB,SAAS;AAAA,MACX;AAAA,IACF,EAAE;AAAA,EACJ;AAEA,SACE;AAAA,IAAC,2BAA2B;AAAA,IAA3B;AAAA,MACC,OAAO;AAAA,QACL;AAAA,MACF;AAAA,MAEA;AAAA,QAAC,6BAA6B;AAAA,QAA7B;AAAA,UACC,OAAO;AAAA,YACL;AAAA,UACF;AAAA,UAEC;AAAA;AAAA,MACH;AAAA;AAAA,EACF;AAEJ;AAEO,MAAM,2BAA2B,MAAM;AAC5C,QAAM,UAAU,WAAW,4BAA4B;AAEvD,SAAO;AACT;AAEO,MAAM,oBAAoB,MAAM;AACrC,QAAM,eAAe,WAAW,0BAA0B;AAC1D,QAAM,gBAAgB,yBAAyB;AAE/C,SAAO,EAAE,GAAG,cAAc,GAAG,cAAc;AAC7C;","names":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "preact/jsx-runtime";
|
|
3
|
+
import configuration from "@intlayer/config/built";
|
|
4
|
+
import {
|
|
5
|
+
createContext
|
|
6
|
+
} from "preact";
|
|
7
|
+
import { useContext, useMemo, useRef } from "preact/hooks";
|
|
8
|
+
import { v4 as uuid } from "uuid";
|
|
9
|
+
const { editor } = configuration;
|
|
10
|
+
const CommunicatorContext = createContext({
|
|
11
|
+
postMessage: () => null,
|
|
12
|
+
allowedOrigins: [
|
|
13
|
+
editor?.applicationURL,
|
|
14
|
+
editor?.editorURL,
|
|
15
|
+
editor?.cmsURL
|
|
16
|
+
],
|
|
17
|
+
senderId: ""
|
|
18
|
+
});
|
|
19
|
+
const CommunicatorProvider = ({ children, allowedOrigins, postMessage }) => {
|
|
20
|
+
const senderIdRef = useRef(uuid());
|
|
21
|
+
const value = useMemo(
|
|
22
|
+
() => ({ postMessage, allowedOrigins, senderId: senderIdRef.current }),
|
|
23
|
+
[postMessage, allowedOrigins]
|
|
24
|
+
// senderIdRef.current is stable
|
|
25
|
+
);
|
|
26
|
+
return /* @__PURE__ */ jsx(CommunicatorContext.Provider, { value, children });
|
|
27
|
+
};
|
|
28
|
+
const useCommunicator = () => useContext(CommunicatorContext);
|
|
29
|
+
export {
|
|
30
|
+
CommunicatorProvider,
|
|
31
|
+
useCommunicator
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=CommunicatorContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\n\nimport {\n createContext,\n type ComponentChildren,\n type FunctionComponent,\n} from 'preact';\nimport { useContext, useMemo, useRef } from 'preact/hooks';\nimport { v4 as uuid } from 'uuid'; // if you prefer a UUID library\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(uuid());\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":";AAgDI;AA9CJ,OAAO,mBAAmB;AAE1B;AAAA,EACE;AAAA,OAGK;AACP,SAAS,YAAY,SAAS,cAAc;AAC5C,SAAS,MAAM,YAAY;AAQ3B,MAAM,EAAE,OAAO,IAAI;AAEnB,MAAM,sBAAsB,cAA0C;AAAA,EACpE,aAAa,MAAM;AAAA,EACnB,gBAAgB;AAAA,IACd,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV;AAAA,EACA,UAAU;AACZ,CAAC;AAQM,MAAM,uBAET,CAAC,EAAE,UAAU,gBAAgB,YAAY,MAAM;AAEjD,QAAM,cAAc,OAAO,KAAK,CAAC;AAEjC,QAAM,QAAQ;AAAA,IACZ,OAAO,EAAE,aAAa,gBAAgB,UAAU,YAAY,QAAQ;AAAA,IACpE,CAAC,aAAa,cAAc;AAAA;AAAA,EAC9B;AAEA,SACE,oBAAC,oBAAoB,UAApB,EAA6B,OAC3B,UACH;AAEJ;AAEO,MAAM,kBAAkB,MAAM,WAAW,mBAAmB;","names":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "preact/jsx-runtime";
|
|
3
|
+
import { MessageKey } from "@intlayer/editor";
|
|
4
|
+
import {
|
|
5
|
+
createContext,
|
|
6
|
+
useContext
|
|
7
|
+
} from "preact/compat";
|
|
8
|
+
import { useCrossFrameState } from "./useCrossFrameState.mjs";
|
|
9
|
+
const ConfigurationStatesContext = createContext(
|
|
10
|
+
void 0
|
|
11
|
+
);
|
|
12
|
+
const useConfigurationState = () => useCrossFrameState(
|
|
13
|
+
MessageKey.INTLAYER_CONFIGURATION,
|
|
14
|
+
void 0,
|
|
15
|
+
{
|
|
16
|
+
receive: false,
|
|
17
|
+
emit: true
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
const ConfigurationProvider = ({ children, configuration }) => /* @__PURE__ */ jsx(ConfigurationStatesContext.Provider, { value: configuration, children });
|
|
21
|
+
const useConfiguration = () => useContext(ConfigurationStatesContext);
|
|
22
|
+
export {
|
|
23
|
+
ConfigurationProvider,
|
|
24
|
+
useConfiguration,
|
|
25
|
+
useConfigurationState
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=ConfigurationContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport { type IntlayerConfig } from '@intlayer/config/client';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n type FC,\n type PropsWithChildren,\n createContext,\n useContext,\n} from 'preact/compat';\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: FC<\n PropsWithChildren<ConfigurationProviderProps>\n> = ({ children, configuration }) => (\n <ConfigurationStatesContext.Provider value={configuration}>\n {children}\n </ConfigurationStatesContext.Provider>\n);\n\nexport const useConfiguration = () => useContext(ConfigurationStatesContext);\n"],"mappings":";AAiCE;AA9BF,SAAS,kBAAkB;AAC3B;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA0B;AAEnC,MAAM,6BAA6B;AAAA,EACjC;AACF;AAEO,MAAM,wBAAwB,MACnC;AAAA,EACE,WAAW;AAAA,EACX;AAAA,EACA;AAAA,IACE,SAAS;AAAA,IACT,MAAM;AAAA,EACR;AACF;AAMK,MAAM,wBAET,CAAC,EAAE,UAAU,cAAc,MAC7B,oBAAC,2BAA2B,UAA3B,EAAoC,OAAO,eACzC,UACH;AAGK,MAAM,mBAAmB,MAAM,WAAW,0BAA0B;","names":[]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "preact/jsx-runtime";
|
|
3
|
+
import { isSameKeyPath } from "@intlayer/core";
|
|
4
|
+
import {
|
|
5
|
+
useCallback,
|
|
6
|
+
useMemo
|
|
7
|
+
} from "preact/compat";
|
|
8
|
+
import { useIntlayerContext } from "../client/index.mjs";
|
|
9
|
+
import { ContentSelector } from "../UI/ContentSelector.mjs";
|
|
10
|
+
import { useEditorEnabled } from "./EditorEnabledContext.mjs";
|
|
11
|
+
import { useFocusDictionary } from "./FocusDictionaryContext.mjs";
|
|
12
|
+
const ContentSelectorWrapperContent = ({
|
|
13
|
+
children,
|
|
14
|
+
dictionaryKey,
|
|
15
|
+
keyPath
|
|
16
|
+
}) => {
|
|
17
|
+
const { focusedContent, setFocusedContent } = useFocusDictionary();
|
|
18
|
+
const handleSelect = useCallback(
|
|
19
|
+
() => setFocusedContent({
|
|
20
|
+
dictionaryKey,
|
|
21
|
+
keyPath
|
|
22
|
+
}),
|
|
23
|
+
[dictionaryKey, keyPath]
|
|
24
|
+
);
|
|
25
|
+
const isSelected = useMemo(
|
|
26
|
+
() => (focusedContent?.dictionaryKey === dictionaryKey && (focusedContent?.keyPath?.length ?? 0) > 0 && isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ?? false,
|
|
27
|
+
[focusedContent, keyPath, dictionaryKey]
|
|
28
|
+
);
|
|
29
|
+
return /* @__PURE__ */ jsx(ContentSelector, { onPress: handleSelect, isSelecting: isSelected, children });
|
|
30
|
+
};
|
|
31
|
+
const ContentSelectorRenderer = ({
|
|
32
|
+
children,
|
|
33
|
+
...props
|
|
34
|
+
}) => {
|
|
35
|
+
const { enabled } = useEditorEnabled();
|
|
36
|
+
const { disableEditor } = useIntlayerContext();
|
|
37
|
+
if (enabled && !disableEditor) {
|
|
38
|
+
return /* @__PURE__ */ jsx(ContentSelectorWrapperContent, { ...props, children });
|
|
39
|
+
}
|
|
40
|
+
return children;
|
|
41
|
+
};
|
|
42
|
+
export {
|
|
43
|
+
ContentSelectorRenderer
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=ContentSelectorWrapper.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport { type NodeProps, isSameKeyPath } from '@intlayer/core';\nimport {\n type FC,\n type HTMLAttributes,\n useCallback,\n useMemo,\n} from 'preact/compat';\nimport { useIntlayerContext } from '../client';\nimport { ContentSelector } from '../UI/ContentSelector';\nimport { useEditorEnabled } from './EditorEnabledContext';\nimport { useFocusDictionary } from './FocusDictionaryContext';\n\nexport type ContentSelectorWrapperProps = NodeProps &\n Omit<HTMLAttributes<HTMLDivElement>, 'children'>;\n\nconst ContentSelectorWrapperContent: FC<ContentSelectorWrapperProps> = ({\n children,\n dictionaryKey,\n keyPath,\n}) => {\n const { focusedContent, setFocusedContent } = useFocusDictionary();\n\n const handleSelect = useCallback(\n () =>\n setFocusedContent({\n dictionaryKey,\n keyPath,\n }),\n [dictionaryKey, keyPath]\n );\n\n const isSelected = useMemo(\n () =>\n (focusedContent?.dictionaryKey === dictionaryKey &&\n (focusedContent?.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ??\n false,\n [focusedContent, keyPath, dictionaryKey]\n );\n\n return (\n <ContentSelector onPress={handleSelect} isSelecting={isSelected}>\n {children}\n </ContentSelector>\n );\n};\n\nexport const ContentSelectorRenderer: FC<ContentSelectorWrapperProps> = ({\n children,\n ...props\n}) => {\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":";AA2CI;AAzCJ,SAAyB,qBAAqB;AAC9C;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA0B;AACnC,SAAS,uBAAuB;AAChC,SAAS,wBAAwB;AACjC,SAAS,0BAA0B;AAKnC,MAAM,gCAAiE,CAAC;AAAA,EACtE;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,EAAE,gBAAgB,kBAAkB,IAAI,mBAAmB;AAEjE,QAAM,eAAe;AAAA,IACnB,MACE,kBAAkB;AAAA,MAChB;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,CAAC,eAAe,OAAO;AAAA,EACzB;AAEA,QAAM,aAAa;AAAA,IACjB,OACG,gBAAgB,kBAAkB,kBAChC,gBAAgB,SAAS,UAAU,KAAK,KACzC,cAAc,gBAAgB,WAAW,CAAC,GAAG,OAAO,MACtD;AAAA,IACF,CAAC,gBAAgB,SAAS,aAAa;AAAA,EACzC;AAEA,SACE,oBAAC,mBAAgB,SAAS,cAAc,aAAa,YAClD,UACH;AAEJ;AAEO,MAAM,0BAA2D,CAAC;AAAA,EACvE;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,QAAM,EAAE,cAAc,IAAI,mBAAmB;AAE7C,MAAI,WAAW,CAAC,eAAe;AAC7B,WACE,oBAAC,iCAA+B,GAAG,OAChC,UACH;AAAA,EAEJ;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "preact/jsx-runtime";
|
|
3
|
+
import { MessageKey } from "@intlayer/editor";
|
|
4
|
+
import {
|
|
5
|
+
createContext,
|
|
6
|
+
useContext,
|
|
7
|
+
useMemo
|
|
8
|
+
} from "preact/compat";
|
|
9
|
+
import { useCrossFrameState } from "./useCrossFrameState.mjs";
|
|
10
|
+
const DictionariesRecordStatesContext = createContext(void 0);
|
|
11
|
+
const DictionariesRecordActionsContext = createContext(void 0);
|
|
12
|
+
const DictionariesRecordProvider = ({
|
|
13
|
+
children
|
|
14
|
+
}) => {
|
|
15
|
+
const [localeDictionaries, setLocaleDictionaries] = useCrossFrameState(
|
|
16
|
+
MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED,
|
|
17
|
+
void 0
|
|
18
|
+
);
|
|
19
|
+
const stateValue = useMemo(
|
|
20
|
+
() => ({
|
|
21
|
+
localeDictionaries: localeDictionaries ?? {}
|
|
22
|
+
}),
|
|
23
|
+
[localeDictionaries]
|
|
24
|
+
);
|
|
25
|
+
const actionValue = useMemo(
|
|
26
|
+
() => ({
|
|
27
|
+
setLocaleDictionaries,
|
|
28
|
+
setLocaleDictionary: (dictionary) => {
|
|
29
|
+
setLocaleDictionaries((dictionaries) => ({
|
|
30
|
+
...dictionaries,
|
|
31
|
+
[dictionary.key]: dictionary
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
}),
|
|
35
|
+
[setLocaleDictionaries]
|
|
36
|
+
);
|
|
37
|
+
return /* @__PURE__ */ jsx(DictionariesRecordStatesContext.Provider, { value: stateValue, children: /* @__PURE__ */ jsx(DictionariesRecordActionsContext.Provider, { value: actionValue, children }) });
|
|
38
|
+
};
|
|
39
|
+
const useDictionariesRecordActions = () => useContext(DictionariesRecordActionsContext);
|
|
40
|
+
const useDictionariesRecord = () => {
|
|
41
|
+
const actionsContext = useDictionariesRecordActions();
|
|
42
|
+
const statesContext = useContext(DictionariesRecordStatesContext);
|
|
43
|
+
if (!statesContext) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
"useDictionariesRecordStates must be used within a DictionariesRecordProvider"
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
return { ...statesContext, ...actionsContext };
|
|
49
|
+
};
|
|
50
|
+
export {
|
|
51
|
+
DictionariesRecordProvider,
|
|
52
|
+
useDictionariesRecord,
|
|
53
|
+
useDictionariesRecordActions
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=DictionariesRecordContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport type { Dictionary } from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n useContext,\n useMemo,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n} from 'preact/compat';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport type DictionaryContent = Record<Dictionary['key'], Dictionary>;\n\ntype DictionariesRecordStatesContextType = {\n localeDictionaries: DictionaryContent;\n};\ntype DictionariesRecordActionsContextType = {\n setLocaleDictionaries: Dispatch<SetStateAction<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: FC<PropsWithChildren> = ({\n children,\n}) => {\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 [dictionary.key]: 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":";AA+DM;AA5DN,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AACP,SAAS,0BAA0B;AAYnC,MAAM,kCAAkC,cAEtC,MAAS;AACX,MAAM,mCAAmC,cAEvC,MAAS;AAEJ,MAAM,6BAAoD,CAAC;AAAA,EAChE;AACF,MAAM;AACJ,QAAM,CAAC,oBAAoB,qBAAqB,IAC9C;AAAA,IACE,WAAW;AAAA,IACX;AAAA,EACF;AAEF,QAAM,aAAa;AAAA,IACjB,OAAO;AAAA,MACL,oBAAoB,sBAAsB,CAAC;AAAA,IAC7C;AAAA,IACA,CAAC,kBAAkB;AAAA,EACrB;AAEA,QAAM,cAAc;AAAA,IAClB,OAAO;AAAA,MACL;AAAA,MACA,qBAAqB,CAAC,eAA2B;AAC/C,8BAAsB,CAAC,kBAAkB;AAAA,UACvC,GAAG;AAAA,UACH,CAAC,WAAW,GAAG,GAAG;AAAA,QACpB,EAAE;AAAA,MACJ;AAAA,IACF;AAAA,IACA,CAAC,qBAAqB;AAAA,EACxB;AAEA,SACE,oBAAC,gCAAgC,UAAhC,EAAyC,OAAO,YAC/C,8BAAC,iCAAiC,UAAjC,EAA0C,OAAO,aAC/C,UACH,GACF;AAEJ;AAEO,MAAM,+BAA+B,MAC1C,WAAW,gCAAgC;AAEtC,MAAM,wBAAwB,MAAM;AACzC,QAAM,iBAAiB,6BAA6B;AACpD,QAAM,gBAAgB,WAAW,+BAA+B;AAEhE,MAAI,CAAC,eAAe;AAClB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,eAAe,GAAG,eAAe;AAC/C;","names":[]}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "preact/jsx-runtime";
|
|
3
|
+
import {
|
|
4
|
+
editDictionaryByKeyPath,
|
|
5
|
+
getContentNodeByKeyPath,
|
|
6
|
+
renameContentNodeByKeyPath
|
|
7
|
+
} from "@intlayer/core";
|
|
8
|
+
import { MessageKey } from "@intlayer/editor";
|
|
9
|
+
import {
|
|
10
|
+
createContext,
|
|
11
|
+
useContext
|
|
12
|
+
} from "preact/compat";
|
|
13
|
+
import {
|
|
14
|
+
useDictionariesRecord
|
|
15
|
+
} from "./DictionariesRecordContext.mjs";
|
|
16
|
+
import { useCrossFrameMessageListener } from "./useCrossFrameMessageListener.mjs";
|
|
17
|
+
import { useCrossFrameState } from "./useCrossFrameState.mjs";
|
|
18
|
+
const EditedContentStateContext = createContext(void 0);
|
|
19
|
+
const usePostEditedContentState = (onEventTriggered) => useCrossFrameMessageListener(
|
|
20
|
+
`${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/post`,
|
|
21
|
+
onEventTriggered
|
|
22
|
+
);
|
|
23
|
+
const useGetEditedContentState = (onEventTriggered) => useCrossFrameMessageListener(
|
|
24
|
+
`${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/get`,
|
|
25
|
+
onEventTriggered
|
|
26
|
+
);
|
|
27
|
+
const EditedContentActionsContext = createContext(void 0);
|
|
28
|
+
const resolveState = (state, prevState) => typeof state === "function" ? state(prevState) : state;
|
|
29
|
+
const EditedContentProvider = ({ children }) => {
|
|
30
|
+
const { localeDictionaries } = useDictionariesRecord();
|
|
31
|
+
const [editedContent, setEditedContentState] = useCrossFrameState(
|
|
32
|
+
MessageKey.INTLAYER_EDITED_CONTENT_CHANGED
|
|
33
|
+
);
|
|
34
|
+
const setEditedDictionary = (newValue) => {
|
|
35
|
+
let updatedDictionaries = resolveState(newValue);
|
|
36
|
+
setEditedContentState((prev) => {
|
|
37
|
+
updatedDictionaries = resolveState(
|
|
38
|
+
newValue,
|
|
39
|
+
prev?.[updatedDictionaries.key]
|
|
40
|
+
);
|
|
41
|
+
return {
|
|
42
|
+
...prev,
|
|
43
|
+
[updatedDictionaries.key]: updatedDictionaries
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
return updatedDictionaries;
|
|
47
|
+
};
|
|
48
|
+
const setEditedContent = (dictionaryKey, newValue) => {
|
|
49
|
+
setEditedContentState((prev) => ({
|
|
50
|
+
...prev,
|
|
51
|
+
[dictionaryKey]: {
|
|
52
|
+
...prev?.[dictionaryKey],
|
|
53
|
+
content: newValue
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
56
|
+
};
|
|
57
|
+
const addEditedContent = (dictionaryKey, newValue, keyPath = [], overwrite = true) => {
|
|
58
|
+
setEditedContentState((prev) => {
|
|
59
|
+
const originalContent = localeDictionaries[dictionaryKey]?.content;
|
|
60
|
+
const currentContent = structuredClone(
|
|
61
|
+
prev?.[dictionaryKey]?.content ?? originalContent
|
|
62
|
+
);
|
|
63
|
+
let newKeyPath = keyPath;
|
|
64
|
+
if (!overwrite) {
|
|
65
|
+
let index = 0;
|
|
66
|
+
const otherKeyPath = keyPath.slice(0, -1);
|
|
67
|
+
const lastKeyPath = keyPath[keyPath.length - 1];
|
|
68
|
+
let finalKey = lastKeyPath.key;
|
|
69
|
+
while (typeof getContentNodeByKeyPath(currentContent, newKeyPath) !== "undefined") {
|
|
70
|
+
index++;
|
|
71
|
+
finalKey = index === 0 ? lastKeyPath.key : `${lastKeyPath.key} (${index})`;
|
|
72
|
+
newKeyPath = [
|
|
73
|
+
...otherKeyPath,
|
|
74
|
+
{ ...lastKeyPath, key: finalKey }
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const updatedContent = editDictionaryByKeyPath(
|
|
79
|
+
currentContent,
|
|
80
|
+
newKeyPath,
|
|
81
|
+
newValue
|
|
82
|
+
);
|
|
83
|
+
return {
|
|
84
|
+
...prev,
|
|
85
|
+
[dictionaryKey]: {
|
|
86
|
+
...prev?.[dictionaryKey],
|
|
87
|
+
content: updatedContent
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
const renameEditedContent = (dictionaryKey, newKey, keyPath = []) => {
|
|
93
|
+
setEditedContentState((prev) => {
|
|
94
|
+
const originalContent = localeDictionaries[dictionaryKey]?.content;
|
|
95
|
+
const currentContent = structuredClone(
|
|
96
|
+
prev?.[dictionaryKey]?.content ?? originalContent
|
|
97
|
+
);
|
|
98
|
+
const contentWithNewField = renameContentNodeByKeyPath(
|
|
99
|
+
currentContent,
|
|
100
|
+
newKey,
|
|
101
|
+
keyPath
|
|
102
|
+
);
|
|
103
|
+
return {
|
|
104
|
+
...prev,
|
|
105
|
+
[dictionaryKey]: {
|
|
106
|
+
...prev?.[dictionaryKey],
|
|
107
|
+
content: contentWithNewField
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
const removeEditedContent = (dictionaryKey, keyPath) => {
|
|
113
|
+
setEditedContentState((prev) => {
|
|
114
|
+
const originalContent = localeDictionaries[dictionaryKey]?.content;
|
|
115
|
+
const currentContent = structuredClone(
|
|
116
|
+
prev?.[dictionaryKey]?.content ?? originalContent
|
|
117
|
+
);
|
|
118
|
+
const initialContent = getContentNodeByKeyPath(originalContent, keyPath);
|
|
119
|
+
const restoredContent = editDictionaryByKeyPath(
|
|
120
|
+
currentContent,
|
|
121
|
+
keyPath,
|
|
122
|
+
initialContent
|
|
123
|
+
);
|
|
124
|
+
return {
|
|
125
|
+
...prev,
|
|
126
|
+
[dictionaryKey]: {
|
|
127
|
+
...prev?.[dictionaryKey],
|
|
128
|
+
content: restoredContent
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
const restoreEditedContent = (dictionaryKey) => {
|
|
134
|
+
setEditedContentState((prev) => {
|
|
135
|
+
const updated = { ...prev };
|
|
136
|
+
delete updated[dictionaryKey];
|
|
137
|
+
return updated;
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
const clearEditedDictionaryContent = (dictionaryKey) => {
|
|
141
|
+
setEditedContentState((prev) => {
|
|
142
|
+
const filtered = Object.entries(prev).reduce((acc, [key, value]) => {
|
|
143
|
+
if (key === dictionaryKey) {
|
|
144
|
+
return acc;
|
|
145
|
+
}
|
|
146
|
+
return { ...acc, [key]: value };
|
|
147
|
+
}, {});
|
|
148
|
+
return filtered;
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
const clearEditedContent = () => {
|
|
152
|
+
setEditedContentState({});
|
|
153
|
+
};
|
|
154
|
+
const getEditedContentValue = (dictionaryKey, keyPath) => {
|
|
155
|
+
const currentContent = editedContent?.[dictionaryKey]?.content ?? {};
|
|
156
|
+
return getContentNodeByKeyPath(currentContent, keyPath);
|
|
157
|
+
};
|
|
158
|
+
return /* @__PURE__ */ jsx(
|
|
159
|
+
EditedContentStateContext.Provider,
|
|
160
|
+
{
|
|
161
|
+
value: {
|
|
162
|
+
editedContent
|
|
163
|
+
},
|
|
164
|
+
children: /* @__PURE__ */ jsx(
|
|
165
|
+
EditedContentActionsContext.Provider,
|
|
166
|
+
{
|
|
167
|
+
value: {
|
|
168
|
+
setEditedContentState,
|
|
169
|
+
setEditedDictionary,
|
|
170
|
+
setEditedContent,
|
|
171
|
+
addEditedContent,
|
|
172
|
+
renameEditedContent,
|
|
173
|
+
removeEditedContent,
|
|
174
|
+
restoreEditedContent,
|
|
175
|
+
clearEditedDictionaryContent,
|
|
176
|
+
clearEditedContent,
|
|
177
|
+
getEditedContentValue
|
|
178
|
+
},
|
|
179
|
+
children
|
|
180
|
+
}
|
|
181
|
+
)
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
};
|
|
185
|
+
const useEditedContentActions = () => useContext(EditedContentActionsContext);
|
|
186
|
+
const useEditedContent = () => {
|
|
187
|
+
const stateContext = useContext(EditedContentStateContext);
|
|
188
|
+
const actionContext = useEditedContentActions();
|
|
189
|
+
return { ...stateContext, ...actionContext };
|
|
190
|
+
};
|
|
191
|
+
export {
|
|
192
|
+
EditedContentProvider,
|
|
193
|
+
useEditedContent,
|
|
194
|
+
useEditedContentActions,
|
|
195
|
+
useGetEditedContentState,
|
|
196
|
+
usePostEditedContentState
|
|
197
|
+
};
|
|
198
|
+
//# sourceMappingURL=EditedContentContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n editDictionaryByKeyPath,\n getContentNodeByKeyPath,\n renameContentNodeByKeyPath,\n type ContentNode,\n type Dictionary,\n type KeyPath,\n} from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n useContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n} from 'preact/compat';\nimport {\n useDictionariesRecord,\n type DictionaryContent,\n} from './DictionariesRecordContext';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\nimport { useCrossFrameState } from './useCrossFrameState';\n\ntype EditedContentStateContextType = {\n editedContent: Record<Dictionary['key'], Dictionary> | undefined;\n};\n\nconst EditedContentStateContext = createContext<\n EditedContentStateContextType | undefined\n>(undefined);\n\nexport const usePostEditedContentState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/post`,\n onEventTriggered\n );\n\nexport const useGetEditedContentState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/get`,\n onEventTriggered\n );\n\ntype EditedContentActionsContextType = {\n setEditedContentState: (\n editedContent: Record<Dictionary['key'], Dictionary>\n ) => void;\n setEditedDictionary: Dispatch<SetStateAction<Dictionary>>;\n setEditedContent: (\n dictionaryKey: Dictionary['key'],\n newValue: Dictionary['content']\n ) => void;\n addEditedContent: (\n dictionaryKey: Dictionary['key'],\n newValue: ContentNode<any>,\n keyPath?: KeyPath[],\n overwrite?: boolean\n ) => void;\n renameEditedContent: (\n dictionaryKey: Dictionary['key'],\n newKey: KeyPath['key'],\n keyPath?: KeyPath[]\n ) => void;\n removeEditedContent: (\n dictionaryKey: Dictionary['key'],\n keyPath: KeyPath[]\n ) => void;\n restoreEditedContent: (dictionaryKey: Dictionary['key']) => void;\n clearEditedDictionaryContent: (dictionaryKey: Dictionary['key']) => void;\n clearEditedContent: () => void;\n getEditedContentValue: (\n dictionaryKey: Dictionary['key'],\n keyPath: KeyPath[]\n ) => ContentNode | undefined;\n};\n\nconst EditedContentActionsContext = createContext<\n EditedContentActionsContextType | undefined\n>(undefined);\n\nconst resolveState = <S,>(state?: SetStateAction<S>, prevState?: S): S =>\n typeof state === 'function'\n ? (state as (prevState?: S) => S)(prevState)\n : (state as S);\n\nexport const EditedContentProvider: FC<PropsWithChildren> = ({ children }) => {\n const { localeDictionaries } = useDictionariesRecord();\n\n const [editedContent, setEditedContentState] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_EDITED_CONTENT_CHANGED\n );\n\n const setEditedDictionary: Dispatch<SetStateAction<Dictionary>> = (\n newValue\n ) => {\n let updatedDictionaries: Dictionary = resolveState(newValue);\n\n setEditedContentState((prev) => {\n updatedDictionaries = resolveState(\n newValue,\n prev?.[updatedDictionaries.key]\n );\n\n return {\n ...prev,\n [updatedDictionaries.key]: updatedDictionaries,\n };\n });\n\n return updatedDictionaries;\n };\n\n const setEditedContent = (\n dictionaryKey: Dictionary['key'],\n newValue: Dictionary['content']\n ) => {\n setEditedContentState((prev) => ({\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: newValue,\n },\n }));\n };\n\n const addEditedContent = (\n dictionaryKey: Dictionary['key'],\n newValue: ContentNode,\n keyPath: KeyPath[] = [],\n overwrite: boolean = true\n ) => {\n setEditedContentState((prev) => {\n // Get the starting content: edited version if available, otherwise a deep copy of the original\n const originalContent = localeDictionaries[dictionaryKey]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryKey]?.content ?? originalContent\n );\n\n let newKeyPath = keyPath;\n if (!overwrite) {\n // Find a unique key based on the keyPath provided\n let index = 0;\n const otherKeyPath = keyPath.slice(0, -1);\n const lastKeyPath: KeyPath = keyPath[keyPath.length - 1];\n let finalKey = lastKeyPath.key;\n\n // Loop until we find a key that does not exist\n while (\n typeof getContentNodeByKeyPath(currentContent, newKeyPath) !==\n 'undefined'\n ) {\n index++;\n finalKey =\n index === 0 ? lastKeyPath.key : `${lastKeyPath.key} (${index})`;\n newKeyPath = [\n ...otherKeyPath,\n { ...lastKeyPath, key: finalKey } as KeyPath,\n ];\n }\n }\n\n const updatedContent = editDictionaryByKeyPath(\n currentContent,\n newKeyPath,\n newValue\n );\n\n return {\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: updatedContent as Dictionary['content'],\n },\n };\n });\n };\n\n const renameEditedContent = (\n dictionaryKey: Dictionary['key'],\n newKey: KeyPath['key'],\n keyPath: KeyPath[] = []\n ) => {\n setEditedContentState((prev) => {\n // Retrieve the base content: use edited version if available, otherwise deep copy of original\n const originalContent = localeDictionaries[dictionaryKey]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryKey]?.content ?? originalContent\n );\n\n const contentWithNewField = renameContentNodeByKeyPath(\n currentContent,\n newKey,\n keyPath\n );\n\n return {\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: contentWithNewField as Dictionary['content'],\n },\n };\n });\n };\n\n const removeEditedContent = (\n dictionaryKey: Dictionary['key'],\n keyPath: KeyPath[]\n ) => {\n setEditedContentState((prev) => {\n // Retrieve the original content as reference\n const originalContent = localeDictionaries[dictionaryKey]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryKey]?.content ?? originalContent\n );\n\n // Get the initial value from the original dictionary content\n const initialContent = getContentNodeByKeyPath(originalContent, keyPath);\n\n // Restore the value at the given keyPath\n const restoredContent = editDictionaryByKeyPath(\n currentContent,\n keyPath,\n initialContent\n );\n\n return {\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: restoredContent as Dictionary['content'],\n },\n };\n });\n };\n\n const restoreEditedContent = (dictionaryKey: Dictionary['key']) => {\n setEditedContentState((prev) => {\n const updated = { ...prev };\n delete updated[dictionaryKey];\n return updated;\n });\n };\n\n const clearEditedDictionaryContent = (dictionaryKey: Dictionary['key']) => {\n setEditedContentState((prev) => {\n const filtered = Object.entries(prev).reduce((acc, [key, value]) => {\n if (key === dictionaryKey) {\n return acc;\n }\n return { ...acc, [key]: value };\n }, {} as DictionaryContent);\n return filtered;\n });\n };\n\n const clearEditedContent = () => {\n setEditedContentState({});\n };\n\n const getEditedContentValue = (\n dictionaryKey: Dictionary['key'],\n keyPath: KeyPath[]\n ): ContentNode | undefined => {\n const currentContent = editedContent?.[dictionaryKey]?.content ?? {};\n return getContentNodeByKeyPath(currentContent, keyPath);\n };\n\n return (\n <EditedContentStateContext.Provider\n value={{\n editedContent,\n }}\n >\n <EditedContentActionsContext.Provider\n value={{\n setEditedContentState,\n setEditedDictionary,\n setEditedContent,\n addEditedContent,\n renameEditedContent,\n removeEditedContent,\n restoreEditedContent,\n clearEditedDictionaryContent,\n clearEditedContent,\n getEditedContentValue,\n }}\n >\n {children}\n </EditedContentActionsContext.Provider>\n </EditedContentStateContext.Provider>\n );\n};\n\nexport const useEditedContentActions = () =>\n useContext(EditedContentActionsContext);\n\nexport const useEditedContent = () => {\n const stateContext = useContext(EditedContentStateContext);\n const actionContext = useEditedContentActions();\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "preact/jsx-runtime";
|
|
3
|
+
import { MessageKey } from "@intlayer/editor";
|
|
4
|
+
import {
|
|
5
|
+
createContext,
|
|
6
|
+
useContext
|
|
7
|
+
} from "preact/compat";
|
|
8
|
+
import { useCrossFrameMessageListener } from "./useCrossFrameMessageListener.mjs";
|
|
9
|
+
import {
|
|
10
|
+
useCrossFrameState
|
|
11
|
+
} from "./useCrossFrameState.mjs";
|
|
12
|
+
const EditorEnabledContext = createContext({
|
|
13
|
+
enabled: false
|
|
14
|
+
});
|
|
15
|
+
const useEditorEnabledState = (options) => useCrossFrameState(MessageKey.INTLAYER_EDITOR_ENABLED, false, options);
|
|
16
|
+
const usePostEditorEnabledState = (onEventTriggered) => useCrossFrameMessageListener(
|
|
17
|
+
`${MessageKey.INTLAYER_EDITOR_ENABLED}/post`,
|
|
18
|
+
onEventTriggered
|
|
19
|
+
);
|
|
20
|
+
const useGetEditorEnabledState = (onEventTriggered) => useCrossFrameMessageListener(
|
|
21
|
+
`${MessageKey.INTLAYER_EDITOR_ENABLED}/get`,
|
|
22
|
+
onEventTriggered
|
|
23
|
+
);
|
|
24
|
+
const EditorEnabledProvider = ({ children }) => {
|
|
25
|
+
const [isEnabled] = useEditorEnabledState({
|
|
26
|
+
emit: false,
|
|
27
|
+
receive: true
|
|
28
|
+
});
|
|
29
|
+
return /* @__PURE__ */ jsx(EditorEnabledContext.Provider, { value: { enabled: isEnabled }, children });
|
|
30
|
+
};
|
|
31
|
+
const useEditorEnabled = () => useContext(EditorEnabledContext);
|
|
32
|
+
export {
|
|
33
|
+
EditorEnabledProvider,
|
|
34
|
+
useEditorEnabled,
|
|
35
|
+
useEditorEnabledState,
|
|
36
|
+
useGetEditorEnabledState,
|
|
37
|
+
usePostEditorEnabledState
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=EditorEnabledContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/EditorEnabledContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n useContext,\n type FC,\n type PropsWithChildren,\n} from 'preact/compat';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\nimport {\n useCrossFrameState,\n type CrossFrameStateOptions,\n} from './useCrossFrameState';\n\nexport type EditorEnabledStateProps = {\n enabled: boolean;\n};\n\nconst EditorEnabledContext = createContext<EditorEnabledStateProps>({\n enabled: false,\n});\n\nexport const useEditorEnabledState = (options?: CrossFrameStateOptions) =>\n useCrossFrameState(MessageKey.INTLAYER_EDITOR_ENABLED, false, options);\n\nexport const usePostEditorEnabledState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITOR_ENABLED}/post`,\n onEventTriggered\n );\n\nexport const useGetEditorEnabledState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITOR_ENABLED}/get`,\n onEventTriggered\n );\n\nexport const EditorEnabledProvider: FC<PropsWithChildren> = ({ children }) => {\n const [isEnabled] = useEditorEnabledState({\n emit: false,\n receive: true,\n });\n\n return (\n <EditorEnabledContext.Provider value={{ enabled: isEnabled }}>\n {children}\n </EditorEnabledContext.Provider>\n );\n};\n\nexport const useEditorEnabled = () => useContext(EditorEnabledContext);\n"],"mappings":";AAiDI;AA/CJ,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,oCAAoC;AAC7C;AAAA,EACE;AAAA,OAEK;AAMP,MAAM,uBAAuB,cAAuC;AAAA,EAClE,SAAS;AACX,CAAC;AAEM,MAAM,wBAAwB,CAAC,YACpC,mBAAmB,WAAW,yBAAyB,OAAO,OAAO;AAEhE,MAAM,4BAA4B,CACvC,qBAEA;AAAA,EACE,GAAG,WAAW,uBAAuB;AAAA,EACrC;AACF;AAEK,MAAM,2BAA2B,CACtC,qBAEA;AAAA,EACE,GAAG,WAAW,uBAAuB;AAAA,EACrC;AACF;AAEK,MAAM,wBAA+C,CAAC,EAAE,SAAS,MAAM;AAC5E,QAAM,CAAC,SAAS,IAAI,sBAAsB;AAAA,IACxC,MAAM;AAAA,IACN,SAAS;AAAA,EACX,CAAC;AAED,SACE,oBAAC,qBAAqB,UAArB,EAA8B,OAAO,EAAE,SAAS,UAAU,GACxD,UACH;AAEJ;AAEO,MAAM,mBAAmB,MAAM,WAAW,oBAAoB;","names":[]}
|