@getspot/spot-widget-vue 0.2.0 → 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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @getspot/spot-widget-vue@0.2.0 build /builds/getspot/spot-widget/packages/vue
2
+ > @getspot/spot-widget-vue@1.0.0 build /builds/getspot/spot-widget/packages/vue
3
3
  > vite build
4
4
 
5
5
  The CJS build of Vite's Node API is deprecated. See https://vite.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.
@@ -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
- dist/index.umd.js 0.80 kB │ gzip: 0.49 kB
13
- dist/index.es.js 0.80 kB │ gzip: 0.48 kB
14
- ✓ built in 213ms
12
+ dist/index.umd.js 3.65 kB │ gzip: 1.18 kB
13
+ dist/index.es.js 4.98 kB │ gzip: 1.29 kB
14
+ ✓ built in 217ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @getspot/spot-widget-vue
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
+
3
18
  ## 0.2.0
4
19
 
5
20
  ### Minor Changes
package/dist/index.es.js CHANGED
@@ -1,37 +1,192 @@
1
1
  import s from "@getspot/spot-widget";
2
- import { createElementBlock as c, openBlock as i } from "vue";
3
- const p = (t, e) => {
4
- const o = t.__vccOpts || t;
5
- for (const [r, n] of e)
6
- o[r] = n;
7
- return o;
8
- }, a = {
2
+ import { createElementBlock as r, openBlock as d } from "vue";
3
+ const a = (t, e) => {
4
+ const i = t.__vccOpts || t;
5
+ for (const [n, o] of e)
6
+ i[n] = o;
7
+ return i;
8
+ }, u = {
9
9
  name: "VueSpotWidget",
10
10
  props: {
11
+ apiConfig: {
12
+ type: Object,
13
+ default: void 0
14
+ },
15
+ quoteRequestData: {
16
+ type: Object,
17
+ default: void 0
18
+ },
19
+ showTable: {
20
+ type: Boolean,
21
+ default: !0
22
+ },
23
+ optInSelected: {
24
+ type: Boolean,
25
+ default: !1
26
+ },
27
+ theme: {
28
+ type: Object,
29
+ default: void 0
30
+ },
31
+ callbacks: {
32
+ type: Object,
33
+ default: () => ({})
34
+ },
35
+ onQuoteRetrieved: {
36
+ type: Function,
37
+ default: void 0
38
+ },
39
+ onOptIn: {
40
+ type: Function,
41
+ default: void 0
42
+ },
43
+ onOptOut: {
44
+ type: Function,
45
+ default: void 0
46
+ },
47
+ onError: {
48
+ type: Function,
49
+ default: void 0
50
+ },
51
+ onNoMatchingQuote: {
52
+ type: Function,
53
+ default: void 0
54
+ },
55
+ onSelectionChange: {
56
+ type: Function,
57
+ default: void 0
58
+ },
11
59
  options: {
12
60
  type: Object,
13
61
  default: () => ({})
14
62
  }
15
63
  },
64
+ data() {
65
+ return {
66
+ widget: null,
67
+ reinitTimeout: null
68
+ };
69
+ },
70
+ computed: {
71
+ mergedCallbacks() {
72
+ return {
73
+ ...this.callbacks,
74
+ ...this.onQuoteRetrieved && { onQuoteRetrieved: this.onQuoteRetrieved },
75
+ ...this.onOptIn && {
76
+ onOptIn: (t) => {
77
+ var e, i;
78
+ (e = this.onOptIn) == null || e.call(this, t), (i = this.onSelectionChange) == null || i.call(this, t);
79
+ }
80
+ },
81
+ ...this.onOptOut && {
82
+ onOptOut: (t) => {
83
+ var e, i;
84
+ (e = this.onOptOut) == null || e.call(this, t), (i = this.onSelectionChange) == null || i.call(this, t);
85
+ }
86
+ },
87
+ ...this.onError && { onError: this.onError },
88
+ ...this.onNoMatchingQuote && { onNoMatchingQuote: this.onNoMatchingQuote }
89
+ };
90
+ },
91
+ widgetOptions() {
92
+ return {
93
+ apiConfig: this.apiConfig,
94
+ quoteRequestData: this.quoteRequestData,
95
+ showTable: this.showTable,
96
+ optInSelected: this.optInSelected,
97
+ theme: this.theme,
98
+ callbacks: this.mergedCallbacks,
99
+ ...this.options
100
+ };
101
+ }
102
+ },
16
103
  mounted() {
17
- try {
18
- this.widget = new s({
19
- ...this.options,
20
- location: this.$refs.container
104
+ this.initializeWidget();
105
+ },
106
+ watch: {
107
+ quoteRequestData: {
108
+ handler(t, e) {
109
+ this.widget && t && JSON.stringify(t) !== JSON.stringify(e) && (this.reinitTimeout && clearTimeout(this.reinitTimeout), this.reinitTimeout = setTimeout(() => {
110
+ this.reinitializeWidget(), this.reinitTimeout = null;
111
+ }, 100));
112
+ },
113
+ deep: !0
114
+ },
115
+ apiConfig: {
116
+ handler() {
117
+ this.reinitializeWidget();
118
+ },
119
+ deep: !0
120
+ },
121
+ showTable(t, e) {
122
+ t !== e && this.reinitializeWidget();
123
+ },
124
+ optInSelected(t, e) {
125
+ t !== e && this.reinitializeWidget();
126
+ },
127
+ theme: {
128
+ handler(t, e) {
129
+ this.widget && JSON.stringify(t) !== JSON.stringify(e) && this.updateTheme(t);
130
+ },
131
+ deep: !0
132
+ },
133
+ mergedCallbacks: {
134
+ handler(t, e) {
135
+ this.widget && JSON.stringify(t) !== JSON.stringify(e) && this.updateCallbacks(t);
136
+ },
137
+ deep: !0
138
+ }
139
+ },
140
+ methods: {
141
+ initializeWidget() {
142
+ this.widget && (this.widget.destroy(), this.widget = null), this.$refs.container && (this.$refs.container.innerHTML = ""), this.$nextTick(() => {
143
+ var t;
144
+ try {
145
+ this.widget = new s({
146
+ ...this.widgetOptions,
147
+ location: this.$refs.container
148
+ });
149
+ } catch (e) {
150
+ this.$emit("error", e), (t = this.onError) == null || t.call(this, e);
151
+ }
152
+ });
153
+ },
154
+ reinitializeWidget() {
155
+ this.widget && (this.widget.destroy(), this.widget = null), this.initializeWidget();
156
+ },
157
+ async updateQuote(t) {
158
+ var e;
159
+ return (e = this.widget) == null ? void 0 : e.updateQuote(t);
160
+ },
161
+ getSelection() {
162
+ var t;
163
+ return (t = this.widget) == null ? void 0 : t.getSelection();
164
+ },
165
+ validateSelection() {
166
+ var t;
167
+ return (t = this.widget) == null ? void 0 : t.validateSelection();
168
+ },
169
+ updateTheme(t) {
170
+ !this.widget || !this.widget.container || Object.entries(t || {}).forEach(([e, i]) => {
171
+ const n = `--${e}`;
172
+ this.widget.container.style.setProperty(n, i);
21
173
  });
22
- } catch (t) {
23
- this.$emit("error", t);
174
+ },
175
+ updateCallbacks(t) {
176
+ this.widget && (this.widget.options.callbacks = t);
177
+ },
178
+ destroy() {
179
+ this.widget && typeof this.widget.destroy == "function" && (this.widget.destroy(), this.widget = null);
24
180
  }
25
181
  },
26
182
  beforeUnmount() {
27
- var t, e;
28
- (e = (t = this.widget) == null ? void 0 : t.destroy) == null || e.call(t);
183
+ this.reinitTimeout && clearTimeout(this.reinitTimeout), this.widget && typeof this.widget.destroy == "function" && this.widget.destroy();
29
184
  }
30
- }, d = { ref: "container" };
31
- function f(t, e, o, r, n, _) {
32
- return i(), c("div", d, null, 512);
185
+ }, h = { ref: "container" };
186
+ function l(t, e, i, n, o, c) {
187
+ return d(), r("div", h, null, 512);
33
188
  }
34
- const l = /* @__PURE__ */ p(a, [["render", f]]);
189
+ const g = /* @__PURE__ */ a(u, [["render", l]]);
35
190
  export {
36
- l as default
191
+ g as default
37
192
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(t,o){typeof exports=="object"&&typeof module<"u"?module.exports=o(require("@getspot/spot-widget"),require("vue")):typeof define=="function"&&define.amd?define(["@getspot/spot-widget","vue"],o):(t=typeof globalThis<"u"?globalThis:t||self,t.VueSpotWidget=o(t.SpotWidget,t.Vue))})(this,function(t,o){"use strict";const d=(e,n)=>{const i=e.__vccOpts||e;for(const[s,r]of n)i[s]=r;return i},p={name:"VueSpotWidget",props:{options:{type:Object,default:()=>({})}},mounted(){try{this.widget=new t({...this.options,location:this.$refs.container})}catch(e){this.$emit("error",e)}},beforeUnmount(){var e,n;(n=(e=this.widget)==null?void 0:e.destroy)==null||n.call(e)}},c={ref:"container"};function u(e,n,i,s,r,_){return o.openBlock(),o.createElementBlock("div",c,null,512)}return d(p,[["render",u]])});
1
+ (function(n,o){typeof exports=="object"&&typeof module<"u"?module.exports=o(require("@getspot/spot-widget"),require("vue")):typeof define=="function"&&define.amd?define(["@getspot/spot-widget","vue"],o):(n=typeof globalThis<"u"?globalThis:n||self,n.VueSpotWidget=o(n.SpotWidget,n.Vue))})(this,function(n,o){"use strict";const r=(t,e)=>{const i=t.__vccOpts||t;for(const[s,d]of e)i[s]=d;return i},u={name:"VueSpotWidget",props:{apiConfig:{type:Object,default:void 0},quoteRequestData:{type:Object,default:void 0},showTable:{type:Boolean,default:!0},optInSelected:{type:Boolean,default:!1},theme:{type:Object,default:void 0},callbacks:{type:Object,default:()=>({})},onQuoteRetrieved:{type:Function,default:void 0},onOptIn:{type:Function,default:void 0},onOptOut:{type:Function,default:void 0},onError:{type:Function,default:void 0},onNoMatchingQuote:{type:Function,default:void 0},onSelectionChange:{type:Function,default:void 0},options:{type:Object,default:()=>({})}},data(){return{widget:null,reinitTimeout:null}},computed:{mergedCallbacks(){return{...this.callbacks,...this.onQuoteRetrieved&&{onQuoteRetrieved:this.onQuoteRetrieved},...this.onOptIn&&{onOptIn:t=>{var e,i;(e=this.onOptIn)==null||e.call(this,t),(i=this.onSelectionChange)==null||i.call(this,t)}},...this.onOptOut&&{onOptOut:t=>{var e,i;(e=this.onOptOut)==null||e.call(this,t),(i=this.onSelectionChange)==null||i.call(this,t)}},...this.onError&&{onError:this.onError},...this.onNoMatchingQuote&&{onNoMatchingQuote:this.onNoMatchingQuote}}},widgetOptions(){return{apiConfig:this.apiConfig,quoteRequestData:this.quoteRequestData,showTable:this.showTable,optInSelected:this.optInSelected,theme:this.theme,callbacks:this.mergedCallbacks,...this.options}}},mounted(){this.initializeWidget()},watch:{quoteRequestData:{handler(t,e){this.widget&&t&&JSON.stringify(t)!==JSON.stringify(e)&&(this.reinitTimeout&&clearTimeout(this.reinitTimeout),this.reinitTimeout=setTimeout(()=>{this.reinitializeWidget(),this.reinitTimeout=null},100))},deep:!0},apiConfig:{handler(){this.reinitializeWidget()},deep:!0},showTable(t,e){t!==e&&this.reinitializeWidget()},optInSelected(t,e){t!==e&&this.reinitializeWidget()},theme:{handler(t,e){this.widget&&JSON.stringify(t)!==JSON.stringify(e)&&this.updateTheme(t)},deep:!0},mergedCallbacks:{handler(t,e){this.widget&&JSON.stringify(t)!==JSON.stringify(e)&&this.updateCallbacks(t)},deep:!0}},methods:{initializeWidget(){this.widget&&(this.widget.destroy(),this.widget=null),this.$refs.container&&(this.$refs.container.innerHTML=""),this.$nextTick(()=>{var t;try{this.widget=new n({...this.widgetOptions,location:this.$refs.container})}catch(e){this.$emit("error",e),(t=this.onError)==null||t.call(this,e)}})},reinitializeWidget(){this.widget&&(this.widget.destroy(),this.widget=null),this.initializeWidget()},async updateQuote(t){var e;return(e=this.widget)==null?void 0:e.updateQuote(t)},getSelection(){var t;return(t=this.widget)==null?void 0:t.getSelection()},validateSelection(){var t;return(t=this.widget)==null?void 0:t.validateSelection()},updateTheme(t){!this.widget||!this.widget.container||Object.entries(t||{}).forEach(([e,i])=>{const s=`--${e}`;this.widget.container.style.setProperty(s,i)})},updateCallbacks(t){this.widget&&(this.widget.options.callbacks=t)},destroy(){this.widget&&typeof this.widget.destroy=="function"&&(this.widget.destroy(),this.widget=null)}},beforeUnmount(){this.reinitTimeout&&clearTimeout(this.reinitTimeout),this.widget&&typeof this.widget.destroy=="function"&&this.widget.destroy()}},h={ref:"container"};function a(t,e,i,s,d,c){return o.openBlock(),o.createElementBlock("div",h,null,512)}return r(u,[["render",a]])});
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@getspot/spot-widget-vue",
3
- "version": "0.2.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.2.0"
10
+ "@getspot/spot-widget": "1.0.0"
11
11
  },
12
12
  "peerDependencies": {
13
13
  "vue": "^3.0.0"
@@ -8,23 +8,220 @@ import SpotWidget from "@getspot/spot-widget";
8
8
  export default {
9
9
  name: "VueSpotWidget",
10
10
  props: {
11
+ apiConfig: {
12
+ type: Object,
13
+ default: undefined,
14
+ },
15
+ quoteRequestData: {
16
+ type: Object,
17
+ default: undefined,
18
+ },
19
+ showTable: {
20
+ type: Boolean,
21
+ default: true,
22
+ },
23
+ optInSelected: {
24
+ type: Boolean,
25
+ default: false,
26
+ },
27
+ theme: {
28
+ type: Object,
29
+ default: undefined,
30
+ },
31
+ callbacks: {
32
+ type: Object,
33
+ default: () => ({}),
34
+ },
35
+ onQuoteRetrieved: {
36
+ type: Function,
37
+ default: undefined,
38
+ },
39
+ onOptIn: {
40
+ type: Function,
41
+ default: undefined,
42
+ },
43
+ onOptOut: {
44
+ type: Function,
45
+ default: undefined,
46
+ },
47
+ onError: {
48
+ type: Function,
49
+ default: undefined,
50
+ },
51
+ onNoMatchingQuote: {
52
+ type: Function,
53
+ default: undefined,
54
+ },
55
+ onSelectionChange: {
56
+ type: Function,
57
+ default: undefined,
58
+ },
11
59
  options: {
12
60
  type: Object,
13
61
  default: () => ({}),
14
62
  },
15
63
  },
16
- mounted() {
17
- try {
18
- this.widget = new SpotWidget({
64
+ data() {
65
+ return {
66
+ widget: null,
67
+ reinitTimeout: null,
68
+ };
69
+ },
70
+ computed: {
71
+ mergedCallbacks() {
72
+ return {
73
+ ...this.callbacks,
74
+ ...(this.onQuoteRetrieved && { onQuoteRetrieved: this.onQuoteRetrieved }),
75
+ ...(this.onOptIn && {
76
+ onOptIn: (data) => {
77
+ this.onOptIn?.(data);
78
+ this.onSelectionChange?.(data);
79
+ }
80
+ }),
81
+ ...(this.onOptOut && {
82
+ onOptOut: (data) => {
83
+ this.onOptOut?.(data);
84
+ this.onSelectionChange?.(data);
85
+ }
86
+ }),
87
+ ...(this.onError && { onError: this.onError }),
88
+ ...(this.onNoMatchingQuote && { onNoMatchingQuote: this.onNoMatchingQuote }),
89
+ };
90
+ },
91
+ widgetOptions() {
92
+ return {
93
+ apiConfig: this.apiConfig,
94
+ quoteRequestData: this.quoteRequestData,
95
+ showTable: this.showTable,
96
+ optInSelected: this.optInSelected,
97
+ theme: this.theme,
98
+ callbacks: this.mergedCallbacks,
19
99
  ...this.options,
20
- location: this.$refs.container,
100
+ };
101
+ },
102
+ },
103
+ mounted() {
104
+ this.initializeWidget();
105
+ },
106
+ watch: {
107
+ quoteRequestData: {
108
+ handler(newQuoteRequestData, oldQuoteRequestData) {
109
+ if (this.widget && newQuoteRequestData && JSON.stringify(newQuoteRequestData) !== JSON.stringify(oldQuoteRequestData)) {
110
+ // Debounce reinitialize to prevent multiple rapid updates
111
+ if (this.reinitTimeout) {
112
+ clearTimeout(this.reinitTimeout);
113
+ }
114
+
115
+ this.reinitTimeout = setTimeout(() => {
116
+ this.reinitializeWidget();
117
+ this.reinitTimeout = null;
118
+ }, 100);
119
+ }
120
+ },
121
+ deep: true,
122
+ },
123
+ apiConfig: {
124
+ handler() {
125
+ this.reinitializeWidget();
126
+ },
127
+ deep: true,
128
+ },
129
+ showTable(newVal, oldVal) {
130
+ if (newVal !== oldVal) {
131
+ this.reinitializeWidget();
132
+ }
133
+ },
134
+ optInSelected(newVal, oldVal) {
135
+ if (newVal !== oldVal) {
136
+ this.reinitializeWidget();
137
+ }
138
+ },
139
+ theme: {
140
+ handler(newTheme, oldTheme) {
141
+ if (this.widget && JSON.stringify(newTheme) !== JSON.stringify(oldTheme)) {
142
+ this.updateTheme(newTheme);
143
+ }
144
+ },
145
+ deep: true,
146
+ },
147
+ mergedCallbacks: {
148
+ handler(newCallbacks, oldCallbacks) {
149
+ if (this.widget && JSON.stringify(newCallbacks) !== JSON.stringify(oldCallbacks)) {
150
+ this.updateCallbacks(newCallbacks);
151
+ }
152
+ },
153
+ deep: true,
154
+ },
155
+ },
156
+ methods: {
157
+ initializeWidget() {
158
+ // Destroy any existing widget first
159
+ if (this.widget) {
160
+ this.widget.destroy();
161
+ this.widget = null;
162
+ }
163
+
164
+ // Clear the container completely
165
+ if (this.$refs.container) {
166
+ this.$refs.container.innerHTML = '';
167
+ }
168
+
169
+ // Add a small delay to ensure DOM is ready
170
+ this.$nextTick(() => {
171
+ try {
172
+ this.widget = new SpotWidget({
173
+ ...this.widgetOptions,
174
+ location: this.$refs.container,
175
+ });
176
+ } catch (err) {
177
+ this.$emit("error", err);
178
+ this.onError?.(err);
179
+ }
21
180
  });
22
- } catch (err) {
23
- this.$emit("error", err);
24
- }
181
+ },
182
+ reinitializeWidget() {
183
+ if (this.widget) {
184
+ this.widget.destroy();
185
+ this.widget = null;
186
+ }
187
+ this.initializeWidget();
188
+ },
189
+ async updateQuote(newQuoteRequestData) {
190
+ return this.widget?.updateQuote(newQuoteRequestData);
191
+ },
192
+ getSelection() {
193
+ return this.widget?.getSelection();
194
+ },
195
+ validateSelection() {
196
+ return this.widget?.validateSelection();
197
+ },
198
+ updateTheme(newTheme) {
199
+ if (!this.widget || !this.widget.container) return;
200
+
201
+ Object.entries(newTheme || {}).forEach(([k, v]) => {
202
+ const cssVariable = `--${k}`;
203
+ this.widget.container.style.setProperty(cssVariable, v);
204
+ });
205
+ },
206
+ updateCallbacks(newCallbacks) {
207
+ if (!this.widget) return;
208
+
209
+ this.widget.options.callbacks = newCallbacks;
210
+ },
211
+ destroy() {
212
+ if (this.widget && typeof this.widget.destroy === "function") {
213
+ this.widget.destroy();
214
+ this.widget = null;
215
+ }
216
+ },
25
217
  },
26
218
  beforeUnmount() {
27
- this.widget?.destroy?.();
219
+ if (this.reinitTimeout) {
220
+ clearTimeout(this.reinitTimeout);
221
+ }
222
+ if (this.widget && typeof this.widget.destroy === "function") {
223
+ this.widget.destroy();
224
+ }
28
225
  },
29
226
  };
30
227
  </script>