@intlayer/editor-react 4.0.3
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/LICENSE +202 -0
- package/README.md +18 -0
- package/dist/cjs/CommunicatorContext.cjs +43 -0
- package/dist/cjs/CommunicatorContext.cjs.map +1 -0
- package/dist/cjs/DictionariesRecordContext.cjs +61 -0
- package/dist/cjs/DictionariesRecordContext.cjs.map +1 -0
- package/dist/cjs/EditedContentContext.cjs +193 -0
- package/dist/cjs/EditedContentContext.cjs.map +1 -0
- package/dist/cjs/EditorProvider.cjs +34 -0
- package/dist/cjs/EditorProvider.cjs.map +1 -0
- package/dist/cjs/FocusDictionaryContext.cjs +79 -0
- package/dist/cjs/FocusDictionaryContext.cjs.map +1 -0
- package/dist/cjs/index.cjs +31 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/useCrossFrameState.cjs +66 -0
- package/dist/cjs/useCrossFrameState.cjs.map +1 -0
- package/dist/esm/CommunicatorContext.mjs +18 -0
- package/dist/esm/CommunicatorContext.mjs.map +1 -0
- package/dist/esm/DictionariesRecordContext.mjs +36 -0
- package/dist/esm/DictionariesRecordContext.mjs.map +1 -0
- package/dist/esm/EditedContentContext.mjs +173 -0
- package/dist/esm/EditedContentContext.mjs.map +1 -0
- package/dist/esm/EditorProvider.mjs +12 -0
- package/dist/esm/EditorProvider.mjs.map +1 -0
- package/dist/esm/FocusDictionaryContext.mjs +53 -0
- package/dist/esm/FocusDictionaryContext.mjs.map +1 -0
- package/dist/esm/index.mjs +6 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/useCrossFrameState.mjs +44 -0
- package/dist/esm/useCrossFrameState.mjs.map +1 -0
- package/dist/types/CommunicatorContext.d.ts +9 -0
- package/dist/types/CommunicatorContext.d.ts.map +1 -0
- package/dist/types/DictionariesRecordContext.d.ts +11 -0
- package/dist/types/DictionariesRecordContext.d.ts.map +1 -0
- package/dist/types/EditedContentContext.d.ts +28 -0
- package/dist/types/EditedContentContext.d.ts.map +1 -0
- package/dist/types/EditorProvider.d.ts +4 -0
- package/dist/types/EditorProvider.d.ts.map +1 -0
- package/dist/types/FocusDictionaryContext.d.ts +21 -0
- package/dist/types/FocusDictionaryContext.d.ts.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/useCrossFrameState.d.ts +3 -0
- package/dist/types/useCrossFrameState.d.ts.map +1 -0
- package/package.json +102 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var FocusDictionaryContext_exports = {};
|
|
20
|
+
__export(FocusDictionaryContext_exports, {
|
|
21
|
+
FocusDictionaryProvider: () => FocusDictionaryProvider,
|
|
22
|
+
useFocusDictionary: () => useFocusDictionary,
|
|
23
|
+
useFocusDictionaryActions: () => useFocusDictionaryActions
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(FocusDictionaryContext_exports);
|
|
26
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
27
|
+
var import_react = require("react");
|
|
28
|
+
var import_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
29
|
+
const FocusDictionaryStateContext = (0, import_react.createContext)(void 0);
|
|
30
|
+
const FocusDictionaryActionsContext = (0, import_react.createContext)(void 0);
|
|
31
|
+
const FocusDictionaryProvider = ({
|
|
32
|
+
children
|
|
33
|
+
}) => {
|
|
34
|
+
const [focusedContent, setFocusedContentState] = (0, import_useCrossFrameState.useCrossFrameState)("FOCUSED_CONTENT_CHANGED", null);
|
|
35
|
+
const setFocusedContent = (content) => {
|
|
36
|
+
setFocusedContentState(content);
|
|
37
|
+
};
|
|
38
|
+
const setFocusedContentKeyPath = (keyPath) => {
|
|
39
|
+
setFocusedContentState((prev) => {
|
|
40
|
+
if (!prev) {
|
|
41
|
+
return prev;
|
|
42
|
+
}
|
|
43
|
+
return { ...prev, keyPath };
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FocusDictionaryStateContext.Provider, { value: { focusedContent }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
47
|
+
FocusDictionaryActionsContext.Provider,
|
|
48
|
+
{
|
|
49
|
+
value: { setFocusedContent, setFocusedContentKeyPath },
|
|
50
|
+
children
|
|
51
|
+
}
|
|
52
|
+
) });
|
|
53
|
+
};
|
|
54
|
+
const useFocusDictionaryActions = () => {
|
|
55
|
+
const context = (0, import_react.useContext)(FocusDictionaryActionsContext);
|
|
56
|
+
if (context === void 0) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
"useFocusDictionaryActions must be used within a FocusDictionaryProvider"
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
return context;
|
|
62
|
+
};
|
|
63
|
+
const useFocusDictionary = () => {
|
|
64
|
+
const actionContext = useFocusDictionaryActions();
|
|
65
|
+
const stateContext = (0, import_react.useContext)(FocusDictionaryStateContext);
|
|
66
|
+
if (stateContext === void 0) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
"useFocusDictionaryState must be used within a FocusDictionaryProvider"
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return { ...stateContext, ...actionContext };
|
|
72
|
+
};
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
FocusDictionaryProvider,
|
|
76
|
+
useFocusDictionary,
|
|
77
|
+
useFocusDictionaryActions
|
|
78
|
+
});
|
|
79
|
+
//# sourceMappingURL=FocusDictionaryContext.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["import type { KeyPath } from '@intlayer/core';\nimport { createContext, useContext, FC, PropsWithChildren } 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\ninterface FocusDictionaryState {\n focusedContent: FileContent | null;\n}\n\ninterface FocusDictionaryActions {\n setFocusedContent: (content: FileContent | null) => void;\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, setFocusedContentState] =\n useCrossFrameState<FileContent | null>('FOCUSED_CONTENT_CHANGED', null);\n\n const setFocusedContent = (content: FileContent | null) => {\n setFocusedContentState(content);\n };\n\n const setFocusedContentKeyPath = (keyPath: KeyPath[]) => {\n setFocusedContentState((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;AAiDM;AAhDN,mBAAiE;AACjE,gCAAmC;AAmBnC,MAAM,kCAA8B,4BAElC,MAAS;AACX,MAAM,oCAAgC,4BAEpC,MAAS;AAEJ,MAAM,0BAAiD,CAAC;AAAA,EAC7D;AACF,MAAM;AACJ,QAAM,CAAC,gBAAgB,sBAAsB,QAC3C,8CAAuC,2BAA2B,IAAI;AAExE,QAAM,oBAAoB,CAAC,YAAgC;AACzD,2BAAuB,OAAO;AAAA,EAChC;AAEA,QAAM,2BAA2B,CAAC,YAAuB;AACvD,2BAAuB,CAAC,SAAS;AAC/B,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":[]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var index_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(index_exports);
|
|
18
|
+
__reExport(index_exports, require('./DictionariesRecordContext.cjs'), module.exports);
|
|
19
|
+
__reExport(index_exports, require('./EditedContentContext.cjs'), module.exports);
|
|
20
|
+
__reExport(index_exports, require('./FocusDictionaryContext.cjs'), module.exports);
|
|
21
|
+
__reExport(index_exports, require('./EditorProvider.cjs'), module.exports);
|
|
22
|
+
__reExport(index_exports, require('./useCrossFrameState.cjs'), module.exports);
|
|
23
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
24
|
+
0 && (module.exports = {
|
|
25
|
+
...require('./DictionariesRecordContext.cjs'),
|
|
26
|
+
...require('./EditedContentContext.cjs'),
|
|
27
|
+
...require('./FocusDictionaryContext.cjs'),
|
|
28
|
+
...require('./EditorProvider.cjs'),
|
|
29
|
+
...require('./useCrossFrameState.cjs')
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './DictionariesRecordContext';\nexport * from './EditedContentContext';\nexport * from './FocusDictionaryContext';\nexport * from './EditorProvider';\nexport * from './useCrossFrameState';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,wCAAd;AACA,0BAAc,mCADd;AAEA,0BAAc,qCAFd;AAGA,0BAAc,6BAHd;AAIA,0BAAc,iCAJd;","names":[]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
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 useCrossFrameState_exports = {};
|
|
21
|
+
__export(useCrossFrameState_exports, {
|
|
22
|
+
useCrossFrameState: () => useCrossFrameState
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(useCrossFrameState_exports);
|
|
25
|
+
var import_editor = require("@intlayer/editor");
|
|
26
|
+
var import_react = require("react");
|
|
27
|
+
var import_CommunicatorContext = require('./CommunicatorContext.cjs');
|
|
28
|
+
const useCrossFrameState = (key, initialValue) => {
|
|
29
|
+
const props = (0, import_CommunicatorContext.useCommunicator)();
|
|
30
|
+
const communicatorRef = (0, import_react.useRef)();
|
|
31
|
+
(0, import_react.useEffect)(() => {
|
|
32
|
+
if (!props.targetWindow) return;
|
|
33
|
+
communicatorRef.current = new import_editor.CrossFrameCommunicator(
|
|
34
|
+
props
|
|
35
|
+
);
|
|
36
|
+
communicatorRef.current.on(key, (data) => {
|
|
37
|
+
setState(data);
|
|
38
|
+
});
|
|
39
|
+
return () => {
|
|
40
|
+
communicatorRef.current?.destroy();
|
|
41
|
+
};
|
|
42
|
+
}, [props, key]);
|
|
43
|
+
const [state, setState] = (0, import_react.useState)(() => {
|
|
44
|
+
if (typeof window === "undefined") {
|
|
45
|
+
return initialValue;
|
|
46
|
+
}
|
|
47
|
+
if (initialValue !== void 0) {
|
|
48
|
+
communicatorRef.current?.sendMessage(key, initialValue);
|
|
49
|
+
return initialValue;
|
|
50
|
+
}
|
|
51
|
+
return void 0;
|
|
52
|
+
});
|
|
53
|
+
const setStateResult = (valueOrUpdater) => {
|
|
54
|
+
setState((prev) => {
|
|
55
|
+
const newValue = typeof valueOrUpdater === "function" ? valueOrUpdater(prev) : valueOrUpdater;
|
|
56
|
+
communicatorRef.current?.sendMessage(key, newValue);
|
|
57
|
+
return newValue;
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
return [state ?? initialValue, setStateResult];
|
|
61
|
+
};
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
useCrossFrameState
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=useCrossFrameState.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/useCrossFrameState.tsx"],"sourcesContent":["'use client';\n\nimport {\n CrossFrameCommunicator,\n type CrossFrameCommunicatorOptions,\n} from '@intlayer/editor';\nimport { type SetStateAction, useEffect, useRef, useState } from 'react';\nimport { useCommunicator } from './CommunicatorContext';\n\nexport const useCrossFrameState = <T,>(key: string, initialValue?: T) => {\n const props = useCommunicator();\n const communicatorRef = useRef<CrossFrameCommunicator>();\n\n useEffect(() => {\n if (!props.targetWindow) return;\n\n communicatorRef.current = new CrossFrameCommunicator(\n props as CrossFrameCommunicatorOptions\n );\n\n communicatorRef.current.on(key, (data) => {\n // When a message is received, update local state\n setState(data as T);\n });\n\n return () => {\n communicatorRef.current?.destroy();\n };\n }, [props, key]);\n\n const [state, setState] = useState<T>(() => {\n if (typeof window === 'undefined') {\n return initialValue as T;\n }\n\n // If you have an initial value on the client, send a message out immediately\n if (initialValue !== undefined) {\n communicatorRef.current?.sendMessage(key, initialValue);\n return initialValue;\n }\n\n return undefined as T;\n });\n\n /**\n * Allows setting state either directly or via a functional update.\n * If passed a function, we merge/update based on the previous state.\n */\n const setStateResult = (valueOrUpdater: SetStateAction<T>) => {\n setState((prev) => {\n const newValue: T =\n typeof valueOrUpdater === 'function'\n ? (valueOrUpdater as (prevVal: T) => T)(prev)\n : valueOrUpdater;\n\n communicatorRef.current?.sendMessage(key, newValue);\n return newValue;\n });\n };\n\n // If `state` is null/undefined but you have an `initialValue`,\n // you could optionally do `(state ?? initialValue) as T`\n return [state ?? (initialValue as T), setStateResult] as const;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAGO;AACP,mBAAiE;AACjE,iCAAgC;AAEzB,MAAM,qBAAqB,CAAK,KAAa,iBAAqB;AACvE,QAAM,YAAQ,4CAAgB;AAC9B,QAAM,sBAAkB,qBAA+B;AAEvD,8BAAU,MAAM;AACd,QAAI,CAAC,MAAM,aAAc;AAEzB,oBAAgB,UAAU,IAAI;AAAA,MAC5B;AAAA,IACF;AAEA,oBAAgB,QAAQ,GAAG,KAAK,CAAC,SAAS;AAExC,eAAS,IAAS;AAAA,IACpB,CAAC;AAED,WAAO,MAAM;AACX,sBAAgB,SAAS,QAAQ;AAAA,IACnC;AAAA,EACF,GAAG,CAAC,OAAO,GAAG,CAAC;AAEf,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAY,MAAM;AAC1C,QAAI,OAAO,WAAW,aAAa;AACjC,aAAO;AAAA,IACT;AAGA,QAAI,iBAAiB,QAAW;AAC9B,sBAAgB,SAAS,YAAY,KAAK,YAAY;AACtD,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT,CAAC;AAMD,QAAM,iBAAiB,CAAC,mBAAsC;AAC5D,aAAS,CAAC,SAAS;AACjB,YAAM,WACJ,OAAO,mBAAmB,aACrB,eAAqC,IAAI,IAC1C;AAEN,sBAAgB,SAAS,YAAY,KAAK,QAAQ;AAClD,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAIA,SAAO,CAAC,SAAU,cAAoB,cAAc;AACtD;","names":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
const CommunicatorContext = createContext(void 0);
|
|
4
|
+
const CommunicatorProvider = ({ children, ...props }) => /* @__PURE__ */ jsx(CommunicatorContext.Provider, { value: props, children });
|
|
5
|
+
const useCommunicator = () => {
|
|
6
|
+
const context = useContext(CommunicatorContext);
|
|
7
|
+
if (!context) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
"useCommunicator must be used within a CommunicatorProvider"
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
return context;
|
|
13
|
+
};
|
|
14
|
+
export {
|
|
15
|
+
CommunicatorProvider,
|
|
16
|
+
useCommunicator
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=CommunicatorContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/CommunicatorContext.tsx"],"sourcesContent":["import { createContext, useContext, FC, PropsWithChildren } from 'react';\n\nexport type UseCrossPlatformStateProps = {\n targetWindow?: Window;\n targetOrigin?: string;\n allowedOrigins?: string[];\n};\n\nconst CommunicatorContext = createContext<\n UseCrossPlatformStateProps | undefined\n>(undefined);\n\nexport const CommunicatorProvider: FC<\n PropsWithChildren<UseCrossPlatformStateProps>\n> = ({ children, ...props }) => (\n <CommunicatorContext.Provider value={props}>\n {children}\n </CommunicatorContext.Provider>\n);\n\nexport const useCommunicator = () => {\n const context = useContext(CommunicatorContext);\n\n if (!context) {\n throw new Error(\n 'useCommunicator must be used within a CommunicatorProvider'\n );\n }\n return context;\n};\n"],"mappings":"AAeE;AAfF,SAAS,eAAe,kBAAyC;AAQjE,MAAM,sBAAsB,cAE1B,MAAS;AAEJ,MAAM,uBAET,CAAC,EAAE,UAAU,GAAG,MAAM,MACxB,oBAAC,oBAAoB,UAApB,EAA6B,OAAO,OAClC,UACH;AAGK,MAAM,kBAAkB,MAAM;AACnC,QAAM,UAAU,WAAW,mBAAmB;AAE9C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
import { useCrossFrameState } from './useCrossFrameState.mjs';
|
|
4
|
+
const DictionariesRecordContext = createContext(void 0);
|
|
5
|
+
const DictionariesRecordProvider = ({
|
|
6
|
+
children
|
|
7
|
+
}) => {
|
|
8
|
+
const [dictionariesRecord, setDictionariesRecordState] = useCrossFrameState("DICTIONARIES_RECORD_CHANGED", {});
|
|
9
|
+
const setDictionariesRecord = (newRecord) => {
|
|
10
|
+
setDictionariesRecordState((prev) => ({
|
|
11
|
+
...prev,
|
|
12
|
+
...newRecord
|
|
13
|
+
}));
|
|
14
|
+
};
|
|
15
|
+
return /* @__PURE__ */ jsx(
|
|
16
|
+
DictionariesRecordContext.Provider,
|
|
17
|
+
{
|
|
18
|
+
value: { dictionariesRecord, setDictionariesRecord },
|
|
19
|
+
children
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
const useDictionariesRecord = () => {
|
|
24
|
+
const context = useContext(DictionariesRecordContext);
|
|
25
|
+
if (!context) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
"useDictionariesRecord must be used within a DictionariesRecordProvider"
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
return context;
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
DictionariesRecordProvider,
|
|
34
|
+
useDictionariesRecord
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=DictionariesRecordContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/DictionariesRecordContext.tsx"],"sourcesContent":["import { type Dictionary } from '@intlayer/core';\nimport { createContext, useContext, FC, PropsWithChildren } from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\n// Types for our state\nexport type DictionaryContent = Record<Dictionary['key'], Dictionary>;\n\ntype DictionariesRecordContextType = {\n dictionariesRecord: DictionaryContent;\n setDictionariesRecord: (\n dictionariesRecord: Record<Dictionary['key'], Dictionary>\n ) => void;\n};\n\nconst DictionariesRecordContext = createContext<\n DictionariesRecordContextType | undefined\n>(undefined);\n\nexport const DictionariesRecordProvider: FC<PropsWithChildren> = ({\n children,\n}) => {\n const [dictionariesRecord, setDictionariesRecordState] =\n useCrossFrameState<DictionaryContent>('DICTIONARIES_RECORD_CHANGED', {});\n\n const setDictionariesRecord = (newRecord: DictionaryContent) => {\n // Here we merge the new record with the existing one:\n setDictionariesRecordState((prev) => ({\n ...prev,\n ...newRecord,\n }));\n };\n\n return (\n <DictionariesRecordContext.Provider\n value={{ dictionariesRecord, setDictionariesRecord }}\n >\n {children}\n </DictionariesRecordContext.Provider>\n );\n};\n\nexport const useDictionariesRecord = () => {\n const context = useContext(DictionariesRecordContext);\n\n if (!context) {\n throw new Error(\n 'useDictionariesRecord must be used within a DictionariesRecordProvider'\n );\n }\n return context;\n};\n"],"mappings":"AAiCI;AAhCJ,SAAS,eAAe,kBAAyC;AACjE,SAAS,0BAA0B;AAYnC,MAAM,4BAA4B,cAEhC,MAAS;AAEJ,MAAM,6BAAoD,CAAC;AAAA,EAChE;AACF,MAAM;AACJ,QAAM,CAAC,oBAAoB,0BAA0B,IACnD,mBAAsC,+BAA+B,CAAC,CAAC;AAEzE,QAAM,wBAAwB,CAAC,cAAiC;AAE9D,+BAA2B,CAAC,UAAU;AAAA,MACpC,GAAG;AAAA,MACH,GAAG;AAAA,IACL,EAAE;AAAA,EACJ;AAEA,SACE;AAAA,IAAC,0BAA0B;AAAA,IAA1B;AAAA,MACC,OAAO,EAAE,oBAAoB,sBAAsB;AAAA,MAElD;AAAA;AAAA,EACH;AAEJ;AAEO,MAAM,wBAAwB,MAAM;AACzC,QAAM,UAAU,WAAW,yBAAyB;AAEpD,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
editDictionaryByKeyPath,
|
|
4
|
+
getDictionaryValueByKeyPath,
|
|
5
|
+
renameDictionaryValueByKeyPath
|
|
6
|
+
} from "@intlayer/core";
|
|
7
|
+
import { createContext, useContext } from "react";
|
|
8
|
+
import {
|
|
9
|
+
useDictionariesRecord
|
|
10
|
+
} from './DictionariesRecordContext.mjs';
|
|
11
|
+
import { useCrossFrameState } from './useCrossFrameState.mjs';
|
|
12
|
+
const EditedContentStateContext = createContext(void 0);
|
|
13
|
+
const EditedContentActionsContext = createContext(void 0);
|
|
14
|
+
const EditedContentProvider = ({ children }) => {
|
|
15
|
+
const { dictionariesRecord } = useDictionariesRecord();
|
|
16
|
+
const [editedContent, setEditedContentState] = useCrossFrameState("EDITED_CONTENT_CHANGED", {});
|
|
17
|
+
const setEditedContent = (dictionaryKey, newValue) => {
|
|
18
|
+
setEditedContentState((prev) => ({
|
|
19
|
+
...prev,
|
|
20
|
+
[dictionaryKey]: {
|
|
21
|
+
...prev[dictionaryKey],
|
|
22
|
+
content: newValue
|
|
23
|
+
}
|
|
24
|
+
}));
|
|
25
|
+
};
|
|
26
|
+
const addEditedContent = (dictionaryKey, newValue, keyPath = [], overwrite = true) => {
|
|
27
|
+
setEditedContentState((prev) => {
|
|
28
|
+
const originalContent = dictionariesRecord[dictionaryKey]?.content;
|
|
29
|
+
const currentContent = prev[dictionaryKey]?.content || JSON.parse(JSON.stringify(originalContent));
|
|
30
|
+
let newKeyPath = keyPath;
|
|
31
|
+
if (!overwrite) {
|
|
32
|
+
let index = 0;
|
|
33
|
+
const otherKeyPath = keyPath.slice(0, -1);
|
|
34
|
+
const lastKeyPath = keyPath[keyPath.length - 1];
|
|
35
|
+
let finalKey = lastKeyPath.key;
|
|
36
|
+
while (typeof getDictionaryValueByKeyPath(currentContent, newKeyPath) !== "undefined") {
|
|
37
|
+
index++;
|
|
38
|
+
finalKey = index === 0 ? lastKeyPath.key : `${lastKeyPath.key} (${index})`;
|
|
39
|
+
newKeyPath = [
|
|
40
|
+
...otherKeyPath,
|
|
41
|
+
{ ...lastKeyPath, key: finalKey }
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const updatedContent = editDictionaryByKeyPath(
|
|
46
|
+
currentContent,
|
|
47
|
+
newKeyPath,
|
|
48
|
+
newValue
|
|
49
|
+
);
|
|
50
|
+
return {
|
|
51
|
+
...prev,
|
|
52
|
+
[dictionaryKey]: {
|
|
53
|
+
...prev[dictionaryKey],
|
|
54
|
+
content: updatedContent
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
const renameEditedContent = (dictionaryKey, newKey, keyPath = []) => {
|
|
60
|
+
setEditedContentState((prev) => {
|
|
61
|
+
const originalContent = dictionariesRecord[dictionaryKey]?.content;
|
|
62
|
+
const currentContent = prev[dictionaryKey]?.content || JSON.parse(JSON.stringify(originalContent));
|
|
63
|
+
const contentWithNewField = renameDictionaryValueByKeyPath(
|
|
64
|
+
currentContent,
|
|
65
|
+
newKey,
|
|
66
|
+
keyPath
|
|
67
|
+
);
|
|
68
|
+
return {
|
|
69
|
+
...prev,
|
|
70
|
+
[dictionaryKey]: {
|
|
71
|
+
...prev[dictionaryKey],
|
|
72
|
+
content: contentWithNewField
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
const removeEditedContent = (dictionaryKey, keyPath) => {
|
|
78
|
+
setEditedContentState((prev) => {
|
|
79
|
+
const originalContent = dictionariesRecord[dictionaryKey]?.content;
|
|
80
|
+
const currentContent = prev[dictionaryKey]?.content || JSON.parse(JSON.stringify(originalContent));
|
|
81
|
+
const initialContent = getDictionaryValueByKeyPath(
|
|
82
|
+
originalContent,
|
|
83
|
+
keyPath
|
|
84
|
+
);
|
|
85
|
+
const restoredContent = editDictionaryByKeyPath(
|
|
86
|
+
currentContent,
|
|
87
|
+
keyPath,
|
|
88
|
+
initialContent
|
|
89
|
+
);
|
|
90
|
+
return {
|
|
91
|
+
...prev,
|
|
92
|
+
[dictionaryKey]: {
|
|
93
|
+
...prev[dictionaryKey],
|
|
94
|
+
content: restoredContent
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
const restoreEditedContent = (dictionaryKey) => {
|
|
100
|
+
setEditedContentState((prev) => {
|
|
101
|
+
const updated = { ...prev };
|
|
102
|
+
delete updated[dictionaryKey];
|
|
103
|
+
return updated;
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
const clearEditedDictionaryContent = (dictionaryKey) => {
|
|
107
|
+
setEditedContentState((prev) => {
|
|
108
|
+
const filtered = Object.entries(prev).reduce((acc, [key, value]) => {
|
|
109
|
+
if (key === dictionaryKey) {
|
|
110
|
+
return acc;
|
|
111
|
+
}
|
|
112
|
+
return { ...acc, [key]: value };
|
|
113
|
+
}, {});
|
|
114
|
+
return filtered;
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
const clearEditedContent = () => {
|
|
118
|
+
setEditedContentState({});
|
|
119
|
+
};
|
|
120
|
+
const getEditedContentValue = (dictionaryKey, keyPath) => {
|
|
121
|
+
const currentContent = editedContent[dictionaryKey]?.content || {};
|
|
122
|
+
return getDictionaryValueByKeyPath(currentContent, keyPath);
|
|
123
|
+
};
|
|
124
|
+
return /* @__PURE__ */ jsx(
|
|
125
|
+
EditedContentStateContext.Provider,
|
|
126
|
+
{
|
|
127
|
+
value: {
|
|
128
|
+
editedContent
|
|
129
|
+
},
|
|
130
|
+
children: /* @__PURE__ */ jsx(
|
|
131
|
+
EditedContentActionsContext.Provider,
|
|
132
|
+
{
|
|
133
|
+
value: {
|
|
134
|
+
setEditedContent,
|
|
135
|
+
addEditedContent,
|
|
136
|
+
renameEditedContent,
|
|
137
|
+
removeEditedContent,
|
|
138
|
+
restoreEditedContent,
|
|
139
|
+
clearEditedDictionaryContent,
|
|
140
|
+
clearEditedContent,
|
|
141
|
+
getEditedContentValue
|
|
142
|
+
},
|
|
143
|
+
children
|
|
144
|
+
}
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
};
|
|
149
|
+
const useEditedContentActions = () => {
|
|
150
|
+
const context = useContext(EditedContentActionsContext);
|
|
151
|
+
if (!context) {
|
|
152
|
+
throw new Error(
|
|
153
|
+
"useEditedContent must be used within an EditedContentActionsProvider"
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
return context;
|
|
157
|
+
};
|
|
158
|
+
const useEditedContent = () => {
|
|
159
|
+
const stateContext = useContext(EditedContentStateContext);
|
|
160
|
+
const actionContext = useEditedContentActions();
|
|
161
|
+
if (!stateContext) {
|
|
162
|
+
throw new Error(
|
|
163
|
+
"useEditedContent must be used within an EditedContentStateProvider"
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
return { ...stateContext, ...actionContext };
|
|
167
|
+
};
|
|
168
|
+
export {
|
|
169
|
+
EditedContentProvider,
|
|
170
|
+
useEditedContent,
|
|
171
|
+
useEditedContentActions
|
|
172
|
+
};
|
|
173
|
+
//# sourceMappingURL=EditedContentContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/EditedContentContext.tsx"],"sourcesContent":["import {\n type Dictionary,\n type DictionaryValue,\n type KeyPath,\n editDictionaryByKeyPath,\n getDictionaryValueByKeyPath,\n renameDictionaryValueByKeyPath,\n} from '@intlayer/core';\nimport { createContext, useContext, FC, PropsWithChildren } from 'react';\nimport {\n DictionaryContent,\n useDictionariesRecord,\n} from './DictionariesRecordContext';\nimport { useCrossFrameState } from './useCrossFrameState';\n\ntype EditedContentStateContextType = {\n editedContent: DictionaryContent;\n};\n\nconst EditedContentStateContext = createContext<\n EditedContentStateContextType | undefined\n>(undefined);\n\ntype EditedContentActionsContextType = {\n setEditedContent: (\n dictionaryKey: Dictionary['key'],\n newValue: DictionaryValue\n ) => void;\n addEditedContent: (\n dictionaryKey: Dictionary['key'],\n newValue: DictionaryValue,\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 ) => DictionaryValue | undefined;\n};\n\nconst EditedContentActionsContext = createContext<\n EditedContentActionsContextType | undefined\n>(undefined);\n\nexport const EditedContentProvider: FC<PropsWithChildren> = ({ children }) => {\n const { dictionariesRecord } = useDictionariesRecord();\n const [editedContent, setEditedContentState] =\n useCrossFrameState<DictionaryContent>('EDITED_CONTENT_CHANGED', {});\n\n const setEditedContent = (\n dictionaryKey: Dictionary['key'],\n newValue: DictionaryValue\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: DictionaryValue,\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 = dictionariesRecord[dictionaryKey]?.content;\n const currentContent =\n prev[dictionaryKey]?.content ||\n JSON.parse(JSON.stringify(originalContent));\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 getDictionaryValueByKeyPath(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,\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 = dictionariesRecord[dictionaryKey]?.content;\n const currentContent =\n prev[dictionaryKey]?.content ||\n JSON.parse(JSON.stringify(originalContent));\n\n const contentWithNewField = renameDictionaryValueByKeyPath(\n currentContent,\n newKey,\n keyPath\n );\n\n return {\n ...prev,\n [dictionaryKey]: {\n ...prev[dictionaryKey],\n content: contentWithNewField,\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 = dictionariesRecord[dictionaryKey]?.content;\n const currentContent =\n prev[dictionaryKey]?.content ||\n JSON.parse(JSON.stringify(originalContent));\n\n // Get the initial value from the original dictionary content\n const initialContent = getDictionaryValueByKeyPath(\n originalContent,\n keyPath\n );\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,\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 ): DictionaryValue | undefined => {\n const currentContent = editedContent[dictionaryKey]?.content || {};\n return getDictionaryValueByKeyPath(currentContent, keyPath);\n };\n\n return (\n <EditedContentStateContext.Provider\n value={{\n editedContent,\n }}\n >\n <EditedContentActionsContext.Provider\n value={{\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 EditedContentActionsProvider'\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 EditedContentStateProvider'\n );\n }\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { DictionariesRecordProvider } from './DictionariesRecordContext.mjs';
|
|
3
|
+
import { FocusDictionaryProvider } from './FocusDictionaryContext.mjs';
|
|
4
|
+
import {
|
|
5
|
+
CommunicatorProvider
|
|
6
|
+
} from './CommunicatorContext.mjs';
|
|
7
|
+
import { EditedContentProvider } from './EditedContentContext.mjs';
|
|
8
|
+
const EditorProvider = ({ children, ...props }) => /* @__PURE__ */ jsx(CommunicatorProvider, { ...props, children: /* @__PURE__ */ jsx(DictionariesRecordProvider, { children: /* @__PURE__ */ jsx(EditedContentProvider, { children: /* @__PURE__ */ jsx(FocusDictionaryProvider, { children }) }) }) });
|
|
9
|
+
export {
|
|
10
|
+
EditorProvider
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=EditorProvider.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/EditorProvider.tsx"],"sourcesContent":["import { type FC, type PropsWithChildren } from 'react';\nimport { DictionariesRecordProvider } from './DictionariesRecordContext';\nimport { FocusDictionaryProvider } from './FocusDictionaryContext';\nimport {\n CommunicatorProvider,\n UseCrossPlatformStateProps,\n} from './CommunicatorContext';\nimport { EditedContentProvider } from './EditedContentContext';\n\nexport const EditorProvider: FC<\n PropsWithChildren<UseCrossPlatformStateProps>\n> = ({ children, ...props }) => (\n <CommunicatorProvider {...props}>\n <DictionariesRecordProvider>\n <EditedContentProvider>\n <FocusDictionaryProvider>{children}</FocusDictionaryProvider>\n </EditedContentProvider>\n </DictionariesRecordProvider>\n </CommunicatorProvider>\n);\n"],"mappings":"AAeQ;AAdR,SAAS,kCAAkC;AAC3C,SAAS,+BAA+B;AACxC;AAAA,EACE;AAAA,OAEK;AACP,SAAS,6BAA6B;AAE/B,MAAM,iBAET,CAAC,EAAE,UAAU,GAAG,MAAM,MACxB,oBAAC,wBAAsB,GAAG,OACxB,8BAAC,8BACC,8BAAC,yBACC,8BAAC,2BAAyB,UAAS,GACrC,GACF,GACF;","names":[]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
import { useCrossFrameState } from './useCrossFrameState.mjs';
|
|
4
|
+
const FocusDictionaryStateContext = createContext(void 0);
|
|
5
|
+
const FocusDictionaryActionsContext = createContext(void 0);
|
|
6
|
+
const FocusDictionaryProvider = ({
|
|
7
|
+
children
|
|
8
|
+
}) => {
|
|
9
|
+
const [focusedContent, setFocusedContentState] = useCrossFrameState("FOCUSED_CONTENT_CHANGED", null);
|
|
10
|
+
const setFocusedContent = (content) => {
|
|
11
|
+
setFocusedContentState(content);
|
|
12
|
+
};
|
|
13
|
+
const setFocusedContentKeyPath = (keyPath) => {
|
|
14
|
+
setFocusedContentState((prev) => {
|
|
15
|
+
if (!prev) {
|
|
16
|
+
return prev;
|
|
17
|
+
}
|
|
18
|
+
return { ...prev, keyPath };
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
return /* @__PURE__ */ jsx(FocusDictionaryStateContext.Provider, { value: { focusedContent }, children: /* @__PURE__ */ jsx(
|
|
22
|
+
FocusDictionaryActionsContext.Provider,
|
|
23
|
+
{
|
|
24
|
+
value: { setFocusedContent, setFocusedContentKeyPath },
|
|
25
|
+
children
|
|
26
|
+
}
|
|
27
|
+
) });
|
|
28
|
+
};
|
|
29
|
+
const useFocusDictionaryActions = () => {
|
|
30
|
+
const context = useContext(FocusDictionaryActionsContext);
|
|
31
|
+
if (context === void 0) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
"useFocusDictionaryActions must be used within a FocusDictionaryProvider"
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return context;
|
|
37
|
+
};
|
|
38
|
+
const useFocusDictionary = () => {
|
|
39
|
+
const actionContext = useFocusDictionaryActions();
|
|
40
|
+
const stateContext = useContext(FocusDictionaryStateContext);
|
|
41
|
+
if (stateContext === void 0) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
"useFocusDictionaryState must be used within a FocusDictionaryProvider"
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
return { ...stateContext, ...actionContext };
|
|
47
|
+
};
|
|
48
|
+
export {
|
|
49
|
+
FocusDictionaryProvider,
|
|
50
|
+
useFocusDictionary,
|
|
51
|
+
useFocusDictionaryActions
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=FocusDictionaryContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["import type { KeyPath } from '@intlayer/core';\nimport { createContext, useContext, FC, PropsWithChildren } 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\ninterface FocusDictionaryState {\n focusedContent: FileContent | null;\n}\n\ninterface FocusDictionaryActions {\n setFocusedContent: (content: FileContent | null) => void;\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, setFocusedContentState] =\n useCrossFrameState<FileContent | null>('FOCUSED_CONTENT_CHANGED', null);\n\n const setFocusedContent = (content: FileContent | null) => {\n setFocusedContentState(content);\n };\n\n const setFocusedContentKeyPath = (keyPath: KeyPath[]) => {\n setFocusedContentState((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":"AAiDM;AAhDN,SAAS,eAAe,kBAAyC;AACjE,SAAS,0BAA0B;AAmBnC,MAAM,8BAA8B,cAElC,MAAS;AACX,MAAM,gCAAgC,cAEpC,MAAS;AAEJ,MAAM,0BAAiD,CAAC;AAAA,EAC7D;AACF,MAAM;AACJ,QAAM,CAAC,gBAAgB,sBAAsB,IAC3C,mBAAuC,2BAA2B,IAAI;AAExE,QAAM,oBAAoB,CAAC,YAAgC;AACzD,2BAAuB,OAAO;AAAA,EAChC;AAEA,QAAM,2BAA2B,CAAC,YAAuB;AACvD,2BAAuB,CAAC,SAAS;AAC/B,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":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './DictionariesRecordContext';\nexport * from './EditedContentContext';\nexport * from './FocusDictionaryContext';\nexport * from './EditorProvider';\nexport * from './useCrossFrameState';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
CrossFrameCommunicator
|
|
4
|
+
} from "@intlayer/editor";
|
|
5
|
+
import { useEffect, useRef, useState } from "react";
|
|
6
|
+
import { useCommunicator } from './CommunicatorContext.mjs';
|
|
7
|
+
const useCrossFrameState = (key, initialValue) => {
|
|
8
|
+
const props = useCommunicator();
|
|
9
|
+
const communicatorRef = useRef();
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (!props.targetWindow) return;
|
|
12
|
+
communicatorRef.current = new CrossFrameCommunicator(
|
|
13
|
+
props
|
|
14
|
+
);
|
|
15
|
+
communicatorRef.current.on(key, (data) => {
|
|
16
|
+
setState(data);
|
|
17
|
+
});
|
|
18
|
+
return () => {
|
|
19
|
+
communicatorRef.current?.destroy();
|
|
20
|
+
};
|
|
21
|
+
}, [props, key]);
|
|
22
|
+
const [state, setState] = useState(() => {
|
|
23
|
+
if (typeof window === "undefined") {
|
|
24
|
+
return initialValue;
|
|
25
|
+
}
|
|
26
|
+
if (initialValue !== void 0) {
|
|
27
|
+
communicatorRef.current?.sendMessage(key, initialValue);
|
|
28
|
+
return initialValue;
|
|
29
|
+
}
|
|
30
|
+
return void 0;
|
|
31
|
+
});
|
|
32
|
+
const setStateResult = (valueOrUpdater) => {
|
|
33
|
+
setState((prev) => {
|
|
34
|
+
const newValue = typeof valueOrUpdater === "function" ? valueOrUpdater(prev) : valueOrUpdater;
|
|
35
|
+
communicatorRef.current?.sendMessage(key, newValue);
|
|
36
|
+
return newValue;
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
return [state ?? initialValue, setStateResult];
|
|
40
|
+
};
|
|
41
|
+
export {
|
|
42
|
+
useCrossFrameState
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=useCrossFrameState.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/useCrossFrameState.tsx"],"sourcesContent":["'use client';\n\nimport {\n CrossFrameCommunicator,\n type CrossFrameCommunicatorOptions,\n} from '@intlayer/editor';\nimport { type SetStateAction, useEffect, useRef, useState } from 'react';\nimport { useCommunicator } from './CommunicatorContext';\n\nexport const useCrossFrameState = <T,>(key: string, initialValue?: T) => {\n const props = useCommunicator();\n const communicatorRef = useRef<CrossFrameCommunicator>();\n\n useEffect(() => {\n if (!props.targetWindow) return;\n\n communicatorRef.current = new CrossFrameCommunicator(\n props as CrossFrameCommunicatorOptions\n );\n\n communicatorRef.current.on(key, (data) => {\n // When a message is received, update local state\n setState(data as T);\n });\n\n return () => {\n communicatorRef.current?.destroy();\n };\n }, [props, key]);\n\n const [state, setState] = useState<T>(() => {\n if (typeof window === 'undefined') {\n return initialValue as T;\n }\n\n // If you have an initial value on the client, send a message out immediately\n if (initialValue !== undefined) {\n communicatorRef.current?.sendMessage(key, initialValue);\n return initialValue;\n }\n\n return undefined as T;\n });\n\n /**\n * Allows setting state either directly or via a functional update.\n * If passed a function, we merge/update based on the previous state.\n */\n const setStateResult = (valueOrUpdater: SetStateAction<T>) => {\n setState((prev) => {\n const newValue: T =\n typeof valueOrUpdater === 'function'\n ? (valueOrUpdater as (prevVal: T) => T)(prev)\n : valueOrUpdater;\n\n communicatorRef.current?.sendMessage(key, newValue);\n return newValue;\n });\n };\n\n // If `state` is null/undefined but you have an `initialValue`,\n // you could optionally do `(state ?? initialValue) as T`\n return [state ?? (initialValue as T), setStateResult] as const;\n};\n"],"mappings":";AAEA;AAAA,EACE;AAAA,OAEK;AACP,SAA8B,WAAW,QAAQ,gBAAgB;AACjE,SAAS,uBAAuB;AAEzB,MAAM,qBAAqB,CAAK,KAAa,iBAAqB;AACvE,QAAM,QAAQ,gBAAgB;AAC9B,QAAM,kBAAkB,OAA+B;AAEvD,YAAU,MAAM;AACd,QAAI,CAAC,MAAM,aAAc;AAEzB,oBAAgB,UAAU,IAAI;AAAA,MAC5B;AAAA,IACF;AAEA,oBAAgB,QAAQ,GAAG,KAAK,CAAC,SAAS;AAExC,eAAS,IAAS;AAAA,IACpB,CAAC;AAED,WAAO,MAAM;AACX,sBAAgB,SAAS,QAAQ;AAAA,IACnC;AAAA,EACF,GAAG,CAAC,OAAO,GAAG,CAAC;AAEf,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAY,MAAM;AAC1C,QAAI,OAAO,WAAW,aAAa;AACjC,aAAO;AAAA,IACT;AAGA,QAAI,iBAAiB,QAAW;AAC9B,sBAAgB,SAAS,YAAY,KAAK,YAAY;AACtD,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT,CAAC;AAMD,QAAM,iBAAiB,CAAC,mBAAsC;AAC5D,aAAS,CAAC,SAAS;AACjB,YAAM,WACJ,OAAO,mBAAmB,aACrB,eAAqC,IAAI,IAC1C;AAEN,sBAAgB,SAAS,YAAY,KAAK,QAAQ;AAClD,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAIA,SAAO,CAAC,SAAU,cAAoB,cAAc;AACtD;","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FC, PropsWithChildren } from 'react';
|
|
2
|
+
export type UseCrossPlatformStateProps = {
|
|
3
|
+
targetWindow?: Window;
|
|
4
|
+
targetOrigin?: string;
|
|
5
|
+
allowedOrigins?: string[];
|
|
6
|
+
};
|
|
7
|
+
export declare const CommunicatorProvider: FC<PropsWithChildren<UseCrossPlatformStateProps>>;
|
|
8
|
+
export declare const useCommunicator: () => UseCrossPlatformStateProps;
|
|
9
|
+
//# sourceMappingURL=CommunicatorContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommunicatorContext.d.ts","sourceRoot":"","sources":["../../src/CommunicatorContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA6B,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAEzE,MAAM,MAAM,0BAA0B,GAAG;IACvC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B,CAAC;AAMF,eAAO,MAAM,oBAAoB,EAAE,EAAE,CACnC,iBAAiB,CAAC,0BAA0B,CAAC,CAK9C,CAAC;AAEF,eAAO,MAAM,eAAe,kCAS3B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Dictionary } from '@intlayer/core';
|
|
2
|
+
import { FC, PropsWithChildren } from 'react';
|
|
3
|
+
export type DictionaryContent = Record<Dictionary['key'], Dictionary>;
|
|
4
|
+
type DictionariesRecordContextType = {
|
|
5
|
+
dictionariesRecord: DictionaryContent;
|
|
6
|
+
setDictionariesRecord: (dictionariesRecord: Record<Dictionary['key'], Dictionary>) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare const DictionariesRecordProvider: FC<PropsWithChildren>;
|
|
9
|
+
export declare const useDictionariesRecord: () => DictionariesRecordContextType;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=DictionariesRecordContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DictionariesRecordContext.d.ts","sourceRoot":"","sources":["../../src/DictionariesRecordContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAA6B,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAIzE,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,CAAC;AAEtE,KAAK,6BAA6B,GAAG;IACnC,kBAAkB,EAAE,iBAAiB,CAAC;IACtC,qBAAqB,EAAE,CACrB,kBAAkB,EAAE,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,KACtD,IAAI,CAAC;CACX,CAAC;AAMF,eAAO,MAAM,0BAA0B,EAAE,EAAE,CAAC,iBAAiB,CAqB5D,CAAC;AAEF,eAAO,MAAM,qBAAqB,qCASjC,CAAC"}
|