@getcortexlabs/create-mavis 0.1.0-rc.13 → 0.1.0-rc.15

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 (80) hide show
  1. package/README.md +44 -7
  2. package/package.json +4 -2
  3. package/src/adapters.mjs +56 -20
  4. package/src/add-desktop.mjs +308 -0
  5. package/src/add-macos.mjs +386 -0
  6. package/src/capabilities.mjs +352 -85
  7. package/src/cli.mjs +181 -9
  8. package/src/desktop.mjs +155 -0
  9. package/src/doctor.mjs +181 -18
  10. package/src/macos-capabilities.generated.mjs +4190 -0
  11. package/src/macos.mjs +147 -29
  12. package/src/migrate-directory.mjs +121 -0
  13. package/src/native-framework.mjs +144 -0
  14. package/src/portability.mjs +123 -5
  15. package/src/scaffold.mjs +59 -11
  16. package/src/ui.mjs +69 -12
  17. package/templates/desktop/common/LICENSE +21 -0
  18. package/templates/desktop/common/build.mjs +58 -0
  19. package/templates/desktop/common/src/components.ts +60 -0
  20. package/templates/desktop/common/src/contract.mjs +35 -0
  21. package/templates/desktop/common/src/renderer.ts +76 -0
  22. package/templates/desktop/common/src/storage.ts +29 -0
  23. package/templates/desktop/directory/main.ts +35 -0
  24. package/templates/desktop/macos/launch.mjs +6 -0
  25. package/templates/desktop/macos/package.mjs +114 -0
  26. package/templates/desktop/macos/src/host.mjs +468 -0
  27. package/templates/desktop/macos/src/motion.mjs +51 -0
  28. package/templates/desktop/welcome/Welcome.vue +56 -0
  29. package/templates/desktop/welcome/main.ts +24 -0
  30. package/templates/desktop/windows/NativeScript-LICENSE +19 -0
  31. package/templates/desktop/windows/launch.mjs +16 -0
  32. package/templates/desktop/windows/package.mjs +54 -0
  33. package/templates/desktop/windows/prepare-host.mjs +73 -0
  34. package/templates/desktop/windows/src/host.mjs +277 -0
  35. package/templates/directory/host/directory-storage.ts +78 -0
  36. package/templates/directory/macos/DirectoryStorage.swift +68 -0
  37. package/templates/directory/mobile/src/app.ts +11 -8
  38. package/templates/directory/nuxt/app/plugins/mavis.ts +11 -8
  39. package/templates/directory/shared/Edit.vue +8 -5
  40. package/templates/directory/shared/directory-store.ts +42 -46
  41. package/templates/directory/vite/src/main.ts +11 -8
  42. package/templates/macos/examples/tasks/shared/TaskDetail.lite.tsx +2 -2
  43. package/templates/macos/examples/tasks/shared/Tasks.lite.tsx +2 -2
  44. package/templates/macos/examples/tasks/shared/types.ts +1 -0
  45. package/templates/macos/mobile/src/App.vue +4 -2
  46. package/templates/macos/native/Package.swift +3 -1
  47. package/templates/macos/native/Sources/MavisDesktop/App.swift +26 -11
  48. package/templates/macos/native/Sources/MavisDesktop/Fonts/LICENSE +45 -0
  49. package/templates/macos/native/Sources/MavisDesktop/Fonts/lucide.ttf +0 -0
  50. package/templates/macos/scripts/generate.mjs +3 -26
  51. package/templates/macos/scripts/macos-manifest.mjs +33 -0
  52. package/templates/macos/scripts/macos.mjs +20 -18
  53. package/templates/macos/web/index.html +1 -1
  54. package/templates/macos/web/src/main.js +176 -3
  55. package/templates/macos/web/src/mavis.js +2 -0
  56. package/templates/macos/web/src/style.css +2 -1
  57. package/templates/macos/web/vite.config.mjs +12 -1
  58. package/templates/migrations/directory-rc13.json +36 -0
  59. package/templates/mobile/src/mavis.ts +2 -82
  60. package/templates/mobile/webpack.config.js +4 -0
  61. package/templates/native-framework/angular/screen.ts +84 -0
  62. package/templates/native-framework/common/nativescript.config.ts +6 -0
  63. package/templates/native-framework/common/src/app.ts +5 -0
  64. package/templates/native-framework/common/src/model.ts +40 -0
  65. package/templates/native-framework/common/src/references.d.ts +8 -0
  66. package/templates/native-framework/common/tsconfig.json +16 -0
  67. package/templates/native-framework/common/webpack.config.js +67 -0
  68. package/templates/native-framework/plain/screen.ts +102 -0
  69. package/templates/native-framework/react/screen.ts +83 -0
  70. package/templates/native-framework/solid/screen.ts +111 -0
  71. package/templates/native-framework/svelte/Welcome.svelte +26 -0
  72. package/templates/native-framework/svelte/screen.ts +14 -0
  73. package/templates/native-framework/svelte-tooling/svelte.config.js +20 -0
  74. package/templates/nuxt/app/mavis.ts +2 -84
  75. package/templates/vite/src/mavis.ts +2 -84
  76. package/templates/macos/scripts/portable/emit-swift.mjs +0 -1287
  77. package/templates/macos/scripts/portable/emit-vue.mjs +0 -615
  78. package/templates/macos/scripts/portable/index.mjs +0 -95
  79. package/templates/macos/scripts/portable/model.mjs +0 -1441
  80. package/templates/macos/scripts/portable/program.mjs +0 -163
