@orangecheck/auth-client 0.2.0 → 0.3.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.d.mts CHANGED
@@ -54,6 +54,29 @@ interface OcAddressInputProps extends Omit<React.InputHTMLAttributes<HTMLInputEl
54
54
  popoverClassName?: string;
55
55
  suggestionClassName?: string;
56
56
  }
57
+ interface UseOcAddressSuggestionOptions {
58
+ value: string;
59
+ onValueChange: (value: string) => void;
60
+ suggestionLabel?: string;
61
+ popoverClassName?: string;
62
+ suggestionClassName?: string;
63
+ }
64
+ interface UseOcAddressSuggestionReturn {
65
+ inputProps: {
66
+ onFocus: (e: React.FocusEvent<HTMLInputElement>) => void;
67
+ onBlur: (e: React.FocusEvent<HTMLInputElement>) => void;
68
+ onKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => void;
69
+ role: 'combobox';
70
+ 'aria-haspopup': 'listbox';
71
+ 'aria-expanded': boolean;
72
+ 'aria-controls': string | undefined;
73
+ 'aria-activedescendant': string | undefined;
74
+ autoComplete: 'off';
75
+ spellCheck: false;
76
+ };
77
+ popover: React.ReactNode;
78
+ }
79
+ declare function useOcAddressSuggestion(options: UseOcAddressSuggestionOptions): UseOcAddressSuggestionReturn;
57
80
  declare const OcAddressInput: React.ForwardRefExoticComponent<OcAddressInputProps & React.RefAttributes<HTMLInputElement>>;
58
81
 
59
- export { DEFAULT_CONFIG, type OcAccount, OcAccountPill, type OcAccountPillProps, OcAddressInput, type OcAddressInputProps, type OcAuthConfig, OcSessionProvider, type OcSessionState, type OcSessionStatus, OcSignInButton, type OcSignInButtonProps, buildSignInUrl, useOcSession, useOptionalOcSession };
82
+ export { DEFAULT_CONFIG, type OcAccount, OcAccountPill, type OcAccountPillProps, OcAddressInput, type OcAddressInputProps, type OcAuthConfig, OcSessionProvider, type OcSessionState, type OcSessionStatus, OcSignInButton, type OcSignInButtonProps, type UseOcAddressSuggestionOptions, type UseOcAddressSuggestionReturn, buildSignInUrl, useOcAddressSuggestion, useOcSession, useOptionalOcSession };
package/dist/index.d.ts CHANGED
@@ -54,6 +54,29 @@ interface OcAddressInputProps extends Omit<React.InputHTMLAttributes<HTMLInputEl
54
54
  popoverClassName?: string;
55
55
  suggestionClassName?: string;
56
56
  }
57
+ interface UseOcAddressSuggestionOptions {
58
+ value: string;
59
+ onValueChange: (value: string) => void;
60
+ suggestionLabel?: string;
61
+ popoverClassName?: string;
62
+ suggestionClassName?: string;
63
+ }
64
+ interface UseOcAddressSuggestionReturn {
65
+ inputProps: {
66
+ onFocus: (e: React.FocusEvent<HTMLInputElement>) => void;
67
+ onBlur: (e: React.FocusEvent<HTMLInputElement>) => void;
68
+ onKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => void;
69
+ role: 'combobox';
70
+ 'aria-haspopup': 'listbox';
71
+ 'aria-expanded': boolean;
72
+ 'aria-controls': string | undefined;
73
+ 'aria-activedescendant': string | undefined;
74
+ autoComplete: 'off';
75
+ spellCheck: false;
76
+ };
77
+ popover: React.ReactNode;
78
+ }
79
+ declare function useOcAddressSuggestion(options: UseOcAddressSuggestionOptions): UseOcAddressSuggestionReturn;
57
80
  declare const OcAddressInput: React.ForwardRefExoticComponent<OcAddressInputProps & React.RefAttributes<HTMLInputElement>>;
58
81
 
59
- export { DEFAULT_CONFIG, type OcAccount, OcAccountPill, type OcAccountPillProps, OcAddressInput, type OcAddressInputProps, type OcAuthConfig, OcSessionProvider, type OcSessionState, type OcSessionStatus, OcSignInButton, type OcSignInButtonProps, buildSignInUrl, useOcSession, useOptionalOcSession };
82
+ export { DEFAULT_CONFIG, type OcAccount, OcAccountPill, type OcAccountPillProps, OcAddressInput, type OcAddressInputProps, type OcAuthConfig, OcSessionProvider, type OcSessionState, type OcSessionStatus, OcSignInButton, type OcSignInButtonProps, type UseOcAddressSuggestionOptions, type UseOcAddressSuggestionReturn, buildSignInUrl, useOcAddressSuggestion, useOcSession, useOptionalOcSession };
package/dist/index.js CHANGED
@@ -209,6 +209,133 @@ function OcAccountPill({
209
209
  }
210
210
  );
211
211
  }
