From 343ff573ae7ed4710b3f3290bf752dee84e7aaae Mon Sep 17 00:00:00 2001 From: Danielo Rodriguez Date: Wed, 13 Sep 2023 11:03:35 +0200 Subject: [PATCH] fix: remove deprecated usages of app --- src/FormModal.ts | 4 ++-- src/suggestArray.ts | 28 --------------------------- src/{ => suggesters}/suggest.ts | 0 src/suggesters/suggestArray.ts | 28 +++++++++++++++++++++++++++ src/{ => suggesters}/suggestFile.ts | 6 +++--- src/{ => suggesters}/suggestFolder.ts | 0 src/utils/files.ts | 10 +++++----- src/views/FormBuilder.svelte | 2 +- 8 files changed, 39 insertions(+), 39 deletions(-) delete mode 100644 src/suggestArray.ts rename src/{ => suggesters}/suggest.ts (100%) create mode 100644 src/suggesters/suggestArray.ts rename src/{ => suggesters}/suggestFile.ts (89%) rename src/{ => suggesters}/suggestFolder.ts (100%) diff --git a/src/FormModal.ts b/src/FormModal.ts index 216595f5..2d2aeef3 100644 --- a/src/FormModal.ts +++ b/src/FormModal.ts @@ -1,9 +1,9 @@ import { App, Modal, Setting } from "obsidian"; import FormResult, { type ModalFormData } from "./FormResult"; import { exhaustiveGuard } from "./safety"; -import { FileSuggest } from "./suggestFile"; import { get_tfiles_from_folder } from "./utils/files"; import type { FormDefinition } from "./core/formDefinition"; +import { FileSuggest } from "./suggesters/suggestFile"; export type SubmitFn = (formResult: FormResult) => void; @@ -124,7 +124,7 @@ export class FormModal extends Modal { case "notes": return fieldBase.addDropdown((element) => { - const files = get_tfiles_from_folder(fieldInput.folder); + const files = get_tfiles_from_folder(fieldInput.folder, this.app); const options = files.reduce( ( acc: Record, diff --git a/src/suggestArray.ts b/src/suggestArray.ts deleted file mode 100644 index 86f5a28d..00000000 --- a/src/suggestArray.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { App } from "obsidian"; -import { TextInputSuggest } from "./suggest"; - -export class ArraySuggest extends TextInputSuggest { - content: Set; - - constructor(app: App, input: HTMLInputElement, content: Set) { - super(app, input); - this.content = content; - } - - getSuggestions(inputStr: string): string[] { - const lowerCaseInputStr = inputStr.toLowerCase(); - return [...this.content].filter((content) => - content.contains(lowerCaseInputStr) - ); - } - - renderSuggestion(content: string, el: HTMLElement): void { - el.setText(content); - } - - selectSuggestion(content: string): void { - this.inputEl.value = content; - this.inputEl.trigger("input"); - this.close(); - } -} diff --git a/src/suggest.ts b/src/suggesters/suggest.ts similarity index 100% rename from src/suggest.ts rename to src/suggesters/suggest.ts diff --git a/src/suggesters/suggestArray.ts b/src/suggesters/suggestArray.ts new file mode 100644 index 00000000..b103dfa0 --- /dev/null +++ b/src/suggesters/suggestArray.ts @@ -0,0 +1,28 @@ +import { App } from "obsidian"; +import { TextInputSuggest } from "./suggest"; + +export class ArraySuggest extends TextInputSuggest { + content: Set; + + constructor(app: App, input: HTMLInputElement, content: Set) { + super(app, input); + this.content = content; + } + + getSuggestions(inputStr: string): string[] { + const lowerCaseInputStr = inputStr.toLowerCase(); + return [...this.content].filter((content) => + content.contains(lowerCaseInputStr) + ); + } + + renderSuggestion(content: string, el: HTMLElement): void { + el.setText(content); + } + + selectSuggestion(content: string): void { + this.inputEl.value = content; + this.inputEl.trigger("input"); + this.close(); + } +} diff --git a/src/suggestFile.ts b/src/suggesters/suggestFile.ts similarity index 89% rename from src/suggestFile.ts rename to src/suggesters/suggestFile.ts index bb935fcb..f5ae0193 100644 --- a/src/suggestFile.ts +++ b/src/suggesters/suggestFile.ts @@ -2,8 +2,8 @@ import { App, TAbstractFile, TFile } from "obsidian"; import { TextInputSuggest } from "./suggest"; -import { get_tfiles_from_folder } from "./utils/files"; -import { errorWrapperSync } from "./utils/Error"; +import { get_tfiles_from_folder } from "../utils/files"; +import { errorWrapperSync } from "../utils/Error"; // Instead of hardcoding the logic in separate and almost identical classes, // we move this little logic parts into an interface and we can use the samme @@ -25,7 +25,7 @@ export class FileSuggest extends TextInputSuggest { getSuggestions(input_str: string): TFile[] { const all_files = errorWrapperSync( - () => get_tfiles_from_folder(this.folder), + () => get_tfiles_from_folder(this.folder, this.app), "The folder does not exist" ); if (!all_files) { diff --git a/src/suggestFolder.ts b/src/suggesters/suggestFolder.ts similarity index 100% rename from src/suggestFolder.ts rename to src/suggesters/suggestFolder.ts diff --git a/src/utils/files.ts b/src/utils/files.ts index a1bda266..48cd5673 100644 --- a/src/utils/files.ts +++ b/src/utils/files.ts @@ -1,7 +1,7 @@ -import { TAbstractFile, TFile, TFolder, Vault, normalizePath } from "obsidian"; +import { App, TAbstractFile, TFile, TFolder, Vault, normalizePath } from "obsidian"; import { ModalFormError } from "./Error"; -export function resolve_tfolder(folder_str: string): TFolder { +export function resolve_tfolder(folder_str: string, app: App): TFolder { folder_str = normalizePath(folder_str); const folder = app.vault.getAbstractFileByPath(folder_str); @@ -15,7 +15,7 @@ export function resolve_tfolder(folder_str: string): TFolder { return folder; } -export function resolve_tfile(file_str: string): TFile { +export function resolve_tfile(file_str: string, app: App): TFile { file_str = normalizePath(file_str); const file = app.vault.getAbstractFileByPath(file_str); @@ -29,8 +29,8 @@ export function resolve_tfile(file_str: string): TFile { return file; } -export function get_tfiles_from_folder(folder_str: string): Array { - const folder = resolve_tfolder(folder_str); +export function get_tfiles_from_folder(folder_str: string, app: App): Array { + const folder = resolve_tfolder(folder_str, app); const files: Array = []; Vault.recurseChildren(folder, (file: TAbstractFile) => { diff --git a/src/views/FormBuilder.svelte b/src/views/FormBuilder.svelte index d4e048e1..19bdd672 100644 --- a/src/views/FormBuilder.svelte +++ b/src/views/FormBuilder.svelte @@ -7,7 +7,7 @@ isValidFormDefinition, isInputNoteFromFolder, } from "src/core/formDefinition"; - import { FolderSuggest } from "src/suggestFolder"; + import { FolderSuggest } from "src/suggesters/suggestFolder"; import { FieldTypeReadable } from "src/views/EditFormView"; import { setIcon, Setting, App } from "obsidian"; import FormRow from "./components/FormRow.svelte";