-
Notifications
You must be signed in to change notification settings - Fork 307
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
feat(codeeditor): support to extensions #286
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
28537cb
feat(codeeditor): support extension
danilowoz f781051
docs(editor): extensions
danilowoz 82082ff
test(extension): integration test
danilowoz 55ce1db
test(extension): integration test
danilowoz bbdf3a3
docs: typo
danilowoz b087aff
test: refactor
danilowoz 827dccd
Update website/docs/docs/advanced-usage/components.md
danilowoz 1ef9163
Update components.md
danilowoz b4cfdf3
Update 8 files
danilowoz File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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 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 |
---|---|---|
|
@@ -153,6 +153,31 @@ If you played with the `Sandpack` preset, you should be familiar already with th | |
</SandpackLayout> | ||
</SandpackProvider> | ||
|
||
### Extensions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes! I was hoping you'd add docs too 🙌 |
||
|
||
Sandpack uses CodeMirror behind the hood to provide a nice editor. You can extend the editor with your own extensions, like [`@codemirror/autocomplete`](https://www.npmjs.com/package/@codemirror/autocomplete). | ||
danilowoz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```jsx | ||
<SandpackProvider template="react"> | ||
<SandpackThemeProvider> | ||
<SandpackCodeEditor | ||
extensions={[autocompletion()]} | ||
extensionsKeymap={[completionKeymap]} | ||
/> | ||
</SandpackThemeProvider> | ||
</SandpackProvider> | ||
|
||
<Sandpack | ||
options={{ | ||
codeEditor: { | ||
extensions: [autocompletion()], | ||
extensionsKeymap: [completionKeymap], | ||
}, | ||
}} | ||
template="react" | ||
/> | ||
``` | ||
|
||
## Code Viewer | ||
|
||
For situations when you strictly want to show some code and run it in the browser, you can use the `SandpackCodeViewer` component. It looks similar to the code editor, but it renders a read-only version of `codemirror`, so users will not be able to edit the code. | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓What's the
id
for? Should we add a comment explaining what it's for? I'm assuming it maps to theid
of theCodeEditor
so maybe that's obvious.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. This is a temp bug fix that I'll approach in another PR soon. It's related to a random id generated in every render, which leads to unmatch values in tests cases. Here's more detail #143