@getcortexlabs/mavis-web 0.1.0-alpha.8 → 0.1.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/components/DateCalendar.d.ts +1 -1
- package/dist/components/LoadingDecoration.d.ts +2 -2
- package/dist/components/MAccordion.d.ts +1 -1
- package/dist/components/MAlert.d.ts +2 -2
- package/dist/components/MAvatar.d.ts +1 -1
- package/dist/components/MBadge.d.ts +1 -1
- package/dist/components/MButton.d.ts +5 -5
- 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 +3 -3
- 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 +1 -1
- package/dist/components/MChip.d.ts +2 -2
- package/dist/components/MCombobox.d.ts +1 -1
- package/dist/components/MDatePicker.d.ts +56 -8
- 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/MEmptyState.d.ts +2 -2
- package/dist/components/MGrid.d.ts +163 -0
- package/dist/components/MGrid.d.ts.map +1 -0
- package/dist/components/MGrid.js +32 -0
- package/dist/components/MGrid.js.map +1 -0
- package/dist/components/MIcon.d.ts +1 -1
- 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 +48 -3
- package/dist/components/MImage.d.ts.map +1 -1
- package/dist/components/MImage.js +23 -8
- package/dist/components/MImage.js.map +1 -1
- package/dist/components/MInput.d.ts +7 -7
- package/dist/components/MInput.d.ts.map +1 -1
- package/dist/components/MInput.js +7 -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 +1 -1
- package/dist/components/MProgress.d.ts +2 -2
- package/dist/components/MRadioGroup.d.ts +1 -1
- package/dist/components/MReveal.d.ts +3 -3
- package/dist/components/MSegmentedControl.d.ts +1 -1
- package/dist/components/MSelect.d.ts +1 -1
- package/dist/components/MSheet.d.ts +10 -1
- 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 +1 -1
- package/dist/components/MStack.d.ts +3 -3
- package/dist/components/MStack.d.ts.map +1 -1
- package/dist/components/MStack.js +3 -13
- 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/MText.d.ts +2 -2
- package/dist/components/configurator.d.ts +3 -3
- package/dist/components/layout.d.ts +12 -12
- 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 +11 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -10
- package/dist/index.js.map +1 -1
- package/dist/services.d.ts +16 -0
- package/dist/services.d.ts.map +1 -0
- package/dist/services.js +18 -0
- package/dist/services.js.map +1 -0
- package/package.json +21 -3
- package/src/base.css +992 -0
- package/src/components/MButton.ts +28 -25
- package/src/components/MCard.ts +3 -1
- package/src/components/MDatePicker.ts +1 -9
- package/src/components/MGrid.ts +45 -0
- package/src/components/MIcon.ts +7 -8
- package/src/components/MImage.ts +26 -11
- package/src/components/MInput.ts +9 -3
- package/src/components/MLink.ts +10 -32
- package/src/components/MSheet.ts +47 -14
- package/src/components/MStack.ts +3 -20
- 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 +63 -63
- package/src/services.ts +33 -0
- package/src/style.css +2 -1000
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useIconContent } from '../icons.js'
|
|
1
2
|
import { defineComponent, h, mergeProps, type VNode, type SlotsType } from 'vue'
|
|
2
3
|
import {
|
|
3
4
|
useButtonAction,
|
|
@@ -5,6 +6,7 @@ import {
|
|
|
5
6
|
buttonContent,
|
|
6
7
|
ButtonAdornment,
|
|
7
8
|
useMavisTheme,
|
|
9
|
+
useNavigationOptions,
|
|
8
10
|
actionEmits,
|
|
9
11
|
textContent,
|
|
10
12
|
useLayoutShrink,
|
|
@@ -15,8 +17,6 @@ import {
|
|
|
15
17
|
resolveRadius,
|
|
16
18
|
shadowStyle,
|
|
17
19
|
nonNegative,
|
|
18
|
-
iconGlyph,
|
|
19
|
-
iconFontFamily,
|
|
20
20
|
iconSizes,
|
|
21
21
|
checkIconOnly,
|
|
22
22
|
} from '@getcortexlabs/mavis-core'
|
|
@@ -38,6 +38,8 @@ export const MButton = defineComponent({
|
|
|
38
38
|
setup(props, { attrs, slots, emit }) {
|
|
39
39
|
useButtonAction()
|
|
40
40
|
const { theme } = useMavisTheme()
|
|
41
|
+
const navigation = useNavigationOptions(props)
|
|
42
|
+
const renderIcon = useIconContent()
|
|
41
43
|
const lifecycle = usePressFeedback(
|
|
42
44
|
() => !props.disabled && !props.loading,
|
|
43
45
|
theme,
|
|
@@ -61,28 +63,29 @@ export const MButton = defineComponent({
|
|
|
61
63
|
checkIconOnly(text, hasIcon, props.accessibilityLabel)
|
|
62
64
|
const iconSize = iconSizes[props.size]
|
|
63
65
|
const paddingX = hasIcon && !text ? Math.round((size.height - iconSize) / 2) : size.padding
|
|
64
|
-
const span = (name: typeof props.icon) =>
|
|
65
|
-
name
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
66
|
+
const span = (name: typeof props.icon) => {
|
|
67
|
+
if (!name) return null
|
|
68
|
+
const icon = renderIcon(name, iconSize)
|
|
69
|
+
return h(
|
|
70
|
+
'span',
|
|
71
|
+
{
|
|
72
|
+
class: 'm-icon',
|
|
73
|
+
'aria-hidden': 'true',
|
|
74
|
+
style: {
|
|
75
|
+
fontFamily: icon.fontFamily,
|
|
76
|
+
fontSize: `${iconSize}px`,
|
|
77
|
+
width: `${iconSize}px`,
|
|
78
|
+
height: `${iconSize}px`,
|
|
79
|
+
lineHeight: 1,
|
|
80
|
+
display: 'inline-flex',
|
|
81
|
+
alignItems: 'center',
|
|
82
|
+
justifyContent: 'center',
|
|
83
|
+
flexShrink: 0,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
icon.content,
|
|
87
|
+
)
|
|
88
|
+
}
|
|
86
89
|
return h(
|
|
87
90
|
props.href === undefined ? 'button' : 'a',
|
|
88
91
|
mergeProps(
|
|
@@ -140,7 +143,7 @@ export const MButton = defineComponent({
|
|
|
140
143
|
props.href === undefined
|
|
141
144
|
? {}
|
|
142
145
|
: navigationAttrs(
|
|
143
|
-
|
|
146
|
+
navigation(),
|
|
144
147
|
props.disabled || props.loading,
|
|
145
148
|
() => emit('click'),
|
|
146
149
|
(error) => emit('error', error),
|
package/src/components/MCard.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
useButtonAction,
|
|
6
6
|
cardProps,
|
|
7
7
|
useMavisTheme,
|
|
8
|
+
useNavigationOptions,
|
|
8
9
|
actionEmits,
|
|
9
10
|
} from '@getcortexlabs/mavis-core/vue'
|
|
10
11
|
import { MColumn, createLayout } from './layout.js'
|
|
@@ -21,6 +22,7 @@ export const MCard = defineComponent({
|
|
|
21
22
|
setup(props, { attrs, slots, emit }) {
|
|
22
23
|
useButtonAction(() => props.interactive || props.href !== undefined)
|
|
23
24
|
const { theme } = useMavisTheme()
|
|
25
|
+
const navigation = useNavigationOptions(props)
|
|
24
26
|
const element = shallowRef<HTMLElement>()
|
|
25
27
|
const lifecycle = usePressFeedback(
|
|
26
28
|
() => (props.interactive || props.href !== undefined) && !props.disabled,
|
|
@@ -92,7 +94,7 @@ export const MCard = defineComponent({
|
|
|
92
94
|
style: preserveBoundPaint(element.value),
|
|
93
95
|
},
|
|
94
96
|
href !== undefined
|
|
95
|
-
? navigationAttrs(
|
|
97
|
+
? navigationAttrs(navigation(), disabled, activate, (error) => emit('error', error))
|
|
96
98
|
: interactive
|
|
97
99
|
? {
|
|
98
100
|
role: 'button',
|
|
@@ -6,8 +6,7 @@ import { MSheet } from './MSheet.js'
|
|
|
6
6
|
import { DateCalendar } from './DateCalendar.js'
|
|
7
7
|
|
|
8
8
|
function focusOpener(opener: unknown) {
|
|
9
|
-
|
|
10
|
-
element?.focus?.({ preventScroll: true })
|
|
9
|
+
;(opener as { focusAction?: () => void } | undefined)?.focusAction?.()
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
export const { MDatePicker, MDateRangePicker } = createDatePickers({
|
|
@@ -18,13 +17,6 @@ export const { MDatePicker, MDateRangePicker } = createDatePickers({
|
|
|
18
17
|
Sheet: MSheet,
|
|
19
18
|
Calendar: DateCalendar,
|
|
20
19
|
deferActions: true,
|
|
21
|
-
openerAttrs: {
|
|
22
|
-
// Safari does not focus buttons on pointer activation. Capture the actual trigger
|
|
23
|
-
// before the Sheet snapshots focus; keyboard activation already has the right owner.
|
|
24
|
-
onMousedown(event: MouseEvent) {
|
|
25
|
-
if (event.button === 0) (event.currentTarget as HTMLElement).focus({ preventScroll: true })
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
20
|
beforeOpen: focusOpener,
|
|
29
21
|
// MSheet restores the Web opener after its close animation.
|
|
30
22
|
afterClose: () => {},
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { defineComponent, h, mergeProps, provide, shallowRef } from 'vue'
|
|
2
|
+
import { gridColumns, resolveSpace } from '@getcortexlabs/mavis-core'
|
|
3
|
+
import {
|
|
4
|
+
gridProps,
|
|
5
|
+
layoutDirection,
|
|
6
|
+
useLayoutShrink,
|
|
7
|
+
useMavisTheme,
|
|
8
|
+
viewAttrs,
|
|
9
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
10
|
+
import { boxStyle, webAttrs } from '../style.js'
|
|
11
|
+
import { useContentWidth } from '../content-width.js'
|
|
12
|
+
|
|
13
|
+
export const MGrid = defineComponent({
|
|
14
|
+
name: 'MGrid',
|
|
15
|
+
inheritAttrs: false,
|
|
16
|
+
props: gridProps,
|
|
17
|
+
setup(props, { attrs, slots }) {
|
|
18
|
+
const { theme } = useMavisTheme()
|
|
19
|
+
const shrink = useLayoutShrink()
|
|
20
|
+
provide(layoutDirection, 'column')
|
|
21
|
+
const element = shallowRef<HTMLElement>()
|
|
22
|
+
const width = useContentWidth(element, () => props.minColumnWidth !== undefined)
|
|
23
|
+
return () => {
|
|
24
|
+
const gap = resolveSpace(theme.value, props.gap ?? 'none')
|
|
25
|
+
const columns = gridColumns(props.columns, props.minColumnWidth, gap, width.value)
|
|
26
|
+
return h(
|
|
27
|
+
'div',
|
|
28
|
+
mergeProps(
|
|
29
|
+
{
|
|
30
|
+
ref: element,
|
|
31
|
+
class: 'm-grid',
|
|
32
|
+
style: {
|
|
33
|
+
...boxStyle(theme.value, props, shrink.value),
|
|
34
|
+
display: 'grid',
|
|
35
|
+
gap: `${gap}px`,
|
|
36
|
+
gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
webAttrs({ ...attrs, ...viewAttrs(props) }),
|
|
40
|
+
),
|
|
41
|
+
slots.default?.(),
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
})
|
package/src/components/MIcon.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { useIconContent } from '../icons.js'
|
|
1
2
|
import { defineComponent, h, mergeProps } from 'vue'
|
|
2
3
|
import { iconProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
3
|
-
import {
|
|
4
|
+
import { resolveIconSize } from '@getcortexlabs/mavis-core'
|
|
4
5
|
import { webAttrs } from '../style.js'
|
|
5
6
|
import { useMotionSurface } from '../use-motion-surface.js'
|
|
6
7
|
|
|
@@ -10,8 +11,10 @@ export const MIcon = defineComponent({
|
|
|
10
11
|
props: iconProps,
|
|
11
12
|
setup(props, { attrs }) {
|
|
12
13
|
const { theme } = useMavisTheme()
|
|
14
|
+
const renderIcon = useIconContent()
|
|
13
15
|
const motion = useMotionSurface(() => props.motionSurface)
|
|
14
16
|
return () => {
|
|
17
|
+
const icon = renderIcon(props.name, resolveIconSize(props.size))
|
|
15
18
|
const size = `${resolveIconSize(props.size)}px`
|
|
16
19
|
return h(
|
|
17
20
|
'span',
|
|
@@ -20,7 +23,7 @@ export const MIcon = defineComponent({
|
|
|
20
23
|
{
|
|
21
24
|
class: 'm-icon',
|
|
22
25
|
style: {
|
|
23
|
-
fontFamily:
|
|
26
|
+
fontFamily: icon.fontFamily,
|
|
24
27
|
fontSize: size,
|
|
25
28
|
width: size,
|
|
26
29
|
height: size,
|
|
@@ -36,12 +39,8 @@ export const MIcon = defineComponent({
|
|
|
36
39
|
props.label ? { role: 'img', 'aria-label': props.label } : { 'aria-hidden': 'true' },
|
|
37
40
|
),
|
|
38
41
|
props.motionSurface
|
|
39
|
-
? h(
|
|
40
|
-
|
|
41
|
-
{ 'data-jolt-symbol-layer': '', 'aria-hidden': 'true' },
|
|
42
|
-
iconGlyph(props.name),
|
|
43
|
-
)
|
|
44
|
-
: iconGlyph(props.name),
|
|
42
|
+
? h('span', { 'data-jolt-symbol-layer': '', 'aria-hidden': 'true' }, icon.content)
|
|
43
|
+
: icon.content,
|
|
45
44
|
)
|
|
46
45
|
}
|
|
47
46
|
},
|
package/src/components/MImage.ts
CHANGED
|
@@ -26,9 +26,13 @@ export const MImage = defineComponent({
|
|
|
26
26
|
status.value === 'ready' ? props.motionSurface : undefined,
|
|
27
27
|
)
|
|
28
28
|
watch(
|
|
29
|
-
() => props.src,
|
|
30
|
-
() => {
|
|
31
|
-
if (
|
|
29
|
+
() => [props.src, props.srcset, props.sizes] as const,
|
|
30
|
+
(selection, previous) => {
|
|
31
|
+
if (
|
|
32
|
+
props.src === committing &&
|
|
33
|
+
selection[1] === previous?.[1] &&
|
|
34
|
+
selection[2] === previous?.[2]
|
|
35
|
+
) {
|
|
32
36
|
committing = undefined
|
|
33
37
|
return
|
|
34
38
|
}
|
|
@@ -47,9 +51,13 @@ export const MImage = defineComponent({
|
|
|
47
51
|
throw new RangeError('aspectRatio must be finite and positive.')
|
|
48
52
|
const current = generation,
|
|
49
53
|
src = props.src
|
|
50
|
-
const settle = (success: boolean) => {
|
|
51
|
-
if (!alive || current !== generation
|
|
52
|
-
|
|
54
|
+
const settle = (success: boolean, candidate?: string) => {
|
|
55
|
+
if (!alive || current !== generation) return
|
|
56
|
+
// The browser can select another srcset candidate without changing any Vue prop.
|
|
57
|
+
if (candidate !== undefined && currentImage?.currentSrc !== candidate) return
|
|
58
|
+
const next = success ? 'ready' : 'error'
|
|
59
|
+
if (status.value === next) return
|
|
60
|
+
status.value = next
|
|
53
61
|
if (success) emit('load', src)
|
|
54
62
|
else emit('error', src)
|
|
55
63
|
}
|
|
@@ -81,15 +89,21 @@ export const MImage = defineComponent({
|
|
|
81
89
|
? h('img', {
|
|
82
90
|
key: current,
|
|
83
91
|
src,
|
|
92
|
+
srcset: props.srcset,
|
|
93
|
+
sizes: props.sizes,
|
|
94
|
+
loading: props.loading,
|
|
95
|
+
decoding: props.decoding,
|
|
96
|
+
fetchpriority: props.fetchpriority,
|
|
84
97
|
alt: props.alt,
|
|
85
98
|
onLoad: (event: Event) => {
|
|
86
99
|
const target = event.target as HTMLImageElement
|
|
100
|
+
const candidate = target?.currentSrc
|
|
87
101
|
if (target?.decode)
|
|
88
102
|
void target.decode().then(
|
|
89
|
-
() => settle(true),
|
|
90
|
-
() => settle(false),
|
|
103
|
+
() => settle(true, candidate),
|
|
104
|
+
() => settle(false, candidate),
|
|
91
105
|
)
|
|
92
|
-
else settle(true)
|
|
106
|
+
else settle(true, candidate)
|
|
93
107
|
},
|
|
94
108
|
onError: () => settle(false),
|
|
95
109
|
onVnodeMounted: (node) => {
|
|
@@ -117,10 +131,11 @@ export const MImage = defineComponent({
|
|
|
117
131
|
})
|
|
118
132
|
motion.onVnodeMounted(node)
|
|
119
133
|
if (image.complete) {
|
|
134
|
+
const candidate = image.currentSrc
|
|
120
135
|
if (image.naturalWidth && image.decode)
|
|
121
136
|
void image.decode().then(
|
|
122
|
-
() => settle(true),
|
|
123
|
-
() => settle(false),
|
|
137
|
+
() => settle(true, candidate),
|
|
138
|
+
() => settle(false, candidate),
|
|
124
139
|
)
|
|
125
140
|
else settle(image.naturalWidth > 0)
|
|
126
141
|
}
|
package/src/components/MInput.ts
CHANGED
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
validateInput,
|
|
27
27
|
iconSizes,
|
|
28
28
|
inputActionSize,
|
|
29
|
-
type
|
|
29
|
+
type InputActionHandle,
|
|
30
30
|
} from '@getcortexlabs/mavis-core'
|
|
31
31
|
import { length, webAttrs } from '../style.js'
|
|
32
32
|
import { MIcon } from './MIcon.js'
|
|
@@ -46,6 +46,7 @@ const Input = defineComponent({
|
|
|
46
46
|
const shrink = useLayoutShrink()
|
|
47
47
|
const generatedId = `m-input-${useId()}`
|
|
48
48
|
const editor = ref<HTMLInputElement | HTMLTextAreaElement>()
|
|
49
|
+
const actionButton = ref<{ $el?: HTMLElement }>()
|
|
49
50
|
const focused = ref(false)
|
|
50
51
|
const hydrationEdit = useHydrationEdit(
|
|
51
52
|
(root) => {
|
|
@@ -141,11 +142,15 @@ const Input = defineComponent({
|
|
|
141
142
|
},
|
|
142
143
|
)
|
|
143
144
|
expose({
|
|
145
|
+
focusAction: () => {
|
|
146
|
+
if (props.disabled || props.readonly || props.trailingAction?.disabled) return
|
|
147
|
+
actionButton.value?.$el?.focus?.({ preventScroll: true })
|
|
148
|
+
},
|
|
144
149
|
focus: () => {
|
|
145
150
|
if (!props.disabled) editor.value?.focus()
|
|
146
151
|
},
|
|
147
152
|
blur: () => editor.value?.blur(),
|
|
148
|
-
} satisfies
|
|
153
|
+
} satisfies InputActionHandle)
|
|
149
154
|
|
|
150
155
|
return () => {
|
|
151
156
|
validateInput(props)
|
|
@@ -303,6 +308,7 @@ const Input = defineComponent({
|
|
|
303
308
|
icon(props.trailingIcon, true),
|
|
304
309
|
action
|
|
305
310
|
? h(MButton, {
|
|
311
|
+
ref: actionButton,
|
|
306
312
|
class: 'm-input-action',
|
|
307
313
|
type: 'button',
|
|
308
314
|
icon: action.icon,
|
|
@@ -352,5 +358,5 @@ const Input = defineComponent({
|
|
|
352
358
|
|
|
353
359
|
// Vue's options overload does not infer setupContext.expose() in its constructor type.
|
|
354
360
|
export const MInput = Input as typeof Input & {
|
|
355
|
-
new (): InstanceType<typeof Input> &
|
|
361
|
+
new (): InstanceType<typeof Input> & InputActionHandle & { $props: InputEditorAttributes }
|
|
356
362
|
}
|
package/src/components/MLink.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { defineComponent, h, mergeProps } from 'vue'
|
|
2
|
-
import { fontFamily,
|
|
2
|
+
import { fontFamily, nonNegative } from '@getcortexlabs/mavis-core'
|
|
3
3
|
import {
|
|
4
4
|
linkProps,
|
|
5
5
|
linkEmits,
|
|
6
6
|
textContent,
|
|
7
7
|
useLayoutShrink,
|
|
8
8
|
useMavisTheme,
|
|
9
|
+
useNavigationOptions,
|
|
9
10
|
viewAttrs,
|
|
10
11
|
} from '@getcortexlabs/mavis-core/vue'
|
|
11
12
|
import { webAttrs } from '../style.js'
|
|
13
|
+
import { navigationAttrs } from '../navigation.js'
|
|
12
14
|
|
|
13
15
|
export const MLink = defineComponent({
|
|
14
16
|
name: 'MLink',
|
|
@@ -18,8 +20,8 @@ export const MLink = defineComponent({
|
|
|
18
20
|
setup(props, { attrs, slots, emit }) {
|
|
19
21
|
const { theme } = useMavisTheme()
|
|
20
22
|
const shrink = useLayoutShrink()
|
|
23
|
+
const navigation = useNavigationOptions(props)
|
|
21
24
|
return () => {
|
|
22
|
-
const href = linkDestination(props.href)
|
|
23
25
|
const text = props.text ?? textContent(slots.default?.())
|
|
24
26
|
if (!(props.accessibilityLabel ?? text).trim()) throw new TypeError('MLink requires a name.')
|
|
25
27
|
const type = theme.value.typography.body
|
|
@@ -27,12 +29,6 @@ export const MLink = defineComponent({
|
|
|
27
29
|
'a',
|
|
28
30
|
mergeProps(webAttrs({ ...attrs, ...viewAttrs(props) }), {
|
|
29
31
|
class: 'm-link',
|
|
30
|
-
href: props.disabled ? undefined : href,
|
|
31
|
-
target: props.target,
|
|
32
|
-
rel: linkRel(props.target, props.rel),
|
|
33
|
-
role: 'link',
|
|
34
|
-
tabindex: props.disabled ? -1 : undefined,
|
|
35
|
-
'aria-disabled': props.disabled || undefined,
|
|
36
32
|
style: {
|
|
37
33
|
'--m-focus': theme.value.colors.primary,
|
|
38
34
|
display: props.inline ? 'inline' : 'inline-flex',
|
|
@@ -53,30 +49,12 @@ export const MLink = defineComponent({
|
|
|
53
49
|
flexShrink: nonNegative(props.shrink ?? shrink.value, 'shrink'),
|
|
54
50
|
minWidth: 0,
|
|
55
51
|
},
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
emit('click')
|
|
63
|
-
if (
|
|
64
|
-
!props.navigate ||
|
|
65
|
-
props.target !== '_self' ||
|
|
66
|
-
event.button !== 0 ||
|
|
67
|
-
event.metaKey ||
|
|
68
|
-
event.ctrlKey ||
|
|
69
|
-
event.shiftKey ||
|
|
70
|
-
event.altKey
|
|
71
|
-
)
|
|
72
|
-
return
|
|
73
|
-
event.preventDefault()
|
|
74
|
-
try {
|
|
75
|
-
Promise.resolve(props.navigate(href)).catch((error) => emit('error', error))
|
|
76
|
-
} catch (error) {
|
|
77
|
-
emit('error', error)
|
|
78
|
-
}
|
|
79
|
-
},
|
|
52
|
+
...navigationAttrs(
|
|
53
|
+
navigation(),
|
|
54
|
+
props.disabled,
|
|
55
|
+
() => emit('click'),
|
|
56
|
+
(error) => emit('error', error),
|
|
57
|
+
),
|
|
80
58
|
}),
|
|
81
59
|
text,
|
|
82
60
|
)
|
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,13 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
computed,
|
|
3
|
-
defineComponent,
|
|
4
|
-
h,
|
|
5
|
-
mergeProps,
|
|
6
|
-
onBeforeUnmount,
|
|
7
|
-
onMounted,
|
|
8
|
-
provide,
|
|
9
|
-
shallowRef,
|
|
10
|
-
} from 'vue'
|
|
1
|
+
import { computed, defineComponent, h, mergeProps, provide, shallowRef } from 'vue'
|
|
11
2
|
import { resolveSpace, stackLayout } from '@getcortexlabs/mavis-core'
|
|
12
3
|
import {
|
|
13
4
|
stackProps,
|
|
@@ -17,6 +8,7 @@ import {
|
|
|
17
8
|
viewAttrs,
|
|
18
9
|
} from '@getcortexlabs/mavis-core/vue'
|
|
19
10
|
import { boxStyle, webAttrs } from '../style.js'
|
|
11
|
+
import { useContentWidth } from '../content-width.js'
|
|
20
12
|
|
|
21
13
|
const align = {
|
|
22
14
|
start: 'flex-start',
|
|
@@ -40,7 +32,7 @@ export const MStack = defineComponent({
|
|
|
40
32
|
const { theme } = useMavisTheme()
|
|
41
33
|
const shrink = useLayoutShrink()
|
|
42
34
|
const element = shallowRef<HTMLElement>()
|
|
43
|
-
const width =
|
|
35
|
+
const width = useContentWidth(element, () => props.responsive !== undefined)
|
|
44
36
|
const layout = computed(() =>
|
|
45
37
|
stackLayout(
|
|
46
38
|
{
|
|
@@ -56,15 +48,6 @@ export const MStack = defineComponent({
|
|
|
56
48
|
)
|
|
57
49
|
const direction = computed(() => layout.value.direction ?? props.direction)
|
|
58
50
|
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
51
|
return () =>
|
|
69
52
|
h(
|
|
70
53
|
'div',
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
onActivated,
|
|
3
|
+
onBeforeUnmount,
|
|
4
|
+
onDeactivated,
|
|
5
|
+
onMounted,
|
|
6
|
+
shallowRef,
|
|
7
|
+
watch,
|
|
8
|
+
type ShallowRef,
|
|
9
|
+
} from 'vue'
|
|
10
|
+
|
|
11
|
+
/** Width-only observation: layout updates run outside ResizeObserver's delivery loop. */
|
|
12
|
+
export function useContentWidth(
|
|
13
|
+
element: ShallowRef<HTMLElement | undefined>,
|
|
14
|
+
enabled: () => boolean,
|
|
15
|
+
) {
|
|
16
|
+
const width = shallowRef<number>()
|
|
17
|
+
let observer: ResizeObserver | undefined
|
|
18
|
+
let frame: number | undefined
|
|
19
|
+
let measured: number | undefined
|
|
20
|
+
let mounted = false
|
|
21
|
+
function stop() {
|
|
22
|
+
observer?.disconnect()
|
|
23
|
+
observer = undefined
|
|
24
|
+
if (frame !== undefined) cancelAnimationFrame(frame)
|
|
25
|
+
frame = undefined
|
|
26
|
+
measured = undefined
|
|
27
|
+
}
|
|
28
|
+
function start() {
|
|
29
|
+
if (
|
|
30
|
+
!mounted ||
|
|
31
|
+
observer ||
|
|
32
|
+
!enabled() ||
|
|
33
|
+
!element.value ||
|
|
34
|
+
typeof ResizeObserver === 'undefined'
|
|
35
|
+
)
|
|
36
|
+
return
|
|
37
|
+
observer = new ResizeObserver(([entry]) => {
|
|
38
|
+
if (!mounted || !enabled() || !entry || entry.contentRect.width === measured) return
|
|
39
|
+
measured = entry.contentRect.width
|
|
40
|
+
if (frame !== undefined) cancelAnimationFrame(frame)
|
|
41
|
+
frame = requestAnimationFrame(() => {
|
|
42
|
+
frame = undefined
|
|
43
|
+
width.value = measured
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
observer.observe(element.value)
|
|
47
|
+
}
|
|
48
|
+
onMounted(() => {
|
|
49
|
+
mounted = true
|
|
50
|
+
start()
|
|
51
|
+
})
|
|
52
|
+
onActivated(() => {
|
|
53
|
+
mounted = true
|
|
54
|
+
start()
|
|
55
|
+
})
|
|
56
|
+
onDeactivated(() => {
|
|
57
|
+
mounted = false
|
|
58
|
+
stop()
|
|
59
|
+
})
|
|
60
|
+
onBeforeUnmount(() => {
|
|
61
|
+
mounted = false
|
|
62
|
+
stop()
|
|
63
|
+
})
|
|
64
|
+
watch(enabled, () => {
|
|
65
|
+
stop()
|
|
66
|
+
if (enabled()) start()
|
|
67
|
+
else width.value = undefined
|
|
68
|
+
})
|
|
69
|
+
return width
|
|
70
|
+
}
|