forked from fanruan/fineui
Zhenfei.Li-李振飞
2 years ago
27 changed files with 3071 additions and 2958 deletions
@ -1,9 +1,45 @@
|
||||
BI.Resizers = new BI.ResizeController(); |
||||
BI.Layers = new BI.LayerController(); |
||||
BI.Maskers = new BI.MaskersController(); |
||||
BI.Bubbles = new BI.BubblesController(); |
||||
BI.Tooltips = new BI.TooltipsController(); |
||||
BI.Popovers = new BI.PopoverController(); |
||||
BI.Drawers = new BI.DrawerController(); |
||||
BI.Broadcasts = new BI.BroadcastController(); |
||||
BI.StyleLoaders = new BI.StyleLoaderManager(); |
||||
import { |
||||
BroadcastController, |
||||
BubblesController, |
||||
DrawerController, |
||||
LayerController, |
||||
MaskersController, |
||||
PopoverController, |
||||
ResizeController, |
||||
TooltipsController, |
||||
StyleLoaderManager |
||||
} from "../core"; |
||||
|
||||
const Resizers = new ResizeController(); |
||||
const Layers = new LayerController(); |
||||
const Maskers = new MaskersController(); |
||||
const Bubbles = new BubblesController(); |
||||
const Tooltips = new TooltipsController(); |
||||
const Popovers = new PopoverController(); |
||||
const Drawers = new DrawerController(); |
||||
const Broadcasts = new BroadcastController(); |
||||
const StyleLoaders = new StyleLoaderManager(); |
||||
|
||||
BI.extend(BI, { |
||||
Resizers, |
||||
Layers, |
||||
Maskers, |
||||
Bubbles, |
||||
Tooltips, |
||||
Popovers, |
||||
Drawers, |
||||
Broadcasts, |
||||
StyleLoaders |
||||
}); |
||||
|
||||
export {
|
||||
Resizers, |
||||
Layers, |
||||
Maskers, |
||||
Bubbles, |
||||
Tooltips, |
||||
Popovers, |
||||
Drawers, |
||||
Broadcasts, |
||||
StyleLoaders |
||||
}; |
||||
|
@ -0,0 +1,15 @@
|
||||
import Pane from "./1.pane"; |
||||
import Single from "./single/0.single"; |
||||
import Text from "./single/1.text"; |
||||
|
||||
BI.extend(BI, { |
||||
Pane, |
||||
Single, |
||||
Text, |
||||
}); |
||||
|
||||
export { |
||||
Pane, |
||||
Single, |
||||
Text, |
||||
} |
@ -1,220 +1,221 @@
|
||||
!(function () { |
||||
function extend() { |
||||
var target = arguments[0] || {}, length = arguments.length, i = 1, options, name, src, copy; |
||||
for (; i < length; i++) { |
||||
// Only deal with non-null/undefined values
|
||||
if ((options = arguments[i]) != null) { |
||||
// Extend the base object
|
||||
for (name in options) { |
||||
src = target[name]; |
||||
copy = options[name]; |
||||
|
||||
// Prevent never-ending loop
|
||||
if (target === copy) { |
||||
continue; |
||||
} |
||||
import BI from "./2.base"; |
||||
|
||||
function extend() { |
||||
let target = arguments[0] || {}, length = arguments.length, i = 1, name, copy; |
||||
for (; i < length; i++) { |
||||
// Only deal with non-null/undefined values
|
||||
const options = arguments[i]; |
||||
if (options !== null) { |
||||
// Extend the base object
|
||||
for (name in options) { |
||||
copy = options[name]; |
||||
|
||||
// Prevent never-ending loop
|
||||
if (target === copy) { |
||||
continue; |
||||
} |
||||
|
||||
if (copy !== undefined) { |
||||
target[name] = copy; |
||||
} |
||||
|
||||
if (copy !== undefined) { |
||||
target[name] = copy; |
||||
} |
||||
} |
||||
} |
||||
return target; |
||||
} |
||||
|
||||
/** |
||||
* 客户端观察者,主要处理事件的添加、删除、执行等 |
||||
* @class BI.OB |
||||
* @abstract |
||||
*/ |
||||
var OB = function (config) { |
||||
this._constructor(config); |
||||
}; |
||||
BI._.extend(OB.prototype, { |
||||
props: {}, |
||||
return target; |
||||
} |
||||
|
||||
init: null, |
||||
export default class OB { |
||||
// props = {};
|
||||
|
||||
destroyed: null, |
||||
// init = null;
|
||||
|
||||
_constructor: function (config) { |
||||
this._initProps(config); |
||||
this._init(); |
||||
this._initRef(); |
||||
}, |
||||
// destroyed = null;
|
||||
|
||||
_defaultConfig: function (config) { |
||||
return {}; |
||||
}, |
||||
constructor(config) { |
||||
this._constructor(config); |
||||
} |
||||
|
||||
_initProps: function (config) { |
||||
var props = this.props; |
||||
if (BI.isFunction(this.props)) { |
||||
props = this.props(config); |
||||
} |
||||
var defaultProps = extend(this._defaultConfig(config), props); |
||||
var modifiedDefaultProps = (config && config.type && BI.OB.configFunctions[config.type + ".props"]) ? BI.reduce(BI.OB.configFunctions[config.type + ".props"], function (value, conf, index) { |
||||
return extend(conf, value.fn(defaultProps, config, value.opt)); |
||||
}, {}) : null; |
||||
this.options = extend(defaultProps, modifiedDefaultProps, config); |
||||
}, |
||||
|
||||
_init: function () { |
||||
this._initListeners(); |
||||
this.init && this.init(); |
||||
}, |
||||
|
||||
_initListeners: function () { |
||||
var self = this; |
||||
if (this.options.listeners != null) { |
||||
BI._.each(this.options.listeners, function (lis, eventName) { |
||||
if (BI._.isFunction(lis)) { |
||||
self.on(eventName, lis); |
||||
return; |
||||
} |
||||
if (BI._.isArray(lis)) { |
||||
BI._.each(lis, function (l) { |
||||
self.on(eventName, l); |
||||
}); |
||||
return; |
||||
} |
||||
(lis.target ? lis.target : self)[lis.once ? "once" : "on"](lis.eventName, BI._.bind(lis.action, self)); |
||||
}); |
||||
delete this.options.listeners; |
||||
} |
||||
}, |
||||
_constructor(config) { |
||||
this._initProps(config); |
||||
this._init(); |
||||
this._initRef(); |
||||
} |
||||
|
||||
// 获得一个当前对象的引用
|
||||
_initRef: function () { |
||||
var o = this.options; |
||||
if (o.__ref) { |
||||
BI.isFunction(o.__ref) ? o.__ref.call(this, this) : o.__ref.current = this; |
||||
} |
||||
if (o.ref) { |
||||
BI.isFunction(o.ref) ? o.ref.call(this, this) : o.ref.current = this; |
||||
} |
||||
}, |
||||
|
||||
//释放当前对象
|
||||
_purgeRef: function () { |
||||
var o = this.options; |
||||
if (o.__ref) { |
||||
BI.isFunction(o.__ref) ? o.__ref.call(null, null) : o.__ref.current = null; |
||||
o.__ref = null; |
||||
} |
||||
if (o.ref) { |
||||
BI.isFunction(o.ref) ? o.ref.call(null, null) : o.ref.current = null; |
||||
o.ref = null; |
||||
} |
||||
}, |
||||
_defaultConfig(config) { |
||||
return {}; |
||||
} |
||||
|
||||
_getEvents: function () { |
||||
if (!BI._.isObject(this.events)) { |
||||
this.events = {}; |
||||
} |
||||
return this.events; |
||||
}, |
||||
|
||||
/** |
||||
* 给观察者绑定一个事件 |
||||
* @param {String} eventName 事件的名字 |
||||
* @param {Function} fn 事件对应的执行函数 |
||||
*/ |
||||
on: function (eventName, fn) { |
||||
var self = this; |
||||
eventName = eventName.toLowerCase(); |
||||
var fns = this._getEvents()[eventName]; |
||||
if (!BI._.isArray(fns)) { |
||||
fns = []; |
||||
this._getEvents()[eventName] = fns; |
||||
} |
||||
fns.push(fn); |
||||
|
||||
return function () { |
||||
self.un(eventName, fn); |
||||
}; |
||||
}, |
||||
|
||||
/** |
||||
* 给观察者绑定一个只执行一次的事件 |
||||
* @param {String} eventName 事件的名字 |
||||
* @param {Function} fn 事件对应的执行函数 |
||||
*/ |
||||
once: function (eventName, fn) { |
||||
var proxy = function () { |
||||
fn.apply(this, arguments); |
||||
this.un(eventName, proxy); |
||||
}; |
||||
this.on(eventName, proxy); |
||||
}, |
||||
|
||||
/** |
||||
* 解除观察者绑定的指定事件 |
||||
* @param {String} eventName 要解除绑定事件的名字 |
||||
* @param {Function} fn 事件对应的执行函数,该参数是可选的,没有该参数时,将解除绑定所有同名字的事件 |
||||
*/ |
||||
un: function (eventName, fn) { |
||||
eventName = eventName.toLowerCase(); |
||||
|
||||
/* alex:如果fn是null,就是把eventName上面所有方法都un掉*/ |
||||
if (fn == null) { |
||||
delete this._getEvents()[eventName]; |
||||
} else { |
||||
var fns = this._getEvents()[eventName]; |
||||
if (BI._.isArray(fns)) { |
||||
var newFns = []; |
||||
BI._.each(fns, function (ifn) { |
||||
if (ifn != fn) { |
||||
newFns.push(ifn); |
||||
} |
||||
_initProps(config) { |
||||
let props = this.props; |
||||
if (BI.isFunction(this.props)) { |
||||
props = this.props(config); |
||||
} |
||||
const defaultProps = extend(this._defaultConfig(config), props); |
||||
const modifiedDefaultProps = (config && config.type && OB.configFunctions[config.type + ".props"]) ? BI.reduce(OB.configFunctions[config.type + ".props"], function (value, conf, index) { |
||||
return extend(conf, value.fn(defaultProps, config, value.opt)); |
||||
}, {}) : null; |
||||
this.options = extend(defaultProps, modifiedDefaultProps, config); |
||||
} |
||||
|
||||
_init() { |
||||
this._initListeners(); |
||||
this.init && this.init(); |
||||
} |
||||
|
||||
_initListeners() { |
||||
if (this.options.listeners !== null) { |
||||
BI._.each(this.options.listeners, (lis, eventName) => { |
||||
if (BI._.isFunction(lis)) { |
||||
this.on(eventName, lis); |
||||
|
||||
return; |
||||
} |
||||
if (BI._.isArray(lis)) { |
||||
BI._.each(lis, (l) => { |
||||
this.on(eventName, l); |
||||
}); |
||||
this._getEvents()[eventName] = newFns; |
||||
|
||||
return; |
||||
} |
||||
} |
||||
}, |
||||
(lis.target ? lis.target : this)[lis.once ? "once" : "on"](lis.eventName, BI._.bind(lis.action, this)); |
||||
}); |
||||
delete this.options.listeners; |
||||
} |
||||
} |
||||
|
||||
// 获得一个当前对象的引用
|
||||
_initRef() { |
||||
const o = this.options; |
||||
if (o.__ref) { |
||||
BI.isFunction(o.__ref) ? o.__ref.call(this, this) : o.__ref.current = this; |
||||
} |
||||
if (o.ref) { |
||||
BI.isFunction(o.ref) ? o.ref.call(this, this) : o.ref.current = this; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 清除观察者的所有事件绑定 |
||||
*/ |
||||
purgeListeners: function () { |
||||
/* alex:清空events*/ |
||||
// 释放当前对象
|
||||
_purgeRef() { |
||||
const o = this.options; |
||||
if (o.__ref) { |
||||
BI.isFunction(o.__ref) ? o.__ref.call(null, null) : o.__ref.current = null; |
||||
o.__ref = null; |
||||
} |
||||
if (o.ref) { |
||||
BI.isFunction(o.ref) ? o.ref.call(null, null) : o.ref.current = null; |
||||
o.ref = null; |
||||
} |
||||
} |
||||
|
||||
_getEvents() { |
||||
if (!BI._.isObject(this.events)) { |
||||
this.events = {}; |
||||
}, |
||||
|
||||
/** |
||||
* 触发绑定过的事件 |
||||
* |
||||
* @param {String} eventName 要触发的事件的名字 |
||||
* @returns {Boolean} 如果事件函数返回false,则返回false并中断其他同名事件的执行,否则执行所有的同名事件并返回true |
||||
*/ |
||||
fireEvent: function () { |
||||
var eventName = arguments[0].toLowerCase(); |
||||
var fns = this._getEvents()[eventName]; |
||||
if (BI.isArray(fns)) { |
||||
if (BI.isArguments(arguments[1])) { |
||||
for (var i = 0; i < fns.length; i++) { |
||||
if (fns[i].apply(this, arguments[1]) === false) { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
return this.events; |
||||
} |
||||
|
||||
/** |
||||
* 给观察者绑定一个事件 |
||||
* @param {String} eventName 事件的名字 |
||||
* @param {Function} fn 事件对应的执行函数 |
||||
*/ |
||||
on(eventName, fn) { |
||||
eventName = eventName.toLowerCase(); |
||||
let fns = this._getEvents()[eventName]; |
||||
if (!BI._.isArray(fns)) { |
||||
fns = []; |
||||
this._getEvents()[eventName] = fns; |
||||
} |
||||
fns.push(fn); |
||||
|
||||
return () => this.un(eventName, fn); |
||||
} |
||||
|
||||
/** |
||||
* 给观察者绑定一个只执行一次的事件 |
||||
* @param {String} eventName 事件的名字 |
||||
* @param {Function} fn 事件对应的执行函数 |
||||
*/ |
||||
once(eventName, fn) { |
||||
const proxy = () => { |
||||
fn.apply(this, arguments); |
||||
this.un(eventName, proxy); |
||||
}; |
||||
this.on(eventName, proxy); |
||||
} |
||||
|
||||
/** |
||||
* 解除观察者绑定的指定事件 |
||||
* @param {String} eventName 要解除绑定事件的名字 |
||||
* @param {Function} fn 事件对应的执行函数,该参数是可选的,没有该参数时,将解除绑定所有同名字的事件 |
||||
*/ |
||||
un(eventName, fn) { |
||||
eventName = eventName.toLowerCase(); |
||||
|
||||
/* alex:如果fn是null,就是把eventName上面所有方法都un掉*/ |
||||
if (fn === null) { |
||||
delete this._getEvents()[eventName]; |
||||
} else { |
||||
const fns = this._getEvents()[eventName]; |
||||
if (BI._.isArray(fns)) { |
||||
const newFns = []; |
||||
BI._.each(fns, function (ifn) { |
||||
if (ifn !== fn) { |
||||
newFns.push(ifn); |
||||
} |
||||
} else { |
||||
var args = Array.prototype.slice.call(arguments, 1); |
||||
for (var i = 0; i < fns.length; i++) { |
||||
if (fns[i].apply(this, args) === false) { |
||||
return false; |
||||
} |
||||
}); |
||||
this._getEvents()[eventName] = newFns; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 清除观察者的所有事件绑定 |
||||
*/ |
||||
purgeListeners() { |
||||
/* alex:清空events*/ |
||||
this.events = {}; |
||||
} |
||||
|
||||
/** |
||||
* 触发绑定过的事件 |
||||
* |
||||
* @param {String} eventName 要触发的事件的名字 |
||||
* @returns {Boolean} 如果事件函数返回false,则返回false并中断其他同名事件的执行,否则执行所有的同名事件并返回true |
||||
*/ |
||||
fireEvent() { |
||||
const eventName = arguments[0].toLowerCase(); |
||||
const fns = this._getEvents()[eventName]; |
||||
if (BI.isArray(fns)) { |
||||
if (BI.isArguments(arguments[1])) { |
||||
for (let i = 0; i < fns.length; i++) { |
||||
if (fns[i].apply(this, arguments[1]) === false) { |
||||
return false; |
||||
} |
||||
} |
||||
} else { |
||||
const args = Array.prototype.slice.call(arguments, 1); |
||||
for (let i = 0; i < fns.length; i++) { |
||||
if (fns[i].apply(this, args) === false) { |
||||
return false; |
||||
} |
||||
} |
||||
} |
||||
return true; |
||||
}, |
||||
|
||||
destroy: function () { |
||||
this.destroyed && this.destroyed(); |
||||
this._purgeRef(); |
||||
this.purgeListeners(); |
||||
} |
||||
}); |
||||
BI.OB = BI.OB || OB; |
||||
})(); |
||||
|
||||
return true; |
||||
} |
||||
|
||||
destroy() { |
||||
this.destroyed && this.destroyed(); |
||||
this._purgeRef(); |
||||
this.purgeListeners(); |
||||
} |
||||
} |
||||
|
||||
// BI.OB = BI.OB || OB;
|
||||
|
||||
BI.extend(BI, { OB }); |
||||
|
@ -0,0 +1,8 @@
|
||||
/** |
||||
* 注册widget |
||||
*/ |
||||
export function shortcut() { |
||||
return function decorator(Target) { |
||||
BI.shortcut(Target.xtype, Target); |
||||
}; |
||||
} |
@ -0,0 +1,59 @@
|
||||
import { shortcut } from "./decorator"; |
||||
import OB from "./3.ob"; |
||||
import Widget from "./4.widget"; |
||||
import Action from "./action/action"; |
||||
import ShowAction from "./action/action.show"; |
||||
import Behavior from "./behavior/0.behavior"; |
||||
import HighlightBehavior from "./behavior/behavior.highlight"; |
||||
import RedMarkBehavior from "./behavior/behavior.redmark"; |
||||
import Controller from "./controller/0.controller"; |
||||
import BroadcastController from "./controller/controller.broadcast"; |
||||
import BubblesController from "./controller/controller.bubbles"; |
||||
import DrawerController from "./controller/controller.drawer"; |
||||
import LayerController from "./controller/controller.layer"; |
||||
import MaskersController from "./controller/controller.masker"; |
||||
import PopoverController from "./controller/controller.popover"; |
||||
import ResizeController from "./controller/controller.resizer"; |
||||
import TooltipsController from "./controller/controller.tooltips"; |
||||
import StyleLoaderManager from "./loader/loader.style"; |
||||
|
||||
BI.extend(BI, { |
||||
OB, |
||||
Widget, |
||||
Action, |
||||
ShowAction, |
||||
Behavior, |
||||
HighlightBehavior, |
||||
RedMarkBehavior, |
||||
Controller, |
||||
BroadcastController, |
||||
BubblesController, |
||||
DrawerController, |
||||
LayerController, |
||||
MaskersController, |
||||
PopoverController, |
||||
ResizeController, |
||||
TooltipsController, |
||||
StyleLoaderManager, |
||||
}); |
||||
|
||||
export { |
||||
shortcut, |
||||
OB, |
||||
Widget, |
||||
Action, |
||||
ShowAction, |
||||
Behavior, |
||||
HighlightBehavior, |
||||
RedMarkBehavior, |
||||
Controller, |
||||
BroadcastController, |
||||
BubblesController, |
||||
DrawerController, |
||||
LayerController, |
||||
MaskersController, |
||||
PopoverController, |
||||
ResizeController, |
||||
TooltipsController, |
||||
StyleLoaderManager, |
||||
} |
Loading…
Reference in new issue