@gravity-ui/page-constructor 8.5.0-alpha.5 → 8.5.0-alpha.7

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 (52) hide show
  1. package/build/cjs/common/constants.d.ts +1 -0
  2. package/build/cjs/common/constants.js +5 -0
  3. package/build/cjs/common/constants.js.map +1 -0
  4. package/build/cjs/common/postMessage.d.ts +1 -0
  5. package/build/cjs/common/postMessage.js +13 -5
  6. package/build/cjs/common/postMessage.js.map +1 -1
  7. package/build/cjs/common/types/actions.d.ts +1 -6
  8. package/build/cjs/common/types/actions.js.map +1 -1
  9. package/build/cjs/common/types/messages.d.ts +3 -0
  10. package/build/cjs/common/types/messages.js.map +1 -1
  11. package/build/cjs/context/editorStoreContext/PCEditorStoreProvider.js +5 -3
  12. package/build/cjs/context/editorStoreContext/PCEditorStoreProvider.js.map +1 -1
  13. package/build/cjs/editor-v2/containers/MiddleScreen/MiddleScreen.css +1 -0
  14. package/build/cjs/editor-v2/containers/MiddleScreen/MiddleScreen.js +17 -13
  15. package/build/cjs/editor-v2/containers/MiddleScreen/MiddleScreen.js.map +1 -1
  16. package/build/cjs/editor-v2/context/editorStore/MainEditorStoreProvider.js +2 -0
  17. package/build/cjs/editor-v2/context/editorStore/MainEditorStoreProvider.js.map +1 -1
  18. package/build/cjs/hooks/usePCEditorInitializeEvents.d.ts +1 -0
  19. package/build/cjs/hooks/usePCEditorInitializeEvents.js +3 -16
  20. package/build/cjs/hooks/usePCEditorInitializeEvents.js.map +1 -1
  21. package/build/cjs/hooks/usePostMessageAPI.js +8 -5
  22. package/build/cjs/hooks/usePostMessageAPI.js.map +1 -1
  23. package/build/cjs/utils/iframe-resizer.d.ts +8 -0
  24. package/build/cjs/utils/iframe-resizer.js +11 -0
  25. package/build/cjs/utils/iframe-resizer.js.map +1 -0
  26. package/build/esm/common/constants.d.ts +1 -0
  27. package/build/esm/common/constants.js +2 -0
  28. package/build/esm/common/constants.js.map +1 -0
  29. package/build/esm/common/postMessage.d.ts +1 -0
  30. package/build/esm/common/postMessage.js +12 -5
  31. package/build/esm/common/postMessage.js.map +1 -1
  32. package/build/esm/common/types/actions.d.ts +1 -6
  33. package/build/esm/common/types/actions.js.map +1 -1
  34. package/build/esm/common/types/messages.d.ts +3 -0
  35. package/build/esm/common/types/messages.js.map +1 -1
  36. package/build/esm/context/editorStoreContext/PCEditorStoreProvider.js +5 -3
  37. package/build/esm/context/editorStoreContext/PCEditorStoreProvider.js.map +1 -1
  38. package/build/esm/editor-v2/containers/MiddleScreen/MiddleScreen.css +1 -0
  39. package/build/esm/editor-v2/containers/MiddleScreen/MiddleScreen.js +17 -13
  40. package/build/esm/editor-v2/containers/MiddleScreen/MiddleScreen.js.map +1 -1
  41. package/build/esm/editor-v2/context/editorStore/MainEditorStoreProvider.js +2 -0
  42. package/build/esm/editor-v2/context/editorStore/MainEditorStoreProvider.js.map +1 -1
  43. package/build/esm/hooks/usePCEditorInitializeEvents.d.ts +1 -0
  44. package/build/esm/hooks/usePCEditorInitializeEvents.js +3 -16
  45. package/build/esm/hooks/usePCEditorInitializeEvents.js.map +1 -1
  46. package/build/esm/hooks/usePostMessageAPI.js +8 -5
  47. package/build/esm/hooks/usePostMessageAPI.js.map +1 -1
  48. package/build/esm/utils/iframe-resizer.d.ts +8 -0
  49. package/build/esm/utils/iframe-resizer.js +9 -0
  50. package/build/esm/utils/iframe-resizer.js.map +1 -0
  51. package/package.json +4 -3
  52. package/widget/index.js +1 -1
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import * as React from 'react';
3
+ import { isValidPostMessage } from "../../common/postMessage.js";
3
4
  import { createPCEditorStore } from "../../common/store.js";
4
5
  import { sendEventPostMessage } from "../../hooks/usePostMessageAPI.js";
5
6
  import { PCEditorStoreContext } from "./PCEditorStoreContext.js";
@@ -12,13 +13,14 @@ export const PCEditorStoreProvider = ({ children }) => {
12
13
  }, []);
13
14
  React.useEffect(() => {
14
15
  const onMessage = (e) => {
16
+ if (!isValidPostMessage(e.data)) {
17
+ return;
18
+ }
15
19
  const message = e.data;
16
20
  syncStore(message);
17
21
  };
18
22
  window.addEventListener('message', onMessage);
19
- return () => {
20
- window.removeEventListener('message', onMessage);
21
- };
23
+ return () => window.removeEventListener('message', onMessage);
22
24
  }, [syncStore]);
23
25
  // When Page Constructor runs inside the editor preview iframe, keyboard focus stays in the iframe
24
26
  // after clicking the canvas — parent window never receives Cmd+Z. Forward to parent via postMessage.
@@ -1 +1 @@
1
- {"version":3,"file":"PCEditorStoreProvider.js","sourceRoot":"../../../../src","sources":["context/editorStoreContext/PCEditorStoreProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,EAAc,mBAAmB,EAAC,8BAA2B;AAEpE,OAAO,EAAC,oBAAoB,EAAC,yCAAsC;AAEnE,OAAO,EAAC,oBAAoB,EAAC,kCAA+B;AAI5D,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,EAAC,QAAQ,EAA6B,EAAE,EAAE;IAC5E,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,EAAyB,CAAC;IAEvD,MAAM,SAAS,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,OAAyB,EAAE,EAAE;QAC9D,IAAI,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;YACpC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC7C,CAAC;IACL,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,MAAM,SAAS,GAAG,CAAC,CAAe,EAAE,EAAE;YAClC,MAAM,OAAO,GAAG,CAAC,CAAC,IAAwB,CAAC;YAC3C,SAAS,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,S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Q,CAAC,OAAO,GAAG,mBAAmB,EAAE,CAAC;IAC7C,CAAC;IAED,OAAO,CACH,KAAC,oBAAoB,CAAC,QAAQ,IAC1B,KAAK,EAAE;YACH,KAAK,EAAE,QAAQ,CAAC,OAAO;SAC1B,YAEA,QAAQ,GACmB,CACnC,CAAC;AACN,CAAC,CAAC","sourcesContent":["import * as React from 'react';\n\nimport {StoreApi} from 'zustand';\n\nimport {EditorState, createPCEditorStore} from '../../common/store';\nimport {StoreSyncMessage} from '../../common/types';\nimport {sendEventPostMessage} from '../../hooks/usePostMessageAPI';\n\nimport {PCEditorStoreContext} from './PCEditorStoreContext';\n\ninterface PCEditorStoreProviderProps extends React.PropsWithChildren {}\n\nexport const PCEditorStoreProvider = ({children}: PCEditorStoreProviderProps) => {\n const storeRef = React.useRef<StoreApi<EditorState>>();\n\n const syncStore = React.useCallback((message: StoreSyncMessage) => {\n if (storeRef.current && message.state) {\n storeRef.current.setState(message.state);\n }\n }, []);\n\n React.useEffect(() => {\n const onMessage = (e: MessageEvent) => {\n const message = e.data as StoreSyncMessage;\n syncStore(message);\n };\n\n window.addEventListener('message', onMessage);\n\n return () => {\n window.removeEventListener('message', onMessage);\n };\n }, [syncStore]);\n\n // When Page Constructor runs inside the editor preview iframe, keyboard focus stays in the iframe\n // after clicking the canvas — parent window never receives Cmd+Z. Forward to parent via postMessage.\n React.useEffect(() => {\n if (typeof window === 'undefined' || window.parent === window) {\n return undefined;\n }\n const onKeyDown = (e: KeyboardEvent) => {\n if (!(e.metaKey || e.ctrlKey) || e.key.toLowerCase() !== 'z') {\n return;\n }\n\n const target = e.target as HTMLElement | null;\n if (target?.closest('input, textarea, select, [contenteditable=\"true\"]')) {\n return;\n }\n\n e.preventDefault();\n\n if (e.shiftKey) {\n sendEventPostMessage('ON_EDITOR_REDO', {});\n } else {\n sendEventPostMessage('ON_EDITOR_UNDO', {});\n }\n };\n window.addEventListener('keydown', onKeyDown, true);\n return () => window.removeEventListener('keydown', onKeyDown, true);\n }, []);\n\n if (!storeRef.current) {\n storeRef.current = createPCEditorStore();\n }\n\n return (\n <PCEditorStoreContext.Provider\n value={{\n state: storeRef.current,\n }}\n >\n {children}\n </PCEditorStoreContext.Provider>\n );\n};\n"]}
1
+ {"version":3,"file":"PCEditorStoreProvider.js","sourceRoot":"../../../../src","sources":["context/editorStoreContext/PCEditorStoreProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,EAAC,kBAAkB,EAAC,oCAAiC;AAC5D,OAAO,EAAc,mBAAmB,EAAC,8BAA2B;AAEpE,OAAO,EAAC,oBAAoB,EAAC,yCAAsC;AAEnE,OAAO,EAAC,oBAAoB,EAAC,kCAA+B;AAI5D,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,EAAC,QAAQ,EAA6B,EAAE,EAAE;IAC5E,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,EAAyB,CAAC;IAEvD,MAAM,SAAS,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,OAAyB,EAAE,EAAE;QAC9D,IAAI,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;YACpC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC7C,CAAC;IACL,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,MAAM,SAAS,GAAG,CAAC,CAAe,EAAE,EAAE;YAClC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC9B,OAAO;YACX,CAAC;YAED,MAAM,OAAO,GAAG,CAAC,CAAC,IAAwB,CAAC;YAC3C,SAAS,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAC9C,OAAO,GAAG,EAA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ACH,KAAC,oBAAoB,CAAC,QAAQ,IAC1B,KAAK,EAAE;YACH,KAAK,EAAE,QAAQ,CAAC,OAAO;SAC1B,YAEA,QAAQ,GACmB,CACnC,CAAC;AACN,CAAC,CAAC","sourcesContent":["import * as React from 'react';\n\nimport {StoreApi} from 'zustand';\n\nimport {isValidPostMessage} from '../../common/postMessage';\nimport {EditorState, createPCEditorStore} from '../../common/store';\nimport {StoreSyncMessage} from '../../common/types';\nimport {sendEventPostMessage} from '../../hooks/usePostMessageAPI';\n\nimport {PCEditorStoreContext} from './PCEditorStoreContext';\n\ninterface PCEditorStoreProviderProps extends React.PropsWithChildren {}\n\nexport const PCEditorStoreProvider = ({children}: PCEditorStoreProviderProps) => {\n const storeRef = React.useRef<StoreApi<EditorState>>();\n\n const syncStore = React.useCallback((message: StoreSyncMessage) => {\n if (storeRef.current && message.state) {\n storeRef.current.setState(message.state);\n }\n }, []);\n\n React.useEffect(() => {\n const onMessage = (e: MessageEvent) => {\n if (!isValidPostMessage(e.data)) {\n return;\n }\n\n const message = e.data as StoreSyncMessage;\n syncStore(message);\n };\n\n window.addEventListener('message', onMessage);\n return () => window.removeEventListener('message', onMessage);\n }, [syncStore]);\n\n // When Page Constructor runs inside the editor preview iframe, keyboard focus stays in the iframe\n // after clicking the canvas — parent window never receives Cmd+Z. Forward to parent via postMessage.\n React.useEffect(() => {\n if (typeof window === 'undefined' || window.parent === window) {\n return undefined;\n }\n const onKeyDown = (e: KeyboardEvent) => {\n if (!(e.metaKey || e.ctrlKey) || e.key.toLowerCase() !== 'z') {\n return;\n }\n\n const target = e.target as HTMLElement | null;\n if (target?.closest('input, textarea, select, [contenteditable=\"true\"]')) {\n return;\n }\n\n e.preventDefault();\n\n if (e.shiftKey) {\n sendEventPostMessage('ON_EDITOR_REDO', {});\n } else {\n sendEventPostMessage('ON_EDITOR_UNDO', {});\n }\n };\n window.addEventListener('keydown', onKeyDown, true);\n return () => window.removeEventListener('keydown', onKeyDown, true);\n }, []);\n\n if (!storeRef.current) {\n storeRef.current = createPCEditorStore();\n }\n\n return (\n <PCEditorStoreContext.Provider\n value={{\n state: storeRef.current,\n }}\n >\n {children}\n </PCEditorStoreContext.Provider>\n );\n};\n"]}
@@ -88,6 +88,7 @@
88
88
  .pceditor-middle-screen__iframe-container {
89
89
  position: relative;
90
90
  margin: 0 auto;
91
+ overflow: hidden;
91
92
  }
92
93
  .pceditor-middle-screen__iframe-container_fullscreen {
93
94
  height: 100%;
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import * as React from 'react';
3
3
  import { Xmark } from '@gravity-ui/icons';
4
4
  import { Button, Icon, Loader } from '@gravity-ui/uikit';
5
- import { usePostMessageAPIListener } from "../../../common/postMessage.js";
5
+ import iframeResize from '@iframe-resizer/parent';
6
6
  import { IframeContext } from "../../context/iframeContext/index.js";
7
7
  import { useMainEditorStore } from "../../hooks/useMainEditorStore.js";
8
8
  import { editorCn } from "../../utils/cn.js";
@@ -11,24 +11,28 @@ import './MiddleScreen.css';
11
11
  const b = editorCn('middle-screen');
12
12
  const MiddleScreen = ({ className, CustomTop }) => {
13
13
  const { zoom, initialized, deviceWidth, isPreviewMode, togglePreviewMode } = useMainEditorStore();
14
- const { url, setIframeElement } = React.useContext(IframeContext);
14
+ const { url, iframeElement, setIframeElement } = React.useContext(IframeContext);
15
15
  const [canvasRef, setCanvasRef] = React.useState(null);
16
- const [height, setHeight] = React.useState(0);
17
16
  const canvasStyle = React.useMemo(() => ({
18
17
  transform: isPreviewMode ? 'none' : `scale(${zoom}%)`,
19
18
  height: isPreviewMode ? '100%' : `${(100 / zoom) * 100}%`,
20
19
  width: isPreviewMode ? '100%' : `${(100 / zoom) * 100}%`,
21
20
  maxWidth: isPreviewMode ? '100%' : `${(100 / zoom) * 100}%`,
22
21
  }), [isPreviewMode, zoom]);
23
- const onResize = React.useCallback((newHeight) => {
24
- setHeight(newHeight + 100);
25
- }, [setHeight]);
26
- usePostMessageAPIListener('ON_RESIZE', ({ height: newHeight }) => {
27
- onResize(newHeight);
28
- });
29
- usePostMessageAPIListener('ON_INIT', ({ height: newHeight }) => {
30
- onResize(newHeight);
31
- });
22
+ React.useEffect(() => {
23
+ if (!iframeElement || isPreviewMode) {
24
+ return undefined;
25
+ }
26
+ const [instance] = iframeResize({
27
+ license: 'GPLv3',
28
+ direction: 'vertical',
29
+ checkOrigin: false,
30
+ waitForLoad: true,
31
+ }, iframeElement);
32
+ return () => {
33
+ instance?.iFrameResizer?.disconnect();
34
+ };
35
+ }, [iframeElement, isPreviewMode]);
32
36
  const isWithBackground = React.useMemo(() => {
33
37
  return deviceWidth !== '100%';
34
38
  }, [deviceWidth]);
@@ -40,7 +44,7 @@ const MiddleScreen = ({ className, CustomTop }) => {
40
44
  if (instance) {
41
45
  setIframeElement(instance);
42
46
  }
43
- }, className: b('iframe', { fullscreen: isPreviewMode }), src: url, height: isPreviewMode ? '100%' : `${height}px`, width: isPreviewMode ? '100%' : deviceWidth, frameBorder: "0", title: "Page Constructor Iframe" }), !isPreviewMode && (_jsx(Overlay, { className: b('overlay'), canvasElement: canvasRef }))] }), isPreviewMode && (_jsx(Button, { view: "normal-contrast", className: b('exit-preview'), onClick: togglePreviewMode, "aria-label": "Exit preview mode", title: "Exit preview mode", size: "l", children: _jsx(Icon, { size: 24, data: Xmark }) })), !initialized && (_jsx("div", { className: b('loading'), children: _jsx(Loader, { size: 'l' }) }))] }) }) })] }));
47
+ }, className: b('iframe', { fullscreen: isPreviewMode }), src: url, width: isPreviewMode ? '100%' : deviceWidth, frameBorder: "0", title: "Page Constructor Iframe" }), !isPreviewMode && (_jsx(Overlay, { className: b('overlay'), canvasElement: canvasRef }))] }), isPreviewMode && (_jsx(Button, { view: "normal-contrast", className: b('exit-preview'), onClick: togglePreviewMode, "aria-label": "Exit preview mode", title: "Exit preview mode", size: "l", children: _jsx(Icon, { size: 24, data: Xmark }) })), !initialized && (_jsx("div", { className: b('loading'), children: _jsx(Loader, { size: 'l' }) }))] }) }) })] }));
44
48
  };
45
49
  export default MiddleScreen;
46
50
  //# sourceMappingURL=MiddleScreen.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MiddleScreen.js","sourceRoot":"../../../../../src","sources":["editor-v2/containers/MiddleScreen/MiddleScreen.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAC,KAAK,EAAC,MAAM,mBAAmB,CAAC;AACxC,OAAO,EAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAC,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAC,yBAAyB,EAAC,uCAAoC;AACtE,OAAO,EAAC,aAAa,EAAC,6CAAoC;AAC1D,OAAO,EAAC,kBAAkB,EAAC,0CAAuC;AAClE,OAAO,EAAC,QAAQ,EAAC,0BAAuB;AACxC,OAAO,OAAO,8BAA2B;AAEzC,OAAO,oBAAoB,CAAC;AAE5B,MAAM,CAAC,GAAG,QAAQ,CAAC,eAAe,CAAC,CAAC;AAOpC,MAAM,YAAY,GAAG,CAAC,EAAC,SAAS,EAAE,SAAS,EAAoB,EAAE,EAAE;IAC/D,MAAM,EAAC,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,iBAAiB,EAAC,GAAG,kBAAkB,EAAE,CAAC;IAChG,MAAM,EAAC,GAAG,EAAE,gBAAgB,EAAC,GAAG,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IAChE,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAwB,IAAI,CAAC,CAAC;IAC9E,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE9C,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAC7B,GAAG,EAAE,CAAC,CAAC;QACH,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,C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CAAC,EAC5B,OAAO,EAAE,iBAAiB,gBACf,mBAAmB,EAC9B,KAAK,EAAC,mBAAmB,EACzB,IAAI,EAAC,GAAG,YAER,KAAC,IAAI,IAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,GAAI,GAC1B,CACZ,EACA,CAAC,WAAW,IAAI,CACb,cAAK,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,YACxB,KAAC,MAAM,IAAC,IAAI,EAAE,GAAG,GAAI,GACnB,CACT,IACC,GACJ,GACJ,IACJ,CACT,CAAC;AACN,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import * as React from 'react';\n\nimport {Xmark} from '@gravity-ui/icons';\nimport {Button, Icon, Loader} from '@gravity-ui/uikit';\n\nimport {usePostMessageAPIListener} from '../../../common/postMessage';\nimport {IframeContext} from '../../context/iframeContext';\nimport {useMainEditorStore} from '../../hooks/useMainEditorStore';\nimport {editorCn} from '../../utils/cn';\nimport Overlay from '../Overlay/Overlay';\n\nimport './MiddleScreen.scss';\n\nconst b = editorCn('middle-screen');\n\ninterface MiddleScreenProps {\n className?: string;\n CustomTop?: React.ElementType;\n}\n\nconst MiddleScreen = ({className, CustomTop}: MiddleScreenProps) => {\n const {zoom, initialized, deviceWidth, isPreviewMode, togglePreviewMode} = useMainEditorStore();\n const {url, setIframeElement} = React.useContext(IframeContext);\n const [canvasRef, setCanvasRef] = React.useState<HTMLDivElement | null>(null);\n const [height, setHeight] = React.useState(0);\n\n const canvasStyle = React.useMemo(\n () => ({\n transform: isPreviewMode ? 'none' : `scale(${zoom}%)`,\n height: isPreviewMode ? '100%' : `${(100 / zoom) * 100}%`,\n width: isPreviewMode ? '100%' : `${(100 / zoom) * 100}%`,\n maxWidth: isPreviewMode ? '100%' : `${(100 / zoom) * 100}%`,\n }),\n [isPreviewMode, zoom],\n );\n\n const onResize = React.useCallback(\n (newHeight: number) => {\n setHeight(newHeight + 100);\n },\n [setHeight],\n );\n\n usePostMessageAPIListener('ON_RESIZE', ({height: newHeight}) => {\n onResize(newHeight);\n });\n\n usePostMessageAPIListener('ON_INIT', ({height: newHeight}) => {\n onResize(newHeight);\n });\n\n const isWithBackground = React.useMemo(() => {\n return deviceWidth !== '100%';\n }, [deviceWidth]);\n\n return (\n <div className={b(null, className)}>\n {CustomTop && !isPreviewMode ? (\n <div className={b('topbar')}>\n <CustomTop />\n </div>\n ) : null}\n <div className={b('content', {fullscreen: isPreviewMode})}>\n <div className={b('wrapper')}>\n <div\n ref={setCanvasRef}\n className={b('canvas', {\n hidden: !initialized,\n fullscreen: isPreviewMode,\n withBackground: isWithBackground,\n })}\n style={canvasStyle}\n >\n <div\n className={b('iframe-container', {fullscreen: isPreviewMode})}\n style={{width: isPreviewMode ? '100%' : deviceWidth}}\n >\n <iframe\n ref={(instance) => {\n if (instance) {\n setIframeElement(instance);\n }\n }}\n className={b('iframe', {fullscreen: isPreviewMode})}\n src={url}\n height={isPreviewMode ? '100%' : `${height}px`}\n width={isPreviewMode ? '100%' : deviceWidth}\n frameBorder=\"0\"\n title=\"Page Constructor Iframe\"\n />\n {!isPreviewMode && (\n <Overlay className={b('overlay')} canvasElement={canvasRef} />\n )}\n </div>\n {isPreviewMode && (\n <Button\n view=\"normal-contrast\"\n className={b('exit-preview')}\n onClick={togglePreviewMode}\n aria-label=\"Exit preview mode\"\n title=\"Exit preview mode\"\n size=\"l\"\n >\n <Icon size={24} data={Xmark} />\n </Button>\n )}\n {!initialized && (\n <div className={b('loading')}>\n <Loader size={'l'} />\n </div>\n )}\n </div>\n </div>\n </div>\n </div>\n );\n};\n\nexport default MiddleScreen;\n"]}
1
+ {"version":3,"file":"MiddleScreen.js","sourceRoot":"../../../../../src","sources":["editor-v2/containers/MiddleScreen/MiddleScreen.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAC,KAAK,EAAC,MAAM,mBAAmB,CAAC;AACxC,OAAO,EAAC,MAAM,EAA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BAAkB,EAAE,EAAC,UAAU,EAAE,aAAa,EAAC,CAAC,EAC7D,KAAK,EAAE,EAAC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,EAAC,aAEpD,iBACI,GAAG,EAAE,CAAC,QAAQ,EAAE,EAAE;4CACd,IAAI,QAAQ,EAAE,CAAC;gDACX,gBAAgB,CAAC,QAAQ,CAAC,CAAC;4CAC/B,CAAC;wCACL,CAAC,EACD,SAAS,EAAE,CAAC,CAAC,QAAQ,EAAE,EAAC,UAAU,EAAE,aAAa,EAAC,CAAC,EACnD,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,EAC3C,WAAW,EAAC,GAAG,EACf,KAAK,EAAC,yBAAyB,GACjC,EACD,CAAC,aAAa,IAAI,CACf,KAAC,OAAO,IAAC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,EAAE,aAAa,EAAE,SAAS,GAAI,CACjE,IACC,EACL,aAAa,IAAI,CACd,KAAC,MAAM,IACH,IAAI,EAAC,iBAAiB,EACtB,SAAS,EAAE,CAAC,CAAC,cAAc,CAAC,EAC5B,OAAO,EAAE,iBAAiB,gBACf,mBAAmB,EAC9B,KAAK,EAAC,mBAAmB,EACzB,IAAI,EAAC,GAAG,YAER,KAAC,IAAI,IAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,GAAI,GAC1B,CACZ,EACA,CAAC,WAAW,IAAI,CACb,cAAK,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,YACxB,KAAC,MAAM,IAAC,IAAI,EAAE,GAAG,GAAI,GACnB,CACT,IACC,GACJ,GACJ,IACJ,CACT,CAAC;AACN,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import * as React from 'react';\n\nimport {Xmark} from '@gravity-ui/icons';\nimport {Button, Icon, Loader} from '@gravity-ui/uikit';\nimport iframeResize from '@iframe-resizer/parent';\n\nimport {IframeContext} from '../../context/iframeContext';\nimport {useMainEditorStore} from '../../hooks/useMainEditorStore';\nimport {editorCn} from '../../utils/cn';\nimport Overlay from '../Overlay/Overlay';\n\nimport './MiddleScreen.scss';\n\nconst b = editorCn('middle-screen');\n\ninterface MiddleScreenProps {\n className?: string;\n CustomTop?: React.ElementType;\n}\n\nconst MiddleScreen = ({className, CustomTop}: MiddleScreenProps) => {\n const {zoom, initialized, deviceWidth, isPreviewMode, togglePreviewMode} = useMainEditorStore();\n const {url, iframeElement, setIframeElement} = React.useContext(IframeContext);\n const [canvasRef, setCanvasRef] = React.useState<HTMLDivElement | null>(null);\n\n const canvasStyle = React.useMemo(\n () => ({\n transform: isPreviewMode ? 'none' : `scale(${zoom}%)`,\n height: isPreviewMode ? '100%' : `${(100 / zoom) * 100}%`,\n width: isPreviewMode ? '100%' : `${(100 / zoom) * 100}%`,\n maxWidth: isPreviewMode ? '100%' : `${(100 / zoom) * 100}%`,\n }),\n [isPreviewMode, zoom],\n );\n\n React.useEffect(() => {\n if (!iframeElement || isPreviewMode) {\n return undefined;\n }\n\n const [instance] = iframeResize(\n {\n license: 'GPLv3',\n direction: 'vertical',\n checkOrigin: false,\n waitForLoad: true,\n },\n iframeElement,\n );\n\n return () => {\n instance?.iFrameResizer?.disconnect();\n };\n }, [iframeElement, isPreviewMode]);\n\n const isWithBackground = React.useMemo(() => {\n return deviceWidth !== '100%';\n }, [deviceWidth]);\n\n return (\n <div className={b(null, className)}>\n {CustomTop && !isPreviewMode ? (\n <div className={b('topbar')}>\n <CustomTop />\n </div>\n ) : null}\n <div className={b('content', {fullscreen: isPreviewMode})}>\n <div className={b('wrapper')}>\n <div\n ref={setCanvasRef}\n className={b('canvas', {\n hidden: !initialized,\n fullscreen: isPreviewMode,\n withBackground: isWithBackground,\n })}\n style={canvasStyle}\n >\n <div\n className={b('iframe-container', {fullscreen: isPreviewMode})}\n style={{width: isPreviewMode ? '100%' : deviceWidth}}\n >\n <iframe\n ref={(instance) => {\n if (instance) {\n setIframeElement(instance);\n }\n }}\n className={b('iframe', {fullscreen: isPreviewMode})}\n src={url}\n width={isPreviewMode ? '100%' : deviceWidth}\n frameBorder=\"0\"\n title=\"Page Constructor Iframe\"\n />\n {!isPreviewMode && (\n <Overlay className={b('overlay')} canvasElement={canvasRef} />\n )}\n </div>\n {isPreviewMode && (\n <Button\n view=\"normal-contrast\"\n className={b('exit-preview')}\n onClick={togglePreviewMode}\n aria-label=\"Exit preview mode\"\n title=\"Exit preview mode\"\n size=\"l\"\n >\n <Icon size={24} data={Xmark} />\n </Button>\n )}\n {!initialized && (\n <div className={b('loading')}>\n <Loader size={'l'} />\n </div>\n )}\n </div>\n </div>\n </div>\n </div>\n );\n};\n\nexport default MiddleScreen;\n"]}
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import * as React from 'react';
3
+ import { POST_MESSAGE_SOURCE } from "../../../common/constants.js";
3
4
  import { removeFn } from "../../../common/utils.js";
