@intlayer/editor-react 8.2.4 → 8.3.0-canary.0
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/EditorProvider.cjs +1 -1
- 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/useCrossURLPathState.cjs +1 -1
- package/dist/cjs/useEditorLocale.cjs.map +1 -1
- package/dist/cjs/useFocusUnmergedDictionary.cjs +1 -1
- package/dist/cjs/useFocusUnmergedDictionary.cjs.map +1 -1
- package/dist/cjs/useIframeClickInterceptor.cjs +1 -1
- package/dist/esm/CommunicatorContext.mjs +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/EditorProvider.mjs +1 -1
- 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/useCrossURLPathState.mjs +1 -1
- package/dist/esm/useEditorLocale.mjs.map +1 -1
- package/dist/esm/useFocusUnmergedDictionary.mjs +1 -1
- package/dist/esm/useFocusUnmergedDictionary.mjs.map +1 -1
- package/dist/esm/useIframeClickInterceptor.mjs +1 -1
- package/dist/types/ConfigurationContext.d.ts +1 -1
- package/dist/types/DictionariesRecordContext.d.ts +1 -1
- package/dist/types/EditedContentContext.d.ts +2 -1
- package/dist/types/EditedContentContext.d.ts.map +1 -1
- package/dist/types/FocusDictionaryContext.d.ts +2 -1
- package/dist/types/FocusDictionaryContext.d.ts.map +1 -1
- package/dist/types/useEditorLocale.d.ts +1 -1
- package/dist/types/useFocusUnmergedDictionary.d.ts +1 -1
- package/dist/types/useFocusUnmergedDictionary.d.ts.map +1 -1
- package/package.json +17 -17
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./_virtual/_rolldown/runtime.cjs`);let t=require(
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./_virtual/_rolldown/runtime.cjs`);let t=require(`react/jsx-runtime`),n=require(`react`),r=require(`@intlayer/config/built`);r=e.__toESM(r);const i=()=>Math.random().toString(36).slice(2),{editor:a}=r.default??{},o=(0,n.createContext)({postMessage:()=>null,allowedOrigins:[a?.applicationURL,a?.editorURL,a?.cmsURL],senderId:``}),s=({children:e,allowedOrigins:r,postMessage:a})=>{let s=(0,n.useRef)(i()),c=(0,n.useMemo)(()=>({postMessage:a,allowedOrigins:r,senderId:s.current}),[a,r,s.current]);return(0,t.jsx)(o.Provider,{value:c,children:e})},c=()=>(0,n.useContext)(o);exports.CommunicatorProvider=s,exports.useCommunicator=c;
|
|
2
2
|
//# sourceMappingURL=CommunicatorContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommunicatorContext.cjs","names":["configuration"],"sources":["../../src/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n useMemo,\n useRef,\n} from 'react';\n\nconst randomUUID = () => Math.random().toString(36).slice(2);\n\nexport type UseCrossPlatformStateProps = {\n postMessage: typeof window.postMessage;\n allowedOrigins?: string[];\n senderId: string;\n};\n\nconst { editor } = configuration ?? {};\n\nconst CommunicatorContext = createContext<UseCrossPlatformStateProps>({\n postMessage: () => null,\n allowedOrigins: [\n editor?.applicationURL,\n editor?.editorURL,\n editor?.cmsURL,\n ] as string[],\n senderId: '',\n});\n\nexport type CommunicatorProviderProps = PropsWithChildren<\n Omit<UseCrossPlatformStateProps, 'senderId'>\n>;\n\nexport const CommunicatorProvider: FC<CommunicatorProviderProps> = ({\n children,\n allowedOrigins,\n postMessage,\n}) => {\n // Create a stable, unique ID for the lifetime of this app/iframe instance.\n const senderIdRef = useRef(randomUUID());\n\n const value = useMemo(\n () => ({ postMessage, allowedOrigins, senderId: senderIdRef.current }),\n [postMessage, allowedOrigins, senderIdRef.current]\n );\n\n return (\n <CommunicatorContext.Provider value={value}>\n {children}\n </CommunicatorContext.Provider>\n );\n};\n\nexport const useCommunicator = () => useContext(CommunicatorContext);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"CommunicatorContext.cjs","names":["configuration"],"sources":["../../src/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n useMemo,\n useRef,\n} from 'react';\n\nconst randomUUID = () => Math.random().toString(36).slice(2);\n\nexport type UseCrossPlatformStateProps = {\n postMessage: typeof window.postMessage;\n allowedOrigins?: string[];\n senderId: string;\n};\n\nconst { editor } = configuration ?? {};\n\nconst CommunicatorContext = createContext<UseCrossPlatformStateProps>({\n postMessage: () => null,\n allowedOrigins: [\n editor?.applicationURL,\n editor?.editorURL,\n editor?.cmsURL,\n ] as string[],\n senderId: '',\n});\n\nexport type CommunicatorProviderProps = PropsWithChildren<\n Omit<UseCrossPlatformStateProps, 'senderId'>\n>;\n\nexport const CommunicatorProvider: FC<CommunicatorProviderProps> = ({\n children,\n allowedOrigins,\n postMessage,\n}) => {\n // Create a stable, unique ID for the lifetime of this app/iframe instance.\n const senderIdRef = useRef(randomUUID());\n\n const value = useMemo(\n () => ({ postMessage, allowedOrigins, senderId: senderIdRef.current }),\n [postMessage, allowedOrigins, senderIdRef.current]\n );\n\n return (\n <CommunicatorContext.Provider value={value}>\n {children}\n </CommunicatorContext.Provider>\n );\n};\n\nexport const useCommunicator = () => useContext(CommunicatorContext);\n"],"mappings":"6OAYA,MAAM,MAAmB,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,MAAM,EAAE,CAQtD,CAAE,UAAWA,EAAAA,SAAiB,EAAE,CAEhC,GAAA,EAAA,EAAA,eAAgE,CACpE,gBAAmB,KACnB,eAAgB,CACd,GAAQ,eACR,GAAQ,UACR,GAAQ,OACT,CACD,SAAU,GACX,CAAC,CAMW,GAAuD,CAClE,WACA,iBACA,iBACI,CAEJ,IAAM,GAAA,EAAA,EAAA,QAAqB,GAAY,CAAC,CAElC,GAAA,EAAA,EAAA,cACG,CAAE,cAAa,iBAAgB,SAAU,EAAY,QAAS,EACrE,CAAC,EAAa,EAAgB,EAAY,QAAQ,CACnD,CAED,OACE,EAAA,EAAA,KAAC,EAAoB,SAArB,CAAqC,QAClC,WAC4B,CAAA,EAItB,OAAA,EAAA,EAAA,YAAmC,EAAoB"}
|
|
@@ -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(`
|
|
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`),n=require(`react/jsx-runtime`),r=require(`react`);const i=(0,r.createContext)(void 0),a=()=>e.useCrossFrameState(t.MessageKey.INTLAYER_CONFIGURATION,void 0,{receive:!1,emit:!0}),o=({children:e,configuration:t})=>(0,n.jsx)(i.Provider,{value:t,children:e}),s=()=>(0,r.useContext)(i);exports.ConfigurationProvider=o,exports.useConfiguration=s,exports.useConfigurationState=a;
|
|
2
2
|
//# sourceMappingURL=ConfigurationContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigurationContext.cjs","names":["useCrossFrameState","MessageKey"],"sources":["../../src/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nconst ConfigurationStatesContext = createContext<IntlayerConfig | undefined>(\n undefined\n);\n\nexport const useConfigurationState = () =>\n useCrossFrameState<IntlayerConfig>(\n MessageKey.INTLAYER_CONFIGURATION,\n undefined,\n {\n receive: false,\n emit: true,\n }\n );\n\nexport type ConfigurationProviderProps = {\n configuration?: IntlayerConfig;\n};\n\nexport const ConfigurationProvider: FC<\n PropsWithChildren<ConfigurationProviderProps>\n> = ({ children, configuration }) => (\n <ConfigurationStatesContext.Provider value={configuration}>\n {children}\n </ConfigurationStatesContext.Provider>\n);\n\nexport const useConfiguration = () => useContext(ConfigurationStatesContext);\n"],"mappings":"4PAYA,MAAM,GAAA,EAAA,EAAA,eACJ,IAAA,GACD,CAEY,MACXA,EAAAA,mBACEC,EAAAA,WAAW,uBACX,IAAA,GACA,CACE,QAAS,GACT,KAAM,GACP,CACF,CAMU,GAER,CAAE,WAAU,oBACf,EAAA,EAAA,KAAC,EAA2B,SAA5B,CAAqC,MAAO,EACzC,WACmC,CAAA,CAG3B,OAAA,EAAA,EAAA,YAAoC,EAA2B"}
|
|
1
|
+
{"version":3,"file":"ConfigurationContext.cjs","names":["useCrossFrameState","MessageKey"],"sources":["../../src/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nconst ConfigurationStatesContext = createContext<IntlayerConfig | undefined>(\n undefined\n);\n\nexport const useConfigurationState = () =>\n useCrossFrameState<IntlayerConfig>(\n MessageKey.INTLAYER_CONFIGURATION,\n undefined,\n {\n receive: false,\n emit: true,\n }\n );\n\nexport type ConfigurationProviderProps = {\n configuration?: IntlayerConfig;\n};\n\nexport const ConfigurationProvider: FC<\n PropsWithChildren<ConfigurationProviderProps>\n> = ({ children, configuration }) => (\n <ConfigurationStatesContext.Provider value={configuration}>\n {children}\n </ConfigurationStatesContext.Provider>\n);\n\nexport const useConfiguration = () => useContext(ConfigurationStatesContext);\n"],"mappings":"4PAYA,MAAM,GAAA,EAAA,EAAA,eACJ,IAAA,GACD,CAEY,MACXA,EAAAA,mBACEC,EAAAA,WAAW,uBACX,IAAA,GACA,CACE,QAAS,GACT,KAAM,GACP,CACF,CAMU,GAER,CAAE,WAAU,oBACf,EAAA,EAAA,KAAC,EAA2B,SAA5B,CAAqC,MAAO,EACzC,WACmC,CAAA,CAG3B,OAAA,EAAA,EAAA,YAAoC,EAA2B"}
|
|
@@ -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(`
|
|
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`),n=require(`react/jsx-runtime`),r=require(`react`);const i=(0,r.createContext)(void 0),a=(0,r.createContext)(void 0),o=({children:o})=>{let[s,c]=e.useCrossFrameState(t.MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED,void 0),l=(0,r.useMemo)(()=>({localeDictionaries:s??{}}),[s]),u=(0,r.useMemo)(()=>({setLocaleDictionaries:c,setLocaleDictionary:e=>{e.localId&&c(t=>({...t,[e.localId]:e}))}}),[c]);return(0,n.jsx)(i.Provider,{value:l,children:(0,n.jsx)(a.Provider,{value:u,children:o})})},s=()=>(0,r.useContext)(a),c=()=>{let e=s(),t=(0,r.useContext)(i);if(!t)throw Error(`useDictionariesRecordStates must be used within a DictionariesRecordProvider`);return{...t,...e}};exports.DictionariesRecordProvider=o,exports.useDictionariesRecord=c,exports.useDictionariesRecordActions=s;
|
|
2
2
|
//# sourceMappingURL=DictionariesRecordContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DictionariesRecordContext.cjs","names":["useCrossFrameState","MessageKey"],"sources":["../../src/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { Dictionary, LocalDictionaryId } from '@intlayer/types';\nimport {\n createContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n useContext,\n useMemo,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport type DictionaryContent = Record<LocalDictionaryId, Dictionary>;\n\ntype DictionariesRecordStatesContextType = {\n localeDictionaries: DictionaryContent;\n};\ntype DictionariesRecordActionsContextType = {\n setLocaleDictionaries: Dispatch<SetStateAction<DictionaryContent>>;\n setLocaleDictionary: (dictionary: Dictionary) => void;\n};\n\nconst DictionariesRecordStatesContext = createContext<\n DictionariesRecordStatesContextType | undefined\n>(undefined);\nconst DictionariesRecordActionsContext = createContext<\n DictionariesRecordActionsContextType | undefined\n>(undefined);\n\nexport const DictionariesRecordProvider: FC<PropsWithChildren> = ({\n children,\n}) => {\n const [localeDictionaries, setLocaleDictionaries] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED,\n undefined\n );\n\n const stateValue = useMemo(\n () => ({\n localeDictionaries: localeDictionaries ?? {},\n }),\n [localeDictionaries]\n );\n\n const actionValue = useMemo(\n () => ({\n setLocaleDictionaries,\n setLocaleDictionary: (dictionary: Dictionary) => {\n if (!dictionary.localId) return;\n\n setLocaleDictionaries((dictionaries) => ({\n ...dictionaries,\n [dictionary.localId as LocalDictionaryId]: dictionary,\n }));\n },\n }),\n [setLocaleDictionaries]\n );\n\n return (\n <DictionariesRecordStatesContext.Provider value={stateValue}>\n <DictionariesRecordActionsContext.Provider value={actionValue}>\n {children}\n </DictionariesRecordActionsContext.Provider>\n </DictionariesRecordStatesContext.Provider>\n );\n};\n\nexport const useDictionariesRecordActions = () =>\n useContext(DictionariesRecordActionsContext);\n\nexport const useDictionariesRecord = () => {\n const actionsContext = useDictionariesRecordActions();\n const statesContext = useContext(DictionariesRecordStatesContext);\n\n if (!statesContext) {\n throw new Error(\n 'useDictionariesRecordStates must be used within a DictionariesRecordProvider'\n );\n }\n\n return { ...statesContext, ...actionsContext };\n};\n"],"mappings":"4PAyBA,MAAM,GAAA,EAAA,EAAA,eAEJ,IAAA,GAAU,CACN,GAAA,EAAA,EAAA,eAEJ,IAAA,GAAU,CAEC,GAAqD,CAChE,cACI,CACJ,GAAM,CAAC,EAAoB,GACzBA,EAAAA,mBACEC,EAAAA,WAAW,qCACX,IAAA,GACD,CAEG,GAAA,EAAA,EAAA,cACG,CACL,mBAAoB,GAAsB,EAAE,CAC7C,EACD,CAAC,EAAmB,CACrB,CAEK,GAAA,EAAA,EAAA,cACG,CACL,wBACA,oBAAsB,GAA2B,CAC1C,EAAW,SAEhB,EAAuB,IAAkB,CACvC,GAAG,GACF,EAAW,SAA+B,EAC5C,EAAE,EAEN,EACD,CAAC,EAAsB,CACxB,CAED,OACE,EAAA,EAAA,KAAC,EAAgC,SAAjC,CAA0C,MAAO,YAC/C,EAAA,EAAA,KAAC,EAAiC,SAAlC,CAA2C,MAAO,EAC/C,WACyC,CAAA,CACH,CAAA,EAIlC,OAAA,EAAA,EAAA,YACA,EAAiC,CAEjC,MAA8B,CACzC,IAAM,EAAiB,GAA8B,CAC/C,GAAA,EAAA,EAAA,YAA2B,EAAgC,CAEjE,GAAI,CAAC,EACH,MAAU,MACR,+EACD,CAGH,MAAO,CAAE,GAAG,EAAe,GAAG,EAAgB"}
|
|
1
|
+
{"version":3,"file":"DictionariesRecordContext.cjs","names":["useCrossFrameState","MessageKey"],"sources":["../../src/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { Dictionary, LocalDictionaryId } from '@intlayer/types/dictionary';\nimport {\n createContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n useContext,\n useMemo,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport type DictionaryContent = Record<LocalDictionaryId, Dictionary>;\n\ntype DictionariesRecordStatesContextType = {\n localeDictionaries: DictionaryContent;\n};\ntype DictionariesRecordActionsContextType = {\n setLocaleDictionaries: Dispatch<SetStateAction<DictionaryContent>>;\n setLocaleDictionary: (dictionary: Dictionary) => void;\n};\n\nconst DictionariesRecordStatesContext = createContext<\n DictionariesRecordStatesContextType | undefined\n>(undefined);\nconst DictionariesRecordActionsContext = createContext<\n DictionariesRecordActionsContextType | undefined\n>(undefined);\n\nexport const DictionariesRecordProvider: FC<PropsWithChildren> = ({\n children,\n}) => {\n const [localeDictionaries, setLocaleDictionaries] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED,\n undefined\n );\n\n const stateValue = useMemo(\n () => ({\n localeDictionaries: localeDictionaries ?? {},\n }),\n [localeDictionaries]\n );\n\n const actionValue = useMemo(\n () => ({\n setLocaleDictionaries,\n setLocaleDictionary: (dictionary: Dictionary) => {\n if (!dictionary.localId) return;\n\n setLocaleDictionaries((dictionaries) => ({\n ...dictionaries,\n [dictionary.localId as LocalDictionaryId]: dictionary,\n }));\n },\n }),\n [setLocaleDictionaries]\n );\n\n return (\n <DictionariesRecordStatesContext.Provider value={stateValue}>\n <DictionariesRecordActionsContext.Provider value={actionValue}>\n {children}\n </DictionariesRecordActionsContext.Provider>\n </DictionariesRecordStatesContext.Provider>\n );\n};\n\nexport const useDictionariesRecordActions = () =>\n useContext(DictionariesRecordActionsContext);\n\nexport const useDictionariesRecord = () => {\n const actionsContext = useDictionariesRecordActions();\n const statesContext = useContext(DictionariesRecordStatesContext);\n\n if (!statesContext) {\n throw new Error(\n 'useDictionariesRecordStates must be used within a DictionariesRecordProvider'\n );\n }\n\n return { ...statesContext, ...actionsContext };\n};\n"],"mappings":"4PAyBA,MAAM,GAAA,EAAA,EAAA,eAEJ,IAAA,GAAU,CACN,GAAA,EAAA,EAAA,eAEJ,IAAA,GAAU,CAEC,GAAqD,CAChE,cACI,CACJ,GAAM,CAAC,EAAoB,GACzBA,EAAAA,mBACEC,EAAAA,WAAW,qCACX,IAAA,GACD,CAEG,GAAA,EAAA,EAAA,cACG,CACL,mBAAoB,GAAsB,EAAE,CAC7C,EACD,CAAC,EAAmB,CACrB,CAEK,GAAA,EAAA,EAAA,cACG,CACL,wBACA,oBAAsB,GAA2B,CAC1C,EAAW,SAEhB,EAAuB,IAAkB,CACvC,GAAG,GACF,EAAW,SAA+B,EAC5C,EAAE,EAEN,EACD,CAAC,EAAsB,CACxB,CAED,OACE,EAAA,EAAA,KAAC,EAAgC,SAAjC,CAA0C,MAAO,YAC/C,EAAA,EAAA,KAAC,EAAiC,SAAlC,CAA2C,MAAO,EAC/C,WACyC,CAAA,CACH,CAAA,EAIlC,OAAA,EAAA,EAAA,YACA,EAAiC,CAEjC,MAA8B,CACzC,IAAM,EAAiB,GAA8B,CAC/C,GAAA,EAAA,EAAA,YAA2B,EAAgC,CAEjE,GAAI,CAAC,EACH,MAAU,MACR,+EACD,CAGH,MAAO,CAAE,GAAG,EAAe,GAAG,EAAgB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./useCrossFrameMessageListener.cjs`),t=require(`./useCrossFrameState.cjs`),n=require(`./DictionariesRecordContext.cjs`),r=require(`./useEditorLocale.cjs`);let i=require(`
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./useCrossFrameMessageListener.cjs`),t=require(`./useCrossFrameState.cjs`),n=require(`./DictionariesRecordContext.cjs`),r=require(`./useEditorLocale.cjs`);let i=require(`@intlayer/editor`),a=require(`react/jsx-runtime`),o=require(`@intlayer/types/nodeType`),s=require(`react`),c=require(`@intlayer/core/dictionaryManipulator`);const l=(0,s.createContext)(void 0),u=t=>e.useCrossFrameMessageListener(`${i.MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/post`,t),d=t=>e.useCrossFrameMessageListener(`${i.MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/get`,t),f=(0,s.createContext)(void 0),p=(e,t)=>typeof e==`function`?e(t):e,m=({children:e})=>{let{localeDictionaries:s}=n.useDictionariesRecord(),u=r.useEditorLocale(),[d,m]=t.useCrossFrameState(i.MessageKey.INTLAYER_EDITED_CONTENT_CHANGED);return(0,a.jsx)(l.Provider,{value:{editedContent:d},children:(0,a.jsx)(f.Provider,{value:{setEditedContentState:m,setEditedDictionary:e=>{let t=p(e);return m(n=>t.localId?(t=p(e,n?.[t.localId]),{...n,[t.localId]:t}):(console.error(`no localId`,t),n)),t},setEditedContent:(e,t)=>{m(n=>({...n,[e]:{...n?.[e],content:t}}))},addEditedContent:(e,t,n=[],r=!0)=>{m(i=>{let a=s[e]?.content,o=structuredClone(i?.[e]?.content??a),l=n;if(!r){let e=0,t=n.slice(0,-1),r=n[n.length-1],i=r.key;for(;(0,c.getContentNodeByKeyPath)(o,l)!==void 0;)e++,i=e===0?r.key:`${r.key} (${e})`,l=[...t,{...r,key:i}]}let u=(0,c.editDictionaryByKeyPath)(o,l,t);return{...i,[e]:{...i?.[e],content:u}}})},renameEditedContent:(e,t,n=[])=>{m(r=>{let i=s[e]?.content,a=(0,c.renameContentNodeByKeyPath)(structuredClone(r?.[e]?.content??i),t,n);return{...r,[e]:{...r?.[e],content:a}}})},removeEditedContent:(e,t)=>{m(n=>{let r=s[e]?.content,i=(0,c.editDictionaryByKeyPath)(structuredClone(n?.[e]?.content??r),t,(0,c.getContentNodeByKeyPath)(r,t));return{...n,[e]:{...n?.[e],content:i}}})},restoreEditedContent:e=>{m(t=>{let n={...t};return delete n[e],n})},clearEditedDictionaryContent:e=>{m(t=>{let n={...t};return delete n[e],n})},clearEditedContent:()=>{m({})},getEditedContentValue:(e,t)=>{if(!d)return;let n=t.filter(e=>e.type!==o.NodeType.Translation);if(e.includes(`:local:`)||e.includes(`:remote:`))return(0,c.getContentNodeByKeyPath)(d?.[e]?.content??{},n,u);let r=Object.keys(d).filter(t=>t.startsWith(`${e}:`));for(let e of r){let t=(0,c.getContentNodeByKeyPath)(d?.[e]?.content??{},n,u);if(t)return t}}},children:e})})},h=()=>(0,s.useContext)(f),g=()=>{let e=(0,s.useContext)(l),t=h();return{...e,...t}};exports.EditedContentProvider=m,exports.useEditedContent=g,exports.useEditedContentActions=h,exports.useGetEditedContentState=d,exports.usePostEditedContentState=u;
|
|
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 {\n type ContentNode,\n type Dictionary,\n type KeyPath,\n type LocalDictionaryId,\n NodeType,\n} from '@intlayer/types';\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":"2cAmCA,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":["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,2 +1,2 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./useCrossFrameMessageListener.cjs`),t=require(`./useCrossFrameState.cjs`);let n=require(`
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./useCrossFrameMessageListener.cjs`),t=require(`./useCrossFrameState.cjs`);let n=require(`@intlayer/editor`),r=require(`react/jsx-runtime`),i=require(`react`);const a=(0,i.createContext)({enabled:!1}),o=e=>t.useCrossFrameState(n.MessageKey.INTLAYER_EDITOR_ENABLED,!1,e),s=t=>e.useCrossFrameMessageListener(`${n.MessageKey.INTLAYER_EDITOR_ENABLED}/post`,t),c=t=>e.useCrossFrameMessageListener(`${n.MessageKey.INTLAYER_EDITOR_ENABLED}/get`,t),l=({children:e})=>{let[t]=o({emit:!1,receive:!0});return(0,r.jsx)(a.Provider,{value:{enabled:t},children:e})},u=()=>(0,i.useContext)(a);exports.EditorEnabledProvider=l,exports.useEditorEnabled=u,exports.useEditorEnabledState=o,exports.useGetEditorEnabledState=c,exports.usePostEditorEnabledState=s;
|
|
2
2
|
//# sourceMappingURL=EditorEnabledContext.cjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./CommunicatorContext.cjs`),t=require(`./
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./CommunicatorContext.cjs`),t=require(`./FocusDictionaryContext.cjs`),n=require(`./DictionariesRecordContext.cjs`),r=require(`./ConfigurationContext.cjs`),i=require(`./EditedContentContext.cjs`),a=require(`./EditorEnabledContext.cjs`);let o=require(`react/jsx-runtime`),s=require(`react`);const c=({children:e})=>{let r=i.useGetEditedContentState();return(0,s.useEffect)(()=>{r()},[]),(0,o.jsx)(n.DictionariesRecordProvider,{children:(0,o.jsx)(i.EditedContentProvider,{children:(0,o.jsx)(t.FocusDictionaryProvider,{children:e})})})},l=({children:e,fallback:t})=>{let n=a.useGetEditorEnabledState(),{enabled:r}=a.useEditorEnabled();return(0,s.useEffect)(()=>{r||n()},[r]),r?e:t},u=({children:e,fallback:t})=>{let[n,r]=(0,s.useState)(!1);return(0,s.useEffect)(()=>{r(window.self!==window.top)},[]),n?e:t},d=({children:t,configuration:n,...i})=>(0,o.jsx)(a.EditorEnabledProvider,{children:(0,o.jsx)(r.ConfigurationProvider,{configuration:n,children:i.mode===`editor`?(0,o.jsx)(e.CommunicatorProvider,{...i,children:(0,o.jsx)(c,{children:t})}):(0,o.jsx)(u,{fallback:t,children:(0,o.jsx)(e.CommunicatorProvider,{...i,children:(0,o.jsx)(l,{fallback:t,children:(0,o.jsx)(c,{children:t})})})})})});exports.EditorProvider=d;
|
|
2
2
|
//# sourceMappingURL=EditorProvider.cjs.map
|
|
@@ -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(`
|
|
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`),n=require(`react/jsx-runtime`),r=require(`@intlayer/types/nodeType`),i=require(`react`);const a=(0,i.createContext)(void 0),o=(0,i.createContext)(void 0),s=({children:i})=>{let[s,c]=e.useCrossFrameState(t.MessageKey.INTLAYER_FOCUSED_CONTENT_CHANGED,null);return(0,n.jsx)(a.Provider,{value:{focusedContent:s},children:(0,n.jsx)(o.Provider,{value:{setFocusedContent:c,setFocusedContentKeyPath:e=>{c(t=>{if(!t)return t;let n=e.filter(e=>e.type!==r.NodeType.Translation);return{...t,keyPath:n}})}},children:i})})},c=()=>{let e=(0,i.useContext)(o);if(e===void 0)throw Error(`useFocusDictionaryActions must be used within a FocusDictionaryProvider`);return e},l=()=>{let e=c(),t=(0,i.useContext)(a);if(t===void 0)throw Error(`useFocusDictionaryState must be used within a FocusDictionaryProvider`);return{...t,...e}};exports.FocusDictionaryProvider=s,exports.useFocusDictionary=l,exports.useFocusDictionaryActions=c;
|
|
2
2
|
//# sourceMappingURL=FocusDictionaryContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FocusDictionaryContext.cjs","names":["useCrossFrameState","MessageKey","NodeType"],"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport
|
|
1
|
+
{"version":3,"file":"FocusDictionaryContext.cjs","names":["useCrossFrameState","MessageKey","NodeType"],"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { LocalDictionaryId } from '@intlayer/types/dictionary';;\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 { useCrossFrameState } from './useCrossFrameState';\n\nexport type FileContent = {\n dictionaryKey: string;\n dictionaryLocalId?: LocalDictionaryId;\n keyPath?: KeyPath[];\n};\n\nexport type FocusDictionaryState = {\n focusedContent: FileContent | null;\n};\n\nexport type FocusDictionaryActions = {\n setFocusedContent: Dispatch<SetStateAction<FileContent | null>>;\n setFocusedContentKeyPath: (keyPath: KeyPath[]) => void;\n};\n\nconst FocusDictionaryStateContext = createContext<\n FocusDictionaryState | undefined\n>(undefined);\nconst FocusDictionaryActionsContext = createContext<\n FocusDictionaryActions | undefined\n>(undefined);\n\nexport const FocusDictionaryProvider: FC<PropsWithChildren> = ({\n children,\n}) => {\n const [focusedContent, setFocusedContent] =\n useCrossFrameState<FileContent | null>(\n MessageKey.INTLAYER_FOCUSED_CONTENT_CHANGED,\n null\n );\n\n const setFocusedContentKeyPath = (keyPath: KeyPath[]) => {\n setFocusedContent((prev) => {\n if (!prev) {\n return prev; // nothing to update if there's no focused content\n }\n\n // Remove translation key path if it exists to make it more flexible with optimization client / editor\n const filteredKeyPath = keyPath.filter(\n (key) => key.type !== NodeType.Translation\n );\n\n return {\n ...prev,\n keyPath: filteredKeyPath,\n };\n });\n };\n\n return (\n <FocusDictionaryStateContext.Provider value={{ focusedContent }}>\n <FocusDictionaryActionsContext.Provider\n value={{ setFocusedContent, setFocusedContentKeyPath }}\n >\n {children}\n </FocusDictionaryActionsContext.Provider>\n </FocusDictionaryStateContext.Provider>\n );\n};\n\nexport const useFocusDictionaryActions = () => {\n const context = useContext(FocusDictionaryActionsContext);\n if (context === undefined) {\n throw new Error(\n 'useFocusDictionaryActions must be used within a FocusDictionaryProvider'\n );\n }\n return context;\n};\n\nexport const useFocusDictionary = () => {\n const actionContext = useFocusDictionaryActions();\n const stateContext = useContext(FocusDictionaryStateContext);\n\n if (stateContext === undefined) {\n throw new Error(\n 'useFocusDictionaryState must be used within a FocusDictionaryProvider'\n );\n }\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":"kSA+BA,MAAM,GAAA,EAAA,EAAA,eAEJ,IAAA,GAAU,CACN,GAAA,EAAA,EAAA,eAEJ,IAAA,GAAU,CAEC,GAAkD,CAC7D,cACI,CACJ,GAAM,CAAC,EAAgB,GACrBA,EAAAA,mBACEC,EAAAA,WAAW,iCACX,KACD,CAoBH,OACE,EAAA,EAAA,KAAC,EAA4B,SAA7B,CAAsC,MAAO,CAAE,iBAAgB,WAC7D,EAAA,EAAA,KAAC,EAA8B,SAA/B,CACE,MAAO,CAAE,oBAAmB,yBArBA,GAAuB,CACvD,EAAmB,GAAS,CAC1B,GAAI,CAAC,EACH,OAAO,EAIT,IAAM,EAAkB,EAAQ,OAC7B,GAAQ,EAAI,OAASC,EAAAA,SAAS,YAChC,CAED,MAAO,CACL,GAAG,EACH,QAAS,EACV,EACD,EAMwD,CAErD,WACsC,CAAA,CACJ,CAAA,EAI9B,MAAkC,CAC7C,IAAM,GAAA,EAAA,EAAA,YAAqB,EAA8B,CACzD,GAAI,IAAY,IAAA,GACd,MAAU,MACR,0EACD,CAEH,OAAO,GAGI,MAA2B,CACtC,IAAM,EAAgB,GAA2B,CAC3C,GAAA,EAAA,EAAA,YAA0B,EAA4B,CAE5D,GAAI,IAAiB,IAAA,GACnB,MAAU,MACR,wEACD,CAGH,MAAO,CAAE,GAAG,EAAc,GAAG,EAAe"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./CommunicatorContext.cjs`),t=require(`./useCrossFrameMessageListener.cjs`),n=require(`./useCrossFrameState.cjs`),r=require(`./
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./CommunicatorContext.cjs`),t=require(`./useCrossFrameMessageListener.cjs`),n=require(`./useCrossFrameState.cjs`),r=require(`./FocusDictionaryContext.cjs`),i=require(`./useCrossURLPathState.cjs`),a=require(`./DictionariesRecordContext.cjs`),o=require(`./useEditorLocale.cjs`),s=require(`./useFocusUnmergedDictionary.cjs`),c=require(`./ConfigurationContext.cjs`),l=require(`./EditedContentContext.cjs`),u=require(`./EditorEnabledContext.cjs`),d=require(`./EditorProvider.cjs`),f=require(`./useIframeClickInterceptor.cjs`);exports.CommunicatorProvider=e.CommunicatorProvider,exports.ConfigurationProvider=c.ConfigurationProvider,exports.DictionariesRecordProvider=a.DictionariesRecordProvider,exports.EditedContentProvider=l.EditedContentProvider,exports.EditorEnabledProvider=u.EditorEnabledProvider,exports.EditorProvider=d.EditorProvider,exports.FocusDictionaryProvider=r.FocusDictionaryProvider,exports.useCommunicator=e.useCommunicator,exports.useConfiguration=c.useConfiguration,exports.useConfigurationState=c.useConfigurationState,exports.useCrossFrameMessageListener=t.useCrossFrameMessageListener,exports.useCrossFrameState=n.useCrossFrameState,exports.useCrossURLPathSetter=i.useCrossURLPathSetter,exports.useCrossURLPathState=i.useCrossURLPathState,exports.useDictionariesRecord=a.useDictionariesRecord,exports.useDictionariesRecordActions=a.useDictionariesRecordActions,exports.useEditedContent=l.useEditedContent,exports.useEditedContentActions=l.useEditedContentActions,exports.useEditorEnabled=u.useEditorEnabled,exports.useEditorEnabledState=u.useEditorEnabledState,exports.useEditorLocale=o.useEditorLocale,exports.useFocusDictionary=r.useFocusDictionary,exports.useFocusDictionaryActions=r.useFocusDictionaryActions,exports.useFocusUnmergedDictionary=s.useFocusUnmergedDictionary,exports.useGetEditedContentState=l.useGetEditedContentState,exports.useGetEditorEnabledState=u.useGetEditorEnabledState,exports.useIframeClickInterceptor=f.useIframeClickInterceptor,exports.useIframeClickMerger=f.useIframeClickMerger,exports.usePostEditedContentState=l.usePostEditedContentState,exports.usePostEditorEnabledState=u.usePostEditorEnabledState,exports.useSetEditorLocale=o.useSetEditorLocale;var p=require(`@intlayer/editor`);Object.keys(p).forEach(function(e){e!==`default`&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return p[e]}})});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./CommunicatorContext.cjs`);let t=require(`
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./CommunicatorContext.cjs`);let t=require(`@intlayer/editor`),n=require(`react`);const r=(r,i,a)=>{let{allowedOrigins:o,postMessage:s,senderId:c}=e.useCommunicator();return(0,n.useEffect)(()=>{if(i){let e=e=>{let{type:n,data:a,senderId:s}=e.data;n===r&&s!==c&&(o===void 0||o?.filter(e=>![null,void 0,``,`*`].includes(e)).some(n=>(0,t.compareUrls)(n,e.origin))||o?.includes(`*`))&&i(a)};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)}},[o,s,c,a]),e=>{s({type:r,data:e,senderId:c})}};exports.useCrossFrameMessageListener=r;
|
|
2
2
|
//# sourceMappingURL=useCrossFrameMessageListener.cjs.map
|
|
@@ -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(`
|
|
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`),n=require(`react`);const r=(n,r)=>e.useCrossFrameState(t.MessageKey.INTLAYER_URL_CHANGE,n,r),i=e=>{let t=r(e,{emit:!0,receive:!1}),[i,a]=t;return(0,n.useEffect)(()=>{let e=history.pushState,t=history.replaceState,n=e=>function(...t){e.apply(this,t),window.dispatchEvent(new Event(`locationchange`))};history.pushState=n(e),history.replaceState=n(t);let r=()=>{a(window.location.pathname)};return window.addEventListener(`locationchange`,r),window.addEventListener(`popstate`,r),window.addEventListener(`hashchange`,r),window.addEventListener(`load`,r),r(),()=>{window.removeEventListener(`locationchange`,r),window.removeEventListener(`popstate`,r),window.removeEventListener(`hashchange`,r),window.removeEventListener(`load`,r),history.pushState=e,history.replaceState=t}},[]),t};exports.useCrossURLPathSetter=i,exports.useCrossURLPathState=r;
|
|
2
2
|
//# sourceMappingURL=useCrossURLPathState.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditorLocale.cjs","names":["useCrossFrameState","MessageKey"],"sources":["../../src/useEditorLocale.tsx"],"sourcesContent":["import { MessageKey } from '@intlayer/editor';\nimport type { Locale } from '@intlayer/types';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport const useEditorLocale = () => {\n const [currentLocale] = useCrossFrameState<Locale>(\n MessageKey.INTLAYER_CURRENT_LOCALE,\n undefined,\n {\n receive: true,\n emit: false,\n }\n );\n\n return currentLocale;\n};\n\nexport const useSetEditorLocale = () => {\n const setCurrentLocale = useCrossFrameState<Locale>(\n MessageKey.INTLAYER_CURRENT_LOCALE,\n undefined,\n {\n receive: true,\n emit: false,\n }\n );\n\n return setCurrentLocale;\n};\n"],"mappings":"6LAIA,MAAa,MAAwB,CACnC,GAAM,CAAC,GAAiBA,EAAAA,mBACtBC,EAAAA,WAAW,wBACX,IAAA,GACA,CACE,QAAS,GACT,KAAM,GACP,CACF,CAED,OAAO,GAGI,MACcD,EAAAA,mBACvBC,EAAAA,WAAW,wBACX,IAAA,GACA,CACE,QAAS,GACT,KAAM,GACP,CACF"}
|
|
1
|
+
{"version":3,"file":"useEditorLocale.cjs","names":["useCrossFrameState","MessageKey"],"sources":["../../src/useEditorLocale.tsx"],"sourcesContent":["import { MessageKey } from '@intlayer/editor';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport const useEditorLocale = () => {\n const [currentLocale] = useCrossFrameState<Locale>(\n MessageKey.INTLAYER_CURRENT_LOCALE,\n undefined,\n {\n receive: true,\n emit: false,\n }\n );\n\n return currentLocale;\n};\n\nexport const useSetEditorLocale = () => {\n const setCurrentLocale = useCrossFrameState<Locale>(\n MessageKey.INTLAYER_CURRENT_LOCALE,\n undefined,\n {\n receive: true,\n emit: false,\n }\n );\n\n return setCurrentLocale;\n};\n"],"mappings":"6LAIA,MAAa,MAAwB,CACnC,GAAM,CAAC,GAAiBA,EAAAA,mBACtBC,EAAAA,WAAW,wBACX,IAAA,GACA,CACE,QAAS,GACT,KAAM,GACP,CACF,CAED,OAAO,GAGI,MACcD,EAAAA,mBACvBC,EAAAA,WAAW,wBACX,IAAA,GACA,CACE,QAAS,GACT,KAAM,GACP,CACF"}
|
|
@@ -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(`./FocusDictionaryContext.cjs`),t=require(`./DictionariesRecordContext.cjs`),n=require(`./useEditorLocale.cjs`);let r=require(`react`),i=require(`@intlayer/core/dictionaryManipulator`);const a=(e,t,n)=>{for(let r of t)try{if((0,i.getContentNodeByKeyPath)(r.content,e??[],n))return{keyPath:e,dictionaryLocalId:r.localId}}catch{}},o=()=>{let{localeDictionaries:i}=t.useDictionariesRecord(),o=n.useEditorLocale(),{setFocusedContent:s,setFocusedContentKeyPath:c,focusedContent:l}=e.useFocusDictionary();return{focusedContent:(0,r.useMemo)(()=>{if(!l||!i||l.dictionaryLocalId)return l;let e=Object.values(i).filter(e=>e.key===l.dictionaryKey),t=a(l.keyPath??[],e,o);return{...l,...t}},[l,i,o]),setFocusedContent:s,setFocusedContentKeyPath:c}};exports.useFocusUnmergedDictionary=o;
|
|
2
2
|
//# sourceMappingURL=useFocusUnmergedDictionary.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFocusUnmergedDictionary.cjs","names":["useDictionariesRecord","useEditorLocale","useFocusDictionary"],"sources":["../../src/useFocusUnmergedDictionary.tsx"],"sourcesContent":["'use client';\n\nimport { getContentNodeByKeyPath } from '@intlayer/core/dictionaryManipulator';\nimport type {
|
|
1
|
+
{"version":3,"file":"useFocusUnmergedDictionary.cjs","names":["useDictionariesRecord","useEditorLocale","useFocusDictionary"],"sources":["../../src/useFocusUnmergedDictionary.tsx"],"sourcesContent":["'use client';\n\nimport { getContentNodeByKeyPath } from '@intlayer/core/dictionaryManipulator';\nimport type { Dictionary, LocalDictionaryId } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useMemo } from 'react';\nimport { useDictionariesRecord } from './DictionariesRecordContext';\nimport { type FileContent, useFocusDictionary } from './FocusDictionaryContext';\nimport { useEditorLocale } from './useEditorLocale';\n\ntype UnmergedKeyPath = {\n keyPath: KeyPath[];\n dictionaryLocalId?: LocalDictionaryId;\n};\n\n/**\n * Converts merged keypath format to unmerged format.\n * Merged: [{type: \"translation\", key: \"fr\"}, {type: \"object\", key: \"title\"}]\n * Unmerged: [{type: \"object\", key: \"title\"}, {type: \"translation\", key: \"fr\"}]\n */\nconst mergedKeyPathToUnmergedKeyPath = (\n keyPath: KeyPath[],\n dictionaries: Dictionary[],\n locale: Locale\n): UnmergedKeyPath | undefined => {\n // If we have a dictionary, verify the path exists\n // Try to find the correct position for the translation key\n // by checking which path actually exists in the dictionary\n for (const dictionary of dictionaries) {\n try {\n const result = getContentNodeByKeyPath(\n dictionary.content,\n keyPath ?? [],\n locale\n );\n\n if (result) {\n return { keyPath, dictionaryLocalId: dictionary.localId };\n }\n } catch {\n // Continue to next candidate\n }\n }\n};\n\nexport const useFocusUnmergedDictionary = () => {\n const { localeDictionaries } = useDictionariesRecord();\n const currentLocale = useEditorLocale();\n const {\n setFocusedContent,\n setFocusedContentKeyPath,\n focusedContent: mergedFocusedContent,\n } = useFocusDictionary();\n\n const focusedContent = useMemo<FileContent | null>(() => {\n if (!mergedFocusedContent) return mergedFocusedContent;\n if (!localeDictionaries) return mergedFocusedContent;\n if (mergedFocusedContent.dictionaryLocalId) return mergedFocusedContent;\n\n const dictionaries = Object.values(localeDictionaries).filter(\n (dictionary) => dictionary.key === mergedFocusedContent.dictionaryKey\n );\n\n const unmergedKeyPath = mergedKeyPathToUnmergedKeyPath(\n mergedFocusedContent.keyPath ?? [],\n dictionaries,\n currentLocale\n );\n\n return {\n ...mergedFocusedContent,\n ...unmergedKeyPath,\n };\n }, [mergedFocusedContent, localeDictionaries, currentLocale]);\n\n return {\n focusedContent,\n setFocusedContent,\n setFocusedContentKeyPath,\n };\n};\n"],"mappings":"qUAqBA,MAAM,GACJ,EACA,EACA,IACgC,CAIhC,IAAK,IAAM,KAAc,EACvB,GAAI,CAOF,IAAA,EAAA,EAAA,yBALE,EAAW,QACX,GAAW,EAAE,CACb,EACD,CAGC,MAAO,CAAE,UAAS,kBAAmB,EAAW,QAAS,MAErD,IAMC,MAAmC,CAC9C,GAAM,CAAE,sBAAuBA,EAAAA,uBAAuB,CAChD,EAAgBC,EAAAA,iBAAiB,CACjC,CACJ,oBACA,2BACA,eAAgB,GACdC,EAAAA,oBAAoB,CAuBxB,MAAO,CACL,gBAAA,EAAA,EAAA,aAtBuD,CAGvD,GAFI,CAAC,GACD,CAAC,GACD,EAAqB,kBAAmB,OAAO,EAEnD,IAAM,EAAe,OAAO,OAAO,EAAmB,CAAC,OACpD,GAAe,EAAW,MAAQ,EAAqB,cACzD,CAEK,EAAkB,EACtB,EAAqB,SAAW,EAAE,CAClC,EACA,EACD,CAED,MAAO,CACL,GAAG,EACH,GAAG,EACJ,EACA,CAAC,EAAsB,EAAoB,EAAc,CAAC,CAI3D,oBACA,2BACD"}
|
|
@@ -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(`
|
|
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`),n=require(`react`);const r=()=>{let r=e.useCrossFrameMessageListener(t.MessageKey.INTLAYER_IFRAME_CLICKED),i=()=>{r()};(0,n.useEffect)(()=>(window.addEventListener(`mousedown`,i),()=>window.removeEventListener(`mousedown`,i)),[r])},i=()=>e.useCrossFrameMessageListener(t.MessageKey.INTLAYER_IFRAME_CLICKED,t.mergeIframeClick);exports.useIframeClickInterceptor=r,exports.useIframeClickMerger=i;
|
|
2
2
|
//# sourceMappingURL=useIframeClickInterceptor.cjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import e
|
|
1
|
+
"use client";import{jsx as e}from"react/jsx-runtime";import{createContext as t,useContext as n,useMemo as r,useRef as i}from"react";import a from"@intlayer/config/built";const o=()=>Math.random().toString(36).slice(2),{editor:s}=a??{},c=t({postMessage:()=>null,allowedOrigins:[s?.applicationURL,s?.editorURL,s?.cmsURL],senderId:``}),l=({children:t,allowedOrigins:n,postMessage:a})=>{let s=i(o()),l=r(()=>({postMessage:a,allowedOrigins:n,senderId:s.current}),[a,n,s.current]);return e(c.Provider,{value:l,children:t})},u=()=>n(c);export{l as CommunicatorProvider,u as useCommunicator};
|
|
2
2
|
//# sourceMappingURL=CommunicatorContext.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{useCrossFrameState as e}from"./useCrossFrameState.mjs";import{
|
|
1
|
+
"use client";import{useCrossFrameState as e}from"./useCrossFrameState.mjs";import{MessageKey as t}from"@intlayer/editor";import{jsx as n}from"react/jsx-runtime";import{createContext as r,useContext as i}from"react";const a=r(void 0),o=()=>e(t.INTLAYER_CONFIGURATION,void 0,{receive:!1,emit:!0}),s=({children:e,configuration:t})=>n(a.Provider,{value:t,children:e}),c=()=>i(a);export{s as ConfigurationProvider,c as useConfiguration,o 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 { MessageKey } from '@intlayer/editor';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nconst ConfigurationStatesContext = createContext<IntlayerConfig | undefined>(\n undefined\n);\n\nexport const useConfigurationState = () =>\n useCrossFrameState<IntlayerConfig>(\n MessageKey.INTLAYER_CONFIGURATION,\n undefined,\n {\n receive: false,\n emit: true,\n }\n );\n\nexport type ConfigurationProviderProps = {\n configuration?: IntlayerConfig;\n};\n\nexport const ConfigurationProvider: FC<\n PropsWithChildren<ConfigurationProviderProps>\n> = ({ children, configuration }) => (\n <ConfigurationStatesContext.Provider value={configuration}>\n {children}\n </ConfigurationStatesContext.Provider>\n);\n\nexport const useConfiguration = () => useContext(ConfigurationStatesContext);\n"],"mappings":"uNAYA,MAAM,EAA6B,EACjC,IAAA,GACD,CAEY,MACX,EACE,EAAW,uBACX,IAAA,GACA,CACE,QAAS,GACT,KAAM,GACP,CACF,CAMU,GAER,CAAE,WAAU,mBACf,EAAC,EAA2B,SAA5B,CAAqC,MAAO,EACzC,WACmC,CAAA,CAG3B,MAAyB,EAAW,EAA2B"}
|
|
1
|
+
{"version":3,"file":"ConfigurationContext.mjs","names":[],"sources":["../../src/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nconst ConfigurationStatesContext = createContext<IntlayerConfig | undefined>(\n undefined\n);\n\nexport const useConfigurationState = () =>\n useCrossFrameState<IntlayerConfig>(\n MessageKey.INTLAYER_CONFIGURATION,\n undefined,\n {\n receive: false,\n emit: true,\n }\n );\n\nexport type ConfigurationProviderProps = {\n configuration?: IntlayerConfig;\n};\n\nexport const ConfigurationProvider: FC<\n PropsWithChildren<ConfigurationProviderProps>\n> = ({ children, configuration }) => (\n <ConfigurationStatesContext.Provider value={configuration}>\n {children}\n </ConfigurationStatesContext.Provider>\n);\n\nexport const useConfiguration = () => useContext(ConfigurationStatesContext);\n"],"mappings":"uNAYA,MAAM,EAA6B,EACjC,IAAA,GACD,CAEY,MACX,EACE,EAAW,uBACX,IAAA,GACA,CACE,QAAS,GACT,KAAM,GACP,CACF,CAMU,GAER,CAAE,WAAU,mBACf,EAAC,EAA2B,SAA5B,CAAqC,MAAO,EACzC,WACmC,CAAA,CAG3B,MAAyB,EAAW,EAA2B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{useCrossFrameState as e}from"./useCrossFrameState.mjs";import{
|
|
1
|
+
"use client";import{useCrossFrameState as e}from"./useCrossFrameState.mjs";import{MessageKey as t}from"@intlayer/editor";import{jsx as n}from"react/jsx-runtime";import{createContext as r,useContext as i,useMemo as a}from"react";const o=r(void 0),s=r(void 0),c=({children:r})=>{let[i,c]=e(t.INTLAYER_LOCALE_DICTIONARIES_CHANGED,void 0),l=a(()=>({localeDictionaries:i??{}}),[i]),u=a(()=>({setLocaleDictionaries:c,setLocaleDictionary:e=>{e.localId&&c(t=>({...t,[e.localId]:e}))}}),[c]);return n(o.Provider,{value:l,children:n(s.Provider,{value:u,children:r})})},l=()=>i(s),u=()=>{let e=l(),t=i(o);if(!t)throw Error(`useDictionariesRecordStates must be used within a DictionariesRecordProvider`);return{...t,...e}};export{c as DictionariesRecordProvider,u as useDictionariesRecord,l 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 { MessageKey } from '@intlayer/editor';\nimport type { Dictionary, LocalDictionaryId } from '@intlayer/types';\nimport {\n createContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n useContext,\n useMemo,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport type DictionaryContent = Record<LocalDictionaryId, Dictionary>;\n\ntype DictionariesRecordStatesContextType = {\n localeDictionaries: DictionaryContent;\n};\ntype DictionariesRecordActionsContextType = {\n setLocaleDictionaries: Dispatch<SetStateAction<DictionaryContent>>;\n setLocaleDictionary: (dictionary: Dictionary) => void;\n};\n\nconst DictionariesRecordStatesContext = createContext<\n DictionariesRecordStatesContextType | undefined\n>(undefined);\nconst DictionariesRecordActionsContext = createContext<\n DictionariesRecordActionsContextType | undefined\n>(undefined);\n\nexport const DictionariesRecordProvider: FC<PropsWithChildren> = ({\n children,\n}) => {\n const [localeDictionaries, setLocaleDictionaries] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED,\n undefined\n );\n\n const stateValue = useMemo(\n () => ({\n localeDictionaries: localeDictionaries ?? {},\n }),\n [localeDictionaries]\n );\n\n const actionValue = useMemo(\n () => ({\n setLocaleDictionaries,\n setLocaleDictionary: (dictionary: Dictionary) => {\n if (!dictionary.localId) return;\n\n setLocaleDictionaries((dictionaries) => ({\n ...dictionaries,\n [dictionary.localId as LocalDictionaryId]: dictionary,\n }));\n },\n }),\n [setLocaleDictionaries]\n );\n\n return (\n <DictionariesRecordStatesContext.Provider value={stateValue}>\n <DictionariesRecordActionsContext.Provider value={actionValue}>\n {children}\n </DictionariesRecordActionsContext.Provider>\n </DictionariesRecordStatesContext.Provider>\n );\n};\n\nexport const useDictionariesRecordActions = () =>\n useContext(DictionariesRecordActionsContext);\n\nexport const useDictionariesRecord = () => {\n const actionsContext = useDictionariesRecordActions();\n const statesContext = useContext(DictionariesRecordStatesContext);\n\n if (!statesContext) {\n throw new Error(\n 'useDictionariesRecordStates must be used within a DictionariesRecordProvider'\n );\n }\n\n return { ...statesContext, ...actionsContext };\n};\n"],"mappings":"oOAyBA,MAAM,EAAkC,EAEtC,IAAA,GAAU,CACN,EAAmC,EAEvC,IAAA,GAAU,CAEC,GAAqD,CAChE,cACI,CACJ,GAAM,CAAC,EAAoB,GACzB,EACE,EAAW,qCACX,IAAA,GACD,CAEG,EAAa,OACV,CACL,mBAAoB,GAAsB,EAAE,CAC7C,EACD,CAAC,EAAmB,CACrB,CAEK,EAAc,OACX,CACL,wBACA,oBAAsB,GAA2B,CAC1C,EAAW,SAEhB,EAAuB,IAAkB,CACvC,GAAG,GACF,EAAW,SAA+B,EAC5C,EAAE,EAEN,EACD,CAAC,EAAsB,CACxB,CAED,OACE,EAAC,EAAgC,SAAjC,CAA0C,MAAO,WAC/C,EAAC,EAAiC,SAAlC,CAA2C,MAAO,EAC/C,WACyC,CAAA,CACH,CAAA,EAIlC,MACX,EAAW,EAAiC,CAEjC,MAA8B,CACzC,IAAM,EAAiB,GAA8B,CAC/C,EAAgB,EAAW,EAAgC,CAEjE,GAAI,CAAC,EACH,MAAU,MACR,+EACD,CAGH,MAAO,CAAE,GAAG,EAAe,GAAG,EAAgB"}
|
|
1
|
+
{"version":3,"file":"DictionariesRecordContext.mjs","names":[],"sources":["../../src/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { Dictionary, LocalDictionaryId } from '@intlayer/types/dictionary';\nimport {\n createContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n useContext,\n useMemo,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport type DictionaryContent = Record<LocalDictionaryId, Dictionary>;\n\ntype DictionariesRecordStatesContextType = {\n localeDictionaries: DictionaryContent;\n};\ntype DictionariesRecordActionsContextType = {\n setLocaleDictionaries: Dispatch<SetStateAction<DictionaryContent>>;\n setLocaleDictionary: (dictionary: Dictionary) => void;\n};\n\nconst DictionariesRecordStatesContext = createContext<\n DictionariesRecordStatesContextType | undefined\n>(undefined);\nconst DictionariesRecordActionsContext = createContext<\n DictionariesRecordActionsContextType | undefined\n>(undefined);\n\nexport const DictionariesRecordProvider: FC<PropsWithChildren> = ({\n children,\n}) => {\n const [localeDictionaries, setLocaleDictionaries] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED,\n undefined\n );\n\n const stateValue = useMemo(\n () => ({\n localeDictionaries: localeDictionaries ?? {},\n }),\n [localeDictionaries]\n );\n\n const actionValue = useMemo(\n () => ({\n setLocaleDictionaries,\n setLocaleDictionary: (dictionary: Dictionary) => {\n if (!dictionary.localId) return;\n\n setLocaleDictionaries((dictionaries) => ({\n ...dictionaries,\n [dictionary.localId as LocalDictionaryId]: dictionary,\n }));\n },\n }),\n [setLocaleDictionaries]\n );\n\n return (\n <DictionariesRecordStatesContext.Provider value={stateValue}>\n <DictionariesRecordActionsContext.Provider value={actionValue}>\n {children}\n </DictionariesRecordActionsContext.Provider>\n </DictionariesRecordStatesContext.Provider>\n );\n};\n\nexport const useDictionariesRecordActions = () =>\n useContext(DictionariesRecordActionsContext);\n\nexport const useDictionariesRecord = () => {\n const actionsContext = useDictionariesRecordActions();\n const statesContext = useContext(DictionariesRecordStatesContext);\n\n if (!statesContext) {\n throw new Error(\n 'useDictionariesRecordStates must be used within a DictionariesRecordProvider'\n );\n }\n\n return { ...statesContext, ...actionsContext };\n};\n"],"mappings":"oOAyBA,MAAM,EAAkC,EAEtC,IAAA,GAAU,CACN,EAAmC,EAEvC,IAAA,GAAU,CAEC,GAAqD,CAChE,cACI,CACJ,GAAM,CAAC,EAAoB,GACzB,EACE,EAAW,qCACX,IAAA,GACD,CAEG,EAAa,OACV,CACL,mBAAoB,GAAsB,EAAE,CAC7C,EACD,CAAC,EAAmB,CACrB,CAEK,EAAc,OACX,CACL,wBACA,oBAAsB,GAA2B,CAC1C,EAAW,SAEhB,EAAuB,IAAkB,CACvC,GAAG,GACF,EAAW,SAA+B,EAC5C,EAAE,EAEN,EACD,CAAC,EAAsB,CACxB,CAED,OACE,EAAC,EAAgC,SAAjC,CAA0C,MAAO,WAC/C,EAAC,EAAiC,SAAlC,CAA2C,MAAO,EAC/C,WACyC,CAAA,CACH,CAAA,EAIlC,MACX,EAAW,EAAiC,CAEjC,MAA8B,CACzC,IAAM,EAAiB,GAA8B,CAC/C,EAAgB,EAAW,EAAgC,CAEjE,GAAI,CAAC,EACH,MAAU,MACR,+EACD,CAGH,MAAO,CAAE,GAAG,EAAe,GAAG,EAAgB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{useCrossFrameMessageListener as e}from"./useCrossFrameMessageListener.mjs";import{useCrossFrameState as t}from"./useCrossFrameState.mjs";import{useDictionariesRecord as n}from"./DictionariesRecordContext.mjs";import{useEditorLocale as r}from"./useEditorLocale.mjs";import{
|
|
1
|
+
"use client";import{useCrossFrameMessageListener as e}from"./useCrossFrameMessageListener.mjs";import{useCrossFrameState as t}from"./useCrossFrameState.mjs";import{useDictionariesRecord as n}from"./DictionariesRecordContext.mjs";import{useEditorLocale as r}from"./useEditorLocale.mjs";import{MessageKey as i}from"@intlayer/editor";import{jsx as a}from"react/jsx-runtime";import{NodeType as o}from"@intlayer/types/nodeType";import{createContext as s,useContext as c}from"react";import{editDictionaryByKeyPath as l,getContentNodeByKeyPath as u,renameContentNodeByKeyPath as d}from"@intlayer/core/dictionaryManipulator";const f=s(void 0),p=t=>e(`${i.INTLAYER_EDITED_CONTENT_CHANGED}/post`,t),m=t=>e(`${i.INTLAYER_EDITED_CONTENT_CHANGED}/get`,t),h=s(void 0),g=(e,t)=>typeof e==`function`?e(t):e,_=({children:e})=>{let{localeDictionaries:s}=n(),c=r(),[p,m]=t(i.INTLAYER_EDITED_CONTENT_CHANGED);return a(f.Provider,{value:{editedContent:p},children:a(h.Provider,{value:{setEditedContentState:m,setEditedDictionary:e=>{let t=g(e);return m(n=>t.localId?(t=g(e,n?.[t.localId]),{...n,[t.localId]:t}):(console.error(`no localId`,t),n)),t},setEditedContent:(e,t)=>{m(n=>({...n,[e]:{...n?.[e],content:t}}))},addEditedContent:(e,t,n=[],r=!0)=>{m(i=>{let a=s[e]?.content,o=structuredClone(i?.[e]?.content??a),c=n;if(!r){let e=0,t=n.slice(0,-1),r=n[n.length-1],i=r.key;for(;u(o,c)!==void 0;)e++,i=e===0?r.key:`${r.key} (${e})`,c=[...t,{...r,key:i}]}let d=l(o,c,t);return{...i,[e]:{...i?.[e],content:d}}})},renameEditedContent:(e,t,n=[])=>{m(r=>{let i=s[e]?.content,a=d(structuredClone(r?.[e]?.content??i),t,n);return{...r,[e]:{...r?.[e],content:a}}})},removeEditedContent:(e,t)=>{m(n=>{let r=s[e]?.content,i=l(structuredClone(n?.[e]?.content??r),t,u(r,t));return{...n,[e]:{...n?.[e],content:i}}})},restoreEditedContent:e=>{m(t=>{let n={...t};return delete n[e],n})},clearEditedDictionaryContent:e=>{m(t=>{let n={...t};return delete n[e],n})},clearEditedContent:()=>{m({})},getEditedContentValue:(e,t)=>{if(!p)return;let n=t.filter(e=>e.type!==o.Translation);if(e.includes(`:local:`)||e.includes(`:remote:`))return u(p?.[e]?.content??{},n,c);let r=Object.keys(p).filter(t=>t.startsWith(`${e}:`));for(let e of r){let t=u(p?.[e]?.content??{},n,c);if(t)return t}}},children:e})})},v=()=>c(h),y=()=>{let e=c(f),t=v();return{...e,...t}};export{_ as EditedContentProvider,y as useEditedContent,v as useEditedContentActions,m as useGetEditedContentState,p as usePostEditedContentState};
|
|
2
2
|
//# sourceMappingURL=EditedContentContext.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditedContentContext.mjs","names":[],"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 {\n type ContentNode,\n type Dictionary,\n type KeyPath,\n type LocalDictionaryId,\n NodeType,\n} from '@intlayer/types';\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":"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"}
|
|
1
|
+
{"version":3,"file":"EditedContentContext.mjs","names":[],"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":"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"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{useCrossFrameMessageListener as e}from"./useCrossFrameMessageListener.mjs";import{useCrossFrameState as t}from"./useCrossFrameState.mjs";import{
|
|
1
|
+
"use client";import{useCrossFrameMessageListener as e}from"./useCrossFrameMessageListener.mjs";import{useCrossFrameState as t}from"./useCrossFrameState.mjs";import{MessageKey as n}from"@intlayer/editor";import{jsx as r}from"react/jsx-runtime";import{createContext as i,useContext as a}from"react";const o=i({enabled:!1}),s=e=>t(n.INTLAYER_EDITOR_ENABLED,!1,e),c=t=>e(`${n.INTLAYER_EDITOR_ENABLED}/post`,t),l=t=>e(`${n.INTLAYER_EDITOR_ENABLED}/get`,t),u=({children:e})=>{let[t]=s({emit:!1,receive:!0});return r(o.Provider,{value:{enabled:t},children:e})},d=()=>a(o);export{u as EditorEnabledProvider,d as useEditorEnabled,s as useEditorEnabledState,l as useGetEditorEnabledState,c as usePostEditorEnabledState};
|
|
2
2
|
//# sourceMappingURL=EditorEnabledContext.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{CommunicatorProvider as e}from"./CommunicatorContext.mjs";import{
|
|
1
|
+
"use client";import{CommunicatorProvider as e}from"./CommunicatorContext.mjs";import{FocusDictionaryProvider as t}from"./FocusDictionaryContext.mjs";import{DictionariesRecordProvider as n}from"./DictionariesRecordContext.mjs";import{ConfigurationProvider as r}from"./ConfigurationContext.mjs";import{EditedContentProvider as i,useGetEditedContentState as a}from"./EditedContentContext.mjs";import{EditorEnabledProvider as o,useEditorEnabled as s,useGetEditorEnabledState as c}from"./EditorEnabledContext.mjs";import{jsx as l}from"react/jsx-runtime";import{useEffect as u,useState as d}from"react";const f=({children:e})=>{let r=a();return u(()=>{r()},[]),l(n,{children:l(i,{children:l(t,{children:e})})})},p=({children:e,fallback:t})=>{let n=c(),{enabled:r}=s();return u(()=>{r||n()},[r]),r?e:t},m=({children:e,fallback:t})=>{let[n,r]=d(!1);return u(()=>{r(window.self!==window.top)},[]),n?e:t},h=({children:t,configuration:n,...i})=>l(o,{children:l(r,{configuration:n,children:i.mode===`editor`?l(e,{...i,children:l(f,{children:t})}):l(m,{fallback:t,children:l(e,{...i,children:l(p,{fallback:t,children:l(f,{children:t})})})})})});export{h as EditorProvider};
|
|
2
2
|
//# sourceMappingURL=EditorProvider.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{useCrossFrameState as e}from"./useCrossFrameState.mjs";import{
|
|
1
|
+
"use client";import{useCrossFrameState as e}from"./useCrossFrameState.mjs";import{MessageKey as t}from"@intlayer/editor";import{jsx as n}from"react/jsx-runtime";import{NodeType as r}from"@intlayer/types/nodeType";import{createContext as i,useContext as a}from"react";const o=i(void 0),s=i(void 0),c=({children:i})=>{let[a,c]=e(t.INTLAYER_FOCUSED_CONTENT_CHANGED,null);return n(o.Provider,{value:{focusedContent:a},children:n(s.Provider,{value:{setFocusedContent:c,setFocusedContentKeyPath:e=>{c(t=>{if(!t)return t;let n=e.filter(e=>e.type!==r.Translation);return{...t,keyPath:n}})}},children:i})})},l=()=>{let e=a(s);if(e===void 0)throw Error(`useFocusDictionaryActions must be used within a FocusDictionaryProvider`);return e},u=()=>{let e=l(),t=a(o);if(t===void 0)throw Error(`useFocusDictionaryState must be used within a FocusDictionaryProvider`);return{...t,...e}};export{c as FocusDictionaryProvider,u as useFocusDictionary,l as useFocusDictionaryActions};
|
|
2
2
|
//# sourceMappingURL=FocusDictionaryContext.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FocusDictionaryContext.mjs","names":[],"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport
|
|
1
|
+
{"version":3,"file":"FocusDictionaryContext.mjs","names":[],"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { LocalDictionaryId } from '@intlayer/types/dictionary';;\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 { useCrossFrameState } from './useCrossFrameState';\n\nexport type FileContent = {\n dictionaryKey: string;\n dictionaryLocalId?: LocalDictionaryId;\n keyPath?: KeyPath[];\n};\n\nexport type FocusDictionaryState = {\n focusedContent: FileContent | null;\n};\n\nexport type FocusDictionaryActions = {\n setFocusedContent: Dispatch<SetStateAction<FileContent | null>>;\n setFocusedContentKeyPath: (keyPath: KeyPath[]) => void;\n};\n\nconst FocusDictionaryStateContext = createContext<\n FocusDictionaryState | undefined\n>(undefined);\nconst FocusDictionaryActionsContext = createContext<\n FocusDictionaryActions | undefined\n>(undefined);\n\nexport const FocusDictionaryProvider: FC<PropsWithChildren> = ({\n children,\n}) => {\n const [focusedContent, setFocusedContent] =\n useCrossFrameState<FileContent | null>(\n MessageKey.INTLAYER_FOCUSED_CONTENT_CHANGED,\n null\n );\n\n const setFocusedContentKeyPath = (keyPath: KeyPath[]) => {\n setFocusedContent((prev) => {\n if (!prev) {\n return prev; // nothing to update if there's no focused content\n }\n\n // Remove translation key path if it exists to make it more flexible with optimization client / editor\n const filteredKeyPath = keyPath.filter(\n (key) => key.type !== NodeType.Translation\n );\n\n return {\n ...prev,\n keyPath: filteredKeyPath,\n };\n });\n };\n\n return (\n <FocusDictionaryStateContext.Provider value={{ focusedContent }}>\n <FocusDictionaryActionsContext.Provider\n value={{ setFocusedContent, setFocusedContentKeyPath }}\n >\n {children}\n </FocusDictionaryActionsContext.Provider>\n </FocusDictionaryStateContext.Provider>\n );\n};\n\nexport const useFocusDictionaryActions = () => {\n const context = useContext(FocusDictionaryActionsContext);\n if (context === undefined) {\n throw new Error(\n 'useFocusDictionaryActions must be used within a FocusDictionaryProvider'\n );\n }\n return context;\n};\n\nexport const useFocusDictionary = () => {\n const actionContext = useFocusDictionaryActions();\n const stateContext = useContext(FocusDictionaryStateContext);\n\n if (stateContext === undefined) {\n throw new Error(\n 'useFocusDictionaryState must be used within a FocusDictionaryProvider'\n );\n }\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":"2QA+BA,MAAM,EAA8B,EAElC,IAAA,GAAU,CACN,EAAgC,EAEpC,IAAA,GAAU,CAEC,GAAkD,CAC7D,cACI,CACJ,GAAM,CAAC,EAAgB,GACrB,EACE,EAAW,iCACX,KACD,CAoBH,OACE,EAAC,EAA4B,SAA7B,CAAsC,MAAO,CAAE,iBAAgB,UAC7D,EAAC,EAA8B,SAA/B,CACE,MAAO,CAAE,oBAAmB,yBArBA,GAAuB,CACvD,EAAmB,GAAS,CAC1B,GAAI,CAAC,EACH,OAAO,EAIT,IAAM,EAAkB,EAAQ,OAC7B,GAAQ,EAAI,OAAS,EAAS,YAChC,CAED,MAAO,CACL,GAAG,EACH,QAAS,EACV,EACD,EAMwD,CAErD,WACsC,CAAA,CACJ,CAAA,EAI9B,MAAkC,CAC7C,IAAM,EAAU,EAAW,EAA8B,CACzD,GAAI,IAAY,IAAA,GACd,MAAU,MACR,0EACD,CAEH,OAAO,GAGI,MAA2B,CACtC,IAAM,EAAgB,GAA2B,CAC3C,EAAe,EAAW,EAA4B,CAE5D,GAAI,IAAiB,IAAA,GACnB,MAAU,MACR,wEACD,CAGH,MAAO,CAAE,GAAG,EAAc,GAAG,EAAe"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CommunicatorProvider as e,useCommunicator as t}from"./CommunicatorContext.mjs";import{useCrossFrameMessageListener as n}from"./useCrossFrameMessageListener.mjs";import{useCrossFrameState as r}from"./useCrossFrameState.mjs";import{
|
|
1
|
+
import{CommunicatorProvider as e,useCommunicator as t}from"./CommunicatorContext.mjs";import{useCrossFrameMessageListener as n}from"./useCrossFrameMessageListener.mjs";import{useCrossFrameState as r}from"./useCrossFrameState.mjs";import{FocusDictionaryProvider as i,useFocusDictionary as a,useFocusDictionaryActions as o}from"./FocusDictionaryContext.mjs";import{useCrossURLPathSetter as s,useCrossURLPathState as c}from"./useCrossURLPathState.mjs";import{DictionariesRecordProvider as l,useDictionariesRecord as u,useDictionariesRecordActions as d}from"./DictionariesRecordContext.mjs";import{useEditorLocale as f,useSetEditorLocale as p}from"./useEditorLocale.mjs";import{useFocusUnmergedDictionary as m}from"./useFocusUnmergedDictionary.mjs";import{ConfigurationProvider as h,useConfiguration as g,useConfigurationState as _}from"./ConfigurationContext.mjs";import{EditedContentProvider as v,useEditedContent as y,useEditedContentActions as b,useGetEditedContentState as x,usePostEditedContentState as S}from"./EditedContentContext.mjs";import{EditorEnabledProvider as C,useEditorEnabled as w,useEditorEnabledState as T,useGetEditorEnabledState as E,usePostEditorEnabledState as D}from"./EditorEnabledContext.mjs";import{EditorProvider as O}from"./EditorProvider.mjs";import{useIframeClickInterceptor as k,useIframeClickMerger as A}from"./useIframeClickInterceptor.mjs";export*from"@intlayer/editor";export{e as CommunicatorProvider,h as ConfigurationProvider,l as DictionariesRecordProvider,v as EditedContentProvider,C as EditorEnabledProvider,O as EditorProvider,i as FocusDictionaryProvider,t as useCommunicator,g as useConfiguration,_ as useConfigurationState,n as useCrossFrameMessageListener,r as useCrossFrameState,s as useCrossURLPathSetter,c as useCrossURLPathState,u as useDictionariesRecord,d as useDictionariesRecordActions,y as useEditedContent,b as useEditedContentActions,w as useEditorEnabled,T as useEditorEnabledState,f as useEditorLocale,a as useFocusDictionary,o as useFocusDictionaryActions,m as useFocusUnmergedDictionary,x as useGetEditedContentState,E as useGetEditorEnabledState,k as useIframeClickInterceptor,A as useIframeClickMerger,S as usePostEditedContentState,D as usePostEditorEnabledState,p as useSetEditorLocale};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{useCommunicator as e}from"./CommunicatorContext.mjs";import{
|
|
1
|
+
"use client";import{useCommunicator as e}from"./CommunicatorContext.mjs";import{compareUrls as t}from"@intlayer/editor";import{useEffect as n}from"react";const r=(r,i,a)=>{let{allowedOrigins:o,postMessage:s,senderId:c}=e();return n(()=>{if(i){let e=e=>{let{type:n,data:a,senderId:s}=e.data;n===r&&s!==c&&(o===void 0||o?.filter(e=>![null,void 0,``,`*`].includes(e)).some(n=>t(n,e.origin))||o?.includes(`*`))&&i(a)};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)}},[o,s,c,a]),e=>{s({type:r,data:e,senderId:c})}};export{r as useCrossFrameMessageListener};
|
|
2
2
|
//# sourceMappingURL=useCrossFrameMessageListener.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{useCrossFrameState as e}from"./useCrossFrameState.mjs";import{
|
|
1
|
+
"use client";import{useCrossFrameState as e}from"./useCrossFrameState.mjs";import{MessageKey as t}from"@intlayer/editor";import{useEffect as n}from"react";const r=(n,r)=>e(t.INTLAYER_URL_CHANGE,n,r),i=e=>{let t=r(e,{emit:!0,receive:!1}),[i,a]=t;return n(()=>{let e=history.pushState,t=history.replaceState,n=e=>function(...t){e.apply(this,t),window.dispatchEvent(new Event(`locationchange`))};history.pushState=n(e),history.replaceState=n(t);let r=()=>{a(window.location.pathname)};return window.addEventListener(`locationchange`,r),window.addEventListener(`popstate`,r),window.addEventListener(`hashchange`,r),window.addEventListener(`load`,r),r(),()=>{window.removeEventListener(`locationchange`,r),window.removeEventListener(`popstate`,r),window.removeEventListener(`hashchange`,r),window.removeEventListener(`load`,r),history.pushState=e,history.replaceState=t}},[]),t};export{i as useCrossURLPathSetter,r as useCrossURLPathState};
|
|
2
2
|
//# sourceMappingURL=useCrossURLPathState.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditorLocale.mjs","names":[],"sources":["../../src/useEditorLocale.tsx"],"sourcesContent":["import { MessageKey } from '@intlayer/editor';\nimport type { Locale } from '@intlayer/types';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport const useEditorLocale = () => {\n const [currentLocale] = useCrossFrameState<Locale>(\n MessageKey.INTLAYER_CURRENT_LOCALE,\n undefined,\n {\n receive: true,\n emit: false,\n }\n );\n\n return currentLocale;\n};\n\nexport const useSetEditorLocale = () => {\n const setCurrentLocale = useCrossFrameState<Locale>(\n MessageKey.INTLAYER_CURRENT_LOCALE,\n undefined,\n {\n receive: true,\n emit: false,\n }\n );\n\n return setCurrentLocale;\n};\n"],"mappings":"4GAIA,MAAa,MAAwB,CACnC,GAAM,CAAC,GAAiB,EACtB,EAAW,wBACX,IAAA,GACA,CACE,QAAS,GACT,KAAM,GACP,CACF,CAED,OAAO,GAGI,MACc,EACvB,EAAW,wBACX,IAAA,GACA,CACE,QAAS,GACT,KAAM,GACP,CACF"}
|
|
1
|
+
{"version":3,"file":"useEditorLocale.mjs","names":[],"sources":["../../src/useEditorLocale.tsx"],"sourcesContent":["import { MessageKey } from '@intlayer/editor';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport const useEditorLocale = () => {\n const [currentLocale] = useCrossFrameState<Locale>(\n MessageKey.INTLAYER_CURRENT_LOCALE,\n undefined,\n {\n receive: true,\n emit: false,\n }\n );\n\n return currentLocale;\n};\n\nexport const useSetEditorLocale = () => {\n const setCurrentLocale = useCrossFrameState<Locale>(\n MessageKey.INTLAYER_CURRENT_LOCALE,\n undefined,\n {\n receive: true,\n emit: false,\n }\n );\n\n return setCurrentLocale;\n};\n"],"mappings":"4GAIA,MAAa,MAAwB,CACnC,GAAM,CAAC,GAAiB,EACtB,EAAW,wBACX,IAAA,GACA,CACE,QAAS,GACT,KAAM,GACP,CACF,CAED,OAAO,GAGI,MACc,EACvB,EAAW,wBACX,IAAA,GACA,CACE,QAAS,GACT,KAAM,GACP,CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{
|
|
1
|
+
"use client";import{useFocusDictionary as e}from"./FocusDictionaryContext.mjs";import{useDictionariesRecord as t}from"./DictionariesRecordContext.mjs";import{useEditorLocale as n}from"./useEditorLocale.mjs";import{useMemo as r}from"react";import{getContentNodeByKeyPath as i}from"@intlayer/core/dictionaryManipulator";const a=(e,t,n)=>{for(let r of t)try{if(i(r.content,e??[],n))return{keyPath:e,dictionaryLocalId:r.localId}}catch{}},o=()=>{let{localeDictionaries:i}=t(),o=n(),{setFocusedContent:s,setFocusedContentKeyPath:c,focusedContent:l}=e();return{focusedContent:r(()=>{if(!l||!i||l.dictionaryLocalId)return l;let e=Object.values(i).filter(e=>e.key===l.dictionaryKey),t=a(l.keyPath??[],e,o);return{...l,...t}},[l,i,o]),setFocusedContent:s,setFocusedContentKeyPath:c}};export{o as useFocusUnmergedDictionary};
|
|
2
2
|
//# sourceMappingURL=useFocusUnmergedDictionary.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFocusUnmergedDictionary.mjs","names":[],"sources":["../../src/useFocusUnmergedDictionary.tsx"],"sourcesContent":["'use client';\n\nimport { getContentNodeByKeyPath } from '@intlayer/core/dictionaryManipulator';\nimport type {
|
|
1
|
+
{"version":3,"file":"useFocusUnmergedDictionary.mjs","names":[],"sources":["../../src/useFocusUnmergedDictionary.tsx"],"sourcesContent":["'use client';\n\nimport { getContentNodeByKeyPath } from '@intlayer/core/dictionaryManipulator';\nimport type { Dictionary, LocalDictionaryId } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useMemo } from 'react';\nimport { useDictionariesRecord } from './DictionariesRecordContext';\nimport { type FileContent, useFocusDictionary } from './FocusDictionaryContext';\nimport { useEditorLocale } from './useEditorLocale';\n\ntype UnmergedKeyPath = {\n keyPath: KeyPath[];\n dictionaryLocalId?: LocalDictionaryId;\n};\n\n/**\n * Converts merged keypath format to unmerged format.\n * Merged: [{type: \"translation\", key: \"fr\"}, {type: \"object\", key: \"title\"}]\n * Unmerged: [{type: \"object\", key: \"title\"}, {type: \"translation\", key: \"fr\"}]\n */\nconst mergedKeyPathToUnmergedKeyPath = (\n keyPath: KeyPath[],\n dictionaries: Dictionary[],\n locale: Locale\n): UnmergedKeyPath | undefined => {\n // If we have a dictionary, verify the path exists\n // Try to find the correct position for the translation key\n // by checking which path actually exists in the dictionary\n for (const dictionary of dictionaries) {\n try {\n const result = getContentNodeByKeyPath(\n dictionary.content,\n keyPath ?? [],\n locale\n );\n\n if (result) {\n return { keyPath, dictionaryLocalId: dictionary.localId };\n }\n } catch {\n // Continue to next candidate\n }\n }\n};\n\nexport const useFocusUnmergedDictionary = () => {\n const { localeDictionaries } = useDictionariesRecord();\n const currentLocale = useEditorLocale();\n const {\n setFocusedContent,\n setFocusedContentKeyPath,\n focusedContent: mergedFocusedContent,\n } = useFocusDictionary();\n\n const focusedContent = useMemo<FileContent | null>(() => {\n if (!mergedFocusedContent) return mergedFocusedContent;\n if (!localeDictionaries) return mergedFocusedContent;\n if (mergedFocusedContent.dictionaryLocalId) return mergedFocusedContent;\n\n const dictionaries = Object.values(localeDictionaries).filter(\n (dictionary) => dictionary.key === mergedFocusedContent.dictionaryKey\n );\n\n const unmergedKeyPath = mergedKeyPathToUnmergedKeyPath(\n mergedFocusedContent.keyPath ?? [],\n dictionaries,\n currentLocale\n );\n\n return {\n ...mergedFocusedContent,\n ...unmergedKeyPath,\n };\n }, [mergedFocusedContent, localeDictionaries, currentLocale]);\n\n return {\n focusedContent,\n setFocusedContent,\n setFocusedContentKeyPath,\n };\n};\n"],"mappings":"8TAqBA,MAAM,GACJ,EACA,EACA,IACgC,CAIhC,IAAK,IAAM,KAAc,EACvB,GAAI,CAOF,GANe,EACb,EAAW,QACX,GAAW,EAAE,CACb,EACD,CAGC,MAAO,CAAE,UAAS,kBAAmB,EAAW,QAAS,MAErD,IAMC,MAAmC,CAC9C,GAAM,CAAE,sBAAuB,GAAuB,CAChD,EAAgB,GAAiB,CACjC,CACJ,oBACA,2BACA,eAAgB,GACd,GAAoB,CAuBxB,MAAO,CACL,eAtBqB,MAAkC,CAGvD,GAFI,CAAC,GACD,CAAC,GACD,EAAqB,kBAAmB,OAAO,EAEnD,IAAM,EAAe,OAAO,OAAO,EAAmB,CAAC,OACpD,GAAe,EAAW,MAAQ,EAAqB,cACzD,CAEK,EAAkB,EACtB,EAAqB,SAAW,EAAE,CAClC,EACA,EACD,CAED,MAAO,CACL,GAAG,EACH,GAAG,EACJ,EACA,CAAC,EAAsB,EAAoB,EAAc,CAAC,CAI3D,oBACA,2BACD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{useCrossFrameMessageListener as e}from"./useCrossFrameMessageListener.mjs";import{
|
|
1
|
+
"use client";import{useCrossFrameMessageListener as e}from"./useCrossFrameMessageListener.mjs";import{MessageKey as t,mergeIframeClick as n}from"@intlayer/editor";import{useEffect as r}from"react";const i=()=>{let n=e(t.INTLAYER_IFRAME_CLICKED),i=()=>{n()};r(()=>(window.addEventListener(`mousedown`,i),()=>window.removeEventListener(`mousedown`,i)),[n])},a=()=>e(t.INTLAYER_IFRAME_CLICKED,n);export{i as useIframeClickInterceptor,a as useIframeClickMerger};
|
|
2
2
|
//# sourceMappingURL=useIframeClickInterceptor.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from "react";
|
|
2
2
|
import { FC, PropsWithChildren } from "react";
|
|
3
|
-
import { IntlayerConfig } from "@intlayer/types";
|
|
3
|
+
import { IntlayerConfig } from "@intlayer/types/config";
|
|
4
4
|
|
|
5
5
|
//#region src/ConfigurationContext.d.ts
|
|
6
6
|
declare const useConfigurationState: () => [IntlayerConfig, react.Dispatch<react.SetStateAction<IntlayerConfig>>, () => void];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Dispatch, FC, PropsWithChildren, SetStateAction } from "react";
|
|
2
|
-
import { Dictionary, LocalDictionaryId } from "@intlayer/types";
|
|
2
|
+
import { Dictionary, LocalDictionaryId } from "@intlayer/types/dictionary";
|
|
3
3
|
|
|
4
4
|
//#region src/DictionariesRecordContext.d.ts
|
|
5
5
|
type DictionaryContent = Record<LocalDictionaryId, Dictionary>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DictionaryContent } from "./DictionariesRecordContext.js";
|
|
2
2
|
import { Dispatch, FC, PropsWithChildren, SetStateAction } from "react";
|
|
3
|
-
import { ContentNode, Dictionary,
|
|
3
|
+
import { ContentNode, Dictionary, LocalDictionaryId } from "@intlayer/types/dictionary";
|
|
4
|
+
import { KeyPath } from "@intlayer/types/keyPath";
|
|
4
5
|
|
|
5
6
|
//#region src/EditedContentContext.d.ts
|
|
6
7
|
declare const usePostEditedContentState: <S>(onEventTriggered?: (data: S) => void) => (data?: S) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditedContentContext.d.ts","names":[],"sources":["../../src/EditedContentContext.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"EditedContentContext.d.ts","names":[],"sources":["../../src/EditedContentContext.tsx"],"mappings":";;;;;;cAmCa,yBAAA,MACX,gBAAA,IAAoB,IAAA,EAAM,CAAA,eAAU,IAAA,GAAA,CAAA;AAAA,cAOzB,wBAAA,MACX,gBAAA,IAAoB,IAAA,EAAM,CAAA,eAAU,IAAA,GAAA,CAAA;AAAA,KAOjC,+BAAA;EACH,qBAAA,GAAwB,aAAA,EAAe,iBAAA;EACvC,mBAAA,EAAqB,QAAA,CAAS,cAAA,CAAe,UAAA;EAC7C,gBAAA,GACE,iBAAA,EAAmB,iBAAA,EACnB,QAAA,EAAU,UAAA;EAEZ,gBAAA,GACE,iBAAA,EAAmB,iBAAA,EACnB,QAAA,EAAU,WAAA,OACV,OAAA,GAAU,OAAA,IACV,SAAA;EAEF,mBAAA,GACE,iBAAA,EAAmB,iBAAA,EACnB,MAAA,EAAQ,OAAA,SACR,OAAA,GAAU,OAAA;EAEZ,mBAAA,GACE,iBAAA,EAAmB,iBAAA,EACnB,OAAA,EAAS,OAAA;EAEX,oBAAA,GAAuB,iBAAA,EAAmB,iBAAA;EAC1C,4BAAA,GAA+B,iBAAA,EAAmB,iBAAA;EAClD,kBAAA;EACA,qBAAA,GACE,sBAAA,EAAwB,iBAAA,GAAoB,UAAA,kBAC5C,OAAA,EAAS,OAAA,OACN,WAAA;AAAA;AAAA,cAYM,qBAAA,EAAuB,EAAA,CAAG,iBAAA;AAAA,cAgQ1B,uBAAA,QAAuB,+BAAA;AAAA,cAGvB,gBAAA;0BA1Sa,aAAA,EAAe,iBAAA;uBAClB,QAAA,CAAS,cAAA,CAAe,UAAA;qBAE3C,iBAAA,EAAmB,iBAAA,EACnB,QAAA,EAAU,UAAA;qBAGV,iBAAA,EAAmB,iBAAA,EACnB,QAAA,EAAU,WAAA,OACV,OAAA,GAAU,OAAA,IACV,SAAA;wBAGA,iBAAA,EAAmB,iBAAA,EACnB,MAAA,EAAQ,OAAA,SACR,OAAA,GAAU,OAAA;wBAGV,iBAAA,EAAmB,iBAAA,EACnB,OAAA,EAAS,OAAA;yBAEY,iBAAA,EAAmB,iBAAA;iCACX,iBAAA,EAAmB,iBAAA;;0BAGhD,sBAAA,EAAwB,iBAAA,GAAoB,UAAA,kBAC5C,OAAA,EAAS,OAAA,OACN,WAAA;iBAnDU,MAAA,CAAO,iBAAA,EAAmB,UAAA;AAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Dispatch, FC, PropsWithChildren, SetStateAction } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { LocalDictionaryId } from "@intlayer/types/dictionary";
|
|
3
|
+
import { KeyPath } from "@intlayer/types/keyPath";
|
|
3
4
|
|
|
4
5
|
//#region src/FocusDictionaryContext.d.ts
|
|
5
6
|
type FileContent = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FocusDictionaryContext.d.ts","names":[],"sources":["../../src/FocusDictionaryContext.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"FocusDictionaryContext.d.ts","names":[],"sources":["../../src/FocusDictionaryContext.tsx"],"mappings":";;;;;KAgBY,WAAA;EACV,aAAA;EACA,iBAAA,GAAoB,iBAAA;EACpB,OAAA,GAAU,OAAA;AAAA;AAAA,KAGA,oBAAA;EACV,cAAA,EAAgB,WAAA;AAAA;AAAA,KAGN,sBAAA;EACV,iBAAA,EAAmB,QAAA,CAAS,cAAA,CAAe,WAAA;EAC3C,wBAAA,GAA2B,OAAA,EAAS,OAAA;AAAA;AAAA,cAUzB,uBAAA,EAAyB,EAAA,CAAG,iBAAA;AAAA,cAsC5B,yBAAA,QAAyB,sBAAA;AAAA,cAUzB,kBAAA;qBA3DQ,QAAA,CAAS,cAAA,CAAe,WAAA;6BAChB,OAAA,EAAS,OAAA;kBALpB,WAAA;AAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FileContent } from "./FocusDictionaryContext.js";
|
|
2
2
|
import * as react from "react";
|
|
3
|
-
import { KeyPath } from "@intlayer/types";
|
|
3
|
+
import { KeyPath } from "@intlayer/types/keyPath";
|
|
4
4
|
|
|
5
5
|
//#region src/useFocusUnmergedDictionary.d.ts
|
|
6
6
|
declare const useFocusUnmergedDictionary: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFocusUnmergedDictionary.d.ts","names":[],"sources":["../../src/useFocusUnmergedDictionary.tsx"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"useFocusUnmergedDictionary.d.ts","names":[],"sources":["../../src/useFocusUnmergedDictionary.tsx"],"mappings":";;;;;cA8Ca,0BAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/editor-react",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.3.0-canary.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Provides the states, contexts, hooks and components to interact with the Intlayer editor for a React application",
|
|
6
6
|
"keywords": [
|
|
@@ -52,29 +52,29 @@
|
|
|
52
52
|
"./package.json"
|
|
53
53
|
],
|
|
54
54
|
"scripts": {
|
|
55
|
-
"build": "tsdown --config tsdown.config.ts",
|
|
56
|
-
"build:ci": "tsdown --config tsdown.config.ts",
|
|
57
|
-
"clean": "rimraf ./dist .turbo",
|
|
58
|
-
"dev": "tsdown --config tsdown.config.ts --watch",
|
|
59
|
-
"format": "biome format . --check",
|
|
60
|
-
"format:fix": "biome format --write .",
|
|
61
|
-
"lint": "biome lint .",
|
|
62
|
-
"lint:fix": "biome lint --write .",
|
|
55
|
+
"build": "bun --bun tsdown --config tsdown.config.ts",
|
|
56
|
+
"build:ci": "bun --bun tsdown --config tsdown.config.ts",
|
|
57
|
+
"clean": "bun --bun rimraf ./dist .turbo",
|
|
58
|
+
"dev": "bun --bun tsdown --config tsdown.config.ts --watch",
|
|
59
|
+
"format": "bun --bun biome format . --check",
|
|
60
|
+
"format:fix": "bun --bun biome format --write .",
|
|
61
|
+
"lint": "bun --bun biome lint .",
|
|
62
|
+
"lint:fix": "bun --bun biome lint --write .",
|
|
63
63
|
"process-files": "ts-node src/transpiler/processFilesCLI.ts --dir $npm_config_dir --extension $npm_config_extension --no-node-snapshot",
|
|
64
64
|
"prepublish": "cp -f ../../../README.md ./README.md",
|
|
65
65
|
"publish": "bun publish || true",
|
|
66
66
|
"publish:canary": "bun publish --access public --tag canary || true",
|
|
67
67
|
"publish:latest": "bun publish --access public --tag latest || true",
|
|
68
|
-
"test": "vitest run",
|
|
69
|
-
"test:watch": "vitest",
|
|
68
|
+
"test": "bun --bun vitest run",
|
|
69
|
+
"test:watch": "bun --bun vitest",
|
|
70
70
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@intlayer/config": "8.
|
|
74
|
-
"@intlayer/core": "8.
|
|
75
|
-
"@intlayer/editor": "8.
|
|
76
|
-
"@intlayer/types": "8.
|
|
77
|
-
"@intlayer/unmerged-dictionaries-entry": "8.
|
|
73
|
+
"@intlayer/config": "8.3.0-canary.0",
|
|
74
|
+
"@intlayer/core": "8.3.0-canary.0",
|
|
75
|
+
"@intlayer/editor": "8.3.0-canary.0",
|
|
76
|
+
"@intlayer/types": "8.3.0-canary.0",
|
|
77
|
+
"@intlayer/unmerged-dictionaries-entry": "8.3.0-canary.0"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
80
|
"@types/node": "25.3.5",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"react": ">=16.0.0",
|
|
87
87
|
"react-dom": ">=16.0.0",
|
|
88
88
|
"rimraf": "6.1.3",
|
|
89
|
-
"tsdown": "0.21.
|
|
89
|
+
"tsdown": "0.21.1",
|
|
90
90
|
"typescript": "5.9.3",
|
|
91
91
|
"vitest": "4.0.18"
|
|
92
92
|
},
|