212
+ function useOcAddressSuggestion(options) {
213
+ const {
214
+ value,
215
+ onValueChange,
216
+ suggestionLabel = "use your address",
217
+ popoverClassName,
218
+ suggestionClassName
219
+ } = options;
220
+ const { status, account } = useOcSession();
221
+ const sessionAddress = status === "authenticated" ? account?.address ?? null : null;
222
+ const [open, setOpen] = React__namespace.useState(false);
223
+ const [highlighted, setHighlighted] = React__namespace.useState(false);
224
+ const blurTimer = React__namespace.useRef(null);
225
+ const listboxId = useUniqueId("oc-addr-listbox");
226
+ const optionId = `${listboxId}-opt`;
227
+ const valueMatchesSession = sessionAddress != null && value.toLowerCase() === sessionAddress.toLowerCase();
228
+ const canSuggest = sessionAddress != null && sessionAddress.length > 0 && !valueMatchesSession && isPrefixOf(value, sessionAddress);
229
+ const showPopover = open && canSuggest;
230
+ function selectSuggestion() {
231
+ if (!sessionAddress) return;
232
+ onValueChange(sessionAddress);
233
+ setOpen(false);
234
+ setHighlighted(false);
235
+ }
236
+ React__namespace.useEffect(() => {
237
+ return () => {
238
+ if (blurTimer.current != null) window.clearTimeout(blurTimer.current);
239
+ };
240
+ }, []);
241
+ const inputProps = {
242
+ onFocus: () => {
243
+ if (blurTimer.current != null) {
244
+ window.clearTimeout(blurTimer.current);
245
+ blurTimer.current = null;
246
+ }
247
+ setOpen(true);
248
+ },
249
+ onBlur: () => {
250
+ blurTimer.current = window.setTimeout(() => {
251
+ setOpen(false);
252
+ setHighlighted(false);
253
+ }, 120);
254
+ },
255
+ onKeyDown: (e) => {
256
+ if (!showPopover) return;
257
+ if (e.key === "ArrowDown") {
258
+ e.preventDefault();
259
+ setHighlighted(true);
260
+ } else if (e.key === "ArrowUp") {
261
+ e.preventDefault();
262
+ setHighlighted(false);
263
+ } else if (e.key === "Escape") {
264
+ e.preventDefault();
265
+ setOpen(false);
266
+ setHighlighted(false);
267
+ } else if (e.key === "Enter" && highlighted) {
268
+ e.preventDefault();
269
+ selectSuggestion();
270
+ }
271
+ },
272
+ role: "combobox",
273
+ "aria-haspopup": "listbox",
274
+ "aria-expanded": showPopover,
275
+ "aria-controls": showPopover ? listboxId : void 0,
276
+ "aria-activedescendant": highlighted ? optionId : void 0,
277
+ autoComplete: "off",
278
+ spellCheck: false
279
+ };
280
+ const popover = showPopover && sessionAddress ? /* @__PURE__ */ jsxRuntime.jsx(
281
+ "div",
282
+ {
283
+ id: listboxId,
284
+ role: "listbox",
285
+ "data-oc-address-popover": "",
286
+ className: popoverClassName,
287
+ style: {
288
+ position: "absolute",
289
+ zIndex: 50,
290
+ top: "calc(100% + 4px)",
291
+ left: 0,
292
+ right: 0
293
+ },
294
+ onMouseDown: (e) => e.preventDefault(),
295
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
296
+ "button",
297
+ {
298
+ type: "button",
299
+ id: optionId,
300
+ role: "option",
301
+ "aria-selected": highlighted,
302
+ "data-oc-address-suggestion": "",
303
+ "data-highlighted": highlighted ? "" : void 0,
304
+ className: suggestionClassName,
305
+ onClick: selectSuggestion,
306
+ onMouseEnter: () => setHighlighted(true),
307
+ onMouseLeave: () => setHighlighted(false),
308
+ style: {
309
+ display: "flex",
310
+ alignItems: "center",
311
+ justifyContent: "space-between",
312
+ gap: "0.75rem",
313
+ width: "100%",
314
+ textAlign: "left",
315
+ cursor: "pointer",
316
+ font: "inherit",
317
+ background: "inherit",
318
+ color: "inherit",
319
+ border: 0,
320
+ padding: "inherit"
321
+ },
322
+ children: [
323
+ /* @__PURE__ */ jsxRuntime.jsx("span", { "data-oc-address-suggestion-label": "", children: suggestionLabel }),
324
+ /* @__PURE__ */ jsxRuntime.jsx(
325
+ "span",
326
+ {
327
+ "data-oc-address-suggestion-value": "",
328
+ style: { fontFamily: "ui-monospace, monospace" },
329
+ children: shortenAddressMid(sessionAddress)
330
+ }
331
+ )
332
+ ]
333
+ }
334
+ )
335
+ }
336
+ ) : null;
337
+ return { inputProps, popover };
338
+ }
212
339
  var OcAddressInput = React__namespace.forwardRef(
213
340
  function OcAddressInput2({
214
341
  value,
@@ -379,6 +506,7 @@ exports.OcAddressInput = OcAddressInput;
379
506
  exports.OcSessionProvider = OcSessionProvider;
380
507
  exports.OcSignInButton = OcSignInButton;
381
508
  exports.buildSignInUrl = buildSignInUrl;
509
+ exports.useOcAddressSuggestion = useOcAddressSuggestion;
382
510
  exports.useOcSession = useOcSession;
383
511
  exports.useOptionalOcSession = useOptionalOcSession;
384
512
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts","../src/provider.tsx","../src/components.tsx"],"names":["React","jsx","React2","jsxs","OcAddressInput"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDO,IAAM,cAAA,GAAyC;AAAA,EAClD,UAAA,EAAY,iBAAA;AAAA,EACZ,UAAA,EAAY,SAAA;AAAA,EACZ,MAAA,EAAQ,cAAA;AAAA,EACR,UAAA,EAAY;AAChB;AAEO,SAAS,cAAc,GAAA,EAAuD;AACjF,EAAA,OAAO,EAAE,GAAG,cAAA,EAAgB,GAAI,GAAA,IAAO,EAAC,EAAG;AAC/C;AAEO,SAAS,cAAA,CAAe,KAA6B,QAAA,EAA2B;AACnF,EAAA,MAAM,OAAO,CAAA,EAAG,GAAA,CAAI,UAAU,CAAA,EAAG,IAAI,UAAU,CAAA,CAAA;AAC/C,EAAA,IAAI,CAAC,UAAU,OAAO,IAAA;AACtB,EAAA,MAAM,CAAA,GAAI,IAAI,GAAA,CAAI,IAAI,CAAA;AACtB,EAAA,CAAA,CAAE,YAAA,CAAa,GAAA,CAAI,WAAA,EAAa,QAAQ,CAAA;AACxC,EAAA,OAAO,EAAE,QAAA,EAAS;AACtB;ACvDA,IAAM,cAAA,GAAuBA,+BAAqC,IAAI,CAAA;AAgBtE,SAAS,iBAAiB,GAAA,EAA8C;AACpE,EAAA,IAAI,CAAC,KAAK,OAAO,IAAA;AACjB,EAAA,MAAM,OAAA,GAAU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Z,KAAA,EAAO,SAAA;AAAA,oBACP,MAAA,EAAQ,SAAA;AAAA,oBACR,OAAA,EAAS;AAAA,mBACb;AAAA,kBAEA,QAAA,EAAA;AAAA,oCAAAF,cAAAA,CAAC,MAAA,EAAA,EAAK,kCAAA,EAAiC,EAAA,EAAI,QAAA,EAAA,eAAA,EAAgB,CAAA;AAAA,oCAC3DA,cAAAA;AAAA,sBAAC,MAAA;AAAA,sBAAA;AAAA,wBACG,kCAAA,EAAiC,EAAA;AAAA,wBACjC,KAAA,EAAO,EAAE,UAAA,EAAY,yBAAA,EAA0B;AAAA,wBAE9C,4BAAkB,cAAc;AAAA;AAAA;AACrC;AAAA;AAAA;AACJ;AAAA;AACJ;AAAA;AAAA,KAER;AAAA,EAER;AACJ","file":"index.js","sourcesContent":["export interface OcAccount {\n accountId: string;\n address: string;\n displayName?: string | null;\n nostrNpub?: string | null;\n}\n\nexport type OcSessionStatus = 'loading' | 'authenticated' | 'anonymous' | 'error';\n\nexport interface OcSessionState {\n status: OcSessionStatus;\n account: OcAccount | null;\n /** `null` while loading; an `Error` instance when `status === 'error'`. */\n error: Error | null;\n /** Re-fetch the session. Useful after sign-in/sign-out happens elsewhere. */\n refresh: () => Promise<void>;\n /** Trigger a sign-out. Resolves once the cookie has been cleared. */\n signOut: () => Promise<void>;\n /** URL to navigate to for sign-in on the auth host. */\n signInUrl: string;\n}\n\nexport interface OcAuthConfig {\n /**\n * Origin of the auth host — the subdomain that runs the sign-in UI,\n * issues session cookies, and exposes `/api/auth/me` + `/api/auth/logout`.\n *\n * Defaults to `https://ochk.io`. Override in preview/dev.\n */\n authOrigin?: string;\n /**\n * Path on the auth host that accepts `?return_to=<url>` and drives the\n * BIP-322 sign-in flow. Defaults to `/signin`.\n */\n signInPath?: string;\n /**\n * Local path (same origin as the current app) that exposes the\n * crypto-verified session. If your app ships one at `/api/auth/me`,\n * leave as default. Returns 200 `{ account }` or 401.\n */\n mePath?: string;\n /**\n * Path on the auth host to hit to clear the session cookie.\n * Defaults to `/api/auth/logout`. Called with `credentials: 'include'`\n * so the `.ochk.io` cookie is sent along.\n */\n logoutPath?: string;\n}\n\nexport const DEFAULT_CONFIG: Required<OcAuthConfig> = {\n authOrigin: 'https://ochk.io',\n signInPath: '/signin',\n mePath: '/api/auth/me',\n logoutPath: '/api/auth/logout',\n};\n\nexport function resolveConfig(cfg: OcAuthConfig | undefined): Required<OcAuthConfig> {\n return { ...DEFAULT_CONFIG, ...(cfg ?? {}) };\n}\n\nexport function buildSignInUrl(cfg: Required<OcAuthConfig>, returnTo?: string): string {\n const base = `${cfg.authOrigin}${cfg.signInPath}`;\n if (!returnTo) return base;\n const u = new URL(base);\n u.searchParams.set('return_to', returnTo);\n return u.toString();\n}\n","import * as React from 'react';\n\nimport {\n buildSignInUrl,\n DEFAULT_CONFIG,\n resolveConfig,\n type OcAccount,\n type OcAuthConfig,\n type OcSessionState,\n} from './types';\n\nconst SessionContext = React.createContext<OcSessionState | null>(null);\n\ninterface MeResponse {\n account?: {\n id?: string;\n account_id?: string;\n accountId?: string;\n btc_address?: string;\n address?: string;\n display_name?: string | null;\n displayName?: string | null;\n nostr_npub?: string | null;\n nostrNpub?: string | null;\n };\n}\n\nfunction normalizeAccount(raw: MeResponse['account']): OcAccount | null {\n if (!raw) return null;\n const address = raw.btc_address ?? raw.address;\n const accountId = raw.id ?? raw.account_id ?? raw.accountId;\n if (!address || !accountId) return null;\n return {\n accountId,\n address,\n displayName: raw.display_name ?? raw.displayName ?? null,\n nostrNpub: raw.nostr_npub ?? raw.nostrNpub ?? null,\n };\n}\n\nexport interface OcSessionProviderProps {\n children: React.ReactNode;\n config?: OcAuthConfig;\n /**\n * Optional return URL passed to the sign-in page. Defaults to the\n * current `window.location.href` at click-time.\n */\n defaultReturnTo?: string;\n}\n\n/**\n * Top-level provider that exposes the cross-subdomain oc_session to every\n * component below it. Mount once, near the root of your tree.\n */\nexport function OcSessionProvider({\n children,\n config,\n defaultReturnTo,\n}: OcSessionProviderProps): React.ReactElement {\n const cfg = React.useMemo(() => resolveConfig(config), [config]);\n const [account, setAccount] = React.useState<OcAccount | null>(null);\n const [status, setStatus] = React.useState<OcSessionState['status']>('loading');\n const [error, setError] = React.useState<Error | null>(null);\n\n const refresh = React.useCallback(async () => {\n if (typeof window === 'undefined') return;\n try {\n const res = await fetch(cfg.mePath, {\n method: 'GET',\n credentials: 'include',\n headers: { Accept: 'application/json' },\n });\n if (res.status === 401) {\n setAccount(null);\n setStatus('anonymous');\n setError(null);\n return;\n }\n if (!res.ok) {\n setStatus('error');\n setError(new Error(`me endpoint returned ${res.status}`));\n return;\n }\n const body = (await res.json()) as MeResponse;\n const acct = normalizeAccount(body.account);\n setAccount(acct);\n setStatus(acct ? 'authenticated' : 'anonymous');\n setError(null);\n } catch (err) {\n setStatus('error');\n setError(err instanceof Error ? err : new Error(String(err)));\n }\n }, [cfg.mePath]);\n\n React.useEffect(() => {\n void refresh();\n }, [refresh]);\n\n const signOut = React.useCallback(async () => {\n try {\n await fetch(`${cfg.authOrigin}${cfg.logoutPath}`, {\n method: 'POST',\n credentials: 'include',\n });\n } catch {\n // fall through — we still clear local state so the UI reflects\n // the user's intent even if the server round-trip fails.\n }\n setAccount(null);\n setStatus('anonymous');\n }, [cfg.authOrigin, cfg.logoutPath]);\n\n const value = React.useMemo<OcSessionState>(() => {\n const returnTo =\n defaultReturnTo ?? (typeof window !== 'undefined' ? window.location.href : undefined);\n return {\n status,\n account,\n error,\n refresh,\n signOut,\n signInUrl: buildSignInUrl(cfg, returnTo),\n };\n }, [status, account, error, refresh, signOut, cfg, defaultReturnTo]);\n\n return <SessionContext.Provider value={value}>{children}</SessionContext.Provider>;\n}\n\n/**\n * Access the current cross-subdomain oc_session. Must be called inside\n * an `<OcSessionProvider>`.\n */\nexport function useOcSession(): OcSessionState {\n const ctx = React.useContext(SessionContext);\n if (!ctx) {\n throw new Error(\n '[@orangecheck/auth-client] useOcSession() must be called inside <OcSessionProvider>'\n );\n }\n return ctx;\n}\n\n/**\n * Non-throwing variant — returns `null` if called outside a provider.\n * Useful for libraries that want to read the session *if it exists* but\n * shouldn't crash on apps that haven't opted in.\n */\nexport function useOptionalOcSession(): OcSessionState | null {\n return React.useContext(SessionContext);\n}\n\nexport { DEFAULT_CONFIG };\n","import * as React from 'react';\n\nimport { useOcSession } from './provider';\n\nfunction shortenAddress(addr: string): string {\n if (addr.length <= 12) return addr;\n return `${addr.slice(0, 6)}…${addr.slice(-4)}`;\n}\n\nfunction shortenAddressMid(addr: string): string {\n if (addr.length <= 16) return addr;\n return `${addr.slice(0, 8)}…${addr.slice(-6)}`;\n}\n\nfunction isPrefixOf(value: string, target: string): boolean {\n return target.toLowerCase().startsWith(value.toLowerCase());\n}\n\nlet listboxIdCounter = 0;\nfunction useUniqueId(prefix: string): string {\n const [id] = React.useState(() => `${prefix}-${++listboxIdCounter}`);\n return id;\n}\n\nexport interface OcSignInButtonProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {\n /** Label shown when no user is signed in. Defaults to `sign in with bitcoin`. */\n label?: string;\n /**\n * When `true`, render an `<a>` even while the session is loading, to\n * avoid layout shift. Defaults to `false` (renders nothing while loading).\n */\n eager?: boolean;\n}\n\n/**\n * Drop-in sign-in button. Renders an anchor that deep-links to the auth\n * host's sign-in page with the current URL as `?return_to=…`.\n *\n * When the user is already authenticated it renders nothing — wrap it in\n * a conditional or use `<OcAccountPill>` as the signed-in affordance.\n */\nexport function OcSignInButton({\n label = 'sign in with bitcoin',\n eager = false,\n className,\n ...rest\n}: OcSignInButtonProps): React.ReactElement | null {\n const { status, signInUrl } = useOcSession();\n if (status === 'authenticated') return null;\n if (!eager && status === 'loading') return null;\n\n return (\n <a\n {...rest}\n href={signInUrl}\n className={className}\n data-oc-sign-in-button=\"\"\n >\n {label}\n </a>\n );\n}\n\nexport interface OcAccountPillProps extends React.HTMLAttributes<HTMLDivElement> {\n /** URL to link the address to. Defaults to the auth origin's `/dashboard`. */\n dashboardUrl?: string;\n /** Override the display text. Defaults to the shortened address. */\n render?: (account: { address: string; displayName?: string | null }) => React.ReactNode;\n}\n\n/**\n * Shows the signed-in user as a short pill: `bc1q…abcd sign out`.\n *\n * Renders nothing while loading or when no user is signed in — pair with\n * `<OcSignInButton>` for the anonymous case.\n */\nexport function OcAccountPill({\n dashboardUrl,\n render,\n className,\n ...rest\n}: OcAccountPillProps): React.ReactElement | null {\n const { status, account, signOut } = useOcSession();\n\n if (status !== 'authenticated' || !account) return null;\n\n const label = render\n ? render({ address: account.address, displayName: account.displayName })\n : (account.displayName ?? shortenAddress(account.address));\n\n return (\n <div\n {...rest}\n className={className}\n data-oc-account-pill=\"\"\n style={{ display: 'inline-flex', alignItems: 'center', gap: '0.5rem', ...(rest.style ?? {}) }}\n >\n {dashboardUrl ? (\n <a href={dashboardUrl}>{label}</a>\n ) : (\n <span>{label}</span>\n )}\n <button\n type=\"button\"\n onClick={() => {\n void signOut();\n }}\n aria-label=\"Sign out\"\n style={{\n background: 'none',\n border: 'none',\n cursor: 'pointer',\n color: 'inherit',\n font: 'inherit',\n padding: 0,\n }}\n >\n sign out\n </button>\n </div>\n );\n}\n\nexport interface OcAddressInputProps\n extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange'> {\n /** Controlled value. */\n value: string;\n /** Called when value changes — typed by the user OR selected from the popover. */\n onValueChange: (value: string) => void;\n /** Label shown above the suggested address in the popover. Defaults to `use your address`. */\n suggestionLabel?: string;\n /** className applied to the wrapper `<div>`. */\n wrapperClassName?: string;\n /** className applied to the suggestion popover. Style with `[data-oc-address-popover]` otherwise. */\n popoverClassName?: string;\n /** className applied to the suggestion button. Style with `[data-oc-address-suggestion]` otherwise. */\n suggestionClassName?: string;\n}\n\n/**\n * Bitcoin-address `<input>` that, when the user is signed in via `oc_session`,\n * surfaces their address as a one-click suggestion on focus.\n *\n * Behaviour:\n * - On focus, if logged-in AND the typed value is a prefix of the session\n * address (or empty), show a small popover with `bc1q…7ke3` as a clickable\n * suggestion.\n * - Click / Enter on the suggestion fills the field with the full address.\n * - Down-arrow from the input highlights the suggestion; Up-arrow clears the\n * highlight; Escape closes the popover; clicking outside closes the popover.\n * - When the user types something that's no longer a prefix of the session\n * address, the popover hides itself out of the way.\n * - When the field already contains the session address exactly, no popover.\n *\n * Style-agnostic: minimal inline styles for positioning only. Style the parts\n * via `wrapperClassName` / `popoverClassName` / `suggestionClassName`, or via\n * the `[data-oc-address-input]`, `[data-oc-address-popover]`, and\n * `[data-oc-address-suggestion]` data attributes.\n */\nexport const OcAddressInput = React.forwardRef<HTMLInputElement, OcAddressInputProps>(\n function OcAddressInput(\n {\n value,\n onValueChange,\n suggestionLabel = 'use your address',\n wrapperClassName,\n popoverClassName,\n suggestionClassName,\n onFocus,\n onBlur,\n onKeyDown,\n ...rest\n },\n forwardedRef\n ): React.ReactElement {\n const { status, account } = useOcSession();\n const sessionAddress = status === 'authenticated' ? (account?.address ?? null) : null;\n\n const [open, setOpen] = React.useState(false);\n const [highlighted, setHighlighted] = React.useState(false);\n\n const innerRef = React.useRef<HTMLInputElement | null>(null);\n const setRef = (node: HTMLInputElement | null) => {\n innerRef.current = node;\n if (typeof forwardedRef === 'function') forwardedRef(node);\n else if (forwardedRef) forwardedRef.current = node;\n };\n const blurTimer = React.useRef<number | null>(null);\n\n const listboxId = useUniqueId('oc-addr-listbox');\n const optionId = `${listboxId}-opt`;\n\n const valueMatchesSession =\n sessionAddress != null && value.toLowerCase() === sessionAddress.toLowerCase();\n const canSuggest =\n sessionAddress != null &&\n sessionAddress.length > 0 &&\n !valueMatchesSession &&\n isPrefixOf(value, sessionAddress);\n const showPopover = open && canSuggest;\n\n function selectSuggestion() {\n if (!sessionAddress) return;\n onValueChange(sessionAddress);\n setOpen(false);\n setHighlighted(false);\n // Re-focus so the next Tab moves on naturally.\n innerRef.current?.focus();\n }\n\n function handleFocus(e: React.FocusEvent<HTMLInputElement>) {\n if (blurTimer.current != null) {\n window.clearTimeout(blurTimer.current);\n blurTimer.current = null;\n }\n setOpen(true);\n onFocus?.(e);\n }\n\n function handleBlur(e: React.FocusEvent<HTMLInputElement>) {\n // Defer close so a click on the suggestion can register first.\n blurTimer.current = window.setTimeout(() => {\n setOpen(false);\n setHighlighted(false);\n }, 120);\n onBlur?.(e);\n }\n\n function handleKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {\n if (showPopover) {\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n setHighlighted(true);\n } else if (e.key === 'ArrowUp') {\n e.preventDefault();\n setHighlighted(false);\n } else if (e.key === 'Escape') {\n e.preventDefault();\n setOpen(false);\n setHighlighted(false);\n } else if (e.key === 'Enter' && highlighted) {\n e.preventDefault();\n selectSuggestion();\n }\n }\n onKeyDown?.(e);\n }\n\n React.useEffect(() => {\n return () => {\n if (blurTimer.current != null) window.clearTimeout(blurTimer.current);\n };\n }, []);\n\n return (\n <div\n data-oc-address-input=\"\"\n className={wrapperClassName}\n style={{ position: 'relative' }}\n >\n <input\n {...rest}\n ref={setRef}\n value={value}\n onChange={(e) => onValueChange(e.target.value)}\n onFocus={handleFocus}\n onBlur={handleBlur}\n onKeyDown={handleKeyDown}\n role=\"combobox\"\n aria-haspopup=\"listbox\"\n aria-expanded={showPopover}\n aria-controls={showPopover ? listboxId : undefined}\n aria-activedescendant={highlighted ? optionId : undefined}\n autoComplete=\"off\"\n spellCheck={false}\n />\n {showPopover && sessionAddress && (\n <div\n id={listboxId}\n role=\"listbox\"\n data-oc-address-popover=\"\"\n className={popoverClassName}\n style={{\n position: 'absolute',\n zIndex: 50,\n top: 'calc(100% + 4px)',\n left: 0,\n right: 0,\n }}\n // Prevent the input from blurring before the click on the suggestion lands.\n onMouseDown={(e) => e.preventDefault()}\n >\n <button\n type=\"button\"\n id={optionId}\n role=\"option\"\n aria-selected={highlighted}\n data-oc-address-suggestion=\"\"\n data-highlighted={highlighted ? '' : undefined}\n className={suggestionClassName}\n onClick={selectSuggestion}\n onMouseEnter={() => setHighlighted(true)}\n onMouseLeave={() => setHighlighted(false)}\n style={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: '0.75rem',\n width: '100%',\n textAlign: 'left',\n cursor: 'pointer',\n font: 'inherit',\n background: 'inherit',\n color: 'inherit',\n border: 'inherit',\n padding: 'inherit',\n }}\n >\n <span data-oc-address-suggestion-label=\"\">{suggestionLabel}</span>\n <span\n data-oc-address-suggestion-value=\"\"\n style={{ fontFamily: 'ui-monospace, monospace' }}\n >\n {shortenAddressMid(sessionAddress)}\n </span>\n </button>\n </div>\n )}\n </div>\n );\n }\n);\n"]}
1
+ {"version":3,"sources":["../src/types.ts","../src/provider.tsx","../src/components.tsx"],"names":["React","jsx","React2","jsxs","OcAddressInput"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDO,IAAM,cAAA,GAAyC;AAAA,EAClD,UAAA,EAAY,iBAAA;AAAA,EACZ,UAAA,EAAY,SAAA;AAAA,EACZ,MAAA,EAAQ,cAAA;AAAA,EACR,UAAA,EAAY;AAChB;AAEO,SAAS,cAAc,GAAA,EAAuD;AACjF,EAAA,OAAO,EAAE,GAAG,cAAA,EAAgB,GAAI,GAAA,IAAO,EAAC,EAAG;AAC/C;AAEO,SAAS,cAAA,CAAe,KAA6B,QAAA,EAA2B;AACnF,EAAA,MAAM,OAAO,CAAA,EAAG,GAAA,CAAI,UAAU,CAAA,EAAG,IAAI,UAAU,CAAA,CAAA;AAC/C,EAAA,IAAI,CAAC,UAAU,OAAO,IAAA;AACtB,EAAA,MAAM,CAAA,GAAI,IAAI,GAAA,CAAI,IAAI,CAAA;AACtB,EAAA,CAAA,CAAE,YAAA,CAAa,GAAA,CAAI,WAAA,EAAa,QAAQ,CAAA;AACxC,EAAA,OAAO,EAAE,QAAA,EAAS;AACtB;ACvDA,IAAM,cAAA,GAAuBA,+BAAqC,IAAI,CAAA;AAgBtE,SAAS,iBAAiB,GAAA,EAA8C;AACpE,EAAA,IAAI,CAAC,KAAK,OAAO,IAAA;AACjB,EAAA,MAAM,OAAA,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string;\n address: string;\n displayName?: string | null;\n nostrNpub?: string | null;\n}\n\nexport type OcSessionStatus = 'loading' | 'authenticated' | 'anonymous' | 'error';\n\nexport interface OcSessionState {\n status: OcSessionStatus;\n account: OcAccount | null;\n /** `null` while loading; an `Error` instance when `status === 'error'`. */\n error: Error | null;\n /** Re-fetch the session. Useful after sign-in/sign-out happens elsewhere. */\n refresh: () => Promise<void>;\n /** Trigger a sign-out. Resolves once the cookie has been cleared. */\n signOut: () => Promise<void>;\n /** URL to navigate to for sign-in on the auth host. */\n signInUrl: string;\n}\n\nexport interface OcAuthConfig {\n /**\n * Origin of the auth host — the subdomain that runs the sign-in UI,\n * issues session cookies, and exposes `/api/auth/me` + `/api/auth/logout`.\n *\n * Defaults to `https://ochk.io`. Override in preview/dev.\n */\n authOrigin?: string;\n /**\n * Path on the auth host that accepts `?return_to=<url>` and drives the\n * BIP-322 sign-in flow. Defaults to `/signin`.\n */\n signInPath?: string;\n /**\n * Local path (same origin as the current app) that exposes the\n * crypto-verified session. If your app ships one at `/api/auth/me`,\n * leave as default. Returns 200 `{ account }` or 401.\n */\n mePath?: string;\n /**\n * Path on the auth host to hit to clear the session cookie.\n * Defaults to `/api/auth/logout`. Called with `credentials: 'include'`\n * so the `.ochk.io` cookie is sent along.\n */\n logoutPath?: string;\n}\n\nexport const DEFAULT_CONFIG: Required<OcAuthConfig> = {\n authOrigin: 'https://ochk.io',\n signInPath: '/signin',\n mePath: '/api/auth/me',\n logoutPath: '/api/auth/logout',\n};\n\nexport function resolveConfig(cfg: OcAuthConfig | undefined): Required<OcAuthConfig> {\n return { ...DEFAULT_CONFIG, ...(cfg ?? {}) };\n}\n\nexport function buildSignInUrl(cfg: Required<OcAuthConfig>, returnTo?: string): string {\n const base = `${cfg.authOrigin}${cfg.signInPath}`;\n if (!returnTo) return base;\n const u = new URL(base);\n u.searchParams.set('return_to', returnTo);\n return u.toString();\n}\n","import * as React from 'react';\n\nimport {\n buildSignInUrl,\n DEFAULT_CONFIG,\n resolveConfig,\n type OcAccount,\n type OcAuthConfig,\n type OcSessionState,\n} from './types';\n\nconst SessionContext = React.createContext<OcSessionState | null>(null);\n\ninterface MeResponse {\n account?: {\n id?: string;\n account_id?: string;\n accountId?: string;\n btc_address?: string;\n address?: string;\n display_name?: string | null;\n displayName?: string | null;\n nostr_npub?: string | null;\n nostrNpub?: string | null;\n };\n}\n\nfunction normalizeAccount(raw: MeResponse['account']): OcAccount | null {\n if (!raw) return null;\n const address = raw.btc_address ?? raw.address;\n const accountId = raw.id ?? raw.account_id ?? raw.accountId;\n if (!address || !accountId) return null;\n return {\n accountId,\n address,\n displayName: raw.display_name ?? raw.displayName ?? null,\n nostrNpub: raw.nostr_npub ?? raw.nostrNpub ?? null,\n };\n}\n\nexport interface OcSessionProviderProps {\n children: React.ReactNode;\n config?: OcAuthConfig;\n /**\n * Optional return URL passed to the sign-in page. Defaults to the\n * current `window.location.href` at click-time.\n */\n defaultReturnTo?: string;\n}\n\n/**\n * Top-level provider that exposes the cross-subdomain oc_session to every\n * component below it. Mount once, near the root of your tree.\n */\nexport function OcSessionProvider({\n children,\n config,\n defaultReturnTo,\n}: OcSessionProviderProps): React.ReactElement {\n const cfg = React.useMemo(() => resolveConfig(config), [config]);\n const [account, setAccount] = React.useState<OcAccount | null>(null);\n const [status, setStatus] = React.useState<OcSessionState['status']>('loading');\n const [error, setError] = React.useState<Error | null>(null);\n\n const refresh = React.useCallback(async () => {\n if (typeof window === 'undefined') return;\n try {\n const res = await fetch(cfg.mePath, {\n method: 'GET',\n credentials: 'include',\n headers: { Accept: 'application/json' },\n });\n if (res.status === 401) {\n setAccount(null);\n setStatus('anonymous');\n setError(null);\n return;\n }\n if (!res.ok) {\n setStatus('error');\n setError(new Error(`me endpoint returned ${res.status}`));\n return;\n }\n const body = (await res.json()) as MeResponse;\n const acct = normalizeAccount(body.account);\n setAccount(acct);\n setStatus(acct ? 'authenticated' : 'anonymous');\n setError(null);\n } catch (err) {\n setStatus('error');\n setError(err instanceof Error ? err : new Error(String(err)));\n }\n }, [cfg.mePath]);\n\n React.useEffect(() => {\n void refresh();\n }, [refresh]);\n\n const signOut = React.useCallback(async () => {\n try {\n await fetch(`${cfg.authOrigin}${cfg.logoutPath}`, {\n method: 'POST',\n credentials: 'include',\n });\n } catch {\n // fall through — we still clear local state so the UI reflects\n // the user's intent even if the server round-trip fails.\n }\n setAccount(null);\n setStatus('anonymous');\n }, [cfg.authOrigin, cfg.logoutPath]);\n\n const value = React.useMemo<OcSessionState>(() => {\n const returnTo =\n defaultReturnTo ?? (typeof window !== 'undefined' ? window.location.href : undefined);\n return {\n status,\n account,\n error,\n refresh,\n signOut,\n signInUrl: buildSignInUrl(cfg, returnTo),\n };\n }, [status, account, error, refresh, signOut, cfg, defaultReturnTo]);\n\n return <SessionContext.Provider value={value}>{children}</SessionContext.Provider>;\n}\n\n/**\n * Access the current cross-subdomain oc_session. Must be called inside\n * an `<OcSessionProvider>`.\n */\nexport function useOcSession(): OcSessionState {\n const ctx = React.useContext(SessionContext);\n if (!ctx) {\n throw new Error(\n '[@orangecheck/auth-client] useOcSession() must be called inside <OcSessionProvider>'\n );\n }\n return ctx;\n}\n\n/**\n * Non-throwing variant — returns `null` if called outside a provider.\n * Useful for libraries that want to read the session *if it exists* but\n * shouldn't crash on apps that haven't opted in.\n */\nexport function useOptionalOcSession(): OcSessionState | null {\n return React.useContext(SessionContext);\n}\n\nexport { DEFAULT_CONFIG };\n","import * as React from 'react';\n\nimport { useOcSession } from './provider';\n\nfunction shortenAddress(addr: string): string {\n if (addr.length <= 12) return addr;\n return `${addr.slice(0, 6)}…${addr.slice(-4)}`;\n}\n\nfunction shortenAddressMid(addr: string): string {\n if (addr.length <= 16) return addr;\n return `${addr.slice(0, 8)}…${addr.slice(-6)}`;\n}\n\nfunction isPrefixOf(value: string, target: string): boolean {\n return target.toLowerCase().startsWith(value.toLowerCase());\n}\n\nlet listboxIdCounter = 0;\nfunction useUniqueId(prefix: string): string {\n const [id] = React.useState(() => `${prefix}-${++listboxIdCounter}`);\n return id;\n}\n\nexport interface OcSignInButtonProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {\n /** Label shown when no user is signed in. Defaults to `sign in with bitcoin`. */\n label?: string;\n /**\n * When `true`, render an `<a>` even while the session is loading, to\n * avoid layout shift. Defaults to `false` (renders nothing while loading).\n */\n eager?: boolean;\n}\n\n/**\n * Drop-in sign-in button. Renders an anchor that deep-links to the auth\n * host's sign-in page with the current URL as `?return_to=…`.\n *\n * When the user is already authenticated it renders nothing — wrap it in\n * a conditional or use `<OcAccountPill>` as the signed-in affordance.\n */\nexport function OcSignInButton({\n label = 'sign in with bitcoin',\n eager = false,\n className,\n ...rest\n}: OcSignInButtonProps): React.ReactElement | null {\n const { status, signInUrl } = useOcSession();\n if (status === 'authenticated') return null;\n if (!eager && status === 'loading') return null;\n\n return (\n <a\n {...rest}\n href={signInUrl}\n className={className}\n data-oc-sign-in-button=\"\"\n >\n {label}\n </a>\n );\n}\n\nexport interface OcAccountPillProps extends React.HTMLAttributes<HTMLDivElement> {\n /** URL to link the address to. Defaults to the auth origin's `/dashboard`. */\n dashboardUrl?: string;\n /** Override the display text. Defaults to the shortened address. */\n render?: (account: { address: string; displayName?: string | null }) => React.ReactNode;\n}\n\n/**\n * Shows the signed-in user as a short pill: `bc1q…abcd sign out`.\n *\n * Renders nothing while loading or when no user is signed in — pair with\n * `<OcSignInButton>` for the anonymous case.\n */\nexport function OcAccountPill({\n dashboardUrl,\n render,\n className,\n ...rest\n}: OcAccountPillProps): React.ReactElement | null {\n const { status, account, signOut } = useOcSession();\n\n if (status !== 'authenticated' || !account) return null;\n\n const label = render\n ? render({ address: account.address, displayName: account.displayName })\n : (account.displayName ?? shortenAddress(account.address));\n\n return (\n <div\n {...rest}\n className={className}\n data-oc-account-pill=\"\"\n style={{ display: 'inline-flex', alignItems: 'center', gap: '0.5rem', ...(rest.style ?? {}) }}\n >\n {dashboardUrl ? (\n <a href={dashboardUrl}>{label}</a>\n ) : (\n <span>{label}</span>\n )}\n <button\n type=\"button\"\n onClick={() => {\n void signOut();\n }}\n aria-label=\"Sign out\"\n style={{\n background: 'none',\n border: 'none',\n cursor: 'pointer',\n color: 'inherit',\n font: 'inherit',\n padding: 0,\n }}\n >\n sign out\n </button>\n </div>\n );\n}\n\nexport interface OcAddressInputProps\n extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange'> {\n /** Controlled value. */\n value: string;\n /** Called when value changes — typed by the user OR selected from the popover. */\n onValueChange: (value: string) => void;\n /** Label shown above the suggested address in the popover. Defaults to `use your address`. */\n suggestionLabel?: string;\n /** className applied to the wrapper `<div>`. */\n wrapperClassName?: string;\n /** className applied to the suggestion popover. Style with `[data-oc-address-popover]` otherwise. */\n popoverClassName?: string;\n /** className applied to the suggestion button. Style with `[data-oc-address-suggestion]` otherwise. */\n suggestionClassName?: string;\n}\n\n/**\n * Bitcoin-address `<input>` that, when the user is signed in via `oc_session`,\n * surfaces their address as a one-click suggestion on focus.\n *\n * Behaviour:\n * - On focus, if logged-in AND the typed value is a prefix of the session\n * address (or empty), show a small popover with `bc1q…7ke3` as a clickable\n * suggestion.\n * - Click / Enter on the suggestion fills the field with the full address.\n * - Down-arrow from the input highlights the suggestion; Up-arrow clears the\n * highlight; Escape closes the popover; clicking outside closes the popover.\n * - When the user types something that's no longer a prefix of the session\n * address, the popover hides itself out of the way.\n * - When the field already contains the session address exactly, no popover.\n *\n * Style-agnostic: minimal inline styles for positioning only. Style the parts\n * via `wrapperClassName` / `popoverClassName` / `suggestionClassName`, or via\n * the `[data-oc-address-input]`, `[data-oc-address-popover]`, and\n * `[data-oc-address-suggestion]` data attributes.\n */\nexport interface UseOcAddressSuggestionOptions {\n /** Current value of the input. */\n value: string;\n /** Called when the user selects the suggestion (or you may also call it from the input's onChange). */\n onValueChange: (value: string) => void;\n /** Label shown above the suggested address in the popover. Defaults to `use your address`. */\n suggestionLabel?: string;\n /** className applied to the suggestion popover. Style with `[data-oc-address-popover]` otherwise. */\n popoverClassName?: string;\n /** className applied to the suggestion button. Style with `[data-oc-address-suggestion]` otherwise. */\n suggestionClassName?: string;\n}\n\nexport interface UseOcAddressSuggestionReturn {\n /**\n * Props to spread onto your `<input>` element. Adds focus/blur/keydown\n * handlers and the combobox ARIA attributes. Combine with your existing\n * `value`/`onChange` props — this hook does NOT control them.\n */\n inputProps: {\n onFocus: (e: React.FocusEvent<HTMLInputElement>) => void;\n onBlur: (e: React.FocusEvent<HTMLInputElement>) => void;\n onKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => void;\n role: 'combobox';\n 'aria-haspopup': 'listbox';\n 'aria-expanded': boolean;\n 'aria-controls': string | undefined;\n 'aria-activedescendant': string | undefined;\n autoComplete: 'off';\n spellCheck: false;\n };\n /**\n * The suggestion popover. Render directly after your `<input>`, inside a\n * `position: relative` container so the popover anchors below the input.\n * Returns `null` when there's no suggestion to show.\n */\n popover: React.ReactNode;\n}\n\n/**\n * Hook variant of `OcAddressInput`. Use when you want to keep your existing\n * styled `<input>` (e.g. shadcn `<Input>`) and just bolt on the\n * session-address suggestion behaviour.\n *\n * Wrap your input in a `position: relative` container, spread `inputProps`\n * onto the input, and render `{popover}` immediately after. The hook's\n * focus / blur / keydown handlers are composed via `inputProps` — they call\n * any handlers you've already passed to your input only when you wire them\n * yourself in addition to spreading `inputProps`.\n *\n * Example:\n * ```tsx\n * const { inputProps, popover } = useOcAddressSuggestion({\n * value: addr,\n * onValueChange: setAddr,\n * });\n * return (\n * <div className=\"relative\">\n * <Input\n * value={addr}\n * onChange={(e) => setAddr(e.target.value)}\n * {...inputProps}\n * placeholder=\"bc1q…\"\n * />\n * {popover}\n * </div>\n * );\n * ```\n */\nexport function useOcAddressSuggestion(\n options: UseOcAddressSuggestionOptions\n): UseOcAddressSuggestionReturn {\n const {\n value,\n onValueChange,\n suggestionLabel = 'use your address',\n popoverClassName,\n suggestionClassName,\n } = options;\n\n const { status, account } = useOcSession();\n const sessionAddress = status === 'authenticated' ? (account?.address ?? null) : null;\n\n const [open, setOpen] = React.useState(false);\n const [highlighted, setHighlighted] = React.useState(false);\n const blurTimer = React.useRef<number | null>(null);\n\n const listboxId = useUniqueId('oc-addr-listbox');\n const optionId = `${listboxId}-opt`;\n\n const valueMatchesSession =\n sessionAddress != null && value.toLowerCase() === sessionAddress.toLowerCase();\n const canSuggest =\n sessionAddress != null &&\n sessionAddress.length > 0 &&\n !valueMatchesSession &&\n isPrefixOf(value, sessionAddress);\n const showPopover = open && canSuggest;\n\n function selectSuggestion() {\n if (!sessionAddress) return;\n onValueChange(sessionAddress);\n setOpen(false);\n setHighlighted(false);\n }\n\n React.useEffect(() => {\n return () => {\n if (blurTimer.current != null) window.clearTimeout(blurTimer.current);\n };\n }, []);\n\n const inputProps: UseOcAddressSuggestionReturn['inputProps'] = {\n onFocus: () => {\n if (blurTimer.current != null) {\n window.clearTimeout(blurTimer.current);\n blurTimer.current = null;\n }\n setOpen(true);\n },\n onBlur: () => {\n blurTimer.current = window.setTimeout(() => {\n setOpen(false);\n setHighlighted(false);\n }, 120);\n },\n onKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (!showPopover) return;\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n setHighlighted(true);\n } else if (e.key === 'ArrowUp') {\n e.preventDefault();\n setHighlighted(false);\n } else if (e.key === 'Escape') {\n e.preventDefault();\n setOpen(false);\n setHighlighted(false);\n } else if (e.key === 'Enter' && highlighted) {\n e.preventDefault();\n selectSuggestion();\n }\n },\n role: 'combobox',\n 'aria-haspopup': 'listbox',\n 'aria-expanded': showPopover,\n 'aria-controls': showPopover ? listboxId : undefined,\n 'aria-activedescendant': highlighted ? optionId : undefined,\n autoComplete: 'off',\n spellCheck: false,\n };\n\n const popover = showPopover && sessionAddress ? (\n <div\n id={listboxId}\n role=\"listbox\"\n data-oc-address-popover=\"\"\n className={popoverClassName}\n style={{\n position: 'absolute',\n zIndex: 50,\n top: 'calc(100% + 4px)',\n left: 0,\n right: 0,\n }}\n onMouseDown={(e) => e.preventDefault()}\n >\n <button\n type=\"button\"\n id={optionId}\n role=\"option\"\n aria-selected={highlighted}\n data-oc-address-suggestion=\"\"\n data-highlighted={highlighted ? '' : undefined}\n className={suggestionClassName}\n onClick={selectSuggestion}\n onMouseEnter={() => setHighlighted(true)}\n onMouseLeave={() => setHighlighted(false)}\n style={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: '0.75rem',\n width: '100%',\n textAlign: 'left',\n cursor: 'pointer',\n font: 'inherit',\n background: 'inherit',\n color: 'inherit',\n border: 0,\n padding: 'inherit',\n }}\n >\n <span data-oc-address-suggestion-label=\"\">{suggestionLabel}</span>\n <span\n data-oc-address-suggestion-value=\"\"\n style={{ fontFamily: 'ui-monospace, monospace' }}\n >\n {shortenAddressMid(sessionAddress)}\n </span>\n </button>\n </div>\n ) : null;\n\n return { inputProps, popover };\n}\n\nexport const OcAddressInput = React.forwardRef<HTMLInputElement, OcAddressInputProps>(\n function OcAddressInput(\n {\n value,\n onValueChange,\n suggestionLabel = 'use your address',\n wrapperClassName,\n popoverClassName,\n suggestionClassName,\n onFocus,\n onBlur,\n onKeyDown,\n ...rest\n },\n forwardedRef\n ): React.ReactElement {\n const { status, account } = useOcSession();\n const sessionAddress = status === 'authenticated' ? (account?.address ?? null) : null;\n\n const [open, setOpen] = React.useState(false);\n const [highlighted, setHighlighted] = React.useState(false);\n\n const innerRef = React.useRef<HTMLInputElement | null>(null);\n const setRef = (node: HTMLInputElement | null) => {\n innerRef.current = node;\n if (typeof forwardedRef === 'function') forwardedRef(node);\n else if (forwardedRef) forwardedRef.current = node;\n };\n const blurTimer = React.useRef<number | null>(null);\n\n const listboxId = useUniqueId('oc-addr-listbox');\n const optionId = `${listboxId}-opt`;\n\n const valueMatchesSession =\n sessionAddress != null && value.toLowerCase() === sessionAddress.toLowerCase();\n const canSuggest =\n sessionAddress != null &&\n sessionAddress.length > 0 &&\n !valueMatchesSession &&\n isPrefixOf(value, sessionAddress);\n const showPopover = open && canSuggest;\n\n function selectSuggestion() {\n if (!sessionAddress) return;\n onValueChange(sessionAddress);\n setOpen(false);\n setHighlighted(false);\n // Re-focus so the next Tab moves on naturally.\n innerRef.current?.focus();\n }\n\n function handleFocus(e: React.FocusEvent<HTMLInputElement>) {\n if (blurTimer.current != null) {\n window.clearTimeout(blurTimer.current);\n blurTimer.current = null;\n }\n setOpen(true);\n onFocus?.(e);\n }\n\n function handleBlur(e: React.FocusEvent<HTMLInputElement>) {\n // Defer close so a click on the suggestion can register first.\n blurTimer.current = window.setTimeout(() => {\n setOpen(false);\n setHighlighted(false);\n }, 120);\n onBlur?.(e);\n }\n\n function handleKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {\n if (showPopover) {\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n setHighlighted(true);\n } else if (e.key === 'ArrowUp') {\n e.preventDefault();\n setHighlighted(false);\n } else if (e.key === 'Escape') {\n e.preventDefault();\n setOpen(false);\n setHighlighted(false);\n } else if (e.key === 'Enter' && highlighted) {\n e.preventDefault();\n selectSuggestion();\n }\n }\n onKeyDown?.(e);\n }\n\n React.useEffect(() => {\n return () => {\n if (blurTimer.current != null) window.clearTimeout(blurTimer.current);\n };\n }, []);\n\n return (\n <div\n data-oc-address-input=\"\"\n className={wrapperClassName}\n style={{ position: 'relative' }}\n >\n <input\n {...rest}\n ref={setRef}\n value={value}\n onChange={(e) => onValueChange(e.target.value)}\n onFocus={handleFocus}\n onBlur={handleBlur}\n onKeyDown={handleKeyDown}\n role=\"combobox\"\n aria-haspopup=\"listbox\"\n aria-expanded={showPopover}\n aria-controls={showPopover ? listboxId : undefined}\n aria-activedescendant={highlighted ? optionId : undefined}\n autoComplete=\"off\"\n spellCheck={false}\n />\n {showPopover && sessionAddress && (\n <div\n id={listboxId}\n role=\"listbox\"\n data-oc-address-popover=\"\"\n className={popoverClassName}\n style={{\n position: 'absolute',\n zIndex: 50,\n top: 'calc(100% + 4px)',\n left: 0,\n right: 0,\n }}\n // Prevent the input from blurring before the click on the suggestion lands.\n onMouseDown={(e) => e.preventDefault()}\n >\n <button\n type=\"button\"\n id={optionId}\n role=\"option\"\n aria-selected={highlighted}\n data-oc-address-suggestion=\"\"\n data-highlighted={highlighted ? '' : undefined}\n className={suggestionClassName}\n onClick={selectSuggestion}\n onMouseEnter={() => setHighlighted(true)}\n onMouseLeave={() => setHighlighted(false)}\n style={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: '0.75rem',\n width: '100%',\n textAlign: 'left',\n cursor: 'pointer',\n font: 'inherit',\n background: 'inherit',\n color: 'inherit',\n border: 'inherit',\n padding: 'inherit',\n }}\n >\n <span data-oc-address-suggestion-label=\"\">{suggestionLabel}</span>\n <span\n data-oc-address-suggestion-value=\"\"\n style={{ fontFamily: 'ui-monospace, monospace' }}\n >\n {shortenAddressMid(sessionAddress)}\n </span>\n </button>\n </div>\n )}\n </div>\n );\n }\n);\n"]}
package/dist/index.mjs CHANGED
@@ -187,6 +187,133 @@ function OcAccountPill({
187
187
  }
188
188
  );
189
189
  }
190
+ function useOcAddressSuggestion(options) {
191
+ const {
192
+ value,
193
+ onValueChange,
194
+ suggestionLabel = "use your address",
195
+ popoverClassName,
196
+ suggestionClassName
197
+ } = options;
198
+ const { status, account } = useOcSession();
199
+ const sessionAddress = status === "authenticated" ? account?.address ?? null : null;
200
+ const [open, setOpen] = React.useState(false);
201
+ const [highlighted, setHighlighted] = React.useState(false);
202
+ const blurTimer = React.useRef(null);
203
+ const listboxId = useUniqueId("oc-addr-listbox");
204
+ const optionId = `${listboxId}-opt`;
205
+ const valueMatchesSession = sessionAddress != null && value.toLowerCase() === sessionAddress.toLowerCase();
206
+ const canSuggest = sessionAddress != null && sessionAddress.length > 0 && !valueMatchesSession && isPrefixOf(value, sessionAddress);
207
+ const showPopover = open && canSuggest;
208
+ function selectSuggestion() {
209
+ if (!sessionAddress) return;
210
+ onValueChange(sessionAddress);
211
+ setOpen(false);
212
+ setHighlighted(false);
213
+ }
214
+ React.useEffect(() => {
215
+ return () => {
216
+ if (blurTimer.current != null) window.clearTimeout(blurTimer.current);
217
+ };
218
+ }, []);
219
+ const inputProps = {
220
+ onFocus: () => {
221
+ if (blurTimer.current != null) {
222
+ window.clearTimeout(blurTimer.current);
223
+ blurTimer.current = null;
224
+ }
225
+ setOpen(true);
226
+ },
227
+ onBlur: () => {
228
+ blurTimer.current = window.setTimeout(() => {
229
+ setOpen(false);
230
+ setHighlighted(false);
231
+ }, 120);
232
+ },
233
+ onKeyDown: (e) => {
234
+ if (!showPopover) return;
235
+ if (e.key === "ArrowDown") {
236
+ e.preventDefault();
237
+ setHighlighted(true);
238
+ } else if (e.key === "ArrowUp") {
239
+ e.preventDefault();
240
+ setHighlighted(false);
241
+ } else if (e.key === "Escape") {
242
+ e.preventDefault();
243
+ setOpen(false);
244
+ setHighlighted(false);
245
+ } else if (e.key === "Enter" && highlighted) {
246
+ e.preventDefault();
247
+ selectSuggestion();
248
+ }
249
+ },
250
+ role: "combobox",
251
+ "aria-haspopup": "listbox",
252
+ "aria-expanded": showPopover,
253
+ "aria-controls": showPopover ? listboxId : void 0,
254
+ "aria-activedescendant": highlighted ? optionId : void 0,
255
+ autoComplete: "off",
256
+ spellCheck: false
257
+ };
258
+ const popover = showPopover && sessionAddress ? /* @__PURE__ */ jsx(
259
+ "div",
260
+ {
261
+ id: listboxId,
262
+ role: "listbox",
263
+ "data-oc-address-popover": "",
264
+ className: popoverClassName,
265
+ style: {
266
+ position: "absolute",
267
+ zIndex: 50,
268
+ top: "calc(100% + 4px)",
269
+ left: 0,
270
+ right: 0
271
+ },
272
+ onMouseDown: (e) => e.preventDefault(),
273
+ children: /* @__PURE__ */ jsxs(
274
+ "button",
275
+ {
276
+ type: "button",
277
+ id: optionId,
278
+ role: "option",
279
+ "aria-selected": highlighted,
280
+ "data-oc-address-suggestion": "",
281
+ "data-highlighted": highlighted ? "" : void 0,
282
+ className: suggestionClassName,
283
+ onClick: selectSuggestion,
284
+ onMouseEnter: () => setHighlighted(true),
285
+ onMouseLeave: () => setHighlighted(false),
286
+ style: {
287
+ display: "flex",
288
+ alignItems: "center",
289
+ justifyContent: "space-between",
290
+ gap: "0.75rem",
291
+ width: "100%",
292
+ textAlign: "left",
293
+ cursor: "pointer",
294
+ font: "inherit",
295
+ background: "inherit",
296
+ color: "inherit",
297
+ border: 0,
298
+ padding: "inherit"
299
+ },
300
+ children: [
301
+ /* @__PURE__ */ jsx("span", { "data-oc-address-suggestion-label": "", children: suggestionLabel }),
302
+ /* @__PURE__ */ jsx(
303
+ "span",
304
+ {
305
+ "data-oc-address-suggestion-value": "",
306
+ style: { fontFamily: "ui-monospace, monospace" },
307
+ children: shortenAddressMid(sessionAddress)
308
+ }
309
+ )
310
+ ]
311
+ }
312
+ )
313
+ }
314
+ ) : null;
315
+ return { inputProps, popover };
316
+ }
190
317
  var OcAddressInput = React.forwardRef(
191
318
  function OcAddressInput2({
192
319
  value,
@@ -351,6 +478,6 @@ var OcAddressInput = React.forwardRef(
351
478
  }
352
479
  );
353
480
 
354
- export { DEFAULT_CONFIG, OcAccountPill, OcAddressInput, OcSessionProvider, OcSignInButton, buildSignInUrl, useOcSession, useOptionalOcSession };
481
+ export { DEFAULT_CONFIG, OcAccountPill, OcAddressInput, OcSessionProvider, OcSignInButton, buildSignInUrl, useOcAddressSuggestion, useOcSession, useOptionalOcSession };
355
482
  //# sourceMappingURL=index.mjs.map
356
483
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts","../src/provider.tsx","../src/components.tsx"],"names":["React2","jsx","OcAddressInput"],"mappings":";;;;;;AAiDO,IAAM,cAAA,GAAyC;AAAA,EAClD,UAAA,EAAY,iBAAA;AAAA,EACZ,UAAA,EAAY,SAAA;AAAA,EACZ,MAAA,EAAQ,cAAA;AAAA,EACR,UAAA,EAAY;AAChB;AAEO,SAAS,cAAc,GAAA,EAAuD;AACjF,EAAA,OAAO,EAAE,GAAG,c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AC3B,kBAAA,EAAkB,cAAc,EAAA,GAAK,MAAA;AAAA,kBACrC,SAAA,EAAW,mBAAA;AAAA,kBACX,OAAA,EAAS,gBAAA;AAAA,kBACT,YAAA,EAAc,MAAM,cAAA,CAAe,IAAI,CAAA;AAAA,kBACvC,YAAA,EAAc,MAAM,cAAA,CAAe,KAAK,CAAA;AAAA,kBACxC,KAAA,EAAO;AAAA,oBACH,OAAA,EAAS,MAAA;AAAA,oBACT,UAAA,EAAY,QAAA;AAAA,oBACZ,cAAA,EAAgB,eAAA;AAAA,oBAChB,GAAA,EAAK,SAAA;AAAA,oBACL,KAAA,EAAO,MAAA;AAAA,oBACP,SAAA,EAAW,MAAA;AAAA,oBACX,MAAA,EAAQ,SAAA;AAAA,oBACR,IAAA,EAAM,SAAA;AAAA,oBACN,UAAA,EAAY,SAAA;AAAA,oBACZ,KAAA,EAAO,SAAA;AAAA,oBACP,MAAA,EAAQ,SAAA;AAAA,oBACR,OAAA,EAAS;AAAA,mBACb;AAAA,kBAEA,QAAA,EAAA;AAAA,oCAAAA,GAAAA,CAAC,MAAA,EAAA,EAAK,kCAAA,EAAiC,EAAA,EAAI,QAAA,EAAA,eAAA,EAAgB,CAAA;AAAA,oCAC3DA,GAAAA;AAAA,sBAAC,MAAA;AAAA,sBAAA;AAAA,wBACG,kCAAA,EAAiC,EAAA;AAAA,wBACjC,KAAA,EAAO,EAAE,UAAA,EAAY,yBAAA,EAA0B;AAAA,wBAE9C,4BAAkB,cAAc;AAAA;AAAA;AACrC;AAAA;AAAA;AACJ;AAAA;AACJ;AAAA;AAAA,KAER;AAAA,EAER;AACJ","file":"index.mjs","sourcesContent":["export interface OcAccount {\n accountId: string;\n address: string;\n displayName?: string | null;\n nostrNpub?: string | null;\n}\n\nexport type OcSessionStatus = 'loading' | 'authenticated' | 'anonymous' | 'error';\n\nexport interface OcSessionState {\n status: OcSessionStatus;\n account: OcAccount | null;\n /** `null` while loading; an `Error` instance when `status === 'error'`. */\n error: Error | null;\n /** Re-fetch the session. Useful after sign-in/sign-out happens elsewhere. */\n refresh: () => Promise<void>;\n /** Trigger a sign-out. Resolves once the cookie has been cleared. */\n signOut: () => Promise<void>;\n /** URL to navigate to for sign-in on the auth host. */\n signInUrl: string;\n}\n\nexport interface OcAuthConfig {\n /**\n * Origin of the auth host — the subdomain that runs the sign-in UI,\n * issues session cookies, and exposes `/api/auth/me` + `/api/auth/logout`.\n *\n * Defaults to `https://ochk.io`. Override in preview/dev.\n */\n authOrigin?: string;\n /**\n * Path on the auth host that accepts `?return_to=<url>` and drives the\n * BIP-322 sign-in flow. Defaults to `/signin`.\n */\n signInPath?: string;\n /**\n * Local path (same origin as the current app) that exposes the\n * crypto-verified session. If your app ships one at `/api/auth/me`,\n * leave as default. Returns 200 `{ account }` or 401.\n */\n mePath?: string;\n /**\n * Path on the auth host to hit to clear the session cookie.\n * Defaults to `/api/auth/logout`. Called with `credentials: 'include'`\n * so the `.ochk.io` cookie is sent along.\n */\n logoutPath?: string;\n}\n\nexport const DEFAULT_CONFIG: Required<OcAuthConfig> = {\n authOrigin: 'https://ochk.io',\n signInPath: '/signin',\n mePath: '/api/auth/me',\n logoutPath: '/api/auth/logout',\n};\n\nexport function resolveConfig(cfg: OcAuthConfig | undefined): Required<OcAuthConfig> {\n return { ...DEFAULT_CONFIG, ...(cfg ?? {}) };\n}\n\nexport function buildSignInUrl(cfg: Required<OcAuthConfig>, returnTo?: string): string {\n const base = `${cfg.authOrigin}${cfg.signInPath}`;\n if (!returnTo) return base;\n const u = new URL(base);\n u.searchParams.set('return_to', returnTo);\n return u.toString();\n}\n","import * as React from 'react';\n\nimport {\n buildSignInUrl,\n DEFAULT_CONFIG,\n resolveConfig,\n type OcAccount,\n type OcAuthConfig,\n type OcSessionState,\n} from './types';\n\nconst SessionContext = React.createContext<OcSessionState | null>(null);\n\ninterface MeResponse {\n account?: {\n id?: string;\n account_id?: string;\n accountId?: string;\n btc_address?: string;\n address?: string;\n display_name?: string | null;\n displayName?: string | null;\n nostr_npub?: string | null;\n nostrNpub?: string | null;\n };\n}\n\nfunction normalizeAccount(raw: MeResponse['account']): OcAccount | null {\n if (!raw) return null;\n const address = raw.btc_address ?? raw.address;\n const accountId = raw.id ?? raw.account_id ?? raw.accountId;\n if (!address || !accountId) return null;\n return {\n accountId,\n address,\n displayName: raw.display_name ?? raw.displayName ?? null,\n nostrNpub: raw.nostr_npub ?? raw.nostrNpub ?? null,\n };\n}\n\nexport interface OcSessionProviderProps {\n children: React.ReactNode;\n config?: OcAuthConfig;\n /**\n * Optional return URL passed to the sign-in page. Defaults to the\n * current `window.location.href` at click-time.\n */\n defaultReturnTo?: string;\n}\n\n/**\n * Top-level provider that exposes the cross-subdomain oc_session to every\n * component below it. Mount once, near the root of your tree.\n */\nexport function OcSessionProvider({\n children,\n config,\n defaultReturnTo,\n}: OcSessionProviderProps): React.ReactElement {\n const cfg = React.useMemo(() => resolveConfig(config), [config]);\n const [account, setAccount] = React.useState<OcAccount | null>(null);\n const [status, setStatus] = React.useState<OcSessionState['status']>('loading');\n const [error, setError] = React.useState<Error | null>(null);\n\n const refresh = React.useCallback(async () => {\n if (typeof window === 'undefined') return;\n try {\n const res = await fetch(cfg.mePath, {\n method: 'GET',\n credentials: 'include',\n headers: { Accept: 'application/json' },\n });\n if (res.status === 401) {\n setAccount(null);\n setStatus('anonymous');\n setError(null);\n return;\n }\n if (!res.ok) {\n setStatus('error');\n setError(new Error(`me endpoint returned ${res.status}`));\n return;\n }\n const body = (await res.json()) as MeResponse;\n const acct = normalizeAccount(body.account);\n setAccount(acct);\n setStatus(acct ? 'authenticated' : 'anonymous');\n setError(null);\n } catch (err) {\n setStatus('error');\n setError(err instanceof Error ? err : new Error(String(err)));\n }\n }, [cfg.mePath]);\n\n React.useEffect(() => {\n void refresh();\n }, [refresh]);\n\n const signOut = React.useCallback(async () => {\n try {\n await fetch(`${cfg.authOrigin}${cfg.logoutPath}`, {\n method: 'POST',\n credentials: 'include',\n });\n } catch {\n // fall through — we still clear local state so the UI reflects\n // the user's intent even if the server round-trip fails.\n }\n setAccount(null);\n setStatus('anonymous');\n }, [cfg.authOrigin, cfg.logoutPath]);\n\n const value = React.useMemo<OcSessionState>(() => {\n const returnTo =\n defaultReturnTo ?? (typeof window !== 'undefined' ? window.location.href : undefined);\n return {\n status,\n account,\n error,\n refresh,\n signOut,\n signInUrl: buildSignInUrl(cfg, returnTo),\n };\n }, [status, account, error, refresh, signOut, cfg, defaultReturnTo]);\n\n return <SessionContext.Provider value={value}>{children}</SessionContext.Provider>;\n}\n\n/**\n * Access the current cross-subdomain oc_session. Must be called inside\n * an `<OcSessionProvider>`.\n */\nexport function useOcSession(): OcSessionState {\n const ctx = React.useContext(SessionContext);\n if (!ctx) {\n throw new Error(\n '[@orangecheck/auth-client] useOcSession() must be called inside <OcSessionProvider>'\n );\n }\n return ctx;\n}\n\n/**\n * Non-throwing variant — returns `null` if called outside a provider.\n * Useful for libraries that want to read the session *if it exists* but\n * shouldn't crash on apps that haven't opted in.\n */\nexport function useOptionalOcSession(): OcSessionState | null {\n return React.useContext(SessionContext);\n}\n\nexport { DEFAULT_CONFIG };\n","import * as React from 'react';\n\nimport { useOcSession } from './provider';\n\nfunction shortenAddress(addr: string): string {\n if (addr.length <= 12) return addr;\n return `${addr.slice(0, 6)}…${addr.slice(-4)}`;\n}\n\nfunction shortenAddressMid(addr: string): string {\n if (addr.length <= 16) return addr;\n return `${addr.slice(0, 8)}…${addr.slice(-6)}`;\n}\n\nfunction isPrefixOf(value: string, target: string): boolean {\n return target.toLowerCase().startsWith(value.toLowerCase());\n}\n\nlet listboxIdCounter = 0;\nfunction useUniqueId(prefix: string): string {\n const [id] = React.useState(() => `${prefix}-${++listboxIdCounter}`);\n return id;\n}\n\nexport interface OcSignInButtonProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {\n /** Label shown when no user is signed in. Defaults to `sign in with bitcoin`. */\n label?: string;\n /**\n * When `true`, render an `<a>` even while the session is loading, to\n * avoid layout shift. Defaults to `false` (renders nothing while loading).\n */\n eager?: boolean;\n}\n\n/**\n * Drop-in sign-in button. Renders an anchor that deep-links to the auth\n * host's sign-in page with the current URL as `?return_to=…`.\n *\n * When the user is already authenticated it renders nothing — wrap it in\n * a conditional or use `<OcAccountPill>` as the signed-in affordance.\n */\nexport function OcSignInButton({\n label = 'sign in with bitcoin',\n eager = false,\n className,\n ...rest\n}: OcSignInButtonProps): React.ReactElement | null {\n const { status, signInUrl } = useOcSession();\n if (status === 'authenticated') return null;\n if (!eager && status === 'loading') return null;\n\n return (\n <a\n {...rest}\n href={signInUrl}\n className={className}\n data-oc-sign-in-button=\"\"\n >\n {label}\n </a>\n );\n}\n\nexport interface OcAccountPillProps extends React.HTMLAttributes<HTMLDivElement> {\n /** URL to link the address to. Defaults to the auth origin's `/dashboard`. */\n dashboardUrl?: string;\n /** Override the display text. Defaults to the shortened address. */\n render?: (account: { address: string; displayName?: string | null }) => React.ReactNode;\n}\n\n/**\n * Shows the signed-in user as a short pill: `bc1q…abcd sign out`.\n *\n * Renders nothing while loading or when no user is signed in — pair with\n * `<OcSignInButton>` for the anonymous case.\n */\nexport function OcAccountPill({\n dashboardUrl,\n render,\n className,\n ...rest\n}: OcAccountPillProps): React.ReactElement | null {\n const { status, account, signOut } = useOcSession();\n\n if (status !== 'authenticated' || !account) return null;\n\n const label = render\n ? render({ address: account.address, displayName: account.displayName })\n : (account.displayName ?? shortenAddress(account.address));\n\n return (\n <div\n {...rest}\n className={className}\n data-oc-account-pill=\"\"\n style={{ display: 'inline-flex', alignItems: 'center', gap: '0.5rem', ...(rest.style ?? {}) }}\n >\n {dashboardUrl ? (\n <a href={dashboardUrl}>{label}</a>\n ) : (\n <span>{label}</span>\n )}\n <button\n type=\"button\"\n onClick={() => {\n void signOut();\n }}\n aria-label=\"Sign out\"\n style={{\n background: 'none',\n border: 'none',\n cursor: 'pointer',\n color: 'inherit',\n font: 'inherit',\n padding: 0,\n }}\n >\n sign out\n </button>\n </div>\n );\n}\n\nexport interface OcAddressInputProps\n extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange'> {\n /** Controlled value. */\n value: string;\n /** Called when value changes — typed by the user OR selected from the popover. */\n onValueChange: (value: string) => void;\n /** Label shown above the suggested address in the popover. Defaults to `use your address`. */\n suggestionLabel?: string;\n /** className applied to the wrapper `<div>`. */\n wrapperClassName?: string;\n /** className applied to the suggestion popover. Style with `[data-oc-address-popover]` otherwise. */\n popoverClassName?: string;\n /** className applied to the suggestion button. Style with `[data-oc-address-suggestion]` otherwise. */\n suggestionClassName?: string;\n}\n\n/**\n * Bitcoin-address `<input>` that, when the user is signed in via `oc_session`,\n * surfaces their address as a one-click suggestion on focus.\n *\n * Behaviour:\n * - On focus, if logged-in AND the typed value is a prefix of the session\n * address (or empty), show a small popover with `bc1q…7ke3` as a clickable\n * suggestion.\n * - Click / Enter on the suggestion fills the field with the full address.\n * - Down-arrow from the input highlights the suggestion; Up-arrow clears the\n * highlight; Escape closes the popover; clicking outside closes the popover.\n * - When the user types something that's no longer a prefix of the session\n * address, the popover hides itself out of the way.\n * - When the field already contains the session address exactly, no popover.\n *\n * Style-agnostic: minimal inline styles for positioning only. Style the parts\n * via `wrapperClassName` / `popoverClassName` / `suggestionClassName`, or via\n * the `[data-oc-address-input]`, `[data-oc-address-popover]`, and\n * `[data-oc-address-suggestion]` data attributes.\n */\nexport const OcAddressInput = React.forwardRef<HTMLInputElement, OcAddressInputProps>(\n function OcAddressInput(\n {\n value,\n onValueChange,\n suggestionLabel = 'use your address',\n wrapperClassName,\n popoverClassName,\n suggestionClassName,\n onFocus,\n onBlur,\n onKeyDown,\n ...rest\n },\n forwardedRef\n ): React.ReactElement {\n const { status, account } = useOcSession();\n const sessionAddress = status === 'authenticated' ? (account?.address ?? null) : null;\n\n const [open, setOpen] = React.useState(false);\n const [highlighted, setHighlighted] = React.useState(false);\n\n const innerRef = React.useRef<HTMLInputElement | null>(null);\n const setRef = (node: HTMLInputElement | null) => {\n innerRef.current = node;\n if (typeof forwardedRef === 'function') forwardedRef(node);\n else if (forwardedRef) forwardedRef.current = node;\n };\n const blurTimer = React.useRef<number | null>(null);\n\n const listboxId = useUniqueId('oc-addr-listbox');\n const optionId = `${listboxId}-opt`;\n\n const valueMatchesSession =\n sessionAddress != null && value.toLowerCase() === sessionAddress.toLowerCase();\n const canSuggest =\n sessionAddress != null &&\n sessionAddress.length > 0 &&\n !valueMatchesSession &&\n isPrefixOf(value, sessionAddress);\n const showPopover = open && canSuggest;\n\n function selectSuggestion() {\n if (!sessionAddress) return;\n onValueChange(sessionAddress);\n setOpen(false);\n setHighlighted(false);\n // Re-focus so the next Tab moves on naturally.\n innerRef.current?.focus();\n }\n\n function handleFocus(e: React.FocusEvent<HTMLInputElement>) {\n if (blurTimer.current != null) {\n window.clearTimeout(blurTimer.current);\n blurTimer.current = null;\n }\n setOpen(true);\n onFocus?.(e);\n }\n\n function handleBlur(e: React.FocusEvent<HTMLInputElement>) {\n // Defer close so a click on the suggestion can register first.\n blurTimer.current = window.setTimeout(() => {\n setOpen(false);\n setHighlighted(false);\n }, 120);\n onBlur?.(e);\n }\n\n function handleKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {\n if (showPopover) {\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n setHighlighted(true);\n } else if (e.key === 'ArrowUp') {\n e.preventDefault();\n setHighlighted(false);\n } else if (e.key === 'Escape') {\n e.preventDefault();\n setOpen(false);\n setHighlighted(false);\n } else if (e.key === 'Enter' && highlighted) {\n e.preventDefault();\n selectSuggestion();\n }\n }\n onKeyDown?.(e);\n }\n\n React.useEffect(() => {\n return () => {\n if (blurTimer.current != null) window.clearTimeout(blurTimer.current);\n };\n }, []);\n\n return (\n <div\n data-oc-address-input=\"\"\n className={wrapperClassName}\n style={{ position: 'relative' }}\n >\n <input\n {...rest}\n ref={setRef}\n value={value}\n onChange={(e) => onValueChange(e.target.value)}\n onFocus={handleFocus}\n onBlur={handleBlur}\n onKeyDown={handleKeyDown}\n role=\"combobox\"\n aria-haspopup=\"listbox\"\n aria-expanded={showPopover}\n aria-controls={showPopover ? listboxId : undefined}\n aria-activedescendant={highlighted ? optionId : undefined}\n autoComplete=\"off\"\n spellCheck={false}\n />\n {showPopover && sessionAddress && (\n <div\n id={listboxId}\n role=\"listbox\"\n data-oc-address-popover=\"\"\n className={popoverClassName}\n style={{\n position: 'absolute',\n zIndex: 50,\n top: 'calc(100% + 4px)',\n left: 0,\n right: 0,\n }}\n // Prevent the input from blurring before the click on the suggestion lands.\n onMouseDown={(e) => e.preventDefault()}\n >\n <button\n type=\"button\"\n id={optionId}\n role=\"option\"\n aria-selected={highlighted}\n data-oc-address-suggestion=\"\"\n data-highlighted={highlighted ? '' : undefined}\n className={suggestionClassName}\n onClick={selectSuggestion}\n onMouseEnter={() => setHighlighted(true)}\n onMouseLeave={() => setHighlighted(false)}\n style={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: '0.75rem',\n width: '100%',\n textAlign: 'left',\n cursor: 'pointer',\n font: 'inherit',\n background: 'inherit',\n color: 'inherit',\n border: 'inherit',\n padding: 'inherit',\n }}\n >\n <span data-oc-address-suggestion-label=\"\">{suggestionLabel}</span>\n <span\n data-oc-address-suggestion-value=\"\"\n style={{ fontFamily: 'ui-monospace, monospace' }}\n >\n {shortenAddressMid(sessionAddress)}\n </span>\n </button>\n </div>\n )}\n </div>\n );\n }\n);\n"]}
1
+ {"version":3,"sources":["../src/types.ts","../src/provider.tsx","../src/components.tsx"],"names":["React2","jsx","OcAddressInput"],"mappings":";;;;;;AAiDO,IAAM,cAAA,GAAyC;AAAA,EAClD,UAAA,EAAY,iBAAA;AAAA,EACZ,UAAA,EAAY,SAAA;AAAA,EACZ,MAAA,EAAQ,cAAA;AAAA,EACR,UAAA,EAAY;AAChB;AAEO,SAAS,cAAc,GAAA,EAAuD;AACjF,EAAA,OAAO,EAAE,GAAG,cAAA,EAAgB,GAAI,GAAA,IAAO,EAAC,EAAG;AAC/C;AAEO,SA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AA;AAAA,oBACR,OAAA,EAAS;AAAA,mBACb;AAAA,kBAEA,QAAA,EAAA;AAAA,oCAAAA,GAAAA,CAAC,MAAA,EAAA,EAAK,kCAAA,EAAiC,EAAA,EAAI,QAAA,EAAA,eAAA,EAAgB,CAAA;AAAA,oCAC3DA,GAAAA;AAAA,sBAAC,MAAA;AAAA,sBAAA;AAAA,wBACG,kCAAA,EAAiC,EAAA;AAAA,wBACjC,KAAA,EAAO,EAAE,UAAA,EAAY,yBAAA,EAA0B;AAAA,wBAE9C,4BAAkB,cAAc;AAAA;AAAA;AACrC;AAAA;AAAA;AACJ;AAAA;AACJ;AAAA;AAAA,KAER;AAAA,EAER;AACJ","file":"index.mjs","sourcesContent":["export interface OcAccount {\n accountId: string;\n address: string;\n displayName?: string | null;\n nostrNpub?: string | null;\n}\n\nexport type OcSessionStatus = 'loading' | 'authenticated' | 'anonymous' | 'error';\n\nexport interface OcSessionState {\n status: OcSessionStatus;\n account: OcAccount | null;\n /** `null` while loading; an `Error` instance when `status === 'error'`. */\n error: Error | null;\n /** Re-fetch the session. Useful after sign-in/sign-out happens elsewhere. */\n refresh: () => Promise<void>;\n /** Trigger a sign-out. Resolves once the cookie has been cleared. */\n signOut: () => Promise<void>;\n /** URL to navigate to for sign-in on the auth host. */\n signInUrl: string;\n}\n\nexport interface OcAuthConfig {\n /**\n * Origin of the auth host — the subdomain that runs the sign-in UI,\n * issues session cookies, and exposes `/api/auth/me` + `/api/auth/logout`.\n *\n * Defaults to `https://ochk.io`. Override in preview/dev.\n */\n authOrigin?: string;\n /**\n * Path on the auth host that accepts `?return_to=<url>` and drives the\n * BIP-322 sign-in flow. Defaults to `/signin`.\n */\n signInPath?: string;\n /**\n * Local path (same origin as the current app) that exposes the\n * crypto-verified session. If your app ships one at `/api/auth/me`,\n * leave as default. Returns 200 `{ account }` or 401.\n */\n mePath?: string;\n /**\n * Path on the auth host to hit to clear the session cookie.\n * Defaults to `/api/auth/logout`. Called with `credentials: 'include'`\n * so the `.ochk.io` cookie is sent along.\n */\n logoutPath?: string;\n}\n\nexport const DEFAULT_CONFIG: Required<OcAuthConfig> = {\n authOrigin: 'https://ochk.io',\n signInPath: '/signin',\n mePath: '/api/auth/me',\n logoutPath: '/api/auth/logout',\n};\n\nexport function resolveConfig(cfg: OcAuthConfig | undefined): Required<OcAuthConfig> {\n return { ...DEFAULT_CONFIG, ...(cfg ?? {}) };\n}\n\nexport function buildSignInUrl(cfg: Required<OcAuthConfig>, returnTo?: string): string {\n const base = `${cfg.authOrigin}${cfg.signInPath}`;\n if (!returnTo) return base;\n const u = new URL(base);\n u.searchParams.set('return_to', returnTo);\n return u.toString();\n}\n","import * as React from 'react';\n\nimport {\n buildSignInUrl,\n DEFAULT_CONFIG,\n resolveConfig,\n type OcAccount,\n type OcAuthConfig,\n type OcSessionState,\n} from './types';\n\nconst SessionContext = React.createContext<OcSessionState | null>(null);\n\ninterface MeResponse {\n account?: {\n id?: string;\n account_id?: string;\n accountId?: string;\n btc_address?: string;\n address?: string;\n display_name?: string | null;\n displayName?: string | null;\n nostr_npub?: string | null;\n nostrNpub?: string | null;\n };\n}\n\nfunction normalizeAccount(raw: MeResponse['account']): OcAccount | null {\n if (!raw) return null;\n const address = raw.btc_address ?? raw.address;\n const accountId = raw.id ?? raw.account_id ?? raw.accountId;\n if (!address || !accountId) return null;\n return {\n accountId,\n address,\n displayName: raw.display_name ?? raw.displayName ?? null,\n nostrNpub: raw.nostr_npub ?? raw.nostrNpub ?? null,\n };\n}\n\nexport interface OcSessionProviderProps {\n children: React.ReactNode;\n config?: OcAuthConfig;\n /**\n * Optional return URL passed to the sign-in page. Defaults to the\n * current `window.location.href` at click-time.\n */\n defaultReturnTo?: string;\n}\n\n/**\n * Top-level provider that exposes the cross-subdomain oc_session to every\n * component below it. Mount once, near the root of your tree.\n */\nexport function OcSessionProvider({\n children,\n config,\n defaultReturnTo,\n}: OcSessionProviderProps): React.ReactElement {\n const cfg = React.useMemo(() => resolveConfig(config), [config]);\n const [account, setAccount] = React.useState<OcAccount | null>(null);\n const [status, setStatus] = React.useState<OcSessionState['status']>('loading');\n const [error, setError] = React.useState<Error | null>(null);\n\n const refresh = React.useCallback(async () => {\n if (typeof window === 'undefined') return;\n try {\n const res = await fetch(cfg.mePath, {\n method: 'GET',\n credentials: 'include',\n headers: { Accept: 'application/json' },\n });\n if (res.status === 401) {\n setAccount(null);\n setStatus('anonymous');\n setError(null);\n return;\n }\n if (!res.ok) {\n setStatus('error');\n setError(new Error(`me endpoint returned ${res.status}`));\n return;\n }\n const body = (await res.json()) as MeResponse;\n const acct = normalizeAccount(body.account);\n setAccount(acct);\n setStatus(acct ? 'authenticated' : 'anonymous');\n setError(null);\n } catch (err) {\n setStatus('error');\n setError(err instanceof Error ? err : new Error(String(err)));\n }\n }, [cfg.mePath]);\n\n React.useEffect(() => {\n void refresh();\n }, [refresh]);\n\n const signOut = React.useCallback(async () => {\n try {\n await fetch(`${cfg.authOrigin}${cfg.logoutPath}`, {\n method: 'POST',\n credentials: 'include',\n });\n } catch {\n // fall through — we still clear local state so the UI reflects\n // the user's intent even if the server round-trip fails.\n }\n setAccount(null);\n setStatus('anonymous');\n }, [cfg.authOrigin, cfg.logoutPath]);\n\n const value = React.useMemo<OcSessionState>(() => {\n const returnTo =\n defaultReturnTo ?? (typeof window !== 'undefined' ? window.location.href : undefined);\n return {\n status,\n account,\n error,\n refresh,\n signOut,\n signInUrl: buildSignInUrl(cfg, returnTo),\n };\n }, [status, account, error, refresh, signOut, cfg, defaultReturnTo]);\n\n return <SessionContext.Provider value={value}>{children}</SessionContext.Provider>;\n}\n\n/**\n * Access the current cross-subdomain oc_session. Must be called inside\n * an `<OcSessionProvider>`.\n */\nexport function useOcSession(): OcSessionState {\n const ctx = React.useContext(SessionContext);\n if (!ctx) {\n throw new Error(\n '[@orangecheck/auth-client] useOcSession() must be called inside <OcSessionProvider>'\n );\n }\n return ctx;\n}\n\n/**\n * Non-throwing variant — returns `null` if called outside a provider.\n * Useful for libraries that want to read the session *if it exists* but\n * shouldn't crash on apps that haven't opted in.\n */\nexport function useOptionalOcSession(): OcSessionState | null {\n return React.useContext(SessionContext);\n}\n\nexport { DEFAULT_CONFIG };\n","import * as React from 'react';\n\nimport { useOcSession } from './provider';\n\nfunction shortenAddress(addr: string): string {\n if (addr.length <= 12) return addr;\n return `${addr.slice(0, 6)}…${addr.slice(-4)}`;\n}\n\nfunction shortenAddressMid(addr: string): string {\n if (addr.length <= 16) return addr;\n return `${addr.slice(0, 8)}…${addr.slice(-6)}`;\n}\n\nfunction isPrefixOf(value: string, target: string): boolean {\n return target.toLowerCase().startsWith(value.toLowerCase());\n}\n\nlet listboxIdCounter = 0;\nfunction useUniqueId(prefix: string): string {\n const [id] = React.useState(() => `${prefix}-${++listboxIdCounter}`);\n return id;\n}\n\nexport interface OcSignInButtonProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {\n /** Label shown when no user is signed in. Defaults to `sign in with bitcoin`. */\n label?: string;\n /**\n * When `true`, render an `<a>` even while the session is loading, to\n * avoid layout shift. Defaults to `false` (renders nothing while loading).\n */\n eager?: boolean;\n}\n\n/**\n * Drop-in sign-in button. Renders an anchor that deep-links to the auth\n * host's sign-in page with the current URL as `?return_to=…`.\n *\n * When the user is already authenticated it renders nothing — wrap it in\n * a conditional or use `<OcAccountPill>` as the signed-in affordance.\n */\nexport function OcSignInButton({\n label = 'sign in with bitcoin',\n eager = false,\n className,\n ...rest\n}: OcSignInButtonProps): React.ReactElement | null {\n const { status, signInUrl } = useOcSession();\n if (status === 'authenticated') return null;\n if (!eager && status === 'loading') return null;\n\n return (\n <a\n {...rest}\n href={signInUrl}\n className={className}\n data-oc-sign-in-button=\"\"\n >\n {label}\n </a>\n );\n}\n\nexport interface OcAccountPillProps extends React.HTMLAttributes<HTMLDivElement> {\n /** URL to link the address to. Defaults to the auth origin's `/dashboard`. */\n dashboardUrl?: string;\n /** Override the display text. Defaults to the shortened address. */\n render?: (account: { address: string; displayName?: string | null }) => React.ReactNode;\n}\n\n/**\n * Shows the signed-in user as a short pill: `bc1q…abcd sign out`.\n *\n * Renders nothing while loading or when no user is signed in — pair with\n * `<OcSignInButton>` for the anonymous case.\n */\nexport function OcAccountPill({\n dashboardUrl,\n render,\n className,\n ...rest\n}: OcAccountPillProps): React.ReactElement | null {\n const { status, account, signOut } = useOcSession();\n\n if (status !== 'authenticated' || !account) return null;\n\n const label = render\n ? render({ address: account.address, displayName: account.displayName })\n : (account.displayName ?? shortenAddress(account.address));\n\n return (\n <div\n {...rest}\n className={className}\n data-oc-account-pill=\"\"\n style={{ display: 'inline-flex', alignItems: 'center', gap: '0.5rem', ...(rest.style ?? {}) }}\n >\n {dashboardUrl ? (\n <a href={dashboardUrl}>{label}</a>\n ) : (\n <span>{label}</span>\n )}\n <button\n type=\"button\"\n onClick={() => {\n void signOut();\n }}\n aria-label=\"Sign out\"\n style={{\n background: 'none',\n border: 'none',\n cursor: 'pointer',\n color: 'inherit',\n font: 'inherit',\n padding: 0,\n }}\n >\n sign out\n </button>\n </div>\n );\n}\n\nexport interface OcAddressInputProps\n extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange'> {\n /** Controlled value. */\n value: string;\n /** Called when value changes — typed by the user OR selected from the popover. */\n onValueChange: (value: string) => void;\n /** Label shown above the suggested address in the popover. Defaults to `use your address`. */\n suggestionLabel?: string;\n /** className applied to the wrapper `<div>`. */\n wrapperClassName?: string;\n /** className applied to the suggestion popover. Style with `[data-oc-address-popover]` otherwise. */\n popoverClassName?: string;\n /** className applied to the suggestion button. Style with `[data-oc-address-suggestion]` otherwise. */\n suggestionClassName?: string;\n}\n\n/**\n * Bitcoin-address `<input>` that, when the user is signed in via `oc_session`,\n * surfaces their address as a one-click suggestion on focus.\n *\n * Behaviour:\n * - On focus, if logged-in AND the typed value is a prefix of the session\n * address (or empty), show a small popover with `bc1q…7ke3` as a clickable\n * suggestion.\n * - Click / Enter on the suggestion fills the field with the full address.\n * - Down-arrow from the input highlights the suggestion; Up-arrow clears the\n * highlight; Escape closes the popover; clicking outside closes the popover.\n * - When the user types something that's no longer a prefix of the session\n * address, the popover hides itself out of the way.\n * - When the field already contains the session address exactly, no popover.\n *\n * Style-agnostic: minimal inline styles for positioning only. Style the parts\n * via `wrapperClassName` / `popoverClassName` / `suggestionClassName`, or via\n * the `[data-oc-address-input]`, `[data-oc-address-popover]`, and\n * `[data-oc-address-suggestion]` data attributes.\n */\nexport interface UseOcAddressSuggestionOptions {\n /** Current value of the input. */\n value: string;\n /** Called when the user selects the suggestion (or you may also call it from the input's onChange). */\n onValueChange: (value: string) => void;\n /** Label shown above the suggested address in the popover. Defaults to `use your address`. */\n suggestionLabel?: string;\n /** className applied to the suggestion popover. Style with `[data-oc-address-popover]` otherwise. */\n popoverClassName?: string;\n /** className applied to the suggestion button. Style with `[data-oc-address-suggestion]` otherwise. */\n suggestionClassName?: string;\n}\n\nexport interface UseOcAddressSuggestionReturn {\n /**\n * Props to spread onto your `<input>` element. Adds focus/blur/keydown\n * handlers and the combobox ARIA attributes. Combine with your existing\n * `value`/`onChange` props — this hook does NOT control them.\n */\n inputProps: {\n onFocus: (e: React.FocusEvent<HTMLInputElement>) => void;\n onBlur: (e: React.FocusEvent<HTMLInputElement>) => void;\n onKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => void;\n role: 'combobox';\n 'aria-haspopup': 'listbox';\n 'aria-expanded': boolean;\n 'aria-controls': string | undefined;\n 'aria-activedescendant': string | undefined;\n autoComplete: 'off';\n spellCheck: false;\n };\n /**\n * The suggestion popover. Render directly after your `<input>`, inside a\n * `position: relative` container so the popover anchors below the input.\n * Returns `null` when there's no suggestion to show.\n */\n popover: React.ReactNode;\n}\n\n/**\n * Hook variant of `OcAddressInput`. Use when you want to keep your existing\n * styled `<input>` (e.g. shadcn `<Input>`) and just bolt on the\n * session-address suggestion behaviour.\n *\n * Wrap your input in a `position: relative` container, spread `inputProps`\n * onto the input, and render `{popover}` immediately after. The hook's\n * focus / blur / keydown handlers are composed via `inputProps` — they call\n * any handlers you've already passed to your input only when you wire them\n * yourself in addition to spreading `inputProps`.\n *\n * Example:\n * ```tsx\n * const { inputProps, popover } = useOcAddressSuggestion({\n * value: addr,\n * onValueChange: setAddr,\n * });\n * return (\n * <div className=\"relative\">\n * <Input\n * value={addr}\n * onChange={(e) => setAddr(e.target.value)}\n * {...inputProps}\n * placeholder=\"bc1q…\"\n * />\n * {popover}\n * </div>\n * );\n * ```\n */\nexport function useOcAddressSuggestion(\n options: UseOcAddressSuggestionOptions\n): UseOcAddressSuggestionReturn {\n const {\n value,\n onValueChange,\n suggestionLabel = 'use your address',\n popoverClassName,\n suggestionClassName,\n } = options;\n\n const { status, account } = useOcSession();\n const sessionAddress = status === 'authenticated' ? (account?.address ?? null) : null;\n\n const [open, setOpen] = React.useState(false);\n const [highlighted, setHighlighted] = React.useState(false);\n const blurTimer = React.useRef<number | null>(null);\n\n const listboxId = useUniqueId('oc-addr-listbox');\n const optionId = `${listboxId}-opt`;\n\n const valueMatchesSession =\n sessionAddress != null && value.toLowerCase() === sessionAddress.toLowerCase();\n const canSuggest =\n sessionAddress != null &&\n sessionAddress.length > 0 &&\n !valueMatchesSession &&\n isPrefixOf(value, sessionAddress);\n const showPopover = open && canSuggest;\n\n function selectSuggestion() {\n if (!sessionAddress) return;\n onValueChange(sessionAddress);\n setOpen(false);\n setHighlighted(false);\n }\n\n React.useEffect(() => {\n return () => {\n if (blurTimer.current != null) window.clearTimeout(blurTimer.current);\n };\n }, []);\n\n const inputProps: UseOcAddressSuggestionReturn['inputProps'] = {\n onFocus: () => {\n if (blurTimer.current != null) {\n window.clearTimeout(blurTimer.current);\n blurTimer.current = null;\n }\n setOpen(true);\n },\n onBlur: () => {\n blurTimer.current = window.setTimeout(() => {\n setOpen(false);\n setHighlighted(false);\n }, 120);\n },\n onKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (!showPopover) return;\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n setHighlighted(true);\n } else if (e.key === 'ArrowUp') {\n e.preventDefault();\n setHighlighted(false);\n } else if (e.key === 'Escape') {\n e.preventDefault();\n setOpen(false);\n setHighlighted(false);\n } else if (e.key === 'Enter' && highlighted) {\n e.preventDefault();\n selectSuggestion();\n }\n },\n role: 'combobox',\n 'aria-haspopup': 'listbox',\n 'aria-expanded': showPopover,\n 'aria-controls': showPopover ? listboxId : undefined,\n 'aria-activedescendant': highlighted ? optionId : undefined,\n autoComplete: 'off',\n spellCheck: false,\n };\n\n const popover = showPopover && sessionAddress ? (\n <div\n id={listboxId}\n role=\"listbox\"\n data-oc-address-popover=\"\"\n className={popoverClassName}\n style={{\n position: 'absolute',\n zIndex: 50,\n top: 'calc(100% + 4px)',\n left: 0,\n right: 0,\n }}\n onMouseDown={(e) => e.preventDefault()}\n >\n <button\n type=\"button\"\n id={optionId}\n role=\"option\"\n aria-selected={highlighted}\n data-oc-address-suggestion=\"\"\n data-highlighted={highlighted ? '' : undefined}\n className={suggestionClassName}\n onClick={selectSuggestion}\n onMouseEnter={() => setHighlighted(true)}\n onMouseLeave={() => setHighlighted(false)}\n style={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: '0.75rem',\n width: '100%',\n textAlign: 'left',\n cursor: 'pointer',\n font: 'inherit',\n background: 'inherit',\n color: 'inherit',\n border: 0,\n padding: 'inherit',\n }}\n >\n <span data-oc-address-suggestion-label=\"\">{suggestionLabel}</span>\n <span\n data-oc-address-suggestion-value=\"\"\n style={{ fontFamily: 'ui-monospace, monospace' }}\n >\n {shortenAddressMid(sessionAddress)}\n </span>\n </button>\n </div>\n ) : null;\n\n return { inputProps, popover };\n}\n\nexport const OcAddressInput = React.forwardRef<HTMLInputElement, OcAddressInputProps>(\n function OcAddressInput(\n {\n value,\n onValueChange,\n suggestionLabel = 'use your address',\n wrapperClassName,\n popoverClassName,\n suggestionClassName,\n onFocus,\n onBlur,\n onKeyDown,\n ...rest\n },\n forwardedRef\n ): React.ReactElement {\n const { status, account } = useOcSession();\n const sessionAddress = status === 'authenticated' ? (account?.address ?? null) : null;\n\n const [open, setOpen] = React.useState(false);\n const [highlighted, setHighlighted] = React.useState(false);\n\n const innerRef = React.useRef<HTMLInputElement | null>(null);\n const setRef = (node: HTMLInputElement | null) => {\n innerRef.current = node;\n if (typeof forwardedRef === 'function') forwardedRef(node);\n else if (forwardedRef) forwardedRef.current = node;\n };\n const blurTimer = React.useRef<number | null>(null);\n\n const listboxId = useUniqueId('oc-addr-listbox');\n const optionId = `${listboxId}-opt`;\n\n const valueMatchesSession =\n sessionAddress != null && value.toLowerCase() === sessionAddress.toLowerCase();\n const canSuggest =\n sessionAddress != null &&\n sessionAddress.length > 0 &&\n !valueMatchesSession &&\n isPrefixOf(value, sessionAddress);\n const showPopover = open && canSuggest;\n\n function selectSuggestion() {\n if (!sessionAddress) return;\n onValueChange(sessionAddress);\n setOpen(false);\n setHighlighted(false);\n // Re-focus so the next Tab moves on naturally.\n innerRef.current?.focus();\n }\n\n function handleFocus(e: React.FocusEvent<HTMLInputElement>) {\n if (blurTimer.current != null) {\n window.clearTimeout(blurTimer.current);\n blurTimer.current = null;\n }\n setOpen(true);\n onFocus?.(e);\n }\n\n function handleBlur(e: React.FocusEvent<HTMLInputElement>) {\n // Defer close so a click on the suggestion can register first.\n blurTimer.current = window.setTimeout(() => {\n setOpen(false);\n setHighlighted(false);\n }, 120);\n onBlur?.(e);\n }\n\n function handleKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {\n if (showPopover) {\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n setHighlighted(true);\n } else if (e.key === 'ArrowUp') {\n e.preventDefault();\n setHighlighted(false);\n } else if (e.key === 'Escape') {\n e.preventDefault();\n setOpen(false);\n setHighlighted(false);\n } else if (e.key === 'Enter' && highlighted) {\n e.preventDefault();\n selectSuggestion();\n }\n }\n onKeyDown?.(e);\n }\n\n React.useEffect(() => {\n return () => {\n if (blurTimer.current != null) window.clearTimeout(blurTimer.current);\n };\n }, []);\n\n return (\n <div\n data-oc-address-input=\"\"\n className={wrapperClassName}\n style={{ position: 'relative' }}\n >\n <input\n {...rest}\n ref={setRef}\n value={value}\n onChange={(e) => onValueChange(e.target.value)}\n onFocus={handleFocus}\n onBlur={handleBlur}\n onKeyDown={handleKeyDown}\n role=\"combobox\"\n aria-haspopup=\"listbox\"\n aria-expanded={showPopover}\n aria-controls={showPopover ? listboxId : undefined}\n aria-activedescendant={highlighted ? optionId : undefined}\n autoComplete=\"off\"\n spellCheck={false}\n />\n {showPopover && sessionAddress && (\n <div\n id={listboxId}\n role=\"listbox\"\n data-oc-address-popover=\"\"\n className={popoverClassName}\n style={{\n position: 'absolute',\n zIndex: 50,\n top: 'calc(100% + 4px)',\n left: 0,\n right: 0,\n }}\n // Prevent the input from blurring before the click on the suggestion lands.\n onMouseDown={(e) => e.preventDefault()}\n >\n <button\n type=\"button\"\n id={optionId}\n role=\"option\"\n aria-selected={highlighted}\n data-oc-address-suggestion=\"\"\n data-highlighted={highlighted ? '' : undefined}\n className={suggestionClassName}\n onClick={selectSuggestion}\n onMouseEnter={() => setHighlighted(true)}\n onMouseLeave={() => setHighlighted(false)}\n style={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: '0.75rem',\n width: '100%',\n textAlign: 'left',\n cursor: 'pointer',\n font: 'inherit',\n background: 'inherit',\n color: 'inherit',\n border: 'inherit',\n padding: 'inherit',\n }}\n >\n <span data-oc-address-suggestion-label=\"\">{suggestionLabel}</span>\n <span\n data-oc-address-suggestion-value=\"\"\n style={{ fontFamily: 'ui-monospace, monospace' }}\n >\n {shortenAddressMid(sessionAddress)}\n </span>\n </button>\n </div>\n )}\n </div>\n );\n }\n);\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orangecheck/auth-client",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "React hooks and components for the cross-subdomain oc_session. Drop-in sign-in button, account pill, session-aware address input, and useOcSession() hook.",
5
5
  "keywords": [
6
6
  "orangecheck",