@getcortexlabs/mavis-core 0.1.0-alpha.10 → 0.1.0-alpha.11

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.
Files changed (100) hide show
  1. package/dist/capabilities.d.ts +7 -7
  2. package/dist/capabilities.d.ts.map +1 -1
  3. package/dist/capabilities.js +16 -4
  4. package/dist/capabilities.js.map +1 -1
  5. package/dist/chart.d.ts +40 -0
  6. package/dist/chart.d.ts.map +1 -0
  7. package/dist/chart.js +73 -0
  8. package/dist/chart.js.map +1 -0
  9. package/dist/discovery.d.ts +49 -0
  10. package/dist/discovery.d.ts.map +1 -0
  11. package/dist/discovery.js +80 -0
  12. package/dist/discovery.js.map +1 -0
  13. package/dist/index.d.ts +3 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +3 -0
  16. package/dist/index.js.map +1 -1
  17. package/dist/vue/carousel.d.ts +11 -0
  18. package/dist/vue/carousel.d.ts.map +1 -0
  19. package/dist/vue/carousel.js +115 -0
  20. package/dist/vue/carousel.js.map +1 -0
  21. package/dist/vue/chart.d.ts +194 -0
  22. package/dist/vue/chart.d.ts.map +1 -0
  23. package/dist/vue/chart.js +246 -0
  24. package/dist/vue/chart.js.map +1 -0
  25. package/dist/vue/command-palette.d.ts +129 -0
  26. package/dist/vue/command-palette.d.ts.map +1 -0
  27. package/dist/vue/command-palette.js +187 -0
  28. package/dist/vue/command-palette.js.map +1 -0
  29. package/dist/vue/component-props.d.ts +475 -18
  30. package/dist/vue/component-props.d.ts.map +1 -1
  31. package/dist/vue/component-props.js +14 -0
  32. package/dist/vue/component-props.js.map +1 -1
  33. package/dist/vue/configurator.d.ts +2 -2
  34. package/dist/vue/data-table.d.ts +17 -0
  35. package/dist/vue/data-table.d.ts.map +1 -0
  36. package/dist/vue/data-table.js +133 -0
  37. package/dist/vue/data-table.js.map +1 -0
  38. package/dist/vue/date-picker.d.ts +8 -8
  39. package/dist/vue/date-props.d.ts +6 -0
  40. package/dist/vue/date-props.d.ts.map +1 -1
  41. package/dist/vue/date-props.js +3 -0
  42. package/dist/vue/date-props.js.map +1 -1
  43. package/dist/vue/discovery-components.d.ts +50 -0
  44. package/dist/vue/discovery-components.d.ts.map +1 -0
  45. package/dist/vue/discovery-components.js +2 -0
  46. package/dist/vue/discovery-components.js.map +1 -0
  47. package/dist/vue/discovery-controls.d.ts +197 -0
  48. package/dist/vue/discovery-controls.d.ts.map +1 -0
  49. package/dist/vue/discovery-controls.js +166 -0
  50. package/dist/vue/discovery-controls.js.map +1 -0
  51. package/dist/vue/discovery-props.d.ts +249 -0
  52. package/dist/vue/discovery-props.d.ts.map +1 -0
  53. package/dist/vue/discovery-props.js +87 -0
  54. package/dist/vue/discovery-props.js.map +1 -0
  55. package/dist/vue/global-components.d.ts +61 -0
  56. package/dist/vue/global-components.d.ts.map +1 -1
  57. package/dist/vue/index.d.ts +10 -0
  58. package/dist/vue/index.d.ts.map +1 -1
  59. package/dist/vue/index.js +9 -0
  60. package/dist/vue/index.js.map +1 -1
  61. package/dist/vue/menu.d.ts +1 -1
  62. package/dist/vue/props.d.ts +36 -36
  63. package/dist/vue/time-picker.d.ts +2 -2
  64. package/dist/vue/tree-view.d.ts +111 -0
  65. package/dist/vue/tree-view.d.ts.map +1 -0
  66. package/dist/vue/tree-view.js +180 -0
  67. package/dist/vue/tree-view.js.map +1 -0
  68. package/dist/vue/wayfinding-controls.d.ts +198 -0
  69. package/dist/vue/wayfinding-controls.d.ts.map +1 -0
  70. package/dist/vue/wayfinding-controls.js +310 -0
  71. package/dist/vue/wayfinding-controls.js.map +1 -0
  72. package/dist/vue/wayfinding-props.d.ts +221 -0
  73. package/dist/vue/wayfinding-props.d.ts.map +1 -0
  74. package/dist/vue/wayfinding-props.js +86 -0
  75. package/dist/vue/wayfinding-props.js.map +1 -0
  76. package/dist/vue/workflows.d.ts +2 -2
  77. package/dist/wayfinding.d.ts +50 -0
  78. package/dist/wayfinding.d.ts.map +1 -0
  79. package/dist/wayfinding.js +54 -0
  80. package/dist/wayfinding.js.map +1 -0
  81. package/package.json +1 -1
  82. package/src/capabilities.ts +16 -4
  83. package/src/chart.ts +112 -0
  84. package/src/discovery.ts +139 -0
  85. package/src/index.ts +5 -0
  86. package/src/vue/carousel.ts +173 -0
  87. package/src/vue/chart.ts +338 -0
  88. package/src/vue/command-palette.ts +232 -0
  89. package/src/vue/component-props.ts +28 -0
  90. package/src/vue/data-table.ts +190 -0
  91. package/src/vue/date-props.ts +3 -0
  92. package/src/vue/discovery-components.ts +60 -0
  93. package/src/vue/discovery-controls.ts +218 -0
  94. package/src/vue/discovery-props.ts +92 -0
  95. package/src/vue/global-components.ts +66 -0
  96. package/src/vue/index.ts +13 -0
  97. package/src/vue/tree-view.ts +220 -0
  98. package/src/vue/wayfinding-controls.ts +412 -0
  99. package/src/vue/wayfinding-props.ts +97 -0
  100. package/src/wayfinding.ts +85 -0
