@intlayer/editor-react 6.1.6 → 7.0.0-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/dist/cjs/CommunicatorContext.cjs +43 -65
  2. package/dist/cjs/CommunicatorContext.cjs.map +1 -1
  3. package/dist/cjs/ConfigurationContext.cjs +26 -47
  4. package/dist/cjs/ConfigurationContext.cjs.map +1 -1
  5. package/dist/cjs/DictionariesRecordContext.cjs +48 -74
  6. package/dist/cjs/DictionariesRecordContext.cjs.map +1 -1
  7. package/dist/cjs/EditedContentContext.cjs +164 -225
  8. package/dist/cjs/EditedContentContext.cjs.map +1 -1
  9. package/dist/cjs/EditorEnabledContext.cjs +34 -59
  10. package/dist/cjs/EditorEnabledContext.cjs.map +1 -1
  11. package/dist/cjs/EditorProvider.cjs +65 -66
  12. package/dist/cjs/EditorProvider.cjs.map +1 -1
  13. package/dist/cjs/FocusDictionaryContext.cjs +51 -75
  14. package/dist/cjs/FocusDictionaryContext.cjs.map +1 -1
  15. package/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
  16. package/dist/cjs/index.cjs +46 -44
  17. package/dist/cjs/useCrossFrameMessageListener.cjs +73 -50
  18. package/dist/cjs/useCrossFrameMessageListener.cjs.map +1 -1
  19. package/dist/cjs/useCrossFrameState.cjs +106 -73
  20. package/dist/cjs/useCrossFrameState.cjs.map +1 -1
  21. package/dist/cjs/useCrossURLPathState.cjs +67 -66
  22. package/dist/cjs/useCrossURLPathState.cjs.map +1 -1
  23. package/dist/cjs/useIframeClickInterceptor.cjs +24 -47
  24. package/dist/cjs/useIframeClickInterceptor.cjs.map +1 -1
  25. package/dist/esm/CommunicatorContext.mjs +34 -32
  26. package/dist/esm/CommunicatorContext.mjs.map +1 -1
  27. package/dist/esm/ConfigurationContext.mjs +19 -23
  28. package/dist/esm/ConfigurationContext.mjs.map +1 -1
  29. package/dist/esm/DictionariesRecordContext.mjs +37 -47
  30. package/dist/esm/DictionariesRecordContext.mjs.map +1 -1
  31. package/dist/esm/EditedContentContext.mjs +150 -201
  32. package/dist/esm/EditedContentContext.mjs.map +1 -1
  33. package/dist/esm/EditorEnabledContext.mjs +22 -32
  34. package/dist/esm/EditorEnabledContext.mjs.map +1 -1
  35. package/dist/esm/EditorProvider.mjs +60 -54
  36. package/dist/esm/EditorProvider.mjs.map +1 -1
  37. package/dist/esm/FocusDictionaryContext.mjs +41 -48
  38. package/dist/esm/FocusDictionaryContext.mjs.map +1 -1
  39. package/dist/esm/index.mjs +15 -13
  40. package/dist/esm/useCrossFrameMessageListener.mjs +69 -25
  41. package/dist/esm/useCrossFrameMessageListener.mjs.map +1 -1
  42. package/dist/esm/useCrossFrameState.mjs +102 -47
  43. package/dist/esm/useCrossFrameState.mjs.map +1 -1
  44. package/dist/esm/useCrossURLPathState.mjs +61 -41
  45. package/dist/esm/useCrossURLPathState.mjs.map +1 -1
  46. package/dist/esm/useIframeClickInterceptor.mjs +19 -21
  47. package/dist/esm/useIframeClickInterceptor.mjs.map +1 -1
  48. package/dist/types/CommunicatorContext.d.ts +12 -8
  49. package/dist/types/CommunicatorContext.d.ts.map +1 -1
  50. package/dist/types/ConfigurationContext.d.ts +12 -7
  51. package/dist/types/ConfigurationContext.d.ts.map +1 -1
  52. package/dist/types/DictionariesRecordContext.d.ts +15 -12
  53. package/dist/types/DictionariesRecordContext.d.ts.map +1 -1
  54. package/dist/types/EditedContentContext.d.ts +33 -30
  55. package/dist/types/EditedContentContext.d.ts.map +1 -1
  56. package/dist/types/EditorEnabledContext.d.ts +14 -9
  57. package/dist/types/EditorEnabledContext.d.ts.map +1 -1
  58. package/dist/types/EditorProvider.d.ts +10 -6
  59. package/dist/types/EditorProvider.d.ts.map +1 -1
  60. package/dist/types/FocusDictionaryContext.d.ts +18 -15
  61. package/dist/types/FocusDictionaryContext.d.ts.map +1 -1
  62. package/dist/types/index.d.ts +13 -13
  63. package/dist/types/useCrossFrameMessageListener.d.ts +7 -2
  64. package/dist/types/useCrossFrameMessageListener.d.ts.map +1 -1
  65. package/dist/types/useCrossFrameState.d.ts +10 -6
  66. package/dist/types/useCrossFrameState.d.ts.map +1 -1
  67. package/dist/types/useCrossURLPathState.d.ts +8 -3
  68. package/dist/types/useCrossURLPathState.d.ts.map +1 -1
  69. package/dist/types/useIframeClickInterceptor.d.ts +5 -2
  70. package/dist/types/useIframeClickInterceptor.d.ts.map +1 -1
  71. package/package.json +34 -40
  72. package/LICENSE +0 -202
  73. package/dist/cjs/index.cjs.map +0 -1
  74. package/dist/esm/index.mjs.map +0 -1
  75. package/dist/types/index.d.ts.map +0 -1
@@ -1,71 +1,70 @@
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 EditorProvider_exports = {};
21
- __export(EditorProvider_exports, {
22
- EditorProvider: () => EditorProvider
23
- });
24
- module.exports = __toCommonJS(EditorProvider_exports);
25
- var import_jsx_runtime = require("react/jsx-runtime");
26
- var import_react = require("react");
27
- var import_CommunicatorContext = require('./CommunicatorContext.cjs');
28
- var import_ConfigurationContext = require('./ConfigurationContext.cjs');
29
- var import_DictionariesRecordContext = require('./DictionariesRecordContext.cjs');
30
- var import_EditedContentContext = require('./EditedContentContext.cjs');
31
- var import_EditorEnabledContext = require('./EditorEnabledContext.cjs');
32
- var import_FocusDictionaryContext = require('./FocusDictionaryContext.cjs');
1
+ 'use client';
2
+
3
+
4
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
5
+ const require_CommunicatorContext = require('./CommunicatorContext.cjs');
6
+ const require_ConfigurationContext = require('./ConfigurationContext.cjs');
7
+ const require_DictionariesRecordContext = require('./DictionariesRecordContext.cjs');
8
+ const require_EditedContentContext = require('./EditedContentContext.cjs');
9
+ const require_EditorEnabledContext = require('./EditorEnabledContext.cjs');
10
+ const require_FocusDictionaryContext = require('./FocusDictionaryContext.cjs');
11
+ let react = require("react");
12
+ react = require_rolldown_runtime.__toESM(react);
13
+ let react_jsx_runtime = require("react/jsx-runtime");
14
+ react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
15
+
16
+ //#region src/EditorProvider.tsx
17
+ /**
18
+ * This component add all the providers needed by the editor.
19
+ * It is used to wrap the application, or the editor to work together.
20
+ */
33
21
  const EditorProvidersWrapper = ({ children }) => {
34
- const getEditedContentState = (0, import_EditedContentContext.useGetEditedContentState)();
35
- (0, import_react.useEffect)(() => {
36
- getEditedContentState();
37
- }, []);
38
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_DictionariesRecordContext.DictionariesRecordProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_EditedContentContext.EditedContentProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_FocusDictionaryContext.FocusDictionaryProvider, { children }) }) });
22
+ const getEditedContentState = require_EditedContentContext.useGetEditedContentState();
23
+ (0, react.useEffect)(() => {
24
+ getEditedContentState();
25
+ }, []);
26
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_DictionariesRecordContext.DictionariesRecordProvider, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_EditedContentContext.EditedContentProvider, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_FocusDictionaryContext.FocusDictionaryProvider, { children }) }) });
39
27
  };
