wj-elements 0.1.46 → 0.1.47

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.
@@ -1,13 +1,13 @@
1
- var h = Object.defineProperty;
2
- var m = (o, e, t) => e in o ? h(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
1
+ var p = Object.defineProperty;
2
+ var m = (o, e, t) => e in o ? p(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
3
  var r = (o, e, t) => (m(o, typeof e != "symbol" ? e + "" : e, t), t);
4
- import f, { event as c } from "./wje-element.js";
5
- import b from "./wje-input.js";
6
- function y(o) {
4
+ import f, { WjElementUtils as b, event as c } from "./wje-element.js";
5
+ import y from "./wje-input.js";
6
+ function g(o) {
7
7
  const e = document.createElement("pre");
8
8
  return e.style.width = "1px", e.style.height = "1px", e.style.position = "fixed", e.style.top = "5px", e.textContent = o, e;
9
9
  }
10
- function p(o) {
10
+ function h(o) {
11
11
  if ("clipboard" in navigator)
12
12
  return navigator.clipboard.writeText(o.textContent || "");
13
13
  const e = getSelection();
@@ -17,16 +17,16 @@ function p(o) {
17
17
  const t = document.createRange();
18
18
  return t.selectNodeContents(o), e.addRange(t), e.removeAllRanges(), Promise.resolve();
19
19
  }
20
- function l(o) {
20
+ function u(o) {
21
21
  if ("clipboard" in navigator)
22
22
  return navigator.clipboard.writeText(o);
23
23
  const e = document.body;
24
24
  if (!e)
25
25
  return Promise.reject(new Error());
26
- const t = y(o);
27
- return e.appendChild(t), p(t), e.removeChild(t), Promise.resolve();
26
+ const t = g(o);
27
+ return e.appendChild(t), h(t), e.removeChild(t), Promise.resolve();
28
28
  }
29
- const g = ":host{cursor:pointer;padding:.5rem}";
29
+ const w = ":host{cursor:pointer;padding:.5rem}";
30
30
  class d extends f {
31
31
  /**
32
32
  * Constructor for the CopyButton class.
@@ -69,11 +69,12 @@ class d extends f {
69
69
  });
70
70
  /**
71
71
  * Handles the copied event.
72
+ * You can override this method to customize the behavior when the text is copied.
72
73
  * @param {Event} e - The event object.
73
74
  */
74
75
  r(this, "copied", (t) => {
75
- this.icon.setAttribute("color", "success"), this.icon.setAttribute("name", "check"), this.tooltip.setAttribute("content", this.labelSuccess || "Copied"), setTimeout(() => {
76
- this.icon.removeAttribute("color"), this.icon.setAttribute("name", "clipboard"), this.tooltip.setAttribute("content", this.label || "Copy");
76
+ this.hasOwnProperty("icon") && (this.icon.setAttribute("color", "success"), this.icon.setAttribute("name", "check")), this.tooltip.setAttribute("content", this.labelSuccess || "Copied"), setTimeout(() => {
77
+ console.log("TIMEOUT", this.hasOwnProperty("icon")), this.hasOwnProperty("icon") && (this.icon.removeAttribute("color"), this.icon.setAttribute("name", "clipboard")), this.tooltip.setAttribute("content", this.label || "Copy");
77
78
  }, this.timeout);
78
79
  });
79
80
  this.timeout = 1e3;
@@ -97,7 +98,7 @@ class d extends f {
97
98
  * @returns {string} The CSS styles.
98
99
  */
99
100
  static get cssStyleSheet() {
100
- return g;
101
+ return w;
101
102
  }
102
103
  /**
103
104
  * Getter for the observedAttributes property.
@@ -119,33 +120,38 @@ class d extends f {
119
120
  * @param {Object} params - The parameters to use.
120
121
  * @returns {DocumentFragment} The created document fragment.
121
122
  */
122
- draw(t, i, a) {
123
+ draw(t, i, l) {
123
124
  let s = document.createDocumentFragment(), n = document.createElement("wje-tooltip");
124
- n.setAttribute("offset", "5"), n.setAttribute("content", this.label || "Copy");
125
- let u = document.createElement("wje-icon");
126
- return u.setAttribute("name", "clipboard"), n.appendChild(u), s.appendChild(n), this.tooltip = n, this.icon = u, s;
125
+ if (n.setAttribute("offset", "5"), n.setAttribute("content", this.label || "Copy"), b.hasSlot(this)) {
126
+ let a = document.createElement("slot");
127
+ n.appendChild(a);
128
+ } else {
129
+ let a = document.createElement("wje-icon");
130
+ a.setAttribute("name", "clipboard"), n.appendChild(a), this.icon = a;
131
+ }
132
+ return s.appendChild(n), this.tooltip = n, s;
127
133
  }
128
134
  /**
129
135
  * Sets up the event listeners after the CopyButton is drawn.
130
136
  */
131
137
  afterDraw() {
132
- c.addListener(this, "click", null, this.clicked), c.addListener(this, "focus", null, this.focused), c.addListener(this, "blur", null, this.blurred), c.addListener(this, "wje:copy-button", null, this.copied);
138
+ c.addListener(this, "click", null, this.clicked), c.addListener(this, "focus", null, this.focused), c.addListener(this, "blur", null, this.blurred), c.addListener(this, "wje-copy-button:click", null, this.copied);
133
139
  }
134
140
  /**
135
141
  * Copies the specified text or node.
136
142
  * @param {HTMLElement} button - The button element.
137
143
  */
138
144
  async copy(t) {
139
- const i = this.getAttribute("for"), a = this.getAttribute("value");
145
+ const i = this.getAttribute("for"), l = this.getAttribute("value");
140
146
  if (t.getAttribute("aria-disabled") !== "true") {
141
- if (a)
142
- await l(a), c.dispatchCustomEvent(this, "wje:copy-button");
147
+ if (l)
148
+ await u(l), c.dispatchCustomEvent(this, "wje-copy-button:click");
143
149
  else if (i) {
144
150
  const s = "getRootNode" in Element.prototype ? t.getRootNode() : t.ownerDocument;
145
151
  if (!(s instanceof Document || "ShadowRoot" in window && s instanceof ShadowRoot))
146
152
  return;
147
153
  const n = s.getElementById(i);
148
- n && (await this.copyTarget(n), c.dispatchCustomEvent(this, "wje:copy-button"));
154
+ n && (await this.copyTarget(n), c.dispatchCustomEvent(this, "wje-copy-button:click"));
149
155
  }
150
156
  }
151
157
  }
@@ -155,7 +161,7 @@ class d extends f {
155
161
  * @returns {Promise} A promise that resolves when the content is copied.
156
162
  */
157
163
  copyTarget(t) {
158
- return t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement || t instanceof b ? l(t.value) : t instanceof HTMLAnchorElement && t.hasAttribute("href") ? l(t.href) : p(t);
164
+ return t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement || t instanceof y ? u(t.value) : t instanceof HTMLAnchorElement && t.hasAttribute("href") ? u(t.href) : h(t);
159
165
  }
160
166
  }
161
167
  d.define("wje-copy-button", d);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wj-elements",
3
3
  "description": "WebJET Elements is a modern set of user interface tools harnessing the power of web components designed to simplify web application development.",
4
- "version": "0.1.46",
4
+ "version": "0.1.47",
5
5
  "homepage": "https://github.com/lencys/wj-elements",
6
6
  "author": "Lukáš Ondrejček <lukas.ondrejcek@gmail.com>",
7
7
  "license": "MIT",