From 9ef65995567727f7c51e4f308564f889e08b1b32 Mon Sep 17 00:00:00 2001 From: vran Date: Wed, 10 Jan 2024 10:16:33 +0800 Subject: [PATCH] feat: use obsidian yaml function to instead of js-yaml library --- README.md | 3 +-- manifest.json | 2 +- package-lock.json | 24 ++++++++++-------------- package.json | 2 -- src/processor/codeBlockProcessor.ts | 5 ++--- src/view/form/GraphFormModal.tsx | 14 ++++++-------- 6 files changed, 20 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 139f794..914aab3 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,7 @@ ## What -Contribution Graph is a plugin for [obsidin.md](https://obsidian.md/) which could generate interactive contribution graphs like GitHub to track your notes, habits, activity, history, and so on. - +Contribution Graph is a plugin for [obsidian.md](https://obsidian.md/) which could generate interactive heatmap graphs like GitHub to track your notes, habits, activity, history, and so on. [![Buy me a coffee](https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png)](https://www.buymeacoffee.com/vran) diff --git a/manifest.json b/manifest.json index e2d7a42..114fe2a 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "name": "Contribution Graph", "version": "0.5.0", "minAppVersion": "1.3.0", - "description": "generate interactive gitxxx style contribution graph for obsidian, use it to track your goals, habits, or anything else you want to track.", + "description": "Generate a interactive headmap graph to visualize and track your productivity", "author": "vran", "authorUrl": "https://github.com/vran-dev", "isDesktopOnly": false, diff --git a/package-lock.json b/package-lock.json index 27eb3ca..bd80ab3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,8 +10,6 @@ "license": "MIT", "dependencies": { "@floating-ui/react": "^0.26.4", - "@types/js-yaml": "^4.0.9", - "js-yaml": "^4.1.0", "luxon": "^3.4.4", "react": "^18.2.0", "react-dom": "^18.2.0" @@ -635,11 +633,6 @@ "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", "dev": true }, - "node_modules/@types/js-yaml": { - "version": "4.0.9", - "resolved": "https://registry.npmmirror.com/@types/js-yaml/-/js-yaml-4.0.9.tgz", - "integrity": "sha512-k4MGaQl5TGo/iipqb2UDG2UwjXziSWkh0uysQelTlJpX1qGlpUZYm8PnO4DxG1qBomtJUdYJ6qR6xdIah10JLg==" - }, "node_modules/@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmmirror.com/@types/json-schema/-/json-schema-7.0.15.tgz", @@ -920,7 +913,9 @@ "node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmmirror.com/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true, + "peer": true }, "node_modules/array-union": { "version": "2.1.0", @@ -1662,6 +1657,8 @@ "version": "4.1.0", "resolved": "https://registry.npmmirror.com/js-yaml/-/js-yaml-4.1.0.tgz", "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "dev": true, + "peer": true, "dependencies": { "argparse": "^2.0.1" }, @@ -2775,11 +2772,6 @@ "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", "dev": true }, - "@types/js-yaml": { - "version": "4.0.9", - "resolved": "https://registry.npmmirror.com/@types/js-yaml/-/js-yaml-4.0.9.tgz", - "integrity": "sha512-k4MGaQl5TGo/iipqb2UDG2UwjXziSWkh0uysQelTlJpX1qGlpUZYm8PnO4DxG1qBomtJUdYJ6qR6xdIah10JLg==" - }, "@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmmirror.com/@types/json-schema/-/json-schema-7.0.15.tgz", @@ -2989,7 +2981,9 @@ "argparse": { "version": "2.0.1", "resolved": "https://registry.npmmirror.com/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true, + "peer": true }, "array-union": { "version": "2.1.0", @@ -3594,6 +3588,8 @@ "version": "4.1.0", "resolved": "https://registry.npmmirror.com/js-yaml/-/js-yaml-4.1.0.tgz", "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "dev": true, + "peer": true, "requires": { "argparse": "^2.0.1" } diff --git a/package.json b/package.json index 4514662..b3022f1 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,6 @@ }, "dependencies": { "@floating-ui/react": "^0.26.4", - "@types/js-yaml": "^4.0.9", - "js-yaml": "^4.1.0", "luxon": "^3.4.4", "react": "^18.2.0", "react-dom": "^18.2.0" diff --git a/src/processor/codeBlockProcessor.ts b/src/processor/codeBlockProcessor.ts index 3ca03bb..28e5955 100644 --- a/src/processor/codeBlockProcessor.ts +++ b/src/processor/codeBlockProcessor.ts @@ -1,5 +1,4 @@ -import { App, MarkdownPostProcessorContext } from "obsidian"; -import { load } from "js-yaml"; +import { App, MarkdownPostProcessorContext, parseYaml } from "obsidian"; import { Renders } from "src/render/renders"; import { MISS_CONFIG } from "./bizErrors"; @@ -70,7 +69,7 @@ export class CodeBlockProcessor { try { // @ts-ignore - const yamlConfig: YamlGraphConfig = load(code); + const yamlConfig: YamlGraphConfig = parseYaml(code); return YamlConfigReconciler.reconcile(yamlConfig); } catch (e) { if (e.mark?.line) { diff --git a/src/view/form/GraphFormModal.tsx b/src/view/form/GraphFormModal.tsx index 3a5836d..a3c5463 100644 --- a/src/view/form/GraphFormModal.tsx +++ b/src/view/form/GraphFormModal.tsx @@ -1,9 +1,7 @@ -import { Modal, App, MarkdownView } from "obsidian"; +import { Modal, App, MarkdownView, parseYaml, stringifyYaml } from "obsidian"; import { StrictMode } from "react"; import { Root, createRoot } from "react-dom/client"; -import { dump, load } from "js-yaml"; import { CreateContributionGraphForm } from "./GraphForm"; -import { DataSource } from "src/query/types"; import { YamlGraphConfig } from "src/processor/types"; import { YamlConfigReconciler } from "src/processor/yamlConfigReconciler"; @@ -50,7 +48,7 @@ export class ContributionGraphCreateModal extends Modal { // update existing Graph onSubmit = (yamlGraphConfig: YamlGraphConfig) => { this.close(); - this.onSave!(dump(yamlGraphConfig)); + this.onSave!(stringifyYaml(yamlGraphConfig)); }; } else { // create new Graph @@ -63,9 +61,9 @@ export class ContributionGraphCreateModal extends Modal { const editor = markdownView.editor; this.close(); if (ignoreLanguagePrefix) { - editor.replaceSelection(dump(yamlGraphConfig)); + editor.replaceSelection(stringifyYaml(yamlGraphConfig)); } else { - const codeblock = `\`\`\`contributionGraph\n${dump( + const codeblock = `\`\`\`contributionGraph\n${stringifyYaml( yamlGraphConfig )}\n\`\`\`\n`; editor.replaceSelection(codeblock); @@ -99,7 +97,7 @@ export class ContributionGraphCreateModal extends Modal { this.originalConfigContent.trim() != "" ) { try { - return load(this.originalConfigContent) as YamlGraphConfig; + return parseYaml(this.originalConfigContent) as YamlGraphConfig; } catch (e) { return null; } @@ -118,7 +116,7 @@ export class ContributionGraphCreateModal extends Modal { const selection = editor.getSelection(); if (selection && selection.trim() != "") { try { - return load(selection) as YamlGraphConfig; + return parseYaml(selection) as YamlGraphConfig; } catch (e) { return null; }