parent
85d4dbd6a2
commit
aa62c3f5b6
11
package.json
11
package.json
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@bd/core",
|
"name": "@bd/core",
|
||||||
"version": "0.2.0",
|
"version": "1.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "百搭UI组件库的核心",
|
"description": "百搭UI组件库的核心",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
@ -15,10 +15,11 @@
|
||||||
"url": "git+https://github.com/bd-js/core.git"
|
"url": "git+https://github.com/bd-js/core.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"nine.",
|
"bd.js",
|
||||||
"ninejs",
|
"bdjs",
|
||||||
"nine-ui",
|
"bd-ui",
|
||||||
"nine-core"
|
"wcui",
|
||||||
|
"bd-core"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"esbuild": "^0.17.11"
|
"esbuild": "^0.17.11"
|
||||||
|
|
33
src/html.js
33
src/html.js
|
@ -25,8 +25,7 @@ var boundAttributeSuffix = '$wc$'
|
||||||
var marker = `wc$${String(Math.random()).slice(9)}$`
|
var marker = `wc$${String(Math.random()).slice(9)}$`
|
||||||
var markerMatch = '?' + marker
|
var markerMatch = '?' + marker
|
||||||
var nodeMarker = `<${markerMatch}>`
|
var nodeMarker = `<${markerMatch}>`
|
||||||
var d = document
|
var createMarker = (v = '') => document.createComment(v)
|
||||||
var createMarker = (v = '') => d.createComment(v)
|
|
||||||
var isPrimitive = value =>
|
var isPrimitive = value =>
|
||||||
value === null || (typeof value != 'object' && typeof value != 'function')
|
value === null || (typeof value != 'object' && typeof value != 'function')
|
||||||
var isArray = Array.isArray
|
var isArray = Array.isArray
|
||||||
|
@ -66,7 +65,7 @@ var ELEMENT_PART = 6
|
||||||
var COMMENT_PART = 7
|
var COMMENT_PART = 7
|
||||||
|
|
||||||
var templateCache = new WeakMap()
|
var templateCache = new WeakMap()
|
||||||
var walker = d.createTreeWalker(d, 129, null, false)
|
var walker = document.createTreeWalker(document, 129, null, false)
|
||||||
var sanitizerFactoryInternal = noopSanitizer
|
var sanitizerFactoryInternal = noopSanitizer
|
||||||
var getTemplateHtml = (strings, type) => {
|
var getTemplateHtml = (strings, type) => {
|
||||||
const len = strings.length - 1
|
const len = strings.length - 1
|
||||||
|
@ -246,7 +245,7 @@ class Template {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static createElement(html2, _options) {
|
static createElement(html2, _options) {
|
||||||
const el = d.createElement('template')
|
let el = document.createElement('template')
|
||||||
el.innerHTML = html2
|
el.innerHTML = html2
|
||||||
return el
|
return el
|
||||||
}
|
}
|
||||||
|
@ -309,24 +308,21 @@ class TemplateInstance {
|
||||||
return this._$parent._$isConnected
|
return this._$parent._$isConnected
|
||||||
}
|
}
|
||||||
_clone(options) {
|
_clone(options) {
|
||||||
var _a4
|
let {
|
||||||
const {
|
|
||||||
el: { content },
|
el: { content },
|
||||||
parts
|
parts
|
||||||
} = this._$template
|
} = this._$template
|
||||||
const fragment = (
|
|
||||||
(_a4 =
|
let fragment = (options?.creationScope || document).importNode(
|
||||||
options === null || options === void 0
|
content,
|
||||||
? void 0
|
true
|
||||||
: options.creationScope) !== null && _a4 !== void 0
|
)
|
||||||
? _a4
|
|
||||||
: d
|
|
||||||
).importNode(content, true)
|
|
||||||
walker.currentNode = fragment
|
walker.currentNode = fragment
|
||||||
let node = walker.nextNode()
|
let node = walker.nextNode()
|
||||||
let nodeIndex = 0
|
let nodeIndex = 0
|
||||||
let partIndex = 0
|
let partIndex = 0
|
||||||
let templatePart = parts[0]
|
let templatePart = parts[0]
|
||||||
|
|
||||||
while (templatePart !== void 0) {
|
while (templatePart !== void 0) {
|
||||||
if (nodeIndex === templatePart.index) {
|
if (nodeIndex === templatePart.index) {
|
||||||
let part
|
let part
|
||||||
|
@ -375,7 +371,6 @@ class TemplateInstance {
|
||||||
}
|
}
|
||||||
class ChildPart {
|
class ChildPart {
|
||||||
constructor(startNode, endNode, parent, options) {
|
constructor(startNode, endNode, parent, options) {
|
||||||
var _a4
|
|
||||||
this.type = CHILD_PART
|
this.type = CHILD_PART
|
||||||
this._$committedValue = NOTHING
|
this._$committedValue = NOTHING
|
||||||
this._$disconnectableChildren = void 0
|
this._$disconnectableChildren = void 0
|
||||||
|
@ -471,7 +466,7 @@ class ChildPart {
|
||||||
|
|
||||||
textNode.data = value
|
textNode.data = value
|
||||||
} else {
|
} else {
|
||||||
this._commitNode(d.createTextNode(value))
|
this._commitNode(document.createTextNode(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._$committedValue = value
|
this._$committedValue = value
|
||||||
|
@ -654,7 +649,7 @@ class PropertyPart extends AttributePart {
|
||||||
this.element[this.name] = value === NOTHING ? void 0 : value
|
this.element[this.name] = value === NOTHING ? void 0 : value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var emptyStringForBooleanAttribute2 = ''
|
|
||||||
class BooleanAttributePart extends AttributePart {
|
class BooleanAttributePart extends AttributePart {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments)
|
super(...arguments)
|
||||||
|
@ -662,12 +657,14 @@ class BooleanAttributePart extends AttributePart {
|
||||||
}
|
}
|
||||||
_commitValue(value) {
|
_commitValue(value) {
|
||||||
if (value && value !== NOTHING) {
|
if (value && value !== NOTHING) {
|
||||||
this.element.setAttribute(this.name, emptyStringForBooleanAttribute2)
|
// 布尔属性,值固定为空
|
||||||
|
this.element.setAttribute(this.name, '')
|
||||||
} else {
|
} else {
|
||||||
this.element.removeAttribute(this.name)
|
this.element.removeAttribute(this.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class EventPart extends AttributePart {
|
class EventPart extends AttributePart {
|
||||||
constructor(element, name, strings, parent, options) {
|
constructor(element, name, strings, parent, options) {
|
||||||
super(element, name, strings, parent, options)
|
super(element, name, strings, parent, options)
|
||||||
|
|
|
@ -122,6 +122,7 @@ export class Component extends HTMLElement {
|
||||||
|
|
||||||
disconnectedCallback() {
|
disconnectedCallback() {
|
||||||
this[__children__]?.setConnected(false)
|
this[__children__]?.setConnected(false)
|
||||||
|
this.unmounted()
|
||||||
}
|
}
|
||||||
// 监听属性变化
|
// 监听属性变化
|
||||||
attributeChangedCallback(name, old, val) {
|
attributeChangedCallback(name, old, val) {
|
||||||
|
@ -226,6 +227,7 @@ export class Component extends HTMLElement {
|
||||||
// 几个生命周期回调
|
// 几个生命周期回调
|
||||||
created() {}
|
created() {}
|
||||||
mounted() {}
|
mounted() {}
|
||||||
|
unmounted() {}
|
||||||
updated() {}
|
updated() {}
|
||||||
|
|
||||||
$on(type, callback) {
|
$on(type, callback) {
|
||||||
|
|
Loading…
Reference in New Issue