@atlaskit/editor-plugin-table 0.1.2 → 0.2.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 (62) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/cjs/plugins/table/commands/misc.js +4 -2
  3. package/dist/cjs/plugins/table/create-plugin-config.js +0 -1
  4. package/dist/cjs/plugins/table/event-handlers.js +5 -6
  5. package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-resizing.js +2 -2
  6. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/dom.js +3 -5
  7. package/dist/cjs/plugins/table/reducer.js +3 -2
  8. package/dist/cjs/plugins/table/types.js +2 -1
  9. package/dist/cjs/plugins/table/ui/common-styles.js +8 -1
  10. package/dist/cjs/plugins/table/ui/ui-styles.js +4 -4
  11. package/dist/cjs/plugins/table/utils/column-controls.js +1 -1
  12. package/dist/cjs/plugins/table/utils/decoration.js +16 -5
  13. package/dist/cjs/version.json +1 -1
  14. package/dist/es2019/plugins/table/commands/misc.js +4 -2
  15. package/dist/es2019/plugins/table/create-plugin-config.js +0 -1
  16. package/dist/es2019/plugins/table/event-handlers.js +6 -7
  17. package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-resizing.js +2 -2
  18. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/dom.js +3 -8
  19. package/dist/es2019/plugins/table/reducer.js +3 -2
  20. package/dist/es2019/plugins/table/types.js +2 -1
  21. package/dist/es2019/plugins/table/ui/common-styles.js +16 -17
  22. package/dist/es2019/plugins/table/ui/ui-styles.js +67 -24
  23. package/dist/es2019/plugins/table/utils/column-controls.js +1 -1
  24. package/dist/es2019/plugins/table/utils/decoration.js +16 -5
  25. package/dist/es2019/version.json +1 -1
  26. package/dist/esm/plugins/table/commands/misc.js +4 -2
  27. package/dist/esm/plugins/table/create-plugin-config.js +0 -1
  28. package/dist/esm/plugins/table/event-handlers.js +6 -7
  29. package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-resizing.js +2 -2
  30. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/dom.js +3 -8
  31. package/dist/esm/plugins/table/reducer.js +3 -2
  32. package/dist/esm/plugins/table/types.js +2 -1
  33. package/dist/esm/plugins/table/ui/common-styles.js +8 -1
  34. package/dist/esm/plugins/table/ui/ui-styles.js +5 -5
  35. package/dist/esm/plugins/table/utils/column-controls.js +1 -1
  36. package/dist/esm/plugins/table/utils/decoration.js +16 -5
  37. package/dist/esm/version.json +1 -1
  38. package/dist/types/plugins/table/commands/misc.d.ts +1 -1
  39. package/dist/types/plugins/table/pm-plugins/decorations/utils/column-resizing.d.ts +1 -1
  40. package/dist/types/plugins/table/types.d.ts +3 -1
  41. package/dist/types/plugins/table/utils/decoration.d.ts +1 -1
  42. package/package.json +2 -2
  43. package/src/__tests__/unit/event-handlers.ts +1 -1
  44. package/src/__tests__/unit/pm-plugins/decorations/column-resizing.ts +5 -4
  45. package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +8 -0
  46. package/src/__tests__/visual-regression/__fixtures__/sticky-header-with-horizontal-scroll.json +5228 -0
  47. package/src/__tests__/visual-regression/__image_snapshots__/sticky-header-ts-snapshot-test-table-sticky-header-should-align-with-table-cell-when-active-1-snap.png +3 -0
  48. package/src/__tests__/visual-regression/__image_snapshots__/sticky-header-ts-snapshot-test-table-sticky-header-should-align-with-table-cell-when-active-2-snap.png +3 -0
  49. package/src/__tests__/visual-regression/cell-options-menu.ts +110 -99
  50. package/src/__tests__/visual-regression/index.ts +56 -44
  51. package/src/__tests__/visual-regression/sticky-header.ts +55 -0
  52. package/src/plugins/table/commands/misc.ts +10 -2
  53. package/src/plugins/table/create-plugin-config.ts +0 -1
  54. package/src/plugins/table/event-handlers.ts +9 -7
  55. package/src/plugins/table/pm-plugins/decorations/utils/column-resizing.ts +4 -2
  56. package/src/plugins/table/pm-plugins/table-resizing/utils/dom.ts +5 -11
  57. package/src/plugins/table/reducer.ts +3 -1
  58. package/src/plugins/table/types.ts +7 -2
  59. package/src/plugins/table/ui/common-styles.ts +16 -20
  60. package/src/plugins/table/ui/ui-styles.ts +66 -25
  61. package/src/plugins/table/utils/column-controls.ts +1 -1
  62. package/src/plugins/table/utils/decoration.ts +17 -4
