mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
updating type definitons
This commit is contained in:
parent
c38b4ee76f
commit
2d5e3d2317
172
src/clipboard.d.ts
vendored
172
src/clipboard.d.ts
vendored
@ -1,136 +1,84 @@
|
|||||||
/// <reference lib="dom"/>
|
/// <reference lib="dom"/>
|
||||||
|
|
||||||
import { TinyEmitter } from 'tiny-emitter';
|
|
||||||
|
|
||||||
type Action = 'cut' | 'copy';
|
type Action = 'cut' | 'copy';
|
||||||
|
type Response = 'success' | 'error';
|
||||||
type Target = string | HTMLElement;
|
|
||||||
|
|
||||||
type Trigger = string | HTMLElement | HTMLCollection | NodeList;
|
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
emmiter?: TinyEmitter;
|
|
||||||
text?: string;
|
text?: string;
|
||||||
action?: Action;
|
action?: Action;
|
||||||
target?: Element;
|
target?: Element;
|
||||||
trigger?: Trigger;
|
|
||||||
container?: Element;
|
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,
|
* Base class which takes one or more elements, adds event listeners to them,
|
||||||
* and instantiates a new `ClipboardAction` on each click.
|
* and instantiates a new `ClipboardAction` on each click.
|
||||||
*/
|
*/
|
||||||
export declare class ClipboardJS {
|
declare class ClipboardJS {
|
||||||
constructor(trigger: Trigger, options?: Options);
|
constructor(
|
||||||
|
selector: string | Element | NodeListOf<Element>,
|
||||||
|
options?: ClipboardJS.Options
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines if attributes would be resolved using internal setter functions
|
* Subscribes to events that indicate the result of a copy/cut operation.
|
||||||
* or custom functions that were passed in the constructor.
|
* @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.
|
* Clears all event bindings.
|
||||||
*/
|
|
||||||
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.
|
|
||||||
*/
|
*/
|
||||||
destroy(): void;
|
destroy(): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if clipboard.js is supported
|
||||||
|
*/
|
||||||
|
static isSupported(): boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
declare namespace ClipboardJS {
|
||||||
* Helper function to retrieve attribute value.
|
interface Options {
|
||||||
|
/**
|
||||||
|
* Overwrites default command ('cut' or 'copy').
|
||||||
|
* @param elem Current element
|
||||||
*/
|
*/
|
||||||
export declare function getAttributeValue(
|
action?(elem: Element): Action;
|
||||||
suffix: string,
|
|
||||||
element: Element
|
|
||||||
): string | undefined;
|
|
||||||
|
|
||||||
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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user