Browse Source

KERNEL-14035 refactor: constant、element、logic文件夹及整体eslint一下

es6
Zhenfei.Li 2 years ago
parent
commit
4addb6aefd
  1. 12
      src/base/1.pane.js
  2. 3
      src/core/2.base.js
  3. 15
      src/core/action/action.js
  4. 17
      src/core/action/action.show.js
  5. 2
      src/core/action/index.js
  6. 24
      src/core/behavior/0.behavior.js
  7. 26
      src/core/behavior/behavior.highlight.js
  8. 21
      src/core/behavior/behavior.redmark.js
  9. 27
      src/core/behavior/index.js
  10. 879
      src/core/constant/events.js
  11. 2
      src/core/constant/index.js
  12. 327
      src/core/constant/var.js
  13. 4
      src/core/controller/0.controller.js
  14. 9
      src/core/controller/controller.broadcast.js
  15. 38
      src/core/controller/controller.bubbles.js
  16. 38
      src/core/controller/controller.drawer.js
  17. 55
      src/core/controller/controller.layer.js
  18. 2
      src/core/controller/controller.masker.js
  19. 46
      src/core/controller/controller.popover.js
  20. 21
      src/core/controller/controller.resizer.js
  21. 40
      src/core/controller/controller.tooltips.js
  22. 124
      src/core/element/element.js
  23. 21
      src/core/element/index.js
  24. 45
      src/core/element/plugins/attr.js
  25. 38
      src/core/element/plugins/class.js
  26. 40
      src/core/element/plugins/css.js
  27. 25
      src/core/element/plugins/data.js
  28. 17
      src/core/element/plugins/empty.js
  29. 63
      src/core/element/plugins/event.js
  30. 32
      src/core/element/plugins/html.js
  31. 58
      src/core/element/plugins/index.js
  32. 11
      src/core/element/plugins/keywordMark.js
  33. 124
      src/core/element/plugins/renderToHtml.js
  34. 96
      src/core/element/plugins/renderToString.js
  35. 20
      src/core/element/plugins/text.js
  36. 18
      src/core/element/plugins/val.js
  37. 9
      src/core/index.js
  38. 20
      src/core/listener/listener.show.js
  39. 9
      src/core/loader/loader.style.js
  40. 83
      src/core/logic/index.js
  41. 82
      src/core/logic/logic.js
  42. 109
      src/core/logic/logic.layout.js

12
src/base/1.pane.js

