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

Commit bb5880a

Browse files
authored
Merge pull request #40 from trey-wallis/dev
Bug fixes
2 parents 08e1663 + 5f3f287 commit bb5880a

File tree

13 files changed

+462
-203
lines changed

13 files changed

+462
-203
lines changed

README.md

+19-23
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,24 @@ Obsidian Notion-Like Tables allows you to create markdown tables using an interf
77
![Screenshot](.readme/preview.png)
88

99
## Roadmap
10-
- 0.1.0
11-
- MVP
12-
- 0.2.0
13-
- Make sort 1 button
14-
- Remove empty cells along side and bottom
15-
- Add ability to create new tag on "Enter" press
16-
- Add hover to header
17-
- 0.3.0
18-
- Multi-tagging
19-
- 0.4.0
20-
- Editable table width
21-
- 0.5.0
22-
- Draggable columns
23-
- Draggable rows
24-
- 0.6.0
25-
- Search bar?
26-
- TBA
27-
28-
### Known Bugs
29-
- Column header doesn't save currently
30-
- Tags are not unique per column
31-
- A text cell with numbers only is considered a number cell and will throw an error
32-
- Tags with spaces causes issues
10+
11+
- 0.1.0
12+
- MVP
13+
- 0.2.0
14+
- Make sort 1 button
15+
- Remove empty cells along side and bottom
16+
- Add ability to create new tag on "Enter" press
17+
- Add hover to header
18+
- 0.3.0
19+
- Multi-tagging
20+
- 0.4.0
21+
- Editable table width
22+
- 0.5.0
23+
- Draggable columns
24+
- Draggable rows
25+
- 0.6.0
26+
- Search bar?
27+
- TBA
3328

3429
## Usage
3530

@@ -118,6 +113,7 @@ Run development server
118113
- `npm run start`
119114

120115
## Reporting Bugs
116+
121117
If you find a bug, please open an issue. I will try to respond as soon as possible.
122118

123119
## Resources

main.ts

+42-19
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import { Plugin, Editor, MarkdownView, TFile } from "obsidian";
1+
import { Plugin, Editor } from "obsidian";
22

33
import { NLTTable } from "src/NLTTable";
44
import { NltSettings, DEFAULT_SETTINGS } from "src/app/services/state";
55
export default class NltPlugin extends Plugin {
66
settings: NltSettings;
7-
containerElements: HTMLElement[] = [];
87

8+
/**
9+
* Called on plugin load.
10+
* This can be when the plugin is enabled or Obsidian is first opened.
11+
*/
912
async onload() {
1013
await this.loadSettings();
1114
await this.forcePostProcessorReload();
@@ -14,12 +17,34 @@ export default class NltPlugin extends Plugin {
1417
const table = element.getElementsByTagName("table");
1518
if (table.length === 1) {
1619
context.addChild(
17-
new NLTTable(table[0], this.app, this, this.settings)
20+
new NLTTable(
21+
table[0],
22+
this.app,
23+
this,
24+
this.settings,
25+
context.sourcePath
26+
)
1827
);
1928
}
2029
});
21-
2230
this.registerCommands();
31+
this.registerFileHandlers();
32+
}
33+
34+
registerFileHandlers() {
35+
this.registerEvent(
36+
this.app.vault.on("rename", (file, oldPath) => {
37+
//If filepath exists for our settings, then we want to rename it
38+
//So that we can keep our app data matched to each file
39+
if (this.settings.appData[oldPath]) {
40+
const newPath = file.path;
41+
const data = { ...this.settings.appData[oldPath] };
42+
delete this.settings.appData[oldPath];
43+
this.settings.appData[newPath] = data;
44+
this.saveSettings();
45+
}
46+
})
47+
);
2348
}
2449

2550
registerCommands() {
@@ -32,6 +57,10 @@ export default class NltPlugin extends Plugin {
3257
});
3358
}
3459

