@mdsfe/mds-ui 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/CHANGELOG.md +778 -0
  2. package/LICENSE +21 -0
  3. package/README.md +106 -0
  4. package/dist/_locale/index.js +18 -0
  5. package/dist/_locale/zh-CN.js +123 -0
  6. package/dist/_mixin/emitter.js +35 -0
  7. package/dist/_mixin/focus.js +13 -0
  8. package/dist/_mixin/locale.js +17 -0
  9. package/dist/_mixin/popper.js +192 -0
  10. package/dist/_mixin/tooltip.js +218 -0
  11. package/dist/_util/__test__/switchcase.test.js +43 -0
  12. package/dist/_util/autoprefixer.js +249 -0
  13. package/dist/_util/clickoutside.js +79 -0
  14. package/dist/_util/date.js +368 -0
  15. package/dist/_util/dateUtil.js +311 -0
  16. package/dist/_util/dom.js +240 -0
  17. package/dist/_util/getRequestAnimationFrame.js +50 -0
  18. package/dist/_util/getScroll.js +21 -0
  19. package/dist/_util/loaders/loaders.css.js +52 -0
  20. package/dist/_util/loaders/loading.js +53 -0
  21. package/dist/_util/merge.js +18 -0
  22. package/dist/_util/popper.js +1261 -0
  23. package/dist/_util/popup/index.js +232 -0
  24. package/dist/_util/popup/popup-manager.js +205 -0
  25. package/dist/_util/proptype.js +12 -0
  26. package/dist/_util/repeatClick.js +30 -0
  27. package/dist/_util/resize.js +61 -0
  28. package/dist/_util/resizeEvent.js +59 -0
  29. package/dist/_util/scrollIntoView.js +38 -0
  30. package/dist/_util/scrollbar-width.js +37 -0
  31. package/dist/_util/soda.js +54 -0
  32. package/dist/_util/switchcase.js +22 -0
  33. package/dist/_util/throttleByAnimationFrame.js +70 -0
  34. package/dist/_util/tree/node.js +412 -0
  35. package/dist/_util/tree/tree.js +410 -0
  36. package/dist/_util/util.js +166 -0
  37. package/dist/_util/vue-popper.js +213 -0
  38. package/dist/affix.js +509 -0
  39. package/dist/anchor.js +522 -0
  40. package/dist/avatar.js +437 -0
  41. package/dist/backtop.js +469 -0
  42. package/dist/badge.js +439 -0
  43. package/dist/bordershadow.js +310 -0
  44. package/dist/breadcrumb.js +434 -0
  45. package/dist/button.js +579 -0
  46. package/dist/card.js +514 -0
  47. package/dist/carousel.js +1326 -0
  48. package/dist/cascaderpanel.js +2320 -0
  49. package/dist/checkbox.js +681 -0
  50. package/dist/col.js +546 -0
  51. package/dist/collapse.js +671 -0
  52. package/dist/color.js +306 -0
  53. package/dist/datepicker.js +8089 -0
  54. package/dist/divider.js +346 -0
  55. package/dist/drawer.js +652 -0
  56. package/dist/dropdown.js +687 -0
  57. package/dist/empty.js +416 -0
  58. package/dist/font.js +306 -0
  59. package/dist/form.js +878 -0
  60. package/dist/icon.js +401 -0
  61. package/dist/index.js +1 -0
  62. package/dist/input.js +1251 -0
  63. package/dist/inputnumber.js +689 -0
  64. package/dist/layout.js +786 -0
  65. package/dist/list.js +789 -0
  66. package/dist/loading.js +430 -0
  67. package/dist/mds-ui.min.css +7 -0
  68. package/dist/mds-ui.min.js +64911 -0
  69. package/dist/menu.js +1131 -0
  70. package/dist/message.js +1016 -0
  71. package/dist/modal.js +895 -0
  72. package/dist/notification.js +818 -0
  73. package/dist/pagination.js +1213 -0
  74. package/dist/popconfirm.js +336 -0
  75. package/dist/popover.js +206 -0
  76. package/dist/progress.js +1023 -0
  77. package/dist/radio.js +760 -0
  78. package/dist/rate.js +765 -0
  79. package/dist/row.js +546 -0
  80. package/dist/select.js +4950 -0
  81. package/dist/slider.js +1411 -0
  82. package/dist/slottable.js +1414 -0
  83. package/dist/steps.js +546 -0
  84. package/dist/style/affix.css +5524 -0
  85. package/dist/style/anchor.css +5572 -0
  86. package/dist/style/avatar.css +5587 -0
  87. package/dist/style/backtop.css +34 -0
  88. package/dist/style/badge.css +5655 -0
  89. package/dist/style/bordershadow.css +5601 -0
  90. package/dist/style/breadcrumb.css +5551 -0
  91. package/dist/style/button.css +7679 -0
  92. package/dist/style/card.css +5670 -0
  93. package/dist/style/carousel.css +5731 -0
  94. package/dist/style/cascaderpanel.css +125 -0
  95. package/dist/style/checkbox.css +5700 -0
  96. package/dist/style/col.css +8121 -0
  97. package/dist/style/collapse.css +5593 -0
  98. package/dist/style/color.css +6136 -0
  99. package/dist/style/datepicker.css +5977 -0
  100. package/dist/style/divider.css +5558 -0
  101. package/dist/style/drawer.css +7979 -0
  102. package/dist/style/dropdown.css +7950 -0
  103. package/dist/style/empty.css +5563 -0
  104. package/dist/style/font.css +5559 -0
  105. package/dist/style/form.css +5662 -0
  106. package/dist/style/icon.css +5538 -0
  107. package/dist/style/input.css +6256 -0
  108. package/dist/style/inputnumber.css +5828 -0
  109. package/dist/style/layout.css +5572 -0
  110. package/dist/style/list.css +5655 -0
  111. package/dist/style/loading.css +5540 -0
  112. package/dist/style/menu.css +6183 -0
  113. package/dist/style/message.css +194 -0
  114. package/dist/style/modal.css +5637 -0
  115. package/dist/style/notification.css +5706 -0
  116. package/dist/style/pagination.css +6683 -0
  117. package/dist/style/popconfirm.css +7951 -0
  118. package/dist/style/popover.css +5727 -0
  119. package/dist/style/progress.css +5714 -0
  120. package/dist/style/radio.css +5769 -0
  121. package/dist/style/rate.css +5616 -0
  122. package/dist/style/row.css +8121 -0
  123. package/dist/style/select.css +5729 -0
  124. package/dist/style/slider.css +5594 -0
  125. package/dist/style/slottable.css +5831 -0
  126. package/dist/style/steps.css +6100 -0
  127. package/dist/style/switch.css +5624 -0
  128. package/dist/style/table.css +8392 -0
  129. package/dist/style/tabs.css +6047 -0
  130. package/dist/style/tag.css +5935 -0
  131. package/dist/style/text.css +5636 -0
  132. package/dist/style/timeline.css +5602 -0
  133. package/dist/style/timepicker.css +5904 -0
  134. package/dist/style/tooltip.css +5686 -0
  135. package/dist/style/transfer.css +101 -0
  136. package/dist/style/transition.css +1417 -0
  137. package/dist/style/tree.css +5598 -0
  138. package/dist/style/typography.css +5640 -0
  139. package/dist/style/upload.css +5834 -0
  140. package/dist/switch.js +448 -0
  141. package/dist/table.js +3809 -0
  142. package/dist/tabs.js +1273 -0
  143. package/dist/tag.js +478 -0
  144. package/dist/text.js +1100 -0
  145. package/dist/timeline.js +495 -0
  146. package/dist/timepicker.js +1567 -0
  147. package/dist/tooltip.js +179 -0
  148. package/dist/transfer.js +981 -0
  149. package/dist/transition.js +246 -0
  150. package/dist/tree.js +1866 -0
  151. package/dist/typography.js +469 -0
  152. package/dist/upload.js +1990 -0
  153. package/package.json +144 -0
@@ -0,0 +1,218 @@
1
+ 'use strict';
2
+
3
+ exports.__esModule = true;
4
+ exports.MdsTooltipContent = undefined;
5
+
6
+ var _from = require('babel-runtime/core-js/array/from');
7
+
8
+ var _from2 = _interopRequireDefault(_from);
9
+
10
+ var _vue = require('vue');
11
+
12
+ var _vue2 = _interopRequireDefault(_vue);
13
+
14
+ var _popper = require('./popper');
15
+
16
+ var _popper2 = _interopRequireDefault(_popper);
17
+
18
+ var _transition = require('../transition');
19
+
20
+ var _transition2 = _interopRequireDefault(_transition);
21
+
22
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+
24
+ var MdsTooltipContent = exports.MdsTooltipContent = {
25
+ functional: true,
26
+ render: function render(h, context) {
27
+ var data = context.data;
28
+ return h('div', {
29
+ 'class': ['mds-tooltip-inner']
30
+ }, data.$slots.title || data.title);
31
+ }
32
+ };
33
+
34
+ /**
35
+ * 统一处理浮层提示功能
36
+ */
37
+ exports.default = {
38
+ mixins: [_popper2.default],
39
+ props: {
40
+ placement: {
41
+ type: String,
42
+ default: 'top'
43
+ },
44
+ title: String,
45
+ disabled: Boolean,
46
+ effect: {
47
+ type: String,
48
+ default: 'dark'
49
+ },
50
+ trigger: {
51
+ type: String,
52
+ default: 'hover'
53
+ },
54
+ mouseEnterDelay: {
55
+ type: Number,
56
+ default: 0
57
+ },
58
+ mouseLeaveDelay: {
59
+ type: Number,
60
+ default: 0.1
61
+ },
62
+ className: {
63
+ type: String
64
+ },
65
+ popperOptions: {
66
+ type: Object,
67
+ default: function _default() {}
68
+ }
69
+ },
70
+ data: function data() {
71
+ return {
72
+ visibleArrow: true
73
+ };
74
+ },
75
+ beforeCreate: function beforeCreate() {
76
+ this.popperVM = new _vue2.default({
77
+ components: {
78
+ MdsTransition: _transition2.default,
79
+ MdsTooltipContent: MdsTooltipContent
80
+ },
81
+ data: {
82
+ _h: function _h() {},
83
+ vnode: ''
84
+ },
85
+ render: function render(h) {
86
+ this._h = h;
87
+ return this.vnode;
88
+ }
89
+ }).$mount();
90
+ },
91
+ render: function render(h) {
92
+ if (this.popperVM) {
93
+ var _h = this.popperVM._h;
94
+ this.popperVM.vnode = _h('mds-transition', {
95
+ props: {
96
+ type: 'zoom',
97
+ motion: 'big-fast'
98
+ }
99
+ }, [_h('div', {
100
+ 'class': this.popperCls,
101
+ directives: [{
102
+ name: 'show',
103
+ value: !this.disabled && this.visible,
104
+ expression: 'show'
105
+ }],
106
+ ref: 'popper'
107
+ }, [_h('div', {
108
+ 'class': [this.prefixCls + '-content', this.effect === 'light' ? 'mds-tooltip-light' : '']
109
+ }, [h('mds-tooltip-content', this)])])]);
110
+ }
111
+ if (!this.$slots.default || !this.$slots.default.length) return this.$slots.default;
112
+ return this.$slots.default[0];
113
+ },
114
+ mounted: function mounted() {
115
+ var _this = this;
116
+
117
+ if (this.$slots.default && this.$slots.default.length > 0) {
118
+ this.reference = this.$slots.default[0].elm;
119
+ if (this.trigger === 'click') {
120
+ this.reference.addEventListener('click', this.toggle);
121
+ document.addEventListener('click', this.clickDocument);
122
+ } else if (this.trigger === 'focus') {
123
+ var flag = false;
124
+ // 元素中包含input/textarea优先使用focus和blur事件,其他使用mouse事件
125
+ if (this.reference.nodeName === 'INPUT' || this.reference.nodeName === 'TEXTAREA') {
126
+ this.reference.addEventListener('focus', this.showPopper);
127
+ this.reference.addEventListener('blur', this.closePopper);
128
+ flag = true;
129
+ } else if (this.reference.children.length > 0) {
130
+ flag = (0, _from2.default)(this.reference.children).some(function (node) {
131
+ if (node.nodeName === 'INPUT' || node.nodeName === 'TEXTAREA') {
132
+ node.addEventListener('focus', _this.showPopper);
133
+ node.addEventListener('blur', _this.closePopper);
134
+ return true;
135
+ }
136
+ return false;
137
+ });
138
+ }
139
+ if (!flag) {
140
+ this.reference.addEventListener('mousedown', this.showPopper);
141
+ this.reference.addEventListener('mouseup', this.closePopper);
142
+ // 处理鼠标一直按下直到移出点击区域时浮层没关闭的情况
143
+ this.reference.addEventListener('blur', this.closePopper);
144
+ }
145
+ } else {
146
+ this.reference.addEventListener('mouseenter', this.showPopper);
147
+ this.reference.addEventListener('mouseleave', this.closePopper);
148
+ }
149
+ this.$nextTick(function () {
150
+ _this.$nextTick(function () {
151
+ _this.popper = _this.popperVM.$el || _this.$refs.popper || _this.popper;
152
+ if (_this.popper && _this.trigger === 'hover') {
153
+ _this.popper.addEventListener('mouseenter', function () {
154
+ clearTimeout(_this.timeout);
155
+ });
156
+ _this.popper.addEventListener('mouseleave', _this.closePopper);
157
+ }
158
+ });
159
+ });
160
+ }
161
+ if (this.$attrs.value) {
162
+ this.showPopper();
163
+ }
164
+ },
165
+
166
+ components: {
167
+ MdsTransition: _transition2.default
168
+ },
169
+ computed: {
170
+ popperCls: function popperCls() {
171
+ return [this.prefixCls].concat(this.placementCls).concat(this.className);
172
+ },
173
+ currentMouseEnterDelay: function currentMouseEnterDelay() {
174
+ return this.mouseEnterDelay * 1000;
175
+ },
176
+ currentMouseLeaveDelay: function currentMouseLeaveDelay() {
177
+ return this.mouseLeaveDelay * 1000;
178
+ }
179
+ },
180
+ destroyed: function destroyed() {
181
+ document.removeEventListener('click', this.clickDocument);
182
+ },
183
+
184
+ methods: {
185
+ toggle: function toggle() {
186
+ return this.visible ? this.closePopper() : this.showPopper();
187
+ },
188
+ showPopper: function showPopper() {
189
+ var _this2 = this;
190
+
191
+ if (this.visible) return;
192
+ clearTimeout(this.timeout);
193
+ this.timeout = setTimeout(function () {
194
+ _this2.visible = true;
195
+ _this2.$emit('onVisibleChange', _this2.visible);
196
+ }, this.currentMouseEnterDelay);
197
+ },
198
+ closePopper: function closePopper() {
199
+ var _this3 = this;
200
+
201
+ if (!this.visible) return;
202
+ clearTimeout(this.timeout);
203
+ this.timeout = setTimeout(function () {
204
+ _this3.visible = false;
205
+ _this3.$emit('onVisibleChange', _this3.visible);
206
+ }, this.currentMouseLeaveDelay);
207
+ },
208
+
209
+ /**
210
+ * 点击其他空白位置需要关闭浮层
211
+ * @param e
212
+ */
213
+ clickDocument: function clickDocument(e) {
214
+ if (!this.visible || !this.$el || !this.reference || !this.popper || this.$el.contains(e.target) || this.reference.contains(e.target) || this.popper.contains(e.target)) return;
215
+ this.closePopper();
216
+ }
217
+ }
218
+ };
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ var _switchcase = require('../switchcase.js');
4
+
5
+ describe('Util Switchcase', function () {
6
+ var rateMap = function rateMap(rate) {
7
+ return (0, _switchcase.switchcase)({
8
+ '1': 'Bad',
9
+ '2': 'Normal',
10
+ '3': 'Good'
11
+ })('No Info')(rate);
12
+ };
13
+
14
+ var rateFunctionMap = function rateFunctionMap(rate) {
15
+ return (0, _switchcase.switchcaseF)({
16
+ bad: function bad() {
17
+ return 1;
18
+ },
19
+ normal: function normal() {
20
+ return 2;
21
+ },
22
+ good: function good() {
23
+ return 3;
24
+ }
25
+ })('No Info')(rate);
26
+ };
27
+
28
+ it('should return the correct value', function () {
29
+ expect(rateMap('1')).toBe('Bad');
30
+ });
31
+
32
+ it('should return the default value', function () {
33
+ expect(rateMap('5')).toBe('No Info');
34
+ });
35
+
36
+ it('should execute the correct function', function () {
37
+ expect(rateFunctionMap('bad')).toBe(1);
38
+ });
39
+
40
+ it('should execute the correct function', function () {
41
+ expect(rateFunctionMap('what')).toBe('No Info');
42
+ });
43
+ });
@@ -0,0 +1,249 @@
1
+ 'use strict';
2
+
3
+ exports.__esModule = true;
4
+ exports.isEmpty = exports.isEqual = exports.arrayEquals = exports.looseEqual = exports.capitalize = exports.kebabCase = exports.autoprefixer = exports.isFirefox = exports.isEdge = exports.isIE = exports.coerceTruthyValueToArray = exports.arrayFind = exports.arrayFindIndex = exports.escapeRegexpString = exports.valueEquals = exports.generateId = exports.getValueByPath = undefined;
5
+
6
+ var _keys = require('babel-runtime/core-js/object/keys');
7
+
8
+ var _keys2 = _interopRequireDefault(_keys);
9
+
10
+ var _stringify = require('babel-runtime/core-js/json/stringify');
11
+
12
+ var _stringify2 = _interopRequireDefault(_stringify);
13
+
14
+ var _typeof2 = require('babel-runtime/helpers/typeof');
15
+
16
+ var _typeof3 = _interopRequireDefault(_typeof2);
17
+
18
+ exports.isString = isString;
19
+ exports.isObject = isObject;
20
+ exports.noop = noop;
21
+ exports.hasOwn = hasOwn;
22
+ exports.toObject = toObject;
23
+ exports.getPropByPath = getPropByPath;
24
+ exports.rafThrottle = rafThrottle;
25
+ exports.objToArray = objToArray;
26
+
27
+ var _vue = require('vue');
28
+
29
+ var _vue2 = _interopRequireDefault(_vue);
30
+
31
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
32
+
33
+ function isString(obj) {
34
+ return Object.prototype.toString.call(obj) === '[object String]';
35
+ }
36
+ function isObject(obj) {
37
+ return Object.prototype.toString.call(obj) === '[object Object]';
38
+ }
39
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
40
+ function noop() {}
41
+ function hasOwn(obj, key) {
42
+ return hasOwnProperty.call(obj, key);
43
+ }
44
+ function extend(to, _from) {
45
+ for (var key in _from) {
46
+ to[key] = _from[key];
47
+ }
48
+ return to;
49
+ }
50
+ function toObject(arr) {
51
+ var res = {};
52
+ for (var i = 0; i < arr.length; i++) {
53
+ if (arr[i]) {
54
+ extend(res, arr[i]);
55
+ }
56
+ }
57
+ return res;
58
+ }
59
+ var getValueByPath = exports.getValueByPath = function getValueByPath(object, prop) {
60
+ prop = prop || '';
61
+ var paths = prop.split('.');
62
+ var current = object;
63
+ var result = null;
64
+ for (var i = 0, j = paths.length; i < j; i++) {
65
+ var path = paths[i];
66
+ if (!current) break;
67
+ if (i === j - 1) {
68
+ result = current[path];
69
+ break;
70
+ }
71
+ current = current[path];
72
+ }
73
+ return result;
74
+ };
75
+ function getPropByPath(obj, path, strict) {
76
+ var tempObj = obj;
77
+ path = path.replace(/\[(\w+)\]/g, '.$1');
78
+ path = path.replace(/^\./, '');
79
+ var keyArr = path.split('.');
80
+ var i = 0;
81
+ for (var len = keyArr.length; i < len - 1; ++i) {
82
+ if (!tempObj && !strict) break;
83
+ var key = keyArr[i];
84
+ if (key in tempObj) {
85
+ tempObj = tempObj[key];
86
+ } else {
87
+ if (strict) {
88
+ throw new Error('please transfer a valid prop path to form item!');
89
+ }
90
+ break;
91
+ }
92
+ }
93
+ return {
94
+ o: tempObj,
95
+ k: keyArr[i],
96
+ v: tempObj ? tempObj[keyArr[i]] : null
97
+ };
98
+ }
99
+ var generateId = exports.generateId = function generateId() {
100
+ return Math.floor(Math.random() * 10000);
101
+ };
102
+ var valueEquals = exports.valueEquals = function valueEquals(a, b) {
103
+ // see: https://stackoverflow.com/questions/3115982/how-to-check-if-two-arrays-are-equal-with-javascript
104
+ if (a === b) return true;
105
+ if (!(a instanceof Array)) return false;
106
+ if (!(b instanceof Array)) return false;
107
+ if (a.length !== b.length) return false;
108
+ for (var i = 0; i !== a.length; ++i) {
109
+ if (a[i] !== b[i]) return false;
110
+ }
111
+ return true;
112
+ };
113
+ var escapeRegexpString = exports.escapeRegexpString = function escapeRegexpString() {
114
+ var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
115
+ return String(value).replace(/[|\\{}()[\]^$+*?.]/g, '\\$&');
116
+ };
117
+ // TODO: use native Array.find, Array.findIndex when IE support is dropped
118
+ var arrayFindIndex = exports.arrayFindIndex = function arrayFindIndex(arr, pred) {
119
+ for (var i = 0; i !== arr.length; ++i) {
120
+ if (pred(arr[i])) {
121
+ return i;
122
+ }
123
+ }
124
+ return -1;
125
+ };
126
+ var arrayFind = exports.arrayFind = function arrayFind(arr, pred) {
127
+ var idx = arrayFindIndex(arr, pred);
128
+ return idx !== -1 ? arr[idx] : undefined;
129
+ };
130
+ // coerce truthy value to array
131
+ var coerceTruthyValueToArray = exports.coerceTruthyValueToArray = function coerceTruthyValueToArray(val) {
132
+ if (Array.isArray(val)) {
133
+ return val;
134
+ } else if (val) {
135
+ return [val];
136
+ } else {
137
+ return [];
138
+ }
139
+ };
140
+ var isIE = exports.isIE = function isIE() {
141
+ return !_vue2.default.prototype.$isServer && !isNaN(Number(document.documentMode));
142
+ };
143
+ var isEdge = exports.isEdge = function isEdge() {
144
+ return !_vue2.default.prototype.$isServer && navigator.userAgent.indexOf('Edge') > -1;
145
+ };
146
+ var isFirefox = exports.isFirefox = function isFirefox() {
147
+ return !_vue2.default.prototype.$isServer && !!window.navigator.userAgent.match(/firefox/i);
148
+ };
149
+ var autoprefixer = exports.autoprefixer = function autoprefixer(style) {
150
+ if ((typeof style === 'undefined' ? 'undefined' : (0, _typeof3.default)(style)) !== 'object') return style;
151
+ var rules = ['transform', 'transition', 'animation'];
152
+ var prefixes = ['ms-', 'webkit-'];
153
+ rules.forEach(function (rule) {
154
+ var value = style[rule];
155
+ if (rule && value) {
156
+ prefixes.forEach(function (prefix) {
157
+ style[prefix + rule] = value;
158
+ });
159
+ }
160
+ });
161
+ return style;
162
+ };
163
+ var kebabCase = exports.kebabCase = function kebabCase(str) {
164
+ var hyphenateRE = /([^-])([A-Z])/g;
165
+ return str.replace(hyphenateRE, '$1-$2').replace(hyphenateRE, '$1-$2').toLowerCase();
166
+ };
167
+ var capitalize = exports.capitalize = function capitalize(str) {
168
+ if (!isString(str)) return str;
169
+ return str.charAt(0).toUpperCase() + str.slice(1);
170
+ };
171
+ var looseEqual = exports.looseEqual = function looseEqual(a, b) {
172
+ var isObjectA = isObject(a);
173
+ var isObjectB = isObject(b);
174
+ if (isObjectA && isObjectB) {
175
+ return (0, _stringify2.default)(a) === (0, _stringify2.default)(b);
176
+ } else if (!isObjectA && !isObjectB) {
177
+ return String(a) === String(b);
178
+ } else {
179
+ return false;
180
+ }
181
+ };
182
+ var arrayEquals = exports.arrayEquals = function arrayEquals(arrayA, arrayB) {
183
+ arrayA = arrayA || [];
184
+ arrayB = arrayB || [];
185
+ if (arrayA.length !== arrayB.length) {
186
+ return false;
187
+ }
188
+ for (var i = 0; i < arrayA.length; i++) {
189
+ if (!looseEqual(arrayA[i], arrayB[i])) {
190
+ return false;
191
+ }
192
+ }
193
+ return true;
194
+ };
195
+ var isEqual = exports.isEqual = function isEqual(value1, value2) {
196
+ if (Array.isArray(value1) && Array.isArray(value2)) {
197
+ return arrayEquals(value1, value2);
198
+ }
199
+ return looseEqual(value1, value2);
200
+ };
201
+ var isEmpty = exports.isEmpty = function isEmpty(val) {
202
+ // null or undefined
203
+ if (val == null) return true;
204
+ if (typeof val === 'boolean') return false;
205
+ if (typeof val === 'number') return !val;
206
+ if (val instanceof Error) return val.message === '';
207
+ switch (Object.prototype.toString.call(val)) {
208
+ // String or Array
209
+ case '[object String]':
210
+ case '[object Array]':
211
+ return !val.length;
212
+ // Map or Set or File
213
+ case '[object File]':
214
+ case '[object Map]':
215
+ case '[object Set]':
216
+ {
217
+ return !val.size;
218
+ }
219
+ // Plain Object
220
+ case '[object Object]':
221
+ {
222
+ return !(0, _keys2.default)(val).length;
223
+ }
224
+ }
225
+ return false;
226
+ };
227
+ function rafThrottle(fn) {
228
+ var locked = false;
229
+ return function () {
230
+ var _this = this;
231
+
232
+ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
233
+ args[_key] = arguments[_key];
234
+ }
235
+
236
+ if (locked) return;
237
+ locked = true;
238
+ window.requestAnimationFrame(function (_) {
239
+ fn.apply(_this, args);
240
+ locked = false;
241
+ });
242
+ };
243
+ }
244
+ function objToArray(obj) {
245
+ if (Array.isArray(obj)) {
246
+ return obj;
247
+ }
248
+ return isEmpty(obj) ? [] : [obj];
249
+ }
@@ -0,0 +1,79 @@
1
+ 'use strict';
2
+
3
+ exports.__esModule = true;
4
+
5
+ var _vue = require('vue');
6
+
7
+ var _vue2 = _interopRequireDefault(_vue);
8
+
9
+ var _dom = require('./dom.js');
10
+
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+
13
+ var nodeList = [];
14
+ var ctx = '@@clickoutsideContext';
15
+
16
+ var startClick = void 0;
17
+ var seed = 0;
18
+
19
+ !_vue2.default.prototype.$isServer && (0, _dom.on)(document, 'mousedown', function (e) {
20
+ return startClick = e;
21
+ });
22
+
23
+ !_vue2.default.prototype.$isServer && (0, _dom.on)(document, 'mouseup', function (e) {
24
+ nodeList.forEach(function (node) {
25
+ return node[ctx].documentHandler(e, startClick);
26
+ });
27
+ });
28
+
29
+ function createDocumentHandler(el, binding, vnode) {
30
+ return function () {
31
+ var mouseup = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
32
+ var mousedown = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
33
+
34
+ if (!vnode || !vnode.context || !mouseup.target || !mousedown.target || el.contains(mouseup.target) || el.contains(mousedown.target) || el === mouseup.target || vnode.context.popperElm && (vnode.context.popperElm.contains(mouseup.target) || vnode.context.popperElm.contains(mousedown.target))) return;
35
+
36
+ if (binding.expression && el[ctx].methodName && vnode.context[el[ctx].methodName]) {
37
+ vnode.context[el[ctx].methodName]();
38
+ } else {
39
+ el[ctx].bindingFn && el[ctx].bindingFn();
40
+ }
41
+ };
42
+ }
43
+
44
+ /**
45
+ * v-clickoutside
46
+ * @desc 点击元素外面才会触发的事件
47
+ * @example
48
+ * ```vue
49
+ * <div v-element-clickoutside="handleClose">
50
+ * ```
51
+ */
52
+ exports.default = {
53
+ bind: function bind(el, binding, vnode) {
54
+ nodeList.push(el);
55
+ var id = seed++;
56
+ el[ctx] = {
57
+ id: id,
58
+ documentHandler: createDocumentHandler(el, binding, vnode),
59
+ methodName: binding.expression,
60
+ bindingFn: binding.value
61
+ };
62
+ },
63
+ update: function update(el, binding, vnode) {
64
+ el[ctx].documentHandler = createDocumentHandler(el, binding, vnode);
65
+ el[ctx].methodName = binding.expression;
66
+ el[ctx].bindingFn = binding.value;
67
+ },
68
+ unbind: function unbind(el) {
69
+ var len = nodeList.length;
70
+
71
+ for (var i = 0; i < len; i++) {
72
+ if (nodeList[i][ctx].id === el[ctx].id) {
73
+ nodeList.splice(i, 1);
74
+ break;
75
+ }
76
+ }
77
+ delete el[ctx];
78
+ }
79
+ };