From 220d67d610741ef99d8446abc20c60a789b48fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Thu, 2 Aug 2018 16:35:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BB=84=E4=BB=B6slots?= =?UTF-8?q?=E6=8F=92=E6=A7=BD=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/js/anot-touch.js | 68 +++++++++++++++++++-------------------- src/js/anot-touch.shim.js | 68 +++++++++++++++++++-------------------- src/js/anot.js | 68 +++++++++++++++++++-------------------- src/js/anot.shim.js | 68 +++++++++++++++++++-------------------- src/js/form/index.js | 4 +-- 5 files changed, 138 insertions(+), 138 deletions(-) diff --git a/src/js/anot-touch.js b/src/js/anot-touch.js index cdee266..5d8672f 100644 --- a/src/js/anot-touch.js +++ b/src/js/anot-touch.js @@ -3750,29 +3750,41 @@ const _Anot = (function() { } } - function parseSlot(collections) { + function parseSlot(collections, vms) { var arr = aslice.call(collections, 0) var obj = { __extra__: [] } arr.forEach(function(elem) { - var slot = elem.getAttribute('slot') - if (isWidget(elem)) { - obj.__extra__.push(elem) - } else { - if (slot) { - obj[slot] = obj[slot] || [] - elem.removeAttribute('slot') - obj[slot].push(elem.outerHTML) - } else { - if ( - rexpr.test(elem.outerHTML) || - /:[\w-]*=".*"/.test(elem.outerHTML) - ) { - return - } - obj.__extra__.push(elem) - } - } + switch (elem.nodeType) { + case 1: + var slot = elem.getAttribute('slot') + if (slot) { + obj[slot] = obj[slot] || [] + elem.removeAttribute('slot') + obj[slot].push(elem.outerHTML) + } else { + var txt = elem.outerHTML + if (isWidget(elem) || /:[\w-]*=".*"/.test(txt)) { + break + } + if (rexpr.test(txt)) { + var expr = normalizeExpr(txt) + txt = parseExpr(expr, vms, {}).apply(0, vms) + } + + obj.__extra__.push(txt) + } + + break + case 3: + var txt = elem.textContent.trim() + if (txt) { + obj.__extra__.push(txt) + } + break + default: + break + } elem.parentNode.removeChild(elem) }) return obj @@ -3827,8 +3839,9 @@ const _Anot = (function() { while (parentVm.$up && parentVm.$up.__WIDGET__ === name) { parentVm = parentVm.$up } - if (elem.firstElementChild) { - slots = parseSlot(elem.children) + + if (elem.childNodes.length) { + slots = parseSlot(elem.childNodes, host.vmodels) } if (props.hasOwnProperty(':disabled')) { @@ -3927,22 +3940,9 @@ const _Anot = (function() { Object.assign(hooks.state, state) var __READY__ = false - elem.parseExpr = function(str) { - str = str.trim() - var expr = normalizeExpr(str) - if (expr === str) { - return str - } - try { - return parseExpr(expr, host.vmodels, {}).apply(0, host.vmodels) - } catch (err) { - return str - } - } hooks.__init__.call(elem, hooks.props, hooks.state, function next() { __READY__ = true - delete elem.parseExpr }) if (!__READY__) { diff --git a/src/js/anot-touch.shim.js b/src/js/anot-touch.shim.js index 517e9ec..10cc6fc 100644 --- a/src/js/anot-touch.shim.js +++ b/src/js/anot-touch.shim.js @@ -3765,29 +3765,41 @@ } } - function parseSlot(collections) { + function parseSlot(collections, vms) { var arr = aslice.call(collections, 0) var obj = { __extra__: [] } arr.forEach(function(elem) { - var slot = elem.getAttribute('slot') - if (isWidget(elem)) { - obj.__extra__.push(elem) - } else { - if (slot) { - obj[slot] = obj[slot] || [] - elem.removeAttribute('slot') - obj[slot].push(elem.outerHTML) - } else { - if ( - rexpr.test(elem.outerHTML) || - /:[\w-]*=".*"/.test(elem.outerHTML) - ) { - return - } - obj.__extra__.push(elem) - } - } + switch (elem.nodeType) { + case 1: + var slot = elem.getAttribute('slot') + if (slot) { + obj[slot] = obj[slot] || [] + elem.removeAttribute('slot') + obj[slot].push(elem.outerHTML) + } else { + var txt = elem.outerHTML + if (isWidget(elem) || /:[\w-]*=".*"/.test(txt)) { + break + } + if (rexpr.test(txt)) { + var expr = normalizeExpr(txt) + txt = parseExpr(expr, vms, {}).apply(0, vms) + } + + obj.__extra__.push(txt) + } + + break + case 3: + var txt = elem.textContent.trim() + if (txt) { + obj.__extra__.push(txt) + } + break + default: + break + } elem.parentNode.removeChild(elem) }) return obj @@ -3842,8 +3854,9 @@ while (parentVm.$up && parentVm.$up.__WIDGET__ === name) { parentVm = parentVm.$up } - if (elem.firstElementChild) { - slots = parseSlot(elem.children) + + if (elem.childNodes.length) { + slots = parseSlot(elem.childNodes, host.vmodels) } if (props.hasOwnProperty(':disabled')) { @@ -3942,22 +3955,9 @@ Object.assign(hooks.state, state) var __READY__ = false - elem.parseExpr = function(str) { - str = str.trim() - var expr = normalizeExpr(str) - if (expr === str) { - return str - } - try { - return parseExpr(expr, host.vmodels, {}).apply(0, host.vmodels) - } catch (err) { - return str - } - } hooks.__init__.call(elem, hooks.props, hooks.state, function next() { __READY__ = true - delete elem.parseExpr }) if (!__READY__) { diff --git a/src/js/anot.js b/src/js/anot.js index e13dba0..0acb488 100644 --- a/src/js/anot.js +++ b/src/js/anot.js @@ -3750,29 +3750,41 @@ const _Anot = (function() { } } - function parseSlot(collections) { + function parseSlot(collections, vms) { var arr = aslice.call(collections, 0) var obj = { __extra__: [] } arr.forEach(function(elem) { - var slot = elem.getAttribute('slot') - if (isWidget(elem)) { - obj.__extra__.push(elem) - } else { - if (slot) { - obj[slot] = obj[slot] || [] - elem.removeAttribute('slot') - obj[slot].push(elem.outerHTML) - } else { - if ( - rexpr.test(elem.outerHTML) || - /:[\w-]*=".*"/.test(elem.outerHTML) - ) { - return - } - obj.__extra__.push(elem) - } - } + switch (elem.nodeType) { + case 1: + var slot = elem.getAttribute('slot') + if (slot) { + obj[slot] = obj[slot] || [] + elem.removeAttribute('slot') + obj[slot].push(elem.outerHTML) + } else { + var txt = elem.outerHTML + if (isWidget(elem) || /:[\w-]*=".*"/.test(txt)) { + break + } + if (rexpr.test(txt)) { + var expr = normalizeExpr(txt) + txt = parseExpr(expr, vms, {}).apply(0, vms) + } + + obj.__extra__.push(txt) + } + + break + case 3: + var txt = elem.textContent.trim() + if (txt) { + obj.__extra__.push(txt) + } + break + default: + break + } elem.parentNode.removeChild(elem) }) return obj @@ -3827,8 +3839,9 @@ const _Anot = (function() { while (parentVm.$up && parentVm.$up.__WIDGET__ === name) { parentVm = parentVm.$up } - if (elem.firstElementChild) { - slots = parseSlot(elem.children) + + if (elem.childNodes.length) { + slots = parseSlot(elem.childNodes, host.vmodels) } if (props.hasOwnProperty(':disabled')) { @@ -3927,22 +3940,9 @@ const _Anot = (function() { Object.assign(hooks.state, state) var __READY__ = false - elem.parseExpr = function(str) { - str = str.trim() - var expr = normalizeExpr(str) - if (expr === str) { - return str - } - try { - return parseExpr(expr, host.vmodels, {}).apply(0, host.vmodels) - } catch (err) { - return str - } - } hooks.__init__.call(elem, hooks.props, hooks.state, function next() { __READY__ = true - delete elem.parseExpr }) if (!__READY__) { diff --git a/src/js/anot.shim.js b/src/js/anot.shim.js index 6bbe7c8..dd8f15f 100644 --- a/src/js/anot.shim.js +++ b/src/js/anot.shim.js @@ -3765,29 +3765,41 @@ } } - function parseSlot(collections) { + function parseSlot(collections, vms) { var arr = aslice.call(collections, 0) var obj = { __extra__: [] } arr.forEach(function(elem) { - var slot = elem.getAttribute('slot') - if (isWidget(elem)) { - obj.__extra__.push(elem) - } else { - if (slot) { - obj[slot] = obj[slot] || [] - elem.removeAttribute('slot') - obj[slot].push(elem.outerHTML) - } else { - if ( - rexpr.test(elem.outerHTML) || - /:[\w-]*=".*"/.test(elem.outerHTML) - ) { - return - } - obj.__extra__.push(elem) - } - } + switch (elem.nodeType) { + case 1: + var slot = elem.getAttribute('slot') + if (slot) { + obj[slot] = obj[slot] || [] + elem.removeAttribute('slot') + obj[slot].push(elem.outerHTML) + } else { + var txt = elem.outerHTML + if (isWidget(elem) || /:[\w-]*=".*"/.test(txt)) { + break + } + if (rexpr.test(txt)) { + var expr = normalizeExpr(txt) + txt = parseExpr(expr, vms, {}).apply(0, vms) + } + + obj.__extra__.push(txt) + } + + break + case 3: + var txt = elem.textContent.trim() + if (txt) { + obj.__extra__.push(txt) + } + break + default: + break + } elem.parentNode.removeChild(elem) }) return obj @@ -3842,8 +3854,9 @@ while (parentVm.$up && parentVm.$up.__WIDGET__ === name) { parentVm = parentVm.$up } - if (elem.firstElementChild) { - slots = parseSlot(elem.children) + + if (elem.childNodes.length) { + slots = parseSlot(elem.childNodes, host.vmodels) } if (props.hasOwnProperty(':disabled')) { @@ -3942,22 +3955,9 @@ Object.assign(hooks.state, state) var __READY__ = false - elem.parseExpr = function(str) { - str = str.trim() - var expr = normalizeExpr(str) - if (expr === str) { - return str - } - try { - return parseExpr(expr, host.vmodels, {}).apply(0, host.vmodels) - } catch (err) { - return str - } - } hooks.__init__.call(elem, hooks.props, hooks.state, function next() { __READY__ = true - delete elem.parseExpr }) if (!__READY__) { diff --git a/src/js/form/index.js b/src/js/form/index.js index d0efa65..48c3e83 100644 --- a/src/js/form/index.js +++ b/src/js/form/index.js @@ -12,7 +12,6 @@ Anot.ui.form = '0.1.0' // 按钮 Anot.component('button', { __init__(props, state, next) { - state.text = this.parseExpr(this.textContent) state.style = { 'border-radius': props.radius } this.classList.add('do-fn-noselect') this.classList.add('do-button') @@ -33,7 +32,8 @@ Anot.component('button', { next() }, - render() { + render(slots) { + this.text = slots.__extra__.join('') let icon = '' if (this.props.icon) { icon = ``