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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@totonoo/vue-codemirror

v1.1.6

Published

codemirror vue组件

Readme

vue-codemirror

codemirror vue组件,支持TS,使用的是codemirror 6。支持明暗模式。

未经测试,不建议使用于生产环境。个人测试作品。

准备开始

安装

首先需要安装 npm

npm install @totonoo/vue-codemirror --save

基础使用

<template>
  <div class="codemirror-demo">
    <MarkdownEditor
      v-model="value"
      @blur="changeHandler"
      @focus="changeHandler"
      @selectionChange="consoleHandler"
      @themeChange="consoleHandler"
      @change="changeHandler" />
  </div>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue'

import '@totonoo/vue-codemirror/dist/style.css'
import { MarkdownEditor } from '@totonoo/vue-codemirror'

export default defineComponent({
  components: {
    MarkdownEditor
  },
  setup () {
    const value = ref(`## 标题
    文章以名为 Markdown 的轻量级标记语言编写,这种方式易于阅读且易于学习。
    `)
    const changeHandler = (val: string, editor: typeof MarkdownEditor) => {
      console.log(val === value.value)
    }
    const consoleHandler = (val: string, editor: typeof MarkdownEditor) => {
      console.log(val)
    }
    return {
      value,
      changeHandler,
      consoleHandler
    }
  },
})
</script>
<style lang="scss">
.codemirror-demo {
  border: 1px #dddddd solid;
  height: 600px;
}
</style>

MarkdownEditor 详细使用说明

Events

  • ready (editor: typeof MarkdownEditor) => {}
  • change (value: string, editor: typeof MarkdownEditor) => {}
  • focus (value: string, editor: typeof MarkdownEditor) => {}
  • blur (value: string, editor: typeof MarkdownEditor) => {}
  • selectionChange (value: Line, editor: typeof MarkdownEditor) => {}
  • toolbarItemAction (item: ToolbarItemType, type: string, editor: typeof MarkdownEditor) => {} 边栏点击或快捷键通知

快捷键

查看帮助文档,编辑器获得焦点,按 Alt + h 即可查看。

基础配置


const dialog = {
  fullScreen: false,
  fixed: false,
  zIndex: 3
}
const theme = {
  def: 'light', // light or dark
  observer: 'body',
  observerAttr: 'theme'
}

const editorConfig = {
  lineWrapping: true, // 较长文本是否自动换行
  lineNumbers: true, // 是否显示行号
  allowMultipleSelections: true // 是否允许多行选择
}

const uploadConfig = {
  uploadUrl: '/api/upload',
  headers: {
    token: 'test token'
  },
  uploadSuccess: (result: any): string => {
    return result.data.domain + result.data.filepath
  },
  uploadFail: (error: any): void => {
    console.log('console', error)
  }
}

// <MarkdownEditor v-model="value" :dialog="dialog" :theme="theme" :editor="editorConfig" :upload="uploadConfig" />

常见问题

本地查看效果

git clone https://github.com/myestorm/vue-codemirror.git
npm install
npm run dev

http://localhost:3000/

如何修改背景颜色?

在编辑器的任意一个父级节点注入即可。

.codemirror-demo {
  --editor-bg: #f5f5f5;
  --editor-bg-dark: #000000;
}

在边栏上我能做什么

<template>
  <div class="codemirror-demo">
    <MarkdownEditor
      v-model="value"
      @toolbarItemAction="toolbarItemAction"
      :beforeInitToolbars="beforeInitToolbars" />
  </div>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue'

import '@totonoo/vue-codemirror/dist/style.css'
import { MarkdownEditor } from '@totonoo/vue-codemirror'
import IconUpload from '../components/editor/theme/markdown/upload.svg?component'

export default defineComponent({
  components: {
    MarkdownEditor
  },
  setup () {
    const value = ref('')
    const TopCustom: MarkdownMDToolbarItemType = {
      type: 'top_custom',
      title: '自定义',
      icon: IconUpload,
      shortcutKey: 'Alt-x',
      action: () => {
        console.log('in')
      }
    }
    const beforeInitToolbars = (toolbars: MarkdownMDToolbarsType) => {
      toolbars.top.push(TopCustom)
      return toolbars
    }
    const toolbarItemAction = (item: MarkdownMDToolbarItemType, type: string, editor: typeof MarkdownEditor) => {
      console.log(item.type, type) // type: click[点击], keyboard[键盘]
      editor.setValue('test demo')
    }
    return {
      value,
      beforeInitToolbars,
      toolbarItemAction
    }

  },
})
</script>