@getspot/spot-widget-react 3.3.2 → 4.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/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ # [4.0.0](https://gitlab.com/getspot/spot-widget/compare/@getspot/spot-widget-react@3.3.2...@getspot/spot-widget-react@4.0.0) (2026-01-12)
2
+
3
+
4
+ * feat!(core): replacing optInSelected prop with selection enum ([0d40913](https://gitlab.com/getspot/spot-widget/commit/0d409135aa50eaa98995b9c1e20ca05cc7e2b2fc))
5
+
6
+
7
+ ### BREAKING CHANGES
8
+
9
+ * better preselection of widget optIn/optOut
10
+
1
11
  ## [3.3.2](https://gitlab.com/getspot/spot-widget/compare/@getspot/spot-widget-react@3.3.1...@getspot/spot-widget-react@3.3.2) (2026-01-09)
2
12
 
3
13
 
package/README.md CHANGED
@@ -79,7 +79,7 @@ This package includes full TypeScript definitions. All props are typed for bette
79
79
  | Prop | Type | Default | Description |
80
80
  |------|------|---------|-------------|
81
81
  | `showTable` | `boolean` | `true` | Whether to show the payout table |
82
- | `optInSelected` | `boolean` | `false` | Whether the widget should be pre-selected for opt-in |
82
+ | `selection` | `SelectionEnum` | `'unselected'` | Initial selection state for the widget |
83
83
  | `theme` | `Theme` | `undefined` | Theme customization options for styling the widget |
84
84
 
85
85
  ### Callback Props
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { type SpotWidgetOptions, type SelectionData, type Quote, type QuoteUpdates } from "@getspot/spot-widget";
2
+ import { type SpotWidgetOptions, type SelectionData, type Quote, type QuoteUpdates, type QuoteRequestData, type ApiConfig, SelectionEnum } from "@getspot/spot-widget";
3
3
  /**
4
4
  * Props for the ReactSpotWidget component
5
5
  */
@@ -11,7 +11,7 @@ interface ReactSpotWidgetProps extends Omit<SpotWidgetOptions, 'location' | 'cal
11
11
  /** Whether to show the payout table. Defaults to true */
12
12
  showTable?: boolean;
13
13
  /** Whether the widget should be pre-selected for opt-in. Defaults to false */
14
- optInSelected?: boolean;
14
+ selection?: SelectionEnum;
15
15
  /** Theme customization options for styling the widget */
16
16
  theme?: SpotWidgetOptions['theme'];
17
17
  /** Callback fired when a quote is successfully retrieved */
@@ -80,4 +80,6 @@ export interface ReactSpotWidgetRef {
80
80
  */
81
81
  declare const ReactSpotWidget: React.ForwardRefExoticComponent<ReactSpotWidgetProps & React.RefAttributes<ReactSpotWidgetRef>>;
82
82
  export default ReactSpotWidget;
83
+ export type { Quote, QuoteUpdates, SelectionData, SpotWidgetOptions, QuoteRequestData, ApiConfig };
84
+ export { SelectionEnum };
83
85
  //# sourceMappingURL=ReactSpotWidget.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ReactSpotWidget.d.ts","sourceRoot":"","sources":["../src/ReactSpotWidget.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmF,MAAM,OAAO,CAAC;AA+BxG,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,a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C;CAC5C;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,6CAA6C;IAC7C,WAAW,EAAE,CAAC,mBAAmB,EAAE,iBAAiB,CAAC,kBAAkB,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9F,qCAAqC;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,iGAwLnB,CAAC;AAIH,eAAe,eAAe,CAAC;AAC/B,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,SAAS,EAAE,CAAC;AACnG,OAAO,EAAE,aAAa,EAAE,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { type SpotWidgetOptions, type SelectionData, type Quote, type QuoteUpdates } from "@getspot/spot-widget";
2
+ import { type SpotWidgetOptions, type SelectionData, type Quote, type QuoteUpdates, type QuoteRequestData, type ApiConfig, SelectionEnum } from "@getspot/spot-widget";
3
3
  /**
4
4
  * Props for the ReactSpotWidget component
5
5
  */
@@ -11,7 +11,7 @@ interface ReactSpotWidgetProps extends Omit<SpotWidgetOptions, 'location' | 'cal
11
11
  /** Whether to show the payout table. Defaults to true */
12
12
  showTable?: boolean;
13
13
  /** Whether the widget should be pre-selected for opt-in. Defaults to false */
14
- optInSelected?: boolean;
14
+ selection?: SelectionEnum;
15
15
  /** Theme customization options for styling the widget */
16
16
  theme?: SpotWidgetOptions['theme'];
17
17
  /** Callback fired when a quote is successfully retrieved */
@@ -80,4 +80,6 @@ export interface ReactSpotWidgetRef {
80
80
  */
81
81
  declare const ReactSpotWidget: React.ForwardRefExoticComponent<ReactSpotWidgetProps & React.RefAttributes<ReactSpotWidgetRef>>;
82
82
  export default ReactSpotWidget;
83
+ export type { Quote, QuoteUpdates, SelectionData, SpotWidgetOptions, QuoteRequestData, ApiConfig };
84
+ export { SelectionEnum };
83
85
  //# sourceMappingURL=ReactSpotWidget.d.ts.map
package/dist/index.es.js CHANGED
@@ -1,6 +1,7 @@
1
- import { jsx as B } from "react/jsx-runtime";
2
- import { forwardRef as H, useRef as p, useCallback as O, useMemo as K, useImperativeHandle as T, useEffect as P } from "react";
3
- import x from "@getspot/spot-widget";
1
+ import { jsx as A } from "react/jsx-runtime";
2
+ import { forwardRef as B, useRef as p, useCallback as O, useMemo as H, useImperativeHandle as K, useEffect as x } from "react";
3
+ import P, { SelectionEnum as L } from "@getspot/spot-widget";
4
+ import { SelectionEnum as Y } from "@getspot/spot-widget";
4
5
  function i(c, u) {
5
6
  if (c === u) return !0;
6
7
  if (c == null || u == null || typeof c != "object" || typeof u != "object") return !1;
@@ -10,43 +11,43 @@ function i(c, u) {
10
11
  if (!d.includes(f) || !i(c[f], u[f])) return !1;
11
12
  return !0;
12
13
  }
13
- function z(c, u) {
14
+ function U(c, u) {
14
15
  const s = p(void 0);
15
16
  return (!s.current || !i(s.current.deps, u)) && (s.current = { deps: u, value: c() }), s.current.value;
16
17
  }
17
- const F = H(({
18
+ const z = B(({
18
19
  apiConfig: c,
19
20
  quoteRequestData: u,
20
21
  showTable: s = !0,
21
- optInSelected: d = !1,
22
+ selection: d = L.UNSELECTED,
22
23
  theme: f,
23
- callbacks: v = {},
24
- useMockData: R,
25
- mockData: Q,
26
- onQuoteRetrieved: k,
27
- onOptIn: m,
24
+ callbacks: m = {},
25
+ useMockData: v,
26
+ mockData: R,
27
+ onQuoteRetrieved: Q,
28
+ onOptIn: k,
28
29
  onOptOut: h,
29
- onError: S,
30
- onNoMatchingQuote: C,
31
- onSelectionChange: I
32
- }, A) => {
30
+ onError: E,
31
+ onNoMatchingQuote: S,
32
+ onSelectionChange: C
33
+ }, T) => {
33
34
  const g = p(null), n = p(null), o = p({
34
- onQuoteRetrieved: k,
35
- onOptIn: m,
35
+ onQuoteRetrieved: Q,
36
+ onOptIn: k,
36
37
  onOptOut: h,
37
- onError: S,
38
- onNoMatchingQuote: C,
39
- onSelectionChange: I
40
- }), w = p(v);
38
+ onError: E,
39
+ onNoMatchingQuote: S,
40
+ onSelectionChange: C
41
+ }), w = p(m);
41
42
  o.current = {
42
- onQuoteRetrieved: k,
43
- onOptIn: m,
43
+ onQuoteRetrieved: Q,
44
+ onOptIn: k,
44
45
  onOptOut: h,
45
- onError: S,
46
- onNoMatchingQuote: C,
47
- onSelectionChange: I
48
- }, w.current = v;
49
- const E = O((e) => {
46
+ onError: E,
47
+ onNoMatchingQuote: S,
48
+ onSelectionChange: C
49
+ }, w.current = m;
50
+ const I = O((e) => {
50
51
  var t, r;
51
52
  return (r = (t = o.current).onQuoteRetrieved) == null ? void 0 : r.call(t, e);
52
53
  }, []), j = O((e) => {
@@ -58,10 +59,10 @@ const F = H(({
58
59
  }, []), M = O((e) => {
59
60
  var t, r;
60
61
  (r = (t = o.current).onError) == null || r.call(t, e);
61
- }, []), W = O((e) => {
62
+ }, []), D = O((e) => {
62
63
  var t, r;
63
64
  (r = (t = o.current).onNoMatchingQuote) == null || r.call(t, e);
64
- }, []), D = K(() => {
65
+ }, []), N = H(() => {
65
66
  const e = {}, t = [
66
67
  "onQuoteRetrieved",
67
68
  "onOptIn",
@@ -71,29 +72,29 @@ const F = H(({
71
72
  ];
72
73
  for (const r of t)
73
74
  e[r] = (...a) => {
74
- var N;
75
- const l = (N = w.current) == null ? void 0 : N[r];
75
+ var W;
76
+ const l = (W = w.current) == null ? void 0 : W[r];
76
77
  if (l) return l(...a);
77
78
  };
78
79
  return {
79
80
  ...e,
80
- ...o.current.onQuoteRetrieved && { onQuoteRetrieved: E },
81
+ ...o.current.onQuoteRetrieved && { onQuoteRetrieved: I },
81
82
  ...o.current.onOptIn && { onOptIn: j },
82
83
  ...o.current.onOptOut && { onOptOut: q },
83
84
  ...o.current.onError && { onError: M },
84
- ...o.current.onNoMatchingQuote && { noMatchingQuote: W }
85
+ ...o.current.onNoMatchingQuote && { noMatchingQuote: D }
85
86
  };
86
- }, [E, j, q, M, W]), b = z(() => ({
87
+ }, [I, j, q, M, D]), b = U(() => ({
87
88
  apiConfig: c,
88
89
  quoteRequestData: u,
89
90
  showTable: s,
90
- optInSelected: d,
91
+ selection: d,
91
92
  theme: f,
92
- callbacks: D,
93
- useMockData: R,
94
- mockData: Q
95
- }), [c, u, s, d, f, D, R, Q]);
96
- T(A, () => ({
93
+ callbacks: N,
94
+ useMockData: v,
95
+ mockData: R
96
+ }), [c, u, s, d, f, N, v, R]);
97
+ K(T, () => ({
97
98
  updateQuote: (e) => {
98
99
  var t;
99
100
  return ((t = n.current) == null ? void 0 : t.updateQuote(e)) ?? Promise.resolve(!1);
@@ -111,22 +112,23 @@ const F = H(({
111
112
  }
112
113
  }));
113
114
  const y = p(void 0);
114
- return P(() => (g.current && !n.current && (n.current = new x({
115
+ return x(() => (g.current && !n.current && (n.current = new P({
115
116
  location: g.current,
116
117
  ...b
117
118
  }), y.current = b), () => {
118
119
  n.current && (n.current.destroy(), n.current = null);
119
- }), []), P(() => {
120
+ }), []), x(() => {
120
121
  if (n.current && y.current) {
121
122
  const e = y.current, t = b;
122
- 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 x({
123
+ i(e.apiConfig, t.apiConfig) && i(e.theme, t.theme) && e.showTable === t.showTable && e.selection === t.selection && i(e.callbacks, t.callbacks) && !i(e.quoteRequestData, t.quoteRequestData) ? n.current.updateQuote(t.quoteRequestData) : i(e, t) || (n.current.destroy(), n.current = new P({
123
124
  location: g.current,
124
125
  ...t
125
126
  })), y.current = t;
126
127
  }
127
- }, [b]), /* @__PURE__ */ B("div", { ref: g });
128
+ }, [b]), /* @__PURE__ */ A("div", { ref: g });
128
129
  });
129
- F.displayName = "ReactSpotWidget";
130
+ z.displayName = "ReactSpotWidget";
130
131
  export {
131
- F as default
132
+ Y as SelectionEnum,
133
+ z as default
132
134
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
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,y){"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 T(s,c){const l=n.useRef(void 0);return(!l.current||!a(l.current.deps,c))&&(l.current={deps:c,value:s()}),l.current.value}const k=n.forwardRef(({apiConfig:s,quoteRequestData:c,showTable:l=!0,optInSelected:R=!1,theme:d,callbacks:v={},useMockData:h,mockData:Q,onQuoteRetrieved:C,onOptIn:m,onOptOut:S,onError:j,onNoMatchingQuote:q,onSelectionChange:w},A)=>{const O=n.useRef(null),u=n.useRef(null),o=n.useRef({onQuoteRetrieved:C,onOptIn:m,onOptOut:S,onError:j,onNoMatchingQuote:q,onSelectionChange:w}),E=n.useRef(v);o.current={onQuoteRetrieved:C,onOptIn:m,onOptOut:S,onError:j,onNoMatchingQuote:q,onSelectionChange:w},E.current=v;const I=n.useCallback(e=>{var t,r;return(r=(t=o.current).onQuoteRetrieved)==null?void 0:r.call(t,e)},[]),x=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)},[]),M=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)},[]),W=n.useCallback(e=>{var t,r;(r=(t=o.current).onError)==null||r.call(t,e)},[]),D=n.useCallback(e=>{var t,r;(r=(t=o.current).onNoMatchingQuote)==null||r.call(t,e)},[]),N=n.useMemo(()=>{const e={},t=["onQuoteRetrieved","onOptIn","onOptOut","onError","noMatchingQuote"];for(const r of t)e[r]=(...p)=>{var P;const f=(P=E.current)==null?void 0:P[r];if(f)return f(...p)};return{...e,...o.current.onQuoteRetrieved&&{onQuoteRetrieved:I},...o.current.onOptIn&&{onOptIn:x},...o.current.onOptOut&&{onOptOut:M},...o.current.onError&&{onError:W},...o.current.onNoMatchingQuote&&{noMatchingQuote:D}}},[I,x,M,W,D]),g=T(()=>({apiConfig:s,quoteRequestData:c,showTable:l,optInSelected:R,theme:d,callbacks:N,useMockData:h,mockData:Q}),[s,c,l,R,d,N,h,Q]);n.useImperativeHandle(A,()=>({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(void 0);return n.useEffect(()=>(O.current&&!u.current&&(u.current=new y({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 y({location:O.current,...t})),b.current=t}},[g]),i.jsx("div",{ref:O})});return k.displayName="ReactSpotWidget",k});
1
+ (function(s,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("react/jsx-runtime"),require("react"),require("@getspot/spot-widget")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@getspot/spot-widget"],b):(s=typeof globalThis<"u"?globalThis:s||self,b(s.ReactSpotWidget={},s.React,s.React,s.SpotWidget))})(this,function(s,b,r,R){"use strict";function a(l,c){if(l===c)return!0;if(l==null||c==null||typeof l!="object"||typeof c!="object")return!1;const i=Object.keys(l),O=Object.keys(c);if(i.length!==O.length)return!1;for(let p of i)if(!O.includes(p)||!a(l[p],c[p]))return!1;return!0}function _(l,c){const i=r.useRef(void 0);return(!i.current||!a(i.current.deps,c))&&(i.current={deps:c,value:l()}),i.current.value}const k=r.forwardRef(({apiConfig:l,quoteRequestData:c,showTable:i=!0,selection:O=R.SelectionEnum.UNSELECTED,theme:p,callbacks:m={},useMockData:h,mockData:C,onQuoteRetrieved:E,onOptIn:Q,onOptOut:S,onError:j,onNoMatchingQuote:q,onSelectionChange:w},A)=>{const g=r.useRef(null),u=r.useRef(null),o=r.useRef({onQuoteRetrieved:E,onOptIn:Q,onOptOut:S,onError:j,onNoMatchingQuote:q,onSelectionChange:w}),M=r.useRef(m);o.current={onQuoteRetrieved:E,onOptIn:Q,onOptOut:S,onError:j,onNoMatchingQuote:q,onSelectionChange:w},M.current=m;const I=r.useCallback(e=>{var t,n;return(n=(t=o.current).onQuoteRetrieved)==null?void 0:n.call(t,e)},[]),P=r.useCallback(e=>{var t,n,d,f;(n=(t=o.current).onOptIn)==null||n.call(t,e),(f=(d=o.current).onSelectionChange)==null||f.call(d,e)},[]),T=r.useCallback(e=>{var t,n,d,f;(n=(t=o.current).onOptOut)==null||n.call(t,e),(f=(d=o.current).onSelectionChange)==null||f.call(d,e)},[]),x=r.useCallback(e=>{var t,n;(n=(t=o.current).onError)==null||n.call(t,e)},[]),D=r.useCallback(e=>{var t,n;(n=(t=o.current).onNoMatchingQuote)==null||n.call(t,e)},[]),N=r.useMemo(()=>{const e={},t=["onQuoteRetrieved","onOptIn","onOptOut","onError","noMatchingQuote"];for(const n of t)e[n]=(...d)=>{var W;const f=(W=M.current)==null?void 0:W[n];if(f)return f(...d)};return{...e,...o.current.onQuoteRetrieved&&{onQuoteRetrieved:I},...o.current.onOptIn&&{onOptIn:P},...o.current.onOptOut&&{onOptOut:T},...o.current.onError&&{onError:x},...o.current.onNoMatchingQuote&&{noMatchingQuote:D}}},[I,P,T,x,D]),y=_(()=>({apiConfig:l,quoteRequestData:c,showTable:i,selection:O,theme:p,callbacks:N,useMockData:h,mockData:C}),[l,c,i,O,p,N,h,C]);r.useImperativeHandle(A,()=>({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 v=r.useRef(void 0);return r.useEffect(()=>(g.current&&!u.current&&(u.current=new R({location:g.current,...y}),v.current=y),()=>{u.current&&(u.current.destroy(),u.current=null)}),[]),r.useEffect(()=>{if(u.current&&v.current){const e=v.current,t=y;a(e.apiConfig,t.apiConfig)&&a(e.theme,t.theme)&&e.showTable===t.showTable&&e.selection===t.selection&&a(e.callbacks,t.callbacks)&&!a(e.quoteRequestData,t.quoteRequestData)?u.current.updateQuote(t.quoteRequestData):a(e,t)||(u.current.destroy(),u.current=new R({location:g.current,...t})),v.current=t}},[y]),b.jsx("div",{ref:g})});k.displayName="ReactSpotWidget",Object.defineProperty(s,"SelectionEnum",{enumerable:!0,get:()=>R.SelectionEnum}),s.default=k,Object.defineProperties(s,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getspot/spot-widget-react",
3
- "version": "3.3.2",
3
+ "version": "4.0.0",
4
4
  "description": "React wrapper for Spot Widget",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -14,7 +14,7 @@
14
14
  "CHANGELOG.md"
15
15
  ],
16
16
  "dependencies": {
17
- "@getspot/spot-widget": "^3.3.2"
17
+ "@getspot/spot-widget": "^4.0.0"
18
18
  },
19
19
  "peerDependencies": {
20
20
  "@types/react": ">=18.0.0",
@@ -48,8 +48,8 @@
48
48
  "vite": "^5.0.0"
49
49
  },
50
50
  "scripts": {
51
- "build": "vite build && npx -p typescript tsc --emitDeclarationOnly && cp dist/ReactSpotWidget.d.ts dist/index.d.ts",
52
- "docs": "npx -p typedoc -p typedoc-plugin-markdown typedoc --plugin typedoc-plugin-markdown --out docs src/ReactSpotWidget.tsx",
51
+ "build": "vite build && npx -p typescript tsc -p tsconfig.build.json --emitDeclarationOnly && cp dist/ReactSpotWidget.d.ts dist/index.d.ts",
52
+ "docs": "npx -p typedoc -p typedoc-plugin-markdown typedoc --plugin typedoc-plugin-markdown --tsconfig tsconfig.build.json --out docs src/ReactSpotWidget.tsx",
53
53
  "docs:readme": "npm run docs && node scripts/generate-readme.js",
54
54
  "test": "jest --watchAll=false",
55
55
  "test:watch": "jest --watch",
@@ -1,2 +0,0 @@
1
- import '@testing-library/jest-dom';
2
- //# sourceMappingURL=setupTests.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setupTests.d.ts","sourceRoot":"","sources":["../src/setupTests.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC"}