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,12 +1,16 @@
|
||||
# web-collab-doc
|
||||
|
||||
Two-browser collaborative notepad over WebSocket room (last-write-wins text).
|
||||
这个工程演示同源 WebSocket 房间中的双浏览器记事本。客户端发送完整文本快照,收到的较新消息覆盖本地内容;它不实现 CRDT、离线合并或持久化历史。服务只在本机演示端口提供匿名房间,部署前应配置真实鉴权。
|
||||
|
||||
```bash
|
||||
marqdo wasm build -o examples/web-collab-doc/static
|
||||
cd examples/web-collab-doc
|
||||
marqdo run index.mq.md
|
||||
# open http://127.0.0.1:18094 twice
|
||||
从仓库根目录构建当前浏览器运行时,再启动服务:
|
||||
|
||||
```sh
|
||||
marqdo call skills/marqdo-dev/index.mq.md build_browser 'out="examples/web-collab-doc/static"' --effects plugin,process.exec,fs.write --fs-root . --require-ok --json
|
||||
marqdo call examples/web-collab-doc/index.mq.md serve --effects plugin,fs.read,network.write --fs-root . --json
|
||||
```
|
||||
|
||||
Design: [ext-web-collab.md](../../doc/design/ext-web-collab.md).
|
||||
打开 http://127.0.0.1:18094 两次,在任一窗口编辑文本。另一窗口收到快照后仍可继续本地编辑,空文本也是有效快照。构建缺少兼容 WASM 目标时,先按 [工具链手册](../../skills/marqdo-dev/toolchain.mq.md) 准备工作区编译器,把返回的 compiler 传给 build_browser。
|
||||
|
||||
入口 [index.mq.md](index.mq.md) 负责页面发现与房间绑定;[home.mq.md](home.mq.md) 组合说明、编辑器和状态,末端内容与控件分别可读;[客户端](static/client.mq.md) 直接表达输入、消息和在线状态处理。
|
||||
|
||||
[开发手册](../../skills/marqdo-dev/index.mq.md) 的 test_browser 使用当前构建运行真实双页交互,覆盖远端更新后的下一次本地输入、空文本与在线状态。设计背景见 [协作设计](../../doc/design/ext-web-collab.md)。
|
||||
@@ -0,0 +1,28 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Native collaborative editor leaf
|
||||
import:
|
||||
component: ext/web/component/index.mq.md
|
||||
table: lib/table.mq.md
|
||||
---
|
||||
|
||||
This intrinsic label/textarea pair contains no socket, page shell or generated HTML.
|
||||
|
||||
## nodes
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | Accessible native multiline editor rows |
|
||||
|
||||
The label names the same doc id used by the client input binding. Rows and columns are typed native attributes rather than interpolated markup. Initial content is empty and ordinary text; the bridge later changes its value. Geometry outside this intrinsic field pair belongs to the parent page component.
|
||||
|
||||
We **label_attrs = [Associate the visible label with the editor](table.put(in=None, at="for", value="doc"))** and **label = [Describe the plain editor label](component.element(kind="label", value="Shared text", attrs=`label_attrs`, slot="editor-label"))**.
|
||||
|
||||
`attrs` =
|
||||
|
||||
| id | rows | cols | aria-label |
|
||||
|---|---|---|---|
|
||||
| doc | 16 | 72 | Shared text |
|
||||
|
||||
We **editor = [Describe the native multiline control](component.element(kind="textarea", attrs=`attrs`, slot="editor"))**.
|
||||
Return *[Keep the field label before its native control](table.concat(a=`label`, b=`editor`))*.
|
||||
@@ -0,0 +1,25 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Collaborative page assembly
|
||||
import:
|
||||
component: ext/web/component/index.mq.md
|
||||
client: ext/web/client/index.mq.md
|
||||
editor: editor.mq.md
|
||||
status: status.mq.md
|
||||
fs: lib/fs.mq.md
|
||||
table: lib/table.mq.md
|
||||
---
|
||||
|
||||
The page composes a terminal Markdown introduction, intrinsic native controls and an official runtime Resource.
|
||||
|
||||
## nodes
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | Complete structured collaborative page |
|
||||
|
||||
The introduction is read as ordinary Markdown from intro.md within the granted site root. The editor and status are independent control leaves, while the script Resource refers to the actual built bridge and WASM files. This assembly describes one page and starts no server or socket. Transport policy remains in serve and client behavior remains in static/client.mq.md.
|
||||
|
||||
We **text = [Read the terminal Markdown introduction](fs.read_text(path="intro.md"))** and **intro = [Describe the introduction as Markdown](component.markdown(text=`text`, slot="intro"))** and **field = [Assemble the independent native editor](editor.nodes())** and **feedback = [Assemble presence and connection status](status.nodes())** and **runtime = [Reference the official client program](client.nodes(source="/static/client.mq.md"))**.
|
||||
We **body = [Keep introduction before the editor](table.concat(a=`intro`, b=`field`))** and **visible = [Place independent feedback after the field](table.concat(a=`body`, b=`feedback`))**.
|
||||
Return *[Retain runtime loading as a separate resource](table.concat(a=`visible`, b=`runtime`))*.
|
||||
@@ -1,26 +1,39 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: web-collab-doc
|
||||
description: Two-browser collaborative plain-text editor over WS room (LWW snapshot sync)
|
||||
type: web
|
||||
view: main
|
||||
route: /
|
||||
title: Collaborative document — declared layout and room Resource
|
||||
import:
|
||||
home: home.mq.md
|
||||
web: ext/web/web.mq.md
|
||||
socket: ext/net/websocket.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
Open two controlled browser tabs to observe complete text snapshots and room presence. This loopback demonstration explicitly permits anonymous room access. It is not durable storage, a CRDT or a history replay service. Build the current browser assets into static before serving.
|
||||
|
||||
Collaborative notepad: open the page in two browsers; edits fan out via
|
||||
`/live/{room}` WebSocket (mode=room + presence). Build WASM first:
|
||||
## main
|
||||
|
||||
```
|
||||
marqdo wasm build -o examples/web-collab-doc/static
|
||||
```
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | Collaborative page View rows |
|
||||
|
||||
**`embed` = > web.client_embed bridge="/static/marqdo-bridge.js" wasm="/static/marqdo_wasm.wasm" source="/static/client.mq.md" boot=True**
|
||||
The Document delegates to the readable page assembly. Follow its imports to the Markdown introduction, native editor and status leaves; none assembles a raw HTML shell. The bridge is a structured Resource. Page assembly reads the selected site root and returns structure before any listener starts.
|
||||
|
||||
**`intro` = "<p class='lede'>Room <code>demo</code> · open twice to co-edit.</p><p id='presence'>presence: —</p><textarea id='doc' rows='16' cols='72' placeholder='Type together…'></textarea><pre id='log'></pre>" + embed**
|
||||
Return *[Assemble the native collaborative page](home.nodes())*.
|
||||
|
||||
**page = > web.page title="Collab doc" intro=intro layout="bare"**
|
||||
**app = > web.app page=page host="127.0.0.1" port=18094**
|
||||
**app = > app.static dir="static" mount="/static"**
|
||||
**app = > `app`.route_ws path="/live/{id}" mode="room" room_key="doc.{id}" presence=True**
|
||||
> `app`.listen
|
||||
## serve
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| root | text | "examples/web-collab-doc" | Explicit site directory relative to the checkout root |
|
||||
| port | number | 18094 | Loopback server port |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Blocking listener for the declared page and collaboration room |
|
||||
|
||||
Use `root`="examples/web-collab-doc" and `port`=18094. Prepare the page and static mount, bind the network-owned /live/{id} room and its presence channel, then listen with the retained site context. Anonymous access is deliberate for this localhost demonstration; a deployed application should attach authentication and retain private room defaults. The client uses a relative WebSocket address, so changing this port keeps the same page/client contract.
|
||||
|
||||
We **app = [Discover the page and its static resources](web.prepare(root=`root`, host="127.0.0.1", port=`port`, static_dir="static"))** and **app = [Bind the declared snapshot and presence room](socket.route(app=`app`, path="/live/{id}", mode="room", room_key="doc.{id}", presence=True, require_auth=False))**.
|
||||
Return *[Listen after layout and transport are ready](web.listen(app=`app`))*.
|
||||
@@ -0,0 +1,5 @@
|
||||
# Shared notepad
|
||||
|
||||
Open this page in **two browser tabs**. Both join `/live/demo` and display native room presence.
|
||||
|
||||
Each edit sends a complete text snapshot. The last received snapshot wins; this demonstration does not store document history or synchronize edits as a CRDT.
|
||||
@@ -1,87 +1,124 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: collab client
|
||||
description: LWW text sync over WS room + presence (DOC\\t protocol)
|
||||
title: Collaborative client — native text snapshots and presence
|
||||
import:
|
||||
browser: lib/browser.mq.md
|
||||
table: lib/table.mq.md
|
||||
text: lib/text.mq.md
|
||||
---
|
||||
|
||||
This program owns document text and event transitions. The Document supplies the native textarea and status leaves; the network resource supplies a same-origin room. All business state stays in Marqdo.
|
||||
|
||||
# main
|
||||
|
||||
**`ws_id` = "doc"**
|
||||
**`applying` = False**
|
||||
**`doc` = ""**
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Client wiring, room connection and initial status effects |
|
||||
|
||||
The client keeps only the last locally observed document text in native entry state. Each edit sends a complete DOC-tab-text snapshot; this is a last-received-message demonstration, not a CRDT, document database or history synchronization service. The relative socket path follows the page's host and port, so a different loopback listen port does not require editing client code. Presence and document messages use separate displayed targets. The official bridge changes textarea.value without emitting a new input event, so applying remote text needs no flag that would discard the next real local edit. BrowserSession retains entry bindings between event callbacks.
|
||||
|
||||
We **ws_id = "doc"** and **doc = ""** before connecting.
|
||||
|
||||
`wire` =
|
||||
|
||||
| @ | 选择器 | 事件 | 调用 | 值选择器 |
|
||||
|---|--------|------|------|----------|
|
||||
|---|---|---|---|---|
|
||||
| 1 | "#doc" | input | on_edit | "#doc" |
|
||||
|
||||
`open` =
|
||||
|
||||
| op | id | url | then_open | then_message | then_error | then_close |
|
||||
|----|----|-----|-----------|--------------|------------|------------|
|
||||
| open | `ws_id` | "ws://127.0.0.1:18094/live/demo" | on_open | on_msg | on_err | on_close |
|
||||
|---|---|---|---|---|---|---|
|
||||
| open | `ws_id` | /live/demo | on_open | on_msg | on_err | on_close |
|
||||
|
||||
**`w` = > table.put in=None at="wire" value=wire**
|
||||
**`ws` = > browser.ws spec=open**
|
||||
**`boot` = > browser.merge a=w b=ws**
|
||||
**`ready` = > browser.set_text sel="#log" text="connecting…"**
|
||||
*> browser.merge a=boot b=ready*
|
||||
We **wiring = [Bind the existing native textarea](table.put(in=None, at="wire", value=`wire`))** and **socket = [Describe the same-origin room connection](browser.ws(spec=`open`))** and **boot = [Keep wiring and transport together](browser.merge(a=`wiring`, b=`socket`))** and **ready = [Describe the initial connection status](browser.set_text(sel="#log", text="connecting…"))**.
|
||||
Return *[Keep initial status with the boot instructions](browser.merge(a=`boot`, b=`ready`))*.
|
||||
|
||||
## on_open
|
||||
+ `ok`=True
|
||||
|
||||
*> browser.set_text sel="#log" text="ws open · room demo"*
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| ok | bool | True | Success flag from the bridge's open callback |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Plain connection status effect |
|
||||
|
||||
Use `ok`=True from the open callback. A successful transport opening says that the room is connected; it does not prove that previous document content was replayed. This callback updates only the log. Presence frames arrive independently through on_msg, and actual editing remains available through the existing textarea binding.
|
||||
|
||||
1. `ok`
|
||||
Return *[Show that the native room connection opened](browser.set_text(sel="#log", text="ws open · room demo"))*.
|
||||
Return *[Keep an unsuccessful open visible](browser.set_text(sel="#log", text="ws open failed"))*.
|
||||
|
||||
## on_err
|
||||
+ `error`=""
|
||||
|
||||
**`msg` = "ws error: " + error**
|
||||
*> browser.set_text sel="#log" text=msg*
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| error | text | "" | Error text supplied by the browser transport |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Plain error text effect |
|
||||
|
||||
Use `error`="" from the bridge. Preserve its text in the status log rather than treating a failed connection as an empty successful document. This callback neither rewrites shared text nor retries a send, so the caller can observe the actual transport state without a hidden duplicate update.
|
||||
|
||||
We **message = "ws error: " + error**.
|
||||
Return *[Display the actual transport failure as text](browser.set_text(sel="#log", text=`message`))*.
|
||||
|
||||
## on_close
|
||||
*> browser.set_text sel="#log" text="ws closed"*
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Closed connection status effect |
|
||||
|
||||
A close notification updates the log while retaining the last displayed document text. This demonstration does not silently reconnect or persist data elsewhere. Reopening the page starts a fresh client session, and subsequent edits need a live socket before peers can receive them.
|
||||
|
||||
Return *[Keep closure visible beside the editor](browser.set_text(sel="#log", text="ws closed"))*.
|
||||
|
||||
## on_edit
|
||||
+ `value`=""
|
||||
|
||||
1. `applying`
|
||||
**`applying` = False**
|
||||
****
|
||||
2. *
|
||||
**`doc` = value**
|
||||
**`payload` = "DOC\t" + value**
|
||||
`send` =
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| value | text | "" | Current plain textarea contents, including an intentionally empty document |
|
||||
|
||||
| op | id | data |
|
||||
|----|----|------|
|
||||
| send | `ws_id` | `payload` |
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | One complete snapshot send instruction, or None for unchanged text |
|
||||
|
||||
*> browser.ws spec=send*
|
||||
Use `value`="" from the input binding. A changed value replaces the native observed text and becomes one DOC-tab snapshot; an empty value is a valid deletion, not a missing edit. Identical input produces no send. Incoming set_value effects do not emit input, so the next real user edit after a remote update must be sent immediately. The callback describes a browser WebSocket action and opens no native socket itself.
|
||||
|
||||
1. `value` == `doc`
|
||||
Return *None* because the observed text is unchanged.
|
||||
We **doc = [Retain the complete new native text](value)** and **payload = "DOC\t" + value**.
|
||||
|
||||
`send` =
|
||||
|
||||
| op | id | data |
|
||||
|---|---|---|
|
||||
| send | `ws_id` | `payload` |
|
||||
|
||||
Return *[Send the complete snapshot through the existing room connection](browser.ws(spec=`send`))*.
|
||||
|
||||
## on_msg
|
||||
+ `data`=""
|
||||
|
||||
1. `data` != ""
|
||||
**`is_pres` = > text.starts_with text=data prefix="{"**
|
||||
1. `is_pres`
|
||||
**`msg` = "presence: " + data**
|
||||
*> browser.set_text sel="#presence" text=msg*
|
||||
2. *
|
||||
**`is_doc` = > text.starts_with text=data prefix="DOC\t"**
|
||||
1. `is_doc`
|
||||
**`remote` = > text.replace text=data old="DOC\t" new="" count=1**
|
||||
1. `remote` != `doc`
|
||||
**`doc` = remote**
|
||||
**`applying` = True**
|
||||
*> browser.set_value sel="#doc" value=remote*
|
||||
2. *
|
||||
****
|
||||
2. *
|
||||
****
|
||||
2. *
|
||||
****
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| data | text | "" | One text frame from the room or its presence channel |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Presence text, a remote textarea value, or None for ignored/echoed frames |
|
||||
|
||||
Use `data`="" from the transport callback. Presence records are displayed separately and never interpreted as document text. A DOC-tab frame contains the entire replacement document, including a possible empty string. Retain that observed text before returning its set_value instruction; an echoed snapshot equal to local state then becomes a no-op. Unknown messages and empty frames leave content unchanged. No JavaScript, HTML or external interpreter parses the document payload.
|
||||
|
||||
1. `data` == ""
|
||||
Return *None* for an empty frame.
|
||||
1. [A native presence record](text.starts_with(text=`data`, prefix="{"))
|
||||
We **message = "presence: " + data**.
|
||||
Return *[Display room presence independently](browser.set_text(sel="#presence", text=`message`))*.
|
||||
1. [A complete document snapshot](text.starts_with(text=`data`, prefix="DOC\t"))
|
||||
We **remote = [Remove only the leading protocol marker](text.replace(text=`data`, old="DOC\t", new="", count=1))**.
|
||||
1. `remote` != `doc`
|
||||
We **doc = [Retain the received native text](remote)**.
|
||||
Return *[Apply remote text without manufacturing an input event](browser.set_value(sel="#doc", value=`remote`))*.
|
||||
Otherwise return *None* for unrelated frames or an already observed snapshot.
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Presence and transport status leaves
|
||||
import:
|
||||
component: ext/web/component/index.mq.md
|
||||
table: lib/table.mq.md
|
||||
---
|
||||
|
||||
Presence information and connection diagnostics have separate native text targets.
|
||||
|
||||
## nodes
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | list | Ordered presence and log leaves |
|
||||
|
||||
Presence frames update one plain-text region, while connection lifecycle messages update a preformatted log. Their stable ids match client callbacks, and neither contains document text or performs transport operations. The parent places these leaves around the independent editor; messages are escaped by the native renderer and later set_text effects.
|
||||
|
||||
`presence_attrs` =
|
||||
|
||||
| id | role | aria-live |
|
||||
|---|---|---|
|
||||
| presence | status | polite |
|
||||
|
||||
`log_attrs` =
|
||||
|
||||
| id | role |
|
||||
|---|---|
|
||||
| log | log |
|
||||
|
||||
We **presence = [Describe the plain presence target](component.element(kind="text", value="Waiting for peers.", attrs=`presence_attrs`, slot="presence"))** and **log = [Describe connection feedback separately](component.element(kind="pre", value="connecting…", attrs=`log_attrs`, slot="log"))**.
|
||||
Return *[Keep presence before transport feedback](table.concat(a=`presence`, b=`log`))*.
|
||||
Reference in new issue
Block a user