@getcortexlabs/mavis-web 0.1.0-alpha.8 → 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 +7 -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 +16 -1
- 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 +5 -5
- package/dist/components/MAccordion.d.ts +2 -2
- 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 +6 -6
- package/dist/components/MButton.d.ts.map +1 -1
- package/dist/components/MButton.js +14 -8
- package/dist/components/MButton.js.map +1 -1
- package/dist/components/MCard.d.ts +8 -8
- package/dist/components/MCard.d.ts.map +1 -1
- package/dist/components/MCard.js +3 -2
- package/dist/components/MCard.js.map +1 -1
- package/dist/components/MCheckbox.d.ts +2 -2
- package/dist/components/MChip.d.ts +3 -3
- 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 +6 -6
- 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 +72 -24
- package/dist/components/MDatePicker.d.ts.map +1 -1
- package/dist/components/MDatePicker.js +2 -10
- package/dist/components/MDatePicker.js.map +1 -1
- 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 +3 -3
- 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 +174 -0
- package/dist/components/MGrid.d.ts.map +1 -0
- package/dist/components/MGrid.js +42 -0
- package/dist/components/MGrid.js.map +1 -0
- package/dist/components/MIcon.d.ts +2 -2
- package/dist/components/MIcon.d.ts.map +1 -1
- package/dist/components/MIcon.js +7 -4
- package/dist/components/MIcon.js.map +1 -1
- package/dist/components/MImage.d.ts +50 -5
- package/dist/components/MImage.d.ts.map +1 -1
- package/dist/components/MImage.js +31 -9
- 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 +11 -11
- package/dist/components/MInput.d.ts.map +1 -1
- package/dist/components/MInput.js +12 -0
- package/dist/components/MInput.js.map +1 -1
- package/dist/components/MLink.d.ts +1 -1
- package/dist/components/MLink.d.ts.map +1 -1
- package/dist/components/MLink.js +5 -33
- package/dist/components/MLink.js.map +1 -1
- package/dist/components/MListItem.d.ts +3 -3
- 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 +4 -4
- 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 +2 -2
- 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 +2 -2
- 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 +4 -4
- package/dist/components/MSeparator.d.ts +1 -1
- package/dist/components/MSheet.d.ts +16 -7
- package/dist/components/MSheet.d.ts.map +1 -1
- package/dist/components/MSheet.js +45 -14
- package/dist/components/MSheet.js.map +1 -1
- package/dist/components/MSkeleton.d.ts +3 -3
- package/dist/components/MStack.d.ts +25 -14
- package/dist/components/MStack.d.ts.map +1 -1
- package/dist/components/MStack.js +8 -14
- package/dist/components/MStack.js.map +1 -1
- package/dist/components/MSwitch.d.ts +2 -2
- package/dist/components/MTabs.d.ts +2 -2
- 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 +5 -5
- 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 +5 -5
- 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/content-width.d.ts +4 -0
- package/dist/content-width.d.ts.map +1 -0
- package/dist/content-width.js +62 -0
- package/dist/content-width.js.map +1 -0
- package/dist/date-format.d.ts +6 -0
- package/dist/date-format.d.ts.map +1 -0
- package/dist/date-format.js +23 -0
- package/dist/date-format.js.map +1 -0
- package/dist/icons.d.ts +14 -0
- package/dist/icons.d.ts.map +1 -0
- package/dist/icons.js +23 -0
- package/dist/icons.js.map +1 -0
- package/dist/image-effects.d.ts.map +1 -1
- package/dist/image-effects.js +2 -0
- package/dist/image-effects.js.map +1 -1
- package/dist/index.d.ts +23 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +49 -10
- 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 +16 -0
- package/dist/services.d.ts.map +1 -0
- package/dist/services.js +22 -0
- package/dist/services.js.map +1 -0
- package/package.json +23 -5
- package/src/animated-number.ts +59 -0
- package/src/base.css +1101 -0
- 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/MButton.ts +28 -25
- package/src/components/MCard.ts +3 -1
- package/src/components/MChip.ts +4 -2
- package/src/components/MCombobox.ts +136 -101
- package/src/components/MDatePicker.ts +1 -9
- 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 +69 -0
- package/src/components/MIcon.ts +7 -8
- package/src/components/MImage.ts +36 -12
- package/src/components/MImageCompare.ts +218 -0
- package/src/components/MImageViewer.ts +560 -0
- package/src/components/MInput.ts +14 -3
- package/src/components/MLink.ts +10 -32
- 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/MSheet.ts +47 -14
- package/src/components/MStack.ts +8 -20
- 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/content-width.ts +70 -0
- package/src/date-format.ts +36 -0
- package/src/icons.css +7 -0
- package/src/icons.ts +28 -0
- package/src/image-effects.ts +2 -0
- package/src/index.ts +143 -63
- 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 +39 -0
- package/src/style.css +2 -1000
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { computed, defineComponent, h, mergeProps, ref, useId, watch } from 'vue'
|
|
2
|
+
import { panelValue, positiveSize } from '@getcortexlabs/mavis-core'
|
|
3
|
+
import { resizablePanelsProps, usePartition, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
4
|
+
import { useAnimatedNumber } from '../animated-number.js'
|
|
5
|
+
import { usePartitionPointer } from '../partition-pointer.js'
|
|
6
|
+
import { MButton } from './MButton.js'
|
|
7
|
+
|
|
8
|
+
export const MResizablePanels = defineComponent({
|
|
9
|
+
name: 'MResizablePanels',
|
|
10
|
+
inheritAttrs: false,
|
|
11
|
+
props: resizablePanelsProps,
|
|
12
|
+
emits: { 'update:modelValue': (_value: number) => true, resize: (_value: number) => true },
|
|
13
|
+
setup(props, { attrs, slots, emit }) {
|
|
14
|
+
const { theme } = useMavisTheme()
|
|
15
|
+
const root = ref<HTMLElement>()
|
|
16
|
+
const primaryId = `m-panel-${useId()}`
|
|
17
|
+
const value = computed(() =>
|
|
18
|
+
panelValue(props.modelValue, props.min, props.max, props.collapsible),
|
|
19
|
+
)
|
|
20
|
+
let remembered = Math.max(props.min, 40)
|
|
21
|
+
const state = usePartition(
|
|
22
|
+
() => value.value,
|
|
23
|
+
() => ({
|
|
24
|
+
min: props.collapsible ? 0 : props.min,
|
|
25
|
+
max: props.max,
|
|
26
|
+
step: props.step,
|
|
27
|
+
disabled: props.disabled,
|
|
28
|
+
}),
|
|
29
|
+
(next) =>
|
|
30
|
+
emit('update:modelValue', next === 0 && props.collapsible ? 0 : Math.max(props.min, next)),
|
|
31
|
+
)
|
|
32
|
+
const shown = useAnimatedNumber(
|
|
33
|
+
() => value.value,
|
|
34
|
+
() => state.dragging.value,
|
|
35
|
+
)
|
|
36
|
+
const vertical = () => props.orientation === 'vertical'
|
|
37
|
+
function finish() {
|
|
38
|
+
state.end()
|
|
39
|
+
const closest = props.snap
|
|
40
|
+
.filter((point) => Number.isFinite(point) && point >= props.min && point <= props.max)
|
|
41
|
+
.sort((a, b) => Math.abs(a - value.value) - Math.abs(b - value.value))[0]
|
|
42
|
+
if (closest !== undefined && Math.abs(closest - value.value) <= 3)
|
|
43
|
+
emit('update:modelValue', closest)
|
|
44
|
+
emit(
|
|
45
|
+
'resize',
|
|
46
|
+
closest !== undefined && Math.abs(closest - value.value) <= 3 ? closest : value.value,
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
const gestures = usePartitionPointer({
|
|
50
|
+
...state,
|
|
51
|
+
value: () => value.value,
|
|
52
|
+
vertical,
|
|
53
|
+
direction: () => (props.direction === 'rtl' ? -1 : 1),
|
|
54
|
+
disabled: () => props.disabled,
|
|
55
|
+
bounds: () => {
|
|
56
|
+
const box = root.value?.getBoundingClientRect()
|
|
57
|
+
return box
|
|
58
|
+
? new DOMRect(
|
|
59
|
+
box.x,
|
|
60
|
+
box.y,
|
|
61
|
+
vertical() ? box.width : Math.max(1, box.width - 44),
|
|
62
|
+
vertical() ? Math.max(1, box.height - 44) : box.height,
|
|
63
|
+
)
|
|
64
|
+
: undefined
|
|
65
|
+
},
|
|
66
|
+
end: finish,
|
|
67
|
+
})
|
|
68
|
+
function toggle() {
|
|
69
|
+
if (!props.collapsible || props.disabled) return
|
|
70
|
+
if (value.value) {
|
|
71
|
+
remembered = value.value
|
|
72
|
+
emit('update:modelValue', 0)
|
|
73
|
+
} else emit('update:modelValue', Math.max(props.min, Math.min(props.max, remembered)))
|
|
74
|
+
}
|
|
75
|
+
watch(
|
|
76
|
+
() => [props.orientation, props.direction],
|
|
77
|
+
() => state.cancel(),
|
|
78
|
+
)
|
|
79
|
+
return () => {
|
|
80
|
+
const ratio = Math.max(0, Math.min(100, shown.value))
|
|
81
|
+
const tracks = `${ratio}fr 44px ${100 - ratio}fr`
|
|
82
|
+
return h(
|
|
83
|
+
'div',
|
|
84
|
+
mergeProps(attrs, {
|
|
85
|
+
class: 'm-resizable-panels',
|
|
86
|
+
role: 'group',
|
|
87
|
+
'aria-label': props.label,
|
|
88
|
+
}),
|
|
89
|
+
[
|
|
90
|
+
h(
|
|
91
|
+
'div',
|
|
92
|
+
{
|
|
93
|
+
ref: root,
|
|
94
|
+
dir: props.direction,
|
|
95
|
+
style: {
|
|
96
|
+
display: 'grid',
|
|
97
|
+
[vertical() ? 'gridTemplateRows' : 'gridTemplateColumns']: tracks,
|
|
98
|
+
height: `${positiveSize(props.height, 'height')}px`,
|
|
99
|
+
minWidth: 0,
|
|
100
|
+
overflow: 'hidden',
|
|
101
|
+
border: `1px solid ${theme.value.colors.border}`,
|
|
102
|
+
borderRadius: '16px',
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
[
|
|
106
|
+
h(
|
|
107
|
+
'section',
|
|
108
|
+
{
|
|
109
|
+
id: primaryId,
|
|
110
|
+
tabindex: value.value === 0 ? -1 : 0,
|
|
111
|
+
'aria-label': props.primaryLabel,
|
|
112
|
+
inert: value.value === 0 ? true : undefined,
|
|
113
|
+
style: {
|
|
114
|
+
minWidth: 0,
|
|
115
|
+
minHeight: 0,
|
|
116
|
+
overflow: 'auto',
|
|
117
|
+
visibility: ratio < 0.01 ? 'hidden' : undefined,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
slots.primary?.(),
|
|
121
|
+
),
|
|
122
|
+
h(
|
|
123
|
+
'div',
|
|
124
|
+
{
|
|
125
|
+
...gestures,
|
|
126
|
+
role: 'separator',
|
|
127
|
+
tabindex: props.disabled ? -1 : 0,
|
|
128
|
+
'aria-label': props.label,
|
|
129
|
+
'aria-orientation': vertical() ? 'horizontal' : 'vertical',
|
|
130
|
+
'aria-valuemin': props.collapsible ? 0 : props.min,
|
|
131
|
+
'aria-valuemax': props.max,
|
|
132
|
+
'aria-valuenow': value.value,
|
|
133
|
+
'aria-valuetext': `${Math.round(value.value)}%`,
|
|
134
|
+
'aria-controls': primaryId,
|
|
135
|
+
'aria-disabled': props.disabled || undefined,
|
|
136
|
+
style: {
|
|
137
|
+
display: 'grid',
|
|
138
|
+
placeItems: 'center',
|
|
139
|
+
cursor: props.disabled ? 'default' : vertical() ? 'row-resize' : 'col-resize',
|
|
140
|
+
touchAction: 'none',
|
|
141
|
+
background: theme.value.colors.elevated,
|
|
142
|
+
outlineOffset: '-3px',
|
|
143
|
+
},
|
|
144
|
+
onDblclick: toggle,
|
|
145
|
+
onKeydown: (event: KeyboardEvent) => {
|
|
146
|
+
if (props.disabled || event.altKey || event.ctrlKey || event.metaKey) return
|
|
147
|
+
const key = event.key
|
|
148
|
+
let next: number | undefined
|
|
149
|
+
if (key === 'Home') next = props.min
|
|
150
|
+
if (key === 'End') next = props.max
|
|
151
|
+
if (key === 'Enter' && props.collapsible) {
|
|
152
|
+
event.preventDefault()
|
|
153
|
+
toggle()
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
if (key === 'Escape') {
|
|
157
|
+
state.cancel()
|
|
158
|
+
return
|
|
159
|
+
}
|
|
160
|
+
const delta = vertical()
|
|
161
|
+
? key === 'ArrowDown'
|
|
162
|
+
? 1
|
|
163
|
+
: key === 'ArrowUp'
|
|
164
|
+
? -1
|
|
165
|
+
: 0
|
|
166
|
+
: (key === 'ArrowRight' ? 1 : key === 'ArrowLeft' ? -1 : 0) *
|
|
167
|
+
(props.direction === 'rtl' ? -1 : 1)
|
|
168
|
+
if (delta) next = value.value + delta * props.step * (event.shiftKey ? 5 : 1)
|
|
169
|
+
if (next !== undefined) {
|
|
170
|
+
event.preventDefault()
|
|
171
|
+
state.update(next)
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
h('span', {
|
|
176
|
+
'aria-hidden': 'true',
|
|
177
|
+
style: {
|
|
178
|
+
width: vertical() ? '28px' : '4px',
|
|
179
|
+
height: vertical() ? '4px' : '28px',
|
|
180
|
+
borderRadius: '4px',
|
|
181
|
+
background: theme.value.colors.muted,
|
|
182
|
+
},
|
|
183
|
+
}),
|
|
184
|
+
),
|
|
185
|
+
h(
|
|
186
|
+
'section',
|
|
187
|
+
{
|
|
188
|
+
tabindex: 0,
|
|
189
|
+
'aria-label': props.secondaryLabel,
|
|
190
|
+
style: { minWidth: 0, minHeight: 0, overflow: 'auto' },
|
|
191
|
+
},
|
|
192
|
+
slots.secondary?.(),
|
|
193
|
+
),
|
|
194
|
+
],
|
|
195
|
+
),
|
|
196
|
+
props.collapsible
|
|
197
|
+
? h(MButton, {
|
|
198
|
+
text: value.value ? props.collapseLabel : props.expandLabel,
|
|
199
|
+
variant: 'ghost',
|
|
200
|
+
disabled: props.disabled,
|
|
201
|
+
onClick: toggle,
|
|
202
|
+
})
|
|
203
|
+
: null,
|
|
204
|
+
],
|
|
205
|
+
)
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
})
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
segmentedEmits,
|
|
15
15
|
useMavisTheme,
|
|
16
16
|
} from '@getcortexlabs/mavis-core/vue'
|
|
17
|
+
import { useSelectionIndicator } from '../component-motion.js'
|
|
17
18
|
import { MColumn } from './layout.js'
|
|
18
19
|
|
|
19
20
|
export const MSegmentedControl = defineComponent({
|
|
@@ -25,6 +26,7 @@ export const MSegmentedControl = defineComponent({
|
|
|
25
26
|
useButtonAction()
|
|
26
27
|
const { theme } = useMavisTheme()
|
|
27
28
|
const controls = new Map<string, HTMLButtonElement>()
|
|
29
|
+
const indicator = useSelectionIndicator(() => controls.get(choiceKey(props.modelValue ?? '')))
|
|
28
30
|
let alive = true
|
|
29
31
|
onBeforeUnmount(() => {
|
|
30
32
|
alive = false
|
|
@@ -104,12 +106,14 @@ export const MSegmentedControl = defineComponent({
|
|
|
104
106
|
[
|
|
105
107
|
h('span', {
|
|
106
108
|
class: 'm-segmented-marker',
|
|
109
|
+
ref: indicator,
|
|
107
110
|
'aria-hidden': 'true',
|
|
108
111
|
style: {
|
|
109
112
|
background: colors.primarySoft,
|
|
110
113
|
visibility: index < 0 ? 'hidden' : 'visible',
|
|
111
|
-
width:
|
|
112
|
-
|
|
114
|
+
width: '100px',
|
|
115
|
+
transformOrigin: '0px 0px',
|
|
116
|
+
transition: 'none',
|
|
113
117
|
},
|
|
114
118
|
}),
|
|
115
119
|
...props.options.map((option) => {
|
package/src/components/MSheet.ts
CHANGED
|
@@ -51,6 +51,7 @@ const Sheet = defineComponent({
|
|
|
51
51
|
let motion: ReturnType<typeof sheetMotion> | undefined
|
|
52
52
|
const handle = ref<HTMLElement>()
|
|
53
53
|
let outside = false
|
|
54
|
+
let attached = true
|
|
54
55
|
let opener: HTMLElement | undefined
|
|
55
56
|
|
|
56
57
|
const announce = (reason: SheetCloseReason) => {
|
|
@@ -102,13 +103,41 @@ const Sheet = defineComponent({
|
|
|
102
103
|
first.focus()
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
|
-
//
|
|
106
|
-
function restoreFocus() {
|
|
107
|
-
const
|
|
106
|
+
// Restore only after native closure; WebKit can retain focus inside the departing panel.
|
|
107
|
+
function restoreFocus(element: HTMLDialogElement, reason: SheetCloseReason) {
|
|
108
|
+
const captured = opener
|
|
108
109
|
opener = undefined
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
const owner = element.ownerDocument
|
|
111
|
+
const active = owner.activeElement
|
|
112
|
+
// A route or another dialog may already own focus. Never take it back from them.
|
|
113
|
+
if (
|
|
114
|
+
active &&
|
|
115
|
+
active !== owner.body &&
|
|
116
|
+
active !== captured &&
|
|
117
|
+
active !== element &&
|
|
118
|
+
!element.contains(active)
|
|
119
|
+
)
|
|
120
|
+
return
|
|
121
|
+
const destination = props.returnFocus
|
|
122
|
+
const target =
|
|
123
|
+
destination === undefined
|
|
124
|
+
? captured
|
|
125
|
+
: typeof destination === 'string'
|
|
126
|
+
? owner.getElementById(destination)
|
|
127
|
+
: typeof destination === 'function'
|
|
128
|
+
? destination(reason)
|
|
129
|
+
: undefined
|
|
130
|
+
if (!target || !('isConnected' in target) || !target.isConnected) return
|
|
131
|
+
const control = target as HTMLElement
|
|
132
|
+
if (!owner.defaultView || !(control instanceof owner.defaultView.HTMLElement)) return
|
|
133
|
+
if (
|
|
134
|
+
element.contains(control) ||
|
|
135
|
+
control.closest('[inert], [hidden], [aria-hidden="true"]') ||
|
|
136
|
+
control.matches(':disabled') ||
|
|
137
|
+
!control.getClientRects().length
|
|
138
|
+
)
|
|
139
|
+
return
|
|
140
|
+
control.focus({ preventScroll: true })
|
|
112
141
|
}
|
|
113
142
|
function present() {
|
|
114
143
|
const current = ++generation
|
|
@@ -140,8 +169,7 @@ const Sheet = defineComponent({
|
|
|
140
169
|
motion = undefined
|
|
141
170
|
if (element.open) element.close()
|
|
142
171
|
presented.value = false
|
|
143
|
-
|
|
144
|
-
restoreFocus()
|
|
172
|
+
// Retain the opener until the queued native close event releases modal focus.
|
|
145
173
|
},
|
|
146
174
|
() => request('swipe'),
|
|
147
175
|
)
|
|
@@ -156,8 +184,7 @@ const Sheet = defineComponent({
|
|
|
156
184
|
else {
|
|
157
185
|
dialog.value?.close?.()
|
|
158
186
|
presented.value = false
|
|
159
|
-
|
|
160
|
-
restoreFocus()
|
|
187
|
+
// Restoration belongs to the native close event, after inertness is released.
|
|
161
188
|
}
|
|
162
189
|
}
|
|
163
190
|
watch(
|
|
@@ -181,26 +208,29 @@ const Sheet = defineComponent({
|
|
|
181
208
|
},
|
|
182
209
|
)
|
|
183
210
|
onActivated(() => {
|
|
211
|
+
attached = true
|
|
184
212
|
if (props.open && !presented.value) present()
|
|
185
213
|
})
|
|
186
214
|
onMounted(() => {
|
|
187
215
|
if (props.open) present()
|
|
188
216
|
})
|
|
189
217
|
onDeactivated(() => {
|
|
218
|
+
attached = false
|
|
190
219
|
generation++
|
|
191
220
|
motion?.dispose()
|
|
192
221
|
motion = undefined
|
|
222
|
+
opener = undefined
|
|
193
223
|
dialog.value?.close?.()
|
|
194
224
|
shown.value = presented.value = false
|
|
195
|
-
opener = undefined
|
|
196
225
|
if (props.open) announce('program')
|
|
197
226
|
})
|
|
198
227
|
onBeforeUnmount(() => {
|
|
228
|
+
attached = false
|
|
199
229
|
generation++
|
|
200
230
|
motion?.dispose()
|
|
201
231
|
motion = undefined
|
|
232
|
+
opener = undefined
|
|
202
233
|
dialog.value?.close?.()
|
|
203
|
-
restoreFocus()
|
|
204
234
|
})
|
|
205
235
|
|
|
206
236
|
return () => {
|
|
@@ -259,14 +289,17 @@ const Sheet = defineComponent({
|
|
|
259
289
|
},
|
|
260
290
|
onClose: () => {
|
|
261
291
|
// close events are queued: a previous dismissal can arrive after a rapid reopen.
|
|
262
|
-
if (dialog.value?.open) return
|
|
292
|
+
if (!attached || dialog.value?.open) return
|
|
263
293
|
// Closed by the browser itself: keep the bound state in step.
|
|
264
294
|
if (props.open && !closing) announce('escape')
|
|
265
295
|
motion?.dispose()
|
|
266
296
|
motion = undefined
|
|
267
297
|
shown.value = false
|
|
268
298
|
presented.value = false
|
|
269
|
-
|
|
299
|
+
const reason = closing ?? 'program'
|
|
300
|
+
closing = undefined
|
|
301
|
+
const element = dialog.value
|
|
302
|
+
if (element) restoreFocus(element, reason)
|
|
270
303
|
},
|
|
271
304
|
onKeydown: trapTab,
|
|
272
305
|
onPointerdown: (event: Event) => {
|
package/src/components/MStack.ts
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
defineComponent,
|
|
4
|
-
h,
|
|
5
|
-
mergeProps,
|
|
6
|
-
onBeforeUnmount,
|
|
7
|
-
onMounted,
|
|
8
|
-
provide,
|
|
9
|
-
shallowRef,
|
|
10
|
-
} from 'vue'
|
|
1
|
+
import { useMotionRegion } from '../motion-region.js'
|
|
2
|
+
import { computed, defineComponent, h, mergeProps, provide, shallowRef } from 'vue'
|
|
11
3
|
import { resolveSpace, stackLayout } from '@getcortexlabs/mavis-core'
|
|
12
4
|
import {
|
|
13
5
|
stackProps,
|
|
14
6
|
layoutDirection,
|
|
15
7
|
useLayoutShrink,
|
|
16
8
|
useMavisTheme,
|
|
9
|
+
useComponentLayout,
|
|
17
10
|
viewAttrs,
|
|
18
11
|
} from '@getcortexlabs/mavis-core/vue'
|
|
19
12
|
import { boxStyle, webAttrs } from '../style.js'
|
|
13
|
+
import { useContentWidth } from '../content-width.js'
|
|
20
14
|
|
|
21
15
|
const align = {
|
|
22
16
|
start: 'flex-start',
|
|
@@ -40,7 +34,7 @@ export const MStack = defineComponent({
|
|
|
40
34
|
const { theme } = useMavisTheme()
|
|
41
35
|
const shrink = useLayoutShrink()
|
|
42
36
|
const element = shallowRef<HTMLElement>()
|
|
43
|
-
const width =
|
|
37
|
+
const width = useContentWidth(element, () => props.responsive !== undefined)
|
|
44
38
|
const layout = computed(() =>
|
|
45
39
|
stackLayout(
|
|
46
40
|
{
|
|
@@ -54,22 +48,16 @@ export const MStack = defineComponent({
|
|
|
54
48
|
width.value,
|
|
55
49
|
),
|
|
56
50
|
)
|
|
51
|
+
const automatic = useComponentLayout(() => JSON.stringify(layout.value), false)
|
|
52
|
+
const motion = useMotionRegion(() => props.motionRegion ?? automatic)
|
|
57
53
|
const direction = computed(() => layout.value.direction ?? props.direction)
|
|
58
54
|
provide(layoutDirection, direction)
|
|
59
|
-
let observer: ResizeObserver | undefined
|
|
60
|
-
onMounted(() => {
|
|
61
|
-
if (!element.value || typeof ResizeObserver === 'undefined') return
|
|
62
|
-
observer = new ResizeObserver(([entry]) => {
|
|
63
|
-
if (entry) width.value = entry.contentRect.width
|
|
64
|
-
})
|
|
65
|
-
observer.observe(element.value)
|
|
66
|
-
})
|
|
67
|
-
onBeforeUnmount(() => observer?.disconnect())
|
|
68
55
|
return () =>
|
|
69
56
|
h(
|
|
70
57
|
'div',
|
|
71
58
|
mergeProps(
|
|
72
59
|
{
|
|
60
|
+
...motion,
|
|
73
61
|
ref: element,
|
|
74
62
|
class: 'm-stack',
|
|
75
63
|
style: {
|
package/src/components/MTabs.ts
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
type TabPanelProps,
|
|
25
25
|
} from '@getcortexlabs/mavis-core'
|
|
26
26
|
import { useButtonAction, tabsProps, tabsEmits, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
27
|
+
import { useSelectionIndicator } from '../component-motion.js'
|
|
27
28
|
import { MColumn } from './layout.js'
|
|
28
29
|
|
|
29
30
|
const TabPanel = defineComponent({
|
|
@@ -52,6 +53,9 @@ export const MTabs = defineComponent({
|
|
|
52
53
|
validateTabs(props.tabs, props.modelValue, props.label)
|
|
53
54
|
return props.tabs.find((tab) => tab.value === props.modelValue)
|
|
54
55
|
})
|
|
56
|
+
const indicator = useSelectionIndicator(
|
|
57
|
+
() => selected.value && controls.get(choiceKey(selected.value.value)),
|
|
58
|
+
)
|
|
55
59
|
let observer: ResizeObserver | undefined
|
|
56
60
|
let frame: number | undefined
|
|
57
61
|
let alive = false
|
|
@@ -216,12 +220,14 @@ export const MTabs = defineComponent({
|
|
|
216
220
|
),
|
|
217
221
|
h('span', {
|
|
218
222
|
class: 'm-tabs-indicator',
|
|
223
|
+
ref: indicator,
|
|
219
224
|
'aria-hidden': 'true',
|
|
220
225
|
style: {
|
|
221
226
|
backgroundColor: colors.primary,
|
|
222
|
-
|
|
223
|
-
width:
|
|
224
|
-
|
|
227
|
+
|
|
228
|
+
width: '100px',
|
|
229
|
+
transformOrigin: '0px 0px',
|
|
230
|
+
transition: 'none',
|
|
225
231
|
},
|
|
226
232
|
}),
|
|
227
233
|
],
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { defineComponent, h } from 'vue'
|
|
2
|
+
import { createTimePicker, timePickerProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
3
|
+
import { localTime, timeMinutes, timeOptions } from '@getcortexlabs/mavis-core'
|
|
4
|
+
import { MInput } from './MInput.js'
|
|
5
|
+
import { MColumn, MRow } from './layout.js'
|
|
6
|
+
import { MButton } from './MButton.js'
|
|
7
|
+
import { MText } from './MText.js'
|
|
8
|
+
import { MSheet } from './MSheet.js'
|
|
9
|
+
|
|
10
|
+
const TimeFields = defineComponent({
|
|
11
|
+
props: timePickerProps,
|
|
12
|
+
emits: ['update:modelValue'],
|
|
13
|
+
setup(props, { emit }) {
|
|
14
|
+
const { theme } = useMavisTheme()
|
|
15
|
+
// Browser-native selects keep hour/minute selection within the current sheet.
|
|
16
|
+
function field(
|
|
17
|
+
label: string,
|
|
18
|
+
value: string | number,
|
|
19
|
+
options: { value: string | number; label: string }[],
|
|
20
|
+
change: (value: string) => void,
|
|
21
|
+
) {
|
|
22
|
+
const { colors, radius } = theme.value
|
|
23
|
+
return h(
|
|
24
|
+
'label',
|
|
25
|
+
{
|
|
26
|
+
class: 'm-time-part',
|
|
27
|
+
style: {
|
|
28
|
+
display: 'flex',
|
|
29
|
+
flexDirection: 'column',
|
|
30
|
+
gap: '8px',
|
|
31
|
+
flex: '1 1 80px',
|
|
32
|
+
minWidth: 0,
|
|
33
|
+
font: 'inherit',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
[
|
|
37
|
+
h('span', { style: { fontSize: '14px', fontWeight: 600 } }, label),
|
|
38
|
+
h(
|
|
39
|
+
'select',
|
|
40
|
+
{
|
|
41
|
+
value: String(value),
|
|
42
|
+
style: {
|
|
43
|
+
boxSizing: 'border-box',
|
|
44
|
+
width: '100%',
|
|
45
|
+
minHeight: '48px',
|
|
46
|
+
padding: '8px',
|
|
47
|
+
font: 'inherit',
|
|
48
|
+
background: colors.surface,
|
|
49
|
+
color: colors.text,
|
|
50
|
+
border: `1px solid ${colors.border}`,
|
|
51
|
+
borderRadius: `${radius.md}px`,
|
|
52
|
+
colorScheme: theme.value.appearance,
|
|
53
|
+
},
|
|
54
|
+
onChange: (event: Event) => change((event.target as HTMLSelectElement).value),
|
|
55
|
+
},
|
|
56
|
+
options.map((option) =>
|
|
57
|
+
h('option', { key: option.value, value: String(option.value) }, option.label),
|
|
58
|
+
),
|
|
59
|
+
),
|
|
60
|
+
],
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
return () => {
|
|
64
|
+
const { cycle, step } = timeOptions(props)
|
|
65
|
+
const minutes = timeMinutes(props.modelValue ?? '00:00')
|
|
66
|
+
const hour = Math.floor(minutes / 60)
|
|
67
|
+
const twelve = cycle === 'h12'
|
|
68
|
+
return h(MRow, { gap: 'sm', wrap: true }, () => [
|
|
69
|
+
field(
|
|
70
|
+
props.hourLabel,
|
|
71
|
+
twelve ? hour % 12 || 12 : hour,
|
|
72
|
+
Array.from({ length: twelve ? 12 : 24 }, (_, i) => ({
|
|
73
|
+
value: twelve ? i + 1 : i,
|
|
74
|
+
label: String(twelve ? i + 1 : i).padStart(2, '0'),
|
|
75
|
+
})),
|
|
76
|
+
(value) =>
|
|
77
|
+
emit(
|
|
78
|
+
'update:modelValue',
|
|
79
|
+
localTime(
|
|
80
|
+
(twelve ? (Number(value) % 12) + (hour >= 12 ? 12 : 0) : Number(value)) * 60 +
|
|
81
|
+
(minutes % 60),
|
|
82
|
+
),
|
|
83
|
+
),
|
|
84
|
+
),
|
|
85
|
+
field(
|
|
86
|
+
props.minuteLabel,
|
|
87
|
+
minutes % 60,
|
|
88
|
+
Array.from({ length: 60 / step }, (_, i) => ({
|
|
89
|
+
value: i * step,
|
|
90
|
+
label: String(i * step).padStart(2, '0'),
|
|
91
|
+
})),
|
|
92
|
+
(value) => emit('update:modelValue', localTime(hour * 60 + Number(value))),
|
|
93
|
+
),
|
|
94
|
+
twelve
|
|
95
|
+
? field(
|
|
96
|
+
props.periodLabel,
|
|
97
|
+
hour >= 12 ? 'PM' : 'AM',
|
|
98
|
+
[
|
|
99
|
+
{ value: 'AM', label: 'AM' },
|
|
100
|
+
{ value: 'PM', label: 'PM' },
|
|
101
|
+
],
|
|
102
|
+
(value) =>
|
|
103
|
+
emit(
|
|
104
|
+
'update:modelValue',
|
|
105
|
+
localTime(((hour % 12) + (value === 'PM' ? 12 : 0)) * 60 + (minutes % 60)),
|
|
106
|
+
),
|
|
107
|
+
)
|
|
108
|
+
: null,
|
|
109
|
+
])
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
})
|
|
113
|
+
export const MTimePicker = createTimePicker(
|
|
114
|
+
{
|
|
115
|
+
Input: MInput,
|
|
116
|
+
Column: MColumn,
|
|
117
|
+
Row: MRow,
|
|
118
|
+
Button: MButton,
|
|
119
|
+
Text: MText,
|
|
120
|
+
Sheet: MSheet,
|
|
121
|
+
Picker: TimeFields,
|
|
122
|
+
},
|
|
123
|
+
'web',
|
|
124
|
+
)
|
package/src/components/MToast.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
useToastHost,
|
|
19
19
|
} from '@getcortexlabs/mavis-core/vue'
|
|
20
20
|
import type { IconName, ToastTone } from '@getcortexlabs/mavis-core'
|
|
21
|
+
import { useComponentTransition } from '../component-motion.js'
|
|
21
22
|
import { MIcon } from './MIcon.js'
|
|
22
23
|
|
|
23
24
|
const icons: Record<ToastTone, IconName> = {
|
|
@@ -35,6 +36,7 @@ export const MToast = defineComponent({
|
|
|
35
36
|
setup(props) {
|
|
36
37
|
useButtonAction()
|
|
37
38
|
const { theme } = useMavisTheme()
|
|
39
|
+
const transition = useComponentTransition(-8)
|
|
38
40
|
const host = useToastHost(() => props.controller)
|
|
39
41
|
const mounted = ref(false)
|
|
40
42
|
const covered = ref(false)
|
|
@@ -131,6 +133,7 @@ export const MToast = defineComponent({
|
|
|
131
133
|
h(
|
|
132
134
|
Transition,
|
|
133
135
|
{
|
|
136
|
+
...transition,
|
|
134
137
|
name: 'm-toast',
|
|
135
138
|
appear: true,
|
|
136
139
|
onBeforeEnter: () => {
|
|
@@ -157,7 +160,8 @@ export const MToast = defineComponent({
|
|
|
157
160
|
host.pause('hover', false)
|
|
158
161
|
host.pause('focus', false)
|
|
159
162
|
},
|
|
160
|
-
onAfterLeave: () => {
|
|
163
|
+
onAfterLeave: (element: Element) => {
|
|
164
|
+
transition.onAfterLeave(element)
|
|
161
165
|
if (message) host.left(message.id)
|
|
162
166
|
},
|
|
163
167
|
},
|