@buyingbuddy/react 0.0.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.
@@ -0,0 +1,31 @@
1
+ import type { BuyingBuddyProviderProps, BuyingBuddyContextValue } from "./types";
2
+ /**
3
+ * Hook to access the BuyingBuddy context.
4
+ * Must be used within a <BuyingBuddyProvider>.
5
+ */
6
+ export declare function useBuyingBuddy(): BuyingBuddyContextValue;
7
+ declare global {
8
+ interface Window {
9
+ MBB?: {
10
+ data: Record<string, string>;
11
+ apiBaseUrl: string;
12
+ [key: string]: unknown;
13
+ };
14
+ }
15
+ }
16
+ /**
17
+ * Provides the BuyingBuddy runtime context to child components.
18
+ *
19
+ * Loads the MBB script tag for the given account ID and exposes
20
+ * loading state via context. Widgets rendered as children will
21
+ * wait for the script to load before mounting.
22
+ *
23
+ * @example
24
+ * ```tsx
25
+ * <BuyingBuddyProvider accountId="your-account-id">
26
+ * <BuyingBuddyWidget type="FeaturedGallery" limit={12} />
27
+ * </BuyingBuddyProvider>
28
+ * ```
29
+ */
30
+ export declare function BuyingBuddyProvider({ accountId, domain, children, fallback, }: BuyingBuddyProviderProps): import("react/jsx-runtime").JSX.Element;
31
+ //# sourceMappingURL=BuyingBuddyProvider.d.ts.map
@@ -0,0 +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,SAAS,EACT,MAAuB,EACvB,QAAQ,EACR,QAAe,GAChB,EAAE,wBAAwB,2CAkF1B"}
@@ -0,0 +1,89 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createContext, useContext, useEffect, useState, useCallback } from "react";
3
+ const BuyingBuddyContext = createContext(null);
4
+ /**
5
+ * Hook to access the BuyingBuddy context.
6
+ * Must be used within a <BuyingBuddyProvider>.
7
+ */
8
+ export function useBuyingBuddy() {
9
+ const ctx = useContext(BuyingBuddyContext);
10
+ if (!ctx) {
11
+ throw new Error("useBuyingBuddy must be used within a <BuyingBuddyProvider>");
12
+ }
13
+ return ctx;
14
+ }
15
+ const LOADED_ACCOUNTS = new Set();
16
+ /**
17
+ * Provides the BuyingBuddy runtime context to child components.
18
+ *
19
+ * Loads the MBB script tag for the given account ID and exposes
20
+ * loading state via context. Widgets rendered as children will
21
+ * wait for the script to load before mounting.
22
+ *
23
+ * @example
24
+ * ```tsx
25
+ * <BuyingBuddyProvider accountId="your-account-id">
26
+ * <BuyingBuddyWidget type="FeaturedGallery" limit={12} />
27
+ * </BuyingBuddyProvider>
28
+ * ```
29
+ */
30
+ export function BuyingBuddyProvider({ accountId, domain = "www.mbb2.com", children, fallback = null, }) {
31
+ const [isLoaded, setIsLoaded] = useState(() => {
32
+ // If already loaded (e.g., script tag in HTML), skip loading
33
+ return typeof window !== "undefined" && !!window.MBB;
34
+ });
35
+ const [error, setError] = useState(null);
36
+ const handleLoad = useCallback(() => {
37
+ // Poll for MBB global — the JSONP script sets it after execution.
38
+ // Also detect the server's invalid-account response which defines
39
+ // displayInvalidAcidMsg instead of setting window.MBB.
40
+ let attempts = 0;
41
+ const check = () => {
42
+ if (window.MBB) {
43
+ LOADED_ACCOUNTS.add(accountId);
44
+ setIsLoaded(true);
45
+ }
46
+ else if ("displayInvalidAcidMsg" in window ||
47
+ attempts >= 50) {
48
+ setError(new Error("displayInvalidAcidMsg" in window
49
+ ? "BuyingBuddy: Invalid Account ID or unauthorized domain. Check your accountId and ensure this domain is registered in your BuyingBuddy dashboard."
50
+ : "BuyingBuddy script loaded but MBB global was not initialized."));
51
+ }
52
+ else {
53
+ attempts++;
54
+ setTimeout(check, 100);
55
+ }
56
+ };
57
+ check();
58
+ }, [accountId]);
59
+ useEffect(() => {
60
+ if (typeof window === "undefined")
61
+ return;
62
+ // Already loaded for this account
63
+ if (window.MBB && LOADED_ACCOUNTS.has(accountId)) {
64
+ setIsLoaded(true);
65
+ return;
66
+ }
67
+ const scriptId = `mbb-script-${accountId}`;
68
+ // Script tag already exists in the DOM
69
+ if (document.getElementById(scriptId)) {
70
+ handleLoad();
71
+ return;
72
+ }
73
+ const script = document.createElement("script");
74
+ script.id = scriptId;
75
+ script.src = `https://${domain}/mbbv3/index/acid/${accountId}`;
76
+ script.async = true;
77
+ script.onload = handleLoad;
78
+ script.onerror = () => {
79
+ setError(new Error(`Failed to load BuyingBuddy script for account: ${accountId}`));
80
+ };
81
+ document.head.appendChild(script);
82
+ return () => {
83
+ // Don't remove the script on unmount — MBB global state is persistent
84
+ };
85
+ }, [accountId, domain, handleLoad]);
86
+ const value = { isLoaded, error, accountId };
87
+ 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 }));
88
+ }
89
+ //# sourceMappingURL=BuyingBuddyProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BuyingBuddyProvider.js","sourceRoot":"","sources":["../src/BuyingBuddyProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EA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M,EAAE,UAAU,CAAC,CAAC,CAAC;IAEpC,MAAM,KAAK,GAA4B,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IAEtE,OAAO,CACL,KAAC,kBAAkB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACtC,KAAK,CAAC,CAAC,CAAC,CACP,eAAK,IAAI,EAAC,OAAO,EAAC,KAAK,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,EAAE,YAAY,EAAE,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,aACtL,kDAAmC,OAAE,KAAK,CAAC,OAAO,IAC9C,CACP,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,GACN,CAC/B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { BuyingBuddyWidgetProps } from "./types";
2
+ /**
3
+ * React wrapper for the `<bb-widget>` custom element.
4
+ *
5
+ * Creates the custom element imperatively via document.createElement and
6
+ * sets all attributes via setAttribute before appending to the DOM. This
7
+ * guarantees attributes are present when connectedCallback fires,
8
+ * regardless of React version (avoids React <19 attribute-handling issues).
9
+ *
10
+ * Must be used within a `<BuyingBuddyProvider>`.
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * <BuyingBuddyWidget type="FeaturedGallery" filter="FIELD(property_beds:3,4,5)" limit={20} />
15
+ * <BuyingBuddyWidget type="SearchForm" />
16
+ * <BuyingBuddyWidget type="InteractiveMap" style={{ height: "600px" }} />
17
+ * ```
18
+ */
19
+ export declare function BuyingBuddyWidget({ type, filter, limit, order, demo, featured, style, className, id, onWidgetLoaded, }: BuyingBuddyWidgetProps): import("react/jsx-runtime").JSX.Element | null;
20
+ //# sourceMappingURL=BuyingBuddyWidget.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,63 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useRef, useEffect } from "react";
3
+ import { useBuyingBuddy } from "./BuyingBuddyProvider";
4
+ /**
5
+ * React wrapper for the `<bb-widget>` custom element.
6
+ *
7
+ * Creates the custom element imperatively via document.createElement and
8
+ * sets all attributes via setAttribute before appending to the DOM. This
9
+ * guarantees attributes are present when connectedCallback fires,
10
+ * regardless of React version (avoids React <19 attribute-handling issues).
11
+ *
12
+ * Must be used within a `<BuyingBuddyProvider>`.
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * <BuyingBuddyWidget type="FeaturedGallery" filter="FIELD(property_beds:3,4,5)" limit={20} />
17
+ * <BuyingBuddyWidget type="SearchForm" />
18
+ * <BuyingBuddyWidget type="InteractiveMap" style={{ height: "600px" }} />
19
+ * ```
20
+ */
21
+ export function BuyingBuddyWidget({ type, filter, limit, order, demo, featured, style, className, id, onWidgetLoaded, }) {
22
+ const containerRef = useRef(null);
23
+ const { isLoaded } = useBuyingBuddy();
24
+ useEffect(() => {
25
+ const container = containerRef.current;
26
+ if (!container || !isLoaded)
27
+ return;
28
+ // Clear any previous widget (handles re-renders and prop changes)
29
+ container.innerHTML = "";
30
+ // Create the custom element imperatively — bypasses React's
31
+ // inconsistent attribute handling on custom elements in React <19.
32
+ // All attributes are set via setAttribute before DOM attachment,
33
+ // ensuring connectedCallback sees them immediately.
34
+ const widget = document.createElement("bb-widget");
35
+ widget.setAttribute("data-type", type);
36
+ if (filter !== undefined)
37
+ widget.setAttribute("data-filter", filter);
38
+ if (limit !== undefined)
39
+ widget.setAttribute("limit", String(limit));
40
+ if (order !== undefined)
41
+ 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
+ if (id !== undefined)
47
+ widget.setAttribute("id", id);
48
+ // Listen for componentLoaded before appending
49
+ if (onWidgetLoaded) {
50
+ widget.addEventListener("componentLoaded", () => onWidgetLoaded(), {
51
+ once: true,
52
+ });
53
+ }
54
+ container.appendChild(widget);
55
+ return () => {
56
+ container.innerHTML = "";
57
+ };
58
+ }, [type, filter, limit, order, demo, featured, id, isLoaded, onWidgetLoaded]);
59
+ if (!isLoaded)
60
+ return null;
61
+ return (_jsx("div", { ref: containerRef, style: { width: "100%", ...style }, className: className, suppressHydrationWarning: true }));
62
+ }
63
+ //# sourceMappingURL=BuyingBuddyWidget.js.map
@@ -0,0 +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,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC;QACvC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AAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC;IAE/E,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"}
@@ -0,0 +1,4 @@
1
+ export { BuyingBuddyProvider, useBuyingBuddy } from "./BuyingBuddyProvider";
2
+ export { BuyingBuddyWidget } from "./BuyingBuddyWidget";
3
+ export type { BuyingBuddyWidgetType, BuyingBuddyWidgetProps, BuyingBuddyProviderProps, BuyingBuddyContextValue, } from "./types";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,YAAY,EACV,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { BuyingBuddyProvider, useBuyingBuddy } from "./BuyingBuddyProvider";
2
+ export { BuyingBuddyWidget } from "./BuyingBuddyWidget";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Valid widget type values for `<bb-widget data-type="...">`.
3
+ *
4
+ * These map to internal custom elements via `getComponentType()` in MbbComponent.
5
+ * Use the PascalCase form (e.g., "FeaturedGallery") for consistency.
6
+ */
7
+ export type BuyingBuddyWidgetType = "Communities" | "FeaturedGallery" | "FeaturedList" | "InteractiveMap" | "SearchForm" | "SearchFormNLS" | "SearchResults" | "ListingResults" | "SearchDetails" | "QuickSearch" | "InteractiveMap2" | "OpenMap" | "ResultsMap" | "LcForm" | "LoginPanel" | "Brokers" | "OfficeRoster" | "Calculator" | "MarketReport" | "MarketStats" | "Disclaimer" | (string & {});
8
+ /**
9
+ * Common attributes accepted by all BuyingBuddy widgets.
10
+ *
11
+ * These are passed as HTML attributes on the `<bb-widget>` element.
12
+ * The widget reads them via `getAttribute()` and passes them to the API.
13
+ */
14
+ export interface BuyingBuddyWidgetProps {
15
+ /** Widget type to render. Required. */
16
+ type: BuyingBuddyWidgetType;
17
+ /**
18
+ * Property filter in FIELD() syntax or key:value format.
19
+ * Example: "FIELD(property_beds:3,4,5)" or "property_type:Residential"
20
+ */
21
+ filter?: string;
22
+ /** Maximum number of results to display. */
23
+ limit?: number | string;
24
+ /**
25
+ * Sort order for results.
26
+ * Example: "price_asc", "price_desc", "date_listed_desc"
27
+ */
28
+ order?: string;
29
+ /** Enable demo mode (shows sample data without an account). */
30
+ demo?: boolean | string;
31
+ /** Show only featured listings. */
32
+ featured?: boolean | string;
33
+ /** Inline style object or string for the widget container. */
34
+ style?: React.CSSProperties;
35
+ /** Additional CSS class name(s). */
36
+ className?: string;
37
+ /** HTML id attribute. */
38
+ id?: string;
39
+ /** Callback fired when the widget finishes loading its content. */
40
+ onWidgetLoaded?: () => void;
41
+ }
42
+ /**
43
+ * Props for the BuyingBuddyProvider component.
44
+ */
45
+ export interface BuyingBuddyProviderProps {
46
+ /**
47
+ * Your BuyingBuddy account ID.
48
+ * This is the `acid` value from your BuyingBuddy account.
49
+ */
50
+ accountId: string;
51
+ /**
52
+ * Custom MBB API domain. Defaults to "www.mbb2.com".
53
+ * Only change this if directed by BuyingBuddy support.
54
+ */
55
+ domain?: string;
56
+ /** Children to render once the script is loaded. */
57
+ children: React.ReactNode;
58
+ /**
59
+ * Content to show while the BuyingBuddy script is loading.
60
+ * Defaults to null (renders nothing until ready).
61
+ */
62
+ fallback?: React.ReactNode;
63
+ }
64
+ /**
65
+ * Context value exposed by BuyingBuddyProvider.
66
+ */
67
+ export interface BuyingBuddyContextValue {
68
+ /** Whether the MBB script has finished loading. */
69
+ isLoaded: boolean;
70
+ /** Error if the script failed to load. */
71
+ error: Error | null;
72
+ /** The account ID passed to the provider. */
73
+ accountId: string;
74
+ }
75
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +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,+DAA+D;IAC/D,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,CAAC,EAAE,MAAM,IAAI,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,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,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAC;CACnB"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@buyingbuddy/react",
3
+ "version": "0.0.1",
4
+ "description": "React wrapper for BuyingBuddy Web Component widgets",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsc",
20
+ "dev": "tsc --watch",
21
+ "test": "vitest run",
22
+ "prepublishOnly": "npm run build"
23
+ },
24
+ "peerDependencies": {
25
+ "react": ">=18",
26
+ "react-dom": ">=18"
27
+ },
28
+ "devDependencies": {
29
+ "@testing-library/jest-dom": "^6.9.1",
30
+ "@testing-library/react": "^16.3.2",
31
+ "@types/react": "^19.0.0",
32
+ "jsdom": "^28.1.0",
33
+ "react": "^19.0.0",
34
+ "react-dom": "^19.0.0",
35
+ "typescript": "^5.7.0",
36
+ "vitest": "^4.0.18"
37
+ },
38
+ "keywords": [
39
+ "buyingbuddy",
40
+ "react",
41
+ "web-components",
42
+ "real-estate",
43
+ "idx",
44
+ "mls"
45
+ ],
46
+ "license": "UNLICENSED",
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "https://github.com/Blue-Fire-Group/buyingbuddy.git",
50
+ "directory": "packages/buyingbuddy-react"
51
+ }
52
+ }