增加特殊类型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", "name": "wkit",
"version": "1.10.14", "version": "1.11.0",
"type": "module", "type": "module",
"description": "A library for building fast, lightweight web components.", "description": "A library for building fast, lightweight web components.",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -101,7 +101,7 @@ function getType(v) {
return { type, default: v, attribute } return { type, default: v, attribute }
default: default:
return { type: String, default: v + '' } return { type: null, default: '' }
} }
} }
@ -131,6 +131,10 @@ export function parsePropsDeclaration(options) {
options = { type: Array } options = { type: Array }
break break
case String:
options = { type: String }
break
default: default:
options = getType(options) options = getType(options)
break break
@ -174,6 +178,9 @@ export function fixedValue(value, options) {
} }
} }
case null:
return value
default: default:
return value === null || value === void 0 ? null : value + '' 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 options = this.#getPropOptions(name) || {}
let attrName = options.attrName let attrName = options.attrName
if (options.attribute === false) { if (options.attribute === false || options.type === null) {
this.removeAttribute(attrName) this.removeAttribute(attrName)
return return
} }
@ -340,7 +340,7 @@ export class Component extends HTMLElement {
if (options) { if (options) {
value = fixedValue(value, options) value = fixedValue(value, options)
if (options.attribute === false) { if (options.attribute === false || options.type === null) {
if (value === null) { if (value === null) {
return return
} }