@getcortexlabs/mavis-web 0.1.0-alpha.9 → 0.1.0-rc.11.1
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 +5 -5
- package/dist/animated-number.d.ts +3 -0
- package/dist/animated-number.d.ts.map +1 -0
- package/dist/animated-number.js +61 -0
- package/dist/animated-number.js.map +1 -0
- package/dist/component-motion.d.ts +18 -0
- package/dist/component-motion.d.ts.map +1 -0
- package/dist/component-motion.js +156 -0
- package/dist/component-motion.js.map +1 -0
- package/dist/component-width.d.ts +6 -0
- package/dist/component-width.d.ts.map +1 -0
- package/dist/component-width.js +30 -0
- package/dist/component-width.js.map +1 -0
- package/dist/components/ChartPlot.d.ts +66 -0
- package/dist/components/ChartPlot.d.ts.map +1 -0
- package/dist/components/ChartPlot.js +254 -0
- package/dist/components/ChartPlot.js.map +1 -0
- package/dist/components/DateCalendar.d.ts +15 -0
- package/dist/components/DateCalendar.d.ts.map +1 -1
- package/dist/components/DateCalendar.js +58 -12
- package/dist/components/DateCalendar.js.map +1 -1
- package/dist/components/LoadingDecoration.d.ts +4 -4
- package/dist/components/MAccordion.d.ts +1 -1
- package/dist/components/MAlert.d.ts +4 -4
- package/dist/components/MAlert.d.ts.map +1 -1
- package/dist/components/MAlert.js +3 -0
- package/dist/components/MAlert.js.map +1 -1
- package/dist/components/MAvatar.d.ts +1 -1
- package/dist/components/MAvatar.d.ts.map +1 -1
- package/dist/components/MAvatar.js +4 -0
- package/dist/components/MAvatar.js.map +1 -1
- package/dist/components/MBadge.d.ts +1 -1
- package/dist/components/MBadge.d.ts.map +1 -1
- package/dist/components/MBadge.js +5 -1
- package/dist/components/MBadge.js.map +1 -1
- package/dist/components/MButton.d.ts +5 -5
- package/dist/components/MCard.d.ts +7 -7
- package/dist/components/MCheckbox.d.ts +1 -1
- package/dist/components/MChip.d.ts +2 -2
- package/dist/components/MChip.d.ts.map +1 -1
- package/dist/components/MChip.js +4 -2
- package/dist/components/MChip.js.map +1 -1
- package/dist/components/MCombobox.d.ts +5 -5
- package/dist/components/MCombobox.d.ts.map +1 -1
- package/dist/components/MCombobox.js +121 -92
- package/dist/components/MCombobox.js.map +1 -1
- package/dist/components/MDatePicker.d.ts +16 -16
- package/dist/components/MDialog.d.ts +4 -4
- package/dist/components/MDialog.d.ts.map +1 -1
- package/dist/components/MDialog.js +9 -4
- package/dist/components/MDialog.js.map +1 -1
- package/dist/components/MEmptyState.d.ts +2 -2
- package/dist/components/MEmptyState.d.ts.map +1 -1
- package/dist/components/MEmptyState.js +3 -0
- package/dist/components/MEmptyState.js.map +1 -1
- package/dist/components/MFilePicker.d.ts +4 -4
- package/dist/components/MFilePicker.d.ts.map +1 -1
- package/dist/components/MFilePicker.js +3 -1
- package/dist/components/MFilePicker.js.map +1 -1
- package/dist/components/MGrid.d.ts +16 -5
- package/dist/components/MGrid.d.ts.map +1 -1
- package/dist/components/MGrid.js +12 -2
- package/dist/components/MGrid.js.map +1 -1
- package/dist/components/MIcon.d.ts +2 -2
- package/dist/components/MImage.d.ts +5 -5
- package/dist/components/MImage.d.ts.map +1 -1
- package/dist/components/MImage.js +8 -1
- package/dist/components/MImage.js.map +1 -1
- package/dist/components/MImageCompare.d.ts +92 -0
- package/dist/components/MImageCompare.d.ts.map +1 -0
- package/dist/components/MImageCompare.js +177 -0
- package/dist/components/MImageCompare.js.map +1 -0
- package/dist/components/MImageViewer.d.ts +121 -0
- package/dist/components/MImageViewer.d.ts.map +1 -0
- package/dist/components/MImageViewer.js +490 -0
- package/dist/components/MImageViewer.js.map +1 -0
- package/dist/components/MInput.d.ts +7 -7
- package/dist/components/MInput.d.ts.map +1 -1
- package/dist/components/MInput.js +5 -0
- package/dist/components/MInput.js.map +1 -1
- package/dist/components/MListItem.d.ts +2 -2
- package/dist/components/MPopover.d.ts +105 -0
- package/dist/components/MPopover.d.ts.map +1 -0
- package/dist/components/MPopover.js +256 -0
- package/dist/components/MPopover.js.map +1 -0
- package/dist/components/MProgress.d.ts +3 -3
- package/dist/components/MProgress.d.ts.map +1 -1
- package/dist/components/MProgress.js +34 -11
- package/dist/components/MProgress.js.map +1 -1
- package/dist/components/MRadioGroup.d.ts +1 -1
- package/dist/components/MRangeSlider.d.ts +104 -0
- package/dist/components/MRangeSlider.d.ts.map +1 -0
- package/dist/components/MRangeSlider.js +125 -0
- package/dist/components/MRangeSlider.js.map +1 -0
- package/dist/components/MResizablePanels.d.ts +137 -0
- package/dist/components/MResizablePanels.d.ts.map +1 -0
- package/dist/components/MResizablePanels.js +174 -0
- package/dist/components/MResizablePanels.js.map +1 -0
- package/dist/components/MReveal.d.ts +14 -14
- package/dist/components/MSegmentedControl.d.ts +1 -1
- package/dist/components/MSegmentedControl.d.ts.map +1 -1
- package/dist/components/MSegmentedControl.js +6 -2
- package/dist/components/MSegmentedControl.js.map +1 -1
- package/dist/components/MSelect.d.ts +3 -3
- package/dist/components/MSeparator.d.ts +1 -1
- package/dist/components/MSheet.d.ts +6 -6
- package/dist/components/MSkeleton.d.ts +2 -2
- package/dist/components/MStack.d.ts +25 -14
- package/dist/components/MStack.d.ts.map +1 -1
- package/dist/components/MStack.js +5 -1
- package/dist/components/MStack.js.map +1 -1
- package/dist/components/MSwitch.d.ts +1 -1
- package/dist/components/MTabs.d.ts +1 -1
- package/dist/components/MTabs.d.ts.map +1 -1
- package/dist/components/MTabs.js +6 -3
- package/dist/components/MTabs.js.map +1 -1
- package/dist/components/MText.d.ts +3 -3
- package/dist/components/MTimePicker.d.ts +655 -0
- package/dist/components/MTimePicker.d.ts.map +1 -0
- package/dist/components/MTimePicker.js +81 -0
- package/dist/components/MTimePicker.js.map +1 -0
- package/dist/components/MToast.d.ts.map +1 -1
- package/dist/components/MToast.js +5 -1
- package/dist/components/MToast.js.map +1 -1
- package/dist/components/MTooltip.d.ts +65 -0
- package/dist/components/MTooltip.d.ts.map +1 -0
- package/dist/components/MTooltip.js +256 -0
- package/dist/components/MTooltip.js.map +1 -0
- package/dist/components/MVirtualList.d.ts +3 -0
- package/dist/components/MVirtualList.d.ts.map +1 -0
- package/dist/components/MVirtualList.js +118 -0
- package/dist/components/MVirtualList.js.map +1 -0
- package/dist/components/MotionRows.d.ts +26 -0
- package/dist/components/MotionRows.d.ts.map +1 -0
- package/dist/components/MotionRows.js +16 -0
- package/dist/components/MotionRows.js.map +1 -0
- package/dist/components/RangeHalo.d.ts +19 -0
- package/dist/components/RangeHalo.d.ts.map +1 -0
- package/dist/components/RangeHalo.js +29 -0
- package/dist/components/RangeHalo.js.map +1 -0
- package/dist/components/configurator.d.ts +2 -2
- package/dist/components/discovery.d.ts +282 -0
- package/dist/components/discovery.d.ts.map +1 -0
- package/dist/components/discovery.js +104 -0
- package/dist/components/discovery.js.map +1 -0
- package/dist/components/interactive.d.ts +163 -0
- package/dist/components/interactive.d.ts.map +1 -0
- package/dist/components/interactive.js +40 -0
- package/dist/components/interactive.js.map +1 -0
- package/dist/components/layout.d.ts +81 -48
- package/dist/components/layout.d.ts.map +1 -1
- package/dist/components/layout.js +2 -1
- package/dist/components/layout.js.map +1 -1
- package/dist/components/navigation.d.ts +225 -0
- package/dist/components/navigation.d.ts.map +1 -0
- package/dist/components/navigation.js +41 -0
- package/dist/components/navigation.js.map +1 -0
- package/dist/components/wayfinding.d.ts +441 -0
- package/dist/components/wayfinding.d.ts.map +1 -0
- package/dist/components/wayfinding.js +58 -0
- package/dist/components/wayfinding.js.map +1 -0
- package/dist/components/workflows.d.ts +2 -2
- package/dist/index.d.ts +15 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -3
- package/dist/index.js.map +1 -1
- package/dist/motion-region.d.ts.map +1 -1
- package/dist/motion-region.js +4 -2
- package/dist/motion-region.js.map +1 -1
- package/dist/motion-surface.d.ts.map +1 -1
- package/dist/motion-surface.js +2 -0
- package/dist/motion-surface.js.map +1 -1
- package/dist/motion.js +1 -1
- package/dist/motion.js.map +1 -1
- package/dist/nuxt-navigation.d.ts +18 -0
- package/dist/nuxt-navigation.d.ts.map +1 -0
- package/dist/nuxt-navigation.js +23 -0
- package/dist/nuxt-navigation.js.map +1 -0
- package/dist/partition-pointer.d.ts +19 -0
- package/dist/partition-pointer.d.ts.map +1 -0
- package/dist/partition-pointer.js +78 -0
- package/dist/partition-pointer.js.map +1 -0
- package/dist/router-navigation.d.ts +31 -0
- package/dist/router-navigation.d.ts.map +1 -0
- package/dist/router-navigation.js +215 -0
- package/dist/router-navigation.js.map +1 -0
- package/dist/screen-viewport.d.ts.map +1 -1
- package/dist/screen-viewport.js +6 -4
- package/dist/screen-viewport.js.map +1 -1
- package/dist/section-scroll.d.ts +8 -0
- package/dist/section-scroll.d.ts.map +1 -0
- package/dist/section-scroll.js +79 -0
- package/dist/section-scroll.js.map +1 -0
- package/dist/services.d.ts.map +1 -1
- package/dist/services.js +6 -2
- package/dist/services.js.map +1 -1
- package/package.json +4 -4
- package/src/animated-number.ts +59 -0
- package/src/base.css +126 -17
- package/src/component-motion.ts +176 -0
- package/src/component-width.ts +34 -0
- package/src/components/ChartPlot.ts +277 -0
- package/src/components/DateCalendar.ts +71 -11
- package/src/components/MAlert.ts +3 -0
- package/src/components/MAvatar.ts +4 -0
- package/src/components/MBadge.ts +10 -1
- package/src/components/MChip.ts +4 -2
- package/src/components/MCombobox.ts +136 -101
- package/src/components/MDialog.ts +9 -4
- package/src/components/MEmptyState.ts +3 -0
- package/src/components/MFilePicker.ts +3 -1
- package/src/components/MGrid.ts +25 -1
- package/src/components/MImage.ts +10 -1
- package/src/components/MImageCompare.ts +218 -0
- package/src/components/MImageViewer.ts +560 -0
- package/src/components/MInput.ts +5 -0
- package/src/components/MPopover.ts +300 -0
- package/src/components/MProgress.ts +36 -11
- package/src/components/MRangeSlider.ts +144 -0
- package/src/components/MResizablePanels.ts +208 -0
- package/src/components/MSegmentedControl.ts +6 -2
- package/src/components/MStack.ts +5 -0
- package/src/components/MTabs.ts +9 -3
- package/src/components/MTimePicker.ts +124 -0
- package/src/components/MToast.ts +5 -1
- package/src/components/MTooltip.ts +291 -0
- package/src/components/MVirtualList.ts +155 -0
- package/src/components/MotionRows.ts +16 -0
- package/src/components/RangeHalo.ts +34 -0
- package/src/components/discovery.ts +147 -0
- package/src/components/interactive.ts +60 -0
- package/src/components/layout.ts +2 -0
- package/src/components/navigation.ts +44 -0
- package/src/components/wayfinding.ts +70 -0
- package/src/index.ts +81 -1
- package/src/motion-region.ts +5 -2
- package/src/motion-surface.ts +10 -0
- package/src/motion.ts +1 -1
- package/src/nuxt-navigation.ts +29 -0
- package/src/partition-pointer.ts +88 -0
- package/src/router-navigation.ts +249 -0
- package/src/screen-viewport.ts +8 -4
- package/src/section-scroll.ts +101 -0
- package/src/services.ts +7 -1
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineComponent,
|
|
3
|
+
h,
|
|
4
|
+
mergeProps,
|
|
5
|
+
nextTick,
|
|
6
|
+
onActivated,
|
|
7
|
+
onBeforeUnmount,
|
|
8
|
+
onDeactivated,
|
|
9
|
+
onMounted,
|
|
10
|
+
ref,
|
|
11
|
+
shallowRef,
|
|
12
|
+
Teleport,
|
|
13
|
+
Transition,
|
|
14
|
+
withDirectives,
|
|
15
|
+
vShow,
|
|
16
|
+
useId,
|
|
17
|
+
watch,
|
|
18
|
+
} from 'vue'
|
|
19
|
+
import { placePopover } from '@getcortexlabs/mavis-core'
|
|
20
|
+
import { useComponentTransition } from '../component-motion.js'
|
|
21
|
+
import { tooltipProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
22
|
+
import { MButton } from './MButton.js'
|
|
23
|
+
import { MBox } from './layout.js'
|
|
24
|
+
|
|
25
|
+
/** Non-interactive help. Focus remains on the trigger; touch users can toggle it. */
|
|
26
|
+
export const MTooltip = defineComponent({
|
|
27
|
+
name: 'MTooltip',
|
|
28
|
+
inheritAttrs: false,
|
|
29
|
+
props: tooltipProps,
|
|
30
|
+
setup(props, { attrs }) {
|
|
31
|
+
const { theme } = useMavisTheme()
|
|
32
|
+
const id = `m-tooltip-${useId()}`
|
|
33
|
+
const trigger = ref<{ $el?: HTMLElement }>()
|
|
34
|
+
const panel = ref<HTMLElement>()
|
|
35
|
+
const host = shallowRef<HTMLElement>()
|
|
36
|
+
const open = ref(false),
|
|
37
|
+
ready = ref(false)
|
|
38
|
+
const position = ref({ x: 0, y: 0 })
|
|
39
|
+
let hovered = false,
|
|
40
|
+
focused = false,
|
|
41
|
+
pinned = false,
|
|
42
|
+
suppressed = false
|
|
43
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
44
|
+
let observer: ResizeObserver | undefined
|
|
45
|
+
let frame = 0,
|
|
46
|
+
revision = 0
|
|
47
|
+
let active = false
|
|
48
|
+
const transition = useComponentTransition(3)
|
|
49
|
+
function clearTimer() {
|
|
50
|
+
if (timer) clearTimeout(timer)
|
|
51
|
+
timer = undefined
|
|
52
|
+
}
|
|
53
|
+
function close() {
|
|
54
|
+
clearTimer()
|
|
55
|
+
open.value = false
|
|
56
|
+
pinned = false
|
|
57
|
+
}
|
|
58
|
+
function place() {
|
|
59
|
+
frame = 0
|
|
60
|
+
const anchor = trigger.value?.$el,
|
|
61
|
+
popup = panel.value
|
|
62
|
+
if (!active || !open.value || !anchor || !popup) return
|
|
63
|
+
const rect = anchor.getBoundingClientRect()
|
|
64
|
+
if (!anchor.isConnected || !rect.width || !rect.height) {
|
|
65
|
+
close()
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
const viewport = window.visualViewport
|
|
69
|
+
position.value = placePopover(
|
|
70
|
+
rect,
|
|
71
|
+
popup.getBoundingClientRect(),
|
|
72
|
+
{
|
|
73
|
+
x: viewport?.offsetLeft ?? 0,
|
|
74
|
+
y: viewport?.offsetTop ?? 0,
|
|
75
|
+
width: viewport?.width ?? window.innerWidth,
|
|
76
|
+
height: viewport?.height ?? window.innerHeight,
|
|
77
|
+
},
|
|
78
|
+
props.placement,
|
|
79
|
+
getComputedStyle(anchor).direction === 'rtl',
|
|
80
|
+
)
|
|
81
|
+
ready.value = true
|
|
82
|
+
}
|
|
83
|
+
const schedule = () => {
|
|
84
|
+
if (open.value && !frame) frame = requestAnimationFrame(place)
|
|
85
|
+
}
|
|
86
|
+
const escape = (event: KeyboardEvent) => {
|
|
87
|
+
if (open.value && event.key === 'Escape') {
|
|
88
|
+
event.preventDefault()
|
|
89
|
+
event.stopPropagation()
|
|
90
|
+
suppressed = true
|
|
91
|
+
close()
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const outside = (event: PointerEvent) => {
|
|
95
|
+
if (
|
|
96
|
+
!trigger.value?.$el?.contains(event.target as Node) &&
|
|
97
|
+
!panel.value?.contains(event.target as Node)
|
|
98
|
+
)
|
|
99
|
+
close()
|
|
100
|
+
}
|
|
101
|
+
function detach() {
|
|
102
|
+
revision++
|
|
103
|
+
observer?.disconnect()
|
|
104
|
+
observer = undefined
|
|
105
|
+
if (typeof window === 'undefined') return
|
|
106
|
+
if (frame) cancelAnimationFrame(frame)
|
|
107
|
+
frame = 0
|
|
108
|
+
window.removeEventListener('resize', schedule)
|
|
109
|
+
document.removeEventListener('scroll', schedule, true)
|
|
110
|
+
document.removeEventListener('keydown', escape, true)
|
|
111
|
+
document.removeEventListener('pointerdown', outside, true)
|
|
112
|
+
window.visualViewport?.removeEventListener('resize', schedule)
|
|
113
|
+
window.visualViewport?.removeEventListener('scroll', schedule)
|
|
114
|
+
}
|
|
115
|
+
async function present() {
|
|
116
|
+
detach()
|
|
117
|
+
ready.value = false
|
|
118
|
+
if (!active || !open.value || props.disabled) return
|
|
119
|
+
const token = revision
|
|
120
|
+
host.value = trigger.value?.$el?.closest('dialog') ?? document.body
|
|
121
|
+
await nextTick()
|
|
122
|
+
if (token !== revision || !active || !open.value) return
|
|
123
|
+
place()
|
|
124
|
+
observer = new ResizeObserver(schedule)
|
|
125
|
+
if (panel.value) observer.observe(panel.value)
|
|
126
|
+
if (trigger.value?.$el) observer.observe(trigger.value.$el)
|
|
127
|
+
window.addEventListener('resize', schedule)
|
|
128
|
+
document.addEventListener('scroll', schedule, true)
|
|
129
|
+
document.addEventListener('keydown', escape, true)
|
|
130
|
+
document.addEventListener('pointerdown', outside, true)
|
|
131
|
+
window.visualViewport?.addEventListener('resize', schedule)
|
|
132
|
+
window.visualViewport?.addEventListener('scroll', schedule)
|
|
133
|
+
}
|
|
134
|
+
function show(delay = 0) {
|
|
135
|
+
clearTimer()
|
|
136
|
+
if (props.disabled || suppressed || !active) return
|
|
137
|
+
if (delay)
|
|
138
|
+
timer = setTimeout(() => {
|
|
139
|
+
open.value = true
|
|
140
|
+
}, delay)
|
|
141
|
+
else open.value = true
|
|
142
|
+
}
|
|
143
|
+
function leave() {
|
|
144
|
+
clearTimer()
|
|
145
|
+
if (!hovered && !focused && !pinned) timer = setTimeout(close, 120)
|
|
146
|
+
}
|
|
147
|
+
watch(open, (value) => {
|
|
148
|
+
if (value) void present()
|
|
149
|
+
else detach()
|
|
150
|
+
})
|
|
151
|
+
watch(
|
|
152
|
+
() => props.disabled,
|
|
153
|
+
(value) => {
|
|
154
|
+
if (value) close()
|
|
155
|
+
},
|
|
156
|
+
)
|
|
157
|
+
watch(() => props.placement, schedule)
|
|
158
|
+
onMounted(() => {
|
|
159
|
+
active = true
|
|
160
|
+
host.value = trigger.value?.$el?.closest('dialog') ?? document.body
|
|
161
|
+
})
|
|
162
|
+
onActivated(() => {
|
|
163
|
+
active = true
|
|
164
|
+
})
|
|
165
|
+
onDeactivated(() => {
|
|
166
|
+
active = false
|
|
167
|
+
close()
|
|
168
|
+
detach()
|
|
169
|
+
hovered = focused = pinned = false
|
|
170
|
+
})
|
|
171
|
+
onBeforeUnmount(() => {
|
|
172
|
+
active = false
|
|
173
|
+
clearTimer()
|
|
174
|
+
detach()
|
|
175
|
+
})
|
|
176
|
+
return () => {
|
|
177
|
+
if (!props.text.trim() || !props.triggerLabel.trim())
|
|
178
|
+
throw new TypeError('Tooltip requires text and a trigger label.')
|
|
179
|
+
if (!Number.isFinite(props.delay) || props.delay < 0)
|
|
180
|
+
throw new RangeError('Tooltip delay must be nonnegative and finite.')
|
|
181
|
+
const tooltipId = props.id ?? id
|
|
182
|
+
const content = h(
|
|
183
|
+
'span',
|
|
184
|
+
{
|
|
185
|
+
ref: panel,
|
|
186
|
+
id: tooltipId,
|
|
187
|
+
role: 'tooltip',
|
|
188
|
+
'aria-hidden': !open.value || undefined,
|
|
189
|
+
class: 'm-tooltip-content',
|
|
190
|
+
style: {
|
|
191
|
+
position: 'fixed',
|
|
192
|
+
zIndex: 1100,
|
|
193
|
+
left: `${position.value.x}px`,
|
|
194
|
+
top: `${position.value.y}px`,
|
|
195
|
+
width: 'max-content',
|
|
196
|
+
maxWidth: 'min(300px, calc(100vw - 16px))',
|
|
197
|
+
visibility: ready.value ? 'visible' : 'hidden',
|
|
198
|
+
},
|
|
199
|
+
onPointerenter: () => {
|
|
200
|
+
hovered = true
|
|
201
|
+
clearTimer()
|
|
202
|
+
},
|
|
203
|
+
onPointerleave: () => {
|
|
204
|
+
hovered = false
|
|
205
|
+
leave()
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
[
|
|
209
|
+
h(
|
|
210
|
+
MBox,
|
|
211
|
+
{
|
|
212
|
+
padding: 'sm',
|
|
213
|
+
radius: 'md',
|
|
214
|
+
backgroundColor: theme.value.colors.text,
|
|
215
|
+
style: {
|
|
216
|
+
color: theme.value.colors.background,
|
|
217
|
+
fontSize: '13px',
|
|
218
|
+
lineHeight: 1.5,
|
|
219
|
+
boxShadow: '0 6px 20px #0002',
|
|
220
|
+
overflowWrap: 'anywhere',
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
() => props.text,
|
|
224
|
+
),
|
|
225
|
+
],
|
|
226
|
+
)
|
|
227
|
+
return h(
|
|
228
|
+
'span',
|
|
229
|
+
mergeProps(attrs, {
|
|
230
|
+
class: 'm-tooltip',
|
|
231
|
+
style: { display: 'inline-flex', alignSelf: 'flex-start' },
|
|
232
|
+
}),
|
|
233
|
+
[
|
|
234
|
+
h(MButton, {
|
|
235
|
+
ref: trigger,
|
|
236
|
+
icon: props.icon,
|
|
237
|
+
accessibilityLabel: props.triggerLabel,
|
|
238
|
+
variant: props.variant,
|
|
239
|
+
disabled: props.disabled,
|
|
240
|
+
'aria-describedby': tooltipId,
|
|
241
|
+
onPointerenter: (event: PointerEvent) => {
|
|
242
|
+
if (event.pointerType === 'touch') return
|
|
243
|
+
hovered = true
|
|
244
|
+
suppressed = false
|
|
245
|
+
show(props.delay)
|
|
246
|
+
},
|
|
247
|
+
onPointerleave: () => {
|
|
248
|
+
hovered = false
|
|
249
|
+
if (!focused) suppressed = false
|
|
250
|
+
leave()
|
|
251
|
+
},
|
|
252
|
+
onFocus: () => {
|
|
253
|
+
focused = true
|
|
254
|
+
suppressed = false
|
|
255
|
+
show()
|
|
256
|
+
},
|
|
257
|
+
onBlur: () => {
|
|
258
|
+
focused = false
|
|
259
|
+
pinned = false
|
|
260
|
+
leave()
|
|
261
|
+
},
|
|
262
|
+
onClick: () => {
|
|
263
|
+
if (props.disabled) return
|
|
264
|
+
if (pinned) {
|
|
265
|
+
suppressed = true
|
|
266
|
+
close()
|
|
267
|
+
} else {
|
|
268
|
+
pinned = true
|
|
269
|
+
suppressed = false
|
|
270
|
+
show()
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
}),
|
|
274
|
+
host.value
|
|
275
|
+
? h(
|
|
276
|
+
Teleport,
|
|
277
|
+
{ to: host.value },
|
|
278
|
+
h(
|
|
279
|
+
Transition,
|
|
280
|
+
{ ...transition, persisted: true },
|
|
281
|
+
{
|
|
282
|
+
default: () => withDirectives(content, [[vShow, open.value]]),
|
|
283
|
+
},
|
|
284
|
+
),
|
|
285
|
+
)
|
|
286
|
+
: withDirectives(content, [[vShow, false]]),
|
|
287
|
+
],
|
|
288
|
+
)
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
})
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { useComponentLayout } from '@getcortexlabs/mavis-core/vue'
|
|
2
|
+
import { useMotionRegion } from '../motion-region.js'
|
|
3
|
+
import type { VirtualListComponent } from '@getcortexlabs/mavis-core/vue'
|
|
4
|
+
import { computed, defineComponent, h, mergeProps, nextTick, onMounted, ref, watch } from 'vue'
|
|
5
|
+
import { virtualListProps } from '@getcortexlabs/mavis-core/vue'
|
|
6
|
+
import {
|
|
7
|
+
choiceKey,
|
|
8
|
+
virtualKeys,
|
|
9
|
+
virtualWindow,
|
|
10
|
+
type VirtualListHandle,
|
|
11
|
+
} from '@getcortexlabs/mavis-core'
|
|
12
|
+
import { MText } from './MText.js'
|
|
13
|
+
|
|
14
|
+
const VirtualList = defineComponent({
|
|
15
|
+
name: 'MVirtualList',
|
|
16
|
+
inheritAttrs: false,
|
|
17
|
+
props: virtualListProps,
|
|
18
|
+
setup(props, { attrs, slots, expose }) {
|
|
19
|
+
const keys = computed(() => virtualKeys(props.items, props.itemKey))
|
|
20
|
+
// Only data mutations animate the realized window. Scrolling never starts motion.
|
|
21
|
+
const layout = useComponentLayout(() => keys.value, false)
|
|
22
|
+
const motion = useMotionRegion(() => layout)
|
|
23
|
+
const root = ref<HTMLElement>()
|
|
24
|
+
const offset = ref(props.initialIndex * props.rowHeight)
|
|
25
|
+
const focusedKey = ref<string>()
|
|
26
|
+
const window = computed(() =>
|
|
27
|
+
virtualWindow(
|
|
28
|
+
props.items.length,
|
|
29
|
+
props.rowHeight,
|
|
30
|
+
props.height,
|
|
31
|
+
offset.value,
|
|
32
|
+
props.overscan,
|
|
33
|
+
),
|
|
34
|
+
)
|
|
35
|
+
function syncOffset() {
|
|
36
|
+
offset.value = window.value.scrollTop
|
|
37
|
+
if (root.value) root.value.scrollTop = offset.value
|
|
38
|
+
}
|
|
39
|
+
watch(
|
|
40
|
+
keys,
|
|
41
|
+
(next, previous) => {
|
|
42
|
+
const index = Math.floor(offset.value / props.rowHeight)
|
|
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)
|
|
47
|
+
if (focusedKey.value && !next.some((key) => choiceKey(key) === focusedKey.value)) {
|
|
48
|
+
if (root.value?.contains(document.activeElement))
|
|
49
|
+
root.value.focus({ preventScroll: true })
|
|
50
|
+
focusedKey.value = undefined
|
|
51
|
+
}
|
|
52
|
+
void nextTick(syncOffset)
|
|
53
|
+
},
|
|
54
|
+
{ flush: 'pre' },
|
|
55
|
+
)
|
|
56
|
+
watch(
|
|
57
|
+
() => [props.rowHeight, props.height],
|
|
58
|
+
() => void nextTick(syncOffset),
|
|
59
|
+
)
|
|
60
|
+
onMounted(syncOffset)
|
|
61
|
+
expose({
|
|
62
|
+
scrollToIndex(index: number) {
|
|
63
|
+
if (!Number.isInteger(index) || index < 0 || index >= props.items.length)
|
|
64
|
+
throw new RangeError('List index is out of range.')
|
|
65
|
+
offset.value = index * props.rowHeight
|
|
66
|
+
syncOffset()
|
|
67
|
+
},
|
|
68
|
+
} satisfies VirtualListHandle)
|
|
69
|
+
return () => {
|
|
70
|
+
if (!props.label.trim()) throw new TypeError('Virtual lists require a label.')
|
|
71
|
+
if (!Number.isInteger(props.initialIndex) || props.initialIndex < 0)
|
|
72
|
+
throw new RangeError('initialIndex must be a nonnegative integer.')
|
|
73
|
+
const state = window.value
|
|
74
|
+
const indices = new Set(
|
|
75
|
+
Array.from({ length: state.end - state.start }, (_, i) => state.start + i),
|
|
76
|
+
)
|
|
77
|
+
if (focusedKey.value) {
|
|
78
|
+
const focused = keys.value.findIndex((key) => choiceKey(key) === focusedKey.value)
|
|
79
|
+
if (focused >= 0) indices.add(focused)
|
|
80
|
+
}
|
|
81
|
+
return h(
|
|
82
|
+
'div',
|
|
83
|
+
mergeProps(attrs, {
|
|
84
|
+
ref: root,
|
|
85
|
+
id: props.id,
|
|
86
|
+
role: 'region',
|
|
87
|
+
'aria-label': props.label,
|
|
88
|
+
tabindex: 0,
|
|
89
|
+
class: 'm-virtual-list',
|
|
90
|
+
style: {
|
|
91
|
+
height: `${props.height}px`,
|
|
92
|
+
overflow: 'auto',
|
|
93
|
+
position: 'relative',
|
|
94
|
+
overflowAnchor: 'none',
|
|
95
|
+
flexShrink: 0,
|
|
96
|
+
},
|
|
97
|
+
onScroll: () => {
|
|
98
|
+
offset.value = root.value?.scrollTop ?? 0
|
|
99
|
+
},
|
|
100
|
+
onFocusin: (event: FocusEvent) => {
|
|
101
|
+
focusedKey.value = (event.target as HTMLElement).closest<HTMLElement>(
|
|
102
|
+
'[data-m-list-key]',
|
|
103
|
+
)?.dataset.mListKey
|
|
104
|
+
},
|
|
105
|
+
onFocusout: () =>
|
|
106
|
+
void nextTick(() => {
|
|
107
|
+
if (!root.value?.contains(document.activeElement)) focusedKey.value = undefined
|
|
108
|
+
}),
|
|
109
|
+
}),
|
|
110
|
+
props.items.length
|
|
111
|
+
? [
|
|
112
|
+
h(
|
|
113
|
+
'div',
|
|
114
|
+
{
|
|
115
|
+
...motion,
|
|
116
|
+
role: 'list',
|
|
117
|
+
style: { height: `${state.totalHeight}px`, position: 'relative' },
|
|
118
|
+
},
|
|
119
|
+
[...indices]
|
|
120
|
+
.sort((a, b) => a - b)
|
|
121
|
+
.map((index) =>
|
|
122
|
+
h(
|
|
123
|
+
'div',
|
|
124
|
+
{
|
|
125
|
+
key: choiceKey(keys.value[index]!),
|
|
126
|
+
role: 'listitem',
|
|
127
|
+
'data-m-list-key': choiceKey(keys.value[index]!),
|
|
128
|
+
'aria-posinset': index + 1,
|
|
129
|
+
'aria-setsize': props.items.length,
|
|
130
|
+
style: {
|
|
131
|
+
position: 'absolute',
|
|
132
|
+
top: `${index * props.rowHeight}px`,
|
|
133
|
+
left: 0,
|
|
134
|
+
right: 0,
|
|
135
|
+
height: `${props.rowHeight}px`,
|
|
136
|
+
overflow: 'hidden',
|
|
137
|
+
boxSizing: 'border-box',
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
slots.default?.({
|
|
141
|
+
item: props.items[index],
|
|
142
|
+
index,
|
|
143
|
+
itemKey: keys.value[index]!,
|
|
144
|
+
}),
|
|
145
|
+
),
|
|
146
|
+
),
|
|
147
|
+
),
|
|
148
|
+
]
|
|
149
|
+
: (slots.empty?.() ?? [h(MText, { text: props.emptyLabel, tone: 'muted' })]),
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
export const MVirtualList = VirtualList as unknown as VirtualListComponent
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineComponent, h, type PropType, type VNode } from 'vue'
|
|
2
|
+
import { useComponentLayout } from '@getcortexlabs/mavis-core/vue'
|
|
3
|
+
import { useMotionRegion } from '../motion-region.js'
|
|
4
|
+
|
|
5
|
+
/** Semantic rows stay in the table; only their private presentation is transformed. */
|
|
6
|
+
export const MotionRows = defineComponent({
|
|
7
|
+
props: {
|
|
8
|
+
nodes: { type: Array as PropType<VNode[]>, required: true },
|
|
9
|
+
tag: { type: String, default: 'tbody' },
|
|
10
|
+
},
|
|
11
|
+
setup(props) {
|
|
12
|
+
const region = useComponentLayout(() => props.nodes.map((node) => node.key))
|
|
13
|
+
const hooks = useMotionRegion(() => region)
|
|
14
|
+
return () => h(props.tag, hooks, props.nodes)
|
|
15
|
+
},
|
|
16
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { defineComponent, h, ref } from 'vue'
|
|
2
|
+
import { useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
3
|
+
import { useComponentPaint } from '../component-motion.js'
|
|
4
|
+
|
|
5
|
+
/** A separate decoration keeps the platform range input and hit target unchanged. */
|
|
6
|
+
export const RangeHalo = defineComponent({
|
|
7
|
+
props: { active: Boolean, position: { type: Number, required: true } },
|
|
8
|
+
setup(props) {
|
|
9
|
+
const target = ref<HTMLElement>()
|
|
10
|
+
const { theme } = useMavisTheme()
|
|
11
|
+
useComponentPaint(
|
|
12
|
+
target,
|
|
13
|
+
() => ({ scale: props.active ? 1 : 0.65, opacity: props.active ? 0.18 : 0 }),
|
|
14
|
+
'feedback',
|
|
15
|
+
)
|
|
16
|
+
return () =>
|
|
17
|
+
h('span', {
|
|
18
|
+
ref: target,
|
|
19
|
+
'aria-hidden': 'true',
|
|
20
|
+
style: {
|
|
21
|
+
position: 'absolute',
|
|
22
|
+
left: `${props.position * 100}%`,
|
|
23
|
+
top: '4px',
|
|
24
|
+
marginLeft: '-20px',
|
|
25
|
+
width: '40px',
|
|
26
|
+
height: '40px',
|
|
27
|
+
borderRadius: '50%',
|
|
28
|
+
background: theme.value.colors.primary,
|
|
29
|
+
pointerEvents: 'none',
|
|
30
|
+
opacity: 0,
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
},
|
|
34
|
+
})
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { MotionRows } from './MotionRows.js'
|
|
2
|
+
import { h } from 'vue'
|
|
3
|
+
import {
|
|
4
|
+
createDiscoveryControls,
|
|
5
|
+
createCarousel,
|
|
6
|
+
createTreeView,
|
|
7
|
+
createDataTable,
|
|
8
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
9
|
+
import type { DataColumn } from '@getcortexlabs/mavis-core'
|
|
10
|
+
import { MRow, MColumn, MBox } from './layout.js'
|
|
11
|
+
import { MText } from './MText.js'
|
|
12
|
+
import { MButton } from './MButton.js'
|
|
13
|
+
import { MIcon } from './MIcon.js'
|
|
14
|
+
import { MSlider } from './MSlider.js'
|
|
15
|
+
import { MCheckbox } from './MCheckbox.js'
|
|
16
|
+
import { MProgress } from './MProgress.js'
|
|
17
|
+
import { MReveal } from './MReveal.js'
|
|
18
|
+
import { DateCalendar } from './DateCalendar.js'
|
|
19
|
+
|
|
20
|
+
const ui = {
|
|
21
|
+
Row: MRow,
|
|
22
|
+
Column: MColumn,
|
|
23
|
+
Box: MBox,
|
|
24
|
+
Text: MText,
|
|
25
|
+
Button: MButton,
|
|
26
|
+
Icon: MIcon,
|
|
27
|
+
Slider: MSlider,
|
|
28
|
+
Checkbox: MCheckbox,
|
|
29
|
+
Progress: MProgress,
|
|
30
|
+
Reveal: MReveal,
|
|
31
|
+
Calendar: DateCalendar,
|
|
32
|
+
}
|
|
33
|
+
export const { MCalendar, MRating } = createDiscoveryControls(ui, 'web')
|
|
34
|
+
export const MTreeView = createTreeView(
|
|
35
|
+
{
|
|
36
|
+
...ui,
|
|
37
|
+
focus: (id) => document.getElementById(id)?.focus(),
|
|
38
|
+
containsFocus: (id) => !!document.getElementById(id)?.contains(document.activeElement),
|
|
39
|
+
},
|
|
40
|
+
'web',
|
|
41
|
+
)
|
|
42
|
+
export const MCarousel = createCarousel(
|
|
43
|
+
{
|
|
44
|
+
...ui,
|
|
45
|
+
gestures: (move, direction) => ({
|
|
46
|
+
tabindex: 0,
|
|
47
|
+
onPointerdownCapture: (event: PointerEvent) => {
|
|
48
|
+
const host = event.currentTarget as HTMLElement
|
|
49
|
+
direction.value = getComputedStyle(host).direction === 'rtl' ? -1 : 1
|
|
50
|
+
if (event.defaultPrevented || !event.isPrimary || event.button !== 0) return
|
|
51
|
+
for (const node of event.composedPath()) {
|
|
52
|
+
if (node === host) break
|
|
53
|
+
if (
|
|
54
|
+
node instanceof Element &&
|
|
55
|
+
node.matches(
|
|
56
|
+
'button, a[href], input, select, textarea, [contenteditable], [role="button"]',
|
|
57
|
+
)
|
|
58
|
+
)
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
// Default pointer focus may scroll a tall slide and cancel Jolt's active drag.
|
|
62
|
+
// Keep keyboard navigation available without changing the viewport or consuming input.
|
|
63
|
+
host.focus({ preventScroll: true })
|
|
64
|
+
},
|
|
65
|
+
onKeydown: (event: KeyboardEvent) => {
|
|
66
|
+
if (event.target !== event.currentTarget || event.altKey || event.ctrlKey || event.metaKey)
|
|
67
|
+
return
|
|
68
|
+
if (event.key === 'ArrowRight' || event.key === 'ArrowLeft') {
|
|
69
|
+
event.preventDefault()
|
|
70
|
+
direction.value =
|
|
71
|
+
getComputedStyle(event.currentTarget as HTMLElement).direction === 'rtl' ? -1 : 1
|
|
72
|
+
move((event.key === 'ArrowRight' ? 1 : -1) * direction.value)
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
}),
|
|
76
|
+
},
|
|
77
|
+
'web',
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
// Theme access must happen in setup, not in the render callback supplied to the factory.
|
|
81
|
+
export const MDataTable = createDataTable(
|
|
82
|
+
{
|
|
83
|
+
...ui,
|
|
84
|
+
table: (columns, header, rows, label, busy) => {
|
|
85
|
+
const cell = (column: DataColumn) => ({
|
|
86
|
+
padding: '12px 16px',
|
|
87
|
+
minWidth: `${column.width ?? 144}px`,
|
|
88
|
+
width: column.width ? `${column.width}px` : undefined,
|
|
89
|
+
textAlign: column.align === 'end' ? ('end' as const) : ('start' as const),
|
|
90
|
+
verticalAlign: 'middle',
|
|
91
|
+
})
|
|
92
|
+
return h(
|
|
93
|
+
'div',
|
|
94
|
+
{
|
|
95
|
+
class: 'm-data-table-scroll',
|
|
96
|
+
tabindex: 0,
|
|
97
|
+
role: 'region',
|
|
98
|
+
'aria-label': label,
|
|
99
|
+
style: { overflowX: 'auto', borderRadius: 'inherit' },
|
|
100
|
+
},
|
|
101
|
+
[
|
|
102
|
+
h(
|
|
103
|
+
'table',
|
|
104
|
+
{
|
|
105
|
+
'aria-label': label,
|
|
106
|
+
'aria-busy': busy,
|
|
107
|
+
style: { width: '100%', borderCollapse: 'collapse' },
|
|
108
|
+
},
|
|
109
|
+
[
|
|
110
|
+
h('thead', [
|
|
111
|
+
h(
|
|
112
|
+
'tr',
|
|
113
|
+
columns.map((column, index) =>
|
|
114
|
+
h(
|
|
115
|
+
'th',
|
|
116
|
+
{
|
|
117
|
+
key: column.key,
|
|
118
|
+
scope: 'col',
|
|
119
|
+
'aria-sort': (column as DataColumn & { sort?: string }).sort,
|
|
120
|
+
style: cell(column),
|
|
121
|
+
},
|
|
122
|
+
[header[index]],
|
|
123
|
+
),
|
|
124
|
+
),
|
|
125
|
+
),
|
|
126
|
+
]),
|
|
127
|
+
h(MotionRows, {
|
|
128
|
+
nodes: rows.map((row) =>
|
|
129
|
+
h(
|
|
130
|
+
'tr',
|
|
131
|
+
{ key: row.key, 'data-selected': row.selected },
|
|
132
|
+
row.cells.map((content, index) =>
|
|
133
|
+
h('td', { key: columns[index]!.key, style: cell(columns[index]!) }, [
|
|
134
|
+
content,
|
|
135
|
+
]),
|
|
136
|
+
),
|
|
137
|
+
),
|
|
138
|
+
),
|
|
139
|
+
}),
|
|
140
|
+
],
|
|
141
|
+
),
|
|
142
|
+
],
|
|
143
|
+
)
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
'web',
|
|
147
|
+
)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { defineComponent, h, ref } from 'vue'
|
|
2
|
+
import {
|
|
3
|
+
createNumberFlow,
|
|
4
|
+
createSortableList,
|
|
5
|
+
createSwipeActions,
|
|
6
|
+
sortableScrollProps,
|
|
7
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
8
|
+
import { useScrollMotion } from '../scroll-motion.js'
|
|
9
|
+
import { MBox, MColumn, MRow } from './layout.js'
|
|
10
|
+
import { MText } from './MText.js'
|
|
11
|
+
import { MButton } from './MButton.js'
|
|
12
|
+
import { MMenu } from './navigation.js'
|
|
13
|
+
|
|
14
|
+
const SortableScroll = defineComponent({
|
|
15
|
+
name: 'MSortableScroll',
|
|
16
|
+
props: sortableScrollProps,
|
|
17
|
+
setup(props, { slots }) {
|
|
18
|
+
const element = ref<HTMLElement>()
|
|
19
|
+
useScrollMotion(
|
|
20
|
+
element,
|
|
21
|
+
() => props.source,
|
|
22
|
+
() => true,
|
|
23
|
+
)
|
|
24
|
+
return () =>
|
|
25
|
+
h(
|
|
26
|
+
'div',
|
|
27
|
+
{
|
|
28
|
+
ref: element,
|
|
29
|
+
style: { height: `${props.height}px`, overflowY: 'auto', overscrollBehavior: 'contain' },
|
|
30
|
+
},
|
|
31
|
+
slots.default?.(),
|
|
32
|
+
)
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
const ui = { Box: MBox, Column: MColumn, Row: MRow, Text: MText, Button: MButton, Menu: MMenu }
|
|
36
|
+
export const MNumberFlow = createNumberFlow(MText, 'web')
|
|
37
|
+
export const MSortableList = createSortableList(
|
|
38
|
+
{
|
|
39
|
+
...ui,
|
|
40
|
+
Scroll: SortableScroll,
|
|
41
|
+
ListBody: MBox,
|
|
42
|
+
input: (fresh) => ({
|
|
43
|
+
onPointerdownCapture: (event: PointerEvent) => {
|
|
44
|
+
if (
|
|
45
|
+
event.isPrimary &&
|
|
46
|
+
event.button === 0 &&
|
|
47
|
+
event.target instanceof Element &&
|
|
48
|
+
!event.target.closest('[data-sort-handle]')
|
|
49
|
+
)
|
|
50
|
+
fresh()
|
|
51
|
+
},
|
|
52
|
+
}),
|
|
53
|
+
},
|
|
54
|
+
'web',
|
|
55
|
+
)
|
|
56
|
+
export const MSwipeActions = createSwipeActions(ui, 'web')
|
|
57
|
+
export { MResizablePanels } from './MResizablePanels.js'
|
|
58
|
+
export { MImageCompare } from './MImageCompare.js'
|
|
59
|
+
|
|
60
|
+
export { MImageViewer } from './MImageViewer.js'
|