@@ -6,7 +6,8 @@ body {
6
6
  margin: 0;
7
7
  font-family: system-ui, sans-serif;
8
8
  }
9
- #app {
9
+ /* The page around a screen without an MScreen of its own. */
10
+ .mavis-page {
10
11
  max-width: __MAVIS_WEB_WIDTH__;
11
12
  margin: 0 auto;
12
13
  padding: clamp(24px, 6vw, 64px);
@@ -1,3 +1,14 @@
1
1
  import { defineConfig } from 'vite'
2
+ import { fileURLToPath } from 'node:url'
2
3
  import vue from '@vitejs/plugin-vue'
3
- export default defineConfig({ plugins: [vue()], resolve: { dedupe: ['vue'] } })
4
+ // Shared Vue files run here as written: they import Mavis from #mavis.
5
+ export default defineConfig({
6
+ plugins: [vue()],
7
+ resolve: {
8
+ alias: {
9
+ '#shared-ui': fileURLToPath(new URL('../../shared', import.meta.url)),
10
+ '#mavis': fileURLToPath(new URL('./src/mavis.js', import.meta.url)),
11
+ },
12
+ dedupe: ['vue'],
13
+ },
14
+ })
@@ -0,0 +1,36 @@
1
+ {
2
+ "release": "v0.1.0-rc.13",
3
+ "commit": "165caa56d249d82d1190382648e3b8731e3bd30d",
4
+ "files": {
5
+ "shared/directory-store.ts": {
6
+ "source": "1057a52eb5b3a6462ddbc5af2d15fa942901933fa5a8d80cb7257dda3cb688f9"
7
+ },
8
+ "shared/Edit.vue": {
9
+ "source": "99dd95f1e51c6f772e414cbb3776cfb87e69c466d629cd64a3a1e6c4d9498b02"
10
+ },
11
+ "shared/Directory.vue": {
12
+ "source": "df10903ecfc74c35f04d7dca6c607577f5a64481cad2e4f07041c4e91b02b869"
13
+ },
14
+ "shared/Details.vue": {
15
+ "source": "13447a479351d429121bc759290a9b9681afc1acdf030e47f8d2d3b0ee546f7a"
16
+ },
17
+ "shared/routes.ts": {
18
+ "source": "8834443fe8da682171d30170e49a2ce23825c30512dc1ff0fdbb5b7941028d66"
19
+ },
20
+ "vite/src/main.ts": {
21
+ "source": "a31a5eeb43f6a2d546cdc178f54d7cb42ef6a12b4851b38d9e7f4f366552a5d9",
22
+ "light": "77f63c02e6af15eedc365ce2594723a26c81d65cf48c29b9dbcc35ca1ed2dbc0",
23
+ "dark": "b96bf8489885b352ca9f2bfbcdc12000ebcf48eea36f815b07a0de0a682a6566"
24
+ },
25
+ "mobile/src/app.ts": {
26
+ "source": "fcf47aba9dfb7da5517c29d2df4af9942ff4a0859089ff39ff551c003f845729",
27
+ "light": "95f9450e62357f0a973bdffc8d9ef86c7f6834420cc60894eecc5d1dfc30f181",
28
+ "dark": "f2002da060b1b7da65c60bef43b0f4dedac0caad1bed570b7be9081274a044d5"
29
+ },
30
+ "nuxt/app/plugins/mavis.ts": {
31
+ "source": "2d3490d89991983850fe5e741cd3163f236d6f583f3c37f807eeeac968a9ae27",
32
+ "light": "bf7bf339f655642d56148e5c23cd75975c7a1e823a2ddf7d8647edf1c884debb",
33
+ "dark": "edefc0f4c15a4d3c2dac1257f5a54408e443c9fd55afba09bda1e1660c3ca166"
34
+ }
35
+ }
36
+ }
@@ -1,84 +1,4 @@
1
- // Resolved by this host. Shared screens import from #mavis.
2
- export {
3
- MThemeProvider,
4
- MPlatform,
5
- MPopover,
6
- MMenu,
7
- MAppBar,
8
- MTabBar,
9
- MTimePicker,
10
- MVirtualList,
11
- MDataTable,
12
- MCarousel,
13
- MRangeSlider,
14
- MCalendar,
15
- MRating,
16
- MTreeView,
17
- MCommandPalette,
18
- MNavigationRail,
19
- MBreadcrumb,
20
- MTooltip,
21
- MTimeline,
22
- MChart,
23
- MImageViewer,
24
- MSortableList,
25
- MSwipeActions,
26
- MNumberFlow,
27
- MResizablePanels,
28
- MImageCompare,
29
- MSpan,
30
- MScreen,
31
- MBox,
32
- MRow,
33
- MColumn,
34
- MStack,
35
- MGrid,
36
- MLink,
37
- MCard,
38
- MText,
39
- MButton,
40
- MSlider,
41
- MSwitch,
42
- MCheckbox,
43
- MRadioGroup,
44
- MSelect,
45
- MToast,
46
- MDialog,
47
- MTabs,
48
- MSkeleton,
49
- MChip,
50
- MEmptyState,
51
- MProgress,
52
- MAccordion,
53
- MSegmentedControl,
54
- MAlert,
55
- MListItem,
56
- MSeparator,
57
- MAvatar,
58
- MBadge,
59
- MInput,
60
- MIcon,
61
- MReveal,
62
- MSheet,
63
- MDatePicker,
64
- MDateRangePicker,
65
- MNumberInput,
66
- MMultiSelect,
67
- MImage,
68
- MCombobox,
69
- MFilePicker,
70
- MFormGroup,
71
- MFormErrors,
72
- MSteps,
73
- MPagination,
74
- useMavisPlatform,
75
- useMavisListMotion,
76
- useMavisTheme,
77
- useToast,
78
- useFormController,
79
- useFormField,
80
- useFileSelection,
81
- useMavisNavigation,
82
- } from '@getcortexlabs/mavis/vue'
1
+ // Resolved by this host. Shared screens import the renderer's public API from #mavis.
2
+ export * from '@getcortexlabs/mavis/vue'
83
3
  export * from '@getcortexlabs/mavis-core'
84
4
  export { formatDateTime, dateTimeToCivilDate } from '@getcortexlabs/mavis/date-format'
@@ -8,6 +8,10 @@ module.exports = (env) => {
8
8
  context: resolve(__dirname, 'node_modules/@getcortexlabs/mavis/fonts'),
9
9
  })
