Release 2.7.0: executable handbooks and native user-site workflows
This commit is contained in:
1 parent
aa0c4d0f55
commit
d9aef957f7
562 files changed
+21064
-20387
No files matched your search
@@ -1,19 +1,24 @@
|
||||
# examples/web-net-site
|
||||
# web-net-site
|
||||
|
||||
Demonstrates the network-extended `ext/web` + `lib/net` surface (design `doc/design/ext-web-net.md`).
|
||||
本工程保留文章列表、关于页、文章表单、Cookie/Multipart 工具页、登录后的原生管理后台,以及 /live WebSocket 回显。页面递归组合到 Markdown 和原生控件;浏览器交互由 public/client.mq.md 表达。
|
||||
|
||||
```bash
|
||||
cargo build -p marqdo_plugin_web
|
||||
cargo run -- examples/web-net-site/index.mq.md
|
||||
从仓库根目录准备当前 CLI 与工程插件后,使用同一份开发手册构建 Web 和浏览器运行时:
|
||||
|
||||
```sh
|
||||
target/debug/marqdo call skills/marqdo-dev/index.mq.md prepare_engineering --effects process.exec --fs-root . --require-ok --json
|
||||
target/debug/marqdo call skills/marqdo-dev/index.mq.md prepare_web --effects plugin --fs-root . --require-ok --json
|
||||
target/debug/marqdo call skills/marqdo-dev/index.mq.md build_browser 'out="examples/web-net-site/public/generated"' --effects plugin,process.exec,fs.write --fs-root . --require-ok --json
|
||||
target/debug/marqdo call examples/web-net-site/index.mq.md serve --effects plugin,fs.write,network.write --fs-root examples/web-net-site --require-ok --json
|
||||
```
|
||||
|
||||
Then open http://127.0.0.1:18083/:
|
||||
打开 http://127.0.0.1:18083。默认数据库位于站点文件根的 data/site-net.db,重启保留已有文章。缺少兼容 WASM 目标时,先按 [工具链任务](../../skills/marqdo-dev/toolchain.mq.md) 准备工作区编译器,再把返回的 compiler 传给 build_browser。
|
||||
|
||||
- `/` — articles from SQLite plus a live WebSocket widget (`/live`, served by `public/live.js`)
|
||||
- `/about`
|
||||
- `/new` — form POST to `/_form/article`
|
||||
- `/tools` — parsing demos powered by `lib/net`: `net.cookie_parse` and `net.multipart_parse`
|
||||
- `/admin` — session-gated admin; sign in with `admin` / `secret`
|
||||
- `/live` — WebSocket echo endpoint (try it from the home widget, or with `web.ws.connect`)
|
||||
- [布局入口](components/index.mq.md) 组合导航、侧栏、主体和页脚,叶子在 components/content。
|
||||
- [文章表单](forms.mq.md) 统一定义字段与服务端规则;校验失败后保留真实 CSRF,成功回到文章列表。
|
||||
- [工具页](pages/tools.mq.md) 展示真实网络解析结果,不请求远端服务。
|
||||
- [客户端](public/client.mq.md) 保留按钮与 Enter 发送、去除首尾空白、忽略空输入及连续回显日志。
|
||||
- 管理后台登录使用本机演示账号 admin / secret。部署时替换账号与访问策略。
|
||||
|
||||
You may run it from the repo root or from this directory: relative `static_dir` (e.g. `public`) and relative db paths (e.g. `data/site-net.db`) resolve against the **entry script's directory**, not the terminal's current working directory.
|
||||
请求资源沿用五列 View;数据库查询随每次请求更新,表单引用解析当前会话。详情见 [请求资源设计](../../doc/design/web-view-resources.md)。
|
||||
|
||||
开发入口的 test_browser 使用实际当前 WASM 验证回显、表单重试、新增文章、后台登录与窄屏布局。HTTP 回归 web_handbook 在 Tree 与 Bytecode 两个后端启动临时站点,验证数据和鉴权,避免操作用户数据库。
|
||||
@@ -0,0 +1,3 @@
|
||||
# About
|
||||
|
||||
This example combines database records, server-side form validation, login sessions, WebSocket echo and the standard network library's cookie/multipart parsing. Each responsibility has its own source file; layouts end in plain Markdown leaves.
|
||||
@@ -0,0 +1 @@
|
||||
[Marqdo web-net example](https://github.com) · [Docs](/tools)
|
||||
@@ -0,0 +1,3 @@
|
||||
# Net Site
|
||||
|
||||
Articles from SQLite, a live WebSocket widget, login-gated administration, and network parsing tools share this readable project. New articles appear on the next request.
|
||||
@@ -0,0 +1,10 @@
|
||||
--net-boundary
|
||||
Content-Disposition: form-data; name="title"
|
||||
|
||||
Hello
|
||||
--net-boundary
|
||||
Content-Disposition: form-data; name="cover"; filename="pic.png"
|
||||
Content-Type: image/png
|
||||
|
||||
<bytes>
|
||||
--net-boundary--
|
||||
@@ -0,0 +1 @@
|
||||
[Home](/) · [About](/about) · [Publish](/new) · [Tools](/tools) · [Admin](/admin)
|
||||
@@ -0,0 +1,3 @@
|
||||
# Publish
|
||||
|
||||
This form inserts into the shared articles table. Title is required and limited to 120 characters; body is optional and limited to 8000. A rejected field keeps the actual session token so it can be corrected and submitted again.
|
||||
@@ -0,0 +1,7 @@
|
||||
## Try the capabilities
|
||||
|
||||
- [Articles](/)
|
||||
- [WebSocket](/#live)
|
||||
- [Authentication](/admin)
|
||||
- [Forms](/new)
|
||||
- [Network parsing](/tools)
|
||||
@@ -1,14 +1,20 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: foot Markdown component
|
||||
import:
|
||||
component: ext/web/component/index.mq.md
|
||||
fs: lib/fs.mq.md
|
||||
---
|
||||
|
||||
This leaf module owns foot content and its semantic region. Parent layout only places the returned nodes. Edit the adjacent Markdown leaf to change wording or links; the component does not query records, authenticate users or generate a raw HTML string.
|
||||
|
||||
## foot
|
||||
|
||||
`foot` =
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | One footer region containing terminal Markdown content |
|
||||
|
||||
| 属性 | 值 | 样式 |
|
||||
|------|-----|------|
|
||||
| Marqdo web-net example | https://github.com | |
|
||||
| Docs | /tools | |
|
||||
Read the Markdown leaf relative to the granted site root with fs.read. Its links keep the original example's destinations; actual routing and access policy remain in the serving entry. This region is already simple enough to express as Markdown, so further wrappers or a custom table dialect would add no responsibility. The semantic container and class preserve its role for the native layout and theme.
|
||||
|
||||
*`foot`*
|
||||
We **text = [Read this region's terminal Markdown](fs.read_text(path="components/content/foot.md"))** and **leaf = [Retain content as native Markdown](component.markdown(text=`text`, slot="foot-content"))**.
|
||||
Return *[Place that leaf in its semantic region](component.wrap(children=`leaf`, kind="footer", slot="foot", style="foot"))*.
|
||||
@@ -0,0 +1,25 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Network-site home content
|
||||
import:
|
||||
component: ext/web/component/index.mq.md
|
||||
query: ext/data/view.mq.md
|
||||
socket: live.mq.md
|
||||
fs: lib/fs.mq.md
|
||||
table: lib/table.mq.md
|
||||
---
|
||||
|
||||
The home body has three responsibilities: a Markdown introduction, the original WebSocket widget, and a current article list. Each remains a separate component or resource. The database query is described at startup and executed per request, so publishing an article appears without restarting the site.
|
||||
|
||||
## nodes
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | Introduction, native live widget and request-time article query nodes |
|
||||
|
||||
Read the terminal introduction with fs.read. The live component owns only native controls and the official bridge reference; network binding belongs to serve. The query uses the application's retained articles resource and stable id ordering. It neither caches startup records nor opens a second database using a guessed relative filename.
|
||||
|
||||
We **text = [Read the home introduction](fs.read_text(path="components/content/home.md"))** and **intro = [Describe it as Markdown](component.markdown(text=`text`, slot="intro"))** and **live = [Assemble the native WebSocket widget](socket.nodes())**.
|
||||
We **current = [Describe the current article query](query.query(source="articles", order="id", link_prefix=""))** and **articles = [Place the dynamic data resource](component.resource(value=`current`, slot="articles"))**.
|
||||
We **body = [Keep introduction before interaction](table.concat(a=`intro`, b=`live`))**.
|
||||
Return *[Keep the actual database list after the live widget](table.concat(a=`body`, b=`articles`))*.
|
||||
@@ -0,0 +1,29 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Network-site recursive layout entry
|
||||
import:
|
||||
component: ext/web/component/index.mq.md
|
||||
nav: nav.mq.md
|
||||
side: side.mq.md
|
||||
foot: foot.mq.md
|
||||
table: lib/table.mq.md
|
||||
---
|
||||
|
||||
Read this entry before changing page geometry. Navigation, side rail and footer end in Markdown leaves; the caller supplies main content nodes. Database queries and form references remain resources inside that main region, preserving fresh request behavior without rebuilding layout or concatenating HTML.
|
||||
|
||||
## frame
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| body | list | required | Main content nodes supplied by the page's own component |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | Ordered navigation, side/main row, footer and stylesheet resource |
|
||||
|
||||
Use `body` to assemble one page in the same site frame. Each child module owns its content; this parent only declares order and one side-by-side relationship. The native row layout collapses on narrow screens. No child is rendered into a string before composition. The theme URL points to a file explicitly compiled by serve before discovery starts.
|
||||
|
||||
We **top = [Read the navigation component](nav.nav())** and **rail = [Read the side-rail component](side.side())** and **main = [Name the supplied main region](component.wrap(children=`body`, kind="column", slot="main"))**.
|
||||
We **columns = [Keep side rail and main as sibling components](table.concat(a=`rail`, b=`main`))** and **center = [Declare the shared row geometry](component.wrap(children=`columns`, kind="row", slot="page-body"))** and **bottom = [Read the closing links](foot.foot())**.
|
||||
We **page = [Keep navigation before content](table.concat(a=`top`, b=`center`))** and **page = [Keep the footer after content](table.concat(a=`page`, b=`bottom`))** and **style = [Reference the compiled declarative theme](component.asset(url="/static/generated/theme.css", kind="stylesheet"))**.
|
||||
Return *[Retain the style resource with the readable page structure](table.concat(a=`page`, b=`style`))*.
|
||||
@@ -0,0 +1,53 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Native WebSocket widget
|
||||
import:
|
||||
component: ext/web/component/index.mq.md
|
||||
client: ext/web/client/index.mq.md
|
||||
table: lib/table.mq.md
|
||||
---
|
||||
|
||||
This component ends at simple Markdown and native controls. It owns no network listener or hand-written HTML. The client program supplies events through the official bridge; serve separately binds the native /live echo resource. Keep control ids stable when editing wording so the client contract stays readable.
|
||||
|
||||
## nodes
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | WebSocket heading, status, input/send controls, message log and bridge resource |
|
||||
|
||||
The heading explains the interaction. Status and output use independent plain-text targets, input supplies the send value, and the button starts disabled until a real connection opens. Values and attributes remain typed data. Each echoed message is appended by the Marqdo client state and shown as text, so message content cannot become HTML. This construction does not open a socket.
|
||||
|
||||
The bridge addresses are explicit resources under the site's static mount. Prepare the current WASM and bridge in public/generated before serving; copying an older bridge can change event behavior even when the page still renders. The source at public/client.mq.md is served as UTF-8 client code and runs in the official browser runtime. To inspect construction alone, call this file's nodes function with no effects: it returns typed structure and performs no network request.
|
||||
|
||||
We **heading = [Describe the widget in ordinary Markdown](component.markdown(text="## Live WebSocket", slot="live-heading"))**.
|
||||
|
||||
`status_attrs` =
|
||||
|
||||
| id | aria-live |
|
||||
|---|---|
|
||||
| live-status | polite |
|
||||
|
||||
`input_attrs` =
|
||||
|
||||
| id | placeholder | type |
|
||||
|---|---|---|
|
||||
| live-msg | type a message… | text |
|
||||
|
||||
`button_attrs` =
|
||||
|
||||
| id | type | disabled |
|
||||
|---|---|---|
|
||||
| live-send | button | True |
|
||||
|
||||
`output_attrs` =
|
||||
|
||||
| id | aria-live |
|
||||
|---|---|
|
||||
| live-out | polite |
|
||||
|
||||
We **status = [Keep connection state separate from messages](component.element(kind="text", value="connecting…", attrs=`status_attrs`, slot="live-status"))** and **input = [Describe the native message input](component.element(kind="input", attrs=`input_attrs`, slot="live-input"))** and **button = [Describe the initially disabled send action](component.element(kind="button", value="Send", attrs=`button_attrs`, slot="live-send"))**.
|
||||
We **controls = [Keep the input beside its send button](table.concat(a=`input`, b=`button`))** and **controls = [Declare responsive control geometry](component.wrap(children=`controls`, kind="row", slot="live-controls"))** and **output = [Describe the plain message log](component.element(kind="pre", attrs=`output_attrs`, slot="live-output"))**.
|
||||
We **body = [Start with the explanatory heading](table.concat(a=`heading`, b=`status`))** and **body = [Place interaction after status](table.concat(a=`body`, b=`controls`))** and **body = [Keep the echoed messages after controls](table.concat(a=`body`, b=`output`))**.
|
||||
We **id = [Name the widget's existing fragment destination](table.put(in=None, at="id", value="live"))** and **widget = [Keep the terminal pieces in one semantic region](component.wrap(children=`body`, kind="section", attrs=`id`, slot="live"))**.
|
||||
We **runtime = [Declare the official runtime and Marqdo client source](client.nodes(source="/static/client.mq.md", wasm="/static/generated/marqdo_wasm.wasm", bridge="/static/generated/marqdo-bridge.js"))**.
|
||||
Return *[Retain widget and runtime as structured nodes](table.concat(a=`widget`, b=`runtime`))*.
|
||||
@@ -1,19 +1,20 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: nav Markdown component
|
||||
import:
|
||||
component: ext/web/component/index.mq.md
|
||||
fs: lib/fs.mq.md
|
||||
---
|
||||
|
||||
This leaf module owns nav content and its semantic region. Parent layout only places the returned nodes. Edit the adjacent Markdown leaf to change wording or links; the component does not query records, authenticate users or generate a raw HTML string.
|
||||
|
||||
## nav
|
||||
|
||||
Site top navigation. The Admin tab points at the login-gated admin page.
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | One nav region containing terminal Markdown content |
|
||||
|
||||
`nav` =
|
||||
Read the Markdown leaf relative to the granted site root with fs.read. Its links keep the original example's destinations; actual routing and access policy remain in the serving entry. This region is already simple enough to express as Markdown, so further wrappers or a custom table dialect would add no responsibility. The semantic container and class preserve its role for the native layout and theme.
|
||||
|
||||
| 属性 | 值 | 样式 |
|
||||
|------|-----|------|
|
||||
| Home | / | |
|
||||
| About | /about | |
|
||||
| Publish | /new | |
|
||||
| Tools | /tools | |
|
||||
| Admin | /admin | |
|
||||
|
||||
*`nav`*
|
||||
We **text = [Read this region's terminal Markdown](fs.read_text(path="components/content/nav.md"))** and **leaf = [Retain content as native Markdown](component.markdown(text=`text`, slot="nav-content"))**.
|
||||
Return *[Place that leaf in its semantic region](component.wrap(children=`leaf`, kind="nav", slot="nav", style="topnav"))*.
|
||||
@@ -1,19 +1,20 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: side Markdown component
|
||||
import:
|
||||
component: ext/web/component/index.mq.md
|
||||
fs: lib/fs.mq.md
|
||||
---
|
||||
|
||||
This leaf module owns side content and its semantic region. Parent layout only places the returned nodes. Edit the adjacent Markdown leaf to change wording or links; the component does not query records, authenticate users or generate a raw HTML string.
|
||||
|
||||
## side
|
||||
|
||||
Sidebar index of what this example demonstrates.
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | One aside region containing terminal Markdown content |
|
||||
|
||||
`side` =
|
||||
Read the Markdown leaf relative to the granted site root with fs.read. Its links keep the original example's destinations; actual routing and access policy remain in the serving entry. This region is already simple enough to express as Markdown, so further wrappers or a custom table dialect would add no responsibility. The semantic container and class preserve its role for the native layout and theme.
|
||||
|
||||
| 属性 | 值 | 样式 |
|
||||
|------|-----|------|
|
||||
| Articles | / | |
|
||||
| WebSocket | /#live | |
|
||||
| Auth | /admin | |
|
||||
| Forms | /new | |
|
||||
| net lib | /tools | |
|
||||
|
||||
*`side`*
|
||||
We **text = [Read this region's terminal Markdown](fs.read_text(path="components/content/side.md"))** and **leaf = [Retain content as native Markdown](component.markdown(text=`text`, slot="side-content"))**.
|
||||
Return *[Place that leaf in its semantic region](component.wrap(children=`leaf`, kind="aside", slot="side", style="side"))*.
|
||||
@@ -1,27 +1,32 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Article schema and seed handbook
|
||||
import:
|
||||
document: lib/document.mq.md
|
||||
---
|
||||
|
||||
This file explains callable use; [articles.tables.md](articles.tables.md) holds the readable literal tables. Set --fs-root to the site directory and grant fs.read. Reading returns data without running prose, opening a database or changing a page.
|
||||
|
||||
## schema
|
||||
|
||||
`fields` =
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Native table value, preserving literal types and column geometry |
|
||||
|
||||
| 字段 | 类型 | 可空 |
|
||||
|------|------|------|
|
||||
| id | integer | false |
|
||||
| title | text | false |
|
||||
| body | text | true |
|
||||
Declare article fields, native types and nullability. The initializer consumes this table to ensure structure; it must not guess a migration or erase existing rows.
|
||||
|
||||
*`fields`*
|
||||
Call independently with fs.read on the site root. The section must match exactly and uniquely. Malformed tables or dynamic expressions retain native document diagnostics. A returned style declaration still needs compilation; returned database data still needs an explicit initializer. This value is neither HTML nor an applied browser effect.
|
||||
|
||||
Return *[读取 schema 的实际字面表](document.read_table(path="db/articles.tables.md", title="schema"))*.
|
||||
|
||||
## seed
|
||||
|
||||
`rows` =
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Native table value, preserving literal types and column geometry |
|
||||
|
||||
| id | title | body |
|
||||
|----|-------|------|
|
||||
| 1 | Welcome to the web-net site | Home page lists rows from SQLite. |
|
||||
| 2 | Login-gated admin | The /admin page requires a session cookie. |
|
||||
| 3 | WebSocket live | The /live endpoint echoes your message in real time. |
|
||||
Provide initial demonstration articles with their original ids, stable slugs and content. Insert only after the database initializer confirms an empty table; this reader never changes existing articles.
|
||||
|
||||
*`rows`*
|
||||
Call independently with fs.read on the site root. The section must match exactly and uniquely. Malformed tables or dynamic expressions retain native document diagnostics. A returned style declaration still needs compilation; returned database data still needs an explicit initializer. This value is neither HTML nor an applied browser effect.
|
||||
|
||||
Return *[读取 seed 的实际字面表](document.read_table(path="db/articles.tables.md", title="seed"))*.
|
||||
@@ -0,0 +1,23 @@
|
||||
# Article data
|
||||
|
||||
Literal article schema and demonstration content. Reading these tables does not open a database or insert rows. Follow articles.mq.md for callable use; the database initializer decides whether seeding is appropriate.
|
||||
|
||||
## schema
|
||||
|
||||
Field definitions for the native database initializer; nullable values remain booleans.
|
||||
|
||||
| 字段 | 类型 | 可空 |
|
||||
|------|------|------|
|
||||
| id | integer | false |
|
||||
| title | text | false |
|
||||
| body | text | true |
|
||||
|
||||
## seed
|
||||
|
||||
Initial demonstration records in their original column-oriented shape; ids and stable slugs retain their meaning.
|
||||
|
||||
| id | title | body |
|
||||
|----|-------|------|
|
||||
| 1 | Welcome to the web-net site | Home page lists rows from SQLite. |
|
||||
| 2 | Login-gated admin | The /admin page requires a session cookie. |
|
||||
| 3 | WebSocket live | The /live endpoint echoes your message in real time. |
|
||||
@@ -1,21 +1,37 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: db/index
|
||||
description: Open sqlite, init articles, seed once.
|
||||
title: web-net-site database lifecycle
|
||||
import:
|
||||
web: ext/web/web.mq.md
|
||||
data: ext/data/db.mq.md
|
||||
articles: articles.mq.md
|
||||
fs: lib/fs.mq.md
|
||||
text: lib/text.mq.md
|
||||
---
|
||||
|
||||
The database entry connects schema and literal seed leaves to the actual data resource. It no longer uses the removed web database constructor. Grant fs.write and plugin with the site directory as --fs-root; the SQLite path is resolved through that native root rather than the process working directory.
|
||||
|
||||
## open
|
||||
|
||||
**store = > web.db url="sqlite:data/site-net.db"**
|
||||
**fields = > articles.schema**
|
||||
> `store`.init name=articles fields=`fields`
|
||||
**rows = > store.select table="articles" limit=1**
|
||||
1. `rows`
|
||||
*store*
|
||||
2. *
|
||||
**seed = > articles.seed**
|
||||
> `store`.insert table=articles rows=`seed`
|
||||
*store*
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| url | any | None | None selects data/site-net.db under the site root; tests provide a disposable explicit URI |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Initialized articles database resource with existing rows preserved |
|
||||
|
||||
Use `url`=None to open the site's local database. Create the default data directory through native file operations, then resolve the actual SQLite filename within the granted root. An explicit SQLite path goes through the same root and symlink checks before the native database resource receives it. Other supported database URIs retain their resource-specific backend contract; they are not sandboxed by filesystem permissions.
|
||||
|
||||
The schema reader preserves native field types and nullability. Initialization ensures the table exists, queries one row to distinguish an empty table, and inserts the original demonstration content only into an empty table. An existing or partly populated table is kept unchanged. This is not a column migrator, data repair tool or reason to delete a user's articles. A native connection, schema or insert diagnostic stops the caller before it starts serving.
|
||||
|
||||
For isolated verification choose a caller-owned temporary SQLite file and copy the article data leaf under that granted site root. Keep the returned resource in the same program for subsequent queries. Close the process before cleaning its owned directory; do not run tests against the example's existing data directory.
|
||||
|
||||
1. `url` == None
|
||||
We **[Create only the site's default data directory](fs.make_dirs(path="data"))** and **file = [Resolve its database filename](fs.resolve(path="data/site-net.db"))** and **url = "sqlite:" + file**.
|
||||
1. [The explicit or default URI selects SQLite](text.starts_with(text=`url`, prefix="sqlite:"))
|
||||
We **file = [Read the selected SQLite path](text.replace(text=`url`, old="sqlite:", new="", count=1))** and **file = [Apply the native file-root policy](fs.resolve(path=`file`))** and **url = "sqlite:" + file**.
|
||||
We **store = [Open the selected actual database resource](data.db(url=`url`))** and **fields = [Read the documented article schema](articles.schema())**.
|
||||
We **[Ensure the table without clearing it](> `store`.init name="articles" fields=`fields`)** and **existing = [Check whether business records already exist](> `store`.select table="articles" limit=1)**.
|
||||
1. not `existing`
|
||||
We **seed = [Read the original demonstration data](articles.seed())** and **[Seed only the empty article table](> `store`.insert table="articles" rows=`seed`)**.
|
||||
Once the selected database is ready, return *store* for the site's resource bindings.
|
||||
@@ -0,0 +1,36 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Article form resource
|
||||
import:
|
||||
form: ext/data/form.mq.md
|
||||
---
|
||||
|
||||
The same form resource supplies the page controls and validates the system submission route. The serving entry mounts it as article. The page only places a reference, so fields, limits and errors cannot drift between two separate form implementations.
|
||||
|
||||
## article
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Native insert form with title/body fields and original validation rules |
|
||||
|
||||
Call with plugin before listening. Title is required and limited to 120 characters; body remains optional with an 8000-character limit. These are the original site's server-side rules. Rendering neither inserts a row nor authenticates a user; submission uses the application's actual articles database and current CSRF context.
|
||||
|
||||
The field and rule tables stay immediately visible beside their explanation. No raw form HTML or client validation program is authored. After a valid submission the resource returns to the article list; rejected values retain field errors for correction. This public demonstration form is distinct from the login-gated native administration surface.
|
||||
|
||||
`fields` =
|
||||
|
||||
| name | label | type | required |
|
||||
|---|---|---|---|
|
||||
| title | Title | text | True |
|
||||
| body | Body | textarea | False |
|
||||
|
||||
`rules` =
|
||||
|
||||
| field | rule | message |
|
||||
|---|---|---|
|
||||
| title | required | Title is required |
|
||||
| title | max:120 | Title is too long |
|
||||
| body | max:8000 | Body is too long |
|
||||
|
||||
We **selected = [Create the actual article insert resource](form.form(table="articles", action="insert"))** and **selected = [Attach the readable field definitions](> `selected`.fields fields=`fields`)** and **selected = [Attach the server validation rules](> `selected`.rules rules=`rules`)**.
|
||||
Return *[Keep submission and cancellation copy with this resource](> `selected`.labels submit="Publish" cancel="Cancel" cancel_href="/")*.
|
||||
@@ -1,131 +1,72 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: web-net-site
|
||||
description: Home + /about + /new (form) + /tools (net lib) + /admin (auth) + /live (WebSocket).
|
||||
type: web
|
||||
view: main
|
||||
route: /
|
||||
title: Marqdo Net Site
|
||||
import:
|
||||
layout: components/index.mq.md
|
||||
home: components/home.mq.md
|
||||
database: db/index.mq.md
|
||||
forms: forms.mq.md
|
||||
styles: styles/shell.mq.md
|
||||
web: ext/web/web.mq.md
|
||||
net: lib/net.mq.md
|
||||
text: lib/text.mq.md
|
||||
shell: styles/shell.mq.md
|
||||
nav: components/nav.mq.md
|
||||
side: components/side.mq.md
|
||||
foot: components/foot.mq.md
|
||||
articles: db/articles.mq.md
|
||||
db: db/index.mq.md
|
||||
form: ext/data/form.mq.md
|
||||
admin: ext/data/admin.mq.md
|
||||
auth: ext/security/auth.mq.md
|
||||
socket: ext/net/websocket.mq.md
|
||||
fs: lib/fs.mq.md
|
||||
result: lib/result.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
Read this entry, then the layout index, content leaves, database entry, form resource and browser client. Home, About, Publish and Tools are declared Documents. Native administration remains enabled and login-gated. The /live socket is a separate network resource. No page uses the removed compose APIs or a raw HTML shell.
|
||||
|
||||
`home` =
|
||||
## main
|
||||
|
||||
| 组件 | 样式 |
|
||||
|------|------|
|
||||
| nav.`nav` | shell.`topnav` |
|
||||
| side.`side` | shell.`side_panel` |
|
||||
| foot.`foot` | |
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | Shared recursive frame around introduction, echo controls and current articles |
|
||||
|
||||
`index` =
|
||||
This startup function describes structure, reading only the terminal Markdown leaves. The database query remains a typed resource resolved per request, while the client uses native controls and the official bridge. Rendering the page cannot initialize or clear business records. Follow each component import to edit one responsibility instead of reproducing the complete page.
|
||||
|
||||
| 属性 | 值 | 样式 |
|
||||
|------|-----|------|
|
||||
| title | articles.`articles`.title | shell.`card_title` |
|
||||
| body | articles.`articles`.body | shell.`card_body` |
|
||||
We **body = [Assemble the three independent home responsibilities](home.nodes())**.
|
||||
Return *[Place them in the shared recursive site frame](layout.frame(body=`body`))*.
|
||||
|
||||
Home intro also embeds the live WebSocket widget (HTML is served raw).
|
||||
## serve
|
||||
|
||||
**store = > db.open**
|
||||
**page = > web.page title="Marqdo Net Site" intro="<h1>Net Site</h1><p>Articles from SQLite, a live WebSocket widget, login-gated admin, and net-library parsing tools.</p><h2 id=\"live\">Live WebSocket</h2><p id=\"live-status\">connecting…</p><input id=\"live-msg\" placeholder=\"type a message…\"><button id=\"live-send\" disabled>send</button><div id=\"live-out\"></div><script src=\"/static/live.js\"></script>"**
|
||||
**page = > page.compose_components components=home**
|
||||
**page = > page.compose_main main=index**
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| root | text | "examples/web-net-site" | Explicit discovery directory relative to the checkout |
|
||||
| port | number | 18083 | Local demonstration listen port |
|
||||
| url | any | None | None chooses the site-root SQLite file; tests use an owned temporary URI |
|
||||
|
||||
About page: same shell.
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Blocking listener with retained article data, forms, authentication and echo |
|
||||
|
||||
**about = > web.page title="About" intro="<h1>About</h1><p>Demonstrates the network-extended web library: sessions, auth, WebSocket, multipart/cookie parsing.</p>"**
|
||||
**about = > about.compose_components components=home**
|
||||
Use `root`="examples/web-net-site", `port`=18083 and `url`=None from the checkout, with --fs-root examples/web-net-site and plugin,fs.write,network.write. Build current browser assets into public/generated through the development handbook first. Missing runtime assets stop before listening rather than leaving the widget apparently ready.
|
||||
|
||||
<!-- Tools page (lib/net parsing) -->
|
||||
Initialization preserves existing articles and seeds only an empty table. Theme compilation uses the original property declarations and writes only the explicit generated stylesheet. Discovery assembles the readable Documents, then the workflow enables native administration, attaches local fixture credentials, mounts the public article form and binds anonymous loopback echo. Real deployment must replace fixture credentials and its network policy. Keep each returned app before listening.
|
||||
|
||||
Parse a `Cookie` request header with the standard library.
|
||||
`assets` =
|
||||
|
||||
**parsed_req = > net.cookie_parse text="session=abc123; theme=dark"**
|
||||
**req_cookie = [1](access(parsed_req, "1"))**
|
||||
| file |
|
||||
|---|
|
||||
| public/generated/marqdo_wasm.wasm |
|
||||
| public/generated/marqdo-bridge.js |
|
||||
|
||||
Parse a `Set-Cookie` response header.
|
||||
- [Require the actual runtime resources before serving](for assets as file)
|
||||
1. not [The selected runtime asset exists](fs.exists(path=`file`))
|
||||
Return *[Explain the required browser preparation](result.error(code="net_site.browser_assets", message="build current browser assets into public/generated before serve", operation="serve"))*.
|
||||
We **store = [Initialize the retained article database](database.open(url=`url`))** and **css = [Compile the actual declarative theme](styles.css())** and **[Create only the generated resource directory](fs.make_dirs(path="public/generated"))** and **[Write that explicit stylesheet through native IO](fs.atomic_write(path="public/generated/theme.css", text=`css`))**.
|
||||
We **app = [Discover all declared Documents and the static root](web.prepare(root=`root`, host="127.0.0.1", port=`port`, db=`store`, static_dir="public"))** and **app = [Retain the existing native administration capability](admin.enable(app=`app`))**.
|
||||
|
||||
**parsed_resp = > net.cookie_parse text="id=42; Path=/; HttpOnly; SameSite=Lax" is_response=True**
|
||||
**resp_cookie = [1](access(parsed_resp, "1"))**
|
||||
`users` =
|
||||
|
||||
Parse a `multipart/form-data` body.
|
||||
| @ | username | password | role |
|
||||
|---|---|---|---|
|
||||
| 1 | admin | secret | admin |
|
||||
|
||||
`_b` = net-boundary
|
||||
|
||||
`_body` = "--`_b`\nContent-Disposition: form-data; name=\"title\"\n\nHello\n--`_b`\nContent-Disposition: form-data; name=\"cover\"; filename=\"pic.png\"\nContent-Type: image/png\n\n<bytes>\n--`_b`--\n"
|
||||
|
||||
**mp = > net.multipart_parse body=`_body` boundary=`_b`**
|
||||
**mp_title = [1](access(mp, "1"))**
|
||||
**mp_cover = [2](access(mp, "2"))**
|
||||
|
||||
Build the tools page as one HTML intro (intro is served raw).
|
||||
|
||||
`tools_parts` =
|
||||
|
||||
| 段 |
|
||||
|----|
|
||||
| <h1>Net tools</h1><p>Parsing demos powered by lib/net: cookie_parse and multipart_parse.</p><section class="content cards"> |
|
||||
| <article><h2>Cookie request</h2><p> |
|
||||
| [name](`req_cookie`)=[value](`req_cookie`) |
|
||||
| </p></article><article><h2>Set-Cookie response</h2><p> |
|
||||
| [name](`resp_cookie`)=[value](`resp_cookie`) · HttpOnly=[http_only](`resp_cookie`) |
|
||||
| </p></article><article><h2>Multipart field</h2><p> |
|
||||
| [name](`mp_title`)=[value](`mp_title`) |
|
||||
| </p></article><article><h2>Multipart file</h2><p> |
|
||||
| [name](`mp_cover`) · [filename](`mp_cover`) · [content_type](`mp_cover`) |
|
||||
| </p></article></section> |
|
||||
|
||||
**tools_intro = > text.str_join xs=`tools_parts` sep=""**
|
||||
**tools = > web.page title="Tools" intro=`tools_intro`**
|
||||
**tools = > tools.compose_components components=home**
|
||||
|
||||
Article create form: field table + rules table.
|
||||
|
||||
`article_fields` =
|
||||
|
||||
| 字段 | 标签 | 类型 | 必填 | 默认 |
|
||||
|------|------|------|------|------|
|
||||
| title | Title | text | true | |
|
||||
| body | Body | textarea | false | |
|
||||
|
||||
`article_rules` =
|
||||
|
||||
| 字段 | 规则 | 消息 |
|
||||
|------|------|------|
|
||||
| title | required | Title is required |
|
||||
| title | max:120 | Title is too long |
|
||||
| body | max:8000 | Body is too long |
|
||||
|
||||
**article_form = > web.form table="articles" action="insert"**
|
||||
**article_form = > article_form.fields fields=article_fields**
|
||||
**article_form = > article_form.rules rules=article_rules**
|
||||
|
||||
New article page: form embedded in the main slot.
|
||||
|
||||
**new = > web.page title="Publish" intro="<h1>Publish</h1><p>Form inserts into articles.</p>"**
|
||||
**new = > new.compose_components components=home**
|
||||
**new = > new.compose_form id="article" form=article_form**
|
||||
|
||||
Admin users table (english + chinese column headers both work).
|
||||
|
||||
`admins` =
|
||||
|
||||
| 行 | username | password |
|
||||
|----|----------|----------|
|
||||
| 1 | admin | secret |
|
||||
|
||||
**app = > web.app page=page db=store admin=True host="127.0.0.1" port=18083**
|
||||
**app = > app.route path="/about" page=about**
|
||||
**app = > app.route path="/new" page=new**
|
||||
**app = > app.route path="/tools" page=tools**
|
||||
**app = > app.static dir="public" mount="/static"**
|
||||
**app = > app.route_ws path="/live" echo=True**
|
||||
**app = > app.auth users=`admins` session_ttl=3600**
|
||||
> `app`.listen
|
||||
We **app = [Attach actual login sessions and the native admin gate](auth.attach(app=`app`, users=`users`, login_path="/admin/login", login_redirect="/admin", logout_redirect="/"))** and **article = [Build the shared validation resource](forms.article())** and **app = [Mount the public creation form explicitly](form.mount(app=`app`, id="article", form=`article`))**.
|
||||
We **app = [Bind the original local WebSocket echo route](socket.route(app=`app`, path="/live", mode="echo", require_auth=False))**.
|
||||
Return *[Listen only after data, resources and policy are ready](web.listen(app=`app`))*.
|
||||
@@ -0,0 +1,24 @@
|
||||
---
|
||||
markup: occlusion
|
||||
type: web
|
||||
view: main
|
||||
route: /about
|
||||
title: About
|
||||
import:
|
||||
component: ext/web/component/index.mq.md
|
||||
layout: ../components/index.mq.md
|
||||
fs: lib/fs.mq.md
|
||||
---
|
||||
|
||||
This Document declares its actual /about route. Its terminal explanation stays in Markdown and its parent frame owns navigation, side rail and footer. No data query or server setup occurs while reading this explanatory page.
|
||||
|
||||
## main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | Shared site frame containing this page's explanation |
|
||||
|
||||
The server assembles these nodes once, then resolves request resources only while serving. Reading requires fs.read. Follow the shared layout imports to change one region without reproducing an HTML shell here. The route remains discoverable from metadata rather than an implicit mutation chain.
|
||||
|
||||
We **text = [Read the page's terminal explanation](fs.read_text(path="components/content/about.md"))** and **body = [Describe ordinary Markdown content](component.markdown(text=`text`, slot="intro"))**.
|
||||
Return *[Place this page within the shared recursive frame](layout.frame(body=`body`))*.
|
||||
@@ -0,0 +1,27 @@
|
||||
---
|
||||
markup: occlusion
|
||||
type: web
|
||||
view: main
|
||||
route: /new
|
||||
title: Publish
|
||||
import:
|
||||
component: ext/web/component/index.mq.md
|
||||
layout: ../components/index.mq.md
|
||||
fs: lib/fs.mq.md
|
||||
form: ext/data/form.mq.md
|
||||
table: lib/table.mq.md
|
||||
---
|
||||
|
||||
This Document declares its actual /new route. Its terminal explanation stays in Markdown and its parent frame owns navigation, side rail and footer. The form is referenced by its explicit mounted id; the resource and real submission policy are defined outside this page.
|
||||
|
||||
## main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | Shared site frame containing this page's explanation and mounted form reference |
|
||||
|
||||
The server assembles these nodes once, then resolves request resources only while serving. Reading requires fs.read. The current session's CSRF token and return path are supplied by the form renderer, so the page cannot embed a stale startup token. Missing form registration is a real request error. The route remains discoverable from metadata rather than an implicit mutation chain.
|
||||
|
||||
We **text = [Read the page's terminal explanation](fs.read_text(path="components/content/new.md"))** and **body = [Describe ordinary Markdown content](component.markdown(text=`text`, slot="intro"))**.
|
||||
We **selected = [Reference the actual mounted article form](form.reference(id="article"))** and **controls = [Place that request resource](component.resource(value=`selected`, slot="article-form"))** and **body = [Keep instructions before the form](table.concat(a=`body`, b=`controls`))**.
|
||||
Return *[Place this page within the shared recursive frame](layout.frame(body=`body`))*.
|
||||
@@ -0,0 +1,73 @@
|
||||
---
|
||||
markup: occlusion
|
||||
type: web
|
||||
view: main
|
||||
route: /tools
|
||||
title: Network parsing tools
|
||||
import:
|
||||
net: lib/net.mq.md
|
||||
fs: lib/fs.mq.md
|
||||
table: lib/table.mq.md
|
||||
component: ext/web/component/index.mq.md
|
||||
layout: ../components/index.mq.md
|
||||
---
|
||||
|
||||
This Document executes the standard network parsers against explicit local fixtures. It makes no external HTTP request. Cookie headers remain text, and the multipart fixture is terminal protocol data in components/content/multipart.txt. The page shows actual returned records as plain preformatted text instead of concatenating raw HTML.
|
||||
|
||||
## _panel
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| title | text | required | Author-controlled heading describing one observed parser value |
|
||||
| value | any | required | Actual native parser result to display literally |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | Markdown heading followed by an escaped native preformatted value |
|
||||
|
||||
Use `title` and `value` to keep each observed value beside its purpose. A parser record is data, not an HTML fragment; convert it to its native display text and let the pre element preserve characters. The author supplies headings, while protocol content never becomes a heading or executable expression. This pure helper performs no IO or parsing itself.
|
||||
|
||||
We **heading = "## " + title** and **label = [Describe the observation in Markdown](component.markdown(text=`heading`))** and **text = [Retain the actual structured parser value](str(value))** and **data = [Show that value literally](component.element(kind="pre", value=`text`))**.
|
||||
Return *[Keep meaning and actual evidence together](table.concat(a=`label`, b=`data`))*.
|
||||
|
||||
## _cookies
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | Actual Cookie request and Set-Cookie response observations |
|
||||
|
||||
The first parser call reads a request Cookie header containing session and theme pairs. The second deliberately enables response-header mode, where Path, HttpOnly and SameSite describe the id cookie rather than becoming independent request cookies. Both results come from the maintained standard library. These are deterministic text fixtures, not real credentials or a browser session lookup.
|
||||
|
||||
Keeping both modes visible preserves the original network-tools capability and explains why their output shapes differ. No cookie is written, accepted for authentication or sent to a remote service. The output panes expose all native fields, so a reader can inspect names, values and flags without decoding a generated HTML string.
|
||||
|
||||
We **request = [Parse the explicit request-cookie fixture](net.cookie_parse(text="session=abc123; theme=dark"))** and **response = [Parse one actual response-cookie fixture](net.cookie_parse(text="id=42; Path=/; HttpOnly; SameSite=Lax", is_response=True))**.
|
||||
We **request_panel = [Show actual request pairs](_panel(title="Cookie request", value=`request`))** and **response_panel = [Show actual response attributes](_panel(title="Set-Cookie response", value=`response`))**.
|
||||
Return *[Keep the two parser modes adjacent](table.concat(a=`request_panel`, b=`response_panel`))*.
|
||||
|
||||
## _multipart
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | Actual multipart field and file-part observations |
|
||||
|
||||
Read the protocol fixture with fs.read from the site root, then parse it using net-boundary, the delimiter declared by that fixture. The title part contains Hello. The cover part names pic.png with image/png content type; its value is the literal demonstration text <bytes>, not an uploaded binary image. This distinction keeps the example's claims aligned with the bytes actually parsed.
|
||||
|
||||
The result is a native part list, so the field and file panes select its first and second records through collection helpers. A missing or malformed fixture remains a parser or filesystem diagnostic rather than a hand-authored expected result. No upload, file extraction or network access occurs, and the fixture is not interpreted as Markdown code.
|
||||
|
||||
We **body = [Read the exact local multipart protocol bytes as text](fs.read_text(path="components/content/multipart.txt"))** and **parts = [Parse the real boundary and disposition fields](net.multipart_parse(body=`body`, boundary="net-boundary"))**.
|
||||
We **field = [Select the first parsed part](table.first(list=`parts`))** and **file = [Select the second parsed part](table.at(xs=`parts`, i=1))** and **field_panel = [Show the actual form field](_panel(title="Multipart field", value=`field`))** and **file_panel = [Show actual file metadata](_panel(title="Multipart file", value=`file`))**.
|
||||
Return *[Keep both actual parser observations](table.concat(a=`field_panel`, b=`file_panel`))*.
|
||||
|
||||
## main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | Shared site frame around all four native parser observations |
|
||||
|
||||
This startup assembly requires fs.read only for the terminal multipart fixture and the shared Markdown layout leaves. The standard parser calls themselves are pure. The four panes preserve request cookies, response cookies, a multipart field and multipart file metadata. None represents a request to an external site or a user upload.
|
||||
|
||||
Changing a fixture should change the displayed result because the page runs the real parser, not a copied expected answer. Keep the explanatory heading and the observed values together, and retain the shared navigation to Publish, administration and the live widget.
|
||||
|
||||
We **intro = [Explain the deterministic tools page](component.markdown(text="# Net tools\n\nParsing demonstrations powered by the actual standard network library."))** and **cookies = [Observe both cookie modes](_cookies())** and **parts = [Observe both multipart part types](_multipart())**.
|
||||
We **body = [Keep the explanation before observations](table.concat(a=`intro`, b=`cookies`))** and **body = [Retain multipart observations after cookies](table.concat(a=`body`, b=`parts`))**.
|
||||
Return *[Place all observations in the shared site frame](layout.frame(body=`body`))*.
|
||||
@@ -0,0 +1,164 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Network-site echo client
|
||||
import:
|
||||
browser: lib/browser.mq.md
|
||||
table: lib/table.mq.md
|
||||
text: lib/text.mq.md
|
||||
---
|
||||
|
||||
The client owns connection state and a plain text message log. Native controls are declared by components/live.mq.md. The relative socket path follows the page's actual host and port, while the server resource owns echo behavior.
|
||||
|
||||
# main
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Native event wiring, socket opening and initial status effects |
|
||||
|
||||
The button click carries the current input value to send. A connection opening enables the button; closure or error disables it. Incoming text appends to retained entry state and never becomes HTML. This is a live echo demonstration, not durable storage or an automatic reconnection loop. BrowserSession keeps entry bindings for callbacks, so they are state rather than fictitious public parameters.
|
||||
|
||||
We **ws_id = "live"** and **messages = ""** before describing the transport.
|
||||
|
||||
`wire` =
|
||||
|
||||
| @ | 选择器 | 事件 | 调用 | 值选择器 |
|
||||
|---|---|---|---|---|
|
||||
| 1 | "#live-send" | click | send | "#live-msg" |
|
||||
| 2 | "#live-msg" | keydown | on_key | "#live-msg" |
|
||||
|
||||
`open` =
|
||||
|
||||
| op | id | url | then_open | then_message | then_error | then_close |
|
||||
|---|---|---|---|---|---|---|
|
||||
| open | `ws_id` | /live | on_open | on_message | on_error | on_close |
|
||||
|
||||
We **bindings = [Bind the existing send control](table.put(in=None, at="wire", value=`wire`))** and **socket = [Describe the same-origin WebSocket connection](browser.ws(spec=`open`))**.
|
||||
Return *[Keep transport and native control wiring together](browser.merge(a=`bindings`, b=`socket`))*.
|
||||
|
||||
## _status
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| text | text | required | Plain connection status to display |
|
||||
| disabled | bool | required | Actual native disabled state for the send button |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Combined status-text and button-attribute effects |
|
||||
|
||||
Use `text` and `disabled` to keep connection feedback consistent with the send control. The attribute must remain a boolean: the bridge removes disabled when False, while the string "false" would still be a present HTML boolean attribute. These effects describe a DOM update and do not send or retry a message.
|
||||
|
||||
We **attributes = [Keep the actual boolean attribute value](table.put(in=None, at="disabled", value=`disabled`))** and **status = [Describe plain connection feedback](browser.set_text(sel="#live-status", text=`text`))** and **button = [Describe actual send availability](browser.set_attr(sel="#live-send", attrs=`attributes`))**.
|
||||
Return *[Keep the independent effect kinds together](browser.merge(a=`status`, b=`button`))*.
|
||||
|
||||
## on_open
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| ok | bool | True | Actual browser transport opening result |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Connected feedback and enabled send, or failed feedback and disabled send |
|
||||
|
||||
Use `ok`=True from the opening callback. A successful opening proves only the transport is ready; an echoed message is observed separately. Failed opening keeps send disabled and visible as failure. The client does not publish a fake initial echo or silently retry.
|
||||
|
||||
1. `ok`
|
||||
Return *[Enable sending only after transport opens](_status(text="connected", disabled=False))*.
|
||||
Return *[Keep failed opening visible](_status(text="connection failed", disabled=True))*.
|
||||
|
||||
## _send
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| value | text | required | Input text supplied by a click or Enter callback |
|
||||
| channel | text | required | Existing socket id retained by the client entry |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | One actual send instruction, or None for empty trimmed input |
|
||||
|
||||
Use `value` and `channel` to share the original widget's send policy. Trim surrounding whitespace and ignore an empty result. A nonempty message remains plain text, never a command or HTML. The official bridge reports transport errors separately. This helper receives its channel explicitly rather than assuming an ordinary nested call automatically captures entry state.
|
||||
|
||||
We **payload = [Keep the original trim-before-send behavior](text.str_trim(s=`value`))**.
|
||||
1. `payload` == ""
|
||||
Return *None* because an empty or whitespace-only input performs no send.
|
||||
|
||||
`operation` =
|
||||
|
||||
| op | id | data |
|
||||
|---|---|---|
|
||||
| send | `channel` | `payload` |
|
||||
|
||||
Return *[Send one nonempty message through the existing connection](browser.ws(spec=`operation`))*.
|
||||
|
||||
## send
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| value | text | "" | Current text supplied by the send-button wiring |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Send effect for nonempty trimmed input, otherwise None |
|
||||
|
||||
Use `value`="" from a button click. The direct browser callback can read retained entry state and passes that socket id explicitly to the pure send helper. The log updates only after an actual echo arrives, so clicking cannot fabricate successful delivery. Whitespace-only input retains the original widget's no-send behavior.
|
||||
|
||||
Return *[Apply the shared send policy to this click](_send(value=`value`, channel=`ws_id`))*.
|
||||
|
||||
## on_key
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| key | text | "" | Actual key name supplied by the official bridge |
|
||||
| value | text | "" | Current message input supplied by this control's value selector |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Enter uses the same send policy as the button; other keys return None |
|
||||
|
||||
Use `key`="" and `value`="" from the keyboard wiring. Preserve the original Enter shortcut without sending on every keydown. Enter and click share trimming and empty-input behavior, and neither appends a local echo before a real frame arrives. This callback does not install another DOM handler or start a second socket.
|
||||
|
||||
1. `key` == "Enter"
|
||||
Return *[Apply exactly the button's send policy](_send(value=`value`, channel=`ws_id`))*.
|
||||
Return *None* for an ordinary editing key.
|
||||
|
||||
## on_message
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| data | text | "" | Actual echoed text frame from the server |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Plain text update containing the retained echo log |
|
||||
|
||||
Use `data`="" from the message callback. Append each real frame and a newline to entry state, preserving earlier messages as the old widget did. set_text escapes content through the bridge; a message containing markup is shown literally. Reloading starts a fresh demonstration log and no durable history is claimed.
|
||||
|
||||
We **messages = [Retain the next observed echo](messages + "echo: " + data + "\n")**.
|
||||
Return *[Display the complete observed log as text](browser.set_text(sel="#live-out", text=`messages`))*.
|
||||
|
||||
## on_error
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| error | text | "" | Browser transport error description |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Error feedback and disabled sending |
|
||||
|
||||
Use `error`="" to retain the actual transport failure beside the controls. No previous message is erased and no new send is attempted. The page can be reloaded for a fresh connection; this demonstration has no hidden reconnect policy.
|
||||
|
||||
We **message = "error: " + error**.
|
||||
Return *[Keep failure and send availability consistent](_status(text=`message`, disabled=True))*.
|
||||
|
||||
## on_close
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Closed feedback with disabled send control |
|
||||
|
||||
A close notification keeps the message log readable while marking the socket unavailable. It neither clears entry state nor silently creates another connection. Subsequent sends require a newly opened page session rather than a fabricated successful transport.
|
||||
|
||||
Return *[Keep closure visible](_status(text="closed", disabled=True))*.
|
||||
@@ -1,40 +0,0 @@
|
||||
// Live widget for the /live WebSocket endpoint.
|
||||
// Connects to ws://host/live, sends the input, shows the echo.
|
||||
(function () {
|
||||
var out = document.getElementById("live-out");
|
||||
var input = document.getElementById("live-msg");
|
||||
var btn = document.getElementById("live-send");
|
||||
var status = document.getElementById("live-status");
|
||||
if (!out || !input || !btn || !status) return;
|
||||
|
||||
var proto = location.protocol === "https:" ? "wss" : "ws";
|
||||
var ws = new WebSocket(proto + "://" + location.host + "/live");
|
||||
status.textContent = "connecting…";
|
||||
|
||||
ws.onopen = function () {
|
||||
status.textContent = "connected";
|
||||
btn.disabled = false;
|
||||
};
|
||||
ws.onmessage = function (ev) {
|
||||
var p = document.createElement("p");
|
||||
p.textContent = "echo: " + ev.data;
|
||||
out.appendChild(p);
|
||||
out.scrollTop = out.scrollHeight;
|
||||
};
|
||||
ws.onclose = function () {
|
||||
status.textContent = "closed";
|
||||
btn.disabled = true;
|
||||
};
|
||||
ws.onerror = function () {
|
||||
status.textContent = "error";
|
||||
btn.disabled = true;
|
||||
};
|
||||
|
||||
btn.onclick = function () {
|
||||
var m = input.value.trim();
|
||||
if (m) ws.send(m);
|
||||
};
|
||||
input.addEventListener("keydown", function (e) {
|
||||
if (e.key === "Enter") btn.onclick();
|
||||
});
|
||||
})();
|
||||
@@ -1,9 +1,16 @@
|
||||
---
|
||||
markup: occlusion
|
||||
import:
|
||||
web: ext/web/web.mq.md
|
||||
text: lib/text.mq.md
|
||||
---
|
||||
|
||||
## topnav
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | The value explicitly returned below; conditional returns follow the selected branch |
|
||||
|
||||
`topnav` =
|
||||
|
||||
| 属性 | 值 |
|
||||
@@ -11,20 +18,28 @@ markup: occlusion
|
||||
| background | #ffffff |
|
||||
| border-bottom | 1px solid #e7e5e4 |
|
||||
|
||||
*`topnav`*
|
||||
After these steps, return *topnav*.
|
||||
|
||||
## side_panel
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | The value explicitly returned below; conditional returns follow the selected branch |
|
||||
|
||||
`side_panel` =
|
||||
|
||||
| 属性 | 值 |
|
||||
|------|-----|
|
||||
| background | #f5f5f4 |
|
||||
|
||||
*`side_panel`*
|
||||
After these steps, return *side_panel*.
|
||||
|
||||
## card_title
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | The value explicitly returned below; conditional returns follow the selected branch |
|
||||
|
||||
`card_title` =
|
||||
|
||||
| 属性 | 值 |
|
||||
@@ -32,10 +47,14 @@ markup: occlusion
|
||||
| font-size | 1.15rem |
|
||||
| margin | 0 0 0.35rem |
|
||||
|
||||
*`card_title`*
|
||||
After these steps, return *card_title*.
|
||||
|
||||
## card_body
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | The value explicitly returned below; conditional returns follow the selected branch |
|
||||
|
||||
`card_body` =
|
||||
|
||||
| 属性 | 值 |
|
||||
@@ -43,4 +62,28 @@ markup: occlusion
|
||||
| color | #57534e |
|
||||
| margin | 0 |
|
||||
|
||||
*`card_body`*
|
||||
After these steps, return *card_body*.
|
||||
|
||||
## css
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | text | CSS compiled from the original four declarative property tables |
|
||||
|
||||
Call with plugin before discovery. This task preserves the original top navigation background/border, side-panel background, card title size/spacing and card body color/spacing. The selector names target the native components and query-card markup directly. The property functions remain independently callable, so changing one region does not require editing a raw CSS string.
|
||||
|
||||
The server writes the returned text through native filesystem IO into its explicit generated resource path. Compilation itself neither writes that file nor mounts static content. These four sections keep their original order; the general View runtime still owns responsive row geometry. A compiler diagnostic stops serving instead of substituting an old stylesheet.
|
||||
|
||||
We **nav = [Read the original navigation declarations](topnav())** and **side = [Read the original side-panel declarations](side_panel())** and **title = [Read the original title declarations](card_title())** and **body = [Read the original summary declarations](card_body())**.
|
||||
We **nav_css = [Compile the navigation selector](web.make_style(name="topnav", table=`nav`))** and **side_css = [Compile the side selector](web.make_style(name="side", table=`side`))** and **title_css = [Compile the native card title selector](web.make_style(name="content.cards h2", table=`title`))** and **body_css = [Compile the native card body selector](web.make_style(name="content.cards p", table=`body`))**.
|
||||
|
||||
`parts` =
|
||||
|
||||
| css |
|
||||
|---|
|
||||
| `nav_css` |
|
||||
| `side_css` |
|
||||
| `title_css` |
|
||||
| `body_css` |
|
||||
|
||||
Return *[Keep the compiled sections in order](text.str_join(xs=`parts`, sep="\n"))*.
|
||||
Reference in new issue
Block a user