@getcortexlabs/mavis 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.
Files changed (131) hide show
  1. package/README.md +5 -7
  2. package/dist/app-icons.d.ts +26 -0
  3. package/dist/app-icons.d.ts.map +1 -0
  4. package/dist/app-icons.js +9 -0
  5. package/dist/app-icons.js.map +1 -0
  6. package/dist/native/app-icons.android.d.ts +4 -0
  7. package/dist/native/app-icons.android.d.ts.map +1 -0
  8. package/dist/native/app-icons.android.js +67 -0
  9. package/dist/native/app-icons.android.js.map +1 -0
  10. package/dist/native/app-icons.d.ts +4 -0
  11. package/dist/native/app-icons.d.ts.map +1 -0
  12. package/dist/native/app-icons.ios.d.ts +4 -0
  13. package/dist/native/app-icons.ios.d.ts.map +1 -0
  14. package/dist/native/app-icons.ios.js +45 -0
  15. package/dist/native/app-icons.ios.js.map +1 -0
  16. package/dist/native/app-icons.js +9 -0
  17. package/dist/native/app-icons.js.map +1 -0
  18. package/dist/native/motion-owner.d.ts.map +1 -1
  19. package/dist/native/motion-owner.js +5 -0
  20. package/dist/native/motion-owner.js.map +1 -1
  21. package/dist/native/motion-region.d.ts.map +1 -1
  22. package/dist/native/motion-region.js +39 -1
  23. package/dist/native/motion-region.js.map +1 -1
  24. package/dist/native/motion-surface.d.ts +1 -1
  25. package/dist/native/motion-surface.d.ts.map +1 -1
  26. package/dist/native/motion-surface.js +36 -3
  27. package/dist/native/motion-surface.js.map +1 -1
  28. package/dist/native/press.d.ts +5 -2
  29. package/dist/native/press.d.ts.map +1 -1
  30. package/dist/native/press.js +6 -0
  31. package/dist/native/press.js.map +1 -1
  32. package/dist/vue/components/ChoiceControl.d.ts.map +1 -1
  33. package/dist/vue/components/ChoiceControl.js +20 -5
  34. package/dist/vue/components/ChoiceControl.js.map +1 -1
  35. package/dist/vue/components/DateCalendar.d.ts +3 -3
  36. package/dist/vue/components/MButton.d.ts +49 -3
  37. package/dist/vue/components/MButton.d.ts.map +1 -1
  38. package/dist/vue/components/MButton.js +20 -13
  39. package/dist/vue/components/MButton.js.map +1 -1
  40. package/dist/vue/components/MCard.d.ts +47 -1
  41. package/dist/vue/components/MCard.d.ts.map +1 -1
  42. package/dist/vue/components/MCard.js +12 -5
  43. package/dist/vue/components/MCard.js.map +1 -1
  44. package/dist/vue/components/MChip.d.ts +2 -2
  45. package/dist/vue/components/MDatePicker.d.ts +72 -24
  46. package/dist/vue/components/MDatePicker.d.ts.map +1 -1
  47. package/dist/vue/components/MDialog.d.ts +1 -1
  48. package/dist/vue/components/MEmptyState.d.ts +1 -1
  49. package/dist/vue/components/MFilePicker.d.ts +2 -2
  50. package/dist/vue/components/MImage.d.ts +192 -0
  51. package/dist/vue/components/MImage.d.ts.map +1 -0
  52. package/dist/vue/components/MImage.js +102 -0
  53. package/dist/vue/components/MImage.js.map +1 -0
  54. package/dist/vue/components/MInput.d.ts +3 -3
  55. package/dist/vue/components/MInput.d.ts.map +1 -1
  56. package/dist/vue/components/MInput.js +12 -8
  57. package/dist/vue/components/MInput.js.map +1 -1
  58. package/dist/vue/components/MLink.d.ts +120 -0
  59. package/dist/vue/components/MLink.d.ts.map +1 -0
  60. package/dist/vue/components/MLink.js +81 -0
  61. package/dist/vue/components/MLink.js.map +1 -0
  62. package/dist/vue/components/MListItem.d.ts +2 -0
  63. package/dist/vue/components/MListItem.d.ts.map +1 -1
  64. package/dist/vue/components/MProgress.d.ts +1 -1
  65. package/dist/vue/components/MReveal.d.ts +2 -2
  66. package/dist/vue/components/MReveal.d.ts.map +1 -1
  67. package/dist/vue/components/MReveal.js +80 -35
  68. package/dist/vue/components/MReveal.js.map +1 -1
  69. package/dist/vue/components/MSheet.d.ts +1 -1
  70. package/dist/vue/components/MStack.d.ts +199 -0
  71. package/dist/vue/components/MStack.d.ts.map +1 -0
  72. package/dist/vue/components/MStack.js +62 -0
  73. package/dist/vue/components/MStack.js.map +1 -0
  74. package/dist/vue/components/MSwitch.d.ts.map +1 -1
  75. package/dist/vue/components/MSwitch.js +13 -3
  76. package/dist/vue/components/MSwitch.js.map +1 -1
  77. package/dist/vue/components/MText.js +3 -3
  78. package/dist/vue/components/MText.js.map +1 -1
  79. package/dist/vue/components/configurator.d.ts +541 -0
  80. package/dist/vue/components/configurator.d.ts.map +1 -0
  81. package/dist/vue/components/configurator.js +24 -0
  82. package/dist/vue/components/configurator.js.map +1 -0
  83. package/dist/vue/components/layout.d.ts +3 -3
  84. package/dist/vue/components/layout.d.ts.map +1 -1
  85. package/dist/vue/components/layout.js +5 -5
  86. package/dist/vue/components/layout.js.map +1 -1
  87. package/dist/vue/components/workflows.d.ts +1 -1
  88. package/dist/vue/index.d.ts +5 -1
  89. package/dist/vue/index.d.ts.map +1 -1
  90. package/dist/vue/index.js +10 -1
  91. package/dist/vue/index.js.map +1 -1
  92. package/dist/vue/navigation.d.ts +4 -0
  93. package/dist/vue/navigation.d.ts.map +1 -0
  94. package/dist/vue/navigation.js +16 -0
  95. package/dist/vue/navigation.js.map +1 -0
  96. package/dist/vue/use-choice-paint.d.ts +9 -0
  97. package/dist/vue/use-choice-paint.d.ts.map +1 -0
  98. package/dist/vue/use-choice-paint.js +32 -0
  99. package/dist/vue/use-choice-paint.js.map +1 -0
  100. package/dist/vue/use-press.js +3 -3
  101. package/dist/vue/use-press.js.map +1 -1
  102. package/package.json +7 -3
  103. package/src/app-icons.ts +21 -0
  104. package/src/native/app-icons.android.ts +95 -0
  105. package/src/native/app-icons.ios.ts +74 -0
  106. package/src/native/app-icons.ts +12 -0
  107. package/src/native/motion-owner.ts +7 -0
  108. package/src/native/motion-region.ts +63 -1
  109. package/src/native/motion-surface.ts +41 -2
  110. package/src/native/press.ts +9 -3
  111. package/src/vue/components/ChoiceControl.ts +25 -5
  112. package/src/vue/components/MButton.ts +20 -10
  113. package/src/vue/components/MCard.ts +22 -5
  114. package/src/vue/components/MImage.ts +117 -0
  115. package/src/vue/components/MInput.ts +12 -8
  116. package/src/vue/components/MLink.ts +96 -0
  117. package/src/vue/components/MReveal.ts +89 -47
  118. package/src/vue/components/MStack.ts +83 -0
  119. package/src/vue/components/MSwitch.ts +16 -3
  120. package/src/vue/components/MText.ts +3 -3
  121. package/src/vue/components/configurator.ts +27 -0
  122. package/src/vue/components/layout.ts +10 -5
  123. package/src/vue/index.ts +14 -0
  124. package/src/vue/navigation.ts +15 -0
  125. package/src/vue/use-choice-paint.ts +39 -0
  126. package/src/vue/use-press.ts +3 -3
  127. package/dist/vue/reveal-motion.d.ts +0 -13
  128. package/dist/vue/reveal-motion.d.ts.map +0 -1
  129. package/dist/vue/reveal-motion.js +0 -55
  130. package/dist/vue/reveal-motion.js.map +0 -1
  131. package/src/vue/reveal-motion.ts +0 -61
