Skip to content

Commit

Permalink
doc: update widget docs
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
EdAyers authored and leodemoura committed Jul 25, 2022
1 parent 18a3d1a commit 839956c
Showing 1 changed file with 13 additions and 34 deletions.
47 changes: 13 additions & 34 deletions doc/widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ dependent on JavaScript. However the primary use case is the web-based infoview
You can write your own user-widgets using the `@[widgetSource]` attribute:

This comment has been minimized.

Copy link
@utensil

utensil Aug 3, 2022

Now @[widgetSource] is no longer an attribute, this line of description could be updated. @EdAyers

This comment has been minimized.

Copy link
@EdAyers

EdAyers Aug 3, 2022

Author Contributor

Thanks for spotting these. We've overhauled the tutorial #1407
waiting for leanprover-community/lean4-samples#3 to be merged


```lean
@[widgetSource]
def widget1 : String := `
import * as React from "react";
import Lean
open Lean Widget
@[widget]
def widget1 : UserWidgetDefinition := {
name := "my fancy widget"
javascript := "
import * as React from 'react';
export default function (props) {
return React.createElement("p", {}, "hello")
}`
return React.createElement('p', {}, 'hello')
}"
}
```

This JavaScript text must include `import * as React from "react"` in the imports and may not use JSX.
Expand All @@ -27,32 +33,5 @@ components such as `InteractiveMessage` to display `MessageData` interactively.

## Using Lake to build your widgets

For larger projects, you can use lake to create files that will be used as `widgetSource`.
Here is an example lakefile snippet that sets this up.
Your npm javascript project lives in a subfolder called `./widget` whose build process generates a single file `widget/dist/index.js`.

```lean
-- ./lakefile.lean
def jsTarget (pkgDir : FilePath) : FileTarget :=
let jsFile := pkgDir / "widget/dist/index.js"
let srcFiles := inputFileTarget <| pkgDir / "widget/src/index.tsx"
fileTargetWithDep jsFile srcFiles fun _srcFile => do
proc {
cmd := "npm"
args := #["install"]
cwd := some <| pkgDir / "widget"
}
proc {
cmd := "npm"
args := #["run", "build"]
cwd := some <| pkgDir / "widget"
}
package MyPackage (pkgDir) {
extraDepTarget := jsTarget pkgDir |>.withoutInfo
...
}
...
```
For larger projects, you can use Lake to create files that will be used as `widgetSource`.
To learn how to do this, please view the readme of the [WidgetsMinimal sample](https://github.com/leanprover/lean4-samples/tree/main/WidgetsMinimal) ([todo] merge sample).

This comment has been minimized.

Copy link
@utensil

utensil Aug 3, 2022

The sample link is broken, could it link to the minimal sample branch (which I could not find) or the Rubik sample for now? @EdAyers

This comment has been minimized.

Copy link
@EdAyers

EdAyers Aug 3, 2022

Author Contributor

yes we are still working on this, will update this doc once the sample is merged

0 comments on commit 839956c

Please sign in to comment.