@getcortexlabs/mavis-web 0.1.0-alpha.5 → 0.1.0-alpha.7
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 -4
- package/dist/components/ChoicePaint.d.ts +17 -0
- package/dist/components/ChoicePaint.d.ts.map +1 -0
- package/dist/components/ChoicePaint.js +81 -0
- package/dist/components/ChoicePaint.js.map +1 -0
- package/dist/components/DateCalendar.d.ts +3 -3
- package/dist/components/MAccordion.d.ts +1 -1
- package/dist/components/MAlert.d.ts +1 -1
- package/dist/components/MAvatar.d.ts +1 -1
- package/dist/components/MBadge.d.ts +1 -1
- package/dist/components/MButton.d.ts +55 -9
- package/dist/components/MButton.d.ts.map +1 -1
- package/dist/components/MButton.js +13 -8
- package/dist/components/MButton.js.map +1 -1
- package/dist/components/MCard.d.ts +49 -2
- package/dist/components/MCard.d.ts.map +1 -1
- package/dist/components/MCard.js +44 -31
- package/dist/components/MCard.js.map +1 -1
- package/dist/components/MCheckbox.d.ts +1 -1
- package/dist/components/MCheckbox.d.ts.map +1 -1
- package/dist/components/MCheckbox.js +11 -6
- package/dist/components/MCheckbox.js.map +1 -1
- package/dist/components/MChip.d.ts +3 -3
- package/dist/components/MCombobox.d.ts +2 -2
- package/dist/components/MCombobox.js +3 -3
- 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 +9 -0
- package/dist/components/MDatePicker.js.map +1 -1
- package/dist/components/MDialog.d.ts +2 -2
- package/dist/components/MEmptyState.d.ts +1 -1
- package/dist/components/MFilePicker.d.ts +2 -2
- package/dist/components/MIcon.d.ts +1 -1
- package/dist/components/MImage.d.ts +192 -0
- package/dist/components/MImage.d.ts.map +1 -0
- package/dist/components/MImage.js +97 -0
- package/dist/components/MImage.js.map +1 -0
- package/dist/components/MInput.d.ts +7 -7
- package/dist/components/MInput.js +3 -3
- package/dist/components/MInput.js.map +1 -1
- package/dist/components/MLink.d.ts +120 -0
- package/dist/components/MLink.d.ts.map +1 -0
- package/dist/components/MLink.js +75 -0
- package/dist/components/MLink.js.map +1 -0
- package/dist/components/MListItem.d.ts +3 -1
- package/dist/components/MListItem.d.ts.map +1 -1
- package/dist/components/MProgress.d.ts +3 -3
- package/dist/components/MRadioGroup.d.ts +1 -1
- package/dist/components/MRadioGroup.d.ts.map +1 -1
- package/dist/components/MRadioGroup.js +5 -3
- package/dist/components/MRadioGroup.js.map +1 -1
- package/dist/components/MReveal.d.ts +2 -2
- package/dist/components/MReveal.d.ts.map +1 -1
- package/dist/components/MReveal.js +39 -50
- package/dist/components/MReveal.js.map +1 -1
- package/dist/components/MSegmentedControl.d.ts +1 -1
- package/dist/components/MSelect.d.ts +1 -1
- package/dist/components/MSeparator.d.ts +1 -1
- package/dist/components/MSheet.d.ts +1 -1
- package/dist/components/MSlider.d.ts +1 -1
- package/dist/components/MStack.d.ts +198 -0
- package/dist/components/MStack.d.ts.map +1 -0
- package/dist/components/MStack.js +62 -0
- package/dist/components/MStack.js.map +1 -0
- package/dist/components/MSwitch.d.ts +1 -1
- package/dist/components/MSwitch.d.ts.map +1 -1
- package/dist/components/MSwitch.js +12 -5
- package/dist/components/MSwitch.js.map +1 -1
- package/dist/components/MTabs.d.ts +1 -1
- package/dist/components/MText.d.ts +4 -4
- package/dist/components/MText.js +6 -6
- package/dist/components/MText.js.map +1 -1
- package/dist/components/configurator.d.ts +541 -0
- package/dist/components/configurator.d.ts.map +1 -0
- package/dist/components/configurator.js +20 -0
- package/dist/components/configurator.js.map +1 -0
- package/dist/components/layout.d.ts +179 -2
- package/dist/components/layout.d.ts.map +1 -1
- package/dist/components/layout.js +10 -10
- package/dist/components/layout.js.map +1 -1
- package/dist/components/workflows.d.ts +1 -1
- package/dist/connected-motion.d.ts +6 -0
- package/dist/connected-motion.d.ts.map +1 -0
- package/dist/connected-motion.js +18 -0
- package/dist/connected-motion.js.map +1 -0
- package/dist/experimental.d.ts +9 -0
- package/dist/experimental.d.ts.map +1 -0
- package/dist/experimental.js +27 -0
- package/dist/experimental.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/motion-region.d.ts +3 -0
- package/dist/motion-region.d.ts.map +1 -1
- package/dist/motion-region.js +69 -39
- package/dist/motion-region.js.map +1 -1
- package/dist/motion-surface.d.ts +4 -0
- package/dist/motion-surface.d.ts.map +1 -1
- package/dist/motion-surface.js +66 -2
- package/dist/motion-surface.js.map +1 -1
- package/dist/motion.d.ts +2 -2
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +8 -27
- package/dist/motion.js.map +1 -1
- package/dist/navigation.d.ts +12 -0
- package/dist/navigation.d.ts.map +1 -0
- package/dist/navigation.js +38 -0
- package/dist/navigation.js.map +1 -0
- package/dist/reveal-motion.d.ts +5 -0
- package/dist/reveal-motion.d.ts.map +1 -0
- package/dist/reveal-motion.js +53 -0
- package/dist/reveal-motion.js.map +1 -0
- package/dist/scroll-motion.d.ts.map +1 -1
- package/dist/scroll-motion.js +33 -18
- package/dist/scroll-motion.js.map +1 -1
- package/dist/tokens.d.ts +7 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +29 -0
- package/dist/tokens.js.map +1 -0
- package/package.json +7 -3
- package/src/components/ChoicePaint.ts +96 -0
- package/src/components/MButton.ts +17 -7
- package/src/components/MCard.ts +54 -28
- package/src/components/MCheckbox.ts +17 -6
- package/src/components/MCombobox.ts +3 -3
- package/src/components/MDatePicker.ts +8 -0
- package/src/components/MImage.ts +108 -0
- package/src/components/MInput.ts +3 -3
- package/src/components/MLink.ts +85 -0
- package/src/components/MRadioGroup.ts +9 -3
- package/src/components/MReveal.ts +57 -64
- package/src/components/MStack.ts +90 -0
- package/src/components/MSwitch.ts +17 -6
- package/src/components/MText.ts +6 -6
- package/src/components/configurator.ts +24 -0
- package/src/components/layout.ts +10 -10
- package/src/connected-motion.ts +23 -0
- package/src/experimental.ts +29 -0
- package/src/index.ts +15 -0
- package/src/motion-region.ts +94 -41
- package/src/motion-surface.ts +72 -4
- package/src/motion.ts +10 -40
- package/src/navigation.ts +44 -0
- package/src/reveal-motion.ts +59 -0
- package/src/scroll-motion.ts +31 -18
- package/src/style.css +13 -10
- package/src/tokens.ts +29 -0
|
@@ -1,80 +1,73 @@
|
|
|
1
|
+
import { defineComponent, h, mergeProps, onActivated, onDeactivated } from 'vue'
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
shallowRef,
|
|
9
|
-
} from 'vue'
|
|
10
|
-
import { revealProps } from '@getcortexlabs/mavis-core/vue'
|
|
3
|
+
revealProps,
|
|
4
|
+
useMavisTheme,
|
|
5
|
+
useRevealState,
|
|
6
|
+
viewAttrs,
|
|
7
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
8
|
+
import { revealHost } from '../reveal-motion.js'
|
|
11
9
|
import { MColumn } from './layout.js'
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
10
|
+
import { useMotionContext } from '../motion-context.js'
|
|
11
|
+
import { webAttrs, boxStyle } from '../style.js'
|
|
14
12
|
|
|
15
13
|
export const MReveal = defineComponent({
|
|
16
14
|
name: 'MReveal',
|
|
17
15
|
inheritAttrs: false,
|
|
18
16
|
props: revealProps,
|
|
19
17
|
setup(props, { attrs, slots }) {
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
const { theme } = useMavisTheme()
|
|
19
|
+
const state = useRevealState(() => props.show)
|
|
20
|
+
const context = useMotionContext()
|
|
21
|
+
let mounted: HTMLElement | undefined
|
|
22
|
+
let retained: HTMLElement | undefined
|
|
23
|
+
function attach(element: HTMLElement) {
|
|
24
|
+
if (mounted === element) return
|
|
25
|
+
mounted = retained = element
|
|
26
|
+
return state.attach(
|
|
27
|
+
revealHost(
|
|
28
|
+
element,
|
|
29
|
+
context,
|
|
30
|
+
() => theme.value,
|
|
31
|
+
() => Boolean(props.accessibilityHidden),
|
|
32
|
+
),
|
|
33
|
+
)
|
|
34
|
+
}
|
|
27
35
|
onDeactivated(() => {
|
|
28
|
-
|
|
36
|
+
state.detach()
|
|
37
|
+
mounted = undefined
|
|
29
38
|
})
|
|
30
39
|
onActivated(() => {
|
|
31
|
-
|
|
40
|
+
if (retained) return attach(retained)
|
|
32
41
|
})
|
|
33
|
-
let trigger: HTMLElement | undefined
|
|
34
42
|
return () => {
|
|
35
|
-
const { show, ...
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
MColumn,
|
|
64
|
-
mergeProps(layout, attrs, {
|
|
65
|
-
key: 'content',
|
|
66
|
-
onVnodeMounted: (node) => {
|
|
67
|
-
target.value = mounted = node.el as HTMLElement
|
|
68
|
-
},
|
|
69
|
-
onVnodeUnmounted: () => {
|
|
70
|
-
target.value = mounted = null
|
|
71
|
-
},
|
|
72
|
-
}),
|
|
73
|
-
slots,
|
|
74
|
-
)
|
|
75
|
-
: null,
|
|
76
|
-
},
|
|
77
|
-
)
|
|
43
|
+
const { show, id, accessibilityLabel, accessibilityHidden, grow, shrink, width, ...content } =
|
|
44
|
+
props
|
|
45
|
+
return state.present.value
|
|
46
|
+
? h(
|
|
47
|
+
'div',
|
|
48
|
+
mergeProps(
|
|
49
|
+
{
|
|
50
|
+
class: 'm-reveal',
|
|
51
|
+
style: {
|
|
52
|
+
...boxStyle(theme.value, { grow, shrink: shrink ?? 0, width }),
|
|
53
|
+
overflow: state.phase.value === 'open' ? undefined : 'clip',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
webAttrs({ ...attrs, ...viewAttrs({ id, accessibilityLabel, accessibilityHidden }) }),
|
|
57
|
+
{
|
|
58
|
+
'data-state': state.phase.value,
|
|
59
|
+
inert: !show || accessibilityHidden || undefined,
|
|
60
|
+
'aria-hidden': !show || accessibilityHidden || undefined,
|
|
61
|
+
onVnodeMounted: (node) => attach(node.el as HTMLElement),
|
|
62
|
+
onVnodeBeforeUnmount: () => {
|
|
63
|
+
state.detach()
|
|
64
|
+
mounted = retained = undefined
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
),
|
|
68
|
+
[h(MColumn, content, slots)],
|
|
69
|
+
)
|
|
70
|
+
: null
|
|
78
71
|
}
|
|
79
72
|
},
|
|
80
73
|
})
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
defineComponent,
|
|
4
|
+
h,
|
|
5
|
+
mergeProps,
|
|
6
|
+
onBeforeUnmount,
|
|
7
|
+
onMounted,
|
|
8
|
+
provide,
|
|
9
|
+
shallowRef,
|
|
10
|
+
} from 'vue'
|
|
11
|
+
import { resolveSpace, stackLayout } from '@getcortexlabs/mavis-core'
|
|
12
|
+
import {
|
|
13
|
+
stackProps,
|
|
14
|
+
layoutDirection,
|
|
15
|
+
useLayoutShrink,
|
|
16
|
+
useMavisTheme,
|
|
17
|
+
viewAttrs,
|
|
18
|
+
} from '@getcortexlabs/mavis-core/vue'
|
|
19
|
+
import { boxStyle, webAttrs } from '../style.js'
|
|
20
|
+
|
|
21
|
+
const align = {
|
|
22
|
+
start: 'flex-start',
|
|
23
|
+
end: 'flex-end',
|
|
24
|
+
center: 'center',
|
|
25
|
+
stretch: 'stretch',
|
|
26
|
+
} as const
|
|
27
|
+
const justify = {
|
|
28
|
+
start: 'flex-start',
|
|
29
|
+
end: 'flex-end',
|
|
30
|
+
center: 'center',
|
|
31
|
+
between: 'space-between',
|
|
32
|
+
around: 'space-around',
|
|
33
|
+
} as const
|
|
34
|
+
|
|
35
|
+
export const MStack = defineComponent({
|
|
36
|
+
name: 'MStack',
|
|
37
|
+
inheritAttrs: false,
|
|
38
|
+
props: stackProps,
|
|
39
|
+
setup(props, { attrs, slots }) {
|
|
40
|
+
const { theme } = useMavisTheme()
|
|
41
|
+
const shrink = useLayoutShrink()
|
|
42
|
+
const element = shallowRef<HTMLElement>()
|
|
43
|
+
const width = shallowRef<number>()
|
|
44
|
+
const layout = computed(() =>
|
|
45
|
+
stackLayout(
|
|
46
|
+
{
|
|
47
|
+
direction: props.direction,
|
|
48
|
+
gap: props.gap,
|
|
49
|
+
align: props.align,
|
|
50
|
+
justify: props.justify,
|
|
51
|
+
wrap: props.wrap,
|
|
52
|
+
},
|
|
53
|
+
props.responsive,
|
|
54
|
+
width.value,
|
|
55
|
+
),
|
|
56
|
+
)
|
|
57
|
+
const direction = computed(() => layout.value.direction ?? props.direction)
|
|
58
|
+
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
|
+
return () =>
|
|
69
|
+
h(
|
|
70
|
+
'div',
|
|
71
|
+
mergeProps(
|
|
72
|
+
{
|
|
73
|
+
ref: element,
|
|
74
|
+
class: 'm-stack',
|
|
75
|
+
style: {
|
|
76
|
+
...boxStyle(theme.value, props, shrink.value),
|
|
77
|
+
display: 'flex',
|
|
78
|
+
flexDirection: direction.value,
|
|
79
|
+
alignItems: align[layout.value.align ?? props.align],
|
|
80
|
+
justifyContent: justify[layout.value.justify ?? props.justify],
|
|
81
|
+
flexWrap: layout.value.wrap ? 'wrap' : 'nowrap',
|
|
82
|
+
gap: `${resolveSpace(theme.value, layout.value.gap ?? 'none')}px`,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
webAttrs({ ...attrs, ...viewAttrs(props) }),
|
|
86
|
+
),
|
|
87
|
+
slots.default?.(),
|
|
88
|
+
)
|
|
89
|
+
},
|
|
90
|
+
})
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ChoicePaintSurface } from './ChoicePaint.js'
|
|
1
2
|
import { fontFamily } from '@getcortexlabs/mavis-core'
|
|
2
3
|
import { defineComponent, h, mergeProps, useId } from 'vue'
|
|
3
4
|
import {
|
|
@@ -5,7 +6,7 @@ import {
|
|
|
5
6
|
switchProps,
|
|
6
7
|
switchEmits,
|
|
7
8
|
useMavisTheme,
|
|
8
|
-
|
|
9
|
+
useLayoutShrink,
|
|
9
10
|
} from '@getcortexlabs/mavis-core/vue'
|
|
10
11
|
import { nonNegative, resolveDimension } from '@getcortexlabs/mavis-core'
|
|
11
12
|
import { length, webAttrs } from '../style.js'
|
|
@@ -18,7 +19,7 @@ export const MSwitch = defineComponent({
|
|
|
18
19
|
setup(props, { attrs, emit }) {
|
|
19
20
|
useButtonAction()
|
|
20
21
|
const { theme } = useMavisTheme()
|
|
21
|
-
const shrink =
|
|
22
|
+
const shrink = useLayoutShrink()
|
|
22
23
|
const labelId = `m-switch-${useId()}`
|
|
23
24
|
return () => {
|
|
24
25
|
const { colors, space, typography, radius } = theme.value
|
|
@@ -47,7 +48,7 @@ export const MSwitch = defineComponent({
|
|
|
47
48
|
lineHeight: 1.5,
|
|
48
49
|
opacity: props.disabled ? 0.45 : 1,
|
|
49
50
|
flexGrow: nonNegative(props.grow, 'grow'),
|
|
50
|
-
flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
|
|
51
|
+
flexShrink: nonNegative(props.shrink ?? shrink.value, 'shrink'),
|
|
51
52
|
width: length(resolveDimension(props.width)),
|
|
52
53
|
'--m-focus': colors.primary,
|
|
53
54
|
'--m-switch-track': props.modelValue ? colors.primary : colors.muted,
|
|
@@ -98,9 +99,19 @@ export const MSwitch = defineComponent({
|
|
|
98
99
|
: null,
|
|
99
100
|
],
|
|
100
101
|
),
|
|
101
|
-
h(
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
h(
|
|
103
|
+
ChoicePaintSurface,
|
|
104
|
+
{
|
|
105
|
+
class: 'm-switch-track',
|
|
106
|
+
paint: { backgroundColor: props.modelValue ? colors.primary : colors.muted },
|
|
107
|
+
},
|
|
108
|
+
() => [
|
|
109
|
+
h(ChoicePaintSurface, {
|
|
110
|
+
class: 'm-switch-thumb',
|
|
111
|
+
paint: { backgroundColor: props.modelValue ? colors.onPrimary : colors.surface },
|
|
112
|
+
}),
|
|
113
|
+
],
|
|
114
|
+
),
|
|
104
115
|
],
|
|
105
116
|
)
|
|
106
117
|
}
|
package/src/components/MText.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
textProps,
|
|
4
4
|
useMavisTheme,
|
|
5
5
|
inlineContent,
|
|
6
|
-
|
|
6
|
+
useLayoutShrink,
|
|
7
7
|
viewAttrs,
|
|
8
8
|
} from '@getcortexlabs/mavis-core/vue'
|
|
9
9
|
import { fontFamily, nonNegative, validateWeight } from '@getcortexlabs/mavis-core'
|
|
@@ -15,7 +15,7 @@ export const MText = defineComponent({
|
|
|
15
15
|
props: textProps,
|
|
16
16
|
setup(props, { attrs, slots }) {
|
|
17
17
|
const { theme } = useMavisTheme()
|
|
18
|
-
const shrink =
|
|
18
|
+
const shrink = useLayoutShrink()
|
|
19
19
|
return () => {
|
|
20
20
|
const type = theme.value.typography[props.variant]
|
|
21
21
|
const runs =
|
|
@@ -34,12 +34,12 @@ export const MText = defineComponent({
|
|
|
34
34
|
: `var(--m-text-font-weight, ${type.fontWeight})`,
|
|
35
35
|
letterSpacing: `var(--m-text-letter-spacing, ${type.letterSpacing}em)`,
|
|
36
36
|
lineHeight: `var(--m-text-line-height, ${type.lineHeight})`,
|
|
37
|
-
color: theme.value.colors[props.tone]
|
|
38
|
-
textAlign: props.align
|
|
39
|
-
whiteSpace: props.wrap ? 'normal' : 'nowrap'
|
|
37
|
+
color: `var(--m-text-color, ${theme.value.colors[props.tone]})`,
|
|
38
|
+
textAlign: `var(--m-text-align, ${props.align})`,
|
|
39
|
+
whiteSpace: `var(--m-text-wrap, ${props.wrap ? 'normal' : 'nowrap'})`,
|
|
40
40
|
overflowWrap: 'anywhere',
|
|
41
41
|
flexGrow: nonNegative(props.grow, 'grow'),
|
|
42
|
-
flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
|
|
42
|
+
flexShrink: nonNegative(props.shrink ?? shrink.value, 'shrink'),
|
|
43
43
|
minWidth: 0,
|
|
44
44
|
},
|
|
45
45
|
},
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createConfiguratorControls } from '@getcortexlabs/mavis-core/vue'
|
|
2
|
+
import { MText } from './MText.js'
|
|
3
|
+
import { MButton } from './MButton.js'
|
|
4
|
+
import { MInput } from './MInput.js'
|
|
5
|
+
import { MChip } from './MChip.js'
|
|
6
|
+
import { MCheckbox } from './MCheckbox.js'
|
|
7
|
+
import { MSheet } from './MSheet.js'
|
|
8
|
+
import { MColumn, MRow } from './layout.js'
|
|
9
|
+
|
|
10
|
+
export const { MNumberInput, MMultiSelect } = createConfiguratorControls(
|
|
11
|
+
{
|
|
12
|
+
Column: MColumn,
|
|
13
|
+
Row: MRow,
|
|
14
|
+
Text: MText,
|
|
15
|
+
Button: MButton,
|
|
16
|
+
Input: MInput,
|
|
17
|
+
Chip: MChip,
|
|
18
|
+
Checkbox: MCheckbox,
|
|
19
|
+
Sheet: MSheet,
|
|
20
|
+
focusTrigger: (component) =>
|
|
21
|
+
(component as { $el?: HTMLElement } | undefined)?.$el?.focus({ preventScroll: true }),
|
|
22
|
+
},
|
|
23
|
+
'web',
|
|
24
|
+
)
|
package/src/components/layout.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
viewAttrs,
|
|
5
5
|
useMavisTheme,
|
|
6
6
|
layoutDirection,
|
|
7
|
-
|
|
7
|
+
useLayoutShrink,
|
|
8
8
|
motionBoxProps,
|
|
9
9
|
} from '@getcortexlabs/mavis-core/vue'
|
|
10
10
|
import { defineComponent, h, mergeProps, provide } from 'vue'
|
|
@@ -28,28 +28,28 @@ const distribution = {
|
|
|
28
28
|
around: 'space-around',
|
|
29
29
|
} as const
|
|
30
30
|
|
|
31
|
-
function createLayout(name: string, direction: 'row' | 'column') {
|
|
31
|
+
export function createLayout(name: string, direction: 'row' | 'column', tag = 'div') {
|
|
32
32
|
return defineComponent({
|
|
33
33
|
name,
|
|
34
34
|
inheritAttrs: false,
|
|
35
35
|
props: direction === 'row' ? rowProps : columnProps,
|
|
36
36
|
setup(props, { attrs, slots }) {
|
|
37
37
|
const { theme } = useMavisTheme()
|
|
38
|
-
const shrink =
|
|
38
|
+
const shrink = useLayoutShrink()
|
|
39
39
|
provide(layoutDirection, direction)
|
|
40
40
|
return () =>
|
|
41
41
|
h(
|
|
42
|
-
|
|
42
|
+
tag,
|
|
43
43
|
mergeProps(
|
|
44
44
|
{
|
|
45
45
|
style: {
|
|
46
|
-
...boxStyle(theme.value, props, shrink),
|
|
46
|
+
...boxStyle(theme.value, props, shrink.value),
|
|
47
47
|
display: 'flex',
|
|
48
48
|
flexDirection: direction,
|
|
49
|
-
alignItems: alignment[props.align]
|
|
50
|
-
justifyContent: distribution[props.justify]
|
|
49
|
+
alignItems: `var(--m-layout-align, ${alignment[props.align]})`,
|
|
50
|
+
justifyContent: `var(--m-layout-justify, ${distribution[props.justify]})`,
|
|
51
51
|
flexWrap: props.wrap ? 'wrap' : 'nowrap',
|
|
52
|
-
gap:
|
|
52
|
+
gap: `var(--m-layout-gap, ${resolveSpace(theme.value, props.gap ?? 'none')}px)`,
|
|
53
53
|
},
|
|
54
54
|
},
|
|
55
55
|
webAttrs({ ...attrs, ...viewAttrs(props) }),
|
|
@@ -69,14 +69,14 @@ export const MBox = defineComponent({
|
|
|
69
69
|
setup(props, { attrs, slots }) {
|
|
70
70
|
const region = useMotionRegion(() => props.motionRegion)
|
|
71
71
|
const { theme } = useMavisTheme()
|
|
72
|
-
const shrink =
|
|
72
|
+
const shrink = useLayoutShrink()
|
|
73
73
|
return () =>
|
|
74
74
|
h(
|
|
75
75
|
'div',
|
|
76
76
|
mergeProps(
|
|
77
77
|
{
|
|
78
78
|
class: 'm-box',
|
|
79
|
-
style: { ...boxStyle(theme.value, props, shrink), display: 'grid' },
|
|
79
|
+
style: { ...boxStyle(theme.value, props, shrink.value), display: 'grid' },
|
|
80
80
|
},
|
|
81
81
|
webAttrs({ ...attrs, ...viewAttrs(props) }),
|
|
82
82
|
region,
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { onScopeDispose, type Ref } from 'vue'
|
|
2
|
+
import { useWebMotion } from '@rafaelaugusto/jolt/web/vue'
|
|
3
|
+
import type { WebRuntime } from '@rafaelaugusto/jolt/web'
|
|
4
|
+
import type { WebMotionContext } from './motion-context.js'
|
|
5
|
+
|
|
6
|
+
/** Jolt owns deferred insertion and KeepAlive; the presentation borrows its region's runtime. */
|
|
7
|
+
export function useConnectedMotion(
|
|
8
|
+
element: Readonly<Ref<HTMLElement | null | undefined>>,
|
|
9
|
+
context: WebMotionContext,
|
|
10
|
+
setup: (runtime: WebRuntime, target: HTMLElement) => () => void,
|
|
11
|
+
) {
|
|
12
|
+
let lease: ReturnType<WebMotionContext['acquire']> | undefined
|
|
13
|
+
const motion = useWebMotion(element, {
|
|
14
|
+
get runtime() {
|
|
15
|
+
// Evaluated only by Jolt after attachment, never during SSR or pending Suspense.
|
|
16
|
+
if (!lease && element.value) lease = context.acquire(element.value.ownerDocument)
|
|
17
|
+
return lease?.runtime
|
|
18
|
+
},
|
|
19
|
+
})
|
|
20
|
+
motion.use((_, target) => setup(lease!.runtime, target))
|
|
21
|
+
// Registered after Jolt: dispose its scopes before releasing the borrowed runtime.
|
|
22
|
+
onScopeDispose(() => lease?.release())
|
|
23
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getCurrentScope, onScopeDispose } from 'vue'
|
|
2
|
+
import type { WebMotionScope, WebMotionResource } from '@rafaelaugusto/jolt/web'
|
|
3
|
+
import { regionState, type MotionRegion } from '@getcortexlabs/mavis-core/experimental'
|
|
4
|
+
import { webRegion } from './motion-region.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Web-only composition for application HTML/SVG inside a declared MBox region.
|
|
8
|
+
* Borrows the very same Jolt context as the region's component press surfaces.
|
|
9
|
+
* Setup is absent during SSR and recreated with its region and document lifecycle.
|
|
10
|
+
*/
|
|
11
|
+
export function useMavisWebMotion(
|
|
12
|
+
region: MotionRegion,
|
|
13
|
+
setup: (scope: WebMotionScope, element: HTMLElement) => void | WebMotionResource,
|
|
14
|
+
): () => void {
|
|
15
|
+
if (!getCurrentScope()) throw new Error('useMavisWebMotion requires a Vue setup scope.')
|
|
16
|
+
const stop = region.onAvailable(() => {
|
|
17
|
+
const { runtime, target } = webRegion(regionState(region).adapter)
|
|
18
|
+
const owner = runtime.scope()
|
|
19
|
+
try {
|
|
20
|
+
owner.use((scope) => setup(scope, target))
|
|
21
|
+
} catch (error) {
|
|
22
|
+
owner.dispose()
|
|
23
|
+
throw error
|
|
24
|
+
}
|
|
25
|
+
return () => owner.dispose()
|
|
26
|
+
})
|
|
27
|
+
onScopeDispose(stop)
|
|
28
|
+
return stop
|
|
29
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import { MNumberInput, MMultiSelect } from './components/configurator.js'
|
|
2
|
+
import { MImage } from './components/MImage.js'
|
|
3
|
+
import { MStack } from './components/MStack.js'
|
|
4
|
+
export { themeVariables, useMavisTokens } from './tokens.js'
|
|
5
|
+
import { MLink } from './components/MLink.js'
|
|
1
6
|
import { MDatePicker, MDateRangePicker } from './components/MDatePicker.js'
|
|
2
7
|
import { MCombobox } from './components/MCombobox.js'
|
|
3
8
|
import { MFilePicker } from './components/MFilePicker.js'
|
|
@@ -48,6 +53,8 @@ export {
|
|
|
48
53
|
MBox,
|
|
49
54
|
MRow,
|
|
50
55
|
MColumn,
|
|
56
|
+
MStack,
|
|
57
|
+
MLink,
|
|
51
58
|
MCard,
|
|
52
59
|
MText,
|
|
53
60
|
MButton,
|
|
@@ -76,6 +83,9 @@ export {
|
|
|
76
83
|
MSheet,
|
|
77
84
|
MDatePicker,
|
|
78
85
|
MDateRangePicker,
|
|
86
|
+
MNumberInput,
|
|
87
|
+
MMultiSelect,
|
|
88
|
+
MImage,
|
|
79
89
|
MCombobox,
|
|
80
90
|
MFilePicker,
|
|
81
91
|
MFormGroup,
|
|
@@ -117,6 +127,8 @@ export function createMavis(options: MavisOptions = {}) {
|
|
|
117
127
|
MBox,
|
|
118
128
|
MRow,
|
|
119
129
|
MColumn,
|
|
130
|
+
MStack,
|
|
131
|
+
MLink,
|
|
120
132
|
MCard,
|
|
121
133
|
MText,
|
|
122
134
|
MButton,
|
|
@@ -145,6 +157,9 @@ export function createMavis(options: MavisOptions = {}) {
|
|
|
145
157
|
MSheet,
|
|
146
158
|
MDatePicker,
|
|
147
159
|
MDateRangePicker,
|
|
160
|
+
MNumberInput,
|
|
161
|
+
MMultiSelect,
|
|
162
|
+
MImage,
|
|
148
163
|
MCombobox,
|
|
149
164
|
MFilePicker,
|
|
150
165
|
MFormGroup,
|
package/src/motion-region.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
onActivated,
|
|
3
|
-
onDeactivated,
|
|
4
|
-
onBeforeUnmount,
|
|
5
|
-
provide,
|
|
6
|
-
shallowRef,
|
|
7
|
-
watch,
|
|
8
|
-
type VNode,
|
|
9
|
-
} from 'vue'
|
|
1
|
+
import { onBeforeUnmount, provide, shallowRef, watch, type VNode } from 'vue'
|
|
10
2
|
import {
|
|
11
3
|
bindMotionRegion,
|
|
12
4
|
type MotionRegion,
|
|
@@ -16,6 +8,7 @@ import { createMotionContext, motionContextKey } from './motion-context.js'
|
|
|
16
8
|
import { webSurfaceTarget } from './motion-surface.js'
|
|
17
9
|
import { webScrollElement } from './scroll-motion.js'
|
|
18
10
|
import type { WebRuntime } from '@rafaelaugusto/jolt/web'
|
|
11
|
+
import { useConnectedMotion } from './connected-motion.js'
|
|
19
12
|
|
|
20
13
|
const regions = new WeakMap<MotionRegionAdapter, { target: HTMLElement; runtime: WebRuntime }>()
|
|
21
14
|
export function webRegion(adapter: MotionRegionAdapter) {
|
|
@@ -30,7 +23,67 @@ function regionAdapter(runtime: WebRuntime, target: HTMLElement): MotionRegionAd
|
|
|
30
23
|
throw new TypeError('Declare each surface inside this motion region.')
|
|
31
24
|
return value.target
|
|
32
25
|
}
|
|
26
|
+
const steps = (
|
|
27
|
+
items: readonly (
|
|
28
|
+
| import('@getcortexlabs/mavis-core/experimental').MotionStep<
|
|
29
|
+
import('@getcortexlabs/mavis-core/experimental').MotionSurfaceAdapter
|
|
30
|
+
>
|
|
31
|
+
| import('@getcortexlabs/mavis-core/experimental').MotionTimelineStep<
|
|
32
|
+
import('@getcortexlabs/mavis-core/experimental').MotionSurfaceAdapter
|
|
33
|
+
>
|
|
34
|
+
)[],
|
|
35
|
+
) =>
|
|
36
|
+
items.map((step) =>
|
|
37
|
+
typeof step === 'function' || 'run' in step
|
|
38
|
+
? step
|
|
39
|
+
: ([resolve(step[0]), step[1], step[2]] as const),
|
|
40
|
+
)
|
|
33
41
|
const adapter: MotionRegionAdapter = {
|
|
42
|
+
sequence: (items) =>
|
|
43
|
+
runtime.sequence(steps(items) as unknown as Parameters<WebRuntime['sequence']>[0]),
|
|
44
|
+
timeline: (items) =>
|
|
45
|
+
runtime.timeline(steps(items) as unknown as Parameters<WebRuntime['timeline']>[0]),
|
|
46
|
+
states(targets, definitions, options) {
|
|
47
|
+
const timing = (
|
|
48
|
+
input: import('@getcortexlabs/mavis-core/experimental').MotionStateTransition | undefined,
|
|
49
|
+
) => {
|
|
50
|
+
const { targets, ...transition } = input ?? {}
|
|
51
|
+
return { ...transition, ...targets }
|
|
52
|
+
}
|
|
53
|
+
const control = runtime.motionStates(
|
|
54
|
+
Object.fromEntries(
|
|
55
|
+
Object.entries(targets).map(([name, surface]) => [name, surface && resolve(surface)]),
|
|
56
|
+
),
|
|
57
|
+
Object.fromEntries(
|
|
58
|
+
Object.entries(definitions).map(([name, frames]) => [
|
|
59
|
+
name,
|
|
60
|
+
Object.fromEntries(
|
|
61
|
+
Object.entries(frames).filter(
|
|
62
|
+
(row): row is [string, NonNullable<(typeof row)[1]>] => row[1] !== undefined,
|
|
63
|
+
),
|
|
64
|
+
),
|
|
65
|
+
]),
|
|
66
|
+
),
|
|
67
|
+
{ transition: timing(options?.transition) },
|
|
68
|
+
)
|
|
69
|
+
return {
|
|
70
|
+
get current() {
|
|
71
|
+
return control.current
|
|
72
|
+
},
|
|
73
|
+
get settled() {
|
|
74
|
+
return control.settled
|
|
75
|
+
},
|
|
76
|
+
get paused() {
|
|
77
|
+
return control.paused
|
|
78
|
+
},
|
|
79
|
+
to: (name, transition) => control.to(name, timing(transition)),
|
|
80
|
+
attach: (name, surface) => control.attach(name, surface && resolve(surface)),
|
|
81
|
+
pause: () => control.pause(),
|
|
82
|
+
play: () => control.play(),
|
|
83
|
+
stop: () => control.stop(),
|
|
84
|
+
dispose: () => control.dispose(),
|
|
85
|
+
}
|
|
86
|
+
},
|
|
34
87
|
kind: 'web',
|
|
35
88
|
viewportEnter(surfaces, options) {
|
|
36
89
|
const control = runtime.viewportEnter(surfaces.map(resolve), {
|
|
@@ -89,48 +142,48 @@ function regionAdapter(runtime: WebRuntime, target: HTMLElement): MotionRegionAd
|
|
|
89
142
|
/** The MBox is the stable input/layout region, separate from every animated child. */
|
|
90
143
|
export function useMotionRegion(reference: () => MotionRegion | undefined) {
|
|
91
144
|
const declared = Boolean(reference())
|
|
145
|
+
if (!declared) {
|
|
146
|
+
watch(reference, (region) => {
|
|
147
|
+
if (region)
|
|
148
|
+
throw new Error('Declare motionRegion when mounting MBox; remount to add a region.')
|
|
149
|
+
})
|
|
150
|
+
return {}
|
|
151
|
+
}
|
|
92
152
|
const context = createMotionContext()
|
|
93
|
-
|
|
153
|
+
provide(motionContextKey, context)
|
|
94
154
|
const element = shallowRef<HTMLElement>()
|
|
95
|
-
let
|
|
96
|
-
release: (() => void) | undefined
|
|
155
|
+
let release: (() => void) | undefined
|
|
97
156
|
const clear = () => {
|
|
98
157
|
release?.()
|
|
99
158
|
release = undefined
|
|
100
159
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const lease = context.acquire(target.ownerDocument)
|
|
109
|
-
const adapter = regionAdapter(lease.runtime, target)
|
|
110
|
-
try {
|
|
111
|
-
const unbind = bindMotionRegion(region, adapter)
|
|
112
|
-
release = () => {
|
|
160
|
+
useConnectedMotion(element, context, (runtime, target) => {
|
|
161
|
+
const stop = watch(
|
|
162
|
+
reference,
|
|
163
|
+
(region) => {
|
|
164
|
+
clear()
|
|
165
|
+
if (!region) return
|
|
166
|
+
const adapter = regionAdapter(runtime, target)
|
|
113
167
|
try {
|
|
114
|
-
unbind()
|
|
115
|
-
|
|
168
|
+
const unbind = bindMotionRegion(region, adapter)
|
|
169
|
+
release = () => {
|
|
170
|
+
try {
|
|
171
|
+
unbind()
|
|
172
|
+
} finally {
|
|
173
|
+
regions.delete(adapter)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
} catch (error) {
|
|
116
177
|
regions.delete(adapter)
|
|
117
|
-
|
|
178
|
+
throw error
|
|
118
179
|
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
180
|
+
},
|
|
181
|
+
{ immediate: true, flush: 'post' },
|
|
182
|
+
)
|
|
183
|
+
return () => {
|
|
184
|
+
stop()
|
|
185
|
+
clear()
|
|
124
186
|
}
|
|
125
|
-
}
|
|
126
|
-
watch([element, reference], attach, { flush: 'post' })
|
|
127
|
-
onActivated(() => {
|
|
128
|
-
active = true
|
|
129
|
-
attach()
|
|
130
|
-
})
|
|
131
|
-
onDeactivated(() => {
|
|
132
|
-
active = false
|
|
133
|
-
clear()
|
|
134
187
|
})
|
|
135
188
|
onBeforeUnmount(clear)
|
|
136
189
|
return {
|