|
|
@ -6,12 +6,27 @@ |
|
|
|
* @cfg {JSON} options 配置属性 |
|
|
|
* @cfg {JSON} options 配置属性 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
import { isFunction, isArray, each, extend, isPlainObject, isNull, uniqueId, isWidget, isWidthOrHeight, isKey, remove, any, isNotNull } from "./2.base"; |
|
|
|
import { |
|
|
|
|
|
|
|
isFunction, |
|
|
|
|
|
|
|
isArray, |
|
|
|
|
|
|
|
each, |
|
|
|
|
|
|
|
extend, |
|
|
|
|
|
|
|
isPlainObject, |
|
|
|
|
|
|
|
isNull, |
|
|
|
|
|
|
|
uniqueId, |
|
|
|
|
|
|
|
isWidget, |
|
|
|
|
|
|
|
isWidthOrHeight, |
|
|
|
|
|
|
|
isKey, |
|
|
|
|
|
|
|
remove, |
|
|
|
|
|
|
|
any, |
|
|
|
|
|
|
|
isNotNull |
|
|
|
|
|
|
|
} from "./2.base"; |
|
|
|
import { OB } from "./3.ob"; |
|
|
|
import { OB } from "./3.ob"; |
|
|
|
import { Providers, _lazyCreateWidget } from "./5.inject"; |
|
|
|
import { Providers, _lazyCreateWidget } from "./5.inject"; |
|
|
|
import { DOM } from "./utils"; |
|
|
|
import { DOM } from "./utils"; |
|
|
|
import { Events, emptyFn, pixFormat } from "./constant"; |
|
|
|
import { Events, emptyFn, pixFormat } from "./constant"; |
|
|
|
import { Plugin } from "./6.plugin"; |
|
|
|
import { Plugin } from "./6.plugin"; |
|
|
|
|
|
|
|
import { _global } from "./0.foundation"; |
|
|
|
|
|
|
|
|
|
|
|
const cancelAnimationFrame = |
|
|
|
const cancelAnimationFrame = |
|
|
|
_global.cancelAnimationFrame || |
|
|
|
_global.cancelAnimationFrame || |
|
|
@ -21,10 +36,17 @@ const cancelAnimationFrame = |
|
|
|
_global.msCancelAnimationFrame || |
|
|
|
_global.msCancelAnimationFrame || |
|
|
|
_global.clearTimeout; |
|
|
|
_global.clearTimeout; |
|
|
|
|
|
|
|
|
|
|
|
const requestAnimationFrame = _global.requestAnimationFrame || _global.webkitRequestAnimationFrame || _global.mozRequestAnimationFrame || _global.oRequestAnimationFrame || _global.msRequestAnimationFrame || _global.setTimeout; |
|
|
|
const requestAnimationFrame = |
|
|
|
|
|
|
|
_global.requestAnimationFrame || |
|
|
|
|
|
|
|
_global.webkitRequestAnimationFrame || |
|
|
|
|
|
|
|
_global.mozRequestAnimationFrame || |
|
|
|
|
|
|
|
_global.oRequestAnimationFrame || |
|
|
|
|
|
|
|
_global.msRequestAnimationFrame || |
|
|
|
|
|
|
|
_global.setTimeout; |
|
|
|
|
|
|
|
|
|
|
|
function callLifeHook(self, life) { |
|
|
|
function callLifeHook(self, life) { |
|
|
|
let hooks = [], hook; |
|
|
|
let hooks = [], |
|
|
|
|
|
|
|
hook; |
|
|
|
hook = self[life]; |
|
|
|
hook = self[life]; |
|
|
|
if (hook) { |
|
|
|
if (hook) { |
|
|
|
hooks = hooks.concat(isArray(hook) ? hook : [hook]); |
|
|
|
hooks = hooks.concat(isArray(hook) ? hook : [hook]); |
|
|
@ -39,7 +61,7 @@ function callLifeHook(self, life) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export class Widget extends OB { |
|
|
|
export class Widget extends OB { |
|
|
|
_defaultConfig () { |
|
|
|
_defaultConfig() { |
|
|
|
return extend(super._defaultConfig(), { |
|
|
|
return extend(super._defaultConfig(), { |
|
|
|
root: false, |
|
|
|
root: false, |
|
|
|
tagName: "div", |
|
|
|
tagName: "div", |
|
|
@ -56,18 +78,16 @@ export class Widget extends OB { |
|
|
|
baseCls: "", |
|
|
|
baseCls: "", |
|
|
|
extraCls: "", |
|
|
|
extraCls: "", |
|
|
|
cls: "", |
|
|
|
cls: "", |
|
|
|
css: null, |
|
|
|
css: null |
|
|
|
|
|
|
|
|
|
|
|
// vdom: false
|
|
|
|
// vdom: false
|
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_constructor () { |
|
|
|
_constructor() {} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 覆盖父类的_constructor方法,widget不走ob的生命周期
|
|
|
|
// 覆盖父类的_constructor方法,widget不走ob的生命周期
|
|
|
|
_constructed () { |
|
|
|
_constructed() { |
|
|
|
if (this.setup) { |
|
|
|
if (this.setup) { |
|
|
|
pushTarget(this); |
|
|
|
pushTarget(this); |
|
|
|
const delegate = this.setup(this.options); |
|
|
|
const delegate = this.setup(this.options); |
|
|
@ -81,7 +101,7 @@ export class Widget extends OB { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_lazyConstructor () { |
|
|
|
_lazyConstructor() { |
|
|
|
if (!this.__constructed) { |
|
|
|
if (!this.__constructed) { |
|
|
|
this.__constructed = true; |
|
|
|
this.__constructed = true; |
|
|
|
this._init(); |
|
|
|
this._init(); |
|
|
@ -134,8 +154,11 @@ export class Widget extends OB { |
|
|
|
const init = () => { |
|
|
|
const init = () => { |
|
|
|
// 加个保险
|
|
|
|
// 加个保险
|
|
|
|
if (initCallbackCalled === true) { |
|
|
|
if (initCallbackCalled === true) { |
|
|
|
_global.console && console.error("组件: 请检查beforeInit内部的写法,callback只能执行一次"); |
|
|
|
_global.console && |
|
|
|
|
|
|
|
console.error( |
|
|
|
|
|
|
|
"组件: 请检查beforeInit内部的写法,callback只能执行一次" |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
initCallbackCalled = true; |
|
|
|
initCallbackCalled = true; |
|
|
@ -143,8 +166,11 @@ export class Widget extends OB { |
|
|
|
const render = () => { |
|
|
|
const render = () => { |
|
|
|
// 加个保险
|
|
|
|
// 加个保险
|
|
|
|
if (renderCallbackCalled === true) { |
|
|
|
if (renderCallbackCalled === true) { |
|
|
|
_global.console && console.error("组件: 请检查beforeRender内部的写法,callback只能执行一次"); |
|
|
|
_global.console && |
|
|
|
|
|
|
|
console.error( |
|
|
|
|
|
|
|
"组件: 请检查beforeRender内部的写法,callback只能执行一次" |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
renderCallbackCalled = true; |
|
|
|
renderCallbackCalled = true; |
|
|
@ -154,9 +180,11 @@ export class Widget extends OB { |
|
|
|
|
|
|
|
|
|
|
|
if (this.options.beforeRender || this.beforeRender) { |
|
|
|
if (this.options.beforeRender || this.beforeRender) { |
|
|
|
this.__async = true; |
|
|
|
this.__async = true; |
|
|
|
const beforeRenderResult = (this.options.beforeRender || this.beforeRender).call(this, render); |
|
|
|
const beforeRenderResult = ( |
|
|
|
|
|
|
|
this.options.beforeRender || this.beforeRender |
|
|
|
|
|
|
|
).call(this, render); |
|
|
|
if (beforeRenderResult instanceof Promise) { |
|
|
|
if (beforeRenderResult instanceof Promise) { |
|
|
|
beforeRenderResult.then(render).catch(e => { |
|
|
|
beforeRenderResult.then(render).catch((e) => { |
|
|
|
_global.console && console.error(e); |
|
|
|
_global.console && console.error(e); |
|
|
|
render(); |
|
|
|
render(); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -169,9 +197,11 @@ export class Widget extends OB { |
|
|
|
|
|
|
|
|
|
|
|
if (this.options.beforeInit || this.beforeInit) { |
|
|
|
if (this.options.beforeInit || this.beforeInit) { |
|
|
|
this.__asking = true; |
|
|
|
this.__asking = true; |
|
|
|
const beforeInitResult = (this.options.beforeInit || this.beforeInit).call(this, init); |
|
|
|
const beforeInitResult = ( |
|
|
|
|
|
|
|
this.options.beforeInit || this.beforeInit |
|
|
|
|
|
|
|
).call(this, init); |
|
|
|
if (beforeInitResult instanceof Promise) { |
|
|
|
if (beforeInitResult instanceof Promise) { |
|
|
|
beforeInitResult.then(init).catch(e => { |
|
|
|
beforeInitResult.then(init).catch((e) => { |
|
|
|
_global.console && console.error(e); |
|
|
|
_global.console && console.error(e); |
|
|
|
init(); |
|
|
|
init(); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -211,12 +241,14 @@ export class Widget extends OB { |
|
|
|
this._initElementWidth(); |
|
|
|
this._initElementWidth(); |
|
|
|
this._initElementHeight(); |
|
|
|
this._initElementHeight(); |
|
|
|
if (o._baseCls || o.baseCls || o.extraCls) { |
|
|
|
if (o._baseCls || o.baseCls || o.extraCls) { |
|
|
|
this.element.addClass(`${o._baseCls || ""} ${o.baseCls || ""} ${o.extraCls || ""}`); |
|
|
|
this.element.addClass( |
|
|
|
|
|
|
|
`${o._baseCls || ""} ${o.baseCls || ""} ${o.extraCls || ""}` |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
if (o.cls) { |
|
|
|
if (o.cls) { |
|
|
|
if (isFunction(o.cls)) { |
|
|
|
if (isFunction(o.cls)) { |
|
|
|
let cls = this.__watch(o.cls, (context, newValue) => { |
|
|
|
let cls = this.__watch(o.cls, (context, newValue) => { |
|
|
|
this.element.removeClass(cls).addClass(cls = newValue); |
|
|
|
this.element.removeClass(cls).addClass((cls = newValue)); |
|
|
|
}); |
|
|
|
}); |
|
|
|
this.element.addClass(cls); |
|
|
|
this.element.addClass(cls); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -240,7 +272,7 @@ export class Widget extends OB { |
|
|
|
newValue[k] = ""; |
|
|
|
newValue[k] = ""; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
this.element.css(css = newValue); |
|
|
|
this.element.css((css = newValue)); |
|
|
|
}); |
|
|
|
}); |
|
|
|
this.element.css(css); |
|
|
|
this.element.css(css); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -252,13 +284,20 @@ export class Widget extends OB { |
|
|
|
__watch(getter, handler, options) { |
|
|
|
__watch(getter, handler, options) { |
|
|
|
if (_global.Fix) { |
|
|
|
if (_global.Fix) { |
|
|
|
this._watchers = this._watchers || []; |
|
|
|
this._watchers = this._watchers || []; |
|
|
|
const watcher = new Fix.Watcher(null, () => getter.call(this, this), (handler && (v => { |
|
|
|
const watcher = new Fix.Watcher( |
|
|
|
handler.call(this, this, v); |
|
|
|
null, |
|
|
|
})) || emptyFn, extend({ deep: true }, options)); |
|
|
|
() => getter.call(this, this), |
|
|
|
|
|
|
|
(handler && |
|
|
|
|
|
|
|
((v) => { |
|
|
|
|
|
|
|
handler.call(this, this, v); |
|
|
|
|
|
|
|
})) || |
|
|
|
|
|
|
|
emptyFn, |
|
|
|
|
|
|
|
extend({ deep: true }, options) |
|
|
|
|
|
|
|
); |
|
|
|
this._watchers.push(() => { |
|
|
|
this._watchers.push(() => { |
|
|
|
watcher.teardown(); |
|
|
|
watcher.teardown(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return watcher.value; |
|
|
|
return watcher.value; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return getter(); |
|
|
|
return getter(); |
|
|
@ -277,7 +316,8 @@ export class Widget extends OB { |
|
|
|
if (isWidget(o.element)) { |
|
|
|
if (isWidget(o.element)) { |
|
|
|
this.element = this.options.element.element; |
|
|
|
this.element = this.options.element.element; |
|
|
|
this._parent = o.element; |
|
|
|
this._parent = o.element; |
|
|
|
this._parent._children && this._parent.addWidget(this.widgetName, this); |
|
|
|
this._parent._children && |
|
|
|
|
|
|
|
this._parent.addWidget(this.widgetName, this); |
|
|
|
} else if (o.element) { |
|
|
|
} else if (o.element) { |
|
|
|
this.element = Widget._renderEngine.createElement(this); |
|
|
|
this.element = Widget._renderEngine.createElement(this); |
|
|
|
this._isRoot = true; |
|
|
|
this._isRoot = true; |
|
|
@ -308,9 +348,11 @@ export class Widget extends OB { |
|
|
|
_initVisual() { |
|
|
|
_initVisual() { |
|
|
|
const o = this.options; |
|
|
|
const o = this.options; |
|
|
|
if (o.invisible) { |
|
|
|
if (o.invisible) { |
|
|
|
const invisible = o.invisible = isFunction(o.invisible) ? this.__watch(o.invisible, (context, newValue) => { |
|
|
|
const invisible = (o.invisible = isFunction(o.invisible) |
|
|
|
this.setVisible(!newValue); |
|
|
|
? this.__watch(o.invisible, (context, newValue) => { |
|
|
|
}) : o.invisible; |
|
|
|
this.setVisible(!newValue); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
: o.invisible); |
|
|
|
if (invisible) { |
|
|
|
if (invisible) { |
|
|
|
// 用display属性做显示和隐藏,否则jquery会在显示时将display设为block会覆盖掉display:flex属性
|
|
|
|
// 用display属性做显示和隐藏,否则jquery会在显示时将display设为block会覆盖掉display:flex属性
|
|
|
|
this.__setElementVisible(false); |
|
|
|
this.__setElementVisible(false); |
|
|
@ -322,17 +364,21 @@ export class Widget extends OB { |
|
|
|
const o = this.options; |
|
|
|
const o = this.options; |
|
|
|
if (o.disabled || o.invalid) { |
|
|
|
if (o.disabled || o.invalid) { |
|
|
|
if (this.options.disabled) { |
|
|
|
if (this.options.disabled) { |
|
|
|
const disabled = o.disabled = isFunction(o.disabled) ? this.__watch(o.disabled, (context, newValue) => { |
|
|
|
const disabled = (o.disabled = isFunction(o.disabled) |
|
|
|
this.setEnable(!newValue); |
|
|
|
? this.__watch(o.disabled, (context, newValue) => { |
|
|
|
}) : o.disabled; |
|
|
|
this.setEnable(!newValue); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
: o.disabled); |
|
|
|
if (disabled) { |
|
|
|
if (disabled) { |
|
|
|
this.setEnable(false); |
|
|
|
this.setEnable(false); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.options.invalid) { |
|
|
|
if (this.options.invalid) { |
|
|
|
const invalid = o.invalid = isFunction(o.invalid) ? this.__watch(o.invalid, (context, newValue) => { |
|
|
|
const invalid = (o.invalid = isFunction(o.invalid) |
|
|
|
this.setValid(!newValue); |
|
|
|
? this.__watch(o.invalid, (context, newValue) => { |
|
|
|
}) : o.invalid; |
|
|
|
this.setValid(!newValue); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
: o.invalid); |
|
|
|
if (invalid) { |
|
|
|
if (invalid) { |
|
|
|
this.setValid(false); |
|
|
|
this.setValid(false); |
|
|
|
} |
|
|
|
} |
|
|
@ -365,10 +411,17 @@ export class Widget extends OB { |
|
|
|
_initElement() { |
|
|
|
_initElement() { |
|
|
|
this.__isMounting = true; |
|
|
|
this.__isMounting = true; |
|
|
|
// 当开启worker模式时,可以通过$render来实现另一种效果
|
|
|
|
// 当开启worker模式时,可以通过$render来实现另一种效果
|
|
|
|
const workerMode = Providers.getProvider("bi.provider.system").getWorkerMode(); |
|
|
|
const workerMode = |
|
|
|
const render = isFunction(this.options.render) ? this.options.render : (workerMode ? (this.$render || this.render) : this.render); |
|
|
|
Providers.getProvider("bi.provider.system").getWorkerMode(); |
|
|
|
|
|
|
|
const render = isFunction(this.options.render) |
|
|
|
|
|
|
|
? this.options.render |
|
|
|
|
|
|
|
: workerMode |
|
|
|
|
|
|
|
? this.$render || this.render |
|
|
|
|
|
|
|
: this.render; |
|
|
|
let els = render && render.call(this); |
|
|
|
let els = render && render.call(this); |
|
|
|
els = this.options.configRender ? this.options.configRender.call(this, els) : els; |
|
|
|
els = this.options.configRender |
|
|
|
|
|
|
|
? this.options.configRender.call(this, els) |
|
|
|
|
|
|
|
: els; |
|
|
|
els = Plugin.getRender(this.options.type, els); |
|
|
|
els = Plugin.getRender(this.options.type, els); |
|
|
|
if (isPlainObject(els)) { |
|
|
|
if (isPlainObject(els)) { |
|
|
|
els = [els]; |
|
|
|
els = [els]; |
|
|
@ -378,7 +431,7 @@ export class Widget extends OB { |
|
|
|
each(els, (i, el) => { |
|
|
|
each(els, (i, el) => { |
|
|
|
if (el) { |
|
|
|
if (el) { |
|
|
|
_lazyCreateWidget(el, { |
|
|
|
_lazyCreateWidget(el, { |
|
|
|
element: this, |
|
|
|
element: this |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
@ -400,16 +453,34 @@ export class Widget extends OB { |
|
|
|
* @private |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
_mount(force, deep, lifeHook, predicate, layer) { |
|
|
|
_mount(force, deep, lifeHook, predicate, layer) { |
|
|
|
if (!force && (this._isMounted || !this.isVisible() || this.__asking === true || !(this._isRoot === true || (this._parent && this._parent._isMounted === true)))) { |
|
|
|
if ( |
|
|
|
|
|
|
|
!force && |
|
|
|
|
|
|
|
(this._isMounted || |
|
|
|
|
|
|
|
!this.isVisible() || |
|
|
|
|
|
|
|
this.__asking === true || |
|
|
|
|
|
|
|
!( |
|
|
|
|
|
|
|
this._isRoot === true || |
|
|
|
|
|
|
|
(this._parent && this._parent._isMounted === true) |
|
|
|
|
|
|
|
)) |
|
|
|
|
|
|
|
) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
layer = layer || 0; |
|
|
|
layer = layer || 0; |
|
|
|
lifeHook !== false && !this.__async && callLifeHook(this, "beforeMount"); |
|
|
|
lifeHook !== false && |
|
|
|
|
|
|
|
!this.__async && |
|
|
|
|
|
|
|
callLifeHook(this, "beforeMount"); |
|
|
|
this._isMounted = true; |
|
|
|
this._isMounted = true; |
|
|
|
this.__isMounting = false; |
|
|
|
this.__isMounting = false; |
|
|
|
for (const key in this._children) { |
|
|
|
for (const key in this._children) { |
|
|
|
const child = this._children[key]; |
|
|
|
const child = this._children[key]; |
|
|
|
child._mount && child._mount(deep ? force : false, deep, lifeHook, predicate, layer + 1); |
|
|
|
child._mount && |
|
|
|
|
|
|
|
child._mount( |
|
|
|
|
|
|
|
deep ? force : false, |
|
|
|
|
|
|
|
deep, |
|
|
|
|
|
|
|
lifeHook, |
|
|
|
|
|
|
|
predicate, |
|
|
|
|
|
|
|
layer + 1 |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
if (this._parent) { |
|
|
|
if (this._parent) { |
|
|
|
if (!this._parent.isEnabled()) { |
|
|
|
if (!this._parent.isEnabled()) { |
|
|
@ -426,7 +497,7 @@ export class Widget extends OB { |
|
|
|
this.__afterMount(lifeHook, predicate); |
|
|
|
this.__afterMount(lifeHook, predicate); |
|
|
|
// }, 0);
|
|
|
|
// }, 0);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -454,7 +525,7 @@ export class Widget extends OB { |
|
|
|
res = this.update && this.update(nextProps, shouldUpdate); |
|
|
|
res = this.update && this.update(nextProps, shouldUpdate); |
|
|
|
} |
|
|
|
} |
|
|
|
callLifeHook(this, "updated"); |
|
|
|
callLifeHook(this, "updated"); |
|
|
|
|
|
|
|
|
|
|
|
return res; |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -484,7 +555,9 @@ export class Widget extends OB { |
|
|
|
} |
|
|
|
} |
|
|
|
// 递归将所有子组件使能
|
|
|
|
// 递归将所有子组件使能
|
|
|
|
each(this._children, (i, child) => { |
|
|
|
each(this._children, (i, child) => { |
|
|
|
!child._manualSetEnable && child._setEnable && child._setEnable(enable); |
|
|
|
!child._manualSetEnable && |
|
|
|
|
|
|
|
child._setEnable && |
|
|
|
|
|
|
|
child._setEnable(enable); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -532,7 +605,10 @@ export class Widget extends OB { |
|
|
|
this.__setElementVisible(true); |
|
|
|
this.__setElementVisible(true); |
|
|
|
this._mount(); |
|
|
|
this._mount(); |
|
|
|
if (o.animation && !lastVisible) { |
|
|
|
if (o.animation && !lastVisible) { |
|
|
|
this.element.removeClass(`${o.animation}-leave`).removeClass(`${o.animation}-leave-active`).addClass(`${o.animation}-enter`); |
|
|
|
this.element |
|
|
|
|
|
|
|
.removeClass(`${o.animation}-leave`) |
|
|
|
|
|
|
|
.removeClass(`${o.animation}-leave-active`) |
|
|
|
|
|
|
|
.addClass(`${o.animation}-enter`); |
|
|
|
if (this._requestAnimationFrame) { |
|
|
|
if (this._requestAnimationFrame) { |
|
|
|
cancelAnimationFrame(this._requestAnimationFrame); |
|
|
|
cancelAnimationFrame(this._requestAnimationFrame); |
|
|
|
} |
|
|
|
} |
|
|
@ -544,12 +620,17 @@ export class Widget extends OB { |
|
|
|
clearTimeout(this._animationDuring); |
|
|
|
clearTimeout(this._animationDuring); |
|
|
|
} |
|
|
|
} |
|
|
|
this._animationDuring = setTimeout(() => { |
|
|
|
this._animationDuring = setTimeout(() => { |
|
|
|
this.element.removeClass(`${o.animation}-enter`).removeClass(`${o.animation}-enter-active`); |
|
|
|
this.element |
|
|
|
|
|
|
|
.removeClass(`${o.animation}-enter`) |
|
|
|
|
|
|
|
.removeClass(`${o.animation}-enter-active`); |
|
|
|
}, o.animationDuring); |
|
|
|
}, o.animationDuring); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (visible === false) { |
|
|
|
} else if (visible === false) { |
|
|
|
if (o.animation && lastVisible) { |
|
|
|
if (o.animation && lastVisible) { |
|
|
|
this.element.removeClass(`${o.animation}-enter`).removeClass(`${o.animation}-enter-active`).addClass(`${o.animation}-leave`); |
|
|
|
this.element |
|
|
|
|
|
|
|
.removeClass(`${o.animation}-enter`) |
|
|
|
|
|
|
|
.removeClass(`${o.animation}-enter-active`) |
|
|
|
|
|
|
|
.addClass(`${o.animation}-leave`); |
|
|
|
if (this._requestAnimationFrame) { |
|
|
|
if (this._requestAnimationFrame) { |
|
|
|
cancelAnimationFrame(this._requestAnimationFrame); |
|
|
|
cancelAnimationFrame(this._requestAnimationFrame); |
|
|
|
} |
|
|
|
} |
|
|
@ -561,7 +642,9 @@ export class Widget extends OB { |
|
|
|
clearTimeout(this._animationDuring); |
|
|
|
clearTimeout(this._animationDuring); |
|
|
|
} |
|
|
|
} |
|
|
|
this._animationDuring = setTimeout(() => { |
|
|
|
this._animationDuring = setTimeout(() => { |
|
|
|
this.element.removeClass(`${o.animation}-leave`).removeClass(`${o.animation}-leave-active`); |
|
|
|
this.element |
|
|
|
|
|
|
|
.removeClass(`${o.animation}-leave`) |
|
|
|
|
|
|
|
.removeClass(`${o.animation}-leave-active`); |
|
|
|
this.__setElementVisible(false); |
|
|
|
this.__setElementVisible(false); |
|
|
|
}, o.animationDuring); |
|
|
|
}, o.animationDuring); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -620,7 +703,7 @@ export class Widget extends OB { |
|
|
|
// TODO: self待删
|
|
|
|
// TODO: self待删
|
|
|
|
remove(self._children, this); |
|
|
|
remove(self._children, this); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return (this._children[name] = widget); |
|
|
|
return (this._children[name] = widget); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -634,7 +717,7 @@ export class Widget extends OB { |
|
|
|
any(this._children, (i, wi) => { |
|
|
|
any(this._children, (i, wi) => { |
|
|
|
if (i === name) { |
|
|
|
if (i === name) { |
|
|
|
widget = wi; |
|
|
|
widget = wi; |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
other[i] = wi; |
|
|
|
other[i] = wi; |
|
|
@ -642,7 +725,7 @@ export class Widget extends OB { |
|
|
|
if (!widget) { |
|
|
|
if (!widget) { |
|
|
|
any(other, (i, wi) => (widget = wi.getWidgetByName(i))); |
|
|
|
any(other, (i, wi) => (widget = wi.getWidgetByName(i))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return widget; |
|
|
|
return widget; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -673,13 +756,13 @@ export class Widget extends OB { |
|
|
|
attr(key, value) { |
|
|
|
attr(key, value) { |
|
|
|
if (isPlainObject(key)) { |
|
|
|
if (isPlainObject(key)) { |
|
|
|
each(key, (k, v) => this.attr(k, v)); |
|
|
|
each(key, (k, v) => this.attr(k, v)); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (isNotNull(value)) { |
|
|
|
if (isNotNull(value)) { |
|
|
|
this.options[key] = value; |
|
|
|
this.options[key] = value; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return this.options[key]; |
|
|
|
return this.options[key]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -687,21 +770,13 @@ export class Widget extends OB { |
|
|
|
return this.element.css(name, value); |
|
|
|
return this.element.css(name, value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getText() { |
|
|
|
getText() {} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setText(text) { |
|
|
|
setText(text) {} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
getValue() {} |
|
|
|
|
|
|
|
|
|
|
|
getValue() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setValue(value) { |
|
|
|
setValue(value) {} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isEnabled() { |
|
|
|
isEnabled() { |
|
|
|
return this.options.disabled === true ? false : !this.options._disabled; |
|
|
|
return this.options.disabled === true ? false : !this.options._disabled; |
|
|
@ -775,7 +850,7 @@ export class Widget extends OB { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_empty () { |
|
|
|
_empty() { |
|
|
|
this._assetMounted(); |
|
|
|
this._assetMounted(); |
|
|
|
each(this._children, (i, widget) => { |
|
|
|
each(this._children, (i, widget) => { |
|
|
|
widget && widget._unMount && widget._unMount(); |
|
|
|
widget && widget._unMount && widget._unMount(); |
|
|
@ -784,19 +859,19 @@ export class Widget extends OB { |
|
|
|
this.element.empty(); |
|
|
|
this.element.empty(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
isolate () { |
|
|
|
isolate() { |
|
|
|
if (this._parent) { |
|
|
|
if (this._parent) { |
|
|
|
this._parent.removeWidget(this); |
|
|
|
this._parent.removeWidget(this); |
|
|
|
} |
|
|
|
} |
|
|
|
DOM.hang([this]); |
|
|
|
DOM.hang([this]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
empty () { |
|
|
|
empty() { |
|
|
|
this._empty(); |
|
|
|
this._empty(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 默认的reset方法就是干掉重来
|
|
|
|
// 默认的reset方法就是干掉重来
|
|
|
|
reset () { |
|
|
|
reset() { |
|
|
|
// 还在异步状态的不需要执行reset
|
|
|
|
// 还在异步状态的不需要执行reset
|
|
|
|
if (this.__async === true || this.__asking === true) { |
|
|
|
if (this.__async === true || this.__asking === true) { |
|
|
|
return; |
|
|
|
return; |
|
|
@ -851,8 +926,10 @@ export class Widget extends OB { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let context = null, current = null; |
|
|
|
let context = null, |
|
|
|
const contextStack = [], currentStack = []; |
|
|
|
current = null; |
|
|
|
|
|
|
|
const contextStack = [], |
|
|
|
|
|
|
|
currentStack = []; |
|
|
|
|
|
|
|
|
|
|
|
Widget.pushContext = function (_context) { |
|
|
|
Widget.pushContext = function (_context) { |
|
|
|
if (context) contextStack.push(context); |
|
|
|
if (context) contextStack.push(context); |
|
|
@ -896,17 +973,17 @@ export function useStore(_store) { |
|
|
|
let origin; |
|
|
|
let origin; |
|
|
|
if (_global.Proxy) { |
|
|
|
if (_global.Proxy) { |
|
|
|
const proxy = new Proxy(delegate, { |
|
|
|
const proxy = new Proxy(delegate, { |
|
|
|
get (target, key) { |
|
|
|
get(target, key) { |
|
|
|
return Reflect.get(origin, key); |
|
|
|
return Reflect.get(origin, key); |
|
|
|
}, |
|
|
|
}, |
|
|
|
set (target, key, value) { |
|
|
|
set(target, key, value) { |
|
|
|
return Reflect.set(origin, key, value); |
|
|
|
return Reflect.set(origin, key, value); |
|
|
|
}, |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
current._store = function () { |
|
|
|
current._store = function () { |
|
|
|
origin = (_store || currentStore).apply(this, arguments); |
|
|
|
origin = (_store || currentStore).apply(this, arguments); |
|
|
|
delegate.$delegate = origin; |
|
|
|
delegate.$delegate = origin; |
|
|
|
|
|
|
|
|
|
|
|
return origin; |
|
|
|
return origin; |
|
|
|
}; |
|
|
|
}; |
|
|
|
current.$storeDelegate = proxy; |
|
|
|
current.$storeDelegate = proxy; |
|
|
@ -916,11 +993,11 @@ export function useStore(_store) { |
|
|
|
current._store = function () { |
|
|
|
current._store = function () { |
|
|
|
const st = (_store || currentStore).apply(this, arguments); |
|
|
|
const st = (_store || currentStore).apply(this, arguments); |
|
|
|
extend(delegate, st); |
|
|
|
extend(delegate, st); |
|
|
|
|
|
|
|
|
|
|
|
return st; |
|
|
|
return st; |
|
|
|
}; |
|
|
|
}; |
|
|
|
current.$storeDelegate = delegate; |
|
|
|
current.$storeDelegate = delegate; |
|
|
|
|
|
|
|
|
|
|
|
return current.$storeDelegate; |
|
|
|
return current.$storeDelegate; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -945,11 +1022,11 @@ export function useContext(inject) { |
|
|
|
} |
|
|
|
} |
|
|
|
vm = vm._parent; |
|
|
|
vm = vm._parent; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return vm; |
|
|
|
return vm; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -967,25 +1044,31 @@ export function watch(vm, watch, handler) { |
|
|
|
const innerHandler = watch[key]; |
|
|
|
const innerHandler = watch[key]; |
|
|
|
if (isArray(handler)) { |
|
|
|
if (isArray(handler)) { |
|
|
|
for (let i = 0; i < handler.length; i++) { |
|
|
|
for (let i = 0; i < handler.length; i++) { |
|
|
|
watchers.push(Fix.watch(vm.model, key, innerHandler, { |
|
|
|
watchers.push( |
|
|
|
store: vm, |
|
|
|
Fix.watch(vm.model, key, innerHandler, { |
|
|
|
})); |
|
|
|
store: vm |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
watchers.push(Fix.watch(vm.model, key, innerHandler, { |
|
|
|
watchers.push( |
|
|
|
store: vm, |
|
|
|
Fix.watch(vm.model, key, innerHandler, { |
|
|
|
})); |
|
|
|
store: vm |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// vm中一定有_widget
|
|
|
|
// vm中一定有_widget
|
|
|
|
Widget.current._watchers || (Widget.current._watchers = []); |
|
|
|
Widget.current._watchers || (Widget.current._watchers = []); |
|
|
|
Widget.current._watchers = Widget.current._watchers.concat(watchers); |
|
|
|
Widget.current._watchers = |
|
|
|
|
|
|
|
Widget.current._watchers.concat(watchers); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
handler = watch; |
|
|
|
handler = watch; |
|
|
|
watch = vm; |
|
|
|
watch = vm; |
|
|
|
Widget.current.$watchDelayCallbacks || (Widget.current.$watchDelayCallbacks = []); |
|
|
|
Widget.current.$watchDelayCallbacks || |
|
|
|
|
|
|
|
(Widget.current.$watchDelayCallbacks = []); |
|
|
|
Widget.current.$watchDelayCallbacks.push([watch, handler]); |
|
|
|
Widget.current.$watchDelayCallbacks.push([watch, handler]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -994,7 +1077,7 @@ export function onBeforeMount(beforeMount) { |
|
|
|
if (current) { |
|
|
|
if (current) { |
|
|
|
if (current.__isMounting) { |
|
|
|
if (current.__isMounting) { |
|
|
|
beforeMount(); |
|
|
|
beforeMount(); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!current.beforeMount) { |
|
|
|
if (!current.beforeMount) { |
|
|
@ -1010,7 +1093,7 @@ export function onMounted(mounted) { |
|
|
|
if (current) { |
|
|
|
if (current) { |
|
|
|
if (current._isMounted && !this.__async) { |
|
|
|
if (current._isMounted && !this.__async) { |
|
|
|
mounted(); |
|
|
|
mounted(); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!current.mounted) { |
|
|
|
if (!current.mounted) { |
|
|
@ -1048,7 +1131,7 @@ Widget.registerRenderEngine = function (engine) { |
|
|
|
Widget._renderEngine = engine; |
|
|
|
Widget._renderEngine = engine; |
|
|
|
}; |
|
|
|
}; |
|
|
|
Widget.registerRenderEngine({ |
|
|
|
Widget.registerRenderEngine({ |
|
|
|
createElement (widget) { |
|
|
|
createElement(widget) { |
|
|
|
if (isWidget(widget)) { |
|
|
|
if (isWidget(widget)) { |
|
|
|
const o = widget.options; |
|
|
|
const o = widget.options; |
|
|
|
if (o.element) { |
|
|
|
if (o.element) { |
|
|
@ -1057,15 +1140,15 @@ Widget.registerRenderEngine({ |
|
|
|
if (o.tagName) { |
|
|
|
if (o.tagName) { |
|
|
|
return BI.$(document.createElement(o.tagName)); |
|
|
|
return BI.$(document.createElement(o.tagName)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return BI.$(document.createDocumentFragment()); |
|
|
|
return BI.$(document.createDocumentFragment()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return BI.$(widget); |
|
|
|
return BI.$(widget); |
|
|
|
}, |
|
|
|
}, |
|
|
|
createFragment () { |
|
|
|
createFragment() { |
|
|
|
return document.createDocumentFragment(); |
|
|
|
return document.createDocumentFragment(); |
|
|
|
}, |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
export function mount(widget, container, predicate, hydrate) { |
|
|
|
export function mount(widget, container, predicate, hydrate) { |
|
|
@ -1087,7 +1170,7 @@ export function mount(widget, container, predicate, hydrate) { |
|
|
|
const c = Widget._renderEngine.createElement; |
|
|
|
const c = Widget._renderEngine.createElement; |
|
|
|
DOM.patchProps(widget.element, c(c(container).children()[0])); |
|
|
|
DOM.patchProps(widget.element, c(c(container).children()[0])); |
|
|
|
|
|
|
|
|
|
|
|
const triggerLifeHook = w => { |
|
|
|
const triggerLifeHook = (w) => { |
|
|
|
w.beforeMount && w.beforeMount(); |
|
|
|
w.beforeMount && w.beforeMount(); |
|
|
|
w.mounted && w.mounted(); |
|
|
|
w.mounted && w.mounted(); |
|
|
|
each(w._children, (i, child) => { |
|
|
|
each(w._children, (i, child) => { |
|
|
@ -1096,12 +1179,12 @@ export function mount(widget, container, predicate, hydrate) { |
|
|
|
}; |
|
|
|
}; |
|
|
|
// 最后触发组件树生命周期函数
|
|
|
|
// 最后触发组件树生命周期函数
|
|
|
|
triggerLifeHook(widget); |
|
|
|
triggerLifeHook(widget); |
|
|
|
|
|
|
|
|
|
|
|
return res; |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|
if (container) { |
|
|
|
if (container) { |
|
|
|
Widget._renderEngine.createElement(container).append(widget.element); |
|
|
|
Widget._renderEngine.createElement(container).append(widget.element); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return widget._mount(true, false, false, predicate); |
|
|
|
return widget._mount(true, false, false, predicate); |
|
|
|
} |
|
|
|
} |
|
|
|