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-codemirror-component

v1.1.1

Published

A vue-codemirror component that natively supports the code split

Downloads

6

Readme

Why need code splitting?

codemirror itself is a very powerful package that does not bundle into a single file when it's released. This is also because many users are most likely to load only some of them, loading all at once is not elegant enough. so that we can combine the dynamic import feature of webpack2+ to achieve the goal of reducing the size effectively.

Quick Start

As above mentioned, to use this component, you need to use webpack2 and above version.

  1. Install webpack, css-loader and style-loader.
npm i install webpack -D
  1. Config in webpack.config.js:
module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [ 'style-loader', 'css-loader' ]
      }
    ]
  }
}

Then, show you the usage code:

If you want to register vue-codemirror as a global component, you can use:

import VueCodemirror from 'vue-codemirror-component'
Vue.use(VueCodemirror, options)

Or if you don't want to pollute the global scope, you can register it when you want to use it:

  import { createComponent } from 'vue-codemirror-component'
  export default {
    name: 'app',
    components: {
      'vue-codemirror': createComponent(options)
    }
  }  

API

Default export

default export is the install function for this component.

import VueCodemirror from 'vue-codemirror-component'
Vue.use(VueCodemirror, options)

options.loadTheme

  • Type: (theme: string): Promise<void>

  • Required: true

    Runs when the editor's theme changes, you can use the import() syntax, and also supports a third-party asynchronous load library.

    loadTheme(theme) {
      return import('codemirror/theme/' + theme + '.css')
    }

options.loadMode

  • Type: (mode: string): Promise<void>

  • Required: true

    Runs when the editor's mode changes, the usage is same to options.loadTheme.

    loadTheme(theme) {
      return import('codemirror/theme/' + theme + '.css')
    }

Example

A full usage example as follows:

<template>
  <div class="simple-editor">
    <div class="editor">
      <vue-codemirror v-model="code" :options="editorOpts"></vue-codemirror>
    </div>
    <div class="preview">
      <pre v-html="code"></pre>
    </div>
  </div>
</template>

<script>
  import { createComponent } from 'vue-codemirror-component'
  
  const vueCodemiiror = createComponent({
    loadTheme(theme) {
      return import('codemirror/theme/' + theme + '.css')
    },
    loadMode(mode) {
      return import('codemirror/mode/' + mode + '/' + mode + '.js')
    }
  })  


  export default {
    components: {
      vueCodemiiror
    },
    data () {
      return {
        code: '<h1>V-Codemirror</h1>',
        editorOpts: {
          mode: 'text/html'
        },
      }
    }
  }
</script>

API

props

Name|Required|Type|Description|Default ---|:---:|:---:|---|:---: v-model|N|String| Code string value, It will work on two-way data binding, so you needn't watch the code value's change |- value|N|String| Code string value, If you use value mode, you need to watch the value's change manually |- options|N|Object| Editor config, please move to codemirror-config to get detailed configuration list | {tabSize: 2, mode: 'text/javascript', theme: 'monokai'}

Property v-model and value are forced alternative.

event

Some useful event are listed:

Event Name| Description | Callback Value ---|---|--- change | Fires every time the content of the editor content is changed. | Current code string

The detailed event list and their docs can refer to codemirror-event