adminforth 4.7.4 → 4.8.0
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/dist/modules/styles.js +4 -4
- package/dist/servers/express.d.ts.map +1 -1
- package/dist/servers/express.js +5 -41
- package/dist/servers/express.js.map +1 -1
- package/dist/servers/startingPages.d.ts +4 -0
- package/dist/servers/startingPages.d.ts.map +1 -0
- package/dist/servers/startingPages.js +127 -0
- package/dist/servers/startingPages.js.map +1 -0
- package/dist/spa/package.json +1 -0
- package/dist/spa/src/afcl/Calendar.vue +211 -0
- package/dist/spa/src/afcl/DateField.vue +257 -0
- package/dist/spa/src/afcl/DatePicker.vue +103 -245
- package/dist/spa/src/afcl/TimeField.vue +52 -0
- package/dist/spa/src/afcl/pickerStyles.ts +25 -0
- package/dist/spa/src/afcl/shadowRoot.ts +1 -2
- package/dist/spa/src/components/ColumnValueInput.vue +9 -7
- package/dist/spa/src/components/ColumnValueInputWrapper.vue +1 -1
- package/dist/spa/src/components/CustomDateRangePicker.vue +47 -165
- package/dist/spa/src/components/Filters.vue +7 -4
- package/dist/spa/src/components/GroupsTable.vue +23 -43
- package/dist/spa/src/components/ShowTable.vue +21 -31
- package/dist/spa/src/components/Sidebar.vue +1 -2
- package/dist/spa/src/utils/dateUtils.ts +33 -21
- package/dist/spa/src/views/CreateEditSkeleton.vue +6 -17
- package/dist/spa/src/views/ShowView.vue +14 -24
- package/dist/spa/tailwind.config.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div ref="rootEl" class="afcl-date-field relative" :style="{ anchorName }">
|
|
3
|
+
<IconCalendar v-if="!bare" :class="PICKER_ICON_CLASSES" aria-hidden="true" />
|
|
4
|
+
<input
|
|
5
|
+
ref="inputEl"
|
|
6
|
+
v-model="text"
|
|
7
|
+
:id="inputId"
|
|
8
|
+
type="text"
|
|
9
|
+
autocomplete="off"
|
|
10
|
+
aria-haspopup="dialog"
|
|
11
|
+
:aria-expanded="isOpen"
|
|
12
|
+
:placeholder="placeholder"
|
|
13
|
+
:disabled="disabled"
|
|
14
|
+
:class="[
|
|
15
|
+
'w-full',
|
|
16
|
+
PICKER_TEXT_CLASSES,
|
|
17
|
+
bare ? 'h-full px-2.5 bg-transparent border-0' : ['ps-8 pe-2.5', PICKER_BOX_CLASSES, isOpen && PICKER_BOX_OPEN_CLASSES],
|
|
18
|
+
inputClass,
|
|
19
|
+
]"
|
|
20
|
+
@focus="onFocus"
|
|
21
|
+
@click="open"
|
|
22
|
+
@input="onInput"
|
|
23
|
+
@keydown="onInputKeydown"
|
|
24
|
+
@blur="commit"
|
|
25
|
+
/>
|
|
26
|
+
<teleport :to="teleportTarget" v-if="isOpen">
|
|
27
|
+
<!-- mousedown keeps the focus in the field, so a click on a day does not blur it and typing goes on -->
|
|
28
|
+
<div
|
|
29
|
+
ref="popoverEl"
|
|
30
|
+
popover="manual"
|
|
31
|
+
role="dialog"
|
|
32
|
+
:style="{ positionAnchor: anchorName }"
|
|
33
|
+
class="afcl-date-field-popover p-0 rounded-lg bg-lightDatePickerCalendarBackground shadow-popover dark:bg-darkDatePickerCalendarBackground dark:shadow-darkPopover"
|
|
34
|
+
@mousedown.prevent
|
|
35
|
+
@keydown="onPopoverKeydown"
|
|
36
|
+
>
|
|
37
|
+
<Calendar ref="calendarRef" :modelValue="previewDay" @update:modelValue="select" />
|
|
38
|
+
</div>
|
|
39
|
+
</teleport>
|
|
40
|
+
</div>
|
|
41
|
+
</template>
|
|
42
|
+
|
|
43
|
+
<script setup lang="ts">
|
|
44
|
+
import { nextTick, onBeforeUnmount, ref, useId, watch } from 'vue';
|
|
45
|
+
import { useI18n } from 'vue-i18n';
|
|
46
|
+
import { IconCalendar } from '@iconify-prerendered/vue-lucide';
|
|
47
|
+
import { formatPickerDay, parseFlexibleDate } from '@/utils/dateUtils';
|
|
48
|
+
import { activeElementIn, useTeleportTarget } from './shadowRoot';
|
|
49
|
+
import Calendar from './Calendar.vue';
|
|
50
|
+
import { PICKER_BOX_CLASSES, PICKER_BOX_OPEN_CLASSES, PICKER_ICON_CLASSES, PICKER_TEXT_CLASSES } from './pickerStyles';
|
|
51
|
+
|
|
52
|
+
const props = defineProps<{
|
|
53
|
+
// the picked day in PICKER_DAY_FORMAT
|
|
54
|
+
modelValue: string | null,
|
|
55
|
+
placeholder?: string,
|
|
56
|
+
disabled?: boolean,
|
|
57
|
+
// closes the calendar once a day is picked
|
|
58
|
+
autoHide?: boolean,
|
|
59
|
+
// no border, icon and background: the field sits inside a box of the parent, like the two halves of a range
|
|
60
|
+
bare?: boolean,
|
|
61
|
+
inputId?: string,
|
|
62
|
+
inputClass?: string,
|
|
63
|
+
}>();
|
|
64
|
+
|
|
65
|
+
const emit = defineEmits<{
|
|
66
|
+
'update:modelValue': [day: string | null],
|
|
67
|
+
}>();
|
|
68
|
+
|
|
69
|
+
const OFFSET = 6;
|
|
70
|
+
const SUPPORTS_ANCHOR = CSS.supports('anchor-name: --a');
|
|
71
|
+
|
|
72
|
+
const { locale } = useI18n();
|
|
73
|
+
const teleportTarget = useTeleportTarget();
|
|
74
|
+
const anchorName = `--afcl-date-field-${useId()}`;
|
|
75
|
+
|
|
76
|
+
const rootEl = ref<HTMLElement>();
|
|
77
|
+
const inputEl = ref<HTMLInputElement>();
|
|
78
|
+
const popoverEl = ref<HTMLElement>();
|
|
79
|
+
const calendarRef = ref<InstanceType<typeof Calendar>>();
|
|
80
|
+
|
|
81
|
+
const isOpen = ref(false);
|
|
82
|
+
const text = ref('');
|
|
83
|
+
// the day the calendar shows while the user types, it becomes the value on Enter or blur
|
|
84
|
+
const previewDay = ref<string | null>(null);
|
|
85
|
+
// focus which the field takes back from its own calendar must not open it again
|
|
86
|
+
let skipFocusOpen = false;
|
|
87
|
+
|
|
88
|
+
function showValue() {
|
|
89
|
+
text.value = props.modelValue ? formatPickerDay(props.modelValue) : '';
|
|
90
|
+
previewDay.value = props.modelValue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
watch(() => props.modelValue, showValue, { immediate: true });
|
|
94
|
+
// month names follow the language
|
|
95
|
+
watch(locale, showValue);
|
|
96
|
+
|
|
97
|
+
function open() {
|
|
98
|
+
if (!props.disabled) {
|
|
99
|
+
isOpen.value = true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function close() {
|
|
104
|
+
isOpen.value = false;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function onFocus() {
|
|
108
|
+
if (skipFocusOpen) {
|
|
109
|
+
skipFocusOpen = false;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
open();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function focusField() {
|
|
116
|
+
skipFocusOpen = true;
|
|
117
|
+
inputEl.value!.focus();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function onInput() {
|
|
121
|
+
open();
|
|
122
|
+
const typed = text.value.trim();
|
|
123
|
+
previewDay.value = typed ? parseFlexibleDate(typed) ?? previewDay.value : null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function commit() {
|
|
127
|
+
const typed = text.value.trim();
|
|
128
|
+
const day = typed ? parseFlexibleDate(typed) : null;
|
|
129
|
+
if (typed && !day) {
|
|
130
|
+
// not a date: the field returns to the value it had
|
|
131
|
+
showValue();
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
text.value = day ? formatPickerDay(day) : '';
|
|
135
|
+
previewDay.value = day;
|
|
136
|
+
if (day !== props.modelValue) {
|
|
137
|
+
emit('update:modelValue', day);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function select(day: string | null) {
|
|
142
|
+
const focusInCalendar = popoverEl.value!.contains(activeElementIn(popoverEl.value!));
|
|
143
|
+
text.value = day ? formatPickerDay(day) : '';
|
|
144
|
+
previewDay.value = day;
|
|
145
|
+
if (day !== props.modelValue) {
|
|
146
|
+
emit('update:modelValue', day);
|
|
147
|
+
}
|
|
148
|
+
if (props.autoHide) {
|
|
149
|
+
close();
|
|
150
|
+
if (focusInCalendar) {
|
|
151
|
+
focusField();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function onInputKeydown(e: KeyboardEvent) {
|
|
157
|
+
if (e.key === 'ArrowDown') {
|
|
158
|
+
e.preventDefault();
|
|
159
|
+
open();
|
|
160
|
+
nextTick(() => calendarRef.value!.focus());
|
|
161
|
+
} else if (e.key === 'Escape' && isOpen.value) {
|
|
162
|
+
// only the calendar closes, not a dialog or drawer around the field
|
|
163
|
+
e.stopPropagation();
|
|
164
|
+
close();
|
|
165
|
+
} else if (e.key === 'Enter' && isOpen.value) {
|
|
166
|
+
e.preventDefault();
|
|
167
|
+
commit();
|
|
168
|
+
if (props.autoHide) {
|
|
169
|
+
close();
|
|
170
|
+
}
|
|
171
|
+
} else if (e.key === 'Tab') {
|
|
172
|
+
close();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function onPopoverKeydown(e: KeyboardEvent) {
|
|
177
|
+
if (e.key === 'Escape') {
|
|
178
|
+
e.stopPropagation();
|
|
179
|
+
close();
|
|
180
|
+
focusField();
|
|
181
|
+
} else if (e.key === 'Tab') {
|
|
182
|
+
// the calendar is teleported to the end of the page, Tab cycles inside it like in a dialog
|
|
183
|
+
const focusable = [...popoverEl.value!.querySelectorAll<HTMLElement>('button:not([disabled]):not([tabindex="-1"])')];
|
|
184
|
+
const current = focusable.indexOf(activeElementIn(popoverEl.value!) as HTMLElement);
|
|
185
|
+
e.preventDefault();
|
|
186
|
+
focusable[(current + (e.shiftKey ? -1 : 1) + focusable.length) % focusable.length].focus();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function onDocumentMousedown(e: MouseEvent) {
|
|
191
|
+
// inside a shadow root e.target is the host, composedPath() starts at the clicked element
|
|
192
|
+
const target = e.composedPath()[0] as Node;
|
|
193
|
+
if (!rootEl.value!.contains(target) && !popoverEl.value?.contains(target)) {
|
|
194
|
+
close();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Safari before 26 and Firefox before 147 have no CSS anchor positioning
|
|
199
|
+
function placeByRect() {
|
|
200
|
+
const field = rootEl.value!.getBoundingClientRect();
|
|
201
|
+
const el = popoverEl.value!;
|
|
202
|
+
const { width, height } = el.getBoundingClientRect();
|
|
203
|
+
const fitsBelow = field.bottom + OFFSET + height <= window.innerHeight;
|
|
204
|
+
el.style.top = `${fitsBelow ? field.bottom + OFFSET : field.top - OFFSET - height}px`;
|
|
205
|
+
el.style.left = `${Math.min(Math.max(field.left, 0), window.innerWidth - width)}px`;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function addListeners() {
|
|
209
|
+
document.addEventListener('mousedown', onDocumentMousedown);
|
|
210
|
+
if (!SUPPORTS_ANCHOR) {
|
|
211
|
+
window.addEventListener('scroll', placeByRect, true);
|
|
212
|
+
window.addEventListener('resize', placeByRect);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function removeListeners() {
|
|
217
|
+
document.removeEventListener('mousedown', onDocumentMousedown);
|
|
218
|
+
window.removeEventListener('scroll', placeByRect, true);
|
|
219
|
+
window.removeEventListener('resize', placeByRect);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
watch(isOpen, async (opened) => {
|
|
223
|
+
if (!opened) {
|
|
224
|
+
removeListeners();
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
await nextTick();
|
|
228
|
+
popoverEl.value!.showPopover();
|
|
229
|
+
if (!SUPPORTS_ANCHOR) {
|
|
230
|
+
placeByRect();
|
|
231
|
+
}
|
|
232
|
+
addListeners();
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
onBeforeUnmount(removeListeners);
|
|
236
|
+
|
|
237
|
+
defineExpose({
|
|
238
|
+
focus: () => inputEl.value!.focus(),
|
|
239
|
+
});
|
|
240
|
+
</script>
|
|
241
|
+
|
|
242
|
+
<style>
|
|
243
|
+
/* popover puts the calendar into the top layer, so no z-index and no clipping by overflow of the parents */
|
|
244
|
+
.afcl-date-field-popover {
|
|
245
|
+
inset: auto;
|
|
246
|
+
margin: 0;
|
|
247
|
+
overflow: visible;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
@supports (anchor-name: --a) {
|
|
251
|
+
.afcl-date-field-popover {
|
|
252
|
+
position-area: bottom span-right;
|
|
253
|
+
position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline;
|
|
254
|
+
margin-top: 6px;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
</style>
|
|
@@ -1,290 +1,148 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div>
|
|
3
|
-
<
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
<IconClock class="w-4 h-4 text-lightDatePickerIcon dark:text-darkDatePickerIcon bg-lightDatePickerButtonBackground dark:bg-darkDatePickerButtonBackground"/>
|
|
26
|
-
</div>
|
|
27
|
-
<input v-model="startTime" type="time" id="start-time" step="1"
|
|
28
|
-
class="af-pick-time-button bg-lightDatePickerButtonBackground border border-lightDatePickerButtonBorder text-lightDatePickerButtonText text-sm rounded-default block w-full px-2.5 py-1.5 leading-5 shadow-customLight focus:outline-none focus:ring-[3px] focus:ring-lightInputFocusRing focus:border-lightInputFocusBorder dark:focus:ring-darkInputFocusRing dark:focus:border-darkInputFocusBorder dark:bg-darkInputBackground dark:border-darkInputBorder dark:placeholder-darkInputPlaceholderText dark:text-darkDatePickerButtonText focus:ring-lightInputFocusRing focus:border-lightInputFocusBorder dark:focus:ring-darkInputFocusRing dark:focus:border-darkInputFocusBorder"
|
|
29
|
-
value="00:00" :disabled="readonly" required/>
|
|
30
|
-
</div>
|
|
31
|
-
</div>
|
|
32
|
-
</div>
|
|
33
|
-
|
|
34
|
-
<button type="button"
|
|
35
|
-
class="text-lightDatePickerExpandText dark:text-darkDatePickerExpandText text-[13px] font-medium hover:underline p-0 inline-flex items-center gap-0.5 mb-2"
|
|
36
|
-
:class="{hidden: column.type !== 'datetime'}"
|
|
37
|
-
@click="toggleTimeInputs">{{ showTimeInputs ? $t('Hide time') : $t('Show time') }}
|
|
38
|
-
<IconChevronDown class="w-4 h-4" :class="{'rotate-180': showTimeInputs}"/>
|
|
39
|
-
</button>
|
|
2
|
+
<div class="afcl-datepicker" :class="{ 'opacity-50': readonly }">
|
|
3
|
+
<label v-if="label" :for="dateInputId" class="block mb-2 text-sm font-medium text-lightDatePickerButtonText dark:text-darkDatePickerButtonText">{{ label }}</label>
|
|
4
|
+
<div class="flex flex-wrap gap-1.5">
|
|
5
|
+
<DateField
|
|
6
|
+
v-if="fieldsType !== 'time'"
|
|
7
|
+
ref="dateField"
|
|
8
|
+
v-model="date"
|
|
9
|
+
class="w-40"
|
|
10
|
+
inputClass="af-pick-date-button"
|
|
11
|
+
:inputId="dateInputId"
|
|
12
|
+
:placeholder="$t('Select date')"
|
|
13
|
+
:disabled="readonly"
|
|
14
|
+
:autoHide="autoHide"
|
|
15
|
+
/>
|
|
16
|
+
<TimeField
|
|
17
|
+
v-if="fieldsType !== 'date'"
|
|
18
|
+
ref="timeField"
|
|
19
|
+
v-model="time"
|
|
20
|
+
class="w-36"
|
|
21
|
+
inputClass="af-pick-time-button"
|
|
22
|
+
:step="1"
|
|
23
|
+
:disabled="readonly"
|
|
24
|
+
/>
|
|
40
25
|
</div>
|
|
41
26
|
</div>
|
|
42
27
|
</template>
|
|
43
|
-
<script setup>
|
|
44
|
-
import {ref, computed,
|
|
45
|
-
import dayjs from 'dayjs';
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
import
|
|
49
|
-
import
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
column:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
},
|
|
67
|
-
autoHide: {
|
|
68
|
-
type: Boolean,
|
|
69
|
-
},
|
|
70
|
-
readonly: {
|
|
71
|
-
type: Boolean,
|
|
72
|
-
},
|
|
28
|
+
<script setup lang="ts">
|
|
29
|
+
import { ref, computed, watch, useId, getCurrentInstance } from 'vue';
|
|
30
|
+
import dayjs, { type Dayjs } from 'dayjs';
|
|
31
|
+
|
|
32
|
+
import { PICKER_DAY_FORMAT } from '@/utils/dateUtils';
|
|
33
|
+
import DateField from './DateField.vue';
|
|
34
|
+
import TimeField from './TimeField.vue';
|
|
35
|
+
|
|
36
|
+
type DatePickerType = 'date' | 'datetime' | 'time';
|
|
37
|
+
|
|
38
|
+
const props = withDefaults(defineProps<{
|
|
39
|
+
// date, time, or both side by side
|
|
40
|
+
type?: DatePickerType,
|
|
41
|
+
label?: string,
|
|
42
|
+
// closes the calendar once a day is picked
|
|
43
|
+
autoHide?: boolean,
|
|
44
|
+
readonly?: boolean,
|
|
45
|
+
/** @deprecated use `type`, removed in the next major version */
|
|
46
|
+
column?: { type: DatePickerType },
|
|
47
|
+
/** @deprecated use `v-model`, removed in the next major version */
|
|
48
|
+
valueStart?: string,
|
|
49
|
+
}>(), {
|
|
50
|
+
type: 'date',
|
|
73
51
|
});
|
|
74
52
|
|
|
75
|
-
const emit = defineEmits
|
|
53
|
+
const emit = defineEmits<{
|
|
54
|
+
/** @deprecated use `v-model`, removed in the next major version */
|
|
55
|
+
'update:valueStart': [value: string | undefined],
|
|
56
|
+
}>();
|
|
76
57
|
|
|
77
|
-
|
|
58
|
+
// "2026-10-14" for date, an ISO string in UTC for datetime, "14:20:00" for time
|
|
59
|
+
const model = defineModel<string>();
|
|
78
60
|
|
|
79
|
-
|
|
61
|
+
// TODO next major: remove column and valueStart with their warnings
|
|
62
|
+
// the props and listeners the parent passed, to tell v-model:valueStart from v-model
|
|
63
|
+
const parentProps = getCurrentInstance()!.vnode.props ?? {};
|
|
64
|
+
const usesValueStart = ['valueStart', 'value-start', 'onUpdate:valueStart'].some((key) => key in parentProps);
|
|
65
|
+
if (props.column) {
|
|
66
|
+
console.warn('AFCL DatePicker: the "column" prop is deprecated and will be removed in the next major version, pass type="date|datetime|time" instead');
|
|
67
|
+
}
|
|
68
|
+
if (usesValueStart) {
|
|
69
|
+
console.warn('AFCL DatePicker: "valueStart" is deprecated and will be removed in the next major version, use v-model instead');
|
|
70
|
+
}
|
|
80
71
|
|
|
81
|
-
const
|
|
72
|
+
const fieldsType = computed(() => props.column?.type ?? props.type);
|
|
73
|
+
const current = computed(() => usesValueStart ? props.valueStart : model.value);
|
|
82
74
|
|
|
83
|
-
|
|
75
|
+
function setValue(value: string | undefined) {
|
|
76
|
+
if (usesValueStart) {
|
|
77
|
+
emit('update:valueStart', value);
|
|
78
|
+
} else {
|
|
79
|
+
model.value = value;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
84
82
|
|
|
85
|
-
const
|
|
83
|
+
const dateField = ref<InstanceType<typeof DateField>>();
|
|
84
|
+
const timeField = ref<InstanceType<typeof TimeField>>();
|
|
85
|
+
const dateInputId = useId();
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
const date = ref<string | null>(null);
|
|
88
88
|
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
const time = ref('');
|
|
90
|
+
|
|
91
|
+
const value = computed(() => {
|
|
92
|
+
if (fieldsType.value === 'time') {
|
|
93
|
+
return formatTime(time.value);
|
|
92
94
|
}
|
|
93
|
-
|
|
94
|
-
if (!
|
|
95
|
+
|
|
96
|
+
if (!date.value) {
|
|
95
97
|
return;
|
|
96
98
|
}
|
|
97
99
|
|
|
98
|
-
let
|
|
100
|
+
let value = dayjs(date.value);
|
|
99
101
|
|
|
100
|
-
if (
|
|
101
|
-
return
|
|
102
|
+
if (fieldsType.value === 'date') {
|
|
103
|
+
return value.format('YYYY-MM-DD');
|
|
102
104
|
}
|
|
103
105
|
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
+
if (time.value) {
|
|
107
|
+
value = addTimeToDate(formatTime(time.value), value)
|
|
106
108
|
}
|
|
107
109
|
|
|
108
|
-
return
|
|
110
|
+
return value.utc().toISOString();
|
|
109
111
|
})
|
|
110
112
|
|
|
111
|
-
|
|
112
|
-
if (!
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
} else if (
|
|
116
|
-
|
|
113
|
+
function updateFromModel() {
|
|
114
|
+
if (!current.value) {
|
|
115
|
+
date.value = null;
|
|
116
|
+
time.value = '';
|
|
117
|
+
} else if (fieldsType.value === 'time') {
|
|
118
|
+
time.value = current.value;
|
|
117
119
|
} else {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
startTime.value = dayjs(props.valueStart).format('HH:mm:ss')
|
|
120
|
+
const value = dayjs(current.value);
|
|
121
|
+
date.value = value.format(PICKER_DAY_FORMAT);
|
|
122
|
+
time.value = value.format('HH:mm:ss');
|
|
122
123
|
}
|
|
123
124
|
}
|
|
124
125
|
|
|
125
|
-
|
|
126
|
-
datepickerReady = initDatepickers();
|
|
127
|
-
updateFromProps();
|
|
126
|
+
watch(current, updateFromModel, { immediate: true });
|
|
128
127
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
});
|
|
128
|
+
watch(value, () => {
|
|
129
|
+
setValue(value.value);
|
|
132
130
|
})
|
|
133
131
|
|
|
134
|
-
|
|
135
|
-
emit('update:valueStart', start.value)
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
const teleportTarget = useTeleportTarget();
|
|
139
|
-
|
|
140
|
-
async function initDatepickers() {
|
|
141
|
-
const LS_LANG_KEY = `afLanguage`;
|
|
142
|
-
const options = {format: FLEXIBLE_DATEPICKER_FORMAT, language: localStorage.getItem(LS_LANG_KEY)};
|
|
143
|
-
|
|
144
|
-
if (props.autoHide) {
|
|
145
|
-
options.autohide = true;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const { default: Datepicker } = await import(
|
|
149
|
-
'flowbite-datepicker/Datepicker'
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
datepickerObject.value = new Datepicker(datepickerStartEl.value, options);
|
|
153
|
-
// the calendar goes to body and takes only a selector of the document for another container
|
|
154
|
-
if (teleportTarget instanceof HTMLElement) {
|
|
155
|
-
datepickerObject.value.config.container = teleportTarget;
|
|
156
|
-
teleportTarget.appendChild(datepickerObject.value.picker.element);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
addChangeDateListener();
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function addChangeDateListener() {
|
|
163
|
-
datepickerStartEl.value.addEventListener('changeDate', setStartDate)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function removeChangeDateListener() {
|
|
167
|
-
datepickerStartEl.value.removeEventListener('changeDate', setStartDate);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function destroyDatepickerElement() {
|
|
171
|
-
datepickerObject.value.destroy();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function setStartDate(event) {
|
|
175
|
-
startDate.value = event.detail.date
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function formatTime(time) {
|
|
132
|
+
function formatTime(time: string) {
|
|
179
133
|
return time.split(':').map(Number).length === 2 ? time + ':00' : time;
|
|
180
134
|
}
|
|
181
135
|
|
|
182
|
-
function addTimeToDate(time, date) {
|
|
136
|
+
function addTimeToDate(time: string, date: Dayjs) {
|
|
183
137
|
const [hours, minutes, seconds] = time.split(':').map(Number)
|
|
184
138
|
return date.hour(hours).minute(minutes).second(seconds)
|
|
185
139
|
}
|
|
186
140
|
|
|
187
|
-
const toggleTimeInputs = () => {
|
|
188
|
-
showTimeInputs.value = !showTimeInputs.value
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
onBeforeUnmount(() => {
|
|
192
|
-
removeChangeDateListener();
|
|
193
|
-
destroyDatepickerElement();
|
|
194
|
-
});
|
|
195
|
-
|
|
196
141
|
function focus() {
|
|
197
|
-
|
|
142
|
+
(fieldsType.value === 'time' ? timeField : dateField).value!.focus();
|
|
198
143
|
}
|
|
199
144
|
|
|
200
145
|
defineExpose({
|
|
201
146
|
focus,
|
|
202
147
|
});
|
|
203
148
|
</script>
|
|
204
|
-
|
|
205
|
-
<style lang="css" scoped>
|
|
206
|
-
|
|
207
|
-
:global(.datepicker-controls button svg),
|
|
208
|
-
:global(.datepicker-controls button) {
|
|
209
|
-
@apply text-lightDatePickerCalendarText;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
:global( .datepicker-dropdown ),
|
|
213
|
-
:global( .datepicker-picker ) {
|
|
214
|
-
@apply !bg-lightDatePickerCalendarBackground
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
:global(.datepicker-controls button:hover) {
|
|
218
|
-
@apply bg-lightDatePickerCalendarArrowButtonBackgroundHover;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
:global(.datepicker-controls button) {
|
|
222
|
-
@apply ring-lightDatePickerCalendarArrowButtonFocusRing bg-lightDatePickerCalendarArrowButtonBackground;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
:global(.datepicker-controls button:focus) {
|
|
226
|
-
@apply ring-lightDatePickerCalendarArrowButtonFocusRing;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
:global(.days-of-week span) {
|
|
230
|
-
@apply text-lightDatePickerCalendarDaysOfWeekText;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
:global(.datepicker-grid span) {
|
|
234
|
-
@apply text-lightDatePickerCalendarDateButtonText;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
:global(.datepicker-grid span:hover:not(.selected)) {
|
|
238
|
-
@apply bg-lightDatePickerCalendarDateButtonBackgroundHover;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
:global(.datepicker-grid .selected ) {
|
|
242
|
-
@apply text-lightDatePickerCalendarDateActiveButtonText bg-lightDatePickerCalendarDateActiveButtonBackground;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
:global(.dark .datepicker-controls button svg),
|
|
253
|
-
:global(.dark .datepicker-controls button) {
|
|
254
|
-
@apply text-darkDatePickerCalendarMainText;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
:global(.dark .datepicker-dropdown),
|
|
258
|
-
:global(.dark .datepicker-picker) {
|
|
259
|
-
@apply !bg-darkDatePickerCalendarBackground;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
:global(.dark .datepicker-controls button:hover) {
|
|
263
|
-
@apply bg-darkDatePickerCalendarArrowButtonBackgroundHover;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
:global(.dark .datepicker-controls button) {
|
|
267
|
-
@apply ring-darkDatePickerCalendarArrowButtonFocusRing bg-darkDatePickerCalendarArrowButtonBackground;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
:global(.dark .datepicker-controls button) {
|
|
271
|
-
@apply ring-darkDatePickerCalendarArrowButtonFocusRing;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
:global(.dark .days-of-week span) {
|
|
275
|
-
@apply text-darkDatePickerCalendarDaysOfWeekText;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
:global(.dark .datepicker-grid span) {
|
|
279
|
-
@apply text-darkDatePickerCalendarDateButtonText;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
:global(.dark .datepicker-grid span:hover:not(.selected)) {
|
|
283
|
-
@apply bg-darkDatePickerCalendarDateButtonBackgroundHover;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
:global(.dark .datepicker-grid .selected) {
|
|
287
|
-
@apply text-darkDatePickerCalendarDateActiveButtonText
|
|
288
|
-
bg-darkDatePickerCalendarDateActiveButtonBackground;
|
|
289
|
-
}
|
|
290
|
-
</style>
|