Skip to content

v0.1.9

Choose a tag to compare

@danilowoz danilowoz released this 18 Aug 15:29
· 1047 commits to main since this release

Features

SandpackCodeViewer

It replaces the Prism syntax-highlight in favor to use the Codemirror itself in read-only mode, which will ensure that syntax-highlight will always match on both component, SandpackCodeEditor and SandpackCodeViewer.

Decorators

Now the SandpackCodeViewer supports decorations, which is useful to highlight entire lines or just parts of the code. This is an abstraction on top of Codemirror decorations and for while only works on read-only instances of the Codemirror:

API

<SandpackCodeViewer
  showLineNumbers
  decorators={[
    { className: "highlight", line: 1 },
    { className: "highlight", line: 9 },
    {
      className: "widget",
      elementAttributes: { "data-id": "1" },
      line: 12,
      startColumn: 26,
      endColumn: 38,
    },
    {
      className: "widget",
      elementAttributes: { "data-id": "2" },
      line: 13,
      startColumn: 8,
      endColumn: 17,
    },
  ]}
/>

Preview
Screenshot 2021-08-18 at 16 20 41

New methods: reset changes

From now the useSandpack provider more two methods to control the state of the code editor:

  • resetAllFiles: reset all files for all paths;
  • resetFile: reset the code for a given path;

Example:

const { sandpack } = useSandpack();

const revertCurrentFile = () => {
  sandpack.resetFile(sandpack.activePath) // receives a path as argument
}

const revertAllFiles = () => {
  sandpack.resetAllFiles()
}

Bundler version

codesandbox/codesandbox-client@e37e8f3