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

Commit 4140c68

Browse files
committed
Merge branch '17-fr-image-column-type'
2 parents 40606ba + ca2c543 commit 4140c68

File tree

14 files changed

+161
-174
lines changed

14 files changed

+161
-174
lines changed

devops/config-template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ base:
66
origin:
77
- /path/to/files/1/
88
- /path/to/files/n/
9-
target: /path/to/vault/.obsidian/plugins/obsidian-dbfolder/
9+
target: /path/to/vault/.obsidian/plugins/dbfolder/

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
"jest": "27.5.1",
4141
"jest-mock-extended": "2.0.6",
4242
"obsidian": "0.14.6",
43-
"obsidian-dataview": "0.5.20",
44-
"rollup": "2.72.0",
43+
"rollup": "2.73.0",
44+
"rollup-plugin-typescript2": "0.31.2",
4545
"ts-jest": "27.1.4",
4646
"tslib": "2.4.0",
4747
"typescript": "4.6.4",
@@ -54,6 +54,7 @@
5454
"immutability-helper": "3.1.1",
5555
"monkey-around": "2.3.0",
5656
"pkg.json": "2.0.8",
57+
"obsidian-dataview": "0.5.20",
5758
"react": "17.0.2",
5859
"react-beautiful-dnd": "13.1.0",
5960
"react-contenteditable": "3.3.6",

rollup.config.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
1-
import typescript from "@rollup/plugin-typescript";
21
import { nodeResolve } from "@rollup/plugin-node-resolve";
32
import commonjs from "@rollup/plugin-commonjs";
43
import json from "@rollup/plugin-json";
5-
4+
import typescript2 from "rollup-plugin-typescript2";
65
const isProd = (process.env.BUILD === 'production');
76

8-
export default (commandLineArgs) => ({
9-
input: 'src/main.ts',
7+
const BASE_CONFIG = {
8+
input: "src/main.ts",
9+
external: ["obsidian","obsidian-dataview/lib/data-model/value"],
10+
onwarn: (warning, warn) => {
11+
// Sorry rollup, but we're using eval...
12+
if (/Use of eval is strongly discouraged/.test(warning.message)) return;
13+
warn(warning);
14+
},
15+
};
16+
17+
const getRollupPlugins = (tsconfig, ...plugins) =>
18+
[
19+
typescript2(tsconfig),
20+
nodeResolve({ browser: true }),
21+
json(),
22+
commonjs(),
23+
].concat(plugins);
24+
25+
const PROD_PLUGIN_CONFIG = {
26+
...BASE_CONFIG,
1027
output: {
1128
dir: 'dist',
1229
sourcemap: 'inline',
1330
sourcemapExcludeSources: isProd,
14-
format: 'cjs',
15-
exports: 'default',
31+
format: "cjs",
32+
exports: "default",
33+
name: "Database Folder (Production)",
1634
},
17-
external: ['obsidian'],
18-
plugins: [
19-
typescript(),
20-
nodeResolve({browser: true}),
21-
commonjs(),
22-
json(),
23-
]
24-
});
35+
plugins: getRollupPlugins(),
36+
};
37+
let configs = [];
38+
configs.push(PROD_PLUGIN_CONFIG);
39+
40+
export default configs;

