@atlaskit/editor-tables 2.2.2 → 2.2.3
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/dist/cjs/cell-selection.js +17 -1
- package/dist/cjs/table-map.js +32 -0
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/cell-selection.js +16 -1
- package/dist/es2019/table-map.js +27 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/cell-selection.js +16 -1
- package/dist/esm/table-map.js +32 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/table-map.d.ts +4 -1
- package/package.json +3 -3
- package/report.api.md +7 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaskit/editor-tables
|
|
2
2
|
|
|
3
|
+
## 2.2.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`dbef481f7df`](https://bitbucket.org/atlassian/atlassian-frontend/commits/dbef481f7df) - [ux] ED-15724: fix the merged row(2nd row or later) cannot been recongnized as row selection and cannot be deleted.
|
|
8
|
+
|
|
3
9
|
## 2.2.2
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -265,9 +265,25 @@ var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
265
265
|
return false;
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
var start = this.$anchorCell.start(-1);
|
|
269
|
+
|
|
268
270
|
var map = _tableMap.TableMap.get(this.$anchorCell.node(-1));
|
|
269
271
|
|
|
270
|
-
var
|
|
272
|
+
var rowAtAnchorCell = map.rowCount(this.$anchorCell.pos - start);
|
|
273
|
+
var rowAtHeadCell = map.rowCount(this.$headCell.pos - start);
|
|
274
|
+
var isSelectionSameRow = rowAtAnchorCell === rowAtHeadCell; // if anchor and head in the same line, counting how many cells
|
|
275
|
+
// should be in the row except merged cell
|
|
276
|
+
|
|
277
|
+
var maxColumnInSelectedRow = map.getMaxColInRow(this.$anchorCell); // if selected cells less than table max column amount, and
|
|
278
|
+
// the anchor/head not in a merged cell
|
|
279
|
+
// it should be select maxColumnInSelectedRow to be TRUE
|
|
280
|
+
|
|
281
|
+
if (isSelectionSameRow && this.ranges.length <= map.width && !map.isPosMerged(this.$anchorCell.pos - start) && !map.isPosMerged(this.$headCell.pos - start)) {
|
|
282
|
+
return this.ranges.length === maxColumnInSelectedRow;
|
|
283
|
+
} // If anchor and head in different row, it should be always in first and
|
|
284
|
+
// last column to select the whole row.
|
|
285
|
+
|
|
286
|
+
|
|
271
287
|
var anchorLeft = map.colCount(this.$anchorCell.pos - start);
|
|
272
288
|
var headLeft = map.colCount(this.$headCell.pos - start);
|
|
273
289
|
|
package/dist/cjs/table-map.js
CHANGED
|
@@ -143,6 +143,29 @@ var TableMap = /*#__PURE__*/function () {
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
throw new RangeError('No cell with offset ' + pos + ' found');
|
|
146
|
+
} // Find the top side of the cell at the given position.
|
|
147
|
+
|
|
148
|
+
}, {
|
|
149
|
+
key: "rowCount",
|
|
150
|
+
value: function rowCount(pos) {
|
|
151
|
+
if (this.width <= 0) {
|
|
152
|
+
throw new RangeError('Wrong table width found');
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
for (var i = 0; i < this.map.length; i++) {
|
|
156
|
+
if (this.map[i] === pos) {
|
|
157
|
+
return Math.floor(i / this.width);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
throw new RangeError('No cell with offset ' + pos + ' found');
|
|
162
|
+
}
|
|
163
|
+
}, {
|
|
164
|
+
key: "isPosMerged",
|
|
165
|
+
value: function isPosMerged(pos) {
|
|
166
|
+
return this.map.filter(function (cellPos) {
|
|
167
|
+
return cellPos === pos;
|
|
168
|
+
}).length > 1;
|
|
146
169
|
} // :: (number, string, number) → ?number
|
|
147
170
|
// Find the next cell in the given direction, starting from the cell
|
|
148
171
|
// at `pos`, if any.
|
|
@@ -239,6 +262,15 @@ var TableMap = /*#__PURE__*/function () {
|
|
|
239
262
|
|
|
240
263
|
rowStart = rowEnd;
|
|
241
264
|
}
|
|
265
|
+
}
|
|
266
|
+
}, {
|
|
267
|
+
key: "getMaxColInRow",
|
|
268
|
+
value: function getMaxColInRow(pos) {
|
|
269
|
+
var parentRowNode = pos.parent;
|
|
270
|
+
|
|
271
|
+
if (parentRowNode.type.name === 'tableRow') {
|
|
272
|
+
return parentRowNode.childCount;
|
|
273
|
+
}
|
|
242
274
|
} // :: (Node) → TableMap
|
|
243
275
|
// Find the table map for the given table node.
|
|
244
276
|
|
package/dist/cjs/version.json
CHANGED
|
@@ -245,8 +245,23 @@ export class CellSelection extends Selection {
|
|
|
245
245
|
return false;
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
-
const map = TableMap.get(this.$anchorCell.node(-1));
|
|
249
248
|
const start = this.$anchorCell.start(-1);
|
|
249
|
+
const map = TableMap.get(this.$anchorCell.node(-1));
|
|
250
|
+
const rowAtAnchorCell = map.rowCount(this.$anchorCell.pos - start);
|
|
251
|
+
const rowAtHeadCell = map.rowCount(this.$headCell.pos - start);
|
|
252
|
+
const isSelectionSameRow = rowAtAnchorCell === rowAtHeadCell; // if anchor and head in the same line, counting how many cells
|
|
253
|
+
// should be in the row except merged cell
|
|
254
|
+
|
|
255
|
+
let maxColumnInSelectedRow = map.getMaxColInRow(this.$anchorCell); // if selected cells less than table max column amount, and
|
|
256
|
+
// the anchor/head not in a merged cell
|
|
257
|
+
// it should be select maxColumnInSelectedRow to be TRUE
|
|
258
|
+
|
|
259
|
+
if (isSelectionSameRow && this.ranges.length <= map.width && !map.isPosMerged(this.$anchorCell.pos - start) && !map.isPosMerged(this.$headCell.pos - start)) {
|
|
260
|
+
return this.ranges.length === maxColumnInSelectedRow;
|
|
261
|
+
} // If anchor and head in different row, it should be always in first and
|
|
262
|
+
// last column to select the whole row.
|
|
263
|
+
|
|
264
|
+
|
|
250
265
|
const anchorLeft = map.colCount(this.$anchorCell.pos - start);
|
|
251
266
|
const headLeft = map.colCount(this.$headCell.pos - start);
|
|
252
267
|
|
package/dist/es2019/table-map.js
CHANGED
|
@@ -122,6 +122,25 @@ export class TableMap {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
throw new RangeError('No cell with offset ' + pos + ' found');
|
|
125
|
+
} // Find the top side of the cell at the given position.
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
rowCount(pos) {
|
|
129
|
+
if (this.width <= 0) {
|
|
130
|
+
throw new RangeError('Wrong table width found');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
for (let i = 0; i < this.map.length; i++) {
|
|
134
|
+
if (this.map[i] === pos) {
|
|
135
|
+
return Math.floor(i / this.width);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
throw new RangeError('No cell with offset ' + pos + ' found');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
isPosMerged(pos) {
|
|
143
|
+
return this.map.filter(cellPos => cellPos === pos).length > 1;
|
|
125
144
|
} // :: (number, string, number) → ?number
|
|
126
145
|
// Find the next cell in the given direction, starting from the cell
|
|
127
146
|
// at `pos`, if any.
|
|
@@ -215,6 +234,14 @@ export class TableMap {
|
|
|
215
234
|
|
|
216
235
|
rowStart = rowEnd;
|
|
217
236
|
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
getMaxColInRow(pos) {
|
|
240
|
+
let parentRowNode = pos.parent;
|
|
241
|
+
|
|
242
|
+
if (parentRowNode.type.name === 'tableRow') {
|
|
243
|
+
return parentRowNode.childCount;
|
|
244
|
+
}
|
|
218
245
|
} // :: (Node) → TableMap
|
|
219
246
|
// Find the table map for the given table node.
|
|
220
247
|
|
package/dist/es2019/version.json
CHANGED
|
@@ -246,8 +246,23 @@ export var CellSelection = /*#__PURE__*/function (_Selection) {
|
|
|
246
246
|
return false;
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
-
var map = TableMap.get(this.$anchorCell.node(-1));
|
|
250
249
|
var start = this.$anchorCell.start(-1);
|
|
250
|
+
var map = TableMap.get(this.$anchorCell.node(-1));
|
|
251
|
+
var rowAtAnchorCell = map.rowCount(this.$anchorCell.pos - start);
|
|
252
|
+
var rowAtHeadCell = map.rowCount(this.$headCell.pos - start);
|
|
253
|
+
var isSelectionSameRow = rowAtAnchorCell === rowAtHeadCell; // if anchor and head in the same line, counting how many cells
|
|
254
|
+
// should be in the row except merged cell
|
|
255
|
+
|
|
256
|
+
var maxColumnInSelectedRow = map.getMaxColInRow(this.$anchorCell); // if selected cells less than table max column amount, and
|
|
257
|
+
// the anchor/head not in a merged cell
|
|
258
|
+
// it should be select maxColumnInSelectedRow to be TRUE
|
|
259
|
+
|
|
260
|
+
if (isSelectionSameRow && this.ranges.length <= map.width && !map.isPosMerged(this.$anchorCell.pos - start) && !map.isPosMerged(this.$headCell.pos - start)) {
|
|
261
|
+
return this.ranges.length === maxColumnInSelectedRow;
|
|
262
|
+
} // If anchor and head in different row, it should be always in first and
|
|
263
|
+
// last column to select the whole row.
|
|
264
|
+
|
|
265
|
+
|
|
251
266
|
var anchorLeft = map.colCount(this.$anchorCell.pos - start);
|
|
252
267
|
var headLeft = map.colCount(this.$headCell.pos - start);
|
|
253
268
|
|
package/dist/esm/table-map.js
CHANGED
|
@@ -130,6 +130,29 @@ export var TableMap = /*#__PURE__*/function () {
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
throw new RangeError('No cell with offset ' + pos + ' found');
|
|
133
|
+
} // Find the top side of the cell at the given position.
|
|
134
|
+
|
|
135
|
+
}, {
|
|
136
|
+
key: "rowCount",
|
|
137
|
+
value: function rowCount(pos) {
|
|
138
|
+
if (this.width <= 0) {
|
|
139
|
+
throw new RangeError('Wrong table width found');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
for (var i = 0; i < this.map.length; i++) {
|
|
143
|
+
if (this.map[i] === pos) {
|
|
144
|
+
return Math.floor(i / this.width);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
throw new RangeError('No cell with offset ' + pos + ' found');
|
|
149
|
+
}
|
|
150
|
+
}, {
|
|
151
|
+
key: "isPosMerged",
|
|
152
|
+
value: function isPosMerged(pos) {
|
|
153
|
+
return this.map.filter(function (cellPos) {
|
|
154
|
+
return cellPos === pos;
|
|
155
|
+
}).length > 1;
|
|
133
156
|
} // :: (number, string, number) → ?number
|
|
134
157
|
// Find the next cell in the given direction, starting from the cell
|
|
135
158
|
// at `pos`, if any.
|
|
@@ -226,6 +249,15 @@ export var TableMap = /*#__PURE__*/function () {
|
|
|
226
249
|
|
|
227
250
|
rowStart = rowEnd;
|
|
228
251
|
}
|
|
252
|
+
}
|
|
253
|
+
}, {
|
|
254
|
+
key: "getMaxColInRow",
|
|
255
|
+
value: function getMaxColInRow(pos) {
|
|
256
|
+
var parentRowNode = pos.parent;
|
|
257
|
+
|
|
258
|
+
if (parentRowNode.type.name === 'tableRow') {
|
|
259
|
+
return parentRowNode.childCount;
|
|
260
|
+
}
|
|
229
261
|
} // :: (Node) → TableMap
|
|
230
262
|
// Find the table map for the given table node.
|
|
231
263
|
|
package/dist/esm/version.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Node as PMNode } from 'prosemirror-model';
|
|
1
|
+
import { Node as PMNode, ResolvedPos } from 'prosemirror-model';
|
|
2
2
|
import { Axis } from './types';
|
|
3
3
|
export declare class Rect {
|
|
4
4
|
left: number;
|
|
@@ -54,9 +54,12 @@ export declare class TableMap {
|
|
|
54
54
|
constructor(width: number, height: number, map: number[], problems?: TableProblem[] | null);
|
|
55
55
|
findCell(pos: number): Rect;
|
|
56
56
|
colCount(pos: number): number;
|
|
57
|
+
rowCount(pos: number): number;
|
|
58
|
+
isPosMerged(pos: number): boolean;
|
|
57
59
|
nextCell(pos: number, axis: Axis, dir: number): number | null;
|
|
58
60
|
rectBetween(a: number, b: number): Rect;
|
|
59
61
|
cellsInRect(rect: Rect): number[];
|
|
60
62
|
positionAt(row: number, col: number, table: PMNode): number;
|
|
63
|
+
getMaxColInRow(pos: ResolvedPos): number | undefined;
|
|
61
64
|
static get(table: PMNode): TableMap;
|
|
62
65
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-tables",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"description": "A package that contains common classes and utility functions for editor tables",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"prosemirror-view": "1.23.2"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@atlaskit/adf-schema": "^
|
|
33
|
-
"@atlaskit/editor-test-helpers": "^
|
|
32
|
+
"@atlaskit/adf-schema": "^25.0.0",
|
|
33
|
+
"@atlaskit/editor-test-helpers": "^18.0.0",
|
|
34
34
|
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1"
|
|
35
35
|
},
|
|
36
36
|
"techstack": {
|
package/report.api.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<!-- API Report Version: 2.
|
|
1
|
+
<!-- API Report Version: 2.3 -->
|
|
2
2
|
|
|
3
3
|
## API Report File for "@atlaskit/editor-tables"
|
|
4
4
|
|
|
@@ -132,8 +132,12 @@ export class TableMap {
|
|
|
132
132
|
// (undocumented)
|
|
133
133
|
static get(table: Node_2): TableMap;
|
|
134
134
|
// (undocumented)
|
|
135
|
+
getMaxColInRow(pos: ResolvedPos): number | undefined;
|
|
136
|
+
// (undocumented)
|
|
135
137
|
height: number;
|
|
136
138
|
// (undocumented)
|
|
139
|
+
isPosMerged(pos: number): boolean;
|
|
140
|
+
// (undocumented)
|
|
137
141
|
map: number[];
|
|
138
142
|
// (undocumented)
|
|
139
143
|
nextCell(pos: number, axis: Axis, dir: number): null | number;
|
|
@@ -144,6 +148,8 @@ export class TableMap {
|
|
|
144
148
|
// (undocumented)
|
|
145
149
|
rectBetween(a: number, b: number): Rect;
|
|
146
150
|
// (undocumented)
|
|
151
|
+
rowCount(pos: number): number;
|
|
152
|
+
// (undocumented)
|
|
147
153
|
width: number;
|
|
148
154
|
}
|
|
149
155
|
|