@getcortexlabs/mavis-core 0.1.0-alpha.6 → 0.1.0-alpha.8
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/capabilities.d.ts +19 -6
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +19 -3
- 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 +42 -2
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +17 -0
- package/dist/contracts.js.map +1 -1
- package/dist/dialog.d.ts +1 -1
- package/dist/dialog.d.ts.map +1 -1
- package/dist/dialog.js +1 -0
- package/dist/dialog.js.map +1 -1
- package/dist/experimental-collections.d.ts +82 -0
- package/dist/experimental-collections.d.ts.map +1 -0
- package/dist/experimental-collections.js +8 -0
- package/dist/experimental-collections.js.map +1 -0
- package/dist/experimental-effects.d.ts +107 -0
- package/dist/experimental-effects.d.ts.map +1 -0
- package/dist/experimental-effects.js +24 -0
- package/dist/experimental-effects.js.map +1 -0
- package/dist/experimental-platforms.d.ts +94 -0
- package/dist/experimental-platforms.d.ts.map +1 -0
- package/dist/experimental-platforms.js +2 -0
- package/dist/experimental-platforms.js.map +1 -0
- package/dist/experimental-playback.d.ts +2 -2
- package/dist/experimental-playback.d.ts.map +1 -1
- package/dist/experimental-regions.d.ts +17 -2
- package/dist/experimental-regions.d.ts.map +1 -1
- package/dist/experimental-regions.js +91 -0
- package/dist/experimental-regions.js.map +1 -1
- package/dist/experimental-sensors.d.ts +42 -0
- package/dist/experimental-sensors.d.ts.map +1 -0
- package/dist/experimental-sensors.js +2 -0
- package/dist/experimental-sensors.js.map +1 -0
- package/dist/experimental-surfaces.d.ts +127 -0
- package/dist/experimental-surfaces.d.ts.map +1 -0
- package/dist/experimental-surfaces.js +2 -0
- package/dist/experimental-surfaces.js.map +1 -0
- package/dist/experimental.d.ts +37 -6
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +289 -5
- package/dist/experimental.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.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/vue/component-props.d.ts +309 -20
- 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 +256 -0
- package/dist/vue/configurator-props.d.ts.map +1 -0
- package/dist/vue/configurator-props.js +57 -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/date-picker.d.ts +8 -8
- package/dist/vue/global-components.d.ts +14 -0
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/index.d.ts +3 -0
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +3 -0
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/loading-effect.d.ts +7 -0
- package/dist/vue/loading-effect.d.ts.map +1 -0
- package/dist/vue/loading-effect.js +32 -0
- package/dist/vue/loading-effect.js.map +1 -0
- package/dist/vue/props.d.ts +123 -43
- package/dist/vue/props.d.ts.map +1 -1
- package/dist/vue/props.js +7 -0
- package/dist/vue/props.js.map +1 -1
- package/dist/vue/workflows.d.ts +1 -1
- package/package.json +1 -1
- package/src/capabilities.ts +19 -3
- package/src/choice-motion.ts +12 -0
- package/src/contracts.ts +17 -0
- package/src/dialog.ts +3 -1
- package/src/experimental-collections.ts +87 -0
- package/src/experimental-effects.ts +146 -0
- package/src/experimental-platforms.ts +96 -0
- package/src/experimental-playback.ts +1 -1
- package/src/experimental-regions.ts +136 -2
- package/src/experimental-sensors.ts +50 -0
- package/src/experimental-surfaces.ts +124 -0
- package/src/experimental.ts +367 -20
- package/src/index.ts +4 -0
- package/src/multi-select.ts +30 -0
- package/src/number-input.ts +80 -0
- package/src/vue/component-props.ts +4 -0
- package/src/vue/configurator-props.ts +61 -0
- package/src/vue/configurator.ts +350 -0
- package/src/vue/global-components.ts +16 -0
- package/src/vue/index.ts +4 -0
- package/src/vue/loading-effect.ts +44 -0
- package/src/vue/props.ts +8 -1
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export type NumberLocale = 'en-US' | 'pt-BR'
|
|
2
|
+
export type NumberDraft =
|
|
3
|
+
| { status: 'valid'; value: number }
|
|
4
|
+
| { status: 'empty'; value: null }
|
|
5
|
+
| { status: 'incomplete' | 'invalid' | 'range'; value: null }
|
|
6
|
+
|
|
7
|
+
export interface NumberConstraints {
|
|
8
|
+
min?: number
|
|
9
|
+
max?: number
|
|
10
|
+
step: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function validateNumberConstraints({ min, max, step }: NumberConstraints) {
|
|
14
|
+
if (!Number.isFinite(step) || step <= 0) throw new RangeError('step must be finite and positive.')
|
|
15
|
+
if ([min, max].some((value) => value !== undefined && !Number.isFinite(value)))
|
|
16
|
+
throw new RangeError('Numeric bounds must be finite.')
|
|
17
|
+
if (min !== undefined && max !== undefined && min > max)
|
|
18
|
+
throw new RangeError('min must not exceed max.')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function formatNumber(value: number | null, locale: NumberLocale) {
|
|
22
|
+
if (value === null) return ''
|
|
23
|
+
if (!Number.isFinite(value)) throw new RangeError('NumberInput requires a finite number or null.')
|
|
24
|
+
const [coefficient, exponent] = String(value).split('e')
|
|
25
|
+
let text = coefficient!
|
|
26
|
+
if (exponent) {
|
|
27
|
+
const negative = text.startsWith('-')
|
|
28
|
+
const [whole, fraction = ''] = text.replace('-', '').split('.')
|
|
29
|
+
const digits = whole! + fraction
|
|
30
|
+
const point = whole!.length + Number(exponent)
|
|
31
|
+
text =
|
|
32
|
+
point <= 0
|
|
33
|
+
? `0.${'0'.repeat(-point)}${digits}`
|
|
34
|
+
: point >= digits.length
|
|
35
|
+
? digits + '0'.repeat(point - digits.length)
|
|
36
|
+
: `${digits.slice(0, point)}.${digits.slice(point)}`
|
|
37
|
+
if (negative) text = `-${text}`
|
|
38
|
+
}
|
|
39
|
+
return locale === 'pt-BR' ? text.replace('.', ',') : text
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function parseNumberDraft(
|
|
43
|
+
text: string,
|
|
44
|
+
locale: NumberLocale,
|
|
45
|
+
bounds: NumberConstraints,
|
|
46
|
+
): NumberDraft {
|
|
47
|
+
const value = text.trim()
|
|
48
|
+
if (!value) return { status: 'empty', value: null }
|
|
49
|
+
const normalized = locale === 'pt-BR' ? value.replace(',', '.') : value
|
|
50
|
+
if (/^[+-]?$/.test(normalized) || /^[+-]?(?:\d+)?\.$/.test(normalized))
|
|
51
|
+
return { status: 'incomplete', value: null }
|
|
52
|
+
if (!/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)$/.test(normalized)) return { status: 'invalid', value: null }
|
|
53
|
+
const number = Number(normalized)
|
|
54
|
+
if (!Number.isFinite(number)) return { status: 'invalid', value: null }
|
|
55
|
+
if (
|
|
56
|
+
(bounds.min !== undefined && number < bounds.min) ||
|
|
57
|
+
(bounds.max !== undefined && number > bounds.max)
|
|
58
|
+
)
|
|
59
|
+
return { status: 'range', value: null }
|
|
60
|
+
return { status: 'valid', value: number }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function stepNumber(value: number | null, direction: -1 | 1, bounds: NumberConstraints) {
|
|
64
|
+
validateNumberConstraints(bounds)
|
|
65
|
+
const base = value ?? Math.max(bounds.min ?? 0, Math.min(0, bounds.max ?? 0))
|
|
66
|
+
// Scale ordinary decimal steps only while the integer arithmetic remains exact.
|
|
67
|
+
// Large or very small values retain JavaScript number precision without rounding to 15 digits.
|
|
68
|
+
const decimals = (number: number) => formatNumber(number, 'en-US').split('.')[1]?.length ?? 0
|
|
69
|
+
const factor = 10 ** Math.max(decimals(base), decimals(bounds.step))
|
|
70
|
+
const scaledBase = Math.round(base * factor),
|
|
71
|
+
scaledStep = Math.round(bounds.step * factor)
|
|
72
|
+
const scaledNext = scaledBase + direction * scaledStep
|
|
73
|
+
const next = [scaledBase, scaledStep, scaledNext].every(Number.isSafeInteger)
|
|
74
|
+
? scaledNext / factor
|
|
75
|
+
: base + direction * bounds.step
|
|
76
|
+
return Math.max(
|
|
77
|
+
bounds.min ?? -Infinity,
|
|
78
|
+
Math.min(bounds.max ?? Infinity, Number.isFinite(next) ? next : base),
|
|
79
|
+
)
|
|
80
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { numberInputProps, multiSelectProps, imageProps } from './configurator-props.js'
|
|
1
2
|
import type { ExtractPublicPropTypes } from '@vue/runtime-core'
|
|
2
3
|
import type { SheetName } from '../sheet.js'
|
|
3
4
|
import { componentProps as foundationProps } from './props.js'
|
|
@@ -9,6 +10,9 @@ import { formGroupProps, formErrorsProps, stepsProps, paginationProps } from './
|
|
|
9
10
|
/** Complete registry, kept separate from the primitives used to compose controls. */
|
|
10
11
|
export const componentProps = {
|
|
11
12
|
...foundationProps,
|
|
13
|
+
MNumberInput: numberInputProps,
|
|
14
|
+
MMultiSelect: multiSelectProps,
|
|
15
|
+
MImage: imageProps,
|
|
12
16
|
MDatePicker: datePickerProps,
|
|
13
17
|
MDateRangePicker: dateRangePickerProps,
|
|
14
18
|
MCombobox: comboboxProps,
|
|
@@ -0,0 +1,61 @@
|
|
|
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 type { MotionSurface } from '../experimental.js'
|
|
5
|
+
import { inputProps, boxProps } from './props.js'
|
|
6
|
+
|
|
7
|
+
const field = {
|
|
8
|
+
id: inputProps.id,
|
|
9
|
+
label: inputProps.label,
|
|
10
|
+
width: inputProps.width,
|
|
11
|
+
grow: inputProps.grow,
|
|
12
|
+
shrink: inputProps.shrink,
|
|
13
|
+
disabled: Boolean,
|
|
14
|
+
readonly: Boolean,
|
|
15
|
+
helperText: inputProps.helperText,
|
|
16
|
+
error: inputProps.error,
|
|
17
|
+
accessibilityHidden: inputProps.accessibilityHidden,
|
|
18
|
+
}
|
|
19
|
+
export const numberInputProps = {
|
|
20
|
+
...field,
|
|
21
|
+
modelValue: { type: Number as PropType<number | null>, default: null },
|
|
22
|
+
draft: { type: String, default: undefined },
|
|
23
|
+
min: { type: Number, default: undefined },
|
|
24
|
+
max: { type: Number, default: undefined },
|
|
25
|
+
step: { type: Number, default: 1 },
|
|
26
|
+
locale: {
|
|
27
|
+
type: String as PropType<NumberLocale>,
|
|
28
|
+
default: 'en-US',
|
|
29
|
+
validator: (value: string) => ['en-US', 'pt-BR'].includes(value),
|
|
30
|
+
},
|
|
31
|
+
name: inputProps.name,
|
|
32
|
+
placeholder: inputProps.placeholder,
|
|
33
|
+
incrementLabel: { type: String, default: 'Increase' },
|
|
34
|
+
decrementLabel: { type: String, default: 'Decrease' },
|
|
35
|
+
}
|
|
36
|
+
export const multiSelectProps = {
|
|
37
|
+
...field,
|
|
38
|
+
modelValue: { type: Array as PropType<readonly ChoiceValue[]>, default: () => [] },
|
|
39
|
+
options: { type: Array as PropType<readonly ChoiceOption[]>, required: true as const },
|
|
40
|
+
maxSelected: { type: Number, default: undefined },
|
|
41
|
+
placeholder: { type: String, default: 'Choose options' },
|
|
42
|
+
searchLabel: { type: String, default: 'Search options' },
|
|
43
|
+
closeLabel: { type: String, default: 'Done' },
|
|
44
|
+
emptyLabel: { type: String, default: 'No matching options' },
|
|
45
|
+
removeLabel: { type: String, default: 'Remove' },
|
|
46
|
+
}
|
|
47
|
+
export const imageProps = {
|
|
48
|
+
...boxProps,
|
|
49
|
+
motionSurface: { type: Object as PropType<MotionSurface>, default: undefined },
|
|
50
|
+
src: { type: String, required: true as const },
|
|
51
|
+
alt: { type: String, required: true as const },
|
|
52
|
+
aspectRatio: { type: Number, default: 4 / 3 },
|
|
53
|
+
fit: {
|
|
54
|
+
type: String as PropType<'cover' | 'contain'>,
|
|
55
|
+
default: 'cover',
|
|
56
|
+
validator: (value: string) => ['cover', 'contain'].includes(value),
|
|
57
|
+
},
|
|
58
|
+
radius: { ...boxProps.radius, default: 'md' },
|
|
59
|
+
loadingLabel: { type: String, default: 'Loading image' },
|
|
60
|
+
errorLabel: { type: String, default: 'Image unavailable' },
|
|
61
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -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<
|
package/src/vue/index.ts
CHANGED
|
@@ -80,3 +80,7 @@ export * from './workflow-props.js'
|
|
|
80
80
|
export * from './workflows.js'
|
|
81
81
|
export { useRevealState } from './reveal-state.js'
|
|
82
82
|
export type { RevealHost } from './reveal-state.js'
|
|
83
|
+
|
|
84
|
+
export * from './configurator-props.js'
|
|
85
|
+
export * from './configurator.js'
|
|
86
|
+
export { useLoadingDecoration } from './loading-effect.js'
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { watch, onScopeDispose } from '@vue/runtime-core'
|
|
2
|
+
import { markRaw } from '@vue/reactivity'
|
|
3
|
+
import {
|
|
4
|
+
createMotionSurface,
|
|
5
|
+
type MotionLoadingEffect,
|
|
6
|
+
type MotionLoaderOptions,
|
|
7
|
+
} from '../experimental.js'
|
|
8
|
+
|
|
9
|
+
/** Internal decoration; the declared presentation and Jolt own its lifetime. */
|
|
10
|
+
export function useLoadingDecoration(
|
|
11
|
+
settings: () => MotionLoaderOptions & {
|
|
12
|
+
kind: 'shimmer' | 'dots' | 'bars' | 'ring'
|
|
13
|
+
animated: boolean
|
|
14
|
+
},
|
|
15
|
+
) {
|
|
16
|
+
const surface = markRaw(createMotionSurface())
|
|
17
|
+
const off = surface.use((motion) => {
|
|
18
|
+
let resource: MotionLoadingEffect | undefined
|
|
19
|
+
const stop = watch(
|
|
20
|
+
settings,
|
|
21
|
+
(options) => {
|
|
22
|
+
resource?.dispose()
|
|
23
|
+
resource = undefined
|
|
24
|
+
if (!options.animated) return
|
|
25
|
+
resource =
|
|
26
|
+
options.kind === 'shimmer'
|
|
27
|
+
? motion.shimmer({ duration: options.duration })
|
|
28
|
+
: motion.loader({
|
|
29
|
+
style: options.kind,
|
|
30
|
+
size: options.size,
|
|
31
|
+
color: options.color,
|
|
32
|
+
duration: options.duration,
|
|
33
|
+
})
|
|
34
|
+
},
|
|
35
|
+
{ immediate: true },
|
|
36
|
+
)
|
|
37
|
+
return () => {
|
|
38
|
+
stop()
|
|
39
|
+
resource?.dispose()
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
onScopeDispose(off)
|
|
43
|
+
return surface
|
|
44
|
+
}
|
package/src/vue/props.ts
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
} from '../contracts.js'
|
|
17
17
|
import { vueProps, vueProperty } from './contracts.js'
|
|
18
18
|
export type { Align, Justify } from '../contracts.js'
|
|
19
|
-
import type { MotionSurface, MotionScrollSource } from '../experimental.js'
|
|
19
|
+
import type { MotionSurface, MotionScrollSource, MotionRegion } from '../experimental.js'
|
|
20
20
|
import type { AccordionItem } from '../accordion.js'
|
|
21
21
|
import type { SegmentedOption } from '../segmented.js'
|
|
22
22
|
import type { TabOption } from '../tabs.js'
|
|
@@ -166,6 +166,7 @@ export const skeletonProps = {
|
|
|
166
166
|
height: { ...dimensionProp, default: 16 },
|
|
167
167
|
radius: { ...radiusProp, default: 'sm' },
|
|
168
168
|
animated: { type: Boolean, default: true },
|
|
169
|
+
effect: choice(['pulse', 'shimmer'] as const, 'pulse'),
|
|
169
170
|
}
|
|
170
171
|
export const rowProps = vueProps(rowContract)
|
|
171
172
|
export const columnProps = vueProps(columnContract)
|
|
@@ -281,6 +282,8 @@ export const segmentedEmits = radioGroupEmits
|
|
|
281
282
|
export const dialogProps = {
|
|
282
283
|
id: viewProps.id,
|
|
283
284
|
open: Boolean,
|
|
285
|
+
/** Opt-in Web drag presentation. Native retains its existing in-page modal owner. */
|
|
286
|
+
interactive: Boolean,
|
|
284
287
|
title: { type: String, required: true as const },
|
|
285
288
|
description: { type: String, default: '' },
|
|
286
289
|
confirmLabel: { type: String, default: 'Continue' },
|
|
@@ -319,6 +322,9 @@ export const inputEmits = {
|
|
|
319
322
|
}
|
|
320
323
|
export const iconProps = {
|
|
321
324
|
id: viewProps.id,
|
|
325
|
+
motionSurface: { type: Object as PropType<MotionSurface>, default: undefined },
|
|
326
|
+
/** Optional native iOS SF Symbol artwork; name remains the portable fallback. */
|
|
327
|
+
systemName: { type: String, default: undefined },
|
|
322
328
|
name: { type: String as PropType<IconName>, required: true as const },
|
|
323
329
|
size: {
|
|
324
330
|
type: [String, Number] as PropType<IconSize>,
|
|
@@ -330,6 +336,7 @@ export const iconProps = {
|
|
|
330
336
|
label: { type: String, default: undefined },
|
|
331
337
|
}
|
|
332
338
|
export const screenProps = {
|
|
339
|
+
motionRegion: { type: Object as PropType<MotionRegion>, default: undefined },
|
|
333
340
|
motionScroll: { type: Object as PropType<MotionScrollSource>, default: undefined },
|
|
334
341
|
...viewProps,
|
|
335
342
|
scroll: Boolean,
|