vueless 0.0.164 → 0.0.165

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "0.0.164",
3
+ "version": "0.0.165",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless Component Framework.",
6
6
  "homepage": "https://vueless.com",
@@ -62,7 +62,7 @@ const props = defineProps({
62
62
 
63
63
  dateFormat: {
64
64
  type: String,
65
- required: true,
65
+ default: undefined,
66
66
  },
67
67
 
68
68
  range: {
@@ -138,10 +138,10 @@ export default /*tw*/ {
138
138
  okLabel: "Ok",
139
139
  },
140
140
  defaultVariants: {
141
- dateFormat: "Y-m-d",
142
141
  userFormat: "F j, Y",
143
142
  range: false,
144
143
  timepicker: false,
144
+ dateFormat: undefined,
145
145
  maxDate: undefined,
146
146
  minDate: undefined,
147
147
  },
@@ -9,9 +9,7 @@ export default {
9
9
  id: "3165",
10
10
  title: "Form Inputs & Controls / Calendar",
11
11
  component: UCalendar,
12
- args: {
13
- label: "Label",
14
- },
12
+ args: {},
15
13
  argTypes: {
16
14
  ...getArgTypes(UCalendar.name),
17
15
  },
@@ -31,32 +29,45 @@ const DefaultTemplate = (args) => ({
31
29
 
32
30
  return { args, slots };
33
31
  },
32
+ data() {
33
+ return {
34
+ value: this.args.value,
35
+ };
36
+ },
34
37
  template: `
35
- <UCalendar v-bind="args" v-model="args.value">
38
+ <UCalendar v-bind="args" v-model="value">
36
39
  <template v-for="(slot, index) of slots" :key="index" v-slot:[slot]>
37
40
  <template v-if="args[slot]">{{ args[slot] }}</template>
38
41
  </template>
39
42
  </UCalendar>
43
+
44
+ <div class="mt-4">
45
+ {{ value }}
46
+ </div>
40
47
  `,
41
48
  });
42
49
 
43
50
  export const Default = DefaultTemplate.bind({});
44
- Default.args = {};
51
+ Default.args = { value: new Date() };
45
52
 
46
53
  export const Range = DefaultTemplate.bind({});
47
54
  Range.args = {
48
55
  range: true,
49
56
  value: {
50
- from: 1651813634,
51
- to: 1654492034,
57
+ from: new Date(2022, 2),
58
+ to: new Date(2024, 2, 14, 12, 24, 14),
52
59
  },
53
60
  };
54
61
 
55
62
  export const Timepicker = DefaultTemplate.bind({});
56
- Timepicker.args = { value: 1645653600, timepicker: true };
63
+ Timepicker.args = { value: new Date(2024, 2, 14, 12, 24, 14), timepicker: true };
57
64
 
58
65
  export const MinMax = DefaultTemplate.bind({});
59
- MinMax.args = { minDate: "2022-02-22", maxDate: "2022-02-26", value: 1645653600 };
66
+ MinMax.args = {
67
+ minDate: "2022-02-22",
68
+ maxDate: new Date(2022, 2, 26),
69
+ value: new Date(2022, 2, 24),
70
+ };
60
71
 
61
72
  export const DateFormat = DefaultTemplate.bind({});
62
- DateFormat.args = { dateFormat: "d.m.Y", userFormat: "d.m.Y", value: 1645653600 };
73
+ DateFormat.args = { dateFormat: "d.m.Y", userFormat: "d.m.Y", value: "28.06.2024" };
@@ -167,7 +167,6 @@ import {
167
167
  } from "./services/calendar.service";
168
168
 
169
169
  import {
170
- getUnixTimestampFromDate,
171
170
  getDateWithoutTime,
172
171
  addMonths,
173
172
  addDays,
@@ -202,10 +201,10 @@ defineOptions({ name: "UCalendar" });
202
201
 
203
202
  const props = defineProps({
204
203
  /**
205
- * Calendar value (timestamp).
204
+ * Calendar value in JS Date Object or String formatted in provided props.dateFormat.
206
205
  */
207
206
  modelValue: {
208
- type: [Number, Object],
207
+ type: [String, Object],
209
208
  default: null,
210
209
  },
211
210
 
@@ -251,7 +250,7 @@ const props = defineProps({
251
250
  },
252
251
 
253
252
  /**
254
- * Min date in format date string or Date.
253
+ * Min date in JS Date Object or Date String formatted in provided props.dateFormat.
255
254
  */
256
255
  minDate: {
257
256
  type: [Date, String],
@@ -259,7 +258,7 @@ const props = defineProps({
259
258
  },
260
259
 
261
260
  /**
262
- * Max date in format date string or Date.
261
+ * Max date in JS Date Object or Date String formatted in provided props.dateFormat.
263
262
  */
264
263
  maxDate: {
265
264
  type: [Date, String],
@@ -402,7 +401,7 @@ const isTimepickerEnabled = computed(() => {
402
401
  const isModelRangeType = computed(() => {
403
402
  return (
404
403
  props.modelValue !== null &&
405
- !isNumeric(props.modelValue) &&
404
+ !(props.modelValue instanceof Date) &&
406
405
  typeof props.modelValue === "object"
407
406
  );
408
407
  });
@@ -414,10 +413,15 @@ const localValue = computed({
414
413
 
415
414
  const to = isModelRangeType.value ? props.modelValue.to : null;
416
415
 
417
- return { from, to };
416
+ return {
417
+ from: parseDate(from || null, props.dateFormat, locale.value),
418
+ to: parseDate(to || null, props.dateFormat, locale.value),
419
+ };
418
420
  }
419
421
 
420
- return isModelRangeType.value ? props.modelValue.from : props.modelValue;
422
+ return isModelRangeType.value
423
+ ? parseDate(props.modelValue.from || null, props.dateFormat, locale.value)
424
+ : parseDate(props.modelValue || null, props.dateFormat, locale.value);
421
425
  },
422
426
  set(value) {
423
427
  value = getCurrentValueType(value);
@@ -433,9 +437,6 @@ const localValue = computed({
433
437
  parsedDate.setMinutes(Number(minutesRef.value.value));
434
438
  }
435
439
 
436
- const timestamp = parsedDate ? getUnixTimestampFromDate(parsedDate) : null;
437
- const timestampTo = parsedDateTo ? getUnixTimestampFromDate(parsedDateTo) : null;
438
-
439
440
  const isOutOfRange = dateIsOutOfRange(
440
441
  parsedDate || new Date(),
441
442
  props.minDate,
@@ -448,7 +449,15 @@ const localValue = computed({
448
449
  return;
449
450
  }
450
451
 
451
- emit("update:modelValue", props.range ? { from: timestamp, to: timestampTo } : timestamp);
452
+ const newDate = props.dateFormat
453
+ ? formatDate(parsedDate || null, props.dateFormat, locale.value)
454
+ : parsedDate;
455
+
456
+ const newDateTo = props.dateFormat
457
+ ? formatDate(parsedDateTo || null, props.dateFormat, locale.value)
458
+ : parsedDateTo;
459
+
460
+ emit("update:modelValue", props.range ? { from: newDate, to: newDateTo } : newDate);
452
461
 
453
462
  if (parsedDate === null && isTimepickerEnabled.value) {
454
463
  const currentDate = new Date();
@@ -568,9 +577,7 @@ function onInputDate(newDate) {
568
577
 
569
578
  if (props.range) {
570
579
  const isFullReset =
571
- localValue.value.to ||
572
- !localValue.value.from ||
573
- getUnixTimestampFromDate(date) <= localValue.value.from;
580
+ localValue.value.to || !localValue.value.from || date <= localValue.value.from;
574
581
 
575
582
  localValue.value = isFullReset
576
583
  ? { from: date, to: null }
@@ -15,7 +15,7 @@ export function getInitialActiveDate(localValue) {
15
15
  return new Date();
16
16
  }
17
17
 
18
- export function formatDate(dateObj, format, locale) {
18
+ export function formatDate(dateObj, format = "Y-m-d H:i:S", locale) {
19
19
  if (dateObj === null) {
20
20
  return "";
21
21
  }
@@ -85,7 +85,7 @@ export function parseDate(date, format = "Y-m-d H:i:S", locale) {
85
85
  return parsedDate;
86
86
  }
87
87
 
88
- export function parseStringDate(dateString, format, localeTokenRegex, locale) {
88
+ export function parseStringDate(dateString, format = "Y-m-d H:i:S", localeTokenRegex, locale) {
89
89
  const isWithinTimezone = /Z$/.test(dateString) || /GMT$/.test(dateString);
90
90
 
91
91
  if (isWithinTimezone) {
@@ -163,18 +163,16 @@ export function dateIsOutOfRange(date, min, max, locale, dateFormat = null) {
163
163
 
164
164
  const maxDate = typeof max === "string" ? parseDate(max, dateFormat, locale) : max;
165
165
 
166
- const time = date.getTime();
167
-
168
166
  if (minDate && maxDate) {
169
- return time < minDate.getTime() || time > maxDate.getTime();
167
+ return date < minDate || date > maxDate;
170
168
  }
171
169
 
172
170
  if (minDate) {
173
- return time < minDate.getTime();
171
+ return date < minDate;
174
172
  }
175
173
 
176
174
  if (maxDate) {
177
- return time > maxDate.getTime();
175
+ return date > maxDate;
178
176
  }
179
177
 
180
178
  return false;
@@ -1,9 +1,4 @@
1
- import {
2
- LOCALE_TYPE,
3
- DAYS_IN_WEEK,
4
- SECONDS_IN_MINUTES,
5
- MILLISECONDS_IN_MINUTE,
6
- } from "../constants";
1
+ import { LOCALE_TYPE, DAYS_IN_WEEK, SECONDS_IN_MINUTES } from "../constants";
7
2
 
8
3
  const daysMap = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
9
4
  const monthsMap = [
@@ -25,10 +20,6 @@ export function minutesToSeconds(minutes) {
25
20
  return Math.trunc(minutes * SECONDS_IN_MINUTES);
26
21
  }
27
22
 
28
- export function utcToGMT(date) {
29
- return new Date(date.getTime() + date.getTimezoneOffset() * MILLISECONDS_IN_MINUTE);
30
- }
31
-
32
23
  export function getDaysInMonth(date) {
33
24
  return new Date(new Date(date.valueOf()).setDate(0)).getDate();
34
25
  }
@@ -152,19 +143,6 @@ export function getStartOfDay(date) {
152
143
  return localDate;
153
144
  }
154
145
 
155
- export function gmtToUTC(date) {
156
- return new Date(
157
- Date.UTC(
158
- date.getUTCFullYear(),
159
- date.getUTCMonth(),
160
- date.getUTCDate(),
161
- date.getUTCHours(),
162
- date.getUTCMinutes(),
163
- date.getUTCSeconds(),
164
- ),
165
- );
166
- }
167
-
168
146
  export function getSortedLocale(locale, type) {
169
147
  const targetMap = type === LOCALE_TYPE.month ? monthsMap : daysMap;
170
148
 
@@ -109,13 +109,13 @@ export default /*tw*/ {
109
109
  okLabel: "Ok",
110
110
  },
111
111
  defaultVariants: {
112
- dateFormat: "Y-m-d",
113
112
  userFormat: "F j, Y",
114
113
  size: "md",
115
114
  openDirectionX: "auto",
116
115
  openDirectionY: "auto",
117
116
  timepicker: false,
118
117
  disabled: false,
118
+ dateFormat: undefined,
119
119
  maxDate: undefined,
120
120
  minDate: undefined,
121
121
  },
@@ -33,12 +33,21 @@ const DefaultTemplate = (args) => ({
33
33
 
34
34
  return { args, slots };
35
35
  },
36
+ data() {
37
+ return {
38
+ value: this.args.value,
39
+ };
40
+ },
36
41
  template: `
37
- <UDatePicker v-bind="args" v-model="args.date">
42
+ <UDatePicker v-bind="args" v-model="value">
38
43
  <template v-for="(slot, index) of slots" :key="index" v-slot:[slot]>
39
44
  <template v-if="args[slot]">{{ args[slot] }}</template>
40
45
  </template>
41
46
  </UDatePicker>
47
+
48
+ <div class="mt-4">
49
+ {{ value }}
50
+ </div>
42
51
  `,
43
52
  });
44
53
 
@@ -64,12 +73,11 @@ const SizesTemplate = (args, { argTypes } = {}) => ({
64
73
  `,
65
74
  });
66
75
 
67
- const OpenDirectionTemplate = (args, { argTypes } = {}) => ({
76
+ const OpenDirectionTemplate = (args) => ({
68
77
  components: { UDatePicker, URow },
69
78
  setup() {
70
79
  return {
71
80
  args,
72
- directions: argTypes.openDirection.options,
73
81
  };
74
82
  },
75
83
  template: `
@@ -117,7 +125,7 @@ const SlotTemplate = (args) => ({
117
125
  });
118
126
 
119
127
  export const Default = DefaultTemplate.bind({});
120
- Default.args = { date: 1645653600 };
128
+ Default.args = { value: new Date() };
121
129
 
122
130
  export const sizes = SizesTemplate.bind({});
123
131
  sizes.args = { label: "" };
@@ -138,13 +146,17 @@ export const placeholder = DefaultTemplate.bind({});
138
146
  placeholder.args = { placeholder: "some placeholder" };
139
147
 
140
148
  export const DateFormat = DefaultTemplate.bind({});
141
- DateFormat.args = { dateFormat: "d.m.Y", userFormat: "d.m.Y", date: 1645653600 };
149
+ DateFormat.args = { dateFormat: "d.m.Y", userFormat: "d.m.Y", value: "28.06.2024" };
142
150
 
143
151
  export const Timepicker = DefaultTemplate.bind({});
144
- Timepicker.args = { timepicker: true, date: 1645653600 };
152
+ Timepicker.args = { timepicker: true, value: new Date(2024, 2, 14, 12, 24, 14) };
145
153
 
146
154
  export const MinMax = DefaultTemplate.bind({});
147
- MinMax.args = { minDate: "2022-02-22", maxDate: "2022-02-26", date: 1645653600 };
155
+ MinMax.args = {
156
+ minDate: new Date(2022, 2, 22),
157
+ maxDate: new Date(2022, 2, 26),
158
+ value: new Date(2022, 2, 24),
159
+ };
148
160
 
149
161
  export const slotIcon = SlotTemplate.bind({});
150
162
  slotIcon.args = {
@@ -61,11 +61,7 @@ import { VIEW } from "../ui.form-calendar/constants";
61
61
 
62
62
  import UIService, { getRandomId } from "../service.ui";
63
63
 
64
- import {
65
- addDays,
66
- isSameDay,
67
- getDateFromUnixTimestamp,
68
- } from "../ui.form-calendar/services/date.service";
64
+ import { addDays, isSameDay } from "../ui.form-calendar/services/date.service";
69
65
 
70
66
  import useAttrs from "./composables/attrs.composable";
71
67
  import { useLocale } from "../composable.locale";
@@ -95,10 +91,10 @@ const props = defineProps({
95
91
  },
96
92
 
97
93
  /**
98
- * Datepicker value (timestamp).
94
+ * Datepicker value in JS Date Object or String formatted in provided props.dateFormat.
99
95
  */
100
96
  modelValue: {
101
- type: Number,
97
+ type: [Object, String],
102
98
  default: null,
103
99
  },
104
100
 
@@ -301,7 +297,7 @@ function onBlur(event) {
301
297
  }
302
298
 
303
299
  function formatUserDate(data) {
304
- if (props.dateFormat !== STANDARD_USER_FORMAT) return data;
300
+ if (props.userFormat !== STANDARD_USER_FORMAT) return data;
305
301
 
306
302
  const i18nGlobal = tm(UDatePicker);
307
303
  const currentLocale = computed(() => merge(defaultConfig.i18n, i18nGlobal, props.config.i18n));
@@ -310,12 +306,11 @@ function formatUserDate(data) {
310
306
  const formattedDate = data.charAt(0).toUpperCase() + data.toLowerCase().slice(1);
311
307
  const formattedDateWithoutDay = formattedDate.split(",").slice(1).join("").trim();
312
308
 
313
- const selectedDate = getDateFromUnixTimestamp(localValue.value);
314
309
  const today = new Date();
315
310
 
316
- const isToday = isSameDay(today, selectedDate);
317
- const isYesterday = isSameDay(addDays(today, -1), selectedDate);
318
- const isTomorrow = isSameDay(addDays(today, 1), selectedDate);
311
+ const isToday = isSameDay(today, localValue.value);
312
+ const isYesterday = isSameDay(addDays(today, -1), localValue.value);
313
+ const isTomorrow = isSameDay(addDays(today, 1), localValue.value);
319
314
 
320
315
  if (isToday) {
321
316
  prefix = currentLocale.value.today;
@@ -200,7 +200,7 @@ export default /*tw*/ {
200
200
  openDirectionY: "auto",
201
201
  timepicker: false,
202
202
  disabled: false,
203
- dateFormat: "d.m.Y",
203
+ dateFormat: undefined,
204
204
  maxDate: undefined,
205
205
  minDate: undefined,
206
206
  },
@@ -14,8 +14,8 @@ export default {
14
14
  component: UDatePickerRange,
15
15
  args: {
16
16
  value: {
17
- from: 1651813634,
18
- to: 1654492034,
17
+ from: new Date(2022, 1, 14),
18
+ to: new Date(2022, 2, 20),
19
19
  },
20
20
  },
21
21
  argTypes: {
@@ -37,12 +37,21 @@ const DefaultTemplate = (args) => ({
37
37
 
38
38
  return { args, slots };
39
39
  },
40
+ data() {
41
+ return {
42
+ value: this.args.value,
43
+ };
44
+ },
40
45
  template: `
41
- <UDatePickerRange v-bind="args" v-model="args.value">
46
+ <UDatePickerRange v-bind="args" v-model="value">
42
47
  <template v-for="(slot, index) of slots" :key="index" v-slot:[slot]>
43
48
  <template v-if="args[slot]">{{ args[slot] }}</template>
44
49
  </template>
45
50
  </UDatePickerRange>
51
+
52
+ <div class="mt-4">
53
+ {{ value }}
54
+ </div>
46
55
  `,
47
56
  });
48
57
 
@@ -142,9 +151,16 @@ error.args = { variant: "input", error: "some error" };
142
151
 
143
152
  export const MinMax = DefaultTemplate.bind({});
144
153
  MinMax.args = {
145
- minDate: "22.02.2022",
146
- maxDate: "26.02.2022",
147
- value: { from: 1645653600, to: null },
154
+ minDate: new Date(2022, 2, 22),
155
+ maxDate: new Date(2022, 2, 26),
156
+ value: { from: new Date(2022, 2, 24), to: null },
157
+ };
158
+
159
+ export const DateFormat = DefaultTemplate.bind({});
160
+ DateFormat.args = {
161
+ dateFormat: "d.m.Y",
162
+ userFormat: "d.m.Y",
163
+ value: { from: "28.06.2024", to: "30.06.2024" },
148
164
  };
149
165
 
150
166
  export const customRangeButton = DefaultTemplate.bind({});
@@ -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.165",
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",