Skip to content

Commit

Permalink
fix: remove condition form iframe window
Browse files Browse the repository at this point in the history
  • Loading branch information
gorgeousvlad committed Jul 19, 2023
1 parent b5a8c45 commit 1f43961
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 27 deletions.
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ task('styles-global', () => {
});

task('styles-components', () => {
return src([`src/**/*.scss`, `!src/**/__stories__/**/*.scss`])
return src([`src/**/*.scss`, `!src/**/__stories__/**/*.scss`, '!src/widget/**/*.scss'])
.pipe(sass().on('error', sass.logError))
.pipe(dest(path.resolve(BUILD_CLIENT_DIR, ESM_DIR)))
.pipe(dest(path.resolve(BUILD_CLIENT_DIR, CJS_DIR)));
Expand Down
4 changes: 1 addition & 3 deletions src/editor/widget/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ export class DeviceIframe {
parentElement.appendChild(iframe);

if (iframe.contentWindow) {
iframe.className = className;
iframe.contentWindow.__isEditorDeviceFrame = true;

const frameDoc = iframe.contentWindow.document;

iframe.className = className;
frameDoc.body.classList.add(...document.body.classList, ...className.split(' '));
iframe.style.visibility = 'hidden';

Expand Down
2 changes: 0 additions & 2 deletions src/internal-typings/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,4 @@ interface Window {
};
};
ymaps: Ymaps;

__isEditorDeviceFrame?: boolean;
}
40 changes: 19 additions & 21 deletions src/widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,24 @@ import {DeviceFrameMessageType} from '../editor/widget/constants';

import './styles.scss';

if (window.self !== window.top && window.__isEditorDeviceFrame) {
const root = document.createElement('div');
document.body.appendChild(root);

window.addEventListener('message', function (event) {
if (event.data?.type === DeviceFrameMessageType.Update) {
const {
data: {constructorProps, providerProps},
} = event.data;

ReactDOM.render(
<PageConstructorProvider {...providerProps}>
<PageConstructor {...constructorProps} />
</PageConstructorProvider>,
root,
);
}
});

window.parent?.postMessage({type: DeviceFrameMessageType.Ready}, window.parent.origin);
}
const root = document.createElement('div');
document.body.appendChild(root);

window.addEventListener('message', function (event) {
if (event.data?.type === DeviceFrameMessageType.Update) {
const {
data: {constructorProps, providerProps},
} = event.data;

ReactDOM.render(
<PageConstructorProvider {...providerProps}>
<PageConstructor {...constructorProps} />
</PageConstructorProvider>,
root,
);
}
});

window.parent?.postMessage({type: DeviceFrameMessageType.Ready}, window.parent.origin);

export default {};

0 comments on commit 1f43961

Please sign in to comment.