@getcortexlabs/create-mavis 0.1.0-alpha.8 → 0.1.0-rc.11.1

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 (36) hide show
  1. package/README.md +31 -6
  2. package/package.json +7 -2
  3. package/src/add-target.mjs +378 -0
  4. package/src/cli.mjs +231 -107
  5. package/src/doctor.mjs +9 -0
  6. package/src/package-manager.mjs +105 -0
  7. package/src/portability.mjs +460 -0
  8. package/src/presets.mjs +25 -7
  9. package/src/reference.mjs +45 -0
  10. package/src/scaffold.mjs +124 -32
  11. package/src/shared-api.mjs +57 -0
  12. package/src/ui.mjs +276 -0
  13. package/templates/directory/mobile/src/App.vue +4 -0
  14. package/templates/directory/mobile/src/app.ts +32 -0
  15. package/templates/directory/nuxt/app/app.vue +1 -0
  16. package/templates/directory/nuxt/app/pages/entries/[id]/edit.vue +5 -0
  17. package/templates/directory/nuxt/app/pages/entries/[id]/index.vue +5 -0
  18. package/templates/directory/nuxt/app/pages/index.vue +4 -0
  19. package/templates/directory/nuxt/app/plugins/mavis.ts +34 -0
  20. package/templates/directory/shared/Details.vue +26 -0
  21. package/templates/directory/shared/Directory.vue +51 -0
  22. package/templates/directory/shared/Edit.vue +99 -0
  23. package/templates/directory/shared/directory-store.ts +82 -0
  24. package/templates/directory/shared/routes.ts +9 -0
  25. package/templates/directory/vite/src/App.vue +4 -0
  26. package/templates/directory/vite/src/main.ts +34 -0
  27. package/templates/mobile/src/App.vue +1 -3
  28. package/templates/mobile/src/mavis.ts +84 -0
  29. package/templates/mobile/tsconfig.json +9 -2
  30. package/templates/mobile/webpack.config.js +2 -0
  31. package/templates/nuxt/app/mavis.ts +84 -0
  32. package/templates/nuxt/nuxt.config.ts +5 -0
  33. package/templates/shared/Welcome.vue +114 -32
  34. package/templates/vite/src/mavis.ts +84 -0
  35. package/templates/vite/tsconfig.json +5 -1
  36. package/templates/vite/vite.config.ts +8 -1
