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

vue3-contenteditable

v1.4.2

Published

A powerful Vue library for creating user editable html elements. Customize the appearance and behavior to fit your needs. Easily handle user input and validation.

Downloads

170

Readme

vue-contenteditable

This plugin provides a <contenteditable/> element supporting v-model. It also provides some (optional) features, like preventing html input and paste, or new lines.

It is inpired by the nice (but limited by design) https://github.com/asconwe/vue-contenteditable-directive .

Contrary to vue-contenteditable-directive, this plugin has full support of v-model reactivity.

npm package : https://www.npmjs.com/package/vue-contenteditable

github repository : https://github.com/hl037/vue-contenteditable

Should you use a content editable ?

The response is generally "no".

But... there are edge cases where neither <input/> nor <textarea> could suit, for example when you need a dynamic object size to adapt to the user input text's size.


Installation

NOTE : Versions 3.0.0+ are only compatible with VueJS v3+. For VueJS v2, please install the version 1.0.2.

With a build system

I recommand using pnpm + vite for any vue project. When using another package manager, you could encounter problems due to several Vue instances (errors like "Missing ref owner context"). Nevertheless, this package should work with any package manager.

    pnpm add vue-contenteditable

or

    yarn add vue-contenteditable

or

    npm install --save vue-contenteditable

(Re)build

The needed files are already provided in dist/, but if you want to re-build, simply run :

Install the dependencies :

pnpm i

Build and typescript declarations:

pnpm build

Directely in html

 <script src="contenteditable.umd.js"></script>

Global registration

This is optionnal, and I would not do it myself, but you can register the contenteditable component globally so that you don't need to import it:

In your main.js :

import contenteditable from 'vue-contenteditable'
Vue.use(contenteditable)

Usage

For advance usages, please refer to the samples provided in the git repository. There are examples writen in js and ts, one using vue-cli, two using vite.

SFC Composition style

<template>
  <contenteditable tag="div" :contenteditable="isEditable" v-model="message" :no-nl="true" :no-html="true" @returned="enterPressed" />
</template>
 
<script setup>
import { defineProps, ref, computed, onMounted, watch } from 'vue';
import contenteditable from 'vue-contenteditable'; // Not needed it registered globally

const isEditable = ref(true);
const message = ref("hello")

function enterPressed(){
  alert('Enter Pressed');
}
</script>

Option style

<template>
  <contenteditable tag="div" :contenteditable="isEditable" v-model="message" :no-nl="true" :no-html="true" @returned="enterPressed" />
</template>
 
<script>
import contenteditable from 'vue-contenteditable'; // Not needed it registered globally
export default {
  components : {
    contenteditable
  }, // Not needed it registered globally
  data() {
    return {
      isEditable: true,
      message: "hello"
    }
  },
  methods : {
    enterPressed(){
      alert('Enter Pressed');
    }
  }
}
</script>

Props

Prop name | Type | Default | Description ----------|------|---------|------------ tag | String | "div" | Html element type (p, div...) v-model | String | | v-model as usually used with <input/> and <textarea/> contenteditable | Boolean | true | Forwarded to DOM's contenteditable https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/contentEditable. no-html | Boolean | true | Prevent insertion (either typed or pasted) of html text no-nl | Boolean | false | Prevent insertion of new-lines. Also activate returned event emission

Events

returned When the user press and no-nl is set, then it emits the returned event with the current value (as a String) as argument.

All js events on the element can be transparantly listened to (the sample projects provide an example).

Changelogs

4.0.2

  • Add String as contenteditable type (To support non-standard values)

4.0.0

  • API breaking change : noNL and noHTML renamed to noNl and noHtml to enable using dashed prop names (no-nl and no-html in templates).
  • Build with vite instead of vue-cli : simpler build and less dev dependencies
  • Smaller package (previous version bundled vue... Oops.

3.0.0

  • Vue 3 support
  • Typescript support

License

This code is provided as-is, under the terms of the MIT license (see License file for more details).

A link to the original sources and contribution / pull request is welcome if you enjoy / use / contribute to this module ! :)