7170b68c0cd4de9233c34adef6db3dddb1a996a9917fe7cea6e5329af407dd3c0dd97a122f9562c5769d9406a0579ba0b9c9d2ab99e6c0f2d0179c5ba9c609 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var lodashUnified = require('lodash-unified');
  5. var index = require('../../../../hooks/use-locale/index.js');
  6. var utils = require('../utils.js');
  7. var shared = require('@vue/shared');
  8. var event = require('../../../../constants/event.js');
  9. const useCommonPicker = (props, emit) => {
  10. const { lang } = index.useLocale();
  11. const pickerVisible = vue.ref(false);
  12. const pickerActualVisible = vue.ref(false);
  13. const userInput = vue.ref(null);
  14. const valueIsEmpty = vue.computed(() => {
  15. const { modelValue } = props;
  16. return !modelValue || shared.isArray(modelValue) && !modelValue.filter(Boolean).length;
  17. });
  18. const emitInput = (input) => {
  19. if (!utils.valueEquals(props.modelValue, input)) {
  20. let formatted;
  21. if (shared.isArray(input)) {
  22. formatted = input.map((item) => utils.formatter(item, props.valueFormat, lang.value));
  23. } else if (input) {
  24. formatted = utils.formatter(input, props.valueFormat, lang.value);
  25. }
  26. const emitVal = input ? formatted : input;
  27. emit(event.UPDATE_MODEL_EVENT, emitVal, lang.value);
  28. }
  29. };
  30. const parsedValue = vue.computed(() => {
  31. var _a;
  32. let dayOrDays;
  33. if (valueIsEmpty.value) {
  34. if (pickerOptions.value.getDefaultValue) {
  35. dayOrDays = pickerOptions.value.getDefaultValue();
  36. }
  37. } else {
  38. if (shared.isArray(props.modelValue)) {
  39. dayOrDays = props.modelValue.map((d) => utils.parseDate(d, props.valueFormat, lang.value));
  40. } else {
  41. dayOrDays = utils.parseDate((_a = props.modelValue) != null ? _a : "", props.valueFormat, lang.value);
  42. }
  43. }
  44. if (pickerOptions.value.getRangeAvailableTime) {
  45. const availableResult = pickerOptions.value.getRangeAvailableTime(dayOrDays);
  46. if (!lodashUnified.isEqual(availableResult, dayOrDays)) {
  47. dayOrDays = availableResult;
  48. if (!valueIsEmpty.value) {
  49. emitInput(utils.dayOrDaysToDate(dayOrDays));
  50. }
  51. }
  52. }
  53. if (shared.isArray(dayOrDays) && dayOrDays.some((day) => !day)) {
  54. dayOrDays = [];
  55. }
  56. return dayOrDays;
  57. });
  58. const pickerOptions = vue.ref({});
  59. const onSetPickerOption = (e) => {
  60. pickerOptions.value[e[0]] = e[1];
  61. pickerOptions.value.panelReady = true;
  62. };
  63. const onCalendarChange = (e) => {
  64. emit("calendar-change", e);
  65. };
  66. const onPanelChange = (value, mode, view) => {
  67. emit("panel-change", value, mode, view);
  68. };
  69. const onPick = (date = "", visible = false) => {
  70. pickerVisible.value = visible;
  71. let result;
  72. if (shared.isArray(date)) {
  73. result = date.map((_) => _.toDate());
  74. } else {
  75. result = date ? date.toDate() : date;
  76. }
  77. userInput.value = null;
  78. emitInput(result);
  79. };
  80. return {
  81. parsedValue,
  82. pickerActualVisible,
  83. pickerOptions,
  84. pickerVisible,
  85. userInput,
  86. valueIsEmpty,
  87. emitInput,
  88. onCalendarChange,
  89. onPanelChange,
  90. onPick,
  91. onSetPickerOption
  92. };
  93. };
  94. exports.useCommonPicker = useCommonPicker;
  95. //# sourceMappingURL=use-common-picker.js.map