diff --git a/dist/Counter.js b/dist/Counter.js index 0d3950d9..cb91055c 100644 --- a/dist/Counter.js +++ b/dist/Counter.js @@ -12,6 +12,10 @@ var __metadata = (undefined && undefined.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; class CounterView extends doric.ViewHolder { + test() { + console.log('Invoke Success') + } + build(root) { root.addChild(doric.vlayout([ doric.text({ diff --git a/dist/index.js b/dist/index.js index 310ea80c..3f7b30e3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1478,7 +1478,7 @@ var doric = (function (exports) { /**--------SandBox--------*/ /**++++++++Lib++++++++*/ -Reflect.apply(doric.jsRegisterModule,this,[doric,Reflect.apply(function(__module){(function(module,exports,require){ +Reflect.apply(doric.jsRegisterModule,this,["doric",Reflect.apply(function(__module){(function(module,exports,require){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); @@ -3537,14 +3537,134 @@ return __module.exports; axios = axios && axios.hasOwnProperty('default') ? axios['default'] : axios; - let contexId = 0; - function getContextId() { - return `${contexId++}`; + const bundles = new Map; + const plugins = new Map; + function acquireJSBundle(name) { + return bundles.get(name); + } + function acquirePlugin(name) { + return plugins.get(name); + } + + let __scriptId__ = 0; + function getScriptId() { + return `script_${__scriptId__++}`; + } + function injectGlobalObject(name, value) { + Reflect.set(window, name, value, window); + } + function loadJS(script) { + const scriptElement = document.createElement('script'); + scriptElement.text = script; + scriptElement.id = getScriptId(); + document.body.appendChild(scriptElement); + } + function packageModuleScript(name, content) { + return `Reflect.apply(doric.jsRegisterModule,this,[${name},Reflect.apply(function(__module){(function(module,exports,require){ +${content} +})(__module,__module.exports,doric.__require__); +return __module.exports;},this,[{exports:{}}])])`; + } + function packageCreateContext(contextId, content) { + return `Reflect.apply(function(doric,context,Entry,require,exports){ +${content} +},doric.jsObtainContext("${contextId}"),[undefined,doric.jsObtainContext("${contextId}"),doric.jsObtainEntry("${contextId}"),doric.__require__,{}])`; } function initDoric() { - sandbox.jsCallReject('', ''); + injectGlobalObject('nativeLog', (type, message) => { + switch (type) { + case 'd': + console.log(message); + break; + case 'w': + console.warn(message); + break; + case 'e': + console.error(message); + break; + } + }); + injectGlobalObject('nativeRequire', (moduleName) => { + const bundle = acquireJSBundle(moduleName); + if (bundle === undefined || bundle.length === 0) { + console.log(`Cannot require JS Bundle :${moduleName}`); + return false; + } + else { + loadJS(packageModuleScript(moduleName, packageModuleScript(name, bundle))); + return true; + } + }); + injectGlobalObject('nativeBridge', (contextId, namespace, method, callbackId, args) => { + const pluginClass = acquirePlugin(namespace); + const doricContext = getDoricContext(contextId); + if (pluginClass === undefined) { + console.error(`Cannot find Plugin:${namespace}`); + return false; + } + if (doricContext === undefined) { + console.error(`Cannot find Doric Context:${contextId}`); + return false; + } + let plugin = doricContext.pluginInstances.get(namespace); + if (plugin === undefined) { + plugin = new pluginClass(doricContext); + doricContext.pluginInstances.set(namespace, plugin); + } + if (!Reflect.has(plugin, method)) { + console.error(`Cannot find Method:${method} in plugin ${namespace}`); + return false; + } + const pluginMethod = Reflect.get(plugin, method, plugin); + if (typeof pluginMethod !== 'function') { + console.error(`Plugin ${namespace}'s property ${method}'s type is ${typeof pluginMethod} not function,`); + } + const ret = Reflect.apply(pluginMethod, plugin, [args]); + if (ret instanceof Promise) { + ret.then(e => { + sandbox.jsCallResolve(contextId, callbackId, e); + }, e => { + sandbox.jsCallReject(contextId, callbackId, e); + }); + } + else { + sandbox.jsCallResolve(contextId, callbackId, ret); + } + return true; + }); + } + function createContext(contextId, content) { + loadJS(packageCreateContext(contextId, content)); } initDoric(); + + const doricContexts = new Map; + let __contextId__ = 0; + function getContextId() { + return `context_${__contextId__++}`; + } + function getDoricContext(contextId) { + return doricContexts.get(contextId); + } + class DoricContext { + constructor(content) { + this.contextId = getContextId(); + this.pluginInstances = new Map; + createContext(this.contextId, content); + doricContexts.set(this.contextId, this); + } + get context() { + return sandbox.jsObtainContext(this.contextId); + } + get panel() { + var _a; + return (_a = this.context) === null || _a === void 0 ? void 0 : _a.entity; + } + getEntityMethod(method) { + return Reflect.get(this.panel, method, this.panel); + } + } + class DoricElement extends HTMLElement { constructor() { super(); @@ -3555,12 +3675,8 @@ return __module.exports; }); } load(content) { - const script = document.createElement('script'); - const contextId = getContextId(); - script.text = `Reflect.apply(function(doric,context,Entry,require,exports){ - ${content} - },doric.jsObtainContext("${contextId}"),[undefined,doric.jsObtainContext("${contextId}"),doric.jsObtainEntry("${contextId}"),doric.__require__,{}]);`; - this.append(script); + this.context = new DoricContext(content); + this.context.getEntityMethod('log')(); } } diff --git a/dist/index.js.map b/dist/index.js.map index 20f13532..4e52235f 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sources":["../build/src/DoricElement.js","../build/index.js"],"sourcesContent":["import axios from 'axios';\nimport { jsCallReject } from 'doric/src/runtime/sandbox';\nlet contexId = 0;\nfunction getContextId() {\n return `${contexId++}`;\n}\nfunction initDoric() {\n jsCallReject('', '');\n}\ninitDoric();\nexport class DoricElement extends HTMLElement {\n constructor() {\n super();\n this.source = this.getAttribute('src') || \"\";\n this.alias = this.getAttribute('alias') || this.source;\n axios.get(this.source).then(result => {\n this.load(result.data);\n });\n }\n load(content) {\n const script = document.createElement('script');\n const contextId = getContextId();\n script.text = `Reflect.apply(function(doric,context,Entry,require,exports){\n ${content}\n },doric.jsObtainContext(\"${contextId}\"),[undefined,doric.jsObtainContext(\"${contextId}\"),doric.jsObtainEntry(\"${contextId}\"),doric.__require__,{}]);`;\n this.append(script);\n }\n}\n","import { DoricElement } from './src/DoricElement';\nwindow.customElements.define('doric-div', DoricElement);\n"],"names":["jsCallReject"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC;IACzC,QAAQ,MAAM,CAAC,IAAI,GAAG,CAAC;gBACP,EAAE,OAAO,CAAC;qCACW,EAAE,SAAS,CAAC,qCAAqC,EAAE,SAAS,CAAC,wBAAwB,EAAE,SAAS,CAAC,0BAA0B,CAAC,CAAC;IAClK,QAAQ,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5B,KAAK;IACL,CAAC;;IC1BD,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;;;;"} \ No newline at end of file +{"version":3,"file":"index.js","sources":["../build/src/DoricRegistry.js","../build/src/DoricDriver.js","../build/src/DoricContext.js","../build/src/DoricElement.js","../build/index.js"],"sourcesContent":["const bundles = new Map;\nconst plugins = new Map;\nexport function acquireJSBundle(name) {\n return bundles.get(name);\n}\nexport function registerJSBundle(name, bundle) {\n bundles.set(name, bundle);\n}\nexport function registerPlugin(name, plugin) {\n plugins.set(name, plugin);\n}\nexport function acquirePlugin(name) {\n return plugins.get(name);\n}\n","import { jsCallResolve, jsCallReject } from 'doric/src/runtime/sandbox';\nimport { acquireJSBundle, acquirePlugin } from './DoricRegistry';\nimport { getDoricContext } from './DoricContext';\nlet __scriptId__ = 0;\nfunction getScriptId() {\n return `script_${__scriptId__++}`;\n}\nexport function injectGlobalObject(name, value) {\n Reflect.set(window, name, value, window);\n}\nexport function loadJS(script) {\n const scriptElement = document.createElement('script');\n scriptElement.text = script;\n scriptElement.id = getScriptId();\n document.body.appendChild(scriptElement);\n}\nfunction packageModuleScript(name, content) {\n return `Reflect.apply(doric.jsRegisterModule,this,[${name},Reflect.apply(function(__module){(function(module,exports,require){\n${content}\n})(__module,__module.exports,doric.__require__);\nreturn __module.exports;},this,[{exports:{}}])])`;\n}\nfunction packageCreateContext(contextId, content) {\n return `Reflect.apply(function(doric,context,Entry,require,exports){\n${content}\n},doric.jsObtainContext(\"${contextId}\"),[undefined,doric.jsObtainContext(\"${contextId}\"),doric.jsObtainEntry(\"${contextId}\"),doric.__require__,{}])`;\n}\nfunction initDoric() {\n injectGlobalObject('nativeLog', (type, message) => {\n switch (type) {\n case 'd':\n console.log(message);\n break;\n case 'w':\n console.warn(message);\n break;\n case 'e':\n console.error(message);\n break;\n }\n });\n injectGlobalObject('nativeRequire', (moduleName) => {\n const bundle = acquireJSBundle(moduleName);\n if (bundle === undefined || bundle.length === 0) {\n console.log(`Cannot require JS Bundle :${moduleName}`);\n return false;\n }\n else {\n loadJS(packageModuleScript(moduleName, packageModuleScript(name, bundle)));\n return true;\n }\n });\n injectGlobalObject('nativeBridge', (contextId, namespace, method, callbackId, args) => {\n const pluginClass = acquirePlugin(namespace);\n const doricContext = getDoricContext(contextId);\n if (pluginClass === undefined) {\n console.error(`Cannot find Plugin:${namespace}`);\n return false;\n }\n if (doricContext === undefined) {\n console.error(`Cannot find Doric Context:${contextId}`);\n return false;\n }\n let plugin = doricContext.pluginInstances.get(namespace);\n if (plugin === undefined) {\n plugin = new pluginClass(doricContext);\n doricContext.pluginInstances.set(namespace, plugin);\n }\n if (!Reflect.has(plugin, method)) {\n console.error(`Cannot find Method:${method} in plugin ${namespace}`);\n return false;\n }\n const pluginMethod = Reflect.get(plugin, method, plugin);\n if (typeof pluginMethod !== 'function') {\n console.error(`Plugin ${namespace}'s property ${method}'s type is ${typeof pluginMethod} not function,`);\n }\n const ret = Reflect.apply(pluginMethod, plugin, [args]);\n if (ret instanceof Promise) {\n ret.then(e => {\n jsCallResolve(contextId, callbackId, e);\n }, e => {\n jsCallReject(contextId, callbackId, e);\n });\n }\n else {\n jsCallResolve(contextId, callbackId, ret);\n }\n return true;\n });\n}\nexport function createContext(contextId, content) {\n loadJS(packageCreateContext(contextId, content));\n}\ninitDoric();\n","import { jsObtainContext } from 'doric/src/runtime/sandbox';\nimport { createContext } from \"./DoricDriver\";\nconst doricContexts = new Map;\nlet __contextId__ = 0;\nfunction getContextId() {\n return `context_${__contextId__++}`;\n}\nexport function getDoricContext(contextId) {\n return doricContexts.get(contextId);\n}\nexport class DoricContext {\n constructor(content) {\n this.contextId = getContextId();\n this.pluginInstances = new Map;\n createContext(this.contextId, content);\n doricContexts.set(this.contextId, this);\n }\n get context() {\n return jsObtainContext(this.contextId);\n }\n get panel() {\n var _a;\n return (_a = this.context) === null || _a === void 0 ? void 0 : _a.entity;\n }\n getEntityMethod(method) {\n return Reflect.get(this.panel, method, this.panel);\n }\n}\n","import axios from 'axios';\nimport { DoricContext } from './DoricContext';\nexport class DoricElement extends HTMLElement {\n constructor() {\n super();\n this.source = this.getAttribute('src') || \"\";\n this.alias = this.getAttribute('alias') || this.source;\n axios.get(this.source).then(result => {\n this.load(result.data);\n });\n }\n load(content) {\n this.context = new DoricContext(content);\n this.context.getEntityMethod('log')();\n }\n}\n","import { DoricElement } from './src/DoricElement';\nwindow.customElements.define('doric-div', DoricElement);\n"],"names":["jsCallResolve","jsCallReject","jsObtainContext"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AY,CAAC,CAAC;;;;"} \ No newline at end of file diff --git a/rollup.config.js b/rollup.config.js index 166b5911..7fa9e196 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -14,7 +14,7 @@ ${sandboxBundle} /**--------SandBox--------*/ /**++++++++Lib++++++++*/ -Reflect.apply(doric.jsRegisterModule,this,[doric,Reflect.apply(function(__module){(function(module,exports,require){ +Reflect.apply(doric.jsRegisterModule,this,["doric",Reflect.apply(function(__module){(function(module,exports,require){ ${doricLibBundle} })(__module,__module.exports,doric.__require__); return __module.exports; diff --git a/src/DoricContext.ts b/src/DoricContext.ts index ea96e982..a4db18d2 100644 --- a/src/DoricContext.ts +++ b/src/DoricContext.ts @@ -1,16 +1,35 @@ +import { jsObtainContext } from 'doric/src/runtime/sandbox' +import { Panel } from 'doric' import { DoricPlugin } from "./DoricPlugin" - +import { createContext } from "./DoricDriver" const doricContexts: Map = new Map +let __contextId__ = 0 +function getContextId() { + return `context_${__contextId__++}` +} + export function getDoricContext(contextId: string) { return doricContexts.get(contextId) } export class DoricContext { - contextId: string + contextId = getContextId() pluginInstances: Map = new Map - constructor(contextId: string) { - this.contextId = contextId - doricContexts.set(contextId, this) + constructor(content: string) { + createContext(this.contextId, content) + doricContexts.set(this.contextId, this) } + get context() { + return jsObtainContext(this.contextId) + } + + get panel() { + return this.context?.entity as Panel + } + + getEntityMethod(method: string) { + return Reflect.get(this.panel, method, this.panel) as Function + } + } \ No newline at end of file diff --git a/src/DoricDriver.ts b/src/DoricDriver.ts index e7b188d0..eaeac886 100644 --- a/src/DoricDriver.ts +++ b/src/DoricDriver.ts @@ -1,4 +1,4 @@ -import { jsObtainContext, jsCallResolve, jsCallReject } from 'doric/src/runtime/sandbox' +import { jsCallResolve, jsCallReject } from 'doric/src/runtime/sandbox' import { acquireJSBundle, acquirePlugin } from './DoricRegistry' import { getDoricContext } from './DoricContext' import { DoricPlugin } from './DoricPlugin' @@ -9,10 +9,6 @@ function getScriptId() { } -let __contextId__ = 0 -export function getContextId() { - return `context_${__contextId__++}` -} export function injectGlobalObject(name: string, value: any) { Reflect.set(window, name, value, window) @@ -38,7 +34,6 @@ ${content} },doric.jsObtainContext("${contextId}"),[undefined,doric.jsObtainContext("${contextId}"),doric.jsObtainEntry("${contextId}"),doric.__require__,{}])` } - function initDoric() { injectGlobalObject('nativeLog', (type: 'd' | 'w' | 'e', message: string) => { switch (type) { @@ -104,5 +99,8 @@ function initDoric() { }) } +export function createContext(contextId: string, content: string) { + loadJS(packageCreateContext(contextId, content)) +} initDoric() \ No newline at end of file diff --git a/src/DoricElement.ts b/src/DoricElement.ts index a191b9c4..be780e72 100644 --- a/src/DoricElement.ts +++ b/src/DoricElement.ts @@ -1,10 +1,11 @@ import axios from 'axios' -import { getContextId } from './DoricDriver' +import { DoricContext } from './DoricContext' export class DoricElement extends HTMLElement { source: string alias: string + context?: DoricContext constructor() { super() this.source = this.getAttribute('src') || "" @@ -15,11 +16,7 @@ export class DoricElement extends HTMLElement { } load(content: string) { - const script = document.createElement('script'); - const contextId = getContextId(); - script.text = `Reflect.apply(function(doric,context,Entry,require,exports){ - ${content} - },doric.jsObtainContext("${contextId}"),[undefined,doric.jsObtainContext("${contextId}"),doric.jsObtainEntry("${contextId}"),doric.__require__,{}]);` - this.append(script) + this.context = new DoricContext(content) + this.context.getEntityMethod('log')() } } \ No newline at end of file