@atlaskit/editor-plugin-table 42.3.8 → 42.4.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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 42.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`c8289f4e731b6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c8289f4e731b6) -
8
+ Keep sticky table header columns aligned when the row under the header has merged cells (behind
9
+ platform_editor_sticky_header_merged_row_width_exp)
10
+
11
+ ## 42.3.9
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies
16
+
3
17
  ## 42.3.8
4
18
 
5
19
  ### Patch Changes
package/compass.yml CHANGED
@@ -35,7 +35,7 @@ customFields:
35
35
  value: true
36
36
  - name: Reviewer Selection Mechanism
37
37
  type: text
38
- value: random(2)
38
+ value: randomTZIgnored(2)
39
39
  - name: Required Reviewer Approvals
40
40
  type: number
41
41
  value: 1
@@ -11,6 +11,7 @@ var _utils = require("@atlaskit/editor-prosemirror/utils");
11
11
  var _tableMap = require("@atlaskit/editor-tables/table-map");
12
12
  var _utils2 = require("@atlaskit/editor-tables/utils");
13
13
  var _getSelectionRect = require("@atlaskit/editor-tables/utils/get-selection-rect");
14
+ var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
14
15
  var _consts = require("../../ui/consts");
15
16
  var getColumnsWidths = exports.getColumnsWidths = function getColumnsWidths(view) {
16
17
  var selection = view.state.selection;
@@ -189,10 +190,43 @@ var getRelativeDomCellWidths = function getRelativeDomCellWidths(_ref) {
189
190
  return width * (cellColWidth / totalCalculatedCellWidth);
190
191
  });
191
192
  };
193
+ var splitCellWidthEvenly = function splitCellWidthEvenly(_ref2) {
194
+ var width = _ref2.width,
195
+ colspan = _ref2.colspan;
196
+ return new Array(colspan).fill(width / colspan);
197
+ };
198
+
199
+ /**
200
+ * Splits a merged cell by its `data-colwidth` ratios only when they describe every spanned column
201
+ * with a positive width. Missing or zero entries (null colwidths serialise as empty strings and
202
+ * padded ones as 0) would collapse or shift columns, so those cells are split evenly instead.
203
+ */
204
+ var splitCellWidthByValidColwidth = function splitCellWidthByValidColwidth(cell) {
205
+ var _cell$colwidth$split$, _cell$colwidth;
206
+ var colwidths = (_cell$colwidth$split$ = (_cell$colwidth = cell.colwidth) === null || _cell$colwidth === void 0 ? void 0 : _cell$colwidth.split(',').map(Number)) !== null && _cell$colwidth$split$ !== void 0 ? _cell$colwidth$split$ : [];
207
+ var isUsable = colwidths.length === cell.colspan && colwidths.every(function (colwidth) {
208
+ return Number.isFinite(colwidth) && colwidth > 0;
209
+ });
210
+ return isUsable ? getRelativeDomCellWidths(cell) : splitCellWidthEvenly(cell);
211
+ };
212
+
213
+ /**
214
+ * A merged cell spans several columns, so its width cannot tell the sticky header how wide each
215
+ * column is. Returns the first row from `startRow` onwards with exactly one cell per column. In a
216
+ * valid table such a row has no merged cells, and rows overlapped by a rowspan from above have
217
+ * fewer cells, so the cell count alone identifies it.
218
+ */
219
+ var findFirstRowWithOneCellPerColumn = function findFirstRowWithOneCellPerColumn(startRow, columnCount) {
220
+ var row = startRow;
221
+ while (row && row.childElementCount !== columnCount) {
222
+ row = row.nextElementSibling;
223
+ }
224
+ return row;
225
+ };
192
226
  var colWidthsForRow = exports.colWidthsForRow = function colWidthsForRow(tr) {
193
- var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
194
- _ref2$useColwidthRati = _ref2.useColwidthRatios,
195
- useColwidthRatios = _ref2$useColwidthRati === void 0 ? false : _ref2$useColwidthRati;
227
+ var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
228
+ _ref3$useColwidthRati = _ref3.useColwidthRatios,
229
+ useColwidthRatios = _ref3$useColwidthRati === void 0 ? false : _ref3$useColwidthRati;
196
230
  // get the colspans
197
231
  var rowColSpans = (0, _dom.maphElem)(tr, function (cell) {
198
232
  return Number(cell.getAttribute('colspan') || 1 /* default to span of 1 */);
@@ -206,7 +240,20 @@ var colWidthsForRow = exports.colWidthsForRow = function colWidthsForRow(tr) {
206
240
  //
207
241
  // prefer copying the widths via the DOM
208
242
  // or inferring from the next row if one exists
209
- var copyTarget = tr.nextElementSibling || tr;
243
+ var nextRow = tr.nextElementSibling;
244
+ var copyTarget = nextRow || tr;
245
+ var splitCellWidth = useColwidthRatios ? getRelativeDomCellWidths : splitCellWidthEvenly;
246
+ if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_sticky_header_merged_row_width_exp')) {
247
+ var columnCount = rowColSpans.reduce(function (acc, val) {
248
+ return acc + val;
249
+ }, 0);
250
+ var rowWithOneCellPerColumn = findFirstRowWithOneCellPerColumn(nextRow, columnCount);
251
+ if (rowWithOneCellPerColumn) {
252
+ copyTarget = rowWithOneCellPerColumn;
253
+ } else {
254
+ splitCellWidth = splitCellWidthByValidColwidth;
255
+ }
256
+ }
210
257
  if (copyTarget) {
211
258
  // either from the first row while it's still in the table
212
259
  var cellInfos = (0, _dom.maphElem)(copyTarget, function (cell) {
@@ -220,7 +267,7 @@ var colWidthsForRow = exports.colWidthsForRow = function colWidthsForRow(tr) {
220
267
  // reverse engineer cell widths from table widths
221
268
  var domBasedCellWidths = [];
222
269
  cellInfos.map(function (cell) {
223
- domBasedCellWidths.push.apply(domBasedCellWidths, (0, _toConsumableArray2.default)(useColwidthRatios ? getRelativeDomCellWidths(cell) : new Array(cell.colspan).fill(cell.width / cell.colspan)));
270
+ domBasedCellWidths.push.apply(domBasedCellWidths, (0, _toConsumableArray2.default)(splitCellWidth(cell)));
224
271
  });
225
272
  if (cellInfos.reduce(function (acc, cell) {
226
273
  return acc + cell.width;
@@ -1,4 +1,4 @@
1
- /* SortDecreasingItem.tsx generated by @compiled/babel-plugin v3.0.2 */
1
+ /* SortDecreasingItem.tsx generated by @compiled/babel-plugin v3.0.4 */
2
2
  "use strict";
3
3
 
4
4
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
@@ -1,4 +1,4 @@
1
- /* SortIncreasingItem.tsx generated by @compiled/babel-plugin v3.0.2 */
1
+ /* SortIncreasingItem.tsx generated by @compiled/babel-plugin v3.0.4 */
2
2
  "use strict";
3
3
 
4
4
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
@@ -1,4 +1,4 @@
1
- /* BackgroundColorItem.tsx generated by @compiled/babel-plugin v3.0.2 */
1
+ /* BackgroundColorItem.tsx generated by @compiled/babel-plugin v3.0.4 */
2
2
  "use strict";
3
3
 
4
4
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
@@ -3,6 +3,7 @@ import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
3
3
  import { TableMap } from '@atlaskit/editor-tables/table-map';
4
4
  import { findTable } from '@atlaskit/editor-tables/utils';
5
5
  import { getSelectionRect } from '@atlaskit/editor-tables/utils/get-selection-rect';
6
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
6
7
  import { tableDeleteButtonSize } from '../../ui/consts';
7
8
  export const getColumnsWidths = view => {
8
9
  const {
@@ -172,6 +173,36 @@ const getRelativeDomCellWidths = ({
172
173
  const totalCalculatedCellWidth = cellColWidths.reduce((acc, cellColWidth) => acc + cellColWidth, 0);
173
174
  return cellColWidths.map(cellColWidth => width * (cellColWidth / totalCalculatedCellWidth));
174
175
  };
176
+ const splitCellWidthEvenly = ({
177
+ width,
178
+ colspan
179
+ }) => new Array(colspan).fill(width / colspan);
180
+
181
+ /**
182
+ * Splits a merged cell by its `data-colwidth` ratios only when they describe every spanned column
183
+ * with a positive width. Missing or zero entries (null colwidths serialise as empty strings and
184
+ * padded ones as 0) would collapse or shift columns, so those cells are split evenly instead.
185
+ */
186
+ const splitCellWidthByValidColwidth = cell => {
187
+ var _cell$colwidth$split$, _cell$colwidth;
188
+ const colwidths = (_cell$colwidth$split$ = (_cell$colwidth = cell.colwidth) === null || _cell$colwidth === void 0 ? void 0 : _cell$colwidth.split(',').map(Number)) !== null && _cell$colwidth$split$ !== void 0 ? _cell$colwidth$split$ : [];
189
+ const isUsable = colwidths.length === cell.colspan && colwidths.every(colwidth => Number.isFinite(colwidth) && colwidth > 0);
190
+ return isUsable ? getRelativeDomCellWidths(cell) : splitCellWidthEvenly(cell);
191
+ };
192
+
193
+ /**
194
+ * A merged cell spans several columns, so its width cannot tell the sticky header how wide each
195
+ * column is. Returns the first row from `startRow` onwards with exactly one cell per column. In a
196
+ * valid table such a row has no merged cells, and rows overlapped by a rowspan from above have
197
+ * fewer cells, so the cell count alone identifies it.
198
+ */
199
+ const findFirstRowWithOneCellPerColumn = (startRow, columnCount) => {
200
+ let row = startRow;
201
+ while (row && row.childElementCount !== columnCount) {
202
+ row = row.nextElementSibling;
203
+ }
204
+ return row;
205
+ };
175
206
  export const colWidthsForRow = (tr, {
176
207
  useColwidthRatios = false
177
208
  } = {}) => {
@@ -186,7 +217,18 @@ export const colWidthsForRow = (tr, {
186
217
  //
187
218
  // prefer copying the widths via the DOM
188
219
  // or inferring from the next row if one exists
189
- const copyTarget = tr.nextElementSibling || tr;
220
+ const nextRow = tr.nextElementSibling;
221
+ let copyTarget = nextRow || tr;
222
+ let splitCellWidth = useColwidthRatios ? getRelativeDomCellWidths : splitCellWidthEvenly;
223
+ if (isExperimentEnabled('platform_editor_sticky_header_merged_row_width_exp')) {
224
+ const columnCount = rowColSpans.reduce((acc, val) => acc + val, 0);
225
+ const rowWithOneCellPerColumn = findFirstRowWithOneCellPerColumn(nextRow, columnCount);
226
+ if (rowWithOneCellPerColumn) {
227
+ copyTarget = rowWithOneCellPerColumn;
228
+ } else {
229
+ splitCellWidth = splitCellWidthByValidColwidth;
230
+ }
231
+ }
190
232
  if (copyTarget) {
191
233
  // either from the first row while it's still in the table
192
234
  const cellInfos = maphElem(copyTarget, cell => ({
@@ -198,7 +240,7 @@ export const colWidthsForRow = (tr, {
198
240
  // reverse engineer cell widths from table widths
199
241
  const domBasedCellWidths = [];
200
242
  cellInfos.map(cell => {
201
- domBasedCellWidths.push(...(useColwidthRatios ? getRelativeDomCellWidths(cell) : new Array(cell.colspan).fill(cell.width / cell.colspan)));
243
+ domBasedCellWidths.push(...splitCellWidth(cell));
202
244
  });
203
245
  if (cellInfos.reduce((acc, cell) => acc + cell.width, 0) !== 0) {
204
246
  const newWidths = mapTableColwidthsToRow(rowColSpans, domBasedCellWidths);
@@ -1,4 +1,4 @@
1
- /* SortDecreasingItem.tsx generated by @compiled/babel-plugin v3.0.2 */
1
+ /* SortDecreasingItem.tsx generated by @compiled/babel-plugin v3.0.4 */
2
2
  import _extends from "@babel/runtime/helpers/extends";
3
3
  import "./SortDecreasingItem.compiled.css";
4
4
  import { ax, ix } from "@compiled/react/runtime";
@@ -1,4 +1,4 @@
1
- /* SortIncreasingItem.tsx generated by @compiled/babel-plugin v3.0.2 */
1
+ /* SortIncreasingItem.tsx generated by @compiled/babel-plugin v3.0.4 */
2
2
  import _extends from "@babel/runtime/helpers/extends";
3
3
  import "./SortIncreasingItem.compiled.css";
4
4
  import { ax, ix } from "@compiled/react/runtime";
@@ -1,4 +1,4 @@
1
- /* BackgroundColorItem.tsx generated by @compiled/babel-plugin v3.0.2 */
1
+ /* BackgroundColorItem.tsx generated by @compiled/babel-plugin v3.0.4 */
2
2
  import "./BackgroundColorItem.compiled.css";
3
3
  import { ax, ix } from "@compiled/react/runtime";
4
4
  import React, { useCallback, useMemo } from 'react';
@@ -4,6 +4,7 @@ import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
4
4
  import { TableMap } from '@atlaskit/editor-tables/table-map';
5
5
  import { findTable } from '@atlaskit/editor-tables/utils';
6
6
  import { getSelectionRect } from '@atlaskit/editor-tables/utils/get-selection-rect';
7
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
7
8
  import { tableDeleteButtonSize } from '../../ui/consts';
8
9
  export var getColumnsWidths = function getColumnsWidths(view) {
9
10
  var selection = view.state.selection;
@@ -182,10 +183,43 @@ var getRelativeDomCellWidths = function getRelativeDomCellWidths(_ref) {
182
183
  return width * (cellColWidth / totalCalculatedCellWidth);
183
184
  });
184
185
  };
186
+ var splitCellWidthEvenly = function splitCellWidthEvenly(_ref2) {
187
+ var width = _ref2.width,
188
+ colspan = _ref2.colspan;
189
+ return new Array(colspan).fill(width / colspan);
190
+ };
191
+
192
+ /**
193
+ * Splits a merged cell by its `data-colwidth` ratios only when they describe every spanned column
194
+ * with a positive width. Missing or zero entries (null colwidths serialise as empty strings and
195
+ * padded ones as 0) would collapse or shift columns, so those cells are split evenly instead.
196
+ */
197
+ var splitCellWidthByValidColwidth = function splitCellWidthByValidColwidth(cell) {
198
+ var _cell$colwidth$split$, _cell$colwidth;
199
+ var colwidths = (_cell$colwidth$split$ = (_cell$colwidth = cell.colwidth) === null || _cell$colwidth === void 0 ? void 0 : _cell$colwidth.split(',').map(Number)) !== null && _cell$colwidth$split$ !== void 0 ? _cell$colwidth$split$ : [];
200
+ var isUsable = colwidths.length === cell.colspan && colwidths.every(function (colwidth) {
201
+ return Number.isFinite(colwidth) && colwidth > 0;
202
+ });
203
+ return isUsable ? getRelativeDomCellWidths(cell) : splitCellWidthEvenly(cell);
204
+ };
205
+
206
+ /**
207
+ * A merged cell spans several columns, so its width cannot tell the sticky header how wide each
208
+ * column is. Returns the first row from `startRow` onwards with exactly one cell per column. In a
209
+ * valid table such a row has no merged cells, and rows overlapped by a rowspan from above have
210
+ * fewer cells, so the cell count alone identifies it.
211
+ */
212
+ var findFirstRowWithOneCellPerColumn = function findFirstRowWithOneCellPerColumn(startRow, columnCount) {
213
+ var row = startRow;
214
+ while (row && row.childElementCount !== columnCount) {
215
+ row = row.nextElementSibling;
216
+ }
217
+ return row;
218
+ };
185
219
  export var colWidthsForRow = function colWidthsForRow(tr) {
186
- var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
187
- _ref2$useColwidthRati = _ref2.useColwidthRatios,
188
- useColwidthRatios = _ref2$useColwidthRati === void 0 ? false : _ref2$useColwidthRati;
220
+ var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
221
+ _ref3$useColwidthRati = _ref3.useColwidthRatios,
222
+ useColwidthRatios = _ref3$useColwidthRati === void 0 ? false : _ref3$useColwidthRati;
189
223
  // get the colspans
190
224
  var rowColSpans = maphElem(tr, function (cell) {
191
225
  return Number(cell.getAttribute('colspan') || 1 /* default to span of 1 */);
@@ -199,7 +233,20 @@ export var colWidthsForRow = function colWidthsForRow(tr) {
199
233
  //
200
234
  // prefer copying the widths via the DOM
201
235
  // or inferring from the next row if one exists
202
- var copyTarget = tr.nextElementSibling || tr;
236
+ var nextRow = tr.nextElementSibling;
237
+ var copyTarget = nextRow || tr;
238
+ var splitCellWidth = useColwidthRatios ? getRelativeDomCellWidths : splitCellWidthEvenly;
239
+ if (isExperimentEnabled('platform_editor_sticky_header_merged_row_width_exp')) {
240
+ var columnCount = rowColSpans.reduce(function (acc, val) {
241
+ return acc + val;
242
+ }, 0);
243
+ var rowWithOneCellPerColumn = findFirstRowWithOneCellPerColumn(nextRow, columnCount);
244
+ if (rowWithOneCellPerColumn) {
245
+ copyTarget = rowWithOneCellPerColumn;
246
+ } else {
247
+ splitCellWidth = splitCellWidthByValidColwidth;
248
+ }
249
+ }
203
250
  if (copyTarget) {
204
251
  // either from the first row while it's still in the table
205
252
  var cellInfos = maphElem(copyTarget, function (cell) {
@@ -213,7 +260,7 @@ export var colWidthsForRow = function colWidthsForRow(tr) {
213
260
  // reverse engineer cell widths from table widths
214
261
  var domBasedCellWidths = [];
215
262
  cellInfos.map(function (cell) {
216
- domBasedCellWidths.push.apply(domBasedCellWidths, _toConsumableArray(useColwidthRatios ? getRelativeDomCellWidths(cell) : new Array(cell.colspan).fill(cell.width / cell.colspan)));
263
+ domBasedCellWidths.push.apply(domBasedCellWidths, _toConsumableArray(splitCellWidth(cell)));
217
264
  });
218
265
  if (cellInfos.reduce(function (acc, cell) {
219
266
  return acc + cell.width;
@@ -1,4 +1,4 @@
1
- /* SortDecreasingItem.tsx generated by @compiled/babel-plugin v3.0.2 */
1
+ /* SortDecreasingItem.tsx generated by @compiled/babel-plugin v3.0.4 */
2
2
  import _extends from "@babel/runtime/helpers/extends";
3
3
  import "./SortDecreasingItem.compiled.css";
4
4
  import { ax, ix } from "@compiled/react/runtime";
@@ -1,4 +1,4 @@
1
- /* SortIncreasingItem.tsx generated by @compiled/babel-plugin v3.0.2 */
1
+ /* SortIncreasingItem.tsx generated by @compiled/babel-plugin v3.0.4 */
2
2
  import _extends from "@babel/runtime/helpers/extends";
3
3
  import "./SortIncreasingItem.compiled.css";
4
4
  import { ax, ix } from "@compiled/react/runtime";
@@ -1,4 +1,4 @@
1
- /* BackgroundColorItem.tsx generated by @compiled/babel-plugin v3.0.2 */
1
+ /* BackgroundColorItem.tsx generated by @compiled/babel-plugin v3.0.4 */
2
2
  import "./BackgroundColorItem.compiled.css";
3
3
  import { ax, ix } from "@compiled/react/runtime";
4
4
  import React, { useCallback, useMemo } from 'react';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "42.3.8",
3
+ "version": "42.4.0",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@atlaskit/adf-schema": "^57.7.0",
24
- "@atlaskit/button": "^25.7.0",
24
+ "@atlaskit/button": "^25.8.0",
25
25
  "@atlaskit/custom-steps": "^1.1.0",
26
26
  "@atlaskit/editor-palette": "^3.5.0",
27
27
  "@atlaskit/editor-plugin-accessibility-utils": "^30.0.0",
@@ -29,7 +29,7 @@
29
29
  "@atlaskit/editor-plugin-batch-attribute-updates": "^30.0.0",
30
30
  "@atlaskit/editor-plugin-content-insertion": "^30.0.0",
31
31
  "@atlaskit/editor-plugin-editor-viewmode": "^32.0.0",
32
- "@atlaskit/editor-plugin-extension": "33.0.17",
32
+ "@atlaskit/editor-plugin-extension": "33.0.18",
33
33
  "@atlaskit/editor-plugin-guideline": "^30.0.0",
34
34
  "@atlaskit/editor-plugin-interaction": "^44.0.0",
35
35
  "@atlaskit/editor-plugin-limited-mode": "^27.0.0",
@@ -53,9 +53,9 @@
53
53
  "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^3.2.0",
54
54
  "@atlaskit/pragmatic-drag-and-drop-hitbox": "^3.0.0",
55
55
  "@atlaskit/primitives": "^22.7.0",
56
- "@atlaskit/tmp-editor-statsig": "^260.0.0",
56
+ "@atlaskit/tmp-editor-statsig": "^261.0.0",
57
57
  "@atlaskit/toggle": "^17.3.0",
58
- "@atlaskit/tokens": "^20.10.0",
58
+ "@atlaskit/tokens": "^20.11.0",
59
59
  "@atlaskit/tooltip": "^24.4.0",
60
60
  "@babel/runtime": "^7.0.0",
61
61
  "@compiled/react": "^1.0.2",
@@ -68,7 +68,7 @@
68
68
  "uuid": "^11.1.1"
69
69
  },
70
70
  "peerDependencies": {
71
- "@atlaskit/editor-common": "^134.9.0",
71
+ "@atlaskit/editor-common": "^134.16.0",
72
72
  "react": "^18.2.0 || ^19.2.0",
73
73
  "react-dom": "^18.2.0 || ^19.2.0",
74
74
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
@@ -107,7 +107,7 @@
107
107
  }
108
108
  },
109
109
  "devDependencies": {
110
- "@atlaskit/editor-common": "^134.9.0",
110
+ "@atlaskit/editor-common": "^134.16.0",
111
111
  "react": "^19.2.0",
112
112
  "react-dom": "^19.2.0",
113
113
  "react-intl": "^7.0.0"