CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-udecode--plate-list

List plugin for Plate rich-text editor providing indent-based list functionality with comprehensive transforms, queries, and React hooks.

Pending
Overview
Eval results
Files

transforms.mddocs/

List Transforms

Transform operations for manipulating list formatting, indentation, and structure. These functions modify the editor state to create, modify, or remove list formatting.

Capabilities

toggleList

Toggles list formatting on selected blocks. This is the primary function for adding or removing list formatting.

/**
 * Toggles list formatting on selected blocks
 * @param editor - The Slate editor instance
 * @param options - Options for list configuration
 * @param getSiblingListOptions - Options for sibling list queries
 */
function toggleList<N extends ElementOf<E>, E extends SlateEditor = SlateEditor>(
  editor: E,
  options: ListOptions,
  getSiblingListOptions?: GetSiblingListOptions<N, E>
): void;

Usage Example:

import { toggleList, ListStyleType } from "@udecode/plate-list";

// Toggle bullet list
toggleList(editor, {
  listStyleType: ListStyleType.Disc,
});

// Toggle numbered list
toggleList(editor, {
  listStyleType: ListStyleType.Decimal,
});

// Toggle list with custom restart number
toggleList(editor, {
  listStyleType: ListStyleType.Decimal,
  listRestart: 5, // Start numbering from 5
});

indentList

Increases the indentation of selected blocks, creating nested list structure.

/**
 * Increases the indentation of selected blocks
 * @param editor - The Slate editor instance
 * @param options - Options for list configuration
 */
function indentList(
  editor: SlateEditor, 
  options?: { listStyleType?: ListStyleType | string } & ListOptions
): void;

Usage Example:

import { indentList, ListStyleType } from "@udecode/plate-list";

// Simple indentation
indentList(editor);

// Indent with specific list style
indentList(editor, {
  listStyleType: ListStyleType.Circle,
});

outdentList

Decreases the indentation of selected blocks, reducing nesting level.

/**
 * Decreases the indentation of selected blocks
 * @param editor - The Slate editor instance
 * @param options - Options for list configuration
 */
function outdentList(editor: SlateEditor, options: ListOptions = {}): void;

Usage Example:

import { outdentList } from "@udecode/plate-list";

// Simple outdentation
outdentList(editor);

// Outdent with options
outdentList(editor, {
  at: specificPath, // Target specific location
});

indentTodo

Increases indentation and converts to todo list format.

/**
 * Increases indentation and converts to todo list
 * @param editor - The Slate editor instance
 * @param options - Options for list configuration
 */
function indentTodo(
  editor: SlateEditor, 
  options: ListOptions = {}
): void;

Usage Example:

import { indentTodo } from "@udecode/plate-list";

// Convert to todo list with indentation
indentTodo(editor);

setListNode

Sets a single node as a list item with specified properties.

/**
 * Sets a single node as a list item
 * @param editor - The Slate editor instance
 * @param options - Options including path, indent, and list style type
 */
function setListNode(
  editor: Editor,
  options: {
    at: Path;
    indent?: number;
    listStyleType?: string;
  }
): void;

setIndentTodoNode

Sets a single node as a todo list item with checkbox functionality.

/**
 * Sets a single node as a todo list item with checkbox functionality
 * @param editor - The Slate editor instance
 * @param options - Options including path, indent, and list style type
 */
function setIndentTodoNode(
  editor: Editor,
  options: {
    at: Path;
    indent?: number;
    listStyleType?: string;
  }
): void;

Usage Example:

import { setIndentTodoNode } from "@udecode/plate-list";

// Convert specific node to todo list item
setIndentTodoNode(editor, {
  at: [0, 1], // Path to target node
  indent: 2,
  listStyleType: 'todo'
});

setListNodes

Sets multiple nodes as list items with the same formatting.

/**
 * Sets multiple nodes as list items
 * @param editor - The Slate editor instance
 * @param entries - Array of node entries to convert
 * @param options - Options including list style type
 */
function setListNodes(
  editor: Editor,
  entries: NodeEntry[],
  options: { listStyleType?: string }
): void;

Usage Example:

import { setListNodes, ListStyleType } from "@udecode/plate-list";

// Get selected nodes
const entries = Array.from(Editor.nodes(editor, {
  match: n => Element.isElement(n) && !n.listStyleType
}));

// Convert all to bullet lists
setListNodes(editor, entries, {
  listStyleType: ListStyleType.Disc
});

setListSiblingNodes

Sets list properties on an entry and its siblings based on sibling list options.

/**
 * Sets list properties on entry and its siblings
 * @param editor - The Slate editor instance
 * @param entry - The reference entry
 * @param options - Options for sibling detection and list style type
 */