60+
/**
61+
* Creates a 1 column NLT markdown table
62+
* @returns An NLT markdown table
63+
*/
3564
emptyTable(): string {
3665
const columnName = "Column 1";
3766
const rows = [];
@@ -55,34 +84,28 @@ export default class NltPlugin extends Plugin {
5584
await this.saveData(this.settings);
5685
}
5786

87+
/**
88+
* Called on plugin unload.
89+
* This can be when the plugin is disabled or Obsidian is closed.
90+
*/
5891
async onunload() {
5992
await this.forcePostProcessorReload();
6093
}
6194

95+
/**
96+
* Forces the post processor to be called again.
97+
* This is necessary for clean up purposes on unload and causing NLT tables
98+
* to be rendered onload.
99+
*/
62100
async forcePostProcessorReload() {
63101
const leaves = [
64102
...this.app.workspace.getLeavesOfType("markdown"),
65103
...this.app.workspace.getLeavesOfType("edit"),
66104
];
67105
for (let i = 0; i < leaves.length; i++) {
68106
const leaf = leaves[i];
69-
let view = null;
70-
if (leaf.view instanceof MarkdownView) view = leaf.view;
71107
this.app.workspace.duplicateLeaf(leaf);
72108
leaf.detach();
73-
74-
//TODO remove
75-
// //Find tables
76-
// //Match |---| or | --- |
77-
// //This is uniquely identity a new table
78-
// const hyphenRows = content.match(/\|\s{0,1}-{3,}\s{0,1}\|\n/g);
79-
// for (let i = 0; i < hyphenRows.length; i++) {
80-
// const old = hyphenRows[i];
81-
// const updated = old.replace("-", "--");
82-
// content = content.replace(old, updated);
83-
// }
84-
// await this.app.vault.modify(file, content);
85-
// }
86109
}
87110
}
88111
}

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "notion-like-tables",
33
"name": "Notion-Like Tables",
4-
"version": "0.1.3",
4+
"version": "0.1.4",
55
"minAppVersion": "0.12.0",
66
"description": "Create markdown tables using an interface similar to that found in Notion.so.",
77
"author": "Trey Wallis",

package-lock.json

+18-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-notion-like-tables",
3-
"version": "0.1.2",
3+
"version": "0.1.4",
44
"description": "Notion-like tables for Obsidian.md",
55
"main": "main.js",
66
"scripts": {
@@ -35,6 +35,7 @@
3535
},
3636
"dependencies": {
3737
"@mui/icons-material": "^5.5.0",
38+
"crc-32": "^1.2.2",
3839
"html-react-parser": "^1.4.9",
3940
"react": "^17.0.2",
4041
"react-dom": "^17.0.2",

src/NLTTable.tsx

+32-18
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ReactDOM from "react-dom";
55
import { AppContext } from "./app/services/hooks";
66
import App from "./app/App";
77
import ErrorDisplay from "./app/components/ErrorDisplay";
8-
import { loadData } from "./app/services/dataUtils";
8+
import { loadAppData } from "./app/services/dataUtils";
99
import { instanceOfErrorData, NltSettings } from "./app/services/state";
1010
import NltPlugin from "main";
1111

@@ -15,37 +15,51 @@ export class NLTTable extends MarkdownRenderChild {
1515
plugin: NltPlugin;
1616
settings: NltSettings;
1717
el: HTMLElement;
18+
sourcePath: string;
1819

1920
constructor(
2021
containerEl: HTMLElement,
2122
app: ObsidianApp,
2223
plugin: NltPlugin,
23-
settings: NltSettings
24+
settings: NltSettings,
25+
sourcePath: string
2426
) {
2527
super(containerEl);
2628
this.app = app;
2729
this.plugin = plugin;
2830
this.settings = settings;
31+
this.sourcePath = sourcePath;
2932
}
3033

3134
onload() {
32-
this.el = this.containerEl.createEl("div");
35+
const data = loadAppData(
36+
this.plugin,
37+
this.app,
38+
this.settings,
39+
this.containerEl,
40+
this.sourcePath
41+
);
3342

34-
const data = loadData(this.containerEl, this.settings);
35-
if (instanceOfErrorData(data)) {
36-
ReactDOM.render(<ErrorDisplay data={data} />, this.el);
37-
} else {
38-
ReactDOM.render(
39-
<AppContext.Provider value={this.app}>
40-
<App
41-
plugin={this.plugin}
42-
settings={this.settings}
43-
data={data}
44-
/>
45-
</AppContext.Provider>,
46-
this.el
47-
);
43+
//If data is not defined then that means that the table doesn't have a type
44+
//defintion row. Therefore, it's not a valid NLT table
45+
if (data) {
46+
this.el = this.containerEl.createEl("div");
47+
if (instanceOfErrorData(data)) {
48+
ReactDOM.render(<ErrorDisplay data={data} />, this.el);
49+
} else {
50+
ReactDOM.render(
51+
<AppContext.Provider value={this.app}>
52+
<App
53+
plugin={this.plugin}
54+
settings={this.settings}
55+
data={data}
56+
sourcePath={this.sourcePath}
57+
/>
58+
</AppContext.Provider>,
59+
this.el
60+
);
61+
}
62+
this.containerEl.replaceWith(this.el);
4863
}
49-
this.containerEl.replaceWith(this.el);
5064
}
5165
}

0 commit comments

Comments
 (0)