@weni/unnnic-system 3.11.1-alpha.1 → 3.11.1-alpha.4
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/CHANGELOG.md +32 -0
- package/dist/components/DatePicker/DatePicker.vue.d.ts +69 -249
- package/dist/components/DatePicker/DatePicker.vue.d.ts.map +1 -1
- package/dist/components/Drawer/Drawer.vue.d.ts.map +1 -1
- package/dist/components/InputDatePicker/InputDatePicker.vue.d.ts +47 -911
- package/dist/components/InputDatePicker/InputDatePicker.vue.d.ts.map +1 -1
- package/dist/components/Select/SelectItem.vue.d.ts +1 -1
- package/dist/components/SelectSmart/SelectSmart.vue.d.ts +1 -1
- package/dist/components/SelectSmart/SelectSmartOption.vue.d.ts +1 -1
- package/dist/components/Sidebar/SidebarItem.vue.d.ts +2 -2
- package/dist/components/ui/drawer/Drawer.vue.d.ts.map +1 -1
- package/dist/components/ui/drawer/DrawerClose.vue.d.ts.map +1 -1
- package/dist/components/ui/drawer/DrawerContent.vue.d.ts.map +1 -1
- package/dist/components/ui/drawer/DrawerDescription.vue.d.ts.map +1 -1
- package/dist/components/ui/drawer/DrawerFooter.vue.d.ts.map +1 -1
- package/dist/components/ui/drawer/DrawerHeader.vue.d.ts.map +1 -1
- package/dist/components/ui/drawer/DrawerOverlay.vue.d.ts.map +1 -1
- package/dist/components/ui/drawer/DrawerTitle.vue.d.ts.map +1 -1
- package/dist/components/ui/drawer/DrawerTrigger.vue.d.ts.map +1 -1
- package/dist/{es-1e5cce64.mjs → es-fc643bdb.mjs} +1 -1
- package/dist/{index-8d75623f.mjs → index-4601aaf4.mjs} +9050 -9107
- package/dist/{pt-br-defd03da.mjs → pt-br-0b82e6d2.mjs} +1 -1
- package/dist/style.css +1 -1
- package/dist/unnnic.mjs +1 -1
- package/dist/unnnic.umd.js +42 -42
- package/package.json +1 -1
- package/src/components/DatePicker/DatePicker.vue +628 -516
- package/src/components/DatePicker/__tests__/DatePicker.spec.js +227 -0
- package/src/components/Drawer/Drawer.vue +6 -2
- package/src/components/Drawer/__tests__/Drawer.spec.js +11 -15
- package/src/components/Drawer/__tests__/__snapshots__/Drawer.spec.js.snap +9 -9
- package/src/components/InputDatePicker/InputDatePicker.vue +149 -183
- package/src/components/InputDatePicker/__test__/InputDatePicker.spec.js +159 -0
- package/src/components/Tab/__test__/__snapshots__/Tab.spec.js.snap +1 -1
- package/src/components/ui/drawer/Drawer.vue +4 -0
- package/src/components/ui/drawer/DrawerClose.vue +4 -0
- package/src/components/ui/drawer/DrawerContent.vue +5 -1
- package/src/components/ui/drawer/DrawerDescription.vue +4 -0
- package/src/components/ui/drawer/DrawerFooter.vue +5 -1
- package/src/components/ui/drawer/DrawerHeader.vue +5 -1
- package/src/components/ui/drawer/DrawerOverlay.vue +5 -1
- package/src/components/ui/drawer/DrawerTitle.vue +5 -1
- package/src/components/ui/drawer/DrawerTrigger.vue +4 -0
- package/src/stories/DatePicker.stories.js +71 -0
- package/src/stories/InputDatePicker.stories.js +22 -0
- package/dist/components/index.d.ts +0 -25946
- package/dist/components/index.d.ts.map +0 -1
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div
|
|
2
|
+
<div
|
|
3
|
+
class="unnnic-date-picker"
|
|
4
|
+
data-testid="date-picker-root"
|
|
5
|
+
>
|
|
3
6
|
<template v-if="type === 'day'">
|
|
4
7
|
<template
|
|
5
8
|
v-for="(openMonth, index) in openMonths"
|
|
6
9
|
:key="openMonth"
|
|
7
10
|
>
|
|
8
|
-
<div
|
|
11
|
+
<div
|
|
12
|
+
class="month-container"
|
|
13
|
+
data-testid="date-picker-month-container"
|
|
14
|
+
>
|
|
9
15
|
<div :class="['header', `header--${size}`]">
|
|
10
16
|
<UnnnicButton
|
|
11
17
|
size="small"
|
|
@@ -13,6 +19,7 @@
|
|
|
13
19
|
:type="size === 'large' ? 'secondary' : 'tertiary'"
|
|
14
20
|
class="button-space"
|
|
15
21
|
:style="{ gridArea: `${index === 0 ? 'left' : 'right'}-button` }"
|
|
22
|
+
:data-testid="`date-picker-nav-${index === 0 ? 'left' : 'right'}`"
|
|
16
23
|
@click.stop="
|
|
17
24
|
referenceDate = addMonth(referenceDate, index === 0 ? -1 : 1)
|
|
18
25
|
"
|
|
@@ -48,6 +55,7 @@
|
|
|
48
55
|
left: date.properties.includes('left-highlighted'),
|
|
49
56
|
right: date.properties.includes('right-highlighted'),
|
|
50
57
|
}"
|
|
58
|
+
data-testid="date-picker-day"
|
|
51
59
|
@click="
|
|
52
60
|
date.properties.includes('inside month') &&
|
|
53
61
|
!date.properties.includes('out of range') &&
|
|
@@ -68,7 +76,10 @@
|
|
|
68
76
|
v-for="openMonth in [referenceDate]"
|
|
69
77
|
:key="openMonth"
|
|
70
78
|
>
|
|
71
|
-
<div
|
|
79
|
+
<div
|
|
80
|
+
class="month-container"
|
|
81
|
+
data-testid="date-picker-month-container"
|
|
82
|
+
>
|
|
72
83
|
<div :class="['header', `header--${size}`]">
|
|
73
84
|
<UnnnicButton
|
|
74
85
|
size="small"
|
|
@@ -76,6 +87,7 @@
|
|
|
76
87
|
:type="size === 'large' ? 'secondary' : 'tertiary'"
|
|
77
88
|
class="button-space"
|
|
78
89
|
:style="{ gridArea: 'left-button' }"
|
|
90
|
+
data-testid="date-picker-month-nav-left"
|
|
79
91
|
@click="referenceDate = addMonth(referenceDate, -12)"
|
|
80
92
|
/>
|
|
81
93
|
|
|
@@ -89,6 +101,7 @@
|
|
|
89
101
|
:type="size === 'large' ? 'secondary' : 'tertiary'"
|
|
90
102
|
class="button-space"
|
|
91
103
|
:style="{ gridArea: 'right-button' }"
|
|
104
|
+
data-testid="date-picker-month-nav-right"
|
|
92
105
|
@click="referenceDate = addMonth(referenceDate, 12)"
|
|
93
106
|
/>
|
|
94
107
|
</div>
|
|
@@ -106,11 +119,12 @@
|
|
|
106
119
|
left: date.properties.includes('left-highlighted'),
|
|
107
120
|
right: date.properties.includes('right-highlighted'),
|
|
108
121
|
}"
|
|
122
|
+
data-testid="date-picker-month-cell"
|
|
109
123
|
@click="
|
|
110
124
|
date.properties.includes('inside month') && selectDate(date)
|
|
111
125
|
"
|
|
112
126
|
>
|
|
113
|
-
{{ monthsLocale[getMonth(date)].substr(0, 3) }}
|
|
127
|
+
{{ monthsLocale[getMonth(date) - 1].substr(0, 3) }}
|
|
114
128
|
</div>
|
|
115
129
|
</div>
|
|
116
130
|
</div>
|
|
@@ -124,7 +138,10 @@
|
|
|
124
138
|
v-for="openMonth in [referenceDate]"
|
|
125
139
|
:key="openMonth"
|
|
126
140
|
>
|
|
127
|
-
<div
|
|
141
|
+
<div
|
|
142
|
+
class="month-container"
|
|
143
|
+
data-testid="date-picker-month-container"
|
|
144
|
+
>
|
|
128
145
|
<div :class="['header', `header--${size}`]">
|
|
129
146
|
<UnnnicButton
|
|
130
147
|
size="small"
|
|
@@ -132,6 +149,7 @@
|
|
|
132
149
|
:type="size === 'large' ? 'secondary' : 'tertiary'"
|
|
133
150
|
class="button-space"
|
|
134
151
|
:style="{ gridArea: 'left-button' }"
|
|
152
|
+
data-testid="date-picker-year-nav-left"
|
|
135
153
|
@click="referenceDate = addMonth(referenceDate, -12 * 12)"
|
|
136
154
|
/>
|
|
137
155
|
|
|
@@ -145,6 +163,7 @@
|
|
|
145
163
|
:type="size === 'large' ? 'secondary' : 'tertiary'"
|
|
146
164
|
class="button-space"
|
|
147
165
|
:style="{ gridArea: 'right-button' }"
|
|
166
|
+
data-testid="date-picker-year-nav-right"
|
|
148
167
|
@click="referenceDate = addMonth(referenceDate, 12 * 12)"
|
|
149
168
|
/>
|
|
150
169
|
</div>
|
|
@@ -162,6 +181,7 @@
|
|
|
162
181
|
left: date.properties.includes('left-highlighted'),
|
|
163
182
|
right: date.properties.includes('right-highlighted'),
|
|
164
183
|
}"
|
|
184
|
+
data-testid="date-picker-year-cell"
|
|
165
185
|
@click="
|
|
166
186
|
date.properties.includes('inside month') && selectDate(date)
|
|
167
187
|
"
|
|
@@ -178,6 +198,7 @@
|
|
|
178
198
|
<div
|
|
179
199
|
v-if="size !== 'small'"
|
|
180
200
|
class="options-container"
|
|
201
|
+
data-testid="date-picker-options"
|
|
181
202
|
>
|
|
182
203
|
<div class="options">
|
|
183
204
|
<div
|
|
@@ -190,6 +211,7 @@
|
|
|
190
211
|
selected: optionSelected === option.id,
|
|
191
212
|
},
|
|
192
213
|
]"
|
|
214
|
+
data-testid="date-picker-option"
|
|
193
215
|
@click="option.id === 'custom' ? null : autoSelect(option.id)"
|
|
194
216
|
>
|
|
195
217
|
{{ option.name }}
|
|
@@ -202,6 +224,7 @@
|
|
|
202
224
|
size="small"
|
|
203
225
|
:text="clearText"
|
|
204
226
|
type="tertiary"
|
|
227
|
+
data-testid="date-picker-clear"
|
|
205
228
|
@click="clear"
|
|
206
229
|
/>
|
|
207
230
|
|
|
@@ -209,6 +232,7 @@
|
|
|
209
232
|
size="small"
|
|
210
233
|
:text="filterText"
|
|
211
234
|
type="secondary"
|
|
235
|
+
data-testid="date-picker-submit"
|
|
212
236
|
@click="submit"
|
|
213
237
|
/>
|
|
214
238
|
</div>
|
|
@@ -216,7 +240,17 @@
|
|
|
216
240
|
</div>
|
|
217
241
|
</template>
|
|
218
242
|
|
|
219
|
-
<script>
|
|
243
|
+
<script setup lang="ts">
|
|
244
|
+
import {
|
|
245
|
+
computed,
|
|
246
|
+
getCurrentInstance,
|
|
247
|
+
nextTick,
|
|
248
|
+
onMounted,
|
|
249
|
+
ref,
|
|
250
|
+
watch,
|
|
251
|
+
} from 'vue';
|
|
252
|
+
import { get } from 'lodash';
|
|
253
|
+
|
|
220
254
|
import {
|
|
221
255
|
months as translationMonths,
|
|
222
256
|
days as translationDays,
|
|
@@ -224,621 +258,699 @@ import {
|
|
|
224
258
|
buttons as translationButtons,
|
|
225
259
|
} from './translations.js';
|
|
226
260
|
|
|
227
|
-
import
|
|
261
|
+
import i18n from '@/utils/plugins/i18n';
|
|
228
262
|
|
|
229
263
|
import UnnnicButton from '../Button/Button.vue';
|
|
230
264
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
265
|
+
defineOptions({
|
|
266
|
+
name: 'UnnnicDatePicker',
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
type PeriodOption = {
|
|
270
|
+
id: string;
|
|
271
|
+
name: string;
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
export interface DatePickerProps {
|
|
275
|
+
initialStartDate?: string;
|
|
276
|
+
initialEndDate?: string;
|
|
277
|
+
|
|
278
|
+
minDate?: string;
|
|
279
|
+
maxDate?: string;
|
|
280
|
+
|
|
281
|
+
periodBaseDate?: string;
|
|
282
|
+
|
|
283
|
+
equivalentOption?: string;
|
|
284
|
+
|
|
285
|
+
type?: 'day' | 'month' | 'year';
|
|
286
|
+
size?: 'small' | 'large';
|
|
287
|
+
|
|
288
|
+
clearLabel?: string;
|
|
289
|
+
actionLabel?: string;
|
|
290
|
+
|
|
291
|
+
months?: string[];
|
|
292
|
+
days?: string[];
|
|
293
|
+
options?: PeriodOption[];
|
|
294
|
+
|
|
295
|
+
disableClear?: boolean;
|
|
296
|
+
|
|
297
|
+
locale?: string;
|
|
298
|
+
translations?: Record<string, unknown>;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const props = withDefaults(defineProps<DatePickerProps>(), {
|
|
302
|
+
initialStartDate: '',
|
|
303
|
+
initialEndDate: '',
|
|
304
|
+
minDate: '',
|
|
305
|
+
maxDate: '',
|
|
306
|
+
periodBaseDate: '',
|
|
307
|
+
equivalentOption: '',
|
|
308
|
+
type: 'day',
|
|
309
|
+
size: 'large',
|
|
310
|
+
clearLabel: '',
|
|
311
|
+
actionLabel: '',
|
|
312
|
+
months: () => [],
|
|
313
|
+
days: () => [],
|
|
314
|
+
options: () => [],
|
|
315
|
+
disableClear: false,
|
|
316
|
+
locale: undefined,
|
|
317
|
+
translations: undefined,
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
const emit = defineEmits<{
|
|
321
|
+
(e: 'change', value: { startDate: string; endDate: string }): void;
|
|
322
|
+
(e: 'submit', value: { startDate: string; endDate: string }): void;
|
|
323
|
+
(e: 'update:equivalentOption', equivalentOption: string): void;
|
|
324
|
+
}>();
|
|
325
|
+
|
|
326
|
+
const today = new Date();
|
|
327
|
+
const referenceDate = ref<string>(
|
|
328
|
+
`${today.getMonth() + 1} 1 ${today.getFullYear()}`,
|
|
329
|
+
);
|
|
330
|
+
const startDate = ref<string>(
|
|
331
|
+
(props.initialStartDate || '').replace(/-/g, ' '),
|
|
332
|
+
);
|
|
333
|
+
const endDate = ref<string>((props.initialEndDate || '').replace(/-/g, ' '));
|
|
334
|
+
const optionSelected = ref<string>('');
|
|
335
|
+
|
|
336
|
+
const defaultTranslations = {
|
|
337
|
+
clean: {
|
|
338
|
+
'pt-br': 'Limpar',
|
|
339
|
+
en: 'Clean',
|
|
340
|
+
es: 'Limpiar',
|
|
234
341
|
},
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
initialEndDate: { type: String, default: '' },
|
|
240
|
-
|
|
241
|
-
minDate: { type: String, default: '' },
|
|
242
|
-
maxDate: { type: String, default: '' },
|
|
243
|
-
|
|
244
|
-
equivalentOption: { type: String, default: '' },
|
|
245
|
-
|
|
246
|
-
type: {
|
|
247
|
-
type: String,
|
|
248
|
-
default: 'day',
|
|
249
|
-
validator(type) {
|
|
250
|
-
return ['day', 'month', 'year'].includes(type);
|
|
251
|
-
},
|
|
252
|
-
},
|
|
253
|
-
|
|
254
|
-
size: {
|
|
255
|
-
type: String,
|
|
256
|
-
default: 'large',
|
|
257
|
-
validator(size) {
|
|
258
|
-
return ['small', 'large'].includes(size);
|
|
259
|
-
},
|
|
260
|
-
},
|
|
261
|
-
|
|
262
|
-
clearLabel: {
|
|
263
|
-
type: String,
|
|
264
|
-
default: '',
|
|
265
|
-
},
|
|
266
|
-
|
|
267
|
-
actionLabel: {
|
|
268
|
-
type: String,
|
|
269
|
-
default: '',
|
|
270
|
-
},
|
|
271
|
-
|
|
272
|
-
months: {
|
|
273
|
-
type: Array,
|
|
274
|
-
default: () => [],
|
|
275
|
-
validator(months) {
|
|
276
|
-
return [0, 12].includes(months.length);
|
|
277
|
-
},
|
|
278
|
-
},
|
|
279
|
-
|
|
280
|
-
days: {
|
|
281
|
-
type: Array,
|
|
282
|
-
default: () => [],
|
|
283
|
-
validator(days) {
|
|
284
|
-
return [0, 7].includes(days.length);
|
|
285
|
-
},
|
|
286
|
-
},
|
|
287
|
-
|
|
288
|
-
options: {
|
|
289
|
-
type: Array,
|
|
290
|
-
default: () => [],
|
|
291
|
-
},
|
|
292
|
-
|
|
293
|
-
disableClear: {
|
|
294
|
-
type: Boolean,
|
|
295
|
-
default: false,
|
|
296
|
-
},
|
|
342
|
+
filter: {
|
|
343
|
+
'pt-br': 'Filtrar',
|
|
344
|
+
en: 'Filter',
|
|
345
|
+
es: 'Filtrar',
|
|
297
346
|
},
|
|
347
|
+
} as const;
|
|
298
348
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
data() {
|
|
302
|
-
const today = new Date();
|
|
303
|
-
const referenceDate = `${today.getMonth() + 1} 1 ${today.getFullYear()}`;
|
|
304
|
-
|
|
305
|
-
return {
|
|
306
|
-
referenceDate,
|
|
307
|
-
startDate: (this.initialStartDate || '').replace(/-/g, ' '),
|
|
308
|
-
endDate: (this.initialEndDate || '').replace(/-/g, ' '),
|
|
309
|
-
optionSelected: '',
|
|
310
|
-
defaultTranslations: {
|
|
311
|
-
clean: {
|
|
312
|
-
'pt-br': 'Limpar',
|
|
313
|
-
en: 'Clean',
|
|
314
|
-
es: 'Limpiar',
|
|
315
|
-
},
|
|
316
|
-
filter: {
|
|
317
|
-
'pt-br': 'Filtrar',
|
|
318
|
-
en: 'Filter',
|
|
319
|
-
es: 'Filtrar',
|
|
320
|
-
},
|
|
321
|
-
},
|
|
322
|
-
};
|
|
323
|
-
},
|
|
349
|
+
const instance = getCurrentInstance();
|
|
324
350
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
value() {
|
|
331
|
-
return {
|
|
332
|
-
startDate: this.startDate.replaceAll(' ', '-'),
|
|
333
|
-
endDate: this.endDate.replaceAll(' ', '-'),
|
|
334
|
-
};
|
|
335
|
-
},
|
|
336
|
-
|
|
337
|
-
i18nLocale() {
|
|
338
|
-
return this.$i18n.locale.toLowerCase();
|
|
339
|
-
},
|
|
340
|
-
|
|
341
|
-
monthsLocale() {
|
|
342
|
-
const { months } = this;
|
|
343
|
-
return months.length ? months : translationMonths[this.i18nLocale];
|
|
344
|
-
},
|
|
345
|
-
daysLocale() {
|
|
346
|
-
const { days } = this;
|
|
347
|
-
return days.length ? days : translationDays[this.i18nLocale];
|
|
348
|
-
},
|
|
349
|
-
periodsLocale() {
|
|
350
|
-
const { options } = this;
|
|
351
|
-
return options.length ? options : translationPeriods[this.i18nLocale];
|
|
352
|
-
},
|
|
353
|
-
|
|
354
|
-
clearText() {
|
|
355
|
-
return this.clearLabel || translationButtons[this.i18nLocale].clear;
|
|
356
|
-
},
|
|
357
|
-
filterText() {
|
|
358
|
-
return this.actionLabel || translationButtons[this.i18nLocale].filter;
|
|
359
|
-
},
|
|
360
|
-
},
|
|
351
|
+
type I18nProxy = {
|
|
352
|
+
$i18n?: {
|
|
353
|
+
locale?: string;
|
|
354
|
+
};
|
|
355
|
+
};
|
|
361
356
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
357
|
+
const i18nLocale = computed(() => {
|
|
358
|
+
const localeFromInstance = (instance?.proxy as I18nProxy | null)?.$i18n
|
|
359
|
+
?.locale;
|
|
360
|
+
const finalLocale = localeFromInstance || 'en-us';
|
|
361
|
+
|
|
362
|
+
return String(finalLocale).toLowerCase();
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
const monthsLocale = computed(() => {
|
|
366
|
+
const months = props.months || [];
|
|
367
|
+
return months.length ? months : translationMonths[i18nLocale.value];
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
const daysLocale = computed(() => {
|
|
371
|
+
const days = props.days || [];
|
|
372
|
+
return days.length ? days : translationDays[i18nLocale.value];
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
const periodsLocale = computed<PeriodOption[]>(() => {
|
|
376
|
+
const options = props.options || [];
|
|
377
|
+
return options.length ? options : translationPeriods[i18nLocale.value];
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
const clearText = computed(() => {
|
|
381
|
+
return props.clearLabel || translationButtons[i18nLocale.value].clear;
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
const filterText = computed(() => {
|
|
385
|
+
return props.actionLabel || translationButtons[i18nLocale.value].filter;
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
const value = computed(() => ({
|
|
389
|
+
startDate: startDate.value.replaceAll(' ', '-'),
|
|
390
|
+
endDate: endDate.value.replaceAll(' ', '-'),
|
|
391
|
+
}));
|
|
392
|
+
|
|
393
|
+
const i18nFn = (...args: any[]): string | undefined => {
|
|
394
|
+
const [key, defaults] = args;
|
|
395
|
+
|
|
396
|
+
const validLocaleValues = Object.keys(
|
|
397
|
+
((i18n as any).global.messages as Record<string, unknown>) || {},
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
let locale = props.locale as string | undefined;
|
|
401
|
+
|
|
402
|
+
const treatedSelectedLocale =
|
|
403
|
+
get(i18n, 'global.locale') === 'en-us'
|
|
404
|
+
? 'en'
|
|
405
|
+
: (get(i18n, 'global.locale') as string | undefined);
|
|
406
|
+
|
|
407
|
+
locale =
|
|
408
|
+
locale && validLocaleValues.includes(locale)
|
|
409
|
+
? locale
|
|
410
|
+
: treatedSelectedLocale;
|
|
411
|
+
|
|
412
|
+
locale = locale?.toLowerCase();
|
|
413
|
+
|
|
414
|
+
let text = get(
|
|
415
|
+
props.translations,
|
|
416
|
+
`${key}.${locale}`,
|
|
417
|
+
get(props.translations, key),
|
|
418
|
+
) as string | undefined;
|
|
419
|
+
|
|
420
|
+
if (!text) {
|
|
421
|
+
text = get(
|
|
422
|
+
defaultTranslations as Record<string, unknown>,
|
|
423
|
+
`${key}.${locale}`,
|
|
424
|
+
get(defaultTranslations as Record<string, unknown>, key, defaults),
|
|
425
|
+
) as string | undefined;
|
|
426
|
+
}
|
|
365
427
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
428
|
+
if (text?.includes('|') && typeof args[1] === 'number') {
|
|
429
|
+
const count: number = args[1];
|
|
430
|
+
const pluralization = text.split('|');
|
|
369
431
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
432
|
+
if (pluralization.length === 3) {
|
|
433
|
+
text = pluralization[count] || pluralization[2];
|
|
434
|
+
} else if (pluralization.length === 2) {
|
|
435
|
+
text = count === 1 ? pluralization[0] : pluralization[1];
|
|
436
|
+
}
|
|
437
|
+
}
|
|
373
438
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
this.$emit(
|
|
382
|
-
'update:equivalentOption',
|
|
383
|
-
this.periodsLocale.find(
|
|
384
|
-
({ id: periodId }) => periodId === this.optionSelected,
|
|
385
|
-
)?.name || '',
|
|
386
|
-
);
|
|
439
|
+
let vars: Record<string, string> = {};
|
|
440
|
+
|
|
441
|
+
Object.values(args)
|
|
442
|
+
.slice(1)
|
|
443
|
+
.forEach((argument) => {
|
|
444
|
+
if (!(argument instanceof Array) && argument instanceof Object) {
|
|
445
|
+
vars = argument as Record<string, string>;
|
|
387
446
|
}
|
|
388
|
-
}
|
|
447
|
+
});
|
|
389
448
|
|
|
390
|
-
|
|
391
|
-
|
|
449
|
+
Object.keys(vars).forEach((varName) => {
|
|
450
|
+
text = text?.replaceAll(new RegExp(`{ *${varName} *}`, 'g'), vars[varName]);
|
|
451
|
+
});
|
|
392
452
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
}
|
|
453
|
+
return text;
|
|
454
|
+
};
|
|
396
455
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
this.getStartAndEndDateByPeriod(periodId);
|
|
456
|
+
defineExpose({
|
|
457
|
+
i18n: i18nFn,
|
|
400
458
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
});
|
|
459
|
+
startDate,
|
|
460
|
+
endDate,
|
|
461
|
+
optionSelected,
|
|
462
|
+
referenceDate,
|
|
406
463
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
464
|
+
autoSelect,
|
|
465
|
+
dateToString,
|
|
466
|
+
getStartAndEndDateByPeriod,
|
|
467
|
+
getDatesOfTheMonth,
|
|
468
|
+
});
|
|
410
469
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
470
|
+
function dateToString(date: Date): string {
|
|
471
|
+
return `${date.getMonth() + 1} ${date.getDate()} ${date.getFullYear()}`;
|
|
472
|
+
}
|
|
414
473
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
474
|
+
function dateToStringMonth(date: Date): string {
|
|
475
|
+
return `${date.getMonth() + 1} ${date.getFullYear()}`;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function dateToStringYear(date: Date): number {
|
|
479
|
+
return date.getFullYear();
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
function stringToTime(date: string): number {
|
|
483
|
+
const [month, day, year] = date.split(' ');
|
|
484
|
+
return new Date(Number(year), Number(month) - 1, Number(day)).getTime();
|
|
485
|
+
}
|
|
418
486
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
487
|
+
function getDate(date: { toString: () => string }): string {
|
|
488
|
+
return date.toString().split(' ')[1];
|
|
489
|
+
}
|
|
422
490
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
},
|
|
491
|
+
function getMonth(date: { toString: () => string }): number {
|
|
492
|
+
return Number(date.toString().split(' ')[0]);
|
|
493
|
+
}
|
|
427
494
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
495
|
+
function getFullYear(date: string): number {
|
|
496
|
+
const [month, day, year] = date.split(' ');
|
|
497
|
+
return new Date(Number(year), Number(month) - 1, Number(day)).getFullYear();
|
|
498
|
+
}
|
|
431
499
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
},
|
|
500
|
+
function addMonth(reference: string, quantity: number): string {
|
|
501
|
+
const [month, day, year] = reference.split(' ');
|
|
435
502
|
|
|
436
|
-
|
|
437
|
-
const [month, day, year] = date.split(' ');
|
|
438
|
-
return new Date(year, Number(month) - 1, day).getFullYear();
|
|
439
|
-
},
|
|
503
|
+
const date = new Date(Number(year), Number(month) - 1, Number(day));
|
|
440
504
|
|
|
441
|
-
|
|
442
|
-
const [month, day, year] = referenceDate.split(' ');
|
|
505
|
+
date.setMonth(date.getMonth() + quantity);
|
|
443
506
|
|
|
444
|
-
|
|
507
|
+
return dateToString(date);
|
|
508
|
+
}
|
|
445
509
|
|
|
446
|
-
|
|
510
|
+
function isDateBetween(internalDate: number): boolean {
|
|
511
|
+
if (startDate.value && endDate.value) {
|
|
512
|
+
if (
|
|
513
|
+
internalDate >= stringToTime(startDate.value) &&
|
|
514
|
+
internalDate <= stringToTime(endDate.value)
|
|
515
|
+
) {
|
|
516
|
+
return true;
|
|
517
|
+
}
|
|
518
|
+
} else if (startDate.value && internalDate >= stringToTime(startDate.value)) {
|
|
519
|
+
return true;
|
|
520
|
+
} else if (endDate.value && internalDate <= stringToTime(endDate.value)) {
|
|
521
|
+
return true;
|
|
522
|
+
}
|
|
447
523
|
|
|
448
|
-
|
|
449
|
-
|
|
524
|
+
return false;
|
|
525
|
+
}
|
|
450
526
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
internalDate <= this.stringToTime(this.endDate)
|
|
456
|
-
) {
|
|
457
|
-
return true;
|
|
458
|
-
}
|
|
459
|
-
} else if (
|
|
460
|
-
this.startDate &&
|
|
461
|
-
internalDate >= this.stringToTime(this.startDate)
|
|
462
|
-
) {
|
|
463
|
-
return true;
|
|
464
|
-
} else if (
|
|
465
|
-
this.endDate &&
|
|
466
|
-
internalDate <= this.stringToTime(this.endDate)
|
|
467
|
-
) {
|
|
468
|
-
return true;
|
|
469
|
-
}
|
|
527
|
+
function isDateBetweenMonth(internalDate: number): boolean {
|
|
528
|
+
if (startDate.value && endDate.value) {
|
|
529
|
+
const startTime = stringToTime(startDate.value);
|
|
530
|
+
const endTime = stringToTime(endDate.value);
|
|
470
531
|
|
|
471
|
-
|
|
472
|
-
|
|
532
|
+
return internalDate >= startTime && internalDate <= endTime;
|
|
533
|
+
}
|
|
473
534
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
const startDateTime = startDate.getTime();
|
|
535
|
+
if (startDate.value) {
|
|
536
|
+
const startTime = stringToTime(startDate.value);
|
|
537
|
+
return internalDate >= startTime;
|
|
538
|
+
}
|
|
479
539
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
) {
|
|
485
|
-
return true;
|
|
486
|
-
}
|
|
487
|
-
} else if (this.startDate && internalDate >= startDateTime) {
|
|
488
|
-
return true;
|
|
489
|
-
} else if (
|
|
490
|
-
this.endDate &&
|
|
491
|
-
internalDate <= this.stringToTime(this.endDate)
|
|
492
|
-
) {
|
|
493
|
-
return true;
|
|
494
|
-
}
|
|
540
|
+
if (endDate.value) {
|
|
541
|
+
const endTime = stringToTime(endDate.value);
|
|
542
|
+
return internalDate <= endTime;
|
|
543
|
+
}
|
|
495
544
|
|
|
496
|
-
|
|
497
|
-
|
|
545
|
+
return false;
|
|
546
|
+
}
|
|
498
547
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
startDate.setMonth(0);
|
|
504
|
-
const startDateTime = startDate.getTime();
|
|
548
|
+
function isDateBetweenYear(internalDate: number): boolean {
|
|
549
|
+
if (startDate.value && endDate.value) {
|
|
550
|
+
const startTime = stringToTime(startDate.value);
|
|
551
|
+
const endTime = stringToTime(endDate.value);
|
|
505
552
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
internalDate >= startDateTime &&
|
|
509
|
-
internalDate <= this.stringToTime(this.endDate)
|
|
510
|
-
) {
|
|
511
|
-
return true;
|
|
512
|
-
}
|
|
513
|
-
} else if (this.startDate && internalDate >= startDateTime) {
|
|
514
|
-
return true;
|
|
515
|
-
} else if (
|
|
516
|
-
this.endDate &&
|
|
517
|
-
internalDate <= this.stringToTime(this.endDate)
|
|
518
|
-
) {
|
|
519
|
-
return true;
|
|
520
|
-
}
|
|
553
|
+
return internalDate >= startTime && internalDate <= endTime;
|
|
554
|
+
}
|
|
521
555
|
|
|
522
|
-
|
|
523
|
-
|
|
556
|
+
if (startDate.value) {
|
|
557
|
+
const startTime = stringToTime(startDate.value);
|
|
558
|
+
return internalDate >= startTime;
|
|
559
|
+
}
|
|
524
560
|
|
|
525
|
-
|
|
526
|
-
|
|
561
|
+
if (endDate.value) {
|
|
562
|
+
const endTime = stringToTime(endDate.value);
|
|
563
|
+
return internalDate <= endTime;
|
|
564
|
+
}
|
|
527
565
|
|
|
528
|
-
|
|
566
|
+
return false;
|
|
567
|
+
}
|
|
529
568
|
|
|
530
|
-
|
|
531
|
-
|
|
569
|
+
function getDatesOfTheMonth(reference: string) {
|
|
570
|
+
const [month, day, year] = reference.split(' ');
|
|
532
571
|
|
|
533
|
-
|
|
572
|
+
const date = new Date(Number(year), Number(month) - 1, Number(day));
|
|
534
573
|
|
|
535
|
-
|
|
574
|
+
const currentMonth = date.getMonth();
|
|
575
|
+
const oneDayInSeconds = 86400;
|
|
536
576
|
|
|
537
|
-
|
|
538
|
-
const dateString = this.dateToString(date);
|
|
539
|
-
const properties = [];
|
|
577
|
+
date.setDate(1 - date.getDay());
|
|
540
578
|
|
|
541
|
-
|
|
542
|
-
const [minDateYear, minDateMonth, minDateDay] =
|
|
543
|
-
this.minDate.split('-');
|
|
579
|
+
const dates: { properties: string[]; toString: () => string }[] = [];
|
|
544
580
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
minDateDay,
|
|
549
|
-
);
|
|
581
|
+
for (let i = 0; i < 6 * 7; i += 1) {
|
|
582
|
+
const dateString = dateToString(date);
|
|
583
|
+
const properties: string[] = [];
|
|
550
584
|
|
|
551
|
-
|
|
552
|
-
|
|
585
|
+
if (props.minDate) {
|
|
586
|
+
const [minDateYear, minDateMonth, minDateDay] = props.minDate.split('-');
|
|
553
587
|
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
588
|
+
const formatedMinDate = new Date(
|
|
589
|
+
Number(minDateYear),
|
|
590
|
+
Number(minDateMonth) - 1,
|
|
591
|
+
Number(minDateDay),
|
|
592
|
+
);
|
|
557
593
|
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
Number(maxDateMonth) - 1,
|
|
561
|
-
maxDateDay,
|
|
562
|
-
);
|
|
594
|
+
if (date < formatedMinDate) properties.push('out of range');
|
|
595
|
+
}
|
|
563
596
|
|
|
564
|
-
|
|
565
|
-
|
|
597
|
+
if (props.maxDate) {
|
|
598
|
+
const [maxDateYear, maxDateMonth, maxDateDay] = props.maxDate.split('-');
|
|
566
599
|
|
|
567
|
-
|
|
568
|
-
|
|
600
|
+
const formatedMaxDate = new Date(
|
|
601
|
+
Number(maxDateYear),
|
|
602
|
+
Number(maxDateMonth) - 1,
|
|
603
|
+
Number(maxDateDay),
|
|
604
|
+
);
|
|
569
605
|
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
const dayAfter = dateInTime + oneDayInSeconds;
|
|
606
|
+
if (date > formatedMaxDate) properties.push('out of range');
|
|
607
|
+
}
|
|
573
608
|
|
|
574
|
-
|
|
575
|
-
|
|
609
|
+
if (currentMonth === date.getMonth()) {
|
|
610
|
+
properties.push('inside month');
|
|
576
611
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
612
|
+
const dateInTime = stringToTime(dateToString(date));
|
|
613
|
+
const dayBefore = dateInTime - oneDayInSeconds;
|
|
614
|
+
const dayAfter = dateInTime + oneDayInSeconds;
|
|
580
615
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
}
|
|
616
|
+
if (isDateBetween(dateInTime)) {
|
|
617
|
+
properties.push('selected');
|
|
584
618
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
properties.includes('right-highlighted')
|
|
588
|
-
) {
|
|
589
|
-
properties.push('highlighted');
|
|
590
|
-
}
|
|
591
|
-
}
|
|
619
|
+
if (!isDateBetween(dayBefore)) {
|
|
620
|
+
properties.push('left-highlighted');
|
|
592
621
|
}
|
|
593
622
|
|
|
594
|
-
if (
|
|
595
|
-
properties.push('
|
|
623
|
+
if (!isDateBetween(dayAfter)) {
|
|
624
|
+
properties.push('right-highlighted');
|
|
596
625
|
}
|
|
597
626
|
|
|
598
|
-
|
|
599
|
-
properties
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
627
|
+
if (
|
|
628
|
+
properties.includes('left-highlighted') ||
|
|
629
|
+
properties.includes('right-highlighted')
|
|
630
|
+
) {
|
|
631
|
+
properties.push('highlighted');
|
|
632
|
+
}
|
|
604
633
|
}
|
|
634
|
+
}
|
|
605
635
|
|
|
606
|
-
|
|
607
|
-
|
|
636
|
+
if (dateToString(date) === dateToString(new Date())) {
|
|
637
|
+
properties.push('today');
|
|
638
|
+
}
|
|
608
639
|
|
|
609
|
-
|
|
610
|
-
|
|
640
|
+
dates.push({
|
|
641
|
+
properties,
|
|
642
|
+
toString: () => dateString,
|
|
643
|
+
});
|
|
611
644
|
|
|
612
|
-
|
|
645
|
+
date.setDate(date.getDate() + 1);
|
|
646
|
+
}
|
|
613
647
|
|
|
614
|
-
|
|
648
|
+
return dates;
|
|
649
|
+
}
|
|
615
650
|
|
|
616
|
-
|
|
651
|
+
function getMonthsOfTheYear(reference: string) {
|
|
652
|
+
const [month, day, year] = reference.split(' ');
|
|
617
653
|
|
|
618
|
-
|
|
619
|
-
const dateString = this.dateToString(date);
|
|
620
|
-
const properties = [];
|
|
654
|
+
const date = new Date(Number(year), Number(month) - 1, Number(day));
|
|
621
655
|
|
|
622
|
-
|
|
656
|
+
date.setMonth(0);
|
|
623
657
|
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
658
|
+
const dates: {
|
|
659
|
+
properties: string[];
|
|
660
|
+
date: string;
|
|
661
|
+
toString: () => string;
|
|
662
|
+
}[] = [];
|
|
627
663
|
|
|
628
|
-
|
|
629
|
-
|
|
664
|
+
for (let i = 0; i < 3 * 4; i += 1) {
|
|
665
|
+
const dateString = dateToString(date);
|
|
666
|
+
const properties: string[] = [];
|
|
630
667
|
|
|
631
|
-
|
|
632
|
-
monthAfter = monthAfter.getTime();
|
|
668
|
+
properties.push('inside month');
|
|
633
669
|
|
|
634
|
-
|
|
635
|
-
|
|
670
|
+
const dateInTime = stringToTime(dateToString(date));
|
|
671
|
+
const monthBefore = new Date(dateInTime);
|
|
672
|
+
const monthAfter = new Date(dateInTime);
|
|
636
673
|
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
}
|
|
674
|
+
monthBefore.setMonth(monthBefore.getMonth() - 1);
|
|
675
|
+
monthAfter.setMonth(monthAfter.getMonth() + 1);
|
|
640
676
|
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
}
|
|
677
|
+
const monthBeforeTime = monthBefore.getTime();
|
|
678
|
+
const monthAfterTime = monthAfter.getTime();
|
|
644
679
|
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
properties.includes('right-highlighted')
|
|
648
|
-
) {
|
|
649
|
-
properties.push('highlighted');
|
|
650
|
-
}
|
|
651
|
-
}
|
|
680
|
+
if (isDateBetweenMonth(dateInTime)) {
|
|
681
|
+
properties.push('selected');
|
|
652
682
|
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
) {
|
|
656
|
-
properties.push('today');
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
dates.push({
|
|
660
|
-
properties,
|
|
661
|
-
date: dateString,
|
|
662
|
-
toString: () => dateString,
|
|
663
|
-
});
|
|
664
|
-
|
|
665
|
-
date.setMonth(date.getMonth() + 1);
|
|
683
|
+
if (!isDateBetweenMonth(monthBeforeTime)) {
|
|
684
|
+
properties.push('left-highlighted');
|
|
666
685
|
}
|
|
667
686
|
|
|
668
|
-
|
|
669
|
-
|
|
687
|
+
if (!isDateBetweenMonth(monthAfterTime)) {
|
|
688
|
+
properties.push('right-highlighted');
|
|
689
|
+
}
|
|
670
690
|
|
|
671
|
-
|
|
672
|
-
|
|
691
|
+
if (
|
|
692
|
+
properties.includes('left-highlighted') ||
|
|
693
|
+
properties.includes('right-highlighted')
|
|
694
|
+
) {
|
|
695
|
+
properties.push('highlighted');
|
|
696
|
+
}
|
|
697
|
+
}
|
|
673
698
|
|
|
674
|
-
|
|
699
|
+
if (dateToStringMonth(date) === dateToStringMonth(new Date())) {
|
|
700
|
+
properties.push('today');
|
|
701
|
+
}
|
|
675
702
|
|
|
676
|
-
|
|
703
|
+
dates.push({
|
|
704
|
+
properties,
|
|
705
|
+
date: dateString,
|
|
706
|
+
toString: () => dateString,
|
|
707
|
+
});
|
|
677
708
|
|
|
678
|
-
|
|
709
|
+
date.setMonth(date.getMonth() + 1);
|
|
710
|
+
}
|
|
679
711
|
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
const properties = [];
|
|
712
|
+
return dates;
|
|
713
|
+
}
|
|
683
714
|
|
|
684
|
-
|
|
715
|
+
function getYears(reference: string) {
|
|
716
|
+
const [month, day, year] = reference.split(' ');
|
|
685
717
|
|
|
686
|
-
|
|
718
|
+
const date = new Date(Number(year), Number(month) - 1, Number(day));
|
|
687
719
|
|
|
688
|
-
|
|
689
|
-
referenceDate.split(' ');
|
|
720
|
+
date.setMonth(0);
|
|
690
721
|
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
let yearAfter = new Date(
|
|
697
|
-
dateInTimeYear,
|
|
698
|
-
Number(dateInTimeMonth) - 1,
|
|
699
|
-
dateInTimeDay,
|
|
700
|
-
);
|
|
722
|
+
const dates: {
|
|
723
|
+
properties: string[];
|
|
724
|
+
date: number;
|
|
725
|
+
toString: () => string;
|
|
726
|
+
}[] = [];
|
|
701
727
|
|
|
702
|
-
|
|
703
|
-
|
|
728
|
+
for (let i = 0; i < 3 * 4; i += 1) {
|
|
729
|
+
const dateString = dateToString(date);
|
|
730
|
+
const properties: string[] = [];
|
|
704
731
|
|
|
705
|
-
|
|
706
|
-
yearAfter = yearAfter.getTime();
|
|
732
|
+
properties.push('inside month');
|
|
707
733
|
|
|
708
|
-
|
|
709
|
-
properties.push('selected');
|
|
734
|
+
const dateInTime = stringToTime(dateToString(date));
|
|
710
735
|
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
}
|
|
736
|
+
const [dateInTimeMonth, dateInTimeDay, dateInTimeYear] =
|
|
737
|
+
reference.split(' ');
|
|
714
738
|
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
739
|
+
const yearBefore = new Date(
|
|
740
|
+
Number(dateInTimeYear),
|
|
741
|
+
Number(dateInTimeMonth) - 1,
|
|
742
|
+
Number(dateInTimeDay),
|
|
743
|
+
);
|
|
744
|
+
const yearAfter = new Date(
|
|
745
|
+
Number(dateInTimeYear),
|
|
746
|
+
Number(dateInTimeMonth) - 1,
|
|
747
|
+
Number(dateInTimeDay),
|
|
748
|
+
);
|
|
718
749
|
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
properties.includes('right-highlighted')
|
|
722
|
-
) {
|
|
723
|
-
properties.push('highlighted');
|
|
724
|
-
}
|
|
725
|
-
}
|
|
750
|
+
yearBefore.setMonth(yearBefore.getMonth() - 12);
|
|
751
|
+
yearAfter.setMonth(yearAfter.getMonth() + 12);
|
|
726
752
|
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
}
|
|
753
|
+
const yearBeforeTime = yearBefore.getTime();
|
|
754
|
+
const yearAfterTime = yearAfter.getTime();
|
|
730
755
|
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
date: date.getFullYear(),
|
|
734
|
-
toString: () => dateString,
|
|
735
|
-
});
|
|
756
|
+
if (isDateBetweenYear(dateInTime)) {
|
|
757
|
+
properties.push('selected');
|
|
736
758
|
|
|
737
|
-
|
|
759
|
+
if (!isDateBetweenYear(yearBeforeTime)) {
|
|
760
|
+
properties.push('left-highlighted');
|
|
738
761
|
}
|
|
739
762
|
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
selectDate(date) {
|
|
744
|
-
if (!this.startDate || !this.endDate) {
|
|
745
|
-
this.startDate = date.toString();
|
|
746
|
-
this.endDate = this.startDate;
|
|
747
|
-
} else {
|
|
748
|
-
const self = this.stringToTime(date.toString());
|
|
749
|
-
|
|
750
|
-
const startDate = this.stringToTime(this.startDate);
|
|
751
|
-
const endDate = this.stringToTime(this.endDate);
|
|
752
|
-
|
|
753
|
-
if (startDate !== endDate) {
|
|
754
|
-
this.startDate = date.toString();
|
|
755
|
-
this.endDate = this.startDate;
|
|
756
|
-
} else if (self > endDate) {
|
|
757
|
-
this.endDate = date.toString();
|
|
758
|
-
} else if (self < startDate) {
|
|
759
|
-
this.startDate = date.toString();
|
|
760
|
-
} else if (self === startDate || self === endDate) {
|
|
761
|
-
this.startDate = date.toString();
|
|
762
|
-
this.endDate = this.startDate;
|
|
763
|
-
} else if (self - startDate < endDate - self) {
|
|
764
|
-
this.startDate = date.toString();
|
|
765
|
-
} else {
|
|
766
|
-
this.endDate = date.toString();
|
|
767
|
-
}
|
|
763
|
+
if (!isDateBetweenYear(yearAfterTime)) {
|
|
764
|
+
properties.push('right-highlighted');
|
|
768
765
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
},
|
|
776
|
-
|
|
777
|
-
getStartAndEndDateByPeriod(period) {
|
|
778
|
-
let startDate;
|
|
779
|
-
let endDate;
|
|
780
|
-
|
|
781
|
-
const today = new Date();
|
|
782
|
-
|
|
783
|
-
const days = period.match(/^last-(\d+)-days$/);
|
|
784
|
-
const months = period.match(/^last-(\d+)-months$/);
|
|
785
|
-
|
|
786
|
-
if (days) {
|
|
787
|
-
const howMuch = Number(days[1]);
|
|
788
|
-
|
|
789
|
-
endDate = this.dateToString(today);
|
|
790
|
-
today.setDate(today.getDate() - howMuch + 1);
|
|
791
|
-
startDate = this.dateToString(today);
|
|
792
|
-
} else if (months) {
|
|
793
|
-
const howMuch = Number(months[1]);
|
|
794
|
-
|
|
795
|
-
endDate = this.dateToString(today);
|
|
796
|
-
today.setDate(today.getDate() + 1);
|
|
797
|
-
today.setMonth(today.getMonth() - howMuch);
|
|
798
|
-
startDate = this.dateToString(today);
|
|
799
|
-
} else if (period === 'current-month') {
|
|
800
|
-
const referenceDate = new Date();
|
|
801
|
-
today.setDate(1);
|
|
802
|
-
startDate = this.dateToString(today);
|
|
803
|
-
const referenceDay = referenceDate.getDate();
|
|
804
|
-
today.setDate(referenceDay);
|
|
805
|
-
endDate = this.dateToString(today);
|
|
806
|
-
} else if (period === 'previous-month') {
|
|
807
|
-
today.setDate(1);
|
|
808
|
-
today.setMonth(today.getMonth() - 1);
|
|
809
|
-
startDate = this.dateToString(today);
|
|
810
|
-
today.setMonth(today.getMonth() + 1);
|
|
811
|
-
today.setDate(0);
|
|
812
|
-
endDate = this.dateToString(today);
|
|
766
|
+
|
|
767
|
+
if (
|
|
768
|
+
properties.includes('left-highlighted') ||
|
|
769
|
+
properties.includes('right-highlighted')
|
|
770
|
+
) {
|
|
771
|
+
properties.push('highlighted');
|
|
813
772
|
}
|
|
773
|
+
}
|
|
814
774
|
|
|
815
|
-
|
|
816
|
-
|
|
775
|
+
if (dateToStringYear(date) === dateToStringYear(new Date())) {
|
|
776
|
+
properties.push('today');
|
|
777
|
+
}
|
|
817
778
|
|
|
818
|
-
|
|
819
|
-
|
|
779
|
+
dates.push({
|
|
780
|
+
properties,
|
|
781
|
+
date: date.getFullYear(),
|
|
782
|
+
toString: () => dateString,
|
|
783
|
+
});
|
|
820
784
|
|
|
821
|
-
|
|
822
|
-
|
|
785
|
+
date.setFullYear(date.getFullYear() + 1);
|
|
786
|
+
}
|
|
823
787
|
|
|
824
|
-
|
|
825
|
-
|
|
788
|
+
return dates;
|
|
789
|
+
}
|
|
826
790
|
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
791
|
+
function selectDate(date: { toString: () => string }) {
|
|
792
|
+
if (!startDate.value || !endDate.value) {
|
|
793
|
+
startDate.value = date.toString();
|
|
794
|
+
endDate.value = startDate.value;
|
|
795
|
+
} else {
|
|
796
|
+
const self = stringToTime(date.toString());
|
|
797
|
+
|
|
798
|
+
const startTime = stringToTime(startDate.value);
|
|
799
|
+
const endTime = stringToTime(endDate.value);
|
|
800
|
+
|
|
801
|
+
if (startTime !== endTime) {
|
|
802
|
+
startDate.value = date.toString();
|
|
803
|
+
endDate.value = startDate.value;
|
|
804
|
+
} else if (self > endTime) {
|
|
805
|
+
endDate.value = date.toString();
|
|
806
|
+
} else if (self < startTime) {
|
|
807
|
+
startDate.value = date.toString();
|
|
808
|
+
} else if (self === startTime || self === endTime) {
|
|
809
|
+
startDate.value = date.toString();
|
|
810
|
+
endDate.value = startDate.value;
|
|
811
|
+
} else if (self - startTime < endTime - self) {
|
|
812
|
+
startDate.value = date.toString();
|
|
813
|
+
} else {
|
|
814
|
+
endDate.value = date.toString();
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
}
|
|
830
818
|
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
819
|
+
function clear() {
|
|
820
|
+
startDate.value = '';
|
|
821
|
+
endDate.value = '';
|
|
822
|
+
optionSelected.value = '';
|
|
823
|
+
}
|
|
835
824
|
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
825
|
+
function getStartAndEndDateByPeriod(period: string) {
|
|
826
|
+
let periodStartDate: string | undefined;
|
|
827
|
+
let periodEndDate: string | undefined;
|
|
828
|
+
|
|
829
|
+
let baseDate: Date;
|
|
830
|
+
|
|
831
|
+
if (props.periodBaseDate) {
|
|
832
|
+
const parts = props.periodBaseDate.split('-');
|
|
833
|
+
|
|
834
|
+
if (parts.length === 3) {
|
|
835
|
+
const [year, month, day] = parts;
|
|
836
|
+
|
|
837
|
+
baseDate = new Date(Number(year), Number(month) - 1, Number(day));
|
|
838
|
+
} else {
|
|
839
|
+
const parsed = new Date(props.periodBaseDate);
|
|
840
|
+
baseDate = Number.isNaN(parsed.getTime()) ? new Date() : parsed;
|
|
841
|
+
}
|
|
842
|
+
} else {
|
|
843
|
+
baseDate = new Date();
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
const todayClone = new Date(baseDate.getTime());
|
|
847
|
+
|
|
848
|
+
const daysMatch = period.match(/^last-(\d+)-days$/);
|
|
849
|
+
const monthsMatch = period.match(/^last-(\d+)-months$/);
|
|
850
|
+
|
|
851
|
+
if (daysMatch) {
|
|
852
|
+
const howMuch = Number(daysMatch[1]);
|
|
853
|
+
|
|
854
|
+
periodEndDate = dateToString(todayClone);
|
|
855
|
+
todayClone.setDate(todayClone.getDate() - howMuch + 1);
|
|
856
|
+
periodStartDate = dateToString(todayClone);
|
|
857
|
+
} else if (monthsMatch) {
|
|
858
|
+
const howMuch = Number(monthsMatch[1]);
|
|
859
|
+
|
|
860
|
+
periodEndDate = dateToString(todayClone);
|
|
861
|
+
todayClone.setDate(todayClone.getDate() + 1);
|
|
862
|
+
todayClone.setMonth(todayClone.getMonth() - howMuch);
|
|
863
|
+
periodStartDate = dateToString(todayClone);
|
|
864
|
+
} else if (period === 'current-month') {
|
|
865
|
+
const referenceDay = baseDate.getDate();
|
|
866
|
+
|
|
867
|
+
todayClone.setDate(1);
|
|
868
|
+
periodStartDate = dateToString(todayClone);
|
|
869
|
+
todayClone.setDate(referenceDay);
|
|
870
|
+
periodEndDate = dateToString(todayClone);
|
|
871
|
+
} else if (period === 'previous-month') {
|
|
872
|
+
todayClone.setDate(1);
|
|
873
|
+
todayClone.setMonth(todayClone.getMonth() - 1);
|
|
874
|
+
periodStartDate = dateToString(todayClone);
|
|
875
|
+
todayClone.setMonth(todayClone.getMonth() + 1);
|
|
876
|
+
todayClone.setDate(0);
|
|
877
|
+
periodEndDate = dateToString(todayClone);
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
return { startDate: periodStartDate, endDate: periodEndDate };
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
function autoSelect(method: string) {
|
|
884
|
+
const { startDate: periodStartDate, endDate: periodEndDate } =
|
|
885
|
+
getStartAndEndDateByPeriod(method);
|
|
886
|
+
|
|
887
|
+
startDate.value = periodStartDate || '';
|
|
888
|
+
endDate.value = periodEndDate || '';
|
|
889
|
+
|
|
890
|
+
if (endDate.value) {
|
|
891
|
+
const secondMonth = addMonth(referenceDate.value, 1);
|
|
892
|
+
|
|
893
|
+
const firstDateOfEndDate = `${Number(
|
|
894
|
+
getMonth({
|
|
895
|
+
toString: () => endDate.value,
|
|
896
|
+
}),
|
|
897
|
+
)} 1 ${getFullYear(endDate.value)}`;
|
|
898
|
+
|
|
899
|
+
if (![referenceDate.value, secondMonth].includes(firstDateOfEndDate)) {
|
|
900
|
+
referenceDate.value = firstDateOfEndDate;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
nextTick(() => {
|
|
905
|
+
optionSelected.value = method;
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
function submit() {
|
|
910
|
+
emit('submit', value.value);
|
|
911
|
+
|
|
912
|
+
if (optionSelected.value === 'custom') {
|
|
913
|
+
emit('update:equivalentOption', '');
|
|
914
|
+
} else {
|
|
915
|
+
const period = periodsLocale.value.find(
|
|
916
|
+
({ id }) => id === optionSelected.value,
|
|
917
|
+
);
|
|
918
|
+
|
|
919
|
+
emit('update:equivalentOption', period?.name || '');
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
function updateOptionSelected() {
|
|
924
|
+
const { startDate: start, endDate: end } = value.value;
|
|
925
|
+
|
|
926
|
+
const isSameTime = (date1?: string, date2?: string) => {
|
|
927
|
+
if (!date1 || !date2) return false;
|
|
928
|
+
return new Date(date1).getTime() === new Date(date2).getTime();
|
|
929
|
+
};
|
|
930
|
+
|
|
931
|
+
const period = periodsLocale.value.find(({ id }) => {
|
|
932
|
+
const { startDate: periodStartDate, endDate: periodEndDate } =
|
|
933
|
+
getStartAndEndDateByPeriod(id);
|
|
934
|
+
|
|
935
|
+
return isSameTime(start, periodStartDate) && isSameTime(end, periodEndDate);
|
|
936
|
+
});
|
|
937
|
+
|
|
938
|
+
optionSelected.value = start || end ? (period ? period.id : 'custom') : '';
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
const openMonths = computed(() => [
|
|
942
|
+
addMonth(referenceDate.value, -1),
|
|
943
|
+
referenceDate.value,
|
|
944
|
+
]);
|
|
945
|
+
|
|
946
|
+
watch(value, (newValue) => {
|
|
947
|
+
updateOptionSelected();
|
|
948
|
+
emit('change', newValue);
|
|
949
|
+
});
|
|
950
|
+
|
|
951
|
+
onMounted(() => {
|
|
952
|
+
updateOptionSelected();
|
|
953
|
+
});
|
|
842
954
|
</script>
|
|
843
955
|
|
|
844
956
|
<style lang="scss" scoped>
|