Files
breadcrumb-the-shire/web/js/components/app-copy-field.js

109 lines
3.4 KiB
JavaScript
Raw Normal View History

feat(addressbook): Stripe-style detail profile — meta chips, always-visible contact stack, copy affordance Refactors the address-book detail partial (templates/partials/app-user-profile.phtml) toward a Stripe/Linear aesthetic: the banner + avatar still carry identity, but the header now also carries meta chips (primary tenant, department, hire date) and primary CTAs (Send email, Call). Email/phone/mobile move out of a tab into an always-visible contact stack directly under the identity block, with icon-led rows and a hover-revealed copy button. Tabs reduce to Address / About / Organization, with Organization only appearing for multi-tenant users — single-tenant assignments are fully communicated through chips. The detail aside is gone; main content is single-column and more focused. Introduces web/js/components/app-copy-field.js — a generic, server- markup-driven copy-to-clipboard button component wired from app-init.js. The markup is rendered by the PHP partial (role-compatible, SSR-safe); the component only attaches the click handler and drives icon-swap feedback via an is-copied class. Address-book index page now loads the 'address-book' CSS group alongside 'address-book-index' so the detail drawer (which mounts the same profile partial inline) gets the correct styles. Contact rows use inline-block + vertical-align centering inside the clickable link; the field-label tooltip lives on a <span> wrapper rather than the <i> itself (Bootstrap icons render their glyph via ::before, and the tooltip rule would otherwise cap it). Hover reveals the copy button on pointer devices; @media (hover: none) shows it permanently on touch. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 22:40:55 +02:00
/**
feat(ui): copyable input partial + dynamic copy-target - New core partial templates/partials/app-input-copy.phtml renders a standard label + input with a compact copy button overlaid on the right edge of the input. Used for privacy/imprint URLs on the tenant form; reusable for any field where a one-click copy is helpful. - Extend the shared copy-field component (web/js/components/app-copy-field.js) with data-copy-target support — the button now reads the target input's .value at click-time, so users can edit a field and still copy the current value. Static data-copy-value keeps working unchanged. - New component CSS web/css/components/app-input-copy.css positions the button absolute/inset + margin-block:auto (robust vertical centering regardless of input height) and uses a descendant selector (0,2,0) so the button wins over the global [data-tooltip] position:relative. - Also register app-input-copy.css + app-tenant-logo.css in core.css @import list — they were only in the shared asset group before, which default-template admin pages don't load, so tenant-logo styles were effectively missing on admin tenant edit (topbar size etc.). - Document the Copy-to-Clipboard + Copyable Input standards in docs/reference-frontend-javascript.md so future consumers don't re-invent the markup/selectors. - File-upload preview: pending-file block restructured to a compact list-item row (small square thumb + filename/size stack + clear X) and removed the transparency checker pattern on the current-image preview in favour of a flat --app-preview-bg surface. - Tenant edit page title + breadcrumb now show the tenant description ("Acme GmbH") instead of the generic "Mandant bearbeiten" when one is present. - i18n: add "Copy to clipboard" / "In Zwischenablage kopieren" across both locales. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 21:26:11 +02:00
* Copy-to-clipboard button click writes a value to the clipboard and swaps
* the button icon to a check for ~1.2s. Self-contained: markup is fully
* rendered server-side, this component only wires the click handler.
feat(addressbook): Stripe-style detail profile — meta chips, always-visible contact stack, copy affordance Refactors the address-book detail partial (templates/partials/app-user-profile.phtml) toward a Stripe/Linear aesthetic: the banner + avatar still carry identity, but the header now also carries meta chips (primary tenant, department, hire date) and primary CTAs (Send email, Call). Email/phone/mobile move out of a tab into an always-visible contact stack directly under the identity block, with icon-led rows and a hover-revealed copy button. Tabs reduce to Address / About / Organization, with Organization only appearing for multi-tenant users — single-tenant assignments are fully communicated through chips. The detail aside is gone; main content is single-column and more focused. Introduces web/js/components/app-copy-field.js — a generic, server- markup-driven copy-to-clipboard button component wired from app-init.js. The markup is rendered by the PHP partial (role-compatible, SSR-safe); the component only attaches the click handler and drives icon-swap feedback via an is-copied class. Address-book index page now loads the 'address-book' CSS group alongside 'address-book-index' so the detail drawer (which mounts the same profile partial inline) gets the correct styles. Contact rows use inline-block + vertical-align centering inside the clickable link; the field-label tooltip lives on a <span> wrapper rather than the <i> itself (Bootstrap icons render their glyph via ::before, and the tooltip rule would otherwise cap it). Hover reveals the copy button on pointer devices; @media (hover: none) shows it permanently on touch. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 22:40:55 +02:00
*
feat(ui): copyable input partial + dynamic copy-target - New core partial templates/partials/app-input-copy.phtml renders a standard label + input with a compact copy button overlaid on the right edge of the input. Used for privacy/imprint URLs on the tenant form; reusable for any field where a one-click copy is helpful. - Extend the shared copy-field component (web/js/components/app-copy-field.js) with data-copy-target support — the button now reads the target input's .value at click-time, so users can edit a field and still copy the current value. Static data-copy-value keeps working unchanged. - New component CSS web/css/components/app-input-copy.css positions the button absolute/inset + margin-block:auto (robust vertical centering regardless of input height) and uses a descendant selector (0,2,0) so the button wins over the global [data-tooltip] position:relative. - Also register app-input-copy.css + app-tenant-logo.css in core.css @import list — they were only in the shared asset group before, which default-template admin pages don't load, so tenant-logo styles were effectively missing on admin tenant edit (topbar size etc.). - Document the Copy-to-Clipboard + Copyable Input standards in docs/reference-frontend-javascript.md so future consumers don't re-invent the markup/selectors. - File-upload preview: pending-file block restructured to a compact list-item row (small square thumb + filename/size stack + clear X) and removed the transparency checker pattern on the current-image preview in favour of a flat --app-preview-bg surface. - Tenant edit page title + breadcrumb now show the tenant description ("Acme GmbH") instead of the generic "Mandant bearbeiten" when one is present. - i18n: add "Copy to clipboard" / "In Zwischenablage kopieren" across both locales. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 21:26:11 +02:00
* Static value (read from the button itself):
* <button type="button" data-copy-button data-copy-value="max@acme.com" ></button>
*
* Live input value (resolved at click-time from the target element's .value):
* <button type="button" data-copy-button data-copy-target="privacy_url" ></button>
feat(addressbook): Stripe-style detail profile — meta chips, always-visible contact stack, copy affordance Refactors the address-book detail partial (templates/partials/app-user-profile.phtml) toward a Stripe/Linear aesthetic: the banner + avatar still carry identity, but the header now also carries meta chips (primary tenant, department, hire date) and primary CTAs (Send email, Call). Email/phone/mobile move out of a tab into an always-visible contact stack directly under the identity block, with icon-led rows and a hover-revealed copy button. Tabs reduce to Address / About / Organization, with Organization only appearing for multi-tenant users — single-tenant assignments are fully communicated through chips. The detail aside is gone; main content is single-column and more focused. Introduces web/js/components/app-copy-field.js — a generic, server- markup-driven copy-to-clipboard button component wired from app-init.js. The markup is rendered by the PHP partial (role-compatible, SSR-safe); the component only attaches the click handler and drives icon-swap feedback via an is-copied class. Address-book index page now loads the 'address-book' CSS group alongside 'address-book-index' so the detail drawer (which mounts the same profile partial inline) gets the correct styles. Contact rows use inline-block + vertical-align centering inside the clickable link; the field-label tooltip lives on a <span> wrapper rather than the <i> itself (Bootstrap icons render their glyph via ::before, and the tooltip rule would otherwise cap it). Hover reveals the copy button on pointer devices; @media (hover: none) shows it permanently on touch. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 22:40:55 +02:00
*/
import { resolveHost } from '../core/app-dom.js';
const BUTTON_SELECTOR = '[data-copy-button]';
const DONE_CLASS = 'is-copied';
const DONE_TIMEOUT_MS = 1200;
const copyText = async (value) => {
if (!value) {return false;}
if (navigator.clipboard?.writeText) {
try {
await navigator.clipboard.writeText(value);
return true;
} catch {
return false;
}
}
const textarea = document.createElement('textarea');
textarea.value = value;
textarea.setAttribute('readonly', 'true');
textarea.style.position = 'fixed';
textarea.style.opacity = '0';
document.body.appendChild(textarea);
textarea.select();
let ok = false;
try {
ok = document.execCommand('copy');
} catch {
ok = false;
}
document.body.removeChild(textarea);
return ok;
};
export function initCopyField(root = document, options = {}) {
const selector = String(options.selector || BUTTON_SELECTOR).trim() || BUTTON_SELECTOR;
const host = resolveHost(root);
const buttons = Array.from(host.querySelectorAll(selector));
if (!buttons.length) {
return { destroy: () => {} };
}
const cleanupFns = [];
const timers = new Map();
buttons.forEach((button) => {
if (!(button instanceof HTMLElement) || button.dataset.copyButtonBound === '1') {
return;
}
button.dataset.copyButtonBound = '1';
// Clipboard API is unavailable in insecure contexts (http without localhost)
// and the execCommand fallback is deprecated. If neither is usable, hide
// the button entirely rather than show a non-functional control.
const clipboardUsable = typeof navigator.clipboard?.writeText === 'function'
|| typeof document.execCommand === 'function';
if (!clipboardUsable) {
button.hidden = true;
return;
}
const onClick = async (event) => {
event.preventDefault();
feat(ui): copyable input partial + dynamic copy-target - New core partial templates/partials/app-input-copy.phtml renders a standard label + input with a compact copy button overlaid on the right edge of the input. Used for privacy/imprint URLs on the tenant form; reusable for any field where a one-click copy is helpful. - Extend the shared copy-field component (web/js/components/app-copy-field.js) with data-copy-target support — the button now reads the target input's .value at click-time, so users can edit a field and still copy the current value. Static data-copy-value keeps working unchanged. - New component CSS web/css/components/app-input-copy.css positions the button absolute/inset + margin-block:auto (robust vertical centering regardless of input height) and uses a descendant selector (0,2,0) so the button wins over the global [data-tooltip] position:relative. - Also register app-input-copy.css + app-tenant-logo.css in core.css @import list — they were only in the shared asset group before, which default-template admin pages don't load, so tenant-logo styles were effectively missing on admin tenant edit (topbar size etc.). - Document the Copy-to-Clipboard + Copyable Input standards in docs/reference-frontend-javascript.md so future consumers don't re-invent the markup/selectors. - File-upload preview: pending-file block restructured to a compact list-item row (small square thumb + filename/size stack + clear X) and removed the transparency checker pattern on the current-image preview in favour of a flat --app-preview-bg surface. - Tenant edit page title + breadcrumb now show the tenant description ("Acme GmbH") instead of the generic "Mandant bearbeiten" when one is present. - i18n: add "Copy to clipboard" / "In Zwischenablage kopieren" across both locales. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 21:26:11 +02:00
const targetId = (button.dataset.copyTarget || '').trim();
let value = button.dataset.copyValue || '';
if (targetId) {
const target = document.getElementById(targetId);
if (target && 'value' in target) {
value = /** @type {HTMLInputElement} */ (target).value;
}
}
feat(addressbook): Stripe-style detail profile — meta chips, always-visible contact stack, copy affordance Refactors the address-book detail partial (templates/partials/app-user-profile.phtml) toward a Stripe/Linear aesthetic: the banner + avatar still carry identity, but the header now also carries meta chips (primary tenant, department, hire date) and primary CTAs (Send email, Call). Email/phone/mobile move out of a tab into an always-visible contact stack directly under the identity block, with icon-led rows and a hover-revealed copy button. Tabs reduce to Address / About / Organization, with Organization only appearing for multi-tenant users — single-tenant assignments are fully communicated through chips. The detail aside is gone; main content is single-column and more focused. Introduces web/js/components/app-copy-field.js — a generic, server- markup-driven copy-to-clipboard button component wired from app-init.js. The markup is rendered by the PHP partial (role-compatible, SSR-safe); the component only attaches the click handler and drives icon-swap feedback via an is-copied class. Address-book index page now loads the 'address-book' CSS group alongside 'address-book-index' so the detail drawer (which mounts the same profile partial inline) gets the correct styles. Contact rows use inline-block + vertical-align centering inside the clickable link; the field-label tooltip lives on a <span> wrapper rather than the <i> itself (Bootstrap icons render their glyph via ::before, and the tooltip rule would otherwise cap it). Hover reveals the copy button on pointer devices; @media (hover: none) shows it permanently on touch. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 22:40:55 +02:00
const ok = await copyText(value);
if (!ok) {return;}
button.classList.add(DONE_CLASS);
const prevTimer = timers.get(button);
if (prevTimer) {window.clearTimeout(prevTimer);}
const timer = window.setTimeout(() => {
button.classList.remove(DONE_CLASS);
timers.delete(button);
}, DONE_TIMEOUT_MS);
timers.set(button, timer);
};
button.addEventListener('click', onClick);
cleanupFns.push(() => {
button.removeEventListener('click', onClick);
delete button.dataset.copyButtonBound;
});
});
const destroy = () => {
cleanupFns.forEach((fn) => fn());
timers.forEach((timer) => window.clearTimeout(timer));
timers.clear();
};
return { destroy };
}