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

优化组件slots插槽机制

old
宇天 2018-08-02 16:35:06 +08:00
parent 2edf946c2d
commit 220d67d610
5 changed files with 138 additions and 138 deletions

View File

@ -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) {
switch (elem.nodeType) {
case 1:
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)
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__) {

View File

@ -3765,29 +3765,41 @@
}
}
function parseSlot(collections) {
function parseSlot(collections, vms) {
var arr = aslice.call(collections, 0)
var obj = { __extra__: [] }
arr.forEach(function(elem) {
switch (elem.nodeType) {
case 1:
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)
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__) {

View File

@ -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) {
switch (elem.nodeType) {
case 1:
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)
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__) {

View File

@ -3765,29 +3765,41 @@
}
}
function parseSlot(collections) {
function parseSlot(collections, vms) {
var arr = aslice.call(collections, 0)
var obj = { __extra__: [] }
arr.forEach(function(elem) {
switch (elem.nodeType) {
case 1:
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)
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__) {

View File

@ -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 = `<i class="do-button__icon do-icon-${this.props.icon}"></i>`