CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-slate-hyperscript

A hyperscript helper for creating Slate documents with JSX-like syntax.

90

1.15x
Overview
Eval results
Files

task.mdevals/scenario-2/

Editor State Builder

Create a utility that constructs Slate editor states for testing purposes. The utility should build editor instances with content and selections using a declarative approach.

Requirements

Your utility should create editor states with:

  1. Basic document structure with text content in elements
  2. Cursor positions at specific offsets within text
  3. Range selections spanning from an anchor point to a focus point
  4. Text formatting such as bold or italic marks

Implementation

@generates

Test Cases

  • Given text "hello world", returns an editor with one element containing that text @test
  • Given text "hello world" with cursor at offset 5, returns an editor with a collapsed selection at position 5 @test
  • Given text "hello world" with anchor at offset 0 and focus at offset 5, returns an editor with a range selection @test
  • Given text "hello" with bold formatting, returns an editor with a text node having the bold property set to true @test

API

/**
 * Creates a Slate editor instance with the specified content and selection
 *
 * @param {Object} config - Configuration for the editor state
 * @param {string} config.text - Text content for the editor
 * @param {number} [config.cursorOffset] - Optional cursor position (collapsed selection)
 * @param {Object} [config.range] - Optional range selection with {anchor: number, focus: number} offsets
 * @param {Object} [config.marks] - Optional formatting marks like {bold: true, italic: true}
 * @returns {Object} Slate editor instance
 */
function buildEditorState(config) {
  // IMPLEMENTATION HERE
}

module.exports = { buildEditorState };

Dependencies { .dependencies }

slate-hyperscript { .dependency }

Provides hyperscript helper for creating Slate documents with JSX-like syntax

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-slate-hyperscript

tile.json