Merge pull request #731 from r3nanp/master

This commit is contained in:
Vitor Alencar 2021-02-23 10:27:38 +01:00 committed by GitHub
commit 16966aac8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 1030 additions and 32 deletions

12
.eslintignore Normal file
View File

@ -0,0 +1,12 @@
# Ignore artifacts:
dist
lib
npm-debug.log
bower_components
node_modules
yarn-error.log
yarn.lock
src/*.ts
/*.js

24
.eslintrc.json Normal file
View File

@ -0,0 +1,24 @@
{
"env": {
"browser": true,
"es2021": true,
"mocha": true
},
"extends": ["airbnb-base", "plugin:prettier/recommended"],
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"prefer-const": "off",
"camelcase": "off",
"no-underscore-dangle": "off",
"consistent-return": "off",
/* Remove the necessity to use this on classes */
"class-methods-use-this": "off",
/* Enable variables declarations from shadowing variables declared in the outer scope */
"no-shadow": "off"
}
}

View File

@ -11,7 +11,6 @@ on:
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
@ -28,4 +27,6 @@ jobs:
node-version: ${{ matrix.node-version }} node-version: ${{ matrix.node-version }}
- run: npm ci - run: npm ci
- run: npm run build --if-present - run: npm run build --if-present
- run: npm run lint
- run: npm test - run: npm test

962
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,11 @@
"license": "MIT", "license": "MIT",
"main": "dist/clipboard.js", "main": "dist/clipboard.js",
"types": "src/clipboard.d.ts", "types": "src/clipboard.d.ts",
"keywords": ["clipboard", "copy", "cut"], "keywords": [
"clipboard",
"copy",
"cut"
],
"dependencies": { "dependencies": {
"good-listener": "^1.2.2", "good-listener": "^1.2.2",
"select": "^1.1.2", "select": "^1.1.2",
@ -19,6 +23,11 @@
"babel-loader": "^8.2.2", "babel-loader": "^8.2.2",
"chai": "^4.2.0", "chai": "^4.2.0",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"eslint": "^7.20.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.3.1",
"husky": "^5.0.9", "husky": "^5.0.9",
"karma": "^6.0.0", "karma": "^6.0.0",
"karma-chai": "^0.1.0", "karma-chai": "^0.1.0",
@ -42,9 +51,13 @@
"build-min": "cross-env NODE_ENV=production webpack", "build-min": "cross-env NODE_ENV=production webpack",
"build-watch": "webpack --watch", "build-watch": "webpack --watch",
"test": "karma start --single-run", "test": "karma start --single-run",
"prepublish": "npm run build" "prepublish": "npm run build",
"lint": "eslint --ext .js src/"
}, },
"lint-staged": { "lint-staged": {
"*.{js,css,md}": "prettier --write" "*.{js,css,md}": [
"prettier --write",
"eslint --fix"
]
} }
} }

View File

@ -45,7 +45,7 @@ class ClipboardAction {
* and makes a selection on it. * and makes a selection on it.
*/ */
selectFake() { selectFake() {
const isRTL = document.documentElement.getAttribute('dir') == 'rtl'; const isRTL = document.documentElement.getAttribute('dir') === 'rtl';
this.removeFake(); this.removeFake();

View File

@ -1,6 +1,21 @@
import ClipboardAction from './clipboard-action';
import Emitter from 'tiny-emitter'; import Emitter from 'tiny-emitter';
import listen from 'good-listener'; import listen from 'good-listener';
import ClipboardAction from './clipboard-action';
/**
* Helper function to retrieve attribute value.
* @param {String} suffix
* @param {Element} element
*/
function getAttributeValue(suffix, element) {
const attribute = `data-clipboard-${suffix}`;
if (!element.hasAttribute(attribute)) {
return;
}
return element.getAttribute(attribute);
}
/** /**
* Base class which takes one or more elements, adds event listeners to them, * Base class which takes one or more elements, adds event listeners to them,
@ -62,7 +77,7 @@ class Clipboard extends Emitter {
target: this.target(trigger), target: this.target(trigger),
text: this.text(trigger), text: this.text(trigger),
container: this.container, container: this.container,
trigger: trigger, trigger,
emitter: this, emitter: this,
}); });
} }
@ -124,19 +139,4 @@ class Clipboard extends Emitter {
} }
} }
/**
* Helper function to retrieve attribute value.
* @param {String} suffix
* @param {Element} element
*/
function getAttributeValue(suffix, element) {
const attribute = `data-clipboard-${suffix}`;
if (!element.hasAttribute(attribute)) {
return;
}
return element.getAttribute(attribute);
}
export default Clipboard; export default Clipboard;

View File

@ -1,5 +1,5 @@
import ClipboardAction from '../src/clipboard-action';
import Emitter from 'tiny-emitter'; import Emitter from 'tiny-emitter';
import ClipboardAction from '../src/clipboard-action';
describe('ClipboardAction', () => { describe('ClipboardAction', () => {
before(() => { before(() => {
@ -55,7 +55,7 @@ describe('ClipboardAction', () => {
describe('#set action', () => { describe('#set action', () => {
it('should throw an error since "action" is invalid', (done) => { it('should throw an error since "action" is invalid', (done) => {
try { try {
new ClipboardAction({ let clip = new ClipboardAction({
text: 'foo', text: 'foo',
action: 'paste', action: 'paste',
}); });
@ -72,7 +72,7 @@ describe('ClipboardAction', () => {
describe('#set target', () => { describe('#set target', () => {
it('should throw an error since "target" do not match any element', (done) => { it('should throw an error since "target" do not match any element', (done) => {
try { try {
new ClipboardAction({ let clip = new ClipboardAction({
target: document.querySelector('#foo'), target: document.querySelector('#foo'),
}); });
} catch (e) { } catch (e) {