4
5
  import { createEditorStore } from "../../store.js";
5
6
  import { IframeContext } from "../iframeContext/index.js";
@@ -10,6 +11,7 @@ export const MainEditorStoreProvider = ({ children }) => {
10
11
  const sendPostMessage = React.useCallback((data) => {
11
12
  const message = {
12
13
  state: data,
14
+ source: POST_MESSAGE_SOURCE,
13
15
  };
14
16
  if (iframeElement && iframeElement.contentWindow) {
15
17
  iframeElement.contentWindow.postMessage(message, '*');
@@ -1 +1 @@
1
- {"version":3,"file":"MainEditorStoreProvider.js","sourceRoot":"../../../../../src","sources":["editor-v2/context/editorStore/MainEditorStoreProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,OAAO,EAAC,QAAQ,EAAC,iCAA8B;AAC/C,OAAO,EAAc,iBAAiB,EAAC,uBAAoB;AAC3D,OAAO,EAAC,aAAa,EAAC,kCAAyB;AAE/C,OAAO,EAAC,sBAAsB,EAAC,oCAAiC;AAIhE,MAA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oreApi} from 'zustand';\n\nimport {EditorState} from '../../../common/store';\nimport {StoreSyncMessage} from '../../../common/types';\nimport {removeFn} from '../../../common/utils';\nimport {EditorStore, createEditorStore} from '../../store';\nimport {IframeContext} from '../iframeContext';\n\nimport {MainEditorStoreContext} from './MainEditorStoreContext';\n\ninterface MainEditorProviderProps extends React.PropsWithChildren {}\n\nexport const MainEditorStoreProvider = ({children}: MainEditorProviderProps) => {\n const {iframeElement} = React.useContext(IframeContext);\n const storeRef = React.useRef<StoreApi<EditorStore>>();\n\n const sendPostMessage = React.useCallback(\n (data: EditorState) => {\n const message: StoreSyncMessage = {\n state: data,\n };\n\n if (iframeElement && iframeElement.contentWindow) {\n iframeElement.contentWindow.postMessage(message, '*');\n }\n },\n [iframeElement],\n );\n\n if (!storeRef.current) {\n storeRef.current = createEditorStore();\n }\n\n React.useEffect(() => {\n storeRef.current?.subscribe((state) => {\n const {historyPast: _historyPast, historyFuture: _historyFuture, ...syncable} = state;\n sendPostMessage(removeFn({...syncable, historyPast: [], historyFuture: []}));\n });\n }, [sendPostMessage]);\n\n return (\n <MainEditorStoreContext.Provider\n value={{\n state: storeRef.current,\n }}\n >\n {children}\n </MainEditorStoreContext.Provider>\n );\n};\n"]}
1
+ {"version":3,"file":"MainEditorStoreProvider.js","sourceRoot":"../../../../../src","sources":["editor-v2/context/editorStore/MainEditorStoreProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,EAAC,mBAAmB,EAAC,qCAAkC;AAG9D,OAAO,EAAC,QAAQ,EAAC,iCAA8B;AAC/C,OAAO,EAAc,iBAAiB,EAAC,uBAAoB;AAC3D,OAAO,EAAC,aAAa,EAAC,kCAAyB;AAE/C,OAAO,EAAC,sBAAsB,EAAC,oCAAiC;AAIhE,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,EAAC,QAAQ,EAA0B,EAAE,EAAE;IAC3E,MAAM,EAAC,aAAa,EAAC,GAAG,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IACxD,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,EAAyB,CAAC;IAEvD,MAAM,eAAe,GAAG,KAAK,CAAC,WAAW,CACrC,CAAC,IAAiB,EAAE,EAAE;QAClB,MAAM,OAAO,GAAqB;YAC9B,KAAK,EAAE,IAAI;YACX,MAAM,EAAE,mBAAmB;SAC9B,CAAC;QAEF,IAAI,aAAa,IAAI,aAAa,CAAC,aAAa,EAAE,CAAC;YAC/C,aAAa,CAAC,aAAa,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC1D,CAAC;IACL,CAAC,EACD,CAAC,aAAa,CAAC,CAClB,CAAC;IAEF,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;QACpB,QAAQ,CAAC,OAAO,GAAG,iBAAiB,EAAE,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;YAClC,MAAM,EAAC,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,GAAG,QAAQ,EAAC,GAAG,KAAK,CAAC;YACtF,eAAe,CAAC,QAAQ,CAAC,EAAC,GAAG,QAAQ,EAAE,WAAW,EAAE,EAAE,EAAE,aAAa,EAAE,EAAE,EAAC,CAAC,CAAC,CAAC;QACjF,CAAC,CAAC,CAAC;IACP,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;IAEtB,OAAO,CACH,KAAC,sBAAsB,CAAC,QAAQ,IAC5B,KAAK,EAAE;YACH,KAAK,EAAE,QAAQ,CAAC,OAAO;SAC1B,YAEA,QAAQ,GACqB,CACrC,CAAC;AACN,CAAC,CAAC","sourcesContent":["import * as React from 'react';\n\nimport {StoreApi} from 'zustand';\n\nimport {POST_MESSAGE_SOURCE} from '../../../common/constants';\nimport {EditorState} from '../../../common/store';\nimport {StoreSyncMessage} from '../../../common/types';\nimport {removeFn} from '../../../common/utils';\nimport {EditorStore, createEditorStore} from '../../store';\nimport {IframeContext} from '../iframeContext';\n\nimport {MainEditorStoreContext} from './MainEditorStoreContext';\n\ninterface MainEditorProviderProps extends React.PropsWithChildren {}\n\nexport const MainEditorStoreProvider = ({children}: MainEditorProviderProps) => {\n const {iframeElement} = React.useContext(IframeContext);\n const storeRef = React.useRef<StoreApi<EditorStore>>();\n\n const sendPostMessage = React.useCallback(\n (data: EditorState) => {\n const message: StoreSyncMessage = {\n state: data,\n source: POST_MESSAGE_SOURCE,\n };\n\n if (iframeElement && iframeElement.contentWindow) {\n iframeElement.contentWindow.postMessage(message, '*');\n }\n },\n [iframeElement],\n );\n\n if (!storeRef.current) {\n storeRef.current = createEditorStore();\n }\n\n React.useEffect(() => {\n storeRef.current?.subscribe((state) => {\n const {historyPast: _historyPast, historyFuture: _historyFuture, ...syncable} = state;\n sendPostMessage(removeFn({...syncable, historyPast: [], historyFuture: []}));\n });\n }, [sendPostMessage]);\n\n return (\n <MainEditorStoreContext.Provider\n value={{\n state: storeRef.current,\n }}\n >\n {children}\n </MainEditorStoreContext.Provider>\n );\n};\n"]}
@@ -2,6 +2,7 @@ import { BlockData } from "../constructor-items.js";
2
2
  import { BlockRegistry } from "../context/blockRegistryContext/index.js";
3
3
  import { Fields } from "../form-generator-v2/types.js";
4
4
  import { PageContent } from "../models/index.js";
5
+ import "../utils/iframe-resizer.js";
5
6
  interface UseEditorInitializeProps {
6
7
  initialContent: PageContent;
7
8
  setContent: (content: PageContent) => void;
@@ -1,6 +1,8 @@
1
1
  import * as React from 'react';
2
2
  import _ from 'lodash';
3
3
  import { toSerializableRect } from "../common/types/rect.js";
4
+ // eslint-disable-next-line import/no-unassigned-import
5
+ import "../utils/iframe-resizer.js";
4
6
  import { usePCEditorStore } from "./usePCEditorStore.js";
5
7
  import { sendEventPostMessage, useInternalPostMessageAPIListener } from "./usePostMessageAPI.js";
6
8
  function collectRectMap(registry) {
@@ -34,10 +36,6 @@ export const usePCEditorInitializeEvents = ({ initialContent, setContent, blocks
34
36
  global: global || [],
35
37
  });
36
38
  });
37
- const onResize = React.useCallback(() => {
38
- const height = document.body.scrollHeight;
39
- sendEventPostMessage('ON_RESIZE', { height });
40
- }, []);
41
39
  React.useEffect(() => {
42
40
  if (!registry) {
43
41
  return undefined;
@@ -69,18 +67,7 @@ export const usePCEditorInitializeEvents = ({ initialContent, setContent, blocks
69
67
  };
70
68
  }, [registry]);
71
69
  React.useEffect(() => {
72
- window.addEventListener('resize', onResize);
73
- const observer = new ResizeObserver(onResize);
74
- observer.observe(document.documentElement);
75
- observer.observe(document.body);
76
- return () => {
77
- window.removeEventListener('resize', onResize);
78
- observer.disconnect();
79
- };
80
- }, [onResize]);
81
- React.useEffect(() => {
82
- const height = document.body.scrollHeight;
83
- sendEventPostMessage('ON_INIT', { height });
70
+ sendEventPostMessage('ON_INIT', {});
84
71
  }, []);
85
72
  };
86
73
  //# sourceMappingURL=usePCEditorInitializeEvents.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"usePCEditorInitializeEvents.js","sourceRoot":"../../../src","sources":["hooks/usePCEditorInitializeEvents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,OAAO,EAAC,kBAAkB,EAAC,gCAA6B;AAMxD,OAAO,EAAC,gBAAgB,EAAC,8BAA2B;AACpD,OAAO,EAAC,oBAAoB,EAAE,iCAAiC,EAAC,+BAA4B;AAW5F,SAAS,cAAc,CAAC,QAAuB;IAC3C,OAAO,QAAQ,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAC,EAAE,EAAE;QAC3D,MAAM,IAAI,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,qBAAq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K,KAAK,IAAI,EAAE,CAAC;gBACjB,oBAAoB,CAAC,KAAK,CAAC,CAAC;YAChC,CAAC;QACL,CAAC,CAAC;IACN,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC5C,MAAM,QAAQ,GAAG,IAAI,cAAc,CAAC,QAAQ,CAAC,CAAC;QAC9C,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;QAC3C,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEhC,OAAO,GAAG,EAAE;YACR,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YAC/C,QAAQ,CAAC,UAAU,EAAE,CAAC;QAC1B,CAAC,CAAC;IACN,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC;QAC1C,oBAAoB,CAAC,SAAS,EAAE,EAAC,MAAM,EAAC,CAAC,CAAC;IAC9C,CAAC,EAAE,EAAE,CAAC,CAAC;AACX,CAAC,CAAC","sourcesContent":["import * as React from 'react';\n\nimport _ from 'lodash';\n\nimport {toSerializableRect} from '../common/types/rect';\nimport {BlockData} from '../constructor-items';\nimport {BlockRegistry} from '../context/blockRegistryContext';\nimport {Fields} from '../form-generator-v2/types';\nimport {PageContent} from '../models';\n\nimport {usePCEditorStore} from './usePCEditorStore';\nimport {sendEventPostMessage, useInternalPostMessageAPIListener} from './usePostMessageAPI';\n\ninterface UseEditorInitializeProps {\n initialContent: PageContent;\n setContent: (content: PageContent) => void;\n blocks: Array<BlockData>;\n global?: Fields;\n blockInputs?: Fields;\n registry: BlockRegistry | null;\n}\n\nfunction collectRectMap(registry: BlockRegistry) {\n return registry.getEntries().map(({path, element, dropZone}) => {\n const rect = element.getClientRects().item(0) ?? element.getBoundingClientRect();\n return {path, rect: toSerializableRect(rect), dropZone};\n });\n}\n\nexport const usePCEditorInitializeEvents = ({\n initialContent,\n setContent,\n blocks,\n global,\n blockInputs,\n registry,\n}: UseEditorInitializeProps) => {\n const {initialized, content} = usePCEditorStore();\n\n React.useEffect(() => {\n if (initialized) {\n setContent(content);\n }\n }, [content, initialized, setContent]);\n\n useInternalPostMessageAPIListener('GET_INITIAL_CONTENT', () => {\n sendEventPostMessage('ON_INITIAL_CONTENT', initialContent);\n });\n\n useInternalPostMessageAPIListener('GET_SUPPORTED_BLOCKS', () => {\n sendEventPostMessage('ON_SUPPORTED_BLOCKS', {\n blocks: blocks.map((block) => ({\n type: block.type,\n schema: blockInputs?.length\n ? {\n ...block.schema,\n inputs: [...blockInputs, ...(block.schema?.inputs || [])],\n }\n : block.schema,\n })),\n subBlocks: [],\n global: global || [],\n });\n });\n\n const onResize = React.useCallback(() => {\n const height = document.body.scrollHeight;\n sendEventPostMessage('ON_RESIZE', {height});\n }, []);\n\n React.useEffect(() => {\n if (!registry) {\n return undefined;\n }\n\n let frame: number | null = null;\n\n const sendRectMap = () => {\n frame = null;\n sendEventPostMessage('ON_UPDATE_RECT_MAP', {rects: collectRectMap(registry)});\n };\n\n const scheduleSend = () => {\n if (frame !== null) {\n return;\n }\n frame = requestAnimationFrame(sendRectMap);\n };\n\n const throttledSchedule = _.throttle(scheduleSend, 100, {leading: true, trailing: true});\n\n const unsubscribe = registry.subscribe(throttledSchedule);\n const observer = new ResizeObserver(throttledSchedule);\n observer.observe(document.body);\n\n // Initial push once registry is ready.\n throttledSchedule();\n\n return () => {\n throttledSchedule.cancel();\n unsubscribe();\n observer.disconnect();\n if (frame !== null) {\n cancelAnimationFrame(frame);\n }\n };\n }, [registry]);\n\n React.useEffect(() => {\n window.addEventListener('resize', onResize);\n const observer = new ResizeObserver(onResize);\n observer.observe(document.documentElement);\n observer.observe(document.body);\n\n return () => {\n window.removeEventListener('resize', onResize);\n observer.disconnect();\n };\n }, [onResize]);\n\n React.useEffect(() => {\n const height = document.body.scrollHeight;\n sendEventPostMessage('ON_INIT', {height});\n }, []);\n};\n"]}
1
+ {"version":3,"file":"usePCEditorInitializeEvents.js","sourceRoot":"../../../src","sources":["hooks/usePCEditorInitializeEvents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,OAAO,EAAC,kBAAkB,EAAC,gCAA6B;AAKxD,uDAAuD;AACvD,oCAAiC;AAEjC,OAAO,EAAC,gBAAgB,EAAC,8BAA2B;AACpD,OAAO,EAAC,oBAAoB,EAAE,iCAAiC,EAAC,+BAA4B;AAW5F,SAAS,cAAc,CAAC,QAAuB;IAC3C,OAAO,QAAQ,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAC,EAAE,EAAE;QAC3D,MAAM,IAAI,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,qBAAqB,EAAE,CAAC;QACjF,OAAO,EAAC,IAAI,EAAE,IAAI,EAAE,kBAAkB,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACP,CAAC;AAED,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,EACxC,cAAc,EACd,UAAU,EACV,MAAM,EACN,MAAM,EACN,WAAW,EACX,QAAQ,GACe,EAAE,EAAE;IAC3B,MAAM,EAAC,WAAW,EAAE,OAAO,EAAC,GAAG,gBAAgB,EAAE,CAAC;IAElD,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,IAAI,WAAW,EAAE,CAAC;YACd,UAAU,CAAC,OAAO,CAAC,CAAC;QACx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W,CAAC,CAAC;QAC/C,CAAC,CAAC;QAEF,MAAM,iBAAiB,GAAG,CAAC,CAAC,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE,EAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC;QAEzF,MAAM,WAAW,GAAG,QAAQ,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC;QAC1D,MAAM,QAAQ,GAAG,IAAI,cAAc,CAAC,iBAAiB,CAAC,CAAC;QACvD,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEhC,uCAAuC;QACvC,iBAAiB,EAAE,CAAC;QAEpB,OAAO,GAAG,EAAE;YACR,iBAAiB,CAAC,MAAM,EAAE,CAAC;YAC3B,WAAW,EAAE,CAAC;YACd,QAAQ,CAAC,UAAU,EAAE,CAAC;YACtB,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBACjB,oBAAoB,CAAC,KAAK,CAAC,CAAC;YAChC,CAAC;QACL,CAAC,CAAC;IACN,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,oBAAoB,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IACxC,CAAC,EAAE,EAAE,CAAC,CAAC;AACX,CAAC,CAAC","sourcesContent":["import * as React from 'react';\n\nimport _ from 'lodash';\n\nimport {toSerializableRect} from '../common/types/rect';\nimport {BlockData} from '../constructor-items';\nimport {BlockRegistry} from '../context/blockRegistryContext';\nimport {Fields} from '../form-generator-v2/types';\nimport {PageContent} from '../models';\n// eslint-disable-next-line import/no-unassigned-import\nimport '../utils/iframe-resizer';\n\nimport {usePCEditorStore} from './usePCEditorStore';\nimport {sendEventPostMessage, useInternalPostMessageAPIListener} from './usePostMessageAPI';\n\ninterface UseEditorInitializeProps {\n initialContent: PageContent;\n setContent: (content: PageContent) => void;\n blocks: Array<BlockData>;\n global?: Fields;\n blockInputs?: Fields;\n registry: BlockRegistry | null;\n}\n\nfunction collectRectMap(registry: BlockRegistry) {\n return registry.getEntries().map(({path, element, dropZone}) => {\n const rect = element.getClientRects().item(0) ?? element.getBoundingClientRect();\n return {path, rect: toSerializableRect(rect), dropZone};\n });\n}\n\nexport const usePCEditorInitializeEvents = ({\n initialContent,\n setContent,\n blocks,\n global,\n blockInputs,\n registry,\n}: UseEditorInitializeProps) => {\n const {initialized, content} = usePCEditorStore();\n\n React.useEffect(() => {\n if (initialized) {\n setContent(content);\n }\n }, [content, initialized, setContent]);\n\n useInternalPostMessageAPIListener('GET_INITIAL_CONTENT', () => {\n sendEventPostMessage('ON_INITIAL_CONTENT', initialContent);\n });\n\n useInternalPostMessageAPIListener('GET_SUPPORTED_BLOCKS', () => {\n sendEventPostMessage('ON_SUPPORTED_BLOCKS', {\n blocks: blocks.map((block) => ({\n type: block.type,\n schema: blockInputs?.length\n ? {\n ...block.schema,\n inputs: [...blockInputs, ...(block.schema?.inputs || [])],\n }\n : block.schema,\n })),\n subBlocks: [],\n global: global || [],\n });\n });\n\n React.useEffect(() => {\n if (!registry) {\n return undefined;\n }\n\n let frame: number | null = null;\n\n const sendRectMap = () => {\n frame = null;\n sendEventPostMessage('ON_UPDATE_RECT_MAP', {rects: collectRectMap(registry)});\n };\n\n const scheduleSend = () => {\n if (frame !== null) {\n return;\n }\n frame = requestAnimationFrame(sendRectMap);\n };\n\n const throttledSchedule = _.throttle(scheduleSend, 100, {leading: true, trailing: true});\n\n const unsubscribe = registry.subscribe(throttledSchedule);\n const observer = new ResizeObserver(throttledSchedule);\n observer.observe(document.body);\n\n // Initial push once registry is ready.\n throttledSchedule();\n\n return () => {\n throttledSchedule.cancel();\n unsubscribe();\n observer.disconnect();\n if (frame !== null) {\n cancelAnimationFrame(frame);\n }\n };\n }, [registry]);\n\n React.useEffect(() => {\n sendEventPostMessage('ON_INIT', {});\n }, []);\n};\n"]}
@@ -1,20 +1,23 @@
1
1
  import * as React from 'react';
2
+ import { POST_MESSAGE_SOURCE } from "../common/constants.js";
3
+ import { isValidPostMessage } from "../common/postMessage.js";
2
4
  export function sendEventPostMessage(action, data) {
3
- const message = { action, data };
5
+ const message = { action, data, source: POST_MESSAGE_SOURCE };
4
6
  window.parent.postMessage(message, '*');
5
7
  }
6
8
  export function listenPostMessageActions(action, callback) {
7
9
  const onMessage = (e) => {
10
+ if (!isValidPostMessage(e.data)) {
11
+ return undefined;
12
+ }
8
13
  const message = e.data;
9
- if ('action' in message && message.action === action) {
14
+ if (message.action === action) {
10
15
  return callback(message.data);
11
16
  }
12
17
  return undefined;
13
18
  };
14
19
  window.addEventListener('message', onMessage);
15
- return () => {
16
- window.removeEventListener('message', onMessage);
17
- };
20
+ return () => window.removeEventListener('message', onMessage);
18
21
  }
19
22
  export function useInternalPostMessageAPIListener(action, callback) {
20
23
  React.useEffect(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"usePostMessageAPI.js","sourceRoot":"../../../src","sources":["hooks/usePostMessageAPI.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,MAAM,UAAU,oBAAoB,CAChC,MAAS,EACT,IAA0B;IAE1B,MAAM,OAAO,GAAG,EAAC,MAAM,EAAE,IAAI,EAA6B,CAAC;IAC3D,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,wBAAwB,CACpC,MAAS,EACT,QAA+C;IAE/C,MAAM,SAAS,GAAG,CAAC,CAAe,EAAE,EAAE;QAClC,MAAM,OAAO,GAAG,CAAC,CAAC,IAAgC,CAAC;QAEnD,IAAI,QAAQ,IAAI,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YACnD,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC;QAED,OAAO,SAAS,CAAC;IACrB,CAAC,CAAC;IAEF,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAE9C,OAAO,GAAG,EAAE;QACR,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IACrD,CAAC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC7C,MAAS,EACT,QAA+C;IAE/C,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,OAAO,wBAAwB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACtD,CAAC,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import * as React from 'react';\n\nimport {PostMessageAPIMessage} from '../common/types';\nimport {ActionMessageTypes, EventMessageTypes} from '../common/types/actions';\n\nexport function sendEventPostMessage<K extends keyof EventMessageTypes>(\n action: K,\n data: EventMessageTypes[K],\n) {\n const message = {action, data} as PostMessageAPIMessage<K>;\n window.parent.postMessage(message, '*');\n}\n\nexport function listenPostMessageActions<K extends keyof ActionMessageTypes>(\n action: K,\n callback: (data: ActionMessageTypes[K]) => void,\n) {\n const onMessage = (e: MessageEvent) => {\n const message = e.data as PostMessageAPIMessage<K>;\n\n if ('action' in message && message.action === action) {\n return callback(message.data);\n }\n\n return undefined;\n };\n\n window.addEventListener('message', onMessage);\n\n return () => {\n window.removeEventListener('message', onMessage);\n };\n}\n\nexport function useInternalPostMessageAPIListener<K extends keyof ActionMessageTypes>(\n action: K,\n callback: (data: ActionMessageTypes[K]) => void,\n) {\n React.useEffect(() => {\n return listenPostMessageActions(action, callback);\n }, [action, callback]);\n}\n"]}
1
+ {"version":3,"file":"usePostMessageAPI.js","sourceRoot":"../../../src","sources":["hooks/usePostMessageAPI.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAC,mBAAmB,EAAC,+BAA4B;AACxD,OAAO,EAAC,kBAAkB,EAAC,iCAA8B;AAIzD,MAAM,UAAU,oBAAoB,CAChC,MAAS,EACT,IAA0B;IAE1B,MAAM,OAAO,GAAG,EAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,mBAAmB,EAA6B,CAAC;IACxF,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,wBAAwB,CACpC,MAAS,EACT,QAA+C;IAE/C,MAAM,SAAS,GAAG,CAAC,CAAe,EAAE,EAAE;QAClC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9B,OAAO,SAAS,CAAC;QACrB,CAAC;QAED,MAAM,OAAO,GAAG,CAAC,CAAC,IAAgC,CAAC;QACnD,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YAC5B,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC;QAED,OAAO,SAAS,CAAC;IACrB,CAAC,CAAC;IAEF,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAC9C,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC7C,MAAS,EACT,QAA+C;IAE/C,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,OAAO,wBAAwB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACtD,CAAC,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import * as React from 'react';\n\nimport {POST_MESSAGE_SOURCE} from '../common/constants';\nimport {isValidPostMessage} from '../common/postMessage';\nimport {PostMessageAPIMessage} from '../common/types';\nimport {ActionMessageTypes, EventMessageTypes} from '../common/types/actions';\n\nexport function sendEventPostMessage<K extends keyof EventMessageTypes>(\n action: K,\n data: EventMessageTypes[K],\n) {\n const message = {action, data, source: POST_MESSAGE_SOURCE} as PostMessageAPIMessage<K>;\n window.parent.postMessage(message, '*');\n}\n\nexport function listenPostMessageActions<K extends keyof ActionMessageTypes>(\n action: K,\n callback: (data: ActionMessageTypes[K]) => void,\n) {\n const onMessage = (e: MessageEvent) => {\n if (!isValidPostMessage(e.data)) {\n return undefined;\n }\n\n const message = e.data as PostMessageAPIMessage<K>;\n if (message.action === action) {\n return callback(message.data);\n }\n\n return undefined;\n };\n\n window.addEventListener('message', onMessage);\n return () => window.removeEventListener('message', onMessage);\n}\n\nexport function useInternalPostMessageAPIListener<K extends keyof ActionMessageTypes>(\n action: K,\n callback: (data: ActionMessageTypes[K]) => void,\n) {\n React.useEffect(() => {\n return listenPostMessageActions(action, callback);\n }, [action, callback]);\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import '@iframe-resizer/child';
2
+ declare module '@iframe-resizer/child' {
3
+ namespace iframeResizer {
4
+ interface IFramePageOptions {
5
+ license?: string;
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,9 @@
1
+ // `@iframe-resizer/child` reads `window.iFrameResizer` lazily, on the first
2
+ // init message from the parent — not at module-load time. So setting the
3
+ // config before/after the side-effect import is equivalent.
4
+ // eslint-disable-next-line import/no-unassigned-import
5
+ import '@iframe-resizer/child';
6
+ if (typeof window !== 'undefined') {
7
+ window.iFrameResizer = { license: 'GPLv3' };
8
+ }
9
+ //# sourceMappingURL=iframe-resizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iframe-resizer.js","sourceRoot":"../../../src","sources":["utils/iframe-resizer.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,yEAAyE;AACzE,4DAA4D;AAC5D,uDAAuD;AACvD,OAAO,uBAAuB,CAAC;AAa/B,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAChC,MAAM,CAAC,aAAa,GAAG,EAAC,OAAO,EAAE,OAAO,EAAC,CAAC;AAC9C,CAAC","sourcesContent":["// `@iframe-resizer/child` reads `window.iFrameResizer` lazily, on the first\n// init message from the parent — not at module-load time. So setting the\n// config before/after the side-effect import is equivalent.\n// eslint-disable-next-line import/no-unassigned-import\nimport '@iframe-resizer/child';\n\n// Augmenting the library's namespace to add the missing `license` field; the\n// shipped .d.ts has not caught up with the v5 runtime that requires it.\ndeclare module '@iframe-resizer/child' {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace iframeResizer {\n interface IFramePageOptions {\n license?: string;\n }\n }\n}\n\nif (typeof window !== 'undefined') {\n window.iFrameResizer = {license: 'GPLv3'};\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/page-constructor",
3
- "version": "8.5.0-alpha.5",
3
+ "version": "8.5.0-alpha.7",
4
4
  "description": "Gravity UI Page Constructor",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
@@ -157,6 +157,7 @@
157
157
  "deep-object-diff": "^1.1.9",
158
158
  "final-form": "^4.20.9",
159
159
  "github-buttons": "2.23.0",
160
+ "iframe-resizer": "^5.5.9",
160
161
  "immutable": "^4.3.7",
161
162
  "js-yaml-source-map": "^0.2.2",
162
163
  "lodash": "^4.17.21",
@@ -284,8 +285,8 @@
284
285
  "webpack-shell-plugin-next": "^2.3.1"
285
286
  },
286
287
  "optionalDependencies": {
287
- "@rollup/rollup-linux-x64-gnu": "^4.60.1",
288
- "@rollup/rollup-darwin-arm64": "^4.60.1"
288
+ "@rollup/rollup-darwin-arm64": "^4.60.1",
289
+ "@rollup/rollup-linux-x64-gnu": "^4.60.1"
289
290
  },
290
291
  "lint-staged": {
291
292
  "*.{css,scss}": [