clipboard.d.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /// <reference lib="dom"/>
  2. type Action = 'cut' | 'copy';
  3. type Response = 'success' | 'error';
  4. type CopyActionOptions = {
  5. container?: Element;
  6. };
  7. /**
  8. * Base class which takes one or more elements, adds event listeners to them,
  9. * and instantiates a new `ClipboardAction` on each click.
  10. */
  11. declare class ClipboardJS {
  12. constructor(
  13. selector: string | Element | NodeListOf<Element>,
  14. options?: ClipboardJS.Options
  15. );
  16. /**
  17. * Subscribes to events that indicate the result of a copy/cut operation.
  18. * @param type Event type ('success' or 'error').
  19. * @param handler Callback function.
  20. */
  21. on(type: Response, handler: (e: ClipboardJS.Event) => void): this;
  22. on(type: string, handler: (...args: any[]) => void): this;
  23. /**
  24. * Clears all event bindings.
  25. */
  26. destroy(): void;
  27. /**
  28. * Checks if clipboard.js is supported
  29. */
  30. static isSupported(): boolean;
  31. /**
  32. * Fires a copy action
  33. */
  34. static copy(target: string | Element, options?: CopyActionOptions): string;
  35. /**
  36. * Fires a cut action
  37. */
  38. static cut(target: string | Element): string;
  39. }
  40. declare namespace ClipboardJS {
  41. interface Options {
  42. /**
  43. * Overwrites default command ('cut' or 'copy').
  44. * @param elem Current element
  45. */
  46. action?(elem: Element): Action;
  47. /**
  48. * Overwrites default target input element.
  49. * @param elem Current element
  50. * @returns <input> element to use.
  51. */
  52. target?(elem: Element): Element;
  53. /**
  54. * Returns the explicit text to copy.
  55. * @param elem Current element
  56. * @returns Text to be copied.
  57. */
  58. text?(elem: Element): string;
  59. /**
  60. * For use in Bootstrap Modals or with any
  61. * other library that changes the focus
  62. * you'll want to set the focused element
  63. * as the container value.
  64. */
  65. container?: Element;
  66. }
  67. interface Event {
  68. action: string;
  69. text: string;
  70. trigger: Element;
  71. clearSelection(): void;
  72. }
  73. }
  74. export = ClipboardJS;
  75. export as namespace ClipboardJS;