# Long content

A long block in a document is cut at one height, fading out above a Show all bar: code shows the rest in place, a patch or an embedded file opens in the viewer.

API [ContentFrame](/ui/storybook/?path=/docs/ui-content-contentframe--docs) [ContentTitleBar](/ui/storybook/?path=/docs/ui-content-contenttitlebar--docs) [DocumentCard](/ui/storybook/?path=/docs/ui-content-documentcard--docs) [AttachmentViewerProvider](/ui/storybook/?path=/docs/ui-content-attachmentviewerprovider--docs) [FenceFrame](/ui/storybook/?path=/docs/ui-code-fenceframe--docs) [PatchView](/ui/storybook/?path=/docs/ui-code-patchview--docs) [JsonView](/ui/storybook/?path=/docs/ui-json-jsonview--docs) [Markdown](/ui/storybook/?path=/docs/ui-markdown-markdown--docs)

**Cut every long block in a document the same way: at one height, fading out, with a Show all bar across its foot. A reader who has learnt it on one block reads them all, and nothing scrolls inside the page they are scrolling.**

```tsx
import pageText from "@orz/fixtures/attachment/demo.html?raw";
import { hydratedResolver, textFile } from "@orz/fixtures/files.ts";
import { SERIES_EML } from "@orz/fixtures/mail.ts";
import seriesText from "@orz/fixtures/patch/series.patch?raw";
import { ATTACHMENT_RENDERERS } from "@orz/fixtures/renderers.ts";
import { ContentRenderers } from "@orz/ui-content";
import { AttachmentViewerProvider } from "@orz/ui-content/attachment";
import { Markdown, markdownEmbeds } from "@orz/ui-markdown";

const STEPS = Array.from(
  { length: 36 },
  (_, i) => `  - run: pnpm --filter step-${i + 1} test`,
).join("\n");

const CHECKS = [
  "The tag points at the commit the release notes name.",
  "Every package's version matches the tag.",
  "The snapshot from the same commit installed cleanly.",
  "The changelog lists every card shipped since the last tag.",
  "The docs site built from the same commit.",
  "Nobody has a deploy running.",
];

const RUNBOOK = `# Release runbook

## Before the tag

${CHECKS.map((check) => `- ${check}`).join("\n")}

## Tagging

Set the version on every package in one commit, merge it as any other, then push a tag named
after the version to the public mirror. The workflow refuses a tag that does not match.

## After the tag

${CHECKS.map((check) => `- ${check.replace(/\.$/, "")}, again.`).join("\n")}

## When it goes wrong

A failed publish leaves the tag in place. Fix the cause on master, set the next patch version,
and tag again; never move a tag that has been pushed.
`;

const PLUGINS = [
  markdownEmbeds(
    hydratedResolver({
      "runbook.md": textFile("runbook.md", "text/markdown", RUNBOOK),
      "demo.html": textFile("demo.html", "text/html", pageText),
      "cover-letter.eml": textFile(
        "cover-letter.eml",
        "message/rfc822",
        SERIES_EML,
      ),
    }),
  ),
];

const DOC = `The pipeline now runs every step's tests:

\`\`\`yaml ci.yaml
steps:
${STEPS}
\`\`\`

The series that changed the fetch task:

\`\`\`patch
${seriesText.trimEnd()}
\`\`\`

And the runbook the release follows:

![runbook](runbook.md)

An HTML attachment, which runs in its sandbox:

![demo](demo.html)

The cover letter the series was sent with:

![cover letter](cover-letter.eml)
`;

