From 32963d8f7a9676c822f49bbe29cfd0329af8801f Mon Sep 17 00:00:00 2001 From: Liam Cain Date: Wed, 28 Apr 2021 05:29:38 -0400 Subject: [PATCH] Handle trailing whitespace in `sectionHeading` (#13) * Handle trailing whitespace * Bump version --- manifest.json | 2 +- package.json | 7 +++---- src/index.ts | 13 ++++++------- src/modal.ts | 19 ------------------- src/settings.ts | 3 ++- src/textUtils.ts | 4 ++-- versions.json | 4 ++++ yarn.lock | 39 ++++++++++++++++++++------------------- 8 files changed, 38 insertions(+), 53 deletions(-) create mode 100644 versions.json diff --git a/manifest.json b/manifest.json index aee4054..b02a2a3 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "id": "things-logbook", "name": "Things Logbook", "description": "Sync your Things.app Logbook with Daily Notes", - "version": "0.1.10", + "version": "0.1.11", "author": "Liam Cain", "authorUrl": "https://github.com/liamcain/", "isDesktopOnly": true, diff --git a/package.json b/package.json index fb01d1f..1c4fc6c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-things-logbook-plugin", - "version": "0.1.10", + "version": "0.1.11", "description": "Sync Things.app Logbook with Obsidian", "author": "liamcain", "main": "main.js", @@ -14,9 +14,9 @@ }, "dependencies": { "obsidian": "obsidianmd/obsidian-api#master", - "obsidian-daily-notes-interface": "0.7.7", + "obsidian-daily-notes-interface": "0.9.2", "papaparse": "5.3.0", - "tslib": "2.1.0" + "tslib": "2.2.0" }, "devDependencies": { "@rollup/plugin-commonjs": "17.1.0", @@ -26,7 +26,6 @@ "@rollup/plugin-typescript": "8.2.0", "@types/jest": "26.0.20", "@types/moment": "2.13.0", - "@types/node": "14.14.34", "@types/papaparse": "5.2.5", "@typescript-eslint/eslint-plugin": "4.17.0", "@typescript-eslint/parser": "4.17.0", diff --git a/src/index.ts b/src/index.ts index e1b8455..48d3b52 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,12 +1,12 @@ import type moment from "moment"; -import { App, Notice, Plugin } from "obsidian"; +import { Notice, Plugin } from "obsidian"; import { createDailyNote, getDailyNote, getAllDailyNotes, } from "obsidian-daily-notes-interface"; -import { createConfirmationDialog } from "./modal"; +import { ConfirmationModal } from "./modal"; import { LogbookRenderer } from "./renderer"; import { DEFAULT_SETTINGS, @@ -24,7 +24,6 @@ import { groupBy, isMacOS, updateSection } from "./textUtils"; declare global { interface Window { - app: App; moment: typeof moment; } } @@ -73,7 +72,7 @@ export default class ThingsLogbookPlugin extends Plugin { if (this.options.hasAcceptedDisclaimer) { this.syncLogbook(); } else { - createConfirmationDialog({ + new ConfirmationModal(this.app, { cta: "Sync", onAccept: async () => { await this.writeOptions({ hasAcceptedDisclaimer: true }); @@ -82,7 +81,7 @@ export default class ThingsLogbookPlugin extends Plugin { text: "Enabling sync will backfill your entire Things Logbook into Obsidian. This means potentially creating or modifying hundreds of notes. Make sure to test the plugin in a test vault before continuing.", title: "Sync Now?", - }); + }).open(); } } @@ -90,7 +89,7 @@ export default class ThingsLogbookPlugin extends Plugin { if (this.options.hasAcceptedDisclaimer) { this.scheduleNextSync(); } else { - createConfirmationDialog({ + new ConfirmationModal(this.app, { cta: "Sync", onAccept: async () => { await this.writeOptions({ hasAcceptedDisclaimer: true }); @@ -104,7 +103,7 @@ export default class ThingsLogbookPlugin extends Plugin { text: "Enabling sync will backfill your entire Things Logbook into Obsidian. This means potentially creating or modifying hundreds of notes. Make sure to test the plugin in a test vault before continuing.", title: "Sync Now?", - }); + }).open(); } } diff --git a/src/modal.ts b/src/modal.ts index 16cdeff..440cfe4 100644 --- a/src/modal.ts +++ b/src/modal.ts @@ -44,22 +44,3 @@ export class ConfirmationModal extends Modal { } } } - -export function createConfirmationDialog({ - cta, - onAccept, - onCancel, - text, - title, -}: IConfirmationDialogParams): ConfirmationModal { - const modal = new ConfirmationModal(window.app, { - cta, - onAccept, - onCancel, - text, - title, - }); - modal.open(); - - return modal; -} diff --git a/src/settings.ts b/src/settings.ts index ac9a784..dda99d6 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -58,7 +58,8 @@ export class ThingsLogbookSettingsTab extends PluginSettingTab { ) .addText((textfield) => { textfield.setValue(this.plugin.options.sectionHeading); - textfield.onChange(async (sectionHeading) => { + textfield.onChange(async (rawSectionHeading) => { + const sectionHeading = rawSectionHeading.trim(); this.plugin.writeOptions({ sectionHeading }); }); }); diff --git a/src/textUtils.ts b/src/textUtils.ts index a584a8f..1161718 100644 --- a/src/textUtils.ts +++ b/src/textUtils.ts @@ -42,7 +42,7 @@ export async function updateSection( ): Promise { const headingLevel = getHeadingLevel(heading); - const { vault } = window.app; + const { vault } = app; const fileContents = await vault.read(file); const fileLines = fileContents.split("\n"); @@ -50,7 +50,7 @@ export async function updateSection( let nextSectionLineNum = -1; for (let i = 0; i < fileLines.length; i++) { - if (fileLines[i] === heading) { + if (fileLines[i].trim() === heading) { logbookSectionLineNum = i; } else if (logbookSectionLineNum !== -1) { const currLevel = getHeadingLevel(fileLines[i]); diff --git a/versions.json b/versions.json new file mode 100644 index 0000000..f385d41 --- /dev/null +++ b/versions.json @@ -0,0 +1,4 @@ +{ + "0.1.10": "0.10.8", + "0.1.11": "0.10.8" +} diff --git a/yarn.lock b/yarn.lock index 57e068b..f469533 100644 --- a/yarn.lock +++ b/yarn.lock @@ -605,17 +605,17 @@ dependencies: "@babel/types" "^7.3.0" -"@types/codemirror@0.0.98": - version "0.0.98" - resolved "https://registry.yarnpkg.com/@types/codemirror/-/codemirror-0.0.98.tgz#b35c7a4ab1fc1684b08a4e3eb65240020556ebfb" - integrity sha512-cbty5LPayy2vNSeuUdjNA9tggG+go5vAxmnLDRWpiZI5a+RDBi9dlozy4/jW/7P/gletbBWbQREEa7A81YxstA== +"@types/codemirror@0.0.108": + version "0.0.108" + resolved "https://registry.yarnpkg.com/@types/codemirror/-/codemirror-0.0.108.tgz#e640422b666bf49251b384c390cdeb2362585bde" + integrity sha512-3FGFcus0P7C2UOGCNUVENqObEb4SFk+S8Dnxq7K6aIsLVs/vDtlangl3PEO0ykaKXyK56swVF6Nho7VsA44uhw== dependencies: "@types/tern" "*" "@types/estree@*": - version "0.0.46" - resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.46.tgz#0fb6bfbbeabd7a30880504993369c4bf1deab1fe" - integrity sha512-laIjwTQaD+5DukBZaygQ79K1Z0jb1bPEMRrkXSLjtCcZm+abyp5YbrqpSLzD42FwWW6gK/aS4NYpJ804nG2brg== + version "0.0.47" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.47.tgz#d7a51db20f0650efec24cd04994f523d93172ed4" + integrity sha512-c5ciR06jK8u9BstrmJyO97m+klJrrhCf9u3rLu3DEAJBirxRqSCvDQoYKmxuYwQI5SZChAWu+tq9oVlGRuzPAg== "@types/estree@0.0.39": version "0.0.39" @@ -673,11 +673,6 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.21.tgz#d934aacc22424fe9622ebf6857370c052eae464e" integrity sha512-cHYfKsnwllYhjOzuC5q1VpguABBeecUp24yFluHpn/BQaVxB1CuQ1FSRZCzrPxrkIfWISXV2LbeoBthLWg0+0A== -"@types/node@14.14.34": - version "14.14.34" - resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.34.tgz#07935194fc049069a1c56c0c274265abeddf88da" - integrity sha512-dBPaxocOK6UVyvhbnpFIj2W+S+1cBTkHQbFQfeeJhoKFbzYcVUGHvddeWPSucKATb3F0+pgDq0i6ghEaZjsugA== - "@types/normalize-package-data@^2.4.0": version "2.4.0" resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e" @@ -3142,19 +3137,20 @@ object.pick@^1.3.0: dependencies: isobject "^3.0.1" -obsidian-daily-notes-interface@0.7.7: - version "0.7.7" - resolved "https://registry.yarnpkg.com/obsidian-daily-notes-interface/-/obsidian-daily-notes-interface-0.7.7.tgz#55057284d1258fc38143fd3adc16203839e3e8a7" - integrity sha512-RAK4Z47qCY6JEWUieseMKc8KOpBxPBSxyRweptxJlTWNrh7iF8ROy+yj/R+c54t7ol8YtkW/CZGf7lr4dtakNQ== +obsidian-daily-notes-interface@0.9.2: + version "0.9.2" + resolved "https://registry.yarnpkg.com/obsidian-daily-notes-interface/-/obsidian-daily-notes-interface-0.9.2.tgz#f551620fbb576c91522699f73c2cdb6b4457e938" + integrity sha512-prwSUpKcvtHjpHGpLm8TQVr5Z1k1ZkL4XdSt8A8JKX+QB+r8yoCxSjvgegKqtU+WVjEW5JYiijDr36FoseS+mQ== dependencies: obsidian obsidianmd/obsidian-api#master tslib "2.1.0" obsidian@obsidianmd/obsidian-api#master: - version "0.10.6" - resolved "https://codeload.github.com/obsidianmd/obsidian-api/tar.gz/a0e0c245561215ced9468859091e01d015f5cda9" + version "0.12.0" + resolved "https://codeload.github.com/obsidianmd/obsidian-api/tar.gz/eb459522e7e35983e3e6c2358301a21b26de7b64" dependencies: - "@types/codemirror" "0.0.98" + "@types/codemirror" "0.0.108" + moment "2.29.1" once@^1.3.0, once@^1.3.1, once@^1.4.0: version "1.4.0" @@ -3998,6 +3994,11 @@ tslib@2.1.0: resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a" integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A== +tslib@2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.2.0.tgz#fb2c475977e35e241311ede2693cee1ec6698f5c" + integrity sha512-gS9GVHRU+RGn5KQM2rllAlR3dU6m7AcpJKdtH8gFvQiC4Otgk98XnmMU+nZenHt/+VhnBPWwgrJsyrdcw6i23w== + tslib@^1.8.1: version "1.14.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"