create-lupine 1.0.30 → 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 +35 -13
- 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 +12 -2
- package/templates/common/apps/server/src/index.ts +2 -1
- 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
|
@@ -1,1002 +0,0 @@
|
|
|
1
|
-
# AI Context for Lupine.js
|
|
2
|
-
|
|
3
|
-
**[CRITICAL SAFEGUARDS FOR CODE MODIFICATION]**
|
|
4
|
-
When performing multi-line code refactoring or replacement operations (`replace_file_content` / `multi_replace_file_content`), massive block-level overwrites and arbitrary code restructuring are **STRICTLY PROHIBITED**!
|
|
5
|
-
|
|
6
|
-
- Before making any modifications, you MUST invoke `view_file` or `grep_search` to verify the exact, up-to-date file structure and line numbers.
|
|
7
|
-
- The `StartLine` and `EndLine` range MUST be restricted strictly to the absolute minimum lines you intend to modify or delete.
|
|
8
|
-
- If you are merely inserting new code (e.g., adding a button or appending logic), target ONLY the immediately preceding line or bracket as your anchor. You are strictly forbidden from wrapping innocent, unmodified surrounding code into the `Replacement` payload. Violating this red line causes severe production accidents!
|
|
9
|
-
|
|
10
|
-
**SYSTEM ROLE**: You are an expert developer in `lupine.js`, a custom TypeScript full-stack framework.
|
|
11
|
-
|
|
12
|
-
**🛑 CRITICAL WARNINGS 🛑**
|
|
13
|
-
|
|
14
|
-
1. **`useState` EXISTS but rerenders the whole component**: Use it for simple/small components. For complex or large components, prefer `HtmlVar` for surgical, partial updates. **WARNING**: Because `useState` causes the entire parent component to re-render, any uncontrolled inner components/DOM elements that haven't explicitly saved their transient state will be abruptly reset to their default props. If you encounter bugs where interactive components (like toggles, inputs, animations) unexpectedly revert to their original state and lose data upon clicking or typing elsewhere, always check if a `useState` trigger in the parent is causing an unintended full reload.
|
|
15
|
-
2. **NO VIRTUAL DOM STATE by default**: Without `useState`, changing a variable DOES NOT re-render the component. You must manually update `HtmlVar.value`.
|
|
16
|
-
3. **NO CONTROLLED INPUTS**: Do not bind `value={state}`. Read values from DOM on submit.
|
|
17
|
-
|
|
18
|
-
---
|
|
19
|
-
|
|
20
|
-
## 1. Core Philosophy & Reactivity
|
|
21
|
-
|
|
22
|
-
- **`useState` — React-style local state (small/simple components)**:
|
|
23
|
-
|
|
24
|
-
- Import: `import { useState } from 'lupine.components';`
|
|
25
|
-
- Syntax: `const [value, setValue] = useState(initial);` — calling `setValue(...)` rerenders the **entire** component.
|
|
26
|
-
- ✅ **Use when**: The component is small, state drives most of the UI, and the React-style patterns feel natural.
|
|
27
|
-
- ⚠️ **Avoid when**: The component is large/complex, or only a tiny portion of the UI needs to change (e.g. a progress counter, a list inside a page) — repeated full rerenders are wasteful.
|
|
28
|
-
- **`ref.onLoad` + useState**: `onLoad` is called **only on initial mount** (not on rerenders). It's the right place for async data fetch that populates state.
|
|
29
|
-
- **Async component functions**: Component functions **can be `async`** — the framework detects the returned Promise and `await`s it. This lets you `await fetch()` directly inside a component body. However, **all `useState()` calls MUST appear before the first `await`**. The internal `_currentStore` pointer is cleared immediately after the synchronous portion of the component executes (before any `await`), so calling `useState()` after an `await` will throw `"useState must be called inside a component function"`.
|
|
30
|
-
|
|
31
|
-
```tsx
|
|
32
|
-
// ✅ Correct: useState before await
|
|
33
|
-
const MyComp = async (props) => {
|
|
34
|
-
const [data, setData] = useState(null); // hooks first
|
|
35
|
-
const result = await fetchData(); // await after hooks
|
|
36
|
-
return <div>{result.title}</div>;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// ❌ Wrong: useState after await — will crash
|
|
40
|
-
const MyComp = async (props) => {
|
|
41
|
-
const result = await fetchData(); // await first
|
|
42
|
-
const [data, setData] = useState(null); // 💥 _currentStore is null
|
|
43
|
-
return <div>{result.title}</div>;
|
|
44
|
-
};
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
- **`HtmlVar` — Surgical partial updates (large/complex components)**:
|
|
48
|
-
|
|
49
|
-
- Use `HtmlVar` to wrap dynamic sections (lists, conditional renderings, async content).
|
|
50
|
-
- **Pattern**: `const dom = new HtmlVar(initialContent);` → JSX `{dom.node}` → `dom.value = updatedContent`.
|
|
51
|
-
- ✅ **Use when**: Only a small part of a large component changes (e.g. list inside a page, progress text), or state is updated by external hooks (`props.hook.onProgress`), or high-frequency updates (file upload progress).
|
|
52
|
-
- The rest of the component DOM is never touched — highly efficient.
|
|
53
|
-
|
|
54
|
-
- **Direct DOM Access**:
|
|
55
|
-
- Use `RefProps` to get reference to the component root.
|
|
56
|
-
- Use `ref.$(selector)` to find the first element, `ref.$all(selector)` to find all elements (inputs, containers).
|
|
57
|
-
- **Value Retrieval**: `const val = ref.$('input.my-class').value`.
|
|
58
|
-
|
|
59
|
-
## 2. Key Interfaces
|
|
60
|
-
|
|
61
|
-
### `RefProps` (Lifecycle & DOM)
|
|
62
|
-
|
|
63
|
-
```typescript
|
|
64
|
-
const ref: RefProps = {
|
|
65
|
-
// Mounted: Initialize data, timers, events
|
|
66
|
-
onLoad: async (el: Element) => {
|
|
67
|
-
await loadData();
|
|
68
|
-
// ref.$('.sub-element').addEventListener(...)
|
|
69
|
-
},
|
|
70
|
-
// Unmounting: Cleanup
|
|
71
|
-
onUnload: async (el: Element) => {
|
|
72
|
-
// Cleanup (timers, sockets)
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
// Usage
|
|
76
|
-
<div ref={ref}>...</div>;
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### `CssProps` (Styling)
|
|
80
|
-
|
|
81
|
-
Supports nesting and media queries. **Prefer this over inline styles.** Define your styles in a `CssProps` object and bind them to the component's root JSX using the `css={css}` property. Use the `&` ampersand pattern (explained below) to guarantee unique class scoping.
|
|
82
|
-
|
|
83
|
-
## 3. Styles & Themes ("The Look")
|
|
84
|
-
|
|
85
|
-
### Global Variables (Theming) & Dark Mode Compatibility
|
|
86
|
-
|
|
87
|
-
**NEVER hardcode colors** (e.g., `#000`, `#fff`, `#f0f0f0`). Always use CSS variables to support Dark/Light modes. If you must use a fallback, wrap it: `var(--primary-bg-color, #fff)`.
|
|
88
|
-
|
|
89
|
-
**Defining Variables for Modes in CSS-in-JS**:
|
|
90
|
-
Since Lupine.js uses a CSS-in-JS styling approach, when you need to define or override CSS variables specifically for light and dark modes within a component, use the `[data-theme="light" i]` and `[data-theme="dark" i]` selectors. **CRITICAL**: Because `CssProps` scopes styles by default, you MUST separate these mode styles into their own object and bind them using `bindGlobalStyle` with `noTopClassName = true` (the 4th argument).
|
|
91
|
-
|
|
92
|
-
```typescript
|
|
93
|
-
// 1. Separate theme variables into their own CSS object
|
|
94
|
-
const cssTheme: CssProps = {
|
|
95
|
-
'[data-theme="light" i]': {
|
|
96
|
-
'--my-comp-bg-color': '#e6e6e6',
|
|
97
|
-
},
|
|
98
|
-
'[data-theme="dark" i]': {
|
|
99
|
-
'--my-comp-bg-color': 'var(--primary-accent-color)',
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
// 2. Bind globally. Param 4 (noTopClassName) MUST be true to prevent injecting a namespace prefix.
|
|
103
|
-
bindGlobalStyle('my-comp-theme', cssTheme, false, true);
|
|
104
|
-
|
|
105
|
-
// 3. Use the variable in your standard component styles
|
|
106
|
-
const css: CssProps = {
|
|
107
|
-
'.&-element': {
|
|
108
|
-
backgroundColor: 'var(--my-comp-bg-color)',
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
// Bind your component styles normally
|
|
112
|
-
bindGlobalStyle('my-comp-main', css);
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
#### 🎨 Color Variable Semantics (CRITICAL FOR DARK MODE)
|
|
116
|
-
|
|
117
|
-
1. **Backgrounds (`--primary-bg-color` vs `--secondary-bg-color`)**:
|
|
118
|
-
- `--primary-bg-color`: The lowest-level background (White in light mode, **Deep Black** in dark mode).
|
|
119
|
-
- `--secondary-bg-color`: An elevated background (Light gray in light mode, **Lighter Black/Gray** in dark mode).
|
|
120
|
-
- _⚠️ Dark Mode Trap_: If you place a floating panel/card on the main body, **do NOT** use `--primary-bg-color` for the panel. It will blend into the body's deep black and become invisible. Use `--secondary-bg-color` for elevated panels to ensure visual separation.
|
|
121
|
-
2. **Text Colors (`--primary-color` vs `--secondary-color`)**:
|
|
122
|
-
- `--primary-color`: The primary **TEXT** color. (Dark grey/black in light mode, **White** in dark mode).
|
|
123
|
-
- _⚠️ Dark Mode Trap_: **Never** use `--primary-color` as the background color for a blue "Primary Action Button". It will turn white in dark mode.
|
|
124
|
-
- Always explicitly declare `color: 'var(--primary-color, inherit)'` on cards/containers so child text properly flips white in dark mode.
|
|
125
|
-
3. **Action / Brand Colors (`--primary-accent-color`)**:
|
|
126
|
-
- `--primary-accent-color`: The vibrant brand color (e.g., Lupine Blue). Use this for the **backgrounds of primary buttons**, active tabs, slider fills, and highlights.
|
|
127
|
-
- When using this as a background, set the text color to `var(--primary-bg-color)` so it stays high-contrast (white) in both themes.
|
|
128
|
-
4. **Borders (`--primary-border` / `--secondary-border-color`)**:
|
|
129
|
-
- Replace all hardcoded `#eee`, `#ccc`, `#999` borders with these to ensure they darken appropriately in dark mode.
|
|
130
|
-
5. **Status Colors**:
|
|
131
|
-
- `--success-color`, `--warning-color`, `--error-color`, `--success-bg-color` (Use replacing hardcoded green/reds).
|
|
132
|
-
6. **Spacing**: `var(--space-m)` (8px), `var(--space-l)` (16px).
|
|
133
|
-
|
|
134
|
-
### Standard Utility Classes
|
|
135
|
-
|
|
136
|
-
- **Flexbox**: `.row-box` (flex row, align-center), `.col` (flex: 1).
|
|
137
|
-
- **Margins/Padding**: `m-auto`, `p-m`, `mt-s`, `pb-l` (s=small, m=medium, l=large).
|
|
138
|
-
- **Text**: `.text-center`, `.ellipsis`.
|
|
139
|
-
|
|
140
|
-
### The Component CSS & Ampersand (`&`) Pattern (must go with RefProps)
|
|
141
|
-
|
|
142
|
-
Lupine.js handles component-scoped CSS safely to avoid class collisions. The modern and **preferred** way to style components is to attach a `css={css}` prop to the root element and use the **Ampersand (`&`) Pattern**.
|
|
143
|
-
|
|
144
|
-
When Lupine renders the component, it generates a unique ID (e.g., `l1234`) and replaces the `&` with this ID everywhere it's used.
|
|
145
|
-
|
|
146
|
-
```typescript
|
|
147
|
-
export const MyComponent = () => {
|
|
148
|
-
const ref: RefProps = {
|
|
149
|
-
onLoad: async () => {
|
|
150
|
-
// 3. Querying namespaced elements
|
|
151
|
-
const btn = ref.$('.&-btn');
|
|
152
|
-
btn.innerHTML = 'Ready';
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
const css: CssProps = {
|
|
157
|
-
// Top-level rules apply to the root component container itself
|
|
158
|
-
width: '100%',
|
|
159
|
-
padding: '1rem',
|
|
160
|
-
|
|
161
|
-
// 1. Defining namespaced sub-classes in CSS:
|
|
162
|
-
'.&-title': { fontWeight: 'bold' },
|
|
163
|
-
'.&-btn': {
|
|
164
|
-
// Nesting pseudo-classes and combination modifiers (no space after &)
|
|
165
|
-
'&:hover': { background: '#f0f0f0' },
|
|
166
|
-
'&.active': { color: 'var(--primary-accent-color)' },
|
|
167
|
-
},
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
return (
|
|
171
|
-
// Setting css={css} safely bounds this style scope
|
|
172
|
-
<aside css={css} ref={ref}>
|
|
173
|
-
{/* 2. Applying namespaced classes in JSX */}
|
|
174
|
-
<div class='&-title'>Hello</div>
|
|
175
|
-
<button class='&-btn active'>Click Me</button>
|
|
176
|
-
</aside>
|
|
177
|
-
);
|
|
178
|
-
};
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
**Key Takeaways for `&` and `RefProps`**:
|
|
182
|
-
|
|
183
|
-
1. **In `CssProps` Binding**: The top-level keys in `CssProps` (like `display: 'flex'`) apply **directly** to the root element (the one attached to `ref={ref}`). **Do not** wrap your root styles in an artificial `.&-container`.
|
|
184
|
-
- `'&.active'` applies to the root element when it has the `.active` native class.
|
|
185
|
-
- `'.&-item'` applies to _descendant_ elements that have `class="&-item"`.
|
|
186
|
-
2. **In JSX `class` attributes**: Add `class="&-item"`. You can still mix native classes: `class="row-box &-item"`.
|
|
187
|
-
3. **In DOM Queries**:
|
|
188
|
-
- **🚨 NEVER use `document.querySelector('.&-item')` or `element.querySelector('.&-item')`**. Standard browser APIs DO NOT understand the `&` symbol and will fail to find the element.
|
|
189
|
-
- Use **`ref.$('.&-item')`** (WITH leading dot) to get the first matching element. The underlying logic replaces `&` with the generated CSS ID, so this correctly translates to querying `.l1234 .l1234-item` which safely finds descendants within the current component's isolated namespace.
|
|
190
|
-
- Use **`ref.$all('.&-item')`** to get a `NodeList` of all matching descendants within the component.
|
|
191
|
-
|
|
192
|
-
## 4. CSS Placement Strategies & Sharing Scopes
|
|
193
|
-
|
|
194
|
-
Lupine.js handles CSS scoping by generating unique IDs and replacing the `&` symbol in class names. Depending on where your components live, you have three strategies for sharing this CSS scope.
|
|
195
|
-
|
|
196
|
-
### 4.1 Sharing CSS inside a method (Component Level)
|
|
197
|
-
|
|
198
|
-
**Best for**: Complex components or pages where you define a single `const css: CssProps` and share it across sub-components rendered in the same function.
|
|
199
|
-
|
|
200
|
-
When you assign `css={css}` to the root element, a unique ID is generated (e.g., `l01`).
|
|
201
|
-
|
|
202
|
-
1. **Automatic Inheritance**: The top node's CSS ID will be automatically inherited by all descendant nodes in most cases. You **do not** need to pass it manually.
|
|
203
|
-
2. **HtmlVar Support**: Detached DOMs rendered via `HtmlVar` now automatically inherit the CSS ID of the element they are mounted into!
|
|
204
|
-
3. **Explicit Linking (`referToCssId`)**: The **ONLY** time the inheritance chain is broken is when a sub-component defines its OWN `css` property (which creates a new CSS scope). If you want descendants of that sub-component to still use the top parent's CSS ID instead of the new one, you must explicitly pass `referToCssId`.
|
|
205
|
-
|
|
206
|
-
```tsx
|
|
207
|
-
import { domUniqueId, HtmlVar, RefProps, CssProps } from 'lupine.components';
|
|
208
|
-
|
|
209
|
-
export const TestCssShareInside = () => {
|
|
210
|
-
const cssInner: CssProps = {
|
|
211
|
-
// Top-level rules apply to the root component
|
|
212
|
-
display: 'flex',
|
|
213
|
-
'.&-content': { color: 'red' },
|
|
214
|
-
'.&-sub-title': { fontWeight: 'bold' },
|
|
215
|
-
'.&-list-item': { color: 'blue' }
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
const ref: RefProps = { id: domUniqueId() };
|
|
219
|
-
|
|
220
|
-
// Example of a detached DOM using HtmlVar.
|
|
221
|
-
// It automatically inherits the CSS ID when mounted inside the component!
|
|
222
|
-
const listDom = new HtmlVar('');
|
|
223
|
-
const renderList = () => {
|
|
224
|
-
listDom.value = (
|
|
225
|
-
<div class='&-list'>
|
|
226
|
-
<div class='&-list-item'>HtmlVar List Item</div>
|
|
227
|
-
</div>
|
|
228
|
-
);
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const SubContent1 = () => {
|
|
232
|
-
const ref2: RefProps = { onLoad: async () => {} };
|
|
233
|
-
// This sub-component only has a ref, so it naturally inherits the parent's css ID!
|
|
234
|
-
return <div ref={ref2} class='&-sub-top'>Sub component without css.</div>;
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
const SubContent2 = (props: { children: VNode<any> }) => {
|
|
238
|
-
// ⚠️ This sub-component has its own `css`, which would break inheritance!
|
|
239
|
-
const css2: CssProps = { color: 'blue' };
|
|
240
|
-
const ref2: RefProps = {
|
|
241
|
-
// So we MUST explicitly link it using referToCssId if we still want parent's css id.
|
|
242
|
-
referToCssId: ref.id,
|
|
243
|
-
onLoad: async () => renderList()
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
return (
|
|
247
|
-
<div ref={ref2} css={css2} class='&-sub-top'>
|
|
248
|
-
<div class='&-sub-title'>Sub component with its own css.</div>
|
|
249
|
-
{listDom.node}
|
|
250
|
-
{props.children}
|
|
251
|
-
</div>
|
|
252
|
-
);
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
return (
|
|
256
|
-
// 1. Assign css to the top node.
|
|
257
|
-
<div ref={ref} css={cssInner}>
|
|
258
|
-
{/* 2. Normal elements automatically inherit the CSS ID */}
|
|
259
|
-
<div class='&-content'>Content</div>
|
|
260
|
-
|
|
261
|
-
{/* 3. SubContent1 automatically inherits */}
|
|
262
|
-
<SubContent1 />
|
|
263
|
-
|
|
264
|
-
{/* 4. SubContent2 explicitly overrides inheritance internally */}
|
|
265
|
-
<SubContent2>
|
|
266
|
-
<div class='&-sub'>Passed as parameter</div>
|
|
267
|
-
</SubContent2>
|
|
268
|
-
</div>
|
|
269
|
-
);
|
|
270
|
-
};
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
### 4.2 Sharing CSS between components (Module Level)
|
|
274
|
-
|
|
275
|
-
**Best for**: Reusable UI components (Buttons, Modals, List Items) that are rendered multiple times across the application, or when sharing a common style block between a few specific components.
|
|
276
|
-
|
|
277
|
-
If you render 100 items using `css={}`, it injects 100 identical `<style>` blocks. To avoid this bloat, use `bindGlobalStyle` to inject the `<style>` block exactly once into the `<head>`, and share its ID using `referToCssId`.
|
|
278
|
-
|
|
279
|
-
**How to share:**
|
|
280
|
-
1. Define the CSS outside or inside of the component method.
|
|
281
|
-
2. Inside the component, get the ID and bind it globally using `bindGlobalStyle()`.
|
|
282
|
-
3. Assign `referToCssId` to the root element's `ref`, **and** add the `globalCssId` to the tag's `class` attribute.
|
|
283
|
-
```tsx
|
|
284
|
-
// 1. Define shared CSS
|
|
285
|
-
const cssShared: CssProps = {
|
|
286
|
-
display: 'flex',
|
|
287
|
-
'.&-content': { color: 'red' },
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
export const TestGlobalCss = () => {
|
|
291
|
-
// 2. Get the unique ID and bind it globally (only happens once)
|
|
292
|
-
// By default, noTopClassName is false, meaning the globalCssId will be prefixed to top level selectors (e.g., '.g00 .g00-content').
|
|
293
|
-
const globalCssId = getGlobalStylesId(cssShared);
|
|
294
|
-
bindGlobalStyle(globalCssId, cssShared);
|
|
295
|
-
|
|
296
|
-
return (
|
|
297
|
-
// 3. Assign referToCssId AND manually add the globalCssId as a class name!
|
|
298
|
-
// Since bindGlobalStyle added `.g00` to the selectors, we MUST add `g00` to the top tag.
|
|
299
|
-
<div ref={{ referToCssId: globalCssId }} class={globalCssId}>
|
|
300
|
-
{/* & is automatically replaced by globalCssId */}
|
|
301
|
-
<div class='&-content'>Share CSS cross components</div>
|
|
302
|
-
</div>
|
|
303
|
-
);
|
|
304
|
-
};
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
### 4.3 The `noTopClassName` Parameter
|
|
308
|
-
|
|
309
|
-
When using `bindGlobalStyle` or `bindAppGlobalStyle`, the `noTopClassName` parameter (4th argument) dictates how top-level CSS selectors are compiled.
|
|
310
|
-
|
|
311
|
-
- **`noTopClassName = false` (Default)**:
|
|
312
|
-
`bindGlobalStyle(globalCssId, cssShared)` will prepend the ID to all top-level selectors.
|
|
313
|
-
If `cssShared` is `{ '.selector-1': {} }` and `globalCssId` is `g00`, it compiles to:
|
|
314
|
-
`'.g00 .selector-1' { ... }`
|
|
315
|
-
This is why you **must** add `class={globalCssId}` to the top tag. In this mode, `cssShared` can also contain styles applied directly to the top tag (e.g., `display: 'flex'`).
|
|
316
|
-
|
|
317
|
-
- **`noTopClassName = true`**:
|
|
318
|
-
`bindGlobalStyle(globalCssId, cssShared, false, true)` will NOT prepend the ID.
|
|
319
|
-
It compiles to:
|
|
320
|
-
`'.selector-1' { ... }`
|
|
321
|
-
In this mode, you **cannot** define top-level styles directly on the root component without a selector, and you **do not** need to add `globalCssId` to the top tag's class name.
|
|
322
|
-
|
|
323
|
-
> [!WARNING]
|
|
324
|
-
> Because `bindGlobalStyle` injects your `<style>` tags into the `<head>` globally, your `CssProps` definition **MUST** be entirely static. Do not put variables (like `size` or `color`) directly inside the `CssProps` object structure.
|
|
325
|
-
|
|
326
|
-
### 4.4 Sharing CSS at application level (Global Scope)
|
|
327
|
-
|
|
328
|
-
**Best for**: True global styles like general utility classes, typography, or theme-wide resets.
|
|
329
|
-
|
|
330
|
-
In this case, you define an application-level CSS block and add it to the header when the app initializes.
|
|
331
|
-
|
|
332
|
-
- You **cannot** use the `&` ampersand to represent a dynamic unique ID prefix (like `&-content`). However, you **can** still use `&` in nested structures to refer to the parent selector (e.g., `&.title` compiles to `.app-header.title`), though explicitly using absolute selectors is generally recommended for clarity.
|
|
333
|
-
- You do not need to pass `referToCssId`. You just use the standard global class names in your JSX.
|
|
334
|
-
|
|
335
|
-
```tsx
|
|
336
|
-
// 1. Define the shared CSS with absolute selectors
|
|
337
|
-
export const appSharedCss = {
|
|
338
|
-
'.app-header': {
|
|
339
|
-
fontSize: '14px',
|
|
340
|
-
// Using & here refers to the parent selector (.app-header),
|
|
341
|
-
// resulting in .app-header.title
|
|
342
|
-
'&.title': { fontSize: '24px' },
|
|
343
|
-
},
|
|
344
|
-
'.app-warning-color': { color: 'red' },
|
|
345
|
-
};
|
|
346
|
-
|
|
347
|
-
// 2. Add this in your app's initialization (e.g., index.tsx)
|
|
348
|
-
// The 4th parameter (noTopClassName = true) is critical here!
|
|
349
|
-
bindAppGlobalStyle('app-shared-css', appSharedCss, false, true);
|
|
350
|
-
|
|
351
|
-
// 3. Use it anywhere
|
|
352
|
-
export const AnyComponent = () => (
|
|
353
|
-
// Use the absolute class names directly
|
|
354
|
-
<div class="app-header title">Hello</div>
|
|
355
|
-
);
|
|
356
|
-
```
|
|
357
|
-
|
|
358
|
-
### 4.5 Using `&` on Top-Level Tags
|
|
359
|
-
|
|
360
|
-
When there is a special need to use an `&-` class prefix on a top-level tag, use the `&.&-box` syntax. The standalone `&` selector is replaced by the CSS ID automatically generated for this top-level tag.
|
|
361
|
-
For instance, `"&.&-box"` compiles to `"l01.l01-box"`.
|
|
362
|
-
|
|
363
|
-
```typescript
|
|
364
|
-
export const Component1 = () => {
|
|
365
|
-
const css: CssProps = {
|
|
366
|
-
color: 'red',
|
|
367
|
-
'&.&-box': { fontWeight: 'bold' },
|
|
368
|
-
'&.&-box .&-item': { backgroundColor: 'blue' },
|
|
369
|
-
};
|
|
370
|
-
const gCssId = getGlobalStylesId(css);
|
|
371
|
-
bindGlobalStyle(gCssId, css);
|
|
372
|
-
|
|
373
|
-
const ref: RefProps = {
|
|
374
|
-
referToCssId: gCssId,
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
return (
|
|
378
|
-
<div ref={ref} class={[gCssId, '&-box'].join(' ')}>
|
|
379
|
-
<div class='&-item'>item</div>
|
|
380
|
-
</div>
|
|
381
|
-
);
|
|
382
|
-
};
|
|
383
|
-
```
|
|
384
|
-
|
|
385
|
-
## 5. Common Patterns ("The Lupine Way")
|
|
386
|
-
|
|
387
|
-
### List / Search (No Re-render)
|
|
388
|
-
|
|
389
|
-
**Pattern**: Create a render function (`makeList`) and assign its result to `HtmlVar`.
|
|
390
|
-
|
|
391
|
-
```typescript
|
|
392
|
-
const MyPage = () => {
|
|
393
|
-
// 1. Logic Variables (Not State)
|
|
394
|
-
let pageIndex = 0;
|
|
395
|
-
|
|
396
|
-
// 2. Dynamic Container
|
|
397
|
-
const listDom = new HtmlVar(<div>Loading...</div>);
|
|
398
|
-
|
|
399
|
-
// 3. Render Function
|
|
400
|
-
const makeList = async () => {
|
|
401
|
-
const data = await fetchData(pageIndex);
|
|
402
|
-
return (
|
|
403
|
-
<div>
|
|
404
|
-
{data.map((item) => (
|
|
405
|
-
<Item item={item} />
|
|
406
|
-
))}
|
|
407
|
-
</div>
|
|
408
|
-
);
|
|
409
|
-
};
|
|
410
|
-
|
|
411
|
-
// 4. Events
|
|
412
|
-
const onSearch = async () => {
|
|
413
|
-
// Read directly from DOM
|
|
414
|
-
const query = ref.$('input.&-search').value;
|
|
415
|
-
// Update logic var
|
|
416
|
-
pageIndex = 0;
|
|
417
|
-
// Update UI manually
|
|
418
|
-
listDom.value = await makeList();
|
|
419
|
-
};
|
|
420
|
-
|
|
421
|
-
const ref: RefProps = {
|
|
422
|
-
onLoad: async () => {
|
|
423
|
-
listDom.value = await makeList();
|
|
424
|
-
},
|
|
425
|
-
};
|
|
426
|
-
|
|
427
|
-
return (
|
|
428
|
-
<div ref={ref}>
|
|
429
|
-
<input class='&-search' />
|
|
430
|
-
<button onClick={onSearch}>Go</button>
|
|
431
|
-
{/* Embed Dynamic Content */}
|
|
432
|
-
{listDom.node}
|
|
433
|
-
</div>
|
|
434
|
-
);
|
|
435
|
-
};
|
|
436
|
-
```
|
|
437
|
-
|
|
438
|
-
### Page Navigation (`initializePage` vs `<a>`)
|
|
439
|
-
|
|
440
|
-
In the Lupine.js system, all standard `<a>` HTML tags are automatically intercepted. If the link points to an internal route, Lupine safely binds it to `_lupineJs.initializePage(href)` behind the scenes to perform a seamless single-page application (SPA) transition without a full browser reload.
|
|
441
|
-
|
|
442
|
-
When performing imperative or programmatic routing via JavaScript (e.g. clicking a `<button>` or a `div`), **DO NOT** use `window.location.href = '/path'`, as this forces a harsh full-page reload.
|
|
443
|
-
|
|
444
|
-
Instead, import and use `initializePage`:
|
|
445
|
-
|
|
446
|
-
```typescript
|
|
447
|
-
import { initializePage } from 'lupine.web';
|
|
448
|
-
|
|
449
|
-
const navigate = () => {
|
|
450
|
-
// CORRECT: Seamless SPA transition
|
|
451
|
-
initializePage('/play/diff01/1');
|
|
452
|
-
|
|
453
|
-
// ERROR / ANTI-PATTERN: Forces full browser reload unless explicitly desired
|
|
454
|
-
// window.location.href = '/play/diff01/1';
|
|
455
|
-
};
|
|
456
|
-
```
|
|
457
|
-
|
|
458
|
-
### Mobile Navigation (`SliderFrame`)
|
|
459
|
-
|
|
460
|
-
Lupine uses a "Slide-over" model for navigation (Drill-down). To achieve infinite nesting (where a child page can open a grandchild page), each Component level simply needs to define its own `sliderHook` and its own `<SliderFrame>` tag to act as the placeholder for its children.
|
|
461
|
-
|
|
462
|
-
```typescript
|
|
463
|
-
import { SliderFrame, SliderFrameHookProps, HeaderWithBackFrame } from 'lupine.components';
|
|
464
|
-
|
|
465
|
-
// 1. Parent Component (or Level 1)
|
|
466
|
-
const Parent = () => {
|
|
467
|
-
// Define hook for Level 2
|
|
468
|
-
const sliderHook: SliderFrameHookProps = {};
|
|
469
|
-
|
|
470
|
-
const openDetail = (id) => {
|
|
471
|
-
// Push new view onto stack
|
|
472
|
-
sliderHook.load!(<DetailComponent id={id} parentSliderFrameHook={sliderHook} />);
|
|
473
|
-
};
|
|
474
|
-
|
|
475
|
-
return (
|
|
476
|
-
<div>
|
|
477
|
-
{/* Placeholder for Level 2 */}
|
|
478
|
-
<SliderFrame hook={sliderHook} />
|
|
479
|
-
|
|
480
|
-
<div onClick={() => openDetail(1)}>Click Me</div>
|
|
481
|
-
</div>
|
|
482
|
-
);
|
|
483
|
-
};
|
|
484
|
-
|
|
485
|
-
// 2. Child Component (Level 2)
|
|
486
|
-
const DetailComponent = (props: { id: number; parentSliderFrameHook: SliderFrameHookProps }) => {
|
|
487
|
-
// Define hook for Level 3
|
|
488
|
-
const childSliderHook: SliderFrameHookProps = {};
|
|
489
|
-
|
|
490
|
-
const openDeeper = () => {
|
|
491
|
-
// Load Level 3 component into this component's placeholder
|
|
492
|
-
childSliderHook.load!(<DetailComponent id={props.id + 1} parentSliderFrameHook={childSliderHook} />);
|
|
493
|
-
};
|
|
494
|
-
|
|
495
|
-
return (
|
|
496
|
-
<HeaderWithBackFrame title='Detail Page' onBack={(e) => props.parentSliderFrameHook.close!(e)}>
|
|
497
|
-
{/* Placeholder for Level 3 */}
|
|
498
|
-
<SliderFrame hook={childSliderHook} />
|
|
499
|
-
|
|
500
|
-
<div onClick={openDeeper}>Go Deeper</div>
|
|
501
|
-
</HeaderWithBackFrame>
|
|
502
|
-
);
|
|
503
|
-
};
|
|
504
|
-
```
|
|
505
|
-
|
|
506
|
-
### Component Hooks (Imperative Control)
|
|
507
|
-
|
|
508
|
-
Instead of React's `useImperativeHandle` or lifting state up, Lupine components often use a `hook` pattern for parent-to-child communication and exposing methods.
|
|
509
|
-
|
|
510
|
-
1. **Parent** creates an empty object: `const myHook: MyComponentHookProps = {};`
|
|
511
|
-
2. **Parent** passes it to the child: `<MyComponent hook={myHook} />`
|
|
512
|
-
3. **Child** populates it during render:
|
|
513
|
-
```typescript
|
|
514
|
-
if (props.hook) {
|
|
515
|
-
props.hook.getValue = () => value;
|
|
516
|
-
props.hook.setValue = (val) => {
|
|
517
|
-
updateDOM(val);
|
|
518
|
-
};
|
|
519
|
-
}
|
|
520
|
-
```
|
|
521
|
-
4. **Parent** calls it later on demand: `console.log(myHook.getValue());`
|
|
522
|
-
|
|
523
|
-
**⚠️ CRITICAL HOOK TIMING**: Do not call hook methods in the parent's top-level execution scope before returning the child component. The child component populates or resets the hook _during_ its own render phase. If you call `myHook.setValue()` and then return `<MyComponent hook={myHook} />`, your changes will be ignored or the hook object will be overwritten. You **MUST** wait until the component is mounted to use the hook, typically via a parent `RefProps.onLoad`:
|
|
524
|
-
|
|
525
|
-
```typescript
|
|
526
|
-
const Parent = () => {
|
|
527
|
-
const myHook: MyComponentHookProps = {};
|
|
528
|
-
|
|
529
|
-
const ref: RefProps = {
|
|
530
|
-
onLoad: async () => {
|
|
531
|
-
// Safe: Child has rendered and populated the hook
|
|
532
|
-
myHook.setValue('Hello');
|
|
533
|
-
},
|
|
534
|
-
};
|
|
535
|
-
|
|
536
|
-
return (
|
|
537
|
-
<div ref={ref}>
|
|
538
|
-
<MyComponent hook={myHook} />
|
|
539
|
-
</div>
|
|
540
|
-
);
|
|
541
|
-
};
|
|
542
|
-
```
|
|
543
|
-
|
|
544
|
-
## 5. Architecture Cheat Sheet
|
|
545
|
-
|
|
546
|
-
- **`lupine.api` (Backend)**:
|
|
547
|
-
- `req.locals.json()` to get body.
|
|
548
|
-
- `apiCache.getDb().selectObject('$__table', ...)`
|
|
549
|
-
- `ApiHelper.sendJson(req, res, { status: 'ok' })`
|
|
550
|
-
- **`lupine.web` (Frontend)**:
|
|
551
|
-
- `NotificationMessage.sendMessage('Msg', NotificationColor.Success)`
|
|
552
|
-
- `getRenderPageProps().renderPageFunctions.fetchData('/api/...')`
|
|
553
|
-
- Retrieve dynamic URL parameters explicitly via `props.urlParameters['paramName']`.
|
|
554
|
-
- **Environment vs Database Config**:
|
|
555
|
-
- `webEnv('API_BASE_URL', '')`: Use this mapping to synchronously read statically injected environment variables defined in `.env` (like `WEB.xxx`).
|
|
556
|
-
- `await WebConfig.get('siteLogo')`: Use this for dynamic configurations. It works asynchronously by fetching data from the backend server first, then caches it for subsequent calls.
|
|
557
|
-
- **Path Parameter Syntax**:
|
|
558
|
-
- Mandatory parameters use `:` (e.g., `pageRouter.use('/page/:id', PlayPage)`).
|
|
559
|
-
- Fixed parameters use `/fixed-parameter/` (e.g., `pageRouter.use('/page/:id/detail/', PlayPage)`), `detail` is a fixed parameter.
|
|
560
|
-
- Optional parameters use `?` (e.g., `/page/:userId/?option1/?option2`). Once an optional parameter is declared, all subsequent route sections become optional (It's not a query string).
|
|
561
|
-
|
|
562
|
-
## 6. Lupine.cms App Integration Guide
|
|
563
|
-
|
|
564
|
-
This section describes Lupine.cms from the app user's point of view: how a frontend app routes public/SSR requests into CMS rendering, how CMS URLs are resolved, how language fallback works, how coded pages/components override CMS content, and where registration code must live.
|
|
565
|
-
|
|
566
|
-
### 6.1 Required frontend entry point
|
|
567
|
-
|
|
568
|
-
A CMS-enabled frontend app must register `CmsRenderPage` as the catch-all page handler in its public app entry, for example in `apps/cms/web/src/index.tsx`:
|
|
569
|
-
|
|
570
|
-
```tsx
|
|
571
|
-
pageRouter.use('*', CmsRenderPage);
|
|
572
|
-
```
|
|
573
|
-
|
|
574
|
-
This is the key integration point. During frontend rendering or SSR, any page request that reaches this catch-all route is delegated to `CmsRenderPage`. Without this route, CMS page JSON will not be used for public page requests.
|
|
575
|
-
|
|
576
|
-
Typical public entry responsibilities:
|
|
577
|
-
|
|
578
|
-
- initialize app/global styles and theme
|
|
579
|
-
- register any public coded CMS frame/content pages with `cmsRegisterPage()`
|
|
580
|
-
- configure `pageRouter`
|
|
581
|
-
- end with `pageRouter.use('*', CmsRenderPage)` so unresolved public routes are served by CMS
|
|
582
|
-
|
|
583
|
-
### 6.2 CMS URL structure: `/lang/frame/content`
|
|
584
|
-
|
|
585
|
-
CMS public URLs are interpreted as three logical levels:
|
|
586
|
-
|
|
587
|
-
```text
|
|
588
|
-
/lang/frame/content
|
|
589
|
-
```
|
|
590
|
-
|
|
591
|
-
Meanings:
|
|
592
|
-
|
|
593
|
-
- `lang`: optional language code
|
|
594
|
-
- `frame`: optional frame page ID
|
|
595
|
-
- `content`: optional content page ID
|
|
596
|
-
|
|
597
|
-
If the first URL segment matches a configured site language, it is treated as `lang`. Otherwise the URL is treated as not having a language prefix.
|
|
598
|
-
|
|
599
|
-
Examples:
|
|
600
|
-
|
|
601
|
-
```text
|
|
602
|
-
/en/home/article-1 -> lang=en, frame=home, content=article-1
|
|
603
|
-
/home/article-1 -> lang is resolved automatically, frame=home, content=article-1
|
|
604
|
-
/en/home -> lang=en, frame=home, content defaults from config
|
|
605
|
-
/home -> lang auto, frame=home, content defaults from config
|
|
606
|
-
/ -> lang auto, frame and content default from config
|
|
607
|
-
```
|
|
608
|
-
|
|
609
|
-
### 6.3 Language resolution and default language
|
|
610
|
-
|
|
611
|
-
If `lang` is omitted from the URL, CMS resolves language in this order:
|
|
612
|
-
|
|
613
|
-
1. explicit `lang` parameter passed to the render/embed API, if any
|
|
614
|
-
2. language in the URL prefix, if any
|
|
615
|
-
3. browser language
|
|
616
|
-
4. the default language configured in `siteLangs`
|
|
617
|
-
|
|
618
|
-
The available languages are configured in the web settings UI using the `siteLangs` setting declared in `packages/lupine.api/admin/admin-setting-web.tsx`:
|
|
619
|
-
|
|
620
|
-
```typescript
|
|
621
|
-
{ label: 'Languages', type: 'text', name: 'siteLangs', tip: 'Languages separated by commas. Format: code:title,code:title. First is default language. Example: en:English,cn:Chinese,ja:Japanese' }
|
|
622
|
-
```
|
|
623
|
-
|
|
624
|
-
The first item in `siteLangs` is the default language. If the browser language is not in `siteLangs`, CMS falls back to this first language.
|
|
625
|
-
|
|
626
|
-
Agent rules:
|
|
627
|
-
|
|
628
|
-
- Do not assume browser language is always accepted. Always compare it against configured `siteLangs`.
|
|
629
|
-
- Keep the first `siteLangs` entry stable because it is the fallback default for public rendering and data fallback.
|
|
630
|
-
- When testing multilingual pages, test both explicit language URLs and language omitted URLs.
|
|
631
|
-
|
|
632
|
-
### 6.4 Default frame and content IDs
|
|
633
|
-
|
|
634
|
-
When `frame` or `content` is missing from the URL, CMS uses web configuration defaults from `render-page.tsx`:
|
|
635
|
-
|
|
636
|
-
```typescript
|
|
637
|
-
const frameId = (hasLangPrefix ? urlParts[1] : urlParts[0]) || await WebConfig.get('cmsPageDefault', '');
|
|
638
|
-
const contentId = (hasLangPrefix ? urlParts[2] : urlParts[1]) || await WebConfig.get('cmsContentDefault', '');
|
|
639
|
-
```
|
|
640
|
-
|
|
641
|
-
Therefore:
|
|
642
|
-
|
|
643
|
-
- missing frame ID falls back to `cmsPageDefault`
|
|
644
|
-
- missing content ID falls back to `cmsContentDefault`
|
|
645
|
-
|
|
646
|
-
Agent rules:
|
|
647
|
-
|
|
648
|
-
- If `/` renders incorrectly, inspect `cmsPageDefault` and `cmsContentDefault` first.
|
|
649
|
-
- If `/en` renders incorrectly, remember it may still be using default frame/content IDs.
|
|
650
|
-
- Do not hardcode default page IDs in rendering logic; use `WebConfig` settings.
|
|
651
|
-
|
|
652
|
-
### 6.5 CMS page data lookup and language fallback
|
|
653
|
-
|
|
654
|
-
When CMS loads persisted page JSON from the backend, it uses language-qualified IDs first:
|
|
655
|
-
|
|
656
|
-
1. try `lang:id`
|
|
657
|
-
2. if missing, try `defaultLang:id`
|
|
658
|
-
3. if still missing, try plain `id`
|
|
659
|
-
|
|
660
|
-
This applies to frame/content page data loaded from CMS storage.
|
|
661
|
-
|
|
662
|
-
Practical result:
|
|
663
|
-
|
|
664
|
-
- Save `en:home` to create an English-specific home page.
|
|
665
|
-
- Save `cn:home` to create a Chinese-specific home page.
|
|
666
|
-
- Save `home` as a language-neutral fallback.
|
|
667
|
-
- If `ja:home` does not exist, CMS can fall back to default language and then plain `home`.
|
|
668
|
-
|
|
669
|
-
Agent rules:
|
|
670
|
-
|
|
671
|
-
- When investigating "wrong language page displayed", check all three possible records: `lang:id`, `defaultLang:id`, and `id`.
|
|
672
|
-
- When creating multilingual content, use `lang:id` consistently in the designer save dialog.
|
|
673
|
-
- Keep fallback pages plain or default-language records intentionally; do not create accidental stale fallbacks.
|
|
674
|
-
|
|
675
|
-
### 6.6 Coded frame/content pages with `cmsRegisterPage()`
|
|
676
|
-
|
|
677
|
-
A frontend app can override or provide a frame/content page with code:
|
|
678
|
-
|
|
679
|
-
```tsx
|
|
680
|
-
const SampleFrame = async (props: PageProps) => {
|
|
681
|
-
return <div>Frame from code</div>;
|
|
682
|
-
};
|
|
683
|
-
|
|
684
|
-
cmsRegisterPage('pagex', SampleFrame);
|
|
685
|
-
```
|
|
686
|
-
|
|
687
|
-
When CMS resolves a frame/content ID, registered pages are checked before persisted CMS JSON. This means a coded registration for `pagex` takes priority over a database page with the same ID.
|
|
688
|
-
|
|
689
|
-
Use this when:
|
|
690
|
-
|
|
691
|
-
- a frame should be implemented in code for full control
|
|
692
|
-
- content is dynamic and not suited to page-designer JSON
|
|
693
|
-
- you want a coded fallback/override for a CMS ID
|
|
694
|
-
|
|
695
|
-
Agent rules:
|
|
696
|
-
|
|
697
|
-
- Registered page keys are public render contracts. Changing them can break URLs and saved CMS references.
|
|
698
|
-
- Keep `cmsRegisterPage()` calls in the public frontend entry when they are needed for public `CmsRenderPage` routing.
|
|
699
|
-
- If a CMS page ID is not loading from database, check whether the same ID was registered with `cmsRegisterPage()` and is taking priority.
|
|
700
|
-
|
|
701
|
-
### 6.7 Saving pages and using `My Components`
|
|
702
|
-
|
|
703
|
-
In the design UI, pages can be saved with language-qualified IDs such as:
|
|
704
|
-
|
|
705
|
-
```text
|
|
706
|
-
en:home
|
|
707
|
-
cn:home
|
|
708
|
-
home
|
|
709
|
-
```
|
|
710
|
-
|
|
711
|
-
If the save dialog has `component` checked, the saved content is also treated as a reusable saved component. It becomes available under `My Components` in the designer and can be dragged into other pages.
|
|
712
|
-
|
|
713
|
-
Important distinction:
|
|
714
|
-
|
|
715
|
-
- A normal saved page/content is resolved by URL and ID.
|
|
716
|
-
- A checked component save is additionally discoverable as a reusable design component.
|
|
717
|
-
- Saved components are persisted CMS data, unlike registered code components which are runtime registrations.
|
|
718
|
-
|
|
719
|
-
Agent rules:
|
|
720
|
-
|
|
721
|
-
- Use saved components for reusable page-designer JSON fragments.
|
|
722
|
-
- Use registered code components for reusable coded JSX/TSX components.
|
|
723
|
-
- Do not confuse `My Components` with `Registered Components`.
|
|
724
|
-
|
|
725
|
-
### 6.8 Coded designer components with `cmsRegisterComponent()`
|
|
726
|
-
|
|
727
|
-
The designer can also expose coded components as draggable design items:
|
|
728
|
-
|
|
729
|
-
```tsx
|
|
730
|
-
const SampleContent = async (props: PageProps) => {
|
|
731
|
-
return (
|
|
732
|
-
<div class='sample-content-box'>
|
|
733
|
-
This is a sample registered components.
|
|
734
|
-
</div>
|
|
735
|
-
);
|
|
736
|
-
};
|
|
737
|
-
|
|
738
|
-
cmsRegisterComponent('contentx', SampleContent, 'Sample Content');
|
|
739
|
-
```
|
|
740
|
-
|
|
741
|
-
These appear in the designer under `Registered Components`. Dragging one into a page stores a `block-registered-component` node with only a component key/label. At render time, CMS looks up the real function from the registered component map and renders it.
|
|
742
|
-
|
|
743
|
-
Critical placement rule:
|
|
744
|
-
|
|
745
|
-
- Register designer components in the admin/dashboard entry, such as `apps/cms/web/src/admin_dev/index.tsx`.
|
|
746
|
-
- Do not register designer-only components only in the public frontend entry, such as `apps/cms/web/src/index.tsx`, because the design page does not go through that public route. If registration only happens there, the admin designer will not see the component.
|
|
747
|
-
|
|
748
|
-
Agent rules:
|
|
749
|
-
|
|
750
|
-
- Use `cmsRegisterComponent()` in the admin dashboard bundle for components that must appear in the design sidebar.
|
|
751
|
-
- Use `cmsRegisterPage()` in the public frontend bundle for pages/frames/content that must be resolved during public CMS rendering.
|
|
752
|
-
- If a registered component is visible in public render but missing in the design sidebar, check whether it was registered in the admin dashboard entry.
|
|
753
|
-
- If a saved page contains `block-registered-component` but render says component not found, check whether the same component key was registered in the currently running bundle/process.
|
|
754
|
-
|
|
755
|
-
### 6.9 Embedding CMS content inside coded components
|
|
756
|
-
|
|
757
|
-
Use `CmsEmbedContent` when coded components need to render CMS-managed content by ID. It accepts an `id` and optional `lang`, and follows the same language priority/fallback logic as CMS public rendering.
|
|
758
|
-
|
|
759
|
-
Use cases:
|
|
760
|
-
|
|
761
|
-
- coded page shells that embed CMS-managed regions
|
|
762
|
-
- coded landing pages with editable CMS sections
|
|
763
|
-
- admin/demo pages that need to preview CMS content by ID
|
|
764
|
-
|
|
765
|
-
Agent rules:
|
|
766
|
-
|
|
767
|
-
- Prefer `CmsEmbedContent` for embedding CMS content inside coded components.
|
|
768
|
-
- Pass `lang` explicitly only when the component must force a language. Otherwise let URL/browser/default language resolution work.
|
|
769
|
-
- Remember backend data fallback still follows `lang:id -> defaultLang:id -> id`.
|
|
770
|
-
|
|
771
|
-
### 6.10 User-facing CMS troubleshooting checklist
|
|
772
|
-
|
|
773
|
-
When CMS routing/rendering does not behave as expected, check in this order:
|
|
774
|
-
|
|
775
|
-
1. Does the public app entry call `pageRouter.use('*', CmsRenderPage)`?
|
|
776
|
-
2. Is the URL parsed as `/lang/frame/content` or `/frame/content`?
|
|
777
|
-
3. Is the `lang` segment present in `siteLangs`?
|
|
778
|
-
4. Are `cmsPageDefault` and `cmsContentDefault` configured when frame/content are omitted?
|
|
779
|
-
5. Does a coded `cmsRegisterPage(id, ...)` override the database page?
|
|
780
|
-
6. Do the expected records exist as `lang:id`, `defaultLang:id`, or plain `id`?
|
|
781
|
-
7. Was the page saved with the intended language-qualified ID?
|
|
782
|
-
8. If using `My Components`, was the saved item checked as component?
|
|
783
|
-
9. If using `Registered Components`, was `cmsRegisterComponent()` called in the admin/dashboard entry?
|
|
784
|
-
10. If rendering a registered component, is the same key registered in the current runtime bundle?
|
|
785
|
-
|
|
786
|
-
## 7. Coding Standards & Gotchas
|
|
787
|
-
|
|
788
|
-
- **`useState` vs `HtmlVar`**: `useState` exists (`import { useState } from 'lupine.components'`) and is elegant for small components. But it rerenders the **entire** component — for large/complex components or high-frequency updates, prefer `HtmlVar` for surgical partial updates. `useEffect`, `useReducer`, `useCallback`, `useContext` **do NOT exist**.
|
|
789
|
-
- **❌ `className`**: Use standard HTML `class`.
|
|
790
|
-
- **⚠️ `style={{}}`**: **Allowed** for simple or dynamic inline styles (e.g., `style={{ border: '1px solid red' }}`), but **prefer `css={CssProps}`** for structural/theme styling.
|
|
791
|
-
- **✅ Native Events**: `onClick`, `onChange`, `onInput`, `onMouseMove` etc. are standard HTML events and **ARE ALLOWED**. Use them for triggering logic or callbacks (e.g., `onInput={(e) => updateOtherThing(e.target.value)}`).
|
|
792
|
-
- **✅ Uncontrolled Inputs**: While you _can_ use `onInput` to track state, the default efficient pattern is often to read `ref.$('input').value` only when the user clicks "Save" or "Search".
|
|
793
|
-
|
|
794
|
-
## 8. System Icons & Customization
|
|
795
|
-
|
|
796
|
-
Lupine.components uses a set of built-in system icons (like `ma-close` and `mg-arrow_back_ios_new_outlined` found in components like `MobileHeaderWithBack`).
|
|
797
|
-
|
|
798
|
-
These icons rely on an icon font generated by [icons-font-customization](https://github.com/uuware/icons-font-customization). If you want to add or modify the standard icon font itself, refer to that repository.
|
|
799
|
-
|
|
800
|
-
### Overriding System Icons without Generating a Font
|
|
801
|
-
|
|
802
|
-
If you do not want to generate or modify the full icon font, you can easily override specific system icons directly via CSS using pure SVG strings or imported SVG files.
|
|
803
|
-
|
|
804
|
-
**1. Define your SVG Data URL:**
|
|
805
|
-
You can import an `.svg` file (if your bundler supports it) or define a raw Data URI string.
|
|
806
|
-
|
|
807
|
-
```typescript
|
|
808
|
-
// Option A: Using bundler import
|
|
809
|
-
import githubIcon from 'github.svg';
|
|
810
|
-
|
|
811
|
-
// Option B: Raw Data URI string
|
|
812
|
-
const closeSvgData = `data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='24' height='24'%3E%3Cpath fill='none' stroke='black' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M18 6L6 18M6 6l12 12'/%3E%3C/svg%3E`;
|
|
813
|
-
|
|
814
|
-
export const DemoIcons = {
|
|
815
|
-
github: githubIcon,
|
|
816
|
-
'ma-close': closeSvgData,
|
|
817
|
-
};
|
|
818
|
-
```
|
|
819
|
-
|
|
820
|
-
**2. Override the specific `.ifc-icon` via CSS Masking:**
|
|
821
|
-
Use the `-webkit-mask-image` and `maskImage` property wrapped in `url()` to apply the SVG data to the icon class. This ensures it inherits colors (`currentColor`) properly.
|
|
822
|
-
|
|
823
|
-
```typescript
|
|
824
|
-
const css: CssProps = {
|
|
825
|
-
// Target the specific system icon class you wish to override
|
|
826
|
-
'.ifc-icon.ma-close': {
|
|
827
|
-
'-webkit-mask-image': `url("${DemoIcons['ma-close']}")`,
|
|
828
|
-
maskImage: `url("${DemoIcons['ma-close']}")`,
|
|
829
|
-
// If needed, specify mask sizing properties:
|
|
830
|
-
// maskRepeat: 'no-repeat',
|
|
831
|
-
// maskPosition: 'center',
|
|
832
|
-
// maskSize: 'contain',
|
|
833
|
-
},
|
|
834
|
-
};
|
|
835
|
-
```
|
|
836
|
-
|
|
837
|
-
## 9. Cross-Platform App Bootstrapping Guidance
|
|
838
|
-
|
|
839
|
-
When creating a new Cross-Platform App using `lupine.js`, follow this standard procedure for scaffolding the entry point, navigation, and icons:
|
|
840
|
-
|
|
841
|
-
1. **Custom Navigation Icons (`app-icons.ts`)**:
|
|
842
|
-
Instead of using the default icon font, you should export SVG Data URIs for your app's specific icons from `app-icons.ts`. Use a `reduce` function to generate the appropriate `CssProps` with `-webkit-mask-image: url("' + svg + '")'` and `maskImage: 'url("' + svg + '")'` to override the `.ifc-icon.[icon-name]` classes. Avoid using backticks (\"\`\") when injecting SVG variables inside the maskImage URL to prevent escaping issues.
|
|
843
|
-
|
|
844
|
-
2. **Base Styles (`base-css.ts`)**:
|
|
845
|
-
Create a `styles/base-css.ts` file that imports the dynamic icon styles (from `app-icons.ts`), and defines any placeholder wrappers (e.g., `.user-page-placeholder` having `width: '100%', height: '100%'`). Use `bindGlobalStyle('comm-css', baseCss, false, true)` in the index file to register these.
|
|
846
|
-
|
|
847
|
-
3. **Global UI Frame (`app-responsive-frame.tsx`)**:
|
|
848
|
-
Use `ResponsiveFrame` along with `SliderFrame` (for drill-down navigation via `SliderFrameHookProps`) to define the app's skeleton.
|
|
849
|
-
|
|
850
|
-
- Define your top/bottom navigation menus based on your icons.
|
|
851
|
-
- Return `ResponsiveFrame` passing in the `mainContent`, menus, and ensure you provide all required properties like `mobileSideMenuContent: <></>` (even if empty) to satisfy TypeScript interfaces.
|
|
852
|
-
|
|
853
|
-
4. **Page Router Configuration (`index.tsx`)**:
|
|
854
|
-
Create a `PageRouter`. Bind the `AppResponsiveFrame` using `pageRouter.setFramePage({ component: AppResponsiveFrame, placeholderClassname: 'user-page-placeholder' })`. Then associate the routes (`pageRouter.use('*', HomePage)`) and finalize with `bindRouter(pageRouter)`.
|
|
855
|
-
|
|
856
|
-
5. **Local Storage Patterns**:
|
|
857
|
-
For pure frontend utility apps (compatible with browsers, Capacitor, and Electron), wrap `localStorage.getItem()` and `localStorage.setItem()` inside dedicated Service singletons (e.g., `LocalNotesService`). Always parse/serialize consistently and assign standard unique IDs (like `Date.now()`) for newly inserted records. Combine this with the `onLoad` pattern inside `RefProps` to fetch data immediately when components render, injecting it directly into an `HtmlVar` wrapping the list.
|
|
858
|
-
|
|
859
|
-
## 10. Standard Mobile App Layout & Interactions
|
|
860
|
-
|
|
861
|
-
When asked to "create a list page" or "initialize a standard mobile framework", rigorously apply this exact structural pattern based on the cross-platform starter app.
|
|
862
|
-
|
|
863
|
-
### A. The Global Root (`index.tsx` & `AppResponsiveFrame`)
|
|
864
|
-
|
|
865
|
-
- Use `bindTheme` to load global color tokens.
|
|
866
|
-
- Set the global frame with `pageRouter.setFramePage({ component: AppResponsiveFrame, placeholderClassname: 'user-page-placeholder' })`.
|
|
867
|
-
- **`AppResponsiveFrame`** handles the macro layout:
|
|
868
|
-
- It renders `<ResponsiveFrame>` wrapping `<main class='user-page-placeholder'></main>`.
|
|
869
|
-
- It contains the global left `mobileSideMenuContent` (typically abstracted into a `<SideMenuContent />` component).
|
|
870
|
-
|
|
871
|
-
### B. The Home / List Page (`HomePage`)
|
|
872
|
-
|
|
873
|
-
A standard mobile list page must employ:
|
|
874
|
-
|
|
875
|
-
1. **The Top Header (`MobileHeaderCenter`)**:
|
|
876
|
-
|
|
877
|
-
- Wrap the top bar in `<MobileHeaderCenter>`.
|
|
878
|
-
- Use `<MobileHeaderTitleIcon title='App Name' left={...} right={...} />`.
|
|
879
|
-
- The _left_ slot usually contains an empty spacer `<MobileHeaderEmptyIcon />`.
|
|
880
|
-
- The _right_ slot contains actions (e.g., Search icon, `<MobileTopSysIcon />` to open the Side Menu).
|
|
881
|
-
|
|
882
|
-
2. **The Scrollable Content Area**:
|
|
883
|
-
|
|
884
|
-
- Beneath the header, create a flex-grow scrollable div: `<div class='flex-1 overflow-y-auto padding-m'>`.
|
|
885
|
-
- Mount an `HtmlVar` instance here (`{dom.node}`) to dynamically bind the list data arrays fetched typically via `RefProps.onLoad`.
|
|
886
|
-
|
|
887
|
-
3. **Floating Action Button (FAB)**:
|
|
888
|
-
- Overlay a primary action button at `bottom: 24px`, `right: 24px` using `.fab-button` styled with `var(--primary-accent-color)`.
|
|
889
|
-
|
|
890
|
-
### C. Advanced Touch Interactions (`createDragUtil` in Lists)
|
|
891
|
-
|
|
892
|
-
For interactive lists, `createDragUtil()` from `lupine.components` handles complex gesture physics.
|
|
893
|
-
|
|
894
|
-
- **Swipe-to-Reveal (Horizontal)**:
|
|
895
|
-
|
|
896
|
-
- Render an absolute positioned `.actions-layer` (opacity: 0 initially) underneath the `.list-card`.
|
|
897
|
-
- When the card's `onTouchStart`/`onMouseDown` is triggered, attach `dragUtil` handlers.
|
|
898
|
-
- In `dragUtil.setOnMoveCallback`, translate the card `transform: translateX(...)` up to a negative boundary (e.g., -100px) and toggle the action layer's opacity to 1.
|
|
899
|
-
- Implement a global `resetSwipeMenus` function attached to `onMouseDown={handleBgTouch}` at the page root to ensure an exclusive accordion-like menu state (only one open at a time).
|
|
900
|
-
|
|
901
|
-
- **Drag-to-Reorder (Vertical)**:
|
|
902
|
-
- Define a distinct `.drag-handle` slot inside the card (e.g., `bs-list` icon).
|
|
903
|
-
- In `dragUtil.setOnMoveCallback`, when dragging this handle, apply `scale(1.02)` and elevated `boxShadow` to the grabbed card. Compare its `relativeY` pointer position against sibling card `offsetTop`s to execute live `insertBefore / insertAfter` DOM swaps.
|
|
904
|
-
- Conclude by saving the new DOM sibling ordering in `dragUtil.setOnMoveEndCallback`.
|
|
905
|
-
|
|
906
|
-
### D. Sub-Page Routing & Drill-Downs (`SliderFrame`)
|
|
907
|
-
|
|
908
|
-
- Slide-over interactions are mandatory for Search panels, Creation modals, and Details views.
|
|
909
|
-
- The `HomePage` must define a top-level `<SliderFrame hook={sliderFrameHook} />` inside its scroll area.
|
|
910
|
-
- Opening a child acts instantly via: `sliderFrameHook.load!(<MyChildPage sliderFrameHook={sliderFrameHook} />)`.
|
|
911
|
-
- **Inside the Child Component**:
|
|
912
|
-
- Must be wrapped with `<HeaderWithBackFrame title='Subpage' onBack={(e) => props.sliderFrameHook.close!(e)}>` to provide the standard top-left back chevron.
|
|
913
|
-
- **Nested SliderFrames**:
|
|
914
|
-
- When opening a sliding frame _from within_ another sliding frame (e.g., opening a Settings About page from the Settings root page), you **MUST** define a new local hook `const innerSliderHook: SliderFrameHookProps = {};` and mount a _new_ `<SliderFrame hook={innerSliderHook} />` inside the parent slider component.
|
|
915
|
-
- Using the parent's hook will replace the parent's content instead of sliding a new frame over it.
|
|
916
|
-
- Wrap multiple children in `<></>` or a `<div>` if they are direct children to satisfy single `VNode` rendering constraints.
|
|
917
|
-
|
|
918
|
-
### E. Dialogs & Action Sheets (Replacing Native Alerts)
|
|
919
|
-
|
|
920
|
-
**DO NOT USE browser native `alert()`, `confirm()`, or `prompt()`**. Instead, use the native `ActionSheet` promises from `lupine.components` for a modern, mobile-friendly overlay experience:
|
|
921
|
-
|
|
922
|
-
1. **Option Selection (`ActionSheetSelectPromise`)** (Replaces `confirm()` or complex choices):
|
|
923
|
-
|
|
924
|
-
```typescript
|
|
925
|
-
import { ActionSheetSelectPromise } from 'lupine.components';
|
|
926
|
-
|
|
927
|
-
const index = await ActionSheetSelectPromise({
|
|
928
|
-
title: 'Delete this saved game?', // Optional
|
|
929
|
-
options: ['Delete', 'Edit'],
|
|
930
|
-
cancelButtonText: 'Cancel',
|
|
931
|
-
});
|
|
932
|
-
|
|
933
|
-
if (index === 0) {
|
|
934
|
-
/* User clicked Delete (Index of options array) */
|
|
935
|
-
}
|
|
936
|
-
if (index === -1) {
|
|
937
|
-
/* User clicked Cancel or tapped background */
|
|
938
|
-
}
|
|
939
|
-
```
|
|
940
|
-
|
|
941
|
-
2. **Simple Messages (`ActionSheetMessagePromise`)** (Replaces `alert()`):
|
|
942
|
-
|
|
943
|
-
```typescript
|
|
944
|
-
import { ActionSheetMessagePromise } from 'lupine.components';
|
|
945
|
-
|
|
946
|
-
await ActionSheetMessagePromise({
|
|
947
|
-
title: 'Success', // Optional
|
|
948
|
-
message: 'Your profile has been saved.',
|
|
949
|
-
closeButtonText: 'OK', // Optional, defaults to a close behavior
|
|
950
|
-
});
|
|
951
|
-
```
|
|
952
|
-
|
|
953
|
-
3. **User Input (`ActionSheetInputPromise`)** (Replaces `prompt()`):
|
|
954
|
-
|
|
955
|
-
```typescript
|
|
956
|
-
import { ActionSheetInputPromise } from 'lupine.components';
|
|
957
|
-
|
|
958
|
-
const value = await ActionSheetInputPromise({
|
|
959
|
-
title: 'Enter your name',
|
|
960
|
-
// placeholder: 'Player 1', // Optional
|
|
961
|
-
confirmButtonText: 'Submit', // Optional
|
|
962
|
-
cancelButtonText: 'Cancel', // Optional
|
|
963
|
-
});
|
|
964
|
-
|
|
965
|
-
if (value !== null) {
|
|
966
|
-
/* User submitted a string */
|
|
967
|
-
}
|
|
968
|
-
```
|
|
969
|
-
|
|
970
|
-
4. **Other Available Prompts (Investigate their API via `lupine.components` when needed)**:
|
|
971
|
-
- `ActionSheetMultiSelectPromise`: For multiple checkbox selections.
|
|
972
|
-
- `ActionSheetTimePicker`: For selecting a time.
|
|
973
|
-
- `ActionSheetDatePicker`: For selecting a date.
|
|
974
|
-
|
|
975
|
-
### F. Hardware Back Button Handling (`data-back-action`)
|
|
976
|
-
|
|
977
|
-
When building mobile interfaces, users expect the physical hardware "Back" button (or swipe-from-edge gesture) to gracefully dismiss overlays, dialogs, sliders, or menus—similar to pressing the `ESC` key on a desktop.
|
|
978
|
-
|
|
979
|
-
**The Rule**: Whenever you implement a cancel button, a close icon (`X`), or a back chevron (`<`) in a mobile overlay or frame, you **MUST** attach the `data-back-action` attribute using the `backActionHelper`.
|
|
980
|
-
|
|
981
|
-
```typescript
|
|
982
|
-
import { backActionHelper } from 'lupine.components';
|
|
983
|
-
|
|
984
|
-
export const MyCloseButton = ({ onClose }) => {
|
|
985
|
-
return (
|
|
986
|
-
<i
|
|
987
|
-
class='ifc-icon ma-close'
|
|
988
|
-
// Generate a unique ID for the back stack
|
|
989
|
-
data-back-action={backActionHelper.genBackActionId()}
|
|
990
|
-
onClick={onClose}
|
|
991
|
-
></i>
|
|
992
|
-
);
|
|
993
|
-
};
|
|
994
|
-
```
|
|
995
|
-
|
|
996
|
-
**How it works**:
|
|
997
|
-
|
|
998
|
-
- When the hardware back button is pressed, the underlying system automatically queries the DOM for all elements with `[data-back-action^="bb-"]`.
|
|
999
|
-
- It finds the most recently created component (the top-most overlay) and automatically triggers a `.click()` event on it.
|
|
1000
|
-
- **Dynamic Mounting vs Static**:
|
|
1001
|
-
- For components that are injected and removed dynamically (like `<ActionSheet />` or `<FloatWindow />`), simply attaching the property to the React/JSX node is sufficient.
|
|
1002
|
-
- For static components that always remain in the DOM but toggle visibility (like an off-canvas sidebar), you must dynamically add/remove the attribute in Javascript (`el.setAttribute` / `el.removeAttribute`) to prevent the back button from intercepting events when the menu is actually closed.
|