@product7/feedback-sdk 1.6.6 → 1.6.8
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/feedback-sdk.js +480 -41
- package/dist/feedback-sdk.js.map +1 -1
- package/dist/feedback-sdk.min.js +1 -1
- package/dist/feedback-sdk.min.js.map +1 -1
- package/package.json +1 -1
- package/src/api/services/ChangelogService.js +1 -1
- package/src/api/services/HelpService.js +1 -1
- package/src/api/services/MessengerService.js +1 -1
- package/src/api/services/SurveyService.js +1 -1
- package/src/core/BaseAPIService.js +36 -4
- package/src/core/FeedbackSDK.js +60 -5
- package/src/styles/changelog.js +64 -0
- package/src/styles/feedback.js +65 -2
- package/src/styles/messengerCustomStyles.js +81 -1
- package/src/styles/survey.js +77 -0
- package/src/widgets/BaseWidget.js +25 -11
- package/src/widgets/ChangelogWidget.js +5 -5
- package/src/widgets/MessengerWidget.js +18 -3
- package/src/widgets/SurveyWidget.js +49 -10
- package/types/index.d.ts +7 -0
|
@@ -12,7 +12,7 @@ export class ChangelogWidget extends BaseWidget {
|
|
|
12
12
|
|
|
13
13
|
_render() {
|
|
14
14
|
const trigger = document.createElement('div');
|
|
15
|
-
trigger.className = `changelog-widget position-${this.options.position}`;
|
|
15
|
+
trigger.className = `changelog-widget position-${this.options.position} changelog-theme-${this.options.theme || 'light'}`;
|
|
16
16
|
trigger.innerHTML = `
|
|
17
17
|
<button class="changelog-trigger-btn" type="button" aria-label="View Updates">
|
|
18
18
|
<svg class="changelog-icon" width="18" height="18" viewBox="0 0 24 24" fill="currentColor">
|
|
@@ -88,12 +88,12 @@ export class ChangelogWidget extends BaseWidget {
|
|
|
88
88
|
|
|
89
89
|
_createModal() {
|
|
90
90
|
this.backdropElement = document.createElement('div');
|
|
91
|
-
this.backdropElement.className =
|
|
91
|
+
this.backdropElement.className = `changelog-modal-backdrop changelog-theme-${this.options.theme || 'light'}`;
|
|
92
92
|
document.body.appendChild(this.backdropElement);
|
|
93
93
|
this.backdropElement.addEventListener('click', () => this.closeModal());
|
|
94
94
|
|
|
95
95
|
this.modalElement = document.createElement('div');
|
|
96
|
-
this.modalElement.className =
|
|
96
|
+
this.modalElement.className = `changelog-modal changelog-theme-${this.options.theme || 'light'}`;
|
|
97
97
|
this.modalElement.innerHTML = `
|
|
98
98
|
<div class="changelog-modal-container">
|
|
99
99
|
<button class="changelog-modal-close" type="button" aria-label="Close"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256"><rect width="256" height="256" fill="none"/><line x1="200" y1="56" x2="56" y2="200" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/><line x1="200" y1="200" x2="56" y2="56" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/></svg></button>
|
|
@@ -231,14 +231,14 @@ export class ChangelogWidget extends BaseWidget {
|
|
|
231
231
|
|
|
232
232
|
_createListModal() {
|
|
233
233
|
this.listModalBackdropElement = document.createElement('div');
|
|
234
|
-
this.listModalBackdropElement.className =
|
|
234
|
+
this.listModalBackdropElement.className = `changelog-list-modal-backdrop changelog-theme-${this.options.theme || 'light'}`;
|
|
235
235
|
document.body.appendChild(this.listModalBackdropElement);
|
|
236
236
|
this.listModalBackdropElement.addEventListener('click', () =>
|
|
237
237
|
this.closeSidebar()
|
|
238
238
|
);
|
|
239
239
|
|
|
240
240
|
this.listModalElement = document.createElement('div');
|
|
241
|
-
this.listModalElement.className =
|
|
241
|
+
this.listModalElement.className = `changelog-list-modal changelog-theme-${this.options.theme || 'light'}`;
|
|
242
242
|
this.listModalElement.innerHTML = `
|
|
243
243
|
<div class="changelog-list-modal-container">
|
|
244
244
|
<div class="changelog-list-modal-header">
|
|
@@ -17,6 +17,19 @@ import { PreChatFormView } from './messenger/views/PreChatFormView.js';
|
|
|
17
17
|
export class MessengerWidget extends BaseWidget {
|
|
18
18
|
constructor(options) {
|
|
19
19
|
super({ ...options, type: 'messenger' });
|
|
20
|
+
const resolvedTheme = options.theme || 'light';
|
|
21
|
+
const hasExplicitTextColor = Object.prototype.hasOwnProperty.call(
|
|
22
|
+
options,
|
|
23
|
+
'textColor'
|
|
24
|
+
);
|
|
25
|
+
const hasExplicitBackgroundColor = Object.prototype.hasOwnProperty.call(
|
|
26
|
+
options,
|
|
27
|
+
'backgroundColor'
|
|
28
|
+
);
|
|
29
|
+
const defaultTextColor =
|
|
30
|
+
resolvedTheme === 'dark' ? '#E2E8F0' : '#1d1d1f';
|
|
31
|
+
const defaultBackgroundColor =
|
|
32
|
+
resolvedTheme === 'dark' ? '#0F172A' : '#ffffff';
|
|
20
33
|
|
|
21
34
|
const resolvedEnableChangelog =
|
|
22
35
|
typeof options.enableChangelog === 'boolean'
|
|
@@ -25,10 +38,12 @@ export class MessengerWidget extends BaseWidget {
|
|
|
25
38
|
|
|
26
39
|
this.messengerOptions = {
|
|
27
40
|
position: options.position || 'bottom-right',
|
|
28
|
-
theme:
|
|
41
|
+
theme: resolvedTheme,
|
|
29
42
|
primaryColor: options.primaryColor || '#155EEF',
|
|
30
|
-
textColor: options.textColor
|
|
31
|
-
backgroundColor:
|
|
43
|
+
textColor: hasExplicitTextColor ? options.textColor : defaultTextColor,
|
|
44
|
+
backgroundColor: hasExplicitBackgroundColor
|
|
45
|
+
? options.backgroundColor
|
|
46
|
+
: defaultBackgroundColor,
|
|
32
47
|
logoUrl: options.logoUrl || 'https://product7.io/p7logo.svg',
|
|
33
48
|
teamName: options.teamName || 'Support',
|
|
34
49
|
teamAvatars: options.teamAvatars || [],
|
|
@@ -8,6 +8,9 @@ export class SurveyWidget extends BaseWidget {
|
|
|
8
8
|
surveyId: options.surveyId || null,
|
|
9
9
|
surveyType: options.surveyType || 'nps',
|
|
10
10
|
position: options.position || 'bottom-right',
|
|
11
|
+
theme: options.theme || 'light',
|
|
12
|
+
enabled:
|
|
13
|
+
typeof options.enabled === 'boolean' ? options.enabled : undefined,
|
|
11
14
|
title: options.title || null,
|
|
12
15
|
description: options.description || null,
|
|
13
16
|
lowLabel: options.lowLabel || null,
|
|
@@ -50,6 +53,20 @@ export class SurveyWidget extends BaseWidget {
|
|
|
50
53
|
};
|
|
51
54
|
}
|
|
52
55
|
|
|
56
|
+
static removeDanglingElements() {
|
|
57
|
+
if (typeof document === 'undefined') return;
|
|
58
|
+
|
|
59
|
+
document
|
|
60
|
+
.querySelectorAll(
|
|
61
|
+
'.feedback-survey, .feedback-survey-backdrop, .feedback-survey-success'
|
|
62
|
+
)
|
|
63
|
+
.forEach((el) => {
|
|
64
|
+
if (el && el.parentNode) {
|
|
65
|
+
el.parentNode.removeChild(el);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
53
70
|
_render() {
|
|
54
71
|
const container = document.createElement('div');
|
|
55
72
|
container.className = 'feedback-survey-container';
|
|
@@ -61,6 +78,16 @@ export class SurveyWidget extends BaseWidget {
|
|
|
61
78
|
}
|
|
62
79
|
|
|
63
80
|
show() {
|
|
81
|
+
if (this.options.enabled === false || this.surveyOptions.enabled === false) {
|
|
82
|
+
this.sdk.eventBus.emit('survey:suppressed', {
|
|
83
|
+
widget: this,
|
|
84
|
+
surveyId: this.surveyOptions.surveyId,
|
|
85
|
+
reason: 'disabled',
|
|
86
|
+
});
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
SurveyWidget.removeDanglingElements();
|
|
64
91
|
this._renderSurvey();
|
|
65
92
|
this.surveyState.isVisible = true;
|
|
66
93
|
this.sdk.eventBus.emit('survey:shown', {
|
|
@@ -96,7 +123,7 @@ export class SurveyWidget extends BaseWidget {
|
|
|
96
123
|
|
|
97
124
|
if (this.surveyOptions.position === 'center') {
|
|
98
125
|
this.backdropElement = document.createElement('div');
|
|
99
|
-
this.backdropElement.className =
|
|
126
|
+
this.backdropElement.className = `feedback-survey-backdrop feedback-survey-backdrop-${this.surveyOptions.theme}`;
|
|
100
127
|
document.body.appendChild(this.backdropElement);
|
|
101
128
|
this.backdropElement.addEventListener('click', () =>
|
|
102
129
|
this._handleDismiss()
|
|
@@ -104,7 +131,7 @@ export class SurveyWidget extends BaseWidget {
|
|
|
104
131
|
}
|
|
105
132
|
|
|
106
133
|
this.surveyElement = document.createElement('div');
|
|
107
|
-
this.surveyElement.className = `feedback-survey feedback-survey-${this.surveyOptions.position}${
|
|
134
|
+
this.surveyElement.className = `feedback-survey feedback-survey-${this.surveyOptions.position} feedback-survey-theme-${this.surveyOptions.theme}${
|
|
108
135
|
showDescription && !showTitle
|
|
109
136
|
? ' feedback-survey-description-primary'
|
|
110
137
|
: ''
|
|
@@ -1124,7 +1151,7 @@ export class SurveyWidget extends BaseWidget {
|
|
|
1124
1151
|
}, 3000);
|
|
1125
1152
|
}
|
|
1126
1153
|
|
|
1127
|
-
_closeSurvey(resetState = true) {
|
|
1154
|
+
_closeSurvey(resetState = true, immediate = false) {
|
|
1128
1155
|
if (this._escapeHandler) {
|
|
1129
1156
|
document.removeEventListener('keydown', this._escapeHandler);
|
|
1130
1157
|
this._escapeHandler = null;
|
|
@@ -1139,21 +1166,33 @@ export class SurveyWidget extends BaseWidget {
|
|
|
1139
1166
|
this.surveyOptions.position === 'center'
|
|
1140
1167
|
? 'translate(-50%, -50%) scale(0.95)'
|
|
1141
1168
|
: 'translateY(20px)';
|
|
1142
|
-
|
|
1143
|
-
if (surveyEl
|
|
1169
|
+
if (immediate) {
|
|
1170
|
+
if (surveyEl.parentNode) {
|
|
1144
1171
|
surveyEl.parentNode.removeChild(surveyEl);
|
|
1145
1172
|
}
|
|
1146
|
-
}
|
|
1173
|
+
} else {
|
|
1174
|
+
setTimeout(() => {
|
|
1175
|
+
if (surveyEl && surveyEl.parentNode) {
|
|
1176
|
+
surveyEl.parentNode.removeChild(surveyEl);
|
|
1177
|
+
}
|
|
1178
|
+
}, 300);
|
|
1179
|
+
}
|
|
1147
1180
|
this.surveyElement = null;
|
|
1148
1181
|
}
|
|
1149
1182
|
|
|
1150
1183
|
if (backdropEl) {
|
|
1151
1184
|
backdropEl.style.opacity = '0';
|
|
1152
|
-
|
|
1153
|
-
if (backdropEl
|
|
1185
|
+
if (immediate) {
|
|
1186
|
+
if (backdropEl.parentNode) {
|
|
1154
1187
|
backdropEl.parentNode.removeChild(backdropEl);
|
|
1155
1188
|
}
|
|
1156
|
-
}
|
|
1189
|
+
} else {
|
|
1190
|
+
setTimeout(() => {
|
|
1191
|
+
if (backdropEl && backdropEl.parentNode) {
|
|
1192
|
+
backdropEl.parentNode.removeChild(backdropEl);
|
|
1193
|
+
}
|
|
1194
|
+
}, 300);
|
|
1195
|
+
}
|
|
1157
1196
|
this.backdropElement = null;
|
|
1158
1197
|
}
|
|
1159
1198
|
|
|
@@ -1171,7 +1210,7 @@ export class SurveyWidget extends BaseWidget {
|
|
|
1171
1210
|
}
|
|
1172
1211
|
|
|
1173
1212
|
destroy() {
|
|
1174
|
-
this._closeSurvey();
|
|
1213
|
+
this._closeSurvey(true, true);
|
|
1175
1214
|
super.destroy();
|
|
1176
1215
|
}
|
|
1177
1216
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ declare module '@product7/feedback-sdk' {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export interface ButtonWidgetOptions {
|
|
31
|
+
enabled?: boolean;
|
|
31
32
|
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
32
33
|
theme?: 'light' | 'dark';
|
|
33
34
|
boardId?: string;
|
|
@@ -78,6 +79,9 @@ declare module '@product7/feedback-sdk' {
|
|
|
78
79
|
config?: any;
|
|
79
80
|
sessionToken?: string;
|
|
80
81
|
expiresIn?: number;
|
|
82
|
+
status?: boolean;
|
|
83
|
+
message?: string | null;
|
|
84
|
+
configVersion?: number | null;
|
|
81
85
|
}>;
|
|
82
86
|
createWidget(type: 'button', options?: ButtonWidgetOptions): ButtonWidget;
|
|
83
87
|
createWidget(type: 'survey', options?: SurveyWidgetOptions): SurveyWidget;
|
|
@@ -152,6 +156,7 @@ declare module '@product7/feedback-sdk' {
|
|
|
152
156
|
}
|
|
153
157
|
|
|
154
158
|
export interface SurveyWidgetOptions {
|
|
159
|
+
enabled?: boolean;
|
|
155
160
|
surveyId?: string | null;
|
|
156
161
|
surveyType?: SurveyType;
|
|
157
162
|
position?: 'bottom-right' | 'bottom-left' | 'center' | 'bottom';
|
|
@@ -225,6 +230,7 @@ declare module '@product7/feedback-sdk' {
|
|
|
225
230
|
}
|
|
226
231
|
|
|
227
232
|
export interface ChangelogWidgetOptions {
|
|
233
|
+
enabled?: boolean;
|
|
228
234
|
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
229
235
|
theme?: 'light' | 'dark';
|
|
230
236
|
triggerText?: string;
|
|
@@ -254,6 +260,7 @@ declare module '@product7/feedback-sdk' {
|
|
|
254
260
|
}
|
|
255
261
|
|
|
256
262
|
export interface MessengerWidgetOptions {
|
|
263
|
+
enabled?: boolean;
|
|
257
264
|
position?: 'bottom-right' | 'bottom-left';
|
|
258
265
|
theme?: 'light' | 'dark';
|
|
259
266
|
teamName?: string;
|