@intlayer/editor-react 5.1.1 → 5.1.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.
Files changed (30) hide show
  1. package/dist/cjs/ChangedContentContext.cjs +2 -2
  2. package/dist/cjs/ChangedContentContext.cjs.map +1 -1
  3. package/dist/cjs/CommunicatorContext.cjs +1 -1
  4. package/dist/cjs/CommunicatorContext.cjs.map +1 -1
  5. package/dist/cjs/ConfigurationContext.cjs +1 -1
  6. package/dist/cjs/ConfigurationContext.cjs.map +1 -1
  7. package/dist/cjs/DictionariesRecordContext.cjs +1 -1
  8. package/dist/cjs/DictionariesRecordContext.cjs.map +1 -1
  9. package/dist/cjs/EditedContentContext.cjs +2 -2
  10. package/dist/cjs/EditedContentContext.cjs.map +1 -1
  11. package/dist/cjs/EditorEnabledContext.cjs +1 -1
  12. package/dist/cjs/EditorEnabledContext.cjs.map +1 -1
  13. package/dist/cjs/FocusDictionaryContext.cjs +2 -2
  14. package/dist/cjs/FocusDictionaryContext.cjs.map +1 -1
  15. package/dist/esm/ChangedContentContext.mjs +2 -2
  16. package/dist/esm/ChangedContentContext.mjs.map +1 -1
  17. package/dist/esm/CommunicatorContext.mjs +1 -1
  18. package/dist/esm/CommunicatorContext.mjs.map +1 -1
  19. package/dist/esm/ConfigurationContext.mjs +1 -1
  20. package/dist/esm/ConfigurationContext.mjs.map +1 -1
  21. package/dist/esm/DictionariesRecordContext.mjs +1 -1
  22. package/dist/esm/DictionariesRecordContext.mjs.map +1 -1
  23. package/dist/esm/EditedContentContext.mjs +2 -2
  24. package/dist/esm/EditedContentContext.mjs.map +1 -1
  25. package/dist/esm/EditorEnabledContext.mjs +1 -1
  26. package/dist/esm/EditorEnabledContext.mjs.map +1 -1
  27. package/dist/esm/FocusDictionaryContext.mjs +2 -2
  28. package/dist/esm/FocusDictionaryContext.mjs.map +1 -1
  29. package/dist/types/CommunicatorContext.d.ts.map +1 -1
  30. package/package.json +9 -9
@@ -42,13 +42,13 @@ const ChangedContentProvider = ({ children }) => {
42
42
  }));
43
43
  };
