@getcortexlabs/mavis-web 0.1.0-alpha.7 → 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 +6 -4
- package/dist/collection-motion.d.ts +4 -0
- package/dist/collection-motion.d.ts.map +1 -0
- package/dist/collection-motion.js +97 -0
- package/dist/collection-motion.js.map +1 -0
- package/dist/components/DateCalendar.d.ts +1 -1
- package/dist/components/LoadingDecoration.d.ts +116 -0
- package/dist/components/LoadingDecoration.d.ts.map +1 -0
- package/dist/components/LoadingDecoration.js +35 -0
- package/dist/components/LoadingDecoration.js.map +1 -0
- package/dist/components/MAccordion.d.ts +2 -2
- package/dist/components/MAlert.d.ts +3 -3
- package/dist/components/MAvatar.d.ts +3 -3
- package/dist/components/MBadge.d.ts +1 -1
- package/dist/components/MButton.d.ts +36 -14
- package/dist/components/MButton.d.ts.map +1 -1
- package/dist/components/MButton.js +29 -9
- package/dist/components/MButton.js.map +1 -1
- package/dist/components/MCard.d.ts +7 -7
- 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/MCombobox.d.ts +2 -2
- package/dist/components/MCombobox.d.ts.map +1 -1
- package/dist/components/MCombobox.js +10 -0
- package/dist/components/MCombobox.js.map +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/MDialog.d.ts +3 -0
- package/dist/components/MDialog.d.ts.map +1 -1
- package/dist/components/MDialog.js +69 -4
- package/dist/components/MDialog.js.map +1 -1
- package/dist/components/MEmptyState.d.ts +3 -3
- 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 +19 -1
- package/dist/components/MIcon.d.ts.map +1 -1
- package/dist/components/MIcon.js +11 -4
- package/dist/components/MIcon.js.map +1 -1
- package/dist/components/MImage.d.ts +61 -5
- package/dist/components/MImage.d.ts.map +1 -1
- package/dist/components/MImage.js +76 -10
- package/dist/components/MImage.js.map +1 -1
- package/dist/components/MInput.d.ts +10 -10
- 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 +3 -3
- 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 +2 -2
- package/dist/components/MProgress.d.ts +3 -3
- package/dist/components/MRadioGroup.d.ts +2 -2
- package/dist/components/MReveal.d.ts +13 -13
- package/dist/components/MScreen.d.ts +9 -0
- package/dist/components/MScreen.d.ts.map +1 -1
- package/dist/components/MScreen.js +37 -24
- package/dist/components/MScreen.js.map +1 -1
- package/dist/components/MSegmentedControl.d.ts +2 -2
- package/dist/components/MSelect.d.ts +2 -2
- package/dist/components/MSelect.d.ts.map +1 -1
- package/dist/components/MSelect.js +6 -0
- package/dist/components/MSelect.js.map +1 -1
- package/dist/components/MSheet.d.ts +15 -6
- package/dist/components/MSheet.d.ts.map +1 -1
- package/dist/components/MSheet.js +65 -27
- package/dist/components/MSheet.js.map +1 -1
- package/dist/components/MSkeleton.d.ts +13 -2
- package/dist/components/MSkeleton.d.ts.map +1 -1
- package/dist/components/MSkeleton.js +10 -4
- package/dist/components/MSkeleton.js.map +1 -1
- package/dist/components/MStack.d.ts +14 -14
- 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 +2 -2
- package/dist/components/MTabs.d.ts +2 -2
- package/dist/components/MText.d.ts +16 -5
- package/dist/components/MText.d.ts.map +1 -1
- package/dist/components/MText.js +8 -3
- package/dist/components/MText.js.map +1 -1
- package/dist/components/configurator.d.ts +3 -3
- package/dist/components/layout.d.ts +55 -44
- package/dist/components/layout.d.ts.map +1 -1
- package/dist/components/layout.js +3 -1
- package/dist/components/layout.js.map +1 -1
- 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/experimental.d.ts +2 -0
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +4 -0
- package/dist/experimental.js.map +1 -1
- 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 +11 -0
- package/dist/image-effects.d.ts.map +1 -0
- package/dist/image-effects.js +67 -0
- package/dist/image-effects.js.map +1 -0
- 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/motion-region.d.ts.map +1 -1
- package/dist/motion-region.js +10 -1
- package/dist/motion-region.js.map +1 -1
- package/dist/motion-surface.d.ts +1 -1
- package/dist/motion-surface.d.ts.map +1 -1
- package/dist/motion-surface.js +45 -2
- package/dist/motion-surface.js.map +1 -1
- package/dist/platform-motion.d.ts +4 -0
- package/dist/platform-motion.d.ts.map +1 -0
- package/dist/platform-motion.js +23 -0
- package/dist/platform-motion.js.map +1 -0
- 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/dist/sheet-motion.d.ts +6 -2
- package/dist/sheet-motion.d.ts.map +1 -1
- package/dist/sheet-motion.js +56 -155
- package/dist/sheet-motion.js.map +1 -1
- package/dist/surface-effects.d.ts +4 -0
- package/dist/surface-effects.d.ts.map +1 -0
- package/dist/surface-effects.js +28 -0
- package/dist/surface-effects.js.map +1 -0
- package/dist/use-motion-surface.d.ts +8 -0
- package/dist/use-motion-surface.d.ts.map +1 -0
- package/dist/use-motion-surface.js +33 -0
- package/dist/use-motion-surface.js.map +1 -0
- package/dist/visual-effects.d.ts +4 -0
- package/dist/visual-effects.d.ts.map +1 -0
- package/dist/visual-effects.js +120 -0
- package/dist/visual-effects.js.map +1 -0
- package/package.json +22 -4
- package/src/base.css +992 -0
- package/src/collection-motion.ts +107 -0
- package/src/components/LoadingDecoration.ts +39 -0
- package/src/components/MButton.ts +43 -26
- package/src/components/MCard.ts +3 -1
- package/src/components/MCombobox.ts +10 -0
- package/src/components/MDatePicker.ts +1 -9
- package/src/components/MDialog.ts +78 -4
- package/src/components/MGrid.ts +45 -0
- package/src/components/MIcon.ts +11 -3
- package/src/components/MImage.ts +85 -10
- package/src/components/MInput.ts +9 -3
- package/src/components/MLink.ts +10 -32
- package/src/components/MScreen.ts +26 -2
- package/src/components/MSelect.ts +5 -0
- package/src/components/MSheet.ts +76 -32
- package/src/components/MSkeleton.ts +13 -4
- package/src/components/MStack.ts +3 -20
- package/src/components/MText.ts +11 -2
- package/src/components/layout.ts +3 -0
- package/src/content-width.ts +70 -0
- package/src/date-format.ts +36 -0
- package/src/experimental.ts +8 -0
- package/src/icons.css +7 -0
- package/src/icons.ts +28 -0
- package/src/image-effects.ts +80 -0
- package/src/index.ts +63 -63
- package/src/motion-region.ts +10 -1
- package/src/motion-surface.ts +47 -1
- package/src/platform-motion.ts +36 -0
- package/src/services.ts +33 -0
- package/src/sheet-motion.ts +51 -152
- package/src/style.css +2 -981
- package/src/surface-effects.ts +33 -0
- package/src/use-motion-surface.ts +43 -0
- package/src/visual-effects.ts +139 -0
package/src/components/MImage.ts
CHANGED
|
@@ -1,21 +1,41 @@
|
|
|
1
|
-
import { defineComponent, h, mergeProps, onBeforeUnmount, ref, watch } from 'vue'
|
|
1
|
+
import { defineComponent, h, mergeProps, nextTick, onBeforeUnmount, ref, watch } from 'vue'
|
|
2
2
|
import { imageProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
3
3
|
import { resolveRadius, resolveDimension } from '@getcortexlabs/mavis-core'
|
|
4
4
|
import { boxStyle, webAttrs, length } from '../style.js'
|
|
5
|
+
import { useMotionSurface } from '../use-motion-surface.js'
|
|
6
|
+
import { registerMotionImage } from '../image-effects.js'
|
|
5
7
|
|
|
6
8
|
export const MImage = defineComponent({
|
|
7
9
|
name: 'MImage',
|
|
8
10
|
inheritAttrs: false,
|
|
9
11
|
props: imageProps,
|
|
10
|
-
emits: {
|
|
12
|
+
emits: {
|
|
13
|
+
load: (_src: string) => true,
|
|
14
|
+
error: (_src: string) => true,
|
|
15
|
+
'update:src': (_src: string) => true,
|
|
16
|
+
},
|
|
11
17
|
setup(props, { attrs, emit }) {
|
|
12
18
|
const { theme } = useMavisTheme()
|
|
13
19
|
const status = ref<'loading' | 'ready' | 'error'>('loading')
|
|
14
20
|
let generation = 0,
|
|
15
21
|
alive = true
|
|
22
|
+
let currentImage: HTMLImageElement | undefined,
|
|
23
|
+
releaseImage: (() => void) | undefined,
|
|
24
|
+
committing: string | undefined
|
|
25
|
+
const motion = useMotionSurface(() =>
|
|
26
|
+
status.value === 'ready' ? props.motionSurface : undefined,
|
|
27
|
+
)
|
|
16
28
|
watch(
|
|
17
|
-
() => props.src,
|
|
18
|
-
() => {
|
|
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
|
+
) {
|
|
36
|
+
committing = undefined
|
|
37
|
+
return
|
|
38
|
+
}
|
|
19
39
|
generation++
|
|
20
40
|
status.value = props.src.trim() ? 'loading' : 'error'
|
|
21
41
|
},
|
|
@@ -24,15 +44,20 @@ export const MImage = defineComponent({
|
|
|
24
44
|
onBeforeUnmount(() => {
|
|
25
45
|
alive = false
|
|
26
46
|
generation++
|
|
47
|
+
releaseImage?.()
|
|
27
48
|
})
|
|
28
49
|
return () => {
|
|
29
50
|
if (!Number.isFinite(props.aspectRatio) || props.aspectRatio <= 0)
|
|
30
51
|
throw new RangeError('aspectRatio must be finite and positive.')
|
|
31
52
|
const current = generation,
|
|
32
53
|
src = props.src
|
|
33
|
-
const settle = (success: boolean) => {
|
|
34
|
-
if (!alive || current !== generation
|
|
35
|
-
|
|
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
|
|
36
61
|
if (success) emit('load', src)
|
|
37
62
|
else emit('error', src)
|
|
38
63
|
}
|
|
@@ -62,14 +87,64 @@ export const MImage = defineComponent({
|
|
|
62
87
|
[
|
|
63
88
|
src.trim()
|
|
64
89
|
? h('img', {
|
|
65
|
-
key:
|
|
90
|
+
key: current,
|
|
66
91
|
src,
|
|
92
|
+
srcset: props.srcset,
|
|
93
|
+
sizes: props.sizes,
|
|
94
|
+
loading: props.loading,
|
|
95
|
+
decoding: props.decoding,
|
|
96
|
+
fetchpriority: props.fetchpriority,
|
|
67
97
|
alt: props.alt,
|
|
68
|
-
onLoad: () =>
|
|
98
|
+
onLoad: (event: Event) => {
|
|
99
|
+
const target = event.target as HTMLImageElement
|
|
100
|
+
const candidate = target?.currentSrc
|
|
101
|
+
if (target?.decode)
|
|
102
|
+
void target.decode().then(
|
|
103
|
+
() => settle(true, candidate),
|
|
104
|
+
() => settle(false, candidate),
|
|
105
|
+
)
|
|
106
|
+
else settle(true, candidate)
|
|
107
|
+
},
|
|
69
108
|
onError: () => settle(false),
|
|
70
109
|
onVnodeMounted: (node) => {
|
|
71
110
|
const image = node.el as HTMLImageElement
|
|
72
|
-
|
|
111
|
+
currentImage = image
|
|
112
|
+
releaseImage?.()
|
|
113
|
+
releaseImage = registerMotionImage(image, {
|
|
114
|
+
current: () => alive && current === generation && currentImage === image,
|
|
115
|
+
async commit(destination) {
|
|
116
|
+
if (!alive || current !== generation || currentImage !== image) return false
|
|
117
|
+
const previous = props.src
|
|
118
|
+
committing = destination
|
|
119
|
+
emit('update:src', destination)
|
|
120
|
+
await nextTick()
|
|
121
|
+
const accepted =
|
|
122
|
+
alive &&
|
|
123
|
+
current === generation &&
|
|
124
|
+
currentImage === image &&
|
|
125
|
+
props.src === destination
|
|
126
|
+
committing = undefined
|
|
127
|
+
if (!accepted && current === generation && currentImage === image)
|
|
128
|
+
image.src = previous
|
|
129
|
+
return accepted
|
|
130
|
+
},
|
|
131
|
+
})
|
|
132
|
+
motion.onVnodeMounted(node)
|
|
133
|
+
if (image.complete) {
|
|
134
|
+
const candidate = image.currentSrc
|
|
135
|
+
if (image.naturalWidth && image.decode)
|
|
136
|
+
void image.decode().then(
|
|
137
|
+
() => settle(true, candidate),
|
|
138
|
+
() => settle(false, candidate),
|
|
139
|
+
)
|
|
140
|
+
else settle(image.naturalWidth > 0)
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
onVnodeBeforeUnmount: () => {
|
|
144
|
+
motion.onVnodeBeforeUnmount()
|
|
145
|
+
releaseImage?.()
|
|
146
|
+
releaseImage = undefined
|
|
147
|
+
currentImage = undefined
|
|
73
148
|
},
|
|
74
149
|
style: {
|
|
75
150
|
position: 'absolute',
|
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
|
)
|
|
@@ -11,12 +11,14 @@ import {
|
|
|
11
11
|
} from '@getcortexlabs/mavis-core/vue'
|
|
12
12
|
import { webAttrs } from '../style.js'
|
|
13
13
|
import { useScreenViewport } from '../screen-viewport.js'
|
|
14
|
+
import { useMotionRegion } from '../motion-region.js'
|
|
14
15
|
|
|
15
16
|
export const MScreen = defineComponent({
|
|
16
17
|
name: 'MScreen',
|
|
17
18
|
inheritAttrs: false,
|
|
18
19
|
props: screenProps,
|
|
19
20
|
setup(props, { attrs, slots }) {
|
|
21
|
+
const region = useMotionRegion(() => props.motionRegion)
|
|
20
22
|
const { theme } = useMavisTheme()
|
|
21
23
|
const appToast = useAppToastHost()
|
|
22
24
|
const element = useScreenViewport(() => props.scroll)
|
|
@@ -39,8 +41,8 @@ export const MScreen = defineComponent({
|
|
|
39
41
|
active.isContentEditable
|
|
40
42
|
if (editor) active.blur()
|
|
41
43
|
}
|
|
42
|
-
return () =>
|
|
43
|
-
h(
|
|
44
|
+
return () => {
|
|
45
|
+
const screen = h(
|
|
44
46
|
'main',
|
|
45
47
|
mergeProps(
|
|
46
48
|
{
|
|
@@ -63,6 +65,7 @@ export const MScreen = defineComponent({
|
|
|
63
65
|
},
|
|
64
66
|
},
|
|
65
67
|
webAttrs({ ...attrs, ...viewAttrs(props) }),
|
|
68
|
+
slots.overlay ? {} : region,
|
|
66
69
|
),
|
|
67
70
|
[
|
|
68
71
|
slots.default?.(),
|
|
@@ -71,5 +74,26 @@ export const MScreen = defineComponent({
|
|
|
71
74
|
: null,
|
|
72
75
|
],
|
|
73
76
|
)
|
|
77
|
+
return slots.overlay
|
|
78
|
+
? h(
|
|
79
|
+
'div',
|
|
80
|
+
mergeProps(
|
|
81
|
+
{ class: 'm-screen-frame', style: { position: 'relative', overflow: 'clip' } },
|
|
82
|
+
region,
|
|
83
|
+
),
|
|
84
|
+
[
|
|
85
|
+
screen,
|
|
86
|
+
h(
|
|
87
|
+
'div',
|
|
88
|
+
{
|
|
89
|
+
class: 'm-screen-overlay',
|
|
90
|
+
style: { position: 'absolute', inset: 0, display: 'grid', pointerEvents: 'none' },
|
|
91
|
+
},
|
|
92
|
+
slots.overlay(),
|
|
93
|
+
),
|
|
94
|
+
],
|
|
95
|
+
)
|
|
96
|
+
: screen
|
|
97
|
+
}
|
|
74
98
|
},
|
|
75
99
|
})
|
|
@@ -299,6 +299,11 @@ export const MSelect = defineComponent({
|
|
|
299
299
|
backgroundColor: checked ? colors.primarySoft : 'transparent',
|
|
300
300
|
opacity: option.disabled ? 0.45 : 1,
|
|
301
301
|
},
|
|
302
|
+
// Keep focus on the listbox and let this option own activation.
|
|
303
|
+
// The enclosing sheet must not capture and retarget its click.
|
|
304
|
+
onPointerdown: (event: PointerEvent) => {
|
|
305
|
+
if (event.button === 0) event.preventDefault()
|
|
306
|
+
},
|
|
302
307
|
onClick: () => choose(option),
|
|
303
308
|
},
|
|
304
309
|
[
|
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
|
|
@@ -128,16 +157,19 @@ const Sheet = defineComponent({
|
|
|
128
157
|
motion = sheetMotion(
|
|
129
158
|
element,
|
|
130
159
|
panel.value!,
|
|
131
|
-
handle.value
|
|
132
|
-
() =>
|
|
160
|
+
handle.value!,
|
|
161
|
+
() => ({
|
|
162
|
+
dismissible: props.dismissible,
|
|
163
|
+
fullscreen: props.fullscreen,
|
|
164
|
+
label: checkSheetName(props.title, props.accessibilityLabel),
|
|
165
|
+
}),
|
|
133
166
|
() => {
|
|
134
167
|
if (props.open) return
|
|
135
168
|
motion?.dispose()
|
|
136
169
|
motion = undefined
|
|
137
170
|
if (element.open) element.close()
|
|
138
171
|
presented.value = false
|
|
139
|
-
|
|
140
|
-
restoreFocus()
|
|
172
|
+
// Retain the opener until the queued native close event releases modal focus.
|
|
141
173
|
},
|
|
142
174
|
() => request('swipe'),
|
|
143
175
|
)
|
|
@@ -152,12 +184,11 @@ const Sheet = defineComponent({
|
|
|
152
184
|
else {
|
|
153
185
|
dialog.value?.close?.()
|
|
154
186
|
presented.value = false
|
|
155
|
-
|
|
156
|
-
restoreFocus()
|
|
187
|
+
// Restoration belongs to the native close event, after inertness is released.
|
|
157
188
|
}
|
|
158
189
|
}
|
|
159
190
|
watch(
|
|
160
|
-
() => props.dismissible,
|
|
191
|
+
() => [props.dismissible, props.fullscreen, props.title, props.accessibilityLabel],
|
|
161
192
|
() => motion?.refresh(),
|
|
162
193
|
)
|
|
163
194
|
|
|
@@ -177,26 +208,29 @@ const Sheet = defineComponent({
|
|
|
177
208
|
},
|
|
178
209
|
)
|
|
179
210
|
onActivated(() => {
|
|
211
|
+
attached = true
|
|
180
212
|
if (props.open && !presented.value) present()
|
|
181
213
|
})
|
|
182
214
|
onMounted(() => {
|
|
183
215
|
if (props.open) present()
|
|
184
216
|
})
|
|
185
217
|
onDeactivated(() => {
|
|
218
|
+
attached = false
|
|
186
219
|
generation++
|
|
187
220
|
motion?.dispose()
|
|
188
221
|
motion = undefined
|
|
222
|
+
opener = undefined
|
|
189
223
|
dialog.value?.close?.()
|
|
190
224
|
shown.value = presented.value = false
|
|
191
|
-
opener = undefined
|
|
192
225
|
if (props.open) announce('program')
|
|
193
226
|
})
|
|
194
227
|
onBeforeUnmount(() => {
|
|
228
|
+
attached = false
|
|
195
229
|
generation++
|
|
196
230
|
motion?.dispose()
|
|
197
231
|
motion = undefined
|
|
232
|
+
opener = undefined
|
|
198
233
|
dialog.value?.close?.()
|
|
199
|
-
restoreFocus()
|
|
200
234
|
})
|
|
201
235
|
|
|
202
236
|
return () => {
|
|
@@ -255,14 +289,17 @@ const Sheet = defineComponent({
|
|
|
255
289
|
},
|
|
256
290
|
onClose: () => {
|
|
257
291
|
// close events are queued: a previous dismissal can arrive after a rapid reopen.
|
|
258
|
-
if (dialog.value?.open) return
|
|
292
|
+
if (!attached || dialog.value?.open) return
|
|
259
293
|
// Closed by the browser itself: keep the bound state in step.
|
|
260
294
|
if (props.open && !closing) announce('escape')
|
|
261
295
|
motion?.dispose()
|
|
262
296
|
motion = undefined
|
|
263
297
|
shown.value = false
|
|
264
298
|
presented.value = false
|
|
265
|
-
|
|
299
|
+
const reason = closing ?? 'program'
|
|
300
|
+
closing = undefined
|
|
301
|
+
const element = dialog.value
|
|
302
|
+
if (element) restoreFocus(element, reason)
|
|
266
303
|
},
|
|
267
304
|
onKeydown: trapTab,
|
|
268
305
|
onPointerdown: (event: Event) => {
|
|
@@ -281,27 +318,34 @@ const Sheet = defineComponent({
|
|
|
281
318
|
{
|
|
282
319
|
class: 'm-sheet-panel',
|
|
283
320
|
ref: panel,
|
|
284
|
-
style: {
|
|
285
|
-
padding: `${resolveSpace(theme.value, props.padding ?? 'lg')}px`,
|
|
286
|
-
gap: `${space.md}px`,
|
|
287
|
-
},
|
|
288
321
|
},
|
|
289
322
|
[
|
|
290
323
|
h(
|
|
291
324
|
'div',
|
|
292
325
|
{
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
326
|
+
class: 'm-sheet-content',
|
|
327
|
+
style: {
|
|
328
|
+
padding: `${resolveSpace(theme.value, props.padding ?? 'lg')}px`,
|
|
329
|
+
gap: `${space.md}px`,
|
|
330
|
+
},
|
|
297
331
|
},
|
|
298
|
-
[
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
332
|
+
[
|
|
333
|
+
h(
|
|
334
|
+
'div',
|
|
335
|
+
{
|
|
336
|
+
ref: handle,
|
|
337
|
+
class: 'm-sheet-handle',
|
|
338
|
+
style: { display: props.dismissible ? undefined : 'none' },
|
|
339
|
+
},
|
|
340
|
+
[h('span')],
|
|
341
|
+
),
|
|
342
|
+
header,
|
|
343
|
+
h(
|
|
344
|
+
MColumn,
|
|
345
|
+
{ class: 'm-sheet-body', shrink: 1, gap: props.gap, align: props.align },
|
|
346
|
+
{ default: () => slots.default?.() },
|
|
347
|
+
),
|
|
348
|
+
],
|
|
305
349
|
),
|
|
306
350
|
],
|
|
307
351
|
),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { defineComponent, h, mergeProps, onBeforeUnmount, onMounted, ref } from 'vue'
|
|
1
|
+
import { defineComponent, h, mergeProps, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
2
2
|
import { skeletonProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
3
3
|
import { MBox } from './layout.js'
|
|
4
|
+
import { LoadingDecoration } from './LoadingDecoration.js'
|
|
4
5
|
|
|
5
6
|
export const MSkeleton = defineComponent({
|
|
6
7
|
name: 'MSkeleton',
|
|
@@ -14,12 +15,19 @@ export const MSkeleton = defineComponent({
|
|
|
14
15
|
}
|
|
15
16
|
onMounted(() => {
|
|
16
17
|
visibility()
|
|
17
|
-
|
|
18
|
+
watch(
|
|
19
|
+
() => props.effect,
|
|
20
|
+
(effect) => {
|
|
21
|
+
document.removeEventListener('visibilitychange', visibility)
|
|
22
|
+
if (effect === 'pulse') document.addEventListener('visibilitychange', visibility)
|
|
23
|
+
},
|
|
24
|
+
{ immediate: true },
|
|
25
|
+
)
|
|
18
26
|
})
|
|
19
27
|
onBeforeUnmount(() => document.removeEventListener('visibilitychange', visibility))
|
|
20
28
|
return () =>
|
|
21
29
|
h(
|
|
22
|
-
MBox,
|
|
30
|
+
props.effect === 'shimmer' ? LoadingDecoration : MBox,
|
|
23
31
|
mergeProps(
|
|
24
32
|
{
|
|
25
33
|
style: {
|
|
@@ -37,7 +45,8 @@ export const MSkeleton = defineComponent({
|
|
|
37
45
|
shrink: props.shrink,
|
|
38
46
|
backgroundColor: theme.value.colors.border,
|
|
39
47
|
class: 'm-skeleton',
|
|
40
|
-
'data-animated': props.animated,
|
|
48
|
+
'data-animated': props.effect === 'pulse' && props.animated,
|
|
49
|
+
...(props.effect === 'shimmer' ? { kind: 'shimmer', animated: props.animated } : {}),
|
|
41
50
|
style: {
|
|
42
51
|
animationPlayState: hidden.value ? 'paused' : 'running',
|
|
43
52
|
pointerEvents: 'none',
|
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',
|
package/src/components/MText.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent, h, mergeProps } from 'vue'
|
|
1
|
+
import { defineComponent, h, mergeProps, Text } from 'vue'
|
|
2
2
|
import {
|
|
3
3
|
textProps,
|
|
4
4
|
useMavisTheme,
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from '@getcortexlabs/mavis-core/vue'
|
|
9
9
|
import { fontFamily, nonNegative, validateWeight } from '@getcortexlabs/mavis-core'
|
|
10
10
|
import { webAttrs } from '../style.js'
|
|
11
|
+
import { useMotionSurface } from '../use-motion-surface.js'
|
|
11
12
|
|
|
12
13
|
export const MText = defineComponent({
|
|
13
14
|
name: 'MText',
|
|
@@ -16,6 +17,10 @@ export const MText = defineComponent({
|
|
|
16
17
|
setup(props, { attrs, slots }) {
|
|
17
18
|
const { theme } = useMavisTheme()
|
|
18
19
|
const shrink = useLayoutShrink()
|
|
20
|
+
const motion = useMotionSurface(
|
|
21
|
+
() => props.motionSurface,
|
|
22
|
+
() => props.text !== undefined,
|
|
23
|
+
)
|
|
19
24
|
return () => {
|
|
20
25
|
const type = theme.value.typography[props.variant]
|
|
21
26
|
const runs =
|
|
@@ -27,6 +32,7 @@ export const MText = defineComponent({
|
|
|
27
32
|
class: 'm-text',
|
|
28
33
|
style: {
|
|
29
34
|
margin: 0,
|
|
35
|
+
display: props.motionSurface && props.as === 'span' ? 'inline-block' : undefined,
|
|
30
36
|
fontFamily: `var(--m-text-font-family, ${fontFamily(type.fontFamily, 'web')})`,
|
|
31
37
|
fontSize: `var(--m-text-font-size, ${type.fontSize}px)`,
|
|
32
38
|
fontWeight: props.weight
|
|
@@ -44,9 +50,12 @@ export const MText = defineComponent({
|
|
|
44
50
|
},
|
|
45
51
|
},
|
|
46
52
|
webAttrs({ ...attrs, ...viewAttrs(props) }),
|
|
53
|
+
motion,
|
|
47
54
|
),
|
|
48
55
|
runs.every((run) => !run.weight && !run.tone && !run.strong && !run.italic)
|
|
49
|
-
?
|
|
56
|
+
? props.motionSurface
|
|
57
|
+
? [h(Text, null, runs.map((run) => run.text).join(''))]
|
|
58
|
+
: runs.map((run) => run.text).join('')
|
|
50
59
|
: runs.map((run) => {
|
|
51
60
|
if (!run.weight && !run.tone && !run.strong && !run.italic) return run.text
|
|
52
61
|
if (run.tone && !(run.tone in theme.value.colors))
|