@atlaskit/editor-plugin-show-diff 10.6.0 → 10.6.2

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-show-diff
2
2
 
3
+ ## 10.6.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 10.6.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [`963920819d38c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/963920819d38c) -
14
+ Fix rounded table diff overlays for whole-table widgets.
15
+ - Updated dependencies
16
+
3
17
  ## 10.6.0
4
18
 
5
19
  ### Minor Changes
@@ -17,60 +17,20 @@ var _standard = require("./colorSchemes/standard");
17
17
  var _traditional = require("./colorSchemes/traditional");
18
18
  var _decorationKeys = require("./decorationKeys");
19
19
  var _findSafeInsertPos = require("./utils/findSafeInsertPos");
20
+ var _tableCellEdgeAttrs = require("./utils/tableCellEdgeAttrs");
20
21
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
21
22
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
22
23
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
23
24
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
24
25
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
25
- /**
26
- * Inserted table rows are rendered as decoration widgets, so their cells do not get the
27
- * `data-reaches-*` attrs normally applied by the table cell node view. Mirror that boundary
28
- * metadata here so the existing rounded-table CSS can round widget cells like real table cells.
29
- */
30
- var getChangedRowCellEdgeAttrs = function getChangedRowCellEdgeAttrs(_ref) {
31
- var rowNode = _ref.rowNode,
32
- rowStart = _ref.rowStart,
33
- tableMap = _ref.tableMap;
34
- var cellEdgeAttrs = [];
35
- rowNode.content.forEach(function (cellNode, cellOffset) {
36
- if (cellNode.type.name !== 'tableCell' && cellNode.type.name !== 'tableHeader') {
37
- return;
38
- }
39
- var cellRect = tableMap.findCell(rowStart + 1 + cellOffset);
40
- cellEdgeAttrs.push({
41
- reachesBottom: cellRect.bottom >= tableMap.height,
42
- reachesLeft: cellRect.left === 0,
43
- reachesRight: cellRect.right >= tableMap.width,
44
- reachesTop: cellRect.top === 0
45
- });
46
- });
47
- return cellEdgeAttrs;
48
- };
49
- var applyCellEdgeAttrs = function applyCellEdgeAttrs(cell, edgeAttrs) {
50
- if (!edgeAttrs) {
51
- return;
52
- }
53
- if (edgeAttrs.reachesTop) {
54
- cell.setAttribute('data-reaches-top', 'true');
55
- }
56
- if (edgeAttrs.reachesBottom) {
57
- cell.setAttribute('data-reaches-bottom', 'true');
58
- }
59
- if (edgeAttrs.reachesLeft) {
60
- cell.setAttribute('data-reaches-left', 'true');
61
- }
62
- if (edgeAttrs.reachesRight) {
63
- cell.setAttribute('data-reaches-right', 'true');
64
- }
65
- };
66
26
  /**
67
27
  * Extracts information about deleted table rows from a change
68
28
  */
