Skip to content

Commit 97b8c00

Browse files
committed
chore: remove clipboardjs
1 parent 219325c commit 97b8c00

3 files changed

Lines changed: 76 additions & 75 deletions

File tree

components/ClipBoard.vue

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
import { Copy } from "lucide-vue-next";
33
</script>
44
<template>
5-
<div class="copy bg-background hover:bg-background/50 transition-colors">
5+
<div class="copy bg-background hover:bg-background/50 transition-colors" @click="copyToClipboard">
66
<div
7-
v-if="!target"
87
ref="copy"
98
class="icon--btn icon--btn-small"
109
:data-clipboard-text="data"
@@ -13,58 +12,67 @@ import { Copy } from "lucide-vue-next";
1312
<Copy></Copy>
1413
</slot>
1514
</div>
16-
<div
17-
v-else
18-
ref="copy"
19-
class="icon--btn icon--btn-small"
20-
:data-clipboard-target="target"
21-
>
22-
<slot>
23-
<Copy></Copy>
24-
</slot>
25-
</div>
2615
</div>
2716
</template>
2817

2918
<script lang="ts">
30-
import ClipboardJS from "clipboard";
3119
import { toast } from "@/components/ui/toast";
3220
export default {
3321
props: {
34-
target: {
35-
required: false,
36-
type: String,
37-
default: undefined,
38-
},
3922
data: {
4023
required: false,
4124
type: String,
4225
default: "",
4326
},
4427
},
45-
data() {
46-
return {
47-
clipboard: undefined,
48-
};
49-
},
50-
mounted() {
51-
if (!this.data && !this.target) {
52-
console.warn("data missing");
53-
return;
54-
}
55-
56-
this.clipboard = new ClipboardJS(this.$refs["copy"]);
28+
methods: {
29+
async copyToClipboard() {
30+
if (!this.data) {
31+
console.warn("data missing");
32+
return;
33+
}
5734
58-
this.clipboard.on("success", (e) => {
59-
toast({
60-
title: "Copied to Clipboard",
61-
});
62-
e.clearSelection();
63-
});
64-
},
65-
beforeUnmount() {
66-
if (this.clipboard) {
67-
this.clipboard.destroy();
35+
try {
36+
if (navigator.clipboard && navigator.clipboard.writeText) {
37+
await navigator.clipboard.writeText(this.data);
38+
} else {
39+
this.fallbackCopyToClipboard(this.data);
40+
}
41+
42+
toast({
43+
title: "Copied to Clipboard",
44+
});
45+
} catch (err) {
46+
console.error('Failed to copy to clipboard:', err);
47+
this.fallbackCopyToClipboard(this.data);
48+
toast({
49+
title: "Copied to Clipboard",
50+
});
51+
}
52+
},
53+
54+
fallbackCopyToClipboard(text) {
55+
// Create a temporary textarea element
56+
const textArea = document.createElement("textarea");
57+
textArea.value = text;
58+
59+
// Make it invisible
60+
textArea.style.position = "fixed";
61+
textArea.style.left = "-999999px";
62+
textArea.style.top = "-999999px";
63+
document.body.appendChild(textArea);
64+
65+
// Select and copy the text
66+
textArea.focus();
67+
textArea.select();
68+
69+
try {
70+
document.execCommand('copy');
71+
} catch (err) {
72+
console.error('Fallback copy failed:', err);
73+
}
74+
75+
document.body.removeChild(textArea);
6876
}
6977
},
7078
};

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"aws4fetch": "^1.0.20",
5353
"chart.js": "^4.4.9",
5454
"class-variance-authority": "^0.7.1",
55-
"clipboard": "^2.0.11",
5655
"clsx": "^2.1.1",
5756
"countries-and-timezones": "^3.8.0",
5857
"country-flag-emoji-polyfill": "^0.1.8",

yarn.lock

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3848,15 +3848,6 @@ cli-width@^4.1.0:
38483848
resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-4.1.0.tgz#42daac41d3c254ef38ad8ac037672130173691c5"
38493849
integrity sha512-ouuZd4/dm2Sw5Gmqy6bGyNNNe1qt9RpmxveLSO7KcgsTnU7RXfsw+/bukWGo1abgBiMAic068rclZsO4IWmmxQ==
38503850

3851-
clipboard@^2.0.11:
3852-
version "2.0.11"
3853-
resolved "https://registry.yarnpkg.com/clipboard/-/clipboard-2.0.11.tgz#62180360b97dd668b6b3a84ec226975762a70be5"
3854-
integrity sha512-C+0bbOqkezLIsmWSvlsXS0Q0bmkugu7jcfMIACB+RDEntIzQIkdr148we28AfSloQLRdZlYL/QYyrq05j/3Faw==
3855-
dependencies:
3856-
good-listener "^1.2.2"
3857-
select "^1.1.2"
3858-
tiny-emitter "^2.0.0"
3859-
38603851
clipboardy@^3.0.0:
38613852
version "3.0.0"
38623853
resolved "https://registry.yarnpkg.com/clipboardy/-/clipboardy-3.0.0.tgz#f3876247404d334c9ed01b6f269c11d09a5e3092"
@@ -4557,11 +4548,6 @@ delayed-stream@~1.0.0:
45574548
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
45584549
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==
45594550

4560-
delegate@^3.1.2:
4561-
version "3.2.0"
4562-
resolved "https://registry.yarnpkg.com/delegate/-/delegate-3.2.0.tgz#b66b71c3158522e8ab5744f720d8ca0c2af59166"
4563-
integrity sha512-IofjkYBZaZivn0V8nnsMJGBr4jVLxHDheKSW88PyxS5QC4Vo9ZbZVvhzlSxY87fVq3STR6r+4cGepyHkcWOQSw==
4564-
45654551
delegates@^1.0.0:
45664552
version "1.0.0"
45674553
resolved "https://registry.yarnpkg.com/delegates/-/delegates-1.0.0.tgz#84c6e159b81904fdca59a0ef44cd870d31250f9a"
@@ -5779,13 +5765,6 @@ gonzales-pe@^4.3.0:
57795765
dependencies:
57805766
minimist "^1.2.5"
57815767

5782-
good-listener@^1.2.2:
5783-
version "1.2.2"
5784-
resolved "https://registry.yarnpkg.com/good-listener/-/good-listener-1.2.2.tgz#d53b30cdf9313dffb7dc9a0d477096aa6d145c50"
5785-
integrity sha512-goW1b+d9q/HIwbVYZzZ6SsTr4IgE+WA44A0GmPIQstuOrgsFcT7VEJ48nmr9GaRtNu0XTKacFLGnBPAM6Afouw==
5786-
dependencies:
5787-
delegate "^3.1.2"
5788-
57895768
gopd@^1.0.1, gopd@^1.2.0:
57905769
version "1.2.0"
57915770
resolved "https://registry.yarnpkg.com/gopd/-/gopd-1.2.0.tgz#89f56b8217bdbc8802bd299df6d7f1081d7e51a1"
@@ -9091,11 +9070,6 @@ scule@^1.3.0:
90919070
resolved "https://registry.yarnpkg.com/scule/-/scule-1.3.0.tgz#6efbd22fd0bb801bdcc585c89266a7d2daa8fbd3"
90929071
integrity sha512-6FtHJEvt+pVMIB9IBY+IcCJ6Z5f1iQnytgyfKMhDKgmzYG+TeH/wx1y3l27rshSbLiSanrR9ffZDrEsmjlQF2g==
90939072

9094-
select@^1.1.2:
9095-
version "1.1.2"
9096-
resolved "https://registry.yarnpkg.com/select/-/select-1.1.2.tgz#0e7350acdec80b1108528786ec1d4418d11b396d"
9097-
integrity sha512-OwpTSOfy6xSs1+pwcNrv0RBMOzI39Lp3qQKUTPVVPRjCdNa5JH/oPRiqsesIskK8TVgmRiHwO4KXlV2Li9dANA==
9098-
90999073
semver@^5.5.0:
91009074
version "5.7.2"
91019075
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.2.tgz#48d55db737c3287cd4835e17fa13feace1c41ef8"
@@ -9551,7 +9525,16 @@ streamx@^2.15.0, streamx@^2.21.0:
95519525
optionalDependencies:
95529526
bare-events "^2.2.0"
95539527

9554-
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
9528+
"string-width-cjs@npm:string-width@^4.2.0":
9529+
version "4.2.3"
9530+
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
9531+
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
9532+
dependencies:
9533+
emoji-regex "^8.0.0"
9534+
is-fullwidth-code-point "^3.0.0"
9535+
strip-ansi "^6.0.1"
9536+
9537+
"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
95559538
version "4.2.3"
95569539
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
95579540
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -9643,7 +9626,14 @@ stringify-object@^3.3.0:
96439626
is-obj "^1.0.1"
96449627
is-regexp "^1.0.0"
96459628

9646-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
9629+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
9630+
version "6.0.1"
9631+
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
9632+
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
9633+
dependencies:
9634+
ansi-regex "^5.0.1"
9635+
9636+
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
96479637
version "6.0.1"
96489638
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
96499639
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -9940,11 +9930,6 @@ throttle-debounce@^5.0.0:
99409930
resolved "https://registry.yarnpkg.com/throttle-debounce/-/throttle-debounce-5.0.2.tgz#ec5549d84e053f043c9fd0f2a6dd892ff84456b1"
99419931
integrity sha512-B71/4oyj61iNH0KeCamLuE2rmKuTO5byTOSVwECM5FA7TiAiAW+UqTKZ9ERueC4qvgSttUhdmq1mXC3kJqGX7A==
99429932

9943-
tiny-emitter@^2.0.0:
9944-
version "2.1.0"
9945-
resolved "https://registry.yarnpkg.com/tiny-emitter/-/tiny-emitter-2.1.0.tgz#1d1a56edfc51c43e863cbb5382a72330e3555423"
9946-
integrity sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==
9947-
99489933
tiny-invariant@^1.3.3:
99499934
version "1.3.3"
99509935
resolved "https://registry.yarnpkg.com/tiny-invariant/-/tiny-invariant-1.3.3.tgz#46680b7a873a0d5d10005995eb90a70d74d60127"
@@ -11000,7 +10985,7 @@ wrangler@^4.14.4:
1100010985
fsevents "~2.3.2"
1100110986
sharp "^0.33.5"
1100210987

11003-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
10988+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
1100410989
version "7.0.0"
1100510990
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
1100610991
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -11018,6 +11003,15 @@ wrap-ansi@^6.2.0:
1101811003
string-width "^4.1.0"
1101911004
strip-ansi "^6.0.0"
1102011005

11006+
wrap-ansi@^7.0.0:
11007+
version "7.0.0"
11008+
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
11009+
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
11010+
dependencies:
11011+
ansi-styles "^4.0.0"
11012+
string-width "^4.1.0"
11013+
strip-ansi "^6.0.0"
11014+
1102111015
wrap-ansi@^8.1.0:
1102211016
version "8.1.0"
1102311017
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)