@bridge-ui/vue 0.10.1 → 0.12.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/ai/AGENTS.md +1 -1
- package/ai/README.md +1 -1
- package/ai/llms.txt +4 -2
- package/ai/skills/bridge-ui-setup/SKILL.md +8 -8
- package/dist/Adapters/Date/index.d.ts +1 -1
- package/dist/Adapters/Date/index.js +2 -2
- package/dist/Adapters/Date/useDateAdapter.d.ts +6 -8
- package/dist/Adapters/Date/useDateAdapter.js +4 -8
- package/dist/Adapters/Examples/date-date-fns.d.ts +9 -0
- package/dist/Adapters/Examples/date-date-fns.js +151 -0
- package/dist/Adapters/Examples/date-dayjs.d.ts +19 -0
- package/dist/Adapters/Examples/date-dayjs.js +174 -0
- package/dist/Adapters/Examples/date-luxon.d.ts +7 -0
- package/dist/Adapters/Examples/date-luxon.js +164 -0
- package/dist/Adapters/Examples/date-moment.d.ts +19 -0
- package/dist/Adapters/Examples/date-moment.js +172 -0
- package/dist/Adapters/Examples/i18n-dictionary.d.ts +15 -0
- package/dist/Adapters/Examples/i18n-dictionary.js +83 -0
- package/dist/Adapters/Examples/i18n-vue-i18n.d.ts +7 -0
- package/dist/Adapters/Examples/i18n-vue-i18n.js +14 -0
- package/dist/Adapters/Examples/icon-fontawesome.d.ts +19 -0
- package/dist/Adapters/Examples/icon-fontawesome.js +80 -0
- package/dist/Adapters/Examples/icon-heroicons.d.ts +5 -0
- package/dist/Adapters/Examples/icon-heroicons.js +54 -0
- package/dist/Adapters/Examples/icon-lucide.d.ts +5 -0
- package/dist/Adapters/Examples/icon-lucide.js +54 -0
- package/dist/Adapters/Examples/icon-phosphor.d.ts +5 -0
- package/dist/Adapters/Examples/icon-phosphor.js +54 -0
- package/dist/Adapters/Examples/icon-tabler.d.ts +5 -0
- package/dist/Adapters/Examples/icon-tabler.js +54 -0
- package/dist/Adapters/Examples/rich-text-tiptap.d.ts +5 -0
- package/dist/Adapters/Examples/rich-text-tiptap.js +138 -0
- package/dist/Adapters/I18n/useI18nAdapter.d.ts +2 -2
- package/dist/Adapters/Icon/useIconAdapter.d.ts +1 -1
- package/dist/Adapters/RichText/index.d.ts +1 -0
- package/dist/Adapters/RichText/index.js +2 -0
- package/dist/Adapters/RichText/mockRichTextAdapter.d.ts +5 -0
- package/dist/Adapters/RichText/useRichTextAdapter.d.ts +12 -0
- package/dist/Adapters/RichText/useRichTextAdapter.js +13 -0
- package/dist/Adapters/index.d.ts +2 -1
- package/dist/Adapters/index.js +5 -4
- package/dist/Components/ActionFooter/composables/useActionFooter.d.ts +6 -6
- package/dist/Components/Autocomplete/Autocomplete.vue.d.ts +2 -2
- package/dist/Components/Autocomplete/composables/useAutocomplete.d.ts +2 -2
- package/dist/Components/Autocomplete/composables/useAutocomplete.js +2 -2
- package/dist/Components/Breadcrumb/Breadcrumb.vue.d.ts +17 -10
- package/dist/Components/Breadcrumb/Breadcrumb.vue_vue_type_script_setup_true_lang.js +7 -2
- package/dist/Components/Breadcrumb/breadcrumb.types.d.ts +22 -4
- package/dist/Components/Breadcrumb/breadcrumbInjectionKey.d.ts +5 -1
- package/dist/Components/Breadcrumb/composables/useBreadcrumb.d.ts +6 -5
- package/dist/Components/Breadcrumb/composables/useBreadcrumb.js +2 -0
- package/dist/Components/BreadcrumbItem/BreadcrumbItem.vue.d.ts +17 -11
- package/dist/Components/BreadcrumbItem/BreadcrumbItem.vue_vue_type_script_setup_true_lang.js +2 -0
- package/dist/Components/BreadcrumbItem/breadcrumbItem.types.d.ts +21 -3
- package/dist/Components/BreadcrumbItem/composables/useBreadcrumbItem.d.ts +10 -6
- package/dist/Components/BreadcrumbItem/composables/useBreadcrumbItem.js +65 -59
- package/dist/Components/Button/Button.vue.d.ts +17 -8
- package/dist/Components/Button/Button.vue_vue_type_script_setup_true_lang.js +10 -10
- package/dist/Components/Button/button.types.d.ts +22 -5
- package/dist/Components/Button/composables/useButton.d.ts +198 -8
- package/dist/Components/Button/composables/useButton.js +101 -86
- package/dist/Components/Calendar/Calendar.vue.d.ts +2 -2
- package/dist/Components/Calendar/Calendar.vue_vue_type_script_setup_true_lang.js +68 -43
- package/dist/Components/Calendar/calendar.types.d.ts +12 -7
- package/dist/Components/Calendar/composables/useCalendar.d.ts +9 -9
- package/dist/Components/Calendar/composables/useCalendar.js +173 -114
- package/dist/Components/Calendar/index.d.ts +2 -1
- package/dist/Components/CalendarDate/composables/useCalendarDate.d.ts +1 -2
- package/dist/Components/CalendarDate/composables/useCalendarDate.js +56 -56
- package/dist/Components/CalendarMonth/CalendarMonth.vue.d.ts +2 -0
- package/dist/Components/CalendarMonth/CalendarMonth.vue_vue_type_script_setup_true_lang.js +7 -1
- package/dist/Components/CalendarMonth/calendarMonth.types.d.ts +43 -0
- package/dist/Components/CalendarMonth/composables/useCalendarMonth.d.ts +10 -2
- package/dist/Components/CalendarMonth/composables/useCalendarMonth.js +143 -70
- package/dist/Components/CalendarRange/CalendarRange.vue_vue_type_script_setup_true_lang.js +109 -87
- package/dist/Components/CalendarRange/calendarRange.types.d.ts +19 -2
- package/dist/Components/CalendarRange/composables/useCalendarRange.d.ts +15 -14
- package/dist/Components/CalendarRange/composables/useCalendarRange.js +237 -200
- package/dist/Components/CalendarYear/CalendarYear.vue.d.ts +2 -0
- package/dist/Components/CalendarYear/CalendarYear.vue_vue_type_script_setup_true_lang.js +6 -1
- package/dist/Components/CalendarYear/calendarYear.types.d.ts +37 -0
- package/dist/Components/CalendarYear/composables/useCalendarYear.d.ts +10 -2
- package/dist/Components/CalendarYear/composables/useCalendarYear.js +140 -72
- package/dist/Components/ColorField/ColorField.vue.d.ts +2 -2
- package/dist/Components/ColorField/composables/useColorField.d.ts +2 -2
- package/dist/Components/ColorPicker/composables/useColorPicker.js +1 -1
- package/dist/Components/DataTable/DataTable.vue.d.ts +2 -2
- package/dist/Components/DataTable/composables/useDataTable.d.ts +2 -2
- package/dist/Components/DataTable/composables/useDataTable.js +288 -282
- package/dist/Components/DateField/DateField.vue.d.ts +2 -2
- package/dist/Components/DateField/DateField.vue_vue_type_script_setup_true_lang.js +3 -1
- package/dist/Components/DateField/composables/useDateField.d.ts +3 -3
- package/dist/Components/DateField/composables/useDateField.js +94 -96
- package/dist/Components/DateField/dateField.types.d.ts +11 -4
- package/dist/Components/DatePicker/DatePicker.vue_vue_type_script_setup_true_lang.js +3 -0
- package/dist/Components/DatePicker/composables/useDatePicker.d.ts +1 -1
- package/dist/Components/DatePicker/composables/useDatePicker.js +1 -27
- package/dist/Components/DatePicker/datePicker.types.d.ts +11 -4
- package/dist/Components/DateRangeField/DateRangeField.vue.d.ts +2 -2
- package/dist/Components/DateRangeField/DateRangeField.vue_vue_type_script_setup_true_lang.js +5 -26
- package/dist/Components/DateRangeField/composables/useDateRangeField.d.ts +3 -3
- package/dist/Components/DateRangeField/composables/useDateRangeField.js +87 -88
- package/dist/Components/DateRangeField/dateRangeField.types.d.ts +15 -1
- package/dist/Components/DateRangePicker/DateRangePicker.vue_vue_type_script_setup_true_lang.js +6 -0
- package/dist/Components/DateRangePicker/composables/useDateRangePicker.d.ts +1 -1
- package/dist/Components/DateRangePicker/composables/useDateRangePicker.js +2 -0
- package/dist/Components/DateRangePicker/dateRangePicker.types.d.ts +15 -1
- package/dist/Components/DateTimeField/DateTimeField.vue.d.ts +2 -2
- package/dist/Components/DateTimeField/DateTimeField.vue_vue_type_script_setup_true_lang.js +3 -3
- package/dist/Components/DateTimeField/composables/useDateTimeField.d.ts +2 -2
- package/dist/Components/DateTimeField/composables/useDateTimeField.js +83 -83
- package/dist/Components/DateTimeField/dateTimeField.types.d.ts +3 -4
- package/dist/Components/DateTimePicker/composables/useDateTimePicker.js +76 -76
- package/dist/Components/DateTimePicker/dateTimePicker.types.d.ts +1 -2
- package/dist/Components/DateTimeRangeField/DateTimeRangeField.vue.d.ts +2 -2
- package/dist/Components/DateTimeRangeField/composables/useDateTimeRangeField.d.ts +2 -2
- package/dist/Components/DateTimeRangeField/composables/useDateTimeRangeField.js +73 -73
- package/dist/Components/DateTimeRangePicker/composables/useDateTimeRangePicker.js +85 -85
- package/dist/Components/Drawer/Drawer.vue.d.ts +1 -1
- package/dist/Components/Drawer/composables/useDrawer.d.ts +1 -1
- package/dist/Components/Drawer/composables/useDrawer.js +2 -2
- package/dist/Components/FileUpload/FileUpload.js +5 -0
- package/dist/Components/FileUpload/FileUpload.vue.d.ts +28 -0
- package/dist/Components/FileUpload/FileUpload.vue_vue_type_script_setup_true_lang.js +132 -0
- package/dist/Components/FileUpload/composables/useFileUpload.d.ts +70 -0
- package/dist/Components/FileUpload/composables/useFileUpload.js +210 -0
- package/dist/Components/FileUpload/fileUpload.types.d.ts +306 -0
- package/dist/Components/FileUpload/index.d.ts +3 -0
- package/dist/Components/FileUpload/index.js +3 -0
- package/dist/Components/FormField/composables/useFormField.d.ts +2 -2
- package/dist/Components/Link/Link.vue.d.ts +17 -8
- package/dist/Components/Link/Link.vue_vue_type_script_setup_true_lang.js +30 -25
- package/dist/Components/Link/composables/useLink.d.ts +8 -6
- package/dist/Components/Link/composables/useLink.js +52 -45
- package/dist/Components/Link/link.types.d.ts +21 -4
- package/dist/Components/ListItem/ListItem.vue.d.ts +17 -15
- package/dist/Components/ListItem/ListItem.vue_vue_type_script_setup_true_lang.js +16 -8
- package/dist/Components/ListItem/composables/useListItem.d.ts +11 -6
- package/dist/Components/ListItem/composables/useListItem.js +122 -102
- package/dist/Components/ListItem/listItem.types.d.ts +44 -7
- package/dist/Components/Listbox/composables/useListbox.d.ts +2 -2
- package/dist/Components/Menu/composables/useMenu.js +6 -6
- package/dist/Components/Modal/Modal.vue.d.ts +1 -1
- package/dist/Components/Modal/composables/useModal.d.ts +1 -1
- package/dist/Components/Modal/composables/useModal.js +2 -2
- package/dist/Components/NumberField/composables/useNumberField.d.ts +2 -2
- package/dist/Components/PasswordField/composables/usePasswordField.d.ts +2 -2
- package/dist/Components/RichTextEditor/RichTextEditor.js +5 -0
- package/dist/Components/RichTextEditor/RichTextEditor.vue.d.ts +23 -0
- package/dist/Components/RichTextEditor/RichTextEditor.vue_vue_type_script_setup_true_lang.js +104 -0
- package/dist/Components/RichTextEditor/composables/useRichTextEditor.d.ts +488 -0
- package/dist/Components/RichTextEditor/composables/useRichTextEditor.js +226 -0
- package/dist/Components/RichTextEditor/index.d.ts +3 -0
- package/dist/Components/RichTextEditor/index.js +3 -0
- package/dist/Components/RichTextEditor/richTextEditor.types.d.ts +103 -0
- package/dist/Components/Select/Select.vue.d.ts +2 -2
- package/dist/Components/Select/composables/useSelect.d.ts +2 -2
- package/dist/Components/Select/composables/useSelect.js +2 -2
- package/dist/Components/Sidebar/SidebarListItem.vue.d.ts +17 -9
- package/dist/Components/Sidebar/SidebarListItem.vue_vue_type_script_setup_true_lang.js +5 -0
- package/dist/Components/Sidebar/composables/useSidebarListItem.js +1 -1
- package/dist/Components/Sidebar/sidebar.types.d.ts +2 -1
- package/dist/Components/Snackbar/composables/useSnackbar.js +1 -1
- package/dist/Components/Tabs/composables/useTabs.d.ts +156 -0
- package/dist/Components/TextField/composables/useTextField.d.ts +2 -2
- package/dist/Components/Textarea/composables/useTextarea.d.ts +2 -2
- package/dist/Components/Textarea/composables/useTextarea.js +1 -1
- package/dist/Components/TimeField/TimeField.vue.d.ts +2 -2
- package/dist/Components/TimeField/composables/useTimeField.d.ts +2 -2
- package/dist/Components/TimeField/composables/useTimeField.js +84 -84
- package/dist/Components/TimePanel/composables/useTimePanel.js +119 -119
- package/dist/Components/TimeRangeField/TimeRangeField.vue.d.ts +2 -2
- package/dist/Components/TimeRangeField/composables/useTimeRangeField.d.ts +2 -2
- package/dist/Components/TimeRangeField/composables/useTimeRangeField.js +88 -88
- package/dist/Components/TimeRangePicker/composables/useTimeRangePicker.js +85 -85
- package/dist/Components/Tooltip/composables/useTooltip.js +3 -3
- package/dist/Provider/bridgeUITypes.d.ts +3 -0
- package/dist/Provider/createBridgeUIApi.js +38 -32
- package/dist/Utils/linkAs.d.ts +29 -0
- package/dist/Utils/linkAs.js +18 -0
- package/dist/augments.d.ts +10 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +178 -173
- package/dist/theme.css +3 -0
- package/docs/README.md +18 -9
- package/docs/components/Breadcrumb.md +16 -0
- package/docs/components/BridgeUIProvider.md +57 -14
- package/docs/components/Button.md +31 -19
- package/docs/components/Calendar.md +33 -30
- package/docs/components/CalendarMonth.md +25 -18
- package/docs/components/CalendarRange.md +31 -27
- package/docs/components/CalendarYear.md +25 -19
- package/docs/components/DataTable.md +1 -1
- package/docs/components/DateField.md +37 -26
- package/docs/components/DatePicker.md +31 -28
- package/docs/components/DateRangeField.md +6 -2
- package/docs/components/DateRangePicker.md +30 -26
- package/docs/components/FileUpload.md +122 -0
- package/docs/components/I18n.md +7 -7
- package/docs/components/Icon.md +12 -12
- package/docs/components/Link.md +28 -12
- package/docs/components/List.md +32 -15
- package/docs/components/RichTextEditor.md +88 -0
- package/docs/components/Sidebar.md +12 -1
- package/package.json +111 -19
- package/docs/examples/date-date-fns.ts +0 -286
- package/docs/examples/date-dayjs.ts +0 -327
- package/docs/examples/date-luxon.ts +0 -332
- package/docs/examples/date-moment.ts +0 -334
- package/docs/examples/i18n-dictionary.ts +0 -79
- package/docs/examples/i18n-vue-i18n.ts +0 -35
- package/docs/examples/icon-fontawesome.ts +0 -141
- package/docs/examples/icon-heroicons.ts +0 -87
- package/docs/examples/icon-lucide.ts +0 -87
- package/docs/examples/icon-phosphor.ts +0 -87
- package/docs/examples/icon-tabler.ts +0 -87
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Example Day.js date adapter for `@bridge-ui/vue`.
|
|
3
|
-
* Copy into your app or wire via `BridgeUIProvider` / `createBridgeUI` `global.dates`.
|
|
4
|
-
* Not published as an npm package.
|
|
5
|
-
*
|
|
6
|
-
* Requires `dayjs`. Loads `utc`, `timezone`, and `customParseFormat` plugins.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// ** External Imports
|
|
10
|
-
import dayjs, { type Dayjs } from "dayjs";
|
|
11
|
-
import customParseFormat from "dayjs/plugin/customParseFormat";
|
|
12
|
-
import timezone from "dayjs/plugin/timezone";
|
|
13
|
-
import utc from "dayjs/plugin/utc";
|
|
14
|
-
import { clamp, isNil, isString, range } from "es-toolkit/compat";
|
|
15
|
-
|
|
16
|
-
// ** Core Imports
|
|
17
|
-
import type {
|
|
18
|
-
DateAdapter,
|
|
19
|
-
DateAdapterContext,
|
|
20
|
-
DateAdapterTimeOptions,
|
|
21
|
-
} from "@bridge-ui/core/Adapters";
|
|
22
|
-
|
|
23
|
-
dayjs.extend(utc);
|
|
24
|
-
dayjs.extend(timezone);
|
|
25
|
-
dayjs.extend(customParseFormat);
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Options for {@link createDayjsDateAdapter}.
|
|
29
|
-
*/
|
|
30
|
-
export type DayjsDateAdapterOptions = {
|
|
31
|
-
/**
|
|
32
|
-
* Default locale when context omits `locale`.
|
|
33
|
-
*
|
|
34
|
-
* @default undefined
|
|
35
|
-
*/
|
|
36
|
-
locale?: string;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Default IANA time zone when context omits `timeZone`.
|
|
40
|
-
*
|
|
41
|
-
* @default undefined (system local zone)
|
|
42
|
-
*/
|
|
43
|
-
timeZone?: string;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Builds a Day.js-backed {@link DateAdapter} (`TDate = Date`) for Bridge calendars.
|
|
48
|
-
*/
|
|
49
|
-
export function createDayjsDateAdapter(
|
|
50
|
-
options: DayjsDateAdapterOptions = {},
|
|
51
|
-
): DateAdapter<Date> {
|
|
52
|
-
const resolveLocale = (context?: DateAdapterContext) => {
|
|
53
|
-
return context?.locale ?? options.locale;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const resolveZone = (context?: DateAdapterContext) => {
|
|
57
|
-
return context?.timeZone ?? options.timeZone;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const toDayjs = (date: Date, context?: DateAdapterContext): Dayjs => {
|
|
61
|
-
const locale = resolveLocale(context);
|
|
62
|
-
const zone = resolveZone(context);
|
|
63
|
-
let value = isNil(zone) ? dayjs(date) : dayjs(date).tz(zone);
|
|
64
|
-
|
|
65
|
-
if (!isNil(locale)) {
|
|
66
|
-
value = value.locale(locale);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return value;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const fromDayjs = (value: Dayjs): Date => {
|
|
73
|
-
return value.toDate();
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const isValid = (date: Date) => {
|
|
77
|
-
return date instanceof Date && !Number.isNaN(date.getTime());
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const adapter: DateAdapter<Date> = {
|
|
81
|
-
getDay: (date, context) => toDayjs(date, context).day(),
|
|
82
|
-
|
|
83
|
-
getDate: (date, context) => toDayjs(date, context).date(),
|
|
84
|
-
|
|
85
|
-
getYear: (date, context) => toDayjs(date, context).year(),
|
|
86
|
-
|
|
87
|
-
getHours: (date, context) => toDayjs(date, context).hour(),
|
|
88
|
-
|
|
89
|
-
getMonth: (date, context) => toDayjs(date, context).month(),
|
|
90
|
-
|
|
91
|
-
isAfter: (a, b, context) => adapter.isBefore(b, a, context),
|
|
92
|
-
|
|
93
|
-
getMinutes: (date, context) => toDayjs(date, context).minute(),
|
|
94
|
-
|
|
95
|
-
getSeconds: (date, context) => toDayjs(date, context).second(),
|
|
96
|
-
|
|
97
|
-
setDate: (date, day, context) => {
|
|
98
|
-
return fromDayjs(toDayjs(date, context).date(day));
|
|
99
|
-
},
|
|
100
|
-
|
|
101
|
-
setYear: (date, year, context) => {
|
|
102
|
-
return fromDayjs(toDayjs(date, context).year(year));
|
|
103
|
-
},
|
|
104
|
-
|
|
105
|
-
startOfDay: (date, context) => {
|
|
106
|
-
return fromDayjs(toDayjs(date, context).startOf("day"));
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
endOfMonth: (date, context) => {
|
|
110
|
-
return fromDayjs(toDayjs(date, context).endOf("month"));
|
|
111
|
-
},
|
|
112
|
-
|
|
113
|
-
setMonth: (date, month, context) => {
|
|
114
|
-
return fromDayjs(toDayjs(date, context).month(month));
|
|
115
|
-
},
|
|
116
|
-
|
|
117
|
-
startOfMonth: (date, context) => {
|
|
118
|
-
return fromDayjs(toDayjs(date, context).startOf("month"));
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
isSameDay: (a, b, context) => {
|
|
122
|
-
return toDayjs(a, context).isSame(toDayjs(b, context), "day");
|
|
123
|
-
},
|
|
124
|
-
|
|
125
|
-
isSameYear: (a, b, context) => {
|
|
126
|
-
return toDayjs(a, context).isSame(toDayjs(b, context), "year");
|
|
127
|
-
},
|
|
128
|
-
|
|
129
|
-
isSameMonth: (a, b, context) => {
|
|
130
|
-
return toDayjs(a, context).isSame(toDayjs(b, context), "month");
|
|
131
|
-
},
|
|
132
|
-
|
|
133
|
-
addDays: (date, amount, context) => {
|
|
134
|
-
return fromDayjs(toDayjs(date, context).add(amount, "day"));
|
|
135
|
-
},
|
|
136
|
-
|
|
137
|
-
addYears: (date, amount, context) => {
|
|
138
|
-
return fromDayjs(toDayjs(date, context).add(amount, "year"));
|
|
139
|
-
},
|
|
140
|
-
|
|
141
|
-
addMonths: (date, amount, context) => {
|
|
142
|
-
return fromDayjs(toDayjs(date, context).add(amount, "month"));
|
|
143
|
-
},
|
|
144
|
-
|
|
145
|
-
setHours: (date, hours, context) => {
|
|
146
|
-
return fromDayjs(toDayjs(date, context).hour(clamp(hours, 0, 23)));
|
|
147
|
-
},
|
|
148
|
-
|
|
149
|
-
setMinutes: (date, minutes, context) => {
|
|
150
|
-
return fromDayjs(toDayjs(date, context).minute(clamp(minutes, 0, 59)));
|
|
151
|
-
},
|
|
152
|
-
|
|
153
|
-
setSeconds: (date, seconds, context) => {
|
|
154
|
-
return fromDayjs(toDayjs(date, context).second(clamp(seconds, 0, 59)));
|
|
155
|
-
},
|
|
156
|
-
|
|
157
|
-
isBefore: (a, b, context) => {
|
|
158
|
-
return toDayjs(a, context)
|
|
159
|
-
.startOf("day")
|
|
160
|
-
.isBefore(toDayjs(b, context).startOf("day"));
|
|
161
|
-
},
|
|
162
|
-
|
|
163
|
-
parseTime: (value, context, timeOptions) => {
|
|
164
|
-
return parseTimeWithDayjs({
|
|
165
|
-
value,
|
|
166
|
-
adapter,
|
|
167
|
-
context,
|
|
168
|
-
toDayjs,
|
|
169
|
-
fromDayjs,
|
|
170
|
-
timeOptions,
|
|
171
|
-
});
|
|
172
|
-
},
|
|
173
|
-
|
|
174
|
-
getMonthNames: (context) => {
|
|
175
|
-
const locale = resolveLocale(context);
|
|
176
|
-
|
|
177
|
-
return range(12).map((month) => {
|
|
178
|
-
return new Intl.DateTimeFormat(locale, { month: "long" }).format(
|
|
179
|
-
new Date(2021, month, 1),
|
|
180
|
-
);
|
|
181
|
-
});
|
|
182
|
-
},
|
|
183
|
-
|
|
184
|
-
isSameTime: (a, b, context) => {
|
|
185
|
-
const left = toDayjs(a, context);
|
|
186
|
-
const right = toDayjs(b, context);
|
|
187
|
-
|
|
188
|
-
return (
|
|
189
|
-
left.hour() === right.hour() &&
|
|
190
|
-
left.minute() === right.minute() &&
|
|
191
|
-
left.second() === right.second()
|
|
192
|
-
);
|
|
193
|
-
},
|
|
194
|
-
|
|
195
|
-
now: (context) => {
|
|
196
|
-
const zone = resolveZone(context);
|
|
197
|
-
const locale = resolveLocale(context);
|
|
198
|
-
let value = isNil(zone) ? dayjs() : dayjs().tz(zone);
|
|
199
|
-
|
|
200
|
-
if (!isNil(locale)) {
|
|
201
|
-
value = value.locale(locale);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return fromDayjs(value);
|
|
205
|
-
},
|
|
206
|
-
|
|
207
|
-
format: (date, context) => {
|
|
208
|
-
if (!isValid(date)) {
|
|
209
|
-
return "";
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const locale = resolveLocale(context);
|
|
213
|
-
const timeZone = resolveZone(context);
|
|
214
|
-
|
|
215
|
-
return new Intl.DateTimeFormat(locale, {
|
|
216
|
-
timeZone,
|
|
217
|
-
day: "2-digit",
|
|
218
|
-
year: "numeric",
|
|
219
|
-
month: "2-digit",
|
|
220
|
-
}).format(date);
|
|
221
|
-
},
|
|
222
|
-
|
|
223
|
-
getWeekdayNames: (context) => {
|
|
224
|
-
const locale = resolveLocale(context);
|
|
225
|
-
const formatter = new Intl.DateTimeFormat(locale, { weekday: "short" });
|
|
226
|
-
const sunday = new Date(2021, 0, 3);
|
|
227
|
-
|
|
228
|
-
return range(7).map((index) => {
|
|
229
|
-
const day = new Date(sunday);
|
|
230
|
-
|
|
231
|
-
day.setDate(sunday.getDate() + index);
|
|
232
|
-
|
|
233
|
-
return formatter.format(day);
|
|
234
|
-
});
|
|
235
|
-
},
|
|
236
|
-
|
|
237
|
-
parse: (value, context) => {
|
|
238
|
-
if (!isString(value) || value.trim() === "") {
|
|
239
|
-
return null;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const trimmed = value.trim();
|
|
243
|
-
const zone = resolveZone(context);
|
|
244
|
-
const parsed = isNil(zone) ? dayjs(trimmed) : dayjs.tz(trimmed, zone);
|
|
245
|
-
|
|
246
|
-
if (!parsed.isValid()) {
|
|
247
|
-
return null;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
return fromDayjs(parsed.startOf("day"));
|
|
251
|
-
},
|
|
252
|
-
|
|
253
|
-
getCalendarDays: (view, startOfWeek, context) => {
|
|
254
|
-
const monthStart = adapter.startOfMonth(view, context);
|
|
255
|
-
const weekday = adapter.getDay(monthStart, context);
|
|
256
|
-
const normalizedStart = ((startOfWeek % 7) + 7) % 7;
|
|
257
|
-
const leading = (weekday - normalizedStart + 7) % 7;
|
|
258
|
-
const gridStart = adapter.addDays(monthStart, -leading, context);
|
|
259
|
-
|
|
260
|
-
return range(42).map((index) => {
|
|
261
|
-
return adapter.addDays(gridStart, index, context);
|
|
262
|
-
});
|
|
263
|
-
},
|
|
264
|
-
|
|
265
|
-
formatTime: (date, context, timeOptions) => {
|
|
266
|
-
if (!isValid(date)) {
|
|
267
|
-
return "";
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
const locale = resolveLocale(context);
|
|
271
|
-
const timeZone = resolveZone(context);
|
|
272
|
-
const ampm = timeOptions?.ampm === true;
|
|
273
|
-
const showSeconds = timeOptions?.showSeconds === true;
|
|
274
|
-
|
|
275
|
-
return new Intl.DateTimeFormat(locale, {
|
|
276
|
-
timeZone,
|
|
277
|
-
hour12: ampm,
|
|
278
|
-
hour: "2-digit",
|
|
279
|
-
minute: "2-digit",
|
|
280
|
-
...(showSeconds ? { second: "2-digit" as const } : {}),
|
|
281
|
-
}).format(date);
|
|
282
|
-
},
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
return adapter;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
function parseTimeWithDayjs(input: {
|
|
289
|
-
adapter: DateAdapter<Date>;
|
|
290
|
-
context?: DateAdapterContext;
|
|
291
|
-
fromDayjs: (value: Dayjs) => Date;
|
|
292
|
-
timeOptions?: DateAdapterTimeOptions;
|
|
293
|
-
toDayjs: (date: Date, context?: DateAdapterContext) => Dayjs;
|
|
294
|
-
value: string;
|
|
295
|
-
}): Date | null {
|
|
296
|
-
const { value, adapter, context, toDayjs, fromDayjs, timeOptions } = input;
|
|
297
|
-
|
|
298
|
-
if (!isString(value) || value.trim() === "") {
|
|
299
|
-
return null;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const trimmed = value.trim();
|
|
303
|
-
const ampm = timeOptions?.ampm === true;
|
|
304
|
-
const showSeconds = timeOptions?.showSeconds === true;
|
|
305
|
-
const format = ampm
|
|
306
|
-
? showSeconds
|
|
307
|
-
? "h:mm:ss A"
|
|
308
|
-
: "h:mm A"
|
|
309
|
-
: showSeconds
|
|
310
|
-
? "H:mm:ss"
|
|
311
|
-
: "H:mm";
|
|
312
|
-
const parsed = dayjs(trimmed, format, true);
|
|
313
|
-
|
|
314
|
-
if (!parsed.isValid()) {
|
|
315
|
-
return null;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
const base = toDayjs(adapter.now(context), context);
|
|
319
|
-
|
|
320
|
-
return fromDayjs(
|
|
321
|
-
base
|
|
322
|
-
.hour(parsed.hour())
|
|
323
|
-
.minute(parsed.minute())
|
|
324
|
-
.second(showSeconds ? parsed.second() : 0)
|
|
325
|
-
.millisecond(0),
|
|
326
|
-
);
|
|
327
|
-
}
|
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Example Luxon date adapter for `@bridge-ui/vue`.
|
|
3
|
-
* Copy into your app or wire via `BridgeUIProvider` / `createBridgeUI` `global.dates`.
|
|
4
|
-
* Not published as an npm package.
|
|
5
|
-
*
|
|
6
|
-
* Requires `luxon`. Strong IANA time-zone support via `DateTime.setZone`.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// ** External Imports
|
|
10
|
-
import { clamp, isNil, isString, range } from "es-toolkit/compat";
|
|
11
|
-
import { DateTime, Info } from "luxon";
|
|
12
|
-
|
|
13
|
-
// ** Core Imports
|
|
14
|
-
import type {
|
|
15
|
-
DateAdapter,
|
|
16
|
-
DateAdapterContext,
|
|
17
|
-
DateAdapterTimeOptions,
|
|
18
|
-
} from "@bridge-ui/core/Adapters";
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Options for {@link createLuxonDateAdapter}.
|
|
22
|
-
*/
|
|
23
|
-
export type LuxonDateAdapterOptions = {
|
|
24
|
-
/**
|
|
25
|
-
* Default locale when context omits `locale`.
|
|
26
|
-
*
|
|
27
|
-
* @default undefined
|
|
28
|
-
*/
|
|
29
|
-
locale?: string;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Default IANA time zone when context omits `timeZone`.
|
|
33
|
-
*
|
|
34
|
-
* @default undefined (system local zone)
|
|
35
|
-
*/
|
|
36
|
-
timeZone?: string;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Builds a Luxon-backed {@link DateAdapter} (`TDate = Date`) for Bridge calendars.
|
|
41
|
-
*/
|
|
42
|
-
export function createLuxonDateAdapter(
|
|
43
|
-
options: LuxonDateAdapterOptions = {},
|
|
44
|
-
): DateAdapter<Date> {
|
|
45
|
-
const resolveLocale = (context?: DateAdapterContext) => {
|
|
46
|
-
return context?.locale ?? options.locale;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const resolveZone = (context?: DateAdapterContext) => {
|
|
50
|
-
return context?.timeZone ?? options.timeZone;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const toDateTime = (date: Date, context?: DateAdapterContext): DateTime => {
|
|
54
|
-
const locale = resolveLocale(context);
|
|
55
|
-
const zone = resolveZone(context);
|
|
56
|
-
let value = DateTime.fromJSDate(date);
|
|
57
|
-
|
|
58
|
-
if (!isNil(zone)) {
|
|
59
|
-
value = value.setZone(zone);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (!isNil(locale)) {
|
|
63
|
-
value = value.setLocale(locale);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return value;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const fromDateTime = (value: DateTime): Date => {
|
|
70
|
-
return value.toJSDate();
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const isValid = (date: Date) => {
|
|
74
|
-
return date instanceof Date && !Number.isNaN(date.getTime());
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const adapter: DateAdapter<Date> = {
|
|
78
|
-
getDate: (date, context) => toDateTime(date, context).day,
|
|
79
|
-
|
|
80
|
-
getYear: (date, context) => toDateTime(date, context).year,
|
|
81
|
-
|
|
82
|
-
getHours: (date, context) => toDateTime(date, context).hour,
|
|
83
|
-
|
|
84
|
-
isAfter: (a, b, context) => adapter.isBefore(b, a, context),
|
|
85
|
-
|
|
86
|
-
getMinutes: (date, context) => toDateTime(date, context).minute,
|
|
87
|
-
|
|
88
|
-
getSeconds: (date, context) => toDateTime(date, context).second,
|
|
89
|
-
|
|
90
|
-
getMonth: (date, context) => toDateTime(date, context).month - 1,
|
|
91
|
-
|
|
92
|
-
getDay: (date, context) => toDateTime(date, context).weekday % 7,
|
|
93
|
-
|
|
94
|
-
startOfDay: (date, context) => {
|
|
95
|
-
return fromDateTime(toDateTime(date, context).startOf("day"));
|
|
96
|
-
},
|
|
97
|
-
|
|
98
|
-
setDate: (date, day, context) => {
|
|
99
|
-
return fromDateTime(toDateTime(date, context).set({ day }));
|
|
100
|
-
},
|
|
101
|
-
|
|
102
|
-
setYear: (date, year, context) => {
|
|
103
|
-
return fromDateTime(toDateTime(date, context).set({ year }));
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
startOfMonth: (date, context) => {
|
|
107
|
-
return fromDateTime(toDateTime(date, context).startOf("month"));
|
|
108
|
-
},
|
|
109
|
-
|
|
110
|
-
isSameDay: (a, b, context) => {
|
|
111
|
-
return toDateTime(a, context).hasSame(toDateTime(b, context), "day");
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
isSameYear: (a, b, context) => {
|
|
115
|
-
return toDateTime(a, context).hasSame(toDateTime(b, context), "year");
|
|
116
|
-
},
|
|
117
|
-
|
|
118
|
-
isSameMonth: (a, b, context) => {
|
|
119
|
-
return toDateTime(a, context).hasSame(toDateTime(b, context), "month");
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
addDays: (date, amount, context) => {
|
|
123
|
-
return fromDateTime(toDateTime(date, context).plus({ days: amount }));
|
|
124
|
-
},
|
|
125
|
-
|
|
126
|
-
addYears: (date, amount, context) => {
|
|
127
|
-
return fromDateTime(toDateTime(date, context).plus({ years: amount }));
|
|
128
|
-
},
|
|
129
|
-
|
|
130
|
-
setMonth: (date, month, context) => {
|
|
131
|
-
return fromDateTime(toDateTime(date, context).set({ month: month + 1 }));
|
|
132
|
-
},
|
|
133
|
-
|
|
134
|
-
addMonths: (date, amount, context) => {
|
|
135
|
-
return fromDateTime(toDateTime(date, context).plus({ months: amount }));
|
|
136
|
-
},
|
|
137
|
-
|
|
138
|
-
getMonthNames: (context) => {
|
|
139
|
-
const locale = resolveLocale(context) ?? "en-US";
|
|
140
|
-
|
|
141
|
-
return Info.months("long", { locale });
|
|
142
|
-
},
|
|
143
|
-
|
|
144
|
-
endOfMonth: (date, context) => {
|
|
145
|
-
return fromDateTime(
|
|
146
|
-
toDateTime(date, context).endOf("month").startOf("second"),
|
|
147
|
-
);
|
|
148
|
-
},
|
|
149
|
-
|
|
150
|
-
setHours: (date, hours, context) => {
|
|
151
|
-
return fromDateTime(
|
|
152
|
-
toDateTime(date, context).set({ hour: clamp(hours, 0, 23) }),
|
|
153
|
-
);
|
|
154
|
-
},
|
|
155
|
-
|
|
156
|
-
isBefore: (a, b, context) => {
|
|
157
|
-
return (
|
|
158
|
-
toDateTime(a, context).startOf("day") <
|
|
159
|
-
toDateTime(b, context).startOf("day")
|
|
160
|
-
);
|
|
161
|
-
},
|
|
162
|
-
|
|
163
|
-
setMinutes: (date, minutes, context) => {
|
|
164
|
-
return fromDateTime(
|
|
165
|
-
toDateTime(date, context).set({ minute: clamp(minutes, 0, 59) }),
|
|
166
|
-
);
|
|
167
|
-
},
|
|
168
|
-
|
|
169
|
-
setSeconds: (date, seconds, context) => {
|
|
170
|
-
return fromDateTime(
|
|
171
|
-
toDateTime(date, context).set({ second: clamp(seconds, 0, 59) }),
|
|
172
|
-
);
|
|
173
|
-
},
|
|
174
|
-
|
|
175
|
-
parseTime: (value, context, timeOptions) => {
|
|
176
|
-
return parseTimeWithLuxon({
|
|
177
|
-
value,
|
|
178
|
-
adapter,
|
|
179
|
-
context,
|
|
180
|
-
toDateTime,
|
|
181
|
-
timeOptions,
|
|
182
|
-
fromDateTime,
|
|
183
|
-
});
|
|
184
|
-
},
|
|
185
|
-
|
|
186
|
-
format: (date, context) => {
|
|
187
|
-
if (!isValid(date)) {
|
|
188
|
-
return "";
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return toDateTime(date, context).toLocaleString({
|
|
192
|
-
day: "2-digit",
|
|
193
|
-
year: "numeric",
|
|
194
|
-
month: "2-digit",
|
|
195
|
-
});
|
|
196
|
-
},
|
|
197
|
-
|
|
198
|
-
isSameTime: (a, b, context) => {
|
|
199
|
-
const left = toDateTime(a, context);
|
|
200
|
-
const right = toDateTime(b, context);
|
|
201
|
-
|
|
202
|
-
return (
|
|
203
|
-
left.hour === right.hour &&
|
|
204
|
-
left.minute === right.minute &&
|
|
205
|
-
left.second === right.second
|
|
206
|
-
);
|
|
207
|
-
},
|
|
208
|
-
|
|
209
|
-
getWeekdayNames: (context) => {
|
|
210
|
-
const locale = resolveLocale(context) ?? "en-US";
|
|
211
|
-
// Luxon weekdays are Monday-first; Bridge expects Sunday → Saturday.
|
|
212
|
-
const names = Info.weekdays("short", { locale });
|
|
213
|
-
|
|
214
|
-
return [names[6]!, ...names.slice(0, 6)];
|
|
215
|
-
},
|
|
216
|
-
|
|
217
|
-
now: (context) => {
|
|
218
|
-
const zone = resolveZone(context);
|
|
219
|
-
const locale = resolveLocale(context);
|
|
220
|
-
let value: DateTime = DateTime.now();
|
|
221
|
-
|
|
222
|
-
if (!isNil(zone)) {
|
|
223
|
-
value = value.setZone(zone);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (!isNil(locale)) {
|
|
227
|
-
value = value.setLocale(locale);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return fromDateTime(value);
|
|
231
|
-
},
|
|
232
|
-
|
|
233
|
-
formatTime: (date, context, timeOptions) => {
|
|
234
|
-
if (!isValid(date)) {
|
|
235
|
-
return "";
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const ampm = timeOptions?.ampm === true;
|
|
239
|
-
const showSeconds = timeOptions?.showSeconds === true;
|
|
240
|
-
|
|
241
|
-
return toDateTime(date, context).toLocaleString({
|
|
242
|
-
hour: "2-digit",
|
|
243
|
-
minute: "2-digit",
|
|
244
|
-
hourCycle: ampm ? "h12" : "h23",
|
|
245
|
-
...(showSeconds ? { second: "2-digit" as const } : {}),
|
|
246
|
-
});
|
|
247
|
-
},
|
|
248
|
-
|
|
249
|
-
getCalendarDays: (view, startOfWeek, context) => {
|
|
250
|
-
const monthStart = adapter.startOfMonth(view, context);
|
|
251
|
-
const weekday = adapter.getDay(monthStart, context);
|
|
252
|
-
const normalizedStart = ((startOfWeek % 7) + 7) % 7;
|
|
253
|
-
const leading = (weekday - normalizedStart + 7) % 7;
|
|
254
|
-
const gridStart = adapter.addDays(monthStart, -leading, context);
|
|
255
|
-
|
|
256
|
-
return range(42).map((index) => {
|
|
257
|
-
return adapter.addDays(gridStart, index, context);
|
|
258
|
-
});
|
|
259
|
-
},
|
|
260
|
-
|
|
261
|
-
parse: (value, context) => {
|
|
262
|
-
if (!isString(value) || value.trim() === "") {
|
|
263
|
-
return null;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
const trimmed = value.trim();
|
|
267
|
-
const iso = DateTime.fromISO(trimmed, {
|
|
268
|
-
zone: resolveZone(context),
|
|
269
|
-
locale: resolveLocale(context),
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
if (iso.isValid) {
|
|
273
|
-
return fromDateTime(iso.startOf("day"));
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
const parsed = DateTime.fromJSDate(new Date(trimmed), {
|
|
277
|
-
zone: resolveZone(context),
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
if (!parsed.isValid) {
|
|
281
|
-
return null;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
return fromDateTime(parsed.startOf("day"));
|
|
285
|
-
},
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
return adapter;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
function parseTimeWithLuxon(input: {
|
|
292
|
-
adapter: DateAdapter<Date>;
|
|
293
|
-
context?: DateAdapterContext;
|
|
294
|
-
fromDateTime: (value: DateTime) => Date;
|
|
295
|
-
timeOptions?: DateAdapterTimeOptions;
|
|
296
|
-
toDateTime: (date: Date, context?: DateAdapterContext) => DateTime;
|
|
297
|
-
value: string;
|
|
298
|
-
}): Date | null {
|
|
299
|
-
const { value, adapter, context, toDateTime, timeOptions, fromDateTime } =
|
|
300
|
-
input;
|
|
301
|
-
|
|
302
|
-
if (!isString(value) || value.trim() === "") {
|
|
303
|
-
return null;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
const trimmed = value.trim();
|
|
307
|
-
const ampm = timeOptions?.ampm === true;
|
|
308
|
-
const showSeconds = timeOptions?.showSeconds === true;
|
|
309
|
-
const format = ampm
|
|
310
|
-
? showSeconds
|
|
311
|
-
? "h:mm:ss a"
|
|
312
|
-
: "h:mm a"
|
|
313
|
-
: showSeconds
|
|
314
|
-
? "H:mm:ss"
|
|
315
|
-
: "H:mm";
|
|
316
|
-
const parsed = DateTime.fromFormat(trimmed, format, { locale: "en-US" });
|
|
317
|
-
|
|
318
|
-
if (!parsed.isValid) {
|
|
319
|
-
return null;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
const base = toDateTime(adapter.now(context), context);
|
|
323
|
-
|
|
324
|
-
return fromDateTime(
|
|
325
|
-
base.set({
|
|
326
|
-
millisecond: 0,
|
|
327
|
-
hour: parsed.hour,
|
|
328
|
-
minute: parsed.minute,
|
|
329
|
-
second: showSeconds ? parsed.second : 0,
|
|
330
|
-
}),
|
|
331
|
-
);
|
|
332
|
-
}
|