Git Product home page Git Product logo

vfg-field-sourcecode's Introduction

vfg-field-sourcecode

Rollup badge Jest Vue Storybook Commitizen semantic-release Npm badge Build Status

A source code field for vue-form-generator

Example

Preview

<template>
  <vue-form-generator :schema="schema" :model="model"></vue-form-generator>
</template>
<script>
export default {
  data() {
    return {
      model: {
        source: `<template></template>`
      },
      schema: {
        fields: [{
          type: "sourcecode",
          label: "source code",
          model: "source",
          theme: 'eclipse',
          mode: {
            name: "javascript",
            json: true
          }
        }]
      }
    };
  }
};
</script>

Installation

npm install vfg-field-sourcecode

vfg-field-sourcecode can be used as a module in both CommonJS and ES modular environments.

When in non-modular environment, vfg-field-sourcecode will register all the components to vue by itself.

ES6

//
// You can register a component manually
//
import { FieldSourcecode } from 'vfg-field-sourcecode';

export default {
  ...
  components: {
    'field-sourcecode': FieldSourcecode
  },
  ...
};

//
// or register the whole module with vue
//
import ModuleLibrary from 'vfg-field-sourcecode';

// Install this library
Vue.use(ModuleLibrary);

CommonJS

//
// You can register a component manually
//
var Vue = require('vue');
var ModuleLibrary = require('vfg-field-sourcecode');

var YourComponent = Vue.extend({
  ...
  components: {
    'field-sourcecode': ModuleLibrary.FieldSourcecode
  },
  ...
});

//
// or register the whole module with vue
//
var Vue = require('vue');
var ModuleLibrary = require('vfg-field-sourcecode');

// Install this library
Vue.use(ModuleLibrary);

Browser

<script src="path/to/vue/vue.min.js"></script>
<script src="path/to/vfg-field-sourcecode/dist/vfg-field-sourcecode.min.js"></script>
<!-- Components are registered globally -->

After that, you can use it with Vue Form Generator:

  schema: {
    fields: [
      {
        type: "sourcecode",
        label: "source code",
        model: "source",
        theme: 'monokai',
        mode: "ruby"
      }
    ]
  }

CodeMirror Options

Any supported CodeMirror option can be passed in the schema. Available options are shown here.

Special note about mode option

When setting the mode option in the schema, vfg-field-sourcecode will automatically load the JS for the specified mode. This currently only works if you set the mode by name, not by mime type. Mode can either by set as as string, eg: mode: python, or as an object, which is required if that mode supports options you want to set - eg: mode: { name: 'javascript', json: true }. See here for more details.

Changelog

See the GitHub release history.

Contributing

See CONTRIBUTING.md.

vfg-field-sourcecode's People

Contributors

dflock avatar gwenaelp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.