@gravity-ui/page-constructor 3.10.3 → 3.12.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 (139) hide show
  1. package/README.md +9 -11
  2. package/build/cjs/components/Media/Image/Image.js +3 -2
  3. package/build/cjs/editor/components/ControlPanel/ControlPanel.js +4 -1
  4. package/build/cjs/editor/components/DeviceEmulation/DeviceEmulation.d.ts +7 -0
  5. package/build/cjs/editor/components/DeviceEmulation/DeviceEmulation.js +10 -0
  6. package/build/cjs/editor/components/DeviceEmulation/DeviceEmulationMobile/DeviceEmulationMobile.css +33 -0
  7. package/build/cjs/editor/components/DeviceEmulation/DeviceEmulationMobile/DeviceEmulationMobile.d.ts +8 -0
  8. package/build/cjs/editor/components/DeviceEmulation/DeviceEmulationMobile/DeviceEmulationMobile.js +41 -0
  9. package/build/cjs/editor/components/DeviceEmulation/utils.d.ts +4 -0
  10. package/build/cjs/editor/components/DeviceEmulation/utils.js +7 -0
  11. package/build/cjs/editor/components/Layout/Layout.js +3 -1
  12. package/build/cjs/editor/containers/Editor/Editor.d.ts +1 -1
  13. package/build/cjs/editor/containers/Editor/Editor.js +34 -9
  14. package/build/cjs/editor/containers/Form/Form.js +2 -2
  15. package/build/cjs/editor/context.d.ts +9 -0
  16. package/build/cjs/editor/context.js +6 -0
  17. package/build/cjs/editor/icons/Tablet.d.ts +2 -0
  18. package/build/cjs/editor/icons/Tablet.js +9 -0
  19. package/build/cjs/editor/types/index.d.ts +14 -5
  20. package/build/cjs/editor/types/index.js +3 -1
  21. package/build/cjs/editor/utils/index.d.ts +2 -0
  22. package/build/cjs/editor/utils/index.js +4 -1
  23. package/build/cjs/editor/widget/constants.d.ts +4 -0
  24. package/build/cjs/editor/widget/constants.js +8 -0
  25. package/build/cjs/editor/widget/index.d.ts +21 -0
  26. package/build/cjs/editor/widget/index.js +76 -0
  27. package/build/cjs/editor/widget/utils.d.ts +1 -0
  28. package/build/cjs/editor/widget/utils.js +19 -0
  29. package/build/cjs/hooks/useHeightCalculator.js +1 -1
  30. package/build/cjs/models/navigation.d.ts +3 -2
  31. package/build/{esm/navigation/components/Header/Header.css → cjs/navigation/components/DesktopNavigation/DesktopNavigation.css} +28 -36
  32. package/build/cjs/navigation/components/DesktopNavigation/DesktopNavigation.d.ts +4 -0
  33. package/build/cjs/navigation/components/DesktopNavigation/DesktopNavigation.js +21 -0
  34. package/build/cjs/navigation/components/MobileMenuButton/MobileMenuButton.css +7 -0
  35. package/build/cjs/navigation/components/MobileMenuButton/MobileMenuButton.d.ts +3 -0
  36. package/build/cjs/navigation/components/MobileMenuButton/MobileMenuButton.js +15 -0
  37. package/build/cjs/navigation/components/MobileNavigation/MobileNavigation.css +10 -5
  38. package/build/cjs/navigation/components/MobileNavigation/MobileNavigation.d.ts +1 -10
  39. package/build/cjs/navigation/components/MobileNavigation/MobileNavigation.js +7 -30
  40. package/build/cjs/navigation/components/Navigation/Navigation.css +8 -13
  41. package/build/cjs/navigation/components/Navigation/Navigation.d.ts +4 -7
  42. package/build/cjs/navigation/components/Navigation/Navigation.js +37 -15
  43. package/build/cjs/navigation/components/NavigationItem/NavigationItem.css +28 -0
  44. package/build/cjs/navigation/components/NavigationItem/NavigationItem.d.ts +3 -9
  45. package/build/cjs/navigation/components/NavigationItem/NavigationItem.js +15 -6
  46. package/build/cjs/navigation/components/NavigationItem/components/GithubButton/GithubButton.d.ts +1 -1
  47. package/build/cjs/navigation/components/NavigationItem/components/NavigationButton/NavigationButton.d.ts +1 -1
  48. package/build/cjs/navigation/components/NavigationItem/components/NavigationDropdown/NavigationDropdown.d.ts +5 -4
  49. package/build/cjs/navigation/components/NavigationItem/components/NavigationDropdown/NavigationDropdown.js +12 -7
  50. package/build/cjs/navigation/components/NavigationItem/components/NavigationLink/NavigationLink.d.ts +1 -1
  51. package/build/cjs/navigation/components/NavigationList/NavigationList.d.ts +3 -0
  52. package/build/cjs/navigation/components/NavigationList/NavigationList.js +11 -0
  53. package/build/cjs/navigation/components/NavigationListItem/NavigationListItem.d.ts +4 -13
  54. package/build/cjs/navigation/components/NavigationListItem/NavigationListItem.js +6 -13
  55. package/build/cjs/navigation/components/NavigationPopup/NavigationPopup.css +5 -4
  56. package/build/cjs/navigation/components/NavigationPopup/NavigationPopup.d.ts +1 -8
  57. package/build/cjs/navigation/components/NavigationPopup/NavigationPopup.js +6 -6
  58. package/build/cjs/navigation/containers/Layout/Layout.js +2 -2
  59. package/build/cjs/navigation/models.d.ts +63 -0
  60. package/build/cjs/navigation/{constants.js → models.js} +7 -1
  61. package/build/cjs/navigation/utils.d.ts +11 -1
  62. package/build/cjs/navigation/utils.js +19 -1
  63. package/build/esm/components/Media/Image/Image.js +3 -2
  64. package/build/esm/editor/components/ControlPanel/ControlPanel.js +6 -3
  65. package/build/esm/editor/components/DeviceEmulation/DeviceEmulation.d.ts +7 -0
  66. package/build/esm/editor/components/DeviceEmulation/DeviceEmulation.js +7 -0
  67. package/build/esm/editor/components/DeviceEmulation/DeviceEmulationMobile/DeviceEmulationMobile.css +33 -0
  68. package/build/esm/editor/components/DeviceEmulation/DeviceEmulationMobile/DeviceEmulationMobile.d.ts +9 -0
  69. package/build/esm/editor/components/DeviceEmulation/DeviceEmulationMobile/DeviceEmulationMobile.js +40 -0
  70. package/build/esm/editor/components/DeviceEmulation/utils.d.ts +4 -0
  71. package/build/esm/editor/components/DeviceEmulation/utils.js +3 -0
  72. package/build/esm/editor/components/Layout/Layout.js +3 -1
  73. package/build/esm/editor/containers/Editor/Editor.d.ts +1 -1
  74. package/build/esm/editor/containers/Editor/Editor.js +35 -10
  75. package/build/esm/editor/containers/Form/Form.js +2 -2
  76. package/build/esm/editor/context.d.ts +9 -0
  77. package/build/esm/editor/context.js +2 -0
  78. package/build/esm/editor/icons/Tablet.d.ts +2 -0
  79. package/build/esm/editor/icons/Tablet.js +4 -0
  80. package/build/esm/editor/types/index.d.ts +14 -5
  81. package/build/esm/editor/types/index.js +3 -1
  82. package/build/esm/editor/utils/index.d.ts +2 -0
  83. package/build/esm/editor/utils/index.js +2 -0
  84. package/build/esm/editor/widget/constants.d.ts +4 -0
  85. package/build/esm/editor/widget/constants.js +5 -0
  86. package/build/esm/editor/widget/index.d.ts +21 -0
  87. package/build/esm/editor/widget/index.js +71 -0
  88. package/build/esm/editor/widget/utils.d.ts +1 -0
  89. package/build/esm/editor/widget/utils.js +15 -0
  90. package/build/esm/hooks/useHeightCalculator.js +1 -1
  91. package/build/esm/models/navigation.d.ts +3 -2
  92. package/build/{cjs/navigation/components/Header/Header.css → esm/navigation/components/DesktopNavigation/DesktopNavigation.css} +28 -36
  93. package/build/esm/navigation/components/DesktopNavigation/DesktopNavigation.d.ts +5 -0
  94. package/build/esm/navigation/components/DesktopNavigation/DesktopNavigation.js +19 -0
  95. package/build/esm/navigation/components/MobileMenuButton/MobileMenuButton.css +7 -0
  96. package/build/esm/navigation/components/MobileMenuButton/MobileMenuButton.d.ts +4 -0
  97. package/build/esm/navigation/components/MobileMenuButton/MobileMenuButton.js +11 -0
  98. package/build/esm/navigation/components/MobileNavigation/MobileNavigation.css +10 -5
  99. package/build/esm/navigation/components/MobileNavigation/MobileNavigation.d.ts +1 -10
  100. package/build/esm/navigation/components/MobileNavigation/MobileNavigation.js +9 -31
  101. package/build/esm/navigation/components/Navigation/Navigation.css +8 -13
  102. package/build/esm/navigation/components/Navigation/Navigation.d.ts +4 -7
  103. package/build/esm/navigation/components/Navigation/Navigation.js +35 -15
  104. package/build/esm/navigation/components/NavigationItem/NavigationItem.css +28 -0
  105. package/build/esm/navigation/components/NavigationItem/NavigationItem.d.ts +4 -9
  106. package/build/esm/navigation/components/NavigationItem/NavigationItem.js +16 -6
  107. package/build/esm/navigation/components/NavigationItem/components/GithubButton/GithubButton.d.ts +1 -1
  108. package/build/esm/navigation/components/NavigationItem/components/NavigationButton/NavigationButton.d.ts +1 -1
  109. package/build/esm/navigation/components/NavigationItem/components/NavigationDropdown/NavigationDropdown.d.ts +5 -4
  110. package/build/esm/navigation/components/NavigationItem/components/NavigationDropdown/NavigationDropdown.js +12 -7
  111. package/build/esm/navigation/components/NavigationItem/components/NavigationLink/NavigationLink.d.ts +1 -1
  112. package/build/esm/navigation/components/NavigationList/NavigationList.d.ts +3 -0
  113. package/build/esm/navigation/components/NavigationList/NavigationList.js +7 -0
  114. package/build/esm/navigation/components/NavigationListItem/NavigationListItem.d.ts +4 -14
  115. package/build/esm/navigation/components/NavigationListItem/NavigationListItem.js +5 -10
  116. package/build/esm/navigation/components/NavigationPopup/NavigationPopup.css +5 -4
  117. package/build/esm/navigation/components/NavigationPopup/NavigationPopup.d.ts +1 -8
  118. package/build/esm/navigation/components/NavigationPopup/NavigationPopup.js +6 -6
  119. package/build/esm/navigation/containers/Layout/Layout.js +2 -2
  120. package/build/esm/navigation/models.d.ts +63 -0
  121. package/build/esm/navigation/{constants.js → models.js} +6 -0
  122. package/build/esm/navigation/utils.d.ts +11 -1
  123. package/build/esm/navigation/utils.js +17 -0
  124. package/package.json +39 -16
  125. package/server/models/navigation.d.ts +3 -2
  126. package/widget/index.js +1 -0
  127. package/CHANGELOG.md +0 -1469
  128. package/build/cjs/navigation/components/Header/Header.d.ts +0 -8
  129. package/build/cjs/navigation/components/Header/Header.js +0 -86
  130. package/build/cjs/navigation/components/NavigationDropdownItem/NavigationDropdownItem.d.ts +0 -11
  131. package/build/cjs/navigation/components/NavigationDropdownItem/NavigationDropdownItem.js +0 -15
  132. package/build/cjs/navigation/components/NavigationListItem/NavigationListItem.css +0 -27
  133. package/build/cjs/navigation/constants.d.ts +0 -6
  134. package/build/esm/navigation/components/Header/Header.d.ts +0 -9
  135. package/build/esm/navigation/components/Header/Header.js +0 -82
  136. package/build/esm/navigation/components/NavigationDropdownItem/NavigationDropdownItem.d.ts +0 -11
  137. package/build/esm/navigation/components/NavigationDropdownItem/NavigationDropdownItem.js +0 -13
  138. package/build/esm/navigation/components/NavigationListItem/NavigationListItem.css +0 -27
  139. package/build/esm/navigation/constants.d.ts +0 -6
