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-live

v2.5.4

Published

A lightweight playground for live editing VueJs code in the browser

Downloads

9,254

Readme

vue-live

A lightweight playground for live editing VueJs code in the browser

Build Status NPM Version NPM Downloads semantic-release


Usage

Install the dependency

npm install --save vue-live

The simplest way to render components is as a VueJs template:

<template>
  <VueLive
    :code="`<date-picker />`"
    :components="{ DatePicker }"
    @error="(e) => handleError(e)"
  />
</template>

<script>
import { VueLive } from "vue-live";
// import the css separately for easier SSR
import "vue-live/lib/vue-live.esm.css";
import DatePicker from "vuejs-datepicker";

export default {
  components: { VueLive },
  data() {
    return {
      // make DatePicker available in template
      DatePicker,
    };
  },
};
</script>

Check out the demo for alternative syntaxes to write your showcases.

Install for Vue 2.X

The default version at @latest is for vue 3 and up.

To install the version for vue 2, use the following:

npm install --save vue-live@1

Events

@error

When the template compilation or the script evaluation fail, errors are returned in this box. Hooking on these errors will not prevent them from displaying on the preview panel but will allow you to provide more info to your users about how to fix what they see.

<template>
  <VueLive
    code="<h1>make this example {{ fail }}</h1>"
    @error="(e) => log('Error on first example', e)"
  />
</template>

@success

When the template compilation and the script evaluation succeed, the @success event is emitted. If you provided extra info to your user about previous errors, you can use this event to clear the error message.

<template>
  <VueLive :code="code" @success="error = undefined" />
</template>

Props

code

Type String

Specifies the initial code to be evaluated

<template>
  <VueLive code="<button>test</button>" />
</template>

layout

Type vue component

Layout to be used for displaying the

Example

<template>
  <VueLive :layout="layout" />
</template>
<script>
import layout from "./Layout.vue";

export default {
  data() {
    return { layout };
  },
};
</script>

layout.vue

<template>
  <div class="my-vuelive">
    <div class="my-vuelive-editor">
      <slot name="editor"></slot>
    </div>
    <div class="my-vuelive-preview">
      <slot name="preview"></slot>
    </div>
  </div>
</template>
<style>
.my-vuelive {
  border: 1px solid #ccc;
  border-radius: 10px;
}

.my-vuelive-editor {
  margin: 8px;
}

.my-vuelive-preview {
  margin: 8px;
}
</style>

components

Type Object:

  • key: registration name
  • value: VueJs component object

Register some components to be used in the vue-live instance.

Example

<template>
  <VueLive :components="registeredComponents" code="<DatePicker />" />
</template>
<script>
import DatePicker from "./DatePicker.vue";

export default {
  data() {
    return {
      registeredComponents: {
        DatePicker,
      },
    };
  },
};
</script>

directives

Type Object:

  • key: registration name
  • value: VueJs directive object

You can use this prop in the same fashion as components above.

requires

Type Object:

  • key: query in the require/import statement
  • value: value returned by an es5 reauire statement

To allow require statements on a code evaluated in the browser, we have to pre-package all dependencies. This allows bundlers to know in advance what external dependencies will be allowed in the code.

Example

<template>
  <VueLive :requires="preRequiredObjects" :code="code" />
</template>
<script>
import DatePicker from "./DatePicker.vue";

export default {
  data() {
    return {
      // lodash can be pre-packaged by the bundler
      // so it can be required at runtime
      preRequiredObjects: {
        lodash: require("lodash"),
      },
      code: `
import _ from 'lodash'

const val = _.each({1,2,3}, (i, v) => {
  return \`\${i} value \${v}\`
})

<li v-for="v in val">
  v : {{v}}
</li>
      `,
    };
  },
};
</script>

jsx

Type Boolean

JSX does not always play nice with vue templates. If you want to expose vue templates, leave this option off. If you plan on using render functions with JSX, you will have to turn this option on.

Example

<template>
  <vue-live :code="code" jsx />
</template>
<script>
export default {
  data() {
    return {
      code: `
const args = {
  type: "button",
  value: "update me"
};

export default {
  render() {
    return <input {...args} />;
  }
};      
      `,
    };
  },
};
</script>

delay

Type Number

Time between a change in the code and its effect in the preview.

Note If a change happens before the prview has changed, the timer is reset.

editorProps

Type Object

Props passed directly to vue-prism-editor as a spread

dataScope

Type Object

Data object that wil be merged with the output data of the preview.

Example

```vue
<template>
  <VueLive
    :components="registeredComponents"
    :data-scope="dataScope"
    code="<DatePicker :value='today' />{{ today }}"
  />
</template>
<script>
import DatePicker from "./DatePicker.vue";

export default {
  data() {
    return {
      registeredComponents: {
        DatePicker,
      },
      // Without this variable declaration,
      // today will not have a value when entering the
      // particularly useful when examples or only a template
      dataScope: {
        today: new Date(),
      },
    };
  },
};
</script>

checkVariableAvailability

Type Boolean

Makes sure that every variable in the template actually exists when the user starts editing.

Throws an error in te preview field when the variable dont exist.

squiggles

Type Boolean default: true

Shows a red indicator when the parser errors with the code given.

How to contribute

npm ci

Compiles and hot-reloads for development

npm run start

Compiles and minifies library for production using rollup

npm run build

Run unit and e2e tests

npm run test:unit
npm run test:e2e

Lints and fixes files

npm run lint