@orangecheck/auth-client 2.33.4 → 2.35.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/appearance.mjs +23 -0
- package/dist/appearance.mjs.map +1 -0
- package/dist/bond.mjs +20 -0
- package/dist/bond.mjs.map +1 -0
- package/dist/chunk-4E7GJ5IB.mjs +1184 -0
- package/dist/chunk-4E7GJ5IB.mjs.map +1 -0
- package/dist/chunk-7ST4Q5KR.mjs +346 -0
- package/dist/chunk-7ST4Q5KR.mjs.map +1 -0
- package/dist/chunk-7UYPMTAV.mjs +652 -0
- package/dist/chunk-7UYPMTAV.mjs.map +1 -0
- package/dist/chunk-BYAF2P2L.mjs +253 -0
- package/dist/chunk-BYAF2P2L.mjs.map +1 -0
- package/dist/chunk-CYR7J4UY.mjs +118 -0
- package/dist/chunk-CYR7J4UY.mjs.map +1 -0
- package/dist/chunk-H2TXOCXH.mjs +23 -0
- package/dist/chunk-H2TXOCXH.mjs.map +1 -0
- package/dist/chunk-HZ4FJMF3.mjs +490 -0
- package/dist/chunk-HZ4FJMF3.mjs.map +1 -0
- package/dist/chunk-TJJNTITX.mjs +187 -0
- package/dist/chunk-TJJNTITX.mjs.map +1 -0
- package/dist/chunk-UFRU3I3D.mjs +913 -0
- package/dist/chunk-UFRU3I3D.mjs.map +1 -0
- package/dist/chunk-VRLFZAGK.mjs +37 -0
- package/dist/chunk-VRLFZAGK.mjs.map +1 -0
- package/dist/chunk-XCZVSE7M.mjs +40 -0
- package/dist/chunk-XCZVSE7M.mjs.map +1 -0
- package/dist/components.mjs +19 -0
- package/dist/components.mjs.map +1 -0
- package/dist/index.js +77 -67
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +112 -4001
- package/dist/index.mjs.map +1 -1
- package/dist/linked-identities.mjs +41 -0
- package/dist/linked-identities.mjs.map +1 -0
- package/dist/provider.mjs +17 -0
- package/dist/provider.mjs.map +1 -0
- package/dist/return-to.mjs +18 -0
- package/dist/return-to.mjs.map +1 -0
- package/dist/signin.mjs +23 -0
- package/dist/signin.mjs.map +1 -0
- package/dist/sudo.mjs +16 -0
- package/dist/sudo.mjs.map +1 -0
- package/dist/tab-session.mjs +29 -0
- package/dist/tab-session.mjs.map +1 -0
- package/dist/types.mjs +17 -0
- package/dist/types.mjs.map +1 -0
- package/dist/webauthn.mjs +15 -0
- package/dist/webauthn.mjs.map +1 -0
- package/package.json +2 -1
- package/dist/index.d.mts +0 -303
|
@@ -0,0 +1,652 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useOcSession
|
|
3
|
+
} from "./chunk-7ST4Q5KR.mjs";
|
|
4
|
+
|
|
5
|
+
// src/components.tsx
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
function shortenAddress(addr) {
|
|
9
|
+
if (addr.length <= 12) return addr;
|
|
10
|
+
return `${addr.slice(0, 6)}\u2026${addr.slice(-4)}`;
|
|
11
|
+
}
|
|
12
|
+
function shortenAddressMid(addr) {
|
|
13
|
+
if (addr.length <= 16) return addr;
|
|
14
|
+
return `${addr.slice(0, 8)}\u2026${addr.slice(-6)}`;
|
|
15
|
+
}
|
|
16
|
+
function isPrefixOf(value, target) {
|
|
17
|
+
return target.toLowerCase().startsWith(value.toLowerCase());
|
|
18
|
+
}
|
|
19
|
+
var listboxIdCounter = 0;
|
|
20
|
+
function useUniqueId(prefix) {
|
|
21
|
+
const [id] = React.useState(() => `${prefix}-${++listboxIdCounter}`);
|
|
22
|
+
return id;
|
|
23
|
+
}
|
|
24
|
+
function OcAccountChip({
|
|
25
|
+
dashboardUrl = "https://ochk.io/dashboard",
|
|
26
|
+
signInUrl: signInUrlOverride,
|
|
27
|
+
signInLabel = "sign in",
|
|
28
|
+
className,
|
|
29
|
+
triggerClassName,
|
|
30
|
+
popoverClassName,
|
|
31
|
+
menuItemClassName
|
|
32
|
+
}) {
|
|
33
|
+
const { status, account, signInUrl: sessionSignInUrl, signOut } = useOcSession();
|
|
34
|
+
const signInUrl = signInUrlOverride ?? sessionSignInUrl;
|
|
35
|
+
const [open, setOpen] = React.useState(false);
|
|
36
|
+
const wrapRef = React.useRef(null);
|
|
37
|
+
React.useEffect(() => {
|
|
38
|
+
if (!open) return;
|
|
39
|
+
function handleClickOutside(e) {
|
|
40
|
+
if (wrapRef.current && !wrapRef.current.contains(e.target)) {
|
|
41
|
+
setOpen(false);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function handleEscape(e) {
|
|
45
|
+
if (e.key === "Escape") setOpen(false);
|
|
46
|
+
}
|
|
47
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
48
|
+
document.addEventListener("keydown", handleEscape);
|
|
49
|
+
return () => {
|
|
50
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
51
|
+
document.removeEventListener("keydown", handleEscape);
|
|
52
|
+
};
|
|
53
|
+
}, [open]);
|
|
54
|
+
if (status === "loading") return null;
|
|
55
|
+
if (status !== "authenticated" || !account) {
|
|
56
|
+
return /* @__PURE__ */ jsx(
|
|
57
|
+
"a",
|
|
58
|
+
{
|
|
59
|
+
href: signInUrl,
|
|
60
|
+
className: triggerClassName ?? className,
|
|
61
|
+
"data-oc-account-chip-signin": "",
|
|
62
|
+
children: signInLabel
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
return /* @__PURE__ */ jsxs(
|
|
67
|
+
"div",
|
|
68
|
+
{
|
|
69
|
+
ref: wrapRef,
|
|
70
|
+
className,
|
|
71
|
+
"data-oc-account-chip": "",
|
|
72
|
+
style: { position: "relative", display: "inline-block" },
|
|
73
|
+
children: [
|
|
74
|
+
/* @__PURE__ */ jsxs(
|
|
75
|
+
"button",
|
|
76
|
+
{
|
|
77
|
+
type: "button",
|
|
78
|
+
onClick: () => setOpen((v) => !v),
|
|
79
|
+
"aria-haspopup": "menu",
|
|
80
|
+
"aria-expanded": open,
|
|
81
|
+
"aria-label": `Signed in as ${account.didOc}. Open account menu.`,
|
|
82
|
+
className: triggerClassName,
|
|
83
|
+
"data-oc-account-chip-trigger": "",
|
|
84
|
+
style: triggerClassName ? void 0 : {
|
|
85
|
+
display: "inline-flex",
|
|
86
|
+
alignItems: "center",
|
|
87
|
+
gap: "0.4rem",
|
|
88
|
+
padding: "0.25rem 0.625rem",
|
|
89
|
+
borderRadius: "9999px",
|
|
90
|
+
border: "1px solid var(--border, #27272a)",
|
|
91
|
+
background: "color-mix(in oklch, var(--muted, #27272a) 40%, transparent)",
|
|
92
|
+
color: "var(--foreground, #fafafa)",
|
|
93
|
+
fontFamily: "ui-monospace, SFMono-Regular, monospace",
|
|
94
|
+
fontSize: 12,
|
|
95
|
+
cursor: "pointer"
|
|
96
|
+
},
|
|
97
|
+
children: [
|
|
98
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", style: { color: "#22c55e", fontSize: 8 }, children: "\u25CF" }),
|
|
99
|
+
/* @__PURE__ */ jsx("span", { children: account.displayName ?? shortenAddress(account.didOc) }),
|
|
100
|
+
/* @__PURE__ */ jsx(
|
|
101
|
+
"svg",
|
|
102
|
+
{
|
|
103
|
+
width: "9",
|
|
104
|
+
height: "9",
|
|
105
|
+
viewBox: "0 0 10 10",
|
|
106
|
+
"aria-hidden": "true",
|
|
107
|
+
style: {
|
|
108
|
+
transition: "transform 120ms",
|
|
109
|
+
transform: open ? "rotate(180deg)" : "rotate(0)",
|
|
110
|
+
opacity: 0.6
|
|
111
|
+
},
|
|
112
|
+
children: /* @__PURE__ */ jsx(
|
|
113
|
+
"path",
|
|
114
|
+
{
|
|
115
|
+
d: "M2 4 L5 7 L8 4",
|
|
116
|
+
stroke: "currentColor",
|
|
117
|
+
strokeWidth: "1.5",
|
|
118
|
+
fill: "none",
|
|
119
|
+
strokeLinecap: "round"
|
|
120
|
+
}
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
]
|
|
125
|
+
}
|
|
126
|
+
),
|
|
127
|
+
open && /* @__PURE__ */ jsxs(
|
|
128
|
+
"div",
|
|
129
|
+
{
|
|
130
|
+
role: "menu",
|
|
131
|
+
"aria-label": "Account menu",
|
|
132
|
+
className: popoverClassName,
|
|
133
|
+
"data-oc-account-chip-popover": "",
|
|
134
|
+
style: popoverClassName ? { position: "absolute", zIndex: 50, top: "calc(100% + 6px)", right: 0 } : {
|
|
135
|
+
position: "absolute",
|
|
136
|
+
zIndex: 50,
|
|
137
|
+
top: "calc(100% + 6px)",
|
|
138
|
+
right: 0,
|
|
139
|
+
minWidth: 240,
|
|
140
|
+
background: "var(--popover, #0a0a0a)",
|
|
141
|
+
color: "var(--popover-foreground, #fafafa)",
|
|
142
|
+
border: "1px solid var(--border, #27272a)",
|
|
143
|
+
boxShadow: "0 10px 32px -4px rgba(0,0,0,0.35)",
|
|
144
|
+
fontFamily: "ui-monospace, SFMono-Regular, monospace"
|
|
145
|
+
},
|
|
146
|
+
children: [
|
|
147
|
+
/* @__PURE__ */ jsxs(
|
|
148
|
+
"div",
|
|
149
|
+
{
|
|
150
|
+
"data-oc-account-chip-header": "",
|
|
151
|
+
style: {
|
|
152
|
+
padding: "0.75rem 0.75rem 0.625rem",
|
|
153
|
+
borderBottom: "1px solid var(--border, #27272a)"
|
|
154
|
+
},
|
|
155
|
+
children: [
|
|
156
|
+
/* @__PURE__ */ jsx(
|
|
157
|
+
"div",
|
|
158
|
+
{
|
|
159
|
+
"data-oc-account-chip-label": "",
|
|
160
|
+
style: {
|
|
161
|
+
color: "var(--primary, #f97316)",
|
|
162
|
+
fontSize: 10,
|
|
163
|
+
letterSpacing: "0.18em",
|
|
164
|
+
textTransform: "uppercase",
|
|
165
|
+
marginBottom: 4
|
|
166
|
+
},
|
|
167
|
+
children: "\xA7 signed in"
|
|
168
|
+
}
|
|
169
|
+
),
|
|
170
|
+
/* @__PURE__ */ jsx(
|
|
171
|
+
"div",
|
|
172
|
+
{
|
|
173
|
+
"data-oc-account-chip-address": "",
|
|
174
|
+
style: {
|
|
175
|
+
color: "var(--popover-foreground, #fafafa)",
|
|
176
|
+
fontSize: 11,
|
|
177
|
+
wordBreak: "break-all",
|
|
178
|
+
lineHeight: 1.35
|
|
179
|
+
},
|
|
180
|
+
children: account.didOc
|
|
181
|
+
}
|
|
182
|
+
),
|
|
183
|
+
account.displayName ? /* @__PURE__ */ jsx(
|
|
184
|
+
"div",
|
|
185
|
+
{
|
|
186
|
+
style: {
|
|
187
|
+
color: "var(--muted-foreground, #a1a1aa)",
|
|
188
|
+
fontSize: 10,
|
|
189
|
+
marginTop: 4,
|
|
190
|
+
letterSpacing: "0.06em"
|
|
191
|
+
},
|
|
192
|
+
children: account.displayName
|
|
193
|
+
}
|
|
194
|
+
) : null
|
|
195
|
+
]
|
|
196
|
+
}
|
|
197
|
+
),
|
|
198
|
+
/* @__PURE__ */ jsxs("div", { role: "none", style: { padding: "0.25rem" }, children: [
|
|
199
|
+
dashboardUrl ? /* @__PURE__ */ jsxs(
|
|
200
|
+
"a",
|
|
201
|
+
{
|
|
202
|
+
role: "menuitem",
|
|
203
|
+
href: dashboardUrl,
|
|
204
|
+
onClick: () => setOpen(false),
|
|
205
|
+
className: menuItemClassName,
|
|
206
|
+
"data-oc-account-chip-item": "",
|
|
207
|
+
style: menuItemClassName ? void 0 : {
|
|
208
|
+
display: "flex",
|
|
209
|
+
alignItems: "center",
|
|
210
|
+
gap: "0.5rem",
|
|
211
|
+
padding: "0.5rem 0.625rem",
|
|
212
|
+
fontSize: 12,
|
|
213
|
+
color: "var(--popover-foreground, #fafafa)",
|
|
214
|
+
textDecoration: "none",
|
|
215
|
+
cursor: "pointer"
|
|
216
|
+
},
|
|
217
|
+
children: [
|
|
218
|
+
/* @__PURE__ */ jsx(
|
|
219
|
+
"span",
|
|
220
|
+
{
|
|
221
|
+
"aria-hidden": "true",
|
|
222
|
+
style: { color: "var(--muted-foreground, #a1a1aa)" },
|
|
223
|
+
children: "\u2192"
|
|
224
|
+
}
|
|
225
|
+
),
|
|
226
|
+
/* @__PURE__ */ jsx("span", { style: { flex: 1 }, children: "dashboard" }),
|
|
227
|
+
/* @__PURE__ */ jsx(
|
|
228
|
+
"span",
|
|
229
|
+
{
|
|
230
|
+
style: {
|
|
231
|
+
color: "var(--muted-foreground, #a1a1aa)",
|
|
232
|
+
fontSize: 10
|
|
233
|
+
},
|
|
234
|
+
children: "\u2197"
|
|
235
|
+
}
|
|
236
|
+
)
|
|
237
|
+
]
|
|
238
|
+
}
|
|
239
|
+
) : null,
|
|
240
|
+
/* @__PURE__ */ jsxs(
|
|
241
|
+
"button",
|
|
242
|
+
{
|
|
243
|
+
type: "button",
|
|
244
|
+
role: "menuitem",
|
|
245
|
+
onClick: () => {
|
|
246
|
+
setOpen(false);
|
|
247
|
+
void signOut();
|
|
248
|
+
},
|
|
249
|
+
className: menuItemClassName,
|
|
250
|
+
"data-oc-account-chip-item": "",
|
|
251
|
+
"data-oc-account-chip-signout": "",
|
|
252
|
+
style: menuItemClassName ? void 0 : {
|
|
253
|
+
display: "flex",
|
|
254
|
+
alignItems: "center",
|
|
255
|
+
gap: "0.5rem",
|
|
256
|
+
width: "100%",
|
|
257
|
+
padding: "0.5rem 0.625rem",
|
|
258
|
+
fontSize: 12,
|
|
259
|
+
color: "var(--popover-foreground, #fafafa)",
|
|
260
|
+
background: "transparent",
|
|
261
|
+
border: 0,
|
|
262
|
+
fontFamily: "inherit",
|
|
263
|
+
textAlign: "left",
|
|
264
|
+
cursor: "pointer"
|
|
265
|
+
},
|
|
266
|
+
children: [
|
|
267
|
+
/* @__PURE__ */ jsx(
|
|
268
|
+
"span",
|
|
269
|
+
{
|
|
270
|
+
"aria-hidden": "true",
|
|
271
|
+
style: { color: "var(--muted-foreground, #a1a1aa)" },
|
|
272
|
+
children: "\u2192"
|
|
273
|
+
}
|
|
274
|
+
),
|
|
275
|
+
/* @__PURE__ */ jsx("span", { style: { flex: 1 }, children: "sign out" })
|
|
276
|
+
]
|
|
277
|
+
}
|
|
278
|
+
)
|
|
279
|
+
] })
|
|
280
|
+
]
|
|
281
|
+
}
|
|
282
|
+
)
|
|
283
|
+
]
|
|
284
|
+
}
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
function OcSignInButton({
|
|
288
|
+
label = "sign in",
|
|
289
|
+
eager = false,
|
|
290
|
+
className,
|
|
291
|
+
signInUrl: signInUrlOverride,
|
|
292
|
+
...rest
|
|
293
|
+
}) {
|
|
294
|
+
const { status, signInUrl: sessionSignInUrl } = useOcSession();
|
|
295
|
+
const href = signInUrlOverride ?? sessionSignInUrl;
|
|
296
|
+
if (status === "authenticated") return null;
|
|
297
|
+
if (!eager && status === "loading") return null;
|
|
298
|
+
return /* @__PURE__ */ jsx(
|
|
299
|
+
"a",
|
|
300
|
+
{
|
|
301
|
+
...rest,
|
|
302
|
+
href,
|
|
303
|
+
className,
|
|
304
|
+
"data-oc-sign-in-button": "",
|
|
305
|
+
children: label
|
|
306
|
+
}
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
function OcAccountPill({
|
|
310
|
+
dashboardUrl,
|
|
311
|
+
render,
|
|
312
|
+
className,
|
|
313
|
+
...rest
|
|
314
|
+
}) {
|
|
315
|
+
const { status, account, signOut } = useOcSession();
|
|
316
|
+
if (status !== "authenticated" || !account) return null;
|
|
317
|
+
const label = render ? render({ address: account.didOc, displayName: account.displayName }) : account.displayName ?? shortenAddress(account.didOc);
|
|
318
|
+
return /* @__PURE__ */ jsxs(
|
|
319
|
+
"div",
|
|
320
|
+
{
|
|
321
|
+
...rest,
|
|
322
|
+
className,
|
|
323
|
+
"data-oc-account-pill": "",
|
|
324
|
+
style: { display: "inline-flex", alignItems: "center", gap: "0.5rem", ...rest.style ?? {} },
|
|
325
|
+
children: [
|
|
326
|
+
dashboardUrl ? /* @__PURE__ */ jsx("a", { href: dashboardUrl, children: label }) : /* @__PURE__ */ jsx("span", { children: label }),
|
|
327
|
+
/* @__PURE__ */ jsx(
|
|
328
|
+
"button",
|
|
329
|
+
{
|
|
330
|
+
type: "button",
|
|
331
|
+
onClick: () => {
|
|
332
|
+
void signOut();
|
|
333
|
+
},
|
|
334
|
+
"aria-label": "Sign out",
|
|
335
|
+
style: {
|
|
336
|
+
background: "none",
|
|
337
|
+
border: "none",
|
|
338
|
+
cursor: "pointer",
|
|
339
|
+
color: "inherit",
|
|
340
|
+
font: "inherit",
|
|
341
|
+
padding: 0
|
|
342
|
+
},
|
|
343
|
+
children: "sign out"
|
|
344
|
+
}
|
|
345
|
+
)
|
|
346
|
+
]
|
|
347
|
+
}
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
function accountAddress(account) {
|
|
351
|
+
if (account?.primaryBtc) return account.primaryBtc;
|
|
352
|
+
return account?.displayIdentity?.kind === "btc" ? account.displayIdentity.value : null;
|
|
353
|
+
}
|
|
354
|
+
function useOcAddressSuggestion(options) {
|
|
355
|
+
const {
|
|
356
|
+
value,
|
|
357
|
+
onValueChange,
|
|
358
|
+
suggestionLabel = "use your address",
|
|
359
|
+
popoverClassName,
|
|
360
|
+
suggestionClassName
|
|
361
|
+
} = options;
|
|
362
|
+
const { status, account } = useOcSession();
|
|
363
|
+
const sessionAddress = status === "authenticated" ? accountAddress(account) : null;
|
|
364
|
+
const [open, setOpen] = React.useState(false);
|
|
365
|
+
const [highlighted, setHighlighted] = React.useState(false);
|
|
366
|
+
const blurTimer = React.useRef(null);
|
|
367
|
+
const listboxId = useUniqueId("oc-addr-listbox");
|
|
368
|
+
const optionId = `${listboxId}-opt`;
|
|
369
|
+
const valueMatchesSession = sessionAddress != null && value.toLowerCase() === sessionAddress.toLowerCase();
|
|
370
|
+
const canSuggest = sessionAddress != null && sessionAddress.length > 0 && !valueMatchesSession && isPrefixOf(value, sessionAddress);
|
|
371
|
+
const showPopover = open && canSuggest;
|
|
372
|
+
function selectSuggestion() {
|
|
373
|
+
if (!sessionAddress) return;
|
|
374
|
+
onValueChange(sessionAddress);
|
|
375
|
+
setOpen(false);
|
|
376
|
+
setHighlighted(false);
|
|
377
|
+
}
|
|
378
|
+
React.useEffect(() => {
|
|
379
|
+
return () => {
|
|
380
|
+
if (blurTimer.current != null) window.clearTimeout(blurTimer.current);
|
|
381
|
+
};
|
|
382
|
+
}, []);
|
|
383
|
+
const inputProps = {
|
|
384
|
+
onFocus: () => {
|
|
385
|
+
if (blurTimer.current != null) {
|
|
386
|
+
window.clearTimeout(blurTimer.current);
|
|
387
|
+
blurTimer.current = null;
|
|
388
|
+
}
|
|
389
|
+
setOpen(true);
|
|
390
|
+
},
|
|
391
|
+
onBlur: () => {
|
|
392
|
+
blurTimer.current = window.setTimeout(() => {
|
|
393
|
+
setOpen(false);
|
|
394
|
+
setHighlighted(false);
|
|
395
|
+
}, 120);
|
|
396
|
+
},
|
|
397
|
+
onKeyDown: (e) => {
|
|
398
|
+
if (!showPopover) return;
|
|
399
|
+
if (e.key === "ArrowDown") {
|
|
400
|
+
e.preventDefault();
|
|
401
|
+
setHighlighted(true);
|
|
402
|
+
} else if (e.key === "ArrowUp") {
|
|
403
|
+
e.preventDefault();
|
|
404
|
+
setHighlighted(false);
|
|
405
|
+
} else if (e.key === "Escape") {
|
|
406
|
+
e.preventDefault();
|
|
407
|
+
setOpen(false);
|
|
408
|
+
setHighlighted(false);
|
|
409
|
+
} else if (e.key === "Enter" && highlighted) {
|
|
410
|
+
e.preventDefault();
|
|
411
|
+
selectSuggestion();
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
role: "combobox",
|
|
415
|
+
"aria-haspopup": "listbox",
|
|
416
|
+
"aria-expanded": showPopover,
|
|
417
|
+
"aria-controls": showPopover ? listboxId : void 0,
|
|
418
|
+
"aria-activedescendant": highlighted ? optionId : void 0,
|
|
419
|
+
autoComplete: "off",
|
|
420
|
+
spellCheck: false
|
|
421
|
+
};
|
|
422
|
+
const popover = showPopover && sessionAddress ? /* @__PURE__ */ jsx(
|
|
423
|
+
"div",
|
|
424
|
+
{
|
|
425
|
+
id: listboxId,
|
|
426
|
+
role: "listbox",
|
|
427
|
+
"data-oc-address-popover": "",
|
|
428
|
+
className: popoverClassName,
|
|
429
|
+
style: {
|
|
430
|
+
position: "absolute",
|
|
431
|
+
zIndex: 50,
|
|
432
|
+
top: "calc(100% + 4px)",
|
|
433
|
+
left: 0,
|
|
434
|
+
right: 0
|
|
435
|
+
},
|
|
436
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
437
|
+
children: /* @__PURE__ */ jsxs(
|
|
438
|
+
"button",
|
|
439
|
+
{
|
|
440
|
+
type: "button",
|
|
441
|
+
id: optionId,
|
|
442
|
+
role: "option",
|
|
443
|
+
"aria-selected": highlighted,
|
|
444
|
+
"data-oc-address-suggestion": "",
|
|
445
|
+
"data-highlighted": highlighted ? "" : void 0,
|
|
446
|
+
className: suggestionClassName,
|
|
447
|
+
onClick: selectSuggestion,
|
|
448
|
+
onMouseEnter: () => setHighlighted(true),
|
|
449
|
+
onMouseLeave: () => setHighlighted(false),
|
|
450
|
+
style: {
|
|
451
|
+
display: "flex",
|
|
452
|
+
alignItems: "center",
|
|
453
|
+
justifyContent: "space-between",
|
|
454
|
+
gap: "0.75rem",
|
|
455
|
+
width: "100%",
|
|
456
|
+
textAlign: "left",
|
|
457
|
+
cursor: "pointer",
|
|
458
|
+
font: "inherit",
|
|
459
|
+
background: "inherit",
|
|
460
|
+
color: "inherit",
|
|
461
|
+
border: 0,
|
|
462
|
+
padding: "inherit"
|
|
463
|
+
},
|
|
464
|
+
children: [
|
|
465
|
+
/* @__PURE__ */ jsx("span", { "data-oc-address-suggestion-label": "", children: suggestionLabel }),
|
|
466
|
+
/* @__PURE__ */ jsx(
|
|
467
|
+
"span",
|
|
468
|
+
{
|
|
469
|
+
"data-oc-address-suggestion-value": "",
|
|
470
|
+
style: { fontFamily: "ui-monospace, monospace" },
|
|
471
|
+
children: shortenAddressMid(sessionAddress)
|
|
472
|
+
}
|
|
473
|
+
)
|
|
474
|
+
]
|
|
475
|
+
}
|
|
476
|
+
)
|
|
477
|
+
}
|
|
478
|
+
) : null;
|
|
479
|
+
return { inputProps, popover };
|
|
480
|
+
}
|
|
481
|
+
var OcAddressInput = React.forwardRef(
|
|
482
|
+
function OcAddressInput2({
|
|
483
|
+
value,
|
|
484
|
+
onValueChange,
|
|
485
|
+
suggestionLabel = "use your address",
|
|
486
|
+
wrapperClassName,
|
|
487
|
+
popoverClassName,
|
|
488
|
+
suggestionClassName,
|
|
489
|
+
onFocus,
|
|
490
|
+
onBlur,
|
|
491
|
+
onKeyDown,
|
|
492
|
+
...rest
|
|
493
|
+
}, forwardedRef) {
|
|
494
|
+
const { status, account } = useOcSession();
|
|
495
|
+
const sessionAddress = status === "authenticated" ? accountAddress(account) : null;
|
|
496
|
+
const [open, setOpen] = React.useState(false);
|
|
497
|
+
const [highlighted, setHighlighted] = React.useState(false);
|
|
498
|
+
const innerRef = React.useRef(null);
|
|
499
|
+
const setRef = (node) => {
|
|
500
|
+
innerRef.current = node;
|
|
501
|
+
if (typeof forwardedRef === "function") forwardedRef(node);
|
|
502
|
+
else if (forwardedRef) forwardedRef.current = node;
|
|
503
|
+
};
|
|
504
|
+
const blurTimer = React.useRef(null);
|
|
505
|
+
const listboxId = useUniqueId("oc-addr-listbox");
|
|
506
|
+
const optionId = `${listboxId}-opt`;
|
|
507
|
+
const valueMatchesSession = sessionAddress != null && value.toLowerCase() === sessionAddress.toLowerCase();
|
|
508
|
+
const canSuggest = sessionAddress != null && sessionAddress.length > 0 && !valueMatchesSession && isPrefixOf(value, sessionAddress);
|
|
509
|
+
const showPopover = open && canSuggest;
|
|
510
|
+
function selectSuggestion() {
|
|
511
|
+
if (!sessionAddress) return;
|
|
512
|
+
onValueChange(sessionAddress);
|
|
513
|
+
setOpen(false);
|
|
514
|
+
setHighlighted(false);
|
|
515
|
+
innerRef.current?.focus();
|
|
516
|
+
}
|
|
517
|
+
function handleFocus(e) {
|
|
518
|
+
if (blurTimer.current != null) {
|
|
519
|
+
window.clearTimeout(blurTimer.current);
|
|
520
|
+
blurTimer.current = null;
|
|
521
|
+
}
|
|
522
|
+
setOpen(true);
|
|
523
|
+
onFocus?.(e);
|
|
524
|
+
}
|
|
525
|
+
function handleBlur(e) {
|
|
526
|
+
blurTimer.current = window.setTimeout(() => {
|
|
527
|
+
setOpen(false);
|
|
528
|
+
setHighlighted(false);
|
|
529
|
+
}, 120);
|
|
530
|
+
onBlur?.(e);
|
|
531
|
+
}
|
|
532
|
+
function handleKeyDown(e) {
|
|
533
|
+
if (showPopover) {
|
|
534
|
+
if (e.key === "ArrowDown") {
|
|
535
|
+
e.preventDefault();
|
|
536
|
+
setHighlighted(true);
|
|
537
|
+
} else if (e.key === "ArrowUp") {
|
|
538
|
+
e.preventDefault();
|
|
539
|
+
setHighlighted(false);
|
|
540
|
+
} else if (e.key === "Escape") {
|
|
541
|
+
e.preventDefault();
|
|
542
|
+
setOpen(false);
|
|
543
|
+
setHighlighted(false);
|
|
544
|
+
} else if (e.key === "Enter" && highlighted) {
|
|
545
|
+
e.preventDefault();
|
|
546
|
+
selectSuggestion();
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
onKeyDown?.(e);
|
|
550
|
+
}
|
|
551
|
+
React.useEffect(() => {
|
|
552
|
+
return () => {
|
|
553
|
+
if (blurTimer.current != null) window.clearTimeout(blurTimer.current);
|
|
554
|
+
};
|
|
555
|
+
}, []);
|
|
556
|
+
return /* @__PURE__ */ jsxs(
|
|
557
|
+
"div",
|
|
558
|
+
{
|
|
559
|
+
"data-oc-address-input": "",
|
|
560
|
+
className: wrapperClassName,
|
|
561
|
+
style: { position: "relative" },
|
|
562
|
+
children: [
|
|
563
|
+
/* @__PURE__ */ jsx(
|
|
564
|
+
"input",
|
|
565
|
+
{
|
|
566
|
+
...rest,
|
|
567
|
+
ref: setRef,
|
|
568
|
+
value,
|
|
569
|
+
onChange: (e) => onValueChange(e.target.value),
|
|
570
|
+
onFocus: handleFocus,
|
|
571
|
+
onBlur: handleBlur,
|
|
572
|
+
onKeyDown: handleKeyDown,
|
|
573
|
+
role: "combobox",
|
|
574
|
+
"aria-haspopup": "listbox",
|
|
575
|
+
"aria-expanded": showPopover,
|
|
576
|
+
"aria-controls": showPopover ? listboxId : void 0,
|
|
577
|
+
"aria-activedescendant": highlighted ? optionId : void 0,
|
|
578
|
+
autoComplete: "off",
|
|
579
|
+
spellCheck: false
|
|
580
|
+
}
|
|
581
|
+
),
|
|
582
|
+
showPopover && sessionAddress && /* @__PURE__ */ jsx(
|
|
583
|
+
"div",
|
|
584
|
+
{
|
|
585
|
+
id: listboxId,
|
|
586
|
+
role: "listbox",
|
|
587
|
+
"data-oc-address-popover": "",
|
|
588
|
+
className: popoverClassName,
|
|
589
|
+
style: {
|
|
590
|
+
position: "absolute",
|
|
591
|
+
zIndex: 50,
|
|
592
|
+
top: "calc(100% + 4px)",
|
|
593
|
+
left: 0,
|
|
594
|
+
right: 0
|
|
595
|
+
},
|
|
596
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
597
|
+
children: /* @__PURE__ */ jsxs(
|
|
598
|
+
"button",
|
|
599
|
+
{
|
|
600
|
+
type: "button",
|
|
601
|
+
id: optionId,
|
|
602
|
+
role: "option",
|
|
603
|
+
"aria-selected": highlighted,
|
|
604
|
+
"data-oc-address-suggestion": "",
|
|
605
|
+
"data-highlighted": highlighted ? "" : void 0,
|
|
606
|
+
className: suggestionClassName,
|
|
607
|
+
onClick: selectSuggestion,
|
|
608
|
+
onMouseEnter: () => setHighlighted(true),
|
|
609
|
+
onMouseLeave: () => setHighlighted(false),
|
|
610
|
+
style: {
|
|
611
|
+
display: "flex",
|
|
612
|
+
alignItems: "center",
|
|
613
|
+
justifyContent: "space-between",
|
|
614
|
+
gap: "0.75rem",
|
|
615
|
+
width: "100%",
|
|
616
|
+
textAlign: "left",
|
|
617
|
+
cursor: "pointer",
|
|
618
|
+
font: "inherit",
|
|
619
|
+
background: "inherit",
|
|
620
|
+
color: "inherit",
|
|
621
|
+
border: "inherit",
|
|
622
|
+
padding: "inherit"
|
|
623
|
+
},
|
|
624
|
+
children: [
|
|
625
|
+
/* @__PURE__ */ jsx("span", { "data-oc-address-suggestion-label": "", children: suggestionLabel }),
|
|
626
|
+
/* @__PURE__ */ jsx(
|
|
627
|
+
"span",
|
|
628
|
+
{
|
|
629
|
+
"data-oc-address-suggestion-value": "",
|
|
630
|
+
style: { fontFamily: "ui-monospace, monospace" },
|
|
631
|
+
children: shortenAddressMid(sessionAddress)
|
|
632
|
+
}
|
|
633
|
+
)
|
|
634
|
+
]
|
|
635
|
+
}
|
|
636
|
+
)
|
|
637
|
+
}
|
|
638
|
+
)
|
|
639
|
+
]
|
|
640
|
+
}
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
);
|
|
644
|
+
|
|
645
|
+
export {
|
|
646
|
+
OcAccountChip,
|
|
647
|
+
OcSignInButton,
|
|
648
|
+
OcAccountPill,
|
|
649
|
+
useOcAddressSuggestion,
|
|
650
|
+
OcAddressInput
|
|
651
|
+
};
|
|
652
|
+
//# sourceMappingURL=chunk-7UYPMTAV.mjs.map
|