@ -33,7 +33,7 @@ export class Pane extends Widget {
element: this, element: this,
items: [{ items: [{
type: "bi.label", type: "bi.label",
ref: (_ref) => { ref: _ref => {
this._tipText = _ref; this._tipText = _ref;
}, },
cls: "bi-tips", cls: "bi-tips",
@ -54,15 +54,15 @@ export class Pane extends Widget {
// loading的异步情况下由loaded后对面板的populate的时机决定 // loading的异步情况下由loaded后对面板的populate的时机决定
this.setTipVisible(false); this.setTipVisible(false);
if (o.overlap === true) { if (o.overlap === true) {
if (!Layers.has(this.getName() + "-loading")) { if (!Layers.has(`${this.getName()}-loading`)) {
createWidget({ createWidget({
type: "bi.center_adapt", type: "bi.center_adapt",
cls: "loading-container", cls: "loading-container",
items: this._getLoadingTipItems(loadingAnimation), items: this._getLoadingTipItems(loadingAnimation),
element: Layers.make(this.getName() + "-loading", this), element: Layers.make(`${this.getName()}-loading`, this),
}); });
} }
Layers.show(this.getName() + "-loading"); Layers.show(`${this.getName()}-loading`);
} else if (isNull(this._loading)) { } else if (isNull(this._loading)) {
loadingAnimation.element.css("zIndex", 1); loadingAnimation.element.css("zIndex", 1);
createWidget({ createWidget({
@ -94,7 +94,7 @@ export class Pane extends Widget {
return [{ return [{
type: "bi.vertical", type: "bi.vertical",
ref: (_ref) => { ref: _ref => {
this._loading = _ref; this._loading = _ref;
}, },
items: loadingTipItems, items: loadingTipItems,
@ -102,7 +102,7 @@ export class Pane extends Widget {
} }
loaded() { loaded() {
Layers.remove(this.getName() + "-loading"); Layers.remove(`${this.getName()}-loading`);
this._loading && this._loading.destroy(); this._loading && this._loading.destroy();
this.options.onLoaded(); this.options.onLoaded();
this.fireEvent(Pane.EVENT_LOADED); this.fireEvent(Pane.EVENT_LOADED);

3
src/core/2.base.js

@ -488,7 +488,7 @@ BI._.each([
"keys", "allKeys", "values", "pairs", "invert", "create", "functions", "extend", "extendOwn", "keys", "allKeys", "values", "pairs", "invert", "create", "functions", "extend", "extendOwn",
"defaults", "clone", "property", "propertyOf", "matcher", "isEqual", "isMatch", "isEmpty", "defaults", "clone", "property", "propertyOf", "matcher", "isEqual", "isMatch", "isEmpty",
"isElement", "isNumber", "isString", "isArray", "isObject", "isPlainObject", "isArguments", "isFunction", "isFinite", "isElement", "isNumber", "isString", "isArray", "isObject", "isPlainObject", "isArguments", "isFunction", "isFinite",
"isBoolean", "isDate", "isRegExp", "isError", "isNaN", "isUndefined", "zipObject", "cloneDeep" "isBoolean", "isDate", "isRegExp", "isError", "isNaN", "isUndefined", "zipObject", "cloneDeep", "pickBy"
], name => { ], name => {
BI[name] = _apply(name); BI[name] = _apply(name);
}); });
@ -526,6 +526,7 @@ export const isNaN = BI.isNaN;
export const isUndefined = BI.isUndefined; export const isUndefined = BI.isUndefined;
export const zipObject = BI.zipObject; export const zipObject = BI.zipObject;
export const cloneDeep = BI.cloneDeep; export const cloneDeep = BI.cloneDeep;
export const pickBy = BI.pickBy;
BI._.each(["mapObject", "findKey", "pick", "omit", "tap"], name => { BI._.each(["mapObject", "findKey", "pick", "omit", "tap"], name => {
BI[name] = _applyFunc(name); BI[name] = _applyFunc(name);

15
src/core/action/action.js

@ -6,10 +6,11 @@
* @abstract * @abstract
*/ */
import { OB } from "../3.ob"; import { OB } from "../3.ob";
export class Action extends OB { export class Action extends OB {
props = { props = {
src: null, src: null,
tar: null tar: null,
}; };
actionPerformed(src, tar, callback) { actionPerformed(src, tar, callback) {
@ -20,15 +21,3 @@ export class Action extends OB {
} }
} }
BI.ActionFactory = {
createAction: function (key, options) {
var action;
switch (key) {
case "show":
action = BI.ShowAction;
break;
}
return new action(options);
}
};

17
src/core/action/action.show.js

@ -1,10 +1,9 @@
/** /**
* guy * guy
* 由一个元素切换到另一个元素的行为 * 由一个元素切换到另一个元素的行为
* @class BI.ShowAction
* @extends BI.Action
*/ */
import { Action } from "./action"; import { Action } from "./action";
export class ShowAction extends Action { export class ShowAction extends Action {
actionPerformed(src, tar, callback) { actionPerformed(src, tar, callback) {
tar = tar || this.options.tar; tar = tar || this.options.tar;
@ -18,3 +17,17 @@ export class ShowAction extends Action {
callback && callback(); callback && callback();
} }
} }
export const ActionFactory = {
createAction (key, options) {
let Action;
switch (key) {
case "show":
Action = ShowAction;
break;
default:
}
return new Action(options);
},
};

2
src/core/action/index.js

@ -1,2 +1,2 @@
export { Action } from "./action"; export { Action } from "./action";
export { ShowAction } from "./action.show"; export { ShowAction, ActionFactory } from "./action.show";

24
src/core/behavior/0.behavior.js

@ -1,30 +1,14 @@
BI.BehaviorFactory = {
createBehavior: function (key, options) {
var behavior;
switch (key) {
case "highlight":
behavior = BI.HighlightBehavior;
break;
case "redmark":
behavior = BI.RedMarkBehavior;
break;
}
return new behavior(options);
}
};
/** /**
* guy * guy
* 行为控件 * 行为控件
* @class BI.Behavior
* @extends BI.OB
*/ */
import { OB } from "../3.ob"; import { OB } from "../3.ob";
import { extend } from "../2.base";
export class Behavior extends OB { export class Behavior extends OB {
_defaultConfig() { _defaultConfig() {
return BI.extend(super._defaultConfig(arguments), { return extend(super._defaultConfig(arguments), {
rule: () => true rule: () => true,
}); });
} }

26
src/core/behavior/behavior.highlight.js

@ -1,33 +1,33 @@
/** /**
* guy * guy
*
* @class BI.HighlightBehavior
* @extends BI.Behavior
*/ */
import { Behavior } from "./0.behavior"; import { Behavior } from "./0.behavior";
import { isFunction, each } from "../2.base";
import { Single } from "../../base";
export class HighlightBehavior extends Behavior { export class HighlightBehavior extends Behavior {
doBehavior(items) { doBehavior(items) {
const args = Array.prototype.slice.call(arguments, 1), const args = Array.prototype.slice.call(arguments, 1),
o = this.options; { rule } = this.options;
BI.each(items, function (i, item) { each(items, (i, item) => {
if (item instanceof BI.Single) { if (item instanceof Single) {
const rule = o.rule(item.getValue(), item); const rules = rule(item.getValue(), item);
function doBe (run) { function doBe (run) {
if (run === true) { if (run === true) {
item.doHighLight && item.doHighLight.apply(item, args); item.doHighLight && item.doHighLight(...args);
} else { } else {
item.unHighLight && item.unHighLight.apply(item, args); item.unHighLight && item.unHighLight(...args);
} }
} }
if (BI.isFunction(rule)) { if (isFunction(rules)) {
rule(doBe); rules(doBe);
} else { } else {
doBe(rule); doBe(rules);
} }
} else { } else {
item.doBehavior && item.doBehavior.apply(item, args); item.doBehavior && item.doBehavior(...args);
} }
}); });
} }

21
src/core/behavior/behavior.redmark.js

@ -1,23 +1,24 @@
/** /**
* guy * guy
* 标红行为 * 标红行为
* @class BI.RedMarkBehavior
* @extends BI.Behavior
*/ */
import { Behavior } from "./0.behavior"; import { Behavior } from "./0.behavior";
import { each } from "../2.base";
import { Single } from "../../base";
export class RedMarkBehavior extends Behavior { export class RedMarkBehavior extends Behavior {
doBehavior(items) { doBehavior(items) {
const args = Array.prototype.slice.call(arguments, 1), const args = Array.prototype.slice.call(arguments, 1),
o = this.options; { rule } = this.options;
BI.each(items, function (i, item) { each(items, (i, item) => {
if(item instanceof BI.Single) { if (item instanceof Single) {
if (o.rule(item.getValue(), item)) { if (rule(item.getValue(), item)) {
item.doRedMark && item.doRedMark.apply(item, args); item.doRedMark && item.doRedMark(...args);
} else { } else {
item.doRedMark && item.unRedMark.apply(item, args); item.doRedMark && item.unRedMark(...args);
} }
} else { } else {
item.doBehavior && item.doBehavior.apply(item, args); item.doBehavior && item.doBehavior(...args);
} }
}); });
} }

27
src/core/behavior/index.js

@ -1,3 +1,26 @@
import { HighlightBehavior } from "./behavior.highlight";
import { RedMarkBehavior } from "./behavior.redmark";
export const BehaviorFactory = {
createBehavior (key, options) {
let Behavior;
switch (key) {
case "highlight":
Behavior = HighlightBehavior;
break;
case "redmark":
Behavior = RedMarkBehavior;
break;
default:
}
return new Behavior(options);
},
};
export { Behavior } from "./0.behavior"; export { Behavior } from "./0.behavior";
export { HighlightBehavior } from "./behavior.highlight"; export {
export { RedMarkBehavior } from "./behavior.redmark"; HighlightBehavior,
RedMarkBehavior
};

879
src/core/constant/events.js

@ -1,444 +1,441 @@
/** /**
* 事件集合 * 事件集合
* @class BI.Events
*/ */
BI._.extend(BI, { export const Events = {
Events: {
/**
/** * @static
* @static * @property keydown事件
* @property keydown事件 */
*/ KEYDOWN: "_KEYDOWN",
KEYDOWN: "_KEYDOWN",
/**
/** * @static
* @static * @property 回撤事件
* @property 回撤事件 */
*/ BACKSPACE: "_BACKSPACE",
BACKSPACE: "_BACKSPACE",
/**
/** * @static
* @static * @property 空格事件
* @property 空格事件 */
*/ SPACE: "_SPACE",
SPACE: "_SPACE",
/**
/** * @static
* @static * @property 回车事件
* @property 回车事件 */
*/ ENTER: "_ENTER",
ENTER: "_ENTER",
/**
/** * @static
* @static * @property 确定事件
* @property 确定事件 */
*/ CONFIRM: "_CONFIRM",
CONFIRM: "_CONFIRM",
/**
/** * @static
* @static * @property 错误事件
* @property 错误事件 */
*/ ERROR: "_ERROR",
ERROR: "_ERROR",
/**
/** * @static
* @static * @property 暂停事件
* @property 暂停事件 */
*/ PAUSE: "_PAUSE",
PAUSE: "_PAUSE",
/**
/** * @static
* @static * @property destroy事件
* @property destroy事件 */
*/ DESTROY: "_DESTROY",
DESTROY: "_DESTROY",
/**
/** * @static
* @static * @property 挂载事件
* @property 挂载事件 */
*/ MOUNT: "_MOUNT",
MOUNT: "_MOUNT",
/**
/** * @static
* @static * @property 取消挂载事件
* @property 取消挂载事件 */
*/ UNMOUNT: "_UNMOUNT",
UNMOUNT: "_UNMOUNT",
/**
/** * @static
* @static * @property 清除选择
* @property 清除选择 */
*/ CLEAR: "_CLEAR",
CLEAR: "_CLEAR",
/**
/** * @static
* @static * @property 添加数据
* @property 添加数据 */
*/ ADD: "_ADD",
ADD: "_ADD",
/**
/** * @static
* @static * @property 正在编辑状态事件
* @property 正在编辑状态事件 */
*/ EDITING: "_EDITING",
EDITING: "_EDITING",
/**
/** * @static
* @static * @property 空状态事件
* @property 空状态事件 */
*/ EMPTY: "_EMPTY",
EMPTY: "_EMPTY",
/**
/** * @static
* @static * @property 显示隐藏事件
* @property 显示隐藏事件 */
*/ VIEW: "_VIEW",
VIEW: "_VIEW",
/**
/** * @static
* @static * @property 窗体改变大小
* @property 窗体改变大小 */
*/ RESIZE: "_RESIZE",
RESIZE: "_RESIZE",
/**
/** * @static
* @static * @property 编辑前事件
* @property 编辑前事件 */
*/ BEFOREEDIT: "_BEFOREEDIT",
BEFOREEDIT: "_BEFOREEDIT",
/**
/** * @static
* @static * @property 编辑后事件
* @property 编辑后事件 */
*/ AFTEREDIT: "_AFTEREDIT",
AFTEREDIT: "_AFTEREDIT",
/**
/** * @static
* @static * @property 开始编辑事件
* @property 开始编辑事件 */
*/ STARTEDIT: "_STARTEDIT",
STARTEDIT: "_STARTEDIT",
/**
/** * @static
* @static * @property 停止编辑事件
* @property 停止编辑事件 */
*/ STOPEDIT: "_STOPEDIT",
STOPEDIT: "_STOPEDIT",
/**
/** * @static
* @static * @property 值改变事件
* @property 值改变事件 */
*/ CHANGE: "_CHANGE",
CHANGE: "_CHANGE",
/**
/** * @static
* @static * @property 下拉弹出菜单事件
* @property 下拉弹出菜单事件 */
*/ EXPAND: "_EXPAND",
EXPAND: "_EXPAND",
/**
/** * @static
* @static * @property 关闭下拉菜单事件
* @property 关闭下拉菜单事件 */
*/ COLLAPSE: "_COLLAPSE",
COLLAPSE: "_COLLAPSE",
/**
/** * @static
* @static * @property 下拉菜单切换展开收起事件
* @property 下拉菜单切换展开收起事件 */
*/ TOGGLE: "_TOGGLE",
TOGGLE: "_TOGGLE",
/**
/** * @static
* @static * @property 回调事件
* @property 回调事件 */
*/ CALLBACK: "_CALLBACK",
CALLBACK: "_CALLBACK",
/**
/** * @static
* @static * @property 点击事件
* @property 点击事件 */
*/ CLICK: "_CLICK",
CLICK: "_CLICK",
/**
/** * @static
* @static * @property 状态改变事件一般是用在复选按钮和单选按钮
* @property 状态改变事件一般是用在复选按钮和单选按钮 */
*/ STATECHANGE: "_STATECHANGE",
STATECHANGE: "_STATECHANGE",
/**
/** * @static
* @static * @property 状态改变前事件
* @property 状态改变前事件 */
*/ BEFORESTATECHANGE: "_BEFORESTATECHANGE",
BEFORESTATECHANGE: "_BEFORESTATECHANGE",
/**
/** * @static
* @static * @property 初始化事件
* @property 初始化事件 */
*/ INIT: "_INIT",
INIT: "_INIT",
/**
/** * @static
* @static * @property 初始化后事件
* @property 初始化后事件 */
*/ AFTERINIT: "_AFTERINIT",
AFTERINIT: "_AFTERINIT",
/**
/** * @static
* @static * @property 滚动条滚动事件
* @property 滚动条滚动事件 */
*/ SCROLL: "_SCROLL",
SCROLL: "_SCROLL",
/**
/** * @static
* @static * @property 开始加载事件
* @property 开始加载事件 */
*/ STARTLOAD: "_STARTLOAD",
STARTLOAD: "_STARTLOAD",
/**
/** * @static
* @static * @property 加载后事件
* @property 加载后事件 */
*/ AFTERLOAD: "_AFTERLOAD",
AFTERLOAD: "_AFTERLOAD",
/**
/** * @static
* @static * @property 提交前事件
* @property 提交前事件 */
*/ BS: "beforesubmit",
BS: "beforesubmit",
/**
/** * @static
* @static * @property 提交后事件
* @property 提交后事件 */
*/ AS: "aftersubmit",
AS: "aftersubmit",
/**
/** * @static
* @static * @property 提交完成事件
* @property 提交完成事件 */
*/ SC: "submitcomplete",
SC: "submitcomplete",
/**
/** * @static
* @static * @property 提交失败事件
* @property 提交失败事件 */
*/ SF: "submitfailure",
SF: "submitfailure",
/**
/** * @static
* @static * @property 提交成功事件
* @property 提交成功事件 */
*/ SS: "submitsuccess",
SS: "submitsuccess",
/**
/** * @static
* @static * @property 校验提交前事件
* @property 校验提交前事件 */
*/ BVW: "beforeverifywrite",
BVW: "beforeverifywrite",
/**
/** * @static
* @static * @property 校验提交后事件
* @property 校验提交后事件 */
*/ AVW: "afterverifywrite",
AVW: "afterverifywrite",
/**
/** * @static
* @static * @property 校验后事件
* @property 校验后事件 */
*/ AV: "afterverify",
AV: "afterverify",
/**
/** * @static
* @static * @property 填报前事件
* @property 填报前事件 */
*/ BW: "beforewrite",
BW: "beforewrite",
/**
/** * @static
* @static * @property 填报后事件
* @property 填报后事件 */
*/ AW: "afterwrite",
AW: "afterwrite",
/**
/** * @static
* @static * @property 填报成功事件
* @property 填报成功事件 */
*/ WS: "writesuccess",
WS: "writesuccess",
/**
/** * @static
* @static * @property 填报失败事件
* @property 填报失败事件 */
*/ WF: "writefailure",
WF: "writefailure",
/**
/** * @static
* @static * @property 添加行前事件
* @property 添加行前事件 */
*/ BA: "beforeappend",
BA: "beforeappend",
/**
/** * @static
* @static * @property 添加行后事件
* @property 添加行后事件 */
*/ AA: "afterappend",
AA: "afterappend",
/**
/** * @static
* @static * @property 删除行前事件
* @property 删除行前事件 */
*/ BD: "beforedelete",
BD: "beforedelete",
/**
/** * @static
* @static * @property 删除行后事件
* @property 删除行后事件 */
*/ AD: "beforedelete",
AD: "beforedelete",
/**
/** * @static
* @static * @property 未提交离开事件
* @property 未提交离开事件 */
*/ UC: "unloadcheck",
UC: "unloadcheck",
/**
/** * @static
* @static * @property PDF导出前事件
* @property PDF导出前事件 */
*/ BTOPDF: "beforetopdf",
BTOPDF: "beforetopdf",
/**
/** * @static
* @static * @property PDF导出后事件
* @property PDF导出后事件 */
*/ ATOPDF: "aftertopdf",
ATOPDF: "aftertopdf",
/**
/** * @static
* @static * @property Excel导出前事件
* @property Excel导出前事件 */
*/ BTOEXCEL: "beforetoexcel",
BTOEXCEL: "beforetoexcel",
/**
/** * @static
* @static * @property Excel导出后事件
* @property Excel导出后事件 */
*/ ATOEXCEL: "aftertoexcel",
ATOEXCEL: "aftertoexcel",
/**
/** * @static
* @static * @property Word导出前事件
* @property Word导出前事件 */
*/ BTOWORD: "beforetoword",
BTOWORD: "beforetoword",
/**
/** * @static
* @static * @property Word导出后事件
* @property Word导出后事件 */
*/ ATOWORD: "aftertoword",
ATOWORD: "aftertoword",
/**
/** * @static
* @static * @property 图片导出前事件
* @property 图片导出前事件 */
*/ BTOIMAGE: "beforetoimage",
BTOIMAGE: "beforetoimage",
/**
/** * @static
* @static * @property 图片导出后事件
* @property 图片导出后事件 */
*/ ATOIMAGE: "aftertoimage",
ATOIMAGE: "aftertoimage",
/**
/** * @static
* @static * @property HTML导出前事件
* @property HTML导出前事件 */
*/ BTOHTML: "beforetohtml",
BTOHTML: "beforetohtml",
/**
/** * @static
* @static * @property HTML导出后事件
* @property HTML导出后事件 */
*/ ATOHTML: "aftertohtml",
ATOHTML: "aftertohtml",
/**
/** * @static
* @static * @property Excel导入前事件
* @property Excel导入前事件 */
*/ BIMEXCEL: "beforeimportexcel",
BIMEXCEL: "beforeimportexcel",
/**
/** * @static
* @static * @property Excel导出后事件
* @property Excel导出后事件 */
*/ AIMEXCEL: "afterimportexcel",
AIMEXCEL: "afterimportexcel",
/**
/** * @static
* @static * @property PDF打印前事件
* @property PDF打印前事件 */
*/ BPDFPRINT: "beforepdfprint",
BPDFPRINT: "beforepdfprint",
/**
/** * @static
* @static * @property PDF打印后事件
* @property PDF打印后事件 */
*/ APDFPRINT: "afterpdfprint",
APDFPRINT: "afterpdfprint",
/**
/** * @static
* @static * @property Flash打印前事件
* @property Flash打印前事件 */
*/ BFLASHPRINT: "beforeflashprint",
BFLASHPRINT: "beforeflashprint",
/**
/** * @static
* @static * @property Flash打印后事件
* @property Flash打印后事件 */
*/ AFLASHPRINT: "afterflashprint",
AFLASHPRINT: "afterflashprint",
/**
/** * @static
* @static * @property Applet打印前事件
* @property Applet打印前事件 */
*/ BAPPLETPRINT: "beforeappletprint",
BAPPLETPRINT: "beforeappletprint",
/**
/** * @static
* @static * @property Applet打印后事件
* @property Applet打印后事件 */
*/ AAPPLETPRINT: "afterappletprint",
AAPPLETPRINT: "afterappletprint",
/**
/** * @static
* @static * @property 服务器打印前事件
* @property 服务器打印前事件 */
*/ BSEVERPRINT: "beforeserverprint",
BSEVERPRINT: "beforeserverprint",
/**
/** * @static
* @static * @property 服务器打印后事件
* @property 服务器打印后事件 */
*/ ASERVERPRINT: "afterserverprint",
ASERVERPRINT: "afterserverprint",
/**
/** * @static
* @static * @property 邮件发送前事件
* @property 邮件发送前事件 */
*/ BEMAIL: "beforeemail",
BEMAIL: "beforeemail",
/**
/** * @static
* @static * @property 邮件发送后事件
* @property 邮件发送后事件 */
*/ AEMAIL: "afteremail",
AEMAIL: "afteremail" };
}
});

2
src/core/constant/index.js

@ -0,0 +1,2 @@
export { Events } from "./events";
export * from "./var";

327
src/core/constant/var.js

@ -1,167 +1,170 @@
/** /**
* 常量 * 常量
*/ */
import { isNumber } from "../2.base";
BI._.extend(BI, { export const MAX = 0xfffffffffffffff;
MAX: 0xfffffffffffffff, export const MIN = -0xfffffffffffffff;
MIN: -0xfffffffffffffff, export const EVENT_RESPONSE_TIME = 200;
EVENT_RESPONSE_TIME: 200, export const EVENT_BLUR = true;
EVENT_BLUR: true, export const zIndex_layer = 1e5;
zIndex_layer: 1e5, export const zIndex_popover = 1e6;
zIndex_popover: 1e6, export const zIndex_popup = 1e7;
zIndex_popup: 1e7, export const zIndex_masker = 1e8;
zIndex_masker: 1e8, export const zIndex_tip = 1e9;
zIndex_tip: 1e9, export const emptyStr = "";
emptyStr: "", export const pixUnit = "px";
pixUnit: "px", export const pixRatio = 1;
pixRatio: 1, export const empty = null;
// 一定返回最终的单位 export const Key = {
pixFormat: function (pix, border) { 48: "0",
if (!BI.isNumber(pix)) { 49: "1",
return pix; 50: "2",
} 51: "3",
if (BI.pixUnit === "px") { 52: "4",
return (pix / BI.pixRatio - (border || 0)) + BI.pixUnit; 53: "5",
} 54: "6",
var length = pix / BI.pixRatio + BI.pixUnit; 55: "7",
if (border > 0) { 56: "8",
return `calc(${length} - ${border + "px"})`; 57: "9",
} 65: "a",
return length; 66: "b",
}, 67: "c",
toPix: function (pix, border) { 68: "d",
if (!BI.isNumber(pix)) { 69: "e",
return pix; 70: "f",
} 71: "g",
if (BI.pixUnit === "px") { 72: "h",
return pix - (border || 0) * BI.pixRatio; 73: "i",
} 74: "j",
if (border > 0) { 75: "k",
return `calc(${pix / BI.pixRatio + BI.pixUnit} - ${border + "px"})`; 76: "l",
} 77: "m",
78: "n",
79: "o",
80: "p",
81: "q",
82: "r",
83: "s",
84: "t",
85: "u",
86: "v",
87: "w",
88: "x",
89: "y",
90: "z",
96: "0",
97: "1",
98: "2",
99: "3",
100: "4",
101: "5",
102: "6",
103: "7",
104: "8",
105: "9",
106: "*",
107: "+",
109: "-",
110: ".",
111: "/",
};
export const KeyCode = {
BACKSPACE: 8,
COMMA: 188,
DELETE: 46,
DOWN: 40,
END: 35,
ENTER: 13,
ESCAPE: 27,
HOME: 36,
LEFT: 37,
NUMPAD_ADD: 107,
NUMPAD_DECIMAL: 110,
NUMPAD_DIVIDE: 111,
NUMPAD_ENTER: 108,
NUMPAD_MULTIPLY: 106,
NUMPAD_SUBTRACT: 109,
PAGE_DOWN: 34,
PAGE_UP: 33,
PERIOD: 190,
RIGHT: 39,
SPACE: 32,
TAB: 9,
UP: 38,
};
export const Status = {
SUCCESS: 1,
WRONG: 2,
START: 3,
END: 4,
WAITING: 5,
READY: 6,
RUNNING: 7,
OUTOFBOUNDS: 8,
NULL: -1,
};
export const Direction = {
Top: "top",
Bottom: "bottom",
Left: "left",
Right: "right",
Custom: "custom",
};
export const Axis = {
Vertical: "vertical",
Horizontal: "horizontal",
};
export const Selection = {
Default: -2,
None: -1,
Single: 0,
Multi: 1,
All: 2,
};
export const HorizontalAlign = {
Left: "left",
Right: "right",
Center: "center",
Stretch: "stretch",
};
export const VerticalAlign = {
Middle: "middle",
Top: "top",
Bottom: "bottom",
Stretch: "stretch",
};
export const StartOfWeek = 1;
export const BlankSplitChar = "\u200b \u200b";
// 一定返回最终的单位
export function pixFormat(pix, border) {
if (!isNumber(pix)) {
return pix;
}
if (pixUnit === "px") {
return (pix / pixRatio - (border || 0)) + pixUnit;
}
const length = pix / pixRatio + pixUnit;
if (border > 0) {
return `calc(${length} - ${`${border}px`})`;
}
return length;
}
export function toPix(pix, border) {
if (!isNumber(pix)) {
return pix; return pix;
}, }
emptyFn: function () { if (pixUnit === "px") {
}, return pix - (border || 0) * pixRatio;
empty: null, }
Key: { if (border > 0) {
48: "0", return `calc(${pix / pixRatio + pixUnit} - ${`${border}px`})`;
49: "1", }
50: "2",
51: "3", return pix;
52: "4", }
53: "5",
54: "6", export function emptyFn() {}
55: "7",
56: "8",
57: "9",
65: "a",
66: "b",
67: "c",
68: "d",
69: "e",
70: "f",
71: "g",
72: "h",
73: "i",
74: "j",
75: "k",
76: "l",
77: "m",
78: "n",
79: "o",
80: "p",
81: "q",
82: "r",
83: "s",
84: "t",
85: "u",
86: "v",
87: "w",
88: "x",
89: "y",
90: "z",
96: "0",
97: "1",
98: "2",
99: "3",
100: "4",
101: "5",
102: "6",
103: "7",
104: "8",
105: "9",
106: "*",
107: "+",
109: "-",
110: ".",
111: "/"
},
KeyCode: {
BACKSPACE: 8,
COMMA: 188,
DELETE: 46,
DOWN: 40,
END: 35,
ENTER: 13,
ESCAPE: 27,
HOME: 36,
LEFT: 37,
NUMPAD_ADD: 107,
NUMPAD_DECIMAL: 110,
NUMPAD_DIVIDE: 111,
NUMPAD_ENTER: 108,
NUMPAD_MULTIPLY: 106,
NUMPAD_SUBTRACT: 109,
PAGE_DOWN: 34,
PAGE_UP: 33,
PERIOD: 190,
RIGHT: 39,
SPACE: 32,
TAB: 9,
UP: 38
},
Status: {
SUCCESS: 1,
WRONG: 2,
START: 3,
END: 4,
WAITING: 5,
READY: 6,
RUNNING: 7,
OUTOFBOUNDS: 8,
NULL: -1
},
Direction: {
Top: "top",
Bottom: "bottom",
Left: "left",
Right: "right",
Custom: "custom"
},
Axis: {
Vertical: "vertical",
Horizontal: "horizontal"
},
Selection: {
Default: -2,
None: -1,
Single: 0,
Multi: 1,
All: 2
},
HorizontalAlign: {
Left: "left",
Right: "right",
Center: "center",
Stretch: "stretch"
},
VerticalAlign: {
Middle: "middle",
Top: "top",
Bottom: "bottom",
Stretch: "stretch"
},
StartOfWeek: 1,
BlankSplitChar: "\u200b \u200b",
});

4
src/core/controller/0.controller.js

@ -2,11 +2,9 @@
* guy * guy
* 控制器 * 控制器
* Controller层超类 * Controller层超类
* @class BI.Controller
* @extends BI.OB
* @abstract
*/ */
import { OB } from "../3.ob"; import { OB } from "../3.ob";
export class Controller extends OB { export class Controller extends OB {
static EVENT_CHANGE = "__EVENT_CHANGE__"; static EVENT_CHANGE = "__EVENT_CHANGE__";
} }

9
src/core/controller/controller.broadcast.js

@ -2,9 +2,10 @@
* 广播 * 广播
* *
* Created by GUY on 2015/12/23. * Created by GUY on 2015/12/23.
* @class
*/ */
import { Controller } from "./0.controller"; import { Controller } from "./0.controller";
import { each, remove } from "../2.base";
export class BroadcastController extends Controller { export class BroadcastController extends Controller {
init() { init() {
this._broadcasts = {}; this._broadcasts = {};
@ -15,23 +16,25 @@ export class BroadcastController extends Controller {
this._broadcasts[name] = []; this._broadcasts[name] = [];
} }
this._broadcasts[name].push(fn); this._broadcasts[name].push(fn);
return () => this.remove(name, fn); return () => this.remove(name, fn);
} }
send(name) { send(name) {
const args = [].slice.call(arguments, 1); const args = [].slice.call(arguments, 1);
BI.each(this._broadcasts[name], (i, fn) => fn.apply(null, args)); each(this._broadcasts[name], (i, fn) => fn(...args));
} }
remove(name, fn) { remove(name, fn) {
if (fn) { if (fn) {
BI.remove(this._broadcasts[name], (index, cb) => fn === cb); remove(this._broadcasts[name], (index, cb) => fn === cb);
if (this._broadcasts[name].length === 0) { if (this._broadcasts[name].length === 0) {
delete this._broadcasts[name]; delete this._broadcasts[name];
} }
} else { } else {
delete this._broadcasts[name]; delete this._broadcasts[name];
} }
return this; return this;
} }
} }

38
src/core/controller/controller.bubbles.js

@ -3,9 +3,11 @@
* 控制气泡图的显示方向 * 控制气泡图的显示方向
* *
* Created by GUY on 2015/8/21. * Created by GUY on 2015/8/21.
* @class
*/ */
import { Controller } from "./0.controller"; import { Controller } from "./0.controller";
import { isNotNull, each } from "../2.base";
import { createWidget } from "../5.inject";
export class BubblesController extends Controller { export class BubblesController extends Controller {
init() { init() {
this.storeBubbles = {}; this.storeBubbles = {};
@ -30,12 +32,12 @@ export class BubblesController extends Controller {
// const fixed = opt.fixed !== false; // const fixed = opt.fixed !== false;
if (!this.storeBubbles[name]) { if (!this.storeBubbles[name]) {
this.storeBubbles[name] = BI.createWidget({ this.storeBubbles[name] = createWidget({
type: "bi.text", type: "bi.text",
cls: "bi-bubble" + " bubble-" + level, cls: `bi-bubble bubble-${level}`,
text: text, text,
hgap: 5, hgap: 5,
height: 18 height: 18,
}); });
} }
const bubble = this.storeBubbles[name]; const bubble = this.storeBubbles[name];
@ -43,14 +45,14 @@ export class BubblesController extends Controller {
bubble.setText(text); bubble.setText(text);
} }
BI.createWidget({ createWidget({
type: "bi.default", type: "bi.default",
element: container, element: container,
items: [ items: [
{ {
el: bubble el: bubble,
} }
] ],
}); });
if (this.storePoppers[name]) { if (this.storePoppers[name]) {
this.storePoppers[name].destroy(); this.storePoppers[name].destroy();
@ -59,32 +61,34 @@ export class BubblesController extends Controller {
placement: ({ placement: ({
left: "top-start", left: "top-start",
center: "top", center: "top",
right: "top-end" right: "top-end",
})[offsetStyle], })[offsetStyle],
strategy: "fixed", strategy: "fixed",
modifiers: [ modifiers: [
{ {
name: "offset", name: "offset",
options: { options: {
offset: [adjustXOffset, adjustYOffset] offset: [adjustXOffset, adjustYOffset],
} },
}, },
{ {
name: "preventOverflow", name: "preventOverflow",
enabled: false enabled: false,
} }
] ],
}); });
return this; return this;
} }
hide(name) { hide(name) {
this.remove(name); this.remove(name);
return this; return this;
} }
has(name) { has(name) {
return this.storeBubbles[name] != null; return isNotNull(this.storeBubbles[name]);
} }
remove(name) { remove(name) {
@ -94,14 +98,16 @@ export class BubblesController extends Controller {
this.storeBubbles[name].destroy(); this.storeBubbles[name].destroy();
this.storePoppers[name] && this.storePoppers[name].destroy(); this.storePoppers[name] && this.storePoppers[name].destroy();
delete this.storeBubbles[name]; delete this.storeBubbles[name];
return this; return this;
} }
removeAll() { removeAll() {
BI.each(this.storeBubbles, (name, bubble) => bubble.destroy()); each(this.storeBubbles, (name, bubble) => bubble.destroy());
BI.each(this.storePoppers, (name, popper) => popper.destroy()); each(this.storePoppers, (name, popper) => popper.destroy());
this.storeBubbles = {}; this.storeBubbles = {};
this.storePoppers = {}; this.storePoppers = {};
return this; return this;
} }
} }

38
src/core/controller/controller.drawer.js

@ -1,10 +1,11 @@
/** /**
* guy * guy
* popover弹出层控制器, z-index在100w层级 * popover弹出层控制器, z-index在100w层级
* @class BI.popoverController
* @extends BI.Controller
*/ */
import { Controller } from "./0.controller"; import { Controller } from "./0.controller";
import { each, isNotNull } from "../2.base";
import { createWidget } from "../5.inject";
export class DrawerController extends Controller { export class DrawerController extends Controller {
constructor() { constructor() {
super(); super();
@ -13,7 +14,7 @@ export class DrawerController extends Controller {
} }
props = { props = {
modal: true, // 模态窗口 modal: true, // 模态窗口
render: "body" render: "body",
} }
init() { init() {
@ -28,15 +29,15 @@ export class DrawerController extends Controller {
if (this.has(name)) { if (this.has(name)) {
return this; return this;
} }
const popover = BI.createWidget(options || {}, { const popover = createWidget(options || {}, {
type: "bi.drawer" type: "bi.drawer",
}, context); }, context);
this.add(name, popover, options, context); this.add(name, popover, options, context);
return this; return this;
} }
open(name) { open(name) {
const o = this.options;
if (!this.has(name)) { if (!this.has(name)) {
return this; return this;
} }
@ -59,6 +60,7 @@ export class DrawerController extends Controller {
const popover = this.get(name); const popover = this.get(name);
popover.show && popover.show(); popover.show && popover.show();
} }
return this; return this;
} }
@ -71,6 +73,7 @@ export class DrawerController extends Controller {
this.floatContainer[name].invisible(); this.floatContainer[name].invisible();
this.modal && this.floatContainer[name].element.__releaseZIndexMask__(this.zindexMap[name]); this.modal && this.floatContainer[name].element.__releaseZIndexMask__(this.zindexMap[name]);
} }
return this; return this;
} }
@ -91,23 +94,23 @@ export class DrawerController extends Controller {
if (this.has(name)) { if (this.has(name)) {
return this; return this;
} }
this.floatContainer[name] = BI.createWidget({ this.floatContainer[name] = createWidget({
type: "bi.absolute", type: "bi.absolute",
cls: "bi-popup-view", cls: "bi-popup-view",
items: [{ items: [{
el: (this.floatLayer[name] = BI.createWidget({ el: (this.floatLayer[name] = createWidget({
type: "bi.absolute", type: "bi.absolute",
items: [popover] items: [popover],
}, context)), }, context)),
left: 0, left: 0,
right: 0, right: 0,
top: 0, top: 0,
bottom: 0 bottom: 0,
}] }],
}); });
this.floatManager[name] = popover; this.floatManager[name] = popover;
popover.on(BI.Drawer.EVENT_CLOSE, () => this.close(name)); popover.on(BI.Drawer.EVENT_CLOSE, () => this.close(name));
BI.createWidget({ createWidget({
type: "bi.absolute", type: "bi.absolute",
element: options.container || this.options.render, element: options.container || this.options.render,
items: [{ items: [{
@ -115,9 +118,10 @@ export class DrawerController extends Controller {
left: 0, left: 0,
right: 0, right: 0,
top: 0, top: 0,
bottom: 0 bottom: 0,
}] }],
}); });
return this; return this;
} }
@ -126,7 +130,7 @@ export class DrawerController extends Controller {
} }
has(name) { has(name) {
return BI.isNotNull(this.floatManager[name]); return isNotNull(this.floatManager[name]);
} }
remove(name) { remove(name) {
@ -140,11 +144,12 @@ export class DrawerController extends Controller {
delete this.zindexMap[name]; delete this.zindexMap[name];
delete this.floatContainer[name]; delete this.floatContainer[name];
delete this.floatOpened[name]; delete this.floatOpened[name];
return this; return this;
} }
removeAll() { removeAll() {
BI.each(this.floatContainer, (name, container) => { each(this.floatContainer, (name, container) => {
container.destroy(); container.destroy();
this.modal && this.floatContainer[name].element.__releaseZIndexMask__(this.zindexMap[name]); this.modal && this.floatContainer[name].element.__releaseZIndexMask__(this.zindexMap[name]);
}); });
@ -153,6 +158,7 @@ export class DrawerController extends Controller {
this.floatContainer = {}; this.floatContainer = {};
this.floatOpened = {}; this.floatOpened = {};
this.zindexMap = {}; this.zindexMap = {};
return this; return this;
} }
} }

55
src/core/controller/controller.layer.js

@ -2,9 +2,12 @@
* 弹出层面板控制器, z-index在10w层级 * 弹出层面板控制器, z-index在10w层级
* *
* Created by GUY on 2015/6/24. * Created by GUY on 2015/6/24.
* @class
*/ */
import { Controller } from "./0.controller"; import { Controller } from "./0.controller";
import { isNull, isNotNull, each, keys, isWidget, isNotEmptyString, extend } from "../2.base";
import { Widget } from "../4.widget";
import { createWidget } from "../5.inject";
export class LayerController extends Controller { export class LayerController extends Controller {
constructor() { constructor() {
super(); super();
@ -12,7 +15,7 @@ export class LayerController extends Controller {
} }
props = { props = {
render: "body" render: "body",
} }
init() { init() {
@ -22,11 +25,11 @@ export class LayerController extends Controller {
} }
_initResizer() { _initResizer() {
this.resizer = BI.Resizers.add("layerController" + BI.uniqueId(), BI.bind(this._resize, this)); this.resizer = BI.Resizers.add(`layerController${BI.uniqueId()}`, BI.bind(this._resize, this));
} }
_resize() { _resize() {
BI.each(this.layouts, function (i, layer) { each(this.layouts, (i, layer) => {
if (layer.element.is(":visible")) { if (layer.element.is(":visible")) {
layer.element.trigger("__resize__"); layer.element.trigger("__resize__");
} }
@ -34,37 +37,38 @@ export class LayerController extends Controller {
} }
make(name, container, op, context) { make(name, container, op, context) {
if (BI.isWidget(container)) { if (isWidget(container)) {
op = op || {}; op = op || {};
op.container = container; op.container = container;
} else { } else {
context = op; context = op;
op = container; op = container;
} }
return this.create(name, null, op, context); return this.create(name, null, op, context);
} }
create(name, from, op, context) { create(name, from, op, context) {
BI.isNull(this.resizer) && this._initResizer(); isNull(this.resizer) && this._initResizer();
if (this.has(name)) { if (this.has(name)) {
return this.get(name); return this.get(name);
} }
op || (op = {}); op || (op = {});
const offset = op.offset || {}; const offset = op.offset || {};
let w = from; let w = from;
if (BI.isWidget(from)) { if (isWidget(from)) {
w = from.element; w = from.element;
} }
if (BI.isNotEmptyString(w)) { if (isNotEmptyString(w)) {
w = BI.Widget._renderEngine.createElement(w); w = Widget._renderEngine.createElement(w);
} }
if (this.has(name)) { if (this.has(name)) {
return this.get(name); return this.get(name);
} }
const widget = BI.createWidget((op.render || {}), BI.extend({ const widget = createWidget((op.render || {}), extend({
type: "bi.layout" type: "bi.layout",
}, op), context); }, op), context);
const layout = BI.createWidget({ const layout = createWidget({
type: "bi.absolute", type: "bi.absolute",
invisible: true, invisible: true,
items: [ items: [
@ -73,11 +77,11 @@ export class LayerController extends Controller {
left: 0, left: 0,
right: 0, right: 0,
top: 0, top: 0,
bottom: 0 bottom: 0,
} }
] ],
}, context); }, context);
BI.createWidget({ createWidget({
type: "bi.absolute", type: "bi.absolute",
element: op.container || this.options.render, element: op.container || this.options.render,
items: [ items: [
@ -86,20 +90,19 @@ export class LayerController extends Controller {
left: offset.left || 0, left: offset.left || 0,
right: offset.right || 0, right: offset.right || 0,
top: offset.top || 0, top: offset.top || 0,
bottom: offset.bottom || 0 bottom: offset.bottom || 0,
} }
] ],
}); });
if (w) { if (w) {
layout.element.addClass("bi-popup-view"); layout.element.addClass("bi-popup-view");
function getComputedPosition() { function getComputedPosition() {
const css = {
var css = {
left: w.offset().left + (offset.left || 0), left: w.offset().left + (offset.left || 0),
top: w.offset().top + (offset.top || 0), top: w.offset().top + (offset.top || 0),
width: offset.width || (w.outerWidth() - (offset.left || 0) - (offset.right || 0)) || "", width: offset.width || (w.outerWidth() - (offset.left || 0) - (offset.right || 0)) || "",
height: offset.height || (w.outerHeight() - (offset.top || 0) - (offset.bottom || 0)) || "" height: offset.height || (w.outerHeight() - (offset.top || 0) - (offset.bottom || 0)) || "",
}; };
const { top, left, scaleY, scaleX } = BI.DOM.getPositionRelativeContainingBlockRect(layout.element[0]); const { top, left, scaleY, scaleX } = BI.DOM.getPositionRelativeContainingBlockRect(layout.element[0]);
@ -112,12 +115,13 @@ export class LayerController extends Controller {
layout.element.css(getComputedPosition()); layout.element.css(getComputedPosition());
layout.element.on("__resize__", function () { layout.element.on("__resize__", () => {
w.is(":visible") && w.is(":visible") &&
layout.element.css(getComputedPosition()); layout.element.css(getComputedPosition());
}); });
} }
this.add(name, widget, layout); this.add(name, widget, layout);
return widget; return widget;
} }
@ -127,6 +131,7 @@ export class LayerController extends Controller {
} }
this._getLayout(name).visible(); this._getLayout(name).visible();
this._getLayout(name).element.css("z-index", this.zindex++).show(0, callback).trigger("__resize__"); this._getLayout(name).element.css("z-index", this.zindex++).show(0, callback).trigger("__resize__");
return this; return this;
} }
@ -136,6 +141,7 @@ export class LayerController extends Controller {
} }
this._getLayout(name).invisible(); this._getLayout(name).invisible();
this._getLayout(name).element.hide(0, callback); this._getLayout(name).element.hide(0, callback);
return this; return this;
} }
@ -151,6 +157,7 @@ export class LayerController extends Controller {
this.layerManager[name] = layer; this.layerManager[name] = layer;
this.layouts[name] = layout; this.layouts[name] = layout;
layout.element.css("z-index", this.zindex++); layout.element.css("z-index", this.zindex++);
return this; return this;
} }
@ -163,7 +170,7 @@ export class LayerController extends Controller {
} }
has(name) { has(name) {
return this.layerManager[name] != null; return isNotNull(this.layerManager[name]);
} }
remove(name) { remove(name) {
@ -174,16 +181,18 @@ export class LayerController extends Controller {
this.layouts[name].destroy(); this.layouts[name].destroy();
delete this.layerManager[name]; delete this.layerManager[name];
delete this.layouts[name]; delete this.layouts[name];
return this; return this;
} }
removeAll() { removeAll() {
BI.each(BI.keys(this.layerManager), (index, name) => { each(keys(this.layerManager), (index, name) => {
this.layerManager[name].destroy(); this.layerManager[name].destroy();
this.layouts[name].destroy(); this.layouts[name].destroy();
}); });
this.layerManager = {}; this.layerManager = {};
this.layouts = {}; this.layouts = {};
return this; return this;
} }
} }

2
src/core/controller/controller.masker.js

@ -2,9 +2,9 @@
* 遮罩面板, z-index在1亿层级 * 遮罩面板, z-index在1亿层级
* *
* Created by GUY on 2015/6/24. * Created by GUY on 2015/6/24.
* @class
*/ */
import { LayerController } from "./controller.layer"; import { LayerController } from "./controller.layer";
export class MaskersController extends LayerController { export class MaskersController extends LayerController {
init() { init() {
super.init(arguments); super.init(arguments);

46
src/core/controller/controller.popover.js

@ -1,10 +1,12 @@
/** /**
* guy * guy
* popover弹出层控制器, z-index在100w层级 * popover弹出层控制器, z-index在100w层级
* @class BI.popoverController
* @extends BI.Controller
*/ */
import { Controller } from "./0.controller"; import { Controller } from "./0.controller";
import { isNotNull, each } from "../2.base";
import { Widget } from "../4.widget";
import { createWidget } from "../5.inject";
export class PopoverController extends Controller { export class PopoverController extends Controller {
constructor() { constructor() {
super(); super();
@ -14,7 +16,7 @@ export class PopoverController extends Controller {
props = { props = {
modal: true, // 模态窗口 modal: true, // 模态窗口
render: "body" render: "body",
} }
init() { init() {
@ -30,10 +32,11 @@ export class PopoverController extends Controller {
if (this.has(name)) { if (this.has(name)) {
return this; return this;
} }
const popover = BI.createWidget(options || {}, { const popover = createWidget(options || {}, {
type: "bi.popover" type: "bi.popover",
}, context); }, context);
this.add(name, popover, options, context); this.add(name, popover, options, context);
return this; return this;
} }
@ -52,8 +55,8 @@ export class PopoverController extends Controller {
this.floatContainer[name].visible(); this.floatContainer[name].visible();
const popover = this.get(name); const popover = this.get(name);
popover.show && popover.show(); popover.show && popover.show();
const W = BI.Widget._renderEngine.createElement(this.options.render).width(), const W = Widget._renderEngine.createElement(this.options.render).width(),
H = BI.Widget._renderEngine.createElement(this.options.render).height(); H = Widget._renderEngine.createElement(this.options.render).height();
const w = popover.element.width(), h = popover.element.height(); const w = popover.element.width(), h = popover.element.height();
let left = (W - w) / 2, top = (H - h) / 2; let left = (W - w) / 2, top = (H - h) / 2;
if (left < 0) { if (left < 0) {
@ -64,10 +67,11 @@ export class PopoverController extends Controller {
} }
popover.element.css({ popover.element.css({
// 这里直接用px就可以 // 这里直接用px就可以
left: left + "px", left: `${left}px`,
top: top + "px" top: `${top}px`,
}); });
} }
return this; return this;
} }
@ -80,6 +84,7 @@ export class PopoverController extends Controller {
this.floatContainer[name].invisible(); this.floatContainer[name].invisible();
this.modal && this.floatContainer[name].element.__releaseZIndexMask__(this.zindexMap[name]); this.modal && this.floatContainer[name].element.__releaseZIndexMask__(this.zindexMap[name]);
} }
return this; return this;
} }
@ -100,23 +105,23 @@ export class PopoverController extends Controller {
if (this.has(name)) { if (this.has(name)) {
return this; return this;
} }
this.floatContainer[name] = BI.createWidget({ this.floatContainer[name] = createWidget({
type: "bi.absolute", type: "bi.absolute",
cls: "bi-popup-view", cls: "bi-popup-view",
items: [{ items: [{
el: (this.floatLayer[name] = BI.createWidget({ el: (this.floatLayer[name] = createWidget({
type: "bi.absolute", type: "bi.absolute",
items: [popover] items: [popover],
}, context)), }, context)),
left: 0, left: 0,
right: 0, right: 0,
top: 0, top: 0,
bottom: 0 bottom: 0,
}] }],
}); });
this.floatManager[name] = popover; this.floatManager[name] = popover;
popover.on(BI.Popover.EVENT_CLOSE, () => this.close(name)); popover.on(BI.Popover.EVENT_CLOSE, () => this.close(name));
BI.createWidget({ createWidget({
type: "bi.absolute", type: "bi.absolute",
element: options.container || this.options.render, element: options.container || this.options.render,
items: [{ items: [{
@ -124,9 +129,10 @@ export class PopoverController extends Controller {
left: 0, left: 0,
right: 0, right: 0,
top: 0, top: 0,
bottom: 0 bottom: 0,
}] }],
}); });
return this; return this;
} }
@ -135,7 +141,7 @@ export class PopoverController extends Controller {
} }
has(name) { has(name) {
return BI.isNotNull(this.floatManager[name]); return isNotNull(this.floatManager[name]);
} }
remove(name) { remove(name) {
@ -149,11 +155,12 @@ export class PopoverController extends Controller {
delete this.zindexMap[name]; delete this.zindexMap[name];
delete this.floatContainer[name]; delete this.floatContainer[name];
delete this.floatOpened[name]; delete this.floatOpened[name];
return this; return this;
} }
removeAll() { removeAll() {
BI.each(this.floatContainer, (name, container) => { each(this.floatContainer, (name, container) => {
container.destroy(); container.destroy();
this.modal && this.floatContainer[name].element.__releaseZIndexMask__(this.zindexMap[name]); this.modal && this.floatContainer[name].element.__releaseZIndexMask__(this.zindexMap[name]);
}); });
@ -162,6 +169,7 @@ export class PopoverController extends Controller {
this.floatContainer = {}; this.floatContainer = {};
this.floatOpened = {}; this.floatOpened = {};
this.zindexMap = {}; this.zindexMap = {};
return this; return this;
} }

21
src/core/controller/controller.resizer.js

@ -2,49 +2,53 @@
* window.resize 控制器 * window.resize 控制器
* *
* Created by GUY on 2015/6/24. * Created by GUY on 2015/6/24.
* @class
*/ */
import { Controller } from "./0.controller"; import { Controller } from "./0.controller";
export class ResizeController extends Controller { import { isNull, each, debounce, isNotNull, isFunction } from "../2.base";
import { Widget } from "../4.widget";
export class ResizeController extends Controller {
init() { init() {
this.resizerManger = {}; this.resizerManger = {};
} }
_initResizeListener() { _initResizeListener() {
this.resizeHandler = BI.debounce((ev) => this._resize(ev), 30); this.resizeHandler = debounce(ev => this._resize(ev), 30);
if ("onorientationchange" in _global) { if ("onorientationchange" in _global) {
_global.onorientationchange = this.resizeHandler; _global.onorientationchange = this.resizeHandler;
} else { } else {
BI.Widget._renderEngine.createElement(_global).resize(this.resizeHandler); Widget._renderEngine.createElement(_global).resize(this.resizeHandler);
} }
} }
_resize(ev) { _resize(ev) {
BI.each(this.resizerManger, function (key, resizer) { each(this.resizerManger, (key, resizer) => {
if (resizer instanceof BI.$) { if (resizer instanceof BI.$) {
if (resizer.is(":visible")) { if (resizer.is(":visible")) {
resizer.trigger("__resize__"); resizer.trigger("__resize__");
} }
return; return;
} }
if (resizer instanceof BI.Layout) { if (resizer instanceof BI.Layout) {
resizer.resize(); resizer.resize();
return; return;
} }
if (BI.isFunction(resizer)) { if (isFunction(resizer)) {
resizer(ev); resizer(ev);
} }
}); });
} }
add(name, resizer) { add(name, resizer) {
BI.isNull(this.resizeHandler) && this._initResizeListener(); isNull(this.resizeHandler) && this._initResizeListener();
if (this.has(name)) { if (this.has(name)) {
return this; return this;
} }
this.resizerManger[name] = resizer; this.resizerManger[name] = resizer;
return () => this.remove(name); return () => this.remove(name);
} }
@ -53,7 +57,7 @@ export class ResizeController extends Controller {
} }
has(name) { has(name) {
return this.resizerManger[name] != null; return isNotNull(this.resizerManger[name]);
} }
remove(name) { remove(name) {
@ -61,6 +65,7 @@ export class ResizeController extends Controller {
return this; return this;
} }
delete this.resizerManger[name]; delete this.resizerManger[name];
return this; return this;
} }
} }

40
src/core/controller/controller.tooltips.js

@ -3,10 +3,12 @@
* 控制tooltip的显示, 且页面中只有一个tooltip显示 * 控制tooltip的显示, 且页面中只有一个tooltip显示
* *
* Created by GUY on 2015/9/8. * Created by GUY on 2015/9/8.
* @class BI.TooltipsController
* @extends BI.Controller
*/ */
import { Controller } from "./0.controller"; import { Controller } from "./0.controller";
import { each, isNotNull } from "../2.base";
import { Widget } from "../4.widget";
import { createWidget } from "../5.inject";
export class TooltipsController extends Controller { export class TooltipsController extends Controller {
init() { init() {
this.tooltipsManager = {}; this.tooltipsManager = {};
@ -23,17 +25,17 @@ export class TooltipsController extends Controller {
* @private * @private
*/ */
_createTooltip(opt) { _createTooltip(opt) {
return BI.createWidget({ return createWidget({
type: "bi.tooltip", type: "bi.tooltip",
...opt, ...opt,
stopEvent: true stopEvent: true,
}); });
} }
// opt: {container: '', belowMouse: false} // opt: {container: '', belowMouse: false}
show(e, name, tooltipOpt, context, opt) { show(e, name, tooltipOpt, context, opt) {
opt || (opt = {}); opt || (opt = {});
BI.each(this.showingTips, (i, tip) => this.hide(i)); each(this.showingTips, (i, tip) => this.hide(i));
this.showingTips = {}; this.showingTips = {};
if (!this.has(name)) { if (!this.has(name)) {
this.create(name, tooltipOpt, document.fullscreenElement ? context : (opt.container || "body")); this.create(name, tooltipOpt, document.fullscreenElement ? context : (opt.container || "body"));
@ -51,7 +53,7 @@ export class TooltipsController extends Controller {
const tooltip = this.get(name); const tooltip = this.get(name);
tooltip.element.css({ tooltip.element.css({
left: "0px", left: "0px",
top: "0px" top: "0px",
}); });
tooltip.visible(); tooltip.visible();
tooltip.element.height(tooltip.element[0].scrollHeight); tooltip.element.height(tooltip.element[0].scrollHeight);
@ -60,10 +62,10 @@ export class TooltipsController extends Controller {
// const scale = context.element.offset().left / context.element.get(0).getBoundingClientRect().left; // const scale = context.element.offset().left / context.element.get(0).getBoundingClientRect().left;
// const x = (e.pageX || e.clientX) * scale + 15, y = (e.pageY || e.clientY) * scale + 15; // const x = (e.pageX || e.clientX) * scale + 15, y = (e.pageY || e.clientY) * scale + 15;
let x = (e.pageX || e.clientX) + 15, y = (e.pageY || e.clientY) + 15; let x = (e.pageX || e.clientX) + 15, y = (e.pageY || e.clientY) + 15;
if (x + tooltip.element.outerWidth() > BI.Widget._renderEngine.createElement("body").outerWidth()) { if (x + tooltip.element.outerWidth() > Widget._renderEngine.createElement("body").outerWidth()) {
x -= tooltip.element.outerWidth() + 15; x -= tooltip.element.outerWidth() + 15;
} }
const bodyHeight = BI.Widget._renderEngine.createElement("body").outerHeight(); const bodyHeight = Widget._renderEngine.createElement("body").outerHeight();
if (y + tooltip.element.outerHeight() > bodyHeight || top + tooltip.element.outerHeight() > bodyHeight) { if (y + tooltip.element.outerHeight() > bodyHeight || top + tooltip.element.outerHeight() > bodyHeight) {
y -= tooltip.element.outerHeight() + 15; y -= tooltip.element.outerHeight() + 15;
!opt.belowMouse && (y = Math.min(y, offset.top - tooltip.element.outerHeight() - 5)); !opt.belowMouse && (y = Math.min(y, offset.top - tooltip.element.outerHeight() - 5));
@ -72,13 +74,14 @@ export class TooltipsController extends Controller {
} }
tooltip.element.css({ tooltip.element.css({
// 这里直接用px就可以 // 这里直接用px就可以
left: x < 0 ? 0 : x + "px", left: x < 0 ? 0 : `${x}px`,
top: y < 0 ? 0 : y + "px" top: y < 0 ? 0 : `${y}px`,
}); });
tooltip.element.hover(() => { tooltip.element.hover(() => {
this.remove(name); this.remove(name);
context.element.trigger("mouseleave.title" + context.getName()); context.element.trigger(`mouseleave.title${context.getName()}`);
}); });
return this; return this;
} }
@ -89,6 +92,7 @@ export class TooltipsController extends Controller {
delete this.showingTips[name]; delete this.showingTips[name];
this.get(name).element.hide(0, callback); this.get(name).element.hide(0, callback);
this.get(name).invisible(); this.get(name).invisible();
return this; return this;
} }
@ -96,15 +100,16 @@ export class TooltipsController extends Controller {
if (!this.has(name)) { if (!this.has(name)) {
const tooltip = this._createTooltip(tooltipOpt); const tooltip = this._createTooltip(tooltipOpt);
this.add(name, tooltip); this.add(name, tooltip);
BI.createWidget({ createWidget({
type: "bi.absolute", type: "bi.absolute",
element: context || "body", element: context || "body",
items: [{ items: [{
el: tooltip el: tooltip,
}] }],
}); });
tooltip.invisible(); tooltip.invisible();
} }
return this.get(name); return this.get(name);
} }
@ -113,6 +118,7 @@ export class TooltipsController extends Controller {
return this; return this;
} }
this.set(name, bubble); this.set(name, bubble);
return this; return this;
} }
@ -125,7 +131,7 @@ export class TooltipsController extends Controller {
} }
has(name) { has(name) {
return this.tooltipsManager[name] != null; return isNotNull(this.tooltipsManager[name]);
} }
remove(name) { remove(name) {
@ -134,15 +140,17 @@ export class TooltipsController extends Controller {
} }
this.tooltipsManager[name].destroy(); this.tooltipsManager[name].destroy();
delete this.tooltipsManager[name]; delete this.tooltipsManager[name];
return this; return this;
} }
removeAll() { removeAll() {
BI.each(this.tooltipsManager, function (name, tooltip) { each(this.tooltipsManager, (name, tooltip) => {
tooltip.destroy(); tooltip.destroy();
}); });
this.tooltipsManager = {}; this.tooltipsManager = {};
this.showingTips = {}; this.showingTips = {};
return this; return this;
} }
} }

124
src/core/element/element.js

@ -1,74 +1,76 @@
import { registFunction } from './plugins'; import { registFunction } from "./plugins";
import { isWidget, isString } from "../2.base";
export function Element(widget, attribs) { export function Element(widget, attribs) {
this.l = this.r = this.t = this.b = 0; // 边框 this.l = this.r = this.t = this.b = 0; // 边框
this.marginLeft = this.marginRight = this.marginTop = this.marginBottom = 0; //间距 this.marginLeft = this.marginRight = this.marginTop = this.marginBottom = 0; // 间距
this.position = {}; this.position = {};
this.classMap = {}; this.classMap = {};
this.classList = []; this.classList = [];
this.children = []; this.children = [];
this.attribs = attribs || {}; this.attribs = attribs || {};
this.styles = {}; this.styles = {};
// 兼容处理 // 兼容处理
this['0'] = this; this["0"] = this;
this.style = {}; this.style = {};
if (!widget) { if (!widget) {
this.nodeName = 'body'; this.nodeName = "body";
this.position.x = 0; this.position.x = 0;
this.position.y = 0; this.position.y = 0;
this.attribs.id = 'body'; this.attribs.id = "body";
} else if (BI.isWidget(widget)) { } else if (isWidget(widget)) {
this.widget = widget; this.widget = widget;
this.nodeName = widget.options.tagName; this.nodeName = widget.options.tagName;
this.textBaseLine = widget.options.textBaseLine; this.textBaseLine = widget.options.textBaseLine;
} else if (BI.isString(widget)) { } else if (isString(widget)) {
this.nodeName = widget; this.nodeName = widget;
} }
} }
initElement(Element); initElement(Element);
registFunction(Element); registFunction(Element);
function initElement(element) { function initElement(element) {
element.prototype = { element.prototype = {
appendChild(child) { appendChild(child) {
child.parent = this; child.parent = this;
if (this.children.push(child) !== 1) { if (this.children.push(child) !== 1) {
var sibling = this.children[this.children.length - 2]; const sibling = this.children[this.children.length - 2];
sibling.next = child; sibling.next = child;
child.prev = sibling; child.prev = sibling;
child.next = null; child.next = null;
} }
}, },
append(child) { append(child) {
child.parent = this; child.parent = this;
if (this.children.push(child) !== 1) { if (this.children.push(child) !== 1) {
var sibling = this.children[this.children.length - 2]; const sibling = this.children[this.children.length - 2];
sibling.next = child; sibling.next = child;
child.prev = sibling; child.prev = sibling;
child.next = null; child.next = null;
} }
}, },
getParent() { getParent() {
return this.parent; return this.parent;
}, },
getSiblings() { getSiblings() {
var parent = this.getParent(); const parent = this.getParent();
return parent ? parent.getChildren() : [this];
},
getChildren() {
return this.children;
},
getBounds() { return parent ? parent.getChildren() : [this];
return {}; },
}, getChildren() {
return this.children;
},
width() { getBounds() {
return {};
},
}, width() {
height() {
} },
}; height() {
},
};
} }

21
src/core/element/index.js

@ -1,16 +1,17 @@
import { Element } from './element'; import { Element } from "./element";
import { isString, isWidget } from "../2.base";
BI.Element = Element; BI.Element = Element;
BI.Element.renderEngine = { BI.Element.renderEngine = {
createElement: (widget) => { createElement: widget => {
// eslint-disable-next-line no-undef if (isWidget(widget)) {
if (BI.isWidget(widget)) { const o = widget.options;
var o = widget.options;
if (o.element instanceof Element) { if (o.element instanceof Element) {
return o.element; return o.element;
} }
if (typeof o.element === 'string' && o.element !== 'body') { if (typeof o.element === "string" && o.element !== "body") {
o.root = false; o.root = false;
return new Element(widget); return new Element(widget);
} }
@ -18,14 +19,14 @@ BI.Element.renderEngine = {
return new Element(); return new Element();
} }
} }
// eslint-disable-next-line no-undef if (isString(widget)) {
if (BI.isString(widget)) {
return new Element(widget); return new Element(widget);
} }
return new Element(widget); return new Element(widget);
}, },
createFragment() { createFragment() {
return new Element(); return new Element();
} },
} };

45
src/core/element/plugins/attr.js

@ -1,22 +1,25 @@
export const registAttrFun = (Element) => { import { isObject, each, isNull, isNotNull } from "../../2.base";
Element.registerFunction('attr', function (key, value) {
var self = this; export const registAttrFun = Element => {
if (BI.isObject(key)) { Element.registerFunction("attr", function (key, value) {
BI.each(key, (k, v) => { if (isObject(key)) {
self.attr(k, v); each(key, (k, v) => {
}); this.attr(k, v);
return this; });
}
if (BI.isNull(value)) { return this;
return this.attribs[key]; }
} if (isNull(value)) {
this.attribs[key] = value; return this.attribs[key];
return this; }
}); this.attribs[key] = value;
Element.registerFunction('hasAttrib', function (key) {
return this.attribs[key] != null; return this;
}); });
Element.registerFunction('removeAttr', function (key) { Element.registerFunction("hasAttrib", function (key) {
delete this.attribs[key]; return isNotNull(this.attribs[key]);
}); });
Element.registerFunction("removeAttr", function (key) {
delete this.attribs[key];
});
}; };

38
src/core/element/plugins/class.js

@ -1,23 +1,23 @@
export const registClassFun = (Element) => { export const registClassFun = Element => {
Element.registerFunction('addClass', function (classList) { Element.registerFunction("addClass", function (classList) {
var self = this; BI.each(classList.split(" "), (i, cls) => {
BI.each(classList.split(' '), (i, cls) => { if (cls && !this.classMap[cls]) {
if (cls && !self.classMap[cls]) { this.classList.push(cls);
self.classList.push(cls); }
} cls && (this.classMap[cls] = true);
cls && (self.classMap[cls] = true); });
return this;
}); });
return this;
});
Element.registerFunction('removeClass', function (classList) { Element.registerFunction("removeClass", function (classList) {
var self = this; BI.each(classList.split(" "), (i, cls) => {
BI.each(classList.split(' '), (i, cls) => { if (cls && this.classMap[cls]) {
if (cls && self.classMap[cls]) { delete this.classMap[cls];
delete self.classMap[cls]; this.classList.splice(this.classList.indexOf(cls), 1);
self.classList.splice(self.classList.indexOf(cls), 1); }
} });
return this;
}); });
return this;
});
}; };

40
src/core/element/plugins/css.js

@ -1,22 +1,26 @@
export const registCssFun = (Element) => { import { isNull, isObject, each, trim, camelize } from "../../2.base";
Element.registerFunction('css', function (key, value) {
var self = this; export const registCssFun = Element => {
if (BI.isObject(key)) { Element.registerFunction("css", function (key, value) {
BI.each(key, (k, v) => { if (isObject(key)) {
self.css(k, v); each(key, (k, v) => {
}); this.css(k, v);
return this; });
}
key = BI.trim(BI.camelize(key)); return this;
return css(this, key, value); }
}); key = trim(camelize(key));
return css(this, key, value);
});
}; };
const css = (elem, key, value) => { const css = (elem, key, value) => {
key = BI.trim(BI.camelize(key)); key = trim(camelize(key));
if (BI.isNull(value)) { if (isNull(value)) {
return elem.styles[key]; return elem.styles[key];
} }
elem.styles[key] = value; elem.styles[key] = value;
return elem;
return elem;
}; };

25
src/core/element/plugins/data.js

@ -1,12 +1,15 @@
export const registDataFun = (Element) => { import { isNull } from "../../2.base";
Element.registerFunction('data', function (key, value) {
if (!this._data) { export const registDataFun = Element => {
this._data = {}; Element.registerFunction("data", function (key, value) {
} if (!this._data) {
if (BI.isNull(value)) { this._data = {};
return this._data[key]; }
} if (isNull(value)) {
this._data[key] = value; return this._data[key];
return this; }
}); this._data[key] = value;
return this;
});
}; };

17
src/core/element/plugins/empty.js

@ -1,9 +1,10 @@
export const registEmptyFun = (Element) => { export const registEmptyFun = Element => {
Element.registerFunction('empty', function (text) { Element.registerFunction("empty", function (text) {
this.children = []; this.children = [];
return this;
}); return this;
Element.registerFunction('destroy', function (text) { });
return this; Element.registerFunction("destroy", function (text) {
}); return this;
});
}; };

63
src/core/element/plugins/event.js

@ -1,32 +1,33 @@
var returnThis = function () { function returnThis () {
return this; return this;
}; }
export const registEventFun = (Element) => {
[ export const registEventFun = Element => {
'mousedown', [
'mouseup', "mousedown",
'mousewheel', "mouseup",
'keydown', "mousewheel",
'keyup', "keydown",
'focus', "keyup",
'focusin', "focus",
'focusout', "focusin",
'click', "focusout",
'on', "click",
'off', "on",
'bind', "off",
'unbind', "bind",
'trigger', "unbind",
'hover', "trigger",
'scroll', "hover",
'scrollLeft', "scroll",
'scrollTop', "scrollLeft",
'resize', "scrollTop",
'show', "resize",
'hide', "show",
'dblclick', "hide",
'blur', "dblclick",
].forEach((event) => { "blur"
Element.registerFunction(event, returnThis); ].forEach(event => {
}); Element.registerFunction(event, returnThis);
});
}; };

32
src/core/element/plugins/html.js

@ -1,15 +1,19 @@
export const registHtmlFun = (Element) => { import { createWidget } from "../../5.inject";
Element.registerFunction('html', function (text) { import { htmlDecode } from "../../func";
if (text && text.charAt(0) === '<') {
BI.createWidget({ export const registHtmlFun = Element => {
type: 'bi.html', Element.registerFunction("html", function (text) {
element: this.widget, if (text && text.charAt(0) === "<") {
html: text, createWidget({
}); type: "bi.html",
this.originalHtml = text; element: this.widget,
} else { html: text,
this.text = BI.htmlDecode(text); });
} this.originalHtml = text;
return this; } else {
}); this.text = htmlDecode(text);
}
return this;
});
}; };

58
src/core/element/plugins/index.js

@ -1,31 +1,31 @@
import { registAttrFun } from './attr'; import { registAttrFun } from "./attr";
import { registClassFun } from './class'; import { registClassFun } from "./class";
import { registCssFun } from './css'; import { registCssFun } from "./css";
import { registDataFun } from './data'; import { registDataFun } from "./data";
import { registEmptyFun } from './empty'; import { registEmptyFun } from "./empty";
import { registEventFun } from './event'; import { registEventFun } from "./event";
import { registHtmlFun } from './html'; import { registHtmlFun } from "./html";
import { registKeywordMarkFun } from './keywordMark'; import { registKeywordMarkFun } from "./keywordMark";
import { registRenderToHtmlFun } from './renderToHtml'; import { registRenderToHtmlFun } from "./renderToHtml";
import { registRenderToStringFun } from './renderToString'; import { registRenderToStringFun } from "./renderToString";
import { registTextFun } from './text'; import { registTextFun } from "./text";
import { registValFun } from './val'; import { registValFun } from "./val";
export const registFunction = (Element) => { export const registFunction = Element => {
var functionMap = {}; const functionMap = {};
Element.registerFunction = (key, fn) => { Element.registerFunction = (key, fn) => {
Element.prototype[key] = functionMap[key] = fn; Element.prototype[key] = functionMap[key] = fn;
}; };
registAttrFun(Element); registAttrFun(Element);
registClassFun(Element); registClassFun(Element);
registCssFun(Element); registCssFun(Element);
registDataFun(Element); registDataFun(Element);
registEmptyFun(Element); registEmptyFun(Element);
registEventFun(Element); registEventFun(Element);
registHtmlFun(Element); registHtmlFun(Element);
registKeywordMarkFun(Element); registKeywordMarkFun(Element);
registRenderToStringFun(Element); registRenderToStringFun(Element);
registRenderToHtmlFun(Element); registRenderToHtmlFun(Element);
registTextFun(Element); registTextFun(Element);
registValFun(Element); registValFun(Element);
}; };

11
src/core/element/plugins/keywordMark.js

@ -1,6 +1,7 @@
export const registKeywordMarkFun = (Element) => { export const registKeywordMarkFun = Element => {
Element.registerFunction('__textKeywordMarked__', function (text) { Element.registerFunction("__textKeywordMarked__", function (text) {
this[0].textContent = text; this[0].textContent = text;
return this;
}); return this;
});
}; };

124
src/core/element/plugins/renderToHtml.js

@ -1,65 +1,69 @@
var skipArray = []; import { each, isNull, hyphenate, isNumeric, isKey } from "../../2.base";
var pxStyle = ['font-size', 'width', 'height'];
var _renderToHtml = function (root) { const skipArray = [];
var str = ''; const pxStyle = ["font-size", "width", "height"];
if (BI.isNull(root.originalHtml)) { function _renderToHtml(root) {
if (root.tag !== 'body') { let str = "";
str += `<${root.tag}`; if (isNull(root.originalHtml)) {
if (root.classList.length > 0) { if (root.tag !== "body") {
str += ' class="'; str += `<${root.tag}`;
BI.each(root.classList, (i, cls) => { if (root.classList.length > 0) {
str += ` ${cls}`; str += " class=\"";
}); each(root.classList, (i, cls) => {
str += '"'; str += ` ${cls}`;
} });
str += ' style="'; str += "\"";
BI.each(root.originalStyles, (key, stl) => { }
if ( str += " style=\"";
skipArray.contains(key) || each(root.originalStyles, (key, stl) => {
(key == 'height' && root.classList.contains('bi-design-components-data-data-table-cell')) if (
) { skipArray.contains(key) ||
return; (key === "height" && root.classList.contains("bi-design-components-data-data-table-cell"))
} ) {
key = BI.hyphenate(key); return;
if (key === 'font-family') { }
stl = stl.replace(/\"/g, ''); key = hyphenate(key);
} if (key === "font-family") {
if (pxStyle.contains(key) && BI.isNumeric(stl)) { stl = stl.replace(/"/g, "");
stl += 'px'; }
} if (pxStyle.contains(key) && isNumeric(stl)) {
if (BI.isKey(stl)) { stl += "px";
str += ` ${key}:${stl};`; }
if (isKey(stl)) {
str += ` ${key}:${stl};`;
}
});
str += "\"";
each(root.attribs, (key, attr) => {
if (isKey(attr)) {
str += ` ${key}=${attr}`;
}
});
if (root.textContent) {
str += ` title=${root.textContent}`;
}
str += ">";
} }
}); // 特殊处理,spread_table的行列元素是不取配置里的高度的,使用stretch拉伸的(leaves取了高度),但是功能代码里给单元格默认高度了,导致拉伸不了
str += '"'; // 而spread_grid_table的行列元素是取配置里的高度的,拉不拉伸都一样
BI.each(root.attribs, (key, attr) => { each(root.children, (i, child) => {
if (BI.isKey(attr)) { str += _renderToHtml(child);
str += ` ${key}=${attr}`; });
} else {
str += root.originalHtml;
}
if (root.tag !== "body") {
if (root.textContent) {
str += root.textContent;
} }
}); str += `</${root.tag}>`;
if (root.textContent) {
str += ` title=${root.textContent}`;
}
str += '>';
} }
// 特殊处理,spread_table的行列元素是不取配置里的高度的,使用stretch拉伸的(leaves取了高度),但是功能代码里给单元格默认高度了,导致拉伸不了
// 而spread_grid_table的行列元素是取配置里的高度的,拉不拉伸都一样 return str;
BI.each(root.children, (i, child) => { }
str += _renderToHtml(child);
export const registRenderToHtmlFun = Element => {
Element.registerFunction("renderToHtml", function () {
return _renderToHtml(this);
}); });
} else {
str += root.originalHtml;
}
if (root.tag !== 'body') {
if (root.textContent) {
str += root.textContent;
}
str += `</${root.tag}>`;
}
return str;
};
export const registRenderToHtmlFun = (Element) => {
Element.registerFunction('renderToHtml', function () {
return _renderToHtml(this);
});
}; };

96
src/core/element/plugins/renderToString.js

@ -1,50 +1,54 @@
var skipArray = ['width', 'height']; import { each, hyphenate } from "../../2.base";
var _renderToString = function (root) {
var str = ''; const skipArray = ["width", "height"];
if (root.nodeName !== 'body') { function _renderToString(root) {
str += `<${root.nodeName}`; let str = "";
if (root.classList.length > 0) { if (root.nodeName !== "body") {
str += ' class="'; str += `<${root.nodeName}`;
BI.each(root.classList, (i, cls) => { if (root.classList.length > 0) {
str += ` ${cls}`; str += " class=\"";
}); each(root.classList, (i, cls) => {
str += '"'; str += ` ${cls}`;
});
str += "\"";
}
str += " style=\"";
each(root.styles, (key, stl) => {
if (skipArray.includes(key)) {
return;
}
key = hyphenate(key);
str += ` ${key}:${stl};`;
});
str += ` width:${root.width}px;`;
str += ` height:${root.height}px;`;
str += " position: fixed;";
str += ` left: ${root.position.x}px;`;
str += ` top: ${root.position.y}px;`;
str += "\"";
each(root.attribs, (key, attr) => {
str += ` ${key}:${attr}`;
});
str += ">";
} }
str += ' style="'; each(root.children, (i, child) => {
BI.each(root.styles, (key, stl) => { str += _renderToString(child);
if (skipArray.includes(key)) {
return;
}
key = BI.hyphenate(key);
str += ` ${key}:${stl};`;
}); });
str += ` width:${root.width}px;`; // if (root.htmlContent) {
str += ` height:${root.height}px;`; // str += root.htmlContent;
str += ' position: fixed;'; // }
str += ` left: ${root.position.x}px;`; if (root.nodeName !== "body") {
str += ` top: ${root.position.y}px;`; if (root.text) {
str += '"'; str += root.text;
BI.each(root.attribs, (key, attr) => { }
str += ` ${key}:${attr}`; str += `</${root.nodeName}>`;
});
str += '>';
}
BI.each(root.children, (i, child) => {
str += _renderToString(child);
});
// if (root.htmlContent) {
// str += root.htmlContent;
// }
if (root.nodeName !== 'body') {
if (root.text) {
str += root.text;
} }
str += `</${root.nodeName}>`;
} return str;
return str; }
};
export const registRenderToStringFun = (Element) => { export const registRenderToStringFun = Element => {
Element.registerFunction('renderToString', function () { Element.registerFunction("renderToString", function () {
return _renderToString(this); return _renderToString(this);
}); });
}; };

20
src/core/element/plugins/text.js

@ -1,10 +1,12 @@
export const registTextFun = (Element) => { export const registTextFun = Element => {
Element.registerFunction('setText', function (text) { Element.registerFunction("setText", function (text) {
this.text = text; this.text = text;
return this;
}); return this;
Element.registerFunction('setValue', function (text) { });
this.text = text; Element.registerFunction("setValue", function (text) {
return this; this.text = text;
});
return this;
});
}; };

18
src/core/element/plugins/val.js

@ -1,9 +1,11 @@
export const registValFun = (Element) => { export const registValFun = Element => {
Element.registerFunction('val', function (value) { Element.registerFunction("val", function (value) {
if (BI.isNotNull(value)) { if (BI.isNotNull(value)) {
this.text = `${value}`; this.text = `${value}`;
return this;
} return this;
return this.text; }
});
return this.text;
});
}; };

9
src/core/index.js

@ -12,6 +12,8 @@ import * as structure from "./structure";
import { StyleLoaderManager } from "./loader/loader.style"; import { StyleLoaderManager } from "./loader/loader.style";
import { ShowListener } from "./listener/listener.show"; import { ShowListener } from "./listener/listener.show";
import { useInWorker } from "./worker"; import { useInWorker } from "./worker";
import * as constant from "./constant";
import * as logic from "./logic";
export * from "./decorator"; export * from "./decorator";
export * from "./2.base"; export * from "./2.base";
@ -24,9 +26,8 @@ export * from "./controller";
export * from "./func"; export * from "./func";
export * from "./structure"; export * from "./structure";
export * from "./h"; export * from "./h";
export * from "./constant";
// 有了后删掉 export * from "./logic";
export const emptyFn = () => { };
export { export {
StyleLoaderManager, StyleLoaderManager,
@ -42,12 +43,14 @@ Object.assign(BI, {
...inject, ...inject,
Plugin, Plugin,
...behavior, ...behavior,
...constant,
component: inject.shortcut, component: inject.shortcut,
...action, ...action,
...controllers, ...controllers,
...func, ...func,
StyleLoaderManager, StyleLoaderManager,
ShowListener, ShowListener,
...logic,
...structure, ...structure,
useInWorker, useInWorker,
...h, ...h,

20
src/core/listener/listener.show.js

@ -1,14 +1,12 @@
/** /**
* guy * guy
* 检测某个Widget的EventChange事件然后去show某个card * 检测某个Widget的EventChange事件然后去show某个card
* @type {*|void|Object}
* @class BI.ShowListener
* @extends BI.OB
*/ */
import { OB } from "../3.ob"; import { OB } from "../3.ob";
import { isArray, isNull, nextTick, } from "../2.base"; import { isArray, isNull, nextTick } from "../2.base";
import { createWidget } from "../5.inject"; import { createWidget } from "../5.inject";
import { Controller } from "../controller/0.controller"; import { Controller } from "../controller/0.controller";
import { Events, emptyFn } from "../constant";
export class ShowListener extends OB { export class ShowListener extends OB {
static EVENT_CHANGE = "EVENT_CHANGE"; static EVENT_CHANGE = "EVENT_CHANGE";
@ -17,12 +15,10 @@ export class ShowListener extends OB {
return { return {
eventObj: createWidget(), eventObj: createWidget(),
cardLayout: null, cardLayout: null,
cardNameCreator: (v) => { cardNameCreator: v => v,
return v; cardCreator: emptyFn,
}, afterCardCreated: emptyFn,
cardCreator: BI.emptyFn, afterCardShow: emptyFn,
afterCardCreated: BI.emptyFn,
afterCardShow: BI.emptyFn
}; };
} }
@ -30,13 +26,13 @@ export class ShowListener extends OB {
const { eventObj, cardLayout, afterCardCreated, cardNameCreator, cardCreator, afterCardShow } = this.options; const { eventObj, cardLayout, afterCardCreated, cardNameCreator, cardCreator, afterCardShow } = this.options;
if (eventObj) { if (eventObj) {
eventObj.on(Controller.EVENT_CHANGE, (type, v, ob) => { eventObj.on(Controller.EVENT_CHANGE, (type, v, ob) => {
if (type === BI.Events.CLICK) { if (type === Events.CLICK) {
v = v || eventObj.getValue(); v = v || eventObj.getValue();
v = isArray(v) ? (v.length > 1 ? v.toString() : v[0]) : v; v = isArray(v) ? (v.length > 1 ? v.toString() : v[0]) : v;
if (isNull(v)) { if (isNull(v)) {
throw new Error("不能为null"); throw new Error("不能为null");
} }
var cardName = cardNameCreator(v); const cardName = cardNameCreator(v);
if (!cardLayout.isCardExisted(cardName)) { if (!cardLayout.isCardExisted(cardName)) {
const card = cardCreator(cardName); const card = cardCreator(cardName);
cardLayout.addCardByName(cardName, card); cardLayout.addCardByName(cardName, card);

9
src/core/loader/loader.style.js

@ -2,13 +2,13 @@
* style加载管理器 * style加载管理器
* *
* Created by GUY on 2015/9/7. * Created by GUY on 2015/9/7.
* @class
*/ */
import { extend, isNotNull } from "../2.base";
import { OB } from "../3.ob"; import { OB } from "../3.ob";
export class StyleLoaderManager extends OB { export class StyleLoaderManager extends OB {
_defaultConfig() { _defaultConfig() {
return BI.extend(super._defaultConfig(arguments), {}); return extend(super._defaultConfig(arguments), {});
} }
_init() { _init() {
@ -17,7 +17,7 @@ export class StyleLoaderManager extends OB {
} }
loadStyle(name, styleString) { loadStyle(name, styleString) {
if(!_global.document) { if (!_global.document) {
return; return;
} }
const d = document, styles = d.createElement("style"); const d = document, styles = d.createElement("style");
@ -38,7 +38,7 @@ export class StyleLoaderManager extends OB {
} }
has(name) { has(name) {
return this.stylesManager[name] != null; return isNotNull(this.stylesManager[name]);
} }
removeStyle(name) { removeStyle(name) {
@ -47,6 +47,7 @@ export class StyleLoaderManager extends OB {
} }
this.stylesManager[name].parentNode.removeChild(this.stylesManager[name]); this.stylesManager[name].parentNode.removeChild(this.stylesManager[name]);
delete this.stylesManager[name]; delete this.stylesManager[name];
return this; return this;
} }
} }

83
src/core/logic/index.js

@ -0,0 +1,83 @@
import { Logic } from "./logic";
import { VerticalLayoutLogic, HorizontalLayoutLogic, TableLayoutLogic, HorizontalFillLayoutLogic } from "./logic.layout";
export const LogicFactory = {
Type: {
Vertical: "vertical",
Horizontal: "horizontal",
Table: "table",
HorizontalFill: "horizontal_fill",
},
createLogic (key, options) {
let LogicCls;
switch (key) {
case LogicFactory.Type.Vertical:
LogicCls = VerticalLayoutLogic;
break;
case LogicFactory.Type.Horizontal:
LogicCls = HorizontalLayoutLogic;
break;
case LogicFactory.Type.Table:
LogicCls = TableLayoutLogic;
break;
case LogicFactory.Type.HorizontalFill:
LogicCls = HorizontalFillLayoutLogic;
break;
default:
LogicCls = Logic;
break;
}
return new LogicCls(options).createLogic();
},
createLogicTypeByDirection (direction) {
switch (direction) {
case BI.Direction.Top:
case BI.Direction.Bottom:
case BI.Direction.Custom:
return BI.LogicFactory.Type.Vertical;
case BI.Direction.Left:
case BI.Direction.Right:
return BI.LogicFactory.Type.Horizontal;
default:
}
},
createLogicItemsByDirection (direction) {
let items = Array.prototype.slice.call(arguments, 1);
items = BI.map(items, (i, item) => {
if (BI.isWidget(item)) {
return {
el: item,
width: item.options.width,
height: item.options.height,
};
}
return item;
});
switch (direction) {
case BI.Direction.Bottom:
items.reverse();
break;
case BI.Direction.Right:
items.reverse();
break;
case BI.Direction.Custom:
items = items.slice(1);
break;
default:
}
return items;
},
};
export {
Logic,
VerticalLayoutLogic,
HorizontalLayoutLogic,
TableLayoutLogic,
HorizontalFillLayoutLogic
};

82
src/core/logic/logic.js

@ -1,80 +1,8 @@
/**
* @class BI.Logic
* @extends BI.OB
*/
BI.Logic = BI.inherit(BI.OB, {
createLogic: function () {
return this.options || {};
}
});
BI.LogicFactory = { import { OB } from "../3.ob";
Type: {
Vertical: "vertical",
Horizontal: "horizontal",
Table: "table",
HorizontalFill: "horizontal_fill"
},
createLogic: function (key, options) {
var logic;
switch (key) {
case BI.LogicFactory.Type.Vertical:
logic = BI.VerticalLayoutLogic;
break;
case BI.LogicFactory.Type.Horizontal:
logic = BI.HorizontalLayoutLogic;
break;
case BI.LogicFactory.Type.Table:
logic = BI.TableLayoutLogic;
break;
case BI.LogicFactory.Type.HorizontalFill:
logic = BI.HorizontalFillLayoutLogic;
break;
default:
logic = BI.Logic;
break;
}
return new logic(options).createLogic();
},
createLogicTypeByDirection: function (direction) { export class Logic extends OB {
switch (direction) { createLogic() {
case BI.Direction.Top: return this.options || {};
case BI.Direction.Bottom:
case BI.Direction.Custom:
return BI.LogicFactory.Type.Vertical;
case BI.Direction.Left:
case BI.Direction.Right:
return BI.LogicFactory.Type.Horizontal;
}
},
createLogicItemsByDirection: function (direction) {
var layout;
var items = Array.prototype.slice.call(arguments, 1);
items = BI.map(items, function (i, item) {
if (BI.isWidget(item)) {
return {
el: item,
width: item.options.width,
height: item.options.height
};
}
return item;
});
switch (direction) {
case BI.Direction.Bottom:
layout = BI.LogicFactory.Type.Vertical;
items.reverse();
break;
case BI.Direction.Right:
layout = BI.LogicFactory.Type.Horizontal;
items.reverse();
break;
case BI.Direction.Custom:
items = items.slice(1);
break;
}
return items;
} }
}; }

109
src/core/logic/logic.layout.js

@ -1,13 +1,13 @@
import { Logic } from "./logic";
import { isNotNull, each, pickBy } from "../2.base";
/** /**
* guy * guy
* 上下布局逻辑 * 上下布局逻辑
* 上下布局的时候要考虑到是动态布局还是静态布局 * 上下布局的时候要考虑到是动态布局还是静态布局
*
* @class BI.VerticalLayoutLogic
* @extends BI.Logic
*/ */
BI.VerticalLayoutLogic = BI.inherit(BI.Logic, { export class VerticalLayoutLogic extends Logic {
props: function () { props() {
return { return {
dynamic: false, dynamic: false,
scrollable: null, scrollable: null,
@ -21,18 +21,20 @@ BI.VerticalLayoutLogic = BI.inherit(BI.Logic, {
tgap: 0, tgap: 0,
bgap: 0, bgap: 0,
innerVgap: 0, innerVgap: 0,
innerHgap: 0 innerHgap: 0,
}; };
}, }
createLogic: function () { createLogic() {
var layout, o = this.options; let layout;
const o = this.options;
if (o.dynamic) { if (o.dynamic) {
layout = "bi.vertical"; layout = "bi.vertical";
} else { } else {
layout = "bi.vtape"; layout = "bi.vtape";
} }
return BI._.pickBy({
return pickBy({
type: layout, type: layout,
scrollable: o.scrollable, scrollable: o.scrollable,
scrolly: o.scrolly, scrolly: o.scrolly,
@ -49,22 +51,19 @@ BI.VerticalLayoutLogic = BI.inherit(BI.Logic, {
horizontalAlign: o.horizontalAlign, horizontalAlign: o.horizontalAlign,
verticalAlign: o.verticalAlign, verticalAlign: o.verticalAlign,
columnSize: o.columnSize, columnSize: o.columnSize,
rowSize: o.rowSize rowSize: o.rowSize,
}, BI.isNotNull); }, isNotNull);
} }
}); }
/** /**
* guy * guy
* 左右布局逻辑 * 左右布局逻辑
* 左右布局的时候要考虑到是动态布局还是静态布局 * 左右布局的时候要考虑到是动态布局还是静态布局
*
* @class BI.HorizontalLayoutLogic
* @extends BI.Logic
*/ */
BI.HorizontalLayoutLogic = BI.inherit(BI.Logic, { export class HorizontalLayoutLogic extends Logic {
props: function () { props() {
return { return {
dynamic: false, dynamic: false,
scrollable: null, scrollable: null,
@ -78,18 +77,20 @@ BI.HorizontalLayoutLogic = BI.inherit(BI.Logic, {
tgap: 0, tgap: 0,
bgap: 0, bgap: 0,
innerVgap: 0, innerVgap: 0,
innerHgap: 0 innerHgap: 0,
}; };
}, }
createLogic: function () { createLogic() {
var layout, o = this.options; let layout;
const o = this.options;
if (o.dynamic) { if (o.dynamic) {
layout = "bi.vertical_adapt"; layout = "bi.vertical_adapt";
} else { } else {
layout = "bi.htape"; layout = "bi.htape";
} }
return BI._.pickBy({
return pickBy({
type: layout, type: layout,
scrollable: o.scrollable, scrollable: o.scrollable,
scrolly: o.scrolly, scrolly: o.scrolly,
@ -106,21 +107,18 @@ BI.HorizontalLayoutLogic = BI.inherit(BI.Logic, {
horizontalAlign: o.horizontalAlign, horizontalAlign: o.horizontalAlign,
verticalAlign: o.verticalAlign, verticalAlign: o.verticalAlign,
columnSize: o.columnSize, columnSize: o.columnSize,
rowSize: o.rowSize rowSize: o.rowSize,
}, BI.isNotNull); }, isNotNull);
} }
}); }
/** /**
* guy * guy
* 表格布局逻辑 * 表格布局逻辑
* 表格布局的时候要考虑到是动态布局还是静态布局 * 表格布局的时候要考虑到是动态布局还是静态布局
*
* @class BI.TableLayoutLogic
* @extends BI.OB
*/ */
BI.TableLayoutLogic = BI.inherit(BI.Logic, { export class TableLayoutLogic extends Logic {
props: function () { props() {
return { return {
dynamic: false, dynamic: false,
scrollable: null, scrollable: null,
@ -132,18 +130,20 @@ BI.TableLayoutLogic = BI.inherit(BI.Logic, {
rowSize: [], rowSize: [],
hgap: 0, hgap: 0,
vgap: 0, vgap: 0,
items: [] items: [],
}; };
}, }
createLogic: function () { createLogic() {
var layout, o = this.options; let layout;
const o = this.options;
if (o.dynamic) { if (o.dynamic) {
layout = "bi.table"; layout = "bi.table";
} else { } else {
layout = "bi.window"; layout = "bi.window";
} }
return BI._.pickBy({
return pickBy({
type: layout, type: layout,
scrollable: o.scrollable, scrollable: o.scrollable,
scrolly: o.scrolly, scrolly: o.scrolly,
@ -156,20 +156,17 @@ BI.TableLayoutLogic = BI.inherit(BI.Logic, {
horizontalAlign: o.horizontalAlign, horizontalAlign: o.horizontalAlign,
verticalAlign: o.verticalAlign, verticalAlign: o.verticalAlign,
columnSize: o.columnSize, columnSize: o.columnSize,
rowSize: o.rowSize rowSize: o.rowSize,
}, BI.isNotNull); }, isNotNull);
} }
}); }
/** /**
* guy * guy
* 左右充满布局逻辑 * 左右充满布局逻辑
*
* @class BI.HorizontalFillLayoutLogic
* @extends BI.Logic
*/ */
BI.HorizontalFillLayoutLogic = BI.inherit(BI.Logic, { export class HorizontalFillLayoutLogic extends Logic {
props: function () { props() {
return { return {
dynamic: false, dynamic: false,
scrollable: null, scrollable: null,
@ -183,14 +180,15 @@ BI.HorizontalFillLayoutLogic = BI.inherit(BI.Logic, {
tgap: 0, tgap: 0,
bgap: 0, bgap: 0,
innerVgap: 0, innerVgap: 0,
innerHgap: 0 innerHgap: 0,
}; };
}, }
createLogic: function () { createLogic() {
var layout, o = this.options; let layout;
var columnSize = []; const o = this.options;
BI.each(o.items, function (i, item) { const columnSize = [];
each(o.items, (i, item) => {
columnSize.push(item.width || 0); columnSize.push(item.width || 0);
}); });
if (o.dynamic) { if (o.dynamic) {
@ -198,7 +196,8 @@ BI.HorizontalFillLayoutLogic = BI.inherit(BI.Logic, {
} else { } else {
layout = "bi.htape"; layout = "bi.htape";
} }
return BI._.pickBy({
return pickBy({
type: layout, type: layout,
scrollable: o.scrollable, scrollable: o.scrollable,
scrolly: o.scrolly, scrolly: o.scrolly,
@ -214,8 +213,8 @@ BI.HorizontalFillLayoutLogic = BI.inherit(BI.Logic, {
items: o.items, items: o.items,
horizontalAlign: o.horizontalAlign, horizontalAlign: o.horizontalAlign,
verticalAlign: o.verticalAlign, verticalAlign: o.verticalAlign,
columnSize: columnSize, columnSize,
rowSize: o.rowSize rowSize: o.rowSize,
}, BI.isNotNull); }, isNotNull);
} }
}); }

Loading…
Cancel
Save