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-6/

Slate Editor Test Fixture Builder

Build a utility that creates Slate editor test fixtures with selections at specific positions in nested document structures.

Requirements

Implement a function createEditorWithSelection(config) that builds Slate editor instances for testing purposes.

Input Configuration

The function accepts a configuration object with:

  • structure: A string identifier for the document structure type ('simple', 'nested', 'deep')
  • selectionType: Type of selection ('cursor', 'range')
  • position: Where to place the selection ('start', 'middle', 'end', 'cross-element')

Supported Document Structures

  1. Simple: Single paragraph with text
  2. Nested: Document containing sections with paragraphs (2 levels deep)
  3. Deep: Document with sections containing subsections with paragraphs (3+ levels deep)

Selection Types

  1. Cursor: Collapsed selection at a single point
  2. Range: Selection spanning from anchor to focus point

Position Options

  • start: Beginning of text in a nested element
  • middle: Middle of text content
  • end: End of text content
  • cross-element: Selection spanning multiple elements at different nesting levels

Return Value

Return an object with:

  • editor: The Slate editor instance with the document and selection
  • selection: The selection object (for verification)

Test Cases

Implement tests that verify:

  • It creates a cursor at the start of text in a deeply nested paragraph @test
  • It creates a cursor in the middle of text within nested elements @test
  • It creates a range selection spanning across sibling elements @test
  • It creates a range selection across different nesting levels @test

@generates

API

/**
 * Creates a Slate editor with a document and selection for testing.
 *
 * @param {Object} config - Configuration for the editor fixture
 * @param {string} config.structure - Document structure: 'simple', 'nested', or 'deep'
 * @param {string} config.selectionType - Selection type: 'cursor' or 'range'
 * @param {string} config.position - Selection position: 'start', 'middle', 'end', or 'cross-element'
 * @returns {Object} Object with editor and selection properties
 */
function createEditorWithSelection(config) {
  // Implementation here
}

module.exports = {
  createEditorWithSelection
};

Dependencies { .dependencies }

slate-hyperscript { .dependency }

Provides JSX-like syntax for creating Slate documents with embedded selections.

Install with Tessl CLI

npx tessl i tessl/npm-slate-hyperscript

tile.json