@buyingbuddy/react 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -136,7 +136,7 @@ Because the widgets are client-only, their listing content is **not server-rende
136
136
 
137
137
  A standalone, single-file widget for the [Framer](https://www.framer.com) website builder is included at [`framer/BuyingBuddyWidget.tsx`](framer/BuyingBuddyWidget.tsx). It bundles the script loading and adds Framer property controls (activation key, widget type, filter), so you configure everything from Framer's design panel — no React code required.
138
138
 
139
- 1. Open the [`framer/BuyingBuddyWidget.tsx`](framer/BuyingBuddyWidget.tsx) file and copy its entire contents.
139
+ 1. Open [`framer/BuyingBuddyWidget.tsx`](framer/BuyingBuddyWidget.tsx) and copy its entire contents. (It also ships inside the npm package at `node_modules/@buyingbuddy/react/framer/BuyingBuddyWidget.tsx`.)
140
140
  2. In Framer, go to **Assets → Code → +** and paste it in.
141
141
  3. Drag the component onto your canvas and set your **activation key** in the property panel.
142
142
 
@@ -184,7 +184,7 @@ import type {
184
184
  - **The script persists after unmount.** Unmounting the provider does not remove the script or reset the global — remounting reuses the already-loaded runtime. This is intentional.
185
185
  - **Error UI is built in.** On load failure the provider renders its own inline error message in place of `children` (and `fallback` is not shown). You can't currently replace the default error UI.
186
186
  - **ESM-only.** This package ships as ES modules only (no CommonJS build). Use it in a project with ESM/bundler support.
187
- - **Pre-release.** This package is `0.0.2` — the API may change.
187
+ - **Pre-release.** This package is `0.x` — the API may change.
188
188
 
189
189
  ## Development
190
190
 
@@ -1 +1 @@
1
- {"version":3,"file":"BuyingBuddyProvider.d.ts","sourceRoot":"","sources":["../src/BuyingBuddyProvider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAIjF;;;GAGG;AACH,wBAAgB,cAAc,IAAI,uBAAuB,CAQxD;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,GAAG,CAAC,EAAE;YACJ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YAC7B,UAAU,EAAE,MAAM,CAAC;YACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;SACxB,CAAC;KACH;CACF;AAID;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,aAAa,EACb,MAAuB,EACvB,UAAU,EACV,QAAQ,EACR,QAAe,GAChB,EAAE,wBAAwB,2CA+G1B"}
1
+ {"version":3,"file":"BuyingBuddyProvider.d.ts","sourceRoot":"","sources":["../src/BuyingBuddyProvider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAIjF;;;GAGG;AACH,wBAAgB,cAAc,IAAI,uBAAuB,CAQxD;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,GAAG,CAAC,EAAE;YACJ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YAC7B,UAAU,EAAE,MAAM,CAAC;YACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;SACxB,CAAC;KACH;CACF;AAID;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,aAAa,EACb,MAAuB,EACvB,UAAU,EACV,QAAQ,EACR,QAAe,GAChB,EAAE,wBAAwB,2CAkH1B"}
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { createContext, useContext, useEffect, useState, useCallback } from "react";
2
+ import { createContext, useContext, useEffect, useState } from "react";
3
3
  const BuyingBuddyContext = createContext(null);
4
4
  /**
5
5
  * Hook to access the BuyingBuddy context.
@@ -38,32 +38,6 @@ export function BuyingBuddyProvider({ activationKey, domain = "www.mbb2.com", ap
38
38
  return typeof window !== "undefined" && !!window.MBB;
39
39
  });
40
40
  const [error, setError] = useState(null);
41
- const handleLoad = useCallback(() => {
42
- // Poll for MBB global — the JSONP script sets it after execution.
43
- // Also detect the server's invalid-account response which defines
44
- // displayInvalidAcidMsg instead of setting window.MBB.
45
- let attempts = 0;
46
- const check = () => {
47
- if (window.MBB) {
48
- // Set before the widget bundle (appended by the bootstrap, loaded
49
- // async) makes its first data request, so DATA follows this base URL.
50
- window.MBB.apiBaseUrl = resolvedApiBaseUrl;
51
- LOADED_ACCOUNTS.add(activationKey);
52
- setIsLoaded(true);
53
- }
54
- else if ("displayInvalidAcidMsg" in window ||
55
- attempts >= 50) {
56
- setError(new Error("displayInvalidAcidMsg" in window
57
- ? "BuyingBuddy: Invalid activation key or unauthorized domain. Check your activationKey and ensure this domain is registered in your BuyingBuddy dashboard."
58
- : "BuyingBuddy script loaded but MBB global was not initialized."));
59
- }
60
- else {
61
- attempts++;
62
- setTimeout(check, 100);
63
- }
64
- };
65
- check();
66
- }, [activationKey, resolvedApiBaseUrl]);
67
41
  useEffect(() => {
68
42
  if (typeof window === "undefined")
69
43
  return;
@@ -86,30 +60,67 @@ export function BuyingBuddyProvider({ activationKey, domain = "www.mbb2.com", ap
86
60
  if (window.MBB) {
87
61
  window.MBB.apiBaseUrl = resolvedApiBaseUrl;
88
62
  }
89
- // Already loaded for this account
63
+ // Already loaded for this account — nothing more to do.
90
64
  if (window.MBB && LOADED_ACCOUNTS.has(activationKey)) {
91
65
  setIsLoaded(true);
92
66
  return;
93
67
  }
68
+ // Poll for the MBB global — the JSONP script sets it after execution.
69
+ // Also detect the server's invalid-account response, which defines
70
+ // displayInvalidAcidMsg instead of setting window.MBB. The poll is
71
+ // cancellable so it can't setState after unmount or run twice (Strict Mode).
72
+ let cancelled = false;
73
+ let timer;
74
+ let attempts = 0;
75
+ const check = () => {
76
+ if (cancelled)
77
+ return;
78
+ if (window.MBB) {
79
+ // Set before the widget bundle (appended by the bootstrap, loaded
80
+ // async) makes its first data request, so DATA follows this base URL.
81
+ window.MBB.apiBaseUrl = resolvedApiBaseUrl;
82
+ LOADED_ACCOUNTS.add(activationKey);
83
+ setIsLoaded(true);
84
+ }
85
+ else if ("displayInvalidAcidMsg" in window || attempts >= 50) {
86
+ setError(new Error("displayInvalidAcidMsg" in window
87
+ ? "BuyingBuddy: Invalid activation key or unauthorized domain. Check your activationKey and ensure this domain is registered in your BuyingBuddy dashboard."
88
+ : "BuyingBuddy script loaded but MBB global was not initialized."));
89
+ }
90
+ else {
91
+ attempts++;
92
+ timer = setTimeout(check, 100);
93
+ }
94
+ };
94
95
  const scriptId = `mbb-script-${activationKey}`;
95
- // Script tag already exists in the DOM
96
+ // Script tag already exists in the DOM — just start polling.
96
97
  if (document.getElementById(scriptId)) {
97
- handleLoad();
98
- return;
98
+ check();
99
+ }
100
+ else {
101
+ const script = document.createElement("script");
102
+ script.id = scriptId;
103
+ script.src = `https://${domain}/mbbv3/index/acid/${activationKey}`;
104
+ script.async = true;
105
+ script.onload = () => {
106
+ if (!cancelled)
107
+ check();
108
+ };
109
+ script.onerror = () => {
110
+ if (cancelled)
111
+ return;
112
+ setError(new Error(`Failed to load BuyingBuddy script for account: ${activationKey}`));
113
+ };
114
+ document.head.appendChild(script);
99
115
  }
100
- const script = document.createElement("script");
101
- script.id = scriptId;
102
- script.src = `https://${domain}/mbbv3/index/acid/${activationKey}`;
103
- script.async = true;
104
- script.onload = handleLoad;
105
- script.onerror = () => {
106
- setError(new Error(`Failed to load BuyingBuddy script for account: ${activationKey}`));
107
- };
108
- document.head.appendChild(script);
109
116
  return () => {
110
- // Don't remove the script on unmount — MBB global state is persistent
117
+ // Don't remove the script (MBB global state is persistent); just stop the
118
+ // poll so it can't setState after unmount.
119
+ cancelled = true;
120
+ if (timer)
121
+ clearTimeout(timer);
111
122
  };
112
- }, [activationKey, domain, resolvedApiBaseUrl, handleLoad]);
123
+ }, [activationKey, domain, resolvedApiBaseUrl]);
113
124
  const value = { isLoaded, error, activationKey };
114
125
  return (_jsx(BuyingBuddyContext.Provider, { value: value, children: error ? (_jsxs("div", { role: "alert", style: { color: "#b91c1c", padding: "12px", border: "1px solid #fca5a5", borderRadius: "6px", backgroundColor: "#fef2f2", fontFamily: "sans-serif", fontSize: "14px" }, children: [_jsx("strong", { children: "BuyingBuddy Error:" }), " ", error.message] })) : isLoaded ? children : fallback }));
115
126
  }
@@ -1 +1 @@
1
- {"version":3,"file":"BuyingBuddyProvider.js","sourceRoot":"","sources":["../src/BuyingBuddyProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAGpF,MAAM,kBAAkB,GAAG,aAAa,CAAiC,IAAI,CAAC,CAAC;AAE/E;;;GAGG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,GAAG,GAAG,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAC3C,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAYD,MAAM,eAAe,GAAG,IAAI,GAAG,EAAU,CAAC;AAE1C;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAClC,aAAa,EACb,MAAM,GAAG,cAAc,EACvB,UAAU,EACV,QAAQ,EACR,QAAQ,GAAG,IAAI,GACU;IACzB,yEAAyE;IACzE,kEAAkE;IAClE,4EAA4E;IAC5E,qCAAqC;IACrC,MAAM,kBAAkB,GAAG,UAAU,IAAI,WAAW,MAAM,EAAE,CAAC;IAC7D,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE;QAC5C,6DAA6D;QAC7D,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;IACvD,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,EAAE,QAA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yWidget type="InteractiveMap" style={{ height: "600px" }} />
17
17
  * ```
18
18
  */
19
- export declare function BuyingBuddyWidget({ type, filter, limit, order, demo, featured, style, className, id, onWidgetLoaded, }: BuyingBuddyWidgetProps): import("react/jsx-runtime").JSX.Element | null;
19
+ export declare function BuyingBuddyWidget({ type, filter, limit, order, style, className, id, onWidgetLoaded, }: BuyingBuddyWidgetProps): import("react/jsx-runtime").JSX.Element | null;
20
20
  //# sourceMappingURL=BuyingBuddyWidget.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BuyingBuddyWidget.d.ts","sourceRoot":"","sources":["../src/BuyingBuddyWidget.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAGtD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,IAAI,EACJ,MAAM,EACN,KAAK,EACL,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,KAAK,EACL,SAAS,EACT,EAAE,EACF,cAAc,GACf,EAAE,sBAAsB,kDAiDxB"}
1
+ {"version":3,"file":"BuyingBuddyWidget.d.ts","sourceRoot":"","sources":["../src/BuyingBuddyWidget.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAGtD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,IAAI,EACJ,MAAM,EACN,KAAK,EACL,KAAK,EACL,KAAK,EACL,SAAS,EACT,EAAE,EACF,cAAc,GACf,EAAE,sBAAsB,kDAyFxB"}
@@ -18,9 +18,17 @@ import { useBuyingBuddy } from "./BuyingBuddyProvider";
18
18
  * <BuyingBuddyWidget type="InteractiveMap" style={{ height: "600px" }} />
19
19
  * ```
20
20
  */
21
- export function BuyingBuddyWidget({ type, filter, limit, order, demo, featured, style, className, id, onWidgetLoaded, }) {
21
+ export function BuyingBuddyWidget({ type, filter, limit, order, style, className, id, onWidgetLoaded, }) {
22
22
  const containerRef = useRef(null);
23
23
  const { isLoaded } = useBuyingBuddy();
24
+ // Keep the latest onWidgetLoaded in a ref so changing its identity (e.g. an
25
+ // inline arrow created on every render) does NOT re-run the widget effect and
26
+ // rebuild the <bb-widget> — which would drop map position / scroll / form
27
+ // state and re-fire data requests.
28
+ const onWidgetLoadedRef = useRef(onWidgetLoaded);
29
+ useEffect(() => {
30
+ onWidgetLoadedRef.current = onWidgetLoaded;
31
+ }, [onWidgetLoaded]);
24
32
  useEffect(() => {
25
33
  const container = containerRef.current;
26
34
  if (!container || !isLoaded)
@@ -39,23 +47,54 @@ export function BuyingBuddyWidget({ type, filter, limit, order, demo, featured,
39
47
  widget.setAttribute("limit", String(limit));
40
48
  if (order !== undefined)
41
49
  widget.setAttribute("order", order);
42
- if (demo !== undefined)
43
- widget.setAttribute("demo", String(demo));
44
- if (featured !== undefined)
45
- widget.setAttribute("featured", String(featured));
46
50
  if (id !== undefined)
47
51
  widget.setAttribute("id", id);
48
- // Listen for componentLoaded before appending
49
- if (onWidgetLoaded) {
50
- widget.addEventListener("componentLoaded", () => onWidgetLoaded(), {
51
- once: true,
52
- });
53
- }
52
+ // Make the custom element fill the wrapper so a size applied via `style`
53
+ // (e.g. a fixed height for InteractiveMap / SearchResults) actually reaches
54
+ // the widget and its internal sticky-map/scroll layout — mirroring native
55
+ // usage where height is set on <bb-widget> directly. Without this the
56
+ // element sizes to its content and overflows a height-constrained wrapper
57
+ // (which then gets clipped → the widget looks broken).
58
+ widget.style.display = "block";
59
+ widget.style.width = "100%";
60
+ widget.style.height = "100%";
61
+ // Fires when the widget finishes loading. The runtime's `componentLoaded`
62
+ // event is NOT composed, so depending on the widget it's dispatched either
63
+ // on the host element (search widgets) or inside the shadow root (most
64
+ // widgets), where it bubbles to the shadow root but not across to the host.
65
+ // Listen on both, firing once, and read the callback from a ref so it isn't
66
+ // an effect dependency (avoids needless rebuilds).
67
+ let firedLoaded = false;
68
+ const fireLoaded = () => {
69
+ if (firedLoaded)
70
+ return;
71
+ firedLoaded = true;
72
+ onWidgetLoadedRef.current?.();
73
+ };
74
+ widget.addEventListener("componentLoaded", fireLoaded, { once: true });
54
75
  container.appendChild(widget);
76
+ // The shadow root is created during connectedCallback; poll briefly for it,
77
+ // then listen there for the in-shadow dispatch.
78
+ let shadowTimer;
79
+ let attempts = 0;
80
+ const attachShadowListener = () => {
81
+ if (firedLoaded)
82
+ return;
83
+ const root = widget.shadowRoot;
84
+ if (root) {
85
+ root.addEventListener("componentLoaded", fireLoaded, { once: true });
86
+ }
87
+ else if (attempts++ < 50) {
88
+ shadowTimer = setTimeout(attachShadowListener, 50);
89
+ }
90
+ };
91
+ attachShadowListener();
55
92
  return () => {
93
+ if (shadowTimer)
94
+ clearTimeout(shadowTimer);
56
95
  container.innerHTML = "";
57
96
  };
58
- }, [type, filter, limit, order, demo, featured, id, isLoaded, onWidgetLoaded]);
97
+ }, [type, filter, limit, order, id, isLoaded]);
59
98
  if (!isLoaded)
60
99
  return null;
61
100
  return (_jsx("div", { ref: containerRef, style: { width: "100%", ...style }, className: className, suppressHydrationWarning: true }));
@@ -1 +1 @@
1
- {"version":3,"file":"BuyingBuddyWidget.js","sourceRoot":"","sources":["../src/BuyingBuddyWidget.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAChC,IAAI,EACJ,MAAM,EACN,KAAK,EACL,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,KAAK,EACL,SAAS,EACT,EAAE,EACF,cAAc,GACS;IACvB,MAAM,YAAY,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAClD,MAAM,EAAE,QAAQ,EAAE,GAAG,cAAc,EAAE,CAAC;IAEtC,SAAS,CAAC,GAAG,EAAE;QACb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AU,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAEvE,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAE9B,4EAA4E;QAC5E,gDAAgD;QAChD,IAAI,WAAsD,CAAC;QAC3D,IAAI,QAAQ,GAAG,CAAC,CAAC;QACjB,MAAM,oBAAoB,GAAG,GAAG,EAAE;YAChC,IAAI,WAAW;gBAAE,OAAO;YACxB,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC;YAC/B,IAAI,IAAI,EAAE,CAAC;gBACT,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YACvE,CAAC;iBAAM,IAAI,QAAQ,EAAE,GAAG,EAAE,EAAE,CAAC;gBAC3B,WAAW,GAAG,UAAU,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAC;YACrD,CAAC;QACH,CAAC,CAAC;QACF,oBAAoB,EAAE,CAAC;QAEvB,OAAO,GAAG,EAAE;YACV,IAAI,WAAW;gBAAE,YAAY,CAAC,WAAW,CAAC,CAAC;YAC3C,SAAS,CAAC,SAAS,GAAG,EAAE,CAAC;QAC3B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE/C,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAE3B,OAAO,CACL,cACE,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,EAClC,SAAS,EAAE,SAAS,EACpB,wBAAwB,SACxB,CACH,CAAC;AACJ,CAAC"}
package/dist/types.d.ts CHANGED
@@ -26,14 +26,7 @@ export interface BuyingBuddyWidgetProps {
26
26
  * Example: "price_asc", "price_desc", "date_listed_desc"
27
27
  */
28
28
  order?: string;
29
- /**
30
- * Sets the `demo` attribute on the widget element. Note: a valid
31
- * account ID is still required — there is no account-less preview mode.
32
- */
33
- demo?: boolean | string;
34
- /** Show only featured listings. */
35
- featured?: boolean | string;
36
- /** Inline style object or string for the widget container. */
29
+ /** Inline styles for the widget. A `height` here reaches the widget element. */
37
30
  style?: React.CSSProperties;
38
31
  /** Additional CSS class name(s). */
39
32
  className?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,GAC7B,aAAa,GACb,iBAAiB,GACjB,cAAc,GACd,gBAAgB,GAChB,YAAY,GACZ,eAAe,GACf,eAAe,GACf,gBAAgB,GAChB,eAAe,GACf,aAAa,GACb,iBAAiB,GACjB,SAAS,GACT,YAAY,GACZ,QAAQ,GACR,YAAY,GACZ,SAAS,GACT,cAAc,GACd,YAAY,GACZ,cAAc,GACd,aAAa,GACb,YAAY,GACZ,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAElB;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACrC,uCAAuC;IACvC,IAAI,EAAE,qBAAqB,CAAC;IAE5B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAExB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAExB,mCAAmC;IACnC,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAE5B,8DAA8D;IAC9D,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAE5B,oCAAoC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,yBAAyB;IACzB,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ,mEAAmE;IACnE,cAAc,C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,EAAE,KAAK,CAAC,aAAa,CAAC;IAE5B,oCAAoC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,yBAAyB;IACzB,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ,mEAAmE;IACnE,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,oDAAoD;IACpD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAE1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,mDAAmD;IACnD,QAAQ,EAAE,OAAO,CAAC;IAElB,0CAA0C;IAC1C,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAEpB,iDAAiD;IACjD,aAAa,EAAE,MAAM,CAAC;CACvB"}
@@ -0,0 +1,274 @@
1
+ // BuyingBuddyWidget.tsx — Framer Code Component
2
+ //
3
+ // Standalone single-file component for Framer website builder.
4
+ // Paste this entire file into Framer's code editor (Assets > Code > +).
5
+ //
6
+ // This is a self-contained version of @buyingbuddy/react that works
7
+ // within Framer's single-file constraint and provides property controls
8
+ // for the Framer design UI.
9
+
10
+ import { useState, useEffect, useRef } from "react"
11
+ import { addPropertyControls, ControlType } from "framer"
12
+
13
+ interface BuyingBuddyWidgetProps {
14
+ accountId: string
15
+ widgetType: string
16
+ filter: string
17
+ limit: number
18
+ order: string
19
+ featured: boolean
20
+ style?: React.CSSProperties
21
+ }
22
+
23
+ /**
24
+ * BuyingBuddy Widget
25
+ *
26
+ * Embeds any BuyingBuddy real estate widget in your Framer site.
27
+ * Configure your activation key and widget type in the property panel.
28
+ *
29
+ * @framerSupportedLayoutWidth any
30
+ * @framerSupportedLayoutHeight any
31
+ */
32
+ export default function BuyingBuddyWidget(props: BuyingBuddyWidgetProps) {
33
+ const {
34
+ accountId,
35
+ widgetType,
36
+ filter,
37
+ limit,
38
+ order,
39
+ featured,
40
+ style: externalStyle,
41
+ } = props
42
+
43
+ const containerRef = useRef<HTMLDivElement>(null)
44
+ const [status, setStatus] = useState<"loading" | "ready" | "error">(
45
+ "loading"
46
+ )
47
+ const [errorMsg, setErrorMsg] = useState("")
48
+
49
+ // Load the MBB plugin script
50
+ useEffect(() => {
51
+ if (!accountId) {
52
+ setStatus("error")
53
+ setErrorMsg(
54
+ "Activation key is required. Set it in the property panel."
55
+ )
56
+ return
57
+ }
58
+
59
+ // Already loaded
60
+ if ((window as any).MBB) {
61
+ setStatus("ready")
62
+ return
63
+ }
64
+
65
+ // Inject the widget theme stylesheet. The plugin embed loads this
66
+ // separately from the runtime script; without it widgets render
67
+ // unthemed and the map logs "Missing acid or theme data".
68
+ const themeId = `mbb-theme-${accountId}`
69
+ if (!document.getElementById(themeId)) {
70
+ const theme = document.createElement("script")
71
+ theme.id = themeId
72
+ theme.src = `https://www.mbb2.com/version3/css/theme/acid/${accountId}`
73
+ theme.async = true
74
+ document.head.appendChild(theme)
75
+ }
76
+
77
+ const scriptId = `mbb-script-${accountId}`
78
+ if (document.getElementById(scriptId)) {
79
+ pollForMBB()
80
+ return
81
+ }
82
+
83
+ const script = document.createElement("script")
84
+ script.id = scriptId
85
+ script.src = `https://www.mbb2.com/mbbv3/index/acid/${accountId}`
86
+ script.async = true
87
+ script.onload = () => pollForMBB()
88
+ script.onerror = () => {
89
+ setStatus("error")
90
+ setErrorMsg("Failed to load BuyingBuddy script.")
91
+ }
92
+ document.head.appendChild(script)
93
+
94
+ function pollForMBB() {
95
+ let attempts = 0
96
+ const check = () => {
97
+ if ((window as any).MBB) {
98
+ setStatus("ready")
99
+ } else if (
100
+ "displayInvalidAcidMsg" in (window as any) ||
101
+ attempts >= 50
102
+ ) {
103
+ setStatus("error")
104
+ setErrorMsg(
105
+ "displayInvalidAcidMsg" in (window as any)
106
+ ? "Invalid activation key or unauthorized domain. Check your activation key and ensure this domain is registered in your Buying Buddy dashboard (Widgets > Plugin Installation and Setup)."
107
+ : "BuyingBuddy script loaded but failed to initialize."
108
+ )
109
+ } else {
110
+ attempts++
111
+ setTimeout(check, 100)
112
+ }
113
+ }
114
+ check()
115
+ }
116
+ }, [accountId])
117
+
118
+ // Create the <bb-widget> custom element imperatively
119
+ useEffect(() => {
120
+ const container = containerRef.current
121
+ if (!container || status !== "ready") return
122
+
123
+ container.innerHTML = ""
124
+
125
+ const widget = document.createElement("bb-widget")
126
+ widget.setAttribute("data-type", widgetType)
127
+ if (filter) widget.setAttribute("data-filter", filter)
128
+ if (limit) widget.setAttribute("limit", String(limit))
129
+ if (order) widget.setAttribute("order", order)
130
+ if (featured) widget.setAttribute("featured", "true")
131
+
132
+ container.appendChild(widget)
133
+
134
+ return () => {
135
+ container.innerHTML = ""
136
+ }
137
+ }, [status, widgetType, filter, limit, order, featured])
138
+
139
+ if (status === "error") {
140
+ return (
141
+ <div
142
+ style={{
143
+ color: "#b91c1c",
144
+ padding: 12,
145
+ border: "1px solid #fca5a5",
146
+ borderRadius: 6,
147
+ background: "#fef2f2",
148
+ fontFamily: "sans-serif",
149
+ fontSize: 14,
150
+ }}
151
+ >
152
+ <strong>BuyingBuddy Error:</strong> {errorMsg}
153
+ </div>
154
+ )
155
+ }
156
+
157
+ if (status === "loading") {
158
+ return (
159
+ <div
160
+ style={{
161
+ padding: 20,
162
+ textAlign: "center",
163
+ color: "#888",
164
+ fontFamily: "sans-serif",
165
+ }}
166
+ >
167
+ Loading BuyingBuddy...
168
+ </div>
169
+ )
170
+ }
171
+
172
+ return (
173
+ <div
174
+ ref={containerRef}
175
+ style={{ width: "100%", minHeight: 200, ...externalStyle }}
176
+ />
177
+ )
178
+ }
179
+
180
+ BuyingBuddyWidget.defaultProps = {
181
+ accountId: "",
182
+ widgetType: "FeaturedGallery",
183
+ filter: "",
184
+ limit: 12,
185
+ order: "",
186
+ featured: false,
187
+ }
188
+
189
+ addPropertyControls(BuyingBuddyWidget, {
190
+ accountId: {
191
+ type: ControlType.String,
192
+ title: "Activation Key",
193
+ description: "Your Buying Buddy activation key (acid value).",
194
+ },
195
+ widgetType: {
196
+ type: ControlType.Enum,
197
+ title: "Widget Type",
198
+ options: [
199
+ "FeaturedGallery",
200
+ "FeaturedList",
201
+ "SearchForm",
202
+ "ListingResults",
203
+ "SearchDetails",
204
+ "QuickSearch",
205
+ "InteractiveMap",
206
+ "Communities",
207
+ "LcForm",
208
+ "LoginPanel",
209
+ "Calculator",
210
+ "MarketReport",
211
+ "MarketStats",
212
+ "Brokers",
213
+ "OfficeRoster",
214
+ "Disclaimer",
215
+ ],
216
+ optionTitles: [
217
+ "Featured Gallery",
218
+ "Featured List",
219
+ "Search Form",
220
+ "Search Results",
221
+ "Property Details",
222
+ "Quick Search",
223
+ "Interactive Map",
224
+ "Communities",
225
+ "Lead Capture Form",
226
+ "Login Panel",
227
+ "Mortgage Calculator",
228
+ "Market Report",
229
+ "Market Stats",
230
+ "Brokers",
231
+ "Office Roster",
232
+ "MLS Disclaimer",
233
+ ],
234
+ },
235
+ filter: {
236
+ type: ControlType.String,
237
+ title: "Filter",
238
+ description:
239
+ 'Property filter, e.g. "city:denver+price_min:300000" or "formType:simple1"',
240
+ placeholder: "city:denver+price_min:300000",
241
+ },
242
+ limit: {
243
+ type: ControlType.Number,
244
+ title: "Limit",
245
+ description: "Maximum number of results to display.",
246
+ min: 1,
247
+ max: 100,
248
+ step: 1,
249
+ },
250
+ order: {
251
+ type: ControlType.Enum,
252
+ title: "Sort Order",
253
+ options: [
254
+ "",
255
+ "price_asc",
256
+ "price_desc",
257
+ "date_listed_desc",
258
+ "date_listed_asc",
259
+ ],
260
+ optionTitles: [
261
+ "Default",
262
+ "Price: Low to High",
263
+ "Price: High to Low",
264
+ "Newest First",
265
+ "Oldest First",
266
+ ],
267
+ },
268
+ featured: {
269
+ type: ControlType.Boolean,
270
+ title: "Featured Only",
271
+ enabledTitle: "Yes",
272
+ disabledTitle: "No",
273
+ },
274
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buyingbuddy/react",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "React wrapper for BuyingBuddy Web Component widgets",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -13,7 +13,8 @@
13
13
  }
14
14
  },
15
15
  "files": [
16
- "dist"
16
+ "dist",
17
+ "framer"
17
18
  ],
18
19
  "scripts": {
19
20
  "build": "tsc",