function setListSiblingNodes<N extends ElementOf<E>, E extends Editor = Editor>(
  editor: E,
  entry: ElementEntryOf<E>,
  options: {
    getSiblingListOptions?: GetSiblingListOptions<N, E>;
    listStyleType?: string;
  }
): void;

toggleListByPath

Toggles list formatting at a specific path in the document.

/**
 * Toggles list formatting at a specific path
 * @param editor - The Slate editor instance
 * @param entry - The node entry to toggle
 * @param listStyleType - The list style type to apply
 */
function toggleListByPath(
  editor: SlateEditor,
  entry: NodeEntry,
  listStyleType: string
): void;

toggleListByPathUnSet

Removes list formatting at a specific path.

/**
 * Removes list formatting at a specific path
 * @param editor - The Slate editor instance
 * @param entry - The node entry to unformat
 */
function toggleListByPathUnSet(
  editor: SlateEditor,
  entry: NodeEntry
): void;

toggleListSet

Sets list formatting if not already set, used internally by toggle operations.

/**
 * Sets list formatting if not already set
 * @param editor - The Slate editor instance
 * @param entry - The node entry to format
 * @param options - Options for list configuration
 * @returns Boolean indicating if formatting was applied, undefined if no change
 */
function toggleListSet(
  editor: Editor,
  entry: NodeEntry,
  options: ListOptions
): boolean | undefined;

toggleListUnset

Removes list formatting if already set, used internally by toggle operations.

/**
 * Removes list formatting if already set
 * @param editor - The Slate editor instance
 * @param entry - The node entry to unformat
 * @param options - Options including list style type
 * @returns Boolean indicating if formatting was removed, undefined if no change
 */
function toggleListUnset(
  editor: Editor,
  entry: NodeEntry,
  options: { listStyleType?: string }
): boolean | undefined;

Transform Options

ListOptions

Comprehensive options for list transformation operations.

/**
 * Options for list transformation operations
 */
interface ListOptions {
  /** Specific location to apply transform (defaults to selection) */
  at?: TLocation;
  /** Restart list numbering from this value */
  listRestart?: number;
  /** Politely restart list numbering (only at list start) */
  listRestartPolite?: number;
  /** List style type to apply */
  listStyleType?: ListStyleType | string;
}

Common Transform Patterns

Basic List Operations

import { toggleList, indentList, outdentList, ListStyleType } from "@udecode/plate-list";

// Create bullet list
toggleList(editor, { listStyleType: ListStyleType.Disc });

// Create numbered list
toggleList(editor, { listStyleType: ListStyleType.Decimal });

// Increase indentation
indentList(editor);

// Decrease indentation
outdentList(editor);

Advanced List Manipulation

import { 
  toggleList, 
  setListNodes, 
  setListSiblingNodes,
  ListStyleType 
} from "@udecode/plate-list";

// Apply consistent formatting to multiple nodes
const entries = Array.from(Editor.nodes(editor, {
  match: n => Element.isElement(n)
}));

setListNodes(editor, entries, {
  listStyleType: ListStyleType.Decimal
});

// Restart numbering at 10
toggleList(editor, {
  listStyleType: ListStyleType.Decimal,
  listRestart: 10
});

Todo List Operations

import { indentTodo, toggleList, ListStyleType } from "@udecode/plate-list";

// Convert to todo list
indentTodo(editor);

// Or use toggleList for todo formatting
toggleList(editor, {
  listStyleType: ListStyleType.Disc, // Style for todo items
});

Working with List Hierarchies

import { 
  indentList, 
  outdentList, 
  getSiblingListStyleType,
  getListAbove 
} from "@udecode/plate-list";

// Smart indentation that matches sibling style
const currentList = getListAbove(editor);
if (currentList) {
  const siblingStyle = getSiblingListStyleType(editor, {
    entry: currentList,
    indent: 2, // Target indent level
    previous: true
  });
  
  indentList(editor, {
    listStyleType: siblingStyle
  });
}

List Restart Features

Immediate Restart

Forces list numbering to restart immediately:

toggleList(editor, {
  listStyleType: ListStyleType.Decimal,
  listRestart: 1 // Force restart at 1
});

Polite Restart

Only restarts numbering if at the beginning of a list sequence:

toggleList(editor, {
  listStyleType: ListStyleType.Decimal,
  listRestartPolite: 1 // Only restart if at list start
});

Install with Tessl CLI

npx tessl i tessl/npm-udecode--plate-list

docs

index.md

normalizers.md

plugins.md

queries.md

react-hooks.md

transforms.md

types.md

tile.json