updating type definitons

This commit is contained in:
vitormalencar 2021-03-07 14:15:36 +01:00
parent c38b4ee76f
commit 2d5e3d2317
1 changed files with 61 additions and 113 deletions

174
src/clipboard.d.ts vendored
View File

@ -1,136 +1,84 @@
/// <reference lib="dom"/>
import { TinyEmitter } from 'tiny-emitter';
type Action = 'cut' | 'copy';
type Target = string | HTMLElement;
type Trigger = string | HTMLElement | HTMLCollection | NodeList;
type Response = 'success' | 'error';
type Options = {
emmiter?: TinyEmitter;
text?: string;
action?: Action;
target?: Element;
trigger?: Trigger;
container?: Element;
selectedText?: string;
};
/**
* Inner class which performs selection from either `text` or `target`
* properties and then executes copy or cut operations.
*/
export declare class ClipboardAction {
constructor(options: Options);
/**
* Defines base properties passed from constructor.
*/
// better define the type of options
resolveOptions(options: Options): void;
/**
* Decides which selection strategy is going to be applied based
* on the existence of `text` and `target` properties.
*/
initSelection(): void;
/**
* Creates a fake textarea element, sets its value from `text` property,
* and makes a selection on it.
*/
selectFake(): void;
/**
* Only removes the fake element after another click event, that way
* a user can hit `Ctrl+C` to copy because selection still exists.
*/
removeFake(): void;
/**
* Selects the content from element passed on `target` property.
*/
selectTarget(): void;
/**
* Executes the copy operation based on the current selection.
*/
copyText(): void;
/**
* Fires an event based on the copy operation result.
*/
handleResult(succeeded: boolean): void;
/**
* Moves focus away from `target` and back to the trigger, removes current selection.
*/
clearSelection(): void;
/**
* Sets the `action` to be performed which can be either 'copy' or 'cut'.
*/
/**
* Sets the `action` to be performed which can be either 'copy' or 'cut'.
*/
action: Action;
/**
* Sets the `target` property using an element
* that will be have its content copied.
*/
target: Target;
/**
* Sets the `target` property using an element
* that will be have its content copied.
*/
/**
* Destroy lifecycle.
*/
destroy(): void;
}
/**
* Base class which takes one or more elements, adds event listeners to them,
* and instantiates a new `ClipboardAction` on each click.
*/
export declare class ClipboardJS {
constructor(trigger: Trigger, options?: Options);
declare class ClipboardJS {
constructor(
selector: string | Element | NodeListOf<Element>,
options?: ClipboardJS.Options
);
/**
* Defines if attributes would be resolved using internal setter functions
* or custom functions that were passed in the constructor.
* Subscribes to events that indicate the result of a copy/cut operation.
* @param type Event type ('success' or 'error').
* @param handler Callback function.
*/
resolveOptions(options: Options): void;
on(type: Response, handler: (e: ClipboardJS.Event) => void): this;
on(type: string, handler: (...args: any[]) => void): this;
/**
* Adds a click event listener to the passed trigger.
*/
listenClick(trigger: Trigger): void;
/**
* Defines a new `ClipboardAction` on each click event.
*/
onClick(e: Event): void;
/**
* Default `action` lookup function.
*/
defaultAction(trigger: Trigger): string | undefined;
/**
* Default `target` lookup function.
*/
// check the return here
defaultTarget(trigger: Trigger): void;
/**
* Returns the support of the given action, or all actions if no action is
* given.
*/
static isSupported(action?: Action): boolean;
/**
* Default `text` lookup function.
*/
defaultText(trigger: Trigger): string | undefined;
/**
* Destroy lifecycle.
* Clears all event bindings.
*/
destroy(): void;
/**
* Checks if clipboard.js is supported
*/
static isSupported(): boolean;
}
/**
* Helper function to retrieve attribute value.
*/
export declare function getAttributeValue(
suffix: string,
element: Element
): string | undefined;
declare namespace ClipboardJS {
interface Options {
/**
* Overwrites default command ('cut' or 'copy').
* @param elem Current element
*/
action?(elem: Element): Action;
export default ClipboardJS;
/**
* Overwrites default target input element.
* @param elem Current element
* @returns <input> element to use.
*/
target?(elem: Element): Element;
/**
* Returns the explicit text to copy.
* @param elem Current element
* @returns Text to be copied.
*/
text?(elem: Element): string;
/**
* For use in Bootstrap Modals or with any
* other library that changes the focus
* you'll want to set the focused element
* as the container value.
*/
container?: Element;
}
interface Event {
action: string;
text: string;
trigger: Element;
clearSelection(): void;
}
}
export = ClipboardJS;
export as namespace ClipboardJS;