Skip to content

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-catalyst-latest';

Signature:

export interface TableEditor extends ChildWidgetType

Extends: ChildWidgetType

Constructor

new TableEditor(app: App, editor: MarkdownBaseView, doc: Text, isDocComplete: boolean)

Constructor.

To extract the constructor type, use ExtractConstructor<TableEditor>.

Properties

PropertyTypeDescription
actionsElHTMLElement | nullElement holding the widget's action buttons, or null until the first action is added.
(Inherited from ChildWidgetType)
alignmentsTableAlignment[]Column alignment settings for the table.
appAppReference to the app.
(Inherited from ChildWidgetType)
cellChildMapMap<TableCell, Component[]>Map from table cells to the child components rendered inside them.
childrenComponent[]Child components added through ChildWidgetType.addChild.
(Inherited from ChildWidgetType)
colWidthsnumber[]Computed column widths, in characters.
containerElHTMLDivElementContainer element for the table widget.
docTextCodeMirror document snapshot for the table region.
editorMarkdownBaseViewEdit view that owns the widget.
(Inherited from ChildWidgetType)
endnumberEnd offset of the widget's range in the document, or -1 before ObsidianWidgetType.setPos is called.
(Inherited from ChildWidgetType)
estimatedHeightnumberEstimated height of the widget in pixels.
isDocCompletebooleanWhether the document backing this table is complete.
isMalformedbooleanWhether the table source is malformed.
noReusebooleanWhether the widget should never be reused for a different instance.
(Inherited from ChildWidgetType)
resizeObserver?ResizeObserverObserver used by ObsidianWidgetType.resizeWidget, created on first use.
(Inherited from ChildWidgetType)
rowsTableRow[]Rows of the table, each containing cells indexed by column.
selectedCellsTableCell[]Currently selected cells.
selectionAnchornull | TableCellAnchor cell of a multi-cell selection.
selectionHeadnull | TableCellHead cell of a multi-cell selection.
startnumberStart offset of the widget's range in the document, or -1 before ObsidianWidgetType.setPos is called.
(Inherited from ChildWidgetType)
tableElHTMLTableElement | nullRoot table DOM element, or null until the table has been rendered.
textstringPlain text content of the table.
updateCellReadonlyDebouncer<[], void>Refresh the readonly state of the focused cell editor.

Methods

