@exmg/exm-copy-to-clipboard 1.1.36 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,49 @@
1
+ import { ExmgElement } from '@exmg/lit-base/index.js';
2
+ /**
3
+ * `<exm-copy-to-clipboard>` Helper element to create icon/buttons that
4
+ * lets the user copy content to the clipboard. Just wrap it arround
5
+ * the button or icon and set the value that needs to be copied.
6
+ *
7
+ * ```html
8
+ * <exm-copy-to-clipboard value="mark@test.com">
9
+ * <md-icon-button icon="content-copy"><md-icon>content-copy</md-icon></md-icon-button>
10
+ * </exm-copy-to-clipboard>
11
+ * ```
12
+ *
13
+ * @customElement exm-copy-to-clipboard
14
+ * @extends ExmgElement
15
+ */
16
+ export declare class ExmCopyToClipboard extends ExmgElement {
17
+ /**
18
+ * Value to be copied
19
+ * @type {String}
20
+ */
21
+ value?: string;
22
+ private isCopySupported;
23
+ protected bubbles: boolean;
24
+ clipboard?: HTMLElement;
25
+ private htmlElement?;
26
+ private handleCopy;
27
+ private _observer?;
28
+ static styles: import("lit").CSSResult[];
29
+ constructor();
30
+ connectedCallback(): void;
31
+ firstUpdated(): void;
32
+ disconnectedCallback(): void;
33
+ addClickListener(): void;
34
+ /**
35
+ * Copy the given value to the clipboard
36
+ * @private
37
+ */
38
+ private copyToClipboard;
39
+ /**
40
+ * Handle button tap event and trigger the actual copy to clipboard
41
+ */
42
+ handleCopyAction(e: Event): void;
43
+ render(): import("lit-html").TemplateResult<1>;
44
+ }
45
+ declare global {
46
+ interface HTMLElementTagNameMap {
47
+ 'exm-copy-to-clipboard': ExmCopyToClipboard;
48
+ }
49
+ }
@@ -0,0 +1,122 @@
1
+ import { __decorate } from "tslib";
2
+ import { html } from 'lit';
3
+ import { customElement, state, property, query } from 'lit/decorators.js';
4
+ import { ExmgElement } from '@exmg/lit-base/index.js';
5
+ import { style } from './styles/exm-copy-to-clipboard-styles-css.js';
6
+ /**
7
+ * `<exm-copy-to-clipboard>` Helper element to create icon/buttons that
8
+ * lets the user copy content to the clipboard. Just wrap it arround
9
+ * the button or icon and set the value that needs to be copied.
10
+ *
11
+ * ```html
12
+ * <exm-copy-to-clipboard value="mark@test.com">
13
+ * <md-icon-button icon="content-copy"><md-icon>content-copy</md-icon></md-icon-button>
14
+ * </exm-copy-to-clipboard>
15
+ * ```
16
+ *
17
+ * @customElement exm-copy-to-clipboard
18
+ * @extends ExmgElement
19
+ */
20
+ let ExmCopyToClipboard = class ExmCopyToClipboard extends ExmgElement {
21
+ constructor() {
22
+ super();
23
+ this.isCopySupported = false;
24
+ this.bubbles = false;
25
+ this.isCopySupported = !!document.queryCommandSupported('copy');
26
+ this.handleCopy = this.handleCopyAction.bind(this);
27
+ }
28
+ connectedCallback() {
29
+ super.connectedCallback();
30
+ // Create an observer instance linked to the callback function
31
+ this._observer = new MutationObserver((mutationsList) => {
32
+ for (const mutation of mutationsList) {
33
+ if (mutation.type === 'childList') {
34
+ this.addClickListener();
35
+ }
36
+ }
37
+ });
38
+ // Start observing the target node for configured mutations
39
+ this._observer.observe(this, { attributes: true, childList: true, subtree: false });
40
+ }
41
+ firstUpdated() {
42
+ this.addClickListener();
43
+ if (!this.isCopySupported && this.htmlElement) {
44
+ this.htmlElement.style.display = 'none';
45
+ this.dispatchEvent(new CustomEvent('copy-not-supported', { bubbles: this.bubbles, composed: true }));
46
+ }
47
+ }
48
+ disconnectedCallback() {
49
+ var _a, _b;
50
+ (_a = this.htmlElement) === null || _a === void 0 ? void 0 : _a.removeEventListener('click', this.handleCopy);
51
+ (_b = this._observer) === null || _b === void 0 ? void 0 : _b.disconnect();
52
+ super.disconnectedCallback();
53
+ }
54
+ addClickListener() {
55
+ var _a, _b;
56
+ (_a = this.htmlElement) === null || _a === void 0 ? void 0 : _a.removeEventListener('click', this.handleCopy);
57
+ const elements = this.querySelectorAll('*');
58
+ this.htmlElement = elements[0];
59
+ (_b = this.htmlElement) === null || _b === void 0 ? void 0 : _b.addEventListener('click', this.handleCopy);
60
+ }
61
+ /**
62
+ * Copy the given value to the clipboard
63
+ * @private
64
+ */
65
+ copyToClipboard() {
66
+ const clipboardNode = this.shadowRoot ? this.clipboard : null;
67
+ if (!clipboardNode) {
68
+ return;
69
+ }
70
+ clipboardNode.style.display = 'block';
71
+ const range = document.createRange();
72
+ const selection = window.getSelection();
73
+ range.selectNodeContents(clipboardNode);
74
+ selection.removeAllRanges();
75
+ selection.addRange(range);
76
+ try {
77
+ document.execCommand('copy');
78
+ this.dispatchEvent(new CustomEvent('exm-copy-to-clipboard-copied', {
79
+ detail: this.value,
80
+ bubbles: this.bubbles,
81
+ composed: true,
82
+ }));
83
+ }
84
+ catch (err) {
85
+ // eslint-disable-next-line no-console
86
+ console.error('copy to clipboard failed', err);
87
+ }
88
+ selection.removeAllRanges();
89
+ clipboardNode.style.display = 'none';
90
+ }
91
+ /**
92
+ * Handle button tap event and trigger the actual copy to clipboard
93
+ */
94
+ handleCopyAction(e) {
95
+ this.copyToClipboard();
96
+ e.stopPropagation();
97
+ }
98
+ render() {
99
+ return html `
100
+ <slot></slot>
101
+ <span id="clipboard">${this.value}</span>
102
+ `;
103
+ }
104
+ };
105
+ ExmCopyToClipboard.styles = [style];
106
+ __decorate([
107
+ property({ type: String })
108
+ ], ExmCopyToClipboard.prototype, "value", void 0);
109
+ __decorate([
110
+ state()
111
+ ], ExmCopyToClipboard.prototype, "isCopySupported", void 0);
112
+ __decorate([
113
+ state()
114
+ ], ExmCopyToClipboard.prototype, "bubbles", void 0);
115
+ __decorate([
116
+ query('#clipboard')
117
+ ], ExmCopyToClipboard.prototype, "clipboard", void 0);
118
+ ExmCopyToClipboard = __decorate([
119
+ customElement('exm-copy-to-clipboard')
120
+ ], ExmCopyToClipboard);
121
+ export { ExmCopyToClipboard };
122
+ //# sourceMappingURL=exm-copy-to-clipboard.js.map
@@ -0,0 +1,2 @@
1
+ export { ExmCopyToClipboard } from './exm-copy-to-clipboard.js';
2
+ export { style as copyToClipboardStyles } from './styles/exm-copy-to-clipboard-styles-css.js';
@@ -0,0 +1,3 @@
1
+ export { ExmCopyToClipboard } from './exm-copy-to-clipboard.js';
2
+ export { style as copyToClipboardStyles } from './styles/exm-copy-to-clipboard-styles-css.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ export declare const style: import("lit").CSSResult;
@@ -0,0 +1,11 @@
1
+ import { css } from 'lit';
2
+ export const style = css `
3
+ :host {
4
+ display: inline-block;
5
+ }
6
+
7
+ #clipboard {
8
+ display: none;
9
+ }
10
+ `;
11
+ //# sourceMappingURL=exm-copy-to-clipboard-styles-css.js.map
@@ -1,8 +1,9 @@
1
- import { __decorate } from "tslib";
1
+ import { __decorate } from 'tslib';
2
2
  import { html } from 'lit';
