diff --git a/runtime/main/app/bundle.ts b/runtime/main/app/bundle.ts index 2782e9c03ca7c61e7c6ef35fd314ada7ef730a28..5ca427fec521255434c0f80aea166131ac3582b1 100644 --- a/runtime/main/app/bundle.ts +++ b/runtime/main/app/bundle.ts @@ -64,7 +64,7 @@ export const defineFn = function(page: Page, packageName: string, name?: string, } }; const moduleContent = { exports: {} }; - parseContent(pageRequire, moduleContent.exports, moduleContent); + parseContent(pageRequire, moduleContent.exports, moduleContent, page.doc); bundleContent = moduleContent.exports; let minPlatformVersion: number = 5; diff --git a/runtime/main/page/entry/bundle.ts b/runtime/main/page/entry/bundle.ts index 3ce8457077a48114a8c5b601d6093df8db0a954d..7f17ebb4bdfc3d122ec3e5e03d322c2f02c7bd21 100644 --- a/runtime/main/page/entry/bundle.ts +++ b/runtime/main/page/entry/bundle.ts @@ -68,7 +68,7 @@ export const defineFn = function(page: Page, name?: string, ...args: any[] | nul return requireModule(appFunction, moduleName); } }; - parseContent(pageRequire, moduleContent.exports, moduleContent); + parseContent(pageRequire, moduleContent.exports, moduleContent, page.doc); bundleContent = moduleContent.exports; } if (isComponent(name)) { diff --git a/runtime/vdom/Element.ts b/runtime/vdom/Element.ts index 0ffac2d4e289808496df96915ddf85be027c8440..b586cfb0a0bcbd6e3153a463be3bb9b8e14c8dfa 100644 --- a/runtime/vdom/Element.ts +++ b/runtime/vdom/Element.ts @@ -473,25 +473,23 @@ class Element extends Node { this.inheritStyle(node, true); const taskCenter = this.getTaskCenter(this.docId); if (taskCenter) { - return taskCenter.send( + taskCenter.send( 'dom', { action: 'addElement' }, [this.ref, element.toJSON(), -1] ); + if (element.children) { + element.children.forEach((child: Element) => { + child.parentNode = null; + element.appendChild(child); + }); + } } } } else { this.moveIndex(node, this.children.length, { changeSibling: true }); if (node.nodeType === Node.NodeType.Element) { - const index = this.moveIndex(node, this.pureChildren.length, { isInPureChildren: true }); - const taskCenter = this.getTaskCenter(this.docId); - if (taskCenter && index >= 0) { - return taskCenter.send( - 'dom', - { action: 'moveElement' }, - [node.ref, this.ref, index] - ); - } + this.moveIndex(node, this.pureChildren.length, { isInPureChildren: true }); } } } @@ -532,32 +530,30 @@ class Element extends Node { this.inheritStyle(node); const taskCenter = this.getTaskCenter(this.docId); if (taskCenter) { - return taskCenter.send( + taskCenter.send( 'dom', { action: 'addElement' }, [this.ref, element.toJSON(), index] ); + if (element.children) { + element.children.forEach((child: Element) => { + child.parentNode = null; + element.appendChild(child); + }); + } } } } else { this.moveIndex(node, this.children.indexOf(before), { changeSibling: true }); if (node.nodeType === Node.NodeType.Element) { const pureBefore = this.nextElement(before); - const index = this.moveIndex( + this.moveIndex( node, pureBefore ? this.pureChildren.indexOf(pureBefore) : this.pureChildren.length, { isInPureChildren: true} ); - const taskCenter = this.getTaskCenter(this.docId); - if (taskCenter && index >= 0) { - return taskCenter.send( - 'dom', - { action: 'moveElement' }, - [node.ref, this.ref, index] - ); - } } } } @@ -592,29 +588,27 @@ class Element extends Node { this.inheritStyle(node); const taskCenter = this.getTaskCenter(this.docId); if (taskCenter) { - return taskCenter.send( + taskCenter.send( 'dom', { action: 'addElement' }, [this.ref, element.toJSON(), index] ); + if (element.children) { + element.children.forEach((child: Element) => { + child.parentNode = null; + element.appendChild(child); + }); + } } } } else { this.moveIndex(node, this.children.indexOf(after) + 1, { changeSibling: true}); if (node.nodeType === Node.NodeType.Element) { - const index = this.moveIndex( + this.moveIndex( node, this.pureChildren.indexOf(this.previousElement(after)) + 1, { isInPureChildren: true } ); - const taskCenter = this.getTaskCenter(this.docId); - if (taskCenter && index >= 0) { - return taskCenter.send( - 'dom', - { action: 'moveElement' }, - [node.ref, this.ref, index] - ); - } } } } @@ -837,37 +831,28 @@ class Element extends Node { * @param {Function} handler - Event handler. * @param {Object} [params] - Event parameters. */ - public addEvent(type: string, handler?: Function, params?: any): void { + public addEvent(type: string, handler?: Function, params?: any): void { if (!this._event) { this._event = {}; } - if (!this._event[type]) { - this._event[type] = { handler, params }; - const taskCenter = this.getTaskCenter(this.docId); - if (taskCenter) { - taskCenter.send( - 'dom', - { action: 'addEvent' }, - [this.ref, type] - ); - } + if (this._event[type]) { + this._event[type].push({ handler, params }); + } else { + this._event[type] = [{ handler, params }]; } } /** * Remove an event handler. * @param {string} type - Event name + * @param {FUnction} handler - Event handler */ - public removeEvent(type: string): void { + public removeEvent(type: string, handler?: Function): void { if (this._event && this._event[type]) { - delete this._event[type]; - const taskCenter = this.getTaskCenter(this.docId); - if (taskCenter) { - taskCenter.send( - 'dom', - { action: 'removeEvent' }, - [this.ref, type] - ); + if (handler) { + this._event[type] = this.event[type].filter(cb => cb.handler != handler); + } else { + delete this._event[type]; } } } @@ -887,19 +872,21 @@ class Element extends Node { 'touchmove', 'touchend', 'panstart', 'panmove', 'panend', 'horizontalpan', 'verticalpan', 'swipe' ]; - let result = null; + const result = []; let isStopPropagation = false; const eventDesc = this._event[type]; if (eventDesc && event) { - const handler = eventDesc.handler; event.stopPropagation = () => { isStopPropagation = true; }; - if (options && options.params) { - result = handler.call(this, event, ...options.params); - } else { - result = handler.call(this, event); - } + eventDesc.forEach(cb => { + const handler = cb.handler; + if (options && options.params) { + result.push(handler.call(this, event, ...options.params)); + } else { + result.push(handler.call(this, event)); + } + }); } if (!isStopPropagation && isBubble && BUBBLE_EVENTS.indexOf(type) !== -1) { @@ -910,7 +897,7 @@ class Element extends Node { } } - return result; + return result.length ? result : null; } /**