@getcortexlabs/mavis-core 0.1.0-alpha.4 → 0.1.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/app-icons.d.ts +27 -0
- package/dist/app-icons.d.ts.map +1 -0
- package/dist/app-icons.js +42 -0
- package/dist/app-icons.js.map +1 -0
- package/dist/capabilities.d.ts +119 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +144 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/combobox.d.ts +42 -0
- package/dist/combobox.d.ts.map +1 -0
- package/dist/combobox.js +159 -0
- package/dist/combobox.js.map +1 -0
- package/dist/contracts.d.ts +1261 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +249 -0
- package/dist/contracts.js.map +1 -0
- package/dist/date.d.ts +96 -0
- package/dist/date.d.ts.map +1 -0
- package/dist/date.js +235 -0
- package/dist/date.js.map +1 -0
- package/dist/experimental-playback.d.ts +63 -0
- package/dist/experimental-playback.d.ts.map +1 -0
- package/dist/experimental-playback.js +46 -0
- package/dist/experimental-playback.js.map +1 -0
- package/dist/experimental-regions.d.ts +154 -0
- package/dist/experimental-regions.d.ts.map +1 -0
- package/dist/experimental-regions.js +440 -0
- package/dist/experimental-regions.js.map +1 -0
- package/dist/experimental.d.ts +42 -3
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +200 -30
- package/dist/experimental.js.map +1 -1
- package/dist/files.d.ts +87 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +328 -0
- package/dist/files.js.map +1 -0
- package/dist/form.d.ts +39 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/form.js +170 -0
- package/dist/form.js.map +1 -0
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/link.d.ts +12 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +19 -0
- package/dist/link.js.map +1 -0
- package/dist/motion.d.ts +29 -4
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +55 -3
- package/dist/motion.js.map +1 -1
- package/dist/navigation.d.ts +22 -0
- package/dist/navigation.d.ts.map +1 -0
- package/dist/navigation.js +54 -0
- package/dist/navigation.js.map +1 -0
- package/dist/responsive.d.ts +18 -0
- package/dist/responsive.d.ts.map +1 -0
- package/dist/responsive.js +35 -0
- package/dist/responsive.js.map +1 -0
- package/dist/theme/themes.js +3 -3
- package/dist/theme/themes.js.map +1 -1
- package/dist/theme/types.d.ts +12 -3
- package/dist/theme/types.d.ts.map +1 -1
- package/dist/vue/combobox.d.ts +155 -0
- package/dist/vue/combobox.d.ts.map +1 -0
- package/dist/vue/combobox.js +195 -0
- package/dist/vue/combobox.js.map +1 -0
- package/dist/vue/component-props.d.ts +2176 -0
- package/dist/vue/component-props.d.ts.map +1 -0
- package/dist/vue/component-props.js +18 -0
- package/dist/vue/component-props.js.map +1 -0
- package/dist/vue/contracts.d.ts +18 -0
- package/dist/vue/contracts.d.ts.map +1 -0
- package/dist/vue/contracts.js +24 -0
- package/dist/vue/contracts.js.map +1 -0
- package/dist/vue/date-calendar.d.ts +64 -0
- package/dist/vue/date-calendar.d.ts.map +1 -0
- package/dist/vue/date-calendar.js +65 -0
- package/dist/vue/date-calendar.js.map +1 -0
- package/dist/vue/date-picker.d.ts +965 -0
- package/dist/vue/date-picker.d.ts.map +1 -0
- package/dist/vue/date-picker.js +341 -0
- package/dist/vue/date-picker.js.map +1 -0
- package/dist/vue/date-props.d.ts +263 -0
- package/dist/vue/date-props.d.ts.map +1 -0
- package/dist/vue/date-props.js +77 -0
- package/dist/vue/date-props.js.map +1 -0
- package/dist/vue/files.d.ts +53 -0
- package/dist/vue/files.d.ts.map +1 -0
- package/dist/vue/files.js +40 -0
- package/dist/vue/files.js.map +1 -0
- package/dist/vue/forms.d.ts +4 -0
- package/dist/vue/forms.d.ts.map +1 -0
- package/dist/vue/forms.js +15 -0
- package/dist/vue/forms.js.map +1 -0
- package/dist/vue/global-components.d.ts +40 -2
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/index.d.ts +15 -3
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +12 -2
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/inline-content.d.ts +3 -1
- package/dist/vue/inline-content.d.ts.map +1 -1
- package/dist/vue/layout-context.d.ts +4 -2
- package/dist/vue/layout-context.d.ts.map +1 -1
- package/dist/vue/layout-context.js +7 -2
- package/dist/vue/layout-context.js.map +1 -1
- package/dist/vue/props.d.ts +1392 -496
- package/dist/vue/props.d.ts.map +1 -1
- package/dist/vue/props.js +39 -116
- package/dist/vue/props.js.map +1 -1
- package/dist/vue/reveal-state.d.ts +18 -0
- package/dist/vue/reveal-state.d.ts.map +1 -0
- package/dist/vue/reveal-state.js +76 -0
- package/dist/vue/reveal-state.js.map +1 -0
- package/dist/vue/theme.d.ts +42 -0
- package/dist/vue/theme.d.ts.map +1 -1
- package/dist/vue/workflow-props.d.ts +110 -0
- package/dist/vue/workflow-props.d.ts.map +1 -0
- package/dist/vue/workflow-props.js +37 -0
- package/dist/vue/workflow-props.js.map +1 -0
- package/dist/vue/workflows.d.ts +267 -0
- package/dist/vue/workflows.d.ts.map +1 -0
- package/dist/vue/workflows.js +200 -0
- package/dist/vue/workflows.js.map +1 -0
- package/package.json +1 -1
- package/src/app-icons.ts +57 -0
- package/src/capabilities.ts +147 -0
- package/src/combobox.ts +198 -0
- package/src/contracts.ts +305 -0
- package/src/date.ts +280 -0
- package/src/experimental-playback.ts +115 -0
- package/src/experimental-regions.ts +614 -0
- package/src/experimental.ts +239 -25
- package/src/files.ts +408 -0
- package/src/form.ts +190 -0
- package/src/index.ts +23 -1
- package/src/link.ts +28 -0
- package/src/motion.ts +61 -3
- package/src/navigation.ts +61 -0
- package/src/responsive.ts +61 -0
- package/src/theme/themes.ts +3 -3
- package/src/theme/types.ts +13 -1
- package/src/vue/combobox.ts +238 -0
- package/src/vue/component-props.ts +24 -0
- package/src/vue/contracts.ts +39 -0
- package/src/vue/date-calendar.ts +76 -0
- package/src/vue/date-picker.ts +414 -0
- package/src/vue/date-props.ts +84 -0
- package/src/vue/files.ts +53 -0
- package/src/vue/forms.ts +20 -0
- package/src/vue/global-components.ts +49 -3
- package/src/vue/index.ts +19 -3
- package/src/vue/layout-context.ts +10 -3
- package/src/vue/props.ts +57 -127
- package/src/vue/reveal-state.ts +83 -0
- package/src/vue/workflow-props.ts +41 -0
- package/src/vue/workflows.ts +257 -0
|
@@ -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
|
}
|
package/src/vue/props.ts
CHANGED
|
@@ -1,15 +1,34 @@
|
|
|
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'
|
|
27
|
+
import type { LinkNavigate } from '../link.js'
|
|
28
|
+
import { navigationContract } from '../contracts.js'
|
|
29
|
+
import type { StackResponsive } from '../responsive.js'
|
|
10
30
|
import { isChoiceValue, type ChoiceValue, type ChoiceOption } from '../choice.js'
|
|
11
31
|
import type { ToastController } from '../toast.js'
|
|
12
|
-
import type { Dimension } from '../layout.js'
|
|
13
32
|
import { iconSizes, type IconName, type IconSize } from '../icon.js'
|
|
14
33
|
import { sheetCloseReasons, type SheetCloseReason } from '../sheet.js'
|
|
15
34
|
|
|
@@ -21,15 +40,10 @@ function choice<T extends string>(values: readonly T[], defaultValue: T) {
|
|
|
21
40
|
}
|
|
22
41
|
}
|
|
23
42
|
|
|
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
|
-
}
|
|
43
|
+
export const spacingProp = vueProperty(spacingProperty)
|
|
44
|
+
const radiusProp = vueProperty(radiusProperty)
|
|
45
|
+
const dimensionProp = vueProperty(dimensionProperty)
|
|
46
|
+
export const viewProps = vueProps(viewContract)
|
|
33
47
|
|
|
34
48
|
export function viewAttrs(props: ExtractPropTypes<typeof viewProps>) {
|
|
35
49
|
return {
|
|
@@ -39,20 +53,23 @@ export function viewAttrs(props: ExtractPropTypes<typeof viewProps>) {
|
|
|
39
53
|
}
|
|
40
54
|
}
|
|
41
55
|
|
|
42
|
-
export const flexProps =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
export const boxProps = {
|
|
56
|
+
export const flexProps = vueProps(flexContract)
|
|
57
|
+
export const boxProps = vueProps(boxContract)
|
|
58
|
+
export const motionBoxProps = vueProps(motionBoxContract)
|
|
59
|
+
export const linkProps = {
|
|
47
60
|
...viewProps,
|
|
48
61
|
...flexProps,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
href: { type: String, required: true as const },
|
|
63
|
+
text: { type: String, default: undefined },
|
|
64
|
+
navigate: { type: Function as PropType<LinkNavigate>, default: undefined },
|
|
65
|
+
target: choice(['_self', '_blank'] as const, '_self'),
|
|
66
|
+
rel: { type: String, default: undefined },
|
|
67
|
+
disabled: Boolean,
|
|
68
|
+
inline: Boolean,
|
|
69
|
+
}
|
|
70
|
+
export const linkEmits = {
|
|
71
|
+
click: () => true,
|
|
72
|
+
error: (_error: unknown) => true,
|
|
56
73
|
}
|
|
57
74
|
export const listItemProps = {
|
|
58
75
|
...viewProps,
|
|
@@ -150,24 +167,15 @@ export const skeletonProps = {
|
|
|
150
167
|
radius: { ...radiusProp, default: 'sm' },
|
|
151
168
|
animated: { type: Boolean, default: true },
|
|
152
169
|
}
|
|
153
|
-
export
|
|
154
|
-
export
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
}
|
|
170
|
+
export const rowProps = vueProps(rowContract)
|
|
171
|
+
export const columnProps = vueProps(columnContract)
|
|
172
|
+
export const stackProps = {
|
|
173
|
+
...columnProps,
|
|
174
|
+
direction: choice(['row', 'column'] as const, 'column'),
|
|
175
|
+
responsive: { type: [Object, Array] as PropType<StackResponsive>, default: undefined },
|
|
167
176
|
}
|
|
168
|
-
export const rowProps = layoutProps('row')
|
|
169
|
-
export const columnProps = layoutProps('column')
|
|
170
177
|
export const cardProps = {
|
|
178
|
+
...vueProps(navigationContract),
|
|
171
179
|
motionSurface: { type: Object as PropType<MotionSurface>, default: undefined },
|
|
172
180
|
...boxProps,
|
|
173
181
|
padding: spacingProp,
|
|
@@ -177,59 +185,16 @@ export const cardProps = {
|
|
|
177
185
|
interactive: Boolean,
|
|
178
186
|
disabled: Boolean,
|
|
179
187
|
}
|
|
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 }
|
|
188
|
+
export const buttonProps = vueProps(buttonContract)
|
|
189
|
+
const tones = paletteTones
|
|
190
|
+
export const weightProp = vueProperty(weightProperty)
|
|
216
191
|
export const spanProps = {
|
|
217
192
|
text: { type: String, default: undefined },
|
|
218
193
|
weight: weightProp,
|
|
219
194
|
tone: { type: String as PropType<keyof Palette>, default: undefined },
|
|
220
195
|
emphasis: { type: String as PropType<'strong' | 'em'>, default: undefined },
|
|
221
196
|
}
|
|
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
|
-
}
|
|
197
|
+
export const textProps = vueProps(textContract)
|
|
233
198
|
export const sliderProps = {
|
|
234
199
|
id: viewProps.id,
|
|
235
200
|
accessibilityHidden: viewProps.accessibilityHidden,
|
|
@@ -344,44 +309,7 @@ export const selectProps = {
|
|
|
344
309
|
emptyText: { type: String, default: 'No options available' },
|
|
345
310
|
}
|
|
346
311
|
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
|
-
}
|
|
312
|
+
export const inputProps = vueProps(inputContract)
|
|
385
313
|
export const inputEmits = {
|
|
386
314
|
action: () => true,
|
|
387
315
|
'update:modelValue': (value: string) => typeof value === 'string',
|
|
@@ -428,14 +356,16 @@ export const sheetEmits = {
|
|
|
428
356
|
close: (reason: SheetCloseReason) => sheetCloseReasons.includes(reason),
|
|
429
357
|
opened: () => true,
|
|
430
358
|
}
|
|
431
|
-
export const actionEmits = { click: () => true }
|
|
359
|
+
export const actionEmits = { click: () => true, error: (_error: unknown) => true }
|
|
432
360
|
export const sliderEmits = { 'update:modelValue': (value: number) => Number.isFinite(value) }
|
|
433
361
|
|
|
434
362
|
export const componentProps = {
|
|
435
363
|
MScreen: screenProps,
|
|
436
364
|
MRow: rowProps,
|
|
437
365
|
MColumn: columnProps,
|
|
438
|
-
|
|
366
|
+
MStack: stackProps,
|
|
367
|
+
MLink: linkProps,
|
|
368
|
+
MBox: motionBoxProps,
|
|
439
369
|
MCard: cardProps,
|
|
440
370
|
MText: textProps,
|
|
441
371
|
MButton: buttonProps,
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { onBeforeUnmount, ref, watch } from '@vue/runtime-core'
|
|
2
|
+
|
|
3
|
+
export interface RevealHost {
|
|
4
|
+
animate(open: boolean, fromClosed: boolean): { finished: Promise<boolean>; stop(): void }
|
|
5
|
+
interactive(enabled: boolean): void
|
|
6
|
+
captureFocus(): void
|
|
7
|
+
restoreFocus(): void
|
|
8
|
+
release(): void
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Presence outlives a closing animation. Reversal updates the same mounted subtree. */
|
|
12
|
+
export function useRevealState(show: () => boolean) {
|
|
13
|
+
const present = ref(show())
|
|
14
|
+
const phase = ref<'open' | 'opening' | 'closing' | 'closed'>(show() ? 'open' : 'closed')
|
|
15
|
+
let host: RevealHost | undefined
|
|
16
|
+
let playback: ReturnType<RevealHost['animate']> | undefined
|
|
17
|
+
let revision = 0
|
|
18
|
+
let fresh = false
|
|
19
|
+
const settle = (open: boolean) => {
|
|
20
|
+
phase.value = open ? 'open' : 'closed'
|
|
21
|
+
present.value = open
|
|
22
|
+
}
|
|
23
|
+
function run(open: boolean) {
|
|
24
|
+
if (!host) return
|
|
25
|
+
const current = ++revision
|
|
26
|
+
if (open) host.captureFocus()
|
|
27
|
+
else host.restoreFocus()
|
|
28
|
+
host.interactive(open)
|
|
29
|
+
// Starting a new Jolt operation hands the current trajectory to its successor.
|
|
30
|
+
playback = host.animate(open, fresh)
|
|
31
|
+
fresh = false
|
|
32
|
+
return playback.finished.then(
|
|
33
|
+
() => {
|
|
34
|
+
if (current === revision) {
|
|
35
|
+
playback = undefined
|
|
36
|
+
settle(open)
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
(error) => {
|
|
40
|
+
if (current === revision) {
|
|
41
|
+
playback = undefined
|
|
42
|
+
settle(open)
|
|
43
|
+
}
|
|
44
|
+
throw error
|
|
45
|
+
},
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
watch(
|
|
49
|
+
show,
|
|
50
|
+
(open) => {
|
|
51
|
+
const wasPresent = present.value
|
|
52
|
+
fresh = open && !wasPresent
|
|
53
|
+
if (open) present.value = true
|
|
54
|
+
phase.value = open ? 'opening' : 'closing'
|
|
55
|
+
if (host) return run(open)
|
|
56
|
+
else if (!open) settle(false)
|
|
57
|
+
},
|
|
58
|
+
{ flush: 'pre' },
|
|
59
|
+
)
|
|
60
|
+
const detach = () => {
|
|
61
|
+
revision++
|
|
62
|
+
playback?.stop()
|
|
63
|
+
playback = undefined
|
|
64
|
+
host?.release()
|
|
65
|
+
host = undefined
|
|
66
|
+
settle(show())
|
|
67
|
+
}
|
|
68
|
+
onBeforeUnmount(detach)
|
|
69
|
+
return {
|
|
70
|
+
present,
|
|
71
|
+
phase,
|
|
72
|
+
detach,
|
|
73
|
+
attach(next: RevealHost) {
|
|
74
|
+
revision++
|
|
75
|
+
playback?.stop()
|
|
76
|
+
playback = undefined
|
|
77
|
+
host?.release()
|
|
78
|
+
host = next
|
|
79
|
+
if (phase.value === 'opening' || phase.value === 'closing') return run(show())
|
|
80
|
+
else host.interactive(show())
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -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
|
+
}
|