This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues/pull-requests.
bytedo
/
wcui
Archived
1
0
Fork 0

优化组件机制,更加完善的slot和普通节点;

old
宇天 2018-06-15 15:14:24 +08:00
parent 6ad4c35194
commit 9c54ccd5a6
5 changed files with 173 additions and 45 deletions

View File

@ -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', {

View File

@ -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', {

View File

@ -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', {

View File

@ -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', {

View File

@ -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')