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

优化markd解析换行;优化单选复选的子节点过滤

old
宇天 2021-05-24 11:43:20 +08:00
parent a4bfa07649
commit c7e8da83e9
4 changed files with 47 additions and 30 deletions

View File

@ -26,7 +26,8 @@ export default class CheckboxGroup {
_updateChildrenStat(checkAll) { _updateChildrenStat(checkAll) {
Array.from(this.children).forEach(it => { Array.from(this.children).forEach(it => {
if (it.tagName === 'WC-CHECKBOX' && it.root) { if (it.tagName === 'WC-CHECKBOX') {
if (it.root) {
if (checkAll) { if (checkAll) {
it.disabled = this.disabled it.disabled = this.disabled
it.readOnly = this.readOnly it.readOnly = this.readOnly
@ -38,6 +39,9 @@ export default class CheckboxGroup {
it.checked = false it.checked = false
} }
} }
} else {
it.remove()
}
}) })
} }

View File

@ -167,7 +167,8 @@ export default class Dropdown {
_updateChildrenStat() { _updateChildrenStat() {
Array.from(this.children).forEach(it => { Array.from(this.children).forEach(it => {
if (it.tagName === 'WC-OPTION' && it.root) { if (it.tagName === 'WC-OPTION') {
if (it.root) {
if (it.value === this.props.value) { if (it.value === this.props.value) {
it.setAttribute('active', '') it.setAttribute('active', '')
this.__INPUT__.value = it.label || it.textContent this.__INPUT__.value = it.label || it.textContent
@ -175,6 +176,9 @@ export default class Dropdown {
it.removeAttribute('active') it.removeAttribute('active')
} }
} }
} else {
it.remove()
}
}) })
} }

View File

@ -26,7 +26,8 @@ export default class RadioGroup {
_updateChildrenStat(checkAll) { _updateChildrenStat(checkAll) {
Array.from(this.children).forEach(it => { Array.from(this.children).forEach(it => {
if (it.tagName === 'WC-RADIO' && it.root) { if (it.tagName === 'WC-RADIO') {
if (it.root) {
if (checkAll) { if (checkAll) {
it.disabled = this.disabled it.disabled = this.disabled
it.readOnly = this.readOnly it.readOnly = this.readOnly
@ -38,6 +39,9 @@ export default class RadioGroup {
it.checked = false it.checked = false
} }
} }
} else {
it.remove()
}
}) })
} }

View File

@ -27,6 +27,11 @@ const INLINE = {
qlist: /((<blockquote class="md\-quote">)*?)([\+\-\*]|\d+\.) (.*)/ // 引用中的列表 qlist: /((<blockquote class="md\-quote">)*?)([\+\-\*]|\d+\.) (.*)/ // 引用中的列表
} }
const ATTR_BR_SYMBOL = '⨨☇'
const NODE_BR_SYMBOL = '⨨⤶'
const ATTR_BR_EXP = new RegExp(ATTR_BR_SYMBOL, 'g')
const NODE_BR_EXP = new RegExp(NODE_BR_SYMBOL, 'g')
const Helper = { const Helper = {
// 是否分割线 // 是否分割线
isHr(str) { isHr(str) {
@ -165,20 +170,20 @@ function fixed(str) {
.replace(/\u2424/g, '\n') .replace(/\u2424/g, '\n')
.replace(TAG_RE, (m, name, attr) => { .replace(TAG_RE, (m, name, attr) => {
// 标签内的换行, 转为一组特殊字符, 方便后面还原 // 标签内的换行, 转为一组特殊字符, 方便后面还原
return `<${name + attr.replace(/\n/g, '⨨☇')}>` return `<${name + attr.replace(/\n/g, ATTR_BR_SYMBOL)}>`
}) })
.replace(BLOCK_RE, (m, tag, attr, txt) => { .replace(BLOCK_RE, (m, tag, attr, txt) => {
return `<${tag + attr}>${txt.replace(/\n/g, '⨨⤶')}</${tag}>` return `<${tag + attr}>${txt.replace(/\n/g, NODE_BR_SYMBOL)}</${tag}>`
}) })
.replace(CODEBLOCK_RE, (m, lang, txt) => { .replace(CODEBLOCK_RE, (m, lang, txt) => {
// 还原换行 // 还原换行
let rollback = txt.replace(/⨨⤶/g, '\n').replace(/⨨☇/g, '\n') let rollback = txt.replace(NODE_BR_EXP, '\n').replace(ATTR_BR_EXP, '\n')
return '```' + lang + rollback + '```' return '```' + lang + rollback + '```'
}) })
.replace(BLOCK_RE, (m, tag, attr, txt) => { .replace(BLOCK_RE, (m, tag, attr, txt) => {
return `<${tag + attr.replace(/(⨨☇)+/g, ' ')}>${txt return `<${tag + attr.replace(ATTR_BR_EXP, ' ')}>${txt
.replace(/⨨⤶/g, '\n') .replace(NODE_BR_EXP, '\n')
.replace(/(⨨☇)+/g, ' ')}</${tag}>` .replace(ATTR_BR_EXP, ' ')}</${tag}>`
}) })
} }