@atlaskit/editor-tables 2.2.1 → 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 CHANGED
@@ -1,5 +1,18 @@
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
+
9
+ ## 2.2.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [`47f1f76cb80`](https://bitbucket.org/atlassian/atlassian-frontend/commits/47f1f76cb80) - Add selectTableClosestToPos function
14
+ - [`755d7bf5c2a`](https://bitbucket.org/atlassian/atlassian-frontend/commits/755d7bf5c2a) - [ux] ED-12527 Prevents editor-tables handleMouseDown() from creating a cell selection when right clicking in a table cell.
15
+
3
16
  ## 2.2.1
4
17
 
5
18
  ### 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 start = this.$anchorCell.start(-1);
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
 
@@ -160,9 +160,10 @@ function handleTripleClick(view, pos) {
160
160
  }
161
161
 
162
162
  function handleMouseDown(view, event) {
163
- var startEvent = event;
163
+ var startEvent = event; // Prevent right clicks from making a cell selection https://product-fabric.atlassian.net/browse/ED-12527
164
164
 
165
- if (startEvent.ctrlKey || startEvent.metaKey) {
165
+ if (startEvent.ctrlKey || startEvent.metaKey || startEvent.button === 2 // right mouse click
166
+ ) {
166
167
  return false;
167
168
  }
168
169
 
@@ -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
 
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.selectTable = exports.selectRow = exports.selectColumn = void 0;
6
+ exports.selectTableClosestToPos = exports.selectTable = exports.selectRow = exports.selectColumn = void 0;
7
7
 
8
8
  var _cellSelection = require("../cell-selection");
9
9
 
@@ -101,4 +101,25 @@ var selectTable = function selectTable(tr) {
101
101
  return tr;
102
102
  };
103
103
 
104
- exports.selectTable = selectTable;
104
+ exports.selectTable = selectTable;
105
+
106
+ var selectTableClosestToPos = function selectTableClosestToPos(tr, $pos) {
107
+ var table = (0, _find.findTableClosestToPos)($pos);
108
+
109
+ if (table) {
110
+ var _TableMap$get2 = _tableMap.TableMap.get(table.node),
111
+ map = _TableMap$get2.map;
112
+
113
+ if (map && map.length) {
114
+ var head = table.start + map[0];
115
+ var anchor = table.start + map[map.length - 1];
116
+ var $head = tr.doc.resolve(head);
117
+ var $anchor = tr.doc.resolve(anchor);
118
+ return (0, _cloneTr.cloneTr)(tr.setSelection(new _cellSelection.CellSelection($anchor, $head)));
119
+ }
120
+ }
121
+
122
+ return tr;
123
+ };
124
+
125
+ exports.selectTableClosestToPos = selectTableClosestToPos;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-tables",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "sideEffects": false
5
5
  }
@@ -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
 
@@ -145,9 +145,10 @@ export function handleTripleClick(view, pos) {
145
145
  return true;
146
146
  }
147
147
  export function handleMouseDown(view, event) {
148
- const startEvent = event;
148
+ const startEvent = event; // Prevent right clicks from making a cell selection https://product-fabric.atlassian.net/browse/ED-12527
149
149
 
150
- if (startEvent.ctrlKey || startEvent.metaKey) {
150
+ if (startEvent.ctrlKey || startEvent.metaKey || startEvent.button === 2 // right mouse click
151
+ ) {
151
152
  return false;
152
153
  }
153
154
 
@@ -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
 
@@ -1,7 +1,7 @@
1
1
  import { CellSelection } from '../cell-selection';
2
2
  import { TableMap } from '../table-map';
3
3
  import { cloneTr } from './clone-tr';
4
- import { findCellClosestToPos, findTable } from './find';
4
+ import { findCellClosestToPos, findTable, findTableClosestToPos } from './find';
5
5
 
6
6
  const select = type => (index, expand) => tr => {
7
7
  const table = findTable(tr.selection);
@@ -81,5 +81,24 @@ export const selectTable = tr => {
81
81
  }
82
82
  }
83
83
 
84
+ return tr;
85
+ };
86
+ export const selectTableClosestToPos = (tr, $pos) => {
87
+ const table = findTableClosestToPos($pos);
88
+
89
+ if (table) {
90
+ const {
91
+ map
92
+ } = TableMap.get(table.node);
93
+
94
+ if (map && map.length) {
95
+ const head = table.start + map[0];
96
+ const anchor = table.start + map[map.length - 1];
97
+ const $head = tr.doc.resolve(head);
98
+ const $anchor = tr.doc.resolve(anchor);
99
+ return cloneTr(tr.setSelection(new CellSelection($anchor, $head)));
100
+ }
101
+ }
102
+
84
103
  return tr;
85
104
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-tables",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "sideEffects": false
5
5
  }
@@ -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
 
@@ -141,9 +141,10 @@ export function handleTripleClick(view, pos) {
141
141
  return true;
142
142
  }
143
143
  export function handleMouseDown(view, event) {
144
- var startEvent = event;
144
+ var startEvent = event; // Prevent right clicks from making a cell selection https://product-fabric.atlassian.net/browse/ED-12527
145
145
 
146
- if (startEvent.ctrlKey || startEvent.metaKey) {
146
+ if (startEvent.ctrlKey || startEvent.metaKey || startEvent.button === 2 // right mouse click
147
+ ) {
147
148
  return false;
148
149
  }
149
150
 
@@ -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
 
@@ -1,7 +1,7 @@
1
1
  import { CellSelection } from '../cell-selection';
2
2
  import { TableMap } from '../table-map';
3
3
  import { cloneTr } from './clone-tr';
4
- import { findCellClosestToPos, findTable } from './find';
4
+ import { findCellClosestToPos, findTable, findTableClosestToPos } from './find';
5
5
 
6
6
  var select = function select(type) {
7
7
  return function (index, expand) {
@@ -84,5 +84,23 @@ export var selectTable = function selectTable(tr) {
84
84
  }
85
85
  }
86
86
 
87
+ return tr;
88
+ };
89
+ export var selectTableClosestToPos = function selectTableClosestToPos(tr, $pos) {
90
+ var table = findTableClosestToPos($pos);
91
+
92
+ if (table) {
93
+ var _TableMap$get2 = TableMap.get(table.node),
94
+ map = _TableMap$get2.map;
95
+
96
+ if (map && map.length) {
97
+ var head = table.start + map[0];
98
+ var anchor = table.start + map[map.length - 1];
99
+ var $head = tr.doc.resolve(head);
100
+ var $anchor = tr.doc.resolve(anchor);
101
+ return cloneTr(tr.setSelection(new CellSelection($anchor, $head)));
102
+ }
103
+ }
104
+
87
105
  return tr;
88
106
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-tables",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "sideEffects": false
5
5
  }
@@ -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
  }
@@ -1,4 +1,6 @@
1
+ import { ResolvedPos } from 'prosemirror-model';
1
2
  import { Transaction } from 'prosemirror-state';
2
3
  export declare const selectColumn: (index: number, expand?: boolean | undefined) => (tr: Transaction) => Transaction;
3
4
  export declare const selectRow: (index: number, expand?: boolean | undefined) => (tr: Transaction) => Transaction;
4
5
  export declare const selectTable: (tr: Transaction) => Transaction;
6
+ export declare const selectTableClosestToPos: (tr: Transaction, $pos: ResolvedPos) => Transaction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-tables",
3
- "version": "2.2.1",
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": "^24.0.0",
33
- "@atlaskit/editor-test-helpers": "^17.2.0",
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,12 +1,17 @@
1
+ <!-- API Report Version: 2.3 -->
2
+
1
3
  ## API Report File for "@atlaskit/editor-tables"
2
4
 
3
- > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
5
+ > Do not edit this file. This report is auto-generated using [API Extractor](https://api-extractor.com/).
6
+ > [Learn more about API reports](https://hello.atlassian.net/wiki/spaces/UR/pages/1825484529/Package+API+Reports)
7
+
8
+ ### Table of contents
4
9
 
5
- <!--
6
- Generated API Report version: 2.0
7
- -->
10
+ - [Main Entry Types](#main-entry-types)
8
11
 
9
- [Learn more about API reports](https://hello.atlassian.net/wiki/spaces/UR/pages/1825484529/Package+API+Reports)
12
+ ### Main Entry Types
13
+
14
+ <!--SECTION START: Main Entry Types-->
10
15
 
11
16
  ```ts
12
17
  import { ContentNodeWithPos } from 'prosemirror-utils';
@@ -127,11 +132,15 @@ export class TableMap {
127
132
  // (undocumented)
128
133
  static get(table: Node_2): TableMap;
129
134
  // (undocumented)
135
+ getMaxColInRow(pos: ResolvedPos): number | undefined;
136
+ // (undocumented)
130
137
  height: number;
131
138
  // (undocumented)
139
+ isPosMerged(pos: number): boolean;
140
+ // (undocumented)
132
141
  map: number[];
133
142
  // (undocumented)
134
- nextCell(pos: number, axis: Axis, dir: number): number | null;
143
+ nextCell(pos: number, axis: Axis, dir: number): null | number;
135
144
  // (undocumented)
136
145
  positionAt(row: number, col: number, table: Node_2): number;
137
146
  // (undocumented)
@@ -139,15 +148,17 @@ export class TableMap {
139
148
  // (undocumented)
140
149
  rectBetween(a: number, b: number): Rect;
141
150
  // (undocumented)
151
+ rowCount(pos: number): number;
152
+ // (undocumented)
142
153
  width: number;
143
154
  }
144
155
 
145
156
  // @public (undocumented)
146
157
  type TableProblem =
158
+ | TableProblemColWidthMismatch
147
159
  | TableProblemCollision
148
160
  | TableProblemLongRowspan
149
- | TableProblemMissing
150
- | TableProblemColWidthMismatch;
161
+ | TableProblemMissing;
151
162
 
152
163
  // @public (undocumented)
153
164
  type TableProblemCollision = {
@@ -192,9 +203,11 @@ enum TableProblemTypes {
192
203
 
193
204
  // @public (undocumented)
194
205
  export const uuid: {
195
- setStatic(value: string | false): void;
206
+ setStatic(value: false | string): void;
196
207
  generate(): string;
197
208
  };
198
209
 
199
210
  // (No @packageDocumentation comment for this package)
200
211
  ```
212
+
213
+ <!--SECTION END: Main Entry Types-->