Consider adding API
danielo515 opened this issue · 7 comments
Hello! Very nice plugin you are developing.
I have been looking for easier ways to create new notes that are fool proof, easy to trigger and that are ideally mobile friendly. Your solution looks like one that can fit that all.
However, I think I'm missing a feature (or two 😅) to match my objectives. This can be achieved in variety of ways, so which one or which ones to pick may be nice to debate if you are willing to do it.
My current workflow uses templater or quickAdd. When I create a new note from a template I just get a succession of single value prompts that I have to fill one after another. There is no way to have a broader context, and in some cases (because a quickAdd limitation) you don't even have a label.
If your plugin had an API that presents the form in a modal and then returns the values, that will be perfect for my use. I can just call the form that I want (or even several) get the values back and then render the template based on those answers. It feels like a perfect workflow.
I'm not sure how it works currently, but it looks like I need to have a dedicated note for data input, but I'm not sure if it is capable of creating new notes.
An additional nice functionality you could add is having select/multi-select fields that are populated with dataview-js queries. Several plugins like metadata-menu or meta-bind allow this, and I think it will be a very interesting and flexible feature to have.
Thanks!
Thank you for your suggestion!
It is currently not capable of generating notes through any API, just a form tied to a note.
Can Templater call a command that exists in the system and use those values?
If so, Data Entry could send a register command for opening a form, passing in data,schema,uischema values and then return your data back in your desired format.
This would essentially allow you to choose your form.
function command( params: { data?: unknown, schema: JsonSchema, uischema: UISchema }):
Templater templates can access other plugins, just like regular functions, so I don't think the indirection of a command is necessary. If you want to see some examples that do this here are some names:
- dataview through its DV namespace
- metadata-menu has an API namespace
- obsidian-tasks allows you to invoke it's add task modal from any place you can execute javaacript and it returns the generated task
So, in the context of your plugin templater could call an asynchronous function that takes a reference to a form definition, shows it and returns the submitted data. Does that make sense?
I see what you mean, that sounds like a good solution too.
I've at a few repos and I can't find an example of how they expose and API like that.
I assume we assign the functions to a global like object.
Would you be able to find an example?
Yeah, sure.
Here you have the API file of dataview:
https://github.com/blacksmithgu/obsidian-dataview/blob/master/src/api/plugin-api.ts
And here you can see how it is attached to the main plugin instance, so people can access and use it:
https://github.com/blacksmithgu/obsidian-dataview/blob/master/src/main.ts#L25-L45
Okay thanks for that.
So setting the API to MyPlugin.api
means others can access it?
Assuming that's the case:
- For your use case, where would you like have this information loaded from, if at all?
a. schema
b. uischema
c. datasource
You know what? Don't bother. I ended building my own plugin in two days. I will be releasing it quite soon. It is very narrow in scope and very specifically designed to integrate with other plugins. Your plugin is much more ambitious and I don't want to shift your focus. If you still want to add the API, feel free
I'll be looking forward to it! Good luck.