@nextcloud/vue
Version:
Nextcloud vue components
40 lines (39 loc) • 1.02 kB
JavaScript
import { d as mdiCheck, e as mdiContentCopy } from "./mdi-XFJRiRqJ.mjs";
import { ref, computed, toValue } from "vue";
import { r as register, c as t22, a as t } from "./_l10n-DrTiip5c.mjs";
register(t22);
/*!
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
const DELAY = 2e3;
function useCopy(content) {
const isCopied = ref(false);
const icon = computed(() => isCopied.value ? mdiCheck : mdiContentCopy);
const altText = computed(() => isCopied.value ? t("Copied") : t("Copy to clipboard"));
async function copy() {
if (isCopied.value) {
return;
}
const value = toValue(content);
try {
await navigator.clipboard.writeText(value);
} catch {
prompt("", value);
}
isCopied.value = true;
setTimeout(() => {
isCopied.value = false;
}, DELAY);
}
return {
isCopied,
copy,
icon,
altText
};
}
export {
useCopy as u
};
//# sourceMappingURL=useCopy-7FVrniF_.mjs.map