@atlaskit/editor-plugin-table 0.2.6 → 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.
Files changed (83) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/cjs/plugins/table/commands/index.js +9 -1
  3. package/dist/cjs/plugins/table/commands/referentiality.js +23 -0
  4. package/dist/cjs/plugins/table/event-handlers.js +5 -1
  5. package/dist/cjs/plugins/table/nodeviews/table.js +10 -1
  6. package/dist/cjs/plugins/table/nodeviews/tableCell.js +5 -1
  7. package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +1 -0
  8. package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -3
  9. package/dist/cjs/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +15 -12
  10. package/dist/cjs/plugins/table/toolbar.js +78 -35
  11. package/dist/cjs/plugins/table/ui/common-styles.js +6 -3
  12. package/dist/cjs/plugins/table/ui/messages.js +17 -2
  13. package/dist/cjs/plugins/table/ui/ui-styles.js +2 -7
  14. package/dist/cjs/plugins/table/utils/decoration.js +19 -12
  15. package/dist/cjs/version.json +1 -1
  16. package/dist/es2019/plugins/table/commands/index.js +2 -1
  17. package/dist/es2019/plugins/table/commands/referentiality.js +10 -0
  18. package/dist/es2019/plugins/table/event-handlers.js +3 -1
  19. package/dist/es2019/plugins/table/nodeviews/table.js +13 -1
  20. package/dist/es2019/plugins/table/nodeviews/tableCell.js +5 -1
  21. package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +1 -0
  22. package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -2
  23. package/dist/es2019/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +16 -11
  24. package/dist/es2019/plugins/table/toolbar.js +65 -29
  25. package/dist/es2019/plugins/table/ui/common-styles.js +15 -5
  26. package/dist/es2019/plugins/table/ui/messages.js +17 -2
  27. package/dist/es2019/plugins/table/ui/ui-styles.js +24 -16
  28. package/dist/es2019/plugins/table/utils/decoration.js +22 -13
  29. package/dist/es2019/version.json +1 -1
  30. package/dist/esm/plugins/table/commands/index.js +2 -1
  31. package/dist/esm/plugins/table/commands/referentiality.js +12 -0
  32. package/dist/esm/plugins/table/event-handlers.js +5 -1
  33. package/dist/esm/plugins/table/nodeviews/table.js +10 -1
  34. package/dist/esm/plugins/table/nodeviews/tableCell.js +5 -1
  35. package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +1 -0
  36. package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +1 -2
  37. package/dist/esm/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +15 -12
  38. package/dist/esm/plugins/table/toolbar.js +74 -29
  39. package/dist/esm/plugins/table/ui/common-styles.js +6 -3
  40. package/dist/esm/plugins/table/ui/messages.js +17 -2
  41. package/dist/esm/plugins/table/ui/ui-styles.js +2 -6
  42. package/dist/esm/plugins/table/utils/decoration.js +19 -12
  43. package/dist/esm/version.json +1 -1
  44. package/dist/types/plugins/table/commands/index.d.ts +1 -0
  45. package/dist/types/plugins/table/commands/referentiality.d.ts +2 -0
  46. package/dist/types/plugins/table/index.d.ts +2 -3
  47. package/dist/types/plugins/table/nodeviews/table.d.ts +4 -1
  48. package/dist/types/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +0 -1
  49. package/dist/types/plugins/table/ui/common-styles.d.ts +4 -1
  50. package/dist/types/plugins/table/ui/messages.d.ts +15 -0
  51. package/package.json +6 -6
  52. package/report.api.md +6 -6
  53. package/src/__tests__/integration/__fixtures__/table-and-paragraph-adf.json +130 -0
  54. package/src/__tests__/integration/floating-toolbar.ts +54 -0
  55. package/src/__tests__/integration/meta-arrowup-cursor-in-first-row.ts +37 -0
  56. package/src/__tests__/unit/color-picker.ts +100 -0
  57. package/src/__tests__/unit/get-toolbar-config.ts +1 -4
  58. package/src/__tests__/unit/keymap.ts +1 -1
  59. package/src/__tests__/unit/nodeviews/cell.ts +52 -57
  60. package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +90 -8
  61. package/src/__tests__/unit/transforms/delete-columns.ts +1 -1
  62. package/src/__tests__/unit/transforms/delete-rows.ts +1 -1
  63. package/src/__tests__/unit/utils/collapse.ts +2 -2
  64. package/src/__tests__/visual-regression/__image_snapshots__/cell-options-menu-ts-table-cell-options-menu-delete-row-menu-item-should-remove-the-table-row-on-click-1-snap.png +2 -2
  65. package/src/plugins/table/commands/index.ts +1 -0
  66. package/src/plugins/table/commands/referentiality.ts +14 -0
  67. package/src/plugins/table/event-handlers.ts +7 -1
  68. package/src/plugins/table/index.tsx +6 -1
  69. package/src/plugins/table/nodeviews/table.tsx +16 -1
  70. package/src/plugins/table/nodeviews/tableCell.tsx +3 -1
  71. package/src/plugins/table/pm-plugins/decorations/plugin.ts +1 -0
  72. package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +1 -1
  73. package/src/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.ts +12 -10
  74. package/src/plugins/table/toolbar.tsx +84 -28
  75. package/src/plugins/table/ui/common-styles.ts +20 -4
  76. package/src/plugins/table/ui/messages.ts +18 -3
  77. package/src/plugins/table/ui/ui-styles.ts +23 -14
  78. package/src/plugins/table/utils/decoration.ts +36 -20
  79. package/dist/cjs/plugins/table/utils/referentiality.js +0 -29
  80. package/dist/es2019/plugins/table/utils/referentiality.js +0 -18
  81. package/dist/esm/plugins/table/utils/referentiality.js +0 -20
  82. package/dist/types/plugins/table/utils/referentiality.d.ts +0 -2
  83. package/src/plugins/table/utils/referentiality.ts +0 -24
