@@ -11,22 +11,6 @@ import { c } from "helpers/StylesHelper";
1111import CalendarPortal from "./portals/CalendarPortal" ;
1212import { TableColumn } from "cdm/FolderModel" ;
1313
14- /**
15- * Obtain the path of the file inside cellValue
16- * i.e. if cellValue is "[[path/to/file.md|File Name]]" then return "path/to/file.md"
17- * i.e. if cellValue is "[[path/to/file.md]]" then return "path/to/file.md"
18- * i.e. if cellValue is "[[file.md]]" then return "file.md"
19- * @param cellValue
20- */
21- function getFilePath ( cellValue : string ) : string {
22- const regex = / \[ \[ ( .* ) \] \] / ;
23- const matches = regex . exec ( cellValue ) ;
24- if ( matches && matches . length > 1 ) {
25- return matches [ 1 ] ;
26- }
27- return "" ;
28- }
29-
3014export default function DefaultCell ( cellProperties : Cell ) {
3115 const dataDispatch = ( cellProperties as any ) . dataDispatch ;
3216 /** Initial state of cell */
@@ -37,6 +21,8 @@ export default function DefaultCell(cellProperties: Cell) {
3721 const dataType = ( cellProperties . column as any ) . dataType ;
3822 /** Note info of current Cell */
3923 const note : NoteInfo = ( cellProperties . row . original as any ) . note ;
24+ /** Ref to cell container */
25+ const containerCellRef = useRef < HTMLDivElement > ( ) ;
4026 /** state of cell value */
4127 const [ contextValue , setContextValue ] = useState ( {
4228 value : initialValue ,
@@ -59,6 +45,19 @@ export default function DefaultCell(cellProperties: Cell) {
5945 }
6046 } , [ ] ) ;
6147
48+ useLayoutEffect ( ( ) => {
49+ if ( ! dirtyCell && containerCellRef . current ) {
50+ //TODO - this is a hack. find why is layout effect called twice
51+ containerCellRef . current . innerHTML = "" ;
52+ MarkdownRenderer . renderMarkdown (
53+ contextValue . value ,
54+ containerCellRef . current ,
55+ note . getFile ( ) . path ,
56+ null
57+ ) ;
58+ }
59+ } , [ dirtyCell ] ) ;
60+
6261 const handleKeyDown = ( event : any ) => {
6362 if ( event . key === "Enter" ) {
6463 event . target . blur ( ) ;
@@ -95,49 +94,43 @@ export default function DefaultCell(cellProperties: Cell) {
9594 setDirtyCell ( false ) ;
9695 }
9796
98- function obsidianMarkdownContainer ( mdContain : string ) {
99- const containerRef = useRef < HTMLElement > ( ) ;
100- useLayoutEffect ( ( ) => {
101- MarkdownRenderer . renderMarkdown (
102- initialValue ,
103- containerRef . current ,
104- mdContain ,
105- null
106- ) ;
107- } ) ;
108- return < span ref = { containerRef } className = { `${ c ( "md_cell" ) } ` } > </ span > ;
109- }
110-
111- function contentEditableContainer ( className : string ) {
112- return (
113- < ContentEditable
114- html = { ( contextValue . value && contextValue . value . toString ( ) ) || "" }
115- onChange = { handleOnChange }
116- onKeyDown = { handleKeyDown }
117- onBlur = { ( ) =>
118- setContextValue ( ( old ) => ( { value : old . value , update : true } ) )
119- }
120- className = { className }
121- />
122- ) ;
123- }
124-
12597 function getCellElement ( ) {
12698 switch ( dataType ) {
12799 /** Plain text option */
128100 case DataTypes . TEXT :
129101 return ( cellProperties . column as any ) . isMetadata ? (
130102 < span className = "data-input" > { contextValue . value . toString ( ) } </ span >
131103 ) : (
132- contentEditableContainer ( "data-input" )
104+ < ContentEditable
105+ html = { ( contextValue . value && contextValue . value . toString ( ) ) || "" }
106+ onChange = { handleOnChange }
107+ onKeyDown = { handleKeyDown }
108+ onBlur = { ( ) =>
109+ setContextValue ( ( old ) => ( { value : old . value , update : true } ) )
110+ }
111+ className = { "data-input" }
112+ innerRef = { containerCellRef }
113+ />
133114 ) ;
134115 /** Number option */
135116 case DataTypes . NUMBER :
136- return contentEditableContainer ( "data-input text-align-right" ) ;
117+ return (
118+ < ContentEditable
119+ html = { ( contextValue . value && contextValue . value . toString ( ) ) || "" }
120+ onChange = { handleOnChange }
121+ onKeyDown = { handleKeyDown }
122+ onBlur = { ( ) =>
123+ setContextValue ( ( old ) => ( { value : old . value , update : true } ) )
124+ }
125+ className = "data-input text-align-right"
126+ />
127+ ) ;
137128
138129 /** Markdown option */
139130 case DataTypes . MARKDOWN :
140- return obsidianMarkdownContainer ( getFilePath ( initialValue ) ) ;
131+ return (
132+ < span ref = { containerCellRef } className = { `${ c ( "md_cell" ) } ` } > </ span >
133+ ) ;
141134 /** Selector option */
142135 case DataTypes . SELECT :
143136 return (
0 commit comments