40
- const EditorEnabledCheckRenderer = ({
41
- children,
42
- fallback
43
- }) => {
44
- const getEditorEnabled = (0, import_EditorEnabledContext.useGetEditorEnabledState)();
45
- const { enabled } = (0, import_EditorEnabledContext.useEditorEnabled)();
46
- (0, import_react.useEffect)(() => {
47
- if (enabled) return;
48
- getEditorEnabled();
49
- }, [enabled]);
50
- return enabled ? children : fallback;
28
+ /**
29
+ * This component check if the editor is enabled to render the editor providers.
30
+ */
31
+ const EditorEnabledCheckRenderer = ({ children, fallback }) => {
32
+ const getEditorEnabled = require_EditorEnabledContext.useGetEditorEnabledState();
33
+ const { enabled } = require_EditorEnabledContext.useEditorEnabled();
34
+ (0, react.useEffect)(() => {
35
+ if (enabled) return;
36
+ getEditorEnabled();
37
+ }, [enabled]);
38
+ return enabled ? children : fallback;
51
39
  };
52
- const IframeCheckRenderer = ({
53
- children,
54
- fallback
55
- }) => {
56
- const [isInIframe, setIsInIframe] = (0, import_react.useState)(false);
57
- (0, import_react.useEffect)(() => {
58
- setIsInIframe(window.self !== window.top);
59
- }, []);
60
- return isInIframe ? children : fallback;
40
+ /**
41
+ * This component is used to check if the editor is wrapping the application.
42
+ * It avoid to send window.postMessage to the application if the editor is not wrapping the application.
43
+ */
44
+ const IframeCheckRenderer = ({ children, fallback }) => {
45
+ const [isInIframe, setIsInIframe] = (0, react.useState)(false);
46
+ (0, react.useEffect)(() => {
47
+ setIsInIframe(window.self !== window.top);
48
+ }, []);
49
+ return isInIframe ? children : fallback;
61
50
  };
62
- const EditorProvider = ({
63
- children,
64
- configuration,
65
- ...props
66
- }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_EditorEnabledContext.EditorEnabledProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ConfigurationContext.ConfigurationProvider, { configuration, children: props.mode === "editor" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_CommunicatorContext.CommunicatorProvider, { ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EditorProvidersWrapper, { children }) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IframeCheckRenderer, { fallback: children, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_CommunicatorContext.CommunicatorProvider, { ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EditorEnabledCheckRenderer, { fallback: children, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EditorProvidersWrapper, { children }) }) }) }) }) });
67
- // Annotate the CommonJS export names for ESM import in node:
68
- 0 && (module.exports = {
69
- EditorProvider
70
- });
51
+ const EditorProvider = ({ children, configuration,...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_EditorEnabledContext.EditorEnabledProvider, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ConfigurationContext.ConfigurationProvider, {
52
+ configuration,
53
+ children: props.mode === "editor" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_CommunicatorContext.CommunicatorProvider, {
54
+ ...props,
55
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EditorProvidersWrapper, { children })
56
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IframeCheckRenderer, {
57
+ fallback: children,
58
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_CommunicatorContext.CommunicatorProvider, {
59
+ ...props,
60
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EditorEnabledCheckRenderer, {
61
+ fallback: children,
62
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EditorProvidersWrapper, { children })
63
+ })
64
+ })
65
+ })
66
+ }) });
67
+
68
+ //#endregion
69
+ exports.EditorProvider = EditorProvider;
71
70
  //# sourceMappingURL=EditorProvider.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/EditorProvider.tsx"],"sourcesContent":["'use client';\n\nimport {\n type FC,\n type PropsWithChildren,\n ReactNode,\n useEffect,\n useState,\n} from 'react';\nimport {\n type CommunicatorProviderProps,\n CommunicatorProvider,\n} from './CommunicatorContext';\nimport {\n type ConfigurationProviderProps,\n ConfigurationProvider,\n} from './ConfigurationContext';\nimport { DictionariesRecordProvider } from './DictionariesRecordContext';\nimport {\n EditedContentProvider,\n useGetEditedContentState,\n} from './EditedContentContext';\nimport {\n EditorEnabledProvider,\n useEditorEnabled,\n useGetEditorEnabledState,\n} from './EditorEnabledContext';\nimport { FocusDictionaryProvider } from './FocusDictionaryContext';\n\n/**\n * This component add all the providers needed by the editor.\n * It is used to wrap the application, or the editor to work together.\n */\nconst EditorProvidersWrapper: FC<PropsWithChildren> = ({ children }) => {\n const getEditedContentState = useGetEditedContentState();\n\n useEffect(() => {\n getEditedContentState();\n }, []);\n\n return (\n <DictionariesRecordProvider>\n <EditedContentProvider>\n <FocusDictionaryProvider>{children}</FocusDictionaryProvider>\n </EditedContentProvider>\n </DictionariesRecordProvider>\n );\n};\n\ntype FallbackProps = {\n fallback: ReactNode;\n};\n\n/**\n * This component check if the editor is enabled to render the editor providers.\n */\nconst EditorEnabledCheckRenderer: FC<PropsWithChildren<FallbackProps>> = ({\n children,\n fallback,\n}) => {\n const getEditorEnabled = useGetEditorEnabledState();\n\n const { enabled } = useEditorEnabled();\n\n useEffect(() => {\n if (enabled) return;\n\n // Check if the editor is wrapping the application\n getEditorEnabled();\n }, [enabled]);\n\n return enabled ? children : fallback;\n};\n\n/**\n * This component is used to check if the editor is wrapping the application.\n * It avoid to send window.postMessage to the application if the editor is not wrapping the application.\n */\nconst IframeCheckRenderer: FC<PropsWithChildren<FallbackProps>> = ({\n children,\n fallback,\n}) => {\n const [isInIframe, setIsInIframe] = useState(false);\n\n useEffect(() => {\n setIsInIframe(window.self !== window.top);\n }, []);\n\n return isInIframe ? children : fallback;\n};\n\nexport type EditorProviderProps = CommunicatorProviderProps &\n ConfigurationProviderProps & {\n mode: 'editor' | 'client';\n };\n\nexport const EditorProvider: FC<PropsWithChildren<EditorProviderProps>> = ({\n children,\n configuration,\n ...props\n}) => (\n <EditorEnabledProvider>\n <ConfigurationProvider configuration={configuration}>\n {props.mode === 'editor' ? (\n <CommunicatorProvider {...props}>\n <EditorProvidersWrapper>{children}</EditorProvidersWrapper>\n </CommunicatorProvider>\n ) : (\n <IframeCheckRenderer fallback={children}>\n <CommunicatorProvider {...props}>\n <EditorEnabledCheckRenderer fallback={children}>\n <EditorProvidersWrapper>{children}</EditorProvidersWrapper>\n </EditorEnabledCheckRenderer>\n </CommunicatorProvider>\n </IframeCheckRenderer>\n )}\n </ConfigurationProvider>\n </EditorEnabledProvider>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2CQ;AAzCR,mBAMO;AACP,iCAGO;AACP,kCAGO;AACP,uCAA2C;AAC3C,kCAGO;AACP,kCAIO;AACP,oCAAwC;AAMxC,MAAM,yBAAgD,CAAC,EAAE,SAAS,MAAM;AACtE,QAAM,4BAAwB,sDAAyB;AAEvD,8BAAU,MAAM;AACd,0BAAsB;AAAA,EACxB,GAAG,CAAC,CAAC;AAEL,SACE,4CAAC,+DACC,sDAAC,qDACC,sDAAC,yDAAyB,UAAS,GACrC,GACF;AAEJ;AASA,MAAM,6BAAmE,CAAC;AAAA,EACxE;AAAA,EACA;AACF,MAAM;AACJ,QAAM,uBAAmB,sDAAyB;AAElD,QAAM,EAAE,QAAQ,QAAI,8CAAiB;AAErC,8BAAU,MAAM;AACd,QAAI,QAAS;AAGb,qBAAiB;AAAA,EACnB,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO,UAAU,WAAW;AAC9B;AAMA,MAAM,sBAA4D,CAAC;AAAA,EACjE;AAAA,EACA;AACF,MAAM;AACJ,QAAM,CAAC,YAAY,aAAa,QAAI,uBAAS,KAAK;AAElD,8BAAU,MAAM;AACd,kBAAc,OAAO,SAAS,OAAO,GAAG;AAAA,EAC1C,GAAG,CAAC,CAAC;AAEL,SAAO,aAAa,WAAW;AACjC;AAOO,MAAM,iBAA6D,CAAC;AAAA,EACzE;AAAA,EACA;AAAA,EACA,GAAG;AACL,MACE,4CAAC,qDACC,sDAAC,qDAAsB,eACpB,gBAAM,SAAS,WACd,4CAAC,mDAAsB,GAAG,OACxB,sDAAC,0BAAwB,UAAS,GACpC,IAEA,4CAAC,uBAAoB,UAAU,UAC7B,sDAAC,mDAAsB,GAAG,OACxB,sDAAC,8BAA2B,UAAU,UACpC,sDAAC,0BAAwB,UAAS,GACpC,GACF,GACF,GAEJ,GACF;","names":[]}
