@intlayer/editor-react 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/CommunicatorContext.cjs +1 -1
- package/dist/cjs/CommunicatorContext.cjs.map +1 -1
- package/dist/cjs/ConfigurationContext.cjs +1 -1
- package/dist/cjs/ConfigurationContext.cjs.map +1 -1
- package/dist/cjs/DictionariesRecordContext.cjs +1 -1
- package/dist/cjs/DictionariesRecordContext.cjs.map +1 -1
- package/dist/cjs/EditedContentContext.cjs +1 -1
- package/dist/cjs/EditedContentContext.cjs.map +1 -1
- package/dist/cjs/EditorEnabledContext.cjs +1 -1
- package/dist/cjs/EditorEnabledContext.cjs.map +1 -1
- package/dist/cjs/EditorProvider.cjs +1 -1
- package/dist/cjs/EditorProvider.cjs.map +1 -1
- package/dist/cjs/EditorStateContext.cjs +2 -0
- package/dist/cjs/EditorStateContext.cjs.map +1 -0
- package/dist/cjs/FocusDictionaryContext.cjs +1 -1
- package/dist/cjs/FocusDictionaryContext.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/useCrossFrameMessageListener.cjs +1 -1
- package/dist/cjs/useCrossFrameMessageListener.cjs.map +1 -1
- package/dist/cjs/useCrossFrameState.cjs +1 -1
- package/dist/cjs/useCrossFrameState.cjs.map +1 -1
- package/dist/cjs/useCrossURLPathState.cjs +1 -1
- package/dist/cjs/useCrossURLPathState.cjs.map +1 -1
- package/dist/cjs/useEditorLocale.cjs +1 -1
- package/dist/cjs/useEditorLocale.cjs.map +1 -1
- package/dist/cjs/useIframeClickInterceptor.cjs +1 -1
- package/dist/cjs/useIframeClickInterceptor.cjs.map +1 -1
- package/dist/esm/CommunicatorContext.mjs +1 -1
- package/dist/esm/CommunicatorContext.mjs.map +1 -1
- package/dist/esm/ConfigurationContext.mjs +1 -1
- package/dist/esm/ConfigurationContext.mjs.map +1 -1
- package/dist/esm/DictionariesRecordContext.mjs +1 -1
- package/dist/esm/DictionariesRecordContext.mjs.map +1 -1
- package/dist/esm/EditedContentContext.mjs +1 -1
- package/dist/esm/EditedContentContext.mjs.map +1 -1
- package/dist/esm/EditorEnabledContext.mjs +1 -1
- package/dist/esm/EditorEnabledContext.mjs.map +1 -1
- package/dist/esm/EditorProvider.mjs +1 -1
- package/dist/esm/EditorProvider.mjs.map +1 -1
- package/dist/esm/EditorStateContext.mjs +2 -0
- package/dist/esm/EditorStateContext.mjs.map +1 -0
- package/dist/esm/FocusDictionaryContext.mjs +1 -1
- package/dist/esm/FocusDictionaryContext.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/useCrossFrameMessageListener.mjs +1 -1
- package/dist/esm/useCrossFrameMessageListener.mjs.map +1 -1
- package/dist/esm/useCrossFrameState.mjs +1 -1
- package/dist/esm/useCrossFrameState.mjs.map +1 -1
- package/dist/esm/useCrossURLPathState.mjs +1 -1
- package/dist/esm/useCrossURLPathState.mjs.map +1 -1
- package/dist/esm/useEditorLocale.mjs +1 -1
- package/dist/esm/useEditorLocale.mjs.map +1 -1
- package/dist/esm/useIframeClickInterceptor.mjs +1 -1
- package/dist/esm/useIframeClickInterceptor.mjs.map +1 -1
- package/dist/types/CommunicatorContext.d.ts +6 -5
- package/dist/types/CommunicatorContext.d.ts.map +1 -1
- package/dist/types/ConfigurationContext.d.ts +9 -5
- package/dist/types/ConfigurationContext.d.ts.map +1 -1
- package/dist/types/DictionariesRecordContext.d.ts +12 -11
- package/dist/types/DictionariesRecordContext.d.ts.map +1 -1
- package/dist/types/EditedContentContext.d.ts +13 -12
- package/dist/types/EditedContentContext.d.ts.map +1 -1
- package/dist/types/EditorEnabledContext.d.ts +16 -9
- package/dist/types/EditorEnabledContext.d.ts.map +1 -1
- package/dist/types/EditorProvider.d.ts +10 -4
- package/dist/types/EditorProvider.d.ts.map +1 -1
- package/dist/types/EditorStateContext.d.ts +11 -0
- package/dist/types/EditorStateContext.d.ts.map +1 -0
- package/dist/types/FocusDictionaryContext.d.ts +8 -16
- package/dist/types/FocusDictionaryContext.d.ts.map +1 -1
- package/dist/types/index.d.ts +9 -8
- package/dist/types/useCrossFrameMessageListener.d.ts +3 -13
- package/dist/types/useCrossFrameMessageListener.d.ts.map +1 -1
- package/dist/types/useCrossFrameState.d.ts +2 -20
- package/dist/types/useCrossFrameState.d.ts.map +1 -1
- package/dist/types/useCrossURLPathState.d.ts.map +1 -1
- package/dist/types/useEditorLocale.d.ts +2 -3
- package/dist/types/useEditorLocale.d.ts.map +1 -1
- package/dist/types/useFocusUnmergedDictionary.d.ts +1 -2
- package/dist/types/useFocusUnmergedDictionary.d.ts.map +1 -1
- package/dist/types/useIframeClickInterceptor.d.ts +11 -1
- package/dist/types/useIframeClickInterceptor.d.ts.map +1 -1
- package/package.json +7 -7
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./EditorStateContext.cjs`),t=()=>{let t=e.useEditorStateManager();return{postMessage:e=>t.messenger.send(e.type,e.data),senderId:t.messenger.senderId}};exports.useCommunicator=t;
|
|
2
2
|
//# sourceMappingURL=CommunicatorContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommunicatorContext.cjs","names":["
|
|
1
|
+
{"version":3,"file":"CommunicatorContext.cjs","names":["useEditorStateManager"],"sources":["../../src/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport type { MessagePayload } from '@intlayer/editor';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type UseCrossPlatformStateProps = {\n postMessage: (payload: MessagePayload) => void;\n allowedOrigins?: string[];\n senderId: string;\n};\n\n/**\n * Returns the communicator API backed by the shared EditorStateManager messenger.\n */\nexport const useCommunicator = (): UseCrossPlatformStateProps => {\n const manager = useEditorStateManager();\n\n return {\n postMessage: (payload: MessagePayload) =>\n manager.messenger.send(payload.type, payload.data),\n senderId: manager.messenger.senderId,\n };\n};\n\n// Re-export type for backward compatibility\nexport type { MessengerConfig } from '@intlayer/editor';\n"],"mappings":"4HAca,MAAoD,CAC/D,IAAM,EAAUA,EAAAA,uBAAuB,CAEvC,MAAO,CACL,YAAc,GACZ,EAAQ,UAAU,KAAK,EAAQ,KAAM,EAAQ,KAAK,CACpD,SAAU,EAAQ,UAAU,SAC7B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./EditorStateContext.cjs`);let t=require(`react`);const n=()=>{let n=e.useEditorStateManager(),[r,i]=(0,t.useState)(n.configuration.value);return(0,t.useEffect)(()=>{let e=e=>i(e.detail);return n.configuration.addEventListener(`change`,e),()=>n.configuration.removeEventListener(`change`,e)},[n]),r},r=()=>{let n=e.useEditorStateManager(),[r,i]=(0,t.useState)(n.configuration.value);return[r,i,()=>n.configuration.postCurrentValue()]};exports.useConfiguration=n,exports.useConfigurationState=r;
|
|
2
2
|
//# sourceMappingURL=ConfigurationContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigurationContext.cjs","names":["
|
|
1
|
+
{"version":3,"file":"ConfigurationContext.cjs","names":["useEditorStateManager"],"sources":["../../src/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type ConfigurationProviderProps = {\n configuration?: IntlayerConfig;\n};\n\n/**\n * Returns the current configuration, backed by EditorStateManager.\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\n/**\n * Returns a function that broadcasts the current configuration.\n */\nexport const useConfigurationState = () => {\n const manager = useEditorStateManager();\n\n const [config, setConfig] = useState<IntlayerConfig | undefined>(\n manager.configuration.value\n );\n\n return [\n config,\n setConfig,\n () => manager.configuration.postCurrentValue(),\n ] as const;\n};\n"],"mappings":"+LAaA,MAAa,MAAqD,CAChE,IAAM,EAAUA,EAAAA,uBAAuB,CACjC,CAAC,EAAQ,IAAA,EAAA,EAAA,UACb,EAAQ,cAAc,MACvB,CASD,OAPA,EAAA,EAAA,eAAgB,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,GAMI,MAA8B,CACzC,IAAM,EAAUA,EAAAA,uBAAuB,CAEjC,CAAC,EAAQ,IAAA,EAAA,EAAA,UACb,EAAQ,cAAc,MACvB,CAED,MAAO,CACL,EACA,MACM,EAAQ,cAAc,kBAAkB,CAC/C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./EditorStateContext.cjs`);let t=require(`react`);const n=()=>{let n=e.useEditorStateManager(),[r,i]=(0,t.useState)(n.localeDictionaries.value??{});return(0,t.useEffect)(()=>{let e=e=>i(e.detail??{});return n.localeDictionaries.addEventListener(`change`,e),()=>n.localeDictionaries.removeEventListener(`change`,e)},[n]),{localeDictionaries:r,setLocaleDictionaries:(0,t.useCallback)(e=>n.localeDictionaries.set(e),[n]),setLocaleDictionary:(0,t.useCallback)(e=>n.setLocaleDictionary(e),[n])}},r=()=>{let{setLocaleDictionaries:e,setLocaleDictionary:t}=n();return{setLocaleDictionaries:e,setLocaleDictionary:t}};exports.useDictionariesRecord=n,exports.useDictionariesRecordActions=r;
|
|
2
2
|
//# sourceMappingURL=DictionariesRecordContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DictionariesRecordContext.cjs","names":["
|
|
1
|
+
{"version":3,"file":"DictionariesRecordContext.cjs","names":["useEditorStateManager"],"sources":["../../src/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport type { DictionaryContent } from '@intlayer/editor';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { useCallback, useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type { DictionaryContent } from '@intlayer/editor';\n\ntype DictionariesRecordStatesContextType = {\n localeDictionaries: DictionaryContent;\n};\ntype DictionariesRecordActionsContextType = {\n setLocaleDictionaries: (value: DictionaryContent) => void;\n setLocaleDictionary: (dictionary: Dictionary) => void;\n};\n\n/**\n * Returns dictionaries record state and setters, backed by EditorStateManager.\n * Replaces the old DictionariesRecordContext + DictionariesRecordProvider.\n */\nexport const useDictionariesRecord = (): DictionariesRecordStatesContextType &\n DictionariesRecordActionsContextType => {\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 const setLocaleDictionaries = useCallback(\n (value: DictionaryContent) => manager.localeDictionaries.set(value),\n [manager]\n );\n\n const setLocaleDictionary = useCallback(\n (dictionary: Dictionary) => manager.setLocaleDictionary(dictionary),\n [manager]\n );\n\n return { localeDictionaries, setLocaleDictionaries, setLocaleDictionary };\n};\n\nexport const useDictionariesRecordActions =\n (): DictionariesRecordActionsContextType => {\n const { setLocaleDictionaries, setLocaleDictionary } =\n useDictionariesRecord();\n return { setLocaleDictionaries, setLocaleDictionary };\n };\n"],"mappings":"+LAqBA,MAAa,MAC6B,CACxC,IAAM,EAAUA,EAAAA,uBAAuB,CACjC,CAAC,EAAoB,IAAA,EAAA,EAAA,UACG,EAAQ,mBAAmB,OAAS,EAAE,CAAC,CAsBrE,OApBA,EAAA,EAAA,eAAgB,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,CAYN,CAAE,qBAAoB,uBAAA,EAAA,EAAA,aAT1B,GAA6B,EAAQ,mBAAmB,IAAI,EAAM,CACnE,CAAC,EAAQ,CACV,CAOmD,qBAAA,EAAA,EAAA,aAJjD,GAA2B,EAAQ,oBAAoB,EAAW,CACnE,CAAC,EAAQ,CACV,CAEwE,EAG9D,MACiC,CAC1C,GAAM,CAAE,wBAAuB,uBAC7B,GAAuB,CACzB,MAAO,CAAE,wBAAuB,sBAAqB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./EditorStateContext.cjs`);let t=require(`react`);const n=()=>{let t=e.useEditorStateManager();return{setEditedContentState:e=>t.editedContent.set(e),setEditedDictionary:e=>t.setEditedDictionary(e),setEditedContent:(e,n)=>t.setEditedContent(e,n),addEditedContent:(e,n,r,i)=>t.addContent(e,n,r,i),renameEditedContent:(e,n,r)=>t.renameContent(e,n,r),removeEditedContent:(e,n)=>t.removeContent(e,n),restoreEditedContent:e=>t.restoreContent(e),clearEditedDictionaryContent:e=>t.clearContent(e),clearEditedContent:()=>t.clearAllContent(),getEditedContentValue:(e,n)=>t.getContentValue(e,n)}},r=()=>{let r=e.useEditorStateManager(),[i,a]=(0,t.useState)(r.editedContent.value);return(0,t.useEffect)(()=>{let e=e=>a(e.detail);return r.editedContent.addEventListener(`change`,e),()=>r.editedContent.removeEventListener(`change`,e)},[r]),{editedContent:i,...n()}},i=n=>{let r=e.useEditorStateManager();(0,t.useEffect)(()=>{if(n)return r.messenger.subscribe(`INTLAYER_EDITED_CONTENT_CHANGED/post`,n)},[r,n])},a=t=>{let n=e.useEditorStateManager();return()=>{n.messenger.send(`INTLAYER_EDITED_CONTENT_CHANGED/get`)}};exports.useEditedContent=r,exports.useEditedContentActions=n,exports.useGetEditedContentState=a,exports.usePostEditedContentState=i;
|
|
2
2
|
//# sourceMappingURL=EditedContentContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditedContentContext.cjs","names":["useCrossFrameMessageListener","MessageKey","useDictionariesRecord","useEditorLocale","useCrossFrameState","NodeType"],"sources":["../../src/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 { ContentNode, Dictionary, LocalDictionaryId } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';;\nimport { NodeType } from '@intlayer/types/nodeType';\nimport {\n createContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n useContext,\n} from 'react';\nimport {\n type DictionaryContent,\n useDictionariesRecord,\n} from './DictionariesRecordContext';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\nimport { useCrossFrameState } from './useCrossFrameState';\nimport { useEditorLocale } from './useEditorLocale';\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: (editedContent: DictionaryContent) => void;\n setEditedDictionary: Dispatch<SetStateAction<Dictionary>>;\n setEditedContent: (\n localDictionaryId: LocalDictionaryId,\n newValue: Dictionary['content']\n ) => void;\n addEditedContent: (\n localDictionaryId: LocalDictionaryId,\n newValue: ContentNode<any>,\n keyPath?: KeyPath[],\n overwrite?: boolean\n ) => void;\n renameEditedContent: (\n localDictionaryId: LocalDictionaryId,\n newKey: KeyPath['key'],\n keyPath?: KeyPath[]\n ) => void;\n removeEditedContent: (\n localDictionaryId: LocalDictionaryId,\n keyPath: KeyPath[]\n ) => void;\n restoreEditedContent: (localDictionaryId: LocalDictionaryId) => void;\n clearEditedDictionaryContent: (localDictionaryId: 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,>(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 const currentLocale = useEditorLocale();\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 if (!updatedDictionaries.localId) {\n console.error('no localId', updatedDictionaries);\n\n return prev;\n }\n\n updatedDictionaries = resolveState(\n newValue,\n prev?.[updatedDictionaries.localId]\n );\n\n return {\n ...prev,\n [updatedDictionaries.localId as LocalDictionaryId]: updatedDictionaries,\n };\n });\n\n return updatedDictionaries;\n };\n\n const setEditedContent = (\n localDictionaryId: LocalDictionaryId,\n newValue: Dictionary['content']\n ) => {\n setEditedContentState((prev) => ({\n ...prev,\n [localDictionaryId]: {\n ...prev?.[localDictionaryId],\n content: newValue,\n },\n }));\n };\n\n const addEditedContent = (\n localDictionaryId: 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[localDictionaryId]?.content;\n const currentContent = structuredClone(\n prev?.[localDictionaryId]?.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\n const otherKeyPath = keyPath.slice(0, -1);\n const lastKeyPath: KeyPath = keyPath[keyPath.length - 1];\n\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 [localDictionaryId]: {\n ...prev?.[localDictionaryId],\n content: updatedContent as Dictionary['content'],\n },\n };\n });\n };\n\n const renameEditedContent = (\n localDictionaryId: 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[localDictionaryId]?.content;\n const currentContent = structuredClone(\n prev?.[localDictionaryId]?.content ?? originalContent\n );\n\n const contentWithNewField = renameContentNodeByKeyPath(\n currentContent,\n newKey,\n keyPath\n );\n\n return {\n ...prev,\n [localDictionaryId]: {\n ...prev?.[localDictionaryId],\n content: contentWithNewField as Dictionary['content'],\n },\n };\n });\n };\n\n const removeEditedContent = (\n localDictionaryId: LocalDictionaryId,\n keyPath: KeyPath[]\n ) => {\n setEditedContentState((prev) => {\n // Retrieve the original content as reference\n const originalContent = localeDictionaries[localDictionaryId]?.content;\n const currentContent = structuredClone(\n prev?.[localDictionaryId]?.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 [localDictionaryId]: {\n ...prev?.[localDictionaryId],\n content: restoredContent as Dictionary['content'],\n },\n };\n });\n };\n\n const restoreEditedContent = (localDictionaryId: LocalDictionaryId) => {\n setEditedContentState((prev) => {\n const updated = { ...prev };\n delete updated[localDictionaryId];\n return updated;\n });\n };\n\n const clearEditedDictionaryContent = (\n localDictionaryId: LocalDictionaryId\n ) => {\n setEditedContentState((prev) => {\n const filtered = { ...prev };\n delete filtered[localDictionaryId];\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 currentLocale\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 currentLocale\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":"odA+BA,MAAM,GAAA,EAAA,EAAA,eAEJ,IAAA,GAAU,CAEC,EACX,GAEAA,EAAAA,6BACE,GAAGC,EAAAA,WAAW,gCAAgC,OAC9C,EACD,CAEU,EACX,GAEAD,EAAAA,6BACE,GAAGC,EAAAA,WAAW,gCAAgC,MAC9C,EACD,CAiCG,GAAA,EAAA,EAAA,eAEJ,IAAA,GAAU,CAEN,GAAoB,EAA2B,IACnD,OAAO,GAAU,WACZ,EAA+B,EAAU,CACzC,EAEM,GAAgD,CAAE,cAAe,CAC5E,GAAM,CAAE,sBAAuBC,EAAAA,uBAAuB,CAChD,EAAgBC,EAAAA,iBAAiB,CAEjC,CAAC,EAAe,GACpBC,EAAAA,mBACEH,EAAAA,WAAW,gCACZ,CA+NH,OACE,EAAA,EAAA,KAAC,EAA0B,SAA3B,CACE,MAAO,CACL,gBACD,WAED,EAAA,EAAA,KAAC,EAA4B,SAA7B,CACE,MAAO,CACL,wBACA,oBArON,GACG,CACH,IAAI,EAAkC,EAAa,EAAS,CAoB5D,OAlBA,EAAuB,GAChB,EAAoB,SAMzB,EAAsB,EACpB,EACA,IAAO,EAAoB,SAC5B,CAEM,CACL,GAAG,GACF,EAAoB,SAA+B,EACrD,GAbC,QAAQ,MAAM,aAAc,EAAoB,CAEzC,GAYT,CAEK,GAgND,kBA5MN,EACA,IACG,CACH,EAAuB,IAAU,CAC/B,GAAG,GACF,GAAoB,CACnB,GAAG,IAAO,GACV,QAAS,EACV,CACF,EAAE,EAoMG,kBAhMN,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,EAEN,EAAe,EAAQ,MAAM,EAAG,GAAG,CACnC,EAAuB,EAAQ,EAAQ,OAAS,GAElD,EAAW,EAAY,IAG3B,MACE,EAAA,EAAA,yBAA+B,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,GAAA,EAAA,EAAA,yBACJ,EACA,EACA,EACD,CAED,MAAO,CACL,GAAG,GACF,GAAoB,CACnB,GAAG,IAAO,GACV,QAAS,EACV,CACF,EACD,EA+II,qBA3IN,EACA,EACA,EAAqB,EAAE,GACpB,CACH,EAAuB,GAAS,CAE9B,IAAM,EAAkB,EAAmB,IAAoB,QAKzD,GAAA,EAAA,EAAA,4BAJiB,gBACrB,IAAO,IAAoB,SAAW,EACvC,CAIC,EACA,EACD,CAED,MAAO,CACL,GAAG,GACF,GAAoB,CACnB,GAAG,IAAO,GACV,QAAS,EACV,CACF,EACD,EAoHI,qBAhHN,EACA,IACG,CACH,EAAuB,GAAS,CAE9B,IAAM,EAAkB,EAAmB,IAAoB,QASzD,GAAA,EAAA,EAAA,yBARiB,gBACrB,IAAO,IAAoB,SAAW,EACvC,CAQC,GAAA,EAAA,EAAA,yBAL6C,EAAiB,EAAQ,CAOvE,CAED,MAAO,CACL,GAAG,GACF,GAAoB,CACnB,GAAG,IAAO,GACV,QAAS,EACV,CACF,EACD,EAsFI,qBAnFsB,GAAyC,CACrE,EAAuB,GAAS,CAC9B,IAAM,EAAU,CAAE,GAAG,EAAM,CAE3B,OADA,OAAO,EAAQ,GACR,GACP,EA+EI,6BA3EN,GACG,CACH,EAAuB,GAAS,CAC9B,IAAM,EAAW,CAAE,GAAG,EAAM,CAE5B,OADA,OAAO,EAAS,GACT,GACP,EAsEI,uBAnEyB,CAC/B,EAAsB,EAAE,CAAC,EAmEnB,uBA/DN,EACA,IAC4B,CAC5B,GAAI,CAAC,EAAe,OAEpB,IAAM,EAAkB,EAAQ,OAC7B,GAAQ,EAAI,OAASI,EAAAA,SAAS,YAChC,CAMD,GAHE,EAAuB,SAAS,UAAU,EAC1C,EAAuB,SAAS,WAAW,CAa3C,OAAA,EAAA,EAAA,yBATE,IAAgB,IAA8C,SAC9D,EAAE,CAIF,EACA,EACD,CAKH,IAAM,EAA8B,OAAO,KAAK,EAAc,CAAC,OAC5D,GAAQ,EAAI,WAAW,GAAG,EAAuB,GAAG,CACtD,CAED,IAAK,IAAM,KAAqB,EAA6B,CAG3D,IAAM,GAAA,EAAA,EAAA,yBADJ,IAAgB,IAAyC,SAAW,EAAE,CAGtE,EACA,EACD,CAED,GAAI,EAAa,OAAO,IAwBrB,CAEA,WACoC,CAAA,CACJ,CAAA,EAI5B,OAAA,EAAA,EAAA,YACA,EAA4B,CAE5B,MAAyB,CACpC,IAAM,GAAA,EAAA,EAAA,YAA0B,EAA0B,CACpD,EAAgB,GAAyB,CAE/C,MAAO,CAAE,GAAG,EAAc,GAAG,EAAe"}
|
|
1
|
+
{"version":3,"file":"EditedContentContext.cjs","names":["useEditorStateManager"],"sources":["../../src/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport 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 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type { DictionaryContent } from '@intlayer/editor';\n\ntype EditedContentActionsContextType = {\n setEditedContentState: (editedContent: DictionaryContent) => void;\n setEditedDictionary: (dict: Dictionary) => void;\n setEditedContent: (\n localDictionaryId: LocalDictionaryId,\n newValue: Dictionary['content']\n ) => void;\n addEditedContent: (\n localDictionaryId: LocalDictionaryId,\n newValue: ContentNode<any>,\n keyPath?: KeyPath[],\n overwrite?: boolean\n ) => void;\n renameEditedContent: (\n localDictionaryId: LocalDictionaryId,\n newKey: KeyPath['key'],\n keyPath?: KeyPath[]\n ) => void;\n removeEditedContent: (\n localDictionaryId: LocalDictionaryId,\n keyPath: KeyPath[]\n ) => void;\n restoreEditedContent: (localDictionaryId: LocalDictionaryId) => void;\n clearEditedDictionaryContent: (localDictionaryId: LocalDictionaryId) => void;\n clearEditedContent: () => void;\n getEditedContentValue: (\n localDictionaryIdOrKey: LocalDictionaryId | Dictionary['key'] | string,\n keyPath: KeyPath[]\n ) => ContentNode | undefined;\n};\n\n/**\n * Returns edited-content state and actions, backed by EditorStateManager.\n */\nexport const useEditedContentActions = ():\n | EditedContentActionsContextType\n | undefined => {\n const manager = useEditorStateManager();\n\n return {\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: (localId, value, keyPath, overwrite) =>\n manager.addContent(localId, value, keyPath, overwrite),\n renameEditedContent: (localId, newKey, keyPath) =>\n manager.renameContent(localId, newKey, keyPath),\n removeEditedContent: (localId, keyPath) =>\n manager.removeContent(localId, keyPath),\n restoreEditedContent: (localId) => manager.restoreContent(localId),\n clearEditedDictionaryContent: (localId) => manager.clearContent(localId),\n clearEditedContent: () => manager.clearAllContent(),\n getEditedContentValue: (localIdOrKey, keyPath) =>\n manager.getContentValue(localIdOrKey, keyPath),\n };\n};\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 const actions = useEditedContentActions();\n return { editedContent, ...actions };\n};\n\nexport const usePostEditedContentState = <S,>(\n onEventTriggered?: (data: S) => void\n) => {\n const manager = useEditorStateManager();\n useEffect(() => {\n if (!onEventTriggered) return;\n return manager.messenger.subscribe(\n `INTLAYER_EDITED_CONTENT_CHANGED/post`,\n onEventTriggered as (data: unknown) => void\n );\n }, [manager, onEventTriggered]);\n};\n\nexport const useGetEditedContentState = <S,>(\n onEventTriggered?: (data: S) => void\n) => {\n const manager = useEditorStateManager();\n return () => {\n manager.messenger.send('INTLAYER_EDITED_CONTENT_CHANGED/get');\n };\n};\n"],"mappings":"+LAgDA,MAAa,MAEI,CACf,IAAM,EAAUA,EAAAA,uBAAuB,CAEvC,MAAO,CACL,sBAAwB,GACtB,EAAQ,cAAc,IAAI,EAAM,CAClC,oBAAsB,GACpB,EAAQ,oBAAoB,EAAK,CACnC,kBACE,EACA,IACG,EAAQ,iBAAiB,EAAS,EAAM,CAC7C,kBAAmB,EAAS,EAAO,EAAS,IAC1C,EAAQ,WAAW,EAAS,EAAO,EAAS,EAAU,CACxD,qBAAsB,EAAS,EAAQ,IACrC,EAAQ,cAAc,EAAS,EAAQ,EAAQ,CACjD,qBAAsB,EAAS,IAC7B,EAAQ,cAAc,EAAS,EAAQ,CACzC,qBAAuB,GAAY,EAAQ,eAAe,EAAQ,CAClE,6BAA+B,GAAY,EAAQ,aAAa,EAAQ,CACxE,uBAA0B,EAAQ,iBAAiB,CACnD,uBAAwB,EAAc,IACpC,EAAQ,gBAAgB,EAAc,EAAQ,CACjD,EAGU,MAAyB,CACpC,IAAM,EAAUA,EAAAA,uBAAuB,CACjC,CAAC,EAAe,IAAA,EAAA,EAAA,UAEpB,EAAQ,cAAc,MAAM,CAU9B,OARA,EAAA,EAAA,eAAgB,CACd,IAAM,EAAW,GACf,EAAuB,EAAqC,OAAO,CAErE,OADA,EAAQ,cAAc,iBAAiB,SAAU,EAAQ,KAC5C,EAAQ,cAAc,oBAAoB,SAAU,EAAQ,EACxE,CAAC,EAAQ,CAAC,CAGN,CAAE,gBAAe,GADR,GAAyB,CACL,EAGzB,EACX,GACG,CACH,IAAM,EAAUA,EAAAA,uBAAuB,EACvC,EAAA,EAAA,eAAgB,CACT,KACL,OAAO,EAAQ,UAAU,UACvB,uCACA,EACD,EACA,CAAC,EAAS,EAAiB,CAAC,EAGpB,EACX,GACG,CACH,IAAM,EAAUA,EAAAA,uBAAuB,CACvC,UAAa,CACX,EAAQ,UAAU,KAAK,sCAAsC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./EditorStateContext.cjs`);let t=require(`react`),n=require(`@intlayer/editor`);const r=()=>{let n=e.useEditorStateManager(),[r,i]=(0,t.useState)(n.editorEnabled.value??!1);return(0,t.useEffect)(()=>{let e=e=>i(e.detail);return n.editorEnabled.addEventListener(`change`,e),()=>n.editorEnabled.removeEventListener(`change`,e)},[n]),{enabled:r}},i=r=>{let i=e.useEditorStateManager();(0,t.useEffect)(()=>{if(r)return i.messenger.subscribe(`${n.MessageKey.INTLAYER_EDITOR_ENABLED}/get`,r)},[i,r])},a=()=>{let t=e.useEditorStateManager();return e=>{t.editorEnabled.set(e),t.editorEnabled.postCurrentValue()}},o=()=>{let{enabled:t}=r(),n=e.useEditorStateManager();return[t,e=>n.editorEnabled.set(e)]};exports.useEditorEnabled=r,exports.useEditorEnabledState=o,exports.useGetEditorEnabledState=i,exports.usePostEditorEnabledState=a;
|
|
2
2
|
//# sourceMappingURL=EditorEnabledContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorEnabledContext.cjs","names":["
|
|
1
|
+
{"version":3,"file":"EditorEnabledContext.cjs","names":["useEditorStateManager","MessageKey"],"sources":["../../src/EditorEnabledContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport { useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type EditorEnabledStateProps = {\n enabled: boolean;\n};\n\n/**\n * Returns the current editor-enabled state, kept in sync with the shared\n * EditorStateManager. Replaces the old EditorEnabledContext + EditorEnabledProvider.\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\n/**\n * Subscribes to incoming \"get\" requests for editor-enabled state and calls\n * the provided callback so the caller can respond.\n * Used by the editor side to respond when the client asks for the current state.\n */\nexport const useGetEditorEnabledState = (onRequest?: () => void) => {\n const manager = useEditorStateManager();\n\n useEffect(() => {\n if (!onRequest) return;\n return manager.messenger.subscribe(\n `${MessageKey.INTLAYER_EDITOR_ENABLED}/get`,\n onRequest\n );\n }, [manager, onRequest]);\n};\n\n/**\n * Returns a function that sets the editor-enabled state and broadcasts it.\n */\nexport const usePostEditorEnabledState = () => {\n const manager = useEditorStateManager();\n return (value: boolean) => {\n manager.editorEnabled.set(value);\n manager.editorEnabled.postCurrentValue();\n };\n};\n\nexport const useEditorEnabledState = () => {\n const { enabled } = useEditorEnabled();\n const manager = useEditorStateManager();\n const setter = (value: boolean) => manager.editorEnabled.set(value);\n return [enabled, setter] as const;\n};\n"],"mappings":"6NAcA,MAAa,MAAkD,CAC7D,IAAM,EAAUA,EAAAA,uBAAuB,CACjC,CAAC,EAAS,IAAA,EAAA,EAAA,UACd,EAAQ,cAAc,OAAS,GAChC,CASD,OAPA,EAAA,EAAA,eAAgB,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,EAQP,EAA4B,GAA2B,CAClE,IAAM,EAAUA,EAAAA,uBAAuB,EAEvC,EAAA,EAAA,eAAgB,CACT,KACL,OAAO,EAAQ,UAAU,UACvB,GAAGC,EAAAA,WAAW,wBAAwB,MACtC,EACD,EACA,CAAC,EAAS,EAAU,CAAC,EAMb,MAAkC,CAC7C,IAAM,EAAUD,EAAAA,uBAAuB,CACvC,MAAQ,IAAmB,CACzB,EAAQ,cAAc,IAAI,EAAM,CAChC,EAAQ,cAAc,kBAAkB,GAI/B,MAA8B,CACzC,GAAM,CAAE,WAAY,GAAkB,CAChC,EAAUA,EAAAA,uBAAuB,CAEvC,MAAO,CAAC,EADQ,GAAmB,EAAQ,cAAc,IAAI,EAAM,CAC3C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`})
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./_virtual/_rolldown/runtime.cjs`),t=require(`./EditorStateContext.cjs`),n=require(`./EditorEnabledContext.cjs`);let r=require(`react`),i=require(`react/jsx-runtime`),a=require(`@intlayer/editor`),o=require(`@intlayer/config/built`);o=e.__toESM(o);const{editor:s}=o.default??{},c=()=>({allowedOrigins:[s?.applicationURL,s?.editorURL,s?.cmsURL].filter(Boolean),postMessageFn:(e,t)=>{typeof window>`u`||window.self!==window.top&&(window.parent?.postMessage(e,t),window.postMessage(e,t))}}),l=({children:e,fallback:t})=>{let{enabled:r}=n.useEditorEnabled();return r?e:t},u=({children:e,fallback:t})=>{let[n,i]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{i(window.self!==window.top)},[]),n?e:t},d=({children:e,mode:n=`client`,configuration:s,postMessage:d,allowedOrigins:f})=>{let p=(0,r.useRef)(null);p.current||=new a.EditorStateManager({mode:n,messenger:d||f?{allowedOrigins:f??[`*`],postMessageFn:d?e=>d(e):c().postMessageFn}:c(),configuration:s??o.default});let m=p.current;return(0,r.useEffect)(()=>((0,a.defineIntlayerElements)(),m.start(),()=>m.stop()),[m]),(0,i.jsx)(t.EditorStateProvider,{manager:m,children:n===`editor`?e:(0,i.jsx)(u,{fallback:e,children:(0,i.jsx)(l,{fallback:e,children:e})})})};exports.EditorProvider=d;
|
|
2
2
|
//# sourceMappingURL=EditorProvider.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorProvider.cjs","names":["
|
|
1
|
+
{"version":3,"file":"EditorProvider.cjs","names":["configuration","useEditorEnabled","EditorStateManager","EditorStateProvider"],"sources":["../../src/EditorProvider.tsx"],"sourcesContent":["'use client';\n\nimport 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 {\n type FC,\n type PropsWithChildren,\n type ReactNode,\n useEffect,\n useRef,\n useState,\n} from 'react';\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 = { fallback: ReactNode };\n\nconst EditorEnabledCheckRenderer: FC<PropsWithChildren<FallbackProps>> = ({\n children,\n fallback,\n}) => {\n const { enabled } = useEditorEnabled();\n return enabled ? children : fallback;\n};\n\nconst IframeCheckRenderer: FC<PropsWithChildren<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};\n\n/**\n * EditorProvider creates and manages the lifecycle of an EditorStateManager,\n * provides it to all descendants, and registers the Lit web components.\n */\nexport const EditorProvider: FC<PropsWithChildren<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"],"mappings":"yVAoBA,KAAM,CAAE,UAAWA,EAAAA,SAAiB,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,EAIK,GAAoE,CACxE,WACA,cACI,CACJ,GAAM,CAAE,WAAYC,EAAAA,kBAAkB,CACtC,OAAO,EAAU,EAAW,GAGxB,GAA6D,CACjE,WACA,cACI,CACJ,GAAM,CAAC,EAAY,IAAA,EAAA,EAAA,UAA0B,GAAM,CAMnD,OAJA,EAAA,EAAA,eAAgB,CACd,EAAc,OAAO,OAAS,OAAO,IAAI,EACxC,EAAE,CAAC,CAEC,EAAa,EAAW,GAcpB,GAA8D,CACzE,WACA,OAAO,SACP,cAAe,EACf,YAAa,EACb,eAAgB,KACZ,CACJ,IAAM,GAAA,EAAA,EAAA,QAA+C,KAAK,CAC1D,AAUE,EAAW,UAAU,IAAIC,EAAAA,mBAAmB,CAC1C,OACA,UAVA,GAAqB,EACjB,CACE,eAAgB,GAAwB,CAAC,IAAI,CAC7C,cAAe,EACV,GAAY,EAAkB,EAAQ,CACvC,GAA6B,CAAC,cACnC,CACD,GAA6B,CAIjC,cAAe,GAAcF,EAAAA,QAC9B,CAAC,CAEJ,IAAM,EAAU,EAAW,QAmB3B,OAjBA,EAAA,EAAA,iBACE,EAAA,EAAA,yBAAwB,CACxB,EAAQ,OAAO,KACF,EAAQ,MAAM,EAC1B,CAAC,EAAQ,CAAC,EAaN,EAAA,EAAA,KAACG,EAAAA,oBAAD,CAA8B,mBAVnC,IAAS,SACP,GAEA,EAAA,EAAA,KAAC,EAAD,CAAqB,SAAU,YAC7B,EAAA,EAAA,KAAC,EAAD,CAA4B,SAAU,EACnC,WAC0B,CAAA,CACT,CAAA,CAGmD,CAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);let e=require(`react`),t=require(`react/jsx-runtime`);const n=(0,e.createContext)(null),r=({children:e,manager:r})=>(0,t.jsx)(n.Provider,{value:r,children:e}),i=()=>{let t=(0,e.useContext)(n);if(!t)throw Error(`useEditorStateManager must be used within an EditorProvider`);return t};exports.EditorStateProvider=r,exports.useEditorStateManager=i;
|
|
2
|
+
//# sourceMappingURL=EditorStateContext.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EditorStateContext.cjs","names":[],"sources":["../../src/EditorStateContext.tsx"],"sourcesContent":["'use client';\n\nimport type { EditorStateManager } from '@intlayer/editor';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n} from 'react';\n\nconst EditorStateContext = createContext<EditorStateManager | null>(null);\n\nexport const EditorStateProvider: FC<\n PropsWithChildren<{ manager: EditorStateManager }>\n> = ({ children, manager }) => (\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(\n 'useEditorStateManager must be used within an EditorProvider'\n );\n }\n return ctx;\n};\n"],"mappings":"kLAUA,MAAM,GAAA,EAAA,EAAA,eAA8D,KAAK,CAE5D,GAER,CAAE,WAAU,cACf,EAAA,EAAA,KAAC,EAAmB,SAApB,CAA6B,MAAO,EACjC,WAC2B,CAAA,CAGnB,MAAkD,CAC7D,IAAM,GAAA,EAAA,EAAA,YAAiB,EAAmB,CAC1C,GAAI,CAAC,EACH,MAAU,MACR,8DACD,CAEH,OAAO"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./EditorStateContext.cjs`);let t=require(`react`);const n=()=>{let n=e.useEditorStateManager(),[r,i]=(0,t.useState)(n.focusedContent.value??null);return(0,t.useEffect)(()=>{let e=e=>i(e.detail);return n.focusedContent.addEventListener(`change`,e),()=>n.focusedContent.removeEventListener(`change`,e)},[n]),{focusedContent:r,setFocusedContent:e=>n.focusedContent.set(e),setFocusedContentKeyPath:e=>n.setFocusedContentKeyPath(e)}},r=()=>{let{setFocusedContent:e,setFocusedContentKeyPath:t}=n();return{setFocusedContent:e,setFocusedContentKeyPath:t}};exports.useFocusDictionary=n,exports.useFocusDictionaryActions=r;
|
|
2
2
|
//# sourceMappingURL=FocusDictionaryContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FocusDictionaryContext.cjs","names":["
|
|
1
|
+
{"version":3,"file":"FocusDictionaryContext.cjs","names":["useEditorStateManager"],"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport type { FileContent } from '@intlayer/editor';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type { FileContent } from '@intlayer/editor';\n\nexport type FocusDictionaryState = {\n focusedContent: FileContent | null;\n};\n\nexport type FocusDictionaryActions = {\n setFocusedContent: (value: FileContent | null) => void;\n setFocusedContentKeyPath: (keyPath: KeyPath[]) => void;\n};\n\n/**\n * Returns the focused-content state and setters, backed by EditorStateManager.\n */\nexport const useFocusDictionary = (): FocusDictionaryState &\n FocusDictionaryActions => {\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 = (): FocusDictionaryActions => {\n const { setFocusedContent, setFocusedContentKeyPath } = useFocusDictionary();\n return { setFocusedContent, setFocusedContentKeyPath };\n};\n"],"mappings":"+LAqBA,MAAa,MACe,CAC1B,IAAM,EAAUA,EAAAA,uBAAuB,CACjC,CAAC,EAAgB,IAAA,EAAA,EAAA,UACrB,EAAQ,eAAe,OAAS,KACjC,CASD,OAPA,EAAA,EAAA,eAAgB,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,MAA0D,CACrE,GAAM,CAAE,oBAAmB,4BAA6B,GAAoB,CAC5E,MAAO,CAAE,oBAAmB,2BAA0B"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./EditorStateContext.cjs`),t=require(`./FocusDictionaryContext.cjs`),n=require(`./useCrossFrameState.cjs`),r=require(`./useCrossURLPathState.cjs`),i=require(`./DictionariesRecordContext.cjs`),a=require(`./useEditorLocale.cjs`),o=require(`./useFocusUnmergedDictionary.cjs`),s=require(`./EditorEnabledContext.cjs`),c=require(`./EditorProvider.cjs`),l=require(`./CommunicatorContext.cjs`),u=require(`./ConfigurationContext.cjs`),d=require(`./EditedContentContext.cjs`),f=require(`./useCrossFrameMessageListener.cjs`),p=require(`./useIframeClickInterceptor.cjs`);exports.EditorProvider=c.EditorProvider,exports.EditorStateProvider=e.EditorStateProvider,exports.useCommunicator=l.useCommunicator,exports.useConfiguration=u.useConfiguration,exports.useConfigurationState=u.useConfigurationState,exports.useCrossFrameMessageListener=f.useCrossFrameMessageListener,exports.useCrossFrameState=n.useCrossFrameState,exports.useCrossURLPathSetter=r.useCrossURLPathSetter,exports.useCrossURLPathState=r.useCrossURLPathState,exports.useDictionariesRecord=i.useDictionariesRecord,exports.useDictionariesRecordActions=i.useDictionariesRecordActions,exports.useEditedContent=d.useEditedContent,exports.useEditedContentActions=d.useEditedContentActions,exports.useEditorEnabled=s.useEditorEnabled,exports.useEditorEnabledState=s.useEditorEnabledState,exports.useEditorLocale=a.useEditorLocale,exports.useEditorStateManager=e.useEditorStateManager,exports.useFocusDictionary=t.useFocusDictionary,exports.useFocusDictionaryActions=t.useFocusDictionaryActions,exports.useFocusUnmergedDictionary=o.useFocusUnmergedDictionary,exports.useGetEditedContentState=d.useGetEditedContentState,exports.useGetEditorEnabledState=s.useGetEditorEnabledState,exports.useIframeClickInterceptor=p.useIframeClickInterceptor,exports.useIframeClickMerger=p.useIframeClickMerger,exports.usePostEditedContentState=d.usePostEditedContentState,exports.usePostEditorEnabledState=s.usePostEditorEnabledState,exports.useSetEditorLocale=a.useSetEditorLocale;var m=require(`@intlayer/editor`);Object.keys(m).forEach(function(e){e!==`default`&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return m[e]}})});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./EditorStateContext.cjs`);let t=require(`react`);const n=(n,r,i)=>{let a=e.useEditorStateManager();return(0,t.useEffect)(()=>{if(r)return a.messenger.subscribe(n,r)},[a,n,i]),e=>{a.messenger.send(n,e)}};exports.useCrossFrameMessageListener=n;
|
|
2
2
|
//# sourceMappingURL=useCrossFrameMessageListener.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCrossFrameMessageListener.cjs","names":["
|
|
1
|
+
{"version":3,"file":"useCrossFrameMessageListener.cjs","names":["useEditorStateManager"],"sources":["../../src/useCrossFrameMessageListener.tsx"],"sourcesContent":["'use client';\n\nimport type { MessageKey } from '@intlayer/editor';\nimport { useEffect } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\n/**\n * Listens for cross-frame messages of the specified type and calls the callback.\n * Returns a function to manually send a message of the same type.\n *\n * Backed by CrossFrameMessenger from EditorStateManager.\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) => {\n manager.messenger.send(key, data);\n };\n};\n"],"mappings":"+LAYA,MAAa,GACX,EACA,EACA,IACG,CACH,IAAM,EAAUA,EAAAA,uBAAuB,CAOvC,OALA,EAAA,EAAA,eAAgB,CACT,KACL,OAAO,EAAQ,UAAU,UAAa,EAAK,EAAiB,EAC3D,CAAC,EAAS,EAAK,EAAY,CAAC,CAEvB,GAAa,CACnB,EAAQ,UAAU,KAAK,EAAK,EAAK"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./EditorStateContext.cjs`);let t=require(`react`),n=require(`@intlayer/editor`);const r=(r,i,a)=>{let o=e.useEditorStateManager(),s=typeof i==`function`?i():i,[c,l]=(0,t.useState)(s),u=(0,t.useRef)(s),d=(0,t.useRef)(null);return(0,t.useEffect)(()=>{let{emit:e=!0,receive:t=!0}=a??{},i=new n.CrossFrameStateManager(r,o.messenger,{emit:e,receive:t,initialValue:s});d.current=i;let c=e=>{let t=e.detail;u.current=t,l(t)};return i.addEventListener(`change`,c),i.start(),()=>{i.removeEventListener(`change`,c),i.stop(),d.current=null}},[r,o.messenger,a?.emit,a?.receive]),[c,e=>{l(t=>{let n=typeof e==`function`?e(t):e;return u.current=n,d.current?.set(n),n})},()=>{d.current?.postCurrentValue()}]};exports.useCrossFrameState=r;
|
|
2
2
|
//# sourceMappingURL=useCrossFrameState.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCrossFrameState.cjs","names":["
|
|
1
|
+
{"version":3,"file":"useCrossFrameState.cjs","names":["useEditorStateManager","CrossFrameStateManager"],"sources":["../../src/useCrossFrameState.tsx"],"sourcesContent":["'use client';\n\nimport { CrossFrameStateManager, type MessageKey } from '@intlayer/editor';\nimport {\n type Dispatch,\n type SetStateAction,\n useEffect,\n useRef,\n useState,\n} from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type CrossFrameStateOptions = {\n emit?: boolean;\n receive?: boolean;\n};\n\n/**\n * Synchronizes a React state value across frames using CrossFrameStateManager.\n */\nexport const useCrossFrameState = <S,>(\n key: `${MessageKey}`,\n initialState?: S | (() => S),\n options?: CrossFrameStateOptions\n): [S, Dispatch<SetStateAction<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 valueRef = useRef<S>(resolvedInitial as S);\n\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 const newValue = (e as CustomEvent<S>).detail;\n valueRef.current = newValue;\n setValueState(newValue);\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 // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [key, manager.messenger, options?.emit, options?.receive]);\n\n const setValue: Dispatch<SetStateAction<S>> = (valueOrUpdater) => {\n setValueState((prev) => {\n const newValue =\n typeof valueOrUpdater === 'function'\n ? (valueOrUpdater as (prev: S) => S)(prev)\n : valueOrUpdater;\n valueRef.current = newValue;\n stateManagerRef.current?.set(newValue);\n return newValue;\n });\n };\n\n const postState = () => {\n stateManagerRef.current?.postCurrentValue();\n };\n\n return [value, setValue, postState];\n};\n"],"mappings":"6NAoBA,MAAa,GACX,EACA,EACA,IACiD,CACjD,IAAM,EAAUA,EAAAA,uBAAuB,CAEjC,EACJ,OAAO,GAAiB,WACnB,GAA0B,CAC3B,EAEA,CAAC,EAAO,IAAA,EAAA,EAAA,UAA6B,EAAqB,CAC1D,GAAA,EAAA,EAAA,QAAqB,EAAqB,CAE1C,GAAA,EAAA,EAAA,QAA2D,KAAK,CA2CtE,OAzCA,EAAA,EAAA,eAAgB,CACd,GAAM,CAAE,OAAO,GAAM,UAAU,IAAS,GAAW,EAAE,CAC/C,EAAe,IAAIC,EAAAA,uBAA0B,EAAK,EAAQ,UAAW,CACzE,OACA,UACA,aAAc,EACf,CAAC,CACF,EAAgB,QAAU,EAE1B,IAAM,EAAW,GAAa,CAC5B,IAAM,EAAY,EAAqB,OACvC,EAAS,QAAU,EACnB,EAAc,EAAS,EAKzB,OAHA,EAAa,iBAAiB,SAAU,EAAQ,CAChD,EAAa,OAAO,KAEP,CACX,EAAa,oBAAoB,SAAU,EAAQ,CACnD,EAAa,MAAM,CACnB,EAAgB,QAAU,OAG3B,CAAC,EAAK,EAAQ,UAAW,GAAS,KAAM,GAAS,QAAQ,CAAC,CAkBtD,CAAC,EAhBuC,GAAmB,CAChE,EAAe,GAAS,CACtB,IAAM,EACJ,OAAO,GAAmB,WACrB,EAAkC,EAAK,CACxC,EAGN,MAFA,GAAS,QAAU,EACnB,EAAgB,SAAS,IAAI,EAAS,CAC/B,GACP,MAGoB,CACtB,EAAgB,SAAS,kBAAkB,EAGV"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./useCrossFrameState.cjs`);let t=require(`@intlayer/editor`)
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./useCrossFrameState.cjs`);let t=require(`@intlayer/editor`);const n=(n,r)=>e.useCrossFrameState(t.MessageKey.INTLAYER_URL_CHANGE,n,r),r=e=>n(e,{emit:!0,receive:!1});exports.useCrossURLPathSetter=r,exports.useCrossURLPathState=n;
|
|
2
2
|
//# sourceMappingURL=useCrossURLPathState.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCrossURLPathState.cjs","names":["useCrossFrameState","MessageKey"],"sources":["../../src/useCrossURLPathState.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport {
|
|
1
|
+
{"version":3,"file":"useCrossURLPathState.cjs","names":["useCrossFrameState","MessageKey"],"sources":["../../src/useCrossURLPathState.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport {\n type CrossFrameStateOptions,\n useCrossFrameState,\n} from './useCrossFrameState';\n\nexport const useCrossURLPathState = (\n initialState?: string,\n options?: CrossFrameStateOptions\n) => useCrossFrameState(MessageKey.INTLAYER_URL_CHANGE, initialState, options);\n\nexport const useCrossURLPathSetter = (initialState?: string) => {\n // The EditorStateManager already handles URL tracking in client mode via\n // UrlStateManager.start(). This hook remains for explicit use cases.\n return useCrossURLPathState(initialState, { emit: true, receive: false });\n};\n"],"mappings":"0MAQA,MAAa,GACX,EACA,IACGA,EAAAA,mBAAmBC,EAAAA,WAAW,oBAAqB,EAAc,EAAQ,CAEjE,EAAyB,GAG7B,EAAqB,EAAc,CAAE,KAAM,GAAM,QAAS,GAAO,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./EditorStateContext.cjs`);let t=require(`react`);const n=()=>{let n=e.useEditorStateManager(),[r,i]=(0,t.useState)(n.currentLocale.value);return(0,t.useEffect)(()=>{let e=e=>i(e.detail);return n.currentLocale.addEventListener(`change`,e),()=>n.currentLocale.removeEventListener(`change`,e)},[n]),r},r=()=>{let t=e.useEditorStateManager();return e=>t.currentLocale.set(e)};exports.useEditorLocale=n,exports.useSetEditorLocale=r;
|
|
2
2
|
//# sourceMappingURL=useEditorLocale.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditorLocale.cjs","names":["
|
|
1
|
+
{"version":3,"file":"useEditorLocale.cjs","names":["useEditorStateManager"],"sources":["../../src/useEditorLocale.tsx"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport { useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport const useEditorLocale = (): Locale | undefined => {\n const manager = useEditorStateManager();\n const [locale, setLocale] = useState<Locale | undefined>(\n manager.currentLocale.value\n );\n\n useEffect(() => {\n const handler = (e: Event) => setLocale((e as CustomEvent<Locale>).detail);\n manager.currentLocale.addEventListener('change', handler);\n return () => manager.currentLocale.removeEventListener('change', handler);\n }, [manager]);\n\n return locale;\n};\n\nexport const useSetEditorLocale = () => {\n const manager = useEditorStateManager();\n return (locale: Locale) => manager.currentLocale.set(locale);\n};\n"],"mappings":"kLAIA,MAAa,MAA4C,CACvD,IAAM,EAAUA,EAAAA,uBAAuB,CACjC,CAAC,EAAQ,IAAA,EAAA,EAAA,UACb,EAAQ,cAAc,MACvB,CAQD,OANA,EAAA,EAAA,eAAgB,CACd,IAAM,EAAW,GAAa,EAAW,EAA0B,OAAO,CAE1E,OADA,EAAQ,cAAc,iBAAiB,SAAU,EAAQ,KAC5C,EAAQ,cAAc,oBAAoB,SAAU,EAAQ,EACxE,CAAC,EAAQ,CAAC,CAEN,GAGI,MAA2B,CACtC,IAAM,EAAUA,EAAAA,uBAAuB,CACvC,MAAQ,IAAmB,EAAQ,cAAc,IAAI,EAAO"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./useCrossFrameMessageListener.cjs`);let t=require(`@intlayer/editor`)
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./useCrossFrameMessageListener.cjs`);let t=require(`@intlayer/editor`);const n=()=>{e.useCrossFrameMessageListener(t.MessageKey.INTLAYER_IFRAME_CLICKED)},r=()=>{e.useCrossFrameMessageListener(t.MessageKey.INTLAYER_IFRAME_CLICKED,t.mergeIframeClick)};exports.useIframeClickInterceptor=n,exports.useIframeClickMerger=r;
|
|
2
2
|
//# sourceMappingURL=useIframeClickInterceptor.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIframeClickInterceptor.cjs","names":["
|
|
1
|
+
{"version":3,"file":"useIframeClickInterceptor.cjs","names":["MessageKey","mergeIframeClick"],"sources":["../../src/useIframeClickInterceptor.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey, mergeIframeClick } from '@intlayer/editor';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\n\n/**\n * Broadcasts mousedown events from within an iframe to the parent frame.\n * Called in the client application (inside the iframe).\n * Note: EditorStateManager.start() already sets this up in client mode.\n * This hook exists for explicit / standalone use cases.\n */\nexport const useIframeClickInterceptor = () => {\n useCrossFrameMessageListener<undefined>(MessageKey.INTLAYER_IFRAME_CLICKED);\n};\n\n/**\n * Merges received iframe click events into the parent's DOM event stream.\n * Called in the editor (parent frame).\n */\nexport const useIframeClickMerger = () => {\n useCrossFrameMessageListener<MessageEvent>(\n MessageKey.INTLAYER_IFRAME_CLICKED,\n mergeIframeClick\n );\n};\n"],"mappings":"oNAWA,MAAa,MAAkC,CAC7C,EAAA,6BAAwCA,EAAAA,WAAW,wBAAwB,EAOhE,MAA6B,CACxC,EAAA,6BACEA,EAAAA,WAAW,wBACXC,EAAAA,iBACD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{
|
|
1
|
+
"use client";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/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport
|
|
1
|
+
{"version":3,"file":"CommunicatorContext.mjs","names":[],"sources":["../../src/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport type { MessagePayload } from '@intlayer/editor';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type UseCrossPlatformStateProps = {\n postMessage: (payload: MessagePayload) => void;\n allowedOrigins?: string[];\n senderId: string;\n};\n\n/**\n * Returns the communicator API backed by the shared EditorStateManager messenger.\n */\nexport const useCommunicator = (): UseCrossPlatformStateProps => {\n const manager = useEditorStateManager();\n\n return {\n postMessage: (payload: MessagePayload) =>\n manager.messenger.send(payload.type, payload.data),\n senderId: manager.messenger.senderId,\n };\n};\n\n// Re-export type for backward compatibility\nexport type { MessengerConfig } from '@intlayer/editor';\n"],"mappings":"8EAcA,MAAa,MAAoD,CAC/D,IAAM,EAAU,GAAuB,CAEvC,MAAO,CACL,YAAc,GACZ,EAAQ,UAAU,KAAK,EAAQ,KAAM,EAAQ,KAAK,CACpD,SAAU,EAAQ,UAAU,SAC7B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{
|
|
1
|
+
"use client";import{useEditorStateManager as e}from"./EditorStateContext.mjs";import{useEffect as t,useState as n}from"react";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},i=()=>{let t=e(),[r,i]=n(t.configuration.value);return[r,i,()=>t.configuration.postCurrentValue()]};export{r as useConfiguration,i as useConfigurationState};
|
|
2
2
|
//# sourceMappingURL=ConfigurationContext.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigurationContext.mjs","names":[],"sources":["../../src/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport
|
|
1
|
+
{"version":3,"file":"ConfigurationContext.mjs","names":[],"sources":["../../src/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type ConfigurationProviderProps = {\n configuration?: IntlayerConfig;\n};\n\n/**\n * Returns the current configuration, backed by EditorStateManager.\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\n/**\n * Returns a function that broadcasts the current configuration.\n */\nexport const useConfigurationState = () => {\n const manager = useEditorStateManager();\n\n const [config, setConfig] = useState<IntlayerConfig | undefined>(\n manager.configuration.value\n );\n\n return [\n config,\n setConfig,\n () => manager.configuration.postCurrentValue(),\n ] as const;\n};\n"],"mappings":"8HAaA,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,GAMI,MAA8B,CACzC,IAAM,EAAU,GAAuB,CAEjC,CAAC,EAAQ,GAAa,EAC1B,EAAQ,cAAc,MACvB,CAED,MAAO,CACL,EACA,MACM,EAAQ,cAAc,kBAAkB,CAC/C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{
|
|
1
|
+
"use client";import{useEditorStateManager as e}from"./EditorStateContext.mjs";import{useCallback as t,useEffect as n,useState as r}from"react";const i=()=>{let i=e(),[a,o]=r(i.localeDictionaries.value??{});return n(()=>{let e=e=>o(e.detail??{});return i.localeDictionaries.addEventListener(`change`,e),()=>i.localeDictionaries.removeEventListener(`change`,e)},[i]),{localeDictionaries:a,setLocaleDictionaries:t(e=>i.localeDictionaries.set(e),[i]),setLocaleDictionary:t(e=>i.setLocaleDictionary(e),[i])}},a=()=>{let{setLocaleDictionaries:e,setLocaleDictionary:t}=i();return{setLocaleDictionaries:e,setLocaleDictionary:t}};export{i as useDictionariesRecord,a as useDictionariesRecordActions};
|
|
2
2
|
//# sourceMappingURL=DictionariesRecordContext.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DictionariesRecordContext.mjs","names":[],"sources":["../../src/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"file":"DictionariesRecordContext.mjs","names":[],"sources":["../../src/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport type { DictionaryContent } from '@intlayer/editor';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { useCallback, useEffect, useState } from 'react';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type { DictionaryContent } from '@intlayer/editor';\n\ntype DictionariesRecordStatesContextType = {\n localeDictionaries: DictionaryContent;\n};\ntype DictionariesRecordActionsContextType = {\n setLocaleDictionaries: (value: DictionaryContent) => void;\n setLocaleDictionary: (dictionary: Dictionary) => void;\n};\n\n/**\n * Returns dictionaries record state and setters, backed by EditorStateManager.\n * Replaces the old DictionariesRecordContext + DictionariesRecordProvider.\n */\nexport const useDictionariesRecord = (): DictionariesRecordStatesContextType &\n DictionariesRecordActionsContextType => {\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 const setLocaleDictionaries = useCallback(\n (value: DictionaryContent) => manager.localeDictionaries.set(value),\n [manager]\n );\n\n const setLocaleDictionary = useCallback(\n (dictionary: Dictionary) => manager.setLocaleDictionary(dictionary),\n [manager]\n );\n\n return { localeDictionaries, setLocaleDictionaries, setLocaleDictionary };\n};\n\nexport const useDictionariesRecordActions =\n (): DictionariesRecordActionsContextType => {\n const { setLocaleDictionaries, setLocaleDictionary } =\n useDictionariesRecord();\n return { setLocaleDictionaries, setLocaleDictionary };\n };\n"],"mappings":"+IAqBA,MAAa,MAC6B,CACxC,IAAM,EAAU,GAAuB,CACjC,CAAC,EAAoB,GACzB,EAA4B,EAAQ,mBAAmB,OAAS,EAAE,CAAC,CAsBrE,OApBA,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,CAYN,CAAE,qBAAoB,sBAVC,EAC3B,GAA6B,EAAQ,mBAAmB,IAAI,EAAM,CACnE,CAAC,EAAQ,CACV,CAOmD,oBALxB,EACzB,GAA2B,EAAQ,oBAAoB,EAAW,CACnE,CAAC,EAAQ,CACV,CAEwE,EAG9D,MACiC,CAC1C,GAAM,CAAE,wBAAuB,uBAC7B,GAAuB,CACzB,MAAO,CAAE,wBAAuB,sBAAqB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{
|
|
1
|
+
"use client";import{useEditorStateManager as e}from"./EditorStateContext.mjs";import{useEffect as t,useState as n}from"react";const r=()=>{let t=e();return{setEditedContentState:e=>t.editedContent.set(e),setEditedDictionary:e=>t.setEditedDictionary(e),setEditedContent:(e,n)=>t.setEditedContent(e,n),addEditedContent:(e,n,r,i)=>t.addContent(e,n,r,i),renameEditedContent:(e,n,r)=>t.renameContent(e,n,r),removeEditedContent:(e,n)=>t.removeContent(e,n),restoreEditedContent:e=>t.restoreContent(e),clearEditedDictionaryContent:e=>t.clearContent(e),clearEditedContent:()=>t.clearAllContent(),getEditedContentValue:(e,n)=>t.getContentValue(e,n)}},i=()=>{let i=e(),[a,o]=n(i.editedContent.value);return t(()=>{let e=e=>o(e.detail);return i.editedContent.addEventListener(`change`,e),()=>i.editedContent.removeEventListener(`change`,e)},[i]),{editedContent:a,...r()}},a=n=>{let r=e();t(()=>{if(n)return r.messenger.subscribe(`INTLAYER_EDITED_CONTENT_CHANGED/post`,n)},[r,n])},o=t=>{let n=e();return()=>{n.messenger.send(`INTLAYER_EDITED_CONTENT_CHANGED/get`)}};export{i as useEditedContent,r as useEditedContentActions,o as useGetEditedContentState,a as usePostEditedContentState};
|
|
2
2
|
//# sourceMappingURL=EditedContentContext.mjs.map
|