@getcortexlabs/mavis-core 0.1.0-alpha.3 → 0.1.0-alpha.5

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 (242) hide show
  1. package/README.md +2 -2
  2. package/dist/accordion.d.ts +17 -0
  3. package/dist/accordion.d.ts.map +1 -0
  4. package/dist/accordion.js +42 -0
  5. package/dist/accordion.js.map +1 -0
  6. package/dist/alert.d.ts +21 -0
  7. package/dist/alert.d.ts.map +1 -0
  8. package/dist/alert.js +13 -0
  9. package/dist/alert.js.map +1 -0
  10. package/dist/avatar.d.ts +10 -0
  11. package/dist/avatar.d.ts.map +1 -0
  12. package/dist/avatar.js +11 -0
  13. package/dist/avatar.js.map +1 -0
  14. package/dist/badge.d.ts +7 -0
  15. package/dist/badge.d.ts.map +1 -0
  16. package/dist/badge.js +11 -0
  17. package/dist/badge.js.map +1 -0
  18. package/dist/capabilities.d.ts +119 -0
  19. package/dist/capabilities.d.ts.map +1 -0
  20. package/dist/capabilities.js +142 -0
  21. package/dist/capabilities.js.map +1 -0
  22. package/dist/chip.d.ts +9 -0
  23. package/dist/chip.d.ts.map +1 -0
  24. package/dist/chip.js +16 -0
  25. package/dist/chip.js.map +1 -0
  26. package/dist/choice.d.ts +15 -0
  27. package/dist/choice.d.ts.map +1 -0
  28. package/dist/choice.js +27 -0
  29. package/dist/choice.js.map +1 -0
  30. package/dist/combobox.d.ts +42 -0
  31. package/dist/combobox.d.ts.map +1 -0
  32. package/dist/combobox.js +159 -0
  33. package/dist/combobox.js.map +1 -0
  34. package/dist/contracts.d.ts +1201 -0
  35. package/dist/contracts.d.ts.map +1 -0
  36. package/dist/contracts.js +242 -0
  37. package/dist/contracts.js.map +1 -0
  38. package/dist/date.d.ts +96 -0
  39. package/dist/date.d.ts.map +1 -0
  40. package/dist/date.js +235 -0
  41. package/dist/date.js.map +1 -0
  42. package/dist/dialog.d.ts +4 -0
  43. package/dist/dialog.d.ts.map +1 -0
  44. package/dist/dialog.js +20 -0
  45. package/dist/dialog.js.map +1 -0
  46. package/dist/empty-state.d.ts +2 -0
  47. package/dist/empty-state.d.ts.map +1 -0
  48. package/dist/empty-state.js +5 -0
  49. package/dist/empty-state.js.map +1 -0
  50. package/dist/experimental-regions.d.ts +142 -0
  51. package/dist/experimental-regions.d.ts.map +1 -0
  52. package/dist/experimental-regions.js +315 -0
  53. package/dist/experimental-regions.js.map +1 -0
  54. package/dist/experimental.d.ts +134 -0
  55. package/dist/experimental.d.ts.map +1 -0
  56. package/dist/experimental.js +502 -0
  57. package/dist/experimental.js.map +1 -0
  58. package/dist/files.d.ts +87 -0
  59. package/dist/files.d.ts.map +1 -0
  60. package/dist/files.js +328 -0
  61. package/dist/files.js.map +1 -0
  62. package/dist/form.d.ts +39 -0
  63. package/dist/form.d.ts.map +1 -0
  64. package/dist/form.js +170 -0
  65. package/dist/form.js.map +1 -0
  66. package/dist/index.d.ts +38 -4
  67. package/dist/index.d.ts.map +1 -1
  68. package/dist/index.js +23 -1
  69. package/dist/index.js.map +1 -1
  70. package/dist/input.d.ts +10 -0
  71. package/dist/input.d.ts.map +1 -1
  72. package/dist/input.js +12 -0
  73. package/dist/input.js.map +1 -1
  74. package/dist/list-item.d.ts +3 -0
  75. package/dist/list-item.d.ts.map +1 -0
  76. package/dist/list-item.js +7 -0
  77. package/dist/list-item.js.map +1 -0
  78. package/dist/motion.d.ts +33 -0
  79. package/dist/motion.d.ts.map +1 -0
  80. package/dist/motion.js +21 -0
  81. package/dist/motion.js.map +1 -0
  82. package/dist/navigation.d.ts +22 -0
  83. package/dist/navigation.d.ts.map +1 -0
  84. package/dist/navigation.js +54 -0
  85. package/dist/navigation.js.map +1 -0
  86. package/dist/progress.d.ts +19 -0
  87. package/dist/progress.d.ts.map +1 -0
  88. package/dist/progress.js +19 -0
  89. package/dist/progress.js.map +1 -0
  90. package/dist/segmented.d.ts +11 -0
  91. package/dist/segmented.d.ts.map +1 -0
  92. package/dist/segmented.js +30 -0
  93. package/dist/segmented.js.map +1 -0
  94. package/dist/sheet.d.ts +8 -1
  95. package/dist/sheet.d.ts.map +1 -1
  96. package/dist/sheet.js +4 -3
  97. package/dist/sheet.js.map +1 -1
  98. package/dist/tabs.d.ts +11 -0
  99. package/dist/tabs.d.ts.map +1 -0
  100. package/dist/tabs.js +28 -0
  101. package/dist/tabs.js.map +1 -0
  102. package/dist/theme/themes.d.ts.map +1 -1
  103. package/dist/theme/themes.js +84 -11
  104. package/dist/theme/themes.js.map +1 -1
  105. package/dist/theme/types.d.ts +52 -1
  106. package/dist/theme/types.d.ts.map +1 -1
  107. package/dist/theme/typography.d.ts +10 -0
  108. package/dist/theme/typography.d.ts.map +1 -0
  109. package/dist/theme/typography.js +90 -0
  110. package/dist/theme/typography.js.map +1 -0
  111. package/dist/toast.d.ts +43 -0
  112. package/dist/toast.d.ts.map +1 -0
  113. package/dist/toast.js +228 -0
  114. package/dist/toast.js.map +1 -0
  115. package/dist/vue/button-content.d.ts +10 -0
  116. package/dist/vue/button-content.d.ts.map +1 -0
  117. package/dist/vue/button-content.js +54 -0
  118. package/dist/vue/button-content.js.map +1 -0
  119. package/dist/vue/cached-activity.d.ts +3 -0
  120. package/dist/vue/cached-activity.d.ts.map +1 -0
  121. package/dist/vue/cached-activity.js +13 -0
  122. package/dist/vue/cached-activity.js.map +1 -0
  123. package/dist/vue/combobox.d.ts +155 -0
  124. package/dist/vue/combobox.d.ts.map +1 -0
  125. package/dist/vue/combobox.js +195 -0
  126. package/dist/vue/combobox.js.map +1 -0
  127. package/dist/vue/component-props.d.ts +1989 -0
  128. package/dist/vue/component-props.d.ts.map +1 -0
  129. package/dist/vue/component-props.js +18 -0
  130. package/dist/vue/component-props.js.map +1 -0
  131. package/dist/vue/contracts.d.ts +18 -0
  132. package/dist/vue/contracts.d.ts.map +1 -0
  133. package/dist/vue/contracts.js +18 -0
  134. package/dist/vue/contracts.js.map +1 -0
  135. package/dist/vue/date-calendar.d.ts +64 -0
  136. package/dist/vue/date-calendar.d.ts.map +1 -0
  137. package/dist/vue/date-calendar.js +65 -0
  138. package/dist/vue/date-calendar.js.map +1 -0
  139. package/dist/vue/date-picker.d.ts +927 -0
  140. package/dist/vue/date-picker.d.ts.map +1 -0
  141. package/dist/vue/date-picker.js +319 -0
  142. package/dist/vue/date-picker.js.map +1 -0
  143. package/dist/vue/date-props.d.ts +254 -0
  144. package/dist/vue/date-props.d.ts.map +1 -0
  145. package/dist/vue/date-props.js +74 -0
  146. package/dist/vue/date-props.js.map +1 -0
  147. package/dist/vue/dialog.d.ts +21 -0
  148. package/dist/vue/dialog.d.ts.map +1 -0
  149. package/dist/vue/dialog.js +58 -0
  150. package/dist/vue/dialog.js.map +1 -0
  151. package/dist/vue/files.d.ts +53 -0
  152. package/dist/vue/files.d.ts.map +1 -0
  153. package/dist/vue/files.js +40 -0
  154. package/dist/vue/files.js.map +1 -0
  155. package/dist/vue/forms.d.ts +4 -0
  156. package/dist/vue/forms.d.ts.map +1 -0
  157. package/dist/vue/forms.js +15 -0
  158. package/dist/vue/forms.js.map +1 -0
  159. package/dist/vue/global-components.d.ts +129 -3
  160. package/dist/vue/global-components.d.ts.map +1 -1
  161. package/dist/vue/index.d.ts +28 -2
  162. package/dist/vue/index.d.ts.map +1 -1
  163. package/dist/vue/index.js +24 -1
  164. package/dist/vue/index.js.map +1 -1
  165. package/dist/vue/inline-content.d.ts +54 -0
  166. package/dist/vue/inline-content.d.ts.map +1 -0
  167. package/dist/vue/inline-content.js +64 -0
  168. package/dist/vue/inline-content.js.map +1 -0
  169. package/dist/vue/props.d.ts +2654 -637
  170. package/dist/vue/props.d.ts.map +1 -1
  171. package/dist/vue/props.js +228 -86
  172. package/dist/vue/props.js.map +1 -1
  173. package/dist/vue/theme-provider.d.ts +58 -0
  174. package/dist/vue/theme-provider.d.ts.map +1 -0
  175. package/dist/vue/theme-provider.js +69 -0
  176. package/dist/vue/theme-provider.js.map +1 -0
  177. package/dist/vue/theme.d.ts +962 -12
  178. package/dist/vue/theme.d.ts.map +1 -1
  179. package/dist/vue/theme.js +17 -7
  180. package/dist/vue/theme.js.map +1 -1
  181. package/dist/vue/toast.d.ts +29 -0
  182. package/dist/vue/toast.d.ts.map +1 -0
  183. package/dist/vue/toast.js +79 -0
  184. package/dist/vue/toast.js.map +1 -0
  185. package/dist/vue/workflow-props.d.ts +110 -0
  186. package/dist/vue/workflow-props.d.ts.map +1 -0
  187. package/dist/vue/workflow-props.js +37 -0
  188. package/dist/vue/workflow-props.js.map +1 -0
  189. package/dist/vue/workflows.d.ts +267 -0
  190. package/dist/vue/workflows.d.ts.map +1 -0
  191. package/dist/vue/workflows.js +200 -0
  192. package/dist/vue/workflows.js.map +1 -0
  193. package/package.json +5 -1
  194. package/src/accordion.ts +66 -0
  195. package/src/alert.ts +16 -0
  196. package/src/avatar.ts +11 -0
  197. package/src/badge.ts +11 -0
  198. package/src/capabilities.ts +145 -0
  199. package/src/chip.ts +20 -0
  200. package/src/choice.ts +41 -0
  201. package/src/combobox.ts +198 -0
  202. package/src/contracts.ts +295 -0
  203. package/src/date.ts +280 -0
  204. package/src/dialog.ts +20 -0
  205. package/src/empty-state.ts +4 -0
  206. package/src/experimental-regions.ts +463 -0
  207. package/src/experimental.ts +643 -0
  208. package/src/files.ts +408 -0
  209. package/src/form.ts +190 -0
  210. package/src/index.ts +64 -3
  211. package/src/input.ts +22 -0
  212. package/src/list-item.ts +5 -0
  213. package/src/motion.ts +22 -0
  214. package/src/navigation.ts +61 -0
  215. package/src/progress.ts +22 -0
  216. package/src/segmented.ts +39 -0
  217. package/src/sheet.ts +6 -3
  218. package/src/tabs.ts +35 -0
  219. package/src/theme/themes.ts +88 -11
  220. package/src/theme/types.ts +42 -1
  221. package/src/theme/typography.ts +84 -0
  222. package/src/toast.ts +249 -0
  223. package/src/vue/button-content.ts +60 -0
  224. package/src/vue/cached-activity.ts +13 -0
  225. package/src/vue/combobox.ts +238 -0
  226. package/src/vue/component-props.ts +24 -0
  227. package/src/vue/contracts.ts +33 -0
  228. package/src/vue/date-calendar.ts +76 -0
  229. package/src/vue/date-picker.ts +387 -0
  230. package/src/vue/date-props.ts +81 -0
  231. package/src/vue/dialog.ts +63 -0
  232. package/src/vue/files.ts +53 -0
  233. package/src/vue/forms.ts +20 -0
  234. package/src/vue/global-components.ts +120 -3
  235. package/src/vue/index.ts +46 -2
  236. package/src/vue/inline-content.ts +71 -0
  237. package/src/vue/props.ts +258 -95
  238. package/src/vue/theme-provider.ts +74 -0
  239. package/src/vue/theme.ts +17 -6
  240. package/src/vue/toast.ts +99 -0
  241. package/src/vue/workflow-props.ts +41 -0
  242. package/src/vue/workflows.ts +257 -0
