@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
@@ -0,0 +1,226 @@
1
+ import {
2
+ defineComponent,
3
+ h,
4
+ mergeProps,
5
+ nextTick,
6
+ onBeforeUnmount,
7
+ onDeactivated,
8
+ shallowRef,
9
+ watch,
10
+ } from 'nativescript-vue'
11
+ import { filePickerProps, fileStatusText, useButtonAction } from '@getcortexlabs/mavis-core/vue'
12
+ import type { InputHandle } from '@getcortexlabs/mavis-core'
13
+ import { createNativeFilePicker } from '../../native/file-picker'
14
+ import { MColumn, MRow } from './layout.js'
15
+ import { MText } from './MText.js'
16
+ import { MButton } from './MButton.js'
17
+ import { MProgress } from './MProgress.js'
18
+ import { MCard } from './MCard.js'
19
+ import { Application, isAndroid, type EventData, type View } from '@nativescript/core'
20
+
21
+ const FilePicker = defineComponent({
22
+ name: 'MFilePicker',
23
+ inheritAttrs: false,
24
+ props: filePickerProps,
25
+ setup(props, { attrs, expose }) {
26
+ useButtonAction()
27
+ const state = shallowRef(props.selection.state)
28
+ const picker = createNativeFilePicker()
29
+ let chooseView: View | undefined
30
+ let loaded = false
31
+ let unsubscribe = () => {}
32
+ watch(
33
+ () => props.selection,
34
+ (selection, previous) => {
35
+ previous?.pause()
36
+ unsubscribe()
37
+ state.value = selection.state
38
+ unsubscribe = selection.subscribe((value) => {
39
+ state.value = value
40
+ })
41
+ },
42
+ { immediate: true, flush: 'sync' },
43
+ )
44
+ watch(
45
+ () => props.disabled,
46
+ (disabled) => {
47
+ if (disabled) props.selection.pause()
48
+ },
49
+ )
50
+ function unload() {
51
+ loaded = false
52
+ // Android stops/unloads the owner Activity when its system document picker opens.
53
+ // Keep that intentional handoff alive; route unloads and component disposal still cancel.
54
+ if (isAndroid && Application.android.paused && props.selection.state.picking) {
55
+ for (const item of props.selection.state.items) props.selection.cancel(item.id)
56
+ } else props.selection.pause()
57
+ chooseView = undefined
58
+ }
59
+ onDeactivated(() => props.selection.pause())
60
+ onBeforeUnmount(() => {
61
+ unsubscribe()
62
+ props.selection.pause()
63
+ unload()
64
+ })
65
+ function focusChoose() {
66
+ if (loaded && !props.disabled && !state.value.picking) chooseView?.focus()
67
+ }
68
+ expose({
69
+ focus: focusChoose,
70
+ blur: () => {
71
+ chooseView?.android?.clearFocus()
72
+ chooseView?.ios?.resignFirstResponder()
73
+ },
74
+ } satisfies InputHandle)
75
+ function choose() {
76
+ if (!loaded || props.disabled || state.value.picking) return
77
+ const selection = props.selection
78
+ void selection.select(picker).finally(async () => {
79
+ await nextTick()
80
+ if (props.selection === selection) focusChoose()
81
+ })
82
+ }
83
+ return () => {
84
+ if (!props.label.trim()) throw new TypeError('FilePicker needs a non-empty label')
85
+ const selection = props.selection
86
+ return h(
87
+ MColumn,
88
+ mergeProps(attrs, {
89
+ gap: 'md',
90
+ onLoaded: () => {
91
+ loaded = true
92
+ },
93
+ onUnloaded: unload,
94
+ }),
95
+ {
96
+ default: () => [
97
+ h(MText, { text: props.label, weight: '600' }),
98
+ h(
99
+ MRow,
100
+ { gap: 'sm', wrap: true },
101
+ {
102
+ default: () => [
103
+ h(MButton, {
104
+ text: props.chooseLabel,
105
+ variant: 'secondary',
106
+ disabled: props.disabled || state.value.picking,
107
+ accessibilityLabel: `${props.chooseLabel}: ${props.label}`,
108
+ onClick: choose,
109
+ onLoaded: (event: EventData) => {
110
+ chooseView = event.object as View
111
+ },
112
+ }),
113
+ state.value.picking
114
+ ? h(MButton, {
115
+ text: props.cancelLabel,
116
+ variant: 'ghost',
117
+ onClick: () => {
118
+ selection.cancelSelection()
119
+ focusChoose()
120
+ },
121
+ })
122
+ : null,
123
+ ],
124
+ },
125
+ ),
126
+ state.value.error
127
+ ? h(MText, {
128
+ text: props.errorLabels[state.value.error.code] ?? state.value.error.message,
129
+ tone: 'danger',
130
+ })
131
+ : null,
132
+ !state.value.items.length ? h(MText, { text: props.emptyLabel, tone: 'muted' }) : null,
133
+ ...state.value.items.map((item) => {
134
+ const preview = selection.preview(item.id)
135
+ const status = fileStatusText(item, props.statusLabels)
136
+ return h(
137
+ MCard,
138
+ { key: item.id, gap: 'sm' },
139
+ {
140
+ default: () => [
141
+ preview
142
+ ? h('Image', {
143
+ src: preview,
144
+ width: 80,
145
+ height: 80,
146
+ stretch: 'aspectFit',
147
+ horizontalAlignment: 'left',
148
+ accessible: false,
149
+ accessibilityHidden: true,
150
+ })
151
+ : null,
152
+ h(MText, { text: item.name, weight: '600' }),
153
+ h(MText, {
154
+ text: `${status}${item.size === undefined ? '' : ` · ${item.size} B`}`,
155
+ variant: 'caption',
156
+ tone:
157
+ item.status === 'failed'
158
+ ? 'danger'
159
+ : item.status === 'uploaded'
160
+ ? 'success'
161
+ : 'muted',
162
+ }),
163
+ item.status === 'uploading'
164
+ ? h(MProgress, {
165
+ value: (item.progress ?? 0) * 100,
166
+ indeterminate: item.progress === undefined,
167
+ label: `${props.uploadLabel}: ${item.name}`,
168
+ indeterminateLabel: props.pendingLabel,
169
+ })
170
+ : null,
171
+ item.error
172
+ ? h(MText, { text: item.error, tone: 'danger', variant: 'caption' })
173
+ : null,
174
+ h(
175
+ MRow,
176
+ { gap: 'sm', wrap: true },
177
+ {
178
+ default: () => [
179
+ item.status === 'uploading'
180
+ ? h(MButton, {
181
+ text: props.cancelLabel,
182
+ accessibilityLabel: `${props.cancelLabel}: ${item.name}`,
183
+ variant: 'secondary',
184
+ disabled: props.disabled,
185
+ onClick: () => selection.cancel(item.id),
186
+ })
187
+ : selection.canUpload && item.status !== 'uploaded'
188
+ ? h(MButton, {
189
+ text:
190
+ item.status === 'failed' || item.status === 'cancelled'
191
+ ? props.retryLabel
192
+ : props.uploadLabel,
193
+ accessibilityLabel: `${item.status === 'failed' || item.status === 'cancelled' ? props.retryLabel : props.uploadLabel}: ${item.name}`,
194
+ disabled: props.disabled || !selection.hasFile(item.id),
195
+ onClick: () => {
196
+ void selection.upload(item.id)
197
+ },
198
+ })
199
+ : null,
200
+ h(MButton, {
201
+ text: props.removeLabel,
202
+ accessibilityLabel: `${props.removeLabel}: ${item.name}`,
203
+ variant: 'ghost',
204
+ disabled: props.disabled,
205
+ onClick: () => {
206
+ focusChoose()
207
+ selection.remove(item.id)
208
+ },
209
+ }),
210
+ ],
211
+ },
212
+ ),
213
+ ],
214
+ },
215
+ )
216
+ }),
217
+ ],
218
+ },
219
+ )
220
+ }
221
+ },
222
+ })
223
+
224
+ export const MFilePicker = FilePicker as typeof FilePicker & {
225
+ new (): InstanceType<typeof FilePicker> & InputHandle
226
+ }
@@ -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
  },
