@getcortexlabs/mavis-web 0.1.0-alpha.5 → 0.1.0-alpha.6

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.
Files changed (121) hide show
  1. package/README.md +4 -4
  2. package/dist/components/MAccordion.d.ts +1 -1
  3. package/dist/components/MAlert.d.ts +1 -1
  4. package/dist/components/MAvatar.d.ts +1 -1
  5. package/dist/components/MButton.d.ts +55 -9
  6. package/dist/components/MButton.d.ts.map +1 -1
  7. package/dist/components/MButton.js +13 -8
  8. package/dist/components/MButton.js.map +1 -1
  9. package/dist/components/MCard.d.ts +49 -3
  10. package/dist/components/MCard.d.ts.map +1 -1
  11. package/dist/components/MCard.js +36 -30
  12. package/dist/components/MCard.js.map +1 -1
  13. package/dist/components/MCheckbox.d.ts +1 -1
  14. package/dist/components/MCheckbox.js +3 -3
  15. package/dist/components/MCheckbox.js.map +1 -1
  16. package/dist/components/MChip.d.ts +2 -2
  17. package/dist/components/MCombobox.d.ts +2 -2
  18. package/dist/components/MCombobox.js +3 -3
  19. package/dist/components/MCombobox.js.map +1 -1
  20. package/dist/components/MDatePicker.d.ts +56 -8
  21. package/dist/components/MDatePicker.d.ts.map +1 -1
  22. package/dist/components/MDatePicker.js +9 -0
  23. package/dist/components/MDatePicker.js.map +1 -1
  24. package/dist/components/MDialog.d.ts +1 -1
  25. package/dist/components/MEmptyState.d.ts +1 -1
  26. package/dist/components/MInput.d.ts +7 -7
  27. package/dist/components/MInput.js +3 -3
  28. package/dist/components/MInput.js.map +1 -1
  29. package/dist/components/MLink.d.ts +120 -0
  30. package/dist/components/MLink.d.ts.map +1 -0
  31. package/dist/components/MLink.js +75 -0
  32. package/dist/components/MLink.js.map +1 -0
  33. package/dist/components/MListItem.d.ts +3 -1
  34. package/dist/components/MListItem.d.ts.map +1 -1
  35. package/dist/components/MProgress.d.ts +1 -1
  36. package/dist/components/MRadioGroup.d.ts +1 -1
  37. package/dist/components/MReveal.d.ts +2 -2
  38. package/dist/components/MReveal.d.ts.map +1 -1
  39. package/dist/components/MReveal.js +39 -50
  40. package/dist/components/MReveal.js.map +1 -1
  41. package/dist/components/MSegmentedControl.d.ts +1 -1
  42. package/dist/components/MSelect.d.ts +1 -1
  43. package/dist/components/MSheet.d.ts +1 -1
  44. package/dist/components/MSlider.d.ts +1 -1
  45. package/dist/components/MStack.d.ts +198 -0
  46. package/dist/components/MStack.d.ts.map +1 -0
  47. package/dist/components/MStack.js +62 -0
  48. package/dist/components/MStack.js.map +1 -0
  49. package/dist/components/MSwitch.d.ts +1 -1
  50. package/dist/components/MSwitch.js +3 -3
  51. package/dist/components/MSwitch.js.map +1 -1
  52. package/dist/components/MTabs.d.ts +1 -1
  53. package/dist/components/MText.d.ts +3 -3
  54. package/dist/components/MText.js +6 -6
  55. package/dist/components/MText.js.map +1 -1
  56. package/dist/components/layout.d.ts +179 -2
  57. package/dist/components/layout.d.ts.map +1 -1
  58. package/dist/components/layout.js +10 -10
  59. package/dist/components/layout.js.map +1 -1
  60. package/dist/connected-motion.d.ts +6 -0
  61. package/dist/connected-motion.d.ts.map +1 -0
  62. package/dist/connected-motion.js +18 -0
  63. package/dist/connected-motion.js.map +1 -0
  64. package/dist/experimental.d.ts +9 -0
  65. package/dist/experimental.d.ts.map +1 -0
  66. package/dist/experimental.js +27 -0
  67. package/dist/experimental.js.map +1 -0
  68. package/dist/index.d.ts +4 -1
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +6 -1
  71. package/dist/index.js.map +1 -1
  72. package/dist/motion-region.d.ts +3 -0
  73. package/dist/motion-region.d.ts.map +1 -1
  74. package/dist/motion-region.js +69 -39
  75. package/dist/motion-region.js.map +1 -1
  76. package/dist/motion-surface.d.ts.map +1 -1
  77. package/dist/motion-surface.js +4 -0
  78. package/dist/motion-surface.js.map +1 -1
  79. package/dist/motion.d.ts +2 -2
  80. package/dist/motion.d.ts.map +1 -1
  81. package/dist/motion.js +8 -27
  82. package/dist/motion.js.map +1 -1
  83. package/dist/navigation.d.ts +12 -0
  84. package/dist/navigation.d.ts.map +1 -0
  85. package/dist/navigation.js +38 -0
  86. package/dist/navigation.js.map +1 -0
  87. package/dist/reveal-motion.d.ts +5 -0
  88. package/dist/reveal-motion.d.ts.map +1 -0
  89. package/dist/reveal-motion.js +53 -0
  90. package/dist/reveal-motion.js.map +1 -0
  91. package/dist/scroll-motion.d.ts.map +1 -1
  92. package/dist/scroll-motion.js +16 -14
  93. package/dist/scroll-motion.js.map +1 -1
  94. package/dist/tokens.d.ts +7 -0
  95. package/dist/tokens.d.ts.map +1 -0
  96. package/dist/tokens.js +29 -0
  97. package/dist/tokens.js.map +1 -0
  98. package/package.json +7 -3
  99. package/src/components/MButton.ts +17 -7
  100. package/src/components/MCard.ts +45 -27
  101. package/src/components/MCheckbox.ts +3 -3
  102. package/src/components/MCombobox.ts +3 -3
  103. package/src/components/MDatePicker.ts +8 -0
  104. package/src/components/MInput.ts +3 -3
  105. package/src/components/MLink.ts +85 -0
  106. package/src/components/MReveal.ts +57 -64
  107. package/src/components/MStack.ts +90 -0
  108. package/src/components/MSwitch.ts +3 -3
  109. package/src/components/MText.ts +6 -6
  110. package/src/components/layout.ts +10 -10
  111. package/src/connected-motion.ts +23 -0
  112. package/src/experimental.ts +29 -0
  113. package/src/index.ts +7 -0
  114. package/src/motion-region.ts +94 -41
  115. package/src/motion-surface.ts +12 -1
  116. package/src/motion.ts +10 -40
  117. package/src/navigation.ts +44 -0
  118. package/src/reveal-motion.ts +59 -0
  119. package/src/scroll-motion.ts +16 -15
  120. package/src/style.css +6 -0
  121. package/src/tokens.ts +29 -0
