@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.
Files changed (282) hide show
  1. package/README.md +2 -2
  2. package/dist/capabilities.d.ts +7 -7
  3. package/dist/capabilities.d.ts.map +1 -1
  4. package/dist/capabilities.js +30 -4
  5. package/dist/capabilities.js.map +1 -1
  6. package/dist/chart.d.ts +43 -0
  7. package/dist/chart.d.ts.map +1 -0
  8. package/dist/chart.js +105 -0
  9. package/dist/chart.js.map +1 -0
  10. package/dist/collections.d.ts +46 -0
  11. package/dist/collections.d.ts.map +1 -0
  12. package/dist/collections.js +48 -0
  13. package/dist/collections.js.map +1 -0
  14. package/dist/contracts.d.ts +20 -0
  15. package/dist/contracts.d.ts.map +1 -1
  16. package/dist/contracts.js +2 -0
  17. package/dist/contracts.js.map +1 -1
  18. package/dist/date-input.d.ts +10 -0
  19. package/dist/date-input.d.ts.map +1 -0
  20. package/dist/date-input.js +58 -0
  21. package/dist/date-input.js.map +1 -0
  22. package/dist/date-time.d.ts +19 -0
  23. package/dist/date-time.d.ts.map +1 -0
  24. package/dist/date-time.js +27 -0
  25. package/dist/date-time.js.map +1 -0
  26. package/dist/discovery.d.ts +49 -0
  27. package/dist/discovery.d.ts.map +1 -0
  28. package/dist/discovery.js +80 -0
  29. package/dist/discovery.js.map +1 -0
  30. package/dist/experimental-regions.d.ts +10 -0
  31. package/dist/experimental-regions.d.ts.map +1 -1
  32. package/dist/experimental-regions.js +23 -0
  33. package/dist/experimental-regions.js.map +1 -1
  34. package/dist/experimental.d.ts +5 -0
  35. package/dist/experimental.d.ts.map +1 -1
  36. package/dist/experimental.js +29 -0
  37. package/dist/experimental.js.map +1 -1
  38. package/dist/grid.d.ts +3 -0
  39. package/dist/grid.d.ts.map +1 -0
  40. package/dist/grid.js +16 -0
  41. package/dist/grid.js.map +1 -0
  42. package/dist/index.d.ts +17 -3
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +13 -1
  45. package/dist/index.js.map +1 -1
  46. package/dist/input.d.ts +4 -0
  47. package/dist/input.d.ts.map +1 -1
  48. package/dist/input.js.map +1 -1
  49. package/dist/interactive.d.ts +36 -0
  50. package/dist/interactive.d.ts.map +1 -0
  51. package/dist/interactive.js +61 -0
  52. package/dist/interactive.js.map +1 -0
  53. package/dist/link.d.ts +24 -0
  54. package/dist/link.d.ts.map +1 -1
  55. package/dist/link.js +41 -0
  56. package/dist/link.js.map +1 -1
  57. package/dist/motion.d.ts +8 -0
  58. package/dist/motion.d.ts.map +1 -1
  59. package/dist/motion.js +11 -0
  60. package/dist/motion.js.map +1 -1
  61. package/dist/navigation-transition.d.ts +10 -0
  62. package/dist/navigation-transition.d.ts.map +1 -0
  63. package/dist/navigation-transition.js +10 -0
  64. package/dist/navigation-transition.js.map +1 -0
  65. package/dist/number-flow-format.d.ts +16 -0
  66. package/dist/number-flow-format.d.ts.map +1 -0
  67. package/dist/number-flow-format.js +49 -0
  68. package/dist/number-flow-format.js.map +1 -0
  69. package/dist/popover.d.ts +17 -0
  70. package/dist/popover.d.ts.map +1 -0
  71. package/dist/popover.js +19 -0
  72. package/dist/popover.js.map +1 -0
  73. package/dist/section-scroll.d.ts +14 -0
  74. package/dist/section-scroll.d.ts.map +1 -0
  75. package/dist/section-scroll.js +28 -0
  76. package/dist/section-scroll.js.map +1 -0
  77. package/dist/sheet.d.ts +7 -0
  78. package/dist/sheet.d.ts.map +1 -1
  79. package/dist/time.d.ts +34 -0
  80. package/dist/time.d.ts.map +1 -0
  81. package/dist/time.js +78 -0
  82. package/dist/time.js.map +1 -0
  83. package/dist/vue/carousel.d.ts +13 -0
  84. package/dist/vue/carousel.d.ts.map +1 -0
  85. package/dist/vue/carousel.js +136 -0
  86. package/dist/vue/carousel.js.map +1 -0
  87. package/dist/vue/chart.d.ts +194 -0
  88. package/dist/vue/chart.d.ts.map +1 -0
  89. package/dist/vue/chart.js +245 -0
  90. package/dist/vue/chart.js.map +1 -0
  91. package/dist/vue/command-palette.d.ts +129 -0
  92. package/dist/vue/command-palette.d.ts.map +1 -0
  93. package/dist/vue/command-palette.js +190 -0
  94. package/dist/vue/command-palette.js.map +1 -0
  95. package/dist/vue/component-motion.d.ts +17 -0
  96. package/dist/vue/component-motion.d.ts.map +1 -0
  97. package/dist/vue/component-motion.js +83 -0
  98. package/dist/vue/component-motion.js.map +1 -0
  99. package/dist/vue/component-props.d.ts +1505 -402
  100. package/dist/vue/component-props.d.ts.map +1 -1
  101. package/dist/vue/component-props.js +28 -0
  102. package/dist/vue/component-props.js.map +1 -1
  103. package/dist/vue/configurator-props.d.ts +21 -0
  104. package/dist/vue/configurator-props.d.ts.map +1 -1
  105. package/dist/vue/configurator-props.js +6 -0
  106. package/dist/vue/configurator-props.js.map +1 -1
  107. package/dist/vue/configurator.d.ts +3 -3
  108. package/dist/vue/configurator.d.ts.map +1 -1
  109. package/dist/vue/configurator.js +3 -1
  110. package/dist/vue/configurator.js.map +1 -1
  111. package/dist/vue/data-table.d.ts +17 -0
  112. package/dist/vue/data-table.d.ts.map +1 -0
  113. package/dist/vue/data-table.js +133 -0
  114. package/dist/vue/data-table.js.map +1 -0
  115. package/dist/vue/date-calendar.d.ts +2 -0
  116. package/dist/vue/date-calendar.d.ts.map +1 -1
  117. package/dist/vue/date-calendar.js +20 -1
  118. package/dist/vue/date-calendar.js.map +1 -1
  119. package/dist/vue/date-picker.d.ts +48 -13
  120. package/dist/vue/date-picker.d.ts.map +1 -1
  121. package/dist/vue/date-picker.js +67 -74
  122. package/dist/vue/date-picker.js.map +1 -1
  123. package/dist/vue/date-props.d.ts +15 -0
  124. package/dist/vue/date-props.d.ts.map +1 -1
  125. package/dist/vue/date-props.js +4 -0
  126. package/dist/vue/date-props.js.map +1 -1
  127. package/dist/vue/discovery-components.d.ts +50 -0
  128. package/dist/vue/discovery-components.d.ts.map +1 -0
  129. package/dist/vue/discovery-components.js +2 -0
  130. package/dist/vue/discovery-components.js.map +1 -0
  131. package/dist/vue/discovery-controls.d.ts +197 -0
  132. package/dist/vue/discovery-controls.d.ts.map +1 -0
  133. package/dist/vue/discovery-controls.js +185 -0
  134. package/dist/vue/discovery-controls.js.map +1 -0
  135. package/dist/vue/discovery-props.d.ts +249 -0
  136. package/dist/vue/discovery-props.d.ts.map +1 -0
  137. package/dist/vue/discovery-props.js +87 -0
  138. package/dist/vue/discovery-props.js.map +1 -0
  139. package/dist/vue/global-components.d.ts +134 -2
  140. package/dist/vue/global-components.d.ts.map +1 -1
  141. package/dist/vue/index.d.ts +27 -1
  142. package/dist/vue/index.d.ts.map +1 -1
  143. package/dist/vue/index.js +23 -1
  144. package/dist/vue/index.js.map +1 -1
  145. package/dist/vue/interactive-components.d.ts +31 -0
  146. package/dist/vue/interactive-components.d.ts.map +1 -0
  147. package/dist/vue/interactive-components.js +2 -0
  148. package/dist/vue/interactive-components.js.map +1 -0
  149. package/dist/vue/interactive-props.d.ts +254 -0
  150. package/dist/vue/interactive-props.d.ts.map +1 -0
  151. package/dist/vue/interactive-props.js +85 -0
  152. package/dist/vue/interactive-props.js.map +1 -0
  153. package/dist/vue/list-motion.d.ts +7 -0
  154. package/dist/vue/list-motion.d.ts.map +1 -0
  155. package/dist/vue/list-motion.js +28 -0
  156. package/dist/vue/list-motion.js.map +1 -0
  157. package/dist/vue/menu.d.ts +122 -0
  158. package/dist/vue/menu.d.ts.map +1 -0
  159. package/dist/vue/menu.js +79 -0
  160. package/dist/vue/menu.js.map +1 -0
  161. package/dist/vue/navigation-controls.d.ts +125 -0
  162. package/dist/vue/navigation-controls.d.ts.map +1 -0
  163. package/dist/vue/navigation-controls.js +130 -0
  164. package/dist/vue/navigation-controls.js.map +1 -0
  165. package/dist/vue/navigation-props.d.ts +283 -0
  166. package/dist/vue/navigation-props.d.ts.map +1 -0
  167. package/dist/vue/navigation-props.js +82 -0
  168. package/dist/vue/navigation-props.js.map +1 -0
  169. package/dist/vue/navigation.d.ts +7 -0
  170. package/dist/vue/navigation.d.ts.map +1 -0
  171. package/dist/vue/navigation.js +15 -0
  172. package/dist/vue/navigation.js.map +1 -0
  173. package/dist/vue/number-flow.d.ts +75 -0
  174. package/dist/vue/number-flow.d.ts.map +1 -0
  175. package/dist/vue/number-flow.js +57 -0
  176. package/dist/vue/number-flow.js.map +1 -0
  177. package/dist/vue/partition.d.ts +15 -0
  178. package/dist/vue/partition.d.ts.map +1 -0
  179. package/dist/vue/partition.js +42 -0
  180. package/dist/vue/partition.js.map +1 -0
  181. package/dist/vue/platform.d.ts +37 -0
  182. package/dist/vue/platform.d.ts.map +1 -0
  183. package/dist/vue/platform.js +46 -0
  184. package/dist/vue/platform.js.map +1 -0
  185. package/dist/vue/props.d.ts +233 -36
  186. package/dist/vue/props.d.ts.map +1 -1
  187. package/dist/vue/props.js +15 -1
  188. package/dist/vue/props.js.map +1 -1
  189. package/dist/vue/sortable-list.d.ts +24 -0
  190. package/dist/vue/sortable-list.d.ts.map +1 -0
  191. package/dist/vue/sortable-list.js +251 -0
  192. package/dist/vue/sortable-list.js.map +1 -0
  193. package/dist/vue/swipe-actions.d.ts +96 -0
  194. package/dist/vue/swipe-actions.d.ts.map +1 -0
  195. package/dist/vue/swipe-actions.js +174 -0
  196. package/dist/vue/swipe-actions.js.map +1 -0
  197. package/dist/vue/time-picker.d.ts +488 -0
  198. package/dist/vue/time-picker.d.ts.map +1 -0
  199. package/dist/vue/time-picker.js +190 -0
  200. package/dist/vue/time-picker.js.map +1 -0
  201. package/dist/vue/tree-view.d.ts +111 -0
  202. package/dist/vue/tree-view.d.ts.map +1 -0
  203. package/dist/vue/tree-view.js +204 -0
  204. package/dist/vue/tree-view.js.map +1 -0
  205. package/dist/vue/virtual-list.d.ts +26 -0
  206. package/dist/vue/virtual-list.d.ts.map +1 -0
  207. package/dist/vue/virtual-list.js +2 -0
  208. package/dist/vue/virtual-list.js.map +1 -0
  209. package/dist/vue/wayfinding-controls.d.ts +199 -0
  210. package/dist/vue/wayfinding-controls.d.ts.map +1 -0
  211. package/dist/vue/wayfinding-controls.js +330 -0
  212. package/dist/vue/wayfinding-controls.js.map +1 -0
  213. package/dist/vue/wayfinding-props.d.ts +221 -0
  214. package/dist/vue/wayfinding-props.d.ts.map +1 -0
  215. package/dist/vue/wayfinding-props.js +86 -0
  216. package/dist/vue/wayfinding-props.js.map +1 -0
  217. package/dist/vue/workflows.d.ts +2 -2
  218. package/dist/vue/workflows.d.ts.map +1 -1
  219. package/dist/vue/workflows.js +17 -4
  220. package/dist/vue/workflows.js.map +1 -1
  221. package/dist/wayfinding.d.ts +50 -0
  222. package/dist/wayfinding.d.ts.map +1 -0
  223. package/dist/wayfinding.js +54 -0
  224. package/dist/wayfinding.js.map +1 -0
  225. package/package.json +2 -2
  226. package/src/capabilities.ts +31 -4
  227. package/src/chart.ts +151 -0
  228. package/src/collections.ts +87 -0
  229. package/src/contracts.ts +2 -0
  230. package/src/date-input.ts +87 -0
  231. package/src/date-time.ts +37 -0
  232. package/src/discovery.ts +139 -0
  233. package/src/experimental-regions.ts +29 -0
  234. package/src/experimental.ts +40 -0
  235. package/src/grid.ts +19 -0
  236. package/src/index.ts +24 -3
  237. package/src/input.ts +5 -0
  238. package/src/interactive.ts +91 -0
  239. package/src/link.ts +63 -0
  240. package/src/motion.ts +14 -0
  241. package/src/navigation-transition.ts +14 -0
  242. package/src/number-flow-format.ts +68 -0
  243. package/src/popover.ts +38 -0
  244. package/src/section-scroll.ts +46 -0
  245. package/src/sheet.ts +11 -0
  246. package/src/time.ts +83 -0
  247. package/src/vue/carousel.ts +198 -0
  248. package/src/vue/chart.ts +337 -0
  249. package/src/vue/command-palette.ts +235 -0
  250. package/src/vue/component-motion.ts +109 -0
  251. package/src/vue/component-props.ts +57 -0
  252. package/src/vue/configurator-props.ts +6 -0
  253. package/src/vue/configurator.ts +3 -1
  254. package/src/vue/data-table.ts +190 -0
  255. package/src/vue/date-calendar.ts +30 -1
  256. package/src/vue/date-picker.ts +81 -85
  257. package/src/vue/date-props.ts +5 -0
  258. package/src/vue/discovery-components.ts +60 -0
  259. package/src/vue/discovery-controls.ts +241 -0
  260. package/src/vue/discovery-props.ts +92 -0
  261. package/src/vue/global-components.ts +124 -2
  262. package/src/vue/index.ts +46 -0
  263. package/src/vue/interactive-components.ts +29 -0
  264. package/src/vue/interactive-props.ts +90 -0
  265. package/src/vue/list-motion.ts +31 -0
  266. package/src/vue/menu.ts +100 -0
  267. package/src/vue/navigation-controls.ts +159 -0
  268. package/src/vue/navigation-props.ts +87 -0
  269. package/src/vue/navigation.ts +16 -0
  270. package/src/vue/number-flow.ts +83 -0
  271. package/src/vue/partition.ts +49 -0
  272. package/src/vue/platform.ts +73 -0
  273. package/src/vue/props.ts +16 -1
  274. package/src/vue/sortable-list.ts +308 -0
  275. package/src/vue/swipe-actions.ts +226 -0
  276. package/src/vue/time-picker.ts +227 -0
  277. package/src/vue/tree-view.ts +259 -0
  278. package/src/vue/virtual-list.ts +28 -0
  279. package/src/vue/wayfinding-controls.ts +430 -0
  280. package/src/vue/wayfinding-props.ts +97 -0
  281. package/src/vue/workflows.ts +17 -4
  282. package/src/wayfinding.ts +85 -0
@@ -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, Row, Sheet, Calendar } = primitives
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 ?? '', end: value.end ?? '' }
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) ?? '', end: '' }
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
- ? validateDateRangeDraft({ start: start.value, end: end.value }, props)
127
- : validateDateDraft(start.value, props)
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: draft.start ? civilDate(draft.start) : null,
169
- end: draft.end ? civilDate(draft.end) : null,
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 = isCivilDate(draft) ? draft : (props.min ?? civilDate(`${props.initialMonth}-01`))
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' ? secondOpener.value : firstOpener.value)
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 = validateDateDraft(start.value, props)
227
- const endValidation = validateDateDraft(end.value, props)
228
- const startError =
229
- touched.value || start.value.length >= 10
230
- ? dateValidationMessage(startValidation, props.locale)
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
- Row,
243
- { gap: 'sm', align: 'end' },
244
- {
245
- default: () => [
246
- h(Input, {
247
- ref: which === 'start' ? first : second,
248
- id: props.id ? `${props.id}${range ? `-${which}` : ''}` : undefined,
249
- grow: 1,
250
- shrink: 1,
251
- label: label(which),
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: isCivilDate(endpoint.value === 'end' ? end.value : start.value)
339
- ? endpoint.value === 'end'
340
- ? end.value
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
  }),
@@ -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
+ }