@getspot/spot-widget-react 0.1.4 → 1.0.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/.turbo/turbo-build.log +4 -4
- package/CHANGELOG.md +26 -0
- package/dist/index.es.js +67 -16
- package/dist/index.umd.js +1 -1
- package/package.json +2 -2
- package/src/ReactSpotWidget.jsx +76 -6
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @getspot/spot-widget-react@0.
|
|
2
|
+
> @getspot/spot-widget-react@1.0.0 build /builds/getspot/spot-widget/packages/react
|
|
3
3
|
> vite build
|
|
4
4
|
|
|
5
5
|
[33mThe CJS build of Vite's Node API is deprecated. See https://vite.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.[39m
|
|
@@ -9,6 +9,6 @@ transforming...
|
|
|
9
9
|
No name was provided for external module "@getspot/spot-widget" in "output.globals" – guessing "SpotWidget".
|
|
10
10
|
rendering chunks...
|
|
11
11
|
computing gzip size...
|
|
12
|
-
[2mdist/[22m[36mindex.umd.js [39m[1m[
|
|
13
|
-
[2mdist/[22m[36mindex.es.js [39m[1m[
|
|
14
|
-
[32m✓ built in
|
|
12
|
+
[2mdist/[22m[36mindex.umd.js [39m[1m[2m1.41 kB[22m[1m[22m[2m │ gzip: 0.65 kB[22m
|
|
13
|
+
[2mdist/[22m[36mindex.es.js [39m[1m[2m1.71 kB[22m[1m[22m[2m │ gzip: 0.68 kB[22m
|
|
14
|
+
[32m✓ built in 115ms[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @getspot/spot-widget-react
|
|
2
2
|
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 4f9e10e: First major release of all the widget variants.
|
|
8
|
+
|
|
9
|
+
This is really a major release for the sake of having our first major bump. The package is now ready for external use.
|
|
10
|
+
|
|
11
|
+
Includes updated functionality for updating quotes.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [4f9e10e]
|
|
16
|
+
- @getspot/spot-widget@1.0.0
|
|
17
|
+
|
|
18
|
+
## 0.2.0
|
|
19
|
+
|
|
20
|
+
### Minor Changes
|
|
21
|
+
|
|
22
|
+
- 25bba43: Making cartId required on quoteRequest
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Updated dependencies [25bba43]
|
|
27
|
+
- @getspot/spot-widget@0.2.0
|
|
28
|
+
|
|
3
29
|
## 0.1.4
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
package/dist/index.es.js
CHANGED
|
@@ -1,19 +1,70 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import z, { forwardRef as A, useRef as x, useImperativeHandle as B, useEffect as E } from "react";
|
|
2
|
+
import F from "@getspot/spot-widget";
|
|
3
|
+
const K = A(({
|
|
4
|
+
apiConfig: m,
|
|
5
|
+
quoteRequestData: y,
|
|
6
|
+
showTable: i = !0,
|
|
7
|
+
optInSelected: W = !1,
|
|
8
|
+
theme: v,
|
|
9
|
+
callbacks: w = {},
|
|
10
|
+
onQuoteRetrieved: s,
|
|
11
|
+
onOptIn: t,
|
|
12
|
+
onOptOut: c,
|
|
13
|
+
onError: f,
|
|
14
|
+
onNoMatchingQuote: d,
|
|
15
|
+
onSelectionChange: e,
|
|
16
|
+
...R
|
|
17
|
+
}, H) => {
|
|
18
|
+
const l = x(null), u = x(null), b = {
|
|
19
|
+
...w,
|
|
20
|
+
...s && { onQuoteRetrieved: s },
|
|
21
|
+
...t && {
|
|
22
|
+
onOptIn: (r) => {
|
|
23
|
+
t == null || t(r), e == null || e(r);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
...c && {
|
|
27
|
+
onOptOut: (r) => {
|
|
28
|
+
c == null || c(r), e == null || e(r);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
...f && { onError: f },
|
|
32
|
+
...d && { onNoMatchingQuote: d }
|
|
33
|
+
}, j = {
|
|
34
|
+
apiConfig: m,
|
|
35
|
+
quoteRequestData: y,
|
|
36
|
+
showTable: i,
|
|
37
|
+
optInSelected: W,
|
|
38
|
+
theme: v,
|
|
39
|
+
callbacks: b,
|
|
40
|
+
...R
|
|
41
|
+
};
|
|
42
|
+
return B(H, () => ({
|
|
43
|
+
updateQuote: (r) => {
|
|
44
|
+
var k;
|
|
45
|
+
return (k = u.current) == null ? void 0 : k.updateQuote(r);
|
|
46
|
+
},
|
|
47
|
+
getSelection: () => {
|
|
48
|
+
var r;
|
|
49
|
+
return (r = u.current) == null ? void 0 : r.getSelection();
|
|
50
|
+
},
|
|
51
|
+
validateSelection: () => {
|
|
52
|
+
var r;
|
|
53
|
+
return (r = u.current) == null ? void 0 : r.validateSelection();
|
|
54
|
+
},
|
|
55
|
+
destroy: () => {
|
|
56
|
+
u.current && (u.current.destroy(), u.current = null);
|
|
14
57
|
}
|
|
15
|
-
},
|
|
16
|
-
|
|
58
|
+
})), E(() => {
|
|
59
|
+
if (l.current)
|
|
60
|
+
return u.current && u.current.destroy(), u.current = new F({
|
|
61
|
+
location: l.current,
|
|
62
|
+
...j
|
|
63
|
+
}), () => {
|
|
64
|
+
u.current && (u.current.destroy(), u.current = null);
|
|
65
|
+
};
|
|
66
|
+
}, [m, y, i, W, v, w, s, t, c, f, d, e, R]), /* @__PURE__ */ z.createElement("div", { ref: l });
|
|
67
|
+
});
|
|
17
68
|
export {
|
|
18
|
-
|
|
69
|
+
K as default
|
|
19
70
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(r,s){typeof exports=="object"&&typeof module<"u"?module.exports=s(require("react"),require("@getspot/spot-widget")):typeof define=="function"&&define.amd?define(["react","@getspot/spot-widget"],s):(r=typeof globalThis<"u"?globalThis:r||self,r.ReactSpotWidget=s(r.React,r.SpotWidget))})(this,function(r,s){"use strict";return r.forwardRef(({apiConfig:y,quoteRequestData:m,showTable:W=!0,optInSelected:w=!1,theme:v,callbacks:x={},onQuoteRetrieved:c,onOptIn:d,onOptOut:f,onError:i,onNoMatchingQuote:l,onSelectionChange:u,...j},H)=>{const p=r.useRef(null),t=r.useRef(null),T={...x,...c&&{onQuoteRetrieved:c},...d&&{onOptIn:e=>{d==null||d(e),u==null||u(e)}},...f&&{onOptOut:e=>{f==null||f(e),u==null||u(e)}},...i&&{onError:i},...l&&{onNoMatchingQuote:l}},q={apiConfig:y,quoteRequestData:m,showTable:W,optInSelected:w,theme:v,callbacks:T,...j};return r.useImperativeHandle(H,()=>({updateQuote:e=>{var k;return(k=t.current)==null?void 0:k.updateQuote(e)},getSelection:()=>{var e;return(e=t.current)==null?void 0:e.getSelection()},validateSelection:()=>{var e;return(e=t.current)==null?void 0:e.validateSelection()},destroy:()=>{t.current&&(t.current.destroy(),t.current=null)}})),r.useEffect(()=>{if(p.current)return t.current&&t.current.destroy(),t.current=new s({location:p.current,...q}),()=>{t.current&&(t.current.destroy(),t.current=null)}},[y,m,W,w,v,x,c,d,f,i,l,u,j]),r.createElement("div",{ref:p})})});
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getspot/spot-widget-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
7
|
"main": "dist/index.umd.js",
|
|
8
8
|
"module": "dist/index.es.js",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@getspot/spot-widget": "0.
|
|
10
|
+
"@getspot/spot-widget": "1.0.0"
|
|
11
11
|
},
|
|
12
12
|
"peerDependencies": {
|
|
13
13
|
"react": "^18.0.0",
|
package/src/ReactSpotWidget.jsx
CHANGED
|
@@ -1,23 +1,93 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from "react";
|
|
1
|
+
import React, { useEffect, useRef, useImperativeHandle, forwardRef } from "react";
|
|
2
2
|
import SpotWidget from "@getspot/spot-widget";
|
|
3
3
|
|
|
4
|
-
const ReactSpotWidget = ({
|
|
4
|
+
const ReactSpotWidget = forwardRef(({
|
|
5
|
+
apiConfig,
|
|
6
|
+
quoteRequestData,
|
|
7
|
+
showTable = true,
|
|
8
|
+
optInSelected = false,
|
|
9
|
+
theme,
|
|
10
|
+
callbacks = {},
|
|
11
|
+
onQuoteRetrieved,
|
|
12
|
+
onOptIn,
|
|
13
|
+
onOptOut,
|
|
14
|
+
onError,
|
|
15
|
+
onNoMatchingQuote,
|
|
16
|
+
onSelectionChange,
|
|
17
|
+
...otherOptions
|
|
18
|
+
}, ref) => {
|
|
5
19
|
const widgetRef = useRef(null);
|
|
20
|
+
const spotWidgetInstance = useRef(null);
|
|
21
|
+
|
|
22
|
+
// Merge callbacks from props with callbacks object
|
|
23
|
+
const mergedCallbacks = {
|
|
24
|
+
...callbacks,
|
|
25
|
+
...(onQuoteRetrieved && { onQuoteRetrieved }),
|
|
26
|
+
...(onOptIn && {
|
|
27
|
+
onOptIn: (data) => {
|
|
28
|
+
onOptIn?.(data);
|
|
29
|
+
onSelectionChange?.(data);
|
|
30
|
+
}
|
|
31
|
+
}),
|
|
32
|
+
...(onOptOut && {
|
|
33
|
+
onOptOut: (data) => {
|
|
34
|
+
onOptOut?.(data);
|
|
35
|
+
onSelectionChange?.(data);
|
|
36
|
+
}
|
|
37
|
+
}),
|
|
38
|
+
...(onError && { onError }),
|
|
39
|
+
...(onNoMatchingQuote && { onNoMatchingQuote }),
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const options = {
|
|
43
|
+
apiConfig,
|
|
44
|
+
quoteRequestData,
|
|
45
|
+
showTable,
|
|
46
|
+
optInSelected,
|
|
47
|
+
theme,
|
|
48
|
+
callbacks: mergedCallbacks,
|
|
49
|
+
...otherOptions,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
useImperativeHandle(ref, () => ({
|
|
53
|
+
updateQuote: (newQuoteRequestData) => {
|
|
54
|
+
return spotWidgetInstance.current?.updateQuote(newQuoteRequestData);
|
|
55
|
+
},
|
|
56
|
+
getSelection: () => {
|
|
57
|
+
return spotWidgetInstance.current?.getSelection();
|
|
58
|
+
},
|
|
59
|
+
validateSelection: () => {
|
|
60
|
+
return spotWidgetInstance.current?.validateSelection();
|
|
61
|
+
},
|
|
62
|
+
destroy: () => {
|
|
63
|
+
if (spotWidgetInstance.current) {
|
|
64
|
+
spotWidgetInstance.current.destroy();
|
|
65
|
+
spotWidgetInstance.current = null;
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
}));
|
|
6
69
|
|
|
7
70
|
useEffect(() => {
|
|
8
71
|
if (widgetRef.current) {
|
|
9
|
-
|
|
72
|
+
if (spotWidgetInstance.current) {
|
|
73
|
+
spotWidgetInstance.current.destroy();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
spotWidgetInstance.current = new SpotWidget({
|
|
10
77
|
location: widgetRef.current,
|
|
11
78
|
...options,
|
|
12
79
|
});
|
|
13
80
|
|
|
14
81
|
return () => {
|
|
15
|
-
|
|
82
|
+
if (spotWidgetInstance.current) {
|
|
83
|
+
spotWidgetInstance.current.destroy();
|
|
84
|
+
spotWidgetInstance.current = null;
|
|
85
|
+
}
|
|
16
86
|
};
|
|
17
87
|
}
|
|
18
|
-
}, [
|
|
88
|
+
}, [apiConfig, quoteRequestData, showTable, optInSelected, theme, callbacks, onQuoteRetrieved, onOptIn, onOptOut, onError, onNoMatchingQuote, onSelectionChange, otherOptions]);
|
|
19
89
|
|
|
20
90
|
return <div ref={widgetRef}></div>;
|
|
21
|
-
};
|
|
91
|
+
});
|
|
22
92
|
|
|
23
93
|
export default ReactSpotWidget;
|