@@ -0,0 +1,34 @@
1
+ import { createMavisServices } from '@getcortexlabs/mavis-web/services'
2
+ import { createRouterNavigation, mavis, midnight } from '@getcortexlabs/mavis-core'
3
+ import { useMavisTheme } from '@getcortexlabs/mavis-core/vue'
4
+ import { createDirectory, directoryKey } from '__MAVIS_SHARED__/directory-store'
5
+
6
+ export default defineNuxtPlugin(({ vueApp, $router }) => {
7
+ const saved = useCookie<string>('appearance')
8
+ const initial = useState<'light' | 'dark'>('mavis:appearance', () =>
9
+ saved.value === 'dark' ? 'dark' : saved.value === 'light' ? 'light' : '__MAVIS_APPEARANCE__',
10
+ )
11
+ vueApp.use(
12
+ createMavisServices({
13
+ theme: mavis,
14
+ darkTheme: midnight,
15
+ appearance: initial.value,
16
+ navigation: createRouterNavigation($router),
17
+ }),
18
+ )
19
+ const theme = vueApp.runWithContext(useMavisTheme)
20
+ // Each server request has its own store. Storage is accessed only after hydration.
21
+ const directory = createDirectory({
22
+ async read() {
23
+ return localStorage.getItem('mavis:directory')
24
+ },
25
+ async write(value) {
26
+ localStorage.setItem('mavis:directory', value)
27
+ },
28
+ })
29
+ vueApp.provide(directoryKey, directory)
30
+ onNuxtReady(() => {
31
+ theme.setAppearance(saved.value === 'dark' || saved.value === 'light' ? saved.value : 'system')
32
+ void directory.restore()
33
+ })
34
+ })
@@ -0,0 +1,26 @@
1
+ <script setup lang="ts">
2
+ import { computed } from 'vue'
3
+ import { MScreen, MColumn, MText, MButton, MLink, MEmptyState } from '#mavis'
4
+ import { useDirectory } from './directory-store'
5
+ const props = defineProps<{ id: string }>()
6
+ const directory = useDirectory()
7
+ const entry = computed(() => directory.entries.value.find((item) => item.id === props.id))
8
+ </script>
9
+ <template>
10
+ <MScreen scroll>
11
+ <MColumn padding="lg" gap="lg">
12
+ <MLink id="places-home" href="/" text="All places" />
13
+ <template v-if="entry">
14
+ <MText as="h1" variant="title">{{ entry.name }}</MText>
15
+ <MText tone="muted">{{ entry.city }}</MText>
16
+ <MText>Keep the directory useful by updating the place’s name.</MText>
17
+ <MButton id="edit-place" :href="`/entries/${entry.id}/edit`" text="Edit place" />
18
+ </template>
19
+ <MEmptyState
20
+ v-else
21
+ title="Place not found"
22
+ description="Return to the directory to choose another place."
23
+ />
24
+ </MColumn>
25
+ </MScreen>
26
+ </template>
@@ -0,0 +1,51 @@
1
+ <script setup lang="ts">
2
+ import { computed } from 'vue'
3
+ import { MScreen, MColumn, MText, MInput, MGrid, MCard, MAlert, MEmptyState } from '#mavis'
4
+ import { useDirectory } from './directory-store'
5
+ const { entries, query, storageError } = useDirectory()
6
+ const results = computed(() => {
7
+ const filter = query.value.trim().toLocaleLowerCase('en')
8
+ return entries.value.filter((entry) =>
9
+ `${entry.name} ${entry.city}`.toLocaleLowerCase('en').includes(filter),
10
+ )
11
+ })
12
+ </script>
13
+ <template>
14
+ <MScreen scroll>
15
+ <MColumn padding="lg" gap="lg">
16
+ <MText as="h1" variant="title">Community directory</MText>
17
+ <MText tone="muted">Find a place to learn, create or meet your neighbours.</MText>
18
+ <MInput
19
+ id="directory-search"
20
+ v-model="query"
21
+ label="Search places"
22
+ placeholder="Name or city"
23
+ />
24
+ <MAlert
25
+ v-if="storageError"
26
+ tone="warning"
27
+ title="Storage unavailable"
28
+ :description="storageError"
29
+ />
30
+ <MText variant="caption">{{ results.length }} places found</MText>
31
+ <MEmptyState
32
+ v-if="!results.length"
33
+ title="No places found"
34
+ description="Try another name or city."
35
+ />
36
+ <MGrid :minColumnWidth="240" gap="md">
37
+ <MCard
38
+ v-for="entry in results"
39
+ :key="entry.id"
40
+ :id="`entry-${entry.id}`"
41
+ :href="`/entries/${entry.id}`"
42
+ :accessibilityLabel="`Open ${entry.name}`"
43
+ gap="sm"
44
+ >
45
+ <MText variant="heading">{{ entry.name }}</MText>
46
+ <MText tone="muted">{{ entry.city }}</MText>
47
+ </MCard>
48
+ </MGrid>
49
+ </MColumn>
50
+ </MScreen>
51
+ </template>
@@ -0,0 +1,99 @@
1
+ <script setup lang="ts">
2
+ import { computed, ref, watch } from 'vue'
3
+ import {
4
+ MScreen,
5
+ MColumn,
6
+ MText,
7
+ MInput,
8
+ MButton,
9
+ MLink,
10
+ MAlert,
11
+ MReveal,
12
+ MEmptyState,
13
+ } from '#mavis'
14
+ import { useDirectory } from './directory-store'
15
+ const props = defineProps<{ id: string }>()
16
+ const directory = useDirectory()
17
+ const entry = computed(() => directory.entries.value.find((item) => item.id === props.id))
18
+ const name = ref(entry.value?.name ?? '')
19
+ const dirty = ref(false),
20
+ saving = ref(false),
21
+ saved = ref(false),
22
+ error = ref('')
23
+ watch(entry, (value) => {
24
+ if (!dirty.value) name.value = value?.name ?? ''
25
+ })
26
+ watch(
27
+ () => props.id,
28
+ () => {
29
+ name.value = entry.value?.name ?? ''
30
+ dirty.value = false
31
+ saved.value = false
32
+ error.value = ''
33
+ },
34
+ )
35
+ function edit() {
36
+ dirty.value = true
37
+ saved.value = false
38
+ }
39
+ async function save() {
40
+ if (saving.value || !name.value.trim()) return
41
+ const id = props.id,
42
+ draft = name.value
43
+ saving.value = true
44
+ saved.value = false
45
+ error.value = ''
46
+ try {
47
+ await directory.save(id, draft)
48
+ if (props.id === id) {
49
+ saved.value = name.value === draft
50
+ dirty.value = name.value !== draft
51
+ }
52
+ } catch {
53
+ if (props.id === id) error.value = 'Could not save. Your draft is still here; try again.'
54
+ } finally {
55
+ saving.value = false
56
+ }
57
+ }
58
+ </script>
59
+ <template>
60
+ <MScreen scroll>
61
+ <MColumn padding="lg" gap="lg">
62
+ <MLink :href="`/entries/${id}`" text="Place details" />
63
+ <template v-if="entry">
64
+ <MText as="h1" variant="title">Edit place</MText>
65
+ <MInput
66
+ id="place-name"
67
+ v-model="name"
68
+ label="Place name"
69
+ :readonly="saving"
70
+ @update:modelValue="edit"
71
+ @submit="save"
72
+ />
73
+ <MAlert
74
+ id="save-error"
75
+ v-if="error"
76
+ tone="error"
77
+ title="Save failed"
78
+ :description="error"
79
+ />
80
+ <MButton
81
+ id="save-place"
82
+ text="Save changes"
83
+ :loading="saving"
84
+ loadingText="Saving…"
85
+ :disabled="!name.trim()"
86
+ @click="save"
87
+ />
88
+ <MReveal :show="saved">
89
+ <MText tone="success">Changes saved.</MText>
90
+ </MReveal>
91
+ </template>
92
+ <MEmptyState
93
+ v-else
94
+ title="Place not found"
95
+ description="Choose a place from the directory."
96
+ />
97
+ </MColumn>
98
+ </MScreen>
99
+ </template>
@@ -0,0 +1,82 @@
1
+ import { inject, ref, readonly, type InjectionKey } from 'vue'
2
+
3
+ export interface DirectoryEntry {
4
+ id: string
5
+ name: string
6
+ city: string
7
+ }
8
+ export interface DirectoryStorage {
9
+ read(): Promise<string | null>
10
+ write(value: string): Promise<void>
11
+ }
12
+ const seed: DirectoryEntry[] = [
13
+ { id: 'garden', name: 'Community garden', city: 'Porto' },
14
+ { id: 'library', name: 'Open library', city: 'Recife' },
15
+ { id: 'studio', name: 'Neighbourhood studio', city: 'Porto' },
16
+ ]
17
+
18
+ /** Create once per app/request. Storage is a host service, never a module singleton. */
19
+ export function createDirectory(storage: DirectoryStorage) {
20
+ const entries = ref(seed.map((entry) => ({ ...entry })))
21
+ const query = ref('')
22
+ const storageError = ref('')
23
+ let restoring: Promise<void> | undefined
24
+ let writing = Promise.resolve()
25
+ const restore = () =>
26
+ (restoring ??= (async () => {
27
+ try {
28
+ const value = await storage.read()
29
+ if (value === null) return
30
+ const parsed: unknown = JSON.parse(value)
31
+ if (
32
+ !Array.isArray(parsed) ||
33
+ parsed.length !== seed.length ||
34
+ !seed.every(
35
+ (original) =>
36
+ parsed.filter(
37
+ (entry) =>
38
+ entry?.id === original.id &&
39
+ typeof entry.name === 'string' &&
40
+ entry.name.trim() &&
41
+ typeof entry.city === 'string',
42
+ ).length === 1,
43
+ )
44
+ )
45
+ throw new Error('Invalid saved directory')
46
+ entries.value = parsed.map(({ id, name, city }) => ({ id, name, city }))
47
+ } catch {
48
+ storageError.value =
49
+ 'Saved entries could not be loaded. The sample entries are still available.'
50
+ }
51
+ })())
52
+ return {
53
+ entries: readonly(entries),
54
+ query,
55
+ storageError: readonly(storageError),
56
+ restore,
57
+ async save(id: string, name: string) {
58
+ if (!name.trim() || !entries.value.some((entry) => entry.id === id))
59
+ throw new Error('Invalid entry')
60
+ const pending = writing
61
+ .catch(() => {})
62
+ .then(async () => {
63
+ await restore()
64
+ const next = entries.value.map((entry) =>
65
+ entry.id === id ? { ...entry, name: name.trim() } : { ...entry },
66
+ )
67
+ // Commit state only after the host confirms persistence. A rejected write preserves the draft.
68
+ await storage.write(JSON.stringify(next))
69
+ entries.value = next
70
+ })
71
+ writing = pending
72
+ await pending
73
+ },
74
+ }
75
+ }
76
+ export type Directory = ReturnType<typeof createDirectory>
77
+ export const directoryKey: InjectionKey<Directory> = Symbol('directory')
78
+ export function useDirectory() {
79
+ const directory = inject(directoryKey)
80
+ if (!directory) throw new Error('Install the directory service at the application entry.')
81
+ return directory
82
+ }
@@ -0,0 +1,9 @@
1
+ import Directory from './Directory.vue'
2
+ import Details from './Details.vue'
3
+ import Edit from './Edit.vue'
4
+
5
+ export const routes = [
6
+ { path: '/', component: Directory },
7
+ { path: '/entries/:id', component: Details, props: true },
8
+ { path: '/entries/:id/edit', component: Edit, props: true },
9
+ ]
@@ -0,0 +1,4 @@
1
+ <script setup lang="ts">
2
+ import { RouterView } from 'vue-router'
3
+ </script>
4
+ <template><RouterView /></template>
@@ -0,0 +1,34 @@
1
+ import { createApp } from 'vue'
2
+ import { createRouter, createWebHistory } from 'vue-router'
3
+ import { createMavisServices } from '@getcortexlabs/mavis-web/services'
4
+ import { createRouterNavigation, mavis, midnight } from '@getcortexlabs/mavis-core'
5
+ import { createDirectory, directoryKey } from '__MAVIS_SHARED__/directory-store'
6
+ import { routes } from '__MAVIS_SHARED__/routes'
7
+ import App from './App.vue'
8
+ import '@getcortexlabs/mavis-web/style.css'
9
+ import './style.css'
10
+
11
+ const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), routes })
12
+ const directory = createDirectory({
13
+ async read() {
14
+ return localStorage.getItem('mavis:directory')
15
+ },
16
+ async write(value) {
17
+ localStorage.setItem('mavis:directory', value)
18
+ },
19
+ })
20
+ const app = createApp(App)
21
+ .use(router)
22
+ .use(
23
+ createMavisServices({
24
+ theme: mavis,
25
+ darkTheme: midnight,
26
+ appearance: '__MAVIS_APPEARANCE__',
27
+ navigation: createRouterNavigation(router),
28
+ }),
29
+ )
30
+ .provide(directoryKey, directory)
31
+ void router.isReady().then(() => {
32
+ app.mount('#app')
33
+ void directory.restore()
34
+ })
@@ -2,7 +2,5 @@
2
2
  import Welcome from '__MAVIS_SHARED__/Welcome.vue'
