@orangecheck/ui 0.9.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -532,6 +532,71 @@ function shortenDid(s) {
532
532
  if (s.length <= 14) return s;
533
533
  return `${s.slice(0, 7)}\u2026${s.slice(-5)}`;
534
534
  }
535
+ async function writeClipboard(text) {
536
+ try {
537
+ if (navigator.clipboard?.writeText) {
538
+ await navigator.clipboard.writeText(text);
539
+ return true;
540
+ }
541
+ } catch {
542
+ }
543
+ try {
544
+ const ta = document.createElement("textarea");
545
+ ta.value = text;
546
+ ta.setAttribute("readonly", "");
547
+ ta.style.position = "fixed";
548
+ ta.style.top = "-1000px";
549
+ ta.style.opacity = "0";
550
+ document.body.appendChild(ta);
551
+ ta.select();
552
+ const ok = document.execCommand("copy");
553
+ document.body.removeChild(ta);
554
+ return ok;
555
+ } catch {
556
+ return false;
557
+ }
558
+ }
559
+ function CopyableDid({ did }) {
560
+ const [copied, setCopied] = react.useState(false);
561
+ const timerRef = react.useRef(null);
562
+ react.useEffect(
563
+ () => () => {
564
+ if (timerRef.current) clearTimeout(timerRef.current);
565
+ },
566
+ []
567
+ );
568
+ const onCopy = async () => {
569
+ const ok = await writeClipboard(did);
570
+ if (!ok) return;
571
+ setCopied(true);
572
+ if (timerRef.current) clearTimeout(timerRef.current);
573
+ timerRef.current = setTimeout(() => setCopied(false), 1600);
574
+ };
575
+ return /* @__PURE__ */ jsxRuntime.jsxs(
576
+ "button",
577
+ {
578
+ type: "button",
579
+ onClick: onCopy,
580
+ "aria-label": copied ? "OrangeCheck identity copied to clipboard" : `Copy OrangeCheck identity ${did} to clipboard`,
581
+ title: "Copy identity",
582
+ "data-oc-account-menu-copy-did": "",
583
+ "data-copied": copied ? "" : void 0,
584
+ className: "group/did hover:bg-accent focus-visible:ring-ring/60 -mx-1.5 mt-px flex w-[calc(100%+0.75rem)] items-start gap-1.5 rounded px-1.5 py-1 text-left transition-colors focus-visible:ring-2 focus-visible:outline-none",
585
+ children: [
586
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-foreground/90 min-w-0 flex-1 font-mono text-[11px] leading-tight break-all", children: did }),
587
+ /* @__PURE__ */ jsxRuntime.jsx(
588
+ "span",
589
+ {
590
+ className: "mt-px shrink-0 transition-colors " + (copied ? "text-primary" : "text-muted-foreground/50 group-hover/did:text-foreground/80"),
591
+ "aria-hidden": true,
592
+ children: copied ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: "size-3.5" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Copy, { className: "size-3.5" })
593
+ }
594
+ ),
595
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", "aria-live": "polite", children: copied ? "Copied to clipboard" : "" })
596
+ ]
597
+ }
598
+ );
599
+ }
535
600
  function OcAccountMenu(props) {
536
601
  const session = authClient.useOcSession();
537
602
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -667,7 +732,7 @@ function OcAccountMenuView({
667
732
  {
668
733
  role: "menu",
669
734
  "aria-label": "Account menu",
670
- className: popoverClassName ?? "border-border bg-popover text-popover-foreground absolute top-[calc(100%+6px)] right-0 z-50 w-[min(18rem,calc(100vw-1rem))] border shadow-xl",
735
+ className: popoverClassName ?? "border-border bg-popover text-popover-foreground absolute top-[calc(100%+6px)] right-0 z-50 w-[min(20rem,calc(100vw-1rem))] border shadow-xl",
671
736
  "data-oc-account-menu-popover": "",
672
737
  children: [
673
738
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "border-border border-b p-3", children: [
@@ -675,7 +740,7 @@ function OcAccountMenuView({
675
740
  "\xA7 signed in \xB7 ",
676
741
  hostname
677
742
  ] }),
678
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-foreground/90 font-mono text-[11px] leading-tight break-all", children: account.didOc }),
743
+ /* @__PURE__ */ jsxRuntime.jsx(CopyableDid, { did: account.didOc }),
679
744
  displayName ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-muted-foreground/80 mt-1 font-mono text-[10px] tracking-wide", children: displayName }) : null
680
745
  ] }),
681
746
  primaryNavLinks && primaryNavLinks.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(