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

Nested Document Builder

Build a document builder utility that creates richly nested document structures for testing a rich text editor.

Requirements

Your utility should create nested document structures with the following capabilities:

Create multi-level nested document

Build a function createNestedDocument() that returns an editor containing a document with the following structure:

  • A top-level "document" element containing:
    • A "section" element with id "intro" containing:
      • A "paragraph" element with the text "Welcome to the guide"
    • A "section" element with id "content" containing:
      • A "subsection" element with id "main" containing:
        • A "paragraph" element with the text "This is the main content"
        • A "paragraph" element with the text "More details here"

Each element should have a type property matching its name (e.g., type: "document").

  • The function creates a properly nested editor structure @test
  • Each element has the correct type property @test

Create nested document with text selection

Build a function createDocumentWithSelection() that returns an editor with a cursor positioned in the middle of the text "main content" (between "main" and "content") in the deeply nested paragraph.

The structure should be:

  • A "document" element containing:

    • A "section" element containing:
      • A "paragraph" element with text "This is the main content" with a cursor between "main" and "content"
  • The cursor is positioned at the correct offset in nested text @test

Create nested list structure

Build a function createNestedList() that returns an editor containing a nested list:

  • A "list" element with listType="ordered" containing:

    • A "list-item" element with text "First item"
    • A "list-item" element containing both:
      • Text content: "Second item with nested list"
      • A nested "list" element with listType="unordered" containing:
        • A "list-item" element with text "Nested item A"
        • A "list-item" element with text "Nested item B"
    • A "list-item" element with text "Third item"
  • The nested list structure is correctly formed @test

  • List items contain proper nesting of text and sub-lists @test

Implementation

@generates

API

/**
 * Creates a multi-level nested document structure
 */
export function createNestedDocument(): any;

/**
 * Creates a nested document with cursor selection in deep content
 */
export function createDocumentWithSelection(): any;

/**
 * Creates a nested ordered/unordered list structure
 */
export function createNestedList(): any;

Dependencies { .dependencies }

slate-hyperscript { .dependency }

Provides utilities for creating Slate document structures with JSX syntax.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-slate-hyperscript

tile.json