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:
parent
b745826151
commit
f55d5d233a
2 changed files with 31 additions and 19 deletions
35
dist/embed/iframe.html
vendored
35
dist/embed/iframe.html
vendored
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue