UNPKG

bk-magic-vue

Version:

基于蓝鲸 Magicbox 和 Vue 的前端组件库

477 lines (435 loc) 15.9 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (global = global || self, factory(global.library = {})); }(this, function (exports) { 'use strict'; function createCommonjsModule(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; } var _global = createCommonjsModule(function (module) { var global = module.exports = typeof window != 'undefined' && window.Math == Math ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')(); if (typeof __g == 'number') __g = global; }); var _core = createCommonjsModule(function (module) { var core = module.exports = { version: '2.6.12' }; if (typeof __e == 'number') __e = core; }); var _core_1 = _core.version; var _aFunction = function (it) { if (typeof it != 'function') throw TypeError(it + ' is not a function!'); return it; }; var _ctx = function (fn, that, length) { _aFunction(fn); if (that === undefined) return fn; switch (length) { case 1: return function (a) { return fn.call(that, a); }; case 2: return function (a, b) { return fn.call(that, a, b); }; case 3: return function (a, b, c) { return fn.call(that, a, b, c); }; } return function () { return fn.apply(that, arguments); }; }; var _isObject = function (it) { return typeof it === 'object' ? it !== null : typeof it === 'function'; }; var _anObject = function (it) { if (!_isObject(it)) throw TypeError(it + ' is not an object!'); return it; }; var _fails = function (exec) { try { return !!exec(); } catch (e) { return true; } }; var _descriptors = !_fails(function () { return Object.defineProperty({}, 'a', { get: function () { return 7; } }).a != 7; }); var document$1 = _global.document; var is = _isObject(document$1) && _isObject(document$1.createElement); var _domCreate = function (it) { return is ? document$1.createElement(it) : {}; }; var _ie8DomDefine = !_descriptors && !_fails(function () { return Object.defineProperty(_domCreate('div'), 'a', { get: function () { return 7; } }).a != 7; }); var _toPrimitive = function (it, S) { if (!_isObject(it)) return it; var fn, val; if (S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val; if (typeof (fn = it.valueOf) == 'function' && !_isObject(val = fn.call(it))) return val; if (!S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val; throw TypeError("Can't convert object to primitive value"); }; var dP = Object.defineProperty; var f = _descriptors ? Object.defineProperty : function defineProperty(O, P, Attributes) { _anObject(O); P = _toPrimitive(P, true); _anObject(Attributes); if (_ie8DomDefine) try { return dP(O, P, Attributes); } catch (e) { } if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported!'); if ('value' in Attributes) O[P] = Attributes.value; return O; }; var _objectDp = { f: f }; var _propertyDesc = function (bitmap, value) { return { enumerable: !(bitmap & 1), configurable: !(bitmap & 2), writable: !(bitmap & 4), value: value }; }; var _hide = _descriptors ? function (object, key, value) { return _objectDp.f(object, key, _propertyDesc(1, value)); } : function (object, key, value) { object[key] = value; return object; }; var hasOwnProperty = {}.hasOwnProperty; var _has = function (it, key) { return hasOwnProperty.call(it, key); }; var PROTOTYPE = 'prototype'; var $export = function (type, name, source) { var IS_FORCED = type & $export.F; var IS_GLOBAL = type & $export.G; var IS_STATIC = type & $export.S; var IS_PROTO = type & $export.P; var IS_BIND = type & $export.B; var IS_WRAP = type & $export.W; var exports = IS_GLOBAL ? _core : _core[name] || (_core[name] = {}); var expProto = exports[PROTOTYPE]; var target = IS_GLOBAL ? _global : IS_STATIC ? _global[name] : (_global[name] || {})[PROTOTYPE]; var key, own, out; if (IS_GLOBAL) source = name; for (key in source) { own = !IS_FORCED && target && target[key] !== undefined; if (own && _has(exports, key)) continue; out = own ? target[key] : source[key]; exports[key] = IS_GLOBAL && typeof target[key] != 'function' ? source[key] : IS_BIND && own ? _ctx(out, _global) : IS_WRAP && target[key] == out ? (function (C) { var F = function (a, b, c) { if (this instanceof C) { switch (arguments.length) { case 0: return new C(); case 1: return new C(a); case 2: return new C(a, b); } return new C(a, b, c); } return C.apply(this, arguments); }; F[PROTOTYPE] = C[PROTOTYPE]; return F; })(out) : IS_PROTO && typeof out == 'function' ? _ctx(Function.call, out) : out; if (IS_PROTO) { (exports.virtual || (exports.virtual = {}))[key] = out; if (type & $export.R && expProto && !expProto[key]) _hide(expProto, key, out); } } }; $export.F = 1; $export.G = 2; $export.S = 4; $export.P = 8; $export.B = 16; $export.W = 32; $export.U = 64; $export.R = 128; var _export = $export; _export(_export.S + _export.F * !_descriptors, 'Object', { defineProperty: _objectDp.f }); var $Object = _core.Object; var defineProperty = function defineProperty(it, key, desc) { return $Object.defineProperty(it, key, desc); }; var defineProperty$1 = defineProperty; _export(_export.S, 'Number', { isNaN: function isNaN(number) { return number != number; } }); var isNan = _core.Number.isNaN; var isNan$1 = isNan; var _defined = function (it) { if (it == undefined) throw TypeError("Can't call method on " + it); return it; }; var _stringWs = '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003' + '\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF'; var space = '[' + _stringWs + ']'; var non = '\u200b\u0085'; var ltrim = RegExp('^' + space + space + '*'); var rtrim = RegExp(space + space + '*$'); var exporter = function (KEY, exec, ALIAS) { var exp = {}; var FORCE = _fails(function () { return !!_stringWs[KEY]() || non[KEY]() != non; }); var fn = exp[KEY] = FORCE ? exec(trim) : _stringWs[KEY]; if (ALIAS) exp[ALIAS] = fn; _export(_export.P + _export.F * FORCE, 'String', exp); }; var trim = exporter.trim = function (string, TYPE) { string = String(_defined(string)); if (TYPE & 1) string = string.replace(ltrim, ''); if (TYPE & 2) string = string.replace(rtrim, ''); return string; }; var _stringTrim = exporter; var $parseFloat = _global.parseFloat; var $trim = _stringTrim.trim; var _parseFloat = 1 / $parseFloat(_stringWs + '-0') !== -Infinity ? function parseFloat(str) { var string = $trim(String(str), 3); var result = $parseFloat(string); return result === 0 && string.charAt(0) == '-' ? -0 : result; } : $parseFloat; _export(_export.G + _export.F * (parseFloat != _parseFloat), { parseFloat: _parseFloat }); var _parseFloat$1 = _core.parseFloat; var $parseInt = _global.parseInt; var $trim$1 = _stringTrim.trim; var hex = /^[-+]?0[xX]/; var _parseInt = $parseInt(_stringWs + '08') !== 8 || $parseInt(_stringWs + '0x16') !== 22 ? function parseInt(str, radix) { var string = $trim$1(String(str), 3); return $parseInt(string, (radix >>> 0) || (hex.test(string) ? 16 : 10)); } : $parseInt; _export(_export.G + _export.F * (parseInt != _parseInt), { parseInt: _parseInt }); var _parseInt$1 = _core.parseInt; var toString = {}.toString; var _cof = function (it) { return toString.call(it).slice(8, -1); }; var _isArray = Array.isArray || function isArray(arg) { return _cof(arg) == 'Array'; }; _export(_export.S, 'Array', { isArray: _isArray }); var isArray = _core.Array.isArray; var requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) { window.setTimeout(callback, 1000 / 60); }; var cancelAnimationFrame = window.cancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || window.oCancelAnimationFrame || window.msCancelAnimationFrame || function (id) { window.clearTimeout(id); }; function uuid() { var id = ''; var randomNum = Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1); for (var i = 0; i < 7; i++) { id += randomNum; } return id; } (function () { if (!window['__bk_pop_manager']) { var __containerId = "bk_pop_".concat(new Date().getTime()); var __maskId = "bk_pop_mask_".concat(new Date().getTime()); var __defaultKey = "bk_pop_key_".concat(new Date().getTime()); var __popInstances = []; var popManager = { containerId: __containerId, maskId: __maskId, defaultKey: __defaultKey, formatKey: function formatKey(key) { return String(key).replace(/#/g, '_'); }, show: function show(key, instance) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { tplAction: 'keepAll', zIndex: '', beforeHide: function beforeHide() {}, ignoreExistMask: false, appendToBody: false }; key = key === undefined || key === null || isNan$1(key) ? this.defaultKey : key; key = this.formatKey(key); var uid = uuid(); var isAppendToBody = false; if (options.tplAction === 'onlyone') { this.clearByTpl(key); } if (this.shouldAppendToBody(key)) { isAppendToBody = true; this.showModalMask(options.zIndex); !options.appendToBody && this.container.append(instance); } else { isAppendToBody = false; var lastInsZindex = options.zIndex; this.showModalMask(lastInsZindex); } var beforeHide = options.beforeHide, zIndex = options.zIndex, ignoreExistMask = options.ignoreExistMask; this.instances.push({ uid: uid, ins: instance, tplName: key, beforeHide: beforeHide, zIndex: zIndex, ignoreExistMask: ignoreExistMask, isAppendToBody: isAppendToBody }); return "".concat(uid, "#").concat(key); }, shouldAppendToBody: function shouldAppendToBody(tplName) { return this.instances.some(function (item) { return item.tplName === tplName; }); }, hide: function hide(popId, options) { options = options || { action: 'hideUid' }; switch (options.action) { case 'hideAll': this.clearAll(); break; case 'hideUid': this.clearByUid(popId); break; case 'hideSameTpl': this.clearByTpl(popId); break; default: this.autoClear(popId); break; } this.updateModalMaskIndex(); }, updateModalMaskIndex: function updateModalMaskIndex() { if (this.instances.length) { var lastIns = this.instances.slice(-1)[0]; var lastInsZindex = lastIns.isAppendToBody ? lastIns.zIndex : lastIns.zIndex - 1; this.showModalMask(lastInsZindex); } else { this.hideModalMask(); } }, autoClear: function autoClear() { var uid = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; if (uid.indexOf('#') > 0) { this.clearByUid(uid); } else { this.clearByTpl(); } }, clearByTpl: function clearByTpl(uid) { var _this = this; var keyStr = uid.split('#'); var tplName = keyStr.slice(-1)[0]; this.instances = this.instances.filter(function (item) { if (item.tplName === tplName) { _this.__hideInstance(item); return false; } else { return true; } }); }, clearByUid: function clearByUid(uid) { var keyStr = uid.split('#'); var instanceUid = keyStr[0]; var tplName = keyStr[1]; var index = this.instances.findIndex(function (ins) { return ins.uid === instanceUid && ins.tplName === tplName; }); if (index >= 0) { this.__hideInstance(this.instances[index]); this.instances.splice(index, 1); } else { console.warn('Can not find pop instance with index ' + index); } }, clearAll: function clearAll() { var _this2 = this; this.instances.forEach(function (item) { return _this2.__hideInstance(item); }); this.instances = []; }, showModalMask: function showModalMask(zIndex) { this.dialogMask.setAttribute('style', "z-index:".concat(zIndex, ";")); document.body.style.overflow = 'hidden'; this.dialogMask.classList.remove('hide-active'); this.dialogMask.classList.add('show-active'); }, hideModalMask: function hideModalMask() { this.dialogMask.classList.remove('show-active'); this.dialogMask.classList.add('hide-active'); document.body.style.overflow = ''; }, __hideInstance: function __hideInstance(instance) { if (typeof instance.beforeHide === 'function') { instance.beforeHide(); setTimeout(function () { if (instance.isAppendToBody) { instance.ins.remove(); } }); } else { if (instance.isAppendToBody) { instance.ins.remove(); } } }, isMaskShown: function isMaskShown() { var mask = document.querySelector('[data-bkpop-mask]'); if (mask) { return mask.classList.contains('show-active'); } return false; } }; defineProperty$1(popManager, 'container', { get: function get() { var container = document.querySelector('[data-bkpop-container]'); if (!container) { container = document.createElement('div'); container.setAttribute('id', this.containerId); container.setAttribute('data-bkpop-container', 'true'); document.body.append(container); } return container; } }); defineProperty$1(popManager, 'dialogMask', { get: function get() { var mask = document.querySelector('[data-bkpop-mask]'); if (!mask) { mask = document.createElement('div'); mask.setAttribute('id', this.maskId); mask.setAttribute('class', 'bk-dialog-mask'); mask.setAttribute('data-bkpop-mask', 'true'); this.container.append(mask); } return mask; } }); defineProperty$1(popManager, 'instances', { get: function get() { return __popInstances; }, set: function set(val) { __popInstances = val; } }); window['__bk_pop_manager'] = popManager; window['__bk_pop_manager'].__container = popManager.container; } })(); var popManager = window['__bk_pop_manager']; exports.default = popManager; Object.defineProperty(exports, '__esModule', { value: true }); }));