@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,300 @@
|
|
|
1
|
+
import { useComponentTransition } from '../component-motion.js'
|
|
2
|
+
import {
|
|
3
|
+
defineComponent,
|
|
4
|
+
h,
|
|
5
|
+
mergeProps,
|
|
6
|
+
nextTick,
|
|
7
|
+
onBeforeUnmount,
|
|
8
|
+
onMounted,
|
|
9
|
+
onDeactivated,
|
|
10
|
+
onActivated,
|
|
11
|
+
ref,
|
|
12
|
+
shallowRef,
|
|
13
|
+
Teleport,
|
|
14
|
+
Transition,
|
|
15
|
+
useId,
|
|
16
|
+
watch,
|
|
17
|
+
} from 'vue'
|
|
18
|
+
import { popoverProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
19
|
+
import { placePopover, resolveSpace, type PopoverCloseReason } from '@getcortexlabs/mavis-core'
|
|
20
|
+
import { MButton } from './MButton.js'
|
|
21
|
+
|
|
22
|
+
export const MPopover = defineComponent({
|
|
23
|
+
name: 'MPopover',
|
|
24
|
+
inheritAttrs: false,
|
|
25
|
+
props: popoverProps,
|
|
26
|
+
emits: {
|
|
27
|
+
'update:open': (_open: boolean) => true,
|
|
28
|
+
close: (_reason: PopoverCloseReason) => true,
|
|
29
|
+
opened: () => true,
|
|
30
|
+
},
|
|
31
|
+
setup(props, { attrs, slots, emit }) {
|
|
32
|
+
const { theme } = useMavisTheme()
|
|
33
|
+
const presentation = useComponentTransition(6)
|
|
34
|
+
const transition = {
|
|
35
|
+
...presentation,
|
|
36
|
+
onBeforeLeave: (element: Element) => {
|
|
37
|
+
element.setAttribute('inert', '')
|
|
38
|
+
element.setAttribute('aria-hidden', 'true')
|
|
39
|
+
},
|
|
40
|
+
onBeforeEnter: (element: Element) => {
|
|
41
|
+
element.removeAttribute('inert')
|
|
42
|
+
element.removeAttribute('aria-hidden')
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
const id = `m-popover-${useId()}`
|
|
46
|
+
const anchor = ref<HTMLElement>()
|
|
47
|
+
const trigger = ref<{ $el?: HTMLElement }>()
|
|
48
|
+
const panel = ref<HTMLElement>()
|
|
49
|
+
const host = shallowRef<HTMLElement>()
|
|
50
|
+
const position = ref({ x: 0, y: 0 })
|
|
51
|
+
const ready = ref(false)
|
|
52
|
+
let observer: ResizeObserver | undefined
|
|
53
|
+
let frame = 0
|
|
54
|
+
let generation = 0
|
|
55
|
+
let mounted = false
|
|
56
|
+
let reason: PopoverCloseReason = 'program'
|
|
57
|
+
function owns(target: EventTarget | null) {
|
|
58
|
+
return (
|
|
59
|
+
target instanceof Node && (anchor.value?.contains(target) || panel.value?.contains(target))
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
function close(value: PopoverCloseReason) {
|
|
63
|
+
if (!props.open) return
|
|
64
|
+
reason = value
|
|
65
|
+
emit('update:open', false)
|
|
66
|
+
emit('close', value)
|
|
67
|
+
}
|
|
68
|
+
function place() {
|
|
69
|
+
frame = 0
|
|
70
|
+
if (!anchor.value || !panel.value || !props.open) return
|
|
71
|
+
const a = anchor.value.getBoundingClientRect()
|
|
72
|
+
if (!anchor.value.isConnected || !a.width || !a.height) {
|
|
73
|
+
close('program')
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
const viewport = window.visualViewport
|
|
77
|
+
position.value = placePopover(
|
|
78
|
+
a,
|
|
79
|
+
panel.value.getBoundingClientRect(),
|
|
80
|
+
{
|
|
81
|
+
x: viewport?.offsetLeft ?? 0,
|
|
82
|
+
y: viewport?.offsetTop ?? 0,
|
|
83
|
+
width: viewport?.width ?? window.innerWidth,
|
|
84
|
+
height: viewport?.height ?? window.innerHeight,
|
|
85
|
+
},
|
|
86
|
+
props.placement,
|
|
87
|
+
getComputedStyle(anchor.value).direction === 'rtl',
|
|
88
|
+
)
|
|
89
|
+
ready.value = true
|
|
90
|
+
}
|
|
91
|
+
function schedule() {
|
|
92
|
+
if (!frame) frame = requestAnimationFrame(place)
|
|
93
|
+
}
|
|
94
|
+
function outside(event: Event) {
|
|
95
|
+
if (!owns(event.target)) close('outside')
|
|
96
|
+
}
|
|
97
|
+
function focusout(event: FocusEvent) {
|
|
98
|
+
if (!owns(event.target)) close('outside')
|
|
99
|
+
}
|
|
100
|
+
function escape(event: KeyboardEvent) {
|
|
101
|
+
if (event.key === 'Escape' && owns(event.target)) {
|
|
102
|
+
event.preventDefault()
|
|
103
|
+
event.stopPropagation()
|
|
104
|
+
close('escape')
|
|
105
|
+
}
|
|
106
|
+
if (
|
|
107
|
+
event.key === 'Tab' &&
|
|
108
|
+
props.role === 'menu' &&
|
|
109
|
+
panel.value?.contains(event.target as Node)
|
|
110
|
+
) {
|
|
111
|
+
event.preventDefault()
|
|
112
|
+
const controls = [
|
|
113
|
+
...document.querySelectorAll<HTMLElement>(
|
|
114
|
+
'button:not(:disabled), a[href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex="0"]',
|
|
115
|
+
),
|
|
116
|
+
].filter(
|
|
117
|
+
(control) =>
|
|
118
|
+
control.tabIndex >= 0 &&
|
|
119
|
+
!panel.value?.contains(control) &&
|
|
120
|
+
!control.closest('[inert], [hidden]') &&
|
|
121
|
+
control.getClientRects().length,
|
|
122
|
+
)
|
|
123
|
+
const index = controls.indexOf(trigger.value?.$el as HTMLElement)
|
|
124
|
+
close('outside')
|
|
125
|
+
;(controls[index + (event.shiftKey ? -1 : 1)] ?? trigger.value?.$el)?.focus({
|
|
126
|
+
preventScroll: true,
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function detach() {
|
|
131
|
+
generation++
|
|
132
|
+
observer?.disconnect()
|
|
133
|
+
observer = undefined
|
|
134
|
+
if (typeof window === 'undefined') return
|
|
135
|
+
if (frame) cancelAnimationFrame(frame)
|
|
136
|
+
frame = 0
|
|
137
|
+
window.removeEventListener('resize', schedule)
|
|
138
|
+
document.removeEventListener('scroll', schedule, true)
|
|
139
|
+
document.removeEventListener('pointerdown', outside, true)
|
|
140
|
+
document.removeEventListener('focusin', focusout)
|
|
141
|
+
document.removeEventListener('keydown', escape)
|
|
142
|
+
window.visualViewport?.removeEventListener('resize', schedule)
|
|
143
|
+
window.visualViewport?.removeEventListener('scroll', schedule)
|
|
144
|
+
}
|
|
145
|
+
async function present() {
|
|
146
|
+
detach()
|
|
147
|
+
if (!mounted || !props.open || props.disabled) return
|
|
148
|
+
const token = generation
|
|
149
|
+
reason = 'program'
|
|
150
|
+
ready.value = false
|
|
151
|
+
host.value = anchor.value?.closest('dialog') ?? document.body
|
|
152
|
+
await nextTick()
|
|
153
|
+
if (!mounted || token !== generation || !props.open || !panel.value) return
|
|
154
|
+
place()
|
|
155
|
+
observer = new ResizeObserver(schedule)
|
|
156
|
+
observer.observe(panel.value)
|
|
157
|
+
if (anchor.value) observer.observe(anchor.value)
|
|
158
|
+
window.addEventListener('resize', schedule)
|
|
159
|
+
document.addEventListener('scroll', schedule, true)
|
|
160
|
+
document.addEventListener('pointerdown', outside, true)
|
|
161
|
+
document.addEventListener('focusin', focusout)
|
|
162
|
+
document.addEventListener('keydown', escape)
|
|
163
|
+
window.visualViewport?.addEventListener('resize', schedule)
|
|
164
|
+
window.visualViewport?.addEventListener('scroll', schedule)
|
|
165
|
+
await nextTick()
|
|
166
|
+
if (token !== generation || !props.open) return
|
|
167
|
+
;(
|
|
168
|
+
panel.value?.querySelector<HTMLElement>(
|
|
169
|
+
'button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex="0"]',
|
|
170
|
+
) ?? panel.value
|
|
171
|
+
)?.focus({ preventScroll: true })
|
|
172
|
+
emit('opened')
|
|
173
|
+
}
|
|
174
|
+
watch(
|
|
175
|
+
() => props.open,
|
|
176
|
+
(open) => {
|
|
177
|
+
if (open) void present()
|
|
178
|
+
else {
|
|
179
|
+
const focused =
|
|
180
|
+
typeof document !== 'undefined' && panel.value?.contains(document.activeElement)
|
|
181
|
+
detach()
|
|
182
|
+
if (focused && reason !== 'outside') trigger.value?.$el?.focus({ preventScroll: true })
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
)
|
|
186
|
+
watch(
|
|
187
|
+
() => props.disabled,
|
|
188
|
+
(value) => {
|
|
189
|
+
if (value && props.open) close('program')
|
|
190
|
+
},
|
|
191
|
+
)
|
|
192
|
+
watch(
|
|
193
|
+
() => [props.placement, props.width],
|
|
194
|
+
() => {
|
|
195
|
+
if (props.open && mounted) schedule()
|
|
196
|
+
},
|
|
197
|
+
)
|
|
198
|
+
onMounted(() => {
|
|
199
|
+
mounted = true
|
|
200
|
+
void present()
|
|
201
|
+
})
|
|
202
|
+
onActivated(() => {
|
|
203
|
+
if (!mounted) {
|
|
204
|
+
mounted = true
|
|
205
|
+
void present()
|
|
206
|
+
}
|
|
207
|
+
})
|
|
208
|
+
onDeactivated(() => {
|
|
209
|
+
mounted = false
|
|
210
|
+
detach()
|
|
211
|
+
host.value = undefined
|
|
212
|
+
if (props.open) close('program')
|
|
213
|
+
})
|
|
214
|
+
onBeforeUnmount(() => {
|
|
215
|
+
mounted = false
|
|
216
|
+
detach()
|
|
217
|
+
})
|
|
218
|
+
return () => {
|
|
219
|
+
if (!props.label.trim() || !props.triggerLabel.trim())
|
|
220
|
+
throw new TypeError('Popovers require panel and trigger labels.')
|
|
221
|
+
if (!Number.isFinite(props.width) || props.width <= 0)
|
|
222
|
+
throw new RangeError('Popover width must be positive and finite.')
|
|
223
|
+
const panelId = props.id ?? id
|
|
224
|
+
return h(
|
|
225
|
+
'span',
|
|
226
|
+
mergeProps(
|
|
227
|
+
{
|
|
228
|
+
ref: anchor,
|
|
229
|
+
class: 'm-popover-anchor',
|
|
230
|
+
style: { display: 'inline-flex', alignSelf: 'flex-start' },
|
|
231
|
+
},
|
|
232
|
+
attrs,
|
|
233
|
+
),
|
|
234
|
+
[
|
|
235
|
+
h(MButton, {
|
|
236
|
+
ref: trigger,
|
|
237
|
+
text: props.triggerLabel,
|
|
238
|
+
icon: props.icon,
|
|
239
|
+
variant: props.variant,
|
|
240
|
+
disabled: props.disabled,
|
|
241
|
+
'aria-haspopup': props.role,
|
|
242
|
+
'aria-expanded': props.open,
|
|
243
|
+
'aria-controls': panelId,
|
|
244
|
+
onClick: () => (props.open ? close('trigger') : emit('update:open', true)),
|
|
245
|
+
onKeydown: (event: KeyboardEvent) => {
|
|
246
|
+
if (event.key === 'ArrowDown' && !props.open) {
|
|
247
|
+
event.preventDefault()
|
|
248
|
+
emit('update:open', true)
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
}),
|
|
252
|
+
host.value
|
|
253
|
+
? h(
|
|
254
|
+
Teleport,
|
|
255
|
+
{ to: host.value },
|
|
256
|
+
h(Transition, transition, {
|
|
257
|
+
default: () =>
|
|
258
|
+
props.open && !props.disabled
|
|
259
|
+
? h(
|
|
260
|
+
'div',
|
|
261
|
+
{
|
|
262
|
+
ref: panel,
|
|
263
|
+
inert: !props.open || undefined,
|
|
264
|
+
'aria-hidden': !props.open || undefined,
|
|
265
|
+
id: panelId,
|
|
266
|
+
role: props.role,
|
|
267
|
+
'aria-label': props.label,
|
|
268
|
+
tabindex: -1,
|
|
269
|
+
class: 'm-popover-panel',
|
|
270
|
+
style: {
|
|
271
|
+
position: 'fixed',
|
|
272
|
+
zIndex: 1000,
|
|
273
|
+
boxSizing: 'border-box',
|
|
274
|
+
left: `${position.value.x}px`,
|
|
275
|
+
top: `${position.value.y}px`,
|
|
276
|
+
width: `${props.width}px`,
|
|
277
|
+
maxWidth: 'calc(100vw - 16px)',
|
|
278
|
+
maxHeight: 'calc(100dvh - 16px)',
|
|
279
|
+
overflow: 'auto',
|
|
280
|
+
visibility: ready.value ? 'visible' : 'hidden',
|
|
281
|
+
padding: `${resolveSpace(theme.value, props.padding)}px`,
|
|
282
|
+
background: theme.value.colors.surface,
|
|
283
|
+
color: theme.value.colors.text,
|
|
284
|
+
border: `1px solid ${theme.value.colors.border}`,
|
|
285
|
+
borderRadius: `${theme.value.radius.md}px`,
|
|
286
|
+
boxShadow: '0 12px 36px #0002',
|
|
287
|
+
colorScheme: theme.value.appearance,
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
slots.default?.({ close: () => close('program') }),
|
|
291
|
+
)
|
|
292
|
+
: null,
|
|
293
|
+
}),
|
|
294
|
+
)
|
|
295
|
+
: null,
|
|
296
|
+
],
|
|
297
|
+
)
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
})
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useComponentPaint } from '../component-motion.js'
|
|
1
2
|
import { defineComponent, h, mergeProps, onBeforeUnmount, onMounted, ref } from 'vue'
|
|
2
3
|
import { progressProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
3
4
|
import {
|
|
@@ -8,6 +9,28 @@ import {
|
|
|
8
9
|
} from '@getcortexlabs/mavis-core'
|
|
9
10
|
import { MBox } from './layout.js'
|
|
10
11
|
|
|
12
|
+
const DeterminateFill = defineComponent({
|
|
13
|
+
props: { ratio: { type: Number, required: true }, color: String },
|
|
14
|
+
setup(props) {
|
|
15
|
+
const element = ref<HTMLElement>()
|
|
16
|
+
useComponentPaint(element, () => ({ scaleX: Math.max(0.0001, props.ratio) }), 'data')
|
|
17
|
+
return () =>
|
|
18
|
+
h('div', {
|
|
19
|
+
ref: element,
|
|
20
|
+
class: 'm-progress-fill',
|
|
21
|
+
'aria-hidden': 'true',
|
|
22
|
+
style: {
|
|
23
|
+
width: '100%',
|
|
24
|
+
height: '100%',
|
|
25
|
+
backgroundColor: props.color,
|
|
26
|
+
borderRadius: 'inherit',
|
|
27
|
+
transformOrigin: '0px 0px',
|
|
28
|
+
animation: 'none',
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
|
|
11
34
|
export const MProgress = defineComponent({
|
|
12
35
|
name: 'MProgress',
|
|
13
36
|
inheritAttrs: false,
|
|
@@ -64,17 +87,19 @@ export const MProgress = defineComponent({
|
|
|
64
87
|
),
|
|
65
88
|
{
|
|
66
89
|
default: () =>
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
90
|
+
!props.indeterminate
|
|
91
|
+
? h(DeterminateFill, { ratio: reading.ratio, color: theme.value.colors[props.tone] })
|
|
92
|
+
: h('div', {
|
|
93
|
+
class: 'm-progress-fill',
|
|
94
|
+
'aria-hidden': 'true',
|
|
95
|
+
style: {
|
|
96
|
+
width: `${fraction * 100}%`,
|
|
97
|
+
height: '100%',
|
|
98
|
+
borderRadius: 'inherit',
|
|
99
|
+
backgroundColor: theme.value.colors[props.tone],
|
|
100
|
+
animationPlayState: hidden.value ? 'paused' : 'running',
|
|
101
|
+
},
|
|
102
|
+
}),
|
|
78
103
|
},
|
|
79
104
|
)
|
|
80
105
|
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { RangeHalo } from './RangeHalo.js'
|
|
2
|
+
import { computed, defineComponent, h, mergeProps, nextTick, useId, ref, watch } from 'vue'
|
|
3
|
+
import { moveRange, rangeValue, sliderScale, type RangeValue } from '@getcortexlabs/mavis-core'
|
|
4
|
+
import { rangeSliderProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
5
|
+
import { MColumn, MRow } from './layout.js'
|
|
6
|
+
import { MText } from './MText.js'
|
|
7
|
+
import { useHydrationEdit } from '../hydration.js'
|
|
8
|
+
export const MRangeSlider = defineComponent({
|
|
9
|
+
name: 'MRangeSlider',
|
|
10
|
+
inheritAttrs: false,
|
|
11
|
+
props: rangeSliderProps,
|
|
12
|
+
emits: { 'update:modelValue': (_value: RangeValue) => true },
|
|
13
|
+
setup(props, { attrs, emit }) {
|
|
14
|
+
const { theme } = useMavisTheme()
|
|
15
|
+
const id = `m-range-${useId()}`
|
|
16
|
+
const active = ref<number | null>(null)
|
|
17
|
+
watch(
|
|
18
|
+
() => props.disabled || props.readonly,
|
|
19
|
+
(blocked) => {
|
|
20
|
+
if (blocked) active.value = null
|
|
21
|
+
},
|
|
22
|
+
)
|
|
23
|
+
const pair = computed(() => rangeValue(props.modelValue, props.min, props.max, props.step))
|
|
24
|
+
const format = (value: number) => props.formatValue?.(value) ?? String(value)
|
|
25
|
+
const pending = useHydrationEdit(
|
|
26
|
+
(root) => {
|
|
27
|
+
if (props.disabled || props.readonly) return
|
|
28
|
+
const inputs = [...root.querySelectorAll<HTMLInputElement>('input[type="range"]')]
|
|
29
|
+
if (inputs.length !== 2) return
|
|
30
|
+
const scale = sliderScale(props.min, props.max, props.step)
|
|
31
|
+
if (
|
|
32
|
+
!inputs.every(
|
|
33
|
+
(input, thumb) => Number(input.defaultValue) === scale.toNative(pair.value[thumb]!),
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
return
|
|
37
|
+
if (inputs.every((input) => input.value === input.defaultValue)) return
|
|
38
|
+
const upper = scale.fromNative(inputs[1]!.valueAsNumber)
|
|
39
|
+
const value: [number, number] = [
|
|
40
|
+
Math.min(scale.fromNative(inputs[0]!.valueAsNumber), upper),
|
|
41
|
+
upper,
|
|
42
|
+
]
|
|
43
|
+
// Match the hydrated value attribute to the user's existing edit. Paint and
|
|
44
|
+
// accessible values update together after the owner accepts the pair.
|
|
45
|
+
inputs.forEach((input, thumb) => {
|
|
46
|
+
input.defaultValue = String(scale.toNative(value[thumb]!))
|
|
47
|
+
})
|
|
48
|
+
return value
|
|
49
|
+
},
|
|
50
|
+
(value) => emit('update:modelValue', value),
|
|
51
|
+
)
|
|
52
|
+
return () => {
|
|
53
|
+
const scale = sliderScale(props.min, props.max, props.step)
|
|
54
|
+
const shown = pending() ?? pair.value
|
|
55
|
+
const lower = scale.toNative(pair.value[0]),
|
|
56
|
+
upper = scale.toNative(pair.value[1])
|
|
57
|
+
return h(
|
|
58
|
+
MColumn,
|
|
59
|
+
mergeProps({ id: props.id, gap: 'sm' }, attrs, {
|
|
60
|
+
class: 'm-range-slider',
|
|
61
|
+
role: 'group',
|
|
62
|
+
'aria-labelledby': id,
|
|
63
|
+
style: {
|
|
64
|
+
'--m-range-color': theme.value.colors.primary,
|
|
65
|
+
'--m-range-track': theme.value.colors.border,
|
|
66
|
+
'--m-range-surface': theme.value.colors.surface,
|
|
67
|
+
'--m-range-from': `${(lower / scale.steps) * 100}%`,
|
|
68
|
+
'--m-range-to': `${(upper / scale.steps) * 100}%`,
|
|
69
|
+
},
|
|
70
|
+
}),
|
|
71
|
+
() => [
|
|
72
|
+
h(MRow, { justify: 'between', gap: 'md', wrap: true }, () => [
|
|
73
|
+
h(MText, { id, text: props.label, weight: '600' }),
|
|
74
|
+
h(MText, {
|
|
75
|
+
text: `${format(pair.value[0])} – ${format(pair.value[1])}`,
|
|
76
|
+
tone: 'muted',
|
|
77
|
+
}),
|
|
78
|
+
]),
|
|
79
|
+
h(
|
|
80
|
+
'div',
|
|
81
|
+
{ class: 'm-range-track' },
|
|
82
|
+
([0, 1] as const).flatMap((thumb) => [
|
|
83
|
+
h(RangeHalo, {
|
|
84
|
+
key: `halo:${thumb}`,
|
|
85
|
+
active: active.value === thumb && !props.disabled && !props.readonly,
|
|
86
|
+
position: scale.toNative(pair.value[thumb]) / scale.steps,
|
|
87
|
+
}),
|
|
88
|
+
h('input', {
|
|
89
|
+
key: thumb,
|
|
90
|
+
onFocus: () => {
|
|
91
|
+
active.value = thumb
|
|
92
|
+
},
|
|
93
|
+
onBlur: () => {
|
|
94
|
+
if (active.value === thumb) active.value = null
|
|
95
|
+
},
|
|
96
|
+
onPointerdown: () => {
|
|
97
|
+
active.value = thumb
|
|
98
|
+
},
|
|
99
|
+
onPointerup: () => {
|
|
100
|
+
active.value = null
|
|
101
|
+
},
|
|
102
|
+
onPointercancel: () => {
|
|
103
|
+
active.value = null
|
|
104
|
+
},
|
|
105
|
+
type: 'range',
|
|
106
|
+
min: 0,
|
|
107
|
+
max: scale.steps,
|
|
108
|
+
step: 1,
|
|
109
|
+
value: scale.toNative(shown[thumb]),
|
|
110
|
+
disabled: props.disabled,
|
|
111
|
+
'aria-readonly': props.readonly || undefined,
|
|
112
|
+
'aria-label': `${props.label}: ${thumb === 0 ? props.lowerLabel : props.upperLabel}`,
|
|
113
|
+
'aria-valuemin': thumb === 0 ? props.min : pair.value[0],
|
|
114
|
+
'aria-valuemax': thumb === 0 ? pair.value[1] : props.max,
|
|
115
|
+
'aria-valuenow': pair.value[thumb],
|
|
116
|
+
'aria-valuetext': format(pair.value[thumb]),
|
|
117
|
+
style: { zIndex: thumb === 0 && lower === scale.steps ? 3 : thumb + 1 },
|
|
118
|
+
onKeydown: (event: KeyboardEvent) => {
|
|
119
|
+
if (props.readonly) event.preventDefault()
|
|
120
|
+
},
|
|
121
|
+
onInput: (event: Event) => {
|
|
122
|
+
const input = event.target as HTMLInputElement
|
|
123
|
+
const next = moveRange(
|
|
124
|
+
pair.value,
|
|
125
|
+
thumb,
|
|
126
|
+
scale.fromNative(input.valueAsNumber),
|
|
127
|
+
props.min,
|
|
128
|
+
props.max,
|
|
129
|
+
props.step,
|
|
130
|
+
)
|
|
131
|
+
if (!props.disabled && !props.readonly && next[thumb] !== pair.value[thumb])
|
|
132
|
+
emit('update:modelValue', next)
|
|
133
|
+
void nextTick(() => {
|
|
134
|
+
input.value = String(scale.toNative(pair.value[thumb]))
|
|
135
|
+
})
|
|
136
|
+
},
|
|
137
|
+
}),
|
|
138
|
+
]),
|
|
139
|
+
),
|
|
140
|
+
],
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
})
|