3
- import { customElement, state, property, query } from 'lit/decorators.js';
3
+ import { property, state, query, customElement } from 'lit/decorators.js';
4
4
  import { ExmgElement } from '@exmg/lit-base/index.js';
5
5
  import { style } from './styles/exm-copy-to-clipboard-styles-css.js';
6
+
6
7
  /**
7
8
  * `<exm-copy-to-clipboard>` Helper element to create icon/buttons that
8
9
  * lets the user copy content to the clipboard. Just wrap it arround
@@ -118,5 +119,6 @@ __decorate([
118
119
  ExmCopyToClipboard = __decorate([
119
120
  customElement('exm-copy-to-clipboard')
120
121
  ], ExmCopyToClipboard);
122
+
121
123
  export { ExmCopyToClipboard };
122
- //# sourceMappingURL=exm-copy-to-clipboard.js.map
124
+ //# sourceMappingURL=exm-copy-to-clipboard.js.map
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export { ExmCopyToClipboard } from './exm-copy-to-clipboard.js';
2
2
  export { style as copyToClipboardStyles } from './styles/exm-copy-to-clipboard-styles-css.js';
3
- //# sourceMappingURL=index.js.map
3
+ //# sourceMappingURL=index.js.map
@@ -1,5 +1,6 @@
1
1
  import { css } from 'lit';
2
- export const style = css `
2
+
3
+ const style = css `
3
4
  :host {
4
5
  display: inline-block;
5
6
  }
@@ -8,4 +9,6 @@ export const style = css `
8
9
  display: none;
9
10
  }
10
11
  `;
11
- //# sourceMappingURL=exm-copy-to-clipboard-styles-css.js.map
12
+
13
+ export { style };
14
+ //# sourceMappingURL=exm-copy-to-clipboard-styles-css.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exmg/exm-copy-to-clipboard",
3
- "version": "1.1.36",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -35,5 +35,5 @@
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "gitHead": "0fb4c4b7fdbc8d149a825e172b63f7e00c8e8a4a"
38
+ "gitHead": "b5f4ed4f41d79e3cce85dc0c44181ef4413d7458"
39
39
  }