create-lupine 1.0.31 → 1.2.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 +25 -0
- package/index.js +11 -9
- package/package.json +1 -1
- package/templates/common/.agents/skills/lupine-framework/SKILL.md +63 -0
- package/templates/common/.agents/skills/lupine-framework/references/backend-api.md +98 -0
- package/templates/common/.agents/skills/lupine-framework/references/icon-handling.md +71 -0
- package/templates/common/.agents/skills/lupine-framework/references/mobile-interactions.md +100 -0
- package/templates/common/.agents/skills/lupine-framework/references/native-apps.md +167 -0
- package/templates/common/.agents/skills/lupine-framework/references/navigation-and-routing.md +54 -0
- package/templates/common/.agents/skills/lupine-framework/references/reactivity-and-state.md +108 -0
- package/templates/common/.agents/skills/lupine-framework/references/styling-and-themes.md +119 -0
- package/templates/common/_env +2 -0
- package/templates/lupine-template-cv-starter/README.md +5 -0
- package/templates/lupine-template-cv-starter/web/src/index.tsx +1 -10
- package/templates/lupine-template-cv-starter/web/src/lupine-template-cv-starter/index.tsx +1 -10
- package/templates/lupine-template-doc-starter/README.md +5 -0
- package/templates/lupine-template-doc-starter/web/src/index.tsx +1 -10
- package/templates/lupine-template-doc-starter/web/src/lupine-template-doc-starter/index.tsx +1 -10
- package/templates/lupine-template-fullstack-starter/README.md +21 -0
- package/templates/lupine-template-fullstack-starter/api/package.json +10 -0
- package/templates/lupine-template-fullstack-starter/api/resources/install.mysql.sql +107 -0
- package/templates/lupine-template-fullstack-starter/api/resources/install.sqlite.sql +75 -0
- package/templates/lupine-template-fullstack-starter/api/src/lang/api-lang-en.ts +39 -0
- package/templates/lupine-template-fullstack-starter/api/src/lang/api-lang-zh-cn.ts +37 -0
- package/templates/lupine-template-fullstack-starter/api/src/service/admin-api.ts +139 -0
- package/templates/lupine-template-fullstack-starter/api/src/service/api.ts +111 -0
- package/templates/lupine-template-fullstack-starter/api/src/service/contact-api.ts +50 -0
- package/templates/lupine-template-fullstack-starter/api/src/service/file-api-base.ts +30 -0
- package/templates/lupine-template-fullstack-starter/api/src/service/root-api.ts +28 -0
- package/templates/lupine-template-fullstack-starter/api/src/service/send-email.ts +47 -0
- package/templates/lupine-template-fullstack-starter/api/src/service/setting-api.ts +60 -0
- package/templates/lupine-template-fullstack-starter/api/src/service/user-api.ts +1041 -0
- package/templates/{lupine-template-hello-world → lupine-template-fullstack-starter}/lupine.json +10 -1
- package/templates/lupine-template-fullstack-starter/web/assets/android-chrome-192x192.png +0 -0
- package/templates/lupine-template-fullstack-starter/web/assets/apple-touch-icon.png +0 -0
- package/templates/lupine-template-fullstack-starter/web/assets/favicon-16x16.png +0 -0
- package/templates/lupine-template-fullstack-starter/web/assets/favicon-32x32.png +0 -0
- package/templates/lupine-template-fullstack-starter/web/assets/icons-font/License-carbon-icons.txt +71 -0
- package/templates/lupine-template-fullstack-starter/web/assets/icons-font/License-material-design.txt +20 -0
- package/templates/lupine-template-fullstack-starter/web/assets/icons-font/i-font.woff2 +0 -0
- package/templates/lupine-template-fullstack-starter/web/assets/icons-font/sample.html +124 -0
- package/templates/lupine-template-fullstack-starter/web/assets/icons-font/style.css +103 -0
- package/templates/lupine-template-fullstack-starter/web/assets/images/sample.png +0 -0
- package/templates/lupine-template-fullstack-starter/web/assets/lupine-flower.png +0 -0
- package/templates/lupine-template-fullstack-starter/web/assets/lupine.svg +71 -0
- package/templates/lupine-template-fullstack-starter/web/assets/site.webmanifest +14 -0
- package/templates/lupine-template-fullstack-starter/web/icons-font.config.js +129 -0
- package/templates/{lupine-template-hello-world → lupine-template-fullstack-starter}/web/package.json +1 -1
- package/templates/lupine-template-fullstack-starter/web/src/admin_dev/admin-about.tsx +16 -0
- package/templates/lupine-template-fullstack-starter/web/src/admin_dev/admin-patch.ts +22 -0
- package/templates/lupine-template-fullstack-starter/web/src/admin_dev/index.html +22 -0
- package/templates/lupine-template-fullstack-starter/web/src/admin_dev/index.tsx +64 -0
- package/templates/lupine-template-fullstack-starter/web/src/components/footer-menu.tsx +52 -0
- package/templates/lupine-template-fullstack-starter/web/src/components/footer.tsx +15 -0
- package/templates/lupine-template-fullstack-starter/web/src/components/header.tsx +75 -0
- package/templates/lupine-template-fullstack-starter/web/src/components/home-search-component.tsx +132 -0
- package/templates/lupine-template-fullstack-starter/web/src/components/login-code-zh.tsx +162 -0
- package/templates/lupine-template-fullstack-starter/web/src/components/login-code.tsx +165 -0
- package/templates/lupine-template-fullstack-starter/web/src/components/login-zh.tsx +118 -0
- package/templates/lupine-template-fullstack-starter/web/src/components/login.tsx +122 -0
- package/templates/lupine-template-fullstack-starter/web/src/components/not-found-page.tsx +12 -0
- package/templates/lupine-template-fullstack-starter/web/src/components/register-zh.tsx +161 -0
- package/templates/lupine-template-fullstack-starter/web/src/components/register.tsx +163 -0
- package/templates/lupine-template-fullstack-starter/web/src/components/reset-password-zh.tsx +166 -0
- package/templates/lupine-template-fullstack-starter/web/src/components/reset-password.tsx +177 -0
- package/templates/lupine-template-fullstack-starter/web/src/components/story-card.tsx +96 -0
- package/templates/lupine-template-fullstack-starter/web/src/components/story-list.tsx +106 -0
- package/templates/lupine-template-fullstack-starter/web/src/components/story-props.ts +34 -0
- package/templates/lupine-template-fullstack-starter/web/src/components/user-info.tsx +84 -0
- package/templates/lupine-template-fullstack-starter/web/src/frames/admin-page-frame.tsx +48 -0
- package/templates/lupine-template-fullstack-starter/web/src/frames/frame1-page-frame.tsx +61 -0
- package/templates/lupine-template-fullstack-starter/web/src/frames/frame2-page-frame.tsx +61 -0
- package/templates/lupine-template-fullstack-starter/web/src/frames/top-frame.tsx +23 -0
- package/templates/lupine-template-fullstack-starter/web/src/frames/user-page-frame.tsx +90 -0
- package/templates/{lupine-template-hello-world → lupine-template-fullstack-starter}/web/src/index.html +6 -0
- package/templates/lupine-template-fullstack-starter/web/src/index.tsx +155 -0
- package/templates/lupine-template-fullstack-starter/web/src/models/client-env-keys.ts +5 -0
- package/templates/lupine-template-fullstack-starter/web/src/models/index.ts +15 -0
- package/templates/lupine-template-fullstack-starter/web/src/pages/admin-cfg.tsx +140 -0
- package/templates/lupine-template-fullstack-starter/web/src/pages/admin-item-edit.tsx +21 -0
- package/templates/lupine-template-fullstack-starter/web/src/pages/admin-item-list.tsx +24 -0
- package/templates/lupine-template-fullstack-starter/web/src/pages/admin-user.tsx +150 -0
- package/templates/lupine-template-fullstack-starter/web/src/pages/contact.tsx +105 -0
- package/templates/lupine-template-fullstack-starter/web/src/pages/page1-page.tsx +38 -0
- package/templates/lupine-template-fullstack-starter/web/src/pages/page2-page.tsx +38 -0
- package/templates/lupine-template-fullstack-starter/web/src/pages/user-favorite-page.tsx +58 -0
- package/templates/lupine-template-fullstack-starter/web/src/pages/user-home-page.tsx +27 -0
- package/templates/lupine-template-fullstack-starter/web/src/pages/user-mine-page.tsx +54 -0
- package/templates/lupine-template-fullstack-starter/web/src/pages/user-profile-page-zh.tsx +112 -0
- package/templates/lupine-template-fullstack-starter/web/src/pages/user-profile-page.tsx +112 -0
- package/templates/lupine-template-fullstack-starter/web/src/pages/user1-page.tsx +57 -0
- package/templates/lupine-template-fullstack-starter/web/src/services/fetch-data.ts +55 -0
- package/templates/lupine-template-fullstack-starter/web/src/services/shared-data.ts +19 -0
- package/templates/lupine-template-fullstack-starter/web/src/styles/base-css.ts +17 -0
- package/templates/{lupine-template-hello-world → lupine-template-fullstack-starter}/web/src/styles/global.css +10 -57
- package/templates/{lupine-template-hello-world → lupine-template-fullstack-starter}/web/src/styles/theme.ts +3 -1
- package/templates/lupine-template-responsive-starter/README.md +7 -0
- package/templates/lupine-template-responsive-starter/web/src/components/input-history-component.tsx +1 -1
- package/templates/lupine-template-responsive-starter/web/src/components/mine-about-page.tsx +2 -1
- package/templates/lupine-template-responsive-starter/web/src/components/mine-premium-page.tsx +2 -1
- package/templates/lupine-template-responsive-starter/web/src/components/mine-settings-page.tsx +8 -17
- package/templates/lupine-template-responsive-starter/web/src/components/mobile-top-search-menu.tsx +15 -27
- package/templates/lupine-template-responsive-starter/web/src/components/note-detail.tsx +2 -8
- package/templates/lupine-template-responsive-starter/web/src/components/note-edit.tsx +26 -36
- package/templates/lupine-template-responsive-starter/web/src/components/note-search-page.tsx +16 -21
- package/templates/lupine-template-responsive-starter/web/src/components/search-input.tsx +9 -9
- package/templates/lupine-template-responsive-starter/web/src/components/side-menu-content.tsx +3 -16
- package/templates/lupine-template-responsive-starter/web/src/frames/app-responsive-frame.tsx +3 -2
- package/templates/lupine-template-responsive-starter/web/src/index.tsx +2 -11
- package/templates/lupine-template-responsive-starter/web/src/lupine-template-responsive-starter/index.tsx +1 -10
- package/templates/lupine-template-responsive-starter/web/src/pages/about-page.tsx +3 -14
- package/templates/lupine-template-responsive-starter/web/src/pages/finance-page.tsx +3 -14
- package/templates/lupine-template-responsive-starter/web/src/pages/home-page.tsx +7 -15
- package/templates/lupine-template-responsive-starter/web/src/pages/mine-page.tsx +7 -14
- package/templates/lupine-template-responsive-starter/web/src/pages/tools-page.tsx +3 -14
- package/templates/lupine-template-responsive-starter/web/src/styles/theme.ts +2 -1
- package/templates/common/AI_CONTEXT.md +0 -1002
- package/templates/lupine-template-hello-world/api/package.json +0 -6
- package/templates/lupine-template-hello-world/api/resources/install.sqlite.sql +0 -4
- package/templates/lupine-template-hello-world/api/src/service/root-api.ts +0 -18
- package/templates/lupine-template-hello-world/web/src/index.tsx +0 -73
- package/templates/lupine-template-hello-world/web/src/styles/base-css.ts +0 -1
- /package/templates/{lupine-template-hello-world → lupine-template-fullstack-starter}/api/resources/config_default.json +0 -0
- /package/templates/{lupine-template-hello-world → lupine-template-fullstack-starter}/api/src/index.ts +0 -0
- /package/templates/{lupine-template-hello-world → lupine-template-fullstack-starter}/web/assets/favicon.ico +0 -0
- /package/templates/{lupine-template-hello-world → lupine-template-fullstack-starter}/web/src/styles/app.css +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# create-lupine
|
|
2
|
+
|
|
3
|
+
Creates a new [lupine.js](https://github.com/uuware/lupine.js) project: a web site or app with lupine.web (front end, SSR) and lupine.api (Node back end).
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx create-lupine@latest my-app
|
|
7
|
+
cd my-app
|
|
8
|
+
npm install
|
|
9
|
+
npm run dev # http://localhost:11080
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Templates to choose from:
|
|
13
|
+
|
|
14
|
+
| Template | |
|
|
15
|
+
| --- | --- |
|
|
16
|
+
| `responsive-starter` (tabs or side menu) | an app for phones that runs on the web, too: notes, pages, settings |
|
|
17
|
+
| `fullstack-starter` | a web site: pages, frames, sign-in and registration, an admin area, an API with a database |
|
|
18
|
+
| `doc-starter` | documentation from Markdown, for GitHub Pages too |
|
|
19
|
+
| `cv-starter` | a CV from Markdown |
|
|
20
|
+
|
|
21
|
+
`npx create-lupine --update-version` brings the lupine packages of an existing project up to date.
|
|
22
|
+
|
|
23
|
+
Native apps (iOS, Android, macOS, Windows): start from `apps/native-starter` of the repository, see [Getting started](https://uuware.github.io/lupine.js/en/native/started).
|
|
24
|
+
|
|
25
|
+
MIT.
|
package/index.js
CHANGED
|
@@ -71,13 +71,6 @@ for (let i = 0; i < args.length; i++) {
|
|
|
71
71
|
const cwd = process.cwd();
|
|
72
72
|
|
|
73
73
|
const TEMPLATES = [
|
|
74
|
-
{
|
|
75
|
-
name: 'hello-world',
|
|
76
|
-
dir: 'lupine-template-hello-world',
|
|
77
|
-
display: 'Hello World',
|
|
78
|
-
itemType: 'frontend',
|
|
79
|
-
color: green,
|
|
80
|
-
},
|
|
81
74
|
{
|
|
82
75
|
name: 'doc-starter',
|
|
83
76
|
dir: 'lupine-template-doc-starter',
|
|
@@ -110,6 +103,13 @@ const TEMPLATES = [
|
|
|
110
103
|
itemType: 'frontend',
|
|
111
104
|
color: green,
|
|
112
105
|
},
|
|
106
|
+
{
|
|
107
|
+
name: 'fullstack-starter',
|
|
108
|
+
dir: 'lupine-template-fullstack-starter',
|
|
109
|
+
display: 'Full-stack Web Starter (pages, accounts, admin, API)',
|
|
110
|
+
itemType: 'frontend',
|
|
111
|
+
color: green,
|
|
112
|
+
},
|
|
113
113
|
];
|
|
114
114
|
|
|
115
115
|
async function init() {
|
|
@@ -117,7 +117,8 @@ async function init() {
|
|
|
117
117
|
const versions = {
|
|
118
118
|
'lupine.api': getLatestVersion('lupine.api', '^1.0.1'),
|
|
119
119
|
'lupine.web': getLatestVersion('lupine.web', '^1.0.1'),
|
|
120
|
-
'lupine.
|
|
120
|
+
'lupine.core': getLatestVersion('lupine.core', '^0.1.0'),
|
|
121
|
+
'lupine.web.components': getLatestVersion('lupine.web.components', '^1.2.0'),
|
|
121
122
|
'lupine.press': getLatestVersion('lupine.press', '^1.0.1')
|
|
122
123
|
};
|
|
123
124
|
|
|
@@ -326,7 +327,8 @@ async function init() {
|
|
|
326
327
|
|
|
327
328
|
pkg.dependencies = {
|
|
328
329
|
'lupine.api': versions['lupine.api'],
|
|
329
|
-
'lupine.
|
|
330
|
+
'lupine.core': versions['lupine.core'],
|
|
331
|
+
'lupine.web.components': versions['lupine.web.components'],
|
|
330
332
|
'lupine.web': versions['lupine.web'],
|
|
331
333
|
};
|
|
332
334
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: lupine-framework
|
|
3
|
+
description: >-
|
|
4
|
+
How to write code for Lupine.js: web sites with lupine.web (TSX, signals, router, CSS-in-JS, SSR), Node back ends
|
|
5
|
+
with lupine.api, and native apps for iOS, Android, macOS, Windows and the web with lupine.native. Use it when writing,
|
|
6
|
+
changing or reviewing pages, components, routes, styles, API handlers or native screens of a Lupine.js project, or
|
|
7
|
+
when building, testing or running native apps with the lupine-native tool.
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Lupine.js
|
|
11
|
+
|
|
12
|
+
One TypeScript code base for web sites, Node.js back ends and native apps. State is **signals**; a component function runs **once**; there is no virtual DOM, no compiler of its own and no React hooks.
|
|
13
|
+
|
|
14
|
+
## Which package
|
|
15
|
+
|
|
16
|
+
| Writing | Import from | Never in that code |
|
|
17
|
+
| --- | --- | --- |
|
|
18
|
+
| a web page or web component | `lupine.web` (signals, `CssProps`, router, SSR), `lupine.web.components` (components, `createField`) | `lupine.native.*` (except as in references/native-apps.md, "native components in a web page") |
|
|
19
|
+
| a native screen (iOS, Android, macOS, Windows, web) | `lupine.native.core` (signals, View, Text, platform functions), `lupine.native.components` (themes, router, forms, overlays) | `document`, `window`, `localStorage`, `lupine.web`, `lupine.web.components`: there is no DOM. Only `src/index.web.tsx` may use the DOM |
|
|
20
|
+
| a back end | `lupine.api` | DOM, browser APIs |
|
|
21
|
+
|
|
22
|
+
Signals come from the framework package (`lupine.web` or `lupine.native.core`); both pass on all of `lupine.core`. Don't add `lupine.core` to an app.
|
|
23
|
+
|
|
24
|
+
## The rules that matter most
|
|
25
|
+
|
|
26
|
+
1. **State is a signal**: `const [count, setCount] = createSignal(0)`. Plain variables don't update the page.
|
|
27
|
+
2. **Pass a function, not its result**: `{count}` or `{() => count() + 1}` is updated; `{count()}` is read once and never again. The same for props and styles: `class={() => (on() ? 'a' : 'b')}`, `style={{ opacity: () => (on() ? 1 : 0.5) }}`.
|
|
28
|
+
3. **A component runs once**: no re-rendering, no dependency arrays. Derived values: `createMemo`. Side effects: `createEffect` (not on the server). Once, when shown: `onMount`. When removed: `onCleanup`. In an async component call them before the first `await`.
|
|
29
|
+
4. **Lists and conditions**: `<For each={items}>{(item) => ...}</For>` keeps rows by identity; `<Show when={on} fallback={...}>`.
|
|
30
|
+
5. **Look before you change**: read the file and the code around it first; change the smallest part that does the job; don't rewrite what you weren't asked to touch.
|
|
31
|
+
|
|
32
|
+
## Web specifics (lupine.web)
|
|
33
|
+
|
|
34
|
+
- Styles: `css={...}` with `&` for the component's own class names (`class='&-title'`), theme variables instead of fixed colors. → references/styling-and-themes.md
|
|
35
|
+
- Pages: `PageRouter`, parameters `/:id`, optional `/?opt`, frames; links are `<a href>`, from code `initializePage(path)`. → references/navigation-and-routing.md
|
|
36
|
+
- **SSR**: pages are rendered on the server first. At the top of a module use `bindAppGlobalStyle`, not `bindGlobalStyle`; while rendering don't touch `window`, `document` or `localStorage` (check `isFrontEnd()` or do it in `onMount`).
|
|
37
|
+
- Phones in the browser: `SliderFrame`, `ActionSheet...Promise` instead of `alert`/`confirm`. → references/mobile-interactions.md
|
|
38
|
+
- Icons: references/icon-handling.md
|
|
39
|
+
|
|
40
|
+
## Native specifics (lupine.native)
|
|
41
|
+
|
|
42
|
+
- Components: `View`, `Text`, `TextInput`, `ScrollView`, `List`, `Image`, `Canvas`, `GL`; styles are objects (flexbox, top to bottom), each value may be a function; `onPress`, `gesture(...)`.
|
|
43
|
+
- Colors from the theme: `col('text')`; pages: `router` with `Pages`, `Screen`; messages: `Toast`, `ActionSheet`; put `<OverlayHost />` last.
|
|
44
|
+
- Build, run, test: `npx lupine-native <ios|android|macos|windows|web> --app=<dir> --run`, `npx lupine-native test <platform> --app=<dir>`, `npx lupine-native doctor`.
|
|
45
|
+
→ references/native-apps.md
|
|
46
|
+
|
|
47
|
+
## Back end (lupine.api)
|
|
48
|
+
|
|
49
|
+
API modules and routers, databases, SSR of the web pages, the admin console; writing routes are POST and check the session. → references/backend-api.md
|
|
50
|
+
|
|
51
|
+
## References
|
|
52
|
+
|
|
53
|
+
| Topic | File |
|
|
54
|
+
| --- | --- |
|
|
55
|
+
| Signals, lifecycle, lists, forms, refs (web and native) | [reactivity-and-state.md](./references/reactivity-and-state.md) |
|
|
56
|
+
| CSS-in-JS, `&` classes, themes and dark mode (web) | [styling-and-themes.md](./references/styling-and-themes.md) |
|
|
57
|
+
| Router, parameters, SSR, environment and settings (web) | [navigation-and-routing.md](./references/navigation-and-routing.md) |
|
|
58
|
+
| SliderFrame, action sheets, the back button (web on phones) | [mobile-interactions.md](./references/mobile-interactions.md) |
|
|
59
|
+
| Icons (web, admin) | [icon-handling.md](./references/icon-handling.md) |
|
|
60
|
+
| Native apps: components, styles, navigation, platform functions, tests, the CLI | [native-apps.md](./references/native-apps.md) |
|
|
61
|
+
| Back end: apps, API routers, databases, security | [backend-api.md](./references/backend-api.md) |
|
|
62
|
+
|
|
63
|
+
Documentation: https://uuware.github.io/lupine.js/ (its Markdown is in `apps/doc/web/markdown/en` of the lupine.js repository).
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Back end (lupine.api)
|
|
2
|
+
|
|
3
|
+
A Node.js server for several apps: the domain chooses the app with its API module, web files and data. It also renders the web pages (SSR) and has an admin console. Documentation: https://uuware.github.io/lupine.js/en/lupine.api/index and https://uuware.github.io/lupine.js/en/essentials/ssr.
|
|
4
|
+
|
|
5
|
+
## A project
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
.env, .env.development, .env.production APPS, DOMAINS:<app>, ports, DB_TYPE, WEB.* for the front end
|
|
9
|
+
apps/server/ starts the server (from the template, usually unchanged)
|
|
10
|
+
apps/my-app/lupine.json webEntryPoints, apiEntryPoint, copyFiles
|
|
11
|
+
apps/my-app/web/src/index.tsx front end (lupine.web)
|
|
12
|
+
apps/my-app/api/src/index.ts export const apiModule = new ApiModule(new RootApi())
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm run dev # lupine-build --dev=1, then the server: http://localhost:11080, rebuilds on change
|
|
17
|
+
npm run build # production build into dist/server_root: <app>_web, <app>_api, <app>_data (data isn't touched)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
A new app needs its name in `APPS` and a `DOMAINS:<name>=...` line of `.env`.
|
|
21
|
+
|
|
22
|
+
## The API module
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { ApiHelper, ApiModule, ApiRouter, IApiBase, StaticServer } from 'lupine.api';
|
|
26
|
+
|
|
27
|
+
class RootApi implements IApiBase {
|
|
28
|
+
private router = new ApiRouter();
|
|
29
|
+
constructor() {
|
|
30
|
+
this.router.use('/api', new Api().getRouter());
|
|
31
|
+
// last: static files, otherwise the page is rendered by SSR
|
|
32
|
+
const staticServer = new StaticServer();
|
|
33
|
+
this.router.use('*', staticServer.processRequest.bind(staticServer));
|
|
34
|
+
}
|
|
35
|
+
getRouter() {
|
|
36
|
+
return this.router;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export const apiModule = new ApiModule(new RootApi());
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- `router.get`, `router.post`, `router.use` (all methods); paths like the page router: `/:id` required, `/?id` optional.
|
|
43
|
+
- A handler returns `true` when it has answered; `false` asks the next one. A handler may be another router; several handlers run in order (`use('/orders', checkUser, orders)`), so a check can stop the request.
|
|
44
|
+
- `setFilter(fn)` runs before all routes of a router.
|
|
45
|
+
|
|
46
|
+
## Requests and answers
|
|
47
|
+
|
|
48
|
+
| | |
|
|
49
|
+
| --- | --- |
|
|
50
|
+
| `req.locals.json()` `text()` `formData()` | the body |
|
|
51
|
+
| `req.locals.query` | `URLSearchParams` |
|
|
52
|
+
| `req.locals.urlParameters.get('id', '')` | parameters of the path |
|
|
53
|
+
| `req.locals.cookies().get(name, '')`, `setCookie`, `clearCookie` | cookies |
|
|
54
|
+
| `ApiHelper.sendJson(req, res, data, status?)` | JSON; also `sendHtml`, `sendFile` |
|
|
55
|
+
|
|
56
|
+
Answers of the templates are `{ status: 'ok' | 'error', message, ... }`; texts for users come from `langHelper.getLang('shared:...')`.
|
|
57
|
+
|
|
58
|
+
## Rules for handlers
|
|
59
|
+
|
|
60
|
+
- **What changes data is POST** and checks the user on the server first (in the templates `getUserFromCookie(req, res, ...)`, and its role for admin functions). Checks in the front end only decide what is shown.
|
|
61
|
+
- Check what was sent: types, lengths, and that an object isn't an array; skip keys like `__proto__` before copying keys into an object.
|
|
62
|
+
- SQL only with parameters (`?`), never with typed text in the string.
|
|
63
|
+
- File names from users: `isSafeFilename`, `resolveSafePath` (files stay inside the app's data folder). URLs the server fetches for users: `validateTargetUrl`.
|
|
64
|
+
- No secrets in the front end: only `.env` variables that start with `WEB.` reach it.
|
|
65
|
+
|
|
66
|
+
## Databases
|
|
67
|
+
|
|
68
|
+
SQLite, MySQL, SQL Server and Oracle, chosen by `DB_TYPE` (also per app: `DB_TYPE:<app>`). `$__` becomes the table prefix.
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { apiCache, ApiHelper, ApiRouter } from 'lupine.api';
|
|
72
|
+
|
|
73
|
+
const notes = new ApiRouter();
|
|
74
|
+
notes.get('/list', async (req, res) => {
|
|
75
|
+
const rows = await apiCache.getDb().select('SELECT id, title FROM $__note WHERE title LIKE ? ORDER BY id DESC', ['%a%']);
|
|
76
|
+
ApiHelper.sendJson(req, res, rows);
|
|
77
|
+
return true;
|
|
78
|
+
});
|
|
79
|
+
notes.post('/add', async (req, res) => {
|
|
80
|
+
const { title } = req.locals.json() as { title: string };
|
|
81
|
+
await apiCache.getDb().transaction(async (trx) => {
|
|
82
|
+
await trx.insertObject('$__note', { title });
|
|
83
|
+
});
|
|
84
|
+
ApiHelper.sendJson(req, res, { status: 'ok' });
|
|
85
|
+
return true;
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
New tables go into the install scripts of the app (`api/resources/install.sqlite.sql`, `install.mysql.sql`, ...).
|
|
90
|
+
|
|
91
|
+
## SSR and settings
|
|
92
|
+
|
|
93
|
+
- Every URL that no API and no file answers is rendered by the front end's `PageRouter` on the server (references/navigation-and-routing.md). Async page components load their data with `props.renderPageFunctions.fetchData(url)`, which on the server calls the API inside the process with the request's cookies.
|
|
94
|
+
- `apiStorage.setWeb(key, value)` + `apiStorage.save()` store settings that the front end reads with `WebConfig.get(key, default)`, without a new release.
|
|
95
|
+
|
|
96
|
+
## Helpers
|
|
97
|
+
|
|
98
|
+
`lupine.api` passes on the helpers of `lupine.core` (`Logger`, dates, `formatBytes`, `SimpleStorage`, ...). Others: `langHelper`, `apiCache`, `apiStorage`, `ApiHelper`, `CryptoUtils`, `resolveSafePath`, `isSafeFilename`, `isSafeSqlIdentifier`, `validateTargetUrl` (no requests to private addresses), CSV and form data parsers; look in `packages/lupine.api/src` before writing one of your own.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Icon Handling in Lupine.api and Target Apps
|
|
2
|
+
|
|
3
|
+
`lupine.api` UI code commonly uses icon classes such as:
|
|
4
|
+
|
|
5
|
+
```tsx
|
|
6
|
+
<i class='ifc-icon ma-pencil-outline mr-m' onClick={onEditLocal} title='Edit'></i>
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The package expects the final app to provide the actual icon implementation. There are two supported patterns.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Pattern A: Generated Icon Font
|
|
14
|
+
|
|
15
|
+
The full-stack template uses `apps/lupine-template-fullstack-starter/web/icons-font.config.js` to generate a font icon bundle. This config defines icon names and source SVG files, then the generated CSS/font makes classes such as `ifc-icon ma-pencil-outline` render correctly.
|
|
16
|
+
|
|
17
|
+
When using this pattern:
|
|
18
|
+
|
|
19
|
+
- Prefer existing icon names already provided by the target app.
|
|
20
|
+
- If a new icon is required, add it to the app-level icon font config, not to `lupine.api` package code.
|
|
21
|
+
- Keep using the existing markup contract: `<i class='ifc-icon icon-name'></i>`.
|
|
22
|
+
- Remember that `lupine.api` is a package; it should not assume a specific app's generated font file exists unless the target app includes it.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Pattern B: Embedded SVG Mask Icons
|
|
27
|
+
|
|
28
|
+
Some target apps do not generate an icon font. For convenience, they can provide CSS mask-based embedded SVG icons instead. The CMS app uses `apps/cms/web/src/styles/app-icons.ts` for this.
|
|
29
|
+
|
|
30
|
+
The pattern is:
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
export const appIconsCss: CssProps = {
|
|
34
|
+
'.ifc-icon': {
|
|
35
|
+
display: 'inline-block',
|
|
36
|
+
width: '24px',
|
|
37
|
+
height: '24px',
|
|
38
|
+
maskRepeat: 'no-repeat',
|
|
39
|
+
maskPosition: 'center',
|
|
40
|
+
maskSize: 'contain',
|
|
41
|
+
'-webkit-mask-repeat': 'no-repeat',
|
|
42
|
+
'-webkit-mask-position': 'center',
|
|
43
|
+
'-webkit-mask-size': 'contain',
|
|
44
|
+
WebkitMaskRepeat: 'no-repeat',
|
|
45
|
+
WebkitMaskPosition: 'center',
|
|
46
|
+
WebkitMaskSize: 'contain',
|
|
47
|
+
backgroundColor: 'currentColor',
|
|
48
|
+
},
|
|
49
|
+
...Object.entries(appIcons).reduce((acc: any, [key, svg]) => {
|
|
50
|
+
acc['.ifc-icon.' + key] = {
|
|
51
|
+
'-webkit-mask-image': 'url("' + svg + '")',
|
|
52
|
+
maskImage: 'url("' + svg + '")',
|
|
53
|
+
};
|
|
54
|
+
return acc;
|
|
55
|
+
}, {} as any),
|
|
56
|
+
};
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
With this approach, the same `ifc-icon` markup works even without a font file because each icon class points to an embedded SVG data URL.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Agent Rules for Adding Icons
|
|
64
|
+
|
|
65
|
+
- First try to reuse an existing icon class. Search app icon config files before inventing a new name.
|
|
66
|
+
- If adding package UI in `lupine.api`, keep the markup generic: `<i class='ifc-icon existing-icon-name'></i>`.
|
|
67
|
+
- If the target app uses generated fonts, add the source SVG to its `icons-font.config.js` and regenerate icons according to that app's process.
|
|
68
|
+
- If the target app uses embedded SVG masks, find its `app-icons.ts` file and add the new SVG entry to the `appIcons` map.
|
|
69
|
+
- Do not hardcode raw inline SVG in every package component unless there is a strong reason. Prefer the app-level icon provider so theming via `currentColor`, sizing, and consistency keep working.
|
|
70
|
+
- Do not assume all apps use the same icon backend. The contract is the CSS class interface (`ifc-icon` plus icon name), while the app decides whether that class is backed by a font or SVG masks.
|
|
71
|
+
- When reviewing missing icons, check whether the icon CSS was loaded by the target app before changing package code.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Mobile Layout & Interactions
|
|
2
|
+
|
|
3
|
+
## 1. Mobile Drill-Down Navigation (`SliderFrame`)
|
|
4
|
+
|
|
5
|
+
Lupine.js uses a slide-over model for multi-level navigation drill-down. **Important: Every child page capable of opening a deeper level must define its own independent `childSliderHook` and mount `<SliderFrame hook={childSliderHook} />` in JSX**. Do not reuse the parent hook, as doing so will replace the current view and destroy the back navigation stack.
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { HeaderWithBackFrame, SliderFrame, SliderFrameHookProps } from 'lupine.web.components';
|
|
9
|
+
|
|
10
|
+
// 1. Parent Component (Level 1, e.g., Home page)
|
|
11
|
+
const Parent = () => {
|
|
12
|
+
const sliderHook: SliderFrameHookProps = {};
|
|
13
|
+
|
|
14
|
+
const openDetail = (id: number) => {
|
|
15
|
+
sliderHook.load!(<DetailComponent id={id} parentSliderFrameHook={sliderHook} />);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div>
|
|
20
|
+
<SliderFrame hook={sliderHook} />
|
|
21
|
+
<button onClick={() => openDetail(1)}>Open Details (Level 2)</button>
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// 2. Child Component (Level 2, e.g., Settings page)
|
|
27
|
+
const DetailComponent = (props: { id: number; parentSliderFrameHook: SliderFrameHookProps }) => {
|
|
28
|
+
// ⭐️ Must define a brand new independent drill-down hook for this component:
|
|
29
|
+
const childSliderHook: SliderFrameHookProps = {};
|
|
30
|
+
|
|
31
|
+
const openDeeper = (id: number) => {
|
|
32
|
+
// ⭐️ Must use childSliderHook to load level 3 pages:
|
|
33
|
+
childSliderHook.load!(<DetailComponent id={id} parentSliderFrameHook={childSliderHook} />);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<HeaderWithBackFrame title='Detail Page' onBack={(e) => props.parentSliderFrameHook.close!(e)}>
|
|
38
|
+
<div>
|
|
39
|
+
{/* ⭐️ Must mount a new SliderFrame placeholder for level 3 display */}
|
|
40
|
+
<SliderFrame hook={childSliderHook} />
|
|
41
|
+
<button onClick={() => openDeeper(props.id + 1)}>Go to Next Level (Level 3)</button>
|
|
42
|
+
</div>
|
|
43
|
+
</HeaderWithBackFrame>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## 2. Mobile Dialogs & Interactive Prompts (Replacing Native Alert/Confirm)
|
|
51
|
+
|
|
52
|
+
**Strictly avoid browser-native `alert()`, `confirm()`, and `prompt()`**. Always use the Promise-based API from `lupine.web.components`:
|
|
53
|
+
|
|
54
|
+
1. **Option Selection / Confirmation (`ActionSheetSelectPromise`)**:
|
|
55
|
+
```typescript
|
|
56
|
+
import { ActionSheetSelectPromise } from 'lupine.web.components';
|
|
57
|
+
|
|
58
|
+
const index = await ActionSheetSelectPromise({
|
|
59
|
+
title: 'Are you sure you want to delete this record?',
|
|
60
|
+
options: ['Delete', 'Edit'],
|
|
61
|
+
cancelButtonText: 'Cancel',
|
|
62
|
+
});
|
|
63
|
+
if (index === 0) { /* User clicked Delete */ }
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
2. **Informational Message (`ActionSheetMessagePromise`)**:
|
|
67
|
+
```typescript
|
|
68
|
+
import { ActionSheetMessagePromise } from 'lupine.web.components';
|
|
69
|
+
|
|
70
|
+
await ActionSheetMessagePromise({
|
|
71
|
+
title: 'Notification',
|
|
72
|
+
message: 'Saved successfully!',
|
|
73
|
+
confirmButtonText: 'OK',
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
3. **User Text Input (`ActionSheetInputPromise`)**:
|
|
78
|
+
```typescript
|
|
79
|
+
import { ActionSheetInputPromise } from 'lupine.web.components';
|
|
80
|
+
|
|
81
|
+
const value = await ActionSheetInputPromise({
|
|
82
|
+
title: 'Enter nickname',
|
|
83
|
+
confirmButtonText: 'OK',
|
|
84
|
+
cancelButtonText: 'Cancel',
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## 3. Hardware Back Button & Close Gestures (`data-back-action`)
|
|
91
|
+
|
|
92
|
+
All close buttons, back chevrons, and overlay backdrop dismissals must bind:
|
|
93
|
+
```tsx
|
|
94
|
+
import { backActionHelper } from 'lupine.web.components';
|
|
95
|
+
|
|
96
|
+
const CloseButton = (props: { onClose: () => void }) => (
|
|
97
|
+
<i class='ifc-icon ma-close' data-back-action={backActionHelper.genBackActionId()} onClick={props.onClose}></i>
|
|
98
|
+
);
|
|
99
|
+
```
|
|
100
|
+
The framework automatically triggers a click event on the top-most active element when the user presses the hardware back button or performs an edge-swipe back gesture.
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# Native apps (lupine.native)
|
|
2
|
+
|
|
3
|
+
One TSX code base for iOS, Android, macOS, Windows and the web. The UI is made of the controls of each platform (Windows paints its own), the layout is flexbox (Yoga), JS runs in Hermes on the UI thread. Documentation: https://uuware.github.io/lupine.js/en/native/overview and https://uuware.github.io/lupine.js/en/native-components/overview.
|
|
4
|
+
|
|
5
|
+
## No DOM
|
|
6
|
+
|
|
7
|
+
- App code imports from `lupine.native.core` and `lupine.native.components` only. `document`, `window`, `localStorage`, `HTMLElement`, `lupine.web` and `lupine.web.components` are errors in a native bundle.
|
|
8
|
+
- Only the entry for the web (`src/index.web.tsx`, and `web.entries`) may use the DOM; `tsconfig.json` has no `dom` and excludes that file.
|
|
9
|
+
- `fetch`, `Headers`, `FormData`, `AbortController`, `URL`, `WebSocket`, `TextEncoder` and timers are there on all platforms. Packages of npm work if they need no DOM, `Blob` or `XMLHttpRequest`.
|
|
10
|
+
|
|
11
|
+
## An app
|
|
12
|
+
|
|
13
|
+
Start by copying `apps/native-starter` (tabs, pages, themes, languages, sign-in); `apps/native-demo` shows everything else.
|
|
14
|
+
|
|
15
|
+
```text
|
|
16
|
+
apps/my-app/
|
|
17
|
+
package.json name, version, "lupineNative": { name, title, id, entry, permissions, plugins, ... }
|
|
18
|
+
src/app.tsx the app
|
|
19
|
+
src/index.native.tsx runApp(App) from 'lupine.native.core/native'
|
|
20
|
+
src/index.web.tsx runApp(App) from 'lupine.native.core/web'
|
|
21
|
+
src/index.test.tsx runApp(App) and the tests
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
// src/app.tsx
|
|
26
|
+
import { createSignal, insets, Text, TextInput, View } from 'lupine.native.core';
|
|
27
|
+
import { Button, col, OverlayHost, Toast } from 'lupine.native.components';
|
|
28
|
+
|
|
29
|
+
export const App = () => {
|
|
30
|
+
const [name, setName] = createSignal('');
|
|
31
|
+
return (
|
|
32
|
+
<View style={{ flex: 1, padding: 16, gap: 12, paddingTop: () => insets().top + 16, backgroundColor: col('bg') }}>
|
|
33
|
+
<TextInput testID='name' value={name} onChangeText={setName} placeholder='Name' />
|
|
34
|
+
<Button title='Greet' kind='primary' disabled={() => !name()} onPress={() => Toast.success(`Hello ${name()}`)} />
|
|
35
|
+
<Text style={{ color: col('text') }}>{() => `${name().length} letters`}</Text>
|
|
36
|
+
<OverlayHost />
|
|
37
|
+
</View>
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Signals, `For`, `Show`, `onMount`, `onCleanup` work as on the web (references/reactivity-and-state.md) and come from `lupine.native.core`.
|
|
43
|
+
|
|
44
|
+
## Components (lupine.native.core)
|
|
45
|
+
|
|
46
|
+
| | |
|
|
47
|
+
| --- | --- |
|
|
48
|
+
| `View` | box; `onPress`, `onLongPress`, `onTouch={gesture({...})}`, `onLayout`, `pointerEvents` |
|
|
49
|
+
| `Text` | all text is inside `Text`; `numberOfLines`, `selectable` |
|
|
50
|
+
| `TextInput` | `value` (signal), `onChangeText`, `onSubmit`, `keyboardType`, `returnKey`, `secureTextEntry`, `multiline` |
|
|
51
|
+
| `ScrollView` | `horizontal`, `onScroll`, `refreshing`/`onRefresh` |
|
|
52
|
+
| `List` | many rows of one height (`items`, `itemHeight`); `VirtualList`, `SectionList`, `InfiniteList` in lupine.native.components |
|
|
53
|
+
| `Image`, `Icon`, `Svg`, `Canvas`, `GL` | pictures, icons, 2D drawing, WebGL 2 and three.js |
|
|
54
|
+
| `Video`, `WebView`, `Camera` | media |
|
|
55
|
+
| `Button`, `Switch`, `Slider` | the system's own controls; for one look on all platforms use those of lupine.native.components |
|
|
56
|
+
|
|
57
|
+
All of them: `style`, `ref` (`focus()`, `measure()`, `scrollTo()`), `testID`, `transition` (milliseconds).
|
|
58
|
+
|
|
59
|
+
## Styles
|
|
60
|
+
|
|
61
|
+
A style is an object; each value may be a function. Nothing is inherited and there are no style sheets: share constants and merge them (`{ ...card, opacity: () => ... }` or `style={[a, b]}`).
|
|
62
|
+
|
|
63
|
+
- Flexbox, **top to bottom** by default; numbers are density independent pixels; `flex: 1` takes what is left.
|
|
64
|
+
- `margin`/`padding` with `Horizontal`, `Vertical`, `Top` etc.; `gap`; `position: 'absolute'`; `display: 'none'`.
|
|
65
|
+
- Look: `backgroundColor`, `backgroundImage: 'linear-gradient(...)'`, `borderRadius`, `borderWidth`, `borderColor`, `boxShadow`, `opacity`, `translateX`, `scale`, `rotate`.
|
|
66
|
+
- What isn't supported is a TypeScript error (no `borderStyle: dashed`, no 3D transforms). Text widths differ a little between platforms: don't rely on where lines break.
|
|
67
|
+
- Safe areas: `insets()`; size of the window: `windowInfo()`; wide or narrow: `isWide()`, `Grid`, `Columns`, `ShowWhen`.
|
|
68
|
+
|
|
69
|
+
## Themes, languages (lupine.native.components)
|
|
70
|
+
|
|
71
|
+
- Colors: `col('bg')`, `col('bgElevated')`, `col('text')`, `col('primary')`, ... (functions, so they follow the theme). No fixed colors in components.
|
|
72
|
+
- `theme()`, `setThemePref('dark' | 'light' | 'system')`, `addThemes`, `deriveTheme`; `syncAppearance` lets the system's controls follow.
|
|
73
|
+
- Texts: `t('key')`, `setLanguages`, `setLang`; `<T>` is a `Text` with the theme's text color.
|
|
74
|
+
|
|
75
|
+
## Pages and navigation
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
import { Show, View } from 'lupine.native.core';
|
|
79
|
+
import { BottomTabBar, col, isWide, NavItem, OverlayHost, Pages, router, Row, Screen, Section, Sidebar } from 'lupine.native.components';
|
|
80
|
+
|
|
81
|
+
const items: NavItem[] = [
|
|
82
|
+
{ key: '/', label: 'Home', icon: 'home', testID: 'tab-home' },
|
|
83
|
+
{ key: '/me', label: 'Me', icon: 'user', testID: 'tab-me' },
|
|
84
|
+
];
|
|
85
|
+
const Home = () => (
|
|
86
|
+
<Screen title='Home' grouped>
|
|
87
|
+
<Section>
|
|
88
|
+
<Row label='First' onPress={() => router.push('/item/1')} />
|
|
89
|
+
</Section>
|
|
90
|
+
</Screen>
|
|
91
|
+
);
|
|
92
|
+
const Me = () => <Screen title='Me' padded />;
|
|
93
|
+
const Item = (p: { id: string }) => <Screen title={`#${p.id}`} onBack={router.back} padded />;
|
|
94
|
+
|
|
95
|
+
export const App = () => (
|
|
96
|
+
<View style={{ flex: 1, flexDirection: 'row', backgroundColor: col('bg') }}>
|
|
97
|
+
<Show when={isWide}>
|
|
98
|
+
<Sidebar items={items} active={router.tab} onPress={router.navigate} />
|
|
99
|
+
</Show>
|
|
100
|
+
<Pages
|
|
101
|
+
tabs={[{ path: '/', page: Home }, { path: '/me', page: Me }]}
|
|
102
|
+
routes={[{ path: '/item/:id', page: (p) => <Item id={p.id} /> }]}
|
|
103
|
+
notFound={() => <Screen title='404' onBack={router.back} />}
|
|
104
|
+
>
|
|
105
|
+
<Show when={() => !isWide()}>
|
|
106
|
+
<BottomTabBar items={items} active={router.tab} onPress={router.navigate} />
|
|
107
|
+
</Show>
|
|
108
|
+
</Pages>
|
|
109
|
+
<OverlayHost />
|
|
110
|
+
</View>
|
|
111
|
+
);
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
- `router.push(path, params?)`, `router.replace`, `router.back()`, `router.navigate(tab)`, `router.path()`, `router.tab()`, `useFocused()`.
|
|
115
|
+
- Tabs are kept; a stacked page is removed when one goes back and its `onCleanup` runs.
|
|
116
|
+
- The Android back button: `onBack(() => ...)`, newest first; return `false` to pass it on.
|
|
117
|
+
|
|
118
|
+
## Messages and panels
|
|
119
|
+
|
|
120
|
+
- `Toast.success('Saved')`, `await MessageBox.confirm({...})`, `await ActionSheet.select({...})`, `Loading.during(promise)`. Questions to the user are bottom action sheets, not alerts.
|
|
121
|
+
- `BottomSheet`, `Dialog`, `SlidePanel`, `DrawerLayout`: opened and closed by a signal (`visible={() => open()}`).
|
|
122
|
+
- They need `<OverlayHost />`, as the last child of the root.
|
|
123
|
+
|
|
124
|
+
## Forms
|
|
125
|
+
|
|
126
|
+
`createForm`, `Field`, `TextField`, `Select`, `DatePicker` and other pickers of lupine.native.components (`apps/doc/.../native-components/forms.md`). A single value is a signal with `TextInput value={v} onChangeText={setV}`.
|
|
127
|
+
|
|
128
|
+
## Platform functions (lupine.native.core)
|
|
129
|
+
|
|
130
|
+
`Platform.OS` (`'ios' | 'android' | 'macos' | 'windows' | 'web'`), `Platform.select({...})`; `storage` (synchronous key/value), `secureStorage`, `files`, `clipboard`, `share`, `pickFiles`, `pickImages`, `Camera`, `geolocation`, `notifications`, `haptics`, `createAudioContext`, `requestPermission`, `deviceInfo`, `appState`, `openURL`, `onURL`, `desktop` and `startProcess` (desktops only). Look up the exact names in the docs before using one.
|
|
131
|
+
|
|
132
|
+
Files for one platform: `name.ios.tsx` before `name.native.tsx` before `name.tsx`; the web takes `name.web.tsx`.
|
|
133
|
+
|
|
134
|
+
Plugins (sign-in, payments, ads, ...): `lupine.native.plugins/<name>`, switched on in `lupineNative.plugins`, often only in a variant (`--variant=...`).
|
|
135
|
+
|
|
136
|
+
## The command line
|
|
137
|
+
|
|
138
|
+
In the repository `npm run native -- ...`, in a project `npx lupine-native ...`:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
npx lupine-native doctor # what is missing for which platform
|
|
142
|
+
npx lupine-native web --app=apps/my-app --watch
|
|
143
|
+
npx lupine-native macos --app=apps/my-app --run # ios, android, windows the same
|
|
144
|
+
npx lupine-native ios --app=apps/my-app --run --device --serial=<udid> --team=<team>
|
|
145
|
+
npx lupine-native android --app=apps/my-app --run --serial=<adb device>
|
|
146
|
+
npx lupine-native windows --app=apps/my-app --run # on a Mac or Linux --run opens it in Wine
|
|
147
|
+
npx lupine-native docker android --app=apps/my-app # builds in Docker, nothing installed
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Options: `--release`, `--variant=<name>`, `--define=NAME=value`, `--engine=quickjs` (smaller, slower). The result is in `dist/native/<app>/<platform>`.
|
|
151
|
+
|
|
152
|
+
## Tests
|
|
153
|
+
|
|
154
|
+
`src/index.test.tsx` drives real controls through `__lupine.test(testID, action, argument)` and prints `TEST ok name`, `TEST FAIL name`, then `TEST RESULT PASSED n ok`.
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
npx lupine-native test macos --app=apps/my-app
|
|
158
|
+
npx lupine-native test android --app=apps/my-app --serial=<adb device>
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
The app id gets `.test`, so the data of the released app isn't touched. After a change, run the tests of the platforms it affects; `tsc --noEmit -p apps/my-app` finds DOM use and wrong styles.
|
|
162
|
+
|
|
163
|
+
## The web target
|
|
164
|
+
|
|
165
|
+
`lupine-native web` makes a static site (DOM, CSS flexbox). `renderToString` of `lupine.native.core/web/server` renders it on a server, with limits: effects don't run, async components are left out (load the data first and pass it as props), and the browser replaces that HTML (no hydration).
|
|
166
|
+
|
|
167
|
+
Native components in a page of lupine.web: both share the same signals, so a web component can host one with `onMount(() => onCleanup(runApp(Chart, box)))`, `runApp` from `lupine.native.core/web`.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Router, SSR and settings (web)
|
|
2
|
+
|
|
3
|
+
Documentation: https://uuware.github.io/lupine.js/en/essentials/page-route, https://uuware.github.io/lupine.js/en/essentials/ssr.
|
|
4
|
+
|
|
5
|
+
## PageRouter
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { bindRouter, PageProps, PageRouter } from 'lupine.web';
|
|
9
|
+
|
|
10
|
+
const HomePage = async () => <h1>Home</h1>;
|
|
11
|
+
const PlayPage = async (props: PageProps) => <p>{props.urlParameters['id']} {props.query['tab']}</p>;
|
|
12
|
+
const NotFoundPage = async () => <h1>404</h1>;
|
|
13
|
+
|
|
14
|
+
const pageRouter = new PageRouter();
|
|
15
|
+
pageRouter.use('/', HomePage);
|
|
16
|
+
pageRouter.use('/play/:id', PlayPage);
|
|
17
|
+
pageRouter.use('*', NotFoundPage); // last
|
|
18
|
+
bindRouter(pageRouter); // in index.tsx
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
- Routes are tried in order; `/about` also matches `/about/...`, so specific paths come first.
|
|
22
|
+
- `/:id` required, `/?id` optional (and everything after it); the first parameter of a path is a `/:` one; fixed segments may follow (`/page/:id/detail`).
|
|
23
|
+
- A page gets `PageProps`: `url`, `query`, `urlParameters`, `renderPageFunctions`. It may be async; `null` passes to the next route.
|
|
24
|
+
- Nested routers: `pageRouter.use('/user', userRouter)`. Filters: `userRouter.setFilter(checkAuth)` or `use(path, checkAuth, Page)`; a filter returns a node to show instead, or `null`. They only decide what is shown: the API checks access to data.
|
|
25
|
+
- Layout: `pageRouter.setFramePage({ component: MainFrame, placeholderClassname: 'app-content' })`; only the placeholder is replaced, the frame keeps its state.
|
|
26
|
+
- `setErrorHandler`, `setSubDir('/my-app')` for a site in a subfolder.
|
|
27
|
+
|
|
28
|
+
## Going to a page
|
|
29
|
+
|
|
30
|
+
Links inside the site are `<a href='/play/1'>` and don't reload the page. From code:
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
import { initializePage } from 'lupine.web';
|
|
34
|
+
|
|
35
|
+
const Next = () => <button onClick={() => initializePage('/play/2')}>Next</button>;
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Not `location.href = ...` (that reloads everything).
|
|
39
|
+
|
|
40
|
+
## SSR
|
|
41
|
+
|
|
42
|
+
For every URL that isn't an API or a file the server runs the router and sends complete HTML (with theme, styles, title and meta tags). The browser then renders the same route again and **replaces** the content; there is no hydration.
|
|
43
|
+
|
|
44
|
+
- Data that belongs in the HTML: load it in the async page with `props.renderPageFunctions.fetchData(url)` (on the server it calls the API inside the process, with the request's cookies). Title and meta: `PageTitle`, `MetaData` of `lupine.web.components`.
|
|
45
|
+
- Only the browser: `localStorage`, window sizes, `document`, data of the signed-in user. Put it in `onMount`, or check `isFrontEnd()`. Code that runs while rendering must not touch them.
|
|
46
|
+
- `createEffect` and `onMount` don't run on the server; signals are read once.
|
|
47
|
+
- Module variables and signals are shared by all users on the server.
|
|
48
|
+
- Styles at the top of a module: `bindAppGlobalStyle`; `bindGlobalStyle` belongs inside a component (references/styling-and-themes.md).
|
|
49
|
+
- Where there are no props: `getRenderPageProps()` gives `url` and `query`.
|
|
50
|
+
|
|
51
|
+
## Settings
|
|
52
|
+
|
|
53
|
+
- `.env` variables that start with `WEB.` reach the front end: `webEnv('API_BASE_URL', '')` (synchronous; the type follows the default). All others stay on the server.
|
|
54
|
+
- Settings that change without a release: `await WebConfig.get('siteLogo', '')`. The server puts them into the first page; written by the back end (`apiStorage.setWeb`).
|