-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #736 from zenorocha/feat-update-type-definitions
updating type definitions
- Loading branch information
Showing
1 changed file
with
60 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
/** | ||
* Defines if attributes would be resolved using internal setter functions | ||
* or custom functions that were passed in the constructor. | ||
*/ | ||
resolveOptions(options: Options): void; | ||
/** | ||
* 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; | ||
declare class ClipboardJS { | ||
constructor( | ||
selector: string | Element | NodeListOf<Element>, | ||
options?: ClipboardJS.Options | ||
); | ||
|
||
/** | ||
* Returns the support of the given action, or all actions if no action is | ||
* given. | ||
* Subscribes to events that indicate the result of a copy/cut operation. | ||
* @param type Event type ('success' or 'error'). | ||
* @param handler Callback function. | ||
*/ | ||
static isSupported(action?: Action): boolean; | ||
on(type: Response, handler: (e: ClipboardJS.Event) => void): this; | ||
|
||
on(type: string, handler: (...args: any[]) => void): this; | ||
|
||
/** | ||
* Default `text` lookup function. | ||
* Clears all event bindings. | ||
*/ | ||
defaultText(trigger: Trigger): string | undefined; | ||
destroy(): void; | ||
|
||
/** | ||
* Destroy lifecycle. | ||
* Checks if clipboard.js is supported | ||
*/ | ||
destroy(): void; | ||
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; | ||
|
||
/** | ||
* 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 default ClipboardJS; | ||
export as namespace ClipboardJS; |