@getcortexlabs/mavis 0.1.0-alpha.4 → 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 (216) hide show
  1. package/README.md +5 -5
  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/files.d.ts +4 -0
  7. package/dist/files.d.ts.map +1 -0
  8. package/dist/files.js +3 -0
  9. package/dist/files.js.map +1 -0
  10. package/dist/native/app-icons.android.d.ts +4 -0
  11. package/dist/native/app-icons.android.d.ts.map +1 -0
  12. package/dist/native/app-icons.android.js +67 -0
  13. package/dist/native/app-icons.android.js.map +1 -0
  14. package/dist/native/app-icons.d.ts +4 -0
  15. package/dist/native/app-icons.d.ts.map +1 -0
  16. package/dist/native/app-icons.ios.d.ts +4 -0
  17. package/dist/native/app-icons.ios.d.ts.map +1 -0
  18. package/dist/native/app-icons.ios.js +45 -0
  19. package/dist/native/app-icons.ios.js.map +1 -0
  20. package/dist/native/app-icons.js +9 -0
  21. package/dist/native/app-icons.js.map +1 -0
  22. package/dist/native/combobox-editor.android.d.ts +3 -0
  23. package/dist/native/combobox-editor.android.d.ts.map +1 -0
  24. package/dist/native/combobox-editor.android.js +5 -0
  25. package/dist/native/combobox-editor.android.js.map +1 -0
  26. package/dist/native/combobox-editor.d.ts +4 -0
  27. package/dist/native/combobox-editor.d.ts.map +1 -0
  28. package/dist/native/combobox-editor.js +5 -0
  29. package/dist/native/combobox-editor.js.map +1 -0
  30. package/dist/native/file-access.d.ts +23 -0
  31. package/dist/native/file-access.d.ts.map +1 -0
  32. package/dist/native/file-access.js +55 -0
  33. package/dist/native/file-access.js.map +1 -0
  34. package/dist/native/file-picker.android.d.ts +3 -0
  35. package/dist/native/file-picker.android.d.ts.map +1 -0
  36. package/dist/native/file-picker.android.js +147 -0
  37. package/dist/native/file-picker.android.js.map +1 -0
  38. package/dist/native/file-picker.d.ts +4 -0
  39. package/dist/native/file-picker.d.ts.map +1 -0
  40. package/dist/native/file-picker.ios.d.ts +3 -0
  41. package/dist/native/file-picker.ios.d.ts.map +1 -0
  42. package/dist/native/file-picker.ios.js +152 -0
  43. package/dist/native/file-picker.ios.js.map +1 -0
  44. package/dist/native/file-picker.js +7 -0
  45. package/dist/native/file-picker.js.map +1 -0
  46. package/dist/native/motion-owner.d.ts +5 -0
  47. package/dist/native/motion-owner.d.ts.map +1 -0
  48. package/dist/native/motion-owner.js +57 -0
  49. package/dist/native/motion-owner.js.map +1 -0
  50. package/dist/native/motion-region.d.ts +6 -0
  51. package/dist/native/motion-region.d.ts.map +1 -0
  52. package/dist/native/motion-region.js +237 -0
  53. package/dist/native/motion-region.js.map +1 -0
  54. package/dist/native/motion-surface.d.ts +1 -1
  55. package/dist/native/motion-surface.d.ts.map +1 -1
  56. package/dist/native/motion-surface.js +43 -2
  57. package/dist/native/motion-surface.js.map +1 -1
  58. package/dist/native/press.d.ts +3 -2
  59. package/dist/native/press.d.ts.map +1 -1
  60. package/dist/native/press.js.map +1 -1
  61. package/dist/native/scroll-motion.d.ts +1 -0
  62. package/dist/native/scroll-motion.d.ts.map +1 -1
  63. package/dist/native/scroll-motion.js +6 -0
  64. package/dist/native/scroll-motion.js.map +1 -1
  65. package/dist/vue/components/ChoiceControl.d.ts +21 -11
  66. package/dist/vue/components/ChoiceControl.d.ts.map +1 -1
  67. package/dist/vue/components/DateCalendar.d.ts +94 -0
  68. package/dist/vue/components/DateCalendar.d.ts.map +1 -0
  69. package/dist/vue/components/DateCalendar.js +96 -0
  70. package/dist/vue/components/DateCalendar.js.map +1 -0
  71. package/dist/vue/components/MAccordion.d.ts +19 -9
  72. package/dist/vue/components/MAccordion.d.ts.map +1 -1
  73. package/dist/vue/components/MAlert.d.ts +20 -10
  74. package/dist/vue/components/MAlert.d.ts.map +1 -1
  75. package/dist/vue/components/MAvatar.d.ts +12 -6
  76. package/dist/vue/components/MAvatar.d.ts.map +1 -1
  77. package/dist/vue/components/MBadge.d.ts +12 -6
  78. package/dist/vue/components/MBadge.d.ts.map +1 -1
  79. package/dist/vue/components/MButton.d.ts +127 -39
  80. package/dist/vue/components/MButton.d.ts.map +1 -1
  81. package/dist/vue/components/MButton.js +20 -13
  82. package/dist/vue/components/MButton.js.map +1 -1
  83. package/dist/vue/components/MCard.d.ts +89 -15
  84. package/dist/vue/components/MCard.d.ts.map +1 -1
  85. package/dist/vue/components/MCard.js +12 -5
  86. package/dist/vue/components/MCard.js.map +1 -1
  87. package/dist/vue/components/MCheckbox.d.ts +20 -10
  88. package/dist/vue/components/MCheckbox.d.ts.map +1 -1
  89. package/dist/vue/components/MChip.d.ts +22 -12
  90. package/dist/vue/components/MChip.d.ts.map +1 -1
  91. package/dist/vue/components/MCombobox.d.ts +279 -0
  92. package/dist/vue/components/MCombobox.d.ts.map +1 -0
  93. package/dist/vue/components/MCombobox.js +234 -0
  94. package/dist/vue/components/MCombobox.js.map +1 -0
  95. package/dist/vue/components/MDatePicker.d.ts +1302 -0
  96. package/dist/vue/components/MDatePicker.d.ts.map +1 -0
  97. package/dist/vue/components/MDatePicker.js +35 -0
  98. package/dist/vue/components/MDatePicker.js.map +1 -0
  99. package/dist/vue/components/MDialog.d.ts +7 -5
  100. package/dist/vue/components/MDialog.d.ts.map +1 -1
  101. package/dist/vue/components/MEmptyState.d.ts +19 -9
  102. package/dist/vue/components/MEmptyState.d.ts.map +1 -1
  103. package/dist/vue/components/MFilePicker.d.ts +112 -0
  104. package/dist/vue/components/MFilePicker.d.ts.map +1 -0
  105. package/dist/vue/components/MFilePicker.js +196 -0
  106. package/dist/vue/components/MFilePicker.js.map +1 -0
  107. package/dist/vue/components/MIcon.d.ts +4 -2
  108. package/dist/vue/components/MIcon.d.ts.map +1 -1
  109. package/dist/vue/components/MInput.d.ts +132 -60
  110. package/dist/vue/components/MInput.d.ts.map +1 -1
  111. package/dist/vue/components/MInput.js +3 -3
  112. package/dist/vue/components/MInput.js.map +1 -1
  113. package/dist/vue/components/MLink.d.ts +120 -0
  114. package/dist/vue/components/MLink.d.ts.map +1 -0
  115. package/dist/vue/components/MLink.js +81 -0
  116. package/dist/vue/components/MLink.js.map +1 -0
  117. package/dist/vue/components/MListItem.d.ts +26 -12
  118. package/dist/vue/components/MListItem.d.ts.map +1 -1
  119. package/dist/vue/components/MProgress.d.ts +18 -8
  120. package/dist/vue/components/MProgress.d.ts.map +1 -1
  121. package/dist/vue/components/MRadioGroup.d.ts +19 -9
  122. package/dist/vue/components/MRadioGroup.d.ts.map +1 -1
  123. package/dist/vue/components/MReveal.d.ts +71 -35
  124. package/dist/vue/components/MReveal.d.ts.map +1 -1
  125. package/dist/vue/components/MReveal.js +80 -35
  126. package/dist/vue/components/MReveal.js.map +1 -1
  127. package/dist/vue/components/MScreen.d.ts +12 -6
  128. package/dist/vue/components/MScreen.d.ts.map +1 -1
  129. package/dist/vue/components/MSegmentedControl.d.ts +19 -9
  130. package/dist/vue/components/MSegmentedControl.d.ts.map +1 -1
  131. package/dist/vue/components/MSelect.d.ts +21 -11
  132. package/dist/vue/components/MSelect.d.ts.map +1 -1
  133. package/dist/vue/components/MSeparator.d.ts +4 -2
  134. package/dist/vue/components/MSeparator.d.ts.map +1 -1
  135. package/dist/vue/components/MSheet.d.ts +18 -12
  136. package/dist/vue/components/MSheet.d.ts.map +1 -1
  137. package/dist/vue/components/MSkeleton.d.ts +16 -8
  138. package/dist/vue/components/MSkeleton.d.ts.map +1 -1
  139. package/dist/vue/components/MSlider.d.ts +9 -5
  140. package/dist/vue/components/MSlider.d.ts.map +1 -1
  141. package/dist/vue/components/MStack.d.ts +199 -0
  142. package/dist/vue/components/MStack.d.ts.map +1 -0
  143. package/dist/vue/components/MStack.js +62 -0
  144. package/dist/vue/components/MStack.js.map +1 -0
  145. package/dist/vue/components/MSwitch.d.ts +19 -9
  146. package/dist/vue/components/MSwitch.d.ts.map +1 -1
  147. package/dist/vue/components/MTabs.d.ts +19 -9
  148. package/dist/vue/components/MTabs.d.ts.map +1 -1
  149. package/dist/vue/components/MText.d.ts +42 -26
  150. package/dist/vue/components/MText.d.ts.map +1 -1
  151. package/dist/vue/components/MText.js +3 -3
  152. package/dist/vue/components/MText.js.map +1 -1
  153. package/dist/vue/components/layout.d.ts +191 -82
  154. package/dist/vue/components/layout.d.ts.map +1 -1
  155. package/dist/vue/components/layout.js +9 -7
  156. package/dist/vue/components/layout.js.map +1 -1
  157. package/dist/vue/components/workflows.d.ts +251 -0
  158. package/dist/vue/components/workflows.d.ts.map +1 -0
  159. package/dist/vue/components/workflows.js +35 -0
  160. package/dist/vue/components/workflows.js.map +1 -0
  161. package/dist/vue/index.d.ts +9 -2
  162. package/dist/vue/index.d.ts.map +1 -1
  163. package/dist/vue/index.js +19 -2
  164. package/dist/vue/index.js.map +1 -1
  165. package/dist/vue/navigation.d.ts +4 -0
  166. package/dist/vue/navigation.d.ts.map +1 -0
  167. package/dist/vue/navigation.js +16 -0
  168. package/dist/vue/navigation.js.map +1 -0
  169. package/dist/vue/reveal-motion.d.ts.map +1 -1
  170. package/dist/vue/reveal-motion.js +6 -3
  171. package/dist/vue/reveal-motion.js.map +1 -1
  172. package/dist/vue/use-motion-region.d.ts +7 -0
  173. package/dist/vue/use-motion-region.d.ts.map +1 -0
  174. package/dist/vue/use-motion-region.js +28 -0
  175. package/dist/vue/use-motion-region.js.map +1 -0
  176. package/dist/vue/use-motion-surface.d.ts.map +1 -1
  177. package/dist/vue/use-motion-surface.js +3 -2
  178. package/dist/vue/use-motion-surface.js.map +1 -1
  179. package/dist/vue/use-press.js +3 -3
  180. package/dist/vue/use-press.js.map +1 -1
  181. package/package.json +7 -3
  182. package/src/app-icons.ts +21 -0
  183. package/src/files.ts +3 -0
  184. package/src/native/app-icons.android.ts +95 -0
  185. package/src/native/app-icons.ios.ts +74 -0
  186. package/src/native/app-icons.ts +12 -0
  187. package/src/native/combobox-editor.android.ts +11 -0
  188. package/src/native/combobox-editor.ts +6 -0
  189. package/src/native/file-access.ts +71 -0
  190. package/src/native/file-picker.android.ts +191 -0
  191. package/src/native/file-picker.ios.ts +230 -0
  192. package/src/native/file-picker.ts +8 -0
  193. package/src/native/motion-owner.ts +65 -0
  194. package/src/native/motion-region.ts +275 -0
  195. package/src/native/motion-surface.ts +55 -2
  196. package/src/native/press.ts +3 -3
  197. package/src/native/scroll-motion.ts +5 -0
  198. package/src/vue/components/DateCalendar.ts +117 -0
  199. package/src/vue/components/MButton.ts +20 -10
  200. package/src/vue/components/MCard.ts +22 -5
  201. package/src/vue/components/MCombobox.ts +257 -0
  202. package/src/vue/components/MDatePicker.ts +33 -0
  203. package/src/vue/components/MFilePicker.ts +226 -0
  204. package/src/vue/components/MInput.ts +3 -3
  205. package/src/vue/components/MLink.ts +96 -0
  206. package/src/vue/components/MReveal.ts +89 -47
  207. package/src/vue/components/MStack.ts +83 -0
  208. package/src/vue/components/MText.ts +3 -3
  209. package/src/vue/components/layout.ts +15 -7
  210. package/src/vue/components/workflows.ts +38 -0
  211. package/src/vue/index.ts +35 -1
  212. package/src/vue/navigation.ts +15 -0
  213. package/src/vue/use-motion-region.ts +29 -0
  214. package/src/vue/use-motion-surface.ts +21 -14
  215. package/src/vue/use-press.ts +3 -3
  216. package/src/vue/reveal-motion.ts +0 -61
