@atlaskit/editor-plugin-table 1.0.0 → 1.0.1

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,11 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 1.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`04f178ea323`](https://bitbucket.org/atlassian/atlassian-frontend/commits/04f178ea323) - [ux] ED-15823 - Table cells on the second column would change their color upon unchecking "Header Column" table option when the selection cursor was placed in the 3rd column. This was caused by a view update not identifying the cells to update correctly. This was causing table data cells to be changed to table header cells.
8
+
3
9
  ## 1.0.0
4
10
 
5
11
  ### Major Changes
@@ -106,7 +106,11 @@ var TableCellNodeView = /*#__PURE__*/function () {
106
106
  key: "update",
107
107
  value: function update(node) {
108
108
  var didUpdate = this.updateNodeView(node);
109
- this.node = node;
109
+
110
+ if (didUpdate) {
111
+ this.node = node;
112
+ }
113
+
110
114
  return didUpdate;
111
115
  }
112
116
  }, {
@@ -63,6 +63,7 @@ var createPlugin = function createPlugin() {
63
63
  }
64
64
 
65
65
  if (tr.docChanged || tr.selectionSet) {
66
+ pluginState = pluginState.map(tr.mapping, tr.doc);
66
67
  return handleDocOrSelectionChanged(tr, pluginState, oldState);
67
68
  }
68
69
 
@@ -9,8 +9,6 @@ var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
9
9
 
10
10
  var _utils = require("@atlaskit/editor-tables/utils");
11
11
 
12
- var _prosemirrorView = require("prosemirror-view");
13
-
14
12
  var _types = require("../../../types");
15
13
 
16
14
  var _decoration = require("../../../utils/decoration");
@@ -80,7 +78,7 @@ var buildColumnControlsDecorations = function buildColumnControlsDecorations(_re
80
78
  var decorationSet = _ref6.decorationSet,
81
79
  tr = _ref6.tr;
82
80
  return (0, _composeDecorations.composeDecorations)([removeColumnControlsSelectedDecoration, removeControlsHoverDecoration, maybeUpdateColumnSelectedDecoration, maybeUpdateColumnControlsDecoration])({
83
- decorationSet: _prosemirrorView.DecorationSet.empty,
81
+ decorationSet: decorationSet,
84
82
  tr: tr
85
83
  });
86
84
  };
@@ -163,16 +163,21 @@ var createColumnControlsDecoration = function createColumnControlsDecoration(sel
163
163
  var cells = (0, _utils.getCellsInRow)(0)(selection) || [];
164
164
  var index = 0;
165
165
  return cells.map(function (cell) {
166
- var colspan = cell.node.attrs.colspan || 1;
167
- var element = document.createElement('div');
168
- element.classList.add(_types.TableCssClassName.COLUMN_CONTROLS_DECORATIONS);
169
- element.dataset.startIndex = "".concat(index);
170
- index += colspan;
171
- element.dataset.endIndex = "".concat(index);
166
+ var colspan = cell.node.attrs.colspan || 1; // It's important these values are scoped locally as the widget callback could be executed anytime in the future
167
+ // and we want to avoid value leak
168
+
169
+ var startIndex = index;
170
+ var endIndex = startIndex + colspan; // The next cell start index will commence from the current cell end index.
171
+
172
+ index = endIndex;
172
173
  return _prosemirrorView.Decoration.widget(cell.pos + 1, function () {
174
+ var element = document.createElement('div');
175
+ element.classList.add(_types.TableCssClassName.COLUMN_CONTROLS_DECORATIONS);
176
+ element.dataset.startIndex = "".concat(startIndex);
177
+ element.dataset.endIndex = "".concat(endIndex);
173
178
  return element;
174
179
  }, {
175
- key: "".concat(_types.TableDecorations.COLUMN_CONTROLS_DECORATIONS, "_").concat(index),
180
+ key: "".concat(_types.TableDecorations.COLUMN_CONTROLS_DECORATIONS, "_").concat(endIndex),
176
181
  // this decoration should be the first one, even before gap cursor.
177
182
  side: -100
178
183
  });
@@ -288,12 +293,14 @@ var createResizeHandleDecoration = function createResizeHandleDecoration(tr, row
288
293
  }
289
294
 
290
295
  var createResizerHandleDecoration = function createResizerHandleDecoration(cellColumnPositioning, columnIndex, rowIndex, cellPos, cellNode) {
291
- var element = document.createElement('div');
292
- element.classList.add(_types.TableCssClassName.RESIZE_HANDLE_DECORATION);
293
- element.dataset.startIndex = "".concat(cellColumnPositioning.left);
294
- element.dataset.endIndex = "".concat(cellColumnPositioning.right);
295
296
  var position = cellPos + cellNode.nodeSize - 1;
296
- return _prosemirrorView.Decoration.widget(position, element, {
297
+ return _prosemirrorView.Decoration.widget(position, function () {
298
+ var element = document.createElement('div');
299
+ element.classList.add(_types.TableCssClassName.RESIZE_HANDLE_DECORATION);
300
+ element.dataset.startIndex = "".concat(cellColumnPositioning.left);
301
+ element.dataset.endIndex = "".concat(cellColumnPositioning.right);
302
+ return element;
303
+ }, {
297
304
  key: "".concat(_types.TableDecorations.COLUMN_RESIZING_HANDLE, "_").concat(rowIndex, "_").concat(columnIndex)
298
305
  });
299
306
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "sideEffects": false
5
5
  }
@@ -63,7 +63,11 @@ export default class TableCellNodeView {
63
63
 
64
64
  update(node) {
65
65
  const didUpdate = this.updateNodeView(node);
66
- this.node = node;
66
+
67
+ if (didUpdate) {
68
+ this.node = node;
69
+ }
70
+
67
71
  return didUpdate;
68
72
  }
69
73
 
@@ -38,6 +38,7 @@ export const createPlugin = () => {
38
38
  }
39
39
 
40
40
  if (tr.docChanged || tr.selectionSet) {
41
+ pluginState = pluginState.map(tr.mapping, tr.doc);
41
42
  return handleDocOrSelectionChanged(tr, pluginState, oldState);
42
43
  }
43
44
 
@@ -1,6 +1,5 @@
1
1
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
2
2
  import { findTable } from '@atlaskit/editor-tables/utils';
3
- import { DecorationSet } from 'prosemirror-view';
4
3
  import { TableDecorations } from '../../../types';
5
4
  import { createColumnControlsDecoration, createColumnSelectedDecoration, findColumnControlSelectedDecoration, findControlsHoverDecoration, updateDecorations } from '../../../utils/decoration';
6
5
  import { composeDecorations } from './compose-decorations';
@@ -61,7 +60,7 @@ export const buildColumnControlsDecorations = ({
61
60
  tr
62
61
  }) => {
63
62
  return composeDecorations([removeColumnControlsSelectedDecoration, removeControlsHoverDecoration, maybeUpdateColumnSelectedDecoration, maybeUpdateColumnControlsDecoration])({
64
- decorationSet: DecorationSet.empty,
63
+ decorationSet,
65
64
  tr
66
65
  });
67
66
  };
@@ -110,14 +110,21 @@ export const createColumnControlsDecoration = selection => {
110
110
  const cells = getCellsInRow(0)(selection) || [];
111
111
  let index = 0;
112
112
  return cells.map(cell => {
113
- const colspan = cell.node.attrs.colspan || 1;
114
- const element = document.createElement('div');
115
- element.classList.add(ClassName.COLUMN_CONTROLS_DECORATIONS);
116
- element.dataset.startIndex = `${index}`;
117
- index += colspan;
118
- element.dataset.endIndex = `${index}`;
119
- return Decoration.widget(cell.pos + 1, () => element, {
120
- key: `${TableDecorations.COLUMN_CONTROLS_DECORATIONS}_${index}`,
113
+ const colspan = cell.node.attrs.colspan || 1; // It's important these values are scoped locally as the widget callback could be executed anytime in the future
114
+ // and we want to avoid value leak
115
+
116
+ const startIndex = index;
117
+ const endIndex = startIndex + colspan; // The next cell start index will commence from the current cell end index.
118
+
119
+ index = endIndex;
120
+ return Decoration.widget(cell.pos + 1, () => {
121
+ const element = document.createElement('div');
122
+ element.classList.add(ClassName.COLUMN_CONTROLS_DECORATIONS);
123
+ element.dataset.startIndex = `${startIndex}`;
124
+ element.dataset.endIndex = `${endIndex}`;
125
+ return element;
126
+ }, {
127
+ key: `${TableDecorations.COLUMN_CONTROLS_DECORATIONS}_${endIndex}`,
121
128
  // this decoration should be the first one, even before gap cursor.
122
129
  side: -100
123
130
  });
@@ -226,12 +233,14 @@ export const createResizeHandleDecoration = (tr, rowIndexTarget, columnEndIndexT
226
233
  }
227
234
 
228
235
  const createResizerHandleDecoration = (cellColumnPositioning, columnIndex, rowIndex, cellPos, cellNode) => {
229
- const element = document.createElement('div');
230
- element.classList.add(ClassName.RESIZE_HANDLE_DECORATION);
231
- element.dataset.startIndex = `${cellColumnPositioning.left}`;
232
- element.dataset.endIndex = `${cellColumnPositioning.right}`;
233
236
  const position = cellPos + cellNode.nodeSize - 1;
234
- return Decoration.widget(position, element, {
237
+ return Decoration.widget(position, () => {
238
+ const element = document.createElement('div');
239
+ element.classList.add(ClassName.RESIZE_HANDLE_DECORATION);
240
+ element.dataset.startIndex = `${cellColumnPositioning.left}`;
241
+ element.dataset.endIndex = `${cellColumnPositioning.right}`;
242
+ return element;
243
+ }, {
235
244
  key: `${TableDecorations.COLUMN_RESIZING_HANDLE}_${rowIndex}_${columnIndex}`
236
245
  });
237
246
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "sideEffects": false
5
5
  }
@@ -92,7 +92,11 @@ var TableCellNodeView = /*#__PURE__*/function () {
92
92
  key: "update",
93
93
  value: function update(node) {
94
94
  var didUpdate = this.updateNodeView(node);
95
- this.node = node;
95
+
96
+ if (didUpdate) {
97
+ this.node = node;
98
+ }
99
+
96
100
  return didUpdate;
97
101
  }
98
102
  }, {
@@ -42,6 +42,7 @@ export var createPlugin = function createPlugin() {
42
42
  }
43
43
 
44
44
  if (tr.docChanged || tr.selectionSet) {
45
+ pluginState = pluginState.map(tr.mapping, tr.doc);
45
46
  return handleDocOrSelectionChanged(tr, pluginState, oldState);
46
47
  }
47
48
 
@@ -1,6 +1,5 @@
1
1
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
2
2
  import { findTable } from '@atlaskit/editor-tables/utils';
3
- import { DecorationSet } from 'prosemirror-view';
4
3
  import { TableDecorations } from '../../../types';
5
4
  import { createColumnControlsDecoration, createColumnSelectedDecoration, findColumnControlSelectedDecoration, findControlsHoverDecoration, updateDecorations } from '../../../utils/decoration';
6
5
  import { composeDecorations } from './compose-decorations';
@@ -65,7 +64,7 @@ export var buildColumnControlsDecorations = function buildColumnControlsDecorati
65
64
  var decorationSet = _ref6.decorationSet,
66
65
  tr = _ref6.tr;
67
66
  return composeDecorations([removeColumnControlsSelectedDecoration, removeControlsHoverDecoration, maybeUpdateColumnSelectedDecoration, maybeUpdateColumnControlsDecoration])({
68
- decorationSet: DecorationSet.empty,
67
+ decorationSet: decorationSet,
69
68
  tr: tr
70
69
  });
71
70
  };
@@ -133,16 +133,21 @@ export var createColumnControlsDecoration = function createColumnControlsDecorat
133
133
  var cells = getCellsInRow(0)(selection) || [];
134
134
  var index = 0;
135
135
  return cells.map(function (cell) {
136
- var colspan = cell.node.attrs.colspan || 1;
137
- var element = document.createElement('div');
138
- element.classList.add(ClassName.COLUMN_CONTROLS_DECORATIONS);
139
- element.dataset.startIndex = "".concat(index);
140
- index += colspan;
141
- element.dataset.endIndex = "".concat(index);
136
+ var colspan = cell.node.attrs.colspan || 1; // It's important these values are scoped locally as the widget callback could be executed anytime in the future
137
+ // and we want to avoid value leak
138
+
139
+ var startIndex = index;
140
+ var endIndex = startIndex + colspan; // The next cell start index will commence from the current cell end index.
141
+
142
+ index = endIndex;
142
143
  return Decoration.widget(cell.pos + 1, function () {
144
+ var element = document.createElement('div');
145
+ element.classList.add(ClassName.COLUMN_CONTROLS_DECORATIONS);
146
+ element.dataset.startIndex = "".concat(startIndex);
147
+ element.dataset.endIndex = "".concat(endIndex);
143
148
  return element;
144
149
  }, {
145
- key: "".concat(TableDecorations.COLUMN_CONTROLS_DECORATIONS, "_").concat(index),
150
+ key: "".concat(TableDecorations.COLUMN_CONTROLS_DECORATIONS, "_").concat(endIndex),
146
151
  // this decoration should be the first one, even before gap cursor.
147
152
  side: -100
148
153
  });
@@ -253,12 +258,14 @@ export var createResizeHandleDecoration = function createResizeHandleDecoration(
253
258
  }
254
259
 
255
260
  var createResizerHandleDecoration = function createResizerHandleDecoration(cellColumnPositioning, columnIndex, rowIndex, cellPos, cellNode) {
256
- var element = document.createElement('div');
257
- element.classList.add(ClassName.RESIZE_HANDLE_DECORATION);
258
- element.dataset.startIndex = "".concat(cellColumnPositioning.left);
259
- element.dataset.endIndex = "".concat(cellColumnPositioning.right);
260
261
  var position = cellPos + cellNode.nodeSize - 1;
261
- return Decoration.widget(position, element, {
262
+ return Decoration.widget(position, function () {
263
+ var element = document.createElement('div');
264
+ element.classList.add(ClassName.RESIZE_HANDLE_DECORATION);
265
+ element.dataset.startIndex = "".concat(cellColumnPositioning.left);
266
+ element.dataset.endIndex = "".concat(cellColumnPositioning.right);
267
+ return element;
268
+ }, {
262
269
  key: "".concat(TableDecorations.COLUMN_RESIZING_HANDLE, "_").concat(rowIndex, "_").concat(columnIndex)
263
270
  });
264
271
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "sideEffects": false
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -1,3 +1,3 @@
1
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:5cd747accdc40bfc52f004ff689a3df00173ee2f27d15c68f3a76172c11050fd
3
- size 13990
2
+ oid sha256:185a432916fe30487eec362617c510dd132f2a37a56bfceeca674da4c6512dc9
3
+ size 13986
@@ -99,7 +99,9 @@ export default class TableCellNodeView implements NodeView {
99
99
 
100
100
  update(node: Node) {
101
101
  const didUpdate = this.updateNodeView(node);
102
- this.node = node;
102
+ if (didUpdate) {
103
+ this.node = node;
104
+ }
103
105
  return didUpdate;
104
106
  }
105
107
 
@@ -60,6 +60,7 @@ export const createPlugin = () => {
60
60
  }
61
61
 
62
62
  if (tr.docChanged || tr.selectionSet) {
63
+ pluginState = pluginState.map(tr.mapping, tr.doc);
63
64
  return handleDocOrSelectionChanged(tr, pluginState, oldState);
64
65
  }
65
66
 
@@ -83,5 +83,5 @@ export const buildColumnControlsDecorations: DecorationTransformer = ({
83
83
  removeControlsHoverDecoration,
84
84
  maybeUpdateColumnSelectedDecoration,
85
85
  maybeUpdateColumnControlsDecoration,
86
- ])({ decorationSet: DecorationSet.empty, tr });
86
+ ])({ decorationSet, tr });
87
87
  };
@@ -182,17 +182,29 @@ export const createColumnControlsDecoration = (
182
182
  let index = 0;
183
183
  return cells.map((cell) => {
184
184
  const colspan = (cell.node.attrs as CellAttributes).colspan || 1;
185
- const element = document.createElement('div');
186
- element.classList.add(ClassName.COLUMN_CONTROLS_DECORATIONS);
187
- element.dataset.startIndex = `${index}`;
188
- index += colspan;
189
- element.dataset.endIndex = `${index}`;
190
-
191
- return Decoration.widget(cell.pos + 1, () => element, {
192
- key: `${TableDecorations.COLUMN_CONTROLS_DECORATIONS}_${index}`,
193
- // this decoration should be the first one, even before gap cursor.
194
- side: -100,
195
- });
185
+ // It's important these values are scoped locally as the widget callback could be executed anytime in the future
186
+ // and we want to avoid value leak
187
+ const startIndex = index;
188
+ const endIndex = startIndex + colspan;
189
+
190
+ // The next cell start index will commence from the current cell end index.
191
+ index = endIndex;
192
+
193
+ return Decoration.widget(
194
+ cell.pos + 1,
195
+ () => {
196
+ const element = document.createElement('div');
197
+ element.classList.add(ClassName.COLUMN_CONTROLS_DECORATIONS);
198
+ element.dataset.startIndex = `${startIndex}`;
199
+ element.dataset.endIndex = `${endIndex}`;
200
+ return element;
201
+ },
202
+ {
203
+ key: `${TableDecorations.COLUMN_CONTROLS_DECORATIONS}_${endIndex}`,
204
+ // this decoration should be the first one, even before gap cursor.
205
+ side: -100,
206
+ },
207
+ );
196
208
  });
197
209
  };
198
210
 
@@ -312,16 +324,20 @@ export const createResizeHandleDecoration = (
312
324
  cellPos: number,
313
325
  cellNode: PmNode,
314
326
  ): Decoration => {
315
- const element = document.createElement('div');
316
- element.classList.add(ClassName.RESIZE_HANDLE_DECORATION);
317
-
318
- element.dataset.startIndex = `${cellColumnPositioning.left}`;
319
- element.dataset.endIndex = `${cellColumnPositioning.right}`;
320
327
  const position = cellPos + cellNode.nodeSize - 1;
321
-
322
- return Decoration.widget(position, element, {
323
- key: `${TableDecorations.COLUMN_RESIZING_HANDLE}_${rowIndex}_${columnIndex}`,
324
- });
328
+ return Decoration.widget(
329
+ position,
330
+ () => {
331
+ const element = document.createElement('div');
332
+ element.classList.add(ClassName.RESIZE_HANDLE_DECORATION);
333
+ element.dataset.startIndex = `${cellColumnPositioning.left}`;
334
+ element.dataset.endIndex = `${cellColumnPositioning.right}`;
335
+ return element;
336
+ },
337
+ {
338
+ key: `${TableDecorations.COLUMN_RESIZING_HANDLE}_${rowIndex}_${columnIndex}`,
339
+ },
340
+ );
325
341
  };
326
342
 
327
343
  const createLastCellElementDecoration = (