@buyingbuddy/react 0.1.2 → 0.2.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/README.md +3 -3
- package/dist/BuyingBuddyProvider.d.ts +1 -1
- package/dist/BuyingBuddyProvider.d.ts.map +1 -1
- package/dist/BuyingBuddyProvider.js +35 -42
- package/dist/BuyingBuddyProvider.js.map +1 -1
- package/dist/BuyingBuddyWidget.d.ts +19 -6
- package/dist/BuyingBuddyWidget.d.ts.map +1 -1
- package/dist/BuyingBuddyWidget.js +51 -68
- package/dist/BuyingBuddyWidget.js.map +1 -1
- package/dist/types.d.ts +8 -6
- package/dist/types.d.ts.map +1 -1
- package/framer/BuyingBuddyWidget.tsx +19 -35
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ Works with **React**, **Next.js**, and **Framer**.
|
|
|
13
13
|
Before anything will render, you need both of these:
|
|
14
14
|
|
|
15
15
|
1. **A Buying Buddy account activation key.** Find it in your dashboard under **Widgets → Plugin Installation and Setup**. There is no anonymous or "try it" mode — the widgets will not load without a valid activation key.
|
|
16
|
-
2. **Your domain authorized on that account.** An activation key only works on domains registered to its account.
|
|
16
|
+
2. **Your domain authorized on that account.** An activation key only works on domains registered to its account. On an unauthorized domain the runtime loads but the widgets stay **empty** (no data is returned) — if widgets render blank, check that the domain is registered under **Widgets → Plugin Installation and Setup**.
|
|
17
17
|
|
|
18
18
|
**Don't have an account yet?** [Start a free trial](https://buyingbuddy.com/free-trial-idx-plugin.php) or [buy a license](https://buyingbuddy.com/order) to get your activation key.
|
|
19
19
|
|
|
@@ -161,7 +161,7 @@ Renders a single widget. Must be a descendant of `<BuyingBuddyProvider>`.
|
|
|
161
161
|
|------|------|-------------|
|
|
162
162
|
| `type` | `BuyingBuddyWidgetType` | **Required.** Widget to render — e.g. `"FeaturedGallery"`, `"SearchForm"`, `"SearchResults"`, `"InteractiveMap"`, `"SearchDetails"`. |
|
|
163
163
|
| `filter` | `string` | Property filter as `+`-joined tokens, e.g. `"city:Denver+FIELD(property_beds:3,4,5)+orderby:price desc+limit:9"`. |
|
|
164
|
-
| `style` | `React.CSSProperties` | Inline styles applied to the
|
|
164
|
+
| `style` | `React.CSSProperties` | Inline styles applied directly to the `<bb-widget>` element. A `height` here sizes the widget (e.g. for `InteractiveMap` / `SearchResults`). |
|
|
165
165
|
|
|
166
166
|
Common `type` values include `FeaturedGallery`, `FeaturedList`, `SearchForm`, `SearchResults`, `SearchDetails`, `QuickSearch`, `InteractiveMap`, `Communities`, `LcForm` (lead capture), `LoginPanel`, `Calculator`, `MarketReport`, `MarketStats`, `Brokers`, `OfficeRoster`, and `Disclaimer`. The `type` prop accepts any string, so newer widget types work even before they're added to the typings.
|
|
167
167
|
|
|
@@ -184,7 +184,7 @@ import type {
|
|
|
184
184
|
- **Client-side only.** Widgets render in the browser after the script loads — nothing is server-rendered. There's no SSR/streaming output, so the listing content isn't in the initial HTML (relevant for SEO).
|
|
185
185
|
- **Changing a prop rebuilds the widget.** Changing `type` or `filter` tears down and recreates the underlying `<bb-widget>`, losing in-widget state (map position, scroll, form input).
|
|
186
186
|
- **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.
|
|
187
|
-
- **Error UI is built in.**
|
|
187
|
+
- **Error UI is built in.** If the runtime script fails to load (network error), 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. Note this only covers script load failure — an unauthorized domain loads fine but renders empty widgets (see Prerequisites).
|
|
188
188
|
- **ESM-only.** This package ships as ES modules only (no CommonJS build). Use it in a project with ESM/bundler support.
|
|
189
189
|
- **Pre-release.** This package is `0.x` — the API may change.
|
|
190
190
|
|
|
@@ -27,5 +27,5 @@ declare global {
|
|
|
27
27
|
* </BuyingBuddyProvider>
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
|
-
export declare function BuyingBuddyProvider({ activationKey, domain, apiBaseUrl, children, fallback, }: BuyingBuddyProviderProps): import("react
|
|
30
|
+
export declare function BuyingBuddyProvider({ activationKey, domain, apiBaseUrl, children, fallback, }: BuyingBuddyProviderProps): import("react").JSX.Element;
|
|
31
31
|
//# sourceMappingURL=BuyingBuddyProvider.d.ts.map
|
|
@@ -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;
|
|
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;AAcD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,aAAa,EACb,MAAuB,EACvB,UAAU,EACV,QAAQ,EACR,QAAe,GAChB,EAAE,wBAAwB,+BAoG1B"}
|
|
@@ -13,6 +13,14 @@ export function useBuyingBuddy() {
|
|
|
13
13
|
return ctx;
|
|
14
14
|
}
|
|
15
15
|
const LOADED_ACCOUNTS = new Set();
|
|
16
|
+
/**
|
|
17
|
+
* The v5 widget runtime, served from the CDN — the exact same bundle every
|
|
18
|
+
* other official integration (WordPress, Joomla, PHP SDK) loads. Loading it
|
|
19
|
+
* directly (rather than via the `mbbv3/index/acid` bootstrap) keeps this
|
|
20
|
+
* package consistent with those embeds and ensures the bundle is served
|
|
21
|
+
* through CloudFront, not S3 origin.
|
|
22
|
+
*/
|
|
23
|
+
const MBB_BUNDLE_URL = "https://d2w6u17ngtanmy.cloudfront.net/scripts/my-buying-buddy.5.0.js.gz";
|
|
16
24
|
/**
|
|
17
25
|
* Provides the BuyingBuddy runtime context to child components.
|
|
18
26
|
*
|
|
@@ -41,12 +49,11 @@ export function BuyingBuddyProvider({ activationKey, domain = "www.mbb2.com", ap
|
|
|
41
49
|
useEffect(() => {
|
|
42
50
|
if (typeof window === "undefined")
|
|
43
51
|
return;
|
|
44
|
-
// Inject the widget theme stylesheet. The
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
// `domain`
|
|
48
|
-
//
|
|
49
|
-
// environment's problem, not this package's.
|
|
52
|
+
// Inject the widget theme stylesheet. The runtime bundle does not load a
|
|
53
|
+
// theme itself, so — exactly like the official WP/Joomla plugin embeds — we
|
|
54
|
+
// load it separately; without it widgets render unthemed and the map logs
|
|
55
|
+
// "Missing acid or theme data". Follows `domain` so the theme matches the
|
|
56
|
+
// environment (production vs preview).
|
|
50
57
|
const themeId = `mbb-theme-${activationKey}`;
|
|
51
58
|
if (!document.getElementById(themeId)) {
|
|
52
59
|
const theme = document.createElement("script");
|
|
@@ -55,8 +62,8 @@ export function BuyingBuddyProvider({ activationKey, domain = "www.mbb2.com", ap
|
|
|
55
62
|
theme.async = true;
|
|
56
63
|
document.head.appendChild(theme);
|
|
57
64
|
}
|
|
58
|
-
// If the runtime global already exists (
|
|
59
|
-
//
|
|
65
|
+
// If the runtime global already exists (a script tag in the page, or a
|
|
66
|
+
// prior mount), point data requests at the resolved base now.
|
|
60
67
|
if (window.MBB) {
|
|
61
68
|
window.MBB.apiBaseUrl = resolvedApiBaseUrl;
|
|
62
69
|
}
|
|
@@ -65,47 +72,35 @@ export function BuyingBuddyProvider({ activationKey, domain = "www.mbb2.com", ap
|
|
|
65
72
|
setIsLoaded(true);
|
|
66
73
|
return;
|
|
67
74
|
}
|
|
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
75
|
let cancelled = false;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const check = () => {
|
|
76
|
+
const scriptId = `mbb-script-${activationKey}`;
|
|
77
|
+
const markLoaded = () => {
|
|
76
78
|
if (cancelled)
|
|
77
79
|
return;
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
}
|
|
80
|
+
LOADED_ACCOUNTS.add(activationKey);
|
|
81
|
+
setIsLoaded(true);
|
|
94
82
|
};
|
|
95
|
-
const scriptId = `mbb-script-${activationKey}`;
|
|
96
|
-
// Script tag already exists in the DOM — just start polling.
|
|
97
83
|
if (document.getElementById(scriptId)) {
|
|
98
|
-
|
|
84
|
+
// Bundle already requested (prior mount) — treat as loaded.
|
|
85
|
+
markLoaded();
|
|
99
86
|
}
|
|
100
87
|
else {
|
|
88
|
+
// Initialise the MBB global the official-embed way (a single `data.acid`
|
|
89
|
+
// plus the data base URL) BEFORE the bundle executes, so its first data
|
|
90
|
+
// request uses our acid and base URL.
|
|
91
|
+
if (!window.MBB) {
|
|
92
|
+
window.MBB = {
|
|
93
|
+
seo: "false",
|
|
94
|
+
data: { acid: activationKey },
|
|
95
|
+
apiBaseUrl: resolvedApiBaseUrl,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
// Load the v5 runtime directly from the CDN.
|
|
101
99
|
const script = document.createElement("script");
|
|
102
100
|
script.id = scriptId;
|
|
103
|
-
script.src =
|
|
101
|
+
script.src = MBB_BUNDLE_URL;
|
|
104
102
|
script.async = true;
|
|
105
|
-
script.onload =
|
|
106
|
-
if (!cancelled)
|
|
107
|
-
check();
|
|
108
|
-
};
|
|
103
|
+
script.onload = markLoaded;
|
|
109
104
|
script.onerror = () => {
|
|
110
105
|
if (cancelled)
|
|
111
106
|
return;
|
|
@@ -115,10 +110,8 @@ export function BuyingBuddyProvider({ activationKey, domain = "www.mbb2.com", ap
|
|
|
115
110
|
}
|
|
116
111
|
return () => {
|
|
117
112
|
// Don't remove the script (MBB global state is persistent); just stop the
|
|
118
|
-
//
|
|
113
|
+
// load handlers from updating state after unmount.
|
|
119
114
|
cancelled = true;
|
|
120
|
-
if (timer)
|
|
121
|
-
clearTimeout(timer);
|
|
122
115
|
};
|
|
123
116
|
}, [activationKey, domain, resolvedApiBaseUrl]);
|
|
124
117
|
const value = { isLoaded, error, activationKey };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuyingBuddyProvider.js","sourceRoot":"","sources":["../src/BuyingBuddyProvider.tsx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|
|
1
|
+
import type { CSSProperties } from "react";
|
|
1
2
|
import type { BuyingBuddyWidgetProps } from "./types";
|
|
2
3
|
/**
|
|
3
4
|
* React wrapper for the `<bb-widget>` custom element.
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Renders the custom element directly — props become attributes and `style`
|
|
7
|
+
* (including `height`) lands straight on the element — matching the native
|
|
8
|
+
* Buying Buddy HTML/JS embed, with no extra wrapper `<div>`. `data-*`
|
|
9
|
+
* attributes are present when the element's `connectedCallback` runs (React
|
|
10
|
+
* emits them as attributes), so the widget initializes with the right type.
|
|
9
11
|
*
|
|
10
12
|
* Must be used within a `<BuyingBuddyProvider>`.
|
|
11
13
|
*
|
|
12
14
|
* @example
|
|
13
15
|
* ```tsx
|
|
14
|
-
* <BuyingBuddyWidget type="FeaturedGallery" filter="
|
|
16
|
+
* <BuyingBuddyWidget type="FeaturedGallery" filter="city:Denver+limit:6" />
|
|
15
17
|
* <BuyingBuddyWidget type="SearchForm" />
|
|
16
18
|
* <BuyingBuddyWidget type="InteractiveMap" style={{ height: "600px" }} />
|
|
17
19
|
* ```
|
|
18
20
|
*/
|
|
19
|
-
export declare function BuyingBuddyWidget({ type, filter, limit, order, style, className, id, onWidgetLoaded, }: BuyingBuddyWidgetProps): import("react
|
|
21
|
+
export declare function BuyingBuddyWidget({ type, filter, limit, order, style, className, id, onWidgetLoaded, }: BuyingBuddyWidgetProps): import("react").ReactElement<{
|
|
22
|
+
key: string;
|
|
23
|
+
ref: (el: HTMLElement | null) => void;
|
|
24
|
+
id: string | undefined;
|
|
25
|
+
className: string | undefined;
|
|
26
|
+
style: CSSProperties;
|
|
27
|
+
suppressHydrationWarning: boolean;
|
|
28
|
+
"data-type": import("./types").BuyingBuddyWidgetType;
|
|
29
|
+
"data-filter": string | undefined;
|
|
30
|
+
"data-limit": string | undefined;
|
|
31
|
+
"data-order": string | undefined;
|
|
32
|
+
}, string | import("react").JSXElementConstructor<any>> | null;
|
|
20
33
|
//# 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
|
|
1
|
+
{"version":3,"file":"BuyingBuddyWidget.d.ts","sourceRoot":"","sources":["../src/BuyingBuddyWidget.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAGtD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,IAAI,EACJ,MAAM,EACN,KAAK,EACL,KAAK,EACL,KAAK,EACL,SAAS,EACT,EAAE,EACF,cAAc,GACf,EAAE,sBAAsB;;cAgBY,WAAW,GAAG,IAAI;;;;;;;;;+DAkDtD"}
|
|
@@ -1,102 +1,85 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useRef, useEffect } from "react";
|
|
1
|
+
import { createElement, useCallback, useEffect, useRef } from "react";
|
|
3
2
|
import { useBuyingBuddy } from "./BuyingBuddyProvider";
|
|
4
3
|
/**
|
|
5
4
|
* React wrapper for the `<bb-widget>` custom element.
|
|
6
5
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* Renders the custom element directly — props become attributes and `style`
|
|
7
|
+
* (including `height`) lands straight on the element — matching the native
|
|
8
|
+
* Buying Buddy HTML/JS embed, with no extra wrapper `<div>`. `data-*`
|
|
9
|
+
* attributes are present when the element's `connectedCallback` runs (React
|
|
10
|
+
* emits them as attributes), so the widget initializes with the right type.
|
|
11
11
|
*
|
|
12
12
|
* Must be used within a `<BuyingBuddyProvider>`.
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```tsx
|
|
16
|
-
* <BuyingBuddyWidget type="FeaturedGallery" filter="
|
|
16
|
+
* <BuyingBuddyWidget type="FeaturedGallery" filter="city:Denver+limit:6" />
|
|
17
17
|
* <BuyingBuddyWidget type="SearchForm" />
|
|
18
18
|
* <BuyingBuddyWidget type="InteractiveMap" style={{ height: "600px" }} />
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
21
|
export function BuyingBuddyWidget({ type, filter, limit, order, style, className, id, onWidgetLoaded, }) {
|
|
22
|
-
const containerRef = useRef(null);
|
|
23
22
|
const { isLoaded } = useBuyingBuddy();
|
|
24
23
|
// Keep the latest onWidgetLoaded in a ref so changing its identity (e.g. an
|
|
25
|
-
// inline arrow created on every render)
|
|
26
|
-
//
|
|
27
|
-
// state and re-fire data requests.
|
|
24
|
+
// inline arrow created on every render) doesn't reattach listeners or re-init
|
|
25
|
+
// the widget.
|
|
28
26
|
const onWidgetLoadedRef = useRef(onWidgetLoaded);
|
|
29
27
|
useEffect(() => {
|
|
30
28
|
onWidgetLoadedRef.current = onWidgetLoaded;
|
|
31
29
|
}, [onWidgetLoaded]);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
// Callback ref: wire up the `componentLoaded` listener when the element
|
|
31
|
+
// mounts (and again after a `key`-driven re-init). The event is NOT composed,
|
|
32
|
+
// so it's dispatched either on the host (search widgets) or inside the shadow
|
|
33
|
+
// root (most widgets) — listen on both and fire once.
|
|
34
|
+
const cleanupRef = useRef(null);
|
|
35
|
+
const widgetRef = useCallback((el) => {
|
|
36
|
+
cleanupRef.current?.();
|
|
37
|
+
cleanupRef.current = null;
|
|
38
|
+
if (!el)
|
|
35
39
|
return;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// inconsistent attribute handling on custom elements in React <19.
|
|
40
|
-
// All attributes are set via setAttribute before DOM attachment,
|
|
41
|
-
// ensuring connectedCallback sees them immediately.
|
|
42
|
-
const widget = document.createElement("bb-widget");
|
|
43
|
-
widget.setAttribute("data-type", type);
|
|
44
|
-
if (filter !== undefined)
|
|
45
|
-
widget.setAttribute("data-filter", filter);
|
|
46
|
-
if (limit !== undefined)
|
|
47
|
-
widget.setAttribute("limit", String(limit));
|
|
48
|
-
if (order !== undefined)
|
|
49
|
-
widget.setAttribute("order", order);
|
|
50
|
-
if (id !== undefined)
|
|
51
|
-
widget.setAttribute("id", id);
|
|
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)
|
|
40
|
+
let fired = false;
|
|
41
|
+
const fire = () => {
|
|
42
|
+
if (fired)
|
|
70
43
|
return;
|
|
71
|
-
|
|
44
|
+
fired = true;
|
|
72
45
|
onWidgetLoadedRef.current?.();
|
|
73
46
|
};
|
|
74
|
-
|
|
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;
|
|
47
|
+
el.addEventListener("componentLoaded", fire, { once: true });
|
|
79
48
|
let attempts = 0;
|
|
80
|
-
|
|
81
|
-
|
|
49
|
+
let timer;
|
|
50
|
+
const attachShadow = () => {
|
|
51
|
+
if (fired)
|
|
82
52
|
return;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
root.addEventListener("componentLoaded", fireLoaded, { once: true });
|
|
53
|
+
if (el.shadowRoot) {
|
|
54
|
+
el.shadowRoot.addEventListener("componentLoaded", fire, { once: true });
|
|
86
55
|
}
|
|
87
|
-
else if (attempts++ <
|
|
88
|
-
|
|
56
|
+
else if (attempts++ < 100) {
|
|
57
|
+
timer = setTimeout(attachShadow, 50);
|
|
89
58
|
}
|
|
90
59
|
};
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (
|
|
94
|
-
clearTimeout(
|
|
95
|
-
container.innerHTML = "";
|
|
60
|
+
attachShadow();
|
|
61
|
+
cleanupRef.current = () => {
|
|
62
|
+
if (timer)
|
|
63
|
+
clearTimeout(timer);
|
|
96
64
|
};
|
|
97
|
-
}, [
|
|
65
|
+
}, []);
|
|
98
66
|
if (!isLoaded)
|
|
99
67
|
return null;
|
|
100
|
-
|
|
68
|
+
const widgetStyle = { display: "block", width: "100%", ...style };
|
|
69
|
+
// `key` ties the element identity to its config, so changing type/filter/etc.
|
|
70
|
+
// remounts (re-inits) the widget rather than mutating a live one.
|
|
71
|
+
const key = `${type}|${filter ?? ""}|${limit ?? ""}|${order ?? ""}|${id ?? ""}`;
|
|
72
|
+
return createElement("bb-widget", {
|
|
73
|
+
key,
|
|
74
|
+
ref: widgetRef,
|
|
75
|
+
id,
|
|
76
|
+
className,
|
|
77
|
+
style: widgetStyle,
|
|
78
|
+
suppressHydrationWarning: true,
|
|
79
|
+
"data-type": type,
|
|
80
|
+
"data-filter": filter,
|
|
81
|
+
"data-limit": limit !== undefined ? String(limit) : undefined,
|
|
82
|
+
"data-order": order,
|
|
83
|
+
});
|
|
101
84
|
}
|
|
102
85
|
//# sourceMappingURL=BuyingBuddyWidget.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuyingBuddyWidget.js","sourceRoot":"","sources":["../src/BuyingBuddyWidget.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BuyingBuddyWidget.js","sourceRoot":"","sources":["../src/BuyingBuddyWidget.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAGtE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAChC,IAAI,EACJ,MAAM,EACN,KAAK,EACL,KAAK,EACL,KAAK,EACL,SAAS,EACT,EAAE,EACF,cAAc,GACS;IACvB,MAAM,EAAE,QAAQ,EAAE,GAAG,cAAc,EAAE,CAAC;IAEtC,4EAA4E;IAC5E,8EAA8E;IAC9E,cAAc;IACd,MAAM,iBAAiB,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;IACjD,SAAS,CAAC,GAAG,EAAE;QACb,iBAAiB,CAAC,OAAO,GAAG,cAAc,CAAC;IAC7C,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC;IAErB,wEAAwE;IACxE,8EAA8E;IAC9E,8EAA8E;IAC9E,sDAAsD;IACtD,MAAM,UAAU,GAAG,MAAM,CAAsB,IAAI,CAAC,CAAC;IACrD,MAAM,SAAS,GAAG,WAAW,CAAC,CAAC,EAAsB,EAAE,EAAE;QACvD,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC;QACvB,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;QAC1B,IAAI,CAAC,EAAE;YAAE,OAAO;QAEhB,IAAI,KAAK,GAAG,KAAK,CAAC;QAClB,MAAM,IAAI,GAAG,GAAG,EAAE;YAChB,IAAI,KAAK;gBAAE,OAAO;YAClB,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AAK,EAAE,WAAW;QAClB,wBAAwB,EAAE,IAAI;QAC9B,WAAW,EAAE,IAAI;QACjB,aAAa,EAAE,MAAM;QACrB,YAAY,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS;QAC7D,YAAY,EAAE,KAAK;KACpB,CAAC,CAAC;AACL,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -44,18 +44,20 @@ export interface BuyingBuddyProviderProps {
|
|
|
44
44
|
*/
|
|
45
45
|
activationKey: string;
|
|
46
46
|
/**
|
|
47
|
-
* Domain the
|
|
48
|
-
* Defaults to "www.mbb2.com".
|
|
49
|
-
*
|
|
50
|
-
*
|
|
47
|
+
* Domain the widget theme and (by default) data requests are loaded from.
|
|
48
|
+
* Defaults to "www.mbb2.com"; set e.g. "preview.mbb2.com" to point the theme
|
|
49
|
+
* and data at the preview environment. The widget runtime bundle itself is
|
|
50
|
+
* always the production CDN build (the same one every other official embed
|
|
51
|
+
* loads), so it is not affected by this value. Only change this if directed
|
|
52
|
+
* by BuyingBuddy support or for testing.
|
|
51
53
|
*/
|
|
52
54
|
domain?: string;
|
|
53
55
|
/**
|
|
54
56
|
* Base URL for widget DATA requests (`window.MBB.apiBaseUrl`).
|
|
55
57
|
* Defaults to `https://{domain}`, so data follows the same environment as
|
|
56
58
|
* `domain`. Set it explicitly to point data at a different environment
|
|
57
|
-
* independently of the
|
|
58
|
-
*
|
|
59
|
+
* independently of the theme — e.g. a quick prod/preview flip for testing.
|
|
60
|
+
* Example: "https://preview.mbb2.com".
|
|
59
61
|
*/
|
|
60
62
|
apiBaseUrl?: string;
|
|
61
63
|
/** Children to render once the script is loaded. */
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,GAC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AAC,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,gFAAgF;IAChF,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,CAAC,EAAE,MAAM,IAAI,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;;;;;OAOG;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"}
|
|
@@ -46,7 +46,7 @@ export default function BuyingBuddyWidget(props: BuyingBuddyWidgetProps) {
|
|
|
46
46
|
)
|
|
47
47
|
const [errorMsg, setErrorMsg] = useState("")
|
|
48
48
|
|
|
49
|
-
// Load the MBB
|
|
49
|
+
// Load the MBB widget runtime
|
|
50
50
|
useEffect(() => {
|
|
51
51
|
if (!accountId) {
|
|
52
52
|
setStatus("error")
|
|
@@ -56,15 +56,19 @@ export default function BuyingBuddyWidget(props: BuyingBuddyWidgetProps) {
|
|
|
56
56
|
return
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
const scriptId = `mbb-script-${accountId}`
|
|
60
|
+
|
|
61
|
+
// Already requested (this mount, a prior mount, or a script tag in the
|
|
62
|
+
// page) — the runtime is loading or loaded; render the widget.
|
|
63
|
+
if (document.getElementById(scriptId)) {
|
|
61
64
|
setStatus("ready")
|
|
62
65
|
return
|
|
63
66
|
}
|
|
64
67
|
|
|
65
|
-
// Inject the widget theme stylesheet. The
|
|
66
|
-
//
|
|
67
|
-
// unthemed and the map logs
|
|
68
|
+
// Inject the widget theme stylesheet. The runtime bundle does not load
|
|
69
|
+
// a theme itself, so — like the official WP/Joomla embeds — we load it
|
|
70
|
+
// separately; without it widgets render unthemed and the map logs
|
|
71
|
+
// "Missing acid or theme data".
|
|
68
72
|
const themeId = `mbb-theme-${accountId}`
|
|
69
73
|
if (!document.getElementById(themeId)) {
|
|
70
74
|
const theme = document.createElement("script")
|
|
@@ -74,45 +78,25 @@ export default function BuyingBuddyWidget(props: BuyingBuddyWidgetProps) {
|
|
|
74
78
|
document.head.appendChild(theme)
|
|
75
79
|
}
|
|
76
80
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
// Initialise the MBB global the official-embed way (a single `data.acid`)
|
|
82
|
+
// before the bundle runs, so its first data request uses our acid.
|
|
83
|
+
if (!(window as any).MBB) {
|
|
84
|
+
;(window as any).MBB = { seo: "false", data: { acid: accountId } }
|
|
81
85
|
}
|
|
82
86
|
|
|
87
|
+
// Load the v5 runtime directly from the CDN — the same bundle every
|
|
88
|
+
// other official integration (WordPress, Joomla, PHP SDK) loads.
|
|
83
89
|
const script = document.createElement("script")
|
|
84
90
|
script.id = scriptId
|
|
85
|
-
script.src =
|
|
91
|
+
script.src =
|
|
92
|
+
"https://d2w6u17ngtanmy.cloudfront.net/scripts/my-buying-buddy.5.0.js.gz"
|
|
86
93
|
script.async = true
|
|
87
|
-
script.onload = () =>
|
|
94
|
+
script.onload = () => setStatus("ready")
|
|
88
95
|
script.onerror = () => {
|
|
89
96
|
setStatus("error")
|
|
90
97
|
setErrorMsg("Failed to load BuyingBuddy script.")
|
|
91
98
|
}
|
|
92
99
|
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
100
|
}, [accountId])
|
|
117
101
|
|
|
118
102
|
// Create the <bb-widget> custom element imperatively
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buyingbuddy/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "IDX MLS real estate integration for React, Next.js, and Framer — property search, map results, listings, lead capture, and CRM via Buying Buddy.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|