@getcortexlabs/mavis-core 0.1.0-alpha.8 → 0.1.0-rc.11.1
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 +7 -7
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +30 -4
- package/dist/capabilities.js.map +1 -1
- package/dist/chart.d.ts +43 -0
- package/dist/chart.d.ts.map +1 -0
- package/dist/chart.js +105 -0
- package/dist/chart.js.map +1 -0
- package/dist/collections.d.ts +46 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +48 -0
- package/dist/collections.js.map +1 -0
- package/dist/contracts.d.ts +20 -0
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +2 -0
- package/dist/contracts.js.map +1 -1
- package/dist/date-input.d.ts +10 -0
- package/dist/date-input.d.ts.map +1 -0
- package/dist/date-input.js +58 -0
- package/dist/date-input.js.map +1 -0
- package/dist/date-time.d.ts +19 -0
- package/dist/date-time.d.ts.map +1 -0
- package/dist/date-time.js +27 -0
- package/dist/date-time.js.map +1 -0
- package/dist/discovery.d.ts +49 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +80 -0
- package/dist/discovery.js.map +1 -0
- package/dist/experimental-regions.d.ts +10 -0
- package/dist/experimental-regions.d.ts.map +1 -1
- package/dist/experimental-regions.js +23 -0
- package/dist/experimental-regions.js.map +1 -1
- package/dist/experimental.d.ts +5 -0
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +29 -0
- package/dist/experimental.js.map +1 -1
- package/dist/grid.d.ts +3 -0
- package/dist/grid.d.ts.map +1 -0
- package/dist/grid.js +16 -0
- package/dist/grid.js.map +1 -0
- package/dist/index.d.ts +17 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -1
- package/dist/index.js.map +1 -1
- package/dist/input.d.ts +4 -0
- package/dist/input.d.ts.map +1 -1
- package/dist/input.js.map +1 -1
- package/dist/interactive.d.ts +36 -0
- package/dist/interactive.d.ts.map +1 -0
- package/dist/interactive.js +61 -0
- package/dist/interactive.js.map +1 -0
- package/dist/link.d.ts +24 -0
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +41 -0
- package/dist/link.js.map +1 -1
- package/dist/motion.d.ts +8 -0
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +11 -0
- package/dist/motion.js.map +1 -1
- package/dist/navigation-transition.d.ts +10 -0
- package/dist/navigation-transition.d.ts.map +1 -0
- package/dist/navigation-transition.js +10 -0
- package/dist/navigation-transition.js.map +1 -0
- package/dist/number-flow-format.d.ts +16 -0
- package/dist/number-flow-format.d.ts.map +1 -0
- package/dist/number-flow-format.js +49 -0
- package/dist/number-flow-format.js.map +1 -0
- package/dist/popover.d.ts +17 -0
- package/dist/popover.d.ts.map +1 -0
- package/dist/popover.js +19 -0
- package/dist/popover.js.map +1 -0
- package/dist/section-scroll.d.ts +14 -0
- package/dist/section-scroll.d.ts.map +1 -0
- package/dist/section-scroll.js +28 -0
- package/dist/section-scroll.js.map +1 -0
- package/dist/sheet.d.ts +7 -0
- package/dist/sheet.d.ts.map +1 -1
- package/dist/time.d.ts +34 -0
- package/dist/time.d.ts.map +1 -0
- package/dist/time.js +78 -0
- package/dist/time.js.map +1 -0
- package/dist/vue/carousel.d.ts +13 -0
- package/dist/vue/carousel.d.ts.map +1 -0
- package/dist/vue/carousel.js +136 -0
- package/dist/vue/carousel.js.map +1 -0
- package/dist/vue/chart.d.ts +194 -0
- package/dist/vue/chart.d.ts.map +1 -0
- package/dist/vue/chart.js +245 -0
- package/dist/vue/chart.js.map +1 -0
- package/dist/vue/command-palette.d.ts +129 -0
- package/dist/vue/command-palette.d.ts.map +1 -0
- package/dist/vue/command-palette.js +190 -0
- package/dist/vue/command-palette.js.map +1 -0
- package/dist/vue/component-motion.d.ts +17 -0
- package/dist/vue/component-motion.d.ts.map +1 -0
- package/dist/vue/component-motion.js +83 -0
- package/dist/vue/component-motion.js.map +1 -0
- package/dist/vue/component-props.d.ts +1505 -402
- package/dist/vue/component-props.d.ts.map +1 -1
- package/dist/vue/component-props.js +28 -0
- package/dist/vue/component-props.js.map +1 -1
- package/dist/vue/configurator-props.d.ts +21 -0
- package/dist/vue/configurator-props.d.ts.map +1 -1
- package/dist/vue/configurator-props.js +6 -0
- package/dist/vue/configurator-props.js.map +1 -1
- package/dist/vue/configurator.d.ts +3 -3
- package/dist/vue/configurator.d.ts.map +1 -1
- package/dist/vue/configurator.js +3 -1
- package/dist/vue/configurator.js.map +1 -1
- package/dist/vue/data-table.d.ts +17 -0
- package/dist/vue/data-table.d.ts.map +1 -0
- package/dist/vue/data-table.js +133 -0
- package/dist/vue/data-table.js.map +1 -0
- package/dist/vue/date-calendar.d.ts +2 -0
- package/dist/vue/date-calendar.d.ts.map +1 -1
- package/dist/vue/date-calendar.js +20 -1
- package/dist/vue/date-calendar.js.map +1 -1
- package/dist/vue/date-picker.d.ts +48 -13
- package/dist/vue/date-picker.d.ts.map +1 -1
- package/dist/vue/date-picker.js +67 -74
- package/dist/vue/date-picker.js.map +1 -1
- package/dist/vue/date-props.d.ts +15 -0
- package/dist/vue/date-props.d.ts.map +1 -1
- package/dist/vue/date-props.js +4 -0
- package/dist/vue/date-props.js.map +1 -1
- package/dist/vue/discovery-components.d.ts +50 -0
- package/dist/vue/discovery-components.d.ts.map +1 -0
- package/dist/vue/discovery-components.js +2 -0
- package/dist/vue/discovery-components.js.map +1 -0
- package/dist/vue/discovery-controls.d.ts +197 -0
- package/dist/vue/discovery-controls.d.ts.map +1 -0
- package/dist/vue/discovery-controls.js +185 -0
- package/dist/vue/discovery-controls.js.map +1 -0
- package/dist/vue/discovery-props.d.ts +249 -0
- package/dist/vue/discovery-props.d.ts.map +1 -0
- package/dist/vue/discovery-props.js +87 -0
- package/dist/vue/discovery-props.js.map +1 -0
- package/dist/vue/global-components.d.ts +134 -2
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/index.d.ts +27 -1
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +23 -1
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/interactive-components.d.ts +31 -0
- package/dist/vue/interactive-components.d.ts.map +1 -0
- package/dist/vue/interactive-components.js +2 -0
- package/dist/vue/interactive-components.js.map +1 -0
- package/dist/vue/interactive-props.d.ts +254 -0
- package/dist/vue/interactive-props.d.ts.map +1 -0
- package/dist/vue/interactive-props.js +85 -0
- package/dist/vue/interactive-props.js.map +1 -0
- package/dist/vue/list-motion.d.ts +7 -0
- package/dist/vue/list-motion.d.ts.map +1 -0
- package/dist/vue/list-motion.js +28 -0
- package/dist/vue/list-motion.js.map +1 -0
- package/dist/vue/menu.d.ts +122 -0
- package/dist/vue/menu.d.ts.map +1 -0
- package/dist/vue/menu.js +79 -0
- package/dist/vue/menu.js.map +1 -0
- package/dist/vue/navigation-controls.d.ts +125 -0
- package/dist/vue/navigation-controls.d.ts.map +1 -0
- package/dist/vue/navigation-controls.js +130 -0
- package/dist/vue/navigation-controls.js.map +1 -0
- package/dist/vue/navigation-props.d.ts +283 -0
- package/dist/vue/navigation-props.d.ts.map +1 -0
- package/dist/vue/navigation-props.js +82 -0
- package/dist/vue/navigation-props.js.map +1 -0
- package/dist/vue/navigation.d.ts +7 -0
- package/dist/vue/navigation.d.ts.map +1 -0
- package/dist/vue/navigation.js +15 -0
- package/dist/vue/navigation.js.map +1 -0
- package/dist/vue/number-flow.d.ts +75 -0
- package/dist/vue/number-flow.d.ts.map +1 -0
- package/dist/vue/number-flow.js +57 -0
- package/dist/vue/number-flow.js.map +1 -0
- package/dist/vue/partition.d.ts +15 -0
- package/dist/vue/partition.d.ts.map +1 -0
- package/dist/vue/partition.js +42 -0
- package/dist/vue/partition.js.map +1 -0
- package/dist/vue/platform.d.ts +37 -0
- package/dist/vue/platform.d.ts.map +1 -0
- package/dist/vue/platform.js +46 -0
- package/dist/vue/platform.js.map +1 -0
- package/dist/vue/props.d.ts +233 -36
- package/dist/vue/props.d.ts.map +1 -1
- package/dist/vue/props.js +15 -1
- package/dist/vue/props.js.map +1 -1
- package/dist/vue/sortable-list.d.ts +24 -0
- package/dist/vue/sortable-list.d.ts.map +1 -0
- package/dist/vue/sortable-list.js +251 -0
- package/dist/vue/sortable-list.js.map +1 -0
- package/dist/vue/swipe-actions.d.ts +96 -0
- package/dist/vue/swipe-actions.d.ts.map +1 -0
- package/dist/vue/swipe-actions.js +174 -0
- package/dist/vue/swipe-actions.js.map +1 -0
- package/dist/vue/time-picker.d.ts +488 -0
- package/dist/vue/time-picker.d.ts.map +1 -0
- package/dist/vue/time-picker.js +190 -0
- package/dist/vue/time-picker.js.map +1 -0
- package/dist/vue/tree-view.d.ts +111 -0
- package/dist/vue/tree-view.d.ts.map +1 -0
- package/dist/vue/tree-view.js +204 -0
- package/dist/vue/tree-view.js.map +1 -0
- package/dist/vue/virtual-list.d.ts +26 -0
- package/dist/vue/virtual-list.d.ts.map +1 -0
- package/dist/vue/virtual-list.js +2 -0
- package/dist/vue/virtual-list.js.map +1 -0
- package/dist/vue/wayfinding-controls.d.ts +199 -0
- package/dist/vue/wayfinding-controls.d.ts.map +1 -0
- package/dist/vue/wayfinding-controls.js +330 -0
- package/dist/vue/wayfinding-controls.js.map +1 -0
- package/dist/vue/wayfinding-props.d.ts +221 -0
- package/dist/vue/wayfinding-props.d.ts.map +1 -0
- package/dist/vue/wayfinding-props.js +86 -0
- package/dist/vue/wayfinding-props.js.map +1 -0
- package/dist/vue/workflows.d.ts +2 -2
- package/dist/vue/workflows.d.ts.map +1 -1
- package/dist/vue/workflows.js +17 -4
- package/dist/vue/workflows.js.map +1 -1
- package/dist/wayfinding.d.ts +50 -0
- package/dist/wayfinding.d.ts.map +1 -0
- package/dist/wayfinding.js +54 -0
- package/dist/wayfinding.js.map +1 -0
- package/package.json +2 -2
- package/src/capabilities.ts +31 -4
- package/src/chart.ts +151 -0
- package/src/collections.ts +87 -0
- package/src/contracts.ts +2 -0
- package/src/date-input.ts +87 -0
- package/src/date-time.ts +37 -0
- package/src/discovery.ts +139 -0
- package/src/experimental-regions.ts +29 -0
- package/src/experimental.ts +40 -0
- package/src/grid.ts +19 -0
- package/src/index.ts +24 -3
- package/src/input.ts +5 -0
- package/src/interactive.ts +91 -0
- package/src/link.ts +63 -0
- package/src/motion.ts +14 -0
- package/src/navigation-transition.ts +14 -0
- package/src/number-flow-format.ts +68 -0
- package/src/popover.ts +38 -0
- package/src/section-scroll.ts +46 -0
- package/src/sheet.ts +11 -0
- package/src/time.ts +83 -0
- package/src/vue/carousel.ts +198 -0
- package/src/vue/chart.ts +337 -0
- package/src/vue/command-palette.ts +235 -0
- package/src/vue/component-motion.ts +109 -0
- package/src/vue/component-props.ts +57 -0
- package/src/vue/configurator-props.ts +6 -0
- package/src/vue/configurator.ts +3 -1
- package/src/vue/data-table.ts +190 -0
- package/src/vue/date-calendar.ts +30 -1
- package/src/vue/date-picker.ts +81 -85
- package/src/vue/date-props.ts +5 -0
- package/src/vue/discovery-components.ts +60 -0
- package/src/vue/discovery-controls.ts +241 -0
- package/src/vue/discovery-props.ts +92 -0
- package/src/vue/global-components.ts +124 -2
- package/src/vue/index.ts +46 -0
- package/src/vue/interactive-components.ts +29 -0
- package/src/vue/interactive-props.ts +90 -0
- package/src/vue/list-motion.ts +31 -0
- package/src/vue/menu.ts +100 -0
- package/src/vue/navigation-controls.ts +159 -0
- package/src/vue/navigation-props.ts +87 -0
- package/src/vue/navigation.ts +16 -0
- package/src/vue/number-flow.ts +83 -0
- package/src/vue/partition.ts +49 -0
- package/src/vue/platform.ts +73 -0
- package/src/vue/props.ts +16 -1
- package/src/vue/sortable-list.ts +308 -0
- package/src/vue/swipe-actions.ts +226 -0
- package/src/vue/time-picker.ts +227 -0
- package/src/vue/tree-view.ts +259 -0
- package/src/vue/virtual-list.ts +28 -0
- package/src/vue/wayfinding-controls.ts +430 -0
- package/src/vue/wayfinding-props.ts +97 -0
- package/src/vue/workflows.ts +17 -4
- package/src/wayfinding.ts +85 -0
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
import { useComponentLayout, useComponentState, useComponentSelection } from './component-motion.js'
|
|
2
|
+
import { componentMotion } from '../motion.js'
|
|
3
|
+
import {
|
|
4
|
+
computed,
|
|
5
|
+
defineComponent,
|
|
6
|
+
h,
|
|
7
|
+
markRaw,
|
|
8
|
+
mergeProps,
|
|
9
|
+
nextTick,
|
|
10
|
+
onScopeDispose,
|
|
11
|
+
ref,
|
|
12
|
+
watch,
|
|
13
|
+
type Component,
|
|
14
|
+
type PropType,
|
|
15
|
+
} from '@vue/runtime-core'
|
|
16
|
+
import { choiceKey } from '../choice.js'
|
|
17
|
+
import {
|
|
18
|
+
breadcrumbParts,
|
|
19
|
+
validateRail,
|
|
20
|
+
validateTimeline,
|
|
21
|
+
type TimelineItem,
|
|
22
|
+
} from '../wayfinding.js'
|
|
23
|
+
import { createMotionSurface } from '../experimental.js'
|
|
24
|
+
import { breadcrumbProps, navigationRailProps, timelineProps } from './wayfinding-props.js'
|
|
25
|
+
import { useMavisTheme } from './theme.js'
|
|
26
|
+
|
|
27
|
+
interface Primitives {
|
|
28
|
+
railWidth(read: () => number): Record<string, unknown>
|
|
29
|
+
focus(component: unknown): void
|
|
30
|
+
Row: Component
|
|
31
|
+
Column: Component
|
|
32
|
+
Box: Component
|
|
33
|
+
Text: Component
|
|
34
|
+
Button: Component
|
|
35
|
+
Link: Component
|
|
36
|
+
Icon: Component
|
|
37
|
+
Badge: Component
|
|
38
|
+
Separator: Component
|
|
39
|
+
}
|
|
40
|
+
export function createWayfindingControls(ui: Primitives, platform: 'web' | 'native') {
|
|
41
|
+
const web = platform === 'web'
|
|
42
|
+
const Signal = defineComponent({
|
|
43
|
+
props: { active: Boolean, color: String, size: { type: Number, default: 8 } },
|
|
44
|
+
setup(props) {
|
|
45
|
+
const { theme } = useMavisTheme()
|
|
46
|
+
const motion = markRaw(createMotionSurface())
|
|
47
|
+
const play = () => {
|
|
48
|
+
if (motion.available)
|
|
49
|
+
motion.animate(
|
|
50
|
+
{ scale: props.active ? [0.7, 1] : 1, opacity: props.active ? 1 : 0.45 },
|
|
51
|
+
componentMotion(theme.value, 'feedback'),
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
onScopeDispose(motion.use(play))
|
|
55
|
+
watch(() => props.active, play)
|
|
56
|
+
return () =>
|
|
57
|
+
h(ui.Box, {
|
|
58
|
+
width: props.size,
|
|
59
|
+
height: props.size,
|
|
60
|
+
radius: 'full',
|
|
61
|
+
backgroundColor: props.color,
|
|
62
|
+
motionSurface: motion,
|
|
63
|
+
accessibilityHidden: true,
|
|
64
|
+
})
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
const MNavigationRail = defineComponent({
|
|
68
|
+
name: 'MNavigationRail',
|
|
69
|
+
inheritAttrs: false,
|
|
70
|
+
props: navigationRailProps,
|
|
71
|
+
emits: { 'update:collapsed': (_collapsed: boolean) => true, error: (_error: unknown) => true },
|
|
72
|
+
setup(props, { attrs, slots, emit }) {
|
|
73
|
+
const { theme } = useMavisTheme()
|
|
74
|
+
const selection = useComponentSelection(() => props.modelValue)
|
|
75
|
+
const width = ui.railWidth(() => (props.collapsed ? 80 : 256))
|
|
76
|
+
return () => {
|
|
77
|
+
validateRail(props.groups)
|
|
78
|
+
if (!props.label.trim()) throw new TypeError('Navigation rail requires a label.')
|
|
79
|
+
return h(
|
|
80
|
+
ui.Column,
|
|
81
|
+
mergeProps(
|
|
82
|
+
{
|
|
83
|
+
id: props.id,
|
|
84
|
+
gap: 'lg',
|
|
85
|
+
padding: 'sm',
|
|
86
|
+
radius: 'lg',
|
|
87
|
+
...width,
|
|
88
|
+
motionRegion: selection.region,
|
|
89
|
+
backgroundColor: theme.value.colors.surface,
|
|
90
|
+
},
|
|
91
|
+
attrs,
|
|
92
|
+
web
|
|
93
|
+
? {
|
|
94
|
+
class: 'm-navigation-rail',
|
|
95
|
+
role: 'navigation',
|
|
96
|
+
'aria-label': props.label,
|
|
97
|
+
style: { maxWidth: '100%', border: `1px solid ${theme.value.colors.border}` },
|
|
98
|
+
}
|
|
99
|
+
: {
|
|
100
|
+
accessibilityLabel: props.label,
|
|
101
|
+
borderWidth: 1,
|
|
102
|
+
borderColor: theme.value.colors.border,
|
|
103
|
+
},
|
|
104
|
+
),
|
|
105
|
+
() => [
|
|
106
|
+
slots.header?.({ collapsed: props.collapsed }),
|
|
107
|
+
...props.groups.map((group) =>
|
|
108
|
+
h(
|
|
109
|
+
ui.Column,
|
|
110
|
+
{
|
|
111
|
+
key: group.key,
|
|
112
|
+
gap: 'xs',
|
|
113
|
+
...(web ? { role: 'group', 'aria-label': group.label } : {}),
|
|
114
|
+
},
|
|
115
|
+
() => [
|
|
116
|
+
props.collapsed
|
|
117
|
+
? h(ui.Separator, { accessibilityHidden: true })
|
|
118
|
+
: h(ui.Text, {
|
|
119
|
+
text: group.label,
|
|
120
|
+
variant: 'overline',
|
|
121
|
+
tone: 'muted',
|
|
122
|
+
paddingX: 'sm',
|
|
123
|
+
}),
|
|
124
|
+
...group.items.map((item) => {
|
|
125
|
+
const current = item.value === props.modelValue
|
|
126
|
+
const badge = item.badge === undefined ? '' : ` ${item.badge}`
|
|
127
|
+
return h(
|
|
128
|
+
ui.Button,
|
|
129
|
+
{
|
|
130
|
+
key: choiceKey(item.value),
|
|
131
|
+
text: props.collapsed ? undefined : item.label,
|
|
132
|
+
icon: item.icon ?? (props.collapsed ? 'circle' : undefined),
|
|
133
|
+
href: item.href,
|
|
134
|
+
navigate: item.navigate,
|
|
135
|
+
disabled: props.disabled || item.disabled,
|
|
136
|
+
variant: current ? 'secondary' : 'ghost',
|
|
137
|
+
accessibilityLabel: `${item.label}${badge}${current && !web ? `. ${props.currentLabel}` : ''}`,
|
|
138
|
+
...(web
|
|
139
|
+
? {
|
|
140
|
+
'aria-current': current ? 'page' : undefined,
|
|
141
|
+
title: props.collapsed ? `${item.label}${badge}` : undefined,
|
|
142
|
+
style: {
|
|
143
|
+
justifyContent: props.collapsed ? 'center' : 'flex-start',
|
|
144
|
+
minWidth: 0,
|
|
145
|
+
},
|
|
146
|
+
}
|
|
147
|
+
: {}),
|
|
148
|
+
onError: (error: unknown) => emit('error', error),
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
leading: !props.collapsed
|
|
152
|
+
? () =>
|
|
153
|
+
h(ui.Row, { gap: 'sm' }, () => [
|
|
154
|
+
h(ui.Box, {
|
|
155
|
+
motionSurface: current ? selection.marker : undefined,
|
|
156
|
+
width: 6,
|
|
157
|
+
height: 6,
|
|
158
|
+
radius: 'full',
|
|
159
|
+
accessibilityHidden: true,
|
|
160
|
+
backgroundColor: current
|
|
161
|
+
? theme.value.colors.primary
|
|
162
|
+
: theme.value.colors.border,
|
|
163
|
+
size: 6,
|
|
164
|
+
}),
|
|
165
|
+
item.icon ? h(ui.Icon, { name: item.icon, size: 18 }) : null,
|
|
166
|
+
])
|
|
167
|
+
: undefined,
|
|
168
|
+
trailing:
|
|
169
|
+
!props.collapsed && item.badge !== undefined
|
|
170
|
+
? () => [
|
|
171
|
+
web ? ' ' : null,
|
|
172
|
+
h(ui.Badge, {
|
|
173
|
+
text: String(item.badge),
|
|
174
|
+
tone: current ? 'primary' : 'neutral',
|
|
175
|
+
accessibilityHidden: true,
|
|
176
|
+
}),
|
|
177
|
+
]
|
|
178
|
+
: undefined,
|
|
179
|
+
},
|
|
180
|
+
)
|
|
181
|
+
}),
|
|
182
|
+
],
|
|
183
|
+
),
|
|
184
|
+
),
|
|
185
|
+
slots.footer?.({ collapsed: props.collapsed }),
|
|
186
|
+
props.collapsible
|
|
187
|
+
? h(ui.Button, {
|
|
188
|
+
text: props.collapsed ? undefined : props.collapseLabel,
|
|
189
|
+
icon: props.collapsed ? 'panel-left-open' : 'panel-left-close',
|
|
190
|
+
accessibilityLabel: props.collapsed ? props.expandLabel : props.collapseLabel,
|
|
191
|
+
variant: 'ghost',
|
|
192
|
+
disabled: props.disabled,
|
|
193
|
+
...(web ? { 'aria-expanded': !props.collapsed } : {}),
|
|
194
|
+
onClick: () => emit('update:collapsed', !props.collapsed),
|
|
195
|
+
})
|
|
196
|
+
: null,
|
|
197
|
+
],
|
|
198
|
+
)
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
})
|
|
202
|
+
const MBreadcrumb = defineComponent({
|
|
203
|
+
name: 'MBreadcrumb',
|
|
204
|
+
inheritAttrs: false,
|
|
205
|
+
props: breadcrumbProps,
|
|
206
|
+
emits: { error: (_error: unknown) => true },
|
|
207
|
+
setup(props, { attrs, emit }) {
|
|
208
|
+
const expanded = ref(false)
|
|
209
|
+
const layout = useComponentLayout(() => [props.items, expanded.value])
|
|
210
|
+
const links = new Map<string, unknown>()
|
|
211
|
+
watch(
|
|
212
|
+
() => props.items.map((item) => choiceKey(item.key)).join('|'),
|
|
213
|
+
() => {
|
|
214
|
+
expanded.value = false
|
|
215
|
+
},
|
|
216
|
+
)
|
|
217
|
+
return () => {
|
|
218
|
+
if (!props.label.trim()) throw new TypeError('Breadcrumb requires a label.')
|
|
219
|
+
const parts = breadcrumbParts(props.items, props.maxItems)
|
|
220
|
+
const entries =
|
|
221
|
+
expanded.value || !parts.hidden.length
|
|
222
|
+
? props.items
|
|
223
|
+
: [...parts.before, null, ...parts.after]
|
|
224
|
+
return h(
|
|
225
|
+
ui.Row,
|
|
226
|
+
mergeProps(
|
|
227
|
+
{ id: props.id, gap: 'xs', wrap: true, motionRegion: layout },
|
|
228
|
+
attrs,
|
|
229
|
+
web
|
|
230
|
+
? { class: 'm-breadcrumb', role: 'navigation', 'aria-label': props.label }
|
|
231
|
+
: { accessibilityLabel: props.label },
|
|
232
|
+
),
|
|
233
|
+
() =>
|
|
234
|
+
entries.flatMap((item, index) => [
|
|
235
|
+
index
|
|
236
|
+
? h(ui.Icon, {
|
|
237
|
+
key: `separator:${index}`,
|
|
238
|
+
name: 'chevron-right',
|
|
239
|
+
size: 14,
|
|
240
|
+
tone: 'muted',
|
|
241
|
+
accessibilityHidden: true,
|
|
242
|
+
})
|
|
243
|
+
: null,
|
|
244
|
+
item === null
|
|
245
|
+
? h(ui.Button, {
|
|
246
|
+
key: 'expand',
|
|
247
|
+
icon: 'ellipsis',
|
|
248
|
+
accessibilityLabel: props.expandLabel,
|
|
249
|
+
variant: 'ghost',
|
|
250
|
+
size: 'sm',
|
|
251
|
+
onClick: () => {
|
|
252
|
+
expanded.value = true
|
|
253
|
+
const first = parts.hidden[0]
|
|
254
|
+
if (first) void nextTick(() => ui.focus(links.get(choiceKey(first.key))))
|
|
255
|
+
},
|
|
256
|
+
})
|
|
257
|
+
: item === props.items[props.items.length - 1]
|
|
258
|
+
? h(ui.Text, {
|
|
259
|
+
key: choiceKey(item.key),
|
|
260
|
+
text: item.label,
|
|
261
|
+
weight: '600',
|
|
262
|
+
shrink: 1,
|
|
263
|
+
...(web ? { 'aria-current': 'page' } : {}),
|
|
264
|
+
})
|
|
265
|
+
: h(ui.Link, {
|
|
266
|
+
ref: (value: unknown) => {
|
|
267
|
+
if (value) links.set(choiceKey(item.key), value)
|
|
268
|
+
else links.delete(choiceKey(item.key))
|
|
269
|
+
},
|
|
270
|
+
key: choiceKey(item.key),
|
|
271
|
+
text: item.label,
|
|
272
|
+
href: item.href,
|
|
273
|
+
navigate: item.navigate,
|
|
274
|
+
shrink: 1,
|
|
275
|
+
onError: (error: unknown) => emit('error', error),
|
|
276
|
+
}),
|
|
277
|
+
]),
|
|
278
|
+
)
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
})
|
|
282
|
+
const Entry = defineComponent({
|
|
283
|
+
props: {
|
|
284
|
+
item: { type: Object as PropType<TimelineItem>, required: true },
|
|
285
|
+
last: Boolean,
|
|
286
|
+
statusText: String,
|
|
287
|
+
},
|
|
288
|
+
setup(props, { slots }) {
|
|
289
|
+
const { theme } = useMavisTheme()
|
|
290
|
+
const status = computed(() => props.item.status ?? 'complete')
|
|
291
|
+
const color = computed(() =>
|
|
292
|
+
status.value === 'error'
|
|
293
|
+
? theme.value.colors.danger
|
|
294
|
+
: status.value === 'upcoming'
|
|
295
|
+
? theme.value.colors.muted
|
|
296
|
+
: theme.value.colors.primary,
|
|
297
|
+
)
|
|
298
|
+
const connector = useComponentState(() => ({
|
|
299
|
+
scaleY: status.value === 'upcoming' ? 0.15 : 1,
|
|
300
|
+
opacity: status.value === 'upcoming' ? 0.3 : 1,
|
|
301
|
+
}))
|
|
302
|
+
const statusMotion = useComponentState(() => ({
|
|
303
|
+
scale: status.value === 'current' ? 1.08 : 1,
|
|
304
|
+
}))
|
|
305
|
+
const motion = markRaw(createMotionSurface())
|
|
306
|
+
onScopeDispose(
|
|
307
|
+
motion.use((owner) => {
|
|
308
|
+
owner.animate({ y: [10, 0] }, componentMotion(theme.value, 'layout'))
|
|
309
|
+
}),
|
|
310
|
+
)
|
|
311
|
+
return () =>
|
|
312
|
+
h(
|
|
313
|
+
ui.Box,
|
|
314
|
+
{
|
|
315
|
+
motionSurface: motion,
|
|
316
|
+
...(web ? { role: 'listitem', class: 'm-timeline-entry' } : {}),
|
|
317
|
+
},
|
|
318
|
+
() =>
|
|
319
|
+
h(ui.Row, { gap: 'md', align: 'stretch' }, () => [
|
|
320
|
+
h(
|
|
321
|
+
ui.Column,
|
|
322
|
+
{ width: 32, align: 'center', gap: 'xs', shrink: 0, accessibilityHidden: true },
|
|
323
|
+
() => [
|
|
324
|
+
h(
|
|
325
|
+
ui.Box,
|
|
326
|
+
{
|
|
327
|
+
width: 32,
|
|
328
|
+
height: 32,
|
|
329
|
+
motionSurface: statusMotion,
|
|
330
|
+
radius: 'full',
|
|
331
|
+
backgroundColor:
|
|
332
|
+
status.value === 'upcoming'
|
|
333
|
+
? theme.value.colors.surface
|
|
334
|
+
: theme.value.colors.primarySoft,
|
|
335
|
+
},
|
|
336
|
+
() =>
|
|
337
|
+
h(ui.Row, { justify: 'center', height: 32 }, () =>
|
|
338
|
+
h(ui.Icon, {
|
|
339
|
+
name:
|
|
340
|
+
props.item.icon ??
|
|
341
|
+
(status.value === 'complete'
|
|
342
|
+
? 'check'
|
|
343
|
+
: status.value === 'error'
|
|
344
|
+
? 'circle-alert'
|
|
345
|
+
: 'circle-dot'),
|
|
346
|
+
size: 16,
|
|
347
|
+
tone:
|
|
348
|
+
status.value === 'error'
|
|
349
|
+
? 'danger'
|
|
350
|
+
: status.value === 'upcoming'
|
|
351
|
+
? 'muted'
|
|
352
|
+
: 'primary',
|
|
353
|
+
}),
|
|
354
|
+
),
|
|
355
|
+
),
|
|
356
|
+
!props.last
|
|
357
|
+
? h(ui.Box, {
|
|
358
|
+
width: 2,
|
|
359
|
+
grow: 1,
|
|
360
|
+
motionSurface: connector,
|
|
361
|
+
backgroundColor: theme.value.colors.border,
|
|
362
|
+
height: 24,
|
|
363
|
+
})
|
|
364
|
+
: null,
|
|
365
|
+
],
|
|
366
|
+
),
|
|
367
|
+
h(ui.Column, { grow: 1, shrink: 1, gap: 'sm', paddingY: 'xs' }, () => [
|
|
368
|
+
h(ui.Row, { gap: 'sm', wrap: true, justify: 'between' }, () => [
|
|
369
|
+
h(ui.Text, { text: props.item.title, weight: '600', shrink: 1 }),
|
|
370
|
+
props.item.time
|
|
371
|
+
? h(ui.Text, { text: props.item.time, variant: 'caption', tone: 'muted' })
|
|
372
|
+
: null,
|
|
373
|
+
]),
|
|
374
|
+
h(ui.Row, { gap: 'xs' }, () => [
|
|
375
|
+
h(Signal, { color: color.value, active: status.value === 'current', size: 6 }),
|
|
376
|
+
h(ui.Text, {
|
|
377
|
+
text: props.statusText,
|
|
378
|
+
variant: 'caption',
|
|
379
|
+
tone: status.value === 'error' ? 'danger' : 'muted',
|
|
380
|
+
}),
|
|
381
|
+
]),
|
|
382
|
+
props.item.description
|
|
383
|
+
? h(ui.Text, { text: props.item.description, tone: 'muted' })
|
|
384
|
+
: null,
|
|
385
|
+
slots.default?.(),
|
|
386
|
+
!props.last ? h(ui.Box, { height: 16, accessibilityHidden: true }) : null,
|
|
387
|
+
]),
|
|
388
|
+
]),
|
|
389
|
+
)
|
|
390
|
+
},
|
|
391
|
+
})
|
|
392
|
+
const MTimeline = defineComponent({
|
|
393
|
+
name: 'MTimeline',
|
|
394
|
+
inheritAttrs: false,
|
|
395
|
+
props: timelineProps,
|
|
396
|
+
setup(props, { attrs, slots }) {
|
|
397
|
+
const layout = useComponentLayout(() => props.items.map((item) => item.key))
|
|
398
|
+
return () => {
|
|
399
|
+
validateTimeline(props.items)
|
|
400
|
+
if (!props.label.trim()) throw new TypeError('Timeline requires a label.')
|
|
401
|
+
return h(
|
|
402
|
+
ui.Column,
|
|
403
|
+
mergeProps(
|
|
404
|
+
{ id: props.id, gap: 'none', motionRegion: layout },
|
|
405
|
+
attrs,
|
|
406
|
+
web
|
|
407
|
+
? { class: 'm-timeline', role: 'list', 'aria-label': props.label }
|
|
408
|
+
: { accessibilityLabel: props.label },
|
|
409
|
+
),
|
|
410
|
+
() =>
|
|
411
|
+
props.items.length
|
|
412
|
+
? props.items.map((item, index) =>
|
|
413
|
+
h(
|
|
414
|
+
Entry,
|
|
415
|
+
{
|
|
416
|
+
key: choiceKey(item.key),
|
|
417
|
+
item,
|
|
418
|
+
last: index === props.items.length - 1,
|
|
419
|
+
statusText: props.statusLabels[item.status ?? 'complete'],
|
|
420
|
+
},
|
|
421
|
+
() => slots.default?.({ item, index }),
|
|
422
|
+
),
|
|
423
|
+
)
|
|
424
|
+
: h(ui.Text, { text: props.emptyLabel, tone: 'muted' }),
|
|
425
|
+
)
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
})
|
|
429
|
+
return { MNavigationRail, MBreadcrumb, MTimeline }
|
|
430
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { PropType } from '@vue/runtime-core'
|
|
2
|
+
import type { ChoiceValue } from '../choice.js'
|
|
3
|
+
import type {
|
|
4
|
+
BreadcrumbItem,
|
|
5
|
+
CommandItem,
|
|
6
|
+
NavigationGroup,
|
|
7
|
+
TimelineItem,
|
|
8
|
+
TimelineStatus,
|
|
9
|
+
} from '../wayfinding.js'
|
|
10
|
+
import type { ChartCategory, ChartSelection, ChartSeries } from '../chart.js'
|
|
11
|
+
import { buttonProps, sheetProps } from './props.js'
|
|
12
|
+
import type { PopoverPlacement } from '../popover.js'
|
|
13
|
+
|
|
14
|
+
const label = { type: String, required: true as const }
|
|
15
|
+
export const commandPaletteProps = {
|
|
16
|
+
id: String,
|
|
17
|
+
label,
|
|
18
|
+
open: Boolean,
|
|
19
|
+
items: { type: Array as PropType<readonly CommandItem[]>, required: true as const },
|
|
20
|
+
query: { type: String, default: undefined },
|
|
21
|
+
disabled: Boolean,
|
|
22
|
+
loading: Boolean,
|
|
23
|
+
/** Opt-in Cmd/Ctrl+K on Web, ignored in editable elements and other modal dialogs. */
|
|
24
|
+
shortcut: Boolean,
|
|
25
|
+
searchLabel: { type: String, default: 'Search commands' },
|
|
26
|
+
placeholder: { type: String, default: 'What would you like to do?' },
|
|
27
|
+
emptyLabel: { type: String, default: 'No matching commands' },
|
|
28
|
+
loadingLabel: { type: String, default: 'Loading commands' },
|
|
29
|
+
closeLabel: { type: String, default: 'Close commands' },
|
|
30
|
+
returnFocus: sheetProps.returnFocus,
|
|
31
|
+
}
|
|
32
|
+
export const navigationRailProps = {
|
|
33
|
+
id: String,
|
|
34
|
+
label,
|
|
35
|
+
groups: { type: Array as PropType<readonly NavigationGroup[]>, required: true as const },
|
|
36
|
+
modelValue: { type: [String, Number] as PropType<ChoiceValue | null>, default: null },
|
|
37
|
+
collapsed: Boolean,
|
|
38
|
+
disabled: Boolean,
|
|
39
|
+
collapsible: { type: Boolean, default: true },
|
|
40
|
+
collapseLabel: { type: String, default: 'Collapse navigation' },
|
|
41
|
+
expandLabel: { type: String, default: 'Expand navigation' },
|
|
42
|
+
currentLabel: { type: String, default: 'Current page' },
|
|
43
|
+
}
|
|
44
|
+
export const breadcrumbProps = {
|
|
45
|
+
id: String,
|
|
46
|
+
label: { type: String, default: 'Breadcrumb' },
|
|
47
|
+
items: { type: Array as PropType<readonly BreadcrumbItem[]>, required: true as const },
|
|
48
|
+
maxItems: { type: Number, default: 4 },
|
|
49
|
+
expandLabel: { type: String, default: 'Show full path' },
|
|
50
|
+
}
|
|
51
|
+
export const tooltipProps = {
|
|
52
|
+
id: String,
|
|
53
|
+
text: label,
|
|
54
|
+
triggerLabel: label,
|
|
55
|
+
icon: { ...buttonProps.icon, default: 'info' },
|
|
56
|
+
variant: { ...buttonProps.variant, default: 'ghost' },
|
|
57
|
+
disabled: Boolean,
|
|
58
|
+
delay: { type: Number, default: 350 },
|
|
59
|
+
placement: { type: String as PropType<PopoverPlacement>, default: 'top-start' },
|
|
60
|
+
}
|
|
61
|
+
export const timelineProps = {
|
|
62
|
+
id: String,
|
|
63
|
+
label,
|
|
64
|
+
items: { type: Array as PropType<readonly TimelineItem[]>, required: true as const },
|
|
65
|
+
emptyLabel: { type: String, default: 'No activity yet' },
|
|
66
|
+
statusLabels: {
|
|
67
|
+
type: Object as PropType<Record<TimelineStatus, string>>,
|
|
68
|
+
default: () => ({
|
|
69
|
+
complete: 'Complete',
|
|
70
|
+
current: 'In progress',
|
|
71
|
+
upcoming: 'Upcoming',
|
|
72
|
+
error: 'Needs attention',
|
|
73
|
+
}),
|
|
74
|
+
},
|
|
75
|
+
}
|
|
76
|
+
export const chartProps = {
|
|
77
|
+
id: String,
|
|
78
|
+
label,
|
|
79
|
+
description: String,
|
|
80
|
+
categories: { type: Array as PropType<readonly ChartCategory[]>, required: true as const },
|
|
81
|
+
series: { type: Array as PropType<readonly ChartSeries[]>, required: true as const },
|
|
82
|
+
type: { type: String as PropType<'line' | 'bar'>, default: 'line' },
|
|
83
|
+
domain: Array as unknown as PropType<readonly [number, number]>,
|
|
84
|
+
height: { type: Number, default: 240 },
|
|
85
|
+
modelValue: { type: Object as PropType<ChartSelection | null>, default: null },
|
|
86
|
+
disabled: Boolean,
|
|
87
|
+
hiddenSeries: { type: Array as PropType<readonly ChoiceValue[]>, default: () => [] },
|
|
88
|
+
formatValue: Function as PropType<(value: number) => string>,
|
|
89
|
+
showData: { type: Boolean, default: false },
|
|
90
|
+
showDataLabel: { type: String, default: 'Show data' },
|
|
91
|
+
hideDataLabel: { type: String, default: 'Hide data' },
|
|
92
|
+
emptyLabel: { type: String, default: 'No chart data' },
|
|
93
|
+
missingLabel: { type: String, default: 'No value' },
|
|
94
|
+
clearLabel: { type: String, default: 'Clear selection' },
|
|
95
|
+
categoryLabel: { type: String, default: 'Category' },
|
|
96
|
+
seriesLabel: { type: String, default: 'Series' },
|
|
97
|
+
}
|
package/src/vue/workflows.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useComponentLayout, useComponentContent } from './component-motion.js'
|
|
1
2
|
import {
|
|
2
3
|
defineComponent,
|
|
3
4
|
h,
|
|
@@ -32,13 +33,14 @@ export function createWorkflows(ui: Primitives, platform: 'web' | 'native') {
|
|
|
32
33
|
props: formGroupProps,
|
|
33
34
|
setup(props, { attrs, slots }) {
|
|
34
35
|
const generatedId = `m-form-group-${useId()}`
|
|
36
|
+
const layout = useComponentLayout(() => props.description, false)
|
|
35
37
|
return () => {
|
|
36
38
|
if (!props.label.trim()) throw new TypeError('Form groups require a visible label.')
|
|
37
39
|
const id = props.id ?? generatedId
|
|
38
40
|
return h(
|
|
39
41
|
ui.Column,
|
|
40
42
|
mergeProps(
|
|
41
|
-
{ gap: 'md', id },
|
|
43
|
+
{ gap: 'md', id, motionRegion: layout },
|
|
42
44
|
attrs,
|
|
43
45
|
platform === 'web'
|
|
44
46
|
? {
|
|
@@ -68,6 +70,8 @@ export function createWorkflows(ui: Primitives, platform: 'web' | 'native') {
|
|
|
68
70
|
const { theme } = useMavisTheme()
|
|
69
71
|
const id = `m-form-errors-${useId()}`
|
|
70
72
|
const revision = shallowRef(0)
|
|
73
|
+
const layout = useComponentLayout(() => revision.value)
|
|
74
|
+
const arrival = useComponentContent(undefined, true)
|
|
71
75
|
let release: (() => void) | undefined
|
|
72
76
|
watch(
|
|
73
77
|
() => props.form,
|
|
@@ -88,7 +92,14 @@ export function createWorkflows(ui: Primitives, platform: 'web' | 'native') {
|
|
|
88
92
|
return h(
|
|
89
93
|
ui.Column,
|
|
90
94
|
mergeProps(
|
|
91
|
-
{
|
|
95
|
+
{
|
|
96
|
+
gap: 'sm',
|
|
97
|
+
padding: 'md',
|
|
98
|
+
radius: 'md',
|
|
99
|
+
backgroundColor: theme.value.colors.surface,
|
|
100
|
+
motionRegion: layout,
|
|
101
|
+
motionSurface: arrival,
|
|
102
|
+
},
|
|
92
103
|
attrs,
|
|
93
104
|
platform === 'web'
|
|
94
105
|
? { role: props.announce ? 'alert' : 'region', 'aria-labelledby': id }
|
|
@@ -120,13 +131,14 @@ export function createWorkflows(ui: Primitives, platform: 'web' | 'native') {
|
|
|
120
131
|
props: stepsProps,
|
|
121
132
|
emits: { 'update:modelValue': (_value: ChoiceValue) => true },
|
|
122
133
|
setup(props, { attrs, emit }) {
|
|
134
|
+
const layout = useComponentLayout(() => [props.steps, props.modelValue])
|
|
123
135
|
return () => {
|
|
124
136
|
if (!props.label.trim()) throw new TypeError('Steps require a navigation label.')
|
|
125
137
|
validateSteps(props.steps, props.modelValue)
|
|
126
138
|
return h(
|
|
127
139
|
ui.Row,
|
|
128
140
|
mergeProps(
|
|
129
|
-
{ gap: 'sm', wrap: true },
|
|
141
|
+
{ gap: 'sm', wrap: true, motionRegion: layout },
|
|
130
142
|
attrs,
|
|
131
143
|
platform === 'web' ? { role: 'navigation', 'aria-label': props.label } : {},
|
|
132
144
|
),
|
|
@@ -176,6 +188,7 @@ export function createWorkflows(ui: Primitives, platform: 'web' | 'native') {
|
|
|
176
188
|
emits: { 'update:modelValue': (_page: number) => true },
|
|
177
189
|
setup(props, { attrs, emit }) {
|
|
178
190
|
const root = shallowRef<unknown>()
|
|
191
|
+
const layout = useComponentLayout(() => [props.modelValue, props.total, props.pageSize])
|
|
179
192
|
const id = `m-pagination-${useId()}`
|
|
180
193
|
let restore = () => {}
|
|
181
194
|
onBeforeUpdate(() => {
|
|
@@ -212,7 +225,7 @@ export function createWorkflows(ui: Primitives, platform: 'web' | 'native') {
|
|
|
212
225
|
: null,
|
|
213
226
|
state.count === 0 ? h(ui.Text, { tone: 'muted', text: props.emptyLabel }) : null,
|
|
214
227
|
state.outOfRange ? h(ui.Text, { tone: 'danger', text: props.invalidPageLabel }) : null,
|
|
215
|
-
h(ui.Row, { gap: 'sm', wrap: true }, () => [
|
|
228
|
+
h(ui.Row, { gap: 'sm', wrap: true, motionRegion: layout }, () => [
|
|
216
229
|
h(ui.Button, {
|
|
217
230
|
variant: 'secondary',
|
|
218
231
|
text: props.previousLabel,
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { collectionKeys } from './discovery.js'
|
|
2
|
+
import type { ChoiceValue } from './choice.js'
|
|
3
|
+
import type { IconName } from './icon.js'
|
|
4
|
+
import { linkDestination, type LinkNavigate } from './link.js'
|
|
5
|
+
import { validateNavigation, type NavigationItem } from './collections.js'
|
|
6
|
+
|
|
7
|
+
export interface CommandItem {
|
|
8
|
+
value: ChoiceValue
|
|
9
|
+
label: string
|
|
10
|
+
description?: string
|
|
11
|
+
keywords?: readonly string[]
|
|
12
|
+
group?: string
|
|
13
|
+
icon?: IconName
|
|
14
|
+
/** Display hint only. Applications own action-specific keyboard shortcuts. */
|
|
15
|
+
shortcut?: string
|
|
16
|
+
disabled?: boolean
|
|
17
|
+
}
|
|
18
|
+
const searchable = (value: string) =>
|
|
19
|
+
value
|
|
20
|
+
.normalize('NFD')
|
|
21
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
22
|
+
.toLowerCase()
|
|
23
|
+
export function filterCommands(items: readonly CommandItem[], query: string) {
|
|
24
|
+
collectionKeys(items, 'value')
|
|
25
|
+
for (const item of items) if (!item.label.trim()) throw new TypeError('Commands require labels.')
|
|
26
|
+
const terms = searchable(query.trim()).split(/\s+/).filter(Boolean)
|
|
27
|
+
return items.filter((item) => {
|
|
28
|
+
const haystack = searchable(
|
|
29
|
+
[item.label, item.description, item.group, ...(item.keywords ?? [])]
|
|
30
|
+
.filter(Boolean)
|
|
31
|
+
.join(' '),
|
|
32
|
+
)
|
|
33
|
+
return terms.every((term) => haystack.includes(term))
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
export interface NavigationGroup {
|
|
37
|
+
key: string
|
|
38
|
+
label: string
|
|
39
|
+
items: readonly NavigationItem[]
|
|
40
|
+
}
|
|
41
|
+
export function validateRail(groups: readonly NavigationGroup[]) {
|
|
42
|
+
collectionKeys(groups, 'key')
|
|
43
|
+
for (const group of groups)
|
|
44
|
+
if (!group.label.trim()) throw new TypeError('Navigation groups require labels.')
|
|
45
|
+
validateNavigation(groups.flatMap((group) => group.items))
|
|
46
|
+
}
|
|
47
|
+
export interface BreadcrumbItem {
|
|
48
|
+
key: ChoiceValue
|
|
49
|
+
label: string
|
|
50
|
+
/** All ancestors require a destination. The last entry is the current page. */
|
|
51
|
+
href?: string
|
|
52
|
+
navigate?: LinkNavigate
|
|
53
|
+
}
|
|
54
|
+
export function breadcrumbParts(items: readonly BreadcrumbItem[], maxItems: number) {
|
|
55
|
+
collectionKeys(items, 'key')
|
|
56
|
+
if (!Number.isInteger(maxItems) || maxItems < 2)
|
|
57
|
+
throw new RangeError('Breadcrumb maxItems must be an integer of at least 2.')
|
|
58
|
+
items.forEach((item, index) => {
|
|
59
|
+
if (!item.label.trim()) throw new TypeError('Breadcrumb entries require labels.')
|
|
60
|
+
if (index < items.length - 1 && !item.href)
|
|
61
|
+
throw new TypeError('Breadcrumb ancestors require destinations.')
|
|
62
|
+
if (item.href !== undefined) linkDestination(item.href)
|
|
63
|
+
})
|
|
64
|
+
if (items.length <= maxItems) return { before: items, hidden: [], after: [] }
|
|
65
|
+
const split = items.length - maxItems + 1
|
|
66
|
+
return { before: items.slice(0, 1), hidden: items.slice(1, split), after: items.slice(split) }
|
|
67
|
+
}
|
|
68
|
+
export type TimelineStatus = 'complete' | 'current' | 'upcoming' | 'error'
|
|
69
|
+
export interface TimelineItem {
|
|
70
|
+
key: ChoiceValue
|
|
71
|
+
title: string
|
|
72
|
+
description?: string
|
|
73
|
+
/** Application-formatted text: no implicit timezone or date parsing. */
|
|
74
|
+
time?: string
|
|
75
|
+
status?: TimelineStatus
|
|
76
|
+
icon?: IconName
|
|
77
|
+
}
|
|
78
|
+
export function validateTimeline(items: readonly TimelineItem[]) {
|
|
79
|
+
collectionKeys(items, 'key')
|
|
80
|
+
for (const item of items) {
|
|
81
|
+
if (!item.title.trim()) throw new TypeError('Timeline entries require titles.')
|
|
82
|
+
if (item.status && !['complete', 'current', 'upcoming', 'error'].includes(item.status))
|
|
83
|
+
throw new TypeError('Unknown timeline status.')
|
|
84
|
+
}
|
|
85
|
+
}
|