-
Notifications
You must be signed in to change notification settings - Fork 2
Add documentation and stories; update React API #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
72522a4
Use TypeDoc to generate docs, tweak README.md
microbit-grace 72ddb57
Add build-docs workflow
microbit-grace 421df26
Add TODO to LICENSE.md
microbit-grace 9c35ef2
Add usage documentation for VanillaJS and React
microbit-grace 9664fa3
Export createMakeCodeRenderBlocks (potentially breaking change)
microbit-grace 0016cea
Add links to React storybook sourcecode
microbit-grace 88a7cd0
Setup VanillaJS stories
microbit-grace f60a419
Add links to VanillaJS storybook sourcecode
microbit-grace 1005d13
Add controls to makeCodeFrameDriver stories
microbit-grace c347154
Remove stories GH pages deployment
microbit-grace 8d36ab7
Tweak stories
microbit-grace 896c994
Organise stories sidebar
microbit-grace 15d1ae3
Tweak license
microbit-grace 71b9bf4
Tweak vanilla embed MakeCode doc
microbit-grace 1e829c7
Refactor
microbit-grace a8cc1b9
Update React editor example
microbit-grace e70ca94
Switch to refs, share toolbar
microbit-matt-hillsdon 3e19e46
Fix links, simplify examples
microbit-matt-hillsdon a90d06b
Flatten options into props for render blocks React.
microbit-matt-hillsdon 3430b0e
Remove not needed props/changes
microbit-grace 009a675
Tweak removal of arg
microbit-grace File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| name: build-docs | ||
| on: | ||
| release: | ||
| types: [created] | ||
| push: | ||
| branches: | ||
| - '**' | ||
| tags: | ||
| - '**' | ||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Setup Pages | ||
| uses: actions/configure-pages@v5 | ||
| - run: npm ci | ||
| - name: Build docs | ||
| run: npm run docs | ||
| - name: Upload artifact | ||
| uses: actions/upload-pages-artifact@v3 | ||
| with: | ||
| path: ./docs/build | ||
|
|
||
| deploy: | ||
| if: ${{ startsWith(github.ref, 'refs/tags/') }} | ||
| permissions: | ||
| pages: write | ||
| id-token: write | ||
| environment: | ||
| name: github-pages | ||
| url: ${{ steps.deployment.outputs.page_url }} | ||
| runs-on: ubuntu-latest | ||
| needs: build | ||
| steps: | ||
| - name: Deploy to GitHub Pages | ||
| id: deployment | ||
| uses: actions/deploy-pages@v4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ node_modules | |
| dist | ||
| dist-ssr | ||
| *.local | ||
| docs/build | ||
|
|
||
| # Editor directories and files | ||
| .vscode/* | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /* Styling for hiding elements in the generated TypeDoc site. */ | ||
| a.typedoc-ignore { | ||
| display: none; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| --- | ||
| title: React Usage | ||
| --- | ||
|
|
||
| # React Usage | ||
|
|
||
| <a href="https://microbit-foundation.github.io/makecode-embed/" class="typedoc-ignore">This documentation is best viewed on the documentation site rather than GitHub or NPM package site.</a> | ||
|
|
||
| ## Blocks rendering | ||
|
|
||
| Use {@link react.MakeCodeRenderBlocksProvider | MakeCodeRenderBlocksProvider} and {@link react.MakeCodeBlocksRendering | MakeCodeBlocksRendering} React components to render MakeCode blocks for a MakeCode project. Example MakeCode projects used for the demo are defined in [fixtures.ts](../src/stories/fixtures.ts). | ||
|
|
||
| ```js | ||
| import { | ||
| MakeCodeRenderBlocksProvider, | ||
| MakeCodeBlocksRendering, | ||
| } from '@microbit/makecode-embed/react'; | ||
|
|
||
| <MakeCodeRenderBlocksProvider options={options}> | ||
| <MakeCodeBlocksRendering code={project} /> | ||
| </MakeCodeRenderBlocksProvider>; | ||
| ``` | ||
|
|
||
| For more examples, take a look at the [MakeCode blocks rendering demo source code](../src/stories/MakeCodeBlocksRendering.stories.tsx). | ||
|
|
||
| ## Embed MakeCode editor | ||
|
|
||
| Use {@link react.MakeCodeFrame | MakeCodeFrame} component to embed MakeCode. | ||
|
|
||
| ```js | ||
| import { MakeCodeFrame } from '@microbit/makecode-embed/react'; | ||
|
|
||
| <MakeCodeFrame | ||
| ref={ref} | ||
| controller={1} | ||
| controllerId={controllerId} | ||
| initialProjects={initialProjects} | ||
| onEditorContentLoaded={(e) => console.log('editorContentLoaded', e)} | ||
| onWorkspaceLoaded={(e) => console.log('workspaceLoaded', e)} | ||
| onWorkspaceSync={(e) => console.log('workspaceSync', e)} | ||
| onWorkspaceReset={(e) => console.log('workspaceReset', e)} | ||
| onWorkspaceEvent={(e) => console.log('workspaceEvent', e)} | ||
| onWorkspaceSave={(e) => { | ||
| savedProjects.current?.set(e.project!.header!.id, e.project); | ||
| console.log(savedProjects.current); | ||
| }} | ||
| onTutorialEvent={(e) => console.log('tutorialEvent', e)} | ||
| /> | ||
| ``` | ||
|
|
||
| For more examples, take a look at the [MakeCode frame demo source code](../src/stories/MakeCodeFrame.stories.tsx). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| --- | ||
| title: VanillaJS Usage | ||
| --- | ||
|
|
||
| # VanillaJS Usage | ||
|
|
||
| <a href="https://microbit-foundation.github.io/makecode-embed/" class="typedoc-ignore">This documentation is best viewed on the documentation site rather than GitHub or NPM package site.</a> | ||
|
|
||
| ## Blocks rendering | ||
|
|
||
| Use {@link vanilla.createMakeCodeRenderBlocks | createMakeCodeRenderBlocks} to create a MakeCode block renderer. Initialise the renderer before calling `renderBlocks` with a {@link vanilla.RenderBlocksRequest | RenderBlocksRequest}, which includes a MakeCode project ([see examples](../src/stories/fixtures.ts)). The function will return a {@link vanilla.RenderBlocksResponse | RenderBlocksResponse}. | ||
|
|
||
| ```js | ||
| import { createMakeCodeRenderBlocks } from "@microbit/makecode-embed/vanilla"; | ||
|
|
||
| const renderer = createMakeCodeRenderBlocks({}); | ||
| renderer.initialize(); | ||
| const result = await renderer.renderBlocks({ code: defaultMakeCodeProject }); | ||
|
|
||
| document.querySelector<HTMLDivElement>("#app")!.innerHTML = ` | ||
| <div> | ||
| ${result.svg} | ||
| </div> | ||
| `; | ||
| ``` | ||
|
|
||
| For more examples, take a look at the [MakeCode blocks rendering demo source code](../src/stories/createMakeCodeRenderBlocks.stories.tsx). | ||
|
|
||
| ## Embed MakeCode editor | ||
|
|
||
| Use {@link vanilla.MakeCodeFrameDriver | MakeCodeFrameDriver} class to create a driverRef for an iframe element. | ||
|
|
||
| ```js | ||
| import { | ||
| Project, | ||
| MakeCodeFrameDriver, | ||
| createMakeCodeURL, | ||
| } from "@microbit/makecode-embed/vanilla"; | ||
|
|
||
| // Set up an iframe element. | ||
| const iframe = document.createElement("iframe"); | ||
| iframe.allow = "usb; autoplay; camera; microphone;"; | ||
| iframe.src = createMakeCodeURL( | ||
| "https://makecode.microbit.org", | ||
| undefined, | ||
| undefined, | ||
| 1, | ||
| undefined | ||
| ); | ||
| iframe.width = "100%"; | ||
| iframe.height = "100%"; | ||
|
|
||
| document.querySelector<HTMLDivElement>("#app")!.appendChild(iframe); | ||
|
|
||
| // Create and initialise an instance of MakeCodeFrameDriver. | ||
| const driverRef = new MakeCodeFrameDriver( | ||
| { | ||
| initialProjects: async () => [makeCodeProject], | ||
| onEditorContentLoaded: (e) => console.log("editorContentLoaded", e), | ||
| onWorkspaceLoaded: (e) => console.log("workspaceLoaded", e), | ||
| onWorkspaceSync: (e) => console.log("workspaceSync", e), | ||
| onWorkspaceReset: (e) => console.log("workspaceReset", e), | ||
| onWorkspaceEvent: (e) => console.log("workspaceEvent", e), | ||
| onWorkspaceSave: (e) => { | ||
| console.log(e.project!.header!.id, e.project); | ||
| }, | ||
| onTutorialEvent: (e) => console.log("tutorialEvent", e), | ||
| }, | ||
| () => iframe | ||
| ); | ||
| driverRef.initialize(); | ||
| ``` | ||
|
|
||
| For more examples, take a look at the [MakeCode frame demo source code](../src/stories/makeCodeFrameDriver.stories.tsx). |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.