Plate
PlateEditorsTemplates
GitHub16kGitHub
DiscordDiscord
    • Overview
    • Why This Fork
    • Examples
    • Installing Plite
    • Adding Event Handlers
    • Defining Custom Elements
    • Applying Custom Formatting
    • Executing Commands
    • Saving to a Database
    • Canonical Change Substrate
    • Improving Performance
    • Interfaces
    • Nodes
    • Locations
    • Transforms
    • Document Changes
    • Commands
    • Editor
    • Plugins
    • Rendering
    • Serializing
    • Normalizing
    • Using TypeScript
    • Roots
    • Document State
    • Editing Behavior
    • Selection And DOM
    • Clipboard And Paste
    • Decorations, annotations, and widgets
    • Schema
    • Anchor API
    • Location API
    • Path API
    • PointEntry API
    • Point API
    • Range API
    • Selection API
    • Location Types APIs
    • Span API
    • Editor
    • Element API
    • NodeEntry API
    • Node API
    • Node Types APIs
    • Text API
    • Debug Value Scrubbing
    • Transforms API
    • Plite DOM
    • History Editor API
    • History Plugin Setup
    • History
    • Plite History
    • Plite Hyperscript
    • Plite PaginationExperimental
    • Annotations
    • DOM Coverage Boundaries
    • Editable Component
    • External Text Views
    • Plite React Event Handling
    • Virtualized Rendering
    • Plite React Hooks
    • React Editor Setup
    • React Editor
    • Plite React
    • Plite Component
    • Plite Yjs
    • Plite
    • Migration
    • Contributing
    • FAQ
    • Resources

Plite Hyperscript

PreviousNext

Write Plite test fixtures as JSX when nested editor state is clearer as markup.

plitejs/hyperscript creates Plite test fixtures with JSX. Use it when nested editor state is easier to read as markup than as raw JSON.

JSX fixtures

/** @jsxRuntime classic */
/** @jsx jsx */
import { jsx } from "plitejs/hyperscript";
 
const editor = (
  <editor>
    <element type="paragraph">
      alpha
      <cursor />
    </element>
  </editor>
);
/** @jsxRuntime classic */










The built-in tags create normal Plite objects:

  • <editor> creates an editor seeded with document and selection state.
  • <fragment> creates a Descendant[].
  • <element> creates an element with resolved children.
  • <text> creates one text node.
  • <cursor /> creates a collapsed selection point.
  • <anchor /> and <focus /> create an expanded selection.
  • <selection> creates a standalone TextSelection from child anchor/focus tags.

Define domain tags with createHyperscript.

import { createHyperscript } from "plitejs/hyperscript";
 
const h = createHyperscript({
  elements: {
    paragraph: { type: "paragraph" },
  },
});
 
const paragraph = h("paragraph", {}, "hello");
import { createHyperscript } from "plitejs/hyperscript";
 
const h = createHyperscript({
  elements: {




Creator helpers

jsx is the default fixture factory. createHyperscript builds a custom factory. createEditor, createEditorFixture, and createText are low-level creators for custom factories and fixture helpers. HyperscriptCreators and HyperscriptShorthands are TypeScript helper types for custom factories.

Keep hyperscript in tests and fixtures. Runtime editor code should use normal Plite node values.

Plite HistoryPlite Pagination

On This Page

JSX fixturesCreator helpers
Build your editor
Production-ready AI template and reusable components.
Get all-access
/** @jsx jsx */
import { jsx } from "plitejs/hyperscript";
const editor = (
<editor>
<element type="paragraph">
alpha
<cursor />
</element>
</editor>
);
paragraph: { type: "paragraph" },
},
});
const paragraph = h("paragraph", {}, "hello");