@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/chart.ts
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
defineComponent,
|
|
4
|
+
h,
|
|
5
|
+
markRaw,
|
|
6
|
+
mergeProps,
|
|
7
|
+
onScopeDispose,
|
|
8
|
+
ref,
|
|
9
|
+
watch,
|
|
10
|
+
type Component,
|
|
11
|
+
type PropType,
|
|
12
|
+
} from '@vue/runtime-core'
|
|
13
|
+
import { chartGeometry, type ChartGeometry, type ChartSelection } from '../chart.js'
|
|
14
|
+
import { choiceKey, type ChoiceValue } from '../choice.js'
|
|
15
|
+
import { createMotionSurface } from '../experimental.js'
|
|
16
|
+
import { chartProps } from './wayfinding-props.js'
|
|
17
|
+
import { useMavisTheme } from './theme.js'
|
|
18
|
+
|
|
19
|
+
export const chartPlotProps = {
|
|
20
|
+
geometry: { type: Object as PropType<ChartGeometry>, required: true as const },
|
|
21
|
+
colors: { type: Array as PropType<readonly string[]>, required: true as const },
|
|
22
|
+
type: { type: String as PropType<'line' | 'bar'>, required: true as const },
|
|
23
|
+
height: { type: Number, required: true as const },
|
|
24
|
+
selected: {
|
|
25
|
+
type: Object as PropType<{ category: number; series: number } | null>,
|
|
26
|
+
default: null,
|
|
27
|
+
},
|
|
28
|
+
disabled: Boolean,
|
|
29
|
+
}
|
|
30
|
+
export function createChart(
|
|
31
|
+
ui: {
|
|
32
|
+
Row: Component
|
|
33
|
+
Column: Component
|
|
34
|
+
Box: Component
|
|
35
|
+
Text: Component
|
|
36
|
+
Button: Component
|
|
37
|
+
Reveal: Component
|
|
38
|
+
Select: Component
|
|
39
|
+
Plot: Component
|
|
40
|
+
},
|
|
41
|
+
platform: 'web' | 'native',
|
|
42
|
+
) {
|
|
43
|
+
return defineComponent({
|
|
44
|
+
name: 'MChart',
|
|
45
|
+
inheritAttrs: false,
|
|
46
|
+
props: chartProps,
|
|
47
|
+
emits: {
|
|
48
|
+
'update:modelValue': (_selection: ChartSelection | null) => true,
|
|
49
|
+
'update:hiddenSeries': (_keys: ChoiceValue[]) => true,
|
|
50
|
+
},
|
|
51
|
+
setup(props, { attrs, emit }) {
|
|
52
|
+
const web = platform === 'web'
|
|
53
|
+
const { theme } = useMavisTheme()
|
|
54
|
+
const dataOpen = ref(props.showData)
|
|
55
|
+
watch(
|
|
56
|
+
() => props.showData,
|
|
57
|
+
(value) => {
|
|
58
|
+
dataOpen.value = value
|
|
59
|
+
},
|
|
60
|
+
)
|
|
61
|
+
const allGeometry = computed(() =>
|
|
62
|
+
chartGeometry(props.categories, props.series, props.domain),
|
|
63
|
+
)
|
|
64
|
+
const visible = computed(() =>
|
|
65
|
+
props.series.filter((series) => !props.hiddenSeries.includes(series.key)),
|
|
66
|
+
)
|
|
67
|
+
const geometry = computed(() => ({
|
|
68
|
+
...allGeometry.value,
|
|
69
|
+
series: allGeometry.value.series.filter(
|
|
70
|
+
(series) => !props.hiddenSeries.includes(series.key),
|
|
71
|
+
),
|
|
72
|
+
}))
|
|
73
|
+
const selected = computed(() => {
|
|
74
|
+
if (!props.modelValue) return null
|
|
75
|
+
const category = props.categories.findIndex(
|
|
76
|
+
(item) => item.key === props.modelValue!.category,
|
|
77
|
+
)
|
|
78
|
+
const series = visible.value.findIndex((item) => item.key === props.modelValue!.series)
|
|
79
|
+
return category < 0 || series < 0 ? null : { category, series }
|
|
80
|
+
})
|
|
81
|
+
const format = (value: number | null | undefined) =>
|
|
82
|
+
value == null ? props.missingLabel : (props.formatValue?.(value) ?? String(value))
|
|
83
|
+
const colors = computed(() => {
|
|
84
|
+
const palette = [
|
|
85
|
+
theme.value.colors.primary,
|
|
86
|
+
theme.value.colors.accent,
|
|
87
|
+
theme.value.colors.success,
|
|
88
|
+
theme.value.colors.warning,
|
|
89
|
+
theme.value.colors.danger,
|
|
90
|
+
theme.value.colors.muted,
|
|
91
|
+
theme.value.colors.text,
|
|
92
|
+
theme.value.colors.border,
|
|
93
|
+
]
|
|
94
|
+
return visible.value.map(
|
|
95
|
+
(series) => series.color ?? palette[props.series.indexOf(series) % palette.length]!,
|
|
96
|
+
)
|
|
97
|
+
})
|
|
98
|
+
const summary = computed(() => {
|
|
99
|
+
const point = selected.value
|
|
100
|
+
if (!point) return props.description ?? props.label
|
|
101
|
+
const series = visible.value[point.series]!
|
|
102
|
+
return `${props.categories[point.category]!.label} · ${series.label}: ${format(series.values[point.category])}`
|
|
103
|
+
})
|
|
104
|
+
function choose(category: number, series: number) {
|
|
105
|
+
if (props.disabled || !props.categories[category] || !visible.value[series]) return
|
|
106
|
+
emit('update:modelValue', {
|
|
107
|
+
category: props.categories[category]!.key,
|
|
108
|
+
series: visible.value[series]!.key,
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
const surface = markRaw(createMotionSurface())
|
|
112
|
+
function animate() {
|
|
113
|
+
if (surface.available)
|
|
114
|
+
surface.animate(
|
|
115
|
+
{ opacity: [0.35, 1], y: [6, 0] },
|
|
116
|
+
{ duration: theme.value.motion.enterDuration, ease: 'easeOut' },
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
onScopeDispose(surface.use(animate))
|
|
120
|
+
return () => {
|
|
121
|
+
if (!props.label.trim()) throw new TypeError('Chart requires a label.')
|
|
122
|
+
if (!Number.isFinite(props.height) || props.height < 120 || props.height > 800)
|
|
123
|
+
throw new RangeError('Chart height must be between 120 and 800.')
|
|
124
|
+
if (!['line', 'bar'].includes(props.type))
|
|
125
|
+
throw new TypeError('Chart type must be line or bar.')
|
|
126
|
+
// Validate hidden series too; toggling a legend must never reveal invalid data.
|
|
127
|
+
const domain = allGeometry.value
|
|
128
|
+
const hasData = geometry.value.series.some((series) => series.points.some(Boolean))
|
|
129
|
+
return h(
|
|
130
|
+
ui.Column,
|
|
131
|
+
mergeProps({ id: props.id, gap: 'md' }, attrs, {
|
|
132
|
+
class: 'm-chart',
|
|
133
|
+
...(web ? { role: 'group', 'aria-label': props.label } : {}),
|
|
134
|
+
}),
|
|
135
|
+
() => [
|
|
136
|
+
h(ui.Column, { gap: 'xs' }, () => [
|
|
137
|
+
h(ui.Text, { text: props.label, as: 'h2', variant: 'heading' }),
|
|
138
|
+
props.description
|
|
139
|
+
? h(ui.Text, { text: props.description, tone: 'muted', variant: 'caption' })
|
|
140
|
+
: null,
|
|
141
|
+
]),
|
|
142
|
+
h(ui.Row, { gap: 'xs', wrap: true }, () =>
|
|
143
|
+
props.series.map((series) => {
|
|
144
|
+
const shown = !props.hiddenSeries.includes(series.key)
|
|
145
|
+
return h(
|
|
146
|
+
ui.Button,
|
|
147
|
+
{
|
|
148
|
+
key: choiceKey(series.key),
|
|
149
|
+
text: series.label,
|
|
150
|
+
variant: shown ? 'secondary' : 'ghost',
|
|
151
|
+
size: 'sm',
|
|
152
|
+
disabled: props.disabled,
|
|
153
|
+
...(web
|
|
154
|
+
? { 'aria-pressed': shown }
|
|
155
|
+
: { accessibilityState: shown ? 'selected' : '' }),
|
|
156
|
+
onClick: () => {
|
|
157
|
+
if (!props.disabled)
|
|
158
|
+
emit(
|
|
159
|
+
'update:hiddenSeries',
|
|
160
|
+
shown
|
|
161
|
+
? [...props.hiddenSeries, series.key]
|
|
162
|
+
: props.hiddenSeries.filter((key) => key !== series.key),
|
|
163
|
+
)
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
leading: () =>
|
|
168
|
+
h(ui.Box, {
|
|
169
|
+
width: 8,
|
|
170
|
+
height: 8,
|
|
171
|
+
radius: 'full',
|
|
172
|
+
backgroundColor: shown
|
|
173
|
+
? colors.value[visible.value.indexOf(series)]
|
|
174
|
+
: theme.value.colors.border,
|
|
175
|
+
accessibilityHidden: true,
|
|
176
|
+
}),
|
|
177
|
+
},
|
|
178
|
+
)
|
|
179
|
+
}),
|
|
180
|
+
),
|
|
181
|
+
// An exact native column prevents measured plot shapes from expanding their own viewport.
|
|
182
|
+
h(
|
|
183
|
+
web ? ui.Row : 'GridLayout',
|
|
184
|
+
web ? { gap: 'xs', align: 'stretch' } : { columns: '56, *', height: props.height },
|
|
185
|
+
() => [
|
|
186
|
+
h(
|
|
187
|
+
ui.Column,
|
|
188
|
+
{ col: 0, justify: 'between', width: 56, shrink: 0, height: props.height },
|
|
189
|
+
() =>
|
|
190
|
+
[...domain.ticks].reverse().map((value, index) =>
|
|
191
|
+
h(ui.Text, {
|
|
192
|
+
key: index,
|
|
193
|
+
text: format(value),
|
|
194
|
+
variant: 'caption',
|
|
195
|
+
tone: 'muted',
|
|
196
|
+
align: 'right',
|
|
197
|
+
}),
|
|
198
|
+
),
|
|
199
|
+
),
|
|
200
|
+
h(
|
|
201
|
+
ui.Box,
|
|
202
|
+
{ col: 1, grow: 1, shrink: 1, height: props.height, motionSurface: surface },
|
|
203
|
+
() =>
|
|
204
|
+
hasData
|
|
205
|
+
? h(ui.Plot, {
|
|
206
|
+
geometry: geometry.value,
|
|
207
|
+
colors: colors.value,
|
|
208
|
+
type: props.type,
|
|
209
|
+
height: props.height,
|
|
210
|
+
selected: selected.value,
|
|
211
|
+
disabled: props.disabled,
|
|
212
|
+
onSelect: choose,
|
|
213
|
+
})
|
|
214
|
+
: h(
|
|
215
|
+
ui.Column,
|
|
216
|
+
{ height: props.height, justify: 'center', align: 'center' },
|
|
217
|
+
() => h(ui.Text, { text: props.emptyLabel, tone: 'muted' }),
|
|
218
|
+
),
|
|
219
|
+
),
|
|
220
|
+
],
|
|
221
|
+
),
|
|
222
|
+
props.categories.length
|
|
223
|
+
? h(ui.Row, { justify: 'between', gap: 'sm' }, () => [
|
|
224
|
+
h(ui.Text, {
|
|
225
|
+
text: props.categories[0]!.label,
|
|
226
|
+
variant: 'caption',
|
|
227
|
+
tone: 'muted',
|
|
228
|
+
}),
|
|
229
|
+
props.categories.length > 1
|
|
230
|
+
? h(ui.Text, {
|
|
231
|
+
text: props.categories[props.categories.length - 1]!.label,
|
|
232
|
+
variant: 'caption',
|
|
233
|
+
tone: 'muted',
|
|
234
|
+
align: 'right',
|
|
235
|
+
})
|
|
236
|
+
: null,
|
|
237
|
+
])
|
|
238
|
+
: null,
|
|
239
|
+
h(ui.Text, {
|
|
240
|
+
text: summary.value,
|
|
241
|
+
weight: '600',
|
|
242
|
+
...(web
|
|
243
|
+
? { role: 'status', 'aria-live': 'polite', 'aria-atomic': 'true' }
|
|
244
|
+
: { accessibilityLiveRegion: 'polite' }),
|
|
245
|
+
}),
|
|
246
|
+
props.categories.length && visible.value.length
|
|
247
|
+
? h(ui.Row, { gap: 'sm', wrap: true }, () => [
|
|
248
|
+
h(ui.Select, {
|
|
249
|
+
label: props.categoryLabel,
|
|
250
|
+
placeholder: props.categoryLabel,
|
|
251
|
+
grow: 1,
|
|
252
|
+
shrink: 1,
|
|
253
|
+
options: props.categories.map((item) => ({
|
|
254
|
+
value: item.key,
|
|
255
|
+
label: item.label,
|
|
256
|
+
})),
|
|
257
|
+
modelValue: props.modelValue?.category ?? null,
|
|
258
|
+
disabled: props.disabled,
|
|
259
|
+
'onUpdate:modelValue': (key: ChoiceValue) =>
|
|
260
|
+
choose(
|
|
261
|
+
props.categories.findIndex((item) => item.key === key),
|
|
262
|
+
selected.value?.series ?? 0,
|
|
263
|
+
),
|
|
264
|
+
}),
|
|
265
|
+
h(ui.Select, {
|
|
266
|
+
label: props.seriesLabel,
|
|
267
|
+
grow: 1,
|
|
268
|
+
shrink: 1,
|
|
269
|
+
options: visible.value.map((item) => ({ value: item.key, label: item.label })),
|
|
270
|
+
modelValue: visible.value[selected.value?.series ?? 0]!.key,
|
|
271
|
+
disabled: props.disabled,
|
|
272
|
+
'onUpdate:modelValue': (key: ChoiceValue) =>
|
|
273
|
+
choose(
|
|
274
|
+
selected.value?.category ?? 0,
|
|
275
|
+
visible.value.findIndex((item) => item.key === key),
|
|
276
|
+
),
|
|
277
|
+
}),
|
|
278
|
+
])
|
|
279
|
+
: null,
|
|
280
|
+
h(ui.Row, { gap: 'sm', wrap: true }, () => [
|
|
281
|
+
h(ui.Button, {
|
|
282
|
+
text: dataOpen.value ? props.hideDataLabel : props.showDataLabel,
|
|
283
|
+
icon: 'table-2',
|
|
284
|
+
variant: 'ghost',
|
|
285
|
+
...(web ? { 'aria-expanded': dataOpen.value } : {}),
|
|
286
|
+
onClick: () => {
|
|
287
|
+
dataOpen.value = !dataOpen.value
|
|
288
|
+
},
|
|
289
|
+
}),
|
|
290
|
+
selected.value
|
|
291
|
+
? h(ui.Button, {
|
|
292
|
+
text: props.clearLabel,
|
|
293
|
+
variant: 'ghost',
|
|
294
|
+
disabled: props.disabled,
|
|
295
|
+
onClick: () => {
|
|
296
|
+
if (!props.disabled) emit('update:modelValue', null)
|
|
297
|
+
},
|
|
298
|
+
})
|
|
299
|
+
: null,
|
|
300
|
+
]),
|
|
301
|
+
h(ui.Reveal, { show: dataOpen.value, gap: 'sm' }, () =>
|
|
302
|
+
h(
|
|
303
|
+
ui.Column,
|
|
304
|
+
{ gap: 'sm', ...(web ? { role: 'list', 'aria-label': props.showDataLabel } : {}) },
|
|
305
|
+
() =>
|
|
306
|
+
props.categories.map((category, index) =>
|
|
307
|
+
h(
|
|
308
|
+
ui.Column,
|
|
309
|
+
{
|
|
310
|
+
key: choiceKey(category.key),
|
|
311
|
+
gap: 'xs',
|
|
312
|
+
padding: 'sm',
|
|
313
|
+
radius: 'md',
|
|
314
|
+
backgroundColor: theme.value.colors.surface,
|
|
315
|
+
...(web ? { role: 'listitem' } : {}),
|
|
316
|
+
},
|
|
317
|
+
() => [
|
|
318
|
+
h(ui.Text, { text: category.label, weight: '600' }),
|
|
319
|
+
...props.series.map((series) =>
|
|
320
|
+
h(ui.Text, {
|
|
321
|
+
key: choiceKey(series.key),
|
|
322
|
+
text: `${series.label}: ${format(series.values[index])}`,
|
|
323
|
+
variant: 'caption',
|
|
324
|
+
tone: 'muted',
|
|
325
|
+
}),
|
|
326
|
+
),
|
|
327
|
+
],
|
|
328
|
+
),
|
|
329
|
+
),
|
|
330
|
+
),
|
|
331
|
+
),
|
|
332
|
+
],
|
|
333
|
+
)
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
})
|
|
337
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { useComponentLayout } from './component-motion.js'
|
|
2
|
+
import {
|
|
3
|
+
computed,
|
|
4
|
+
defineComponent,
|
|
5
|
+
h,
|
|
6
|
+
nextTick,
|
|
7
|
+
onMounted,
|
|
8
|
+
onScopeDispose,
|
|
9
|
+
ref,
|
|
10
|
+
watch,
|
|
11
|
+
type Component,
|
|
12
|
+
} from '@vue/runtime-core'
|
|
13
|
+
import { filterCommands, type CommandItem } from '../wayfinding.js'
|
|
14
|
+
import { choiceKey, type ChoiceValue } from '../choice.js'
|
|
15
|
+
import type { InputHandle } from '../input.js'
|
|
16
|
+
import { commandPaletteProps } from './wayfinding-props.js'
|
|
17
|
+
import { useCachedActivity } from './cached-activity.js'
|
|
18
|
+
|
|
19
|
+
export interface CommandKeyboard {
|
|
20
|
+
key: string
|
|
21
|
+
isComposing?: boolean
|
|
22
|
+
altKey?: boolean
|
|
23
|
+
ctrlKey?: boolean
|
|
24
|
+
metaKey?: boolean
|
|
25
|
+
preventDefault(): void
|
|
26
|
+
}
|
|
27
|
+
export function createCommandPalette(
|
|
28
|
+
ui: {
|
|
29
|
+
Sheet: Component
|
|
30
|
+
Input: Component
|
|
31
|
+
Column: Component
|
|
32
|
+
Row: Component
|
|
33
|
+
Text: Component
|
|
34
|
+
Button: Component
|
|
35
|
+
Badge: Component
|
|
36
|
+
focus(component: unknown): void
|
|
37
|
+
shortcut?(callback: () => void, enabled: () => boolean): () => void
|
|
38
|
+
},
|
|
39
|
+
platform: 'web' | 'native',
|
|
40
|
+
) {
|
|
41
|
+
return defineComponent({
|
|
42
|
+
name: 'MCommandPalette',
|
|
43
|
+
inheritAttrs: false,
|
|
44
|
+
props: commandPaletteProps,
|
|
45
|
+
emits: {
|
|
46
|
+
'update:open': (_value: boolean) => true,
|
|
47
|
+
'update:query': (_value: string) => true,
|
|
48
|
+
select: (_key: ChoiceValue, _item: CommandItem) => true,
|
|
49
|
+
},
|
|
50
|
+
setup(props, { attrs, emit }) {
|
|
51
|
+
const web = platform === 'web'
|
|
52
|
+
const active = useCachedActivity()
|
|
53
|
+
const local = ref('')
|
|
54
|
+
const input = ref<InputHandle>()
|
|
55
|
+
const buttons = new Map<string, unknown>()
|
|
56
|
+
const query = computed(() => props.query ?? local.value)
|
|
57
|
+
const matches = computed(() => filterCommands(props.items, query.value))
|
|
58
|
+
const resultsMotion = useComponentLayout(() => matches.value.map((item) => item.value), false)
|
|
59
|
+
function update(value: string) {
|
|
60
|
+
local.value = value
|
|
61
|
+
emit('update:query', value)
|
|
62
|
+
}
|
|
63
|
+
function select(item: CommandItem) {
|
|
64
|
+
if (!props.open || props.disabled || props.loading || item.disabled) return
|
|
65
|
+
emit('select', item.value, item)
|
|
66
|
+
emit('update:open', false)
|
|
67
|
+
}
|
|
68
|
+
let release = () => {}
|
|
69
|
+
onMounted(() => {
|
|
70
|
+
release =
|
|
71
|
+
ui.shortcut?.(
|
|
72
|
+
() => emit('update:open', !props.open),
|
|
73
|
+
() => active.value && props.shortcut && !props.disabled,
|
|
74
|
+
) ?? release
|
|
75
|
+
})
|
|
76
|
+
onScopeDispose(() => release())
|
|
77
|
+
watch(
|
|
78
|
+
() => props.open,
|
|
79
|
+
(open) => {
|
|
80
|
+
if (!open && props.query === undefined) local.value = ''
|
|
81
|
+
},
|
|
82
|
+
)
|
|
83
|
+
watch(
|
|
84
|
+
() => props.disabled,
|
|
85
|
+
(disabled) => {
|
|
86
|
+
if (disabled && props.open) emit('update:open', false)
|
|
87
|
+
},
|
|
88
|
+
)
|
|
89
|
+
function keys(event: CommandKeyboard, item?: CommandItem) {
|
|
90
|
+
if (
|
|
91
|
+
event.isComposing ||
|
|
92
|
+
event.altKey ||
|
|
93
|
+
event.ctrlKey ||
|
|
94
|
+
event.metaKey ||
|
|
95
|
+
props.loading ||
|
|
96
|
+
props.disabled
|
|
97
|
+
)
|
|
98
|
+
return
|
|
99
|
+
const available = matches.value.filter((entry) => !entry.disabled)
|
|
100
|
+
if (!available.length) return
|
|
101
|
+
const current = item ? available.findIndex((entry) => entry.value === item.value) : -1
|
|
102
|
+
let next: number
|
|
103
|
+
if (event.key === 'ArrowDown') next = Math.min(current + 1, available.length - 1)
|
|
104
|
+
else if (event.key === 'ArrowUp') next = current < 0 ? available.length - 1 : current - 1
|
|
105
|
+
else if (item && event.key === 'Home') next = 0
|
|
106
|
+
else if (item && event.key === 'End') next = available.length - 1
|
|
107
|
+
else if (!item && event.key === 'Enter') {
|
|
108
|
+
event.preventDefault()
|
|
109
|
+
select(available[0]!)
|
|
110
|
+
return
|
|
111
|
+
} else return
|
|
112
|
+
event.preventDefault()
|
|
113
|
+
if (next < 0) input.value?.focus()
|
|
114
|
+
else ui.focus(buttons.get(choiceKey(available[next]!.value)))
|
|
115
|
+
}
|
|
116
|
+
return () => {
|
|
117
|
+
if (!props.label.trim() || !props.searchLabel.trim())
|
|
118
|
+
throw new TypeError('Command palette requires a title and search label.')
|
|
119
|
+
return h(
|
|
120
|
+
ui.Sheet,
|
|
121
|
+
{
|
|
122
|
+
...attrs,
|
|
123
|
+
id: props.id,
|
|
124
|
+
open: props.open && !props.disabled,
|
|
125
|
+
title: props.label,
|
|
126
|
+
closeLabel: props.closeLabel,
|
|
127
|
+
returnFocus: props.returnFocus,
|
|
128
|
+
gap: 'md',
|
|
129
|
+
'onUpdate:open': (open: boolean) => emit('update:open', open),
|
|
130
|
+
},
|
|
131
|
+
() => [
|
|
132
|
+
h(ui.Input, {
|
|
133
|
+
ref: input,
|
|
134
|
+
label: props.searchLabel,
|
|
135
|
+
placeholder: props.placeholder,
|
|
136
|
+
modelValue: query.value,
|
|
137
|
+
disabled: props.disabled,
|
|
138
|
+
'onUpdate:modelValue': update,
|
|
139
|
+
onSubmit: web
|
|
140
|
+
? undefined
|
|
141
|
+
: () => {
|
|
142
|
+
const first = matches.value.find((item) => !item.disabled)
|
|
143
|
+
if (first) select(first)
|
|
144
|
+
},
|
|
145
|
+
...(web
|
|
146
|
+
? {
|
|
147
|
+
onKeydown: (event: CommandKeyboard) => keys(event),
|
|
148
|
+
onVnodeMounted: () =>
|
|
149
|
+
void nextTick(() => {
|
|
150
|
+
if (props.open) input.value?.focus()
|
|
151
|
+
}),
|
|
152
|
+
}
|
|
153
|
+
: {}),
|
|
154
|
+
}),
|
|
155
|
+
h(
|
|
156
|
+
ui.Column,
|
|
157
|
+
{
|
|
158
|
+
gap: 'xs',
|
|
159
|
+
motionRegion: resultsMotion,
|
|
160
|
+
...(web
|
|
161
|
+
? {
|
|
162
|
+
class: 'm-command-results',
|
|
163
|
+
role: 'group',
|
|
164
|
+
'aria-label': props.label,
|
|
165
|
+
'aria-busy': props.loading,
|
|
166
|
+
}
|
|
167
|
+
: {}),
|
|
168
|
+
},
|
|
169
|
+
() =>
|
|
170
|
+
props.loading || !matches.value.length
|
|
171
|
+
? h(ui.Text, {
|
|
172
|
+
text: props.loading ? props.loadingLabel : props.emptyLabel,
|
|
173
|
+
tone: 'muted',
|
|
174
|
+
...(web ? { role: 'status' } : { accessibilityLiveRegion: 'polite' }),
|
|
175
|
+
})
|
|
176
|
+
: matches.value.flatMap((item, index) => [
|
|
177
|
+
item.group && item.group !== matches.value[index - 1]?.group
|
|
178
|
+
? h(ui.Text, {
|
|
179
|
+
key: `group:${choiceKey(item.value)}`,
|
|
180
|
+
text: item.group,
|
|
181
|
+
variant: 'overline',
|
|
182
|
+
tone: 'muted',
|
|
183
|
+
})
|
|
184
|
+
: null,
|
|
185
|
+
h(
|
|
186
|
+
ui.Column,
|
|
187
|
+
{ key: choiceKey(item.value), gap: 'xs', paddingY: 'xs' },
|
|
188
|
+
() => [
|
|
189
|
+
h(
|
|
190
|
+
ui.Button,
|
|
191
|
+
{
|
|
192
|
+
ref: (value: unknown) => {
|
|
193
|
+
if (value) buttons.set(choiceKey(item.value), value)
|
|
194
|
+
else buttons.delete(choiceKey(item.value))
|
|
195
|
+
},
|
|
196
|
+
text: item.label,
|
|
197
|
+
icon: item.icon,
|
|
198
|
+
variant: 'ghost',
|
|
199
|
+
disabled: item.disabled,
|
|
200
|
+
accessibilityLabel: `${item.label}${item.shortcut ? ` ${item.shortcut}` : ''}`,
|
|
201
|
+
...(web
|
|
202
|
+
? {
|
|
203
|
+
style: { justifyContent: 'flex-start' },
|
|
204
|
+
onKeydown: (event: CommandKeyboard) => keys(event, item),
|
|
205
|
+
}
|
|
206
|
+
: {}),
|
|
207
|
+
onClick: () => select(item),
|
|
208
|
+
},
|
|
209
|
+
item.shortcut
|
|
210
|
+
? {
|
|
211
|
+
trailing: () => [
|
|
212
|
+
web ? ' ' : null,
|
|
213
|
+
h(ui.Badge, { text: item.shortcut, accessibilityHidden: true }),
|
|
214
|
+
],
|
|
215
|
+
}
|
|
216
|
+
: undefined,
|
|
217
|
+
),
|
|
218
|
+
item.description
|
|
219
|
+
? h(ui.Text, {
|
|
220
|
+
text: item.description,
|
|
221
|
+
variant: 'caption',
|
|
222
|
+
tone: 'muted',
|
|
223
|
+
paddingX: 'sm',
|
|
224
|
+
})
|
|
225
|
+
: null,
|
|
226
|
+
],
|
|
227
|
+
),
|
|
228
|
+
]),
|
|
229
|
+
),
|
|
230
|
+
],
|
|
231
|
+
)
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
})
|
|
235
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { markRaw, onScopeDispose, watch, type WatchSource } from '@vue/runtime-core'
|
|
2
|
+
import {
|
|
3
|
+
createMotionRegion,
|
|
4
|
+
createMotionSurface,
|
|
5
|
+
type MotionValues,
|
|
6
|
+
type MotionPlayback,
|
|
7
|
+
type MotionSharedLayout,
|
|
8
|
+
type MotionRegion,
|
|
9
|
+
} from '../experimental.js'
|
|
10
|
+
import { componentMotion, type ComponentMotion } from '../motion.js'
|
|
11
|
+
import { useMavisTheme } from './theme.js'
|
|
12
|
+
|
|
13
|
+
const componentRegions = new WeakSet<MotionRegion>()
|
|
14
|
+
function createComponentRegion() {
|
|
15
|
+
const region = markRaw(createMotionRegion())
|
|
16
|
+
componentRegions.add(region)
|
|
17
|
+
return region
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** @internal Built-in layout must not isolate application-owned descendant surfaces. */
|
|
21
|
+
export function isComponentMotionRegion(region: MotionRegion) {
|
|
22
|
+
return componentRegions.has(region)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** A private decorative surface. Initial state is immediate; subsequent states are continuous. */
|
|
26
|
+
export function useComponentState(read: () => MotionValues, kind: ComponentMotion = 'selection') {
|
|
27
|
+
const { theme } = useMavisTheme()
|
|
28
|
+
const surface = markRaw(createMotionSurface())
|
|
29
|
+
onScopeDispose(
|
|
30
|
+
surface.use((owner) => {
|
|
31
|
+
owner.set(read())
|
|
32
|
+
}),
|
|
33
|
+
)
|
|
34
|
+
watch(
|
|
35
|
+
read,
|
|
36
|
+
(values) => {
|
|
37
|
+
if (surface.available) surface.animate(values, componentMotion(theme.value, kind))
|
|
38
|
+
},
|
|
39
|
+
{ deep: true, flush: 'post' },
|
|
40
|
+
)
|
|
41
|
+
return surface
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Vue pre-watch captures old layout; Jolt waits for renderer layout after the patch. */
|
|
45
|
+
export function useComponentLayout(source: WatchSource, enter = true, enabled = () => true) {
|
|
46
|
+
const { theme } = useMavisTheme()
|
|
47
|
+
const region = createComponentRegion()
|
|
48
|
+
let active: MotionPlayback | undefined
|
|
49
|
+
watch(
|
|
50
|
+
source,
|
|
51
|
+
() => {
|
|
52
|
+
if (enabled() && region.available) {
|
|
53
|
+
active = region.animateLayout(() => {}, {
|
|
54
|
+
transition: componentMotion(theme.value, 'layout'),
|
|
55
|
+
size: false,
|
|
56
|
+
enter,
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
{ deep: true, flush: 'pre' },
|
|
61
|
+
)
|
|
62
|
+
onScopeDispose(() => active?.stop())
|
|
63
|
+
return region
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** One identity follows the active destination without moving focus or the destination itself. */
|
|
67
|
+
export function useComponentSelection(source: WatchSource) {
|
|
68
|
+
const { theme } = useMavisTheme()
|
|
69
|
+
const region = createComponentRegion()
|
|
70
|
+
const marker = markRaw(createMotionSurface())
|
|
71
|
+
let layout: MotionSharedLayout | undefined
|
|
72
|
+
onScopeDispose(
|
|
73
|
+
region.onAvailable(() => {
|
|
74
|
+
const owned = region.sharedLayout({ transition: componentMotion(theme.value, 'selection') })
|
|
75
|
+
layout = owned
|
|
76
|
+
const detach = owned.attach(marker, 'selection')
|
|
77
|
+
return () => {
|
|
78
|
+
detach()
|
|
79
|
+
owned.dispose()
|
|
80
|
+
if (layout === owned) layout = undefined
|
|
81
|
+
}
|
|
82
|
+
}),
|
|
83
|
+
)
|
|
84
|
+
watch(
|
|
85
|
+
source,
|
|
86
|
+
() => {
|
|
87
|
+
layout?.transition(() => {}, componentMotion(theme.value, 'selection'))
|
|
88
|
+
},
|
|
89
|
+
{ flush: 'pre' },
|
|
90
|
+
)
|
|
91
|
+
return { region, marker }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Short content feedback; editable values must never use this presentation recipe. */
|
|
95
|
+
export function useComponentContent(source?: WatchSource, appear = true) {
|
|
96
|
+
const { theme } = useMavisTheme()
|
|
97
|
+
const surface = markRaw(createMotionSurface())
|
|
98
|
+
const play = () => {
|
|
99
|
+
if (surface.available)
|
|
100
|
+
surface.animate({ opacity: [0.65, 1], y: [3, 0] }, componentMotion(theme.value, 'overlay'))
|
|
101
|
+
}
|
|
102
|
+
onScopeDispose(
|
|
103
|
+
surface.use(() => {
|
|
104
|
+
if (appear) play()
|
|
105
|
+
}),
|
|
106
|
+
)
|
|
107
|
+
if (source) watch(source, play, { flush: 'post' })
|
|
108
|
+
return surface
|
|
109
|
+
}
|