Skip to content

Commit 0caa225

Browse files
committed
feat: add iframe block allow permissions configuration #1260
1 parent 2c1f378 commit 0caa225

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

docs/en/guide/schema.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ interface IElement {
177177
iframeBlock?: {
178178
src?: string;
179179
srcdoc?: string;
180+
sandbox?: string[];
181+
allow?: string[];
180182
};
181183
videoBlock?: {
182184
src: string;

docs/guide/schema.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ interface IElement {
177177
iframeBlock?: {
178178
src?: string;
179179
srcdoc?: string;
180+
sandbox?: string[];
181+
allow?: string[];
180182
};
181183
videoBlock?: {
182184
src: string;

src/editor/core/draw/particle/block/modules/IFrameBlock.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { IRowElement } from '../../../../../interface/Row'
22

33
export class IFrameBlock {
44
public static readonly sandbox = ['allow-scripts', 'allow-same-origin']
5+
public static readonly allow = ['fullscreen']
6+
57
private element: IRowElement
68

79
constructor(element: IRowElement) {
@@ -22,17 +24,21 @@ export class IFrameBlock {
2224
}
2325

2426
public render(blockItemContainer: HTMLDivElement) {
25-
const block = this.element.block!
27+
const { iframeBlock } = this.element.block || {}
2628
const iframe = document.createElement('iframe')
2729
iframe.setAttribute('data-id', this.element.id!)
28-
iframe.sandbox.add(...IFrameBlock.sandbox)
30+
iframe.sandbox.add(...(iframeBlock?.sandbox || IFrameBlock.sandbox))
31+
iframe.setAttribute(
32+
'allow',
33+
[iframeBlock?.allow || IFrameBlock.allow].join(' ')
34+
)
2935
iframe.style.border = 'none'
3036
iframe.style.width = '100%'
3137
iframe.style.height = '100%'
32-
if (block.iframeBlock?.src) {
33-
iframe.src = block.iframeBlock.src
34-
} else if (block.iframeBlock?.srcdoc) {
35-
iframe.srcdoc = block.iframeBlock.srcdoc
38+
if (iframeBlock?.src) {
39+
iframe.src = iframeBlock.src
40+
} else if (iframeBlock?.srcdoc) {
41+
iframe.srcdoc = iframeBlock.srcdoc
3642
}
3743
blockItemContainer.append(iframe)
3844
// 重新定义iframe上属性

src/editor/interface/Block.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { BlockType } from '../dataset/enum/Block'
33
export interface IIFrameBlock {
44
src?: string
55
srcdoc?: string
6+
sandbox?: string[]
7+
allow?: string[]
68
}
79

810
export interface IVideoBlock {

src/editor/utils/element.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,10 +1298,12 @@ export function createDomFromElementList(
12981298
clipboardDom.append(video)
12991299
}
13001300
} else if (element.block?.type === BlockType.IFRAME) {
1301-
const { src, srcdoc } = element.block.iframeBlock || {}
1301+
const { src, srcdoc, sandbox, allow } =
1302+
element.block.iframeBlock || {}
13021303
if (src || srcdoc) {
13031304
const iframe = document.createElement('iframe')
1304-
iframe.sandbox.add(...IFrameBlock.sandbox)
1305+
iframe.sandbox.add(...(sandbox || IFrameBlock.sandbox))
1306+
iframe.setAttribute('allow', [allow || IFrameBlock.allow].join(' '))
13051307
iframe.style.display = 'block'
13061308
iframe.style.border = 'none'
13071309
if (src) {

0 commit comments

Comments
 (0)