@xeplr/cli 0.3.15 → 0.5.0
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.
- package/README.md +1 -0
- package/lib/generate/index.js +27 -2
- package/package.json +1 -1
- package/templates/BUILDING.md +9 -0
- package/templates/README.md +2 -0
- package/templates/mobile/README.md +71 -0
- package/templates/mobile/app.json +19 -0
- package/templates/mobile/eas.json +13 -0
- package/templates/mobile/gitignore.tpl +5 -0
- package/templates/mobile/metro.config.js +14 -0
- package/templates/mobile/package.json +37 -0
- package/templates/mobile/src/app/_layout.jsx +53 -0
- package/templates/mobile/src/app/flows/index.jsx +13 -0
- package/templates/mobile/src/app/forms/[form]/[id].jsx +14 -0
- package/templates/mobile/src/app/forms/[form]/index.jsx +23 -0
- package/templates/mobile/src/app/index.jsx +32 -0
- package/templates/mobile/src/app/journey/[flow].jsx +27 -0
- package/templates/mobile/src/app/login.jsx +13 -0
- package/templates/mobile/src/lib/app.js +41 -0
- package/templates/ui/package.json +1 -1
- package/templates/ui/pages.json +2 -3
- package/templates-tenancy/mobile/src/app/select.jsx +16 -0
- package/templates-tenancy/ui/src/pages/SelectScope.jsx +38 -113
package/README.md
CHANGED
|
@@ -50,6 +50,7 @@ Already working, with nothing to wire up:
|
|
|
50
50
|
It follows the app's tenancy (none, or the levels you chose) and never creates
|
|
51
51
|
companies or workspaces of its own. Approvals (another person's turn) are not
|
|
52
52
|
part of it.
|
|
53
|
+
- **A phone app** — `mobile/` (Expo): the same app drawn natively on Android and iOS — every form added to the menu, its list, add / edit, its buttons and the journeys — with no screen code of its own: it draws what the server holds (`@xeplr/ui-factory/native`, `@xeplr/ui-account/native`). Try it with Expo Go, build an APK with `npm run build:apk`. An app whose data is split by company asks for the company first, on the phone as on the web.
|
|
53
54
|
- **Functions** — `api/functions/`: the app's own code, registered with
|
|
54
55
|
`@xeplr/actions` by the event it is for (`beforeSave`, `afterSave`, …,
|
|
55
56
|
`decide`) and picked by name in a screen's events or a flow step. Two to start
|
package/lib/generate/index.js
CHANGED
|
@@ -24,6 +24,11 @@ var RENAME = {
|
|
|
24
24
|
function substitutions(answers) {
|
|
25
25
|
return Object.assign({
|
|
26
26
|
__NAME__: answers.name,
|
|
27
|
+
// The phone app (mobile/): "rental-desk" shows as "Rental Desk", and is
|
|
28
|
+
// com.example.rentaldesk until the owner gives it an id of their own.
|
|
29
|
+
__TITLE__: titleOf(answers.name),
|
|
30
|
+
__APP_ID__: 'com.example.' + answers.name.replace(/[^a-z0-9]/g, ''),
|
|
31
|
+
__APP_SCHEME__: answers.name.replace(/[^a-z0-9]/g, ''),
|
|
27
32
|
__DB_API__: answers.databases.api,
|
|
28
33
|
__DB_AUTH__: answers.databases.auth,
|
|
29
34
|
__DB_WORKFLOW__: answers.databases.workflow,
|
|
@@ -115,8 +120,22 @@ function tenancySubstitutions(levels) {
|
|
|
115
120
|
|
|
116
121
|
// ui/src/App.jsx
|
|
117
122
|
__MT_APP_UI_IMPORTS__: on ? "import SelectScope, { ScopeGate } from './pages/SelectScope.jsx'" : '',
|
|
118
|
-
// ui/pages.json: the company picker is
|
|
119
|
-
__MT_PAGES_SELECT__: on ? ' { "path": "/select", "menu": "Switch ' + first.label.toLowerCase() + '", "
|
|
123
|
+
// ui/pages.json: the company picker is on the phone too (NativeScopePicker), as a page of its own.
|
|
124
|
+
__MT_PAGES_SELECT__: on ? ',\n { "path": "/select", "menu": "Switch ' + first.label.toLowerCase() + '", "screen": "the ' + levels.map(function (l) { return l.label.toLowerCase(); }).join(' and ') + ' picker — NativeScopePicker on a phone" }' : '',
|
|
125
|
+
// mobile/: the same levels on the phone, the picker first, Switch on the menu.
|
|
126
|
+
__MT_MOBILE_TENANCY__: on ? [
|
|
127
|
+
'',
|
|
128
|
+
'/**',
|
|
129
|
+
' * Who the data belongs to — the same levels as the API and the website. The',
|
|
130
|
+
' * first page after signing in is choosing them (app/select.jsx), and every',
|
|
131
|
+
' * request carries the choice.',
|
|
132
|
+
' */',
|
|
133
|
+
'export const TENANCY = ' + JSON.stringify({ levels: levels, slots: slots }, null, 2)
|
|
134
|
+
].join('\n') : '',
|
|
135
|
+
__MT_MOBILE_IMPORTS__: on ? "import { registerMTs, scopeChosen } from '@xeplr/ui-account/native'\nimport { TENANCY } from '../lib/app.js'" : '',
|
|
136
|
+
__MT_MOBILE_GATE__: on ? " // The company first (once — the choice is remembered).\n if (signedIn && !scopeChosen(TENANCY.levels) && segments[0] !== 'select') return <Redirect href=\"/select\" />" : '',
|
|
137
|
+
__MT_MOBILE_REGISTER__: on ? ' registerMTs(TENANCY.slots)' : '',
|
|
138
|
+
__MT_MOBILE_SWITCH__: on ? " <View style={{ marginBottom: 10 }}><Btn label=\"" + 'Switch ' + first.label.toLowerCase() + "\" onPress={() => router.push('/select')} /></View>" : '',
|
|
120
139
|
__MT_MENU_KEY__: on ? " 'Switch " + first.label.toLowerCase() + "'," : '',
|
|
121
140
|
__MT_DRAWER_ITEM__: on ? " { key: 'Switch " + first.label.toLowerCase() + "', icon: SwitchIcon, clickHandler: () => navigate('/select') }," : '',
|
|
122
141
|
__MT_SWITCH_ICON__: on ? [
|
|
@@ -141,6 +160,11 @@ function tenancySubstitutions(levels) {
|
|
|
141
160
|
};
|
|
142
161
|
}
|
|
143
162
|
|
|
163
|
+
/** "rental-desk" → "Rental Desk". */
|
|
164
|
+
function titleOf(name) {
|
|
165
|
+
return String(name).split(/[-_]+/).filter(Boolean).map(function (w) { return w.charAt(0).toUpperCase() + w.slice(1); }).join(' ');
|
|
166
|
+
}
|
|
167
|
+
|
|
144
168
|
/** The README's Flows section. */
|
|
145
169
|
function flowsReadme(answers) {
|
|
146
170
|
var tenancy = answers.tenancy || [];
|
|
@@ -319,6 +343,7 @@ function generate(answers, target) {
|
|
|
319
343
|
|
|
320
344
|
Object.keys(sources).forEach(function (rel) {
|
|
321
345
|
var src = sources[rel];
|
|
346
|
+
|
|
322
347
|
var dir = path.dirname(rel);
|
|
323
348
|
var base = path.basename(rel);
|
|
324
349
|
var outName = RENAME[base] || base;
|
package/package.json
CHANGED
package/templates/BUILDING.md
CHANGED
|
@@ -262,6 +262,15 @@ If a screen *nearly* says what you need, ask for the control to be added to
|
|
|
262
262
|
|
|
263
263
|
---
|
|
264
264
|
|
|
265
|
+
## On a phone
|
|
266
|
+
|
|
267
|
+
`mobile/` is this app on a phone (Expo), drawn **natively**, with no screen
|
|
268
|
+
code of its own: the menu is whatever Configure UI → Menu shows this person,
|
|
269
|
+
each form's list and add / edit, its buttons and journeys. So everything in
|
|
270
|
+
steps 1–6 is on the phone as soon as it is published — no change there, no new
|
|
271
|
+
build. Designing stays on a computer. `mobile/README.md` says how to try it
|
|
272
|
+
(Expo Go) and build an APK.
|
|
273
|
+
|
|
265
274
|
## With Claude
|
|
266
275
|
|
|
267
276
|
Every step above can also be asked for. Open Claude in this folder:
|
package/templates/README.md
CHANGED
|
@@ -6,6 +6,7 @@ An xeplr application, created by [`@xeplr/cli`](https://www.npmjs.com/package/@x
|
|
|
6
6
|
__NAME__/
|
|
7
7
|
├─ api/ the API and the sign-in service → api/README.md
|
|
8
8
|
├─ ui/ the React app → ui/README.md
|
|
9
|
+
├─ mobile/ the same app on a phone, drawn natively → mobile/README.md
|
|
9
10
|
├─ BUILDING.md every step of building the app: what is a click, what needs a function
|
|
10
11
|
└─ CLAUDE.md how to change this app — for Claude, and a good read for people
|
|
11
12
|
```
|
|
@@ -64,6 +65,7 @@ Every one of these checks the same sign-in token, so one login covers them all.
|
|
|
64
65
|
- **Tasks** — a sample built from screens: a list, and a form it opens on a page of its own, saved into an ordinary `tasks` table. The form is filled in over three steps and uses every control there is — text, a dropdown, radio buttons, a tick box, a date, a date and time, several tags at once, and a file.
|
|
65
66
|
- **Configure UI** — in the settings menu, for Super Admin: every form (make one, design it, publish it, add it to the side rail), every flow (screens one after another — each screen's events, and where it goes next) and the side rail itself (rename, reorder, hide).
|
|
66
67
|
- **Flows** — in the side rail: the journeys people can start, run by `@xeplr/workflow-api` inside the API.
|
|
68
|
+
- **A phone app** — `mobile/` (Expo): every form added to the menu, its list, add / edit, its buttons and the journeys, drawn natively from what the server holds — no screen code, nothing to change when a form is added (see `mobile/README.md`).
|
|
67
69
|
- **Functions** — `api/functions/`: your code, registered by event and picked by name in a screen's events or a flow step (see "Functions" below).
|
|
68
70
|
|
|
69
71
|
## Create a new UI
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# __TITLE__ — on a phone
|
|
2
|
+
|
|
3
|
+
The same app as the website, drawn **natively** on Android and iOS: every form
|
|
4
|
+
added to the menu in Configure UI, its list, add and edit, its buttons, and the
|
|
5
|
+
journeys designed in Configure UI → Flows. Nothing here is a screen — the
|
|
6
|
+
screens are read from the server and drawn by `@xeplr/ui-factory/native`, and
|
|
7
|
+
signing in is `@xeplr/ui-account/native`'s, the same as the website's.
|
|
8
|
+
|
|
9
|
+
So **design in the browser, use it on the phone**: add a form to the menu in
|
|
10
|
+
Configure UI and it is on the phone too, with no change here and no new build.
|
|
11
|
+
Designing (Configure UI) and the admin screens stay on a computer.
|
|
12
|
+
|
|
13
|
+
## Try it on your phone (Expo Go)
|
|
14
|
+
|
|
15
|
+
1. Install **Expo Go** on the phone (Play Store / App Store).
|
|
16
|
+
2. Start the app's services as usual, and let the website be reached from the
|
|
17
|
+
phone — same Wi-Fi as this computer:
|
|
18
|
+
```bash
|
|
19
|
+
cd ../api && npm run start-auth
|
|
20
|
+
cd ../api && npm run start-api
|
|
21
|
+
cd ../ui && npm run dev -- --host # --host: the phone can reach it
|
|
22
|
+
```
|
|
23
|
+
3. Start the phone app and scan the QR code it prints with the phone's camera
|
|
24
|
+
(Android: from Expo Go):
|
|
25
|
+
```bash
|
|
26
|
+
npm install # once
|
|
27
|
+
npm start
|
|
28
|
+
```
|
|
29
|
+
4. Sign in. The server address starts as this computer's own
|
|
30
|
+
(`http://<this computer>:__UI_PORT__`).
|
|
31
|
+
|
|
32
|
+
`npm run web` opens the same app in a browser — handy for a quick look.
|
|
33
|
+
|
|
34
|
+
## An installable app (APK)
|
|
35
|
+
|
|
36
|
+
1. In `eas.json`, set `EXPO_PUBLIC_SERVER_URL` to the app's real address
|
|
37
|
+
(`https://rentals.example.com`) — a build made for one server asks for no
|
|
38
|
+
address at all.
|
|
39
|
+
2. In `app.json`, give it an id of your own instead of `__APP_ID__`
|
|
40
|
+
(`android.package`, `ios.bundleIdentifier`).
|
|
41
|
+
3. `npm run build:apk` — built by Expo's servers (an Expo account, free); it
|
|
42
|
+
prints a link to the APK.
|
|
43
|
+
|
|
44
|
+
## What is on the phone
|
|
45
|
+
|
|
46
|
+
| | |
|
|
47
|
+
|---|---|
|
|
48
|
+
| **The menu** | every form added to the menu in Configure UI, in its order and under its names, and **Journeys** — only what this person's roles allow (from the server, read again when the app opens) |
|
|
49
|
+
| **A form's list** | its records as cards, with search, filter chips, KPI cards and a date range when the list has them; a tap opens one, **+ New** adds one |
|
|
50
|
+
| **A record** | its form, one field under another; Save and Cancel; its buttons (with their ask-first questions) |
|
|
51
|
+
| **Pictures and files** | the camera or the gallery; documents from the phone's files |
|
|
52
|
+
| **Dates** | the phone's own date picker |
|
|
53
|
+
| **Journeys** | Start, then each screen with **Next**, as on the website |
|
|
54
|
+
|
|
55
|
+
Every control a form can hold is on the phone — a `table` as a card per row
|
|
56
|
+
with a tick, a `subform` drawn inside its form. When the app's data is split by
|
|
57
|
+
company, the first page after signing in is choosing it (and the workspace),
|
|
58
|
+
as on the website; **Switch company** is on the menu. Designing (Configure UI)
|
|
59
|
+
and the admin screens are for a computer.
|
|
60
|
+
|
|
61
|
+
## Layout
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
mobile/
|
|
65
|
+
├─ app.json, eas.json the app's name and id; the server a build is for
|
|
66
|
+
├─ metro.config.js react-router-dom → ui-factory's stand-in (a phone has no URL)
|
|
67
|
+
└─ src/
|
|
68
|
+
├─ lib/app.js the app's name, the server, the calls every page makes
|
|
69
|
+
└─ app/ the pages (expo-router): sign-in, the menu,
|
|
70
|
+
forms/<form>, forms/<form>/<id>, flows, journey/<flow>
|
|
71
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"expo": {
|
|
3
|
+
"name": "__TITLE__",
|
|
4
|
+
"slug": "__NAME__",
|
|
5
|
+
"scheme": "__APP_SCHEME__",
|
|
6
|
+
"version": "1.0.0",
|
|
7
|
+
"orientation": "portrait",
|
|
8
|
+
"userInterfaceStyle": "automatic",
|
|
9
|
+
"ios": { "supportsTablet": true, "bundleIdentifier": "__APP_ID__" },
|
|
10
|
+
"android": { "package": "__APP_ID__" },
|
|
11
|
+
"plugins": [
|
|
12
|
+
"expo-router",
|
|
13
|
+
"expo-status-bar",
|
|
14
|
+
"@react-native-community/datetimepicker",
|
|
15
|
+
["expo-camera", { "cameraPermission": "__TITLE__ uses the camera to take photos and read barcodes", "recordAudioAndroid": false, "barcodeScannerEnabled": true }],
|
|
16
|
+
["expo-build-properties", { "android": { "usesCleartextTraffic": true } }]
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cli": { "version": ">= 16.0.0", "appVersionSource": "remote" },
|
|
3
|
+
"build": {
|
|
4
|
+
"preview": {
|
|
5
|
+
"distribution": "internal",
|
|
6
|
+
"android": { "buildType": "apk" },
|
|
7
|
+
"env": { "EXPO_PUBLIC_SERVER_URL": "" }
|
|
8
|
+
},
|
|
9
|
+
"production": {
|
|
10
|
+
"env": { "EXPO_PUBLIC_SERVER_URL": "" }
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Metro, as Expo sets it up, plus one thing: 'react-router-dom' answered by
|
|
2
|
+
// @xeplr/ui-factory/native's stand-in. A phone has no URL — the screens keep
|
|
3
|
+
// their state in memory without a router — and react-router's own code does
|
|
4
|
+
// not compile for Hermes.
|
|
5
|
+
const { getDefaultConfig } = require('expo/metro-config')
|
|
6
|
+
|
|
7
|
+
const config = getDefaultConfig(__dirname)
|
|
8
|
+
const noRouter = require.resolve('@xeplr/ui-factory/native/noRouter')
|
|
9
|
+
const resolveRequest = config.resolver.resolveRequest
|
|
10
|
+
config.resolver.resolveRequest = (context, name, platform) => {
|
|
11
|
+
if (name === 'react-router-dom') return { type: 'sourceFile', filePath: noRouter }
|
|
12
|
+
return resolveRequest ? resolveRequest(context, name, platform) : context.resolveRequest(context, name, platform)
|
|
13
|
+
}
|
|
14
|
+
module.exports = config
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__NAME__-mobile",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"main": "expo-router/entry",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "expo start",
|
|
8
|
+
"android": "expo start --android",
|
|
9
|
+
"ios": "expo start --ios",
|
|
10
|
+
"web": "expo start --web",
|
|
11
|
+
"build:apk": "EAS_NO_VCS=1 npx eas-cli@latest build -p android --profile preview"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@react-native-async-storage/async-storage": "2.2.0",
|
|
15
|
+
"@react-native-community/datetimepicker": "9.2.1",
|
|
16
|
+
"@xeplr/ui-account": "^1.8.0",
|
|
17
|
+
"@xeplr/ui-factory": "^1.21.0",
|
|
18
|
+
"expo": "~58.0.26",
|
|
19
|
+
"expo-build-properties": "~58.0.12",
|
|
20
|
+
"expo-camera": "~58.0.14",
|
|
21
|
+
"expo-constants": "~58.0.16",
|
|
22
|
+
"expo-document-picker": "~58.0.5",
|
|
23
|
+
"expo-image-picker": "~58.0.10",
|
|
24
|
+
"expo-linking": "~58.0.17",
|
|
25
|
+
"expo-router": "~58.0.32",
|
|
26
|
+
"expo-status-bar": "~58.0.5",
|
|
27
|
+
"react": "19.3.0",
|
|
28
|
+
"react-dom": "19.3.0",
|
|
29
|
+
"react-native": "0.88.1",
|
|
30
|
+
"react-native-safe-area-context": "~5.11.1",
|
|
31
|
+
"react-native-screens": "~4.30.1",
|
|
32
|
+
"react-native-web": "^0.21.4"
|
|
33
|
+
},
|
|
34
|
+
"overrides": {
|
|
35
|
+
"minimatch": "^11.0.9"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// THE APP'S FRAME — read what the phone remembered, then a stack of pages with
|
|
2
|
+
// a header and Back. Nobody signed in: the sign-in page. Light or dark follows
|
|
3
|
+
// the phone's own setting.
|
|
4
|
+
import { useEffect, useState } from 'react'
|
|
5
|
+
import { Platform, Text, View, useColorScheme } from 'react-native'
|
|
6
|
+
import { Redirect, Stack, useSegments } from 'expo-router'
|
|
7
|
+
import { StatusBar } from 'expo-status-bar'
|
|
8
|
+
import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
9
|
+
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
10
|
+
import * as ImagePicker from 'expo-image-picker'
|
|
11
|
+
import * as DocumentPicker from 'expo-document-picker'
|
|
12
|
+
import DateTimePicker, { DateTimePickerAndroid } from '@react-native-community/datetimepicker'
|
|
13
|
+
import { CameraView, Camera } from 'expo-camera'
|
|
14
|
+
import { hydrateStorage, startSession, useSession } from '@xeplr/ui-account/native'
|
|
15
|
+
import { NativeHostProvider, NativeInsets, NativeTheme, DARK, LIGHT, useNativeTheme } from '@xeplr/ui-factory/native'
|
|
16
|
+
import { APP_NAME, BUILT_IN_SERVER, devServer } from '../lib/app.js'
|
|
17
|
+
__MT_MOBILE_IMPORTS__
|
|
18
|
+
|
|
19
|
+
const PICKERS = { ImagePicker, DocumentPicker, DateTimePicker, DateTimePickerAndroid, CameraView, Camera }
|
|
20
|
+
|
|
21
|
+
function Frame() {
|
|
22
|
+
const t = useNativeTheme()
|
|
23
|
+
const insets = useSafeAreaInsets()
|
|
24
|
+
const { signedIn, server } = useSession()
|
|
25
|
+
const segments = useSegments()
|
|
26
|
+
if (!signedIn && segments[0] !== 'login') return <Redirect href="/login" />
|
|
27
|
+
__MT_MOBILE_GATE__
|
|
28
|
+
return (
|
|
29
|
+
<NativeInsets value={insets}>
|
|
30
|
+
<NativeHostProvider modules={PICKERS} baseUrl={server} appName={APP_NAME}>
|
|
31
|
+
<StatusBar style={t.dark ? 'light' : 'dark'} />
|
|
32
|
+
<Stack screenOptions={{ headerStyle: { backgroundColor: t.surface }, headerTintColor: t.ink, headerTitleStyle: { color: t.ink }, contentStyle: { backgroundColor: t.plane } }} />
|
|
33
|
+
</NativeHostProvider>
|
|
34
|
+
</NativeInsets>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default function RootLayout() {
|
|
39
|
+
const scheme = useColorScheme()
|
|
40
|
+
const [ready, setReady] = useState(false)
|
|
41
|
+
const [failed, setFailed] = useState(null)
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
hydrateStorage({ AsyncStorage, prefix: '__NAME__', web: Platform.OS === 'web' })
|
|
44
|
+
.then(() => {
|
|
45
|
+
__MT_MOBILE_REGISTER__
|
|
46
|
+
startSession({ builtInServer: BUILT_IN_SERVER, suggested: devServer() })
|
|
47
|
+
setReady(true)
|
|
48
|
+
}, (e) => setFailed(e.message || 'Could not start'))
|
|
49
|
+
}, [])
|
|
50
|
+
if (failed) return <View style={{ flex: 1, padding: 24, justifyContent: 'center' }}><Text>{failed}</Text></View>
|
|
51
|
+
if (!ready) return null
|
|
52
|
+
return <SafeAreaProvider><NativeTheme value={scheme === 'light' ? LIGHT : DARK}><Frame /></NativeTheme></SafeAreaProvider>
|
|
53
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// /flows — the journeys designed in Configure UI → Flows, each with Start.
|
|
2
|
+
import { Stack, router } from 'expo-router'
|
|
3
|
+
import { NativeFlows } from '@xeplr/ui-factory/native'
|
|
4
|
+
import { flows } from '../../lib/app.js'
|
|
5
|
+
|
|
6
|
+
export default function Flows() {
|
|
7
|
+
return (
|
|
8
|
+
<>
|
|
9
|
+
<Stack.Screen options={{ title: 'Journeys' }} />
|
|
10
|
+
<NativeFlows flows={flows} onStart={(f) => router.push(`/journey/${encodeURIComponent(f.key)}`)} />
|
|
11
|
+
</>
|
|
12
|
+
)
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// /forms/:form/:id — one record in its form; "new" is a new one. Save or Cancel goes back.
|
|
2
|
+
import { Stack, router, useLocalSearchParams } from 'expo-router'
|
|
3
|
+
import { NativeRecord } from '@xeplr/ui-factory/native'
|
|
4
|
+
import { factory } from '../../../lib/app.js'
|
|
5
|
+
|
|
6
|
+
export default function FormRecord() {
|
|
7
|
+
const { form, id } = useLocalSearchParams()
|
|
8
|
+
return (
|
|
9
|
+
<>
|
|
10
|
+
<Stack.Screen options={{ title: id === 'new' ? 'New' : '' }} />
|
|
11
|
+
<NativeRecord factory={factory} form={String(form)} id={String(id)} onDone={() => router.back()} />
|
|
12
|
+
</>
|
|
13
|
+
)
|
|
14
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// /forms/:form — a form's records, as on the web. A row opens it; + New a new one.
|
|
2
|
+
import { useCallback, useState } from 'react'
|
|
3
|
+
import { Stack, router, useFocusEffect, useLocalSearchParams } from 'expo-router'
|
|
4
|
+
import { useSession } from '@xeplr/ui-account/native'
|
|
5
|
+
import { NativeFormRecords, phoneMenu } from '@xeplr/ui-factory/native'
|
|
6
|
+
import { factory, PAGES } from '../../../lib/app.js'
|
|
7
|
+
|
|
8
|
+
export default function FormRecords() {
|
|
9
|
+
const { form } = useLocalSearchParams()
|
|
10
|
+
const { access } = useSession()
|
|
11
|
+
const key = String(form)
|
|
12
|
+
const item = phoneMenu(access, { pages: PAGES }).find((m) => m.form === key)
|
|
13
|
+
// Coming back from a record reads the list again: what was done there shows here.
|
|
14
|
+
const [tick, setTick] = useState(0)
|
|
15
|
+
useFocusEffect(useCallback(() => { setTick((n) => n + 1) }, []))
|
|
16
|
+
return (
|
|
17
|
+
<>
|
|
18
|
+
<Stack.Screen options={{ title: item ? item.label : key.replace(/_/g, ' ') }} />
|
|
19
|
+
<NativeFormRecords factory={factory} form={key} reloadKey={tick}
|
|
20
|
+
onOpen={({ id }) => router.push(`/forms/${encodeURIComponent(key)}/${id === null || id === undefined ? 'new' : encodeURIComponent(id)}`)} />
|
|
21
|
+
</>
|
|
22
|
+
)
|
|
23
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// THE MENU — what the server says this person may see: every form added to the
|
|
2
|
+
// menu in Configure UI (in its order, under its names), and the journeys.
|
|
3
|
+
import { Text, View } from 'react-native'
|
|
4
|
+
import { Stack, router } from 'expo-router'
|
|
5
|
+
import { useSession, signOut } from '@xeplr/ui-account/native'
|
|
6
|
+
import { Btn, NativeMenu, phoneMenu, useNativeTheme } from '@xeplr/ui-factory/native'
|
|
7
|
+
import { APP_NAME, PAGES } from '../lib/app.js'
|
|
8
|
+
|
|
9
|
+
export default function Menu() {
|
|
10
|
+
const t = useNativeTheme()
|
|
11
|
+
const { user, access, server } = useSession()
|
|
12
|
+
const open = (m) => router.push(m.kind === 'flows' ? '/flows' : `/forms/${encodeURIComponent(m.form)}`)
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
<Stack.Screen options={{ title: APP_NAME }} />
|
|
16
|
+
<NativeMenu items={phoneMenu(access, { pages: PAGES })} onOpen={open}
|
|
17
|
+
header={(
|
|
18
|
+
<View style={{ marginBottom: 16 }}>
|
|
19
|
+
<Text style={{ color: t.ink, fontSize: 22, fontWeight: '800' }}>{APP_NAME}</Text>
|
|
20
|
+
{user ? <Text style={{ color: t.muted }}>Signed in as {user.name || user.email}</Text> : null}
|
|
21
|
+
</View>
|
|
22
|
+
)}
|
|
23
|
+
footer={(
|
|
24
|
+
<View style={{ marginTop: 24 }}>
|
|
25
|
+
<Text style={{ color: t.muted, marginBottom: 8, fontSize: 12 }}>{server}</Text>
|
|
26
|
+
__MT_MOBILE_SWITCH__
|
|
27
|
+
<Btn label="Sign out" onPress={() => { signOut(); router.replace('/login') }} />
|
|
28
|
+
</View>
|
|
29
|
+
)} />
|
|
30
|
+
</>
|
|
31
|
+
)
|
|
32
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// /journey/:flow — a journey, walked: the run says which screen comes next.
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
import { Text, View } from 'react-native'
|
|
4
|
+
import { Stack, router, useLocalSearchParams } from 'expo-router'
|
|
5
|
+
import { Btn, NativeFlowRunner, useNativeHost, useNativeTheme } from '@xeplr/ui-factory/native'
|
|
6
|
+
import { factory, flows } from '../../lib/app.js'
|
|
7
|
+
|
|
8
|
+
export default function Journey() {
|
|
9
|
+
const t = useNativeTheme()
|
|
10
|
+
const host = useNativeHost()
|
|
11
|
+
const { flow } = useLocalSearchParams()
|
|
12
|
+
const [round, setRound] = useState(0) // Start another: a new run
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
<Stack.Screen options={{ title: 'Journey' }} />
|
|
16
|
+
<NativeFlowRunner key={round} {...flows.runnerProps} {...factory.screenProps} flowKey={String(flow)} host={host}
|
|
17
|
+
renderDone={() => (
|
|
18
|
+
<View style={{ flex: 1, padding: 16, backgroundColor: t.plane, gap: 12 }}>
|
|
19
|
+
<Text style={{ color: t.ink, fontSize: 20, fontWeight: '800' }}>All done</Text>
|
|
20
|
+
<Text style={{ color: t.muted }}>Everything in this journey is filled in.</Text>
|
|
21
|
+
<Btn label="Start another" variant="primary" onPress={() => setRound((n) => n + 1)} />
|
|
22
|
+
<Btn label="Back to the menu" onPress={() => router.replace('/')} />
|
|
23
|
+
</View>
|
|
24
|
+
)} />
|
|
25
|
+
</>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// SIGNING IN — @xeplr/ui-account's own, the same ways in as the website.
|
|
2
|
+
import { Stack, router } from 'expo-router'
|
|
3
|
+
import { NativeSignIn } from '@xeplr/ui-account/native'
|
|
4
|
+
import { APP_NAME } from '../lib/app.js'
|
|
5
|
+
|
|
6
|
+
export default function Login() {
|
|
7
|
+
return (
|
|
8
|
+
<>
|
|
9
|
+
<Stack.Screen options={{ title: 'Sign in', headerBackVisible: false }} />
|
|
10
|
+
<NativeSignIn title={APP_NAME} tagline="Sign in to carry on." onSignedIn={() => router.replace('/')} />
|
|
11
|
+
</>
|
|
12
|
+
)
|
|
13
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// THIS APP, ON A PHONE — its name, the server, and the calls every page makes.
|
|
2
|
+
//
|
|
3
|
+
// Nothing here is a screen: the forms, lists, buttons and journeys are the ones
|
|
4
|
+
// designed in Configure UI, read from the server and drawn natively by
|
|
5
|
+
// @xeplr/ui-factory/native. Add a form to the menu in Configure UI and it is on
|
|
6
|
+
// the phone too — no change here, no new build.
|
|
7
|
+
import Constants from 'expo-constants'
|
|
8
|
+
import { authFetch, authFetchFile } from '@xeplr/ui-account/native'
|
|
9
|
+
import { createFactoryApi, createFlowsApi } from '@xeplr/ui-factory/model'
|
|
10
|
+
|
|
11
|
+
export const APP_NAME = '__TITLE__'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The server this build is for — EXPO_PUBLIC_SERVER_URL, written in when the
|
|
15
|
+
* app is built (eas.json). Set, the app goes there and asks for no address.
|
|
16
|
+
* Empty (Expo Go while developing), the address is typed on the sign-in
|
|
17
|
+
* screen, starting from this Mac's own web app (port __UI_PORT__) — run it with
|
|
18
|
+
* `npm run dev -- --host` so the phone can reach it.
|
|
19
|
+
*/
|
|
20
|
+
export const BUILT_IN_SERVER = process.env.EXPO_PUBLIC_SERVER_URL || ''
|
|
21
|
+
|
|
22
|
+
export function devServer() {
|
|
23
|
+
const host = Constants.expoConfig && Constants.expoConfig.hostUri ? Constants.expoConfig.hostUri.split(':')[0] : null
|
|
24
|
+
return process.env.NODE_ENV !== 'production' && host ? `http://${host}:__UI_PORT__` : ''
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// The calls, signed with the session's tokens; they read the server's address
|
|
28
|
+
// when they are made, so one of each is enough.
|
|
29
|
+
export const factory = createFactoryApi({ fetch: authFetch, fetchFile: authFetchFile, base: '/api' })
|
|
30
|
+
export const flows = createFlowsApi({ fetch: authFetch, base: '/api/workflow' })
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The app's own pages that are drawn from a form, by their menu key — on the
|
|
34
|
+
* phone as that form's list. Forms added in Configure UI need nothing here;
|
|
35
|
+
* a page added in code with its own menu key is listed like Tasks.
|
|
36
|
+
*/
|
|
37
|
+
export const PAGES = {
|
|
38
|
+
Tasks: { form: 'task' }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
__MT_MOBILE_TENANCY__
|
package/templates/ui/pages.json
CHANGED
|
@@ -6,12 +6,11 @@
|
|
|
6
6
|
{ "path": "/tasks/:id", "screen": "task_edit" },
|
|
7
7
|
{ "path": "/forms/:form", "screen": "every form's list" },
|
|
8
8
|
{ "path": "/journey/:flow", "screen": "a flow's screens" },
|
|
9
|
-
{ "path": "/journey/:flow/:run", "screen": "a flow's screens" }
|
|
9
|
+
{ "path": "/journey/:flow/:run", "screen": "a flow's screens" },
|
|
10
|
+
{ "path": "/flows", "menu": "Flows", "screen": "the journeys to start — NativeFlows on a phone" }__MT_PAGES_SELECT__
|
|
10
11
|
],
|
|
11
12
|
"webOnly": [
|
|
12
|
-
__MT_PAGES_SELECT__
|
|
13
13
|
{ "path": "/home", "menu": "Home", "reason": "The starter page that proves sign-in and the API work — replace it with your first page." },
|
|
14
|
-
{ "path": "/flows", "menu": "Flows", "reason": "The flows list and designer are tools for building, used on a computer." },
|
|
15
14
|
{ "path": "/configure/flows/:flow", "reason": "The flow designer is a tool for building, used on a computer." },
|
|
16
15
|
{ "path": "/configure", "menu": "Configure UI", "reason": "The form designer and menu settings are tools for building, used on a computer." },
|
|
17
16
|
{ "path": "/configure/forms/:form/design/:part", "reason": "The form designer is a tool for building, used on a computer." }
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// WHERE ARE YOU WORKING? — the company (and workspace) this app's data belongs
|
|
2
|
+
// to, for apps whose data is split by company: @xeplr/ui-account's own picker,
|
|
3
|
+
// the same picking as the website's. What the person may see depends on the
|
|
4
|
+
// company (its admin there, a viewer elsewhere), so the menu is read again.
|
|
5
|
+
import { Stack, router } from 'expo-router'
|
|
6
|
+
import { NativeScopePicker, refreshAccess } from '@xeplr/ui-account/native'
|
|
7
|
+
import { TENANCY } from '../lib/app.js'
|
|
8
|
+
|
|
9
|
+
export default function Select() {
|
|
10
|
+
return (
|
|
11
|
+
<>
|
|
12
|
+
<Stack.Screen options={{ title: 'Choose', headerBackVisible: router.canGoBack() }} />
|
|
13
|
+
<NativeScopePicker levels={TENANCY.levels} onChosen={() => { refreshAccess().finally(() => router.replace('/')) }} />
|
|
14
|
+
</>
|
|
15
|
+
)
|
|
16
|
+
}
|
|
@@ -4,14 +4,13 @@
|
|
|
4
4
|
// authFetch sends it as a header on every request, the API stamps new rows
|
|
5
5
|
// with it and reads only its rows.
|
|
6
6
|
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
|
|
7
|
+
// The picking is @xeplr/ui-account's (useScopeChoice) — the same as the phone
|
|
8
|
+
// app's (NativeScopePicker): each level's list, the last choice already
|
|
9
|
+
// chosen, a list of one chosen for you, adding a new one. This page only
|
|
10
|
+
// draws it. Shown once per browser tab (ScopeGate below); "__MT_SWITCH_NAME__"
|
|
11
|
+
// in the side rail comes back here.
|
|
11
12
|
import { Navigate, useLocation, useNavigate } from 'react-router-dom'
|
|
12
|
-
import {
|
|
13
|
-
authFetch, getActiveScope, setActiveScope, getLastScope, setLastScope, saveReturnTo, consumeReturnTo
|
|
14
|
-
} from '@xeplr/ui-account'
|
|
13
|
+
import { useScopeChoice, scopeChosen, saveReturnTo, consumeReturnTo } from '@xeplr/ui-account'
|
|
15
14
|
import { tenancy } from '../tenancy.js'
|
|
16
15
|
import './SelectScope.css'
|
|
17
16
|
|
|
@@ -23,8 +22,7 @@ const setConfirmed = (yes) => { try { yes ? sessionStorage.setItem(CONFIRMED, '1
|
|
|
23
22
|
/** Lets the app's pages render only once every level is chosen in this tab. */
|
|
24
23
|
export function ScopeGate({ children }) {
|
|
25
24
|
const location = useLocation()
|
|
26
|
-
|
|
27
|
-
if (!complete || !confirmed()) {
|
|
25
|
+
if (!scopeChosen(tenancy.levels) || !confirmed()) {
|
|
28
26
|
saveReturnTo(location)
|
|
29
27
|
return <Navigate to="/select" replace />
|
|
30
28
|
}
|
|
@@ -33,32 +31,10 @@ export function ScopeGate({ children }) {
|
|
|
33
31
|
|
|
34
32
|
export default function SelectScope() {
|
|
35
33
|
const navigate = useNavigate()
|
|
36
|
-
|
|
37
|
-
// Made active straight away — before the lists below load, since a level's
|
|
38
|
-
// list is asked for with the level above it as a header.
|
|
39
|
-
const [chosen, setChosen] = useState(() => {
|
|
40
|
-
const start = Object.fromEntries(tenancy.levels.map((l) => [l.key, getActiveScope(l.key) || getLastScope(l.key) || null]))
|
|
41
|
-
tenancy.levels.forEach((l) => setActiveScope(l.key, start[l.key]))
|
|
42
|
-
return start
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
const choose = useCallback((index, item) => {
|
|
46
|
-
setChosen((c) => {
|
|
47
|
-
const next = { ...c, [tenancy.levels[index].key]: item }
|
|
48
|
-
// A different parent: whatever was chosen below it belonged to the old one.
|
|
49
|
-
tenancy.levels.slice(index + 1).forEach((l) => { next[l.key] = null })
|
|
50
|
-
return next
|
|
51
|
-
})
|
|
52
|
-
// Set as it is chosen, so the level below lists this one's children.
|
|
53
|
-
setActiveScope(tenancy.levels[index].key, item)
|
|
54
|
-
tenancy.levels.slice(index + 1).forEach((l) => setActiveScope(l.key, null))
|
|
55
|
-
setConfirmed(false)
|
|
56
|
-
}, [])
|
|
57
|
-
|
|
58
|
-
const complete = tenancy.levels.every((l) => chosen[l.key])
|
|
34
|
+
const choice = useScopeChoice({ levels: tenancy.levels })
|
|
59
35
|
|
|
60
36
|
const go = () => {
|
|
61
|
-
|
|
37
|
+
if (!choice.finish()) return
|
|
62
38
|
setConfirmed(true)
|
|
63
39
|
navigate(consumeReturnTo() || '/home', { replace: true })
|
|
64
40
|
}
|
|
@@ -68,87 +44,36 @@ export default function SelectScope() {
|
|
|
68
44
|
<h1>Where are you working?</h1>
|
|
69
45
|
<p className="app-page-lead">Everything you see and save next belongs to this choice.</p>
|
|
70
46
|
|
|
71
|
-
{
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
<
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
47
|
+
{choice.levels.map((level, i) => (
|
|
48
|
+
<section key={level.key} className={'app-select-level' + (level.enabled ? '' : ' is-disabled')}>
|
|
49
|
+
<h2>{level.label}</h2>
|
|
50
|
+
{!level.enabled && <p className="app-sub">Choose the one above first.</p>}
|
|
51
|
+
{level.enabled && level.items === null && !level.error && <p className="app-sub">Loading…</p>}
|
|
52
|
+
{level.error && <div className="app-error">{level.error}</div>}
|
|
53
|
+
{level.enabled && level.items && (
|
|
54
|
+
<>
|
|
55
|
+
{level.items.length === 0 && <p className="app-sub">No {level.noun} yet — add the first one.</p>}
|
|
56
|
+
<div className="app-select-items">
|
|
57
|
+
{level.items.map((item) => {
|
|
58
|
+
const on = !!level.value && level.value.id === item.id
|
|
59
|
+
return (
|
|
60
|
+
<button key={item.id} type="button" className={'app-select-item' + (on ? ' is-chosen' : '')} aria-pressed={on}
|
|
61
|
+
onClick={() => { setConfirmed(false); choice.choose(i, item) }}>
|
|
62
|
+
{item.name}
|
|
63
|
+
</button>
|
|
64
|
+
)
|
|
65
|
+
})}
|
|
66
|
+
</div>
|
|
67
|
+
<form className="app-select-add" onSubmit={(e) => { e.preventDefault(); setConfirmed(false); choice.add(i) }}>
|
|
68
|
+
<input value={level.adding} onChange={(e) => choice.setAdding(i, e.target.value)} placeholder={'New ' + level.noun + ' name'} aria-label={'New ' + level.noun + ' name'} />
|
|
69
|
+
<button type="submit" className="app-btn app-btn-quiet" disabled={level.busy || !level.adding.trim()}>Add {level.noun}</button>
|
|
70
|
+
</form>
|
|
71
|
+
</>
|
|
72
|
+
)}
|
|
73
|
+
</section>
|
|
74
|
+
))}
|
|
83
75
|
|
|
84
|
-
<button type="button" className="app-btn" disabled={!complete} onClick={go}>Continue</button>
|
|
76
|
+
<button type="button" className="app-btn" disabled={!choice.complete} onClick={go}>Continue</button>
|
|
85
77
|
</div>
|
|
86
78
|
)
|
|
87
79
|
}
|
|
88
|
-
|
|
89
|
-
function LevelChoice({ level, enabled, value, onChoose }) {
|
|
90
|
-
const [items, setItems] = useState(null)
|
|
91
|
-
const [error, setError] = useState(null)
|
|
92
|
-
const [adding, setAdding] = useState('')
|
|
93
|
-
const [busy, setBusy] = useState(false)
|
|
94
|
-
const noun = level.label.toLowerCase()
|
|
95
|
-
|
|
96
|
-
useEffect(() => {
|
|
97
|
-
if (!enabled) return
|
|
98
|
-
authFetch('/api/tenants/' + level.key).then((body) => {
|
|
99
|
-
const rows = body.dataArray || []
|
|
100
|
-
setItems(rows)
|
|
101
|
-
// A remembered choice that is no longer on the list is not a choice.
|
|
102
|
-
if (value && !rows.some((r) => r.id === value.id)) onChoose(null)
|
|
103
|
-
else if (!value && rows.length === 1) onChoose(rows[0])
|
|
104
|
-
}, (e) => setError(e.message))
|
|
105
|
-
}, [enabled, level.key]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
106
|
-
|
|
107
|
-
const add = async (e) => {
|
|
108
|
-
e.preventDefault()
|
|
109
|
-
setBusy(true)
|
|
110
|
-
try {
|
|
111
|
-
const body = await authFetch('/api/tenants/' + level.key, { method: 'POST', body: JSON.stringify({ name: adding }) })
|
|
112
|
-
const created = body.dataArray[0]
|
|
113
|
-
setItems((list) => [...(list || []), created].sort((a, b) => a.name.localeCompare(b.name)))
|
|
114
|
-
setAdding('')
|
|
115
|
-
setError(null)
|
|
116
|
-
onChoose(created)
|
|
117
|
-
} catch (err) {
|
|
118
|
-
setError(err.message)
|
|
119
|
-
} finally {
|
|
120
|
-
setBusy(false)
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return (
|
|
125
|
-
<section className={'app-select-level' + (enabled ? '' : ' is-disabled')}>
|
|
126
|
-
<h2>{level.label}</h2>
|
|
127
|
-
{!enabled && <p className="app-sub">Choose the one above first.</p>}
|
|
128
|
-
{enabled && items === null && !error && <p className="app-sub">Loading…</p>}
|
|
129
|
-
{error && <div className="app-error">{error}</div>}
|
|
130
|
-
{enabled && items && (
|
|
131
|
-
<>
|
|
132
|
-
{items.length === 0 && <p className="app-sub">No {noun} yet — add the first one.</p>}
|
|
133
|
-
<div className="app-select-items">
|
|
134
|
-
{items.map((item) => (
|
|
135
|
-
<button
|
|
136
|
-
key={item.id}
|
|
137
|
-
type="button"
|
|
138
|
-
className={'app-select-item' + (value && value.id === item.id ? ' is-chosen' : '')}
|
|
139
|
-
aria-pressed={!!value && value.id === item.id}
|
|
140
|
-
onClick={() => onChoose(item)}
|
|
141
|
-
>
|
|
142
|
-
{item.name}
|
|
143
|
-
</button>
|
|
144
|
-
))}
|
|
145
|
-
</div>
|
|
146
|
-
<form className="app-select-add" onSubmit={add}>
|
|
147
|
-
<input value={adding} onChange={(e) => setAdding(e.target.value)} placeholder={'New ' + noun + ' name'} aria-label={'New ' + noun + ' name'} />
|
|
148
|
-
<button type="submit" className="app-btn app-btn-quiet" disabled={busy || !adding.trim()}>Add {noun}</button>
|
|
149
|
-
</form>
|
|
150
|
-
</>
|
|
151
|
-
)}
|
|
152
|
-
</section>
|
|
153
|
-
)
|
|
154
|
-
}
|