create-lupine 1.0.26 → 1.0.28
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/index.js +1 -1
- package/package.json +2 -2
- package/templates/common/AI_CONTEXT.md +370 -64
- package/templates/common/dev/dev-watch.js +19 -1
- package/templates/lupine-template-cv-starter/web/src/index.tsx +0 -3
- package/templates/lupine-template-cv-starter/web/src/lupine-template-cv-starter/index.tsx +0 -3
- package/templates/lupine-template-doc-starter/web/src/index.tsx +0 -3
- package/templates/lupine-template-doc-starter/web/src/lupine-template-doc-starter/index.tsx +0 -3
- package/templates/lupine-template-hello-world/web/src/styles/global.css +57 -70
- package/templates/lupine-template-responsive-starter/web/src/components/side-menu-content.tsx +7 -3
- package/templates/lupine-template-responsive-starter/web/src/index.tsx +0 -3
- package/templates/lupine-template-responsive-starter/web/src/lupine-template-responsive-starter/index.tsx +0 -3
- package/templates/lupine-template-responsive-starter/web/src/styles/global.css +57 -70
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -191,91 +191,174 @@ export const MyComponent = () => {
|
|
|
191
191
|
|
|
192
192
|
## 4. CSS Placement Strategies & Sharing Scopes
|
|
193
193
|
|
|
194
|
-
Lupine.js
|
|
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
195
|
|
|
196
|
-
###
|
|
196
|
+
### 4.1 Sharing CSS inside a method (Component Level)
|
|
197
197
|
|
|
198
|
-
**Best for**:
|
|
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
199
|
|
|
200
|
-
When you
|
|
200
|
+
When you assign `css={css}` to the root element, a unique ID is generated (e.g., `l01`).
|
|
201
201
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
### Strategy B: `bindGlobalStyle` (Reusable Components)
|
|
206
|
-
|
|
207
|
-
**Best for**: Reusable UI components (Buttons, Toggles, List Items, Modals) that will be rendered multiple times.
|
|
208
|
-
|
|
209
|
-
`bindGlobalStyle`, combined with `getGlobalStylesId`, places the `<style>` block in the `<head>` of the document **exactly once**. All instances of the component share the same CSS class names, but those names are still guaranteed to be collision-free!
|
|
210
|
-
|
|
211
|
-
**How it works seamlessly with `&`**:
|
|
212
|
-
|
|
213
|
-
1. Generate an ID based on the `CssProps` content: `const globalCssId = getGlobalStylesId(css);`. (Call this _inside_ the component!)
|
|
214
|
-
2. Bind the style block globally once: `bindGlobalStyle(globalCssId, css);`
|
|
215
|
-
3. Assign this ID to the component's `ref` to link the scope: `const ref: RefProps = { globalCssId };` / `<div ref={ref}>`
|
|
216
|
-
4. Use `class="&-item"` normally. Lupine replaces `&` with the identical `globalCssId` across all instances.
|
|
217
|
-
|
|
218
|
-
> [!WARNING]
|
|
219
|
-
> Because `getGlobalStylesId` relies on `getRequestContext()` data to correctly attach and track styles (especially across SSR and interactive client renders), `getGlobalStylesId` and `bindGlobalStyle` **MUST** be called inside the component function scope. Calling them at the file/module level will result in runtime errors like: `Uncaught Error: Request context is not initialized`.
|
|
220
|
-
|
|
221
|
-
### ⚠️ IMPORTANT: The "Static `CssProps`" Rule
|
|
222
|
-
|
|
223
|
-
Because `bindGlobalStyle` injects your `<style>` tags into the `<head>` globally, your `CssProps` definition **MUST** be entirely static.
|
|
224
|
-
|
|
225
|
-
**ANTI-PATTERN:** Putting variables (like `isVertical`, `size`, `color`) directly inside the `CssProps` object structure. Every time the component re-renders with a different prop, it will generate conflicting CSS IDs and the latter will overwrite the former's styles, corrupting the layout. Define one immutable `const css: CssProps = {...}` and handle visual variations by appending standard class names to your root element (`class={isVertical ? '&-vertical' : '&-horizontal'}`) and map those variations inside your static `CssProps`.
|
|
226
|
-
|
|
227
|
-
### 🔗 Sharing the same CSS scope (`globalCssId`) among Separated DOMs
|
|
228
|
-
|
|
229
|
-
If your component divides its logic so that some internal floating DOM elements are rendered dynamically later (e.g. through a function passed to `HtmlVar`) _separated_ from the root return statement, the inner DOM will automatically generate a **new, mismatched** CSS ID if not linked. Its internal `class="&-item"` references will break and styles will fail to apply.
|
|
230
|
-
|
|
231
|
-
To force separated local DOM partitions to share the exact same `&` CSS Scope as their parent page, explicitly share a globally unique CSS ID using `globalStyleUniqueId()`:
|
|
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`.
|
|
232
205
|
|
|
233
206
|
```tsx
|
|
234
|
-
import {
|
|
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
|
+
};
|
|
235
217
|
|
|
236
|
-
|
|
237
|
-
// 1. Generate a manual ID for the container scope beforehand
|
|
238
|
-
const cssId = globalStyleUniqueId();
|
|
218
|
+
const ref: RefProps = { id: domUniqueId() };
|
|
239
219
|
|
|
220
|
+
// Example of a detached DOM using HtmlVar.
|
|
221
|
+
// It automatically inherits the CSS ID when mounted inside the component!
|
|
240
222
|
const listDom = new HtmlVar('');
|
|
241
|
-
|
|
242
223
|
const renderList = () => {
|
|
243
|
-
// 2. Explicitly bind the inner detached DOM to the parent's globalCssId
|
|
244
224
|
listDom.value = (
|
|
245
|
-
<div
|
|
246
|
-
<div class='&-
|
|
225
|
+
<div class='&-list'>
|
|
226
|
+
<div class='&-list-item'>HtmlVar List Item</div>
|
|
247
227
|
</div>
|
|
248
228
|
);
|
|
249
229
|
};
|
|
250
230
|
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
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
|
+
);
|
|
254
253
|
};
|
|
255
|
-
const css: CssProps = { '.&-bundle-name': { color: 'red' } };
|
|
256
254
|
|
|
257
255
|
return (
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
{
|
|
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>
|
|
261
268
|
</div>
|
|
262
269
|
);
|
|
263
270
|
};
|
|
264
271
|
```
|
|
265
272
|
|
|
266
|
-
###
|
|
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);
|
|
267
295
|
|
|
268
|
-
|
|
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
|
+
```
|
|
269
306
|
|
|
270
|
-
|
|
307
|
+
### 4.3 The `noTopClassName` Parameter
|
|
271
308
|
|
|
272
|
-
|
|
309
|
+
When using `bindGlobalStyle` or `bindAppGlobalStyle`, the `noTopClassName` parameter (4th argument) dictates how top-level CSS selectors are compiled.
|
|
273
310
|
|
|
274
|
-
|
|
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'`).
|
|
275
316
|
|
|
276
|
-
|
|
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.
|
|
277
325
|
|
|
278
|
-
|
|
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"`.
|
|
279
362
|
|
|
280
363
|
```typescript
|
|
281
364
|
export const Component1 = () => {
|
|
@@ -288,18 +371,17 @@ export const Component1 = () => {
|
|
|
288
371
|
bindGlobalStyle(gCssId, css);
|
|
289
372
|
|
|
290
373
|
const ref: RefProps = {
|
|
291
|
-
|
|
374
|
+
referToCssId: gCssId,
|
|
292
375
|
};
|
|
376
|
+
|
|
293
377
|
return (
|
|
294
|
-
<div ref={ref} class='&-box'>
|
|
378
|
+
<div ref={ref} class={[gCssId, '&-box'].join(' ')}>
|
|
295
379
|
<div class='&-item'>item</div>
|
|
296
380
|
</div>
|
|
297
381
|
);
|
|
298
382
|
};
|
|
299
383
|
```
|
|
300
384
|
|
|
301
|
-
---
|
|
302
|
-
|
|
303
385
|
## 5. Common Patterns ("The Lupine Way")
|
|
304
386
|
|
|
305
387
|
### List / Search (No Re-render)
|
|
@@ -477,7 +559,231 @@ const Parent = () => {
|
|
|
477
559
|
- Fixed parameters use `/fixed-parameter/` (e.g., `pageRouter.use('/page/:id/detail/', PlayPage)`), `detail` is a fixed parameter.
|
|
478
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).
|
|
479
561
|
|
|
480
|
-
## 6.
|
|
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
|
|
481
787
|
|
|
482
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**.
|
|
483
789
|
- **❌ `className`**: Use standard HTML `class`.
|
|
@@ -485,7 +791,7 @@ const Parent = () => {
|
|
|
485
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)}`).
|
|
486
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".
|
|
487
793
|
|
|
488
|
-
##
|
|
794
|
+
## 8. System Icons & Customization
|
|
489
795
|
|
|
490
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`).
|
|
491
797
|
|
|
@@ -528,7 +834,7 @@ const css: CssProps = {
|
|
|
528
834
|
};
|
|
529
835
|
```
|
|
530
836
|
|
|
531
|
-
##
|
|
837
|
+
## 9. Cross-Platform App Bootstrapping Guidance
|
|
532
838
|
|
|
533
839
|
When creating a new Cross-Platform App using `lupine.js`, follow this standard procedure for scaffolding the entry point, navigation, and icons:
|
|
534
840
|
|
|
@@ -550,7 +856,7 @@ When creating a new Cross-Platform App using `lupine.js`, follow this standard p
|
|
|
550
856
|
5. **Local Storage Patterns**:
|
|
551
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.
|
|
552
858
|
|
|
553
|
-
##
|
|
859
|
+
## 10. Standard Mobile App Layout & Interactions
|
|
554
860
|
|
|
555
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.
|
|
556
862
|
|
|
@@ -110,6 +110,13 @@ const watchServer = async (isDev, npmCmd, httpPort, serverRootPath) => {
|
|
|
110
110
|
|
|
111
111
|
// copy files to output directory
|
|
112
112
|
const copyCache = new Map();
|
|
113
|
+
const writeBuildTimeFiles = async (saved) => {
|
|
114
|
+
if (!saved.webVersionFile) return;
|
|
115
|
+
const buildTimeContent = JSON.stringify({ version: new Date().toISOString() }, null, 2) + '\n';
|
|
116
|
+
const sourceBuildTimePath = path.join(saved.appDir, saved.webVersionFile);
|
|
117
|
+
await fs.writeFile(sourceBuildTimePath, buildTimeContent, 'utf8');
|
|
118
|
+
};
|
|
119
|
+
|
|
113
120
|
const clientProcessOnEnd = async (saved) => {
|
|
114
121
|
saved.indexHtml &&
|
|
115
122
|
cpIndexHtml(
|
|
@@ -140,6 +147,10 @@ const watchClientPlugin = (saved) => {
|
|
|
140
147
|
return {
|
|
141
148
|
name: 'watchClientPlugin',
|
|
142
149
|
setup(build) {
|
|
150
|
+
build.onStart(async () => {
|
|
151
|
+
await writeBuildTimeFiles(saved);
|
|
152
|
+
});
|
|
153
|
+
|
|
143
154
|
build.onEnd(async (res) => {
|
|
144
155
|
// console.log(`Build meta data: `, res);
|
|
145
156
|
console.log(`[dev-client:${saved.appName}] Build finished`);
|
|
@@ -180,7 +191,11 @@ const watchClient = async (saved, isDev, entryPoints, outbase) => {
|
|
|
180
191
|
jsxImportSource: 'lupine.web',
|
|
181
192
|
jsx: 'automatic',
|
|
182
193
|
target: ['chrome87'],
|
|
183
|
-
plugins: [
|
|
194
|
+
plugins: [
|
|
195
|
+
watchClientPlugin(saved),
|
|
196
|
+
pluginIfelse(ifPluginVars),
|
|
197
|
+
obfuscatePlugin(saved.isObfuscate, saved.skipObfuscateFiles || []),
|
|
198
|
+
],
|
|
184
199
|
});
|
|
185
200
|
|
|
186
201
|
isDev && (await ctx.watch());
|
|
@@ -316,6 +331,9 @@ const start = async () => {
|
|
|
316
331
|
isObfuscate,
|
|
317
332
|
defaultThemeName: 'light',
|
|
318
333
|
appName,
|
|
334
|
+
appDir,
|
|
335
|
+
webVersionFile: appCfg['webVersionFile'],
|
|
336
|
+
skipObfuscateFiles: (appCfg['skipObfuscateFiles'] || []).map((p) => path.normalize(p)),
|
|
319
337
|
httpPort,
|
|
320
338
|
serverRoot: serverRootPath,
|
|
321
339
|
outdirWeb: `${serverRootPath}/${appName}_web`,
|
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
bindRouter,
|
|
3
3
|
PageRouter,
|
|
4
4
|
bindTheme,
|
|
5
|
-
bindLang,
|
|
6
5
|
setDefaultPageTitle,
|
|
7
6
|
isFrontEnd,
|
|
8
7
|
debugWatch,
|
|
@@ -17,8 +16,6 @@ import { baseCss } from './styles/base-css';
|
|
|
17
16
|
if (isFrontEnd() && webEnv(ClientEnvKeys.NODE_ENV, '') === 'development') {
|
|
18
17
|
debugWatch(webEnv(ClientEnvKeys.API_PORT, 0));
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
bindLang('en', {});
|
|
22
19
|
bindTheme('light', pressThemes);
|
|
23
20
|
bindAppGlobalStyle('comm-css', baseCss, false, true);
|
|
24
21
|
setDefaultPageTitle('Lupine.js Doc');
|
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
bindRouter,
|
|
3
3
|
PageRouter,
|
|
4
4
|
bindTheme,
|
|
5
|
-
bindLang,
|
|
6
5
|
setDefaultPageTitle,
|
|
7
6
|
isFrontEnd,
|
|
8
7
|
debugWatch,
|
|
@@ -17,8 +16,6 @@ import { markdownConfig } from '../markdown-built/markdown-config';
|
|
|
17
16
|
if (isFrontEnd() && webEnv(ClientEnvKeys.NODE_ENV, '') === 'development') {
|
|
18
17
|
debugWatch(webEnv(ClientEnvKeys.API_PORT, 0));
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
bindLang('en', {});
|
|
22
19
|
bindTheme('light', pressThemes);
|
|
23
20
|
bindAppGlobalStyle('comm-css', baseCss, false, true);
|
|
24
21
|
setDefaultPageTitle('Doc Starter');
|
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
bindRouter,
|
|
3
3
|
PageRouter,
|
|
4
4
|
bindTheme,
|
|
5
|
-
bindLang,
|
|
6
5
|
setDefaultPageTitle,
|
|
7
6
|
isFrontEnd,
|
|
8
7
|
debugWatch,
|
|
@@ -17,8 +16,6 @@ import { baseCss } from './styles/base-css';
|
|
|
17
16
|
if (isFrontEnd() && webEnv(ClientEnvKeys.NODE_ENV, '') === 'development') {
|
|
18
17
|
debugWatch(webEnv(ClientEnvKeys.API_PORT, 0));
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
bindLang('en', {});
|
|
22
19
|
bindTheme('light', pressThemes);
|
|
23
20
|
bindAppGlobalStyle('comm-css', baseCss, false, true);
|
|
24
21
|
setDefaultPageTitle('Lupine.js Doc');
|
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
bindRouter,
|
|
3
3
|
PageRouter,
|
|
4
4
|
bindTheme,
|
|
5
|
-
bindLang,
|
|
6
5
|
setDefaultPageTitle,
|
|
7
6
|
isFrontEnd,
|
|
8
7
|
debugWatch,
|
|
@@ -17,8 +16,6 @@ import { markdownConfig } from '../markdown-built/markdown-config';
|
|
|
17
16
|
if (isFrontEnd() && webEnv(ClientEnvKeys.NODE_ENV, '') === 'development') {
|
|
18
17
|
debugWatch(webEnv(ClientEnvKeys.API_PORT, 0));
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
bindLang('en', {});
|
|
22
19
|
bindTheme('light', pressThemes);
|
|
23
20
|
bindAppGlobalStyle('comm-css', baseCss, false, true);
|
|
24
21
|
setDefaultPageTitle('Doc Starter');
|