Adding definitions for prosemirror-table

This commit is contained in:
Oscar Wallhult
2017-09-18 15:37:44 +10:00
parent 7b26943522
commit 5befba4a80
5 changed files with 173 additions and 0 deletions

21
types/prosemirror-tables/dom.d.ts vendored Normal file
View File

@@ -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,
};

125
types/prosemirror-tables/index.d.ts vendored Normal file
View File

@@ -0,0 +1,125 @@
// Type definitions for prosemirror-tables 0.1
// Project: https://github.com/ProseMirror/prosemirror-tables
// Definitions by: Oscar Wallhult <https://github.com/superchu>
// Eduard Shvedai <https://github.com/eshvedai>
// 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;

View File

@@ -0,0 +1,3 @@
import * as tables from 'prosemirror-tables';
const table = tables.tableEditing();

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }