@duvandroid/react-blind-agents 0.1.1 → 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/dist/index.d.mts CHANGED
@@ -1,30 +1,70 @@
1
- interface BlindAgentsWidgetProps {
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ /** Common props shared by all widget types. */
4
+ interface BaseWidgetProps {
2
5
  /** Your Blind Agents public API key (ba_...) */
3
6
  apiKey: string;
7
+ /** Pre-filled WhatsApp number to skip identity verification */
8
+ userWhatsapp?: string;
9
+ /** Override the CDN base URL (useful for self-hosting) */
10
+ cdnBase?: string;
11
+ /** Script loading strategy @default "afterInteractive" */
12
+ strategy?: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';
13
+ /** Called once the script finishes loading */
14
+ onLoad?: () => void;
15
+ /** Called if the script fails to load */
16
+ onError?: (error: Error) => void;
17
+ }
18
+ /** Report / bug-reporter widget */
19
+ interface ReportWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {
4
20
  /** Accent color for the widget UI — any valid CSS color */
5
21
  primaryColor?: string;
6
22
  /** Title displayed in the widget panel header @default "Help Center" */
7
23
  title?: string;
8
24
  /** Label for the report button @default "Report an issue" */
9
25
  reportBtnText?: string;
10
- /** Emoji on the launcher floating button */
26
+ /** Emoji on the launcher floating button @default "🐛" */
11
27
  btnEmoji?: string;
12
28
  /** Tooltip on the launcher button */
13
29
  btnTooltip?: string;
14
30
  /** Text shown when there are no reports @default "No issues reported yet." */
15
31
  emptyText?: string;
16
- /** Pre-fill the user's WhatsApp number or email to skip identity verification */
17
- userWhatsapp?: string;
18
- /** Script loading strategy @default "afterInteractive" */
19
- strategy?: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';
20
- /** Override the CDN URL (useful for self-hosting) @default "https://cdn.blindagents.com/report.js" */
32
+ }
33
+ /** Webchat widget */
34
+ interface ChatWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {
35
+ /** The agent UUID to connect this chat to */
36
+ agentId?: string;
37
+ /** Accent color for the chat bubble and header */
38
+ primaryColor?: string;
39
+ }
40
+ /** Product guides widget */
41
+ interface GuideWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {
42
+ }
43
+ /** Root provider props — all children share this apiKey */
44
+ interface BlindAgentsProps extends BaseWidgetProps {
45
+ children: React.ReactNode;
46
+ }
47
+ /** @deprecated Use <BlindAgents apiKey="..."><BlindAgents.Report /></BlindAgents> instead */
48
+ interface BlindAgentsWidgetProps extends BaseWidgetProps {
49
+ primaryColor?: string;
50
+ title?: string;
51
+ reportBtnText?: string;
52
+ btnEmoji?: string;
53
+ btnTooltip?: string;
54
+ emptyText?: string;
55
+ /** @deprecated Prefer userWhatsapp */
21
56
  src?: string;
22
- /** Called once the script finishes loading */
23
- onLoad?: () => void;
24
- /** Called if the script fails to load */
25
- onError?: (error: Error) => void;
26
57
  }
27
58
 
28
- declare function BlindAgentsWidget({ apiKey, primaryColor, title, reportBtnText, btnEmoji, btnTooltip, emptyText, userWhatsapp, strategy, src, onLoad, onError, }: BlindAgentsWidgetProps): null;
59
+ declare function BlindAgents({ apiKey, userWhatsapp, cdnBase, strategy, children, }: BlindAgentsProps): react_jsx_runtime.JSX.Element;
60
+ declare namespace BlindAgents {
61
+ var Report: ({ primaryColor, title, reportBtnText, btnEmoji, btnTooltip, emptyText, userWhatsapp: localWhatsapp, cdnBase: localCdn, strategy: localStrategy, onLoad, onError, }: ReportWidgetProps) => null;
62
+ var Chat: ({ agentId, primaryColor, userWhatsapp: localWhatsapp, cdnBase: localCdn, strategy: localStrategy, onLoad, onError, }: ChatWidgetProps) => null;
63
+ var Guide: ({ userWhatsapp: localWhatsapp, cdnBase: localCdn, strategy: localStrategy, onLoad, onError, }: GuideWidgetProps) => null;
64
+ }
65
+ /** @deprecated Use <BlindAgents><BlindAgents.Report /></BlindAgents> */
66
+ declare function BlindAgentsWidget(props: ReportWidgetProps & {
67
+ apiKey: string;
68
+ }): react_jsx_runtime.JSX.Element;
29
69
 
30
- export { BlindAgentsWidget, type BlindAgentsWidgetProps };
70
+ export { BlindAgents, type BlindAgentsProps, BlindAgentsWidget, type BlindAgentsWidgetProps, type ChatWidgetProps, type GuideWidgetProps, type ReportWidgetProps };
package/dist/index.d.ts CHANGED
@@ -1,30 +1,70 @@
1
- interface BlindAgentsWidgetProps {
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ /** Common props shared by all widget types. */
4
+ interface BaseWidgetProps {
2
5
  /** Your Blind Agents public API key (ba_...) */
3
6
  apiKey: string;
7
+ /** Pre-filled WhatsApp number to skip identity verification */
8
+ userWhatsapp?: string;
9
+ /** Override the CDN base URL (useful for self-hosting) */
10
+ cdnBase?: string;
11
+ /** Script loading strategy @default "afterInteractive" */
12
+ strategy?: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';
13
+ /** Called once the script finishes loading */
14
+ onLoad?: () => void;
15
+ /** Called if the script fails to load */
16
+ onError?: (error: Error) => void;
17
+ }
18
+ /** Report / bug-reporter widget */
19
+ interface ReportWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {
4
20
  /** Accent color for the widget UI — any valid CSS color */
5
21
  primaryColor?: string;
6
22
  /** Title displayed in the widget panel header @default "Help Center" */
7
23
  title?: string;
8
24
  /** Label for the report button @default "Report an issue" */
9
25
  reportBtnText?: string;
10
- /** Emoji on the launcher floating button */
26
+ /** Emoji on the launcher floating button @default "🐛" */
11
27
  btnEmoji?: string;
12
28
  /** Tooltip on the launcher button */
13
29
  btnTooltip?: string;
14
30
  /** Text shown when there are no reports @default "No issues reported yet." */
15
31
  emptyText?: string;
16
- /** Pre-fill the user's WhatsApp number or email to skip identity verification */
17
- userWhatsapp?: string;
18
- /** Script loading strategy @default "afterInteractive" */
19
- strategy?: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';
20
- /** Override the CDN URL (useful for self-hosting) @default "https://cdn.blindagents.com/report.js" */
32
+ }
33
+ /** Webchat widget */
34
+ interface ChatWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {
35
+ /** The agent UUID to connect this chat to */
36
+ agentId?: string;
37
+ /** Accent color for the chat bubble and header */
38
+ primaryColor?: string;
39
+ }
40
+ /** Product guides widget */
41
+ interface GuideWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {
42
+ }
43
+ /** Root provider props — all children share this apiKey */
44
+ interface BlindAgentsProps extends BaseWidgetProps {
45
+ children: React.ReactNode;
46
+ }
47
+ /** @deprecated Use <BlindAgents apiKey="..."><BlindAgents.Report /></BlindAgents> instead */
48
+ interface BlindAgentsWidgetProps extends BaseWidgetProps {
49
+ primaryColor?: string;
50
+ title?: string;
51
+ reportBtnText?: string;
52
+ btnEmoji?: string;
53
+ btnTooltip?: string;
54
+ emptyText?: string;
55
+ /** @deprecated Prefer userWhatsapp */
21
56
  src?: string;
22
- /** Called once the script finishes loading */
23
- onLoad?: () => void;
24
- /** Called if the script fails to load */
25
- onError?: (error: Error) => void;
26
57
  }
27
58
 
28
- declare function BlindAgentsWidget({ apiKey, primaryColor, title, reportBtnText, btnEmoji, btnTooltip, emptyText, userWhatsapp, strategy, src, onLoad, onError, }: BlindAgentsWidgetProps): null;
59
+ declare function BlindAgents({ apiKey, userWhatsapp, cdnBase, strategy, children, }: BlindAgentsProps): react_jsx_runtime.JSX.Element;
60
+ declare namespace BlindAgents {
61
+ var Report: ({ primaryColor, title, reportBtnText, btnEmoji, btnTooltip, emptyText, userWhatsapp: localWhatsapp, cdnBase: localCdn, strategy: localStrategy, onLoad, onError, }: ReportWidgetProps) => null;
62
+ var Chat: ({ agentId, primaryColor, userWhatsapp: localWhatsapp, cdnBase: localCdn, strategy: localStrategy, onLoad, onError, }: ChatWidgetProps) => null;
63
+ var Guide: ({ userWhatsapp: localWhatsapp, cdnBase: localCdn, strategy: localStrategy, onLoad, onError, }: GuideWidgetProps) => null;
64
+ }
65
+ /** @deprecated Use <BlindAgents><BlindAgents.Report /></BlindAgents> */
66
+ declare function BlindAgentsWidget(props: ReportWidgetProps & {
67
+ apiKey: string;
68
+ }): react_jsx_runtime.JSX.Element;
29
69
 
30
- export { BlindAgentsWidget, type BlindAgentsWidgetProps };
70
+ export { BlindAgents, type BlindAgentsProps, BlindAgentsWidget, type BlindAgentsWidgetProps, type ChatWidgetProps, type GuideWidgetProps, type ReportWidgetProps };
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,51 +17,54 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
21
31
  var src_exports = {};
22
32
  __export(src_exports, {
33
+ BlindAgents: () => BlindAgents,
23
34
  BlindAgentsWidget: () => BlindAgentsWidget
24
35
  });
25
36
  module.exports = __toCommonJS(src_exports);
26
37
 
27
- // src/ReactBlindAgentsWidget.tsx
38
+ // src/ReactBlindAgents.tsx
39
+ var import_react2 = __toESM(require("react"));
40
+
41
+ // src/context.ts
28
42
  var import_react = require("react");
29
- var CDN_DEFAULT = "https://cdn.blindagents.com/report.js";
30
- function BlindAgentsWidget({
31
- apiKey,
32
- primaryColor,
33
- title,
34
- reportBtnText,
35
- btnEmoji,
36
- btnTooltip,
37
- emptyText,
38
- userWhatsapp,
39
- strategy = "afterInteractive",
40
- src = CDN_DEFAULT,
41
- onLoad,
42
- onError
43
- }) {
44
- const injected = (0, import_react.useRef)(false);
45
- (0, import_react.useEffect)(() => {
43
+
44
+ // src/types.ts
45
+ var CDN_BASE = "https://cdn.blindagents.com";
46
+
47
+ // src/context.ts
48
+ var BlindAgentsContext = (0, import_react.createContext)({
49
+ apiKey: "",
50
+ cdnBase: CDN_BASE,
51
+ strategy: "afterInteractive"
52
+ });
53
+
54
+ // src/ReactBlindAgents.tsx
55
+ var import_jsx_runtime = require("react/jsx-runtime");
56
+ function useScript(src, attrs, strategy, onLoad, onError) {
57
+ const injected = (0, import_react2.useRef)(false);
58
+ (0, import_react2.useEffect)(() => {
46
59
  if (injected.current) return;
47
60
  injected.current = true;
48
- const existing = document.querySelector(
49
- `script[src="${src}"][data-ba-managed]`
50
- );
51
- if (existing) return;
61
+ if (document.querySelector(`script[src="${src}"][data-ba-managed]`)) return;
52
62
  const el = document.createElement("script");
53
63
  el.src = src;
54
64
  el.setAttribute("data-ba-managed", "true");
55
- el.setAttribute("data-api-key", apiKey);
56
- if (primaryColor) el.setAttribute("data-primary-color", primaryColor);
57
- if (title) el.setAttribute("data-title", title);
58
- if (reportBtnText) el.setAttribute("data-report-btn-text", reportBtnText);
59
- if (btnEmoji) el.setAttribute("data-btn-emoji", btnEmoji);
60
- if (btnTooltip) el.setAttribute("data-btn-tooltip", btnTooltip);
61
- if (emptyText) el.setAttribute("data-empty-text", emptyText);
62
- if (userWhatsapp) el.setAttribute("data-user-whatsapp", userWhatsapp);
65
+ Object.entries(attrs).forEach(([k, v]) => {
66
+ if (v != null && v !== "") el.setAttribute(k, v);
67
+ });
63
68
  if (onLoad) el.addEventListener("load", () => onLoad());
64
69
  if (onError) el.addEventListener("error", () => onError(new Error(`Failed to load ${src}`)));
65
70
  const inject = () => {
@@ -67,7 +72,7 @@ function BlindAgentsWidget({
67
72
  if (strategy === "lazyOnload") el.async = true;
68
73
  document.head.appendChild(el);
69
74
  };
70
- if (strategy === "lazyOnload" && typeof window !== "undefined" && "requestIdleCallback" in window) {
75
+ if (strategy === "lazyOnload" && "requestIdleCallback" in window) {
71
76
  window.requestIdleCallback(inject);
72
77
  } else {
73
78
  inject();
@@ -76,11 +81,90 @@ function BlindAgentsWidget({
76
81
  el.parentNode?.removeChild(el);
77
82
  injected.current = false;
78
83
  };
79
- }, [apiKey, src]);
84
+ }, [src]);
85
+ }
86
+ function Report({
87
+ primaryColor,
88
+ title,
89
+ reportBtnText,
90
+ btnEmoji,
91
+ btnTooltip,
92
+ emptyText,
93
+ userWhatsapp: localWhatsapp,
94
+ cdnBase: localCdn,
95
+ strategy: localStrategy,
96
+ onLoad,
97
+ onError
98
+ }) {
99
+ const ctx = import_react2.default.useContext(BlindAgentsContext);
100
+ const src = `${localCdn ?? ctx.cdnBase}/report.js`;
101
+ const wa = localWhatsapp ?? ctx.userWhatsapp;
102
+ useScript(src, {
103
+ "data-api-key": ctx.apiKey,
104
+ "data-primary-color": primaryColor,
105
+ "data-title": title,
106
+ "data-report-btn-text": reportBtnText,
107
+ "data-btn-emoji": btnEmoji,
108
+ "data-btn-tooltip": btnTooltip,
109
+ "data-empty-text": emptyText,
110
+ "data-user-whatsapp": wa
111
+ }, localStrategy ?? ctx.strategy, onLoad, onError);
112
+ return null;
113
+ }
114
+ function Chat({
115
+ agentId,
116
+ primaryColor,
117
+ userWhatsapp: localWhatsapp,
118
+ cdnBase: localCdn,
119
+ strategy: localStrategy,
120
+ onLoad,
121
+ onError
122
+ }) {
123
+ const ctx = import_react2.default.useContext(BlindAgentsContext);
124
+ const src = `${localCdn ?? ctx.cdnBase}/chat.js`;
125
+ const wa = localWhatsapp ?? ctx.userWhatsapp;
126
+ useScript(src, {
127
+ "data-api-key": ctx.apiKey,
128
+ "data-agent-id": agentId,
129
+ "data-primary-color": primaryColor,
130
+ "data-user-whatsapp": wa
131
+ }, localStrategy ?? ctx.strategy, onLoad, onError);
80
132
  return null;
81
133
  }
134
+ function Guide({
135
+ userWhatsapp: localWhatsapp,
136
+ cdnBase: localCdn,
137
+ strategy: localStrategy,
138
+ onLoad,
139
+ onError
140
+ }) {
141
+ const ctx = import_react2.default.useContext(BlindAgentsContext);
142
+ const src = `${localCdn ?? ctx.cdnBase}/guide.js`;
143
+ const wa = localWhatsapp ?? ctx.userWhatsapp;
144
+ useScript(src, {
145
+ "data-api-key": ctx.apiKey,
146
+ "data-user-whatsapp": wa
147
+ }, localStrategy ?? ctx.strategy, onLoad, onError);
148
+ return null;
149
+ }
150
+ function BlindAgents({
151
+ apiKey,
152
+ userWhatsapp,
153
+ cdnBase = CDN_BASE,
154
+ strategy = "afterInteractive",
155
+ children
156
+ }) {
157
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BlindAgentsContext.Provider, { value: { apiKey, userWhatsapp, cdnBase, strategy }, children });
158
+ }
159
+ BlindAgents.Report = Report;
160
+ BlindAgents.Chat = Chat;
161
+ BlindAgents.Guide = Guide;
162
+ function BlindAgentsWidget(props) {
163
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BlindAgents, { apiKey: props.apiKey, userWhatsapp: props.userWhatsapp, strategy: props.strategy, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Report, { ...props }) });
164
+ }
82
165
  // Annotate the CommonJS export names for ESM import in node:
83
166
  0 && (module.exports = {
167
+ BlindAgents,
84
168
  BlindAgentsWidget
85
169
  });
86
170
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/ReactBlindAgentsWidget.tsx"],"sourcesContent":["// Plain React entry — Vite, CRA, etc.\n// For Next.js use: import { BlindAgentsWidget } from 'react-blind-agents/next'\nexport { BlindAgentsWidget } from './ReactBlindAgentsWidget';\nexport type { BlindAgentsWidgetProps } from './types';\n","'use client';\n\nimport { useEffect, useRef } from 'react';\nimport type { BlindAgentsWidgetProps } from './types';\n\nconst CDN_DEFAULT = 'https://cdn.blindagents.com/report.js';\n\nexport function BlindAgentsWidget({\n apiKey,\n primaryColor,\n title,\n reportBtnText,\n btnEmoji,\n btnTooltip,\n emptyText,\n userWhatsapp,\n strategy = 'afterInteractive',\n src = CDN_DEFAULT,\n onLoad,\n onError,\n}: BlindAgentsWidgetProps) {\n const injected = useRef(false);\n\n useEffect(() => {\n if (injected.current) return;\n injected.current = true;\n\n // Deduplicate across multiple widget instances\n const existing = document.querySelector<HTMLScriptElement>(\n `script[src=\"${src}\"][data-ba-managed]`\n );\n if (existing) return;\n\n const el = document.createElement('script');\n el.src = src;\n el.setAttribute('data-ba-managed', 'true');\n el.setAttribute('data-api-key', apiKey);\n if (primaryColor) el.setAttribute('data-primary-color', primaryColor);\n if (title) el.setAttribute('data-title', title);\n if (reportBtnText) el.setAttribute('data-report-btn-text', reportBtnText);\n if (btnEmoji) el.setAttribute('data-btn-emoji', btnEmoji);\n if (btnTooltip) el.setAttribute('data-btn-tooltip', btnTooltip);\n if (emptyText) el.setAttribute('data-empty-text', emptyText);\n if (userWhatsapp) el.setAttribute('data-user-whatsapp', userWhatsapp);\n\n if (onLoad) el.addEventListener('load', () => onLoad());\n if (onError) el.addEventListener('error', () => onError(new Error(`Failed to load ${src}`)));\n\n const inject = () => {\n if (strategy === 'afterInteractive') el.defer = true;\n if (strategy === 'lazyOnload') el.async = true;\n document.head.appendChild(el);\n };\n\n if (strategy === 'lazyOnload' && typeof window !== 'undefined' && 'requestIdleCallback' in window) {\n (window as Window & { requestIdleCallback: (cb: () => void) => void }).requestIdleCallback(inject);\n } else {\n inject();\n }\n\n return () => {\n el.parentNode?.removeChild(el);\n injected.current = false;\n };\n }, [apiKey, src]); // eslint-disable-line react-hooks/exhaustive-deps\n\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA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AA,IACnG,OAAO;AACL,aAAO;AAAA,IACT;AAEA,WAAO,MAAM;AACX,SAAG,YAAY,YAAY,EAAE;AAC7B,eAAS,UAAU;AAAA,IACrB;AAAA,EACF,GAAG,CAAC,QAAQ,GAAG,CAAC;AAEhB,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/ReactBlindAgents.tsx","../src/context.ts","../src/types.ts"],"sourcesContent":["// Plain React entry — Vite, CRA, Remix, etc.\n// For Next.js use: import { BlindAgents } from '@duvandroid/react-blind-agents/next'\nexport { BlindAgents, BlindAgentsWidget } from './ReactBlindAgents';\nexport type {\n BlindAgentsProps,\n ReportWidgetProps,\n ChatWidgetProps,\n GuideWidgetProps,\n BlindAgentsWidgetProps,\n} from './types';\n","'use client';\n\nimport React, { useEffect, useRef } from 'react';\nimport { BlindAgentsContext } from './context';\nimport type {\n BlindAgentsProps,\n ReportWidgetProps,\n ChatWidgetProps,\n GuideWidgetProps,\n} from './types';\nimport { CDN_BASE } from './types';\n\n// ── Script injection helper ───────────────────────────────────────────────────\n\nfunction useScript(\n src: string,\n attrs: Record<string, string | undefined>,\n strategy: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive',\n onLoad?: () => void,\n onError?: (e: Error) => void,\n) {\n const injected = useRef(false);\n\n useEffect(() => {\n if (injected.current) return;\n injected.current = true;\n\n // Deduplicate — only one script per src\n if (document.querySelector(`script[src=\"${src}\"][data-ba-managed]`)) return;\n\n const el = document.createElement('script');\n el.src = src;\n el.setAttribute('data-ba-managed', 'true');\n Object.entries(attrs).forEach(([k, v]) => {\n if (v != null && v !== '') el.setAttribute(k, v);\n });\n\n if (onLoad) el.addEventListener('load', () => onLoad());\n if (onError) el.addEventListener('error', () => onError(new Error(`Failed to load ${src}`)));\n\n const inject = () => {\n if (strategy === 'afterInteractive') el.defer = true;\n if (strategy === 'lazyOnload') el.async = true;\n document.head.appendChild(el);\n };\n\n if (strategy === 'lazyOnload' && 'requestIdleCallback' in window) {\n (window as any).requestIdleCallback(inject);\n } else {\n inject();\n }\n\n return () => { el.parentNode?.removeChild(el); injected.current = false; };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [src]);\n}\n\n// ── Widget sub-components ─────────────────────────────────────────────────────\n\nfunction Report({\n primaryColor,\n title,\n reportBtnText,\n btnEmoji,\n btnTooltip,\n emptyText,\n userWhatsapp: localWhatsapp,\n cdnBase: localCdn,\n strategy: localStrategy,\n onLoad,\n onError,\n}: ReportWidgetProps) {\n const ctx = React.useContext(BlindAgentsContext);\n const src = `${localCdn ?? ctx.cdnBase}/report.js`;\n const wa = localWhatsapp ?? ctx.userWhatsapp;\n\n useScript(src, {\n 'data-api-key': ctx.apiKey,\n 'data-primary-color': primaryColor,\n 'data-title': title,\n 'data-report-btn-text': reportBtnText,\n 'data-btn-emoji': btnEmoji,\n 'data-btn-tooltip': btnTooltip,\n 'data-empty-text': emptyText,\n 'data-user-whatsapp': wa,\n }, localStrategy ?? ctx.strategy, onLoad, onError);\n\n return null;\n}\n\nfunction Chat({\n agentId,\n primaryColor,\n userWhatsapp: localWhatsapp,\n cdnBase: localCdn,\n strategy: localStrategy,\n onLoad,\n onError,\n}: ChatWidgetProps) {\n const ctx = React.useContext(BlindAgentsContext);\n const src = `${localCdn ?? ctx.cdnBase}/chat.js`;\n const wa = localWhatsapp ?? ctx.userWhatsapp;\n\n useScript(src, {\n 'data-api-key': ctx.apiKey,\n 'data-agent-id': agentId,\n 'data-primary-color': primaryColor,\n 'data-user-whatsapp': wa,\n }, localStrategy ?? ctx.strategy, onLoad, onError);\n\n return null;\n}\n\nfunction Guide({\n userWhatsapp: localWhatsapp,\n cdnBase: localCdn,\n strategy: localStrategy,\n onLoad,\n onError,\n}: GuideWidgetProps) {\n const ctx = React.useContext(BlindAgentsContext);\n const src = `${localCdn ?? ctx.cdnBase}/guide.js`;\n const wa = localWhatsapp ?? ctx.userWhatsapp;\n\n useScript(src, {\n 'data-api-key': ctx.apiKey,\n 'data-user-whatsapp': wa,\n }, localStrategy ?? ctx.strategy, onLoad, onError);\n\n return null;\n}\n\n// ── Root provider ─────────────────────────────────────────────────────────────\n\nexport function BlindAgents({\n apiKey,\n userWhatsapp,\n cdnBase = CDN_BASE,\n strategy = 'afterInteractive',\n children,\n}: BlindAgentsProps) {\n return (\n <BlindAgentsContext.Provider value={{ apiKey, userWhatsapp, cdnBase, strategy }}>\n {children}\n </BlindAgentsContext.Provider>\n );\n}\n\nBlindAgents.Report = Report;\nBlindAgents.Chat = Chat;\nBlindAgents.Guide = Guide;\n\n// ── Legacy single-widget export (backwards compat) ───────────────────────────\n/** @deprecated Use <BlindAgents><BlindAgents.Report /></BlindAgents> */\nexport function BlindAgentsWidget(props: ReportWidgetProps & { apiKey: string }) {\n return (\n <BlindAgents apiKey={props.apiKey} userWhatsapp={props.userWhatsapp} strategy={props.strategy}>\n <Report {...props} />\n </BlindAgents>\n );\n}\n","import { createContext, useContext } from 'react';\nimport { CDN_BASE } from './types';\n\nexport interface BlindAgentsContextValue {\n apiKey: string;\n userWhatsapp?: string;\n cdnBase: string;\n strategy: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';\n}\n\nexport const BlindAgentsContext = createContext<BlindAgentsContextValue>({\n apiKey: '',\n cdnBase: CDN_BASE,\n strategy: 'afterInteractive',\n});\n\nexport function useBlindAgents(): BlindAgentsContextValue {\n return useContext(BlindAgentsContext);\n}\n","const CDN_BASE = 'https://cdn.blindagents.com';\n\nexport { CDN_BASE };\n\n/** Common props shared by all widget types. */\nexport interface BaseWidgetProps {\n /** Your Blind Agents public API key (ba_...) */\n apiKey: string;\n /** Pre-filled WhatsApp number to skip identity verification */\n userWhatsapp?: string;\n /** Override the CDN base URL (useful for self-hosting) */\n cdnBase?: string;\n /** Script loading strategy @default \"afterInteractive\" */\n strategy?: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';\n /** Called once the script finishes loading */\n onLoad?: () => void;\n /** Called if the script fails to load */\n onError?: (error: Error) => void;\n}\n\n/** Report / bug-reporter widget */\nexport interface ReportWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {\n /** Accent color for the widget UI — any valid CSS color */\n primaryColor?: string;\n /** Title displayed in the widget panel header @default \"Help Center\" */\n title?: string;\n /** Label for the report button @default \"Report an issue\" */\n reportBtnText?: string;\n /** Emoji on the launcher floating button @default \"🐛\" */\n btnEmoji?: string;\n /** Tooltip on the launcher button */\n btnTooltip?: string;\n /** Text shown when there are no reports @default \"No issues reported yet.\" */\n emptyText?: string;\n}\n\n/** Webchat widget */\nexport interface ChatWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {\n /** The agent UUID to connect this chat to */\n agentId?: string;\n /** Accent color for the chat bubble and header */\n primaryColor?: string;\n}\n\n/** Product guides widget */\nexport interface GuideWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {\n // No additional props yet — the guide SDK reads config from the dashboard\n}\n\n/** Root provider props — all children share this apiKey */\nexport interface BlindAgentsProps extends BaseWidgetProps {\n children: React.ReactNode;\n}\n\n// ── Legacy single-widget props (kept for backwards compatibility) ──────────────\n/** @deprecated Use <BlindAgents apiKey=\"...\"><BlindAgents.Report /></BlindAgents> instead */\nexport interface BlindAgentsWidgetProps extends BaseWidgetProps {\n primaryColor?: string;\n title?: string;\n reportBtnText?: string;\n btnEmoji?: string;\n btnTooltip?: string;\n emptyText?: string;\n /** @deprecated Prefer userWhatsapp */\n src?: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,IAAAA,gBAAyC;;;ACFzC,mBAA0C;;;ACA1C,IAAM,WAAW;;;ADUV,IAAM,yBAAqB,4BAAuC;AAAA,EACvE,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,UAAU;AACZ,CAAC;;;ADgIG;AAhIJ,SAAS,UACP,KACA,OACA,UACA,QACA,SACA;AACA,QAAM,eAAW,sBAAO,KAAK;AAE7B,+BAAU,MAAM;AACd,QAAI,SAAS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,4CAAC,eAAY,QAAQ,MAAM,QAAQ,cAAc,MAAM,cAAc,UAAU,MAAM,UACnF,sDAAC,UAAQ,GAAG,OAAO,GACrB;AAEJ;","names":["import_react","React"]}
package/dist/index.mjs CHANGED
@@ -1,39 +1,33 @@
1
- // src/ReactBlindAgentsWidget.tsx
2
- import { useEffect, useRef } from "react";
3
- var CDN_DEFAULT = "https://cdn.blindagents.com/report.js";
4
- function BlindAgentsWidget({
5
- apiKey,
6
- primaryColor,
7
- title,
8
- reportBtnText,
9
- btnEmoji,
10
- btnTooltip,
11
- emptyText,
12
- userWhatsapp,
13
- strategy = "afterInteractive",
14
- src = CDN_DEFAULT,
15
- onLoad,
16
- onError
17
- }) {
1
+ // src/ReactBlindAgents.tsx
2
+ import React, { useEffect, useRef } from "react";
3
+
4
+ // src/context.ts
5
+ import { createContext, useContext } from "react";
6
+
7
+ // src/types.ts
8
+ var CDN_BASE = "https://cdn.blindagents.com";
9
+
10
+ // src/context.ts
11
+ var BlindAgentsContext = createContext({
12
+ apiKey: "",
13
+ cdnBase: CDN_BASE,
14
+ strategy: "afterInteractive"
15
+ });
16
+
17
+ // src/ReactBlindAgents.tsx
18
+ import { jsx } from "react/jsx-runtime";
19
+ function useScript(src, attrs, strategy, onLoad, onError) {
18
20
  const injected = useRef(false);
19
21
  useEffect(() => {
20
22
  if (injected.current) return;
21
23
  injected.current = true;
22
- const existing = document.querySelector(
23
- `script[src="${src}"][data-ba-managed]`
24
- );
25
- if (existing) return;
24
+ if (document.querySelector(`script[src="${src}"][data-ba-managed]`)) return;
26
25
  const el = document.createElement("script");
27
26
  el.src = src;
28
27
  el.setAttribute("data-ba-managed", "true");
29
- el.setAttribute("data-api-key", apiKey);
30
- if (primaryColor) el.setAttribute("data-primary-color", primaryColor);
31
- if (title) el.setAttribute("data-title", title);
32
- if (reportBtnText) el.setAttribute("data-report-btn-text", reportBtnText);
33
- if (btnEmoji) el.setAttribute("data-btn-emoji", btnEmoji);
34
- if (btnTooltip) el.setAttribute("data-btn-tooltip", btnTooltip);
35
- if (emptyText) el.setAttribute("data-empty-text", emptyText);
36
- if (userWhatsapp) el.setAttribute("data-user-whatsapp", userWhatsapp);
28
+ Object.entries(attrs).forEach(([k, v]) => {
29
+ if (v != null && v !== "") el.setAttribute(k, v);
30
+ });
37
31
  if (onLoad) el.addEventListener("load", () => onLoad());
38
32
  if (onError) el.addEventListener("error", () => onError(new Error(`Failed to load ${src}`)));
39
33
  const inject = () => {
@@ -41,7 +35,7 @@ function BlindAgentsWidget({
41
35
  if (strategy === "lazyOnload") el.async = true;
42
36
  document.head.appendChild(el);
43
37
  };
44
- if (strategy === "lazyOnload" && typeof window !== "undefined" && "requestIdleCallback" in window) {
38
+ if (strategy === "lazyOnload" && "requestIdleCallback" in window) {
45
39
  window.requestIdleCallback(inject);
46
40
  } else {
47
41
  inject();
@@ -50,10 +44,89 @@ function BlindAgentsWidget({
50
44
  el.parentNode?.removeChild(el);
51
45
  injected.current = false;
52
46
  };
53
- }, [apiKey, src]);
47
+ }, [src]);
48
+ }
49
+ function Report({
50
+ primaryColor,
51
+ title,
52
+ reportBtnText,
53
+ btnEmoji,
54
+ btnTooltip,
55
+ emptyText,
56
+ userWhatsapp: localWhatsapp,
57
+ cdnBase: localCdn,
58
+ strategy: localStrategy,
59
+ onLoad,
60
+ onError
61
+ }) {
62
+ const ctx = React.useContext(BlindAgentsContext);
63
+ const src = `${localCdn ?? ctx.cdnBase}/report.js`;
64
+ const wa = localWhatsapp ?? ctx.userWhatsapp;
65
+ useScript(src, {
66
+ "data-api-key": ctx.apiKey,
67
+ "data-primary-color": primaryColor,
68
+ "data-title": title,
69
+ "data-report-btn-text": reportBtnText,
70
+ "data-btn-emoji": btnEmoji,
71
+ "data-btn-tooltip": btnTooltip,
72
+ "data-empty-text": emptyText,
73
+ "data-user-whatsapp": wa
74
+ }, localStrategy ?? ctx.strategy, onLoad, onError);
75
+ return null;
76
+ }
77
+ function Chat({
78
+ agentId,
79
+ primaryColor,
80
+ userWhatsapp: localWhatsapp,
81
+ cdnBase: localCdn,
82
+ strategy: localStrategy,
83
+ onLoad,
84
+ onError
85
+ }) {
86
+ const ctx = React.useContext(BlindAgentsContext);
87
+ const src = `${localCdn ?? ctx.cdnBase}/chat.js`;
88
+ const wa = localWhatsapp ?? ctx.userWhatsapp;
89
+ useScript(src, {
90
+ "data-api-key": ctx.apiKey,
91
+ "data-agent-id": agentId,
92
+ "data-primary-color": primaryColor,
93
+ "data-user-whatsapp": wa
94
+ }, localStrategy ?? ctx.strategy, onLoad, onError);
54
95
  return null;
55
96
  }
97
+ function Guide({
98
+ userWhatsapp: localWhatsapp,
99
+ cdnBase: localCdn,
100
+ strategy: localStrategy,
101
+ onLoad,
102
+ onError
103
+ }) {
104
+ const ctx = React.useContext(BlindAgentsContext);
105
+ const src = `${localCdn ?? ctx.cdnBase}/guide.js`;
106
+ const wa = localWhatsapp ?? ctx.userWhatsapp;
107
+ useScript(src, {
108
+ "data-api-key": ctx.apiKey,
109
+ "data-user-whatsapp": wa
110
+ }, localStrategy ?? ctx.strategy, onLoad, onError);
111
+ return null;
112
+ }
113
+ function BlindAgents({
114
+ apiKey,
115
+ userWhatsapp,
116
+ cdnBase = CDN_BASE,
117
+ strategy = "afterInteractive",
118
+ children
119
+ }) {
120
+ return /* @__PURE__ */ jsx(BlindAgentsContext.Provider, { value: { apiKey, userWhatsapp, cdnBase, strategy }, children });
121
+ }
122
+ BlindAgents.Report = Report;
123
+ BlindAgents.Chat = Chat;
124
+ BlindAgents.Guide = Guide;
125
+ function BlindAgentsWidget(props) {
126
+ return /* @__PURE__ */ jsx(BlindAgents, { apiKey: props.apiKey, userWhatsapp: props.userWhatsapp, strategy: props.strategy, children: /* @__PURE__ */ jsx(Report, { ...props }) });
127
+ }
56
128
  export {
129
+ BlindAgents,
57
130
  BlindAgentsWidget
58
131
  };
59
132
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ReactBlindAgentsWidget.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef } from 'react';\nimport type { BlindAgentsWidgetProps } from './types';\n\nconst CDN_DEFAULT = 'https://cdn.blindagents.com/report.js';\n\nexport function BlindAgentsWidget({\n apiKey,\n primaryColor,\n title,\n reportBtnText,\n btnEmoji,\n btnTooltip,\n emptyText,\n userWhatsapp,\n strategy = 'afterInteractive',\n src = CDN_DEFAULT,\n onLoad,\n onError,\n}: BlindAgentsWidgetProps) {\n const injected = useRef(false);\n\n useEffect(() => {\n if (injected.current) return;\n injected.current = true;\n\n // Deduplicate across multiple widget instances\n const existing = document.querySelector<HTMLScriptElement>(\n `script[src=\"${src}\"][data-ba-managed]`\n );\n if (existing) return;\n\n const el = document.createElement('script');\n el.src = src;\n el.setAttribute('data-ba-managed', 'true');\n el.setAttribute('data-api-key', apiKey);\n if (primaryColor) el.setAttribute('data-primary-color', primaryColor);\n if (title) el.setAttribute('data-title', title);\n if (reportBtnText) el.setAttribute('data-report-btn-text', reportBtnText);\n if (btnEmoji) el.setAttribute('data-btn-emoji', btnEmoji);\n if (btnTooltip) el.setAttribute('data-btn-tooltip', btnTooltip);\n if (emptyText) el.setAttribute('data-empty-text', emptyText);\n if (userWhatsapp) el.setAttribute('data-user-whatsapp', userWhatsapp);\n\n if (onLoad) el.addEventListener('load', () => onLoad());\n if (onError) el.addEventListener('error', () => onError(new Error(`Failed to load ${src}`)));\n\n const inject = () => {\n if (strategy === 'afterInteractive') el.defer = true;\n if (strategy === 'lazyOnload') el.async = true;\n document.head.appendChild(el);\n };\n\n if (strategy === 'lazyOnload' && typeof window !== 'undefined' && 'requestIdleCallback' in window) {\n (window as Window & { requestIdleCallback: (cb: () => void) => void }).requestIdleCallback(inject);\n } else {\n inject();\n }\n\n return () => {\n el.parentNode?.removeChild(el);\n injected.current = false;\n };\n }, [apiKey, src]); // eslint-disable-line react-hooks/exhaustive-deps\n\n return null;\n}\n"],"mappings":";AAEA,SAAS,WAAW,cAAc;AAGlC,IAAM,cAAc;AA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SAAG,YAAY,YAAY,EAAE;AAC7B,eAAS,UAAU;AAAA,IACrB;AAAA,EACF,GAAG,CAAC,QAAQ,GAAG,CAAC;AAEhB,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/ReactBlindAgents.tsx","../src/context.ts","../src/types.ts"],"sourcesContent":["'use client';\n\nimport React, { useEffect, useRef } from 'react';\nimport { BlindAgentsContext } from './context';\nimport type {\n BlindAgentsProps,\n ReportWidgetProps,\n ChatWidgetProps,\n GuideWidgetProps,\n} from './types';\nimport { CDN_BASE } from './types';\n\n// ── Script injection helper ───────────────────────────────────────────────────\n\nfunction useScript(\n src: string,\n attrs: Record<string, string | undefined>,\n strategy: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive',\n onLoad?: () => void,\n onError?: (e: Error) => void,\n) {\n const injected = useRef(false);\n\n useEffect(() => {\n if (injected.current) return;\n injected.current = true;\n\n // Deduplicate — only one script per src\n if (document.querySelector(`script[src=\"${src}\"][data-ba-managed]`)) return;\n\n const el = document.createElement('script');\n el.src = src;\n el.setAttribute('data-ba-managed', 'true');\n Object.entries(attrs).forEach(([k, v]) => {\n if (v != null && v !== '') el.setAttribute(k, v);\n });\n\n if (onLoad) el.addEventListener('load', () => onLoad());\n if (onError) el.addEventListener('error', () => onError(new Error(`Failed to load ${src}`)));\n\n const inject = () => {\n if (strategy === 'afterInteractive') el.defer = true;\n if (strategy === 'lazyOnload') el.async = true;\n document.head.appendChild(el);\n };\n\n if (strategy === 'lazyOnload' && 'requestIdleCallback' in window) {\n (window as any).requestIdleCallback(inject);\n } else {\n inject();\n }\n\n return () => { el.parentNode?.removeChild(el); injected.current = false; };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [src]);\n}\n\n// ── Widget sub-components ─────────────────────────────────────────────────────\n\nfunction Report({\n primaryColor,\n title,\n reportBtnText,\n btnEmoji,\n btnTooltip,\n emptyText,\n userWhatsapp: localWhatsapp,\n cdnBase: localCdn,\n strategy: localStrategy,\n onLoad,\n onError,\n}: ReportWidgetProps) {\n const ctx = React.useContext(BlindAgentsContext);\n const src = `${localCdn ?? ctx.cdnBase}/report.js`;\n const wa = localWhatsapp ?? ctx.userWhatsapp;\n\n useScript(src, {\n 'data-api-key': ctx.apiKey,\n 'data-primary-color': primaryColor,\n 'data-title': title,\n 'data-report-btn-text': reportBtnText,\n 'data-btn-emoji': btnEmoji,\n 'data-btn-tooltip': btnTooltip,\n 'data-empty-text': emptyText,\n 'data-user-whatsapp': wa,\n }, localStrategy ?? ctx.strategy, onLoad, onError);\n\n return null;\n}\n\nfunction Chat({\n agentId,\n primaryColor,\n userWhatsapp: localWhatsapp,\n cdnBase: localCdn,\n strategy: localStrategy,\n onLoad,\n onError,\n}: ChatWidgetProps) {\n const ctx = React.useContext(BlindAgentsContext);\n const src = `${localCdn ?? ctx.cdnBase}/chat.js`;\n const wa = localWhatsapp ?? ctx.userWhatsapp;\n\n useScript(src, {\n 'data-api-key': ctx.apiKey,\n 'data-agent-id': agentId,\n 'data-primary-color': primaryColor,\n 'data-user-whatsapp': wa,\n }, localStrategy ?? ctx.strategy, onLoad, onError);\n\n return null;\n}\n\nfunction Guide({\n userWhatsapp: localWhatsapp,\n cdnBase: localCdn,\n strategy: localStrategy,\n onLoad,\n onError,\n}: GuideWidgetProps) {\n const ctx = React.useContext(BlindAgentsContext);\n const src = `${localCdn ?? ctx.cdnBase}/guide.js`;\n const wa = localWhatsapp ?? ctx.userWhatsapp;\n\n useScript(src, {\n 'data-api-key': ctx.apiKey,\n 'data-user-whatsapp': wa,\n }, localStrategy ?? ctx.strategy, onLoad, onError);\n\n return null;\n}\n\n// ── Root provider ─────────────────────────────────────────────────────────────\n\nexport function BlindAgents({\n apiKey,\n userWhatsapp,\n cdnBase = CDN_BASE,\n strategy = 'afterInteractive',\n children,\n}: BlindAgentsProps) {\n return (\n <BlindAgentsContext.Provider value={{ apiKey, userWhatsapp, cdnBase, strategy }}>\n {children}\n </BlindAgentsContext.Provider>\n );\n}\n\nBlindAgents.Report = Report;\nBlindAgents.Chat = Chat;\nBlindAgents.Guide = Guide;\n\n// ── Legacy single-widget export (backwards compat) ───────────────────────────\n/** @deprecated Use <BlindAgents><BlindAgents.Report /></BlindAgents> */\nexport function BlindAgentsWidget(props: ReportWidgetProps & { apiKey: string }) {\n return (\n <BlindAgents apiKey={props.apiKey} userWhatsapp={props.userWhatsapp} strategy={props.strategy}>\n <Report {...props} />\n </BlindAgents>\n );\n}\n","import { createContext, useContext } from 'react';\nimport { CDN_BASE } from './types';\n\nexport interface BlindAgentsContextValue {\n apiKey: string;\n userWhatsapp?: string;\n cdnBase: string;\n strategy: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';\n}\n\nexport const BlindAgentsContext = createContext<BlindAgentsContextValue>({\n apiKey: '',\n cdnBase: CDN_BASE,\n strategy: 'afterInteractive',\n});\n\nexport function useBlindAgents(): BlindAgentsContextValue {\n return useContext(BlindAgentsContext);\n}\n","const CDN_BASE = 'https://cdn.blindagents.com';\n\nexport { CDN_BASE };\n\n/** Common props shared by all widget types. */\nexport interface BaseWidgetProps {\n /** Your Blind Agents public API key (ba_...) */\n apiKey: string;\n /** Pre-filled WhatsApp number to skip identity verification */\n userWhatsapp?: string;\n /** Override the CDN base URL (useful for self-hosting) */\n cdnBase?: string;\n /** Script loading strategy @default \"afterInteractive\" */\n strategy?: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';\n /** Called once the script finishes loading */\n onLoad?: () => void;\n /** Called if the script fails to load */\n onError?: (error: Error) => void;\n}\n\n/** Report / bug-reporter widget */\nexport interface ReportWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {\n /** Accent color for the widget UI — any valid CSS color */\n primaryColor?: string;\n /** Title displayed in the widget panel header @default \"Help Center\" */\n title?: string;\n /** Label for the report button @default \"Report an issue\" */\n reportBtnText?: string;\n /** Emoji on the launcher floating button @default \"🐛\" */\n btnEmoji?: string;\n /** Tooltip on the launcher button */\n btnTooltip?: string;\n /** Text shown when there are no reports @default \"No issues reported yet.\" */\n emptyText?: string;\n}\n\n/** Webchat widget */\nexport interface ChatWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {\n /** The agent UUID to connect this chat to */\n agentId?: string;\n /** Accent color for the chat bubble and header */\n primaryColor?: string;\n}\n\n/** Product guides widget */\nexport interface GuideWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {\n // No additional props yet — the guide SDK reads config from the dashboard\n}\n\n/** Root provider props — all children share this apiKey */\nexport interface BlindAgentsProps extends BaseWidgetProps {\n children: React.ReactNode;\n}\n\n// ── Legacy single-widget props (kept for backwards compatibility) ──────────────\n/** @deprecated Use <BlindAgents apiKey=\"...\"><BlindAgents.Report /></BlindAgents> instead */\nexport interface BlindAgentsWidgetProps extends BaseWidgetProps {\n primaryColor?: string;\n title?: string;\n reportBtnText?: string;\n btnEmoji?: string;\n btnTooltip?: string;\n emptyText?: string;\n /** @deprecated Prefer userWhatsapp */\n src?: string;\n}\n"],"mappings":";AAEA,OAAO,SAAS,WAAW,cAAc;;;ACFzC,SAAS,eAAe,kBAAkB;;;ACA1C,IAAM,WAAW;;;ADUV,IAAM,qBAAqB,cAAuC;AAAA,EACvE,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,UAAU;AACZ,CAAC;;;ADgIG;AAhIJ,SAAS,UACP,KACA,OACA,UACA,QACA,SACA;AACA,QAAM,WAAW,OAAO,KAAK;AAE7B,YAAU,MAAM;AACd,QAAI,SAAS,QAAS;AACtB,aAAS,UAAU;AAGnB,QAAI,SAAS,cAAc,eAAe,GAAG,qBAAqB,EAAG;AAErE,UAAM,KAAK,SAAS,cAAc,QAAQ;AAC1C,OAAG,MAAM;AACT,OAAG,aAAa,mBAAmB,MAAM;AACzC,WAAO,QAAQ,KAAK,EAAE,QAAQ,CAAC,CAAC,GAAG,CAAC,MAAM;AACxC,UAAI,KAAK,QAAQ,MAAM,GAAI,IAAG,aAAa,GAAG,CAAC;AAAA,IACjD,CAAC;AAED,QAAI,OAAS,IAAG,iB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AAG,YAAY,IAAI,OAAO;AACtC,QAAM,KAAM,iBAAiB,IAAI;AAEjC,YAAU,KAAK;AAAA,IACb,gBAAsB,IAAI;AAAA,IAC1B,iBAAsB;AAAA,IACtB,sBAAsB;AAAA,IACtB,sBAAsB;AAAA,EACxB,GAAG,iBAAiB,IAAI,UAAU,QAAQ,OAAO;AAEjD,SAAO;AACT;AAEA,SAAS,MAAM;AAAA,EACb,cAAc;AAAA,EACd,SAAS;AAAA,EACT,UAAU;AAAA,EACV;AAAA,EACA;AACF,GAAqB;AACnB,QAAM,MAAM,MAAM,WAAW,kBAAkB;AAC/C,QAAM,MAAM,GAAG,YAAY,IAAI,OAAO;AACtC,QAAM,KAAM,iBAAiB,IAAI;AAEjC,YAAU,KAAK;AAAA,IACb,gBAAsB,IAAI;AAAA,IAC1B,sBAAsB;AAAA,EACxB,GAAG,iBAAiB,IAAI,UAAU,QAAQ,OAAO;AAEjD,SAAO;AACT;AAIO,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV,WAAW;AAAA,EACX;AACF,GAAqB;AACnB,SACE,oBAAC,mBAAmB,UAAnB,EAA4B,OAAO,EAAE,QAAQ,cAAc,SAAS,SAAS,GAC3E,UACH;AAEJ;AAEA,YAAY,SAAS;AACrB,YAAY,OAAS;AACrB,YAAY,QAAS;AAId,SAAS,kBAAkB,OAA+C;AAC/E,SACE,oBAAC,eAAY,QAAQ,MAAM,QAAQ,cAAc,MAAM,cAAc,UAAU,MAAM,UACnF,8BAAC,UAAQ,GAAG,OAAO,GACrB;AAEJ;","names":[]}
package/dist/next.d.mts CHANGED
@@ -1,32 +1,70 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
 
3
- interface BlindAgentsWidgetProps {
3
+ /** Common props shared by all widget types. */
4
+ interface BaseWidgetProps {
4
5
  /** Your Blind Agents public API key (ba_...) */
5
6
  apiKey: string;
7
+ /** Pre-filled WhatsApp number to skip identity verification */
8
+ userWhatsapp?: string;
9
+ /** Override the CDN base URL (useful for self-hosting) */
10
+ cdnBase?: string;
11
+ /** Script loading strategy @default "afterInteractive" */
12
+ strategy?: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';
13
+ /** Called once the script finishes loading */
14
+ onLoad?: () => void;
15
+ /** Called if the script fails to load */
16
+ onError?: (error: Error) => void;
17
+ }
18
+ /** Report / bug-reporter widget */
19
+ interface ReportWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {
6
20
  /** Accent color for the widget UI — any valid CSS color */
7
21
  primaryColor?: string;
8
22
  /** Title displayed in the widget panel header @default "Help Center" */
9
23
  title?: string;
10
24
  /** Label for the report button @default "Report an issue" */
11
25
  reportBtnText?: string;
12
- /** Emoji on the launcher floating button */
26
+ /** Emoji on the launcher floating button @default "🐛" */
13
27
  btnEmoji?: string;
14
28
  /** Tooltip on the launcher button */
15
29
  btnTooltip?: string;
16
30
  /** Text shown when there are no reports @default "No issues reported yet." */
17
31
  emptyText?: string;
18
- /** Pre-fill the user's WhatsApp number or email to skip identity verification */
19
- userWhatsapp?: string;
20
- /** Script loading strategy @default "afterInteractive" */
21
- strategy?: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';
22
- /** Override the CDN URL (useful for self-hosting) @default "https://cdn.blindagents.com/report.js" */
32
+ }
33
+ /** Webchat widget */
34
+ interface ChatWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {
35
+ /** The agent UUID to connect this chat to */
36
+ agentId?: string;
37
+ /** Accent color for the chat bubble and header */
38
+ primaryColor?: string;
39
+ }
40
+ /** Product guides widget */
41
+ interface GuideWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {
42
+ }
43
+ /** Root provider props — all children share this apiKey */
44
+ interface BlindAgentsProps extends BaseWidgetProps {
45
+ children: React.ReactNode;
46
+ }
47
+ /** @deprecated Use <BlindAgents apiKey="..."><BlindAgents.Report /></BlindAgents> instead */
48
+ interface BlindAgentsWidgetProps extends BaseWidgetProps {
49
+ primaryColor?: string;
50
+ title?: string;
51
+ reportBtnText?: string;
52
+ btnEmoji?: string;
53
+ btnTooltip?: string;
54
+ emptyText?: string;
55
+ /** @deprecated Prefer userWhatsapp */
23
56
  src?: string;
24
- /** Called once the script finishes loading */
25
- onLoad?: () => void;
26
- /** Called if the script fails to load */
27
- onError?: (error: Error) => void;
28
57
  }
29
58
 
30
- declare function BlindAgentsWidget({ apiKey, primaryColor, title, reportBtnText, btnEmoji, btnTooltip, emptyText, userWhatsapp, strategy, src, onLoad, onError, }: BlindAgentsWidgetProps): react_jsx_runtime.JSX.Element;
59
+ declare function BlindAgents({ apiKey, userWhatsapp, cdnBase, strategy, children, }: BlindAgentsProps): react_jsx_runtime.JSX.Element;
60
+ declare namespace BlindAgents {
61
+ var Report: ({ primaryColor, title, reportBtnText, btnEmoji, btnTooltip, emptyText, userWhatsapp: localWhatsapp, cdnBase: localCdn, strategy: localStrategy, onLoad, onError, }: ReportWidgetProps) => react_jsx_runtime.JSX.Element;
62
+ var Chat: ({ agentId, primaryColor, userWhatsapp: localWhatsapp, cdnBase: localCdn, strategy: localStrategy, onLoad, onError, }: ChatWidgetProps) => react_jsx_runtime.JSX.Element;
63
+ var Guide: ({ userWhatsapp: localWhatsapp, cdnBase: localCdn, strategy: localStrategy, onLoad, onError, }: GuideWidgetProps) => react_jsx_runtime.JSX.Element;
64
+ }
65
+ /** @deprecated Use <BlindAgents><BlindAgents.Report /></BlindAgents> */
66
+ declare function BlindAgentsWidget(props: ReportWidgetProps & {
67
+ apiKey: string;
68
+ }): react_jsx_runtime.JSX.Element;
31
69
 
32
- export { BlindAgentsWidget, type BlindAgentsWidgetProps };
70
+ export { BlindAgents, type BlindAgentsProps, BlindAgentsWidget, type BlindAgentsWidgetProps, type ChatWidgetProps, type GuideWidgetProps, type ReportWidgetProps };
package/dist/next.d.ts CHANGED
@@ -1,32 +1,70 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
 
3
- interface BlindAgentsWidgetProps {
3
+ /** Common props shared by all widget types. */
4
+ interface BaseWidgetProps {
4
5
  /** Your Blind Agents public API key (ba_...) */
5
6
  apiKey: string;
7
+ /** Pre-filled WhatsApp number to skip identity verification */
8
+ userWhatsapp?: string;
9
+ /** Override the CDN base URL (useful for self-hosting) */
10
+ cdnBase?: string;
11
+ /** Script loading strategy @default "afterInteractive" */
12
+ strategy?: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';
13
+ /** Called once the script finishes loading */
14
+ onLoad?: () => void;
15
+ /** Called if the script fails to load */
16
+ onError?: (error: Error) => void;
17
+ }
18
+ /** Report / bug-reporter widget */
19
+ interface ReportWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {
6
20
  /** Accent color for the widget UI — any valid CSS color */
7
21
  primaryColor?: string;
8
22
  /** Title displayed in the widget panel header @default "Help Center" */
9
23
  title?: string;
10
24
  /** Label for the report button @default "Report an issue" */
11
25
  reportBtnText?: string;
12
- /** Emoji on the launcher floating button */
26
+ /** Emoji on the launcher floating button @default "🐛" */
13
27
  btnEmoji?: string;
14
28
  /** Tooltip on the launcher button */
15
29
  btnTooltip?: string;
16
30
  /** Text shown when there are no reports @default "No issues reported yet." */
17
31
  emptyText?: string;
18
- /** Pre-fill the user's WhatsApp number or email to skip identity verification */
19
- userWhatsapp?: string;
20
- /** Script loading strategy @default "afterInteractive" */
21
- strategy?: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';
22
- /** Override the CDN URL (useful for self-hosting) @default "https://cdn.blindagents.com/report.js" */
32
+ }
33
+ /** Webchat widget */
34
+ interface ChatWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {
35
+ /** The agent UUID to connect this chat to */
36
+ agentId?: string;
37
+ /** Accent color for the chat bubble and header */
38
+ primaryColor?: string;
39
+ }
40
+ /** Product guides widget */
41
+ interface GuideWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {
42
+ }
43
+ /** Root provider props — all children share this apiKey */
44
+ interface BlindAgentsProps extends BaseWidgetProps {
45
+ children: React.ReactNode;
46
+ }
47
+ /** @deprecated Use <BlindAgents apiKey="..."><BlindAgents.Report /></BlindAgents> instead */
48
+ interface BlindAgentsWidgetProps extends BaseWidgetProps {
49
+ primaryColor?: string;
50
+ title?: string;
51
+ reportBtnText?: string;
52
+ btnEmoji?: string;
53
+ btnTooltip?: string;
54
+ emptyText?: string;
55
+ /** @deprecated Prefer userWhatsapp */
23
56
  src?: string;
24
- /** Called once the script finishes loading */
25
- onLoad?: () => void;
26
- /** Called if the script fails to load */
27
- onError?: (error: Error) => void;
28
57
  }
29
58
 
30
- declare function BlindAgentsWidget({ apiKey, primaryColor, title, reportBtnText, btnEmoji, btnTooltip, emptyText, userWhatsapp, strategy, src, onLoad, onError, }: BlindAgentsWidgetProps): react_jsx_runtime.JSX.Element;
59
+ declare function BlindAgents({ apiKey, userWhatsapp, cdnBase, strategy, children, }: BlindAgentsProps): react_jsx_runtime.JSX.Element;
60
+ declare namespace BlindAgents {
61
+ var Report: ({ primaryColor, title, reportBtnText, btnEmoji, btnTooltip, emptyText, userWhatsapp: localWhatsapp, cdnBase: localCdn, strategy: localStrategy, onLoad, onError, }: ReportWidgetProps) => react_jsx_runtime.JSX.Element;
62
+ var Chat: ({ agentId, primaryColor, userWhatsapp: localWhatsapp, cdnBase: localCdn, strategy: localStrategy, onLoad, onError, }: ChatWidgetProps) => react_jsx_runtime.JSX.Element;
63
+ var Guide: ({ userWhatsapp: localWhatsapp, cdnBase: localCdn, strategy: localStrategy, onLoad, onError, }: GuideWidgetProps) => react_jsx_runtime.JSX.Element;
64
+ }
65
+ /** @deprecated Use <BlindAgents><BlindAgents.Report /></BlindAgents> */
66
+ declare function BlindAgentsWidget(props: ReportWidgetProps & {
67
+ apiKey: string;
68
+ }): react_jsx_runtime.JSX.Element;
31
69
 
32
- export { BlindAgentsWidget, type BlindAgentsWidgetProps };
70
+ export { BlindAgents, type BlindAgentsProps, BlindAgentsWidget, type BlindAgentsWidgetProps, type ChatWidgetProps, type GuideWidgetProps, type ReportWidgetProps };
package/dist/next.js CHANGED
@@ -30,48 +30,130 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/next.ts
31
31
  var next_exports = {};
32
32
  __export(next_exports, {
33
+ BlindAgents: () => BlindAgents,
33
34
  BlindAgentsWidget: () => BlindAgentsWidget
34
35
  });
35
36
  module.exports = __toCommonJS(next_exports);
36
37
 
37
- // src/NextBlindAgentsWidget.tsx
38
+ // src/NextBlindAgents.tsx
39
+ var import_react2 = __toESM(require("react"));
38
40
  var import_script = __toESM(require("next/script"));
41
+
42
+ // src/context.ts
43
+ var import_react = require("react");
44
+
45
+ // src/types.ts
46
+ var CDN_BASE = "https://cdn.blindagents.com";
47
+
48
+ // src/context.ts
49
+ var BlindAgentsContext = (0, import_react.createContext)({
50
+ apiKey: "",
51
+ cdnBase: CDN_BASE,
52
+ strategy: "afterInteractive"
53
+ });
54
+
55
+ // src/NextBlindAgents.tsx
39
56
  var import_jsx_runtime = require("react/jsx-runtime");
40
- var CDN_DEFAULT = "https://cdn.blindagents.com/report.js";
41
- function BlindAgentsWidget({
42
- apiKey,
57
+ function Report({
43
58
  primaryColor,
44
59
  title,
45
60
  reportBtnText,
46
61
  btnEmoji,
47
62
  btnTooltip,
48
63
  emptyText,
49
- userWhatsapp,
50
- strategy = "afterInteractive",
51
- src = CDN_DEFAULT,
64
+ userWhatsapp: localWhatsapp,
65
+ cdnBase: localCdn,
66
+ strategy: localStrategy,
52
67
  onLoad,
53
68
  onError
54
69
  }) {
70
+ const ctx = import_react2.default.useContext(BlindAgentsContext);
71
+ const src = `${localCdn ?? ctx.cdnBase}/report.js`;
72
+ const wa = localWhatsapp ?? ctx.userWhatsapp ?? "";
55
73
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
56
74
  import_script.default,
57
75
  {
58
76
  src,
59
- strategy,
60
- "data-api-key": apiKey,
77
+ strategy: localStrategy ?? ctx.strategy,
78
+ "data-api-key": ctx.apiKey,
61
79
  "data-primary-color": primaryColor,
62
80
  "data-title": title,
63
81
  "data-report-btn-text": reportBtnText,
64
82
  "data-btn-emoji": btnEmoji,
65
83
  "data-btn-tooltip": btnTooltip,
66
84
  "data-empty-text": emptyText,
67
- "data-user-whatsapp": userWhatsapp ?? "",
85
+ "data-user-whatsapp": wa,
86
+ onLoad,
87
+ onError: onError ? () => onError(new Error(`Failed to load ${src}`)) : void 0
88
+ }
89
+ );
90
+ }
91
+ function Chat({
92
+ agentId,
93
+ primaryColor,
94
+ userWhatsapp: localWhatsapp,
95
+ cdnBase: localCdn,
96
+ strategy: localStrategy,
97
+ onLoad,
98
+ onError
99
+ }) {
100
+ const ctx = import_react2.default.useContext(BlindAgentsContext);
101
+ const src = `${localCdn ?? ctx.cdnBase}/chat.js`;
102
+ const wa = localWhatsapp ?? ctx.userWhatsapp ?? "";
103
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
104
+ import_script.default,
105
+ {
106
+ src,
107
+ strategy: localStrategy ?? ctx.strategy,
108
+ "data-api-key": ctx.apiKey,
109
+ "data-agent-id": agentId,
110
+ "data-primary-color": primaryColor,
111
+ "data-user-whatsapp": wa,
112
+ onLoad,
113
+ onError: onError ? () => onError(new Error(`Failed to load ${src}`)) : void 0
114
+ }
115
+ );
116
+ }
117
+ function Guide({
118
+ userWhatsapp: localWhatsapp,
119
+ cdnBase: localCdn,
120
+ strategy: localStrategy,
121
+ onLoad,
122
+ onError
123
+ }) {
124
+ const ctx = import_react2.default.useContext(BlindAgentsContext);
125
+ const src = `${localCdn ?? ctx.cdnBase}/guide.js`;
126
+ const wa = localWhatsapp ?? ctx.userWhatsapp ?? "";
127
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
128
+ import_script.default,
129
+ {
130
+ src,
131
+ strategy: localStrategy ?? ctx.strategy,
132
+ "data-api-key": ctx.apiKey,
133
+ "data-user-whatsapp": wa,
68
134
  onLoad,
69
135
  onError: onError ? () => onError(new Error(`Failed to load ${src}`)) : void 0
70
136
  }
71
137
  );
72
138
  }
139
+ function BlindAgents({
140
+ apiKey,
141
+ userWhatsapp,
142
+ cdnBase = CDN_BASE,
143
+ strategy = "afterInteractive",
144
+ children
145
+ }) {
146
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BlindAgentsContext.Provider, { value: { apiKey, userWhatsapp, cdnBase, strategy }, children });
147
+ }
148
+ BlindAgents.Report = Report;
149
+ BlindAgents.Chat = Chat;
150
+ BlindAgents.Guide = Guide;
151
+ function BlindAgentsWidget(props) {
152
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BlindAgents, { apiKey: props.apiKey, userWhatsapp: props.userWhatsapp, strategy: props.strategy, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Report, { ...props }) });
153
+ }
73
154
  // Annotate the CommonJS export names for ESM import in node:
74
155
  0 && (module.exports = {
156
+ BlindAgents,
75
157
  BlindAgentsWidget
76
158
  });
77
159
  //# sourceMappingURL=next.js.map
package/dist/next.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/next.ts","../src/NextBlindAgentsWidget.tsx"],"sourcesContent":["// Next.js entry (App Router + Pages Router)\n// Uses next/script for correct hydration and strategy support.\nexport { BlindAgentsWidget } from './NextBlindAgentsWidget';\nexport type { BlindAgentsWidgetProps } from './types';\n","'use client';\n\n// This file is only included in the `react-blind-agents/next` subpath entry.\n// It relies on `next/script` which is NOT available in plain React apps.\nimport Script from 'next/script';\nimport type { BlindAgentsWidgetProps } from './types';\n\nconst CDN_DEFAULT = 'https://cdn.blindagents.com/report.js';\n\nexport function BlindAgentsWidget({\n apiKey,\n primaryColor,\n title,\n reportBtnText,\n btnEmoji,\n btnTooltip,\n emptyText,\n userWhatsapp,\n strategy = 'afterInteractive',\n src = CDN_DEFAULT,\n onLoad,\n onError,\n}: BlindAgentsWidgetProps) {\n return (\n <Script\n src={src}\n strategy={strategy}\n data-api-key={apiKey}\n data-primary-color={primaryColor}\n data-title={title}\n data-report-btn-text={reportBtnText}\n data-btn-emoji={btnEmoji}\n data-btn-tooltip={btnTooltip}\n data-empty-text={emptyText}\n data-user-whatsapp={userWhatsapp ?? ''}\n onLoad={onLoad}\n onError={onError ? () => onError(new Error(`Failed to load ${src}`)) : undefined}\n />\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIA,oBAAmB;AAoBf;AAjBJ,IAAM,cAAc;AAEb,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX,MAAM;AAAA,EACN;AAAA,EACA;AACF,GAA2B;AACzB,SACE;AAAA,IAAC,cAAAA;AAAA,IAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA,gBAAc;AAAA,MACd,sBAAoB;AAAA,MACpB,cAAY;AAAA,MACZ,wBAAsB;AAAA,MACtB,kBAAgB;AAAA,MAChB,oBAAkB;AAAA,MAClB,mBAAiB;AAAA,MACjB,sBAAoB,gBAAgB;AAAA,MACpC;AAAA,MACA,SAAS,UAAU,MAAM,QAAQ,IAAI,MAAM,kBAAkB,GAAG,EAAE,CAAC,IAAI;AAAA;AAAA,EACzE;AAEJ;","names":["Script"]}
1
+ {"version":3,"sources":["../src/next.ts","../src/NextBlindAgents.tsx","../src/context.ts","../src/types.ts"],"sourcesContent":["// Next.js entry (App Router + Pages Router)\n// Uses next/script for correct hydration and strategy support.\nexport { BlindAgents, BlindAgentsWidget } from './NextBlindAgents';\nexport type {\n BlindAgentsProps,\n ReportWidgetProps,\n ChatWidgetProps,\n GuideWidgetProps,\n BlindAgentsWidgetProps,\n} from './types';\n","'use client';\n\n// Next.js subpath entry uses next/script for correct strategy & hydration.\nimport React from 'react';\nimport Script from 'next/script';\nimport { BlindAgentsContext } from './context';\nimport type {\n BlindAgentsProps,\n ReportWidgetProps,\n ChatWidgetProps,\n GuideWidgetProps,\n} from './types';\nimport { CDN_BASE } from './types';\n\n// ── Widget sub-components ─────────────────────────────────────────────────────\n\nfunction Report({\n primaryColor,\n title,\n reportBtnText,\n btnEmoji,\n btnTooltip,\n emptyText,\n userWhatsapp: localWhatsapp,\n cdnBase: localCdn,\n strategy: localStrategy,\n onLoad,\n onError,\n}: ReportWidgetProps) {\n const ctx = React.useContext(BlindAgentsContext);\n const src = `${localCdn ?? ctx.cdnBase}/report.js`;\n const wa = localWhatsapp ?? ctx.userWhatsapp ?? '';\n\n return (\n <Script\n src={src}\n strategy={localStrategy ?? ctx.strategy}\n data-api-key={ctx.apiKey}\n data-primary-color={primaryColor}\n data-title={title}\n data-report-btn-text={reportBtnText}\n data-btn-emoji={btnEmoji}\n data-btn-tooltip={btnTooltip}\n data-empty-text={emptyText}\n data-user-whatsapp={wa}\n onLoad={onLoad}\n onError={onError ? () => onError(new Error(`Failed to load ${src}`)) : undefined}\n />\n );\n}\n\nfunction Chat({\n agentId,\n primaryColor,\n userWhatsapp: localWhatsapp,\n cdnBase: localCdn,\n strategy: localStrategy,\n onLoad,\n onError,\n}: ChatWidgetProps) {\n const ctx = React.useContext(BlindAgentsContext);\n const src = `${localCdn ?? ctx.cdnBase}/chat.js`;\n const wa = localWhatsapp ?? ctx.userWhatsapp ?? '';\n\n return (\n <Script\n src={src}\n strategy={localStrategy ?? ctx.strategy}\n data-api-key={ctx.apiKey}\n data-agent-id={agentId}\n data-primary-color={primaryColor}\n data-user-whatsapp={wa}\n onLoad={onLoad}\n onError={onError ? () => onError(new Error(`Failed to load ${src}`)) : undefined}\n />\n );\n}\n\nfunction Guide({\n userWhatsapp: localWhatsapp,\n cdnBase: localCdn,\n strategy: localStrategy,\n onLoad,\n onError,\n}: GuideWidgetProps) {\n const ctx = React.useContext(BlindAgentsContext);\n const src = `${localCdn ?? ctx.cdnBase}/guide.js`;\n const wa = localWhatsapp ?? ctx.userWhatsapp ?? '';\n\n return (\n <Script\n src={src}\n strategy={localStrategy ?? ctx.strategy}\n data-api-key={ctx.apiKey}\n data-user-whatsapp={wa}\n onLoad={onLoad}\n onError={onError ? () => onError(new Error(`Failed to load ${src}`)) : undefined}\n />\n );\n}\n\n// ── Root provider ─────────────────────────────────────────────────────────────\n\nexport function BlindAgents({\n apiKey,\n userWhatsapp,\n cdnBase = CDN_BASE,\n strategy = 'afterInteractive',\n children,\n}: BlindAgentsProps) {\n return (\n <BlindAgentsContext.Provider value={{ apiKey, userWhatsapp, cdnBase, strategy }}>\n {children}\n </BlindAgentsContext.Provider>\n );\n}\n\nBlindAgents.Report = Report;\nBlindAgents.Chat = Chat;\nBlindAgents.Guide = Guide;\n\n// ── Legacy single-widget export (backwards compat) ───────────────────────────\n/** @deprecated Use <BlindAgents><BlindAgents.Report /></BlindAgents> */\nexport function BlindAgentsWidget(props: ReportWidgetProps & { apiKey: string }) {\n return (\n <BlindAgents apiKey={props.apiKey} userWhatsapp={props.userWhatsapp} strategy={props.strategy}>\n <Report {...props} />\n </BlindAgents>\n );\n}\n","import { createContext, useContext } from 'react';\nimport { CDN_BASE } from './types';\n\nexport interface BlindAgentsContextValue {\n apiKey: string;\n userWhatsapp?: string;\n cdnBase: string;\n strategy: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';\n}\n\nexport const BlindAgentsContext = createContext<BlindAgentsContextValue>({\n apiKey: '',\n cdnBase: CDN_BASE,\n strategy: 'afterInteractive',\n});\n\nexport function useBlindAgents(): BlindAgentsContextValue {\n return useContext(BlindAgentsContext);\n}\n","const CDN_BASE = 'https://cdn.blindagents.com';\n\nexport { CDN_BASE };\n\n/** Common props shared by all widget types. */\nexport interface BaseWidgetProps {\n /** Your Blind Agents public API key (ba_...) */\n apiKey: string;\n /** Pre-filled WhatsApp number to skip identity verification */\n userWhatsapp?: string;\n /** Override the CDN base URL (useful for self-hosting) */\n cdnBase?: string;\n /** Script loading strategy @default \"afterInteractive\" */\n strategy?: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';\n /** Called once the script finishes loading */\n onLoad?: () => void;\n /** Called if the script fails to load */\n onError?: (error: Error) => void;\n}\n\n/** Report / bug-reporter widget */\nexport interface ReportWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {\n /** Accent color for the widget UI — any valid CSS color */\n primaryColor?: string;\n /** Title displayed in the widget panel header @default \"Help Center\" */\n title?: string;\n /** Label for the report button @default \"Report an issue\" */\n reportBtnText?: string;\n /** Emoji on the launcher floating button @default \"🐛\" */\n btnEmoji?: string;\n /** Tooltip on the launcher button */\n btnTooltip?: string;\n /** Text shown when there are no reports @default \"No issues reported yet.\" */\n emptyText?: string;\n}\n\n/** Webchat widget */\nexport interface ChatWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {\n /** The agent UUID to connect this chat to */\n agentId?: string;\n /** Accent color for the chat bubble and header */\n primaryColor?: string;\n}\n\n/** Product guides widget */\nexport interface GuideWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {\n // No additional props yet — the guide SDK reads config from the dashboard\n}\n\n/** Root provider props — all children share this apiKey */\nexport interface BlindAgentsProps extends BaseWidgetProps {\n children: React.ReactNode;\n}\n\n// ── Legacy single-widget props (kept for backwards compatibility) ──────────────\n/** @deprecated Use <BlindAgents apiKey=\"...\"><BlindAgents.Report /></BlindAgents> instead */\nexport interface BlindAgentsWidgetProps extends BaseWidgetProps {\n primaryColor?: string;\n title?: string;\n reportBtnText?: string;\n btnEmoji?: string;\n btnTooltip?: string;\n emptyText?: string;\n /** @deprecated Prefer userWhatsapp */\n src?: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,IAAAA,gBAAkB;AAClB,oBAAmB;;;ACJnB,mBAA0C;;;ACA1C,IAAM,WAAW;;;ADUV,IAAM,yBAAqB,4BAAuC;AAAA,EACvE,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,UAAU;AACZ,CAAC;;;ADoBG;AAlBJ,SAAS,OAAO;A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,EACd,SAAS;AAAA,EACT,UAAU;AAAA,EACV;AAAA,EACA;AACF,GAAqB;AACnB,QAAM,MAAM,cAAAD,QAAM,WAAW,kBAAkB;AAC/C,QAAM,MAAM,GAAG,YAAY,IAAI,OAAO;AACtC,QAAM,KAAM,iBAAiB,IAAI,gBAAgB;AAEjD,SACE;AAAA,IAAC,cAAAC;AAAA,IAAA;AAAA,MACC;AAAA,MACA,UAAU,iBAAiB,IAAI;AAAA,MAC/B,gBAAc,IAAI;AAAA,MAClB,sBAAoB;AAAA,MACpB;AAAA,MACA,SAAS,UAAU,MAAM,QAAQ,IAAI,MAAM,kBAAkB,GAAG,EAAE,CAAC,IAAI;AAAA;AAAA,EACzE;AAEJ;AAIO,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV,WAAW;AAAA,EACX;AACF,GAAqB;AACnB,SACE,4CAAC,mBAAmB,UAAnB,EAA4B,OAAO,EAAE,QAAQ,cAAc,SAAS,SAAS,GAC3E,UACH;AAEJ;AAEA,YAAY,SAAS;AACrB,YAAY,OAAS;AACrB,YAAY,QAAS;AAId,SAAS,kBAAkB,OAA+C;AAC/E,SACE,4CAAC,eAAY,QAAQ,MAAM,QAAQ,cAAc,MAAM,cAAc,UAAU,MAAM,UACnF,sDAAC,UAAQ,GAAG,OAAO,GACrB;AAEJ;","names":["import_react","React","Script"]}
package/dist/next.mjs CHANGED
@@ -1,40 +1,121 @@
1
- // src/NextBlindAgentsWidget.tsx
1
+ // src/NextBlindAgents.tsx
2
+ import React from "react";
2
3
  import Script from "next/script";
4
+
5
+ // src/context.ts
6
+ import { createContext, useContext } from "react";
7
+
8
+ // src/types.ts
9
+ var CDN_BASE = "https://cdn.blindagents.com";
10
+
11
+ // src/context.ts
12
+ var BlindAgentsContext = createContext({
13
+ apiKey: "",
14
+ cdnBase: CDN_BASE,
15
+ strategy: "afterInteractive"
16
+ });
17
+
18
+ // src/NextBlindAgents.tsx
3
19
  import { jsx } from "react/jsx-runtime";
4
- var CDN_DEFAULT = "https://cdn.blindagents.com/report.js";
5
- function BlindAgentsWidget({
6
- apiKey,
20
+ function Report({
7
21
  primaryColor,
8
22
  title,
9
23
  reportBtnText,
10
24
  btnEmoji,
11
25
  btnTooltip,
12
26
  emptyText,
13
- userWhatsapp,
14
- strategy = "afterInteractive",
15
- src = CDN_DEFAULT,
27
+ userWhatsapp: localWhatsapp,
28
+ cdnBase: localCdn,
29
+ strategy: localStrategy,
16
30
  onLoad,
17
31
  onError
18
32
  }) {
33
+ const ctx = React.useContext(BlindAgentsContext);
34
+ const src = `${localCdn ?? ctx.cdnBase}/report.js`;
35
+ const wa = localWhatsapp ?? ctx.userWhatsapp ?? "";
19
36
  return /* @__PURE__ */ jsx(
20
37
  Script,
21
38
  {
22
39
  src,
23
- strategy,
24
- "data-api-key": apiKey,
40
+ strategy: localStrategy ?? ctx.strategy,
41
+ "data-api-key": ctx.apiKey,
25
42
  "data-primary-color": primaryColor,
26
43
  "data-title": title,
27
44
  "data-report-btn-text": reportBtnText,
28
45
  "data-btn-emoji": btnEmoji,
29
46
  "data-btn-tooltip": btnTooltip,
30
47
  "data-empty-text": emptyText,
31
- "data-user-whatsapp": userWhatsapp ?? "",
48
+ "data-user-whatsapp": wa,
49
+ onLoad,
50
+ onError: onError ? () => onError(new Error(`Failed to load ${src}`)) : void 0
51
+ }
52
+ );
53
+ }
54
+ function Chat({
55
+ agentId,
56
+ primaryColor,
57
+ userWhatsapp: localWhatsapp,
58
+ cdnBase: localCdn,
59
+ strategy: localStrategy,
60
+ onLoad,
61
+ onError
62
+ }) {
63
+ const ctx = React.useContext(BlindAgentsContext);
64
+ const src = `${localCdn ?? ctx.cdnBase}/chat.js`;
65
+ const wa = localWhatsapp ?? ctx.userWhatsapp ?? "";
66
+ return /* @__PURE__ */ jsx(
67
+ Script,
68
+ {
69
+ src,
70
+ strategy: localStrategy ?? ctx.strategy,
71
+ "data-api-key": ctx.apiKey,
72
+ "data-agent-id": agentId,
73
+ "data-primary-color": primaryColor,
74
+ "data-user-whatsapp": wa,
32
75
  onLoad,
33
76
  onError: onError ? () => onError(new Error(`Failed to load ${src}`)) : void 0
34
77
  }
35
78
  );
36
79
  }
80
+ function Guide({
81
+ userWhatsapp: localWhatsapp,
82
+ cdnBase: localCdn,
83
+ strategy: localStrategy,
84
+ onLoad,
85
+ onError
86
+ }) {
87
+ const ctx = React.useContext(BlindAgentsContext);
88
+ const src = `${localCdn ?? ctx.cdnBase}/guide.js`;
89
+ const wa = localWhatsapp ?? ctx.userWhatsapp ?? "";
90
+ return /* @__PURE__ */ jsx(
91
+ Script,
92
+ {
93
+ src,
94
+ strategy: localStrategy ?? ctx.strategy,
95
+ "data-api-key": ctx.apiKey,
96
+ "data-user-whatsapp": wa,
97
+ onLoad,
98
+ onError: onError ? () => onError(new Error(`Failed to load ${src}`)) : void 0
99
+ }
100
+ );
101
+ }
102
+ function BlindAgents({
103
+ apiKey,
104
+ userWhatsapp,
105
+ cdnBase = CDN_BASE,
106
+ strategy = "afterInteractive",
107
+ children
108
+ }) {
109
+ return /* @__PURE__ */ jsx(BlindAgentsContext.Provider, { value: { apiKey, userWhatsapp, cdnBase, strategy }, children });
110
+ }
111
+ BlindAgents.Report = Report;
112
+ BlindAgents.Chat = Chat;
113
+ BlindAgents.Guide = Guide;
114
+ function BlindAgentsWidget(props) {
115
+ return /* @__PURE__ */ jsx(BlindAgents, { apiKey: props.apiKey, userWhatsapp: props.userWhatsapp, strategy: props.strategy, children: /* @__PURE__ */ jsx(Report, { ...props }) });
116
+ }
37
117
  export {
118
+ BlindAgents,
38
119
  BlindAgentsWidget
39
120
  };
40
121
  //# sourceMappingURL=next.mjs.map
package/dist/next.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/NextBlindAgentsWidget.tsx"],"sourcesContent":["'use client';\n\n// This file is only included in the `react-blind-agents/next` subpath entry.\n// It relies on `next/script` which is NOT available in plain React apps.\nimport Script from 'next/script';\nimport type { BlindAgentsWidgetProps } from './types';\n\nconst CDN_DEFAULT = 'https://cdn.blindagents.com/report.js';\n\nexport function BlindAgentsWidget({\n apiKey,\n primaryColor,\n title,\n reportBtnText,\n btnEmoji,\n btnTooltip,\n emptyText,\n userWhatsapp,\n strategy = 'afterInteractive',\n src = CDN_DEFAULT,\n onLoad,\n onError,\n}: BlindAgentsWidgetProps) {\n return (\n <Script\n src={src}\n strategy={strategy}\n data-api-key={apiKey}\n data-primary-color={primaryColor}\n data-title={title}\n data-report-btn-text={reportBtnText}\n data-btn-emoji={btnEmoji}\n data-btn-tooltip={btnTooltip}\n data-empty-text={emptyText}\n data-user-whatsapp={userWhatsapp ?? ''}\n onLoad={onLoad}\n onError={onError ? () => onError(new Error(`Failed to load ${src}`)) : undefined}\n />\n );\n}\n"],"mappings":";AAIA,OAAO,YAAY;AAoBf;AAjBJ,IAAM,cAAc;AAEb,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX,MAAM;AAAA,EACN;AAAA,EACA;AACF,GAA2B;AACzB,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA,gBAAc;AAAA,MACd,sBAAoB;AAAA,MACpB,cAAY;AAAA,MACZ,wBAAsB;AAAA,MACtB,kBAAgB;AAAA,MAChB,oBAAkB;AAAA,MAClB,mBAAiB;AAAA,MACjB,sBAAoB,gBAAgB;AAAA,MACpC;AAAA,MACA,SAAS,UAAU,MAAM,QAAQ,IAAI,MAAM,kBAAkB,GAAG,EAAE,CAAC,IAAI;AAAA;AAAA,EACzE;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../src/NextBlindAgents.tsx","../src/context.ts","../src/types.ts"],"sourcesContent":["'use client';\n\n// Next.js subpath entry uses next/script for correct strategy & hydration.\nimport React from 'react';\nimport Script from 'next/script';\nimport { BlindAgentsContext } from './context';\nimport type {\n BlindAgentsProps,\n ReportWidgetProps,\n ChatWidgetProps,\n GuideWidgetProps,\n} from './types';\nimport { CDN_BASE } from './types';\n\n// ── Widget sub-components ─────────────────────────────────────────────────────\n\nfunction Report({\n primaryColor,\n title,\n reportBtnText,\n btnEmoji,\n btnTooltip,\n emptyText,\n userWhatsapp: localWhatsapp,\n cdnBase: localCdn,\n strategy: localStrategy,\n onLoad,\n onError,\n}: ReportWidgetProps) {\n const ctx = React.useContext(BlindAgentsContext);\n const src = `${localCdn ?? ctx.cdnBase}/report.js`;\n const wa = localWhatsapp ?? ctx.userWhatsapp ?? '';\n\n return (\n <Script\n src={src}\n strategy={localStrategy ?? ctx.strategy}\n data-api-key={ctx.apiKey}\n data-primary-color={primaryColor}\n data-title={title}\n data-report-btn-text={reportBtnText}\n data-btn-emoji={btnEmoji}\n data-btn-tooltip={btnTooltip}\n data-empty-text={emptyText}\n data-user-whatsapp={wa}\n onLoad={onLoad}\n onError={onError ? () => onError(new Error(`Failed to load ${src}`)) : undefined}\n />\n );\n}\n\nfunction Chat({\n agentId,\n primaryColor,\n userWhatsapp: localWhatsapp,\n cdnBase: localCdn,\n strategy: localStrategy,\n onLoad,\n onError,\n}: ChatWidgetProps) {\n const ctx = React.useContext(BlindAgentsContext);\n const src = `${localCdn ?? ctx.cdnBase}/chat.js`;\n const wa = localWhatsapp ?? ctx.userWhatsapp ?? '';\n\n return (\n <Script\n src={src}\n strategy={localStrategy ?? ctx.strategy}\n data-api-key={ctx.apiKey}\n data-agent-id={agentId}\n data-primary-color={primaryColor}\n data-user-whatsapp={wa}\n onLoad={onLoad}\n onError={onError ? () => onError(new Error(`Failed to load ${src}`)) : undefined}\n />\n );\n}\n\nfunction Guide({\n userWhatsapp: localWhatsapp,\n cdnBase: localCdn,\n strategy: localStrategy,\n onLoad,\n onError,\n}: GuideWidgetProps) {\n const ctx = React.useContext(BlindAgentsContext);\n const src = `${localCdn ?? ctx.cdnBase}/guide.js`;\n const wa = localWhatsapp ?? ctx.userWhatsapp ?? '';\n\n return (\n <Script\n src={src}\n strategy={localStrategy ?? ctx.strategy}\n data-api-key={ctx.apiKey}\n data-user-whatsapp={wa}\n onLoad={onLoad}\n onError={onError ? () => onError(new Error(`Failed to load ${src}`)) : undefined}\n />\n );\n}\n\n// ── Root provider ─────────────────────────────────────────────────────────────\n\nexport function BlindAgents({\n apiKey,\n userWhatsapp,\n cdnBase = CDN_BASE,\n strategy = 'afterInteractive',\n children,\n}: BlindAgentsProps) {\n return (\n <BlindAgentsContext.Provider value={{ apiKey, userWhatsapp, cdnBase, strategy }}>\n {children}\n </BlindAgentsContext.Provider>\n );\n}\n\nBlindAgents.Report = Report;\nBlindAgents.Chat = Chat;\nBlindAgents.Guide = Guide;\n\n// ── Legacy single-widget export (backwards compat) ───────────────────────────\n/** @deprecated Use <BlindAgents><BlindAgents.Report /></BlindAgents> */\nexport function BlindAgentsWidget(props: ReportWidgetProps & { apiKey: string }) {\n return (\n <BlindAgents apiKey={props.apiKey} userWhatsapp={props.userWhatsapp} strategy={props.strategy}>\n <Report {...props} />\n </BlindAgents>\n );\n}\n","import { createContext, useContext } from 'react';\nimport { CDN_BASE } from './types';\n\nexport interface BlindAgentsContextValue {\n apiKey: string;\n userWhatsapp?: string;\n cdnBase: string;\n strategy: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';\n}\n\nexport const BlindAgentsContext = createContext<BlindAgentsContextValue>({\n apiKey: '',\n cdnBase: CDN_BASE,\n strategy: 'afterInteractive',\n});\n\nexport function useBlindAgents(): BlindAgentsContextValue {\n return useContext(BlindAgentsContext);\n}\n","const CDN_BASE = 'https://cdn.blindagents.com';\n\nexport { CDN_BASE };\n\n/** Common props shared by all widget types. */\nexport interface BaseWidgetProps {\n /** Your Blind Agents public API key (ba_...) */\n apiKey: string;\n /** Pre-filled WhatsApp number to skip identity verification */\n userWhatsapp?: string;\n /** Override the CDN base URL (useful for self-hosting) */\n cdnBase?: string;\n /** Script loading strategy @default \"afterInteractive\" */\n strategy?: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive';\n /** Called once the script finishes loading */\n onLoad?: () => void;\n /** Called if the script fails to load */\n onError?: (error: Error) => void;\n}\n\n/** Report / bug-reporter widget */\nexport interface ReportWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {\n /** Accent color for the widget UI — any valid CSS color */\n primaryColor?: string;\n /** Title displayed in the widget panel header @default \"Help Center\" */\n title?: string;\n /** Label for the report button @default \"Report an issue\" */\n reportBtnText?: string;\n /** Emoji on the launcher floating button @default \"🐛\" */\n btnEmoji?: string;\n /** Tooltip on the launcher button */\n btnTooltip?: string;\n /** Text shown when there are no reports @default \"No issues reported yet.\" */\n emptyText?: string;\n}\n\n/** Webchat widget */\nexport interface ChatWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {\n /** The agent UUID to connect this chat to */\n agentId?: string;\n /** Accent color for the chat bubble and header */\n primaryColor?: string;\n}\n\n/** Product guides widget */\nexport interface GuideWidgetProps extends Omit<BaseWidgetProps, 'apiKey'> {\n // No additional props yet — the guide SDK reads config from the dashboard\n}\n\n/** Root provider props — all children share this apiKey */\nexport interface BlindAgentsProps extends BaseWidgetProps {\n children: React.ReactNode;\n}\n\n// ── Legacy single-widget props (kept for backwards compatibility) ──────────────\n/** @deprecated Use <BlindAgents apiKey=\"...\"><BlindAgents.Report /></BlindAgents> instead */\nexport interface BlindAgentsWidgetProps extends BaseWidgetProps {\n primaryColor?: string;\n title?: string;\n reportBtnText?: string;\n btnEmoji?: string;\n btnTooltip?: string;\n emptyText?: string;\n /** @deprecated Prefer userWhatsapp */\n src?: string;\n}\n"],"mappings":";AAGA,OAAO,WAAW;AAClB,OAAO,YAAY;;;ACJnB,SAAS,eAAe,kBAAkB;;;ACA1C,IAAM,WAAW;;;ADUV,IAAM,qBAAqB,cAAuC;AAAA,EACvE,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,UAAU;AACZ,CAAC;;;ADoBG;AAlBJ,SAAS,OAAO;AAAA,EACd;AAAA,EACA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B;AACnB,QAAM,MAAM,MAAM,WAAW,kBAAkB;AAC/C,QAAM,MAAM,GAAG,YAAY,IAAI,OAAO;AACtC,QAAM,KAAM,iBAAiB,IAAI,gBAAgB;AAEjD,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,UAAU,iBAAiB,IAAI;AAAA,MAC/B,gBAAc,IAAI;AAAA,MAClB,sBAAoB;AAAA,MACpB;AAAA,MACA,SAAS,UAAU,MAAM,QAAQ,IAAI,MAAM,kBAAkB,GAAG,EAAE,CAAC,IAAI;AAAA;AAAA,EACzE;AAEJ;AAIO,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV,WAAW;AAAA,EACX;AACF,GAAqB;AACnB,SACE,oBAAC,mBAAmB,UAAnB,EAA4B,OAAO,EAAE,QAAQ,cAAc,SAAS,SAAS,GAC3E,UACH;AAEJ;AAEA,YAAY,SAAS;AACrB,YAAY,OAAS;AACrB,YAAY,QAAS;AAId,SAAS,kBAAkB,OAA+C;AAC/E,SACE,oBAAC,eAAY,QAAQ,MAAM,QAAQ,cAAc,MAAM,cAAc,UAAU,MAAM,UACnF,8BAAC,UAAQ,GAAG,OAAO,GACrB;AAEJ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duvandroid/react-blind-agents",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "React component for the Blind Agents pixel widget — bug reporter, webchat, and product guides.",
5
5
  "author": "Blind Agents <hola@blindagents.com>",
6
6
  "license": "MIT",