@@ -243,22 +243,27 @@ export const DeleteButton = css`
243
243
  }
244
244
  `;
245
245
 
246
- // TODO: https://product-fabric.atlassian.net/browse/DSP-4451
247
- /* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
248
246
  export const OverflowShadow = (props: ThemeProps) => css`
249
247
  .${ClassName.TABLE_RIGHT_SHADOW}, .${ClassName.TABLE_LEFT_SHADOW} {
250
248
  display: block;
251
- height: calc(
252
- 100% - ${tableMarginTop + tableMarginBottom + tableToolbarSize - 2}px
253
- );
249
+ height: calc(100% - ${tableMarginTop + tableMarginBottom}px);
254
250
  position: absolute;
255
251
  pointer-events: none;
256
- top: ${tableMarginTop + tableToolbarSize - 1}px;
252
+ top: ${tableMarginTop}px;
257
253
  z-index: ${akEditorShadowZIndex};
258
254
  width: 8px;
259
255
  }
260
256
  .${ClassName.TABLE_LEFT_SHADOW} {
261
- background: linear-gradient(to left, rgba(99, 114, 130, 0) 0, ${N40A} 100%);
257
+ background: linear-gradient(
258
+ to left,
259
+ transparent 0,
260
+ ${token('elevation.shadow.overflow.spread', N40A)} 100%
261
+ ),
262
+ linear-gradient(
263
+ to right,
264
+ ${token('elevation.shadow.overflow.perimeter', 'transparent')} 0px,
265
+ transparent 1px
266
+ );
262
267
  left: 0px;
263
268
  }
264
269
  .${ClassName.TABLE_CONTAINER}[data-number-column='true'] > :not(.${ClassName.TABLE_STICKY_SHADOW}).${ClassName.TABLE_LEFT_SHADOW} {
@@ -266,23 +271,27 @@ export const OverflowShadow = (props: ThemeProps) => css`
266
271
  }
267
272
  .${ClassName.TABLE_RIGHT_SHADOW} {
268
273
  background: linear-gradient(
269
- to right,
270
- rgba(99, 114, 130, 0) 0,
271
- ${N40A} 100%
272
- );
274
+ to right,
275
+ transparent 0,
276
+ ${token('elevation.shadow.overflow.spread', N40A)} 100%
277
+ ),
278
+ linear-gradient(
279
+ to left,
280
+ ${token('elevation.shadow.overflow.perimeter', 'transparent')} 0px,
281
+ transparent 1px
282
+ );
273
283
  left: calc(100% + 2px);
274
284
  }
275
285
  .${ClassName.WITH_CONTROLS} {
276
286
  .${ClassName.TABLE_RIGHT_SHADOW}, .${ClassName.TABLE_LEFT_SHADOW} {
277
- height: calc(100% - ${tableMarginTop + tableMarginBottom - 2}px);
278
- top: ${tableMarginTop - 1}px;
287
+ height: calc(100% - ${tableMarginTop + tableMarginBottom}px);
288
+ top: ${tableMarginTop}px;
279
289
  }
280
290
  .${ClassName.TABLE_LEFT_SHADOW} {
281
291
  border-left: 1px solid ${tableBorderColor(props)};
282
292
  }
283
293
  }
284
294
  `;
285
- /* eslint-enable @atlaskit/design-system/ensure-design-token-usage */
286
295
 
287
296
  const columnHeaderButton = (props: ThemeProps, cssString?: string) => css`
288
297
  background: ${tableToolbarColor(props)};
@@ -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 = (
@@ -1,29 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isReferencedSource = void 0;
7
-
8
- var isReferencedSource = function isReferencedSource(state, localId) {
9
- var found = false;
10
- state.doc.descendants(function (node) {
11
- if (found) {
12
- return false;
13
- }
14
-
15
- var dataConsumer = node.marks.find(function (mark) {
16
- return mark.type === state.schema.marks.dataConsumer;
17
- });
18
-
19
- if (!dataConsumer) {
20
- return true;
21
- }
22
-
23
- found = (dataConsumer.attrs.sources || []).includes(localId);
24
- return !found;
25
- });
26
- return found;
27
- };
28
-
29
- exports.isReferencedSource = isReferencedSource;
@@ -1,18 +0,0 @@
1
- export const isReferencedSource = (state, localId) => {
2
- let found = false;
3
- state.doc.descendants(node => {
4
- if (found) {
5
- return false;
6
- }
7
-
8
- const dataConsumer = node.marks.find(mark => mark.type === state.schema.marks.dataConsumer);
9
-
10
- if (!dataConsumer) {
11
- return true;
12
- }
13
-
14
- found = (dataConsumer.attrs.sources || []).includes(localId);
15
- return !found;
16
- });
17
- return found;
18
- };
@@ -1,20 +0,0 @@
1
- export var isReferencedSource = function isReferencedSource(state, localId) {
2
- var found = false;
3
- state.doc.descendants(function (node) {
4
- if (found) {
5
- return false;
6
- }
7
-
8
- var dataConsumer = node.marks.find(function (mark) {
9
- return mark.type === state.schema.marks.dataConsumer;
10
- });
11
-
12
- if (!dataConsumer) {
13
- return true;
14
- }
15
-
16
- found = (dataConsumer.attrs.sources || []).includes(localId);
17
- return !found;
18
- });
19
- return found;
20
- };
@@ -1,2 +0,0 @@
1
- import { EditorState } from 'prosemirror-state';
2
- export declare const isReferencedSource: (state: EditorState, localId: string) => boolean;
@@ -1,24 +0,0 @@
1
- import { EditorState } from 'prosemirror-state';
2
-
3
- export const isReferencedSource = (state: EditorState, localId: string) => {
4
- let found = false;
5
-
6
- state.doc.descendants((node) => {
7
- if (found) {
8
- return false;
9
- }
10
-
11
- const dataConsumer = node.marks.find(
12
- (mark) => mark.type === state.schema.marks.dataConsumer,
13
- );
14
-
15
- if (!dataConsumer) {
16
- return true;
17
- }
18
-
19
- found = (dataConsumer.attrs.sources || []).includes(localId);
20
- return !found;
21
- });
22
-
23
- return found;
24
- };