import type { ContentEditorTableAlignment } from '@admin/utils/editor/content-editor-table-alignment' import type { Editor } from '@tiptap/react' import { getSelectedTableColumnCellPositions } from '@admin/utils/editor/get-selected-table-column-cell-positions' export function setActiveTableColumnAlignment( editor: Editor, alignment: ContentEditorTableAlignment ): boolean { const positions = getSelectedTableColumnCellPositions(editor) if (!positions.length) return false const tr = editor.state.tr let changed = false for (const position of positions) { const node = tr.doc.nodeAt(position) if (!node) continue if (node.type.name !== 'tableCell' && node.type.name !== 'tableHeader') { continue } if (node.attrs.align === alignment) continue tr.setNodeMarkup(position, undefined, { ...node.attrs, align: alignment }) changed = true } if (!changed) { editor.commands.focus() return true } editor.view.dispatch(tr.scrollIntoView()) editor.commands.focus() return true }