@getspot/spot-widget-react 3.0.1 → 3.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @getspot/spot-widget-react
2
2
 
3
+ ## 3.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 7b695ae: Fix re-rendering issues
8
+
3
9
  ## 3.0.1
4
10
 
5
11
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"ReactSpotWidget.d.ts","sourceRoot":"","sources":["../src/ReactSpotWidget.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6D,MAAM,OAAO,CAAC;AAClF,OAAmB,EAAE,KAAK,iBAAiB,EAAE,KAAK,aAAa,EAAE,KAAK,KAAK,EAAE,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAE7H;;GAEG;AACH,UAAU,oBAAqB,SAAQ,IAAI,CAAC,iBAAiB,EAAE,UAAU,GAAG,WAAW,CAAC;IACtF,0EAA0E;IAC1E,SAAS,EAAE,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAC1C,iEAAiE;IACjE,gBAAgB,EAAE,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;IACxD,yDAAyD;IACzD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,8EAA8E;IAC9E,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,yDAAyD;IACzD,KAAK,CAAC,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACnC,4DAA4D;IAC5D,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,YAAY,GAAG,IAAI,CAAC;IACzD,+DAA+D;IAC/D,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,CAAC;IACxC,gEAAgE;IAChE,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,CAAC;IACzC,iEAAiE;IACjE,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AqC;IACrC,YAAY,EAAE,MAAM,aAAa,GAAG,IAAI,CAAC;IACzC,kDAAkD;IAClD,iBAAiB,EAAE,MAAM,OAAO,CAAC;IACjC,yDAAyD;IACzD,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,QAAA,MAAM,eAAe,iGAuJnB,CAAC;AAIH,eAAe,eAAe,CAAC"}
package/dist/index.es.js CHANGED
@@ -1,72 +1,113 @@
1
- import { jsx as P } from "react/jsx-runtime";
2
- import { forwardRef as b, useRef as R, useImperativeHandle as p, useEffect as z } from "react";
3
- import A from "@getspot/spot-widget";
4
- const B = b(({
5
- apiConfig: m,
6
- quoteRequestData: i,
7
- showTable: y = !0,
8
- optInSelected: W = !1,
1
+ import { jsx as x } from "react/jsx-runtime";
2
+ import { forwardRef as A, useRef as g, useCallback as d, useImperativeHandle as B, useEffect as E } from "react";
3
+ import M from "@getspot/spot-widget";
4
+ function s(c, o) {
5
+ if (c === o) return !0;
6
+ if (c == null || o == null || typeof c != "object" || typeof o != "object") return !1;
7
+ const l = Object.keys(c), i = Object.keys(o);
8
+ if (l.length !== i.length) return !1;
9
+ for (let a of l)
10
+ if (!i.includes(a) || !s(c[a], o[a])) return !1;
11
+ return !0;
12
+ }
13
+ function W(c, o) {
14
+ const l = g(void 0);
15
+ return (!l.current || !s(l.current.deps, o)) && (l.current = { deps: o, value: c() }), l.current.value;
16
+ }
17
+ const H = A(({
18
+ apiConfig: c,
19
+ quoteRequestData: o,
20
+ showTable: l = !0,
21
+ optInSelected: i = !1,
9
22
  theme: a,
10
- callbacks: v = {},
11
- onQuoteRetrieved: c,
12
- onOptIn: s,
13
- onOptOut: t,
14
- onError: f,
15
- onNoMatchingQuote: d,
16
- onSelectionChange: e,
17
- ...w
18
- }, j) => {
19
- const l = R(null), u = R(null), k = {
20
- ...v,
21
- ...c && { onQuoteRetrieved: c },
22
- ...s && {
23
- onOptIn: (r) => {
24
- s == null || s(r), e == null || e(r);
25
- }
26
- },
27
- ...t && {
28
- onOptOut: (r) => {
29
- t == null || t(r), e == null || e(r);
30
- }
31
- },
32
- ...f && { onError: f },
33
- ...d && { noMatchingQuote: d }
34
- }, H = {
35
- apiConfig: m,
36
- quoteRequestData: i,
37
- showTable: y,
38
- optInSelected: W,
39
- theme: a,
40
- callbacks: k,
41
- ...w
23
+ callbacks: m = {},
24
+ onQuoteRetrieved: R,
25
+ onOptIn: b,
26
+ onOptOut: Q,
27
+ onError: h,
28
+ onNoMatchingQuote: k,
29
+ onSelectionChange: S
30
+ }, N) => {
31
+ const O = g(null), r = g(null), u = g({
32
+ onQuoteRetrieved: R,
33
+ onOptIn: b,
34
+ onOptOut: Q,
35
+ onError: h,
36
+ onNoMatchingQuote: k,
37
+ onSelectionChange: S
38
+ });
39
+ u.current = {
40
+ onQuoteRetrieved: R,
41
+ onOptIn: b,
42
+ onOptOut: Q,
43
+ onError: h,
44
+ onNoMatchingQuote: k,
45
+ onSelectionChange: S
42
46
  };
43
- return p(j, () => ({
44
- updateQuote: (r) => {
45
- var x;
46
- return ((x = u.current) == null ? void 0 : x.updateQuote(r)) ?? Promise.resolve(!1);
47
+ const C = d((t) => {
48
+ var e, n;
49
+ return (n = (e = u.current).onQuoteRetrieved) == null ? void 0 : n.call(e, t);
50
+ }, []), I = d((t) => {
51
+ var e, n, f, p;
52
+ (n = (e = u.current).onOptIn) == null || n.call(e, t), (p = (f = u.current).onSelectionChange) == null || p.call(f, t);
53
+ }, []), j = d((t) => {
54
+ var e, n, f, p;
55
+ (n = (e = u.current).onOptOut) == null || n.call(e, t), (p = (f = u.current).onSelectionChange) == null || p.call(f, t);
56
+ }, []), q = d((t) => {
57
+ var e, n;
58
+ (n = (e = u.current).onError) == null || n.call(e, t);
59
+ }, []), w = d((t) => {
60
+ var e, n;
61
+ (n = (e = u.current).onNoMatchingQuote) == null || n.call(e, t);
62
+ }, []), D = W(() => ({
63
+ ...m,
64
+ ...u.current.onQuoteRetrieved && { onQuoteRetrieved: C },
65
+ ...u.current.onOptIn && { onOptIn: I },
66
+ ...u.current.onOptOut && { onOptOut: j },
67
+ ...u.current.onError && { onError: q },
68
+ ...u.current.onNoMatchingQuote && { noMatchingQuote: w }
69
+ }), [m, C, I, j, q, w]), v = W(() => ({
70
+ apiConfig: c,
71
+ quoteRequestData: o,
72
+ showTable: l,
73
+ optInSelected: i,
74
+ theme: a,
75
+ callbacks: D
76
+ }), [c, o, l, i, a, D]);
77
+ B(N, () => ({
78
+ updateQuote: (t) => {
79
+ var e;
80
+ return ((e = r.current) == null ? void 0 : e.updateQuote(t)) ?? Promise.resolve(!1);
47
81
  },
48
82
  getSelection: () => {
49
- var r;
50
- return ((r = u.current) == null ? void 0 : r.getSelection()) ?? null;
83
+ var t;
84
+ return ((t = r.current) == null ? void 0 : t.getSelection()) ?? null;
51
85
  },
52
86
  validateSelection: () => {
53
- var r;
54
- return ((r = u.current) == null ? void 0 : r.validateSelection()) ?? !1;
87
+ var t;
88
+ return ((t = r.current) == null ? void 0 : t.validateSelection()) ?? !1;
55
89
  },
56
90
  destroy: () => {
57
- u.current && (u.current.destroy(), u.current = null);
91
+ r.current && (r.current.destroy(), r.current = null);
92
+ }
93
+ }));
94
+ const y = g(void 0);
95
+ return E(() => (O.current && !r.current && (r.current = new M({
96
+ location: O.current,
97
+ ...v
98
+ }), y.current = v), () => {
99
+ r.current && (r.current.destroy(), r.current = null);
100
+ }), []), E(() => {
101
+ if (r.current && y.current) {
102
+ const t = y.current, e = v;
103
+ s(t.apiConfig, e.apiConfig) && s(t.theme, e.theme) && t.showTable === e.showTable && t.optInSelected === e.optInSelected && s(t.callbacks, e.callbacks) && !s(t.quoteRequestData, e.quoteRequestData) ? r.current.updateQuote(e.quoteRequestData) : s(t, e) || (r.current.destroy(), r.current = new M({
104
+ location: O.current,
105
+ ...e
106
+ })), y.current = e;
58
107
  }
59
- })), z(() => {
60
- if (l.current)
61
- return u.current && u.current.destroy(), u.current = new A({
62
- location: l.current,
63
- ...H
64
- }), () => {
65
- u.current && (u.current.destroy(), u.current = null);
66
- };
67
- }, [m, i, y, W, a, v, c, s, t, f, d, e, w]), /* @__PURE__ */ P("div", { ref: l });
108
+ }, [v]), /* @__PURE__ */ x("div", { ref: O });
68
109
  });
69
- B.displayName = "ReactSpotWidget";
110
+ H.displayName = "ReactSpotWidget";
70
111
  export {
71
- B as default
112
+ H as default
72
113
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(u,t){typeof exports=="object"&&typeof module<"u"?module.exports=t(require("react/jsx-runtime"),require("react"),require("@getspot/spot-widget")):typeof define=="function"&&define.amd?define(["react/jsx-runtime","react","@getspot/spot-widget"],t):(u=typeof globalThis<"u"?globalThis:u||self,u.ReactSpotWidget=t(u.React,u.React,u.SpotWidget))})(this,function(u,t,n){"use strict";const p=t.forwardRef(({apiConfig:y,quoteRequestData:R,showTable:x=!0,optInSelected:W=!1,theme:j,callbacks:w={},onQuoteRetrieved:i,onOptIn:d,onOptOut:f,onError:c,onNoMatchingQuote:l,onSelectionChange:s,...v},q)=>{const m=t.useRef(null),r=t.useRef(null),H={...w,...i&&{onQuoteRetrieved:i},...d&&{onOptIn:e=>{d==null||d(e),s==null||s(e)}},...f&&{onOptOut:e=>{f==null||f(e),s==null||s(e)}},...c&&{onError:c},...l&&{noMatchingQuote:l}},P={apiConfig:y,quoteRequestData:R,showTable:x,optInSelected:W,theme:j,callbacks:H,...v};return t.useImperativeHandle(q,()=>({updateQuote:e=>{var k;return((k=r.current)==null?void 0:k.updateQuote(e))??Promise.resolve(!1)},getSelection:()=>{var e;return((e=r.current)==null?void 0:e.getSelection())??null},validateSelection:()=>{var e;return((e=r.current)==null?void 0:e.validateSelection())??!1},destroy:()=>{r.current&&(r.current.destroy(),r.current=null)}})),t.useEffect(()=>{if(m.current)return r.current&&r.current.destroy(),r.current=new n({location:m.current,...P}),()=>{r.current&&(r.current.destroy(),r.current=null)}},[y,R,x,W,j,w,i,d,f,c,l,s,v]),u.jsx("div",{ref:m})});return p.displayName="ReactSpotWidget",p});
1
+ (function(i,n){typeof exports=="object"&&typeof module<"u"?module.exports=n(require("react/jsx-runtime"),require("react"),require("@getspot/spot-widget")):typeof define=="function"&&define.amd?define(["react/jsx-runtime","react","@getspot/spot-widget"],n):(i=typeof globalThis<"u"?globalThis:i||self,i.ReactSpotWidget=n(i.React,i.React,i.SpotWidget))})(this,function(i,n,k){"use strict";function f(s,c){if(s===c)return!0;if(s==null||c==null||typeof s!="object"||typeof c!="object")return!1;const l=Object.keys(s),d=Object.keys(c);if(l.length!==d.length)return!1;for(let a of l)if(!d.includes(a)||!f(s[a],c[a]))return!1;return!0}function v(s,c){const l=n.useRef(void 0);return(!l.current||!f(l.current.deps,c))&&(l.current={deps:c,value:s()}),l.current.value}const b=n.forwardRef(({apiConfig:s,quoteRequestData:c,showTable:l=!0,optInSelected:d=!1,theme:a,callbacks:h={},onQuoteRetrieved:m,onOptIn:Q,onOptOut:C,onError:S,onNoMatchingQuote:j,onSelectionChange:q},W)=>{const g=n.useRef(null),r=n.useRef(null),o=n.useRef({onQuoteRetrieved:m,onOptIn:Q,onOptOut:C,onError:S,onNoMatchingQuote:j,onSelectionChange:q});o.current={onQuoteRetrieved:m,onOptIn:Q,onOptOut:C,onError:S,onNoMatchingQuote:j,onSelectionChange:q};const w=n.useCallback(t=>{var e,u;return(u=(e=o.current).onQuoteRetrieved)==null?void 0:u.call(e,t)},[]),E=n.useCallback(t=>{var e,u,p,R;(u=(e=o.current).onOptIn)==null||u.call(e,t),(R=(p=o.current).onSelectionChange)==null||R.call(p,t)},[]),I=n.useCallback(t=>{var e,u,p,R;(u=(e=o.current).onOptOut)==null||u.call(e,t),(R=(p=o.current).onSelectionChange)==null||R.call(p,t)},[]),x=n.useCallback(t=>{var e,u;(u=(e=o.current).onError)==null||u.call(e,t)},[]),D=n.useCallback(t=>{var e,u;(u=(e=o.current).onNoMatchingQuote)==null||u.call(e,t)},[]),M=v(()=>({...h,...o.current.onQuoteRetrieved&&{onQuoteRetrieved:w},...o.current.onOptIn&&{onOptIn:E},...o.current.onOptOut&&{onOptOut:I},...o.current.onError&&{onError:x},...o.current.onNoMatchingQuote&&{noMatchingQuote:D}}),[h,w,E,I,x,D]),O=v(()=>({apiConfig:s,quoteRequestData:c,showTable:l,optInSelected:d,theme:a,callbacks:M}),[s,c,l,d,a,M]);n.useImperativeHandle(W,()=>({updateQuote:t=>{var e;return((e=r.current)==null?void 0:e.updateQuote(t))??Promise.resolve(!1)},getSelection:()=>{var t;return((t=r.current)==null?void 0:t.getSelection())??null},validateSelection:()=>{var t;return((t=r.current)==null?void 0:t.validateSelection())??!1},destroy:()=>{r.current&&(r.current.destroy(),r.current=null)}}));const y=n.useRef(void 0);return n.useEffect(()=>(g.current&&!r.current&&(r.current=new k({location:g.current,...O}),y.current=O),()=>{r.current&&(r.current.destroy(),r.current=null)}),[]),n.useEffect(()=>{if(r.current&&y.current){const t=y.current,e=O;f(t.apiConfig,e.apiConfig)&&f(t.theme,e.theme)&&t.showTable===e.showTable&&t.optInSelected===e.optInSelected&&f(t.callbacks,e.callbacks)&&!f(t.quoteRequestData,e.quoteRequestData)?r.current.updateQuote(e.quoteRequestData):f(t,e)||(r.current.destroy(),r.current=new k({location:g.current,...e})),y.current=e}},[O]),i.jsx("div",{ref:g})});return b.displayName="ReactSpotWidget",b});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getspot/spot-widget-react",
3
- "version": "3.0.1",
3
+ "version": "3.1.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },