orio-ui 1.23.3 → 1.27.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/README.md +5 -5
- package/dist/module.json +1 -1
- package/dist/runtime/components/Button.d.vue.ts +3 -2
- package/dist/runtime/components/Button.vue +19 -11
- package/dist/runtime/components/Button.vue.d.ts +3 -2
- package/dist/runtime/components/Calendar.USAGE.md +51 -0
- package/dist/runtime/components/Calendar.d.vue.ts +33 -0
- package/dist/runtime/components/Calendar.vue +418 -0
- package/dist/runtime/components/Calendar.vue.d.ts +33 -0
- package/dist/runtime/components/Canvas/USAGE.md +65 -0
- package/dist/runtime/components/CheckBox.vue +9 -3
- package/dist/runtime/components/CheckboxGroup.vue +7 -1
- package/dist/runtime/components/ControlElement.USAGE.md +69 -0
- package/dist/runtime/components/ControlElement.d.vue.ts +42 -27
- package/dist/runtime/components/ControlElement.vue +28 -9
- package/dist/runtime/components/ControlElement.vue.d.ts +42 -27
- package/dist/runtime/components/Form.d.vue.ts +1 -1
- package/dist/runtime/components/Form.vue.d.ts +1 -1
- package/dist/runtime/components/Input.USAGE.md +49 -0
- package/dist/runtime/components/Input.vue +13 -3
- package/dist/runtime/components/Modal.USAGE.md +64 -0
- package/dist/runtime/components/NavButton.d.vue.ts +0 -1
- package/dist/runtime/components/NavButton.vue +9 -5
- package/dist/runtime/components/NavButton.vue.d.ts +0 -1
- package/dist/runtime/components/NumberInput/Horizontal.vue +7 -2
- package/dist/runtime/components/NumberInput/Vertical.vue +7 -2
- package/dist/runtime/components/NumberInput/index.d.vue.ts +0 -2
- package/dist/runtime/components/NumberInput/index.vue +9 -7
- package/dist/runtime/components/NumberInput/index.vue.d.ts +0 -2
- package/dist/runtime/components/RadioButton.d.vue.ts +0 -2
- package/dist/runtime/components/RadioButton.vue +9 -4
- package/dist/runtime/components/RadioButton.vue.d.ts +0 -2
- package/dist/runtime/components/Selector.d.vue.ts +1 -0
- package/dist/runtime/components/Selector.vue +10 -4
- package/dist/runtime/components/Selector.vue.d.ts +1 -0
- package/dist/runtime/components/SwitchButton.d.vue.ts +1 -4
- package/dist/runtime/components/SwitchButton.vue +10 -7
- package/dist/runtime/components/SwitchButton.vue.d.ts +1 -4
- package/dist/runtime/components/TaggableSelector.vue +7 -1
- package/dist/runtime/components/Textarea.vue +13 -3
- package/dist/runtime/components/date/Picker.USAGE.md +44 -0
- package/dist/runtime/components/date/Picker.d.vue.ts +26 -0
- package/dist/runtime/components/date/Picker.vue +60 -0
- package/dist/runtime/components/date/Picker.vue.d.ts +26 -0
- package/dist/runtime/components/date/PickerTrigger.d.vue.ts +23 -0
- package/dist/runtime/components/date/PickerTrigger.vue +86 -0
- package/dist/runtime/components/date/PickerTrigger.vue.d.ts +23 -0
- package/dist/runtime/components/date/RangePicker.d.vue.ts +28 -0
- package/dist/runtime/components/date/RangePicker.vue +154 -0
- package/dist/runtime/components/date/RangePicker.vue.d.ts +28 -0
- package/dist/runtime/components/view/Dates.d.vue.ts +2 -5
- package/dist/runtime/components/view/Dates.vue +17 -23
- package/dist/runtime/components/view/Dates.vue.d.ts +2 -5
- package/dist/runtime/composables/useFilter.d.ts +91 -0
- package/dist/runtime/composables/useFilter.js +111 -0
- package/dist/runtime/composables/useRovingGrid.d.ts +35 -0
- package/dist/runtime/composables/useRovingGrid.js +115 -0
- package/dist/runtime/i18n/en.json +11 -5
- package/dist/runtime/i18n/uk.json +11 -5
- package/dist/runtime/index.d.ts +4 -2
- package/dist/runtime/index.js +6 -2
- package/dist/runtime/utils/date.d.ts +10 -0
- package/dist/runtime/utils/date.js +38 -0
- package/package.json +1 -1
- package/dist/runtime/components/DatePicker.d.vue.ts +0 -15
- package/dist/runtime/components/DatePicker.vue +0 -24
- package/dist/runtime/components/DatePicker.vue.d.ts +0 -15
- package/dist/runtime/components/DateRangePicker.d.vue.ts +0 -18
- package/dist/runtime/components/DateRangePicker.vue +0 -67
- package/dist/runtime/components/DateRangePicker.vue.d.ts +0 -18
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed, ref, watch } from "vue";
|
|
3
|
+
import { useI18n } from "vue-i18n";
|
|
4
|
+
import {
|
|
5
|
+
addMonths,
|
|
6
|
+
formatDate,
|
|
7
|
+
formatISO,
|
|
8
|
+
parseISO,
|
|
9
|
+
startOfMonth
|
|
10
|
+
} from "../../utils/date";
|
|
11
|
+
const props = defineProps({
|
|
12
|
+
placeholder: { type: String, required: false },
|
|
13
|
+
min: { type: [String, null], required: false, default: null },
|
|
14
|
+
max: { type: [String, null], required: false, default: null },
|
|
15
|
+
markers: { type: Array, required: false, default: () => [] },
|
|
16
|
+
getMarker: { type: Function, required: false },
|
|
17
|
+
isDisabled: { type: Function, required: false },
|
|
18
|
+
appearance: { type: String, required: false },
|
|
19
|
+
error: { type: [String, null], required: false },
|
|
20
|
+
group: { type: Boolean, required: false },
|
|
21
|
+
id: { type: String, required: false },
|
|
22
|
+
label: { type: String, required: false },
|
|
23
|
+
layout: { type: String, required: false },
|
|
24
|
+
size: { type: String, required: false },
|
|
25
|
+
fill: { type: Boolean, required: false },
|
|
26
|
+
tabindex: { type: [Number, String], required: false },
|
|
27
|
+
focusKey: { type: String, required: false },
|
|
28
|
+
disabled: { type: Boolean, required: false },
|
|
29
|
+
required: { type: Boolean, required: false },
|
|
30
|
+
name: { type: String, required: false },
|
|
31
|
+
ariaLabel: { type: String, required: false }
|
|
32
|
+
});
|
|
33
|
+
const range = defineModel({ type: Object, ...{
|
|
34
|
+
default: () => ({ start: null, end: null })
|
|
35
|
+
} });
|
|
36
|
+
const { locale, t } = useI18n();
|
|
37
|
+
const display = computed(() => {
|
|
38
|
+
const start = formatDate(range.value?.start, locale.value);
|
|
39
|
+
const end = formatDate(range.value?.end, locale.value);
|
|
40
|
+
if (start && end) return `${start} \u2013 ${end}`;
|
|
41
|
+
return start || end || "";
|
|
42
|
+
});
|
|
43
|
+
const placeholderText = computed(
|
|
44
|
+
() => props.placeholder ?? t("dateRangePicker.placeholder")
|
|
45
|
+
);
|
|
46
|
+
const seedMonth = startOfMonth(parseISO(range.value?.start) ?? /* @__PURE__ */ new Date());
|
|
47
|
+
const leftAnchor = ref(formatISO(seedMonth));
|
|
48
|
+
const rightAnchor = ref(formatISO(addMonths(seedMonth, 1)));
|
|
49
|
+
watch(
|
|
50
|
+
() => range.value?.start,
|
|
51
|
+
(start) => {
|
|
52
|
+
const date = parseISO(start);
|
|
53
|
+
if (!date) return;
|
|
54
|
+
const monthIso = formatISO(startOfMonth(date));
|
|
55
|
+
if (leftAnchor.value === monthIso || rightAnchor.value === monthIso) return;
|
|
56
|
+
leftAnchor.value = monthIso;
|
|
57
|
+
rightAnchor.value = formatISO(addMonths(startOfMonth(date), 1));
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
const hovering = ref(null);
|
|
61
|
+
const previewEnd = computed(() => {
|
|
62
|
+
if (range.value?.end) return range.value.end;
|
|
63
|
+
if (!hovering.value || !range.value?.start) return null;
|
|
64
|
+
const start = parseISO(range.value.start);
|
|
65
|
+
const hover = parseISO(hovering.value);
|
|
66
|
+
if (!start || !hover) return null;
|
|
67
|
+
return hover > start ? hovering.value : null;
|
|
68
|
+
});
|
|
69
|
+
const previewStart = computed(() => {
|
|
70
|
+
if (range.value?.start && range.value?.end) return range.value.start;
|
|
71
|
+
if (!hovering.value || !range.value?.start) return range.value?.start ?? null;
|
|
72
|
+
const start = parseISO(range.value.start);
|
|
73
|
+
const hover = parseISO(hovering.value);
|
|
74
|
+
if (!start || !hover) return range.value.start;
|
|
75
|
+
return hover < start ? hovering.value : range.value.start;
|
|
76
|
+
});
|
|
77
|
+
const previewMarker = computed(() => {
|
|
78
|
+
if (!previewStart.value || !previewEnd.value) return null;
|
|
79
|
+
return {
|
|
80
|
+
variant: "accent",
|
|
81
|
+
start: previewStart.value,
|
|
82
|
+
end: previewEnd.value
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
const calendarGetMarker = computed(() => (iso) => {
|
|
86
|
+
const preview = previewMarker.value;
|
|
87
|
+
if (preview && iso >= preview.start && iso <= preview.end) return preview;
|
|
88
|
+
return props.getMarker?.(iso) ?? null;
|
|
89
|
+
});
|
|
90
|
+
const calendarIsDisabled = computed(() => (iso) => {
|
|
91
|
+
if (props.min && iso < props.min) return true;
|
|
92
|
+
if (props.max && iso > props.max) return true;
|
|
93
|
+
return props.isDisabled?.(iso) ?? false;
|
|
94
|
+
});
|
|
95
|
+
function pick(iso, toggle) {
|
|
96
|
+
const current = range.value ?? { start: null, end: null };
|
|
97
|
+
if (!current.start || current.start && current.end) {
|
|
98
|
+
range.value = { start: iso, end: null };
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const startDate = parseISO(current.start);
|
|
102
|
+
const picked = parseISO(iso);
|
|
103
|
+
if (!startDate || !picked) return;
|
|
104
|
+
if (picked < startDate) {
|
|
105
|
+
range.value = { start: iso, end: current.start };
|
|
106
|
+
} else {
|
|
107
|
+
range.value = { start: current.start, end: iso };
|
|
108
|
+
}
|
|
109
|
+
hovering.value = null;
|
|
110
|
+
toggle(false);
|
|
111
|
+
}
|
|
112
|
+
function onHover(iso) {
|
|
113
|
+
hovering.value = iso;
|
|
114
|
+
}
|
|
115
|
+
function clearHover() {
|
|
116
|
+
hovering.value = null;
|
|
117
|
+
}
|
|
118
|
+
</script>
|
|
119
|
+
|
|
120
|
+
<template>
|
|
121
|
+
<orio-date-picker-trigger
|
|
122
|
+
v-bind="props"
|
|
123
|
+
:text="display"
|
|
124
|
+
:placeholder="placeholderText"
|
|
125
|
+
>
|
|
126
|
+
<template #default="{ toggle }">
|
|
127
|
+
<div class="range-content" @mouseleave="clearHover">
|
|
128
|
+
<orio-calendar
|
|
129
|
+
v-model:anchor="leftAnchor"
|
|
130
|
+
:markers
|
|
131
|
+
:get-marker="calendarGetMarker"
|
|
132
|
+
:is-disabled="calendarIsDisabled"
|
|
133
|
+
@select="pick($event, toggle)"
|
|
134
|
+
@day-enter="onHover"
|
|
135
|
+
/>
|
|
136
|
+
<orio-calendar
|
|
137
|
+
v-model:anchor="rightAnchor"
|
|
138
|
+
:markers
|
|
139
|
+
:get-marker="calendarGetMarker"
|
|
140
|
+
:is-disabled="calendarIsDisabled"
|
|
141
|
+
@select="pick($event, toggle)"
|
|
142
|
+
@day-enter="onHover"
|
|
143
|
+
/>
|
|
144
|
+
</div>
|
|
145
|
+
</template>
|
|
146
|
+
</orio-date-picker-trigger>
|
|
147
|
+
</template>
|
|
148
|
+
|
|
149
|
+
<style scoped>
|
|
150
|
+
.range-content {
|
|
151
|
+
display: flex;
|
|
152
|
+
gap: 0.75rem;
|
|
153
|
+
}
|
|
154
|
+
</style>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ControlProps } from "../ControlElement.vue.js";
|
|
2
|
+
import type { CalendarMarker } from "../Calendar.vue.js";
|
|
3
|
+
import { type DateRange } from "../../utils/date.js";
|
|
4
|
+
export type { DateRange };
|
|
5
|
+
interface Props extends ControlProps {
|
|
6
|
+
placeholder?: string;
|
|
7
|
+
min?: string | null;
|
|
8
|
+
max?: string | null;
|
|
9
|
+
markers?: CalendarMarker[];
|
|
10
|
+
getMarker?: (iso: string) => CalendarMarker | null;
|
|
11
|
+
isDisabled?: (iso: string) => boolean;
|
|
12
|
+
}
|
|
13
|
+
type __VLS_Props = Props;
|
|
14
|
+
type __VLS_ModelProps = {
|
|
15
|
+
modelValue?: DateRange;
|
|
16
|
+
};
|
|
17
|
+
type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
|
|
18
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
19
|
+
"update:modelValue": (value: DateRange) => any;
|
|
20
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
21
|
+
"onUpdate:modelValue"?: ((value: DateRange) => any) | undefined;
|
|
22
|
+
}>, {
|
|
23
|
+
markers: CalendarMarker[];
|
|
24
|
+
min: string | null;
|
|
25
|
+
max: string | null;
|
|
26
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
27
|
+
declare const _default: typeof __VLS_export;
|
|
28
|
+
export default _default;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
startDate: string;
|
|
3
|
-
endDate?: string | null;
|
|
4
|
-
}
|
|
1
|
+
import { type DateRange } from "../../utils/date.js";
|
|
5
2
|
interface Props {
|
|
6
|
-
dates:
|
|
3
|
+
dates: DateRange;
|
|
7
4
|
month?: boolean;
|
|
8
5
|
size?: "small" | "medium" | "large";
|
|
9
6
|
type?: "text" | "title" | "subtitle" | "italics";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed, toRefs } from "vue";
|
|
3
3
|
import { useI18n } from "vue-i18n";
|
|
4
|
+
import { formatDate } from "../../utils/date";
|
|
4
5
|
const props = defineProps({
|
|
5
6
|
dates: { type: Object, required: true },
|
|
6
7
|
month: { type: Boolean, required: false },
|
|
@@ -8,33 +9,26 @@ const props = defineProps({
|
|
|
8
9
|
type: { type: String, required: false, default: "italics" }
|
|
9
10
|
});
|
|
10
11
|
const { dates } = toRefs(props);
|
|
11
|
-
const {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}).format(new Date(value));
|
|
24
|
-
}
|
|
25
|
-
const startDate = computed(() => formatMonthYear(dates.value.startDate));
|
|
26
|
-
const endDate = computed(() => {
|
|
27
|
-
if (dates.value.endDate === void 0) return null;
|
|
28
|
-
return dates.value.endDate !== null ? formatMonthYear(dates.value.endDate) : t("dates.present");
|
|
29
|
-
});
|
|
12
|
+
const { locale } = useI18n();
|
|
13
|
+
const formatOptions = computed(() => ({
|
|
14
|
+
day: props.month ? void 0 : "numeric",
|
|
15
|
+
month: "short",
|
|
16
|
+
year: "numeric"
|
|
17
|
+
}));
|
|
18
|
+
const startText = computed(
|
|
19
|
+
() => formatDate(dates.value?.start, locale.value, formatOptions.value)
|
|
20
|
+
);
|
|
21
|
+
const endText = computed(
|
|
22
|
+
() => formatDate(dates.value?.end, locale.value, formatOptions.value)
|
|
23
|
+
);
|
|
30
24
|
</script>
|
|
31
25
|
|
|
32
26
|
<template>
|
|
33
27
|
<div class="view-date">
|
|
34
|
-
<orio-view-text :model-value="
|
|
35
|
-
<template v-if="
|
|
36
|
-
<span v-if="
|
|
37
|
-
<orio-view-text :model-value="
|
|
28
|
+
<orio-view-text :model-value="startText" :type :size />
|
|
29
|
+
<template v-if="endText">
|
|
30
|
+
<span v-if="startText"> - </span>
|
|
31
|
+
<orio-view-text :model-value="endText" :type :size />
|
|
38
32
|
</template>
|
|
39
33
|
</div>
|
|
40
34
|
</template>
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
startDate: string;
|
|
3
|
-
endDate?: string | null;
|
|
4
|
-
}
|
|
1
|
+
import { type DateRange } from "../../utils/date.js";
|
|
5
2
|
interface Props {
|
|
6
|
-
dates:
|
|
3
|
+
dates: DateRange;
|
|
7
4
|
month?: boolean;
|
|
8
5
|
size?: "small" | "medium" | "large";
|
|
9
6
|
type?: "text" | "title" | "subtitle" | "italics";
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { type ComputedRef, type Ref } from "vue";
|
|
2
|
+
/**
|
|
3
|
+
* Definition of a single filter inside a group.
|
|
4
|
+
*
|
|
5
|
+
* `value` is both the initial value and the "empty" baseline used to compute
|
|
6
|
+
* `isActive` and to reset to via `clear()`.
|
|
7
|
+
*/
|
|
8
|
+
export interface FilterDefinition<Value = unknown> {
|
|
9
|
+
value: Value;
|
|
10
|
+
}
|
|
11
|
+
export type FilterConfig = Record<string, FilterDefinition>;
|
|
12
|
+
export interface FilterOptions {
|
|
13
|
+
/**
|
|
14
|
+
* When true, the group's state is mirrored to URL query params via
|
|
15
|
+
* `useUrlSync`. The dependency is loaded lazily — `useUrlSync` (and its
|
|
16
|
+
* `#imports` use of `useRoute`) is never touched unless this flag is set,
|
|
17
|
+
* keeping `useFilter` runnable outside of a Nuxt context.
|
|
18
|
+
*
|
|
19
|
+
* Filter names become top-level URL keys; avoid colliding names across
|
|
20
|
+
* multiple URL-synced groups on the same page.
|
|
21
|
+
*/
|
|
22
|
+
url?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Bindable prop bag — spread onto any `v-model`-compatible component:
|
|
26
|
+
* `<orio-selector v-bind="filters.category" :options="..." />`
|
|
27
|
+
*/
|
|
28
|
+
export interface FilterBind<Value = unknown> {
|
|
29
|
+
modelValue: Value;
|
|
30
|
+
"onUpdate:modelValue": (value: Value) => void;
|
|
31
|
+
}
|
|
32
|
+
/** Per-filter helpers accessed via `filters.$.<name>`. */
|
|
33
|
+
export interface FilterHelpers<Value = unknown> {
|
|
34
|
+
value: Value;
|
|
35
|
+
initial: Value;
|
|
36
|
+
isActive: boolean;
|
|
37
|
+
clear: () => void;
|
|
38
|
+
}
|
|
39
|
+
export interface ActiveFilter {
|
|
40
|
+
name: string;
|
|
41
|
+
value: unknown;
|
|
42
|
+
clear: () => void;
|
|
43
|
+
}
|
|
44
|
+
export type FilterGroup<Config extends FilterConfig> = {
|
|
45
|
+
[Key in keyof Config]: FilterBind<Config[Key]["value"]>;
|
|
46
|
+
} & {
|
|
47
|
+
$: {
|
|
48
|
+
[Key in keyof Config]: FilterHelpers<Config[Key]["value"]>;
|
|
49
|
+
};
|
|
50
|
+
$active: ComputedRef<ActiveFilter[]>;
|
|
51
|
+
$clearAll: () => void;
|
|
52
|
+
$state: Ref<Record<string, unknown>>;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Define or retrieve a named filter group.
|
|
56
|
+
*
|
|
57
|
+
* Define once anywhere in the page (setup, layout, store). Retrieve the same
|
|
58
|
+
* instance elsewhere by id — any component that knows the id can read and
|
|
59
|
+
* mutate the same reactive state, regardless of where it lives in the tree.
|
|
60
|
+
*
|
|
61
|
+
* @example Define
|
|
62
|
+
* ```ts
|
|
63
|
+
* const filters = useFilter('appointments', {
|
|
64
|
+
* category: { value: null },
|
|
65
|
+
* status: { value: [] as string[] },
|
|
66
|
+
* dateRange: { value: { from: null, to: null } },
|
|
67
|
+
* })
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @example Bind to any v-model component
|
|
71
|
+
* ```vue
|
|
72
|
+
* <orio-selector v-bind="filters.category" :options="categories" />
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @example Retrieve elsewhere
|
|
76
|
+
* ```ts
|
|
77
|
+
* const filters = useFilter('appointments')
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @example Mirror to URL (Nuxt only)
|
|
81
|
+
* ```ts
|
|
82
|
+
* const filters = useFilter('appointments', config, { url: true })
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare function useFilter<Config extends FilterConfig>(id: string, config: Config, options?: FilterOptions): FilterGroup<Config>;
|
|
86
|
+
export declare function useFilter(id: string): FilterGroup<FilterConfig>;
|
|
87
|
+
/**
|
|
88
|
+
* Remove a filter group from the registry. Use in SPAs where filter groups
|
|
89
|
+
* are page-scoped and should not leak between routes.
|
|
90
|
+
*/
|
|
91
|
+
export declare function disposeFilter(id: string): void;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
effectScope,
|
|
4
|
+
ref
|
|
5
|
+
} from "vue";
|
|
6
|
+
const registry = /* @__PURE__ */ new Map();
|
|
7
|
+
const urlSyncScopes = /* @__PURE__ */ new Map();
|
|
8
|
+
export function useFilter(id, config, options = {}) {
|
|
9
|
+
const existing = registry.get(id);
|
|
10
|
+
if (existing) {
|
|
11
|
+
if (config) {
|
|
12
|
+
console.warn(
|
|
13
|
+
`[useFilter] group "${id}" is already defined \u2014 ignoring new config.`
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
return existing;
|
|
17
|
+
}
|
|
18
|
+
if (!config) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
`[useFilter] group "${id}" is not defined. Pass a config on the first call.`
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
const initial = {};
|
|
24
|
+
for (const [name, definition] of Object.entries(config)) {
|
|
25
|
+
initial[name] = clone(definition.value);
|
|
26
|
+
}
|
|
27
|
+
const state = ref({ ...initial });
|
|
28
|
+
if (options.url) {
|
|
29
|
+
const scope = effectScope(true);
|
|
30
|
+
urlSyncScopes.set(id, scope);
|
|
31
|
+
void import("./useUrlSync.js").then(({ useUrlSync }) => {
|
|
32
|
+
scope.run(() => useUrlSync(state, Object.keys(config)));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const handle = {};
|
|
36
|
+
const helpers = {};
|
|
37
|
+
for (const name of Object.keys(config)) {
|
|
38
|
+
helpers[name] = {
|
|
39
|
+
get value() {
|
|
40
|
+
return state.value[name];
|
|
41
|
+
},
|
|
42
|
+
get initial() {
|
|
43
|
+
return initial[name];
|
|
44
|
+
},
|
|
45
|
+
get isActive() {
|
|
46
|
+
return !isEqual(state.value[name], initial[name]);
|
|
47
|
+
},
|
|
48
|
+
clear() {
|
|
49
|
+
state.value[name] = clone(initial[name]);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(handle, name, {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
value: {
|
|
55
|
+
get modelValue() {
|
|
56
|
+
return state.value[name];
|
|
57
|
+
},
|
|
58
|
+
"onUpdate:modelValue": (value) => {
|
|
59
|
+
state.value[name] = value;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
Object.defineProperty(handle, "$", { value: helpers });
|
|
65
|
+
Object.defineProperty(handle, "$active", {
|
|
66
|
+
value: computed(
|
|
67
|
+
() => Object.keys(config).flatMap((name) => {
|
|
68
|
+
const helper = helpers[name];
|
|
69
|
+
return helper.isActive ? [{ name, value: helper.value, clear: helper.clear }] : [];
|
|
70
|
+
})
|
|
71
|
+
)
|
|
72
|
+
});
|
|
73
|
+
Object.defineProperty(handle, "$clearAll", {
|
|
74
|
+
value: () => {
|
|
75
|
+
for (const name of Object.keys(config)) {
|
|
76
|
+
state.value[name] = clone(initial[name]);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
Object.defineProperty(handle, "$state", { value: state });
|
|
81
|
+
registry.set(id, handle);
|
|
82
|
+
return handle;
|
|
83
|
+
}
|
|
84
|
+
export function disposeFilter(id) {
|
|
85
|
+
urlSyncScopes.get(id)?.stop();
|
|
86
|
+
urlSyncScopes.delete(id);
|
|
87
|
+
registry.delete(id);
|
|
88
|
+
}
|
|
89
|
+
function clone(value) {
|
|
90
|
+
if (value === null || typeof value !== "object") return value;
|
|
91
|
+
return structuredClone(value);
|
|
92
|
+
}
|
|
93
|
+
function isEqual(a, b) {
|
|
94
|
+
if (a === b) return true;
|
|
95
|
+
if (a === null || b === null) return false;
|
|
96
|
+
if (typeof a !== typeof b) return false;
|
|
97
|
+
if (typeof a !== "object") return false;
|
|
98
|
+
if (Array.isArray(a)) {
|
|
99
|
+
if (!Array.isArray(b) || a.length !== b.length) return false;
|
|
100
|
+
return a.every((item, index) => isEqual(item, b[index]));
|
|
101
|
+
}
|
|
102
|
+
const keysA = Object.keys(a);
|
|
103
|
+
const keysB = Object.keys(b);
|
|
104
|
+
if (keysA.length !== keysB.length) return false;
|
|
105
|
+
return keysA.every(
|
|
106
|
+
(key) => isEqual(
|
|
107
|
+
a[key],
|
|
108
|
+
b[key]
|
|
109
|
+
)
|
|
110
|
+
);
|
|
111
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type Ref } from "vue";
|
|
2
|
+
export type ArrowDirection = "up" | "down" | "left" | "right";
|
|
3
|
+
export type PageDirection = "up" | "down";
|
|
4
|
+
export interface RovingGridOptions<Cell> {
|
|
5
|
+
rows: Ref<Cell[][]>;
|
|
6
|
+
gridRef: Ref<HTMLElement | null>;
|
|
7
|
+
getKey: (cell: Cell) => string;
|
|
8
|
+
initial: () => string;
|
|
9
|
+
/**
|
|
10
|
+
* Cells where this returns `false` are skipped by arrow navigation —
|
|
11
|
+
* pressing Arrow steps past them in the same direction until a navigable
|
|
12
|
+
* cell is found (or the grid edge is reached, then `onArrowOverflow` fires).
|
|
13
|
+
* Default: every cell is navigable.
|
|
14
|
+
*/
|
|
15
|
+
isNavigable?: (cell: Cell) => boolean;
|
|
16
|
+
onActivate?: (cell: Cell) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Called when an arrow key would move past the rendered grid edge.
|
|
19
|
+
* Return a new key to focus (caller should update any backing state, e.g.
|
|
20
|
+
* paging to a new month, before returning). Return null to do nothing.
|
|
21
|
+
*/
|
|
22
|
+
onArrowOverflow?: (direction: ArrowDirection, activeKey: string) => string | null;
|
|
23
|
+
/**
|
|
24
|
+
* Called for PageUp / PageDown (with Shift = larger jump).
|
|
25
|
+
* Return a new key to focus, or null to do nothing.
|
|
26
|
+
*/
|
|
27
|
+
onPage?: (direction: PageDirection, bigJump: boolean, activeKey: string) => string | null;
|
|
28
|
+
}
|
|
29
|
+
export declare function useRovingGrid<Cell>(options: RovingGridOptions<Cell>): {
|
|
30
|
+
activeKey: import("vue").ComputedRef<string>;
|
|
31
|
+
setActive: (key: string, shouldFocus?: boolean) => void;
|
|
32
|
+
focusActive: () => void;
|
|
33
|
+
onKeydown: (event: KeyboardEvent) => void;
|
|
34
|
+
tabindexFor: (key: string) => 0 | -1;
|
|
35
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { computed, nextTick, ref } from "vue";
|
|
2
|
+
const ARROW_OFFSETS = {
|
|
3
|
+
up: { rowDelta: -1, columnDelta: 0 },
|
|
4
|
+
down: { rowDelta: 1, columnDelta: 0 },
|
|
5
|
+
left: { rowDelta: 0, columnDelta: -1 },
|
|
6
|
+
right: { rowDelta: 0, columnDelta: 1 }
|
|
7
|
+
};
|
|
8
|
+
const ARROW_KEYS = {
|
|
9
|
+
ArrowUp: "up",
|
|
10
|
+
ArrowDown: "down",
|
|
11
|
+
ArrowLeft: "left",
|
|
12
|
+
ArrowRight: "right"
|
|
13
|
+
};
|
|
14
|
+
export function useRovingGrid(options) {
|
|
15
|
+
const focusedKey = ref(null);
|
|
16
|
+
function findCell(key) {
|
|
17
|
+
for (const [rowIndex, cellsInRow] of options.rows.value.entries()) {
|
|
18
|
+
const columnIndex = cellsInRow.findIndex(
|
|
19
|
+
(cell) => options.getKey(cell) === key
|
|
20
|
+
);
|
|
21
|
+
if (columnIndex !== -1) {
|
|
22
|
+
return { rowIndex, columnIndex, cell: cellsInRow[columnIndex] };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const activeKey = computed(() => {
|
|
28
|
+
if (focusedKey.value && findCell(focusedKey.value)) return focusedKey.value;
|
|
29
|
+
return options.initial();
|
|
30
|
+
});
|
|
31
|
+
function focusActive() {
|
|
32
|
+
nextTick(() => {
|
|
33
|
+
const selector = `[focus-key="${CSS.escape(activeKey.value)}"]`;
|
|
34
|
+
const element = options.gridRef.value?.querySelector(selector);
|
|
35
|
+
if (!element) return;
|
|
36
|
+
element.scrollIntoView({
|
|
37
|
+
block: "nearest",
|
|
38
|
+
inline: "nearest",
|
|
39
|
+
behavior: "smooth"
|
|
40
|
+
});
|
|
41
|
+
element.focus({ preventScroll: true });
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function setActive(key, shouldFocus = true) {
|
|
45
|
+
focusedKey.value = key;
|
|
46
|
+
if (shouldFocus) focusActive();
|
|
47
|
+
}
|
|
48
|
+
function tryArrow(direction) {
|
|
49
|
+
const position = findCell(activeKey.value);
|
|
50
|
+
if (!position) return;
|
|
51
|
+
const offset = ARROW_OFFSETS[direction];
|
|
52
|
+
const rows = options.rows.value;
|
|
53
|
+
let targetRowIndex = position.rowIndex + offset.rowDelta;
|
|
54
|
+
let targetColumnIndex = position.columnIndex + offset.columnDelta;
|
|
55
|
+
while (rows[targetRowIndex]?.[targetColumnIndex] !== void 0) {
|
|
56
|
+
const candidate = rows[targetRowIndex][targetColumnIndex];
|
|
57
|
+
if (!options.isNavigable || options.isNavigable(candidate)) {
|
|
58
|
+
setActive(options.getKey(candidate));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
targetRowIndex += offset.rowDelta;
|
|
62
|
+
targetColumnIndex += offset.columnDelta;
|
|
63
|
+
}
|
|
64
|
+
const overflowKey = options.onArrowOverflow?.(direction, activeKey.value);
|
|
65
|
+
if (overflowKey) setActive(overflowKey);
|
|
66
|
+
}
|
|
67
|
+
function moveToRowEdge(toEnd) {
|
|
68
|
+
const position = findCell(activeKey.value);
|
|
69
|
+
if (!position) return;
|
|
70
|
+
const row = options.rows.value[position.rowIndex];
|
|
71
|
+
const ordered = toEnd ? [...row].reverse() : row;
|
|
72
|
+
const edgeCell = ordered.find(
|
|
73
|
+
(cell) => !options.isNavigable || options.isNavigable(cell)
|
|
74
|
+
);
|
|
75
|
+
if (!edgeCell) return;
|
|
76
|
+
setActive(options.getKey(edgeCell));
|
|
77
|
+
}
|
|
78
|
+
function tryPage(direction, bigJump) {
|
|
79
|
+
const newKey = options.onPage?.(direction, bigJump, activeKey.value);
|
|
80
|
+
if (newKey) setActive(newKey);
|
|
81
|
+
}
|
|
82
|
+
function activate() {
|
|
83
|
+
const position = findCell(activeKey.value);
|
|
84
|
+
if (position) options.onActivate?.(position.cell);
|
|
85
|
+
}
|
|
86
|
+
function onKeydown(event) {
|
|
87
|
+
const arrow = ARROW_KEYS[event.key];
|
|
88
|
+
if (arrow) {
|
|
89
|
+
tryArrow(arrow);
|
|
90
|
+
} else if (event.key === "Home") {
|
|
91
|
+
moveToRowEdge(false);
|
|
92
|
+
} else if (event.key === "End") {
|
|
93
|
+
moveToRowEdge(true);
|
|
94
|
+
} else if (event.key === "PageUp") {
|
|
95
|
+
tryPage("up", event.shiftKey);
|
|
96
|
+
} else if (event.key === "PageDown") {
|
|
97
|
+
tryPage("down", event.shiftKey);
|
|
98
|
+
} else if (event.key === "Enter" || event.key === " ") {
|
|
99
|
+
activate();
|
|
100
|
+
} else {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
event.preventDefault();
|
|
104
|
+
}
|
|
105
|
+
function tabindexFor(key) {
|
|
106
|
+
return key === activeKey.value ? 0 : -1;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
activeKey,
|
|
110
|
+
setActive,
|
|
111
|
+
focusActive,
|
|
112
|
+
onKeydown,
|
|
113
|
+
tabindexFor
|
|
114
|
+
};
|
|
115
|
+
}
|
|
@@ -4,12 +4,18 @@
|
|
|
4
4
|
"selected": "{count} selected",
|
|
5
5
|
"noOptions": "No options found"
|
|
6
6
|
},
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
7
|
+
"calendar": {
|
|
8
|
+
"previousMonth": "Previous month",
|
|
9
|
+
"nextMonth": "Next month",
|
|
10
|
+
"previousYear": "Previous year",
|
|
11
|
+
"nextYear": "Next year",
|
|
12
|
+
"navigation": "Calendar navigation"
|
|
13
|
+
},
|
|
14
|
+
"datePicker": {
|
|
15
|
+
"placeholder": "Select a date"
|
|
10
16
|
},
|
|
11
|
-
"
|
|
12
|
-
"
|
|
17
|
+
"dateRangePicker": {
|
|
18
|
+
"placeholder": "Select a date range"
|
|
13
19
|
},
|
|
14
20
|
"validation": {
|
|
15
21
|
"fieldError": "Error on this field"
|
|
@@ -4,12 +4,18 @@
|
|
|
4
4
|
"selected": "{count} обрано",
|
|
5
5
|
"noOptions": "Опцій не знайдено"
|
|
6
6
|
},
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
7
|
+
"calendar": {
|
|
8
|
+
"previousMonth": "Попередній місяць",
|
|
9
|
+
"nextMonth": "Наступний місяць",
|
|
10
|
+
"previousYear": "Попередній рік",
|
|
11
|
+
"nextYear": "Наступний рік",
|
|
12
|
+
"navigation": "Навігація календаря"
|
|
13
|
+
},
|
|
14
|
+
"datePicker": {
|
|
15
|
+
"placeholder": "Оберіть дату"
|
|
10
16
|
},
|
|
11
|
-
"
|
|
12
|
-
"
|
|
17
|
+
"dateRangePicker": {
|
|
18
|
+
"placeholder": "Оберіть діапазон дат"
|
|
13
19
|
},
|
|
14
20
|
"validation": {
|
|
15
21
|
"fieldError": "Помилка в цьому полі"
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -11,8 +11,10 @@ export { default as CheckBox } from "./components/CheckBox.vue.js";
|
|
|
11
11
|
export { default as CheckboxGroup, type CheckboxOption, type CheckboxGroupProps, } from "./components/CheckboxGroup.vue.js";
|
|
12
12
|
export { default as RadioButton, type RadioButtonProps, } from "./components/RadioButton.vue.js";
|
|
13
13
|
export { default as SwitchButton } from "./components/SwitchButton.vue.js";
|
|
14
|
-
export { default as
|
|
15
|
-
export { default as
|
|
14
|
+
export { default as Calendar, type CalendarProps, } from "./components/Calendar.vue.js";
|
|
15
|
+
export { default as DatePicker } from "./components/date/Picker.vue.js";
|
|
16
|
+
export { default as DateRangePicker } from "./components/date/RangePicker.vue.js";
|
|
17
|
+
export { type DateRange, parseISO, formatISO, formatDate } from "./utils/date.js";
|
|
16
18
|
export { default as Selector } from "./components/Selector.vue.js";
|
|
17
19
|
export { default as TaggableSelector } from "./components/TaggableSelector.vue.js";
|
|
18
20
|
export { default as Tag } from "./components/Tag.vue.js";
|