diff --git a/dist/fix/fix.compact.js b/dist/fix/fix.compact.js index 35a642878..88148367c 100644 --- a/dist/fix/fix.compact.js +++ b/dist/fix/fix.compact.js @@ -99,23 +99,13 @@ } } - // _.each(["populate", "addItems", "prependItems"], function (name) { - // var old = BI.Loader.prototype[name]; - // BI.Loader.prototype[name] = function () { - // BI.Widget.pushContext(this); - // try { - // var result = old.apply(this, arguments); - // } catch (e) { - // console.error(e); - // } - // BI.Widget.popContext(); - // return result; - // }; - // }); - function createStore () { var needPop = false; - if (_global.Fix && this._store) { + var workerMode = BI.Providers.getProvider("bi.provider.system").getWorkerMode(); + if (workerMode && this._worker) { + return; + } + if (this._store) { var store = findStore(this.options.context || this._parent || this.options.element || this._context); if (store) { pushTarget(store); @@ -151,7 +141,11 @@ var __initWatch = BI.Widget.prototype.__initWatch; BI.Widget.prototype.__initWatch = function () { __initWatch.apply(this, arguments); - if (_global.Fix && this._store) { + var workerMode = BI.Providers.getProvider("bi.provider.system").getWorkerMode(); + if (workerMode && this._worker) { + return; + } + if (this._store) { initWatch(this, this.watch); } }; diff --git a/dist/fix/fix.js b/dist/fix/fix.js index 54ae610ef..e16bdf99f 100644 --- a/dist/fix/fix.js +++ b/dist/fix/fix.js @@ -90,12 +90,13 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons } } - var bailRE = /[^\w.$]/; + // const bailRE = /[^\w.$]/ function parsePath(path) { - if (bailRE.test(path)) { - return; - } + // 正常表达式比较慢,能不要的就不要了 + // if (bailRE.test(path)) { + // return + // } var segments = path.split('.'); return function (obj) { for (var i = 0; i < segments.length; i++) { @@ -975,7 +976,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons options = options || {}; options.user = true; var exps = void 0; - if (_.isFunction(expOrFn) || !(exps = expOrFn.match(/[a-zA-Z0-9_.*]+|[|][|]|[&][&]|[(]|[)]/g)) || exps.length === 1 && !/\*/.test(expOrFn)) { + if (_.isFunction(expOrFn) || !(exps = expOrFn.match(/[a-zA-Z0-9_.*]+|[|][|]|[&][&]|[(]|[)]/g)) || exps.length === 1 && expOrFn.indexOf("*") < 0) { var watcher = new Watcher(model, expOrFn, cb, options); if (options.immediate) { cb(watcher.value); @@ -1016,45 +1017,96 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons if (_.has(operators, exp)) { return; } - //a.**或a.*形式 - if (/^[1-9a-zA-Z.]+(\*\*$|\*$)/.test(exp) || exp === "**") { - var isGlobal = /\*\*$/.test(exp); - if (isGlobal) { - //a.**的形式 - exp = exp.replace(".**", ""); - } else { - //a.*的形式 - exp = exp.replace(".*", ""); + if (exp.indexOf("*") >= 0) { + //a.**或a.*形式 + if (/^[1-9a-zA-Z.]+(\*\*$|\*$)/.test(exp) || exp === "**" || exp === "*") { + var isGlobal = exp.indexOf("**") >= 0; + if (isGlobal) { + //a.**的形式 + exp = exp.replace(".**", ""); + } else { + //a.*的形式 + exp = exp.replace(".*", ""); + } + var getter = exp === "**" || exp === "*" ? function (m) { + return m; + } : parsePath(exp); + var v = getter.call(model, model); + var _dep = new Dep(); + if (isGlobal) { + (v.__ob__._scopeDeps || (v.__ob__._scopeDeps = [])).push(_dep); + } else { + (v.__ob__._deps || (v.__ob__._deps = [])).push(_dep); + } + var _w = new Watcher(model, function () { + _dep.depend(); + return NaN; + }, function (newValue, oldValue, attrs) { + callback(i, newValue, oldValue, _.extend({ index: i }, attrs)); + }, options); + watchers.push(function unwatchFn() { + _w.teardown(); + v.__ob__._scopeDeps && remove(v.__ob__._scopeDeps, _dep); + v.__ob__._deps && remove(v.__ob__._deps, _dep); + }); + return; } - var getter = exp === "**" ? function (m) { - return m; - } : parsePath(exp); - var v = getter.call(model, model); - var dep = new Dep(); - if (isGlobal) { - (v.__ob__._scopeDeps || (v.__ob__._scopeDeps = [])).push(dep); - } else { - (v.__ob__._deps || (v.__ob__._deps = [])).push(dep); + // **.a.**的情况,场景:a.b.c, 如果用b.**监听, a被重新赋值b上的_scopeDes就不存在了 + if (/^(\*\*\.)+[1-9a-zA-Z]+(\.\*\*$)/.test(exp)) { + //先获取到能获取到的对象 + var _paths = exp.split("."); + var _currentModel = model[_paths[1]]; + exp = _paths[1] + ".**"; + //补全路径 + var _parent = _currentModel.__ob__.parent, + _root = _currentModel.__ob__; + while (_parent) { + exp = '*.' + exp; + _root = _parent; + _parent = _parent.parent; + } + var _regStr = routeToRegExp(exp); + var _dep2 = new Dep(); + _root._globalDeps || (_root._globalDeps = {}); + if (_.isArray(_root._globalDeps[_regStr])) { + _root._globalDeps[_regStr].push(_dep2); + } else { + _root._globalDeps[_regStr] = [_dep2]; + } + + var _w2 = new Watcher(_currentModel, function () { + _dep2.depend(); + return NaN; + }, function (newValue, oldValue, attrs) { + callback(i, newValue, oldValue, _.extend({ index: i }, attrs)); + }, options); + watchers.push(function unwatchFn() { + if (_root._globalDeps) { + remove(_root._globalDeps[_regStr], _dep2); + + if (_root._globalDeps[_regStr].length === 0) { + delete _root._globalDeps[_regStr]; + _w2.teardown(); + } + } + }); + return; } - var w = new Watcher(model, function () { - dep.depend(); - return NaN; - }, function (newValue, oldValue, attrs) { - callback(i, newValue, oldValue, _.extend({ index: i }, attrs)); - }, options); - watchers.push(function unwatchFn() { - w.teardown(); - v.__ob__._scopeDeps && remove(v.__ob__._scopeDeps, dep); - v.__ob__._deps && remove(v.__ob__._deps, dep); - }); - return; - } - // **.a.**的情况,场景:a.b.c, 如果用b.**监听, a被重新赋值b上的_scopeDes就不存在了 - if (/^(\*\*\.)+[1-9a-zA-Z]+(\.\*\*$)/.test(exp)) { + // 再有结尾有*的就不支持了 + if (exp[exp.length - 1] === "*") { + throw new Error('not support'); + } + //其他含有*的情况,如*.a,*.*.a,a.*.a + var currentModel = model; //先获取到能获取到的对象 var paths = exp.split("."); - var currentModel = model[paths[1]]; - exp = paths[1] + ".**"; + for (var _i = 0, len = paths.length; _i < len; _i++) { + if (paths[_i] === "*") { + break; + } + currentModel = model[paths[_i]]; + } + exp = exp.substr(exp.indexOf("*")); //补全路径 var parent = currentModel.__ob__.parent, root = currentModel.__ob__; @@ -1064,77 +1116,26 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons parent = parent.parent; } var regStr = routeToRegExp(exp); - var _dep = new Dep(); + var dep = new Dep(); root._globalDeps || (root._globalDeps = {}); if (_.isArray(root._globalDeps[regStr])) { - root._globalDeps[regStr].push(_dep); + root._globalDeps[regStr].push(dep); } else { - root._globalDeps[regStr] = [_dep]; + root._globalDeps[regStr] = [dep]; } - var _w = new Watcher(currentModel, function () { - _dep.depend(); + var w = new Watcher(currentModel, function () { + dep.depend(); return NaN; }, function (newValue, oldValue, attrs) { callback(i, newValue, oldValue, _.extend({ index: i }, attrs)); }, options); watchers.push(function unwatchFn() { if (root._globalDeps) { - remove(root._globalDeps[regStr], _dep); - + remove(root._globalDeps[regStr], dep); if (root._globalDeps[regStr].length === 0) { delete root._globalDeps[regStr]; - _w.teardown(); - } - } - }); - return; - } - if (/\*\*$|\*$/.test(exp)) { - throw new Error('not support'); - } - //其他含有*的情况,如*.a,*.*.a,a.*.a - if (/\*/.test(exp)) { - var _currentModel = model; - //先获取到能获取到的对象 - var _paths = exp.split("."); - for (var _i = 0, len = _paths.length; _i < len; _i++) { - if (_paths[_i] === "*") { - break; - } - _currentModel = model[_paths[_i]]; - } - exp = exp.substr(exp.indexOf("*")); - //补全路径 - var _parent = _currentModel.__ob__.parent, - _root = _currentModel.__ob__; - while (_parent) { - exp = '*.' + exp; - _root = _parent; - _parent = _parent.parent; - } - var _regStr = routeToRegExp(exp); - var _dep2 = new Dep(); - _root._globalDeps || (_root._globalDeps = {}); - if (_.isArray(_root._globalDeps[_regStr])) { - _root._globalDeps[_regStr].push(_dep2); - } else { - _root._globalDeps[_regStr] = [_dep2]; - } - - var _w2 = new Watcher(_currentModel, function () { - _dep2.depend(); - return NaN; - }, function (newValue, oldValue, attrs) { - callback(i, newValue, oldValue, _.extend({ index: i }, attrs)); - }, options); - watchers.push(function unwatchFn() { - if (_root._globalDeps) { - remove(_root._globalDeps[_regStr], _dep2); - - if (_root._globalDeps[_regStr].length === 0) { - delete _root._globalDeps[_regStr]; - _w2.teardown(); + w.teardown(); } } }); diff --git a/dist/fix/worker.compact.js b/dist/fix/worker.compact.js index 63cfbe759..e537706ad 100644 --- a/dist/fix/worker.compact.js +++ b/dist/fix/worker.compact.js @@ -1,10 +1,17 @@ ;(function () { var contexts = {}; + var init = false; var WORKER; - BI.useWorker = function (wk) { - WORKER = wk; + var enableWorker = function () { + if (init) { + return init; + } + // 开启Worker模式 + BI.config("bi.provider.system", function (provider) { + provider.setWorkerMode(true); + }); var _init = BI.Widget.prototype._init; BI.Widget.prototype._init = function () { this.$destroyWorker = createWorker.call(this); @@ -46,7 +53,16 @@ console.error(e); } }; + init = postMessage; + return postMessage; + }; + BI.useWorker = function (wk) { + if (!_global.Worker || !_global.Proxy) { + return; + } + var postMessage = enableWorker(); + WORKER = wk; if (WORKER) { WORKER.addEventListener("message", function (e) { var data = e.data; @@ -72,7 +88,7 @@ name: name, eventType: "create", options: options, - watches: BI.map(this.watch, function (key) { + watches: BI.map(this.$watch || this.watch, function (key) { return key; }) }); @@ -101,57 +117,7 @@ eventType: "destroy" }); }; - } else { - this.store = BI.Models.getModel(modelType, options); - this.store && (this.store._widget = this); - if (this.store instanceof Fix.Model) { - this.model = this.store.model; - } else { - this.model = this.store; - } - initWatch(this, this.watch); - return function () { - this.store && BI.isFunction(this.store.destroy) && this.store.destroy(); - BI.each(this._watchers, function (i, unwatches) { - unwatches = BI.isArray(unwatches) ? unwatches : [unwatches]; - BI.each(unwatches, function (j, unwatch) { - unwatch(); - }); - }); - this._watchers && (this._watchers = []); - if (this.store) { - this.store._parent && (this.store._parent = null); - this.store._widget && (this.store._widget = null); - this.store = null; - } - }; - } - - } - } - - function initWatch (vm, watch) { - vm._watchers || (vm._watchers = []); - for (var key in watch) { - var handler = watch[key]; - if (BI.isArray(handler)) { - for (var i = 0; i < handler.length; i++) { - vm._watchers.push(createWatcher(vm, key, handler[i])); - } - } else { - vm._watchers.push(createWatcher(vm, key, handler)); } } } - - function createWatcher (vm, keyOrFn, cb, options) { - if (BI.isPlainObject(cb)) { - options = cb; - cb = cb.handler; - } - options = options || {}; - return Fix.watch(vm.model, keyOrFn, _.bind(cb, vm), BI.extend(options, { - store: vm.store - })); - } }()); diff --git a/dist/font/iconfont.eot b/dist/font/iconfont.eot index 44a04d8c3..60f0cedee 100644 Binary files a/dist/font/iconfont.eot and b/dist/font/iconfont.eot differ diff --git a/dist/font/iconfont.svg b/dist/font/iconfont.svg index c642b62c8..2b3356620 100644 --- a/dist/font/iconfont.svg +++ b/dist/font/iconfont.svg @@ -14,6 +14,18 @@ /> + + + + + + + + + + + + @@ -414,8 +426,6 @@ - - @@ -522,8 +532,6 @@ - - diff --git a/dist/font/iconfont.ttf b/dist/font/iconfont.ttf index 6b0173372..fb12a78a7 100644 Binary files a/dist/font/iconfont.ttf and b/dist/font/iconfont.ttf differ diff --git a/dist/font/iconfont.woff b/dist/font/iconfont.woff index 2a7a2de40..8a0afe5b7 100644 Binary files a/dist/font/iconfont.woff and b/dist/font/iconfont.woff differ diff --git a/dist/font/iconfont.woff2 b/dist/font/iconfont.woff2 index 8dedba1b2..1618fc6c5 100644 Binary files a/dist/font/iconfont.woff2 and b/dist/font/iconfont.woff2 differ diff --git a/dist/images/1x/background/marker.png b/dist/images/1x/background/marker.png deleted file mode 100644 index 3929bbb51..000000000 Binary files a/dist/images/1x/background/marker.png and /dev/null differ diff --git a/dist/images/1x/background/mask.png b/dist/images/1x/background/mask.png deleted file mode 100644 index b0a4d406f..000000000 Binary files a/dist/images/1x/background/mask.png and /dev/null differ diff --git a/dist/images/1x/background/wheel.png b/dist/images/1x/background/wheel.png deleted file mode 100644 index 97b343d98..000000000 Binary files a/dist/images/1x/background/wheel.png and /dev/null differ diff --git a/dist/images/2x/background/marker.png b/dist/images/2x/background/marker.png deleted file mode 100644 index 3929bbb51..000000000 Binary files a/dist/images/2x/background/marker.png and /dev/null differ diff --git a/dist/images/2x/background/mask.png b/dist/images/2x/background/mask.png deleted file mode 100644 index b0a4d406f..000000000 Binary files a/dist/images/2x/background/mask.png and /dev/null differ diff --git a/dist/images/2x/background/wheel.png b/dist/images/2x/background/wheel.png deleted file mode 100644 index 97b343d98..000000000 Binary files a/dist/images/2x/background/wheel.png and /dev/null differ diff --git a/examples/demo.worker.js b/examples/demo.worker.js index fecbf994e..dae3c723a 100644 --- a/examples/demo.worker.js +++ b/examples/demo.worker.js @@ -1,6 +1,6 @@ if (this.importScripts) { - importScripts("../dist/fineui_without_jquery_polyfill.js"); - BI.initWorker(); + importScripts("https://fanruan.design/fineui/fineui_without_jquery_polyfill.js"); + BI.useInWorker(); } var Model = BI.inherit(Fix.Model, { state: function () { diff --git a/examples/worker.html b/examples/worker.html index 03cdc5be6..759f0eac4 100644 --- a/examples/worker.html +++ b/examples/worker.html @@ -6,7 +6,6 @@ --> - diff --git a/package.json b/package.json index e3542ddbb..8adfa9a5b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fineui", - "version": "2.0.20211210090328", + "version": "2.0.20211213191328", "description": "fineui", "main": "dist/fineui.min.js", "types": "dist/lib/index.d.ts", diff --git a/src/core/4.widget.js b/src/core/4.widget.js index 5de5d7c85..5d420df20 100644 --- a/src/core/4.widget.js +++ b/src/core/4.widget.js @@ -326,7 +326,9 @@ _initElement: function () { var self = this; this.__isMounting = true; - var render = BI.isFunction(this.options.render) ? this.options.render : this.render; + // 当开启worker模式时,可以通过$render来实现另一种效果 + var workerMode = BI.Providers.getProvider("bi.provider.system").getWorkerMode(); + var render = BI.isFunction(this.options.render) ? this.options.render : (workerMode ? (this.$render || this.render) : this.render); var els = render && render.call(this); els = BI.Plugin.getRender(this.options.type, els); if (BI.isPlainObject(els)) { diff --git a/src/core/system.js b/src/core/system.js index 08a872860..59281243c 100644 --- a/src/core/system.js +++ b/src/core/system.js @@ -8,6 +8,7 @@ var system = { dependencies: {}, responsiveMode: false, + workerMode: false, size: { // 尺寸 TOOL_BAR_HEIGHT: 24, LIST_ITEM_HEIGHT: 24, @@ -28,6 +29,10 @@ system.responsiveMode = !!mode; }; + this.setWorkerMode = function (mode) { + system.workerMode = !!mode; + }; + this.addDependency = function (moduleId, minVersion, maxVersion) { system.dependencies[moduleId] = { min: minVersion, @@ -50,6 +55,10 @@ return system.responsiveMode; }, + getWorkerMode: function () { + return system.workerMode; + }, + getDependencies: function () { return system.dependencies; } diff --git a/src/core/worker.js b/src/core/worker.js index e23d73c5d..d3ba08ee4 100644 --- a/src/core/worker.js +++ b/src/core/worker.js @@ -1,6 +1,10 @@ !(function () { - BI.initWorker = function () { + BI.useInWorker = function () { function createWatcher (model, keyOrFn, cb, options) { + if (BI.isPlainObject(cb)) { + options = cb; + cb = cb.handler; + } options = options || {}; return Fix.watch(model, keyOrFn, cb, BI.extend(options, { store: model diff --git a/src/less/lib/background.less b/src/less/lib/background.less index 1f291a5fe..a331a88da 100644 --- a/src/less/lib/background.less +++ b/src/less/lib/background.less @@ -8,7 +8,3 @@ @background-trans-color-disabled: "background/trans_disable.png"; @background-auto-color-square-normal: "icon/auto_square_normal.png"; @background-auto-color-no-square-normal: "icon/auto_no_square_normal.png"; - -@background-farbtastic-wheel:"background/wheel.png"; -@background-farbtastic-overlay:"background/mask.png"; -@background-farbtastic-marker:"background/marker.png"; diff --git a/typescript/index.ts b/typescript/index.ts index 27dc12099..54f7106a8 100644 --- a/typescript/index.ts +++ b/typescript/index.ts @@ -44,8 +44,8 @@ import { _inject } from "./core/inject"; import { Layout } from "./core/wrapper/layout"; import { AbsoluteLayout } from "./core/wrapper/layout/layout.absolute"; import { HTapeLayout, VTapeLayout } from "./core/wrapper/layout/layout.tape"; -import {HorizontalFillLayout} from "./core/wrapper/layout/fill/fill.horizontal"; -import {VerticalFillLayout} from "./core/wrapper/layout/fill/fill.vertical"; +import { HorizontalFillLayout } from "./core/wrapper/layout/fill/fill.horizontal"; +import { VerticalFillLayout } from "./core/wrapper/layout/fill/fill.vertical"; import { VerticalLayout } from "./core/wrapper/layout/layout.vertical"; import { DefaultLayout } from "./core/wrapper/layout/layout.default"; import { DownListCombo } from "./widget/downlist/combo.downlist"; @@ -179,6 +179,7 @@ import { TreeValueChooserPane } from './component/treevaluechooser/pane.treevalu import { TdLayout } from './core/wrapper/layout/layout.td'; import { MultiLayerSelectLevelTree } from './widget/multilayerselecttree/multilayerselecttree.leveltree'; import { SelectTreeExpander } from './widget/selecttree/selecttree.expander'; +import { DownListGroupItem } from "./widget/downlist/item.downlistgroup"; export interface BI extends _func, _i18n, _base, _inject, _var, _web, _utils { @@ -365,6 +366,7 @@ export interface BI extends _func, _i18n, _base, _inject, _var, _web, _utils { TdLayout: typeof TdLayout; MultiLayerSelectLevelTree: typeof MultiLayerSelectLevelTree; SelectTreeExpander: typeof SelectTreeExpander; + DownListGroupItem: typeof DownListGroupItem; } export default { @@ -551,4 +553,5 @@ export { MultiLayerSelectLevelTree, SelectTreeExpander, DirectionPager, + DownListGroupItem, }; diff --git a/typescript/widget/downlist/item.downlistgroup.ts b/typescript/widget/downlist/item.downlistgroup.ts new file mode 100644 index 000000000..8c85305ea --- /dev/null +++ b/typescript/widget/downlist/item.downlistgroup.ts @@ -0,0 +1,10 @@ +import { BasicButton } from "../../base/single/button/button.basic"; + +export declare class DownListGroupItem extends BasicButton { + static xtype: string; + static EVENT_CHANGE: string; + + doRedMark(...args: any[]): void; + + unRedMark(...args: any[]): void; +}