69
- var extractChangedRows = function extractChangedRows(_ref2) {
70
- var change = _ref2.change,
71
- originalDoc = _ref2.originalDoc,
72
- newDoc = _ref2.newDoc,
73
- diffType = _ref2.diffType;
29
+ var extractChangedRows = function extractChangedRows(_ref) {
30
+ var change = _ref.change,
31
+ originalDoc = _ref.originalDoc,
32
+ newDoc = _ref.newDoc,
33
+ diffType = _ref.diffType;
74
34
  var changedRows = [];
75
35
 
76
36
  // Find the table in the original document
@@ -111,7 +71,7 @@ var extractChangedRows = function extractChangedRows(_ref2) {
111
71
  // Check if this row overlaps with the deletion range
112
72
  var rowOverlapsChange = rowStart >= changeStartInTable && rowStart < changeEndInTable || rowEnd > changeStartInTable && rowEnd <= changeEndInTable || rowStart < changeStartInTable && rowEnd > changeEndInTable;
113
73
  if (rowOverlapsChange && rowNode.type.name === 'tableRow' && ((0, _isExtendedEnabled.isExtendedEnabled)(diffType) || !isEmptyRow(rowNode))) {
114
- var cellEdgeAttrs = (0, _isExtendedEnabled.isExtendedEnabled)(diffType) && (0, _expValEquals.expValEquals)('platform_editor_table_diff_rounded_corners', 'isEnabled', true) ? getChangedRowCellEdgeAttrs({
74
+ var cellEdgeAttrs = (0, _isExtendedEnabled.isExtendedEnabled)(diffType) && (0, _expValEquals.expValEquals)('platform_editor_table_q4_loveability', 'isEnabled', true) && (0, _expValEquals.expValEquals)('platform_editor_table_diff_rounded_corners', 'isEnabled', true) ? (0, _tableCellEdgeAttrs.getRowCellEdgeAttrs)({
115
75
  rowNode: rowNode,
116
76
  rowStart: rowStart,
117
77
  tableMap: oldTableMap
@@ -189,7 +149,7 @@ var createChangedRowDOM = function createChangedRowDOM(rowNode, cellEdgeAttrs, n
189
149
  var nodeView = nodeViewSerializer.tryCreateNodeView(cellNode);
190
150
  if (nodeView) {
191
151
  if (nodeView instanceof HTMLElement) {
192
- applyCellEdgeAttrs(nodeView, cellEdgeAttrs === null || cellEdgeAttrs === void 0 ? void 0 : cellEdgeAttrs[cellIndex]);
152
+ (0, _tableCellEdgeAttrs.applyCellEdgeAttrs)(nodeView, cellEdgeAttrs === null || cellEdgeAttrs === void 0 ? void 0 : cellEdgeAttrs[cellIndex]);
193
153
  if ((0, _isExtendedEnabled.isExtendedEnabled)(diffType)) {
194
154
  var overlay = document.createElement('span');
195
155
  var isRoundedTable = (0, _expValEquals.expValEquals)('platform_editor_table_diff_rounded_corners', 'isEnabled', true);
@@ -218,11 +178,11 @@ var createChangedRowDOM = function createChangedRowDOM(rowNode, cellEdgeAttrs, n
218
178
  /**
219
179
  * Expands a diff to include whole changed rows when table rows are affected
220
180
  */
221
- var expandDiffForChangedRows = function expandDiffForChangedRows(_ref3) {
222
- var changes = _ref3.changes,
223
- originalDoc = _ref3.originalDoc,
224
- newDoc = _ref3.newDoc,
225
- diffType = _ref3.diffType;
181
+ var expandDiffForChangedRows = function expandDiffForChangedRows(_ref2) {
182
+ var changes = _ref2.changes,
183
+ originalDoc = _ref2.originalDoc,
184
+ newDoc = _ref2.newDoc,
185
+ diffType = _ref2.diffType;
226
186
  var rowInfo = [];
227
187
  var _iterator = _createForOfIteratorHelper(changes),
228
188
  _step;
@@ -251,15 +211,15 @@ var expandDiffForChangedRows = function expandDiffForChangedRows(_ref3) {
251
211
  /**
252
212
  * Main function to handle deleted rows - computes diff and creates decorations
253
213
  */
254
- var createChangedRowDecorationWidgets = exports.createChangedRowDecorationWidgets = function createChangedRowDecorationWidgets(_ref4) {
255
- var changes = _ref4.changes,
256
- originalDoc = _ref4.originalDoc,
257
- newDoc = _ref4.newDoc,
258
- nodeViewSerializer = _ref4.nodeViewSerializer,
259
- colorScheme = _ref4.colorScheme,
260
- _ref4$isInserted = _ref4.isInserted,
261
- isInserted = _ref4$isInserted === void 0 ? false : _ref4$isInserted,
262
- diffType = _ref4.diffType;
214
+ var createChangedRowDecorationWidgets = exports.createChangedRowDecorationWidgets = function createChangedRowDecorationWidgets(_ref3) {
215
+ var changes = _ref3.changes,
216
+ originalDoc = _ref3.originalDoc,
217
+ newDoc = _ref3.newDoc,
218
+ nodeViewSerializer = _ref3.nodeViewSerializer,
219
+ colorScheme = _ref3.colorScheme,
220
+ _ref3$isInserted = _ref3.isInserted,
221
+ isInserted = _ref3$isInserted === void 0 ? false : _ref3$isInserted,
222
+ diffType = _ref3.diffType;
263
223
  // First, expand the changes to include complete deleted rows
264
224
  var changedRows = expandDiffForChangedRows({
265
225
  changes: changes.filter(function (change) {
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getRowCellEdgeAttrs = exports.applyTableCellEdgeAttrs = exports.applyCellEdgeAttrs = void 0;
7
+ var _tableMap = require("@atlaskit/editor-tables/table-map");
8
+ var getRowCellEdgeAttrs = exports.getRowCellEdgeAttrs = function getRowCellEdgeAttrs(_ref) {
9
+ var rowNode = _ref.rowNode,
10
+ rowStart = _ref.rowStart,
11
+ tableMap = _ref.tableMap;
12
+ var cellEdgeAttrs = [];
13
+ rowNode.content.forEach(function (cellNode, cellOffset) {
14
+ if (cellNode.type.name !== 'tableCell' && cellNode.type.name !== 'tableHeader') {
15
+ return;
16
+ }
17
+ var cellRect = tableMap.findCell(rowStart + 1 + cellOffset);
18
+ cellEdgeAttrs.push({
19
+ reachesBottom: cellRect.bottom >= tableMap.height,
20
+ reachesLeft: cellRect.left === 0,
21
+ reachesRight: cellRect.right >= tableMap.width,
22
+ reachesTop: cellRect.top === 0
23
+ });
24
+ });
25
+ return cellEdgeAttrs;
26
+ };
27
+ var applyCellEdgeAttrs = exports.applyCellEdgeAttrs = function applyCellEdgeAttrs(cell, edgeAttrs) {
28
+ if (!edgeAttrs) {
29
+ return;
30
+ }
31
+ if (edgeAttrs.reachesTop) {
32
+ cell.setAttribute('data-reaches-top', 'true');
33
+ }
34
+ if (edgeAttrs.reachesBottom) {
35
+ cell.setAttribute('data-reaches-bottom', 'true');
36
+ }
37
+ if (edgeAttrs.reachesLeft) {
38
+ cell.setAttribute('data-reaches-left', 'true');
39
+ }
40
+ if (edgeAttrs.reachesRight) {
41
+ cell.setAttribute('data-reaches-right', 'true');
42
+ }
43
+ };
44
+ var applyTableCellEdgeAttrs = exports.applyTableCellEdgeAttrs = function applyTableCellEdgeAttrs(_ref2) {
45
+ var element = _ref2.element,
46
+ tableNode = _ref2.tableNode;
47
+ try {
48
+ var table = element instanceof HTMLTableElement ? element : element.querySelector('table');
49
+ if (!(table instanceof HTMLTableElement)) {
50
+ return;
51
+ }
52
+ var tableMap = _tableMap.TableMap.get(tableNode);
53
+ var cells = Array.from(table.rows).flatMap(function (row) {
54
+ return Array.from(row.cells);
55
+ });
56
+ var cellIndex = 0;
57
+ tableNode.content.forEach(function (rowNode, rowStart) {
58
+ getRowCellEdgeAttrs({
59
+ rowNode: rowNode,
60
+ rowStart: rowStart,
61
+ tableMap: tableMap
62
+ }).forEach(function (edgeAttrs) {
63
+ var cell = cells[cellIndex];
64
+ cellIndex++;
65
+ if (cell) {
66
+ applyCellEdgeAttrs(cell, edgeAttrs);
67
+ }
68
+ });
69
+ });
70
+ } catch (_unused) {
71
+ // Table structure can be transient while widget DOM is being assembled.
72
+ }
73
+ };
@@ -13,6 +13,7 @@ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
13
13
  var _isExtendedEnabled = require("../../isExtendedEnabled");
14
14
  var _standard = require("../colorSchemes/standard");
15
15
  var _traditional = require("../colorSchemes/traditional");
16
+ var _tableCellEdgeAttrs = require("./tableCellEdgeAttrs");
16
17
  var lozengeStyle = (0, _lazyNodeView.convertToInlineCss)({
17
18
  display: 'inline-flex',
18
19
  boxSizing: 'border-box',
@@ -178,9 +179,13 @@ var applyCellOverlayStyles = function applyCellOverlayStyles(_ref2) {
178
179
  var element = _ref2.element,
179
180
  colorScheme = _ref2.colorScheme,
180
181
  isInserted = _ref2.isInserted;
182
+ var isRoundedTable = (0, _expValEquals.expValEquals)('platform_editor_table_diff_rounded_corners', 'isEnabled', true);
181
183
  element.querySelectorAll('td, th').forEach(function (cell) {
182
184
  var overlay = document.createElement('span');
183
- var overlayStyle = colorScheme === 'traditional' ? isInserted ? _traditional.traditionalAddedCellOverlayStyleNew : _traditional.deletedTraditionalCellOverlayStyle : isInserted ? _standard.addedCellOverlayStyle : _standard.deletedCellOverlayStyle;
185
+ var isTraditional = colorScheme === 'traditional';
186
+ var deletedCellStyle = isTraditional ? _traditional.deletedTraditionalCellOverlayStyle : _standard.deletedCellOverlayStyle;
187
+ var addedCellStyle = isTraditional ? isRoundedTable ? _traditional.traditionalAddedCellOverlayRoundedStyle : _traditional.traditionalAddedCellOverlayStyleNew : isRoundedTable ? _standard.addedCellOverlayRoundedStyle : _standard.addedCellOverlayStyle;
188
+ var overlayStyle = isInserted ? addedCellStyle : deletedCellStyle;
184
189
  overlay.setAttribute('style', overlayStyle);
185
190
  cell.appendChild(overlay);
186
191
  });
@@ -544,6 +549,12 @@ var wrapBlockNodeView = exports.wrapBlockNodeView = function wrapBlockNodeView(_
544
549
  return;
545
550
  }
546
551
  if (targetNode.type.name === 'table') {
552
+ if ((0, _expValEquals.expValEquals)('platform_editor_table_q4_loveability', 'isEnabled', true) && (0, _expValEquals.expValEquals)('platform_editor_table_diff_rounded_corners', 'isEnabled', true)) {
553
+ (0, _tableCellEdgeAttrs.applyTableCellEdgeAttrs)({
554
+ element: nodeView,
555
+ tableNode: targetNode
556
+ });
557
+ }
547
558
  applyCellOverlayStyles({
548
559
  element: nodeView,
549
560
  colorScheme: colorScheme,
@@ -8,48 +8,7 @@ import { addedCellOverlayStyle, addedCellOverlayRoundedStyle, deletedRowStyle, d
8
8
  import { deletedTraditionalRowStyle, deletedTraditionalCellOverlayStyle, traditionalAddedCellOverlayStyle, traditionalAddedCellOverlayRoundedStyle } from './colorSchemes/traditional';
9
9
  import { buildDiffDecorationSpec } from './decorationKeys';
10
10
  import { findSafeInsertPos } from './utils/findSafeInsertPos';
11
- /**
12
- * Inserted table rows are rendered as decoration widgets, so their cells do not get the
13
- * `data-reaches-*` attrs normally applied by the table cell node view. Mirror that boundary
14
- * metadata here so the existing rounded-table CSS can round widget cells like real table cells.
15
- */
16
- const getChangedRowCellEdgeAttrs = ({
17
- rowNode,
18
- rowStart,
19
- tableMap
20
- }) => {
21
- const cellEdgeAttrs = [];
22
- rowNode.content.forEach((cellNode, cellOffset) => {
23
- if (cellNode.type.name !== 'tableCell' && cellNode.type.name !== 'tableHeader') {
24
- return;
25
- }
26
- const cellRect = tableMap.findCell(rowStart + 1 + cellOffset);
27
- cellEdgeAttrs.push({
28
- reachesBottom: cellRect.bottom >= tableMap.height,
29
- reachesLeft: cellRect.left === 0,
30
- reachesRight: cellRect.right >= tableMap.width,
31
- reachesTop: cellRect.top === 0
32
- });
33
- });
34
- return cellEdgeAttrs;
35
- };
36
- const applyCellEdgeAttrs = (cell, edgeAttrs) => {
37
- if (!edgeAttrs) {
38
- return;
39
- }
40
- if (edgeAttrs.reachesTop) {
41
- cell.setAttribute('data-reaches-top', 'true');
42
- }
43
- if (edgeAttrs.reachesBottom) {
44
- cell.setAttribute('data-reaches-bottom', 'true');
45
- }
46
- if (edgeAttrs.reachesLeft) {
47
- cell.setAttribute('data-reaches-left', 'true');
48
- }
49
- if (edgeAttrs.reachesRight) {
50
- cell.setAttribute('data-reaches-right', 'true');
51
- }
52
- };
11
+ import { applyCellEdgeAttrs, getRowCellEdgeAttrs } from './utils/tableCellEdgeAttrs';
53
12
  /**
54
13
  * Extracts information about deleted table rows from a change
55
14
  */
@@ -95,7 +54,7 @@ const extractChangedRows = ({
95
54
  // Check if this row overlaps with the deletion range
96
55
  const rowOverlapsChange = rowStart >= changeStartInTable && rowStart < changeEndInTable || rowEnd > changeStartInTable && rowEnd <= changeEndInTable || rowStart < changeStartInTable && rowEnd > changeEndInTable;
97
56
  if (rowOverlapsChange && rowNode.type.name === 'tableRow' && (isExtendedEnabled(diffType) || !isEmptyRow(rowNode))) {
98
- const cellEdgeAttrs = isExtendedEnabled(diffType) && expValEquals('platform_editor_table_diff_rounded_corners', 'isEnabled', true) ? getChangedRowCellEdgeAttrs({
57
+ const cellEdgeAttrs = isExtendedEnabled(diffType) && expValEquals('platform_editor_table_q4_loveability', 'isEnabled', true) && expValEquals('platform_editor_table_diff_rounded_corners', 'isEnabled', true) ? getRowCellEdgeAttrs({
99
58
  rowNode,
100
59
  rowStart,
101
60
  tableMap: oldTableMap
@@ -0,0 +1,67 @@
1
+ import { TableMap } from '@atlaskit/editor-tables/table-map';
2
+ export const getRowCellEdgeAttrs = ({
3
+ rowNode,
4
+ rowStart,
5
+ tableMap
6
+ }) => {
7
+ const cellEdgeAttrs = [];
8
+ rowNode.content.forEach((cellNode, cellOffset) => {
9
+ if (cellNode.type.name !== 'tableCell' && cellNode.type.name !== 'tableHeader') {
10
+ return;
11
+ }
12
+ const cellRect = tableMap.findCell(rowStart + 1 + cellOffset);
13
+ cellEdgeAttrs.push({
14
+ reachesBottom: cellRect.bottom >= tableMap.height,
15
+ reachesLeft: cellRect.left === 0,
16
+ reachesRight: cellRect.right >= tableMap.width,
17
+ reachesTop: cellRect.top === 0
18
+ });
19
+ });
20
+ return cellEdgeAttrs;
21
+ };
22
+ export const applyCellEdgeAttrs = (cell, edgeAttrs) => {
23
+ if (!edgeAttrs) {
24
+ return;
25
+ }
26
+ if (edgeAttrs.reachesTop) {
27
+ cell.setAttribute('data-reaches-top', 'true');
28
+ }
29
+ if (edgeAttrs.reachesBottom) {
30
+ cell.setAttribute('data-reaches-bottom', 'true');
31
+ }
32
+ if (edgeAttrs.reachesLeft) {
33
+ cell.setAttribute('data-reaches-left', 'true');
34
+ }
35
+ if (edgeAttrs.reachesRight) {
36
+ cell.setAttribute('data-reaches-right', 'true');
37
+ }
38
+ };
39
+ export const applyTableCellEdgeAttrs = ({
40
+ element,
41
+ tableNode
42
+ }) => {
43
+ try {
44
+ const table = element instanceof HTMLTableElement ? element : element.querySelector('table');
45
+ if (!(table instanceof HTMLTableElement)) {
46
+ return;
47
+ }
48
+ const tableMap = TableMap.get(tableNode);
49
+ const cells = Array.from(table.rows).flatMap(row => Array.from(row.cells));
50
+ let cellIndex = 0;
51
+ tableNode.content.forEach((rowNode, rowStart) => {
52
+ getRowCellEdgeAttrs({
53
+ rowNode,
54
+ rowStart,
55
+ tableMap
56
+ }).forEach(edgeAttrs => {
57
+ const cell = cells[cellIndex];
58
+ cellIndex++;
59
+ if (cell) {
60
+ applyCellEdgeAttrs(cell, edgeAttrs);
61
+ }
62
+ });
63
+ });
64
+ } catch {
65
+ // Table structure can be transient while widget DOM is being assembled.
66
+ }
67
+ };
@@ -3,8 +3,9 @@ import { trackChangesMessages } from '@atlaskit/editor-common/messages';
3
3
  import { getBaseNodeTypeName } from '@atlaskit/editor-common/utils/node-type-utils';
4
4
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
5
5
  import { isExtendedEnabled } from '../../isExtendedEnabled';
6
- import { deletedBlockOutline, deletedBlockOutlineActive, deletedBlockOutlineRounded, deletedBlockOutlineRoundedActive, deletedContentStyle, deletedContentStyleActive, deletedContentStyleNew, deletedContentStyleUnbounded, deletedInlineContentStyleExtended, deletedStyleQuoteNodeWithLozenge, deletedStyleQuoteNodeWithLozengeActive, editingContentStyleInBlockExtended, editingContentStyleInBlockExtendedNoUnderline, editingStyleExtended, editingStyleExtendedNoUnderline, editingStyleActiveExtended, editingStyleActiveExtendedNoUnderline, editingStyleNode, addedCellOverlayStyle, deletedCellOverlayStyle } from '../colorSchemes/standard';
7
- import { deletedTraditionalBlockOutlineActive, deletedTraditionalBlockOutlineNew, deletedTraditionalBlockOutlineRoundedActive, deletedTraditionalBlockOutlineRoundedNew, deletedTraditionalContentStyleUnbounded, deletedTraditionalContentStyleUnboundedActive, getDeletedTraditionalInlineStyle, deletedTraditionalStyleQuoteNode, deletedTraditionalStyleQuoteNodeActive, traditionalInsertStyle, traditionalInsertStyleActive, traditionalStyleNodeActive, traditionalStyleNodeNew, traditionalAddedCellOverlayStyleNew, deletedTraditionalCellOverlayStyle } from '../colorSchemes/traditional';
6
+ import { deletedBlockOutline, deletedBlockOutlineActive, deletedBlockOutlineRounded, deletedBlockOutlineRoundedActive, deletedContentStyle, deletedContentStyleActive, deletedContentStyleNew, deletedContentStyleUnbounded, deletedInlineContentStyleExtended, deletedStyleQuoteNodeWithLozenge, deletedStyleQuoteNodeWithLozengeActive, editingContentStyleInBlockExtended, editingContentStyleInBlockExtendedNoUnderline, editingStyleExtended, editingStyleExtendedNoUnderline, editingStyleActiveExtended, editingStyleActiveExtendedNoUnderline, editingStyleNode, addedCellOverlayStyle, addedCellOverlayRoundedStyle, deletedCellOverlayStyle } from '../colorSchemes/standard';
7
+ import { deletedTraditionalBlockOutlineActive, deletedTraditionalBlockOutlineNew, deletedTraditionalBlockOutlineRoundedActive, deletedTraditionalBlockOutlineRoundedNew, deletedTraditionalContentStyleUnbounded, deletedTraditionalContentStyleUnboundedActive, getDeletedTraditionalInlineStyle, deletedTraditionalStyleQuoteNode, deletedTraditionalStyleQuoteNodeActive, traditionalInsertStyle, traditionalInsertStyleActive, traditionalStyleNodeActive, traditionalStyleNodeNew, traditionalAddedCellOverlayRoundedStyle, traditionalAddedCellOverlayStyleNew, deletedTraditionalCellOverlayStyle } from '../colorSchemes/traditional';
8
+ import { applyTableCellEdgeAttrs } from './tableCellEdgeAttrs';
8
9
  const lozengeStyle = convertToInlineCss({
9
10
  display: 'inline-flex',
10
11
  boxSizing: 'border-box',
@@ -163,9 +164,13 @@ const applyCellOverlayStyles = ({
163
164
  colorScheme,
164
165
  isInserted
165
166
  }) => {
167
+ const isRoundedTable = expValEquals('platform_editor_table_diff_rounded_corners', 'isEnabled', true);
166
168
  element.querySelectorAll('td, th').forEach(cell => {
167
169
  const overlay = document.createElement('span');
168
- const overlayStyle = colorScheme === 'traditional' ? isInserted ? traditionalAddedCellOverlayStyleNew : deletedTraditionalCellOverlayStyle : isInserted ? addedCellOverlayStyle : deletedCellOverlayStyle;
170
+ const isTraditional = colorScheme === 'traditional';
171
+ const deletedCellStyle = isTraditional ? deletedTraditionalCellOverlayStyle : deletedCellOverlayStyle;
172
+ const addedCellStyle = isTraditional ? isRoundedTable ? traditionalAddedCellOverlayRoundedStyle : traditionalAddedCellOverlayStyleNew : isRoundedTable ? addedCellOverlayRoundedStyle : addedCellOverlayStyle;
173
+ const overlayStyle = isInserted ? addedCellStyle : deletedCellStyle;
169
174
  overlay.setAttribute('style', overlayStyle);
170
175
  cell.appendChild(overlay);
171
176
  });
@@ -523,6 +528,12 @@ export const wrapBlockNodeView = ({
523
528
  return;
524
529
  }
525
530
  if (targetNode.type.name === 'table') {
531
+ if (expValEquals('platform_editor_table_q4_loveability', 'isEnabled', true) && expValEquals('platform_editor_table_diff_rounded_corners', 'isEnabled', true)) {
532
+ applyTableCellEdgeAttrs({
533
+ element: nodeView,
534
+ tableNode: targetNode
535
+ });
536
+ }
526
537
  applyCellOverlayStyles({
527
538
  element: nodeView,
528
539
  colorScheme,
@@ -15,55 +15,15 @@ import { addedCellOverlayStyle, addedCellOverlayRoundedStyle, deletedRowStyle, d
15
15
  import { deletedTraditionalRowStyle, deletedTraditionalCellOverlayStyle, traditionalAddedCellOverlayStyle, traditionalAddedCellOverlayRoundedStyle } from './colorSchemes/traditional';
16
16
  import { buildDiffDecorationSpec } from './decorationKeys';
17
17
  import { findSafeInsertPos } from './utils/findSafeInsertPos';
18
- /**
19
- * Inserted table rows are rendered as decoration widgets, so their cells do not get the
20
- * `data-reaches-*` attrs normally applied by the table cell node view. Mirror that boundary
21
- * metadata here so the existing rounded-table CSS can round widget cells like real table cells.
22
- */
23
- var getChangedRowCellEdgeAttrs = function getChangedRowCellEdgeAttrs(_ref) {
24
- var rowNode = _ref.rowNode,
25
- rowStart = _ref.rowStart,
26
- tableMap = _ref.tableMap;
27
- var cellEdgeAttrs = [];
28
- rowNode.content.forEach(function (cellNode, cellOffset) {
29
- if (cellNode.type.name !== 'tableCell' && cellNode.type.name !== 'tableHeader') {
30
- return;
31
- }
32
- var cellRect = tableMap.findCell(rowStart + 1 + cellOffset);
33
- cellEdgeAttrs.push({
34
- reachesBottom: cellRect.bottom >= tableMap.height,
35
- reachesLeft: cellRect.left === 0,
36
- reachesRight: cellRect.right >= tableMap.width,
37
- reachesTop: cellRect.top === 0
38
- });
39
- });
40
- return cellEdgeAttrs;
41
- };
42
- var applyCellEdgeAttrs = function applyCellEdgeAttrs(cell, edgeAttrs) {
43
- if (!edgeAttrs) {
44
- return;
45
- }
46
- if (edgeAttrs.reachesTop) {
47
- cell.setAttribute('data-reaches-top', 'true');
48
- }
49
- if (edgeAttrs.reachesBottom) {
50
- cell.setAttribute('data-reaches-bottom', 'true');
51
- }
52
- if (edgeAttrs.reachesLeft) {
53
- cell.setAttribute('data-reaches-left', 'true');
54
- }
55
- if (edgeAttrs.reachesRight) {
56
- cell.setAttribute('data-reaches-right', 'true');
57
- }
58
- };
18
+ import { applyCellEdgeAttrs, getRowCellEdgeAttrs } from './utils/tableCellEdgeAttrs';
59
19
  /**
60
20
  * Extracts information about deleted table rows from a change
61
21
  */
62
- var extractChangedRows = function extractChangedRows(_ref2) {
63
- var change = _ref2.change,
64
- originalDoc = _ref2.originalDoc,
65
- newDoc = _ref2.newDoc,
66
- diffType = _ref2.diffType;
22
+ var extractChangedRows = function extractChangedRows(_ref) {
23
+ var change = _ref.change,
24
+ originalDoc = _ref.originalDoc,
25
+ newDoc = _ref.newDoc,
26
+ diffType = _ref.diffType;
67
27
  var changedRows = [];
68
28
 
69
29
  // Find the table in the original document
@@ -104,7 +64,7 @@ var extractChangedRows = function extractChangedRows(_ref2) {
104
64
  // Check if this row overlaps with the deletion range
105
65
  var rowOverlapsChange = rowStart >= changeStartInTable && rowStart < changeEndInTable || rowEnd > changeStartInTable && rowEnd <= changeEndInTable || rowStart < changeStartInTable && rowEnd > changeEndInTable;
106
66
  if (rowOverlapsChange && rowNode.type.name === 'tableRow' && (isExtendedEnabled(diffType) || !isEmptyRow(rowNode))) {
107
- var cellEdgeAttrs = isExtendedEnabled(diffType) && expValEquals('platform_editor_table_diff_rounded_corners', 'isEnabled', true) ? getChangedRowCellEdgeAttrs({
67
+ var cellEdgeAttrs = isExtendedEnabled(diffType) && expValEquals('platform_editor_table_q4_loveability', 'isEnabled', true) && expValEquals('platform_editor_table_diff_rounded_corners', 'isEnabled', true) ? getRowCellEdgeAttrs({
108
68
  rowNode: rowNode,
109
69
  rowStart: rowStart,
110
70
  tableMap: oldTableMap
@@ -211,11 +171,11 @@ var createChangedRowDOM = function createChangedRowDOM(rowNode, cellEdgeAttrs, n
211
171
  /**
212
172
  * Expands a diff to include whole changed rows when table rows are affected
213
173
  */
214
- var expandDiffForChangedRows = function expandDiffForChangedRows(_ref3) {
215
- var changes = _ref3.changes,
216
- originalDoc = _ref3.originalDoc,
217
- newDoc = _ref3.newDoc,
218
- diffType = _ref3.diffType;
174
+ var expandDiffForChangedRows = function expandDiffForChangedRows(_ref2) {
175
+ var changes = _ref2.changes,
176
+ originalDoc = _ref2.originalDoc,
177
+ newDoc = _ref2.newDoc,
178
+ diffType = _ref2.diffType;
219
179
  var rowInfo = [];
220
180
  var _iterator = _createForOfIteratorHelper(changes),
221
181
  _step;
@@ -244,15 +204,15 @@ var expandDiffForChangedRows = function expandDiffForChangedRows(_ref3) {
244
204
  /**
245
205
  * Main function to handle deleted rows - computes diff and creates decorations
246
206
  */
247
- export var createChangedRowDecorationWidgets = function createChangedRowDecorationWidgets(_ref4) {
248
- var changes = _ref4.changes,
249
- originalDoc = _ref4.originalDoc,
250
- newDoc = _ref4.newDoc,
251
- nodeViewSerializer = _ref4.nodeViewSerializer,
252
- colorScheme = _ref4.colorScheme,
253
- _ref4$isInserted = _ref4.isInserted,
254
- isInserted = _ref4$isInserted === void 0 ? false : _ref4$isInserted,
255
- diffType = _ref4.diffType;
207
+ export var createChangedRowDecorationWidgets = function createChangedRowDecorationWidgets(_ref3) {
208
+ var changes = _ref3.changes,
209
+ originalDoc = _ref3.originalDoc,
210
+ newDoc = _ref3.newDoc,
211
+ nodeViewSerializer = _ref3.nodeViewSerializer,
212
+ colorScheme = _ref3.colorScheme,
213
+ _ref3$isInserted = _ref3.isInserted,
214
+ isInserted = _ref3$isInserted === void 0 ? false : _ref3$isInserted,
215
+ diffType = _ref3.diffType;
256
216
  // First, expand the changes to include complete deleted rows
257
217
  var changedRows = expandDiffForChangedRows({
258
218
  changes: changes.filter(function (change) {
@@ -0,0 +1,67 @@
1
+ import { TableMap } from '@atlaskit/editor-tables/table-map';
2
+ export var getRowCellEdgeAttrs = function getRowCellEdgeAttrs(_ref) {
3
+ var rowNode = _ref.rowNode,
4
+ rowStart = _ref.rowStart,
5
+ tableMap = _ref.tableMap;
6
+ var cellEdgeAttrs = [];
7
+ rowNode.content.forEach(function (cellNode, cellOffset) {
8
+ if (cellNode.type.name !== 'tableCell' && cellNode.type.name !== 'tableHeader') {
9
+ return;
10
+ }
11
+ var cellRect = tableMap.findCell(rowStart + 1 + cellOffset);
12
+ cellEdgeAttrs.push({
13
+ reachesBottom: cellRect.bottom >= tableMap.height,
14
+ reachesLeft: cellRect.left === 0,
15
+ reachesRight: cellRect.right >= tableMap.width,
16
+ reachesTop: cellRect.top === 0
17
+ });
18
+ });
19
+ return cellEdgeAttrs;
20
+ };
21
+ export var applyCellEdgeAttrs = function applyCellEdgeAttrs(cell, edgeAttrs) {
22
+ if (!edgeAttrs) {
23
+ return;
24
+ }
25
+ if (edgeAttrs.reachesTop) {
26
+ cell.setAttribute('data-reaches-top', 'true');
27
+ }
28
+ if (edgeAttrs.reachesBottom) {
29
+ cell.setAttribute('data-reaches-bottom', 'true');
30
+ }
31
+ if (edgeAttrs.reachesLeft) {
32
+ cell.setAttribute('data-reaches-left', 'true');
33
+ }
34
+ if (edgeAttrs.reachesRight) {
35
+ cell.setAttribute('data-reaches-right', 'true');
36
+ }
37
+ };
38
+ export var applyTableCellEdgeAttrs = function applyTableCellEdgeAttrs(_ref2) {
39
+ var element = _ref2.element,
40
+ tableNode = _ref2.tableNode;
41
+ try {
42
+ var table = element instanceof HTMLTableElement ? element : element.querySelector('table');
43
+ if (!(table instanceof HTMLTableElement)) {
44
+ return;
45
+ }
46
+ var tableMap = TableMap.get(tableNode);
47
+ var cells = Array.from(table.rows).flatMap(function (row) {
48
+ return Array.from(row.cells);
49
+ });
50
+ var cellIndex = 0;
51
+ tableNode.content.forEach(function (rowNode, rowStart) {
52
+ getRowCellEdgeAttrs({
53
+ rowNode: rowNode,
54
+ rowStart: rowStart,
55
+ tableMap: tableMap
56
+ }).forEach(function (edgeAttrs) {
57
+ var cell = cells[cellIndex];
58
+ cellIndex++;
59
+ if (cell) {
60
+ applyCellEdgeAttrs(cell, edgeAttrs);
61
+ }
62
+ });
63
+ });
64
+ } catch (_unused) {
65
+ // Table structure can be transient while widget DOM is being assembled.
66
+ }
67
+ };
@@ -4,8 +4,9 @@ import { trackChangesMessages } from '@atlaskit/editor-common/messages';
4
4
  import { getBaseNodeTypeName } from '@atlaskit/editor-common/utils/node-type-utils';
5
5
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
6
6
  import { isExtendedEnabled } from '../../isExtendedEnabled';
7
- import { deletedBlockOutline, deletedBlockOutlineActive, deletedBlockOutlineRounded, deletedBlockOutlineRoundedActive, deletedContentStyle, deletedContentStyleActive, deletedContentStyleNew, deletedContentStyleUnbounded, deletedInlineContentStyleExtended, deletedStyleQuoteNodeWithLozenge, deletedStyleQuoteNodeWithLozengeActive, editingContentStyleInBlockExtended, editingContentStyleInBlockExtendedNoUnderline, editingStyleExtended, editingStyleExtendedNoUnderline, editingStyleActiveExtended, editingStyleActiveExtendedNoUnderline, editingStyleNode, addedCellOverlayStyle, deletedCellOverlayStyle } from '../colorSchemes/standard';
8
- import { deletedTraditionalBlockOutlineActive, deletedTraditionalBlockOutlineNew, deletedTraditionalBlockOutlineRoundedActive, deletedTraditionalBlockOutlineRoundedNew, deletedTraditionalContentStyleUnbounded, deletedTraditionalContentStyleUnboundedActive, getDeletedTraditionalInlineStyle, deletedTraditionalStyleQuoteNode, deletedTraditionalStyleQuoteNodeActive, traditionalInsertStyle, traditionalInsertStyleActive, traditionalStyleNodeActive, traditionalStyleNodeNew, traditionalAddedCellOverlayStyleNew, deletedTraditionalCellOverlayStyle } from '../colorSchemes/traditional';
7
+ import { deletedBlockOutline, deletedBlockOutlineActive, deletedBlockOutlineRounded, deletedBlockOutlineRoundedActive, deletedContentStyle, deletedContentStyleActive, deletedContentStyleNew, deletedContentStyleUnbounded, deletedInlineContentStyleExtended, deletedStyleQuoteNodeWithLozenge, deletedStyleQuoteNodeWithLozengeActive, editingContentStyleInBlockExtended, editingContentStyleInBlockExtendedNoUnderline, editingStyleExtended, editingStyleExtendedNoUnderline, editingStyleActiveExtended, editingStyleActiveExtendedNoUnderline, editingStyleNode, addedCellOverlayStyle, addedCellOverlayRoundedStyle, deletedCellOverlayStyle } from '../colorSchemes/standard';
8
+ import { deletedTraditionalBlockOutlineActive, deletedTraditionalBlockOutlineNew, deletedTraditionalBlockOutlineRoundedActive, deletedTraditionalBlockOutlineRoundedNew, deletedTraditionalContentStyleUnbounded, deletedTraditionalContentStyleUnboundedActive, getDeletedTraditionalInlineStyle, deletedTraditionalStyleQuoteNode, deletedTraditionalStyleQuoteNodeActive, traditionalInsertStyle, traditionalInsertStyleActive, traditionalStyleNodeActive, traditionalStyleNodeNew, traditionalAddedCellOverlayRoundedStyle, traditionalAddedCellOverlayStyleNew, deletedTraditionalCellOverlayStyle } from '../colorSchemes/traditional';
9
+ import { applyTableCellEdgeAttrs } from './tableCellEdgeAttrs';
9
10
  var lozengeStyle = convertToInlineCss({
10
11
  display: 'inline-flex',
11
12
  boxSizing: 'border-box',
@@ -171,9 +172,13 @@ var applyCellOverlayStyles = function applyCellOverlayStyles(_ref2) {
171
172
  var element = _ref2.element,
172
173
  colorScheme = _ref2.colorScheme,
173
174
  isInserted = _ref2.isInserted;
175
+ var isRoundedTable = expValEquals('platform_editor_table_diff_rounded_corners', 'isEnabled', true);
174
176
  element.querySelectorAll('td, th').forEach(function (cell) {
175
177
  var overlay = document.createElement('span');
176
- var overlayStyle = colorScheme === 'traditional' ? isInserted ? traditionalAddedCellOverlayStyleNew : deletedTraditionalCellOverlayStyle : isInserted ? addedCellOverlayStyle : deletedCellOverlayStyle;
178
+ var isTraditional = colorScheme === 'traditional';
179
+ var deletedCellStyle = isTraditional ? deletedTraditionalCellOverlayStyle : deletedCellOverlayStyle;
180
+ var addedCellStyle = isTraditional ? isRoundedTable ? traditionalAddedCellOverlayRoundedStyle : traditionalAddedCellOverlayStyleNew : isRoundedTable ? addedCellOverlayRoundedStyle : addedCellOverlayStyle;
181
+ var overlayStyle = isInserted ? addedCellStyle : deletedCellStyle;
177
182
  overlay.setAttribute('style', overlayStyle);
178
183
  cell.appendChild(overlay);
179
184
  });
@@ -537,6 +542,12 @@ export var wrapBlockNodeView = function wrapBlockNodeView(_ref0) {
537
542
  return;
538
543
  }
539
544
  if (targetNode.type.name === 'table') {
545
+ if (expValEquals('platform_editor_table_q4_loveability', 'isEnabled', true) && expValEquals('platform_editor_table_diff_rounded_corners', 'isEnabled', true)) {
546
+ applyTableCellEdgeAttrs({
547
+ element: nodeView,
548
+ tableNode: targetNode
549
+ });
550
+ }
540
551
  applyCellOverlayStyles({
541
552
  element: nodeView,
542
553
  colorScheme: colorScheme,
@@ -0,0 +1,18 @@
1
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
+ import { TableMap } from '@atlaskit/editor-tables/table-map';
3
+ export type CellEdgeAttrs = {
4
+ reachesBottom: boolean;
5
+ reachesLeft: boolean;
6
+ reachesRight: boolean;
7
+ reachesTop: boolean;
8
+ };
9
+ export declare const getRowCellEdgeAttrs: ({ rowNode, rowStart, tableMap, }: {
10
+ rowNode: PMNode;
11
+ rowStart: number;
12
+ tableMap: TableMap;
13
+ }) => CellEdgeAttrs[];
14
+ export declare const applyCellEdgeAttrs: (cell: HTMLElement, edgeAttrs?: CellEdgeAttrs) => void;
15
+ export declare const applyTableCellEdgeAttrs: ({ element, tableNode, }: {
16
+ element: HTMLElement;
17
+ tableNode: PMNode;
18
+ }) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-show-diff",
3
- "version": "10.6.0",
3
+ "version": "10.6.2",
4
4
  "description": "ShowDiff plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -24,12 +24,12 @@
24
24
  "@atlaskit/custom-steps": "^1.0.0",
25
25
  "@atlaskit/editor-plugin-analytics": "^12.0.0",
26
26
  "@atlaskit/editor-plugin-expand": "^13.1.0",
27
- "@atlaskit/editor-plugin-user-intent": "^10.0.0",
27
+ "@atlaskit/editor-plugin-user-intent": "^10.1.0",
28
28
  "@atlaskit/editor-prosemirror": "^8.0.0",
29
29
  "@atlaskit/editor-tables": "^3.0.0",
30
30
  "@atlaskit/platform-feature-flags": "^2.1.0",
31
- "@atlaskit/tmp-editor-statsig": "^132.2.0",
32
- "@atlaskit/tokens": "^16.2.0",
31
+ "@atlaskit/tmp-editor-statsig": "^134.0.0",
32
+ "@atlaskit/tokens": "^16.3.0",
33
33
  "@babel/runtime": "^7.0.0",
34
34
  "@compiled/react": "^1.0.0",
35
35
  "lodash": "^4.17.21",
@@ -41,10 +41,10 @@
41
41
  "@atlaskit/button": "^24.3.0",
42
42
  "@atlaskit/css": "^1.0.0",
43
43
  "@atlaskit/dropdown-menu": "^17.1.0",
44
- "@atlaskit/editor-core": "^221.12.0",
45
- "@atlaskit/editor-json-transformer": "^9.0.0",
44
+ "@atlaskit/editor-core": "^221.14.0",
45
+ "@atlaskit/editor-json-transformer": "^9.1.0",
46
46
  "@atlaskit/form": "^16.1.0",
47
- "@atlaskit/primitives": "^22.1.0",
47
+ "@atlaskit/primitives": "^22.2.0",
48
48
  "@atlaskit/section-message": "^9.2.0",
49
49
  "@atlaskit/textarea": "^9.1.0",
50
50
  "@atlassian/confluence-presets": "workspace:^",
@@ -54,7 +54,7 @@
54
54
  "react-intl": "^7.0.0"
55
55
  },
56
56
  "peerDependencies": {
57
- "@atlaskit/editor-common": "^116.35.0",
57
+ "@atlaskit/editor-common": "^116.40.0",
58
58
  "react": "^18.2.0"
59
59
  },
60
60
  "techstack": {