Release 2.7.0: executable handbooks and native user-site workflows

This commit is contained in:
cflmy committed 2026-11-10 17:03:06 +08:00
1 parent aa0c4d0f55
commit d9aef957f7
562 files changed
+21064 -20387

No files matched your search

+10 -8
View File
@@ -1,14 +1,16 @@
# web-spa-app
Marqdo **native SPA**: list → detail → edit with client routes + `scope=memory` store. Zero author JS.
这个工程演示列表、详情、编辑和新建之间的浏览器路由。客户端用原生记录保存条目,以稳定 id 选择内容;刷新页面后恢复演示数据,不提供持久化存储。用户输入通过文本效果和结构化列表显示。
## Run
从仓库根目录先构建浏览器运行时,再启动可调用服务:
```bash
marqdo wasm build -o examples/web-spa-app/static
cd examples/web-spa-app
marqdo run index.mq.md
# http://127.0.0.1:18093
```sh
marqdo call skills/marqdo-dev/index.mq.md build_browser 'out="examples/web-spa-app/static"' --effects plugin,process.exec,fs.write --fs-root . --require-ok --json
marqdo call examples/web-spa-app/index.mq.md serve --effects plugin,fs.read,network.write --fs-root . --json
```
Design: [ext-web-spa.md](../../doc/design/ext-web-spa.md).
打开 http://127.0.0.1:18093。构建需要兼容的 WASM 工具链;缺少时按 [工具链手册](../../skills/marqdo-dev/toolchain.mq.md) 准备工作区编译器,并把返回的 compiler 传给 build_browser。不要用旧版运行时替代当前源码的构建。
工程入口 [index.mq.md](index.mq.md) 负责发现和服务;[components/index.mq.md](components/index.mq.md) 逐层组合导航和视图面板;[客户端源码](static/client.mq.md) 说明事件、路由和状态更新。修改内容从 Markdown 叶子开始,修改布局在组件中完成。
[开发手册](../../skills/marqdo-dev/index.mq.md) 的 test_browser 使用当前构建验证实际列表编辑、浏览器后退、输入转义和移动端布局。设计背景见 [SPA 设计](../../doc/design/ext-web-spa.md)。
@@ -0,0 +1,47 @@
---
markup: occlusion
title: Native control leaves
import:
component: ext/web/component/index.mq.md
table: lib/table.mq.md
---
These small leaves retain accessible ids and plain text. Parent components decide their arrangement; callbacks use the same ids in the client wiring.
## button
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| id | text | required | Stable id used by the client event table |
| label | text | required | Plain button text |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | One native button leaf |
Use `id` and `label` for one event target. A button has type button so it does not accidentally submit a surrounding form. Its label stays plain text, including quotes and angle brackets. This function describes a control and performs no click, navigation or DOM mutation. The same leaf is reused by navigation, detail actions and editor actions.
`attrs` =
| id | type |
|---|---|
| `id` | button |
Return *[Describe this native action button](component.element(kind="button", value=`label`, attrs=`attrs`, slot=`id`))*.
## text
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| id | text | required | Stable client text target |
| value | text | "" | Initial plain text |
| kind | text | "text" | Native text, title or pre kind |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | One native text target |
Use `id`, `value`="" and `kind`="text" to declare a simple display leaf. Initial content is escaped by the renderer, and later updates use browser set_text rather than HTML. Select pre for a log or title for the page heading. The control carries no sibling layout, state machine or event handler; its parent owns placement.
We **attrs = [Retain the stable text target](table.put(in=None, at="id", value=`id`))**.
Return *[Describe the native text leaf](component.element(kind=`kind`, value=`value`, attrs=`attrs`, slot=`id`))*.
@@ -0,0 +1,24 @@
---
markup: occlusion
title: SPA homepage assembly
import:
nav: nav.mq.md
panels: panels/index.mq.md
controls: controls.mq.md
client: ext/web/client/index.mq.md
table: lib/table.mq.md
---
The homepage composes navigation, heading, independent panels, status and the official runtime Resource.
## nodes
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Complete structured homepage without raw HTML |
This root contains component relationships only. Navigation and panels are ordinary child modules; their content and controls are already simple leaves. The official client runtime is a script Resource referencing built static assets, so no page HTML or author JavaScript is needed. The title and log use stable text targets. A valid node tree does not prove the WASM asset exists; build it and mount the static directory before opening the page.
We **navigation = [Assemble the navigation component](nav.nodes())** and **title = [Describe the changing page heading](controls.text(id="title", value="Items", kind="title"))** and **content = [Assemble the independent panels](panels.nodes())** and **log = [Describe the status text leaf](controls.text(id="log", value="spa ready", kind="pre"))** and **runtime = [Reference the official client program](client.nodes(source="/static/client.mq.md"))**.
We **head = [Keep navigation before the heading](table.concat(a=`navigation`, b=`title`))** and **body = [Keep panels after the heading](table.concat(a=`head`, b=`content`))** and **visible = [Place feedback after the panels](table.concat(a=`body`, b=`log`))**.
Return *[Retain the runtime as a separate Resource](table.concat(a=`visible`, b=`runtime`))*.
+21
View File
@@ -0,0 +1,21 @@
---
markup: occlusion
title: SPA navigation
import:
controls: controls.mq.md
component: ext/web/component/index.mq.md
table: lib/table.mq.md
---
Navigation composes reusable native buttons; the client owns their transitions.
## nodes
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Navigation containing Items and New controls |
The two buttons have independent stable ids and shared accessible button semantics. They contain labels only; selecting an item or opening an editor belongs to the client callbacks. Their parent is a nav region, so this file expresses one placement responsibility without duplicating the surrounding page.
We **items = [Describe the list action](controls.button(id="nav-list", label="Items"))** and **create = [Describe the creation action](controls.button(id="nav-new", label="New"))** and **children = [Keep their reading order](table.concat(a=`items`, b=`create`))**.
Return *[Place these actions in navigation](component.wrap(children=`children`, kind="nav", slot="navigation"))*.
@@ -0,0 +1,29 @@
---
markup: occlusion
title: Detail panel
import:
controls: ../controls.mq.md
component: ext/web/component/index.mq.md
table: lib/table.mq.md
---
Detail separates its changing text from the reusable Edit and Back action leaves.
## nodes
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Initially hidden detail panel |
The body has id detail-body and receives plain text after selection. Edit retains the selected stable id; Back returns to the list. Neither action's behavior is embedded in markup. The panel starts hidden and the shared client paint function explicitly controls its hidden attribute, using the same ids as the other panels.
We **body = [Describe the selected record's text target](controls.text(id="detail-body"))** and **edit = [Describe the edit action](controls.button(id="btn-edit", label="Edit"))** and **back = [Describe the list action](controls.button(id="btn-back", label="Back"))**.
We **buttons = [Keep the action order](table.concat(a=`edit`, b=`back`))** and **actions = [Group only these detail actions](component.wrap(children=`buttons`, kind="row", slot="detail-actions"))** and **children = [Keep data before actions](table.concat(a=`body`, b=`actions`))**.
`attrs` =
| id | hidden |
|---|---|
| view-detail | True |
Return *[Describe the independent detail panel](component.wrap(children=`children`, kind="section", attrs=`attrs`, slot="detail-panel"))*.
@@ -0,0 +1,37 @@
---
markup: occlusion
title: Editor panel
import:
controls: ../controls.mq.md
component: ext/web/component/index.mq.md
table: lib/table.mq.md
---
The editor is a native input plus reusable action leaves. Saving remains a client transition, not an implicit HTTP form.
## nodes
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Initially hidden editor with accessible label and native input |
The label's for attribute names edit-title, the same input read by the Save binding. The input keeps a plain text value. Save validates nonempty text in Marqdo before changing the record list; Cancel changes the route without calling that update. This component describes controls only and starts hidden. The parent keeps field content separate from the action row, allowing the existing responsive layout renderer to place them.
We **label_attrs = [Associate the label with its input](table.put(in=None, at="for", value="edit-title"))** and **label = [Describe the visible field label](component.element(kind="label", value="Title", attrs=`label_attrs`, slot="title-label"))**.
`input_attrs` =
| id | name | type |
|---|---|---|
| edit-title | title | text |
We **input = [Describe the native title input](component.element(kind="input", attrs=`input_attrs`, slot="title-input"))** and **field = [Keep label and input together](table.concat(a=`label`, b=`input`))**.
We **save = [Describe the save action](controls.button(id="btn-save", label="Save"))** and **cancel = [Describe the cancel action](controls.button(id="btn-cancel", label="Cancel"))** and **buttons = [Keep these editor actions ordered](table.concat(a=`save`, b=`cancel`))** and **actions = [Group the action row](component.wrap(children=`buttons`, kind="row", slot="editor-actions"))** and **children = [Place the field before its actions](table.concat(a=`field`, b=`actions`))**.
`attrs` =
| id | hidden |
|---|---|
| view-edit | True |
Return *[Describe the independent editor panel](component.wrap(children=`children`, kind="section", attrs=`attrs`, slot="editor-panel"))*.
@@ -0,0 +1,22 @@
---
markup: occlusion
title: SPA panel assembly
import:
listing: list.mq.md
detail: detail.mq.md
editor: edit.mq.md
table: lib/table.mq.md
---
This parent owns only the three sibling panel relationships.
## nodes
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Ordered list, detail and editor panel rows |
Each child owns one panel and names its own native controls. This function retains their structured values and stable order; the client independently selects visibility using hidden attributes. It does not render a second page or concatenate HTML. Changes to editor fields therefore remain inside the editor component instead of growing a single application string.
We **list = [Assemble the listing component](listing.nodes())** and **view = [Assemble the detail component](detail.nodes())** and **edit = [Assemble the editor component](editor.nodes())** and **first = [Retain list and detail order](table.concat(a=`list`, b=`view`))**.
Return *[Keep the editor as the third sibling](table.concat(a=`first`, b=`edit`))*.
@@ -0,0 +1,28 @@
---
markup: occlusion
title: List panel
import:
component: ext/web/component/index.mq.md
table: lib/table.mq.md
---
The existing list container is populated by the official bridge's structured render_list effect.
## nodes
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Initially visible list panel with its Markdown hint |
The empty native list provides id items for delegated clicks. Its actual entries come from native client records and use stable data-id attributes. The hint is ordinary Markdown and knows nothing about item data or routing. Only this parent sets the list panel's visibility; detail and editor remain separate components.
We **empty = [Start with no server-owned item rows](table.empty_list())** and **target = [Name the client-owned list container](table.put(in=None, at="id", value="items"))** and **list = [Describe the native unordered list](component.wrap(children=`empty`, kind="list", attrs=`target`, slot="items"))**.
We **hint = [Keep the instruction as ordinary Markdown](component.markdown(text="Click an item for detail.", slot="list-hint"))** and **children = [Place the hint after its list](table.concat(a=`list`, b=`hint`))**.
`attrs` =
| id | hidden |
|---|---|
| view-list | False |
Return *[Describe the visible list panel](component.wrap(children=`children`, kind="section", attrs=`attrs`, slot="list-panel"))*.
+28 -14
View File
@@ -1,25 +1,39 @@
---
markup: occlusion
title: web-spa-app
description: Native Marqdo SPA — list/detail/edit via WASM client routes + memory store
type: web
view: main
route: /
title: Marqdo SPA — Document layout and native client records
import:
home: components/index.mq.md
web: ext/web/web.mq.md
http: ext/net/http.mq.md
---
# main
The Document's main assembles View nodes; serve owns the process lifetime. Build current WASM assets into static before starting. From the checkout root, call serve with plugin,fs.read,network.write and --fs-root examples/web-spa-app. List, detail and edit behavior stays in static/client.mq.md, with native row records and the official bridge's list effect.
Full-page client app (zero author JS). Build assets first:
## main
```
marqdo wasm build -o examples/web-spa-app/static
```
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Homepage View rows |
**`embed` = > web.client_embed bridge="/static/marqdo-bridge.js" wasm="/static/marqdo_wasm.wasm" source="/static/client.mq.md" boot=True**
The page delegates layout to the component root. Follow that root into navigation and the three independent panels until reaching plain text, Markdown or a native control leaf. The runtime is a structured Resource. This function neither starts a server nor mixes client state into a page HTML string; serve later mounts the actual assets.
**`intro` = "<nav class='spa-nav'><button type='button' id='nav-list'>Items</button> <button type='button' id='nav-new'>New</button></nav><p id='title' class='spa-title'>Items</p><section id='view-list'><ul id='items'></ul><p class='hint'>Click an item for detail.</p></section><section id='view-detail' hidden><p id='detail-body'></p><p><button type='button' id='btn-edit'>Edit</button> <button type='button' id='btn-back'>Back</button></p></section><section id='view-edit' hidden><label>Title <input id='edit-title' /></label><p><button type='button' id='btn-save'>Save</button> <button type='button' id='btn-cancel'>Cancel</button></p></section><pre id='log'></pre>" + embed**
Return *[Assemble the inspectable homepage](home.nodes())*.
**page = > web.page title="Marqdo SPA" intro=intro layout="bare"**
**app = > web.app page=page host="127.0.0.1" port=18093**
**app = > app.static dir="static" mount="/static"**
**app = > app.redirect from="/item" to="/" permanent=False**
> `app`.listen
## serve
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| root | text | "examples/web-spa-app" | Explicit site directory from the checkout root |
| port | number | 18093 | Loopback listen port |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Blocking site listener result |
Use `root`="examples/web-spa-app" and `port`=18093. The site prepares declared Documents and Endpoints, mounts static, then binds the existing /item redirect through the network resource. The explicit localhost address matches this demonstration's scope. Browser transitions use history inside the page; the server redirect preserves the old direct /item entry behavior. This function blocks until its supervisor stops it, and missing assets remain a real build prerequisite.
We **app = [Prepare the declared page and static mount](web.prepare(root=`root`, host="127.0.0.1", port=`port`, static_dir="static"))** and **app = [Preserve the declared direct-entry redirect](http.redirect(app=`app`, from="/item", to="/", permanent=False))**.
Return *[Listen after all resources are bound](web.listen(app=`app`))*.
+187 -123
View File
@@ -1,33 +1,46 @@
---
markup: occlusion
title: spa client
description: routes table + memory store; list / detail / edit
title: SPA client with native records and structured browser effects
import:
browser: lib/browser.mq.md
table: lib/table.mq.md
text: lib/text.mq.md
---
The Document supplies native controls; this client supplies transitions between list, detail and edit. BrowserSession retains the entry state between callbacks. Stable ids keep selection separate from user text, and all dynamic list content is sent as records to the existing official bridge.
# main
Routes (documentation + titles). Runtime switches panels by `path`.
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Boot bindings, initial list, memory storage and panel effects |
`routes` =
This client keeps route, selection and records in the browser session's native Marqdo entry state. Titles are text; stable ids select records even when a title contains punctuation or is edited. The initial list is a row table rather than a newline string. Boot binds the existing controls, seeds the memory store and paints the first view immediately. Storage lasts for this client session; it is not a server database or durable reload persistence. Page geometry and labels live in separate Document components. Event callbacks only calculate state changes and return instructions for the official bridge.
| @ | 路径 | 面板 | 标题 |
|---|------|------|------|
| 1 | / | #view-list | Items |
| 2 | /item | #view-detail | Detail |
| 3 | /edit | #view-edit | Edit |
We **route = "/"** and **cur_id = ""** and **next_id = 2** to start with no selected record.
**`path` = "/"**
**`cur_id` = ""**
**`items` = "Alpha\nBeta"**
`items` =
`wire` =
| @ | id | title |
|---|---|---|
| 1 | "1" | Alpha |
| 2 | "2" | Beta |
We **bindings = [Read the explicit event wiring](_bindings())** and **wired = [Describe those control bindings](table.put(in=None, at="wire", value=`bindings`))**.
We **painted = [Paint the initial list without changing history](spa_paint(records=`items`, path=`route`, selected_id=`cur_id`, update_url=False))**.
After boot, return *[Keep bindings and initial effects together](browser.merge(a=`wired`, b=`painted`))*.
## _bindings
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Explicit delegated event rows for existing native controls |
These rows connect the Document's stable ids to Marqdo callbacks. List clicks are delegated to li[data-id], so replacing list entries does not discard the listener. Save reads the existing input value, and browser back/forward supplies path to on_pop. The bridge owns event dispatch; this table does not contain author JavaScript or page HTML. Every referenced callback below has an actual parameter and return contract.
`bindings` =
| @ | 选择器 | 事件 | 调用 | 委托 | 值选择器 |
|---|--------|------|------|------|----------|
|---|---|---|---|---|---|
| 1 | "#nav-list" | click | go_list | | |
| 2 | "#nav-new" | click | go_new | | |
| 3 | "#items" | click | open_item | "li[data-id]" | |
@@ -35,142 +48,193 @@ Routes (documentation + titles). Runtime switches panels by `path`.
| 5 | "#btn-back" | click | go_list | | |
| 6 | "#btn-save" | click | save_item | | "#edit-title" |
| 7 | "#btn-cancel" | click | go_list | | |
| 8 | "window" | popstate | on_pop | | |
| 8 | window | popstate | on_pop | | |
`seed` =
| op | key | value | scope |
|----|-----|-------|-------|
| set | spa-items | `items` | memory |
**`w` = > table.put in=None at="wire" value=wire**
**`s` = > browser.storage spec=seed**
**`boot` = > browser.merge a=w b=s**
**`ready` = > browser.set_text sel="#log" text="spa ready — click Items"**
*> browser.merge a=boot b=ready*
Return *bindings*.
## on_pop
+ `path`=""
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | "" | Location path supplied by the browser's popstate event |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Panel, list and storage effects without pushing a second history entry |
Use `path`="" from the event payload. Route state uses a different name so assigning the event value changes shared state instead of shadowing a path parameter. An empty payload leaves the current route unchanged. Painting a history event deliberately avoids spa_goto: pressing Back must not create another forward history record.
1. `path` != ""
**`path` = path**
2. *
****
*> spa_render*
We **route = [Retain the location supplied by the browser](path)**.
Return *[Repaint the restored route without another navigation](spa_paint(records=`items`, path=`route`, selected_id=`cur_id`, update_url=False))*.
## go_list
**`path` = "/"**
**`cur_id` = ""**
*> spa_render*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | List panel effects and one navigation instruction |
The Items and Back controls share this transition. Clear the selected id so the list does not retain an editing target, switch the shared route to the list path, then paint through the common function. Stored item data remains unchanged. The browser bridge performs the returned navigation and DOM instructions after the state update.
We **route = "/"** and **cur_id = ""**.
Return *[Show the current list](spa_paint(records=`items`, path=`route`, selected_id=`cur_id`))*.
## go_new
**`path` = "/edit"**
**`cur_id` = ""**
*> spa_render*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Empty editor effects and one navigation instruction |
Creating a record opens the editor without selecting an existing id. Save allocates an id only after nonempty text arrives, so merely opening or cancelling this panel does not insert a blank record. The common paint function puts an empty value in the native input and hides the other panels.
We **route = "/edit"** and **cur_id = ""**.
Return *[Open the empty editor](spa_paint(records=`items`, path=`route`, selected_id=`cur_id`))*.
## go_edit
**`path` = "/edit"**
*> spa_render*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Editor effects for the existing selection |
Editing keeps the selected id and changes only the current panel. The paint function looks up the current title from native rows, so a renamed record is still found by its stable id. Navigation and rendering remain instructions for the bridge; this callback neither writes a file nor calls a server.
We **route = "/edit"**.
Return *[Show the selected record in the editor](spa_paint(records=`items`, path=`route`, selected_id=`cur_id`))*.
## open_item
+ `data_id`=""
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| data_id | text | "" | Stable data-id from the delegated list item |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Detail effects, or None when no record id was clicked |
Use `data_id`="" from the delegated event. A click outside a real list entry must not invent a selection. Keep the id separately from its displayed title; quoted text, angle brackets and later renames therefore do not alter the event identity. Actual text is selected when the detail panel is painted.
1. `data_id` != ""
**`cur_id` = data_id**
**`path` = "/item"**
*> spa_render*
2. *
****
We **cur_id = [Retain the clicked record identity](data_id)** and **route = "/item"**.
Return *[Show the selected record](spa_paint(records=`items`, path=`route`, selected_id=`cur_id`))*.
If no record was clicked, return *None*.
## save_item
+ `value`=""
1. `value` != ""
1. `cur_id` != ""
**`parts` = > text.str_split s=items sep="\n"**
**`next` = ""**
- [item](遍历 parts 为 item)
1. `item` != ""
1. `item` == `cur_id`
1. `next` == ""
**`next` = value**
2. *
**`next` = next + "\n" + value**
2. *
1. `next` == ""
**`next` = item**
2. *
**`next` = next + "\n" + item**
**`items` = next**
**`cur_id` = value**
2. *
1. `items` == ""
**`items` = value**
2. *
**`items` = items + "\n" + value**
**`cur_id` = value**
**`path` = "/item"**
*> spa_render*
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | text | "" | Plain title from the native editor input |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Saved detail effects, or a title-required text effect |
Use `value`="" from the Save binding. Empty text returns a validation message before changing data. For an existing id, replace that row's title while retaining all ids and row order. For a new record, allocate the next native integer id and convert it to event text. The resulting records are kept in the session and mirrored to the memory store by painting. No HTML is generated from a title and no external interpreter performs the array update. Cancel bypasses this function entirely.
1. `value` == ""
Return *[Explain the required title](browser.set_text(sel="#log", text="title required"))*.
1. `cur_id` != ""
We **updated = [Start the replacement record list](table.empty_list())**.
- [Retain each record or replace only its title](for items as item)
1. access(`item`, "id") == `cur_id`
We **item = [Update the title without changing its id](table.put(in=`item`, at="title", value=`value`))**.
We **updated = [Retain this row in its original order](table.append(list=`updated`, item=`item`))**.
We **items = [Keep the completed native row list](updated)**.
2. *
*> browser.set_text sel="#log" text="title required"*
We **next_id = next_id + 1** and **cur_id = [Use the stable integer id as event text](str(next_id))**.
`item` =
| id | title |
|---|---|
| `cur_id` | `value` |
We **items = [Append the new native record](table.append(list=`items`, item=`item`))**.
We **route = "/item"** after a successful save.
Return *[Display and mirror the saved record](spa_paint(records=`items`, path=`route`, selected_id=`cur_id`))*.
## _list_rows
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| records | list | required | Native rows with id and title |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Bridge list items containing escaped text and stable data-id attributes |
Use `records` as the only list input. Each output item carries plain text plus an attribute record; the official bridge performs text escaping when it renders the list. The source never interpolates a title into an HTML tag. The delegated click id comes from the original record id, preserving selection independently of the displayed title.
We **rows = [Start the browser list descriptions](table.empty_list())**.
- [Describe every native record as a text item](for records as record)
We **label = [Read its plain title](access(`record`, "title"))** and **id = [Read its stable identity](access(`record`, "id"))** and **attrs = [Retain the delegated event id](table.put(in=None, at="data-id", value=`id`))**.
`row` =
| text | attrs |
|---|---|
| `label` | `attrs` |
We **rows = [Retain this structured list item](table.append(list=`rows`, item=`row`))**.
Return *rows*.
## spa_render
*> spa_paint*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Current panel, list, memory and navigation effects |
This named entry preserves the common rendering callback used by the demonstration. It delegates to the same paint function as direct transitions so panel selection, item text and memory storage stay consistent. No page string is compiled or evaluated here; the returned value is a normal bridge instruction record.
Return *[Paint the current native state](spa_paint(records=`items`, path=`route`, selected_id=`cur_id`))*.
## spa_paint
**`hide` = > table.put in=None at="hidden" value=""**
**`show` = > table.put in=None at="hidden" value=False**
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| records | list | required | Native item rows to display and mirror |
| path | text | required | Current client route |
| selected_id | text | required | Stable selected id, or empty for a new item |
| update_url | bool | True | False for history events and initial boot; True for user navigation |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | One complete structured effect map for the current native state |
Use `records`, `path`, `selected_id` and `update_url`=True for ordinary user navigation, and False when repainting an existing history entry. The selected row is found by id; all content remains plain text. Three panels receive explicit hidden flags, while title, detail and log text are described together. Browser merge replaces whole top-level effect keys, so combining those text targets first prevents later messages from discarding earlier text updates. List rows go through render_list, and the editor value changes only while that panel is active. Storage uses a record list in the memory scope. This function describes effects and performs no direct DOM, network or file access.
We **selected = [Find the native record by stable identity](table.find(list=`records`, key="id", value=`selected_id`))** and **body = ""** and **title = "Items"**.
1. `selected` != None
We **body = [Read the current selected title](access(`selected`, "title"))**.
1. `path` == "/item"
`attrs` =
We **title = "Detail"**.
1. `path` == "/edit"
We **title = "Edit"**.
We **list_flag = [Hide the list outside its route](table.put(in=None, at="hidden", value=(path != "/")))** and **detail_flag = [Show only the detail route](table.put(in=None, at="hidden", value=(path != "/item")))** and **edit_flag = [Show only the editor route](table.put(in=None, at="hidden", value=(path != "/edit")))**.
| #view-detail | #view-list | #view-edit |
|--------------|------------|------------|
| `show` | `hide` | `hide` |
**`title` = "Detail"**
**`body` = cur_id**
2. *
1. `path` == "/edit"
`attrs` =
`visibility` =
| #view-edit | #view-list | #view-detail |
|------------|------------|--------------|
| `show` | `hide` | `hide` |
**`title` = "Edit"**
**`body` = cur_id**
2. *
`attrs` =
| #view-list | #view-detail | #view-edit |
|---|---|---|
| `list_flag` | `detail_flag` | `edit_flag` |
`texts` =
| #title | #detail-body | #log |
|---|---|---|
| `title` | `body` | `path` |
We **ret = [Describe all text updates in one effect](browser.wrap(key="set_text", value=`texts`))** and **flags = [Describe the three panel visibility updates](browser.wrap(key="set_attr", value=`visibility`))** and **ret = [Keep independent text and attribute effects](browser.merge(a=`ret`, b=`flags`))**.
We **rows = [Describe record text without HTML](_list_rows(records=`records`))** and **listing = [Replace the existing list using structured items](browser.render_list(sel="#items", items=`rows`))** and **ret = [Retain the list update](browser.merge(a=`ret`, b=`listing`))**.
1. `path` == "/edit"
We **edit = [Populate the native editor input](browser.set_value(sel="#edit-title", value=`body`))** and **ret = [Retain the input value update](browser.merge(a=`ret`, b=`edit`))**.
1. `update_url`
We **navigation = [Navigate only for a user transition](browser.spa_goto(url=`path`))** and **ret = [Retain this history instruction](browser.merge(a=`ret`, b=`navigation`))**.
| #view-list | #view-detail | #view-edit |
|------------|--------------|------------|
| `show` | `hide` | `hide` |
**`title` = "Items"**
**`body` = ""**
**`parts` = > text.str_split s=items sep="\n"**
**`html` = ""**
- [item](遍历 parts 为 item)
1. `item` != ""
**`html` = html + "<li data-id=\"" + item + "\">" + item + "</li>"**
`persist` =
| op | key | value | scope |
|----|-----|-------|-------|
| set | spa-items | `items` | memory |
|---|---|---|---|
| set | spa-items | `records` | memory |
**`t` = > browser.set_text sel="#title" text=title**
**`a` = > browser.wrap key="set_attr" value=attrs**
**`ret` = > browser.merge a=t b=a**
**`list` = > browser.set_html sel="#items" html=html**
**`ret` = > browser.merge a=ret b=list**
**`d` = > browser.set_text sel="#detail-body" text=body**
**`ret` = > browser.merge a=ret b=d**
1. `path` == "/edit"
**`v` = > browser.set_value sel="#edit-title" value=cur_id**
**`ret` = > browser.merge a=ret b=v**
2. *
****
**`nav` = > browser.spa_goto url=path**
**`ret` = > browser.merge a=ret b=nav**
**`log` = > browser.set_text sel="#log" text=path**
**`ret` = > browser.merge a=ret b=log**
**`sav` = > browser.storage spec=persist**
*> browser.merge a=ret b=sav*
We **storage = [Mirror the native records in memory](browser.storage(spec=`persist`))**.
Return *[Keep the completed paint and memory instructions](browser.merge(a=`ret`, b=`storage`))*.