From a66c75c52cdfa678f1e1bc51467db3f926f20c73 Mon Sep 17 00:00:00 2001 From: Petyo Ivanov Date: Sat, 18 Nov 2023 18:10:25 +0200 Subject: [PATCH] fix: table readOnly mode Fixes #101 --- docs/theming.md | 3 +- src/plugins/table/TableEditor.tsx | 127 ++++++++++++++++-------------- 2 files changed, 69 insertions(+), 61 deletions(-) diff --git a/docs/theming.md b/docs/theming.md index 54366d21..78767d2a 100644 --- a/docs/theming.md +++ b/docs/theming.md @@ -29,6 +29,7 @@ The example below swaps the editor gray/blue colors with tomato/mauve. In additi --accentText: var(--tomato11); --accentTextContrast: var(--tomato12); + --basePageBg: white; --baseBase: var(--mauve1); --baseBgSubtle: var(--mauve2); --baseBg: var(--mauve3); @@ -43,7 +44,7 @@ The example below swaps the editor gray/blue colors with tomato/mauve. In additi --baseTextContrast: var(--mauve12); color: var(--baseText); - background: var(--baseBg); + background: var(--basePageBg); } ``` diff --git a/src/plugins/table/TableEditor.tsx b/src/plugins/table/TableEditor.tsx index 66b715d5..94cf6be9 100644 --- a/src/plugins/table/TableEditor.tsx +++ b/src/plugins/table/TableEditor.tsx @@ -45,7 +45,7 @@ export interface TableEditorProps { export const TableEditor: React.FC = ({ mdastNode, parentEditor, lexicalTable }) => { const [activeCell, setActiveCell] = React.useState<[number, number] | null>(null) - const [iconComponentFor] = corePluginHooks.useEmitterValues('iconComponentFor') + const [iconComponentFor, readOnly] = corePluginHooks.useEmitterValues('iconComponentFor', 'readOnly') const getCellKey = React.useMemo(() => { const cellKeyMap = new WeakMap() return (cell: Mdast.TableCell) => { @@ -168,51 +168,55 @@ export const TableEditor: React.FC = ({ mdastNode, parentEdito - - - - - - {Array.from({ length: mdastNode.children[0].children.length }, (_, colIndex) => { - return ( - - - - ) - })} - - - + {readOnly || ( + + + + + + {Array.from({ length: mdastNode.children[0].children.length }, (_, colIndex) => { + return ( + + + + ) + })} + + + + )} {mdastNode.children.map((row, rowIndex) => { return ( - - - + {readOnly || ( + + + + )} {row.children.map((mdastCell, colIndex) => { return ( = ({ mdastNode, parentEdito colIndex, lexicalTable, parentEditor, - activeCell + activeCell: readOnly ? [-1, -1] : activeCell }} /> ) })} - {rowIndex === 0 && ( - - - - )} + {readOnly || + (rowIndex === 0 && ( + + + + ))} ) })} - - - - - - - - - + {readOnly || ( + + + + + + + + + + )} ) }