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

@vue-monaco/editor

v0.0.6

Published

Monaco Editor for Vue - use the monaco-editor in Vue2/3 without needing to use plugins

Downloads

571

Readme

@vue-monaco/editor

不需要给 webpack (or rollup, vite) 等打包工具配置插件,就可以在 Vue 2&3 中使用 monaco-editor gitHub license npm version

简体中文 | English

安装

npm i @vue-monaco/editor

Vue <= 2.6.14 需要安装 @vue/composition-api.

npm i @vue-monaco/editor @vue/composition-api

Usage

Editor

<script lang="ts" setup>
  import { ref, shallowRef } from 'vue'

  const MONACO_EDITOR_OPTIONS = {
    automaticLayout: true,
    formatOnType: true,
    formatOnPaste: true,
  }

  const code = ref('// some code...')
  const editorRef = shallowRef()
  const handleMount = editor => (editorRef.value = editor)

  // your action
  function formatCode() {
    editorRef.value?.getAction('editor.action.formatDocument').run()
  }
</script>

<template>
  <monaco-editor
    v-model:value="code"
    theme="vs-dark"
    :options="MONACO_EDITOR_OPTIONS"
    @mount="handleMount"
  />
</template>

Diff Editor

<script lang="ts" setup>
  import { ref, shallowRef } from 'vue'

  const OPTIONS = {
    automaticLayout: true,
    formatOnType: true,
    formatOnPaste: true,
    readOnly: true,
  }

  const diffEditorRef = shallowRef()
  const handleMount = diffEditor => (diffEditorRef.value = diffEditor)

  // get the original value
  function getOriginalValue() {
    return diffEditorRef.value.getOriginalEditor().getValue()
  }

  // get the modified value
  function getOriginalValue() {
    return diffEditorRef.value.getModifiedEditor().getValue()
  }
</script>

<template>
  <monaco-diff-editor
    theme="vs-dark"
    original="// the original code"
    modified="// the modified code"
    language="javascript"
    :options="OPTIONS"
    @mount="handleMount"
  />
</template>

Props & Events & slots

Editor

| Name | Type | Default | Description | remark | | --- | --- | --- | --- | --- | | value | string | | 当前编辑器的值,可以使用 v-model:value | v-model:value | | language | string | | 当前编辑器的语言 | monaco-editor 支持的语言查看此处 | | path | string | | 当前编辑器的路径 | | | defaultValue | string | | 当前编辑器的默认值 | | | defaultLanguage | string | | 当前编辑器的默认语言 | monaco-editor 支持的语言查看此处 | | defaultPath | string | | 当前编辑器的默认路径 | monaco.editor.createModel(..., ..., monaco.Uri.parse(defaultPath)) | | theme | vs | vs-dark | vs | 主题 | | | line | number | | 可以设置要跳到行数 | | | options | object | {} | IStandaloneEditorConstructionOptions | | | overrideServices | object | {} | IEditorOverrideServices | | | saveViewState | boolean | true | 编辑器 model 变更后,保存 model 的视图状态(滚动位置等) | 需要给每个 model 配置唯一 path | | width | number | string | 100% | 容器宽度 | | | height | number | string | 100% | 容器高度 | | | className | string | | 内层容器 class | | | onBeforeMount | (monaco: Monaco) => void | | 编辑器实例创建前执行 | | | onMount | (editor: monaco.editor.IStandaloneCodeEditor, monaco: Monaco) => void | | 编辑器实例创建后执行 | | | onChange | (value: string \| undefined, monaco.editor.IModelContentChangedEvent) => void) => void | | 编辑改变值后执行 | | | onValidate | (markers: monaco.editor.IMarker[]) => void | | 当语法发生错误时执行 | monaco-editor 支持语法校验的语言查看此处 | | #loading | slot | 'loading...' | 加载状态 | | | #failure | slot | 'load failed' | 加载失败状态 |

Diff Editor

| Name | Type | Default | Description | | --- | --- | --- | --- | | original | string | | 原始值 (左边编辑器) | | modified | string | | 修改值 (右边编辑器) | | language | string | | 左右两个编辑器的语言 (monaco-editor 支持的所有语言, 点击这里查看) | | originalLanguage | string | | 此属性可以让你单独指定原始值的语言(优先级高于 language) | | modifiedLanguage | string | | 此属性可以让你单独指定修改值的语言(优先级高于 language) | | originalModelPath | string | | 原始值 model 的路径。作为第三个参数传递给 .createModel 方法 -- monaco.editor.createModel(..., ..., monaco.Uri.parse(originalModelPath)) | | modifiedModelPath | string | | 修改值 model 的路径。作为第三个参数传递给 .createModel 方法 -- monaco.editor.createModel(..., ..., monaco.Uri.parse(modifiedModelPath)) | | theme | vs | vs-dark | string | vs (vs 主题就是 light 主题) | 主题 | | options | object | {} | IStandaloneDiffEditorConstructionOptions | | width | number | string | 100% | 容器宽度 | | height | number | string | 100% | 容器高度 | | className | string | | 内层容器 class | | onBeforeMount | (monaco: Monaco) => void | | 编辑器实例创建前执行 | | onMount | (editor: monaco.editor.IStandaloneDiffEditor, monaco: Monaco) => void | | 编辑器实例创建后执行 | | #loading | slot | 'loading...' | 加载状态 | | #failure | slot | 'load failed' | 加载失败状态 |

Vite

如果使用 vite,你需要这样做(具体可查看 #1791 (comment)):

import { loader } from '@vue-monaco/editor'

import * as monaco from 'monaco-editor'
import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker'
import jsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker'
import cssWorker from 'monaco-editor/esm/vs/language/css/css.worker?worker'
import htmlWorker from 'monaco-editor/esm/vs/language/html/html.worker?worker'
import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker'

self.MonacoEnvironment = {
  getWorker(_, label) {
    if (label === 'json')
      return new jsonWorker()

    if (label === 'css' || label === 'scss' || label === 'less')
      return new cssWorker()

    if (label === 'html' || label === 'handlebars' || label === 'razor')
      return new htmlWorker()

    if (label === 'typescript' || label === 'javascript')
      return new tsWorker()

    return new editorWorker()
  }
}

loader.config({ monaco })

Inspiration

源自于以下项目:

License

MIT