Fix prosemirror-transform Transform methods to allow inheritence. (#18681)

This commit is contained in:
Bradley Ayers
2017-08-08 12:17:10 -07:00
committed by Mohamed Hegazy
parent 34f60516b3
commit e8ff5620d6
2 changed files with 50 additions and 17 deletions
@@ -1,4 +1,6 @@
import * as state from 'prosemirror-state';
import * as model from 'prosemirror-model';
import * as transform from 'prosemirror-transform';
let plugin: state.Plugin;
@@ -6,3 +8,34 @@ plugin = new state.Plugin({});
plugin = new state.Plugin({
props: {}
});
// Verify that Transaction (that extends Transform) has the correct return types
// for its builder methods. There was a bug where Transform's methods returned type
// 'Transform', rather than 'this', which prevented subclassing from working
// correctly.
const node = {} as model.Node;
const mark = {} as model.Mark;
const slice = {} as model.Slice;
const nodeRange = {} as model.NodeRange;
const step = {} as transform.Step;
let transaction: state.Transaction;
transaction = new state.Transaction(node).delete(0, 0);
transaction = new state.Transaction(node).addMark(0, 0, mark);
transaction = new state.Transaction(node).removeMark(0, 0);
transaction = new state.Transaction(node).clearMarkup(0, 0);
transaction = new state.Transaction(node).replaceRange(0, 0, slice);
transaction = new state.Transaction(node).replaceRangeWith(0, 0, node);
transaction = new state.Transaction(node).deleteRange(0, 0);
transaction = new state.Transaction(node).delete(0, 0);
transaction = new state.Transaction(node).replace(0, 0);
transaction = new state.Transaction(node).replaceWith(0, 0, node);
transaction = new state.Transaction(node).insert(0, node);
transaction = new state.Transaction(node).lift(nodeRange, 0);
transaction = new state.Transaction(node).wrap(nodeRange, []);
transaction = new state.Transaction(node).setBlockType(0, 0, node.type);
transaction = new state.Transaction(node).setNodeType(0);
transaction = new state.Transaction(node).split(0);
transaction = new state.Transaction(node).join(0);
transaction = new state.Transaction(node).step(step);
+17 -17
View File
@@ -42,28 +42,28 @@ export class RemoveMarkStep extends Step {
}
export class Transform {
constructor(doc: Node)
addMark(from: number, to: number, mark: Mark): Transform;
removeMark(from: number, to: number, mark?: Mark | MarkType): Transform;
clearMarkup(from: number, to: number): Transform;
replaceRange(from: number, to: number, slice: Slice): Transform;
replaceRangeWith(from: number, to: number, node: Node): Transform;
deleteRange(from: number, to: number): Transform;
delete(from: number, to: number): Transform;
replace(from: number, to?: number, slice?: Slice): Transform;
replaceWith(from: number, to: number, content: Fragment | Node | Node[]): Transform;
insert(pos: number, content: Fragment | Node | Node[]): Transform;
lift(range: NodeRange, target: number): Transform;
wrap(range: NodeRange, wrappers: Array<{ type: NodeType, attrs?: object | null }>): Transform;
setBlockType(from: number, to: number | undefined, type: NodeType, attrs?: object): Transform;
setNodeType(pos: number, type?: NodeType, attrs?: object, marks?: Mark[]): Transform;
split(pos: number, depth?: number, typesAfter?: Array<{ type: NodeType, attrs?: object | null }>): Transform;
join(pos: number, depth?: number, p1?: boolean): Transform;
addMark(from: number, to: number, mark: Mark): this;
removeMark(from: number, to: number, mark?: Mark | MarkType): this;
clearMarkup(from: number, to: number): this;
replaceRange(from: number, to: number, slice: Slice): this;
replaceRangeWith(from: number, to: number, node: Node): this;
deleteRange(from: number, to: number): this;
delete(from: number, to: number): this;
replace(from: number, to?: number, slice?: Slice): this;
replaceWith(from: number, to: number, content: Fragment | Node | Node[]): this;
insert(pos: number, content: Fragment | Node | Node[]): this;
lift(range: NodeRange, target: number): this;
wrap(range: NodeRange, wrappers: Array<{ type: NodeType, attrs?: object | null }>): this;
setBlockType(from: number, to: number | undefined, type: NodeType, attrs?: object): this;
setNodeType(pos: number, type?: NodeType, attrs?: object, marks?: Mark[]): this;
split(pos: number, depth?: number, typesAfter?: Array<{ type: NodeType, attrs?: object | null }>): this;
join(pos: number, depth?: number, p1?: boolean): this;
doc: Node;
steps: Step[];
docs: Node[];
mapping: Mapping;
before: Node;
step(step: Step): Transform;
step(step: Step): this;
maybeStep(step: Step): StepResult;
docChanged: boolean;
}