@getspot/spot-widget-react 2.1.1 → 2.1.2

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.
@@ -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,MAAM,sBAAsB,CAAC;AAE1G;;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,IAAI,CAAC;IAC1C,+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,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,GAAG,CAAA;KAAE,KAAK,IAAI,CAAC;IACpF,qDAAqD;IACrD,iBAAiB,CAAC,EAAE,CAAC,IAA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AC;AAIH,eAAe,eAAe,CAAC"}
package/dist/index.es.js CHANGED
@@ -1,72 +1,128 @@
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,
9
- 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
42
- };
43
- return p(j, () => ({
44
- updateQuote: (r) => {
45
- var x;
46
- return ((x = u.current) == null ? void 0 : x.updateQuote(r)) ?? Promise.resolve(!1);
1
+ import { jsx as x } from "react/jsx-runtime";
2
+ import { forwardRef as A, useRef as p, useCallback as O, useMemo as B, useImperativeHandle as H, useEffect as W } from "react";
3
+ import N from "@getspot/spot-widget";
4
+ function i(c, u) {
5
+ if (c === u) return !0;
6
+ if (c == null || u == null || typeof c != "object" || typeof u != "object") return !1;
7
+ const s = Object.keys(c), d = Object.keys(u);
8
+ if (s.length !== d.length) return !1;
9
+ for (let f of s)
10
+ if (!d.includes(f) || !i(c[f], u[f])) return !1;
11
+ return !0;
12
+ }
13
+ function K(c, u) {
14
+ const s = p();
15
+ return (!s.current || !i(s.current.deps, u)) && (s.current = { deps: u, value: c() }), s.current.value;
16
+ }
17
+ const T = A(({
18
+ apiConfig: c,
19
+ quoteRequestData: u,
20
+ showTable: s = !0,
21
+ optInSelected: d = !1,
22
+ theme: f,
23
+ callbacks: k = {},
24
+ onQuoteRetrieved: R,
25
+ onOptIn: m,
26
+ onOptOut: v,
27
+ onError: Q,
28
+ onNoMatchingQuote: h,
29
+ onSelectionChange: S
30
+ }, P) => {
31
+ const g = p(null), n = p(null), o = p({
32
+ onQuoteRetrieved: R,
33
+ onOptIn: m,
34
+ onOptOut: v,
35
+ onError: Q,
36
+ onNoMatchingQuote: h,
37
+ onSelectionChange: S
38
+ }), C = p(k);
39
+ o.current = {
40
+ onQuoteRetrieved: R,
41
+ onOptIn: m,
42
+ onOptOut: v,
43
+ onError: Q,
44
+ onNoMatchingQuote: h,
45
+ onSelectionChange: S
46
+ }, C.current = k;
47
+ const I = O((e) => {
48
+ var t, r;
49
+ return (r = (t = o.current).onQuoteRetrieved) == null ? void 0 : r.call(t, e);
50
+ }, []), w = O((e) => {
51
+ var t, r, a, l;
52
+ (r = (t = o.current).onOptIn) == null || r.call(t, e), (l = (a = o.current).onSelectionChange) == null || l.call(a, e);
53
+ }, []), E = O((e) => {
54
+ var t, r, a, l;
55
+ (r = (t = o.current).onOptOut) == null || r.call(t, e), (l = (a = o.current).onSelectionChange) == null || l.call(a, e);
56
+ }, []), M = O((e) => {
57
+ var t, r;
58
+ (r = (t = o.current).onError) == null || r.call(t, e);
59
+ }, []), j = O((e) => {
60
+ var t, r;
61
+ (r = (t = o.current).onNoMatchingQuote) == null || r.call(t, e);
62
+ }, []), q = B(() => {
63
+ const e = {}, t = [
64
+ "onQuoteRetrieved",
65
+ "onOptIn",
66
+ "onOptOut",
67
+ "onError",
68
+ "noMatchingQuote"
69
+ ];
70
+ for (const r of t)
71
+ e[r] = (...a) => {
72
+ var D;
73
+ const l = (D = C.current) == null ? void 0 : D[r];
74
+ if (l) return l(...a);
75
+ };
76
+ return {
77
+ ...e,
78
+ ...o.current.onQuoteRetrieved && { onQuoteRetrieved: I },
79
+ ...o.current.onOptIn && { onOptIn: w },
80
+ ...o.current.onOptOut && { onOptOut: E },
81
+ ...o.current.onError && { onError: M },
82
+ ...o.current.onNoMatchingQuote && { noMatchingQuote: j }
83
+ };
84
+ }, [I, w, E, M, j]), b = K(() => ({
85
+ apiConfig: c,
86
+ quoteRequestData: u,
87
+ showTable: s,
88
+ optInSelected: d,
89
+ theme: f,
90
+ callbacks: q
91
+ }), [c, u, s, d, f, q]);
92
+ H(P, () => ({
93
+ updateQuote: (e) => {
94
+ var t;
95
+ return ((t = n.current) == null ? void 0 : t.updateQuote(e)) ?? Promise.resolve(!1);
47
96
  },
48
97
  getSelection: () => {
49
- var r;
50
- return ((r = u.current) == null ? void 0 : r.getSelection()) ?? null;
98
+ var e;
99
+ return ((e = n.current) == null ? void 0 : e.getSelection()) ?? null;
51
100
  },
52
101
  validateSelection: () => {
53
- var r;
54
- return ((r = u.current) == null ? void 0 : r.validateSelection()) ?? !1;
102
+ var e;
103
+ return ((e = n.current) == null ? void 0 : e.validateSelection()) ?? !1;
55
104
  },
56
105
  destroy: () => {
57
- u.current && (u.current.destroy(), u.current = null);
106
+ n.current && (n.current.destroy(), n.current = null);
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
+ }));
109
+ const y = p();
110
+ return W(() => (g.current && !n.current && (n.current = new N({
111
+ location: g.current,
112
+ ...b
113
+ }), y.current = b), () => {
114
+ n.current && (n.current.destroy(), n.current = null);
115
+ }), []), W(() => {
116
+ if (n.current && y.current) {
117
+ const e = y.current, t = b;
118
+ i(e.apiConfig, t.apiConfig) && i(e.theme, t.theme) && e.showTable === t.showTable && e.optInSelected === t.optInSelected && i(e.callbacks, t.callbacks) && !i(e.quoteRequestData, t.quoteRequestData) ? n.current.updateQuote(t.quoteRequestData) : i(e, t) || (n.current.destroy(), n.current = new N({
119
+ location: g.current,
120
+ ...t
121
+ })), y.current = t;
122
+ }
123
+ }, [b]), /* @__PURE__ */ x("div", { ref: g });
68
124
  });
69
- B.displayName = "ReactSpotWidget";
125
+ T.displayName = "ReactSpotWidget";
70
126
  export {
71
- B as default
127
+ T as default
72
128
  };
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 a(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),R=Object.keys(c);if(l.length!==R.length)return!1;for(let d of l)if(!R.includes(d)||!a(s[d],c[d]))return!1;return!0}function N(s,c){const l=n.useRef();return(!l.current||!a(l.current.deps,c))&&(l.current={deps:c,value:s()}),l.current.value}const y=n.forwardRef(({apiConfig:s,quoteRequestData:c,showTable:l=!0,optInSelected:R=!1,theme:d,callbacks:h={},onQuoteRetrieved:v,onOptIn:Q,onOptOut:m,onError:C,onNoMatchingQuote:S,onSelectionChange:j},P)=>{const O=n.useRef(null),u=n.useRef(null),o=n.useRef({onQuoteRetrieved:v,onOptIn:Q,onOptOut:m,onError:C,onNoMatchingQuote:S,onSelectionChange:j}),q=n.useRef(h);o.current={onQuoteRetrieved:v,onOptIn:Q,onOptOut:m,onError:C,onNoMatchingQuote:S,onSelectionChange:j},q.current=h;const w=n.useCallback(e=>{var t,r;return(r=(t=o.current).onQuoteRetrieved)==null?void 0:r.call(t,e)},[]),E=n.useCallback(e=>{var t,r,p,f;(r=(t=o.current).onOptIn)==null||r.call(t,e),(f=(p=o.current).onSelectionChange)==null||f.call(p,e)},[]),I=n.useCallback(e=>{var t,r,p,f;(r=(t=o.current).onOptOut)==null||r.call(t,e),(f=(p=o.current).onSelectionChange)==null||f.call(p,e)},[]),M=n.useCallback(e=>{var t,r;(r=(t=o.current).onError)==null||r.call(t,e)},[]),x=n.useCallback(e=>{var t,r;(r=(t=o.current).onNoMatchingQuote)==null||r.call(t,e)},[]),D=n.useMemo(()=>{const e={},t=["onQuoteRetrieved","onOptIn","onOptOut","onError","noMatchingQuote"];for(const r of t)e[r]=(...p)=>{var W;const f=(W=q.current)==null?void 0:W[r];if(f)return f(...p)};return{...e,...o.current.onQuoteRetrieved&&{onQuoteRetrieved:w},...o.current.onOptIn&&{onOptIn:E},...o.current.onOptOut&&{onOptOut:I},...o.current.onError&&{onError:M},...o.current.onNoMatchingQuote&&{noMatchingQuote:x}}},[w,E,I,M,x]),g=N(()=>({apiConfig:s,quoteRequestData:c,showTable:l,optInSelected:R,theme:d,callbacks:D}),[s,c,l,R,d,D]);n.useImperativeHandle(P,()=>({updateQuote:e=>{var t;return((t=u.current)==null?void 0:t.updateQuote(e))??Promise.resolve(!1)},getSelection:()=>{var e;return((e=u.current)==null?void 0:e.getSelection())??null},validateSelection:()=>{var e;return((e=u.current)==null?void 0:e.validateSelection())??!1},destroy:()=>{u.current&&(u.current.destroy(),u.current=null)}}));const b=n.useRef();return n.useEffect(()=>(O.current&&!u.current&&(u.current=new k({location:O.current,...g}),b.current=g),()=>{u.current&&(u.current.destroy(),u.current=null)}),[]),n.useEffect(()=>{if(u.current&&b.current){const e=b.current,t=g;a(e.apiConfig,t.apiConfig)&&a(e.theme,t.theme)&&e.showTable===t.showTable&&e.optInSelected===t.optInSelected&&a(e.callbacks,t.callbacks)&&!a(e.quoteRequestData,t.quoteRequestData)?u.current.updateQuote(t.quoteRequestData):a(e,t)||(u.current.destroy(),u.current=new k({location:O.current,...t})),b.current=t}},[g]),i.jsx("div",{ref:O})});return y.displayName="ReactSpotWidget",y});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getspot/spot-widget-react",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -12,8 +12,18 @@
12
12
  "README.md",
13
13
  "CHANGELOG.md"
14
14
  ],
15
+ "scripts": {
16
+ "build": "vite build && npx -p typescript tsc --emitDeclarationOnly && cp dist/ReactSpotWidget.d.ts dist/index.d.ts",
17
+ "docs": "npx -p typedoc -p typedoc-plugin-markdown typedoc --plugin typedoc-plugin-markdown --out docs src/ReactSpotWidget.tsx",
18
+ "docs:readme": "npm run docs && node scripts/generate-readme.js",
19
+ "test": "jest",
20
+ "test:watch": "jest --watch",
21
+ "test:coverage": "jest --coverage",
22
+ "test:ci": "jest --ci --coverage --watchAll=false",
23
+ "prepublishOnly": "npm run build"
24
+ },
15
25
  "dependencies": {
16
- "@getspot/spot-widget": "2.1.1"
26
+ "@getspot/spot-widget": "workspace:*"
17
27
  },
18
28
  "peerDependencies": {
19
29
  "react": ">=18.0.0",
@@ -38,14 +48,5 @@
38
48
  "react": "^18.0.0",
39
49
  "react-dom": "^18.0.0",
40
50
  "ts-jest": "^29.0.0"
41
- },
42
- "scripts": {
43
- "build": "vite build && npx -p typescript tsc --emitDeclarationOnly && cp dist/ReactSpotWidget.d.ts dist/index.d.ts",
44
- "docs": "npx -p typedoc -p typedoc-plugin-markdown typedoc --plugin typedoc-plugin-markdown --out docs src/ReactSpotWidget.tsx",
45
- "docs:readme": "npm run docs && node scripts/generate-readme.js",
46
- "test": "jest",
47
- "test:watch": "jest --watch",
48
- "test:coverage": "jest --coverage",
49
- "test:ci": "jest --ci --coverage --watchAll=false"
50
51
  }
51
- }
52
+ }