@atlaskit/adf-schema 28.1.12 → 28.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/__tests__/unit/json-schema/v1.ts +0 -55
- package/src/__tests__/unit/schema/create-schema.ts +0 -214
- package/src/__tests__/unit/schema/default-schema.ts +0 -192
- package/src/__tests__/unit/schema/marks/annotation.ts +0 -46
- package/src/__tests__/unit/schema/marks/border.ts +0 -76
- package/src/__tests__/unit/schema/marks/breakout.ts +0 -24
- package/src/__tests__/unit/schema/marks/code.ts +0 -44
- package/src/__tests__/unit/schema/marks/confluence-inline-comment.ts +0 -25
- package/src/__tests__/unit/schema/marks/data-consumer.ts +0 -52
- package/src/__tests__/unit/schema/marks/em.ts +0 -37
- package/src/__tests__/unit/schema/marks/link.ts +0 -188
- package/src/__tests__/unit/schema/marks/strike.ts +0 -37
- package/src/__tests__/unit/schema/marks/strong.ts +0 -43
- package/src/__tests__/unit/schema/marks/subsup.ts +0 -50
- package/src/__tests__/unit/schema/marks/text-color.ts +0 -61
- package/src/__tests__/unit/schema/marks/underline.ts +0 -36
- package/src/__tests__/unit/schema/nodes/_consts.ts +0 -964
- package/src/__tests__/unit/schema/nodes/block-card.ts +0 -184
- package/src/__tests__/unit/schema/nodes/blockquote.ts +0 -44
- package/src/__tests__/unit/schema/nodes/bodied-extension.ts +0 -101
- package/src/__tests__/unit/schema/nodes/code-block.ts +0 -221
- package/src/__tests__/unit/schema/nodes/confluence-unsupported-block.ts +0 -32
- package/src/__tests__/unit/schema/nodes/confluence-unsupported-inline.ts +0 -35
- package/src/__tests__/unit/schema/nodes/date.ts +0 -51
- package/src/__tests__/unit/schema/nodes/decision-item.ts +0 -46
- package/src/__tests__/unit/schema/nodes/decision-list.ts +0 -52
- package/src/__tests__/unit/schema/nodes/embed-card.ts +0 -60
- package/src/__tests__/unit/schema/nodes/emoji.ts +0 -71
- package/src/__tests__/unit/schema/nodes/expand.ts +0 -51
- package/src/__tests__/unit/schema/nodes/extension.ts +0 -101
- package/src/__tests__/unit/schema/nodes/hard-break.ts +0 -24
- package/src/__tests__/unit/schema/nodes/heading.ts +0 -56
- package/src/__tests__/unit/schema/nodes/image.ts +0 -32
- package/src/__tests__/unit/schema/nodes/inline-card.ts +0 -106
- package/src/__tests__/unit/schema/nodes/inline-extension.ts +0 -79
- package/src/__tests__/unit/schema/nodes/layout-column.ts +0 -54
- package/src/__tests__/unit/schema/nodes/layout-section.ts +0 -95
- package/src/__tests__/unit/schema/nodes/list-item.ts +0 -49
- package/src/__tests__/unit/schema/nodes/media-group.ts +0 -67
- package/src/__tests__/unit/schema/nodes/media-single.ts +0 -171
- package/src/__tests__/unit/schema/nodes/media.ts +0 -384
- package/src/__tests__/unit/schema/nodes/mention.ts +0 -115
- package/src/__tests__/unit/schema/nodes/nestedExpand.ts +0 -72
- package/src/__tests__/unit/schema/nodes/ordered-list.ts +0 -49
- package/src/__tests__/unit/schema/nodes/panel.ts +0 -180
- package/src/__tests__/unit/schema/nodes/paragraph.ts +0 -25
- package/src/__tests__/unit/schema/nodes/placeholder.ts +0 -46
- package/src/__tests__/unit/schema/nodes/rule.ts +0 -24
- package/src/__tests__/unit/schema/nodes/status.ts +0 -120
- package/src/__tests__/unit/schema/nodes/tableNodes.ts +0 -555
- package/src/__tests__/unit/schema/nodes/task-item.ts +0 -39
- package/src/__tests__/unit/schema/nodes/task-list.ts +0 -45
- package/src/__tests__/unit/schema/nodes/unknown-block.ts +0 -42
- package/src/__tests__/unit/schema/nodes/unsupported-block.ts +0 -42
- package/src/__tests__/unit/schema/nodes/unsupported-inline.ts +0 -38
- package/src/__tests__/unit/utils/colors.ts +0 -42
- package/src/__tests__/unit/utils/url.ts +0 -209
- package/src/schema/bitbucket-schema.ts +0 -43
- package/src/schema/confluence-schema.ts +0 -76
- package/src/schema/create-schema.ts +0 -337
- package/src/schema/default-schema.ts +0 -180
- package/src/schema/groups.ts +0 -30
- package/src/schema/inline-nodes.ts +0 -9
- package/src/schema/jira-schema.ts +0 -158
- package/src/schema/marks/__tests__/unit/annotation.ts +0 -18
- package/src/schema/marks/alignment.ts +0 -48
- package/src/schema/marks/annotation.ts +0 -107
- package/src/schema/marks/border.ts +0 -74
- package/src/schema/marks/breakout.ts +0 -42
- package/src/schema/marks/code.ts +0 -45
- package/src/schema/marks/confluence-inline-comment.ts +0 -32
- package/src/schema/marks/data-consumer.ts +0 -100
- package/src/schema/marks/em.ts +0 -19
- package/src/schema/marks/fragment.ts +0 -77
- package/src/schema/marks/indentation.ts +0 -47
- package/src/schema/marks/link.ts +0 -139
- package/src/schema/marks/strike.ts +0 -26
- package/src/schema/marks/strong.ts +0 -45
- package/src/schema/marks/subsup.ts +0 -53
- package/src/schema/marks/text-color.ts +0 -172
- package/src/schema/marks/type-ahead-query.ts +0 -22
- package/src/schema/marks/underline.ts +0 -24
- package/src/schema/marks/unsupported-mark.ts +0 -9
- package/src/schema/marks/unsupported-node-attributes.ts +0 -8
- package/src/schema/nodes/block-card.ts +0 -121
- package/src/schema/nodes/blockquote.ts +0 -25
- package/src/schema/nodes/bodied-extension.ts +0 -75
- package/src/schema/nodes/bullet-list.ts +0 -17
- package/src/schema/nodes/caption.ts +0 -51
- package/src/schema/nodes/code-block.ts +0 -176
- package/src/schema/nodes/confluence-jira-issue.ts +0 -43
- package/src/schema/nodes/confluence-unsupported-block.ts +0 -29
- package/src/schema/nodes/confluence-unsupported-inline.ts +0 -30
- package/src/schema/nodes/date.ts +0 -38
- package/src/schema/nodes/decision-item.ts +0 -50
- package/src/schema/nodes/decision-list.ts +0 -56
- package/src/schema/nodes/doc.ts +0 -30
- package/src/schema/nodes/embed-card.ts +0 -62
- package/src/schema/nodes/emoji.ts +0 -89
- package/src/schema/nodes/expand.ts +0 -101
- package/src/schema/nodes/extension.ts +0 -60
- package/src/schema/nodes/hard-break.ts +0 -21
- package/src/schema/nodes/heading.ts +0 -64
- package/src/schema/nodes/image.ts +0 -32
- package/src/schema/nodes/inline-card.ts +0 -70
- package/src/schema/nodes/inline-extension.ts +0 -57
- package/src/schema/nodes/layout-column.ts +0 -68
- package/src/schema/nodes/layout-section.ts +0 -93
- package/src/schema/nodes/list-item.ts +0 -13
- package/src/schema/nodes/media-group.ts +0 -44
- package/src/schema/nodes/media-inline.ts +0 -19
- package/src/schema/nodes/media-single.ts +0 -179
- package/src/schema/nodes/media.ts +0 -253
- package/src/schema/nodes/mention.ts +0 -86
- package/src/schema/nodes/nested-expand.ts +0 -77
- package/src/schema/nodes/ordered-list.ts +0 -62
- package/src/schema/nodes/panel.ts +0 -133
- package/src/schema/nodes/paragraph.ts +0 -79
- package/src/schema/nodes/placeholder.ts +0 -40
- package/src/schema/nodes/rule.ts +0 -17
- package/src/schema/nodes/status.ts +0 -58
- package/src/schema/nodes/tableNodes.ts +0 -478
- package/src/schema/nodes/task-item.ts +0 -51
- package/src/schema/nodes/task-list.ts +0 -61
- package/src/schema/nodes/text.ts +0 -19
- package/src/schema/nodes/types/block-content.ts +0 -51
- package/src/schema/nodes/types/extensions.ts +0 -36
- package/src/schema/nodes/types/inline-content.ts +0 -56
- package/src/schema/nodes/types/list.ts +0 -54
- package/src/schema/nodes/types/mark.ts +0 -16
- package/src/schema/nodes/types/non-nestable-block-content.ts +0 -39
- package/src/schema/nodes/types/rich-media-common.ts +0 -51
- package/src/schema/nodes/unknown-block.ts +0 -13
- package/src/schema/nodes/unsupported-block.ts +0 -28
- package/src/schema/nodes/unsupported-inline.ts +0 -27
- package/src/schema/unsupported.ts +0 -4
- package/src/steps/__tests__/unit/analytics.ts +0 -72
- package/src/steps/__tests__/unit/link-meta-step.ts +0 -64
- package/src/steps/__tests__/unit/override-document-step.ts +0 -174
- package/src/steps/__tests__/unit/set-attrs.ts +0 -71
- package/src/steps/analytics.ts +0 -189
- package/src/steps/link-meta-step.ts +0 -105
- package/src/steps/override-document-step.ts +0 -97
- package/src/steps/set-attrs.tsx +0 -74
- package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-0.json +0 -15
- package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-1.json +0 -15
- package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-2.json +0 -15
- package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-3.json +0 -15
- package/src/steps/table/__tests__/__fixtures__/basic/remove-column-at-0.json +0 -9
- package/src/steps/table/__tests__/__fixtures__/basic/remove-column-at-1.json +0 -9
- package/src/steps/table/__tests__/__fixtures__/basic/remove-column-at-2.json +0 -9
- package/src/steps/table/__tests__/__fixtures__/basic/remove-table/remove-last-row-inverted.json +0 -98
- package/src/steps/table/__tests__/__fixtures__/basic/remove-table/remove-last-row.json +0 -71
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-0-inverted.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-0.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-1-inverted.json +0 -21
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-1.json +0 -21
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-2-inverted.json +0 -21
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-2.json +0 -21
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-3-inverted.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-3.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-0-inverted.json +0 -63
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-0.json +0 -21
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-1-inverted.json +0 -64
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-1.json +0 -22
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-2-inverted.json +0 -63
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-2.json +0 -21
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-0-inverted.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-0.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-1-inverted.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-1.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-2-inverted.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-2.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-3-inverted.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-3.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-0-inverted.json +0 -52
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-0.json +0 -38
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-1-inverted.json +0 -52
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-1.json +0 -38
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-2-inverted.json +0 -25
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-2.json +0 -11
- package/src/steps/table/__tests__/_utils.ts +0 -102
- package/src/steps/table/__tests__/add-column-merge-columns.ts +0 -509
- package/src/steps/table/__tests__/add-column-merge-rows.ts +0 -466
- package/src/steps/table/__tests__/add-column.ts +0 -638
- package/src/steps/table/add-column.ts +0 -443
- package/src/steps/table/constants.ts +0 -4
- package/src/steps/table/sort-column.ts +0 -57
- package/src/steps/table/types.ts +0 -48
- package/src/steps/table/utils/cell-step.ts +0 -239
- package/src/steps/table/utils/cells-at-column.ts +0 -75
- package/src/steps/table/utils/find-column.ts +0 -90
- package/src/steps/table/utils/get-table-rect-from-doc.ts +0 -37
- package/src/steps/table/utils/side-effects/rows.ts +0 -327
- package/src/steps/table/utils/side-effects/side-effects.ts +0 -90
- package/src/steps/table/utils/side-effects/table.ts +0 -112
- package/src/steps/table/utils/side-effects/types.ts +0 -34
- package/src/steps/table/utils/table-map.ts +0 -28
- package/src/steps/type-ahead.ts +0 -100
- package/src/steps.ts +0 -16
- package/src/utils/colors.ts +0 -171
- package/src/utils/confluence/emoji.ts +0 -99
- package/src/utils/extensions.ts +0 -32
- package/src/utils/parseDOM.ts +0 -2
- package/src/utils/url.ts +0 -173
- package/src/utils/uuid.ts +0 -19
- package/src/version.json +0 -6
@@ -1,443 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
Node as ProseMirrorNode,
|
3
|
-
Schema,
|
4
|
-
} from '@atlaskit/editor-prosemirror/model';
|
5
|
-
import {
|
6
|
-
Mappable,
|
7
|
-
Step,
|
8
|
-
StepMap,
|
9
|
-
StepResult,
|
10
|
-
Transform,
|
11
|
-
} from '@atlaskit/editor-prosemirror/transform';
|
12
|
-
import { TableRect } from '@atlaskit/editor-tables/table-map';
|
13
|
-
|
14
|
-
import { Cell, cellsAtColumn } from './utils/cells-at-column';
|
15
|
-
import { findColumn } from './utils/find-column';
|
16
|
-
import {
|
17
|
-
AddColumnStepInfo,
|
18
|
-
AddColumnStepJson,
|
19
|
-
CellStep,
|
20
|
-
CellStepJson,
|
21
|
-
ColumnInfo,
|
22
|
-
} from './types';
|
23
|
-
import { getTableRectFromDoc } from './utils/get-table-rect-from-doc';
|
24
|
-
import {
|
25
|
-
applyCellStep,
|
26
|
-
createCellStep,
|
27
|
-
getMapFromCellStep,
|
28
|
-
invertCellStep,
|
29
|
-
} from './utils/cell-step';
|
30
|
-
import { SideEffectsHandler } from './utils/side-effects/side-effects';
|
31
|
-
import memoizeOne from 'memoize-one';
|
32
|
-
import { SideEffects } from './utils/side-effects/types';
|
33
|
-
|
34
|
-
const ADD_COLUMN_STEP = 'ak-add-column';
|
35
|
-
|
36
|
-
function printColumnInfo(columnInfo: ColumnInfo) {
|
37
|
-
let cellsFrom = [];
|
38
|
-
for (const cellInfo of columnInfo.values()) {
|
39
|
-
cellsFrom.push(cellInfo.from);
|
40
|
-
}
|
41
|
-
return `[${cellsFrom.join(',')}]`;
|
42
|
-
}
|
43
|
-
|
44
|
-
function createColumnInfo(cellsInfo: CellStep[]): ColumnInfo {
|
45
|
-
return new Map<number, CellStep>(
|
46
|
-
cellsInfo.map((cellInfo) => [cellInfo.from, cellInfo]),
|
47
|
-
);
|
48
|
-
}
|
49
|
-
|
50
|
-
const getTableRectAndColumnFactory = (
|
51
|
-
doc: ProseMirrorNode,
|
52
|
-
pos: number,
|
53
|
-
columnInfo: ColumnInfo,
|
54
|
-
) => {
|
55
|
-
return memoizeOne(() => {
|
56
|
-
const rect = getTableRectFromDoc(doc, pos);
|
57
|
-
|
58
|
-
const column = findColumn(columnInfo, rect);
|
59
|
-
if (column === null) {
|
60
|
-
throw new Error('no column');
|
61
|
-
}
|
62
|
-
return {
|
63
|
-
rect,
|
64
|
-
column,
|
65
|
-
};
|
66
|
-
});
|
67
|
-
};
|
68
|
-
|
69
|
-
/**
|
70
|
-
* Index and positions looks like
|
71
|
-
* 0 1 2 3 -> Add Column Index
|
72
|
-
* | 5 | 10 | 15 | -> Table with Positions
|
73
|
-
* | 20 | 25 | 30 |
|
74
|
-
* 0 1 2 x -> Remove Column Index
|
75
|
-
*
|
76
|
-
*/
|
77
|
-
export class AddColumnStep<S extends Schema = any> extends Step {
|
78
|
-
private readonly tablePos: number;
|
79
|
-
private readonly isDelete: boolean;
|
80
|
-
private columnInfo: ColumnInfo;
|
81
|
-
private sideEffectsHandler: SideEffectsHandler;
|
82
|
-
|
83
|
-
constructor(
|
84
|
-
tablePos: number,
|
85
|
-
addColumnStepInfo: AddColumnStepInfo,
|
86
|
-
isDelete = false,
|
87
|
-
) {
|
88
|
-
super();
|
89
|
-
|
90
|
-
this.tablePos = tablePos;
|
91
|
-
this.isDelete = isDelete;
|
92
|
-
this.sideEffectsHandler = new SideEffectsHandler(
|
93
|
-
addColumnStepInfo.sideEffects,
|
94
|
-
);
|
95
|
-
this.columnInfo = createColumnInfo(addColumnStepInfo.cells);
|
96
|
-
}
|
97
|
-
|
98
|
-
/**
|
99
|
-
* Detect the column based on all the cells step in column info.
|
100
|
-
* Recreate columnInfo based on the current document. We might need to add new cells added by insert row or unmerge cells.
|
101
|
-
* If isDelete
|
102
|
-
* Decrease colspan if one row has merged cell
|
103
|
-
* Remove all the cells using columnInfo.cellStep[].from
|
104
|
-
* else
|
105
|
-
* Increase colspan if one row had merged cell
|
106
|
-
* Add all new cells at columnInfo.cellStep[].from,
|
107
|
-
* if there is columnInfo.cellStep[].newCell use it
|
108
|
-
* else create an empty cell
|
109
|
-
*
|
110
|
-
* @param doc Current document
|
111
|
-
*/
|
112
|
-
apply(doc: ProseMirrorNode): StepResult {
|
113
|
-
const { tablePos } = this;
|
114
|
-
// Create transform base on the doc
|
115
|
-
const tr = new Transform(doc);
|
116
|
-
|
117
|
-
if (this.sideEffectsHandler.table.handleAddTable(tr, this.isDelete)) {
|
118
|
-
return StepResult.ok(tr.doc);
|
119
|
-
}
|
120
|
-
|
121
|
-
let tableRect: TableRect | undefined;
|
122
|
-
try {
|
123
|
-
tableRect = getTableRectFromDoc(doc, tablePos);
|
124
|
-
} catch (e) {
|
125
|
-
return StepResult.fail((e as Error).message);
|
126
|
-
}
|
127
|
-
|
128
|
-
const column = findColumn(this.columnInfo, tableRect);
|
129
|
-
|
130
|
-
if (column === null) {
|
131
|
-
return StepResult.fail(
|
132
|
-
`No column for this cells "${printColumnInfo(
|
133
|
-
this.columnInfo,
|
134
|
-
)}" in table at position "${tablePos}".`,
|
135
|
-
);
|
136
|
-
}
|
137
|
-
|
138
|
-
if (
|
139
|
-
this.sideEffectsHandler.table.handleRemoveTable(
|
140
|
-
tr,
|
141
|
-
this.tablePos,
|
142
|
-
tableRect,
|
143
|
-
column,
|
144
|
-
this.isDelete,
|
145
|
-
)
|
146
|
-
) {
|
147
|
-
return StepResult.ok(tr.doc);
|
148
|
-
}
|
149
|
-
|
150
|
-
this.columnInfo = this.applyCellSteps(tr, tableRect, column, this.isDelete);
|
151
|
-
|
152
|
-
// Return the document modified.
|
153
|
-
return StepResult.ok(tr.doc);
|
154
|
-
}
|
155
|
-
|
156
|
-
/**
|
157
|
-
* Update tablePos with the new position. If tablePos doesnt exist any more remove the step
|
158
|
-
* Update all the cellStep inside columnInfo. If cellStep.from position gets deleted removed it from column info
|
159
|
-
* if cellStep.length === 0 remove the step
|
160
|
-
* Create a new step with all the position updated
|
161
|
-
* @param mapping
|
162
|
-
*/
|
163
|
-
map(mapping: Mappable): Step | null {
|
164
|
-
const tablePosResult = mapping.mapResult(this.tablePos);
|
165
|
-
if (tablePosResult.deleted) {
|
166
|
-
// If table was deleted remove the step
|
167
|
-
return null;
|
168
|
-
}
|
169
|
-
|
170
|
-
const cellSteps: CellStep[] = [];
|
171
|
-
for (const oldCellStep of this.columnInfo.values()) {
|
172
|
-
const fromResult = mapping.mapResult(oldCellStep.from);
|
173
|
-
const toResult = mapping.mapResult(oldCellStep.to);
|
174
|
-
if (fromResult.deleted && toResult.deleted) {
|
175
|
-
continue;
|
176
|
-
}
|
177
|
-
const cellStep: CellStep = {
|
178
|
-
...oldCellStep,
|
179
|
-
from: fromResult.pos,
|
180
|
-
to: toResult.pos,
|
181
|
-
};
|
182
|
-
|
183
|
-
if (oldCellStep.mergeWith !== undefined) {
|
184
|
-
cellStep.mergeWith = mapping.map(oldCellStep.mergeWith);
|
185
|
-
}
|
186
|
-
cellSteps.push(cellStep);
|
187
|
-
}
|
188
|
-
|
189
|
-
if (cellSteps.length === 0) {
|
190
|
-
return null;
|
191
|
-
}
|
192
|
-
|
193
|
-
const sideEffects = this.sideEffectsHandler.map(mapping);
|
194
|
-
|
195
|
-
return new AddColumnStep(
|
196
|
-
tablePosResult.pos,
|
197
|
-
{ cells: cellSteps, sideEffects },
|
198
|
-
this.isDelete,
|
199
|
-
);
|
200
|
-
}
|
201
|
-
|
202
|
-
/**
|
203
|
-
* if isDelete
|
204
|
-
* Get the original cell node at columnInfo.cellStep[].from to columnInfo.cellStep[].to
|
205
|
-
* Create a copy of the node
|
206
|
-
* Create a new cellStep with the same positions but with the clone node as a content
|
207
|
-
* return new step inverted
|
208
|
-
* else
|
209
|
-
* Remove the content from each columnInfo.cellStep[].content
|
210
|
-
* return new step inverted
|
211
|
-
* @param originalDoc
|
212
|
-
*/
|
213
|
-
invert(originalDoc: ProseMirrorNode): Step {
|
214
|
-
const stepMap = this.getMap();
|
215
|
-
|
216
|
-
// Memoize function to be called only on delete scenarios
|
217
|
-
const getTableRectAndColumn = getTableRectAndColumnFactory(
|
218
|
-
originalDoc,
|
219
|
-
this.tablePos,
|
220
|
-
this.columnInfo,
|
221
|
-
);
|
222
|
-
// This is needed because the real pos of the cell in the generated document is affected by the previous operations.
|
223
|
-
const newCellSteps: CellStep[] = Array.from(
|
224
|
-
this.columnInfo.values(),
|
225
|
-
(oldCellStep) => {
|
226
|
-
const newCellStep = invertCellStep(
|
227
|
-
originalDoc,
|
228
|
-
getTableRectAndColumn,
|
229
|
-
oldCellStep,
|
230
|
-
this.isDelete,
|
231
|
-
stepMap,
|
232
|
-
);
|
233
|
-
return newCellStep;
|
234
|
-
},
|
235
|
-
);
|
236
|
-
|
237
|
-
const sideEffects = this.sideEffectsHandler.invert(
|
238
|
-
originalDoc,
|
239
|
-
this.isDelete,
|
240
|
-
stepMap,
|
241
|
-
);
|
242
|
-
|
243
|
-
return new AddColumnStep(
|
244
|
-
this.tablePos,
|
245
|
-
{ cells: newCellSteps, sideEffects },
|
246
|
-
!this.isDelete,
|
247
|
-
);
|
248
|
-
}
|
249
|
-
|
250
|
-
/**
|
251
|
-
* StepMap is created based on columnInfo.
|
252
|
-
* ColumnInfo is created on constructor and once is applied (the document could have new cells that weren't part of the original set)
|
253
|
-
* if isDelete
|
254
|
-
* Create range array based on cell info where each range is [cellStep.from, cellStep.from - cellStep.to, 0]
|
255
|
-
* else
|
256
|
-
* Create range array base on cell info where each range is [cellStep.from, 0, cellStep.content ? cellStep.content.nodeSize : defaultEmptyCellNodeSize]
|
257
|
-
*
|
258
|
-
* Ranges in ProseMirror are represented by each 3 elements in an array.
|
259
|
-
* As [pos, currentSize, newSize, pos2, currentSize2, newSize2] where:
|
260
|
-
* pos: Position in the document
|
261
|
-
* currentSize: Represent the affected range, this will be pos + currentSize
|
262
|
-
* newSize: Represent the new values, pos + newSize
|
263
|
-
*/
|
264
|
-
getMap(): StepMap {
|
265
|
-
const tableMap = this.sideEffectsHandler.getTableMap(this.isDelete);
|
266
|
-
if (tableMap) {
|
267
|
-
return tableMap;
|
268
|
-
}
|
269
|
-
|
270
|
-
let ranges: number[] = [];
|
271
|
-
for (const cellStep of this.columnInfo.values()) {
|
272
|
-
ranges.push(...getMapFromCellStep(cellStep, this.isDelete));
|
273
|
-
}
|
274
|
-
|
275
|
-
ranges = this.sideEffectsHandler.rows.addRowRanges(ranges, this.isDelete);
|
276
|
-
|
277
|
-
// If no steps, I create am empty stepMap
|
278
|
-
return new StepMap(ranges);
|
279
|
-
}
|
280
|
-
|
281
|
-
/**
|
282
|
-
* Try to merge this step with another one, to be applied directly
|
283
|
-
* after it. Returns the merged step when possible, null if the
|
284
|
-
* steps can't be merged.
|
285
|
-
*/
|
286
|
-
merge(other: Step): Step | null {
|
287
|
-
// We cannot merge add column step at the moment
|
288
|
-
return null;
|
289
|
-
}
|
290
|
-
|
291
|
-
/**
|
292
|
-
* Create a JSON-serializeable representation of this step. When
|
293
|
-
* defining this for a custom subclass, make sure the result object
|
294
|
-
* includes the step type's [JSON id](#transform.Step^jsonID) under
|
295
|
-
* the `stepType` property.
|
296
|
-
*/
|
297
|
-
toJSON() {
|
298
|
-
const addColumnStepJson: AddColumnStepJson = {
|
299
|
-
stepType: ADD_COLUMN_STEP,
|
300
|
-
tablePos: this.tablePos,
|
301
|
-
cells: Array.from(this.columnInfo.values(), (cellStep) => {
|
302
|
-
const cellStepJson: CellStepJson = {
|
303
|
-
from: cellStep.from,
|
304
|
-
to: cellStep.to,
|
305
|
-
};
|
306
|
-
|
307
|
-
if (cellStep.mergeWith !== undefined) {
|
308
|
-
cellStepJson.mergeWith = cellStep.mergeWith;
|
309
|
-
}
|
310
|
-
|
311
|
-
if (cellStep.newCell !== undefined) {
|
312
|
-
cellStepJson.newCell = cellStep.newCell.toJSON();
|
313
|
-
}
|
314
|
-
return cellStepJson;
|
315
|
-
}),
|
316
|
-
isDelete: this.isDelete,
|
317
|
-
};
|
318
|
-
|
319
|
-
const sideEffectsJSON = this.sideEffectsHandler.toJSON();
|
320
|
-
if (sideEffectsJSON) {
|
321
|
-
addColumnStepJson.sideEffects = sideEffectsJSON;
|
322
|
-
}
|
323
|
-
|
324
|
-
return addColumnStepJson;
|
325
|
-
}
|
326
|
-
|
327
|
-
/**
|
328
|
-
* Deserialize a step from its JSON representation. Will call
|
329
|
-
* through to the step class' own implementation of this method.
|
330
|
-
*/
|
331
|
-
static fromJSON<S extends Schema = any>(
|
332
|
-
schema: S,
|
333
|
-
json: AddColumnStepJson,
|
334
|
-
): Step {
|
335
|
-
// TODO: Add validation. Return null if it is invalid. Check in review if this is necessary
|
336
|
-
const cells = json.cells.map((cellsJson) => {
|
337
|
-
const cell: CellStep = {
|
338
|
-
...cellsJson,
|
339
|
-
newCell: cellsJson.newCell
|
340
|
-
? schema.nodeFromJSON(cellsJson.newCell)
|
341
|
-
: undefined,
|
342
|
-
};
|
343
|
-
return cell;
|
344
|
-
});
|
345
|
-
|
346
|
-
let sideEffects: SideEffects | undefined;
|
347
|
-
if (json.sideEffects) {
|
348
|
-
sideEffects = SideEffectsHandler.fromJSON(schema, json.sideEffects);
|
349
|
-
}
|
350
|
-
|
351
|
-
return new AddColumnStep(
|
352
|
-
json.tablePos,
|
353
|
-
{ cells, sideEffects },
|
354
|
-
json.isDelete,
|
355
|
-
);
|
356
|
-
}
|
357
|
-
|
358
|
-
static create(
|
359
|
-
doc: ProseMirrorNode,
|
360
|
-
tablePos: number,
|
361
|
-
column: number,
|
362
|
-
isDelete = false,
|
363
|
-
) {
|
364
|
-
const tableRect = getTableRectFromDoc(doc, tablePos);
|
365
|
-
|
366
|
-
// By default add column will rely on default behaviour (add empty cell).
|
367
|
-
// There is no need to add content
|
368
|
-
const cells: CellStep[] = [];
|
369
|
-
const iter = cellsAtColumn(tableRect, column);
|
370
|
-
let next = iter.next();
|
371
|
-
while (!next.done) {
|
372
|
-
const cell: Cell = next.value as Cell;
|
373
|
-
cells.push(createCellStep(cell, column, isDelete));
|
374
|
-
|
375
|
-
let skipRows = 0;
|
376
|
-
if (cell.attrs && cell.attrs.rowspan) {
|
377
|
-
skipRows = cell.attrs.rowspan - 1;
|
378
|
-
}
|
379
|
-
|
380
|
-
next = iter.next(skipRows);
|
381
|
-
}
|
382
|
-
|
383
|
-
return new AddColumnStep(tablePos, { cells }, isDelete);
|
384
|
-
}
|
385
|
-
|
386
|
-
private applyCellSteps(
|
387
|
-
tr: Transform,
|
388
|
-
tableRect: TableRect,
|
389
|
-
column: number,
|
390
|
-
isDelete: boolean,
|
391
|
-
) {
|
392
|
-
const newColumnInfo: Map<number, CellStep> = new Map<number, CellStep>();
|
393
|
-
const rowsHandler = this.sideEffectsHandler.rows.start(this.isDelete);
|
394
|
-
|
395
|
-
const iter = cellsAtColumn(tableRect, column);
|
396
|
-
let next = iter.next();
|
397
|
-
// Iterate for all the cells in the current document
|
398
|
-
while (!next.done) {
|
399
|
-
const cell: Cell = next.value as Cell;
|
400
|
-
|
401
|
-
const previousCellStep = this.columnInfo.get(cell.from);
|
402
|
-
|
403
|
-
const newCellStep: CellStep = createCellStep(
|
404
|
-
cell,
|
405
|
-
column,
|
406
|
-
isDelete,
|
407
|
-
previousCellStep,
|
408
|
-
);
|
409
|
-
|
410
|
-
// If is the last cell in the row and doesnt have colspan I need to remove the whole row.
|
411
|
-
const removeRowResult = rowsHandler.handle(
|
412
|
-
tr,
|
413
|
-
tableRect,
|
414
|
-
cell.row,
|
415
|
-
column,
|
416
|
-
cell,
|
417
|
-
);
|
418
|
-
if (removeRowResult.handled) {
|
419
|
-
next = iter.next(removeRowResult.skipRows);
|
420
|
-
continue;
|
421
|
-
}
|
422
|
-
|
423
|
-
// Apply the step, to the pseudo document, get rows to skip, and the cellstep (might be modified, for example, a merge cell that remove the cell instead)
|
424
|
-
const { skipRows, cellStep } = applyCellStep(
|
425
|
-
tr,
|
426
|
-
tableRect,
|
427
|
-
cell,
|
428
|
-
newCellStep,
|
429
|
-
isDelete,
|
430
|
-
column,
|
431
|
-
);
|
432
|
-
|
433
|
-
// Store the new cell step. This could be an existing one or a new cell.
|
434
|
-
newColumnInfo.set(newCellStep.from, cellStep);
|
435
|
-
next = iter.next(skipRows);
|
436
|
-
}
|
437
|
-
|
438
|
-
rowsHandler.end(tr, tableRect, column);
|
439
|
-
return newColumnInfo;
|
440
|
-
}
|
441
|
-
}
|
442
|
-
|
443
|
-
Step.jsonID(ADD_COLUMN_STEP, AddColumnStep);
|
@@ -1,57 +0,0 @@
|
|
1
|
-
import { Node as PMNode, Slice } from '@atlaskit/editor-prosemirror/model';
|
2
|
-
import {
|
3
|
-
ReplaceStep,
|
4
|
-
Step,
|
5
|
-
StepMap,
|
6
|
-
StepResult,
|
7
|
-
} from '@atlaskit/editor-prosemirror/transform';
|
8
|
-
|
9
|
-
import { TableColumnOrdering } from './types';
|
10
|
-
|
11
|
-
export const tableSortingStepType = 'atlaskit-table-sorting-ordering';
|
12
|
-
|
13
|
-
export class TableSortStep extends Step {
|
14
|
-
prev: TableColumnOrdering | undefined;
|
15
|
-
next: TableColumnOrdering | undefined;
|
16
|
-
pos: number;
|
17
|
-
|
18
|
-
constructor(
|
19
|
-
pos: number,
|
20
|
-
prev?: TableColumnOrdering,
|
21
|
-
next?: TableColumnOrdering,
|
22
|
-
) {
|
23
|
-
super();
|
24
|
-
this.prev = prev;
|
25
|
-
this.next = next;
|
26
|
-
this.pos = pos;
|
27
|
-
}
|
28
|
-
|
29
|
-
invert() {
|
30
|
-
return new TableSortStep(this.pos, this.next, this.prev);
|
31
|
-
}
|
32
|
-
|
33
|
-
apply(doc: PMNode) {
|
34
|
-
return StepResult.ok(doc);
|
35
|
-
}
|
36
|
-
|
37
|
-
map(): null {
|
38
|
-
return null;
|
39
|
-
}
|
40
|
-
|
41
|
-
getMap() {
|
42
|
-
return new StepMap([0, 0, 0]);
|
43
|
-
}
|
44
|
-
|
45
|
-
toJSON() {
|
46
|
-
return {
|
47
|
-
stepType: tableSortingStepType,
|
48
|
-
};
|
49
|
-
}
|
50
|
-
|
51
|
-
static fromJSON() {
|
52
|
-
return new ReplaceStep(0, 0, Slice.empty);
|
53
|
-
}
|
54
|
-
}
|
55
|
-
|
56
|
-
/** Register this step with Prosemirror */
|
57
|
-
Step.jsonID(tableSortingStepType, TableSortStep);
|
package/src/steps/table/types.ts
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
import { Node as ProseMirrorNode } from '@atlaskit/editor-prosemirror/model';
|
2
|
-
import { SideEffects, SideEffectsJSON } from './utils/side-effects/types';
|
3
|
-
import { SortOrder } from './constants';
|
4
|
-
|
5
|
-
export type ColumnInfo = Map<number, CellStep>;
|
6
|
-
|
7
|
-
export interface AddColumnStepInfo {
|
8
|
-
cells: CellStep[];
|
9
|
-
sideEffects?: SideEffects;
|
10
|
-
}
|
11
|
-
|
12
|
-
/**
|
13
|
-
* Information about the cell
|
14
|
-
* from: where the cell will be added removed
|
15
|
-
* to: where the original cell ends
|
16
|
-
* newCell?: the content of the new cells if it's added
|
17
|
-
*/
|
18
|
-
export interface CellStep {
|
19
|
-
from: number; // beginning of cell at column
|
20
|
-
to: number; // end of cell at column
|
21
|
-
|
22
|
-
// Used to add a cell with a specific content. Useful for reverse a delete add column
|
23
|
-
newCell?: ProseMirrorNode;
|
24
|
-
|
25
|
-
mergeWith?: number; // Represent the cell that has to do the merge operation
|
26
|
-
}
|
27
|
-
|
28
|
-
export interface CellStepJson {
|
29
|
-
from: number;
|
30
|
-
to: number; // end of cell at column
|
31
|
-
|
32
|
-
// Used to add a cell with a specific content. Useful for reverse a delete add column
|
33
|
-
newCell?: { [key: string]: any }; // ToJson type of ProseMirrorNode.toJson()
|
34
|
-
mergeWith?: number; // Represent the cell that has to do the merge operation
|
35
|
-
}
|
36
|
-
|
37
|
-
export interface AddColumnStepJson {
|
38
|
-
stepType: 'ak-add-column';
|
39
|
-
tablePos: number;
|
40
|
-
cells: CellStepJson[];
|
41
|
-
sideEffects?: SideEffectsJSON;
|
42
|
-
isDelete: boolean;
|
43
|
-
}
|
44
|
-
|
45
|
-
export interface TableColumnOrdering {
|
46
|
-
columnIndex: number;
|
47
|
-
order: SortOrder;
|
48
|
-
}
|