包文件→ .shtukbase/packages/layout-studio/README.md
README.md
89 行, 4.9 KB.
这段内容尚未翻译,下面是英文原文。
- # layout-studio
- A second, richer layout for the prototype cloud app: pages open as tabs, the main area splits in
- two, and a resizable right panel holds lenses contributed to the `panel` slot. Lenses are unchanged:
- they link `/_pkg/layout-basic/lens.js` and work in both layouts.
- Files: `shell.html`, `shell.css`, `shell.js` (served at `/`), `package.md` (with the `settings:`
- block), `test/fake-host.ts`, `test/props-lens.html` (the demo panel lens "Свойства").
- Run: `bun apps/standard/packages/layout-studio/test/fake-host.ts 4377` (add `CACHE=long` to send
- `Cache-Control: public, max-age=31536000, immutable` for `/_pkg` and `/_kit`, as real hosts do).
- ## Behaviour
- - Sidebar click opens the page in the focused side's current tab; Cmd/Ctrl-click or middle-click
- opens a new tab; Alt-click opens it on the right half (split). Opening a page that is already open
- focuses its tab.
- - Tabs: click focuses, × or middle-click closes. With the `tabs` setting off there is one view.
- - Split: the button in the top bar (or Alt-click) opens the right half; × on its header closes it.
- The focused side is the one last clicked (the shell watches `document.activeElement`); the crumbs,
- the lens switch and the right panel follow it.
- - Right panel: its own tab strip, one tab per panel contribution. Resize edge on its left: drag,
- arrow keys (16 px), Home or double-click resets to 320 px; limits 240..560 px and at least 480 px
- stay for the document; the width is kept in `localStorage['studio.panelWidth']`.
- - Settings popover (top bar): flips the settings live; values in `localStorage['studio.<key>']`,
- defaults from `package.md` (fetched once at boot, in parallel with `space.info` and `tree`).
- ## URL (all view state; reload and back/forward restore it)
- `/?t=<lens>:<path>&t=...&a=<active tab index>&s=<lens>:<path>&f=R&p=<panel lens id>`
- - `t` once per tab, in order; `<lens>` may be empty (the first lens for the page's kind).
- - `a` omitted when 0; `s` is the right half; `f=R` when the right half has focus; `p` the panel tab.
- - `?path=&lens=` (layout-basic links, `lens.js` standalone `open`) is accepted as one tab.
- - Every change is a `pushState`; a focus change is a `replaceState`. The last URL is also kept in
- `localStorage['studio.last']` and used when `/` is opened bare.
- ## Caching
- - All frames sit in one stage and are placed by class (`L`, `R`), so a frame is never moved in the
- DOM (moving reloads it). Frames of open tabs and of the split stay alive; any other frame (closed
- tabs, hover preloads, other lenses) goes to an LRU of 8.
- - A frame is swapped in after `shtuk.ready()` or 800 ms; until then the old one stays on screen.
- - Hovering a sidebar row or a lens tab preloads its frame.
- - The tree is polled every 5 s only while the page is visible and the sidebar shown; records are
- read only by lenses.
- ## Contract additions (proposed for apps/cloud/CONTRACT.md)
- 1. **Focus message (shell to panel frames).** The shell posts to every frame shown in the right
- panel, after it is ready and whenever the focused main view changes:
- ```js
- { type: 'focus', path: '/leads/lead-1.md' } // path: string | null (nothing open)
- ```
- The panel frame's first path is also in its URL (`?path=`), so `shtuk.path` is right before the
- first message. `lens.js` does not route this message today, so a panel lens listens itself:
- `window.addEventListener('message', e => e.source === parent && e.data.type === 'focus' && ...)`.
- Proposal for lens.js: route it to `shtuk.on('focus', fn)` and update `shtuk.path`.
- 2. **Panel slot.** A package contributes a panel lens with `slot: panel`:
- ```yaml
- contributes:
- - {lens: props, file: props.html, title: "Свойства", for: Record, slot: panel}
- ```
- `space.info` lists contributions as
- `contributions: [{package, lens, file, title, for?, slot}]` (`slot` defaults to `main`). If
- `contributions` is absent, the shell takes `lenses` entries with `slot: "panel"`. Lenses with
- another slot than `main` never appear as main lenses.
- 3. **Settings block in package.md.**
- ```yaml
- settings:
- - {key: tabs, kind: bool, label: "Вкладки", default: true}
- - {key: panel, kind: bool, label: "Правая панель", default: true}
- - {key: sidebarWidth, kind: select, label: "Ширина боковой панели", default: normal, options: [narrow, normal, wide]}
- ```
- `kind` is `bool` or `select` (`options` required for `select`). Until a settings package exists,
- the value is `localStorage['studio.<key>']`, falling back to `default`.
- 4. **Open with a mode (optional field).** The shell accepts `{type: 'open', path, mode}` with
- `mode: 'here' | 'tab' | 'split'` (absent means `here`). `lens.js` sends no mode today, so a click
- in a table lens opens in the current tab; a modifier-click in a lens needs
- `shtuk.open(path, {mode})` in lens.js (proposal, not done: lens.js is not forked here).