npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ts-live/react-previewer

v0.0.8

Published

typescript 编辑器,可以实时编译、预览 react 组件

Downloads

3

Readme

react-previewer

typescript 编辑器,可以实时编译、运行代码并生成预览效果。

Usage

安装:

npm i @ts-live/react-previewer

Demo

使用时需要先手动引入一下 monaco-editorworker,该 worker 位于 ts-editor 包下的 workers 目录,加载 worker 时如果碰到跨域问题,可参考monaco 文档

// ./index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Previewer Demo</title>
    <script>
        window.MonacoEnvironment = {
            // getWorkerUrl 返回的是 worker 的路径,monaco 会通过该路径去加载 worker,所以要确保路径正确。
            getWorkerUrl: function (moduleId, label) {
                if (label === "json") {
                    return "./worker/json.worker.js";
                }
                if (label === "css") {
                    return "./worker/css.worker.js";
                }
                if (label === "html") {
                    return "./worker/html.worker.js";
                }
                if (label === "typescript" || label === "javascript") {
                    return "./worker/ts.worker.js";
                }
                return "./worker/editor.worker.js";
            }
        };
    </script>
</head>

<body>
  <div id="root"></div>
</body>

</html>
import {
    PreviewerProvider,
    Previewer,
    PreviewerEditor,
    PreviewerError
} from '@ts-live/react-previewer';

<PreviewerProvider
    code={'<strong>Hello World!</strong>'}
>
    <Previewer />
    <PreviewerEditor
        autoHeight
        width="600px"
    />
    <PreviewerError />
</PreviewerProvider>

更多使用 demo 可参考 ./examples

API

<PreviewerProvider/>

|参数|说明|类型|默认值| |---|---|---|---| | className | 自定义class name | string | -- |

PreviewerProvider 的 props 还支持 @ts-live/ts-editor 包的 IEditorOptions 所有选项

<PreviewerEditor/>

|参数|说明|类型|默认值| |---|---|---|---| | width | 编辑器宽度 | string | -- | | height | 编辑器高度 | string | 0 | | autoHeight | 编辑器是否自适应内容高度 | boolean | false | | minHeight | autoHeight 为 true 时,编辑器最小高度 | number | 0 | | maxHeight | autoHeight 为 true 时,编辑器最大高度,为 0 时表示不限制高度 | number | 0 | | getEditor | 获取 editor 实例 | (editor: Editor) => void | -- | | className | 自定义class name | string | -- |

<Previewer/>

|参数|说明|类型|默认值| |---|---|---|---| | renderError | 当有错误时,自定义渲染 error | (error: Error | null) => JSX.Element | null | -- | | className | 自定义class name | string | -- |

<PreviewerError/>

|参数|说明|类型|默认值| |---|---|---|---| | className | 自定义class name | string | -- |