Deploy Ladill Hosting / deploy (push) Successful in 1m29s
Expose authenticated service endpoints for assigning, listing, renewing, and managing hosting accounts from the platform, with tests and deploy docs. Co-authored-by: Cursor <cursoragent@cursor.com>
58 lines
1.3 KiB
JavaScript
58 lines
1.3 KiB
JavaScript
const COPY_FEEDBACK_MS = 2000;
|
|
|
|
export async function writeClipboardText(text) {
|
|
const value = String(text ?? '');
|
|
if (!value) {
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
if (navigator.clipboard?.writeText) {
|
|
await navigator.clipboard.writeText(value);
|
|
|
|
return true;
|
|
}
|
|
} catch {
|
|
// fall through to legacy copy
|
|
}
|
|
|
|
try {
|
|
const textarea = document.createElement('textarea');
|
|
textarea.value = value;
|
|
textarea.style.position = 'fixed';
|
|
textarea.style.opacity = '0';
|
|
document.body.appendChild(textarea);
|
|
textarea.select();
|
|
const ok = document.execCommand('copy');
|
|
document.body.removeChild(textarea);
|
|
|
|
return ok;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export function registerLadillClipboard(Alpine) {
|
|
Alpine.data('copyButton', (text = '') => ({
|
|
copied: false,
|
|
text: text ?? '',
|
|
resetTimer: null,
|
|
async copy() {
|
|
const ok = await writeClipboardText(this.text);
|
|
if (!ok) {
|
|
return;
|
|
}
|
|
|
|
this.copied = true;
|
|
|
|
if (this.resetTimer) {
|
|
clearTimeout(this.resetTimer);
|
|
}
|
|
|
|
this.resetTimer = setTimeout(() => {
|
|
this.copied = false;
|
|
}, COPY_FEEDBACK_MS);
|
|
},
|
|
}));
|
|
}
|