A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
editor: only show table toolbars when table is selected
Abdullah Atta33bf5e26ffd3
diff --git a/packages/editor/src/extensions/table/component.tsx b/packages/editor/src/extensions/table/component.tsxindex aace614db..d9cbf724a 100644--- a/packages/editor/src/extensions/table/component.tsx+++ b/packages/editor/src/extensions/table/component.tsx@@ -135,16 +135,21 @@ type TableToolbarProps = {};function TableRowToolbar(props: TableToolbarProps) {- const { editor, textDirection } = props;+ const { editor, textDirection, table } = props;const rowToolsRef = useRef<HTMLDivElement>(null);useEffect(() => {function onSelectionUpdate() {- if (!rowToolsRef.current) {+ if (!rowToolsRef.current || !table?.current) {return;}+const currentRow = findSelectedDOMNode(editor, ["tableRow"]);- if (!currentRow) return;+ if (!currentRow || !table.current.contains(currentRow)) {+ rowToolsRef.current.style.display = "none";+ return;+ }+ rowToolsRef.current.style.display = "flex";const pos = getPosition(rowToolsRef.current, {location: "left",@@ -153,6 +158,7 @@ function TableRowToolbar(props: TableToolbarProps) {xOffset: -5,yOffset: -3});+rowToolsRef.current.style.top = `${pos.top}px`;if (textDirection) {rowToolsRef.current.style.right = `${pos.left}px`;@@ -173,6 +179,7 @@ function TableRowToolbar(props: TableToolbarProps) {<Flexref={rowToolsRef}sx={{+ display: "none",zIndex: 999,top: 0,left: 0,@@ -216,7 +223,11 @@ function TableColumnToolbar(props: TableToolbarProps) {"tableCell","tableHeader"]);- if (!currentCell) return;+ if (!currentCell || !table.current.contains(currentCell)) {+ columnToolsRef.current.style.display = `none`;+ return;+ }+ columnToolsRef.current.style.display = "flex";// tableRef.currentconst pos = getPosition(columnToolsRef.current, {@@ -241,6 +252,7 @@ function TableColumnToolbar(props: TableToolbarProps) {<Flexref={columnToolsRef}sx={{+ display: "none",zIndex: 999,top: 0,left: 0,diff --git a/packages/editor/styles/styles.css b/packages/editor/styles/styles.cssindex 10edaad6e..56d215424 100644--- a/packages/editor/styles/styles.css+++ b/packages/editor/styles/styles.css@@ -198,6 +198,10 @@ img.ProseMirror-separator {vertical-align: top;}+.ProseMirror table .selectedCell {+ border-color: var(--primary);+}+.ProseMirror table td > *,.ProseMirror table th > * {margin-bottom: 0;@@ -226,7 +230,7 @@ img.ProseMirror-separator {background-color: var(--primary);bottom: -2px;position: absolute;- right: -2px;+ right: 0px;pointer-events: none;top: 0;width: 5px;