package/README.md CHANGED
@@ -1,11 +1,5 @@
1
1
  # @gravity-ui/page-constructor · [![npm package](https://img.shields.io/npm/v/@gravity-ui/page-constructor)](https://www.npmjs.com/package/@gravity-ui/page-constructor) [![CI](https://img.shields.io/github/actions/workflow/status/gravity-ui/page-constructor/ci.yml?branch=main&label=CI)](https://github.com/gravity-ui/page-constructor/actions/workflows/ci.yml?query=branch:main) [![Release](https://img.shields.io/github/actions/workflow/status/gravity-ui/page-constructor/release.yml?branch=main&label=Release)](https://github.com/gravity-ui/page-constructor/actions/workflows/release.yml?query=branch:main) [![storybook](https://img.shields.io/badge/Storybook-deployed-ff4685)](https://preview.yandexcloud.dev/page-constructor/)
2
2
 
3
- ## Install
4
-
5
- ```shell
6
- npm install @gravity-ui/page-constructor
7
- ```
8
-
9
3
  ## Page constructor
10
4
 
11
5
  `Page-constructor` is a library for rendering web pages or their parts based on `JSON` data (support for `YAML` format is to be added later).
@@ -14,6 +8,12 @@ When creating pages, component-based approach is used: a page is built using a s
14
8
 
15
9
  For the format of input data and list of available blocks, see the [documentation](https://preview.yandexcloud.dev/page-constructor/?path=/story/information--blocks).
16
10
 
11
+ ## Install
12
+
13
+ ```shell
14
+ npm install @gravity-ui/page-constructor
15
+ ```
16
+
17
17
  ### Getting started
18
18
 
19
19
  The page constructor is imported as a React component. To make sure it runs properly, wrap it in `PageConstructorProvider`:
@@ -374,17 +374,15 @@ Editor provides user interface for page content management with realtime preview
374
374
  How to use:
375
375
 
376
376
  ```tsx
377
- import {PageConstructor} from '@gravity-ui/page-constructor';
378
377
  import {Editor} from '@gravity-ui/page-constructor/editor';
379
378
 
380
379
  interface MyAppEditorProps {
381
380
  initialContent: PageContent;
381
+ transformContent: ContentTransformer;
382
382
  onChange: (content: PageContent) => void;
383
383
  }
384
384
 
385
- export const MyAppEditor = ({initialContent, onChange}: MyAppEditorProps) => (
386
- <Editor onChange={onChange} content={initialContent}>
387
- {(props) => <PageConstructor {...props} />}
388
- </Editor>
385
+ export const MyAppEditor = ({initialContent, onChange, transformContent}: MyAppEditorProps) => (
386
+ <Editor content={initialContent} onChange={onChange} transformContent={transformContent} />
389
387
  );
390
388
  ```
@@ -23,8 +23,9 @@ const Image = (props) => {
23
23
  (0, react_1.useEffect)(() => {
24
24
  if (parallax) {
25
25
  const handleScroll = () => setScrollY(window.scrollY);
26
- window.addEventListener('scroll', lodash_1.default.debounce(handleScroll, 5), { passive: true });
27
- return () => window.removeEventListener('scroll', lodash_1.default.debounce(handleScroll, 5));
26
+ const debouncedHandler = lodash_1.default.debounce(handleScroll, 5);
27
+ window.addEventListener('scroll', debouncedHandler, { passive: true });
28
+ return () => window.removeEventListener('scroll', debouncedHandler);
28
29
  }
29
30
  return () => { };
30
31
  });
@@ -5,13 +5,16 @@ const react_1 = tslib_1.__importDefault(require("react"));
5
5
  const icons_1 = require("@gravity-ui/icons");
6
6
  const uikit_1 = require("@gravity-ui/uikit");
7
7
  const utils_1 = require("../../../utils");
8
+ const Tablet_1 = require("../../icons/Tablet");
8
9
  const types_1 = require("../../types");
9
10
  const i18n_1 = tslib_1.__importDefault(require("./i18n"));
10
11
  const ICON_SIZE = 14;
11
12
  const b = (0, utils_1.block)('control-panel');
12
13
  const ControlPanelViewModeIcons = {
13
14
  [types_1.ViewModeItem.Edititng]: icons_1.Pencil,
14
- [types_1.ViewModeItem.View]: icons_1.Display,
15
+ [types_1.ViewModeItem.Desktop]: icons_1.Display,
16
+ [types_1.ViewModeItem.Tablet]: Tablet_1.Tablet,
17
+ [types_1.ViewModeItem.Mobile]: icons_1.Smartphone,
15
18
  };
16
19
  const ControlPanel = ({ viewMode = types_1.ViewModeItem.Edititng, onViewModeChange, className, }) => (react_1.default.createElement("div", { className: b(null, className) },
17
20
  react_1.default.createElement("div", { className: b('mode-switch') },
@@ -0,0 +1,7 @@
1
+ import { PropsWithChildren } from 'react';
2
+ import { ViewModeItem } from '../../types';
3
+ export interface DeviceEmulationProps extends PropsWithChildren {
4
+ mode: ViewModeItem;
5
+ }
6
+ declare const DeviceEmulation: ({ children, mode }: DeviceEmulationProps) => JSX.Element;
7
+ export default DeviceEmulation;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const react_1 = tslib_1.__importStar(require("react"));
5
+ const DeviceEmulationMobile_1 = tslib_1.__importDefault(require("./DeviceEmulationMobile/DeviceEmulationMobile"));
6
+ const utils_1 = require("./utils");
7
+ const DeviceEmulation = ({ children, mode }) => (react_1.default.createElement(react_1.Fragment, null,
8
+ !(0, utils_1.isMobileDevice)(mode) && children,
9
+ utils_1.mobileDevices.map((device) => (react_1.default.createElement(DeviceEmulationMobile_1.default, { key: device, device: device, active: mode === device }, children)))));
10
+ exports.default = DeviceEmulation;
@@ -0,0 +1,33 @@
1
+ .pc-device-emulation-mobile {
2
+ position: absolute;
3
+ top: 0;
4
+ left: 0;
5
+ width: 100%;
6
+ display: flex;
7
+ justify-content: center;
8
+ opacity: 0;
9
+ pointer-events: none;
10
+ }
11
+ .pc-device-emulation-mobile_active {
12
+ opacity: 1;
13
+ pointer-events: all;
14
+ }
15
+ .pc-device-emulation-mobile__frame {
16
+ border: none;
17
+ }
18
+ .pc-device-emulation-mobile__frame_device_mobile {
19
+ width: 390px;
20
+ height: 844px;
21
+ }
22
+ .pc-device-emulation-mobile__frame_device_tablet {
23
+ width: 768px;
24
+ height: 1024px;
25
+ }
26
+
27
+ .pc-device-emulation-mobile__frame {
28
+ margin: 0;
29
+ }
30
+
31
+ .pc-device-emulation-mobile__container {
32
+ overflow: auto;
33
+ }
@@ -0,0 +1,8 @@
1
+ import { PropsWithChildren } from 'react';
2
+ import { MobileDevice } from '../utils';
3
+ interface DeviceEmulationMobileProps extends PropsWithChildren {
4
+ device: MobileDevice;
5
+ active: boolean;
6
+ }
7
+ declare const DeviceEmulationMobile: ({ device, active }: DeviceEmulationMobileProps) => JSX.Element;
8
+ export default DeviceEmulationMobile;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const react_1 = tslib_1.__importStar(require("react"));
5
+ const utils_1 = require("../../../../utils");
6
+ const context_1 = require("../../../context");
7
+ const widget_1 = require("../../../widget");
8
+ const b = (0, utils_1.block)('device-emulation-mobile');
9
+ const DeviceEmulationMobile = ({ device, active }) => {
10
+ const _a = (0, react_1.useContext)(context_1.EditorContext), { deviceEmulationSettings } = _a, initialData = tslib_1.__rest(_a, ["deviceEmulationSettings"]);
11
+ const containerRef = (0, react_1.useRef)(null);
12
+ const deviceIframeRef = (0, react_1.useRef)(null);
13
+ (0, react_1.useEffect)(() => {
14
+ let iframe;
15
+ if (containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) {
16
+ iframe = new widget_1.DeviceIframe(containerRef === null || containerRef === void 0 ? void 0 : containerRef.current, {
17
+ initialData,
18
+ className: b('frame', { device }),
19
+ settings: deviceEmulationSettings,
20
+ });
21
+ deviceIframeRef.current = iframe;
22
+ }
23
+ return () => {
24
+ iframe === null || iframe === void 0 ? void 0 : iframe.destroy();
25
+ };
26
+ // render iframe only once, then update it's data with postMessage
27
+ // eslint-disable-next-line react-hooks/exhaustive-deps
28
+ }, [device]);
29
+ (0, react_1.useEffect)(() => {
30
+ if (deviceIframeRef.current) {
31
+ deviceIframeRef.current.onActivenessUpdate(active);
32
+ }
33
+ }, [active]);
34
+ (0, react_1.useEffect)(() => {
35
+ if (deviceIframeRef.current && initialData) {
36
+ deviceIframeRef.current.onDataUpdate(initialData);
37
+ }
38
+ }, [initialData]);
39
+ return react_1.default.createElement("div", { className: b({ active, device }), ref: containerRef });
40
+ };
41
+ exports.default = DeviceEmulationMobile;
@@ -0,0 +1,4 @@
1
+ import { ViewModeItem } from '../../types';
2
+ export type MobileDevice = ViewModeItem.Mobile | ViewModeItem.Tablet;
3
+ export declare const mobileDevices: readonly [ViewModeItem.Tablet, ViewModeItem.Mobile];
4
+ export declare const isMobileDevice: (mode: ViewModeItem) => mode is MobileDevice;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isMobileDevice = exports.mobileDevices = void 0;
4
+ const types_1 = require("../../types");
5
+ exports.mobileDevices = [types_1.ViewModeItem.Tablet, types_1.ViewModeItem.Mobile];
6
+ const isMobileDevice = (mode) => [types_1.ViewModeItem.Tablet, types_1.ViewModeItem.Mobile].includes(mode);
7
+ exports.isMobileDevice = isMobileDevice;
@@ -5,6 +5,7 @@ const react_1 = tslib_1.__importStar(require("react"));
5
5
  const utils_1 = require("../../../utils");
6
6
  const types_1 = require("../../types");
7
7
  const ControlPanel_1 = tslib_1.__importDefault(require("../ControlPanel/ControlPanel"));
8
+ const DeviceEmulation_1 = tslib_1.__importDefault(require("../DeviceEmulation/DeviceEmulation"));
8
9
  const b = (0, utils_1.block)('editor-layout');
9
10
  const Left = () => null;
10
11
  const Right = () => null;
@@ -29,7 +30,8 @@ const Layout = ({ children, mode, onModeChange }) => {
29
30
  react_1.default.createElement("div", { className: b('container') },
30
31
  react_1.default.createElement(react_1.Fragment, null,
31
32
  left && react_1.default.createElement("div", { className: b('left') }, left),
32
- right && react_1.default.createElement("div", { className: b('right', { editing: isEditingMode }) }, right)))));
33
+ right && (react_1.default.createElement("div", { className: b('right', { editing: isEditingMode }) },
34
+ react_1.default.createElement(DeviceEmulation_1.default, { mode: mode }, right)))))));
33
35
  };
