@intlayer/editor-react 7.0.2-canary.0 → 7.0.2
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/EditedContentContext.cjs +7 -2
- package/dist/cjs/EditedContentContext.cjs.map +1 -1
- package/dist/cjs/FocusDictionaryContext copy.cjs +57 -0
- package/dist/cjs/FocusDictionaryContext copy.cjs.map +1 -0
- package/dist/cjs/FocusDictionaryContext.cjs +4 -1
- package/dist/cjs/FocusDictionaryContext.cjs.map +1 -1
- package/dist/cjs/FocusDictionaryServerContext.cjs +24 -0
- package/dist/cjs/FocusDictionaryServerContext.cjs.map +1 -0
- package/dist/cjs/FocusDictionaryUnmergedContext.cjs +102 -0
- package/dist/cjs/FocusDictionaryUnmergedContext.cjs.map +1 -0
- package/dist/cjs/index.cjs +5 -0
- package/dist/cjs/useCrossFrameMessageListener.cjs +6 -1
- package/dist/cjs/useCrossFrameMessageListener.cjs.map +1 -1
- package/dist/cjs/useEditorLocale.cjs +24 -0
- package/dist/cjs/useEditorLocale.cjs.map +1 -0
- package/dist/cjs/useFocusUnmergedDictionary.cjs +64 -0
- package/dist/cjs/useFocusUnmergedDictionary.cjs.map +1 -0
- package/dist/esm/EditedContentContext.mjs +6 -2
- package/dist/esm/EditedContentContext.mjs.map +1 -1
- package/dist/esm/FocusDictionaryContext copy.mjs +51 -0
- package/dist/esm/FocusDictionaryContext copy.mjs.map +1 -0
- package/dist/esm/FocusDictionaryContext.mjs +3 -1
- package/dist/esm/FocusDictionaryContext.mjs.map +1 -1
- package/dist/esm/FocusDictionaryServerContext.mjs +21 -0
- package/dist/esm/FocusDictionaryServerContext.mjs.map +1 -0
- package/dist/esm/FocusDictionaryUnmergedContext.mjs +93 -0
- package/dist/esm/FocusDictionaryUnmergedContext.mjs.map +1 -0
- package/dist/esm/index.mjs +3 -1
- package/dist/esm/useCrossFrameMessageListener.mjs +6 -1
- package/dist/esm/useCrossFrameMessageListener.mjs.map +1 -1
- package/dist/esm/useEditorLocale.mjs +21 -0
- package/dist/esm/useEditorLocale.mjs.map +1 -0
- package/dist/esm/useFocusUnmergedDictionary.mjs +61 -0
- package/dist/esm/useFocusUnmergedDictionary.mjs.map +1 -0
- package/dist/types/ConfigurationContext.d.ts +2 -2
- package/dist/types/EditedContentContext.d.ts.map +1 -1
- package/dist/types/EditorEnabledContext.d.ts +2 -2
- package/dist/types/FocusDictionaryContext copy.d.ts +23 -0
- package/dist/types/FocusDictionaryContext copy.d.ts.map +1 -0
- package/dist/types/FocusDictionaryContext.d.ts +6 -3
- package/dist/types/FocusDictionaryContext.d.ts.map +1 -1
- package/dist/types/FocusDictionaryServerContext.d.ts +9 -0
- package/dist/types/FocusDictionaryServerContext.d.ts.map +1 -0
- package/dist/types/FocusDictionaryUnmergedContext.d.ts +43 -0
- package/dist/types/FocusDictionaryUnmergedContext.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -2
- package/dist/types/useCrossFrameMessageListener.d.ts.map +1 -1
- package/dist/types/useCrossURLPathState.d.ts +3 -3
- package/dist/types/useEditorLocale.d.ts +9 -0
- package/dist/types/useEditorLocale.d.ts.map +1 -0
- package/dist/types/useFocusUnmergedDictionary.d.ts +13 -0
- package/dist/types/useFocusUnmergedDictionary.d.ts.map +1 -0
- package/package.json +13 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditedContentContext.mjs","names":["EditedContentProvider: FC<PropsWithChildren>","setEditedDictionary: Dispatch<SetStateAction<Dictionary>>","updatedDictionaries: Dictionary","lastKeyPath: KeyPath"],"sources":["../../src/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n editDictionaryByKeyPath,\n getContentNodeByKeyPath,\n renameContentNodeByKeyPath,\n} from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport type {\n ContentNode,\n Dictionary,\n KeyPath,\n LocalDictionaryId,\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';\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\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 const otherKeyPath = keyPath.slice(0, -1);\n const lastKeyPath: KeyPath = keyPath[keyPath.length - 1];\n let finalKey = lastKeyPath.key;\n\n // Loop until we find a key that does not exist\n while (\n typeof getContentNodeByKeyPath(currentContent, newKeyPath) !==\n 'undefined'\n ) {\n index++;\n finalKey =\n index === 0 ? lastKeyPath.key : `${lastKeyPath.key} (${index})`;\n newKeyPath = [\n ...otherKeyPath,\n { ...lastKeyPath, key: finalKey } as KeyPath,\n ];\n }\n }\n\n const updatedContent = editDictionaryByKeyPath(\n currentContent,\n newKeyPath,\n newValue\n );\n\n return {\n ...prev,\n [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 = Object.entries(prev).reduce((acc, [key, value]) => {\n if (key === localDictionaryId) {\n return acc;\n }\n return { ...acc, [key]: value };\n }, {} as DictionaryContent);\n return filtered;\n });\n };\n\n const clearEditedContent = () => {\n setEditedContentState({});\n };\n\n const getEditedContentValue = (\n localDictionaryIdOrKey: LocalDictionaryId | Dictionary['key'] | string,\n keyPath: KeyPath[]\n ): ContentNode | undefined => {\n if (!editedContent) return undefined;\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(currentContent, keyPath);\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(currentContent, keyPath);\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":";;;;;;;;;;;;AAiCA,MAAM,4BAA4B,cAEhC,OAAU;AAEZ,MAAa,6BACX,qBAEA,6BACE,GAAG,WAAW,gCAAgC,QAC9C,iBACD;AAEH,MAAa,4BACX,qBAEA,6BACE,GAAG,WAAW,gCAAgC,OAC9C,iBACD;AAiCH,MAAM,8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AW,GAAG,uBAAuB,GAAG,CACtD;AAED,OAAK,MAAM,qBAAqB,6BAA6B;GAG3D,MAAM,cAAc,wBADlB,gBAAgB,oBAAyC,WAAW,EAAE,EACZ,QAAQ;AAEpE,OAAI,YAAa,QAAO;;;AAM5B,QACE,oBAAC,0BAA0B;EACzB,OAAO,EACL,eACD;YAED,oBAAC,4BAA4B;GAC3B,OAAO;IACL;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACD;GAEA;IACoC;GACJ;;AAIzC,MAAa,gCACX,WAAW,4BAA4B;AAEzC,MAAa,yBAAyB;CACpC,MAAM,eAAe,WAAW,0BAA0B;CAC1D,MAAM,gBAAgB,yBAAyB;AAE/C,QAAO;EAAE,GAAG;EAAc,GAAG;EAAe"}
|
|
1
|
+
{"version":3,"file":"EditedContentContext.mjs","names":["EditedContentProvider: FC<PropsWithChildren>","setEditedDictionary: Dispatch<SetStateAction<Dictionary>>","updatedDictionaries: Dictionary","lastKeyPath: KeyPath"],"sources":["../../src/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n editDictionaryByKeyPath,\n getContentNodeByKeyPath,\n renameContentNodeByKeyPath,\n} from '@intlayer/core';\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 = Object.entries(prev).reduce((acc, [key, value]) => {\n if (key === localDictionaryId) {\n return acc;\n }\n return { ...acc, [key]: value };\n }, {} as DictionaryContent);\n return filtered;\n });\n };\n\n const clearEditedContent = () => {\n setEditedContentState({});\n };\n\n const getEditedContentValue = (\n 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":";;;;;;;;;;;;;;AAmCA,MAAM,4BAA4B,cAEhC,OAAU;AAEZ,MAAa,6BACX,qBAEA,6BACE,GAAG,WAAW,gCAAgC,QAC9C,iBACD;AAEH,MAAa,4BACX,qBAEA,6BACE,GAAG,WAAW,gCAAgC,OAC9C,iBACD;AAiCH,MAAM,8BAA8B,cAElC,OAAU;AAEZ,MAAM,gBAAoB,OAA2B,cACnD,OAAO,UAAU,aACZ,MAA+B,UAAU,GACzC;AAEP,MAAaA,yBAAgD,EAAE,eAAe;CAC5E,MAAM,EAAE,uBAAuB,uBAAuB;CACtD,MAAM,gBAAgB,iBAAiB;CA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gB,oBAAyC,WAAW,EAAE,EAGtE,iBACA,cACD;AAED,OAAI,YAAa,QAAO;;;AAM5B,QACE,oBAAC,0BAA0B;EACzB,OAAO,EACL,eACD;YAED,oBAAC,4BAA4B;GAC3B,OAAO;IACL;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACD;GAEA;IACoC;GACJ;;AAIzC,MAAa,gCACX,WAAW,4BAA4B;AAEzC,MAAa,yBAAyB;CACpC,MAAM,eAAe,WAAW,0BAA0B;CAC1D,MAAM,gBAAgB,yBAAyB;AAE/C,QAAO;EAAE,GAAG;EAAc,GAAG;EAAe"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { useCrossFrameState } from "./useCrossFrameState.mjs";
|
|
5
|
+
import { createContext, useContext } from "react";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import { MessageKey } from "@intlayer/editor";
|
|
8
|
+
|
|
9
|
+
//#region src/FocusDictionaryContext copy.tsx
|
|
10
|
+
const FocusDictionaryStateContext = createContext(void 0);
|
|
11
|
+
const FocusDictionaryActionsContext = createContext(void 0);
|
|
12
|
+
const FocusDictionaryProvider = ({ children }) => {
|
|
13
|
+
const [focusedContent, setFocusedContent] = useCrossFrameState(MessageKey.INTLAYER_FOCUSED_CONTENT_CHANGED, null);
|
|
14
|
+
const setFocusedContentKeyPath = (keyPath) => {
|
|
15
|
+
setFocusedContent((prev) => {
|
|
16
|
+
if (!prev) return prev;
|
|
17
|
+
return {
|
|
18
|
+
...prev,
|
|
19
|
+
keyPath
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
return /* @__PURE__ */ jsx(FocusDictionaryStateContext.Provider, {
|
|
24
|
+
value: { focusedContent },
|
|
25
|
+
children: /* @__PURE__ */ jsx(FocusDictionaryActionsContext.Provider, {
|
|
26
|
+
value: {
|
|
27
|
+
setFocusedContent,
|
|
28
|
+
setFocusedContentKeyPath
|
|
29
|
+
},
|
|
30
|
+
children
|
|
31
|
+
})
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
const useFocusDictionaryActions = () => {
|
|
35
|
+
const context = useContext(FocusDictionaryActionsContext);
|
|
36
|
+
if (context === void 0) throw new Error("useFocusDictionaryActions must be used within a FocusDictionaryProvider");
|
|
37
|
+
return context;
|
|
38
|
+
};
|
|
39
|
+
const useFocusDictionary = () => {
|
|
40
|
+
const actionContext = useFocusDictionaryActions();
|
|
41
|
+
const stateContext = useContext(FocusDictionaryStateContext);
|
|
42
|
+
if (stateContext === void 0) throw new Error("useFocusDictionaryState must be used within a FocusDictionaryProvider");
|
|
43
|
+
return {
|
|
44
|
+
...stateContext,
|
|
45
|
+
...actionContext
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
export { FocusDictionaryProvider, useFocusDictionary, useFocusDictionaryActions };
|
|
51
|
+
//# sourceMappingURL=FocusDictionaryContext copy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FocusDictionaryContext copy.mjs","names":["FocusDictionaryProvider: FC<PropsWithChildren>"],"sources":["../../src/FocusDictionaryContext copy.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { KeyPath } from '@intlayer/types';\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?: string;\n keyPath?: KeyPath[];\n};\n\ntype FocusDictionaryState = {\n focusedContent: FileContent | null;\n};\n\ntype 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 return { ...prev, keyPath };\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":";;;;;;;;;AA6BA,MAAM,8BAA8B,cAElC,OAAU;AACZ,MAAM,gCAAgC,cAEpC,OAAU;AAEZ,MAAaA,2BAAkD,EAC7D,eACI;CACJ,MAAM,CAAC,gBAAgB,qBACrB,mBACE,WAAW,kCACX,KACD;CAEH,MAAM,4BAA4B,YAAuB;AACvD,qBAAmB,SAAS;AAC1B,OAAI,CAAC,KACH,QAAO;AAET,UAAO;IAAE,GAAG;IAAM;IAAS;IAC3B;;AAGJ,QACE,oBAAC,4BAA4B;EAAS,OAAO,EAAE,gBAAgB;YAC7D,oBAAC,8BAA8B;GAC7B,OAAO;IAAE;IAAmB;IAA0B;GAErD;IACsC;GACJ;;AAI3C,MAAa,kCAAkC;CAC7C,MAAM,UAAU,WAAW,8BAA8B;AACzD,KAAI,YAAY,OACd,OAAM,IAAI,MACR,0EACD;AAEH,QAAO;;AAGT,MAAa,2BAA2B;CACtC,MAAM,gBAAgB,2BAA2B;CACjD,MAAM,eAAe,WAAW,4BAA4B;AAE5D,KAAI,iBAAiB,OACnB,OAAM,IAAI,MACR,wEACD;AAGH,QAAO;EAAE,GAAG;EAAc,GAAG;EAAe"}
|
|
@@ -5,6 +5,7 @@ import { useCrossFrameState } from "./useCrossFrameState.mjs";
|
|
|
5
5
|
import { createContext, useContext } from "react";
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
7
7
|
import { MessageKey } from "@intlayer/editor";
|
|
8
|
+
import { NodeType } from "@intlayer/types";
|
|
8
9
|
|
|
9
10
|
//#region src/FocusDictionaryContext.tsx
|
|
10
11
|
const FocusDictionaryStateContext = createContext(void 0);
|
|
@@ -14,9 +15,10 @@ const FocusDictionaryProvider = ({ children }) => {
|
|
|
14
15
|
const setFocusedContentKeyPath = (keyPath) => {
|
|
15
16
|
setFocusedContent((prev) => {
|
|
16
17
|
if (!prev) return prev;
|
|
18
|
+
const filteredKeyPath = keyPath.filter((key) => key.type !== NodeType.Translation);
|
|
17
19
|
return {
|
|
18
20
|
...prev,
|
|
19
|
-
keyPath
|
|
21
|
+
keyPath: filteredKeyPath
|
|
20
22
|
};
|
|
21
23
|
});
|
|
22
24
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FocusDictionaryContext.mjs","names":["FocusDictionaryProvider: FC<PropsWithChildren>"],"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type
|
|
1
|
+
{"version":3,"file":"FocusDictionaryContext.mjs","names":["FocusDictionaryProvider: FC<PropsWithChildren>"],"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport {\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 { 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":";;;;;;;;;;AAiCA,MAAM,8BAA8B,cAElC,OAAU;AACZ,MAAM,gCAAgC,cAEpC,OAAU;AAEZ,MAAaA,2BAAkD,EAC7D,eACI;CACJ,MAAM,CAAC,gBAAgB,qBACrB,mBACE,WAAW,kCACX,KACD;CAEH,MAAM,4BAA4B,YAAuB;AACvD,qBAAmB,SAAS;AAC1B,OAAI,CAAC,KACH,QAAO;GAIT,MAAM,kBAAkB,QAAQ,QAC7B,QAAQ,IAAI,SAAS,SAAS,YAChC;AAED,UAAO;IACL,GAAG;IACH,SAAS;IACV;IACD;;AAGJ,QACE,oBAAC,4BAA4B;EAAS,OAAO,EAAE,gBAAgB;YAC7D,oBAAC,8BAA8B;GAC7B,OAAO;IAAE;IAAmB;IAA0B;GAErD;IACsC;GACJ;;AAI3C,MAAa,kCAAkC;CAC7C,MAAM,UAAU,WAAW,8BAA8B;AACzD,KAAI,YAAY,OACd,OAAM,IAAI,MACR,0EACD;AAEH,QAAO;;AAGT,MAAa,2BAA2B;CACtC,MAAM,gBAAgB,2BAA2B;CACjD,MAAM,eAAe,WAAW,4BAA4B;AAE5D,KAAI,iBAAiB,OACnB,OAAM,IAAI,MACR,wEACD;AAGH,QAAO;EAAE,GAAG;EAAc,GAAG;EAAe"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { useFocusDictionary } from "./FocusDictionaryContext.mjs";
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
import { NodeType } from "@intlayer/types";
|
|
7
|
+
|
|
8
|
+
//#region src/FocusDictionaryServerContext.tsx
|
|
9
|
+
const unmergedKeyPathToMergedKeyPath = (keyPath) => {
|
|
10
|
+
if (!keyPath.find((key) => key.type === NodeType.Translation)) return keyPath;
|
|
11
|
+
return [keyPath.find((key) => key.type === NodeType.Translation), ...keyPath.filter((key) => key.type !== NodeType.Translation)];
|
|
12
|
+
};
|
|
13
|
+
const useFocusUnmergedDictionary = () => {
|
|
14
|
+
const [focusedKeyPath, setFocusedKeyPath] = useState([]);
|
|
15
|
+
const { setFocusedContent: setMergedFocusedContent, setFocusedContentKeyPath: setMergedFocusedContentKeyPath, focusedContent: mergedFocusedContent } = useFocusDictionary();
|
|
16
|
+
return { focusedContent: unmergedKeyPathToMergedKeyPath(focusedKeyPath) };
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { useFocusUnmergedDictionary };
|
|
21
|
+
//# sourceMappingURL=FocusDictionaryServerContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FocusDictionaryServerContext.mjs","names":[],"sources":["../../src/FocusDictionaryServerContext.tsx"],"sourcesContent":["'use client';\n\nimport { type Dictionary, type KeyPath, NodeType } from '@intlayer/types';\nimport { useState } from 'react';\nimport { useFocusDictionary } from './FocusDictionaryContext';\n\nconst unmergedKeyPathToMergedKeyPath = (keyPath: KeyPath[]): KeyPath[] => {\n if (!keyPath.find((key) => key.type === NodeType.Translation)) return keyPath;\n\n const translationKeyPath = keyPath.find(\n (key) => key.type === NodeType.Translation\n )!;\n const otherKeyPath = keyPath.filter(\n (key) => key.type !== NodeType.Translation\n );\n\n return [translationKeyPath, ...otherKeyPath];\n};\n\nconst mergedKeyPathToUnmergedKeyPath = (\n keyPath: KeyPath[],\n dictionary: Dictionary\n): KeyPath[] => {\n if (!keyPath.find((key) => key.type === NodeType.Translation)) return keyPath;\n\n const translationKeyPath = keyPath.find(\n (key) => key.type === NodeType.Translation\n )!;\n const otherKeyPath = keyPath.filter(\n (key) => key.type !== NodeType.Translation\n );\n\n // it should insert the translation key path at the end and then end -1, end -2, etc.\n const candidates = Object(otherKeyPath.length).map((_, index) =>\n otherKeyPath.slice(0, index + 1)\n );\n\n for (const candidate of candidates) {\n const result = getContentNodeByKeyPath(dictionary.content, candidate);\n\n if (result) {\n return candidate;\n }\n }\n\n return null;\n};\n\nexport const useFocusUnmergedDictionary = () => {\n const [focusedKeyPath, setFocusedKeyPath] = useState<KeyPath[]>([]);\n\n const {\n setFocusedContent: setMergedFocusedContent,\n setFocusedContentKeyPath: setMergedFocusedContentKeyPath,\n focusedContent: mergedFocusedContent,\n } = useFocusDictionary();\n\n const focusedContent = unmergedKeyPathToMergedKeyPath(focusedKeyPath);\n\n return { focusedContent };\n};\n"],"mappings":";;;;;;;;AAMA,MAAM,kCAAkC,YAAkC;AACxE,KAAI,CAAC,QAAQ,MAAM,QAAQ,IAAI,SAAS,SAAS,YAAY,CAAE,QAAO;AAStE,QAAO,CAPoB,QAAQ,MAChC,QAAQ,IAAI,SAAS,SAAS,YAChC,EAK2B,GAJP,QAAQ,QAC1B,QAAQ,IAAI,SAAS,SAAS,YAChC,CAE2C;;AAgC9C,MAAa,mCAAmC;CAC9C,MAAM,CAAC,gBAAgB,qBAAqB,SAAoB,EAAE,CAAC;CAEnE,MAAM,EACJ,mBAAmB,yBACnB,0BAA0B,gCAC1B,gBAAgB,yBACd,oBAAoB;AAIxB,QAAO,EAAE,gBAFc,+BAA+B,eAAe,EAE5C"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { useFocusDictionary, useFocusDictionaryActions } from "./FocusDictionaryContext.mjs";
|
|
5
|
+
import { createContext, useContext, useMemo } from "react";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import { getContentNodeByKeyPath } from "@intlayer/core";
|
|
8
|
+
import { NodeType } from "@intlayer/types";
|
|
9
|
+
|
|
10
|
+
//#region src/FocusDictionaryUnmergedContext.tsx
|
|
11
|
+
/**
|
|
12
|
+
* Transforms a keypath from unmerged dictionary format to merged dictionary format.
|
|
13
|
+
* In merged format, translation keys come first.
|
|
14
|
+
*
|
|
15
|
+
* Example:
|
|
16
|
+
* Unmerged: [{ type: 'object', key: 'title' }, { type: 'translation', key: 'fr' }]
|
|
17
|
+
* Merged: [{ type: 'translation', key: 'fr' }, { type: 'object', key: 'title' }]
|
|
18
|
+
*/
|
|
19
|
+
const unmergedKeyPathToMergedKeyPath = (keyPath) => {
|
|
20
|
+
if (!keyPath || keyPath.length === 0) return keyPath;
|
|
21
|
+
const translationKeyPath = keyPath.find((key) => key.type === NodeType.Translation);
|
|
22
|
+
if (!translationKeyPath) return keyPath;
|
|
23
|
+
return [translationKeyPath, ...keyPath.filter((key) => key.type !== NodeType.Translation)];
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Transforms a keypath from merged dictionary format to unmerged dictionary format.
|
|
27
|
+
* In unmerged format, translation keys are placed at the appropriate nesting level.
|
|
28
|
+
*
|
|
29
|
+
* Example:
|
|
30
|
+
* Merged: [{ type: 'translation', key: 'fr' }, { type: 'object', key: 'title' }]
|
|
31
|
+
* Unmerged: [{ type: 'object', key: 'title' }, { type: 'translation', key: 'fr' }]
|
|
32
|
+
*/
|
|
33
|
+
const mergedKeyPathToUnmergedKeyPath = (keyPath, dictionary) => {
|
|
34
|
+
if (!keyPath || keyPath.length === 0) return keyPath;
|
|
35
|
+
const translationKeyPath = keyPath.find((key) => key.type === NodeType.Translation);
|
|
36
|
+
if (!translationKeyPath) return keyPath;
|
|
37
|
+
const otherKeyPaths = keyPath.filter((key) => key.type !== NodeType.Translation);
|
|
38
|
+
if (dictionary?.content) for (let i = otherKeyPaths.length; i >= 0; i--) {
|
|
39
|
+
const candidateKeyPath = [
|
|
40
|
+
...otherKeyPaths.slice(0, i),
|
|
41
|
+
translationKeyPath,
|
|
42
|
+
...otherKeyPaths.slice(i)
|
|
43
|
+
];
|
|
44
|
+
try {
|
|
45
|
+
if (getContentNodeByKeyPath(dictionary.content, candidateKeyPath)) return candidateKeyPath;
|
|
46
|
+
} catch {}
|
|
47
|
+
}
|
|
48
|
+
return [...otherKeyPaths, translationKeyPath];
|
|
49
|
+
};
|
|
50
|
+
const FocusDictionaryUnmergedStateContext = createContext(void 0);
|
|
51
|
+
const FocusDictionaryUnmergedActionsContext = createContext(void 0);
|
|
52
|
+
const FocusDictionaryUnmergedProvider = ({ children }) => {
|
|
53
|
+
const { focusedContent, setFocusedContent } = useFocusDictionary();
|
|
54
|
+
const { setFocusedContentKeyPath: setMergedKeyPath } = useFocusDictionaryActions();
|
|
55
|
+
const focusedUnmergedKeyPath = useMemo(() => {
|
|
56
|
+
if (!focusedContent?.keyPath) return void 0;
|
|
57
|
+
return focusedContent.keyPath;
|
|
58
|
+
}, [focusedContent?.keyPath]);
|
|
59
|
+
const setFocusedUnmergedKeyPath = (keyPath) => {
|
|
60
|
+
setMergedKeyPath(unmergedKeyPathToMergedKeyPath(keyPath));
|
|
61
|
+
};
|
|
62
|
+
return /* @__PURE__ */ jsx(FocusDictionaryUnmergedStateContext.Provider, {
|
|
63
|
+
value: {
|
|
64
|
+
focusedContent,
|
|
65
|
+
focusedUnmergedKeyPath
|
|
66
|
+
},
|
|
67
|
+
children: /* @__PURE__ */ jsx(FocusDictionaryUnmergedActionsContext.Provider, {
|
|
68
|
+
value: {
|
|
69
|
+
setFocusedContent,
|
|
70
|
+
setFocusedUnmergedKeyPath
|
|
71
|
+
},
|
|
72
|
+
children
|
|
73
|
+
})
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
const useFocusDictionaryUnmergedActions = () => {
|
|
77
|
+
const context = useContext(FocusDictionaryUnmergedActionsContext);
|
|
78
|
+
if (context === void 0) throw new Error("useFocusDictionaryUnmergedActions must be used within a FocusDictionaryUnmergedProvider");
|
|
79
|
+
return context;
|
|
80
|
+
};
|
|
81
|
+
const useFocusDictionaryUnmerged = () => {
|
|
82
|
+
const actionContext = useFocusDictionaryUnmergedActions();
|
|
83
|
+
const stateContext = useContext(FocusDictionaryUnmergedStateContext);
|
|
84
|
+
if (stateContext === void 0) throw new Error("useFocusDictionaryUnmerged must be used within a FocusDictionaryUnmergedProvider");
|
|
85
|
+
return {
|
|
86
|
+
...stateContext,
|
|
87
|
+
...actionContext
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
//#endregion
|
|
92
|
+
export { FocusDictionaryUnmergedProvider, mergedKeyPathToUnmergedKeyPath, unmergedKeyPathToMergedKeyPath, useFocusDictionaryUnmerged, useFocusDictionaryUnmergedActions };
|
|
93
|
+
//# sourceMappingURL=FocusDictionaryUnmergedContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FocusDictionaryUnmergedContext.mjs","names":["FocusDictionaryUnmergedProvider: FC<PropsWithChildren>"],"sources":["../../src/FocusDictionaryUnmergedContext.tsx"],"sourcesContent":["'use client';\n\nimport { getContentNodeByKeyPath } from '@intlayer/core';\nimport type { Dictionary, KeyPath } from '@intlayer/types';\nimport { NodeType } 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 {\n type FileContent,\n useFocusDictionary,\n useFocusDictionaryActions,\n} from './FocusDictionaryContext';\n\n/**\n * Transforms a keypath from unmerged dictionary format to merged dictionary format.\n * In merged format, translation keys come first.\n *\n * Example:\n * Unmerged: [{ type: 'object', key: 'title' }, { type: 'translation', key: 'fr' }]\n * Merged: [{ type: 'translation', key: 'fr' }, { type: 'object', key: 'title' }]\n */\nconst unmergedKeyPathToMergedKeyPath = (keyPath: KeyPath[]): KeyPath[] => {\n if (!keyPath || keyPath.length === 0) return keyPath;\n\n const translationKeyPath = keyPath.find(\n (key) => key.type === NodeType.Translation\n );\n\n // If no translation key, return as is\n if (!translationKeyPath) return keyPath;\n\n const otherKeyPaths = keyPath.filter(\n (key) => key.type !== NodeType.Translation\n );\n\n // Translation key comes first in merged format\n return [translationKeyPath, ...otherKeyPaths];\n};\n\n/**\n * Transforms a keypath from merged dictionary format to unmerged dictionary format.\n * In unmerged format, translation keys are placed at the appropriate nesting level.\n *\n * Example:\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 dictionary?: Dictionary\n): KeyPath[] => {\n if (!keyPath || keyPath.length === 0) return keyPath;\n\n const translationKeyPath = keyPath.find(\n (key) => key.type === NodeType.Translation\n );\n\n // If no translation key, return as is\n if (!translationKeyPath) return keyPath;\n\n const otherKeyPaths = keyPath.filter(\n (key) => key.type !== NodeType.Translation\n );\n\n // If we have a dictionary, try to find the correct position for the translation key\n if (dictionary?.content) {\n // Try inserting the translation key at different positions from end to start\n // to find where it should be placed in the unmerged structure\n for (let i = otherKeyPaths.length; i >= 0; i--) {\n const candidateKeyPath = [\n ...otherKeyPaths.slice(0, i),\n translationKeyPath,\n ...otherKeyPaths.slice(i),\n ];\n\n try {\n const result = getContentNodeByKeyPath(\n dictionary.content,\n candidateKeyPath\n );\n if (result) {\n return candidateKeyPath;\n }\n } catch {\n // Continue trying other positions\n }\n }\n }\n\n // Default: translation key at the end (most common unmerged format)\n return [...otherKeyPaths, translationKeyPath];\n};\n\nexport type FocusDictionaryUnmergedState = {\n focusedContent: FileContent | null;\n focusedUnmergedKeyPath: KeyPath[] | undefined;\n};\n\nexport type FocusDictionaryUnmergedActions = {\n setFocusedContent: Dispatch<SetStateAction<FileContent | null>>;\n setFocusedUnmergedKeyPath: (keyPath: KeyPath[]) => void;\n};\n\nconst FocusDictionaryUnmergedStateContext = createContext<\n FocusDictionaryUnmergedState | undefined\n>(undefined);\n\nconst FocusDictionaryUnmergedActionsContext = createContext<\n FocusDictionaryUnmergedActions | undefined\n>(undefined);\n\nexport const FocusDictionaryUnmergedProvider: FC<PropsWithChildren> = ({\n children,\n}) => {\n const { focusedContent, setFocusedContent } = useFocusDictionary();\n const { setFocusedContentKeyPath: setMergedKeyPath } =\n useFocusDictionaryActions();\n\n const focusedUnmergedKeyPath = useMemo(() => {\n if (!focusedContent?.keyPath) return undefined;\n // The focusedContent.keyPath from FocusDictionaryContext is in merged format\n // We don't transform it here because we don't have the dictionary\n // The consumer should use setFocusedUnmergedKeyPath with a dictionary\n return focusedContent.keyPath;\n }, [focusedContent?.keyPath]);\n\n const setFocusedUnmergedKeyPath = (keyPath: KeyPath[]) => {\n // Transform unmerged keypath to merged keypath before setting it\n const mergedKeyPath = unmergedKeyPathToMergedKeyPath(keyPath);\n setMergedKeyPath(mergedKeyPath);\n };\n\n return (\n <FocusDictionaryUnmergedStateContext.Provider\n value={{ focusedContent, focusedUnmergedKeyPath }}\n >\n <FocusDictionaryUnmergedActionsContext.Provider\n value={{ setFocusedContent, setFocusedUnmergedKeyPath }}\n >\n {children}\n </FocusDictionaryUnmergedActionsContext.Provider>\n </FocusDictionaryUnmergedStateContext.Provider>\n );\n};\n\nexport const useFocusDictionaryUnmergedActions = () => {\n const context = useContext(FocusDictionaryUnmergedActionsContext);\n if (context === undefined) {\n throw new Error(\n 'useFocusDictionaryUnmergedActions must be used within a FocusDictionaryUnmergedProvider'\n );\n }\n return context;\n};\n\nexport const useFocusDictionaryUnmerged = () => {\n const actionContext = useFocusDictionaryUnmergedActions();\n const stateContext = useContext(FocusDictionaryUnmergedStateContext);\n\n if (stateContext === undefined) {\n throw new Error(\n 'useFocusDictionaryUnmerged must be used within a FocusDictionaryUnmergedProvider'\n );\n }\n\n return { ...stateContext, ...actionContext };\n};\n\n// Export the mapper functions for use elsewhere\nexport { unmergedKeyPathToMergedKeyPath, mergedKeyPathToUnmergedKeyPath };\n"],"mappings":";;;;;;;;;;;;;;;;;;AA4BA,MAAM,kCAAkC,YAAkC;AACxE,KAAI,CAAC,WAAW,QAAQ,WAAW,EAAG,QAAO;CAE7C,MAAM,qBAAqB,QAAQ,MAChC,QAAQ,IAAI,SAAS,SAAS,YAChC;AAGD,KAAI,CAAC,mBAAoB,QAAO;AAOhC,QA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AO;;AAGT,MAAa,mCAAmC;CAC9C,MAAM,gBAAgB,mCAAmC;CACzD,MAAM,eAAe,WAAW,oCAAoC;AAEpE,KAAI,iBAAiB,OACnB,OAAM,IAAI,MACR,mFACD;AAGH,QAAO;EAAE,GAAG;EAAc,GAAG;EAAe"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -3,13 +3,15 @@ import { useCrossFrameMessageListener } from "./useCrossFrameMessageListener.mjs
|
|
|
3
3
|
import { useCrossFrameState } from "./useCrossFrameState.mjs";
|
|
4
4
|
import { ConfigurationProvider, useConfiguration, useConfigurationState } from "./ConfigurationContext.mjs";
|
|
5
5
|
import { DictionariesRecordProvider, useDictionariesRecord, useDictionariesRecordActions } from "./DictionariesRecordContext.mjs";
|
|
6
|
+
import { useEditorLocale, useSetEditorLocale } from "./useEditorLocale.mjs";
|
|
6
7
|
import { EditedContentProvider, useEditedContent, useEditedContentActions, useGetEditedContentState, usePostEditedContentState } from "./EditedContentContext.mjs";
|
|
7
8
|
import { EditorEnabledProvider, useEditorEnabled, useEditorEnabledState, useGetEditorEnabledState, usePostEditorEnabledState } from "./EditorEnabledContext.mjs";
|
|
8
9
|
import { FocusDictionaryProvider, useFocusDictionary, useFocusDictionaryActions } from "./FocusDictionaryContext.mjs";
|
|
9
10
|
import { EditorProvider } from "./EditorProvider.mjs";
|
|
10
11
|
import { useCrossURLPathSetter, useCrossURLPathState } from "./useCrossURLPathState.mjs";
|
|
12
|
+
import { useFocusUnmergedDictionary } from "./useFocusUnmergedDictionary.mjs";
|
|
11
13
|
import { useIframeClickInterceptor, useIframeClickMerger } from "./useIframeClickInterceptor.mjs";
|
|
12
14
|
|
|
13
15
|
export * from "@intlayer/editor"
|
|
14
16
|
|
|
15
|
-
export { CommunicatorProvider, ConfigurationProvider, DictionariesRecordProvider, EditedContentProvider, EditorEnabledProvider, EditorProvider, FocusDictionaryProvider, useCommunicator, useConfiguration, useConfigurationState, useCrossFrameMessageListener, useCrossFrameState, useCrossURLPathSetter, useCrossURLPathState, useDictionariesRecord, useDictionariesRecordActions, useEditedContent, useEditedContentActions, useEditorEnabled, useEditorEnabledState, useFocusDictionary, useFocusDictionaryActions, useGetEditedContentState, useGetEditorEnabledState, useIframeClickInterceptor, useIframeClickMerger, usePostEditedContentState, usePostEditorEnabledState };
|
|
17
|
+
export { CommunicatorProvider, ConfigurationProvider, DictionariesRecordProvider, EditedContentProvider, EditorEnabledProvider, EditorProvider, FocusDictionaryProvider, useCommunicator, useConfiguration, useConfigurationState, useCrossFrameMessageListener, useCrossFrameState, useCrossURLPathSetter, useCrossURLPathState, useDictionariesRecord, useDictionariesRecordActions, useEditedContent, useEditedContentActions, useEditorEnabled, useEditorEnabledState, useEditorLocale, useFocusDictionary, useFocusDictionaryActions, useFocusUnmergedDictionary, useGetEditedContentState, useGetEditorEnabledState, useIframeClickInterceptor, useIframeClickMerger, usePostEditedContentState, usePostEditorEnabledState, useSetEditorLocale };
|
|
@@ -38,7 +38,12 @@ const useCrossFrameMessageListener = (key, onEventTriggered, revalidator) => {
|
|
|
38
38
|
const { type, data, senderId: msgSenderId } = event.data;
|
|
39
39
|
if (type !== key) return;
|
|
40
40
|
if (msgSenderId === senderId) return;
|
|
41
|
-
if (typeof allowedOrigins === "undefined" || allowedOrigins?.
|
|
41
|
+
if (typeof allowedOrigins === "undefined" || allowedOrigins?.filter((url) => ![
|
|
42
|
+
null,
|
|
43
|
+
void 0,
|
|
44
|
+
"",
|
|
45
|
+
"*"
|
|
46
|
+
].includes(url)).some((url) => compareUrls(url, event.origin)) || allowedOrigins?.includes("*")) onEventTriggered(data);
|
|
42
47
|
};
|
|
43
48
|
window.addEventListener("message", handleMessage);
|
|
44
49
|
return () => window.removeEventListener("message", handleMessage);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCrossFrameMessageListener.mjs","names":["postMessageWrapper: (data?: S) => void"],"sources":["../../src/useCrossFrameMessageListener.tsx"],"sourcesContent":["'use client';\n\nimport { compareUrls, type MessageKey } from '@intlayer/editor';\nimport { useEffect } from 'react';\nimport { useCommunicator } from './CommunicatorContext';\n\n/**\n * useCrossFrameMessageListener\n *\n * This React hook listens for messages sent via the `postMessage` API and triggers a callback\n * whenever a message of the specified type (`key`) is received. It is useful for synchronizing\n * state or events across different windows, iframes, or contexts.\n *\n * @template S - The type of the data payload in the message.\n * @param key - A unique identifier for the message type to listen for.\n * @param [onEventTriggered] - A callback function triggered when a message\n * @param [revalidator] - A function that re-suscribes the listener. Could be usefull if onEventTriggered depend of some state\n * with the specified key is received. The callback receives the message data as its argument.\n *\n * @returns {{ postMessage: (data: S) => void }} An object containing a `postMessage` function\n * that allows broadcasting messages with the specified key and data.\n */\nexport const useCrossFrameMessageListener = <S,>(\n key: `${MessageKey}` | `${MessageKey}/post` | `${MessageKey}/get`,\n onEventTriggered?: (data: S) => void,\n revalidator?: any\n) => {\n const { allowedOrigins, postMessage, senderId } = useCommunicator();\n\n useEffect(() => {\n if (onEventTriggered) {\n /**\n * Message handler to process incoming messages.\n *\n * - **Message Filtering:** Ensures only messages with the specified `key` are processed.\n * - **Origin Validation:** Checks that the origin of the message is within the allowed origins.\n *\n * @param {MessageEvent<{ type: string; data: S }>} event - The incoming message event object.\n */\n const handleMessage = (\n event: MessageEvent<{ type: string; data: S; senderId: string }>\n ) => {\n const { type, data, senderId: msgSenderId } = event.data;\n\n // Ignore messages that do not match the current key\n if (type !== key) return;\n\n // Ignore messages from myself\n if (msgSenderId === senderId) return;\n\n // Check if the message origin is allowed\n if (\n typeof allowedOrigins === 'undefined' ||\n allowedOrigins?.some((url) => compareUrls(url, event.origin)) ||\n allowedOrigins?.includes('*')\n ) {\n // Update the local state with the received data\n onEventTriggered(data);\n }\n };\n\n window.addEventListener('message', handleMessage);\n\n // Clean up the event listener on unmount\n return () => window.removeEventListener('message', handleMessage);\n }\n }, [allowedOrigins, postMessage, senderId, revalidator]);\n\n /**\n * A wrapper function around the `postMessage` function to broadcast messages efficiently.\n *\n * - **Encapsulation:** Ensures the `postMessage` function is scoped to the provided key.\n * - **Ease of Use:** Simplifies broadcasting messages with consistent type and format.\n *\n * @param {S} data - The data payload to include in the message.\n * @returns {void}\n */\n const postMessageWrapper: (data?: S) => void = (data) => {\n postMessage({ type: key, data, senderId });\n };\n\n return postMessageWrapper;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,gCACX,KACA,kBACA,gBACG;CACH,MAAM,EAAE,gBAAgB,aAAa,aAAa,iBAAiB;AAEnE,iBAAgB;AACd,MAAI,kBAAkB;;;;;;;;;GASpB,MAAM,iBACJ,UACG;IACH,MAAM,EAAE,MAAM,MAAM,UAAU,gBAAgB,MAAM;AAGpD,QAAI,SAAS,IAAK;AAGlB,QAAI,gBAAgB,SAAU;AAG9B,QACE,OAAO,mBAAmB,eAC1B,
|
|
1
|
+
{"version":3,"file":"useCrossFrameMessageListener.mjs","names":["postMessageWrapper: (data?: S) => void"],"sources":["../../src/useCrossFrameMessageListener.tsx"],"sourcesContent":["'use client';\n\nimport { compareUrls, type MessageKey } from '@intlayer/editor';\nimport { useEffect } from 'react';\nimport { useCommunicator } from './CommunicatorContext';\n\n/**\n * useCrossFrameMessageListener\n *\n * This React hook listens for messages sent via the `postMessage` API and triggers a callback\n * whenever a message of the specified type (`key`) is received. It is useful for synchronizing\n * state or events across different windows, iframes, or contexts.\n *\n * @template S - The type of the data payload in the message.\n * @param key - A unique identifier for the message type to listen for.\n * @param [onEventTriggered] - A callback function triggered when a message\n * @param [revalidator] - A function that re-suscribes the listener. Could be usefull if onEventTriggered depend of some state\n * with the specified key is received. The callback receives the message data as its argument.\n *\n * @returns {{ postMessage: (data: S) => void }} An object containing a `postMessage` function\n * that allows broadcasting messages with the specified key and data.\n */\nexport const useCrossFrameMessageListener = <S,>(\n key: `${MessageKey}` | `${MessageKey}/post` | `${MessageKey}/get`,\n onEventTriggered?: (data: S) => void,\n revalidator?: any\n) => {\n const { allowedOrigins, postMessage, senderId } = useCommunicator();\n\n useEffect(() => {\n if (onEventTriggered) {\n /**\n * Message handler to process incoming messages.\n *\n * - **Message Filtering:** Ensures only messages with the specified `key` are processed.\n * - **Origin Validation:** Checks that the origin of the message is within the allowed origins.\n *\n * @param {MessageEvent<{ type: string; data: S }>} event - The incoming message event object.\n */\n const handleMessage = (\n event: MessageEvent<{ type: string; data: S; senderId: string }>\n ) => {\n const { type, data, senderId: msgSenderId } = event.data;\n\n // Ignore messages that do not match the current key\n if (type !== key) return;\n\n // Ignore messages from myself\n if (msgSenderId === senderId) return;\n\n // Check if the message origin is allowed\n if (\n typeof allowedOrigins === 'undefined' ||\n allowedOrigins\n ?.filter((url) => ![null, undefined, '', '*'].includes(url))\n .some((url) => compareUrls(url, event.origin)) ||\n allowedOrigins?.includes('*')\n ) {\n // Update the local state with the received data\n onEventTriggered(data);\n }\n };\n\n window.addEventListener('message', handleMessage);\n\n // Clean up the event listener on unmount\n return () => window.removeEventListener('message', handleMessage);\n }\n }, [allowedOrigins, postMessage, senderId, revalidator]);\n\n /**\n * A wrapper function around the `postMessage` function to broadcast messages efficiently.\n *\n * - **Encapsulation:** Ensures the `postMessage` function is scoped to the provided key.\n * - **Ease of Use:** Simplifies broadcasting messages with consistent type and format.\n *\n * @param {S} data - The data payload to include in the message.\n * @returns {void}\n */\n const postMessageWrapper: (data?: S) => void = (data) => {\n postMessage({ type: key, data, senderId });\n };\n\n return postMessageWrapper;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,gCACX,KACA,kBACA,gBACG;CACH,MAAM,EAAE,gBAAgB,aAAa,aAAa,iBAAiB;AAEnE,iBAAgB;AACd,MAAI,kBAAkB;;;;;;;;;GASpB,MAAM,iBACJ,UACG;IACH,MAAM,EAAE,MAAM,MAAM,UAAU,gBAAgB,MAAM;AAGpD,QAAI,SAAS,IAAK;AAGlB,QAAI,gBAAgB,SAAU;AAG9B,QACE,OAAO,mBAAmB,eAC1B,gBACI,QAAQ,QAAQ,CAAC;KAAC;KAAM;KAAW;KAAI;KAAI,CAAC,SAAS,IAAI,CAAC,CAC3D,MAAM,QAAQ,YAAY,KAAK,MAAM,OAAO,CAAC,IAChD,gBAAgB,SAAS,IAAI,CAG7B,kBAAiB,KAAK;;AAI1B,UAAO,iBAAiB,WAAW,cAAc;AAGjD,gBAAa,OAAO,oBAAoB,WAAW,cAAc;;IAElE;EAAC;EAAgB;EAAa;EAAU;EAAY,CAAC;;;;;;;;;;CAWxD,MAAMA,sBAA0C,SAAS;AACvD,cAAY;GAAE,MAAM;GAAK;GAAM;GAAU,CAAC;;AAG5C,QAAO"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useCrossFrameState } from "./useCrossFrameState.mjs";
|
|
2
|
+
import { MessageKey } from "@intlayer/editor";
|
|
3
|
+
|
|
4
|
+
//#region src/useEditorLocale.tsx
|
|
5
|
+
const useEditorLocale = () => {
|
|
6
|
+
const [currentLocale] = useCrossFrameState(MessageKey.INTLAYER_CURRENT_LOCALE, void 0, {
|
|
7
|
+
receive: true,
|
|
8
|
+
emit: false
|
|
9
|
+
});
|
|
10
|
+
return currentLocale;
|
|
11
|
+
};
|
|
12
|
+
const useSetEditorLocale = () => {
|
|
13
|
+
return useCrossFrameState(MessageKey.INTLAYER_CURRENT_LOCALE, void 0, {
|
|
14
|
+
receive: true,
|
|
15
|
+
emit: false
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { useEditorLocale, useSetEditorLocale };
|
|
21
|
+
//# sourceMappingURL=useEditorLocale.mjs.map
|
|
@@ -0,0 +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":";;;;AAIA,MAAa,wBAAwB;CACnC,MAAM,CAAC,iBAAiB,mBACtB,WAAW,yBACX,QACA;EACE,SAAS;EACT,MAAM;EACP,CACF;AAED,QAAO;;AAGT,MAAa,2BAA2B;AAUtC,QATyB,mBACvB,WAAW,yBACX,QACA;EACE,SAAS;EACT,MAAM;EACP,CACF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { useDictionariesRecord } from "./DictionariesRecordContext.mjs";
|
|
5
|
+
import { useEditorLocale } from "./useEditorLocale.mjs";
|
|
6
|
+
import { useFocusDictionary } from "./FocusDictionaryContext.mjs";
|
|
7
|
+
import { useMemo } from "react";
|
|
8
|
+
import { getContentNodeByKeyPath } from "@intlayer/core";
|
|
9
|
+
|
|
10
|
+
//#region src/useFocusUnmergedDictionary.tsx
|
|
11
|
+
/**
|
|
12
|
+
* Converts merged keypath format to unmerged format.
|
|
13
|
+
* Merged: [{type: "translation", key: "fr"}, {type: "object", key: "title"}]
|
|
14
|
+
* Unmerged: [{type: "object", key: "title"}, {type: "translation", key: "fr"}]
|
|
15
|
+
*/
|
|
16
|
+
const mergedKeyPathToUnmergedKeyPath = (keyPath, dictionaries, locale) => {
|
|
17
|
+
console.log("test2", {
|
|
18
|
+
keyPath,
|
|
19
|
+
dictionaries,
|
|
20
|
+
locale
|
|
21
|
+
});
|
|
22
|
+
for (const dictionary of dictionaries) {
|
|
23
|
+
console.log("test2", { dictionary });
|
|
24
|
+
try {
|
|
25
|
+
const result = getContentNodeByKeyPath(dictionary.content, keyPath ?? [], locale);
|
|
26
|
+
console.log("test2", { result });
|
|
27
|
+
if (result) return {
|
|
28
|
+
keyPath,
|
|
29
|
+
dictionaryLocalId: dictionary.localId
|
|
30
|
+
};
|
|
31
|
+
} catch {}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const useFocusUnmergedDictionary = () => {
|
|
35
|
+
const { localeDictionaries } = useDictionariesRecord();
|
|
36
|
+
const currentLocale = useEditorLocale();
|
|
37
|
+
const { setFocusedContent, setFocusedContentKeyPath, focusedContent: mergedFocusedContent } = useFocusDictionary();
|
|
38
|
+
return {
|
|
39
|
+
focusedContent: useMemo(() => {
|
|
40
|
+
if (!mergedFocusedContent) return mergedFocusedContent;
|
|
41
|
+
if (!localeDictionaries) return mergedFocusedContent;
|
|
42
|
+
if (mergedFocusedContent.dictionaryLocalId) return mergedFocusedContent;
|
|
43
|
+
const dictionaries = Object.values(localeDictionaries).filter((dictionary) => dictionary.key === mergedFocusedContent.dictionaryKey);
|
|
44
|
+
const unmergedKeyPath = mergedKeyPathToUnmergedKeyPath(mergedFocusedContent.keyPath ?? [], dictionaries, currentLocale);
|
|
45
|
+
return {
|
|
46
|
+
...mergedFocusedContent,
|
|
47
|
+
...unmergedKeyPath
|
|
48
|
+
};
|
|
49
|
+
}, [
|
|
50
|
+
mergedFocusedContent,
|
|
51
|
+
localeDictionaries,
|
|
52
|
+
currentLocale
|
|
53
|
+
]),
|
|
54
|
+
setFocusedContent,
|
|
55
|
+
setFocusedContentKeyPath
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
export { useFocusUnmergedDictionary };
|
|
61
|
+
//# sourceMappingURL=useFocusUnmergedDictionary.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFocusUnmergedDictionary.mjs","names":[],"sources":["../../src/useFocusUnmergedDictionary.tsx"],"sourcesContent":["'use client';\n\nimport { getContentNodeByKeyPath } from '@intlayer/core';\nimport type {\n Dictionary,\n KeyPath,\n LocalDictionaryId,\n Locale,\n} from '@intlayer/types';\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 console.log('test2', { keyPath, dictionaries, locale });\n\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 console.log('test2', { dictionary });\n try {\n const result = getContentNodeByKeyPath(\n dictionary.content,\n keyPath ?? [],\n locale\n );\n\n console.log('test2', { result });\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":";;;;;;;;;;;;;;;AAwBA,MAAM,kCACJ,SACA,cACA,WACgC;AAChC,SAAQ,IAAI,SAAS;EAAE;EAAS;EAAc;EAAQ,CAAC;AAKvD,MAAK,MAAM,cAAc,cAAc;AACrC,UAAQ,IAAI,SAAS,EAAE,YAAY,CAAC;AACpC,MAAI;GACF,MAAM,SAAS,wBACb,WAAW,SACX,WAAW,EAAE,EACb,OACD;AAED,WAAQ,IAAI,SAAS,EAAE,QAAQ,CAAC;AAEhC,OAAI,OACF,QAAO;IAAE;IAAS,mBAAmB,WAAW;IAAS;UAErD;;;AAMZ,MAAa,mCAAmC;CAC9C,MAAM,EAAE,uBAAuB,uBAAuB;CACtD,MAAM,gBAAgB,iBAAiB;CACvC,MAAM,EACJ,mBACA,0BACA,gBAAgB,yBACd,oBAAoB;AAuBxB,QAAO;EACL,gBAtBqB,cAAkC;AACvD,OAAI,CAAC,qBAAsB,QAAO;AAClC,OAAI,CAAC,mBAAoB,QAAO;AAChC,OAAI,qBAAqB,kBAAmB,QAAO;GAEnD,MAAM,eAAe,OAAO,OAAO,mBAAmB,CAAC,QACpD,eAAe,WAAW,QAAQ,qBAAqB,cACzD;GAED,MAAM,kBAAkB,+BACtB,qBAAqB,WAAW,EAAE,EAClC,cACA,cACD;AAED,UAAO;IACL,GAAG;IACH,GAAG;IACJ;KACA;GAAC;GAAsB;GAAoB;GAAc,CAAC;EAI3D;EACA;EACD"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react0 from "react";
|
|
2
2
|
import { FC, PropsWithChildren } from "react";
|
|
3
3
|
import { IntlayerConfig } from "@intlayer/types";
|
|
4
4
|
|
|
5
5
|
//#region src/ConfigurationContext.d.ts
|
|
6
|
-
declare const useConfigurationState: () => [IntlayerConfig,
|
|
6
|
+
declare const useConfigurationState: () => [IntlayerConfig, react0.Dispatch<react0.SetStateAction<IntlayerConfig>>, () => void];
|
|
7
7
|
type ConfigurationProviderProps = {
|
|
8
8
|
configuration?: IntlayerConfig;
|
|
9
9
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditedContentContext.d.ts","names":[],"sources":["../../src/EditedContentContext.tsx"],"sourcesContent":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"EditedContentContext.d.ts","names":[],"sources":["../../src/EditedContentContext.tsx"],"sourcesContent":[],"mappings":";;;;;cAuCa,yDACe,uBAAU;cAOzB,wDACe,uBAAU;AATtC,KAgBK,+BAAA,GAVF;EAEU,qBAAA,EAAA,CAAA,aAMV,EAGsC,iBARH,EAAA,GAAA,IAAA;EAOjC,mBAAA,EAEkB,QAFlB,CAE2B,cAFI,CAEW,UAFX,CAAA,CAAA;EACK,gBAAA,EAAA,CAAA,iBAAA,EAGlB,iBAHkB,EAAA,QAAA,EAI3B,UAJ2B,CAAA,SAAA,CAAA,EAAA,GAAA,IAAA;EACM,gBAAA,EAAA,CAAA,iBAAA,EAMxB,iBANwB,EAAA,QAAA,EAOjC,WAPiC,CAAA,GAAA,CAAA,EAAA,OAAA,CAAA,EAQjC,OARiC,EAAA,EAAA,SAAA,CAAA,EAAA,OAAA,EAAA,GAAA,IAAA;EAAf,mBAAA,EAAA,CAAA,iBAAA,EAYT,iBAZS,EAAA,MAAA,EAapB,OAboB,CAAA,KAAA,CAAA,EAAA,OAAA,CAAA,EAclB,OAdkB,EAAA,EAAA,GAAA,IAAA;EAAT,mBAAA,EAAA,CAAA,iBAAA,EAiBA,iBAjBA,EAAA,OAAA,EAkBV,OAlBU,EAAA,EAAA,GAAA,IAAA;EAEA,oBAAA,EAAA,CAAA,iBAAA,EAkBqB,iBAlBrB,EAAA,GAAA,IAAA;EACT,4BAAA,EAAA,CAAA,iBAAA,EAkBsC,iBAlBtC,EAAA,GAAA,IAAA;EAGS,kBAAA,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AcU,GAdU,UAcV,CAAA,KAAA,CAAA,GAAA,MAAA,EAAA,OAAA,EAbzB,OAayB,EAAA,EAAA,GAZ/B,WAY+B,GAAA,SAAA;EAoQzB,aAAA,EAnUI,MAmUJ,CAnUW,iBAmUY,EAnUO,UAmUP,CAAA,GAAA,SAAA;AAGpC,CAAA"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { CrossFrameStateOptions } from "./useCrossFrameState.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as react1 from "react";
|
|
3
3
|
import { FC, PropsWithChildren } from "react";
|
|
4
4
|
|
|
5
5
|
//#region src/EditorEnabledContext.d.ts
|
|
6
6
|
type EditorEnabledStateProps = {
|
|
7
7
|
enabled: boolean;
|
|
8
8
|
};
|
|
9
|
-
declare const useEditorEnabledState: (options?: CrossFrameStateOptions) => [boolean,
|
|
9
|
+
declare const useEditorEnabledState: (options?: CrossFrameStateOptions) => [boolean, react1.Dispatch<react1.SetStateAction<boolean>>, () => void];
|
|
10
10
|
declare const usePostEditorEnabledState: <S>(onEventTriggered?: (data: S) => void) => (data?: S) => void;
|
|
11
11
|
declare const useGetEditorEnabledState: <S>(onEventTriggered?: (data: S) => void) => (data?: S) => void;
|
|
12
12
|
declare const EditorEnabledProvider: FC<PropsWithChildren>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Dispatch, FC, PropsWithChildren, SetStateAction } from "react";
|
|
2
|
+
import { KeyPath } from "@intlayer/types";
|
|
3
|
+
|
|
4
|
+
//#region src/FocusDictionaryContext copy.d.ts
|
|
5
|
+
type FileContent = {
|
|
6
|
+
dictionaryKey: string;
|
|
7
|
+
dictionaryLocalId?: string;
|
|
8
|
+
keyPath?: KeyPath[];
|
|
9
|
+
};
|
|
10
|
+
type FocusDictionaryActions = {
|
|
11
|
+
setFocusedContent: Dispatch<SetStateAction<FileContent | null>>;
|
|
12
|
+
setFocusedContentKeyPath: (keyPath: KeyPath[]) => void;
|
|
13
|
+
};
|
|
14
|
+
declare const FocusDictionaryProvider: FC<PropsWithChildren>;
|
|
15
|
+
declare const useFocusDictionaryActions: () => FocusDictionaryActions;
|
|
16
|
+
declare const useFocusDictionary: () => {
|
|
17
|
+
setFocusedContent: Dispatch<SetStateAction<FileContent | null>>;
|
|
18
|
+
setFocusedContentKeyPath: (keyPath: KeyPath[]) => void;
|
|
19
|
+
focusedContent: FileContent | null;
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
22
|
+
export { FileContent, FocusDictionaryProvider, useFocusDictionary, useFocusDictionaryActions };
|
|
23
|
+
//# sourceMappingURL=FocusDictionaryContext copy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FocusDictionaryContext copy.d.ts","names":[],"sources":["../../src/FocusDictionaryContext copy.tsx"],"sourcesContent":[],"mappings":";;;;KAcY,WAAA;;EAAA,iBAAW,CAAA,EAAA,MAGX;EAOP,OAAA,CAAA,EAPO,OAOP,EAAA;CACwC;KADxC,sBAAA,GACyB;EAAT,iBAAA,EAAA,QAAA,CAAS,cAAT,CAAwB,WAAxB,GAAA,IAAA,CAAA,CAAA;EACiB,wBAAA,EAAA,CAAA,OAAA,EAAA,OAAA,EAAA,EAAA,GAAA,IAAA;CAAO;AAUhC,cAAA,uBAA4B,EAAH,EAAG,CAAA,iBAAD,CAAA;AA6B3B,cAAA,yBAAyB,EAAA,GAAA,GAAA,sBAQrC;AAEY,cAAA,kBAWZ,EAAA,GAAA,GAAA;EA7D4C,iBAAA,EAAxB,QAAwB,CAAf,cAAe,CAAA,WAAA,GAAA,IAAA,CAAA,CAAA;EAAf,wBAAA,EAAA,CAAA,OAAA,EACQ,OADR,EAAA,EAAA,GAAA,IAAA;EAAT,cAAA,EAJH,WAIG,GAAA,IAAA;CACiB"}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { Dispatch, FC, PropsWithChildren, SetStateAction } from "react";
|
|
2
|
-
import { KeyPath } from "@intlayer/types";
|
|
2
|
+
import { KeyPath, LocalDictionaryId } from "@intlayer/types";
|
|
3
3
|
|
|
4
4
|
//#region src/FocusDictionaryContext.d.ts
|
|
5
5
|
type FileContent = {
|
|
6
6
|
dictionaryKey: string;
|
|
7
|
-
dictionaryLocalId?:
|
|
7
|
+
dictionaryLocalId?: LocalDictionaryId;
|
|
8
8
|
keyPath?: KeyPath[];
|
|
9
9
|
};
|
|
10
|
+
type FocusDictionaryState = {
|
|
11
|
+
focusedContent: FileContent | null;
|
|
12
|
+
};
|
|
10
13
|
type FocusDictionaryActions = {
|
|
11
14
|
setFocusedContent: Dispatch<SetStateAction<FileContent | null>>;
|
|
12
15
|
setFocusedContentKeyPath: (keyPath: KeyPath[]) => void;
|
|
@@ -19,5 +22,5 @@ declare const useFocusDictionary: () => {
|
|
|
19
22
|
focusedContent: FileContent | null;
|
|
20
23
|
};
|
|
21
24
|
//#endregion
|
|
22
|
-
export { FileContent, FocusDictionaryProvider, useFocusDictionary, useFocusDictionaryActions };
|
|
25
|
+
export { FileContent, FocusDictionaryActions, FocusDictionaryProvider, FocusDictionaryState, useFocusDictionary, useFocusDictionaryActions };
|
|
23
26
|
//# sourceMappingURL=FocusDictionaryContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FocusDictionaryContext.d.ts","names":[],"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"FocusDictionaryContext.d.ts","names":[],"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":[],"mappings":";;;;KAkBY,WAAA;;EAAA,iBAAW,CAAA,EAED,iBAAA;EAIV,OAAA,CAAA,EAHA,OAGA,EAAA;AAIZ,CAAA;AAC6C,KALjC,oBAAA,GAKiC;EAAf,cAAA,EAJZ,WAIY,GAAA,IAAA;CAAT;AACiB,KAF1B,sBAAA,GAE0B;EAAO,iBAAA,EADxB,QACwB,CADf,cACe,CADA,WACA,GAAA,IAAA,CAAA,CAAA;EAUhC,wBAAA,EAoCZ,CAAA,OAAA,EA9CqC,OAUG,EAAA,EAAA,GAAA,IAAA;AAsCzC,CAAA;AAUa,cAhDA,uBA2DZ,EA3DqC,EA2DrC,CA3DwC,iBA2DxC,CAAA;AAtE4C,cAiDhC,yBAjDgC,EAAA,GAAA,GAiDP,sBAjDO;AAAf,cA2DjB,kBA3DiB,EAAA,GAAA,GAAA;EAAT,iBAAA,EAAA,QAAA,CAAS,cAAT,CAAwB,WAAxB,GAAA,IAAA,CAAA,CAAA;EACiB,wBAAA,EAAA,CAAA,OAAA,EAAA,OAAA,EAAA,EAAA,GAAA,IAAA;EALpB,cAAA,EAAA,WAAA,GAAA,IAAA;CAAW"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { KeyPath } from "@intlayer/types";
|
|
2
|
+
|
|
3
|
+
//#region src/FocusDictionaryServerContext.d.ts
|
|
4
|
+
declare const useFocusUnmergedDictionary: () => {
|
|
5
|
+
focusedContent: KeyPath[];
|
|
6
|
+
};
|
|
7
|
+
//#endregion
|
|
8
|
+
export { useFocusUnmergedDictionary };
|
|
9
|
+
//# sourceMappingURL=FocusDictionaryServerContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FocusDictionaryServerContext.d.ts","names":[],"sources":["../../src/FocusDictionaryServerContext.tsx"],"sourcesContent":[],"mappings":";;;cAgDa;kBAYZ;AAZD,CAAA"}
|