@getcortexlabs/mavis-core 0.1.0-rc.11.1 → 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 +23 -4
- package/dist/capabilities.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/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- 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/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/component-props.d.ts +692 -3
- package/dist/vue/component-props.d.ts.map +1 -1
- package/dist/vue/component-props.js +22 -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 +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/discovery-controls.d.ts +1 -1
- package/dist/vue/global-components.d.ts +106 -0
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/index.d.ts +16 -0
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +16 -0
- package/dist/vue/index.js.map +1 -1
- 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/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/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/props.d.ts +6 -6
- 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/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-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 +2 -2
- 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 +1 -1
- package/package.json +1 -1
- package/src/capabilities.ts +24 -4
- package/src/creative-controls.ts +169 -0
- package/src/dashboard.ts +164 -0
- package/src/index.ts +5 -0
- package/src/screen-components.ts +59 -0
- package/src/vue/animated-text.ts +72 -0
- package/src/vue/component-props.ts +47 -0
- package/src/vue/composer.ts +192 -0
- 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/global-components.ts +116 -0
- package/src/vue/index.ts +20 -0
- package/src/vue/kanban.ts +360 -0
- package/src/vue/marquee.ts +248 -0
- package/src/vue/pin-cell.ts +26 -0
- package/src/vue/pin-input.ts +31 -0
- package/src/vue/screen-component-props.ts +92 -0
- package/src/vue/scroll-frame.ts +429 -0
- package/src/vue/speed-dial.ts +108 -0
- package/src/vue/swipe-deck.ts +277 -0
- package/src/vue/tour.ts +239 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
defineComponent,
|
|
4
|
+
h,
|
|
5
|
+
markRaw,
|
|
6
|
+
mergeProps,
|
|
7
|
+
nextTick,
|
|
8
|
+
onScopeDispose,
|
|
9
|
+
ref,
|
|
10
|
+
watch,
|
|
11
|
+
} from '@vue/runtime-core'
|
|
12
|
+
import { createMotionSurface, type MotionDrag, type MotionPlayback } from '../experimental.js'
|
|
13
|
+
import {
|
|
14
|
+
deckDecision,
|
|
15
|
+
validateCards,
|
|
16
|
+
type SwipeCard,
|
|
17
|
+
type SwipeDecision,
|
|
18
|
+
} from '../creative-controls.js'
|
|
19
|
+
import { swipeDeckProps } from './creative-props.js'
|
|
20
|
+
import type { CreativeUI } from './creative-controls.js'
|
|
21
|
+
import type { ChoiceValue } from '../choice.js'
|
|
22
|
+
import { useMavisTheme } from './theme.js'
|
|
23
|
+
import { componentMotion } from '../motion.js'
|
|
24
|
+
|
|
25
|
+
export function createSwipeDeck(ui: CreativeUI, platform: 'web' | 'native') {
|
|
26
|
+
return defineComponent({
|
|
27
|
+
name: 'MSwipeDeck',
|
|
28
|
+
inheritAttrs: false,
|
|
29
|
+
props: swipeDeckProps,
|
|
30
|
+
emits: {
|
|
31
|
+
'update:modelValue': (_id: ChoiceValue | null) => true,
|
|
32
|
+
decide: (_event: { item: SwipeCard; decision: SwipeDecision }) => true,
|
|
33
|
+
undo: () => true,
|
|
34
|
+
},
|
|
35
|
+
setup(props, { attrs, slots, emit }) {
|
|
36
|
+
const { theme } = useMavisTheme()
|
|
37
|
+
const surface = markRaw(createMotionSurface())
|
|
38
|
+
const busy = ref(false)
|
|
39
|
+
const index = computed(() =>
|
|
40
|
+
validateCards(props.items).findIndex((item) => item.id === props.modelValue),
|
|
41
|
+
)
|
|
42
|
+
const item = computed(() => props.items[index.value])
|
|
43
|
+
let drag: MotionDrag | undefined,
|
|
44
|
+
playback: MotionPlayback | undefined,
|
|
45
|
+
revision = 0
|
|
46
|
+
function reset() {
|
|
47
|
+
revision++
|
|
48
|
+
busy.value = false
|
|
49
|
+
playback?.stop()
|
|
50
|
+
if (surface.available) {
|
|
51
|
+
drag?.cancel()
|
|
52
|
+
surface.set({ x: 0, y: 0, rotate: 0, opacity: 1, scale: 1 })
|
|
53
|
+
if (!props.disabled) drag?.resume()
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function settle() {
|
|
57
|
+
if (surface.available) {
|
|
58
|
+
if (props.animated)
|
|
59
|
+
surface.animate({ x: 0, rotate: 0 }, componentMotion(theme.value, 'selection'))
|
|
60
|
+
else surface.set({ x: 0, rotate: 0 })
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async function decide(decision: SwipeDecision) {
|
|
64
|
+
const current = item.value
|
|
65
|
+
if (props.disabled || busy.value || !current) return
|
|
66
|
+
busy.value = true
|
|
67
|
+
const token = ++revision,
|
|
68
|
+
next = props.items[index.value + 1]?.id ?? null
|
|
69
|
+
drag?.pause()
|
|
70
|
+
if (surface.available && props.animated) {
|
|
71
|
+
playback = surface.animate(
|
|
72
|
+
{
|
|
73
|
+
x: decision === 'accept' ? 340 : -340,
|
|
74
|
+
rotate: decision === 'accept' ? 14 : -14,
|
|
75
|
+
opacity: 0,
|
|
76
|
+
},
|
|
77
|
+
{ duration: 220, ease: 'easeIn' },
|
|
78
|
+
)
|
|
79
|
+
await playback.finished
|
|
80
|
+
}
|
|
81
|
+
if (token !== revision || props.disabled || item.value?.id !== current.id) return
|
|
82
|
+
emit('decide', { item: current, decision })
|
|
83
|
+
emit('update:modelValue', next)
|
|
84
|
+
await nextTick()
|
|
85
|
+
if (token === revision) {
|
|
86
|
+
busy.value = false
|
|
87
|
+
drag?.resume()
|
|
88
|
+
settle()
|
|
89
|
+
if (surface.available) surface.set({ opacity: 1 })
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
onScopeDispose(
|
|
93
|
+
surface.use((owner) => {
|
|
94
|
+
const stop = watch(
|
|
95
|
+
() => [props.disabled, props.threshold],
|
|
96
|
+
() => {
|
|
97
|
+
drag?.dispose()
|
|
98
|
+
drag = undefined
|
|
99
|
+
if (!Number.isFinite(props.threshold) || props.threshold <= 0)
|
|
100
|
+
throw new RangeError('Swipe threshold must be positive.')
|
|
101
|
+
if (props.disabled) {
|
|
102
|
+
reset()
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
drag = owner.drag({
|
|
106
|
+
axis: 'x',
|
|
107
|
+
bounds: { left: -360, right: 360 },
|
|
108
|
+
onRelease: (event) => {
|
|
109
|
+
const decision = deckDecision(event.x, event.velocityX, props.threshold)
|
|
110
|
+
void nextTick(() => {
|
|
111
|
+
if (decision) void decide(decision)
|
|
112
|
+
else settle()
|
|
113
|
+
})
|
|
114
|
+
},
|
|
115
|
+
})
|
|
116
|
+
},
|
|
117
|
+
{ immediate: true },
|
|
118
|
+
)
|
|
119
|
+
return () => {
|
|
120
|
+
revision++
|
|
121
|
+
busy.value = false
|
|
122
|
+
playback?.stop()
|
|
123
|
+
stop()
|
|
124
|
+
drag?.dispose()
|
|
125
|
+
drag = undefined
|
|
126
|
+
}
|
|
127
|
+
}),
|
|
128
|
+
)
|
|
129
|
+
watch(() => [props.modelValue, props.items], reset, { flush: 'post' })
|
|
130
|
+
onScopeDispose(() => {
|
|
131
|
+
revision++
|
|
132
|
+
playback?.stop()
|
|
133
|
+
})
|
|
134
|
+
return () => {
|
|
135
|
+
if (!Number.isFinite(props.height) || props.height < 180)
|
|
136
|
+
throw new RangeError('Swipe deck height must be at least 180.')
|
|
137
|
+
return h(
|
|
138
|
+
ui.Column,
|
|
139
|
+
mergeProps(attrs, {
|
|
140
|
+
id: props.id,
|
|
141
|
+
gap: 'md',
|
|
142
|
+
...(platform === 'web'
|
|
143
|
+
? { role: 'region', 'aria-label': props.label, class: 'm-swipe-deck' }
|
|
144
|
+
: { accessibilityLabel: props.label }),
|
|
145
|
+
}),
|
|
146
|
+
{
|
|
147
|
+
default: () => [
|
|
148
|
+
h(ui.Text, { text: props.label, variant: 'heading' }),
|
|
149
|
+
h(
|
|
150
|
+
ui.Box,
|
|
151
|
+
{
|
|
152
|
+
height: props.height + 20,
|
|
153
|
+
...(platform === 'web'
|
|
154
|
+
? { style: { display: 'grid', overflow: 'hidden', touchAction: 'pan-y' } }
|
|
155
|
+
: { clipToBounds: true }),
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
default: () =>
|
|
159
|
+
item.value
|
|
160
|
+
? [
|
|
161
|
+
...[2, 1]
|
|
162
|
+
.filter((depth) => props.items[index.value + depth])
|
|
163
|
+
.map((depth) =>
|
|
164
|
+
h(ui.Box, {
|
|
165
|
+
key: depth,
|
|
166
|
+
backgroundColor:
|
|
167
|
+
depth === 1
|
|
168
|
+
? theme.value.colors.primarySoft
|
|
169
|
+
: theme.value.colors.elevated,
|
|
170
|
+
radius: 'lg',
|
|
171
|
+
margin: depth * 8,
|
|
172
|
+
height: props.height,
|
|
173
|
+
accessibilityHidden: true,
|
|
174
|
+
...(platform === 'web'
|
|
175
|
+
? {
|
|
176
|
+
style: {
|
|
177
|
+
gridArea: '1 / 1',
|
|
178
|
+
transform: `translateY(${depth * 6}px)`,
|
|
179
|
+
},
|
|
180
|
+
}
|
|
181
|
+
: { translateY: depth * 6 }),
|
|
182
|
+
}),
|
|
183
|
+
),
|
|
184
|
+
h(
|
|
185
|
+
ui.Card,
|
|
186
|
+
{
|
|
187
|
+
key: 'active',
|
|
188
|
+
id: props.id ? `${props.id}-card` : undefined,
|
|
189
|
+
motionSurface: surface,
|
|
190
|
+
padding: 'lg',
|
|
191
|
+
height: props.height,
|
|
192
|
+
radius: 'lg',
|
|
193
|
+
...(platform === 'web'
|
|
194
|
+
? {
|
|
195
|
+
style: {
|
|
196
|
+
gridArea: '1 / 1',
|
|
197
|
+
userSelect: 'none',
|
|
198
|
+
touchAction: 'pan-y',
|
|
199
|
+
},
|
|
200
|
+
}
|
|
201
|
+
: {}),
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
default: () =>
|
|
205
|
+
slots.item?.({ item: item.value, index: index.value }) ??
|
|
206
|
+
h(
|
|
207
|
+
ui.Column,
|
|
208
|
+
{ gap: 'md' },
|
|
209
|
+
{
|
|
210
|
+
default: () => [
|
|
211
|
+
item.value!.image
|
|
212
|
+
? h(ui.Image, {
|
|
213
|
+
src: item.value!.image,
|
|
214
|
+
alt: '',
|
|
215
|
+
height: Math.max(80, props.height - 180),
|
|
216
|
+
width: '100%',
|
|
217
|
+
fit: 'cover',
|
|
218
|
+
radius: 'md',
|
|
219
|
+
})
|
|
220
|
+
: null,
|
|
221
|
+
h(ui.Text, { text: item.value!.title, variant: 'title' }),
|
|
222
|
+
h(ui.Text, { text: item.value!.description, tone: 'muted' }),
|
|
223
|
+
],
|
|
224
|
+
},
|
|
225
|
+
),
|
|
226
|
+
},
|
|
227
|
+
),
|
|
228
|
+
]
|
|
229
|
+
: [h(ui.Text, { text: props.emptyLabel, variant: 'heading' })],
|
|
230
|
+
},
|
|
231
|
+
),
|
|
232
|
+
h(
|
|
233
|
+
ui.Row,
|
|
234
|
+
{ gap: 'sm', wrap: true },
|
|
235
|
+
{
|
|
236
|
+
default: () => [
|
|
237
|
+
h(ui.Button, {
|
|
238
|
+
text: props.rejectLabel,
|
|
239
|
+
icon: 'x',
|
|
240
|
+
variant: 'secondary',
|
|
241
|
+
disabled: props.disabled || busy.value || !item.value,
|
|
242
|
+
onClick: () => void decide('reject'),
|
|
243
|
+
}),
|
|
244
|
+
h(ui.Button, {
|
|
245
|
+
text: props.acceptLabel,
|
|
246
|
+
icon: 'check',
|
|
247
|
+
disabled: props.disabled || busy.value || !item.value,
|
|
248
|
+
onClick: () => void decide('accept'),
|
|
249
|
+
}),
|
|
250
|
+
h(ui.Button, {
|
|
251
|
+
text: props.undoLabel,
|
|
252
|
+
icon: 'undo-2',
|
|
253
|
+
variant: 'ghost',
|
|
254
|
+
disabled: props.disabled || busy.value || !props.canUndo,
|
|
255
|
+
onClick: () => {
|
|
256
|
+
if (!props.disabled && !busy.value && props.canUndo) emit('undo')
|
|
257
|
+
},
|
|
258
|
+
}),
|
|
259
|
+
],
|
|
260
|
+
},
|
|
261
|
+
),
|
|
262
|
+
h(ui.Text, {
|
|
263
|
+
text: item.value
|
|
264
|
+
? `${index.value + 1} / ${props.items.length} · ${item.value.title}`
|
|
265
|
+
: props.emptyLabel,
|
|
266
|
+
variant: 'caption',
|
|
267
|
+
...(platform === 'web'
|
|
268
|
+
? { role: 'status', 'aria-live': 'polite' }
|
|
269
|
+
: { accessibilityLiveRegion: 'polite' }),
|
|
270
|
+
}),
|
|
271
|
+
],
|
|
272
|
+
},
|
|
273
|
+
)
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
})
|
|
277
|
+
}
|
package/src/vue/tour.ts
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
defineComponent,
|
|
4
|
+
h,
|
|
5
|
+
inject,
|
|
6
|
+
mergeProps,
|
|
7
|
+
nextTick,
|
|
8
|
+
onMounted,
|
|
9
|
+
onScopeDispose,
|
|
10
|
+
provide,
|
|
11
|
+
reactive,
|
|
12
|
+
ref,
|
|
13
|
+
watch,
|
|
14
|
+
type Component,
|
|
15
|
+
type InjectionKey,
|
|
16
|
+
} from '@vue/runtime-core'
|
|
17
|
+
import { validateTour, type TourStep } from '../creative-controls.js'
|
|
18
|
+
import { tourProps, tourTargetProps } from './creative-props.js'
|
|
19
|
+
import { useComponentState } from './component-motion.js'
|
|
20
|
+
import { useMavisTheme } from './theme.js'
|
|
21
|
+
|
|
22
|
+
interface TourContext {
|
|
23
|
+
current(): TourStep | undefined
|
|
24
|
+
register(id: string): () => void
|
|
25
|
+
panel(): ReturnType<typeof h>
|
|
26
|
+
close(reason: string): void
|
|
27
|
+
animated(): boolean
|
|
28
|
+
}
|
|
29
|
+
const tourKey: InjectionKey<TourContext> = Symbol('mavis-tour')
|
|
30
|
+
export const tourHostProps = { active: Boolean, restoreFocus: { type: Boolean, default: true } }
|
|
31
|
+
export function createTour(
|
|
32
|
+
ui: {
|
|
33
|
+
Column: Component
|
|
34
|
+
Row: Component
|
|
35
|
+
Box: Component
|
|
36
|
+
Text: Component
|
|
37
|
+
Button: Component
|
|
38
|
+
Popover: Component
|
|
39
|
+
Host: Component
|
|
40
|
+
TargetHost: Component
|
|
41
|
+
},
|
|
42
|
+
platform: 'web' | 'native',
|
|
43
|
+
) {
|
|
44
|
+
const MTour = defineComponent({
|
|
45
|
+
name: 'MTour',
|
|
46
|
+
inheritAttrs: false,
|
|
47
|
+
props: tourProps,
|
|
48
|
+
emits: {
|
|
49
|
+
'update:modelValue': (_id: string | null) => true,
|
|
50
|
+
finish: (_reason: string) => true,
|
|
51
|
+
missing: (_id: string) => true,
|
|
52
|
+
},
|
|
53
|
+
setup(props, { attrs, slots, emit }) {
|
|
54
|
+
const targets = reactive(new Set<string>())
|
|
55
|
+
const index = computed(() =>
|
|
56
|
+
validateTour(props.steps).findIndex((step) => step.id === props.modelValue),
|
|
57
|
+
)
|
|
58
|
+
const step = computed(() => props.steps[index.value])
|
|
59
|
+
let mounted = false,
|
|
60
|
+
generation = 0
|
|
61
|
+
const closeReason = ref('')
|
|
62
|
+
watch(
|
|
63
|
+
() => props.modelValue,
|
|
64
|
+
(value) => {
|
|
65
|
+
if (value !== null) closeReason.value = ''
|
|
66
|
+
},
|
|
67
|
+
)
|
|
68
|
+
function close(reason: string) {
|
|
69
|
+
if (props.modelValue === null) return
|
|
70
|
+
closeReason.value = reason
|
|
71
|
+
emit('update:modelValue', null)
|
|
72
|
+
emit('finish', reason)
|
|
73
|
+
}
|
|
74
|
+
function move(direction: number) {
|
|
75
|
+
for (let i = index.value + direction; i >= 0 && i < props.steps.length; i += direction) {
|
|
76
|
+
const next = props.steps[i]!
|
|
77
|
+
if (targets.has(next.id)) {
|
|
78
|
+
emit('update:modelValue', next.id)
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
emit('missing', next.id)
|
|
82
|
+
}
|
|
83
|
+
close(direction > 0 ? 'complete' : 'missing')
|
|
84
|
+
}
|
|
85
|
+
async function check() {
|
|
86
|
+
const token = ++generation
|
|
87
|
+
await nextTick()
|
|
88
|
+
if (!mounted || token !== generation || props.modelValue === null) return
|
|
89
|
+
if (!step.value || !targets.has(step.value.id)) {
|
|
90
|
+
emit('missing', props.modelValue)
|
|
91
|
+
move(1)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
provide(tourKey, {
|
|
95
|
+
current: () => step.value,
|
|
96
|
+
animated: () => props.animated,
|
|
97
|
+
register(id) {
|
|
98
|
+
if (!id.trim() || targets.has(id))
|
|
99
|
+
throw new TypeError('Tour target names must be nonempty and unique within a tour.')
|
|
100
|
+
targets.add(id)
|
|
101
|
+
return () => targets.delete(id)
|
|
102
|
+
},
|
|
103
|
+
close,
|
|
104
|
+
panel: () =>
|
|
105
|
+
h(
|
|
106
|
+
ui.Column,
|
|
107
|
+
{ gap: 'md' },
|
|
108
|
+
{
|
|
109
|
+
default: () => [
|
|
110
|
+
h(ui.Text, {
|
|
111
|
+
text: `${props.label} · ${index.value + 1} / ${props.steps.length}`,
|
|
112
|
+
variant: 'caption',
|
|
113
|
+
tone: 'muted',
|
|
114
|
+
}),
|
|
115
|
+
h(ui.Text, { text: step.value?.title, variant: 'heading' }),
|
|
116
|
+
h(ui.Text, { text: step.value?.description }),
|
|
117
|
+
h(
|
|
118
|
+
ui.Row,
|
|
119
|
+
{ gap: 'xs', wrap: true },
|
|
120
|
+
{
|
|
121
|
+
default: () => [
|
|
122
|
+
h(ui.Button, {
|
|
123
|
+
text: props.backLabel,
|
|
124
|
+
variant: 'secondary',
|
|
125
|
+
disabled: index.value <= 0,
|
|
126
|
+
onClick: () => move(-1),
|
|
127
|
+
}),
|
|
128
|
+
h(ui.Button, {
|
|
129
|
+
text:
|
|
130
|
+
index.value === props.steps.length - 1
|
|
131
|
+
? props.finishLabel
|
|
132
|
+
: props.nextLabel,
|
|
133
|
+
onClick: () => move(1),
|
|
134
|
+
}),
|
|
135
|
+
h(ui.Button, {
|
|
136
|
+
text: props.skipLabel,
|
|
137
|
+
variant: 'ghost',
|
|
138
|
+
onClick: () => close('skip'),
|
|
139
|
+
}),
|
|
140
|
+
],
|
|
141
|
+
},
|
|
142
|
+
),
|
|
143
|
+
],
|
|
144
|
+
},
|
|
145
|
+
),
|
|
146
|
+
})
|
|
147
|
+
watch(() => [props.modelValue, props.steps, [...targets]], check, {
|
|
148
|
+
flush: 'post',
|
|
149
|
+
deep: true,
|
|
150
|
+
})
|
|
151
|
+
onMounted(() => {
|
|
152
|
+
mounted = true
|
|
153
|
+
void check()
|
|
154
|
+
})
|
|
155
|
+
onScopeDispose(() => {
|
|
156
|
+
mounted = false
|
|
157
|
+
generation++
|
|
158
|
+
})
|
|
159
|
+
return () =>
|
|
160
|
+
h(
|
|
161
|
+
ui.Host,
|
|
162
|
+
mergeProps(attrs, {
|
|
163
|
+
id: props.id,
|
|
164
|
+
active: props.modelValue !== null,
|
|
165
|
+
restoreFocus: closeReason.value !== 'outside',
|
|
166
|
+
...(platform === 'web' ? { class: 'm-tour' } : {}),
|
|
167
|
+
}),
|
|
168
|
+
slots,
|
|
169
|
+
)
|
|
170
|
+
},
|
|
171
|
+
})
|
|
172
|
+
const MTourTarget = defineComponent({
|
|
173
|
+
name: 'MTourTarget',
|
|
174
|
+
inheritAttrs: false,
|
|
175
|
+
props: tourTargetProps,
|
|
176
|
+
setup(props, { attrs, slots }) {
|
|
177
|
+
const context = inject(tourKey)
|
|
178
|
+
if (!context) throw new Error('MTourTarget must be inside MTour.')
|
|
179
|
+
const { theme } = useMavisTheme()
|
|
180
|
+
const active = computed(() => context.current()?.id === props.name)
|
|
181
|
+
const surface = useComponentState(() => ({ opacity: active.value ? 1 : 0.55 }), 'selection')
|
|
182
|
+
let release = () => {}
|
|
183
|
+
watch(
|
|
184
|
+
() => props.name,
|
|
185
|
+
(name) => {
|
|
186
|
+
release()
|
|
187
|
+
release = context.register(name)
|
|
188
|
+
},
|
|
189
|
+
{ immediate: true },
|
|
190
|
+
)
|
|
191
|
+
onScopeDispose(() => release())
|
|
192
|
+
return () =>
|
|
193
|
+
h(
|
|
194
|
+
ui.TargetHost,
|
|
195
|
+
mergeProps(attrs, {
|
|
196
|
+
active: active.value,
|
|
197
|
+
...(platform === 'web'
|
|
198
|
+
? { class: 'm-tour-target', 'data-tour-target': props.name }
|
|
199
|
+
: {}),
|
|
200
|
+
}),
|
|
201
|
+
{
|
|
202
|
+
default: () =>
|
|
203
|
+
h(
|
|
204
|
+
ui.Popover,
|
|
205
|
+
{
|
|
206
|
+
open: active.value,
|
|
207
|
+
label: context.current()?.title ?? props.name,
|
|
208
|
+
triggerLabel: props.name,
|
|
209
|
+
width: 320,
|
|
210
|
+
onClose: (reason: string) => {
|
|
211
|
+
if (active.value) context.close(reason)
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
anchor: () =>
|
|
216
|
+
h(
|
|
217
|
+
ui.Box,
|
|
218
|
+
{
|
|
219
|
+
padding: 'xs',
|
|
220
|
+
radius: 'md',
|
|
221
|
+
borderWidth: 2,
|
|
222
|
+
borderColor: active.value ? theme.value.colors.primary : 'transparent',
|
|
223
|
+
},
|
|
224
|
+
{ default: () => slots.default?.({ active: active.value }) },
|
|
225
|
+
),
|
|
226
|
+
default: () =>
|
|
227
|
+
h(
|
|
228
|
+
ui.Column,
|
|
229
|
+
{ motionSurface: context.animated() ? surface : undefined, gap: 'sm' },
|
|
230
|
+
{ default: () => context.panel() },
|
|
231
|
+
),
|
|
232
|
+
},
|
|
233
|
+
),
|
|
234
|
+
},
|
|
235
|
+
)
|
|
236
|
+
},
|
|
237
|
+
})
|
|
238
|
+
return { MTour, MTourTarget }
|
|
239
|
+
}
|