34
36
  Layout.Left = Left;
35
37
  Layout.Right = Right;
@@ -1,2 +1,2 @@
1
1
  import { EditorProps } from '../../types';
2
- export declare const Editor: ({ children, customSchema, onChange, ...rest }: EditorProps) => JSX.Element;
2
+ export declare const Editor: ({ customSchema, onChange, providerProps, transformContent, deviceEmulationSettings, ...rest }: EditorProps) => JSX.Element;
@@ -3,21 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Editor = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importStar(require("react"));
6
+ const PageConstructor_1 = require("../../../containers/PageConstructor");
6
7
  const AddBlock_1 = tslib_1.__importDefault(require("../../components/AddBlock/AddBlock"));
7
8
  const EditBlock_1 = tslib_1.__importDefault(require("../../components/EditBlock/EditBlock"));
8
9
  const ErrorBoundary_1 = require("../../components/ErrorBoundary/ErrorBoundary");
9
10
  const Layout_1 = tslib_1.__importDefault(require("../../components/Layout/Layout"));
10
11
  const NotFoundBlock_1 = require("../../components/NotFoundBlock/NotFoundBlock");
12
+ const context_1 = require("../../context");
11
13
  const useFormSpec_1 = tslib_1.__importDefault(require("../../hooks/useFormSpec"));
