增加特殊类型null的支持

master 1.11.0
yutent 2023-11-23 10:32:30 +08:00
parent afac6fddb2
commit 47090149f8
3 changed files with 11 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{
"name": "wkit",
"version": "1.10.14",
"version": "1.11.0",
"type": "module",
"description": "A library for building fast, lightweight web components.",
"main": "dist/index.js",

View File

@ -101,7 +101,7 @@ function getType(v) {
return { type, default: v, attribute }
default:
return { type: String, default: v + '' }
return { type: null, default: '' }
}
}
@ -131,6 +131,10 @@ export function parsePropsDeclaration(options) {
options = { type: Array }
break
case String:
options = { type: String }
break
default:
options = getType(options)
break
@ -174,6 +178,9 @@ export function fixedValue(value, options) {
}
}
case null:
return value
default:
return value === null || value === void 0 ? null : value + ''
}

View File

@ -296,7 +296,7 @@ export class Component extends HTMLElement {
let options = this.#getPropOptions(name) || {}
let attrName = options.attrName
if (options.attribute === false) {
if (options.attribute === false || options.type === null) {
this.removeAttribute(attrName)
return
}
@ -340,7 +340,7 @@ export class Component extends HTMLElement {
if (options) {
value = fixedValue(value, options)
if (options.attribute === false) {
if (options.attribute === false || options.type === null) {
if (value === null) {
return
}