1declare module 'prosemirror-utils' { 2 import { Node as ProsemirrorNode, Schema, NodeType, Mark, MarkType, ResolvedPos, Fragment } from 'prosemirror-model'; 3 import { Selection, Transaction } from 'prosemirror-state'; 4 5 export type Predicate = (node: ProsemirrorNode) => boolean; 6 7 export type DomAtPos = (pos: number) => { node: Node; offset: number }; 8 9 export type ContentNodeWithPos = { pos: number; start: number; depth: number; node: ProsemirrorNode }; 10 11 export type NodeWithPos = { pos: number; node: ProsemirrorNode }; 12 13 export type CellTransform = (cell: ContentNodeWithPos, tr: Transaction) => Transaction; 14 15 export type MovementOptions = { tryToFit: boolean; direction?: -1 | 0 | 1 }; 16 17 // Selection 18 export function findParentNode(predicate: Predicate): (selection: Selection) => ContentNodeWithPos | undefined; 19 20 export function findParentNodeClosestToPos($pos: ResolvedPos, predicate: Predicate): ContentNodeWithPos | undefined; 21 22 export function findParentDomRef( 23 predicate: Predicate, 24 domAtPos: DomAtPos, 25 ): (selection: Selection) => Node | undefined; 26 27 export function hasParentNode(predicate: Predicate): (selection: Selection) => boolean; 28 29 export function findParentNodeOfType( 30 nodeType: NodeType | NodeType[], 31 ): (selection: Selection) => ContentNodeWithPos | undefined; 32 33 export function findParentNodeOfTypeClosestToPos( 34 $pos: ResolvedPos, 35 nodeType: NodeType | NodeType[], 36 ): ContentNodeWithPos | undefined; 37 38 export function hasParentNodeOfType(nodeType: NodeType | NodeType[]): (selection: Selection) => boolean; 39 40 export function findParentDomRefOfType( 41 nodeType: NodeType | NodeType[], 42 domAtPos: DomAtPos, 43 ): (selection: Selection) => Node | undefined; 44 45 export function findSelectedNodeOfType( 46 nodeType: NodeType | NodeType[], 47 ): (selection: Selection) => ContentNodeWithPos | undefined; 48 49 export function isNodeSelection(selection: Selection): boolean; 50 51 export function findPositionOfNodeBefore(selection: Selection): number | undefined; 52 53 export function findDomRefAtPos(position: number, domAtPos: DomAtPos): Node; 54 55 // Node 56 export function flatten(node: ProsemirrorNode, descend?: boolean): NodeWithPos[]; 57 58 export function findChildren(node: ProsemirrorNode, predicate: Predicate, descend?: boolean): NodeWithPos[]; 59 60 export function findTextNodes(node: ProsemirrorNode, descend?: boolean): NodeWithPos[]; 61 62 export function findInlineNodes(node: ProsemirrorNode, descend?: boolean): NodeWithPos[]; 63 64 export function findBlockNodes(node: ProsemirrorNode, descend?: boolean): NodeWithPos[]; 65 66 export function findChildrenByAttr(node: ProsemirrorNode, predicate: Predicate, descend?: boolean): NodeWithPos[]; 67 68 export function findChildrenByType(node: ProsemirrorNode, nodeType: NodeType, descend?: boolean): NodeWithPos[]; 69 70 export function findChildrenByMark(node: ProsemirrorNode, markType: MarkType, descend?: boolean): NodeWithPos[]; 71 72 export function contains(node: ProsemirrorNode, nodeType: NodeType): boolean; 73 74 // Table 75 export function findTable(selection: Selection): ContentNodeWithPos | undefined; 76 77 export function isCellSelection(selection: Selection): boolean; 78 79 export function isColumnSelected(columnIndex: number): (selection: Selection) => boolean; 80 81 export function isRowSelected(rowIndex: number): (selection: Selection) => boolean; 82 83 export function isTableSelected(selection: Selection): boolean; 84 85 export function getCellsInColumn( 86 columnIndex: number | number[], 87 ): (selection: Selection) => ContentNodeWithPos[] | undefined; 88 89 export function getCellsInRow( 90 rowIndex: number | number[], 91 ): (selection: Selection) => ContentNodeWithPos[] | undefined; 92 93 export function getCellsInTable(selection: Selection): ContentNodeWithPos[] | undefined; 94 95 export function selectColumn(columnIndex: number, expand?: boolean): (tr: Transaction) => Transaction; 96 97 export function selectRow(rowIndex: number, expand?: boolean): (tr: Transaction) => Transaction; 98 99 export function selectTable(tr: Transaction): Transaction; 100 101 export function emptyCell(cell: ContentNodeWithPos, schema: Schema): (tr: Transaction) => Transaction; 102 103 export function addColumnAt(columnIndex: number): (tr: Transaction) => Transaction; 104 105 export function moveRow( 106 originRowIndex: number, 107 targetRowIndex: number, 108 options?: MovementOptions, 109 ): (tr: Transaction) => Transaction; 110 111 export function moveColumn( 112 originColumnIndex: number, 113 targetColumnIndex: number, 114 options?: MovementOptions, 115 ): (tr: Transaction) => Transaction; 116 117 export function addRowAt(rowIndex: number, clonePreviousRow?: boolean): (tr: Transaction) => Transaction; 118 119 export function cloneRowAt(cloneRowIndex: number): (tr: Transaction) => Transaction; 120 121 export function removeColumnAt(columnIndex: number): (tr: Transaction) => Transaction; 122 123 export function removeRowAt(rowIndex: number): (tr: Transaction) => Transaction; 124 125 export function removeSelectedColumns(tr: Transaction): Transaction; 126 127 export function removeSelectedRows(tr: Transaction): Transaction; 128 129 export function removeTable(tr: Transaction): Transaction; 130 131 export function removeColumnClosestToPos($pos: ResolvedPos): (tr: Transaction) => Transaction; 132 133 export function removeRowClosestToPos($pos: ResolvedPos): (tr: Transaction) => Transaction; 134 135 export function forEachCellInColumn( 136 columnIndex: number, 137 cellTransform: CellTransform, 138 moveCursorToLastCell?: boolean, 139 ): (tr: Transaction) => Transaction; 140 141 export function forEachCellInRow( 142 rowIndex: number, 143 cellTransform: CellTransform, 144 moveCursorToLastCell?: boolean, 145 ): (tr: Transaction) => Transaction; 146 147 export function setCellAttrs(cell: ContentNodeWithPos, attrs: Object): (tr: Transaction) => Transaction; 148 149 export function findCellClosestToPos($pos: ResolvedPos): ContentNodeWithPos | undefined; 150 151 export function findCellRectClosestToPos( 152 $pos: ResolvedPos, 153 ): { top: number; bottom: number; left: number; right: number } | undefined; 154 155 export function createTable( 156 schema: Schema, 157 rowsCount?: number, 158 colsCount?: number, 159 withHeaderRow?: boolean, 160 cellContent?: Node, 161 ): ProsemirrorNode; 162 163 export function getSelectionRect( 164 selection: Selection, 165 ): { top: number; bottom: number; left: number; right: number } | undefined; 166 167 export function getSelectionRangeInColumn( 168 columnIndex: number, 169 ): (tr: Transaction) => { $anchor: ResolvedPos; $head: ResolvedPos; indexes: number[] }; 170 171 export function getSelectionRangeInRow( 172 rowIndex: number, 173 ): (tr: Transaction) => { $anchor: ResolvedPos; $head: ResolvedPos; indexes: number[] }; 174 175 // Transforms 176 export function removeParentNodeOfType(nodeType: NodeType | NodeType[]): (tr: Transaction) => Transaction; 177 178 export function replaceParentNodeOfType( 179 nodeType: NodeType | NodeType[], 180 node: ProsemirrorNode, 181 ): (tr: Transaction) => Transaction; 182 183 export function removeSelectedNode(tr: Transaction): Transaction; 184 185 export function replaceSelectedNode(node: ProsemirrorNode): (tr: Transaction) => Transaction; 186 187 export function convertTableNodeToArrayOfRows(tableNode: ProsemirrorNode): ProsemirrorNode[]; 188 189 export function convertArrayOfRowsToTableNode( 190 tableNode: ProsemirrorNode, 191 tableArray: ProsemirrorNode[], 192 ): ProsemirrorNode; 193 194 export function canInsert($pos: ResolvedPos, node: ProsemirrorNode | Fragment): boolean; 195 196 export function safeInsert( 197 node: ProsemirrorNode | Fragment, 198 position?: number, 199 tryToReplace?: boolean, 200 ): (tr: Transaction) => Transaction; 201 202 export function setParentNodeMarkup( 203 nodeType: NodeType | NodeType[], 204 type?: NodeType | null, 205 attrs?: { [key: string]: any } | null, 206 marks?: Mark[], 207 ): (tr: Transaction) => Transaction; 208 209 export function selectParentNodeOfType(nodeType: NodeType | NodeType[]): (tr: Transaction) => Transaction; 210 211 export function removeNodeBefore(tr: Transaction): Transaction; 212 213 export function setTextSelection(position: number, dir?: number): (tr: Transaction) => Transaction; 214} 215