@atlaskit/editor-plugin-table 5.2.2 → 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.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +20 -2
- package/dist/cjs/plugins/table/nodeviews/table.js +1 -0
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +36 -7
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/handlers.js +24 -0
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin-factory.js +29 -4
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +83 -9
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/index.js +12 -0
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +59 -0
- package/dist/cjs/plugins/table/types.js +12 -1
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +106 -0
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +90 -0
- package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
- package/dist/cjs/plugins/table/ui/consts.js +2 -1
- package/dist/cjs/plugins/table/ui/ui-styles.js +15 -9
- package/dist/cjs/plugins/table/utils/decoration.js +67 -1
- package/dist/cjs/plugins/table/utils/index.js +26 -1
- package/dist/cjs/plugins/table/utils/merged-cells.js +66 -0
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +20 -2
- package/dist/es2019/plugins/table/nodeviews/table.js +1 -0
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +35 -7
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/handlers.js +10 -0
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin-factory.js +28 -4
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +82 -6
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/index.js +1 -0
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +56 -0
- package/dist/es2019/plugins/table/types.js +12 -1
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +101 -0
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +60 -0
- package/dist/es2019/plugins/table/ui/common-styles.js +14 -1
- package/dist/es2019/plugins/table/ui/consts.js +1 -0
- package/dist/es2019/plugins/table/ui/ui-styles.js +127 -1
- package/dist/es2019/plugins/table/utils/decoration.js +62 -0
- package/dist/es2019/plugins/table/utils/index.js +3 -2
- package/dist/es2019/plugins/table/utils/merged-cells.js +48 -0
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +20 -2
- package/dist/esm/plugins/table/nodeviews/table.js +1 -0
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +36 -7
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/handlers.js +18 -0
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin-factory.js +28 -3
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +82 -9
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/index.js +1 -0
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +53 -0
- package/dist/esm/plugins/table/types.js +12 -1
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +97 -0
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +80 -0
- package/dist/esm/plugins/table/ui/common-styles.js +2 -2
- package/dist/esm/plugins/table/ui/consts.js +1 -0
- package/dist/esm/plugins/table/ui/ui-styles.js +15 -9
- package/dist/esm/plugins/table/utils/decoration.js +66 -0
- package/dist/esm/plugins/table/utils/index.js +3 -2
- package/dist/esm/plugins/table/utils/merged-cells.js +60 -0
- package/dist/types/plugins/table/index.d.ts +1 -1
- package/dist/types/plugins/table/nodeviews/TableComponent.d.ts +1 -0
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +5 -1
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +6 -1
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/handlers.d.ts +3 -0
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/plugin-factory.d.ts +1 -2
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/types.d.ts +2 -0
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/utils/monitor.d.ts +3 -0
- package/dist/types/plugins/table/types.d.ts +23 -1
- package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +11 -0
- package/dist/types/plugins/table/ui/TableFloatingColumnControls/index.d.ts +20 -0
- package/dist/types/plugins/table/ui/consts.d.ts +1 -0
- package/dist/types/plugins/table/ui/ui-styles.d.ts +2 -0
- package/dist/types/plugins/table/utils/decoration.d.ts +2 -0
- package/dist/types/plugins/table/utils/index.d.ts +2 -1
- package/dist/types/plugins/table/utils/merged-cells.d.ts +3 -0
- package/dist/types-ts4.5/plugins/table/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/nodeviews/TableComponent.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +5 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +6 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/handlers.d.ts +3 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/plugin-factory.d.ts +1 -2
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/types.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/utils/monitor.d.ts +3 -0
- package/dist/types-ts4.5/plugins/table/types.d.ts +23 -1
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +11 -0
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/index.d.ts +20 -0
- package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/ui/ui-styles.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/utils/decoration.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/utils/index.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/utils/merged-cells.d.ts +3 -0
- package/package.json +4 -1
- package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +139 -0
- package/src/plugins/table/index.tsx +1 -1
- package/src/plugins/table/nodeviews/TableComponent.tsx +25 -0
- package/src/plugins/table/nodeviews/table.tsx +1 -0
- package/src/plugins/table/pm-plugins/drag-and-drop/actions.ts +6 -1
- package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +58 -8
- package/src/plugins/table/pm-plugins/drag-and-drop/handlers.ts +35 -0
- package/src/plugins/table/pm-plugins/drag-and-drop/plugin-factory.ts +27 -2
- package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +88 -6
- package/src/plugins/table/pm-plugins/drag-and-drop/reducer.ts +2 -0
- package/src/plugins/table/pm-plugins/drag-and-drop/types.ts +3 -0
- package/src/plugins/table/pm-plugins/drag-and-drop/utils/index.ts +1 -0
- package/src/plugins/table/pm-plugins/drag-and-drop/utils/monitor.ts +72 -0
- package/src/plugins/table/types.ts +28 -1
- package/src/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +128 -0
- package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +101 -0
- package/src/plugins/table/ui/common-styles.ts +15 -0
- package/src/plugins/table/ui/consts.ts +1 -0
- package/src/plugins/table/ui/ui-styles.ts +129 -0
- package/src/plugins/table/utils/decoration.ts +101 -0
- package/src/plugins/table/utils/index.ts +3 -0
- package/src/plugins/table/utils/merged-cells.ts +67 -0
|
@@ -55,6 +55,7 @@ import {
|
|
|
55
55
|
columnControlsDecoration,
|
|
56
56
|
columnControlsLineMarker,
|
|
57
57
|
DeleteButton,
|
|
58
|
+
floatingColumnControls,
|
|
58
59
|
HeaderButton,
|
|
59
60
|
HeaderButtonDanger,
|
|
60
61
|
HeaderButtonHover,
|
|
@@ -62,6 +63,7 @@ import {
|
|
|
62
63
|
hoveredDeleteButton,
|
|
63
64
|
hoveredWarningCell,
|
|
64
65
|
insertColumnButtonWrapper,
|
|
66
|
+
insertLine,
|
|
65
67
|
InsertMarker,
|
|
66
68
|
insertRowButtonWrapper,
|
|
67
69
|
OverflowShadow,
|
|
@@ -290,6 +292,7 @@ export const tableStyles = (
|
|
|
290
292
|
${hoveredDeleteButton(props)};
|
|
291
293
|
${hoveredCell(props)};
|
|
292
294
|
${hoveredWarningCell};
|
|
295
|
+
${getBooleanFF('platform.editor.table.drag-and-drop') && insertLine(props)};
|
|
293
296
|
${resizeHandle(props)};
|
|
294
297
|
${rangeSelectionStyles};
|
|
295
298
|
|
|
@@ -515,6 +518,10 @@ export const tableStyles = (
|
|
|
515
518
|
}
|
|
516
519
|
}
|
|
517
520
|
|
|
521
|
+
.${ClassName.COLUMN_CONTROLS_WRAPPER} {
|
|
522
|
+
padding: 0 ${tablePadding}px;
|
|
523
|
+
}
|
|
524
|
+
|
|
518
525
|
&.${ClassName.TABLE_CONTAINER}[data-number-column='true'] {
|
|
519
526
|
padding-left: ${akEditorTableNumberColumnWidth + tablePadding - 1}px;
|
|
520
527
|
}
|
|
@@ -670,6 +677,8 @@ export const tableStyles = (
|
|
|
670
677
|
)}
|
|
671
678
|
}
|
|
672
679
|
|
|
680
|
+
${floatingColumnControls(props)}
|
|
681
|
+
|
|
673
682
|
:not(.${ClassName.IS_RESIZING}) .${ClassName.ROW_CONTROLS} {
|
|
674
683
|
${HeaderButtonHover(props)}
|
|
675
684
|
${HeaderButtonDanger(props)}
|
|
@@ -855,6 +864,12 @@ export const tableStyles = (
|
|
|
855
864
|
.${ClassName.ROW_CONTROLS_WRAPPER} {
|
|
856
865
|
left: -${tableToolbarSize}px;
|
|
857
866
|
}
|
|
867
|
+
|
|
868
|
+
.${ClassName.COLUMN_CONTROLS_WRAPPER} {
|
|
869
|
+
position: absolute;
|
|
870
|
+
top: ${tableMarginTop + 1}px;
|
|
871
|
+
}
|
|
872
|
+
|
|
858
873
|
${tableWrapperStyles()}
|
|
859
874
|
}
|
|
860
875
|
|
|
@@ -131,6 +131,7 @@ export const columnControlsDecorationHeight = 25;
|
|
|
131
131
|
export const columnControlsZIndex = akEditorUnitZIndex * 10;
|
|
132
132
|
export const columnControlsSelectedZIndex = columnControlsZIndex + 1;
|
|
133
133
|
export const columnResizeHandleZIndex = columnControlsSelectedZIndex + 1;
|
|
134
|
+
export const insertLineWidth = 3;
|
|
134
135
|
export const resizeHandlerAreaWidth = RESIZE_HANDLE_AREA_DECORATION_GAP / 3;
|
|
135
136
|
export const resizeLineWidth = 2;
|
|
136
137
|
export const resizeHandlerZIndex =
|
|
@@ -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,
|
|
@@ -374,6 +375,20 @@ const getFloatingDotOverrides = (props: ThemeProps) => {
|
|
|
374
375
|
: '';
|
|
375
376
|
};
|
|
376
377
|
|
|
378
|
+
export const floatingColumnControls = (props: ThemeProps) => {
|
|
379
|
+
return css`
|
|
380
|
+
.${ClassName.COLUMN_DROP_TARGET_CONTROLS} {
|
|
381
|
+
box-sizing: border-box;
|
|
382
|
+
position: absolute;
|
|
383
|
+
|
|
384
|
+
.${ClassName.COLUMN_CONTROLS_INNER} {
|
|
385
|
+
display: flex;
|
|
386
|
+
flex-direction: row;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
`;
|
|
390
|
+
};
|
|
391
|
+
|
|
377
392
|
export const columnControlsDecoration = (props: ThemeProps) => {
|
|
378
393
|
if (getBooleanFF('platform.editor.table.column-controls-styles-updated')) {
|
|
379
394
|
return css`
|
|
@@ -732,3 +747,117 @@ export const resizeHandle = (props: ThemeProps) => css`
|
|
|
732
747
|
}
|
|
733
748
|
}
|
|
734
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
|
+
});
|