2019-12-19 13:34:56 +08:00
|
|
|
import { jsObtainContext, jsCallEntityMethod } from 'doric/src/runtime/sandbox'
|
2019-12-19 13:07:33 +08:00
|
|
|
import { Panel } from 'doric'
|
2019-12-19 11:52:15 +08:00
|
|
|
import { DoricPlugin } from "./DoricPlugin"
|
2019-12-19 13:07:33 +08:00
|
|
|
import { createContext } from "./DoricDriver"
|
2019-12-19 21:12:41 +08:00
|
|
|
import { DoricStackViewNode } from './shader/DoricStackViewNode'
|
2019-12-19 11:52:15 +08:00
|
|
|
const doricContexts: Map<string, DoricContext> = new Map
|
|
|
|
|
2019-12-19 13:07:33 +08:00
|
|
|
let __contextId__ = 0
|
|
|
|
function getContextId() {
|
|
|
|
return `context_${__contextId__++}`
|
|
|
|
}
|
|
|
|
|
2019-12-19 11:52:15 +08:00
|
|
|
export function getDoricContext(contextId: string) {
|
|
|
|
return doricContexts.get(contextId)
|
|
|
|
}
|
|
|
|
|
|
|
|
export class DoricContext {
|
2019-12-19 13:07:33 +08:00
|
|
|
contextId = getContextId()
|
2019-12-19 11:52:15 +08:00
|
|
|
pluginInstances: Map<string, DoricPlugin> = new Map
|
2019-12-19 21:12:41 +08:00
|
|
|
rootNode: DoricStackViewNode
|
2019-12-19 13:07:33 +08:00
|
|
|
constructor(content: string) {
|
|
|
|
createContext(this.contextId, content)
|
|
|
|
doricContexts.set(this.contextId, this)
|
2019-12-19 21:12:41 +08:00
|
|
|
this.rootNode = new DoricStackViewNode(this)
|
2019-12-19 11:52:15 +08:00
|
|
|
}
|
2019-12-19 13:07:33 +08:00
|
|
|
|
|
|
|
get panel() {
|
2019-12-19 13:34:56 +08:00
|
|
|
return jsObtainContext(this.contextId)?.entity as Panel
|
|
|
|
}
|
|
|
|
|
|
|
|
invokeEntityMethod(method: string, ...otherArgs: any) {
|
|
|
|
const argumentsList: any = [this.contextId]
|
|
|
|
for (let i = 0; i < arguments.length; i++) {
|
|
|
|
argumentsList.push(arguments[i])
|
|
|
|
}
|
|
|
|
Reflect.apply(jsCallEntityMethod, this.panel, argumentsList)
|
2019-12-19 13:07:33 +08:00
|
|
|
}
|
|
|
|
|
2019-12-19 13:34:56 +08:00
|
|
|
init(frame: {
|
|
|
|
width: number,
|
|
|
|
height: number,
|
|
|
|
}, extra?: object) {
|
|
|
|
this.invokeEntityMethod("__init__", frame, extra ? JSON.stringify(extra) : undefined)
|
2019-12-19 13:07:33 +08:00
|
|
|
}
|
|
|
|
|
2019-12-19 11:52:15 +08:00
|
|
|
}
|