Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 72451b0

Browse files
committed
minor refactor
1 parent db690c2 commit 72451b0

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed

src/components/Cell.tsx

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -95,50 +95,49 @@ export default function DefaultCell(cellProperties: Cell) {
9595
setDirtyCell(false);
9696
}
9797

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+
98125
function getCellElement() {
99126
switch (dataType) {
100127
/** Plain text option */
101128
case DataTypes.TEXT:
102129
return (cellProperties.column as any).isMetadata ? (
103130
<span className="data-input">{contextValue.value.toString()}</span>
104131
) : (
105-
<ContentEditable
106-
html={(contextValue.value && contextValue.value.toString()) || ""}
107-
onChange={handleOnChange}
108-
onKeyDown={handleKeyDown}
109-
onBlur={() =>
110-
setContextValue((old) => ({ value: old.value, update: true }))
111-
}
112-
className="data-input"
113-
/>
132+
contentEditableContainer("data-input")
114133
);
115134
/** Number option */
116135
case DataTypes.NUMBER:
117-
return (
118-
<ContentEditable
119-
html={(contextValue.value && contextValue.value.toString()) || ""}
120-
onChange={handleOnChange}
121-
onBlur={() =>
122-
setContextValue((old) => ({ value: old.value, update: true }))
123-
}
124-
className="data-input text-align-right"
125-
/>
126-
);
136+
return contentEditableContainer("data-input text-align-right");
137+
127138
/** Markdown option */
128139
case DataTypes.MARKDOWN:
129-
const containerRef = useRef<HTMLElement>();
130-
useLayoutEffect(() => {
131-
//TODO - this is a hack. find why is layout effect called twice
132-
containerRef.current.innerHTML = "";
133-
MarkdownRenderer.renderMarkdown(
134-
initialValue,
135-
containerRef.current,
136-
getFilePath(initialValue),
137-
null
138-
);
139-
});
140-
141-
return <span ref={containerRef} className={`${c("md_cell")}`}></span>;
140+
return obsidianMarkdownContainer(getFilePath(initialValue));
142141
/** Selector option */
143142
case DataTypes.SELECT:
144143
return (

styles.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@
446446

447447
.react-calendar__tile:enabled:hover,
448448
.react-calendar__tile:enabled:focus {
449-
background-color: #e6e6e6;
449+
background-color: var(--background-secondary-alt);
450450
}
451451

452452
.react-calendar__tile--now {
@@ -464,7 +464,7 @@
464464

465465
.react-calendar__tile--hasActive:enabled:hover,
466466
.react-calendar__tile--hasActive:enabled:focus {
467-
background: #a9d4ff;
467+
background: var(--background-secondary-alt);
468468
}
469469

470470
.react-calendar__tile--active {

0 commit comments

Comments
 (0)