diff --git a/src/form/checkbox.wc b/src/form/checkbox.wc index 607716a..21ef8d6 100644 --- a/src/form/checkbox.wc +++ b/src/form/checkbox.wc @@ -26,17 +26,21 @@ export default class CheckboxGroup { _updateChildrenStat(checkAll) { Array.from(this.children).forEach(it => { - if (it.tagName === 'WC-CHECKBOX' && it.root) { - if (checkAll) { - it.disabled = this.disabled - it.readOnly = this.readOnly - } + if (it.tagName === 'WC-CHECKBOX') { + if (it.root) { + if (checkAll) { + it.disabled = this.disabled + it.readOnly = this.readOnly + } - if (this.value.includes(it.value)) { - it.checked = true - } else { - it.checked = false + if (this.value.includes(it.value)) { + it.checked = true + } else { + it.checked = false + } } + } else { + it.remove() } }) } diff --git a/src/form/dropdown.wc b/src/form/dropdown.wc index 1476a86..63cc886 100644 --- a/src/form/dropdown.wc +++ b/src/form/dropdown.wc @@ -167,13 +167,17 @@ export default class Dropdown { _updateChildrenStat() { Array.from(this.children).forEach(it => { - if (it.tagName === 'WC-OPTION' && it.root) { - if (it.value === this.props.value) { - it.setAttribute('active', '') - this.__INPUT__.value = it.label || it.textContent - } else { - it.removeAttribute('active') + if (it.tagName === 'WC-OPTION') { + if (it.root) { + if (it.value === this.props.value) { + it.setAttribute('active', '') + this.__INPUT__.value = it.label || it.textContent + } else { + it.removeAttribute('active') + } } + } else { + it.remove() } }) } diff --git a/src/form/radio.wc b/src/form/radio.wc index 3ce7a82..59b5697 100644 --- a/src/form/radio.wc +++ b/src/form/radio.wc @@ -26,17 +26,21 @@ export default class RadioGroup { _updateChildrenStat(checkAll) { Array.from(this.children).forEach(it => { - if (it.tagName === 'WC-RADIO' && it.root) { - if (checkAll) { - it.disabled = this.disabled - it.readOnly = this.readOnly - } + if (it.tagName === 'WC-RADIO') { + if (it.root) { + if (checkAll) { + it.disabled = this.disabled + it.readOnly = this.readOnly + } - if (it.value === this.props.value) { - it.checked = true - } else { - it.checked = false + if (it.value === this.props.value) { + it.checked = true + } else { + it.checked = false + } } + } else { + it.remove() } }) } diff --git a/src/markd/core.js b/src/markd/core.js index 0811116..b9448b7 100644 --- a/src/markd/core.js +++ b/src/markd/core.js @@ -27,6 +27,11 @@ const INLINE = { qlist: /((
)*?)([\+\-\*]|\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 = { // 是否分割线 isHr(str) { @@ -165,20 +170,20 @@ function fixed(str) { .replace(/\u2424/g, '\n') .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) => { - return `<${tag + attr}>${txt.replace(/\n/g, '⨨⤶')}` + return `<${tag + attr}>${txt.replace(/\n/g, NODE_BR_SYMBOL)}` }) .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 + '```' }) .replace(BLOCK_RE, (m, tag, attr, txt) => { - return `<${tag + attr.replace(/(⨨☇)+/g, ' ')}>${txt - .replace(/⨨⤶/g, '\n') - .replace(/(⨨☇)+/g, ' ')}` + return `<${tag + attr.replace(ATTR_BR_EXP, ' ')}>${txt + .replace(NODE_BR_EXP, '\n') + .replace(ATTR_BR_EXP, ' ')}` }) }