UNPKG

4.04 kBTypeScriptView Raw
1import { Node as ProseMirrorNode, Schema } from 'prosemirror-model';
2import { Mappable, Step, StepMap, StepResult } from 'prosemirror-transform';
3import { AddColumnStepInfo, AddColumnStepJson } from './types';
4/**
5 * Index and positions looks like
6 * 0 1 2 3 -> Add Column Index
7 * | 5 | 10 | 15 | -> Table with Positions
8 * | 20 | 25 | 30 |
9 * 0 1 2 x -> Remove Column Index
10 *
11 */
12export declare class AddColumnStep<S extends Schema = any> extends Step {
13 private readonly tablePos;
14 private readonly isDelete;
15 private columnInfo;
16 private sideEffectsHandler;
17 constructor(tablePos: number, addColumnStepInfo: AddColumnStepInfo, isDelete?: boolean);
18 /**
19 * Detect the column based on all the cells step in column info.
20 * Recreate columnInfo based on the current document. We might need to add new cells added by insert row or unmerge cells.
21 * If isDelete
22 * Decrease colspan if one row has merged cell
23 * Remove all the cells using columnInfo.cellStep[].from
24 * else
25 * Increase colspan if one row had merged cell
26 * Add all new cells at columnInfo.cellStep[].from,
27 * if there is columnInfo.cellStep[].newCell use it
28 * else create an empty cell
29 *
30 * @param doc Current document
31 */
32 apply(doc: ProseMirrorNode<S>): StepResult<S>;
33 /**
34 * Update tablePos with the new position. If tablePos doesnt exist any more remove the step
35 * Update all the cellStep inside columnInfo. If cellStep.from position gets deleted removed it from column info
36 * if cellStep.length === 0 remove the step
37 * Create a new step with all the position updated
38 * @param mapping
39 */
40 map(mapping: Mappable): Step<S> | null | undefined;
41 /**
42 * if isDelete
43 * Get the original cell node at columnInfo.cellStep[].from to columnInfo.cellStep[].to
44 * Create a copy of the node
45 * Create a new cellStep with the same positions but with the clone node as a content
46 * return new step inverted
47 * else
48 * Remove the content from each columnInfo.cellStep[].content
49 * return new step inverted
50 * @param originalDoc
51 */
52 invert(originalDoc: ProseMirrorNode<S>): Step<S>;
53 /**
54 * StepMap is created based on columnInfo.
55 * ColumnInfo is created on constructor and once is applied (the document could have new cells that weren't part of the original set)
56 * if isDelete
57 * Create range array based on cell info where each range is [cellStep.from, cellStep.from - cellStep.to, 0]
58 * else
59 * Create range array base on cell info where each range is [cellStep.from, 0, cellStep.content ? cellStep.content.nodeSize : defaultEmptyCellNodeSize]
60 *
61 * Ranges in ProseMirror are represented by each 3 elements in an array.
62 * As [pos, currentSize, newSize, pos2, currentSize2, newSize2] where:
63 * pos: Position in the document
64 * currentSize: Represent the affected range, this will be pos + currentSize
65 * newSize: Represent the new values, pos + newSize
66 */
67 getMap(): StepMap;
68 /**
69 * Try to merge this step with another one, to be applied directly
70 * after it. Returns the merged step when possible, null if the
71 * steps can't be merged.
72 */
73 merge(other: Step<S>): Step<S> | null | undefined;
74 /**
75 * Create a JSON-serializeable representation of this step. When
76 * defining this for a custom subclass, make sure the result object
77 * includes the step type's [JSON id](#transform.Step^jsonID) under
78 * the `stepType` property.
79 */
80 toJSON(): AddColumnStepJson;
81 /**
82 * Deserialize a step from its JSON representation. Will call
83 * through to the step class' own implementation of this method.
84 */
85 static fromJSON<S extends Schema = any>(schema: S, json: AddColumnStepJson): Step<S>;
86 static create(doc: ProseMirrorNode, tablePos: number, column: number, isDelete?: boolean): AddColumnStep<any>;
87 private applyCellSteps;
88}