obsidian#App TypeScript Examples

The following examples show how to use obsidian#App. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: suggest.ts    From Templater with GNU Affero General Public License v3.0 7 votes vote down vote up
constructor(app: App, inputEl: HTMLInputElement | HTMLTextAreaElement) {
        this.app = app;
        this.inputEl = inputEl;
        this.scope = new Scope();

        this.suggestEl = createDiv("suggestion-container");
        const suggestion = this.suggestEl.createDiv("suggestion");
        this.suggest = new Suggest(this, suggestion, this.scope);

        this.scope.register([], "Escape", this.close.bind(this));

        this.inputEl.addEventListener("input", this.onInputChanged.bind(this));
        this.inputEl.addEventListener("focus", this.onInputChanged.bind(this));
        this.inputEl.addEventListener("blur", this.close.bind(this));
        this.suggestEl.on(
            "mousedown",
            ".suggestion-container",
            (event: MouseEvent) => {
                event.preventDefault();
            }
        );
    }
Example #2
Source File: utils.ts    From nldates-obsidian with MIT License 7 votes vote down vote up
export function generateMarkdownLink(app: App, subpath: string, alias?: string) {
  const useMarkdownLinks = (app.vault as any).getConfig("useMarkdownLinks");
  const path = normalizePath(subpath);

  if (useMarkdownLinks) {
    if (alias) {
      return `[${alias}](${path.replace(/ /g, "%20")})`;
    } else {
      return `[${subpath}](${path})`;
    }
  } else {
    if (alias) {
      return `[[${path}|${alias}]]`;
    } else {
      return `[[${path}]]`;
    }
  }
}
Example #3
Source File: utility.ts    From quickadd with MIT License 7 votes vote down vote up
function getCoreTemplatesPath(app: App) {
    // @ts-ignore
    const internalTemplatePlugin = app.internalPlugins.plugins.templates;
    if (internalTemplatePlugin) {
        const templateFolderPath = internalTemplatePlugin.instance.options.folder;
        if (templateFolderPath)
            return templateFolderPath;
    }
}
Example #4
Source File: utils.ts    From obsidian-map-view with GNU General Public License v3.0 7 votes vote down vote up
export async function getEditor(
    app: App,
    leafToUse?: WorkspaceLeaf
): Promise<Editor> {
    let view =
        leafToUse && leafToUse.view instanceof MarkdownView
            ? leafToUse.view
            : app.workspace.getActiveViewOfType(MarkdownView);
    if (view) return view.editor;
    return null;
}
Example #5
Source File: WebsiteParser.ts    From obsidian-ReadItLater with MIT License 6 votes vote down vote up
private async parsableArticle(app: App, article: Article, url: string) {
        const title = article.title || 'No title';
        let content = await parseHtmlContent(article.content);

        if (this.settings.downloadImages && Platform.isDesktop) {
            content = await replaceImages(app, content, this.settings.assetsDir);
        }

        const processedContent = this.settings.parsableArticleNote
            .replace(/%articleTitle%/g, title)
            .replace(/%articleURL%/g, url)
            .replace(/%articleContent%/g, content);

        const fileNameTemplate = this.settings.parseableArticleNoteTitle.replace(/%title%/g, title);

        const fileName = `${fileNameTemplate}.md`;
        return new Note(fileName, processedContent);
    }
Example #6
Source File: main.ts    From luhman-obsidian-plugin with GNU General Public License v3.0 6 votes vote down vote up
constructor(app: App, completion: (title: string) => void) {
    super(app);
    this.completion = completion;

    let { contentEl } = this;
    contentEl.parentElement!.addClass("zettel-modal");
    this.titleEl.setText("New zettel title...");

    let container = contentEl.createEl("div", {
      cls: "zettel-modal-container",
    });
    this.textBox = contentEl.createEl("input", {
      type: "text",
      cls: "zettel-modal-textbox",
    });
    this.textBox.id = "zettel-modal-textbox";
    this.textBox.addEventListener("keydown", (event) => {
      if (event.key == "Enter") {
        event.preventDefault();
        this.goTapped();
      }
    });
    container.append(this.textBox);

    let button = contentEl.createEl("input", {
      type: "button",
      value: "GO",
      cls: "zettel-modal-button",
    });
    button.addEventListener("click", (e: Event) => this.goTapped());
    container.append(button);

    contentEl.append(container);
  }
Example #7
Source File: InternalFunctions.ts    From Templater with GNU Affero General Public License v3.0 6 votes vote down vote up
constructor(protected app: App, protected plugin: TemplaterPlugin) {
        this.modules_array.push(new InternalModuleDate(this.app, this.plugin));
        this.modules_array.push(new InternalModuleFile(this.app, this.plugin));
        this.modules_array.push(new InternalModuleWeb(this.app, this.plugin));
        this.modules_array.push(
            new InternalModuleFrontmatter(this.app, this.plugin)
        );
        this.modules_array.push(
            new InternalModuleSystem(this.app, this.plugin)
        );
        this.modules_array.push(
            new InternalModuleConfig(this.app, this.plugin)
        );
    }
Example #8
Source File: fnc-main.ts    From folder-note-core with MIT License 6 votes vote down vote up
constructor(app: App, manifest: PluginManifest) {
    super(app, manifest);
    log.setDefaultLevel("ERROR");
    const plugin = this;
    this.api = getApi(plugin);
    (window[API_NAME] = this.api) &&
      this.register(() => delete window[API_NAME]);
    this.trigger("folder-note:api-ready", this.api);

    // patch create new note location for outside-same
    this.register(
      around(app.fileManager, {
        // eslint-disable-next-line prefer-arrow/prefer-arrow-functions
        getNewFileParent(next) {
          // eslint-disable-next-line prefer-arrow/prefer-arrow-functions
          return function (sourcePath) {
            if (app.vault.getConfig("newFileLocation") === "current") {
              const pref = plugin.settings.folderNotePref;
              switch (pref) {
                case NoteLoc.Index:
                case NoteLoc.Inside:
                  break;
                case NoteLoc.Outside: {
                  const folder = plugin.resolver.getFolderFromNote(sourcePath);
                  if (folder) return folder;
                  break;
                }
                default:
                  assertNever(pref);
              }
            }
            return next.call(app.fileManager, sourcePath);
          };
        },
      }),
    );
  }
Example #9
Source File: date-suggest.ts    From nldates-obsidian with MIT License 6 votes vote down vote up
constructor(app: App, plugin: NaturalLanguageDates) {
    super(app);
    this.app = app;
    this.plugin = plugin;

    // @ts-ignore
    this.scope.register(["Shift"], "Enter", (evt: KeyboardEvent) => {
      // @ts-ignore
      this.suggestions.useSelectedItem(evt);
      return false;
    });

    if (this.plugin.settings.autosuggestToggleLink) {
      this.setInstructions([{ command: "Shift", purpose: "Keep text as alias" }]);
    }
  }
Example #10
Source File: inline-api.ts    From obsidian-dataview with MIT License 6 votes vote down vote up
constructor(
        index: FullIndex,
        component: Component,
        container: HTMLElement,
        app: App,
        settings: DataviewSettings,
        verNum: string,
        currentFilePath: string
    ) {
        this.index = index;
        this.component = component;
        this.container = container;
        this.app = app;
        this.currentFilePath = currentFilePath;
        this.settings = settings;

        this.api = new DataviewApi(this.app, this.index, this.settings, verNum);
        this.io = new DataviewInlineIOApi(this.api.io, this.currentFilePath);

        // Set up the evaluation context with variables from the current file.
        let fileMeta = this.index.pages.get(this.currentFilePath)?.serialize(this.index) ?? {};
        this.evaluationContext = new Context(defaultLinkHandler(this.index, this.currentFilePath), settings, {
            this: fileMeta,
        });

        this.func = Functions.bindAll(DEFAULT_FUNCTIONS, this.evaluationContext);
    }
Example #11
Source File: tools.ts    From obsidian-chartsview-plugin with MIT License 6 votes vote down vote up
export function getFolderOptions(app: App) {
    const options: Record<string, string> = {};

    Vault.recurseChildren(app.vault.getRoot(), (f) => {
        if (f instanceof TFolder) {
            options[f.path] = f.path;
        }
    });

    return options;
}
Example #12
Source File: MacrosManager.ts    From quickadd with MIT License 6 votes vote down vote up
constructor(public app: App, plugin: QuickAdd, private macros: IMacro[], private choices: IChoice[]) {
        super(app)
        this.plugin = plugin;

        this.waitForClose = new Promise<IMacro[]>(
            ((resolve, reject) => {
                this.rejectPromise = reject;
                this.resolvePromise = resolve;
            })
        );

        this.open();
        this.display();
    }
