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

Test Fixture Builder

Build a function that creates Slate editor test fixtures using JSX syntax, with correct text node merging behavior.

Overview

Create a JSX factory function that generates Slate editor structures. The function must correctly handle how adjacent text content merges: plain strings should combine when adjacent, but explicitly tagged text nodes must remain separate.

Requirements

The JSX factory function should:

  • Accept a tag name, attributes object, and child elements
  • Convert plain strings into text nodes with a text property
  • Merge adjacent plain strings into a single text node
  • Keep explicitly tagged <text> elements separate (never merge them)
  • Support creating editor and element structures with children arrays

Test Cases

  • Three adjacent plain strings "one", "two", "three" merge into a single text node with text: "onetwothree" @test
  • Two explicit text tags <text>foo</text><text>bar</text> remain as two separate text nodes @test
  • Mixed content: plain string "a" + <text>b</text> + plain string "c" creates three separate text nodes @test

Implementation

@generates

API

/**
 * Creates a Slate editor structure from JSX elements.
 * Handles text node merging according to Slate's conventions.
 *
 * @param {string} tagName - The JSX tag name (e.g., 'editor', 'element', 'text')
 * @param {Object} attributes - Properties to apply to the created node
 * @param {Array} children - Child nodes or strings
 * @returns {Object} A valid Slate data structure
 */
function jsx(tagName, attributes, ...children) {
  // Implementation here
}

module.exports = { jsx };

Dependencies { .dependencies }

slate-hyperscript { .dependency }

Provides JSX-based document creation with automatic text node merging.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-slate-hyperscript

tile.json