12
14
  const store_1 = require("../../store");
13
15
  const types_1 = require("../../types");
14
16
  const utils_1 = require("../../utils");
15
17
  const Form_1 = require("../Form/Form");
16
18
  const Editor = (_a) => {
17
- var { children, customSchema, onChange } = _a, rest = tslib_1.__rest(_a, ["children", "customSchema", "onChange"]);
19
+ var { customSchema, onChange, providerProps, transformContent, deviceEmulationSettings } = _a, rest = tslib_1.__rest(_a, ["customSchema", "onChange", "providerProps", "transformContent", "deviceEmulationSettings"]);
18
20
  const { content, activeBlockIndex, errorBoundaryState, viewMode, onContentUpdate, onViewModeUpdate, onAdd, onSelect, injectEditBlockProps, } = (0, store_1.useEditorState)(rest);
19
21
  const formSpecs = (0, useFormSpec_1.default)(customSchema);
20
22
  const isEditingMode = viewMode === types_1.ViewModeItem.Edititng;
23
+ const transformedContent = (0, react_1.useMemo)(() => (transformContent ? transformContent(content, { viewMode }) : content), [content, transformContent, viewMode]);
21
24
  const outgoingProps = (0, react_1.useMemo)(() => {
22
25
  const custom = isEditingMode
23
26
  ? (0, utils_1.addCustomDecorator)([
@@ -27,16 +30,38 @@ const Editor = (_a) => {
27
30
  (props) => (react_1.default.createElement(ErrorBoundary_1.ErrorBoundary, Object.assign({}, props, { key: `${(0, utils_1.getBlockId)(props)}-${errorBoundaryState}` }))),
28
31
  ], rest.custom)
29
32
  : rest.custom;
30
- return { content, custom, viewMode };
31
- }, [injectEditBlockProps, content, errorBoundaryState, isEditingMode, viewMode, rest.custom]);
33
+ return {
34
+ content: transformedContent,
35
+ custom,
36
+ viewMode,
37
+ };
38
+ }, [
39
+ injectEditBlockProps,
40
+ errorBoundaryState,
41
+ isEditingMode,
42
+ viewMode,
43
+ transformedContent,
44
+ rest.custom,
45
+ ]);
46
+ const context = (0, react_1.useMemo)(() => ({
47
+ constructorProps: {
48
+ content: transformedContent,
49
+ custom: rest.custom,
50
+ },
51
+ providerProps: Object.assign(Object.assign({}, providerProps), { isMobile: (0, utils_1.checkIsMobile)(viewMode) }),
52
+ deviceEmulationSettings,
53
+ }), [providerProps, rest.custom, viewMode, transformedContent, deviceEmulationSettings]);
32
54
  (0, react_1.useEffect)(() => {
33
55
  onChange === null || onChange === void 0 ? void 0 : onChange(content);
34
56
  }, [content, onChange]);
