@getcortexlabs/mavis-core 0.1.0-alpha.1 → 0.1.0-alpha.10
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 +2 -2
- package/dist/accordion.d.ts +17 -0
- package/dist/accordion.d.ts.map +1 -0
- package/dist/accordion.js +42 -0
- package/dist/accordion.js.map +1 -0
- package/dist/alert.d.ts +21 -0
- package/dist/alert.d.ts.map +1 -0
- package/dist/alert.js +13 -0
- package/dist/alert.js.map +1 -0
- package/dist/app-icons.d.ts +27 -0
- package/dist/app-icons.d.ts.map +1 -0
- package/dist/app-icons.js +42 -0
- package/dist/app-icons.js.map +1 -0
- package/dist/avatar.d.ts +10 -0
- package/dist/avatar.d.ts.map +1 -0
- package/dist/avatar.js +11 -0
- package/dist/avatar.js.map +1 -0
- package/dist/badge.d.ts +7 -0
- package/dist/badge.d.ts.map +1 -0
- package/dist/badge.js +11 -0
- package/dist/badge.js.map +1 -0
- package/dist/capabilities.d.ts +132 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +168 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/chip.d.ts +9 -0
- package/dist/chip.d.ts.map +1 -0
- package/dist/chip.js +16 -0
- package/dist/chip.js.map +1 -0
- package/dist/choice-motion.d.ts +14 -0
- package/dist/choice-motion.d.ts.map +1 -0
- package/dist/choice-motion.js +5 -0
- package/dist/choice-motion.js.map +1 -0
- package/dist/choice.d.ts +15 -0
- package/dist/choice.d.ts.map +1 -0
- package/dist/choice.js +27 -0
- package/dist/choice.js.map +1 -0
- package/dist/collections.d.ts +46 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +48 -0
- package/dist/collections.js.map +1 -0
- package/dist/combobox.d.ts +42 -0
- package/dist/combobox.d.ts.map +1 -0
- package/dist/combobox.js +159 -0
- package/dist/combobox.js.map +1 -0
- package/dist/contracts.d.ts +1321 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +268 -0
- package/dist/contracts.js.map +1 -0
- package/dist/date-input.d.ts +10 -0
- package/dist/date-input.d.ts.map +1 -0
- package/dist/date-input.js +58 -0
- package/dist/date-input.js.map +1 -0
- package/dist/date-time.d.ts +19 -0
- package/dist/date-time.d.ts.map +1 -0
- package/dist/date-time.js +27 -0
- package/dist/date-time.js.map +1 -0
- package/dist/date.d.ts +96 -0
- package/dist/date.d.ts.map +1 -0
- package/dist/date.js +235 -0
- package/dist/date.js.map +1 -0
- package/dist/dialog.d.ts +4 -0
- package/dist/dialog.d.ts.map +1 -0
- package/dist/dialog.js +21 -0
- package/dist/dialog.js.map +1 -0
- package/dist/empty-state.d.ts +2 -0
- package/dist/empty-state.d.ts.map +1 -0
- package/dist/empty-state.js +5 -0
- package/dist/empty-state.js.map +1 -0
- package/dist/experimental-collections.d.ts +82 -0
- package/dist/experimental-collections.d.ts.map +1 -0
- package/dist/experimental-collections.js +8 -0
- package/dist/experimental-collections.js.map +1 -0
- package/dist/experimental-effects.d.ts +107 -0
- package/dist/experimental-effects.d.ts.map +1 -0
- package/dist/experimental-effects.js +24 -0
- package/dist/experimental-effects.js.map +1 -0
- package/dist/experimental-platforms.d.ts +94 -0
- package/dist/experimental-platforms.d.ts.map +1 -0
- package/dist/experimental-platforms.js +2 -0
- package/dist/experimental-platforms.js.map +1 -0
- package/dist/experimental-playback.d.ts +63 -0
- package/dist/experimental-playback.d.ts.map +1 -0
- package/dist/experimental-playback.js +46 -0
- package/dist/experimental-playback.js.map +1 -0
- package/dist/experimental-regions.d.ts +179 -0
- package/dist/experimental-regions.d.ts.map +1 -0
- package/dist/experimental-regions.js +554 -0
- package/dist/experimental-regions.js.map +1 -0
- package/dist/experimental-sensors.d.ts +42 -0
- package/dist/experimental-sensors.d.ts.map +1 -0
- package/dist/experimental-sensors.js +2 -0
- package/dist/experimental-sensors.js.map +1 -0
- package/dist/experimental-surfaces.d.ts +127 -0
- package/dist/experimental-surfaces.d.ts.map +1 -0
- package/dist/experimental-surfaces.js +2 -0
- package/dist/experimental-surfaces.js.map +1 -0
- package/dist/experimental.d.ts +197 -0
- package/dist/experimental.d.ts.map +1 -0
- package/dist/experimental.js +855 -0
- package/dist/experimental.js.map +1 -0
- package/dist/files.d.ts +87 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +328 -0
- package/dist/files.js.map +1 -0
- package/dist/form.d.ts +39 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/form.js +170 -0
- package/dist/form.js.map +1 -0
- package/dist/grid.d.ts +3 -0
- package/dist/grid.d.ts.map +1 -0
- package/dist/grid.js +16 -0
- package/dist/grid.js.map +1 -0
- package/dist/icon.d.ts +15 -0
- package/dist/icon.d.ts.map +1 -0
- package/dist/icon.js +28 -0
- package/dist/icon.js.map +1 -0
- package/dist/icons.d.ts +2002 -0
- package/dist/icons.d.ts.map +1 -0
- package/dist/icons.js +2003 -0
- package/dist/icons.js.map +1 -0
- package/dist/index.d.ts +56 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -1
- package/dist/index.js.map +1 -1
- package/dist/input.d.ts +14 -0
- package/dist/input.d.ts.map +1 -1
- package/dist/input.js +12 -0
- package/dist/input.js.map +1 -1
- package/dist/link.d.ts +36 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +60 -0
- package/dist/link.js.map +1 -0
- package/dist/list-item.d.ts +3 -0
- package/dist/list-item.d.ts.map +1 -0
- package/dist/list-item.js +7 -0
- package/dist/list-item.js.map +1 -0
- package/dist/motion.d.ts +58 -0
- package/dist/motion.d.ts.map +1 -0
- package/dist/motion.js +73 -0
- package/dist/motion.js.map +1 -0
- package/dist/multi-select.d.ts +4 -0
- package/dist/multi-select.d.ts.map +1 -0
- package/dist/multi-select.js +23 -0
- package/dist/multi-select.js.map +1 -0
- package/dist/navigation-transition.d.ts +10 -0
- package/dist/navigation-transition.d.ts.map +1 -0
- package/dist/navigation-transition.js +10 -0
- package/dist/navigation-transition.js.map +1 -0
- package/dist/navigation.d.ts +22 -0
- package/dist/navigation.d.ts.map +1 -0
- package/dist/navigation.js +54 -0
- package/dist/navigation.js.map +1 -0
- package/dist/number-input.d.ts +21 -0
- package/dist/number-input.d.ts.map +1 -0
- package/dist/number-input.js +63 -0
- package/dist/number-input.js.map +1 -0
- package/dist/popover.d.ts +17 -0
- package/dist/popover.d.ts.map +1 -0
- package/dist/popover.js +19 -0
- package/dist/popover.js.map +1 -0
- package/dist/progress.d.ts +19 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +19 -0
- package/dist/progress.js.map +1 -0
- package/dist/responsive.d.ts +18 -0
- package/dist/responsive.d.ts.map +1 -0
- package/dist/responsive.js +35 -0
- package/dist/responsive.js.map +1 -0
- package/dist/section-scroll.d.ts +14 -0
- package/dist/section-scroll.d.ts.map +1 -0
- package/dist/section-scroll.js +28 -0
- package/dist/section-scroll.js.map +1 -0
- package/dist/segmented.d.ts +11 -0
- package/dist/segmented.d.ts.map +1 -0
- package/dist/segmented.js +30 -0
- package/dist/segmented.js.map +1 -0
- package/dist/sheet.d.ts +19 -0
- package/dist/sheet.d.ts.map +1 -0
- package/dist/sheet.js +15 -0
- package/dist/sheet.js.map +1 -0
- package/dist/tabs.d.ts +11 -0
- package/dist/tabs.d.ts.map +1 -0
- package/dist/tabs.js +28 -0
- package/dist/tabs.js.map +1 -0
- package/dist/theme/themes.d.ts.map +1 -1
- package/dist/theme/themes.js +85 -12
- package/dist/theme/themes.js.map +1 -1
- package/dist/theme/types.d.ts +64 -4
- package/dist/theme/types.d.ts.map +1 -1
- package/dist/theme/typography.d.ts +10 -0
- package/dist/theme/typography.d.ts.map +1 -0
- package/dist/theme/typography.js +90 -0
- package/dist/theme/typography.js.map +1 -0
- package/dist/time.d.ts +34 -0
- package/dist/time.d.ts.map +1 -0
- package/dist/time.js +78 -0
- package/dist/time.js.map +1 -0
- package/dist/toast.d.ts +43 -0
- package/dist/toast.d.ts.map +1 -0
- package/dist/toast.js +228 -0
- package/dist/toast.js.map +1 -0
- package/dist/vue/button-content.d.ts +10 -0
- package/dist/vue/button-content.d.ts.map +1 -0
- package/dist/vue/button-content.js +54 -0
- package/dist/vue/button-content.js.map +1 -0
- package/dist/vue/cached-activity.d.ts +3 -0
- package/dist/vue/cached-activity.d.ts.map +1 -0
- package/dist/vue/cached-activity.js +13 -0
- package/dist/vue/cached-activity.js.map +1 -0
- package/dist/vue/combobox.d.ts +155 -0
- package/dist/vue/combobox.d.ts.map +1 -0
- package/dist/vue/combobox.js +195 -0
- package/dist/vue/combobox.js.map +1 -0
- package/dist/vue/component-props.d.ts +2853 -0
- package/dist/vue/component-props.d.ts.map +1 -0
- package/dist/vue/component-props.js +29 -0
- package/dist/vue/component-props.js.map +1 -0
- package/dist/vue/configurator-props.d.ts +277 -0
- package/dist/vue/configurator-props.d.ts.map +1 -0
- package/dist/vue/configurator-props.js +63 -0
- package/dist/vue/configurator-props.js.map +1 -0
- package/dist/vue/configurator.d.ts +403 -0
- package/dist/vue/configurator.d.ts.map +1 -0
- package/dist/vue/configurator.js +287 -0
- package/dist/vue/configurator.js.map +1 -0
- package/dist/vue/contracts.d.ts +18 -0
- package/dist/vue/contracts.d.ts.map +1 -0
- package/dist/vue/contracts.js +24 -0
- package/dist/vue/contracts.js.map +1 -0
- package/dist/vue/date-calendar.d.ts +64 -0
- package/dist/vue/date-calendar.d.ts.map +1 -0
- package/dist/vue/date-calendar.js +65 -0
- package/dist/vue/date-calendar.js.map +1 -0
- package/dist/vue/date-picker.d.ts +1000 -0
- package/dist/vue/date-picker.d.ts.map +1 -0
- package/dist/vue/date-picker.js +334 -0
- package/dist/vue/date-picker.js.map +1 -0
- package/dist/vue/date-props.d.ts +272 -0
- package/dist/vue/date-props.d.ts.map +1 -0
- package/dist/vue/date-props.js +78 -0
- package/dist/vue/date-props.js.map +1 -0
- package/dist/vue/dialog.d.ts +21 -0
- package/dist/vue/dialog.d.ts.map +1 -0
- package/dist/vue/dialog.js +58 -0
- package/dist/vue/dialog.js.map +1 -0
- package/dist/vue/files.d.ts +53 -0
- package/dist/vue/files.d.ts.map +1 -0
- package/dist/vue/files.js +40 -0
- package/dist/vue/files.js.map +1 -0
- package/dist/vue/forms.d.ts +4 -0
- package/dist/vue/forms.d.ts.map +1 -0
- package/dist/vue/forms.js +15 -0
- package/dist/vue/forms.js.map +1 -0
- package/dist/vue/global-components.d.ts +198 -3
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/index.d.ts +44 -4
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +36 -2
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/inline-content.d.ts +54 -0
- package/dist/vue/inline-content.d.ts.map +1 -0
- package/dist/vue/inline-content.js +64 -0
- package/dist/vue/inline-content.js.map +1 -0
- package/dist/vue/layout-context.d.ts +4 -2
- package/dist/vue/layout-context.d.ts.map +1 -1
- package/dist/vue/layout-context.js +7 -2
- package/dist/vue/layout-context.js.map +1 -1
- package/dist/vue/list-motion.d.ts +7 -0
- package/dist/vue/list-motion.d.ts.map +1 -0
- package/dist/vue/list-motion.js +28 -0
- package/dist/vue/list-motion.js.map +1 -0
- package/dist/vue/loading-effect.d.ts +7 -0
- package/dist/vue/loading-effect.d.ts.map +1 -0
- package/dist/vue/loading-effect.js +32 -0
- package/dist/vue/loading-effect.js.map +1 -0
- package/dist/vue/menu.d.ts +122 -0
- package/dist/vue/menu.d.ts.map +1 -0
- package/dist/vue/menu.js +79 -0
- package/dist/vue/menu.js.map +1 -0
- package/dist/vue/navigation-controls.d.ts +124 -0
- package/dist/vue/navigation-controls.d.ts.map +1 -0
- package/dist/vue/navigation-controls.js +117 -0
- package/dist/vue/navigation-controls.js.map +1 -0
- package/dist/vue/navigation-props.d.ts +283 -0
- package/dist/vue/navigation-props.d.ts.map +1 -0
- package/dist/vue/navigation-props.js +82 -0
- package/dist/vue/navigation-props.js.map +1 -0
- package/dist/vue/navigation.d.ts +7 -0
- package/dist/vue/navigation.d.ts.map +1 -0
- package/dist/vue/navigation.js +15 -0
- package/dist/vue/navigation.js.map +1 -0
- package/dist/vue/platform.d.ts +37 -0
- package/dist/vue/platform.d.ts.map +1 -0
- package/dist/vue/platform.js +46 -0
- package/dist/vue/platform.js.map +1 -0
- package/dist/vue/props.d.ts +3326 -510
- package/dist/vue/props.d.ts.map +1 -1
- package/dist/vue/props.js +314 -83
- package/dist/vue/props.js.map +1 -1
- package/dist/vue/reveal-state.d.ts +18 -0
- package/dist/vue/reveal-state.d.ts.map +1 -0
- package/dist/vue/reveal-state.js +76 -0
- package/dist/vue/reveal-state.js.map +1 -0
- package/dist/vue/theme-provider.d.ts +58 -0
- package/dist/vue/theme-provider.d.ts.map +1 -0
- package/dist/vue/theme-provider.js +69 -0
- package/dist/vue/theme-provider.js.map +1 -0
- package/dist/vue/theme.d.ts +1029 -19
- package/dist/vue/theme.d.ts.map +1 -1
- package/dist/vue/theme.js +47 -2
- package/dist/vue/theme.js.map +1 -1
- package/dist/vue/time-picker.d.ts +488 -0
- package/dist/vue/time-picker.d.ts.map +1 -0
- package/dist/vue/time-picker.js +190 -0
- package/dist/vue/time-picker.js.map +1 -0
- package/dist/vue/toast.d.ts +29 -0
- package/dist/vue/toast.d.ts.map +1 -0
- package/dist/vue/toast.js +79 -0
- package/dist/vue/toast.js.map +1 -0
- package/dist/vue/virtual-list.d.ts +26 -0
- package/dist/vue/virtual-list.d.ts.map +1 -0
- package/dist/vue/virtual-list.js +2 -0
- package/dist/vue/virtual-list.js.map +1 -0
- package/dist/vue/workflow-props.d.ts +110 -0
- package/dist/vue/workflow-props.d.ts.map +1 -0
- package/dist/vue/workflow-props.js +37 -0
- package/dist/vue/workflow-props.js.map +1 -0
- package/dist/vue/workflows.d.ts +267 -0
- package/dist/vue/workflows.d.ts.map +1 -0
- package/dist/vue/workflows.js +200 -0
- package/dist/vue/workflows.js.map +1 -0
- package/package.json +5 -1
- package/src/accordion.ts +66 -0
- package/src/alert.ts +16 -0
- package/src/app-icons.ts +57 -0
- package/src/avatar.ts +11 -0
- package/src/badge.ts +11 -0
- package/src/capabilities.ts +171 -0
- package/src/chip.ts +20 -0
- package/src/choice-motion.ts +12 -0
- package/src/choice.ts +41 -0
- package/src/collections.ts +87 -0
- package/src/combobox.ts +198 -0
- package/src/contracts.ts +324 -0
- package/src/date-input.ts +87 -0
- package/src/date-time.ts +37 -0
- package/src/date.ts +280 -0
- package/src/dialog.ts +22 -0
- package/src/empty-state.ts +4 -0
- package/src/experimental-collections.ts +87 -0
- package/src/experimental-effects.ts +146 -0
- package/src/experimental-platforms.ts +96 -0
- package/src/experimental-playback.ts +115 -0
- package/src/experimental-regions.ts +777 -0
- package/src/experimental-sensors.ts +50 -0
- package/src/experimental-surfaces.ts +124 -0
- package/src/experimental.ts +1102 -0
- package/src/files.ts +408 -0
- package/src/form.ts +190 -0
- package/src/grid.ts +19 -0
- package/src/icon.ts +30 -0
- package/src/icons.ts +2002 -0
- package/src/index.ts +88 -2
- package/src/input.ts +27 -0
- package/src/link.ts +91 -0
- package/src/list-item.ts +5 -0
- package/src/motion.ts +80 -0
- package/src/multi-select.ts +30 -0
- package/src/navigation-transition.ts +14 -0
- package/src/navigation.ts +61 -0
- package/src/number-input.ts +80 -0
- package/src/popover.ts +38 -0
- package/src/progress.ts +22 -0
- package/src/responsive.ts +61 -0
- package/src/section-scroll.ts +46 -0
- package/src/segmented.ts +39 -0
- package/src/sheet.ts +31 -0
- package/src/tabs.ts +35 -0
- package/src/theme/themes.ts +89 -12
- package/src/theme/types.ts +55 -2
- package/src/theme/typography.ts +84 -0
- package/src/time.ts +83 -0
- package/src/toast.ts +249 -0
- package/src/vue/button-content.ts +60 -0
- package/src/vue/cached-activity.ts +13 -0
- package/src/vue/combobox.ts +238 -0
- package/src/vue/component-props.ts +42 -0
- package/src/vue/configurator-props.ts +67 -0
- package/src/vue/configurator.ts +350 -0
- package/src/vue/contracts.ts +39 -0
- package/src/vue/date-calendar.ts +76 -0
- package/src/vue/date-picker.ts +410 -0
- package/src/vue/date-props.ts +86 -0
- package/src/vue/dialog.ts +63 -0
- package/src/vue/files.ts +53 -0
- package/src/vue/forms.ts +20 -0
- package/src/vue/global-components.ts +182 -4
- package/src/vue/index.ts +84 -4
- package/src/vue/inline-content.ts +71 -0
- package/src/vue/layout-context.ts +10 -3
- package/src/vue/list-motion.ts +31 -0
- package/src/vue/loading-effect.ts +44 -0
- package/src/vue/menu.ts +100 -0
- package/src/vue/navigation-controls.ts +138 -0
- package/src/vue/navigation-props.ts +87 -0
- package/src/vue/navigation.ts +16 -0
- package/src/vue/platform.ts +73 -0
- package/src/vue/props.ts +348 -96
- package/src/vue/reveal-state.ts +83 -0
- package/src/vue/theme-provider.ts +74 -0
- package/src/vue/theme.ts +65 -3
- package/src/vue/time-picker.ts +227 -0
- package/src/vue/toast.ts +99 -0
- package/src/vue/virtual-list.ts +28 -0
- package/src/vue/workflow-props.ts +41 -0
- package/src/vue/workflows.ts +257 -0
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
defineComponent,
|
|
4
|
+
h,
|
|
5
|
+
mergeProps,
|
|
6
|
+
nextTick,
|
|
7
|
+
onBeforeUnmount,
|
|
8
|
+
onMounted,
|
|
9
|
+
ref,
|
|
10
|
+
watch,
|
|
11
|
+
type Component,
|
|
12
|
+
type ExtractPropTypes,
|
|
13
|
+
} from '@vue/runtime-core'
|
|
14
|
+
import {
|
|
15
|
+
civilDate,
|
|
16
|
+
dateLocales,
|
|
17
|
+
dateValidationMessage,
|
|
18
|
+
validateDateConstraints,
|
|
19
|
+
validateDateDraft,
|
|
20
|
+
type CivilDate,
|
|
21
|
+
type DateRange,
|
|
22
|
+
type DateRangeDraft,
|
|
23
|
+
type DateValidation,
|
|
24
|
+
} from '../date.js'
|
|
25
|
+
import {
|
|
26
|
+
formatDateInput,
|
|
27
|
+
parseDateInput,
|
|
28
|
+
validateDateInput,
|
|
29
|
+
validateDateRangeInput,
|
|
30
|
+
dateInputPlaceholder,
|
|
31
|
+
} from '../date-input.js'
|
|
32
|
+
import type { InputHandle } from '../input.js'
|
|
33
|
+
import {
|
|
34
|
+
datePickerProps,
|
|
35
|
+
datePickerEmits,
|
|
36
|
+
dateRangePickerProps,
|
|
37
|
+
dateRangePickerEmits,
|
|
38
|
+
} from './date-props.js'
|
|
39
|
+
import { useButtonAction } from './button-content.js'
|
|
40
|
+
|
|
41
|
+
type EntryProps = Omit<ExtractPropTypes<typeof dateRangePickerProps>, 'modelValue' | 'draft'> & {
|
|
42
|
+
modelValue: CivilDate | null | DateRange
|
|
43
|
+
draft?: string | DateRangeDraft
|
|
44
|
+
name?: string
|
|
45
|
+
}
|
|
46
|
+
interface DatePrimitives {
|
|
47
|
+
Input: Component
|
|
48
|
+
Button: Component
|
|
49
|
+
Column: Component
|
|
50
|
+
Row: Component
|
|
51
|
+
Sheet: Component
|
|
52
|
+
Calendar: Component
|
|
53
|
+
/** Internal adapter boundary: capture a focusable opener and dismiss the native keyboard. */
|
|
54
|
+
beforeOpen(opener: unknown): void
|
|
55
|
+
afterClose(opener: unknown): void
|
|
56
|
+
deferActions?: boolean
|
|
57
|
+
}
|
|
58
|
+
interface EntryEvents {
|
|
59
|
+
model(value: CivilDate | null | DateRange): void
|
|
60
|
+
draft(value: string | DateRangeDraft): void
|
|
61
|
+
validity(value: DateValidation): void
|
|
62
|
+
focus(): void
|
|
63
|
+
blur(): void
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @internal One Vue editing contract, composed with each renderer's existing primitives. */
|
|
67
|
+
export function createDatePickers(primitives: DatePrimitives) {
|
|
68
|
+
const { Input, Button, Column, Sheet, Calendar } = primitives
|
|
69
|
+
function useEntry(props: EntryProps, range: boolean, events: EntryEvents) {
|
|
70
|
+
useButtonAction()
|
|
71
|
+
const start = ref('')
|
|
72
|
+
const end = ref('')
|
|
73
|
+
const touched = ref(false)
|
|
74
|
+
const open = ref(false)
|
|
75
|
+
const ready = ref(!primitives.deferActions)
|
|
76
|
+
onMounted(() => {
|
|
77
|
+
ready.value = true
|
|
78
|
+
})
|
|
79
|
+
const endpoint = ref<'start' | 'end'>('start')
|
|
80
|
+
const activeDate = ref<CivilDate>('2000-01-01')
|
|
81
|
+
const first = ref<InputHandle>()
|
|
82
|
+
const second = ref<InputHandle>()
|
|
83
|
+
let alive = true
|
|
84
|
+
let revision = 0
|
|
85
|
+
let returnFocus = true
|
|
86
|
+
const words = computed(() => {
|
|
87
|
+
if (!Object.hasOwn(dateLocales, props.locale))
|
|
88
|
+
throw new RangeError('Date locale must be en-US or pt-BR')
|
|
89
|
+
return dateLocales[props.locale]
|
|
90
|
+
})
|
|
91
|
+
const parse = (value: string) => parseDateInput(value, props.dateFormat, props.locale)
|
|
92
|
+
const format = (value: CivilDate | null) =>
|
|
93
|
+
value ? formatDateInput(value, props.dateFormat, props.locale) : ''
|
|
94
|
+
const validate = (value: string) =>
|
|
95
|
+
validateDateInput(value, props, props.dateFormat, props.locale)
|
|
96
|
+
function snapshot(): DateRangeDraft {
|
|
97
|
+
if (range) {
|
|
98
|
+
const value = props.modelValue as DateRange
|
|
99
|
+
if (!value || typeof value !== 'object')
|
|
100
|
+
throw new RangeError('A date range needs start and end endpoints')
|
|
101
|
+
for (const date of [value.start, value.end]) if (date !== null) civilDate(date)
|
|
102
|
+
return { start: format(value.start), end: format(value.end) }
|
|
103
|
+
}
|
|
104
|
+
if (props.modelValue !== null) civilDate(props.modelValue as string)
|
|
105
|
+
return { start: format(props.modelValue as CivilDate | null), end: '' }
|
|
106
|
+
}
|
|
107
|
+
function restore() {
|
|
108
|
+
// A controlled draft owns the editor. The canonical model remains independently valid.
|
|
109
|
+
const canonical = snapshot()
|
|
110
|
+
const value =
|
|
111
|
+
props.draft === undefined
|
|
112
|
+
? canonical
|
|
113
|
+
: range
|
|
114
|
+
? (props.draft as DateRangeDraft)
|
|
115
|
+
: { start: props.draft as string, end: '' }
|
|
116
|
+
if (!value || typeof value.start !== 'string' || typeof value.end !== 'string')
|
|
117
|
+
throw new TypeError('A date draft must contain text for each endpoint')
|
|
118
|
+
start.value = value.start
|
|
119
|
+
end.value = value.end
|
|
120
|
+
}
|
|
121
|
+
restore()
|
|
122
|
+
watch(
|
|
123
|
+
() => [props.modelValue, props.draft],
|
|
124
|
+
() => {
|
|
125
|
+
revision++
|
|
126
|
+
restore()
|
|
127
|
+
},
|
|
128
|
+
{ deep: true },
|
|
129
|
+
)
|
|
130
|
+
watch(
|
|
131
|
+
() => [props.dateFormat, props.locale] as const,
|
|
132
|
+
(_next, previous) => {
|
|
133
|
+
revision++
|
|
134
|
+
if (props.draft !== undefined) return
|
|
135
|
+
for (const draft of [start, end]) {
|
|
136
|
+
const parsed = parseDateInput(draft.value, previous[0], previous[1])
|
|
137
|
+
if (parsed) draft.value = format(parsed)
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
)
|
|
141
|
+
const validity = computed(() => {
|
|
142
|
+
validateDateConstraints(props)
|
|
143
|
+
return range
|
|
144
|
+
? validateDateRangeInput(
|
|
145
|
+
{ start: start.value, end: end.value },
|
|
146
|
+
props,
|
|
147
|
+
props.dateFormat,
|
|
148
|
+
props.locale,
|
|
149
|
+
)
|
|
150
|
+
: validate(start.value)
|
|
151
|
+
})
|
|
152
|
+
watch(validity, (value, previous) => {
|
|
153
|
+
if (JSON.stringify(value) !== JSON.stringify(previous)) events.validity(value)
|
|
154
|
+
})
|
|
155
|
+
watch(
|
|
156
|
+
() => props.disabled || props.readonly,
|
|
157
|
+
(blocked) => {
|
|
158
|
+
if (blocked) close(false)
|
|
159
|
+
},
|
|
160
|
+
)
|
|
161
|
+
onBeforeUnmount(() => {
|
|
162
|
+
alive = false
|
|
163
|
+
revision++
|
|
164
|
+
})
|
|
165
|
+
function close(restoreFocus = true) {
|
|
166
|
+
if (!open.value) return
|
|
167
|
+
open.value = false
|
|
168
|
+
returnFocus = restoreFocus
|
|
169
|
+
}
|
|
170
|
+
function edit(which: 'start' | 'end', value: string) {
|
|
171
|
+
if (props.disabled || props.readonly) return
|
|
172
|
+
if (which === 'start') start.value = value
|
|
173
|
+
else end.value = value
|
|
174
|
+
propose()
|
|
175
|
+
}
|
|
176
|
+
function propose() {
|
|
177
|
+
const current = ++revision
|
|
178
|
+
const draft = { start: start.value, end: end.value }
|
|
179
|
+
events.draft(range ? { ...draft } : draft.start)
|
|
180
|
+
if (props.draft !== undefined) {
|
|
181
|
+
void nextTick(() => {
|
|
182
|
+
if (alive && revision === current) restore()
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
if (!validity.value.valid) return
|
|
186
|
+
const previous = snapshot()
|
|
187
|
+
if (previous.start === draft.start && previous.end === draft.end) return
|
|
188
|
+
events.model(
|
|
189
|
+
range
|
|
190
|
+
? {
|
|
191
|
+
start: parse(draft.start),
|
|
192
|
+
end: parse(draft.end),
|
|
193
|
+
}
|
|
194
|
+
: parse(draft.start),
|
|
195
|
+
)
|
|
196
|
+
// A model proposal is controlled. Invalid/incomplete drafts remain local; a rejected
|
|
197
|
+
// valid proposal returns to the parent's value without manufacturing another edit.
|
|
198
|
+
void nextTick(() => {
|
|
199
|
+
if (alive && revision === current) restore()
|
|
200
|
+
})
|
|
201
|
+
}
|
|
202
|
+
function show(which: 'start' | 'end') {
|
|
203
|
+
if (!ready.value || props.disabled || props.readonly || open.value) return
|
|
204
|
+
endpoint.value = which
|
|
205
|
+
const draft = which === 'end' ? end.value : start.value
|
|
206
|
+
let target = parse(draft) ?? props.min ?? civilDate(`${props.initialMonth}-01`)
|
|
207
|
+
if (props.min && target < props.min) target = props.min
|
|
208
|
+
if (props.max && target > props.max) target = props.max
|
|
209
|
+
activeDate.value = target
|
|
210
|
+
primitives.beforeOpen(which === 'end' ? second.value : first.value)
|
|
211
|
+
open.value = true
|
|
212
|
+
}
|
|
213
|
+
const handle: InputHandle = {
|
|
214
|
+
focus: () => {
|
|
215
|
+
if (!props.disabled) first.value?.focus()
|
|
216
|
+
},
|
|
217
|
+
blur: () => {
|
|
218
|
+
first.value?.blur()
|
|
219
|
+
second.value?.blur()
|
|
220
|
+
},
|
|
221
|
+
}
|
|
222
|
+
function render(attrs: Record<string, unknown>) {
|
|
223
|
+
if (!props.label.trim()) throw new RangeError('A date picker needs a visible label')
|
|
224
|
+
for (const name of [
|
|
225
|
+
'calendarLabel',
|
|
226
|
+
'clearLabel',
|
|
227
|
+
'closeLabel',
|
|
228
|
+
'startLabel',
|
|
229
|
+
'endLabel',
|
|
230
|
+
] as const) {
|
|
231
|
+
if (props[name] !== undefined && !props[name]!.trim())
|
|
232
|
+
throw new RangeError(`${name} must not be blank`)
|
|
233
|
+
}
|
|
234
|
+
civilDate(`${props.initialMonth}-01`)
|
|
235
|
+
if (
|
|
236
|
+
props.firstDayOfWeek !== undefined &&
|
|
237
|
+
(!Number.isInteger(props.firstDayOfWeek) ||
|
|
238
|
+
props.firstDayOfWeek < 0 ||
|
|
239
|
+
props.firstDayOfWeek > 6)
|
|
240
|
+
)
|
|
241
|
+
throw new RangeError('firstDayOfWeek must be an integer from 0 to 6')
|
|
242
|
+
const translations = words.value
|
|
243
|
+
const placeholder = dateInputPlaceholder(props.dateFormat, props.locale)
|
|
244
|
+
const message = (value: DateValidation) =>
|
|
245
|
+
dateValidationMessage(value, props.locale).replace(translations.format, placeholder)
|
|
246
|
+
const label = (which: 'start' | 'end') =>
|
|
247
|
+
range
|
|
248
|
+
? `${props.label} · ${which === 'start' ? (props.startLabel ?? translations.start) : (props.endLabel ?? translations.end)}`
|
|
249
|
+
: props.label
|
|
250
|
+
const startValidation = validate(start.value)
|
|
251
|
+
const endValidation = validate(end.value)
|
|
252
|
+
const startError = touched.value || start.value.length >= 10 ? message(startValidation) : ''
|
|
253
|
+
const endError = touched.value || end.value.length >= 10 ? message(endValidation) : ''
|
|
254
|
+
const rangeError = startValidation.valid && endValidation.valid ? message(validity.value) : ''
|
|
255
|
+
const field = (which: 'start' | 'end') =>
|
|
256
|
+
h(Input, {
|
|
257
|
+
ref: which === 'start' ? first : second,
|
|
258
|
+
id: props.id ? `${props.id}${range ? `-${which}` : ''}` : undefined,
|
|
259
|
+
label: label(which),
|
|
260
|
+
modelValue: which === 'start' ? start.value : end.value,
|
|
261
|
+
name: range ? (which === 'start' ? props.startName : props.endName) : props.name,
|
|
262
|
+
type: 'text',
|
|
263
|
+
trailingAction: {
|
|
264
|
+
icon: 'calendar-days',
|
|
265
|
+
label: `${props.calendarLabel ?? translations.calendar}: ${label(which)}`,
|
|
266
|
+
disabled: !ready.value,
|
|
267
|
+
},
|
|
268
|
+
onAction: () => show(which),
|
|
269
|
+
placeholder,
|
|
270
|
+
autocapitalize: 'none',
|
|
271
|
+
autocorrect: false,
|
|
272
|
+
disabled: props.disabled,
|
|
273
|
+
readonly: props.readonly,
|
|
274
|
+
helperText: !range || which === 'end' ? props.helperText : '',
|
|
275
|
+
error: !range
|
|
276
|
+
? props.error || startError
|
|
277
|
+
: which === 'start'
|
|
278
|
+
? startError
|
|
279
|
+
: props.error || endError || rangeError,
|
|
280
|
+
'onUpdate:modelValue': (value: string) => edit(which, value),
|
|
281
|
+
onFocus: events.focus,
|
|
282
|
+
onBlur: () => {
|
|
283
|
+
touched.value = true
|
|
284
|
+
events.blur()
|
|
285
|
+
},
|
|
286
|
+
})
|
|
287
|
+
return h(
|
|
288
|
+
Column,
|
|
289
|
+
mergeProps(attrs, {
|
|
290
|
+
gap: 'sm',
|
|
291
|
+
width: props.width,
|
|
292
|
+
grow: props.grow,
|
|
293
|
+
shrink: props.shrink,
|
|
294
|
+
accessibilityHidden: props.accessibilityHidden,
|
|
295
|
+
onUnloaded: () => close(false),
|
|
296
|
+
}),
|
|
297
|
+
{
|
|
298
|
+
default: () => [
|
|
299
|
+
field('start'),
|
|
300
|
+
range ? field('end') : null,
|
|
301
|
+
props.clearable
|
|
302
|
+
? h(Button, {
|
|
303
|
+
text: props.clearLabel ?? `${translations.clear}: ${props.label}`,
|
|
304
|
+
variant: 'ghost',
|
|
305
|
+
size: 'sm',
|
|
306
|
+
disabled:
|
|
307
|
+
!ready.value ||
|
|
308
|
+
props.disabled ||
|
|
309
|
+
props.readonly ||
|
|
310
|
+
(!start.value && !end.value),
|
|
311
|
+
onClick: () => {
|
|
312
|
+
if (props.disabled || props.readonly) return
|
|
313
|
+
start.value = ''
|
|
314
|
+
end.value = ''
|
|
315
|
+
touched.value = false
|
|
316
|
+
propose()
|
|
317
|
+
},
|
|
318
|
+
})
|
|
319
|
+
: null,
|
|
320
|
+
h(
|
|
321
|
+
Sheet,
|
|
322
|
+
{
|
|
323
|
+
open: open.value,
|
|
324
|
+
title: label(endpoint.value),
|
|
325
|
+
closeLabel: props.closeLabel ?? translations.close,
|
|
326
|
+
'onUpdate:open': (value: boolean) => {
|
|
327
|
+
if (!value) close()
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
default: () =>
|
|
332
|
+
h(Calendar, {
|
|
333
|
+
activeDate: activeDate.value,
|
|
334
|
+
onVnodeUnmounted: () => {
|
|
335
|
+
if (alive && returnFocus && !props.disabled && !open.value)
|
|
336
|
+
primitives.afterClose(endpoint.value === 'end' ? second.value : first.value)
|
|
337
|
+
},
|
|
338
|
+
selected: parse(endpoint.value === 'end' ? end.value : start.value),
|
|
339
|
+
rangeStart: range ? parse(start.value) : null,
|
|
340
|
+
rangeEnd: range ? parse(end.value) : null,
|
|
341
|
+
min: props.min,
|
|
342
|
+
max: props.max,
|
|
343
|
+
unavailableDates: props.unavailableDates,
|
|
344
|
+
locale: props.locale,
|
|
345
|
+
firstDayOfWeek: props.firstDayOfWeek,
|
|
346
|
+
'onUpdate:activeDate': (value: CivilDate) => {
|
|
347
|
+
activeDate.value = value
|
|
348
|
+
},
|
|
349
|
+
onSelect: (value: CivilDate) => {
|
|
350
|
+
if (
|
|
351
|
+
!open.value ||
|
|
352
|
+
props.disabled ||
|
|
353
|
+
props.readonly ||
|
|
354
|
+
!validateDateDraft(value, props).valid
|
|
355
|
+
)
|
|
356
|
+
return
|
|
357
|
+
touched.value = true
|
|
358
|
+
edit(endpoint.value, format(value))
|
|
359
|
+
close()
|
|
360
|
+
},
|
|
361
|
+
}),
|
|
362
|
+
},
|
|
363
|
+
),
|
|
364
|
+
],
|
|
365
|
+
},
|
|
366
|
+
)
|
|
367
|
+
}
|
|
368
|
+
return { handle, render }
|
|
369
|
+
}
|
|
370
|
+
const Picker = defineComponent({
|
|
371
|
+
name: 'MDatePicker',
|
|
372
|
+
inheritAttrs: false,
|
|
373
|
+
props: datePickerProps,
|
|
374
|
+
emits: datePickerEmits,
|
|
375
|
+
setup(props, { attrs, emit, expose }) {
|
|
376
|
+
const entry = useEntry(props as EntryProps, false, {
|
|
377
|
+
model: (value) => emit('update:modelValue', value as CivilDate | null),
|
|
378
|
+
draft: (value) => emit('update:draft', value as string),
|
|
379
|
+
validity: (value) => emit('validityChange', value),
|
|
380
|
+
focus: () => emit('focus'),
|
|
381
|
+
blur: () => emit('blur'),
|
|
382
|
+
})
|
|
383
|
+
expose(entry.handle)
|
|
384
|
+
return () => entry.render(attrs)
|
|
385
|
+
},
|
|
386
|
+
})
|
|
387
|
+
const RangePicker = defineComponent({
|
|
388
|
+
name: 'MDateRangePicker',
|
|
389
|
+
inheritAttrs: false,
|
|
390
|
+
props: dateRangePickerProps,
|
|
391
|
+
emits: dateRangePickerEmits,
|
|
392
|
+
setup(props, { attrs, emit, expose }) {
|
|
393
|
+
const entry = useEntry(props, true, {
|
|
394
|
+
model: (value) => emit('update:modelValue', value as DateRange),
|
|
395
|
+
draft: (value) => emit('update:draft', value as DateRangeDraft),
|
|
396
|
+
validity: (value) => emit('validityChange', value),
|
|
397
|
+
focus: () => emit('focus'),
|
|
398
|
+
blur: () => emit('blur'),
|
|
399
|
+
})
|
|
400
|
+
expose(entry.handle)
|
|
401
|
+
return () => entry.render(attrs)
|
|
402
|
+
},
|
|
403
|
+
})
|
|
404
|
+
return {
|
|
405
|
+
MDatePicker: Picker as typeof Picker & { new (): InstanceType<typeof Picker> & InputHandle },
|
|
406
|
+
MDateRangePicker: RangePicker as typeof RangePicker & {
|
|
407
|
+
new (): InstanceType<typeof RangePicker> & InputHandle
|
|
408
|
+
},
|
|
409
|
+
}
|
|
410
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { ExtractPublicPropTypes, PropType } from '@vue/runtime-core'
|
|
2
|
+
import type { CivilDate, DateLocale, DateRange, DateRangeDraft, DateValidation } from '../date.js'
|
|
3
|
+
import { isCivilDate } from '../date.js'
|
|
4
|
+
import type { DateInputFormat } from '../date-input.js'
|
|
5
|
+
import { dimensionProperty } from '../contracts.js'
|
|
6
|
+
import { vueProperty } from './contracts.js'
|
|
7
|
+
import { flexProps, viewProps } from './props.js'
|
|
8
|
+
|
|
9
|
+
const dateOptions = {
|
|
10
|
+
min: { type: String as PropType<CivilDate>, default: undefined },
|
|
11
|
+
max: { type: String as PropType<CivilDate>, default: undefined },
|
|
12
|
+
unavailableDates: { type: Array as PropType<readonly CivilDate[]>, default: () => [] },
|
|
13
|
+
locale: { type: String as PropType<DateLocale>, default: 'en-US' as const },
|
|
14
|
+
firstDayOfWeek: { type: Number, default: undefined },
|
|
15
|
+
}
|
|
16
|
+
const common = {
|
|
17
|
+
dateFormat: { type: String as PropType<DateInputFormat>, default: 'iso' as const },
|
|
18
|
+
id: viewProps.id,
|
|
19
|
+
accessibilityHidden: viewProps.accessibilityHidden,
|
|
20
|
+
...flexProps,
|
|
21
|
+
width: vueProperty(dimensionProperty),
|
|
22
|
+
...dateOptions,
|
|
23
|
+
label: { type: String, required: true as const },
|
|
24
|
+
helperText: { type: String, default: '' },
|
|
25
|
+
error: { type: String, default: '' },
|
|
26
|
+
disabled: Boolean,
|
|
27
|
+
readonly: Boolean,
|
|
28
|
+
clearable: { type: Boolean, default: true },
|
|
29
|
+
clearLabel: { type: String, default: undefined },
|
|
30
|
+
calendarLabel: { type: String, default: undefined },
|
|
31
|
+
closeLabel: { type: String, default: undefined },
|
|
32
|
+
/** Deterministic empty calendar snapshot; never reads the clock. */
|
|
33
|
+
initialMonth: { type: String, default: '2000-01' },
|
|
34
|
+
}
|
|
35
|
+
export const datePickerProps = {
|
|
36
|
+
...common,
|
|
37
|
+
/** Optional controlled editor text, including incomplete or invalid dates. */
|
|
38
|
+
draft: { type: String, default: undefined },
|
|
39
|
+
modelValue: { type: String as PropType<CivilDate | null>, default: null },
|
|
40
|
+
name: { type: String, default: undefined },
|
|
41
|
+
}
|
|
42
|
+
export const dateRangePickerProps = {
|
|
43
|
+
...common,
|
|
44
|
+
draft: { type: Object as PropType<DateRangeDraft>, default: undefined },
|
|
45
|
+
modelValue: {
|
|
46
|
+
type: Object as PropType<DateRange>,
|
|
47
|
+
default: (): DateRange => ({ start: null, end: null }),
|
|
48
|
+
},
|
|
49
|
+
startLabel: { type: String, default: undefined },
|
|
50
|
+
endLabel: { type: String, default: undefined },
|
|
51
|
+
startName: { type: String, default: undefined },
|
|
52
|
+
endName: { type: String, default: undefined },
|
|
53
|
+
}
|
|
54
|
+
const editingEmits = {
|
|
55
|
+
validityChange: (value: DateValidation) => typeof value.valid === 'boolean',
|
|
56
|
+
focus: () => true,
|
|
57
|
+
blur: () => true,
|
|
58
|
+
}
|
|
59
|
+
export const datePickerEmits = {
|
|
60
|
+
...editingEmits,
|
|
61
|
+
'update:modelValue': (value: CivilDate | null) => value === null || isCivilDate(value),
|
|
62
|
+
'update:draft': (value: string) => typeof value === 'string',
|
|
63
|
+
}
|
|
64
|
+
export const dateRangePickerEmits = {
|
|
65
|
+
...editingEmits,
|
|
66
|
+
'update:modelValue': (value: DateRange) =>
|
|
67
|
+
(value.start === null || isCivilDate(value.start)) &&
|
|
68
|
+
(value.end === null || isCivilDate(value.end)),
|
|
69
|
+
'update:draft': (value: DateRangeDraft) =>
|
|
70
|
+
typeof value.start === 'string' && typeof value.end === 'string',
|
|
71
|
+
}
|
|
72
|
+
export type DatePickerProps = ExtractPublicPropTypes<typeof datePickerProps>
|
|
73
|
+
export type DateRangePickerProps = ExtractPublicPropTypes<typeof dateRangePickerProps>
|
|
74
|
+
|
|
75
|
+
/** @internal Shared themed calendar presentation contract. */
|
|
76
|
+
export const dateCalendarProps = {
|
|
77
|
+
...dateOptions,
|
|
78
|
+
activeDate: { type: String as PropType<CivilDate>, required: true as const },
|
|
79
|
+
selected: { type: String as PropType<CivilDate | null>, default: null },
|
|
80
|
+
rangeStart: { type: String as PropType<CivilDate | null>, default: null },
|
|
81
|
+
rangeEnd: { type: String as PropType<CivilDate | null>, default: null },
|
|
82
|
+
}
|
|
83
|
+
export const dateCalendarEmits = {
|
|
84
|
+
select: (value: CivilDate) => isCivilDate(value),
|
|
85
|
+
'update:activeDate': (value: CivilDate) => isCivilDate(value),
|
|
86
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { nextTick, ref, watch } from '@vue/runtime-core'
|
|
2
|
+
import type { DialogCloseReason } from '../dialog.js'
|
|
3
|
+
|
|
4
|
+
type State = Readonly<{ open: boolean; loading: boolean; dismissible: boolean }>
|
|
5
|
+
type Events = {
|
|
6
|
+
(event: 'update:open', value: boolean): void
|
|
7
|
+
(event: 'close', reason: DialogCloseReason): void
|
|
8
|
+
(event: 'confirm'): void
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** @internal Controlled decisions share the same event semantics in both renderers. */
|
|
12
|
+
export function useDialogState(props: State, emit: Events) {
|
|
13
|
+
const presented = ref(props.open)
|
|
14
|
+
const visible = ref(props.open)
|
|
15
|
+
let requested: DialogCloseReason | undefined
|
|
16
|
+
let confirming = false
|
|
17
|
+
let generation = 0
|
|
18
|
+
watch(
|
|
19
|
+
() => props.open,
|
|
20
|
+
(open) => {
|
|
21
|
+
generation++
|
|
22
|
+
confirming = false
|
|
23
|
+
visible.value = open
|
|
24
|
+
if (open) presented.value = true
|
|
25
|
+
else if (presented.value && !requested) emit('close', 'program')
|
|
26
|
+
requested = undefined
|
|
27
|
+
},
|
|
28
|
+
{ flush: 'sync' },
|
|
29
|
+
)
|
|
30
|
+
function request(reason: DialogCloseReason) {
|
|
31
|
+
const navigation = reason === 'navigation'
|
|
32
|
+
if (!props.open || requested || (!navigation && props.loading)) return
|
|
33
|
+
if (!navigation && reason !== 'cancel' && !props.dismissible) return
|
|
34
|
+
requested = reason
|
|
35
|
+
const current = generation
|
|
36
|
+
if (navigation) {
|
|
37
|
+
visible.value = false
|
|
38
|
+
presented.value = false
|
|
39
|
+
}
|
|
40
|
+
emit('update:open', false)
|
|
41
|
+
emit('close', reason)
|
|
42
|
+
// The parent can reject a request. Do not leave the still-open dialog inert afterward.
|
|
43
|
+
void nextTick(() => {
|
|
44
|
+
if (current === generation) requested = undefined
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
presented,
|
|
49
|
+
visible,
|
|
50
|
+
request,
|
|
51
|
+
confirm() {
|
|
52
|
+
if (!props.open || props.loading || confirming || requested) return
|
|
53
|
+
confirming = true
|
|
54
|
+
emit('confirm')
|
|
55
|
+
void nextTick(() => {
|
|
56
|
+
confirming = false
|
|
57
|
+
})
|
|
58
|
+
},
|
|
59
|
+
left() {
|
|
60
|
+
if (!visible.value) presented.value = false
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
}
|
package/src/vue/files.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { markRaw, onBeforeUnmount, onDeactivated, type PropType } from '@vue/runtime-core'
|
|
2
|
+
import {
|
|
3
|
+
createFileSelection,
|
|
4
|
+
type FileSelectionController,
|
|
5
|
+
type FileSelectionOptions,
|
|
6
|
+
type FileItem,
|
|
7
|
+
type FileSelectionErrorCode,
|
|
8
|
+
} from '../files.js'
|
|
9
|
+
|
|
10
|
+
/** Own this in the component that owns the selected files, not in a module singleton. */
|
|
11
|
+
export function useFileSelection(options: FileSelectionOptions = {}) {
|
|
12
|
+
const selection = markRaw(createFileSelection(options))
|
|
13
|
+
onDeactivated(() => selection.pause())
|
|
14
|
+
onBeforeUnmount(() => selection.dispose())
|
|
15
|
+
return selection
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const filePickerProps = {
|
|
19
|
+
selection: { type: Object as PropType<FileSelectionController>, required: true as const },
|
|
20
|
+
label: { type: String, required: true as const },
|
|
21
|
+
disabled: Boolean,
|
|
22
|
+
chooseLabel: { type: String, default: 'Choose files' },
|
|
23
|
+
uploadLabel: { type: String, default: 'Upload' },
|
|
24
|
+
cancelLabel: { type: String, default: 'Cancel' },
|
|
25
|
+
retryLabel: { type: String, default: 'Retry' },
|
|
26
|
+
removeLabel: { type: String, default: 'Remove' },
|
|
27
|
+
emptyLabel: { type: String, default: 'No files selected' },
|
|
28
|
+
pendingLabel: { type: String, default: 'Working' },
|
|
29
|
+
statusLabels: {
|
|
30
|
+
type: Object as PropType<Partial<Record<FileItem['status'], string>>>,
|
|
31
|
+
default: () => ({}),
|
|
32
|
+
},
|
|
33
|
+
errorLabels: {
|
|
34
|
+
type: Object as PropType<Partial<Record<FileSelectionErrorCode, string>>>,
|
|
35
|
+
default: () => ({}),
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function fileStatusText(
|
|
40
|
+
item: FileItem,
|
|
41
|
+
labels: Partial<Record<FileItem['status'], string>>,
|
|
42
|
+
) {
|
|
43
|
+
return (
|
|
44
|
+
labels[item.status] ??
|
|
45
|
+
{
|
|
46
|
+
selected: 'Ready',
|
|
47
|
+
uploading: 'Uploading',
|
|
48
|
+
uploaded: 'Uploaded',
|
|
49
|
+
failed: 'Failed',
|
|
50
|
+
cancelled: 'Cancelled',
|
|
51
|
+
}[item.status]
|
|
52
|
+
)
|
|
53
|
+
}
|
package/src/vue/forms.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { markRaw, onScopeDispose } from '@vue/runtime-core'
|
|
2
|
+
import { useCachedActivity } from './cached-activity.js'
|
|
3
|
+
import {
|
|
4
|
+
createFormController,
|
|
5
|
+
type FormController,
|
|
6
|
+
type FormError,
|
|
7
|
+
type FormField,
|
|
8
|
+
} from '../form.js'
|
|
9
|
+
|
|
10
|
+
export function useFormController(initial: readonly FormError[] = []) {
|
|
11
|
+
const form = markRaw(createFormController(initial))
|
|
12
|
+
onScopeDispose(() => form.dispose())
|
|
13
|
+
return form
|
|
14
|
+
}
|
|
15
|
+
export function useFormField(form: FormController, field: FormField) {
|
|
16
|
+
const active = useCachedActivity()
|
|
17
|
+
const release = form.register({ ...field, target: () => (active.value ? field.target() : null) })
|
|
18
|
+
onScopeDispose(release)
|
|
19
|
+
return release
|
|
20
|
+
}
|