src/components/Cell.tsx

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,6 @@ import { c } from "helpers/StylesHelper";
1111
import CalendarPortal from "./portals/CalendarPortal";
1212
import { 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-
3014
export 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+
useEffect(() => {
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();
@@ -109,36 +108,39 @@ export default function DefaultCell(cellProperties: Cell) {
109108
onBlur={() =>
110109
setContextValue((old) => ({ value: old.value, update: true }))
111110
}
112-
className="data-input"
111+
className={"data-input"}
112+
//innerRef={containerCellRef}
113113
/>
114114
);
115+
115116
/** Number option */
116117
case DataTypes.NUMBER:
117118
return (
118119
<ContentEditable
119120
html={(contextValue.value && contextValue.value.toString()) || ""}
120121
onChange={handleOnChange}
122+
onKeyDown={handleKeyDown}
121123
onBlur={() =>
122124
setContextValue((old) => ({ value: old.value, update: true }))
123125
}
124126
className="data-input text-align-right"
125127
/>
126128
);
129+
127130
/** Markdown option */
128131
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-
});
132+
return (
133+
<span ref={containerCellRef} className={`${c("md_cell")}`}></span>
134+
);
135+
136+
/** Calendar with time option */
137+
case DataTypes.CALENDAR_TIME:
138+
return (
139+
<span className="data-input calendar-time">
140+
{contextValue.value.toString()}
141+
</span>
142+
);
140143

141-
return <span ref={containerRef} className={`${c("md_cell")}`}></span>;
142144
/** Selector option */
143145
case DataTypes.SELECT:
144146
return (
@@ -153,6 +155,7 @@ export default function DefaultCell(cellProperties: Cell) {
153155
/>
154156
</CellContext.Provider>
155157
);
158+
156159
/** Calendar option */
157160
case DataTypes.CALENDAR:
158161
return (
@@ -164,6 +167,7 @@ export default function DefaultCell(cellProperties: Cell) {
164167
/>
165168
</CellContext.Provider>
166169
);
170+
167171
/** Default option */
168172
default:
169173
LOGGER.warn(`Unknown data type: ${dataType}`);

src/components/Columns.tsx

Lines changed: 12 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -68,115 +68,27 @@ export async function obtainColumnsFromFolder(
6868
return sortColumnsByPosition(columns);
6969
}
7070

71-
function parseDatabaseToTableColumn(
72-
databaseColumn: DatabaseColumn,
73-
columnKey: string,
74-
index: number
75-
): TableColumn {
76-
const tableColumn: TableColumn = {
77-
...(databaseColumn as Partial<TableColumn>),
78-
id: columnKey,
79-
dataType: databaseColumn.input,
80-
position: databaseColumn.position ?? index,
81-
key: databaseColumn.key ?? columnKey,
82-
label: databaseColumn.label,
83-
accessor: databaseColumn.accessor ?? dbTrim(databaseColumn.label),
84-
csvCandidate: databaseColumn.csvCandidate ?? true,
85-
};
86-
return tableColumn;
87-
}
88-
89-
async function columnOptions(
71+
function columnOptions(
9072
columnKey: string,
9173
index: number,
9274
column: DatabaseColumn
93-
): Promise<TableColumn> {
75+
): TableColumn {
9476
LOGGER.debug(`=> columnOptions. column: ${JSON.stringify(column)}`);
9577
const options: RowSelectOption[] = [];
96-
const tableRow: TableColumn = parseDatabaseToTableColumn(
97-
column,
98-
columnKey,
99-
index
100-
);
101-
/**
102-
* return plain text
103-
* @returns {TableColumn}
104-
*/
105-
function isText(): TableColumn {
106-
LOGGER.debug(`<= columnOptions`, `return text column`);
107-
return {
108-
...tableRow,
109-
dataType: DataTypes.TEXT,
110-
options: options,
111-
};
112-
}
113-
114-
/**
115-
* return number
116-
* @returns {TableColumn}
117-
*/
118-
function isNumber(): TableColumn {
119-
LOGGER.debug(`<= columnOptions`, `return number column`);
120-
return {
121-
...tableRow,
122-
dataType: DataTypes.NUMBER,
123-
options: options,
124-
};
125-
}
126-
/**
127-
* return selector
128-
* @returns {TableColumn}
129-
*/
130-
function isSelect(): TableColumn {
131-
LOGGER.debug(`<= columnOptions`, `return select column`);
132-
return {
133-
...tableRow,
134-
dataType: DataTypes.SELECT,
135-
options: options,
136-
};
137-
}
138-
139-
/**
140-
* return markdown rendered text
141-
* @returns {TableColumn}
142-
*/
143-
function isMarkdown(): TableColumn {
144-
LOGGER.debug(`<= columnOptions`, `return markdown column`);
145-
return {
146-
...tableRow,
147-
dataType: DataTypes.MARKDOWN,
148-
options: options,
149-
};
150-
}
151-
152-
function isNewColumn(): TableColumn {
153-
LOGGER.debug(`<= columnOptions`, `return new column`);
154-
return {
155-
...tableRow,
156-
dataType: DataTypes.NEW_COLUMN,
157-
options: options,
158-
};
159-
}
16078

161-
function isCalendar(): TableColumn {
162-
LOGGER.debug(`<= columnOptions`, `return calendar column`);
79+
if (Object.values(DataTypes).includes(column.input)) {
80+
LOGGER.debug(`<= columnOptions`, `return ${column.input} column`);
16381
return {
164-
...tableRow,
165-
dataType: DataTypes.CALENDAR,
82+
...(column as Partial<TableColumn>),
83+
position: column.position ?? index,
84+
key: column.key ?? columnKey,
85+
accessor: column.accessor ?? dbTrim(column.label),
86+
csvCandidate: column.csvCandidate ?? true,
87+
id: columnKey,
88+
label: column.label,
89+
dataType: column.input,
16690
options: options,
16791
};
168-
}
169-
170-
// Record of options
171-
let inputs: Record<string, any> = {};
172-
inputs[DataTypes.TEXT] = isText;
173-
inputs[DataTypes.NUMBER] = isNumber;
174-
inputs[DataTypes.SELECT] = isSelect;
175-
inputs[DataTypes.MARKDOWN] = isMarkdown;
176-
inputs[DataTypes.NEW_COLUMN] = isNewColumn;
177-
inputs[DataTypes.CALENDAR] = isCalendar;
178-
if (inputs.hasOwnProperty(column.input)) {
179-
return await inputs[column.input]();
18092
} else {
18193
throw `Error: option ${column.input} not supported yet`;
18294
}

src/components/Header.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import PlusIcon from "components/img/Plus";
77
import HeaderMenu from "components/HeaderMenu";
88
import CalendarIcon from "components/img/CalendarIcon";
99
import MarkdownObsidian from "components/img/Markdown";
10+
import CalendarTimeIcon from "components/img/CalendarTime";
1011
import {
1112
ActionTypes,
1213
DataTypes,
@@ -78,6 +79,9 @@ export default function Header(headerProps: DatabaseHeaderProps) {
7879
case DataTypes.CALENDAR:
7980
propertyIcon = <CalendarIcon />;
8081
break;
82+
case DataTypes.CALENDAR_TIME:
83+
propertyIcon = <CalendarTimeIcon />;
84+
break;
8185
case DataTypes.MARKDOWN:
8286
// TODO : add a markdown icon
8387
propertyIcon = <MarkdownObsidian />;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from "react";
2+
3+
export default function CalendarTimeIcon() {
4+
return (
5+
<svg
6+
width="24"
7+
height="24"
8+
viewBox="0 0 24 24"
9+
strokeWidth="2"
10+
stroke="currentColor"
11+
fill="none"
12+
strokeLinecap="round"
13+
strokeLinejoin="round"
14+
>
15+
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
16+
<path d="M11.795 21h-6.795a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v4" />
17+
<circle cx="18" cy="18" r="4" />
18+
<path d="M15 3v4" />
19+
<path d="M7 3v4" />
20+
<path d="M3 11h16" />
21+
<path d="M18 16.496v1.504l1 1" />
22+
</svg>
23+
);
24+
}

0 commit comments

Comments
 (0)