@marketrix.ai/widget 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -30,9 +30,11 @@ Add the widget to your HTML page using a script tag:
|
|
|
30
30
|
|
|
31
31
|
```html
|
|
32
32
|
<script
|
|
33
|
-
src="path/to/
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
src="path/to/index.mjs"
|
|
34
|
+
mtx-ai-host="https://agent.marketrix.ai"
|
|
35
|
+
mtx-api-host="https://api.marketrix.ai"
|
|
36
|
+
mtx-id="your-marketrix-id"
|
|
37
|
+
mtx-key="your-marketrix-key"
|
|
36
38
|
></script>
|
|
37
39
|
```
|
|
38
40
|
|
|
@@ -42,13 +44,11 @@ You can customize the widget using data attributes:
|
|
|
42
44
|
|
|
43
45
|
```html
|
|
44
46
|
<script
|
|
45
|
-
src="path/to/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
data-agent-name="Support Agent"
|
|
51
|
-
data-api-base-url="https://api.marketrix.com"
|
|
47
|
+
src="path/to/index.mjs"
|
|
48
|
+
mtx-ai-host="https://agent.marketrix.ai"
|
|
49
|
+
mtx-api-host="https://api.marketrix.ai"
|
|
50
|
+
mtx-id="your-marketrix-id"
|
|
51
|
+
mtx-key="your-marketrix-key"
|
|
52
52
|
></script>
|
|
53
53
|
```
|
|
54
54
|
|
|
@@ -229,9 +229,11 @@ npx serve dist -l 5174 --cors
|
|
|
229
229
|
```javascript
|
|
230
230
|
javascript: (function () {
|
|
231
231
|
var s = document.createElement('script');
|
|
232
|
-
s.src = 'http://localhost:5174/
|
|
233
|
-
s.setAttribute('
|
|
234
|
-
s.setAttribute('
|
|
232
|
+
s.src = 'http://localhost:5174/index.mjs';
|
|
233
|
+
s.setAttribute('mtx-ai-host', 'https://agent.marketrix.ai');
|
|
234
|
+
s.setAttribute('mtx-api-host', 'https://api.marketrix.ai');
|
|
235
|
+
s.setAttribute('mtx-app', 'YOUR_APP_ID');
|
|
236
|
+
s.setAttribute('mtx-agent', 'YOUR_AGENT_ID');
|
|
235
237
|
document.head.appendChild(s);
|
|
236
238
|
})();
|
|
237
239
|
```
|
|
@@ -247,9 +249,11 @@ First visit `https://localhost:5174` and accept the certificate, then use:
|
|
|
247
249
|
```javascript
|
|
248
250
|
javascript: (function () {
|
|
249
251
|
var s = document.createElement('script');
|
|
250
|
-
s.src = 'https://localhost:5174/
|
|
251
|
-
s.setAttribute('
|
|
252
|
-
s.setAttribute('
|
|
252
|
+
s.src = 'https://localhost:5174/index.mjs';
|
|
253
|
+
s.setAttribute('mtx-ai-host', 'https://agent.marketrix.ai');
|
|
254
|
+
s.setAttribute('mtx-api-host', 'https://api.marketrix.ai');
|
|
255
|
+
s.setAttribute('mtx-app', 'YOUR_APP_ID');
|
|
256
|
+
s.setAttribute('mtx-agent', 'YOUR_AGENT_ID');
|
|
253
257
|
document.head.appendChild(s);
|
|
254
258
|
})();
|
|
255
259
|
```
|
|
@@ -259,9 +263,11 @@ javascript: (function () {
|
|
|
259
263
|
```javascript
|
|
260
264
|
javascript: (function () {
|
|
261
265
|
var s = document.createElement('script');
|
|
262
|
-
s.src = 'https://cdn.marketrix.io/widget/dev/
|
|
263
|
-
s.setAttribute('
|
|
264
|
-
s.setAttribute('
|
|
266
|
+
s.src = 'https://cdn.marketrix.io/widget/dev/index.mjs';
|
|
267
|
+
s.setAttribute('mtx-ai-host', 'https://agent.marketrix.ai');
|
|
268
|
+
s.setAttribute('mtx-api-host', 'https://api.marketrix.ai');
|
|
269
|
+
s.setAttribute('mtx-app', 'YOUR_APP_ID');
|
|
270
|
+
s.setAttribute('mtx-agent', 'YOUR_AGENT_ID');
|
|
265
271
|
document.head.appendChild(s);
|
|
266
272
|
})();
|
|
267
273
|
```
|
|
@@ -286,12 +292,14 @@ create a new script:
|
|
|
286
292
|
'use strict';
|
|
287
293
|
var script = document.createElement('script');
|
|
288
294
|
// Use one of the following sources:
|
|
289
|
-
// Local dev server (HTTPS): script.src = "https://localhost:5174/
|
|
290
|
-
// Local built version: script.src = "http://localhost:5174/
|
|
295
|
+
// Local dev server (HTTPS): script.src = "https://localhost:5174/index.mjs";
|
|
296
|
+
// Local built version: script.src = "http://localhost:5174/index.mjs";
|
|
291
297
|
// Production CDN:
|
|
292
|
-
script.src = 'https://cdn.marketrix.io/widget/dev/
|
|
293
|
-
|
|
294
|
-
|
|
298
|
+
script.src = 'https://cdn.marketrix.io/widget/dev/index.mjs';
|
|
299
|
+
s.setAttribute('mtx-ai-host', 'https://agent.marketrix.ai');
|
|
300
|
+
s.setAttribute('mtx-api-host', 'https://api.marketrix.ai');
|
|
301
|
+
script.setAttribute('mtx-app', 'YOUR_APP_ID');
|
|
302
|
+
script.setAttribute('mtx-agent', 'YOUR_AGENT_ID');
|
|
295
303
|
document.head.appendChild(script);
|
|
296
304
|
})();
|
|
297
305
|
```
|
|
@@ -352,7 +360,7 @@ widget/
|
|
|
352
360
|
├── vite.config.ts # Vite configuration
|
|
353
361
|
├── tailwind.config.js # Tailwind configuration
|
|
354
362
|
└── dist/ # Build output
|
|
355
|
-
├──
|
|
363
|
+
├── index.mjs # Main widget bundle (IIFE)
|
|
356
364
|
└── index.html # Demo page
|
|
357
365
|
```
|
|
358
366
|
|
|
@@ -363,27 +371,23 @@ The widget uses Vite with a custom CSS injection plugin that:
|
|
|
363
371
|
- Bundles all dependencies (React, etc.) into a single file
|
|
364
372
|
- Injects CSS directly into the JavaScript bundle
|
|
365
373
|
- Outputs an IIFE (Immediately Invoked Function Expression) format
|
|
366
|
-
- Creates a standalone `
|
|
374
|
+
- Creates a standalone `index.mjs` file with no external dependencies
|
|
367
375
|
|
|
368
376
|
## API Reference
|
|
369
377
|
|
|
370
378
|
### Functions
|
|
371
379
|
|
|
372
|
-
#### `
|
|
380
|
+
#### `mountWidget(config: MarketrixConfig)`
|
|
373
381
|
|
|
374
|
-
Initializes the widget
|
|
382
|
+
Initializes the widget and adds it into the DOM.
|
|
375
383
|
|
|
376
|
-
#### `
|
|
384
|
+
#### `unmountWidget()`
|
|
377
385
|
|
|
378
386
|
Destroys the widget and removes it from the DOM.
|
|
379
387
|
|
|
380
|
-
#### `
|
|
388
|
+
#### `previewWidget(config: MarketrixConfig)`
|
|
381
389
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
#### `getCurrentConfig(): MarketrixConfig`
|
|
385
|
-
|
|
386
|
-
Returns the current widget configuration.
|
|
390
|
+
Previews the widget for quick appearance-checking.
|
|
387
391
|
|
|
388
392
|
### Types
|
|
389
393
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatWindow.d.ts","sourceRoot":"","sources":["../../../src/components/chat/ChatWindow.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAG3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAcjD,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQ9E,UAAU,eAAe;IACvB,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,WAAW,EAAE,eAAe,CAAC;IAC7B,cAAc,EAAE,OAAO,CAAC;IACxB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,YAAY,CAAC,EAAE,YAAY,EAAE,CAAC;IAC9B,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,aAAa,EAAE,CACb,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,eAAe,EACtB,YAAY,CAAC,EAAE,MAAM,EACrB,QAAQ,CAAC,EAAE,MAAM,EACjB,eAAe,CAAC,EAAE,OAAO,KACtB,IAAI,CAAC;IACV,SAAS,EAAE,CAAC,IAAI,EAAE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B,QAAQ,CAAC,EAAE,MAAM,EACjB,eAAe,CAAC,EAAE,OAAO,KACtB,IAAI,CAAC;IACV,SAAS,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAC;IAC3C,YAAY,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;IAC7C,eAAe,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;IAC5E,eAAe,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,qBAAqB,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;CACtD;AAED,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CA+tBhD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WidgetButton.d.ts","sourceRoot":"","sources":["../../../src/components/layout/WidgetButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAInD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAInD,UAAU,iBAAiB;IACzB,MAAM,EAAE,eAAe,CAAC;IACxB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,
|
|
1
|
+
{"version":3,"file":"WidgetButton.d.ts","sourceRoot":"","sources":["../../../src/components/layout/WidgetButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAInD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAInD,UAAU,iBAAiB;IACzB,MAAM,EAAE,eAAe,CAAC;IACxB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAwNpD,CAAC"}
|
package/dist/index.mjs
CHANGED
|
@@ -11807,7 +11807,9 @@ const ChatWindow = ({
|
|
|
11807
11807
|
}) => {
|
|
11808
11808
|
const [inputValue, setInputValue] = useState("");
|
|
11809
11809
|
const messagesEndRef = useRef(null);
|
|
11810
|
+
const chatWindowRef = useRef(null);
|
|
11810
11811
|
const [isScreenSharing$1, setIsScreenSharing] = useState(false);
|
|
11812
|
+
const [isPreviewMode, setIsPreviewMode] = useState(false);
|
|
11811
11813
|
const [screenShareMessageId, setScreenShareMessageId] = useState(null);
|
|
11812
11814
|
const [screenAccessRequestMessageId, setScreenAccessRequestMessageId] = useState(
|
|
11813
11815
|
null
|
|
@@ -12014,6 +12016,19 @@ const ChatWindow = ({
|
|
|
12014
12016
|
};
|
|
12015
12017
|
const effectivePosition = widgetPosition.position || settings.widget_position || "bottom_right";
|
|
12016
12018
|
const positionClasses = getPositionClasses(effectivePosition);
|
|
12019
|
+
useEffect(() => {
|
|
12020
|
+
if (chatWindowRef.current) {
|
|
12021
|
+
const rootNode = chatWindowRef.current.getRootNode();
|
|
12022
|
+
if (rootNode instanceof ShadowRoot) {
|
|
12023
|
+
const host = rootNode.host;
|
|
12024
|
+
if (host && host.parentElement && host.parentElement !== document.body) {
|
|
12025
|
+
setIsPreviewMode(true);
|
|
12026
|
+
return;
|
|
12027
|
+
}
|
|
12028
|
+
}
|
|
12029
|
+
setIsPreviewMode(false);
|
|
12030
|
+
}
|
|
12031
|
+
}, []);
|
|
12017
12032
|
if (!isOpen) return null;
|
|
12018
12033
|
const customStyles = {
|
|
12019
12034
|
width: settings.widget_width,
|
|
@@ -12045,10 +12060,12 @@ const ChatWindow = ({
|
|
|
12045
12060
|
return this.props.children;
|
|
12046
12061
|
}
|
|
12047
12062
|
}
|
|
12063
|
+
const positionClass = isPreviewMode ? "absolute" : "fixed";
|
|
12048
12064
|
return /* @__PURE__ */ jsx(
|
|
12049
12065
|
"div",
|
|
12050
12066
|
{
|
|
12051
|
-
|
|
12067
|
+
ref: chatWindowRef,
|
|
12068
|
+
className: `${positionClass} rounded-xl ${positionClasses} pointer-events-auto`,
|
|
12052
12069
|
style: {
|
|
12053
12070
|
zIndex: widgetPosition.z_index || 40,
|
|
12054
12071
|
backgroundColor: "#ffffff",
|
|
@@ -12421,8 +12438,23 @@ const WidgetButton = ({
|
|
|
12421
12438
|
isScreenSharing: isScreenSharing2 = false
|
|
12422
12439
|
}) => {
|
|
12423
12440
|
const [showWelcomeText, setShowWelcomeText] = useState(false);
|
|
12441
|
+
const [isPreviewMode, setIsPreviewMode] = useState(false);
|
|
12442
|
+
const buttonRef = React.useRef(null);
|
|
12424
12443
|
const { getWidgetPosition: getWidgetPosition2, settings } = useWidget({ config });
|
|
12425
12444
|
const widgetPosition = getWidgetPosition2();
|
|
12445
|
+
useEffect(() => {
|
|
12446
|
+
if (buttonRef.current) {
|
|
12447
|
+
const rootNode = buttonRef.current.getRootNode();
|
|
12448
|
+
if (rootNode instanceof ShadowRoot) {
|
|
12449
|
+
const host = rootNode.host;
|
|
12450
|
+
if (host && host.parentElement && host.parentElement !== document.body) {
|
|
12451
|
+
setIsPreviewMode(true);
|
|
12452
|
+
return;
|
|
12453
|
+
}
|
|
12454
|
+
}
|
|
12455
|
+
setIsPreviewMode(false);
|
|
12456
|
+
}
|
|
12457
|
+
}, []);
|
|
12426
12458
|
useEffect(() => {
|
|
12427
12459
|
setShowWelcomeText(false);
|
|
12428
12460
|
if (isMinimized) {
|
|
@@ -12440,10 +12472,12 @@ const WidgetButton = ({
|
|
|
12440
12472
|
}, [settings.widget_appearance, isMinimized]);
|
|
12441
12473
|
const effectivePosition = widgetPosition.position || settings.widget_position || "bottom_right";
|
|
12442
12474
|
const effectivePositionClasses = getPositionClasses(effectivePosition);
|
|
12475
|
+
const positionClass = isPreviewMode ? "absolute" : "fixed";
|
|
12443
12476
|
return /* @__PURE__ */ jsxs(
|
|
12444
12477
|
"div",
|
|
12445
12478
|
{
|
|
12446
|
-
|
|
12479
|
+
ref: buttonRef,
|
|
12480
|
+
className: `${positionClass} ${effectivePositionClasses} transition-transform duration-500 ease-in-out ${showWelcomeText && !isOpen ? effectivePosition.includes("left") ? "transform translate-x-64" : "transform -translate-x-64" : ""}`,
|
|
12447
12481
|
style: { zIndex: widgetPosition.z_index || 50 },
|
|
12448
12482
|
children: [
|
|
12449
12483
|
/* @__PURE__ */ jsx(
|