@getcortexlabs/mavis-core 0.1.0-alpha.6 → 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/capabilities.d.ts +5 -5
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +5 -2
- 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/experimental.d.ts +9 -2
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +23 -4
- 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 +247 -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/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 +2 -0
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +2 -0
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/workflows.d.ts +1 -1
- package/package.json +1 -1
- package/src/capabilities.ts +5 -2
- package/src/choice-motion.ts +12 -0
- package/src/experimental.ts +58 -12
- 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 +59 -0
- package/src/vue/configurator.ts +350 -0
- package/src/vue/global-components.ts +16 -0
- package/src/vue/index.ts +3 -0
|
@@ -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