@@ -1,11 +1,16 @@
1
1
  import type { EventData, TouchGestureEventData, View } from '@nativescript/core'
2
2
  import { animate, stop, onReducedMotion } from '@rafaelaugusto/jolt'
3
- import { pressMotion } from '@getcortexlabs/mavis-core'
3
+ import { pressMotion, type MotionTheme } from '@getcortexlabs/mavis-core'
4
4
 
5
+ const pressCallbacks = new WeakSet<Function>()
6
+ /** Internal diagnostics distinguish animation input from a control's own touch behavior. */
7
+ export function isPressFeedbackCallback(callback: unknown) {
8
+ return typeof callback === 'function' && pressCallbacks.has(callback)
9
+ }
5
10
  let nextLayer = 0
6
11
 
7
12
  /** Press multiplies the app's scale; releasing it removes only that contribution. */
8
- export function attachPressFeedback(view: View, scale: number) {
13
+ export function attachPressFeedback(view: View, scale: number | Readonly<MotionTheme>) {
9
14
  let motion = pressMotion(scale)
10
15
  // Each attachment owns its channel, including after a theme change or reload.
11
16
  const layer = `mavis-press-${++nextLayer}`
@@ -41,13 +46,14 @@ export function attachPressFeedback(view: View, scale: number) {
41
46
  animate(view, motion[pressed ? 'pressed' : 'released'][0], { duration: 0, layer })
42
47
  }
43
48
  })
