windingwind / zotero-plugin-toolkit

Toolkit for Zotero Plugin Developers.
https://www.npmjs.com/package/zotero-plugin-toolkit
MIT License
115 stars 13 forks source link

Add: Prompt #3

Closed MuiseDestiny closed 1 year ago

MuiseDestiny commented 1 year ago

image

I add a Prompt class. Different addons can register some commands that they themselves defined in this Prompt. The UI interface deeply mimics Obsidian, but its short key is Shift + P instead of Ctrl + P (Obsidian's short key). Because pressing Ctrl when a item is selected will hightlight item's collections.

This Prompt will extend Zotero's interaction, it is a new arena. I define four application types, including Default, CreateView, SetValue, SelectValue.

Fig. 1 image

Fig. 2 image

Fig. 3 image

I registered different commands by calling Prompt.register() in both plugins and the tests worked fine. But there are still some problems when it is used by developers, for example, the Enumeration type TaskType cannot be read by developers.

In the end, allow me to introduce the parameters received by the regeister function, Command[].

interface Command {
  name: string;
  label?: string;
  when?: () => Boolean;
  task: DefaultTask | CreateViewTask | SetValueTask | SelectValueTask | Command[];
}

A Commad contains:

Finally, Happy New Year!

windingwind commented 1 year ago

Thanks!

More comments and descriptions for APIs would be nice. It would be perfect if users can understand the methods through information in code hints, without reading the source code. I noticed these parts do not have a description and thus leave empty in the compiled docs:

Thanks for this exciting work!

MuiseDestiny commented 1 year ago

I change the interface Command, so now developers can see the code hints of types. image

interface Command {
  name: string;
  label?: string;
  when?: () => Boolean;
  task: {
    Default?: Function;
    CreateView?: Function;
    SetValue?: {
      values: { intro: string, check: (text: string) => boolean }[],
      get?: () => boolean | string | number | undefined;
      set: (values) => void,
    };
    SelectValue?: {
      values: string[],
      set: (value: string) => void,
      get: () => boolean | string | number | undefined;
    };
    Commands?: Command[];
  }
}

But I admit it's not concise. @windingwind @volatile-static, Is there a better form of interface with code hinting? Looking forward to your answers, thank you.