webwriter-app / webwriter

Authoring tool for interactive content
https://webwriter.app
Other
15 stars 1 forks source link

Edit-mode widgets API #11

Open salmenf opened 1 year ago

salmenf commented 1 year ago

Some widgets could provide advanced editing capabilities, such as a video widget allowing video editing or a H5P widget that can install H5P content types locally.

Specification by developers The mechanism to specify advanced editing capabilities is to create a second entry point file edit.ts, additional to the standard entry point index.ts. Using the "exports" field, the developer can map the edit.ts file to my-widget/edit such that it can be imported with import MyWidget from "my-widget/edit".

my-widget/package.json

{
  "main": "index.ts",
  "exports": {
    ".": "index.ts",
    "./edit": "edit.ts"
  }
}

The main entrypoint should contain the normal widget with no dependency on the editing entry point. my-widget/index.ts

// Imports omitted
@customElement("my-widget")
export class MyWidget extends LitElementWw {
...
}

The "edit" entrypoint can depend on the main entrypoint. my-widget/edit.ts

import MyWidget from "."
...

Editing by teachers The editor automatically imports the editing widget from the edit entrypoint.

Usage by students None