@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
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "@getcortexlabs/mavis",
3
- "version": "0.1.0-alpha.4",
3
+ "version": "0.1.0-alpha.6",
4
4
  "description": "Mavis UI foundations for NativeScript, with a Vue integration.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "exports": {
8
+ "./app-icons": {
9
+ "types": "./dist/app-icons.d.ts",
10
+ "default": "./dist/app-icons.js"
11
+ },
8
12
  ".": {
9
13
  "types": "./dist/index.d.ts",
10
14
  "default": "./dist/index.js"
@@ -28,7 +32,7 @@
28
32
  },
29
33
  "peerDependencies": {
30
34
  "@nativescript/core": "^9.1.3",
31
- "@rafaelaugusto/jolt": "^0.1.0-rc.6",
35
+ "@rafaelaugusto/jolt": "^0.1.0-rc.8",
32
36
  "nativescript-vue": "^3.1.3"
33
37
  },
34
38
  "peerDependenciesMeta": {
@@ -37,7 +41,7 @@
37
41
  }
38
42
  },
39
43
  "dependencies": {
40
- "@getcortexlabs/mavis-core": "0.1.0-alpha.4"
44
+ "@getcortexlabs/mavis-core": "0.1.0-alpha.6"
41
45
  },
42
46
  "nativescript": {
43
47
  "platforms": {
@@ -0,0 +1,21 @@
1
+ import { createAppIconController, type AppIconChoice } from '@getcortexlabs/mavis-core'
2
+ import { nativeAppIcons } from './native/app-icons'
3
+
4
+ export interface NativeAppIcon extends AppIconChoice {
5
+ /** null for the primary icon; alternate names must appear in CFBundleAlternateIcons. */
6
+ iosName: string | null
7
+ /** Fully qualified activity-alias name, including the primary launcher alias. */
8
+ androidAlias: string
9
+ }
10
+ export interface AppIconsOptions {
11
+ primary: string
12
+ icons: readonly NativeAppIcon[]
13
+ }
14
+
15
+ /** Optional integration: importing Mavis components never changes launcher configuration. */
16
+ export function createAppIcons(options: AppIconsOptions) {
17
+ const config = { primary: options.primary, icons: options.icons.map((icon) => ({ ...icon })) }
18
+ return createAppIconController(config.icons, config.primary, nativeAppIcons(config))
19
+ }
20
+ export { AppIconError } from '@getcortexlabs/mavis-core'
21
+ export type { AppIconController, AppIconChoice } from '@getcortexlabs/mavis-core'
package/src/files.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { createNativeFilePicker } from './native/file-picker'
2
+ export { getNativeFile } from './native/file-access.js'
3
+ export type { NativeFileAccess, NativeFileReadHandle } from './native/file-access.js'
@@ -0,0 +1,95 @@
1
+ import { Application } from '@nativescript/core'
2
+ import { SDK_VERSION } from '@nativescript/core/utils/constants'
3
+ import { AppIconError, type AppIconAdapter } from '@getcortexlabs/mavis-core'
4
+ import type { AppIconsOptions } from '../app-icons.js'
5
+
6
+ type Component = object
7
+ interface PackageManager {
8
+ getActivityInfo(
9
+ component: Component,
10
+ flags: number,
11
+ ): { enabled: boolean; targetActivity: string | null }
12
+ getComponentEnabledSetting(component: Component): number
13
+ setComponentEnabledSetting(component: Component, state: number, flags: number): void
14
+ setComponentEnabledSettings(settings: object): void
15
+ }
16
+ declare const android: {
17
+ content: {
18
+ ComponentName: new (context: object, name: string) => Component
19
+ pm: {
20
+ PackageManager: {
21
+ ComponentEnabledSetting: new (component: Component, state: number, flags: number) => object
22
+ }
23
+ }
24
+ }
25
+ }
26
+ declare const java: { util: { ArrayList: new () => { add(value: object): void } } }
27
+
28
+ export function nativeAppIcons(options: AppIconsOptions): AppIconAdapter {
29
+ const aliases = new Set<string>()
30
+ for (const icon of options.icons) {
31
+ if (!/^[\w]+(?:\.[\w$]+)+$/.test(icon.androidAlias) || aliases.has(icon.androidAlias))
32
+ throw new AppIconError(
33
+ 'configuration',
34
+ 'Android needs unique fully qualified activity-alias names.',
35
+ )
36
+ aliases.add(icon.androidAlias)
37
+ }
38
+ const runtime = () => {
39
+ const context = Application.android.context
40
+ const manager = context.getPackageManager() as PackageManager
41
+ const choices = options.icons.map((icon) => {
42
+ const component = new android.content.ComponentName(context, icon.androidAlias)
43
+ const info = manager.getActivityInfo(component, 512) // MATCH_DISABLED_COMPONENTS
44
+ if (!info.targetActivity)
45
+ throw new AppIconError('configuration', `${icon.androidAlias} must be an activity-alias.`)
46
+ const state = manager.getComponentEnabledSetting(component)
47
+ return { ...icon, component, state, enabled: state === 1 || (state === 0 && info.enabled) }
48
+ })
49
+ return { manager, choices }
50
+ }
51
+ return {
52
+ supported: () => Boolean(Application.android.context),
53
+ current() {
54
+ const enabled = runtime().choices.filter((icon) => icon.enabled)
55
+ return enabled.length === 1 ? enabled[0]!.id : undefined
56
+ },
57
+ async select(id) {
58
+ const { manager, choices } = runtime()
59
+ const next = choices.find((icon) => icon.id === id)!
60
+ try {
61
+ if (SDK_VERSION >= 33) {
62
+ const settings = new java.util.ArrayList()
63
+ for (const icon of choices)
64
+ settings.add(
65
+ new android.content.pm.PackageManager.ComponentEnabledSetting(
66
+ icon.component,
67
+ icon.id === id ? 1 : 2,
68
+ 1,
69
+ ),
70
+ )
71
+ manager.setComponentEnabledSettings(settings)
72
+ } else {
73
+ // Keep at least one launcher entry enabled throughout the non-atomic fallback.
74
+ manager.setComponentEnabledSetting(next.component, 1, 1) // ENABLED, DONT_KILL_APP
75
+ for (const icon of choices)
76
+ if (icon.id !== id) manager.setComponentEnabledSetting(icon.component, 2, 1)
77
+ }
78
+ } catch (cause) {
79
+ const rollback: unknown[] = []
80
+ for (const icon of [...choices].sort((a, b) => Number(b.enabled) - Number(a.enabled))) {
81
+ try {
82
+ manager.setComponentEnabledSetting(icon.component, icon.state, 1)
83
+ } catch (error) {
84
+ rollback.push(error)
85
+ }
86
+ }
87
+ throw new AppIconError('platform', 'Android could not update launcher aliases.', {
88
+ cause: rollback.length
89
+ ? new AggregateError([cause, ...rollback], 'Launcher rollback failed')
90
+ : cause,
91
+ })
92
+ }
93
+ },
94
+ }
95
+ }
@@ -0,0 +1,74 @@
1
+ import { Utils } from '@nativescript/core'
2
+ import { AppIconError, type AppIconAdapter } from '@getcortexlabs/mavis-core'
3
+ import type { AppIconsOptions } from '../app-icons.js'
4
+
5
+ declare const UIApplication: {
6
+ sharedApplication: {
7
+ supportsAlternateIcons: boolean
8
+ alternateIconName: string | null
9
+ setAlternateIconNameCompletionHandler(
10
+ name: string | null,
11
+ complete: (error: { localizedDescription: string } | null) => void,
12
+ ): void
13
+ }
14
+ }
15
+ interface Dictionary {
16
+ objectForKey(key: string): Dictionary | undefined
17
+ }
18
+ declare const NSBundle: {
19
+ mainBundle: { objectForInfoDictionaryKey(key: string): Dictionary | undefined }
20
+ }
21
+
22
+ export function nativeAppIcons(options: AppIconsOptions): AppIconAdapter {
23
+ const names = new Set<string | null>()
24
+ for (const icon of options.icons) {
25
+ if (
26
+ (icon.iosName !== null && typeof icon.iosName !== 'string') ||
27
+ (icon.id === options.primary) !== (icon.iosName === null) ||
28
+ names.has(icon.iosName) ||
29
+ icon.iosName === ''
30
+ )
31
+ throw new AppIconError(
32
+ 'configuration',
33
+ 'iOS needs one primary icon and unique alternate names.',
34
+ )
35
+ names.add(icon.iosName)
36
+ }
37
+ const application = () => UIApplication.sharedApplication
38
+ return {
39
+ supported: () => Boolean(application().supportsAlternateIcons),
40
+ current: () =>
41
+ options.icons.find((icon) => icon.iosName === (application().alternateIconName ?? null))?.id,
42
+ select(id) {
43
+ const icon = options.icons.find((choice) => choice.id === id)!
44
+ if (icon.iosName !== null) {
45
+ const declared = ['CFBundleIcons', 'CFBundleIcons~ipad'].some((key) =>
46
+ NSBundle.mainBundle
47
+ .objectForInfoDictionaryKey(key)
48
+ ?.objectForKey('CFBundleAlternateIcons')
49
+ ?.objectForKey(icon.iosName!),
50
+ )
51
+ if (!declared)
52
+ return Promise.reject(
53
+ new AppIconError('configuration', `Missing bundled alternate icon: ${icon.iosName}`),
54
+ )
55
+ }
56
+ return new Promise((resolve, reject) => {
57
+ Utils.executeOnMainThread(() => {
58
+ try {
59
+ application().setAlternateIconNameCompletionHandler(icon.iosName, (error) => {
60
+ // UIKit may invoke completion away from its main queue.
61
+ Utils.executeOnMainThread(() =>
62
+ error
63
+ ? reject(new AppIconError('platform', error.localizedDescription))
64
+ : resolve(),
65
+ )
66
+ })
67
+ } catch (cause) {
68
+ reject(new AppIconError('platform', 'iOS could not change the app icon.', { cause }))
69
+ }
70
+ })
71
+ })
72
+ },
73
+ }
74
+ }
@@ -0,0 +1,12 @@
1
+ import type { AppIconAdapter } from '@getcortexlabs/mavis-core'
2
+ import { AppIconError } from '@getcortexlabs/mavis-core'
3
+ import type { AppIconsOptions } from '../app-icons.js'
4
+
5
+ export function nativeAppIcons(_options: AppIconsOptions): AppIconAdapter {
6
+ return {
7
+ supported: () => false,
8
+ current: () => undefined,
9
+ select: () =>
10
+ Promise.reject(new AppIconError('unsupported', 'App icons require iOS or Android.')),
11
+ }
12
+ }
@@ -0,0 +1,11 @@
1
+ import type { TextField } from '@nativescript/core'
2
+ declare const android: {
3
+ view: { inputmethod: { BaseInputConnection: { getComposingSpanStart(text: unknown): number } } }
4
+ }
5
+
6
+ export function comboboxComposing(view: TextField | undefined): boolean {
7
+ return Boolean(
8
+ view?.android &&
9
+ android.view.inputmethod.BaseInputConnection.getComposingSpanStart(view.android.getText()) >= 0,
10
+ )
11
+ }
@@ -0,0 +1,6 @@
1
+ import type { TextField } from '@nativescript/core'
2
+
3
+ /** iOS marked text must finish before a remote query can observe it. */
4
+ export function comboboxComposing(view: TextField | undefined): boolean {
5
+ return Boolean(view?.ios?.markedTextRange)
6
+ }
@@ -0,0 +1,71 @@
1
+ import type { FileHandle } from '@getcortexlabs/mavis-core'
2
+
3
+ export interface NativeFileReadHandle {
4
+ /** Android java.io.InputStream or an opened iOS NSInputStream. */
5
+ readonly native: unknown
6
+ close(): void
7
+ }
8
+ export interface NativeFileAccess {
9
+ readonly platform: 'android' | 'ios'
10
+ /** Android content Uri or iOS NSURL. Never a portable filesystem path. */
11
+ readonly native: unknown
12
+ /** Close after use. Removing/disposal also closes streams still owned by this handle. */
13
+ openRead(): NativeFileReadHandle
14
+ }
15
+
16
+ const handles = new WeakMap<FileHandle, NativeFileAccess>()
17
+
18
+ export function getNativeFile(handle: FileHandle): NativeFileAccess {
19
+ const access = handles.get(handle)
20
+ if (!access) throw new Error('This native file handle is unavailable or has been released')
21
+ return access
22
+ }
23
+
24
+ /** @internal Platform adapters register a resource without exposing it in item metadata. */
25
+ export function ownNativeFile(
26
+ platform: NativeFileAccess['platform'],
27
+ native: unknown,
28
+ open: () => { native: unknown; close(): void },
29
+ cleanup: () => void,
30
+ ) {
31
+ const handle = Object.freeze({}) as FileHandle
32
+ const readers = new Set<NativeFileReadHandle>()
33
+ let released = false
34
+ const access: NativeFileAccess = {
35
+ platform,
36
+ native,
37
+ openRead() {
38
+ if (released) throw new Error('This native file has been released')
39
+ const reader = open()
40
+ let closed = false
41
+ const owned = {
42
+ native: reader.native,
43
+ close() {
44
+ if (closed) return
45
+ closed = true
46
+ readers.delete(owned)
47
+ reader.close()
48
+ },
49
+ }
50
+ readers.add(owned)
51
+ return owned
52
+ },
53
+ }
54
+ handles.set(handle, access)
55
+ return {
56
+ handle,
57
+ release() {
58
+ if (released) return
59
+ released = true
60
+ handles.delete(handle)
61
+ for (const reader of readers) {
62
+ try {
63
+ reader.close()
64
+ } catch {
65
+ /* continue cleanup */
66
+ }
67
+ }
68
+ cleanup()
69
+ },
70
+ }
71
+ }
@@ -0,0 +1,191 @@
1
+ import { Application, ImageSource } from '@nativescript/core'
2
+ import { SDK_VERSION } from '@nativescript/core/utils/constants'
3
+ import type { FilePickerAdapter, SelectedFile } from '@getcortexlabs/mavis-core'
4
+ import { ownNativeFile } from './file-access.js'
5
+
6
+ interface Uri {
7
+ toString(): string
8
+ getLastPathSegment(): string
9
+ }
10
+ interface Stream {
11
+ close(): void
12
+ }
13
+ interface Cursor {
14
+ moveToFirst(): boolean
15
+ getColumnIndex(name: string): number
16
+ isNull(index: number): boolean
17
+ getString(index: number): string
18
+ getLong(index: number): number
19
+ close(): void
20
+ }
21
+ interface Resolver {
22
+ getType(uri: Uri): string | null
23
+ query(uri: Uri, projection: null, selection: null, args: null, order: null): Cursor | null
24
+ openInputStream(uri: Uri): Stream | null
25
+ loadThumbnail(uri: Uri, size: unknown, cancellation: null): unknown
26
+ }
27
+ interface Intent {
28
+ addCategory(value: string): Intent
29
+ setType(type: string): Intent
30
+ putExtra(name: string, value: unknown): Intent
31
+ addFlags(flags: number): Intent
32
+ getData(): Uri | null
33
+ getClipData(): { getItemCount(): number; getItemAt(index: number): { getUri(): Uri } } | null
34
+ }
35
+ declare const android: {
36
+ content: {
37
+ Intent: {
38
+ new (action: string): Intent
39
+ ACTION_OPEN_DOCUMENT: string
40
+ CATEGORY_OPENABLE: string
41
+ EXTRA_ALLOW_MULTIPLE: string
42
+ EXTRA_MIME_TYPES: string
43
+ FLAG_GRANT_READ_URI_PERMISSION: number
44
+ }
45
+ }
46
+ util: { Size: new (width: number, height: number) => unknown }
47
+ webkit: {
48
+ MimeTypeMap: { getSingleton(): { getMimeTypeFromExtension(extension: string): string | null } }
49
+ }
50
+ }
51
+
52
+ // One active system picker per adapter; unique codes prevent cross-delivery between owners.
53
+ let requestSequence = 0x4d00
54
+ export function createNativeFilePicker(): FilePickerAdapter {
55
+ return {
56
+ pick(request, cancellation) {
57
+ if (cancellation.cancelled) return Promise.resolve(null)
58
+ const app = Application.android
59
+ const activity = app.foregroundActivity ?? app.startActivity
60
+ if (!activity)
61
+ return Promise.reject(new Error('File selection requires a foreground Activity'))
62
+ const resolver = activity.getContentResolver() as Resolver
63
+ const requestCode = requestSequence++
64
+ if (requestSequence > 0x5d00) requestSequence = 0x4d00
65
+ return new Promise((resolve, reject) => {
66
+ let done = false
67
+ let unsubscribe = () => {}
68
+ function finish(files: readonly SelectedFile[] | null, error?: unknown) {
69
+ if (done) {
70
+ for (const file of files ?? []) file.release()
71
+ return
72
+ }
73
+ done = true
74
+ unsubscribe()
75
+ app.off('activityResult', result)
76
+ if (error) reject(error)
77
+ else resolve(files)
78
+ }
79
+ function result(event: { requestCode: number; resultCode: number; intent?: Intent }) {
80
+ if (event.requestCode !== requestCode) return
81
+ if (event.resultCode !== -1 || !event.intent) {
82
+ finish(null)
83
+ return
84
+ }
85
+ const files: SelectedFile[] = []
86
+ try {
87
+ const uris: Uri[] = []
88
+ const clip = event.intent.getClipData()
89
+ if (clip)
90
+ for (let index = 0; index < clip.getItemCount(); index++)
91
+ uris.push(clip.getItemAt(index).getUri())
92
+ else {
93
+ const uri = event.intent.getData()
94
+ if (uri) uris.push(uri)
95
+ }
96
+ const unique = new Set<string>()
97
+ for (const uri of uris) {
98
+ if (unique.has(uri.toString())) continue
99
+ unique.add(uri.toString())
100
+ let name = uri.getLastPathSegment()?.split('/').at(-1) || 'Document'
101
+ let size: number | undefined
102
+ const cursor = resolver.query(uri, null, null, null, null)
103
+ try {
104
+ if (cursor?.moveToFirst()) {
105
+ const nameColumn = cursor.getColumnIndex('_display_name')
106
+ const sizeColumn = cursor.getColumnIndex('_size')
107
+ if (nameColumn >= 0 && !cursor.isNull(nameColumn))
108
+ name = cursor.getString(nameColumn)
109
+ if (sizeColumn >= 0 && !cursor.isNull(sizeColumn))
110
+ size = Number(cursor.getLong(sizeColumn))
111
+ }
112
+ } finally {
113
+ cursor?.close()
114
+ }
115
+ let released = false
116
+ const owner = ownNativeFile(
117
+ 'android',
118
+ uri,
119
+ () => {
120
+ const stream = resolver.openInputStream(uri)
121
+ if (!stream) throw new Error('The document provider did not open this file')
122
+ return { native: stream, close: () => stream.close() }
123
+ },
124
+ () => {
125
+ released = true
126
+ },
127
+ )
128
+ files.push({
129
+ name,
130
+ size,
131
+ type: resolver.getType(uri) ?? undefined,
132
+ ...owner,
133
+ async preview() {
134
+ if (released || SDK_VERSION < 29) return
135
+ // The provider creates a bounded thumbnail; failures retain the file.
136
+ const bitmap = resolver.loadThumbnail(uri, new android.util.Size(160, 160), null)
137
+ if (released || !bitmap) return
138
+ return new ImageSource(bitmap)
139
+ },
140
+ })
141
+ }
142
+ finish(files)
143
+ } catch (error) {
144
+ for (const file of files) file.release()
145
+ finish(null, error)
146
+ }
147
+ }
148
+ app.on('activityResult', result)
149
+ unsubscribe = cancellation.onCancel(() => {
150
+ // finishActivity only dismisses the child Activity launched by this request.
151
+ try {
152
+ activity.finishActivity(requestCode)
153
+ } finally {
154
+ finish(null)
155
+ }
156
+ })
157
+ try {
158
+ const intent = new android.content.Intent(android.content.Intent.ACTION_OPEN_DOCUMENT)
159
+ intent.addCategory(android.content.Intent.CATEGORY_OPENABLE)
160
+ const hints = request.accept.map((hint) =>
161
+ hint.startsWith('.')
162
+ ? android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(
163
+ hint.slice(1).toLowerCase(),
164
+ )
165
+ : hint,
166
+ )
167
+ const types = hints.filter((hint): hint is string => Boolean(hint))
168
+ // Unknown extensions widen the platform hint; core checks names after selection.
169
+ intent.setType(types.length === 1 && types.length === hints.length ? types[0]! : '*/*')
170
+ if (types.length > 1 && types.length === hints.length) {
171
+ // A JS array selects the Bundle overload in the NativeScript bridge.
172
+ const nativeTypes = (
173
+ Array as ArrayConstructor & {
174
+ create(type: string, length: number): string[]
175
+ }
176
+ ).create('java.lang.String', types.length)
177
+ types.forEach((type, index) => {
178
+ nativeTypes[index] = type
179
+ })
180
+ intent.putExtra(android.content.Intent.EXTRA_MIME_TYPES, nativeTypes)
181
+ }
182
+ intent.putExtra(android.content.Intent.EXTRA_ALLOW_MULTIPLE, request.multiple)
183
+ intent.addFlags(android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION)
184
+ activity.startActivityForResult(intent, requestCode)
185
+ } catch (error) {
186
+ finish(null, error)
187
+ }
188
+ })
189
+ },
190
+ }
191
+ }