import { Node } from "prosemirror-model"; import { EditorState, Transaction } from "prosemirror-state"; import { EditorView } from "prosemirror-view"; import { EditorSchema } from "./schema"; export type Dispatch = (tr: Transaction) => void; export type Command = (state: EditorState, dispatch?: Dispatch, view?: EditorView) => boolean; export type CommandPredicate = (state: EditorState) => boolean; /** * Nominal typing for any TypeScript interface or class. * * If T is an enum type, any type which includes this interface * will only match other types that are tagged with the same * enum type. * * See https://stackoverflow.com/a/37074697/253686 */ export interface Nominal { "nominal structural brand": T; } export interface NominalDocPos { "position in document brand": T; } export interface NominalTablePos { "position in table brand": T; } export declare namespace Tag { // Position relative to the start (first position inside) of a doc. export const enum DocPos {} // Position of a cell in a doc (relative to the start of the doc). export const enum DocPosOfCell {} // Position of a cell in a table (relative to the start of the table). export const enum TablePosOfCell {} // A table node export const enum TableNode {} // A doc node (this might actually be a table, if the schema defines doc to be // a table). export const enum DocNode {} // In general the "start" position of a table is stored rather than its // "before" position. Using this perspective provides support for schemas // where `doc` is actually the table node. // // When the table is the doc, its start position (0) can be resolved via // `doc.resolve(pos)`. If instead the before position (-1) was used, it would // not be possible to resolve via `doc.resolve(pos)`. export const enum TableStart {} // The 0-index of a table row. export const enum TableRowIndex {} // The 0-index of a table column edge. export const enum TableRowEdgeIndex {} // The 0-index of a table column. export const enum TableColumnIndex {} // The 0-index of a table column edge. export const enum TableColumnEdgeIndex {} } export type DocPos = number & Nominal; export type DocPosOfCell = DocPos & NominalDocPos; export type DocNode = Node & Nominal; export type TablePosOfCell = number & NominalTablePos; export type TableNode = Node & Nominal; export type TableStart = DocPos & NominalDocPos; export type TableRowIndex = number & Nominal; export type TableRowEdgeIndex = number & Nominal; export type TableColumnIndex = number & Nominal; export type TableColumnEdgeIndex = number & Nominal; export interface PosRange { readonly from: T; readonly to: T; } /** * Position range of a doc. */ export interface DocPosRange extends PosRange {} export const enum TableAxis { ROW, COLUMN } export const enum CartesianAxis { HORIZONTAL, VERTICAL } export type DirString = "up" | "down" | "left" | "right" | "forward" | "backward"; export const enum Bias { FORWARD = "a", BACKWARD = "b" } export interface NodeTypeSpec { allowWedge?: boolean; } /** * A helper that translates an interface describing a ProseMirror node's * attributes, into the shape required for the NodeType's attrs spec. */ export type AttrsSpec = { [P in keyof T]-?: T[P] extends object | boolean | null | string | number ? { default?: T[P] } : { default: T[P] } }; export type Omit = Pick>;