vueless 0.0.164 → 0.0.166

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.
@@ -199,13 +199,9 @@ import UIService, { getRandomId } from "../service.ui";
199
199
 
200
200
  import {
201
201
  addDays,
202
- gmtToUTC,
203
- getUnixTimestampFromDate,
204
202
  addMonths,
205
203
  addYears,
206
- getDateFromUnixTimestamp,
207
204
  getSortedLocale,
208
- utcToGMT,
209
205
  getEndOfMonth,
210
206
  getEndOfQuarter,
211
207
  getEndOfWeek,
@@ -251,7 +247,7 @@ defineOptions({ name: "UDatePickerRange", inheritAttrs: false });
251
247
 
252
248
  const props = defineProps({
253
249
  /**
254
- * Dater picker range value as object with from and to keys (timestamp).
250
+ * Datepicker value in JS Date Objects or Strings formatted in provided props.dateFormat.
255
251
  */
256
252
  modelValue: {
257
253
  type: Object,
@@ -267,7 +263,7 @@ const props = defineProps({
267
263
  customRangeButton: {
268
264
  type: Object,
269
265
  default: () => ({
270
- range: { from: 0, to: 0 },
266
+ range: { from: null, to: null },
271
267
  label: "",
272
268
  description: "",
273
269
  }),
@@ -444,9 +440,32 @@ const {
444
440
  } = useAttrs(props, { isShownMenu, isTop, isRight });
445
441
  const { tm } = useLocale();
446
442
 
443
+ const i18nGlobal = tm(UDatePickerRange);
444
+
445
+ const currentLocale = computed(() => merge(defaultConfig.i18n, i18nGlobal, props.config.i18n));
446
+
447
+ const locale = computed(() => {
448
+ const { months, weekdays } = currentLocale.value;
449
+
450
+ // formatted locale
451
+ return {
452
+ ...currentLocale.value,
453
+ months: {
454
+ shorthand: getSortedLocale(months.shorthand, LOCALE_TYPE.month),
455
+ longhand: getSortedLocale(months.longhand, LOCALE_TYPE.month),
456
+ },
457
+ weekdays: {
458
+ shorthand: getSortedLocale(weekdays.shorthand, LOCALE_TYPE.day),
459
+ longhand: getSortedLocale(weekdays.longhand, LOCALE_TYPE.day),
460
+ },
461
+ };
462
+ });
463
+
447
464
  const calendarValue = ref(props.modelValue);
448
465
  const activeDate = ref(
449
- props.modelValue.from !== null ? getDateFromUnixTimestamp(props.modelValue.from) : new Date(),
466
+ props.modelValue.from !== null
467
+ ? parseDate(props.modelValue.from, props.dateFormat, locale.value)
468
+ : new Date(),
450
469
  );
451
470
  const period = ref(PERIOD.ownRange);
452
471
  const rangeStart = ref("");
@@ -457,39 +476,39 @@ const isHoverEvent = ref(false);
457
476
  const periodDateList = ref(null);
458
477
 
459
478
  const { isMobileBreakpoint } = useBreakpoint();
460
- const i18nGlobal = tm(UDatePickerRange);
461
479
 
462
480
  const localValue = computed({
463
- get: () => props.modelValue,
481
+ get: () => {
482
+ return {
483
+ from: parseDate(props.modelValue.from || null, props.dateFormat, locale.value),
484
+ to: parseDate(props.modelValue.to || null, props.dateFormat, locale.value),
485
+ };
486
+ },
464
487
  set: (value) => {
465
- if (value.from && value.to) {
488
+ if (value.from && value.to && !props.dateFormat) {
466
489
  emit("update:modelValue", value);
467
490
  }
468
491
 
469
- activeDate.value = getDateFromUnixTimestamp(value.from || new Date());
470
- },
471
- });
492
+ const parsedDateFrom = parseDate(value.from || null, props.dateFormat, locale.value);
493
+ const parsedDateTo = parseDate(value.to || null, props.dateFormat, locale.value);
472
494
 
473
- const rangeInputName = computed(() => `rangeInput-${props.id}`);
474
- const currentLocale = computed(() => merge(defaultConfig.i18n, i18nGlobal, props.config.i18n));
495
+ if (value.from && value.to && props.dateFormat) {
496
+ const newValue = {
497
+ from: formatDate(parsedDateFrom, props.dateFormat, locale.value),
498
+ to: formatDate(parsedDateTo, props.dateFormat, locale.value),
499
+ };
475
500
 
476
- const locale = computed(() => {
477
- const { months, weekdays } = currentLocale.value;
501
+ emit("update:modelValue", newValue);
502
+ }
478
503
 
479
- // formatted locale
480
- return {
481
- ...currentLocale.value,
482
- months: {
483
- shorthand: getSortedLocale(months.shorthand, LOCALE_TYPE.month),
484
- longhand: getSortedLocale(months.longhand, LOCALE_TYPE.month),
485
- },
486
- weekdays: {
487
- shorthand: getSortedLocale(weekdays.shorthand, LOCALE_TYPE.day),
488
- longhand: getSortedLocale(weekdays.longhand, LOCALE_TYPE.day),
489
- },
490
- };
504
+ activeDate.value = props.dateFormat
505
+ ? formatDate(parsedDateFrom || new Date(), props.dateFormat, locale.value)
506
+ : value.from || new Date();
507
+ },
491
508
  });
492
509
 
510
+ const rangeInputName = computed(() => `rangeInput-${props.id}`);
511
+
493
512
  const userFormatLocale = computed(() => {
494
513
  const { months, weekdays } = currentLocale.value;
495
514
 
@@ -575,8 +594,8 @@ const userFormatDate = computed(() => {
575
594
 
576
595
  const isDefaultTitle = isPeriod.value.week || isPeriod.value.custom || isPeriod.value.ownRange;
577
596
 
578
- const from = getDateFromUnixTimestamp(localValue.value.from);
579
- const to = localValue.value.to !== null ? getDateFromUnixTimestamp(localValue.value.to) : null;
597
+ const from = localValue.value.from;
598
+ const to = localValue.value.to !== null ? localValue.value.to : null;
580
599
 
581
600
  if (isDefaultTitle) {
582
601
  let startMonthName = userFormatLocale.value.months.longhand[from.getMonth()];
@@ -637,14 +656,8 @@ watch(
637
656
  calendarValue,
638
657
  () => {
639
658
  localValue.value = {
640
- from:
641
- calendarValue.value.from === null
642
- ? calendarValue.value.from
643
- : getUnixTimestampFromDate(gmtToUTC(getDateFromUnixTimestamp(calendarValue.value.from))),
644
- to:
645
- calendarValue.value.to === null
646
- ? calendarValue.value.to
647
- : getUnixTimestampFromDate(gmtToUTC(getDateFromUnixTimestamp(calendarValue.value.to))),
659
+ from: calendarValue.value.from,
660
+ to: calendarValue.value.to,
648
661
  };
649
662
 
650
663
  nextTick(() => menuRef.value?.focus());
@@ -655,21 +668,22 @@ watch(
655
668
  watch(
656
669
  () => props.modelValue,
657
670
  () => {
658
- if (props.modelValue.to !== calendarValue.value.to) {
671
+ if (String(props.modelValue.to) !== String(calendarValue.value.to)) {
659
672
  calendarValue.value.to = props.modelValue.to;
660
673
  }
661
674
 
662
- if (props.modelValue.from !== calendarValue.value.from) {
675
+ if (String(props.modelValue.from) !== String(calendarValue.value.from)) {
663
676
  calendarValue.value.from = props.modelValue.from;
664
677
  }
665
678
 
679
+ const parsedDateFrom = parseDate(props.modelValue.from, props.dateFormat, locale.value);
680
+ const parsedDateTo = parseDate(props.modelValue.to, props.dateFormat, locale.value);
681
+
666
682
  rangeStart.value = props.modelValue.from
667
- ? formatDate(getDateFromUnixTimestamp(props.modelValue.from), props.dateFormat, locale.value)
683
+ ? formatDate(parsedDateFrom, "d.m.Y", locale.value)
668
684
  : "";
669
685
 
670
- rangeEnd.value = props.modelValue.to
671
- ? formatDate(getDateFromUnixTimestamp(props.modelValue.to), props.dateFormat, locale.value)
672
- : "";
686
+ rangeEnd.value = props.modelValue.to ? formatDate(parsedDateTo, "d.m.Y", locale.value) : "";
673
687
 
674
688
  inputRangeStartError.value = "";
675
689
  inputRangeEndError.value = "";
@@ -678,13 +692,11 @@ watch(
678
692
  );
679
693
 
680
694
  watch(period, () => {
681
- activeDate.value =
682
- localValue.value.from !== null ? getDateFromUnixTimestamp(localValue.value.from) : new Date();
695
+ activeDate.value = localValue.value.from !== null ? localValue.value.from : new Date();
683
696
  });
684
697
 
685
698
  function onClickPeriodButton(periodName) {
686
- const localDate =
687
- localValue.value.from !== null ? getDateFromUnixTimestamp(localValue.value.from) : new Date();
699
+ const localDate = localValue.value.from !== null ? localValue.value.from : new Date();
688
700
 
689
701
  if (periodName === PERIOD.week) {
690
702
  periodDateList.value = getWeekDateList(localDate, locale.value.months.shorthand);
@@ -736,37 +748,21 @@ function onClickCustomRangeButton() {
736
748
  }
737
749
 
738
750
  function selectCustomRange() {
739
- const from =
740
- typeof props.customRangeButton.range.from === "number"
741
- ? getDateFromUnixTimestamp(props.customRangeButton.range.from)
742
- : props.customRangeButton.range.from;
743
-
744
- const to =
745
- typeof props.customRangeButton.range.to === "number"
746
- ? getDateFromUnixTimestamp(props.customRangeButton.range.to)
747
- : props.customRangeButton.range.to;
748
-
749
751
  localValue.value = {
750
- from: getUnixTimestampFromDate(gmtToUTC(from)),
751
- to: getUnixTimestampFromDate(gmtToUTC(to)),
752
+ from: props.customRangeButton.range.from,
753
+ to: props.customRangeButton.range.to,
752
754
  };
753
755
  }
754
756
 
755
757
  function isDatePeriodOutOfRange(datePeriod) {
756
758
  return (
757
759
  dateIsOutOfRange(
758
- getDateFromUnixTimestamp(datePeriod.startRange),
760
+ datePeriod.startRange,
759
761
  props.minDate,
760
762
  props.maxDate,
761
763
  locale.value,
762
764
  props.dateFormat,
763
- ) ||
764
- dateIsOutOfRange(
765
- getDateFromUnixTimestamp(datePeriod.endRange),
766
- props.minDate,
767
- props.maxDate,
768
- props.dateFormat,
769
- )
765
+ ) || dateIsOutOfRange(datePeriod.endRange, props.minDate, props.maxDate, props.dateFormat)
770
766
  );
771
767
  }
772
768
 
@@ -874,8 +870,7 @@ function onInputRangeInput(value, type) {
874
870
  inputRangeEndError.value = error;
875
871
  }
876
872
 
877
- const parsedValue = gmtToUTC(parseDate(value || new Date(), props.dateFormat, locale.value));
878
- const unixTimeValue = getUnixTimestampFromDate(parsedValue);
873
+ const parsedValue = parseDate(value || new Date(), props.dateFormat, locale.value);
879
874
  const isOutOfRange = dateIsOutOfRange(
880
875
  parsedValue,
881
876
  props.minDate,
@@ -883,25 +878,25 @@ function onInputRangeInput(value, type) {
883
878
  locale.value,
884
879
  props.dateFormat,
885
880
  );
886
- const isToLessThanFrom = unixTimeValue <= localValue.value.from;
881
+ const isToLessThanFrom = parsedValue <= localValue.value.from;
887
882
 
888
883
  if (type === INPUT_RANGE_TYPE.start && !error && !isOutOfRange) {
889
- localValue.value.from = value ? unixTimeValue : "";
884
+ localValue.value.from = value ? parsedValue : "";
890
885
  }
891
886
 
892
887
  if (type === INPUT_RANGE_TYPE.end && !error && !isOutOfRange && !isToLessThanFrom) {
893
- localValue.value.to = value ? unixTimeValue : "";
888
+ localValue.value.to = value ? parsedValue : "";
894
889
  }
895
890
  }
896
891
 
897
892
  setDefaultPeriodForButton();
898
893
 
899
894
  function setDefaultPeriodForButton() {
900
- const from = utcToGMT(getDateFromUnixTimestamp(props.modelValue.from || new Date()));
901
- const to = utcToGMT(getDateFromUnixTimestamp(props.modelValue.to || new Date()));
895
+ const from = props.modelValue.from || new Date();
896
+ const to = props.modelValue.to || new Date();
902
897
 
903
- const customFrom = utcToGMT(getDateFromUnixTimestamp(props.customRangeButton.range.from));
904
- const customTo = utcToGMT(getDateFromUnixTimestamp(props.customRangeButton.range.to));
898
+ const customFrom = props.customRangeButton.range.from || new Date();
899
+ const customTo = props.customRangeButton.range.to || new Date();
905
900
 
906
901
  const isWeekPeriod =
907
902
  String(from) === String(getStartOfWeek(from, { weekStartsOn: 1 })) &&
@@ -946,15 +941,15 @@ function onClickShiftRange(action) {
946
941
  const millisecondsPerDay =
947
942
  millisecondsPerSecond * secondsPerMinute * minutesPerHour * hoursPerDay;
948
943
 
949
- const from = getDateFromUnixTimestamp(localValue.value.from);
950
- const to = localValue.value.to ? getDateFromUnixTimestamp(localValue.value.to) : addDays(from, 1);
944
+ const from = localValue.value.from;
945
+ const to = localValue.value.to ? localValue.value.to : addDays(from, 1);
951
946
  const daysDifference = Math.ceil(Math.abs(getDatesDifference(from, to)) / millisecondsPerDay);
952
947
 
953
948
  if (action === "next") {
954
949
  if (isPeriod.value.ownRange) {
955
950
  const nextDate = {
956
- to: getUnixTimestampFromDate(addDays(to, daysDifference)),
957
- from: getUnixTimestampFromDate(addDays(from, daysDifference)),
951
+ to: addDays(to, daysDifference),
952
+ from: addDays(from, daysDifference),
958
953
  };
959
954
 
960
955
  if (isDatePeriodOutOfRange(nextDate)) return;
@@ -979,8 +974,8 @@ function onClickShiftRange(action) {
979
974
  } else {
980
975
  if (isPeriod.value.ownRange) {
981
976
  const previousDate = {
982
- to: getUnixTimestampFromDate(gmtToUTC(addDays(to, daysDifference * -1))),
983
- from: getUnixTimestampFromDate(gmtToUTC(addDays(from, daysDifference * -1))),
977
+ to: addDays(to, daysDifference * -1),
978
+ from: addDays(from, daysDifference * -1),
984
979
  };
985
980
 
986
981
  if (isDatePeriodOutOfRange(previousDate)) return;
@@ -2,9 +2,7 @@ import {
2
2
  getWeeksInMonth,
3
3
  getStartOfWeek,
4
4
  getEndOfWeek,
5
- gmtToUTC,
6
5
  addWeeks,
7
- getUnixTimestampFromDate,
8
6
  getEndOfMonth,
9
7
  getStartOfMonth,
10
8
  getEndOfQuarter,
@@ -27,8 +25,8 @@ export function getYearDateList(date) {
27
25
 
28
26
  years.push({
29
27
  title: currentYear,
30
- startRange: getUnixTimestampFromDate(gmtToUTC(getStartOfYear(new Date(currentYear, month)))),
31
- endRange: getUnixTimestampFromDate(gmtToUTC(getEndOfYear(new Date(currentYear, month)))),
28
+ startRange: getStartOfYear(new Date(currentYear, month)),
29
+ endRange: getEndOfYear(new Date(currentYear, month)),
32
30
  });
33
31
  }
34
32
 
@@ -51,8 +49,8 @@ export function getQuartersDateList(date, quarterLocales = "") {
51
49
 
52
50
  quarters.push({
53
51
  title: `${currentQuarter} ${quarterLocales}`,
54
- startRange: getUnixTimestampFromDate(gmtToUTC(getStartOfQuarter(newQuarter))),
55
- endRange: getUnixTimestampFromDate(gmtToUTC(getEndOfQuarter(newQuarter))),
52
+ startRange: getStartOfQuarter(newQuarter),
53
+ endRange: getEndOfQuarter(newQuarter),
56
54
  });
57
55
  }
58
56
 
@@ -65,8 +63,8 @@ export function getMonthsDateList(date, monthLocales = []) {
65
63
  const months = monthLocales.map((item, index) => {
66
64
  return {
67
65
  title: item,
68
- startRange: getUnixTimestampFromDate(gmtToUTC(getStartOfMonth(new Date(year, index)))),
69
- endRange: getUnixTimestampFromDate(gmtToUTC(getEndOfMonth(new Date(year, index)))),
66
+ startRange: getStartOfMonth(new Date(year, index)),
67
+ endRange: getEndOfMonth(new Date(year, index)),
70
68
  };
71
69
  });
72
70
 
@@ -105,8 +103,8 @@ export function getWeekDateList(date, monthShortLocales = {}) {
105
103
 
106
104
  weeks.push({
107
105
  title,
108
- startRange: getUnixTimestampFromDate(gmtToUTC(startOfWeekDate)),
109
- endRange: getUnixTimestampFromDate(gmtToUTC(endOfWeekDate)),
106
+ startRange: startOfWeekDate,
107
+ endRange: endOfWeekDate,
110
108
  });
111
109
  }
112
110
 
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "framework": "vue",
3
3
  "name": "vueless",
4
- "version": "0.0.164",
4
+ "version": "0.0.166",
5
5
  "contributions": {
6
6
  "html": {
7
7
  "description-markup": "markdown",
@@ -53,11 +53,11 @@
53
53
  },
54
54
  {
55
55
  "name": "dateFormat",
56
- "required": true,
57
56
  "value": {
58
57
  "kind": "expression",
59
58
  "type": "string"
60
- }
59
+ },
60
+ "default": "undefined"
61
61
  },
62
62
  {
63
63
  "name": "range",
@@ -701,10 +701,10 @@
701
701
  "attributes": [
702
702
  {
703
703
  "name": "modelValue",
704
- "description": "Calendar value (timestamp).",
704
+ "description": "Calendar value in JS Date Object or String formatted in provided props.dateFormat.",
705
705
  "value": {
706
706
  "kind": "expression",
707
- "type": "number|object"
707
+ "type": "string|object"
708
708
  },
709
709
  "default": "null"
710
710
  },
@@ -741,8 +741,7 @@
741
741
  "value": {
742
742
  "kind": "expression",
743
743
  "type": "string"
744
- },
745
- "default": "Y-m-d"
744
+ }
746
745
  },
747
746
  {
748
747
  "name": "userFormat",
@@ -755,7 +754,7 @@
755
754
  },
756
755
  {
757
756
  "name": "minDate",
758
- "description": "Min date in format date string or Date.",
757
+ "description": "Min date in JS Date Object or Date String formatted in provided props.dateFormat.",
759
758
  "value": {
760
759
  "kind": "expression",
761
760
  "type": "date|string"
@@ -763,7 +762,7 @@
763
762
  },
764
763
  {
765
764
  "name": "maxDate",
766
- "description": "Max date in format date string or Date.",
765
+ "description": "Max date in JS Date Object or Date String formatted in provided props.dateFormat.",
767
766
  "value": {
768
767
  "kind": "expression",
769
768
  "type": "date|string"
@@ -1533,10 +1532,10 @@
1533
1532
  },
1534
1533
  {
1535
1534
  "name": "modelValue",
1536
- "description": "Datepicker value (timestamp).",
1535
+ "description": "Datepicker value in JS Date Object or String formatted in provided props.dateFormat.",
1537
1536
  "value": {
1538
1537
  "kind": "expression",
1539
- "type": "number"
1538
+ "type": "object|string"
1540
1539
  },
1541
1540
  "default": "null"
1542
1541
  },
@@ -1625,8 +1624,7 @@
1625
1624
  "value": {
1626
1625
  "kind": "expression",
1627
1626
  "type": "string"
1628
- },
1629
- "default": "Y-m-d"
1627
+ }
1630
1628
  },
1631
1629
  {
1632
1630
  "name": "userFormat",
@@ -1695,7 +1693,7 @@
1695
1693
  "attributes": [
1696
1694
  {
1697
1695
  "name": "modelValue",
1698
- "description": "Dater picker range value as object with from and to keys (timestamp).",
1696
+ "description": "Datepicker value in JS Date Objects or Strings formatted in provided props.dateFormat.",
1699
1697
  "value": {
1700
1698
  "kind": "expression",
1701
1699
  "type": "object"
@@ -1709,7 +1707,7 @@
1709
1707
  "kind": "expression",
1710
1708
  "type": "object"
1711
1709
  },
1712
- "default": "{\n range: { from: 0, to: 0 },\n label: \"\",\n description: \"\"\n}"
1710
+ "default": "{\n range: { from: null, to: null },\n label: \"\",\n description: \"\"\n}"
1713
1711
  },
1714
1712
  {
1715
1713
  "name": "openDirectionX",
@@ -1814,8 +1812,7 @@
1814
1812
  "value": {
1815
1813
  "kind": "expression",
1816
1814
  "type": "string"
1817
- },
1818
- "default": "d.m.Y"
1815
+ }
1819
1816
  },
1820
1817
  {
1821
1818
  "name": "id",
@@ -6552,7 +6549,7 @@
6552
6549
  },
6553
6550
  {
6554
6551
  "name": "dateDivider",
6555
- "description": "Show/hide date divider or set label for specific date.",
6552
+ "description": "Show date divider label.",
6556
6553
  "value": {
6557
6554
  "kind": "expression",
6558
6555
  "type": "array|boolean"
@@ -6650,19 +6647,20 @@
6650
6647
  ],
6651
6648
  "slots": [
6652
6649
  {
6653
- "name": "thead-actions",
6654
- "description": "Use it to add actions instead table head (it appears when you select rows in table)."
6650
+ "name": "header-actions",
6651
+ "description": "Use it to add action buttons instead of table row when some rows are selected."
6655
6652
  },
6656
6653
  {
6657
- "name": "`thead-${column.key}`",
6654
+ "name": "`header-${column.key}`",
6658
6655
  "description": "Use it to customise table column."
6659
6656
  },
6660
6657
  {
6661
- "name": "`thead-${column.key}-after`",
6658
+ "name": "`header-${column.key}-after`",
6662
6659
  "description": "Use it to add content after table column."
6663
6660
  },
6664
6661
  {
6665
- "name": "before-header-row"
6662
+ "name": "before-header",
6663
+ "description": "Use it to add something before header row."
6666
6664
  },
6667
6665
  {
6668
6666
  "name": "before-first-row",
@@ -6672,18 +6670,16 @@
6672
6670
  "name": "`cell-${key}`",
6673
6671
  "description": "Use it to customise table cell item (in whole column)."
6674
6672
  },
6675
- {
6676
- "name": "cell-other"
6677
- },
6678
6673
  {
6679
6674
  "name": "after-last-row",
6680
6675
  "description": "Use it to add something after last row."
6681
6676
  },
6682
6677
  {
6683
- "name": "empty-table-msg"
6678
+ "name": "empty-state",
6679
+ "description": "Use it to add custom empty state."
6684
6680
  },
6685
6681
  {
6686
- "name": "tfoot",
6682
+ "name": "footer",
6687
6683
  "description": "Use it to add something in table footer."
6688
6684
  }
6689
6685
  ],