@@ -0,0 +1,85 @@
1
+ import { defineComponent, h, mergeProps } from 'vue'
2
+ import { fontFamily, linkDestination, linkRel, nonNegative } from '@getcortexlabs/mavis-core'
3
+ import {
4
+ linkProps,
5
+ linkEmits,
6
+ textContent,
7
+ useLayoutShrink,
8
+ useMavisTheme,
9
+ viewAttrs,
10
+ } from '@getcortexlabs/mavis-core/vue'
11
+ import { webAttrs } from '../style.js'
12
+
13
+ export const MLink = defineComponent({
14
+ name: 'MLink',
15
+ inheritAttrs: false,
16
+ props: linkProps,
17
+ emits: linkEmits,
18
+ setup(props, { attrs, slots, emit }) {
19
+ const { theme } = useMavisTheme()
20
+ const shrink = useLayoutShrink()
21
+ return () => {
22
+ const href = linkDestination(props.href)
23
+ const text = props.text ?? textContent(slots.default?.())
24
+ if (!(props.accessibilityLabel ?? text).trim()) throw new TypeError('MLink requires a name.')
25
+ const type = theme.value.typography.body
26
+ return h(
27
+ 'a',
28
+ mergeProps(webAttrs({ ...attrs, ...viewAttrs(props) }), {
29
+ 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
+ style: {
37
+ '--m-focus': theme.value.colors.primary,
38
+ display: props.inline ? 'inline' : 'inline-flex',
39
+ alignItems: 'center',
40
+ justifyContent: 'center',
41
+ minHeight: props.inline ? undefined : '44px',
42
+ fontFamily: fontFamily(type.fontFamily, 'web'),
43
+ fontSize: `${type.fontSize}px`,
44
+ fontWeight: type.fontWeight,
45
+ lineHeight: type.lineHeight,
46
+ color: theme.value.colors.primary,
47
+ textDecoration: 'underline',
48
+ textUnderlineOffset: '0.18em',
49
+ cursor: props.disabled ? 'default' : 'pointer',
50
+ opacity: props.disabled ? 0.45 : 1,
51
+ overflowWrap: 'anywhere',
52
+ flexGrow: nonNegative(props.grow, 'grow'),
53
+ flexShrink: nonNegative(props.shrink ?? shrink.value, 'shrink'),
54
+ minWidth: 0,
55
+ },
56
+ onClick(event: MouseEvent) {
57
+ if (props.disabled) {
58
+ event.preventDefault()
59
+ return
60
+ }
61
+ if (event.defaultPrevented) return
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
+ },
80
+ }),
81
+ text,
82
+ )
83
+ }
84
+ },
85
+ })
@@ -1,80 +1,73 @@
1
+ import { defineComponent, h, mergeProps, onActivated, onDeactivated } from 'vue'
1
2
  import {
2
- defineComponent,
3
- onActivated,
4
- onDeactivated,
5
- h,
6
- mergeProps,
7
- Transition,
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 { revealMotion } from '@getcortexlabs/mavis-core'
13
- import { useWebMotion } from '@rafaelaugusto/jolt/web/vue'
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 target = shallowRef<HTMLElement | null>(null)
21
- const motion = useWebMotion(target, {
22
- initial: { opacity: revealMotion.enter[0].opacity[0], y: revealMotion.enter[0].y[0] },
23
- enter: { keyframes: { opacity: 1, y: 0 }, transition: revealMotion.enter[1] },
24
- leave: { keyframes: revealMotion.leave[0], transition: revealMotion.leave[1] },
25
- })
26
- let mounted: HTMLElement | null = null
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
- target.value = null
36
+ state.detach()
37
+ mounted = undefined
29
38
  })
