@atlaskit/editor-plugin-table 0.1.2 → 0.2.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/plugins/table/commands/misc.js +4 -2
  3. package/dist/cjs/plugins/table/event-handlers.js +5 -6
  4. package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-resizing.js +2 -2
  5. package/dist/cjs/plugins/table/reducer.js +3 -2
  6. package/dist/cjs/plugins/table/types.js +2 -1
  7. package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
  8. package/dist/cjs/plugins/table/ui/ui-styles.js +3 -3
  9. package/dist/cjs/plugins/table/utils/decoration.js +16 -5
  10. package/dist/cjs/version.json +1 -1
  11. package/dist/es2019/plugins/table/commands/misc.js +4 -2
  12. package/dist/es2019/plugins/table/event-handlers.js +6 -7
  13. package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-resizing.js +2 -2
  14. package/dist/es2019/plugins/table/reducer.js +3 -2
  15. package/dist/es2019/plugins/table/types.js +2 -1
  16. package/dist/es2019/plugins/table/ui/common-styles.js +0 -9
  17. package/dist/es2019/plugins/table/ui/ui-styles.js +67 -19
  18. package/dist/es2019/plugins/table/utils/decoration.js +16 -5
  19. package/dist/es2019/version.json +1 -1
  20. package/dist/esm/plugins/table/commands/misc.js +4 -2
  21. package/dist/esm/plugins/table/event-handlers.js +6 -7
  22. package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-resizing.js +2 -2
  23. package/dist/esm/plugins/table/reducer.js +3 -2
  24. package/dist/esm/plugins/table/types.js +2 -1
  25. package/dist/esm/plugins/table/ui/common-styles.js +1 -1
  26. package/dist/esm/plugins/table/ui/ui-styles.js +4 -4
  27. package/dist/esm/plugins/table/utils/decoration.js +16 -5
  28. package/dist/esm/version.json +1 -1
  29. package/dist/types/plugins/table/commands/misc.d.ts +1 -1
  30. package/dist/types/plugins/table/pm-plugins/decorations/utils/column-resizing.d.ts +1 -1
  31. package/dist/types/plugins/table/types.d.ts +3 -0
  32. package/dist/types/plugins/table/utils/decoration.d.ts +1 -1
  33. package/package.json +2 -2
  34. package/src/__tests__/unit/event-handlers.ts +1 -1
  35. package/src/__tests__/unit/pm-plugins/decorations/column-resizing.ts +5 -4
  36. package/src/plugins/table/commands/misc.ts +10 -2
  37. package/src/plugins/table/event-handlers.ts +9 -7
  38. package/src/plugins/table/pm-plugins/decorations/utils/column-resizing.ts +4 -2
  39. package/src/plugins/table/reducer.ts +3 -1
  40. package/src/plugins/table/types.ts +7 -1
  41. package/src/plugins/table/ui/common-styles.ts +0 -12
  42. package/src/plugins/table/ui/ui-styles.ts +66 -19
  43. package/src/plugins/table/utils/decoration.ts +17 -4
@@ -116,6 +116,7 @@ export interface TablePluginState {
116
116
  isFullWidthModeEnabled?: boolean;
117
117
  layout?: TableLayout;
118
118
  ordering?: TableColumnOrdering;
119
+ resizeHandleRowIndex?: number;
119
120
  resizeHandleColumnIndex?: number;
120
121
  tableCellOptimization?: boolean;
121
122
  // for table wrap/collapse
@@ -172,7 +173,11 @@ export type TablePluginAction =
172
173
  }
173
174
  | {
174
175
  type: 'ADD_RESIZE_HANDLE_DECORATIONS';
175
- data: { decorationSet: DecorationSet; resizeHandleColumnIndex: number };
176
+ data: {
177
+ decorationSet: DecorationSet;
178
+ resizeHandleRowIndex: number;
179
+ resizeHandleColumnIndex: number;
180
+ };
176
181
  }
177
182
  | { type: 'CLEAR_HOVER_SELECTION'; data: { decorationSet: DecorationSet } }
178
183
  | { type: 'SHOW_RESIZE_HANDLE_LINE'; data: { decorationSet: DecorationSet } }
@@ -302,6 +307,7 @@ export const TableCssClassName = {
302
307
  LAST_ITEM_IN_CELL: `${tablePrefixSelector}-last-item-in-cell`,
303
308
 
304
309
  WITH_RESIZE_LINE: `${tablePrefixSelector}-column-resize-line`,
310
+ WITH_RESIZE_LINE_LAST_COLUMN: `${tablePrefixSelector}-column-resize-line-last-column`,
305
311
  };