10
10
  webpack.chainWebpack((config) => {
11
+ // Shared value modules can differ from SFC names only in case (stays.ts/Stays.vue).
12
+ // NativeScript-Vue puts .vue first; prefer TS for extensionless module imports while
13
+ // component imports keep their explicit .vue extension on case-insensitive hosts.
14
+ config.resolve.extensions.prepend('.ts')
11
15
  config.resolve.alias.set('#shared-ui', resolve(__dirname, '__MAVIS_SHARED_ROOT__'))
12
16
  config.resolve.alias.set('#mavis$', resolve(__dirname, 'src/mavis.ts'))
13
17
  config.resolve.alias.set('vue$', resolve(__dirname, 'node_modules/nativescript-vue'))
@@ -0,0 +1,84 @@
1
+ import '@angular/compiler'
2
+ import { Component, signal, ViewChild } from '@angular/core'
3
+ import {
4
+ NativeScriptCommonModule,
5
+ bootstrapApplication,
6
+ runNativeScriptAngularApp,
7
+ } from '@nativescript/angular'
8
+ import { MAVIS_COMPONENTS, MInput } from '@getcortexlabs/mavis-angular-nativescript'
9
+ import { bridge, initial, theme, isolatedTheme, surface } from './model'
10
+
11
+ @Component({
12
+ selector: 'adapter-catalog',
13
+ standalone: true,
14
+ imports: [NativeScriptCommonModule, ...MAVIS_COMPONENTS],
15
+ template: `<Page actionBarHidden="true">
16
+ <MColumn
17
+ id="catalog"
18
+ gap="md"
19
+ padding="lg"
20
+ height="100%"
21
+ [backgroundColor]="background()"
22
+ [theme]="theme"
23
+ >
24
+ <MText id="heading" text="__MAVIS_NAME__" variant="title" [theme]="theme" />
25
+ <MRow id="row" gap="sm"
26
+ ><MButton
27
+ id="action"
28
+ [theme]="theme"
29
+ [text]="'Count ' + state().count"
30
+ [disabled]="state().disabled"
31
+ [loading]="state().loading"
32
+ (click)="update({ count: state().count + 1 })"
33
+ /></MRow>
34
+ <MInput
35
+ id="editor"
36
+ label="Name"
37
+ [theme]="theme"
38
+ [modelValue]="state().value"
39
+ [disabled]="state().disabled"
40
+ (modelValueChange)="update({ value: $event })"
41
+ />
42
+ @if (state().visible) {
43
+ <MBox
44
+ id="motion"
45
+ [width]="100"
46
+ [height]="30"
47
+ backgroundColor="#4f46e5"
48
+ [motionSurface]="surface"
49
+ />
50
+ }
51
+ <MBox padding="md" radius="md" [backgroundColor]="isolated.theme.colors.background"
52
+ ><MText id="isolated" text="Independent theme" [theme]="isolated"
53
+ /></MBox>
54
+ </MColumn>
55
+ </Page>`,
56
+ })
57
+ class Catalog {
58
+ @ViewChild(MInput) input?: MInput
59
+ background = signal(theme.theme.colors.background)
60
+ private offTheme = theme.subscribe(() => this.background.set(theme.theme.colors.background))
61
+ ngOnDestroy() {
62
+ this.offTheme()
63
+ }
64
+ state = signal({ ...initial })
65
+ theme = theme
66
+ isolated = isolatedTheme
67
+ surface = surface
68
+ update = (patch: Partial<typeof initial>) =>
69
+ this.state.update((value) => ({ ...value, ...patch }))
70
+ constructor() {
71
+ bridge.read = this.state
72
+ bridge.update = this.update
73
+ bridge.focus = () => this.input?.focusInput()
74
+ }
75
+ }
76
+ export function start() {
77
+ runNativeScriptAngularApp({
78
+ appModuleBootstrap: async () => {
79
+ const app = await bootstrapApplication(Catalog)
80
+ bridge.dispose = () => app.destroy()
81
+ return app
82
+ },
83
+ })
84
+ }
@@ -0,0 +1,6 @@
1
+ import type { NativeScriptConfig } from '@nativescript/core'
2
+ export default {
3
+ id: 'org.nativescript.__MAVIS_APPID__',
4
+ appPath: 'src',
5
+ appResourcesPath: 'App_Resources',
6
+ } satisfies NativeScriptConfig
@@ -0,0 +1,5 @@
1
+ import { Application } from '@nativescript/core'
2
+ import { start } from './screen'
3
+ import { bridge } from './model'
4
+ Application.on(Application.exitEvent, () => bridge.dispose?.())
5
+ start()
@@ -0,0 +1,40 @@
1
+ import { createMavisTheme } from '@getcortexlabs/mavis/native'
2
+ import { mavis, midnight } from '@getcortexlabs/mavis-core'
3
+ import { createMotionSurface } from '@getcortexlabs/mavis-core/experimental'
4
+
5
+ export type State = {
6
+ value: string
7
+ count: number
8
+ disabled: boolean
9
+ loading: boolean
10
+ visible: boolean
11
+ }
12
+ export const initial: State = {
13
+ value: 'Ada',
14
+ count: 0,
15
+ disabled: false,
16
+ loading: false,
17
+ visible: true,
18
+ }
19
+ export const theme = createMavisTheme(__MAVIS_THEME__)
20
+ export const isolatedTheme = createMavisTheme(midnight)
21
+ export const surface = createMotionSurface()
22
+ export const lifecycle = { active: 0, attached: 0, animations: 0 }
23
+ surface.use((motion) => {
24
+ lifecycle.active++
25
+ lifecycle.attached++
26
+ const animation = motion.animate({ opacity: [0.7, 1] }, { duration: 60 })
27
+ void animation.finished.then(() => {
28
+ lifecycle.animations++
29
+ })
30
+ return () => {
31
+ lifecycle.active--
32
+ animation.stop()
33
+ }
34
+ })
35
+ export const bridge: {
36
+ read?: () => State
37
+ update?: (patch: Partial<State>) => void
38
+ dispose?: () => void
39
+ focus?: () => void
40
+ } = {}
@@ -0,0 +1,8 @@
1
+ /// <reference types="@nativescript/types" />
2
+ /// <reference types="@nativescript/types-ios" />
3
+ /// <reference types="@nativescript/types-android" />
4
+
5
+ declare module '*.svelte' {
6
+ import type { SvelteComponentTyped } from 'svelte'
7
+ export default class Component extends SvelteComponentTyped {}
8
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "strict": true,
7
+ "ignoreDeprecations": "6.0",
8
+ "skipLibCheck": true,
9
+ "experimentalDecorators": true,
10
+ "useDefineForClassFields": false,
11
+ "esModuleInterop": true,
12
+ "lib": ["ES2023", "DOM"],
13
+ "types": ["@nativescript/types"]
14
+ },
15
+ "include": ["src"]
16
+ }
@@ -0,0 +1,67 @@
1
+ const { resolve, dirname } = require('node:path')
2
+ const webpack = require('@nativescript/webpack')
3
+ module.exports = (env) => {
4
+ const framework = '__MAVIS_FRAMEWORK__'
5
+ if (!['plain', 'react', 'angular', 'svelte', 'solid'].includes(framework))
6
+ throw new Error('Unknown framework')
7
+ webpack.init(env)
8
+ webpack.useConfig('typescript')
9
+ webpack.Utils.addCopyRule({
10
+ from: 'lucide.ttf',
11
+ to: 'fonts',
12
+ context: resolve(__dirname, 'node_modules/@getcortexlabs/mavis/fonts'),
13
+ })
14
+ webpack.chainWebpack((config) => {
15
+ config.resolve.alias.set(
16
+ '@nativescript/core',
17
+ resolve(__dirname, 'node_modules/@nativescript/core'),
18
+ )
19
+ config.resolve.alias.set('@rafaelaugusto/jolt$', require.resolve('@rafaelaugusto/jolt'))
20
+ config.resolve.merge({ conditionNames: ['svelte', 'browser', '...'] })
21
+ config.plugin('NoVueInDirectAdapters').use(
22
+ class {
23
+ apply(compiler) {
24
+ compiler.hooks.afterCompile.tap('NoVueInDirectAdapters', (compilation) => {
25
+ for (const module of compilation.modules) {
26
+ const file = module.resource?.replaceAll('\\', '/') ?? ''
27
+ if (
28
+ /\/node_modules\/(vue|@vue|nativescript-vue)\//.test(file) ||
29
+ /\/mavis\/dist\/vue\//.test(file)
30
+ )
31
+ throw new Error(`Direct ${framework} adapter imported Vue: ${file}`)
32
+ }
33
+ })
34
+ }
35
+ },
36
+ )
37
+ config.plugin('DefinePlugin').tap((args) => {
38
+ Object.assign(args[0], {
39
+ __DEV__: 'true',
40
+ __TEST__: 'false',
41
+ __FRAMEWORK__: JSON.stringify(framework),
42
+ __ADAPTER_CHECK__: 'false',
43
+ })
44
+ return args
45
+ })
46
+ // NativeScript's resolver otherwise chooses Solid's nonreactive Node/server condition.
47
+ if (framework === 'solid')
48
+ for (const name of ['solid-js', '@solidjs/signals', '@solidjs/universal']) {
49
+ const manifest = resolve(__dirname, 'node_modules', name, 'package.json')
50
+ const pkg = require(manifest)
51
+ let entry = pkg.exports['.']
52
+ while (typeof entry !== 'string') entry = entry.browser ?? entry.default
53
+ config.resolve.alias.set(`${name}$`, resolve(dirname(manifest), entry))
54
+ }
55
+ if (framework === 'svelte')
56
+ config.module
57
+ .rule('svelte')
58
+ .test(/\.svelte$/)
59
+ .use('svelte-loader')
60
+ .loader('svelte-loader')
61
+ .options({
62
+ compilerOptions: { dev: false, namespace: 'foreign' },
63
+ preprocess: require('./svelte.config.js').preprocess,
64
+ })
65
+ })
66
+ return webpack.resolveConfig()
67
+ }
@@ -0,0 +1,102 @@
1
+ import { Application, Page, GridLayout, type LayoutBase } from '@nativescript/core'
2
+ import { createNativeComponent } from '@getcortexlabs/mavis/native'
3
+ import { bridge, initial, theme, isolatedTheme, surface, type State } from './model'
4
+
5
+ export function start() {
6
+ Application.run({
7
+ create: () => {
8
+ let state: State = { ...initial }
9
+ const all: Array<{ dispose(): void }> = []
10
+ const create: typeof createNativeComponent = (name, props, options = {}) => {
11
+ const control = createNativeComponent(name, props, { theme, ...options })
12
+ all.push(control)
13
+ return control
14
+ }
15
+ const root = create('MColumn', {
16
+ id: 'catalog',
17
+ gap: 'md',
18
+ padding: 'lg',
19
+ height: '100%',
20
+ backgroundColor: theme.theme.colors.background,
21
+ })
22
+ const heading = create('MText', {
23
+ id: 'heading',
24
+ text: '__MAVIS_NAME__',
25
+ variant: 'title',
26
+ })
27
+ const row = create('MRow', { id: 'row', gap: 'sm' })
28
+ const button = create(
29
+ 'MButton',
30
+ { id: 'action', text: 'Count 0' },
31
+ { events: { activate: () => update({ count: state.count + 1 }) } },
32
+ )
33
+ const input = create(
34
+ 'MInput',
35
+ { id: 'editor', label: 'Name', modelValue: state.value },
36
+ { events: { valueChange: (value) => update({ value }) } },
37
+ )
38
+ const box = create('MBox', {
39
+ id: 'motion',
40
+ width: 100,
41
+ height: 30,
42
+ backgroundColor: '#4f46e5',
43
+ motionSurface: surface,
44
+ })
45
+ const separate = create(
46
+ 'MText',
47
+ { id: 'isolated', text: 'Independent theme' },
48
+ { theme: isolatedTheme },
49
+ )
50
+ const separateBox = create('MBox', {
51
+ padding: 'md',
52
+ radius: 'md',
53
+ backgroundColor: isolatedTheme.theme.colors.background,
54
+ })
55
+ separateBox.view.addChild(separate.view)
56
+ const offTheme = theme.subscribe(() =>
57
+ root.update({
58
+ id: 'catalog',
59
+ gap: 'md',
60
+ padding: 'lg',
61
+ height: '100%',
62
+ backgroundColor: theme.theme.colors.background,
63
+ }),
64
+ )
65
+ ;(row.view as LayoutBase).addChild(button.view)
66
+ for (const control of [heading, row, input, box, separateBox])
67
+ (root.view as LayoutBase).addChild(control.view)
68
+ function update(patch: Partial<State>) {
69
+ const before = state
70
+ state = { ...state, ...patch }
71
+ button.update({
72
+ id: 'action',
73
+ text: `Count ${state.count}`,
74
+ disabled: state.disabled,
75
+ loading: state.loading,
76
+ })
77
+ input.update({
78
+ id: 'editor',
79
+ label: 'Name',
80
+ modelValue: state.value,
81
+ disabled: state.disabled,
82
+ })
83
+ if (before.visible !== state.visible) {
84
+ if (state.visible) (root.view as LayoutBase).addChild(box.view)
85
+ else (root.view as LayoutBase).removeChild(box.view)
86
+ }
87
+ }
88
+ const page = new Page()
89
+ page.actionBarHidden = true
90
+ page.content = root.view
91
+ bridge.read = () => state
92
+ bridge.update = update
93
+ bridge.focus = input.focus
94
+ bridge.dispose = () => {
95
+ page.content = new GridLayout()
96
+ offTheme()
97
+ all.forEach((control) => control.dispose())
98
+ }
99
+ return page
100
+ },
101
+ })
102
+ }
@@ -0,0 +1,83 @@
1
+ import { Application, type View } from '@nativescript/core'
2
+ import { createElement as h, useState, useRef, useEffect } from 'react'
3
+ import { NSVRoot, render, unmountComponentAtNode } from 'react-nativescript'
4
+ import {
5
+ MColumn,
6
+ MRow,
7
+ MBox,
8
+ MText,
9
+ MButton,
10
+ MInput,
11
+ MThemeProvider,
12
+ type MavisComponentHandle,
13
+ } from '@getcortexlabs/mavis-react-nativescript'
14
+ import { bridge, initial, theme, isolatedTheme, surface } from './model'
15
+
16
+ function Catalog() {
17
+ const [state, setState] = useState(initial)
18
+ const [background, setBackground] = useState(theme.theme.colors.background)
19
+ useEffect(() => theme.subscribe(() => setBackground(theme.theme.colors.background)), [])
20
+ const input = useRef<MavisComponentHandle>(null)
21
+ bridge.read = () => state
22
+ bridge.update = (patch) => setState((value) => ({ ...value, ...patch }))
23
+ bridge.focus = () => input.current?.focus()
24
+ return h(
25
+ 'page',
26
+ { actionBarHidden: true },
27
+ h(
28
+ MThemeProvider,
29
+ { theme },
30
+ h(
31
+ MColumn,
32
+ { id: 'catalog', gap: 'md', padding: 'lg', height: '100%', backgroundColor: background },
33
+ h(MText, { id: 'heading', variant: 'title' }, '__MAVIS_NAME__'),
34
+ h(
35
+ MRow,
36
+ { id: 'row', gap: 'sm' },
37
+ h(
38
+ MButton,
39
+ {
40
+ id: 'action',
41
+ disabled: state.disabled,
42
+ loading: state.loading,
43
+ onClick: () => bridge.update?.({ count: state.count + 1 }),
44
+ },
45
+ `Count ${state.count}`,
46
+ ),
47
+ ),
48
+ h(MInput, {
49
+ id: 'editor',
50
+ label: 'Name',
51
+ modelValue: state.value,
52
+ disabled: state.disabled,
53
+ onValueChange: (value) => bridge.update?.({ value }),
54
+ ref: input,
55
+ }),
56
+ state.visible
57
+ ? h(MBox, {
58
+ id: 'motion',
59
+ width: 100,
60
+ height: 30,
61
+ backgroundColor: '#4f46e5',
62
+ motionSurface: surface,
63
+ })
64
+ : null,
65
+ h(
66
+ MBox,
67
+ { padding: 'md', radius: 'md', backgroundColor: isolatedTheme.theme.colors.background },
68
+ h(MText, { id: 'isolated', theme: isolatedTheme, text: 'Independent theme' }),
69
+ ),
70
+ ),
71
+ ),
72
+ )
73
+ }
74
+ export function start() {
75
+ Application.run({
76
+ create: () => {
77
+ const root = new NSVRoot()
78
+ render(h(Catalog), root, undefined, 'mavis-adapters')
79
+ bridge.dispose = () => unmountComponentAtNode('mavis-adapters')
80
+ return root.baseRef!.nativeView as View
81
+ },
82
+ })
83
+ }