ten-design-vue
Version:
ten-vue
905 lines (793 loc) • 25.4 kB
JavaScript
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 4);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {
module.exports = require("../icon");
/***/ }),
/* 1 */
/***/ (function(module, exports) {
module.exports = require("../scripts/mixins/emitter");
/***/ }),
/* 2 */
/***/ (function(module, exports) {
module.exports = require("../scripts/utils/dom-helper");
/***/ }),
/* 3 */
/***/ (function(module, exports) {
module.exports = require("v-click-outside");
/***/ }),
/* 4 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./src/components/drawer/drawer.vue?vue&type=template&id=d5e12a92&
var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return (_vm.containerVisible || !_vm.destroy)?_c('div',{directives:[{name:"show",rawName:"v-show",value:(_vm.containerVisible),expression:"containerVisible"}],staticClass:"ten-drawer__container",style:({ 'z-index': _vm.zindex })},[(_vm.showMask)?[_c('transition',{attrs:{"name":"ten-drawer-effect","appear":""}},[_c('div',{directives:[{name:"show",rawName:"v-show",value:(_vm.drawerVisible),expression:"drawerVisible"}],ref:"mask",staticClass:"ten-drawer__mask",on:{"click":_vm.handleMaskClick}})])]:_vm._e(),_c('transition',{attrs:{"name":"ten-drawer-effect","appear":""}},[_c('div',_vm._b({directives:[{name:"show",rawName:"v-show",value:(_vm.drawerVisible),expression:"drawerVisible"},{name:"click-outside",rawName:"v-click-outside",value:(_vm.handleOutsideClick),expression:"handleOutsideClick"}],staticClass:"ten-drawer",class:[("ten-drawer__" + _vm.position)],style:(_vm.drawerStyle)},'div',_vm.$attrs,false),[(_vm.resizable)?_c('div',{staticClass:"ten-drawer__resizebar"}):_vm._e(),(_vm.title && !_vm.hideHeader)?_c('div',{staticClass:"ten-drawer__header"},[_c('div',{staticClass:"ten-drawer__header-title"},[_vm._t("title",function(){return [_vm._v("\n "+_vm._s(_vm.title)+"\n ")]})],2)]):_vm._e(),(_vm.showCloseButton)?_c('ten-icon',{staticClass:"ten-drawer__close",attrs:{"icon":"clear"},on:{"click":_vm.handleCloseClick}}):_vm._e(),_c('div',{staticClass:"ten-drawer__body"},[_vm._t("default")],2)],1)])],2):_vm._e()}
var staticRenderFns = []
// CONCATENATED MODULE: ./src/components/drawer/drawer.vue?vue&type=template&id=d5e12a92&
// EXTERNAL MODULE: external "../icon"
var external_icon_ = __webpack_require__(0);
var external_icon_default = /*#__PURE__*/__webpack_require__.n(external_icon_);
// EXTERNAL MODULE: external "../scripts/mixins/emitter"
var emitter_ = __webpack_require__(1);
var emitter_default = /*#__PURE__*/__webpack_require__.n(emitter_);
// EXTERNAL MODULE: external "../scripts/utils/dom-helper"
var dom_helper_ = __webpack_require__(2);
var dom_helper_default = /*#__PURE__*/__webpack_require__.n(dom_helper_);
// EXTERNAL MODULE: external "v-click-outside"
var external_v_click_outside_ = __webpack_require__(3);
var external_v_click_outside_default = /*#__PURE__*/__webpack_require__.n(external_v_click_outside_);
// CONCATENATED MODULE: ./node_modules/babel-loader/lib??ref--1!./node_modules/vue-loader/lib??vue-loader-options!./src/components/drawer/drawer.vue?vue&type=script&lang=js&
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
var drawervue_type_script_lang_js_name = 'ten-drawer';
var ANIMATION_DURATION = 240;
var idCounter = 1;
var renderStack = [];
/* harmony default export */ var drawervue_type_script_lang_js_ = ({
name: drawervue_type_script_lang_js_name,
components: {
TenIcon: external_icon_default.a
},
directives: {
clickOutside: external_v_click_outside_default.a.directive
},
mixins: [emitter_default.a],
model: {
prop: 'visible',
event: 'change'
},
props: {
/**
* @model
* 是否显示 Drawer
*/
visible: {
type: Boolean,
default: false
},
/**
* Drawer 标题
*/
title: String,
/**
* Drawer 显示位置
* @member right | left | top | bottom
*/
position: {
type: String,
default: 'right',
validator: function validator(value) {
return ['right', 'left', 'top', 'bottom'].indexOf(value) > -1;
}
},
/**
* Drawer 尺寸。position 为 left / right 时设置为宽度,为 top / bottom 时设置为高度。数字值默认使用像素作为尺寸单位,可传递 px / % 形式的值
*/
size: {
type: [Number, String],
default: 592,
validator: function validator(size) {
var parsedSize = parseFloat(size);
var valid = typeof size === 'number' || !isNaN(parsedSize) && parsedSize >= 0 && parsedSize <= 100;
return valid;
}
},
/**
* 手动设置 Drawer 的 z-index
*/
zIndex: {
type: Number,
default: 10000
},
/**
* 关闭 Drawer 时是否销毁组件
*/
destroy: {
type: Boolean,
default: true
},
/**
* 是否显示一个遮罩层
*/
showMask: {
type: Boolean,
default: true
},
/**
* 是否显示关闭按钮
*/
showCloseButton: {
type: Boolean,
default: true
},
/**
* 显示 Drawer 时,如果页面高度超出 viewport 是否允许页面滚动
*/
bodyScrollable: {
type: Boolean,
default: false
},
/**
* 是否允许 ESC 按键自动关闭 Drawer
*/
escClosable: {
type: Boolean,
default: true
},
/**
* 点击 Drawer 面板外部是否关闭面板,只在 showMask=false 时生效
*/
outsideClickClosable: {
type: Boolean,
default: true
},
/**
* 关闭 Drawer 前执行的回调,返回 false 则放弃关闭 Drawer。(注意这个时间
*/
beforeClose: Function,
/**
* 不显示头部
*/
hideHeader: Boolean,
/**
* 是否启用 Resize 功能
*/
resizable: {
type: Boolean,
default: false
},
/**
* Drawer 面板最小尺寸
*/
minSize: {
type: [Number, String],
default: 0,
validator: function validator(size) {
var parsedSize = parseFloat(size);
var valid = typeof size === 'number' || !isNaN(parsedSize) && parsedSize >= 0 && parsedSize <= 100;
return valid;
}
},
/**
* Drawer 面板最大尺寸
*/
maxSize: {
type: [Number, String],
default: '100%',
validator: function validator(size) {
var parsedSize = parseFloat(size);
var valid = typeof size === 'number' || !isNaN(parsedSize) && parsedSize >= 0 && parsedSize <= 100;
return valid;
}
}
},
data: function data() {
// inner state
return {
containerVisible: this.visible,
drawerVisible: this.visible,
zindex: this.zIndex,
// for resizing
resizing: false,
dragging: false,
width: 0,
height: 0,
minWidth: 0,
maxWidth: 0,
minHeight: 0,
maxHeight: 0,
offsetX: 0,
offsetY: 0,
mouseX: 0,
mouseY: 0
};
},
computed: {
// computed drawer size
drawerStyle: function drawerStyle() {
if (this.isHorizontal()) {
return {
width: "".concat(this.width, "px")
};
}
return {
height: "".concat(this.height, "px")
};
}
},
watch: {
// watch visible state
visible: function visible(value) {
this.setVisible(value, true);
},
size: function size(value) {
this.size = value;
this.width = this.getWidth();
this.height = this.getHeight();
},
minSize: function minSize(value) {
this.minSize = value;
this.minWidth = this.getMinWidth();
this.maxWidth = this.getMaxWidth();
this.minHeight = this.getMinHeight();
this.maxHeight = this.getMaxHeight();
},
maxSize: function maxSize(value) {
this.maxSize = value;
this.minWidth = this.getMinWidth();
this.maxWidth = this.getMaxWidth();
this.minHeight = this.getMinHeight();
this.maxHeight = this.getMaxHeight();
},
position: function position(value) {
this.position = value;
this.width = this.getWidth();
this.height = this.getHeight();
this.minWidth = this.getMinWidth();
this.maxWidth = this.getMaxWidth();
this.minHeight = this.getMinHeight();
this.maxHeight = this.getMaxHeight();
}
},
beforeMount: function beforeMount() {
this._id = "ten-drawer-".concat(idCounter);
idCounter += 1;
},
mounted: function mounted() {
this.width = this.getWidth();
this.height = this.getHeight();
this.minWidth = this.getMinWidth();
this.maxWidth = this.getMaxWidth();
this.minHeight = this.getMinHeight();
this.maxHeight = this.getMaxHeight(); // mounted hook
this._animationTimeout = 0;
if (this.visible) {
document.body.appendChild(this.$el);
}
},
destroyed: function destroyed() {
// destroyed hook
try {
this.$el && document.body.removeChild(this.$el);
} catch (error) {}
},
methods: {
isHorizontal: function isHorizontal() {
return ['left', 'right'].indexOf(this.position) > -1;
},
getSizeNumber: function getSizeNumber(size) {
if (typeof size === 'number') {
return size;
}
var parentSize = this.isHorizontal() ? window.innerWidth : window.innerHeight;
var _size = parentSize * (parseFloat(size) / 100);
return parseInt(_size, 10);
},
getWidth: function getWidth() {
if (this.isHorizontal()) {
return this.getSizeNumber(this.size);
}
return window.innerWidth;
},
getHeight: function getHeight() {
if (this.isHorizontal()) {
return window.innerHeight;
}
return this.getSizeNumber(this.size);
},
getMinWidth: function getMinWidth() {
if (this.isHorizontal()) {
return this.getSizeNumber(this.minSize);
}
return window.innerWidth;
},
getMaxWidth: function getMaxWidth() {
if (this.isHorizontal()) {
return this.getSizeNumber(this.maxSize);
}
return window.innerWidth;
},
getMinHeight: function getMinHeight() {
if (this.isHorizontal()) {
return window.innerHeight;
}
return this.getSizeNumber(this.minSize);
},
getMaxHeight: function getMaxHeight() {
if (this.isHorizontal()) {
return window.innerHeight;
}
return this.getSizeNumber(this.maxSize);
},
setBodyCalcSize: function setBodyCalcSize(clear) {
var bodyIsScroll = document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight) && window.innerWidth > document.body.offsetWidth;
if (!bodyIsScroll) {
return;
}
if (clear) {
document.body.style.position = '';
document.body.style.width = '';
return;
}
var calcSize = dom_helper_default.a.getBrowserScrollSize();
if (calcSize) {
document.body.style.position = 'relative';
document.body.style.width = "calc(100% - ".concat(calcSize, "px)");
}
},
setVisible: function setVisible(value, initiative) {
var _this = this;
var _isChanged = false; // close
if (!value && this.drawerVisible) {
if (typeof this.beforeClose === 'function') {
var result = this.beforeClose();
if (!result) {
return;
}
}
/**
* 关闭回调函数
*/
this.$emit('close');
_isChanged = true;
this.drawerVisible = value;
clearTimeout(this._animationTimeout);
this._animationTimeout = setTimeout(function () {
document.body.style.overflow = '';
_this.setBodyCalcSize(true);
/**
* 关闭动画结束回调函数
*/
_this.$emit('closed');
_this.unbindGlobalEvent();
_this.containerVisible = false;
renderStack.pop();
}, ANIMATION_DURATION); // open
} else if (value && !this.drawerVisible) {
_isChanged = true;
this.drawerVisible = value;
this.containerVisible = value;
renderStack.push({
id: this._id
});
if (renderStack.length > 0) {
this.zindex = this.zIndex + renderStack.length;
}
document.body.appendChild(this.$el);
this.setBodyCalcSize();
if (!this.bodyScrollable) {
document.body.style.overflow = 'hidden';
}
/**
* 显示回调函数
*/
this.$emit('open');
clearTimeout(this._animationTimeout);
this._animationTimeout = setTimeout(function () {
/**
* 显示动画结束回调函数
*/
_this.$emit('opened');
_this.bindGlobalEvent();
}, ANIMATION_DURATION);
}
if (_isChanged && !initiative) {
/**
* visible 状态改变回调
*/
this.$emit('change', value);
}
this.broadcastAll('do-layout');
},
bindGlobalEvent: function bindGlobalEvent() {
if (!this.globalEventBinded) {
this.globalEventBinded = true;
window.addEventListener('keydown', this.onKeydown);
if (this.resizable) {
document.documentElement.addEventListener('mousedown', this.handleDown, true);
}
}
},
unbindGlobalEvent: function unbindGlobalEvent() {
this.globalEventBinded = false;
window.removeEventListener('keydown', this.onKeydown);
if (this.resizable) {
document.documentElement.removeEventListener('mousedown', this.handleDown, true);
document.documentElement.removeEventListener('mouseup', this.handleUp, true);
}
},
handleCloseClick: function handleCloseClick() {
this.setVisible(false);
},
handleMaskClick: function handleMaskClick(event) {
event.stopPropagation();
if (this.outsideClickClosable) {
this.setVisible(false);
}
},
handleOutsideClick: function handleOutsideClick(event) {
event.stopPropagation();
if (!this.drawerVisible || this.showMask && this.outsideClickClosable || event.target.closest('.ten-drawer')) {
return;
}
if (this.outsideClickClosable) {
// 关闭最顶层 Drawer
if (renderStack.length > 0) {
var topDrawer = renderStack[renderStack.length - 1];
if (this._id === topDrawer.id) {
this.setVisible(false);
}
}
}
},
onKeydown: function onKeydown(event) {
var isEscape = event.keyCode === 27;
if (this.escClosable && isEscape) {
this.handleCloseClick();
}
},
// resizing start
handleDown: function handleDown(event) {
if (this.$el && this.$el.nodeType === 1 && this.$el.contains(event.target) && event.target.classList.contains('ten-drawer__resizebar')) {
event.stopPropagation && event.stopPropagation();
event.preventDefault && event.preventDefault();
this.offsetX = 0;
this.offsetY = 0;
this.mouseX = event.clientX;
this.mouseY = event.clientY;
this.resizing = true;
document.documentElement.addEventListener('mousemove', this.handleMove, true);
document.documentElement.addEventListener('mouseup', this.handleUp, true);
/**
* resizing 开始
*/
this.$emit('resizing:start', true);
}
},
// dragging start
handleMove: function handleMove(event) {
if (this.resizable && this.resizing) {
// get offset
var diffX = event.clientX - this.mouseX + this.offsetX;
var diffY = event.clientY - this.mouseY + this.offsetY;
this.offsetX = 0;
this.offsetY = 0; // update style
// drag to left
if (this.position === 'right') {
if (this.width - diffX < this.minWidth) {
this.offsetX = diffX - (diffX = this.width - this.minWidth);
} else if (this.width - diffX > this.maxWidth) {
this.offsetX = diffX - (diffX = this.width - this.maxWidth);
}
this.width -= diffX;
} // drag to right
if (this.position === 'left') {
if (this.width + diffX < this.minWidth) {
this.offsetX = diffX - (diffX = this.minWidth - this.width);
} else if (this.width + diffX > this.maxWidth) {
this.offsetX = diffX - (diffX = this.maxWidth - this.width);
}
this.width += diffX;
} // drag to bottom
if (this.position === 'top') {
if (this.height + diffY < this.minHeight) {
this.offsetY = diffY - (diffY = this.minHeight - this.height);
} else if (this.height + diffY > this.maxHeight) {
this.offsetY = diffY - (diffY = this.maxHeight - this.height);
}
this.height += diffY;
} // drag to top
if (this.position === 'bottom') {
if (this.height - diffY < this.minHeight) {
this.offsetY = diffY - (diffY = this.height - this.minHeight);
} else if (this.height - diffY > this.maxHeight) {
this.offsetY = diffY - (diffY = this.height - this.maxHeight);
}
this.height -= diffY;
}
this.mouseX = event.clientX;
this.mouseY = event.clientY;
this.dragging = true;
/**
* dragging 进行中
*/
this.$emit('dragging:start');
}
},
// resizing end && dragging end
handleUp: function handleUp() {
if (this.resizable && this.resizing) {
this.resizing = false;
/**
* resizing 结束
*/
this.$emit('resizing:end');
}
if (this.resizable && this.dragging) {
this.dragging = false;
document.documentElement.removeEventListener('mousemove', this.handleMove, true);
/**
* dragging 结束
*/
this.$emit('dragging:end');
}
}
}
});
// CONCATENATED MODULE: ./src/components/drawer/drawer.vue?vue&type=script&lang=js&
/* harmony default export */ var drawer_drawervue_type_script_lang_js_ = (drawervue_type_script_lang_js_);
// CONCATENATED MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
/* globals __VUE_SSR_CONTEXT__ */
// IMPORTANT: Do NOT use ES2015 features in this file (except for modules).
// This module is a runtime utility for cleaner component module output and will
// be included in the final webpack user bundle.
function normalizeComponent (
scriptExports,
render,
staticRenderFns,
functionalTemplate,
injectStyles,
scopeId,
moduleIdentifier, /* server only */
shadowMode /* vue-cli only */
) {
// Vue.extend constructor export interop
var options = typeof scriptExports === 'function'
? scriptExports.options
: scriptExports
// render functions
if (render) {
options.render = render
options.staticRenderFns = staticRenderFns
options._compiled = true
}
// functional template
if (functionalTemplate) {
options.functional = true
}
// scopedId
if (scopeId) {
options._scopeId = 'data-v-' + scopeId
}
var hook
if (moduleIdentifier) { // server build
hook = function (context) {
// 2.3 injection
context =
context || // cached call
(this.$vnode && this.$vnode.ssrContext) || // stateful
(this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
// 2.2 with runInNewContext: true
if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
context = __VUE_SSR_CONTEXT__
}
// inject component styles
if (injectStyles) {
injectStyles.call(this, context)
}
// register component module identifier for async chunk inferrence
if (context && context._registeredComponents) {
context._registeredComponents.add(moduleIdentifier)
}
}
// used by ssr in case component is cached and beforeCreate
// never gets called
options._ssrRegister = hook
} else if (injectStyles) {
hook = shadowMode
? function () {
injectStyles.call(
this,
(options.functional ? this.parent : this).$root.$options.shadowRoot
)
}
: injectStyles
}
if (hook) {
if (options.functional) {
// for template-only hot-reload because in that case the render fn doesn't
// go through the normalizer
options._injectStyles = hook
// register for functional component in vue file
var originalRender = options.render
options.render = function renderWithStyleInjection (h, context) {
hook.call(context)
return originalRender(h, context)
}
} else {
// inject component registration as beforeCreate hook
var existing = options.beforeCreate
options.beforeCreate = existing
? [].concat(existing, hook)
: [hook]
}
}
return {
exports: scriptExports,
options: options
}
}
// CONCATENATED MODULE: ./src/components/drawer/drawer.vue
/* normalize component */
var component = normalizeComponent(
drawer_drawervue_type_script_lang_js_,
render,
staticRenderFns,
false,
null,
null,
null
)
/* harmony default export */ var drawer = __webpack_exports__["default"] = (component.exports);
/***/ })
/******/ ]);