Compare commits

...
2 Commits
Author SHA1 Message Date
pk 5bacaec865 Bump version to 2.1.0 2026-10-25 12:51:21 +01:00
pk 8877361fdc Copy message to clipboard on click 2026-10-25 12:51:21 +01:00
3 changed files with 163 additions and 18 deletions

No files matched your search

+125 -15
View File
@@ -1,24 +1,26 @@
{ {
"name": "@tp/tp-toaster", "name": "@tp/tp-toaster",
"version": "0.0.1", "version": "2.1.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@tp/tp-toaster", "name": "@tp/tp-toaster",
"version": "0.0.1", "version": "2.1.0",
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"@tp/helpers": "^1.2.1", "@tp/helpers": "^2.8.0",
"@tp/tp-icon": "^1.0.1", "@tp/tp-icon": "^1.0.1",
"@tp/tp-media-query": "^1.0.0", "@tp/tp-media-query": "^1.0.0",
"@tp/tp-timeout-strip": "^1.0.0",
"lit": "^2.2.0" "lit": "^2.2.0"
} }
}, },
"node_modules/@lit-labs/ssr-dom-shim": { "node_modules/@lit-labs/ssr-dom-shim": {
"version": "1.1.1", "version": "1.6.0",
"resolved": "https://registry.npmjs.org/@lit-labs/ssr-dom-shim/-/ssr-dom-shim-1.1.1.tgz", "resolved": "https://registry.npmjs.org/@lit-labs/ssr-dom-shim/-/ssr-dom-shim-1.6.0.tgz",
"integrity": "sha512-kXOeFbfCm4fFf2A3WwVEeQj55tMZa8c8/f9AKHMobQMkzNUfUj+antR3fRPaZJawsa1aZiP/Da3ndpZrwEe4rQ==" "integrity": "sha512-VHb0ALPMTlgKjM6yIxxoQNnpKyUKLD04VzeQdsiXkMqkvYlAHxq9glGLmgbb889/1GsohSOAjvQYoiBppXFqrQ==",
"license": "BSD-3-Clause"
}, },
"node_modules/@lit/reactive-element": { "node_modules/@lit/reactive-element": {
"version": "1.6.2", "version": "1.6.2",
@@ -29,9 +31,9 @@
} }
}, },
"node_modules/@tp/helpers": { "node_modules/@tp/helpers": {
"version": "1.2.1", "version": "2.14.0",
"resolved": "https://gitea.codeblob.work/api/packages/tp-elements/npm/%40tp%2Fhelpers/-/1.2.1/helpers-1.2.1.tgz", "resolved": "https://gitea.codeblob.work/api/packages/tp-elements/npm/@tp/helpers/-/helpers-2.14.0.tgz",
"integrity": "sha512-ukcITyYE10lFT9lTOuu8UQM0s/qKIfw6ihYHVZbUViKyMgGNihWPIQSTZJS5UV2bVbBtQdwQJ+91WcO79ymk3g==", "integrity": "sha512-sJsSkQPvxDXCMr/WJ9cgSJygqGKwDUpgd2ClV83t3+PASH1iozMjDDhJMW18wjza5qZWz9blqYQMues9XFGv7Q==",
"license": "Apache-2.0" "license": "Apache-2.0"
}, },
"node_modules/@tp/tp-icon": { "node_modules/@tp/tp-icon": {
@@ -53,6 +55,55 @@
"lit": "^2.2.0" "lit": "^2.2.0"
} }
}, },
"node_modules/@tp/tp-timeout-strip": {
"version": "1.0.1",
"resolved": "https://gitea.codeblob.work/api/packages/tp-elements/npm/@tp/tp-timeout-strip/-/tp-timeout-strip-1.0.1.tgz",
"integrity": "sha512-Iw2BstoE4cANffZCauNkDX9N6Yv3jfN2PrSmGkAo9X1o25tl+o0J3ZrP2ySAJhMma1XqLv/tWP0j3Ubt0UPD+Q==",
"license": "Apache-2.0",
"dependencies": {
"lit": "^3.0.0"
}
},
"node_modules/@tp/tp-timeout-strip/node_modules/@lit/reactive-element": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/@lit/reactive-element/-/reactive-element-2.1.2.tgz",
"integrity": "sha512-pbCDiVMnne1lYUIaYNN5wrwQXDtHaYtg7YEFPeW+hws6U47WeFvISGUWekPGKWOP1ygrs0ef0o1VJMk1exos5A==",
"license": "BSD-3-Clause",
"dependencies": {
"@lit-labs/ssr-dom-shim": "^1.5.0"
}
},
"node_modules/@tp/tp-timeout-strip/node_modules/lit": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/lit/-/lit-3.3.3.tgz",
"integrity": "sha512-fycuvZg/hkpozL00lm1pEJH5nN/lr9ZXd6mJI2HSN4+Bzc+LDNdEApJ6HFbPkdFNHLvOplIIuJvxkS4XUxqirw==",
"license": "BSD-3-Clause",
"dependencies": {
"@lit/reactive-element": "^2.1.0",
"lit-element": "^4.2.0",
"lit-html": "^3.3.0"
}
},
"node_modules/@tp/tp-timeout-strip/node_modules/lit-element": {
"version": "4.2.2",
"resolved": "https://registry.npmjs.org/lit-element/-/lit-element-4.2.2.tgz",
"integrity": "sha512-aFKhNToWxoyhkNDmWZwEva2SlQia+jfG0fjIWV//YeTaWrVnOxD89dPKfigCUspXFmjzOEUQpOkejH5Ly6sG0w==",
"license": "BSD-3-Clause",
"dependencies": {
"@lit-labs/ssr-dom-shim": "^1.5.0",
"@lit/reactive-element": "^2.1.0",
"lit-html": "^3.3.0"
}
},
"node_modules/@tp/tp-timeout-strip/node_modules/lit-html": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/lit-html/-/lit-html-3.3.3.tgz",
"integrity": "sha512-el8M6jK2o3RXBnrSHX3ZKrsN8zEV63pSExTO1wYJz7QndGYZ8353e2a5PPX+qHe2aGayfnchQmkAojaWAREOIA==",
"license": "BSD-3-Clause",
"dependencies": {
"@types/trusted-types": "^2.0.2"
}
},
"node_modules/@tp/tp-tooltip": { "node_modules/@tp/tp-tooltip": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://gitea.codeblob.work/api/packages/tp-elements/npm/%40tp%2Ftp-tooltip/-/1.0.0/tp-tooltip-1.0.0.tgz", "resolved": "https://gitea.codeblob.work/api/packages/tp-elements/npm/%40tp%2Ftp-tooltip/-/1.0.0/tp-tooltip-1.0.0.tgz",
@@ -63,6 +114,12 @@
"lit": "^2.2.0" "lit": "^2.2.0"
} }
}, },
"node_modules/@tp/tp-tooltip/node_modules/@tp/helpers": {
"version": "1.3.0",
"resolved": "https://gitea.codeblob.work/api/packages/tp-elements/npm/@tp/helpers/-/helpers-1.3.0.tgz",
"integrity": "sha512-mOAVP45kkEYXwonaOd5jkFQLX1nbeKtl8YX8FpL2ytON0cOSsh6TUAbCEcMU5xqgyD6L1ZEZNvxCjhOKOKdGyA==",
"license": "Apache-2.0"
},
"node_modules/@types/trusted-types": { "node_modules/@types/trusted-types": {
"version": "2.0.3", "version": "2.0.3",
"resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.3.tgz", "resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.3.tgz",
@@ -99,9 +156,9 @@
}, },
"dependencies": { "dependencies": {
"@lit-labs/ssr-dom-shim": { "@lit-labs/ssr-dom-shim": {
"version": "1.1.1", "version": "1.6.0",
"resolved": "https://registry.npmjs.org/@lit-labs/ssr-dom-shim/-/ssr-dom-shim-1.1.1.tgz", "resolved": "https://registry.npmjs.org/@lit-labs/ssr-dom-shim/-/ssr-dom-shim-1.6.0.tgz",
"integrity": "sha512-kXOeFbfCm4fFf2A3WwVEeQj55tMZa8c8/f9AKHMobQMkzNUfUj+antR3fRPaZJawsa1aZiP/Da3ndpZrwEe4rQ==" "integrity": "sha512-VHb0ALPMTlgKjM6yIxxoQNnpKyUKLD04VzeQdsiXkMqkvYlAHxq9glGLmgbb889/1GsohSOAjvQYoiBppXFqrQ=="
}, },
"@lit/reactive-element": { "@lit/reactive-element": {
"version": "1.6.2", "version": "1.6.2",
@@ -112,9 +169,9 @@
} }
}, },
"@tp/helpers": { "@tp/helpers": {
"version": "1.2.1", "version": "2.14.0",
"resolved": "https://gitea.codeblob.work/api/packages/tp-elements/npm/%40tp%2Fhelpers/-/1.2.1/helpers-1.2.1.tgz", "resolved": "https://gitea.codeblob.work/api/packages/tp-elements/npm/@tp/helpers/-/helpers-2.14.0.tgz",
"integrity": "sha512-ukcITyYE10lFT9lTOuu8UQM0s/qKIfw6ihYHVZbUViKyMgGNihWPIQSTZJS5UV2bVbBtQdwQJ+91WcO79ymk3g==" "integrity": "sha512-sJsSkQPvxDXCMr/WJ9cgSJygqGKwDUpgd2ClV83t3+PASH1iozMjDDhJMW18wjza5qZWz9blqYQMues9XFGv7Q=="
}, },
"@tp/tp-icon": { "@tp/tp-icon": {
"version": "1.0.1", "version": "1.0.1",
@@ -133,6 +190,52 @@
"lit": "^2.2.0" "lit": "^2.2.0"
} }
}, },
"@tp/tp-timeout-strip": {
"version": "1.0.1",
"resolved": "https://gitea.codeblob.work/api/packages/tp-elements/npm/@tp/tp-timeout-strip/-/tp-timeout-strip-1.0.1.tgz",
"integrity": "sha512-Iw2BstoE4cANffZCauNkDX9N6Yv3jfN2PrSmGkAo9X1o25tl+o0J3ZrP2ySAJhMma1XqLv/tWP0j3Ubt0UPD+Q==",
"requires": {
"lit": "^3.0.0"
},
"dependencies": {
"@lit/reactive-element": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/@lit/reactive-element/-/reactive-element-2.1.2.tgz",
"integrity": "sha512-pbCDiVMnne1lYUIaYNN5wrwQXDtHaYtg7YEFPeW+hws6U47WeFvISGUWekPGKWOP1ygrs0ef0o1VJMk1exos5A==",
"requires": {
"@lit-labs/ssr-dom-shim": "^1.5.0"
}
},
"lit": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/lit/-/lit-3.3.3.tgz",
"integrity": "sha512-fycuvZg/hkpozL00lm1pEJH5nN/lr9ZXd6mJI2HSN4+Bzc+LDNdEApJ6HFbPkdFNHLvOplIIuJvxkS4XUxqirw==",
"requires": {
"@lit/reactive-element": "^2.1.0",
"lit-element": "^4.2.0",
"lit-html": "^3.3.0"
}
},
"lit-element": {
"version": "4.2.2",
"resolved": "https://registry.npmjs.org/lit-element/-/lit-element-4.2.2.tgz",
"integrity": "sha512-aFKhNToWxoyhkNDmWZwEva2SlQia+jfG0fjIWV//YeTaWrVnOxD89dPKfigCUspXFmjzOEUQpOkejH5Ly6sG0w==",
"requires": {
"@lit-labs/ssr-dom-shim": "^1.5.0",
"@lit/reactive-element": "^2.1.0",
"lit-html": "^3.3.0"
}
},
"lit-html": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/lit-html/-/lit-html-3.3.3.tgz",
"integrity": "sha512-el8M6jK2o3RXBnrSHX3ZKrsN8zEV63pSExTO1wYJz7QndGYZ8353e2a5PPX+qHe2aGayfnchQmkAojaWAREOIA==",
"requires": {
"@types/trusted-types": "^2.0.2"
}
}
}
},
"@tp/tp-tooltip": { "@tp/tp-tooltip": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://gitea.codeblob.work/api/packages/tp-elements/npm/%40tp%2Ftp-tooltip/-/1.0.0/tp-tooltip-1.0.0.tgz", "resolved": "https://gitea.codeblob.work/api/packages/tp-elements/npm/%40tp%2Ftp-tooltip/-/1.0.0/tp-tooltip-1.0.0.tgz",
@@ -140,6 +243,13 @@
"requires": { "requires": {
"@tp/helpers": "^1.0.0", "@tp/helpers": "^1.0.0",
"lit": "^2.2.0" "lit": "^2.2.0"
},
"dependencies": {
"@tp/helpers": {
"version": "1.3.0",
"resolved": "https://gitea.codeblob.work/api/packages/tp-elements/npm/@tp/helpers/-/helpers-1.3.0.tgz",
"integrity": "sha512-mOAVP45kkEYXwonaOd5jkFQLX1nbeKtl8YX8FpL2ytON0cOSsh6TUAbCEcMU5xqgyD6L1ZEZNvxCjhOKOKdGyA=="
}
} }
}, },
"@types/trusted-types": { "@types/trusted-types": {
+2 -2
View File
@@ -1,6 +1,6 @@
{ {
"name": "@tp/tp-toaster", "name": "@tp/tp-toaster",
"version": "2.0.0", "version": "2.1.0",
"description": "", "description": "",
"main": "tp-toaster.js", "main": "tp-toaster.js",
"scripts": { "scripts": {
@@ -13,7 +13,7 @@
"author": "trading_peter", "author": "trading_peter",
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"@tp/helpers": "^1.2.1", "@tp/helpers": "^2.8.0",
"@tp/tp-icon": "^1.0.1", "@tp/tp-icon": "^1.0.1",
"@tp/tp-media-query": "^1.0.0", "@tp/tp-media-query": "^1.0.0",
"@tp/tp-timeout-strip": "^1.0.0", "@tp/tp-timeout-strip": "^1.0.0",
+36 -1
View File
@@ -5,6 +5,7 @@ Copyright (c) 2023 EDV Wasmeier
import '@tp/tp-timeout-strip/tp-timeout-strip.js'; import '@tp/tp-timeout-strip/tp-timeout-strip.js';
import { EventHelpers } from '@tp/helpers/event-helpers.js'; import { EventHelpers } from '@tp/helpers/event-helpers.js';
import { copyToClipboard } from '@tp/helpers/clipboard.js';
import { LitElement, html, css, svg } from 'lit'; import { LitElement, html, css, svg } from 'lit';
class TpToast extends EventHelpers(LitElement) { class TpToast extends EventHelpers(LitElement) {
@@ -76,7 +77,7 @@ class TpToast extends EventHelpers(LitElement) {
<div class="icon" part="type-icon-wrap"> <div class="icon" part="type-icon-wrap">
<tp-icon part="type-icon" .icon=${icon || TpToast[this.type + 'Icon']}></tp-icon> <tp-icon part="type-icon" .icon=${icon || TpToast[this.type + 'Icon']}></tp-icon>
</div> </div>
<div class="content" part="content"> <div class="content" part="content" @click=${this._copyContent}>
<slot></slot> <slot></slot>
</div> </div>
${!sticky ? html` ${!sticky ? html`
@@ -107,6 +108,14 @@ class TpToast extends EventHelpers(LitElement) {
*/ */
delay: { type: Number }, delay: { type: Number },
/**
* If true (default), clicking the message copies the toast content to the clipboard
* and fires a `toast-copied` event.
* Disable via property binding (`.copyOnClick=${false}`) — a present boolean attribute
* always converts to true.
*/
copyOnClick: { type: Boolean },
/** /**
* If true, the toast cant be dismissed manually. * If true, the toast cant be dismissed manually.
*/ */
@@ -122,6 +131,7 @@ class TpToast extends EventHelpers(LitElement) {
super(); super();
this.type = 'info'; this.type = 'info';
this.delay = 5000; this.delay = 5000;
this.copyOnClick = true;
this.translateY = -150; this.translateY = -150;
this.dismiss = this.dismiss.bind(this); this.dismiss = this.dismiss.bind(this);
} }
@@ -167,6 +177,31 @@ class TpToast extends EventHelpers(LitElement) {
this.style.opacity = '0'; this.style.opacity = '0';
} }
/**
* Copies the toast content (slotted light-dom text) to the clipboard.
* Fires a bubbling, composed `toast-copied` event with `detail.text` on success.
* Skipped when `copyOnClick` is false, when the content is empty, or when the user
* made a manual text selection inside the toast (don't clobber their own copy).
*/
async _copyContent() {
if (!this.copyOnClick) return;
const selection = window.getSelection();
if (selection && selection.toString()) return;
const text = this.textContent.trim();
if (!text) return;
const success = await copyToClipboard(text);
if (success) {
this.dispatchEvent(new CustomEvent('toast-copied', {
detail: { text },
bubbles: true,
composed: true,
}));
}
}
/** /**
* Starts the delay timeout to dismiss the toast automatically. * Starts the delay timeout to dismiss the toast automatically.
*/ */