@intlayer/editor-react 6.1.6-canary.0 → 7.0.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/CommunicatorContext.cjs +43 -65
- package/dist/cjs/CommunicatorContext.cjs.map +1 -1
- package/dist/cjs/ConfigurationContext.cjs +26 -47
- package/dist/cjs/ConfigurationContext.cjs.map +1 -1
- package/dist/cjs/DictionariesRecordContext.cjs +48 -74
- package/dist/cjs/DictionariesRecordContext.cjs.map +1 -1
- package/dist/cjs/EditedContentContext.cjs +164 -225
- package/dist/cjs/EditedContentContext.cjs.map +1 -1
- package/dist/cjs/EditorEnabledContext.cjs +34 -59
- package/dist/cjs/EditorEnabledContext.cjs.map +1 -1
- package/dist/cjs/EditorProvider.cjs +65 -66
- package/dist/cjs/EditorProvider.cjs.map +1 -1
- package/dist/cjs/FocusDictionaryContext.cjs +51 -75
- package/dist/cjs/FocusDictionaryContext.cjs.map +1 -1
- package/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/cjs/index.cjs +46 -44
- package/dist/cjs/useCrossFrameMessageListener.cjs +73 -50
- package/dist/cjs/useCrossFrameMessageListener.cjs.map +1 -1
- package/dist/cjs/useCrossFrameState.cjs +106 -73
- package/dist/cjs/useCrossFrameState.cjs.map +1 -1
- package/dist/cjs/useCrossURLPathState.cjs +67 -66
- package/dist/cjs/useCrossURLPathState.cjs.map +1 -1
- package/dist/cjs/useIframeClickInterceptor.cjs +24 -47
- package/dist/cjs/useIframeClickInterceptor.cjs.map +1 -1
- package/dist/esm/CommunicatorContext.mjs +34 -32
- package/dist/esm/CommunicatorContext.mjs.map +1 -1
- package/dist/esm/ConfigurationContext.mjs +19 -23
- package/dist/esm/ConfigurationContext.mjs.map +1 -1
- package/dist/esm/DictionariesRecordContext.mjs +37 -47
- package/dist/esm/DictionariesRecordContext.mjs.map +1 -1
- package/dist/esm/EditedContentContext.mjs +150 -201
- package/dist/esm/EditedContentContext.mjs.map +1 -1
- package/dist/esm/EditorEnabledContext.mjs +22 -32
- package/dist/esm/EditorEnabledContext.mjs.map +1 -1
- package/dist/esm/EditorProvider.mjs +60 -54
- package/dist/esm/EditorProvider.mjs.map +1 -1
- package/dist/esm/FocusDictionaryContext.mjs +41 -48
- package/dist/esm/FocusDictionaryContext.mjs.map +1 -1
- package/dist/esm/index.mjs +15 -13
- package/dist/esm/useCrossFrameMessageListener.mjs +69 -25
- package/dist/esm/useCrossFrameMessageListener.mjs.map +1 -1
- package/dist/esm/useCrossFrameState.mjs +102 -47
- package/dist/esm/useCrossFrameState.mjs.map +1 -1
- package/dist/esm/useCrossURLPathState.mjs +61 -41
- package/dist/esm/useCrossURLPathState.mjs.map +1 -1
- package/dist/esm/useIframeClickInterceptor.mjs +19 -21
- package/dist/esm/useIframeClickInterceptor.mjs.map +1 -1
- package/dist/types/CommunicatorContext.d.ts +12 -8
- package/dist/types/CommunicatorContext.d.ts.map +1 -1
- package/dist/types/ConfigurationContext.d.ts +12 -7
- package/dist/types/ConfigurationContext.d.ts.map +1 -1
- package/dist/types/DictionariesRecordContext.d.ts +15 -12
- package/dist/types/DictionariesRecordContext.d.ts.map +1 -1
- package/dist/types/EditedContentContext.d.ts +33 -30
- package/dist/types/EditedContentContext.d.ts.map +1 -1
- package/dist/types/EditorEnabledContext.d.ts +14 -9
- package/dist/types/EditorEnabledContext.d.ts.map +1 -1
- package/dist/types/EditorProvider.d.ts +10 -6
- package/dist/types/EditorProvider.d.ts.map +1 -1
- package/dist/types/FocusDictionaryContext.d.ts +18 -15
- package/dist/types/FocusDictionaryContext.d.ts.map +1 -1
- package/dist/types/index.d.ts +13 -13
- package/dist/types/useCrossFrameMessageListener.d.ts +7 -2
- package/dist/types/useCrossFrameMessageListener.d.ts.map +1 -1
- package/dist/types/useCrossFrameState.d.ts +10 -6
- package/dist/types/useCrossFrameState.d.ts.map +1 -1
- package/dist/types/useCrossURLPathState.d.ts +8 -3
- package/dist/types/useCrossURLPathState.d.ts.map +1 -1
- package/dist/types/useIframeClickInterceptor.d.ts +5 -2
- package/dist/types/useIframeClickInterceptor.d.ts.map +1 -1
- package/package.json +34 -40
- package/LICENSE +0 -202
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
|
@@ -1,68 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
var CommunicatorContext_exports = {};
|
|
31
|
-
__export(CommunicatorContext_exports, {
|
|
32
|
-
CommunicatorProvider: () => CommunicatorProvider,
|
|
33
|
-
useCommunicator: () => useCommunicator
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
5
|
+
let __intlayer_config_built = require("@intlayer/config/built");
|
|
6
|
+
__intlayer_config_built = require_rolldown_runtime.__toESM(__intlayer_config_built);
|
|
7
|
+
let react = require("react");
|
|
8
|
+
react = require_rolldown_runtime.__toESM(react);
|
|
9
|
+
let uuid = require("uuid");
|
|
10
|
+
uuid = require_rolldown_runtime.__toESM(uuid);
|
|
11
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
12
|
+
react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
|
|
13
|
+
|
|
14
|
+
//#region src/CommunicatorContext.tsx
|
|
15
|
+
const { editor } = __intlayer_config_built.default ?? {};
|
|
16
|
+
const CommunicatorContext = (0, react.createContext)({
|
|
17
|
+
postMessage: () => null,
|
|
18
|
+
allowedOrigins: [
|
|
19
|
+
editor?.applicationURL,
|
|
20
|
+
editor?.editorURL,
|
|
21
|
+
editor?.cmsURL
|
|
22
|
+
],
|
|
23
|
+
senderId: ""
|
|
34
24
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
const CommunicatorProvider = ({
|
|
51
|
-
children,
|
|
52
|
-
allowedOrigins,
|
|
53
|
-
postMessage
|
|
54
|
-
}) => {
|
|
55
|
-
const senderIdRef = (0, import_react.useRef)((0, import_uuid.v4)());
|
|
56
|
-
const value = (0, import_react.useMemo)(
|
|
57
|
-
() => ({ postMessage, allowedOrigins, senderId: senderIdRef.current }),
|
|
58
|
-
[postMessage, allowedOrigins, senderIdRef.current]
|
|
59
|
-
);
|
|
60
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CommunicatorContext.Provider, { value, children });
|
|
25
|
+
const CommunicatorProvider = ({ children, allowedOrigins, postMessage }) => {
|
|
26
|
+
const senderIdRef = (0, react.useRef)((0, uuid.v4)());
|
|
27
|
+
const value = (0, react.useMemo)(() => ({
|
|
28
|
+
postMessage,
|
|
29
|
+
allowedOrigins,
|
|
30
|
+
senderId: senderIdRef.current
|
|
31
|
+
}), [
|
|
32
|
+
postMessage,
|
|
33
|
+
allowedOrigins,
|
|
34
|
+
senderIdRef.current
|
|
35
|
+
]);
|
|
36
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CommunicatorContext.Provider, {
|
|
37
|
+
value,
|
|
38
|
+
children
|
|
39
|
+
});
|
|
61
40
|
};
|
|
62
|
-
const useCommunicator = () => (0,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
});
|
|
41
|
+
const useCommunicator = () => (0, react.useContext)(CommunicatorContext);
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
exports.CommunicatorProvider = CommunicatorProvider;
|
|
45
|
+
exports.useCommunicator = useCommunicator;
|
|
68
46
|
//# sourceMappingURL=CommunicatorContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\
|
|
1
|
+
{"version":3,"file":"CommunicatorContext.cjs","names":["configuration","CommunicatorProvider: FC<CommunicatorProviderProps>"],"sources":["../../src/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n useMemo,\n useRef,\n} from 'react';\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 } = configuration ?? {};\n\nconst CommunicatorContext = createContext<UseCrossPlatformStateProps>({\n postMessage: () => null,\n allowedOrigins: [\n editor?.applicationURL,\n editor?.editorURL,\n editor?.cmsURL,\n ] as string[],\n senderId: '',\n});\n\nexport type CommunicatorProviderProps = PropsWithChildren<\n Omit<UseCrossPlatformStateProps, 'senderId'>\n>;\n\nexport const CommunicatorProvider: FC<CommunicatorProviderProps> = ({\n children,\n allowedOrigins,\n postMessage,\n}) => {\n // Create a stable, unique ID for the lifetime of this app/iframe instance.\n const senderIdRef = useRef(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":";;;;;;;;;;;;;;AAmBA,MAAM,EAAE,WAAWA,mCAAiB,EAAE;AAEtC,MAAM,+CAAgE;CACpE,mBAAmB;CACnB,gBAAgB;EACd,QAAQ;EACR,QAAQ;EACR,QAAQ;EACT;CACD,UAAU;CACX,CAAC;AAMF,MAAaC,wBAAuD,EAClE,UACA,gBACA,kBACI;CAEJ,MAAM,8CAA2B,CAAC;CAElC,MAAM,kCACG;EAAE;EAAa;EAAgB,UAAU,YAAY;EAAS,GACrE;EAAC;EAAa;EAAgB,YAAY;EAAQ,CACnD;AAED,QACE,2CAAC,oBAAoB;EAAgB;EAClC;GAC4B;;AAInC,MAAa,8CAAmC,oBAAoB"}
|
|
@@ -1,50 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var ConfigurationContext_exports = {};
|
|
21
|
-
__export(ConfigurationContext_exports, {
|
|
22
|
-
ConfigurationProvider: () => ConfigurationProvider,
|
|
23
|
-
useConfiguration: () => useConfiguration,
|
|
24
|
-
useConfigurationState: () => useConfigurationState
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
5
|
+
const require_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
6
|
+
let react = require("react");
|
|
7
|
+
react = require_rolldown_runtime.__toESM(react);
|
|
8
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
|
+
react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
|
|
10
|
+
let __intlayer_editor = require("@intlayer/editor");
|
|
11
|
+
__intlayer_editor = require_rolldown_runtime.__toESM(__intlayer_editor);
|
|
12
|
+
|
|
13
|
+
//#region src/ConfigurationContext.tsx
|
|
14
|
+
const ConfigurationStatesContext = (0, react.createContext)(void 0);
|
|
15
|
+
const useConfigurationState = () => require_useCrossFrameState.useCrossFrameState(__intlayer_editor.MessageKey.INTLAYER_CONFIGURATION, void 0, {
|
|
16
|
+
receive: false,
|
|
17
|
+
emit: true
|
|
25
18
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var import_react = require("react");
|
|
30
|
-
var import_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
31
|
-
const ConfigurationStatesContext = (0, import_react.createContext)(
|
|
32
|
-
void 0
|
|
33
|
-
);
|
|
34
|
-
const useConfigurationState = () => (0, import_useCrossFrameState.useCrossFrameState)(
|
|
35
|
-
import_editor.MessageKey.INTLAYER_CONFIGURATION,
|
|
36
|
-
void 0,
|
|
37
|
-
{
|
|
38
|
-
receive: false,
|
|
39
|
-
emit: true
|
|
40
|
-
}
|
|
41
|
-
);
|
|
42
|
-
const ConfigurationProvider = ({ children, configuration }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ConfigurationStatesContext.Provider, { value: configuration, children });
|
|
43
|
-
const useConfiguration = () => (0, import_react.useContext)(ConfigurationStatesContext);
|
|
44
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
-
0 && (module.exports = {
|
|
46
|
-
ConfigurationProvider,
|
|
47
|
-
useConfiguration,
|
|
48
|
-
useConfigurationState
|
|
19
|
+
const ConfigurationProvider = ({ children, configuration }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ConfigurationStatesContext.Provider, {
|
|
20
|
+
value: configuration,
|
|
21
|
+
children
|
|
49
22
|
});
|
|
23
|
+
const useConfiguration = () => (0, react.useContext)(ConfigurationStatesContext);
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.ConfigurationProvider = ConfigurationProvider;
|
|
27
|
+
exports.useConfiguration = useConfiguration;
|
|
28
|
+
exports.useConfigurationState = useConfigurationState;
|
|
50
29
|
//# sourceMappingURL=ConfigurationContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"file":"ConfigurationContext.cjs","names":["useCrossFrameState","MessageKey","ConfigurationProvider: FC<\n PropsWithChildren<ConfigurationProviderProps>\n>"],"sources":["../../src/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nconst ConfigurationStatesContext = createContext<IntlayerConfig | undefined>(\n undefined\n);\n\nexport const useConfigurationState = () =>\n useCrossFrameState<IntlayerConfig>(\n MessageKey.INTLAYER_CONFIGURATION,\n undefined,\n {\n receive: false,\n emit: true,\n }\n );\n\nexport type ConfigurationProviderProps = {\n configuration?: IntlayerConfig;\n};\n\nexport const ConfigurationProvider: FC<\n PropsWithChildren<ConfigurationProviderProps>\n> = ({ children, configuration }) => (\n <ConfigurationStatesContext.Provider value={configuration}>\n {children}\n </ConfigurationStatesContext.Provider>\n);\n\nexport const useConfiguration = () => useContext(ConfigurationStatesContext);\n"],"mappings":";;;;;;;;;;;;;AAYA,MAAM,sDACJ,OACD;AAED,MAAa,8BACXA,8CACEC,6BAAW,wBACX,QACA;CACE,SAAS;CACT,MAAM;CACP,CACF;AAMH,MAAaC,yBAER,EAAE,UAAU,oBACf,2CAAC,2BAA2B;CAAS,OAAO;CACzC;EACmC;AAGxC,MAAa,+CAAoC,2BAA2B"}
|
|
@@ -1,78 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
5
|
+
const require_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
6
|
+
let react = require("react");
|
|
7
|
+
react = require_rolldown_runtime.__toESM(react);
|
|
8
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
|
+
react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
|
|
10
|
+
let __intlayer_editor = require("@intlayer/editor");
|
|
11
|
+
__intlayer_editor = require_rolldown_runtime.__toESM(__intlayer_editor);
|
|
12
|
+
|
|
13
|
+
//#region src/DictionariesRecordContext.tsx
|
|
14
|
+
const DictionariesRecordStatesContext = (0, react.createContext)(void 0);
|
|
15
|
+
const DictionariesRecordActionsContext = (0, react.createContext)(void 0);
|
|
16
|
+
const DictionariesRecordProvider = ({ children }) => {
|
|
17
|
+
const [localeDictionaries, setLocaleDictionaries] = require_useCrossFrameState.useCrossFrameState(__intlayer_editor.MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED, void 0);
|
|
18
|
+
const stateValue = (0, react.useMemo)(() => ({ localeDictionaries: localeDictionaries ?? {} }), [localeDictionaries]);
|
|
19
|
+
const actionValue = (0, react.useMemo)(() => ({
|
|
20
|
+
setLocaleDictionaries,
|
|
21
|
+
setLocaleDictionary: (dictionary) => {
|
|
22
|
+
if (!dictionary.localId) return;
|
|
23
|
+
setLocaleDictionaries((dictionaries) => ({
|
|
24
|
+
...dictionaries,
|
|
25
|
+
[dictionary.localId]: dictionary
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
}), [setLocaleDictionaries]);
|
|
29
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DictionariesRecordStatesContext.Provider, {
|
|
30
|
+
value: stateValue,
|
|
31
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DictionariesRecordActionsContext.Provider, {
|
|
32
|
+
value: actionValue,
|
|
33
|
+
children
|
|
34
|
+
})
|
|
35
|
+
});
|
|
10
36
|
};
|
|
11
|
-
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var DictionariesRecordContext_exports = {};
|
|
21
|
-
__export(DictionariesRecordContext_exports, {
|
|
22
|
-
DictionariesRecordProvider: () => DictionariesRecordProvider,
|
|
23
|
-
useDictionariesRecord: () => useDictionariesRecord,
|
|
24
|
-
useDictionariesRecordActions: () => useDictionariesRecordActions
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(DictionariesRecordContext_exports);
|
|
27
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
28
|
-
var import_editor = require("@intlayer/editor");
|
|
29
|
-
var import_react = require("react");
|
|
30
|
-
var import_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
31
|
-
const DictionariesRecordStatesContext = (0, import_react.createContext)(void 0);
|
|
32
|
-
const DictionariesRecordActionsContext = (0, import_react.createContext)(void 0);
|
|
33
|
-
const DictionariesRecordProvider = ({
|
|
34
|
-
children
|
|
35
|
-
}) => {
|
|
36
|
-
const [localeDictionaries, setLocaleDictionaries] = (0, import_useCrossFrameState.useCrossFrameState)(
|
|
37
|
-
import_editor.MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED,
|
|
38
|
-
void 0
|
|
39
|
-
);
|
|
40
|
-
const stateValue = (0, import_react.useMemo)(
|
|
41
|
-
() => ({
|
|
42
|
-
localeDictionaries: localeDictionaries ?? {}
|
|
43
|
-
}),
|
|
44
|
-
[localeDictionaries]
|
|
45
|
-
);
|
|
46
|
-
const actionValue = (0, import_react.useMemo)(
|
|
47
|
-
() => ({
|
|
48
|
-
setLocaleDictionaries,
|
|
49
|
-
setLocaleDictionary: (dictionary) => {
|
|
50
|
-
if (!dictionary.localId) return;
|
|
51
|
-
setLocaleDictionaries((dictionaries) => ({
|
|
52
|
-
...dictionaries,
|
|
53
|
-
[dictionary.localId]: dictionary
|
|
54
|
-
}));
|
|
55
|
-
}
|
|
56
|
-
}),
|
|
57
|
-
[setLocaleDictionaries]
|
|
58
|
-
);
|
|
59
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DictionariesRecordStatesContext.Provider, { value: stateValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DictionariesRecordActionsContext.Provider, { value: actionValue, children }) });
|
|
60
|
-
};
|
|
61
|
-
const useDictionariesRecordActions = () => (0, import_react.useContext)(DictionariesRecordActionsContext);
|
|
37
|
+
const useDictionariesRecordActions = () => (0, react.useContext)(DictionariesRecordActionsContext);
|
|
62
38
|
const useDictionariesRecord = () => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return { ...statesContext, ...actionsContext };
|
|
39
|
+
const actionsContext = useDictionariesRecordActions();
|
|
40
|
+
const statesContext = (0, react.useContext)(DictionariesRecordStatesContext);
|
|
41
|
+
if (!statesContext) throw new Error("useDictionariesRecordStates must be used within a DictionariesRecordProvider");
|
|
42
|
+
return {
|
|
43
|
+
...statesContext,
|
|
44
|
+
...actionsContext
|
|
45
|
+
};
|
|
71
46
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
});
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
exports.DictionariesRecordProvider = DictionariesRecordProvider;
|
|
50
|
+
exports.useDictionariesRecord = useDictionariesRecord;
|
|
51
|
+
exports.useDictionariesRecordActions = useDictionariesRecordActions;
|
|
78
52
|
//# sourceMappingURL=DictionariesRecordContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport
|
|
1
|
+
{"version":3,"file":"DictionariesRecordContext.cjs","names":["DictionariesRecordProvider: FC<PropsWithChildren>","useCrossFrameState","MessageKey"],"sources":["../../src/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { Dictionary, LocalDictionaryId } from '@intlayer/types';\nimport {\n createContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n useContext,\n useMemo,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport type DictionaryContent = Record<LocalDictionaryId, Dictionary>;\n\ntype DictionariesRecordStatesContextType = {\n localeDictionaries: DictionaryContent;\n};\ntype DictionariesRecordActionsContextType = {\n setLocaleDictionaries: Dispatch<SetStateAction<DictionaryContent>>;\n setLocaleDictionary: (dictionary: Dictionary) => void;\n};\n\nconst DictionariesRecordStatesContext = createContext<\n DictionariesRecordStatesContextType | undefined\n>(undefined);\nconst DictionariesRecordActionsContext = createContext<\n DictionariesRecordActionsContextType | undefined\n>(undefined);\n\nexport const DictionariesRecordProvider: FC<PropsWithChildren> = ({\n children,\n}) => {\n const [localeDictionaries, setLocaleDictionaries] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED,\n undefined\n );\n\n const stateValue = useMemo(\n () => ({\n localeDictionaries: localeDictionaries ?? {},\n }),\n [localeDictionaries]\n );\n\n const actionValue = useMemo(\n () => ({\n setLocaleDictionaries,\n setLocaleDictionary: (dictionary: Dictionary) => {\n if (!dictionary.localId) return;\n\n setLocaleDictionaries((dictionaries) => ({\n ...dictionaries,\n [dictionary.localId as LocalDictionaryId]: dictionary,\n }));\n },\n }),\n [setLocaleDictionaries]\n );\n\n return (\n <DictionariesRecordStatesContext.Provider value={stateValue}>\n <DictionariesRecordActionsContext.Provider value={actionValue}>\n {children}\n </DictionariesRecordActionsContext.Provider>\n </DictionariesRecordStatesContext.Provider>\n );\n};\n\nexport const useDictionariesRecordActions = () =>\n useContext(DictionariesRecordActionsContext);\n\nexport const useDictionariesRecord = () => {\n const actionsContext = useDictionariesRecordActions();\n const statesContext = useContext(DictionariesRecordStatesContext);\n\n if (!statesContext) {\n throw new Error(\n 'useDictionariesRecordStates must be used within a DictionariesRecordProvider'\n );\n }\n\n return { ...statesContext, ...actionsContext };\n};\n"],"mappings":";;;;;;;;;;;;;AAyBA,MAAM,2DAEJ,OAAU;AACZ,MAAM,4DAEJ,OAAU;AAEZ,MAAaA,8BAAqD,EAChE,eACI;CACJ,MAAM,CAAC,oBAAoB,yBACzBC,8CACEC,6BAAW,sCACX,OACD;CAEH,MAAM,uCACG,EACL,oBAAoB,sBAAsB,EAAE,EAC7C,GACD,CAAC,mBAAmB,CACrB;CAED,MAAM,wCACG;EACL;EACA,sBAAsB,eAA2B;AAC/C,OAAI,CAAC,WAAW,QAAS;AAEzB,0BAAuB,kBAAkB;IACvC,GAAG;KACF,WAAW,UAA+B;IAC5C,EAAE;;EAEN,GACD,CAAC,sBAAsB,CACxB;AAED,QACE,2CAAC,gCAAgC;EAAS,OAAO;YAC/C,2CAAC,iCAAiC;GAAS,OAAO;GAC/C;IACyC;GACH;;AAI/C,MAAa,2DACA,iCAAiC;AAE9C,MAAa,8BAA8B;CACzC,MAAM,iBAAiB,8BAA8B;CACrD,MAAM,sCAA2B,gCAAgC;AAEjE,KAAI,CAAC,cACH,OAAM,IAAI,MACR,+EACD;AAGH,QAAO;EAAE,GAAG;EAAe,GAAG;EAAgB"}
|