A hyperscript helper for creating Slate documents with JSX-like syntax.
90
Build a utility that creates Slate editor test fixtures with selections at specific positions in nested document structures.
Implement a function createEditorWithSelection(config) that builds Slate editor instances for testing purposes.
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')start: Beginning of text in a nested elementmiddle: Middle of text contentend: End of text contentcross-element: Selection spanning multiple elements at different nesting levelsReturn an object with:
editor: The Slate editor instance with the document and selectionselection: The selection object (for verification)Implement tests that verify:
@generates
/**
* 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
};Provides JSX-like syntax for creating Slate documents with embedded selections.
Install with Tessl CLI
npx tessl i tessl/npm-slate-hyperscriptdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10