utils.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var dayjs = require('dayjs');
  4. require('../../../utils/index.js');
  5. var shared = require('@vue/shared');
  6. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  7. var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
  8. const isValidRange = (range) => {
  9. if (!shared.isArray(range))
  10. return false;
  11. const [left, right] = range;
  12. return dayjs__default["default"].isDayjs(left) && dayjs__default["default"].isDayjs(right) && left.isSameOrBefore(right);
  13. };
  14. const getDefaultValue = (defaultValue, { lang, unit, unlinkPanels }) => {
  15. let start;
  16. if (shared.isArray(defaultValue)) {
  17. let [left, right] = defaultValue.map((d) => dayjs__default["default"](d).locale(lang));
  18. if (!unlinkPanels) {
  19. right = left.add(1, unit);
  20. }
  21. return [left, right];
  22. } else if (defaultValue) {
  23. start = dayjs__default["default"](defaultValue);
  24. } else {
  25. start = dayjs__default["default"]();
  26. }
  27. start = start.locale(lang);
  28. return [start, start.add(1, unit)];
  29. };
  30. const buildPickerTable = (dimension, rows, {
  31. columnIndexOffset,
  32. startDate,
  33. nextEndDate,
  34. now,
  35. unit,
  36. relativeDateGetter,
  37. setCellMetadata,
  38. setRowMetadata
  39. }) => {
  40. for (let rowIndex = 0; rowIndex < dimension.row; rowIndex++) {
  41. const row = rows[rowIndex];
  42. for (let columnIndex = 0; columnIndex < dimension.column; columnIndex++) {
  43. let cell = row[columnIndex + columnIndexOffset];
  44. if (!cell) {
  45. cell = {
  46. row: rowIndex,
  47. column: columnIndex,
  48. type: "normal",
  49. inRange: false,
  50. start: false,
  51. end: false
  52. };
  53. }
  54. const index = rowIndex * dimension.column + columnIndex;
  55. const nextStartDate = relativeDateGetter(index);
  56. cell.dayjs = nextStartDate;
  57. cell.date = nextStartDate.toDate();
  58. cell.timestamp = nextStartDate.valueOf();
  59. cell.type = "normal";
  60. cell.inRange = !!(startDate && nextStartDate.isSameOrAfter(startDate, unit) && nextEndDate && nextStartDate.isSameOrBefore(nextEndDate, unit)) || !!(startDate && nextStartDate.isSameOrBefore(startDate, unit) && nextEndDate && nextStartDate.isSameOrAfter(nextEndDate, unit));
  61. if (startDate == null ? void 0 : startDate.isSameOrAfter(nextEndDate)) {
  62. cell.start = !!nextEndDate && nextStartDate.isSame(nextEndDate, unit);
  63. cell.end = startDate && nextStartDate.isSame(startDate, unit);
  64. } else {
  65. cell.start = !!startDate && nextStartDate.isSame(startDate, unit);
  66. cell.end = !!nextEndDate && nextStartDate.isSame(nextEndDate, unit);
  67. }
  68. const isToday = nextStartDate.isSame(now, unit);
  69. if (isToday) {
  70. cell.type = "today";
  71. }
  72. setCellMetadata == null ? void 0 : setCellMetadata(cell, { rowIndex, columnIndex });
  73. row[columnIndex + columnIndexOffset] = cell;
  74. }
  75. setRowMetadata == null ? void 0 : setRowMetadata(row);
  76. }
  77. };
  78. exports.buildPickerTable = buildPickerTable;
  79. exports.getDefaultValue = getDefaultValue;
  80. exports.isValidRange = isValidRange;
  81. //# sourceMappingURL=utils.js.map