35
- return (react_1.default.createElement(Layout_1.default, { mode: viewMode, onModeChange: onViewModeUpdate },
36
- isEditingMode && (react_1.default.createElement(Layout_1.default.Left, null,
37
- react_1.default.createElement(Form_1.Form, { content: content, onChange: onContentUpdate, activeBlockIndex: activeBlockIndex, onSelect: onSelect, spec: formSpecs }))),
38
- react_1.default.createElement(Layout_1.default.Right, null,
39
- react_1.default.createElement(ErrorBoundary_1.ErrorBoundary, { key: errorBoundaryState }, children(outgoingProps)),
40
- isEditingMode && react_1.default.createElement(AddBlock_1.default, { onAdd: onAdd }))));
57
+ return (react_1.default.createElement(context_1.EditorContext.Provider, { value: context },
58
+ react_1.default.createElement(Layout_1.default, { mode: viewMode, onModeChange: onViewModeUpdate },
59
+ isEditingMode && (react_1.default.createElement(Layout_1.default.Left, null,
60
+ react_1.default.createElement(Form_1.Form, { content: content, onChange: onContentUpdate, activeBlockIndex: activeBlockIndex, onSelect: onSelect, spec: formSpecs }))),
61
+ react_1.default.createElement(Layout_1.default.Right, null,
62
+ react_1.default.createElement(ErrorBoundary_1.ErrorBoundary, { key: errorBoundaryState },
63
+ react_1.default.createElement(PageConstructor_1.PageConstructorProvider, Object.assign({}, providerProps),
64
+ react_1.default.createElement(PageConstructor_1.PageConstructor, Object.assign({}, outgoingProps)))),
65
+ isEditingMode && react_1.default.createElement(AddBlock_1.default, { onAdd: onAdd })))));
41
66
  };
42
67
  exports.Editor = Editor;