export function LongBlocks() {
  return (
    <ContentRenderers renderers={ATTACHMENT_RENDERERS}>
      <AttachmentViewerProvider>
        <Markdown plugins={PLUGINS}>{DOC}</Markdown>
      </AttachmentViewerProvider>
    </ContentRenderers>
  );
}
```

A note with a long pipeline, a patch series, an embedded runbook, a page and a cover letter. Each is cut at the same height. **Show all** under the pipeline names its lines and draws the rest of them in place, and **Show less** cuts it again without moving the bar. **Show all in the viewer** under the patch, the runbook and the letter opens them in the attachment viewer, as ⤢ in their headers does; the page behind keeps them cut. The page stands at the cut's height and scrolls in its frame, with no bar.

## When a block is cut

- A code block past 30 lines is cut from the first frame, so a page rendered on the server does not jump. Its bar names how many lines it has.
- Any other block is measured: a patch, an embedded file, a block of your own. It is cut only when it is clearly taller than the cut, since a bar that shows a few lines more costs about what they do. It is measured again as it grows (an image arriving, a file unfolding) and as the window changes.
- A short block has no bar. ⤢ in its header stays the way into the viewer, and so does the name of a file with an address of its own.

## Views that keep their own height

A block the reader works in rather than reads down holds one height and scrolls inside it, so nothing the reader does in it cuts the card under them. It has no bar; ⤢ opens it in the viewer.

- **A page** (an embedded HTML file) stands at the cut's height, its width the card's, and scrolls in its frame. It loads once it is scrolled near.
- **A tree** (a JSON, YAML or TOML file shown as a tree) grows with its rows up to the cut's height, then scrolls in its box. Folding a node open never cuts the card, and search and Expand all scroll the box to what they find.

A message reads top to bottom, as a document does, so it is cut as one: measured, and opened in the viewer from its bar. Its HTML body is as tall as its page.

## Where Show all goes

The bar's icon and words say where the rest goes, by what the block is rather than by whether its header has a ⤢.

- **In place**, for text written into the document: a code block, a diagram's source, a log. The reader is reading it, and a dialog for the next few lines is a detour. The bar reads **Show all** with the block's line count when it shows its text line for line, and its chevron points down. **Show less** keeps the bar where it was on the screen and scrolls the page up to it.
- **In the viewer**, for a patch or an embedded file: what they hold reads better at the viewer's size, with its file list and paging. The bar reads **Show all in the viewer**, with the ⤢ of the header's **Open in the viewer**. Give `ContentCollapse` an `onOpen` (a card's `onExpand`, a `FenceFrame`'s `openOnCut`) that opens the viewer. A command that takes the reader to something past the cut, such as a patch's files menu, lifts the cut in place all the same.
- Where there is no viewer to open (no `AttachmentViewerProvider`, a file the viewer cannot draw), or the block is already inside the viewer, the bar shows the rest in place. A reader can always reach the end of a block.

## What stays in the page

What is past the cut stays in the document, so find in page reaches it. When find in page, Tab or a link lands on something past the cut of a block that expands in place, the block opens and keeps that thing where it was on the screen. A patch or a code file drawn in a card shows only its first screen until it is opened: the rest is laid out when the reader asks for it.

## Turning it off

`collapseLongFences={false}` on `Markdown` leaves its code blocks whole and its patches in a scroller of their own, for a review whose comments point at lines a cut would hide. A document embedded in another follows its host. Embedded files are cut whatever it says: their length is the file's, not the author's.

## Blocks inside blocks

Each block is cut on its own. A card cut above a long code block hides that block's bar too; the viewer shows the card whole, bar and all. A card shown in place opens itself, not the blocks inside it.

## A block's header

A block's header is a toolbar named by the block's name, and the name comes first: it keeps its first 20 characters, all of a shorter one, while the commands give way by the rules of [toolbars](/ui/guidelines/patterns/toolbars/index.md). The header is as tall in every form.

Every block draws its commands from one set of parts, in one order out from the name:

1. The marker, the name, then its meta: a size, a log's line count, a one-file patch's counts.
2. The view's own commands: a search, a patch's files menu, a mode, Wrap lines.
3. **Source**, held down while the text as written shows, on every file drawn as something other than its text. The view's commands stand left of it and come and go with the view, so switching views never moves what is under the pointer.
4. The app's own commands, such as a card's version chips.
5. **Download**, for a block that is or names a file.
6. **Open in the viewer** (⤢), on a block the viewer draws bigger or better than the page.
7. **Copy**, always last, the text as written in either view.

With a pointer their words hide first, then they go into a `⋯`: Download and ⤢ before the view's commands, then **Source**, and Copy last of all, being what a block is most often used for. Source outlasts the rest of them: it is the way to the text Copy copies.

⤢, the bar and the name open the viewer on what the block shows: a card showing a diagram's source opens the viewer on the source, and one showing the drawing, on the drawing. Every opening starts over from there, and so does every page in the viewer; nothing carries from one file to the next.

The name names and the commands act. A file with an address of its own has a name that is a link to it: a plain click opens the viewer and a modified or middle click follows the link, as a row in a file list does. Any other name is plain text, with its whole value in a tooltip. A name never downloads; **Download** is its own command.

The viewer's title bar is the same header one step out, at the next size: the same marker, name and order, with **Open in new tab** where ⤢ stands, since the reader is in the viewer already, then a rule and the viewer's own paging, **Maximize** and **Close**. Its footer only reports: the file's type and size, or an inline block's tag, and what the view says about what is shown.

A renderer drawn in a card or the viewer puts its controls in the title bar it is lent: it asks `useContentTitleBar` for the slot and fills it with `ContentTitleBarControls`. There they are the header's own commands, giving way and taking the arrow keys as the card's do. They are drawn in the header, so they read what is around the header, not what is around the renderer: hand them what they need.

Lent a bar, a view draws no frame and no bar of its own: the card or the viewer is its frame, and names it and offers its download already, so the view draws neither again. Its commands and its search go into the bar, and the text it copies goes to the bar's one Copy through `ContentTitleBarCopy`, so a bar never shows two. A count of what it holds, a log's lines, goes after the card's name through `ContentTitleBarMeta`. What belongs to the content itself and is read at a glance stays on the view, a band of its own under the bar: a log's level chips, with its line count at their end. The viewer lends its footer too, for what the view reports about what is shown: a renderer asks `useContentStatusBar` for that slot, and a log's line count and a hex dump's selection follow the file's type and size there.

The header is one Tab stop. Tab lands on the name when it is a link that opens the block, and the arrow keys walk the commands and the `⋯`, so a page of blocks costs a Tab each.

## A block of your own

Build it from the same parts, so it is cut as every other block is: `ContentFrame` for the edge, `ContentHeader` for the name and controls, and `ContentCollapse` around the header and a `ContentCollapseBody`. The commands every block shares are parts of their own, `ContentSourceToggle`, `ContentDownload`, `ContentOpen` and `ContentCopy`, each with its icon, words and place in the order fixed; the view's own are toolbar parts themselves (`ToolbarButton`, `ToolbarItem`). A name that links to the file is a `ContentName`, which the arrow keys reach. A view that lays out only what is on screen reads `useContentCollapse` to size its box. A renderer drawing into a card that fills it edge to edge marks its root `data-content-flush`, and the card drops its padding around it; the viewer, too, takes such a view out to its sides and up to its title bar. A strip of the view's own lines up with the surface's bar by `--content-inset`, which the viewer sets and a card leaves to the view's own default.

## On each platform

### Desktop & pointer

- The header and the bar are each a row tall, and the bar is one target across the block's whole width.

### Touch

- The header and the bar grow to a finger's height. Nothing about the cut needs hover: the fade and the bar are always there.
- A name that opens the viewer takes a tap across the header's height, and is drawn as it is with a pointer.
- A header's commands keep their words; what does not fit goes into its `⋯` whole.

### Print

- A printed page has no bar to press: blocks print whole, and a patch or a code file drawn in a card prints the screen it shows.

## In the demos

- [Notes](/ui/demos/notes/index.md): Open Retry design and scroll to its end: the series embedded there is cut, and Show all in the viewer under it opens the patch there, as its header's ⤢ does.
