diff --git a/src/js/anot-touch.js b/src/js/anot-touch.js index 26f5f23..7e2feb7 100644 --- a/src/js/anot-touch.js +++ b/src/js/anot-touch.js @@ -3758,14 +3758,28 @@ const _Anot = (function() { function parseSlot(collections) { var arr = aslice.call(collections, 0) - var obj = {} + var obj = { __extra__: [] } arr.forEach(function(elem) { var slot = elem.getAttribute('slot') - if (slot) { - obj[slot] = obj[slot] || [] - elem.removeAttribute('slot') - obj[slot].push(elem.outerHTML) + 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) + } } + + elem.parentNode.removeChild(elem) }) return obj } @@ -3801,6 +3815,11 @@ const _Anot = (function() { var props = getOptionsFromTag(elem, host.vmodels) var $id = props.uuid || generateID(widget) var __willpush__ = null + var slots = null + + if (elem.firstElementChild) { + slots = parseSlot(elem.children) + } if (props.hasOwnProperty('hostPush')) { elem.removeAttribute('host-push') @@ -3860,9 +3879,22 @@ 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__) { @@ -3901,12 +3933,6 @@ const _Anot = (function() { componentWillMount.call(vmodel) globalHooks.componentWillMount.call(null, vmodel) - var slots = null - - if (elem.firstElementChild) { - slots = parseSlot(elem.children) - } - Anot.clearHTML(elem) var html = render.call(vmodel, slots) || '' @@ -3916,6 +3942,12 @@ const _Anot = (function() { elem.innerHTML = html + if (slots && slots.__extra__.length) { + try { + elem.appendChild.apply(elem, slots.__extra__) + } catch (err) {} + } + hideProperty(vmodel, '$elem', elem) Anot.fireDom(elem, 'datasetchanged', { diff --git a/src/js/anot-touch.shim.js b/src/js/anot-touch.shim.js index 1e80b76..c3b668c 100644 --- a/src/js/anot-touch.shim.js +++ b/src/js/anot-touch.shim.js @@ -3773,14 +3773,28 @@ function parseSlot(collections) { var arr = aslice.call(collections, 0) - var obj = {} + var obj = { __extra__: [] } arr.forEach(function(elem) { var slot = elem.getAttribute('slot') - if (slot) { - obj[slot] = obj[slot] || [] - elem.removeAttribute('slot') - obj[slot].push(elem.outerHTML) + 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) + } } + + elem.parentNode.removeChild(elem) }) return obj } @@ -3816,6 +3830,11 @@ var props = getOptionsFromTag(elem, host.vmodels) var $id = props.uuid || generateID(widget) var __willpush__ = null + var slots = null + + if (elem.firstElementChild) { + slots = parseSlot(elem.children) + } if (props.hasOwnProperty('hostPush')) { elem.removeAttribute('host-push') @@ -3875,9 +3894,22 @@ 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__) { @@ -3916,12 +3948,6 @@ componentWillMount.call(vmodel) globalHooks.componentWillMount.call(null, vmodel) - var slots = null - - if (elem.firstElementChild) { - slots = parseSlot(elem.children) - } - Anot.clearHTML(elem) var html = render.call(vmodel, slots) || '' @@ -3931,6 +3957,12 @@ elem.innerHTML = html + if (slots && slots.__extra__.length) { + try { + elem.appendChild.apply(elem, slots.__extra__) + } catch (err) {} + } + hideProperty(vmodel, '$elem', elem) Anot.fireDom(elem, 'datasetchanged', { diff --git a/src/js/anot.js b/src/js/anot.js index f61b4ed..7cb4665 100644 --- a/src/js/anot.js +++ b/src/js/anot.js @@ -3758,14 +3758,28 @@ const _Anot = (function() { function parseSlot(collections) { var arr = aslice.call(collections, 0) - var obj = {} + var obj = { __extra__: [] } arr.forEach(function(elem) { var slot = elem.getAttribute('slot') - if (slot) { - obj[slot] = obj[slot] || [] - elem.removeAttribute('slot') - obj[slot].push(elem.outerHTML) + 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) + } } + + elem.parentNode.removeChild(elem) }) return obj } @@ -3801,6 +3815,11 @@ const _Anot = (function() { var props = getOptionsFromTag(elem, host.vmodels) var $id = props.uuid || generateID(widget) var __willpush__ = null + var slots = null + + if (elem.firstElementChild) { + slots = parseSlot(elem.children) + } if (props.hasOwnProperty('hostPush')) { elem.removeAttribute('host-push') @@ -3860,9 +3879,22 @@ 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__) { @@ -3901,12 +3933,6 @@ const _Anot = (function() { componentWillMount.call(vmodel) globalHooks.componentWillMount.call(null, vmodel) - var slots = null - - if (elem.firstElementChild) { - slots = parseSlot(elem.children) - } - Anot.clearHTML(elem) var html = render.call(vmodel, slots) || '' @@ -3916,6 +3942,12 @@ const _Anot = (function() { elem.innerHTML = html + if (slots && slots.__extra__.length) { + try { + elem.appendChild.apply(elem, slots.__extra__) + } catch (err) {} + } + hideProperty(vmodel, '$elem', elem) Anot.fireDom(elem, 'datasetchanged', { diff --git a/src/js/anot.shim.js b/src/js/anot.shim.js index c2c3e5b..9d29ecc 100644 --- a/src/js/anot.shim.js +++ b/src/js/anot.shim.js @@ -3773,14 +3773,28 @@ function parseSlot(collections) { var arr = aslice.call(collections, 0) - var obj = {} + var obj = { __extra__: [] } arr.forEach(function(elem) { var slot = elem.getAttribute('slot') - if (slot) { - obj[slot] = obj[slot] || [] - elem.removeAttribute('slot') - obj[slot].push(elem.outerHTML) + 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) + } } + + elem.parentNode.removeChild(elem) }) return obj } @@ -3816,6 +3830,11 @@ var props = getOptionsFromTag(elem, host.vmodels) var $id = props.uuid || generateID(widget) var __willpush__ = null + var slots = null + + if (elem.firstElementChild) { + slots = parseSlot(elem.children) + } if (props.hasOwnProperty('hostPush')) { elem.removeAttribute('host-push') @@ -3875,9 +3894,22 @@ 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__) { @@ -3916,12 +3948,6 @@ componentWillMount.call(vmodel) globalHooks.componentWillMount.call(null, vmodel) - var slots = null - - if (elem.firstElementChild) { - slots = parseSlot(elem.children) - } - Anot.clearHTML(elem) var html = render.call(vmodel, slots) || '' @@ -3931,6 +3957,12 @@ elem.innerHTML = html + if (slots && slots.__extra__.length) { + try { + elem.appendChild.apply(elem, slots.__extra__) + } catch (err) {} + } + hideProperty(vmodel, '$elem', elem) Anot.fireDom(elem, 'datasetchanged', { diff --git a/src/js/form/index.js b/src/js/form/index.js index d3dd19f..7ca3790 100644 --- a/src/js/form/index.js +++ b/src/js/form/index.js @@ -12,7 +12,7 @@ Anot.ui.form = '0.1.0' // 按钮 Anot.component('button', { __init__(props, state, next) { - state.text = this.textContent + state.text = this.parseExpr(this.textContent) state.style = { 'border-radius': props.radius } this.classList.add('do-fn-noselect') this.classList.add('do-button')