@getcortexlabs/mavis-core 0.1.0-alpha.4 → 0.1.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/capabilities.d.ts +119 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +142 -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 +1201 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +242 -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-regions.d.ts +142 -0
- package/dist/experimental-regions.d.ts.map +1 -0
- package/dist/experimental-regions.js +315 -0
- package/dist/experimental-regions.js.map +1 -0
- package/dist/experimental.d.ts +13 -1
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +153 -23
- 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 +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.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/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 +1989 -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 +18 -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 +927 -0
- package/dist/vue/date-picker.d.ts.map +1 -0
- package/dist/vue/date-picker.js +319 -0
- package/dist/vue/date-picker.js.map +1 -0
- package/dist/vue/date-props.d.ts +254 -0
- package/dist/vue/date-props.d.ts.map +1 -0
- package/dist/vue/date-props.js +74 -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 +35 -2
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/index.d.ts +12 -2
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +10 -1
- 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/props.d.ts +1026 -495
- package/dist/vue/props.d.ts.map +1 -1
- package/dist/vue/props.js +17 -118
- package/dist/vue/props.js.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/capabilities.ts +145 -0
- package/src/combobox.ts +198 -0
- package/src/contracts.ts +295 -0
- package/src/date.ts +280 -0
- package/src/experimental-regions.ts +463 -0
- package/src/experimental.ts +158 -16
- package/src/files.ts +408 -0
- package/src/form.ts +190 -0
- package/src/index.ts +17 -0
- package/src/navigation.ts +61 -0
- package/src/vue/combobox.ts +238 -0
- package/src/vue/component-props.ts +24 -0
- package/src/vue/contracts.ts +33 -0
- package/src/vue/date-calendar.ts +76 -0
- package/src/vue/date-picker.ts +387 -0
- package/src/vue/date-props.ts +81 -0
- package/src/vue/files.ts +53 -0
- package/src/vue/forms.ts +20 -0
- package/src/vue/global-components.ts +44 -2
- package/src/vue/index.ts +13 -2
- package/src/vue/props.ts +34 -130
- package/src/vue/workflow-props.ts +41 -0
- package/src/vue/workflows.ts +257 -0
package/src/vue/props.ts
CHANGED
|
@@ -1,15 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
viewContract,
|
|
3
|
+
flexContract,
|
|
4
|
+
boxContract,
|
|
5
|
+
motionBoxContract,
|
|
6
|
+
rowContract,
|
|
7
|
+
columnContract,
|
|
8
|
+
buttonContract,
|
|
9
|
+
textContract,
|
|
10
|
+
inputContract,
|
|
11
|
+
spacingProperty,
|
|
12
|
+
radiusProperty,
|
|
13
|
+
dimensionProperty,
|
|
14
|
+
weightProperty,
|
|
15
|
+
paletteTones,
|
|
16
|
+
} from '../contracts.js'
|
|
17
|
+
import { vueProps, vueProperty } from './contracts.js'
|
|
18
|
+
export type { Align, Justify } from '../contracts.js'
|
|
1
19
|
import type { MotionSurface, MotionScrollSource } from '../experimental.js'
|
|
2
20
|
import type { AccordionItem } from '../accordion.js'
|
|
3
21
|
import type { SegmentedOption } from '../segmented.js'
|
|
4
22
|
import type { TabOption } from '../tabs.js'
|
|
5
|
-
import type { InputAction } from '../input.js'
|
|
6
23
|
import type { SheetName } from '../sheet.js'
|
|
7
24
|
import { dialogCloseReasons, type DialogCloseReason } from '../dialog.js'
|
|
8
25
|
import type { ExtractPropTypes, ExtractPublicPropTypes, PropType } from '@vue/runtime-core'
|
|
9
|
-
import type { Palette,
|
|
26
|
+
import type { Palette, Elevation } from '../theme/types.js'
|
|
10
27
|
import { isChoiceValue, type ChoiceValue, type ChoiceOption } from '../choice.js'
|
|
11
28
|
import type { ToastController } from '../toast.js'
|
|
12
|
-
import type { Dimension } from '../layout.js'
|
|
13
29
|
import { iconSizes, type IconName, type IconSize } from '../icon.js'
|
|
14
30
|
import { sheetCloseReasons, type SheetCloseReason } from '../sheet.js'
|
|
15
31
|
|
|
@@ -21,15 +37,10 @@ function choice<T extends string>(values: readonly T[], defaultValue: T) {
|
|
|
21
37
|
}
|
|
22
38
|
}
|
|
23
39
|
|
|
24
|
-
export const spacingProp =
|
|
25
|
-
const radiusProp =
|
|
26
|
-
const dimensionProp =
|
|
27
|
-
|
|
28
|
-
export const viewProps = {
|
|
29
|
-
id: { type: String, default: undefined },
|
|
30
|
-
accessibilityLabel: { type: String, default: undefined },
|
|
31
|
-
accessibilityHidden: { type: Boolean, default: undefined },
|
|
32
|
-
}
|
|
40
|
+
export const spacingProp = vueProperty(spacingProperty)
|
|
41
|
+
const radiusProp = vueProperty(radiusProperty)
|
|
42
|
+
const dimensionProp = vueProperty(dimensionProperty)
|
|
43
|
+
export const viewProps = vueProps(viewContract)
|
|
33
44
|
|
|
34
45
|
export function viewAttrs(props: ExtractPropTypes<typeof viewProps>) {
|
|
35
46
|
return {
|
|
@@ -39,21 +50,9 @@ export function viewAttrs(props: ExtractPropTypes<typeof viewProps>) {
|
|
|
39
50
|
}
|
|
40
51
|
}
|
|
41
52
|
|
|
42
|
-
export const flexProps =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
export const boxProps = {
|
|
47
|
-
...viewProps,
|
|
48
|
-
...flexProps,
|
|
49
|
-
padding: spacingProp,
|
|
50
|
-
paddingX: spacingProp,
|
|
51
|
-
paddingY: spacingProp,
|
|
52
|
-
radius: radiusProp,
|
|
53
|
-
width: dimensionProp,
|
|
54
|
-
height: dimensionProp,
|
|
55
|
-
backgroundColor: String,
|
|
56
|
-
}
|
|
53
|
+
export const flexProps = vueProps(flexContract)
|
|
54
|
+
export const boxProps = vueProps(boxContract)
|
|
55
|
+
export const motionBoxProps = vueProps(motionBoxContract)
|
|
57
56
|
export const listItemProps = {
|
|
58
57
|
...viewProps,
|
|
59
58
|
...flexProps,
|
|
@@ -150,23 +149,8 @@ export const skeletonProps = {
|
|
|
150
149
|
radius: { ...radiusProp, default: 'sm' },
|
|
151
150
|
animated: { type: Boolean, default: true },
|
|
152
151
|
}
|
|
153
|
-
export
|
|
154
|
-
export
|
|
155
|
-
|
|
156
|
-
function layoutProps(direction: 'row' | 'column') {
|
|
157
|
-
return {
|
|
158
|
-
...boxProps,
|
|
159
|
-
gap: spacingProp,
|
|
160
|
-
align: choice<Align>(
|
|
161
|
-
['start', 'center', 'end', 'stretch'],
|
|
162
|
-
direction === 'row' ? 'center' : 'stretch',
|
|
163
|
-
),
|
|
164
|
-
justify: choice<Justify>(['start', 'center', 'end', 'between', 'around'], 'start'),
|
|
165
|
-
wrap: Boolean,
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
export const rowProps = layoutProps('row')
|
|
169
|
-
export const columnProps = layoutProps('column')
|
|
152
|
+
export const rowProps = vueProps(rowContract)
|
|
153
|
+
export const columnProps = vueProps(columnContract)
|
|
170
154
|
export const cardProps = {
|
|
171
155
|
motionSurface: { type: Object as PropType<MotionSurface>, default: undefined },
|
|
172
156
|
...boxProps,
|
|
@@ -177,59 +161,16 @@ export const cardProps = {
|
|
|
177
161
|
interactive: Boolean,
|
|
178
162
|
disabled: Boolean,
|
|
179
163
|
}
|
|
180
|
-
export const buttonProps =
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
...flexProps,
|
|
184
|
-
text: { type: String, default: undefined },
|
|
185
|
-
// HTML form behavior; NativeScript buttons remain application actions.
|
|
186
|
-
type: choice(['button', 'submit', 'reset'] as const, 'button'),
|
|
187
|
-
name: { type: String, default: undefined },
|
|
188
|
-
value: { type: String, default: undefined },
|
|
189
|
-
form: { type: String, default: undefined },
|
|
190
|
-
variant: choice(['primary', 'secondary', 'ghost'] as const, 'primary'),
|
|
191
|
-
size: choice(['sm', 'md', 'lg'] as const, 'md'),
|
|
192
|
-
disabled: Boolean,
|
|
193
|
-
loading: Boolean,
|
|
194
|
-
loadingText: { type: String, default: 'Loading…' },
|
|
195
|
-
icon: { type: String as PropType<IconName>, default: undefined },
|
|
196
|
-
trailingIcon: { type: String as PropType<IconName>, default: undefined },
|
|
197
|
-
}
|
|
198
|
-
const tones: readonly (keyof Palette)[] = [
|
|
199
|
-
'background',
|
|
200
|
-
'surface',
|
|
201
|
-
'elevated',
|
|
202
|
-
'text',
|
|
203
|
-
'muted',
|
|
204
|
-
'primary',
|
|
205
|
-
'onPrimary',
|
|
206
|
-
'primarySoft',
|
|
207
|
-
'accent',
|
|
208
|
-
'onAccent',
|
|
209
|
-
'accentSoft',
|
|
210
|
-
'border',
|
|
211
|
-
'warning',
|
|
212
|
-
'success',
|
|
213
|
-
'danger',
|
|
214
|
-
]
|
|
215
|
-
export const weightProp = { type: String as PropType<FontWeight>, default: undefined }
|
|
164
|
+
export const buttonProps = vueProps(buttonContract)
|
|
165
|
+
const tones = paletteTones
|
|
166
|
+
export const weightProp = vueProperty(weightProperty)
|
|
216
167
|
export const spanProps = {
|
|
217
168
|
text: { type: String, default: undefined },
|
|
218
169
|
weight: weightProp,
|
|
219
170
|
tone: { type: String as PropType<keyof Palette>, default: undefined },
|
|
220
171
|
emphasis: { type: String as PropType<'strong' | 'em'>, default: undefined },
|
|
221
172
|
}
|
|
222
|
-
export const textProps =
|
|
223
|
-
weight: weightProp,
|
|
224
|
-
...viewProps,
|
|
225
|
-
...flexProps,
|
|
226
|
-
text: { type: String, default: undefined },
|
|
227
|
-
as: choice(['p', 'span', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'] as const, 'p'),
|
|
228
|
-
variant: choice(['display', 'title', 'heading', 'body', 'caption', 'overline'] as const, 'body'),
|
|
229
|
-
tone: choice<keyof Palette>(tones, 'text'),
|
|
230
|
-
align: choice(['left', 'center', 'right'] as const, 'left'),
|
|
231
|
-
wrap: { type: Boolean, default: true },
|
|
232
|
-
}
|
|
173
|
+
export const textProps = vueProps(textContract)
|
|
233
174
|
export const sliderProps = {
|
|
234
175
|
id: viewProps.id,
|
|
235
176
|
accessibilityHidden: viewProps.accessibilityHidden,
|
|
@@ -344,44 +285,7 @@ export const selectProps = {
|
|
|
344
285
|
emptyText: { type: String, default: 'No options available' },
|
|
345
286
|
}
|
|
346
287
|
export const selectEmits = radioGroupEmits
|
|
347
|
-
export const inputProps =
|
|
348
|
-
id: viewProps.id,
|
|
349
|
-
accessibilityHidden: viewProps.accessibilityHidden,
|
|
350
|
-
...flexProps,
|
|
351
|
-
width: dimensionProp,
|
|
352
|
-
modelValue: { type: String, default: '' },
|
|
353
|
-
label: { type: String, required: true as const },
|
|
354
|
-
placeholder: { type: String, default: '' },
|
|
355
|
-
helperText: { type: String, default: '' },
|
|
356
|
-
error: { type: String, default: '' },
|
|
357
|
-
type: choice(['text', 'email', 'password', 'tel', 'url', 'search'] as const, 'text'),
|
|
358
|
-
// Browser editor attributes. NativeScript has no HTML form owner.
|
|
359
|
-
name: { type: String, default: undefined },
|
|
360
|
-
autocomplete: { type: String, default: undefined },
|
|
361
|
-
required: Boolean,
|
|
362
|
-
inputmode: {
|
|
363
|
-
type: String as PropType<
|
|
364
|
-
'none' | 'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url'
|
|
365
|
-
>,
|
|
366
|
-
default: undefined,
|
|
367
|
-
},
|
|
368
|
-
form: { type: String, default: undefined },
|
|
369
|
-
disabled: Boolean,
|
|
370
|
-
readonly: Boolean,
|
|
371
|
-
multiline: Boolean,
|
|
372
|
-
rows: { type: Number, default: 3 },
|
|
373
|
-
maxLength: { type: Number, default: undefined },
|
|
374
|
-
autocapitalize: {
|
|
375
|
-
type: String as PropType<'none' | 'sentences' | 'words' | 'characters'>,
|
|
376
|
-
default: undefined,
|
|
377
|
-
validator: (value: string) => ['none', 'sentences', 'words', 'characters'].includes(value),
|
|
378
|
-
},
|
|
379
|
-
autocorrect: { type: Boolean, default: undefined },
|
|
380
|
-
returnKey: choice(['done', 'next', 'go', 'search', 'send'] as const, 'done'),
|
|
381
|
-
trailingAction: { type: Object as PropType<InputAction>, default: undefined },
|
|
382
|
-
icon: { type: String as PropType<IconName>, default: undefined },
|
|
383
|
-
trailingIcon: { type: String as PropType<IconName>, default: undefined },
|
|
384
|
-
}
|
|
288
|
+
export const inputProps = vueProps(inputContract)
|
|
385
289
|
export const inputEmits = {
|
|
386
290
|
action: () => true,
|
|
387
291
|
'update:modelValue': (value: string) => typeof value === 'string',
|
|
@@ -435,7 +339,7 @@ export const componentProps = {
|
|
|
435
339
|
MScreen: screenProps,
|
|
436
340
|
MRow: rowProps,
|
|
437
341
|
MColumn: columnProps,
|
|
438
|
-
MBox:
|
|
342
|
+
MBox: motionBoxProps,
|
|
439
343
|
MCard: cardProps,
|
|
440
344
|
MText: textProps,
|
|
441
345
|
MButton: buttonProps,
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { PropType } from '@vue/runtime-core'
|
|
2
|
+
import type { FormController } from '../form.js'
|
|
3
|
+
import type { StepOption } from '../navigation.js'
|
|
4
|
+
import type { ChoiceValue } from '../choice.js'
|
|
5
|
+
|
|
6
|
+
export const formGroupProps = {
|
|
7
|
+
label: { type: String, required: true as const },
|
|
8
|
+
description: { type: String, default: '' },
|
|
9
|
+
id: { type: String, default: undefined },
|
|
10
|
+
}
|
|
11
|
+
export const formErrorsProps = {
|
|
12
|
+
form: { type: Object as PropType<FormController>, required: true as const },
|
|
13
|
+
title: { type: String, default: 'Review these fields' },
|
|
14
|
+
announce: Boolean,
|
|
15
|
+
}
|
|
16
|
+
export const stepsProps = {
|
|
17
|
+
steps: { type: Array as PropType<readonly StepOption[]>, required: true as const },
|
|
18
|
+
modelValue: { type: [String, Number] as PropType<ChoiceValue | null>, default: null },
|
|
19
|
+
label: { type: String, required: true as const },
|
|
20
|
+
disabled: Boolean,
|
|
21
|
+
loading: Boolean,
|
|
22
|
+
currentLabel: { type: String, default: 'Current' },
|
|
23
|
+
completeLabel: { type: String, default: 'Complete' },
|
|
24
|
+
errorLabel: { type: String, default: 'Needs attention' },
|
|
25
|
+
}
|
|
26
|
+
export const paginationProps = {
|
|
27
|
+
modelValue: { type: Number, default: 1 },
|
|
28
|
+
total: { type: Number, required: true as const },
|
|
29
|
+
pageSize: { type: Number, default: 20 },
|
|
30
|
+
siblingCount: { type: Number, default: 1 },
|
|
31
|
+
label: { type: String, default: 'Result pages' },
|
|
32
|
+
previousLabel: { type: String, default: 'Previous' },
|
|
33
|
+
nextLabel: { type: String, default: 'Next' },
|
|
34
|
+
pageLabel: { type: String, default: 'Page' },
|
|
35
|
+
currentLabel: { type: String, default: 'Current' },
|
|
36
|
+
statusText: { type: String, default: '' },
|
|
37
|
+
emptyLabel: { type: String, default: 'No results' },
|
|
38
|
+
invalidPageLabel: { type: String, default: 'This page is no longer available.' },
|
|
39
|
+
loading: Boolean,
|
|
40
|
+
disabled: Boolean,
|
|
41
|
+
}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineComponent,
|
|
3
|
+
h,
|
|
4
|
+
mergeProps,
|
|
5
|
+
shallowRef,
|
|
6
|
+
watch,
|
|
7
|
+
onScopeDispose,
|
|
8
|
+
onBeforeUpdate,
|
|
9
|
+
onUpdated,
|
|
10
|
+
nextTick,
|
|
11
|
+
useId,
|
|
12
|
+
type Component,
|
|
13
|
+
} from '@vue/runtime-core'
|
|
14
|
+
import { choiceKey, type ChoiceValue } from '../choice.js'
|
|
15
|
+
import { pagination, validateSteps } from '../navigation.js'
|
|
16
|
+
import { formErrorsProps, formGroupProps, stepsProps, paginationProps } from './workflow-props.js'
|
|
17
|
+
import { useMavisTheme } from './theme.js'
|
|
18
|
+
|
|
19
|
+
interface Primitives {
|
|
20
|
+
Column: Component
|
|
21
|
+
Row: Component
|
|
22
|
+
Text: Component
|
|
23
|
+
Button: Component
|
|
24
|
+
preserveFocus?: (root: unknown, currentId: string) => () => void
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Composed controls share behavior; each supplied primitive owns its platform rendering. */
|
|
28
|
+
export function createWorkflows(ui: Primitives, platform: 'web' | 'native') {
|
|
29
|
+
const MFormGroup = defineComponent({
|
|
30
|
+
name: 'MFormGroup',
|
|
31
|
+
inheritAttrs: false,
|
|
32
|
+
props: formGroupProps,
|
|
33
|
+
setup(props, { attrs, slots }) {
|
|
34
|
+
const generatedId = `m-form-group-${useId()}`
|
|
35
|
+
return () => {
|
|
36
|
+
if (!props.label.trim()) throw new TypeError('Form groups require a visible label.')
|
|
37
|
+
const id = props.id ?? generatedId
|
|
38
|
+
return h(
|
|
39
|
+
ui.Column,
|
|
40
|
+
mergeProps(
|
|
41
|
+
{ gap: 'md', id },
|
|
42
|
+
attrs,
|
|
43
|
+
platform === 'web'
|
|
44
|
+
? {
|
|
45
|
+
role: 'group',
|
|
46
|
+
'aria-labelledby': `${id}-label`,
|
|
47
|
+
'aria-describedby': props.description ? `${id}-description` : undefined,
|
|
48
|
+
}
|
|
49
|
+
: {},
|
|
50
|
+
),
|
|
51
|
+
() => [
|
|
52
|
+
h(ui.Text, { id: `${id}-label`, as: 'h2', variant: 'heading', text: props.label }),
|
|
53
|
+
props.description
|
|
54
|
+
? h(ui.Text, { id: `${id}-description`, tone: 'muted', text: props.description })
|
|
55
|
+
: null,
|
|
56
|
+
slots.default?.(),
|
|
57
|
+
],
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
const MFormErrors = defineComponent({
|
|
63
|
+
name: 'MFormErrors',
|
|
64
|
+
inheritAttrs: false,
|
|
65
|
+
props: formErrorsProps,
|
|
66
|
+
emits: { focus: (_field: string, _focused: boolean) => true },
|
|
67
|
+
setup(props, { attrs, emit }) {
|
|
68
|
+
const { theme } = useMavisTheme()
|
|
69
|
+
const id = `m-form-errors-${useId()}`
|
|
70
|
+
const revision = shallowRef(0)
|
|
71
|
+
let release: (() => void) | undefined
|
|
72
|
+
watch(
|
|
73
|
+
() => props.form,
|
|
74
|
+
(form) => {
|
|
75
|
+
release?.()
|
|
76
|
+
release = form.subscribe(() => {
|
|
77
|
+
revision.value++
|
|
78
|
+
})
|
|
79
|
+
revision.value++
|
|
80
|
+
},
|
|
81
|
+
{ immediate: true },
|
|
82
|
+
)
|
|
83
|
+
onScopeDispose(() => release?.())
|
|
84
|
+
return () => {
|
|
85
|
+
void revision.value
|
|
86
|
+
const { errors } = props.form.state
|
|
87
|
+
if (!errors.length) return null
|
|
88
|
+
return h(
|
|
89
|
+
ui.Column,
|
|
90
|
+
mergeProps(
|
|
91
|
+
{ gap: 'sm', padding: 'md', radius: 'md', backgroundColor: theme.value.colors.surface },
|
|
92
|
+
attrs,
|
|
93
|
+
platform === 'web'
|
|
94
|
+
? { role: props.announce ? 'alert' : 'region', 'aria-labelledby': id }
|
|
95
|
+
: {},
|
|
96
|
+
),
|
|
97
|
+
() => [
|
|
98
|
+
h(ui.Text, { id, as: 'h2', variant: 'heading', tone: 'danger', text: props.title }),
|
|
99
|
+
...errors.map((error, index) =>
|
|
100
|
+
h(ui.Button, {
|
|
101
|
+
key: `${error.field}:${index}`,
|
|
102
|
+
variant: 'ghost',
|
|
103
|
+
disabled: !props.form.has(error.field),
|
|
104
|
+
text: props.form.label(error.field)
|
|
105
|
+
? `${props.form.label(error.field)}: ${error.message}`
|
|
106
|
+
: error.message,
|
|
107
|
+
onClick: async () => {
|
|
108
|
+
emit('focus', error.field, await props.form.focusError(error.field))
|
|
109
|
+
},
|
|
110
|
+
}),
|
|
111
|
+
),
|
|
112
|
+
],
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
})
|
|
117
|
+
const MSteps = defineComponent({
|
|
118
|
+
name: 'MSteps',
|
|
119
|
+
inheritAttrs: false,
|
|
120
|
+
props: stepsProps,
|
|
121
|
+
emits: { 'update:modelValue': (_value: ChoiceValue) => true },
|
|
122
|
+
setup(props, { attrs, emit }) {
|
|
123
|
+
return () => {
|
|
124
|
+
if (!props.label.trim()) throw new TypeError('Steps require a navigation label.')
|
|
125
|
+
validateSteps(props.steps, props.modelValue)
|
|
126
|
+
return h(
|
|
127
|
+
ui.Row,
|
|
128
|
+
mergeProps(
|
|
129
|
+
{ gap: 'sm', wrap: true },
|
|
130
|
+
attrs,
|
|
131
|
+
platform === 'web' ? { role: 'navigation', 'aria-label': props.label } : {},
|
|
132
|
+
),
|
|
133
|
+
() =>
|
|
134
|
+
props.steps.map((step, index) => {
|
|
135
|
+
const current = step.value === props.modelValue
|
|
136
|
+
const status = [
|
|
137
|
+
current ? props.currentLabel : '',
|
|
138
|
+
step.status === 'error'
|
|
139
|
+
? props.errorLabel
|
|
140
|
+
: step.status === 'complete'
|
|
141
|
+
? props.completeLabel
|
|
142
|
+
: '',
|
|
143
|
+
]
|
|
144
|
+
.filter(Boolean)
|
|
145
|
+
.join(' · ')
|
|
146
|
+
return h(ui.Column, { key: choiceKey(step.value), gap: 'xs', grow: 1 }, () => [
|
|
147
|
+
h(ui.Button, {
|
|
148
|
+
text: `${index + 1}. ${step.label}`,
|
|
149
|
+
variant: current ? 'primary' : 'secondary',
|
|
150
|
+
disabled: props.disabled || step.disabled || (props.loading && !current),
|
|
151
|
+
loading: props.loading && current,
|
|
152
|
+
accessibilityLabel: `${index + 1}. ${step.label}${status ? `. ${status}` : ''}`,
|
|
153
|
+
...(platform === 'web' ? { 'aria-current': current ? 'step' : undefined } : {}),
|
|
154
|
+
onClick: () => {
|
|
155
|
+
if (!props.disabled && !props.loading && !step.disabled && !current)
|
|
156
|
+
emit('update:modelValue', step.value)
|
|
157
|
+
},
|
|
158
|
+
}),
|
|
159
|
+
status
|
|
160
|
+
? h(ui.Text, {
|
|
161
|
+
variant: 'caption',
|
|
162
|
+
tone: step.status === 'error' ? 'danger' : 'muted',
|
|
163
|
+
text: status,
|
|
164
|
+
})
|
|
165
|
+
: null,
|
|
166
|
+
])
|
|
167
|
+
}),
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
})
|
|
172
|
+
const MPagination = defineComponent({
|
|
173
|
+
name: 'MPagination',
|
|
174
|
+
inheritAttrs: false,
|
|
175
|
+
props: paginationProps,
|
|
176
|
+
emits: { 'update:modelValue': (_page: number) => true },
|
|
177
|
+
setup(props, { attrs, emit }) {
|
|
178
|
+
const root = shallowRef<unknown>()
|
|
179
|
+
const id = `m-pagination-${useId()}`
|
|
180
|
+
let restore = () => {}
|
|
181
|
+
onBeforeUpdate(() => {
|
|
182
|
+
restore = ui.preserveFocus?.(root.value, `${id}-page-${props.modelValue}`) ?? (() => {})
|
|
183
|
+
})
|
|
184
|
+
onUpdated(() => {
|
|
185
|
+
const apply = restore
|
|
186
|
+
void nextTick(apply)
|
|
187
|
+
})
|
|
188
|
+
const request = (page: number | null) => {
|
|
189
|
+
if (page !== null && page !== props.modelValue && !props.disabled && !props.loading)
|
|
190
|
+
emit('update:modelValue', page)
|
|
191
|
+
}
|
|
192
|
+
return () => {
|
|
193
|
+
if (!props.label.trim()) throw new TypeError('Pagination requires a navigation label.')
|
|
194
|
+
const state = pagination(props.total, props.pageSize, props.modelValue, props.siblingCount)
|
|
195
|
+
return h(
|
|
196
|
+
ui.Column,
|
|
197
|
+
mergeProps(
|
|
198
|
+
{ gap: 'sm', ref: root },
|
|
199
|
+
attrs,
|
|
200
|
+
platform === 'web' ? { role: 'navigation', 'aria-label': props.label } : {},
|
|
201
|
+
),
|
|
202
|
+
() => [
|
|
203
|
+
props.statusText
|
|
204
|
+
? h(ui.Text, {
|
|
205
|
+
text: props.statusText,
|
|
206
|
+
variant: 'caption',
|
|
207
|
+
tone: 'muted',
|
|
208
|
+
...(platform === 'web'
|
|
209
|
+
? { role: 'status', 'aria-live': 'polite', 'aria-atomic': 'true' }
|
|
210
|
+
: { accessibilityLiveRegion: 'polite' }),
|
|
211
|
+
})
|
|
212
|
+
: null,
|
|
213
|
+
state.count === 0 ? h(ui.Text, { tone: 'muted', text: props.emptyLabel }) : null,
|
|
214
|
+
state.outOfRange ? h(ui.Text, { tone: 'danger', text: props.invalidPageLabel }) : null,
|
|
215
|
+
h(ui.Row, { gap: 'sm', wrap: true }, () => [
|
|
216
|
+
h(ui.Button, {
|
|
217
|
+
variant: 'secondary',
|
|
218
|
+
text: props.previousLabel,
|
|
219
|
+
disabled: props.disabled || state.previous === null,
|
|
220
|
+
loading: props.loading,
|
|
221
|
+
loadingText: props.previousLabel,
|
|
222
|
+
onClick: () => request(state.previous),
|
|
223
|
+
}),
|
|
224
|
+
...state.items.map((item) =>
|
|
225
|
+
item.kind === 'gap'
|
|
226
|
+
? h(ui.Text, { key: item.key, text: '…', accessibilityHidden: true })
|
|
227
|
+
: h(ui.Button, {
|
|
228
|
+
key: item.page,
|
|
229
|
+
text: String(item.page),
|
|
230
|
+
accessibilityLabel: `${props.pageLabel} ${item.page}${platform === 'native' && item.page === props.modelValue ? `. ${props.currentLabel}` : ''}`,
|
|
231
|
+
variant: item.page === props.modelValue ? 'primary' : 'ghost',
|
|
232
|
+
id: `${id}-page-${item.page}`,
|
|
233
|
+
disabled: props.disabled,
|
|
234
|
+
loading: props.loading,
|
|
235
|
+
loadingText: String(item.page),
|
|
236
|
+
...(platform === 'web'
|
|
237
|
+
? { 'aria-current': item.page === props.modelValue ? 'page' : undefined }
|
|
238
|
+
: {}),
|
|
239
|
+
onClick: () => request(item.page),
|
|
240
|
+
}),
|
|
241
|
+
),
|
|
242
|
+
h(ui.Button, {
|
|
243
|
+
variant: 'secondary',
|
|
244
|
+
text: props.nextLabel,
|
|
245
|
+
disabled: props.disabled || state.next === null,
|
|
246
|
+
loading: props.loading,
|
|
247
|
+
loadingText: props.nextLabel,
|
|
248
|
+
onClick: () => request(state.next),
|
|
249
|
+
}),
|
|
250
|
+
]),
|
|
251
|
+
],
|
|
252
|
+
)
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
})
|
|
256
|
+
return { MFormGroup, MFormErrors, MSteps, MPagination }
|
|
257
|
+
}
|