MethodReturnsDescription
addAction(el, callback)thisAdd an action to the widget's action bar, creating the bar on first use.
(Inherited from ChildWidgetType)
addChild(component)voidAdd a child component, registering it on the owning edit view.
(Inherited from ChildWidgetType)
addEditButton(view, el)voidAdd the standard edit button, which selects the widget's source range when clicked.
(Inherited from ChildWidgetType)
addNewLine(placement)voidAdd a new line before or after the table.
applyCellUpdates(tr, cellMap, offset)voidApply pending cell content updates to the document.
cleanupChildren()voidUnload the child components of every cell.
clear()voidClear all rows, alignments, and DOM contents from the table.
containedBySelection(selection)booleanCheck whether the selection fully encloses the table.
containsRange(from, to)booleanCheck whether a document range lies within the table.
containsSelection(selection)booleanCheck whether every range of the selection lies within the table.
copySelection(event, cut)voidCopy the current cell selection to the clipboard, optionally cutting.
createDragHandle(cell, type)voidAdd a row or column drag handle to a cell.
deleteSelection(cut)voidDelete the current cell selection.
deselectCells()voidClear the current cell selection.
deselectTable()voidClear the table-wide selection.
dispatchTable(focusRow?, focusCol?, selectionFn?)voidRebuild the table and dispatch it to the editor as a single change.
dispatchUpdate(cellEditor, tr)voidForward an update made inside a cell editor to the parent document.
getCellAbove(cell)null | TableCellGet the cell above the given cell.
getCellAt(row, col)null | TableCellGet the cell at the given row and column.
getCellBelow(cell)null | TableCellGet the cell below the given cell.
getClosestCell(x, y)TableCellGet the cell closest to the given viewport coordinates.
getNextCell(cell, direction)null | TableCellGet the next cell in the given direction, wrapping across rows.
getSelectedCell(selection)null | TableCellGet the single cell that fully contains every range of the selection.
getSelectionBounds()null | TableSelectionBoundsGet the bounds of the current cell selection.
getTableString(bounds)stringGet the markdown string for the cells within the given bounds.
hookClickHandler(view, el)voidMake clicks on the element select the widget's source range, unless they land inside a nested editor.
(Inherited from ChildWidgetType)
initDOM()HTMLDivElementBuild the widget's container element.
initDOM(view)HTMLElementBuild the widget's container element.
(Inherited from ChildWidgetType)
insertColumn(focusRow, index, alignment, copyFromCol?)voidInsert a column into the table.
insertRow(index, focusCol, copyFromRow?)voidInsert a row into the table.
makeAlignmentMenu(menu, cols)voidAdd the alignment items for the given columns to a menu.
makeAlignmentRow(minCol, maxCol)stringBuild the markdown alignment (separator) row for a range of columns.
makeColMenu(menu, cell)voidAdd the column items for a cell's column to a menu.
makeRowMenu(menu, cell)voidAdd the row items for a cell's row to a menu.
makeSortMenu(menu, cell)voidAdd the sort items for a cell's column to a menu.
moveColumn(from, to, focusRow)voidMove a column to a new position.
moveRow(from, to, focusCol)voidMove a row to a new position.
offsetCellsAfter(cell, offset)voidShift the document offsets of every cell after the given one.
onContextMenu(cell, menu)voidPopulate the context menu for a cell.
pasteSelection(event)voidPaste clipboard content into the current cell selection.
placeCursorAround(placement)voidPlace the cursor on the line before or after the table, inserting one if needed.
placeCursorInCell(cell, position)voidFocus a cell and place the cursor inside it.
postProcess(cell)voidRun the markdown post-processors over a rendered cell.
rebuildTable()TextRebuild the table document from the current cell contents and re-render it.
receiveCellFocus(row, col, selectionFn?, isUserInitiated?)TableCellEditorFocus a cell and create a cell editor for it.
receiveIncompleteUpdate(tr, newDoc)booleanHandle a document update while the table's source is still incomplete.
receiveSelection(tr)voidHandle a selection change from the editor, moving focus into or out of the table.
receiveUpdate(tr, newDoc)booleanHandle a document update from the editor.
reconcileChanges(newDoc, tr)null | TextTry to reconcile external document changes with the table state without a full re-render.
removeChild(component)voidRemove a child component, unregistering it from the owning edit view.
(Inherited from ChildWidgetType)
removeChildren(cell)voidUnload the child components of a cell.
removeColumn(focusRow, index)voidRemove a column from the table.
removeRow(index, focusCol)voidRemove a row from the table.
render()voidRender the table into the container element.
rerenderCell(cell)voidRe-render a single cell.
resizeWidget(view, el)voidRe-measure the editor whenever the given element resizes.
(Inherited from ChildWidgetType)
selectCells(anchor, head, force?)voidSelect the rectangular range of cells between an anchor and a head.
selectTable()voidSelect every cell in the table.
setActiveDragHandles(cell)voidShow the drag handles belonging to a cell's row and column.
setAlignment(cols, alignment)voidSet the alignment of columns.
setCellFocus(row, col, selectionFn?)voidFocus a cell, rebuilding the table first if its source is malformed.
setOwner(el)voidRegister 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)voidRecord the document range the widget stands for.
(Inherited from ChildWidgetType)
sortByColumn(focusRow, col, compareFn)voidSort the table's body rows with the given comparator.
toDOM()HTMLDivElementCreate the DOM element for this widget.
toDOM(view)HTMLElementGet the widget's container element, building it via ObsidianWidgetType.initDOM on first call.
(Inherited from ChildWidgetType)
trimCell(cell)voidTrim whitespace from a cell's content, marking the table malformed if anything changed.
unsetActiveDragHandles(cell)voidHide 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)TableSelectionBoundsClamp selection bounds to the table dimensions.

Links to this page: