@atlaskit/editor-plugin-table 5.3.0 → 5.3.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 (71) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +36 -7
  3. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +69 -7
  4. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
  5. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/index.js +12 -0
  6. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +59 -0
  7. package/dist/cjs/plugins/table/types.js +8 -1
  8. package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
  9. package/dist/cjs/plugins/table/ui/consts.js +2 -1
  10. package/dist/cjs/plugins/table/ui/ui-styles.js +5 -2
  11. package/dist/cjs/plugins/table/utils/decoration.js +67 -1
  12. package/dist/cjs/plugins/table/utils/index.js +26 -1
  13. package/dist/cjs/plugins/table/utils/merged-cells.js +66 -0
  14. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +35 -7
  15. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +69 -4
  16. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
  17. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/index.js +1 -0
  18. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +56 -0
  19. package/dist/es2019/plugins/table/types.js +8 -1
  20. package/dist/es2019/plugins/table/ui/common-styles.js +2 -1
  21. package/dist/es2019/plugins/table/ui/consts.js +1 -0
  22. package/dist/es2019/plugins/table/ui/ui-styles.js +114 -1
  23. package/dist/es2019/plugins/table/utils/decoration.js +62 -0
  24. package/dist/es2019/plugins/table/utils/index.js +3 -2
  25. package/dist/es2019/plugins/table/utils/merged-cells.js +48 -0
  26. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +36 -7
  27. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +65 -4
  28. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
  29. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/index.js +1 -0
  30. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +53 -0
  31. package/dist/esm/plugins/table/types.js +8 -1
  32. package/dist/esm/plugins/table/ui/common-styles.js +2 -2
  33. package/dist/esm/plugins/table/ui/consts.js +1 -0
  34. package/dist/esm/plugins/table/ui/ui-styles.js +5 -2
  35. package/dist/esm/plugins/table/utils/decoration.js +66 -0
  36. package/dist/esm/plugins/table/utils/index.js +3 -2
  37. package/dist/esm/plugins/table/utils/merged-cells.js +60 -0
  38. package/dist/types/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +5 -1
  39. package/dist/types/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +6 -1
  40. package/dist/types/plugins/table/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
  41. package/dist/types/plugins/table/pm-plugins/drag-and-drop/utils/monitor.d.ts +3 -0
  42. package/dist/types/plugins/table/types.d.ts +19 -1
  43. package/dist/types/plugins/table/ui/consts.d.ts +1 -0
  44. package/dist/types/plugins/table/ui/ui-styles.d.ts +1 -0
  45. package/dist/types/plugins/table/utils/decoration.d.ts +2 -0
  46. package/dist/types/plugins/table/utils/index.d.ts +2 -1
  47. package/dist/types/plugins/table/utils/merged-cells.d.ts +3 -0
  48. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +5 -1
  49. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +6 -1
  50. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
  51. package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/utils/monitor.d.ts +3 -0
  52. package/dist/types-ts4.5/plugins/table/types.d.ts +19 -1
  53. package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +1 -0
  54. package/dist/types-ts4.5/plugins/table/ui/ui-styles.d.ts +1 -0
  55. package/dist/types-ts4.5/plugins/table/utils/decoration.d.ts +2 -0
  56. package/dist/types-ts4.5/plugins/table/utils/index.d.ts +2 -1
  57. package/dist/types-ts4.5/plugins/table/utils/merged-cells.d.ts +3 -0
  58. package/package.json +4 -1
  59. package/src/plugins/table/pm-plugins/drag-and-drop/actions.ts +6 -1
  60. package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +58 -8
  61. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +77 -4
  62. package/src/plugins/table/pm-plugins/drag-and-drop/reducer.ts +2 -0
  63. package/src/plugins/table/pm-plugins/drag-and-drop/utils/index.ts +1 -0
  64. package/src/plugins/table/pm-plugins/drag-and-drop/utils/monitor.ts +72 -0
  65. package/src/plugins/table/types.ts +23 -1
  66. package/src/plugins/table/ui/common-styles.ts +2 -0
  67. package/src/plugins/table/ui/consts.ts +1 -0
  68. package/src/plugins/table/ui/ui-styles.ts +115 -0
  69. package/src/plugins/table/utils/decoration.ts +101 -0
  70. package/src/plugins/table/utils/index.ts +3 -0
  71. package/src/plugins/table/utils/merged-cells.ts +67 -0
@@ -22,6 +22,7 @@ import {
22
22
  columnControlsDecorationHeight,
23
23
  columnControlsSelectedZIndex,
24
24
  columnControlsZIndex,
25
+ insertLineWidth,
25
26
  lineMarkerSize,
26
27
  resizeHandlerAreaWidth,
27
28
  resizeHandlerZIndex,
@@ -746,3 +747,117 @@ export const resizeHandle = (props: ThemeProps) => css`
746
747
  }
747
748
  }
748
749
  `;
750
+
751
+ export const insertLine = (props: ThemeProps) => css`
752
+ .${ClassName.TABLE_CONTAINER} {
753
+ td.${ClassName.WITH_FIRST_COLUMN_INSERT_LINE}::before {
754
+ content: ' ';
755
+ position: absolute;
756
+ left: -1px;
757
+ top: -1px;
758
+ width: ${insertLineWidth}px;
759
+ height: calc(100% + ${tableCellBorderWidth * 2}px);
760
+ background-color: ${tableBorderSelectedColor(props)};
761
+ z-index: ${columnControlsZIndex * 2};
762
+ }
763
+
764
+ th.${ClassName.WITH_FIRST_COLUMN_INSERT_LINE}::before {
765
+ content: ' ';
766
+ left: -1px;
767
+ position: absolute;
768
+ width: ${insertLineWidth}px;
769
+ height: calc(100% + ${tableCellBorderWidth * 2}px);
770
+ background-color: ${tableBorderSelectedColor(props)};
771
+ z-index: ${columnControlsZIndex * 2};
772
+ top: -${tableCellBorderWidth}px;
773
+ }
774
+
775
+ td.${ClassName.WITH_COLUMN_INSERT_LINE}::before {
776
+ content: ' ';
777
+ position: absolute;
778
+ left: ${token('space.negative.025', '-2px')};
779
+ top: -1px;
780
+ width: ${insertLineWidth}px;
781
+ height: calc(100% + ${tableCellBorderWidth * 2}px);
782
+ background-color: ${tableBorderSelectedColor(props)};
783
+ z-index: ${columnControlsZIndex * 2};
784
+ }
785
+
786
+ th.${ClassName.WITH_COLUMN_INSERT_LINE}::before {
787
+ content: ' ';
788
+ left: ${token('space.negative.025', '-2px')};
789
+ position: absolute;
790
+ width: ${insertLineWidth}px;
791
+ height: calc(100% + ${tableCellBorderWidth * 2}px);
792
+ background-color: ${tableBorderSelectedColor(props)};
793
+ z-index: ${columnControlsZIndex * 2};
794
+ top: -${tableCellBorderWidth}px;
795
+ }
796
+
797
+ td.${ClassName.WITH_LAST_COLUMN_INSERT_LINE}::before {
798
+ content: ' ';
799
+ position: absolute;
800
+ right: -1px;
801
+ top: -1px;
802
+ width: ${insertLineWidth}px;
803
+ height: calc(100% + ${tableCellBorderWidth * 2}px);
804
+ background-color: ${tableBorderSelectedColor(props)};
805
+ z-index: ${columnControlsZIndex * 2};
806
+ }
807
+
808
+ th.${ClassName.WITH_LAST_COLUMN_INSERT_LINE}::before {
809
+ content: ' ';
810
+ right: -1px;
811
+ position: absolute;
812
+ width: ${insertLineWidth}px;
813
+ height: calc(100% + ${tableCellBorderWidth * 2}px);
814
+ background-color: ${tableBorderSelectedColor(props)};
815
+ z-index: ${columnControlsZIndex * 2};
816
+ top: -${tableCellBorderWidth}px;
817
+ }
818
+
819
+ td.${ClassName.WITH_ROW_INSERT_LINE}::before {
820
+ content: ' ';
821
+ position: absolute;
822
+ left: ${token('space.negative.025', '-2px')};
823
+ top: -1px;
824
+ height: ${insertLineWidth}px;
825
+ width: calc(100% + ${tableCellBorderWidth * 2}px);
826
+ background-color: ${tableBorderSelectedColor(props)};
827
+ z-index: ${columnControlsZIndex * 2};
828
+ }
829
+
830
+ th.${ClassName.WITH_ROW_INSERT_LINE}::before {
831
+ content: ' ';
832
+ left: ${token('space.negative.025', '-2px')};
833
+ position: absolute;
834
+ height: ${insertLineWidth}px;
835
+ width: calc(100% + ${tableCellBorderWidth * 2}px);
836
+ background-color: ${tableBorderSelectedColor(props)};
837
+ z-index: ${columnControlsZIndex * 2};
838
+ top: -1px;
839
+ }
840
+
841
+ td.${ClassName.WITH_LAST_ROW_INSERT_LINE}::before {
842
+ content: ' ';
843
+ position: absolute;
844
+ left: ${token('space.negative.025', '-2px')};
845
+ bottom: 0;
846
+ height: ${insertLineWidth}px;
847
+ width: calc(100% + 2px);
848
+ background-color: ${tableBorderSelectedColor(props)};
849
+ z-index: ${columnControlsZIndex * 2};
850
+ }
851
+
852
+ th.${ClassName.WITH_LAST_ROW_INSERT_LINE}::before {
853
+ content: ' ';
854
+ left: ${token('space.negative.025', '-2px')};
855
+ bottom: 0;
856
+ position: absolute;
857
+ height: ${insertLineWidth}px;
858
+ width: calc(100% + ${tableCellBorderWidth * 2}px);
859
+ background-color: ${tableBorderSelectedColor(props)};
860
+ z-index: ${columnControlsZIndex * 2};
861
+ }
862
+ }
863
+ `;
@@ -566,3 +566,104 @@ export const createColumnLineResize = (
566
566
  })
567
567
  .filter(nonNullable);
568
568
  };
569
+
570
+ export const createColumnInsertLine = (
571
+ columnIndex: number,
572
+ selection: Selection,
573
+ ): Decoration[] => {
574
+ const table = findTable(selection);
575
+ if (!table) {
576
+ return [];
577
+ }
578
+
579
+ const map = TableMap.get(table.node);
580
+
581
+ const isFirstColumn = columnIndex === 0;
582
+ const isLastColumn = columnIndex === map.width;
583
+ if (isLastColumn) {
584
+ columnIndex -= 1;
585
+ }
586
+ const decorationClassName = isFirstColumn
587
+ ? ClassName.WITH_FIRST_COLUMN_INSERT_LINE
588
+ : isLastColumn
589
+ ? ClassName.WITH_LAST_COLUMN_INSERT_LINE
590
+ : ClassName.WITH_COLUMN_INSERT_LINE;
591
+
592
+ const cellPositions = makeArray(map.height)
593
+ .map((rowIndex) => map.map[map.width * rowIndex + columnIndex])
594
+ .filter((cellPosition, rowIndex) => {
595
+ if (isLastColumn) {
596
+ return true; // If is the last column no filter applied
597
+ }
598
+ const nextPosition = map.map[map.width * rowIndex + columnIndex - 1];
599
+ return cellPosition !== nextPosition; // Removed it if next position is merged
600
+ });
601
+
602
+ const cells = cellPositions.map((pos) => ({
603
+ pos: pos + table.start,
604
+ node: table.node.nodeAt(pos),
605
+ }));
606
+
607
+ return cells
608
+ .map((cell, index) => {
609
+ if (!cell || !cell.node) {
610
+ return;
611
+ }
612
+
613
+ return Decoration.node(
614
+ cell.pos,
615
+ cell.pos + cell.node.nodeSize,
616
+ {
617
+ class: decorationClassName,
618
+ },
619
+ {
620
+ key: `${TableDecorations.COLUMN_INSERT_LINE}_${index}`,
621
+ },
622
+ );
623
+ })
624
+ .filter(nonNullable);
625
+ };
626
+
627
+ export const createRowInsertLine = (
628
+ rowIndex: number,
629
+ selection: Selection,
630
+ ): Decoration[] => {
631
+ const table = findTable(selection);
632
+ if (!table) {
633
+ return [];
634
+ }
635
+
636
+ const map = TableMap.get(table.node);
637
+ const isLastRow = rowIndex === map.height;
638
+ if (isLastRow) {
639
+ rowIndex -= 1;
640
+ }
641
+
642
+ const cells = getCellsInRow(rowIndex)(selection);
643
+ if (!cells) {
644
+ return [];
645
+ }
646
+
647
+ const decorationClassName = isLastRow
648
+ ? ClassName.WITH_LAST_ROW_INSERT_LINE
649
+ : ClassName.WITH_ROW_INSERT_LINE;
650
+
651
+ return cells
652
+ .map((cell, index) => {
653
+ if (!cell || !cell.node) {
654
+ return;
655
+ }
656
+
657
+ return Decoration.node(
658
+ cell.pos,
659
+ cell.pos + cell.node.nodeSize,
660
+ {
661
+ class: decorationClassName,
662
+ },
663
+ {
664
+ key: `${TableDecorations.ROW_INSERT_LINE}_${index}`,
665
+ },
666
+ );
667
+ })
668
+ .filter(nonNullable);
669
+ };
@@ -12,7 +12,9 @@ export {
12
12
  createCellHoverDecoration,
13
13
  updateDecorations,
14
14
  createResizeHandleDecoration,
15
+ createColumnInsertLine,
15
16
  createColumnLineResize,
17
+ createRowInsertLine,
16
18
  } from './decoration';
17
19
  export {
18
20
  isIsolating,
@@ -70,3 +72,4 @@ export type { RowParams } from './row-controls';
70
72
  export { getSelectedTableInfo, getSelectedCellInfo } from './analytics';
71
73
  export { getMergedCellsPositions } from './table';
72
74
  export { updatePluginStateDecorations } from './update-plugin-state-decorations';
75
+ export { hasMergedCellsInColumn, hasMergedCellsInRow } from './merged-cells';
@@ -0,0 +1,67 @@
1
+ import type { Selection } from '@atlaskit/editor-prosemirror/state';
2
+ import type { Rect } from '@atlaskit/editor-tables';
3
+ import { findTable, TableMap } from '@atlaskit/editor-tables';
4
+
5
+ const hasMergedCells =
6
+ (
7
+ indexes: number | number[],
8
+ normalizeRect: (index: number, map: TableMap) => Rect,
9
+ ) =>
10
+ (selection: Selection): boolean => {
11
+ const table = findTable(selection);
12
+ if (!table) {
13
+ return false;
14
+ }
15
+
16
+ const map = TableMap.get(table.node);
17
+ const cellPositions = new Set<number>();
18
+ const mergedCells = new Set<number>();
19
+
20
+ map.map.forEach((value) => {
21
+ if (cellPositions.has(value)) {
22
+ mergedCells.add(value);
23
+ } else {
24
+ cellPositions.add(value);
25
+ }
26
+ });
27
+
28
+ if (!mergedCells.size) {
29
+ return false;
30
+ }
31
+
32
+ return (Array.isArray(indexes) ? indexes : [indexes])
33
+ .map((index) => normalizeRect(index, map))
34
+ .filter((rect) => rect.left < rect.right && rect.top < rect.bottom)
35
+ .some((rect) => {
36
+ const n = (rect.right - rect.left) * (rect.bottom - rect.top);
37
+ const cells = map.cellsInRect(rect);
38
+ if (cells.length !== n) {
39
+ // We can quickly assume that if the amount of cells from the map is different to what the rect says
40
+ // then there is most likely merged cells across this area which is removing cells
41
+ return true;
42
+ }
43
+ return cells.some((nodePos) => mergedCells.has(nodePos));
44
+ });
45
+ };
46
+
47
+ export const hasMergedCellsInColumn = (columnIndexes: number | number[]) =>
48
+ hasMergedCells(columnIndexes, (index: number, map: TableMap) => {
49
+ const x = Math.max(Math.min(index, map.width - 1), 0); // clamped index
50
+ return {
51
+ left: x,
52
+ right: x === index ? x + 1 : x,
53
+ top: 0,
54
+ bottom: map.height,
55
+ };
56
+ });
57
+
58
+ export const hasMergedCellsInRow = (rowIndexes: number | number[]) =>
59
+ hasMergedCells(rowIndexes, (index: number, map: TableMap) => {
60
+ const y = Math.max(Math.min(index, map.height - 1), 0); // clamped index
61
+ return {
62
+ left: 0,
63
+ right: map.width,
64
+ top: y,
65
+ bottom: y === index ? y + 1 : y,
66
+ };
67
+ });