@atlaskit/editor-plugin-table 5.3.1 → 5.3.2
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 +6 -0
- package/dist/cjs/plugins/table/commands/hover.js +17 -8
- package/dist/cjs/plugins/table/commands/index.js +6 -0
- package/dist/cjs/plugins/table/commands/misc.js +1 -7
- package/dist/cjs/plugins/table/event-handlers.js +29 -2
- package/dist/cjs/plugins/table/index.js +1 -1
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +5 -3
- package/dist/cjs/plugins/table/nodeviews/table.js +4 -2
- package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +7 -3
- package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
- package/dist/cjs/plugins/table/pm-plugins/default-table-selection.js +14 -1
- package/dist/cjs/plugins/table/pm-plugins/main.js +5 -5
- package/dist/cjs/plugins/table/reducer.js +2 -1
- package/dist/cjs/plugins/table/types.js +6 -0
- package/dist/cjs/plugins/table/ui/DragHandle/index.js +50 -0
- package/dist/cjs/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +53 -14
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +114 -0
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +53 -0
- package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/index.js +11 -106
- package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +16 -6
- package/dist/cjs/plugins/table/ui/common-styles.js +9 -6
- package/dist/cjs/plugins/table/ui/consts.js +2 -1
- package/dist/cjs/plugins/table/ui/ui-styles.js +18 -9
- package/dist/cjs/plugins/table/utils/decoration.js +44 -18
- package/dist/cjs/plugins/table/utils/dom.js +7 -1
- package/dist/cjs/plugins/table/utils/index.js +12 -0
- package/dist/es2019/plugins/table/commands/hover.js +12 -8
- package/dist/es2019/plugins/table/commands/index.js +1 -1
- package/dist/es2019/plugins/table/commands/misc.js +1 -7
- package/dist/es2019/plugins/table/event-handlers.js +28 -2
- package/dist/es2019/plugins/table/index.js +1 -1
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +5 -3
- package/dist/es2019/plugins/table/nodeviews/table.js +4 -2
- package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +8 -6
- package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
- package/dist/es2019/plugins/table/pm-plugins/default-table-selection.js +13 -0
- package/dist/es2019/plugins/table/pm-plugins/main.js +6 -5
- package/dist/es2019/plugins/table/reducer.js +2 -1
- package/dist/es2019/plugins/table/types.js +6 -0
- package/dist/es2019/plugins/table/ui/DragHandle/index.js +41 -0
- package/dist/es2019/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +54 -10
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +86 -0
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +43 -0
- package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/index.js +2 -88
- package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +17 -7
- package/dist/es2019/plugins/table/ui/common-styles.js +47 -12
- package/dist/es2019/plugins/table/ui/consts.js +1 -0
- package/dist/es2019/plugins/table/ui/ui-styles.js +57 -14
- package/dist/es2019/plugins/table/utils/decoration.js +44 -18
- package/dist/es2019/plugins/table/utils/dom.js +2 -0
- package/dist/es2019/plugins/table/utils/index.js +1 -1
- package/dist/esm/plugins/table/commands/hover.js +16 -8
- package/dist/esm/plugins/table/commands/index.js +1 -1
- package/dist/esm/plugins/table/commands/misc.js +1 -7
- package/dist/esm/plugins/table/event-handlers.js +29 -2
- package/dist/esm/plugins/table/index.js +1 -1
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +5 -3
- package/dist/esm/plugins/table/nodeviews/table.js +4 -2
- package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +8 -6
- package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +7 -2
- package/dist/esm/plugins/table/pm-plugins/default-table-selection.js +13 -0
- package/dist/esm/plugins/table/pm-plugins/main.js +7 -7
- package/dist/esm/plugins/table/reducer.js +2 -1
- package/dist/esm/plugins/table/types.js +6 -0
- package/dist/esm/plugins/table/ui/DragHandle/index.js +41 -0
- package/dist/esm/plugins/table/ui/TableFloatingControls/NumberColumn/index.js +54 -15
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.js +104 -0
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +46 -0
- package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/index.js +2 -104
- package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +17 -7
- package/dist/esm/plugins/table/ui/common-styles.js +10 -7
- package/dist/esm/plugins/table/ui/consts.js +1 -0
- package/dist/esm/plugins/table/ui/ui-styles.js +18 -9
- package/dist/esm/plugins/table/utils/decoration.js +44 -18
- package/dist/esm/plugins/table/utils/dom.js +6 -0
- package/dist/esm/plugins/table/utils/index.js +1 -1
- package/dist/types/plugins/table/commands/hover.d.ts +2 -1
- package/dist/types/plugins/table/commands/index.d.ts +1 -1
- package/dist/types/plugins/table/event-handlers.d.ts +1 -0
- package/dist/types/plugins/table/nodeviews/types.d.ts +4 -3
- package/dist/types/plugins/table/pm-plugins/decorations/plugin.d.ts +2 -1
- package/dist/types/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +1 -1
- package/dist/types/plugins/table/pm-plugins/default-table-selection.d.ts +12 -0
- package/dist/types/plugins/table/pm-plugins/main.d.ts +1 -1
- package/dist/types/plugins/table/types.d.ts +16 -1
- package/dist/types/plugins/table/ui/DragHandle/index.d.ts +11 -0
- package/dist/types/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +4 -1
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.d.ts +17 -0
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +16 -0
- package/dist/types/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +2 -17
- package/dist/types/plugins/table/ui/TableFloatingControls/index.d.ts +3 -2
- package/dist/types/plugins/table/ui/consts.d.ts +1 -0
- package/dist/types/plugins/table/utils/decoration.d.ts +2 -2
- package/dist/types/plugins/table/utils/dom.d.ts +2 -0
- package/dist/types/plugins/table/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/commands/hover.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/commands/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/event-handlers.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/nodeviews/types.d.ts +4 -3
- package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/plugin.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/default-table-selection.d.ts +12 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/main.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/types.d.ts +16 -1
- package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +11 -0
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +4 -1
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.d.ts +17 -0
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/DragControls.d.ts +16 -0
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +2 -17
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/index.d.ts +3 -2
- package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/utils/decoration.d.ts +2 -2
- package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/utils/index.d.ts +1 -1
- package/package.json +3 -2
- package/src/__tests__/unit/event-handlers.ts +74 -1
- package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +35 -15
- package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +146 -42
- package/src/__tests__/unit/ui/NumberColumn.tsx +148 -0
- package/src/__tests__/unit/ui/RowControls.tsx +4 -4
- package/src/__tests__/unit/ui/RowDragControls.tsx +118 -0
- package/src/__tests__/unit/ui/TableFloatingControls.tsx +9 -5
- package/src/plugins/table/commands/hover.ts +16 -7
- package/src/plugins/table/commands/index.ts +1 -0
- package/src/plugins/table/commands/misc.ts +0 -5
- package/src/plugins/table/event-handlers.ts +49 -2
- package/src/plugins/table/index.tsx +1 -1
- package/src/plugins/table/nodeviews/TableComponent.tsx +3 -2
- package/src/plugins/table/nodeviews/table.tsx +2 -0
- package/src/plugins/table/nodeviews/types.ts +4 -3
- package/src/plugins/table/pm-plugins/decorations/plugin.ts +13 -4
- package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +10 -5
- package/src/plugins/table/pm-plugins/default-table-selection.ts +10 -0
- package/src/plugins/table/pm-plugins/main.ts +9 -4
- package/src/plugins/table/reducer.ts +2 -1
- package/src/plugins/table/types.ts +14 -2
- package/src/plugins/table/ui/DragHandle/index.tsx +57 -0
- package/src/plugins/table/ui/TableFloatingControls/NumberColumn/index.tsx +68 -30
- package/src/plugins/table/ui/TableFloatingControls/RowControls/ClassicControls.tsx +129 -0
- package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +75 -0
- package/src/plugins/table/ui/TableFloatingControls/RowControls/index.tsx +2 -135
- package/src/plugins/table/ui/TableFloatingControls/index.tsx +43 -24
- package/src/plugins/table/ui/common-styles.ts +52 -11
- package/src/plugins/table/ui/consts.ts +1 -0
- package/src/plugins/table/ui/ui-styles.ts +58 -14
- package/src/plugins/table/utils/decoration.ts +75 -27
- package/src/plugins/table/utils/dom.ts +8 -0
- package/src/plugins/table/utils/index.ts +2 -0
- package/tsconfig.app.json +3 -0
|
@@ -390,6 +390,17 @@ export const floatingColumnControls = (props: ThemeProps) => {
|
|
|
390
390
|
};
|
|
391
391
|
|
|
392
392
|
export const columnControlsDecoration = (props: ThemeProps) => {
|
|
393
|
+
if (getBooleanFF('platform.editor.table.drag-and-drop')) {
|
|
394
|
+
return css`
|
|
395
|
+
.${ClassName.COLUMN_CONTROLS_DECORATIONS_WITH_DRAG} {
|
|
396
|
+
position: absolute;
|
|
397
|
+
// kinda a hacky way to center an element with absolute positioning inside a relative element
|
|
398
|
+
top: 25%;
|
|
399
|
+
left: 50%;
|
|
400
|
+
transform: translate(-50%, -100%);
|
|
401
|
+
}
|
|
402
|
+
`;
|
|
403
|
+
}
|
|
393
404
|
if (getBooleanFF('platform.editor.table.column-controls-styles-updated')) {
|
|
394
405
|
return css`
|
|
395
406
|
.${ClassName.COLUMN_CONTROLS_DECORATIONS} {
|
|
@@ -675,21 +686,35 @@ const getLastColumnResizerOverrides = () => {
|
|
|
675
686
|
: '';
|
|
676
687
|
};
|
|
677
688
|
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
689
|
+
const resizeHandleOverrides = (props: ThemeProps) => {
|
|
690
|
+
if (getBooleanFF('platform.editor.table.drag-and-drop')) {
|
|
691
|
+
return css`
|
|
692
|
+
th.${ClassName.WITH_RESIZE_LINE}::before,
|
|
693
|
+
td.${ClassName.WITH_RESIZE_LINE}::before {
|
|
694
|
+
content: ' ';
|
|
695
|
+
position: absolute;
|
|
696
|
+
left: ${token('space.negative.025', '-2px')};
|
|
697
|
+
top: -1px;
|
|
698
|
+
width: ${resizeLineWidth}px;
|
|
699
|
+
height: calc(100% + 2px);
|
|
700
|
+
background-color: ${tableBorderSelectedColor(props)};
|
|
701
|
+
z-index: ${columnControlsZIndex * 2};
|
|
702
|
+
}
|
|
692
703
|
|
|
704
|
+
th.${ClassName.WITH_RESIZE_LINE_LAST_COLUMN}::before,
|
|
705
|
+
td.${ClassName.WITH_RESIZE_LINE_LAST_COLUMN}::before {
|
|
706
|
+
content: ' ';
|
|
707
|
+
position: absolute;
|
|
708
|
+
right: -1px;
|
|
709
|
+
top: -1px;
|
|
710
|
+
width: ${resizeLineWidth}px;
|
|
711
|
+
height: calc(100% + 2px);
|
|
712
|
+
background-color: ${tableBorderSelectedColor(props)};
|
|
713
|
+
z-index: ${columnControlsZIndex * 2};
|
|
714
|
+
}
|
|
715
|
+
`;
|
|
716
|
+
}
|
|
717
|
+
return css`
|
|
693
718
|
td.${ClassName.WITH_RESIZE_LINE}::before {
|
|
694
719
|
content: ' ';
|
|
695
720
|
position: absolute;
|
|
@@ -733,6 +758,25 @@ export const resizeHandle = (props: ThemeProps) => css`
|
|
|
733
758
|
z-index: ${columnControlsZIndex * 2};
|
|
734
759
|
top: -${tableToolbarSize + tableCellBorderWidth}px;
|
|
735
760
|
}
|
|
761
|
+
`;
|
|
762
|
+
};
|
|
763
|
+
|
|
764
|
+
export const resizeHandle = (props: ThemeProps) => css`
|
|
765
|
+
.${ClassName.TABLE_CONTAINER} {
|
|
766
|
+
.${ClassName.RESIZE_HANDLE_DECORATION} {
|
|
767
|
+
background-color: transparent;
|
|
768
|
+
position: absolute;
|
|
769
|
+
width: ${resizeHandlerAreaWidth}px;
|
|
770
|
+
height: 100%;
|
|
771
|
+
top: 0;
|
|
772
|
+
right: -${resizeHandlerAreaWidth / 2}px;
|
|
773
|
+
cursor: col-resize;
|
|
774
|
+
z-index: ${resizeHandlerZIndex};
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
${getLastColumnResizerOverrides()}
|
|
778
|
+
|
|
779
|
+
${resizeHandleOverrides(props)}
|
|
736
780
|
|
|
737
781
|
table
|
|
738
782
|
tr:first-of-type
|
|
@@ -22,10 +22,16 @@ import {
|
|
|
22
22
|
getCellsInRow,
|
|
23
23
|
getSelectionRect,
|
|
24
24
|
} from '@atlaskit/editor-tables/utils';
|
|
25
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
25
26
|
|
|
26
|
-
import type {
|
|
27
|
+
import type {
|
|
28
|
+
Cell,
|
|
29
|
+
CellColumnPositioning,
|
|
30
|
+
CellHoverCoordinates,
|
|
31
|
+
} from '../types';
|
|
27
32
|
import { TableCssClassName as ClassName, TableDecorations } from '../types';
|
|
28
33
|
import { ColumnResizeWidget } from '../ui/ColumnResizeWidget';
|
|
34
|
+
import { DragHandle } from '../ui/DragHandle';
|
|
29
35
|
|
|
30
36
|
const filterDecorationByKey = (
|
|
31
37
|
key: TableDecorations,
|
|
@@ -206,35 +212,77 @@ export const createColumnSelectedDecoration = (
|
|
|
206
212
|
|
|
207
213
|
export const createColumnControlsDecoration = (
|
|
208
214
|
selection: Selection,
|
|
215
|
+
hoverLocation?: CellHoverCoordinates,
|
|
209
216
|
): Decoration[] => {
|
|
217
|
+
// todo: issue here where table may not be selected yet
|
|
210
218
|
const cells: ContentNodeWithPos[] = getCellsInRow(0)(selection) || [];
|
|
211
|
-
|
|
212
|
-
return cells.map((cell) => {
|
|
213
|
-
const colspan = (cell.node.attrs as CellAttributes).colspan || 1;
|
|
214
|
-
// It's important these values are scoped locally as the widget callback could be executed anytime in the future
|
|
215
|
-
// and we want to avoid value leak
|
|
216
|
-
const startIndex = index;
|
|
217
|
-
const endIndex = startIndex + colspan;
|
|
218
|
-
|
|
219
|
-
// The next cell start index will commence from the current cell end index.
|
|
220
|
-
index = endIndex;
|
|
219
|
+
const table = findTable(selection);
|
|
221
220
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
221
|
+
if (
|
|
222
|
+
getBooleanFF('platform.editor.table.drag-and-drop') &&
|
|
223
|
+
hoverLocation &&
|
|
224
|
+
!Number.isNaN(hoverLocation?.colIndex) &&
|
|
225
|
+
table
|
|
226
|
+
) {
|
|
227
|
+
const colIndex = hoverLocation.colIndex as number;
|
|
228
|
+
const cell = cells[colIndex];
|
|
229
|
+
return [
|
|
230
|
+
Decoration.widget(
|
|
231
|
+
cell.pos + 1,
|
|
232
|
+
() => {
|
|
233
|
+
const element = document.createElement('div');
|
|
234
|
+
element.classList.add(
|
|
235
|
+
ClassName.COLUMN_CONTROLS_DECORATIONS_WITH_DRAG,
|
|
236
|
+
);
|
|
237
|
+
ReactDOM.render(
|
|
238
|
+
createElement(DragHandle, {
|
|
239
|
+
tableLocalId: table.node.attrs.localId,
|
|
240
|
+
direction: 'column',
|
|
241
|
+
indexes: [colIndex],
|
|
242
|
+
}),
|
|
243
|
+
element,
|
|
244
|
+
);
|
|
245
|
+
return element;
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
key: `${TableDecorations.COLUMN_CONTROLS_DECORATIONS}_${colIndex}`,
|
|
249
|
+
// this decoration should be the first one, even before gap cursor.
|
|
250
|
+
side: -100,
|
|
251
|
+
destroy: (node) => {
|
|
252
|
+
ReactDOM.unmountComponentAtNode(node as HTMLDivElement);
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
),
|
|
256
|
+
];
|
|
257
|
+
} else {
|
|
258
|
+
let index = 0;
|
|
259
|
+
return cells.map((cell) => {
|
|
260
|
+
const colspan = (cell.node.attrs as CellAttributes).colspan || 1;
|
|
261
|
+
// It's important these values are scoped locally as the widget callback could be executed anytime in the future
|
|
262
|
+
// and we want to avoid value leak
|
|
263
|
+
const startIndex = index;
|
|
264
|
+
const endIndex = startIndex + colspan;
|
|
265
|
+
|
|
266
|
+
// The next cell start index will commence from the current cell end index.
|
|
267
|
+
index = endIndex;
|
|
268
|
+
|
|
269
|
+
return Decoration.widget(
|
|
270
|
+
cell.pos + 1,
|
|
271
|
+
() => {
|
|
272
|
+
const element = document.createElement('div');
|
|
273
|
+
element.classList.add(ClassName.COLUMN_CONTROLS_DECORATIONS);
|
|
274
|
+
element.dataset.startIndex = `${startIndex}`;
|
|
275
|
+
element.dataset.endIndex = `${endIndex}`;
|
|
276
|
+
return element;
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
key: `${TableDecorations.COLUMN_CONTROLS_DECORATIONS}_${endIndex}`,
|
|
280
|
+
// this decoration should be the first one, even before gap cursor.
|
|
281
|
+
side: -100,
|
|
282
|
+
},
|
|
283
|
+
);
|
|
284
|
+
});
|
|
285
|
+
}
|
|
238
286
|
};
|
|
239
287
|
|
|
240
288
|
export const updateDecorations = (
|
|
@@ -36,10 +36,18 @@ export const isColumnControlsDecorations = (
|
|
|
36
36
|
node: HTMLElement | null,
|
|
37
37
|
): boolean => containsClassName(node, ClassName.COLUMN_CONTROLS_DECORATIONS);
|
|
38
38
|
|
|
39
|
+
export const isColumnDragControlsDecorations = (node: HTMLElement | null) =>
|
|
40
|
+
containsClassName(node, ClassName.COLUMN_CONTROLS_DECORATIONS_WITH_DRAG) ||
|
|
41
|
+
closestElement(node, `.${ClassName.COLUMN_CONTROLS_DECORATIONS_WITH_DRAG}`);
|
|
42
|
+
|
|
39
43
|
export const isRowControlsButton = (node: HTMLElement | null): boolean =>
|
|
40
44
|
containsClassName(node, ClassName.ROW_CONTROLS_BUTTON) ||
|
|
41
45
|
containsClassName(node, ClassName.NUMBERED_COLUMN_BUTTON);
|
|
42
46
|
|
|
47
|
+
export const isRowDragControlsButton = (node: HTMLElement | null) =>
|
|
48
|
+
containsClassName(node, ClassName.ROW_CONTROLS_WITH_DRAG) ||
|
|
49
|
+
closestElement(node, `.${ClassName.ROW_CONTROLS_WITH_DRAG}`);
|
|
50
|
+
|
|
43
51
|
export const isResizeHandleDecoration = (node: HTMLElement | null): boolean =>
|
|
44
52
|
containsClassName(node, ClassName.RESIZE_HANDLE_DECORATION);
|
|
45
53
|
|
package/tsconfig.app.json
CHANGED