44
44
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
45
- ChangedContentStateContext,
45
+ ChangedContentStateContext.Provider,
46
46
  {
47
47
  value: {
48
48
  changedContent
49
49
  },
50
50
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
51
- ChangedContentActionsContext,
51
+ ChangedContentActionsContext.Provider,
52
52
  {
53
53
  value: {
54
54
  setChangedContent
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ChangedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport type { Dictionary } from '@intlayer/core';\nimport {\n createContext,\n useContext,\n useState,\n type FC,\n type PropsWithChildren,\n} from 'react';\nimport type { DictionaryContent } from './DictionariesRecordContext';\n\ntype ChangedContentStateContextType = {\n changedContent: Record<Dictionary['key'], Dictionary> | undefined;\n};\n\nconst ChangedContentStateContext = createContext<\n ChangedContentStateContextType | undefined\n>(undefined);\n\ntype ChangedContentActionsContextType = {\n setChangedContent: (\n dictionaryKey: Dictionary['key'],\n newValue: Dictionary['content']\n ) => void;\n};\n\nconst ChangedContentActionsContext = createContext<\n ChangedContentActionsContextType | undefined\n>(undefined);\n\nexport const ChangedContentProvider: FC<PropsWithChildren> = ({ children }) => {\n const [changedContent, setChangedContentState] = useState<DictionaryContent>(\n {}\n );\n\n const setChangedContent = (\n dictionaryKey: Dictionary['key'],\n newValue: Dictionary['content']\n ) => {\n setChangedContentState((prev) => ({\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: newValue,\n },\n }));\n };\n\n return (\n <ChangedContentStateContext\n value={{\n changedContent,\n }}\n >\n <ChangedContentActionsContext\n value={{\n setChangedContent,\n }}\n >\n {children}\n </ChangedContentActionsContext>\n </ChangedContentStateContext>\n );\n};\n\nexport const useChangedContentActions = () => {\n const context = useContext(ChangedContentActionsContext);\n\n if (!context) {\n throw new Error(\n 'useChangedContent must be used within an ChangedContentProvider'\n );\n }\n\n return context;\n};\n\nexport const useChangedContent = () => {\n const stateContext = useContext(ChangedContentStateContext);\n const actionContext = useChangedContentActions();\n\n if (!stateContext) {\n throw new Error(\n 'useChangedContent must be used within an ChangedContentProvider'\n );\n }\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuDM;AApDN,mBAMO;AAOP,MAAM,iCAA6B,4BAEjC,MAAS;AASX,MAAM,mCAA+B,4BAEnC,MAAS;AAEJ,MAAM,yBAAgD,CAAC,EAAE,SAAS,MAAM;AAC7E,QAAM,CAAC,gBAAgB,sBAAsB,QAAI;AAAA,IAC/C,CAAC;AAAA,EACH;AAEA,QAAM,oBAAoB,CACxB,eACA,aACG;AACH,2BAAuB,CAAC,UAAU;AAAA,MAChC,GAAG;AAAA,MACH,CAAC,aAAa,GAAG;AAAA,QACf,GAAG,OAAO,aAAa;AAAA,QACvB,SAAS;AAAA,MACX;AAAA,IACF,EAAE;AAAA,EACJ;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO;AAAA,QACL;AAAA,MACF;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UACC,OAAO;AAAA,YACL;AAAA,UACF;AAAA,UAEC;AAAA;AAAA,MACH;AAAA;AAAA,EACF;AAEJ;AAEO,MAAM,2BAA2B,MAAM;AAC5C,QAAM,cAAU,yBAAW,4BAA4B;AAEvD,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEO,MAAM,oBAAoB,MAAM;AACrC,QAAM,mBAAe,yBAAW,0BAA0B;AAC1D,QAAM,gBAAgB,yBAAyB;AAE/C,MAAI,CAAC,cAAc;AACjB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,cAAc,GAAG,cAAc;AAC7C;","names":[]}
1
+ {"version":3,"sources":["../../src/ChangedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport type { Dictionary } from '@intlayer/core';\nimport {\n createContext,\n useContext,\n useState,\n type FC,\n type PropsWithChildren,\n} from 'react';\nimport type { DictionaryContent } from './DictionariesRecordContext';\n\ntype ChangedContentStateContextType = {\n changedContent: Record<Dictionary['key'], Dictionary> | undefined;\n};\n\nconst ChangedContentStateContext = createContext<\n ChangedContentStateContextType | undefined\n>(undefined);\n\ntype ChangedContentActionsContextType = {\n setChangedContent: (\n dictionaryKey: Dictionary['key'],\n newValue: Dictionary['content']\n ) => void;\n};\n\nconst ChangedContentActionsContext = createContext<\n ChangedContentActionsContextType | undefined\n>(undefined);\n\nexport const ChangedContentProvider: FC<PropsWithChildren> = ({ children }) => {\n const [changedContent, setChangedContentState] = useState<DictionaryContent>(\n {}\n );\n\n const setChangedContent = (\n dictionaryKey: Dictionary['key'],\n newValue: Dictionary['content']\n ) => {\n setChangedContentState((prev) => ({\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: newValue,\n },\n }));\n };\n\n return (\n <ChangedContentStateContext.Provider\n value={{\n changedContent,\n }}\n >\n <ChangedContentActionsContext.Provider\n value={{\n setChangedContent,\n }}\n >\n {children}\n </ChangedContentActionsContext.Provider>\n </ChangedContentStateContext.Provider>\n );\n};\n\nexport const useChangedContentActions = () => {\n const context = useContext(ChangedContentActionsContext);\n\n if (!context) {\n throw new Error(\n 'useChangedContent must be used within an ChangedContentProvider'\n );\n }\n\n return context;\n};\n\nexport const useChangedContent = () => {\n const stateContext = useContext(ChangedContentStateContext);\n const actionContext = useChangedContentActions();\n\n if (!stateContext) {\n throw new Error(\n 'useChangedContent must be used within an ChangedContentProvider'\n );\n }\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuDM;AApDN,mBAMO;AAOP,MAAM,iCAA6B,4BAEjC,MAAS;AASX,MAAM,mCAA+B,4BAEnC,MAAS;AAEJ,MAAM,yBAAgD,CAAC,EAAE,SAAS,MAAM;AAC7E,QAAM,CAAC,gBAAgB,sBAAsB,QAAI;AAAA,IAC/C,CAAC;AAAA,EACH;AAEA,QAAM,oBAAoB,CACxB,eACA,aACG;AACH,2BAAuB,CAAC,UAAU;AAAA,MAChC,GAAG;AAAA,MACH,CAAC,aAAa,GAAG;AAAA,QACf,GAAG,OAAO,aAAa;AAAA,QACvB,SAAS;AAAA,MACX;AAAA,IACF,EAAE;AAAA,EACJ;AAEA,SACE;AAAA,IAAC,2BAA2B;AAAA,IAA3B;AAAA,MACC,OAAO;AAAA,QACL;AAAA,MACF;AAAA,MAEA;AAAA,QAAC,6BAA6B;AAAA,QAA7B;AAAA,UACC,OAAO;AAAA,YACL;AAAA,UACF;AAAA,UAEC;AAAA;AAAA,MACH;AAAA;AAAA,EACF;AAEJ;AAEO,MAAM,2BAA2B,MAAM;AAC5C,QAAM,cAAU,yBAAW,4BAA4B;AAEvD,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEO,MAAM,oBAAoB,MAAM;AACrC,QAAM,mBAAe,yBAAW,0BAA0B;AAC1D,QAAM,gBAAgB,yBAAyB;AAE/C,MAAI,CAAC,cAAc;AACjB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,cAAc,GAAG,cAAc;AAC7C;","names":[]}
@@ -43,7 +43,7 @@ const CommunicatorProvider = ({
43
43
  () => ({ postMessage, allowedOrigins, senderId: senderIdRef.current }),
44
44
  [postMessage, allowedOrigins, senderIdRef.current]
45
45
  );
46
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CommunicatorContext, { value, children });
46
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CommunicatorContext.Provider, { value, children });
47
47
  };
48
48
  const useCommunicator = () => (0, import_react.useContext)(CommunicatorContext);
49
49
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport {\n createContext,\n useContext,\n useMemo,\n useRef,\n type FC,\n type PropsWithChildren,\n} from 'react';\nimport { v4 as uuid } from 'uuid'; // if you prefer a UUID library\n\nexport type UseCrossPlatformStateProps = {\n postMessage: typeof window.postMessage;\n allowedOrigins?: string[];\n senderId: string;\n};\n\nconst { editor } = getConfiguration();\n\nconst CommunicatorContext = createContext<UseCrossPlatformStateProps>({\n postMessage: () => null,\n allowedOrigins: [editor.applicationURL, editor.editorURL, editor.cmsURL],\n senderId: '',\n});\n\nexport type CommunicatorProviderProps = PropsWithChildren<\n Omit<UseCrossPlatformStateProps, 'senderId'>\n>;\n\nexport const CommunicatorProvider: FC<CommunicatorProviderProps> = ({\n children,\n allowedOrigins,\n postMessage,\n}) => {\n // Create a stable, unique ID for the lifetime of this app/iframe instance.\n const senderIdRef = useRef(uuid());\n\n const value = useMemo(\n () => ({ postMessage, allowedOrigins, senderId: senderIdRef.current }),\n [postMessage, allowedOrigins, senderIdRef.current]\n );\n\n return <CommunicatorContext value={value}>{children}</CommunicatorContext>;\n};\n\nexport const useCommunicator = () => useContext(CommunicatorContext);\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA4CS;AA1CT,oBAAiC;AACjC,mBAOO;AACP,kBAA2B;AAQ3B,MAAM,EAAE,OAAO,QAAI,gCAAiB;AAEpC,MAAM,0BAAsB,4BAA0C;AAAA,EACpE,aAAa,MAAM;AAAA,EACnB,gBAAgB,CAAC,OAAO,gBAAgB,OAAO,WAAW,OAAO,MAAM;AAAA,EACvE,UAAU;AACZ,CAAC;AAMM,MAAM,uBAAsD,CAAC;AAAA,EAClE;AAAA,EACA;AAAA,EACA;AACF,MAAM;AAEJ,QAAM,kBAAc,yBAAO,YAAAA,IAAK,CAAC;AAEjC,QAAM,YAAQ;AAAA,IACZ,OAAO,EAAE,aAAa,gBAAgB,UAAU,YAAY,QAAQ;AAAA,IACpE,CAAC,aAAa,gBAAgB,YAAY,OAAO;AAAA,EACnD;AAEA,SAAO,4CAAC,uBAAoB,OAAe,UAAS;AACtD;AAEO,MAAM,kBAAkB,UAAM,yBAAW,mBAAmB;","names":["uuid"]}
1
+ {"version":3,"sources":["../../src/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport {\n createContext,\n useContext,\n useMemo,\n useRef,\n type FC,\n type PropsWithChildren,\n} from 'react';\nimport { v4 as uuid } from 'uuid'; // if you prefer a UUID library\n\nexport type UseCrossPlatformStateProps = {\n postMessage: typeof window.postMessage;\n allowedOrigins?: string[];\n senderId: string;\n};\n\nconst { editor } = getConfiguration();\n\nconst CommunicatorContext = createContext<UseCrossPlatformStateProps>({\n postMessage: () => null,\n allowedOrigins: [editor.applicationURL, editor.editorURL, editor.cmsURL],\n senderId: '',\n});\n\nexport type CommunicatorProviderProps = PropsWithChildren<\n Omit<UseCrossPlatformStateProps, 'senderId'>\n>;\n\nexport const CommunicatorProvider: FC<CommunicatorProviderProps> = ({\n children,\n allowedOrigins,\n postMessage,\n}) => {\n // Create a stable, unique ID for the lifetime of this app/iframe instance.\n const senderIdRef = useRef(uuid());\n\n const value = useMemo(\n () => ({ postMessage, allowedOrigins, senderId: senderIdRef.current }),\n [postMessage, allowedOrigins, senderIdRef.current]\n );\n\n return (\n <CommunicatorContext.Provider value={value}>\n {children}\n </CommunicatorContext.Provider>\n );\n};\n\nexport const useCommunicator = () => useContext(CommunicatorContext);\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA6CI;AA3CJ,oBAAiC;AACjC,mBAOO;AACP,kBAA2B;AAQ3B,MAAM,EAAE,OAAO,QAAI,gCAAiB;AAEpC,MAAM,0BAAsB,4BAA0C;AAAA,EACpE,aAAa,MAAM;AAAA,EACnB,gBAAgB,CAAC,OAAO,gBAAgB,OAAO,WAAW,OAAO,MAAM;AAAA,EACvE,UAAU;AACZ,CAAC;AAMM,MAAM,uBAAsD,CAAC;AAAA,EAClE;AAAA,EACA;AAAA,EACA;AACF,MAAM;AAEJ,QAAM,kBAAc,yBAAO,YAAAA,IAAK,CAAC;AAEjC,QAAM,YAAQ;AAAA,IACZ,OAAO,EAAE,aAAa,gBAAgB,UAAU,YAAY,QAAQ;AAAA,IACpE,CAAC,aAAa,gBAAgB,YAAY,OAAO;AAAA,EACnD;AAEA,SACE,4CAAC,oBAAoB,UAApB,EAA6B,OAC3B,UACH;AAEJ;AAEO,MAAM,kBAAkB,UAAM,yBAAW,mBAAmB;","names":["uuid"]}
@@ -34,7 +34,7 @@ const useConfigurationState = () => (0, import_useCrossFrameState.useCrossFrameS
34
34
  receive: false,
35
35
  emit: true
36
36
  });
37
- const ConfigurationProvider = ({ children, configuration }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ConfigurationStatesContext, { value: configuration, children });
37
+ const ConfigurationProvider = ({ children, configuration }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ConfigurationStatesContext.Provider, { value: configuration, children });
38
38
  const useConfiguration = () => {
39
39
  const statesContext = (0, import_react.useContext)(ConfigurationStatesContext);
40
40
  if (!statesContext) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport { type IntlayerConfig } from '@intlayer/config/client';\nimport {\n type FC,\n type PropsWithChildren,\n createContext,\n useContext,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nconst ConfigurationStatesContext = createContext<IntlayerConfig | undefined>(\n undefined\n);\n\nexport const useConfigurationState = () =>\n useCrossFrameState<IntlayerConfig>('INTLAYER_CONFIGURATION', undefined, {\n receive: false,\n emit: true,\n });\n\nexport type ConfigurationProviderProps = {\n configuration?: IntlayerConfig;\n};\n\nexport const ConfigurationProvider: FC<\n PropsWithChildren<ConfigurationProviderProps>\n> = ({ children, configuration }) => (\n <ConfigurationStatesContext value={configuration}>\n {children}\n </ConfigurationStatesContext>\n);\n\nexport const useConfiguration = () => {\n const statesContext = useContext(ConfigurationStatesContext);\n\n if (!statesContext) {\n throw new Error(\n 'useConfigurationStates must be used within a ConfigurationProvider'\n );\n }\n\n return statesContext;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA4BE;AAzBF,mBAKO;AACP,gCAAmC;AAEnC,MAAM,iCAA6B;AAAA,EACjC;AACF;AAEO,MAAM,wBAAwB,UACnC,8CAAmC,0BAA0B,QAAW;AAAA,EACtE,SAAS;AAAA,EACT,MAAM;AACR,CAAC;AAMI,MAAM,wBAET,CAAC,EAAE,UAAU,cAAc,MAC7B,4CAAC,8BAA2B,OAAO,eAChC,UACH;AAGK,MAAM,mBAAmB,MAAM;AACpC,QAAM,oBAAgB,yBAAW,0BAA0B;AAE3D,MAAI,CAAC,eAAe;AAClB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport { type IntlayerConfig } from '@intlayer/config/client';\nimport {\n type FC,\n type PropsWithChildren,\n createContext,\n useContext,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nconst ConfigurationStatesContext = createContext<IntlayerConfig | undefined>(\n undefined\n);\n\nexport const useConfigurationState = () =>\n useCrossFrameState<IntlayerConfig>('INTLAYER_CONFIGURATION', undefined, {\n receive: false,\n emit: true,\n });\n\nexport type ConfigurationProviderProps = {\n configuration?: IntlayerConfig;\n};\n\nexport const ConfigurationProvider: FC<\n PropsWithChildren<ConfigurationProviderProps>\n> = ({ children, configuration }) => (\n <ConfigurationStatesContext.Provider value={configuration}>\n {children}\n </ConfigurationStatesContext.Provider>\n);\n\nexport const useConfiguration = () => {\n const statesContext = useContext(ConfigurationStatesContext);\n\n if (!statesContext) {\n throw new Error(\n 'useConfigurationStates must be used within a ConfigurationProvider'\n );\n }\n\n return statesContext;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA4BE;AAzBF,mBAKO;AACP,gCAAmC;AAEnC,MAAM,iCAA6B;AAAA,EACjC;AACF;AAEO,MAAM,wBAAwB,UACnC,8CAAmC,0BAA0B,QAAW;AAAA,EACtE,SAAS;AAAA,EACT,MAAM;AACR,CAAC;AAMI,MAAM,wBAET,CAAC,EAAE,UAAU,cAAc,MAC7B,4CAAC,2BAA2B,UAA3B,EAAoC,OAAO,eACzC,UACH;AAGK,MAAM,mBAAmB,MAAM;AACpC,QAAM,oBAAgB,yBAAW,0BAA0B;AAE3D,MAAI,CAAC,eAAe;AAClB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -54,7 +54,7 @@ const DictionariesRecordProvider = ({
54
54
  }),
55
55
  [setLocaleDictionaries]
56
56
  );
57
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DictionariesRecordStatesContext, { value: stateValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DictionariesRecordActionsContext, { value: actionValue, children }) });
57
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DictionariesRecordStatesContext.Provider, { value: stateValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DictionariesRecordActionsContext.Provider, { value: actionValue, children }) });
58
58
  };
59
59
  const useDictionariesRecordActions = () => (0, import_react.useContext)(DictionariesRecordActionsContext);
60
60
  const useDictionariesRecord = () => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport type { Dictionary } from '@intlayer/core';\nimport {\n createContext,\n useContext,\n type Dispatch,\n type SetStateAction,\n type FC,\n type PropsWithChildren,\n useMemo,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport type DictionaryContent = Record<Dictionary['key'], 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 '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 setLocaleDictionaries((dictionaries) => ({\n ...dictionaries,\n [dictionary.key]: dictionary,\n }));\n },\n }),\n [setLocaleDictionaries]\n );\n\n return (\n <DictionariesRecordStatesContext value={stateValue}>\n <DictionariesRecordActionsContext value={actionValue}>\n {children}\n </DictionariesRecordActionsContext>\n </DictionariesRecordStatesContext>\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;AA8DM;AA3DN,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;AAAA,IACA;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,8BAAsB,CAAC,kBAAkB;AAAA,UACvC,GAAG;AAAA,UACH,CAAC,WAAW,GAAG,GAAG;AAAA,QACpB,EAAE;AAAA,MACJ;AAAA,IACF;AAAA,IACA,CAAC,qBAAqB;AAAA,EACxB;AAEA,SACE,4CAAC,mCAAgC,OAAO,YACtC,sDAAC,oCAAiC,OAAO,aACtC,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":[]}
1
+ {"version":3,"sources":["../../src/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport type { Dictionary } from '@intlayer/core';\nimport {\n createContext,\n useContext,\n type Dispatch,\n type SetStateAction,\n type FC,\n type PropsWithChildren,\n useMemo,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport type DictionaryContent = Record<Dictionary['key'], 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 '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 setLocaleDictionaries((dictionaries) => ({\n ...dictionaries,\n [dictionary.key]: 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;AA8DM;AA3DN,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;AAAA,IACA;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,8BAAsB,CAAC,kBAAkB;AAAA,UACvC,GAAG;AAAA,UACH,CAAC,WAAW,GAAG,GAAG;AAAA,QACpB,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":[]}
@@ -154,13 +154,13 @@ const EditedContentProvider = ({ children }) => {
154
154
  return (0, import_core.getContentNodeByKeyPath)(currentContent, keyPath);
155
155
  };
156
156
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
157
- EditedContentStateContext,
157
+ EditedContentStateContext.Provider,
158
158
  {
159
159
  value: {
160
160
  editedContent
161
161
  },
162
162
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
163
- EditedContentActionsContext,
163
+ EditedContentActionsContext.Provider,
164
164
  {
165
165
  value: {
166
166
  setEditedContentState,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n type Dictionary,\n type ContentNode,\n type KeyPath,\n editDictionaryByKeyPath,\n getContentNodeByKeyPath,\n renameContentNodeByKeyPath,\n} from '@intlayer/core';\nimport {\n createContext,\n useContext,\n type FC,\n type PropsWithChildren,\n} from 'react';\nimport {\n useDictionariesRecord,\n type DictionaryContent,\n} from './DictionariesRecordContext';\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\ntype EditedContentActionsContextType = {\n setEditedContentState: (\n editedContent: Record<Dictionary['key'], Dictionary>\n ) => void;\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\nexport const useEditedContentState = () =>\n useCrossFrameState<DictionaryContent>(\n 'INTLAYER_EDITED_CONTENT_CHANGED',\n undefined,\n { emit: true, receive: false }\n );\n\nexport const EditedContentProvider: FC<PropsWithChildren> = ({ children }) => {\n const { localeDictionaries } = useDictionariesRecord();\n\n const [editedContent, setEditedContentState] =\n useCrossFrameState<DictionaryContent>(\n 'INTLAYER_EDITED_CONTENT_CHANGED',\n undefined\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\n value={{\n editedContent,\n }}\n >\n <EditedContentActionsContext\n value={{\n setEditedContentState,\n setEditedContent,\n addEditedContent,\n renameEditedContent,\n removeEditedContent,\n restoreEditedContent,\n clearEditedDictionaryContent,\n clearEditedContent,\n getEditedContentValue,\n }}\n >\n {children}\n </EditedContentActionsContext>\n </EditedContentStateContext>\n );\n};\n\nexport const useEditedContentActions = () => {\n const context = useContext(EditedContentActionsContext);\n\n if (!context) {\n throw new Error(\n 'useEditedContent must be used within an EditedContentProvider'\n );\n }\n\n return context;\n};\n\nexport const useEditedContent = () => {\n const stateContext = useContext(EditedContentStateContext);\n const actionContext = useEditedContentActions();\n\n if (!stateContext) {\n throw new Error(\n 'useEditedContent must be used within an EditedContentProvider'\n );\n }\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoPM;AAlPN,kBAOO;AACP,mBAKO;AACP,uCAGO;AACP,gCAAmC;AAMnC,MAAM,gCAA4B,4BAEhC,MAAS;AAkCX,MAAM,kCAA8B,4BAElC,MAAS;AAEJ,MAAM,wBAAwB,UACnC;AAAA,EACE;AAAA,EACA;AAAA,EACA,EAAE,MAAM,MAAM,SAAS,MAAM;AAC/B;AAEK,MAAM,wBAA+C,CAAC,EAAE,SAAS,MAAM;AAC5E,QAAM,EAAE,mBAAmB,QAAI,wDAAsB;AAErD,QAAM,CAAC,eAAe,qBAAqB,QACzC;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAEF,QAAM,mBAAmB,CACvB,eACA,aACG;AACH,0BAAsB,CAAC,UAAU;AAAA,MAC/B,GAAG;AAAA,MACH,CAAC,aAAa,GAAG;AAAA,QACf,GAAG,OAAO,aAAa;AAAA,QACvB,SAAS;AAAA,MACX;AAAA,IACF,EAAE;AAAA,EACJ;AAEA,QAAM,mBAAmB,CACvB,eACA,UACA,UAAqB,CAAC,GACtB,YAAqB,SAClB;AACH,0BAAsB,CAAC,SAAS;AAE9B,YAAM,kBAAkB,mBAAmB,aAAa,GAAG;AAC3D,YAAM,iBAAiB;AAAA,QACrB,OAAO,aAAa,GAAG,WAAW;AAAA,MACpC;AAEA,UAAI,aAAa;AACjB,UAAI,CAAC,WAAW;AAEd,YAAI,QAAQ;AACZ,cAAM,eAAe,QAAQ,MAAM,GAAG,EAAE;AACxC,cAAM,cAAuB,QAAQ,QAAQ,SAAS,CAAC;AACvD,YAAI,WAAW,YAAY;AAG3B,eACE,WAAO,qCAAwB,gBA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AM,gBAAgB,wBAAwB;AAE9C,MAAI,CAAC,cAAc;AACjB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,cAAc,GAAG,cAAc;AAC7C;","names":[]}
1
+ {"version":3,"sources":["../../src/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n type Dictionary,\n type ContentNode,\n type KeyPath,\n editDictionaryByKeyPath,\n getContentNodeByKeyPath,\n renameContentNodeByKeyPath,\n} from '@intlayer/core';\nimport {\n createContext,\n useContext,\n type FC,\n type PropsWithChildren,\n} from 'react';\nimport {\n useDictionariesRecord,\n type DictionaryContent,\n} from './DictionariesRecordContext';\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\ntype EditedContentActionsContextType = {\n setEditedContentState: (\n editedContent: Record<Dictionary['key'], Dictionary>\n ) => void;\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\nexport const useEditedContentState = () =>\n useCrossFrameState<DictionaryContent>(\n 'INTLAYER_EDITED_CONTENT_CHANGED',\n undefined,\n { emit: true, receive: false }\n );\n\nexport const EditedContentProvider: FC<PropsWithChildren> = ({ children }) => {\n const { localeDictionaries } = useDictionariesRecord();\n\n const [editedContent, setEditedContentState] =\n useCrossFrameState<DictionaryContent>(\n 'INTLAYER_EDITED_CONTENT_CHANGED',\n undefined\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 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 const context = useContext(EditedContentActionsContext);\n\n if (!context) {\n throw new Error(\n 'useEditedContent must be used within an EditedContentProvider'\n );\n }\n\n return context;\n};\n\nexport const useEditedContent = () => {\n const stateContext = useContext(EditedContentStateContext);\n const actionContext = useEditedContentActions();\n\n if (!stateContext) {\n throw new Error(\n 'useEditedContent must be used within an EditedContentProvider'\n );\n }\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoPM;AAlPN,kBAOO;AACP,mBAKO;AACP,uCAGO;AACP,gCAAmC;AAMnC,MAAM,gCAA4B,4BAEhC,MAAS;AAkCX,MAAM,kCAA8B,4BAElC,MAAS;AAEJ,MAAM,wBAAwB,UACnC;AAAA,EACE;AAAA,EACA;AAAA,EACA,EAAE,MAAM,MAAM,SAAS,MAAM;AAC/B;AAEK,MAAM,wBAA+C,CAAC,EAAE,SAAS,MAAM;AAC5E,QAAM,EAAE,mBAAmB,QAAI,wDAAsB;AAErD,QAAM,CAAC,eAAe,qBAAqB,QACzC;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAEF,QAAM,mBAAmB,CACvB,eACA,aACG;AACH,0BAAsB,CAAC,UAAU;AAAA,MAC/B,GAAG;AAAA,MACH,CAAC,aAAa,GAAG;AAAA,QACf,GAAG,OAAO,aAAa;AAAA,QACvB,SAAS;AAAA,MACX;AAAA,IACF,EAAE;AAAA,EACJ;AAEA,QAAM,mBAAmB,CACvB,eACA,UACA,UAAqB,CAAC,GACtB,YAAqB,SAClB;AACH,0BAAsB,CAAC,SAAS;AAE9B,YAAM,kBAAkB,mBAAmB,aAAa,GAAG;AAC3D,YAAM,iBAAiB;AA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UACF;AAAA,UAEC;AAAA;AAAA,MACH;AAAA;AAAA,EACF;AAEJ;AAEO,MAAM,0BAA0B,MAAM;AAC3C,QAAM,cAAU,yBAAW,2BAA2B;AAEtD,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEO,MAAM,mBAAmB,MAAM;AACpC,QAAM,mBAAe,yBAAW,yBAAyB;AACzD,QAAM,gBAAgB,wBAAwB;AAE9C,MAAI,CAAC,cAAc;AACjB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,cAAc,GAAG,cAAc;AAC7C;","names":[]}
@@ -36,7 +36,7 @@ const EditorEnabledProvider = ({ children }) => {
36
36
  emit: false,
37
37
  receive: true
38
38
  });
39
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EditorEnabledContext, { value: { enabled: isEnabled }, children });
39
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EditorEnabledContext.Provider, { value: { enabled: isEnabled }, children });
40
40
  };
41
41
  const useEditorEnabled = () => {
42
42
  const context = (0, import_react.useContext)(EditorEnabledContext);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/EditorEnabledContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n createContext,\n useContext,\n type FC,\n type PropsWithChildren,\n} from 'react';\nimport {\n type CrossFrameStateOptions,\n useCrossFrameState,\n} from './useCrossFrameState';\n\nexport type EditorEnabledStateProps = {\n enabled: boolean;\n};\n\nconst EditorEnabledContext = createContext<EditorEnabledStateProps | undefined>(\n undefined\n);\n\nexport const useEditorEnabledState = (options?: CrossFrameStateOptions) =>\n useCrossFrameState('INTLAYER_EDITOR_ENABLED', false, options);\n\nexport const EditorEnabledProvider: FC<PropsWithChildren> = ({ children }) => {\n const [isEnabled] = useEditorEnabledState({\n emit: false,\n receive: true,\n });\n\n return (\n <EditorEnabledContext value={{ enabled: isEnabled }}>\n {children}\n </EditorEnabledContext>\n );\n};\n\nexport const useEditorEnabled = () => {\n const context = useContext(EditorEnabledContext);\n\n if (!context) {\n throw new Error('useEditorEnabled must be used within a EnabledProvider');\n }\n return context;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA+BI;AA7BJ,mBAKO;AACP,gCAGO;AAMP,MAAM,2BAAuB;AAAA,EAC3B;AACF;AAEO,MAAM,wBAAwB,CAAC,gBACpC,8CAAmB,2BAA2B,OAAO,OAAO;AAEvD,MAAM,wBAA+C,CAAC,EAAE,SAAS,MAAM;AAC5E,QAAM,CAAC,SAAS,IAAI,sBAAsB;AAAA,IACxC,MAAM;AAAA,IACN,SAAS;AAAA,EACX,CAAC;AAED,SACE,4CAAC,wBAAqB,OAAO,EAAE,SAAS,UAAU,GAC/C,UACH;AAEJ;AAEO,MAAM,mBAAmB,MAAM;AACpC,QAAM,cAAU,yBAAW,oBAAoB;AAE/C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,wDAAwD;AAAA,EAC1E;AACA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/EditorEnabledContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n createContext,\n useContext,\n type FC,\n type PropsWithChildren,\n} from 'react';\nimport {\n type CrossFrameStateOptions,\n useCrossFrameState,\n} from './useCrossFrameState';\n\nexport type EditorEnabledStateProps = {\n enabled: boolean;\n};\n\nconst EditorEnabledContext = createContext<EditorEnabledStateProps | undefined>(\n undefined\n);\n\nexport const useEditorEnabledState = (options?: CrossFrameStateOptions) =>\n useCrossFrameState('INTLAYER_EDITOR_ENABLED', false, options);\n\nexport const EditorEnabledProvider: FC<PropsWithChildren> = ({ children }) => {\n const [isEnabled] = useEditorEnabledState({\n emit: false,\n receive: true,\n });\n\n return (\n <EditorEnabledContext.Provider value={{ enabled: isEnabled }}>\n {children}\n </EditorEnabledContext.Provider>\n );\n};\n\nexport const useEditorEnabled = () => {\n const context = useContext(EditorEnabledContext);\n\n if (!context) {\n throw new Error('useEditorEnabled must be used within a EnabledProvider');\n }\n return context;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA+BI;AA7BJ,mBAKO;AACP,gCAGO;AAMP,MAAM,2BAAuB;AAAA,EAC3B;AACF;AAEO,MAAM,wBAAwB,CAAC,gBACpC,8CAAmB,2BAA2B,OAAO,OAAO;AAEvD,MAAM,wBAA+C,CAAC,EAAE,SAAS,MAAM;AAC5E,QAAM,CAAC,SAAS,IAAI,sBAAsB;AAAA,IACxC,MAAM;AAAA,IACN,SAAS;AAAA,EACX,CAAC;AAED,SACE,4CAAC,qBAAqB,UAArB,EAA8B,OAAO,EAAE,SAAS,UAAU,GACxD,UACH;AAEJ;AAEO,MAAM,mBAAmB,MAAM;AACpC,QAAM,cAAU,yBAAW,oBAAoB;AAE/C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,wDAAwD;AAAA,EAC1E;AACA,SAAO;AACT;","names":[]}
@@ -44,8 +44,8 @@ const FocusDictionaryProvider = ({
44
44
  return { ...prev, keyPath };
45
45
  });
46
46
  };
47
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FocusDictionaryStateContext, { value: { focusedContent }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
48
- FocusDictionaryActionsContext,
47
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FocusDictionaryStateContext.Provider, { value: { focusedContent }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
48
+ FocusDictionaryActionsContext.Provider,
49
49
  {
50
50
  value: { setFocusedContent, setFocusedContentKeyPath },
51
51
  children
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport type { KeyPath } from '@intlayer/core';\nimport {\n createContext,\n useContext,\n type FC,\n type PropsWithChildren,\n type Dispatch,\n type SetStateAction,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\ntype DictionaryPath = string;\n\nexport type FileContent = {\n dictionaryKey: string;\n keyPath?: KeyPath[];\n dictionaryPath?: DictionaryPath;\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 '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 value={{ focusedContent }}>\n <FocusDictionaryActionsContext\n value={{ setFocusedContent, setFocusedContentKeyPath }}\n >\n {children}\n </FocusDictionaryActionsContext>\n </FocusDictionaryStateContext>\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;AAyDM;AAtDN,mBAOO;AACP,gCAAmC;AAmBnC,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;AAAA,IACA;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,+BAA4B,OAAO,EAAE,eAAe,GACnD;AAAA,IAAC;AAAA;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":[]}
1
+ {"version":3,"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport type { KeyPath } from '@intlayer/core';\nimport {\n createContext,\n useContext,\n type FC,\n type PropsWithChildren,\n type Dispatch,\n type SetStateAction,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\ntype DictionaryPath = string;\n\nexport type FileContent = {\n dictionaryKey: string;\n keyPath?: KeyPath[];\n dictionaryPath?: DictionaryPath;\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 '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;AAyDM;AAtDN,mBAOO;AACP,gCAAmC;AAmBnC,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;AAAA,IACA;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":[]}
@@ -21,13 +21,13 @@ const ChangedContentProvider = ({ children }) => {
21
21
  }));
22
22
  };
23
23
  return /* @__PURE__ */ jsx(
24
- ChangedContentStateContext,
24
+ ChangedContentStateContext.Provider,
25
25
  {
26
26
  value: {
27
27
  changedContent
28
28
  },
29
29
  children: /* @__PURE__ */ jsx(
30
- ChangedContentActionsContext,
30
+ ChangedContentActionsContext.Provider,
31
31
  {
32
32
  value: {
33
33
  setChangedContent
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ChangedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport type { Dictionary } from '@intlayer/core';\nimport {\n createContext,\n useContext,\n useState,\n type FC,\n type PropsWithChildren,\n} from 'react';\nimport type { DictionaryContent } from './DictionariesRecordContext';\n\ntype ChangedContentStateContextType = {\n changedContent: Record<Dictionary['key'], Dictionary> | undefined;\n};\n\nconst ChangedContentStateContext = createContext<\n ChangedContentStateContextType | undefined\n>(undefined);\n\ntype ChangedContentActionsContextType = {\n setChangedContent: (\n dictionaryKey: Dictionary['key'],\n newValue: Dictionary['content']\n ) => void;\n};\n\nconst ChangedContentActionsContext = createContext<\n ChangedContentActionsContextType | undefined\n>(undefined);\n\nexport const ChangedContentProvider: FC<PropsWithChildren> = ({ children }) => {\n const [changedContent, setChangedContentState] = useState<DictionaryContent>(\n {}\n );\n\n const setChangedContent = (\n dictionaryKey: Dictionary['key'],\n newValue: Dictionary['content']\n ) => {\n setChangedContentState((prev) => ({\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: newValue,\n },\n }));\n };\n\n return (\n <ChangedContentStateContext\n value={{\n changedContent,\n }}\n >\n <ChangedContentActionsContext\n value={{\n setChangedContent,\n }}\n >\n {children}\n </ChangedContentActionsContext>\n </ChangedContentStateContext>\n );\n};\n\nexport const useChangedContentActions = () => {\n const context = useContext(ChangedContentActionsContext);\n\n if (!context) {\n throw new Error(\n 'useChangedContent must be used within an ChangedContentProvider'\n );\n }\n\n return context;\n};\n\nexport const useChangedContent = () => {\n const stateContext = useContext(ChangedContentStateContext);\n const actionContext = useChangedContentActions();\n\n if (!stateContext) {\n throw new Error(\n 'useChangedContent must be used within an ChangedContentProvider'\n );\n }\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":";AAuDM;AApDN;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAOP,MAAM,6BAA6B,cAEjC,MAAS;AASX,MAAM,+BAA+B,cAEnC,MAAS;AAEJ,MAAM,yBAAgD,CAAC,EAAE,SAAS,MAAM;AAC7E,QAAM,CAAC,gBAAgB,sBAAsB,IAAI;AAAA,IAC/C,CAAC;AAAA,EACH;AAEA,QAAM,oBAAoB,CACxB,eACA,aACG;AACH,2BAAuB,CAAC,UAAU;AAAA,MAChC,GAAG;AAAA,MACH,CAAC,aAAa,GAAG;AAAA,QACf,GAAG,OAAO,aAAa;AAAA,QACvB,SAAS;AAAA,MACX;AAAA,IACF,EAAE;AAAA,EACJ;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO;AAAA,QACL;AAAA,MACF;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UACC,OAAO;AAAA,YACL;AAAA,UACF;AAAA,UAEC;AAAA;AAAA,MACH;AAAA;AAAA,EACF;AAEJ;AAEO,MAAM,2BAA2B,MAAM;AAC5C,QAAM,UAAU,WAAW,4BAA4B;AAEvD,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEO,MAAM,oBAAoB,MAAM;AACrC,QAAM,eAAe,WAAW,0BAA0B;AAC1D,QAAM,gBAAgB,yBAAyB;AAE/C,MAAI,CAAC,cAAc;AACjB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,cAAc,GAAG,cAAc;AAC7C;","names":[]}
1
+ {"version":3,"sources":["../../src/ChangedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport type { Dictionary } from '@intlayer/core';\nimport {\n createContext,\n useContext,\n useState,\n type FC,\n type PropsWithChildren,\n} from 'react';\nimport type { DictionaryContent } from './DictionariesRecordContext';\n\ntype ChangedContentStateContextType = {\n changedContent: Record<Dictionary['key'], Dictionary> | undefined;\n};\n\nconst ChangedContentStateContext = createContext<\n ChangedContentStateContextType | undefined\n>(undefined);\n\ntype ChangedContentActionsContextType = {\n setChangedContent: (\n dictionaryKey: Dictionary['key'],\n newValue: Dictionary['content']\n ) => void;\n};\n\nconst ChangedContentActionsContext = createContext<\n ChangedContentActionsContextType | undefined\n>(undefined);\n\nexport const ChangedContentProvider: FC<PropsWithChildren> = ({ children }) => {\n const [changedContent, setChangedContentState] = useState<DictionaryContent>(\n {}\n );\n\n const setChangedContent = (\n dictionaryKey: Dictionary['key'],\n newValue: Dictionary['content']\n ) => {\n setChangedContentState((prev) => ({\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: newValue,\n },\n }));\n };\n\n return (\n <ChangedContentStateContext.Provider\n value={{\n changedContent,\n }}\n >\n <ChangedContentActionsContext.Provider\n value={{\n setChangedContent,\n }}\n >\n {children}\n </ChangedContentActionsContext.Provider>\n </ChangedContentStateContext.Provider>\n );\n};\n\nexport const useChangedContentActions = () => {\n const context = useContext(ChangedContentActionsContext);\n\n if (!context) {\n throw new Error(\n 'useChangedContent must be used within an ChangedContentProvider'\n );\n }\n\n return context;\n};\n\nexport const useChangedContent = () => {\n const stateContext = useContext(ChangedContentStateContext);\n const actionContext = useChangedContentActions();\n\n if (!stateContext) {\n throw new Error(\n 'useChangedContent must be used within an ChangedContentProvider'\n );\n }\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":";AAuDM;AApDN;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAOP,MAAM,6BAA6B,cAEjC,MAAS;AASX,MAAM,+BAA+B,cAEnC,MAAS;AAEJ,MAAM,yBAAgD,CAAC,EAAE,SAAS,MAAM;AAC7E,QAAM,CAAC,gBAAgB,sBAAsB,IAAI;AAAA,IAC/C,CAAC;AAAA,EACH;AAEA,QAAM,oBAAoB,CACxB,eACA,aACG;AACH,2BAAuB,CAAC,UAAU;AAAA,MAChC,GAAG;AAAA,MACH,CAAC,aAAa,GAAG;AAAA,QACf,GAAG,OAAO,aAAa;AAAA,QACvB,SAAS;AAAA,MACX;AAAA,IACF,EAAE;AAAA,EACJ;AAEA,SACE;AAAA,IAAC,2BAA2B;AAAA,IAA3B;AAAA,MACC,OAAO;AAAA,QACL;AAAA,MACF;AAAA,MAEA;AAAA,QAAC,6BAA6B;AAAA,QAA7B;AAAA,UACC,OAAO;AAAA,YACL;AAAA,UACF;AAAA,UAEC;AAAA;AAAA,MACH;AAAA;AAAA,EACF;AAEJ;AAEO,MAAM,2BAA2B,MAAM;AAC5C,QAAM,UAAU,WAAW,4BAA4B;AAEvD,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEO,MAAM,oBAAoB,MAAM;AACrC,QAAM,eAAe,WAAW,0BAA0B;AAC1D,QAAM,gBAAgB,yBAAyB;AAE/C,MAAI,CAAC,cAAc;AACjB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,cAAc,GAAG,cAAc;AAC7C;","names":[]}
@@ -24,7 +24,7 @@ const CommunicatorProvider = ({
24
24
  () => ({ postMessage, allowedOrigins, senderId: senderIdRef.current }),
25
25
  [postMessage, allowedOrigins, senderIdRef.current]
26
26
  );
27
- return /* @__PURE__ */ jsx(CommunicatorContext, { value, children });
27
+ return /* @__PURE__ */ jsx(CommunicatorContext.Provider, { value, children });
28
28
  };
29
29
  const useCommunicator = () => useContext(CommunicatorContext);
30
30
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport {\n createContext,\n useContext,\n useMemo,\n useRef,\n type FC,\n type PropsWithChildren,\n} from 'react';\nimport { v4 as uuid } from 'uuid'; // if you prefer a UUID library\n\nexport type UseCrossPlatformStateProps = {\n postMessage: typeof window.postMessage;\n allowedOrigins?: string[];\n senderId: string;\n};\n\nconst { editor } = getConfiguration();\n\nconst CommunicatorContext = createContext<UseCrossPlatformStateProps>({\n postMessage: () => null,\n allowedOrigins: [editor.applicationURL, editor.editorURL, editor.cmsURL],\n senderId: '',\n});\n\nexport type CommunicatorProviderProps = PropsWithChildren<\n Omit<UseCrossPlatformStateProps, 'senderId'>\n>;\n\nexport const CommunicatorProvider: FC<CommunicatorProviderProps> = ({\n children,\n allowedOrigins,\n postMessage,\n}) => {\n // Create a stable, unique ID for the lifetime of this app/iframe instance.\n const senderIdRef = useRef(uuid());\n\n const value = useMemo(\n () => ({ postMessage, allowedOrigins, senderId: senderIdRef.current }),\n [postMessage, allowedOrigins, senderIdRef.current]\n );\n\n return <CommunicatorContext value={value}>{children}</CommunicatorContext>;\n};\n\nexport const useCommunicator = () => useContext(CommunicatorContext);\n"],"mappings":";AA4CS;AA1CT,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,SAAS,MAAM,YAAY;AAQ3B,MAAM,EAAE,OAAO,IAAI,iBAAiB;AAEpC,MAAM,sBAAsB,cAA0C;AAAA,EACpE,aAAa,MAAM;AAAA,EACnB,gBAAgB,CAAC,OAAO,gBAAgB,OAAO,WAAW,OAAO,MAAM;AAAA,EACvE,UAAU;AACZ,CAAC;AAMM,MAAM,uBAAsD,CAAC;AAAA,EAClE;AAAA,EACA;AAAA,EACA;AACF,MAAM;AAEJ,QAAM,cAAc,OAAO,KAAK,CAAC;AAEjC,QAAM,QAAQ;AAAA,IACZ,OAAO,EAAE,aAAa,gBAAgB,UAAU,YAAY,QAAQ;AAAA,IACpE,CAAC,aAAa,gBAAgB,YAAY,OAAO;AAAA,EACnD;AAEA,SAAO,oBAAC,uBAAoB,OAAe,UAAS;AACtD;AAEO,MAAM,kBAAkB,MAAM,WAAW,mBAAmB;","names":[]}
1
+ {"version":3,"sources":["../../src/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport {\n createContext,\n useContext,\n useMemo,\n useRef,\n type FC,\n type PropsWithChildren,\n} from 'react';\nimport { v4 as uuid } from 'uuid'; // if you prefer a UUID library\n\nexport type UseCrossPlatformStateProps = {\n postMessage: typeof window.postMessage;\n allowedOrigins?: string[];\n senderId: string;\n};\n\nconst { editor } = getConfiguration();\n\nconst CommunicatorContext = createContext<UseCrossPlatformStateProps>({\n postMessage: () => null,\n allowedOrigins: [editor.applicationURL, editor.editorURL, editor.cmsURL],\n senderId: '',\n});\n\nexport type CommunicatorProviderProps = PropsWithChildren<\n Omit<UseCrossPlatformStateProps, 'senderId'>\n>;\n\nexport const CommunicatorProvider: FC<CommunicatorProviderProps> = ({\n children,\n allowedOrigins,\n postMessage,\n}) => {\n // Create a stable, unique ID for the lifetime of this app/iframe instance.\n const senderIdRef = useRef(uuid());\n\n const value = useMemo(\n () => ({ postMessage, allowedOrigins, senderId: senderIdRef.current }),\n [postMessage, allowedOrigins, senderIdRef.current]\n );\n\n return (\n <CommunicatorContext.Provider value={value}>\n {children}\n </CommunicatorContext.Provider>\n );\n};\n\nexport const useCommunicator = () => useContext(CommunicatorContext);\n"],"mappings":";AA6CI;AA3CJ,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,SAAS,MAAM,YAAY;AAQ3B,MAAM,EAAE,OAAO,IAAI,iBAAiB;AAEpC,MAAM,sBAAsB,cAA0C;AAAA,EACpE,aAAa,MAAM;AAAA,EACnB,gBAAgB,CAAC,OAAO,gBAAgB,OAAO,WAAW,OAAO,MAAM;AAAA,EACvE,UAAU;AACZ,CAAC;AAMM,MAAM,uBAAsD,CAAC;AAAA,EAClE;AAAA,EACA;AAAA,EACA;AACF,MAAM;AAEJ,QAAM,cAAc,OAAO,KAAK,CAAC;AAEjC,QAAM,QAAQ;AAAA,IACZ,OAAO,EAAE,aAAa,gBAAgB,UAAU,YAAY,QAAQ;AAAA,IACpE,CAAC,aAAa,gBAAgB,YAAY,OAAO;AAAA,EACnD;AAEA,SACE,oBAAC,oBAAoB,UAApB,EAA6B,OAC3B,UACH;AAEJ;AAEO,MAAM,kBAAkB,MAAM,WAAW,mBAAmB;","names":[]}
@@ -12,7 +12,7 @@ const useConfigurationState = () => useCrossFrameState("INTLAYER_CONFIGURATION",
12
12
  receive: false,
13
13
  emit: true
14
14
  });
15
- const ConfigurationProvider = ({ children, configuration }) => /* @__PURE__ */ jsx(ConfigurationStatesContext, { value: configuration, children });
15
+ const ConfigurationProvider = ({ children, configuration }) => /* @__PURE__ */ jsx(ConfigurationStatesContext.Provider, { value: configuration, children });
16
16
  const useConfiguration = () => {
17
17
  const statesContext = useContext(ConfigurationStatesContext);
18
18
  if (!statesContext) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport { type IntlayerConfig } from '@intlayer/config/client';\nimport {\n type FC,\n type PropsWithChildren,\n createContext,\n useContext,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nconst ConfigurationStatesContext = createContext<IntlayerConfig | undefined>(\n undefined\n);\n\nexport const useConfigurationState = () =>\n useCrossFrameState<IntlayerConfig>('INTLAYER_CONFIGURATION', undefined, {\n receive: false,\n emit: true,\n });\n\nexport type ConfigurationProviderProps = {\n configuration?: IntlayerConfig;\n};\n\nexport const ConfigurationProvider: FC<\n PropsWithChildren<ConfigurationProviderProps>\n> = ({ children, configuration }) => (\n <ConfigurationStatesContext value={configuration}>\n {children}\n </ConfigurationStatesContext>\n);\n\nexport const useConfiguration = () => {\n const statesContext = useContext(ConfigurationStatesContext);\n\n if (!statesContext) {\n throw new Error(\n 'useConfigurationStates must be used within a ConfigurationProvider'\n );\n }\n\n return statesContext;\n};\n"],"mappings":";AA4BE;AAzBF;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA0B;AAEnC,MAAM,6BAA6B;AAAA,EACjC;AACF;AAEO,MAAM,wBAAwB,MACnC,mBAAmC,0BAA0B,QAAW;AAAA,EACtE,SAAS;AAAA,EACT,MAAM;AACR,CAAC;AAMI,MAAM,wBAET,CAAC,EAAE,UAAU,cAAc,MAC7B,oBAAC,8BAA2B,OAAO,eAChC,UACH;AAGK,MAAM,mBAAmB,MAAM;AACpC,QAAM,gBAAgB,WAAW,0BAA0B;AAE3D,MAAI,CAAC,eAAe;AAClB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport { type IntlayerConfig } from '@intlayer/config/client';\nimport {\n type FC,\n type PropsWithChildren,\n createContext,\n useContext,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nconst ConfigurationStatesContext = createContext<IntlayerConfig | undefined>(\n undefined\n);\n\nexport const useConfigurationState = () =>\n useCrossFrameState<IntlayerConfig>('INTLAYER_CONFIGURATION', undefined, {\n receive: false,\n emit: true,\n });\n\nexport type ConfigurationProviderProps = {\n configuration?: IntlayerConfig;\n};\n\nexport const ConfigurationProvider: FC<\n PropsWithChildren<ConfigurationProviderProps>\n> = ({ children, configuration }) => (\n <ConfigurationStatesContext.Provider value={configuration}>\n {children}\n </ConfigurationStatesContext.Provider>\n);\n\nexport const useConfiguration = () => {\n const statesContext = useContext(ConfigurationStatesContext);\n\n if (!statesContext) {\n throw new Error(\n 'useConfigurationStates must be used within a ConfigurationProvider'\n );\n }\n\n return statesContext;\n};\n"],"mappings":";AA4BE;AAzBF;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA0B;AAEnC,MAAM,6BAA6B;AAAA,EACjC;AACF;AAEO,MAAM,wBAAwB,MACnC,mBAAmC,0BAA0B,QAAW;AAAA,EACtE,SAAS;AAAA,EACT,MAAM;AACR,CAAC;AAMI,MAAM,wBAET,CAAC,EAAE,UAAU,cAAc,MAC7B,oBAAC,2BAA2B,UAA3B,EAAoC,OAAO,eACzC,UACH;AAGK,MAAM,mBAAmB,MAAM;AACpC,QAAM,gBAAgB,WAAW,0BAA0B;AAE3D,MAAI,CAAC,eAAe;AAClB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -33,7 +33,7 @@ const DictionariesRecordProvider = ({
33
33
  }),
34
34
  [setLocaleDictionaries]
35
35
  );
36
- return /* @__PURE__ */ jsx(DictionariesRecordStatesContext, { value: stateValue, children: /* @__PURE__ */ jsx(DictionariesRecordActionsContext, { value: actionValue, children }) });
36
+ return /* @__PURE__ */ jsx(DictionariesRecordStatesContext.Provider, { value: stateValue, children: /* @__PURE__ */ jsx(DictionariesRecordActionsContext.Provider, { value: actionValue, children }) });
37
37
  };
38
38
  const useDictionariesRecordActions = () => useContext(DictionariesRecordActionsContext);
39
39
  const useDictionariesRecord = () => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport type { Dictionary } from '@intlayer/core';\nimport {\n createContext,\n useContext,\n type Dispatch,\n type SetStateAction,\n type FC,\n type PropsWithChildren,\n useMemo,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport type DictionaryContent = Record<Dictionary['key'], 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 '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 setLocaleDictionaries((dictionaries) => ({\n ...dictionaries,\n [dictionary.key]: dictionary,\n }));\n },\n }),\n [setLocaleDictionaries]\n );\n\n return (\n <DictionariesRecordStatesContext value={stateValue}>\n <DictionariesRecordActionsContext value={actionValue}>\n {children}\n </DictionariesRecordActionsContext>\n </DictionariesRecordStatesContext>\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":";AA8DM;AA3DN;AAAA,EACE;AAAA,EACA;AAAA,EAKA;AAAA,OACK;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;AAAA,IACA;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,8BAAsB,CAAC,kBAAkB;AAAA,UACvC,GAAG;AAAA,UACH,CAAC,WAAW,GAAG,GAAG;AAAA,QACpB,EAAE;AAAA,MACJ;AAAA,IACF;AAAA,IACA,CAAC,qBAAqB;AAAA,EACxB;AAEA,SACE,oBAAC,mCAAgC,OAAO,YACtC,8BAAC,oCAAiC,OAAO,aACtC,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":[]}
1
+ {"version":3,"sources":["../../src/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport type { Dictionary } from '@intlayer/core';\nimport {\n createContext,\n useContext,\n type Dispatch,\n type SetStateAction,\n type FC,\n type PropsWithChildren,\n useMemo,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport type DictionaryContent = Record<Dictionary['key'], 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 '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 setLocaleDictionaries((dictionaries) => ({\n ...dictionaries,\n [dictionary.key]: 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":";AA8DM;AA3DN;AAAA,EACE;AAAA,EACA;AAAA,EAKA;AAAA,OACK;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;AAAA,IACA;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,8BAAsB,CAAC,kBAAkB;AAAA,UACvC,GAAG;AAAA,UACH,CAAC,WAAW,GAAG,GAAG;AAAA,QACpB,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":[]}
@@ -137,13 +137,13 @@ const EditedContentProvider = ({ children }) => {
137
137
  return getContentNodeByKeyPath(currentContent, keyPath);
138
138
  };
139
139
  return /* @__PURE__ */ jsx(
140
- EditedContentStateContext,
140
+ EditedContentStateContext.Provider,
141
141
  {
142
142
  value: {
143
143
  editedContent
144
144
  },
145
145
  children: /* @__PURE__ */ jsx(
146
- EditedContentActionsContext,
146
+ EditedContentActionsContext.Provider,
147
147
  {
148
148
  value: {
149
149
  setEditedContentState,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n type Dictionary,\n type ContentNode,\n type KeyPath,\n editDictionaryByKeyPath,\n getContentNodeByKeyPath,\n renameContentNodeByKeyPath,\n} from '@intlayer/core';\nimport {\n createContext,\n useContext,\n type FC,\n type PropsWithChildren,\n} from 'react';\nimport {\n useDictionariesRecord,\n type DictionaryContent,\n} from './DictionariesRecordContext';\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\ntype EditedContentActionsContextType = {\n setEditedContentState: (\n editedContent: Record<Dictionary['key'], Dictionary>\n ) => void;\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\nexport const useEditedContentState = () =>\n useCrossFrameState<DictionaryContent>(\n 'INTLAYER_EDITED_CONTENT_CHANGED',\n undefined,\n { emit: true, receive: false }\n );\n\nexport const EditedContentProvider: FC<PropsWithChildren> = ({ children }) => {\n const { localeDictionaries } = useDictionariesRecord();\n\n const [editedContent, setEditedContentState] =\n useCrossFrameState<DictionaryContent>(\n 'INTLAYER_EDITED_CONTENT_CHANGED',\n undefined\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\n value={{\n editedContent,\n }}\n >\n <EditedContentActionsContext\n value={{\n setEditedContentState,\n setEditedContent,\n addEditedContent,\n renameEditedContent,\n removeEditedContent,\n restoreEditedContent,\n clearEditedDictionaryContent,\n clearEditedContent,\n getEditedContentValue,\n }}\n >\n {children}\n </EditedContentActionsContext>\n </EditedContentStateContext>\n );\n};\n\nexport const useEditedContentActions = () => {\n const context = useContext(EditedContentActionsContext);\n\n if (!context) {\n throw new Error(\n 'useEditedContent must be used within an EditedContentProvider'\n );\n }\n\n return context;\n};\n\nexport const useEditedContent = () => {\n const stateContext = useContext(EditedContentStateContext);\n const actionContext = useEditedContentActions();\n\n if (!stateContext) {\n throw new Error(\n 'useEditedContent must be used within an EditedContentProvider'\n );\n }\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":";AAoPM;AAlPN;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP;AAAA,EACE;AAAA,OAEK;AACP,SAAS,0BAA0B;AAMnC,MAAM,4BAA4B,cAEhC,MAAS;AAkCX,MAAM,8BAA8B,cAElC,MAAS;AAEJ,MAAM,wBAAwB,MACnC;AAAA,EACE;AAAA,EACA;AAAA,EACA,EAAE,MAAM,MAAM,SAAS,MAAM;AAC/B;AAEK,MAAM,wBAA+C,CAAC,EAAE,SAAS,MAAM;AAC5E,QAAM,EAAE,mBAAmB,IAAI,sBAAsB;AAErD,QAAM,CAAC,eAAe,qBAAqB,IACzC;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAEF,QAAM,mBAAmB,CACvB,eACA,aACG;AACH,0BAAsB,CAAC,UAAU;AAAA,MAC/B,GAAG;AAAA,MACH,CAAC,aAAa,GAAG;AAAA,QACf,GAAG,OAAO,aAAa;AAAA,QACvB,SAAS;AAAA,MACX;AAAA,IACF,EAAE;AAAA,EACJ;AAEA,QAAM,mBAAmB,CACvB,eACA,UACA,UAAqB,CAAC,GACtB,YAAqB,SAClB;AACH,0BAAsB,CAAC,SAAS;AAE9B,YAAM,kBAA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AAAA,YACA;AAAA,UACF;AAAA,UAEC;AAAA;AAAA,MACH;AAAA;AAAA,EACF;AAEJ;AAEO,MAAM,0BAA0B,MAAM;AAC3C,QAAM,UAAU,WAAW,2BAA2B;AAEtD,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEO,MAAM,mBAAmB,MAAM;AACpC,QAAM,eAAe,WAAW,yBAAyB;AACzD,QAAM,gBAAgB,wBAAwB;AAE9C,MAAI,CAAC,cAAc;AACjB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,cAAc,GAAG,cAAc;AAC7C;","names":[]}
1
+ {"version":3,"sources":["../../src/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n type Dictionary,\n type ContentNode,\n type KeyPath,\n editDictionaryByKeyPath,\n getContentNodeByKeyPath,\n renameContentNodeByKeyPath,\n} from '@intlayer/core';\nimport {\n createContext,\n useContext,\n type FC,\n type PropsWithChildren,\n} from 'react';\nimport {\n useDictionariesRecord,\n type DictionaryContent,\n} from './DictionariesRecordContext';\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\ntype EditedContentActionsContextType = {\n setEditedContentState: (\n editedContent: Record<Dictionary['key'], Dictionary>\n ) => void;\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\nexport const useEditedContentState = () =>\n useCrossFrameState<DictionaryContent>(\n 'INTLAYER_EDITED_CONTENT_CHANGED',\n undefined,\n { emit: true, receive: false }\n );\n\nexport const EditedContentProvider: FC<PropsWithChildren> = ({ children }) => {\n const { localeDictionaries } = useDictionariesRecord();\n\n const [editedContent, setEditedContentState] =\n useCrossFrameState<DictionaryContent>(\n 'INTLAYER_EDITED_CONTENT_CHANGED',\n undefined\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 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 const context = useContext(EditedContentActionsContext);\n\n if (!context) {\n throw new Error(\n 'useEditedContent must be used within an EditedContentProvider'\n );\n }\n\n return context;\n};\n\nexport const useEditedContent = () => {\n const stateContext = useContext(EditedContentStateContext);\n const actionContext = useEditedContentActions();\n\n if (!stateContext) {\n throw new Error(\n 'useEditedContent must be used within an EditedContentProvider'\n );\n }\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":";AAoPM;AAlPN;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP;AAAA,EACE;AAAA,OAEK;AACP,SAAS,0BAA0B;AAMnC,MAAM,4BAA4B,cAEhC,MAAS;AAkCX,MAAM,8BAA8B,cAElC,MAAS;AAEJ,MAAM,wBAAwB,MACnC;AAAA,EACE;AAAA,EACA;AAAA,EACA,EAAE,MAAM,MAAM,SAAS,MAAM;AAC/B;AAEK,MAAM,wBAA+C,CAAC,EAAE,SAAS,MAAM;AAC5E,QAAM,EAAE,mBAAmB,IAAI,sBAAsB;AAErD,QAAM,CAAC,eAAe,qBAAqB,IACzC;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAEF,QAAM,mBAAmB,CACvB,eACA,aACG;AACH,0BAAsB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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,UACF;AAAA,UAEC;AAAA;AAAA,MACH;AAAA;AAAA,EACF;AAEJ;AAEO,MAAM,0BAA0B,MAAM;AAC3C,QAAM,UAAU,WAAW,2BAA2B;AAEtD,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEO,MAAM,mBAAmB,MAAM;AACpC,QAAM,eAAe,WAAW,yBAAyB;AACzD,QAAM,gBAAgB,wBAAwB;AAE9C,MAAI,CAAC,cAAc;AACjB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,cAAc,GAAG,cAAc;AAC7C;","names":[]}
@@ -16,7 +16,7 @@ const EditorEnabledProvider = ({ children }) => {
16
16
  emit: false,
17
17
  receive: true
18
18
  });
19
- return /* @__PURE__ */ jsx(EditorEnabledContext, { value: { enabled: isEnabled }, children });
19
+ return /* @__PURE__ */ jsx(EditorEnabledContext.Provider, { value: { enabled: isEnabled }, children });
20
20
  };
21
21
  const useEditorEnabled = () => {
22
22
  const context = useContext(EditorEnabledContext);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/EditorEnabledContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n createContext,\n useContext,\n type FC,\n type PropsWithChildren,\n} from 'react';\nimport {\n type CrossFrameStateOptions,\n useCrossFrameState,\n} from './useCrossFrameState';\n\nexport type EditorEnabledStateProps = {\n enabled: boolean;\n};\n\nconst EditorEnabledContext = createContext<EditorEnabledStateProps | undefined>(\n undefined\n);\n\nexport const useEditorEnabledState = (options?: CrossFrameStateOptions) =>\n useCrossFrameState('INTLAYER_EDITOR_ENABLED', false, options);\n\nexport const EditorEnabledProvider: FC<PropsWithChildren> = ({ children }) => {\n const [isEnabled] = useEditorEnabledState({\n emit: false,\n receive: true,\n });\n\n return (\n <EditorEnabledContext value={{ enabled: isEnabled }}>\n {children}\n </EditorEnabledContext>\n );\n};\n\nexport const useEditorEnabled = () => {\n const context = useContext(EditorEnabledContext);\n\n if (!context) {\n throw new Error('useEditorEnabled must be used within a EnabledProvider');\n }\n return context;\n};\n"],"mappings":";AA+BI;AA7BJ;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP;AAAA,EAEE;AAAA,OACK;AAMP,MAAM,uBAAuB;AAAA,EAC3B;AACF;AAEO,MAAM,wBAAwB,CAAC,YACpC,mBAAmB,2BAA2B,OAAO,OAAO;AAEvD,MAAM,wBAA+C,CAAC,EAAE,SAAS,MAAM;AAC5E,QAAM,CAAC,SAAS,IAAI,sBAAsB;AAAA,IACxC,MAAM;AAAA,IACN,SAAS;AAAA,EACX,CAAC;AAED,SACE,oBAAC,wBAAqB,OAAO,EAAE,SAAS,UAAU,GAC/C,UACH;AAEJ;AAEO,MAAM,mBAAmB,MAAM;AACpC,QAAM,UAAU,WAAW,oBAAoB;AAE/C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,wDAAwD;AAAA,EAC1E;AACA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/EditorEnabledContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n createContext,\n useContext,\n type FC,\n type PropsWithChildren,\n} from 'react';\nimport {\n type CrossFrameStateOptions,\n useCrossFrameState,\n} from './useCrossFrameState';\n\nexport type EditorEnabledStateProps = {\n enabled: boolean;\n};\n\nconst EditorEnabledContext = createContext<EditorEnabledStateProps | undefined>(\n undefined\n);\n\nexport const useEditorEnabledState = (options?: CrossFrameStateOptions) =>\n useCrossFrameState('INTLAYER_EDITOR_ENABLED', false, options);\n\nexport const EditorEnabledProvider: FC<PropsWithChildren> = ({ children }) => {\n const [isEnabled] = useEditorEnabledState({\n emit: false,\n receive: true,\n });\n\n return (\n <EditorEnabledContext.Provider value={{ enabled: isEnabled }}>\n {children}\n </EditorEnabledContext.Provider>\n );\n};\n\nexport const useEditorEnabled = () => {\n const context = useContext(EditorEnabledContext);\n\n if (!context) {\n throw new Error('useEditorEnabled must be used within a EnabledProvider');\n }\n return context;\n};\n"],"mappings":";AA+BI;AA7BJ;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP;AAAA,EAEE;AAAA,OACK;AAMP,MAAM,uBAAuB;AAAA,EAC3B;AACF;AAEO,MAAM,wBAAwB,CAAC,YACpC,mBAAmB,2BAA2B,OAAO,OAAO;AAEvD,MAAM,wBAA+C,CAAC,EAAE,SAAS,MAAM;AAC5E,QAAM,CAAC,SAAS,IAAI,sBAAsB;AAAA,IACxC,MAAM;AAAA,IACN,SAAS;AAAA,EACX,CAAC;AAED,SACE,oBAAC,qBAAqB,UAArB,EAA8B,OAAO,EAAE,SAAS,UAAU,GACxD,UACH;AAEJ;AAEO,MAAM,mBAAmB,MAAM;AACpC,QAAM,UAAU,WAAW,oBAAoB;AAE/C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,wDAAwD;AAAA,EAC1E;AACA,SAAO;AACT;","names":[]}
@@ -22,8 +22,8 @@ const FocusDictionaryProvider = ({
22
22
  return { ...prev, keyPath };
23
23
  });
24
24
  };
25
- return /* @__PURE__ */ jsx(FocusDictionaryStateContext, { value: { focusedContent }, children: /* @__PURE__ */ jsx(
26
- FocusDictionaryActionsContext,
25
+ return /* @__PURE__ */ jsx(FocusDictionaryStateContext.Provider, { value: { focusedContent }, children: /* @__PURE__ */ jsx(
26
+ FocusDictionaryActionsContext.Provider,
27
27
  {
28
28
  value: { setFocusedContent, setFocusedContentKeyPath },
29
29
  children
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport type { KeyPath } from '@intlayer/core';\nimport {\n createContext,\n useContext,\n type FC,\n type PropsWithChildren,\n type Dispatch,\n type SetStateAction,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\ntype DictionaryPath = string;\n\nexport type FileContent = {\n dictionaryKey: string;\n keyPath?: KeyPath[];\n dictionaryPath?: DictionaryPath;\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 '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 value={{ focusedContent }}>\n <FocusDictionaryActionsContext\n value={{ setFocusedContent, setFocusedContentKeyPath }}\n >\n {children}\n </FocusDictionaryActionsContext>\n </FocusDictionaryStateContext>\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":";AAyDM;AAtDN;AAAA,EACE;AAAA,EACA;AAAA,OAKK;AACP,SAAS,0BAA0B;AAmBnC,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;AAAA,IACA;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,+BAA4B,OAAO,EAAE,eAAe,GACnD;AAAA,IAAC;AAAA;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
+ {"version":3,"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport type { KeyPath } from '@intlayer/core';\nimport {\n createContext,\n useContext,\n type FC,\n type PropsWithChildren,\n type Dispatch,\n type SetStateAction,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\ntype DictionaryPath = string;\n\nexport type FileContent = {\n dictionaryKey: string;\n keyPath?: KeyPath[];\n dictionaryPath?: DictionaryPath;\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 '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":";AAyDM;AAtDN;AAAA,EACE;AAAA,EACA;AAAA,OAKK;AACP,SAAS,0BAA0B;AAmBnC,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;AAAA,IACA;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 +1 @@
1
- {"version":3,"file":"CommunicatorContext.d.ts","sourceRoot":"","sources":["../../src/CommunicatorContext.tsx"],"names":[],"mappings":"AAGA,OAAO,EAKL,KAAK,EAAE,EACP,KAAK,iBAAiB,EACvB,MAAM,OAAO,CAAC;AAGf,MAAM,MAAM,0BAA0B,GAAG;IACvC,WAAW,EAAE,OAAO,MAAM,CAAC,WAAW,CAAC;IACvC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAUF,MAAM,MAAM,yBAAyB,GAAG,iBAAiB,CACvD,IAAI,CAAC,0BAA0B,EAAE,UAAU,CAAC,CAC7C,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,EAAE,CAAC,yBAAyB,CAc9D,CAAC;AAEF,eAAO,MAAM,eAAe,kCAAwC,CAAC"}
1
+ {"version":3,"file":"CommunicatorContext.d.ts","sourceRoot":"","sources":["../../src/CommunicatorContext.tsx"],"names":[],"mappings":"AAGA,OAAO,EAKL,KAAK,EAAE,EACP,KAAK,iBAAiB,EACvB,MAAM,OAAO,CAAC;AAGf,MAAM,MAAM,0BAA0B,GAAG;IACvC,WAAW,EAAE,OAAO,MAAM,CAAC,WAAW,CAAC;IACvC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAUF,MAAM,MAAM,yBAAyB,GAAG,iBAAiB,CACvD,IAAI,CAAC,0BAA0B,EAAE,UAAU,CAAC,CAC7C,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,EAAE,CAAC,yBAAyB,CAkB9D,CAAC;AAEF,eAAO,MAAM,eAAe,kCAAwC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/editor-react",
3
- "version": "5.1.1",
3
+ "version": "5.1.2",
4
4
  "private": false,
5
5
  "description": "Provides the states, contexts, hooks and components to interact with the Intlayer editor for a React application",
6
6
  "keywords": [
@@ -52,9 +52,9 @@
52
52
  ],
53
53
  "dependencies": {
54
54
  "uuid": "^11.0.5",
55
- "@intlayer/config": "^5.1.1",
56
- "@intlayer/core": "5.1.1",
57
- "@intlayer/editor": "5.1.1"
55
+ "@intlayer/config": "5.1.2",
56
+ "@intlayer/core": "5.1.2",
57
+ "@intlayer/editor": "5.1.2"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@types/node": "^22.10.6",
@@ -70,15 +70,15 @@
70
70
  "typescript": "^5.7.3",
71
71
  "@utils/eslint-config": "1.0.4",
72
72
  "@utils/ts-config": "1.0.4",
73
- "@utils/ts-config-types": "1.0.4",
74
- "@utils/tsup-config": "1.0.4"
73
+ "@utils/tsup-config": "1.0.4",
74
+ "@utils/ts-config-types": "1.0.4"
75
75
  },
76
76
  "peerDependencies": {
77
77
  "react": ">=16.0.0",
78
78
  "react-dom": ">=16.0.0",
79
- "@intlayer/config": "5.1.1",
80
- "@intlayer/core": "^5.1.1",
81
- "@intlayer/editor": "5.1.1"
79
+ "@intlayer/config": "5.1.2",
80
+ "@intlayer/core": "5.1.2",
81
+ "@intlayer/editor": "5.1.2"
82
82
  },
83
83
  "engines": {
84
84
  "node": ">=14.18"