1
+ {"version":3,"file":"EditorProvider.cjs","names":["EditorProvidersWrapper: FC<PropsWithChildren>","useGetEditedContentState","DictionariesRecordProvider","EditedContentProvider","FocusDictionaryProvider","EditorEnabledCheckRenderer: FC<PropsWithChildren<FallbackProps>>","useGetEditorEnabledState","useEditorEnabled","IframeCheckRenderer: FC<PropsWithChildren<FallbackProps>>","EditorProvider: FC<PropsWithChildren<EditorProviderProps>>","EditorEnabledProvider","ConfigurationProvider","CommunicatorProvider"],"sources":["../../src/EditorProvider.tsx"],"sourcesContent":["'use client';\n\nimport {\n type FC,\n type PropsWithChildren,\n type ReactNode,\n useEffect,\n useState,\n} from 'react';\nimport {\n CommunicatorProvider,\n type CommunicatorProviderProps,\n} from './CommunicatorContext';\nimport {\n ConfigurationProvider,\n type ConfigurationProviderProps,\n} from './ConfigurationContext';\nimport { DictionariesRecordProvider } from './DictionariesRecordContext';\nimport {\n EditedContentProvider,\n useGetEditedContentState,\n} from './EditedContentContext';\nimport {\n EditorEnabledProvider,\n useEditorEnabled,\n useGetEditorEnabledState,\n} from './EditorEnabledContext';\nimport { FocusDictionaryProvider } from './FocusDictionaryContext';\n\n/**\n * This component add all the providers needed by the editor.\n * It is used to wrap the application, or the editor to work together.\n */\nconst EditorProvidersWrapper: FC<PropsWithChildren> = ({ children }) => {\n const getEditedContentState = useGetEditedContentState();\n\n useEffect(() => {\n getEditedContentState();\n }, []);\n\n return (\n <DictionariesRecordProvider>\n <EditedContentProvider>\n <FocusDictionaryProvider>{children}</FocusDictionaryProvider>\n </EditedContentProvider>\n </DictionariesRecordProvider>\n );\n};\n\ntype FallbackProps = {\n fallback: ReactNode;\n};\n\n/**\n * This component check if the editor is enabled to render the editor providers.\n */\nconst EditorEnabledCheckRenderer: FC<PropsWithChildren<FallbackProps>> = ({\n children,\n fallback,\n}) => {\n const getEditorEnabled = useGetEditorEnabledState();\n\n const { enabled } = useEditorEnabled();\n\n useEffect(() => {\n if (enabled) return;\n\n // Check if the editor is wrapping the application\n getEditorEnabled();\n }, [enabled]);\n\n return enabled ? children : fallback;\n};\n\n/**\n * This component is used to check if the editor is wrapping the application.\n * It avoid to send window.postMessage to the application if the editor is not wrapping the application.\n */\nconst IframeCheckRenderer: FC<PropsWithChildren<FallbackProps>> = ({\n children,\n fallback,\n}) => {\n const [isInIframe, setIsInIframe] = useState(false);\n\n useEffect(() => {\n setIsInIframe(window.self !== window.top);\n }, []);\n\n return isInIframe ? children : fallback;\n};\n\nexport type EditorProviderProps = CommunicatorProviderProps &\n ConfigurationProviderProps & {\n mode: 'editor' | 'client';\n };\n\nexport const EditorProvider: FC<PropsWithChildren<EditorProviderProps>> = ({\n children,\n configuration,\n ...props\n}) => (\n <EditorEnabledProvider>\n <ConfigurationProvider configuration={configuration}>\n {props.mode === 'editor' ? (\n <CommunicatorProvider {...props}>\n <EditorProvidersWrapper>{children}</EditorProvidersWrapper>\n </CommunicatorProvider>\n ) : (\n <IframeCheckRenderer fallback={children}>\n <CommunicatorProvider {...props}>\n <EditorEnabledCheckRenderer fallback={children}>\n <EditorProvidersWrapper>{children}</EditorProvidersWrapper>\n </EditorEnabledCheckRenderer>\n </CommunicatorProvider>\n </IframeCheckRenderer>\n )}\n </ConfigurationProvider>\n </EditorEnabledProvider>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAiCA,MAAMA,0BAAiD,EAAE,eAAe;CACtE,MAAM,wBAAwBC,uDAA0B;AAExD,4BAAgB;AACd,yBAAuB;IACtB,EAAE,CAAC;AAEN,QACE,2CAACC,0EACC,2CAACC,gEACC,2CAACC,0DAAyB,WAAmC,GACvC,GACG;;;;;AAWjC,MAAMC,8BAAoE,EACxE,UACA,eACI;CACJ,MAAM,mBAAmBC,uDAA0B;CAEnD,MAAM,EAAE,YAAYC,+CAAkB;AAEtC,4BAAgB;AACd,MAAI,QAAS;AAGb,oBAAkB;IACjB,CAAC,QAAQ,CAAC;AAEb,QAAO,UAAU,WAAW;;;;;;AAO9B,MAAMC,uBAA6D,EACjE,UACA,eACI;CACJ,MAAM,CAAC,YAAY,qCAA0B,MAAM;AAEnD,4BAAgB;AACd,gBAAc,OAAO,SAAS,OAAO,IAAI;IACxC,EAAE,CAAC;AAEN,QAAO,aAAa,WAAW;;AAQjC,MAAaC,kBAA8D,EACzE,UACA,cACA,GAAG,YAEH,2CAACC,gEACC,2CAACC;CAAqC;WACnC,MAAM,SAAS,WACd,2CAACC;EAAqB,GAAI;YACxB,2CAAC,0BAAwB,WAAkC;GACtC,GAEvB,2CAAC;EAAoB,UAAU;YAC7B,2CAACA;GAAqB,GAAI;aACxB,2CAAC;IAA2B,UAAU;cACpC,2CAAC,0BAAwB,WAAkC;KAChC;IACR;GACH;EAEF,GACF"}
@@ -1,81 +1,57 @@
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 FocusDictionaryContext_exports = {};
21
- __export(FocusDictionaryContext_exports, {
22
- FocusDictionaryProvider: () => FocusDictionaryProvider,
23
- useFocusDictionary: () => useFocusDictionary,
24
- useFocusDictionaryActions: () => useFocusDictionaryActions
25
- });
26
- module.exports = __toCommonJS(FocusDictionaryContext_exports);
27
- var import_jsx_runtime = require("react/jsx-runtime");
28
- var import_editor = require("@intlayer/editor");
29
- var import_react = require("react");
30
- var import_useCrossFrameState = require('./useCrossFrameState.cjs');
31
- const FocusDictionaryStateContext = (0, import_react.createContext)(void 0);
32
- const FocusDictionaryActionsContext = (0, import_react.createContext)(void 0);
33
- const FocusDictionaryProvider = ({
34
- children
35
- }) => {
36
- const [focusedContent, setFocusedContent] = (0, import_useCrossFrameState.useCrossFrameState)(
37
- import_editor.MessageKey.INTLAYER_FOCUSED_CONTENT_CHANGED,
38
- null
39
- );
40
- const setFocusedContentKeyPath = (keyPath) => {
41
- setFocusedContent((prev) => {
42
- if (!prev) {
43
- return prev;
44
- }
45
- return { ...prev, keyPath };
46
- });
47
- };
48
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FocusDictionaryStateContext.Provider, { value: { focusedContent }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
49
- FocusDictionaryActionsContext.Provider,
50
- {
51
- value: { setFocusedContent, setFocusedContentKeyPath },
52
- children
53
- }
54
- ) });
1
+ 'use client';
2
+
3
+
4
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
5
+ const require_useCrossFrameState = require('./useCrossFrameState.cjs');
6
+ let react = require("react");
7
+ react = require_rolldown_runtime.__toESM(react);
8
+ let react_jsx_runtime = require("react/jsx-runtime");
9
+ react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
10
+ let __intlayer_editor = require("@intlayer/editor");
11
+ __intlayer_editor = require_rolldown_runtime.__toESM(__intlayer_editor);
12
+
13
+ //#region src/FocusDictionaryContext.tsx
14
+ const FocusDictionaryStateContext = (0, react.createContext)(void 0);
15
+ const FocusDictionaryActionsContext = (0, react.createContext)(void 0);
16
+ const FocusDictionaryProvider = ({ children }) => {
17
+ const [focusedContent, setFocusedContent] = require_useCrossFrameState.useCrossFrameState(__intlayer_editor.MessageKey.INTLAYER_FOCUSED_CONTENT_CHANGED, null);
18
+ const setFocusedContentKeyPath = (keyPath) => {
19
+ setFocusedContent((prev) => {
20
+ if (!prev) return prev;
21
+ return {
22
+ ...prev,
23
+ keyPath
24
+ };
25
+ });
26
+ };
27
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FocusDictionaryStateContext.Provider, {
28
+ value: { focusedContent },
29
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FocusDictionaryActionsContext.Provider, {
30
+ value: {
31
+ setFocusedContent,
32
+ setFocusedContentKeyPath
33
+ },
34
+ children
35
+ })
36
+ });
55
37
  };
