@bwalletx/connect 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.
@@ -0,0 +1,58 @@
1
+ import * as react from 'react';
2
+ import { CSSProperties, ReactNode } from 'react';
3
+ import { B as BappManifest, S as SlotId } from './manifest-Caj_Raqm.cjs';
4
+
5
+ interface NavigateDetail {
6
+ slot?: SlotId;
7
+ path: string | null;
8
+ source: 'web' | 'wallet';
9
+ }
10
+ type Handler<D> = (detail: D, event: CustomEvent<D>) => void;
11
+ interface Common {
12
+ manifest: BappManifest | null;
13
+ /** "auto" (default) detects bWallet; true/false forces. */
14
+ inWallet?: boolean | 'auto';
15
+ /** true = never call location.assign; route in onNavigate. */
16
+ manualNavigation?: boolean;
17
+ onNavigate?: Handler<NavigateDetail>;
18
+ id?: string;
19
+ className?: string;
20
+ style?: CSSProperties;
21
+ /** Slotted content, e.g. <button slot="tools"> or <span slot="strip-left">. */
22
+ children?: ReactNode;
23
+ }
24
+ interface BappBarProps extends Common {
25
+ active?: SlotId | null;
26
+ onActive?: Handler<{
27
+ slot: SlotId;
28
+ }>;
29
+ onBPress?: Handler<{
30
+ path: string | null;
31
+ }>;
32
+ onBHold?: Handler<{
33
+ phase: 'start' | 'end';
34
+ }>;
35
+ }
36
+ declare function BappBar(p: BappBarProps): react.DOMElement<Record<string, unknown>, Element>;
37
+ interface BappTopbarProps extends Common {
38
+ title?: string;
39
+ subtitle?: string;
40
+ /** id of the <bwalletx-drawer> the app icon opens. */
41
+ drawer?: string;
42
+ /** Show ☰ on the web too (it always shows in the wallet). */
43
+ menu?: boolean;
44
+ strip?: boolean;
45
+ onMenu?: Handler<object>;
46
+ onClose?: Handler<object>;
47
+ onDrawerToggle?: Handler<object>;
48
+ }
49
+ declare function BappTopbar(p: BappTopbarProps): react.DOMElement<Record<string, unknown>, Element>;
50
+ interface BappDrawerProps extends Common {
51
+ open?: boolean;
52
+ /** Path to highlight; default location.pathname. */
53
+ current?: string;
54
+ onClose?: Handler<object>;
55
+ }
56
+ declare function BappDrawer(p: BappDrawerProps): react.DOMElement<Record<string, unknown>, Element>;
57
+
58
+ export { BappBar, type BappBarProps, BappDrawer, type BappDrawerProps, BappManifest, BappTopbar, type BappTopbarProps, type NavigateDetail, SlotId };
@@ -0,0 +1,58 @@
1
+ import * as react from 'react';
2
+ import { CSSProperties, ReactNode } from 'react';
3
+ import { B as BappManifest, S as SlotId } from './manifest-Caj_Raqm.js';
4
+
5
+ interface NavigateDetail {
6
+ slot?: SlotId;
7
+ path: string | null;
8
+ source: 'web' | 'wallet';
9
+ }
10
+ type Handler<D> = (detail: D, event: CustomEvent<D>) => void;
11
+ interface Common {
12
+ manifest: BappManifest | null;
13
+ /** "auto" (default) detects bWallet; true/false forces. */
14
+ inWallet?: boolean | 'auto';
15
+ /** true = never call location.assign; route in onNavigate. */
16
+ manualNavigation?: boolean;
17
+ onNavigate?: Handler<NavigateDetail>;
18
+ id?: string;
19
+ className?: string;
20
+ style?: CSSProperties;
21
+ /** Slotted content, e.g. <button slot="tools"> or <span slot="strip-left">. */
22
+ children?: ReactNode;
23
+ }
24
+ interface BappBarProps extends Common {
25
+ active?: SlotId | null;
26
+ onActive?: Handler<{
27
+ slot: SlotId;
28
+ }>;
29
+ onBPress?: Handler<{
30
+ path: string | null;
31
+ }>;
32
+ onBHold?: Handler<{
33
+ phase: 'start' | 'end';
34
+ }>;
35
+ }
36
+ declare function BappBar(p: BappBarProps): react.DOMElement<Record<string, unknown>, Element>;
37
+ interface BappTopbarProps extends Common {
38
+ title?: string;
39
+ subtitle?: string;
40
+ /** id of the <bwalletx-drawer> the app icon opens. */
41
+ drawer?: string;
42
+ /** Show ☰ on the web too (it always shows in the wallet). */
43
+ menu?: boolean;
44
+ strip?: boolean;
45
+ onMenu?: Handler<object>;
46
+ onClose?: Handler<object>;
47
+ onDrawerToggle?: Handler<object>;
48
+ }
49
+ declare function BappTopbar(p: BappTopbarProps): react.DOMElement<Record<string, unknown>, Element>;
50
+ interface BappDrawerProps extends Common {
51
+ open?: boolean;
52
+ /** Path to highlight; default location.pathname. */
53
+ current?: string;
54
+ onClose?: Handler<object>;
55
+ }
56
+ declare function BappDrawer(p: BappDrawerProps): react.DOMElement<Record<string, unknown>, Element>;
57
+
58
+ export { BappBar, type BappBarProps, BappDrawer, type BappDrawerProps, BappManifest, BappTopbar, type BappTopbarProps, type NavigateDetail, SlotId };
@@ -0,0 +1,52 @@
1
+ import {
2
+ defineBappShell
3
+ } from "./chunk-OMEKHKMM.js";
4
+
5
+ // src/shell/react.ts
6
+ import { createElement, useEffect, useRef } from "react";
7
+ function useShell(tag, props, attrs, events) {
8
+ const ref = useRef(null);
9
+ useEffect(() => {
10
+ defineBappShell();
11
+ }, []);
12
+ useEffect(() => {
13
+ if (ref.current) ref.current.manifest = props.manifest;
14
+ }, [props.manifest]);
15
+ useEffect(() => {
16
+ const el = ref.current;
17
+ if (!el) return;
18
+ const all = { "bapp-navigate": props.onNavigate, ...events };
19
+ const subs = Object.entries(all).filter(([, h]) => h).map(([type, h]) => {
20
+ const fn = (e) => h(e.detail, e);
21
+ el.addEventListener(type, fn);
22
+ return () => el.removeEventListener(type, fn);
23
+ });
24
+ return () => subs.forEach((u) => u());
25
+ });
26
+ const a = { ref, id: props.id, class: props.className, style: props.style };
27
+ if (props.inWallet !== void 0 && props.inWallet !== "auto") a["in-wallet"] = String(props.inWallet);
28
+ if (props.manualNavigation) a.navigate = "manual";
29
+ for (const [k, v] of Object.entries(attrs)) if (v !== void 0) a[k] = v;
30
+ return createElement(tag, a, props.children);
31
+ }
32
+ function BappBar(p) {
33
+ return useShell("bwalletx-bar", p, { active: p.active ?? void 0 }, { "bapp-active": p.onActive, "bapp-b-press": p.onBPress, "bapp-b-hold": p.onBHold });
34
+ }
35
+ function BappTopbar(p) {
36
+ return useShell("bwalletx-topbar", p, {
37
+ title: p.title,
38
+ subtitle: p.subtitle,
39
+ drawer: p.drawer,
40
+ menu: p.menu ? "true" : void 0,
41
+ strip: p.strip === false ? "off" : void 0
42
+ }, { "bapp-menu": p.onMenu, "bapp-close": p.onClose, "bapp-drawer-toggle": p.onDrawerToggle });
43
+ }
44
+ function BappDrawer(p) {
45
+ return useShell("bwalletx-drawer", p, { open: p.open ? "" : void 0, current: p.current }, { "bapp-close": p.onClose });
46
+ }
47
+ export {
48
+ BappBar,
49
+ BappDrawer,
50
+ BappTopbar
51
+ };
52
+ //# sourceMappingURL=shell-react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shell/react.ts"],"sourcesContent":["/**\n * React wrappers for the bApp shell. The elements do the work; these set the manifest property\n * and wire the events.\n *\n * import { BappBar, BappTopbar, BappDrawer } from '@bwalletx/connect/shell/react';\n * <BappTopbar manifest={m} drawer=\"sections\" />\n * <BappDrawer id=\"sections\" manifest={m} />\n * <BappBar manifest={m} active=\"feed\" onNavigate={(d, e) => { e.preventDefault(); router.push(d.path) }} />\n */\nimport { createElement, useEffect, useRef, type CSSProperties, type ReactNode } from 'react';\nimport { defineBappShell } from './elements.js';\nimport type { BappManifest, SlotId } from './manifest.js';\n\nexport interface NavigateDetail { slot?: SlotId; path: string | null; source: 'web' | 'wallet' }\ntype Handler<D> = (detail: D, event: CustomEvent<D>) => void;\n\ninterface Common {\n manifest: BappManifest | null;\n /** \"auto\" (default) detects bWallet; true/false forces. */\n inWallet?: boolean | 'auto';\n /** true = never call location.assign; route in onNavigate. */\n manualNavigation?: boolean;\n onNavigate?: Handler<NavigateDetail>;\n id?: string;\n className?: string;\n style?: CSSProperties;\n /** Slotted content, e.g. <button slot=\"tools\"> or <span slot=\"strip-left\">. */\n children?: ReactNode;\n}\n\nfunction useShell(tag: string, props: Common, attrs: Record<string, string | undefined>, events: Record<string, Handler<any> | undefined>) {\n const ref = useRef<HTMLElement & { manifest: BappManifest | null }>(null);\n useEffect(() => { defineBappShell(); }, []);\n useEffect(() => { if (ref.current) ref.current.manifest = props.manifest; }, [props.manifest]);\n useEffect(() => {\n const el = ref.current;\n if (!el) return;\n const all = { 'bapp-navigate': props.onNavigate, ...events };\n const subs = Object.entries(all).filter(([, h]) => h).map(([type, h]) => {\n const fn = (e: Event) => h!((e as CustomEvent).detail, e as CustomEvent);\n el.addEventListener(type, fn);\n return () => el.removeEventListener(type, fn);\n });\n return () => subs.forEach((u) => u());\n });\n const a: Record<string, unknown> = { ref, id: props.id, class: props.className, style: props.style };\n if (props.inWallet !== undefined && props.inWallet !== 'auto') a['in-wallet'] = String(props.inWallet);\n if (props.manualNavigation) a.navigate = 'manual';\n for (const [k, v] of Object.entries(attrs)) if (v !== undefined) a[k] = v;\n return createElement(tag, a, props.children);\n}\n\nexport interface BappBarProps extends Common {\n active?: SlotId | null;\n onActive?: Handler<{ slot: SlotId }>;\n onBPress?: Handler<{ path: string | null }>;\n onBHold?: Handler<{ phase: 'start' | 'end' }>;\n}\nexport function BappBar(p: BappBarProps) {\n return useShell('bwalletx-bar', p, { active: p.active ?? undefined }, { 'bapp-active': p.onActive, 'bapp-b-press': p.onBPress, 'bapp-b-hold': p.onBHold });\n}\n\nexport interface BappTopbarProps extends Common {\n title?: string;\n subtitle?: string;\n /** id of the <bwalletx-drawer> the app icon opens. */\n drawer?: string;\n /** Show ☰ on the web too (it always shows in the wallet). */\n menu?: boolean;\n strip?: boolean;\n onMenu?: Handler<object>;\n onClose?: Handler<object>;\n onDrawerToggle?: Handler<object>;\n}\nexport function BappTopbar(p: BappTopbarProps) {\n return useShell('bwalletx-topbar', p, {\n title: p.title, subtitle: p.subtitle, drawer: p.drawer, menu: p.menu ? 'true' : undefined, strip: p.strip === false ? 'off' : undefined,\n }, { 'bapp-menu': p.onMenu, 'bapp-close': p.onClose, 'bapp-drawer-toggle': p.onDrawerToggle });\n}\n\nexport interface BappDrawerProps extends Common {\n open?: boolean;\n /** Path to highlight; default location.pathname. */\n current?: string;\n onClose?: Handler<object>;\n}\nexport function BappDrawer(p: BappDrawerProps) {\n return useShell('bwalletx-drawer', p, { open: p.open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