1
0
Fork 0
mirror of https://github.com/anyproto/anytype-ts.git synced 2025-06-11 10:18:07 +09:00

embed fixes

This commit is contained in:
Andrew Simachev 2023-12-06 13:07:05 +01:00
parent b745826151
commit f55d5d233a
No known key found for this signature in database
GPG key ID: 49A163D0D14E6FD8
2 changed files with 31 additions and 19 deletions

View file

@ -14,22 +14,29 @@
</head>
<body>
<script type="text/javascript">
window.addEventListener('message', e => {
if (e.origin.match('http://localhost:') || (e.origin === null)) {
const body = document.body;
const { html, js, theme, libs } = e.data;
loadLibs(libs, () => {
body.innerHTML = html;
body.className = theme;
if (js) {
eval(js);
};
resize(e);
});
if (!e.origin.match(/\/\/localhost:/) && (e.origin !== null)) {
return;
};
const body = document.body;
const { html, js, theme, libs } = e.data;
loadLibs(libs, () => {
body.innerHTML = html;
body.className = theme;
if (js) {
try {
eval(js);
} catch (e) {
console.error(e);
};
};
resize(e);
});
});
window.addEventListener('resize', resize);

View file

@ -459,23 +459,28 @@ const BlockEmbed = observer(class BlockEmbedIndex extends React.Component<I.Bloc
const sandbox = [ 'allow-scripts' ];
const allowSameOrigin = [ I.EmbedProcessor.Youtube, I.EmbedProcessor.Vimeo, I.EmbedProcessor.Soundcloud, I.EmbedProcessor.GoogleMaps, I.EmbedProcessor.Miro ];
const allowPresentation = [ I.EmbedProcessor.Youtube ];
const allowEmbedUrl = [ I.EmbedProcessor.Youtube, I.EmbedProcessor.Vimeo, I.EmbedProcessor.GoogleMaps, I.EmbedProcessor.Miro ];
const allowJs = [ I.EmbedProcessor.Chart ];
if (allowSameOrigin.includes(processor)) {
sandbox.push('allow-same-origin');
};
if (allowPresentation.includes(processor)) {
sandbox.push('allow-presentation');
};
const onLoad = () => {
const iw = (iframe[0] as HTMLIFrameElement).contentWindow;
const env = this.getEnvironmentContent();
const data: any = { ...env, theme: commonStore.getThemeClass() };
if ([ I.EmbedProcessor.Youtube, I.EmbedProcessor.Vimeo, I.EmbedProcessor.GoogleMaps, I.EmbedProcessor.Miro ].includes(processor)) {
if (!text.match(/<iframe/)) {
text = UtilEmbed.getHtml(processor, UtilEmbed.getParsedUrl(text));
};
if (allowEmbedUrl.includes(processor) && !text.match(/<iframe/)) {
text = UtilEmbed.getHtml(processor, UtilEmbed.getParsedUrl(text));
};
if (processor == I.EmbedProcessor.Chart) {
if (allowJs.includes(processor)) {
data.js = text;
} else {
data.html = text;