surveysparrow-ionic-plugin 2.0.1 → 2.0.2-beta.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.
- package/dist/angular-ui/esm2022/spotchecks/SpotCheckComponent.mjs +80 -51
- package/dist/angular-ui/esm2022/spotchecks/SpotCheckEventListener.mjs +26 -0
- package/dist/angular-ui/esm2022/spotchecks/api.mjs +1 -1
- package/dist/angular-ui/esm2022/spotchecks/helpers.mjs +6 -3
- package/dist/angular-ui/esm2022/spotchecks/index.mjs +2 -1
- package/dist/angular-ui/fesm2022/angular-ui.mjs +109 -54
- package/dist/angular-ui/fesm2022/angular-ui.mjs.map +1 -1
- package/dist/angular-ui/spotchecks/SpotCheckComponent.d.ts +10 -4
- package/dist/angular-ui/spotchecks/SpotCheckEventListener.d.ts +16 -0
- package/dist/angular-ui/spotchecks/index.d.ts +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheckComponent.d.ts +10 -4
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheckComponent.js +75 -48
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheckComponent.js.map +1 -1
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheckEventListener.d.ts +16 -0
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheckEventListener.js +28 -0
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheckEventListener.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/api.js.map +1 -1
- package/dist/esm/angular-ui/lib/spotchecks/helpers.js +5 -2
- package/dist/esm/angular-ui/lib/spotchecks/helpers.js.map +1 -1
- package/dist/esm/angular-ui/lib/spotchecks/index.d.ts +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/index.js +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/index.js.map +1 -1
- package/dist/plugin.cjs.js +103 -44
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +103 -44
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
- package/src/angular-ui/lib/spotchecks/SpotCheckComponent.ts +75 -44
- package/src/angular-ui/lib/spotchecks/SpotCheckEventListener.ts +50 -0
- package/src/angular-ui/lib/spotchecks/api.ts +2 -2
- package/src/angular-ui/lib/spotchecks/helpers.ts +6 -4
- package/src/angular-ui/lib/spotchecks/index.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "surveysparrow-ionic-plugin",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2-beta.2",
|
|
4
4
|
"description": "SurveySparrow SDK enables you to collect feedback from your mobile app. Embed the Classic, Chat & NPS surveys in your ionic application seamlessly with few lines of code.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/plugin.cjs.js",
|
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
ElementRef,
|
|
8
8
|
AfterViewInit,
|
|
9
9
|
HostListener,
|
|
10
|
+
NgZone,
|
|
11
|
+
ChangeDetectorRef,
|
|
10
12
|
} from '@angular/core';
|
|
11
13
|
import { CommonModule } from '@angular/common';
|
|
12
14
|
import { Subscription } from 'rxjs';
|
|
@@ -15,6 +17,7 @@ import { closeSpotCheck, closeSpotCheckAndHandleSurveyEnd, getSpotcheckComponent
|
|
|
15
17
|
import { SpotcheckState } from './types';
|
|
16
18
|
import { getSpotcheckStateService } from './helpers';
|
|
17
19
|
import { SpotcheckStateService } from './SpotcheckStateService';
|
|
20
|
+
import { getSpotCheckEventListener } from './SpotCheckEventListener';
|
|
18
21
|
import axios from 'axios';
|
|
19
22
|
|
|
20
23
|
@Component({
|
|
@@ -42,7 +45,11 @@ export class WebViewComponent implements OnInit, AfterViewInit {
|
|
|
42
45
|
safeUrl: SafeResourceUrl | null = null;
|
|
43
46
|
@ViewChild('iframeRef') iframe!: ElementRef<HTMLIFrameElement>;
|
|
44
47
|
|
|
45
|
-
constructor(
|
|
48
|
+
constructor(
|
|
49
|
+
private sanitizer: DomSanitizer,
|
|
50
|
+
private ngZone: NgZone,
|
|
51
|
+
private cdr: ChangeDetectorRef,
|
|
52
|
+
) {}
|
|
46
53
|
ngOnInit() {
|
|
47
54
|
if (this.url) {
|
|
48
55
|
this.safeUrl = this.sanitizer.bypassSecurityTrustResourceUrl(this.url);
|
|
@@ -70,50 +77,57 @@ export class WebViewComponent implements OnInit, AfterViewInit {
|
|
|
70
77
|
private setupIframeLoadListener() {
|
|
71
78
|
const iframe = this.iframe.nativeElement;
|
|
72
79
|
iframe.addEventListener('load', () => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
80
|
+
this.ngZone.run(() => {
|
|
81
|
+
const stateService = getSpotcheckStateService();
|
|
82
|
+
if (this.webviewType === 'classic') {
|
|
83
|
+
stateService.setState({ isClassicLoading: false });
|
|
84
|
+
} else {
|
|
85
|
+
stateService.setState({ isChatLoading: false });
|
|
86
|
+
}
|
|
87
|
+
});
|
|
79
88
|
});
|
|
80
89
|
}
|
|
81
90
|
|
|
82
91
|
@HostListener('window:message', ['$event'])
|
|
83
92
|
onMessage(event: MessageEvent) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
93
|
+
this.ngZone.run(() => {
|
|
94
|
+
const stateService = getSpotcheckStateService();
|
|
95
|
+
const { data } = event;
|
|
96
|
+
switch (data.type) {
|
|
97
|
+
case 'slideInFrame':
|
|
98
|
+
if (data.mounted) {
|
|
99
|
+
stateService.setState({ isMounted: true });
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
92
102
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
case 'resizeWindow':
|
|
104
|
+
if (data.size) {
|
|
105
|
+
stateService.setState({
|
|
106
|
+
currentQuestionHeight: data.size.height,
|
|
107
|
+
});
|
|
108
|
+
} else if (data.isCloseButtonEnabled) {
|
|
109
|
+
stateService.setState({
|
|
110
|
+
isCloseButtonEnabled: data.isCloseButtonEnabled,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
break;
|
|
104
114
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
115
|
+
case 'surveyCompleted':
|
|
116
|
+
closeSpotCheckAndHandleSurveyEnd().then(() => {
|
|
117
|
+
getSpotCheckEventListener().emit('surveyCompleted', data.response);
|
|
118
|
+
this.cdr.detectChanges();
|
|
119
|
+
});
|
|
120
|
+
break;
|
|
109
121
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
122
|
+
case 'surveyLoadStarted':
|
|
123
|
+
getSpotCheckEventListener().emit('surveyLoadStarted', data.surveyDetails);
|
|
124
|
+
break;
|
|
113
125
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
126
|
+
default:
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
this.cdr.detectChanges();
|
|
130
|
+
});
|
|
117
131
|
}
|
|
118
132
|
}
|
|
119
133
|
|
|
@@ -170,15 +184,21 @@ export class CloseButtonComponent implements OnDestroy {
|
|
|
170
184
|
isMiniCard: boolean = false;
|
|
171
185
|
stroke: string = 'black';
|
|
172
186
|
|
|
173
|
-
constructor(
|
|
187
|
+
constructor(
|
|
188
|
+
private ngZone: NgZone,
|
|
189
|
+
private cdr: ChangeDetectorRef,
|
|
190
|
+
) {
|
|
174
191
|
this.stateService = getSpotcheckStateService();
|
|
175
192
|
this.state = this.stateService.getState();
|
|
176
193
|
this.updateComponentState();
|
|
177
194
|
|
|
178
195
|
this.stateSubscription = this.stateService.state$.subscribe(
|
|
179
196
|
(newState: SpotcheckState) => {
|
|
180
|
-
this.
|
|
181
|
-
|
|
197
|
+
this.ngZone.run(() => {
|
|
198
|
+
this.state = newState;
|
|
199
|
+
this.updateComponentState();
|
|
200
|
+
this.cdr.detectChanges();
|
|
201
|
+
});
|
|
182
202
|
}
|
|
183
203
|
);
|
|
184
204
|
}
|
|
@@ -205,6 +225,9 @@ export class CloseButtonComponent implements OnDestroy {
|
|
|
205
225
|
onClick = async () => {
|
|
206
226
|
await closeSpotCheck();
|
|
207
227
|
handleSurveyEnd();
|
|
228
|
+
this.ngZone.run(() => {
|
|
229
|
+
this.cdr.detectChanges();
|
|
230
|
+
});
|
|
208
231
|
};
|
|
209
232
|
}
|
|
210
233
|
|
|
@@ -223,16 +246,22 @@ export class SpotCheckComponent implements OnInit, OnDestroy {
|
|
|
223
246
|
componentStyles: any = {};
|
|
224
247
|
avatarUrl: string = '';
|
|
225
248
|
|
|
226
|
-
constructor(
|
|
249
|
+
constructor(
|
|
250
|
+
private ngZone: NgZone,
|
|
251
|
+
private cdr: ChangeDetectorRef,
|
|
252
|
+
) {
|
|
227
253
|
this.spotcheckStateService = getSpotcheckStateService();
|
|
228
254
|
this.state = this.spotcheckStateService.getState();
|
|
229
255
|
this.updateComponentStyles();
|
|
230
256
|
|
|
231
257
|
this.stateSubscription = this.spotcheckStateService.state$.subscribe(
|
|
232
258
|
(newState: SpotcheckState) => {
|
|
233
|
-
this.
|
|
234
|
-
|
|
235
|
-
|
|
259
|
+
this.ngZone.run(() => {
|
|
260
|
+
this.state = newState;
|
|
261
|
+
this.updateComponentStyles();
|
|
262
|
+
this.avatarUrl = this.state.avatarUrl || "https://static.surveysparrow.com/application/images/profile.png";
|
|
263
|
+
this.cdr.detectChanges();
|
|
264
|
+
});
|
|
236
265
|
}
|
|
237
266
|
);
|
|
238
267
|
}
|
|
@@ -255,9 +284,11 @@ export class SpotCheckComponent implements OnInit, OnDestroy {
|
|
|
255
284
|
try {
|
|
256
285
|
const domainName = this.state.domainName;
|
|
257
286
|
const targetToken = this.state.targetToken;
|
|
258
|
-
|
|
287
|
+
|
|
288
|
+
const response = await axios.get<any>(
|
|
259
289
|
`https://${domainName}/api/internal/spotcheck/widget/${targetToken}/init`
|
|
260
290
|
);
|
|
291
|
+
|
|
261
292
|
const data = response.data;
|
|
262
293
|
|
|
263
294
|
if (data.filteredSpotChecks && data.filteredSpotChecks.length > 0) {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Subject } from 'rxjs';
|
|
2
|
+
import type { Subscription } from 'rxjs';
|
|
3
|
+
|
|
4
|
+
export type SpotCheckEventType =
|
|
5
|
+
| 'surveyCompleted'
|
|
6
|
+
| 'surveyDismissed'
|
|
7
|
+
| 'surveyLoadStarted';
|
|
8
|
+
|
|
9
|
+
export interface SpotCheckEvent {
|
|
10
|
+
type: SpotCheckEventType;
|
|
11
|
+
data?: any;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type EventCallback = (data?: any) => void;
|
|
15
|
+
|
|
16
|
+
class SpotCheckEventListenerService {
|
|
17
|
+
private eventSubject = new Subject<SpotCheckEvent>();
|
|
18
|
+
private event$ = this.eventSubject.asObservable();
|
|
19
|
+
|
|
20
|
+
emit(type: SpotCheckEventType, data?: any): void {
|
|
21
|
+
this.eventSubject.next({ type, data });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
addListener(
|
|
25
|
+
eventType: SpotCheckEventType,
|
|
26
|
+
callback: EventCallback
|
|
27
|
+
): Subscription {
|
|
28
|
+
return this.event$.subscribe((event: SpotCheckEvent) => {
|
|
29
|
+
if (event.type === eventType) {
|
|
30
|
+
callback(event.data);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let globalInstance: SpotCheckEventListenerService;
|
|
37
|
+
|
|
38
|
+
export const getSpotCheckEventListener = (): SpotCheckEventListenerService => {
|
|
39
|
+
if (!globalInstance) {
|
|
40
|
+
globalInstance = new SpotCheckEventListenerService();
|
|
41
|
+
}
|
|
42
|
+
return globalInstance;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const addSpotCheckListener = (
|
|
46
|
+
eventType: SpotCheckEventType,
|
|
47
|
+
callback: EventCallback
|
|
48
|
+
): Subscription => {
|
|
49
|
+
return getSpotCheckEventListener().addListener(eventType, callback);
|
|
50
|
+
};
|
|
@@ -65,7 +65,7 @@ export const sendTrackScreenRequest = async ({
|
|
|
65
65
|
};
|
|
66
66
|
|
|
67
67
|
const url = `https://${state.domainName}/api/internal/spotcheck/widget/${state.targetToken}/properties?isSpotCheck=true&sdk=IONIC`;
|
|
68
|
-
const response = await axios.post(url, payload, {
|
|
68
|
+
const response = await axios.post<any>(url, payload, {
|
|
69
69
|
headers: {
|
|
70
70
|
'Content-Type': 'application/json',
|
|
71
71
|
},
|
|
@@ -212,7 +212,7 @@ export const sendTrackEventRequest = async ({ screen, event }: TrackEventProps)
|
|
|
212
212
|
const url = `https://${state.domainName}/api/internal/spotcheck/widget/${state.targetToken}/eventTrigger?isSpotCheck=true`;
|
|
213
213
|
|
|
214
214
|
try {
|
|
215
|
-
const response = await axios.post(url, payload, {
|
|
215
|
+
const response = await axios.post<any>(url, payload, {
|
|
216
216
|
headers: {
|
|
217
217
|
'Content-Type': 'application/json',
|
|
218
218
|
},
|
|
@@ -3,6 +3,7 @@ import { Device } from '@capacitor/device';
|
|
|
3
3
|
import { SpotcheckState } from './types';
|
|
4
4
|
import axios from 'axios';
|
|
5
5
|
import { SpotcheckStateService } from './SpotcheckStateService';
|
|
6
|
+
import { getSpotCheckEventListener } from './SpotCheckEventListener';
|
|
6
7
|
|
|
7
8
|
let globalSpotcheckStateService: SpotcheckStateService;
|
|
8
9
|
|
|
@@ -120,7 +121,7 @@ export const setAppearance = async (
|
|
|
120
121
|
spotcheckStateService.setState(updatedState);
|
|
121
122
|
|
|
122
123
|
try {
|
|
123
|
-
const response = await axios.get(fullSpotcheckURL);
|
|
124
|
+
const response = await axios.get<any>(fullSpotcheckURL);
|
|
124
125
|
const themeInfo = response.data.config.generatedCSS;
|
|
125
126
|
const theme_payload = { type: 'THEME_UPDATE_SPOTCHECK', themeInfo };
|
|
126
127
|
state = spotcheckStateService.getState();
|
|
@@ -256,8 +257,10 @@ export const closeSpotCheck = async () => {
|
|
|
256
257
|
body: JSON.stringify(payload),
|
|
257
258
|
}
|
|
258
259
|
);
|
|
259
|
-
|
|
260
|
-
|
|
260
|
+
if(response.status == 200) {
|
|
261
|
+
getSpotCheckEventListener().emit('surveyDismissed');
|
|
262
|
+
}
|
|
263
|
+
else{
|
|
261
264
|
console.log(`Error: ${response.status}`);
|
|
262
265
|
}
|
|
263
266
|
} catch (error) {
|
|
@@ -396,6 +399,5 @@ export const getSpotcheckComponentCssStyles = (state: SpotcheckState) => {
|
|
|
396
399
|
};
|
|
397
400
|
|
|
398
401
|
export const closeSpotCheckAndHandleSurveyEnd = async () => {
|
|
399
|
-
await closeSpotCheck();
|
|
400
402
|
handleSurveyEnd();
|
|
401
403
|
};
|