@getcortexlabs/mavis-core 0.1.0-alpha.5 → 0.1.0-alpha.7
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/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 +7 -7
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +9 -4
- package/dist/capabilities.js.map +1 -1
- package/dist/choice-motion.d.ts +14 -0
- package/dist/choice-motion.d.ts.map +1 -0
- package/dist/choice-motion.js +5 -0
- package/dist/choice-motion.js.map +1 -0
- package/dist/contracts.d.ts +61 -1
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +8 -1
- package/dist/contracts.js.map +1 -1
- 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 +12 -0
- package/dist/experimental-regions.d.ts.map +1 -1
- package/dist/experimental-regions.js +125 -0
- package/dist/experimental-regions.js.map +1 -1
- package/dist/experimental.d.ts +38 -4
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +70 -11
- package/dist/experimental.js.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -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/multi-select.d.ts +4 -0
- package/dist/multi-select.d.ts.map +1 -0
- package/dist/multi-select.js +23 -0
- package/dist/multi-select.js.map +1 -0
- package/dist/number-input.d.ts +21 -0
- package/dist/number-input.d.ts.map +1 -0
- package/dist/number-input.js +63 -0
- package/dist/number-input.js.map +1 -0
- package/dist/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/component-props.d.ts +434 -0
- package/dist/vue/component-props.d.ts.map +1 -1
- package/dist/vue/component-props.js +4 -0
- package/dist/vue/component-props.js.map +1 -1
- package/dist/vue/configurator-props.d.ts +251 -0
- package/dist/vue/configurator-props.d.ts.map +1 -0
- package/dist/vue/configurator-props.js +56 -0
- package/dist/vue/configurator-props.js.map +1 -0
- package/dist/vue/configurator.d.ts +403 -0
- package/dist/vue/configurator.d.ts.map +1 -0
- package/dist/vue/configurator.js +287 -0
- package/dist/vue/configurator.js.map +1 -0
- package/dist/vue/contracts.d.ts.map +1 -1
- package/dist/vue/contracts.js +7 -1
- package/dist/vue/contracts.js.map +1 -1
- package/dist/vue/date-picker.d.ts +50 -12
- package/dist/vue/date-picker.d.ts.map +1 -1
- package/dist/vue/date-picker.js +28 -6
- package/dist/vue/date-picker.js.map +1 -1
- package/dist/vue/date-props.d.ts +9 -0
- package/dist/vue/date-props.d.ts.map +1 -1
- package/dist/vue/date-props.js +3 -0
- package/dist/vue/date-props.js.map +1 -1
- package/dist/vue/global-components.d.ts +19 -0
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/index.d.ts +6 -2
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +5 -2
- package/dist/vue/index.js.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 +365 -0
- package/dist/vue/props.d.ts.map +1 -1
- package/dist/vue/props.js +25 -1
- 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/workflows.d.ts +1 -1
- package/package.json +1 -1
- package/src/app-icons.ts +57 -0
- package/src/capabilities.ts +9 -4
- package/src/choice-motion.ts +12 -0
- package/src/contracts.ts +12 -2
- package/src/experimental-playback.ts +115 -0
- package/src/experimental-regions.ts +151 -0
- package/src/experimental.ts +139 -21
- package/src/index.ts +10 -1
- package/src/link.ts +28 -0
- package/src/motion.ts +61 -3
- package/src/multi-select.ts +30 -0
- package/src/number-input.ts +80 -0
- package/src/responsive.ts +61 -0
- package/src/theme/themes.ts +3 -3
- package/src/theme/types.ts +13 -1
- package/src/vue/component-props.ts +4 -0
- package/src/vue/configurator-props.ts +59 -0
- package/src/vue/configurator.ts +350 -0
- package/src/vue/contracts.ts +7 -1
- package/src/vue/date-picker.ts +33 -6
- package/src/vue/date-props.ts +3 -0
- package/src/vue/global-components.ts +21 -1
- package/src/vue/index.ts +9 -1
- package/src/vue/layout-context.ts +10 -3
- package/src/vue/props.ts +27 -1
- package/src/vue/reveal-state.ts +83 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { PropType } from '@vue/runtime-core'
|
|
2
|
+
import type { ChoiceOption, ChoiceValue } from '../choice.js'
|
|
3
|
+
import type { NumberLocale } from '../number-input.js'
|
|
4
|
+
import { inputProps, boxProps } from './props.js'
|
|
5
|
+
|
|
6
|
+
const field = {
|
|
7
|
+
id: inputProps.id,
|
|
8
|
+
label: inputProps.label,
|
|
9
|
+
width: inputProps.width,
|
|
10
|
+
grow: inputProps.grow,
|
|
11
|
+
shrink: inputProps.shrink,
|
|
12
|
+
disabled: Boolean,
|
|
13
|
+
readonly: Boolean,
|
|
14
|
+
helperText: inputProps.helperText,
|
|
15
|
+
error: inputProps.error,
|
|
16
|
+
accessibilityHidden: inputProps.accessibilityHidden,
|
|
17
|
+
}
|
|
18
|
+
export const numberInputProps = {
|
|
19
|
+
...field,
|
|
20
|
+
modelValue: { type: Number as PropType<number | null>, default: null },
|
|
21
|
+
draft: { type: String, default: undefined },
|
|
22
|
+
min: { type: Number, default: undefined },
|
|
23
|
+
max: { type: Number, default: undefined },
|
|
24
|
+
step: { type: Number, default: 1 },
|
|
25
|
+
locale: {
|
|
26
|
+
type: String as PropType<NumberLocale>,
|
|
27
|
+
default: 'en-US',
|
|
28
|
+
validator: (value: string) => ['en-US', 'pt-BR'].includes(value),
|
|
29
|
+
},
|
|
30
|
+
name: inputProps.name,
|
|
31
|
+
placeholder: inputProps.placeholder,
|
|
32
|
+
incrementLabel: { type: String, default: 'Increase' },
|
|
33
|
+
decrementLabel: { type: String, default: 'Decrease' },
|
|
34
|
+
}
|
|
35
|
+
export const multiSelectProps = {
|
|
36
|
+
...field,
|
|
37
|
+
modelValue: { type: Array as PropType<readonly ChoiceValue[]>, default: () => [] },
|
|
38
|
+
options: { type: Array as PropType<readonly ChoiceOption[]>, required: true as const },
|
|
39
|
+
maxSelected: { type: Number, default: undefined },
|
|
40
|
+
placeholder: { type: String, default: 'Choose options' },
|
|
41
|
+
searchLabel: { type: String, default: 'Search options' },
|
|
42
|
+
closeLabel: { type: String, default: 'Done' },
|
|
43
|
+
emptyLabel: { type: String, default: 'No matching options' },
|
|
44
|
+
removeLabel: { type: String, default: 'Remove' },
|
|
45
|
+
}
|
|
46
|
+
export const imageProps = {
|
|
47
|
+
...boxProps,
|
|
48
|
+
src: { type: String, required: true as const },
|
|
49
|
+
alt: { type: String, required: true as const },
|
|
50
|
+
aspectRatio: { type: Number, default: 4 / 3 },
|
|
51
|
+
fit: {
|
|
52
|
+
type: String as PropType<'cover' | 'contain'>,
|
|
53
|
+
default: 'cover',
|
|
54
|
+
validator: (value: string) => ['cover', 'contain'].includes(value),
|
|
55
|
+
},
|
|
56
|
+
radius: { ...boxProps.radius, default: 'md' },
|
|
57
|
+
loadingLabel: { type: String, default: 'Loading image' },
|
|
58
|
+
errorLabel: { type: String, default: 'Image unavailable' },
|
|
59
|
+
}
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
onBeforeUnmount,
|
|
4
|
+
defineComponent,
|
|
5
|
+
h,
|
|
6
|
+
mergeProps,
|
|
7
|
+
nextTick,
|
|
8
|
+
ref,
|
|
9
|
+
watch,
|
|
10
|
+
type Component,
|
|
11
|
+
} from '@vue/runtime-core'
|
|
12
|
+
import type { InputHandle } from '../input.js'
|
|
13
|
+
import type { ChoiceValue } from '../choice.js'
|
|
14
|
+
import { choiceKey } from '../choice.js'
|
|
15
|
+
import {
|
|
16
|
+
formatNumber,
|
|
17
|
+
parseNumberDraft,
|
|
18
|
+
stepNumber,
|
|
19
|
+
validateNumberConstraints,
|
|
20
|
+
type NumberDraft,
|
|
21
|
+
} from '../number-input.js'
|
|
22
|
+
import { toggleMultiSelection, validateMultiSelection } from '../multi-select.js'
|
|
23
|
+
import { numberInputProps, multiSelectProps } from './configurator-props.js'
|
|
24
|
+
import { useButtonAction } from './button-content.js'
|
|
25
|
+
|
|
26
|
+
interface Primitives {
|
|
27
|
+
Column: Component
|
|
28
|
+
Row: Component
|
|
29
|
+
Text: Component
|
|
30
|
+
Button: Component
|
|
31
|
+
Input: Component
|
|
32
|
+
Chip: Component
|
|
33
|
+
Checkbox: Component
|
|
34
|
+
Sheet: Component
|
|
35
|
+
focusTrigger: (component: unknown) => void
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Shared controls compose the renderer primitives, keeping editing and selection in one place. */
|
|
39
|
+
export function createConfiguratorControls(ui: Primitives, platform: 'web' | 'native') {
|
|
40
|
+
const NumberInput = defineComponent({
|
|
41
|
+
name: 'MNumberInput',
|
|
42
|
+
inheritAttrs: false,
|
|
43
|
+
props: numberInputProps,
|
|
44
|
+
emits: {
|
|
45
|
+
'update:modelValue': (_value: number | null) => true,
|
|
46
|
+
'update:draft': (_value: string) => true,
|
|
47
|
+
validityChange: (_value: NumberDraft) => true,
|
|
48
|
+
focus: () => true,
|
|
49
|
+
blur: () => true,
|
|
50
|
+
},
|
|
51
|
+
setup(props, { attrs, emit, expose }) {
|
|
52
|
+
useButtonAction()
|
|
53
|
+
const editor = ref<InputHandle>()
|
|
54
|
+
const local = ref(props.draft ?? formatNumber(props.modelValue, props.locale))
|
|
55
|
+
const draft = computed(() => props.draft ?? local.value)
|
|
56
|
+
const parsed = computed(() => parseNumberDraft(draft.value, props.locale, props))
|
|
57
|
+
let alive = true
|
|
58
|
+
onBeforeUnmount(() => {
|
|
59
|
+
alive = false
|
|
60
|
+
})
|
|
61
|
+
let revision = 0
|
|
62
|
+
let requested: number | null | undefined
|
|
63
|
+
function setDraft(value: string) {
|
|
64
|
+
local.value = value
|
|
65
|
+
emit('update:draft', value)
|
|
66
|
+
}
|
|
67
|
+
watch(
|
|
68
|
+
() => [props.modelValue, props.locale] as const,
|
|
69
|
+
([value, locale], previous) => {
|
|
70
|
+
if (!Object.is(value, requested) || locale !== previous[1])
|
|
71
|
+
setDraft(formatNumber(value, locale))
|
|
72
|
+
requested = undefined
|
|
73
|
+
},
|
|
74
|
+
)
|
|
75
|
+
watch(
|
|
76
|
+
() => props.draft,
|
|
77
|
+
(value) => {
|
|
78
|
+
if (value !== undefined) local.value = value
|
|
79
|
+
},
|
|
80
|
+
)
|
|
81
|
+
function publish(value: number | null) {
|
|
82
|
+
const current = ++revision
|
|
83
|
+
requested = value
|
|
84
|
+
emit('update:modelValue', value)
|
|
85
|
+
void nextTick(() => {
|
|
86
|
+
if (!alive || current !== revision) return
|
|
87
|
+
if (!Object.is(props.modelValue, value))
|
|
88
|
+
setDraft(formatNumber(props.modelValue, props.locale))
|
|
89
|
+
requested = undefined
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
function edit(value: string) {
|
|
93
|
+
if (props.disabled || props.readonly) return
|
|
94
|
+
revision++
|
|
95
|
+
setDraft(value)
|
|
96
|
+
const validation = parseNumberDraft(value, props.locale, props)
|
|
97
|
+
emit('validityChange', validation)
|
|
98
|
+
if (validation.status === 'valid' || validation.status === 'empty')
|
|
99
|
+
publish(validation.value)
|
|
100
|
+
}
|
|
101
|
+
function step(direction: -1 | 1) {
|
|
102
|
+
if (props.disabled || props.readonly) return
|
|
103
|
+
const current = parsed.value.status === 'valid' ? parsed.value.value : props.modelValue
|
|
104
|
+
const value = stepNumber(current, direction, props)
|
|
105
|
+
setDraft(formatNumber(value, props.locale))
|
|
106
|
+
publish(value)
|
|
107
|
+
emit('validityChange', { status: 'valid', value })
|
|
108
|
+
}
|
|
109
|
+
expose({
|
|
110
|
+
focus: () => editor.value?.focus(),
|
|
111
|
+
blur: () => editor.value?.blur(),
|
|
112
|
+
} satisfies InputHandle)
|
|
113
|
+
return () => {
|
|
114
|
+
validateNumberConstraints(props)
|
|
115
|
+
if (!props.label.trim()) throw new TypeError('NumberInput requires a label.')
|
|
116
|
+
const blocked = props.disabled || props.readonly
|
|
117
|
+
const issue = ['invalid', 'range'].includes(parsed.value.status)
|
|
118
|
+
const message = issue
|
|
119
|
+
? props.locale === 'pt-BR'
|
|
120
|
+
? 'Informe um número dentro dos limites.'
|
|
121
|
+
: 'Enter a number within the allowed range.'
|
|
122
|
+
: ''
|
|
123
|
+
return h(
|
|
124
|
+
ui.Row,
|
|
125
|
+
{
|
|
126
|
+
gap: 'sm',
|
|
127
|
+
align: 'end',
|
|
128
|
+
width: props.width,
|
|
129
|
+
grow: props.grow,
|
|
130
|
+
shrink: props.shrink,
|
|
131
|
+
accessibilityHidden: props.accessibilityHidden,
|
|
132
|
+
},
|
|
133
|
+
() => [
|
|
134
|
+
h(
|
|
135
|
+
ui.Input,
|
|
136
|
+
mergeProps(attrs, {
|
|
137
|
+
ref: editor,
|
|
138
|
+
id: props.id,
|
|
139
|
+
modelValue: draft.value,
|
|
140
|
+
label: props.label,
|
|
141
|
+
name: props.name,
|
|
142
|
+
placeholder: props.placeholder,
|
|
143
|
+
inputmode: 'decimal',
|
|
144
|
+
disabled: props.disabled,
|
|
145
|
+
readonly: props.readonly,
|
|
146
|
+
helperText: props.helperText,
|
|
147
|
+
error: props.error || message,
|
|
148
|
+
accessibilityHidden: props.accessibilityHidden,
|
|
149
|
+
width: 0,
|
|
150
|
+
grow: 1,
|
|
151
|
+
autocorrect: false,
|
|
152
|
+
autocapitalize: 'none',
|
|
153
|
+
'onUpdate:modelValue': edit,
|
|
154
|
+
onFocus: () => emit('focus'),
|
|
155
|
+
onBlur: () => emit('blur'),
|
|
156
|
+
...(platform === 'web'
|
|
157
|
+
? {
|
|
158
|
+
onKeydown: (event: {
|
|
159
|
+
key: string
|
|
160
|
+
isComposing: boolean
|
|
161
|
+
preventDefault(): void
|
|
162
|
+
}) => {
|
|
163
|
+
if (
|
|
164
|
+
!blocked &&
|
|
165
|
+
!event.isComposing &&
|
|
166
|
+
['ArrowUp', 'ArrowDown'].includes(event.key)
|
|
167
|
+
) {
|
|
168
|
+
event.preventDefault()
|
|
169
|
+
step(event.key === 'ArrowUp' ? 1 : -1)
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
}
|
|
173
|
+
: {}),
|
|
174
|
+
}),
|
|
175
|
+
),
|
|
176
|
+
h(ui.Button, {
|
|
177
|
+
text: '−',
|
|
178
|
+
variant: 'secondary',
|
|
179
|
+
accessibilityLabel: `${props.decrementLabel}: ${props.label}`,
|
|
180
|
+
disabled:
|
|
181
|
+
blocked ||
|
|
182
|
+
(props.min !== undefined &&
|
|
183
|
+
props.modelValue !== null &&
|
|
184
|
+
props.modelValue <= props.min),
|
|
185
|
+
onClick: () => step(-1),
|
|
186
|
+
}),
|
|
187
|
+
h(ui.Button, {
|
|
188
|
+
text: '+',
|
|
189
|
+
variant: 'secondary',
|
|
190
|
+
accessibilityLabel: `${props.incrementLabel}: ${props.label}`,
|
|
191
|
+
disabled:
|
|
192
|
+
blocked ||
|
|
193
|
+
(props.max !== undefined &&
|
|
194
|
+
props.modelValue !== null &&
|
|
195
|
+
props.modelValue >= props.max),
|
|
196
|
+
onClick: () => step(1),
|
|
197
|
+
}),
|
|
198
|
+
],
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
})
|
|
203
|
+
const MultiSelect = defineComponent({
|
|
204
|
+
name: 'MMultiSelect',
|
|
205
|
+
inheritAttrs: false,
|
|
206
|
+
props: multiSelectProps,
|
|
207
|
+
emits: { 'update:modelValue': (_values: ChoiceValue[]) => true },
|
|
208
|
+
setup(props, { attrs, emit }) {
|
|
209
|
+
useButtonAction()
|
|
210
|
+
const open = ref(false),
|
|
211
|
+
query = ref('')
|
|
212
|
+
const trigger = ref<unknown>()
|
|
213
|
+
let alive = true
|
|
214
|
+
onBeforeUnmount(() => {
|
|
215
|
+
alive = false
|
|
216
|
+
})
|
|
217
|
+
function restoreFocus() {
|
|
218
|
+
void nextTick(() => {
|
|
219
|
+
if (alive) ui.focusTrigger(trigger.value)
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
watch(
|
|
223
|
+
() => props.disabled || props.readonly,
|
|
224
|
+
(blocked) => {
|
|
225
|
+
if (blocked) open.value = false
|
|
226
|
+
},
|
|
227
|
+
)
|
|
228
|
+
watch(open, (value) => {
|
|
229
|
+
if (!value && platform === 'native' && !props.disabled) restoreFocus()
|
|
230
|
+
})
|
|
231
|
+
function toggle(value: ChoiceValue) {
|
|
232
|
+
if (props.disabled || props.readonly) return
|
|
233
|
+
const next = toggleMultiSelection(props.options, props.modelValue, value, props.maxSelected)
|
|
234
|
+
if (next) emit('update:modelValue', next)
|
|
235
|
+
}
|
|
236
|
+
return () => {
|
|
237
|
+
validateMultiSelection(props.options, props.modelValue, props.maxSelected)
|
|
238
|
+
if (!props.label.trim()) throw new TypeError('MultiSelect requires a label.')
|
|
239
|
+
const selected = props.modelValue.map((value) =>
|
|
240
|
+
props.options.find((option) => option.value === value)!,
|
|
241
|
+
)
|
|
242
|
+
const filter = query.value.trim().toLocaleLowerCase()
|
|
243
|
+
const options = props.options.filter((option) =>
|
|
244
|
+
option.label.toLocaleLowerCase().includes(filter),
|
|
245
|
+
)
|
|
246
|
+
return h(
|
|
247
|
+
ui.Column,
|
|
248
|
+
mergeProps(attrs, {
|
|
249
|
+
gap: 'sm',
|
|
250
|
+
width: props.width,
|
|
251
|
+
grow: props.grow,
|
|
252
|
+
shrink: props.shrink,
|
|
253
|
+
accessibilityHidden: props.accessibilityHidden,
|
|
254
|
+
}),
|
|
255
|
+
() => [
|
|
256
|
+
h(ui.Text, { text: props.label, variant: 'caption', weight: '600' }),
|
|
257
|
+
h(ui.Button, {
|
|
258
|
+
ref: trigger,
|
|
259
|
+
id: props.id,
|
|
260
|
+
text: selected.length ? `${props.label} · ${selected.length}` : props.placeholder,
|
|
261
|
+
accessibilityLabel: `${props.label}: ${selected.map((option) => option.label).join(', ') || props.placeholder}`,
|
|
262
|
+
variant: 'secondary',
|
|
263
|
+
disabled: props.disabled || props.readonly,
|
|
264
|
+
onClick: () => {
|
|
265
|
+
ui.focusTrigger(trigger.value)
|
|
266
|
+
query.value = ''
|
|
267
|
+
open.value = true
|
|
268
|
+
},
|
|
269
|
+
}),
|
|
270
|
+
selected.length
|
|
271
|
+
? h(ui.Row, { gap: 'sm', wrap: true }, () =>
|
|
272
|
+
selected.map((option) =>
|
|
273
|
+
h(ui.Chip, {
|
|
274
|
+
key: choiceKey(option.value),
|
|
275
|
+
label: option.label,
|
|
276
|
+
removable: true,
|
|
277
|
+
removeLabel: `${props.removeLabel}: ${option.label}`,
|
|
278
|
+
disabled: props.disabled || props.readonly || option.disabled,
|
|
279
|
+
onRemove: () => {
|
|
280
|
+
toggle(option.value)
|
|
281
|
+
restoreFocus()
|
|
282
|
+
},
|
|
283
|
+
}),
|
|
284
|
+
),
|
|
285
|
+
)
|
|
286
|
+
: null,
|
|
287
|
+
props.error || props.helperText
|
|
288
|
+
? h(ui.Text, {
|
|
289
|
+
text: props.error || props.helperText,
|
|
290
|
+
tone: props.error ? 'danger' : 'muted',
|
|
291
|
+
variant: 'caption',
|
|
292
|
+
})
|
|
293
|
+
: null,
|
|
294
|
+
h(
|
|
295
|
+
ui.Sheet,
|
|
296
|
+
{
|
|
297
|
+
open: open.value,
|
|
298
|
+
title: props.label,
|
|
299
|
+
closeLabel: props.closeLabel,
|
|
300
|
+
'onUpdate:open': (value: boolean) => {
|
|
301
|
+
open.value = value
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
() => [
|
|
305
|
+
h(ui.Column, { gap: 'md' }, () => [
|
|
306
|
+
h(ui.Input, {
|
|
307
|
+
modelValue: query.value,
|
|
308
|
+
label: props.searchLabel,
|
|
309
|
+
type: 'search',
|
|
310
|
+
autocorrect: false,
|
|
311
|
+
'onUpdate:modelValue': (value: string) => {
|
|
312
|
+
query.value = value
|
|
313
|
+
},
|
|
314
|
+
}),
|
|
315
|
+
...options.map((option) =>
|
|
316
|
+
h(ui.Checkbox, {
|
|
317
|
+
key: choiceKey(option.value),
|
|
318
|
+
label: option.label,
|
|
319
|
+
helperText: option.helperText ?? '',
|
|
320
|
+
modelValue: props.modelValue.includes(option.value),
|
|
321
|
+
disabled:
|
|
322
|
+
props.disabled ||
|
|
323
|
+
props.readonly ||
|
|
324
|
+
option.disabled ||
|
|
325
|
+
(!props.modelValue.includes(option.value) &&
|
|
326
|
+
props.maxSelected !== undefined &&
|
|
327
|
+
props.modelValue.length >= props.maxSelected),
|
|
328
|
+
'onUpdate:modelValue': () => toggle(option.value),
|
|
329
|
+
}),
|
|
330
|
+
),
|
|
331
|
+
!options.length ? h(ui.Text, { text: props.emptyLabel, tone: 'muted' }) : null,
|
|
332
|
+
h(ui.Button, {
|
|
333
|
+
text: props.closeLabel,
|
|
334
|
+
onClick: () => {
|
|
335
|
+
open.value = false
|
|
336
|
+
},
|
|
337
|
+
}),
|
|
338
|
+
]),
|
|
339
|
+
],
|
|
340
|
+
),
|
|
341
|
+
],
|
|
342
|
+
)
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
})
|
|
346
|
+
return {
|
|
347
|
+
MNumberInput: NumberInput as typeof NumberInput & { new (): InputHandle },
|
|
348
|
+
MMultiSelect: MultiSelect,
|
|
349
|
+
}
|
|
350
|
+
}
|
package/src/vue/contracts.ts
CHANGED
|
@@ -8,7 +8,13 @@ type VueProperty<P extends Property> = { type: PropType<PropertyValue<P>> } & (P
|
|
|
8
8
|
: unknown) &
|
|
9
9
|
(P extends { required: true } ? { required: true } : unknown)
|
|
10
10
|
|
|
11
|
-
const constructors = {
|
|
11
|
+
const constructors = {
|
|
12
|
+
string: String,
|
|
13
|
+
number: Number,
|
|
14
|
+
boolean: Boolean,
|
|
15
|
+
object: Object,
|
|
16
|
+
function: Function,
|
|
17
|
+
}
|
|
12
18
|
|
|
13
19
|
/** Vue owns coercion and warnings; portable metadata owns names, defaults and allowed values. */
|
|
14
20
|
export function vueProperty<P extends Property>(definition: P): VueProperty<P> {
|
package/src/vue/date-picker.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
mergeProps,
|
|
6
6
|
nextTick,
|
|
7
7
|
onBeforeUnmount,
|
|
8
|
+
onMounted,
|
|
8
9
|
ref,
|
|
9
10
|
watch,
|
|
10
11
|
type Component,
|
|
@@ -32,8 +33,9 @@ import {
|
|
|
32
33
|
} from './date-props.js'
|
|
33
34
|
import { useButtonAction } from './button-content.js'
|
|
34
35
|
|
|
35
|
-
type EntryProps = Omit<ExtractPropTypes<typeof dateRangePickerProps>, 'modelValue'> & {
|
|
36
|
+
type EntryProps = Omit<ExtractPropTypes<typeof dateRangePickerProps>, 'modelValue' | 'draft'> & {
|
|
36
37
|
modelValue: CivilDate | null | DateRange
|
|
38
|
+
draft?: string | DateRangeDraft
|
|
37
39
|
name?: string
|
|
38
40
|
}
|
|
39
41
|
interface DatePrimitives {
|
|
@@ -46,6 +48,8 @@ interface DatePrimitives {
|
|
|
46
48
|
/** Internal adapter boundary: capture a focusable opener and dismiss the native keyboard. */
|
|
47
49
|
beforeOpen(opener: unknown): void
|
|
48
50
|
afterClose(opener: unknown): void
|
|
51
|
+
deferActions?: boolean
|
|
52
|
+
openerAttrs?: Record<string, unknown>
|
|
49
53
|
}
|
|
50
54
|
interface EntryEvents {
|
|
51
55
|
model(value: CivilDate | null | DateRange): void
|
|
@@ -64,6 +68,10 @@ export function createDatePickers(primitives: DatePrimitives) {
|
|
|
64
68
|
const end = ref('')
|
|
65
69
|
const touched = ref(false)
|
|
66
70
|
const open = ref(false)
|
|
71
|
+
const ready = ref(!primitives.deferActions)
|
|
72
|
+
onMounted(() => {
|
|
73
|
+
ready.value = true
|
|
74
|
+
})
|
|
67
75
|
const endpoint = ref<'start' | 'end'>('start')
|
|
68
76
|
const activeDate = ref<CivilDate>('2000-01-01')
|
|
69
77
|
const first = ref<InputHandle>()
|
|
@@ -90,13 +98,22 @@ export function createDatePickers(primitives: DatePrimitives) {
|
|
|
90
98
|
return { start: (props.modelValue as CivilDate | null) ?? '', end: '' }
|
|
91
99
|
}
|
|
92
100
|
function restore() {
|
|
93
|
-
|
|
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')
|
|
94
111
|
start.value = value.start
|
|
95
112
|
end.value = value.end
|
|
96
113
|
}
|
|
97
114
|
restore()
|
|
98
115
|
watch(
|
|
99
|
-
() => props.modelValue,
|
|
116
|
+
() => [props.modelValue, props.draft],
|
|
100
117
|
() => {
|
|
101
118
|
revision++
|
|
102
119
|
restore()
|
|
@@ -137,6 +154,11 @@ export function createDatePickers(primitives: DatePrimitives) {
|
|
|
137
154
|
const current = ++revision
|
|
138
155
|
const draft = { start: start.value, end: end.value }
|
|
139
156
|
events.draft(range ? { ...draft } : draft.start)
|
|
157
|
+
if (props.draft !== undefined) {
|
|
158
|
+
void nextTick(() => {
|
|
159
|
+
if (alive && revision === current) restore()
|
|
160
|
+
})
|
|
161
|
+
}
|
|
140
162
|
if (!validity.value.valid) return
|
|
141
163
|
const previous = snapshot()
|
|
142
164
|
if (previous.start === draft.start && previous.end === draft.end) return
|
|
@@ -157,7 +179,7 @@ export function createDatePickers(primitives: DatePrimitives) {
|
|
|
157
179
|
})
|
|
158
180
|
}
|
|
159
181
|
function show(which: 'start' | 'end') {
|
|
160
|
-
if (props.disabled || props.readonly || open.value) return
|
|
182
|
+
if (!ready.value || props.disabled || props.readonly || open.value) return
|
|
161
183
|
endpoint.value = which
|
|
162
184
|
const draft = which === 'end' ? end.value : start.value
|
|
163
185
|
let target = isCivilDate(draft) ? draft : (props.min ?? civilDate(`${props.initialMonth}-01`))
|
|
@@ -249,11 +271,12 @@ export function createDatePickers(primitives: DatePrimitives) {
|
|
|
249
271
|
},
|
|
250
272
|
}),
|
|
251
273
|
h(Button, {
|
|
274
|
+
...primitives.openerAttrs,
|
|
252
275
|
ref: which === 'start' ? firstOpener : secondOpener,
|
|
253
276
|
icon: 'calendar-days',
|
|
254
277
|
variant: 'secondary',
|
|
255
278
|
accessibilityLabel: `${props.calendarLabel ?? translations.calendar}: ${label(which)}`,
|
|
256
|
-
disabled: props.disabled || props.readonly,
|
|
279
|
+
disabled: !ready.value || props.disabled || props.readonly,
|
|
257
280
|
onClick: () => show(which),
|
|
258
281
|
}),
|
|
259
282
|
],
|
|
@@ -278,7 +301,11 @@ export function createDatePickers(primitives: DatePrimitives) {
|
|
|
278
301
|
text: props.clearLabel ?? `${translations.clear}: ${props.label}`,
|
|
279
302
|
variant: 'ghost',
|
|
280
303
|
size: 'sm',
|
|
281
|
-
disabled:
|
|
304
|
+
disabled:
|
|
305
|
+
!ready.value ||
|
|
306
|
+
props.disabled ||
|
|
307
|
+
props.readonly ||
|
|
308
|
+
(!start.value && !end.value),
|
|
282
309
|
onClick: () => {
|
|
283
310
|
if (props.disabled || props.readonly) return
|
|
284
311
|
start.value = ''
|
package/src/vue/date-props.ts
CHANGED
|
@@ -32,11 +32,14 @@ const common = {
|
|
|
32
32
|
}
|
|
33
33
|
export const datePickerProps = {
|
|
34
34
|
...common,
|
|
35
|
+
/** Optional controlled editor text, including incomplete or invalid dates. */
|
|
36
|
+
draft: { type: String, default: undefined },
|
|
35
37
|
modelValue: { type: String as PropType<CivilDate | null>, default: null },
|
|
36
38
|
name: { type: String, default: undefined },
|
|
37
39
|
}
|
|
38
40
|
export const dateRangePickerProps = {
|
|
39
41
|
...common,
|
|
42
|
+
draft: { type: Object as PropType<DateRangeDraft>, default: undefined },
|
|
40
43
|
modelValue: {
|
|
41
44
|
type: Object as PropType<DateRange>,
|
|
42
45
|
default: (): DateRange => ({ start: null, end: null }),
|
|
@@ -8,7 +8,7 @@ import type { DialogCloseReason } from '../dialog.js'
|
|
|
8
8
|
import type { SheetCloseReason } from '../sheet.js'
|
|
9
9
|
import type { InputHandle } from '../input.js'
|
|
10
10
|
|
|
11
|
-
type Action = { onClick?: () => void }
|
|
11
|
+
type Action = { onClick?: () => void; onError?: (error: unknown) => void }
|
|
12
12
|
type Model = { 'onUpdate:modelValue'?: (value: number) => void }
|
|
13
13
|
type InputEvents = {
|
|
14
14
|
onAction?: () => void
|
|
@@ -61,6 +61,22 @@ declare module '@vue/runtime-core' {
|
|
|
61
61
|
},
|
|
62
62
|
InputHandle
|
|
63
63
|
>
|
|
64
|
+
MNumberInput: DefineComponent<
|
|
65
|
+
ComponentProps['MNumberInput'] & {
|
|
66
|
+
'onUpdate:modelValue'?: (value: number | null) => void
|
|
67
|
+
'onUpdate:draft'?: (value: string) => void
|
|
68
|
+
onValidityChange?: (value: import('../number-input.js').NumberDraft) => void
|
|
69
|
+
onFocus?: () => void
|
|
70
|
+
onBlur?: () => void
|
|
71
|
+
},
|
|
72
|
+
InputHandle
|
|
73
|
+
>
|
|
74
|
+
MMultiSelect: DefineComponent<
|
|
75
|
+
ComponentProps['MMultiSelect'] & { 'onUpdate:modelValue'?: (value: ChoiceValue[]) => void }
|
|
76
|
+
>
|
|
77
|
+
MImage: DefineComponent<
|
|
78
|
+
ComponentProps['MImage'] & { onLoad?: (src: string) => void; onError?: (src: string) => void }
|
|
79
|
+
>
|
|
64
80
|
MFilePicker: DefineComponent<ComponentProps['MFilePicker'], InputHandle>
|
|
65
81
|
MFormGroup: DefineComponent<ComponentProps['MFormGroup']>
|
|
66
82
|
MFormErrors: DefineComponent<
|
|
@@ -75,6 +91,10 @@ declare module '@vue/runtime-core' {
|
|
|
75
91
|
MScreen: DefineComponent<ComponentProps['MScreen']>
|
|
76
92
|
MRow: DefineComponent<ComponentProps['MRow']>
|
|
77
93
|
MColumn: DefineComponent<ComponentProps['MColumn']>
|
|
94
|
+
MStack: DefineComponent<ComponentProps['MStack']>
|
|
95
|
+
MLink: DefineComponent<
|
|
96
|
+
ComponentProps['MLink'] & Action & { onError?: (error: unknown) => void }
|
|
97
|
+
>
|
|
78
98
|
MBox: DefineComponent<ComponentProps['MBox']>
|
|
79
99
|
MCard: DefineComponent<ComponentProps['MCard'] & Action>
|
|
80
100
|
MText: DefineComponent<ComponentProps['MText']>
|
package/src/vue/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ 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'
|
|
@@ -16,6 +16,9 @@ export {
|
|
|
16
16
|
spacingProp,
|
|
17
17
|
rowProps,
|
|
18
18
|
columnProps,
|
|
19
|
+
stackProps,
|
|
20
|
+
linkProps,
|
|
21
|
+
linkEmits,
|
|
19
22
|
cardProps,
|
|
20
23
|
buttonProps,
|
|
21
24
|
textProps,
|
|
@@ -75,3 +78,8 @@ export * from './files.js'
|
|
|
75
78
|
export * from './forms.js'
|
|
76
79
|
export * from './workflow-props.js'
|
|
77
80
|
export * from './workflows.js'
|
|
81
|
+
export { useRevealState } from './reveal-state.js'
|
|
82
|
+
export type { RevealHost } from './reveal-state.js'
|
|
83
|
+
|
|
84
|
+
export * from './configurator-props.js'
|
|
85
|
+
export * from './configurator.js'
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import { inject, type InjectionKey } from '@vue/runtime-core'
|
|
1
|
+
import { computed, inject, unref, type InjectionKey, type Ref } from '@vue/runtime-core'
|
|
2
2
|
|
|
3
|
-
export const layoutDirection: InjectionKey<'row' | 'column'
|
|
3
|
+
export const layoutDirection: InjectionKey<'row' | 'column' | Readonly<Ref<'row' | 'column'>>> =
|
|
4
|
+
Symbol('mavis.layout')
|
|
4
5
|
|
|
5
6
|
/** Rows may wrap text to fit their width; columns preserve the natural height of content. */
|
|
6
7
|
export function useDefaultShrink(): number {
|
|
7
|
-
return inject(layoutDirection, 'column') === 'row' ? 1 : 0
|
|
8
|
+
return unref(inject(layoutDirection, 'column')) === 'row' ? 1 : 0
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** A responsive parent changes direction without replacing its children. */
|
|
12
|
+
export function useLayoutShrink() {
|
|
13
|
+
const direction = inject(layoutDirection, 'column')
|
|
14
|
+
return computed(() => (unref(direction) === 'row' ? 1 : 0))
|
|
8
15
|
}
|