slate-hyperscript

  • Version 0.125.0
  • Published
  • 190 kB
  • No dependencies
  • MIT license

Install

npm i slate-hyperscript
yarn add slate-hyperscript
pnpm add slate-hyperscript

Overview

A hyperscript helper for creating Slate documents.

Index

Functions

function createEditor

createEditor: (
makeEditor: () => Editor
) => (
tagName: string,
attributes: { [key: string]: any },
children: any[]
) => Editor;
  • Create a top-level Editor object.

function createHyperscript

createHyperscript: (options?: {
creators?: HyperscriptCreators;
elements?: HyperscriptShorthands;
}) => <
S extends
| 'anchor'
| 'cursor'
| 'editor'
| 'element'
| 'focus'
| 'fragment'
| 'point'
| 'selection'
| 'text'
>(
tagName: S,
attributes?: Object,
...children: any[]
) => ReturnType<
{
anchor: typeof createAnchor;
cursor: typeof createCursor;
editor: (
tagName: string,
attributes: { [key: string]: any },
children: any[]
) => any;
element: typeof createElement;
focus: typeof createFocus;
fragment: typeof createFragment;
point: typeof createPoint;
selection: typeof createSelection;
text: typeof createText;
}[S]
>;
  • Create a Slate hyperscript function with options.

function createText

createText: (
tagName: string,
attributes: { [key: string]: any },
children: any[]
) => Text;
  • Create a Text object.

function jsx

jsx: <
S extends
| 'anchor'
| 'cursor'
| 'editor'
| 'element'
| 'focus'
| 'fragment'
| 'point'
| 'selection'
| 'text'
>(
tagName: S,
attributes?: Object | undefined,
...children: any[]
) => ReturnType<
{
anchor: typeof import('./creators').createAnchor;
cursor: typeof import('./creators').createCursor;
editor: (
tagName: string,
attributes: { [key: string]: any },
children: any[]
) => any;
element: typeof import('./creators').createElement;
focus: typeof import('./creators').createFocus;
fragment: typeof import('./creators').createFragment;
point: typeof import('./creators').createPoint;
selection: typeof import('./creators').createSelection;
text: typeof createText;
}[S]
>;
  • The default hyperscript factory that ships with Slate, without custom tags.

Classes

class HyperscriptPointRef

class HyperscriptPointRef {}
  • Hyperscript point refs can be used to construct arbitrary points using the ref prop of a tag.

property offset

offset?: number;

    property path

    path?: Path;

      method point

      point: () => Point;

        class HyperscriptRangeRef

        class HyperscriptRangeRef {}
        • Hyperscript range refs can be used to construct arbitrary range using the ref props of and tags.

        property anchor

        anchor?: Point;

          property focus

          focus?: Point;

            method range

            range: () => Range;

              Type Aliases

              type HyperscriptCreators

              type HyperscriptCreators<T = any> = Record<
              string,
              (
              tagName: string,
              attributes: {
              [key: string]: any;
              },
              children: any[]
              ) => T
              >;
              • HyperscriptCreators are dictionaries of HyperscriptCreator functions keyed by tag name.

              type HyperscriptShorthands

              type HyperscriptShorthands = Record<string, Record<string, any>>;
              • HyperscriptShorthands are dictionaries of properties applied to specific kind of object, keyed by tag name. They allow you to easily define custom hyperscript tags for your domain.

              Package Files (4)

              Dependencies (0)

              No dependencies.

              Dev Dependencies (3)

              Peer Dependencies (1)

              Badge

              To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

              You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/slate-hyperscript.

              • Markdown
                [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/slate-hyperscript)
              • HTML
                <a href="https://www.jsdocs.io/package/slate-hyperscript"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>