@@ -0,0 +1,220 @@
1
+ import {
2
+ computed,
3
+ defineComponent,
4
+ h,
5
+ mergeProps,
6
+ nextTick,
7
+ ref,
8
+ watch,
9
+ useId,
10
+ type Component,
11
+ } from '@vue/runtime-core'
12
+ import { choiceKey, type ChoiceValue } from '../choice.js'
13
+ import { treeBranch, treeEntries, type TreeNode } from '../discovery.js'
14
+ import { treeViewProps } from './discovery-props.js'
15
+ import { useMavisTheme } from './theme.js'
16
+
17
+ export function createTreeView(
18
+ ui: {
19
+ Column: Component
20
+ Row: Component
21
+ Text: Component
22
+ Button: Component
23
+ Reveal: Component
24
+ Icon: Component
25
+ focus?: (id: string) => void
26
+ containsFocus?: (id: string) => boolean
27
+ },
28
+ platform: 'web' | 'native',
29
+ ) {
30
+ return defineComponent({
31
+ name: 'MTreeView',
32
+ inheritAttrs: false,
33
+ props: treeViewProps,
34
+ emits: {
35
+ 'update:modelValue': (_key: ChoiceValue) => true,
36
+ 'update:expanded': (_keys: ChoiceValue[]) => true,
37
+ load: (_node: TreeNode) => true,
38
+ },
39
+ setup(props, { attrs, emit }) {
40
+ const { theme } = useMavisTheme()
41
+ const treeId = `m-tree-${useId()}`
42
+ const entries = computed(() => treeEntries(props.nodes, props.expanded))
43
+ const focused = ref<ChoiceValue | null>(props.modelValue)
44
+ const idFor = (key: ChoiceValue) => `${treeId}-${encodeURIComponent(choiceKey(key))}`
45
+ function isOpen(key: ChoiceValue) {
46
+ return props.expanded.includes(key)
47
+ }
48
+ function select(node: TreeNode) {
49
+ if (!props.disabled && !node.disabled) emit('update:modelValue', node.key)
50
+ }
51
+ function toggle(node: TreeNode, open = !isOpen(node.key)) {
52
+ if (
53
+ props.disabled ||
54
+ node.disabled ||
55
+ !treeBranch(node) ||
56
+ props.loadingKeys.includes(node.key)
57
+ )
58
+ return
59
+ if (open === isOpen(node.key)) return
60
+ emit(
61
+ 'update:expanded',
62
+ open ? [...props.expanded, node.key] : props.expanded.filter((key) => key !== node.key),
63
+ )
64
+ if (open && node.children === undefined) emit('load', node)
65
+ }
66
+ function focus(key: ChoiceValue) {
67
+ focused.value = key
68
+ void nextTick(() => ui.focus?.(idFor(key)))
69
+ }
70
+ watch(
71
+ entries,
72
+ (visible, previous) => {
73
+ if (visible.some((entry) => entry.node.key === focused.value)) return
74
+ const restore = focused.value !== null && ui.containsFocus?.(idFor(focused.value))
75
+ // Prefer the collapsed ancestor; never reset a retained logical node by array index.
76
+ let parent = previous?.find((entry) => entry.node.key === focused.value)?.parent
77
+ while (parent != null && !visible.some((entry) => entry.node.key === parent))
78
+ parent = previous?.find((entry) => entry.node.key === parent)?.parent
79
+ focused.value = parent ?? visible.find((entry) => !entry.node.disabled)?.node.key ?? null
80
+ if (restore && focused.value !== null) focus(focused.value)
81
+ },
82
+ { immediate: true },
83
+ )
84
+ function keydown(event: KeyboardEvent, node: TreeNode) {
85
+ if (event.altKey || event.ctrlKey || event.metaKey || event.isComposing || props.disabled)
86
+ return
87
+ const visible = entries.value.filter((entry) => !entry.node.disabled)
88
+ const index = visible.findIndex((entry) => entry.node.key === node.key)
89
+ let next: ChoiceValue | undefined
90
+ if (event.key === 'ArrowDown')
91
+ next = visible[Math.min(visible.length - 1, index + 1)]?.node.key
92
+ else if (event.key === 'ArrowUp') next = visible[Math.max(0, index - 1)]?.node.key
93
+ else if (event.key === 'Home') next = visible[0]?.node.key
94
+ else if (event.key === 'End') next = visible.at(-1)?.node.key
95
+ else if (event.key === 'ArrowRight') {
96
+ if (!isOpen(node.key)) toggle(node, true)
97
+ else next = node.children?.find((child) => !child.disabled)?.key
98
+ } else if (event.key === 'ArrowLeft') {
99
+ if (isOpen(node.key)) toggle(node, false)
100
+ else
101
+ next = entries.value.find((entry) => entry.node.key === node.key)?.parent ?? undefined
102
+ } else if (event.key === 'Enter' || event.key === ' ') select(node)
103
+ else if (event.key.length === 1) {
104
+ const order = [...visible.slice(index + 1), ...visible.slice(0, index + 1)]
105
+ next = order.find((entry) =>
106
+ entry.node.label.toLocaleLowerCase().startsWith(event.key.toLocaleLowerCase()),
107
+ )?.node.key
108
+ } else return
109
+ event.preventDefault()
110
+ if (next !== undefined) focus(next)
111
+ }
112
+ function render(nodes: readonly TreeNode[], level = 1): ReturnType<typeof h>[] {
113
+ return nodes.map((node, index) => {
114
+ const branch = treeBranch(node),
115
+ open = isOpen(node.key),
116
+ selected = props.modelValue === node.key
117
+ const busy = props.loadingKeys.includes(node.key)
118
+ const unavailable = props.disabled || node.disabled
119
+ return h(ui.Column, { key: choiceKey(node.key), gap: 'none' }, () => [
120
+ h(
121
+ ui.Row,
122
+ {
123
+ id: idFor(node.key),
124
+ gap: 'xs',
125
+ padding: 'xs',
126
+ radius: 'md',
127
+ backgroundColor: selected ? theme.value.colors.primarySoft : 'transparent',
128
+ ...(platform === 'web'
129
+ ? {
130
+ role: 'treeitem',
131
+ tabindex: !unavailable && focused.value === node.key ? 0 : -1,
132
+ 'aria-level': level,
133
+ 'aria-posinset': index + 1,
134
+ 'aria-setsize': nodes.length,
135
+ 'aria-selected': selected,
136
+ 'aria-expanded': branch ? open : undefined,
137
+ 'aria-disabled': unavailable || undefined,
138
+ 'aria-busy': busy || undefined,
139
+ 'aria-label': node.label,
140
+ onFocus: () => {
141
+ focused.value = node.key
142
+ },
143
+ onKeydown: (event: KeyboardEvent) => keydown(event, node),
144
+ }
145
+ : {}),
146
+ },
147
+ () => [
148
+ branch
149
+ ? h(ui.Button, {
150
+ icon: open ? 'chevron-down' : 'chevron-right',
151
+ variant: 'ghost',
152
+ accessibilityLabel: `${node.label}: ${open ? props.expandedLabel : props.collapsedLabel}`,
153
+ disabled: unavailable || busy,
154
+ ...(platform === 'web' ? { tabindex: -1 } : {}),
155
+ onClick: () => toggle(node),
156
+ })
157
+ : h(ui.Icon, { name: 'file', tone: 'muted', size: 18, style: { margin: 12 } }),
158
+ h(ui.Button, {
159
+ text: node.label,
160
+ style:
161
+ platform === 'web'
162
+ ? { justifyContent: 'flex-start', textAlign: 'start' }
163
+ : { textAlignment: 'left' },
164
+ variant: 'ghost',
165
+ grow: platform === 'web' ? 1 : 0,
166
+ shrink: 1,
167
+ disabled: unavailable,
168
+ ...(platform === 'web'
169
+ ? { tabindex: -1 }
170
+ : { accessibilityValue: selected ? 'Selected' : '' }),
171
+ onClick: () => select(node),
172
+ }),
173
+ busy
174
+ ? h(ui.Text, { text: props.loadingLabel, variant: 'caption', tone: 'muted' })
175
+ : null,
176
+ ],
177
+ ),
178
+ branch
179
+ ? h(
180
+ ui.Reveal,
181
+ {
182
+ show: open,
183
+ style:
184
+ platform === 'web'
185
+ ? { paddingInlineStart: `${theme.value.space.lg}px` }
186
+ : { paddingLeft: theme.value.space.lg },
187
+ },
188
+ () => render(node.children ?? [], level + 1),
189
+ )
190
+ : null,
191
+ ])
192
+ })
193
+ }
194
+ return () => {
195
+ void entries.value
196
+ return h(
197
+ ui.Column,
198
+ mergeProps(
199
+ { id: props.id, gap: 'sm' },
200
+ attrs,
201
+ platform === 'web' ? { class: 'm-tree-view' } : {},
202
+ ),
203
+ () => [
204
+ h(ui.Text, { as: 'h2', variant: 'heading', text: props.label }),
205
+ props.nodes.length
206
+ ? h(
207
+ ui.Column,
208
+ {
209
+ gap: 'xs',
210
+ ...(platform === 'web' ? { role: 'tree', 'aria-label': props.label } : {}),
211
+ },
212
+ () => render(props.nodes),
213
+ )
214
+ : h(ui.Text, { text: props.emptyLabel, tone: 'muted' }),
215
+ ],
216
+ )
217
+ }
218
+ },
219
+ })
220
+ }
@@ -0,0 +1,412 @@
1
+ import {
2
+ computed,
3
+ defineComponent,
4
+ h,
5
+ markRaw,
6
+ mergeProps,
7
+ nextTick,
8
+ onScopeDispose,
9
+ ref,
10
+ watch,
11
+ type Component,
12
+ type PropType,
13
+ } from '@vue/runtime-core'
14
+ import { choiceKey } from '../choice.js'
15
+ import {
16
+ breadcrumbParts,
17
+ validateRail,
18
+ validateTimeline,
19
+ type TimelineItem,
20
+ } from '../wayfinding.js'
21
+ import { createMotionSurface } from '../experimental.js'
22
+ import { breadcrumbProps, navigationRailProps, timelineProps } from './wayfinding-props.js'
23
+ import { useMavisTheme } from './theme.js'
24
+
25
+ interface Primitives {
26
+ focus(component: unknown): void
27
+ Row: Component
28
+ Column: Component
29
+ Box: Component
30
+ Text: Component
31
+ Button: Component
32
+ Link: Component
33
+ Icon: Component
34
+ Badge: Component
35
+ Separator: Component
36
+ }
37
+ export function createWayfindingControls(ui: Primitives, platform: 'web' | 'native') {
38
+ const web = platform === 'web'
39
+ const Signal = defineComponent({
40
+ props: { active: Boolean, color: String, size: { type: Number, default: 8 } },
41
+ setup(props) {
42
+ const { theme } = useMavisTheme()
43
+ const motion = markRaw(createMotionSurface())
44
+ const play = () => {
45
+ if (motion.available)
46
+ motion.animate(
47
+ { scale: props.active ? [0.7, 1] : 1, opacity: props.active ? 1 : 0.45 },
48
+ { type: 'spring', duration: theme.value.motion.enterDuration, bounce: 0.15 },
49
+ )
50
+ }
51
+ onScopeDispose(motion.use(play))
52
+ watch(() => props.active, play)
53
+ return () =>
54
+ h(ui.Box, {
55
+ width: props.size,
56
+ height: props.size,
57
+ radius: 'full',
58
+ backgroundColor: props.color,
59
+ motionSurface: motion,
60
+ accessibilityHidden: true,
61
+ })
62
+ },
63
+ })
64
+ const MNavigationRail = defineComponent({
65
+ name: 'MNavigationRail',
66
+ inheritAttrs: false,
67
+ props: navigationRailProps,
68
+ emits: { 'update:collapsed': (_collapsed: boolean) => true, error: (_error: unknown) => true },
69
+ setup(props, { attrs, slots, emit }) {
70
+ const { theme } = useMavisTheme()
71
+ return () => {
72
+ validateRail(props.groups)
73
+ if (!props.label.trim()) throw new TypeError('Navigation rail requires a label.')
74
+ return h(
75
+ ui.Column,
76
+ mergeProps(
77
+ {
78
+ id: props.id,
79
+ gap: 'lg',
80
+ padding: 'sm',
81
+ radius: 'lg',
82
+ width: props.collapsed ? 80 : 256,
83
+ backgroundColor: theme.value.colors.surface,
84
+ },
85
+ attrs,
86
+ web
87
+ ? {
88
+ class: 'm-navigation-rail',
89
+ role: 'navigation',
90
+ 'aria-label': props.label,
91
+ style: { maxWidth: '100%', border: `1px solid ${theme.value.colors.border}` },
92
+ }
93
+ : {
94
+ accessibilityLabel: props.label,
95
+ borderWidth: 1,
96
+ borderColor: theme.value.colors.border,
97
+ },
98
+ ),
99
+ () => [
100
+ slots.header?.({ collapsed: props.collapsed }),
101
+ ...props.groups.map((group) =>
102
+ h(
103
+ ui.Column,
104
+ {
105
+ key: group.key,
106
+ gap: 'xs',
107
+ ...(web ? { role: 'group', 'aria-label': group.label } : {}),
108
+ },
109
+ () => [
110
+ props.collapsed
111
+ ? h(ui.Separator, { accessibilityHidden: true })
112
+ : h(ui.Text, {
113
+ text: group.label,
114
+ variant: 'overline',
115
+ tone: 'muted',
116
+ paddingX: 'sm',
117
+ }),
118
+ ...group.items.map((item) => {
119
+ const current = item.value === props.modelValue
120
+ const badge = item.badge === undefined ? '' : ` ${item.badge}`
121
+ return h(
122
+ ui.Button,
123
+ {
124
+ key: choiceKey(item.value),
125
+ text: props.collapsed ? undefined : item.label,
126
+ icon: item.icon ?? (props.collapsed ? 'circle' : undefined),
127
+ href: item.href,
128
+ navigate: item.navigate,
129
+ disabled: props.disabled || item.disabled,
130
+ variant: current ? 'secondary' : 'ghost',
131
+ accessibilityLabel: `${item.label}${badge}${current && !web ? `. ${props.currentLabel}` : ''}`,
132
+ ...(web
133
+ ? {
134
+ 'aria-current': current ? 'page' : undefined,
135
+ title: props.collapsed ? `${item.label}${badge}` : undefined,
136
+ style: {
137
+ justifyContent: props.collapsed ? 'center' : 'flex-start',
138
+ minWidth: 0,
139
+ },
140
+ }
141
+ : {}),
142
+ onError: (error: unknown) => emit('error', error),
143
+ },
144
+ {
145
+ leading: !props.collapsed
146
+ ? () =>
147
+ h(ui.Row, { gap: 'sm' }, () => [
148
+ h(Signal, {
149
+ active: current,
150
+ color: current
151
+ ? theme.value.colors.primary
152
+ : theme.value.colors.border,
153
+ size: 6,
154
+ }),
155
+ item.icon ? h(ui.Icon, { name: item.icon, size: 18 }) : null,
156
+ ])
157
+ : undefined,
158
+ trailing:
159
+ !props.collapsed && item.badge !== undefined
160
+ ? () => [
161
+ web ? ' ' : null,
162
+ h(ui.Badge, {
163
+ text: String(item.badge),
164
+ tone: current ? 'primary' : 'neutral',
165
+ accessibilityHidden: true,
166
+ }),
167
+ ]
168
+ : undefined,
169
+ },
170
+ )
171
+ }),
172
+ ],
173
+ ),
174
+ ),
175
+ slots.footer?.({ collapsed: props.collapsed }),
176
+ props.collapsible
177
+ ? h(ui.Button, {
178
+ text: props.collapsed ? undefined : props.collapseLabel,
179
+ icon: props.collapsed ? 'panel-left-open' : 'panel-left-close',
180
+ accessibilityLabel: props.collapsed ? props.expandLabel : props.collapseLabel,
181
+ variant: 'ghost',
182
+ disabled: props.disabled,
183
+ ...(web ? { 'aria-expanded': !props.collapsed } : {}),
184
+ onClick: () => emit('update:collapsed', !props.collapsed),
185
+ })
186
+ : null,
187
+ ],
188
+ )
189
+ }
190
+ },
191
+ })
192
+ const MBreadcrumb = defineComponent({
193
+ name: 'MBreadcrumb',
194
+ inheritAttrs: false,
195
+ props: breadcrumbProps,
196
+ emits: { error: (_error: unknown) => true },
197
+ setup(props, { attrs, emit }) {
198
+ const expanded = ref(false)
199
+ const links = new Map<string, unknown>()
200
+ watch(
201
+ () => props.items.map((item) => choiceKey(item.key)).join('|'),
202
+ () => {
203
+ expanded.value = false
204
+ },
205
+ )
206
+ return () => {
207
+ if (!props.label.trim()) throw new TypeError('Breadcrumb requires a label.')
208
+ const parts = breadcrumbParts(props.items, props.maxItems)
209
+ const entries =
210
+ expanded.value || !parts.hidden.length
211
+ ? props.items
212
+ : [...parts.before, null, ...parts.after]
213
+ return h(
214
+ ui.Row,
215
+ mergeProps(
216
+ { id: props.id, gap: 'xs', wrap: true },
217
+ attrs,
218
+ web
219
+ ? { class: 'm-breadcrumb', role: 'navigation', 'aria-label': props.label }
220
+ : { accessibilityLabel: props.label },
221
+ ),
222
+ () =>
223
+ entries.flatMap((item, index) => [
224
+ index
225
+ ? h(ui.Icon, {
226
+ key: `separator:${index}`,
227
+ name: 'chevron-right',
228
+ size: 14,
229
+ tone: 'muted',
230
+ accessibilityHidden: true,
231
+ })
232
+ : null,
233
+ item === null
234
+ ? h(ui.Button, {
235
+ key: 'expand',
236
+ icon: 'ellipsis',
237
+ accessibilityLabel: props.expandLabel,
238
+ variant: 'ghost',
239
+ size: 'sm',
240
+ onClick: () => {
241
+ expanded.value = true
242
+ const first = parts.hidden[0]
243
+ if (first) void nextTick(() => ui.focus(links.get(choiceKey(first.key))))
244
+ },
245
+ })
246
+ : item === props.items[props.items.length - 1]
247
+ ? h(ui.Text, {
248
+ key: choiceKey(item.key),
249
+ text: item.label,
250
+ weight: '600',
251
+ shrink: 1,
252
+ ...(web ? { 'aria-current': 'page' } : {}),
253
+ })
254
+ : h(ui.Link, {
255
+ ref: (value: unknown) => {
256
+ if (value) links.set(choiceKey(item.key), value)
257
+ else links.delete(choiceKey(item.key))
258
+ },
259
+ key: choiceKey(item.key),
260
+ text: item.label,
261
+ href: item.href,
262
+ navigate: item.navigate,
263
+ shrink: 1,
264
+ onError: (error: unknown) => emit('error', error),
265
+ }),
266
+ ]),
267
+ )
268
+ }
269
+ },
270
+ })
271
+ const Entry = defineComponent({
272
+ props: {
273
+ item: { type: Object as PropType<TimelineItem>, required: true },
274
+ last: Boolean,
275
+ statusText: String,
276
+ },
277
+ setup(props, { slots }) {
278
+ const { theme } = useMavisTheme()
279
+ const status = computed(() => props.item.status ?? 'complete')
280
+ const color = computed(() =>
281
+ status.value === 'error'
282
+ ? theme.value.colors.danger
283
+ : status.value === 'upcoming'
284
+ ? theme.value.colors.muted
285
+ : theme.value.colors.primary,
286
+ )
287
+ const motion = markRaw(createMotionSurface())
288
+ onScopeDispose(
289
+ motion.use((owner) => {
290
+ owner.animate(
291
+ { y: [10, 0] },
292
+ { type: 'spring', duration: theme.value.motion.enterDuration, bounce: 0.1 },
293
+ )
294
+ }),
295
+ )
296
+ return () =>
297
+ h(
298
+ ui.Box,
299
+ {
300
+ motionSurface: motion,
301
+ ...(web ? { role: 'listitem', class: 'm-timeline-entry' } : {}),
302
+ },
303
+ () =>
304
+ h(ui.Row, { gap: 'md', align: 'stretch' }, () => [
305
+ h(
306
+ ui.Column,
307
+ { width: 32, align: 'center', gap: 'xs', shrink: 0, accessibilityHidden: true },
308
+ () => [
309
+ h(
310
+ ui.Box,
311
+ {
312
+ width: 32,
313
+ height: 32,
314
+ radius: 'full',
315
+ backgroundColor:
316
+ status.value === 'upcoming'
317
+ ? theme.value.colors.surface
318
+ : theme.value.colors.primarySoft,
319
+ },
320
+ () =>
321
+ h(ui.Row, { justify: 'center', height: 32 }, () =>
322
+ h(ui.Icon, {
323
+ name:
324
+ props.item.icon ??
325
+ (status.value === 'complete'
326
+ ? 'check'
327
+ : status.value === 'error'
328
+ ? 'circle-alert'
329
+ : 'circle-dot'),
330
+ size: 16,
331
+ tone:
332
+ status.value === 'error'
333
+ ? 'danger'
334
+ : status.value === 'upcoming'
335
+ ? 'muted'
336
+ : 'primary',
337
+ }),
338
+ ),
339
+ ),
340
+ !props.last
341
+ ? h(ui.Box, {
342
+ width: 2,
343
+ grow: 1,
344
+ backgroundColor: theme.value.colors.border,
345
+ height: 24,
346
+ })
347
+ : null,
348
+ ],
349
+ ),
350
+ h(ui.Column, { grow: 1, shrink: 1, gap: 'sm', paddingY: 'xs' }, () => [
351
+ h(ui.Row, { gap: 'sm', wrap: true, justify: 'between' }, () => [
352
+ h(ui.Text, { text: props.item.title, weight: '600', shrink: 1 }),
353
+ props.item.time
354
+ ? h(ui.Text, { text: props.item.time, variant: 'caption', tone: 'muted' })
355
+ : null,
356
+ ]),
357
+ h(ui.Row, { gap: 'xs' }, () => [
358
+ h(Signal, { color: color.value, active: status.value === 'current', size: 6 }),
359
+ h(ui.Text, {
360
+ text: props.statusText,
361
+ variant: 'caption',
362
+ tone: status.value === 'error' ? 'danger' : 'muted',
363
+ }),
364
+ ]),
365
+ props.item.description
366
+ ? h(ui.Text, { text: props.item.description, tone: 'muted' })
367
+ : null,
368
+ slots.default?.(),
369
+ !props.last ? h(ui.Box, { height: 16, accessibilityHidden: true }) : null,
370
+ ]),
371
+ ]),
372
+ )
373
+ },
374
+ })
375
+ const MTimeline = defineComponent({
376
+ name: 'MTimeline',
377
+ inheritAttrs: false,
378
+ props: timelineProps,
379
+ setup(props, { attrs, slots }) {
380
+ return () => {
381
+ validateTimeline(props.items)
382
+ if (!props.label.trim()) throw new TypeError('Timeline requires a label.')
383
+ return h(
384
+ ui.Column,
385
+ mergeProps(
386
+ { id: props.id, gap: 'none' },
387
+ attrs,
388
+ web
389
+ ? { class: 'm-timeline', role: 'list', 'aria-label': props.label }
390
+ : { accessibilityLabel: props.label },
391
+ ),
392
+ () =>
393
+ props.items.length
394
+ ? props.items.map((item, index) =>
395
+ h(
396
+ Entry,
397
+ {
398
+ key: choiceKey(item.key),
399
+ item,
400
+ last: index === props.items.length - 1,
401
+ statusText: props.statusLabels[item.status ?? 'complete'],
402
+ },
403
+ () => slots.default?.({ item, index }),
404
+ ),
405
+ )
406
+ : h(ui.Text, { text: props.emptyLabel, tone: 'muted' }),
407
+ )
408
+ }
409
+ },
410
+ })
411
+ return { MNavigationRail, MBreadcrumb, MTimeline }
412
+ }