@@ -238,7 +238,7 @@ var makeArray = function makeArray(n) {
238
238
  */
239
239
 
240
240
 
241
- export var createResizeHandleDecoration = function createResizeHandleDecoration(tr, columnEndIndexTarget) {
241
+ export var createResizeHandleDecoration = function createResizeHandleDecoration(tr, rowIndexTarget, columnEndIndexTarget) {
242
242
  var emptyResult = [[], []];
243
243
  var table = findTable(tr.selection);
244
244
 
@@ -292,6 +292,10 @@ export var createResizeHandleDecoration = function createResizeHandleDecoration(
292
292
  for (var rowIndex = 0; rowIndex < map.height; rowIndex++) {
293
293
  var seen = {};
294
294
 
295
+ if (rowIndex !== rowIndexTarget) {
296
+ continue;
297
+ }
298
+
295
299
  for (var columnIndex = 0; columnIndex < map.width; columnIndex++) {
296
300
  var cellPosition = map.map[map.width * rowIndex + columnIndex];
297
301
 
@@ -380,16 +384,23 @@ export var createColumnLineResize = function createColumnLineResize(selection, c
380
384
  return [];
381
385
  }
382
386
 
383
- var columnIndex = cellColumnPositioning.right - 1;
387
+ var columnIndex = cellColumnPositioning.right;
384
388
  var map = TableMap.get(table.node);
389
+ var isLastColumn = columnIndex === map.width;
390
+
391
+ if (isLastColumn) {
392
+ columnIndex -= 1;
393
+ }
394
+
395
+ var decorationClassName = isLastColumn ? ClassName.WITH_RESIZE_LINE_LAST_COLUMN : ClassName.WITH_RESIZE_LINE;
385
396
  var cellPositions = makeArray(map.height).map(function (rowIndex) {
386
397
  return map.map[map.width * rowIndex + columnIndex];
387
398
  }).filter(function (cellPosition, rowIndex) {
388
- if (columnIndex === map.width) {
399
+ if (isLastColumn) {
389
400
  return true; // If is the last column no filter applied
390
401
  }
391
402
 
392
- var nextPosition = map.map[map.width * rowIndex + columnIndex + 1];
403
+ var nextPosition = map.map[map.width * rowIndex + columnIndex - 1];
393
404
  return cellPosition !== nextPosition; // Removed it if next position is merged
394
405
  });
395
406
  var cells = cellPositions.map(function (pos) {
@@ -404,7 +415,7 @@ export var createColumnLineResize = function createColumnLineResize(selection, c
404
415
  }
405
416
 
406
417
  return Decoration.node(cell.pos, cell.pos + cell.node.nodeSize, {
407
- class: ClassName.WITH_RESIZE_LINE
418
+ class: decorationClassName
408
419
  }, {
409
420
  key: "".concat(TableDecorations.COLUMN_RESIZING_HANDLE_LINE, "_").concat(cellColumnPositioning.right, "_").concat(index)
410
421
  });
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "0.1.2"
3
+ "version": "0.2.1"
4
4
  }
@@ -20,7 +20,7 @@ export declare const selectRow: (row: number, expand?: boolean | undefined) => C
20
20
  export declare const showInsertColumnButton: (columnIndex: number) => Command;
21
21
  export declare const showInsertRowButton: (rowIndex: number) => Command;
22
22
  export declare const hideInsertColumnOrRowButton: () => Command;
23
- export declare const addResizeHandleDecorations: (columnIndex: number) => Command;
23
+ export declare const addResizeHandleDecorations: (rowIndex: number, columnIndex: number) => Command;
24
24
  export declare const autoSizeTable: (view: EditorView, node: PMNode, table: HTMLTableElement, basePos: number, opts: {
25
25
  containerWidth: number;
26
26
  }) => boolean;
@@ -1,2 +1,2 @@
1
1
  import { DecorationTransformer } from './types';
2
- export declare const buildColumnResizingDecorations: (columnEndIndex: number) => DecorationTransformer;
2
+ export declare const buildColumnResizingDecorations: (rowEndIndex: number, columnEndIndex: number) => DecorationTransformer;
@@ -32,7 +32,6 @@ export interface PluginConfig {
32
32
  allowAddColumnWithCustomStep?: boolean;
33
33
  allowCollapse?: boolean;
34
34
  isHeaderRowRequired?: boolean;
35
- stickToolbarToBottom?: boolean;
36
35
  permittedLayouts?: PermittedLayoutsDescriptor;
37
36
  allowControls?: boolean;
38
37
  stickyHeaders?: boolean;
@@ -79,6 +78,7 @@ export interface TablePluginState {
79
78
  isFullWidthModeEnabled?: boolean;
80
79
  layout?: TableLayout;
81
80
  ordering?: TableColumnOrdering;
81
+ resizeHandleRowIndex?: number;
82
82
  resizeHandleColumnIndex?: number;
83
83
  tableCellOptimization?: boolean;
84
84
  isTableCollapsed?: boolean;
@@ -139,6 +139,7 @@ export declare type TablePluginAction = {
139
139
  type: 'ADD_RESIZE_HANDLE_DECORATIONS';
140
140
  data: {
141
141
  decorationSet: DecorationSet;
142
+ resizeHandleRowIndex: number;
142
143
  resizeHandleColumnIndex: number;
143
144
  };
144
145
  } | {
@@ -281,6 +282,7 @@ export declare const TableCssClassName: {
281
282
  TOP_LEFT_CELL: string;
282
283
  LAST_ITEM_IN_CELL: string;
283
284
  WITH_RESIZE_LINE: string;
285
+ WITH_RESIZE_LINE_LAST_COLUMN: string;
284
286
  TABLE_CONTAINER: string;
285
287
  TABLE_NODE_WRAPPER: string;
286
288
  TABLE_LEFT_SHADOW: string;
@@ -9,5 +9,5 @@ export declare const createControlsHoverDecoration: (cells: Cell[], type: 'row'
9
9
  export declare const createColumnSelectedDecoration: (tr: Transaction | ReadonlyTransaction) => Decoration[];
10
10
  export declare const createColumnControlsDecoration: (selection: Selection) => Decoration[];
11
11
  export declare const updateDecorations: (node: PmNode, decorationSet: DecorationSet, decorations: Decoration[], key: TableDecorations) => DecorationSet;
12
- export declare const createResizeHandleDecoration: (tr: Transaction | ReadonlyTransaction, columnEndIndexTarget: Omit<CellColumnPositioning, 'left'>) => [Decoration[], Decoration[]];
12
+ export declare const createResizeHandleDecoration: (tr: Transaction | ReadonlyTransaction, rowIndexTarget: number, columnEndIndexTarget: Omit<CellColumnPositioning, 'left'>) => [Decoration[], Decoration[]];
13
13
  export declare const createColumnLineResize: (selection: Selection, cellColumnPositioning: Omit<CellColumnPositioning, 'left'>) => Decoration[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "0.1.2",
3
+ "version": "0.2.1",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@atlaskit/adf-schema": "^24.0.0",
21
- "@atlaskit/editor-common": "^70.2.0",
21
+ "@atlaskit/editor-common": "^70.3.0",
22
22
  "@atlaskit/editor-shared-styles": "^2.2.0",
23
23
  "@atlaskit/editor-tables": "^2.2.0",
24
24
  "@atlaskit/icon": "^21.11.0",
@@ -208,7 +208,7 @@ describe('table event handlers', () => {
208
208
  );
209
209
  const { state, dispatch } = editorView;
210
210
 
211
- addResizeHandleDecorations(0)(state, dispatch);
211
+ addResizeHandleDecorations(0, 0)(state, dispatch);
212
212
 
213
213
  const firstCell = editorView.domAtPos(refs['<>']);
214
214
  const event = {
@@ -66,17 +66,18 @@ describe('tables: column resizing decorations', () => {
66
66
 
67
67
  describe('#buildColumnResizingDecorations', () => {
68
68
  describe.each([
69
- [-1, TableDecorations.COLUMN_RESIZING_HANDLE, 0],
70
- [0, TableDecorations.COLUMN_RESIZING_HANDLE, 0],
71
- [1, TableDecorations.COLUMN_RESIZING_HANDLE, 1],
69
+ [0, -1, TableDecorations.COLUMN_RESIZING_HANDLE, 0],
70
+ [0, 0, TableDecorations.COLUMN_RESIZING_HANDLE, 0],
71
+ [0, 1, TableDecorations.COLUMN_RESIZING_HANDLE, 1],
72
72
  ])(
73
73
  'when columnEndIndex is %i',
74
- (columnEndIndex, decorationKey, expectedDecorations) => {
74
+ (rowEndIndex, columnEndIndex, decorationKey, expectedDecorations) => {
75
75
  it(`should return a decorationSet with ${expectedDecorations} ${decorationKey} type`, () => {
76
76
  const {
77
77
  editorView: { state },
78
78
  } = editor(doc(table()(tr(tdCursor, tdEmpty))));
79
79
  const nextDecorationSet = buildColumnResizingDecorations(
80
+ rowEndIndex,
80
81
  columnEndIndex,
81
82
  )({
82
83
  decorationSet: DecorationSet.empty,
@@ -134,28 +134,36 @@ describe('Floating Delete Button', () => {
134
134
  expect(screen.getAllByLabelText('Delete row').length).toBe(1);
135
135
  });
136
136
  });
137
+
137
138
  describe('when deleting with the delete button', () => {
138
139
  describe('Columns', () => {
139
140
  it('should move cursor within the table after delete', () => {
140
141
  selectColumns([0, 1])(editorView.state, editorView.dispatch);
141
142
  component({ selection: editorView.state.selection, editorView });
143
+
142
144
  const { tr } = editorView.state;
143
145
  const { pos } = getCellsInColumn(2)(tr.selection)![2];
144
146
  const lastCellPos = tr.doc.resolve(pos).pos + 1;
147
+
145
148
  fireEvent.click(screen.getByLabelText('Delete column'));
149
+
146
150
  expect(editorView.state.selection.from).toBeLessThanOrEqual(
147
151
  lastCellPos,
148
152
  );
149
153
  });
150
154
  });
155
+
151
156
  describe('Rows', () => {
152
157
  it('should move cursor within the table after delete', () => {
153
158
  selectRows([0, 1])(editorView.state, editorView.dispatch);
154
159
  component({ selection: editorView.state.selection, editorView });
160
+
155
161
  const { tr } = editorView.state;
156
162
  const { pos } = getCellsInColumn(2)(tr.selection)![2];
157
163
  const lastCellPos = tr.doc.resolve(pos).pos + 1;
164
+
158
165
  fireEvent.click(screen.getByLabelText('Delete row'));
166
+
159
167
  expect(editorView.state.selection.from).toBeLessThanOrEqual(
160
168
  lastCellPos,
161
169
  );