vue-text-selection

a vue directive of text selection
889 11
Install
npm install vue-text-selection
Latest Version:0.0.4
License:MIT
Last Updated:Jun 22, 2020
Links: GitHub  ·  npm
Maintainer: s010s

vue-text-selection

Overview

It's a vue 2.X directive of text-selection. Base on Selection and Range API, It can get the innerText of the selected range.

example.gif

Installation

NPM
npm install vue-selectable  --save
Direct <script> Include
<script src="the-package-path/dist/v-selection.js"></script>

Usage

NPM
import selection from 'vue-text-selection';

// Register a global custom directive called v-selection
Vue.directive('selection', selection);

// Register the directive locally instead
new Vue({
  el: '#app',
  directives: { selection },
  methods:{
    getSelection: function(fixStr, allStr){
      // fixStr - the string that fix the boudary 
                  of the dom use the directive of the selection
      // allStr - the string of the selection
    }
  }
});
Direct <script> Include
new Vue({
  el: '#app',
  directives: { 
    selection: selection.default
  },
  methods:{
    getSelection: function(fixStr, allStr){
      // fixStr - the string that fix the boudary 
                  of the dom use the directive of the selection
      // allStr - the string of the selection
    }
  }
});
HTML
<div class="select-box" v-selection.fix="{getSelection:getSelection}">
  Text here!
</div>

Option

v-selection requires one mandatory parameter - directive parameter - object with one function, getSelection, to get the fixStr ( the string that fix the boudary of the dom use the directive of the selection ) and the allStr ( the string of the selection ).

v-selection has an optional modifiers, fix, to auto limit the selection in the boundary of the dom use the directive.

Examples

You can find the example in examples directory. Examples for v2 were tested against version 2.5.9.

Related Packages

@sparing-software/v-clamp

Vue directive plugin for text truncate

3,655 15
vue3-highlight-text

a vue3 directive of highlight text

84,789
vue-proportion-directive

vue 固定元素比例指令

6,003 10
ardirectives

Ardirectives

811
vue-on-click-outside

vue mixin/directive that does something when you click outside a container

169,297 31

Version History

Version Released License
0.0.4 MIT
0.0.3 MIT
0.0.2 MIT
0.0.1 MIT