@@ -9,6 +9,11 @@ import {
9
9
  } from '@getcortexlabs/mavis-core/experimental'
10
10
 
11
11
  const sources = new WeakMap<MotionScrollAdapter, ScrollView>()
12
+ export function nativeScrollElement(adapter: MotionScrollAdapter) {
13
+ const source = sources.get(adapter)
14
+ if (!source) throw new TypeError('Use a scrolling native MScreen.')
15
+ return source
16
+ }
12
17
  export function attachNativeScrollSource(reference: MotionScrollSource, source: ScrollView) {
13
18
  const adapter: MotionScrollAdapter = { kind: 'native' }
14
19
  sources.set(adapter, source)
@@ -0,0 +1,117 @@
1
+ import { defineComponent, h } from 'nativescript-vue'
2
+ import { calendarDayLabel } from '@getcortexlabs/mavis-core'
3
+ import {
4
+ dateCalendarProps,
5
+ dateCalendarEmits,
6
+ useDateCalendar,
7
+ useMavisTheme,
8
+ } from '@getcortexlabs/mavis-core/vue'
9
+ import { MButton } from './MButton.js'
10
+ import { MText } from './MText.js'
11
+ import { MColumn, MRow } from './layout.js'
12
+
13
+ /** @internal Natural-size native buttons; horizontal scrolling preserves large text and targets. */
14
+ export const DateCalendar = defineComponent({
15
+ name: 'DateCalendar',
16
+ props: dateCalendarProps,
17
+ emits: dateCalendarEmits,
18
+ setup(props, { emit }) {
19
+ const { theme } = useMavisTheme()
20
+ const calendar = useDateCalendar(props, (value) => emit('update:activeDate', value))
21
+ return () => {
22
+ const { colors, radius } = theme.value
23
+ return h(
24
+ MColumn,
25
+ { gap: 'sm' },
26
+ {
27
+ default: () => [
28
+ h(
29
+ MRow,
30
+ { justify: 'between', gap: 'sm', wrap: true },
31
+ {
32
+ default: () => [
33
+ h(MButton, {
34
+ icon: 'chevron-left',
35
+ variant: 'ghost',
36
+ accessibilityLabel: calendar.words.value.previous,
37
+ disabled: !calendar.canPage(-1),
38
+ onClick: () => calendar.page(-1),
39
+ }),
40
+ h(MText, {
41
+ text: calendar.title.value,
42
+ weight: '600',
43
+ shrink: 1,
44
+ accessibilityLiveRegion: 'polite',
45
+ }),
46
+ h(MButton, {
47
+ icon: 'chevron-right',
48
+ variant: 'ghost',
49
+ accessibilityLabel: calendar.words.value.next,
50
+ disabled: !calendar.canPage(1),
51
+ onClick: () => calendar.page(1),
52
+ }),
53
+ ],
54
+ },
55
+ ),
56
+ h('ScrollView', { orientation: 'horizontal' }, [
57
+ h(
58
+ 'GridLayout',
59
+ {
60
+ columns: 'auto,auto,auto,auto,auto,auto,auto',
61
+ rows: Array.from(
62
+ { length: calendar.cells.value.length / 7 + 1 },
63
+ () => 'auto',
64
+ ).join(','),
65
+ },
66
+ [
67
+ ...calendar.weekdays.value.map((weekday, column) =>
68
+ h(MText, {
69
+ key: `weekday-${weekday}`,
70
+ row: 0,
71
+ col: column,
72
+ text: calendar.words.value.shortWeekdays[weekday],
73
+ variant: 'caption',
74
+ tone: 'muted',
75
+ accessibilityLabel: calendar.words.value.weekdays[weekday],
76
+ style: { minWidth: 48, textAlignment: 'center', padding: 8 },
77
+ }),
78
+ ),
79
+ ...calendar.cells.value.map((date, index) => {
80
+ if (!date) return null
81
+ const selected = date === props.selected
82
+ return h(MButton, {
83
+ key: date,
84
+ row: Math.floor(index / 7) + 1,
85
+ col: index % 7,
86
+ text: String(Number(date.slice(8))),
87
+ variant: 'ghost',
88
+ accessibilityLabel: calendarDayLabel(date, props.locale),
89
+ accessibilityValue: selected ? calendar.words.value.selected : '',
90
+ disabled: !calendar.available(date),
91
+ style: {
92
+ minWidth: 48,
93
+ minHeight: 48,
94
+ margin: 1,
95
+ paddingLeft: 6,
96
+ paddingRight: 6,
97
+ borderWidth: 2,
98
+ borderColor: selected ? colors.primary : 'transparent',
99
+ borderRadius: radius.sm,
100
+ backgroundColor:
101
+ selected || calendar.inRange(date) ? colors.primarySoft : 'transparent',
102
+ color: colors.text,
103
+ },
104
+ onClick: () => {
105
+ if (calendar.available(date)) emit('select', date)
106
+ },
107
+ })
108
+ }),
109
+ ],
110
+ ),
111
+ ]),
112
+ ],
113
+ },
114
+ )
115
+ }
116
+ },
117
+ })
@@ -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,257 @@
1
+ import {
2
+ defineComponent,
3
+ h,
4
+ mergeProps,
5
+ onBeforeUnmount,
6
+ nextTick,
7
+ ref,
8
+ watch,
9
+ } from 'nativescript-vue'
10
+ import { TextField, isAndroid, type EventData, type View } from '@nativescript/core'
11
+ import { choiceKey, type InputHandle } from '@getcortexlabs/mavis-core'
12
+ import {
13
+ comboboxProps,
14
+ comboboxEmits,
15
+ useCombobox,
16
+ useButtonAction,
17
+ } from '@getcortexlabs/mavis-core/vue'
18
+ import { comboboxComposing } from '../../native/combobox-editor'
19
+ import { MColumn, MRow } from './layout.js'
20
+ import { MInput } from './MInput.js'
21
+ import { MButton } from './MButton.js'
22
+ import { MText } from './MText.js'
23
+ import { ChoiceControl } from './ChoiceControl.js'
24
+
25
+ const Combobox = defineComponent({
26
+ name: 'MCombobox',
27
+ inheritAttrs: false,
28
+ props: comboboxProps,
29
+ emits: comboboxEmits,
30
+ setup(props, { attrs, emit, expose }) {
31
+ useButtonAction()
32
+ const combo = useCombobox(props, emit)
33
+ const input = ref<InputHandle>()
34
+ let nativeEditor: TextField | undefined
35
+ let compositionTimer: ReturnType<typeof setTimeout> | undefined
36
+ let editTimer: ReturnType<typeof setTimeout> | undefined
37
+ let blurTimer: ReturnType<typeof setTimeout> | undefined
38
+ function clearTimers() {
39
+ clearTimeout(compositionTimer)
40
+ clearTimeout(blurTimer)
41
+ clearTimeout(editTimer)
42
+ compositionTimer = blurTimer = editTimer = undefined
43
+ }
44
+ function close() {
45
+ clearTimers()
46
+ combo.close()
47
+ }
48
+ function unload() {
49
+ close()
50
+ nativeEditor = undefined
51
+ }
52
+ onBeforeUnmount(unload)
53
+ watch(combo.open, (open) => {
54
+ if (!open) clearTimers()
55
+ })
56
+ function finishComposition() {
57
+ clearTimeout(compositionTimer)
58
+ compositionTimer = undefined
59
+ if (!combo.open.value || !nativeEditor?.isLoaded) return
60
+ if (comboboxComposing(nativeEditor)) compositionTimer = setTimeout(finishComposition, 30)
61
+ else applyEdit(nativeEditor.text ?? '')
62
+ }
63
+ function applyEdit(value: string) {
64
+ if (comboboxComposing(nativeEditor)) {
65
+ combo.startComposition()
66
+ combo.edit(value)
67
+ clearTimeout(compositionTimer)
68
+ compositionTimer = setTimeout(finishComposition, 30)
69
+ } else if (combo.composing.value) combo.endComposition(value)
70
+ else combo.edit(value)
71
+ const field = nativeEditor
72
+ void nextTick(() => {
73
+ // Native text is mutable before Vue receives textChange. A rejected query
74
+ // can leave equal old/new props, so only rejection needs an explicit repair.
75
+ if (
76
+ field &&
77
+ nativeEditor === field &&
78
+ field.isLoaded &&
79
+ !combo.composing.value &&
80
+ props.query !== value &&
81
+ field.text === value
82
+ )
83
+ field.text = props.query
84
+ })
85
+ }
86
+ function edit(value: string) {
87
+ // Native text notifications can precede the IME attaching its composing span.
88
+ // Inspect on the next turn, before even a zero-debounce search is allowed to start.
89
+ clearTimeout(editTimer)
90
+ editTimer = setTimeout(() => {
91
+ editTimer = undefined
92
+ if (nativeEditor?.isLoaded) applyEdit(value)
93
+ }, 0)
94
+ }
95
+ function findEditor(view: View) {
96
+ if (view instanceof TextField) {
97
+ nativeEditor = view
98
+ return
99
+ }
100
+ view.eachChild?.((child) => {
101
+ findEditor(child as View)
102
+ return !nativeEditor
103
+ })
104
+ }
105
+ const focus = () => {
106
+ if (!props.disabled) input.value?.focus()
107
+ }
108
+ const blur = () => {
109
+ close()
110
+ input.value?.blur()
111
+ }
112
+ expose({ focus, blur } satisfies InputHandle)
113
+ return () => {
114
+ const state = combo.state.value
115
+ const selected = combo.selected.value
116
+ const status =
117
+ state.status === 'loading' || state.status === 'debouncing'
118
+ ? props.loadingText
119
+ : state.status === 'error'
120
+ ? props.searchErrorText
121
+ : state.status === 'empty'
122
+ ? props.emptyText
123
+ : state.status === 'idle'
124
+ ? props.idleText
125
+ : state.limited
126
+ ? props.limitedText
127
+ : ''
128
+ void combo.revision.value
129
+ return h(
130
+ MColumn,
131
+ mergeProps(attrs, {
132
+ width: props.width,
133
+ grow: props.grow,
134
+ shrink: props.shrink,
135
+ gap: 'sm',
136
+ accessibilityHidden: props.accessibilityHidden,
137
+ onUnloaded: unload,
138
+ }),
139
+ {
140
+ default: () => [
141
+ h(MInput, {
142
+ ref: input,
143
+ id: props.id,
144
+ label: props.label,
145
+ modelValue: props.query,
146
+ placeholder: props.placeholder,
147
+ helperText: props.helperText,
148
+ error: props.error,
149
+ disabled: props.disabled,
150
+ type: 'search',
151
+ returnKey: 'search',
152
+ autocapitalize: 'none',
153
+ autocorrect: false,
154
+ trailingAction:
155
+ props.clearable && (props.query || props.modelValue !== null)
156
+ ? { icon: 'x', label: props.clearLabel }
157
+ : undefined,
158
+ onAction: () => {
159
+ close()
160
+ combo.clear()
161
+ focus()
162
+ },
163
+ 'onUpdate:modelValue': edit,
164
+ onLoaded: (event: EventData) => {
165
+ nativeEditor = undefined
166
+ findEditor(event.object as View)
167
+ },
168
+ onFocus: () => {
169
+ clearTimeout(blurTimer)
170
+ combo.show()
171
+ emit('focus')
172
+ },
173
+ onBlur: () => {
174
+ emit('blur')
175
+ // Let a result's tap commit before closing the results on an unrelated focus move.
176
+ blurTimer = setTimeout(close, 0)
177
+ },
178
+ onSubmit: () => {
179
+ if (!combo.composing.value) {
180
+ combo.show()
181
+ combo.retry()
182
+ }
183
+ },
184
+ }),
185
+ selected && props.query !== selected.label
186
+ ? h(MText, { text: selected.label, variant: 'caption', tone: 'primary' })
187
+ : null,
188
+ combo.open.value
189
+ ? h(
190
+ MColumn,
191
+ { gap: 'xs' },
192
+ {
193
+ default: () => [
194
+ ...state.options.map((option) =>
195
+ h(ChoiceControl, {
196
+ key: choiceKey(option.value),
197
+ radio: true,
198
+ pressFeedback: !isAndroid,
199
+ label: option.label,
200
+ helperText: option.helperText,
201
+ modelValue: option.value === props.modelValue,
202
+ disabled: props.disabled || option.disabled,
203
+ onActivate: () => {
204
+ clearTimers()
205
+ combo.choose(option)
206
+ if (!combo.open.value) input.value?.blur()
207
+ },
208
+ }),
209
+ ),
210
+ status
211
+ ? h(MText, {
212
+ text: status,
213
+ variant: 'caption',
214
+ tone: state.status === 'error' ? 'danger' : 'muted',
215
+ })
216
+ : null,
217
+ h(
218
+ MRow,
219
+ { gap: 'sm', wrap: true },
220
+ {
221
+ default: () => [
222
+ state.status === 'error'
223
+ ? h(MButton, {
224
+ text: props.retryLabel,
225
+ variant: 'ghost',
226
+ onClick: () => {
227
+ clearTimers()
228
+ combo.show()
229
+ combo.retry()
230
+ focus()
231
+ },
232
+ })
233
+ : null,
234
+ h(MButton, {
235
+ text: props.closeLabel,
236
+ variant: 'ghost',
237
+ onClick: () => {
238
+ combo.cancel()
239
+ blur()
240
+ },
241
+ }),
242
+ ],
243
+ },
244
+ ),
245
+ ],
246
+ },
247
+ )
248
+ : null,
249
+ ],
250
+ },
251
+ )
252
+ }
253
+ },
254
+ })
255
+ export const MCombobox = Combobox as typeof Combobox & {
256
+ new (): InstanceType<typeof Combobox> & InputHandle
257
+ }
@@ -0,0 +1,33 @@
1
+ import { Utils, isAndroid, type View } from '@nativescript/core'
2
+ import { createDatePickers } from '@getcortexlabs/mavis-core/vue'
3
+ import { MInput } from './MInput.js'
4
+ import { MButton } from './MButton.js'
5
+ import { MColumn, MRow } from './layout.js'
6
+ import { MSheet } from './MSheet.js'
7
+ import { DateCalendar } from './DateCalendar.js'
8
+ import { notifyAccessibilityLayout } from '../../native/accessibility-layout'
9
+
10
+ function focusOpener(opener: unknown) {
11
+ const view = (opener as { $el?: { nativeView?: View } } | undefined)?.$el?.nativeView
12
+ view?.focus()
13
+ }
14
+
15
+ export const { MDatePicker, MDateRangePicker } = createDatePickers({
16
+ Input: MInput,
17
+ Button: MButton,
18
+ Column: MColumn,
19
+ Row: MRow,
20
+ Sheet: MSheet,
21
+ Calendar: DateCalendar,
22
+ beforeOpen: (opener) => {
23
+ Utils.dismissKeyboard()
24
+ focusOpener(opener)
25
+ },
26
+ afterClose: (opener) => {
27
+ const view = (opener as { $el?: { nativeView?: View } } | undefined)?.$el?.nativeView
28
+ if (!view?.isLoaded) return
29
+ view.focus()
30
+ if (isAndroid) view.android.performAccessibilityAction(64, null)
31
+ else notifyAccessibilityLayout(view)
32
+ },
33
+ })