@@ -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
+ })
@@ -1,8 +1,9 @@
1
- import { defineComponent, h, mergeProps, BaseTransition } from 'nativescript-vue'
2
- import { useRevealMotion } from '../reveal-motion.js'
3
- import { revealProps } from '@getcortexlabs/mavis-core/vue'
4
- import { MColumn } from './layout.js'
5
- import { isAndroid, type View } from '@nativescript/core'
1
+ import { defineComponent, h, mergeProps } from 'nativescript-vue'
2
+ import { animate, animateSize } from '@rafaelaugusto/jolt'
3
+ import { motionRecipe } from '@getcortexlabs/mavis-core'
4
+ import { revealProps, useMavisTheme, useRevealState } from '@getcortexlabs/mavis-core/vue'
5
+ import { MColumn, MBox } from './layout.js'
6
+ import { isAndroid, type EventData, type View } from '@nativescript/core'
6
7
  import { focusedView } from '../accessibility.js'
7
8
  import { notifyAccessibilityLayout } from '../../native/accessibility-layout'
8
9
 
@@ -11,51 +12,92 @@ export const MReveal = defineComponent({
11
12
  inheritAttrs: false,
12
13
  props: revealProps,
13
14
  setup(props, { attrs, slots }) {
14
- const motion = useRevealMotion()
15
+ const { theme } = useMavisTheme()
16
+ const state = useRevealState(() => props.show)
15
17
  let trigger: WeakRef<View> | undefined
16
- let restore = false
17
- return () => {
18
- const { show, ...layout } = props
19
- return h(
20
- BaseTransition,
21
- {
22
- ...motion,
23
- onBeforeEnter: (element: { nativeView?: View }) => {
24
- if (element.nativeView)
25
- element.nativeView.accessibilityHidden = Boolean(props.accessibilityHidden)
26
-
27
- const page = element.nativeView?.page
28
- const focused = page && focusedView(page)
29
- trigger = focused ? new WeakRef(focused) : undefined
30
- restore = false
31
- },
32
- onAfterEnter: (element: { nativeView?: View }) => {
33
- const page = element.nativeView?.page
34
- notifyAccessibilityLayout(page ? focusedView(page) : undefined)
35
- },
36
- onBeforeLeave: (element: { nativeView?: View }) => {
37
- const view = element.nativeView
38
- if (!view?.page) return
39
- let focused = focusedView(view.page)
40
- while (focused && focused !== view) focused = focused.parent as View | undefined
41
- restore = focused === view
42
- view.accessibilityHidden = true
43
- },
44
- onAfterLeave: () => {
45
- const target = trigger?.deref()
46
- if (restore && target?.isLoaded) {
47
- if (isAndroid) target.android.performAccessibilityAction(64, null)
48
- else notifyAccessibilityLayout(target)
49
- }
50
- trigger = undefined
51
- restore = false
52
- },
18
+ function activeView(root: View): View | undefined {
19
+ if (
20
+ isAndroid
21
+ ? root.android?.hasFocus?.() && !root.android?.getFocusedChild?.()
22
+ : root.ios?.isFirstResponder
23
+ )
24
+ return root
25
+ let found: View | undefined
26
+ root.eachChildView((child) => {
27
+ found = activeView(child)
28
+ return !found
29
+ })
30
+ return found
31
+ }
32
+ function currentFocus(view: View) {
33
+ return view.page && (activeView(view.page) ?? focusedView(view.page))
34
+ }
35
+ function attach(view: View) {
36
+ const focusability = isAndroid ? view.android.getDescendantFocusability() : undefined
37
+ return state.attach({
38
+ animate(open, fromClosed) {
39
+ if (fromClosed) {
40
+ view.height = 0
41
+ view.opacity = 0
42
+ }
43
+ const recipe = motionRecipe(theme.value, open ? 'enter' : 'exit')
44
+ const size = animateSize(view, { height: open ? 'auto' : 0 }, recipe.transition)
45
+ const opacity = animate(view, { opacity: open ? 1 : 0 }, recipe.transition)
46
+ return {
47
+ finished: size.finished,
48
+ stop() {
49
+ size.stop({ restore: true })
50
+ opacity.stop()
51
+ },
52
+ }
53
53
  },
54
- {
55
- default: () =>
56
- show ? h(MColumn, mergeProps(layout, attrs, { key: 'content' }), slots) : null,
54
+ interactive(enabled) {
55
+ view.accessibilityHidden = !enabled || Boolean(props.accessibilityHidden)
56
+ view.isUserInteractionEnabled = enabled
57
+ if (isAndroid) view.android.setDescendantFocusability(enabled ? focusability : 393216)
57
58
  },
58
- )
59
+ captureFocus() {
60
+ const active = currentFocus(view)
61
+ let ancestor = active
62
+ while (ancestor && ancestor !== view) ancestor = ancestor.parent as View | undefined
63
+ if (active && !ancestor) trigger = new WeakRef(active)
64
+ },
65
+ restoreFocus() {
66
+ const focused = currentFocus(view)
67
+ let active = focused
68
+ while (active && active !== view) active = active.parent as View | undefined
69
+ const target = trigger?.deref()
70
+ if (active === view && target?.isLoaded) {
71
+ ;(focused as View & { dismissSoftInput?(): void })?.dismissSoftInput?.()
72
+ target.focus()
73
+ if (isAndroid) target.android.performAccessibilityAction(64, null)
74
+ else notifyAccessibilityLayout(target)
75
+ }
76
+ },
77
+ release() {
78
+ view.height = 'auto'
79
+ view.opacity = 1
80
+ if (isAndroid && view.android) view.android.setDescendantFocusability(focusability)
81
+ },
82
+ })
83
+ }
84
+ return () => {
85
+ const { show, grow, shrink, width, id, ...content } = props
86
+ return state.present.value
87
+ ? h(MBox, mergeProps({ grow, shrink, width, id }, attrs), {
88
+ default: () =>
89
+ h(
90
+ MBox,
91
+ {
92
+ clipToBounds: true,
93
+ accessibilityHidden: !show || props.accessibilityHidden,
94
+ onLoaded: (event: EventData) => attach(event.object as View),
95
+ onUnloaded: state.detach,
96
+ },
97
+ { default: () => h(MColumn, content, slots) },
98
+ ),
99
+ })
100
+ : null
59
101
  }
60
102
  },
61
103
  })
@@ -0,0 +1,83 @@
1
+ import { computed, defineComponent, h, mergeProps, provide, shallowRef } from 'nativescript-vue'
2
+ import type { EventData, View } from '@nativescript/core'
3
+ import { resolveSpace, stackLayout } from '@getcortexlabs/mavis-core'
4
+ import {
5
+ stackProps,
6
+ layoutDirection,
7
+ useLayoutShrink,
8
+ useMavisTheme,
9
+ } from '@getcortexlabs/mavis-core/vue'
10
+ import { boxStyle } from '../props.js'
11
+ import { useNativeViewAttrs } from '../accessibility.js'
12
+ import './layout.js'
13
+
14
+ const align = {
15
+ start: 'flex-start',
16
+ end: 'flex-end',
17
+ center: 'center',
18
+ stretch: 'stretch',
19
+ } as const
20
+ const justify = {
21
+ start: 'flex-start',
22
+ end: 'flex-end',
23
+ center: 'center',
24
+ between: 'space-between',
25
+ around: 'space-around',
26
+ } as const
27
+
28
+ export const MStack = defineComponent({
29
+ name: 'MStack',
30
+ inheritAttrs: false,
31
+ props: stackProps,
32
+ setup(props, { attrs, slots }) {
33
+ const { theme } = useMavisTheme()
34
+ const nativeAttrs = useNativeViewAttrs(props)
35
+ const shrink = useLayoutShrink()
36
+ const width = shallowRef<number>()
37
+ const layout = computed(() =>
38
+ stackLayout(
39
+ {
40
+ direction: props.direction,
41
+ gap: props.gap,
42
+ align: props.align,
43
+ justify: props.justify,
44
+ wrap: props.wrap,
45
+ },
46
+ props.responsive,
47
+ width.value,
48
+ ),
49
+ )
50
+ const direction = computed(() => layout.value.direction ?? props.direction)
51
+ provide(layoutDirection, direction)
52
+ const measure = (event: EventData) => {
53
+ const view = event.object as View
54
+ const size = view.getActualSize().width
55
+ // The inner layout occupies the outer Box's content area, after padding.
56
+ if (size > 0 && size !== width.value) width.value = size
57
+ }
58
+ return () =>
59
+ h(
60
+ 'MavisBox',
61
+ mergeProps({ style: boxStyle(theme.value, props, shrink.value) }, nativeAttrs(), attrs),
62
+ [
63
+ h(
64
+ 'MavisFlexLayout',
65
+ {
66
+ onLayoutChanged: measure,
67
+ onUnloaded: () => {
68
+ width.value = undefined
69
+ },
70
+ style: {
71
+ flexDirection: direction.value,
72
+ alignItems: align[layout.value.align ?? props.align],
73
+ justifyContent: justify[layout.value.justify ?? props.justify],
74
+ flexWrap: layout.value.wrap ? 'wrap' : 'nowrap',
75
+ gap: resolveSpace(theme.value, layout.value.gap ?? 'none'),
76
+ },
77
+ },
78
+ slots.default?.(),
79
+ ),
80
+ ],
81
+ )
82
+ },
83
+ })
@@ -3,7 +3,7 @@ import {
3
3
  textProps,
4
4
  useMavisTheme,
5
5
  inlineContent,
6
- useDefaultShrink,
6
+ useLayoutShrink,
7
7
  } from '@getcortexlabs/mavis-core/vue'
8
8
  import { fontFamily, nonNegative, validateWeight } from '@getcortexlabs/mavis-core'
9
9
  import { isAndroid } from '@nativescript/core'
@@ -19,7 +19,7 @@ export const MText = defineComponent({
19
19
  setup(props, { attrs, slots }) {
20
20
  const { theme } = useMavisTheme()
21
21
  const nativeAttrs = useNativeViewAttrs(props)
22
- const shrink = useDefaultShrink()
22
+ const shrink = useLayoutShrink()
23
23
  return () => {
24
24
  const type = theme.value.typography[props.variant]
25
25
  const runs =
@@ -46,7 +46,7 @@ export const MText = defineComponent({
46
46
  color: theme.value.colors[props.tone],
47
47
  textAlignment: props.align,
48
48
  flexGrow: nonNegative(props.grow, 'grow'),
49
- flexShrink: nonNegative(props.shrink ?? shrink, 'shrink'),
49
+ flexShrink: nonNegative(props.shrink ?? shrink.value, 'shrink'),
50
50
  minWidth: 0,
51
51
  },
52
52
  },
@@ -3,14 +3,16 @@ import {
3
3
  columnProps,
4
4
  useMavisTheme,
5
5
  layoutDirection,
6
- useDefaultShrink,
6
+ useLayoutShrink,
7
+ motionBoxProps,
7
8
  } from '@getcortexlabs/mavis-core/vue'
8
9
  import { defineComponent, h, mergeProps, provide, registerElement } from 'nativescript-vue'
9
10
  import { resolveSpace } from '@getcortexlabs/mavis-core'
10
- import { boxProps, boxStyle } from '../props.js'
11
+ import { boxStyle } from '../props.js'
11
12
  import { MavisFlexLayout } from '../../native/flex-layout'
12
13
  import { MavisBox } from '../../native/box'
13
14
  import { useNativeViewAttrs } from '../accessibility.js'
15
+ import { useMotionRegion } from '../use-motion-region.js'
14
16
 
15
17
  export type { Align, Justify } from '@getcortexlabs/mavis-core/vue'
16
18
 
@@ -42,7 +44,7 @@ function createLayout(name: string, direction: 'row' | 'column') {
42
44
  setup(props, { attrs, slots }) {
43
45
  const { theme } = useMavisTheme()
44
46
  const nativeAttrs = useNativeViewAttrs(props)
45
- const shrink = useDefaultShrink()
47
+ const shrink = useLayoutShrink()
46
48
  provide(layoutDirection, direction)
47
49
  return () =>
48
50
  h(
@@ -50,7 +52,7 @@ function createLayout(name: string, direction: 'row' | 'column') {
50
52
  mergeProps(
51
53
  {
52
54
  style: {
53
- ...boxStyle(theme.value, props, shrink),
55
+ ...boxStyle(theme.value, props, shrink.value),
54
56
  flexDirection: direction,
55
57
  alignItems: alignment[props.align],
56
58
  justifyContent: distribution[props.justify],
@@ -74,15 +76,21 @@ export const MColumn = createLayout('MColumn', 'column')
74
76
  export const MBox = defineComponent({
75
77
  name: 'MBox',
76
78
  inheritAttrs: false,
77
- props: boxProps,
79
+ props: motionBoxProps,
78
80
  setup(props, { attrs, slots }) {
81
+ const region = useMotionRegion(() => props.motionRegion)
79
82
  const { theme } = useMavisTheme()
80
83
  const nativeAttrs = useNativeViewAttrs(props)
81
- const shrink = useDefaultShrink()
84
+ const shrink = useLayoutShrink()
82
85
  return () =>
83
86
  h(
84
87
  'MavisBox',
85
- mergeProps({ style: boxStyle(theme.value, props, shrink) }, nativeAttrs(), attrs),
88
+ mergeProps(
89
+ { style: boxStyle(theme.value, props, shrink.value) },
90
+ nativeAttrs(),
91
+ attrs,
92
+ region,
93
+ ),
86
94
  slots.default?.(),
87
95
  )
88
96
  },