Add types. Fix tsd check env. Improve in-code doc comments

This commit is contained in:
Beto Muniz 2021-05-17 12:38:18 -03:00
parent ef32d876de
commit b43d93e69d
3 changed files with 24 additions and 6 deletions

17
src/clipboard.d.ts vendored
View File

@ -2,11 +2,7 @@
type Action = 'cut' | 'copy';
type Response = 'success' | 'error';
type Options = {
text?: string;
action?: Action;
target?: Element;
type CopyActionOptions = {
container?: Element;
};
@ -38,6 +34,17 @@ declare class ClipboardJS {
* Checks if clipboard.js is supported
*/
static isSupported(): boolean;
/**
* Fires a copy action
*/
static copy(target: string | Element, options: CopyActionOptions): string;
/**
* Fires a cut action
*/
static cut(target: string | Element): string;
}
declare namespace ClipboardJS {

View File

@ -111,10 +111,21 @@ class Clipboard extends Emitter {
}
}
/**
* Allow fire programmatically a copy action
* @param {Element} target
* @param {Object} options
* @returns Text copied.
*/
static copy(target, options = { container: document.body }) {
return ClipboardActionCopy(target, options);
}
/**
* Allow fire programmatically a cut action
* @param {Element} target
* @returns Text cutted.
*/
static cut(target) {
return ClipboardActionCut(target);
}

View File

@ -1,4 +1,4 @@
import { expectType } from 'tsd';
import Clipboard from './clipboard';
import * as Clipboard from './clipboard';
expectType<Clipboard>(new Clipboard('.btn'));