@atlaskit/editor-tables 2.3.16 → 2.3.18

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,17 @@
1
1
  # @atlaskit/editor-tables
2
2
 
3
+ ## 2.3.18
4
+
5
+ ### Patch Changes
6
+
7
+ - [#60278](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/60278) [`bc2785a02329`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/bc2785a02329) - Selection of multiple rows / column should remain when clicking the drag handle
8
+
9
+ ## 2.3.17
10
+
11
+ ### Patch Changes
12
+
13
+ - [#59009](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/59009) [`f7e9d874ff37`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/f7e9d874ff37) - Fix table expand selection when `platform.editor.table-shift-click-selection-backward` FF is enabled
14
+
3
15
  ## 2.3.16
4
16
 
5
17
  ### Patch Changes
@@ -0,0 +1,25 @@
1
+ {
2
+ "extends": "../../../../tsconfig.entry-points.confluence.json",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "target": "es5",
6
+ "composite": true,
7
+ "outDir": "../dist",
8
+ "rootDir": "../",
9
+ "baseUrl": "../"
10
+ },
11
+ "include": [
12
+ "../src/**/*.ts",
13
+ "../src/**/*.tsx"
14
+ ],
15
+ "exclude": [
16
+ "../src/**/__tests__/*",
17
+ "../src/**/*.test.*",
18
+ "../src/**/test.*"
19
+ ],
20
+ "references": [
21
+ {
22
+ "path": "../../../platform/feature-flags/afm-cc/tsconfig.json"
23
+ }
24
+ ]
25
+ }
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
- exports.selectTableClosestToPos = exports.selectTable = exports.selectRow = exports.selectColumn = void 0;
7
+ exports.selectTableClosestToPos = exports.selectTable = exports.selectRows = exports.selectRow = exports.selectColumns = exports.selectColumn = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
7
9
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
8
10
  var _cellSelection = require("../cell-selection");
9
11
  var _tableMap = require("../table-map");
@@ -48,7 +50,7 @@ var select = function select(type) {
48
50
  right: right,
49
51
  bottom: index + 1
50
52
  });
51
- var isBackwardSelection = targetRowCells[0] < prevSelection.$head.pos;
53
+ var isBackwardSelection = targetRowCells[0] < prevSelection.$head.pos - table.start;
52
54
  if (isBackwardSelection && isPrevRowSelection) {
53
55
  var _head = table.start + cellsInFirstRow[0];
54
56
  var _anchor = prevSelection.$anchorCell.pos;
@@ -73,7 +75,7 @@ var select = function select(type) {
73
75
  right: index + 1,
74
76
  bottom: bottom
75
77
  });
76
- var _isBackwardSelection = _targetRowCells[0] < prevSelection.$head.pos;
78
+ var _isBackwardSelection = _targetRowCells[0] < prevSelection.$head.pos - table.start;
77
79
  if (_isBackwardSelection && isPrevRowSelection) {
78
80
  var _head2 = table.start + cellsInFirstRow[0];
79
81
  var _anchor2 = prevSelection.$anchorCell.pos;
@@ -115,6 +117,43 @@ var selectColumn = exports.selectColumn = select('column');
115
117
  // Returns a new transaction that selects a row at index `rowIndex`.
116
118
  // Use the optional `expand` param to extend from current selection.
117
119
  var selectRow = exports.selectRow = select('row');
120
+ var selectRowsOrColumns = function selectRowsOrColumns(type) {
121
+ return function (indexes) {
122
+ return function (tr) {
123
+ var table = (0, _find.findTable)(tr.selection);
124
+ if (!table) {
125
+ return tr;
126
+ }
127
+ var map = _tableMap.TableMap.get(table.node);
128
+ if (!indexes || indexes.length <= 0 || type === 'rows' && Math.max.apply(Math, (0, _toConsumableArray2.default)(indexes)) > map.height || type === 'columns' && Math.max.apply(Math, (0, _toConsumableArray2.default)(indexes)) > map.width || Math.min.apply(Math, (0, _toConsumableArray2.default)(indexes)) < 0) {
129
+ return tr;
130
+ }
131
+ var startCellRect = map.cellsInRect({
132
+ left: type === 'rows' ? 0 : Math.min.apply(Math, (0, _toConsumableArray2.default)(indexes)),
133
+ top: type === 'rows' ? Math.min.apply(Math, (0, _toConsumableArray2.default)(indexes)) : 0,
134
+ right: type === 'rows' ? map.width : Math.min.apply(Math, (0, _toConsumableArray2.default)(indexes)) + 1,
135
+ bottom: type === 'rows' ? Math.min.apply(Math, (0, _toConsumableArray2.default)(indexes)) + 1 : 1
136
+ });
137
+ var endCellRect = map.cellsInRect({
138
+ left: type === 'rows' ? map.width - 1 : Math.max.apply(Math, (0, _toConsumableArray2.default)(indexes)),
139
+ top: type === 'rows' ? Math.max.apply(Math, (0, _toConsumableArray2.default)(indexes)) : map.height - 1,
140
+ right: type === 'rows' ? map.width : Math.max.apply(Math, (0, _toConsumableArray2.default)(indexes)) + 1,
141
+ bottom: type === 'rows' ? Math.max.apply(Math, (0, _toConsumableArray2.default)(indexes)) + 1 : map.height
142
+ });
143
+ var head = table.start + startCellRect[0];
144
+ var anchor = table.start + endCellRect[endCellRect.length - 1];
145
+ var $head = tr.doc.resolve(head);
146
+ var $anchor = tr.doc.resolve(anchor);
147
+ return (0, _cloneTr.cloneTr)(tr.setSelection(new _cellSelection.CellSelection($anchor, $head)));
148
+ };
149
+ };
150
+ };
151
+
152
+ // Returns a new transaction that selects all rows at `indexes`.
153
+ var selectRows = exports.selectRows = selectRowsOrColumns('rows');
154
+
155
+ // Returns a new transaction that selects all columns at `indexes`.
156
+ var selectColumns = exports.selectColumns = selectRowsOrColumns('columns');
118
157
 
119
158
  // Returns a new transaction that selects a table.
120
159
  var selectTable = exports.selectTable = function selectTable(tr) {
package/dist/cjs/utils.js CHANGED
@@ -333,12 +333,24 @@ Object.defineProperty(exports, "selectColumn", {
333
333
  return _selectNodes.selectColumn;
334
334
  }
335
335
  });
336
+ Object.defineProperty(exports, "selectColumns", {
337
+ enumerable: true,
338
+ get: function get() {
339
+ return _selectNodes.selectColumns;
340
+ }
341
+ });
336
342
  Object.defineProperty(exports, "selectRow", {
337
343
  enumerable: true,
338
344
  get: function get() {
339
345
  return _selectNodes.selectRow;
340
346
  }
341
347
  });
348
+ Object.defineProperty(exports, "selectRows", {
349
+ enumerable: true,
350
+ get: function get() {
351
+ return _selectNodes.selectRows;
352
+ }
353
+ });
342
354
  Object.defineProperty(exports, "selectTable", {
343
355
  enumerable: true,
344
356
  get: function get() {
@@ -40,7 +40,7 @@ const select = type => (index, expand) => tr => {
40
40
  right,
41
41
  bottom: index + 1
42
42
  });
43
- const isBackwardSelection = targetRowCells[0] < prevSelection.$head.pos;
43
+ const isBackwardSelection = targetRowCells[0] < prevSelection.$head.pos - table.start;
44
44
  if (isBackwardSelection && isPrevRowSelection) {
45
45
  const head = table.start + cellsInFirstRow[0];
46
46
  const anchor = prevSelection.$anchorCell.pos;
@@ -65,7 +65,7 @@ const select = type => (index, expand) => tr => {
65
65
  right: index + 1,
66
66
  bottom
67
67
  });
68
- const isBackwardSelection = targetRowCells[0] < prevSelection.$head.pos;
68
+ const isBackwardSelection = targetRowCells[0] < prevSelection.$head.pos - table.start;
69
69
  if (isBackwardSelection && isPrevRowSelection) {
70
70
  const head = table.start + cellsInFirstRow[0];
71
71
  const anchor = prevSelection.$anchorCell.pos;
@@ -105,6 +105,39 @@ export const selectColumn = select('column');
105
105
  // Returns a new transaction that selects a row at index `rowIndex`.
106
106
  // Use the optional `expand` param to extend from current selection.
107
107
  export const selectRow = select('row');
108
+ const selectRowsOrColumns = type => indexes => tr => {
109
+ const table = findTable(tr.selection);
110
+ if (!table) {
111
+ return tr;
112
+ }
113
+ const map = TableMap.get(table.node);
114
+ if (!indexes || indexes.length <= 0 || type === 'rows' && Math.max(...indexes) > map.height || type === 'columns' && Math.max(...indexes) > map.width || Math.min(...indexes) < 0) {
115
+ return tr;
116
+ }
117
+ const startCellRect = map.cellsInRect({
118
+ left: type === 'rows' ? 0 : Math.min(...indexes),
119
+ top: type === 'rows' ? Math.min(...indexes) : 0,
120
+ right: type === 'rows' ? map.width : Math.min(...indexes) + 1,
121
+ bottom: type === 'rows' ? Math.min(...indexes) + 1 : 1
122
+ });
123
+ const endCellRect = map.cellsInRect({
124
+ left: type === 'rows' ? map.width - 1 : Math.max(...indexes),
125
+ top: type === 'rows' ? Math.max(...indexes) : map.height - 1,
126
+ right: type === 'rows' ? map.width : Math.max(...indexes) + 1,
127
+ bottom: type === 'rows' ? Math.max(...indexes) + 1 : map.height
128
+ });
129
+ const head = table.start + startCellRect[0];
130
+ const anchor = table.start + endCellRect[endCellRect.length - 1];
131
+ const $head = tr.doc.resolve(head);
132
+ const $anchor = tr.doc.resolve(anchor);
133
+ return cloneTr(tr.setSelection(new CellSelection($anchor, $head)));
134
+ };
135
+
136
+ // Returns a new transaction that selects all rows at `indexes`.
137
+ export const selectRows = selectRowsOrColumns('rows');
138
+
139
+ // Returns a new transaction that selects all columns at `indexes`.
140
+ export const selectColumns = selectRowsOrColumns('columns');
108
141
 
109
142
  // Returns a new transaction that selects a table.
110
143
  export const selectTable = tr => {
@@ -27,7 +27,7 @@ export { normalizeSelection } from './utils/normalize-selection';
27
27
  export { removeColumnAt, removeSelectedColumns, removeColumnClosestToPos } from './utils/remove-column';
28
28
  export { removeRowAt, removeSelectedRows, removeRowClosestToPos } from './utils/remove-row';
29
29
  export { removeTable } from './utils/remove-table';
30
- export { selectColumn, selectRow, selectTable } from './utils/select-nodes';
30
+ export { selectColumn, selectColumns, selectRow, selectRows, selectTable } from './utils/select-nodes';
31
31
  export { selectionCell } from './utils/selection-cell';
32
32
  export { selectedRect } from './utils/selection-rect';
33
33
  export { setCellAttrs } from './utils/set-cell-attrs';
@@ -1,3 +1,4 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
1
2
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
2
3
  import { CellSelection } from '../cell-selection';
3
4
  import { TableMap } from '../table-map';
@@ -42,7 +43,7 @@ var select = function select(type) {
42
43
  right: right,
43
44
  bottom: index + 1
44
45
  });
45
- var isBackwardSelection = targetRowCells[0] < prevSelection.$head.pos;
46
+ var isBackwardSelection = targetRowCells[0] < prevSelection.$head.pos - table.start;
46
47
  if (isBackwardSelection && isPrevRowSelection) {
47
48
  var _head = table.start + cellsInFirstRow[0];
48
49
  var _anchor = prevSelection.$anchorCell.pos;
@@ -67,7 +68,7 @@ var select = function select(type) {
67
68
  right: index + 1,
68
69
  bottom: bottom
69
70
  });
70
- var _isBackwardSelection = _targetRowCells[0] < prevSelection.$head.pos;
71
+ var _isBackwardSelection = _targetRowCells[0] < prevSelection.$head.pos - table.start;
71
72
  if (_isBackwardSelection && isPrevRowSelection) {
72
73
  var _head2 = table.start + cellsInFirstRow[0];
73
74
  var _anchor2 = prevSelection.$anchorCell.pos;
@@ -109,6 +110,43 @@ export var selectColumn = select('column');
109
110
  // Returns a new transaction that selects a row at index `rowIndex`.
110
111
  // Use the optional `expand` param to extend from current selection.
111
112
  export var selectRow = select('row');
113
+ var selectRowsOrColumns = function selectRowsOrColumns(type) {
114
+ return function (indexes) {
115
+ return function (tr) {
116
+ var table = findTable(tr.selection);
117
+ if (!table) {
118
+ return tr;
119
+ }
120
+ var map = TableMap.get(table.node);
121
+ if (!indexes || indexes.length <= 0 || type === 'rows' && Math.max.apply(Math, _toConsumableArray(indexes)) > map.height || type === 'columns' && Math.max.apply(Math, _toConsumableArray(indexes)) > map.width || Math.min.apply(Math, _toConsumableArray(indexes)) < 0) {
122
+ return tr;
123
+ }
124
+ var startCellRect = map.cellsInRect({
125
+ left: type === 'rows' ? 0 : Math.min.apply(Math, _toConsumableArray(indexes)),
126
+ top: type === 'rows' ? Math.min.apply(Math, _toConsumableArray(indexes)) : 0,
127
+ right: type === 'rows' ? map.width : Math.min.apply(Math, _toConsumableArray(indexes)) + 1,
128
+ bottom: type === 'rows' ? Math.min.apply(Math, _toConsumableArray(indexes)) + 1 : 1
129
+ });
130
+ var endCellRect = map.cellsInRect({
131
+ left: type === 'rows' ? map.width - 1 : Math.max.apply(Math, _toConsumableArray(indexes)),
132
+ top: type === 'rows' ? Math.max.apply(Math, _toConsumableArray(indexes)) : map.height - 1,
133
+ right: type === 'rows' ? map.width : Math.max.apply(Math, _toConsumableArray(indexes)) + 1,
134
+ bottom: type === 'rows' ? Math.max.apply(Math, _toConsumableArray(indexes)) + 1 : map.height
135
+ });
136
+ var head = table.start + startCellRect[0];
137
+ var anchor = table.start + endCellRect[endCellRect.length - 1];
138
+ var $head = tr.doc.resolve(head);
139
+ var $anchor = tr.doc.resolve(anchor);
140
+ return cloneTr(tr.setSelection(new CellSelection($anchor, $head)));
141
+ };
142
+ };
143
+ };
144
+
145
+ // Returns a new transaction that selects all rows at `indexes`.
146
+ export var selectRows = selectRowsOrColumns('rows');
147
+
148
+ // Returns a new transaction that selects all columns at `indexes`.
149
+ export var selectColumns = selectRowsOrColumns('columns');
112
150
 
113
151
  // Returns a new transaction that selects a table.
114
152
  export var selectTable = function selectTable(tr) {
package/dist/esm/utils.js CHANGED
@@ -27,7 +27,7 @@ export { normalizeSelection } from './utils/normalize-selection';
27
27
  export { removeColumnAt, removeSelectedColumns, removeColumnClosestToPos } from './utils/remove-column';
28
28
  export { removeRowAt, removeSelectedRows, removeRowClosestToPos } from './utils/remove-row';
29
29
  export { removeTable } from './utils/remove-table';
30
- export { selectColumn, selectRow, selectTable } from './utils/select-nodes';
30
+ export { selectColumn, selectColumns, selectRow, selectRows, selectTable } from './utils/select-nodes';
31
31
  export { selectionCell } from './utils/selection-cell';
32
32
  export { selectedRect } from './utils/selection-rect';
33
33
  export { setCellAttrs } from './utils/set-cell-attrs';
@@ -2,5 +2,7 @@ import type { ResolvedPos } from '@atlaskit/editor-prosemirror/model';
2
2
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
3
3
  export declare const selectColumn: (index: number, expand?: boolean) => (tr: Transaction) => Transaction;
4
4
  export declare const selectRow: (index: number, expand?: boolean) => (tr: Transaction) => Transaction;
5
+ export declare const selectRows: (indexes: number[]) => (tr: Transaction) => Transaction;
6
+ export declare const selectColumns: (indexes: number[]) => (tr: Transaction) => Transaction;
5
7
  export declare const selectTable: (tr: Transaction) => Transaction;
6
8
  export declare const selectTableClosestToPos: (tr: Transaction, $pos: ResolvedPos) => Transaction;
@@ -27,7 +27,7 @@ export { normalizeSelection } from './utils/normalize-selection';
27
27
  export { removeColumnAt, removeSelectedColumns, removeColumnClosestToPos, } from './utils/remove-column';
28
28
  export { removeRowAt, removeSelectedRows, removeRowClosestToPos, } from './utils/remove-row';
29
29
  export { removeTable } from './utils/remove-table';
30
- export { selectColumn, selectRow, selectTable } from './utils/select-nodes';
30
+ export { selectColumn, selectColumns, selectRow, selectRows, selectTable, } from './utils/select-nodes';
31
31
  export { selectionCell } from './utils/selection-cell';
32
32
  export { selectedRect } from './utils/selection-rect';
33
33
  export type { SelectionRect } from './utils/selection-rect';
@@ -2,5 +2,7 @@ import type { ResolvedPos } from '@atlaskit/editor-prosemirror/model';
2
2
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
3
3
  export declare const selectColumn: (index: number, expand?: boolean) => (tr: Transaction) => Transaction;
4
4
  export declare const selectRow: (index: number, expand?: boolean) => (tr: Transaction) => Transaction;
5
+ export declare const selectRows: (indexes: number[]) => (tr: Transaction) => Transaction;
6
+ export declare const selectColumns: (indexes: number[]) => (tr: Transaction) => Transaction;
5
7
  export declare const selectTable: (tr: Transaction) => Transaction;
6
8
  export declare const selectTableClosestToPos: (tr: Transaction, $pos: ResolvedPos) => Transaction;
@@ -27,7 +27,7 @@ export { normalizeSelection } from './utils/normalize-selection';
27
27
  export { removeColumnAt, removeSelectedColumns, removeColumnClosestToPos, } from './utils/remove-column';
28
28
  export { removeRowAt, removeSelectedRows, removeRowClosestToPos, } from './utils/remove-row';
29
29
  export { removeTable } from './utils/remove-table';
30
- export { selectColumn, selectRow, selectTable } from './utils/select-nodes';
30
+ export { selectColumn, selectColumns, selectRow, selectRows, selectTable, } from './utils/select-nodes';
31
31
  export { selectionCell } from './utils/selection-cell';
32
32
  export { selectedRect } from './utils/selection-rect';
33
33
  export type { SelectionRect } from './utils/selection-rect';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-tables",
3
- "version": "2.3.16",
3
+ "version": "2.3.18",
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/"