@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.
Files changed (340) hide show
  1. package/README.md +2 -2
  2. package/dist/capabilities.d.ts +7 -7
  3. package/dist/capabilities.d.ts.map +1 -1
  4. package/dist/capabilities.js +48 -4
  5. package/dist/capabilities.js.map +1 -1
  6. package/dist/chart.d.ts +43 -0
  7. package/dist/chart.d.ts.map +1 -0
  8. package/dist/chart.js +105 -0
  9. package/dist/chart.js.map +1 -0
  10. package/dist/collections.d.ts +46 -0
  11. package/dist/collections.d.ts.map +1 -0
  12. package/dist/collections.js +48 -0
  13. package/dist/collections.js.map +1 -0
  14. package/dist/contracts.d.ts +20 -0
  15. package/dist/contracts.d.ts.map +1 -1
  16. package/dist/contracts.js +2 -0
  17. package/dist/contracts.js.map +1 -1
  18. package/dist/creative-controls.d.ts +47 -0
  19. package/dist/creative-controls.d.ts.map +1 -0
  20. package/dist/creative-controls.js +112 -0
  21. package/dist/creative-controls.js.map +1 -0
  22. package/dist/dashboard.d.ts +72 -0
  23. package/dist/dashboard.d.ts.map +1 -0
  24. package/dist/dashboard.js +115 -0
  25. package/dist/dashboard.js.map +1 -0
  26. package/dist/discovery.d.ts +49 -0
  27. package/dist/discovery.d.ts.map +1 -0
  28. package/dist/discovery.js +80 -0
  29. package/dist/discovery.js.map +1 -0
  30. package/dist/experimental-regions.d.ts +10 -0
  31. package/dist/experimental-regions.d.ts.map +1 -1
  32. package/dist/experimental-regions.js +23 -0
  33. package/dist/experimental-regions.js.map +1 -1
  34. package/dist/experimental.d.ts +5 -0
  35. package/dist/experimental.d.ts.map +1 -1
  36. package/dist/experimental.js +29 -0
  37. package/dist/experimental.js.map +1 -1
  38. package/dist/index.d.ts +15 -1
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +13 -1
  41. package/dist/index.js.map +1 -1
  42. package/dist/interactive.d.ts +36 -0
  43. package/dist/interactive.d.ts.map +1 -0
  44. package/dist/interactive.js +61 -0
  45. package/dist/interactive.js.map +1 -0
  46. package/dist/link.d.ts +2 -0
  47. package/dist/link.d.ts.map +1 -1
  48. package/dist/link.js.map +1 -1
  49. package/dist/motion.d.ts +8 -0
  50. package/dist/motion.d.ts.map +1 -1
  51. package/dist/motion.js +11 -0
  52. package/dist/motion.js.map +1 -1
  53. package/dist/navigation-transition.d.ts +10 -0
  54. package/dist/navigation-transition.d.ts.map +1 -0
  55. package/dist/navigation-transition.js +10 -0
  56. package/dist/navigation-transition.js.map +1 -0
  57. package/dist/number-flow-format.d.ts +16 -0
  58. package/dist/number-flow-format.d.ts.map +1 -0
  59. package/dist/number-flow-format.js +49 -0
  60. package/dist/number-flow-format.js.map +1 -0
  61. package/dist/popover.d.ts +17 -0
  62. package/dist/popover.d.ts.map +1 -0
  63. package/dist/popover.js +19 -0
  64. package/dist/popover.js.map +1 -0
  65. package/dist/screen-components.d.ts +45 -0
  66. package/dist/screen-components.d.ts.map +1 -0
  67. package/dist/screen-components.js +23 -0
  68. package/dist/screen-components.js.map +1 -0
  69. package/dist/section-scroll.d.ts +14 -0
  70. package/dist/section-scroll.d.ts.map +1 -0
  71. package/dist/section-scroll.js +28 -0
  72. package/dist/section-scroll.js.map +1 -0
  73. package/dist/time.d.ts +34 -0
  74. package/dist/time.d.ts.map +1 -0
  75. package/dist/time.js +78 -0
  76. package/dist/time.js.map +1 -0
  77. package/dist/vue/animated-text.d.ts +101 -0
  78. package/dist/vue/animated-text.d.ts.map +1 -0
  79. package/dist/vue/animated-text.js +56 -0
  80. package/dist/vue/animated-text.js.map +1 -0
  81. package/dist/vue/carousel.d.ts +13 -0
  82. package/dist/vue/carousel.d.ts.map +1 -0
  83. package/dist/vue/carousel.js +136 -0
  84. package/dist/vue/carousel.js.map +1 -0
  85. package/dist/vue/chart.d.ts +194 -0
  86. package/dist/vue/chart.d.ts.map +1 -0
  87. package/dist/vue/chart.js +245 -0
  88. package/dist/vue/chart.js.map +1 -0
  89. package/dist/vue/command-palette.d.ts +129 -0
  90. package/dist/vue/command-palette.d.ts.map +1 -0
  91. package/dist/vue/command-palette.js +190 -0
  92. package/dist/vue/command-palette.js.map +1 -0
  93. package/dist/vue/component-motion.d.ts +17 -0
  94. package/dist/vue/component-motion.d.ts.map +1 -0
  95. package/dist/vue/component-motion.js +83 -0
  96. package/dist/vue/component-motion.js.map +1 -0
  97. package/dist/vue/component-props.d.ts +1708 -21
  98. package/dist/vue/component-props.d.ts.map +1 -1
  99. package/dist/vue/component-props.js +50 -0
  100. package/dist/vue/component-props.js.map +1 -1
  101. package/dist/vue/composer.d.ts +159 -0
  102. package/dist/vue/composer.d.ts.map +1 -0
  103. package/dist/vue/composer.js +142 -0
  104. package/dist/vue/composer.js.map +1 -0
  105. package/dist/vue/configurator.d.ts +2 -2
  106. package/dist/vue/configurator.d.ts.map +1 -1
  107. package/dist/vue/configurator.js +3 -1
  108. package/dist/vue/configurator.js.map +1 -1
  109. package/dist/vue/creative-controls.d.ts +328 -0
  110. package/dist/vue/creative-controls.d.ts.map +1 -0
  111. package/dist/vue/creative-controls.js +396 -0
  112. package/dist/vue/creative-controls.js.map +1 -0
  113. package/dist/vue/creative-props.d.ts +260 -0
  114. package/dist/vue/creative-props.d.ts.map +1 -0
  115. package/dist/vue/creative-props.js +92 -0
  116. package/dist/vue/creative-props.js.map +1 -0
  117. package/dist/vue/dashboard-charts.d.ts +240 -0
  118. package/dist/vue/dashboard-charts.d.ts.map +1 -0
  119. package/dist/vue/dashboard-charts.js +263 -0
  120. package/dist/vue/dashboard-charts.js.map +1 -0
  121. package/dist/vue/dashboard-effects.d.ts +211 -0
  122. package/dist/vue/dashboard-effects.d.ts.map +1 -0
  123. package/dist/vue/dashboard-effects.js +235 -0
  124. package/dist/vue/dashboard-effects.js.map +1 -0
  125. package/dist/vue/dashboard-props.d.ts +244 -0
  126. package/dist/vue/dashboard-props.d.ts.map +1 -0
  127. package/dist/vue/dashboard-props.js +94 -0
  128. package/dist/vue/dashboard-props.js.map +1 -0
  129. package/dist/vue/data-table.d.ts +17 -0
  130. package/dist/vue/data-table.d.ts.map +1 -0
  131. package/dist/vue/data-table.js +133 -0
  132. package/dist/vue/data-table.js.map +1 -0
  133. package/dist/vue/date-calendar.d.ts +2 -0
  134. package/dist/vue/date-calendar.d.ts.map +1 -1
  135. package/dist/vue/date-calendar.js +20 -1
  136. package/dist/vue/date-calendar.js.map +1 -1
  137. package/dist/vue/date-picker.d.ts +8 -8
  138. package/dist/vue/date-props.d.ts +6 -0
  139. package/dist/vue/date-props.d.ts.map +1 -1
  140. package/dist/vue/date-props.js +3 -0
  141. package/dist/vue/date-props.js.map +1 -1
  142. package/dist/vue/discovery-components.d.ts +50 -0
  143. package/dist/vue/discovery-components.d.ts.map +1 -0
  144. package/dist/vue/discovery-components.js +2 -0
  145. package/dist/vue/discovery-components.js.map +1 -0
  146. package/dist/vue/discovery-controls.d.ts +197 -0
  147. package/dist/vue/discovery-controls.d.ts.map +1 -0
  148. package/dist/vue/discovery-controls.js +185 -0
  149. package/dist/vue/discovery-controls.js.map +1 -0
  150. package/dist/vue/discovery-props.d.ts +249 -0
  151. package/dist/vue/discovery-props.d.ts.map +1 -0
  152. package/dist/vue/discovery-props.js +87 -0
  153. package/dist/vue/discovery-props.js.map +1 -0
  154. package/dist/vue/global-components.d.ts +237 -0
  155. package/dist/vue/global-components.d.ts.map +1 -1
  156. package/dist/vue/index.d.ts +41 -0
  157. package/dist/vue/index.d.ts.map +1 -1
  158. package/dist/vue/index.js +37 -0
  159. package/dist/vue/index.js.map +1 -1
  160. package/dist/vue/interactive-components.d.ts +31 -0
  161. package/dist/vue/interactive-components.d.ts.map +1 -0
  162. package/dist/vue/interactive-components.js +2 -0
  163. package/dist/vue/interactive-components.js.map +1 -0
  164. package/dist/vue/interactive-props.d.ts +254 -0
  165. package/dist/vue/interactive-props.d.ts.map +1 -0
  166. package/dist/vue/interactive-props.js +85 -0
  167. package/dist/vue/interactive-props.js.map +1 -0
  168. package/dist/vue/kanban.d.ts +150 -0
  169. package/dist/vue/kanban.d.ts.map +1 -0
  170. package/dist/vue/kanban.js +267 -0
  171. package/dist/vue/kanban.js.map +1 -0
  172. package/dist/vue/list-motion.d.ts +7 -0
  173. package/dist/vue/list-motion.d.ts.map +1 -0
  174. package/dist/vue/list-motion.js +28 -0
  175. package/dist/vue/list-motion.js.map +1 -0
  176. package/dist/vue/marquee.d.ts +96 -0
  177. package/dist/vue/marquee.d.ts.map +1 -0
  178. package/dist/vue/marquee.js +186 -0
  179. package/dist/vue/marquee.js.map +1 -0
  180. package/dist/vue/menu.d.ts +122 -0
  181. package/dist/vue/menu.d.ts.map +1 -0
  182. package/dist/vue/menu.js +79 -0
  183. package/dist/vue/menu.js.map +1 -0
  184. package/dist/vue/navigation-controls.d.ts +125 -0
  185. package/dist/vue/navigation-controls.d.ts.map +1 -0
  186. package/dist/vue/navigation-controls.js +130 -0
  187. package/dist/vue/navigation-controls.js.map +1 -0
  188. package/dist/vue/navigation-props.d.ts +283 -0
  189. package/dist/vue/navigation-props.d.ts.map +1 -0
  190. package/dist/vue/navigation-props.js +82 -0
  191. package/dist/vue/navigation-props.js.map +1 -0
  192. package/dist/vue/number-flow.d.ts +75 -0
  193. package/dist/vue/number-flow.d.ts.map +1 -0
  194. package/dist/vue/number-flow.js +57 -0
  195. package/dist/vue/number-flow.js.map +1 -0
  196. package/dist/vue/partition.d.ts +15 -0
  197. package/dist/vue/partition.d.ts.map +1 -0
  198. package/dist/vue/partition.js +42 -0
  199. package/dist/vue/partition.js.map +1 -0
  200. package/dist/vue/pin-cell.d.ts +14 -0
  201. package/dist/vue/pin-cell.d.ts.map +1 -0
  202. package/dist/vue/pin-cell.js +19 -0
  203. package/dist/vue/pin-cell.js.map +1 -0
  204. package/dist/vue/pin-input.d.ts +14 -0
  205. package/dist/vue/pin-input.d.ts.map +1 -0
  206. package/dist/vue/pin-input.js +23 -0
  207. package/dist/vue/pin-input.js.map +1 -0
  208. package/dist/vue/platform.d.ts +37 -0
  209. package/dist/vue/platform.d.ts.map +1 -0
  210. package/dist/vue/platform.js +46 -0
  211. package/dist/vue/platform.js.map +1 -0
  212. package/dist/vue/props.d.ts +82 -42
  213. package/dist/vue/props.d.ts.map +1 -1
  214. package/dist/vue/props.js +3 -1
  215. package/dist/vue/props.js.map +1 -1
  216. package/dist/vue/screen-component-props.d.ts +236 -0
  217. package/dist/vue/screen-component-props.d.ts.map +1 -0
  218. package/dist/vue/screen-component-props.js +90 -0
  219. package/dist/vue/screen-component-props.js.map +1 -0
  220. package/dist/vue/scroll-frame.d.ts +223 -0
  221. package/dist/vue/scroll-frame.d.ts.map +1 -0
  222. package/dist/vue/scroll-frame.js +346 -0
  223. package/dist/vue/scroll-frame.js.map +1 -0
  224. package/dist/vue/sortable-list.d.ts +24 -0
  225. package/dist/vue/sortable-list.d.ts.map +1 -0
  226. package/dist/vue/sortable-list.js +251 -0
  227. package/dist/vue/sortable-list.js.map +1 -0
  228. package/dist/vue/speed-dial.d.ts +73 -0
  229. package/dist/vue/speed-dial.d.ts.map +1 -0
  230. package/dist/vue/speed-dial.js +78 -0
  231. package/dist/vue/speed-dial.js.map +1 -0
  232. package/dist/vue/swipe-actions.d.ts +96 -0
  233. package/dist/vue/swipe-actions.d.ts.map +1 -0
  234. package/dist/vue/swipe-actions.js +174 -0
  235. package/dist/vue/swipe-actions.js.map +1 -0
  236. package/dist/vue/swipe-deck.d.ts +120 -0
  237. package/dist/vue/swipe-deck.d.ts.map +1 -0
  238. package/dist/vue/swipe-deck.js +229 -0
  239. package/dist/vue/swipe-deck.js.map +1 -0
  240. package/dist/vue/time-picker.d.ts +488 -0
  241. package/dist/vue/time-picker.d.ts.map +1 -0
  242. package/dist/vue/time-picker.js +190 -0
  243. package/dist/vue/time-picker.js.map +1 -0
  244. package/dist/vue/tour.d.ts +120 -0
  245. package/dist/vue/tour.d.ts.map +1 -0
  246. package/dist/vue/tour.js +165 -0
  247. package/dist/vue/tour.js.map +1 -0
  248. package/dist/vue/tree-view.d.ts +111 -0
  249. package/dist/vue/tree-view.d.ts.map +1 -0
  250. package/dist/vue/tree-view.js +204 -0
  251. package/dist/vue/tree-view.js.map +1 -0
  252. package/dist/vue/virtual-list.d.ts +26 -0
  253. package/dist/vue/virtual-list.d.ts.map +1 -0
  254. package/dist/vue/virtual-list.js +2 -0
  255. package/dist/vue/virtual-list.js.map +1 -0
  256. package/dist/vue/wayfinding-controls.d.ts +199 -0
  257. package/dist/vue/wayfinding-controls.d.ts.map +1 -0
  258. package/dist/vue/wayfinding-controls.js +330 -0
  259. package/dist/vue/wayfinding-controls.js.map +1 -0
  260. package/dist/vue/wayfinding-props.d.ts +221 -0
  261. package/dist/vue/wayfinding-props.d.ts.map +1 -0
  262. package/dist/vue/wayfinding-props.js +86 -0
  263. package/dist/vue/wayfinding-props.js.map +1 -0
  264. package/dist/vue/workflows.d.ts +2 -2
  265. package/dist/vue/workflows.d.ts.map +1 -1
  266. package/dist/vue/workflows.js +17 -4
  267. package/dist/vue/workflows.js.map +1 -1
  268. package/dist/wayfinding.d.ts +50 -0
  269. package/dist/wayfinding.d.ts.map +1 -0
  270. package/dist/wayfinding.js +54 -0
  271. package/dist/wayfinding.js.map +1 -0
  272. package/package.json +2 -2
  273. package/src/capabilities.ts +50 -4
  274. package/src/chart.ts +151 -0
  275. package/src/collections.ts +87 -0
  276. package/src/contracts.ts +2 -0
  277. package/src/creative-controls.ts +169 -0
  278. package/src/dashboard.ts +164 -0
  279. package/src/discovery.ts +139 -0
  280. package/src/experimental-regions.ts +29 -0
  281. package/src/experimental.ts +40 -0
  282. package/src/index.ts +23 -1
  283. package/src/interactive.ts +91 -0
  284. package/src/link.ts +2 -0
  285. package/src/motion.ts +14 -0
  286. package/src/navigation-transition.ts +14 -0
  287. package/src/number-flow-format.ts +68 -0
  288. package/src/popover.ts +38 -0
  289. package/src/screen-components.ts +59 -0
  290. package/src/section-scroll.ts +46 -0
  291. package/src/time.ts +83 -0
  292. package/src/vue/animated-text.ts +72 -0
  293. package/src/vue/carousel.ts +198 -0
  294. package/src/vue/chart.ts +337 -0
  295. package/src/vue/command-palette.ts +235 -0
  296. package/src/vue/component-motion.ts +109 -0
  297. package/src/vue/component-props.ts +104 -0
  298. package/src/vue/composer.ts +192 -0
  299. package/src/vue/configurator.ts +3 -1
  300. package/src/vue/creative-controls.ts +524 -0
  301. package/src/vue/creative-props.ts +94 -0
  302. package/src/vue/dashboard-charts.ts +346 -0
  303. package/src/vue/dashboard-effects.ts +304 -0
  304. package/src/vue/dashboard-props.ts +95 -0
  305. package/src/vue/data-table.ts +190 -0
  306. package/src/vue/date-calendar.ts +30 -1
  307. package/src/vue/date-props.ts +3 -0
  308. package/src/vue/discovery-components.ts +60 -0
  309. package/src/vue/discovery-controls.ts +241 -0
  310. package/src/vue/discovery-props.ts +92 -0
  311. package/src/vue/global-components.ts +237 -0
  312. package/src/vue/index.ts +64 -0
  313. package/src/vue/interactive-components.ts +29 -0
  314. package/src/vue/interactive-props.ts +90 -0
  315. package/src/vue/kanban.ts +360 -0
  316. package/src/vue/list-motion.ts +31 -0
  317. package/src/vue/marquee.ts +248 -0
  318. package/src/vue/menu.ts +100 -0
  319. package/src/vue/navigation-controls.ts +159 -0
  320. package/src/vue/navigation-props.ts +87 -0
  321. package/src/vue/number-flow.ts +83 -0
  322. package/src/vue/partition.ts +49 -0
  323. package/src/vue/pin-cell.ts +26 -0
  324. package/src/vue/pin-input.ts +31 -0
  325. package/src/vue/platform.ts +73 -0
  326. package/src/vue/props.ts +3 -1
  327. package/src/vue/screen-component-props.ts +92 -0
  328. package/src/vue/scroll-frame.ts +429 -0
  329. package/src/vue/sortable-list.ts +308 -0
  330. package/src/vue/speed-dial.ts +108 -0
  331. package/src/vue/swipe-actions.ts +226 -0
  332. package/src/vue/swipe-deck.ts +277 -0
  333. package/src/vue/time-picker.ts +227 -0
  334. package/src/vue/tour.ts +239 -0
  335. package/src/vue/tree-view.ts +259 -0
  336. package/src/vue/virtual-list.ts +28 -0
  337. package/src/vue/wayfinding-controls.ts +430 -0
  338. package/src/vue/wayfinding-props.ts +97 -0
  339. package/src/vue/workflows.ts +17 -4
  340. package/src/wayfinding.ts +85 -0
@@ -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
+ }