49
+ pressCallbacks.add(onTouch)
44
50
  view.on('touch', onTouch)
45
51
  view.on('unloaded', remove)
46
52
  return Object.assign(remove, {
47
53
  press(pressed: boolean) {
48
54
  onTouch({ action: pressed ? 'down' : 'cancel' } as TouchGestureEventData)
49
55
  },
50
- update(scale: number) {
56
+ update(scale: number | Readonly<MotionTheme>) {
51
57
  motion = pressMotion(scale)
52
58
  if (pressed && !disposed) animate(view, motion.pressed[0], { ...motion.pressed[1], layer })
53
59
  },
@@ -1,3 +1,4 @@
1
+ import { useChoicePaint } from '../use-choice-paint.js'
1
2
  import {
2
3
  defineComponent,
3
4
  h,
@@ -27,7 +28,21 @@ export const ChoiceControl = defineComponent({
27
28
  setup(props, { attrs, emit }) {
28
29
  const { theme } = useMavisTheme()
29
30
  const nativeAttrs = useNativeViewAttrs(props)
31
+ const paint = useChoicePaint(
32
+ () => ({
33
+ borderColor:
34
+ props.modelValue || props.indeterminate
35
+ ? theme.value.colors.primary
36
+ : theme.value.colors.muted,
37
+ backgroundColor:
38
+ !props.radio && (props.modelValue || props.indeterminate)
39
+ ? theme.value.colors.primary
40
+ : 'transparent',
41
+ }),
42
+ theme,
43
+ )
30
44
  const focused = ref(false)
45
+ let touchView: View | undefined
31
46
  let mark: View | undefined
32
47
  let motion: ReturnType<typeof animate> | undefined
33
48
  let observer: ReturnType<typeof observeCheckbox> | undefined
@@ -41,6 +56,8 @@ export const ChoiceControl = defineComponent({
41
56
  }
42
57
  }
43
58
  function unload() {
59
+ touchView?.off('touch', touch)
60
+ touchView = undefined
44
61
  restore()
45
62
  observer?.dispose()
46
63
  observer = undefined
@@ -60,8 +77,9 @@ export const ChoiceControl = defineComponent({
60
77
  { flush: 'post' },
61
78
  )
62
79
 
63
- function touch(event: TouchGestureEventData) {
64
- if (!mark || props.disabled) return
80
+ function touch(data: EventData) {
81
+ const event = data as TouchGestureEventData
82
+ if (!mark || props.disabled || !props.pressFeedback) return
65
83
  if (!['down', 'up', 'cancel'].includes(event.action)) return
66
84
  motion?.stop()
67
85
  const scale = event.action === 'down' ? 0.9 : 1
@@ -123,9 +141,10 @@ export const ChoiceControl = defineComponent({
123
141
  onTap: () => {
124
142
  if (!props.disabled) emit('activate')
125
143
  },
126
- onTouch: props.pressFeedback ? touch : undefined,
127
144
  onLoaded: (event: EventData) => {
128
145
  unload()
146
+ touchView = event.object as View
147
+ touchView.on('touch', touch)
129
148
  observer = observeCheckbox(event.object as View, (value) => {
130
149
  focused.value = value
131
150
  })
@@ -154,14 +173,15 @@ export const ChoiceControl = defineComponent({
154
173
  accessibilityHidden: true,
155
174
  style: {
156
175
  borderWidth: 2,
157
- borderColor: selected ? colors.primary : colors.muted,
158
- backgroundColor: !props.radio && selected ? colors.primary : 'transparent',
176
+ ...paint.style,
159
177
  },
160
178
  onLoaded: (event: EventData) => {
161
179
  mark = event.object as View
180
+ paint.onLoaded(event)
162
181
  },
163
182
  onUnloaded: () => {
164
183
  restore()
184
+ paint.onUnloaded()
165
185
  mark = undefined
166
186
  },
167
187
  },
@@ -1,3 +1,4 @@
1
+ import { nativeDestination, navigateNative } from '../navigation.js'
1
2
  import { MRow } from './layout.js'
2
3
  import { MText } from './MText.js'
3
4
  import { MIcon } from './MIcon.js'
@@ -21,7 +22,7 @@ import {
21
22
  useMavisTheme,
22
23
  actionEmits,
23
24
  textContent,
24
- useDefaultShrink,
25
+ useLayoutShrink,
25
26
  } from '@getcortexlabs/mavis-core/vue'
26
27
  import {
27
28
  fontFamily,
@@ -55,7 +56,7 @@ export const MButton = defineComponent({
55
56
  useButtonAction()
56
57
  const { theme } = useMavisTheme()
57
58
  const nativeAttrs = useNativeViewAttrs(props)
58
- const shrink = useDefaultShrink()
59
+ const shrink = useLayoutShrink()
59
60
  const enabled = () => !props.disabled && !props.loading
60
61
  const keyboardPressed = ref(false)
61
62
  const lifecycle = usePressFeedback(enabled, theme, keyboardPressed)
@@ -68,7 +69,14 @@ export const MButton = defineComponent({
68
69
  focused.value = false
69
70
  }
70
71
  onBeforeUnmount(clearFocus)
72
+ const activate = () => {
73
+ if (!enabled() || !allowsActivation()) return
74
+ emit('click')
75
+ if (props.href !== undefined)
76
+ void navigateNative(props).catch((error) => emit('error', error))
77
+ }
71
78
  return () => {
79
+ if (props.href !== undefined) nativeDestination(props)
72
80
  const { colors, control, radius } = theme.value
73
81
  const tokens = theme.value.components.button
74
82
  const family = fontFamily(
@@ -82,7 +90,9 @@ export const MButton = defineComponent({
82
90
  : (props.text ?? textContent(slots.default?.()))
83
91
  const leading = buttonContent(slots.leading?.())
84
92
  const trailing = buttonContent(slots.trailing?.())
85
- const composed = Boolean(slots.leading || slots.trailing)
93
+ const composed = Boolean(
94
+ slots.leading || slots.trailing || (isAndroid && (props.icon || props.trailingIcon)),
95
+ )
86
96
  const hasIcon = Boolean(composed || props.icon || props.trailingIcon)
87
97
  checkIconOnly(text, hasIcon, props.accessibilityLabel)
88
98
  const iconSize = iconSizes[props.size]
@@ -135,7 +145,7 @@ export const MButton = defineComponent({
135
145
  : shadowStyle(theme.value.elevation[tokens.elevation], 'native'),
136
146
  opacity: props.disabled ? 0.45 : 1,
137
147
  flexGrow: nonNegative(props.grow, 'grow'),
138
- flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
148
+ flexShrink: nonNegative(props.shrink ?? shrink.value, 'shrink'),
139
149
  },
140
150
  },
141
151
  nativeAttrs(),
@@ -145,12 +155,12 @@ export const MButton = defineComponent({
145
155
  {
146
156
  isEnabled: enabled(),
147
157
  accessible: true,
148
- accessibilityRole: 'button',
158
+ accessibilityRole: props.href === undefined ? 'button' : 'link',
149
159
  accessibilityState: enabled() ? '' : 'disabled',
150
160
  accessibilityLabel: props.accessibilityLabel ?? text,
151
161
  accessibilityValue: props.accessibilityLabel ? text : undefined,
152
162
  onTap: () => {
153
- if (enabled() && allowsActivation()) emit('click')
163
+ activate()
154
164
  },
155
165
  onLoaded: (event: EventData) => {
156
166
  clearFocus()
@@ -160,7 +170,7 @@ export const MButton = defineComponent({
160
170
  focused.value = value
161
171
  },
162
172
  () => {
163
- if (enabled() && allowsActivation()) emit('click')
173
+ activate()
164
174
  },
165
175
  (value) => {
166
176
  keyboardPressed.value = value
@@ -246,7 +256,7 @@ export const MButton = defineComponent({
246
256
  margin: 0,
247
257
  opacity: props.disabled ? 0.45 : 1,
248
258
  flexGrow: nonNegative(props.grow, 'grow'),
249
- flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
259
+ flexShrink: nonNegative(props.shrink ?? shrink.value, 'shrink'),
250
260
  minWidth: isAndroid ? 48 : 44,
251
261
  },
252
262
  },
@@ -257,13 +267,13 @@ export const MButton = defineComponent({
257
267
  {
258
268
  isEnabled: enabled(),
259
269
  accessible: true,
260
- accessibilityRole: 'button',
270
+ accessibilityRole: props.href === undefined ? 'button' : 'link',
261
271
  accessibilityState: enabled() ? '' : 'disabled',
262
272
  accessibilityLabel: props.accessibilityLabel ?? text,
263
273
  accessibilityValue:
264
274
  attrs.accessibilityValue ?? (props.accessibilityLabel ? text : undefined),
265
275
  onTap: () => {
266
- if (enabled() && allowsActivation()) emit('click')
276
+ activate()
267
277
  },
268
278
  },
269
279
  ),
@@ -1,3 +1,4 @@
1
+ import { nativeDestination, navigateNative } from '../navigation.js'
1
2
  import { resolveSpace, resolveRadius, shadowStyle } from '@getcortexlabs/mavis-core'
2
3
  import { ActionChildren } from '../accessibility.js'
3
4
  import { defineComponent, h, mergeProps } from 'nativescript-vue'
@@ -17,16 +18,28 @@ export const MCard = defineComponent({
17
18
  props: cardProps,
18
19
  emits: actionEmits,
19
20
  setup(props, { attrs, slots, emit }) {
20
- useButtonAction(() => props.interactive)
21
+ useButtonAction(() => props.interactive || props.href !== undefined)
21
22
  const { theme } = useMavisTheme()
22
- const enabled = () => props.interactive && !props.disabled
23
+ const enabled = () => (props.interactive || props.href !== undefined) && !props.disabled
23
24
  const lifecycle = usePressFeedback(enabled, theme)
24
25
  const { allowsActivation, ...surface } = useMotionSurface(
25
26
  () => props.motionSurface,
26
27
  () => !props.disabled,
27
28
  )
28
29
  return () => {
29
- const { interactive, disabled, elevation, motionSurface, ...layout } = props
30
+ const {
31
+ interactive: action,
32
+ disabled,
33
+ elevation,
34
+ motionSurface,
35
+ href,
36
+ navigate,
37
+ target,
38
+ rel,
39
+ ...layout
40
+ } = props
41
+ const interactive = action || href !== undefined
42
+ if (href !== undefined) nativeDestination(props)
30
43
  const tokens = theme.value.components.card
31
44
  layout.padding ??= tokens.padding
32
45
  layout.radius ??= tokens.radius
@@ -51,11 +64,15 @@ export const MCard = defineComponent({
51
64
  surface,
52
65
  {
53
66
  accessible: interactive,
54
- accessibilityRole: interactive ? 'button' : '',
67
+ accessibilityRole: href !== undefined ? 'link' : interactive ? 'button' : '',
55
68
  accessibilityState: interactive && disabled ? 'disabled' : '',
56
69
  onTap: interactive
57
70
  ? () => {
58
- if (enabled() && allowsActivation()) emit('click')
71
+ if (enabled() && allowsActivation()) {
72
+ emit('click')
73
+ if (href !== undefined)
74
+ void navigateNative(props).catch((error) => emit('error', error))
75
+ }
59
76
  }
60
77
  : undefined,
61
78
  },
@@ -0,0 +1,117 @@
1
+ import {
2
+ defineComponent,
3
+ h,
4
+ mergeProps,
5
+ onBeforeUnmount,
6
+ ref,
7
+ shallowRef,
8
+ watch,
9
+ } from 'nativescript-vue'
10
+ import type { EventData, View, ImageSource } from '@nativescript/core'
11
+ import { imageProps, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
12
+ import { resolveRadius } from '@getcortexlabs/mavis-core'
13
+ import { loadAvatarImage } from '../../native/avatar-image'
14
+ import { MBox } from './layout.js'
15
+ import { MText } from './MText.js'
16
+
17
+ export const MImage = defineComponent({
18
+ name: 'MImage',
19
+ inheritAttrs: false,
20
+ props: imageProps,
21
+ emits: { load: (_src: string) => true, error: (_src: string) => true },
22
+ setup(props, { attrs, emit }) {
23
+ const { theme } = useMavisTheme()
24
+ const image = shallowRef<ImageSource | null>(null)
25
+ const status = ref<'loading' | 'ready' | 'error'>('loading')
26
+ const width = ref(typeof props.width === 'number' ? props.width : 0)
27
+ let generation = 0,
28
+ loaded = false
29
+ async function load() {
30
+ const current = ++generation,
31
+ src = props.src
32
+ image.value = null
33
+ status.value = src.trim() ? 'loading' : 'error'
34
+ if (!loaded || !src.trim()) return
35
+ try {
36
+ const result = await loadAvatarImage(src.trim())
37
+ if (current !== generation || !loaded) return
38
+ if (!result || result.width <= 0 || result.height <= 0)
39
+ throw new Error('Image could not be decoded.')
40
+ image.value = result
41
+ status.value = 'ready'
42
+ emit('load', src)
43
+ } catch {
44
+ if (current !== generation || !loaded) return
45
+ status.value = 'error'
46
+ emit('error', src)
47
+ }
48
+ }
49
+ function unload() {
50
+ loaded = false
51
+ generation++
52
+ image.value = null
53
+ }
54
+ watch(
55
+ () => props.src,
56
+ () => {
57
+ void load()
58
+ },
59
+ )
60
+ onBeforeUnmount(unload)
61
+ return () => {
62
+ if (!Number.isFinite(props.aspectRatio) || props.aspectRatio <= 0)
63
+ throw new RangeError('aspectRatio must be finite and positive.')
64
+ const radius = resolveRadius(theme.value, props.radius)
65
+ return h(
66
+ MBox,
67
+ mergeProps(attrs, {
68
+ ...props,
69
+ width: props.width ?? '100%',
70
+ height: props.height ?? width.value / props.aspectRatio,
71
+ backgroundColor: props.backgroundColor || theme.value.colors.elevated,
72
+ accessible: Boolean(props.alt),
73
+ accessibilityRole: 'image',
74
+ accessibilityLabel: props.alt,
75
+ accessibilityHint:
76
+ status.value === 'ready'
77
+ ? ''
78
+ : status.value === 'error'
79
+ ? props.errorLabel
80
+ : props.loadingLabel,
81
+ accessibilityHidden: props.accessibilityHidden || !props.alt,
82
+ onLoaded: () => {
83
+ loaded = true
84
+ void load()
85
+ },
86
+ onUnloaded: unload,
87
+ onLayoutChanged: (event: EventData) => {
88
+ const next = (event.object as View).getActualSize().width
89
+ if (next > 0 && Math.abs(next - width.value) > 0.1) width.value = next
90
+ },
91
+ }),
92
+ () =>
93
+ image.value
94
+ ? [
95
+ h('Image', {
96
+ imageSource: image.value,
97
+ width: '100%',
98
+ height: '100%',
99
+ stretch: props.fit === 'cover' ? 'aspectFill' : 'aspectFit',
100
+ borderRadius: radius,
101
+ accessible: false,
102
+ accessibilityHidden: true,
103
+ }),
104
+ ]
105
+ : [
106
+ h(MText, {
107
+ text: status.value === 'error' ? props.errorLabel : props.loadingLabel,
108
+ tone: 'muted',
109
+ variant: 'caption',
110
+ accessibilityHidden: true,
111
+ style: { textAlignment: 'center', verticalAlignment: 'middle', padding: 16 },
112
+ }),
113
+ ],
114
+ )
115
+ }
116
+ },
117
+ })
@@ -14,7 +14,7 @@ import {
14
14
  inputProps,
15
15
  inputEmits,
16
16
  useMavisTheme,
17
- useDefaultShrink,
17
+ useLayoutShrink,
18
18
  layoutDirection,
19
19
  } from '@getcortexlabs/mavis-core/vue'
20
20
  import {
@@ -48,7 +48,7 @@ const Input = defineComponent({
48
48
  setup(props, { attrs, emit, expose }) {
49
49
  useButtonAction()
50
50
  const { theme } = useMavisTheme()
51
- const shrink = useDefaultShrink()
51
+ const shrink = useLayoutShrink()
52
52
  provide(layoutDirection, 'column')
53
53
  const nativeAttrs = useNativeViewAttrs(props)
54
54
  const editor = shallowRef<{ nativeView: TextField | TextView }>()
@@ -127,7 +127,7 @@ const Input = defineComponent({
127
127
  style: {
128
128
  width: resolveDimension(props.width),
129
129
  flexGrow: nonNegative(props.grow, 'grow'),
130
- flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
130
+ flexShrink: nonNegative(props.shrink ?? shrink.value, 'shrink'),
131
131
  minWidth: 0,
132
132
  opacity: props.disabled ? 0.5 : 1,
133
133
  },
@@ -158,11 +158,15 @@ const Input = defineComponent({
158
158
  returnKeyType: props.returnKey,
159
159
  }),
160
160
  keyboardType:
161
- props.type === 'tel'
162
- ? 'phone'
163
- : ['email', 'url'].includes(props.type)
164
- ? props.type
165
- : undefined,
161
+ props.inputmode === 'decimal'
162
+ ? 'decimal'
163
+ : props.inputmode === 'numeric'
164
+ ? 'number'
165
+ : props.type === 'tel'
166
+ ? 'phone'
167
+ : ['email', 'url'].includes(props.type)
168
+ ? props.type
169
+ : undefined,
166
170
  autocapitalizationType: capitalize === 'characters' ? 'allcharacters' : capitalize,
167
171
  autocorrect: props.autocorrect ?? text,
168
172
  maxLength: props.maxLength ?? Infinity,
@@ -0,0 +1,96 @@
1
+ import { defineComponent, h, mergeProps, onBeforeUnmount, ref } from 'nativescript-vue'
2
+ import { Utils, type EventData, type View } from '@nativescript/core'
3
+ import { linkDestination } from '@getcortexlabs/mavis-core'
4
+ import { linkProps, linkEmits, textContent, useMavisTheme } from '@getcortexlabs/mavis-core/vue'
5
+ import { MRow } from './layout.js'
6
+ import { MText } from './MText.js'
7
+ import { ActionChildren, useNativeViewAttrs } from '../accessibility.js'
8
+ import { observeComposedButton } from '../../native/composed-button'
9
+
10
+ export const MLink = defineComponent({
11
+ name: 'MLink',
12
+ inheritAttrs: false,
13
+ props: linkProps,
14
+ emits: linkEmits,
15
+ setup(props, { attrs, slots, emit }) {
16
+ const { theme } = useMavisTheme()
17
+ const nativeAttrs = useNativeViewAttrs(props)
18
+ const focused = ref(false)
19
+ let release: (() => void) | undefined
20
+ const clear = () => {
21
+ release?.()
22
+ release = undefined
23
+ focused.value = false
24
+ }
25
+ onBeforeUnmount(clear)
26
+ const activate = async () => {
27
+ if (props.disabled) return
28
+ const href = linkDestination(props.href)
29
+ emit('click')
30
+ try {
31
+ if (props.navigate) await props.navigate(href)
32
+ else if (!(await Utils.openUrl(href))) throw new Error(`The system could not open ${href}.`)
33
+ } catch (error) {
34
+ emit('error', error)
35
+ }
36
+ }
37
+ return () => {
38
+ const href = linkDestination(props.href)
39
+ if (!props.navigate && !/^[a-z][a-z\d+.-]*:/i.test(href))
40
+ throw new TypeError('Native MLink needs a navigate handler for in-app destinations.')
41
+ const text = props.text ?? textContent(slots.default?.())
42
+ const label = props.accessibilityLabel ?? text
43
+ if (!label.trim()) throw new TypeError('MLink requires a name.')
44
+ return h(
45
+ MRow,
46
+ mergeProps(
47
+ {
48
+ align: 'center',
49
+ justify: 'center',
50
+ grow: props.grow,
51
+ shrink: props.shrink,
52
+ style: {
53
+ minHeight: props.inline ? 0 : 44,
54
+ opacity: props.disabled ? 0.45 : 1,
55
+ borderWidth: focused.value ? 1 : 0,
56
+ borderColor: theme.value.colors.primary,
57
+ },
58
+ },
59
+ nativeAttrs(),
60
+ attrs,
61
+ {
62
+ accessible: true,
63
+ accessibilityRole: 'link',
64
+ accessibilityLabel: label,
65
+ accessibilityState: props.disabled ? 'disabled' : '',
66
+ isEnabled: !props.disabled,
67
+ onTap: activate,
68
+ onLoaded(event: EventData) {
69
+ clear()
70
+ release = observeComposedButton(
71
+ event.object as View,
72
+ (value) => {
73
+ focused.value = value
74
+ },
75
+ activate,
76
+ () => {},
77
+ )
78
+ },
79
+ onUnloaded: clear,
80
+ },
81
+ ),
82
+ {
83
+ default: () =>
84
+ h(
85
+ ActionChildren,
86
+ { hidden: true },
87
+ {
88
+ default: () =>
89
+ h(MText, { text, tone: 'primary', style: { textDecoration: 'underline' } }),
90
+ },
91
+ ),
92
+ },
93
+ )
94
+ }
95
+ },
96
+ })