parent
134e465dd0
commit
ecd46ba23d
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@bd/core",
|
"name": "@bd/core",
|
||||||
"version": "1.9.3",
|
"version": "1.9.4",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "百搭UI组件库的核心",
|
"description": "百搭UI组件库的核心",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
|
|
@ -136,9 +136,7 @@ function getTemplateHtml(strings, type) {
|
||||||
let htmlResult =
|
let htmlResult =
|
||||||
html2 + (strings[len] || '<?>') + (type === SVG_RESULT ? '</svg>' : '')
|
html2 + (strings[len] || '<?>') + (type === SVG_RESULT ? '</svg>' : '')
|
||||||
if (!Array.isArray(strings) || !strings.hasOwnProperty('raw')) {
|
if (!Array.isArray(strings) || !strings.hasOwnProperty('raw')) {
|
||||||
let message = 'invalid template strings array'
|
throw new Error('invalid html ast')
|
||||||
|
|
||||||
throw new Error(message)
|
|
||||||
}
|
}
|
||||||
return [htmlResult, attrNames]
|
return [htmlResult, attrNames]
|
||||||
}
|
}
|
||||||
|
|
|
@ -337,7 +337,7 @@ export class Component extends HTMLElement {
|
||||||
unbind(this, type, callback, options)
|
unbind(this, type, callback, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
$emit(type, data = {}) {
|
$emit(type, data = {}, stop = false) {
|
||||||
return fire(this, type, data)
|
return fire(this, type, data, stop)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
src/utils.js
10
src/utils.js
|
@ -185,9 +185,15 @@ export function clearOutsideClick(fn = noop) {
|
||||||
unbind(document, 'mousedown', fn)
|
unbind(document, 'mousedown', fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fire(el, name = 'click', data = {}) {
|
/**
|
||||||
|
* @param el <DOM> 节点
|
||||||
|
* @param name <String> 自定义的事件名
|
||||||
|
* @param data <Object> 要合并进event对象的参数
|
||||||
|
* @param stop <Boolean> 是否禁止事件冒泡
|
||||||
|
*/
|
||||||
|
export function fire(el, name = 'click', data = {}, stop) {
|
||||||
let ev = document.createEvent('Events')
|
let ev = document.createEvent('Events')
|
||||||
ev.initEvent(name, true, true)
|
ev.initEvent(name, !stop, true)
|
||||||
Object.assign(ev, data)
|
Object.assign(ev, data)
|
||||||
el.dispatchEvent(ev)
|
el.dispatchEvent(ev)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue