Add media-shared-assets package (from MediaCollection/MediaShared)
Browser theme CSS/JS assets shared across MediaCollection's client apps, moved here per owner request to centralize shared components. The build:theme sync script now lives inside the package itself rather than assuming a monorepo-root scripts/ sibling; its 'test' script is a no-op placeholder since the package has no tests of its own yet. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
94af6d7601
commit
79d9461769
38 files changed
+10807
No files matched your search
@@ -0,0 +1,184 @@
|
||||
// Shared confirm dialog utility — matches the dark design language of the monorepo.
|
||||
// Usage: const ok = await NCConfirm.show({ title, message, confirmLabel, cancelLabel, danger });
|
||||
// Returns a Promise<boolean>: true = confirmed, false = cancelled.
|
||||
|
||||
(function (global) {
|
||||
if (global.NCConfirm) return;
|
||||
|
||||
const DIALOG_ID = 'nc-confirm-dialog';
|
||||
|
||||
function ensureDialog() {
|
||||
let dialog = document.getElementById(DIALOG_ID);
|
||||
if (dialog) return dialog;
|
||||
|
||||
dialog = document.createElement('div');
|
||||
dialog.id = DIALOG_ID;
|
||||
dialog.setAttribute('role', 'dialog');
|
||||
dialog.setAttribute('aria-modal', 'true');
|
||||
dialog.setAttribute('hidden', '');
|
||||
dialog.style.display = 'none';
|
||||
// Backdrop + centering
|
||||
dialog.className = 'fixed inset-0 z-[10100] flex items-center justify-center p-4';
|
||||
dialog.style.background = 'rgba(0,0,0,0.65)';
|
||||
dialog.style.backdropFilter = 'blur(2px)';
|
||||
|
||||
dialog.innerHTML = `
|
||||
<div
|
||||
id="nc-confirm-panel"
|
||||
class="w-full max-w-sm rounded-lg border border-slate-700 bg-slate-900 p-4 shadow-2xl"
|
||||
role="document"
|
||||
>
|
||||
<h2
|
||||
id="nc-confirm-title"
|
||||
class="mb-2 text-base font-semibold text-white"
|
||||
></h2>
|
||||
<p
|
||||
id="nc-confirm-message"
|
||||
class="mb-4 text-sm leading-relaxed text-slate-300"
|
||||
></p>
|
||||
<div class="flex justify-end gap-3">
|
||||
<button
|
||||
id="nc-confirm-cancel"
|
||||
type="button"
|
||||
class="inline-flex items-center rounded-lg border border-slate-600 px-4 py-2 text-sm font-medium text-slate-300 transition hover:bg-slate-800 focus:outline-none focus:ring-2 focus:ring-blue-300/20"
|
||||
></button>
|
||||
<button
|
||||
id="nc-confirm-ok"
|
||||
type="button"
|
||||
class="inline-flex items-center rounded-lg px-4 py-2 text-sm font-medium text-white transition focus:outline-none focus:ring-2 focus:ring-offset-1 focus:ring-offset-slate-900"
|
||||
></button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
document.body.appendChild(dialog);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
let _resolve = null;
|
||||
let _lastActive = null;
|
||||
|
||||
function focusables(dialog) {
|
||||
return [
|
||||
...dialog.querySelectorAll(
|
||||
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
|
||||
),
|
||||
].filter(el => !el.disabled && el.offsetParent !== null);
|
||||
}
|
||||
|
||||
function onKeyDown(e) {
|
||||
const dialog = document.getElementById(DIALOG_ID);
|
||||
if (!dialog || dialog.style.display === 'none') return;
|
||||
|
||||
if (e.key === 'Escape') {
|
||||
e.preventDefault();
|
||||
close(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.key === 'Tab') {
|
||||
const els = focusables(dialog);
|
||||
if (!els.length) return;
|
||||
const first = els[0];
|
||||
const last = els[els.length - 1];
|
||||
if (e.shiftKey && document.activeElement === first) {
|
||||
e.preventDefault();
|
||||
last.focus();
|
||||
} else if (!e.shiftKey && document.activeElement === last) {
|
||||
e.preventDefault();
|
||||
first.focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function close(result) {
|
||||
const dialog = document.getElementById(DIALOG_ID);
|
||||
if (dialog) {
|
||||
dialog.style.display = 'none';
|
||||
}
|
||||
document.removeEventListener('keydown', onKeyDown);
|
||||
if (_lastActive && typeof _lastActive.focus === 'function') {
|
||||
try {
|
||||
_lastActive.focus();
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
_lastActive = null;
|
||||
if (_resolve) {
|
||||
const r = _resolve;
|
||||
_resolve = null;
|
||||
r(result);
|
||||
}
|
||||
}
|
||||
|
||||
function show({
|
||||
title = 'Confirm',
|
||||
message = '',
|
||||
confirmLabel = 'Confirm',
|
||||
cancelLabel = 'Cancel',
|
||||
danger = false,
|
||||
} = {}) {
|
||||
return new Promise(resolve => {
|
||||
const dialog = ensureDialog();
|
||||
|
||||
document.getElementById('nc-confirm-title').textContent = title;
|
||||
document.getElementById('nc-confirm-message').textContent = message;
|
||||
document.getElementById('nc-confirm-cancel').textContent = cancelLabel;
|
||||
|
||||
const okBtn = document.getElementById('nc-confirm-ok');
|
||||
okBtn.textContent = confirmLabel;
|
||||
|
||||
// Danger vs primary style for confirm button
|
||||
if (danger) {
|
||||
okBtn.className = okBtn.className.replace(/focus:ring-\S+/g, 'focus:ring-red-500/50');
|
||||
okBtn.style.background = 'var(--color-danger-strong, #ef4444)';
|
||||
okBtn.onmouseover = () => {
|
||||
okBtn.style.background = 'var(--color-danger-hover, #dc2626)';
|
||||
};
|
||||
okBtn.onmouseout = () => {
|
||||
okBtn.style.background = 'var(--color-danger-strong, #ef4444)';
|
||||
};
|
||||
} else {
|
||||
okBtn.style.background = 'var(--color-action, #2563eb)';
|
||||
okBtn.onmouseover = () => {
|
||||
okBtn.style.background = 'var(--color-action-hover, #1d4ed8)';
|
||||
};
|
||||
okBtn.onmouseout = () => {
|
||||
okBtn.style.background = 'var(--color-action, #2563eb)';
|
||||
};
|
||||
// Reset ring class in case it was set to danger previously
|
||||
const cls = okBtn.className;
|
||||
if (!cls.includes('focus:ring-blue')) {
|
||||
okBtn.className = cls.replace(/focus:ring-\S+/g, 'focus:ring-blue-300/50');
|
||||
}
|
||||
}
|
||||
|
||||
// Wire up resolve
|
||||
_resolve = resolve;
|
||||
_lastActive = document.activeElement;
|
||||
|
||||
// Re-attach listeners (removes stale ones first)
|
||||
const cancelBtn = document.getElementById('nc-confirm-cancel');
|
||||
const freshCancel = cancelBtn.cloneNode(true);
|
||||
cancelBtn.parentNode.replaceChild(freshCancel, cancelBtn);
|
||||
const freshOk = okBtn.cloneNode(true);
|
||||
okBtn.parentNode.replaceChild(freshOk, okBtn);
|
||||
|
||||
// Re-query after replacement
|
||||
document.getElementById('nc-confirm-cancel').addEventListener('click', () => close(false));
|
||||
document.getElementById('nc-confirm-ok').addEventListener('click', () => close(true));
|
||||
|
||||
document.addEventListener('keydown', onKeyDown);
|
||||
|
||||
dialog.style.display = '';
|
||||
// Move focus to confirm button after paint
|
||||
setTimeout(() => {
|
||||
const btn = document.getElementById('nc-confirm-ok');
|
||||
if (btn) btn.focus();
|
||||
}, 10);
|
||||
});
|
||||
}
|
||||
|
||||
global.NCConfirm = { show };
|
||||
})(window);
|
||||
Reference in new issue
Block a user