@getcortexlabs/mavis-core 0.1.0-alpha.4 → 0.1.0-alpha.6
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/app-icons.d.ts +27 -0
- package/dist/app-icons.d.ts.map +1 -0
- package/dist/app-icons.js +42 -0
- package/dist/app-icons.js.map +1 -0
- package/dist/capabilities.d.ts +119 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +144 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/combobox.d.ts +42 -0
- package/dist/combobox.d.ts.map +1 -0
- package/dist/combobox.js +159 -0
- package/dist/combobox.js.map +1 -0
- package/dist/contracts.d.ts +1261 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +249 -0
- package/dist/contracts.js.map +1 -0
- package/dist/date.d.ts +96 -0
- package/dist/date.d.ts.map +1 -0
- package/dist/date.js +235 -0
- package/dist/date.js.map +1 -0
- package/dist/experimental-playback.d.ts +63 -0
- package/dist/experimental-playback.d.ts.map +1 -0
- package/dist/experimental-playback.js +46 -0
- package/dist/experimental-playback.js.map +1 -0
- package/dist/experimental-regions.d.ts +154 -0
- package/dist/experimental-regions.d.ts.map +1 -0
- package/dist/experimental-regions.js +440 -0
- package/dist/experimental-regions.js.map +1 -0
- package/dist/experimental.d.ts +42 -3
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +200 -30
- package/dist/experimental.js.map +1 -1
- package/dist/files.d.ts +87 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +328 -0
- package/dist/files.js.map +1 -0
- package/dist/form.d.ts +39 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/form.js +170 -0
- package/dist/form.js.map +1 -0
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/link.d.ts +12 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +19 -0
- package/dist/link.js.map +1 -0
- package/dist/motion.d.ts +29 -4
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +55 -3
- package/dist/motion.js.map +1 -1
- package/dist/navigation.d.ts +22 -0
- package/dist/navigation.d.ts.map +1 -0
- package/dist/navigation.js +54 -0
- package/dist/navigation.js.map +1 -0
- package/dist/responsive.d.ts +18 -0
- package/dist/responsive.d.ts.map +1 -0
- package/dist/responsive.js +35 -0
- package/dist/responsive.js.map +1 -0
- package/dist/theme/themes.js +3 -3
- package/dist/theme/themes.js.map +1 -1
- package/dist/theme/types.d.ts +12 -3
- package/dist/theme/types.d.ts.map +1 -1
- package/dist/vue/combobox.d.ts +155 -0
- package/dist/vue/combobox.d.ts.map +1 -0
- package/dist/vue/combobox.js +195 -0
- package/dist/vue/combobox.js.map +1 -0
- package/dist/vue/component-props.d.ts +2176 -0
- package/dist/vue/component-props.d.ts.map +1 -0
- package/dist/vue/component-props.js +18 -0
- package/dist/vue/component-props.js.map +1 -0
- package/dist/vue/contracts.d.ts +18 -0
- package/dist/vue/contracts.d.ts.map +1 -0
- package/dist/vue/contracts.js +24 -0
- package/dist/vue/contracts.js.map +1 -0
- package/dist/vue/date-calendar.d.ts +64 -0
- package/dist/vue/date-calendar.d.ts.map +1 -0
- package/dist/vue/date-calendar.js +65 -0
- package/dist/vue/date-calendar.js.map +1 -0
- package/dist/vue/date-picker.d.ts +965 -0
- package/dist/vue/date-picker.d.ts.map +1 -0
- package/dist/vue/date-picker.js +341 -0
- package/dist/vue/date-picker.js.map +1 -0
- package/dist/vue/date-props.d.ts +263 -0
- package/dist/vue/date-props.d.ts.map +1 -0
- package/dist/vue/date-props.js +77 -0
- package/dist/vue/date-props.js.map +1 -0
- package/dist/vue/files.d.ts +53 -0
- package/dist/vue/files.d.ts.map +1 -0
- package/dist/vue/files.js +40 -0
- package/dist/vue/files.js.map +1 -0
- package/dist/vue/forms.d.ts +4 -0
- package/dist/vue/forms.d.ts.map +1 -0
- package/dist/vue/forms.js +15 -0
- package/dist/vue/forms.js.map +1 -0
- package/dist/vue/global-components.d.ts +40 -2
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/index.d.ts +15 -3
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +12 -2
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/inline-content.d.ts +3 -1
- package/dist/vue/inline-content.d.ts.map +1 -1
- package/dist/vue/layout-context.d.ts +4 -2
- package/dist/vue/layout-context.d.ts.map +1 -1
- package/dist/vue/layout-context.js +7 -2
- package/dist/vue/layout-context.js.map +1 -1
- package/dist/vue/props.d.ts +1392 -496
- package/dist/vue/props.d.ts.map +1 -1
- package/dist/vue/props.js +39 -116
- package/dist/vue/props.js.map +1 -1
- package/dist/vue/reveal-state.d.ts +18 -0
- package/dist/vue/reveal-state.d.ts.map +1 -0
- package/dist/vue/reveal-state.js +76 -0
- package/dist/vue/reveal-state.js.map +1 -0
- package/dist/vue/theme.d.ts +42 -0
- package/dist/vue/theme.d.ts.map +1 -1
- package/dist/vue/workflow-props.d.ts +110 -0
- package/dist/vue/workflow-props.d.ts.map +1 -0
- package/dist/vue/workflow-props.js +37 -0
- package/dist/vue/workflow-props.js.map +1 -0
- package/dist/vue/workflows.d.ts +267 -0
- package/dist/vue/workflows.d.ts.map +1 -0
- package/dist/vue/workflows.js +200 -0
- package/dist/vue/workflows.js.map +1 -0
- package/package.json +1 -1
- package/src/app-icons.ts +57 -0
- package/src/capabilities.ts +147 -0
- package/src/combobox.ts +198 -0
- package/src/contracts.ts +305 -0
- package/src/date.ts +280 -0
- package/src/experimental-playback.ts +115 -0
- package/src/experimental-regions.ts +614 -0
- package/src/experimental.ts +239 -25
- package/src/files.ts +408 -0
- package/src/form.ts +190 -0
- package/src/index.ts +23 -1
- package/src/link.ts +28 -0
- package/src/motion.ts +61 -3
- package/src/navigation.ts +61 -0
- package/src/responsive.ts +61 -0
- package/src/theme/themes.ts +3 -3
- package/src/theme/types.ts +13 -1
- package/src/vue/combobox.ts +238 -0
- package/src/vue/component-props.ts +24 -0
- package/src/vue/contracts.ts +39 -0
- package/src/vue/date-calendar.ts +76 -0
- package/src/vue/date-picker.ts +414 -0
- package/src/vue/date-props.ts +84 -0
- package/src/vue/files.ts +53 -0
- package/src/vue/forms.ts +20 -0
- package/src/vue/global-components.ts +49 -3
- package/src/vue/index.ts +19 -3
- package/src/vue/layout-context.ts +10 -3
- package/src/vue/props.ts +57 -127
- package/src/vue/reveal-state.ts +83 -0
- package/src/vue/workflow-props.ts +41 -0
- package/src/vue/workflows.ts +257 -0
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
defineComponent,
|
|
4
|
+
h,
|
|
5
|
+
mergeProps,
|
|
6
|
+
nextTick,
|
|
7
|
+
onBeforeUnmount,
|
|
8
|
+
onMounted,
|
|
9
|
+
ref,
|
|
10
|
+
watch,
|
|
11
|
+
type Component,
|
|
12
|
+
type ExtractPropTypes,
|
|
13
|
+
} from '@vue/runtime-core'
|
|
14
|
+
import {
|
|
15
|
+
civilDate,
|
|
16
|
+
dateLocales,
|
|
17
|
+
dateValidationMessage,
|
|
18
|
+
isCivilDate,
|
|
19
|
+
validateDateConstraints,
|
|
20
|
+
validateDateDraft,
|
|
21
|
+
validateDateRangeDraft,
|
|
22
|
+
type CivilDate,
|
|
23
|
+
type DateRange,
|
|
24
|
+
type DateRangeDraft,
|
|
25
|
+
type DateValidation,
|
|
26
|
+
} from '../date.js'
|
|
27
|
+
import type { InputHandle } from '../input.js'
|
|
28
|
+
import {
|
|
29
|
+
datePickerProps,
|
|
30
|
+
datePickerEmits,
|
|
31
|
+
dateRangePickerProps,
|
|
32
|
+
dateRangePickerEmits,
|
|
33
|
+
} from './date-props.js'
|
|
34
|
+
import { useButtonAction } from './button-content.js'
|
|
35
|
+
|
|
36
|
+
type EntryProps = Omit<ExtractPropTypes<typeof dateRangePickerProps>, 'modelValue' | 'draft'> & {
|
|
37
|
+
modelValue: CivilDate | null | DateRange
|
|
38
|
+
draft?: string | DateRangeDraft
|
|
39
|
+
name?: string
|
|
40
|
+
}
|
|
41
|
+
interface DatePrimitives {
|
|
42
|
+
Input: Component
|
|
43
|
+
Button: Component
|
|
44
|
+
Column: Component
|
|
45
|
+
Row: Component
|
|
46
|
+
Sheet: Component
|
|
47
|
+
Calendar: Component
|
|
48
|
+
/** Internal adapter boundary: capture a focusable opener and dismiss the native keyboard. */
|
|
49
|
+
beforeOpen(opener: unknown): void
|
|
50
|
+
afterClose(opener: unknown): void
|
|
51
|
+
deferActions?: boolean
|
|
52
|
+
openerAttrs?: Record<string, unknown>
|
|
53
|
+
}
|
|
54
|
+
interface EntryEvents {
|
|
55
|
+
model(value: CivilDate | null | DateRange): void
|
|
56
|
+
draft(value: string | DateRangeDraft): void
|
|
57
|
+
validity(value: DateValidation): void
|
|
58
|
+
focus(): void
|
|
59
|
+
blur(): void
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** @internal One Vue editing contract, composed with each renderer's existing primitives. */
|
|
63
|
+
export function createDatePickers(primitives: DatePrimitives) {
|
|
64
|
+
const { Input, Button, Column, Row, Sheet, Calendar } = primitives
|
|
65
|
+
function useEntry(props: EntryProps, range: boolean, events: EntryEvents) {
|
|
66
|
+
useButtonAction()
|
|
67
|
+
const start = ref('')
|
|
68
|
+
const end = ref('')
|
|
69
|
+
const touched = ref(false)
|
|
70
|
+
const open = ref(false)
|
|
71
|
+
const ready = ref(!primitives.deferActions)
|
|
72
|
+
onMounted(() => {
|
|
73
|
+
ready.value = true
|
|
74
|
+
})
|
|
75
|
+
const endpoint = ref<'start' | 'end'>('start')
|
|
76
|
+
const activeDate = ref<CivilDate>('2000-01-01')
|
|
77
|
+
const first = ref<InputHandle>()
|
|
78
|
+
const second = ref<InputHandle>()
|
|
79
|
+
const firstOpener = ref<unknown>()
|
|
80
|
+
const secondOpener = ref<unknown>()
|
|
81
|
+
let alive = true
|
|
82
|
+
let revision = 0
|
|
83
|
+
let returnFocus = true
|
|
84
|
+
const words = computed(() => {
|
|
85
|
+
if (!Object.hasOwn(dateLocales, props.locale))
|
|
86
|
+
throw new RangeError('Date locale must be en-US or pt-BR')
|
|
87
|
+
return dateLocales[props.locale]
|
|
88
|
+
})
|
|
89
|
+
function snapshot(): DateRangeDraft {
|
|
90
|
+
if (range) {
|
|
91
|
+
const value = props.modelValue as DateRange
|
|
92
|
+
if (!value || typeof value !== 'object')
|
|
93
|
+
throw new RangeError('A date range needs start and end endpoints')
|
|
94
|
+
for (const date of [value.start, value.end]) if (date !== null) civilDate(date)
|
|
95
|
+
return { start: value.start ?? '', end: value.end ?? '' }
|
|
96
|
+
}
|
|
97
|
+
if (props.modelValue !== null) civilDate(props.modelValue as string)
|
|
98
|
+
return { start: (props.modelValue as CivilDate | null) ?? '', end: '' }
|
|
99
|
+
}
|
|
100
|
+
function restore() {
|
|
101
|
+
// A controlled draft owns the editor. The canonical model remains independently valid.
|
|
102
|
+
const canonical = snapshot()
|
|
103
|
+
const value =
|
|
104
|
+
props.draft === undefined
|
|
105
|
+
? canonical
|
|
106
|
+
: range
|
|
107
|
+
? (props.draft as DateRangeDraft)
|
|
108
|
+
: { start: props.draft as string, end: '' }
|
|
109
|
+
if (!value || typeof value.start !== 'string' || typeof value.end !== 'string')
|
|
110
|
+
throw new TypeError('A date draft must contain text for each endpoint')
|
|
111
|
+
start.value = value.start
|
|
112
|
+
end.value = value.end
|
|
113
|
+
}
|
|
114
|
+
restore()
|
|
115
|
+
watch(
|
|
116
|
+
() => [props.modelValue, props.draft],
|
|
117
|
+
() => {
|
|
118
|
+
revision++
|
|
119
|
+
restore()
|
|
120
|
+
},
|
|
121
|
+
{ deep: true },
|
|
122
|
+
)
|
|
123
|
+
const validity = computed(() => {
|
|
124
|
+
validateDateConstraints(props)
|
|
125
|
+
return range
|
|
126
|
+
? validateDateRangeDraft({ start: start.value, end: end.value }, props)
|
|
127
|
+
: validateDateDraft(start.value, props)
|
|
128
|
+
})
|
|
129
|
+
watch(validity, (value, previous) => {
|
|
130
|
+
if (JSON.stringify(value) !== JSON.stringify(previous)) events.validity(value)
|
|
131
|
+
})
|
|
132
|
+
watch(
|
|
133
|
+
() => props.disabled || props.readonly,
|
|
134
|
+
(blocked) => {
|
|
135
|
+
if (blocked) close(false)
|
|
136
|
+
},
|
|
137
|
+
)
|
|
138
|
+
onBeforeUnmount(() => {
|
|
139
|
+
alive = false
|
|
140
|
+
revision++
|
|
141
|
+
})
|
|
142
|
+
function close(restoreFocus = true) {
|
|
143
|
+
if (!open.value) return
|
|
144
|
+
open.value = false
|
|
145
|
+
returnFocus = restoreFocus
|
|
146
|
+
}
|
|
147
|
+
function edit(which: 'start' | 'end', value: string) {
|
|
148
|
+
if (props.disabled || props.readonly) return
|
|
149
|
+
if (which === 'start') start.value = value
|
|
150
|
+
else end.value = value
|
|
151
|
+
propose()
|
|
152
|
+
}
|
|
153
|
+
function propose() {
|
|
154
|
+
const current = ++revision
|
|
155
|
+
const draft = { start: start.value, end: end.value }
|
|
156
|
+
events.draft(range ? { ...draft } : draft.start)
|
|
157
|
+
if (props.draft !== undefined) {
|
|
158
|
+
void nextTick(() => {
|
|
159
|
+
if (alive && revision === current) restore()
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
if (!validity.value.valid) return
|
|
163
|
+
const previous = snapshot()
|
|
164
|
+
if (previous.start === draft.start && previous.end === draft.end) return
|
|
165
|
+
events.model(
|
|
166
|
+
range
|
|
167
|
+
? {
|
|
168
|
+
start: draft.start ? civilDate(draft.start) : null,
|
|
169
|
+
end: draft.end ? civilDate(draft.end) : null,
|
|
170
|
+
}
|
|
171
|
+
: draft.start
|
|
172
|
+
? civilDate(draft.start)
|
|
173
|
+
: null,
|
|
174
|
+
)
|
|
175
|
+
// A model proposal is controlled. Invalid/incomplete drafts remain local; a rejected
|
|
176
|
+
// valid proposal returns to the parent's value without manufacturing another edit.
|
|
177
|
+
void nextTick(() => {
|
|
178
|
+
if (alive && revision === current) restore()
|
|
179
|
+
})
|
|
180
|
+
}
|
|
181
|
+
function show(which: 'start' | 'end') {
|
|
182
|
+
if (!ready.value || props.disabled || props.readonly || open.value) return
|
|
183
|
+
endpoint.value = which
|
|
184
|
+
const draft = which === 'end' ? end.value : start.value
|
|
185
|
+
let target = isCivilDate(draft) ? draft : (props.min ?? civilDate(`${props.initialMonth}-01`))
|
|
186
|
+
if (props.min && target < props.min) target = props.min
|
|
187
|
+
if (props.max && target > props.max) target = props.max
|
|
188
|
+
activeDate.value = target
|
|
189
|
+
primitives.beforeOpen(which === 'end' ? secondOpener.value : firstOpener.value)
|
|
190
|
+
open.value = true
|
|
191
|
+
}
|
|
192
|
+
const handle: InputHandle = {
|
|
193
|
+
focus: () => {
|
|
194
|
+
if (!props.disabled) first.value?.focus()
|
|
195
|
+
},
|
|
196
|
+
blur: () => {
|
|
197
|
+
first.value?.blur()
|
|
198
|
+
second.value?.blur()
|
|
199
|
+
},
|
|
200
|
+
}
|
|
201
|
+
function render(attrs: Record<string, unknown>) {
|
|
202
|
+
if (!props.label.trim()) throw new RangeError('A date picker needs a visible label')
|
|
203
|
+
for (const name of [
|
|
204
|
+
'calendarLabel',
|
|
205
|
+
'clearLabel',
|
|
206
|
+
'closeLabel',
|
|
207
|
+
'startLabel',
|
|
208
|
+
'endLabel',
|
|
209
|
+
] as const) {
|
|
210
|
+
if (props[name] !== undefined && !props[name]!.trim())
|
|
211
|
+
throw new RangeError(`${name} must not be blank`)
|
|
212
|
+
}
|
|
213
|
+
civilDate(`${props.initialMonth}-01`)
|
|
214
|
+
if (
|
|
215
|
+
props.firstDayOfWeek !== undefined &&
|
|
216
|
+
(!Number.isInteger(props.firstDayOfWeek) ||
|
|
217
|
+
props.firstDayOfWeek < 0 ||
|
|
218
|
+
props.firstDayOfWeek > 6)
|
|
219
|
+
)
|
|
220
|
+
throw new RangeError('firstDayOfWeek must be an integer from 0 to 6')
|
|
221
|
+
const translations = words.value
|
|
222
|
+
const label = (which: 'start' | 'end') =>
|
|
223
|
+
range
|
|
224
|
+
? `${props.label} · ${which === 'start' ? (props.startLabel ?? translations.start) : (props.endLabel ?? translations.end)}`
|
|
225
|
+
: 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
|
+
: ''
|
|
240
|
+
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
|
+
],
|
|
283
|
+
},
|
|
284
|
+
)
|
|
285
|
+
return h(
|
|
286
|
+
Column,
|
|
287
|
+
mergeProps(attrs, {
|
|
288
|
+
gap: 'sm',
|
|
289
|
+
width: props.width,
|
|
290
|
+
grow: props.grow,
|
|
291
|
+
shrink: props.shrink,
|
|
292
|
+
accessibilityHidden: props.accessibilityHidden,
|
|
293
|
+
onUnloaded: () => close(false),
|
|
294
|
+
}),
|
|
295
|
+
{
|
|
296
|
+
default: () => [
|
|
297
|
+
field('start'),
|
|
298
|
+
range ? field('end') : null,
|
|
299
|
+
props.clearable
|
|
300
|
+
? h(Button, {
|
|
301
|
+
text: props.clearLabel ?? `${translations.clear}: ${props.label}`,
|
|
302
|
+
variant: 'ghost',
|
|
303
|
+
size: 'sm',
|
|
304
|
+
disabled:
|
|
305
|
+
!ready.value ||
|
|
306
|
+
props.disabled ||
|
|
307
|
+
props.readonly ||
|
|
308
|
+
(!start.value && !end.value),
|
|
309
|
+
onClick: () => {
|
|
310
|
+
if (props.disabled || props.readonly) return
|
|
311
|
+
start.value = ''
|
|
312
|
+
end.value = ''
|
|
313
|
+
touched.value = false
|
|
314
|
+
propose()
|
|
315
|
+
},
|
|
316
|
+
})
|
|
317
|
+
: null,
|
|
318
|
+
h(
|
|
319
|
+
Sheet,
|
|
320
|
+
{
|
|
321
|
+
open: open.value,
|
|
322
|
+
title: label(endpoint.value),
|
|
323
|
+
closeLabel: props.closeLabel ?? translations.close,
|
|
324
|
+
'onUpdate:open': (value: boolean) => {
|
|
325
|
+
if (!value) close()
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
default: () =>
|
|
330
|
+
h(Calendar, {
|
|
331
|
+
activeDate: activeDate.value,
|
|
332
|
+
onVnodeUnmounted: () => {
|
|
333
|
+
if (alive && returnFocus && !props.disabled && !open.value)
|
|
334
|
+
primitives.afterClose(
|
|
335
|
+
endpoint.value === 'end' ? secondOpener.value : firstOpener.value,
|
|
336
|
+
)
|
|
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,
|
|
345
|
+
min: props.min,
|
|
346
|
+
max: props.max,
|
|
347
|
+
unavailableDates: props.unavailableDates,
|
|
348
|
+
locale: props.locale,
|
|
349
|
+
firstDayOfWeek: props.firstDayOfWeek,
|
|
350
|
+
'onUpdate:activeDate': (value: CivilDate) => {
|
|
351
|
+
activeDate.value = value
|
|
352
|
+
},
|
|
353
|
+
onSelect: (value: CivilDate) => {
|
|
354
|
+
if (
|
|
355
|
+
!open.value ||
|
|
356
|
+
props.disabled ||
|
|
357
|
+
props.readonly ||
|
|
358
|
+
!validateDateDraft(value, props).valid
|
|
359
|
+
)
|
|
360
|
+
return
|
|
361
|
+
touched.value = true
|
|
362
|
+
edit(endpoint.value, value)
|
|
363
|
+
close()
|
|
364
|
+
},
|
|
365
|
+
}),
|
|
366
|
+
},
|
|
367
|
+
),
|
|
368
|
+
],
|
|
369
|
+
},
|
|
370
|
+
)
|
|
371
|
+
}
|
|
372
|
+
return { handle, render }
|
|
373
|
+
}
|
|
374
|
+
const Picker = defineComponent({
|
|
375
|
+
name: 'MDatePicker',
|
|
376
|
+
inheritAttrs: false,
|
|
377
|
+
props: datePickerProps,
|
|
378
|
+
emits: datePickerEmits,
|
|
379
|
+
setup(props, { attrs, emit, expose }) {
|
|
380
|
+
const entry = useEntry(props as EntryProps, false, {
|
|
381
|
+
model: (value) => emit('update:modelValue', value as CivilDate | null),
|
|
382
|
+
draft: (value) => emit('update:draft', value as string),
|
|
383
|
+
validity: (value) => emit('validityChange', value),
|
|
384
|
+
focus: () => emit('focus'),
|
|
385
|
+
blur: () => emit('blur'),
|
|
386
|
+
})
|
|
387
|
+
expose(entry.handle)
|
|
388
|
+
return () => entry.render(attrs)
|
|
389
|
+
},
|
|
390
|
+
})
|
|
391
|
+
const RangePicker = defineComponent({
|
|
392
|
+
name: 'MDateRangePicker',
|
|
393
|
+
inheritAttrs: false,
|
|
394
|
+
props: dateRangePickerProps,
|
|
395
|
+
emits: dateRangePickerEmits,
|
|
396
|
+
setup(props, { attrs, emit, expose }) {
|
|
397
|
+
const entry = useEntry(props, true, {
|
|
398
|
+
model: (value) => emit('update:modelValue', value as DateRange),
|
|
399
|
+
draft: (value) => emit('update:draft', value as DateRangeDraft),
|
|
400
|
+
validity: (value) => emit('validityChange', value),
|
|
401
|
+
focus: () => emit('focus'),
|
|
402
|
+
blur: () => emit('blur'),
|
|
403
|
+
})
|
|
404
|
+
expose(entry.handle)
|
|
405
|
+
return () => entry.render(attrs)
|
|
406
|
+
},
|
|
407
|
+
})
|
|
408
|
+
return {
|
|
409
|
+
MDatePicker: Picker as typeof Picker & { new (): InstanceType<typeof Picker> & InputHandle },
|
|
410
|
+
MDateRangePicker: RangePicker as typeof RangePicker & {
|
|
411
|
+
new (): InstanceType<typeof RangePicker> & InputHandle
|
|
412
|
+
},
|
|
413
|
+
}
|
|
414
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
/** Optional controlled editor text, including incomplete or invalid dates. */
|
|
36
|
+
draft: { type: String, default: undefined },
|
|
37
|
+
modelValue: { type: String as PropType<CivilDate | null>, default: null },
|
|
38
|
+
name: { type: String, default: undefined },
|
|
39
|
+
}
|
|
40
|
+
export const dateRangePickerProps = {
|
|
41
|
+
...common,
|
|
42
|
+
draft: { type: Object as PropType<DateRangeDraft>, default: undefined },
|
|
43
|
+
modelValue: {
|
|
44
|
+
type: Object as PropType<DateRange>,
|
|
45
|
+
default: (): DateRange => ({ start: null, end: null }),
|
|
46
|
+
},
|
|
47
|
+
startLabel: { type: String, default: undefined },
|
|
48
|
+
endLabel: { type: String, default: undefined },
|
|
49
|
+
startName: { type: String, default: undefined },
|
|
50
|
+
endName: { type: String, default: undefined },
|
|
51
|
+
}
|
|
52
|
+
const editingEmits = {
|
|
53
|
+
validityChange: (value: DateValidation) => typeof value.valid === 'boolean',
|
|
54
|
+
focus: () => true,
|
|
55
|
+
blur: () => true,
|
|
56
|
+
}
|
|
57
|
+
export const datePickerEmits = {
|
|
58
|
+
...editingEmits,
|
|
59
|
+
'update:modelValue': (value: CivilDate | null) => value === null || isCivilDate(value),
|
|
60
|
+
'update:draft': (value: string) => typeof value === 'string',
|
|
61
|
+
}
|
|
62
|
+
export const dateRangePickerEmits = {
|
|
63
|
+
...editingEmits,
|
|
64
|
+
'update:modelValue': (value: DateRange) =>
|
|
65
|
+
(value.start === null || isCivilDate(value.start)) &&
|
|
66
|
+
(value.end === null || isCivilDate(value.end)),
|
|
67
|
+
'update:draft': (value: DateRangeDraft) =>
|
|
68
|
+
typeof value.start === 'string' && typeof value.end === 'string',
|
|
69
|
+
}
|
|
70
|
+
export type DatePickerProps = ExtractPublicPropTypes<typeof datePickerProps>
|
|
71
|
+
export type DateRangePickerProps = ExtractPublicPropTypes<typeof dateRangePickerProps>
|
|
72
|
+
|
|
73
|
+
/** @internal Shared themed calendar presentation contract. */
|
|
74
|
+
export const dateCalendarProps = {
|
|
75
|
+
...dateOptions,
|
|
76
|
+
activeDate: { type: String as PropType<CivilDate>, required: true as const },
|
|
77
|
+
selected: { type: String as PropType<CivilDate | null>, default: null },
|
|
78
|
+
rangeStart: { type: String as PropType<CivilDate | null>, default: null },
|
|
79
|
+
rangeEnd: { type: String as PropType<CivilDate | null>, default: null },
|
|
80
|
+
}
|
|
81
|
+
export const dateCalendarEmits = {
|
|
82
|
+
select: (value: CivilDate) => isCivilDate(value),
|
|
83
|
+
'update:activeDate': (value: CivilDate) => isCivilDate(value),
|
|
84
|
+
}
|
package/src/vue/files.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { markRaw, onBeforeUnmount, onDeactivated, type PropType } from '@vue/runtime-core'
|
|
2
|
+
import {
|
|
3
|
+
createFileSelection,
|
|
4
|
+
type FileSelectionController,
|
|
5
|
+
type FileSelectionOptions,
|
|
6
|
+
type FileItem,
|
|
7
|
+
type FileSelectionErrorCode,
|
|
8
|
+
} from '../files.js'
|
|
9
|
+
|
|
10
|
+
/** Own this in the component that owns the selected files, not in a module singleton. */
|
|
11
|
+
export function useFileSelection(options: FileSelectionOptions = {}) {
|
|
12
|
+
const selection = markRaw(createFileSelection(options))
|
|
13
|
+
onDeactivated(() => selection.pause())
|
|
14
|
+
onBeforeUnmount(() => selection.dispose())
|
|
15
|
+
return selection
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const filePickerProps = {
|
|
19
|
+
selection: { type: Object as PropType<FileSelectionController>, required: true as const },
|
|
20
|
+
label: { type: String, required: true as const },
|
|
21
|
+
disabled: Boolean,
|
|
22
|
+
chooseLabel: { type: String, default: 'Choose files' },
|
|
23
|
+
uploadLabel: { type: String, default: 'Upload' },
|
|
24
|
+
cancelLabel: { type: String, default: 'Cancel' },
|
|
25
|
+
retryLabel: { type: String, default: 'Retry' },
|
|
26
|
+
removeLabel: { type: String, default: 'Remove' },
|
|
27
|
+
emptyLabel: { type: String, default: 'No files selected' },
|
|
28
|
+
pendingLabel: { type: String, default: 'Working' },
|
|
29
|
+
statusLabels: {
|
|
30
|
+
type: Object as PropType<Partial<Record<FileItem['status'], string>>>,
|
|
31
|
+
default: () => ({}),
|
|
32
|
+
},
|
|
33
|
+
errorLabels: {
|
|
34
|
+
type: Object as PropType<Partial<Record<FileSelectionErrorCode, string>>>,
|
|
35
|
+
default: () => ({}),
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function fileStatusText(
|
|
40
|
+
item: FileItem,
|
|
41
|
+
labels: Partial<Record<FileItem['status'], string>>,
|
|
42
|
+
) {
|
|
43
|
+
return (
|
|
44
|
+
labels[item.status] ??
|
|
45
|
+
{
|
|
46
|
+
selected: 'Ready',
|
|
47
|
+
uploading: 'Uploading',
|
|
48
|
+
uploaded: 'Uploaded',
|
|
49
|
+
failed: 'Failed',
|
|
50
|
+
cancelled: 'Cancelled',
|
|
51
|
+
}[item.status]
|
|
52
|
+
)
|
|
53
|
+
}
|
package/src/vue/forms.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { markRaw, onScopeDispose } from '@vue/runtime-core'
|
|
2
|
+
import { useCachedActivity } from './cached-activity.js'
|
|
3
|
+
import {
|
|
4
|
+
createFormController,
|
|
5
|
+
type FormController,
|
|
6
|
+
type FormError,
|
|
7
|
+
type FormField,
|
|
8
|
+
} from '../form.js'
|
|
9
|
+
|
|
10
|
+
export function useFormController(initial: readonly FormError[] = []) {
|
|
11
|
+
const form = markRaw(createFormController(initial))
|
|
12
|
+
onScopeDispose(() => form.dispose())
|
|
13
|
+
return form
|
|
14
|
+
}
|
|
15
|
+
export function useFormField(form: FormController, field: FormField) {
|
|
16
|
+
const active = useCachedActivity()
|
|
17
|
+
const release = form.register({ ...field, target: () => (active.value ? field.target() : null) })
|
|
18
|
+
onScopeDispose(release)
|
|
19
|
+
return release
|
|
20
|
+
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { AccordionPanelProps } from '../accordion.js'
|
|
2
2
|
import type { TabPanelProps } from '../tabs.js'
|
|
3
|
-
import type {
|
|
3
|
+
import type { CivilDate, DateRange, DateRangeDraft, DateValidation } from '../date.js'
|
|
4
|
+
import type { ChoiceValue, ChoiceOption } from '../choice.js'
|
|
4
5
|
import type { DefineComponent } from '@vue/runtime-core'
|
|
5
|
-
import type { ComponentProps } from './props.js'
|
|
6
|
+
import type { ComponentProps } from './component-props.js'
|
|
6
7
|
import type { DialogCloseReason } from '../dialog.js'
|
|
7
8
|
import type { SheetCloseReason } from '../sheet.js'
|
|
8
9
|
import type { InputHandle } from '../input.js'
|
|
9
10
|
|
|
10
|
-
type Action = { onClick?: () => void }
|
|
11
|
+
type Action = { onClick?: () => void; onError?: (error: unknown) => void }
|
|
11
12
|
type Model = { 'onUpdate:modelValue'?: (value: number) => void }
|
|
12
13
|
type InputEvents = {
|
|
13
14
|
onAction?: () => void
|
|
@@ -30,9 +31,54 @@ declare module '@vue/runtime-core' {
|
|
|
30
31
|
export interface GlobalComponents {
|
|
31
32
|
MThemeProvider: typeof import('./theme-provider.js').MThemeProvider
|
|
32
33
|
MSpan: typeof import('./inline-content.js').MSpan
|
|
34
|
+
MDatePicker: DefineComponent<
|
|
35
|
+
ComponentProps['MDatePicker'] & {
|
|
36
|
+
'onUpdate:modelValue'?: (value: CivilDate | null) => void
|
|
37
|
+
'onUpdate:draft'?: (value: string) => void
|
|
38
|
+
onValidityChange?: (value: DateValidation) => void
|
|
39
|
+
onFocus?: () => void
|
|
40
|
+
onBlur?: () => void
|
|
41
|
+
},
|
|
42
|
+
InputHandle
|
|
43
|
+
>
|
|
44
|
+
MDateRangePicker: DefineComponent<
|
|
45
|
+
ComponentProps['MDateRangePicker'] & {
|
|
46
|
+
'onUpdate:modelValue'?: (value: DateRange) => void
|
|
47
|
+
'onUpdate:draft'?: (value: DateRangeDraft) => void
|
|
48
|
+
onValidityChange?: (value: DateValidation) => void
|
|
49
|
+
onFocus?: () => void
|
|
50
|
+
onBlur?: () => void
|
|
51
|
+
},
|
|
52
|
+
InputHandle
|
|
53
|
+
>
|
|
54
|
+
MCombobox: DefineComponent<
|
|
55
|
+
ComponentProps['MCombobox'] & {
|
|
56
|
+
'onUpdate:modelValue'?: (value: ChoiceValue | null) => void
|
|
57
|
+
'onUpdate:query'?: (value: string) => void
|
|
58
|
+
onSelect?: (value: ChoiceOption | null) => void
|
|
59
|
+
onFocus?: () => void
|
|
60
|
+
onBlur?: () => void
|
|
61
|
+
},
|
|
62
|
+
InputHandle
|
|
63
|
+
>
|
|
64
|
+
MFilePicker: DefineComponent<ComponentProps['MFilePicker'], InputHandle>
|
|
65
|
+
MFormGroup: DefineComponent<ComponentProps['MFormGroup']>
|
|
66
|
+
MFormErrors: DefineComponent<
|
|
67
|
+
ComponentProps['MFormErrors'] & { onFocus?: (field: string, focused: boolean) => void }
|
|
68
|
+
>
|
|
69
|
+
MSteps: DefineComponent<
|
|
70
|
+
ComponentProps['MSteps'] & { 'onUpdate:modelValue'?: (value: ChoiceValue) => void }
|
|
71
|
+
>
|
|
72
|
+
MPagination: DefineComponent<
|
|
73
|
+
ComponentProps['MPagination'] & { 'onUpdate:modelValue'?: (value: number) => void }
|
|
74
|
+
>
|
|
33
75
|
MScreen: DefineComponent<ComponentProps['MScreen']>
|
|
34
76
|
MRow: DefineComponent<ComponentProps['MRow']>
|
|
35
77
|
MColumn: DefineComponent<ComponentProps['MColumn']>
|
|
78
|
+
MStack: DefineComponent<ComponentProps['MStack']>
|
|
79
|
+
MLink: DefineComponent<
|
|
80
|
+
ComponentProps['MLink'] & Action & { onError?: (error: unknown) => void }
|
|
81
|
+
>
|
|
36
82
|
MBox: DefineComponent<ComponentProps['MBox']>
|
|
37
83
|
MCard: DefineComponent<ComponentProps['MCard'] & Action>
|
|
38
84
|
MText: DefineComponent<ComponentProps['MText']>
|
package/src/vue/index.ts
CHANGED
|
@@ -6,15 +6,19 @@ export type {
|
|
|
6
6
|
AppearanceSource,
|
|
7
7
|
ThemeContextOptions,
|
|
8
8
|
} from './theme.js'
|
|
9
|
-
export { layoutDirection, useDefaultShrink } from './layout-context.js'
|
|
9
|
+
export { layoutDirection, useDefaultShrink, useLayoutShrink } from './layout-context.js'
|
|
10
10
|
export { textContent } from './text-content.js'
|
|
11
11
|
export type {} from './global-components.js'
|
|
12
12
|
export type { InputPlatformAttributes } from './global-components.js'
|
|
13
13
|
export {
|
|
14
14
|
boxProps,
|
|
15
|
+
motionBoxProps,
|
|
15
16
|
spacingProp,
|
|
16
17
|
rowProps,
|
|
17
18
|
columnProps,
|
|
19
|
+
stackProps,
|
|
20
|
+
linkProps,
|
|
21
|
+
linkEmits,
|
|
18
22
|
cardProps,
|
|
19
23
|
buttonProps,
|
|
20
24
|
textProps,
|
|
@@ -34,12 +38,11 @@ export {
|
|
|
34
38
|
revealProps,
|
|
35
39
|
sheetProps,
|
|
36
40
|
sheetEmits,
|
|
37
|
-
componentProps,
|
|
38
41
|
viewAttrs,
|
|
39
42
|
actionEmits,
|
|
40
43
|
sliderEmits,
|
|
41
44
|
} from './props.js'
|
|
42
|
-
export type { BoxProps,
|
|
45
|
+
export type { BoxProps, Align, Justify } from './props.js'
|
|
43
46
|
|
|
44
47
|
export { useToast, useToastHost, installAppToast, useAppToastHost } from './toast.js'
|
|
45
48
|
export { toastProps } from './props.js'
|
|
@@ -64,3 +67,16 @@ export { spanProps } from './props.js'
|
|
|
64
67
|
|
|
65
68
|
export { useCachedActivity } from './cached-activity.js'
|
|
66
69
|
export { buttonContent, ButtonAdornment, useButtonAction } from './button-content.js'
|
|
70
|
+
|
|
71
|
+
export { componentProps } from './component-props.js'
|
|
72
|
+
export type { ComponentProps } from './component-props.js'
|
|
73
|
+
export * from './date-props.js'
|
|
74
|
+
export * from './date-picker.js'
|
|
75
|
+
export * from './date-calendar.js'
|
|
76
|
+
export * from './combobox.js'
|
|
77
|
+
export * from './files.js'
|
|
78
|
+
export * from './forms.js'
|
|
79
|
+
export * from './workflow-props.js'
|
|
80
|
+
export * from './workflows.js'
|
|
81
|
+
export { useRevealState } from './reveal-state.js'
|
|
82
|
+
export type { RevealHost } from './reveal-state.js'
|