@intlayer/editor-react 5.8.1 → 6.0.0-canary.1
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/DictionariesRecordContext.cjs +2 -1
- package/dist/cjs/DictionariesRecordContext.cjs.map +1 -1
- package/dist/cjs/EditedContentContext.cjs +39 -25
- package/dist/cjs/EditedContentContext.cjs.map +1 -1
- package/dist/cjs/FocusDictionaryContext.cjs.map +1 -1
- package/dist/esm/DictionariesRecordContext.mjs +2 -1
- package/dist/esm/DictionariesRecordContext.mjs.map +1 -1
- package/dist/esm/EditedContentContext.mjs +39 -25
- package/dist/esm/EditedContentContext.mjs.map +1 -1
- package/dist/esm/FocusDictionaryContext.mjs.map +1 -1
- package/dist/types/DictionariesRecordContext.d.ts +2 -2
- package/dist/types/DictionariesRecordContext.d.ts.map +1 -1
- package/dist/types/EditedContentContext.d.ts +19 -18
- package/dist/types/EditedContentContext.d.ts.map +1 -1
- package/dist/types/FocusDictionaryContext.d.ts +1 -2
- package/dist/types/FocusDictionaryContext.d.ts.map +1 -1
- package/package.json +10 -10
|
@@ -47,9 +47,10 @@ const DictionariesRecordProvider = ({
|
|
|
47
47
|
() => ({
|
|
48
48
|
setLocaleDictionaries,
|
|
49
49
|
setLocaleDictionary: (dictionary) => {
|
|
50
|
+
if (!dictionary.localId) return;
|
|
50
51
|
setLocaleDictionaries((dictionaries) => ({
|
|
51
52
|
...dictionaries,
|
|
52
|
-
[dictionary.
|
|
53
|
+
[dictionary.localId]: dictionary
|
|
53
54
|
}));
|
|
54
55
|
}
|
|
55
56
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport type { Dictionary } from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n useContext,\n useMemo,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport type DictionaryContent = Record<
|
|
1
|
+
{"version":3,"sources":["../../src/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport type { Dictionary, LocalDictionaryId } from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n useContext,\n useMemo,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n} from '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":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiEM;AA9DN,oBAA2B;AAC3B,mBAQO;AACP,gCAAmC;AAYnC,MAAM,sCAAkC,4BAEtC,MAAS;AACX,MAAM,uCAAmC,4BAEvC,MAAS;AAEJ,MAAM,6BAAoD,CAAC;AAAA,EAChE;AACF,MAAM;AACJ,QAAM,CAAC,oBAAoB,qBAAqB,QAC9C;AAAA,IACE,yBAAW;AAAA,IACX;AAAA,EACF;AAEF,QAAM,iBAAa;AAAA,IACjB,OAAO;AAAA,MACL,oBAAoB,sBAAsB,CAAC;AAAA,IAC7C;AAAA,IACA,CAAC,kBAAkB;AAAA,EACrB;AAEA,QAAM,kBAAc;AAAA,IAClB,OAAO;AAAA,MACL;AAAA,MACA,qBAAqB,CAAC,eAA2B;AAC/C,YAAI,CAAC,WAAW,QAAS;AAEzB,8BAAsB,CAAC,kBAAkB;AAAA,UACvC,GAAG;AAAA,UACH,CAAC,WAAW,OAA4B,GAAG;AAAA,QAC7C,EAAE;AAAA,MACJ;AAAA,IACF;AAAA,IACA,CAAC,qBAAqB;AAAA,EACxB;AAEA,SACE,4CAAC,gCAAgC,UAAhC,EAAyC,OAAO,YAC/C,sDAAC,iCAAiC,UAAjC,EAA0C,OAAO,aAC/C,UACH,GACF;AAEJ;AAEO,MAAM,+BAA+B,UAC1C,yBAAW,gCAAgC;AAEtC,MAAM,wBAAwB,MAAM;AACzC,QAAM,iBAAiB,6BAA6B;AACpD,QAAM,oBAAgB,yBAAW,+BAA+B;AAEhE,MAAI,CAAC,eAAe;AAClB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,eAAe,GAAG,eAAe;AAC/C;","names":[]}
|
|
@@ -63,20 +63,20 @@ const EditedContentProvider = ({ children }) => {
|
|
|
63
63
|
});
|
|
64
64
|
return updatedDictionaries;
|
|
65
65
|
};
|
|
66
|
-
const setEditedContent = (
|
|
66
|
+
const setEditedContent = (localDictionaryId, newValue) => {
|
|
67
67
|
setEditedContentState((prev) => ({
|
|
68
68
|
...prev,
|
|
69
|
-
[
|
|
70
|
-
...prev?.[
|
|
69
|
+
[localDictionaryId]: {
|
|
70
|
+
...prev?.[localDictionaryId],
|
|
71
71
|
content: newValue
|
|
72
72
|
}
|
|
73
73
|
}));
|
|
74
74
|
};
|
|
75
|
-
const addEditedContent = (
|
|
75
|
+
const addEditedContent = (localDictionaryId, newValue, keyPath = [], overwrite = true) => {
|
|
76
76
|
setEditedContentState((prev) => {
|
|
77
|
-
const originalContent = localeDictionaries[
|
|
77
|
+
const originalContent = localeDictionaries[localDictionaryId]?.content;
|
|
78
78
|
const currentContent = structuredClone(
|
|
79
|
-
prev?.[
|
|
79
|
+
prev?.[localDictionaryId]?.content ?? originalContent
|
|
80
80
|
);
|
|
81
81
|
let newKeyPath = keyPath;
|
|
82
82
|
if (!overwrite) {
|
|
@@ -100,18 +100,18 @@ const EditedContentProvider = ({ children }) => {
|
|
|
100
100
|
);
|
|
101
101
|
return {
|
|
102
102
|
...prev,
|
|
103
|
-
[
|
|
104
|
-
...prev?.[
|
|
103
|
+
[localDictionaryId]: {
|
|
104
|
+
...prev?.[localDictionaryId],
|
|
105
105
|
content: updatedContent
|
|
106
106
|
}
|
|
107
107
|
};
|
|
108
108
|
});
|
|
109
109
|
};
|
|
110
|
-
const renameEditedContent = (
|
|
110
|
+
const renameEditedContent = (localDictionaryId, newKey, keyPath = []) => {
|
|
111
111
|
setEditedContentState((prev) => {
|
|
112
|
-
const originalContent = localeDictionaries[
|
|
112
|
+
const originalContent = localeDictionaries[localDictionaryId]?.content;
|
|
113
113
|
const currentContent = structuredClone(
|
|
114
|
-
prev?.[
|
|
114
|
+
prev?.[localDictionaryId]?.content ?? originalContent
|
|
115
115
|
);
|
|
116
116
|
const contentWithNewField = (0, import_core.renameContentNodeByKeyPath)(
|
|
117
117
|
currentContent,
|
|
@@ -120,18 +120,18 @@ const EditedContentProvider = ({ children }) => {
|
|
|
120
120
|
);
|
|
121
121
|
return {
|
|
122
122
|
...prev,
|
|
123
|
-
[
|
|
124
|
-
...prev?.[
|
|
123
|
+
[localDictionaryId]: {
|
|
124
|
+
...prev?.[localDictionaryId],
|
|
125
125
|
content: contentWithNewField
|
|
126
126
|
}
|
|
127
127
|
};
|
|
128
128
|
});
|
|
129
129
|
};
|
|
130
|
-
const removeEditedContent = (
|
|
130
|
+
const removeEditedContent = (localDictionaryId, keyPath) => {
|
|
131
131
|
setEditedContentState((prev) => {
|
|
132
|
-
const originalContent = localeDictionaries[
|
|
132
|
+
const originalContent = localeDictionaries[localDictionaryId]?.content;
|
|
133
133
|
const currentContent = structuredClone(
|
|
134
|
-
prev?.[
|
|
134
|
+
prev?.[localDictionaryId]?.content ?? originalContent
|
|
135
135
|
);
|
|
136
136
|
const initialContent = (0, import_core.getContentNodeByKeyPath)(originalContent, keyPath);
|
|
137
137
|
const restoredContent = (0, import_core.editDictionaryByKeyPath)(
|
|
@@ -141,24 +141,24 @@ const EditedContentProvider = ({ children }) => {
|
|
|
141
141
|
);
|
|
142
142
|
return {
|
|
143
143
|
...prev,
|
|
144
|
-
[
|
|
145
|
-
...prev?.[
|
|
144
|
+
[localDictionaryId]: {
|
|
145
|
+
...prev?.[localDictionaryId],
|
|
146
146
|
content: restoredContent
|
|
147
147
|
}
|
|
148
148
|
};
|
|
149
149
|
});
|
|
150
150
|
};
|
|
151
|
-
const restoreEditedContent = (
|
|
151
|
+
const restoreEditedContent = (localDictionaryId) => {
|
|
152
152
|
setEditedContentState((prev) => {
|
|
153
153
|
const updated = { ...prev };
|
|
154
|
-
delete updated[
|
|
154
|
+
delete updated[localDictionaryId];
|
|
155
155
|
return updated;
|
|
156
156
|
});
|
|
157
157
|
};
|
|
158
|
-
const clearEditedDictionaryContent = (
|
|
158
|
+
const clearEditedDictionaryContent = (localDictionaryId) => {
|
|
159
159
|
setEditedContentState((prev) => {
|
|
160
160
|
const filtered = Object.entries(prev).reduce((acc, [key, value]) => {
|
|
161
|
-
if (key ===
|
|
161
|
+
if (key === localDictionaryId) {
|
|
162
162
|
return acc;
|
|
163
163
|
}
|
|
164
164
|
return { ...acc, [key]: value };
|
|
@@ -169,9 +169,23 @@ const EditedContentProvider = ({ children }) => {
|
|
|
169
169
|
const clearEditedContent = () => {
|
|
170
170
|
setEditedContentState({});
|
|
171
171
|
};
|
|
172
|
-
const getEditedContentValue = (
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
const getEditedContentValue = (localDictionaryIdOrKey, keyPath) => {
|
|
173
|
+
if (!editedContent) return void 0;
|
|
174
|
+
const isDictionaryId = localDictionaryIdOrKey.includes(":local:") || localDictionaryIdOrKey.includes(":remote:");
|
|
175
|
+
if (isDictionaryId) {
|
|
176
|
+
const currentContent = editedContent?.[localDictionaryIdOrKey]?.content ?? {};
|
|
177
|
+
const contentNode = (0, import_core.getContentNodeByKeyPath)(currentContent, keyPath);
|
|
178
|
+
return contentNode;
|
|
179
|
+
}
|
|
180
|
+
const filteredDictionariesLocalId = Object.keys(editedContent).filter(
|
|
181
|
+
(key) => key.startsWith(`${localDictionaryIdOrKey}:`)
|
|
182
|
+
);
|
|
183
|
+
for (const localDictionaryId of filteredDictionariesLocalId) {
|
|
184
|
+
const currentContent = editedContent?.[localDictionaryId]?.content ?? {};
|
|
185
|
+
const contentNode = (0, import_core.getContentNodeByKeyPath)(currentContent, keyPath);
|
|
186
|
+
if (contentNode) return contentNode;
|
|
187
|
+
}
|
|
188
|
+
return void 0;
|
|
175
189
|
};
|
|
176
190
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
177
191
|
EditedContentStateContext.Provider,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n editDictionaryByKeyPath,\n getContentNodeByKeyPath,\n renameContentNodeByKeyPath,\n type ContentNode,\n type Dictionary,\n type KeyPath,\n} from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n useContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n} from 'react';\nimport {\n useDictionariesRecord,\n type DictionaryContent,\n} from './DictionariesRecordContext';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\nimport { useCrossFrameState } from './useCrossFrameState';\n\ntype EditedContentStateContextType = {\n editedContent: Record<Dictionary['key'], Dictionary> | undefined;\n};\n\nconst EditedContentStateContext = createContext<\n EditedContentStateContextType | undefined\n>(undefined);\n\nexport const usePostEditedContentState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/post`,\n onEventTriggered\n );\n\nexport const useGetEditedContentState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/get`,\n onEventTriggered\n );\n\ntype EditedContentActionsContextType = {\n setEditedContentState: (\n editedContent: Record<Dictionary['key'], Dictionary>\n ) => void;\n setEditedDictionary: Dispatch<SetStateAction<Dictionary>>;\n setEditedContent: (\n dictionaryKey: Dictionary['key'],\n newValue: Dictionary['content']\n ) => void;\n addEditedContent: (\n dictionaryKey: Dictionary['key'],\n newValue: ContentNode<any>,\n keyPath?: KeyPath[],\n overwrite?: boolean\n ) => void;\n renameEditedContent: (\n dictionaryKey: Dictionary['key'],\n newKey: KeyPath['key'],\n keyPath?: KeyPath[]\n ) => void;\n removeEditedContent: (\n dictionaryKey: Dictionary['key'],\n keyPath: KeyPath[]\n ) => void;\n restoreEditedContent: (dictionaryKey: Dictionary['key']) => void;\n clearEditedDictionaryContent: (dictionaryKey: Dictionary['key']) => void;\n clearEditedContent: () => void;\n getEditedContentValue: (\n dictionaryKey: Dictionary['key'],\n keyPath: KeyPath[]\n ) => ContentNode | undefined;\n};\n\nconst EditedContentActionsContext = createContext<\n EditedContentActionsContextType | undefined\n>(undefined);\n\nconst resolveState = <S,>(state?: SetStateAction<S>, prevState?: S): S =>\n typeof state === 'function'\n ? (state as (prevState?: S) => S)(prevState)\n : (state as S);\n\nexport const EditedContentProvider: FC<PropsWithChildren> = ({ children }) => {\n const { localeDictionaries } = useDictionariesRecord();\n\n const [editedContent, setEditedContentState] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_EDITED_CONTENT_CHANGED\n );\n\n const setEditedDictionary: Dispatch<SetStateAction<Dictionary>> = (\n newValue\n ) => {\n let updatedDictionaries: Dictionary = resolveState(newValue);\n\n setEditedContentState((prev) => {\n updatedDictionaries = resolveState(\n newValue,\n prev?.[updatedDictionaries.key]\n );\n\n return {\n ...prev,\n [updatedDictionaries.key]: updatedDictionaries,\n };\n });\n\n return updatedDictionaries;\n };\n\n const setEditedContent = (\n dictionaryKey: Dictionary['key'],\n newValue: Dictionary['content']\n ) => {\n setEditedContentState((prev) => ({\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: newValue,\n },\n }));\n };\n\n const addEditedContent = (\n dictionaryKey: Dictionary['key'],\n newValue: ContentNode,\n keyPath: KeyPath[] = [],\n overwrite: boolean = true\n ) => {\n setEditedContentState((prev) => {\n // Get the starting content: edited version if available, otherwise a deep copy of the original\n const originalContent = localeDictionaries[dictionaryKey]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryKey]?.content ?? originalContent\n );\n\n let newKeyPath = keyPath;\n if (!overwrite) {\n // Find a unique key based on the keyPath provided\n let index = 0;\n const otherKeyPath = keyPath.slice(0, -1);\n const lastKeyPath: KeyPath = keyPath[keyPath.length - 1];\n let finalKey = lastKeyPath.key;\n\n // Loop until we find a key that does not exist\n while (\n typeof getContentNodeByKeyPath(currentContent, newKeyPath) !==\n 'undefined'\n ) {\n index++;\n finalKey =\n index === 0 ? lastKeyPath.key : `${lastKeyPath.key} (${index})`;\n newKeyPath = [\n ...otherKeyPath,\n { ...lastKeyPath, key: finalKey } as KeyPath,\n ];\n }\n }\n\n const updatedContent = editDictionaryByKeyPath(\n currentContent,\n newKeyPath,\n newValue\n );\n\n return {\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: updatedContent as Dictionary['content'],\n },\n };\n });\n };\n\n const renameEditedContent = (\n dictionaryKey: Dictionary['key'],\n newKey: KeyPath['key'],\n keyPath: KeyPath[] = []\n ) => {\n setEditedContentState((prev) => {\n // Retrieve the base content: use edited version if available, otherwise deep copy of original\n const originalContent = localeDictionaries[dictionaryKey]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryKey]?.content ?? originalContent\n );\n\n const contentWithNewField = renameContentNodeByKeyPath(\n currentContent,\n newKey,\n keyPath\n );\n\n return {\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: contentWithNewField as Dictionary['content'],\n },\n };\n });\n };\n\n const removeEditedContent = (\n dictionaryKey: Dictionary['key'],\n keyPath: KeyPath[]\n ) => {\n setEditedContentState((prev) => {\n // Retrieve the original content as reference\n const originalContent = localeDictionaries[dictionaryKey]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryKey]?.content ?? originalContent\n );\n\n // Get the initial value from the original dictionary content\n const initialContent = getContentNodeByKeyPath(originalContent, keyPath);\n\n // Restore the value at the given keyPath\n const restoredContent = editDictionaryByKeyPath(\n currentContent,\n keyPath,\n initialContent\n );\n\n return {\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: restoredContent as Dictionary['content'],\n },\n };\n });\n };\n\n const restoreEditedContent = (dictionaryKey: Dictionary['key']) => {\n setEditedContentState((prev) => {\n const updated = { ...prev };\n delete updated[dictionaryKey];\n return updated;\n });\n };\n\n const clearEditedDictionaryContent = (dictionaryKey: Dictionary['key']) => {\n setEditedContentState((prev) => {\n const filtered = Object.entries(prev).reduce((acc, [key, value]) => {\n if (key === dictionaryKey) {\n return acc;\n }\n return { ...acc, [key]: value };\n }, {} as DictionaryContent);\n return filtered;\n });\n };\n\n const clearEditedContent = () => {\n setEditedContentState({});\n };\n\n const getEditedContentValue = (\n dictionaryKey: Dictionary['key'],\n keyPath: KeyPath[]\n ): ContentNode | undefined => {\n const currentContent = editedContent?.[dictionaryKey]?.content ?? {};\n return getContentNodeByKeyPath(currentContent, keyPath);\n };\n\n return (\n <EditedContentStateContext.Provider\n value={{\n editedContent,\n }}\n >\n <EditedContentActionsContext.Provider\n value={{\n setEditedContentState,\n setEditedDictionary,\n setEditedContent,\n addEditedContent,\n renameEditedContent,\n removeEditedContent,\n restoreEditedContent,\n clearEditedDictionaryContent,\n clearEditedContent,\n getEditedContentValue,\n }}\n >\n {children}\n </EditedContentActionsContext.Provider>\n </EditedContentStateContext.Provider>\n );\n};\n\nexport const useEditedContentActions = () =>\n useContext(EditedContentActionsContext);\n\nexport const useEditedContent = () => {\n const stateContext = useContext(EditedContentStateContext);\n const actionContext = useEditedContentActions();\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0RM;AAxRN,kBAOO;AACP,oBAA2B;AAC3B,mBAOO;AACP,uCAGO;AACP,0CAA6C;AAC7C,gCAAmC;AAMnC,MAAM,gCAA4B,4BAEhC,MAAS;AAEJ,MAAM,4BAA4B,CACvC,yBAEA;AAAA,EACE,GAAG,yBAAW,+BAA+B;AAAA,EAC7C;AACF;AAEK,MAAM,2BAA2B,CACtC,yBAEA;AAAA,EACE,GAAG,yBAAW,+BAA+B;AAAA,EAC7C;AACF;AAmCF,MAAM,kCAA8B,4BAElC,MAAS;AAEX,MAAM,eAAe,CAAK,OAA2B,cACnD,O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aAAa;AAC5B,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,QAAM,+BAA+B,CAAC,kBAAqC;AACzE,0BAAsB,CAAC,SAAS;AAC9B,YAAM,WAAW,OAAO,QAAQ,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM;AAClE,YAAI,QAAQ,eAAe;AACzB,iBAAO;AAAA,QACT;AACA,eAAO,EAAE,GAAG,KAAK,CAAC,GAAG,GAAG,MAAM;AAAA,MAChC,GAAG,CAAC,CAAsB;AAC1B,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,QAAM,qBAAqB,MAAM;AAC/B,0BAAsB,CAAC,CAAC;AAAA,EAC1B;AAEA,QAAM,wBAAwB,CAC5B,eACA,YAC4B;AAC5B,UAAM,iBAAiB,gBAAgB,aAAa,GAAG,WAAW,CAAC;AACnE,eAAO,qCAAwB,gBAAgB,OAAO;AAAA,EACxD;AAEA,SACE;AAAA,IAAC,0BAA0B;AAAA,IAA1B;AAAA,MACC,OAAO;AAAA,QACL;AAAA,MACF;AAAA,MAEA;AAAA,QAAC,4BAA4B;AAAA,QAA5B;AAAA,UACC,OAAO;AAAA,YACL;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,UAEC;AAAA;AAAA,MACH;AAAA;AAAA,EACF;AAEJ;AAEO,MAAM,0BAA0B,UACrC,yBAAW,2BAA2B;AAEjC,MAAM,mBAAmB,MAAM;AACpC,QAAM,mBAAe,yBAAW,yBAAyB;AACzD,QAAM,gBAAgB,wBAAwB;AAE9C,SAAO,EAAE,GAAG,cAAc,GAAG,cAAc;AAC7C;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n editDictionaryByKeyPath,\n getContentNodeByKeyPath,\n renameContentNodeByKeyPath,\n type ContentNode,\n type Dictionary,\n type KeyPath,\n type LocalDictionaryId,\n} from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n useContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n} from 'react';\nimport {\n useDictionariesRecord,\n type DictionaryContent,\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 dictionaryKey: string,\n keyPath: KeyPath[],\n localDictionaryId?: LocalDictionaryId\n ) => ContentNode | undefined;\n};\n\nconst EditedContentActionsContext = createContext<\n EditedContentActionsContextType | undefined\n>(undefined);\n\nconst resolveState = <S,>(state?: SetStateAction<S>, prevState?: S): S =>\n typeof state === 'function'\n ? (state as (prevState?: S) => S)(prevState)\n : (state as S);\n\nexport const EditedContentProvider: FC<PropsWithChildren> = ({ children }) => {\n const { localeDictionaries } = useDictionariesRecord();\n\n const [editedContent, setEditedContentState] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_EDITED_CONTENT_CHANGED\n );\n\n const setEditedDictionary: Dispatch<SetStateAction<Dictionary>> = (\n newValue\n ) => {\n let updatedDictionaries: Dictionary = resolveState(newValue);\n\n setEditedContentState((prev) => {\n updatedDictionaries = resolveState(\n newValue,\n prev?.[updatedDictionaries.key]\n );\n\n return {\n ...prev,\n [updatedDictionaries.key]: updatedDictionaries,\n };\n });\n\n return updatedDictionaries;\n };\n\n const setEditedContent = (\n 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 | 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]?.content ?? {};\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 = editedContent?.[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":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqTM;AAnTN,kBAQO;AACP,oBAA2B;AAC3B,mBAOO;AACP,uCAGO;AACP,0CAA6C;AAC7C,gCAAmC;AAMnC,MAAM,gCAA4B,4BAEhC,MAAS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,qCAAwB,gBAAgB,OAAO;AAEnE,UAAI,YAAa,QAAO;AAAA,IAC1B;AAEA,WAAO;AAAA,EACT;AAEA,SACE;AAAA,IAAC,0BAA0B;AAAA,IAA1B;AAAA,MACC,OAAO;AAAA,QACL;AAAA,MACF;AAAA,MAEA;AAAA,QAAC,4BAA4B;AAAA,QAA5B;AAAA,UACC,OAAO;AAAA,YACL;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,UAEC;AAAA;AAAA,MACH;AAAA;AAAA,EACF;AAEJ;AAEO,MAAM,0BAA0B,UACrC,yBAAW,2BAA2B;AAEjC,MAAM,mBAAmB,MAAM;AACpC,QAAM,mBAAe,yBAAW,yBAAyB;AACzD,QAAM,gBAAgB,wBAAwB;AAE9C,SAAO,EAAE,GAAG,cAAc,GAAG,cAAc;AAC7C;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport type { KeyPath } from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n useContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\
|
|
1
|
+
{"version":3,"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport type { KeyPath } from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n useContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n} from '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":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwDM;AArDN,oBAA2B;AAC3B,mBAOO;AACP,gCAAmC;AAiBnC,MAAM,kCAA8B,4BAElC,MAAS;AACX,MAAM,oCAAgC,4BAEpC,MAAS;AAEJ,MAAM,0BAAiD,CAAC;AAAA,EAC7D;AACF,MAAM;AACJ,QAAM,CAAC,gBAAgB,iBAAiB,QACtC;AAAA,IACE,yBAAW;AAAA,IACX;AAAA,EACF;AAEF,QAAM,2BAA2B,CAAC,YAAuB;AACvD,sBAAkB,CAAC,SAAS;AAC1B,UAAI,CAAC,MAAM;AACT,eAAO;AAAA,MACT;AACA,aAAO,EAAE,GAAG,MAAM,QAAQ;AAAA,IAC5B,CAAC;AAAA,EACH;AAEA,SACE,4CAAC,4BAA4B,UAA5B,EAAqC,OAAO,EAAE,eAAe,GAC5D;AAAA,IAAC,8BAA8B;AAAA,IAA9B;AAAA,MACC,OAAO,EAAE,mBAAmB,yBAAyB;AAAA,MAEpD;AAAA;AAAA,EACH,GACF;AAEJ;AAEO,MAAM,4BAA4B,MAAM;AAC7C,QAAM,cAAU,yBAAW,6BAA6B;AACxD,MAAI,YAAY,QAAW;AACzB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,qBAAqB,MAAM;AACtC,QAAM,gBAAgB,0BAA0B;AAChD,QAAM,mBAAe,yBAAW,2BAA2B;AAE3D,MAAI,iBAAiB,QAAW;AAC9B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,cAAc,GAAG,cAAc;AAC7C;","names":[]}
|
|
@@ -26,9 +26,10 @@ const DictionariesRecordProvider = ({
|
|
|
26
26
|
() => ({
|
|
27
27
|
setLocaleDictionaries,
|
|
28
28
|
setLocaleDictionary: (dictionary) => {
|
|
29
|
+
if (!dictionary.localId) return;
|
|
29
30
|
setLocaleDictionaries((dictionaries) => ({
|
|
30
31
|
...dictionaries,
|
|
31
|
-
[dictionary.
|
|
32
|
+
[dictionary.localId]: dictionary
|
|
32
33
|
}));
|
|
33
34
|
}
|
|
34
35
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport type { Dictionary } from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n useContext,\n useMemo,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport type DictionaryContent = Record<
|
|
1
|
+
{"version":3,"sources":["../../src/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport type { Dictionary, LocalDictionaryId } from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n useContext,\n useMemo,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n} from '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":";AAiEM;AA9DN,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AACP,SAAS,0BAA0B;AAYnC,MAAM,kCAAkC,cAEtC,MAAS;AACX,MAAM,mCAAmC,cAEvC,MAAS;AAEJ,MAAM,6BAAoD,CAAC;AAAA,EAChE;AACF,MAAM;AACJ,QAAM,CAAC,oBAAoB,qBAAqB,IAC9C;AAAA,IACE,WAAW;AAAA,IACX;AAAA,EACF;AAEF,QAAM,aAAa;AAAA,IACjB,OAAO;AAAA,MACL,oBAAoB,sBAAsB,CAAC;AAAA,IAC7C;AAAA,IACA,CAAC,kBAAkB;AAAA,EACrB;AAEA,QAAM,cAAc;AAAA,IAClB,OAAO;AAAA,MACL;AAAA,MACA,qBAAqB,CAAC,eAA2B;AAC/C,YAAI,CAAC,WAAW,QAAS;AAEzB,8BAAsB,CAAC,kBAAkB;AAAA,UACvC,GAAG;AAAA,UACH,CAAC,WAAW,OAA4B,GAAG;AAAA,QAC7C,EAAE;AAAA,MACJ;AAAA,IACF;AAAA,IACA,CAAC,qBAAqB;AAAA,EACxB;AAEA,SACE,oBAAC,gCAAgC,UAAhC,EAAyC,OAAO,YAC/C,8BAAC,iCAAiC,UAAjC,EAA0C,OAAO,aAC/C,UACH,GACF;AAEJ;AAEO,MAAM,+BAA+B,MAC1C,WAAW,gCAAgC;AAEtC,MAAM,wBAAwB,MAAM;AACzC,QAAM,iBAAiB,6BAA6B;AACpD,QAAM,gBAAgB,WAAW,+BAA+B;AAEhE,MAAI,CAAC,eAAe;AAClB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,eAAe,GAAG,eAAe;AAC/C;","names":[]}
|
|
@@ -45,20 +45,20 @@ const EditedContentProvider = ({ children }) => {
|
|
|
45
45
|
});
|
|
46
46
|
return updatedDictionaries;
|
|
47
47
|
};
|
|
48
|
-
const setEditedContent = (
|
|
48
|
+
const setEditedContent = (localDictionaryId, newValue) => {
|
|
49
49
|
setEditedContentState((prev) => ({
|
|
50
50
|
...prev,
|
|
51
|
-
[
|
|
52
|
-
...prev?.[
|
|
51
|
+
[localDictionaryId]: {
|
|
52
|
+
...prev?.[localDictionaryId],
|
|
53
53
|
content: newValue
|
|
54
54
|
}
|
|
55
55
|
}));
|
|
56
56
|
};
|
|
57
|
-
const addEditedContent = (
|
|
57
|
+
const addEditedContent = (localDictionaryId, newValue, keyPath = [], overwrite = true) => {
|
|
58
58
|
setEditedContentState((prev) => {
|
|
59
|
-
const originalContent = localeDictionaries[
|
|
59
|
+
const originalContent = localeDictionaries[localDictionaryId]?.content;
|
|
60
60
|
const currentContent = structuredClone(
|
|
61
|
-
prev?.[
|
|
61
|
+
prev?.[localDictionaryId]?.content ?? originalContent
|
|
62
62
|
);
|
|
63
63
|
let newKeyPath = keyPath;
|
|
64
64
|
if (!overwrite) {
|
|
@@ -82,18 +82,18 @@ const EditedContentProvider = ({ children }) => {
|
|
|
82
82
|
);
|
|
83
83
|
return {
|
|
84
84
|
...prev,
|
|
85
|
-
[
|
|
86
|
-
...prev?.[
|
|
85
|
+
[localDictionaryId]: {
|
|
86
|
+
...prev?.[localDictionaryId],
|
|
87
87
|
content: updatedContent
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
90
|
});
|
|
91
91
|
};
|
|
92
|
-
const renameEditedContent = (
|
|
92
|
+
const renameEditedContent = (localDictionaryId, newKey, keyPath = []) => {
|
|
93
93
|
setEditedContentState((prev) => {
|
|
94
|
-
const originalContent = localeDictionaries[
|
|
94
|
+
const originalContent = localeDictionaries[localDictionaryId]?.content;
|
|
95
95
|
const currentContent = structuredClone(
|
|
96
|
-
prev?.[
|
|
96
|
+
prev?.[localDictionaryId]?.content ?? originalContent
|
|
97
97
|
);
|
|
98
98
|
const contentWithNewField = renameContentNodeByKeyPath(
|
|
99
99
|
currentContent,
|
|
@@ -102,18 +102,18 @@ const EditedContentProvider = ({ children }) => {
|
|
|
102
102
|
);
|
|
103
103
|
return {
|
|
104
104
|
...prev,
|
|
105
|
-
[
|
|
106
|
-
...prev?.[
|
|
105
|
+
[localDictionaryId]: {
|
|
106
|
+
...prev?.[localDictionaryId],
|
|
107
107
|
content: contentWithNewField
|
|
108
108
|
}
|
|
109
109
|
};
|
|
110
110
|
});
|
|
111
111
|
};
|
|
112
|
-
const removeEditedContent = (
|
|
112
|
+
const removeEditedContent = (localDictionaryId, keyPath) => {
|
|
113
113
|
setEditedContentState((prev) => {
|
|
114
|
-
const originalContent = localeDictionaries[
|
|
114
|
+
const originalContent = localeDictionaries[localDictionaryId]?.content;
|
|
115
115
|
const currentContent = structuredClone(
|
|
116
|
-
prev?.[
|
|
116
|
+
prev?.[localDictionaryId]?.content ?? originalContent
|
|
117
117
|
);
|
|
118
118
|
const initialContent = getContentNodeByKeyPath(originalContent, keyPath);
|
|
119
119
|
const restoredContent = editDictionaryByKeyPath(
|
|
@@ -123,24 +123,24 @@ const EditedContentProvider = ({ children }) => {
|
|
|
123
123
|
);
|
|
124
124
|
return {
|
|
125
125
|
...prev,
|
|
126
|
-
[
|
|
127
|
-
...prev?.[
|
|
126
|
+
[localDictionaryId]: {
|
|
127
|
+
...prev?.[localDictionaryId],
|
|
128
128
|
content: restoredContent
|
|
129
129
|
}
|
|
130
130
|
};
|
|
131
131
|
});
|
|
132
132
|
};
|
|
133
|
-
const restoreEditedContent = (
|
|
133
|
+
const restoreEditedContent = (localDictionaryId) => {
|
|
134
134
|
setEditedContentState((prev) => {
|
|
135
135
|
const updated = { ...prev };
|
|
136
|
-
delete updated[
|
|
136
|
+
delete updated[localDictionaryId];
|
|
137
137
|
return updated;
|
|
138
138
|
});
|
|
139
139
|
};
|
|
140
|
-
const clearEditedDictionaryContent = (
|
|
140
|
+
const clearEditedDictionaryContent = (localDictionaryId) => {
|
|
141
141
|
setEditedContentState((prev) => {
|
|
142
142
|
const filtered = Object.entries(prev).reduce((acc, [key, value]) => {
|
|
143
|
-
if (key ===
|
|
143
|
+
if (key === localDictionaryId) {
|
|
144
144
|
return acc;
|
|
145
145
|
}
|
|
146
146
|
return { ...acc, [key]: value };
|
|
@@ -151,9 +151,23 @@ const EditedContentProvider = ({ children }) => {
|
|
|
151
151
|
const clearEditedContent = () => {
|
|
152
152
|
setEditedContentState({});
|
|
153
153
|
};
|
|
154
|
-
const getEditedContentValue = (
|
|
155
|
-
|
|
156
|
-
|
|
154
|
+
const getEditedContentValue = (localDictionaryIdOrKey, keyPath) => {
|
|
155
|
+
if (!editedContent) return void 0;
|
|
156
|
+
const isDictionaryId = localDictionaryIdOrKey.includes(":local:") || localDictionaryIdOrKey.includes(":remote:");
|
|
157
|
+
if (isDictionaryId) {
|
|
158
|
+
const currentContent = editedContent?.[localDictionaryIdOrKey]?.content ?? {};
|
|
159
|
+
const contentNode = getContentNodeByKeyPath(currentContent, keyPath);
|
|
160
|
+
return contentNode;
|
|
161
|
+
}
|
|
162
|
+
const filteredDictionariesLocalId = Object.keys(editedContent).filter(
|
|
163
|
+
(key) => key.startsWith(`${localDictionaryIdOrKey}:`)
|
|
164
|
+
);
|
|
165
|
+
for (const localDictionaryId of filteredDictionariesLocalId) {
|
|
166
|
+
const currentContent = editedContent?.[localDictionaryId]?.content ?? {};
|
|
167
|
+
const contentNode = getContentNodeByKeyPath(currentContent, keyPath);
|
|
168
|
+
if (contentNode) return contentNode;
|
|
169
|
+
}
|
|
170
|
+
return void 0;
|
|
157
171
|
};
|
|
158
172
|
return /* @__PURE__ */ jsx(
|
|
159
173
|
EditedContentStateContext.Provider,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n editDictionaryByKeyPath,\n getContentNodeByKeyPath,\n renameContentNodeByKeyPath,\n type ContentNode,\n type Dictionary,\n type KeyPath,\n} from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n useContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n} from 'react';\nimport {\n useDictionariesRecord,\n type DictionaryContent,\n} from './DictionariesRecordContext';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\nimport { useCrossFrameState } from './useCrossFrameState';\n\ntype EditedContentStateContextType = {\n editedContent: Record<Dictionary['key'], Dictionary> | undefined;\n};\n\nconst EditedContentStateContext = createContext<\n EditedContentStateContextType | undefined\n>(undefined);\n\nexport const usePostEditedContentState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/post`,\n onEventTriggered\n );\n\nexport const useGetEditedContentState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/get`,\n onEventTriggered\n );\n\ntype EditedContentActionsContextType = {\n setEditedContentState: (\n editedContent: Record<Dictionary['key'], Dictionary>\n ) => void;\n setEditedDictionary: Dispatch<SetStateAction<Dictionary>>;\n setEditedContent: (\n dictionaryKey: Dictionary['key'],\n newValue: Dictionary['content']\n ) => void;\n addEditedContent: (\n dictionaryKey: Dictionary['key'],\n newValue: ContentNode<any>,\n keyPath?: KeyPath[],\n overwrite?: boolean\n ) => void;\n renameEditedContent: (\n dictionaryKey: Dictionary['key'],\n newKey: KeyPath['key'],\n keyPath?: KeyPath[]\n ) => void;\n removeEditedContent: (\n dictionaryKey: Dictionary['key'],\n keyPath: KeyPath[]\n ) => void;\n restoreEditedContent: (dictionaryKey: Dictionary['key']) => void;\n clearEditedDictionaryContent: (dictionaryKey: Dictionary['key']) => void;\n clearEditedContent: () => void;\n getEditedContentValue: (\n dictionaryKey: Dictionary['key'],\n keyPath: KeyPath[]\n ) => ContentNode | undefined;\n};\n\nconst EditedContentActionsContext = createContext<\n EditedContentActionsContextType | undefined\n>(undefined);\n\nconst resolveState = <S,>(state?: SetStateAction<S>, prevState?: S): S =>\n typeof state === 'function'\n ? (state as (prevState?: S) => S)(prevState)\n : (state as S);\n\nexport const EditedContentProvider: FC<PropsWithChildren> = ({ children }) => {\n const { localeDictionaries } = useDictionariesRecord();\n\n const [editedContent, setEditedContentState] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_EDITED_CONTENT_CHANGED\n );\n\n const setEditedDictionary: Dispatch<SetStateAction<Dictionary>> = (\n newValue\n ) => {\n let updatedDictionaries: Dictionary = resolveState(newValue);\n\n setEditedContentState((prev) => {\n updatedDictionaries = resolveState(\n newValue,\n prev?.[updatedDictionaries.key]\n );\n\n return {\n ...prev,\n [updatedDictionaries.key]: updatedDictionaries,\n };\n });\n\n return updatedDictionaries;\n };\n\n const setEditedContent = (\n dictionaryKey: Dictionary['key'],\n newValue: Dictionary['content']\n ) => {\n setEditedContentState((prev) => ({\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: newValue,\n },\n }));\n };\n\n const addEditedContent = (\n dictionaryKey: Dictionary['key'],\n newValue: ContentNode,\n keyPath: KeyPath[] = [],\n overwrite: boolean = true\n ) => {\n setEditedContentState((prev) => {\n // Get the starting content: edited version if available, otherwise a deep copy of the original\n const originalContent = localeDictionaries[dictionaryKey]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryKey]?.content ?? originalContent\n );\n\n let newKeyPath = keyPath;\n if (!overwrite) {\n // Find a unique key based on the keyPath provided\n let index = 0;\n const otherKeyPath = keyPath.slice(0, -1);\n const lastKeyPath: KeyPath = keyPath[keyPath.length - 1];\n let finalKey = lastKeyPath.key;\n\n // Loop until we find a key that does not exist\n while (\n typeof getContentNodeByKeyPath(currentContent, newKeyPath) !==\n 'undefined'\n ) {\n index++;\n finalKey =\n index === 0 ? lastKeyPath.key : `${lastKeyPath.key} (${index})`;\n newKeyPath = [\n ...otherKeyPath,\n { ...lastKeyPath, key: finalKey } as KeyPath,\n ];\n }\n }\n\n const updatedContent = editDictionaryByKeyPath(\n currentContent,\n newKeyPath,\n newValue\n );\n\n return {\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: updatedContent as Dictionary['content'],\n },\n };\n });\n };\n\n const renameEditedContent = (\n dictionaryKey: Dictionary['key'],\n newKey: KeyPath['key'],\n keyPath: KeyPath[] = []\n ) => {\n setEditedContentState((prev) => {\n // Retrieve the base content: use edited version if available, otherwise deep copy of original\n const originalContent = localeDictionaries[dictionaryKey]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryKey]?.content ?? originalContent\n );\n\n const contentWithNewField = renameContentNodeByKeyPath(\n currentContent,\n newKey,\n keyPath\n );\n\n return {\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: contentWithNewField as Dictionary['content'],\n },\n };\n });\n };\n\n const removeEditedContent = (\n dictionaryKey: Dictionary['key'],\n keyPath: KeyPath[]\n ) => {\n setEditedContentState((prev) => {\n // Retrieve the original content as reference\n const originalContent = localeDictionaries[dictionaryKey]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryKey]?.content ?? originalContent\n );\n\n // Get the initial value from the original dictionary content\n const initialContent = getContentNodeByKeyPath(originalContent, keyPath);\n\n // Restore the value at the given keyPath\n const restoredContent = editDictionaryByKeyPath(\n currentContent,\n keyPath,\n initialContent\n );\n\n return {\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: restoredContent as Dictionary['content'],\n },\n };\n });\n };\n\n const restoreEditedContent = (dictionaryKey: Dictionary['key']) => {\n setEditedContentState((prev) => {\n const updated = { ...prev };\n delete updated[dictionaryKey];\n return updated;\n });\n };\n\n const clearEditedDictionaryContent = (dictionaryKey: Dictionary['key']) => {\n setEditedContentState((prev) => {\n const filtered = Object.entries(prev).reduce((acc, [key, value]) => {\n if (key === dictionaryKey) {\n return acc;\n }\n return { ...acc, [key]: value };\n }, {} as DictionaryContent);\n return filtered;\n });\n };\n\n const clearEditedContent = () => {\n setEditedContentState({});\n };\n\n const getEditedContentValue = (\n dictionaryKey: Dictionary['key'],\n keyPath: KeyPath[]\n ): ContentNode | undefined => {\n const currentContent = editedContent?.[dictionaryKey]?.content ?? {};\n return getContentNodeByKeyPath(currentContent, keyPath);\n };\n\n return (\n <EditedContentStateContext.Provider\n value={{\n editedContent,\n }}\n >\n <EditedContentActionsContext.Provider\n value={{\n setEditedContentState,\n setEditedDictionary,\n setEditedContent,\n addEditedContent,\n renameEditedContent,\n removeEditedContent,\n restoreEditedContent,\n clearEditedDictionaryContent,\n clearEditedContent,\n getEditedContentValue,\n }}\n >\n {children}\n </EditedContentActionsContext.Provider>\n </EditedContentStateContext.Provider>\n );\n};\n\nexport const useEditedContentActions = () =>\n useContext(EditedContentActionsContext);\n\nexport const useEditedContent = () => {\n const stateContext = useContext(EditedContentStateContext);\n const actionContext = useEditedContentActions();\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":";AA0RM;AAxRN;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,OAKK;AACP;AAAA,EACE;AAAA,OAEK;AACP,SAAS,oCAAoC;AAC7C,SAAS,0BAA0B;AAMnC,MAAM,4BAA4B,cAEhC,MAAS;AAEJ,MAAM,4BAA4B,CACvC,qBAEA;AAAA,EACE,GAAG,WAAW,+BAA+B;AAAA,EAC7C;AACF;AAEK,MAAM,2BAA2B,CACtC,qBAEA;AAAA,EACE,GAAG,WAAW,+BAA+B;AAAA,EAC7C;AACF;AAmCF,MAAM,8BAA8B,cAElC,MAAS;AAEX,MAAM,eAAe,CAAK,OAA2B,cACnD,OAAO,UAAU,aACZ,MAA+B,SA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T,CAAC;AAAA,EACH;AAEA,QAAM,+BAA+B,CAAC,kBAAqC;AACzE,0BAAsB,CAAC,SAAS;AAC9B,YAAM,WAAW,OAAO,QAAQ,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM;AAClE,YAAI,QAAQ,eAAe;AACzB,iBAAO;AAAA,QACT;AACA,eAAO,EAAE,GAAG,KAAK,CAAC,GAAG,GAAG,MAAM;AAAA,MAChC,GAAG,CAAC,CAAsB;AAC1B,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,QAAM,qBAAqB,MAAM;AAC/B,0BAAsB,CAAC,CAAC;AAAA,EAC1B;AAEA,QAAM,wBAAwB,CAC5B,eACA,YAC4B;AAC5B,UAAM,iBAAiB,gBAAgB,aAAa,GAAG,WAAW,CAAC;AACnE,WAAO,wBAAwB,gBAAgB,OAAO;AAAA,EACxD;AAEA,SACE;AAAA,IAAC,0BAA0B;AAAA,IAA1B;AAAA,MACC,OAAO;AAAA,QACL;AAAA,MACF;AAAA,MAEA;AAAA,QAAC,4BAA4B;AAAA,QAA5B;AAAA,UACC,OAAO;AAAA,YACL;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,UAEC;AAAA;AAAA,MACH;AAAA;AAAA,EACF;AAEJ;AAEO,MAAM,0BAA0B,MACrC,WAAW,2BAA2B;AAEjC,MAAM,mBAAmB,MAAM;AACpC,QAAM,eAAe,WAAW,yBAAyB;AACzD,QAAM,gBAAgB,wBAAwB;AAE9C,SAAO,EAAE,GAAG,cAAc,GAAG,cAAc;AAC7C;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n editDictionaryByKeyPath,\n getContentNodeByKeyPath,\n renameContentNodeByKeyPath,\n type ContentNode,\n type Dictionary,\n type KeyPath,\n type LocalDictionaryId,\n} from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n useContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n} from 'react';\nimport {\n useDictionariesRecord,\n type DictionaryContent,\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 dictionaryKey: string,\n keyPath: KeyPath[],\n localDictionaryId?: LocalDictionaryId\n ) => ContentNode | undefined;\n};\n\nconst EditedContentActionsContext = createContext<\n EditedContentActionsContextType | undefined\n>(undefined);\n\nconst resolveState = <S,>(state?: SetStateAction<S>, prevState?: S): S =>\n typeof state === 'function'\n ? (state as (prevState?: S) => S)(prevState)\n : (state as S);\n\nexport const EditedContentProvider: FC<PropsWithChildren> = ({ children }) => {\n const { localeDictionaries } = useDictionariesRecord();\n\n const [editedContent, setEditedContentState] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_EDITED_CONTENT_CHANGED\n );\n\n const setEditedDictionary: Dispatch<SetStateAction<Dictionary>> = (\n newValue\n ) => {\n let updatedDictionaries: Dictionary = resolveState(newValue);\n\n setEditedContentState((prev) => {\n updatedDictionaries = resolveState(\n newValue,\n prev?.[updatedDictionaries.key]\n );\n\n return {\n ...prev,\n [updatedDictionaries.key]: updatedDictionaries,\n };\n });\n\n return updatedDictionaries;\n };\n\n const setEditedContent = (\n 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 | 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]?.content ?? {};\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 = editedContent?.[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":";AAqTM;AAnTN;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AACP,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,OAKK;AACP;AAAA,EACE;AAAA,OAEK;AACP,SAAS,oCAAoC;AAC7C,SAAS,0BAA0B;AAMnC,MAAM,4BAA4B,cAEhC,MAAS;AAEJ,MA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OAAO;AAEnE,UAAI,YAAa,QAAO;AAAA,IAC1B;AAEA,WAAO;AAAA,EACT;AAEA,SACE;AAAA,IAAC,0BAA0B;AAAA,IAA1B;AAAA,MACC,OAAO;AAAA,QACL;AAAA,MACF;AAAA,MAEA;AAAA,QAAC,4BAA4B;AAAA,QAA5B;AAAA,UACC,OAAO;AAAA,YACL;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,UAEC;AAAA;AAAA,MACH;AAAA;AAAA,EACF;AAEJ;AAEO,MAAM,0BAA0B,MACrC,WAAW,2BAA2B;AAEjC,MAAM,mBAAmB,MAAM;AACpC,QAAM,eAAe,WAAW,yBAAyB;AACzD,QAAM,gBAAgB,wBAAwB;AAE9C,SAAO,EAAE,GAAG,cAAc,GAAG,cAAc;AAC7C;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport type { KeyPath } from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n useContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\
|
|
1
|
+
{"version":3,"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport type { KeyPath } from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n useContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n} from '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":";AAwDM;AArDN,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,OAKK;AACP,SAAS,0BAA0B;AAiBnC,MAAM,8BAA8B,cAElC,MAAS;AACX,MAAM,gCAAgC,cAEpC,MAAS;AAEJ,MAAM,0BAAiD,CAAC;AAAA,EAC7D;AACF,MAAM;AACJ,QAAM,CAAC,gBAAgB,iBAAiB,IACtC;AAAA,IACE,WAAW;AAAA,IACX;AAAA,EACF;AAEF,QAAM,2BAA2B,CAAC,YAAuB;AACvD,sBAAkB,CAAC,SAAS;AAC1B,UAAI,CAAC,MAAM;AACT,eAAO;AAAA,MACT;AACA,aAAO,EAAE,GAAG,MAAM,QAAQ;AAAA,IAC5B,CAAC;AAAA,EACH;AAEA,SACE,oBAAC,4BAA4B,UAA5B,EAAqC,OAAO,EAAE,eAAe,GAC5D;AAAA,IAAC,8BAA8B;AAAA,IAA9B;AAAA,MACC,OAAO,EAAE,mBAAmB,yBAAyB;AAAA,MAEpD;AAAA;AAAA,EACH,GACF;AAEJ;AAEO,MAAM,4BAA4B,MAAM;AAC7C,QAAM,UAAU,WAAW,6BAA6B;AACxD,MAAI,YAAY,QAAW;AACzB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,qBAAqB,MAAM;AACtC,QAAM,gBAAgB,0BAA0B;AAChD,QAAM,eAAe,WAAW,2BAA2B;AAE3D,MAAI,iBAAiB,QAAW;AAC9B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,cAAc,GAAG,cAAc;AAC7C;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Dictionary } from '@intlayer/core';
|
|
1
|
+
import type { Dictionary, LocalDictionaryId } from '@intlayer/core';
|
|
2
2
|
import { type Dispatch, type FC, type PropsWithChildren, type SetStateAction } from 'react';
|
|
3
|
-
export type DictionaryContent = Record<
|
|
3
|
+
export type DictionaryContent = Record<LocalDictionaryId, Dictionary>;
|
|
4
4
|
type DictionariesRecordActionsContextType = {
|
|
5
5
|
setLocaleDictionaries: Dispatch<SetStateAction<DictionaryContent>>;
|
|
6
6
|
setLocaleDictionary: (dictionary: Dictionary) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DictionariesRecordContext.d.ts","sourceRoot":"","sources":["../../src/DictionariesRecordContext.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"DictionariesRecordContext.d.ts","sourceRoot":"","sources":["../../src/DictionariesRecordContext.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEpE,OAAO,EAIL,KAAK,QAAQ,EACb,KAAK,EAAE,EACP,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACpB,MAAM,OAAO,CAAC;AAGf,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;AAKtE,KAAK,oCAAoC,GAAG;IAC1C,qBAAqB,EAAE,QAAQ,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC,CAAC;IACnE,mBAAmB,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;CACvD,CAAC;AASF,eAAO,MAAM,0BAA0B,EAAE,EAAE,CAAC,iBAAiB,CAsC5D,CAAC;AAEF,eAAO,MAAM,4BAA4B,4CACK,CAAC;AAE/C,eAAO,MAAM,qBAAqB;2BAtDT,QAAQ,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;yBAC7C,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI;wBAJjC,iBAAiB;CAoEtC,CAAC"}
|
|
@@ -1,33 +1,34 @@
|
|
|
1
|
-
import { type ContentNode, type Dictionary, type KeyPath } from '@intlayer/core';
|
|
1
|
+
import { type ContentNode, type Dictionary, type KeyPath, type LocalDictionaryId } from '@intlayer/core';
|
|
2
2
|
import { type Dispatch, type FC, type PropsWithChildren, type SetStateAction } from 'react';
|
|
3
|
+
import { type DictionaryContent } from './DictionariesRecordContext';
|
|
3
4
|
export declare const usePostEditedContentState: <S>(onEventTriggered?: (data: S) => void) => (data?: S) => void;
|
|
4
5
|
export declare const useGetEditedContentState: <S>(onEventTriggered?: (data: S) => void) => (data?: S) => void;
|
|
5
6
|
type EditedContentActionsContextType = {
|
|
6
|
-
setEditedContentState: (editedContent:
|
|
7
|
+
setEditedContentState: (editedContent: DictionaryContent) => void;
|
|
7
8
|
setEditedDictionary: Dispatch<SetStateAction<Dictionary>>;
|
|
8
|
-
setEditedContent: (
|
|
9
|
-
addEditedContent: (
|
|
10
|
-
renameEditedContent: (
|
|
11
|
-
removeEditedContent: (
|
|
12
|
-
restoreEditedContent: (
|
|
13
|
-
clearEditedDictionaryContent: (
|
|
9
|
+
setEditedContent: (localDictionaryId: LocalDictionaryId, newValue: Dictionary['content']) => void;
|
|
10
|
+
addEditedContent: (localDictionaryId: LocalDictionaryId, newValue: ContentNode<any>, keyPath?: KeyPath[], overwrite?: boolean) => void;
|
|
11
|
+
renameEditedContent: (localDictionaryId: LocalDictionaryId, newKey: KeyPath['key'], keyPath?: KeyPath[]) => void;
|
|
12
|
+
removeEditedContent: (localDictionaryId: LocalDictionaryId, keyPath: KeyPath[]) => void;
|
|
13
|
+
restoreEditedContent: (localDictionaryId: LocalDictionaryId) => void;
|
|
14
|
+
clearEditedDictionaryContent: (localDictionaryId: LocalDictionaryId) => void;
|
|
14
15
|
clearEditedContent: () => void;
|
|
15
|
-
getEditedContentValue: (dictionaryKey:
|
|
16
|
+
getEditedContentValue: (dictionaryKey: string, keyPath: KeyPath[], localDictionaryId?: LocalDictionaryId) => ContentNode | undefined;
|
|
16
17
|
};
|
|
17
18
|
export declare const EditedContentProvider: FC<PropsWithChildren>;
|
|
18
19
|
export declare const useEditedContentActions: () => EditedContentActionsContextType;
|
|
19
20
|
export declare const useEditedContent: () => {
|
|
20
|
-
setEditedContentState: (editedContent:
|
|
21
|
+
setEditedContentState: (editedContent: DictionaryContent) => void;
|
|
21
22
|
setEditedDictionary: Dispatch<SetStateAction<Dictionary>>;
|
|
22
|
-
setEditedContent: (
|
|
23
|
-
addEditedContent: (
|
|
24
|
-
renameEditedContent: (
|
|
25
|
-
removeEditedContent: (
|
|
26
|
-
restoreEditedContent: (
|
|
27
|
-
clearEditedDictionaryContent: (
|
|
23
|
+
setEditedContent: (localDictionaryId: LocalDictionaryId, newValue: Dictionary["content"]) => void;
|
|
24
|
+
addEditedContent: (localDictionaryId: LocalDictionaryId, newValue: ContentNode<any>, keyPath?: KeyPath[], overwrite?: boolean) => void;
|
|
25
|
+
renameEditedContent: (localDictionaryId: LocalDictionaryId, newKey: KeyPath["key"], keyPath?: KeyPath[]) => void;
|
|
26
|
+
removeEditedContent: (localDictionaryId: LocalDictionaryId, keyPath: KeyPath[]) => void;
|
|
27
|
+
restoreEditedContent: (localDictionaryId: LocalDictionaryId) => void;
|
|
28
|
+
clearEditedDictionaryContent: (localDictionaryId: LocalDictionaryId) => void;
|
|
28
29
|
clearEditedContent: () => void;
|
|
29
|
-
getEditedContentValue: (dictionaryKey:
|
|
30
|
-
editedContent: Record<
|
|
30
|
+
getEditedContentValue: (dictionaryKey: string, keyPath: KeyPath[], localDictionaryId?: LocalDictionaryId) => ContentNode | undefined;
|
|
31
|
+
editedContent: Record<LocalDictionaryId, Dictionary> | undefined;
|
|
31
32
|
};
|
|
32
33
|
export {};
|
|
33
34
|
//# sourceMappingURL=EditedContentContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditedContentContext.d.ts","sourceRoot":"","sources":["../../src/EditedContentContext.tsx"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,OAAO,
|
|
1
|
+
{"version":3,"file":"EditedContentContext.d.ts","sourceRoot":"","sources":["../../src/EditedContentContext.tsx"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,iBAAiB,EACvB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAGL,KAAK,QAAQ,EACb,KAAK,EAAE,EACP,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACpB,MAAM,OAAO,CAAC;AACf,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,6BAA6B,CAAC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WF,eAAO,MAAM,qBAAqB,EAAE,EAAE,CAAC,iBAAiB,CA2OvD,CAAC;AAEF,eAAO,MAAM,uBAAuB,uCACK,CAAC;AAE1C,eAAO,MAAM,gBAAgB;2BAxRJ,CAAC,aAAa,EAAE,iBAAiB,KAAK,IAAI;yBAC5C,QAAQ,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;sBACvC,CAChB,iBAAiB,EAAE,iBAAiB,EACpC,QAAQ,EAAE,UAAU,CAAC,SAAS,CAAC,KAC5B,IAAI;sBACS,CAChB,iBAAiB,EAAE,iBAAiB,EACpC,QAAQ,EAAE,WAAW,CAAC,GAAG,CAAC,EAC1B,OAAO,CAAC,EAAE,OAAO,EAAE,EACnB,SAAS,CAAC,EAAE,OAAO,KAChB,IAAI;yBACY,CACnB,iBAAiB,EAAE,iBAAiB,EACpC,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,EACtB,OAAO,CAAC,EAAE,OAAO,EAAE,KAChB,IAAI;yBACY,CACnB,iBAAiB,EAAE,iBAAiB,EACpC,OAAO,EAAE,OAAO,EAAE,KACf,IAAI;0BACa,CAAC,iBAAiB,EAAE,iBAAiB,KAAK,IAAI;kCACtC,CAAC,iBAAiB,EAAE,iBAAiB,KAAK,IAAI;wBACxD,MAAM,IAAI;2BACP,CACrB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,OAAO,EAAE,EAClB,iBAAiB,CAAC,EAAE,iBAAiB,KAClC,WAAW,GAAG,SAAS;mBApDb,MAAM,CAAC,iBAAiB,EAAE,UAAU,CAAC,GAAG,SAAS;CAqTjE,CAAC"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { KeyPath } from '@intlayer/core';
|
|
2
2
|
import { type Dispatch, type FC, type PropsWithChildren, type SetStateAction } from 'react';
|
|
3
|
-
type DictionaryPath = string;
|
|
4
3
|
export type FileContent = {
|
|
5
4
|
dictionaryKey: string;
|
|
5
|
+
dictionaryLocalId?: string;
|
|
6
6
|
keyPath?: KeyPath[];
|
|
7
|
-
dictionaryPath?: DictionaryPath;
|
|
8
7
|
};
|
|
9
8
|
type FocusDictionaryActions = {
|
|
10
9
|
setFocusedContent: Dispatch<SetStateAction<FileContent | null>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FocusDictionaryContext.d.ts","sourceRoot":"","sources":["../../src/FocusDictionaryContext.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAGL,KAAK,QAAQ,EACb,KAAK,EAAE,EACP,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACpB,MAAM,OAAO,CAAC;AAGf,
|
|
1
|
+
{"version":3,"file":"FocusDictionaryContext.d.ts","sourceRoot":"","sources":["../../src/FocusDictionaryContext.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAGL,KAAK,QAAQ,EACb,KAAK,EAAE,EACP,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACpB,MAAM,OAAO,CAAC;AAGf,MAAM,MAAM,WAAW,GAAG;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;CACrB,CAAC;AAMF,KAAK,sBAAsB,GAAG;IAC5B,iBAAiB,EAAE,QAAQ,CAAC,cAAc,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC;IAChE,wBAAwB,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;CACxD,CAAC;AASF,eAAO,MAAM,uBAAuB,EAAE,EAAE,CAAC,iBAAiB,CA2BzD,CAAC;AAEF,eAAO,MAAM,yBAAyB,8BAQrC,CAAC;AAEF,eAAO,MAAM,kBAAkB;uBAlDV,QAAQ,CAAC,cAAc,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;8BACrC,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,IAAI;oBALtC,WAAW,GAAG,IAAI;CAiEnC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/editor-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-canary.1",
|
|
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": [
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"uuid": "^11.1.0",
|
|
56
|
-
"@intlayer/config": "
|
|
57
|
-
"@intlayer/editor": "
|
|
58
|
-
"@intlayer/core": "
|
|
56
|
+
"@intlayer/config": "6.0.0-canary.1",
|
|
57
|
+
"@intlayer/editor": "6.0.0-canary.1",
|
|
58
|
+
"@intlayer/core": "6.0.0-canary.1"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/node": "^24.2.1",
|
|
@@ -63,25 +63,25 @@
|
|
|
63
63
|
"@types/react-dom": ">=16.0.0",
|
|
64
64
|
"@typescript-eslint/parser": "^8.33.1",
|
|
65
65
|
"concurrently": "^9.1.2",
|
|
66
|
-
"eslint": "^9.
|
|
67
|
-
"prettier": "^3.
|
|
66
|
+
"eslint": "^9.34.0",
|
|
67
|
+
"prettier": "^3.6.2",
|
|
68
68
|
"react": ">=16.0.0",
|
|
69
69
|
"react-dom": ">=16.0.0",
|
|
70
70
|
"rimraf": "^6.0.1",
|
|
71
71
|
"tsc-alias": "^1.8.16",
|
|
72
72
|
"tsup": "^8.5.0",
|
|
73
73
|
"typescript": "^5.9.2",
|
|
74
|
-
"vitest": "^3.2.
|
|
74
|
+
"vitest": "^3.2.4",
|
|
75
75
|
"@utils/eslint-config": "1.0.4",
|
|
76
|
-
"@utils/ts-config-types": "1.0.4",
|
|
77
76
|
"@utils/ts-config": "1.0.4",
|
|
77
|
+
"@utils/ts-config-types": "1.0.4",
|
|
78
78
|
"@utils/tsup-config": "1.0.4"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
81
|
"react": ">=16.0.0",
|
|
82
82
|
"react-dom": ">=16.0.0",
|
|
83
|
-
"@intlayer/config": "
|
|
84
|
-
"@intlayer/core": "
|
|
83
|
+
"@intlayer/config": "6.0.0-canary.1",
|
|
84
|
+
"@intlayer/core": "6.0.0-canary.1"
|
|
85
85
|
},
|
|
86
86
|
"engines": {
|
|
87
87
|
"node": ">=14.18"
|