kjk / edna

Note taking for developers and power users
https://edna.arslexis.io
Other
391 stars 18 forks source link

Ability for JavaScript commands to ask for arguments #60

Open kjk opened 4 months ago

kjk commented 4 months ago

Consider a potential JavaScript command that downloads a content of a webpage as markdown and creates a block (or note?) with the result.

This command needs website url as an argument.

We don't have a way to provide such argument.

Could implement by allowing the command to ask for argument by calling:

const argSchema = [["url", "string", "url of a webpage to download as markdown"], ...];
const args = await getArgumentsFromUser(argSchema);
if (args === null) {
   // user cancelled the operation
   return;
}
const url = args.url;
// validate arguments
// do the work

getArgumentsFromUser() is a function implemented by Edna which shows a generic form for entering the values.

It's async because this shows a dialog to the user and we must wait until the user enters the values or cancels dialog.

User can cancel the operation, in which case we return null

There could also be a way to call that function with argument from a block, not sure about the syntax. Maybe something like:

call_function: Slurp Webpage As Markdown
url: https://edna.arslexis.io/help

and then such block could be run with Ctrl + E. Slurp Webpage As Markdown is a name of the function as defined by the author. Would have to deal with duplicate name functions.