Searching Puzzle Pieces

Type to search Puzzle Pieces.

Code

A complete code panel in one piece: syntax highlighting on a GitHub light/dark palette, an optional line-number gutter, a corner copy button, and a collapsible View Code preview that animates open. Hand it a snippet string and it takes care of the rest — this docs site renders every example through it.

export function debounce(fn, wait = 150) {
  let timer = null;
  return (...args) => {
    clearTimeout(timer);
    timer = setTimeout(() => fn(...args), wait);
  };
}

Installation

Copy the piece and its highlighting lib, then install highlight.js:

puzzle add piece code
npm install highlight.js@^11.11.1

The highlighter registers only the javascript, xml, css, json, ini, bash, and puzzle grammars — add more in app/lib/highlight.js if your snippets need them. The token colors travel inside Code.pzl in a global <style> block, so there is nothing to merge into pieces.css — retheme the palette by editing the --hl- variables at the bottom of the file.

Usage

import Code from '@/components/ui/Code.pzl';
<Code code={ snippet }/>

Command block

npm install @magic-spells/morph-engine
npm run build

Collapsible

Language detection

The grammar is guessed from the snippet's shape — install-style commands go to bash, snippets with markup or template syntax go to puzzle, and everything else goes to javascript. Pass lang to override the guess.

cp registry/ui/button/Button.pzl app/components/ui/
<Select options={ opts } value={ pet } @change={ setPet } />