Hooks and components for consuming remirror with your fave framework React.
Overall
score
36%
Evaluation — 36%
↑ 1.09xAgent success when using this tile
React-specific table functionality with interactive components for creating and editing tables within the editor.
Core extensions for table functionality with React-based node views.
/**
* Main table extension with React node views and interactive features
*/
class TableExtension extends NodeExtension<TableOptions> {
/** Extension name */
static readonly name = 'table';
/** Create table commands */
createCommands(): TableCommands;
/** Create table node views with React components */
createNodeViews(): NodeViewMethod;
/** Create table-specific plugins */
createPlugins(): ProsemirrorPlugin[];
}
interface TableOptions {
/** Whether tables are resizable */
resizable?: boolean;
/** Default number of rows */
defaultRows?: number;
/** Default number of columns */
defaultColumns?: number;
/** Whether to show table controls */
showControls?: boolean;
/** Custom cell types */
cellTypes?: string[];
}
/**
* Extension for table cell nodes
*/
class TableCellExtension extends NodeExtension<TableCellOptions> {
static readonly name = 'tableCell';
}
interface TableCellOptions {
/** Whether cells can span multiple columns */
allowColumnSpan?: boolean;
/** Whether cells can span multiple rows */
allowRowSpan?: boolean;
/** Default cell content */
defaultContent?: string;
}
/**
* Extension for table header cell nodes
*/
class TableHeaderCellExtension extends NodeExtension<TableHeaderCellOptions> {
static readonly name = 'tableHeaderCell';
}
interface TableHeaderCellOptions extends TableCellOptions {
/** Header cell styling */
headerStyle?: 'bold' | 'background' | 'both';
}
/**
* Extension for table row nodes
*/
class TableRowExtension extends NodeExtension<TableRowOptions> {
static readonly name = 'tableRow';
}
interface TableRowOptions {
/** Whether rows can be reordered */
allowReorder?: boolean;
/** Minimum number of cells per row */
minCells?: number;
}
/**
* Extension for table controller cells (for row/column operations)
*/
class TableControllerCellExtension extends NodeExtension<TableControllerOptions> {
static readonly name = 'tableControllerCell';
}
interface TableControllerOptions {
/** Controller cell position */
position?: 'top-left' | 'top' | 'left';
/** Whether to show controller */
showController?: boolean;
}Usage Example:
import React from 'react';
import {
useRemirror,
Remirror,
TableExtension,
TableCellExtension,
TableHeaderCellExtension,
TableRowExtension,
CreateTableButton
} from '@remirror/react';
function EditorWithTables() {
const { manager, state } = useRemirror({
extensions: () => [
new TableExtension({
resizable: true,
defaultRows: 3,
defaultColumns: 3,
showControls: true,
}),
new TableCellExtension(),
new TableHeaderCellExtension(),
new TableRowExtension(),
],
});
return (
<div>
<div>
<CreateTableButton />
</div>
<Remirror manager={manager} initialContent={state} />
</div>
);
}React components for table interaction and management.
/**
* Main wrapper component for all table UI elements
*/
interface TableComponents extends React.Component<TableComponentsProps> {}
interface TableComponentsProps {
/** Whether to show table controls */
showControls?: boolean;
/** Custom control components */
controlComponents?: {
deleteRow?: ComponentType;
deleteColumn?: ComponentType;
addRow?: ComponentType;
addColumn?: ComponentType;
};
}
/**
* Interactive menu for table cells with editing options
*/
interface TableCellMenu extends React.Component<TableCellMenuProps> {}
interface TableCellMenuProps {
/** Cell position */
position?: { row: number; col: number };
/** Available menu actions */
actions?: TableCellAction[];
/** Custom menu items */
customItems?: React.ReactNode;
/** Menu visibility */
visible?: boolean;
/** Callback when menu item is selected */
onSelect?: (action: TableCellAction) => void;
}
interface TableCellAction {
/** Action identifier */
id: string;
/** Display label */
label: string;
/** Action icon */
icon?: React.ReactNode;
/** Action handler */
handler: () => void;
/** Whether action is disabled */
disabled?: boolean;
}
/**
* Props for table cell menu components
*/
interface TableCellMenuComponentProps {
/** Current cell element */
cell: HTMLElement;
/** Cell coordinates */
coordinates: { row: number; col: number };
/** Available actions */
actions: TableCellAction[];
/** Close menu callback */
onClose: () => void;
}Specialized button components for table operations.
/**
* Button for deleting table rows or columns
*/
interface TableDeleteRowColumnButton extends React.Component<TableDeleteButtonProps> {}
interface TableDeleteButtonProps {
/** What to delete */
target: 'row' | 'column';
/** Button icon */
icon?: React.ReactNode;
/** Button label */
label?: string;
/** Custom styling */
className?: string;
}
/**
* Button for deleting entire tables
*/
interface TableDeleteButton extends React.Component<{
/** Confirmation message */
confirmMessage?: string;
/** Button icon */
icon?: React.ReactNode;
/** Button label */
label?: string;
}> {}Usage Example:
import React from 'react';
import {
TableComponents,
TableCellMenu,
TableDeleteRowColumnButton,
TableDeleteButton,
useCommands
} from '@remirror/react';
function TableInterface() {
const commands = useCommands();
const cellActions = [
{
id: 'merge-right',
label: 'Merge Right',
handler: () => commands.mergeCells(),
},
{
id: 'split-cell',
label: 'Split Cell',
handler: () => commands.splitCell(),
},
];
return (
<div>
<TableComponents
showControls={true}
controlComponents={{
deleteRow: () => <TableDeleteRowColumnButton target="row" />,
deleteColumn: () => <TableDeleteRowColumnButton target="column" />,
}}
/>
<TableCellMenu
actions={cellActions}
onSelect={(action) => action.handler()}
/>
</div>
);
}TypeScript interfaces for table-related commands.
interface TableCommands {
/** Create a new table */
createTable: (options?: {
rows?: number;
columns?: number;
withHeaderRow?: boolean;
}) => CommandFunction;
/** Delete the current table */
deleteTable: () => CommandFunction;
/** Add a row above current position */
addRowBefore: () => CommandFunction;
/** Add a row below current position */
addRowAfter: () => CommandFunction;
/** Delete the current row */
deleteRow: () => CommandFunction;
/** Add a column before current position */
addColumnBefore: () => CommandFunction;
/** Add a column after current position */
addColumnAfter: () => CommandFunction;
/** Delete the current column */
deleteColumn: () => CommandFunction;
/** Merge selected cells */
mergeCells: () => CommandFunction;
/** Split the current cell */
splitCell: () => CommandFunction;
/** Toggle header row */
toggleHeaderRow: () => CommandFunction;
/** Toggle header column */
toggleHeaderColumn: () => CommandFunction;
/** Move to next cell */
goToNextCell: () => CommandFunction;
/** Move to previous cell */
goToPreviousCell: () => CommandFunction;
}Plugin key and utilities for table functionality.
/**
* Plugin key for table controller functionality
*/
const tableControllerPluginKey: PluginKey<TableControllerState>;
interface TableControllerState {
/** Currently selected table */
selectedTable?: HTMLElement;
/** Selected cells */
selectedCells: HTMLElement[];
/** Controller UI state */
controllerVisible: boolean;
/** Current operation mode */
mode: 'select' | 'resize' | 'edit';
}
/**
* Utilities for working with table structures
*/
interface TableUtils {
/** Find table containing the current selection */
findTable: (state: EditorState) => ProsemirrorNode | null;
/** Get cell at specific coordinates */
getCellAt: (table: ProsemirrorNode, row: number, col: number) => ProsemirrorNode | null;
/** Get table dimensions */
getTableDimensions: (table: ProsemirrorNode) => { rows: number; cols: number };
/** Check if position is inside a table */
isInTable: (state: EditorState) => boolean;
/** Get current cell coordinates */
getCellCoordinates: (state: EditorState) => { row: number; col: number } | null;
}/**
* Table theme configuration
*/
interface TableTheme {
/** Table border styles */
border?: {
width?: string;
style?: 'solid' | 'dashed' | 'dotted';
color?: string;
};
/** Cell padding */
cellPadding?: string;
/** Header cell styling */
headerCell?: {
backgroundColor?: string;
fontWeight?: string;
textAlign?: 'left' | 'center' | 'right';
};
/** Selected cell styling */
selectedCell?: {
backgroundColor?: string;
borderColor?: string;
};
/** Controller styling */
controller?: {
backgroundColor?: string;
borderColor?: string;
buttonColor?: string;
};
}
/**
* Apply theme to table components
* @param theme - Table theme configuration
*/
function applyTableTheme(theme: TableTheme): void;/**
* Table resize functionality
*/
interface TableResizer {
/** Enable column resizing */
enableColumnResize: (table: HTMLElement) => void;
/** Disable column resizing */
disableColumnResize: (table: HTMLElement) => void;
/** Set column width */
setColumnWidth: (columnIndex: number, width: number) => void;
/** Get column width */
getColumnWidth: (columnIndex: number) => number;
}
/**
* Table sorting functionality
*/
interface TableSorter {
/** Sort table by column */
sortByColumn: (columnIndex: number, direction: 'asc' | 'desc') => void;
/** Enable column sorting */
enableSorting: (columns: number[]) => void;
/** Disable column sorting */
disableSorting: () => void;
}
/**
* Table export functionality
*/
interface TableExporter {
/** Export table as CSV */
toCSV: (table: ProsemirrorNode) => string;
/** Export table as HTML */
toHTML: (table: ProsemirrorNode) => string;
/** Export table as JSON */
toJSON: (table: ProsemirrorNode) => any[][];
}Usage Example:
import React from 'react';
import {
useCommands,
useExtension,
TableExtension,
applyTableTheme
} from '@remirror/react';
function AdvancedTableControls() {
const commands = useCommands();
const tableExtension = useExtension(TableExtension);
React.useEffect(() => {
// Apply custom table theme
applyTableTheme({
border: { width: '2px', style: 'solid', color: '#333' },
cellPadding: '12px',
headerCell: {
backgroundColor: '#f5f5f5',
fontWeight: 'bold',
},
});
}, []);
const createAdvancedTable = () => {
commands.createTable({
rows: 5,
columns: 4,
withHeaderRow: true,
});
};
return (
<div>
<button onClick={createAdvancedTable}>
Create Advanced Table
</button>
<button onClick={() => commands.mergeCells()}>
Merge Cells
</button>
<button onClick={() => commands.splitCell()}>
Split Cell
</button>
</div>
);
}docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10