@it-consultis/page-builder 1.1.34 → 1.1.36

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.
@@ -0,0 +1,23 @@
1
+ import React, { AllHTMLAttributes } from 'react';
2
+ import { Block } from './types';
3
+ export declare const EDITOR_READY = "editor/editorReady";
4
+ export declare const EDITOR_DATA = "editor/editorData";
5
+ export declare const EDITOR_BLOCK_UPDATE = "editor/blockUpdate";
6
+ export declare const EDITOR_BLOCK_DELETE = "editor/blockDelete";
7
+ export declare const EDITOR_BLOCK_ADD = "editor/blockAdd";
8
+ export type EditorInstance = {
9
+ element: HTMLIFrameElement | null;
10
+ setData(data: Block[]): void;
11
+ dispatch(action: {
12
+ type: string;
13
+ payload: any;
14
+ }): void;
15
+ };
16
+ type Props = Omit<AllHTMLAttributes<HTMLIFrameElement>, 'onLoad' | 'src' | 'className'> & {
17
+ src: string;
18
+ className?: string;
19
+ onLoad(editor: EditorInstance): void;
20
+ onChange(data: Block[]): void;
21
+ };
22
+ declare const EditorIframe: React.FC<Props>;
23
+ export default EditorIframe;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.EDITOR_READY = exports.EDITOR_DATA = exports.EDITOR_BLOCK_UPDATE = exports.EDITOR_BLOCK_DELETE = exports.EDITOR_BLOCK_ADD = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _jsxRuntime = require("react/jsx-runtime");
9
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
+ const EDITOR_READY = exports.EDITOR_READY = 'editor/editorReady';
12
+ const EDITOR_DATA = exports.EDITOR_DATA = 'editor/editorData';
13
+ const EDITOR_BLOCK_UPDATE = exports.EDITOR_BLOCK_UPDATE = 'editor/blockUpdate';
14
+ const EDITOR_BLOCK_DELETE = exports.EDITOR_BLOCK_DELETE = 'editor/blockDelete';
15
+ const EDITOR_BLOCK_ADD = exports.EDITOR_BLOCK_ADD = 'editor/blockAdd';
16
+ const EditorIframe = props => {
17
+ const {
18
+ src,
19
+ onLoad,
20
+ className,
21
+ onChange,
22
+ ...otherProps
23
+ } = props;
24
+ const editorUrl = (0, _react.useMemo)(() => {
25
+ return new URL(src);
26
+ }, [src]);
27
+ const [editorIframeEl, setEditorIframeEl] = (0, _react.useState)(null);
28
+ (0, _react.useEffect)(() => {
29
+ if (!editorIframeEl) {
30
+ return undefined;
31
+ }
32
+ const iframeWindow = editorIframeEl.contentWindow;
33
+ if (!iframeWindow) {
34
+ return undefined;
35
+ }
36
+ const dispatch = action => {
37
+ iframeWindow.postMessage({
38
+ ...action,
39
+ type: action.type.startsWith('editor/') ? action.type : `editor/${action.type}`
40
+ }, editorUrl.origin);
41
+ };
42
+ const sendData = data => {
43
+ dispatch({
44
+ type: EDITOR_DATA,
45
+ payload: data
46
+ });
47
+ };
48
+ const listener = event => {
49
+ if (event.origin !== editorUrl.origin) {
50
+ return;
51
+ }
52
+ const {
53
+ type,
54
+ payload
55
+ } = event.data;
56
+ switch (type) {
57
+ case EDITOR_READY:
58
+ onLoad({
59
+ element: editorIframeEl,
60
+ setData(data) {
61
+ sendData(data);
62
+ },
63
+ dispatch
64
+ });
65
+ break;
66
+ case EDITOR_DATA:
67
+ onChange(payload);
68
+ break;
69
+ default:
70
+ // Ignore unsupported events.
71
+ break;
72
+ }
73
+ };
74
+ window.addEventListener('message', listener);
75
+ return () => {
76
+ window.removeEventListener('message', listener);
77
+ };
78
+ }, [editorIframeEl, onLoad, editorUrl, onChange]);
79
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("iframe", {
80
+ ...otherProps,
81
+ className: className,
82
+ ref: node => {
83
+ if (!node || !node.contentDocument) {
84
+ return;
85
+ }
86
+ if (node.contentDocument.readyState === 'complete') {
87
+ setEditorIframeEl(node);
88
+ } else {
89
+ node.addEventListener('load', () => setEditorIframeEl(node));
90
+ }
91
+ },
92
+ src: src
93
+ });
94
+ };
95
+ var _default = exports.default = EditorIframe;
@@ -243,7 +243,9 @@ const EditorPreview = props => {
243
243
  p: 2,
244
244
  display: 'flex',
245
245
  justifyContent: 'center',
246
- alignItems: 'center',
246
+ paddingTop: '5vh',
247
+ // It'll looks like cut off top area when high not enough
248
+ // alignItems: 'center',
247
249
  bgcolor: 'background.paper'
248
250
  },
249
251
  onDrop: handleDrop,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@it-consultis/page-builder",
3
- "version": "1.1.34",
3
+ "version": "1.1.36",
4
4
  "license": "MIT",
5
5
  "author": "itc",
6
6
  "scripts": {