@@ -30,8 +30,8 @@ exports.Form = (0, react_1.memo)(({ content, onChange, activeBlockIndex, onSelec
30
30
  break;
31
31
  }
32
32
  case FormTab.Blocks: {
33
- form = (react_1.default.createElement(react_1.Fragment, null, blocks.map((blockData, index) => blocksSpec[blockData.type] ? (react_1.default.createElement("div", { className: b('block-form') },
34
- react_1.default.createElement(BlockForm_1.BlockForm, { spec: blocksSpec[blockData.type], key: (0, utils_1.getBlockKey)(blockData, index), data: blockData, active: activeBlockIndex === index, onChange: (data) => {
33
+ form = (react_1.default.createElement(react_1.Fragment, null, blocks.map((blockData, index) => blocksSpec[blockData.type] ? (react_1.default.createElement("div", { className: b('block-form'), key: (0, utils_1.getBlockKey)(blockData, index) },
34
+ react_1.default.createElement(BlockForm_1.BlockForm, { spec: blocksSpec[blockData.type], data: blockData, active: activeBlockIndex === index, onChange: (data) => {
35
35
  onChange(Object.assign(Object.assign({}, content), { blocks: [
36
36
  ...blocks.slice(0, index),
37
37
  data,
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import { PageConstructorProps, PageConstructorProviderProps } from '../containers/PageConstructor';
3
+ import { EditorProps } from './types';
4
+ export interface EditorContextType {
5
+ constructorProps?: PageConstructorProps;
6
+ providerProps?: PageConstructorProviderProps;
7
+ deviceEmulationSettings?: EditorProps['deviceEmulationSettings'];
8
+ }
9
+ export declare const EditorContext: React.Context<Partial<EditorContextType>>;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EditorContext = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ exports.EditorContext = react_1.default.createContext({});
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const Tablet: React.FC<React.SVGProps<SVGSVGElement>>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Tablet = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const svg_1 = require("../../utils/svg");
7
+ const Tablet = (props) => (react_1.default.createElement("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", width: "12", height: "14", viewBox: "0 0 12 14", fill: "none" }, svg_1.a11yHiddenSvgProps, props),
8
+ react_1.default.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M10.5 3L10.5 11C10.5 11.8284 9.82843 12.5 9 12.5L3 12.5C2.17157 12.5 1.5 11.8284 1.5 11L1.5 3C1.5 2.17157 2.17157 1.5 3 1.5L9 1.5C9.82843 1.5 10.5 2.17157 10.5 3ZM9 -1.31134e-07C10.6569 -5.87108e-08 12 1.34315 12 3L12 11C12 12.6569 10.6569 14 9 14L3 14C1.34315 14 4.00426e-07 12.6569 4.72849e-07 11L8.2254e-07 3C8.94964e-07 1.34315 1.34315 -4.65826e-07 3 -3.93403e-07L9 -1.31134e-07ZM3.75 9.5C3.33579 9.5 3 9.83579 3 10.25C3 10.6642 3.33579 11 3.75 11L8.25 11C8.66421 11 9 10.6642 9 10.25C9 9.83579 8.66421 9.5 8.25 9.5L3.75 9.5Z", fill: "currentColor", fillOpacity: "0.85" })));
9
+ exports.Tablet = Tablet;
@@ -1,16 +1,22 @@
1
- /// <reference types="react" />
2
- import { PageConstructorProps } from '../../containers/PageConstructor';
1
+ import { PageConstructorProps, PageConstructorProviderProps } from '../../containers/PageConstructor';
3
2
  import { BlockDecorationProps, PageContent } from '../../models';
4
3
  import { SchemaCustomConfig } from '../../schema';
5
4
  import { EditBlockActions } from '../components/EditBlock/EditBlock';
6
5
  export type EditorBlockId = number | string;
7
- export interface EditorOutgoingProps extends Partial<PageConstructorProps> {
6
+ interface ContentTransformersOptions {
8
7
  viewMode: ViewModeItem;
9
8
  }
9
+ export type ContentTransformer = (content: PageContent, options: ContentTransformersOptions) => PageContent;
10
+ export interface DeviceEmulationSettings {
11
+ customStyles?: string;
12
+ applyHostStyles?: boolean;
13
+ }
10
14
  export interface EditorProps extends Required<Pick<PageConstructorProps, 'content'>>, Partial<Omit<PageConstructorProps, 'content'>> {
11
- children: (props: EditorOutgoingProps) => React.ReactNode;
15
+ providerProps?: PageConstructorProviderProps;
12
16
  onChange?: (data: PageContent) => void;
17
+ transformContent?: ContentTransformer;
13
18
  customSchema?: SchemaCustomConfig;
19
+ deviceEmulationSettings?: DeviceEmulationSettings;
14
20
  }
15
21
  export interface EditBlockEditorProps {
16
22
  isActive?: boolean;
@@ -22,5 +28,8 @@ export interface EditBlockProps extends EditBlockEditorProps, BlockDecorationPro
22
28
  }
23
29
  export declare enum ViewModeItem {
24
30
  Edititng = "editing",
25
- View = "view"
31
+ Desktop = "desktop",
32
+ Tablet = "tablet",
33
+ Mobile = "mobile"
26
34
  }
35
+ export {};
@@ -4,5 +4,7 @@ exports.ViewModeItem = void 0;
4
4
  var ViewModeItem;
5
5
  (function (ViewModeItem) {
6
6
  ViewModeItem["Edititng"] = "editing";
7
- ViewModeItem["View"] = "view";
7
+ ViewModeItem["Desktop"] = "desktop";
8
+ ViewModeItem["Tablet"] = "tablet";
9
+ ViewModeItem["Mobile"] = "mobile";
8
10
  })(ViewModeItem = exports.ViewModeItem || (exports.ViewModeItem = {}));
@@ -1,4 +1,5 @@
1
1
  import { BlockDecorationProps, BlockDecorator, CustomConfig } from '../../models';
2
+ import { ViewModeItem } from '../types';
2
3
  export declare const formatBlockName: (name: string) => string;
3
4
  export declare const addCustomDecorator: (decorators: BlockDecorator[], custom?: CustomConfig) => {
4
5
  decorators: {
@@ -10,3 +11,4 @@ export declare const addCustomDecorator: (decorators: BlockDecorator[], custom?:
10
11
  loadable?: import("../../models").LoadableConfig | undefined;
11
12
  };
12
13
  export declare const getBlockId: ({ index, type }: BlockDecorationProps) => string;
14
+ export declare const checkIsMobile: (viewMode: ViewModeItem) => boolean;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getBlockId = exports.addCustomDecorator = exports.formatBlockName = void 0;
3
+ exports.checkIsMobile = exports.getBlockId = exports.addCustomDecorator = exports.formatBlockName = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
6
+ const types_1 = require("../types");
6
7
  const formatBlockName = (name) => lodash_1.default.capitalize(name).replace(/(block|-)/g, ' ');
7
8
  exports.formatBlockName = formatBlockName;
8
9
  const addCustomDecorator = (decorators, custom = {}) => {
@@ -12,3 +13,5 @@ const addCustomDecorator = (decorators, custom = {}) => {
12
13
  exports.addCustomDecorator = addCustomDecorator;
13
14
  const getBlockId = ({ index, type }) => `${type}${index === undefined ? '' : `-${index}`}`;
14
15
  exports.getBlockId = getBlockId;
16
+ const checkIsMobile = (viewMode) => [types_1.ViewModeItem.Mobile, types_1.ViewModeItem.Tablet].includes(viewMode);
17
+ exports.checkIsMobile = checkIsMobile;
@@ -0,0 +1,4 @@
1
+ export declare const DeviceFrameMessageType: {
2
+ Ready: string;
3
+ Update: string;
4
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeviceFrameMessageType = void 0;
4
+ const prefix = 'PC_EDITOR_DEVICE';
5
+ exports.DeviceFrameMessageType = {
6
+ Ready: `${prefix}_MESSAGE_READY`,
7
+ Update: `${prefix}_MESSAGE_UPDATE`,
8
+ };
@@ -0,0 +1,21 @@
1
+ import { EditorContextType } from '../context';
2
+ import { DeviceEmulationSettings } from '../types';
3
+ interface DeviceIframeParams {
4
+ initialData?: EditorContextType;
5
+ className?: string;
6
+ settings?: DeviceEmulationSettings;
7
+ }
8
+ type InitialData = EditorContextType;
9
+ export declare class DeviceIframe {
10
+ iframeElement?: HTMLIFrameElement;
11
+ private initialData?;
12
+ private settings?;
13
+ constructor(parentElement: HTMLDivElement, { className, initialData, settings }: DeviceIframeParams);
14
+ onDataUpdate(data: InitialData): void;
15
+ onActivenessUpdate(active: boolean): void;
16
+ destroy(): void;
17
+ private addWidgetScript;
18
+ private addCustomStyles;
19
+ private onInit;
20
+ }
21
+ export {};
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeviceIframe = void 0;
4
+ const tslib_1 = require("tslib");
5
+ //widget bundle available after build only
6
+ //@ts-ignore
7
+ const widget_1 = tslib_1.__importDefault(require("../../../../widget"));
8
+ const constants_1 = require("./constants");
9
+ const utils_1 = require("./utils");
10
+ class DeviceIframe {
11
+ constructor(parentElement, { className = '', initialData, settings }) {
12
+ const iframe = document.createElement('iframe');
13
+ parentElement.appendChild(iframe);
14
+ if (iframe.contentWindow) {
15
+ const frameDoc = iframe.contentWindow.document;
16
+ iframe.className = className;
17
+ frameDoc.body.classList.add(...document.body.classList, ...className.split(' '));
18
+ iframe.style.visibility = 'hidden';
19
+ this.iframeElement = iframe;
20
+ this.initialData = initialData;
21
+ this.settings = settings;
22
+ window.addEventListener('message', this.onInit.bind(this));
23
+ this.addWidgetScript();
24
+ this.addCustomStyles();
25
+ }
26
+ }
27
+ onDataUpdate(data) {
28
+ var _a, _b;
29
+ (_b = (_a = this.iframeElement) === null || _a === void 0 ? void 0 : _a.contentWindow) === null || _b === void 0 ? void 0 : _b.postMessage({
30
+ type: constants_1.DeviceFrameMessageType.Update,
31
+ data,
32
+ }, window.origin);
33
+ }
34
+ onActivenessUpdate(active) {
35
+ if (this.iframeElement) {
36
+ this.iframeElement.style.visibility = active ? 'visible' : 'hidden';
37
+ }
38
+ }
39
+ destroy() {
40
+ window.removeEventListener('message', this.onInit.bind(this));
41
+ }
42
+ addWidgetScript() {
43
+ var _a, _b;
44
+ const frameDoc = (_b = (_a = this.iframeElement) === null || _a === void 0 ? void 0 : _a.contentWindow) === null || _b === void 0 ? void 0 : _b.document;
45
+ if (frameDoc) {
46
+ const head = frameDoc === null || frameDoc === void 0 ? void 0 : frameDoc.getElementsByTagName('head')[0];
47
+ const script = frameDoc.createElement('script');
48
+ script.appendChild(document.createTextNode(widget_1.default));
49
+ head.appendChild(script);
50
+ }
51
+ }
52
+ addCustomStyles() {
53
+ var _a, _b;
54
+ const { applyHostStyles, customStyles } = this.settings || {};
55
+ const frameDoc = (_b = (_a = this.iframeElement) === null || _a === void 0 ? void 0 : _a.contentWindow) === null || _b === void 0 ? void 0 : _b.document;
56
+ if (frameDoc) {
57
+ const head = frameDoc === null || frameDoc === void 0 ? void 0 : frameDoc.getElementsByTagName('head')[0];
58
+ let styles = applyHostStyles ? (0, utils_1.getHostStyles)() : '';
59
+ if (customStyles) {
60
+ styles += `\n${customStyles}`;
61
+ }
62
+ if (styles) {
63
+ const style = frameDoc.createElement('style');
64
+ style.appendChild(document.createTextNode(styles));
65
+ head.appendChild(style);
66
+ }
67
+ }
68
+ }
69
+ onInit(event) {
70
+ const { type } = event.data;
71
+ if (type === constants_1.DeviceFrameMessageType.Ready && this.initialData) {
72
+ this.onDataUpdate(this.initialData);
73
+ }
74
+ }
75
+ }
76
+ exports.DeviceIframe = DeviceIframe;
@@ -0,0 +1 @@
1
+ export declare const getHostStyles: () => string;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getHostStyles = void 0;
4
+ const getHostStyles = () => {
5
+ return [...document.styleSheets]
6
+ .map((styleSheet) => {
7
+ try {
8
+ return [...styleSheet.cssRules].map((rule) => rule.cssText).join('');
9
+ }
10
+ catch (e) {
11
+ //eslint-disable-next-line no-console
12
+ console.log(`Access to stylesheet ${styleSheet.href} is denied. Ignoring...`);
13
+ return '';
14
+ }
15
+ })
16
+ .filter(Boolean)
17
+ .join('\n');
18
+ };
19
+ exports.getHostStyles = getHostStyles;
@@ -16,7 +16,7 @@ const useHeightCalculator = (containerRef, options = DEFAULT_OPTIONS) => {
16
16
  }, [containerRef, containerHeight, setContainerHeight]);
17
17
  (0, react_1.useEffect)(() => {
18
18
  const handleResize = lodash_1.default.debounce(calculateContainerHeight, recalculateOnResizeDelay);
19
- calculateContainerHeight();
19
+ handleResize();
20
20
  window.addEventListener('resize', handleResize, { passive: true });
21
21
  return () => {
22
22
  window.removeEventListener('resize', handleResize);
@@ -44,6 +44,8 @@ export interface NavigationButtonItem extends ButtonProps {
44
44
  export interface NavigationDropdownItem extends NavigationItemBase {
45
45
  type: NavigationItemType.Dropdown;
46
46
  items: NavigationLinkItem[];
47
+ hidePopup: () => void;
48
+ isActive: boolean;
47
49
  }
48
50
  export interface NavigationSocialItem extends Omit<NavigationItemBase, 'text'> {
49
51
  type: NavigationItemType.Social;
@@ -51,8 +53,7 @@ export interface NavigationSocialItem extends Omit<NavigationItemBase, 'text'> {
51
53
  url: string;
52
54
  }
53
55
  export type NavigationItemModel = NavigationLinkItem | NavigationButtonItem | NavigationDropdownItem;
54
- export type NavigationItemData = NavigationLinkItem | NavigationButtonItem | NavigationSocialItem | DropdownItemData;
55
- export type DropdownItemData = Omit<NavigationDropdownItem, 'items'>;
56
+ export type NavigationItemData = NavigationLinkItem | NavigationButtonItem | NavigationSocialItem | NavigationDropdownItem;
56
57
  export interface NavigationLogoData {
57
58
  icon: ImageProps;
58
59
  text?: string;