UNPKG

@yoopta/editor

Version:

<h2 align="center">Yoopta-Editor v1 🎉</h2> <p align="center">Yoopta-Editor - is an open source notion-like editor 💥</p> <div align="center"> <img width="574" alt="Screen Shot 2023-01-25 at 16 04 29" src="https://user-images.githubusercontent.com/2909311

150 lines • 4.4 kB
import type { Descendant } from 'slate'; import type { SlateElement, SlateElementTextNode, YooEditor } from '../types'; export type ElementStructureOptions = { id?: string; props?: Record<string, unknown>; children?: Descendant[]; }; export type TextNodeOptions = { bold?: boolean; italic?: boolean; underline?: boolean; code?: boolean; strike?: boolean; highlight?: { color?: string; backgroundColor?: string; }; }; /** * Creates a text node with optional marks (bold, italic, etc.) * * @param text - Text content * @param marks - Optional marks (bold, italic, underline, code, strike, highlight) * * @example * ```typescript * // Plain text * editor.y.text('Hello world') * * // Text with marks * editor.y.text('Bold text', { bold: true }) * editor.y.text('Italic text', { italic: true }) * editor.y.text('Bold and italic', { bold: true, italic: true }) * ``` */ export declare function yText(text: string, marks?: TextNodeOptions): SlateElementTextNode; /** * Creates an inline element (e.g., link, mention) * Inline elements are embedded within text and can contain text nodes * * @param editor - YooEditor instance * @param type - Inline element type (e.g., 'link', 'mention') * @param options - Optional props and children (text nodes) * * @example * ```typescript * // Simple link * editor.y.inline('link', { * props: { url: 'https://example.com', target: '_blank' }, * children: [editor.y.text('Click me')] * }) * * // Link with formatted text * editor.y.inline('link', { * props: { url: 'https://example.com' }, * children: [ * editor.y.text('Bold ', { bold: true }), * editor.y.text('link') * ] * }) * * // Inline element in paragraph * editor.y('paragraph', { * children: [ * editor.y.text('Visit '), * editor.y.inline('link', { * props: { url: 'https://example.com' }, * children: [editor.y.text('example.com')] * }), * editor.y.text(' for more info') * ] * }) * ``` */ export declare function yInline(editor: YooEditor, type: string, options?: ElementStructureOptions): SlateElement; /** * Creates a SlateElement structure for use in insertBlock or other operations * * @param editor - YooEditor instance * @param type - Element type (e.g., 'accordion-list', 'paragraph', etc.) * @param options - Optional props and children * * @example * ```typescript * // Simple element * editor.y('paragraph') * * // Element with custom props * editor.y('accordion-list-item', { props: { isExpanded: false } }) * * // Nested structure * editor.y('accordion-list', { * children: [ * editor.y('accordion-list-item', { * props: { isExpanded: false }, * children: [ * editor.y('accordion-list-item-heading'), * editor.y('accordion-list-item-content') * ] * }) * ] * }) * * // Element with text and marks * editor.y('paragraph', { * children: [ * editor.y.text('Hello '), * editor.y.text('world', { bold: true }), * editor.y.text('!', { italic: true }) * ] * }) * * // Mixed: elements and text * editor.y('step-list-item-content', { * children: [ * editor.y.text('Step 1: '), * editor.y('callout', { props: { theme: 'info' } }), * editor.y.text(' - completed', { strike: true }) * ] * }) * ``` */ export declare function y(editor: YooEditor, type: string, options?: ElementStructureOptions): SlateElement; /** * Creates a JSX-compatible function bound to the editor * Use this for JSX pragma * * @example * ```typescript * import { createJSXFactory } from '@yoopta/editor'; * * const y = createJSXFactory(editor); * * // Now you can use JSX: * // @jsx y * const structure = ( * <accordion-list> * <accordion-list-item props={{ isExpanded: false }}> * <accordion-list-item-heading /> * </accordion-list-item> * </accordion-list> * ); * * editor.insertBlock('Accordion', { * blockData: { value: [structure] } * }); * ``` */ export declare function createJSXFactory(editor: YooEditor): (type: string, props: Record<string, unknown> | null, ...children: unknown[]) => SlateElement; //# sourceMappingURL=create-element-structure.d.ts.map