polyipseity / obsidian-modules

Load JavaScript and related languages like TypeScript modules from the vault and the Internet.
GNU Affero General Public License v3.0
68 stars 4 forks source link

Question: Can we create user dialogs with this? #6

Closed stecydube closed 1 year ago

stecydube commented 1 year ago

Sorry to raise an issue as this repo does not have a discussion area.

Is it possible to create a class that extends Modal and being able to use it somewhere?

Thanks 😀

polyipseity commented 1 year ago

Turn on "Expose internal modules" in plugin settings and use the following code:

const { Modal } = await require.import("obsidian");
export class MyModal extends Modal {
  // custom modal code
}

Then you can use it:

const { MyModal } = await require.import("path/to/script.js");
new MyModal(app).open();

For future references, require("obsidian") will return an object containing everything in obsidian.d.ts. You just need to access them by name, like require("obsidian").Modal for Modal.

stecydube commented 1 year ago

Awesome. Thanks!