30
39
  onActivated(() => {
31
- target.value = mounted
40
+ if (retained) return attach(retained)
32
41
  })
33
- let trigger: HTMLElement | undefined
34
42
  return () => {
35
- const { show, ...layout } = props
36
- return h(
37
- Transition,
38
- {
39
- ...motion.transition,
40
- onBeforeEnter: (element: Element) => {
41
- if (typeof HTMLElement === 'undefined' || !(element instanceof HTMLElement)) return
42
- if (!props.accessibilityHidden) {
43
- element.removeAttribute('inert')
44
- element.removeAttribute('aria-hidden')
45
- }
46
- trigger =
47
- document.activeElement instanceof HTMLElement ? document.activeElement : undefined
48
- },
49
- onBeforeLeave: (element: Element) => {
50
- if (typeof HTMLElement === 'undefined' || !(element instanceof HTMLElement)) return
51
- if (element.contains(document.activeElement) && trigger?.isConnected)
52
- trigger.focus({ preventScroll: true })
53
- // The leaving animation must not leave hidden controls in the tab order.
54
- element.setAttribute('inert', '')
55
- element.setAttribute('aria-hidden', 'true')
56
- trigger = undefined
57
- },
58
- },
59
- {
60
- default: () =>
61
- show
62
- ? h(
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
+ })
@@ -5,7 +5,7 @@ import {
5
5
  switchProps,
6
6
  switchEmits,
7
7
  useMavisTheme,
8
- useDefaultShrink,
8
+ useLayoutShrink,
9
9
  } from '@getcortexlabs/mavis-core/vue'
10
10
  import { nonNegative, resolveDimension } from '@getcortexlabs/mavis-core'
11
11
  import { length, webAttrs } from '../style.js'
@@ -18,7 +18,7 @@ export const MSwitch = defineComponent({
18
18
  setup(props, { attrs, emit }) {
19
19
  useButtonAction()
20
20
  const { theme } = useMavisTheme()
21
- const shrink = useDefaultShrink()
21
+ const shrink = useLayoutShrink()
22
22
  const labelId = `m-switch-${useId()}`
23
23
  return () => {
24
24
  const { colors, space, typography, radius } = theme.value
@@ -47,7 +47,7 @@ export const MSwitch = defineComponent({
47
47
  lineHeight: 1.5,
48
48
  opacity: props.disabled ? 0.45 : 1,
49
49
  flexGrow: nonNegative(props.grow, 'grow'),
50
- flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
50
+ flexShrink: nonNegative(props.shrink ?? shrink.value, 'shrink'),
51
51
  width: length(resolveDimension(props.width)),
52
52
  '--m-focus': colors.primary,
53
53
  '--m-switch-track': props.modelValue ? colors.primary : colors.muted,
@@ -3,7 +3,7 @@ import {
3
3
  textProps,
4
4
  useMavisTheme,
5
5
  inlineContent,
6
- useDefaultShrink,
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 = useDefaultShrink()
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
  },
@@ -4,7 +4,7 @@ import {
4
4
  viewAttrs,
5
5
  useMavisTheme,
6
6
  layoutDirection,
7
- useDefaultShrink,
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 = useDefaultShrink()
38
+ const shrink = useLayoutShrink()
39
39
  provide(layoutDirection, direction)
40
40
  return () =>
41
41
  h(
42
- 'div',
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: `${resolveSpace(theme.value, props.gap ?? 'none')}px`,
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 = useDefaultShrink()
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,6 @@
1
+ import { MStack } from './components/MStack.js'
2
+ export { themeVariables, useMavisTokens } from './tokens.js'
3
+ import { MLink } from './components/MLink.js'
1
4
  import { MDatePicker, MDateRangePicker } from './components/MDatePicker.js'
2
5
  import { MCombobox } from './components/MCombobox.js'
3
6
  import { MFilePicker } from './components/MFilePicker.js'
@@ -48,6 +51,8 @@ export {
48
51
  MBox,
49
52
  MRow,
50
53
  MColumn,
54
+ MStack,
55
+ MLink,
51
56
  MCard,
52
57
  MText,
53
58
  MButton,
@@ -117,6 +122,8 @@ export function createMavis(options: MavisOptions = {}) {
117
122
  MBox,
118
123
  MRow,
119
124
  MColumn,
125
+ MStack,
126
+ MLink,
120
127
  MCard,
121
128
  MText,
122
129
  MButton,