59 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			59 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import { DoricPlugin } from '../DoricPlugin'
 | 
						|
import { DVModel, DoricViewNode } from '../shader/DoricViewNode';
 | 
						|
import { DoricContext } from '../DoricContext';
 | 
						|
 | 
						|
export class PopoverPlugin extends DoricPlugin {
 | 
						|
    fullScreen = document.createElement('div')
 | 
						|
    constructor(context: DoricContext) {
 | 
						|
        super(context)
 | 
						|
        this.fullScreen.id = `PopOver__${context.contextId}`
 | 
						|
        this.fullScreen.style.position = 'fixed'
 | 
						|
        this.fullScreen.style.top = '0px'
 | 
						|
        this.fullScreen.style.width = "100%"
 | 
						|
        this.fullScreen.style.height = "100%"
 | 
						|
    }
 | 
						|
 | 
						|
    show(model: DVModel) {
 | 
						|
        const viewNode = DoricViewNode.create(this.context, model.type)
 | 
						|
        if (viewNode === undefined) {
 | 
						|
            return Promise.reject(`Cannot create ViewNode for ${model.type}`)
 | 
						|
        }
 | 
						|
        viewNode.viewId = model.id
 | 
						|
        viewNode.init()
 | 
						|
        viewNode.blend(model.props)
 | 
						|
        this.fullScreen.appendChild(viewNode.view)
 | 
						|
        this.context.headNodes.set(model.id, viewNode)
 | 
						|
        if (!document.body.contains(this.fullScreen)) {
 | 
						|
            document.body.appendChild(this.fullScreen)
 | 
						|
        }
 | 
						|
        return Promise.resolve()
 | 
						|
    }
 | 
						|
 | 
						|
    dismiss(args?: { id: string }) {
 | 
						|
        if (args) {
 | 
						|
            const viewNode = this.context.headNodes.get(args.id)
 | 
						|
            if (viewNode) {
 | 
						|
                this.fullScreen.removeChild(viewNode.view)
 | 
						|
            }
 | 
						|
            if (this.context.headNodes.size === 0) {
 | 
						|
                document.body.removeChild(this.fullScreen)
 | 
						|
            }
 | 
						|
        } else {
 | 
						|
            this.dismissAll()
 | 
						|
        }
 | 
						|
        return Promise.resolve()
 | 
						|
    }
 | 
						|
    dismissAll() {
 | 
						|
        for (let node of this.context.headNodes.values()) {
 | 
						|
            this.context.headNodes.delete(node.viewId)
 | 
						|
            this.fullScreen.removeChild(node.view)
 | 
						|
        }
 | 
						|
        if (document.body.contains(this.fullScreen)) {
 | 
						|
            document.body.removeChild(this.fullScreen)
 | 
						|
        }
 | 
						|
    }
 | 
						|
    onTearDown() {
 | 
						|
        super.onTearDown()
 | 
						|
        this.dismissAll()
 | 
						|
    }
 | 
						|
} |