Skip to content

Commit

Permalink
1.1.1 - Better error showing and no more Notice Spam
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeydarrenlau committed Aug 6, 2024
1 parent 24f66fd commit 9aa1add
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 11 deletions.
2 changes: 1 addition & 1 deletion esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const args = {
"@lezer/highlight",
...builtins],
format: "cjs",
target: "es2016",
target: "es2017",
logLevel: "info",
sourcemap: prod ? false : "inline",
treeShaking: true,
Expand Down
24 changes: 22 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { lintKeymap } from "@codemirror/lint";
import { EditorView, ViewUpdate } from "@codemirror/view";
import { debounce, App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting, PluginManifest } from 'obsidian';
import { tags as t } from "@lezer/highlight";
import { error } from "console";

const config = {
name: "obsidian",
Expand Down Expand Up @@ -222,6 +223,7 @@ export default class ObisidianKV extends Plugin {
online: any
offline: any
injectexterchnage: any
app: App

constructor(app: App, manifest: PluginManifest) {
super(app, manifest);
Expand Down Expand Up @@ -366,7 +368,7 @@ class ObisidianKVSettingTab extends PluginSettingTab {
dropCursor(),
EditorState.allowMultipleSelections.of(true),
indentOnInput(),
indentUnit.of(" "),
indentUnit.of(" "),
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
EditorView.lineWrapping,
bracketMatching(),
Expand All @@ -387,15 +389,27 @@ class ObisidianKVSettingTab extends PluginSettingTab {
createJSONEditor(snippetsSetting: Setting) {
const container = snippetsSetting.controlEl.createDiv("kv-store-json-editor");

const errorpane = container.createDiv("kv-store-json-editor-error");
errorpane.style.color = "green";
errorpane.style.fontWeight = "bold"
errorpane.style.paddingBottom = "10px";

let greenmessage = "No errors found!"

errorpane.setText(greenmessage);

const change = EditorView.updateListener.of(async (v: ViewUpdate) => {
if (v.docChanged) {
const value = v.state.doc.toString();
try {
this.plugin.settings.kvdata = JSON.parse(value);
await this.plugin.saveSettings();
window.kv = new SharedStuff(this.plugin.settings.kvdata, this.plugin);
errorpane.style.color = "green";
errorpane.setText(greenmessage);
} catch (error) {
new Notice('Invalid JSON: ' + error.message, 1000);
errorpane.style.color = "red";
errorpane.setText(error.message);
}
}
});
Expand All @@ -405,7 +419,13 @@ class ObisidianKVSettingTab extends PluginSettingTab {
extensions.push(change);

this.snippetsEditor = this.createJSONCMEditor(JSON.stringify(this.plugin.settings.kvdata, null, 2), extensions);
let blankbr = document.createElement("br");

container.appendChild(errorpane);
container.appendChild(blankbr);
container.appendChild(blankbr);
container.appendChild(this.snippetsEditor.dom);
container.appendChild(blankbr);

}

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "kv-store",
"name": "KV Store",
"version": "1.1.0",
"version": "1.1.1",
"minAppVersion": "0.15.0",
"description": "Adds a key-value store. Use it to store and retrieve key-value pairs in your vault.",
"author": "Darren-project",
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"@fingerprintjs/fingerprintjs": "^4.2.2",
"esbuild-plugin-inline-import": "^1.1.0",
"obsidian": "^1.4.11",
"tslib": "^2.6.2"
"tslib": "^2.6.3"
}
}
5 changes: 5 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@ If your plugin does not need CSS, delete this file.

.kv-store-json-editor-css .setting-item-control {
text-align: unset;
justify-content: unset;
}


.setting-item.kv-store-json-editor-css {
display: unset;
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"DOM",
"ES5",
"ES6",
"ES7"
"ES7",
"ES2017",
]
},
"include": [
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"1.0.4": "0.15.0",
"1.0.5": "0.15.0",
"1.0.6": "0.15.0",
"1.1.0": "0.15.0"
"1.1.0": "0.15.0",
"1.1.1": "0.15.0"
}

0 comments on commit 9aa1add

Please sign in to comment.