Skip to content
docsv0.31.1

CodeBlockComponent

A COMMAND, SHOWN AS A TERMINAL SHOWS IT, WITH A WAY TO TAKE IT — the primitive the catalogue lacked. Measured before writing it: `components:catalogue` listed seventeen components and not one of them was for code. So every page that had to show a command wrote its own `<pre>`, and the framework's own welcome page wrote six hand-picked hex values in the process — two of which rendered at 1.07:1 and 1.02:1, invisible (greenhouse decisions/0298, 0299). Rod's words on seeing it: «esa página TAMBIÉN tendría que estar hecha de Milpa Components», and «el área de code se debe parecer MÁS a una terminal […] para el humano tiene que quedar claro visualmente que hablamos de código». Both are the same instruction: the look belongs to a primitive the family owns, not to whichever page needed it first. ── WHAT IT IS AND WHAT IT REFUSES ────────────────────────────────────────────────────────────────── It shows ONE command per line, with a prompt glyph, and offers to copy it. It does no syntax highlighting: a shell line is not a language, and a highlighter is a dependency, a grammar and a palette decision this primitive does not need to be useful. `actions` is empty and that is the design. Copying is a LOCAL act — the clipboard is in the browser, nothing is persisted and no principal is involved — so it needs no round trip and declares no server action. A component that posted to copy would be asking a governed runtime for permission to use the clipboard.

CodeBlockComponent::contract()

public static function contract(): Milpa\Live\ValueObjects\ComponentContract

The contract: the command, what it is called, and whether it can be taken. `prompt` is a prop rather than a constant because a block can be showing a shell line, a SQL statement or a URL, and `$` on a URL is a lie about what the reader is looking at. Its default is the shell's, because that is what a house shows most.

CodeBlockComponent::mount()

public function mount(array $props, Milpa\Live\ValueObjects\ComponentContext $context): Milpa\Live\ValueObjects\StateSnapshot

The lines are the state, so a re-render says what it is showing. A command that arrives empty mounts with zero lines rather than one blank prompt: an empty terminal row reads as «run nothing», which is not what an absent prop means.

Parameters

Parameters of mount()
NameTypeDescription
$propsarray
$contextMilpa\Live\ValueObjects\ComponentContext

CodeBlockComponent::handle()

public function handle(Milpa\Live\ValueObjects\InteractionRequest $request): Milpa\Live\ValueObjects\InteractionResult

Inert: copying happens in the browser, so there is nothing here to handle.

Parameters

Parameters of handle()
NameTypeDescription
$requestMilpa\Live\ValueObjects\InteractionRequest

CodeBlockComponent::lines()

public static function lines(?mixed $command): array

The command split into the lines a terminal would show, with blank ones dropped.

Parameters

Parameters of lines()
NameTypeDescription
$command?mixed