ShtukbaseStandard
package file→ .shtukbase/packages/lenses/kit/README.md

kit/README.md

182 lines, 13.9 KB.

  1. # Shtukbase HTML lenses
  2. A lens is an HTML page that shows the records of a Shtukbase base in its own perspective:
  3. architecture with links, an ontology of types, nesting, a board. The source of truth is markdown records;
  4. lenses are built from them by a script and rebuilt on every change of the base.
  5. **Where it lies.** Since 28.11.2026 the kit is part of the standard's `lenses` package: `apps/standard/packages/lenses/kit/` in the repository,
  6. `.shtukbase/packages/lenses/kit/` in a project after install. In a project it is run by the package's actions:
  7. `shtuk run lenses build | check | serve`. There are no npm dependencies: js-yaml lies as one file in `vendor/`
  8. (the build `dist/js-yaml.min.js`, the MIT license in `vendor/js-yaml.LICENSE`); `bun install` is not needed.
  9. **Ready patterns (patterns/).** Building a map lens — one canvas with pictures on cards, frames, a tree and
  10. a view switch — step by step: [`patterns/map.md`](patterns/map.md), a working example in `examples/base/`.
  11. Card pictures in the set's style and the helper `bin/shtukbase-icons.js`: [`patterns/pictures.md`](patterns/pictures.md).
  12. ```
  13. <base>/
  14. lib/ ← the one helper folder of the base (in the base root, visible, no dot)
  15. kit.js, kit.css ← the component set and templates (in git); kit.css = the skins and style of the kit-style package + its own part kit/kit.css
  16. index.html ← the gallery of all lenses (in git)
  17. data.js ← the base's records in one file (built, not in git)
  18. bodies.js ← the records' texts, loaded when a record is first opened (built, not in git)
  19. <layer>/*.data.js ← the layer's lens data from the standard's generators (in git)
  20. <any folder>/x.html ← an HTML lens: the header `type: Lens` in the first comment
  21. ```
  22. A lens lies anywhere and links `lib/` by a relative path (`../lib/kit.js`,
  23. `../../lib/kit.js` …). This way it opens both in Shtukbase and straight from disk (`file://`, a double
  24. click), no server needed. A browser does not let a page from disk read `.md` files (`fetch` to `file://`
  25. is forbidden), but `<script src>` is allowed — so the data is built into `data.js`. After a clone:
  26. `shtukbase-lenses build` in the base root.
  27. ## Commands
  28. ```sh
  29. bun bin/shtukbase-lenses.js build --root <base> # build the lenses
  30. bun bin/shtukbase-lenses.js check --root <base> # check that lenses are up to date (code 1 — out of date)
  31. bun bin/shtukbase-lenses.js hook --root <base> # print a git hook that rebuilds the lenses
  32. ```
  33. It also works under Node. There are no npm dependencies.
  34. ## A new lens
  35. Create `<base>/lenses/<id>.lens.md`:
  36. ```yaml
  37. ---
  38. type: Lens
  39. title: Title
  40. icon: "🧭"
  41. description: "One line: what is visible on this lens"
  42. template: canvas # canvas | lanes | types | nest | board | custom
  43. ...template parameters
  44. ---
  45. The text "About the lens": how to read the picture. Links to records are as in the base: [agents](/product/agents.md).
  46. ```
  47. Run `shtukbase-lenses build` — `<id>.html` and a card in `index.html` appear.
  48. ### How to select records
  49. The same in all templates: `from` — a folder (`/product/agents`), `type` — a record type,
  50. `where` / `not` — a filter on fields (`{kind: channel}`, a value or a list), `sort` — the sort field.
  51. ### Templates
  52. | Template | What it shows | Main parameters |
  53. |---|---|---|
  54. | `canvas` — canvas | areas with cards and arrows along link fields | `layout {columns, stacks \| areas}`, `regions [{id, title, from, where, group, card, linked}]`, `edges [{field, from, to, label, color, dash, reverse}]` |
  55. | `lanes` — lanes | rows by a field's value (for example, a business function), inside — columns: entry → main path → branches, a shared column on the right; arrows along link fields, filters in the side panel | `lane {field, sort, other}`, `columns [{id, title, role: entry\|main\|child\|side, from, where, attach, parent, sortBy, card}]`, `edges [… off]`, `filters` |
  56. | `types` — ontology | record types by layer and the links between types | `layers`, `skipTypes`, `skipFields`, `layout {columns, stacks \| areas}` |
  57. | `nest` — nesting | boxes inside boxes by a parent field | `from`, `parent`, `group`, `groupOrder`, `chips`, `refs` |
  58. | `board` — board | columns by a field, link counters on the cards | `by`, `columns {from, sort}`, `card`, `meters [{label, field} \| {label, back}]` |
  59. | `custom` — own layout | anything | `script`, `style` — files next to the lens |
  60. Details are in the header of each file `kit/templates/*.js`.
  61. A link in `edges` can have `off: true` — that kind of link is hidden at first and is turned on by clicking the legend.
  62. A link kind can combine several fields: `fields: [field, …]` instead of `field`; `edgeLabel: true` labels
  63. the arrow with the field's name. Record fields whose name starts with `_` are service fields: the record card does not show them.
  64. A canvas also has `counters [[label, number], …]` — a row of counters above the canvas, `list {title, hint, groups, card}` —
  65. record cards under the canvas, `fit: "width"` — shrink a wide canvas to the window width on opening.
  66. This is how, for example, the lens of concept links of a layer in shtukbase-standard is built (`render_layer_ontology.py`).
  67. It is meant for frequent links that without a filter turn a canvas into a cobweb (an example is `leads on to` in the scenario map).
  68. In YAML records boolean values are only `true`/`false`; `on`, `off`, `yes`, `no` are read as strings.
  69. ### Compact layout
  70. A lens does not stretch to the whole screen: the content is centered and takes as much room as it needs.
  71. - No long rows: up to three cards or areas stand in a row, beyond that the group folds into a grid close to a square
  72. (9 is 3×3, 6 is 3×2), a row is no longer than four. The columns are computed by `Lens.gridCols(count, cap)`; on a canvas `columns: auto` on an area does the same (`units: auto` if the
  73. cards have a `size`). In your own layout call `Lens.gridCols` yourself. The class `lx-lines-3` holds exactly three lines for text —
  74. cards in a row come out the same height.
  75. - Canvas: an area with `tree: <field>` is drawn as a tree left to right — a card, and to the right those that enter it by this field.
  76. - Canvas: `layout.groups` — named stacks of areas inside the `areas` layout (areas one under another with no gaps, a nested list — in a row).
  77. - Canvas: `areaMax` — the cap on an area's and a card's width (720px in the set); an area with `hug: true` — an area as wide as its content, in the middle of its cell. In detail — `patterns/map.md`.
  78. - Canvas and ontology: `layout.stacks` — a list of columns, in each the areas go one under another with no gaps;
  79. `layout.columns` — the column widths (better fixed ones, for example `"250px 250px 520px 270px"`).
  80. `layout.areas` (CSS grid areas) is kept for complex grids, but rows there stretch to the tallest area.
  81. - Nesting: boxes are laid out as "bricks" in columns of 330px, big boxes move to the neighboring column.
  82. - Board: columns of 270px, the board is centered; if there are many columns — sideways scroll.
  83. ### Own layout
  84. `template: custom`, next to it `script: my-view.js` (and if wanted `style: my-view.css`).
  85. The script registers `Lens.templates.custom = function (cfg) { ... }` and builds the page from shared elements:
  86. - `Lens.page(cfg)` → `{main, sidebar, panel, section, settings, left, showBar, layout}`. The frame follows the
  87. [Lens layout convention](../../design-components/pages/design/conventions/layout.md). Lens authors append content to
  88. `main`, add settings with `section` or `settings`, and can add the optional left panel with `left`. `layout` exposes
  89. the mounted frame controller. The build reads `layout:` from `/design/design.md` and bundles its assets.
  90. - `Lens.stats([[label, n], ...])`, `Lens.segmented(options, value, onchange)`, `Lens.edgesPanel(...)` —
  91. blocks for the side panel;
  92. - `Lens.zoom(scroller, target)` — scale for a canvas: the buttons −/+/fit, Ctrl/⌘ + wheel, the keys `+ − 0 f`;
  93. - `Lens.query({from, type, where, sort})`, `Lens.prop(r, key)`, `Lens.targets(id, field)`, `Lens.back(id, field)` — data and links;
  94. - `Lens.card(id, {sub, chips, compact, full, art, ratio, size})` (`full` — the text under the title in full, no truncation; `art` — a record field with a path to a picture from the base root, a large icon to the left of the title and text instead of the glyph; `ratio` — the card's aspect ratio, for example `"3/2"`; `size` — the size `xs`, `s`, `m`, `l` or `auto` by text length, on a canvas such cards lie in a dense grid; `modes` on a canvas — card views with a switch in the side panel; on a canvas `surface: paper` makes the areas white and the cards lightly tinted with a shadow), `Lens.region({...})`, `Lens.chip(text, color)`, `Lens.optionChip(r, key)` — elements;
  95. - `Lens.icon(r)`, `Lens.iconOf(r)`, `Lens.glyph(value, fromId)` — a record's icon with the fallback (own `icon` → the collection's `icons.item` → the collection page's icon → 📄; tier `none` gives none), an emoji as text, an `.svg` path as `<img>` (the package "Page icons");
  96. - `Lens.edges(container, edges, opts)`, `Lens.legend(...)` — arrows between cards (`data-node`);
  97. - `Lens.open(id)` — a record page, as in the Shtukbase app: properties, markdown, links there and back.
  98. Colors are the Notion palette from Shtukbase: `Lens.color(name)`, `Lens.tone(name)` (background, dot, text).
  99. An example is `examples/access-matrix.*` (the matrix "agents × accesses").
  100. ## How a record opens and what is remembered
  101. A click on a card opens its record. The record is drawn compactly:
  102. - the glyph and the title — in one line and once; there is no separate header with the title;
  103. - the buttons (back, expand to the whole window and back, pin, how to open, close) appear at the top right when you hover the record
  104. or enter it with the keyboard; on a screen without a mouse they are always visible;
  105. - under the title the main fields stand in one row: the record type and up to four select fields (the field's label is in the tooltip);
  106. - in the same row two icons, visible on hover over the record: a chevron opens the other fields ("Details"), a chain link
  107. with a number — back links ("Linked here"); they open under the row, the choice is remembered;
  108. - below goes the record text; there are no divider lines;
  109. - in the "Card" mode the window is no taller than its record: height by content, but no more than the remembered one, a long record
  110. scrolls inside.
  111. How to open a record is chosen in the menu on it ("How to open records"):
  112. - **Side** — over the lens on the right; the width is dragged by the left edge, a double click — the usual width.
  113. - **Center** — a window over a dimmed backdrop.
  114. - **Side panel** — next to the lens, does not cover it; the width is dragged the same way as for "Side".
  115. - **Card** — a small window with no dimming, scrolls inside. The first time it stands next to what was
  116. clicked; after that all records (in this and other lenses) open in it, in the same place and of the same size.
  117. It is moved by the header, the size is dragged by the bottom right corner; it closes with the cross, Esc and a click outside.
  118. The icon in the header switches pinning: **to the window** (by default: stays in place, the canvas moves under it, it does not leave
  119. the window's edge) or **to the board** (pinned to the canvas: it moves and scales together with it; in templates without
  120. scaling — board, gallery, nest — it scrolls with the page). On switching it stays where it is visible.
  121. A canvas (`canvas`) moves in any direction: by wheel and trackpad on two axes or by dragging an empty spot; around the diagram
  122. there is a margin. Arrows go over the areas and where possible around the cards, labels — over everything, on a plate.
  123. Counters (`counters`) are in the "Overview" section of the side panel, as in the other templates, not on the canvas.
  124. An area or a card is no wider than `--block-max` (720px), even if the layout stretched it to the full width; an area's
  125. explanation is up to three lines, a click opens it in full.
  126. **Rule: what is remembered and where.** All of a user's view settings the kit stores only through `Lens.prefs`
  127. (`get`/`set`, keys with the prefix `lx-`, the format version in `lx-prefs-version`) in `localStorage`; they survive
  128. a reload and a move to another lens. Shared by all lenses: the theme `lx-theme`, the style (skin) `lx-skin`, the background `lx-bg`, the record mode
  129. `lx-open-mode`, the width `lx-reader-w-side` / `lx-reader-w-panel`, for "Card" the place `lx-card-x`/`-y`, the size
  130. `lx-reader-w-card`/`lx-reader-h-card`, the pinning `lx-card-pin`, the panel's collapsed sections `lx-fold:<section>`,
  131. whether the panel is open `lx-side`. Each lens has its own (the key by file path, `Lens.prefs.lens(name)`): the scale and place of the canvas
  132. `lx-lens:<path>:view`. An address can set settings for one showing without remembering them: `?skin=keer&theme=dark` (shared `theme`, `skin`, `bg`, `side`, `open-mode`), the other parameters are the lens's own settings (`?view=deps` → `Lens.prefs.lens("view")`). `localStorage` is shared by lenses of one origin — a site or files from disk in Chrome and Electron.
  133. Where it is closed or separate for each file (a sandbox without `allow-same-origin`, private mode, `file://` in Firefox),
  134. the settings are duplicated in `window.name`: they pass to the next lens in the same tab or window, but not to a new tab.
  135. ## Auto-update
  136. The hook from `shtukbase-lenses hook` rebuilds the lenses after checkout and merge.
  137. `shtukbase-lenses check` suits CI: it fails if someone committed records without a rebuild.
  138. ## Examples
  139. `examples/base/` — a teaching base (a vegetable garden) with a map lens `map.html`: `patterns/map.md` walks through it, and `npm run check` builds
  140. and checks it (build, freshness, picture style).
  141. `examples/*.lens.md` — lenses of the an earlier product base in the old `lens.md` format: the architecture of agents (canvas),
  142. the ontology (types), surfaces (nesting), capabilities by direction (board), the access matrix (own layout).
  143. The base itself is not in the repository; these are samples of settings, not working lenses.