@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,308 @@
1
+ import type { SortableListComponent } from './interactive-components.js'
2
+ import {
3
+ computed,
4
+ defineComponent,
5
+ h,
6
+ markRaw,
7
+ mergeProps,
8
+ nextTick,
9
+ onScopeDispose,
10
+ ref,
11
+ watch,
12
+ type Component,
13
+ type PropType,
14
+ } from '@vue/runtime-core'
15
+ import { choiceKey } from '../choice.js'
16
+ import { virtualKeys } from '../collections.js'
17
+ import { moveItem, positiveSize, type SortableMove } from '../interactive.js'
18
+ import {
19
+ createMotionRegion,
20
+ createMotionSurface,
21
+ createMotionScrollSource,
22
+ type MotionSurface,
23
+ type MotionReorder,
24
+ } from '../experimental.js'
25
+ import { sortableListProps } from './interactive-props.js'
26
+ import { useMavisTheme } from './theme.js'
27
+
28
+ export const sortableScrollProps = {
29
+ source: {
30
+ type: Object as PropType<ReturnType<typeof createMotionScrollSource>>,
31
+ required: true as const,
32
+ },
33
+ height: { type: Number, required: true as const },
34
+ }
35
+ export function createSortableList(
36
+ ui: {
37
+ Box: Component
38
+ Column: Component
39
+ Row: Component
40
+ Text: Component
41
+ Button: Component
42
+ Scroll: Component
43
+ ListBody: Component
44
+ input?: (fresh: () => void) => Record<string, unknown>
45
+ },
46
+ platform: 'web' | 'native',
47
+ ) {
48
+ return defineComponent({
49
+ name: 'MSortableList',
50
+ inheritAttrs: false,
51
+ props: sortableListProps,
52
+ emits: {
53
+ 'update:modelValue': (_items: unknown[]) => true,
54
+ reorder: (_move: SortableMove) => true,
55
+ },
56
+ setup(props, { attrs, slots, emit }) {
57
+ const { theme } = useMavisTheme()
58
+ const keys = computed(() => virtualKeys(props.modelValue, props.itemKey))
59
+ const region = markRaw(createMotionRegion())
60
+ const container = markRaw(createMotionSurface())
61
+ const scroll = markRaw(createMotionScrollSource())
62
+ const rows = new Map<
63
+ string,
64
+ { target: MotionSurface; handle: MotionSurface; release: () => void }
65
+ >()
66
+ const announcement = ref('')
67
+ let control: MotionReorder | undefined
68
+ let afterDrop = false
69
+ let disposed = false
70
+ let queued = false
71
+ const dispose = () => {
72
+ control?.dispose()
73
+ control = undefined
74
+ }
75
+ function commit(id: string, before: string | null) {
76
+ if (props.disabled) return
77
+ const key = keys.value.find((key) => choiceKey(key) === id)
78
+ const beforeKey =
79
+ before === null ? null : keys.value.find((key) => choiceKey(key) === before)
80
+ if (key === undefined || beforeKey === undefined) return
81
+ const result = moveItem(props.modelValue, props.itemKey, key, beforeKey)
82
+ if (!result) return
83
+ emit('update:modelValue', result.items)
84
+ emit('reorder', result.move)
85
+ void nextTick(() => {
86
+ const index = keys.value.indexOf(key)
87
+ if (index >= 0)
88
+ announcement.value = `${labelAt(index)} · ${index + 1} / ${keys.value.length}`
89
+ control?.refresh()
90
+ })
91
+ }
92
+ function schedule() {
93
+ if (queued || disposed) return
94
+ queued = true
95
+ void nextTick(() => {
96
+ queued = false
97
+ if (disposed || !region.available || !container.available || !scroll.available) return
98
+ if (
99
+ !keys.value.every((key) => {
100
+ const row = rows.get(choiceKey(key))
101
+ return row?.target.available && row.handle.available
102
+ })
103
+ )
104
+ return
105
+ if (!control)
106
+ control = region.reorder({
107
+ container,
108
+ scroll,
109
+ items: () =>
110
+ keys.value.map((key) => ({ key: choiceKey(key), ...rows.get(choiceKey(key))! })),
111
+ onCommit: (move) => {
112
+ afterDrop = true
113
+ commit(move.key, move.beforeKey)
114
+ },
115
+ accessibility: {
116
+ moveUp: props.moveUpLabel,
117
+ moveDown: props.moveDownLabel,
118
+ label: (id) => labelAt(keys.value.findIndex((key) => choiceKey(key) === id)),
119
+ },
120
+ })
121
+ else control.refresh()
122
+ if (props.disabled) control.pause()
123
+ else control.play()
124
+ })
125
+ }
126
+ for (const owner of [region, container, scroll])
127
+ onScopeDispose(
128
+ owner.onAvailable(() => {
129
+ schedule()
130
+ return dispose
131
+ }),
132
+ )
133
+ watch(
134
+ keys,
135
+ (next) => {
136
+ for (const key of next) {
137
+ const id = choiceKey(key)
138
+ if (rows.has(id)) continue
139
+ const target = markRaw(createMotionSurface()),
140
+ handle = markRaw(createMotionSurface())
141
+ const a = target.onAvailable(schedule),
142
+ b = handle.onAvailable(schedule)
143
+ rows.set(id, {
144
+ target,
145
+ handle,
146
+ release: () => {
147
+ a()
148
+ b()
149
+ },
150
+ })
151
+ }
152
+ for (const [id, row] of rows)
153
+ if (!next.some((key) => choiceKey(key) === id)) {
154
+ row.release()
155
+ rows.delete(id)
156
+ }
157
+ schedule()
158
+ },
159
+ { immediate: true, flush: 'sync' },
160
+ )
161
+ watch(() => props.modelValue, schedule, { deep: true, flush: 'post' })
162
+ watch(
163
+ () => props.disabled,
164
+ () => {
165
+ if (props.disabled) {
166
+ control?.cancel()
167
+ control?.pause()
168
+ } else schedule()
169
+ },
170
+ )
171
+ onScopeDispose(() => {
172
+ disposed = true
173
+ dispose()
174
+ for (const row of rows.values()) row.release()
175
+ })
176
+ function labelAt(index: number) {
177
+ return index < 0
178
+ ? ''
179
+ : (props.itemLabel?.(props.modelValue[index]) ?? String(keys.value[index]))
180
+ }
181
+ function move(index: number, delta: number) {
182
+ const key = keys.value[index]
183
+ if (key === undefined || index + delta < 0 || index + delta >= keys.value.length) return
184
+ const before = delta < 0 ? keys.value[index - 1] : keys.value[index + 2]
185
+ const beforeId = before === undefined ? null : choiceKey(before)
186
+ if (control) control.move(choiceKey(key), beforeId)
187
+ else commit(choiceKey(key), beforeId)
188
+ }
189
+ const input =
190
+ ui.input?.(() => {
191
+ // Jolt suppresses the click synthesized by a completed drag. A distinct
192
+ // pointer sequence on another control must be usable immediately.
193
+ if (afterDrop && !control?.activeKey) {
194
+ afterDrop = false
195
+ dispose()
196
+ schedule()
197
+ }
198
+ }) ?? {}
199
+ return () =>
200
+ h(
201
+ ui.Column,
202
+ mergeProps(attrs, {
203
+ id: props.id,
204
+ motionRegion: region,
205
+ ...(platform === 'web'
206
+ ? { class: 'm-sortable-list', role: 'group', 'aria-label': props.label }
207
+ : { accessibilityLabel: props.label }),
208
+ }),
209
+ () => [
210
+ h(ui.Scroll, { source: scroll, height: positiveSize(props.height, 'height') }, () =>
211
+ h(
212
+ ui.ListBody,
213
+ {
214
+ ...input,
215
+ motionSurface: container,
216
+ ...(platform === 'web'
217
+ ? {
218
+ role: 'list',
219
+ style: {
220
+ display: 'flex',
221
+ flexDirection: 'column',
222
+ gap: '8px',
223
+ padding: '6px',
224
+ },
225
+ }
226
+ : {}),
227
+ },
228
+ () =>
229
+ keys.value.length
230
+ ? keys.value.map((key, index) => {
231
+ const row = rows.get(choiceKey(key))!
232
+ const label = labelAt(index)
233
+ return h(
234
+ ui.Box,
235
+ {
236
+ key: choiceKey(key),
237
+ motionSurface: row.target,
238
+ radius: 'md',
239
+ padding: 'sm',
240
+ backgroundColor: theme.value.colors.surface,
241
+ ...(platform === 'web'
242
+ ? {
243
+ role: 'listitem',
244
+ 'data-key': String(key),
245
+ style: { border: `1px solid ${theme.value.colors.border}` },
246
+ }
247
+ : { marginBottom: 8 }),
248
+ },
249
+ () =>
250
+ h(ui.Row, { gap: 'sm', align: 'center' }, () => [
251
+ h(ui.Button, {
252
+ text: '⋮⋮',
253
+ variant: 'ghost',
254
+ reorderHandle: true,
255
+ ...(platform === 'web' ? { 'data-sort-handle': '' } : {}),
256
+ motionSurface: row.handle,
257
+ disabled: props.disabled,
258
+ accessibilityLabel: `${props.handleLabel}: ${label}`,
259
+ }),
260
+ h(
261
+ ui.Column,
262
+ { grow: 1, shrink: 1 },
263
+ () =>
264
+ slots.default?.({
265
+ item: props.modelValue[index],
266
+ index,
267
+ itemKey: key,
268
+ }) ?? h(ui.Text, { text: label }),
269
+ ),
270
+ h(ui.Column, { gap: 'xs' }, () => [
271
+ h(ui.Button, {
272
+ icon: 'chevron-up',
273
+ variant: 'ghost',
274
+ disabled: props.disabled || index === 0,
275
+ accessibilityLabel: `${props.moveUpLabel}: ${label}`,
276
+ onClick: () => move(index, -1),
277
+ }),
278
+ h(ui.Button, {
279
+ icon: 'chevron-down',
280
+ variant: 'ghost',
281
+ disabled: props.disabled || index === keys.value.length - 1,
282
+ accessibilityLabel: `${props.moveDownLabel}: ${label}`,
283
+ onClick: () => move(index, 1),
284
+ }),
285
+ ]),
286
+ ]),
287
+ )
288
+ })
289
+ : (slots.empty?.() ?? h(ui.Text, { text: props.emptyLabel, tone: 'muted' })),
290
+ ),
291
+ ),
292
+ h(ui.Text, {
293
+ text: announcement.value,
294
+ variant: 'caption',
295
+ ...(platform === 'web'
296
+ ? {
297
+ class: 'm-sr-only',
298
+ role: 'status',
299
+ 'aria-live': 'polite',
300
+ 'aria-atomic': 'true',
301
+ }
302
+ : { accessibilityLiveRegion: 'polite' }),
303
+ }),
304
+ ],
305
+ )
306
+ },
307
+ }) as unknown as SortableListComponent
308
+ }
@@ -0,0 +1,108 @@
1
+ import {
2
+ defineComponent,
3
+ h,
4
+ markRaw,
5
+ mergeProps,
6
+ onScopeDispose,
7
+ type Component,
8
+ } from '@vue/runtime-core'
9
+ import { createMotionSurface } from '../experimental.js'
10
+ import { uniqueActions, type SpeedDialAction } from '../screen-components.js'
11
+ import { speedDialProps } from './screen-component-props.js'
12
+ import type { ChoiceValue } from '../choice.js'
13
+ import { useMavisTheme } from './theme.js'
14
+ import { componentMotion } from '../motion.js'
15
+
16
+ export function createSpeedDial(ui: { Popover: Component; Column: Component; Button: Component }) {
17
+ const Action = defineComponent({
18
+ props: { index: { type: Number, required: true }, direction: String },
19
+ setup(props, { slots }) {
20
+ const { theme } = useMavisTheme()
21
+ const surface = markRaw(createMotionSurface())
22
+ onScopeDispose(
23
+ surface.use((owner) => {
24
+ owner.animate(
25
+ { opacity: [0, 1], y: [props.direction === 'up' ? 12 : -12, 0], scale: [0.94, 1] },
26
+ { ...componentMotion(theme.value, 'overlay'), delay: props.index * 35 },
27
+ )
28
+ }),
29
+ )
30
+ return () => h(ui.Column, { motionSurface: surface }, slots)
31
+ },
32
+ })
33
+ return defineComponent({
34
+ name: 'MSpeedDial',
35
+ inheritAttrs: false,
36
+ props: speedDialProps,
37
+ emits: {
38
+ 'update:open': (_v: boolean) => true,
39
+ select: (_v: ChoiceValue, _a: SpeedDialAction) => true,
40
+ close: (_reason: string) => true,
41
+ },
42
+ setup(props, { attrs, emit }) {
43
+ return () =>
44
+ h(
45
+ ui.Popover,
46
+ mergeProps(attrs, {
47
+ id: props.id,
48
+ label: props.label,
49
+ triggerLabel: props.label,
50
+ icon: props.open ? 'x' : props.icon,
51
+ variant: 'primary',
52
+ open: props.open,
53
+ disabled: props.disabled,
54
+ placement: props.direction === 'up' ? 'top-end' : 'bottom-end',
55
+ width: 260,
56
+ padding: 'sm',
57
+ 'onUpdate:open': (v: boolean) => emit('update:open', v),
58
+ onClose: (reason: string) => emit('close', reason),
59
+ }),
60
+ {
61
+ default: () =>
62
+ h(
63
+ ui.Column,
64
+ { gap: 'xs' },
65
+ {
66
+ default: () => [
67
+ ...uniqueActions(props.actions).map((action, index) =>
68
+ h(
69
+ Action,
70
+ {
71
+ key: `${typeof action.value}:${action.value}`,
72
+ index,
73
+ direction: props.direction,
74
+ },
75
+ {
76
+ default: () =>
77
+ h(ui.Button, {
78
+ text: action.label,
79
+ icon: action.icon,
80
+ variant: 'ghost',
81
+ disabled: props.disabled || action.disabled,
82
+ onClick: () => {
83
+ if (!props.disabled && !action.disabled) {
84
+ emit('select', action.value, action)
85
+ emit('update:open', false)
86
+ }
87
+ },
88
+ }),
89
+ },
90
+ ),
91
+ ),
92
+ h(ui.Button, {
93
+ text: props.closeLabel,
94
+ variant: 'ghost',
95
+ size: 'sm',
96
+ onClick: () => {
97
+ emit('update:open', false)
98
+ emit('close', 'action')
99
+ },
100
+ }),
101
+ ],
102
+ },
103
+ ),
104
+ },
105
+ )
106
+ },
107
+ })
108
+ }
@@ -0,0 +1,226 @@
1
+ import {
2
+ defineComponent,
3
+ h,
4
+ markRaw,
5
+ mergeProps,
6
+ nextTick,
7
+ onScopeDispose,
8
+ ref,
9
+ watch,
10
+ type Component,
11
+ } from '@vue/runtime-core'
12
+ import { componentMotion } from '../motion.js'
13
+ import { createMotionSurface } from '../experimental.js'
14
+ import { choiceKey } from '../choice.js'
15
+ import {
16
+ positiveSize,
17
+ swipeDestination,
18
+ validateActions,
19
+ type SwipeAction,
20
+ type SwipeSide,
21
+ } from '../interactive.js'
22
+ import { swipeActionsProps } from './interactive-props.js'
23
+ import { useMavisTheme } from './theme.js'
24
+
25
+ export function createSwipeActions(
26
+ ui: {
27
+ Box: Component
28
+ Column: Component
29
+ Row: Component
30
+ Text: Component
31
+ Button: Component
32
+ Menu: Component
33
+ },
34
+ platform: 'web' | 'native',
35
+ ) {
36
+ return defineComponent({
37
+ name: 'MSwipeActions',
38
+ inheritAttrs: false,
39
+ props: swipeActionsProps,
40
+ emits: {
41
+ 'update:modelValue': (_side: SwipeSide) => true,
42
+ action: (_action: SwipeAction) => true,
43
+ },
44
+ setup(props, { attrs, slots, emit }) {
45
+ const { theme } = useMavisTheme()
46
+ const surface = markRaw(createMotionSurface())
47
+ const menuOpen = ref(false)
48
+ const direction = () => (props.direction === 'rtl' ? -1 : 1)
49
+ const offset = () =>
50
+ props.disabled
51
+ ? 0
52
+ : props.modelValue === 'start'
53
+ ? props.start.length * props.actionWidth * direction()
54
+ : props.modelValue === 'end'
55
+ ? -props.end.length * props.actionWidth * direction()
56
+ : 0
57
+ const settle = () => {
58
+ if (surface.available)
59
+ surface.animate({ x: offset() }, componentMotion(theme.value, 'selection'))
60
+ }
61
+ const select = (side: SwipeSide) => {
62
+ if (props.disabled) return
63
+ emit('update:modelValue', side)
64
+ void nextTick(settle)
65
+ }
66
+ onScopeDispose(
67
+ surface.use((owner) => {
68
+ let release = () => {}
69
+ const stop = watch(
70
+ () => [
71
+ props.start.length,
72
+ props.end.length,
73
+ props.actionWidth,
74
+ props.direction,
75
+ props.disabled,
76
+ ],
77
+ () => {
78
+ release()
79
+ owner.set({ x: offset() })
80
+ if (props.disabled) return
81
+ const start = props.start.length * positiveSize(props.actionWidth, 'actionWidth'),
82
+ end = props.end.length * props.actionWidth
83
+ const control = owner.drag({
84
+ axis: 'x',
85
+ bounds: {
86
+ left: direction() === 1 ? -end : -start,
87
+ right: direction() === 1 ? start : end,
88
+ },
89
+ onRelease: (event) =>
90
+ select(swipeDestination(event.x, event.velocityX, start, end, direction())),
91
+ })
92
+ release = () => control.dispose()
93
+ },
94
+ { immediate: true },
95
+ )
96
+ return () => {
97
+ stop()
98
+ release()
99
+ }
100
+ }),
101
+ )
102
+ watch(() => props.modelValue, settle, { flush: 'post' })
103
+ function run(action: SwipeAction) {
104
+ if (props.disabled || action.disabled) return
105
+ emit('action', action)
106
+ select(null)
107
+ }
108
+ const actions = (side: 'start' | 'end') =>
109
+ h(
110
+ ui.Row,
111
+ {
112
+ gap: 'none',
113
+ justify: side === 'start' ? 'start' : 'end',
114
+ ...(platform === 'web'
115
+ ? {
116
+ inert: props.disabled || props.modelValue !== side ? true : undefined,
117
+ style: {
118
+ gridArea: '1 / 1',
119
+ alignSelf: 'stretch',
120
+ justifySelf: (side === 'start') === (direction() === 1) ? 'start' : 'end',
121
+ },
122
+ }
123
+ : {
124
+ horizontalAlignment:
125
+ (side === 'start') === (direction() === 1) ? 'left' : 'right',
126
+ accessibilityHidden: props.disabled || props.modelValue !== side,
127
+ }),
128
+ },
129
+ () =>
130
+ props[side].map((action) =>
131
+ h(ui.Button, {
132
+ key: choiceKey(action.value),
133
+ text: action.label,
134
+ icon: action.icon,
135
+ width: props.actionWidth,
136
+ variant: 'secondary',
137
+ disabled: props.disabled || action.disabled,
138
+ onClick: () => run(action),
139
+ }),
140
+ ),
141
+ )
142
+ return () => {
143
+ validateActions(props.start, props.end)
144
+ return h(
145
+ ui.Column,
146
+ mergeProps(attrs, {
147
+ gap: 'xs',
148
+ ...(platform === 'web'
149
+ ? {
150
+ class: 'm-swipe-actions',
151
+ role: 'group',
152
+ 'aria-label': props.label,
153
+ onKeydown: (event: KeyboardEvent) => {
154
+ if (event.key === 'Escape') {
155
+ event.preventDefault()
156
+ select(null)
157
+ }
158
+ },
159
+ }
160
+ : { accessibilityLabel: props.label }),
161
+ }),
162
+ () => [
163
+ h(
164
+ ui.Box,
165
+ {
166
+ radius: 'lg',
167
+ ...(platform === 'web'
168
+ ? { style: { overflow: 'clip', isolation: 'isolate' } }
169
+ : { clipToBounds: true }),
170
+ },
171
+ () => [
172
+ actions('start'),
173
+ actions('end'),
174
+ h(
175
+ ui.Box,
176
+ {
177
+ motionSurface: surface,
178
+ padding: 'md',
179
+ radius: 'lg',
180
+ backgroundColor: theme.value.colors.surface,
181
+ ...(platform === 'web'
182
+ ? {
183
+ style: {
184
+ gridArea: '1 / 1',
185
+ zIndex: 1,
186
+ touchAction: 'pan-y',
187
+ minWidth: 0,
188
+ border: `1px solid ${theme.value.colors.border}`,
189
+ },
190
+ }
191
+ : {}),
192
+ },
193
+ () => slots.default?.(),
194
+ ),
195
+ ],
196
+ ),
197
+ h(ui.Row, { justify: 'end', gap: 'xs' }, () => [
198
+ props.modelValue
199
+ ? h(ui.Button, {
200
+ text: props.closeLabel,
201
+ variant: 'ghost',
202
+ disabled: props.disabled,
203
+ onClick: () => select(null),
204
+ })
205
+ : null,
206
+ h(ui.Menu, {
207
+ open: menuOpen.value,
208
+ 'onUpdate:open': (open: boolean) => {
209
+ menuOpen.value = open
210
+ },
211
+ label: `${props.actionsLabel}: ${props.label}`,
212
+ triggerLabel: props.actionsLabel,
213
+ disabled: props.disabled,
214
+ items: [...props.start, ...props.end],
215
+ onSelect: (value: string | number) => {
216
+ const action = [...props.start, ...props.end].find((a) => a.value === value)
217
+ if (action) run(action)
218
+ },
219
+ }),
220
+ ]),
221
+ ],
222
+ )
223
+ }
224
+ },
225
+ })
226
+ }