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

Commit b7d0ff8

Browse files
authored
Merge pull request #19 from trey-wallis/dev
Fix bugs for release
2 parents 458f668 + f38ded0 commit b7d0ff8

File tree

9 files changed

+118
-75
lines changed

9 files changed

+118
-75
lines changed

main.ts

+36-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
import { Plugin, Editor, MarkdownView } from "obsidian";
1+
import { Plugin, Editor, MarkdownView, TFile } 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[] = [];
78

89
async onload() {
910
await this.loadSettings();
11+
await this.forcePostProcessorReload();
1012

1113
this.registerMarkdownPostProcessor((element, context) => {
14+
console.log("REGISTERING!");
1215
const table = element.getElementsByTagName("table");
1316
if (table.length === 1) {
1417
context.addChild(
@@ -24,7 +27,7 @@ export default class NltPlugin extends Plugin {
2427
this.addCommand({
2528
id: "nlt-add-table",
2629
name: "Add table",
27-
editorCallback: (editor: Editor, view: MarkdownView) => {
30+
editorCallback: (editor: Editor) => {
2831
editor.replaceSelection(this.emptyTable());
2932
},
3033
});
@@ -52,4 +55,35 @@ export default class NltPlugin extends Plugin {
5255
async saveSettings() {
5356
await this.saveData(this.settings);
5457
}
58+
59+
async onunload() {
60+
await this.forcePostProcessorReload();
61+
}
62+
63+
async forcePostProcessorReload() {
64+
const leaves = [
65+
...this.app.workspace.getLeavesOfType("markdown"),
66+
...this.app.workspace.getLeavesOfType("edit"),
67+
];
68+
for (let i = 0; i < leaves.length; i++) {
69+
const leaf = leaves[i];
70+
let view = null;
71+
if (leaf.view instanceof MarkdownView) view = leaf.view;
72+
const file = this.app.vault.getAbstractFileByPath(view.file.path);
73+
if (file instanceof TFile) {
74+
let content = await this.app.vault.read(file);
75+
76+
//Find tables
77+
//Match |---| or | --- |
78+
//This is uniquely identity a new table
79+
const hyphenRows = content.match(/\|\s{0,1}-{3,}\s{0,1}\|\n/g);
80+
for (let i = 0; i < hyphenRows.length; i++) {
81+
const old = hyphenRows[i];
82+
const updated = old.replace("-", "--");
83+
content = content.replace(old, updated);
84+
}
85+
this.app.vault.modify(file, content);
86+
}
87+
}
88+
}
5589
}

package-lock.json

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

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"@types/lodash": "^4.14.180",
2121
"@types/node": "^16.11.26",
2222
"@types/react": "^17.0.40",
23-
"@types/react-dom": "^17.0.13",
23+
"@types/react-dom": "^17.0.14",
2424
"@types/uuid": "^8.3.4",
2525
"@typescript-eslint/eslint-plugin": "^5.2.0",
2626
"@typescript-eslint/parser": "^5.2.0",
@@ -31,7 +31,6 @@
3131
"renamer": "^4.0.0",
3232
"tslib": "2.3.1",
3333
"typescript": "4.4.4",
34-
"uninstall": "^0.0.0",
3534
"web-vitals": "^2.1.4"
3635
},
3736
"dependencies": {

src/NLTTable.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,4 @@ export class NLTTable extends MarkdownRenderChild {
4848
}
4949
this.containerEl.replaceWith(this.el);
5050
}
51-
52-
onunload(): void {}
5351
}

src/app/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ export default function App({ plugin, settings, data }: Props) {
435435
}
436436

437437
return (
438-
<div>
438+
<div className="NLT__overflow">
439439
<Table
440440
headers={appData.headers.map((header) => {
441441
return {

src/app/app.css

+8
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@
55
color: red;
66
}
77

8+
.NLT__overflow {
9+
overflow: auto;
10+
}
11+
812
/*
913
* Button
1014
*/
1115
.NLT__button {
1216
padding: 4px !important;
1317
}
1418

19+
.NLT__button--sm {
20+
width: 50px;
21+
}
22+
1523
.NLT__button--reset {
1624
padding: 0;
1725
border: 0;

src/app/components/ErrorDisplay/index.tsx

+13-7
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@ interface Props {
88

99
export default function ErrorDisplay({ data }: Props) {
1010
return (
11-
<ul>
12-
{data.columnIds.map((column, i) => (
13-
<li key={i} className="NLT__error">
14-
Invalid type definition in column {column}
15-
</li>
16-
))}
17-
</ul>
11+
<>
12+
{data.columnIds.length > 0 ? (
13+
<ul>
14+
{data.columnIds.map((column, i) => (
15+
<li key={i} className="NLT__error">
16+
Invalid type definition in column {column}
17+
</li>
18+
))}
19+
</ul>
20+
) : (
21+
<div className="NLT__error">Missing type definition row</div>
22+
)}
23+
</>
1824
);
1925
}

src/app/components/Table/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default function Table({ headers, rows, onAddColumn, onAddRow }: Props) {
4646
<div className="NLT__tr">
4747
<div className="NLT__td">
4848
<button
49-
className="NLT__button"
49+
className="NLT__button NLT__button--sm"
5050
onClick={() => onAddRow()}
5151
>
5252
New

0 commit comments

Comments
 (0)