diff --git a/types/prosemirror-tables/dom.d.ts b/types/prosemirror-tables/dom.d.ts new file mode 100644 index 0000000000..b4b02d1c24 --- /dev/null +++ b/types/prosemirror-tables/dom.d.ts @@ -0,0 +1,21 @@ +export type DOMDataTransfer = DataTransfer; +export type DOMDocument = Document; +export type DOMElement = HTMLElement; +export type DOMEvent = Event; +export type DOMFragment = DocumentFragment; +export type DOMKeyboardEvent = KeyboardEvent; +export type DOMMouseEvent = MouseEvent; +export type DOMMutationRecord = MutationRecord; +export type DOMNode = Node; + +export { + DOMDataTransfer as DataTransfer, + DOMDocument as Document, + DOMElement as Element, + DOMEvent as Event, + DOMFragment as DocumentFragment, + DOMKeyboardEvent as KeyboardEvent, + DOMMouseEvent as MouseEvent, + DOMMutationRecord as MutationRecord, + DOMNode as Node, +}; diff --git a/types/prosemirror-tables/index.d.ts b/types/prosemirror-tables/index.d.ts new file mode 100644 index 0000000000..fe24b41189 --- /dev/null +++ b/types/prosemirror-tables/index.d.ts @@ -0,0 +1,125 @@ +// Type definitions for prosemirror-tables 0.1 +// Project: https://github.com/ProseMirror/prosemirror-tables +// Definitions by: Oscar Wallhult +// Eduard Shvedai +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 +import { EditorState, Plugin, SelectionRange, Transaction } from 'prosemirror-state'; +import { Node, NodeSpec, Slice, ResolvedPos } from 'prosemirror-model'; +import * as dom from './dom'; + +export interface TableNodesOptions { + tableGroup?: string; + cellContent: string; + cellAttributes: { [key: string]: CellAttributes }; +} + +export type getFromDOM = (dom: dom.DOMElement) => any; +export type setDOMAttr = (value: any, attrs: any) => any; + +export interface CellAttributes { + default: any; + getFromDOM?: getFromDOM; + setDOMAttr?: setDOMAttr; +} + +export interface TableNodes { + table: NodeSpec; + table_row: NodeSpec; + table_cell: NodeSpec; + table_header: NodeSpec; +} + +export function tableNodes(options: TableNodesOptions): TableNodes; + +export interface CellSelectionJSON { + type: string; + anchor: number; + head: number; +} + +export class CellSelection { + constructor($anchorCell: ResolvedPos, $headCell?: ResolvedPos); + + from: number; + to: number; + $from: ResolvedPos; + $to: ResolvedPos; + anchor: number; + head: number; + $anchor: ResolvedPos; + $head: ResolvedPos; + $anchorCell: ResolvedPos; + $headCell: ResolvedPos; + empty: boolean; + ranges: SelectionRange[]; + + map(doc: Node, mapping: any): any; + content(): Slice; + replace(tr: Transaction, content: Slice): void; + replaceWith(tr: Transaction, node: Node): void; + forEachCell(f: (node: Node, pos: number) => void): void; + isRowSelection(): boolean; + isColSelection(): boolean; + eq(other: any): boolean; + toJSON(): CellSelectionJSON; + getBookmark(): {anchor: number, head: number}; + + static colSelection(anchorCell: ResolvedPos, headCell?: ResolvedPos): CellSelection; + static rowSelection(anchorCell: ResolvedPos, headCell?: ResolvedPos): CellSelection; + static create(doc: Node, anchorCell: number, headCell?: number): CellSelection; + static fromJSON(doc: Node, json: CellSelectionJSON): CellSelection; +} + +export interface Rect { + left: number; + top: number; + right: number; + bottom: number; +} + +export class TableMap { + width: number; + height: number; + map: number[]; + problems?: object[]; + + findCell(pos: number): Rect; + colCount(pos: number): number; + nextCell(pos: number, axis: string, dir: number): number; + rectBetween(a: number, b: number): Rect; + cellsInRect(rect: Rect): number[]; + positionAt(row: number, col: number, table: Node): number; + + static get(table: Node): TableMap; +} + +export function tableEditing(): Plugin; + +export function deleteTable(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; + +export function goToNextCell(direction: number): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean; + +export function toggleHeaderCell(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; + +export function toggleHeaderColumn(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; + +export function toggleHeaderRow(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; + +export function setCellAttr(name: string, value: any): (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean; + +export function splitCell(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; + +export function mergeCells(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; + +export function deleteRow(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; + +export function addRowAfter(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; + +export function addRowBefore(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; + +export function deleteColumn(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; + +export function addColumnAfter(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; + +export function addColumnBefore(state: EditorState, dispatch?: (tr: Transaction) => void): boolean; diff --git a/types/prosemirror-tables/prosemirror-tables-tests.ts b/types/prosemirror-tables/prosemirror-tables-tests.ts new file mode 100644 index 0000000000..8c788ed54f --- /dev/null +++ b/types/prosemirror-tables/prosemirror-tables-tests.ts @@ -0,0 +1,3 @@ +import * as tables from 'prosemirror-tables'; + +const table = tables.tableEditing(); diff --git a/types/prosemirror-tables/tsconfig.json b/types/prosemirror-tables/tsconfig.json new file mode 100644 index 0000000000..822345265f --- /dev/null +++ b/types/prosemirror-tables/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "prosemirror-tables-tests.ts" + ] +} \ No newline at end of file diff --git a/types/prosemirror-tables/tslint.json b/types/prosemirror-tables/tslint.json new file mode 100644 index 0000000000..2750cc0197 --- /dev/null +++ b/types/prosemirror-tables/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } \ No newline at end of file