preact-intlayer 5.5.5 → 5.5.6
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/IntlayerNode.cjs +47 -0
- package/dist/cjs/IntlayerNode.cjs.map +1 -0
- package/dist/cjs/UI/ContentSelector.cjs +127 -0
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -0
- package/dist/cjs/client/IntlayerProvider.cjs +98 -0
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -0
- package/dist/cjs/client/getBrowserLocale.cjs +173 -0
- package/dist/cjs/client/getBrowserLocale.cjs.map +1 -0
- package/dist/cjs/client/index.cjs +69 -0
- package/dist/cjs/client/index.cjs.map +1 -0
- package/dist/cjs/client/t.cjs +37 -0
- package/dist/cjs/client/t.cjs.map +1 -0
- package/dist/cjs/client/useContent.cjs +39 -0
- package/dist/cjs/client/useContent.cjs.map +1 -0
- package/dist/cjs/client/useDictionary.cjs +42 -0
- package/dist/cjs/client/useDictionary.cjs.map +1 -0
- package/dist/cjs/client/useDictionaryDynamic.cjs +42 -0
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -0
- package/dist/cjs/client/useIntlayer.cjs +43 -0
- package/dist/cjs/client/useIntlayer.cjs.map +1 -0
- package/dist/cjs/client/useIntlayerAsync.cjs +54 -0
- package/dist/cjs/client/useIntlayerAsync.cjs.map +1 -0
- package/dist/cjs/client/useLoadDynamic.cjs +56 -0
- package/dist/cjs/client/useLoadDynamic.cjs.map +1 -0
- package/dist/cjs/client/useLocale.cjs +69 -0
- package/dist/cjs/client/useLocale.cjs.map +1 -0
- package/dist/cjs/client/useLocaleBase.cjs +56 -0
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -0
- package/dist/cjs/client/useLocaleCookie.cjs +60 -0
- package/dist/cjs/client/useLocaleCookie.cjs.map +1 -0
- package/dist/cjs/client/useTraduction.cjs +35 -0
- package/dist/cjs/client/useTraduction.cjs.map +1 -0
- package/dist/cjs/editor/ChangedContentContext.cjs +77 -0
- package/dist/cjs/editor/ChangedContentContext.cjs.map +1 -0
- package/dist/cjs/editor/CommunicatorContext.cjs +66 -0
- package/dist/cjs/editor/CommunicatorContext.cjs.map +1 -0
- package/dist/cjs/editor/ConfigurationContext.cjs +50 -0
- package/dist/cjs/editor/ConfigurationContext.cjs.map +1 -0
- package/dist/cjs/editor/ContentSelectorWrapper.cjs +66 -0
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -0
- package/dist/cjs/editor/DictionariesRecordContext.cjs +77 -0
- package/dist/cjs/editor/DictionariesRecordContext.cjs.map +1 -0
- package/dist/cjs/editor/EditedContentContext.cjs +217 -0
- package/dist/cjs/editor/EditedContentContext.cjs.map +1 -0
- package/dist/cjs/editor/EditorEnabledContext.cjs +62 -0
- package/dist/cjs/editor/EditorEnabledContext.cjs.map +1 -0
- package/dist/cjs/editor/EditorProvider.cjs +72 -0
- package/dist/cjs/editor/EditorProvider.cjs.map +1 -0
- package/dist/cjs/editor/FocusDictionaryContext.cjs +81 -0
- package/dist/cjs/editor/FocusDictionaryContext.cjs.map +1 -0
- package/dist/cjs/editor/IntlayerEditorProvider.cjs +122 -0
- package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -0
- package/dist/cjs/editor/index.cjs +23 -0
- package/dist/cjs/editor/index.cjs.map +1 -0
- package/dist/cjs/editor/useCrossFrameMessageListener.cjs +53 -0
- package/dist/cjs/editor/useCrossFrameMessageListener.cjs.map +1 -0
- package/dist/cjs/editor/useCrossFrameState.cjs +77 -0
- package/dist/cjs/editor/useCrossFrameState.cjs.map +1 -0
- package/dist/cjs/editor/useCrossURLPathState.cjs +69 -0
- package/dist/cjs/editor/useCrossURLPathState.cjs.map +1 -0
- package/dist/cjs/editor/useEditedContentRenderer.cjs +63 -0
- package/dist/cjs/editor/useEditedContentRenderer.cjs.map +1 -0
- package/dist/cjs/editor/useIframeClickInterceptor.cjs +50 -0
- package/dist/cjs/editor/useIframeClickInterceptor.cjs.map +1 -0
- package/dist/cjs/getDictionary.cjs +43 -0
- package/dist/cjs/getDictionary.cjs.map +1 -0
- package/dist/cjs/getIntlayer.cjs +39 -0
- package/dist/cjs/getIntlayer.cjs.map +1 -0
- package/dist/cjs/index.cjs +42 -5
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownProvider.cjs +41 -0
- package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -0
- package/dist/cjs/markdown/MarkdownRenderer.cjs +83 -0
- package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -0
- package/dist/cjs/markdown/index.cjs +25 -0
- package/dist/cjs/markdown/index.cjs.map +1 -0
- package/dist/cjs/plugins.cjs +128 -0
- package/dist/cjs/plugins.cjs.map +1 -0
- package/dist/cjs/preactElement/renderPreactElement.cjs +62 -0
- package/dist/cjs/preactElement/renderPreactElement.cjs.map +1 -0
- package/dist/esm/IntlayerNode.mjs +27 -0
- package/dist/esm/IntlayerNode.mjs.map +1 -0
- package/dist/esm/UI/ContentSelector.mjs +103 -0
- package/dist/esm/UI/ContentSelector.mjs.map +1 -0
- package/dist/esm/client/IntlayerProvider.mjs +63 -0
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -0
- package/dist/esm/client/getBrowserLocale.mjs +138 -0
- package/dist/esm/client/getBrowserLocale.mjs.map +1 -0
- package/dist/esm/client/index.mjs +39 -0
- package/dist/esm/client/index.mjs.map +1 -0
- package/dist/esm/client/t.mjs +13 -0
- package/dist/esm/client/t.mjs.map +1 -0
- package/dist/esm/client/useContent.mjs +15 -0
- package/dist/esm/client/useContent.mjs.map +1 -0
- package/dist/esm/client/useDictionary.mjs +18 -0
- package/dist/esm/client/useDictionary.mjs.map +1 -0
- package/dist/esm/client/useDictionaryDynamic.mjs +18 -0
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -0
- package/dist/esm/client/useIntlayer.mjs +19 -0
- package/dist/esm/client/useIntlayer.mjs.map +1 -0
- package/dist/esm/client/useIntlayerAsync.mjs +33 -0
- package/dist/esm/client/useIntlayerAsync.mjs.map +1 -0
- package/dist/esm/client/useLoadDynamic.mjs +32 -0
- package/dist/esm/client/useLoadDynamic.mjs.map +1 -0
- package/dist/esm/client/useLocale.mjs +35 -0
- package/dist/esm/client/useLocale.mjs.map +1 -0
- package/dist/esm/client/useLocaleBase.mjs +22 -0
- package/dist/esm/client/useLocaleBase.mjs.map +1 -0
- package/dist/esm/client/useLocaleCookie.mjs +24 -0
- package/dist/esm/client/useLocaleCookie.mjs.map +1 -0
- package/dist/esm/client/useTraduction.mjs +11 -0
- package/dist/esm/client/useTraduction.mjs.map +1 -0
- package/dist/esm/editor/ChangedContentContext.mjs +55 -0
- package/dist/esm/editor/ChangedContentContext.mjs.map +1 -0
- package/dist/esm/editor/CommunicatorContext.mjs +33 -0
- package/dist/esm/editor/CommunicatorContext.mjs.map +1 -0
- package/dist/esm/editor/ConfigurationContext.mjs +27 -0
- package/dist/esm/editor/ConfigurationContext.mjs.map +1 -0
- package/dist/esm/editor/ContentSelectorWrapper.mjs +45 -0
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -0
- package/dist/esm/editor/DictionariesRecordContext.mjs +55 -0
- package/dist/esm/editor/DictionariesRecordContext.mjs.map +1 -0
- package/dist/esm/editor/EditedContentContext.mjs +198 -0
- package/dist/esm/editor/EditedContentContext.mjs.map +1 -0
- package/dist/esm/editor/EditorEnabledContext.mjs +39 -0
- package/dist/esm/editor/EditorEnabledContext.mjs.map +1 -0
- package/dist/esm/editor/EditorProvider.mjs +62 -0
- package/dist/esm/editor/EditorProvider.mjs.map +1 -0
- package/dist/esm/editor/FocusDictionaryContext.mjs +58 -0
- package/dist/esm/editor/FocusDictionaryContext.mjs.map +1 -0
- package/dist/esm/editor/IntlayerEditorProvider.mjs +88 -0
- package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -0
- package/dist/esm/editor/index.mjs +2 -0
- package/dist/esm/editor/index.mjs.map +1 -0
- package/dist/esm/editor/useCrossFrameMessageListener.mjs +29 -0
- package/dist/esm/editor/useCrossFrameMessageListener.mjs.map +1 -0
- package/dist/esm/editor/useCrossFrameState.mjs +53 -0
- package/dist/esm/editor/useCrossFrameState.mjs.map +1 -0
- package/dist/esm/editor/useCrossURLPathState.mjs +46 -0
- package/dist/esm/editor/useCrossURLPathState.mjs.map +1 -0
- package/dist/esm/editor/useEditedContentRenderer.mjs +38 -0
- package/dist/esm/editor/useEditedContentRenderer.mjs.map +1 -0
- package/dist/esm/editor/useIframeClickInterceptor.mjs +25 -0
- package/dist/esm/editor/useIframeClickInterceptor.mjs.map +1 -0
- package/dist/esm/getDictionary.mjs +25 -0
- package/dist/esm/getDictionary.mjs.map +1 -0
- package/dist/esm/getIntlayer.mjs +21 -0
- package/dist/esm/getIntlayer.mjs.map +1 -0
- package/dist/esm/index.mjs +38 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownProvider.mjs +19 -0
- package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -0
- package/dist/esm/markdown/MarkdownRenderer.mjs +62 -0
- package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -0
- package/dist/esm/markdown/index.mjs +3 -0
- package/dist/esm/markdown/index.mjs.map +1 -0
- package/dist/esm/plugins.mjs +104 -0
- package/dist/esm/plugins.mjs.map +1 -0
- package/dist/esm/preactElement/renderPreactElement.mjs +38 -0
- package/dist/esm/preactElement/renderPreactElement.mjs.map +1 -0
- package/dist/types/IntlayerNode.d.ts +15 -0
- package/dist/types/IntlayerNode.d.ts.map +1 -0
- package/dist/types/UI/ContentSelector.d.ts +10 -0
- package/dist/types/UI/ContentSelector.d.ts.map +1 -0
- package/dist/types/client/IntlayerProvider.d.ts +29 -0
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -0
- package/dist/types/client/getBrowserLocale.d.ts +25 -0
- package/dist/types/client/getBrowserLocale.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +12 -0
- package/dist/types/client/index.d.ts.map +1 -0
- package/dist/types/client/t.d.ts +9 -0
- package/dist/types/client/t.d.ts.map +1 -0
- package/dist/types/client/useContent.d.ts +10 -0
- package/dist/types/client/useContent.d.ts.map +1 -0
- package/dist/types/client/useDictionary.d.ts +9 -0
- package/dist/types/client/useDictionary.d.ts.map +1 -0
- package/dist/types/client/useDictionaryDynamic.d.ts +9 -0
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -0
- package/dist/types/client/useIntlayer.d.ts +11 -0
- package/dist/types/client/useIntlayer.d.ts.map +1 -0
- package/dist/types/client/useIntlayerAsync.d.ts +14 -0
- package/dist/types/client/useIntlayerAsync.d.ts.map +1 -0
- package/dist/types/client/useLoadDynamic.d.ts +2 -0
- package/dist/types/client/useLoadDynamic.d.ts.map +1 -0
- package/dist/types/client/useLocale.d.ts +15 -0
- package/dist/types/client/useLocale.d.ts.map +1 -0
- package/dist/types/client/useLocaleBase.d.ts +10 -0
- package/dist/types/client/useLocaleBase.d.ts.map +1 -0
- package/dist/types/client/useLocaleCookie.d.ts +17 -0
- package/dist/types/client/useLocaleCookie.d.ts.map +1 -0
- package/dist/types/client/useTraduction.d.ts +24 -0
- package/dist/types/client/useTraduction.d.ts.map +1 -0
- package/dist/types/editor/ChangedContentContext.d.ts +13 -0
- package/dist/types/editor/ChangedContentContext.d.ts.map +1 -0
- package/dist/types/editor/CommunicatorContext.d.ts +14 -0
- package/dist/types/editor/CommunicatorContext.d.ts.map +1 -0
- package/dist/types/editor/ConfigurationContext.d.ts +9 -0
- package/dist/types/editor/ConfigurationContext.d.ts.map +1 -0
- package/dist/types/editor/ContentSelectorWrapper.d.ts +5 -0
- package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -0
- package/dist/types/editor/DictionariesRecordContext.d.ts +16 -0
- package/dist/types/editor/DictionariesRecordContext.d.ts.map +1 -0
- package/dist/types/editor/EditedContentContext.d.ts +33 -0
- package/dist/types/editor/EditedContentContext.d.ts.map +1 -0
- package/dist/types/editor/EditorEnabledContext.d.ts +11 -0
- package/dist/types/editor/EditorEnabledContext.d.ts.map +1 -0
- package/dist/types/editor/EditorProvider.d.ts +6 -0
- package/dist/types/editor/EditorProvider.d.ts.map +1 -0
- package/dist/types/editor/FocusDictionaryContext.d.ts +21 -0
- package/dist/types/editor/FocusDictionaryContext.d.ts.map +1 -0
- package/dist/types/editor/IntlayerEditorProvider.d.ts +5 -0
- package/dist/types/editor/IntlayerEditorProvider.d.ts.map +1 -0
- package/dist/types/editor/index.d.ts +2 -0
- package/dist/types/editor/index.d.ts.map +1 -0
- package/dist/types/editor/useCrossFrameMessageListener.d.ts +19 -0
- package/dist/types/editor/useCrossFrameMessageListener.d.ts.map +1 -0
- package/dist/types/editor/useCrossFrameState.d.ts +30 -0
- package/dist/types/editor/useCrossFrameState.d.ts.map +1 -0
- package/dist/types/editor/useCrossURLPathState.d.ts +4 -0
- package/dist/types/editor/useCrossURLPathState.d.ts.map +1 -0
- package/dist/types/editor/useEditedContentRenderer.d.ts +13 -0
- package/dist/types/editor/useEditedContentRenderer.d.ts.map +1 -0
- package/dist/types/editor/useIframeClickInterceptor.d.ts +3 -0
- package/dist/types/editor/useIframeClickInterceptor.d.ts.map +1 -0
- package/dist/types/getDictionary.d.ts +5 -0
- package/dist/types/getDictionary.d.ts.map +1 -0
- package/dist/types/getIntlayer.d.ts +5 -0
- package/dist/types/getIntlayer.d.ts.map +1 -0
- package/dist/types/index.d.ts +8 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/markdown/MarkdownProvider.d.ts +9 -0
- package/dist/types/markdown/MarkdownProvider.d.ts.map +1 -0
- package/dist/types/markdown/MarkdownRenderer.d.ts +16 -0
- package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -0
- package/dist/types/markdown/index.d.ts +3 -0
- package/dist/types/markdown/index.d.ts.map +1 -0
- package/dist/types/plugins.d.ts +54 -0
- package/dist/types/plugins.d.ts.map +1 -0
- package/dist/types/preactElement/renderPreactElement.d.ts +5 -0
- package/dist/types/preactElement/renderPreactElement.d.ts.map +1 -0
- package/package.json +15 -8
- package/dist/cjs/intlayerMiddlewarePlugin.cjs +0 -224
- package/dist/cjs/intlayerMiddlewarePlugin.cjs.map +0 -1
- package/dist/cjs/intlayerPlugin.cjs +0 -76
- package/dist/cjs/intlayerPlugin.cjs.map +0 -1
- package/dist/esm/intlayerMiddlewarePlugin.mjs +0 -200
- package/dist/esm/intlayerMiddlewarePlugin.mjs.map +0 -1
- package/dist/esm/intlayerPlugin.mjs +0 -52
- package/dist/esm/intlayerPlugin.mjs.map +0 -1
- package/dist/types/intlayerMiddlewarePlugin.d.ts +0 -6
- package/dist/types/intlayerMiddlewarePlugin.d.ts.map +0 -1
- package/dist/types/intlayerPlugin.d.ts +0 -16
- package/dist/types/intlayerPlugin.d.ts.map +0 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
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
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(CommunicatorContext_exports);
|
|
36
|
+
var import_jsx_runtime = require("preact/jsx-runtime");
|
|
37
|
+
var import_built = __toESM(require("@intlayer/config/built"));
|
|
38
|
+
var import_preact = require("preact");
|
|
39
|
+
var import_hooks = require("preact/hooks");
|
|
40
|
+
var import_uuid = require("uuid");
|
|
41
|
+
const { editor } = import_built.default;
|
|
42
|
+
const CommunicatorContext = (0, import_preact.createContext)({
|
|
43
|
+
postMessage: () => null,
|
|
44
|
+
allowedOrigins: [
|
|
45
|
+
editor?.applicationURL,
|
|
46
|
+
editor?.editorURL,
|
|
47
|
+
editor?.cmsURL
|
|
48
|
+
],
|
|
49
|
+
senderId: ""
|
|
50
|
+
});
|
|
51
|
+
const CommunicatorProvider = ({ children, allowedOrigins, postMessage }) => {
|
|
52
|
+
const senderIdRef = (0, import_hooks.useRef)((0, import_uuid.v4)());
|
|
53
|
+
const value = (0, import_hooks.useMemo)(
|
|
54
|
+
() => ({ postMessage, allowedOrigins, senderId: senderIdRef.current }),
|
|
55
|
+
[postMessage, allowedOrigins]
|
|
56
|
+
// senderIdRef.current is stable
|
|
57
|
+
);
|
|
58
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CommunicatorContext.Provider, { value, children });
|
|
59
|
+
};
|
|
60
|
+
const useCommunicator = () => (0, import_hooks.useContext)(CommunicatorContext);
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
CommunicatorProvider,
|
|
64
|
+
useCommunicator
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=CommunicatorContext.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/CommunicatorContext.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\n\nimport {\n createContext,\n type ComponentChildren,\n type FunctionComponent,\n} from 'preact';\nimport { useContext, useMemo, useRef } from 'preact/hooks';\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 = {\n children?: ComponentChildren;\n postMessage: typeof window.postMessage;\n allowedOrigins?: string[];\n};\n\nexport const CommunicatorProvider: FunctionComponent<\n CommunicatorProviderProps\n> = ({ children, allowedOrigins, postMessage }) => {\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 is stable\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;AAgDI;AA9CJ,mBAA0B;AAE1B,oBAIO;AACP,mBAA4C;AAC5C,kBAA2B;AAQ3B,MAAM,EAAE,OAAO,IAAI,aAAAA;AAEnB,MAAM,0BAAsB,6BAA0C;AAAA,EACpE,aAAa,MAAM;AAAA,EACnB,gBAAgB;AAAA,IACd,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV;AAAA,EACA,UAAU;AACZ,CAAC;AAQM,MAAM,uBAET,CAAC,EAAE,UAAU,gBAAgB,YAAY,MAAM;AAEjD,QAAM,kBAAc,yBAAO,YAAAC,IAAK,CAAC;AAEjC,QAAM,YAAQ;AAAA,IACZ,OAAO,EAAE,aAAa,gBAAgB,UAAU,YAAY,QAAQ;AAAA,IACpE,CAAC,aAAa,cAAc;AAAA;AAAA,EAC9B;AAEA,SACE,4CAAC,oBAAoB,UAApB,EAA6B,OAC3B,UACH;AAEJ;AAEO,MAAM,kBAAkB,UAAM,yBAAW,mBAAmB;","names":["configuration","uuid"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
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 ConfigurationContext_exports = {};
|
|
21
|
+
__export(ConfigurationContext_exports, {
|
|
22
|
+
ConfigurationProvider: () => ConfigurationProvider,
|
|
23
|
+
useConfiguration: () => useConfiguration,
|
|
24
|
+
useConfigurationState: () => useConfigurationState
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(ConfigurationContext_exports);
|
|
27
|
+
var import_jsx_runtime = require("preact/jsx-runtime");
|
|
28
|
+
var import_editor = require("@intlayer/editor");
|
|
29
|
+
var import_compat = require("preact/compat");
|
|
30
|
+
var import_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
31
|
+
const ConfigurationStatesContext = (0, import_compat.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_compat.useContext)(ConfigurationStatesContext);
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
ConfigurationProvider,
|
|
47
|
+
useConfiguration,
|
|
48
|
+
useConfigurationState
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=ConfigurationContext.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/ConfigurationContext.tsx"],"sourcesContent":["'use client';\n\nimport { type IntlayerConfig } from '@intlayer/config/client';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n type FC,\n type PropsWithChildren,\n createContext,\n useContext,\n} from 'preact/compat';\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":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiCE;AA9BF,oBAA2B;AAC3B,oBAKO;AACP,gCAAmC;AAEnC,MAAM,iCAA6B;AAAA,EACjC;AACF;AAEO,MAAM,wBAAwB,UACnC;AAAA,EACE,yBAAW;AAAA,EACX;AAAA,EACA;AAAA,IACE,SAAS;AAAA,IACT,MAAM;AAAA,EACR;AACF;AAMK,MAAM,wBAET,CAAC,EAAE,UAAU,cAAc,MAC7B,4CAAC,2BAA2B,UAA3B,EAAoC,OAAO,eACzC,UACH;AAGK,MAAM,mBAAmB,UAAM,0BAAW,0BAA0B;","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 ContentSelectorWrapper_exports = {};
|
|
21
|
+
__export(ContentSelectorWrapper_exports, {
|
|
22
|
+
ContentSelectorRenderer: () => ContentSelectorRenderer
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(ContentSelectorWrapper_exports);
|
|
25
|
+
var import_jsx_runtime = require("preact/jsx-runtime");
|
|
26
|
+
var import_core = require("@intlayer/core");
|
|
27
|
+
var import_compat = require("preact/compat");
|
|
28
|
+
var import_client = require('../client/index.cjs');
|
|
29
|
+
var import_ContentSelector = require('../UI/ContentSelector.cjs');
|
|
30
|
+
var import_EditorEnabledContext = require('./EditorEnabledContext.cjs');
|
|
31
|
+
var import_FocusDictionaryContext = require('./FocusDictionaryContext.cjs');
|
|
32
|
+
const ContentSelectorWrapperContent = ({
|
|
33
|
+
children,
|
|
34
|
+
dictionaryKey,
|
|
35
|
+
keyPath
|
|
36
|
+
}) => {
|
|
37
|
+
const { focusedContent, setFocusedContent } = (0, import_FocusDictionaryContext.useFocusDictionary)();
|
|
38
|
+
const handleSelect = (0, import_compat.useCallback)(
|
|
39
|
+
() => setFocusedContent({
|
|
40
|
+
dictionaryKey,
|
|
41
|
+
keyPath
|
|
42
|
+
}),
|
|
43
|
+
[dictionaryKey, keyPath]
|
|
44
|
+
);
|
|
45
|
+
const isSelected = (0, import_compat.useMemo)(
|
|
46
|
+
() => (focusedContent?.dictionaryKey === dictionaryKey && (focusedContent?.keyPath?.length ?? 0) > 0 && (0, import_core.isSameKeyPath)(focusedContent?.keyPath ?? [], keyPath)) ?? false,
|
|
47
|
+
[focusedContent, keyPath, dictionaryKey]
|
|
48
|
+
);
|
|
49
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ContentSelector.ContentSelector, { onPress: handleSelect, isSelecting: isSelected, children });
|
|
50
|
+
};
|
|
51
|
+
const ContentSelectorRenderer = ({
|
|
52
|
+
children,
|
|
53
|
+
...props
|
|
54
|
+
}) => {
|
|
55
|
+
const { enabled } = (0, import_EditorEnabledContext.useEditorEnabled)();
|
|
56
|
+
const { disableEditor } = (0, import_client.useIntlayerContext)();
|
|
57
|
+
if (enabled && !disableEditor) {
|
|
58
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContentSelectorWrapperContent, { ...props, children });
|
|
59
|
+
}
|
|
60
|
+
return children;
|
|
61
|
+
};
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
ContentSelectorRenderer
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=ContentSelectorWrapper.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["'use client';\n\nimport { type NodeProps, isSameKeyPath } from '@intlayer/core';\nimport {\n type FC,\n type HTMLAttributes,\n useCallback,\n useMemo,\n} from 'preact/compat';\nimport { useIntlayerContext } from '../client';\nimport { ContentSelector } from '../UI/ContentSelector';\nimport { useEditorEnabled } from './EditorEnabledContext';\nimport { useFocusDictionary } from './FocusDictionaryContext';\n\nexport type ContentSelectorWrapperProps = NodeProps &\n Omit<HTMLAttributes<HTMLDivElement>, 'children'>;\n\nconst ContentSelectorWrapperContent: FC<ContentSelectorWrapperProps> = ({\n children,\n dictionaryKey,\n keyPath,\n}) => {\n const { focusedContent, setFocusedContent } = useFocusDictionary();\n\n const handleSelect = useCallback(\n () =>\n setFocusedContent({\n dictionaryKey,\n keyPath,\n }),\n [dictionaryKey, keyPath]\n );\n\n const isSelected = useMemo(\n () =>\n (focusedContent?.dictionaryKey === dictionaryKey &&\n (focusedContent?.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent?.keyPath ?? [], keyPath)) ??\n false,\n [focusedContent, keyPath, dictionaryKey]\n );\n\n return (\n <ContentSelector onPress={handleSelect} isSelecting={isSelected}>\n {children}\n </ContentSelector>\n );\n};\n\nexport const ContentSelectorRenderer: FC<ContentSelectorWrapperProps> = ({\n children,\n ...props\n}) => {\n const { enabled } = useEditorEnabled();\n const { disableEditor } = useIntlayerContext();\n\n if (enabled && !disableEditor) {\n return (\n <ContentSelectorWrapperContent {...props}>\n {children}\n </ContentSelectorWrapperContent>\n );\n }\n\n return children;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2CI;AAzCJ,kBAA8C;AAC9C,oBAKO;AACP,oBAAmC;AACnC,6BAAgC;AAChC,kCAAiC;AACjC,oCAAmC;AAKnC,MAAM,gCAAiE,CAAC;AAAA,EACtE;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,EAAE,gBAAgB,kBAAkB,QAAI,kDAAmB;AAEjE,QAAM,mBAAe;AAAA,IACnB,MACE,kBAAkB;AAAA,MAChB;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,CAAC,eAAe,OAAO;AAAA,EACzB;AAEA,QAAM,iBAAa;AAAA,IACjB,OACG,gBAAgB,kBAAkB,kBAChC,gBAAgB,SAAS,UAAU,KAAK,SACzC,2BAAc,gBAAgB,WAAW,CAAC,GAAG,OAAO,MACtD;AAAA,IACF,CAAC,gBAAgB,SAAS,aAAa;AAAA,EACzC;AAEA,SACE,4CAAC,0CAAgB,SAAS,cAAc,aAAa,YAClD,UACH;AAEJ;AAEO,MAAM,0BAA2D,CAAC;AAAA,EACvE;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,EAAE,QAAQ,QAAI,8CAAiB;AACrC,QAAM,EAAE,cAAc,QAAI,kCAAmB;AAE7C,MAAI,WAAW,CAAC,eAAe;AAC7B,WACE,4CAAC,iCAA+B,GAAG,OAChC,UACH;AAAA,EAEJ;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,77 @@
|
|
|
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 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("preact/jsx-runtime");
|
|
28
|
+
var import_editor = require("@intlayer/editor");
|
|
29
|
+
var import_compat = require("preact/compat");
|
|
30
|
+
var import_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
31
|
+
const DictionariesRecordStatesContext = (0, import_compat.createContext)(void 0);
|
|
32
|
+
const DictionariesRecordActionsContext = (0, import_compat.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_compat.useMemo)(
|
|
41
|
+
() => ({
|
|
42
|
+
localeDictionaries: localeDictionaries ?? {}
|
|
43
|
+
}),
|
|
44
|
+
[localeDictionaries]
|
|
45
|
+
);
|
|
46
|
+
const actionValue = (0, import_compat.useMemo)(
|
|
47
|
+
() => ({
|
|
48
|
+
setLocaleDictionaries,
|
|
49
|
+
setLocaleDictionary: (dictionary) => {
|
|
50
|
+
setLocaleDictionaries((dictionaries) => ({
|
|
51
|
+
...dictionaries,
|
|
52
|
+
[dictionary.key]: dictionary
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
}),
|
|
56
|
+
[setLocaleDictionaries]
|
|
57
|
+
);
|
|
58
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DictionariesRecordStatesContext.Provider, { value: stateValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DictionariesRecordActionsContext.Provider, { value: actionValue, children }) });
|
|
59
|
+
};
|
|
60
|
+
const useDictionariesRecordActions = () => (0, import_compat.useContext)(DictionariesRecordActionsContext);
|
|
61
|
+
const useDictionariesRecord = () => {
|
|
62
|
+
const actionsContext = useDictionariesRecordActions();
|
|
63
|
+
const statesContext = (0, import_compat.useContext)(DictionariesRecordStatesContext);
|
|
64
|
+
if (!statesContext) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
"useDictionariesRecordStates must be used within a DictionariesRecordProvider"
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
return { ...statesContext, ...actionsContext };
|
|
70
|
+
};
|
|
71
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
72
|
+
0 && (module.exports = {
|
|
73
|
+
DictionariesRecordProvider,
|
|
74
|
+
useDictionariesRecord,
|
|
75
|
+
useDictionariesRecordActions
|
|
76
|
+
});
|
|
77
|
+
//# sourceMappingURL=DictionariesRecordContext.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/DictionariesRecordContext.tsx"],"sourcesContent":["'use client';\n\nimport type { Dictionary } from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n useContext,\n useMemo,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n} from 'preact/compat';\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 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 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;AA+DM;AA5DN,oBAA2B;AAC3B,oBAQO;AACP,gCAAmC;AAYnC,MAAM,sCAAkC,6BAEtC,MAAS;AACX,MAAM,uCAAmC,6BAEvC,MAAS;AAEJ,MAAM,6BAAoD,CAAC;AAAA,EAChE;AACF,MAAM;AACJ,QAAM,CAAC,oBAAoB,qBAAqB,QAC9C;AAAA,IACE,yBAAW;AAAA,IACX;AAAA,EACF;AAEF,QAAM,iBAAa;AAAA,IACjB,OAAO;AAAA,MACL,oBAAoB,sBAAsB,CAAC;AAAA,IAC7C;AAAA,IACA,CAAC,kBAAkB;AAAA,EACrB;AAEA,QAAM,kBAAc;AAAA,IAClB,OAAO;AAAA,MACL;AAAA,MACA,qBAAqB,CAAC,eAA2B;AAC/C,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,0BAAW,gCAAgC;AAEtC,MAAM,wBAAwB,MAAM;AACzC,QAAM,iBAAiB,6BAA6B;AACpD,QAAM,oBAAgB,0BAAW,+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":[]}
|
|
@@ -0,0 +1,217 @@
|
|
|
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 EditedContentContext_exports = {};
|
|
21
|
+
__export(EditedContentContext_exports, {
|
|
22
|
+
EditedContentProvider: () => EditedContentProvider,
|
|
23
|
+
useEditedContent: () => useEditedContent,
|
|
24
|
+
useEditedContentActions: () => useEditedContentActions,
|
|
25
|
+
useGetEditedContentState: () => useGetEditedContentState,
|
|
26
|
+
usePostEditedContentState: () => usePostEditedContentState
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(EditedContentContext_exports);
|
|
29
|
+
var import_jsx_runtime = require("preact/jsx-runtime");
|
|
30
|
+
var import_core = require("@intlayer/core");
|
|
31
|
+
var import_editor = require("@intlayer/editor");
|
|
32
|
+
var import_compat = require("preact/compat");
|
|
33
|
+
var import_DictionariesRecordContext = require('./DictionariesRecordContext.cjs');
|
|
34
|
+
var import_useCrossFrameMessageListener = require('./useCrossFrameMessageListener.cjs');
|
|
35
|
+
var import_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
36
|
+
const EditedContentStateContext = (0, import_compat.createContext)(void 0);
|
|
37
|
+
const usePostEditedContentState = (onEventTriggered) => (0, import_useCrossFrameMessageListener.useCrossFrameMessageListener)(
|
|
38
|
+
`${import_editor.MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/post`,
|
|
39
|
+
onEventTriggered
|
|
40
|
+
);
|
|
41
|
+
const useGetEditedContentState = (onEventTriggered) => (0, import_useCrossFrameMessageListener.useCrossFrameMessageListener)(
|
|
42
|
+
`${import_editor.MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/get`,
|
|
43
|
+
onEventTriggered
|
|
44
|
+
);
|
|
45
|
+
const EditedContentActionsContext = (0, import_compat.createContext)(void 0);
|
|
46
|
+
const resolveState = (state, prevState) => typeof state === "function" ? state(prevState) : state;
|
|
47
|
+
const EditedContentProvider = ({ children }) => {
|
|
48
|
+
const { localeDictionaries } = (0, import_DictionariesRecordContext.useDictionariesRecord)();
|
|
49
|
+
const [editedContent, setEditedContentState] = (0, import_useCrossFrameState.useCrossFrameState)(
|
|
50
|
+
import_editor.MessageKey.INTLAYER_EDITED_CONTENT_CHANGED
|
|
51
|
+
);
|
|
52
|
+
const setEditedDictionary = (newValue) => {
|
|
53
|
+
let updatedDictionaries = resolveState(newValue);
|
|
54
|
+
setEditedContentState((prev) => {
|
|
55
|
+
updatedDictionaries = resolveState(
|
|
56
|
+
newValue,
|
|
57
|
+
prev?.[updatedDictionaries.key]
|
|
58
|
+
);
|
|
59
|
+
return {
|
|
60
|
+
...prev,
|
|
61
|
+
[updatedDictionaries.key]: updatedDictionaries
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
return updatedDictionaries;
|
|
65
|
+
};
|
|
66
|
+
const setEditedContent = (dictionaryKey, newValue) => {
|
|
67
|
+
setEditedContentState((prev) => ({
|
|
68
|
+
...prev,
|
|
69
|
+
[dictionaryKey]: {
|
|
70
|
+
...prev?.[dictionaryKey],
|
|
71
|
+
content: newValue
|
|
72
|
+
}
|
|
73
|
+
}));
|
|
74
|
+
};
|
|
75
|
+
const addEditedContent = (dictionaryKey, newValue, keyPath = [], overwrite = true) => {
|
|
76
|
+
setEditedContentState((prev) => {
|
|
77
|
+
const originalContent = localeDictionaries[dictionaryKey]?.content;
|
|
78
|
+
const currentContent = structuredClone(
|
|
79
|
+
prev?.[dictionaryKey]?.content ?? originalContent
|
|
80
|
+
);
|
|
81
|
+
let newKeyPath = keyPath;
|
|
82
|
+
if (!overwrite) {
|
|
83
|
+
let index = 0;
|
|
84
|
+
const otherKeyPath = keyPath.slice(0, -1);
|
|
85
|
+
const lastKeyPath = keyPath[keyPath.length - 1];
|
|
86
|
+
let finalKey = lastKeyPath.key;
|
|
87
|
+
while (typeof (0, import_core.getContentNodeByKeyPath)(currentContent, newKeyPath) !== "undefined") {
|
|
88
|
+
index++;
|
|
89
|
+
finalKey = index === 0 ? lastKeyPath.key : `${lastKeyPath.key} (${index})`;
|
|
90
|
+
newKeyPath = [
|
|
91
|
+
...otherKeyPath,
|
|
92
|
+
{ ...lastKeyPath, key: finalKey }
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const updatedContent = (0, import_core.editDictionaryByKeyPath)(
|
|
97
|
+
currentContent,
|
|
98
|
+
newKeyPath,
|
|
99
|
+
newValue
|
|
100
|
+
);
|
|
101
|
+
return {
|
|
102
|
+
...prev,
|
|
103
|
+
[dictionaryKey]: {
|
|
104
|
+
...prev?.[dictionaryKey],
|
|
105
|
+
content: updatedContent
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
const renameEditedContent = (dictionaryKey, newKey, keyPath = []) => {
|
|
111
|
+
setEditedContentState((prev) => {
|
|
112
|
+
const originalContent = localeDictionaries[dictionaryKey]?.content;
|
|
113
|
+
const currentContent = structuredClone(
|
|
114
|
+
prev?.[dictionaryKey]?.content ?? originalContent
|
|
115
|
+
);
|
|
116
|
+
const contentWithNewField = (0, import_core.renameContentNodeByKeyPath)(
|
|
117
|
+
currentContent,
|
|
118
|
+
newKey,
|
|
119
|
+
keyPath
|
|
120
|
+
);
|
|
121
|
+
return {
|
|
122
|
+
...prev,
|
|
123
|
+
[dictionaryKey]: {
|
|
124
|
+
...prev?.[dictionaryKey],
|
|
125
|
+
content: contentWithNewField
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
const removeEditedContent = (dictionaryKey, keyPath) => {
|
|
131
|
+
setEditedContentState((prev) => {
|
|
132
|
+
const originalContent = localeDictionaries[dictionaryKey]?.content;
|
|
133
|
+
const currentContent = structuredClone(
|
|
134
|
+
prev?.[dictionaryKey]?.content ?? originalContent
|
|
135
|
+
);
|
|
136
|
+
const initialContent = (0, import_core.getContentNodeByKeyPath)(originalContent, keyPath);
|
|
137
|
+
const restoredContent = (0, import_core.editDictionaryByKeyPath)(
|
|
138
|
+
currentContent,
|
|
139
|
+
keyPath,
|
|
140
|
+
initialContent
|
|
141
|
+
);
|
|
142
|
+
return {
|
|
143
|
+
...prev,
|
|
144
|
+
[dictionaryKey]: {
|
|
145
|
+
...prev?.[dictionaryKey],
|
|
146
|
+
content: restoredContent
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
const restoreEditedContent = (dictionaryKey) => {
|
|
152
|
+
setEditedContentState((prev) => {
|
|
153
|
+
const updated = { ...prev };
|
|
154
|
+
delete updated[dictionaryKey];
|
|
155
|
+
return updated;
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
const clearEditedDictionaryContent = (dictionaryKey) => {
|
|
159
|
+
setEditedContentState((prev) => {
|
|
160
|
+
const filtered = Object.entries(prev).reduce((acc, [key, value]) => {
|
|
161
|
+
if (key === dictionaryKey) {
|
|
162
|
+
return acc;
|
|
163
|
+
}
|
|
164
|
+
return { ...acc, [key]: value };
|
|
165
|
+
}, {});
|
|
166
|
+
return filtered;
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
const clearEditedContent = () => {
|
|
170
|
+
setEditedContentState({});
|
|
171
|
+
};
|
|
172
|
+
const getEditedContentValue = (dictionaryKey, keyPath) => {
|
|
173
|
+
const currentContent = editedContent?.[dictionaryKey]?.content ?? {};
|
|
174
|
+
return (0, import_core.getContentNodeByKeyPath)(currentContent, keyPath);
|
|
175
|
+
};
|
|
176
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
177
|
+
EditedContentStateContext.Provider,
|
|
178
|
+
{
|
|
179
|
+
value: {
|
|
180
|
+
editedContent
|
|
181
|
+
},
|
|
182
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
183
|
+
EditedContentActionsContext.Provider,
|
|
184
|
+
{
|
|
185
|
+
value: {
|
|
186
|
+
setEditedContentState,
|
|
187
|
+
setEditedDictionary,
|
|
188
|
+
setEditedContent,
|
|
189
|
+
addEditedContent,
|
|
190
|
+
renameEditedContent,
|
|
191
|
+
removeEditedContent,
|
|
192
|
+
restoreEditedContent,
|
|
193
|
+
clearEditedDictionaryContent,
|
|
194
|
+
clearEditedContent,
|
|
195
|
+
getEditedContentValue
|
|
196
|
+
},
|
|
197
|
+
children
|
|
198
|
+
}
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
);
|
|
202
|
+
};
|
|
203
|
+
const useEditedContentActions = () => (0, import_compat.useContext)(EditedContentActionsContext);
|
|
204
|
+
const useEditedContent = () => {
|
|
205
|
+
const stateContext = (0, import_compat.useContext)(EditedContentStateContext);
|
|
206
|
+
const actionContext = useEditedContentActions();
|
|
207
|
+
return { ...stateContext, ...actionContext };
|
|
208
|
+
};
|
|
209
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
210
|
+
0 && (module.exports = {
|
|
211
|
+
EditedContentProvider,
|
|
212
|
+
useEditedContent,
|
|
213
|
+
useEditedContentActions,
|
|
214
|
+
useGetEditedContentState,
|
|
215
|
+
usePostEditedContentState
|
|
216
|
+
});
|
|
217
|
+
//# sourceMappingURL=EditedContentContext.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/EditedContentContext.tsx"],"sourcesContent":["'use client';\n\nimport {\n editDictionaryByKeyPath,\n getContentNodeByKeyPath,\n renameContentNodeByKeyPath,\n type ContentNode,\n type Dictionary,\n type KeyPath,\n} from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n useContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n} from 'preact/compat';\nimport {\n useDictionariesRecord,\n type DictionaryContent,\n} from './DictionariesRecordContext';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\nimport { useCrossFrameState } from './useCrossFrameState';\n\ntype EditedContentStateContextType = {\n editedContent: Record<Dictionary['key'], Dictionary> | undefined;\n};\n\nconst EditedContentStateContext = createContext<\n EditedContentStateContextType | undefined\n>(undefined);\n\nexport const usePostEditedContentState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/post`,\n onEventTriggered\n );\n\nexport const useGetEditedContentState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITED_CONTENT_CHANGED}/get`,\n onEventTriggered\n );\n\ntype EditedContentActionsContextType = {\n setEditedContentState: (\n editedContent: Record<Dictionary['key'], Dictionary>\n ) => void;\n setEditedDictionary: Dispatch<SetStateAction<Dictionary>>;\n setEditedContent: (\n dictionaryKey: Dictionary['key'],\n newValue: Dictionary['content']\n ) => void;\n addEditedContent: (\n dictionaryKey: Dictionary['key'],\n newValue: ContentNode<any>,\n keyPath?: KeyPath[],\n overwrite?: boolean\n ) => void;\n renameEditedContent: (\n dictionaryKey: Dictionary['key'],\n newKey: KeyPath['key'],\n keyPath?: KeyPath[]\n ) => void;\n removeEditedContent: (\n dictionaryKey: Dictionary['key'],\n keyPath: KeyPath[]\n ) => void;\n restoreEditedContent: (dictionaryKey: Dictionary['key']) => void;\n clearEditedDictionaryContent: (dictionaryKey: Dictionary['key']) => void;\n clearEditedContent: () => void;\n getEditedContentValue: (\n dictionaryKey: Dictionary['key'],\n keyPath: KeyPath[]\n ) => ContentNode | undefined;\n};\n\nconst EditedContentActionsContext = createContext<\n EditedContentActionsContextType | undefined\n>(undefined);\n\nconst resolveState = <S,>(state?: SetStateAction<S>, prevState?: S): S =>\n typeof state === 'function'\n ? (state as (prevState?: S) => S)(prevState)\n : (state as S);\n\nexport const EditedContentProvider: FC<PropsWithChildren> = ({ children }) => {\n const { localeDictionaries } = useDictionariesRecord();\n\n const [editedContent, setEditedContentState] =\n useCrossFrameState<DictionaryContent>(\n MessageKey.INTLAYER_EDITED_CONTENT_CHANGED\n );\n\n const setEditedDictionary: Dispatch<SetStateAction<Dictionary>> = (\n newValue\n ) => {\n let updatedDictionaries: Dictionary = resolveState(newValue);\n\n setEditedContentState((prev) => {\n updatedDictionaries = resolveState(\n newValue,\n prev?.[updatedDictionaries.key]\n );\n\n return {\n ...prev,\n [updatedDictionaries.key]: updatedDictionaries,\n };\n });\n\n return updatedDictionaries;\n };\n\n const setEditedContent = (\n dictionaryKey: Dictionary['key'],\n newValue: Dictionary['content']\n ) => {\n setEditedContentState((prev) => ({\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: newValue,\n },\n }));\n };\n\n const addEditedContent = (\n dictionaryKey: Dictionary['key'],\n newValue: ContentNode,\n keyPath: KeyPath[] = [],\n overwrite: boolean = true\n ) => {\n setEditedContentState((prev) => {\n // Get the starting content: edited version if available, otherwise a deep copy of the original\n const originalContent = localeDictionaries[dictionaryKey]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryKey]?.content ?? originalContent\n );\n\n let newKeyPath = keyPath;\n if (!overwrite) {\n // Find a unique key based on the keyPath provided\n let index = 0;\n const otherKeyPath = keyPath.slice(0, -1);\n const lastKeyPath: KeyPath = keyPath[keyPath.length - 1];\n let finalKey = lastKeyPath.key;\n\n // Loop until we find a key that does not exist\n while (\n typeof getContentNodeByKeyPath(currentContent, newKeyPath) !==\n 'undefined'\n ) {\n index++;\n finalKey =\n index === 0 ? lastKeyPath.key : `${lastKeyPath.key} (${index})`;\n newKeyPath = [\n ...otherKeyPath,\n { ...lastKeyPath, key: finalKey } as KeyPath,\n ];\n }\n }\n\n const updatedContent = editDictionaryByKeyPath(\n currentContent,\n newKeyPath,\n newValue\n );\n\n return {\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: updatedContent as Dictionary['content'],\n },\n };\n });\n };\n\n const renameEditedContent = (\n dictionaryKey: Dictionary['key'],\n newKey: KeyPath['key'],\n keyPath: KeyPath[] = []\n ) => {\n setEditedContentState((prev) => {\n // Retrieve the base content: use edited version if available, otherwise deep copy of original\n const originalContent = localeDictionaries[dictionaryKey]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryKey]?.content ?? originalContent\n );\n\n const contentWithNewField = renameContentNodeByKeyPath(\n currentContent,\n newKey,\n keyPath\n );\n\n return {\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: contentWithNewField as Dictionary['content'],\n },\n };\n });\n };\n\n const removeEditedContent = (\n dictionaryKey: Dictionary['key'],\n keyPath: KeyPath[]\n ) => {\n setEditedContentState((prev) => {\n // Retrieve the original content as reference\n const originalContent = localeDictionaries[dictionaryKey]?.content;\n const currentContent = structuredClone(\n prev?.[dictionaryKey]?.content ?? originalContent\n );\n\n // Get the initial value from the original dictionary content\n const initialContent = getContentNodeByKeyPath(originalContent, keyPath);\n\n // Restore the value at the given keyPath\n const restoredContent = editDictionaryByKeyPath(\n currentContent,\n keyPath,\n initialContent\n );\n\n return {\n ...prev,\n [dictionaryKey]: {\n ...prev?.[dictionaryKey],\n content: restoredContent as Dictionary['content'],\n },\n };\n });\n };\n\n const restoreEditedContent = (dictionaryKey: Dictionary['key']) => {\n setEditedContentState((prev) => {\n const updated = { ...prev };\n delete updated[dictionaryKey];\n return updated;\n });\n };\n\n const clearEditedDictionaryContent = (dictionaryKey: Dictionary['key']) => {\n setEditedContentState((prev) => {\n const filtered = Object.entries(prev).reduce((acc, [key, value]) => {\n if (key === dictionaryKey) {\n return acc;\n }\n return { ...acc, [key]: value };\n }, {} as DictionaryContent);\n return filtered;\n });\n };\n\n const clearEditedContent = () => {\n setEditedContentState({});\n };\n\n const getEditedContentValue = (\n dictionaryKey: Dictionary['key'],\n keyPath: KeyPath[]\n ): ContentNode | undefined => {\n const currentContent = editedContent?.[dictionaryKey]?.content ?? {};\n return getContentNodeByKeyPath(currentContent, keyPath);\n };\n\n return (\n <EditedContentStateContext.Provider\n value={{\n editedContent,\n }}\n >\n <EditedContentActionsContext.Provider\n value={{\n setEditedContentState,\n setEditedDictionary,\n setEditedContent,\n addEditedContent,\n renameEditedContent,\n removeEditedContent,\n restoreEditedContent,\n clearEditedDictionaryContent,\n clearEditedContent,\n getEditedContentValue,\n }}\n >\n {children}\n </EditedContentActionsContext.Provider>\n </EditedContentStateContext.Provider>\n );\n};\n\nexport const useEditedContentActions = () =>\n useContext(EditedContentActionsContext);\n\nexport const useEditedContent = () => {\n const stateContext = useContext(EditedContentStateContext);\n const actionContext = useEditedContentActions();\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,62 @@
|
|
|
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 EditorEnabledContext_exports = {};
|
|
21
|
+
__export(EditorEnabledContext_exports, {
|
|
22
|
+
EditorEnabledProvider: () => EditorEnabledProvider,
|
|
23
|
+
useEditorEnabled: () => useEditorEnabled,
|
|
24
|
+
useEditorEnabledState: () => useEditorEnabledState,
|
|
25
|
+
useGetEditorEnabledState: () => useGetEditorEnabledState,
|
|
26
|
+
usePostEditorEnabledState: () => usePostEditorEnabledState
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(EditorEnabledContext_exports);
|
|
29
|
+
var import_jsx_runtime = require("preact/jsx-runtime");
|
|
30
|
+
var import_editor = require("@intlayer/editor");
|
|
31
|
+
var import_compat = require("preact/compat");
|
|
32
|
+
var import_useCrossFrameMessageListener = require('./useCrossFrameMessageListener.cjs');
|
|
33
|
+
var import_useCrossFrameState = require('./useCrossFrameState.cjs');
|
|
34
|
+
const EditorEnabledContext = (0, import_compat.createContext)({
|
|
35
|
+
enabled: false
|
|
36
|
+
});
|
|
37
|
+
const useEditorEnabledState = (options) => (0, import_useCrossFrameState.useCrossFrameState)(import_editor.MessageKey.INTLAYER_EDITOR_ENABLED, false, options);
|
|
38
|
+
const usePostEditorEnabledState = (onEventTriggered) => (0, import_useCrossFrameMessageListener.useCrossFrameMessageListener)(
|
|
39
|
+
`${import_editor.MessageKey.INTLAYER_EDITOR_ENABLED}/post`,
|
|
40
|
+
onEventTriggered
|
|
41
|
+
);
|
|
42
|
+
const useGetEditorEnabledState = (onEventTriggered) => (0, import_useCrossFrameMessageListener.useCrossFrameMessageListener)(
|
|
43
|
+
`${import_editor.MessageKey.INTLAYER_EDITOR_ENABLED}/get`,
|
|
44
|
+
onEventTriggered
|
|
45
|
+
);
|
|
46
|
+
const EditorEnabledProvider = ({ children }) => {
|
|
47
|
+
const [isEnabled] = useEditorEnabledState({
|
|
48
|
+
emit: false,
|
|
49
|
+
receive: true
|
|
50
|
+
});
|
|
51
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EditorEnabledContext.Provider, { value: { enabled: isEnabled }, children });
|
|
52
|
+
};
|
|
53
|
+
const useEditorEnabled = () => (0, import_compat.useContext)(EditorEnabledContext);
|
|
54
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
55
|
+
0 && (module.exports = {
|
|
56
|
+
EditorEnabledProvider,
|
|
57
|
+
useEditorEnabled,
|
|
58
|
+
useEditorEnabledState,
|
|
59
|
+
useGetEditorEnabledState,
|
|
60
|
+
usePostEditorEnabledState
|
|
61
|
+
});
|
|
62
|
+
//# sourceMappingURL=EditorEnabledContext.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/EditorEnabledContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n useContext,\n type FC,\n type PropsWithChildren,\n} from 'preact/compat';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\nimport {\n useCrossFrameState,\n type CrossFrameStateOptions,\n} from './useCrossFrameState';\n\nexport type EditorEnabledStateProps = {\n enabled: boolean;\n};\n\nconst EditorEnabledContext = createContext<EditorEnabledStateProps>({\n enabled: false,\n});\n\nexport const useEditorEnabledState = (options?: CrossFrameStateOptions) =>\n useCrossFrameState(MessageKey.INTLAYER_EDITOR_ENABLED, false, options);\n\nexport const usePostEditorEnabledState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITOR_ENABLED}/post`,\n onEventTriggered\n );\n\nexport const useGetEditorEnabledState = <S,>(\n onEventTriggered?: (data: S) => void\n) =>\n useCrossFrameMessageListener(\n `${MessageKey.INTLAYER_EDITOR_ENABLED}/get`,\n onEventTriggered\n );\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 = () => useContext(EditorEnabledContext);\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiDI;AA/CJ,oBAA2B;AAC3B,oBAKO;AACP,0CAA6C;AAC7C,gCAGO;AAMP,MAAM,2BAAuB,6BAAuC;AAAA,EAClE,SAAS;AACX,CAAC;AAEM,MAAM,wBAAwB,CAAC,gBACpC,8CAAmB,yBAAW,yBAAyB,OAAO,OAAO;AAEhE,MAAM,4BAA4B,CACvC,yBAEA;AAAA,EACE,GAAG,yBAAW,uBAAuB;AAAA,EACrC;AACF;AAEK,MAAM,2BAA2B,CACtC,yBAEA;AAAA,EACE,GAAG,yBAAW,uBAAuB;AAAA,EACrC;AACF;AAEK,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,UAAM,0BAAW,oBAAoB;","names":[]}
|