@getcortexlabs/mavis-web 0.1.0-rc.12.2 → 0.1.0-rc.14
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 +4 -4
- package/dist/animated-number.d.ts.map +1 -1
- package/dist/animated-number.js +8 -10
- package/dist/animated-number.js.map +1 -1
- package/dist/component-motion.d.ts.map +1 -1
- package/dist/component-motion.js +26 -3
- package/dist/component-motion.js.map +1 -1
- package/dist/components/ChartPlot.d.ts +8 -0
- package/dist/components/ChartPlot.d.ts.map +1 -1
- package/dist/components/ChartPlot.js +30 -8
- package/dist/components/ChartPlot.js.map +1 -1
- package/dist/components/DateCalendar.d.ts +1 -1
- package/dist/components/DateCalendar.d.ts.map +1 -1
- package/dist/components/DateCalendar.js +3 -1
- package/dist/components/DateCalendar.js.map +1 -1
- package/dist/components/MButton.d.ts +7 -7
- package/dist/components/MCard.d.ts.map +1 -1
- package/dist/components/MCard.js +68 -21
- package/dist/components/MCard.js.map +1 -1
- package/dist/components/MChip.d.ts +1 -1
- package/dist/components/MDatePicker.d.ts +96 -96
- package/dist/components/MDatePicker.d.ts.map +1 -1
- package/dist/components/MEmptyState.d.ts +1 -1
- package/dist/components/MInput.d.ts +5 -5
- package/dist/components/MInput.d.ts.map +1 -1
- package/dist/components/MInput.js +16 -4
- package/dist/components/MInput.js.map +1 -1
- package/dist/components/MLink.d.ts +1 -1
- package/dist/components/MPopover.d.ts +1 -1
- package/dist/components/MProgress.d.ts +1 -1
- package/dist/components/MRangeSlider.d.ts +2 -2
- package/dist/components/MResizablePanels.d.ts +2 -2
- package/dist/components/MReveal.d.ts +10 -10
- package/dist/components/MSheet.d.ts +5 -5
- package/dist/components/MSlider.d.ts +2 -2
- package/dist/components/MStack.d.ts +10 -10
- package/dist/components/MTimePicker.d.ts +40 -40
- package/dist/components/MTimePicker.d.ts.map +1 -1
- package/dist/components/MTooltip.d.ts +1 -1
- package/dist/components/MVirtualList.d.ts.map +1 -1
- package/dist/components/MVirtualList.js +111 -40
- package/dist/components/MVirtualList.js.map +1 -1
- package/dist/components/advanced.d.ts +34 -34
- package/dist/components/configurator.d.ts +33 -33
- package/dist/components/creative.d.ts +20 -20
- package/dist/components/creative.d.ts.map +1 -1
- package/dist/components/creative.js +7 -5
- package/dist/components/creative.js.map +1 -1
- package/dist/components/dashboard.d.ts +12 -12
- package/dist/components/dashboard.d.ts.map +1 -1
- package/dist/components/dashboard.js +144 -79
- package/dist/components/dashboard.js.map +1 -1
- package/dist/components/discovery.d.ts +10 -10
- package/dist/components/interactive.d.ts +6 -6
- package/dist/components/layout.d.ts +41 -30
- package/dist/components/layout.d.ts.map +1 -1
- package/dist/components/layout.js +8 -1
- package/dist/components/layout.js.map +1 -1
- package/dist/components/navigation.d.ts +4 -4
- package/dist/components/screen-components.d.ts +23 -23
- package/dist/components/wayfinding.d.ts +11 -11
- package/dist/components/workflows.d.ts +5 -5
- package/dist/experimental.d.ts +8 -0
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +17 -0
- package/dist/experimental.js.map +1 -1
- package/dist/motion-region.d.ts.map +1 -1
- package/dist/motion-region.js +1 -0
- package/dist/motion-region.js.map +1 -1
- package/dist/motion-surface.d.ts +12 -6
- package/dist/motion-surface.d.ts.map +1 -1
- package/dist/motion-surface.js +94 -17
- package/dist/motion-surface.js.map +1 -1
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +8 -3
- package/dist/motion.js.map +1 -1
- package/dist/reduced-motion.d.ts +10 -0
- package/dist/reduced-motion.d.ts.map +1 -0
- package/dist/reduced-motion.js +26 -0
- package/dist/reduced-motion.js.map +1 -0
- package/dist/scroll-motion.d.ts.map +1 -1
- package/dist/scroll-motion.js +19 -6
- package/dist/scroll-motion.js.map +1 -1
- package/dist/section-scroll.d.ts +2 -1
- package/dist/section-scroll.d.ts.map +1 -1
- package/dist/section-scroll.js +43 -12
- package/dist/section-scroll.js.map +1 -1
- package/dist/visual-effects.d.ts.map +1 -1
- package/dist/visual-effects.js +14 -1
- package/dist/visual-effects.js.map +1 -1
- package/package.json +3 -3
- package/src/animated-number.ts +7 -9
- package/src/base.css +43 -1
- package/src/component-motion.ts +26 -2
- package/src/components/ChartPlot.ts +29 -10
- package/src/components/DateCalendar.ts +3 -1
- package/src/components/MCard.ts +81 -20
- package/src/components/MInput.ts +13 -4
- package/src/components/MVirtualList.ts +107 -29
- package/src/components/creative.ts +7 -5
- package/src/components/dashboard.ts +140 -80
- package/src/components/layout.ts +8 -1
- package/src/experimental.ts +20 -0
- package/src/motion-region.ts +1 -0
- package/src/motion-surface.ts +104 -22
- package/src/motion.ts +16 -5
- package/src/reduced-motion.ts +30 -0
- package/src/scroll-motion.ts +17 -6
- package/src/section-scroll.ts +38 -12
- package/src/visual-effects.ts +12 -1
package/src/component-motion.ts
CHANGED
|
@@ -23,6 +23,12 @@ export function useComponentPaint(
|
|
|
23
23
|
const { theme } = useMavisTheme()
|
|
24
24
|
useConnectedMotion(element, useMotionContext(), (runtime, target) => {
|
|
25
25
|
let playback = runtime.animate(target, values(), { duration: 0 })
|
|
26
|
+
const display = target.ownerDocument.defaultView!.getComputedStyle(target).display
|
|
27
|
+
// Selection paint can be claimed inside a closed sheet before its box gets dimensions.
|
|
28
|
+
// Keep the geometry lease through opening, responsive resizing and later selections.
|
|
29
|
+
const geometry = ['inline', 'none', 'contents'].includes(display)
|
|
30
|
+
? undefined
|
|
31
|
+
: runtime.observeGeometry(target)
|
|
26
32
|
const off = watch(
|
|
27
33
|
values,
|
|
28
34
|
() => {
|
|
@@ -34,6 +40,7 @@ export function useComponentPaint(
|
|
|
34
40
|
off()
|
|
35
41
|
playback.stop()
|
|
36
42
|
runtime.release(target)
|
|
43
|
+
geometry?.dispose()
|
|
37
44
|
}
|
|
38
45
|
})
|
|
39
46
|
}
|
|
@@ -47,7 +54,9 @@ export function useComponentTransition(offset = 6) {
|
|
|
47
54
|
{
|
|
48
55
|
lease: ReturnType<typeof context.acquire>
|
|
49
56
|
playback?: ReturnType<WebRuntime['animate']>
|
|
57
|
+
geometry?: ReturnType<WebRuntime['observeGeometry']>
|
|
50
58
|
generation: number
|
|
59
|
+
leaving?: () => void
|
|
51
60
|
}
|
|
52
61
|
>()
|
|
53
62
|
function release(element: Element) {
|
|
@@ -57,6 +66,7 @@ export function useComponentTransition(offset = 6) {
|
|
|
57
66
|
entry.generation++
|
|
58
67
|
entry.playback?.stop()
|
|
59
68
|
entry.lease.runtime.release(element as HTMLElement)
|
|
69
|
+
entry.geometry?.dispose()
|
|
60
70
|
entry.lease.release()
|
|
61
71
|
}
|
|
62
72
|
function play(element: Element, done: () => void, entering: boolean) {
|
|
@@ -67,9 +77,14 @@ export function useComponentTransition(offset = 6) {
|
|
|
67
77
|
entries.set(element, entry)
|
|
68
78
|
}
|
|
69
79
|
const token = ++entry.generation
|
|
80
|
+
entry.leaving = entering ? undefined : done
|
|
70
81
|
const target = element as HTMLElement
|
|
71
82
|
if (entering && fresh)
|
|
72
83
|
entry.lease.runtime.animate(target, { opacity: 0, y: offset }, { duration: 0 })
|
|
84
|
+
// The surface stays claimed while visible. Async results, translated text and responsive
|
|
85
|
+
// wrapping can change its box before the next frame or leave hook. Declare that ownership
|
|
86
|
+
// now: Jolt accepts geometry changes, while still guarding external transforms and paint.
|
|
87
|
+
if (entering && fresh) entry.geometry = entry.lease.runtime.observeGeometry(target)
|
|
73
88
|
entry.playback = entry.lease.runtime.animate(
|
|
74
89
|
target,
|
|
75
90
|
entering ? { opacity: 1, y: 0 } : { opacity: 0, y: offset / 2 },
|
|
@@ -77,14 +92,21 @@ export function useComponentTransition(offset = 6) {
|
|
|
77
92
|
? componentMotion(theme.value, 'overlay')
|
|
78
93
|
: { duration: theme.value.motion.exitDuration },
|
|
79
94
|
)
|
|
95
|
+
// Vue can start with a leave (for example when appear is suppressed by its parent).
|
|
96
|
+
if (fresh && !entering) entry.geometry = entry.lease.runtime.observeGeometry(target)
|
|
80
97
|
void entry.playback.finished.then(() => {
|
|
81
98
|
if (entries.get(element) !== entry || entry.generation !== token) return
|
|
99
|
+
entry.leaving = undefined
|
|
82
100
|
done()
|
|
83
101
|
if (!entering) release(element)
|
|
84
102
|
})
|
|
85
103
|
}
|
|
86
104
|
onScopeDispose(() => {
|
|
87
|
-
for (const element of entries
|
|
105
|
+
for (const [element, { leaving }] of [...entries]) {
|
|
106
|
+
release(element)
|
|
107
|
+
// Vue keeps a leaving element until done(); without it the node outlives its owner.
|
|
108
|
+
leaving?.()
|
|
109
|
+
}
|
|
88
110
|
})
|
|
89
111
|
return {
|
|
90
112
|
css: false,
|
|
@@ -98,7 +120,9 @@ export function useComponentTransition(offset = 6) {
|
|
|
98
120
|
},
|
|
99
121
|
onLeaveCancelled: (element: Element) => {
|
|
100
122
|
const entry = entries.get(element)
|
|
101
|
-
if (entry)
|
|
123
|
+
if (!entry) return
|
|
124
|
+
entry.generation++
|
|
125
|
+
entry.leaving = undefined
|
|
102
126
|
},
|
|
103
127
|
}
|
|
104
128
|
}
|
|
@@ -22,7 +22,10 @@ import {
|
|
|
22
22
|
export const ChartPlot = defineComponent({
|
|
23
23
|
name: 'MChartPlot',
|
|
24
24
|
props: chartPlotProps,
|
|
25
|
-
emits: {
|
|
25
|
+
emits: {
|
|
26
|
+
select: (_category: number, _series: number) => true,
|
|
27
|
+
preview: (_hit: { category: number; series: number } | null) => true,
|
|
28
|
+
},
|
|
26
29
|
setup(props, { emit }) {
|
|
27
30
|
const { theme } = useMavisTheme()
|
|
28
31
|
const plot = ref<SVGSVGElement>()
|
|
@@ -32,10 +35,10 @@ export const ChartPlot = defineComponent({
|
|
|
32
35
|
let progress:
|
|
33
36
|
ReturnType<ReturnType<typeof context.acquire>['runtime']['motionValue']> | undefined
|
|
34
37
|
let off: (() => void) | undefined
|
|
35
|
-
let
|
|
38
|
+
let unfollow: (() => void) | undefined
|
|
36
39
|
let generation = 0
|
|
37
40
|
const settle = () => {
|
|
38
|
-
if (
|
|
41
|
+
if (lease && progress) {
|
|
39
42
|
generation++
|
|
40
43
|
lease.runtime.stop(progress)
|
|
41
44
|
lease.runtime.set(progress, 1)
|
|
@@ -96,7 +99,7 @@ export const ChartPlot = defineComponent({
|
|
|
96
99
|
}
|
|
97
100
|
startGeometry = presentation
|
|
98
101
|
const token = ++generation
|
|
99
|
-
if (
|
|
102
|
+
if (lease.runtime.reducedMotion()) {
|
|
100
103
|
settle()
|
|
101
104
|
return
|
|
102
105
|
}
|
|
@@ -111,10 +114,9 @@ export const ChartPlot = defineComponent({
|
|
|
111
114
|
function connect() {
|
|
112
115
|
if (lease || !plot.value) return
|
|
113
116
|
lease = context.acquire(plot.value.ownerDocument)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
)
|
|
117
|
-
preference.addEventListener('change', settle)
|
|
117
|
+
unfollow = lease.runtime.onReducedMotion((reduced) => {
|
|
118
|
+
if (reduced) settle()
|
|
119
|
+
})
|
|
118
120
|
progress = lease.runtime.motionValue(0)
|
|
119
121
|
off = progress.subscribe((value) =>
|
|
120
122
|
paint(interpolateChart(startGeometry, destination, value)),
|
|
@@ -122,9 +124,10 @@ export const ChartPlot = defineComponent({
|
|
|
122
124
|
update()
|
|
123
125
|
}
|
|
124
126
|
function disconnect() {
|
|
127
|
+
emit('preview', null)
|
|
125
128
|
generation++
|
|
126
|
-
|
|
127
|
-
|
|
129
|
+
unfollow?.()
|
|
130
|
+
unfollow = undefined
|
|
128
131
|
off?.()
|
|
129
132
|
off = undefined
|
|
130
133
|
progress?.dispose()
|
|
@@ -177,6 +180,22 @@ export const ChartPlot = defineComponent({
|
|
|
177
180
|
preserveAspectRatio: 'none',
|
|
178
181
|
'aria-hidden': 'true',
|
|
179
182
|
focusable: 'false',
|
|
183
|
+
onPointermove: (event: PointerEvent) => {
|
|
184
|
+
if (props.disabled || event.pointerType === 'touch') {
|
|
185
|
+
emit('preview', null)
|
|
186
|
+
return
|
|
187
|
+
}
|
|
188
|
+
const rect = (event.currentTarget as SVGElement).getBoundingClientRect()
|
|
189
|
+
if (rect.width <= 0 || rect.height <= 0) {
|
|
190
|
+
emit('preview', null)
|
|
191
|
+
return
|
|
192
|
+
}
|
|
193
|
+
const x = (event.clientX - rect.left) / rect.width
|
|
194
|
+
const y = (((event.clientY - rect.top) / rect.height) * height - 8) / (height - 16)
|
|
195
|
+
emit('preview', chartHitTest(props.geometry, props.type, x, y))
|
|
196
|
+
},
|
|
197
|
+
onPointerleave: () => emit('preview', null),
|
|
198
|
+
onPointercancel: () => emit('preview', null),
|
|
180
199
|
style: { display: 'block', width: '100%', height: `${height}px`, overflow: 'visible' },
|
|
181
200
|
},
|
|
182
201
|
[
|
|
@@ -39,7 +39,9 @@ const CalendarDay = defineComponent({
|
|
|
39
39
|
borderRadius: 'inherit',
|
|
40
40
|
backgroundColor: theme.value.colors.primarySoft,
|
|
41
41
|
pointerEvents: 'none',
|
|
42
|
-
|
|
42
|
+
// After attachment Jolt owns this channel. Keep its current paint through Vue
|
|
43
|
+
// updates; the post-render motion watcher changes the selected state.
|
|
44
|
+
opacity: background.value?.style.opacity || (props.painted ? '1' : '0'),
|
|
43
45
|
},
|
|
44
46
|
}),
|
|
45
47
|
h('span', { style: { position: 'relative' } }, slots.default?.()),
|
package/src/components/MCard.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { resolveSpace, resolveRadius, shadowStyle } from '@getcortexlabs/mavis-core'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
defineComponent,
|
|
4
|
+
getCurrentInstance,
|
|
5
|
+
h,
|
|
6
|
+
mergeProps,
|
|
7
|
+
shallowRef,
|
|
8
|
+
useId,
|
|
9
|
+
type VNode,
|
|
10
|
+
} from 'vue'
|
|
3
11
|
import { preserveBoundPaint } from '../motion-surface.js'
|
|
4
12
|
import {
|
|
5
13
|
useButtonAction,
|
|
@@ -14,6 +22,26 @@ import { usePressFeedback } from '../motion.js'
|
|
|
14
22
|
|
|
15
23
|
const LinkColumn = createLayout('MCardLink', 'column', 'a')
|
|
16
24
|
|
|
25
|
+
/** A control owns clicks from its descendants; the surrounding card owns the remaining surface. */
|
|
26
|
+
function ownsClick(event?: MouseEvent) {
|
|
27
|
+
if (!event) return true
|
|
28
|
+
if (event.defaultPrevented) return false
|
|
29
|
+
const element = event.currentTarget as HTMLElement | null
|
|
30
|
+
const Element = element?.ownerDocument.defaultView?.Element
|
|
31
|
+
if (!element || !Element) return event.target === event.currentTarget
|
|
32
|
+
for (const node of event.composedPath()) {
|
|
33
|
+
if (node === element) return true
|
|
34
|
+
if (
|
|
35
|
+
node instanceof Element &&
|
|
36
|
+
node.matches(
|
|
37
|
+
'button, a[href], input, select, textarea, label, [contenteditable]:not([contenteditable="false"]), [tabindex], [role="button"], [role="checkbox"], [role="radio"], [role="switch"], [role="slider"], [role="tab"], [role="combobox"]',
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
return false
|
|
43
|
+
}
|
|
44
|
+
|
|
17
45
|
export const MCard = defineComponent({
|
|
18
46
|
name: 'MCard',
|
|
19
47
|
inheritAttrs: false,
|
|
@@ -23,6 +51,8 @@ export const MCard = defineComponent({
|
|
|
23
51
|
useButtonAction(() => props.interactive || props.href !== undefined)
|
|
24
52
|
const { theme } = useMavisTheme()
|
|
25
53
|
const navigation = useNavigationOptions(props)
|
|
54
|
+
const instance = getCurrentInstance()
|
|
55
|
+
const contentId = `m-card-content-${useId()}`
|
|
26
56
|
const element = shallowRef<HTMLElement>()
|
|
27
57
|
const lifecycle = usePressFeedback(
|
|
28
58
|
() => (props.interactive || props.href !== undefined) && !props.disabled,
|
|
@@ -45,7 +75,12 @@ export const MCard = defineComponent({
|
|
|
45
75
|
rel,
|
|
46
76
|
...layout
|
|
47
77
|
} = props
|
|
78
|
+
const separateAction = interactive && href === undefined
|
|
79
|
+
const { 'aria-label': explicitLabel, ...cardAttrs } = attrs
|
|
80
|
+
const label = props.accessibilityLabel ?? (explicitLabel as string | undefined)
|
|
81
|
+
if (separateAction) layout.accessibilityLabel = undefined
|
|
48
82
|
const tokens = theme.value.components.card
|
|
83
|
+
const shadow = `var(--m-card-shadow, ${shadowStyle(theme.value.elevation[elevation ?? tokens.elevation])})`
|
|
49
84
|
layout.padding ??= tokens.padding
|
|
50
85
|
layout.radius ??= tokens.radius
|
|
51
86
|
return h(
|
|
@@ -55,7 +90,10 @@ export const MCard = defineComponent({
|
|
|
55
90
|
layout,
|
|
56
91
|
{
|
|
57
92
|
class: 'm-card',
|
|
93
|
+
'data-m-card-interactive': separateAction || undefined,
|
|
58
94
|
style: {
|
|
95
|
+
position: 'relative',
|
|
96
|
+
isolation: 'isolate',
|
|
59
97
|
paddingLeft:
|
|
60
98
|
props.paddingX !== undefined || props.padding !== undefined
|
|
61
99
|
? `${resolveSpace(theme.value, props.paddingX ?? props.padding!)}px`
|
|
@@ -76,7 +114,7 @@ export const MCard = defineComponent({
|
|
|
76
114
|
props.radius !== undefined
|
|
77
115
|
? `${resolveRadius(theme.value, props.radius)}px`
|
|
78
116
|
: `var(--m-card-radius, ${resolveRadius(theme.value, tokens.radius)}px)`,
|
|
79
|
-
boxShadow:
|
|
117
|
+
boxShadow: shadow,
|
|
80
118
|
backgroundColor:
|
|
81
119
|
props.backgroundColor ?? `var(--m-card-background, ${theme.value.colors.surface})`,
|
|
82
120
|
border: `var(--m-card-border, 1px solid ${theme.value.colors.border})`,
|
|
@@ -86,36 +124,59 @@ export const MCard = defineComponent({
|
|
|
86
124
|
color: 'inherit',
|
|
87
125
|
},
|
|
88
126
|
},
|
|
89
|
-
attrs,
|
|
127
|
+
separateAction ? cardAttrs : attrs,
|
|
90
128
|
{
|
|
91
129
|
onVnodeMounted: (node: VNode) => {
|
|
92
130
|
element.value = node.el as HTMLElement
|
|
93
131
|
},
|
|
94
|
-
style: preserveBoundPaint(element.value),
|
|
132
|
+
style: preserveBoundPaint(element.value, shadow),
|
|
95
133
|
},
|
|
96
134
|
href !== undefined
|
|
97
135
|
? navigationAttrs(navigation(), disabled, activate, (error) => emit('error', error))
|
|
98
136
|
: interactive
|
|
99
137
|
? {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
'aria-disabled': disabled || undefined,
|
|
103
|
-
onClick: activate,
|
|
104
|
-
onKeydown: (event: KeyboardEvent) => {
|
|
105
|
-
if (event.target !== event.currentTarget) return
|
|
106
|
-
if (event.key === 'Enter' || event.key === ' ') event.preventDefault()
|
|
107
|
-
if (event.key === 'Enter' && !event.repeat) activate()
|
|
108
|
-
},
|
|
109
|
-
onKeyup: (event: KeyboardEvent) => {
|
|
110
|
-
if (event.target === event.currentTarget && event.key === ' ') {
|
|
111
|
-
event.preventDefault()
|
|
112
|
-
activate()
|
|
113
|
-
}
|
|
138
|
+
onClick: (event: MouseEvent) => {
|
|
139
|
+
if (ownsClick(event)) activate()
|
|
114
140
|
},
|
|
115
141
|
}
|
|
116
|
-
:
|
|
142
|
+
: // A labelled card with no action wired is read as one element, as on native.
|
|
143
|
+
props.accessibilityLabel &&
|
|
144
|
+
attrs.role === undefined &&
|
|
145
|
+
!instance?.vnode.props?.onClick
|
|
146
|
+
? { role: 'img' }
|
|
147
|
+
: {},
|
|
117
148
|
),
|
|
118
|
-
|
|
149
|
+
href !== undefined
|
|
150
|
+
? slots
|
|
151
|
+
: {
|
|
152
|
+
...slots,
|
|
153
|
+
default: () => [
|
|
154
|
+
separateAction
|
|
155
|
+
? h('button', {
|
|
156
|
+
key: 'action',
|
|
157
|
+
class: 'm-card-action',
|
|
158
|
+
type: 'button',
|
|
159
|
+
role: 'button',
|
|
160
|
+
tabindex: disabled ? -1 : 0,
|
|
161
|
+
disabled,
|
|
162
|
+
'aria-disabled': disabled || undefined,
|
|
163
|
+
'aria-label': label,
|
|
164
|
+
'aria-labelledby': label ? undefined : contentId,
|
|
165
|
+
onClick: activate,
|
|
166
|
+
})
|
|
167
|
+
: null,
|
|
168
|
+
h(
|
|
169
|
+
'div',
|
|
170
|
+
{
|
|
171
|
+
key: 'content',
|
|
172
|
+
id: contentId,
|
|
173
|
+
class: 'm-card-content',
|
|
174
|
+
style: { display: 'contents' },
|
|
175
|
+
},
|
|
176
|
+
slots.default?.(),
|
|
177
|
+
),
|
|
178
|
+
],
|
|
179
|
+
},
|
|
119
180
|
)
|
|
120
181
|
}
|
|
121
182
|
},
|
package/src/components/MInput.ts
CHANGED
|
@@ -93,6 +93,7 @@ const Input = defineComponent({
|
|
|
93
93
|
let observer: ResizeObserver | undefined
|
|
94
94
|
let observed: HTMLElement | undefined
|
|
95
95
|
let width = 0
|
|
96
|
+
let frame: number | undefined
|
|
96
97
|
let measured = ''
|
|
97
98
|
|
|
98
99
|
function resize() {
|
|
@@ -129,16 +130,24 @@ const Input = defineComponent({
|
|
|
129
130
|
if (typeof document !== 'undefined') focused.value = editor.value === document.activeElement
|
|
130
131
|
if (typeof ResizeObserver !== 'undefined') {
|
|
131
132
|
observer = new ResizeObserver(([entry]) => {
|
|
132
|
-
if (entry
|
|
133
|
-
|
|
133
|
+
if (!entry || entry.contentRect.width === width) return
|
|
134
|
+
width = entry.contentRect.width
|
|
135
|
+
// The new height also resizes observed ancestors, such as a grid. Inside this
|
|
136
|
+
// delivery browsers report that as a ResizeObserver loop error.
|
|
137
|
+
if (frame !== undefined) cancelAnimationFrame(frame)
|
|
138
|
+
frame = requestAnimationFrame(() => {
|
|
139
|
+
frame = undefined
|
|
134
140
|
resize()
|
|
135
|
-
}
|
|
141
|
+
})
|
|
136
142
|
})
|
|
137
143
|
}
|
|
138
144
|
observe()
|
|
139
145
|
})
|
|
140
146
|
onUpdated(observe)
|
|
141
|
-
onBeforeUnmount(() =>
|
|
147
|
+
onBeforeUnmount(() => {
|
|
148
|
+
observer?.disconnect()
|
|
149
|
+
if (frame !== undefined) cancelAnimationFrame(frame)
|
|
150
|
+
})
|
|
142
151
|
watch(
|
|
143
152
|
() => props.disabled,
|
|
144
153
|
(disabled) => {
|
|
@@ -1,10 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
2
|
+
import { useMotionContext } from '../motion-context.js'
|
|
3
|
+
import { useConnectedMotion } from '../connected-motion.js'
|
|
4
|
+
import type { ListChanges } from '@rafaelaugusto/jolt/web'
|
|
3
5
|
import type { VirtualListComponent } from '@getcortexlabs/mavis-core/vue'
|
|
4
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
computed,
|
|
8
|
+
defineComponent,
|
|
9
|
+
getCurrentInstance,
|
|
10
|
+
h,
|
|
11
|
+
mergeProps,
|
|
12
|
+
nextTick,
|
|
13
|
+
onMounted,
|
|
14
|
+
ref,
|
|
15
|
+
shallowRef,
|
|
16
|
+
watch,
|
|
17
|
+
} from 'vue'
|
|
5
18
|
import { virtualListProps } from '@getcortexlabs/mavis-core/vue'
|
|
6
19
|
import {
|
|
7
20
|
choiceKey,
|
|
21
|
+
componentMotion,
|
|
22
|
+
virtualAnchor,
|
|
8
23
|
virtualKeys,
|
|
9
24
|
virtualWindow,
|
|
10
25
|
type VirtualListHandle,
|
|
@@ -16,16 +31,19 @@ const VirtualList = defineComponent({
|
|
|
16
31
|
inheritAttrs: false,
|
|
17
32
|
props: virtualListProps,
|
|
18
33
|
setup(props, { attrs, slots, expose }) {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
34
|
+
const instance = getCurrentInstance()!
|
|
35
|
+
const { theme } = useMavisTheme()
|
|
36
|
+
const rendered = shallowRef<readonly unknown[]>([...props.items])
|
|
37
|
+
const keys = computed(() => virtualKeys(rendered.value, props.itemKey))
|
|
23
38
|
const root = ref<HTMLElement>()
|
|
39
|
+
let controller: ListChanges<unknown> | undefined
|
|
40
|
+
let notifyRecycling: ((target: HTMLElement) => void) | undefined
|
|
41
|
+
const rowElements = new Map<string, HTMLElement>()
|
|
24
42
|
const offset = ref(props.initialIndex * props.rowHeight)
|
|
25
43
|
const focusedKey = ref<string>()
|
|
26
44
|
const window = computed(() =>
|
|
27
45
|
virtualWindow(
|
|
28
|
-
|
|
46
|
+
rendered.value.length,
|
|
29
47
|
props.rowHeight,
|
|
30
48
|
props.height,
|
|
31
49
|
offset.value,
|
|
@@ -36,32 +54,82 @@ const VirtualList = defineComponent({
|
|
|
36
54
|
offset.value = window.value.scrollTop
|
|
37
55
|
if (root.value) root.value.scrollTop = offset.value
|
|
38
56
|
}
|
|
57
|
+
function commit(items: readonly unknown[]) {
|
|
58
|
+
const next = virtualKeys(items, props.itemKey)
|
|
59
|
+
const anchored = virtualAnchor(keys.value, next, props.rowHeight, props.height, offset.value)
|
|
60
|
+
// Reconcile the window and its anchor together. A shorter spacer can make
|
|
61
|
+
// the browser clamp scrollTop and dispatch scroll before Jolt's deferred
|
|
62
|
+
// layout pass; that event would cancel the pending anchor restoration.
|
|
63
|
+
rendered.value = [...items]
|
|
64
|
+
offset.value = anchored
|
|
65
|
+
instance.update()
|
|
66
|
+
syncOffset()
|
|
67
|
+
}
|
|
68
|
+
useConnectedMotion(root, useMotionContext(), (runtime, target) => {
|
|
69
|
+
const owned = runtime.listChanges(target, {
|
|
70
|
+
key: (item) => choiceKey(virtualKeys([item], props.itemKey)[0]!),
|
|
71
|
+
move: componentMotion(theme.value, 'layout'),
|
|
72
|
+
enter: true,
|
|
73
|
+
exit: 'fadeOut',
|
|
74
|
+
adapter: {
|
|
75
|
+
virtualized: true,
|
|
76
|
+
items: () => rendered.value,
|
|
77
|
+
render: commit,
|
|
78
|
+
rows: () => [...rowElements].map(([key, target]) => ({ key, target })),
|
|
79
|
+
anchor: (previous) => {
|
|
80
|
+
const before = offset.value
|
|
81
|
+
return (next) => {
|
|
82
|
+
offset.value = virtualAnchor(previous, next, props.rowHeight, props.height, before)
|
|
83
|
+
instance.update()
|
|
84
|
+
syncOffset()
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
observeRecycling: (notify) => {
|
|
88
|
+
notifyRecycling = notify
|
|
89
|
+
return () => {
|
|
90
|
+
notifyRecycling = undefined
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
})
|
|
95
|
+
controller = owned
|
|
96
|
+
if (!props.animated) owned.pause()
|
|
97
|
+
return () => {
|
|
98
|
+
owned.dispose()
|
|
99
|
+
if (controller === owned) controller = undefined
|
|
100
|
+
}
|
|
101
|
+
})
|
|
39
102
|
watch(
|
|
40
|
-
|
|
41
|
-
(
|
|
42
|
-
const
|
|
43
|
-
const anchor = previous[index]
|
|
44
|
-
const newIndex = anchor === undefined ? -1 : next.indexOf(anchor)
|
|
45
|
-
if (newIndex >= 0)
|
|
46
|
-
offset.value = newIndex * props.rowHeight + (offset.value % props.rowHeight)
|
|
103
|
+
() => props.items.map((item) => ({ item, key: virtualKeys([item], props.itemKey)[0]! })),
|
|
104
|
+
() => {
|
|
105
|
+
const next = virtualKeys(props.items, props.itemKey)
|
|
47
106
|
if (focusedKey.value && !next.some((key) => choiceKey(key) === focusedKey.value)) {
|
|
48
107
|
if (root.value?.contains(document.activeElement))
|
|
49
108
|
root.value.focus({ preventScroll: true })
|
|
50
109
|
focusedKey.value = undefined
|
|
51
110
|
}
|
|
52
|
-
|
|
111
|
+
if (controller && !controller.disposed) controller.update([...props.items])
|
|
112
|
+
else commit(props.items)
|
|
53
113
|
},
|
|
54
114
|
{ flush: 'pre' },
|
|
55
115
|
)
|
|
116
|
+
watch(
|
|
117
|
+
() => props.animated,
|
|
118
|
+
(enabled) => (enabled ? controller?.play() : controller?.pause()),
|
|
119
|
+
)
|
|
56
120
|
watch(
|
|
57
121
|
() => [props.rowHeight, props.height],
|
|
58
|
-
() =>
|
|
122
|
+
() => {
|
|
123
|
+
controller?.stop()
|
|
124
|
+
void nextTick(syncOffset)
|
|
125
|
+
},
|
|
59
126
|
)
|
|
60
127
|
onMounted(syncOffset)
|
|
61
128
|
expose({
|
|
62
129
|
scrollToIndex(index: number) {
|
|
63
130
|
if (!Number.isInteger(index) || index < 0 || index >= props.items.length)
|
|
64
131
|
throw new RangeError('List index is out of range.')
|
|
132
|
+
controller?.stop()
|
|
65
133
|
offset.value = index * props.rowHeight
|
|
66
134
|
syncOffset()
|
|
67
135
|
},
|
|
@@ -95,7 +163,9 @@ const VirtualList = defineComponent({
|
|
|
95
163
|
flexShrink: 0,
|
|
96
164
|
},
|
|
97
165
|
onScroll: () => {
|
|
98
|
-
|
|
166
|
+
const next = root.value?.scrollTop ?? 0
|
|
167
|
+
if (next !== offset.value) controller?.stop()
|
|
168
|
+
offset.value = next
|
|
99
169
|
},
|
|
100
170
|
onFocusin: (event: FocusEvent) => {
|
|
101
171
|
focusedKey.value = (event.target as HTMLElement).closest<HTMLElement>(
|
|
@@ -107,26 +177,34 @@ const VirtualList = defineComponent({
|
|
|
107
177
|
if (!root.value?.contains(document.activeElement)) focusedKey.value = undefined
|
|
108
178
|
}),
|
|
109
179
|
}),
|
|
110
|
-
|
|
180
|
+
rendered.value.length
|
|
111
181
|
? [
|
|
112
182
|
h(
|
|
113
183
|
'div',
|
|
114
184
|
{
|
|
115
|
-
...motion,
|
|
116
185
|
role: 'list',
|
|
117
186
|
style: { height: `${state.totalHeight}px`, position: 'relative' },
|
|
118
187
|
},
|
|
119
188
|
[...indices]
|
|
120
189
|
.sort((a, b) => a - b)
|
|
121
|
-
.map((index) =>
|
|
122
|
-
|
|
190
|
+
.map((index) => {
|
|
191
|
+
const itemKey = keys.value[index]!
|
|
192
|
+
const key = choiceKey(itemKey)
|
|
193
|
+
return h(
|
|
123
194
|
'div',
|
|
124
195
|
{
|
|
125
|
-
key
|
|
196
|
+
key,
|
|
197
|
+
ref: (element: unknown) => {
|
|
198
|
+
if (element instanceof HTMLElement) rowElements.set(key, element)
|
|
199
|
+
else rowElements.delete(key)
|
|
200
|
+
},
|
|
201
|
+
onVnodeBeforeUnmount: (node: { el?: unknown }) => {
|
|
202
|
+
if (node.el instanceof HTMLElement) notifyRecycling?.(node.el)
|
|
203
|
+
},
|
|
126
204
|
role: 'listitem',
|
|
127
|
-
'data-m-list-key':
|
|
205
|
+
'data-m-list-key': key,
|
|
128
206
|
'aria-posinset': index + 1,
|
|
129
|
-
'aria-setsize':
|
|
207
|
+
'aria-setsize': rendered.value.length,
|
|
130
208
|
style: {
|
|
131
209
|
position: 'absolute',
|
|
132
210
|
top: `${index * props.rowHeight}px`,
|
|
@@ -138,12 +216,12 @@ const VirtualList = defineComponent({
|
|
|
138
216
|
},
|
|
139
217
|
},
|
|
140
218
|
slots.default?.({
|
|
141
|
-
item:
|
|
219
|
+
item: rendered.value[index],
|
|
142
220
|
index,
|
|
143
|
-
itemKey
|
|
221
|
+
itemKey,
|
|
144
222
|
}),
|
|
145
|
-
)
|
|
146
|
-
),
|
|
223
|
+
)
|
|
224
|
+
}),
|
|
147
225
|
),
|
|
148
226
|
]
|
|
149
227
|
: (slots.empty?.() ?? [h(MText, { text: props.emptyLabel, tone: 'muted' })]),
|
|
@@ -23,6 +23,8 @@ import {
|
|
|
23
23
|
} from '@getcortexlabs/mavis-core/vue'
|
|
24
24
|
import type { gaugeGeometry } from '@getcortexlabs/mavis-core'
|
|
25
25
|
import { MBox, MColumn, MRow } from './layout.js'
|
|
26
|
+
import { useMotionContext } from '../motion-context.js'
|
|
27
|
+
import { followReducedMotion } from '../reduced-motion.js'
|
|
26
28
|
import { MStack } from './MStack.js'
|
|
27
29
|
import { MCard } from './MCard.js'
|
|
28
30
|
import { MText } from './MText.js'
|
|
@@ -145,7 +147,8 @@ const MarqueeHost = defineComponent({
|
|
|
145
147
|
emits: ['environment'],
|
|
146
148
|
setup(_props, { attrs, slots, emit }) {
|
|
147
149
|
const root = ref<HTMLElement>()
|
|
148
|
-
|
|
150
|
+
const context = useMotionContext()
|
|
151
|
+
let follow: ReturnType<typeof followReducedMotion> | undefined,
|
|
149
152
|
resize: ResizeObserver | undefined,
|
|
150
153
|
intersection: IntersectionObserver | undefined
|
|
151
154
|
let hovered = false,
|
|
@@ -154,15 +157,14 @@ const MarqueeHost = defineComponent({
|
|
|
154
157
|
attached = false
|
|
155
158
|
const update = () =>
|
|
156
159
|
emit('environment', {
|
|
157
|
-
reduced:
|
|
160
|
+
reduced: follow?.reduced ?? true,
|
|
158
161
|
paused: !attached || document.hidden || hovered || focused || !visible,
|
|
159
162
|
width: root.value?.clientWidth ?? 0,
|
|
160
163
|
})
|
|
161
164
|
function attach() {
|
|
162
165
|
if (attached || !root.value) return
|
|
163
166
|
attached = true
|
|
164
|
-
|
|
165
|
-
media.addEventListener('change', update)
|
|
167
|
+
follow = followReducedMotion(context, root.value.ownerDocument, update)
|
|
166
168
|
resize = new ResizeObserver(update)
|
|
167
169
|
resize.observe(root.value)
|
|
168
170
|
intersection = new IntersectionObserver(([entry]) => {
|
|
@@ -175,7 +177,7 @@ const MarqueeHost = defineComponent({
|
|
|
175
177
|
}
|
|
176
178
|
function detach() {
|
|
177
179
|
attached = false
|
|
178
|
-
|
|
180
|
+
follow?.release()
|
|
179
181
|
resize?.disconnect()
|
|
180
182
|
intersection?.disconnect()
|
|
181
183
|
document.removeEventListener('visibilitychange', update)
|