The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Bring back row and column controls in rich text tables (#28704)
neo773b5ba87f8f920
diff --git a/packages/twenty-docs/snippets/ui/generated/icon/catalog.mdx b/packages/twenty-docs/snippets/ui/generated/icon/catalog.mdxindex 520a2b8f625..0afae90f200 100644--- a/packages/twenty-docs/snippets/ui/generated/icon/catalog.mdx+++ b/packages/twenty-docs/snippets/ui/generated/icon/catalog.mdx@@ -116,6 +116,7 @@ Supported props: `color`, `size`, `stroke`, `title`. Native SVG attributes and r- `IconCodeCircle`- `IconCoins`- `IconColorSwatch`+- `IconColumnInsertLeft`- `IconColumnInsertRight`- `IconColumns`- `IconCommand`@@ -230,6 +231,7 @@ Supported props: `color`, `size`, `stroke`, `title`. Native SVG attributes and r- `IconGitCommit`- `IconGizmo`- `IconGraph`+- `IconGripHorizontal`- `IconGripVertical`- `IconH1`- `IconH2`diff --git a/packages/twenty-front/src/modules/advanced-text-editor/components/AdvancedTextEditor.tsx b/packages/twenty-front/src/modules/advanced-text-editor/components/AdvancedTextEditor.tsxindex eee0411b5a3..027e05f58fc 100644--- a/packages/twenty-front/src/modules/advanced-text-editor/components/AdvancedTextEditor.tsx+++ b/packages/twenty-front/src/modules/advanced-text-editor/components/AdvancedTextEditor.tsx@@ -1,12 +1,15 @@+import { AdvancedTextEditorTableHandles } from '@/advanced-text-editor/components/AdvancedTextEditorTableHandles';import { ImageBubbleMenu } from '@/advanced-text-editor/components/ImageBubbleMenu';import { LinkBubbleMenu } from '@/advanced-text-editor/components/LinkBubbleMenu';import { TextBubbleMenu } from '@/advanced-text-editor/components/TextBubbleMenu';+import { useHoveredTableCell } from '@/advanced-text-editor/hooks/useHoveredTableCell';import { type AdvancedTextEditorComponentProps } from '@/advanced-text-editor/types/AdvancedTextEditorComponentProps';import { getAdvancedTextEditorTypographyStyle } from '@/advanced-text-editor/utils/getAdvancedTextEditorTypographyStyle';import { hasEditorExtension } from '@/advanced-text-editor/utils/hasEditorExtension';import { FORM_FIELD_PLACEHOLDER_STYLES } from '@/ui/input/constants/FormFieldPlaceholderStyles';import { styled } from '@linaria/react';import { EditorContent } from '@tiptap/react';+import { isDefined, TIPTAP_NODE_TYPES } from 'twenty-shared/utils';import { themeCssVariables } from 'twenty-ui/theme';const StyledEditorContainer = styled.div<{@@ -17,6 +20,7 @@ const StyledEditorContainer = styled.div<{display: flex;flex-direction: column;height: 100%;+ position: relative;width: 100%;.editor-content {@@ -284,6 +288,8 @@ const StyledEditorContainer = styled.div<{.tableWrapper {margin: 0 0 var(--editor-block-spacing);overflow-x: auto;+ padding: 0 ${themeCssVariables.spacing[4]} ${themeCssVariables.spacing[4]}+ 0;}table {@@ -315,6 +321,7 @@ const StyledEditorContainer = styled.div<{background-color: ${themeCssVariables.color.blue3};content: '';inset: 0;+ mix-blend-mode: multiply;pointer-events: none;position: absolute;}@@ -504,14 +511,34 @@ export const AdvancedTextEditor = ({const hasTextBubbleMenu = TEXT_BUBBLE_MENU_EXTENSION_NAMES.some((extensionName) => hasEditorExtension(editor, extensionName),);+ const {+ hoveredTableCell,+ handleMouseMove,+ handleMouseLeave,+ handleTableMenuOpenChange,+ clearHoveredTableCell,+ } = useHoveredTableCell({+ editor,+ isEnabled: !readonly && hasEditorExtension(editor, TIPTAP_NODE_TYPES.TABLE),+ });return (<StyledEditorContainerreadonly={readonly}minHeight={minHeight}style={getAdvancedTextEditorTypographyStyle(variant)}+ onMouseMove={handleMouseMove}+ onMouseLeave={handleMouseLeave}><EditorContent className="editor-content" editor={editor} />+ {isDefined(hoveredTableCell) && (+ <AdvancedTextEditorTableHandles+ editor={editor}+ hoveredTableCell={hoveredTableCell}+ onMenuOpenChange={handleTableMenuOpenChange}+ onCellCommandRun={clearHoveredTableCell}+ />+ )}{hasEditorExtension(editor, 'image') &&!hasEditorExtension(editor, 'section') && (<ImageBubbleMenu editor={editor} />diff --git a/packages/twenty-front/src/modules/advanced-text-editor/components/AdvancedTextEditorBlockHandle.tsx b/packages/twenty-front/src/modules/advanced-text-editor/components/AdvancedTextEditorBlockHandle.tsxindex 63147fa4ee7..282175ee823 100644--- a/packages/twenty-front/src/modules/advanced-text-editor/components/AdvancedTextEditorBlockHandle.tsx+++ b/packages/twenty-front/src/modules/advanced-text-editor/components/AdvancedTextEditorBlockHandle.tsx@@ -22,12 +22,17 @@ const DRAG_HANDLE_OPTIONS: Pick<edgeDetection: 'none',rules: [{- id: 'excludeColumnAndItsContent',+ id: 'excludeColumnAndColumnOrTableContent',evaluate: ({ node, $pos, depth }) =>node.type.name === TIPTAP_NODE_TYPES.COLUMN ||- Array.from({ length: depth }, (_, ancestorDepth) =>- $pos.node(ancestorDepth),- ).some((ancestor) => ancestor.type.name === TIPTAP_NODE_TYPES.COLUMN)+ Array.from(+ { length: depth },+ (_, ancestorDepth) => $pos.node(ancestorDepth).type.name,+ ).some(+ (ancestorType) =>+ ancestorType === TIPTAP_NODE_TYPES.COLUMN ||+ ancestorType === TIPTAP_NODE_TYPES.TABLE,+ )? 1000: 0,},diff --git a/packages/twenty-front/src/modules/advanced-text-editor/components/AdvancedTextEditorBlockHandleMenu.tsx b/packages/twenty-front/src/modules/advanced-text-editor/components/AdvancedTextEditorBlockHandleMenu.tsxindex 5ac345dfd36..bcc680160ae 100644--- a/packages/twenty-front/src/modules/advanced-text-editor/components/AdvancedTextEditorBlockHandleMenu.tsx+++ b/packages/twenty-front/src/modules/advanced-text-editor/components/AdvancedTextEditorBlockHandleMenu.tsx@@ -6,7 +6,7 @@ import { DropdownContent } from '@/ui/layout/dropdown/components/DropdownContentimport { DropdownRoot } from '@/ui/layout/dropdown/components/DropdownRoot';import { GenericDropdownContentWidth } from '@/ui/layout/dropdown/constants/GenericDropdownContentWidth';import { useLingui } from '@lingui/react/macro';-import { type Editor } from '@tiptap/core';+import { type ChainedCommands, type Editor } from '@tiptap/core';import { useId } from 'react';import { isDefined, TIPTAP_NODE_TYPES } from 'twenty-shared/utils';import { LightIconButton } from 'twenty-ui/components/input';@@ -65,6 +65,24 @@ export const AdvancedTextEditorBlockHandleMenu = ({const currentBlockTypeTitle = turnIntoOptions.find(({ id }) => id === currentBlockTypeOptionId,)?.title;+ const isTable = blockNode.type.name === TIPTAP_NODE_TYPES.TABLE;+ const hasHeaderRow =+ blockNode.firstChild?.children.every(+ (cell) => cell.type.name === TIPTAP_NODE_TYPES.TABLE_HEADER,+ ) ?? false;+ const hasHeaderColumn = blockNode.children.every(+ (row) => row.firstChild?.type.name === TIPTAP_NODE_TYPES.TABLE_HEADER,+ );++ const handleToggleTableHeader = (+ toggleHeader: (chain: ChainedCommands) => ChainedCommands,+ ) =>+ toggleHeader(+ editor+ .chain()+ .focus()+ .setCellSelection({ anchorCell: blockPos + 2 }),+ ).run();const handleAddBlock = () =>editor@@ -170,6 +188,29 @@ export const AdvancedTextEditorBlockHandleMenu = ({<Dropdown.Separator /></>)}+ {isTable && (+ <>+ <Dropdown.Section>+ <Dropdown.OptionItem+ selected={hasHeaderRow}+ onSelect={() =>+ handleToggleTableHeader((chain) => chain.toggleHeaderRow())+ }+ >+ {t`Header row`}+ </Dropdown.OptionItem>+ <Dropdown.OptionItem+ selected={hasHeaderColumn}+ onSelect={() =>+ handleToggleTableHeader((chain) => chain.toggleHeaderColumn())+ }+ >+ {t`Header column`}+ </Dropdown.OptionItem>+ </Dropdown.Section>+ <Dropdown.Separator />+ </>+ )}<Dropdown.Section><Dropdown.ActionItemstartIcon={<IconPlus />}diff --git a/packages/twenty-front/src/modules/advanced-text-editor/components/AdvancedTextEditorTableHandleMenu.tsx b/packages/twenty-front/src/modules/advanced-text-editor/components/AdvancedTextEditorTableHandleMenu.tsxnew file mode 100644index 00000000000..8ce90e2b9f0--- /dev/null+++ b/packages/twenty-front/src/modules/advanced-text-editor/components/AdvancedTextEditorTableHandleMenu.tsx@@ -0,0 +1,224 @@+import { type HoveredTableCell } from '@/advanced-text-editor/types/HoveredTableCell';+import { runTableCellCommand } from '@/advanced-text-editor/utils/runTableCellCommand';+import { DropdownContent } from '@/ui/layout/dropdown/components/DropdownContent';+import { DropdownRoot } from '@/ui/layout/dropdown/components/DropdownRoot';+import { GenericDropdownContentWidth } from '@/ui/layout/dropdown/constants/GenericDropdownContentWidth';+import { styled } from '@linaria/react';+import { useLingui } from '@lingui/react/macro';+import { type ChainedCommands, type Editor } from '@tiptap/core';+import { useId } from 'react';+import { Dropdown } from 'twenty-ui/components/navigation';+import {+ type IconComponent,+ IconArrowMerge,+ IconArrowsSplit2,+ IconColumnInsertLeft,+ IconColumnInsertRight,+ IconGripHorizontal,+ IconGripVertical,+ IconRowInsertBottom,+ IconRowInsertTop,+ IconTrash,+} from 'twenty-ui/icon';+import { themeCssVariables, useTheme } from 'twenty-ui/theme';++const StyledHandle = styled.div`+ position: absolute;+ transform: translate(-50%, -50%);+ z-index: 1;+`;++const StyledHandleButton = styled.button`+ align-items: center;+ background-color: ${themeCssVariables.background.primary};+ border: 1px solid ${themeCssVariables.border.color.medium};+ border-radius: ${themeCssVariables.border.radius.sm};+ color: ${themeCssVariables.font.color.tertiary};+ cursor: pointer;+ display: flex;+ justify-content: center;+ padding: 0;++ &:hover {+ background-color: ${themeCssVariables.background.tertiary};+ }+`;++const HANDLE_LENGTH = 24;+const HANDLE_THICKNESS = 14;++type TableHandleOrientation = 'row' | 'column';++type TableHandleAction = {+ label: string;+ icon: IconComponent;+ command: (chain: ChainedCommands) => ChainedCommands;+};++type AdvancedTextEditorTableHandleMenuProps = {+ editor: Editor;+ hoveredTableCell: HoveredTableCell;+ orientation: TableHandleOrientation;+ onOpenChange: (isOpen: boolean) => void;+};++export const AdvancedTextEditorTableHandleMenu = ({+ editor,+ hoveredTableCell,+ orientation,+ onOpenChange,+}: AdvancedTextEditorTableHandleMenuProps) => {+ const { t } = useLingui();+ const theme = useTheme();+ const instanceId = useId();++ const getHandleDisplay = () => {+ switch (orientation) {+ case 'row':+ return {+ ariaLabel: t`Open row menu`,+ HandleIcon: IconGripVertical,+ size: { width: HANDLE_THICKNESS, height: HANDLE_LENGTH },+ position: {+ left: hoveredTableCell.tableLeft,+ top: hoveredTableCell.rowTop + hoveredTableCell.rowHeight / 2,+ },+ insertActions: [+ {+ label: t`Add row above`,+ icon: IconRowInsertTop,+ command: (chain) => chain.addRowBefore(),+ },+ {+ label: t`Add row below`,+ icon: IconRowInsertBottom,+ command: (chain) => chain.addRowAfter(),+ },+ ] satisfies TableHandleAction[],+ deleteAction: {+ label: t`Delete row`,+ icon: IconTrash,+ command: (chain) => chain.deleteRow(),+ } satisfies TableHandleAction,+ };+ case 'column':+ return {+ ariaLabel: t`Open column menu`,+ HandleIcon: IconGripHorizontal,+ size: { width: HANDLE_LENGTH, height: HANDLE_THICKNESS },+ position: {+ left:+ hoveredTableCell.columnLeft + hoveredTableCell.columnWidth / 2,+ top: hoveredTableCell.tableTop,+ },+ insertActions: [+ {+ label: t`Add column left`,+ icon: IconColumnInsertLeft,+ command: (chain) => chain.addColumnBefore(),+ },+ {+ label: t`Add column right`,+ icon: IconColumnInsertRight,+ command: (chain) => chain.addColumnAfter(),+ },+ ] satisfies TableHandleAction[],+ deleteAction: {+ label: t`Delete column`,+ icon: IconTrash,+ command: (chain) => chain.deleteColumn(),+ } satisfies TableHandleAction,+ };+ }+ };++ const { ariaLabel, HandleIcon, size, position, insertActions, deleteAction } =+ getHandleDisplay();+ const canMergeCells = editor.can().mergeCells();+ const canSplitCell = editor.can().splitCell();++ const runOnHoveredCell = ({ command }: TableHandleAction) =>+ runTableCellCommand({+ editor,+ tablePosition: hoveredTableCell.tablePosition,+ rowIndex: hoveredTableCell.rowIndex,+ columnIndex: hoveredTableCell.columnIndex,+ command,+ });++ return (+ <StyledHandle data-table-handle style={position}>+ <DropdownRoot+ dropdownId={`advanced-text-editor-table-${orientation}-handle-${instanceId}`}+ type="menu"+ onOpenChange={onOpenChange}+ >+ <Dropdown.Trigger+ render={+ <StyledHandleButton+ type="button"+ aria-label={ariaLabel}+ style={size}+ onMouseDown={(event) => event.preventDefault()}+ >+ <HandleIcon+ size={theme.icon.size.sm}+ stroke={theme.icon.stroke.lg}+ />+ </StyledHandleButton>+ }+ />+ <DropdownContent+ side="bottom"+ align="start"+ width={GenericDropdownContentWidth.Medium}+ >+ <Dropdown.Section>+ {insertActions.map((action) => (+ <Dropdown.ActionItem+ key={action.label}+ startIcon={<action.icon />}+ onClick={() => runOnHoveredCell(action)}+ >+ {action.label}+ </Dropdown.ActionItem>+ ))}+ </Dropdown.Section>+ {(canMergeCells || canSplitCell) && (+ <>+ <Dropdown.Separator />+ <Dropdown.Section>+ {canMergeCells && (+ <Dropdown.ActionItem+ startIcon={<IconArrowMerge />}+ onClick={() => editor.chain().focus().mergeCells().run()}+ >+ {t`Merge cells`}+ </Dropdown.ActionItem>+ )}+ {canSplitCell && (+ <Dropdown.ActionItem+ startIcon={<IconArrowsSplit2 />}+ onClick={() => editor.chain().focus().splitCell().run()}+ >+ {t`Split cell`}+ </Dropdown.ActionItem>+ )}+ </Dropdown.Section>+ </>+ )}+ <Dropdown.Separator />+ <Dropdown.Section>+ <Dropdown.ActionItem+ color="danger"+ startIcon={<deleteAction.icon />}+ onClick={() => runOnHoveredCell(deleteAction)}+ >+ {deleteAction.label}+ </Dropdown.ActionItem>+ </Dropdown.Section>+ </DropdownContent>+ </DropdownRoot>+ </StyledHandle>+ );+};diff --git a/packages/twenty-front/src/modules/advanced-text-editor/components/AdvancedTextEditorTableHandles.tsx b/packages/twenty-front/src/modules/advanced-text-editor/components/AdvancedTextEditorTableHandles.tsxnew file mode 100644index 00000000000..7e7dc810120--- /dev/null+++ b/packages/twenty-front/src/modules/advanced-text-editor/components/AdvancedTextEditorTableHandles.tsx@@ -0,0 +1,113 @@+import { AdvancedTextEditorTableHandleMenu } from '@/advanced-text-editor/components/AdvancedTextEditorTableHandleMenu';+import { type HoveredTableCell } from '@/advanced-text-editor/types/HoveredTableCell';+import { runTableCellCommand } from '@/advanced-text-editor/utils/runTableCellCommand';+import { styled } from '@linaria/react';+import { useLingui } from '@lingui/react/macro';+import { type Editor } from '@tiptap/core';+import { IconPlus } from 'twenty-ui/icon';+import { themeCssVariables } from 'twenty-ui/theme';++const StyledExtendButton = styled.button`+ align-items: center;+ background-color: ${themeCssVariables.background.transparent.light};+ border: none;+ border-radius: ${themeCssVariables.border.radius.sm};+ color: ${themeCssVariables.font.color.tertiary};+ cursor: pointer;+ display: flex;+ justify-content: center;+ padding: 0;+ position: absolute;+ z-index: 1;++ &:hover {+ background-color: ${themeCssVariables.background.transparent.medium};+ }+`;++const EXTEND_BUTTON_THICKNESS = themeCssVariables.spacing[4];++type AdvancedTextEditorTableHandlesProps = {+ editor: Editor;+ hoveredTableCell: HoveredTableCell;+ onMenuOpenChange: (isOpen: boolean) => void;+ onCellCommandRun: () => void;+};++export const AdvancedTextEditorTableHandles = ({+ editor,+ hoveredTableCell,+ onMenuOpenChange,+ onCellCommandRun,+}: AdvancedTextEditorTableHandlesProps) => {+ const { t } = useLingui();++ const handleAddRowAtEnd = () => {+ runTableCellCommand({+ editor,+ tablePosition: hoveredTableCell.tablePosition,+ rowIndex: hoveredTableCell.rowCount - 1,+ columnIndex: 0,+ command: (chain) => chain.addRowAfter(),+ });+ onCellCommandRun();+ };++ const handleAddColumnAtEnd = () => {+ runTableCellCommand({+ editor,+ tablePosition: hoveredTableCell.tablePosition,+ rowIndex: 0,+ columnIndex: hoveredTableCell.columnCount - 1,+ command: (chain) => chain.addColumnAfter(),+ });+ onCellCommandRun();+ };++ return (+ <>+ <AdvancedTextEditorTableHandleMenu+ editor={editor}+ hoveredTableCell={hoveredTableCell}+ orientation="row"+ onOpenChange={onMenuOpenChange}+ />+ <AdvancedTextEditorTableHandleMenu+ editor={editor}+ hoveredTableCell={hoveredTableCell}+ orientation="column"+ onOpenChange={onMenuOpenChange}+ />+ <StyledExtendButton+ type="button"+ data-table-handle+ aria-label={t`Add row`}+ style={{+ left: hoveredTableCell.tableLeft,+ top: hoveredTableCell.tableTop + hoveredTableCell.tableHeight,+ width: hoveredTableCell.tableWidth,+ height: EXTEND_BUTTON_THICKNESS,+ }}+ onMouseDown={(event) => event.preventDefault()}+ onClick={handleAddRowAtEnd}+ >+ <IconPlus size={12} />+ </StyledExtendButton>+ <StyledExtendButton+ type="button"+ data-table-handle+ aria-label={t`Add column`}+ style={{+ left: hoveredTableCell.tableLeft + hoveredTableCell.tableWidth,+ top: hoveredTableCell.tableTop,+ width: EXTEND_BUTTON_THICKNESS,+ height: hoveredTableCell.tableHeight,+ }}+ onMouseDown={(event) => event.preventDefault()}+ onClick={handleAddColumnAtEnd}+ >+ <IconPlus size={12} />+ </StyledExtendButton>+ </>+ );+};diff --git a/packages/twenty-front/src/modules/advanced-text-editor/hooks/useHoveredTableCell.ts b/packages/twenty-front/src/modules/advanced-text-editor/hooks/useHoveredTableCell.tsnew file mode 100644index 00000000000..89aa7961935--- /dev/null+++ b/packages/twenty-front/src/modules/advanced-text-editor/hooks/useHoveredTableCell.ts@@ -0,0 +1,60 @@+import { type HoveredTableCell } from '@/advanced-text-editor/types/HoveredTableCell';+import { getHoveredTableCell } from '@/advanced-text-editor/utils/getHoveredTableCell';+import { type Editor } from '@tiptap/core';+import { type MouseEvent, useState } from 'react';+import { isDefined } from 'twenty-shared/utils';++export const useHoveredTableCell = ({+ editor,+ isEnabled,+}: {+ editor: Editor;+ isEnabled: boolean;+}) => {+ const [hoveredTableCell, setHoveredTableCell] =+ useState<HoveredTableCell | null>(null);+ const [isTableMenuOpen, setIsTableMenuOpen] = useState(false);++ const handleMouseMove = (event: MouseEvent<HTMLDivElement>) => {+ if (+ !isEnabled ||+ isTableMenuOpen ||+ !(event.target instanceof Element) ||+ isDefined(event.target.closest('[data-table-handle]'))+ ) {+ return;+ }++ setHoveredTableCell(+ getHoveredTableCell({+ view: editor.view,+ target: event.target,+ container: event.currentTarget,+ }),+ );+ };++ const handleMouseLeave = () => {+ if (!isTableMenuOpen) {+ setHoveredTableCell(null);+ }+ };++ const handleTableMenuOpenChange = (isOpen: boolean) => {+ setIsTableMenuOpen(isOpen);++ if (!isOpen) {+ setHoveredTableCell(null);+ }+ };++ const clearHoveredTableCell = () => setHoveredTableCell(null);++ return {+ hoveredTableCell,+ handleMouseMove,+ handleMouseLeave,+ handleTableMenuOpenChange,+ clearHoveredTableCell,+ };+};diff --git a/packages/twenty-front/src/modules/advanced-text-editor/types/HoveredTableCell.ts b/packages/twenty-front/src/modules/advanced-text-editor/types/HoveredTableCell.tsnew file mode 100644index 00000000000..68c4557ba99--- /dev/null+++ b/packages/twenty-front/src/modules/advanced-text-editor/types/HoveredTableCell.ts@@ -0,0 +1,15 @@+export type HoveredTableCell = {+ tablePosition: number;+ rowIndex: number;+ columnIndex: number;+ rowCount: number;+ columnCount: number;+ rowTop: number;+ rowHeight: number;+ columnLeft: number;+ columnWidth: number;+ tableTop: number;+ tableLeft: number;+ tableWidth: number;+ tableHeight: number;+};diff --git a/packages/twenty-front/src/modules/advanced-text-editor/utils/getHoveredTableCell.ts b/packages/twenty-front/src/modules/advanced-text-editor/utils/getHoveredTableCell.tsnew file mode 100644index 00000000000..665c2b21c18--- /dev/null+++ b/packages/twenty-front/src/modules/advanced-text-editor/utils/getHoveredTableCell.ts@@ -0,0 +1,69 @@+import { TableMap } from '@tiptap/pm/tables';+import { type EditorView } from '@tiptap/pm/view';+import { doNotTranslate } from 'twenty-shared/i18n';+import { isDefined, TIPTAP_NODE_TYPES } from 'twenty-shared/utils';++import { type HoveredTableCell } from '@/advanced-text-editor/types/HoveredTableCell';++type GetHoveredTableCellArgs = {+ view: EditorView;+ target: Element;+ container: HTMLElement;+};++export const getHoveredTableCell = ({+ view,+ target,+ container,+}: GetHoveredTableCellArgs): HoveredTableCell | null => {+ const cellElement = target.closest(doNotTranslate('td, th'));+ const rowElement = cellElement?.closest('tr');+ const tableElement = cellElement?.closest('table');++ if (+ !isDefined(cellElement) ||+ !isDefined(rowElement) ||+ !isDefined(tableElement) ||+ !view.dom.contains(cellElement)+ ) {+ return null;+ }++ const cellPosition = view.posAtDOM(cellElement, 0) - 1;+ const $cell = view.state.doc.resolve(cellPosition);++ if ($cell.depth < 2 || $cell.node(-1).type.name !== TIPTAP_NODE_TYPES.TABLE) {+ return null;+ }++ const table = $cell.node(-1);+ const tablePosition = $cell.before(-1);+ const tableMap = TableMap.get(table);+ const cellRect = tableMap.findCell(cellPosition - tablePosition - 1);++ const containerRect = container.getBoundingClientRect();+ const visibleRect = (+ tableElement.parentElement ?? tableElement+ ).getBoundingClientRect();+ const tableRect = tableElement.getBoundingClientRect();+ const rowRect = rowElement.getBoundingClientRect();+ const columnRect = cellElement.getBoundingClientRect();+ const tableLeft = Math.max(tableRect.left, visibleRect.left);+ const tableRight = Math.min(tableRect.right, visibleRect.right);++ return {+ tablePosition,+ rowIndex: cellRect.top,+ columnIndex: cellRect.left,+ rowCount: tableMap.height,+ columnCount: tableMap.width,+ rowTop: rowRect.top - containerRect.top,+ rowHeight: rowRect.height,+ columnLeft: columnRect.left - containerRect.left,+ columnWidth: columnRect.width,+ tableTop: tableRect.top - containerRect.top,+ tableLeft: tableLeft - containerRect.left,+ tableWidth: tableRight - tableLeft,+ tableHeight: tableRect.height,+ };+};diff --git a/packages/twenty-front/src/modules/advanced-text-editor/utils/runTableCellCommand.ts b/packages/twenty-front/src/modules/advanced-text-editor/utils/runTableCellCommand.tsnew file mode 100644index 00000000000..fbbfcf34bc6--- /dev/null+++ b/packages/twenty-front/src/modules/advanced-text-editor/utils/runTableCellCommand.ts@@ -0,0 +1,38 @@+import { type ChainedCommands, type Editor } from '@tiptap/core';+import { TableMap } from '@tiptap/pm/tables';+import { TIPTAP_NODE_TYPES } from 'twenty-shared/utils';++type RunTableCellCommandArgs = {+ editor: Editor;+ tablePosition: number;+ rowIndex: number;+ columnIndex: number;+ command: (chain: ChainedCommands) => ChainedCommands;+};++export const runTableCellCommand = ({+ editor,+ tablePosition,+ rowIndex,+ columnIndex,+ command,+}: RunTableCellCommandArgs) => {+ const table = editor.state.doc.nodeAt(tablePosition);++ if (table?.type.name !== TIPTAP_NODE_TYPES.TABLE) {+ return;+ }++ const tableMap = TableMap.get(table);++ if (rowIndex >= tableMap.height || columnIndex >= tableMap.width) {+ return;+ }++ const cellPosition =+ tablePosition + 1 + tableMap.map[rowIndex * tableMap.width + columnIndex];++ command(+ editor.chain().focus().setCellSelection({ anchorCell: cellPosition }),+ ).run();+};diff --git a/packages/twenty-front/vite.config.ts b/packages/twenty-front/vite.config.tsindex 24da06d8f8a..d9c452a833e 100644--- a/packages/twenty-front/vite.config.ts+++ b/packages/twenty-front/vite.config.ts@@ -207,6 +207,7 @@ export default defineConfig(({ mode }) => {'@nivo/arcs','@react-spring/web','d3-shape',+ '@tiptap/pm/tables',],},diff --git a/packages/twenty-ui/docs/public-exports.json b/packages/twenty-ui/docs/public-exports.jsonindex d9132e14440..03fc2e4187b 100644--- a/packages/twenty-ui/docs/public-exports.json+++ b/packages/twenty-ui/docs/public-exports.json@@ -319,6 +319,7 @@"IconCodeCircle": "icon/components/TablerIcons","IconCoins": "icon/components/TablerIcons","IconColorSwatch": "icon/components/TablerIcons",+ "IconColumnInsertLeft": "icon/components/TablerIcons","IconColumnInsertRight": "icon/components/TablerIcons","IconColumns": "icon/components/TablerIcons","IconCommand": "icon/components/TablerIcons",@@ -436,6 +437,7 @@"IconGoogle": "icon/components/IconGoogle","IconGoogleCalendar": "icon/components/IconGoogleCalendar","IconGraph": "icon/components/TablerIcons",+ "IconGripHorizontal": "icon/components/TablerIcons","IconGripVertical": "icon/components/TablerIcons","IconH1": "icon/components/TablerIcons","IconH2": "icon/components/TablerIcons",diff --git a/packages/twenty-ui/generated/icons.docs.json b/packages/twenty-ui/generated/icons.docs.jsonindex 0cd4e21663c..4efd7608096 100644--- a/packages/twenty-ui/generated/icons.docs.json+++ b/packages/twenty-ui/generated/icons.docs.json@@ -102,6 +102,7 @@"IconCodeCircle","IconCoins","IconColorSwatch",+ "IconColumnInsertLeft","IconColumnInsertRight","IconColumns","IconCommand",@@ -216,6 +217,7 @@"IconGitCommit","IconGizmo","IconGraph",+ "IconGripHorizontal","IconGripVertical","IconH1","IconH2",diff --git a/packages/twenty-ui/src/icon/components/TablerIcons.ts b/packages/twenty-ui/src/icon/components/TablerIcons.tsindex 6a04a7a1068..f30a1a507c3 100644--- a/packages/twenty-ui/src/icon/components/TablerIcons.ts+++ b/packages/twenty-ui/src/icon/components/TablerIcons.ts@@ -101,6 +101,7 @@ export {IconCodeCircle,IconCoins,IconColorSwatch,+ IconColumnInsertLeft,IconColumnInsertRight,IconColumns,IconCommand,@@ -216,6 +217,7 @@ export {IconGitCommit,IconGizmo,IconGraph,+ IconGripHorizontal,IconGripVertical,IconH1,IconH2,diff --git a/packages/twenty-ui/src/icon/index.ts b/packages/twenty-ui/src/icon/index.tsindex 45a5d2d1788..079eb764580 100644--- a/packages/twenty-ui/src/icon/index.ts+++ b/packages/twenty-ui/src/icon/index.ts@@ -157,6 +157,7 @@ export {IconCodeCircle,IconCoins,IconColorSwatch,+ IconColumnInsertLeft,IconColumnInsertRight,IconColumns,IconCommand,@@ -272,6 +273,7 @@ export {IconGitCommit,IconGizmo,IconGraph,+ IconGripHorizontal,IconGripVertical,IconH1,IconH2,