306
312
 
307
313
  export interface ToolbarMenuConfig {
@@ -394,18 +394,6 @@ export const tableStyles = (props: ThemeProps) => css`
394
394
  `,
395
395
  )};
396
396
  }
397
-
398
- .${ClassName.CORNER_CONTROLS_INSERT_COLUMN_MARKER} {
399
- position: relative;
400
-
401
- ${InsertMarker(
402
- props,
403
- `
404
- right: -1px;
405
- top: -12px;
406
- `,
407
- )};
408
- }
409
397
  }
410
398
 
411
399
  .${ClassName.CORNER_CONTROLS}.sticky {
@@ -28,7 +28,6 @@ import {
28
28
  tableCellDeleteColor,
29
29
  tableBorderDeleteColor,
30
30
  tableToolbarDeleteColor,
31
- lineMarkerOffsetFromColumnControls,
32
31
  lineMarkerSize,
33
32
  columnControlsDecorationHeight,
34
33
  columnControlsZIndex,
@@ -211,13 +210,6 @@ export const columnControlsLineMarker = (props: ThemeProps) => css`
211
210
  tr:first-of-type
212
211
  th {
213
212
  position: relative;
214
-
215
- &::before {
216
- content: ' ';
217
- ${Marker(props)};
218
- top: -${tableToolbarSize + lineMarkerOffsetFromColumnControls}px;
219
- right: -${lineMarkerSize / 2}px;
220
- }
221
213
  }
222
214
  `;
223
215
 
@@ -320,6 +312,18 @@ export const columnControlsDecoration = (props: ThemeProps) => css`
320
312
  top: -${columnControlsDecorationHeight + tableCellBorderWidth}px;
321
313
  height: ${columnControlsDecorationHeight}px;
322
314
 
315
+ &::before {
316
+ content: ' ';
317
+ background-color: ${tableBorderColor(props)};
318
+ position: absolute;
319
+ height: ${lineMarkerSize}px;
320
+ width: ${lineMarkerSize}px;
321
+ border-radius: 50%;
322
+ pointer-events: none;
323
+ top: 2px;
324
+ right: -1px;
325
+ }
326
+
323
327
  &::after {
324
328
  content: ' ';
325
329
 
@@ -341,6 +345,18 @@ export const columnControlsDecoration = (props: ThemeProps) => css`
341
345
  }
342
346
  }
343
347
 
348
+ div.${ClassName.WITH_CONTROLS}>.${ClassName.ROW_CONTROLS_WRAPPER}::after {
349
+ content: ' ';
350
+ background-color: ${tableBorderColor(props)};
351
+ position: absolute;
352
+ height: ${lineMarkerSize}px;
353
+ width: ${lineMarkerSize}px;
354
+ border-radius: 50%;
355
+ pointer-events: none;
356
+ top: -${tableToolbarSize + tableCellBorderWidth}px;
357
+ right: -1px;
358
+ }
359
+
344
360
  .${ClassName.WITH_CONTROLS} .${ClassName.COLUMN_CONTROLS_DECORATIONS} {
345
361
  display: block;
346
362
  }
