@getcortexlabs/mavis-core 0.1.0-alpha.8 → 0.1.0-rc.11.1
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/capabilities.d.ts +7 -7
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +30 -4
- package/dist/capabilities.js.map +1 -1
- package/dist/chart.d.ts +43 -0
- package/dist/chart.d.ts.map +1 -0
- package/dist/chart.js +105 -0
- package/dist/chart.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/contracts.d.ts +20 -0
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +2 -0
- package/dist/contracts.js.map +1 -1
- 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/discovery.d.ts +49 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +80 -0
- package/dist/discovery.js.map +1 -0
- package/dist/experimental-regions.d.ts +10 -0
- package/dist/experimental-regions.d.ts.map +1 -1
- package/dist/experimental-regions.js +23 -0
- package/dist/experimental-regions.js.map +1 -1
- package/dist/experimental.d.ts +5 -0
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +29 -0
- package/dist/experimental.js.map +1 -1
- 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/index.d.ts +17 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -1
- package/dist/index.js.map +1 -1
- package/dist/input.d.ts +4 -0
- package/dist/input.d.ts.map +1 -1
- package/dist/input.js.map +1 -1
- package/dist/interactive.d.ts +36 -0
- package/dist/interactive.d.ts.map +1 -0
- package/dist/interactive.js +61 -0
- package/dist/interactive.js.map +1 -0
- package/dist/link.d.ts +24 -0
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +41 -0
- package/dist/link.js.map +1 -1
- package/dist/motion.d.ts +8 -0
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +11 -0
- package/dist/motion.js.map +1 -1
- 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/number-flow-format.d.ts +16 -0
- package/dist/number-flow-format.d.ts.map +1 -0
- package/dist/number-flow-format.js +49 -0
- package/dist/number-flow-format.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/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/sheet.d.ts +7 -0
- package/dist/sheet.d.ts.map +1 -1
- 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/vue/carousel.d.ts +13 -0
- package/dist/vue/carousel.d.ts.map +1 -0
- package/dist/vue/carousel.js +136 -0
- package/dist/vue/carousel.js.map +1 -0
- package/dist/vue/chart.d.ts +194 -0
- package/dist/vue/chart.d.ts.map +1 -0
- package/dist/vue/chart.js +245 -0
- package/dist/vue/chart.js.map +1 -0
- package/dist/vue/command-palette.d.ts +129 -0
- package/dist/vue/command-palette.d.ts.map +1 -0
- package/dist/vue/command-palette.js +190 -0
- package/dist/vue/command-palette.js.map +1 -0
- package/dist/vue/component-motion.d.ts +17 -0
- package/dist/vue/component-motion.d.ts.map +1 -0
- package/dist/vue/component-motion.js +83 -0
- package/dist/vue/component-motion.js.map +1 -0
- package/dist/vue/component-props.d.ts +1505 -402
- package/dist/vue/component-props.d.ts.map +1 -1
- package/dist/vue/component-props.js +28 -0
- package/dist/vue/component-props.js.map +1 -1
- package/dist/vue/configurator-props.d.ts +21 -0
- package/dist/vue/configurator-props.d.ts.map +1 -1
- package/dist/vue/configurator-props.js +6 -0
- package/dist/vue/configurator-props.js.map +1 -1
- package/dist/vue/configurator.d.ts +3 -3
- package/dist/vue/configurator.d.ts.map +1 -1
- package/dist/vue/configurator.js +3 -1
- package/dist/vue/configurator.js.map +1 -1
- package/dist/vue/data-table.d.ts +17 -0
- package/dist/vue/data-table.d.ts.map +1 -0
- package/dist/vue/data-table.js +133 -0
- package/dist/vue/data-table.js.map +1 -0
- package/dist/vue/date-calendar.d.ts +2 -0
- package/dist/vue/date-calendar.d.ts.map +1 -1
- package/dist/vue/date-calendar.js +20 -1
- package/dist/vue/date-calendar.js.map +1 -1
- package/dist/vue/date-picker.d.ts +48 -13
- package/dist/vue/date-picker.d.ts.map +1 -1
- package/dist/vue/date-picker.js +67 -74
- package/dist/vue/date-picker.js.map +1 -1
- package/dist/vue/date-props.d.ts +15 -0
- package/dist/vue/date-props.d.ts.map +1 -1
- package/dist/vue/date-props.js +4 -0
- package/dist/vue/date-props.js.map +1 -1
- package/dist/vue/discovery-components.d.ts +50 -0
- package/dist/vue/discovery-components.d.ts.map +1 -0
- package/dist/vue/discovery-components.js +2 -0
- package/dist/vue/discovery-components.js.map +1 -0
- package/dist/vue/discovery-controls.d.ts +197 -0
- package/dist/vue/discovery-controls.d.ts.map +1 -0
- package/dist/vue/discovery-controls.js +185 -0
- package/dist/vue/discovery-controls.js.map +1 -0
- package/dist/vue/discovery-props.d.ts +249 -0
- package/dist/vue/discovery-props.d.ts.map +1 -0
- package/dist/vue/discovery-props.js +87 -0
- package/dist/vue/discovery-props.js.map +1 -0
- package/dist/vue/global-components.d.ts +134 -2
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/index.d.ts +27 -1
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +23 -1
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/interactive-components.d.ts +31 -0
- package/dist/vue/interactive-components.d.ts.map +1 -0
- package/dist/vue/interactive-components.js +2 -0
- package/dist/vue/interactive-components.js.map +1 -0
- package/dist/vue/interactive-props.d.ts +254 -0
- package/dist/vue/interactive-props.d.ts.map +1 -0
- package/dist/vue/interactive-props.js +85 -0
- package/dist/vue/interactive-props.js.map +1 -0
- 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/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 +125 -0
- package/dist/vue/navigation-controls.d.ts.map +1 -0
- package/dist/vue/navigation-controls.js +130 -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/number-flow.d.ts +75 -0
- package/dist/vue/number-flow.d.ts.map +1 -0
- package/dist/vue/number-flow.js +57 -0
- package/dist/vue/number-flow.js.map +1 -0
- package/dist/vue/partition.d.ts +15 -0
- package/dist/vue/partition.d.ts.map +1 -0
- package/dist/vue/partition.js +42 -0
- package/dist/vue/partition.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 +233 -36
- package/dist/vue/props.d.ts.map +1 -1
- package/dist/vue/props.js +15 -1
- package/dist/vue/props.js.map +1 -1
- package/dist/vue/sortable-list.d.ts +24 -0
- package/dist/vue/sortable-list.d.ts.map +1 -0
- package/dist/vue/sortable-list.js +251 -0
- package/dist/vue/sortable-list.js.map +1 -0
- package/dist/vue/swipe-actions.d.ts +96 -0
- package/dist/vue/swipe-actions.d.ts.map +1 -0
- package/dist/vue/swipe-actions.js +174 -0
- package/dist/vue/swipe-actions.js.map +1 -0
- 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/tree-view.d.ts +111 -0
- package/dist/vue/tree-view.d.ts.map +1 -0
- package/dist/vue/tree-view.js +204 -0
- package/dist/vue/tree-view.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/wayfinding-controls.d.ts +199 -0
- package/dist/vue/wayfinding-controls.d.ts.map +1 -0
- package/dist/vue/wayfinding-controls.js +330 -0
- package/dist/vue/wayfinding-controls.js.map +1 -0
- package/dist/vue/wayfinding-props.d.ts +221 -0
- package/dist/vue/wayfinding-props.d.ts.map +1 -0
- package/dist/vue/wayfinding-props.js +86 -0
- package/dist/vue/wayfinding-props.js.map +1 -0
- package/dist/vue/workflows.d.ts +2 -2
- package/dist/vue/workflows.d.ts.map +1 -1
- package/dist/vue/workflows.js +17 -4
- package/dist/vue/workflows.js.map +1 -1
- package/dist/wayfinding.d.ts +50 -0
- package/dist/wayfinding.d.ts.map +1 -0
- package/dist/wayfinding.js +54 -0
- package/dist/wayfinding.js.map +1 -0
- package/package.json +2 -2
- package/src/capabilities.ts +31 -4
- package/src/chart.ts +151 -0
- package/src/collections.ts +87 -0
- package/src/contracts.ts +2 -0
- package/src/date-input.ts +87 -0
- package/src/date-time.ts +37 -0
- package/src/discovery.ts +139 -0
- package/src/experimental-regions.ts +29 -0
- package/src/experimental.ts +40 -0
- package/src/grid.ts +19 -0
- package/src/index.ts +24 -3
- package/src/input.ts +5 -0
- package/src/interactive.ts +91 -0
- package/src/link.ts +63 -0
- package/src/motion.ts +14 -0
- package/src/navigation-transition.ts +14 -0
- package/src/number-flow-format.ts +68 -0
- package/src/popover.ts +38 -0
- package/src/section-scroll.ts +46 -0
- package/src/sheet.ts +11 -0
- package/src/time.ts +83 -0
- package/src/vue/carousel.ts +198 -0
- package/src/vue/chart.ts +337 -0
- package/src/vue/command-palette.ts +235 -0
- package/src/vue/component-motion.ts +109 -0
- package/src/vue/component-props.ts +57 -0
- package/src/vue/configurator-props.ts +6 -0
- package/src/vue/configurator.ts +3 -1
- package/src/vue/data-table.ts +190 -0
- package/src/vue/date-calendar.ts +30 -1
- package/src/vue/date-picker.ts +81 -85
- package/src/vue/date-props.ts +5 -0
- package/src/vue/discovery-components.ts +60 -0
- package/src/vue/discovery-controls.ts +241 -0
- package/src/vue/discovery-props.ts +92 -0
- package/src/vue/global-components.ts +124 -2
- package/src/vue/index.ts +46 -0
- package/src/vue/interactive-components.ts +29 -0
- package/src/vue/interactive-props.ts +90 -0
- package/src/vue/list-motion.ts +31 -0
- package/src/vue/menu.ts +100 -0
- package/src/vue/navigation-controls.ts +159 -0
- package/src/vue/navigation-props.ts +87 -0
- package/src/vue/navigation.ts +16 -0
- package/src/vue/number-flow.ts +83 -0
- package/src/vue/partition.ts +49 -0
- package/src/vue/platform.ts +73 -0
- package/src/vue/props.ts +16 -1
- package/src/vue/sortable-list.ts +308 -0
- package/src/vue/swipe-actions.ts +226 -0
- package/src/vue/time-picker.ts +227 -0
- package/src/vue/tree-view.ts +259 -0
- package/src/vue/virtual-list.ts +28 -0
- package/src/vue/wayfinding-controls.ts +430 -0
- package/src/vue/wayfinding-props.ts +97 -0
- package/src/vue/workflows.ts +17 -4
- package/src/wayfinding.ts +85 -0
package/src/vue/date-picker.ts
CHANGED
|
@@ -15,15 +15,20 @@ import {
|
|
|
15
15
|
civilDate,
|
|
16
16
|
dateLocales,
|
|
17
17
|
dateValidationMessage,
|
|
18
|
-
isCivilDate,
|
|
19
18
|
validateDateConstraints,
|
|
20
19
|
validateDateDraft,
|
|
21
|
-
validateDateRangeDraft,
|
|
22
20
|
type CivilDate,
|
|
23
21
|
type DateRange,
|
|
24
22
|
type DateRangeDraft,
|
|
25
23
|
type DateValidation,
|
|
26
24
|
} from '../date.js'
|
|
25
|
+
import {
|
|
26
|
+
formatDateInput,
|
|
27
|
+
parseDateInput,
|
|
28
|
+
validateDateInput,
|
|
29
|
+
validateDateRangeInput,
|
|
30
|
+
dateInputPlaceholder,
|
|
31
|
+
} from '../date-input.js'
|
|
27
32
|
import type { InputHandle } from '../input.js'
|
|
28
33
|
import {
|
|
29
34
|
datePickerProps,
|
|
@@ -49,7 +54,6 @@ interface DatePrimitives {
|
|
|
49
54
|
beforeOpen(opener: unknown): void
|
|
50
55
|
afterClose(opener: unknown): void
|
|
51
56
|
deferActions?: boolean
|
|
52
|
-
openerAttrs?: Record<string, unknown>
|
|
53
57
|
}
|
|
54
58
|
interface EntryEvents {
|
|
55
59
|
model(value: CivilDate | null | DateRange): void
|
|
@@ -61,7 +65,7 @@ interface EntryEvents {
|
|
|
61
65
|
|
|
62
66
|
/** @internal One Vue editing contract, composed with each renderer's existing primitives. */
|
|
63
67
|
export function createDatePickers(primitives: DatePrimitives) {
|
|
64
|
-
const { Input, Button, Column,
|
|
68
|
+
const { Input, Button, Column, Sheet, Calendar } = primitives
|
|
65
69
|
function useEntry(props: EntryProps, range: boolean, events: EntryEvents) {
|
|
66
70
|
useButtonAction()
|
|
67
71
|
const start = ref('')
|
|
@@ -76,8 +80,6 @@ export function createDatePickers(primitives: DatePrimitives) {
|
|
|
76
80
|
const activeDate = ref<CivilDate>('2000-01-01')
|
|
77
81
|
const first = ref<InputHandle>()
|
|
78
82
|
const second = ref<InputHandle>()
|
|
79
|
-
const firstOpener = ref<unknown>()
|
|
80
|
-
const secondOpener = ref<unknown>()
|
|
81
83
|
let alive = true
|
|
82
84
|
let revision = 0
|
|
83
85
|
let returnFocus = true
|
|
@@ -86,16 +88,21 @@ export function createDatePickers(primitives: DatePrimitives) {
|
|
|
86
88
|
throw new RangeError('Date locale must be en-US or pt-BR')
|
|
87
89
|
return dateLocales[props.locale]
|
|
88
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)
|
|
89
96
|
function snapshot(): DateRangeDraft {
|
|
90
97
|
if (range) {
|
|
91
98
|
const value = props.modelValue as DateRange
|
|
92
99
|
if (!value || typeof value !== 'object')
|
|
93
100
|
throw new RangeError('A date range needs start and end endpoints')
|
|
94
101
|
for (const date of [value.start, value.end]) if (date !== null) civilDate(date)
|
|
95
|
-
return { start: value.start
|
|
102
|
+
return { start: format(value.start), end: format(value.end) }
|
|
96
103
|
}
|
|
97
104
|
if (props.modelValue !== null) civilDate(props.modelValue as string)
|
|
98
|
-
return { start: (props.modelValue as CivilDate | null)
|
|
105
|
+
return { start: format(props.modelValue as CivilDate | null), end: '' }
|
|
99
106
|
}
|
|
100
107
|
function restore() {
|
|
101
108
|
// A controlled draft owns the editor. The canonical model remains independently valid.
|
|
@@ -120,11 +127,27 @@ export function createDatePickers(primitives: DatePrimitives) {
|
|
|
120
127
|
},
|
|
121
128
|
{ deep: true },
|
|
122
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
|
+
)
|
|
123
141
|
const validity = computed(() => {
|
|
124
142
|
validateDateConstraints(props)
|
|
125
143
|
return range
|
|
126
|
-
?
|
|
127
|
-
|
|
144
|
+
? validateDateRangeInput(
|
|
145
|
+
{ start: start.value, end: end.value },
|
|
146
|
+
props,
|
|
147
|
+
props.dateFormat,
|
|
148
|
+
props.locale,
|
|
149
|
+
)
|
|
150
|
+
: validate(start.value)
|
|
128
151
|
})
|
|
129
152
|
watch(validity, (value, previous) => {
|
|
130
153
|
if (JSON.stringify(value) !== JSON.stringify(previous)) events.validity(value)
|
|
@@ -165,12 +188,10 @@ export function createDatePickers(primitives: DatePrimitives) {
|
|
|
165
188
|
events.model(
|
|
166
189
|
range
|
|
167
190
|
? {
|
|
168
|
-
start:
|
|
169
|
-
end:
|
|
191
|
+
start: parse(draft.start),
|
|
192
|
+
end: parse(draft.end),
|
|
170
193
|
}
|
|
171
|
-
: draft.start
|
|
172
|
-
? civilDate(draft.start)
|
|
173
|
-
: null,
|
|
194
|
+
: parse(draft.start),
|
|
174
195
|
)
|
|
175
196
|
// A model proposal is controlled. Invalid/incomplete drafts remain local; a rejected
|
|
176
197
|
// valid proposal returns to the parent's value without manufacturing another edit.
|
|
@@ -182,11 +203,11 @@ export function createDatePickers(primitives: DatePrimitives) {
|
|
|
182
203
|
if (!ready.value || props.disabled || props.readonly || open.value) return
|
|
183
204
|
endpoint.value = which
|
|
184
205
|
const draft = which === 'end' ? end.value : start.value
|
|
185
|
-
let target =
|
|
206
|
+
let target = parse(draft) ?? props.min ?? civilDate(`${props.initialMonth}-01`)
|
|
186
207
|
if (props.min && target < props.min) target = props.min
|
|
187
208
|
if (props.max && target > props.max) target = props.max
|
|
188
209
|
activeDate.value = target
|
|
189
|
-
primitives.beforeOpen(which === 'end' ?
|
|
210
|
+
primitives.beforeOpen(which === 'end' ? second.value : first.value)
|
|
190
211
|
open.value = true
|
|
191
212
|
}
|
|
192
213
|
const handle: InputHandle = {
|
|
@@ -219,69 +240,50 @@ export function createDatePickers(primitives: DatePrimitives) {
|
|
|
219
240
|
)
|
|
220
241
|
throw new RangeError('firstDayOfWeek must be an integer from 0 to 6')
|
|
221
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)
|
|
222
246
|
const label = (which: 'start' | 'end') =>
|
|
223
247
|
range
|
|
224
248
|
? `${props.label} · ${which === 'start' ? (props.startLabel ?? translations.start) : (props.endLabel ?? translations.end)}`
|
|
225
249
|
: props.label
|
|
226
|
-
const startValidation =
|
|
227
|
-
const endValidation =
|
|
228
|
-
const startError =
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
: ''
|
|
232
|
-
const endError =
|
|
233
|
-
touched.value || end.value.length >= 10
|
|
234
|
-
? dateValidationMessage(endValidation, props.locale)
|
|
235
|
-
: ''
|
|
236
|
-
const rangeError =
|
|
237
|
-
startValidation.valid && endValidation.valid
|
|
238
|
-
? dateValidationMessage(validity.value, props.locale)
|
|
239
|
-
: ''
|
|
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) : ''
|
|
240
255
|
const field = (which: 'start' | 'end') =>
|
|
241
|
-
h(
|
|
242
|
-
|
|
243
|
-
{
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
modelValue: which === 'start' ? start.value : end.value,
|
|
253
|
-
name: range ? (which === 'start' ? props.startName : props.endName) : props.name,
|
|
254
|
-
type: 'text',
|
|
255
|
-
placeholder: translations.format,
|
|
256
|
-
autocapitalize: 'none',
|
|
257
|
-
autocorrect: false,
|
|
258
|
-
disabled: props.disabled,
|
|
259
|
-
readonly: props.readonly,
|
|
260
|
-
helperText: !range || which === 'end' ? props.helperText : '',
|
|
261
|
-
error: !range
|
|
262
|
-
? props.error || startError
|
|
263
|
-
: which === 'start'
|
|
264
|
-
? startError
|
|
265
|
-
: props.error || endError || rangeError,
|
|
266
|
-
'onUpdate:modelValue': (value: string) => edit(which, value),
|
|
267
|
-
onFocus: events.focus,
|
|
268
|
-
onBlur: () => {
|
|
269
|
-
touched.value = true
|
|
270
|
-
events.blur()
|
|
271
|
-
},
|
|
272
|
-
}),
|
|
273
|
-
h(Button, {
|
|
274
|
-
...primitives.openerAttrs,
|
|
275
|
-
ref: which === 'start' ? firstOpener : secondOpener,
|
|
276
|
-
icon: 'calendar-days',
|
|
277
|
-
variant: 'secondary',
|
|
278
|
-
accessibilityLabel: `${props.calendarLabel ?? translations.calendar}: ${label(which)}`,
|
|
279
|
-
disabled: !ready.value || props.disabled || props.readonly,
|
|
280
|
-
onClick: () => show(which),
|
|
281
|
-
}),
|
|
282
|
-
],
|
|
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,
|
|
283
267
|
},
|
|
284
|
-
|
|
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
|
+
})
|
|
285
287
|
return h(
|
|
286
288
|
Column,
|
|
287
289
|
mergeProps(attrs, {
|
|
@@ -331,17 +333,11 @@ export function createDatePickers(primitives: DatePrimitives) {
|
|
|
331
333
|
activeDate: activeDate.value,
|
|
332
334
|
onVnodeUnmounted: () => {
|
|
333
335
|
if (alive && returnFocus && !props.disabled && !open.value)
|
|
334
|
-
primitives.afterClose(
|
|
335
|
-
endpoint.value === 'end' ? secondOpener.value : firstOpener.value,
|
|
336
|
-
)
|
|
336
|
+
primitives.afterClose(endpoint.value === 'end' ? second.value : first.value)
|
|
337
337
|
},
|
|
338
|
-
selected:
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
: start.value
|
|
342
|
-
: null,
|
|
343
|
-
rangeStart: range && isCivilDate(start.value) ? start.value : null,
|
|
344
|
-
rangeEnd: range && isCivilDate(end.value) ? end.value : null,
|
|
338
|
+
selected: parse(endpoint.value === 'end' ? end.value : start.value),
|
|
339
|
+
rangeStart: range ? parse(start.value) : null,
|
|
340
|
+
rangeEnd: range ? parse(end.value) : null,
|
|
345
341
|
min: props.min,
|
|
346
342
|
max: props.max,
|
|
347
343
|
unavailableDates: props.unavailableDates,
|
|
@@ -359,7 +355,7 @@ export function createDatePickers(primitives: DatePrimitives) {
|
|
|
359
355
|
)
|
|
360
356
|
return
|
|
361
357
|
touched.value = true
|
|
362
|
-
edit(endpoint.value, value)
|
|
358
|
+
edit(endpoint.value, format(value))
|
|
363
359
|
close()
|
|
364
360
|
},
|
|
365
361
|
}),
|
package/src/vue/date-props.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ExtractPublicPropTypes, PropType } from '@vue/runtime-core'
|
|
2
2
|
import type { CivilDate, DateLocale, DateRange, DateRangeDraft, DateValidation } from '../date.js'
|
|
3
3
|
import { isCivilDate } from '../date.js'
|
|
4
|
+
import type { DateInputFormat } from '../date-input.js'
|
|
4
5
|
import { dimensionProperty } from '../contracts.js'
|
|
5
6
|
import { vueProperty } from './contracts.js'
|
|
6
7
|
import { flexProps, viewProps } from './props.js'
|
|
@@ -13,6 +14,7 @@ const dateOptions = {
|
|
|
13
14
|
firstDayOfWeek: { type: Number, default: undefined },
|
|
14
15
|
}
|
|
15
16
|
const common = {
|
|
17
|
+
dateFormat: { type: String as PropType<DateInputFormat>, default: 'iso' as const },
|
|
16
18
|
id: viewProps.id,
|
|
17
19
|
accessibilityHidden: viewProps.accessibilityHidden,
|
|
18
20
|
...flexProps,
|
|
@@ -72,6 +74,9 @@ export type DateRangePickerProps = ExtractPublicPropTypes<typeof dateRangePicker
|
|
|
72
74
|
|
|
73
75
|
/** @internal Shared themed calendar presentation contract. */
|
|
74
76
|
export const dateCalendarProps = {
|
|
77
|
+
autofocus: { type: Boolean, default: true },
|
|
78
|
+
disabled: Boolean,
|
|
79
|
+
readonly: Boolean,
|
|
75
80
|
...dateOptions,
|
|
76
81
|
activeDate: { type: String as PropType<CivilDate>, required: true as const },
|
|
77
82
|
selected: { type: String as PropType<CivilDate | null>, default: null },
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { PublicProps, VNode, VNodeChild } from '@vue/runtime-core'
|
|
2
|
+
import type { ComponentProps } from './component-props.js'
|
|
3
|
+
import type { ChoiceValue } from '../choice.js'
|
|
4
|
+
import type { VirtualItemSlot } from '../collections.js'
|
|
5
|
+
import type { DataColumn, DataCellSlot, DataSort } from '../discovery.js'
|
|
6
|
+
|
|
7
|
+
type Key<T> = Extract<keyof T, string> | ((item: T) => ChoiceValue)
|
|
8
|
+
interface Context<P, S> {
|
|
9
|
+
props: P
|
|
10
|
+
attrs: Record<string, unknown>
|
|
11
|
+
emit: (event: string, ...args: unknown[]) => void
|
|
12
|
+
slots: S
|
|
13
|
+
}
|
|
14
|
+
type CarouselProps<T> = PublicProps &
|
|
15
|
+
Omit<ComponentProps['MCarousel'], 'items' | 'itemKey'> & {
|
|
16
|
+
items: readonly T[]
|
|
17
|
+
itemKey?: Key<T>
|
|
18
|
+
'onUpdate:modelValue'?: (key: ChoiceValue) => void
|
|
19
|
+
}
|
|
20
|
+
type CarouselContext<T> = Context<
|
|
21
|
+
CarouselProps<T>,
|
|
22
|
+
{ default?: (scope: VirtualItemSlot<T>) => VNodeChild; empty?: () => VNodeChild }
|
|
23
|
+
>
|
|
24
|
+
export interface CarouselComponent {
|
|
25
|
+
<T>(
|
|
26
|
+
props: NonNullable<Awaited<typeof setup>>['props'],
|
|
27
|
+
context?: Pick<NonNullable<Awaited<typeof setup>>, 'attrs' | 'emit' | 'slots'>,
|
|
28
|
+
exposed?: undefined,
|
|
29
|
+
setup?: Promise<CarouselContext<T>>,
|
|
30
|
+
): VNode & { __ctx?: NonNullable<Awaited<typeof setup>> }
|
|
31
|
+
}
|
|
32
|
+
type TableProps<T> = PublicProps &
|
|
33
|
+
Omit<
|
|
34
|
+
ComponentProps['MDataTable'],
|
|
35
|
+
'items' | 'itemKey' | 'columns' | 'rowLabel' | 'rowDisabled'
|
|
36
|
+
> & {
|
|
37
|
+
items: readonly T[]
|
|
38
|
+
itemKey?: Key<T>
|
|
39
|
+
columns: readonly DataColumn<T>[]
|
|
40
|
+
rowLabel?: (item: T) => string
|
|
41
|
+
rowDisabled?: (item: T) => boolean
|
|
42
|
+
'onUpdate:sort'?: (sort: DataSort | null) => void
|
|
43
|
+
'onUpdate:selected'?: (keys: ChoiceValue[]) => void
|
|
44
|
+
}
|
|
45
|
+
type TableSlots<T> = {
|
|
46
|
+
cell?: (scope: DataCellSlot<T>) => VNodeChild
|
|
47
|
+
actions?: () => VNodeChild
|
|
48
|
+
footer?: () => VNodeChild
|
|
49
|
+
empty?: () => VNodeChild
|
|
50
|
+
} & {
|
|
51
|
+
[name: `cell:${string}`]: ((scope: DataCellSlot<T>) => VNodeChild) | undefined
|
|
52
|
+
}
|
|
53
|
+
export interface DataTableComponent {
|
|
54
|
+
<T>(
|
|
55
|
+
props: NonNullable<Awaited<typeof setup>>['props'],
|
|
56
|
+
context?: Pick<NonNullable<Awaited<typeof setup>>, 'attrs' | 'emit' | 'slots'>,
|
|
57
|
+
exposed?: undefined,
|
|
58
|
+
setup?: Promise<Context<TableProps<T>, TableSlots<T>>>,
|
|
59
|
+
): VNode & { __ctx?: NonNullable<Awaited<typeof setup>> }
|
|
60
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { useComponentState } from './component-motion.js'
|
|
2
|
+
import {
|
|
3
|
+
computed,
|
|
4
|
+
defineComponent,
|
|
5
|
+
h,
|
|
6
|
+
mergeProps,
|
|
7
|
+
ref,
|
|
8
|
+
watch,
|
|
9
|
+
type Component,
|
|
10
|
+
} from '@vue/runtime-core'
|
|
11
|
+
import { calendarProps, ratingProps } from './discovery-props.js'
|
|
12
|
+
import { ratingValue } from '../discovery.js'
|
|
13
|
+
import {
|
|
14
|
+
civilDate,
|
|
15
|
+
dateAvailability,
|
|
16
|
+
validateDateConstraints,
|
|
17
|
+
validateDateRangeDraft,
|
|
18
|
+
type CivilDate,
|
|
19
|
+
type DateRange,
|
|
20
|
+
} from '../date.js'
|
|
21
|
+
import { useMavisTheme } from './theme.js'
|
|
22
|
+
|
|
23
|
+
interface Primitives {
|
|
24
|
+
Column: Component
|
|
25
|
+
Row: Component
|
|
26
|
+
Text: Component
|
|
27
|
+
Button: Component
|
|
28
|
+
Icon: Component
|
|
29
|
+
Slider: Component
|
|
30
|
+
Calendar: Component
|
|
31
|
+
}
|
|
32
|
+
function initialCalendarDate(
|
|
33
|
+
value: CivilDate | null,
|
|
34
|
+
props: { min?: CivilDate; max?: CivilDate; initialMonth: string },
|
|
35
|
+
) {
|
|
36
|
+
let date = value ?? props.min ?? civilDate(`${props.initialMonth}-01`)
|
|
37
|
+
if (props.min && date < props.min) date = props.min
|
|
38
|
+
if (props.max && date > props.max) date = props.max
|
|
39
|
+
return date
|
|
40
|
+
}
|
|
41
|
+
export function createDiscoveryControls(ui: Primitives, platform: 'web' | 'native') {
|
|
42
|
+
const MCalendar = defineComponent({
|
|
43
|
+
name: 'MCalendar',
|
|
44
|
+
inheritAttrs: false,
|
|
45
|
+
props: calendarProps,
|
|
46
|
+
emits: {
|
|
47
|
+
'update:modelValue': (_value: CivilDate | DateRange | null) => true,
|
|
48
|
+
invalid: () => true,
|
|
49
|
+
},
|
|
50
|
+
setup(props, { attrs, emit, slots }) {
|
|
51
|
+
const { theme } = useMavisTheme()
|
|
52
|
+
const selected = computed(() =>
|
|
53
|
+
typeof props.modelValue === 'string' ? civilDate(props.modelValue) : null,
|
|
54
|
+
)
|
|
55
|
+
const range = computed(() =>
|
|
56
|
+
typeof props.modelValue === 'object' && props.modelValue !== null
|
|
57
|
+
? props.modelValue
|
|
58
|
+
: { start: null, end: null },
|
|
59
|
+
)
|
|
60
|
+
const active = ref<CivilDate>(initialCalendarDate(selected.value ?? range.value.start, props))
|
|
61
|
+
const invalid = ref(false)
|
|
62
|
+
watch(
|
|
63
|
+
() => [props.modelValue, props.initialMonth],
|
|
64
|
+
() => {
|
|
65
|
+
active.value = initialCalendarDate(
|
|
66
|
+
selected.value ?? range.value.end ?? range.value.start,
|
|
67
|
+
props,
|
|
68
|
+
)
|
|
69
|
+
invalid.value = false
|
|
70
|
+
},
|
|
71
|
+
)
|
|
72
|
+
function select(date: CivilDate) {
|
|
73
|
+
if (props.disabled || props.readonly || dateAvailability(date, props)) return
|
|
74
|
+
invalid.value = false
|
|
75
|
+
if (props.mode === 'single') emit('update:modelValue', date)
|
|
76
|
+
else if (!range.value.start || range.value.end)
|
|
77
|
+
emit('update:modelValue', { start: date, end: null })
|
|
78
|
+
else {
|
|
79
|
+
const next =
|
|
80
|
+
date < range.value.start
|
|
81
|
+
? { start: date, end: range.value.start }
|
|
82
|
+
: { start: range.value.start, end: date }
|
|
83
|
+
if (!validateDateRangeDraft({ start: next.start, end: next.end }, props).valid) {
|
|
84
|
+
invalid.value = true
|
|
85
|
+
emit('invalid')
|
|
86
|
+
} else emit('update:modelValue', next)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return () => {
|
|
90
|
+
validateDateConstraints(props)
|
|
91
|
+
if (
|
|
92
|
+
props.mode === 'single' &&
|
|
93
|
+
props.modelValue !== null &&
|
|
94
|
+
typeof props.modelValue !== 'string'
|
|
95
|
+
)
|
|
96
|
+
throw new TypeError('Single calendars require a civil date.')
|
|
97
|
+
if (props.mode === 'range' && typeof props.modelValue === 'string')
|
|
98
|
+
throw new TypeError('Range calendars require start and end.')
|
|
99
|
+
for (const date of [range.value.start, range.value.end]) if (date !== null) civilDate(date)
|
|
100
|
+
return h(
|
|
101
|
+
ui.Column,
|
|
102
|
+
mergeProps(
|
|
103
|
+
{
|
|
104
|
+
id: props.id,
|
|
105
|
+
gap: 'md',
|
|
106
|
+
padding: 'sm',
|
|
107
|
+
radius: 'lg',
|
|
108
|
+
backgroundColor: theme.value.colors.surface,
|
|
109
|
+
},
|
|
110
|
+
attrs,
|
|
111
|
+
platform === 'web'
|
|
112
|
+
? { role: 'group', 'aria-label': props.label, class: 'm-calendar' }
|
|
113
|
+
: {},
|
|
114
|
+
),
|
|
115
|
+
() => [
|
|
116
|
+
h(ui.Text, { as: 'h2', variant: 'heading', text: props.label }),
|
|
117
|
+
h(ui.Calendar, {
|
|
118
|
+
...props,
|
|
119
|
+
autofocus: false,
|
|
120
|
+
activeDate: active.value,
|
|
121
|
+
selected: selected.value,
|
|
122
|
+
rangeStart: range.value.start,
|
|
123
|
+
rangeEnd: range.value.end,
|
|
124
|
+
'onUpdate:activeDate': (date: CivilDate) => {
|
|
125
|
+
active.value = date
|
|
126
|
+
},
|
|
127
|
+
onSelect: select,
|
|
128
|
+
}),
|
|
129
|
+
invalid.value
|
|
130
|
+
? h(ui.Text, {
|
|
131
|
+
text: props.invalidRangeLabel,
|
|
132
|
+
tone: 'danger',
|
|
133
|
+
...(platform === 'web'
|
|
134
|
+
? { role: 'alert' }
|
|
135
|
+
: { accessibilityLiveRegion: 'assertive' }),
|
|
136
|
+
})
|
|
137
|
+
: null,
|
|
138
|
+
slots.footer?.(),
|
|
139
|
+
],
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
})
|
|
144
|
+
const RatingStar = defineComponent({
|
|
145
|
+
props: { filled: Boolean, half: Boolean, readonly: Boolean, disabled: Boolean, label: String },
|
|
146
|
+
emits: ['choose'],
|
|
147
|
+
setup(props, { emit }) {
|
|
148
|
+
const motion = useComponentState(
|
|
149
|
+
() => ({
|
|
150
|
+
scale: props.filled || props.half ? 1 : 0.9,
|
|
151
|
+
rotate: props.filled || props.half ? 0 : -8,
|
|
152
|
+
}),
|
|
153
|
+
'feedback',
|
|
154
|
+
)
|
|
155
|
+
return () =>
|
|
156
|
+
props.readonly
|
|
157
|
+
? h(ui.Icon, {
|
|
158
|
+
name: props.half ? 'star-half' : 'star',
|
|
159
|
+
size: 28,
|
|
160
|
+
tone: props.filled || props.half ? 'primary' : 'muted',
|
|
161
|
+
motionSurface: motion,
|
|
162
|
+
accessibilityHidden: true,
|
|
163
|
+
})
|
|
164
|
+
: h(ui.Button, {
|
|
165
|
+
icon: props.half ? 'star-half' : 'star',
|
|
166
|
+
variant: props.filled || props.half ? 'primary' : 'secondary',
|
|
167
|
+
motionSurface: motion,
|
|
168
|
+
disabled: props.disabled,
|
|
169
|
+
accessibilityLabel: props.label,
|
|
170
|
+
onClick: () => emit('choose'),
|
|
171
|
+
})
|
|
172
|
+
},
|
|
173
|
+
})
|
|
174
|
+
const MRating = defineComponent({
|
|
175
|
+
name: 'MRating',
|
|
176
|
+
inheritAttrs: false,
|
|
177
|
+
props: ratingProps,
|
|
178
|
+
emits: { 'update:modelValue': (_value: number) => true },
|
|
179
|
+
setup(props, { attrs, emit }) {
|
|
180
|
+
const value = computed(() => ratingValue(props.modelValue, props.max, props.step))
|
|
181
|
+
const label = (next: number) =>
|
|
182
|
+
props.formatValue?.(next, props.max) ?? `${next} / ${props.max}`
|
|
183
|
+
function choose(next: number) {
|
|
184
|
+
if (!props.readonly && !props.disabled && next !== value.value)
|
|
185
|
+
emit('update:modelValue', ratingValue(next, props.max, props.step))
|
|
186
|
+
}
|
|
187
|
+
return () =>
|
|
188
|
+
h(
|
|
189
|
+
ui.Column,
|
|
190
|
+
mergeProps(
|
|
191
|
+
{ id: props.id, gap: 'sm' },
|
|
192
|
+
attrs,
|
|
193
|
+
platform === 'web'
|
|
194
|
+
? { class: 'm-rating', role: 'group', 'aria-label': props.label }
|
|
195
|
+
: {},
|
|
196
|
+
),
|
|
197
|
+
() => [
|
|
198
|
+
h(ui.Row, { justify: 'between', gap: 'sm', wrap: true }, () => [
|
|
199
|
+
h(ui.Text, { text: props.label, weight: '600' }),
|
|
200
|
+
h(ui.Text, { text: label(value.value), tone: 'muted', variant: 'caption' }),
|
|
201
|
+
]),
|
|
202
|
+
h(ui.Row, { gap: 'xs', wrap: true }, () =>
|
|
203
|
+
Array.from({ length: props.max }, (_, index) => {
|
|
204
|
+
const filled = value.value >= index + 1
|
|
205
|
+
const half = value.value > index && !filled
|
|
206
|
+
return h(RatingStar, {
|
|
207
|
+
key: index,
|
|
208
|
+
filled,
|
|
209
|
+
half,
|
|
210
|
+
readonly: props.readonly,
|
|
211
|
+
disabled: props.disabled,
|
|
212
|
+
label: `${props.label}: ${label(index + 1)}`,
|
|
213
|
+
onChoose: () => choose(index + 1),
|
|
214
|
+
})
|
|
215
|
+
}),
|
|
216
|
+
),
|
|
217
|
+
!props.readonly && props.step === 0.5
|
|
218
|
+
? h(ui.Slider, {
|
|
219
|
+
modelValue: value.value,
|
|
220
|
+
min: 0,
|
|
221
|
+
max: props.max,
|
|
222
|
+
step: props.step,
|
|
223
|
+
label: props.label,
|
|
224
|
+
disabled: props.disabled,
|
|
225
|
+
'onUpdate:modelValue': choose,
|
|
226
|
+
})
|
|
227
|
+
: null,
|
|
228
|
+
props.clearable && !props.readonly
|
|
229
|
+
? h(ui.Button, {
|
|
230
|
+
text: props.clearLabel,
|
|
231
|
+
variant: 'ghost',
|
|
232
|
+
disabled: props.disabled || value.value === 0,
|
|
233
|
+
onClick: () => choose(0),
|
|
234
|
+
})
|
|
235
|
+
: null,
|
|
236
|
+
],
|
|
237
|
+
)
|
|
238
|
+
},
|
|
239
|
+
})
|
|
240
|
+
return { MCalendar, MRating }
|
|
241
|
+
}
|