@atlaskit/adf-schema 28.1.12 → 28.2.0
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 +12 -0
- package/dist/types/index.d.ts +1 -1
- 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,327 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
Node as ProseMirrorNode,
|
3
|
-
Schema,
|
4
|
-
} from '@atlaskit/editor-prosemirror/model';
|
5
|
-
import {
|
6
|
-
Mappable,
|
7
|
-
StepMap,
|
8
|
-
Transform,
|
9
|
-
} from '@atlaskit/editor-prosemirror/transform';
|
10
|
-
import { TableRect } from '@atlaskit/editor-tables/table-map';
|
11
|
-
import { hasMergedColumns } from '../table-map';
|
12
|
-
import { RowSideEffect, RowSideEffectJSON } from './types';
|
13
|
-
import { Cell } from '../cells-at-column';
|
14
|
-
|
15
|
-
function mergedRanges(first: number[], second: number[]) {
|
16
|
-
const newRanges: number[] = [];
|
17
|
-
const firstLength = first.length;
|
18
|
-
const secondLength = second.length;
|
19
|
-
|
20
|
-
let i = 0;
|
21
|
-
let j = 0;
|
22
|
-
while (i < firstLength && j < secondLength) {
|
23
|
-
if (first[i] < second[j]) {
|
24
|
-
newRanges.push(first[i], first[i + 1], first[i + 2]);
|
25
|
-
i += 3;
|
26
|
-
} else {
|
27
|
-
newRanges.push(second[j], second[j + 1], second[j + 2]);
|
28
|
-
j += 3;
|
29
|
-
}
|
30
|
-
}
|
31
|
-
|
32
|
-
if (i < firstLength) {
|
33
|
-
newRanges.push(...first.slice(i));
|
34
|
-
}
|
35
|
-
if (j < secondLength) {
|
36
|
-
newRanges.push(...second.slice(i));
|
37
|
-
}
|
38
|
-
return newRanges;
|
39
|
-
}
|
40
|
-
|
41
|
-
function increaseRowSpan(tr: Transform, rect: TableRect, row: number): void {
|
42
|
-
const { map, tableStart } = rect;
|
43
|
-
for (let col = 0; col < map.width; col++) {
|
44
|
-
let index = row * map.width + col;
|
45
|
-
let pos = map.map[index];
|
46
|
-
const mappedPos = tr.mapping.map(pos + tableStart);
|
47
|
-
let attrs = tr.doc.nodeAt(mappedPos)!.attrs;
|
48
|
-
tr.setNodeMarkup(mappedPos, undefined, {
|
49
|
-
...attrs,
|
50
|
-
rowspan: attrs.rowspan + 1,
|
51
|
-
});
|
52
|
-
col += attrs.colspan - 1;
|
53
|
-
}
|
54
|
-
}
|
55
|
-
|
56
|
-
function decreaseRowspan(
|
57
|
-
tr: Transform,
|
58
|
-
rect: TableRect,
|
59
|
-
row: number,
|
60
|
-
colToRemove: number,
|
61
|
-
): number {
|
62
|
-
let skipRows = 0;
|
63
|
-
const { map, table, tableStart } = rect;
|
64
|
-
for (let col = 0; col < map.width; col++) {
|
65
|
-
let index = row * map.width + col;
|
66
|
-
let pos = map.map[index];
|
67
|
-
if (row > 0 && pos === map.map[index - map.width]) {
|
68
|
-
// If this cell starts in the row above, simply reduce its rowspan
|
69
|
-
const mappedPos = tr.mapping.map(pos + tableStart);
|
70
|
-
let attrs = tr.doc.nodeAt(mappedPos)!.attrs;
|
71
|
-
tr.setNodeMarkup(mappedPos, undefined, {
|
72
|
-
...attrs,
|
73
|
-
rowspan: attrs.rowspan - 1,
|
74
|
-
});
|
75
|
-
col += attrs.colspan - 1;
|
76
|
-
} else if (col === colToRemove) {
|
77
|
-
skipRows = table.nodeAt(pos)!.attrs.rowspan - 1;
|
78
|
-
}
|
79
|
-
}
|
80
|
-
return skipRows;
|
81
|
-
}
|
82
|
-
|
83
|
-
function isLastCellInRow(rect: TableRect, row: number, col: number): boolean {
|
84
|
-
const rowNode = rect.table.child(row);
|
85
|
-
if (!rowNode) {
|
86
|
-
return false;
|
87
|
-
}
|
88
|
-
return rowNode.childCount === 1 && !hasMergedColumns(rect.map, row, col);
|
89
|
-
}
|
90
|
-
|
91
|
-
interface RowsHandler {
|
92
|
-
handle: (
|
93
|
-
tr: Transform,
|
94
|
-
rect: TableRect,
|
95
|
-
row: number,
|
96
|
-
col: number,
|
97
|
-
cell: Cell,
|
98
|
-
) => {
|
99
|
-
handled: boolean;
|
100
|
-
skipRows?: number;
|
101
|
-
};
|
102
|
-
|
103
|
-
end: (tr: Transform, rect: TableRect, col: number) => void;
|
104
|
-
}
|
105
|
-
|
106
|
-
function removeRowWithLastCell(
|
107
|
-
tr: Transform,
|
108
|
-
rect: TableRect,
|
109
|
-
row: number,
|
110
|
-
_col: number,
|
111
|
-
): {
|
112
|
-
skipRows: number;
|
113
|
-
row: RowSideEffect;
|
114
|
-
} {
|
115
|
-
// Get row pos
|
116
|
-
let from = rect.tableStart;
|
117
|
-
for (let i = 0; i < row; i++) {
|
118
|
-
from += rect.table.child(i).nodeSize;
|
119
|
-
}
|
120
|
-
const rowNode = rect.table.child(row);
|
121
|
-
let to = from + rowNode.nodeSize;
|
122
|
-
|
123
|
-
// Create sideEffect and delete the row
|
124
|
-
// We store original row position before modifications
|
125
|
-
tr.delete(tr.mapping.map(from), tr.mapping.map(to));
|
126
|
-
|
127
|
-
// Change rowspan of all cells except current col and get the rows to skip
|
128
|
-
const skipRows = decreaseRowspan(tr, rect, row, _col);
|
129
|
-
|
130
|
-
return {
|
131
|
-
skipRows,
|
132
|
-
row: {
|
133
|
-
from,
|
134
|
-
to,
|
135
|
-
rowNode: rowNode.copy(rowNode.content),
|
136
|
-
},
|
137
|
-
};
|
138
|
-
}
|
139
|
-
|
140
|
-
function addRow(
|
141
|
-
tr: Transform,
|
142
|
-
rect: TableRect,
|
143
|
-
prevRow: number,
|
144
|
-
rowSideEffect: RowSideEffect,
|
145
|
-
): number {
|
146
|
-
const cellNode = rowSideEffect.rowNode.child(0);
|
147
|
-
|
148
|
-
tr.insert(tr.mapping.map(rowSideEffect.from), rowSideEffect.rowNode);
|
149
|
-
|
150
|
-
increaseRowSpan(tr, rect, prevRow);
|
151
|
-
return cellNode.attrs.rowspan - 1;
|
152
|
-
}
|
153
|
-
|
154
|
-
export class RowsSideEffectHandler {
|
155
|
-
public rows?: RowSideEffect[];
|
156
|
-
|
157
|
-
constructor(rowsSideEffect?: RowSideEffect[]) {
|
158
|
-
this.rows = rowsSideEffect;
|
159
|
-
}
|
160
|
-
|
161
|
-
private deleteHandler = (): RowsHandler => {
|
162
|
-
const newRows: RowSideEffect[] = [];
|
163
|
-
return {
|
164
|
-
handle: (tr, rect, row, col, cell) => {
|
165
|
-
if (!isLastCellInRow(rect, row, col)) {
|
166
|
-
return {
|
167
|
-
handled: false,
|
168
|
-
};
|
169
|
-
}
|
170
|
-
|
171
|
-
const { row: rowSideEffect, skipRows } = removeRowWithLastCell(
|
172
|
-
tr,
|
173
|
-
rect,
|
174
|
-
row,
|
175
|
-
col,
|
176
|
-
);
|
177
|
-
newRows.push(rowSideEffect);
|
178
|
-
|
179
|
-
return { handled: true, skipRows: skipRows };
|
180
|
-
},
|
181
|
-
end: () => {
|
182
|
-
if (newRows.length > 0) {
|
183
|
-
this.rows = newRows;
|
184
|
-
} else {
|
185
|
-
this.rows = undefined;
|
186
|
-
}
|
187
|
-
},
|
188
|
-
};
|
189
|
-
};
|
190
|
-
|
191
|
-
private addHandler = (): RowsHandler => {
|
192
|
-
let lastCellFrom = 0;
|
193
|
-
let i = 0;
|
194
|
-
|
195
|
-
return {
|
196
|
-
handle: (tr, rect, row, col, cell) => {
|
197
|
-
// // If not sideEffects stored return;
|
198
|
-
if (!this.rows || i >= this.rows.length) {
|
199
|
-
return { handled: false };
|
200
|
-
}
|
201
|
-
|
202
|
-
// Next row to add;
|
203
|
-
let skipRows: undefined | number;
|
204
|
-
let nextRow: RowSideEffect;
|
205
|
-
while (
|
206
|
-
(nextRow = this.rows[i]) &&
|
207
|
-
nextRow.from > lastCellFrom &&
|
208
|
-
nextRow.from < cell.from
|
209
|
-
) {
|
210
|
-
// I am in between of the previous and next row in the table;
|
211
|
-
skipRows = addRow(tr, rect, row - 1, nextRow);
|
212
|
-
i++;
|
213
|
-
}
|
214
|
-
lastCellFrom = cell.from;
|
215
|
-
if (!skipRows || skipRows === 0) {
|
216
|
-
return { handled: false };
|
217
|
-
}
|
218
|
-
|
219
|
-
return {
|
220
|
-
handled: true,
|
221
|
-
skipRows: skipRows - 1,
|
222
|
-
};
|
223
|
-
},
|
224
|
-
end: (tr, rect, col: number) => {
|
225
|
-
if (!this.rows || i >= this.rows.length) {
|
226
|
-
return;
|
227
|
-
}
|
228
|
-
|
229
|
-
// Add rows at the end of the table
|
230
|
-
let nextRow: RowSideEffect;
|
231
|
-
while ((nextRow = this.rows[i])) {
|
232
|
-
addRow(tr, rect, rect.map.height - 1, nextRow);
|
233
|
-
i++;
|
234
|
-
}
|
235
|
-
},
|
236
|
-
};
|
237
|
-
};
|
238
|
-
|
239
|
-
start(isDelete: boolean): RowsHandler {
|
240
|
-
if (isDelete) {
|
241
|
-
return this.deleteHandler();
|
242
|
-
}
|
243
|
-
|
244
|
-
return this.addHandler();
|
245
|
-
}
|
246
|
-
|
247
|
-
addRowRanges(ranges: number[], isDelete: boolean): number[] {
|
248
|
-
if (!this.rows) {
|
249
|
-
return ranges;
|
250
|
-
}
|
251
|
-
|
252
|
-
const rowRanges: number[] = [];
|
253
|
-
for (const row of this.rows) {
|
254
|
-
const { from, to } = row;
|
255
|
-
if (isDelete) {
|
256
|
-
rowRanges.push(from, to - from, 0);
|
257
|
-
} else {
|
258
|
-
rowRanges.push(from, 0, to - from);
|
259
|
-
}
|
260
|
-
}
|
261
|
-
|
262
|
-
// Merged ranges
|
263
|
-
return mergedRanges(ranges, rowRanges);
|
264
|
-
}
|
265
|
-
|
266
|
-
map(mapping: Mappable): RowSideEffect[] {
|
267
|
-
return [];
|
268
|
-
}
|
269
|
-
|
270
|
-
invert(
|
271
|
-
originalDoc: ProseMirrorNode,
|
272
|
-
isDelete: boolean,
|
273
|
-
map: StepMap,
|
274
|
-
): RowSideEffect[] | undefined {
|
275
|
-
if (!this.rows) {
|
276
|
-
return;
|
277
|
-
}
|
278
|
-
const invertedRows: RowSideEffect[] = [];
|
279
|
-
|
280
|
-
for (const row of this.rows) {
|
281
|
-
if (isDelete) {
|
282
|
-
// Moving from delete to add keep the inverted rows + offset
|
283
|
-
let offset = map.map(row.from) - row.from;
|
284
|
-
invertedRows.push({
|
285
|
-
...row,
|
286
|
-
from: row.from + offset,
|
287
|
-
to: row.from + offset,
|
288
|
-
});
|
289
|
-
} else {
|
290
|
-
// Moving from add to delete keep
|
291
|
-
// TODO: I think we need to add the respective cell into the cellSteps...... not sure....
|
292
|
-
}
|
293
|
-
}
|
294
|
-
return invertedRows;
|
295
|
-
}
|
296
|
-
|
297
|
-
toJSON(): RowSideEffectJSON[] | undefined {
|
298
|
-
if (!this.rows) {
|
299
|
-
return;
|
300
|
-
}
|
301
|
-
const rowsInJson: RowSideEffectJSON[] = [];
|
302
|
-
|
303
|
-
for (const row of this.rows) {
|
304
|
-
rowsInJson.push({
|
305
|
-
from: row.from,
|
306
|
-
to: row.to,
|
307
|
-
rowNode: row.rowNode.toJSON(),
|
308
|
-
});
|
309
|
-
}
|
310
|
-
|
311
|
-
return rowsInJson;
|
312
|
-
}
|
313
|
-
|
314
|
-
static fromJSON(schema: Schema, json: RowSideEffectJSON[]): RowSideEffect[] {
|
315
|
-
const rowSideEffects: RowSideEffect[] = [];
|
316
|
-
|
317
|
-
for (const row of json) {
|
318
|
-
rowSideEffects.push({
|
319
|
-
from: row.from,
|
320
|
-
to: row.to,
|
321
|
-
rowNode: schema.nodeFromJSON(row.rowNode),
|
322
|
-
});
|
323
|
-
}
|
324
|
-
|
325
|
-
return rowSideEffects;
|
326
|
-
}
|
327
|
-
}
|
@@ -1,90 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
Node as ProseMirrorNode,
|
3
|
-
Schema,
|
4
|
-
} from '@atlaskit/editor-prosemirror/model';
|
5
|
-
import { Mappable, StepMap } from '@atlaskit/editor-prosemirror/transform';
|
6
|
-
import { SideEffects, SideEffectsJSON } from './types';
|
7
|
-
import { TableSideEffectHandler } from './table';
|
8
|
-
import { RowsSideEffectHandler } from './rows';
|
9
|
-
|
10
|
-
export class SideEffectsHandler {
|
11
|
-
public table: TableSideEffectHandler;
|
12
|
-
public rows: RowsSideEffectHandler;
|
13
|
-
|
14
|
-
constructor(sideEffects?: SideEffects) {
|
15
|
-
this.table = new TableSideEffectHandler(sideEffects && sideEffects.table);
|
16
|
-
this.rows = new RowsSideEffectHandler(sideEffects && sideEffects.rows);
|
17
|
-
}
|
18
|
-
|
19
|
-
getTableMap(isDelete: boolean): StepMap | undefined {
|
20
|
-
return this.table.getTableMap(isDelete);
|
21
|
-
}
|
22
|
-
|
23
|
-
map(mapping: Mappable): SideEffects {
|
24
|
-
const sideEffects: SideEffects = {};
|
25
|
-
const tableSideEffect = this.table.map(mapping);
|
26
|
-
const rowsSideEffect = this.rows.map(mapping);
|
27
|
-
|
28
|
-
if (tableSideEffect) {
|
29
|
-
sideEffects.table = tableSideEffect;
|
30
|
-
}
|
31
|
-
|
32
|
-
if (rowsSideEffect) {
|
33
|
-
sideEffects.rows = rowsSideEffect;
|
34
|
-
}
|
35
|
-
return sideEffects;
|
36
|
-
}
|
37
|
-
|
38
|
-
invert(
|
39
|
-
originalDoc: ProseMirrorNode,
|
40
|
-
isDelete: boolean,
|
41
|
-
map: StepMap,
|
42
|
-
): SideEffects {
|
43
|
-
const sideEffects: SideEffects = {};
|
44
|
-
|
45
|
-
const tableSideEffect = this.table.invert(originalDoc);
|
46
|
-
if (tableSideEffect) {
|
47
|
-
sideEffects.table = tableSideEffect;
|
48
|
-
}
|
49
|
-
|
50
|
-
const rowsSideEffect = this.rows.invert(originalDoc, isDelete, map);
|
51
|
-
if (rowsSideEffect) {
|
52
|
-
sideEffects.rows = rowsSideEffect;
|
53
|
-
}
|
54
|
-
|
55
|
-
return sideEffects;
|
56
|
-
}
|
57
|
-
|
58
|
-
toJSON(): SideEffectsJSON | undefined {
|
59
|
-
const tableSideEffectJson = this.table.toJSON();
|
60
|
-
const rowsSideEffectJson = this.rows.toJSON();
|
61
|
-
|
62
|
-
if (!tableSideEffectJson && !rowsSideEffectJson) {
|
63
|
-
return;
|
64
|
-
}
|
65
|
-
|
66
|
-
const sideEffectsJSON: SideEffectsJSON = {};
|
67
|
-
if (tableSideEffectJson) {
|
68
|
-
sideEffectsJSON.table = tableSideEffectJson;
|
69
|
-
}
|
70
|
-
if (rowsSideEffectJson) {
|
71
|
-
sideEffectsJSON.rows = rowsSideEffectJson;
|
72
|
-
}
|
73
|
-
|
74
|
-
return sideEffectsJSON;
|
75
|
-
}
|
76
|
-
|
77
|
-
static fromJSON(schema: Schema, json: SideEffectsJSON): SideEffects {
|
78
|
-
const sideEffects: SideEffects = {};
|
79
|
-
|
80
|
-
if (json.table) {
|
81
|
-
sideEffects.table = TableSideEffectHandler.fromJSON(schema, json.table);
|
82
|
-
}
|
83
|
-
|
84
|
-
if (json.rows) {
|
85
|
-
sideEffects.rows = RowsSideEffectHandler.fromJSON(schema, json.rows);
|
86
|
-
}
|
87
|
-
|
88
|
-
return sideEffects;
|
89
|
-
}
|
90
|
-
}
|
@@ -1,112 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
Node as ProseMirrorNode,
|
3
|
-
Schema,
|
4
|
-
} from '@atlaskit/editor-prosemirror/model';
|
5
|
-
import {
|
6
|
-
Mappable,
|
7
|
-
StepMap,
|
8
|
-
Transform,
|
9
|
-
} from '@atlaskit/editor-prosemirror/transform';
|
10
|
-
import { TableRect } from '@atlaskit/editor-tables/table-map';
|
11
|
-
import { TableSideEffect, TableSideEffectJSON } from './types';
|
12
|
-
|
13
|
-
export class TableSideEffectHandler {
|
14
|
-
public table?: TableSideEffect;
|
15
|
-
|
16
|
-
constructor(tableSideEffect?: TableSideEffect) {
|
17
|
-
if (tableSideEffect) {
|
18
|
-
this.table = tableSideEffect;
|
19
|
-
}
|
20
|
-
}
|
21
|
-
|
22
|
-
private addTableSideEffect(from: number, to: number, node: ProseMirrorNode) {
|
23
|
-
this.table = { from, to, node };
|
24
|
-
}
|
25
|
-
|
26
|
-
handleAddTable(tr: Transform, isDelete: boolean): boolean {
|
27
|
-
if (isDelete || !this.table) {
|
28
|
-
return false;
|
29
|
-
}
|
30
|
-
|
31
|
-
tr.insert(this.table.from, this.table.node);
|
32
|
-
return true;
|
33
|
-
}
|
34
|
-
|
35
|
-
handleRemoveTable(
|
36
|
-
tr: Transform,
|
37
|
-
tablePos: number,
|
38
|
-
tableRect: TableRect,
|
39
|
-
column: number | null,
|
40
|
-
isDelete: boolean,
|
41
|
-
) {
|
42
|
-
if (isDelete && tableRect.map.width === 1 && column === 0) {
|
43
|
-
// Add side effect
|
44
|
-
this.addTableSideEffect(
|
45
|
-
tablePos,
|
46
|
-
tablePos + tableRect.table.nodeSize,
|
47
|
-
tableRect.table.copy(tableRect.table.content),
|
48
|
-
);
|
49
|
-
|
50
|
-
tr.delete(tablePos, tablePos + tableRect.table.nodeSize);
|
51
|
-
return true;
|
52
|
-
}
|
53
|
-
return false;
|
54
|
-
}
|
55
|
-
|
56
|
-
getTableMap(isDelete: boolean): StepMap | undefined {
|
57
|
-
if (!this.table) {
|
58
|
-
return;
|
59
|
-
}
|
60
|
-
const { from, to } = this.table;
|
61
|
-
if (isDelete) {
|
62
|
-
return new StepMap([from, to - from, 0]);
|
63
|
-
}
|
64
|
-
|
65
|
-
return new StepMap([from, 0, to - from]);
|
66
|
-
}
|
67
|
-
|
68
|
-
map(mapping: Mappable): TableSideEffect | undefined {
|
69
|
-
if (!this.table) {
|
70
|
-
return;
|
71
|
-
}
|
72
|
-
|
73
|
-
return {
|
74
|
-
from: mapping.map(this.table.from),
|
75
|
-
to: mapping.map(this.table.to),
|
76
|
-
node: this.table.node,
|
77
|
-
};
|
78
|
-
}
|
79
|
-
|
80
|
-
invert(doc: ProseMirrorNode): TableSideEffect | undefined {
|
81
|
-
if (!this.table) {
|
82
|
-
return;
|
83
|
-
}
|
84
|
-
const tableNode = doc.nodeAt(this.table.from)!;
|
85
|
-
|
86
|
-
return {
|
87
|
-
from: this.table.from,
|
88
|
-
to: this.table.from + tableNode.nodeSize,
|
89
|
-
node: tableNode.copy(tableNode.content),
|
90
|
-
};
|
91
|
-
}
|
92
|
-
|
93
|
-
toJSON(): TableSideEffectJSON | undefined {
|
94
|
-
if (!this.table) {
|
95
|
-
return;
|
96
|
-
}
|
97
|
-
|
98
|
-
return {
|
99
|
-
from: this.table.from,
|
100
|
-
to: this.table.to,
|
101
|
-
node: this.table.node.toJSON(),
|
102
|
-
};
|
103
|
-
}
|
104
|
-
|
105
|
-
static fromJSON(schema: Schema, json: TableSideEffectJSON): TableSideEffect {
|
106
|
-
return {
|
107
|
-
from: json.from,
|
108
|
-
to: json.to,
|
109
|
-
node: schema.nodeFromJSON(json.node),
|
110
|
-
};
|
111
|
-
}
|
112
|
-
}
|
@@ -1,34 +0,0 @@
|
|
1
|
-
import { Node as ProseMirrorNode } from '@atlaskit/editor-prosemirror/model';
|
2
|
-
|
3
|
-
export interface TableSideEffect {
|
4
|
-
from: number;
|
5
|
-
to: number;
|
6
|
-
node: ProseMirrorNode;
|
7
|
-
}
|
8
|
-
|
9
|
-
export interface RowSideEffect {
|
10
|
-
from: number;
|
11
|
-
to: number;
|
12
|
-
rowNode: ProseMirrorNode;
|
13
|
-
}
|
14
|
-
|
15
|
-
export interface TableSideEffectJSON {
|
16
|
-
from: number;
|
17
|
-
to: number;
|
18
|
-
node: { [key: string]: any }; // ToJson type of ProseMirrorNode.toJson()
|
19
|
-
}
|
20
|
-
|
21
|
-
export interface RowSideEffectJSON {
|
22
|
-
from: number;
|
23
|
-
to: number;
|
24
|
-
rowNode: { [key: string]: any }; // ToJson type of ProseMirrorNode.toJson()
|
25
|
-
}
|
26
|
-
|
27
|
-
export type SideEffects = {
|
28
|
-
table?: TableSideEffect;
|
29
|
-
rows?: RowSideEffect[];
|
30
|
-
};
|
31
|
-
export type SideEffectsJSON = {
|
32
|
-
table?: TableSideEffectJSON;
|
33
|
-
rows?: RowSideEffectJSON[];
|
34
|
-
};
|
@@ -1,28 +0,0 @@
|
|
1
|
-
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
2
|
-
|
3
|
-
export const getCellIndex = (map: TableMap, row: number, col: number) => {
|
4
|
-
return row * map.width + col;
|
5
|
-
};
|
6
|
-
|
7
|
-
export function hasMergedColumns(map: TableMap, row: number, col: number) {
|
8
|
-
const index = getCellIndex(map, row, col);
|
9
|
-
return (
|
10
|
-
(col > 0 && map.map[index - 1] === map.map[index]) ||
|
11
|
-
(col < map.width - 1 && map.map[index + 1] === map.map[index])
|
12
|
-
);
|
13
|
-
}
|
14
|
-
export function hasMergedRows(map: TableMap, row: number, col: number) {
|
15
|
-
const index = getCellIndex(map, row, col);
|
16
|
-
return (
|
17
|
-
(row > 0 && map.map[index - map.width] !== map.map[index]) ||
|
18
|
-
(row < map.height - 1 && map.map[index + map.width] === map.map[index])
|
19
|
-
);
|
20
|
-
}
|
21
|
-
export function isRootRow(map: TableMap, row: number, col: number) {
|
22
|
-
const index = getCellIndex(map, row, col);
|
23
|
-
return row > 0 ? map.map[index - map.width] !== map.map[index] : true;
|
24
|
-
}
|
25
|
-
export function isRootCol(map: TableMap, row: number, col: number) {
|
26
|
-
const index = getCellIndex(map, row, col);
|
27
|
-
return row > 0 ? map.map[index - 1] !== map.map[index] : true;
|
28
|
-
}
|
package/src/steps/type-ahead.ts
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
import { Node as PMNode, Slice } from '@atlaskit/editor-prosemirror/model';
|
2
|
-
import {
|
3
|
-
Mappable,
|
4
|
-
ReplaceStep,
|
5
|
-
Step,
|
6
|
-
StepMap,
|
7
|
-
StepResult,
|
8
|
-
} from '@atlaskit/editor-prosemirror/transform';
|
9
|
-
|
10
|
-
export const insertTypeAheadStepType = 'atlaskit-insert-type-ahead';
|
11
|
-
|
12
|
-
export enum InsertTypeAheadStages {
|
13
|
-
DELETING_RAW_QUERY = 'DELETING_RAW_QUERY',
|
14
|
-
INSERTING_ITEM = 'INSERTING_ITEM',
|
15
|
-
}
|
16
|
-
|
17
|
-
type Config = {
|
18
|
-
selectedIndex: number;
|
19
|
-
stage: InsertTypeAheadStages;
|
20
|
-
query: string;
|
21
|
-
trigger: string;
|
22
|
-
};
|
23
|
-
export class InsertTypeAheadStep extends Step {
|
24
|
-
private isInvertStep: boolean;
|
25
|
-
selectedIndex: number;
|
26
|
-
stage: InsertTypeAheadStages;
|
27
|
-
query: string;
|
28
|
-
trigger: string;
|
29
|
-
|
30
|
-
constructor(
|
31
|
-
{ stage, query, trigger, selectedIndex }: Config,
|
32
|
-
isInvertStep: boolean = false,
|
33
|
-
) {
|
34
|
-
super();
|
35
|
-
this.isInvertStep = isInvertStep;
|
36
|
-
this.stage = stage;
|
37
|
-
this.query = query;
|
38
|
-
this.trigger = trigger;
|
39
|
-
this.selectedIndex = selectedIndex;
|
40
|
-
}
|
41
|
-
|
42
|
-
invert() {
|
43
|
-
const config = {
|
44
|
-
stage: this.stage,
|
45
|
-
query: this.query,
|
46
|
-
trigger: this.trigger,
|
47
|
-
selectedIndex: this.selectedIndex,
|
48
|
-
};
|
49
|
-
return new InsertTypeAheadStep(config, !this.isInvertStep);
|
50
|
-
}
|
51
|
-
|
52
|
-
apply(doc: PMNode) {
|
53
|
-
return StepResult.ok(doc);
|
54
|
-
}
|
55
|
-
|
56
|
-
merge(): null {
|
57
|
-
return null;
|
58
|
-
}
|
59
|
-
|
60
|
-
isInsertionStep() {
|
61
|
-
return !this.isInvertStep;
|
62
|
-
}
|
63
|
-
|
64
|
-
isUndoingStep() {
|
65
|
-
return this.isInvertStep;
|
66
|
-
}
|
67
|
-
|
68
|
-
map(mapping: Mappable) {
|
69
|
-
const config = {
|
70
|
-
stage: this.stage,
|
71
|
-
query: this.query,
|
72
|
-
trigger: this.trigger,
|
73
|
-
selectedIndex: this.selectedIndex,
|
74
|
-
};
|
75
|
-
// Return the same events, this step will never be removed
|
76
|
-
return new InsertTypeAheadStep(config, this.isInvertStep);
|
77
|
-
}
|
78
|
-
|
79
|
-
getMap() {
|
80
|
-
return new StepMap([0, 0, 0]);
|
81
|
-
}
|
82
|
-
|
83
|
-
toJSON() {
|
84
|
-
// When serialized we should create a noop Replace step
|
85
|
-
return {
|
86
|
-
stepType: 'replace',
|
87
|
-
from: 0,
|
88
|
-
to: 0,
|
89
|
-
};
|
90
|
-
}
|
91
|
-
|
92
|
-
static fromJSON() {
|
93
|
-
// This is a "local custom step" once serialized
|
94
|
-
// we need to transform it in a no-operation action
|
95
|
-
return new ReplaceStep(0, 0, Slice.empty);
|
96
|
-
}
|
97
|
-
}
|
98
|
-
|
99
|
-
/** Register this step with Prosemirror */
|
100
|
-
Step.jsonID(insertTypeAheadStepType, InsertTypeAheadStep);
|
package/src/steps.ts
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
export { SortOrder as TableSortOrder } from './steps/table/constants';
|
2
|
-
export { TableSortStep } from './steps/table/sort-column';
|
3
|
-
export { InsertTypeAheadStages, InsertTypeAheadStep } from './steps/type-ahead';
|
4
|
-
export { AddColumnStep } from './steps/table/add-column';
|
5
|
-
export { SetAttrsStep } from './steps/set-attrs';
|
6
|
-
export { AnalyticsStep } from './steps/analytics';
|
7
|
-
export type { TableColumnOrdering } from './steps/table/types';
|
8
|
-
export type {
|
9
|
-
AnalyticsInvertStep,
|
10
|
-
AnalyticsWithChannel,
|
11
|
-
AnalyticsPayload,
|
12
|
-
} from './steps/analytics';
|
13
|
-
export { LinkMetaStep } from './steps/link-meta-step';
|
14
|
-
export type { LinkStepMetadata } from './steps/link-meta-step';
|
15
|
-
export { OverrideDocumentStep } from './steps/override-document-step';
|
16
|
-
export type { OverrideDocumentStepJSON } from './steps/override-document-step';
|