56
38
  const useFocusDictionaryActions = () => {
57
- const context = (0, import_react.useContext)(FocusDictionaryActionsContext);
58
- if (context === void 0) {
59
- throw new Error(
60
- "useFocusDictionaryActions must be used within a FocusDictionaryProvider"
61
- );
62
- }
63
- return context;
39
+ const context = (0, react.useContext)(FocusDictionaryActionsContext);
40
+ if (context === void 0) throw new Error("useFocusDictionaryActions must be used within a FocusDictionaryProvider");
41
+ return context;
64
42
  };
65
43
  const useFocusDictionary = () => {
66
- const actionContext = useFocusDictionaryActions();
67
- const stateContext = (0, import_react.useContext)(FocusDictionaryStateContext);
68
- if (stateContext === void 0) {
69
- throw new Error(
70
- "useFocusDictionaryState must be used within a FocusDictionaryProvider"
71
- );
72
- }
73
- return { ...stateContext, ...actionContext };
44
+ const actionContext = useFocusDictionaryActions();
45
+ const stateContext = (0, react.useContext)(FocusDictionaryStateContext);
46
+ if (stateContext === void 0) throw new Error("useFocusDictionaryState must be used within a FocusDictionaryProvider");
47
+ return {
48
+ ...stateContext,
49
+ ...actionContext
50
+ };
74
51
  };
75
- // Annotate the CommonJS export names for ESM import in node:
76
- 0 && (module.exports = {
77
- FocusDictionaryProvider,
78
- useFocusDictionary,
79
- useFocusDictionaryActions
80
- });
52
+
53
+ //#endregion
54
+ exports.FocusDictionaryProvider = FocusDictionaryProvider;
55
+ exports.useFocusDictionary = useFocusDictionary;
56
+ exports.useFocusDictionaryActions = useFocusDictionaryActions;
81
57
  //# sourceMappingURL=FocusDictionaryContext.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport type { KeyPath } from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n createContext,\n useContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport type FileContent = {\n dictionaryKey: string;\n dictionaryLocalId?: string;\n keyPath?: KeyPath[];\n};\n\ntype FocusDictionaryState = {\n focusedContent: FileContent | null;\n};\n\ntype FocusDictionaryActions = {\n setFocusedContent: Dispatch<SetStateAction<FileContent | null>>;\n setFocusedContentKeyPath: (keyPath: KeyPath[]) => void;\n};\n\nconst FocusDictionaryStateContext = createContext<\n FocusDictionaryState | undefined\n>(undefined);\nconst FocusDictionaryActionsContext = createContext<\n FocusDictionaryActions | undefined\n>(undefined);\n\nexport const FocusDictionaryProvider: FC<PropsWithChildren> = ({\n children,\n}) => {\n const [focusedContent, setFocusedContent] =\n useCrossFrameState<FileContent | null>(\n MessageKey.INTLAYER_FOCUSED_CONTENT_CHANGED,\n null\n );\n\n const setFocusedContentKeyPath = (keyPath: KeyPath[]) => {\n setFocusedContent((prev) => {\n if (!prev) {\n return prev; // nothing to update if there's no focused content\n }\n return { ...prev, keyPath };\n });\n };\n\n return (\n <FocusDictionaryStateContext.Provider value={{ focusedContent }}>\n <FocusDictionaryActionsContext.Provider\n value={{ setFocusedContent, setFocusedContentKeyPath }}\n >\n {children}\n </FocusDictionaryActionsContext.Provider>\n </FocusDictionaryStateContext.Provider>\n );\n};\n\nexport const useFocusDictionaryActions = () => {\n const context = useContext(FocusDictionaryActionsContext);\n if (context === undefined) {\n throw new Error(\n 'useFocusDictionaryActions must be used within a FocusDictionaryProvider'\n );\n }\n return context;\n};\n\nexport const useFocusDictionary = () => {\n const actionContext = useFocusDictionaryActions();\n const stateContext = useContext(FocusDictionaryStateContext);\n\n if (stateContext === undefined) {\n throw new Error(\n 'useFocusDictionaryState must be used within a FocusDictionaryProvider'\n );\n }\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwDM;AArDN,oBAA2B;AAC3B,mBAOO;AACP,gCAAmC;AAiBnC,MAAM,kCAA8B,4BAElC,MAAS;AACX,MAAM,oCAAgC,4BAEpC,MAAS;AAEJ,MAAM,0BAAiD,CAAC;AAAA,EAC7D;AACF,MAAM;AACJ,QAAM,CAAC,gBAAgB,iBAAiB,QACtC;AAAA,IACE,yBAAW;AAAA,IACX;AAAA,EACF;AAEF,QAAM,2BAA2B,CAAC,YAAuB;AACvD,sBAAkB,CAAC,SAAS;AAC1B,UAAI,CAAC,MAAM;AACT,eAAO;AAAA,MACT;AACA,aAAO,EAAE,GAAG,MAAM,QAAQ;AAAA,IAC5B,CAAC;AAAA,EACH;AAEA,SACE,4CAAC,4BAA4B,UAA5B,EAAqC,OAAO,EAAE,eAAe,GAC5D;AAAA,IAAC,8BAA8B;AAAA,IAA9B;AAAA,MACC,OAAO,EAAE,mBAAmB,yBAAyB;AAAA,MAEpD;AAAA;AAAA,EACH,GACF;AAEJ;AAEO,MAAM,4BAA4B,MAAM;AAC7C,QAAM,cAAU,yBAAW,6BAA6B;AACxD,MAAI,YAAY,QAAW;AACzB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,qBAAqB,MAAM;AACtC,QAAM,gBAAgB,0BAA0B;AAChD,QAAM,mBAAe,yBAAW,2BAA2B;AAE3D,MAAI,iBAAiB,QAAW;AAC9B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,cAAc,GAAG,cAAc;AAC7C;","names":[]}
1
+ {"version":3,"file":"FocusDictionaryContext.cjs","names":["FocusDictionaryProvider: FC<PropsWithChildren>","useCrossFrameState","MessageKey"],"sources":["../../src/FocusDictionaryContext.tsx"],"sourcesContent":["'use client';\n\nimport { MessageKey } from '@intlayer/editor';\nimport type { KeyPath } from '@intlayer/types';\nimport {\n createContext,\n type Dispatch,\n type FC,\n type PropsWithChildren,\n type SetStateAction,\n useContext,\n} from 'react';\nimport { useCrossFrameState } from './useCrossFrameState';\n\nexport type FileContent = {\n dictionaryKey: string;\n dictionaryLocalId?: string;\n keyPath?: KeyPath[];\n};\n\ntype FocusDictionaryState = {\n focusedContent: FileContent | null;\n};\n\ntype FocusDictionaryActions = {\n setFocusedContent: Dispatch<SetStateAction<FileContent | null>>;\n setFocusedContentKeyPath: (keyPath: KeyPath[]) => void;\n};\n\nconst FocusDictionaryStateContext = createContext<\n FocusDictionaryState | undefined\n>(undefined);\nconst FocusDictionaryActionsContext = createContext<\n FocusDictionaryActions | undefined\n>(undefined);\n\nexport const FocusDictionaryProvider: FC<PropsWithChildren> = ({\n children,\n}) => {\n const [focusedContent, setFocusedContent] =\n useCrossFrameState<FileContent | null>(\n MessageKey.INTLAYER_FOCUSED_CONTENT_CHANGED,\n null\n );\n\n const setFocusedContentKeyPath = (keyPath: KeyPath[]) => {\n setFocusedContent((prev) => {\n if (!prev) {\n return prev; // nothing to update if there's no focused content\n }\n return { ...prev, keyPath };\n });\n };\n\n return (\n <FocusDictionaryStateContext.Provider value={{ focusedContent }}>\n <FocusDictionaryActionsContext.Provider\n value={{ setFocusedContent, setFocusedContentKeyPath }}\n >\n {children}\n </FocusDictionaryActionsContext.Provider>\n </FocusDictionaryStateContext.Provider>\n );\n};\n\nexport const useFocusDictionaryActions = () => {\n const context = useContext(FocusDictionaryActionsContext);\n if (context === undefined) {\n throw new Error(\n 'useFocusDictionaryActions must be used within a FocusDictionaryProvider'\n );\n }\n return context;\n};\n\nexport const useFocusDictionary = () => {\n const actionContext = useFocusDictionaryActions();\n const stateContext = useContext(FocusDictionaryStateContext);\n\n if (stateContext === undefined) {\n throw new Error(\n 'useFocusDictionaryState must be used within a FocusDictionaryProvider'\n );\n }\n\n return { ...stateContext, ...actionContext };\n};\n"],"mappings":";;;;;;;;;;;;;AA6BA,MAAM,uDAEJ,OAAU;AACZ,MAAM,yDAEJ,OAAU;AAEZ,MAAaA,2BAAkD,EAC7D,eACI;CACJ,MAAM,CAAC,gBAAgB,qBACrBC,8CACEC,6BAAW,kCACX,KACD;CAEH,MAAM,4BAA4B,YAAuB;AACvD,qBAAmB,SAAS;AAC1B,OAAI,CAAC,KACH,QAAO;AAET,UAAO;IAAE,GAAG;IAAM;IAAS;IAC3B;;AAGJ,QACE,2CAAC,4BAA4B;EAAS,OAAO,EAAE,gBAAgB;YAC7D,2CAAC,8BAA8B;GAC7B,OAAO;IAAE;IAAmB;IAA0B;GAErD;IACsC;GACJ;;AAI3C,MAAa,kCAAkC;CAC7C,MAAM,gCAAqB,8BAA8B;AACzD,KAAI,YAAY,OACd,OAAM,IAAI,MACR,0EACD;AAEH,QAAO;;AAGT,MAAa,2BAA2B;CACtC,MAAM,gBAAgB,2BAA2B;CACjD,MAAM,qCAA0B,4BAA4B;AAE5D,KAAI,iBAAiB,OACnB,OAAM,IAAI,MACR,wEACD;AAGH,QAAO;EAAE,GAAG;EAAc,GAAG;EAAe"}
@@ -0,0 +1,25 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+
25
+ exports.__toESM = __toESM;
@@ -1,45 +1,47 @@
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("@intlayer/editor"), module.exports);
19
- __reExport(index_exports, require('./CommunicatorContext.cjs'), module.exports);
20
- __reExport(index_exports, require('./ConfigurationContext.cjs'), module.exports);
21
- __reExport(index_exports, require('./DictionariesRecordContext.cjs'), module.exports);
22
- __reExport(index_exports, require('./EditedContentContext.cjs'), module.exports);
23
- __reExport(index_exports, require('./EditorEnabledContext.cjs'), module.exports);
24
- __reExport(index_exports, require('./EditorProvider.cjs'), module.exports);
25
- __reExport(index_exports, require('./FocusDictionaryContext.cjs'), module.exports);
26
- __reExport(index_exports, require('./useCrossFrameMessageListener.cjs'), module.exports);
27
- __reExport(index_exports, require('./useCrossFrameState.cjs'), module.exports);
28
- __reExport(index_exports, require('./useCrossURLPathState.cjs'), module.exports);
29
- __reExport(index_exports, require('./useIframeClickInterceptor.cjs'), module.exports);
30
- // Annotate the CommonJS export names for ESM import in node:
31
- 0 && (module.exports = {
32
- ...require("@intlayer/editor"),
33
- ...require('./CommunicatorContext.cjs'),
34
- ...require('./ConfigurationContext.cjs'),
35
- ...require('./DictionariesRecordContext.cjs'),
36
- ...require('./EditedContentContext.cjs'),
37
- ...require('./EditorEnabledContext.cjs'),
38
- ...require('./EditorProvider.cjs'),
39
- ...require('./FocusDictionaryContext.cjs'),
40
- ...require('./useCrossFrameMessageListener.cjs'),
41
- ...require('./useCrossFrameState.cjs'),
42
- ...require('./useCrossURLPathState.cjs'),
43
- ...require('./useIframeClickInterceptor.cjs')
1
+ const require_CommunicatorContext = require('./CommunicatorContext.cjs');
2
+ const require_useCrossFrameMessageListener = require('./useCrossFrameMessageListener.cjs');
3
+ const require_useCrossFrameState = require('./useCrossFrameState.cjs');
4
+ const require_ConfigurationContext = require('./ConfigurationContext.cjs');
5
+ const require_DictionariesRecordContext = require('./DictionariesRecordContext.cjs');
6
+ const require_EditedContentContext = require('./EditedContentContext.cjs');
7
+ const require_EditorEnabledContext = require('./EditorEnabledContext.cjs');
8
+ const require_FocusDictionaryContext = require('./FocusDictionaryContext.cjs');
9
+ const require_EditorProvider = require('./EditorProvider.cjs');
10
+ const require_useCrossURLPathState = require('./useCrossURLPathState.cjs');
11
+ const require_useIframeClickInterceptor = require('./useIframeClickInterceptor.cjs');
12
+
13
+ exports.CommunicatorProvider = require_CommunicatorContext.CommunicatorProvider;
14
+ exports.ConfigurationProvider = require_ConfigurationContext.ConfigurationProvider;
15
+ exports.DictionariesRecordProvider = require_DictionariesRecordContext.DictionariesRecordProvider;
16
+ exports.EditedContentProvider = require_EditedContentContext.EditedContentProvider;
17
+ exports.EditorEnabledProvider = require_EditorEnabledContext.EditorEnabledProvider;
18
+ exports.EditorProvider = require_EditorProvider.EditorProvider;
19
+ exports.FocusDictionaryProvider = require_FocusDictionaryContext.FocusDictionaryProvider;
20
+ exports.useCommunicator = require_CommunicatorContext.useCommunicator;
21
+ exports.useConfiguration = require_ConfigurationContext.useConfiguration;
22
+ exports.useConfigurationState = require_ConfigurationContext.useConfigurationState;
23
+ exports.useCrossFrameMessageListener = require_useCrossFrameMessageListener.useCrossFrameMessageListener;
24
+ exports.useCrossFrameState = require_useCrossFrameState.useCrossFrameState;
25
+ exports.useCrossURLPathSetter = require_useCrossURLPathState.useCrossURLPathSetter;
26
+ exports.useCrossURLPathState = require_useCrossURLPathState.useCrossURLPathState;
27
+ exports.useDictionariesRecord = require_DictionariesRecordContext.useDictionariesRecord;
28
+ exports.useDictionariesRecordActions = require_DictionariesRecordContext.useDictionariesRecordActions;
29
+ exports.useEditedContent = require_EditedContentContext.useEditedContent;
30
+ exports.useEditedContentActions = require_EditedContentContext.useEditedContentActions;
31
+ exports.useEditorEnabled = require_EditorEnabledContext.useEditorEnabled;
32
+ exports.useEditorEnabledState = require_EditorEnabledContext.useEditorEnabledState;
33
+ exports.useFocusDictionary = require_FocusDictionaryContext.useFocusDictionary;
34
+ exports.useFocusDictionaryActions = require_FocusDictionaryContext.useFocusDictionaryActions;
35
+ exports.useGetEditedContentState = require_EditedContentContext.useGetEditedContentState;
36
+ exports.useGetEditorEnabledState = require_EditorEnabledContext.useGetEditorEnabledState;
37
+ exports.useIframeClickInterceptor = require_useIframeClickInterceptor.useIframeClickInterceptor;
38
+ exports.useIframeClickMerger = require_useIframeClickInterceptor.useIframeClickMerger;
39
+ exports.usePostEditedContentState = require_EditedContentContext.usePostEditedContentState;
40
+ exports.usePostEditorEnabledState = require_EditorEnabledContext.usePostEditorEnabledState;
41
+ var __intlayer_editor = require("@intlayer/editor");
42
+ Object.keys(__intlayer_editor).forEach(function (k) {
43
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
44
+ enumerable: true,
45
+ get: function () { return __intlayer_editor[k]; }
46
+ });
44
47
  });
