@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,368 @@
1
+ 'use strict';
2
+
3
+ /* Modified from https://github.com/taylorhakes/fecha
4
+ *
5
+ * The MIT License (MIT)
6
+ *
7
+ * Copyright (c) 2015 Taylor Hakes
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ * of this software and associated documentation files (the "Software"), to deal
11
+ * in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ * copies of the Software, and to permit persons to whom the Software is
14
+ * furnished to do so, subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in all
17
+ * copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ * SOFTWARE.
26
+ */
27
+
28
+ /*eslint-disable*/
29
+ // 把 YYYY-MM-DD 改成了 yyyy-MM-dd
30
+ (function (main) {
31
+ 'use strict';
32
+
33
+ /**
34
+ * Parse or format dates
35
+ * @class fecha
36
+ */
37
+
38
+ var fecha = {};
39
+ var token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
40
+ var twoDigits = '\\d\\d?';
41
+ var threeDigits = '\\d{3}';
42
+ var fourDigits = '\\d{4}';
43
+ var word = '[^\\s]+';
44
+ var literal = /\[([^]*?)\]/gm;
45
+ var noop = function noop() {};
46
+
47
+ function regexEscape(str) {
48
+ return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
49
+ }
50
+
51
+ function shorten(arr, sLen) {
52
+ var newArr = [];
53
+ for (var i = 0, len = arr.length; i < len; i++) {
54
+ newArr.push(arr[i].substr(0, sLen));
55
+ }
56
+ return newArr;
57
+ }
58
+
59
+ function monthUpdate(arrName) {
60
+ return function (d, v, i18n) {
61
+ var index = i18n[arrName].indexOf(v.charAt(0).toUpperCase() + v.substr(1).toLowerCase());
62
+ if (~index) {
63
+ d.month = index;
64
+ }
65
+ };
66
+ }
67
+
68
+ function pad(val, len) {
69
+ val = String(val);
70
+ len = len || 2;
71
+ while (val.length < len) {
72
+ val = '0' + val;
73
+ }
74
+ return val;
75
+ }
76
+
77
+ var dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
78
+ var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
79
+ var monthNamesShort = shorten(monthNames, 3);
80
+ var dayNamesShort = shorten(dayNames, 3);
81
+ fecha.i18n = {
82
+ dayNamesShort: dayNamesShort,
83
+ dayNames: dayNames,
84
+ monthNamesShort: monthNamesShort,
85
+ monthNames: monthNames,
86
+ amPm: ['am', 'pm'],
87
+ DoFn: function DoFn(D) {
88
+ return D + ['th', 'st', 'nd', 'rd'][D % 10 > 3 ? 0 : (D - D % 10 !== 10) * D % 10];
89
+ }
90
+ };
91
+
92
+ var formatFlags = {
93
+ D: function D(dateObj) {
94
+ return dateObj.getDay();
95
+ },
96
+ DD: function DD(dateObj) {
97
+ return pad(dateObj.getDay());
98
+ },
99
+ Do: function Do(dateObj, i18n) {
100
+ return i18n.DoFn(dateObj.getDate());
101
+ },
102
+ d: function d(dateObj) {
103
+ return dateObj.getDate();
104
+ },
105
+ dd: function dd(dateObj) {
106
+ return pad(dateObj.getDate());
107
+ },
108
+ ddd: function ddd(dateObj, i18n) {
109
+ return i18n.dayNamesShort[dateObj.getDay()];
110
+ },
111
+ dddd: function dddd(dateObj, i18n) {
112
+ return i18n.dayNames[dateObj.getDay()];
113
+ },
114
+ M: function M(dateObj) {
115
+ return dateObj.getMonth() + 1;
116
+ },
117
+ MM: function MM(dateObj) {
118
+ return pad(dateObj.getMonth() + 1);
119
+ },
120
+ MMM: function MMM(dateObj, i18n) {
121
+ return i18n.monthNamesShort[dateObj.getMonth()];
122
+ },
123
+ MMMM: function MMMM(dateObj, i18n) {
124
+ return i18n.monthNames[dateObj.getMonth()];
125
+ },
126
+ yy: function yy(dateObj) {
127
+ return pad(String(dateObj.getFullYear()), 4).substr(2);
128
+ },
129
+ yyyy: function yyyy(dateObj) {
130
+ return pad(dateObj.getFullYear(), 4);
131
+ },
132
+ h: function h(dateObj) {
133
+ return dateObj.getHours() % 12 || 12;
134
+ },
135
+ hh: function hh(dateObj) {
136
+ return pad(dateObj.getHours() % 12 || 12);
137
+ },
138
+ H: function H(dateObj) {
139
+ return dateObj.getHours();
140
+ },
141
+ HH: function HH(dateObj) {
142
+ return pad(dateObj.getHours());
143
+ },
144
+ m: function m(dateObj) {
145
+ return dateObj.getMinutes();
146
+ },
147
+ mm: function mm(dateObj) {
148
+ return pad(dateObj.getMinutes());
149
+ },
150
+ s: function s(dateObj) {
151
+ return dateObj.getSeconds();
152
+ },
153
+ ss: function ss(dateObj) {
154
+ return pad(dateObj.getSeconds());
155
+ },
156
+ S: function S(dateObj) {
157
+ return Math.round(dateObj.getMilliseconds() / 100);
158
+ },
159
+ SS: function SS(dateObj) {
160
+ return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
161
+ },
162
+ SSS: function SSS(dateObj) {
163
+ return pad(dateObj.getMilliseconds(), 3);
164
+ },
165
+ a: function a(dateObj, i18n) {
166
+ return dateObj.getHours() < 12 ? i18n.amPm[0] : i18n.amPm[1];
167
+ },
168
+ A: function A(dateObj, i18n) {
169
+ return dateObj.getHours() < 12 ? i18n.amPm[0].toUpperCase() : i18n.amPm[1].toUpperCase();
170
+ },
171
+ ZZ: function ZZ(dateObj) {
172
+ var o = dateObj.getTimezoneOffset();
173
+ return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
174
+ }
175
+ };
176
+
177
+ var parseFlags = {
178
+ d: [twoDigits, function (d, v) {
179
+ d.day = v;
180
+ }],
181
+ Do: [twoDigits + word, function (d, v) {
182
+ d.day = parseInt(v, 10);
183
+ }],
184
+ M: [twoDigits, function (d, v) {
185
+ d.month = v - 1;
186
+ }],
187
+ yy: [twoDigits, function (d, v) {
188
+ var da = new Date(),
189
+ cent = +('' + da.getFullYear()).substr(0, 2);
190
+ d.year = '' + (v > 68 ? cent - 1 : cent) + v;
191
+ }],
192
+ h: [twoDigits, function (d, v) {
193
+ d.hour = v;
194
+ }],
195
+ m: [twoDigits, function (d, v) {
196
+ d.minute = v;
197
+ }],
198
+ s: [twoDigits, function (d, v) {
199
+ d.second = v;
200
+ }],
201
+ yyyy: [fourDigits, function (d, v) {
202
+ d.year = v;
203
+ }],
204
+ S: ['\\d', function (d, v) {
205
+ d.millisecond = v * 100;
206
+ }],
207
+ SS: ['\\d{2}', function (d, v) {
208
+ d.millisecond = v * 10;
209
+ }],
210
+ SSS: [threeDigits, function (d, v) {
211
+ d.millisecond = v;
212
+ }],
213
+ D: [twoDigits, noop],
214
+ ddd: [word, noop],
215
+ MMM: [word, monthUpdate('monthNamesShort')],
216
+ MMMM: [word, monthUpdate('monthNames')],
217
+ a: [word, function (d, v, i18n) {
218
+ var val = v.toLowerCase();
219
+ if (val === i18n.amPm[0]) {
220
+ d.isPm = false;
221
+ } else if (val === i18n.amPm[1]) {
222
+ d.isPm = true;
223
+ }
224
+ }],
225
+ ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
226
+ var parts = (v + '').match(/([+-]|\d\d)/gi),
227
+ minutes;
228
+
229
+ if (parts) {
230
+ minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
231
+ d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
232
+ }
233
+ }]
234
+ };
235
+ parseFlags.dd = parseFlags.d;
236
+ parseFlags.dddd = parseFlags.ddd;
237
+ parseFlags.DD = parseFlags.D;
238
+ parseFlags.mm = parseFlags.m;
239
+ parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
240
+ parseFlags.MM = parseFlags.M;
241
+ parseFlags.ss = parseFlags.s;
242
+ parseFlags.A = parseFlags.a;
243
+
244
+ // Some common format strings
245
+ fecha.masks = {
246
+ default: 'ddd MMM dd yyyy HH:mm:ss',
247
+ shortDate: 'M/D/yy',
248
+ mediumDate: 'MMM d, yyyy',
249
+ longDate: 'MMMM d, yyyy',
250
+ fullDate: 'dddd, MMMM d, yyyy',
251
+ shortTime: 'HH:mm',
252
+ mediumTime: 'HH:mm:ss',
253
+ longTime: 'HH:mm:ss.SSS'
254
+
255
+ /***
256
+ * Format a date
257
+ * @method format
258
+ * @param {Date|number} dateObj
259
+ * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
260
+ */
261
+ };fecha.format = function (dateObj, mask, i18nSettings) {
262
+ var i18n = i18nSettings || fecha.i18n;
263
+
264
+ if (typeof dateObj === 'number') {
265
+ dateObj = new Date(dateObj);
266
+ }
267
+
268
+ if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
269
+ throw new Error('Invalid Date in fecha.format');
270
+ }
271
+
272
+ mask = fecha.masks[mask] || mask || fecha.masks['default'];
273
+
274
+ var literals = [];
275
+
276
+ // Make literals inactive by replacing them with ??
277
+ mask = mask.replace(literal, function ($0, $1) {
278
+ literals.push($1);
279
+ return '@@@';
280
+ });
281
+ // Apply formatting rules
282
+ mask = mask.replace(token, function ($0) {
283
+ return $0 in formatFlags ? formatFlags[$0](dateObj, i18n) : $0.slice(1, $0.length - 1);
284
+ });
285
+ // Inline literal values back into the formatted value
286
+ return mask.replace(/@@@/g, function () {
287
+ return literals.shift();
288
+ });
289
+ };
290
+
291
+ /**
292
+ * Parse a date string into an object, changes - into /
293
+ * @method parse
294
+ * @param {string} dateStr Date string
295
+ * @param {string} format Date parse format
296
+ * @returns {Date|boolean}
297
+ */
298
+ fecha.parse = function (dateStr, format, i18nSettings) {
299
+ var i18n = i18nSettings || fecha.i18n;
300
+
301
+ if (typeof format !== 'string') {
302
+ throw new Error('Invalid format in fecha.parse');
303
+ }
304
+
305
+ format = fecha.masks[format] || format;
306
+
307
+ // Avoid regular expression denial of service, fail early for really long strings
308
+ // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
309
+ if (dateStr.length > 1000) {
310
+ return null;
311
+ }
312
+
313
+ var dateInfo = {};
314
+ var parseInfo = [];
315
+ var literals = [];
316
+ format = format.replace(literal, function ($0, $1) {
317
+ literals.push($1);
318
+ return '@@@';
319
+ });
320
+ var newFormat = regexEscape(format).replace(token, function ($0) {
321
+ if (parseFlags[$0]) {
322
+ var info = parseFlags[$0];
323
+ parseInfo.push(info[1]);
324
+ return '(' + info[0] + ')';
325
+ }
326
+
327
+ return $0;
328
+ });
329
+ newFormat = newFormat.replace(/@@@/g, function () {
330
+ return literals.shift();
331
+ });
332
+ var matches = dateStr.match(new RegExp(newFormat, 'i'));
333
+ if (!matches) {
334
+ return null;
335
+ }
336
+
337
+ for (var i = 1; i < matches.length; i++) {
338
+ parseInfo[i - 1](dateInfo, matches[i], i18n);
339
+ }
340
+
341
+ var today = new Date();
342
+ if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
343
+ dateInfo.hour = +dateInfo.hour + 12;
344
+ } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
345
+ dateInfo.hour = 0;
346
+ }
347
+
348
+ var date;
349
+ if (dateInfo.timezoneOffset != null) {
350
+ dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
351
+ date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1, dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
352
+ } else {
353
+ date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1, dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
354
+ }
355
+ return date;
356
+ };
357
+
358
+ /* istanbul ignore next */
359
+ if (typeof module !== 'undefined' && module.exports) {
360
+ module.exports = fecha;
361
+ } else if (typeof define === 'function' && define.amd) {
362
+ define(function () {
363
+ return fecha;
364
+ });
365
+ } else {
366
+ main.fecha = fecha;
367
+ }
368
+ })(undefined);
@@ -0,0 +1,311 @@
1
+ 'use strict';
2
+
3
+ exports.__esModule = true;
4
+ exports.validateRangeInOneMonth = exports.extractTimeFormat = exports.extractDateFormat = exports.nextYear = exports.prevYear = exports.nextMonth = exports.prevMonth = exports.changeYearMonthAndClampDate = exports.timeWithinRange = exports.limitTimeRange = exports.clearMilliseconds = exports.clearTime = exports.modifyWithTimeString = exports.modifyTime = exports.modifyDate = exports.range = exports.getRangeMinutes = exports.getMonthDays = exports.getPrevMonthLastDays = exports.getRangeHours = exports.getWeekNumber = exports.getStartDateOfMonth = exports.nextDate = exports.prevDate = exports.getFirstDayOfMonth = exports.getDayCountOfYear = exports.getDayCountOfMonth = exports.parseDate = exports.formatDate = exports.isDateObject = exports.isDate = exports.toDate = exports.getI18nSettings = undefined;
5
+
6
+ var _date = require('./date.js');
7
+
8
+ var _date2 = _interopRequireDefault(_date);
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ var weeks = ['日', '一', '二', '三', '四', '五', '六'];
13
+ var months = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
14
+
15
+ var newArray = function newArray(start, end) {
16
+ var result = [];
17
+ for (var i = start; i <= end; i++) {
18
+ result.push(i);
19
+ }
20
+ return result;
21
+ };
22
+
23
+ var getI18nSettings = exports.getI18nSettings = function getI18nSettings() {
24
+ return {
25
+ dayNamesShort: weeks,
26
+ dayNames: weeks,
27
+ monthNamesShort: months,
28
+ monthNames: months,
29
+ amPm: ['am', 'pm']
30
+ };
31
+ };
32
+
33
+ var toDate = exports.toDate = function toDate(date) {
34
+ return isDate(date) ? new Date(date) : null;
35
+ };
36
+
37
+ var isDate = exports.isDate = function isDate(date) {
38
+ if (date === null || date === undefined) return false;
39
+ if (isNaN(new Date(date).getTime())) return false;
40
+ if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
41
+ return true;
42
+ };
43
+
44
+ var isDateObject = exports.isDateObject = function isDateObject(val) {
45
+ return val instanceof Date;
46
+ };
47
+
48
+ var formatDate = exports.formatDate = function formatDate(date, format) {
49
+ date = toDate(date);
50
+ if (!date) return '';
51
+ return _date2.default.format(date, format || 'yyyy-MM-dd', getI18nSettings());
52
+ };
53
+
54
+ var parseDate = exports.parseDate = function parseDate(string, format) {
55
+ return _date2.default.parse(string, format || 'yyyy-MM-dd', getI18nSettings());
56
+ };
57
+
58
+ var getDayCountOfMonth = exports.getDayCountOfMonth = function getDayCountOfMonth(year, month) {
59
+ if (month === 3 || month === 5 || month === 8 || month === 10) {
60
+ return 30;
61
+ }
62
+
63
+ if (month === 1) {
64
+ if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
65
+ return 29;
66
+ } else {
67
+ return 28;
68
+ }
69
+ }
70
+
71
+ return 31;
72
+ };
73
+
74
+ var getDayCountOfYear = exports.getDayCountOfYear = function getDayCountOfYear(year) {
75
+ var isLeapYear = year % 400 === 0 || year % 100 !== 0 && year % 4 === 0;
76
+ return isLeapYear ? 366 : 365;
77
+ };
78
+
79
+ var getFirstDayOfMonth = exports.getFirstDayOfMonth = function getFirstDayOfMonth(date) {
80
+ var temp = new Date(date.getTime());
81
+ temp.setDate(1);
82
+ return temp.getDay();
83
+ };
84
+
85
+ // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
86
+ // {prev, next} Date should work for Daylight Saving Time
87
+ // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
88
+ var prevDate = exports.prevDate = function prevDate(date) {
89
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
90
+
91
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
92
+ };
93
+
94
+ var nextDate = exports.nextDate = function nextDate(date) {
95
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
96
+
97
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
98
+ };
99
+
100
+ var getStartDateOfMonth = exports.getStartDateOfMonth = function getStartDateOfMonth(year, month) {
101
+ var result = new Date(year, month, 1);
102
+ var day = result.getDay();
103
+
104
+ if (day === 0) {
105
+ return prevDate(result, 7);
106
+ } else {
107
+ return prevDate(result, day);
108
+ }
109
+ };
110
+
111
+ var getWeekNumber = exports.getWeekNumber = function getWeekNumber(src) {
112
+ if (!isDate(src)) return null;
113
+ var date = new Date(src.getTime());
114
+ date.setHours(0, 0, 0, 0);
115
+ // Thursday in current week decides the year.
116
+ date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
117
+ // January 4 is always in week 1.
118
+ var week1 = new Date(date.getFullYear(), 0, 4);
119
+ // Adjust to Thursday in week 1 and count number of weeks from date to week 1.
120
+ // Rounding should be fine for Daylight Saving Time. Its shift should never be more than 12 hours.
121
+ return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7);
122
+ };
123
+
124
+ var getRangeHours = exports.getRangeHours = function getRangeHours() {
125
+ var ranges = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
126
+
127
+ var hours = [];
128
+ var disabledHours = [];
129
+
130
+ ranges.forEach(function (range) {
131
+ var value = range.map(function (date) {
132
+ return date.getHours();
133
+ });
134
+
135
+ disabledHours = disabledHours.concat(newArray(value[0], value[1]));
136
+ });
137
+
138
+ if (disabledHours.length) {
139
+ for (var i = 0; i < 24; i++) {
140
+ hours[i] = disabledHours.indexOf(i) === -1;
141
+ }
142
+ } else {
143
+ for (var _i = 0; _i < 24; _i++) {
144
+ hours[_i] = false;
145
+ }
146
+ }
147
+
148
+ return hours;
149
+ };
150
+
151
+ var getPrevMonthLastDays = exports.getPrevMonthLastDays = function getPrevMonthLastDays(date, amount) {
152
+ if (amount <= 0) return [];
153
+ var temp = new Date(date.getTime());
154
+ temp.setDate(0);
155
+ var lastDay = temp.getDate();
156
+ return range(amount).map(function (_, index) {
157
+ return lastDay - (amount - index - 1);
158
+ });
159
+ };
160
+
161
+ var getMonthDays = exports.getMonthDays = function getMonthDays(date) {
162
+ var temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
163
+ var days = temp.getDate();
164
+ return range(days).map(function (_, index) {
165
+ return index + 1;
166
+ });
167
+ };
168
+
169
+ function setRangeData(arr, start, end, value, step) {
170
+ for (var i = start; i < end; i += step) {
171
+ arr.push(i);
172
+ }
173
+ }
174
+
175
+ var getRangeMinutes = exports.getRangeMinutes = function getRangeMinutes(ranges, hour, step) {
176
+ var minutes = [];
177
+ if (ranges.length > 0) {
178
+ ranges.forEach(function (range) {
179
+ var start = range[0];
180
+ var end = range[1];
181
+ var startHour = start.getHours();
182
+ var startMinute = start.getMinutes();
183
+ var endHour = end.getHours();
184
+ var endMinute = end.getMinutes();
185
+ if (startHour === hour && endHour !== hour) {
186
+ setRangeData(minutes, startMinute, 60, true, step);
187
+ } else if (startHour === hour && endHour === hour) {
188
+ setRangeData(minutes, startMinute, endMinute + 1, true, step);
189
+ } else if (startHour !== hour && endHour === hour) {
190
+ setRangeData(minutes, 0, endMinute + 1, true, step);
191
+ } else if (startHour < hour && endHour > hour) {
192
+ setRangeData(minutes, 0, 60, true, step);
193
+ }
194
+ });
195
+ } else {
196
+ setRangeData(minutes, 0, 60, true, step);
197
+ }
198
+ return minutes;
199
+ };
200
+
201
+ var range = exports.range = function range(n) {
202
+ // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
203
+ return Array.apply(null, { length: n }).map(function (_, n) {
204
+ return n;
205
+ });
206
+ };
207
+
208
+ var modifyDate = exports.modifyDate = function modifyDate(date, y, m, d) {
209
+ return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
210
+ };
211
+
212
+ var modifyTime = exports.modifyTime = function modifyTime(date, h, m, s) {
213
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
214
+ };
215
+
216
+ var modifyWithTimeString = exports.modifyWithTimeString = function modifyWithTimeString(date, time) {
217
+ if (date == null || !time) {
218
+ return date;
219
+ }
220
+ time = parseDate(time, 'HH:mm:ss');
221
+ return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
222
+ };
223
+
224
+ var clearTime = exports.clearTime = function clearTime(date) {
225
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
226
+ };
227
+
228
+ var clearMilliseconds = exports.clearMilliseconds = function clearMilliseconds(date) {
229
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
230
+ };
231
+
232
+ var limitTimeRange = exports.limitTimeRange = function limitTimeRange(date, ranges) {
233
+ var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'HH:mm:ss';
234
+
235
+ // TODO: refactory a more elegant solution
236
+ if (ranges.length === 0) return date;
237
+ var normalizeDate = function normalizeDate(date) {
238
+ return _date2.default.parse(_date2.default.format(date, format), format);
239
+ };
240
+ var ndate = normalizeDate(date);
241
+ var nranges = ranges.map(function (range) {
242
+ return range.map(normalizeDate);
243
+ });
244
+ if (nranges.some(function (nrange) {
245
+ return ndate >= nrange[0] && ndate <= nrange[1];
246
+ })) return date;
247
+
248
+ var minDate = nranges[0][0];
249
+ var maxDate = nranges[0][0];
250
+
251
+ nranges.forEach(function (nrange) {
252
+ minDate = new Date(Math.min(nrange[0], minDate));
253
+ maxDate = new Date(Math.max(nrange[1], minDate));
254
+ });
255
+
256
+ var ret = ndate < minDate ? minDate : maxDate;
257
+ // preserve Year/Month/Date
258
+ return modifyDate(ret, date.getFullYear(), date.getMonth(), date.getDate());
259
+ };
260
+
261
+ var timeWithinRange = exports.timeWithinRange = function timeWithinRange(date, selectableRange, format) {
262
+ var limitedDate = limitTimeRange(date, selectableRange, format);
263
+ return limitedDate.getTime() === date.getTime();
264
+ };
265
+
266
+ var changeYearMonthAndClampDate = exports.changeYearMonthAndClampDate = function changeYearMonthAndClampDate(date, year, month) {
267
+ // clamp date to the number of days in `year`, `month`
268
+ // eg: (2010-1-31, 2010, 2) => 2010-2-28
269
+ var monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
270
+ return modifyDate(date, year, month, monthDate);
271
+ };
272
+
273
+ var prevMonth = exports.prevMonth = function prevMonth(date) {
274
+ var year = date.getFullYear();
275
+ var month = date.getMonth();
276
+ return month === 0 ? changeYearMonthAndClampDate(date, year - 1, 11) : changeYearMonthAndClampDate(date, year, month - 1);
277
+ };
278
+
279
+ var nextMonth = exports.nextMonth = function nextMonth(date) {
280
+ var year = date.getFullYear();
281
+ var month = date.getMonth();
282
+ return month === 11 ? changeYearMonthAndClampDate(date, year + 1, 0) : changeYearMonthAndClampDate(date, year, month + 1);
283
+ };
284
+
285
+ var prevYear = exports.prevYear = function prevYear(date) {
286
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
287
+
288
+ var year = date.getFullYear();
289
+ var month = date.getMonth();
290
+ return changeYearMonthAndClampDate(date, year - amount, month);
291
+ };
292
+
293
+ var nextYear = exports.nextYear = function nextYear(date) {
294
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
295
+
296
+ var year = date.getFullYear();
297
+ var month = date.getMonth();
298
+ return changeYearMonthAndClampDate(date, year + amount, month);
299
+ };
300
+
301
+ var extractDateFormat = exports.extractDateFormat = function extractDateFormat(format) {
302
+ return format.replace(/\W?m{1,2}|\W?ZZ/g, '').replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '').trim();
303
+ };
304
+
305
+ var extractTimeFormat = exports.extractTimeFormat = function extractTimeFormat(format) {
306
+ return format.replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '').trim();
307
+ };
308
+
309
+ var validateRangeInOneMonth = exports.validateRangeInOneMonth = function validateRangeInOneMonth(start, end) {
310
+ return start.getMonth() === end.getMonth() && start.getFullYear() === end.getFullYear();
311
+ };