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

+28 -16
View File
@@ -1,21 +1,33 @@
# browser-app(路线 E)
# browser-app:可读源码中的浏览器工程
作者**零业务 JS**;逻辑用 **GFM 表格 + `lib/browser`**(无 `json.set` 链)。
从 [index.mq.md](index.mq.md) 开始阅读和执行,再沿 [组件入口](components/index.mq.md) 查看布局。首页拆成列表与计时,网络页再拆成输出、批量请求和 WebSocket 控件;内容在 content 中保留普通 Markdown,控件叶子使用原生 View 节点。
| 能力 | 演示 |
|------|------|
| 列表 CRUD | 添加 / 委托删除(`bag` + `set_html`) |
| storage | 草稿 localStorage |
| navigate | `/` `/about` `/net` + `popstate` |
| interval | 计时起停 |
| fetch_all | 并行两个 uuid |
| ws | `wss://echo.websocket.events`(依赖外网) |
| clipboard / download | 复制/下载列表文本 |
浏览器程序是 [static/app.mq.md](static/app.mq.md)。事件表、参数与返回契约就在回调旁边;操作用可读标签表达,列表文本始终保留为数据。样式入口为 [styles/index.mq.md](styles/index.mq.md),旁边的字面表保留旧页面全部 59 条声明,并给出 View 包装层的几何适配。
```bash
cargo build -p marqdo --release
./target/release/marqdo wasm build -o examples/browser-app
cd examples/browser-app && python3 -m http.server 8766
| 能力 | 实际行为与边界 |
|---|---|
| 列表 | 原生记录保留独立 ID;重复内容可单独删除,特殊字符使用 text,删除按钮使用 children |
| 草稿 | localStorage 保存输入框文本;完成回调确认保存,缺失值与空草稿分别处理;条目不跨刷新保存 |
| 历史 | 三个面板使用真实 pathname;popstate 只反映现有位置,不重复 push;直接打开 /about 或 /net 返回首页 |
| 计时 | 同名计时器替换,停止保留已累计次数 |
| 批量请求 | 两个公开 UUID 请求可能失败;输出每项真实状态、响应体或错误 |
| WebSocket | 本地 /live 原生回声资源;展示实际打开、消息、错误与关闭回调 |
| 剪贴板与下载 | 导出当前列表文本;即时提示仅确认已发起,浏览器策略仍可能阻止完成 |
在仓库根目录构建当前官方运行时,再启动原生服务器。需要已经可用的 Rust/WASM 工具链和本仓库工程、网络插件;缺少 WASM 标准库时先阅读 [工作区工具链手册](../../skills/marqdo-dev/toolchain.mq.md),并将返回的 compiler 传给 build_browser。生成资源与编译样式不作为业务源码提交。
```sh
marqdo call skills/marqdo-dev/index.mq.md build_browser 'out="examples/browser-app/static"' --effects plugin,process.exec,fs.write --fs-root . --require-ok --json
marqdo call examples/browser-app/index.mq.md serve --effects plugin,fs.write,network.write --fs-root examples/browser-app --require-ok --json
```
写法:[marqdo-dev](../../.cursor/skills/marqdo-dev/SKILL.md) · 路线图:[browser-wasm-e.md](../../doc/roadmap/browser-wasm-e.md)。
打开 http://127.0.0.1:18095。控件等待实际启动成功后启用;缺失资源返回明确失败,不能把加载说明当作已运行。服务只监听本机,示例不引入数据库、认证或持久条目存储。
开发验证同样通过可执行手册完成。下列浏览器任务原生复制当前运行时,并运行真实页面交互;它覆盖重复项、字面文本、草稿、历史、计时、导出内容、受控批量请求失败与本地 WebSocket 收发。Node/Playwright 是自动化测试的外联边界,文件读写与任务编排仍由 Marqdo 执行。
```sh
marqdo call skills/marqdo-dev/index.mq.md check 'path="examples/browser-app/index.mq.md"' --effects plugin --require-ok --json
marqdo call skills/marqdo-dev/index.mq.md test_browser --effects plugin,process.exec,fs.write --fs-root . --require-ok --json
```
后续修改先阅读 [编程规范](../../doc/library-development.mq.md),再修改一个职责的组件或回调。需要新的浏览器宿主能力时扩充正式 bridge 与标准库契约,保留真实浏览器验收;不在父组件中重新拼接 HTML 或业务 JavaScript。
-285
View File
@@ -1,285 +0,0 @@
---
markup: occlusion
title: browser-app (route E+)
description: list CRUD, storage, navigate, interval, fetch_all, ws — GFM + lib/browser
import:
browser: lib/browser.mq.md
table: lib/table.mq.md
text: lib/text.mq.md
---
# main
**`ticks` = 0**
**`bag` = ""**
**`path` = "/"**
**`ws_id` = "echo"**
`wire` =
| @ | 选择器 | 事件 | 调用 | 委托 | 值选择器 |
|---|--------|------|------|------|----------|
| 1 | "#add" | click | add | | "#draft" |
| 2 | "#save" | click | save_draft | | "#draft" |
| 3 | "#load" | click | load_draft | | |
| 4 | "#start-tick" | click | start_tick | | |
| 5 | "#stop-tick" | click | stop_tick | | |
| 6 | "#nav-home" | click | go_home | | |
| 7 | "#nav-about" | click | go_about | | |
| 8 | "#nav-net" | click | go_net | | |
| 9 | "window" | popstate | on_pop | | |
| 10 | "#items" | click | on_item | "button[data-id]" | |
| 11 | "#fetch-all" | click | do_fetch_all | | |
| 12 | "#ws-open" | click | ws_open | | |
| 13 | "#ws-send" | click | ws_send | | "#ws-msg" |
| 14 | "#ws-close" | click | ws_close | | |
| 15 | "#copy-log" | click | copy_log | | |
| 16 | "#dl-list" | click | dl_list | | |
`nav` =
| url | replace |
|-----|---------|
| / | False |
`st` =
| op | key | then |
|----|-----|------|
| get | mq-draft | on_draft |
`boot` =
| wire | navigate | storage |
|------|----------|---------|
| `wire` | `nav` | `st` |
*boot*
## add
+ `value`=""
1. `value` != ""
1. `bag` == ""
**`bag` = value**
2. *
**`bag` = bag + "\n" + value**
**`parts` = > text.str_split s=bag sep="\n"**
**`html` = ""**
- [item](遍历 parts 为 item)
1. `item` != ""
**`html` = html + "<li><span>" + item + "</span> <button type=\"button\" data-id=\"" + item + "\">删</button></li>"**
**`ret` = > browser.set_html sel="#items" html=html**
**`clr` = > browser.set_value sel="#draft" value=""**
**`ret` = > browser.merge a=ret b=clr**
**`f` = > browser.focus sel="#draft"**
*> browser.merge a=ret b=f*
2. *
****
## on_item
+ `data_id`=""
1. `data_id` != ""
**`parts` = > text.str_split s=bag sep="\n"**
**`next` = ""**
- [item](遍历 parts 为 item)
1. `item` != ""
1. `item` != `data_id`
1. `next` == ""
**`next` = item**
2. *
**`next` = next + "\n" + item**
**`bag` = next**
**`parts2` = > text.str_split s=bag sep="\n"**
**`html` = ""**
- [item](遍历 parts2 为 item)
1. `item` != ""
**`html` = html + "<li><span>" + item + "</span> <button type=\"button\" data-id=\"" + item + "\">删</button></li>"**
**`ret` = > browser.set_html sel="#items" html=html**
**`msg` = "removed " + data_id**
**`t` = > browser.set_text sel="#log" text=msg**
*> browser.merge a=ret b=t*
2. *
****
## save_draft
+ `value`=""
`st` =
| op | key | value |
|----|-----|-------|
| set | mq-draft | `value` |
**`msg` = > browser.set_text sel="#log" text="draft saved"**
**`s` = > browser.storage spec=st**
*> browser.merge a=msg b=s*
## load_draft
`st` =
| op | key | then |
|----|-----|------|
| get | mq-draft | on_draft |
*> browser.storage spec=st*
## on_draft
+ `ok`=True
+ `value`=""
+ `found`=False
1. `found`
**`ret` = > browser.set_value sel="#draft" value=value**
**`msg` = > browser.set_text sel="#log" text="draft loaded"**
*> browser.merge a=ret b=msg*
2. *
*> browser.set_text sel="#log" text="no draft"*
## start_tick
*> browser.interval ms=1000 then="on_tick" id="tick"*
## stop_tick
*> browser.clear_interval id="tick"*
## on_tick
+ `ok`=True
+ `id`=""
**`ticks` = ticks + 1**
**`label` = > str ticks**
*> browser.set_text sel="#tick" text=label*
## go_home
**`path` = "/"**
*> show_path*
## go_about
**`path` = "/about"**
*> show_path*
## go_net
**`path` = "/net"**
*> show_path*
## on_pop
+ `path`=""
**`path` = path**
*> show_path*
## show_path
**`hide` = > table.put in=None at="hidden" value=""**
**`show` = > table.put in=None at="hidden" value=False**
1. `path` == "/about"
`attrs` =
| #panel-about | #panel-home | #panel-net |
|--------------|-------------|------------|
| `show` | `hide` | `hide` |
2. *
1. `path` == "/net"
`attrs` =
| #panel-net | #panel-home | #panel-about |
|------------|-------------|--------------|
| `show` | `hide` | `hide` |
2. *
`attrs` =
| #panel-home | #panel-about | #panel-net |
|-------------|--------------|------------|
| `show` | `hide` | `hide` |
**`label` = "path: " + path**
**`ret` = > browser.set_text sel="#path" text=label**
**`a` = > browser.wrap key="set_attr" value=attrs**
**`ret` = > browser.merge a=ret b=a**
**`nav` = > browser.navigate url=path**
*> browser.merge a=ret b=nav*
## do_fetch_all
`reqs` =
| @ | url |
|---|-----|
| 1 | "https://httpbin.org/uuid" |
| 2 | "https://httpbin.org/uuid" |
**`msg` = > browser.set_text sel="#net-out" text="fetch_all…"**
**`fa` = > browser.fetch_all requests=reqs then="on_fetch_all"**
*> browser.merge a=msg b=fa*
## on_fetch_all
+ `ok`=True
+ `results`=None
*> browser.set_text sel="#net-out" text="fetch_all done (see console / results in session)"*
## ws_open
`w` =
| op | id | url | then_open | then_message | then_error | then_close |
|----|----|-----|-----------|--------------|------------|------------|
| open | `ws_id` | "wss://echo.websocket.events" | on_ws_open | on_ws_msg | on_ws_err | on_ws_close |
*> browser.ws spec=w*
## on_ws_open
+ `ok`=True
+ `id`=""
*> browser.set_text sel="#net-out" text="ws open"*
## on_ws_msg
+ `ok`=True
+ `data`=""
**`msg` = "ws ← " + data**
*> browser.set_text sel="#net-out" text=msg*
## on_ws_err
+ `ok`=False
+ `error`=""
**`msg` = "ws error: " + error**
*> browser.set_text sel="#net-out" text=msg*
## on_ws_close
+ `ok`=True
*> browser.set_text sel="#net-out" text="ws closed"*
## ws_send
+ `value`=""
`w` =
| op | id | data |
|----|----|------|
| send | `ws_id` | `value` |
*> browser.ws spec=w*
## ws_close
`w` =
| op | id |
|----|----|
| close | `ws_id` |
*> browser.ws spec=w*
## copy_log
**`msg` = > browser.set_text sel="#log" text="copied bag to clipboard"**
**`c` = > browser.clipboard text=bag**
*> browser.merge a=msg b=c*
## dl_list
**`msg` = > browser.set_text sel="#log" text="download started"**
**`d` = > browser.download body=bag filename="items.txt"**
*> browser.merge a=msg b=d*
@@ -0,0 +1,25 @@
---
markup: occlusion
title: About panel Markdown leaf
import:
component: ext/web/component/index.mq.md
fs: lib/fs.mq.md
---
## nodes
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Structured View rows for this component |
About is a terminal Markdown leaf, so further layout splitting would add no useful responsibility. Read its content through the native filesystem under the granted site root. The wrapper supplies only its client visibility id and initial hidden state. The page describes official host capabilities without embedding implementation JavaScript or an HTML shell.
We **source = [Read the literal About content](fs.read_text(path="content/about.md"))** and **children = [Keep it as ordinary Markdown](component.markdown(text=`source`, slot="about-content"))**.
`attrs` =
| id | hidden |
|---|---|
| panel-about | True |
Return *[Describe the initially hidden About panel](component.wrap(children=`children`, kind="section", attrs=`attrs`, slot="about"))*.
@@ -0,0 +1,70 @@
---
markup: occlusion
title: Native browser control leaves
import:
component: ext/web/component/index.mq.md
table: lib/table.mq.md
---
## button
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| id | text | required | Event target shared with the client wire table |
| label | text | required | Literal visible action |
| secondary | bool | False | Use the retained secondary palette |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | One disabled native button awaiting successful runtime boot |
Use `id`, `label` and `secondary`=False for one leaf. The button starts disabled, carries type button and is enabled only after the official runtime boots successfully. Its label remains plain text. The caller chooses placement; this helper neither binds a click handler nor hides a sibling layout. Keep its id aligned with static/app.mq.md.
`attrs` =
| id | type | disabled |
|---|---|---|
| `id` | button | True |
We **style = ""**.
1. `secondary`
We **style = "secondary"**.
Return *[Describe one literal native action](component.element(kind="button", value=`label`, attrs=`attrs`, style=`style`, slot=`id`))*.
## input
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| id | text | required | Client value target |
| hint | text | required | Plain placeholder text |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | One disabled text input |
Use `id` and `hint` for the draft or socket message. A native text input preserves its ordinary editing semantics and starts disabled until WASM is ready. The hint is placeholder text rather than a markup template. The component owns one control; the client selects its value through the wire table when the adjacent action is clicked.
`attrs` =
| id | type | placeholder | disabled |
|---|---|---|---|
| `id` | text | `hint` | True |
Return *[Describe this native value input](component.element(kind="input", attrs=`attrs`, slot=`id`))*.
## text
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| id | text | required | Stable output target |
| value | text | required | Literal initial text |
| kind | text | "text" | Native text or pre output |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | One escaped text leaf |
Use `id`, `value` and `kind`="text" for an output target. Select pre for the runtime log and ordinary text for the path, tick count or network outcome. Initial and later content stays literal: the renderer escapes this value and callbacks use set_text. This leaf declares no timer or network operation; those belong to the browser program.
We **attrs = [Retain the exact output target](table.put(in=None, at="id", value=`id`))**.
Return *[Describe the literal output leaf](component.element(kind=`kind`, value=`value`, attrs=`attrs`, slot=`id`))*.
@@ -0,0 +1,33 @@
---
markup: occlusion
title: Draft and list editor
import:
controls: ../controls.mq.md
component: ext/web/component/index.mq.md
table: lib/table.mq.md
---
## nodes
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Structured View rows for this component |
The editor contains one draft input, three draft actions, the export actions and an initially empty native list. The client owns records, stable identities and delegated deletion; no authored list HTML is stored here. Save persists only the draft under this origin. Copy and Download export current item text while list state remains in browser session memory.
We **heading = [Read the plain editor heading](component.markdown(text="## 待办"))** and **input = [Describe the exact draft target](controls.input(id="draft", hint="新项…"))** and **children = [Place input after its heading](table.concat(a=`heading`, b=`input`))**.
`actions` =
| @ | id | label | secondary |
|---|---|---|---|
| 1 | add | 添加 | False |
| 2 | save | 存草稿 | True |
| 3 | load | 读草稿 | True |
| 4 | copy-log | 复制列表 | True |
| 5 | dl-list | 下载列表 | True |
- [Describe each native action leaf](for actions as action)
We **button = [Keep this action separate from state](controls.button(id=access(action, "id"), label=access(action, "label"), secondary=access(action, "secondary")))** and **children = [Preserve the authored action order](table.concat(a=`children`, b=`button`))**.
We **empty = [Start the empty native list](table.empty_list())** and **attrs = [Retain the delegated list target](table.put(in=None, at="id", value="items"))** and **list = [Describe the list container](component.wrap(children=`empty`, kind="list", attrs=`attrs`, slot="items"))**.
Return *[Keep the list after its editing controls](table.concat(a=`children`, b=`list`))*.
@@ -0,0 +1,20 @@
---
markup: occlusion
title: Home panel assembly
import:
editor: editor.mq.md
timer: timer.mq.md
component: ext/web/component/index.mq.md
table: lib/table.mq.md
---
## nodes
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Structured View rows for this component |
Home has two independent children: the list editor and the named timer. This parent expresses only that ordering and the panel identity used by the client. Start with Home visible; About and Network are hidden in their own definitions. State and transport do not belong in layout tables, and changing one child does not require copying the entire page.
We **list = [Assemble the editor responsibility](editor.nodes())** and **clock = [Assemble the timer responsibility](timer.nodes())** and **children = [Keep the two home regions ordered](table.concat(a=`list`, b=`clock`))** and **attrs = [Name the client visibility target](table.put(in=None, at="id", value="panel-home"))**.
Return *[Describe the initially visible Home panel](component.wrap(children=`children`, kind="section", attrs=`attrs`, slot="home"))*.
@@ -0,0 +1,19 @@
---
markup: occlusion
title: Named timer controls
import:
controls: ../controls.mq.md
component: ext/web/component/index.mq.md
table: lib/table.mq.md
---
## nodes
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Structured View rows for this component |
This region describes the tick output and its two actions. The client increments retained state only when the named timer actually calls back. Start replaces a timer with the same id; Stop preserves the count. This layout performs no sleeping or counting on the server, and its native text output can be tested independently of timer scheduling.
We **label = [Describe the timer label](component.markdown(text="计时(秒):"))** and **counter = [Describe the initial count](controls.text(id="tick", value="0"))** and **start = [Describe the explicit start action](controls.button(id="start-tick", label="开始"))** and **stop = [Describe the explicit stop action](controls.button(id="stop-tick", label="停止", secondary=True))** and **content = [Keep label before count](table.concat(a=`label`, b=`counter`))** and **actions = [Keep the two actions together](table.concat(a=`start`, b=`stop`))** and **children = [Place actions beside their output](table.concat(a=`content`, b=`actions`))**.
Return *[Wrap this one timer responsibility](component.wrap(children=`children`, kind="row", slot="timer"))*.
@@ -0,0 +1,50 @@
---
markup: occlusion
title: Browser example recursive page assembly
import:
navigation: navigation.mq.md
home: home/index.mq.md
about: about.mq.md
network: network/index.mq.md
controls: controls.mq.md
component: ext/web/component/index.mq.md
fs: lib/fs.mq.md
table: lib/table.mq.md
---
## nodes
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Structured View rows for this component |
Read this root to see the whole page: introduction, path, navigation, three panels, feedback and runtime. Follow one import at a time until a child is a plain Markdown leaf or native control. Business values never become a page HTML string. The official runtime starts only after the server has staged the current built assets and the actual client source. Controls stay disabled until boot succeeds; missing resources therefore remain visible as a loading failure. The readiness target and enable selectors are typed resource metadata, not executable snippets. Styles reference the generated stylesheet produced by serve. Server discovery reads the terminal content leaves under the granted root; the browser receives the same ordered region tree.
We **source = [Read the plain introduction](fs.read_text(path="content/intro.md"))** and **intro = [Retain its Markdown](component.markdown(text=`source`, slot="intro"))** and **path = [Describe the initial pathname](controls.text(id="path", value="path: /"))** and **nav = [Assemble the authored destinations](navigation.nodes())** and **home = [Assemble list and timer](home.nodes())** and **about = [Read the About leaf](about.nodes())** and **network = [Assemble independent network controls](network.nodes())** and **log = [Describe literal runtime feedback](controls.text(id="log", value="loading…", kind="pre"))** and **style = [Reference the compiled declarative theme](component.asset(url="/static/theme.css", kind="stylesheet"))**.
`runtime_attrs` =
| type | data-mq-wasm | data-mq-source-url | data-mq-ready | data-mq-enable |
|---|---|---|---|---|
| module | "/static/marqdo_wasm.wasm" | "/static/app.mq.md" | "#log" | "#draft,#add,#save,#load,#start-tick,#stop-tick,#fetch-all,#ws-open,#ws-msg,#ws-send,#ws-close,#copy-log,#dl-list" |
We **runtime = [Declare the official module and readiness targets](component.asset(url="/static/marqdo-bridge.js", attrs=`runtime_attrs`, slot="runtime"))**.
`groups` =
| rows |
|---|
| `intro` |
| `path` |
| `nav` |
| `home` |
| `about` |
| `network` |
| `log` |
| `style` |
| `runtime` |
We **children = [Start the complete ordered page](table.empty_list())**.
- [Retain each independently inspectable region](for groups as group)
We **children = [Keep typed children in reading order](table.concat(a=`children`, b=`group`))**.
Return *[Wrap the recursive page once](component.wrap(children=`children`, slot="browser-app", style="browser-app"))*.
@@ -0,0 +1,36 @@
---
markup: occlusion
title: Three browser panel destinations
import:
component: ext/web/component/index.mq.md
table: lib/table.mq.md
---
## nodes
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Structured View rows for this component |
Navigation contains three ordinary links with stable ids. Their fragment destinations leave a readable fallback without issuing a server page request. The official wire table intercepts each click and requests one deliberate history entry. Back and Forward only repaint the already selected panel. This component does not own client state or generate navigation JavaScript.
`destinations` =
| @ | id | href | label |
|---|---|---|---|
| 1 | nav-home | "#/" | 首页 |
| 2 | nav-about | "#/about" | 关于 |
| 3 | nav-net | "#/net" | 网络 |
We **links = [Start the ordered native navigation](table.empty_list())**.
- [Declare each independently named destination](for destinations as destination)
We **label = [Read its literal label](access(destination, "label"))** and **id = [Read its stable event target](access(destination, "id"))** and **href = [Read its fallback destination](access(destination, "href"))**.
`attrs` =
| id | href |
|---|---|
| `id` | `href` |
We **link = [Describe this native destination](component.element(kind="link", value=`label`, attrs=`attrs`))** and **links = [Preserve navigation order](table.concat(a=`links`, b=`link`))**.
Return *[Place those links in a navigation region](component.wrap(children=`links`, kind="nav", slot="navigation"))*.
@@ -0,0 +1,27 @@
---
markup: occlusion
title: Network panel assembly
import:
socket: socket.mq.md
controls: ../controls.mq.md
component: ext/web/component/index.mq.md
table: lib/table.mq.md
---
## nodes
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Structured View rows for this component |
Network places plain explanatory content, the actual response output, a batch-fetch action and a local echo group. Batch requests retain the original public demonstration endpoint and may fail; ordered callback records show each status and body. Socket transport is local and independent. The panel starts hidden and the browser client alone selects it.
We **heading = [Describe the network responsibility](component.markdown(text="## 网络\n\n批量请求显示每项的实际状态;WebSocket 使用本机 /live 回声服务。"))** and **output = [Describe literal transport feedback](controls.text(id="net-out", value="idle"))** and **fetch = [Describe the batch request action](controls.button(id="fetch-all", label="fetch_all ×2 uuid"))** and **echo = [Assemble local socket controls](socket.nodes())** and **first = [Place feedback below its explanation](table.concat(a=`heading`, b=`output`))** and **last = [Keep fetch before socket interaction](table.concat(a=`fetch`, b=`echo`))** and **children = [Preserve the two network responsibilities](table.concat(a=`first`, b=`last`))**.
`attrs` =
| id | hidden |
|---|---|
| panel-net | True |
Return *[Describe the initially hidden Network panel](component.wrap(children=`children`, kind="section", attrs=`attrs`, slot="network"))*.
@@ -0,0 +1,18 @@
---
markup: occlusion
title: Local echo socket controls
import:
controls: ../controls.mq.md
table: lib/table.mq.md
---
## nodes
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Structured View rows for this component |
The echo group contains Open, the message input, Send and Close as separate native leaves. The server binds /live, and the official bridge sends the browser program’s transport instructions. Actual lifecycle callbacks update the network output. This component performs no handshake itself and does not rely on availability of a public echo service.
We **open = [Describe the connection action](controls.button(id="ws-open", label="WS 打开"))** and **message = [Describe exact message input](controls.input(id="ws-msg", hint="ws 消息"))** and **send = [Describe the explicit send action](controls.button(id="ws-send", label="WS 发送"))** and **close = [Describe the explicit close action](controls.button(id="ws-close", label="WS 关闭", secondary=True))** and **first = [Keep open before message entry](table.concat(a=`open`, b=`message`))** and **last = [Keep send before close](table.concat(a=`send`, b=`close`))**.
Return *[Keep the local echo interaction ordered](table.concat(a=`first`, b=`last`))*.
+5
View File
@@ -0,0 +1,5 @@
## 关于
从 `index.mq.md` 阅读工程入口,沿 `components/index.mq.md` 逐层查看布局,再阅读 `static/app.mq.md` 的事件与回调。
普通内容使用 Markdown,控件使用原生节点,列表保留带独立 ID 的记录。浏览器执行官方 bridge 提供的 DOM、历史、存储与网络能力,无需作者撰写业务 JavaScript。
+3
View File
@@ -0,0 +1,3 @@
# Marqdo browser-app
列表、草稿存储、历史导航、计时、批量请求、WebSocket、剪贴板和下载。页面和业务流程均由 Marqdo 源码表达,浏览器宿主能力由官方 bridge 提供。
-96
View File
@@ -1,96 +0,0 @@
<!DOCTYPE html>
<html lang="zh-Hans">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Marqdo · browser-app (route E)</title>
<style>
:root { --ink: #1a1f1c; --paper: #e8efe6; --accent: #2f6f4e; --muted: #5a6b60; }
* { box-sizing: border-box; }
body {
margin: 0; min-height: 100vh; font-family: "IBM Plex Sans", "Noto Sans SC", sans-serif;
color: var(--ink);
background: linear-gradient(165deg, #f3f7f2, var(--paper));
padding: 2rem clamp(1rem, 4vw, 3rem);
}
h1 { font-family: "IBM Plex Serif", "Noto Serif SC", serif; margin: 0 0 0.35rem; }
.lead { color: var(--muted); max-width: 42rem; }
nav a { margin-right: 0.75rem; color: var(--accent); }
section { margin: 1.5rem 0; padding: 1rem 0; border-top: 1px solid #c5d4c9; }
#path { font-family: ui-monospace, monospace; color: var(--muted); }
#items { list-style: none; padding: 0; margin: 0.75rem 0; }
#items li {
display: flex; align-items: center; gap: 0.5rem;
padding: 0.4rem 0.6rem; margin-bottom: 0.35rem;
background: rgba(255,255,255,0.65); border: 1px solid #b7c7bb;
}
#items button { margin-left: auto; }
input[type="text"] { padding: 0.45rem 0.65rem; border: 1px solid #b7c7bb; width: min(16rem, 70%); }
button {
padding: 0.45rem 0.9rem; border: 0; background: var(--accent); color: #f5faf6;
font: inherit; cursor: pointer; margin: 0.2rem 0.35rem 0.2rem 0;
}
button.secondary { background: #3a4740; }
#tick, #net-out { font-variant-numeric: tabular-nums; }
#net-out {
min-height: 2.5rem; padding: 0.6rem 0.75rem; background: rgba(255,255,255,0.55);
border: 1px solid #b7c7bb; white-space: pre-wrap; word-break: break-all;
}
pre {
margin-top: 1rem; padding: 0.85rem 1rem; background: #122018; color: #d7eadc;
font-size: 0.8rem; overflow: auto; max-width: 42rem;
}
.err { color: #ffb4a8; }
</style>
</head>
<body>
<h1>Marqdo browser-app</h1>
<p class="lead">路线 E:列表 CRUD / storage / navigate / interval / fetch_all / ws / clipboard / download — <strong>无作者业务 JS</strong>。</p>
<p id="path">path: /</p>
<nav>
<a href="#/" id="nav-home">首页</a>
<a href="#/about" id="nav-about">关于</a>
<a href="#/net" id="nav-net">网络</a>
</nav>
<section id="panel-home">
<h2>待办</h2>
<input id="draft" type="text" placeholder="新项…" disabled />
<button id="add" type="button" disabled>添加</button>
<button id="save" class="secondary" type="button" disabled>存草稿</button>
<button id="load" class="secondary" type="button" disabled>读草稿</button>
<button id="copy-log" class="secondary" type="button" disabled>复制列表</button>
<button id="dl-list" class="secondary" type="button" disabled>下载列表</button>
<ul id="items"></ul>
<p>计时:<span id="tick">0</span>s
<button id="start-tick" type="button" disabled>开始</button>
<button id="stop-tick" class="secondary" type="button" disabled>停止</button>
</p>
</section>
<section id="panel-about" hidden>
<h2>关于</h2>
<p>作者只写 <code>app.mq.md</code>。官方 bridge 提供 DOM / 路由 / storage / ws / fetch_all 等宿主能力。</p>
</section>
<section id="panel-net" hidden>
<h2>网络</h2>
<p id="net-out">idle</p>
<button id="fetch-all" type="button" disabled>fetch_all ×2 uuid</button>
<button id="ws-open" type="button" disabled>WS 打开</button>
<input id="ws-msg" type="text" placeholder="ws 消息" disabled />
<button id="ws-send" type="button" disabled>WS 发送</button>
<button id="ws-close" class="secondary" type="button" disabled>WS 关闭</button>
</section>
<pre id="log">loading…</pre>
<script
type="module"
src="./marqdo-bridge.js"
data-mq-wasm="./marqdo_wasm.wasm"
data-mq-source-url="./app.mq.md"
data-mq-ready="#log"
data-mq-enable="#draft,#add,#save,#load,#start-tick,#stop-tick,#fetch-all,#ws-open,#ws-msg,#ws-send,#ws-close,#copy-log,#dl-list"
></script>
</body>
</html>
+55
View File
@@ -0,0 +1,55 @@
---
markup: occlusion
type: web
view: main
route: /
title: Marqdo browser-app
import:
page: components/index.mq.md
styles: styles/index.mq.md
web: ext/web/web.mq.md
http: ext/net/http.mq.md
socket: ext/net/websocket.mq.md
fs: lib/fs.mq.md
result: lib/result.mq.md
---
This is the callable engineering entry. Follow components/index.mq.md for recursive layout, static/app.mq.md for browser state and effects, and styles/index.mq.md for the retained theme. Plain content is Markdown; controls and resources remain native structured values. There is no authored HTML host or business JavaScript. Serve runs from the checkout root with --fs-root examples/browser-app.
## main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Inspectable native page rows |
The Document delegates page assembly to its component root. Home, About and Network are client panels within this one page, with their own independently readable components. The client controls visibility and history while ordinary content remains Markdown. This function does not start a server, fetch public endpoints or open a socket. Read the returned tree as layout data, and call serve for a real running application.
Return *[Assemble the recursive browser demonstration](page.nodes())*.
## serve
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| root | text | "examples/browser-app" | Explicit site directory relative to the checkout |
| port | number | 18095 | Loopback listen port |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Blocking listener or missing-asset failure |
Use `root`="examples/browser-app" and `port`=18095 with plugin,fs.write,network.write and the site filesystem root. Build current browser assets through the development handbook first. Both generated assets must exist before theme compilation or listening; missing files produce an actionable Result. The native filesystem writes only the explicit compiled stylesheet. No Python static server or generated shell workflow is needed.
Discovery prepares the Document and the static mount. Direct /about and /net visits redirect to the entry page, matching the transient panel-state model; Back and Forward inside a live page retain their actual history positions. A separate local network resource binds /live for anonymous demonstration echo. This loopback example does not authenticate or persist item records. Keep every returned app value and listen only after binding all resources.
`assets` =
| file |
|---|
| static/marqdo_wasm.wasm |
| static/marqdo-bridge.js |
- [Require current official browser resources](for assets as file)
1. not [The required runtime asset exists](fs.exists(path=`file`))
Return *[Expose the actual build prerequisite](result.error(code="browser_app.assets", message="call build_browser and stage its assets in examples/browser-app/static before serve", operation="serve"))*.
We **css = [Compile the retained declarative theme](styles.css())** and **[Write only the generated stylesheet](fs.atomic_write(path="static/theme.css", text=`css`))** and **app = [Discover the native Document and static assets](web.prepare(root=`root`, host="127.0.0.1", port=`port`, static_dir="static"))** and **app = [Retain a direct About entry](http.redirect(app=`app`, from="/about", to="/", permanent=False))** and **app = [Retain a direct Network entry](http.redirect(app=`app`, from="/net", to="/", permanent=False))** and **app = [Bind the actual local echo resource](socket.route(app=`app`, path="/live", mode="echo", require_auth=False))**.
Return *[Listen after the real resources are ready](web.listen(app=`app`))*.
File diff suppressed because it is too large. Load diff
+568
View File
@@ -0,0 +1,568 @@
---
markup: occlusion
title: Browser effects — native records and explicit completion
description: list CRUD, storage, navigate, interval, fetch_all, ws — GFM + lib/browser
import:
browser: lib/browser.mq.md
table: lib/table.mq.md
text: lib/text.mq.md
---
# main
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Initial browser view/state record |
This entry prepares browser instructions; it does not itself fetch a URL or manipulate a server filesystem. The host page must supply the selectors listed below. List state uses native records with stable ids, keeping duplicate text and literal newlines independent. The wire table maps each UI event to one actual callback, including delegated item buttons, history navigation, timer controls, parallel fetches and a named WebSocket connection.
Event declarations contain no user values interpolated into code. Input values flow through callback parameters while the server page remains a separate document.
The returned boot record combines event registration and a storage lookup, without pushing an initial history entry. The browser bridge applies those instructions and dispatches later events into the callbacks. Draft text, tick count, route and socket identifier belong to that browser instance. Storage callbacks complete asynchronously; the initial return is not proof that a saved draft was found.
We **ticks = 0** as the retained count before the first real timer event.
We **items = [Start native list state](table.empty_list())** and **next_id = 1** for independent record identities.
We **route_path = "/"** as this browser instance’s panel state.
We **ws_id = "echo"** as the one named local connection.
`wire` =
| @ | 选择器 | 事件 | 调用 | 委托 | 值选择器 |
|---|--------|------|------|------|----------|
| 1 | "#add" | click | add | | "#draft" |
| 2 | "#save" | click | save_draft | | "#draft" |
| 3 | "#load" | click | load_draft | | |
| 4 | "#start-tick" | click | start_tick | | |
| 5 | "#stop-tick" | click | stop_tick | | |
| 6 | "#nav-home" | click | go_home | | |
| 7 | "#nav-about" | click | go_about | | |
| 8 | "#nav-net" | click | go_net | | |
| 9 | "window" | popstate | on_pop | | |
| 10 | "#items" | click | on_item | "button[data-id]" | |
| 11 | "#fetch-all" | click | do_fetch_all | | |
| 12 | "#ws-open" | click | ws_open | | |
| 13 | "#ws-send" | click | ws_send | | "#ws-msg" |
| 14 | "#ws-close" | click | ws_close | | |
| 15 | "#copy-log" | click | copy_log | | |
| 16 | "#dl-list" | click | dl_list | | |
`st` =
| op | key | then |
|----|-----|------|
| get | mq-draft | on_draft |
`boot` =
| wire | storage |
|---|---|
| `wire` | `st` |
After these steps, return *boot*.
## add
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | text | "" | Exact draft text supplied by the add control |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Native list refresh, input clear and focus; None for empty text |
Use `value`="" from the input. Retain each nonempty value exactly as one record, including quotes, angle brackets or a literal newline. A monotonically assigned id separates duplicate titles; deleting one must not erase its siblings. This direct callback updates entry state, then passes those records explicitly to the pure renderer. No business value is interpolated into HTML.
The input clears and regains focus after a real local addition. An empty string returns None without changing records or consuming an id. This list is session memory; only the separately saved draft uses browser storage.
1. `value` == ""
Return *None* because there is no new item.
We **id = [Assign an independent stable identity](str(next_id))** and **next_id = next_id + 1**.
`record` =
| id | text |
|---|---|
| `id` | `value` |
We **items = [Retain the actual text record](table.append(list=`items`, item=`record`))** and **view = [Render typed labels and delete controls](_list(records=`items`))** and **clear = [Clear the completed input](browser.set_value(sel="#draft", value=""))** and **focus = [Return to the draft control](browser.focus(sel="#draft"))**.
We **view = [Keep the independent list and value effects](browser.merge(a=`view`, b=`clear`))**.
Return *[Keep focus with the completed list update](browser.merge(a=`view`, b=`focus`))*.
## on_item
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| data_id | text | "" | Stable id supplied by the delegated delete button |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Remaining native records and removal feedback, or None for an unknown id |
Use `data_id`="" from button[data-id]. Compare identities rather than text, so duplicate values and values containing newlines stay independent. Preserve remaining order and do nothing for an empty or unknown id. The renderer receives retained records explicitly; it does not infer client state inside a normal helper call.
A deletion rebuilds the same list through typed controls and reports the removed id as text. It neither modifies a saved draft nor changes timer, transport or route state. Ids are not recycled after deletion, avoiding a stale event selecting a different later item.
1. `data_id` == ""
Return *None* for an absent selection.
We **remaining = [Start the retained row order](table.empty_list())**.
- [Keep every record except the selected identity](for items as item)
1. access(`item`, "id") != `data_id`
We **remaining = [Keep this independent record](table.append(list=`remaining`, item=`item`))**.
1. len(`remaining`) == len(`items`)
Return *None* because no selected identity exists.
We **items = remaining** and **view = [Render the actual retained rows](_list(records=`items`))** and **message = "removed " + data_id** and **status = [Describe the observed local removal](browser.set_text(sel="#log", text=`message`))**.
Return *[Keep list and feedback together](browser.merge(a=`view`, b=`status`))*.
## save_draft
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | text | "" | Exact text selected from the draft input |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Storage write request; completion arrives at on_saved |
Use `value`="" from the draft control. The storage record names the local key and its completion callback. Return the request immediately; only on_saved can announce a successful write. An intentionally empty draft is valid and differs from an absent key. Storage belongs to this browser origin, while list records stay in session memory. Returning this record does not write server files or grant process access.
`request` =
| op | key | value | then |
|---|---|---|---|
| set | mq-draft | `value` | on_saved |
Return *[Ask the browser to persist the exact draft](browser.storage(spec=`request`))*.
## load_draft
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Storage read request with an explicit completion callback |
Request mq-draft from this browser origin. The callback distinguishes a missing key, an empty saved value and a failed read. No input is cleared while the read is pending, and this operation never replaces the native item list. The same read runs at boot, so a reload restores the saved draft without claiming to persist list records.
`request` =
| op | key | then |
|---|---|---|
| get | mq-draft | on_draft |
Return *[Request the stored draft and its actual outcome](browser.storage(spec=`request`))*.
## on_draft
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| ok | bool | True | Actual storage-read completion |
| value | text | "" | Stored draft text, including an intentionally empty value |
| found | bool | False | Whether the key actually existed |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Restored value and feedback, or actual missing/failure feedback |
Use `ok`=True, `value`="" and `found`=False from storage. A missing key differs from a stored empty draft, and an unsuccessful read must not be described as absence. Restore the exact value only after a successful read with found=True. This changes the draft input, not the native item list, and never interprets the stored text as code.
1. not `ok`
Return *[Keep a failed read visible](browser.set_text(sel="#log", text="draft read failed"))*.
1. not `found`
Return *[Keep an absent draft visible](browser.set_text(sel="#log", text="no draft"))*.
We **value_effect = [Restore exact stored draft text](browser.set_value(sel="#draft", value=`value`))** and **status = [Confirm the observed read](browser.set_text(sel="#log", text="draft loaded"))**.
Return *[Keep the actual value and feedback](browser.merge(a=`value_effect`, b=`status`))*.
## start_tick
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | One named repeating timer instruction |
Start tick at one-second intervals. The bridge replaces a timer with the same id, so repeated Start clicks do not accumulate independent clocks. Each callback increments the session counter once. This returns an instruction; it is neither a blocking sleep nor proof that one second has passed. Stop cancels future callbacks and preserves the accumulated display.
Return *[Start or replace the one named timer](browser.interval(ms=1000, then="on_tick", id="tick"))*.
## stop_tick
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Cancellation of the named timer |
Cancel tick through its explicit id. Calling Stop before Start is harmless, and stopping does not reset the visible count or alter other timers. A later Start resumes counting from retained state. The browser owns the timer handle; authors do not keep a JavaScript handle or generate a client program to clear it.
Return *[Cancel future callbacks for this timer](browser.clear_interval(id="tick"))*.
## on_tick
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| ok | bool | True | Whether this timer callback is valid |
| id | text | "" | Actual named timer id |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Updated count, or None for a failed/unrelated callback |
Use `ok`=True and `id`="" from the timer. Count only successful events belonging to tick; unrelated callbacks must not change this counter. Retained ticks belongs to the direct browser callback, rather than being supplied by the event. A manual call to this function constructs the same text effect but does not prove that a real timer fired.
1. not `ok` or `id` != "tick"
Return *None* for an unrelated timer outcome.
We **ticks = ticks + 1** and **label = [Format the actual accumulated count](str(ticks))**.
Return *[Display that observed timer count](browser.set_text(sel="#tick", text=`label`))*.
## go_home
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Selected panel effects and one actual navigation request |
Select / from its authored navigation control. This direct callback updates the retained panel state and requests exactly one history entry. The helper receives the path explicitly rather than assuming an ordinary call captures entry bindings. Back/Forward uses on_pop, which renders without navigation. No server request or page HTML is constructed here.
We **route_path = "/"**.
Return *[Render and request this one deliberate navigation](_view(route=`route_path`, push=True))*.
## go_about
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Selected panel effects and one actual navigation request |
Select /about from its authored navigation control. This direct callback updates the retained panel state and requests exactly one history entry. The helper receives the path explicitly rather than assuming an ordinary call captures entry bindings. Back/Forward uses on_pop, which renders without navigation. No server request or page HTML is constructed here.
We **route_path = "/about"**.
Return *[Render and request this one deliberate navigation](_view(route=`route_path`, push=True))*.
## go_net
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Selected panel effects and one actual navigation request |
Select /net from its authored navigation control. This direct callback updates the retained panel state and requests exactly one history entry. The helper receives the path explicitly rather than assuming an ordinary call captures entry bindings. Back/Forward uses on_pop, which renders without navigation. No server request or page HTML is constructed here.
We **route_path = "/net"**.
Return *[Render and request this one deliberate navigation](_view(route=`route_path`, push=True))*.
## on_pop
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | "" | Actual browser pathname, including optional query string |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | History-selected panel effects without pushing history again |
Use `path`="" from the real popstate callback. Keep its normalized panel route in the differently named entry state, avoiding accidental shadowing of a callback parameter. The browser has already selected this history entry, so returning navigate would add an incorrect new entry. Query text does not choose a different panel; only the known pathname is used.
We **parts = [Separate the pathname from query text](text.str_split(s=`path`, sep="?"))** and **route_path = [Keep the actual panel path](table.first(list=`parts`))**.
Return *[Reflect the actual history position](_view(route=`route_path`))*.
## show_path
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Current panel visibility and label without history mutation |
This direct browser callback reads retained route_path and delegates pure rendering with explicit input. It never pushes another history entry, so a repaint cannot trap Back/Forward. Call the navigation callbacks to request a new route. Server routing and page structure remain separate responsibilities; unknown browser paths select the home panel.
Return *[Refresh the retained panel without navigating](_view(route=`route_path`))*.
## do_fetch_all
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | The value explicitly returned below; conditional returns follow the selected branch |
Queue two independent browser fetches and return an immediate loading message together with the request instruction. Results arrive through on_fetch_all; this initial return does not contain either HTTP response. The request table keeps both URLs visible and avoids generating JavaScript to construct the batch.
The example endpoint is external and may fail or be unavailable. Consumers must inspect the actual callback records rather than count request declarations as successful responses. Browser network policy still applies; no backend file or shell operation is authorized by this instruction.
`reqs` =
| @ | url |
|---|-----|
| 1 | "https://httpbin.org/uuid" |
| 2 | "https://httpbin.org/uuid" |
We **msg = [Describe the pending batch](browser.set_text(sel="#net-out", text="fetch_all…"))** and **requests = [Request both actual HTTP outcomes](browser.fetch_all(requests=`reqs`, then="on_fetch_all"))**.
Return *[Keep pending feedback with its asynchronous requests](browser.merge(a=`msg`, b=`requests`))*.
## on_fetch_all
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| ok | bool | True | Whether the batch callback itself completed |
| results | any | None | Ordered per-request ok/status/body/error records |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Actual per-request outcomes shown as plain text |
Use `ok`=True and `results`=None from the bridge. A completed batch can still contain failed HTTP or network operations; the outer callback flag does not make each record successful. Show the real ordered records, including status, body and errors, rather than a fixed completion message. Text output cannot become HTML or a browser command.
A missing result list stays visibly unavailable. Public endpoints remain demonstration dependencies; local tests supply controlled responses and a failure. This callback does not retry a request or replace its body with a predetermined answer.
1. not `ok`
Return *[Keep batch failure visible](browser.set_text(sel="#net-out", text="fetch_all failed"))*.
1. `results` == None
Return *[Keep absent results distinct](browser.set_text(sel="#net-out", text="fetch_all returned no results"))*.
We **message = [Retain actual request outcomes](str(results))**.
Return *[Display observed successes and failures literally](browser.set_text(sel="#net-out", text=`message`))*.
## ws_open
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Named local WebSocket request and lifecycle callbacks |
Open the site’s /live echo resource under the explicit echo id. A relative URL uses the current origin and its transport security, allowing the example to run without a public echo provider. The server separately binds this native network resource. Returning the record only requests a connection; open, message, error and close callbacks describe actual transport outcomes. Subsequent send and close instructions reuse the same id.
`request` =
| op | id | url | then_open | then_message | then_error | then_close |
|---|---|---|---|---|---|---|---|
| open | `ws_id` | "/live" | on_ws_open | on_ws_msg | on_ws_err | on_ws_close |
Return *[Request the local echo connection](browser.ws(spec=`request`))*.
## on_ws_open
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| ok | bool | True | Actual connection completion |
| id | text | "" | Connected socket id |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Confirmed connection text, or None for a failed/unrelated callback |
Use `ok`=True and `id`="" from the real transport. Accept only the named echo socket; a different resource cannot announce this widget ready. This callback confirms the handshake, while sending still requires a separate user action. It neither invents a received message nor marks a requested connection successful before the bridge reports it.
1. not `ok` or `id` != `ws_id`
Return *None* for an unrelated connection.
Return *[Confirm the observed handshake](browser.set_text(sel="#net-out", text="ws open"))*.
## on_ws_msg
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| ok | bool | True | Actual message completion |
| data | text | "" | Exact received text |
| id | text | "" | Receiving socket id |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Literal received message, or None for a failed/unrelated callback |
Use `ok`=True, `data`="" and `id`="" from the echo connection. Preserve the complete received text, including quotes and angle brackets. Display it through set_text so a message is data rather than page markup. Receipt is independent of the send click: the remote resource may respond later or close without replying.
1. not `ok` or `id` != `ws_id`
Return *None* for an unrelated message.
We **message = "ws ← " + data**.
Return *[Display the actual echo as plain text](browser.set_text(sel="#net-out", text=`message`))*.
## on_ws_err
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| ok | bool | False | Failure flag supplied by the bridge |
| error | text | "" | Actual transport failure text |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Visible transport failure |
Use `ok`=False and `error`="" from the transport callback. Keep the actual error text in the output rather than substituting a success message. The callback performs no automatic reconnect and sends no pending message. Reopening is an explicit user operation; failures remain inspectable while the rest of the page can continue operating.
We **message = "ws error: " + error**.
Return *[Expose the actual connection failure](browser.set_text(sel="#net-out", text=`message`))*.
## on_ws_close
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| ok | bool | True | Actual close callback flag |
| id | text | "" | Closed socket id |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Observed close text, or None for an unrelated socket |
Use `ok`=True and `id`="" after the bridge observes closure. The named socket may close because of the user’s request or the server. This is a lifecycle observation and does not itself initiate another close or reopen. Leave list state, draft and timer untouched so transport changes remain independent of local page work.
1. `id` != `ws_id`
Return *None* for an unrelated socket.
Return *[Report the observed connection closure](browser.set_text(sel="#net-out", text="ws closed"))*.
## ws_send
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | text | "" | Exact text selected from the message input |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Send request for the existing named socket |
Use `value`="" as the message payload. Sending preserves literal text and addresses the existing echo socket; it does not create a second hidden connection. Open first and wait for the real connection callback. The request is not an echo result: only on_ws_msg displays a received response, and transport failures remain visible through the bridge.
`request` =
| op | id | data |
|---|---|---|
| send | `ws_id` | `value` |
Return *[Send exact text through the named connection](browser.ws(spec=`request`))*.
## ws_close
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Close request for the named socket |
Ask the bridge to close echo, reusing the same identity as open and send. The close callback supplies the observed lifecycle result. Returning this instruction does not delete page records or cancel the independent timer. Closing an absent connection is harmless; opening a later connection remains an explicit user action.
`request` =
| op | id |
|---|---|
| close | `ws_id` |
Return *[Request closure of this connection](browser.ws(spec=`request`))*.
## copy_log
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Clipboard request and truthful queued feedback |
Export the retained item texts in their current order, including duplicate values and literal newlines. The native records remain unchanged. This browser capability is a request: policy, user activation or the destination environment may prevent completion. The bridge exposes errors, and the immediate feedback says queued because no completion callback confirms a final clipboard write or saved file.
We **plain = [Read the current literal list export](_plain(records=`items`))** and **request = [Request clipboard delivery](browser.clipboard(text=`plain`))** and **status = [Describe only the requested operation](browser.set_text(sel="#log", text="clipboard request queued"))**.
Return *[Keep the request and its truthful feedback](browser.merge(a=`request`, b=`status`))*.
## dl_list
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Download request and truthful queued feedback |
Export the retained item texts in their current order, including duplicate values and literal newlines. The native records remain unchanged. This browser capability is a request: policy, user activation or the destination environment may prevent completion. The bridge exposes errors, and the immediate feedback says queued because no completion callback confirms a final clipboard write or saved file.
We **plain = [Read the current literal list export](_plain(records=`items`))** and **request = [Request the plain-text download](browser.download(body=`plain`, filename="items.txt"))** and **status = [Describe only the requested operation](browser.set_text(sel="#log", text="download request queued"))**.
Return *[Keep the request and its truthful feedback](browser.merge(a=`request`, b=`status`))*.
## _list
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| records | list | required | Native id/text records in visible order |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Structured list effect with literal labels and native delete buttons |
Use `records` from the direct callback's retained state. Each row contains a span label and button as typed children. The button's data-id carries the independent record identity; visible business text stays in text, never html. The official bridge escapes it and preserves delegation without rebuilding the parent page.
This helper is pure and receives records explicitly. It does not read hidden entry state, delete anything or assume that a returned effect has already reached the DOM. The existing host list and event wiring own those later steps.
We **rows = [Start the native visible row records](table.empty_list())**.
- [Describe one label and native delete action](for records as record)
We **id = [Retain the exact row identity](access(record, "id"))** and **value = [Retain literal business text](access(record, "text"))**.
`label` =
| tag | text |
|---|---|
| span | `value` |
`attributes` =
| type | data-id |
|---|---|
| button | `id` |
`button` =
| tag | text | attrs |
|---|---|---|
| button | 删 | `attributes` |
`children` =
| node |
|---|
| `label` |
| `button` |
`row` =
| tag | children |
|---|---|
| li | `children` |
We **rows = [Retain this typed row](table.append(list=`rows`, item=`row`))**.
Return *[Update only the existing list](browser.render_list(sel="#items", items=`rows`))*.
## _view
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| route | text | required | Selected panel pathname |
| push | bool | False | Explicit navigation callback requests one history entry |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Actual boolean panel visibility, path label and optional deliberate navigation |
Use `route` and `push`=False. Only /about and /net select secondary panels; other paths render Home. Hidden attributes are actual booleans, while False removes the attribute. The pure helper receives its path explicitly and does not pretend to capture the browser entry state.
History observations use the default without navigation; authored link callbacks opt in once. Keep all three targets inside a single set_attr record because effect merging is shallow and otherwise one target map could overwrite another. This function performs no fetch, storage write or socket operation.
We **selected = "/"**.
1. `route` == "/about" or `route` == "/net"
We **selected = route**.
We **home = [Describe Home visibility](table.put(in=None, at="hidden", value=(`selected` != "/")))** and **about = [Describe About visibility](table.put(in=None, at="hidden", value=(`selected` != "/about")))** and **network = [Describe Network visibility](table.put(in=None, at="hidden", value=(`selected` != "/net")))**.
`targets` =
| #panel-home | #panel-about | #panel-net |
|---|---|---|
| `home` | `about` | `network` |
We **visibility = [Keep every panel target together](browser.wrap(key="set_attr", value=`targets`))** and **message = "path: " + selected** and **label = [Display the selected path](browser.set_text(sel="#path", text=`message`))** and **effects = [Keep independent visibility and text effects](browser.merge(a=`visibility`, b=`label`))**.
1. `push`
We **navigation = [Request one intentional history entry](browser.navigate(url=`selected`))** and **effects = [Keep navigation with its actual panel effects](browser.merge(a=`effects`, b=`navigation`))**.
Return *effects* after describing the real selected panel.
## _plain
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| records | list | required | Native text records in retained order |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Literal newline-joined values for copy or download |
Use `records` to retain the original plain-text export purpose without turning the client state into a newline-encoded database. Each item's text remains a single native value; newlines are introduced only in this human-readable export. This pure transformation neither writes the clipboard nor starts a download, and it does not encode HTML.
We **values = [Select actual text fields in order](table.pluck(list=`records`, key="text"))**.
Return *[Form the intended text export](text.str_join(xs=`values`, sep="\n"))*.
## on_saved
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| ok | bool | True | Actual storage-write completion |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Feedback for the completed write |
Use `ok`=True from the storage callback. Confirm saving after the browser reports completion, rather than when the user merely clicks Save. A failed callback remains a failure message. Host storage exceptions also appear through the official bridge error channel; this function cannot turn an unavailable storage service into a successful write.
1. not `ok`
Return *[Expose the failed write](browser.set_text(sel="#log", text="draft save failed"))*.
Return *[Confirm the completed write](browser.set_text(sel="#log", text="draft saved"))*.
+19
View File
@@ -0,0 +1,19 @@
---
markup: occlusion
title: Retained browser theme compilation
import:
document: lib/document.mq.md
web: ext/web/web.mq.md
text: lib/text.mq.md
---
## css
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Original theme declarations followed by bounded View geometry |
Call with fs.read and plugin under the site root. The original table retains every declaration from the former host page, including fonts, green palette, panel spacing and feedback surfaces. The geometry table only adapts native View wrappers and long text for a narrow viewport. Compilation returns CSS through the existing native style capability; it neither writes a file nor starts a server. Serve owns the explicit generated output. Review the data leaf when adjusting appearance and verify actual computed styles in the browser.
We **original = [Read all retained declarations](document.read_table(path="styles/theme.tables.md", title="original"))** and **geometry = [Read explicit native wrapper rules](document.read_table(path="styles/theme.tables.md", title="geometry"))** and **base = [Compile the retained theme](web.make_style(name="original", table=`original`))** and **wrappers = [Compile bounded View adaptation](web.make_style(name="geometry", table=`geometry`))**.
Return *[Keep original cascade before native adaptation](`base` + "\n" + `wrappers`)*.
@@ -0,0 +1,88 @@
# Browser example theme
This literal data preserves the original browser-app palette, typefaces, spacing, backgrounds and controls. Region selectors are scoped to the native View frame. Callable compilation is documented in index.mq.md beside this data.
## original
Every original declaration appears in its original order. Only selectors gain the known frame address, keeping basic preview defaults from overriding the authored theme.
| selector | property | value |
|---|---|---|
| ":root" | "--ink" | "#1a1f1c" |
| ":root" | "--paper" | "#e8efe6" |
| ":root" | "--accent" | "#2f6f4e" |
| ":root" | "--muted" | "#5a6b60" |
| "*" | "box-sizing" | "border-box" |
| "body" | "margin" | "0" |
| "body" | "min-height" | "100vh" |
| "body" | "font-family" | "\"IBM Plex Sans\", \"Noto Sans SC\", sans-serif" |
| "body" | "color" | "var(--ink)" |
| "body" | "background" | "linear-gradient(165deg, #f3f7f2, var(--paper))" |
| "body" | "padding" | "2rem clamp(1rem, 4vw, 3rem)" |
| ".mq-document .browser-app h1" | "font-family" | "\"IBM Plex Serif\", \"Noto Serif SC\", serif" |
| ".mq-document .browser-app h1" | "margin" | "0 0 0.35rem" |
| ".mq-document .browser-app .lead" | "color" | "var(--muted)" |
| ".mq-document .browser-app .lead" | "max-width" | "42rem" |
| ".mq-document .browser-app nav a" | "margin-right" | "0.75rem" |
| ".mq-document .browser-app nav a" | "color" | "var(--accent)" |
| ".mq-document .browser-app section" | "margin" | "1.5rem 0" |
| ".mq-document .browser-app section" | "padding" | "1rem 0" |
| ".mq-document .browser-app section" | "border-top" | "1px solid #c5d4c9" |
| ".mq-document .browser-app #path" | "font-family" | "ui-monospace, monospace" |
| ".mq-document .browser-app #path" | "color" | "var(--muted)" |
| ".mq-document .browser-app #items" | "list-style" | "none" |
| ".mq-document .browser-app #items" | "padding" | "0" |
| ".mq-document .browser-app #items" | "margin" | "0.75rem 0" |
| ".mq-document .browser-app #items li" | "display" | "flex" |
| ".mq-document .browser-app #items li" | "align-items" | "center" |
| ".mq-document .browser-app #items li" | "gap" | "0.5rem" |
| ".mq-document .browser-app #items li" | "padding" | "0.4rem 0.6rem" |
| ".mq-document .browser-app #items li" | "margin-bottom" | "0.35rem" |
| ".mq-document .browser-app #items li" | "background" | "rgba(255,255,255,0.65)" |
| ".mq-document .browser-app #items li" | "border" | "1px solid #b7c7bb" |
| ".mq-document .browser-app #items button" | "margin-left" | "auto" |
| ".mq-document .browser-app input[type=\"text\"]" | "padding" | "0.45rem 0.65rem" |
| ".mq-document .browser-app input[type=\"text\"]" | "border" | "1px solid #b7c7bb" |
| ".mq-document .browser-app input[type=\"text\"]" | "width" | "min(16rem, 70%)" |
| ".mq-document .browser-app button" | "padding" | "0.45rem 0.9rem" |
| ".mq-document .browser-app button" | "border" | "0" |
| ".mq-document .browser-app button" | "background" | "var(--accent)" |
| ".mq-document .browser-app button" | "color" | "#f5faf6" |
| ".mq-document .browser-app button" | "font" | "inherit" |
| ".mq-document .browser-app button" | "cursor" | "pointer" |
| ".mq-document .browser-app button" | "margin" | "0.2rem 0.35rem 0.2rem 0" |
| ".mq-document .browser-app button.secondary" | "background" | "#3a4740" |
| ".mq-document .browser-app #tick, #net-out" | "font-variant-numeric" | "tabular-nums" |
| ".mq-document .browser-app #net-out" | "min-height" | "2.5rem" |
| ".mq-document .browser-app #net-out" | "padding" | "0.6rem 0.75rem" |
| ".mq-document .browser-app #net-out" | "background" | "rgba(255,255,255,0.55)" |
| ".mq-document .browser-app #net-out" | "border" | "1px solid #b7c7bb" |
| ".mq-document .browser-app #net-out" | "white-space" | "pre-wrap" |
| ".mq-document .browser-app #net-out" | "word-break" | "break-all" |
| ".mq-document .browser-app pre" | "margin-top" | "1rem" |
| ".mq-document .browser-app pre" | "padding" | "0.85rem 1rem" |
| ".mq-document .browser-app pre" | "background" | "#122018" |
| ".mq-document .browser-app pre" | "color" | "#d7eadc" |
| ".mq-document .browser-app pre" | "font-size" | "0.8rem" |
| ".mq-document .browser-app pre" | "overflow" | "auto" |
| ".mq-document .browser-app pre" | "max-width" | "42rem" |
| ".mq-document .browser-app .err" | "color" | "#ffb4a8" |
## geometry
These additions adapt the preview wrappers and keep native controls and literal long text within a narrow viewport. They do not replace the retained palette or typography.
| selector | property | value |
|---|---|---|
| ".mq-document .mq-view" | "max-width" | "none" |
| ".mq-document .mq-view" | "margin" | "0" |
| ".mq-document .mq-view" | "padding" | "0" |
| ".mq-document .mq-view" | "font-family" | "inherit" |
| ".mq-document .mq-view" | "line-height" | "inherit" |
| ".mq-document .browser-app" | "display" | "block" |
| ".mq-document .browser-app .mq-column" | "display" | "block" |
| ".mq-document .browser-app .mq-row" | "flex-wrap" | "wrap" |
| ".mq-document .browser-app #items span" | "overflow-wrap" | "anywhere" |
| ".mq-document .browser-app button" | "max-width" | "100%" |
| ".mq-document .browser-app pre" | "white-space" | "pre-wrap" |
| ".mq-document .browser-app pre" | "overflow-wrap" | "anywhere" |