45
- //# sourceMappingURL=index.cjs.map
@@ -1,53 +1,76 @@
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 useCrossFrameMessageListener_exports = {};
21
- __export(useCrossFrameMessageListener_exports, {
22
- useCrossFrameMessageListener: () => useCrossFrameMessageListener
23
- });
24
- module.exports = __toCommonJS(useCrossFrameMessageListener_exports);
25
- var import_editor = require("@intlayer/editor");
26
- var import_react = require("react");
27
- var import_CommunicatorContext = require('./CommunicatorContext.cjs');
1
+ 'use client';
2
+
3
+
4
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
5
+ const require_CommunicatorContext = require('./CommunicatorContext.cjs');
6
+ let react = require("react");
7
+ react = require_rolldown_runtime.__toESM(react);
8
+ let __intlayer_editor = require("@intlayer/editor");
9
+ __intlayer_editor = require_rolldown_runtime.__toESM(__intlayer_editor);
10
+
11
+ //#region src/useCrossFrameMessageListener.tsx
12
+ /**
13
+ * useCrossFrameMessageListener
14
+ *
15
+ * This React hook listens for messages sent via the `postMessage` API and triggers a callback
16
+ * whenever a message of the specified type (`key`) is received. It is useful for synchronizing
17
+ * state or events across different windows, iframes, or contexts.
18
+ *
19
+ * @template S - The type of the data payload in the message.
20
+ * @param key - A unique identifier for the message type to listen for.
21
+ * @param [onEventTriggered] - A callback function triggered when a message
22
+ * @param [revalidator] - A function that re-suscribes the listener. Could be usefull if onEventTriggered depend of some state
23
+ * with the specified key is received. The callback receives the message data as its argument.
24
+ *
25
+ * @returns {{ postMessage: (data: S) => void }} An object containing a `postMessage` function
26
+ * that allows broadcasting messages with the specified key and data.
27
+ */
28
28
  const useCrossFrameMessageListener = (key, onEventTriggered, revalidator) => {
29
- const { allowedOrigins, postMessage, senderId } = (0, import_CommunicatorContext.useCommunicator)();
30
- (0, import_react.useEffect)(() => {
31
- if (onEventTriggered) {
32
- const handleMessage = (event) => {
33
- const { type, data, senderId: msgSenderId } = event.data;
34
- if (type !== key) return;
35
- if (msgSenderId === senderId) return;
36
- if (typeof allowedOrigins === "undefined" || allowedOrigins?.some((url) => (0, import_editor.compareUrls)(url, event.origin)) || allowedOrigins?.includes("*")) {
37
- onEventTriggered(data);
38
- }
39
- };
40
- window.addEventListener("message", handleMessage);
41
- return () => window.removeEventListener("message", handleMessage);
42
- }
43
- }, [allowedOrigins, postMessage, senderId, revalidator]);
44
- const postMessageWrapper = (data) => {
45
- postMessage({ type: key, data, senderId });
46
- };
47
- return postMessageWrapper;
29
+ const { allowedOrigins, postMessage, senderId } = require_CommunicatorContext.useCommunicator();
30
+ (0, react.useEffect)(() => {
31
+ if (onEventTriggered) {
32
+ /**
33
+ * Message handler to process incoming messages.
34
+ *
35
+ * - **Message Filtering:** Ensures only messages with the specified `key` are processed.
36
+ * - **Origin Validation:** Checks that the origin of the message is within the allowed origins.
37
+ *
38
+ * @param {MessageEvent<{ type: string; data: S }>} event - The incoming message event object.
39
+ */
40
+ const handleMessage = (event) => {
41
+ const { type, data, senderId: msgSenderId } = event.data;
42
+ if (type !== key) return;
43
+ if (msgSenderId === senderId) return;
44
+ if (typeof allowedOrigins === "undefined" || allowedOrigins?.some((url) => (0, __intlayer_editor.compareUrls)(url, event.origin)) || allowedOrigins?.includes("*")) onEventTriggered(data);
45
+ };
46
+ window.addEventListener("message", handleMessage);
47
+ return () => window.removeEventListener("message", handleMessage);
48
+ }
49
+ }, [
50
+ allowedOrigins,
51
+ postMessage,
52
+ senderId,
53
+ revalidator
54
+ ]);
55
+ /**
56
+ * A wrapper function around the `postMessage` function to broadcast messages efficiently.
57
+ *
58
+ * - **Encapsulation:** Ensures the `postMessage` function is scoped to the provided key.
59
+ * - **Ease of Use:** Simplifies broadcasting messages with consistent type and format.
60
+ *
61
+ * @param {S} data - The data payload to include in the message.
62
+ * @returns {void}
63
+ */
64
+ const postMessageWrapper = (data) => {
65
+ postMessage({
66
+ type: key,
67
+ data,
68
+ senderId
69
+ });
70
+ };
71
+ return postMessageWrapper;
48
72
  };