3
3
  </script>
4
4
  <template>
5
- <Frame
6
- ><Page actionBarHidden="true"><Welcome /></Page
7
- ></Frame>
5
+ <Frame><Welcome /></Frame>
8
6
  </template>
@@ -0,0 +1,84 @@
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'
83
+ export * from '@getcortexlabs/mavis-core'
84
+ export { formatDateTime, dateTimeToCivilDate } from '@getcortexlabs/mavis/date-format'
@@ -7,8 +7,15 @@
7
7
  "lib": ["ES2023", "DOM"],
8
8
  "skipLibCheck": true,
9
9
  "esModuleInterop": true,
10
- "paths": { "vue": ["./node_modules/nativescript-vue"] }
10
+ "paths": {
11
+ "vue": ["./node_modules/nativescript-vue"],
12
+ "#mavis": ["./src/mavis.ts"],
13
+ "#shared-ui/*": ["__MAVIS_SHARED_ROOT__/*"]
14
+ }
15
+ },
16
+ "vueCompilerOptions": {
17
+ "target": 3,
18
+ "lib": "nativescript-vue"
11
19
  },
12
- "vueCompilerOptions": { "target": 3, "lib": "nativescript-vue" },
13
20
  "include": ["src", "../../shared"]
14
21
  }
@@ -8,6 +8,8 @@ module.exports = (env) => {
8
8
  context: resolve(__dirname, 'node_modules/@getcortexlabs/mavis/fonts'),
9
9
  })
10
10
  webpack.chainWebpack((config) => {
11
+ config.resolve.alias.set('#shared-ui', resolve(__dirname, '__MAVIS_SHARED_ROOT__'))
12
+ config.resolve.alias.set('#mavis$', resolve(__dirname, 'src/mavis.ts'))
11
13
  config.resolve.alias.set('vue$', resolve(__dirname, 'node_modules/nativescript-vue'))
12
14
  for (const name of [
13
15
  'nativescript-vue',
@@ -0,0 +1,84 @@
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-web'
83
+ export * from '@getcortexlabs/mavis-core'
84
+ export { formatDateTime, dateTimeToCivilDate } from '@getcortexlabs/mavis-web/date-format'
@@ -1,5 +1,10 @@
1
+ import { fileURLToPath } from 'node:url'
1
2
  export default defineNuxtConfig({
2
3
  compatibilityDate: '2026-11-02',
4
+ alias: {
5
+ '#shared-ui': fileURLToPath(new URL('__MAVIS_SHARED_ROOT__', import.meta.url)),
6
+ '#mavis': fileURLToPath(new URL('./app/mavis.ts', import.meta.url)),
7
+ },
3
8
  devtools: { enabled: false },
4
9
  css: ['@getcortexlabs/mavis-web/style.css', '~/assets/main.css'],
5
10
  app: { head: { title: '__MAVIS_NAME__', htmlAttrs: { lang: 'en' } } },