@likable-hair/svelte 4.2.4 → 4.3.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/components/composed/buttons/ActivableButton.svelte +25 -7
- package/dist/components/composed/common/HeadersDrawer.svelte +66 -28
- package/dist/components/composed/common/HeadersDrawer.svelte.d.ts +22 -12
- package/dist/components/composed/common/MenuOrDrawer.svelte +40 -12
- package/dist/components/composed/common/MenuOrDrawerOptions.svelte +51 -27
- package/dist/components/composed/common/MenuOrDrawerOptions.svelte.d.ts +15 -10
- package/dist/components/composed/common/QuickActions.css +5 -5
- package/dist/components/composed/common/QuickActions.svelte +76 -33
- package/dist/components/composed/common/ToolTip.svelte +51 -32
- package/dist/components/composed/dashboard/DashboardShaper.svelte +280 -147
- package/dist/components/composed/dashboard/DashboardShaper.svelte.d.ts +54 -45
- package/dist/components/composed/forms/AsyncAutocomplete.svelte +81 -30
- package/dist/components/composed/forms/AsyncAutocomplete.svelte.d.ts +17 -5
- package/dist/components/composed/forms/AvatarDropdown.svelte +146 -70
- package/dist/components/composed/forms/AvatarDropdown.svelte.d.ts +27 -22
- package/dist/components/composed/forms/ConfirmOrCancelButtons.svelte +65 -19
- package/dist/components/composed/forms/CountriesAutocomplete.svelte +33 -4
- package/dist/components/composed/forms/DatePickerTextField.svelte +266 -161
- package/dist/components/composed/forms/Dropdown.svelte +89 -22
- package/dist/components/composed/forms/Dropdown.svelte.d.ts +18 -13
- package/dist/components/composed/forms/IconsDropdown.svelte +85 -40
- package/dist/components/composed/forms/IconsDropdown.svelte.d.ts +15 -8
- package/dist/components/composed/forms/LabelAndSelect.svelte +46 -5
- package/dist/components/composed/forms/LabelAndTextField.svelte +56 -3
- package/dist/components/composed/forms/PeriodPicker.svelte +38 -18
- package/dist/components/composed/forms/PeriodPicker.svelte.d.ts +32 -7
- package/dist/components/composed/forms/PeriodSelector.svelte +427 -312
- package/dist/components/composed/forms/PeriodSelector.svelte.d.ts +20 -13
- package/dist/components/composed/forms/ToggleList.svelte +71 -37
- package/dist/components/composed/forms/ToggleList.svelte.d.ts +14 -7
- package/dist/components/composed/forms/YearPickerTextField.svelte +154 -82
- package/dist/components/composed/list/DynamicTable.svelte +1377 -808
- package/dist/components/composed/list/DynamicTable.svelte.d.ts +85 -70
- package/dist/components/composed/list/EnhancedPaginatedTable.svelte +75 -32
- package/dist/components/composed/list/EnhancedPaginatedTable.svelte.d.ts +16 -6
- package/dist/components/composed/list/PaginatedTable.svelte +325 -120
- package/dist/components/composed/list/PaginatedTable.svelte.d.ts +26 -22
- package/dist/components/composed/progress/HorizontalStackedProgress.svelte +67 -29
- package/dist/components/composed/search/DynamicFilters.svelte +126 -91
- package/dist/components/composed/search/FilterEditor.svelte +178 -115
- package/dist/components/composed/search/Filters.svelte +441 -301
- package/dist/components/composed/search/GlobalSearchTextField.svelte +102 -42
- package/dist/components/composed/search/GlobalSearchTextField.svelte.d.ts +23 -20
- package/dist/components/composed/search/MobileFilterEditor.svelte +174 -120
- package/dist/components/composed/search/QuickFilters.svelte +133 -23
- package/dist/components/composed/search/SearchBar.svelte +42 -3
- package/dist/components/composed/search/SearchResults.svelte +48 -5
- package/dist/components/composed/search/SearchResults.svelte.d.ts +17 -17
- package/dist/components/layouts/CollapsibleSideBarLayout.svelte +100 -24
- package/dist/components/layouts/StableDividedSideBarLayout.svelte +74 -24
- package/dist/components/layouts/UnstableDividedSideBarLayout.svelte +140 -57
- package/dist/components/simple/buttons/Button.svelte +86 -36
- package/dist/components/simple/buttons/LinkButton.svelte +81 -25
- package/dist/components/simple/charts/BarChart.svelte +137 -105
- package/dist/components/simple/charts/LineChart.svelte +124 -92
- package/dist/components/simple/charts/PieChart.svelte +51 -23
- package/dist/components/simple/common/CollapsibleDivider.svelte +58 -26
- package/dist/components/simple/common/Divider.svelte +2 -1
- package/dist/components/simple/common/InfiniteScroll.svelte +60 -34
- package/dist/components/simple/common/MediaQuery.svelte +28 -3
- package/dist/components/simple/common/Menu.svelte +516 -390
- package/dist/components/simple/common/NoData.svelte +18 -4
- package/dist/components/simple/common/VerticalDraggableList.svelte +52 -26
- package/dist/components/simple/common/VerticalDraggableList.svelte.d.ts +20 -9
- package/dist/components/simple/dashboards/DashboardGridShaper.svelte +28 -22
- package/dist/components/simple/dates/Calendar.svelte +142 -72
- package/dist/components/simple/dates/DatePicker.svelte +138 -71
- package/dist/components/simple/dates/MonthSelector.svelte +49 -13
- package/dist/components/simple/dates/YearSelector.svelte +73 -30
- package/dist/components/simple/dialogs/Dialog.svelte +109 -59
- package/dist/components/simple/forms/Autocomplete.css +3 -0
- package/dist/components/simple/forms/Autocomplete.svelte +366 -164
- package/dist/components/simple/forms/Autocomplete.svelte.d.ts +31 -19
- package/dist/components/simple/forms/Checkbox.svelte +57 -29
- package/dist/components/simple/forms/FileInput.svelte +103 -58
- package/dist/components/simple/forms/FileInputList.svelte +115 -51
- package/dist/components/simple/forms/RadioButton.svelte +36 -3
- package/dist/components/simple/forms/Select.svelte +30 -3
- package/dist/components/simple/forms/SimpleTextField.svelte +94 -4
- package/dist/components/simple/forms/Switch.svelte +33 -11
- package/dist/components/simple/forms/Textarea.svelte +22 -5
- package/dist/components/simple/forms/VerticalSwitch.svelte +19 -2
- package/dist/components/simple/forms/VerticalTextSwitch.svelte +35 -3
- package/dist/components/simple/lists/BoxList.svelte +42 -11
- package/dist/components/simple/lists/ColorInvertedSelector.svelte +83 -25
- package/dist/components/simple/lists/HierarchyMenu.svelte +55 -20
- package/dist/components/simple/lists/Paginator.svelte +53 -34
- package/dist/components/simple/lists/SelectableMenuList.svelte +52 -16
- package/dist/components/simple/lists/SelectableVerticalList.svelte +169 -85
- package/dist/components/simple/lists/SelectableVerticalList.svelte.d.ts +21 -14
- package/dist/components/simple/lists/SidebarMenuList.svelte +127 -79
- package/dist/components/simple/lists/SimpleTable.svelte +449 -239
- package/dist/components/simple/lists/SimpleTable.svelte.d.ts +31 -22
- package/dist/components/simple/loaders/CircularLoader.css +1 -1
- package/dist/components/simple/loaders/CircularLoader.svelte +11 -3
- package/dist/components/simple/loaders/Skeleton.svelte +3 -2
- package/dist/components/simple/media/Avatar.svelte +35 -15
- package/dist/components/simple/media/DescriptiveAvatar.svelte +30 -4
- package/dist/components/simple/media/FlagIcon.svelte +13 -3
- package/dist/components/simple/media/Icon.svelte +21 -6
- package/dist/components/simple/navigation/Breadcrumb.svelte +41 -9
- package/dist/components/simple/navigation/Chip.css +1 -1
- package/dist/components/simple/navigation/Chip.svelte +65 -36
- package/dist/components/simple/navigation/Drawer.svelte +132 -71
- package/dist/components/simple/navigation/HeaderMenu.svelte +69 -25
- package/dist/components/simple/navigation/Navigator.svelte +45 -11
- package/dist/components/simple/navigation/TabSwitcher.svelte +60 -19
- package/dist/components/simple/notifiers/AlertBanner.svelte +59 -11
- package/dist/components/simple/progress/ProgressBar.svelte +26 -10
- package/dist/components/simple/timeline/SimpleTimeLine.svelte +52 -5
- package/dist/components/simple/timeline/SimpleTimeLine.svelte.d.ts +16 -9
- package/dist/components/simple/typography/Code.svelte +41 -12
- package/dist/stores/layouts/unstableSidebarOpened.d.ts +1 -1
- package/dist/stores/layouts/unstableSidebarOpened.js +1 -1
- package/dist/stores/theme.js +2 -2
- package/dist/utils/filters/builder.d.ts +2 -2
- package/dist/utils/filters/builder.js +7 -7
- package/dist/utils/filters/modifiers/where.d.ts +1 -1
- package/dist/utils/teleporter.js +4 -4
- package/package.json +39 -33
|
@@ -1,372 +1,487 @@
|
|
|
1
|
-
<script module lang="ts">
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
type RollingMeasurementUnit = 'days' | 'weeks' | 'months' | 'years';
|
|
3
|
+
type RollingDirection = 'last' | 'next';
|
|
4
|
+
|
|
5
|
+
type PickerSelectValues = {
|
|
6
|
+
from?: Date,
|
|
7
|
+
to?: Date
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type RollingSelectValues = {
|
|
11
|
+
numberOfUnits?: number,
|
|
12
|
+
measurementUnit?: RollingMeasurementUnit
|
|
13
|
+
direction?: RollingDirection
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type TimespanMap<T extends string> = {
|
|
17
|
+
quick: T | undefined
|
|
18
|
+
rolling: RollingSelectValues
|
|
19
|
+
picker: PickerSelectValues
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type TimespanSettings<T extends string = string> = {
|
|
23
|
+
[K in keyof TimespanMap<T>]: {
|
|
24
|
+
method?: K
|
|
25
|
+
values?: TimespanMap<T>[K]
|
|
26
|
+
}
|
|
27
|
+
}[keyof TimespanMap<T>]
|
|
28
|
+
|
|
29
|
+
export const defaultQuickOptions = {
|
|
2
30
|
'it': [
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
31
|
+
{ value: 'today', label: 'Oggi' },
|
|
32
|
+
{ value: 'this-week', label: 'Questa settimana' },
|
|
33
|
+
{ value: 'this-month', label: 'Questo mese' },
|
|
34
|
+
{ value: 'last-3month', label: 'Ultimi 3 mesi' },
|
|
35
|
+
{ value: 'last-6month', label: 'Ultimi 6 mesi' },
|
|
36
|
+
{ value: 'this-year', label: "Quest'anno" },
|
|
37
|
+
{ value: 'total', label: 'Sempre' },
|
|
10
38
|
],
|
|
11
39
|
'en': [
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
40
|
+
{ value: 'today', label: 'Today' },
|
|
41
|
+
{ value: 'this-week', label: 'This week' },
|
|
42
|
+
{ value: 'this-month', label: 'This month' },
|
|
43
|
+
{ value: 'last-3month', label: 'Last 3 months' },
|
|
44
|
+
{ value: 'last-6month', label: 'Last 6 months' },
|
|
45
|
+
{ value: 'this-year', label: 'This year' },
|
|
46
|
+
{ value: 'total', label: 'All time' },
|
|
19
47
|
],
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function getPeriodLabel<T extends string>(
|
|
51
|
+
settings: TimespanSettings<T> | undefined,
|
|
52
|
+
lang: 'en' | 'it' = 'en',
|
|
53
|
+
quickOptions: { value: string | T; label: string }[] = defaultQuickOptions[lang]
|
|
54
|
+
): string {
|
|
55
|
+
if (!settings?.method) return lang == 'en' ? 'Select range mode' : 'Seleziona una modalità';
|
|
56
|
+
|
|
24
57
|
if (settings.method === 'picker') {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return `${lang == 'en' ? 'Until' : 'Fino al'} ${toStr}`;
|
|
33
|
-
return lang == 'en' ? 'Select dates' : 'Seleziona date';
|
|
58
|
+
let fromStr = settings.values?.from ? new Date(settings.values.from).toLocaleDateString(lang) : '';
|
|
59
|
+
let toStr = settings.values?.to ? new Date(settings.values.to).toLocaleDateString(lang) : '';
|
|
60
|
+
|
|
61
|
+
if (fromStr && toStr) return `${lang == 'en' ? 'From' : 'Dal'} ${fromStr} ${lang == 'en' ? 'to' : 'al'} ${toStr}`;
|
|
62
|
+
if (fromStr) return `${lang == 'en' ? 'From' : 'Dal'} ${fromStr}`;
|
|
63
|
+
if (toStr) return `${lang == 'en' ? 'Until' : 'Fino al'} ${toStr}`;
|
|
64
|
+
return lang == 'en' ? 'Select dates' : 'Seleziona date';
|
|
34
65
|
}
|
|
66
|
+
|
|
35
67
|
if (settings.method === 'quick') {
|
|
36
|
-
|
|
68
|
+
return quickOptions.find(o => o.value === settings.values)?.label || (lang == 'en' ? 'Select a period' : 'Seleziona un periodo');
|
|
37
69
|
}
|
|
70
|
+
|
|
38
71
|
if (settings.method === 'rolling') {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return `${dirLabel} ${num} ${unitLabel}`;
|
|
72
|
+
const num = settings.values?.numberOfUnits;
|
|
73
|
+
const unit = settings.values?.measurementUnit;
|
|
74
|
+
const dir = settings.values?.direction ?? 'last';
|
|
75
|
+
|
|
76
|
+
if (!unit || !num) return lang == 'en' ? 'Configure rolling window' : 'Configura periodo';
|
|
77
|
+
|
|
78
|
+
let unitLabel = '';
|
|
79
|
+
if (unit === 'days') unitLabel = lang == 'en' ? 'Days' : 'Giorni';
|
|
80
|
+
if (unit === 'weeks') unitLabel = lang == 'en' ? 'Weeks' : 'Settimane';
|
|
81
|
+
if (unit === 'months') unitLabel = lang == 'en' ? 'Months' : 'Mesi';
|
|
82
|
+
if (unit === 'years') unitLabel = lang == 'en' ? 'Years' : 'Anni';
|
|
83
|
+
|
|
84
|
+
const dirLabel = dir === 'next'
|
|
85
|
+
? (lang == 'en' ? 'Next' : unit == 'weeks' ? 'Prossime' : 'Prossimi')
|
|
86
|
+
: (lang == 'en' ? 'Last' : unit == 'weeks' ? 'Ultime' : 'Ultimi');
|
|
87
|
+
|
|
88
|
+
return `${dirLabel} ${num} ${unitLabel}`;
|
|
57
89
|
}
|
|
90
|
+
|
|
58
91
|
return lang == 'en' ? 'Select range mode' : 'Seleziona una modalità';
|
|
59
|
-
}
|
|
92
|
+
}
|
|
60
93
|
</script>
|
|
61
94
|
|
|
62
|
-
<script lang="ts" generics="T extends string = string">
|
|
63
|
-
import
|
|
64
|
-
import
|
|
65
|
-
import
|
|
66
|
-
import
|
|
67
|
-
import
|
|
68
|
-
import
|
|
69
|
-
import
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
95
|
+
<script lang="ts" generics="T extends string = string">
|
|
96
|
+
import Dropdown from "./Dropdown.svelte"
|
|
97
|
+
import SimpleTextField from "../../simple/forms/SimpleTextField.svelte"
|
|
98
|
+
import type { DateStat } from "../../simple/dates/utils";
|
|
99
|
+
import SelectableVerticalList from "../../simple/lists/SelectableVerticalList.svelte";
|
|
100
|
+
import DatePicker from "../../simple/dates/DatePicker.svelte";
|
|
101
|
+
import { fly } from "svelte/transition";
|
|
102
|
+
import Icon from "../../simple/media/Icon.svelte";
|
|
103
|
+
import Chip from "../../simple/navigation/Chip.svelte";
|
|
104
|
+
import { tick } from "svelte";
|
|
105
|
+
|
|
106
|
+
interface Props {
|
|
107
|
+
timespanSettings?: TimespanSettings<T>
|
|
108
|
+
quickSelectOptions?: {
|
|
109
|
+
value: T
|
|
110
|
+
label: string
|
|
111
|
+
}[]
|
|
112
|
+
valid?: boolean
|
|
113
|
+
mode?: 'default' | 'datepicker'
|
|
114
|
+
lang?: 'it' | 'en'
|
|
115
|
+
locale?: 'it' | 'en'
|
|
116
|
+
showTimeRangeLabel?: boolean
|
|
117
|
+
isSelectionMode?: boolean
|
|
118
|
+
onchange?: (event: {
|
|
119
|
+
timespanSettings?: TimespanSettings<T>
|
|
120
|
+
}) => void
|
|
121
|
+
quickRangeConvertor?: typeof getDatesFromQuick
|
|
122
|
+
setTimespanLabel?: (params: {
|
|
123
|
+
timespanSettings: typeof timespanSettings
|
|
124
|
+
}) => string
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
let {
|
|
128
|
+
timespanSettings = $bindable(),
|
|
129
|
+
lang = 'en',
|
|
130
|
+
quickSelectOptions = defaultQuickOptions[lang] as { value: T; label: string }[],
|
|
131
|
+
valid = $bindable(),
|
|
132
|
+
mode = 'default',
|
|
133
|
+
locale = lang,
|
|
134
|
+
showTimeRangeLabel = false,
|
|
135
|
+
isSelectionMode = $bindable(),
|
|
136
|
+
onchange,
|
|
137
|
+
quickRangeConvertor,
|
|
138
|
+
setTimespanLabel,
|
|
139
|
+
}: Props = $props()
|
|
140
|
+
|
|
141
|
+
if (!timespanSettings) {
|
|
142
|
+
timespanSettings = {}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (isSelectionMode == undefined) {
|
|
146
|
+
isSelectionMode = true
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
$effect(() => {
|
|
150
|
+
if(localValid != valid) valid = localValid
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
let timeRangeLabel = $derived(setTimespanLabel ? setTimespanLabel({ timespanSettings }) : getPeriodLabel(timespanSettings, lang, quickSelectOptions));
|
|
154
|
+
|
|
155
|
+
let rollingAutocompleteValues: {
|
|
156
|
+
value: RollingMeasurementUnit,
|
|
157
|
+
label: string
|
|
158
|
+
}[] = [
|
|
159
|
+
{ value: 'days', label: lang == 'en' ? 'Days' : 'Giorni' },
|
|
160
|
+
{ value: 'weeks', label: lang == 'en' ? 'Weeks' : 'Settimane' },
|
|
161
|
+
{ value: 'months', label: lang == 'en' ? 'Months' : 'Mesi' },
|
|
162
|
+
{ value: 'years', label: lang == 'en' ? 'Years' : 'Anni' },
|
|
163
|
+
],
|
|
164
|
+
rollingNumberOfUnits = $state(timespanSettings?.method === 'rolling'
|
|
165
|
+
? timespanSettings.values?.numberOfUnits
|
|
166
|
+
: 0
|
|
167
|
+
),
|
|
168
|
+
rollingMeasurementOfUnit = $state(timespanSettings?.method === 'rolling' && timespanSettings.values?.measurementUnit
|
|
169
|
+
//@ts-ignore
|
|
170
|
+
? rollingAutocompleteValues.find(v => v.value == timespanSettings!.values.measurementUnit)
|
|
171
|
+
: undefined
|
|
172
|
+
),
|
|
173
|
+
rollingDirectionOptions: {
|
|
174
|
+
value: RollingDirection,
|
|
175
|
+
label: string
|
|
176
|
+
}[] = $derived([
|
|
177
|
+
{ value: 'last', label: lang == 'en' ? 'Last' : rollingMeasurementOfUnit?.value == 'weeks' ? 'Ultime' : 'Ultimi' },
|
|
178
|
+
{ value: 'next', label: lang == 'en' ? 'Next' : rollingMeasurementOfUnit?.value == 'weeks' ? 'Prossime' : 'Prossimi' },
|
|
179
|
+
]),
|
|
180
|
+
rollingDirection = $state<RollingDirection>(
|
|
181
|
+
timespanSettings?.method === 'rolling'
|
|
182
|
+
? timespanSettings.values?.direction ?? 'last'
|
|
183
|
+
: 'last'
|
|
184
|
+
),
|
|
185
|
+
pickerFromValue = $derived(timespanSettings?.method === 'picker' && timespanSettings.values?.from
|
|
186
|
+
? new Date(timespanSettings.values.from)
|
|
187
|
+
: undefined
|
|
188
|
+
),
|
|
189
|
+
pickerToValue = $derived(timespanSettings?.method === 'picker' && timespanSettings.values?.to
|
|
190
|
+
? new Date(timespanSettings.values.to)
|
|
191
|
+
: undefined
|
|
192
|
+
),
|
|
193
|
+
quickSelectCustomOption = {
|
|
194
|
+
title: lang == 'en' ? 'Custom Range' : 'Intervallo personalizzato',
|
|
195
|
+
name: 'picker',
|
|
196
|
+
},
|
|
197
|
+
quickSelectRollingOption = {
|
|
198
|
+
title: lang == 'en' ? 'Rolling Window' : 'Periodo dinamico',
|
|
199
|
+
name: 'rolling',
|
|
200
|
+
},
|
|
201
|
+
selectedOption: string | undefined = $state(timespanSettings?.method),
|
|
202
|
+
quickSelectValue = $derived(
|
|
203
|
+
mode == 'datepicker'
|
|
204
|
+
? selectedOption == 'picker'
|
|
205
|
+
? [quickSelectCustomOption]
|
|
206
|
+
: selectedOption == 'rolling'
|
|
111
207
|
? [quickSelectRollingOption]
|
|
112
208
|
: [{
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}]
|
|
116
|
-
: timespanSettings?.method === 'quick' && timespanSettings.values
|
|
117
|
-
? [{
|
|
118
|
-
name: timespanSettings.values,
|
|
119
|
-
title: quickSelectOptions.find((item) => item.value === timespanSettings.values)?.label,
|
|
209
|
+
name: quickSelectOptions.find(o => o.value == selectedOption)?.value,
|
|
210
|
+
title: quickSelectOptions.find(o => o.value == selectedOption)?.label,
|
|
120
211
|
}]
|
|
121
|
-
: timespanSettings?.method
|
|
212
|
+
: timespanSettings?.method === 'quick' && timespanSettings.values
|
|
213
|
+
? [{
|
|
214
|
+
name: timespanSettings.values,
|
|
215
|
+
title: quickSelectOptions.find((item) => item.value === timespanSettings!.values)?.label,
|
|
216
|
+
}]
|
|
217
|
+
: timespanSettings?.method == 'picker'
|
|
122
218
|
? [quickSelectCustomOption]
|
|
123
219
|
: timespanSettings?.method == 'rolling'
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return !!rollingNumberOfUnits && !!rollingMeasurementOfUnit
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}),
|
|
137
|
-
|
|
220
|
+
? [quickSelectRollingOption]
|
|
221
|
+
: []
|
|
222
|
+
),
|
|
223
|
+
localValid = $derived.by(() => {
|
|
224
|
+
if (timespanSettings?.method == 'picker') {
|
|
225
|
+
return !!timespanSettings.values?.from || !!timespanSettings.values?.to
|
|
226
|
+
} else if (timespanSettings?.method == 'quick') {
|
|
227
|
+
return !!timespanSettings.values
|
|
228
|
+
} else if (timespanSettings?.method == 'rolling') {
|
|
229
|
+
return !!rollingNumberOfUnits && !!rollingMeasurementOfUnit
|
|
230
|
+
}
|
|
231
|
+
return false
|
|
232
|
+
}),
|
|
233
|
+
activeSlot: 'from' | 'to' = $state('from')
|
|
234
|
+
|
|
235
|
+
function getDatesFromRolling(
|
|
236
|
+
num: number,
|
|
237
|
+
unit: RollingMeasurementUnit,
|
|
238
|
+
direction: RollingDirection = 'last'
|
|
239
|
+
): { from: Date, to: Date } {
|
|
138
240
|
const from = new Date();
|
|
139
241
|
const to = new Date();
|
|
242
|
+
|
|
140
243
|
if (direction === 'last') {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if (unit === 'days')
|
|
155
|
-
to.setDate(to.getDate() + num);
|
|
156
|
-
if (unit === 'weeks')
|
|
157
|
-
to.setDate(to.getDate() + (num * 7));
|
|
158
|
-
if (unit === 'months')
|
|
159
|
-
to.setMonth(to.getMonth() + num);
|
|
160
|
-
if (unit === 'years')
|
|
161
|
-
to.setFullYear(to.getFullYear() + num);
|
|
162
|
-
to.setHours(23, 59, 59, 999);
|
|
244
|
+
to.setHours(23, 59, 59, 999);
|
|
245
|
+
if (unit === 'days') from.setDate(from.getDate() - num);
|
|
246
|
+
if (unit === 'weeks') from.setDate(from.getDate() - (num * 7));
|
|
247
|
+
if (unit === 'months') from.setMonth(from.getMonth() - num);
|
|
248
|
+
if (unit === 'years') from.setFullYear(from.getFullYear() - num);
|
|
249
|
+
from.setHours(0, 0, 0, 0);
|
|
250
|
+
} else {
|
|
251
|
+
from.setHours(0, 0, 0, 0);
|
|
252
|
+
if (unit === 'days') to.setDate(to.getDate() + num);
|
|
253
|
+
if (unit === 'weeks') to.setDate(to.getDate() + (num * 7));
|
|
254
|
+
if (unit === 'months') to.setMonth(to.getMonth() + num);
|
|
255
|
+
if (unit === 'years') to.setFullYear(to.getFullYear() + num);
|
|
256
|
+
to.setHours(23, 59, 59, 999);
|
|
163
257
|
}
|
|
258
|
+
|
|
164
259
|
return { from, to };
|
|
165
|
-
}
|
|
166
|
-
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function getDatesFromQuick(value: string): { from?: Date, to: Date } | undefined {
|
|
167
263
|
if (!!quickRangeConvertor) {
|
|
168
|
-
|
|
264
|
+
return quickRangeConvertor(value)
|
|
169
265
|
}
|
|
266
|
+
|
|
170
267
|
let now = new Date();
|
|
171
|
-
let from = new Date(now);
|
|
268
|
+
let from: Date | undefined = new Date(now);
|
|
172
269
|
let to = new Date(now);
|
|
270
|
+
|
|
173
271
|
to.setHours(23, 59, 59, 999);
|
|
174
272
|
from.setHours(0, 0, 0, 0);
|
|
273
|
+
|
|
175
274
|
if (value === 'today') {
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
else if (value === '
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
else if (value === 'this-year') {
|
|
192
|
-
from.setMonth(0, 1);
|
|
193
|
-
}
|
|
194
|
-
else if (value === 'total') {
|
|
195
|
-
from = undefined;
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
return;
|
|
275
|
+
} else if (value === 'this-week') {
|
|
276
|
+
const day = now.getDay() || 7;
|
|
277
|
+
if (day !== 1) from.setHours(-24 * (day - 1));
|
|
278
|
+
} else if (value === 'this-month') {
|
|
279
|
+
from.setDate(1);
|
|
280
|
+
} else if (value === 'last-3month') {
|
|
281
|
+
from.setMonth(from.getMonth() - 3);
|
|
282
|
+
} else if (value === 'last-6month') {
|
|
283
|
+
from.setMonth(from.getMonth() - 6);
|
|
284
|
+
} else if (value === 'this-year') {
|
|
285
|
+
from.setMonth(0, 1);
|
|
286
|
+
} else if (value === 'total') {
|
|
287
|
+
from = undefined
|
|
288
|
+
} else {
|
|
289
|
+
return
|
|
199
290
|
}
|
|
200
291
|
return { from, to };
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
let
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if (fromStr)
|
|
208
|
-
|
|
209
|
-
if (toStr)
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
async function handleRollingInput(value, direction) {
|
|
214
|
-
rollingNumberOfUnits = Math.max(Number(rollingNumberOfUnits), 0)
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function formatDateLabel(from?: Date, to?: Date): string {
|
|
295
|
+
let fromStr = from ? from.toLocaleDateString(locale) : ''
|
|
296
|
+
let toStr = to ? to.toLocaleDateString(locale) : ''
|
|
297
|
+
|
|
298
|
+
if (fromStr && toStr) return `${lang == 'en' ? 'From' : 'Dal'} ${fromStr} ${lang == 'en' ? 'to' : 'al'} ${toStr}`
|
|
299
|
+
if (fromStr) return `${lang == 'en' ? 'From' : 'Dal'} ${fromStr}`
|
|
300
|
+
if (toStr) return `${lang == 'en' ? 'Until' : 'Fino al'} ${toStr}`
|
|
301
|
+
return lang == 'en' ? 'Select dates' : 'Seleziona date'
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
async function handleRollingInput(value?: string, direction?: string) {
|
|
305
|
+
rollingNumberOfUnits = Math.max(Number(rollingNumberOfUnits), 0)
|
|
215
306
|
if (value) {
|
|
216
|
-
|
|
307
|
+
rollingMeasurementOfUnit = rollingAutocompleteValues.find(v => v.value == value)
|
|
217
308
|
}
|
|
218
309
|
if (direction == 'next' || direction == 'last') {
|
|
219
|
-
|
|
310
|
+
rollingDirection = direction;
|
|
220
311
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
312
|
+
|
|
313
|
+
if(mode == 'datepicker' && rollingMeasurementOfUnit && rollingNumberOfUnits) {
|
|
314
|
+
const { from, to } = getDatesFromRolling(rollingNumberOfUnits, rollingMeasurementOfUnit.value, rollingDirection);
|
|
315
|
+
|
|
316
|
+
timespanSettings = {
|
|
317
|
+
method: 'picker',
|
|
318
|
+
values: {
|
|
319
|
+
from,
|
|
320
|
+
to,
|
|
321
|
+
}
|
|
322
|
+
}
|
|
230
323
|
}
|
|
231
324
|
else if (timespanSettings?.method == 'rolling') {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
325
|
+
timespanSettings = {
|
|
326
|
+
method: 'rolling',
|
|
327
|
+
values: {
|
|
328
|
+
numberOfUnits: rollingNumberOfUnits,
|
|
329
|
+
measurementUnit: rollingMeasurementOfUnit?.value,
|
|
330
|
+
direction: rollingDirection
|
|
331
|
+
}
|
|
332
|
+
}
|
|
240
333
|
}
|
|
241
|
-
|
|
334
|
+
|
|
335
|
+
await tick()
|
|
336
|
+
|
|
242
337
|
onchange?.({
|
|
243
|
-
|
|
244
|
-
})
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
338
|
+
timespanSettings
|
|
339
|
+
})
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
async function handleQuickChange(value?: string | number) {
|
|
343
|
+
if(timespanSettings) {
|
|
344
|
+
if(value == 'picker') {
|
|
345
|
+
if(selectedOption != 'picker'){
|
|
346
|
+
activeSlot = 'from'
|
|
347
|
+
|
|
348
|
+
timespanSettings = {
|
|
349
|
+
method: 'picker',
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
isSelectionMode = false
|
|
354
|
+
}
|
|
355
|
+
else if (value == 'rolling') {
|
|
356
|
+
if(selectedOption != 'rolling'){
|
|
357
|
+
rollingNumberOfUnits = 0
|
|
358
|
+
rollingMeasurementOfUnit = undefined
|
|
359
|
+
|
|
360
|
+
timespanSettings = {
|
|
361
|
+
method: 'rolling'
|
|
362
|
+
}
|
|
256
363
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
364
|
+
|
|
365
|
+
isSelectionMode = false
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
let foundValue = quickSelectOptions.find(o => o.value == value)?.value
|
|
369
|
+
|
|
370
|
+
if (mode === 'datepicker' && foundValue) {
|
|
371
|
+
const dates = getDatesFromQuick(foundValue);
|
|
372
|
+
if (dates) {
|
|
373
|
+
timespanSettings = {
|
|
374
|
+
method: 'picker',
|
|
375
|
+
values: dates
|
|
264
376
|
}
|
|
265
|
-
|
|
377
|
+
}
|
|
266
378
|
}
|
|
267
379
|
else {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
timespanSettings = {
|
|
273
|
-
method: 'picker',
|
|
274
|
-
values: dates
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
else {
|
|
279
|
-
timespanSettings = {
|
|
280
|
-
method: 'quick',
|
|
281
|
-
values: foundValue
|
|
282
|
-
};
|
|
283
|
-
}
|
|
380
|
+
timespanSettings = {
|
|
381
|
+
method: 'quick',
|
|
382
|
+
values: foundValue
|
|
383
|
+
}
|
|
284
384
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
385
|
+
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
await tick()
|
|
389
|
+
|
|
390
|
+
selectedOption = value?.toString()
|
|
391
|
+
onchange?.({
|
|
392
|
+
timespanSettings
|
|
393
|
+
})
|
|
290
394
|
}
|
|
291
|
-
}
|
|
292
|
-
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
async function handleSlotToggle(slot: 'from' | 'to') {
|
|
293
398
|
activeSlot = slot;
|
|
399
|
+
|
|
294
400
|
if (timespanSettings?.method === 'picker' && timespanSettings.values) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
401
|
+
const { from, to } = timespanSettings.values;
|
|
402
|
+
const hasFrom = !!from;
|
|
403
|
+
const hasTo = !!to;
|
|
404
|
+
|
|
405
|
+
if (hasFrom && !hasTo && slot === 'to') {
|
|
406
|
+
timespanSettings.values = { from: undefined, to: from };
|
|
407
|
+
}
|
|
408
|
+
else if (!hasFrom && hasTo && slot === 'from') {
|
|
409
|
+
timespanSettings.values = { from: to, to: undefined };
|
|
410
|
+
}
|
|
304
411
|
}
|
|
305
|
-
|
|
412
|
+
|
|
413
|
+
await tick()
|
|
414
|
+
|
|
306
415
|
onchange?.({
|
|
307
|
-
|
|
416
|
+
timespanSettings
|
|
308
417
|
});
|
|
309
|
-
}
|
|
310
|
-
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
async function handleDatePickerDayClick(dateStat: DateStat) {
|
|
311
421
|
const clickedDate = new Date(dateStat.year, dateStat.month, dateStat.dayOfMonth);
|
|
422
|
+
|
|
312
423
|
if (timespanSettings) {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
};
|
|
424
|
+
if(timespanSettings.method != 'picker') {
|
|
425
|
+
timespanSettings = {
|
|
426
|
+
method: 'picker'
|
|
317
427
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
let nextFrom = timespanSettings.values?.from ? new Date(timespanSettings.values.from) : undefined;
|
|
431
|
+
let nextTo = timespanSettings.values?.to ? new Date(timespanSettings.values.to) : undefined;
|
|
432
|
+
|
|
433
|
+
if (activeSlot == 'from') {
|
|
434
|
+
if (!nextFrom) {
|
|
435
|
+
nextFrom = clickedDate;
|
|
436
|
+
} else if (!nextTo) {
|
|
437
|
+
nextTo = clickedDate;
|
|
438
|
+
|
|
439
|
+
if (nextFrom > nextTo) {
|
|
440
|
+
const temp = nextFrom;
|
|
441
|
+
nextFrom = nextTo;
|
|
442
|
+
nextTo = temp;
|
|
443
|
+
}
|
|
444
|
+
} else {
|
|
445
|
+
nextFrom = clickedDate
|
|
446
|
+
nextTo = undefined
|
|
336
447
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}
|
|
448
|
+
}
|
|
449
|
+
else {
|
|
450
|
+
if (!nextTo) {
|
|
451
|
+
nextTo = clickedDate;
|
|
452
|
+
} else if (!nextFrom) {
|
|
453
|
+
nextFrom = clickedDate;
|
|
454
|
+
|
|
455
|
+
if (nextFrom > nextTo) {
|
|
456
|
+
const temp = nextFrom;
|
|
457
|
+
nextFrom = nextTo;
|
|
458
|
+
nextTo = temp;
|
|
459
|
+
}
|
|
460
|
+
} else {
|
|
461
|
+
nextTo = clickedDate
|
|
462
|
+
nextFrom = undefined
|
|
353
463
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
timespanSettings = {
|
|
467
|
+
method: 'picker',
|
|
468
|
+
values: {
|
|
469
|
+
from: nextFrom,
|
|
470
|
+
to: nextTo
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
await tick()
|
|
475
|
+
|
|
476
|
+
onchange?.({
|
|
477
|
+
timespanSettings
|
|
478
|
+
});
|
|
365
479
|
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
function handleBack() {
|
|
483
|
+
isSelectionMode = true
|
|
484
|
+
}
|
|
370
485
|
</script>
|
|
371
486
|
|
|
372
487
|
<div class="period-selector-container">
|