feat: add sandbox iframe under btn
This commit is contained in:
parent
f6536114ae
commit
935b56e4d2
2 changed files with 5 additions and 12 deletions
10
src/btn.ts
10
src/btn.ts
|
@ -148,7 +148,7 @@ export class BtnList {
|
|||
|
||||
case BtnListMode.ExtWindow: {
|
||||
const div = this._commit()
|
||||
const w = await windowOpenAsync('', undefined, 'resizable,width=230,height=270')
|
||||
const w = await windowOpenAsync(undefined, '', undefined, 'resizable,width=230,height=270')
|
||||
// eslint-disable-next-line no-unused-expressions
|
||||
w?.document.body.append(div)
|
||||
window.addEventListener('unload', () => w?.close())
|
||||
|
@ -174,12 +174,6 @@ export namespace BtnAction {
|
|||
else return url
|
||||
}
|
||||
|
||||
export const openUrl = (url: UrlInput): BtnAction => {
|
||||
return process(async (): Promise<any> => {
|
||||
return windowOpenAsync(await normalizeUrlInput(url))
|
||||
})
|
||||
}
|
||||
|
||||
export const download = (url: UrlInput, fallback?: () => Promisable<void>, timeout?: number): BtnAction => {
|
||||
return process(async (): Promise<void> => {
|
||||
const _url = await normalizeUrlInput(url)
|
||||
|
@ -195,7 +189,7 @@ export namespace BtnAction {
|
|||
btn.onclick = null
|
||||
setText(i18n('PROCESSING')())
|
||||
|
||||
const w = await windowOpenAsync('') as Window
|
||||
const w = await windowOpenAsync(btn, '') as Window
|
||||
const txt = document.createTextNode(i18n('PROCESSING')())
|
||||
w.document.body.append(txt)
|
||||
|
||||
|
|
|
@ -47,11 +47,10 @@ export const useTimeout = async <T> (promise: T | Promise<T>, ms: number): Promi
|
|||
})
|
||||
}
|
||||
|
||||
export const getSandboxWindowAsync = async (): Promise<Window> => {
|
||||
export const getSandboxWindowAsync = async (targetEl = document.documentElement): Promise<Window> => {
|
||||
if (typeof document === 'undefined') return {} as any as Window
|
||||
|
||||
return new Promise((resolve) => {
|
||||
const targetEl = document.documentElement
|
||||
const eventName = 'onmousemove'
|
||||
const id = Math.random().toString()
|
||||
|
||||
|
@ -76,8 +75,8 @@ export const getUnsafeWindow = (): Window => {
|
|||
|
||||
export const console: Console = (window || global).console // Object.is(window.console, unsafeWindow.console) == false
|
||||
|
||||
export const windowOpenAsync = (...args: Parameters<Window['open']>): Promise<Window | null> => {
|
||||
return getSandboxWindowAsync().then(w => w.open(...args))
|
||||
export const windowOpenAsync = (targetEl = document.documentElement, ...args: Parameters<Window['open']>): Promise<Window | null> => {
|
||||
return getSandboxWindowAsync(targetEl).then(w => w.open(...args))
|
||||
}
|
||||
|
||||
export const attachShadow = (el: Element): ShadowRoot => {
|
||||
|
|
Loading…
Reference in a new issue