@@ -431,17 +447,48 @@ export const resizeHandle = css`
431
447
  z-index: ${resizeHandlerZIndex};
432
448
  }
433
449
 
434
- td.${ClassName.WITH_RESIZE_LINE}, th.${ClassName.WITH_RESIZE_LINE} {
435
- .${ClassName.RESIZE_HANDLE_DECORATION}::after {
436
- content: ' ';
437
- right: ${(resizeHandlerAreaWidth - resizeLineWidth) / 2}px;
438
- position: absolute;
439
- width: ${resizeLineWidth}px;
440
- height: calc(100% + 1px);
441
- background-color: ${tableBorderSelectedColor};
442
- z-index: ${columnControlsZIndex * 2};
443
- top: 0;
444
- }
450
+ td.${ClassName.WITH_RESIZE_LINE}::before {
451
+ content: ' ';
452
+ position: absolute;
453
+ left: -2px;
454
+ top: -1px;
455
+ width: ${resizeLineWidth}px;
456
+ height: calc(100% + 2px);
457
+ background-color: ${tableBorderSelectedColor};
458
+ z-index: ${columnControlsZIndex * 2};
459
+ }
460
+
461
+ th.${ClassName.WITH_RESIZE_LINE}::before {
462
+ content: ' ';
463
+ left: -2px;
464
+ position: absolute;
465
+ width: ${resizeLineWidth}px;
466
+ height: calc(100% + ${tableToolbarSize + tableCellBorderWidth}px);
467
+ background-color: ${tableBorderSelectedColor};
468
+ z-index: ${columnControlsZIndex * 2};
469
+ top: -${tableToolbarSize + tableCellBorderWidth}px;
470
+ }
471
+
472
+ td.${ClassName.WITH_RESIZE_LINE_LAST_COLUMN}::before {
473
+ content: ' ';
474
+ position: absolute;
475
+ right: -1px;
476
+ top: -1px;
477
+ width: ${resizeLineWidth}px;
478
+ height: calc(100% + 2px);
479
+ background-color: ${tableBorderSelectedColor};
480
+ z-index: ${columnControlsZIndex * 2};
481
+ }
482
+
483
+ th.${ClassName.WITH_RESIZE_LINE_LAST_COLUMN}::before {
484
+ content: ' ';
485
+ right: -1px;
486
+ position: absolute;
487
+ width: ${resizeLineWidth}px;
488
+ height: calc(100% + ${tableToolbarSize + tableCellBorderWidth}px);
489
+ background-color: ${tableBorderSelectedColor};
490
+ z-index: ${columnControlsZIndex * 2};
491
+ top: -${tableToolbarSize + tableCellBorderWidth}px;
445
492
  }
446
493
 
447
494
  table
@@ -291,6 +291,7 @@ const makeArray = (n: number) => Array.from(Array(n).keys());
291
291
  */
292
292
  export const createResizeHandleDecoration = (
293
293
  tr: Transaction | ReadonlyTransaction,
294
+ rowIndexTarget: number,
294
295
  columnEndIndexTarget: Omit<CellColumnPositioning, 'left'>,
295
296
  ): [Decoration[], Decoration[]] => {
296
297
  const emptyResult: [Decoration[], Decoration[]] = [[], []];
@@ -361,6 +362,10 @@ export const createResizeHandleDecoration = (
361
362
  for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
362
363
  const seen: { [key: number]: boolean } = {};
363
364
 
365
+ if (rowIndex !== rowIndexTarget) {
366
+ continue;
367
+ }
368
+
364
369
  for (let columnIndex = 0; columnIndex < map.width; columnIndex++) {
365
370
  const cellPosition = map.map[map.width * rowIndex + columnIndex];
366
371
  if (seen[cellPosition]) {
@@ -456,16 +461,24 @@ export const createColumnLineResize = (
456
461
  return [];
457
462
  }
458
463
 
459
- const columnIndex = cellColumnPositioning.right - 1;
464
+ let columnIndex = cellColumnPositioning.right;
460
465
  const map = TableMap.get(table.node);
461
466
 
467
+ const isLastColumn = columnIndex === map.width;
468
+ if (isLastColumn) {
469
+ columnIndex -= 1;
470
+ }
471
+ const decorationClassName = isLastColumn
472
+ ? ClassName.WITH_RESIZE_LINE_LAST_COLUMN
473
+ : ClassName.WITH_RESIZE_LINE;
474
+
462
475
  const cellPositions = makeArray(map.height)
463
476
  .map((rowIndex) => map.map[map.width * rowIndex + columnIndex])
464
477
  .filter((cellPosition, rowIndex) => {
465
- if (columnIndex === map.width) {
478
+ if (isLastColumn) {
466
479
  return true; // If is the last column no filter applied
467
480
  }
468
- const nextPosition = map.map[map.width * rowIndex + columnIndex + 1];
481
+ const nextPosition = map.map[map.width * rowIndex + columnIndex - 1];
469
482
  return cellPosition !== nextPosition; // Removed it if next position is merged
470
483
  });
471
484
 
@@ -484,7 +497,7 @@ export const createColumnLineResize = (
484
497
  cell.pos,
485
498
  cell.pos + cell.node.nodeSize,
486
499
  {
487
- class: ClassName.WITH_RESIZE_LINE,
500
+ class: decorationClassName,
488
501
  },
489
502
  {
490
503
  key: `${TableDecorations.COLUMN_RESIZING_HANDLE_LINE}_${cellColumnPositioning.right}_${index}`,