@@ -0,0 +1,387 @@
1
+ import {
2
+ computed,
3
+ defineComponent,
4
+ h,
5
+ mergeProps,
6
+ nextTick,
7
+ onBeforeUnmount,
8
+ ref,
9
+ watch,
10
+ type Component,
11
+ type ExtractPropTypes,
12
+ } from '@vue/runtime-core'
13
+ import {
14
+ civilDate,
15
+ dateLocales,
16
+ dateValidationMessage,
17
+ isCivilDate,
18
+ validateDateConstraints,
19
+ validateDateDraft,
20
+ validateDateRangeDraft,
21
+ type CivilDate,
22
+ type DateRange,
23
+ type DateRangeDraft,
24
+ type DateValidation,
25
+ } from '../date.js'
26
+ import type { InputHandle } from '../input.js'
27
+ import {
28
+ datePickerProps,
29
+ datePickerEmits,
30
+ dateRangePickerProps,
31
+ dateRangePickerEmits,
32
+ } from './date-props.js'
33
+ import { useButtonAction } from './button-content.js'
34
+
35
+ type EntryProps = Omit<ExtractPropTypes<typeof dateRangePickerProps>, 'modelValue'> & {
36
+ modelValue: CivilDate | null | DateRange
37
+ name?: string
38
+ }
39
+ interface DatePrimitives {
40
+ Input: Component
41
+ Button: Component
42
+ Column: Component
43
+ Row: Component
44
+ Sheet: Component
45
+ Calendar: Component
46
+ /** Internal adapter boundary: capture a focusable opener and dismiss the native keyboard. */
47
+ beforeOpen(opener: unknown): void
48
+ afterClose(opener: unknown): void
49
+ }
50
+ interface EntryEvents {
51
+ model(value: CivilDate | null | DateRange): void
52
+ draft(value: string | DateRangeDraft): void
53
+ validity(value: DateValidation): void
54
+ focus(): void
55
+ blur(): void
56
+ }
57
+
58
+ /** @internal One Vue editing contract, composed with each renderer's existing primitives. */
59
+ export function createDatePickers(primitives: DatePrimitives) {
60
+ const { Input, Button, Column, Row, Sheet, Calendar } = primitives
61
+ function useEntry(props: EntryProps, range: boolean, events: EntryEvents) {
62
+ useButtonAction()
63
+ const start = ref('')
64
+ const end = ref('')
65
+ const touched = ref(false)
66
+ const open = ref(false)
67
+ const endpoint = ref<'start' | 'end'>('start')
68
+ const activeDate = ref<CivilDate>('2000-01-01')
69
+ const first = ref<InputHandle>()
70
+ const second = ref<InputHandle>()
71
+ const firstOpener = ref<unknown>()
72
+ const secondOpener = ref<unknown>()
73
+ let alive = true
74
+ let revision = 0
75
+ let returnFocus = true
76
+ const words = computed(() => {
77
+ if (!Object.hasOwn(dateLocales, props.locale))
78
+ throw new RangeError('Date locale must be en-US or pt-BR')
79
+ return dateLocales[props.locale]
80
+ })
81
+ function snapshot(): DateRangeDraft {
82
+ if (range) {
83
+ const value = props.modelValue as DateRange
84
+ if (!value || typeof value !== 'object')
85
+ throw new RangeError('A date range needs start and end endpoints')
86
+ for (const date of [value.start, value.end]) if (date !== null) civilDate(date)
87
+ return { start: value.start ?? '', end: value.end ?? '' }
88
+ }
89
+ if (props.modelValue !== null) civilDate(props.modelValue as string)
90
+ return { start: (props.modelValue as CivilDate | null) ?? '', end: '' }
91
+ }
92
+ function restore() {
93
+ const value = snapshot()
94
+ start.value = value.start
95
+ end.value = value.end
96
+ }
97
+ restore()
98
+ watch(
99
+ () => props.modelValue,
100
+ () => {
101
+ revision++
102
+ restore()
103
+ },
104
+ { deep: true },
105
+ )
106
+ const validity = computed(() => {
107
+ validateDateConstraints(props)
108
+ return range
109
+ ? validateDateRangeDraft({ start: start.value, end: end.value }, props)
110
+ : validateDateDraft(start.value, props)
111
+ })
112
+ watch(validity, (value, previous) => {
113
+ if (JSON.stringify(value) !== JSON.stringify(previous)) events.validity(value)
114
+ })
115
+ watch(
116
+ () => props.disabled || props.readonly,
117
+ (blocked) => {
118
+ if (blocked) close(false)
119
+ },
120
+ )
121
+ onBeforeUnmount(() => {
122
+ alive = false
123
+ revision++
124
+ })
125
+ function close(restoreFocus = true) {
126
+ if (!open.value) return
127
+ open.value = false
128
+ returnFocus = restoreFocus
129
+ }
130
+ function edit(which: 'start' | 'end', value: string) {
131
+ if (props.disabled || props.readonly) return
132
+ if (which === 'start') start.value = value
133
+ else end.value = value
134
+ propose()
135
+ }
136
+ function propose() {
137
+ const current = ++revision
138
+ const draft = { start: start.value, end: end.value }
139
+ events.draft(range ? { ...draft } : draft.start)
140
+ if (!validity.value.valid) return
141
+ const previous = snapshot()
142
+ if (previous.start === draft.start && previous.end === draft.end) return
143
+ events.model(
144
+ range
145
+ ? {
146
+ start: draft.start ? civilDate(draft.start) : null,
147
+ end: draft.end ? civilDate(draft.end) : null,
148
+ }
149
+ : draft.start
150
+ ? civilDate(draft.start)
151
+ : null,
152
+ )
153
+ // A model proposal is controlled. Invalid/incomplete drafts remain local; a rejected
154
+ // valid proposal returns to the parent's value without manufacturing another edit.
155
+ void nextTick(() => {
156
+ if (alive && revision === current) restore()
157
+ })
158
+ }
159
+ function show(which: 'start' | 'end') {
160
+ if (props.disabled || props.readonly || open.value) return
161
+ endpoint.value = which
162
+ const draft = which === 'end' ? end.value : start.value
163
+ let target = isCivilDate(draft) ? draft : (props.min ?? civilDate(`${props.initialMonth}-01`))
164
+ if (props.min && target < props.min) target = props.min
165
+ if (props.max && target > props.max) target = props.max
166
+ activeDate.value = target
167
+ primitives.beforeOpen(which === 'end' ? secondOpener.value : firstOpener.value)
168
+ open.value = true
169
+ }
170
+ const handle: InputHandle = {
171
+ focus: () => {
172
+ if (!props.disabled) first.value?.focus()
173
+ },
174
+ blur: () => {
175
+ first.value?.blur()
176
+ second.value?.blur()
177
+ },
178
+ }
179
+ function render(attrs: Record<string, unknown>) {
180
+ if (!props.label.trim()) throw new RangeError('A date picker needs a visible label')
181
+ for (const name of [
182
+ 'calendarLabel',
183
+ 'clearLabel',
184
+ 'closeLabel',
185
+ 'startLabel',
186
+ 'endLabel',
187
+ ] as const) {
188
+ if (props[name] !== undefined && !props[name]!.trim())
189
+ throw new RangeError(`${name} must not be blank`)
190
+ }
191
+ civilDate(`${props.initialMonth}-01`)
192
+ if (
193
+ props.firstDayOfWeek !== undefined &&
194
+ (!Number.isInteger(props.firstDayOfWeek) ||
195
+ props.firstDayOfWeek < 0 ||
196
+ props.firstDayOfWeek > 6)
197
+ )
198
+ throw new RangeError('firstDayOfWeek must be an integer from 0 to 6')
199
+ const translations = words.value
200
+ const label = (which: 'start' | 'end') =>
201
+ range
202
+ ? `${props.label} · ${which === 'start' ? (props.startLabel ?? translations.start) : (props.endLabel ?? translations.end)}`
203
+ : props.label
204
+ const startValidation = validateDateDraft(start.value, props)
205
+ const endValidation = validateDateDraft(end.value, props)
206
+ const startError =
207
+ touched.value || start.value.length >= 10
208
+ ? dateValidationMessage(startValidation, props.locale)
209
+ : ''
210
+ const endError =
211
+ touched.value || end.value.length >= 10
212
+ ? dateValidationMessage(endValidation, props.locale)
213
+ : ''
214
+ const rangeError =
215
+ startValidation.valid && endValidation.valid
216
+ ? dateValidationMessage(validity.value, props.locale)
217
+ : ''
218
+ const field = (which: 'start' | 'end') =>
219
+ h(
220
+ Row,
221
+ { gap: 'sm', align: 'end' },
222
+ {
223
+ default: () => [
224
+ h(Input, {
225
+ ref: which === 'start' ? first : second,
226
+ id: props.id ? `${props.id}${range ? `-${which}` : ''}` : undefined,
227
+ grow: 1,
228
+ shrink: 1,
229
+ label: label(which),
230
+ modelValue: which === 'start' ? start.value : end.value,
231
+ name: range ? (which === 'start' ? props.startName : props.endName) : props.name,
232
+ type: 'text',
233
+ placeholder: translations.format,
234
+ autocapitalize: 'none',
235
+ autocorrect: false,
236
+ disabled: props.disabled,
237
+ readonly: props.readonly,
238
+ helperText: !range || which === 'end' ? props.helperText : '',
239
+ error: !range
240
+ ? props.error || startError
241
+ : which === 'start'
242
+ ? startError
243
+ : props.error || endError || rangeError,
244
+ 'onUpdate:modelValue': (value: string) => edit(which, value),
245
+ onFocus: events.focus,
246
+ onBlur: () => {
247
+ touched.value = true
248
+ events.blur()
249
+ },
250
+ }),
251
+ h(Button, {
252
+ ref: which === 'start' ? firstOpener : secondOpener,
253
+ icon: 'calendar-days',
254
+ variant: 'secondary',
255
+ accessibilityLabel: `${props.calendarLabel ?? translations.calendar}: ${label(which)}`,
256
+ disabled: props.disabled || props.readonly,
257
+ onClick: () => show(which),
258
+ }),
259
+ ],
260
+ },
261
+ )
262
+ return h(
263
+ Column,
264
+ mergeProps(attrs, {
265
+ gap: 'sm',
266
+ width: props.width,
267
+ grow: props.grow,
268
+ shrink: props.shrink,
269
+ accessibilityHidden: props.accessibilityHidden,
270
+ onUnloaded: () => close(false),
271
+ }),
272
+ {
273
+ default: () => [
274
+ field('start'),
275
+ range ? field('end') : null,
276
+ props.clearable
277
+ ? h(Button, {
278
+ text: props.clearLabel ?? `${translations.clear}: ${props.label}`,
279
+ variant: 'ghost',
280
+ size: 'sm',
281
+ disabled: props.disabled || props.readonly || (!start.value && !end.value),
282
+ onClick: () => {
283
+ if (props.disabled || props.readonly) return
284
+ start.value = ''
285
+ end.value = ''
286
+ touched.value = false
287
+ propose()
288
+ },
289
+ })
290
+ : null,
291
+ h(
292
+ Sheet,
293
+ {
294
+ open: open.value,
295
+ title: label(endpoint.value),
296
+ closeLabel: props.closeLabel ?? translations.close,
297
+ 'onUpdate:open': (value: boolean) => {
298
+ if (!value) close()
299
+ },
300
+ },
301
+ {
302
+ default: () =>
303
+ h(Calendar, {
304
+ activeDate: activeDate.value,
305
+ onVnodeUnmounted: () => {
306
+ if (alive && returnFocus && !props.disabled && !open.value)
307
+ primitives.afterClose(
308
+ endpoint.value === 'end' ? secondOpener.value : firstOpener.value,
309
+ )
310
+ },
311
+ selected: isCivilDate(endpoint.value === 'end' ? end.value : start.value)
312
+ ? endpoint.value === 'end'
313
+ ? end.value
314
+ : start.value
315
+ : null,
316
+ rangeStart: range && isCivilDate(start.value) ? start.value : null,
317
+ rangeEnd: range && isCivilDate(end.value) ? end.value : null,
318
+ min: props.min,
319
+ max: props.max,
320
+ unavailableDates: props.unavailableDates,
321
+ locale: props.locale,
322
+ firstDayOfWeek: props.firstDayOfWeek,
323
+ 'onUpdate:activeDate': (value: CivilDate) => {
324
+ activeDate.value = value
325
+ },
326
+ onSelect: (value: CivilDate) => {
327
+ if (
328
+ !open.value ||
329
+ props.disabled ||
330
+ props.readonly ||
331
+ !validateDateDraft(value, props).valid
332
+ )
333
+ return
334
+ touched.value = true
335
+ edit(endpoint.value, value)
336
+ close()
337
+ },
338
+ }),
339
+ },
340
+ ),
341
+ ],
342
+ },
343
+ )
344
+ }
345
+ return { handle, render }
346
+ }
347
+ const Picker = defineComponent({
348
+ name: 'MDatePicker',
349
+ inheritAttrs: false,
350
+ props: datePickerProps,
351
+ emits: datePickerEmits,
352
+ setup(props, { attrs, emit, expose }) {
353
+ const entry = useEntry(props as EntryProps, false, {
354
+ model: (value) => emit('update:modelValue', value as CivilDate | null),
355
+ draft: (value) => emit('update:draft', value as string),
356
+ validity: (value) => emit('validityChange', value),
357
+ focus: () => emit('focus'),
358
+ blur: () => emit('blur'),
359
+ })
360
+ expose(entry.handle)
361
+ return () => entry.render(attrs)
362
+ },
363
+ })
364
+ const RangePicker = defineComponent({
365
+ name: 'MDateRangePicker',
366
+ inheritAttrs: false,
367
+ props: dateRangePickerProps,
368
+ emits: dateRangePickerEmits,
369
+ setup(props, { attrs, emit, expose }) {
370
+ const entry = useEntry(props, true, {
371
+ model: (value) => emit('update:modelValue', value as DateRange),
372
+ draft: (value) => emit('update:draft', value as DateRangeDraft),
373
+ validity: (value) => emit('validityChange', value),
374
+ focus: () => emit('focus'),
375
+ blur: () => emit('blur'),
376
+ })
377
+ expose(entry.handle)
378
+ return () => entry.render(attrs)
379
+ },
380
+ })
381
+ return {
382
+ MDatePicker: Picker as typeof Picker & { new (): InstanceType<typeof Picker> & InputHandle },
383
+ MDateRangePicker: RangePicker as typeof RangePicker & {
384
+ new (): InstanceType<typeof RangePicker> & InputHandle
385
+ },
386
+ }
387
+ }
@@ -0,0 +1,81 @@
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 { dimensionProperty } from '../contracts.js'
5
+ import { vueProperty } from './contracts.js'
6
+ import { flexProps, viewProps } from './props.js'
7
+
8
+ const dateOptions = {
9
+ min: { type: String as PropType<CivilDate>, default: undefined },
10
+ max: { type: String as PropType<CivilDate>, default: undefined },
11
+ unavailableDates: { type: Array as PropType<readonly CivilDate[]>, default: () => [] },
12
+ locale: { type: String as PropType<DateLocale>, default: 'en-US' as const },
13
+ firstDayOfWeek: { type: Number, default: undefined },
14
+ }
15
+ const common = {
16
+ id: viewProps.id,
17
+ accessibilityHidden: viewProps.accessibilityHidden,
18
+ ...flexProps,
19
+ width: vueProperty(dimensionProperty),
20
+ ...dateOptions,
21
+ label: { type: String, required: true as const },
22
+ helperText: { type: String, default: '' },
23
+ error: { type: String, default: '' },
24
+ disabled: Boolean,
25
+ readonly: Boolean,
26
+ clearable: { type: Boolean, default: true },
27
+ clearLabel: { type: String, default: undefined },
28
+ calendarLabel: { type: String, default: undefined },
29
+ closeLabel: { type: String, default: undefined },
30
+ /** Deterministic empty calendar snapshot; never reads the clock. */
31
+ initialMonth: { type: String, default: '2000-01' },
32
+ }
33
+ export const datePickerProps = {
34
+ ...common,
35
+ modelValue: { type: String as PropType<CivilDate | null>, default: null },
36
+ name: { type: String, default: undefined },
37
+ }
38
+ export const dateRangePickerProps = {
39
+ ...common,
40
+ modelValue: {
41
+ type: Object as PropType<DateRange>,
42
+ default: (): DateRange => ({ start: null, end: null }),
43
+ },
44
+ startLabel: { type: String, default: undefined },
45
+ endLabel: { type: String, default: undefined },
46
+ startName: { type: String, default: undefined },
47
+ endName: { type: String, default: undefined },
48
+ }
49
+ const editingEmits = {
50
+ validityChange: (value: DateValidation) => typeof value.valid === 'boolean',
51
+ focus: () => true,
52
+ blur: () => true,
53
+ }
54
+ export const datePickerEmits = {
55
+ ...editingEmits,
56
+ 'update:modelValue': (value: CivilDate | null) => value === null || isCivilDate(value),
57
+ 'update:draft': (value: string) => typeof value === 'string',
58
+ }
59
+ export const dateRangePickerEmits = {
60
+ ...editingEmits,
61
+ 'update:modelValue': (value: DateRange) =>
62
+ (value.start === null || isCivilDate(value.start)) &&
63
+ (value.end === null || isCivilDate(value.end)),
64
+ 'update:draft': (value: DateRangeDraft) =>
65
+ typeof value.start === 'string' && typeof value.end === 'string',
66
+ }
67
+ export type DatePickerProps = ExtractPublicPropTypes<typeof datePickerProps>
68
+ export type DateRangePickerProps = ExtractPublicPropTypes<typeof dateRangePickerProps>
69
+
70
+ /** @internal Shared themed calendar presentation contract. */
71
+ export const dateCalendarProps = {
72
+ ...dateOptions,
73
+ activeDate: { type: String as PropType<CivilDate>, required: true as const },
74
+ selected: { type: String as PropType<CivilDate | null>, default: null },
75
+ rangeStart: { type: String as PropType<CivilDate | null>, default: null },
76
+ rangeEnd: { type: String as PropType<CivilDate | null>, default: null },
77
+ }
78
+ export const dateCalendarEmits = {
79
+ select: (value: CivilDate) => isCivilDate(value),
80
+ 'update:activeDate': (value: CivilDate) => isCivilDate(value),
81
+ }
@@ -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
+ }
@@ -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
+ }
@@ -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
+ }