preact-intlayer 8.3.2 → 8.3.4
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/UI/ContentSelector.cjs +1 -1
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
- package/dist/cjs/client/IntlayerProvider.cjs +1 -1
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/format/useCompact.cjs +1 -1
- package/dist/cjs/client/format/useCompact.cjs.map +1 -1
- package/dist/cjs/client/format/useCurrency.cjs +1 -1
- package/dist/cjs/client/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/client/format/useDate.cjs +1 -1
- package/dist/cjs/client/format/useDate.cjs.map +1 -1
- package/dist/cjs/client/format/useList.cjs +1 -1
- package/dist/cjs/client/format/useList.cjs.map +1 -1
- package/dist/cjs/client/format/useNumber.cjs +1 -1
- package/dist/cjs/client/format/useNumber.cjs.map +1 -1
- package/dist/cjs/client/format/usePercentage.cjs +1 -1
- package/dist/cjs/client/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/client/format/useRelativeTime.cjs +1 -1
- package/dist/cjs/client/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/client/format/useUnit.cjs +1 -1
- package/dist/cjs/client/format/useUnit.cjs.map +1 -1
- package/dist/cjs/client/t.cjs +1 -1
- package/dist/cjs/client/t.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +1 -1
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +1 -1
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +1 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleBase.cjs +1 -1
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
- package/dist/cjs/editor/CommunicatorContext.cjs +1 -1
- package/dist/cjs/editor/CommunicatorContext.cjs.map +1 -1
- package/dist/cjs/editor/ConfigurationContext.cjs +1 -1
- package/dist/cjs/editor/ConfigurationContext.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelectorWrapper.cjs +1 -1
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/editor/DictionariesRecordContext.cjs +1 -1
- package/dist/cjs/editor/DictionariesRecordContext.cjs.map +1 -1
- package/dist/cjs/editor/EditedContentContext.cjs +1 -1
- package/dist/cjs/editor/EditedContentContext.cjs.map +1 -1
- package/dist/cjs/editor/EditorEnabledContext.cjs +1 -1
- package/dist/cjs/editor/EditorEnabledContext.cjs.map +1 -1
- package/dist/cjs/editor/EditorProvider.cjs +1 -1
- package/dist/cjs/editor/EditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/EditorStateContext.cjs +2 -0
- package/dist/cjs/editor/EditorStateContext.cjs.map +1 -0
- package/dist/cjs/editor/FocusDictionaryContext.cjs +1 -1
- package/dist/cjs/editor/FocusDictionaryContext.cjs.map +1 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs +1 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/index.cjs +1 -1
- package/dist/cjs/editor/useCrossFrameMessageListener.cjs +1 -1
- package/dist/cjs/editor/useCrossFrameMessageListener.cjs.map +1 -1
- package/dist/cjs/editor/useCrossFrameState.cjs +1 -1
- package/dist/cjs/editor/useCrossFrameState.cjs.map +1 -1
- package/dist/cjs/editor/useCrossURLPathState.cjs +1 -1
- package/dist/cjs/editor/useCrossURLPathState.cjs.map +1 -1
- package/dist/cjs/editor/useEditedContentRenderer.cjs +1 -1
- package/dist/cjs/editor/useEditedContentRenderer.cjs.map +1 -1
- package/dist/cjs/editor/useIframeClickInterceptor.cjs +1 -1
- package/dist/cjs/editor/useIframeClickInterceptor.cjs.map +1 -1
- package/dist/cjs/html/HTMLProvider.cjs +1 -1
- package/dist/cjs/html/HTMLProvider.cjs.map +1 -1
- package/dist/esm/UI/ContentSelector.mjs +1 -1
- package/dist/esm/UI/ContentSelector.mjs.map +1 -1
- package/dist/esm/client/IntlayerProvider.mjs +1 -1
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/format/useCompact.mjs +1 -1
- package/dist/esm/client/format/useCompact.mjs.map +1 -1
- package/dist/esm/client/format/useCurrency.mjs +1 -1
- package/dist/esm/client/format/useCurrency.mjs.map +1 -1
- package/dist/esm/client/format/useDate.mjs +1 -1
- package/dist/esm/client/format/useDate.mjs.map +1 -1
- package/dist/esm/client/format/useList.mjs +1 -1
- package/dist/esm/client/format/useList.mjs.map +1 -1
- package/dist/esm/client/format/useNumber.mjs +1 -1
- package/dist/esm/client/format/useNumber.mjs.map +1 -1
- package/dist/esm/client/format/usePercentage.mjs +1 -1
- package/dist/esm/client/format/usePercentage.mjs.map +1 -1
- package/dist/esm/client/format/useRelativeTime.mjs +1 -1
- package/dist/esm/client/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/client/format/useUnit.mjs +1 -1
- package/dist/esm/client/format/useUnit.mjs.map +1 -1
- package/dist/esm/client/t.mjs +1 -1
- package/dist/esm/client/t.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +1 -1
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +1 -1
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +1 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.mjs +1 -1
- package/dist/esm/client/useLocaleBase.mjs.map +1 -1
- package/dist/esm/editor/CommunicatorContext.mjs +1 -1
- package/dist/esm/editor/CommunicatorContext.mjs.map +1 -1
- package/dist/esm/editor/ConfigurationContext.mjs +1 -1
- package/dist/esm/editor/ConfigurationContext.mjs.map +1 -1
- package/dist/esm/editor/ContentSelectorWrapper.mjs +1 -1
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/editor/DictionariesRecordContext.mjs +1 -1
- package/dist/esm/editor/DictionariesRecordContext.mjs.map +1 -1
- package/dist/esm/editor/EditedContentContext.mjs +1 -1
- package/dist/esm/editor/EditedContentContext.mjs.map +1 -1
- package/dist/esm/editor/EditorEnabledContext.mjs +1 -1
- package/dist/esm/editor/EditorEnabledContext.mjs.map +1 -1
- package/dist/esm/editor/EditorProvider.mjs +1 -1
- package/dist/esm/editor/EditorProvider.mjs.map +1 -1
- package/dist/esm/editor/EditorStateContext.mjs +2 -0
- package/dist/esm/editor/EditorStateContext.mjs.map +1 -0
- package/dist/esm/editor/FocusDictionaryContext.mjs +1 -1
- package/dist/esm/editor/FocusDictionaryContext.mjs.map +1 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs +1 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
- package/dist/esm/editor/index.mjs +1 -1
- package/dist/esm/editor/useCrossFrameMessageListener.mjs +1 -1
- package/dist/esm/editor/useCrossFrameMessageListener.mjs.map +1 -1
- package/dist/esm/editor/useCrossFrameState.mjs +1 -1
- package/dist/esm/editor/useCrossFrameState.mjs.map +1 -1
- package/dist/esm/editor/useCrossURLPathState.mjs +1 -1
- package/dist/esm/editor/useCrossURLPathState.mjs.map +1 -1
- package/dist/esm/editor/useEditedContentRenderer.mjs +1 -1
- package/dist/esm/editor/useEditedContentRenderer.mjs.map +1 -1
- package/dist/esm/editor/useIframeClickInterceptor.mjs +1 -1
- package/dist/esm/editor/useIframeClickInterceptor.mjs.map +1 -1
- package/dist/esm/html/HTMLProvider.mjs +1 -1
- package/dist/esm/html/HTMLProvider.mjs.map +1 -1
- package/dist/types/UI/ContentSelector.d.ts.map +1 -1
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -1
- package/dist/types/client/format/useCompact.d.ts.map +1 -1
- package/dist/types/client/format/useCurrency.d.ts.map +1 -1
- package/dist/types/client/format/useDate.d.ts.map +1 -1
- package/dist/types/client/format/useList.d.ts.map +1 -1
- package/dist/types/client/format/useNumber.d.ts.map +1 -1
- package/dist/types/client/format/usePercentage.d.ts.map +1 -1
- package/dist/types/client/format/useRelativeTime.d.ts.map +1 -1
- package/dist/types/client/format/useUnit.d.ts.map +1 -1
- package/dist/types/client/t.d.ts.map +1 -1
- package/dist/types/client/useDictionary.d.ts.map +1 -1
- package/dist/types/client/useDictionaryAsync.d.ts.map +1 -1
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/client/useIntlayer.d.ts.map +1 -1
- package/dist/types/client/useLocale.d.ts.map +1 -1
- package/dist/types/client/useLocaleBase.d.ts.map +1 -1
- package/dist/types/editor/CommunicatorContext.d.ts +4 -10
- package/dist/types/editor/CommunicatorContext.d.ts.map +1 -1
- package/dist/types/editor/ConfigurationContext.d.ts +2 -6
- package/dist/types/editor/ConfigurationContext.d.ts.map +1 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
- package/dist/types/editor/DictionariesRecordContext.d.ts +7 -11
- package/dist/types/editor/DictionariesRecordContext.d.ts.map +1 -1
- package/dist/types/editor/EditedContentContext.d.ts +25 -28
- package/dist/types/editor/EditedContentContext.d.ts.map +1 -1
- package/dist/types/editor/EditorEnabledContext.d.ts +4 -8
- package/dist/types/editor/EditorEnabledContext.d.ts.map +1 -1
- package/dist/types/editor/EditorProvider.d.ts +18 -6
- package/dist/types/editor/EditorProvider.d.ts.map +1 -1
- package/dist/types/editor/EditorStateContext.d.ts +12 -0
- package/dist/types/editor/EditorStateContext.d.ts.map +1 -0
- package/dist/types/editor/FocusDictionaryContext.d.ts +7 -16
- package/dist/types/editor/FocusDictionaryContext.d.ts.map +1 -1
- package/dist/types/editor/IntlayerEditorProvider.d.ts.map +1 -1
- package/dist/types/editor/index.d.ts +2 -1
- package/dist/types/editor/useCrossFrameMessageListener.d.ts +0 -16
- package/dist/types/editor/useCrossFrameMessageListener.d.ts.map +1 -1
- package/dist/types/editor/useCrossFrameState.d.ts +0 -21
- package/dist/types/editor/useCrossFrameState.d.ts.map +1 -1
- package/dist/types/editor/useCrossURLPathState.d.ts +2 -4
- package/dist/types/editor/useCrossURLPathState.d.ts.map +1 -1
- package/dist/types/editor/useEditedContentRenderer.d.ts.map +1 -1
- package/dist/types/editor/useIframeClickInterceptor.d.ts +1 -1
- package/dist/types/editor/useIframeClickInterceptor.d.ts.map +1 -1
- package/dist/types/html/HTMLProvider.d.ts.map +1 -1
- package/package.json +8 -9
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{IntlayerClientContext as e}from"./IntlayerProvider.mjs";import{useDictionary as t}from"./useDictionary.mjs";import n from"@intlayer/config/built";import{useContext as r,useMemo as i}from"preact/hooks";const a=async(a,o)=>{let{locale:s}=r(e),c=i(()=>o??s??n?.internationalization.defaultLocale,[s,o]);return t(await i(async()=>await a[c]?.(),[a,c]),c)};export{a as useDictionaryAsync};
|
|
2
2
|
//# sourceMappingURL=useDictionaryAsync.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryAsync.mjs","names":[],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.mjs","names":[],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryAsync = async <T extends Dictionary>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: LocalesValues\n): Promise<T> => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n const localeTarget = useMemo(\n () =>\n locale ??\n currentLocale ??\n configuration?.internationalization.defaultLocale,\n [currentLocale, locale]\n );\n\n const dictionary = await useMemo(\n async () =>\n (await dictionaryPromise[\n localeTarget as keyof typeof dictionaryPromise\n ]?.()) as T,\n [dictionaryPromise, localeTarget]\n );\n\n return useDictionary(dictionary, localeTarget) as any;\n};\n"],"mappings":"gNAeA,MAAa,EAAqB,MAChC,EACA,IACe,CACf,GAAM,CAAE,OAAQ,GAAkB,EAAW,EAAsB,CAE7D,EAAe,MAEjB,GACA,GACA,GAAe,qBAAqB,cACtC,CAAC,EAAe,EAAO,CACxB,CAUD,OAAO,EARY,MAAM,EACvB,SACG,MAAM,EACL,MACG,CACP,CAAC,EAAmB,EAAa,CAClC,CAEgC,EAAa"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{IntlayerClientContext as e}from"./IntlayerProvider.mjs";import{useDictionary as t}from"./useDictionary.mjs";import{useLoadDynamic as n}from"./useLoadDynamic.mjs";import{useContext as r,useMemo as i}from"preact/hooks";const a=(a,o,s)=>{let{locale:c}=r(e),l=i(()=>s??c,[c,s]);return t(n(`${String(o)}.${l}`,a[l]?.()),l)};export{a as useDictionaryDynamic};
|
|
2
2
|
//# sourceMappingURL=useDictionaryDynamic.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.mjs","names":[],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.mjs","names":[],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n K extends DictionaryKeys,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = useMemo(\n () => locale ?? currentLocale,\n [currentLocale, locale]\n );\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget}`,\n (dictionaryPromise as any)[localeTarget]?.()\n ) as T;\n\n return useDictionary(dictionary, localeTarget);\n};\n"],"mappings":"gOAgBA,MAAa,GAIX,EACA,EACA,IACG,CACH,GAAM,CAAE,OAAQ,GAAkB,EAAW,EAAsB,CAC7D,EAAe,MACb,GAAU,EAChB,CAAC,EAAe,EAAO,CACxB,CAOD,OAAO,EALY,EACjB,GAAG,OAAO,EAAI,CAAC,GAAG,IACjB,EAA0B,MAAiB,CAC7C,CAEgC,EAAa"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{IntlayerClientContext as e}from"./IntlayerProvider.mjs";import{getIntlayer as t}from"../getIntlayer.mjs";import{useContext as n,useMemo as r}from"preact/hooks";const i=(i,a)=>{let{locale:o}=n(e);return r(()=>t(i,a??o),[i,o,a])};export{i as useIntlayer};
|
|
2
2
|
//# sourceMappingURL=useIntlayer.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import type {\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Preact hook that picks one dictionary by its key and returns its content.\n *\n * If the locale is not provided, it will use the locale from the client context.\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param locale - Optional locale to override the current context locale.\n * @returns The transformed dictionary content.\n *\n * @example\n * ```tsx\n * import { useIntlayer } from 'preact-intlayer';\n *\n * const MyComponent = () => {\n * const content = useIntlayer('my-dictionary-key');\n *\n * return <div>{content.myField.value}</div>;\n * };\n * ```\n */\nexport const useIntlayer = <T extends DictionaryKeys, L extends LocalesValues>(\n key: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? currentLocale;\n\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n return getIntlayer<T, L>(key, localeTarget as L) as DeepTransformContent<\n DictionaryRegistryContent<T>\n >;\n }, [key, currentLocale, locale]);\n};\n"],"mappings":"uKA8BA,MAAa,GACX,EACA,IACG,CACH,GAAM,CAAE,OAAQ,GAAkB,EAAW,EAAsB,CAEnE,OAAO,MAIE,EAAkB,EAHJ,GAAU,EAGiB,CAG/C,CAAC,EAAK,EAAe,EAAO,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{setLocaleInStorage as e}from"./useLocaleStorage.mjs";import{IntlayerClientContext as t}from"./IntlayerProvider.mjs";import n from"@intlayer/config/built";import{useContext as r}from"preact/hooks";const i=({isCookieEnabled:i,onLocaleChange:a}={})=>{let{defaultLocale:o,locales:s}=n?.internationalization??{},{locale:c,setLocale:l,isCookieEnabled:u}=r(t);return{locale:c,defaultLocale:o,availableLocales:s,setLocale:t=>{if(!s?.map(String).includes(t)){console.error(`Locale ${t} is not available`);return}l(t),e(t,i??u??!0),a?.(t)}}};export{i as useLocale};
|
|
2
2
|
//# sourceMappingURL=useLocale.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.mjs","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"useLocale.mjs","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype useLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: LocalesValues) => void;\n};\n\n/**\n * Preact hook to get the current locale and related locale management functions.\n *\n * @param props - Optional properties for the hook.\n * @returns An object containing the current locale, default locale, available locales, and a function to update the locale.\n *\n * @example\n * ```tsx\n * import { useLocale } from 'preact-intlayer';\n *\n * const LocaleSwitcher = () => {\n * const { locale, setLocale, availableLocales } = useLocale();\n *\n * return (\n * <select value={locale} onChange={(e) => setLocale(e.target.value)}>\n * {availableLocales.map((loc) => (\n * <option key={loc} value={loc}>{loc}</option>\n * ))}\n * </select>\n * );\n * };\n * ```\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: useLocaleProps = {}) => {\n const { defaultLocale, locales: availableLocales } =\n configuration?.internationalization ?? {};\n\n const {\n locale,\n setLocale: setLocaleState,\n isCookieEnabled: isCookieEnabledContext,\n } = useContext(IntlayerClientContext);\n\n const setLocale = (locale: LocalesValues) => {\n if (!availableLocales?.map(String).includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n\n setLocaleInStorage(\n locale,\n isCookieEnabled ?? isCookieEnabledContext ?? true\n );\n\n onLocaleChange?.(locale);\n };\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":"2MAkCA,MAAa,GAAa,CACxB,kBACA,kBACkB,EAAE,GAAK,CACzB,GAAM,CAAE,gBAAe,QAAS,GAC9B,GAAe,sBAAwB,EAAE,CAErC,CACJ,SACA,UAAW,EACX,gBAAiB,GACf,EAAW,EAAsB,CAkBrC,MAAO,CACL,SACA,gBACA,mBACA,UApBiB,GAA0B,CAC3C,GAAI,CAAC,GAAkB,IAAI,OAAO,CAAC,SAAS,EAAO,CAAE,CACnD,QAAQ,MAAM,UAAU,EAAO,mBAAmB,CAClD,OAGF,EAAe,EAAO,CAEtB,EACE,EACA,GAAmB,GAA0B,GAC9C,CAED,IAAiB,EAAO,EAQzB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{IntlayerClientContext as e}from"./IntlayerProvider.mjs";import t from"@intlayer/config/built";import{useContext as n}from"preact/hooks";const{defaultLocale:r,locales:i}=t.internationalization,a=()=>{let{locale:t,setLocale:a}=n(e);return{locale:t,defaultLocale:r,availableLocales:i,setLocale:a}};export{a as useLocaleBase};
|
|
2
2
|
//# sourceMappingURL=useLocaleBase.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleBase.mjs","names":[],"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"useLocaleBase.mjs","names":[],"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["import 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":"+IAIA,KAAM,CAAE,gBAAe,QAAS,GAC9B,EAAc,qBAKH,MAAsB,CACjC,GAAM,CAAE,SAAQ,aAAc,EAAW,EAAsB,CAE/D,MAAO,CACL,SACA,gBACA,mBACA,YACD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{useEditorStateManager as e}from"./EditorStateContext.mjs";const t=()=>{let t=e();return{postMessage:e=>t.messenger.send(e.type,e.data),senderId:t.messenger.senderId}};export{t as useCommunicator};
|
|
2
2
|
//# sourceMappingURL=CommunicatorContext.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommunicatorContext.mjs","names":[],"sources":["../../../src/editor/CommunicatorContext.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"CommunicatorContext.mjs","names":[],"sources":["../../../src/editor/CommunicatorContext.tsx"],"sourcesContent":["import { useEditorStateManager } from './EditorStateContext';\n\nexport const useCommunicator = () => {\n const manager = useEditorStateManager();\n return {\n postMessage: (data: any) => manager.messenger.send(data.type, data.data),\n senderId: manager.messenger.senderId,\n };\n};\n\n// Backward-compat types\nexport type CommunicatorProviderProps = {\n postMessage?: (data: any) => void;\n allowedOrigins?: string[];\n};\n"],"mappings":"iEAEA,MAAa,MAAwB,CACnC,IAAM,EAAU,GAAuB,CACvC,MAAO,CACL,YAAc,GAAc,EAAQ,UAAU,KAAK,EAAK,KAAM,EAAK,KAAK,CACxE,SAAU,EAAQ,UAAU,SAC7B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{useEditorStateManager as e}from"./EditorStateContext.mjs";import{useEffect as t,useState as n}from"preact/hooks";const r=()=>{let r=e(),[i,a]=n(r.configuration.value);return t(()=>{let e=e=>a(e.detail);return r.configuration.addEventListener(`change`,e),()=>r.configuration.removeEventListener(`change`,e)},[r]),i};export{r as useConfiguration};
|
|
2
2
|
//# sourceMappingURL=ConfigurationContext.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigurationContext.mjs","names":[],"sources":["../../../src/editor/ConfigurationContext.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"ConfigurationContext.mjs","names":[],"sources":["../../../src/editor/ConfigurationContext.tsx"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/types/config';\nimport { useEffect, useState } from 'preact/hooks';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport const useConfiguration = (): IntlayerConfig | undefined => {\n const manager = useEditorStateManager();\n const [config, setConfig] = useState<IntlayerConfig | undefined>(\n manager.configuration.value\n );\n\n useEffect(() => {\n const handler = (e: Event) =>\n setConfig((e as CustomEvent<IntlayerConfig>).detail);\n manager.configuration.addEventListener('change', handler);\n return () => manager.configuration.removeEventListener('change', handler);\n }, [manager]);\n\n return config;\n};\n\nexport type ConfigurationProviderProps = { configuration?: IntlayerConfig };\n"],"mappings":"wHAIA,MAAa,MAAqD,CAChE,IAAM,EAAU,GAAuB,CACjC,CAAC,EAAQ,GAAa,EAC1B,EAAQ,cAAc,MACvB,CASD,OAPA,MAAgB,CACd,IAAM,EAAW,GACf,EAAW,EAAkC,OAAO,CAEtD,OADA,EAAQ,cAAc,iBAAiB,SAAU,EAAQ,KAC5C,EAAQ,cAAc,oBAAoB,SAAU,EAAQ,EACxE,CAAC,EAAQ,CAAC,CAEN"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{useEditorStateManager as e}from"./EditorStateContext.mjs";import{useEditorEnabled as t}from"./EditorEnabledContext.mjs";import{useIntlayerContext as n}from"../client/IntlayerProvider.mjs";import{useFocusDictionary as r}from"./FocusDictionaryContext.mjs";import{NodeType as i}from"@intlayer/types/nodeType";import{isSameKeyPath as a}from"@intlayer/core/utils";import{MessageKey as o,defineIntlayerElements as s}from"@intlayer/editor";import{useEffect as c,useRef as l}from"preact/hooks";import{jsx as u}from"preact/jsx-runtime";const d=({children:t,dictionaryKey:n,keyPath:s})=>{let{focusedContent:d,setFocusedContent:f}=r(),p=e(),m=l(null),h=s.filter(e=>e.type!==i.Translation),g=(d?.dictionaryKey===n&&(d?.keyPath?.length??0)>0&&a(d?.keyPath??[],h))??!1;return c(()=>{let e=m.current;if(!e)return;let t=()=>{f({dictionaryKey:n,keyPath:h})},r=()=>{p.messenger.send(`${o.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,{dictionaryKey:n,keyPath:h})},i=()=>{p.messenger.send(`${o.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,null)};return e.addEventListener(`intlayer:press`,t),e.addEventListener(`intlayer:hover`,r),e.addEventListener(`intlayer:unhover`,i),()=>{e.removeEventListener(`intlayer:press`,t),e.removeEventListener(`intlayer:hover`,r),e.removeEventListener(`intlayer:unhover`,i)}}),u(`intlayer-content-selector`,{ref:m,"is-selecting":g||void 0,children:t})},f=({children:e,...r})=>{let{enabled:i}=t(),{disableEditor:a}=n();return c(()=>{s()},[]),i&&!a?u(d,{...r,children:e}):e};export{f as ContentSelectorRenderer};
|
|
2
2
|
//# sourceMappingURL=ContentSelectorWrapper.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSelectorWrapper.mjs","names":[],"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"ContentSelectorWrapper.mjs","names":[],"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["import type { NodeProps } from '@intlayer/core/interpreter';\nimport { isSameKeyPath } from '@intlayer/core/utils';\nimport { defineIntlayerElements, MessageKey } from '@intlayer/editor';\nimport { NodeType } from '@intlayer/types/nodeType';\nimport type { FunctionalComponent, JSX } from 'preact';\nimport { useEffect, useRef } from 'preact/hooks';\nimport { useIntlayerContext } from '../client';\nimport { useEditorEnabled } from './EditorEnabledContext';\nimport { useEditorStateManager } from './EditorStateContext';\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 manager = useEditorStateManager();\n const ref = useRef<HTMLElement>(null);\n\n const filteredKeyPath = keyPath.filter(\n (key) => key.type !== NodeType.Translation\n );\n\n const isSelected =\n (focusedContent?.dictionaryKey === dictionaryKey &&\n (focusedContent?.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent?.keyPath ?? [], filteredKeyPath)) ??\n false;\n\n // Preact (like React 18) requires addEventListener for web component custom events\n useEffect(() => {\n const el = ref.current;\n if (!el) return;\n\n const handlePress = () => {\n setFocusedContent({ dictionaryKey, keyPath: filteredKeyPath });\n };\n\n const handleHover = () => {\n manager.messenger.send(\n `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n { dictionaryKey, keyPath: filteredKeyPath }\n );\n };\n\n const handleUnhover = () => {\n manager.messenger.send(\n `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n null\n );\n };\n\n el.addEventListener('intlayer:press', handlePress);\n el.addEventListener('intlayer:hover', handleHover);\n el.addEventListener('intlayer:unhover', handleUnhover);\n return () => {\n el.removeEventListener('intlayer:press', handlePress);\n el.removeEventListener('intlayer:hover', handleHover);\n el.removeEventListener('intlayer:unhover', handleUnhover);\n };\n });\n\n return (\n // @ts-ignore — custom element typing\n <intlayer-content-selector ref={ref} is-selecting={isSelected || undefined}>\n {children}\n </intlayer-content-selector>\n );\n};\n\nexport const ContentSelectorRenderer: FunctionalComponent<\n ContentSelectorWrapperProps\n> = ({ children, ...props }) => {\n const { enabled } = useEditorEnabled();\n const { disableEditor } = useIntlayerContext();\n\n useEffect(() => {\n defineIntlayerElements();\n }, []);\n\n if (enabled && !disableEditor) {\n return (\n <ContentSelectorWrapperContent {...props}>\n {children}\n </ContentSelectorWrapperContent>\n );\n }\n\n return children;\n};\n"],"mappings":"shBAcA,MAAM,GAED,CAAE,WAAU,gBAAe,aAAc,CAC5C,GAAM,CAAE,iBAAgB,qBAAsB,GAAoB,CAC5D,EAAU,GAAuB,CACjC,EAAM,EAAoB,KAAK,CAE/B,EAAkB,EAAQ,OAC7B,GAAQ,EAAI,OAAS,EAAS,YAChC,CAEK,GACH,GAAgB,gBAAkB,IAChC,GAAgB,SAAS,QAAU,GAAK,GACzC,EAAc,GAAgB,SAAW,EAAE,CAAE,EAAgB,GAC/D,GAmCF,OAhCA,MAAgB,CACd,IAAM,EAAK,EAAI,QACf,GAAI,CAAC,EAAI,OAET,IAAM,MAAoB,CACxB,EAAkB,CAAE,gBAAe,QAAS,EAAiB,CAAC,EAG1D,MAAoB,CACxB,EAAQ,UAAU,KAChB,GAAG,EAAW,iCAAiC,OAC/C,CAAE,gBAAe,QAAS,EAAiB,CAC5C,EAGG,MAAsB,CAC1B,EAAQ,UAAU,KAChB,GAAG,EAAW,iCAAiC,OAC/C,KACD,EAMH,OAHA,EAAG,iBAAiB,iBAAkB,EAAY,CAClD,EAAG,iBAAiB,iBAAkB,EAAY,CAClD,EAAG,iBAAiB,mBAAoB,EAAc,KACzC,CACX,EAAG,oBAAoB,iBAAkB,EAAY,CACrD,EAAG,oBAAoB,iBAAkB,EAAY,CACrD,EAAG,oBAAoB,mBAAoB,EAAc,GAE3D,CAIA,EAAC,4BAAD,CAAgC,MAAK,eAAc,GAAc,IAAA,GAC9D,WACyB,CAAA,EAInB,GAER,CAAE,WAAU,GAAG,KAAY,CAC9B,GAAM,CAAE,WAAY,GAAkB,CAChC,CAAE,iBAAkB,GAAoB,CAc9C,OAZA,MAAgB,CACd,GAAwB,EACvB,EAAE,CAAC,CAEF,GAAW,CAAC,EAEZ,EAAC,EAAD,CAA+B,GAAI,EAChC,WAC6B,CAAA,CAI7B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{useEditorStateManager as e}from"./EditorStateContext.mjs";import{useEffect as t,useState as n}from"preact/hooks";const r=()=>{let r=e(),[i,a]=n(r.localeDictionaries.value??{});return t(()=>{let e=e=>a(e.detail??{});return r.localeDictionaries.addEventListener(`change`,e),()=>r.localeDictionaries.removeEventListener(`change`,e)},[r]),{localeDictionaries:i,setLocaleDictionaries:e=>r.localeDictionaries.set(e),setLocaleDictionary:e=>r.setLocaleDictionary(e)}},i=()=>{let{setLocaleDictionaries:e,setLocaleDictionary:t}=r();return{setLocaleDictionaries:e,setLocaleDictionary:t}};export{r as useDictionariesRecord,i as useDictionariesRecordActions};
|
|
2
2
|
//# sourceMappingURL=DictionariesRecordContext.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DictionariesRecordContext.mjs","names":[],"sources":["../../../src/editor/DictionariesRecordContext.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"DictionariesRecordContext.mjs","names":[],"sources":["../../../src/editor/DictionariesRecordContext.tsx"],"sourcesContent":["import type { DictionaryContent } from '@intlayer/editor';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { useEffect, useState } from 'preact/hooks';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type { DictionaryContent };\n\nexport const useDictionariesRecord = () => {\n const manager = useEditorStateManager();\n const [localeDictionaries, setLocaleDictionariesState] =\n useState<DictionaryContent>(manager.localeDictionaries.value ?? {});\n\n useEffect(() => {\n const handler = (e: Event) =>\n setLocaleDictionariesState(\n (e as CustomEvent<DictionaryContent>).detail ?? {}\n );\n manager.localeDictionaries.addEventListener('change', handler);\n return () =>\n manager.localeDictionaries.removeEventListener('change', handler);\n }, [manager]);\n\n return {\n localeDictionaries,\n setLocaleDictionaries: (value: DictionaryContent) =>\n manager.localeDictionaries.set(value),\n setLocaleDictionary: (dictionary: Dictionary) =>\n manager.setLocaleDictionary(dictionary),\n };\n};\n\nexport const useDictionariesRecordActions = () => {\n const { setLocaleDictionaries, setLocaleDictionary } =\n useDictionariesRecord();\n return { setLocaleDictionaries, setLocaleDictionary };\n};\n"],"mappings":"wHAOA,MAAa,MAA8B,CACzC,IAAM,EAAU,GAAuB,CACjC,CAAC,EAAoB,GACzB,EAA4B,EAAQ,mBAAmB,OAAS,EAAE,CAAC,CAYrE,OAVA,MAAgB,CACd,IAAM,EAAW,GACf,EACG,EAAqC,QAAU,EAAE,CACnD,CAEH,OADA,EAAQ,mBAAmB,iBAAiB,SAAU,EAAQ,KAE5D,EAAQ,mBAAmB,oBAAoB,SAAU,EAAQ,EAClE,CAAC,EAAQ,CAAC,CAEN,CACL,qBACA,sBAAwB,GACtB,EAAQ,mBAAmB,IAAI,EAAM,CACvC,oBAAsB,GACpB,EAAQ,oBAAoB,EAAW,CAC1C,EAGU,MAAqC,CAChD,GAAM,CAAE,wBAAuB,uBAC7B,GAAuB,CACzB,MAAO,CAAE,wBAAuB,sBAAqB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{useEditorStateManager as e}from"./EditorStateContext.mjs";import{useEffect as t,useState as n}from"preact/hooks";const r=()=>{let r=e(),[i,a]=n(r.editedContent.value);return t(()=>{let e=e=>a(e.detail);return r.editedContent.addEventListener(`change`,e),()=>r.editedContent.removeEventListener(`change`,e)},[r]),{editedContent:i,setEditedContentState:e=>r.editedContent.set(e),setEditedDictionary:e=>r.setEditedDictionary(e),setEditedContent:(e,t)=>r.setEditedContent(e,t),addEditedContent:(e,t,n,i)=>r.addContent(e,t,n,i),renameEditedContent:(e,t,n)=>r.renameContent(e,t,n),removeEditedContent:(e,t)=>r.removeContent(e,t),restoreEditedContent:e=>r.restoreContent(e),clearEditedDictionaryContent:e=>r.clearContent(e),clearEditedContent:()=>r.clearAllContent(),getEditedContentValue:(e,t)=>r.getContentValue(e,t)}},i=()=>{let{editedContent:e,...t}=r();return t},a=()=>{let t=e();return()=>t.messenger.send(`INTLAYER_EDITED_CONTENT_CHANGED/get`)},o=()=>{let t=e();return()=>t.editedContent.postCurrentValue()};export{r as useEditedContent,i as useEditedContentActions,a as useGetEditedContentState,o as usePostEditedContentState};
|
|
2
2
|
//# sourceMappingURL=EditedContentContext.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditedContentContext.mjs","names":[],"sources":["../../../src/editor/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n editDictionaryByKeyPath,\n getContentNodeByKeyPath,\n renameContentNodeByKeyPath,\n} from '@intlayer/core/dictionaryManipulator';\nimport { MessageKey } from '@intlayer/editor';\nimport type {\n ContentNode,\n Dictionary,\n LocalDictionaryId,\n} from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { NodeType } from '@intlayer/types/nodeType';\nimport {\n createContext,\n type FunctionalComponent,\n type RenderableProps,\n} from 'preact';\nimport { useContext } from 'preact/hooks';\nimport {\n type DictionaryContent,\n useDictionariesRecord,\n} from './DictionariesRecordContext';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\nimport {\n type CrossFrameStateUpdater,\n useCrossFrameState,\n} from './useCrossFrameState';\n\ntype EditedContentStateContextType = {\n editedContent: Record<LocalDictionaryId, 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<LocalDictionaryId, Dictionary>\n ) => void;\n setEditedDictionary: CrossFrameStateUpdater<Dictionary>;\n setEditedContent: (\n dictionaryLocalId: LocalDictionaryId,\n newValue: Dictionary['content']\n ) => void;\n addEditedContent: (\n dictionaryLocalId: LocalDictionaryId,\n newValue: ContentNode<any>,\n keyPath?: KeyPath[],\n overwrite?: boolean\n ) => void;\n renameEditedContent: (\n dictionaryLocalId: LocalDictionaryId,\n newKey: KeyPath['key'],\n keyPath?: KeyPath[]\n ) => void;\n removeEditedContent: (\n dictionaryLocalId: LocalDictionaryId,\n keyPath: KeyPath[]\n ) => void;\n restoreEditedContent: (dictionaryLocalId: LocalDictionaryId) => void;\n clearEditedDictionaryContent: (dictionaryLocalId: LocalDictionaryId) => void;\n clearEditedContent: () => void;\n getEditedContentValue: (\n localDictionaryIdOrKey: LocalDictionaryId | Dictionary['key'] | string,\n keyPath: KeyPath[]\n ) => ContentNode | undefined;\n};\n\nconst EditedContentActionsContext = createContext<\n EditedContentActionsContextType | undefined\n>(undefined);\n\nconst resolveState = <S,>(\n state?: S | ((prevState: S) => S),\n prevState?: S\n): S =>\n typeof state === 'function'\n ? (state as (prevState?: S) => S)(prevState)\n : (state as S);\n\nexport const EditedContentProvider: FunctionalComponent<\n RenderableProps<{}>\n> = ({ children }) => {\n const { localeDictionaries } = useDictionariesRecord();\n\n const [editedContent, setEditedContentState] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_EDITED_CONTENT_CHANGED\n );\n\n const setEditedDictionary: CrossFrameStateUpdater<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\n const setEditedContent = (\n dictionaryLocalId: LocalDictionaryId,\n newValue: Dictionary['content']\n ) => {\n setEditedContentState((prev) => ({\n ...prev,\n [dictionaryLocalId]: {\n ...prev?.[dictionaryLocalId],\n content: newValue,\n },\n }));\n };\n\n const addEditedContent = (\n dictionaryLocalId: LocalDictionaryId,\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[dictionaryLocalId]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryLocalId]?.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 [dictionaryLocalId]: {\n ...prev?.[dictionaryLocalId],\n content: updatedContent as Dictionary['content'],\n },\n };\n });\n };\n\n const renameEditedContent = (\n dictionaryLocalId: LocalDictionaryId,\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[dictionaryLocalId]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryLocalId]?.content ?? originalContent\n );\n\n const contentWithNewField = renameContentNodeByKeyPath(\n currentContent,\n newKey,\n keyPath\n );\n\n return {\n ...prev,\n [dictionaryLocalId]: {\n ...prev?.[dictionaryLocalId],\n content: contentWithNewField as Dictionary['content'],\n },\n };\n });\n };\n\n const removeEditedContent = (\n dictionaryLocalId: LocalDictionaryId,\n keyPath: KeyPath[]\n ) => {\n setEditedContentState((prev) => {\n // Retrieve the original content as reference\n const originalContent = localeDictionaries[dictionaryLocalId]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryLocalId]?.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 [dictionaryLocalId]: {\n ...prev?.[dictionaryLocalId],\n content: restoredContent as Dictionary['content'],\n },\n };\n });\n };\n\n const restoreEditedContent = (dictionaryLocalId: LocalDictionaryId) => {\n setEditedContentState((prev) => {\n const updated = { ...prev };\n delete updated[dictionaryLocalId];\n return updated;\n });\n };\n\n const clearEditedDictionaryContent = (\n dictionaryLocalId: LocalDictionaryId\n ) => {\n setEditedContentState((prev) => {\n const filtered = { ...prev };\n delete filtered[dictionaryLocalId];\n return filtered;\n });\n };\n\n const clearEditedContent = () => {\n setEditedContentState({});\n };\n\n const getEditedContentValue = (\n localDictionaryIdOrKey: LocalDictionaryId | Dictionary['key'] | string,\n keyPath: KeyPath[]\n ): ContentNode | undefined => {\n if (!editedContent) return undefined;\n\n const filteredKeyPath = keyPath.filter(\n (key) => key.type !== NodeType.Translation\n );\n\n const isDictionaryId =\n localDictionaryIdOrKey.includes(':local:') ||\n localDictionaryIdOrKey.includes(':remote:');\n\n if (isDictionaryId) {\n const currentContent =\n editedContent?.[localDictionaryIdOrKey as LocalDictionaryId]?.content ??\n {};\n\n const contentNode = getContentNodeByKeyPath(\n currentContent,\n filteredKeyPath\n );\n\n return contentNode;\n }\n\n const filteredDictionariesLocalId = Object.keys(editedContent).filter(\n (key) => key.startsWith(`${localDictionaryIdOrKey}:`)\n );\n\n for (const localDictionaryId of filteredDictionariesLocalId) {\n const currentContent =\n editedContent?.[localDictionaryId as LocalDictionaryId]?.content ?? {};\n const contentNode = getContentNodeByKeyPath(\n currentContent,\n filteredKeyPath\n );\n\n if (contentNode) return contentNode;\n }\n\n return undefined;\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":"6kBAmCA,MAAM,EAA4B,EAEhC,IAAA,GAAU,CAEC,EACX,GAEA,EACE,GAAG,EAAW,gCAAgC,OAC9C,EACD,CAEU,EACX,GAEA,EACE,GAAG,EAAW,gCAAgC,MAC9C,EACD,CAmCG,EAA8B,EAElC,IAAA,GAAU,CAEN,GACJ,EACA,IAEA,OAAO,GAAU,WACZ,EAA+B,EAAU,CACzC,EAEM,GAER,CAAE,cAAe,CACpB,GAAM,CAAE,sBAAuB,GAAuB,CAEhD,CAAC,EAAe,GACpB,EACE,EAAW,gCACZ,CAmNH,OACE,EAAC,EAA0B,SAA3B,CACE,MAAO,CACL,gBACD,UAED,EAAC,EAA4B,SAA7B,CACE,MAAO,CACL,wBACA,oBAzNN,GACG,CACH,IAAI,EAAkC,EAAa,EAAS,CAE5D,EAAuB,IACrB,EAAsB,EACpB,EACA,IAAO,EAAoB,KAC5B,CAEM,CACL,GAAG,GACF,EAAoB,KAAM,EAC5B,EACD,EA4MI,kBAxMN,EACA,IACG,CACH,EAAuB,IAAU,CAC/B,GAAG,GACF,GAAoB,CACnB,GAAG,IAAO,GACV,QAAS,EACV,CACF,EAAE,EAgMG,kBA5LN,EACA,EACA,EAAqB,EAAE,CACvB,EAAqB,KAClB,CACH,EAAuB,GAAS,CAE9B,IAAM,EAAkB,EAAmB,IAAoB,QACzD,EAAiB,gBACrB,IAAO,IAAoB,SAAW,EACvC,CAEG,EAAa,EACjB,GAAI,CAAC,EAAW,CAEd,IAAI,EAAQ,EACN,EAAe,EAAQ,MAAM,EAAG,GAAG,CACnC,EAAuB,EAAQ,EAAQ,OAAS,GAClD,EAAW,EAAY,IAG3B,KACS,EAAwB,EAAgB,EAAW,GAC1D,QAEA,IACA,EACE,IAAU,EAAI,EAAY,IAAM,GAAG,EAAY,IAAI,IAAI,EAAM,GAC/D,EAAa,CACX,GAAG,EACH,CAAE,GAAG,EAAa,IAAK,EAAU,CAClC,CAIL,IAAM,EAAiB,EACrB,EACA,EACA,EACD,CAED,MAAO,CACL,GAAG,GACF,GAAoB,CACnB,GAAG,IAAO,GACV,QAAS,EACV,CACF,EACD,EA6II,qBAzIN,EACA,EACA,EAAqB,EAAE,GACpB,CACH,EAAuB,GAAS,CAE9B,IAAM,EAAkB,EAAmB,IAAoB,QAKzD,EAAsB,EAJL,gBACrB,IAAO,IAAoB,SAAW,EACvC,CAIC,EACA,EACD,CAED,MAAO,CACL,GAAG,GACF,GAAoB,CACnB,GAAG,IAAO,GACV,QAAS,EACV,CACF,EACD,EAkHI,qBA9GN,EACA,IACG,CACH,EAAuB,GAAS,CAE9B,IAAM,EAAkB,EAAmB,IAAoB,QASzD,EAAkB,EARD,gBACrB,IAAO,IAAoB,SAAW,EACvC,CAQC,EALqB,EAAwB,EAAiB,EAAQ,CAOvE,CAED,MAAO,CACL,GAAG,GACF,GAAoB,CACnB,GAAG,IAAO,GACV,QAAS,EACV,CACF,EACD,EAoFI,qBAjFsB,GAAyC,CACrE,EAAuB,GAAS,CAC9B,IAAM,EAAU,CAAE,GAAG,EAAM,CAE3B,OADA,OAAO,EAAQ,GACR,GACP,EA6EI,6BAzEN,GACG,CACH,EAAuB,GAAS,CAC9B,IAAM,EAAW,CAAE,GAAG,EAAM,CAE5B,OADA,OAAO,EAAS,GACT,GACP,EAoEI,uBAjEyB,CAC/B,EAAsB,EAAE,CAAC,EAiEnB,uBA7DN,EACA,IAC4B,CAC5B,GAAI,CAAC,EAAe,OAEpB,IAAM,EAAkB,EAAQ,OAC7B,GAAQ,EAAI,OAAS,EAAS,YAChC,CAMD,GAHE,EAAuB,SAAS,UAAU,EAC1C,EAAuB,SAAS,WAAW,CAY3C,OALoB,EAHlB,IAAgB,IAA8C,SAC9D,EAAE,CAIF,EACD,CAKH,IAAM,EAA8B,OAAO,KAAK,EAAc,CAAC,OAC5D,GAAQ,EAAI,WAAW,GAAG,EAAuB,GAAG,CACtD,CAED,IAAK,IAAM,KAAqB,EAA6B,CAG3D,IAAM,EAAc,EADlB,IAAgB,IAAyC,SAAW,EAAE,CAGtE,EACD,CAED,GAAI,EAAa,OAAO,IAwBrB,CAEA,WACoC,CAAA,CACJ,CAAA,EAI5B,MACX,EAAW,EAA4B,CAE5B,MAAyB,CACpC,IAAM,EAAe,EAAW,EAA0B,CACpD,EAAgB,GAAyB,CAE/C,MAAO,CAAE,GAAG,EAAc,GAAG,EAAe"}
|
|
1
|
+
{"version":3,"file":"EditedContentContext.mjs","names":[],"sources":["../../../src/editor/EditedContentContext.tsx"],"sourcesContent":["import type { DictionaryContent } from '@intlayer/editor';\nimport type {\n ContentNode,\n Dictionary,\n LocalDictionaryId,\n} from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { useEffect, useState } from 'preact/hooks';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport const useEditedContent = () => {\n const manager = useEditorStateManager();\n const [editedContent, setEditedContentState] = useState<\n DictionaryContent | undefined\n >(manager.editedContent.value);\n\n useEffect(() => {\n const handler = (e: Event) =>\n setEditedContentState((e as CustomEvent<DictionaryContent>).detail);\n manager.editedContent.addEventListener('change', handler);\n return () => manager.editedContent.removeEventListener('change', handler);\n }, [manager]);\n\n return {\n editedContent,\n setEditedContentState: (value: DictionaryContent) =>\n manager.editedContent.set(value),\n setEditedDictionary: (dict: Dictionary) =>\n manager.setEditedDictionary(dict),\n setEditedContent: (\n localId: LocalDictionaryId,\n value: Dictionary['content']\n ) => manager.setEditedContent(localId, value),\n addEditedContent: (\n localId: LocalDictionaryId,\n value: ContentNode,\n keyPath?: KeyPath[],\n overwrite?: boolean\n ) => manager.addContent(localId, value, keyPath, overwrite),\n renameEditedContent: (\n localId: LocalDictionaryId,\n newKey: KeyPath['key'],\n keyPath?: KeyPath[]\n ) => manager.renameContent(localId, newKey, keyPath),\n removeEditedContent: (localId: LocalDictionaryId, keyPath: KeyPath[]) =>\n manager.removeContent(localId, keyPath),\n restoreEditedContent: (localId: LocalDictionaryId) =>\n manager.restoreContent(localId),\n clearEditedDictionaryContent: (localId: LocalDictionaryId) =>\n manager.clearContent(localId),\n clearEditedContent: () => manager.clearAllContent(),\n getEditedContentValue: (\n localIdOrKey: LocalDictionaryId | string,\n keyPath: KeyPath[]\n ): ContentNode | undefined =>\n manager.getContentValue(localIdOrKey, keyPath),\n };\n};\n\nexport const useEditedContentActions = () => {\n const actions = useEditedContent();\n const { editedContent, ...rest } = actions;\n return rest;\n};\n\nexport const useGetEditedContentState = () => {\n const manager = useEditorStateManager();\n return () => manager.messenger.send('INTLAYER_EDITED_CONTENT_CHANGED/get');\n};\n\nexport const usePostEditedContentState = () => {\n const manager = useEditorStateManager();\n return () => manager.editedContent.postCurrentValue();\n};\n"],"mappings":"wHAUA,MAAa,MAAyB,CACpC,IAAM,EAAU,GAAuB,CACjC,CAAC,EAAe,GAAyB,EAE7C,EAAQ,cAAc,MAAM,CAS9B,OAPA,MAAgB,CACd,IAAM,EAAW,GACf,EAAuB,EAAqC,OAAO,CAErE,OADA,EAAQ,cAAc,iBAAiB,SAAU,EAAQ,KAC5C,EAAQ,cAAc,oBAAoB,SAAU,EAAQ,EACxE,CAAC,EAAQ,CAAC,CAEN,CACL,gBACA,sBAAwB,GACtB,EAAQ,cAAc,IAAI,EAAM,CAClC,oBAAsB,GACpB,EAAQ,oBAAoB,EAAK,CACnC,kBACE,EACA,IACG,EAAQ,iBAAiB,EAAS,EAAM,CAC7C,kBACE,EACA,EACA,EACA,IACG,EAAQ,WAAW,EAAS,EAAO,EAAS,EAAU,CAC3D,qBACE,EACA,EACA,IACG,EAAQ,cAAc,EAAS,EAAQ,EAAQ,CACpD,qBAAsB,EAA4B,IAChD,EAAQ,cAAc,EAAS,EAAQ,CACzC,qBAAuB,GACrB,EAAQ,eAAe,EAAQ,CACjC,6BAA+B,GAC7B,EAAQ,aAAa,EAAQ,CAC/B,uBAA0B,EAAQ,iBAAiB,CACnD,uBACE,EACA,IAEA,EAAQ,gBAAgB,EAAc,EAAQ,CACjD,EAGU,MAAgC,CAE3C,GAAM,CAAE,gBAAe,GAAG,GADV,GAAkB,CAElC,OAAO,GAGI,MAAiC,CAC5C,IAAM,EAAU,GAAuB,CACvC,UAAa,EAAQ,UAAU,KAAK,sCAAsC,EAG/D,MAAkC,CAC7C,IAAM,EAAU,GAAuB,CACvC,UAAa,EAAQ,cAAc,kBAAkB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{useEditorStateManager as e}from"./EditorStateContext.mjs";import{MessageKey as t}from"@intlayer/editor";import{useEffect as n,useState as r}from"preact/hooks";const i=()=>{let t=e(),[i,a]=r(t.editorEnabled.value??!1);return n(()=>{let e=e=>a(e.detail);return t.editorEnabled.addEventListener(`change`,e),()=>t.editorEnabled.removeEventListener(`change`,e)},[t]),{enabled:i}},a=()=>{let{enabled:t}=i(),n=e();return[t,e=>n.editorEnabled.set(e)]},o=()=>{let n=e();return()=>{n.messenger.send(`${t.INTLAYER_EDITOR_ENABLED}/get`)}},s=()=>{let t=e();return()=>t.editorEnabled.postCurrentValue()};export{i as useEditorEnabled,a as useEditorEnabledState,o as useGetEditorEnabledState,s as usePostEditorEnabledState};
|
|
2
2
|
//# sourceMappingURL=EditorEnabledContext.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorEnabledContext.mjs","names":[],"sources":["../../../src/editor/EditorEnabledContext.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"EditorEnabledContext.mjs","names":[],"sources":["../../../src/editor/EditorEnabledContext.tsx"],"sourcesContent":["import { MessageKey } from '@intlayer/editor';\nimport { useEffect, useState } from 'preact/hooks';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type EditorEnabledStateProps = {\n enabled: boolean;\n};\n\nexport const useEditorEnabled = (): EditorEnabledStateProps => {\n const manager = useEditorStateManager();\n const [enabled, setEnabled] = useState<boolean>(\n manager.editorEnabled.value ?? false\n );\n\n useEffect(() => {\n const handler = (e: Event) =>\n setEnabled((e as CustomEvent<boolean>).detail);\n manager.editorEnabled.addEventListener('change', handler);\n return () => manager.editorEnabled.removeEventListener('change', handler);\n }, [manager]);\n\n return { enabled };\n};\n\nexport const useEditorEnabledState = () => {\n const { enabled } = useEditorEnabled();\n const manager = useEditorStateManager();\n return [\n enabled,\n (value: boolean) => manager.editorEnabled.set(value),\n ] as const;\n};\n\nexport const useGetEditorEnabledState = () => {\n const manager = useEditorStateManager();\n return () => {\n manager.messenger.send(`${MessageKey.INTLAYER_EDITOR_ENABLED}/get`);\n };\n};\n\nexport const usePostEditorEnabledState = () => {\n const manager = useEditorStateManager();\n return () => manager.editorEnabled.postCurrentValue();\n};\n"],"mappings":"sKAQA,MAAa,MAAkD,CAC7D,IAAM,EAAU,GAAuB,CACjC,CAAC,EAAS,GAAc,EAC5B,EAAQ,cAAc,OAAS,GAChC,CASD,OAPA,MAAgB,CACd,IAAM,EAAW,GACf,EAAY,EAA2B,OAAO,CAEhD,OADA,EAAQ,cAAc,iBAAiB,SAAU,EAAQ,KAC5C,EAAQ,cAAc,oBAAoB,SAAU,EAAQ,EACxE,CAAC,EAAQ,CAAC,CAEN,CAAE,UAAS,EAGP,MAA8B,CACzC,GAAM,CAAE,WAAY,GAAkB,CAChC,EAAU,GAAuB,CACvC,MAAO,CACL,EACC,GAAmB,EAAQ,cAAc,IAAI,EAAM,CACrD,EAGU,MAAiC,CAC5C,IAAM,EAAU,GAAuB,CACvC,UAAa,CACX,EAAQ,UAAU,KAAK,GAAG,EAAW,wBAAwB,MAAM,GAI1D,MAAkC,CAC7C,IAAM,EAAU,GAAuB,CACvC,UAAa,EAAQ,cAAc,kBAAkB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{EditorStateProvider as e}from"./EditorStateContext.mjs";import{useEditorEnabled as t}from"./EditorEnabledContext.mjs";import n from"@intlayer/config/built";import{EditorStateManager as r,defineIntlayerElements as i}from"@intlayer/editor";import{useEffect as a,useRef as o,useState as s}from"preact/hooks";import{jsx as c}from"preact/jsx-runtime";const{editor:l}=n??{},u=()=>({allowedOrigins:[l?.applicationURL,l?.editorURL,l?.cmsURL].filter(Boolean),postMessageFn:(e,t)=>{typeof window>`u`||window.self!==window.top&&(window.parent?.postMessage(e,t),window.postMessage(e,t))}}),d=({children:e,fallback:n})=>{let{enabled:r}=t();return r?e:n},f=({children:e,fallback:t})=>{let[n,r]=s(!1);return a(()=>{r(window.self!==window.top)},[]),n?e:t},p=({children:t,mode:s=`client`,configuration:l,postMessage:p,allowedOrigins:m})=>{let h=o(null);h.current||=new r({mode:s,messenger:p||m?{allowedOrigins:m??[`*`],postMessageFn:p?e=>p(e):u().postMessageFn}:u(),configuration:l??n});let g=h.current;return a(()=>(i(),g.start(),()=>g.stop()),[g]),c(e,{manager:g,children:s===`editor`?t:c(f,{fallback:t,children:c(d,{fallback:t,children:t})})})};export{p as EditorProvider};
|
|
2
2
|
//# sourceMappingURL=EditorProvider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorProvider.mjs","names":[],"sources":["../../../src/editor/EditorProvider.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"EditorProvider.mjs","names":[],"sources":["../../../src/editor/EditorProvider.tsx"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {\n defineIntlayerElements,\n EditorStateManager,\n type MessengerConfig,\n} from '@intlayer/editor';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { ComponentChildren, FunctionComponent } from 'preact';\nimport { useEffect, useRef, useState } from 'preact/hooks';\nimport { useEditorEnabled } from './EditorEnabledContext';\nimport { EditorStateProvider } from './EditorStateContext';\n\nconst { editor } = configuration ?? {};\n\nconst buildDefaultMessengerConfig = (): MessengerConfig => ({\n allowedOrigins: [\n editor?.applicationURL,\n editor?.editorURL,\n editor?.cmsURL,\n ].filter(Boolean) as string[],\n postMessageFn: (payload, origin) => {\n if (typeof window === 'undefined') return;\n const isInIframe = window.self !== window.top;\n if (!isInIframe) return;\n window.parent?.postMessage(payload, origin);\n window.postMessage(payload, origin);\n },\n});\n\ntype FallbackProps = {\n fallback: ComponentChildren;\n children?: ComponentChildren;\n};\n\nconst EditorEnabledCheckRenderer: FunctionComponent<FallbackProps> = ({\n children,\n fallback,\n}) => {\n const { enabled } = useEditorEnabled();\n return enabled ? children : fallback;\n};\n\nconst IframeCheckRenderer: FunctionComponent<FallbackProps> = ({\n children,\n fallback,\n}) => {\n const [isInIframe, setIsInIframe] = useState(false);\n\n useEffect(() => {\n setIsInIframe(window.self !== window.top);\n }, []);\n\n return isInIframe ? children : fallback;\n};\n\nexport type EditorProviderProps = {\n mode?: 'editor' | 'client';\n configuration?: IntlayerConfig;\n postMessage?: (data: any) => void;\n allowedOrigins?: string[];\n children?: ComponentChildren;\n};\n\nexport const EditorProvider: FunctionComponent<EditorProviderProps> = ({\n children,\n mode = 'client',\n configuration: configProp,\n postMessage: customPostMessage,\n allowedOrigins: customAllowedOrigins,\n}) => {\n const managerRef = useRef<EditorStateManager | null>(null);\n if (!managerRef.current) {\n const messengerConfig: MessengerConfig =\n customPostMessage || customAllowedOrigins\n ? {\n allowedOrigins: customAllowedOrigins ?? ['*'],\n postMessageFn: customPostMessage\n ? (payload) => customPostMessage(payload)\n : buildDefaultMessengerConfig().postMessageFn,\n }\n : buildDefaultMessengerConfig();\n managerRef.current = new EditorStateManager({\n mode,\n messenger: messengerConfig,\n configuration: configProp ?? configuration,\n });\n }\n const manager = managerRef.current;\n\n useEffect(() => {\n defineIntlayerElements();\n manager.start();\n return () => manager.stop();\n }, [manager]);\n\n const content =\n mode === 'editor' ? (\n children\n ) : (\n <IframeCheckRenderer fallback={children}>\n <EditorEnabledCheckRenderer fallback={children}>\n {children}\n </EditorEnabledCheckRenderer>\n </IframeCheckRenderer>\n );\n\n return <EditorStateProvider manager={manager}>{content}</EditorStateProvider>;\n};\n\n// Backward-compat types\nexport type CommunicatorProviderProps = {\n postMessage?: (data: any) => void;\n allowedOrigins?: string[];\n};\nexport type ConfigurationProviderProps = { configuration?: IntlayerConfig };\n"],"mappings":"iWAYA,KAAM,CAAE,UAAW,GAAiB,EAAE,CAEhC,OAAsD,CAC1D,eAAgB,CACd,GAAQ,eACR,GAAQ,UACR,GAAQ,OACT,CAAC,OAAO,QAAQ,CACjB,eAAgB,EAAS,IAAW,CAC9B,OAAO,OAAW,KACH,OAAO,OAAS,OAAO,MAE1C,OAAO,QAAQ,YAAY,EAAS,EAAO,CAC3C,OAAO,YAAY,EAAS,EAAO,GAEtC,EAOK,GAAgE,CACpE,WACA,cACI,CACJ,GAAM,CAAE,WAAY,GAAkB,CACtC,OAAO,EAAU,EAAW,GAGxB,GAAyD,CAC7D,WACA,cACI,CACJ,GAAM,CAAC,EAAY,GAAiB,EAAS,GAAM,CAMnD,OAJA,MAAgB,CACd,EAAc,OAAO,OAAS,OAAO,IAAI,EACxC,EAAE,CAAC,CAEC,EAAa,EAAW,GAWpB,GAA0D,CACrE,WACA,OAAO,SACP,cAAe,EACf,YAAa,EACb,eAAgB,KACZ,CACJ,IAAM,EAAa,EAAkC,KAAK,CAC1D,AAUE,EAAW,UAAU,IAAI,EAAmB,CAC1C,OACA,UAVA,GAAqB,EACjB,CACE,eAAgB,GAAwB,CAAC,IAAI,CAC7C,cAAe,EACV,GAAY,EAAkB,EAAQ,CACvC,GAA6B,CAAC,cACnC,CACD,GAA6B,CAIjC,cAAe,GAAc,EAC9B,CAAC,CAEJ,IAAM,EAAU,EAAW,QAmB3B,OAjBA,OACE,GAAwB,CACxB,EAAQ,OAAO,KACF,EAAQ,MAAM,EAC1B,CAAC,EAAQ,CAAC,CAaN,EAAC,EAAD,CAA8B,mBAVnC,IAAS,SACP,EAEA,EAAC,EAAD,CAAqB,SAAU,WAC7B,EAAC,EAAD,CAA4B,SAAU,EACnC,WAC0B,CAAA,CACT,CAAA,CAGmD,CAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createContext as e}from"preact";import{useContext as t}from"preact/hooks";import{jsx as n}from"preact/jsx-runtime";const r=e(null),i=({manager:e,children:t})=>n(r.Provider,{value:e,children:t}),a=()=>{let e=t(r);if(!e)throw Error(`useEditorStateManager: no EditorStateProvider found`);return e};export{i as EditorStateProvider,a as useEditorStateManager};
|
|
2
|
+
//# sourceMappingURL=EditorStateContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EditorStateContext.mjs","names":[],"sources":["../../../src/editor/EditorStateContext.tsx"],"sourcesContent":["import type { EditorStateManager } from '@intlayer/editor';\nimport {\n type ComponentChildren,\n createContext,\n type FunctionComponent,\n} from 'preact';\nimport { useContext } from 'preact/hooks';\n\nconst EditorStateContext = createContext<EditorStateManager | null>(null);\n\nexport const EditorStateProvider: FunctionComponent<{\n manager: EditorStateManager;\n children?: ComponentChildren;\n}> = ({ manager, children }) => (\n <EditorStateContext.Provider value={manager}>\n {children}\n </EditorStateContext.Provider>\n);\n\nexport const useEditorStateManager = (): EditorStateManager => {\n const ctx = useContext(EditorStateContext);\n if (!ctx)\n throw new Error('useEditorStateManager: no EditorStateProvider found');\n return ctx;\n};\n"],"mappings":"0HAQA,MAAM,EAAqB,EAAyC,KAAK,CAE5D,GAGP,CAAE,UAAS,cACf,EAAC,EAAmB,SAApB,CAA6B,MAAO,EACjC,WAC2B,CAAA,CAGnB,MAAkD,CAC7D,IAAM,EAAM,EAAW,EAAmB,CAC1C,GAAI,CAAC,EACH,MAAU,MAAM,sDAAsD,CACxE,OAAO"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{useEditorStateManager as e}from"./EditorStateContext.mjs";import{useEffect as t,useState as n}from"preact/hooks";const r=()=>{let r=e(),[i,a]=n(r.focusedContent.value??null);return t(()=>{let e=e=>a(e.detail);return r.focusedContent.addEventListener(`change`,e),()=>r.focusedContent.removeEventListener(`change`,e)},[r]),{focusedContent:i,setFocusedContent:e=>r.focusedContent.set(e),setFocusedContentKeyPath:e=>r.setFocusedContentKeyPath(e)}},i=()=>{let{setFocusedContent:e,setFocusedContentKeyPath:t}=r();return{setFocusedContent:e,setFocusedContentKeyPath:t}};export{r as useFocusDictionary,i as useFocusDictionaryActions};
|
|
2
2
|
//# sourceMappingURL=FocusDictionaryContext.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FocusDictionaryContext.mjs","names":[],"sources":["../../../src/editor/FocusDictionaryContext.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"FocusDictionaryContext.mjs","names":[],"sources":["../../../src/editor/FocusDictionaryContext.tsx"],"sourcesContent":["import type { FileContent } from '@intlayer/editor';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { useEffect, useState } from 'preact/hooks';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type { FileContent };\n\nexport const useFocusDictionary = () => {\n const manager = useEditorStateManager();\n const [focusedContent, setFocusedContentState] = useState<FileContent | null>(\n manager.focusedContent.value ?? null\n );\n\n useEffect(() => {\n const handler = (e: Event) =>\n setFocusedContentState((e as CustomEvent<FileContent | null>).detail);\n manager.focusedContent.addEventListener('change', handler);\n return () => manager.focusedContent.removeEventListener('change', handler);\n }, [manager]);\n\n return {\n focusedContent,\n setFocusedContent: (value: FileContent | null) =>\n manager.focusedContent.set(value),\n setFocusedContentKeyPath: (keyPath: KeyPath[]) =>\n manager.setFocusedContentKeyPath(keyPath),\n };\n};\n\nexport const useFocusDictionaryActions = () => {\n const { setFocusedContent, setFocusedContentKeyPath } = useFocusDictionary();\n return { setFocusedContent, setFocusedContentKeyPath };\n};\n"],"mappings":"wHAOA,MAAa,MAA2B,CACtC,IAAM,EAAU,GAAuB,CACjC,CAAC,EAAgB,GAA0B,EAC/C,EAAQ,eAAe,OAAS,KACjC,CASD,OAPA,MAAgB,CACd,IAAM,EAAW,GACf,EAAwB,EAAsC,OAAO,CAEvE,OADA,EAAQ,eAAe,iBAAiB,SAAU,EAAQ,KAC7C,EAAQ,eAAe,oBAAoB,SAAU,EAAQ,EACzE,CAAC,EAAQ,CAAC,CAEN,CACL,iBACA,kBAAoB,GAClB,EAAQ,eAAe,IAAI,EAAM,CACnC,yBAA2B,GACzB,EAAQ,yBAAyB,EAAQ,CAC5C,EAGU,MAAkC,CAC7C,GAAM,CAAE,oBAAmB,4BAA6B,GAAoB,CAC5E,MAAO,CAAE,oBAAmB,2BAA0B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{EditorProvider as e}from"./EditorProvider.mjs";import{jsx as t}from"preact/jsx-runtime";const n=({children:n})=>t(e,{mode:`client`,children:n});export{n as IntlayerEditorProvider};
|
|
2
2
|
//# sourceMappingURL=IntlayerEditorProvider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerEditorProvider.mjs","names":[],"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"IntlayerEditorProvider.mjs","names":[],"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["import type { ComponentChildren, FunctionComponent } from 'preact';\nimport { EditorProvider } from './EditorProvider';\n\nexport const IntlayerEditorProvider: FunctionComponent<{\n children?: ComponentChildren;\n}> = ({ children }) => (\n <EditorProvider mode=\"client\">{children}</EditorProvider>\n);\n"],"mappings":"+FAGA,MAAa,GAEP,CAAE,cACN,EAAC,EAAD,CAAgB,KAAK,SAAU,WAA0B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{EditorStateProvider as e,useEditorStateManager as t}from"./EditorStateContext.mjs";import{ContentSelectorRenderer as n}from"./ContentSelectorWrapper.mjs";export{n as ContentSelectorRenderer,e as EditorStateProvider,t as useEditorStateManager};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{useEditorStateManager as e}from"./EditorStateContext.mjs";import{useEffect as t}from"preact/hooks";const n=(n,r,i)=>{let a=e();return t(()=>{if(r)return a.messenger.subscribe(n,r)},[a,n,i]),e=>a.messenger.send(n,e)};export{n as useCrossFrameMessageListener};
|
|
2
2
|
//# sourceMappingURL=useCrossFrameMessageListener.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCrossFrameMessageListener.mjs","names":[],"sources":["../../../src/editor/useCrossFrameMessageListener.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"useCrossFrameMessageListener.mjs","names":[],"sources":["../../../src/editor/useCrossFrameMessageListener.tsx"],"sourcesContent":["import type { MessageKey } from '@intlayer/editor';\nimport { useEffect } from 'preact/hooks';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport const useCrossFrameMessageListener = <S,>(\n key: `${MessageKey}` | `${MessageKey}/post` | `${MessageKey}/get`,\n onEventTriggered?: (data: S) => void,\n revalidator?: any\n) => {\n const manager = useEditorStateManager();\n\n useEffect(() => {\n if (!onEventTriggered) return;\n return manager.messenger.subscribe<S>(key, onEventTriggered);\n }, [manager, key, revalidator]);\n\n return (data?: S) => manager.messenger.send(key, data);\n};\n"],"mappings":"0GAIA,MAAa,GACX,EACA,EACA,IACG,CACH,IAAM,EAAU,GAAuB,CAOvC,OALA,MAAgB,CACT,KACL,OAAO,EAAQ,UAAU,UAAa,EAAK,EAAiB,EAC3D,CAAC,EAAS,EAAK,EAAY,CAAC,CAEvB,GAAa,EAAQ,UAAU,KAAK,EAAK,EAAK"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{useEditorStateManager as e}from"./EditorStateContext.mjs";import{CrossFrameStateManager as t}from"@intlayer/editor";import{useEffect as n,useRef as r,useState as i}from"preact/hooks";const a=(a,o,s)=>{let c=e(),l=typeof o==`function`?o():o,[u,d]=i(l),f=r(null);return n(()=>{let{emit:e=!0,receive:n=!0}=s??{},r=new t(a,c.messenger,{emit:e,receive:n,initialValue:l});f.current=r;let i=e=>{d(e.detail)};return r.addEventListener(`change`,i),r.start(),()=>{r.removeEventListener(`change`,i),r.stop(),f.current=null}},[a,c.messenger,s?.emit,s?.receive]),[u,e=>{d(t=>{let n=typeof e==`function`?e(t):e;return f.current?.set(n),n})},()=>f.current?.postCurrentValue()]};export{a as useCrossFrameState};
|
|
2
2
|
//# sourceMappingURL=useCrossFrameState.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCrossFrameState.mjs","names":[],"sources":["../../../src/editor/useCrossFrameState.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"useCrossFrameState.mjs","names":[],"sources":["../../../src/editor/useCrossFrameState.tsx"],"sourcesContent":["import { CrossFrameStateManager, type MessageKey } from '@intlayer/editor';\nimport {\n type Dispatch,\n type StateUpdater,\n useEffect,\n useRef,\n useState,\n} from 'preact/hooks';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type CrossFrameStateOptions = {\n emit?: boolean;\n receive?: boolean;\n};\n\nexport type SetStateAction<S> = S | ((prevState: S) => S);\nexport type CrossFrameStateUpdater<S> = (value: SetStateAction<S>) => void;\n\nexport const useCrossFrameState = <S,>(\n key: `${MessageKey}`,\n initialState?: S | (() => S),\n options?: CrossFrameStateOptions\n): [S, CrossFrameStateUpdater<S>, () => void] => {\n const manager = useEditorStateManager();\n\n const resolvedInitial =\n typeof initialState === 'function'\n ? (initialState as () => S)()\n : initialState;\n\n const [value, setValueState] = useState<S>(resolvedInitial as S);\n const stateManagerRef = useRef<CrossFrameStateManager<S> | null>(null);\n\n useEffect(() => {\n const { emit = true, receive = true } = options ?? {};\n const stateManager = new CrossFrameStateManager<S>(key, manager.messenger, {\n emit,\n receive,\n initialValue: resolvedInitial,\n });\n stateManagerRef.current = stateManager;\n\n const handler = (e: Event) => {\n setValueState((e as CustomEvent<S>).detail);\n };\n stateManager.addEventListener('change', handler);\n stateManager.start();\n\n return () => {\n stateManager.removeEventListener('change', handler);\n stateManager.stop();\n stateManagerRef.current = null;\n };\n }, [key, manager.messenger, options?.emit, options?.receive]);\n\n const setValue: CrossFrameStateUpdater<S> = (valueOrUpdater) => {\n setValueState((prev) => {\n const newValue =\n typeof valueOrUpdater === 'function'\n ? (valueOrUpdater as (prev: S) => S)(prev)\n : valueOrUpdater;\n stateManagerRef.current?.set(newValue);\n return newValue;\n });\n };\n\n const postState = () => stateManagerRef.current?.postCurrentValue();\n\n return [value, setValue, postState];\n};\n"],"mappings":"8LAkBA,MAAa,GACX,EACA,EACA,IAC+C,CAC/C,IAAM,EAAU,GAAuB,CAEjC,EACJ,OAAO,GAAiB,WACnB,GAA0B,CAC3B,EAEA,CAAC,EAAO,GAAiB,EAAY,EAAqB,CAC1D,EAAkB,EAAyC,KAAK,CAqCtE,OAnCA,MAAgB,CACd,GAAM,CAAE,OAAO,GAAM,UAAU,IAAS,GAAW,EAAE,CAC/C,EAAe,IAAI,EAA0B,EAAK,EAAQ,UAAW,CACzE,OACA,UACA,aAAc,EACf,CAAC,CACF,EAAgB,QAAU,EAE1B,IAAM,EAAW,GAAa,CAC5B,EAAe,EAAqB,OAAO,EAK7C,OAHA,EAAa,iBAAiB,SAAU,EAAQ,CAChD,EAAa,OAAO,KAEP,CACX,EAAa,oBAAoB,SAAU,EAAQ,CACnD,EAAa,MAAM,CACnB,EAAgB,QAAU,OAE3B,CAAC,EAAK,EAAQ,UAAW,GAAS,KAAM,GAAS,QAAQ,CAAC,CAetD,CAAC,EAbqC,GAAmB,CAC9D,EAAe,GAAS,CACtB,IAAM,EACJ,OAAO,GAAmB,WACrB,EAAkC,EAAK,CACxC,EAEN,OADA,EAAgB,SAAS,IAAI,EAAS,CAC/B,GACP,MAGoB,EAAgB,SAAS,kBAAkB,CAEhC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
const e=()=>{},t=()=>{};export{e as useCrossURLPathSetter,t as useCrossURLPathState};
|
|
2
2
|
//# sourceMappingURL=useCrossURLPathState.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCrossURLPathState.mjs","names":[],"sources":["../../../src/editor/useCrossURLPathState.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"useCrossURLPathState.mjs","names":[],"sources":["../../../src/editor/useCrossURLPathState.tsx"],"sourcesContent":["// UrlStateManager is started by EditorStateManager.start() in client mode.\n// Nothing extra needed here.\nexport const useCrossURLPathSetter = () => {\n // No-op: managed by EditorStateManager\n};\n\nexport const useCrossURLPathState = () => {\n // No-op: managed by EditorStateManager\n};\n"],"mappings":"AAEA,MAAa,MAA8B,GAI9B,MAA6B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{useEditedContentActions as e}from"./EditedContentContext.mjs";import{getBasePlugins as t,getContent as n}from"@intlayer/core/interpreter";const r=({dictionaryKey:t,keyPath:n,children:r})=>{let i=e();return i?i.getEditedContentValue(t,n)??r:r},i=e=>{let i=r(e);if(typeof i==`object`){let r=n(i,{...e,locale:e.locale},t(e.locale));return typeof r==`string`?r:(console.error(`Incorrect edited content format. Content type: ${typeof r}. Expected string. Value ${JSON.stringify(r)}`),e.children)}return i};export{i as EditedContentRenderer,r as useEditedContentRenderer};
|
|
2
2
|
//# sourceMappingURL=useEditedContentRenderer.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditedContentRenderer.mjs","names":[],"sources":["../../../src/editor/useEditedContentRenderer.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"useEditedContentRenderer.mjs","names":[],"sources":["../../../src/editor/useEditedContentRenderer.tsx"],"sourcesContent":["import { getBasePlugins, getContent } from '@intlayer/core/interpreter';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { FunctionalComponent } from 'preact';\nimport { useEditedContentActions } from './EditedContentContext';\n\ntype EditedContentRendererProps = {\n dictionaryKey: Dictionary['key'];\n keyPath: KeyPath[];\n children: string;\n locale?: Locale;\n};\n\nexport const useEditedContentRenderer = ({\n dictionaryKey,\n keyPath,\n children,\n}: EditedContentRendererProps) => {\n const editedContentContext = useEditedContentActions();\n\n if (editedContentContext) {\n const editedValue = editedContentContext.getEditedContentValue(\n dictionaryKey,\n keyPath\n ) as string;\n\n const value = editedValue ?? children;\n\n return value;\n }\n\n return children;\n};\n\nexport const EditedContentRenderer: FunctionalComponent<\n EditedContentRendererProps\n> = (props) => {\n const content = useEditedContentRenderer(props);\n\n if (typeof content === 'object') {\n const transformedEditedContent = getContent(\n content,\n { ...props, locale: props.locale },\n getBasePlugins(props.locale)\n );\n\n if (typeof transformedEditedContent !== 'string') {\n console.error(\n `Incorrect edited content format. Content type: ${typeof transformedEditedContent}. Expected string. Value ${JSON.stringify(transformedEditedContent)}`\n );\n\n return props.children;\n }\n\n return transformedEditedContent;\n }\n\n return content;\n};\n"],"mappings":"iJAcA,MAAa,GAA4B,CACvC,gBACA,UACA,cACgC,CAChC,IAAM,EAAuB,GAAyB,CAatD,OAXI,EACkB,EAAqB,sBACvC,EACA,EACD,EAE4B,EAKxB,GAGI,EAER,GAAU,CACb,IAAM,EAAU,EAAyB,EAAM,CAE/C,GAAI,OAAO,GAAY,SAAU,CAC/B,IAAM,EAA2B,EAC/B,EACA,CAAE,GAAG,EAAO,OAAQ,EAAM,OAAQ,CAClC,EAAe,EAAM,OAAO,CAC7B,CAUD,OARI,OAAO,GAA6B,SAQjC,GAPL,QAAQ,MACN,kDAAkD,OAAO,EAAyB,2BAA2B,KAAK,UAAU,EAAyB,GACtJ,CAEM,EAAM,UAMjB,OAAO"}
|