TableEditor
Unofficial
Widget that manages a rendered markdown table in the editor.
Manages the full lifecycle of table rendering, cell editing, row/column operations, selection, clipboard, drag handles, and document synchronization.
Import:
import type { TableEditor } from '@obsidian-typings/obsidian-public-latest';Signature:
export interface TableEditor extends ChildWidgetTypeExtends: ChildWidgetType
Constructor
new TableEditor(app: App, editor: MarkdownBaseView, doc: Text, isDocComplete: boolean)Constructor.
To extract the constructor type, use ExtractConstructor<TableEditor>.
Properties
| Property | Type | Description | |
|---|---|---|---|
| actionsEl | HTMLElement | null | Element holding the widget's action buttons, or null until the first action is added.(Inherited from ChildWidgetType) | |
| alignments | TableAlignment[] | Column alignment settings for the table. | |
| app | App | Reference to the app. (Inherited from ChildWidgetType) | |
| cellChildMap | Map<TableCell, Component[]> | Map from table cells to the child components rendered inside them. | |
| children | Component[] | Child components added through ChildWidgetType.addChild. (Inherited from ChildWidgetType) | |
| colWidths | number[] | Computed column widths, in characters. | |
| containerEl | HTMLDivElement | Container element for the table widget. | |
| doc | Text | CodeMirror document snapshot for the table region. | |
| editor | MarkdownBaseView | Edit view that owns the widget. (Inherited from ChildWidgetType) | |
| end | number | End offset of the widget's range in the document, or -1 before ObsidianWidgetType.setPos is called.(Inherited from ChildWidgetType) | |
| estimatedHeight | number | Estimated height of the widget in pixels. | |
| isDocComplete | boolean | Whether the document backing this table is complete. | |
| isMalformed | boolean | Whether the table source is malformed. | |
| noReuse | boolean | Whether the widget should never be reused for a different instance. (Inherited from ChildWidgetType) | |
| resizeObserver? | ResizeObserver | Observer used by ObsidianWidgetType.resizeWidget, created on first use. (Inherited from ChildWidgetType) | |
| rows | TableRow[] | Rows of the table, each containing cells indexed by column. | |
| selectedCells | TableCell[] | Currently selected cells. | |
| selectionAnchor | null | TableCell | Anchor cell of a multi-cell selection. | |
| selectionHead | null | TableCell | Head cell of a multi-cell selection. | |
| start | number | Start offset of the widget's range in the document, or -1 before ObsidianWidgetType.setPos is called.(Inherited from ChildWidgetType) | |
| tableEl | HTMLTableElement | null | Root table DOM element, or null until the table has been rendered. | |
| text | string | Plain text content of the table. | |
| updateCellReadonly | Debouncer<[], void> | Refresh the readonly state of the focused cell editor. |
Methods
| Method | Returns | Description | |
|---|---|---|---|
| addAction(el, callback) | this | Add an action to the widget's action bar, creating the bar on first use. (Inherited from ChildWidgetType) | |
| addChild(component) | void | Add a child component, registering it on the owning edit view. (Inherited from ChildWidgetType) | |
| addEditButton(view, el) | void | Add the standard edit button, which selects the widget's source range when clicked. (Inherited from ChildWidgetType) | |
| addNewLine(placement) | void | Add a new line before or after the table. | |
| applyCellUpdates(tr, cellMap, offset) | void | Apply pending cell content updates to the document. | |
| cleanupChildren() | void | Unload the child components of every cell. | |
| clear() | void | Clear all rows, alignments, and DOM contents from the table. | |
| containedBySelection(selection) | boolean | Check whether the selection fully encloses the table. | |
| containsRange(from, to) | boolean | Check whether a document range lies within the table. | |
| containsSelection(selection) | boolean | Check whether every range of the selection lies within the table. | |
| copySelection(event, cut) | void | Copy the current cell selection to the clipboard, optionally cutting. | |
| createDragHandle(cell, type) | void | Add a row or column drag handle to a cell. | |
| deleteSelection(cut) | void | Delete the current cell selection. | |
| deselectCells() | void | Clear the current cell selection. | |
| deselectTable() | void | Clear the table-wide selection. | |
| dispatchTable(focusRow?, focusCol?, selectionFn?) | void | Rebuild the table and dispatch it to the editor as a single change. | |
| dispatchUpdate(cellEditor, tr) | void | Forward an update made inside a cell editor to the parent document. | |
| getCellAbove(cell) | null | TableCell | Get the cell above the given cell. | |
| getCellAt(row, col) | null | TableCell | Get the cell at the given row and column. | |
| getCellBelow(cell) | null | TableCell | Get the cell below the given cell. | |
| getClosestCell(x, y) | TableCell | Get the cell closest to the given viewport coordinates. | |
| getNextCell(cell, direction) | null | TableCell | Get the next cell in the given direction, wrapping across rows. | |
| getSelectedCell(selection) | null | TableCell | Get the single cell that fully contains every range of the selection. | |
| getSelectionBounds() | null | TableSelectionBounds | Get the bounds of the current cell selection. | |
| getTableString(bounds) | string | Get the markdown string for the cells within the given bounds. | |
| hookClickHandler(view, el) | void | Make clicks on the element select the widget's source range, unless they land inside a nested editor. (Inherited from ChildWidgetType) | |
| initDOM() | HTMLDivElement | Build the widget's container element. | |
| initDOM(view) | HTMLElement | Build the widget's container element. (Inherited from ChildWidgetType) | |
| insertColumn(focusRow, index, alignment, copyFromCol?) | void | Insert a column into the table. | |
| insertRow(index, focusCol, copyFromRow?) | void | Insert a row into the table. | |
| makeAlignmentMenu(menu, cols) | void | Add the alignment items for the given columns to a menu. | |
| makeAlignmentRow(minCol, maxCol) | string | Build the markdown alignment (separator) row for a range of columns. | |
| makeColMenu(menu, cell) | void | Add the column items for a cell's column to a menu. | |
| makeRowMenu(menu, cell) | void | Add the row items for a cell's row to a menu. | |
| makeSortMenu(menu, cell) | void | Add the sort items for a cell's column to a menu. | |
| moveColumn(from, to, focusRow) | void | Move a column to a new position. | |
| moveRow(from, to, focusCol) | void | Move a row to a new position. | |
| offsetCellsAfter(cell, offset) | void | Shift the document offsets of every cell after the given one. | |
| onContextMenu(cell, menu) | void | Populate the context menu for a cell. | |
| pasteSelection(event) | void | Paste clipboard content into the current cell selection. | |
| placeCursorAround(placement) | void | Place the cursor on the line before or after the table, inserting one if needed. | |
| placeCursorInCell(cell, position) | void | Focus a cell and place the cursor inside it. | |
| postProcess(cell) | void | Run the markdown post-processors over a rendered cell. | |
| rebuildTable() | Text | Rebuild the table document from the current cell contents and re-render it. | |
| receiveCellFocus(row, col, selectionFn?, isUserInitiated?) | TableCellEditor | Focus a cell and create a cell editor for it. | |
| receiveIncompleteUpdate(tr, newDoc) | boolean | Handle a document update while the table's source is still incomplete. | |
| receiveSelection(tr) | void | Handle a selection change from the editor, moving focus into or out of the table. | |
| receiveUpdate(tr, newDoc) | boolean | Handle a document update from the editor. | |
| reconcileChanges(newDoc, tr) | null | Text | Try to reconcile external document changes with the table state without a full re-render. | |
| removeChild(component) | void | Remove a child component, unregistering it from the owning edit view. (Inherited from ChildWidgetType) | |
| removeChildren(cell) | void | Unload the child components of a cell. | |
| removeColumn(focusRow, index) | void | Remove a column from the table. | |
| removeRow(index, focusCol) | void | Remove a row from the table. | |
| render() | void | Render the table into the container element. | |
| rerenderCell(cell) | void | Re-render a single cell. | |
| resizeWidget(view, el) | void | Re-measure the editor whenever the given element resizes. (Inherited from ChildWidgetType) | |
| selectCells(anchor, head, force?) | void | Select the rectangular range of cells between an anchor and a head. | |
| selectTable() | void | Select every cell in the table. | |
| setActiveDragHandles(cell) | void | Show the drag handles belonging to a cell's row and column. | |
| setAlignment(cols, alignment) | void | Set the alignment of columns. | |
| setCellFocus(row, col, selectionFn?) | void | Focus a cell, rebuilding the table first if its source is malformed. | |
| setOwner(el) | void | Register the widget as the owner of the given element, so that clicks on it can be routed back here. (Inherited from ChildWidgetType) | |
| setPos(start, end) | void | Record the document range the widget stands for. (Inherited from ChildWidgetType) | |
| sortByColumn(focusRow, col, compareFn) | void | Sort the table's body rows with the given comparator. | |
| toDOM() | HTMLDivElement | Create the DOM element for this widget. | |
| toDOM(view) | HTMLElement | Get the widget's container element, building it via ObsidianWidgetType.initDOM on first call. (Inherited from ChildWidgetType) | |
| trimCell(cell) | void | Trim whitespace from a cell's content, marking the table malformed if anything changed. | |
| unsetActiveDragHandles(cell) | void | Hide the drag handles belonging to a cell's row and column. | |
| updateCell(cell, text) | TableCellChange[] | Update a cell's text and re-pad every cell in its column to the new width. | |
| validateSelectionBounds(bounds) | TableSelectionBounds | Clamp selection bounds to the table dimensions. |
Links to this page: