@ewc-lib/ewc-dialog-clipboard
Advanced tools
Comparing version 1.0.4-alpha to 1.0.5-alpha
{ | ||
"name": "@ewc-lib/ewc-dialog-clipboard", | ||
"version": "1.0.4-alpha", | ||
"version": "1.0.5-alpha", | ||
"description": "", | ||
"main": "src/main.js", | ||
"scripts": { | ||
}, | ||
"scripts": {}, | ||
"author": "", | ||
@@ -14,5 +13,5 @@ "license": "EUPL v.1.1", | ||
"dependencies": { | ||
"@ewc-lib/ewc-css": "^0.8.0", | ||
"@ewc-lib/ewc-dialog": "^2.0.1-alpha" | ||
"@ewc-lib/ewc-css": "^0.12.5", | ||
"@ewc-lib/ewc-dialog": "^2.0.5-alpha" | ||
} | ||
} |
103
src/main.js
@@ -1,53 +0,74 @@ | ||
import * as HTML from "./html.js" // keep this file html free | ||
import * as HTML from "./html.js"; // keep this file html free | ||
import Dialog from "../../ewc-dialog/src/main.js" | ||
import Dialog from "../../ewc-dialog/src/main.js"; | ||
class Element extends Dialog { | ||
#isInitialized = false; | ||
#clipboardContent = null; | ||
#isInitialized=false | ||
#clipboardContent = null | ||
constructor() { | ||
super(); | ||
} | ||
constructor() { | ||
super() | ||
} | ||
connectedCallback() { | ||
if( this.#isInitialized ) { return } | ||
connectedCallback() { | ||
if (this.#isInitialized) { | ||
return; | ||
} | ||
this.#isInitialized=true | ||
super.connectedCallback() | ||
this.#isInitialized = true; | ||
super.connectedCallback(); | ||
this.#modifyParent() | ||
this.#setupEventHandler() | ||
} | ||
this.#modifyParent(); | ||
this.#setupEventHandler(); | ||
} | ||
set clipboardContent(val) { | ||
this.#clipboardContent = val | ||
} | ||
// ... (No need for setFocusTrapElements() here) ... | ||
set visible(val) { | ||
this.querySelector(".ewc-notification--success").style.display = "none" | ||
this.querySelector(".ewc-notification--error").style.display = "none" | ||
super.visible=val | ||
super.focusTrap.setFirstElement( this.querySelector(".ewc-dialog__top-copy-image").closest("button") ) | ||
super.focusTrap.setLastElement(this.querySelector(".ewc-dialog__top-close-image").closest("button")) | ||
} | ||
set clipboardContent(val) { | ||
this.#clipboardContent = val; | ||
} | ||
#modifyParent() { | ||
const titleEl = this.querySelector(".ewc-dialog__title") | ||
titleEl.insertAdjacentElement("afterend", HTML.button().firstElementChild) | ||
titleEl.style.flexGrow = "unset" | ||
this.querySelector(".ewc-dialog__content").appendChild(HTML.footer()) | ||
} | ||
set visible(val) { | ||
this.querySelector(".ewc-notification--success").style.display = "none"; | ||
this.querySelector(".ewc-notification--error").style.display = "none"; | ||
super.visible = val; | ||
#setupEventHandler() { | ||
this.querySelector(".ewc-dialog__top-copy-image").addEventListener("click", this.#copyToClipboard.bind(this)) | ||
this.querySelector(".ewc-dialog__top-copy-image").closest("button").addEventListener("keydown", (ev)=>{ | ||
if(ev.key==="Enter"||ev.key===" "){ | ||
this.#copyToClipboard(this) | ||
} | ||
}) | ||
} | ||
// ... (No need to set focus trap elements here) ... | ||
} | ||
#modifyParent() { | ||
const titleEl = this.querySelector(".ewc-dialog__title"); | ||
titleEl.insertAdjacentElement("afterend", HTML.button().firstElementChild); | ||
titleEl.style.flexGrow = "unset"; | ||
this.querySelector(".ewc-dialog__content").appendChild(HTML.footer()); | ||
} | ||
#setupEventHandler() { | ||
this.querySelector(".ewc-dialog__top-copy-image").addEventListener( | ||
"click", | ||
this.#copyToClipboard.bind(this), | ||
); | ||
this.querySelector(".ewc-dialog__top-copy-image") | ||
.closest("button") | ||
.addEventListener("keydown", (ev) => { | ||
if (ev.key === "Enter" || ev.key === " ") { | ||
this.#copyToClipboard(this); | ||
} | ||
}); | ||
} | ||
async #copyToClipboard() { | ||
if (this.#clipboardContent != null) { | ||
try { | ||
await navigator.clipboard.writeText(this.#clipboardContent); | ||
this.querySelector(".ewc-notification--success").style.display = "flex"; | ||
} catch (error) { | ||
this.querySelector(".ewc-notification--error").style.display = "flex"; | ||
} | ||
} else { | ||
console.warn("No clipboard content"); | ||
} | ||
} | ||
async #copyToClipboard() { | ||
@@ -71,2 +92,2 @@ if(this.#clipboardContent != null) { | ||
document.body.append(HTML.getSvg()) | ||
} | ||
} |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
39593
166
1
+ Added@ewc-lib/ewc-css@0.12.8(transitive)
+ Added@ewc-lib/ewc-dialog@2.0.5-alpha(transitive)
- Removed@ewc-lib/ewc-css@0.8.0(transitive)
- Removed@ewc-lib/ewc-dialog@2.0.1-alpha(transitive)
Updated@ewc-lib/ewc-css@^0.12.5