@getcortexlabs/mavis-core 0.1.0-alpha.9 → 0.1.0-rc.12
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 +48 -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/creative-controls.d.ts +47 -0
- package/dist/creative-controls.d.ts.map +1 -0
- package/dist/creative-controls.js +112 -0
- package/dist/creative-controls.js.map +1 -0
- package/dist/dashboard.d.ts +72 -0
- package/dist/dashboard.d.ts.map +1 -0
- package/dist/dashboard.js +115 -0
- package/dist/dashboard.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/index.d.ts +15 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -1
- package/dist/index.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 +2 -0
- package/dist/link.d.ts.map +1 -1
- 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/screen-components.d.ts +45 -0
- package/dist/screen-components.d.ts.map +1 -0
- package/dist/screen-components.js +23 -0
- package/dist/screen-components.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/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/animated-text.d.ts +101 -0
- package/dist/vue/animated-text.d.ts.map +1 -0
- package/dist/vue/animated-text.js +56 -0
- package/dist/vue/animated-text.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 +1708 -21
- package/dist/vue/component-props.d.ts.map +1 -1
- package/dist/vue/component-props.js +50 -0
- package/dist/vue/component-props.js.map +1 -1
- package/dist/vue/composer.d.ts +159 -0
- package/dist/vue/composer.d.ts.map +1 -0
- package/dist/vue/composer.js +142 -0
- package/dist/vue/composer.js.map +1 -0
- package/dist/vue/configurator.d.ts +2 -2
- 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/creative-controls.d.ts +328 -0
- package/dist/vue/creative-controls.d.ts.map +1 -0
- package/dist/vue/creative-controls.js +396 -0
- package/dist/vue/creative-controls.js.map +1 -0
- package/dist/vue/creative-props.d.ts +260 -0
- package/dist/vue/creative-props.d.ts.map +1 -0
- package/dist/vue/creative-props.js +92 -0
- package/dist/vue/creative-props.js.map +1 -0
- package/dist/vue/dashboard-charts.d.ts +240 -0
- package/dist/vue/dashboard-charts.d.ts.map +1 -0
- package/dist/vue/dashboard-charts.js +263 -0
- package/dist/vue/dashboard-charts.js.map +1 -0
- package/dist/vue/dashboard-effects.d.ts +211 -0
- package/dist/vue/dashboard-effects.d.ts.map +1 -0
- package/dist/vue/dashboard-effects.js +235 -0
- package/dist/vue/dashboard-effects.js.map +1 -0
- package/dist/vue/dashboard-props.d.ts +244 -0
- package/dist/vue/dashboard-props.d.ts.map +1 -0
- package/dist/vue/dashboard-props.js +94 -0
- package/dist/vue/dashboard-props.js.map +1 -0
- 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 +8 -8
- package/dist/vue/date-props.d.ts +6 -0
- package/dist/vue/date-props.d.ts.map +1 -1
- package/dist/vue/date-props.js +3 -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 +237 -0
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/index.d.ts +41 -0
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +37 -0
- 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/kanban.d.ts +150 -0
- package/dist/vue/kanban.d.ts.map +1 -0
- package/dist/vue/kanban.js +267 -0
- package/dist/vue/kanban.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/marquee.d.ts +96 -0
- package/dist/vue/marquee.d.ts.map +1 -0
- package/dist/vue/marquee.js +186 -0
- package/dist/vue/marquee.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/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/pin-cell.d.ts +14 -0
- package/dist/vue/pin-cell.d.ts.map +1 -0
- package/dist/vue/pin-cell.js +19 -0
- package/dist/vue/pin-cell.js.map +1 -0
- package/dist/vue/pin-input.d.ts +14 -0
- package/dist/vue/pin-input.d.ts.map +1 -0
- package/dist/vue/pin-input.js +23 -0
- package/dist/vue/pin-input.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 +82 -42
- package/dist/vue/props.d.ts.map +1 -1
- package/dist/vue/props.js +3 -1
- package/dist/vue/props.js.map +1 -1
- package/dist/vue/screen-component-props.d.ts +236 -0
- package/dist/vue/screen-component-props.d.ts.map +1 -0
- package/dist/vue/screen-component-props.js +90 -0
- package/dist/vue/screen-component-props.js.map +1 -0
- package/dist/vue/scroll-frame.d.ts +223 -0
- package/dist/vue/scroll-frame.d.ts.map +1 -0
- package/dist/vue/scroll-frame.js +346 -0
- package/dist/vue/scroll-frame.js.map +1 -0
- 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/speed-dial.d.ts +73 -0
- package/dist/vue/speed-dial.d.ts.map +1 -0
- package/dist/vue/speed-dial.js +78 -0
- package/dist/vue/speed-dial.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/swipe-deck.d.ts +120 -0
- package/dist/vue/swipe-deck.d.ts.map +1 -0
- package/dist/vue/swipe-deck.js +229 -0
- package/dist/vue/swipe-deck.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/tour.d.ts +120 -0
- package/dist/vue/tour.d.ts.map +1 -0
- package/dist/vue/tour.js +165 -0
- package/dist/vue/tour.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 +50 -4
- package/src/chart.ts +151 -0
- package/src/collections.ts +87 -0
- package/src/contracts.ts +2 -0
- package/src/creative-controls.ts +169 -0
- package/src/dashboard.ts +164 -0
- package/src/discovery.ts +139 -0
- package/src/experimental-regions.ts +29 -0
- package/src/experimental.ts +40 -0
- package/src/index.ts +23 -1
- package/src/interactive.ts +91 -0
- package/src/link.ts +2 -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/screen-components.ts +59 -0
- package/src/section-scroll.ts +46 -0
- package/src/time.ts +83 -0
- package/src/vue/animated-text.ts +72 -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 +104 -0
- package/src/vue/composer.ts +192 -0
- package/src/vue/configurator.ts +3 -1
- package/src/vue/creative-controls.ts +524 -0
- package/src/vue/creative-props.ts +94 -0
- package/src/vue/dashboard-charts.ts +346 -0
- package/src/vue/dashboard-effects.ts +304 -0
- package/src/vue/dashboard-props.ts +95 -0
- package/src/vue/data-table.ts +190 -0
- package/src/vue/date-calendar.ts +30 -1
- package/src/vue/date-props.ts +3 -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 +237 -0
- package/src/vue/index.ts +64 -0
- package/src/vue/interactive-components.ts +29 -0
- package/src/vue/interactive-props.ts +90 -0
- package/src/vue/kanban.ts +360 -0
- package/src/vue/list-motion.ts +31 -0
- package/src/vue/marquee.ts +248 -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/number-flow.ts +83 -0
- package/src/vue/partition.ts +49 -0
- package/src/vue/pin-cell.ts +26 -0
- package/src/vue/pin-input.ts +31 -0
- package/src/vue/platform.ts +73 -0
- package/src/vue/props.ts +3 -1
- package/src/vue/screen-component-props.ts +92 -0
- package/src/vue/scroll-frame.ts +429 -0
- package/src/vue/sortable-list.ts +308 -0
- package/src/vue/speed-dial.ts +108 -0
- package/src/vue/swipe-actions.ts +226 -0
- package/src/vue/swipe-deck.ts +277 -0
- package/src/vue/time-picker.ts +227 -0
- package/src/vue/tour.ts +239 -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
package/src/vue/tour.ts
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
defineComponent,
|
|
4
|
+
h,
|
|
5
|
+
inject,
|
|
6
|
+
mergeProps,
|
|
7
|
+
nextTick,
|
|
8
|
+
onMounted,
|
|
9
|
+
onScopeDispose,
|
|
10
|
+
provide,
|
|
11
|
+
reactive,
|
|
12
|
+
ref,
|
|
13
|
+
watch,
|
|
14
|
+
type Component,
|
|
15
|
+
type InjectionKey,
|
|
16
|
+
} from '@vue/runtime-core'
|
|
17
|
+
import { validateTour, type TourStep } from '../creative-controls.js'
|
|
18
|
+
import { tourProps, tourTargetProps } from './creative-props.js'
|
|
19
|
+
import { useComponentState } from './component-motion.js'
|
|
20
|
+
import { useMavisTheme } from './theme.js'
|
|
21
|
+
|
|
22
|
+
interface TourContext {
|
|
23
|
+
current(): TourStep | undefined
|
|
24
|
+
register(id: string): () => void
|
|
25
|
+
panel(): ReturnType<typeof h>
|
|
26
|
+
close(reason: string): void
|
|
27
|
+
animated(): boolean
|
|
28
|
+
}
|
|
29
|
+
const tourKey: InjectionKey<TourContext> = Symbol('mavis-tour')
|
|
30
|
+
export const tourHostProps = { active: Boolean, restoreFocus: { type: Boolean, default: true } }
|
|
31
|
+
export function createTour(
|
|
32
|
+
ui: {
|
|
33
|
+
Column: Component
|
|
34
|
+
Row: Component
|
|
35
|
+
Box: Component
|
|
36
|
+
Text: Component
|
|
37
|
+
Button: Component
|
|
38
|
+
Popover: Component
|
|
39
|
+
Host: Component
|
|
40
|
+
TargetHost: Component
|
|
41
|
+
},
|
|
42
|
+
platform: 'web' | 'native',
|
|
43
|
+
) {
|
|
44
|
+
const MTour = defineComponent({
|
|
45
|
+
name: 'MTour',
|
|
46
|
+
inheritAttrs: false,
|
|
47
|
+
props: tourProps,
|
|
48
|
+
emits: {
|
|
49
|
+
'update:modelValue': (_id: string | null) => true,
|
|
50
|
+
finish: (_reason: string) => true,
|
|
51
|
+
missing: (_id: string) => true,
|
|
52
|
+
},
|
|
53
|
+
setup(props, { attrs, slots, emit }) {
|
|
54
|
+
const targets = reactive(new Set<string>())
|
|
55
|
+
const index = computed(() =>
|
|
56
|
+
validateTour(props.steps).findIndex((step) => step.id === props.modelValue),
|
|
57
|
+
)
|
|
58
|
+
const step = computed(() => props.steps[index.value])
|
|
59
|
+
let mounted = false,
|
|
60
|
+
generation = 0
|
|
61
|
+
const closeReason = ref('')
|
|
62
|
+
watch(
|
|
63
|
+
() => props.modelValue,
|
|
64
|
+
(value) => {
|
|
65
|
+
if (value !== null) closeReason.value = ''
|
|
66
|
+
},
|
|
67
|
+
)
|
|
68
|
+
function close(reason: string) {
|
|
69
|
+
if (props.modelValue === null) return
|
|
70
|
+
closeReason.value = reason
|
|
71
|
+
emit('update:modelValue', null)
|
|
72
|
+
emit('finish', reason)
|
|
73
|
+
}
|
|
74
|
+
function move(direction: number) {
|
|
75
|
+
for (let i = index.value + direction; i >= 0 && i < props.steps.length; i += direction) {
|
|
76
|
+
const next = props.steps[i]!
|
|
77
|
+
if (targets.has(next.id)) {
|
|
78
|
+
emit('update:modelValue', next.id)
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
emit('missing', next.id)
|
|
82
|
+
}
|
|
83
|
+
close(direction > 0 ? 'complete' : 'missing')
|
|
84
|
+
}
|
|
85
|
+
async function check() {
|
|
86
|
+
const token = ++generation
|
|
87
|
+
await nextTick()
|
|
88
|
+
if (!mounted || token !== generation || props.modelValue === null) return
|
|
89
|
+
if (!step.value || !targets.has(step.value.id)) {
|
|
90
|
+
emit('missing', props.modelValue)
|
|
91
|
+
move(1)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
provide(tourKey, {
|
|
95
|
+
current: () => step.value,
|
|
96
|
+
animated: () => props.animated,
|
|
97
|
+
register(id) {
|
|
98
|
+
if (!id.trim() || targets.has(id))
|
|
99
|
+
throw new TypeError('Tour target names must be nonempty and unique within a tour.')
|
|
100
|
+
targets.add(id)
|
|
101
|
+
return () => targets.delete(id)
|
|
102
|
+
},
|
|
103
|
+
close,
|
|
104
|
+
panel: () =>
|
|
105
|
+
h(
|
|
106
|
+
ui.Column,
|
|
107
|
+
{ gap: 'md' },
|
|
108
|
+
{
|
|
109
|
+
default: () => [
|
|
110
|
+
h(ui.Text, {
|
|
111
|
+
text: `${props.label} · ${index.value + 1} / ${props.steps.length}`,
|
|
112
|
+
variant: 'caption',
|
|
113
|
+
tone: 'muted',
|
|
114
|
+
}),
|
|
115
|
+
h(ui.Text, { text: step.value?.title, variant: 'heading' }),
|
|
116
|
+
h(ui.Text, { text: step.value?.description }),
|
|
117
|
+
h(
|
|
118
|
+
ui.Row,
|
|
119
|
+
{ gap: 'xs', wrap: true },
|
|
120
|
+
{
|
|
121
|
+
default: () => [
|
|
122
|
+
h(ui.Button, {
|
|
123
|
+
text: props.backLabel,
|
|
124
|
+
variant: 'secondary',
|
|
125
|
+
disabled: index.value <= 0,
|
|
126
|
+
onClick: () => move(-1),
|
|
127
|
+
}),
|
|
128
|
+
h(ui.Button, {
|
|
129
|
+
text:
|
|
130
|
+
index.value === props.steps.length - 1
|
|
131
|
+
? props.finishLabel
|
|
132
|
+
: props.nextLabel,
|
|
133
|
+
onClick: () => move(1),
|
|
134
|
+
}),
|
|
135
|
+
h(ui.Button, {
|
|
136
|
+
text: props.skipLabel,
|
|
137
|
+
variant: 'ghost',
|
|
138
|
+
onClick: () => close('skip'),
|
|
139
|
+
}),
|
|
140
|
+
],
|
|
141
|
+
},
|
|
142
|
+
),
|
|
143
|
+
],
|
|
144
|
+
},
|
|
145
|
+
),
|
|
146
|
+
})
|
|
147
|
+
watch(() => [props.modelValue, props.steps, [...targets]], check, {
|
|
148
|
+
flush: 'post',
|
|
149
|
+
deep: true,
|
|
150
|
+
})
|
|
151
|
+
onMounted(() => {
|
|
152
|
+
mounted = true
|
|
153
|
+
void check()
|
|
154
|
+
})
|
|
155
|
+
onScopeDispose(() => {
|
|
156
|
+
mounted = false
|
|
157
|
+
generation++
|
|
158
|
+
})
|
|
159
|
+
return () =>
|
|
160
|
+
h(
|
|
161
|
+
ui.Host,
|
|
162
|
+
mergeProps(attrs, {
|
|
163
|
+
id: props.id,
|
|
164
|
+
active: props.modelValue !== null,
|
|
165
|
+
restoreFocus: closeReason.value !== 'outside',
|
|
166
|
+
...(platform === 'web' ? { class: 'm-tour' } : {}),
|
|
167
|
+
}),
|
|
168
|
+
slots,
|
|
169
|
+
)
|
|
170
|
+
},
|
|
171
|
+
})
|
|
172
|
+
const MTourTarget = defineComponent({
|
|
173
|
+
name: 'MTourTarget',
|
|
174
|
+
inheritAttrs: false,
|
|
175
|
+
props: tourTargetProps,
|
|
176
|
+
setup(props, { attrs, slots }) {
|
|
177
|
+
const context = inject(tourKey)
|
|
178
|
+
if (!context) throw new Error('MTourTarget must be inside MTour.')
|
|
179
|
+
const { theme } = useMavisTheme()
|
|
180
|
+
const active = computed(() => context.current()?.id === props.name)
|
|
181
|
+
const surface = useComponentState(() => ({ opacity: active.value ? 1 : 0.55 }), 'selection')
|
|
182
|
+
let release = () => {}
|
|
183
|
+
watch(
|
|
184
|
+
() => props.name,
|
|
185
|
+
(name) => {
|
|
186
|
+
release()
|
|
187
|
+
release = context.register(name)
|
|
188
|
+
},
|
|
189
|
+
{ immediate: true },
|
|
190
|
+
)
|
|
191
|
+
onScopeDispose(() => release())
|
|
192
|
+
return () =>
|
|
193
|
+
h(
|
|
194
|
+
ui.TargetHost,
|
|
195
|
+
mergeProps(attrs, {
|
|
196
|
+
active: active.value,
|
|
197
|
+
...(platform === 'web'
|
|
198
|
+
? { class: 'm-tour-target', 'data-tour-target': props.name }
|
|
199
|
+
: {}),
|
|
200
|
+
}),
|
|
201
|
+
{
|
|
202
|
+
default: () =>
|
|
203
|
+
h(
|
|
204
|
+
ui.Popover,
|
|
205
|
+
{
|
|
206
|
+
open: active.value,
|
|
207
|
+
label: context.current()?.title ?? props.name,
|
|
208
|
+
triggerLabel: props.name,
|
|
209
|
+
width: 320,
|
|
210
|
+
onClose: (reason: string) => {
|
|
211
|
+
if (active.value) context.close(reason)
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
anchor: () =>
|
|
216
|
+
h(
|
|
217
|
+
ui.Box,
|
|
218
|
+
{
|
|
219
|
+
padding: 'xs',
|
|
220
|
+
radius: 'md',
|
|
221
|
+
borderWidth: 2,
|
|
222
|
+
borderColor: active.value ? theme.value.colors.primary : 'transparent',
|
|
223
|
+
},
|
|
224
|
+
{ default: () => slots.default?.({ active: active.value }) },
|
|
225
|
+
),
|
|
226
|
+
default: () =>
|
|
227
|
+
h(
|
|
228
|
+
ui.Column,
|
|
229
|
+
{ motionSurface: context.animated() ? surface : undefined, gap: 'sm' },
|
|
230
|
+
{ default: () => context.panel() },
|
|
231
|
+
),
|
|
232
|
+
},
|
|
233
|
+
),
|
|
234
|
+
},
|
|
235
|
+
)
|
|
236
|
+
},
|
|
237
|
+
})
|
|
238
|
+
return { MTour, MTourTarget }
|
|
239
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { useComponentLayout, useComponentState } from './component-motion.js'
|
|
2
|
+
import {
|
|
3
|
+
computed,
|
|
4
|
+
defineComponent,
|
|
5
|
+
h,
|
|
6
|
+
mergeProps,
|
|
7
|
+
nextTick,
|
|
8
|
+
ref,
|
|
9
|
+
watch,
|
|
10
|
+
useId,
|
|
11
|
+
type Component,
|
|
12
|
+
type PropType,
|
|
13
|
+
} from '@vue/runtime-core'
|
|
14
|
+
import { choiceKey, type ChoiceValue } from '../choice.js'
|
|
15
|
+
import { treeBranch, treeEntries, type TreeNode } from '../discovery.js'
|
|
16
|
+
import { treeViewProps } from './discovery-props.js'
|
|
17
|
+
import { useMavisTheme } from './theme.js'
|
|
18
|
+
|
|
19
|
+
export function createTreeView(
|
|
20
|
+
ui: {
|
|
21
|
+
Column: Component
|
|
22
|
+
Row: Component
|
|
23
|
+
Text: Component
|
|
24
|
+
Button: Component
|
|
25
|
+
Reveal: Component
|
|
26
|
+
Icon: Component
|
|
27
|
+
focus?: (id: string) => void
|
|
28
|
+
containsFocus?: (id: string) => boolean
|
|
29
|
+
},
|
|
30
|
+
platform: 'web' | 'native',
|
|
31
|
+
) {
|
|
32
|
+
const BranchChildren = defineComponent({
|
|
33
|
+
props: { nodes: { type: Array as PropType<readonly TreeNode[]>, required: true } },
|
|
34
|
+
setup(props, { slots }) {
|
|
35
|
+
const region = useComponentLayout(() => props.nodes.map((node) => node.key))
|
|
36
|
+
return () =>
|
|
37
|
+
h(
|
|
38
|
+
ui.Column,
|
|
39
|
+
{ gap: 'xs', motionRegion: region, ...(platform === 'web' ? { role: 'group' } : {}) },
|
|
40
|
+
slots,
|
|
41
|
+
)
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
const BranchToggle = defineComponent({
|
|
45
|
+
props: { expanded: Boolean },
|
|
46
|
+
setup(props, { attrs }) {
|
|
47
|
+
const surface = useComponentState(() => ({ rotate: props.expanded ? 90 : 0 }))
|
|
48
|
+
return () =>
|
|
49
|
+
h(
|
|
50
|
+
ui.Button,
|
|
51
|
+
{ ...attrs, variant: 'ghost' },
|
|
52
|
+
{
|
|
53
|
+
leading: () =>
|
|
54
|
+
h(ui.Icon, {
|
|
55
|
+
name: 'chevron-right',
|
|
56
|
+
size: 18,
|
|
57
|
+
motionSurface: surface,
|
|
58
|
+
accessibilityHidden: true,
|
|
59
|
+
}),
|
|
60
|
+
},
|
|
61
|
+
)
|
|
62
|
+
},
|
|
63
|
+
})
|
|
64
|
+
return defineComponent({
|
|
65
|
+
name: 'MTreeView',
|
|
66
|
+
inheritAttrs: false,
|
|
67
|
+
props: treeViewProps,
|
|
68
|
+
emits: {
|
|
69
|
+
'update:modelValue': (_key: ChoiceValue) => true,
|
|
70
|
+
'update:expanded': (_keys: ChoiceValue[]) => true,
|
|
71
|
+
load: (_node: TreeNode) => true,
|
|
72
|
+
},
|
|
73
|
+
setup(props, { attrs, emit }) {
|
|
74
|
+
const { theme } = useMavisTheme()
|
|
75
|
+
const layout = useComponentLayout(() => props.nodes.map((node) => node.key))
|
|
76
|
+
const treeId = `m-tree-${useId()}`
|
|
77
|
+
const entries = computed(() => treeEntries(props.nodes, props.expanded))
|
|
78
|
+
const focused = ref<ChoiceValue | null>(props.modelValue)
|
|
79
|
+
const idFor = (key: ChoiceValue) => `${treeId}-${encodeURIComponent(choiceKey(key))}`
|
|
80
|
+
function isOpen(key: ChoiceValue) {
|
|
81
|
+
return props.expanded.includes(key)
|
|
82
|
+
}
|
|
83
|
+
function select(node: TreeNode) {
|
|
84
|
+
if (!props.disabled && !node.disabled) emit('update:modelValue', node.key)
|
|
85
|
+
}
|
|
86
|
+
function toggle(node: TreeNode, open = !isOpen(node.key)) {
|
|
87
|
+
if (
|
|
88
|
+
props.disabled ||
|
|
89
|
+
node.disabled ||
|
|
90
|
+
!treeBranch(node) ||
|
|
91
|
+
props.loadingKeys.includes(node.key)
|
|
92
|
+
)
|
|
93
|
+
return
|
|
94
|
+
if (open === isOpen(node.key)) return
|
|
95
|
+
emit(
|
|
96
|
+
'update:expanded',
|
|
97
|
+
open ? [...props.expanded, node.key] : props.expanded.filter((key) => key !== node.key),
|
|
98
|
+
)
|
|
99
|
+
if (open && node.children === undefined) emit('load', node)
|
|
100
|
+
}
|
|
101
|
+
function focus(key: ChoiceValue) {
|
|
102
|
+
focused.value = key
|
|
103
|
+
void nextTick(() => ui.focus?.(idFor(key)))
|
|
104
|
+
}
|
|
105
|
+
watch(
|
|
106
|
+
entries,
|
|
107
|
+
(visible, previous) => {
|
|
108
|
+
if (visible.some((entry) => entry.node.key === focused.value)) return
|
|
109
|
+
const restore = focused.value !== null && ui.containsFocus?.(idFor(focused.value))
|
|
110
|
+
// Prefer the collapsed ancestor; never reset a retained logical node by array index.
|
|
111
|
+
let parent = previous?.find((entry) => entry.node.key === focused.value)?.parent
|
|
112
|
+
while (parent != null && !visible.some((entry) => entry.node.key === parent))
|
|
113
|
+
parent = previous?.find((entry) => entry.node.key === parent)?.parent
|
|
114
|
+
focused.value = parent ?? visible.find((entry) => !entry.node.disabled)?.node.key ?? null
|
|
115
|
+
if (restore && focused.value !== null) focus(focused.value)
|
|
116
|
+
},
|
|
117
|
+
{ immediate: true },
|
|
118
|
+
)
|
|
119
|
+
function keydown(event: KeyboardEvent, node: TreeNode) {
|
|
120
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.isComposing || props.disabled)
|
|
121
|
+
return
|
|
122
|
+
const visible = entries.value.filter((entry) => !entry.node.disabled)
|
|
123
|
+
const index = visible.findIndex((entry) => entry.node.key === node.key)
|
|
124
|
+
let next: ChoiceValue | undefined
|
|
125
|
+
if (event.key === 'ArrowDown')
|
|
126
|
+
next = visible[Math.min(visible.length - 1, index + 1)]?.node.key
|
|
127
|
+
else if (event.key === 'ArrowUp') next = visible[Math.max(0, index - 1)]?.node.key
|
|
128
|
+
else if (event.key === 'Home') next = visible[0]?.node.key
|
|
129
|
+
else if (event.key === 'End') next = visible.at(-1)?.node.key
|
|
130
|
+
else if (event.key === 'ArrowRight') {
|
|
131
|
+
if (!isOpen(node.key)) toggle(node, true)
|
|
132
|
+
else next = node.children?.find((child) => !child.disabled)?.key
|
|
133
|
+
} else if (event.key === 'ArrowLeft') {
|
|
134
|
+
if (isOpen(node.key)) toggle(node, false)
|
|
135
|
+
else
|
|
136
|
+
next = entries.value.find((entry) => entry.node.key === node.key)?.parent ?? undefined
|
|
137
|
+
} else if (event.key === 'Enter' || event.key === ' ') select(node)
|
|
138
|
+
else if (event.key.length === 1) {
|
|
139
|
+
const order = [...visible.slice(index + 1), ...visible.slice(0, index + 1)]
|
|
140
|
+
next = order.find((entry) =>
|
|
141
|
+
entry.node.label.toLocaleLowerCase().startsWith(event.key.toLocaleLowerCase()),
|
|
142
|
+
)?.node.key
|
|
143
|
+
} else return
|
|
144
|
+
event.preventDefault()
|
|
145
|
+
if (next !== undefined) focus(next)
|
|
146
|
+
}
|
|
147
|
+
function render(nodes: readonly TreeNode[], level = 1): ReturnType<typeof h>[] {
|
|
148
|
+
return nodes.map((node, index) => {
|
|
149
|
+
const branch = treeBranch(node),
|
|
150
|
+
open = isOpen(node.key),
|
|
151
|
+
selected = props.modelValue === node.key
|
|
152
|
+
const busy = props.loadingKeys.includes(node.key)
|
|
153
|
+
const unavailable = props.disabled || node.disabled
|
|
154
|
+
return h(ui.Column, { key: choiceKey(node.key), gap: 'none' }, () => [
|
|
155
|
+
h(
|
|
156
|
+
ui.Row,
|
|
157
|
+
{
|
|
158
|
+
id: idFor(node.key),
|
|
159
|
+
gap: 'xs',
|
|
160
|
+
padding: 'xs',
|
|
161
|
+
radius: 'md',
|
|
162
|
+
backgroundColor: selected ? theme.value.colors.primarySoft : 'transparent',
|
|
163
|
+
...(platform === 'web'
|
|
164
|
+
? {
|
|
165
|
+
role: 'treeitem',
|
|
166
|
+
tabindex: !unavailable && focused.value === node.key ? 0 : -1,
|
|
167
|
+
'aria-level': level,
|
|
168
|
+
'aria-posinset': index + 1,
|
|
169
|
+
'aria-setsize': nodes.length,
|
|
170
|
+
'aria-selected': selected,
|
|
171
|
+
'aria-expanded': branch ? open : undefined,
|
|
172
|
+
'aria-disabled': unavailable || undefined,
|
|
173
|
+
'aria-busy': busy || undefined,
|
|
174
|
+
'aria-label': node.label,
|
|
175
|
+
onFocus: () => {
|
|
176
|
+
focused.value = node.key
|
|
177
|
+
},
|
|
178
|
+
onKeydown: (event: KeyboardEvent) => keydown(event, node),
|
|
179
|
+
}
|
|
180
|
+
: {}),
|
|
181
|
+
},
|
|
182
|
+
() => [
|
|
183
|
+
branch
|
|
184
|
+
? h(BranchToggle, {
|
|
185
|
+
expanded: open,
|
|
186
|
+
variant: 'ghost',
|
|
187
|
+
accessibilityLabel: `${node.label}: ${open ? props.expandedLabel : props.collapsedLabel}`,
|
|
188
|
+
disabled: unavailable || busy,
|
|
189
|
+
...(platform === 'web' ? { tabindex: -1 } : {}),
|
|
190
|
+
onClick: () => toggle(node),
|
|
191
|
+
})
|
|
192
|
+
: h(ui.Icon, { name: 'file', tone: 'muted', size: 18, style: { margin: 12 } }),
|
|
193
|
+
h(ui.Button, {
|
|
194
|
+
text: node.label,
|
|
195
|
+
style:
|
|
196
|
+
platform === 'web'
|
|
197
|
+
? { justifyContent: 'flex-start', textAlign: 'start' }
|
|
198
|
+
: { textAlignment: 'left' },
|
|
199
|
+
variant: 'ghost',
|
|
200
|
+
grow: platform === 'web' ? 1 : 0,
|
|
201
|
+
shrink: 1,
|
|
202
|
+
disabled: unavailable,
|
|
203
|
+
...(platform === 'web'
|
|
204
|
+
? { tabindex: -1 }
|
|
205
|
+
: { accessibilityValue: selected ? 'Selected' : '' }),
|
|
206
|
+
onClick: () => select(node),
|
|
207
|
+
}),
|
|
208
|
+
busy
|
|
209
|
+
? h(ui.Text, { text: props.loadingLabel, variant: 'caption', tone: 'muted' })
|
|
210
|
+
: null,
|
|
211
|
+
],
|
|
212
|
+
),
|
|
213
|
+
branch
|
|
214
|
+
? h(
|
|
215
|
+
ui.Reveal,
|
|
216
|
+
{
|
|
217
|
+
show: open,
|
|
218
|
+
style:
|
|
219
|
+
platform === 'web'
|
|
220
|
+
? { paddingInlineStart: `${theme.value.space.lg}px` }
|
|
221
|
+
: { paddingLeft: theme.value.space.lg },
|
|
222
|
+
},
|
|
223
|
+
() =>
|
|
224
|
+
h(BranchChildren, { nodes: node.children ?? [] }, () =>
|
|
225
|
+
render(node.children ?? [], level + 1),
|
|
226
|
+
),
|
|
227
|
+
)
|
|
228
|
+
: null,
|
|
229
|
+
])
|
|
230
|
+
})
|
|
231
|
+
}
|
|
232
|
+
return () => {
|
|
233
|
+
void entries.value
|
|
234
|
+
return h(
|
|
235
|
+
ui.Column,
|
|
236
|
+
mergeProps(
|
|
237
|
+
{ id: props.id, gap: 'sm' },
|
|
238
|
+
attrs,
|
|
239
|
+
platform === 'web' ? { class: 'm-tree-view' } : {},
|
|
240
|
+
),
|
|
241
|
+
() => [
|
|
242
|
+
h(ui.Text, { as: 'h2', variant: 'heading', text: props.label }),
|
|
243
|
+
props.nodes.length
|
|
244
|
+
? h(
|
|
245
|
+
ui.Column,
|
|
246
|
+
{
|
|
247
|
+
gap: 'xs',
|
|
248
|
+
motionRegion: layout,
|
|
249
|
+
...(platform === 'web' ? { role: 'tree', 'aria-label': props.label } : {}),
|
|
250
|
+
},
|
|
251
|
+
() => render(props.nodes),
|
|
252
|
+
)
|
|
253
|
+
: h(ui.Text, { text: props.emptyLabel, tone: 'muted' }),
|
|
254
|
+
],
|
|
255
|
+
)
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
})
|
|
259
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { VNode, VNodeChild, PublicProps } from '@vue/runtime-core'
|
|
2
|
+
import type { ChoiceValue } from '../choice.js'
|
|
3
|
+
import type { VirtualItemSlot, VirtualListHandle } from '../collections.js'
|
|
4
|
+
import type { ComponentProps } from './component-props.js'
|
|
5
|
+
|
|
6
|
+
/** Both renderers expose the same item type to template slots and key callbacks. */
|
|
7
|
+
type VirtualListProps<T> = PublicProps &
|
|
8
|
+
Omit<ComponentProps['MVirtualList'], 'items' | 'itemKey'> & {
|
|
9
|
+
items: readonly T[]
|
|
10
|
+
itemKey?: Extract<keyof T, string> | ((item: T) => ChoiceValue)
|
|
11
|
+
}
|
|
12
|
+
type VirtualListContext<T> = {
|
|
13
|
+
props: VirtualListProps<T>
|
|
14
|
+
attrs: Record<string, unknown>
|
|
15
|
+
emit: (event: string, ...args: unknown[]) => void
|
|
16
|
+
slots: { default?: (scope: VirtualItemSlot<T>) => VNodeChild; empty?: () => VNodeChild }
|
|
17
|
+
expose(exposed: VirtualListHandle): void
|
|
18
|
+
}
|
|
19
|
+
export interface VirtualListComponent {
|
|
20
|
+
<T>(
|
|
21
|
+
props: NonNullable<Awaited<typeof setup>>['props'],
|
|
22
|
+
context?: Pick<NonNullable<Awaited<typeof setup>>, 'attrs' | 'emit' | 'slots'>,
|
|
23
|
+
exposed?: NonNullable<Awaited<typeof setup>>['expose'],
|
|
24
|
+
setup?: Promise<VirtualListContext<T>>,
|
|
25
|
+
): VNode & {
|
|
26
|
+
__ctx?: NonNullable<Awaited<typeof setup>>
|
|
27
|
+
}
|
|
28
|
+
}
|