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

vmo-monaco-editor

v0.1.1

Published

monaco editor vue3 component vscode

Downloads

31

Readme

vmo-monaco-editor

vmo-monaco-editor 是基于 vue3monaco-editor 的再次封装;可在实际项目开发中简便的引入 monaco-editor

安装

npm i monaco-editor // current:0.33.0
npm i vmo-monaco-editor --save // install vmo-monaco-editor

插件环境配置

vite 配置方式

npm i vite-plugin-monaco-editor  -D // install vite-plugin-monaco-editor

vite.config

import { defineConfig } from 'vite' // 5.0
import vue from '@vitejs/plugin-vue' // 3.3.4
import monacoEditorPlugin from 'vite-plugin-monaco-editor' //1.1.0

export default defineConfig({
  ...
  plugins: [
    vue(),
    // 如果 vite.config 为 ts 则可能需要使用注释,vite-plugin-monaco-editor 的模块入口与类型声明不一致 导致的问题修复
    //@ts-ignore
    monacoEditorPlugin.default({
      languageWorkers: ['editorWorkerService', 'css', 'html', 'json', 'typescript'],
      ....
    })
    ...
  ],
})

使用方式

创建 componet.vue 单文件,此单例使用了 tailwind.css

<script setup lang='ts'>
  import {ref} from 'vue';
  import { vmoMonacoEditor } from 'vmo-monaco-editor'; // 引入组件
  import 'vmo-monaco-editor/dist/style.css'; // 引入组件外观样式
  const codeContent = ref('SELECT * FROM table_name');
</script>

<template>
  <div class="flex flex-row grow-1 h-full">
    <div class="flex-col flex flex-grow w-0 bg-white border p-[10px]">
      <textarea v-model="codeContent" class="border h-[200px]" :rows="4" />
    </div>
    <vmo-monaco-editor
      :model-value="codeContent"
      prefix="function(name){"
      :option-config="{
        theme: 'vs-dark',
        language: 'sql'
      }"
      class="w-[800px]"
      @update:modeValue="codeContent = $event"
      @change="codeContent = $event">
    </vmo-monaco-editor>
  </div>
</template>

组件属性与事件

实例属性

props: {
  prefix: {
    // 前置内容
    type: String as PropType<string>,
    default: '(()=>{})'
  },
  modelValue: {
    // 代码内容
    type: String as PropType<string>,
    default: 'const aa:number = 12;'
  },
  suffix: {
    // 后置内容
    type: String as PropType<string>,
    default: '};'
  },
  needConfirm: {
    // 是否需要触发确认才能提交代码
    type: Boolean as PropType<boolean>,
    default: false
  },
  bidibind: {
    // 是否双向绑定,当 props.modelValue 在外部发生变化时,也会同步触发代码编辑内容变化
    type: Boolean as PropType<boolean>,
    default: true
  },
  zIndex: {
    // 全屏模式时,其z-index 的值
    type: Number as PropType<number>,
    default: 99
  },
  monacoOptions: {
    // monaco-editor 配置
    type: Object as PropType<
      Partial<Monaco.editor.IStandaloneEditorConstructionOptions & { theme: 'vs-dark' | 'vs-light' }>
    >,
    default: () => ({})
  }
},

实例事件

emits: ['update:modelValue', 'change', 'focuse', 'blur'],

// 前提:props.needConfirm:false
updata:modelValue:($event:string)=>any // v-model 的实现,返回当前编写的代码
// 前提:props.needConfirm:false
change:($event:string)=>any // 时失焦后触发代码内容提交,返回当前编写的代码,

focues // 获得焦点事件
blur // 失去焦点事件

实例插槽

<template #default></template>
<template #prefix></template>
<template #suffix></template>

实例方法

instance.insertCodeString(code:string) // 在当前光标位置插入代码 code
instance.fullscreenSwitch() // 全屏模式切换
instance.resetMonacoEditorOptions(options: Partial<Monaco.editor.IStandaloneEditorConstructionOptions>) // 将重制 MonacoEditor的配置 运行时更改
instance.refreshMonacoEditor() // 刷新
instance.changeLanguage(language:string) // 切换语言
instance.commit() // 外部主动触发提交内部编写的代码