Files
outline/app/editor/menus/tableRow.tsx
codegen-sh[bot]andTom Moor dc3952212f Add table cell merge/unmerge functionality (#9322)
* Add table cell merge/unmerge functionality

- Add new tableCell menu with merge and unmerge options
- Update SelectionToolbar to show tableCell menu for CellSelection
- Add mergeCells and splitCell commands to Table node
- Add dictionary entries for merge/split cell tooltips
- Use placeholder icons (PlusIcon for merge, MoreIcon for split)

Fixes #6977

* fixes

* fix: Header cells end up floating with some effort

* refactor

* collapse

---------

Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com>
Co-authored-by: Tom Moor <tom@getoutline.com>
2025-06-08 22:05:29 -04:00

76 lines
1.8 KiB
TypeScript

import {
TrashIcon,
InsertAboveIcon,
InsertBelowIcon,
MoreIcon,
TableHeaderRowIcon,
TableSplitCellsIcon,
TableMergeCellsIcon,
} from "outline-icons";
import { EditorState } from "prosemirror-state";
import { CellSelection } from "prosemirror-tables";
import {
isMergedCellSelection,
isMultipleCellSelection,
} from "@shared/editor/queries/table";
import { MenuItem } from "@shared/editor/types";
import { Dictionary } from "~/hooks/useDictionary";
export default function tableRowMenuItems(
state: EditorState,
index: number,
dictionary: Dictionary
): MenuItem[] {
const { selection } = state;
if (!(selection instanceof CellSelection)) {
return [];
}
return [
{
icon: <MoreIcon />,
children: [
{
name: "toggleHeaderRow",
label: dictionary.toggleHeader,
icon: <TableHeaderRowIcon />,
visible: index === 0,
},
{
name: "addRowBefore",
label: dictionary.addRowBefore,
icon: <InsertAboveIcon />,
attrs: { index },
},
{
name: "addRowAfter",
label: dictionary.addRowAfter,
icon: <InsertBelowIcon />,
attrs: { index },
},
{
name: "mergeCells",
label: dictionary.mergeCells,
icon: <TableMergeCellsIcon />,
visible: isMultipleCellSelection(state),
},
{
name: "splitCell",
label: dictionary.splitCell,
icon: <TableSplitCellsIcon />,
visible: isMergedCellSelection(state),
},
{
name: "separator",
},
{
name: "deleteRow",
label: dictionary.deleteRow,
dangerous: true,
icon: <TrashIcon />,
},
],
},
];
}