Example #13
Source File: modeHandler.ts    From obsidian-switcher-plus with GNU General Public License v3.0 6 votes vote down vote up
constructor(
    private app: App,
    private settings: SwitcherPlusSettings,
    public exKeymap: Keymap,
  ) {
    const handlersByMode = new Map<Omit<Mode, 'Standard'>, Handler<AnySuggestion>>();
    this.handlersByMode = handlersByMode;
    handlersByMode.set(Mode.SymbolList, new SymbolHandler(app, settings));
    handlersByMode.set(Mode.WorkspaceList, new WorkspaceHandler(app, settings));
    handlersByMode.set(Mode.HeadingsList, new HeadingsHandler(app, settings));
    handlersByMode.set(Mode.EditorList, new EditorHandler(app, settings));
    handlersByMode.set(Mode.StarredList, new StarredHandler(app, settings));
    handlersByMode.set(Mode.CommandList, new CommandHandler(app, settings));
    handlersByMode.set(Mode.RelatedItemsList, new RelatedItemsHandler(app, settings));

    this.debouncedGetSuggestions = debounce(this.getSuggestions.bind(this), 400, true);
    this.reset();
  }
Example #14
Source File: files.ts    From obsidian-checklist-plugin with MIT License 6 votes vote down vote up
navToFile = async (app: App, path: string, ev: MouseEvent, line?: number) => {
  path = ensureMdExtension(path)
  const file = getFileFromPath(app.vault, path)
  if (!file) return
  const leaf = isMetaPressed(ev) ? app.workspace.splitActiveLeaf() : app.workspace.getUnpinnedLeaf()
  await leaf.openFile(file)
  if (line) {
    app.workspace.getActiveViewOfType(MarkdownView)?.currentMode?.applyScroll(line)
  }
}
Example #15
Source File: geosearch.ts    From obsidian-map-view with GNU General Public License v3.0 6 votes vote down vote up
constructor(app: App, settings: PluginSettings) {
        this.settings = settings;
        this.urlConvertor = new UrlConvertor(app, settings);
        if (settings.searchProvider == 'osm')
            this.searchProvider = new geosearch.OpenStreetMapProvider();
        else if (settings.searchProvider == 'google') {
            this.searchProvider = new geosearch.GoogleProvider({
                params: { key: settings.geocodingApiKey },
            });
        }
    }
Example #16
Source File: confirm.ts    From obsidian-fantasy-calendar with MIT License 6 votes vote down vote up
export async function confirmWithModal(
    app: App,
    text: string,
    buttons: { cta: string; secondary: string } = {
        cta: "Yes",
        secondary: "No"
    }
): Promise<boolean> {
    return new Promise((resolve, reject) => {
        try {
            const modal = new ConfirmModal(app, text, buttons);
            modal.onClose = () => {
                resolve(modal.confirmed);
            };
            modal.open();
        } catch (e) {
            reject();
        }
    });
}
Example #17
Source File: replaceImages.ts    From obsidian-ReadItLater with MIT License 5 votes vote down vote up
export async function replaceImages(app: App, content: string, assetsDir: string) {
    return await replaceAsync(content, EXTERNAL_MEDIA_LINK_PATTERN, imageTagProcessor(app, assetsDir));
}
Example #18
Source File: main.ts    From luhman-obsidian-plugin with GNU General Public License v3.0 5 votes vote down vote up
constructor(app: App, plugin: NewZettel) {
    super(app, plugin);
    this.plugin = plugin;
  }
Example #19
Source File: settings.ts    From obsidian-pandoc with MIT License 5 votes vote down vote up
constructor(app: App, plugin: PandocPlugin) {
        super(app, plugin);
        this.plugin = plugin;
    }
Example #20
Source File: files-manager.ts    From Obsidian_to_Anki with GNU General Public License v3.0 5 votes vote down vote up
constructor(app: App, data:ParsedSettings, files: TFile[], file_hashes: Record<string, string>, added_media: string[]) {
        this.app = app
        this.data = data
        this.files = files
        this.ownFiles = []
        this.file_hashes = file_hashes
        this.added_media_set = new Set(added_media)
    }
Example #21
Source File: main.ts    From obsidian-custom-attachment-location with GNU General Public License v3.0 5 votes vote down vote up
constructor(app: App, plugin: CustomAttachmentLocation) {
        super(app, plugin);
        this.plugin = plugin;
    }
Example #22
Source File: Templater.ts    From Templater with GNU Affero General Public License v3.0 5 votes vote down vote up
constructor(private app: App, private plugin: TemplaterPlugin) {
        this.functions_generator = new FunctionsGenerator(
            this.app,
            this.plugin
        );
        this.parser = new Parser();
    }