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

@cgxqd/monaco-editor

v0.0.12

Published

在线编辑器

Downloads

14

Readme

@cgxqd/monaco-editor

npm npm NPM

Monaco Editor 是为 VS Code 提供支持的代码编辑器。

环境支持

@cgxqd/monaco-editor 可以在支持 ES2015 和 ResizeObserver 的浏览器上运行。 如果您确实需要支持旧版本的浏览器,请自行添加 Babel 和相应的 Polyfill 。

由于 monaco-editor 停止对 IE 的支持 #1790,@cgxqd/monaco-editor 也不再支持 IE 浏览器。

安装

使用包管理器

# 选择一个你喜欢的包管理器

# NPM
$ npm install @cgxqd/monaco-editor --save

# Yarn
$ yarn add @cgxqd/monaco-editor

# pnpm
$ pnpm install @cgxqd/monaco-editor

浏览器直接引入

我们建议您使用 CDN 引入,直接通过浏览器的 HTML 标签导入 @cgxqd/monaco-editor,然后就可以使用全局变量 monaco 了。

根据不同的 CDN 提供商有不同的引入方式, 我们在这里以 unpkg 和 jsDelivr 举例。 你也可以使用其它的 CDN 供应商。

unpkg

<head>
	<!-- Import style -->
	<link
		rel="stylesheet"
		href="https://unpkg.com/@cgxqd/monaco-editor/dist/index.css"
	/>
	<!-- Import @cgxqd/monaco-editor -->
	<script src="https://unpkg.com/@cgxqd/monaco-editor"></script>
</head>

jsDelivr

<head>
	<!-- Import style -->
	<link
		rel="stylesheet"
		href="https://cdn.jsdelivr.net/npm/@cgxqd/monaco-editor/dist/index.css"
	/>
	<!-- jsDelivr + Github 加速 -->
	<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/cgxqd/monaco-editor/dist/index.css" /> -->

	<!-- Import @cgxqd/monaco-editor -->
	<script src="https://cdn.jsdelivr.net/npm/@cgxqd/monaco-editor"></script>
	<!-- jsDelivr + Github 加速 -->
	<!-- <script src="https://cdn.jsdelivr.net/gh/cgxqd/monaco-editor/dist/index.global.js"></script> -->
</head>

api

monaco.initWorkerUrl(basePath, languages) 初始化 Worker

注意:initWorkerUrl 方法需要 await 异步等待后执行 editor.create api

declare const initWorkerUrl: (basePath?: string, languages?: languages) => Promise<void>;
  • basePath string:CDN 前缀地址
  • languages (ts|css|json|html)[]: 加载对应语言的 worker
    • editor language 为 typescript | javascript时, languages 需要包含 ts
    • editor language 为 css | scss | less时,languages 需要包含 css
    • editor language 为 json时,languages 需要包含 json
    • editor language 为 html | handlebars | razor时,languages 需要包含 html

项目中使用

CDN

// 引入样式
import "https://cdn.jsdelivr.net/npm/@cgxqd/monaco-editor/dist/index.css";

function loadScript(url, name) {
	// 需要自己实现
}

const basePath = "https://cdn.jsdelivr.net/npm/@cgxqd/monaco-editor";

const { editor, initWorkerUrl } = await loadScript(basePath, "monaco");

// 设置 monaco worker 地址
await initWorkerUrl(basePath, ["html"]);

// 创建编辑器
editor.create(document.querySelector("body"), {
	value: "",
	language: "html",
	theme: "vs-dark",
	automaticLayout: true,
});

ESM

import { editor, initWorkerUrl } from "@cgxqd/monaco-editor";
import "@cgxqd/monaco-editor/dist/index.css";

const basePath = "https://cdn.jsdelivr.net/npm/@cgxqd/monaco-editor";
// 设置 monaco worker 地址
await initWorkerUrl(basePath, ["ts"]);
// 创建编辑器
editor.create(document.querySelector("body"), {
	value: "",
	language: "javascript",
	theme: "vs-dark",
	automaticLayout: true,
});