@gravity-ui/page-constructor 3.10.3 → 3.11.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.
- package/CHANGELOG.md +15 -0
- package/README.md +3 -5
- package/build/cjs/editor/components/ControlPanel/ControlPanel.js +4 -1
- package/build/cjs/editor/components/DeviceEmulation/DeviceEmulation.d.ts +7 -0
- package/build/cjs/editor/components/DeviceEmulation/DeviceEmulation.js +10 -0
- package/build/cjs/editor/components/DeviceEmulation/DeviceEmulationMobile/DeviceEmulationMobile.css +33 -0
- package/build/cjs/editor/components/DeviceEmulation/DeviceEmulationMobile/DeviceEmulationMobile.d.ts +8 -0
- package/build/cjs/editor/components/DeviceEmulation/DeviceEmulationMobile/DeviceEmulationMobile.js +41 -0
- package/build/cjs/editor/components/DeviceEmulation/utils.d.ts +4 -0
- package/build/cjs/editor/components/DeviceEmulation/utils.js +7 -0
- package/build/cjs/editor/components/Layout/Layout.js +3 -1
- package/build/cjs/editor/containers/Editor/Editor.d.ts +1 -1
- package/build/cjs/editor/containers/Editor/Editor.js +34 -9
- package/build/cjs/editor/containers/Form/Form.js +2 -2
- package/build/cjs/editor/context.d.ts +9 -0
- package/build/cjs/editor/context.js +6 -0
- package/build/cjs/editor/icons/Tablet.d.ts +2 -0
- package/build/cjs/editor/icons/Tablet.js +9 -0
- package/build/cjs/editor/types/index.d.ts +14 -5
- package/build/cjs/editor/types/index.js +3 -1
- package/build/cjs/editor/utils/index.d.ts +2 -0
- package/build/cjs/editor/utils/index.js +4 -1
- package/build/cjs/editor/widget/constants.d.ts +4 -0
- package/build/cjs/editor/widget/constants.js +8 -0
- package/build/cjs/editor/widget/index.d.ts +21 -0
- package/build/cjs/editor/widget/index.js +76 -0
- package/build/cjs/editor/widget/utils.d.ts +1 -0
- package/build/cjs/editor/widget/utils.js +19 -0
- package/build/esm/editor/components/ControlPanel/ControlPanel.js +6 -3
- package/build/esm/editor/components/DeviceEmulation/DeviceEmulation.d.ts +7 -0
- package/build/esm/editor/components/DeviceEmulation/DeviceEmulation.js +7 -0
- package/build/esm/editor/components/DeviceEmulation/DeviceEmulationMobile/DeviceEmulationMobile.css +33 -0
- package/build/esm/editor/components/DeviceEmulation/DeviceEmulationMobile/DeviceEmulationMobile.d.ts +9 -0
- package/build/esm/editor/components/DeviceEmulation/DeviceEmulationMobile/DeviceEmulationMobile.js +40 -0
- package/build/esm/editor/components/DeviceEmulation/utils.d.ts +4 -0
- package/build/esm/editor/components/DeviceEmulation/utils.js +3 -0
- package/build/esm/editor/components/Layout/Layout.js +3 -1
- package/build/esm/editor/containers/Editor/Editor.d.ts +1 -1
- package/build/esm/editor/containers/Editor/Editor.js +35 -10
- package/build/esm/editor/containers/Form/Form.js +2 -2
- package/build/esm/editor/context.d.ts +9 -0
- package/build/esm/editor/context.js +2 -0
- package/build/esm/editor/icons/Tablet.d.ts +2 -0
- package/build/esm/editor/icons/Tablet.js +4 -0
- package/build/esm/editor/types/index.d.ts +14 -5
- package/build/esm/editor/types/index.js +3 -1
- package/build/esm/editor/utils/index.d.ts +2 -0
- package/build/esm/editor/utils/index.js +2 -0
- package/build/esm/editor/widget/constants.d.ts +4 -0
- package/build/esm/editor/widget/constants.js +5 -0
- package/build/esm/editor/widget/index.d.ts +21 -0
- package/build/esm/editor/widget/index.js +71 -0
- package/build/esm/editor/widget/utils.d.ts +1 -0
- package/build/esm/editor/widget/utils.js +15 -0
- package/package.json +23 -8
- package/widget/index.js +1 -0
package/build/esm/editor/components/DeviceEmulation/DeviceEmulationMobile/DeviceEmulationMobile.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import React, { useContext, useEffect, useRef } from 'react';
|
|
3
|
+
import { block } from '../../../../utils';
|
|
4
|
+
import { EditorContext } from '../../../context';
|
|
5
|
+
import { DeviceIframe } from '../../../widget';
|
|
6
|
+
import './DeviceEmulationMobile.css';
|
|
7
|
+
const b = block('device-emulation-mobile');
|
|
8
|
+
const DeviceEmulationMobile = ({ device, active }) => {
|
|
9
|
+
const _a = useContext(EditorContext), { deviceEmulationSettings } = _a, initialData = __rest(_a, ["deviceEmulationSettings"]);
|
|
10
|
+
const containerRef = useRef(null);
|
|
11
|
+
const deviceIframeRef = useRef(null);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
let iframe;
|
|
14
|
+
if (containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) {
|
|
15
|
+
iframe = new DeviceIframe(containerRef === null || containerRef === void 0 ? void 0 : containerRef.current, {
|
|
16
|
+
initialData,
|
|
17
|
+
className: b('frame', { device }),
|
|
18
|
+
settings: deviceEmulationSettings,
|
|
19
|
+
});
|
|
20
|
+
deviceIframeRef.current = iframe;
|
|
21
|
+
}
|
|
22
|
+
return () => {
|
|
23
|
+
iframe === null || iframe === void 0 ? void 0 : iframe.destroy();
|
|
24
|
+
};
|
|
25
|
+
// render iframe only once, then update it's data with postMessage
|
|
26
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
27
|
+
}, [device]);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (deviceIframeRef.current) {
|
|
30
|
+
deviceIframeRef.current.onActivenessUpdate(active);
|
|
31
|
+
}
|
|
32
|
+
}, [active]);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (deviceIframeRef.current && initialData) {
|
|
35
|
+
deviceIframeRef.current.onDataUpdate(initialData);
|
|
36
|
+
}
|
|
37
|
+
}, [initialData]);
|
|
38
|
+
return React.createElement("div", { className: b({ active, device }), ref: containerRef });
|
|
39
|
+
};
|
|
40
|
+
export 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;
|
|
@@ -2,6 +2,7 @@ import React, { Children, Fragment } from 'react';
|
|
|
2
2
|
import { block } from '../../../utils';
|
|
3
3
|
import { ViewModeItem } from '../../types';
|
|
4
4
|
import ControlPanel from '../ControlPanel/ControlPanel';
|
|
5
|
+
import DeviceEmulation from '../DeviceEmulation/DeviceEmulation';
|
|
5
6
|
import './Layout.css';
|
|
6
7
|
const b = block('editor-layout');
|
|
7
8
|
const Left = () => null;
|
|
@@ -27,7 +28,8 @@ const Layout = ({ children, mode, onModeChange }) => {
|
|
|
27
28
|
React.createElement("div", { className: b('container') },
|
|
28
29
|
React.createElement(Fragment, null,
|
|
29
30
|
left && React.createElement("div", { className: b('left') }, left),
|
|
30
|
-
right && React.createElement("div", { className: b('right', { editing: isEditingMode }) },
|
|
31
|
+
right && (React.createElement("div", { className: b('right', { editing: isEditingMode }) },
|
|
32
|
+
React.createElement(DeviceEmulation, { mode: mode }, right)))))));
|
|
31
33
|
};
|
|
32
34
|
Layout.Left = Left;
|
|
33
35
|
Layout.Right = Right;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { EditorProps } from '../../types';
|
|
2
|
-
export declare const Editor: ({
|
|
2
|
+
export declare const Editor: ({ customSchema, onChange, providerProps, transformContent, deviceEmulationSettings, ...rest }: EditorProps) => JSX.Element;
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import React, { useEffect, useMemo } from 'react';
|
|
3
|
+
import { PageConstructor, PageConstructorProvider } from '../../../containers/PageConstructor';
|
|
3
4
|
import AddBlock from '../../components/AddBlock/AddBlock';
|
|
4
5
|
import EditBlock from '../../components/EditBlock/EditBlock';
|
|
5
6
|
import { ErrorBoundary } from '../../components/ErrorBoundary/ErrorBoundary';
|
|
6
7
|
import Layout from '../../components/Layout/Layout';
|
|
7
8
|
import { NotFoundBlock } from '../../components/NotFoundBlock/NotFoundBlock';
|
|
9
|
+
import { EditorContext } from '../../context';
|
|
8
10
|
import useFormSpec from '../../hooks/useFormSpec';
|
|
9
11
|
import { useEditorState } from '../../store';
|
|
10
12
|
import { ViewModeItem } from '../../types';
|
|
11
|
-
import { addCustomDecorator, getBlockId } from '../../utils';
|
|
13
|
+
import { addCustomDecorator, checkIsMobile, getBlockId } from '../../utils';
|
|
12
14
|
import { Form } from '../Form/Form';
|
|
13
15
|
export const Editor = (_a) => {
|
|
14
|
-
var {
|
|
16
|
+
var { customSchema, onChange, providerProps, transformContent, deviceEmulationSettings } = _a, rest = __rest(_a, ["customSchema", "onChange", "providerProps", "transformContent", "deviceEmulationSettings"]);
|
|
15
17
|
const { content, activeBlockIndex, errorBoundaryState, viewMode, onContentUpdate, onViewModeUpdate, onAdd, onSelect, injectEditBlockProps, } = useEditorState(rest);
|
|
16
18
|
const formSpecs = useFormSpec(customSchema);
|
|
17
19
|
const isEditingMode = viewMode === ViewModeItem.Edititng;
|
|
20
|
+
const transformedContent = useMemo(() => (transformContent ? transformContent(content, { viewMode }) : content), [content, transformContent, viewMode]);
|
|
18
21
|
const outgoingProps = useMemo(() => {
|
|
19
22
|
const custom = isEditingMode
|
|
20
23
|
? addCustomDecorator([
|
|
@@ -24,15 +27,37 @@ export const Editor = (_a) => {
|
|
|
24
27
|
(props) => (React.createElement(ErrorBoundary, Object.assign({}, props, { key: `${getBlockId(props)}-${errorBoundaryState}` }))),
|
|
25
28
|
], rest.custom)
|
|
26
29
|
: rest.custom;
|
|
27
|
-
return {
|
|
28
|
-
|
|
30
|
+
return {
|
|
31
|
+
content: transformedContent,
|
|
32
|
+
custom,
|
|
33
|
+
viewMode,
|
|
34
|
+
};
|
|
35
|
+
}, [
|
|
36
|
+
injectEditBlockProps,
|
|
37
|
+
errorBoundaryState,
|
|
38
|
+
isEditingMode,
|
|
39
|
+
viewMode,
|
|
40
|
+
transformedContent,
|
|
41
|
+
rest.custom,
|
|
42
|
+
]);
|
|
43
|
+
const context = useMemo(() => ({
|
|
44
|
+
constructorProps: {
|
|
45
|
+
content: transformedContent,
|
|
46
|
+
custom: rest.custom,
|
|
47
|
+
},
|
|
48
|
+
providerProps: Object.assign(Object.assign({}, providerProps), { isMobile: checkIsMobile(viewMode) }),
|
|
49
|
+
deviceEmulationSettings,
|
|
50
|
+
}), [providerProps, rest.custom, viewMode, transformedContent, deviceEmulationSettings]);
|
|
29
51
|
useEffect(() => {
|
|
30
52
|
onChange === null || onChange === void 0 ? void 0 : onChange(content);
|
|
31
53
|
}, [content, onChange]);
|
|
32
|
-
return (React.createElement(
|
|
33
|
-
|
|
34
|
-
React.createElement(
|
|
35
|
-
|
|
36
|
-
React.createElement(
|
|
37
|
-
|
|
54
|
+
return (React.createElement(EditorContext.Provider, { value: context },
|
|
55
|
+
React.createElement(Layout, { mode: viewMode, onModeChange: onViewModeUpdate },
|
|
56
|
+
isEditingMode && (React.createElement(Layout.Left, null,
|
|
57
|
+
React.createElement(Form, { content: content, onChange: onContentUpdate, activeBlockIndex: activeBlockIndex, onSelect: onSelect, spec: formSpecs }))),
|
|
58
|
+
React.createElement(Layout.Right, null,
|
|
59
|
+
React.createElement(ErrorBoundary, { key: errorBoundaryState },
|
|
60
|
+
React.createElement(PageConstructorProvider, Object.assign({}, providerProps),
|
|
61
|
+
React.createElement(PageConstructor, Object.assign({}, outgoingProps)))),
|
|
62
|
+
isEditingMode && React.createElement(AddBlock, { onAdd: onAdd })))));
|
|
38
63
|
};
|
|
@@ -28,8 +28,8 @@ export const Form = memo(({ content, onChange, activeBlockIndex, onSelect, spec
|
|
|
28
28
|
break;
|
|
29
29
|
}
|
|
30
30
|
case FormTab.Blocks: {
|
|
31
|
-
form = (React.createElement(Fragment, null, blocks.map((blockData, index) => blocksSpec[blockData.type] ? (React.createElement("div", { className: b('block-form') },
|
|
32
|
-
React.createElement(BlockForm, { spec: blocksSpec[blockData.type],
|
|
31
|
+
form = (React.createElement(Fragment, null, blocks.map((blockData, index) => blocksSpec[blockData.type] ? (React.createElement("div", { className: b('block-form'), key: getBlockKey(blockData, index) },
|
|
32
|
+
React.createElement(BlockForm, { spec: blocksSpec[blockData.type], data: blockData, active: activeBlockIndex === index, onChange: (data) => {
|
|
33
33
|
onChange(Object.assign(Object.assign({}, content), { blocks: [
|
|
34
34
|
...blocks.slice(0, index),
|
|
35
35
|
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,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { a11yHiddenSvgProps } from '../../utils/svg';
|
|
3
|
+
export const Tablet = (props) => (React.createElement("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", width: "12", height: "14", viewBox: "0 0 12 14", fill: "none" }, a11yHiddenSvgProps, props),
|
|
4
|
+
React.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" })));
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
31
|
+
Desktop = "desktop",
|
|
32
|
+
Tablet = "tablet",
|
|
33
|
+
Mobile = "mobile"
|
|
26
34
|
}
|
|
35
|
+
export {};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export var ViewModeItem;
|
|
2
2
|
(function (ViewModeItem) {
|
|
3
3
|
ViewModeItem["Edititng"] = "editing";
|
|
4
|
-
ViewModeItem["
|
|
4
|
+
ViewModeItem["Desktop"] = "desktop";
|
|
5
|
+
ViewModeItem["Tablet"] = "tablet";
|
|
6
|
+
ViewModeItem["Mobile"] = "mobile";
|
|
5
7
|
})(ViewModeItem || (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,7 +1,9 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
|
+
import { ViewModeItem } from '../types';
|
|
2
3
|
export const formatBlockName = (name) => _.capitalize(name).replace(/(block|-)/g, ' ');
|
|
3
4
|
export const addCustomDecorator = (decorators, custom = {}) => {
|
|
4
5
|
const customDecorators = custom.decorators || {};
|
|
5
6
|
return Object.assign(Object.assign({}, custom), { decorators: Object.assign(Object.assign({}, customDecorators), { block: [...(customDecorators.block || []), ...decorators] }) });
|
|
6
7
|
};
|
|
7
8
|
export const getBlockId = ({ index, type }) => `${type}${index === undefined ? '' : `-${index}`}`;
|
|
9
|
+
export const checkIsMobile = (viewMode) => [ViewModeItem.Mobile, ViewModeItem.Tablet].includes(viewMode);
|
|
@@ -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,71 @@
|
|
|
1
|
+
//widget bundle available after build only
|
|
2
|
+
//@ts-ignore
|
|
3
|
+
import bundle from '../../../../widget';
|
|
4
|
+
import { DeviceFrameMessageType } from './constants';
|
|
5
|
+
import { getHostStyles } from './utils';
|
|
6
|
+
export class DeviceIframe {
|
|
7
|
+
constructor(parentElement, { className = '', initialData, settings }) {
|
|
8
|
+
const iframe = document.createElement('iframe');
|
|
9
|
+
parentElement.appendChild(iframe);
|
|
10
|
+
if (iframe.contentWindow) {
|
|
11
|
+
const frameDoc = iframe.contentWindow.document;
|
|
12
|
+
iframe.className = className;
|
|
13
|
+
frameDoc.body.classList.add(...document.body.classList, ...className.split(' '));
|
|
14
|
+
iframe.style.visibility = 'hidden';
|
|
15
|
+
this.iframeElement = iframe;
|
|
16
|
+
this.initialData = initialData;
|
|
17
|
+
this.settings = settings;
|
|
18
|
+
window.addEventListener('message', this.onInit.bind(this));
|
|
19
|
+
this.addWidgetScript();
|
|
20
|
+
this.addCustomStyles();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
onDataUpdate(data) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
(_b = (_a = this.iframeElement) === null || _a === void 0 ? void 0 : _a.contentWindow) === null || _b === void 0 ? void 0 : _b.postMessage({
|
|
26
|
+
type: DeviceFrameMessageType.Update,
|
|
27
|
+
data,
|
|
28
|
+
}, window.origin);
|
|
29
|
+
}
|
|
30
|
+
onActivenessUpdate(active) {
|
|
31
|
+
if (this.iframeElement) {
|
|
32
|
+
this.iframeElement.style.visibility = active ? 'visible' : 'hidden';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
destroy() {
|
|
36
|
+
window.removeEventListener('message', this.onInit.bind(this));
|
|
37
|
+
}
|
|
38
|
+
addWidgetScript() {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
const frameDoc = (_b = (_a = this.iframeElement) === null || _a === void 0 ? void 0 : _a.contentWindow) === null || _b === void 0 ? void 0 : _b.document;
|
|
41
|
+
if (frameDoc) {
|
|
42
|
+
const head = frameDoc === null || frameDoc === void 0 ? void 0 : frameDoc.getElementsByTagName('head')[0];
|
|
43
|
+
const script = frameDoc.createElement('script');
|
|
44
|
+
script.appendChild(document.createTextNode(bundle));
|
|
45
|
+
head.appendChild(script);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
addCustomStyles() {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
const { applyHostStyles, customStyles } = this.settings || {};
|
|
51
|
+
const frameDoc = (_b = (_a = this.iframeElement) === null || _a === void 0 ? void 0 : _a.contentWindow) === null || _b === void 0 ? void 0 : _b.document;
|
|
52
|
+
if (frameDoc) {
|
|
53
|
+
const head = frameDoc === null || frameDoc === void 0 ? void 0 : frameDoc.getElementsByTagName('head')[0];
|
|
54
|
+
let styles = applyHostStyles ? getHostStyles() : '';
|
|
55
|
+
if (customStyles) {
|
|
56
|
+
styles += `\n${customStyles}`;
|
|
57
|
+
}
|
|
58
|
+
if (styles) {
|
|
59
|
+
const style = frameDoc.createElement('style');
|
|
60
|
+
style.appendChild(document.createTextNode(styles));
|
|
61
|
+
head.appendChild(style);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
onInit(event) {
|
|
66
|
+
const { type } = event.data;
|
|
67
|
+
if (type === DeviceFrameMessageType.Ready && this.initialData) {
|
|
68
|
+
this.onDataUpdate(this.initialData);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getHostStyles: () => string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const getHostStyles = () => {
|
|
2
|
+
return [...document.styleSheets]
|
|
3
|
+
.map((styleSheet) => {
|
|
4
|
+
try {
|
|
5
|
+
return [...styleSheet.cssRules].map((rule) => rule.cssText).join('');
|
|
6
|
+
}
|
|
7
|
+
catch (e) {
|
|
8
|
+
//eslint-disable-next-line no-console
|
|
9
|
+
console.log(`Access to stylesheet ${styleSheet.href} is denied. Ignoring...`);
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
})
|
|
13
|
+
.filter(Boolean)
|
|
14
|
+
.join('\n');
|
|
15
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/page-constructor",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.11.0",
|
|
4
4
|
"description": "Gravity UI Page Constructor",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"require": "./server/index.js",
|
|
24
24
|
"import": "./server/index.js"
|
|
25
25
|
},
|
|
26
|
-
"./styles/*": "./styles/*"
|
|
26
|
+
"./styles/*": "./styles/*",
|
|
27
|
+
"./widget/*": "./widget/*"
|
|
27
28
|
},
|
|
28
29
|
"main": "./build/cjs/index.js",
|
|
29
30
|
"module": "./build/esm/index.js",
|
|
@@ -44,7 +45,8 @@
|
|
|
44
45
|
"files": [
|
|
45
46
|
"build",
|
|
46
47
|
"styles",
|
|
47
|
-
"server"
|
|
48
|
+
"server",
|
|
49
|
+
"widget"
|
|
48
50
|
],
|
|
49
51
|
"sideEffects": [
|
|
50
52
|
"*.css",
|
|
@@ -69,7 +71,8 @@
|
|
|
69
71
|
"clean": "gulp clean",
|
|
70
72
|
"build:client": "gulp",
|
|
71
73
|
"build:server": "rimraf server && tsc -p tsconfig.server.json && move-file server/server.js server/index.js && move-file server/server.d.ts server/index.d.ts",
|
|
72
|
-
"build": "
|
|
74
|
+
"build:widget": "webpack --config widget.webpack.js",
|
|
75
|
+
"build": "run-p build:client build:server build:widget",
|
|
73
76
|
"prepublishOnly": "npm run lint && npm run build",
|
|
74
77
|
"prepare": "husky install",
|
|
75
78
|
"test": "jest",
|
|
@@ -100,9 +103,11 @@
|
|
|
100
103
|
"react": "^16.0.0 || ^17.0.0 || ^18.0.0"
|
|
101
104
|
},
|
|
102
105
|
"devDependencies": {
|
|
106
|
+
"@babel/core": "^7.22.8",
|
|
103
107
|
"@commitlint/cli": "^17.1.2",
|
|
104
108
|
"@commitlint/config-conventional": "^17.1.0",
|
|
105
109
|
"@doc-tools/transform": "2.12.0",
|
|
110
|
+
"@gravity-ui/babel-preset": "^1.0.1",
|
|
106
111
|
"@gravity-ui/eslint-config": "^2.0.0",
|
|
107
112
|
"@gravity-ui/icons": "^2.1.0",
|
|
108
113
|
"@gravity-ui/prettier-config": "^1.0.1",
|
|
@@ -127,6 +132,9 @@
|
|
|
127
132
|
"@types/react-transition-group": "^4.4.4",
|
|
128
133
|
"@types/sanitize-html": "2.6.1",
|
|
129
134
|
"@types/uuid": "^9.0.0",
|
|
135
|
+
"autoprefixer": "^10.4.14",
|
|
136
|
+
"babel-loader": "^8.3.0",
|
|
137
|
+
"css-loader": "^5.2.7",
|
|
130
138
|
"es5-ext": "0.10.53",
|
|
131
139
|
"eslint": "^8.34.0",
|
|
132
140
|
"eslint-plugin-local": "./eslint-plugin-local",
|
|
@@ -134,7 +142,8 @@
|
|
|
134
142
|
"eslint-plugin-testing-library": "^5.9.1",
|
|
135
143
|
"gulp": "^4.0.2",
|
|
136
144
|
"gulp-dart-sass": "^1.0.2",
|
|
137
|
-
"gulp-replace": "^1.1.
|
|
145
|
+
"gulp-replace": "^1.1.4",
|
|
146
|
+
"gulp-ts-alias": "^2.0.0",
|
|
138
147
|
"gulp-typescript": "^6.0.0-alpha.1",
|
|
139
148
|
"html-loader": "^1.3.2",
|
|
140
149
|
"htmlparser2": "^6.1.0",
|
|
@@ -148,20 +157,26 @@
|
|
|
148
157
|
"move-file-cli": "^3.0.0",
|
|
149
158
|
"npm-run-all": "^4.1.5",
|
|
150
159
|
"postcss": "^8.4.16",
|
|
160
|
+
"postcss-loader": "^4.3.0",
|
|
161
|
+
"postcss-preset-env": "^9.0.0",
|
|
151
162
|
"postcss-scss": "^4.0.4",
|
|
152
163
|
"prettier": "2.4.1",
|
|
153
164
|
"react": "^18.2.0",
|
|
154
165
|
"react-docgen-typescript": "^2.2.2",
|
|
155
166
|
"react-dom": "^18.2.0",
|
|
167
|
+
"resolve-url-loader": "^3.1.5",
|
|
156
168
|
"rimraf": "^3.0.2",
|
|
157
|
-
"sass": "^1.
|
|
158
|
-
"sass-loader": "^10.
|
|
169
|
+
"sass": "^1.63.6",
|
|
170
|
+
"sass-loader": "^10.4.1",
|
|
171
|
+
"style-loader": "^2.0.0",
|
|
159
172
|
"stylelint": "^14.11.0",
|
|
160
173
|
"svg-sprite-loader": "^6.0.11",
|
|
161
174
|
"ts-jest": "^29.0.3",
|
|
162
175
|
"tslib": "^2.4.0",
|
|
163
176
|
"typescript": "^4.9.4",
|
|
164
|
-
"webpack": "^4.46.0"
|
|
177
|
+
"webpack": "^4.46.0",
|
|
178
|
+
"webpack-cli": "^4.10.0",
|
|
179
|
+
"webpack-shell-plugin": "^0.4.10"
|
|
165
180
|
},
|
|
166
181
|
"lint-staged": {
|
|
167
182
|
"*.{css,scss}": [
|