Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

v-clipboard

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

v-clipboard - npm Package Compare versions

Comparing version 2.2.2 to 2.2.3

.prettierrc

2

dist/index.min.js

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["v-clipboard"]=t():e["v-clipboard"]=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="/dist/",t(t.s=0)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(e){var t=document.createElement("textarea"),n=void 0;if("string"!=typeof e)try{n=JSON.stringify(e)}catch(e){throw"Failed to copy value to clipboard. Unknown type."}else n=e;if(t.value=n,t.setAttribute("readonly",""),t.style.cssText="position:fixed;pointer-events:none;z-index:-9999;opacity:0;",document.body.appendChild(t),navigator.userAgent.match(/ipad|ipod|iphone/i)){var r=t.contentEditable,o=t.readOnly;t.contentEditable=!0,t.readOnly=!0;var a=document.createRange();a.selectNodeContents(t);var i=window.getSelection();i.removeAllRanges(),i.addRange(a),t.setSelectionRange(0,999999),t.contentEditable=r,t.readOnly=o}else t.select();var c=!1;try{c=document.execCommand("copy")}catch(e){console.warn(e)}return document.body.removeChild(t),c};t.default={install:function(e){e.prototype.$clipboard=r;var t=function(e){return function(){return"$"+e++}}(1),n={},o=function(e){e&&(n[e]=null,delete n[e])},a=function(e){var r=t();return n[r]=e,r};e.directive("clipboard",{bind:function(e,t){var o=t.arg,i=t.value;switch(o){case"error":var c=a(i);return void(e.dataset.clipboardErrorHandler=c);case"success":var d=a(i);return void(e.dataset.clipboardSuccessHandler=d);default:var l=function(o){if(t.hasOwnProperty("value")){var a={value:"function"==typeof i?i():i,event:o},c=r(a.value)?e.dataset.clipboardSuccessHandler:e.dataset.clipboardErrorHandler,d=n[c];d&&d(a)}},u=a(l);return e.dataset.clipboardClickHandler=u,void e.addEventListener("click",n[u])}},unbind:function(e){var t=e.dataset,r=t.clipboardSuccessHandler,a=t.clipboardErrorHandler,i=t.clipboardClickHandler;o(r),o(a),i&&(e.removeEventListener("click",n[i]),o(i))}})}}}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["v-clipboard"]=t():e["v-clipboard"]=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.i=function(e){return e},t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="/dist/",t(t.s=0)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(e){var t=void 0;if("string"!=typeof e)try{t=JSON.stringify(e)}catch(e){throw"Failed to copy value to clipboard. Unknown type."}else t=e;var r=document.createElement("textarea");if(r.value=t,r.setAttribute("readonly",""),r.style.cssText="position:fixed;pointer-events:none;z-index:-9999;opacity:0;",document.body.appendChild(r),navigator.userAgent.match(/ipad|ipod|iphone/i)){r.contentEditable=!0,r.readOnly=!0;var n=document.createRange();n.selectNodeContents(r);var o=window.getSelection();o.removeAllRanges(),o.addRange(n),r.setSelectionRange(0,999999)}else r.select();var a=!1;try{a=document.execCommand("copy")}catch(e){console.warn(e)}return document.body.removeChild(r),a};t.default={install:function(e){e.prototype.$clipboard=n;var t=function(e){return function(){return"$"+e++}}(1),r={},o=function(e){e&&(r[e]=null,delete r[e])},a=function(e){var n=t();return r[n]=e,n};e.directive("clipboard",{bind:function(e,t){var o=t.arg,i=t.value;switch(o){case"error":var c=a(i);return void(e.dataset.clipboardErrorHandler=c);case"success":var d=a(i);return void(e.dataset.clipboardSuccessHandler=d);default:var l=function(o){if(t.hasOwnProperty("value")){var a={value:"function"==typeof i?i():i,event:o},c=n(a.value)?e.dataset.clipboardSuccessHandler:e.dataset.clipboardErrorHandler,d=r[c];d&&d(a)}},u=a(l);return e.dataset.clipboardClickHandler=u,void e.addEventListener("click",r[u])}},unbind:function(e){var t=e.dataset,n=t.clipboardSuccessHandler,a=t.clipboardErrorHandler,i=t.clipboardClickHandler;o(n),o(a),i&&(e.removeEventListener("click",r[i]),o(i))}})}}}])});
//# sourceMappingURL=index.min.js.map
{
"name": "v-clipboard",
"description": "Vue.js Clipboard Plugin",
"version": "2.2.2",
"version": "2.2.3",
"author": "euvl <yev.vlasenko@gmail.com>",
"license": "MIT",
"private": false,

@@ -7,0 +8,0 @@ "types": "src/index.d.ts",

@@ -12,3 +12,3 @@ [![npm version](https://badge.fury.io/js/v-clipboard.svg)](https://badge.fury.io/js/v-clipboard)

```javascript
import Vue from 'vue'
import Vue from 'vue'
import Clipboard from 'v-clipboard'

@@ -24,2 +24,3 @@

Copying **static** value (directive should receive actual value):
```vue

@@ -32,2 +33,3 @@ <button v-clipboard="value">

Copying **dynamic** value (directive should recieve a function that returns value):
```vue

@@ -40,2 +42,3 @@ <button v-clipboard="() => value">

Copying **anything** in your methods:
```js

@@ -49,6 +52,6 @@ this.$clipboard(value)

<button v-clipboard="foo"
v-clipboard:success="clipboardSuccessHandler" // Success event handler
v-clipboard:success="clipboardSuccessHandler" // Success event handler
v-clipboard:error="clipboardErrorHandler"> // Error event handler
Copy to clipboard
</button>
</button>
```

@@ -55,0 +58,0 @@

/**
* Copyright (c) 2017 - 2018 - Yev Vlasenko
*/
const cssText = "position:fixed;pointer-events:none;z-index:-9999;opacity:0;";
const copyErrorMessage = "Failed to copy value to clipboard. Unknown type.";
const cssText = 'position:fixed;pointer-events:none;z-index:-9999;opacity:0;'
const copyErrorMessage = 'Failed to copy value to clipboard. Unknown type.'
const $clipboard = input => {
const textarea = document.createElement("textarea");
let value;
const $clipboard = (input) => {
let value
if (typeof input !== "string") {
if (typeof input !== 'string') {
try {
value = JSON.stringify(input);
value = JSON.stringify(input)
} catch (e) {
throw copyErrorMessage;
throw copyErrorMessage
}

@@ -21,106 +20,102 @@ } else {

textarea.value = value;
textarea.setAttribute("readonly", "");
textarea.style.cssText = cssText;
const textarea = document.createElement('textarea')
document.body.appendChild(textarea);
textarea.value = value
textarea.setAttribute('readonly', '')
textarea.style.cssText = cssText
document.body.appendChild(textarea)
if (navigator.userAgent.match(/ipad|ipod|iphone/i)) {
const editable = textarea.contentEditable;
const readOnly = textarea.readOnly;
textarea.contentEditable = true
textarea.readOnly = true
textarea.contentEditable = true;
textarea.readOnly = true;
const range = document.createRange()
const range = document.createRange();
range.selectNodeContents(textarea)
range.selectNodeContents(textarea);
const selection = window.getSelection()
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
textarea.setSelectionRange(0, 999999);
textarea.contentEditable = editable;
textarea.readOnly = readOnly;
selection.removeAllRanges()
selection.addRange(range)
textarea.setSelectionRange(0, 999999)
} else {
textarea.select();
textarea.select()
}
let success = false;
let success = false
try {
success = document.execCommand("copy");
success = document.execCommand('copy')
} catch (err) {
console.warn(err);
console.warn(err)
}
document.body.removeChild(textarea);
document.body.removeChild(textarea)
return success;
};
return success
}
export default {
install(Vue) {
Vue.prototype.$clipboard = $clipboard;
Vue.prototype.$clipboard = $clipboard
const generateId = (id => () => "$" + id++)(1);
const handlers = {};
const generateId = ((id) => () => '$' + id++)(1)
const handlers = {}
const removeHandler = id => {
const removeHandler = (id) => {
if (id) {
handlers[id] = null;
delete handlers[id];
handlers[id] = null
delete handlers[id]
}
};
}
const addHandler = func => {
const id = generateId();
handlers[id] = func;
const addHandler = (func) => {
const id = generateId()
handlers[id] = func
return id;
};
return id
}
Vue.directive("clipboard", {
Vue.directive('clipboard', {
bind(el, binding) {
const { arg, value } = binding;
const { arg, value } = binding
switch (arg) {
case "error":
const errorHandlerId = addHandler(value);
el.dataset.clipboardErrorHandler = errorHandlerId;
return;
case 'error':
const errorHandlerId = addHandler(value)
el.dataset.clipboardErrorHandler = errorHandlerId
return
case "success":
const successHandlerId = addHandler(value);
el.dataset.clipboardSuccessHandler = successHandlerId;
return;
case 'success':
const successHandlerId = addHandler(value)
el.dataset.clipboardSuccessHandler = successHandlerId
return
default:
const clickEventHandler = event => {
if (binding.hasOwnProperty("value")) {
const clickEventHandler = (event) => {
if (binding.hasOwnProperty('value')) {
const payload = {
value: typeof value === "function" ? value() : value,
value: typeof value === 'function' ? value() : value,
event
};
}
const handlerId = $clipboard(payload.value)
? el.dataset.clipboardSuccessHandler
: el.dataset.clipboardErrorHandler;
: el.dataset.clipboardErrorHandler
const handler = handlers[handlerId];
const handler = handlers[handlerId]
if (handler) {
handler(payload);
handler(payload)
}
}
};
}
const clickEventHandlerId = addHandler(clickEventHandler);
const clickEventHandlerId = addHandler(clickEventHandler)
el.dataset.clipboardClickHandler = clickEventHandlerId;
el.addEventListener("click", handlers[clickEventHandlerId]);
el.dataset.clipboardClickHandler = clickEventHandlerId
el.addEventListener('click', handlers[clickEventHandlerId])
return;
return
}

@@ -134,14 +129,14 @@ },

clipboardClickHandler
} = el.dataset;
} = el.dataset
removeHandler(clipboardSuccessHandler);
removeHandler(clipboardErrorHandler);
removeHandler(clipboardSuccessHandler)
removeHandler(clipboardErrorHandler)
if (clipboardClickHandler) {
el.removeEventListener("click", handlers[clipboardClickHandler]);
removeHandler(clipboardClickHandler);
el.removeEventListener('click', handlers[clipboardClickHandler])
removeHandler(clipboardClickHandler)
}
}
});
})
}
};
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc