@orangecheck/ui 0.9.0 → 0.10.0
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 +66 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/CHANGELOG.md +0 -23
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Boxes, ChevronDown, Check, CornerDownLeft } from 'lucide-react';
|
|
1
|
+
import { Boxes, ChevronDown, Check, CornerDownLeft, Copy } from 'lucide-react';
|
|
2
2
|
import Link5 from 'next/link';
|
|
3
3
|
import { useState, useRef, useEffect, useId } from 'react';
|
|
4
4
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
@@ -526,6 +526,71 @@ function shortenDid(s) {
|
|
|
526
526
|
if (s.length <= 14) return s;
|
|
527
527
|
return `${s.slice(0, 7)}\u2026${s.slice(-5)}`;
|
|
528
528
|
}
|
|
529
|
+
async function writeClipboard(text) {
|
|
530
|
+
try {
|
|
531
|
+
if (navigator.clipboard?.writeText) {
|
|
532
|
+
await navigator.clipboard.writeText(text);
|
|
533
|
+
return true;
|
|
534
|
+
}
|
|
535
|
+
} catch {
|
|
536
|
+
}
|
|
537
|
+
try {
|
|
538
|
+
const ta = document.createElement("textarea");
|
|
539
|
+
ta.value = text;
|
|
540
|
+
ta.setAttribute("readonly", "");
|
|
541
|
+
ta.style.position = "fixed";
|
|
542
|
+
ta.style.top = "-1000px";
|
|
543
|
+
ta.style.opacity = "0";
|
|
544
|
+
document.body.appendChild(ta);
|
|
545
|
+
ta.select();
|
|
546
|
+
const ok = document.execCommand("copy");
|
|
547
|
+
document.body.removeChild(ta);
|
|
548
|
+
return ok;
|
|
549
|
+
} catch {
|
|
550
|
+
return false;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
function CopyableDid({ did }) {
|
|
554
|
+
const [copied, setCopied] = useState(false);
|
|
555
|
+
const timerRef = useRef(null);
|
|
556
|
+
useEffect(
|
|
557
|
+
() => () => {
|
|
558
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
559
|
+
},
|
|
560
|
+
[]
|
|
561
|
+
);
|
|
562
|
+
const onCopy = async () => {
|
|
563
|
+
const ok = await writeClipboard(did);
|
|
564
|
+
if (!ok) return;
|
|
565
|
+
setCopied(true);
|
|
566
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
567
|
+
timerRef.current = setTimeout(() => setCopied(false), 1600);
|
|
568
|
+
};
|
|
569
|
+
return /* @__PURE__ */ jsxs(
|
|
570
|
+
"button",
|
|
571
|
+
{
|
|
572
|
+
type: "button",
|
|
573
|
+
onClick: onCopy,
|
|
574
|
+
"aria-label": copied ? "OrangeCheck identity copied to clipboard" : `Copy OrangeCheck identity ${did} to clipboard`,
|
|
575
|
+
title: "Copy identity",
|
|
576
|
+
"data-oc-account-menu-copy-did": "",
|
|
577
|
+
"data-copied": copied ? "" : void 0,
|
|
578
|
+
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",
|
|
579
|
+
children: [
|
|
580
|
+
/* @__PURE__ */ jsx("span", { className: "text-foreground/90 min-w-0 flex-1 font-mono text-[11px] leading-tight break-all", children: did }),
|
|
581
|
+
/* @__PURE__ */ jsx(
|
|
582
|
+
"span",
|
|
583
|
+
{
|
|
584
|
+
className: "mt-px shrink-0 transition-colors " + (copied ? "text-primary" : "text-muted-foreground/50 group-hover/did:text-foreground/80"),
|
|
585
|
+
"aria-hidden": true,
|
|
586
|
+
children: copied ? /* @__PURE__ */ jsx(Check, { className: "size-3.5" }) : /* @__PURE__ */ jsx(Copy, { className: "size-3.5" })
|
|
587
|
+
}
|
|
588
|
+
),
|
|
589
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", "aria-live": "polite", children: copied ? "Copied to clipboard" : "" })
|
|
590
|
+
]
|
|
591
|
+
}
|
|
592
|
+
);
|
|
593
|
+
}
|
|
529
594
|
function OcAccountMenu(props) {
|
|
530
595
|
const session = useOcSession();
|
|
531
596
|
return /* @__PURE__ */ jsx(
|
|
@@ -669,7 +734,7 @@ function OcAccountMenuView({
|
|
|
669
734
|
"\xA7 signed in \xB7 ",
|
|
670
735
|
hostname
|
|
671
736
|
] }),
|
|
672
|
-
/* @__PURE__ */ jsx(
|
|
737
|
+
/* @__PURE__ */ jsx(CopyableDid, { did: account.didOc }),
|
|
673
738
|
displayName ? /* @__PURE__ */ jsx("div", { className: "text-muted-foreground/80 mt-1 font-mono text-[10px] tracking-wide", children: displayName }) : null
|
|
674
739
|
] }),
|
|
675
740
|
primaryNavLinks && primaryNavLinks.length > 0 ? /* @__PURE__ */ jsx(
|