49
- // Annotate the CommonJS export names for ESM import in node:
50
- 0 && (module.exports = {
51
- useCrossFrameMessageListener
52
- });
73
+
74
+ //#endregion
75
+ exports.useCrossFrameMessageListener = useCrossFrameMessageListener;
53
76
  //# sourceMappingURL=useCrossFrameMessageListener.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/useCrossFrameMessageListener.tsx"],"sourcesContent":["'use client';\n\nimport { type MessageKey, compareUrls } from '@intlayer/editor';\nimport { useEffect } from 'react';\nimport { useCommunicator } from './CommunicatorContext';\n\n/**\n * useCrossFrameMessageListener\n *\n * This React hook listens for messages sent via the `postMessage` API and triggers a callback\n * whenever a message of the specified type (`key`) is received. It is useful for synchronizing\n * state or events across different windows, iframes, or contexts.\n *\n * @template S - The type of the data payload in the message.\n * @param key - A unique identifier for the message type to listen for.\n * @param [onEventTriggered] - A callback function triggered when a message\n * @param [revalidator] - A function that re-suscribes the listener. Could be usefull if onEventTriggered depend of some state\n * with the specified key is received. The callback receives the message data as its argument.\n *\n * @returns {{ postMessage: (data: S) => void }} An object containing a `postMessage` function\n * that allows broadcasting messages with the specified key and data.\n */\nexport const useCrossFrameMessageListener = <S,>(\n key: `${MessageKey}` | `${MessageKey}/post` | `${MessageKey}/get`,\n onEventTriggered?: (data: S) => void,\n revalidator?: any\n) => {\n const { allowedOrigins, postMessage, senderId } = useCommunicator();\n\n useEffect(() => {\n if (onEventTriggered) {\n /**\n * Message handler to process incoming messages.\n *\n * - **Message Filtering:** Ensures only messages with the specified `key` are processed.\n * - **Origin Validation:** Checks that the origin of the message is within the allowed origins.\n *\n * @param {MessageEvent<{ type: string; data: S }>} event - The incoming message event object.\n */\n const handleMessage = (\n event: MessageEvent<{ type: string; data: S; senderId: string }>\n ) => {\n const { type, data, senderId: msgSenderId } = event.data;\n\n // Ignore messages that do not match the current key\n if (type !== key) return;\n\n // Ignore messages from myself\n if (msgSenderId === senderId) return;\n\n // Check if the message origin is allowed\n if (\n typeof allowedOrigins === 'undefined' ||\n allowedOrigins?.some((url) => compareUrls(url, event.origin)) ||\n allowedOrigins?.includes('*')\n ) {\n // Update the local state with the received data\n onEventTriggered(data);\n }\n };\n\n window.addEventListener('message', handleMessage);\n\n // Clean up the event listener on unmount\n return () => window.removeEventListener('message', handleMessage);\n }\n }, [allowedOrigins, postMessage, senderId, revalidator]);\n\n /**\n * A wrapper function around the `postMessage` function to broadcast messages efficiently.\n *\n * - **Encapsulation:** Ensures the `postMessage` function is scoped to the provided key.\n * - **Ease of Use:** Simplifies broadcasting messages with consistent type and format.\n *\n * @param {S} data - The data payload to include in the message.\n * @returns {void}\n */\n const postMessageWrapper: (data?: S) => void = (data) => {\n postMessage({ type: key, data, senderId });\n };\n\n return postMessageWrapper;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAA6C;AAC7C,mBAA0B;AAC1B,iCAAgC;AAkBzB,MAAM,+BAA+B,CAC1C,KACA,kBACA,gBACG;AACH,QAAM,EAAE,gBAAgB,aAAa,SAAS,QAAI,4CAAgB;AAElE,8BAAU,MAAM;AACd,QAAI,kBAAkB;AASpB,YAAM,gBAAgB,CACpB,UACG;AACH,cAAM,EAAE,MAAM,MAAM,UAAU,YAAY,IAAI,MAAM;AAGpD,YAAI,SAAS,IAAK;AAGlB,YAAI,gBAAgB,SAAU;AAG9B,YACE,OAAO,mBAAmB,eAC1B,gBAAgB,KAAK,CAAC,YAAQ,2BAAY,KAAK,MAAM,MAAM,CAAC,KAC5D,gBAAgB,SAAS,GAAG,GAC5B;AAEA,2BAAiB,IAAI;AAAA,QACvB;AAAA,MACF;AAEA,aAAO,iBAAiB,WAAW,aAAa;AAGhD,aAAO,MAAM,OAAO,oBAAoB,WAAW,aAAa;AAAA,IAClE;AAAA,EACF,GAAG,CAAC,gBAAgB,aAAa,UAAU,WAAW,CAAC;AAWvD,QAAM,qBAAyC,CAAC,SAAS;AACvD,gBAAY,EAAE,MAAM,KAAK,MAAM,SAAS,CAAC;AAAA,EAC3C;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"file":"useCrossFrameMessageListener.cjs","names":["useCommunicator","postMessageWrapper: (data?: S) => void"],"sources":["../../src/useCrossFrameMessageListener.tsx"],"sourcesContent":["'use client';\n\nimport { compareUrls, type MessageKey } from '@intlayer/editor';\nimport { useEffect } from 'react';\nimport { useCommunicator } from './CommunicatorContext';\n\n/**\n * useCrossFrameMessageListener\n *\n * This React hook listens for messages sent via the `postMessage` API and triggers a callback\n * whenever a message of the specified type (`key`) is received. It is useful for synchronizing\n * state or events across different windows, iframes, or contexts.\n *\n * @template S - The type of the data payload in the message.\n * @param key - A unique identifier for the message type to listen for.\n * @param [onEventTriggered] - A callback function triggered when a message\n * @param [revalidator] - A function that re-suscribes the listener. Could be usefull if onEventTriggered depend of some state\n * with the specified key is received. The callback receives the message data as its argument.\n *\n * @returns {{ postMessage: (data: S) => void }} An object containing a `postMessage` function\n * that allows broadcasting messages with the specified key and data.\n */\nexport const useCrossFrameMessageListener = <S,>(\n key: `${MessageKey}` | `${MessageKey}/post` | `${MessageKey}/get`,\n onEventTriggered?: (data: S) => void,\n revalidator?: any\n) => {\n const { allowedOrigins, postMessage, senderId } = useCommunicator();\n\n useEffect(() => {\n if (onEventTriggered) {\n /**\n * Message handler to process incoming messages.\n *\n * - **Message Filtering:** Ensures only messages with the specified `key` are processed.\n * - **Origin Validation:** Checks that the origin of the message is within the allowed origins.\n *\n * @param {MessageEvent<{ type: string; data: S }>} event - The incoming message event object.\n */\n const handleMessage = (\n event: MessageEvent<{ type: string; data: S; senderId: string }>\n ) => {\n const { type, data, senderId: msgSenderId } = event.data;\n\n // Ignore messages that do not match the current key\n if (type !== key) return;\n\n // Ignore messages from myself\n if (msgSenderId === senderId) return;\n\n // Check if the message origin is allowed\n if (\n typeof allowedOrigins === 'undefined' ||\n allowedOrigins?.some((url) => compareUrls(url, event.origin)) ||\n allowedOrigins?.includes('*')\n ) {\n // Update the local state with the received data\n onEventTriggered(data);\n }\n };\n\n window.addEventListener('message', handleMessage);\n\n // Clean up the event listener on unmount\n return () => window.removeEventListener('message', handleMessage);\n }\n }, [allowedOrigins, postMessage, senderId, revalidator]);\n\n /**\n * A wrapper function around the `postMessage` function to broadcast messages efficiently.\n *\n * - **Encapsulation:** Ensures the `postMessage` function is scoped to the provided key.\n * - **Ease of Use:** Simplifies broadcasting messages with consistent type and format.\n *\n * @param {S} data - The data payload to include in the message.\n * @returns {void}\n */\n const postMessageWrapper: (data?: S) => void = (data) => {\n postMessage({ type: key, data, senderId });\n };\n\n return postMessageWrapper;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,gCACX,KACA,kBACA,gBACG;CACH,MAAM,EAAE,gBAAgB,aAAa,aAAaA,6CAAiB;AAEnE,4BAAgB;AACd,MAAI,kBAAkB;;;;;;;;;GASpB,MAAM,iBACJ,UACG;IACH,MAAM,EAAE,MAAM,MAAM,UAAU,gBAAgB,MAAM;AAGpD,QAAI,SAAS,IAAK;AAGlB,QAAI,gBAAgB,SAAU;AAG9B,QACE,OAAO,mBAAmB,eAC1B,gBAAgB,MAAM,2CAAoB,KAAK,MAAM,OAAO,CAAC,IAC7D,gBAAgB,SAAS,IAAI,CAG7B,kBAAiB,KAAK;;AAI1B,UAAO,iBAAiB,WAAW,cAAc;AAGjD,gBAAa,OAAO,oBAAoB,WAAW,cAAc;;IAElE;EAAC;EAAgB;EAAa;EAAU;EAAY,CAAC;;;;;;;;;;CAWxD,MAAMC,sBAA0C,SAAS;AACvD,cAAY;GAAE,MAAM;GAAK;GAAM;GAAU,CAAC;;AAG5C,QAAO"}