@product7/product7-js 0.5.1 → 0.5.4
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/README.md +4 -4
- package/dist/README.md +4 -4
- package/dist/product7-js.js +7124 -7130
- package/dist/product7-js.js.map +1 -1
- package/dist/product7-js.min.js +1 -1
- package/dist/product7-js.min.js.map +1 -1
- package/package.json +1 -1
- package/src/api/APIService.js +1 -0
- package/src/api/services/{MessengerService.js → WebChatService.js} +15 -15
- package/src/core/APIService.js +16 -16
- package/src/core/Product7.js +4 -4
- package/src/core/WebSocketService.js +3 -3
- package/src/docs/api.md +9 -9
- package/src/docs/example.md +12 -12
- package/src/docs/framework-integrations.md +5 -5
- package/src/index.js +41 -42
- package/src/styles/base.js +9 -9
- package/src/styles/design-tokens.js +2 -2
- package/src/styles/feedback.js +2 -2
- package/src/styles/styles.js +4 -4
- package/src/styles/survey.js +3 -2
- package/src/styles/{messenger-components.js → web-chat-components.js} +114 -114
- package/src/styles/{messenger-core.js → web-chat-core.js} +32 -32
- package/src/styles/{messenger-features.js → web-chat-features.js} +20 -20
- package/src/styles/{messenger-views.js → web-chat-views.js} +137 -137
- package/src/styles/web-chat.js +17 -0
- package/src/styles/{messengerCustomStyles.js → webChatCustomStyles.js} +17 -19
- package/src/widgets/SurveyWidget.js +6 -1
- package/src/widgets/{MessengerWidget.js → WebChatWidget.js} +169 -172
- package/src/widgets/WidgetFactory.js +3 -3
- package/src/widgets/{messenger/MessengerState.js → web-chat/WebChatState.js} +1 -1
- package/src/widgets/{messenger → web-chat}/components/NavigationTabs.js +13 -13
- package/src/widgets/{messenger/components/MessengerLauncher.js → web-chat/components/WebChatLauncher.js} +15 -17
- package/src/widgets/{messenger/components/MessengerPanel.js → web-chat/components/WebChatPanel.js} +11 -11
- package/src/widgets/{messenger → web-chat}/views/ChangelogView.js +17 -17
- package/src/widgets/{messenger → web-chat}/views/ChatView.js +97 -99
- package/src/widgets/{messenger → web-chat}/views/ConversationsView.js +24 -24
- package/src/widgets/{messenger → web-chat}/views/HelpView.js +29 -29
- package/src/widgets/{messenger → web-chat}/views/HomeView.js +53 -55
- package/src/widgets/{messenger → web-chat}/views/PreChatFormView.js +17 -17
- package/src/styles/messenger.js +0 -17
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { SDKError } from '../utils/errors.js';
|
|
1
|
+
import { SDKError } from '../utils/errors.js';
|
|
2
2
|
import { ButtonWidget } from './ButtonWidget.js';
|
|
3
3
|
import { ChangelogWidget } from './ChangelogWidget.js';
|
|
4
4
|
import { InlineWidget } from './InlineWidget.js';
|
|
5
|
-
import { MessengerWidget } from './MessengerWidget.js';
|
|
6
5
|
import { SurveyWidget } from './SurveyWidget.js';
|
|
7
6
|
import { TabWidget } from './TabWidget.js';
|
|
7
|
+
import { WebChatWidget } from './WebChatWidget.js';
|
|
8
8
|
|
|
9
9
|
export class WidgetFactory {
|
|
10
10
|
static widgets = new Map([
|
|
@@ -12,7 +12,7 @@ export class WidgetFactory {
|
|
|
12
12
|
['tab', TabWidget],
|
|
13
13
|
['inline', InlineWidget],
|
|
14
14
|
['survey', SurveyWidget],
|
|
15
|
-
['
|
|
15
|
+
['webChat', WebChatWidget],
|
|
16
16
|
['changelog', ChangelogWidget],
|
|
17
17
|
]);
|
|
18
18
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export class NavigationTabs {
|
|
1
|
+
export class NavigationTabs {
|
|
2
2
|
constructor(state, options = {}) {
|
|
3
3
|
this.state = state;
|
|
4
4
|
this.options = options;
|
|
@@ -8,7 +8,7 @@ export class NavigationTabs {
|
|
|
8
8
|
|
|
9
9
|
render() {
|
|
10
10
|
this.element = document.createElement('div');
|
|
11
|
-
this.element.className = '
|
|
11
|
+
this.element.className = 'web-chat-panel-nav';
|
|
12
12
|
|
|
13
13
|
this._updateContent();
|
|
14
14
|
this._attachEvents();
|
|
@@ -55,15 +55,15 @@ export class NavigationTabs {
|
|
|
55
55
|
const isActive = this.state.currentView === tab.id;
|
|
56
56
|
const badgeHtml =
|
|
57
57
|
tab.badge && tab.badge > 0
|
|
58
|
-
? `<span class="
|
|
58
|
+
? `<span class="web-chat-nav-badge">${tab.badge > 9 ? '9+' : tab.badge}</span>`
|
|
59
59
|
: '';
|
|
60
60
|
|
|
61
61
|
return `
|
|
62
|
-
<button class="
|
|
63
|
-
<span class="
|
|
62
|
+
<button class="web-chat-nav-tab ${isActive ? 'active' : ''}" data-tab="${tab.id}">
|
|
63
|
+
<span class="web-chat-nav-icon">
|
|
64
64
|
<iconify-icon icon="${tab.icon}" width="22" height="22"></iconify-icon>
|
|
65
65
|
</span>
|
|
66
|
-
<span class="
|
|
66
|
+
<span class="web-chat-nav-label">${tab.label}</span>
|
|
67
67
|
${badgeHtml}
|
|
68
68
|
</button>
|
|
69
69
|
`;
|
|
@@ -71,11 +71,11 @@ export class NavigationTabs {
|
|
|
71
71
|
.join('');
|
|
72
72
|
|
|
73
73
|
this.element.innerHTML = `
|
|
74
|
-
<div class="
|
|
74
|
+
<div class="web-chat-nav-tabs">
|
|
75
75
|
${tabsHtml}
|
|
76
76
|
</div>
|
|
77
|
-
<div class="
|
|
78
|
-
<a href="https://product7.io" target="_blank" rel="noopener noreferrer" class="
|
|
77
|
+
<div class="web-chat-nav-footer">
|
|
78
|
+
<a href="https://product7.io" target="_blank" rel="noopener noreferrer" class="web-chat-powered-by">
|
|
79
79
|
<svg width="12" height="14" viewBox="0 0 28 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
80
80
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M15.0615 5.28044C8.5161 4.42949 3.30825 11.1456 5.89967 17.6588C6.9321 20.2538 9.06268 22.2644 11.8777 23.1968C16.2682 24.6507 18.4038 22.3222 19.0483 23.9691C19.4055 24.8894 18.7282 25.3209 17.988 25.4938C10.9146 27.15 5.15304 22.7566 3.5869 17.5531C1.52205 10.6941 5.98684 4.6667 11.3483 3.41065C17.8801 1.88094 24.0325 6.19355 24.3926 12.7175C24.7448 19.0921 18.6217 24.5978 11.927 22.2036C10.8789 21.8285 8.8419 20.6682 8.46823 19.858C8.06026 18.9727 8.80261 18.1725 9.68285 18.3576C10.2223 18.4726 10.3116 18.8706 11.3161 19.5372C14.4549 21.6213 19.1276 20.6132 21.2046 17.0972C23.991 12.3817 21.0481 6.05351 15.06 5.27758L15.0615 5.28044Z" fill="#21244A"/>
|
|
81
81
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M15.2492 2.19833C11.944 1.71463 8.88819 3.07214 6.91479 4.49682C2.27067 7.85488 0.76169 14.5038 3.49672 19.8731C4.08535 21.0096 4.84379 22.0497 5.7459 22.9576L7.16343 24.2515C7.67214 24.9131 7.27203 25.7176 6.64115 25.9269C5.13502 26.4271 2.0499 21.8172 1.42044 20.5383C0.0872204 17.8297 -0.312889 14.9047 0.242977 11.503C1.66908 2.77063 11.221 -2.51652 19.7197 1.21021C27.7548 4.73331 30.2733 15.4555 23.9351 22.0773C23.3107 22.7296 21.6352 24.4823 20.6278 23.8907C20.0076 23.5263 19.8933 22.6446 20.5192 22.1238C21.0301 21.6986 21.4759 21.435 21.9896 20.9734C23.6665 19.4688 25.2562 16.8752 25.3477 13.5636C25.4427 10.2055 24.1266 7.5848 22.3904 5.74859C20.6392 3.89665 18.6751 2.69919 15.2456 2.19691L15.2492 2.19833Z" fill="#F69F06"/>
|
|
@@ -90,7 +90,7 @@ export class NavigationTabs {
|
|
|
90
90
|
|
|
91
91
|
_attachEvents() {
|
|
92
92
|
this.element.addEventListener('click', (e) => {
|
|
93
|
-
const tab = e.target.closest('.
|
|
93
|
+
const tab = e.target.closest('.web-chat-nav-tab');
|
|
94
94
|
if (tab) {
|
|
95
95
|
const tabId = tab.dataset.tab;
|
|
96
96
|
this.state.setView(tabId);
|
|
@@ -99,18 +99,18 @@ export class NavigationTabs {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
_updateActiveTab() {
|
|
102
|
-
const tabs = this.element.querySelectorAll('.
|
|
102
|
+
const tabs = this.element.querySelectorAll('.web-chat-nav-tab');
|
|
103
103
|
tabs.forEach((tab) => {
|
|
104
104
|
const isActive = tab.dataset.tab === this.state.currentView;
|
|
105
105
|
tab.classList.toggle('active', isActive);
|
|
106
106
|
|
|
107
107
|
if (tab.dataset.tab === 'messages') {
|
|
108
|
-
const existingBadge = tab.querySelector('.
|
|
108
|
+
const existingBadge = tab.querySelector('.web-chat-nav-badge');
|
|
109
109
|
if (existingBadge) existingBadge.remove();
|
|
110
110
|
|
|
111
111
|
if (this.state.unreadCount > 0) {
|
|
112
112
|
const badge = document.createElement('span');
|
|
113
|
-
badge.className = '
|
|
113
|
+
badge.className = 'web-chat-nav-badge';
|
|
114
114
|
badge.textContent =
|
|
115
115
|
this.state.unreadCount > 9 ? '9+' : this.state.unreadCount;
|
|
116
116
|
tab.appendChild(badge);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export class
|
|
1
|
+
export class WebChatLauncher {
|
|
2
2
|
constructor(state, options = {}) {
|
|
3
3
|
this.state = state;
|
|
4
4
|
this.options = {
|
|
@@ -12,7 +12,7 @@ export class MessengerLauncher {
|
|
|
12
12
|
|
|
13
13
|
render() {
|
|
14
14
|
this.element = document.createElement('div');
|
|
15
|
-
this.element.className = `
|
|
15
|
+
this.element.className = `web-chat-launcher web-chat-launcher-${this.options.position}`;
|
|
16
16
|
|
|
17
17
|
this._updateContent();
|
|
18
18
|
this._attachEvents();
|
|
@@ -32,22 +32,22 @@ export class MessengerLauncher {
|
|
|
32
32
|
_updateContent() {
|
|
33
33
|
const badgeHtml =
|
|
34
34
|
this.state.unreadCount > 0
|
|
35
|
-
? `<span class="
|
|
35
|
+
? `<span class="web-chat-launcher-badge">${this.state.unreadCount > 9 ? '9+' : this.state.unreadCount}</span>`
|
|
36
36
|
: '';
|
|
37
37
|
|
|
38
38
|
this.element.innerHTML = `
|
|
39
|
-
<button class="
|
|
40
|
-
<span class="
|
|
39
|
+
<button class="web-chat-launcher-btn" aria-label="Open web chat">
|
|
40
|
+
<span class="web-chat-launcher-icon web-chat-launcher-icon-chat">
|
|
41
41
|
<iconify-icon icon="ph:chats-circle-duotone" width="24" height="24"></iconify-icon>
|
|
42
42
|
</span>
|
|
43
|
-
<span class="
|
|
43
|
+
<span class="web-chat-launcher-icon web-chat-launcher-icon-close" style="display: none;">
|
|
44
44
|
<iconify-icon icon="ph:caret-down-bold" width="22" height="22"></iconify-icon>
|
|
45
45
|
</span>
|
|
46
46
|
${badgeHtml}
|
|
47
47
|
</button>
|
|
48
48
|
`;
|
|
49
49
|
|
|
50
|
-
const btn = this.element.querySelector('.
|
|
50
|
+
const btn = this.element.querySelector('.web-chat-launcher-btn');
|
|
51
51
|
if (btn && this.options.primaryColor) {
|
|
52
52
|
btn.style.setProperty(
|
|
53
53
|
'background',
|
|
@@ -59,34 +59,32 @@ export class MessengerLauncher {
|
|
|
59
59
|
|
|
60
60
|
_attachEvents() {
|
|
61
61
|
this.element
|
|
62
|
-
.querySelector('.
|
|
62
|
+
.querySelector('.web-chat-launcher-btn')
|
|
63
63
|
.addEventListener('click', () => {
|
|
64
64
|
this.state.setOpen(!this.state.isOpen);
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
_updateIcon() {
|
|
69
|
-
const chatIcon = this.element.querySelector(
|
|
70
|
-
'.messenger-launcher-icon-chat'
|
|
71
|
-
);
|
|
69
|
+
const chatIcon = this.element.querySelector('.web-chat-launcher-icon-chat');
|
|
72
70
|
const closeIcon = this.element.querySelector(
|
|
73
|
-
'.
|
|
71
|
+
'.web-chat-launcher-icon-close'
|
|
74
72
|
);
|
|
75
73
|
|
|
76
74
|
if (this.state.isOpen) {
|
|
77
75
|
chatIcon.style.display = 'none';
|
|
78
76
|
closeIcon.style.display = 'flex';
|
|
79
|
-
this.element.classList.add('
|
|
77
|
+
this.element.classList.add('web-chat-launcher-open');
|
|
80
78
|
} else {
|
|
81
79
|
chatIcon.style.display = 'flex';
|
|
82
80
|
closeIcon.style.display = 'none';
|
|
83
|
-
this.element.classList.remove('
|
|
81
|
+
this.element.classList.remove('web-chat-launcher-open');
|
|
84
82
|
}
|
|
85
83
|
}
|
|
86
84
|
|
|
87
85
|
_updateBadge() {
|
|
88
86
|
const existingBadge = this.element.querySelector(
|
|
89
|
-
'.
|
|
87
|
+
'.web-chat-launcher-badge'
|
|
90
88
|
);
|
|
91
89
|
if (existingBadge) {
|
|
92
90
|
existingBadge.remove();
|
|
@@ -94,10 +92,10 @@ export class MessengerLauncher {
|
|
|
94
92
|
|
|
95
93
|
if (this.state.unreadCount > 0 && !this.state.isOpen) {
|
|
96
94
|
const badge = document.createElement('span');
|
|
97
|
-
badge.className = '
|
|
95
|
+
badge.className = 'web-chat-launcher-badge';
|
|
98
96
|
badge.textContent =
|
|
99
97
|
this.state.unreadCount > 9 ? '9+' : this.state.unreadCount;
|
|
100
|
-
this.element.querySelector('.
|
|
98
|
+
this.element.querySelector('.web-chat-launcher-btn').appendChild(badge);
|
|
101
99
|
}
|
|
102
100
|
}
|
|
103
101
|
|
package/src/widgets/{messenger/components/MessengerPanel.js → web-chat/components/WebChatPanel.js}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { NavigationTabs } from './NavigationTabs.js';
|
|
1
|
+
import { NavigationTabs } from './NavigationTabs.js';
|
|
2
2
|
|
|
3
|
-
export class
|
|
3
|
+
export class WebChatPanel {
|
|
4
4
|
constructor(state, options = {}) {
|
|
5
5
|
this.state = state;
|
|
6
6
|
this.options = {
|
|
@@ -20,17 +20,17 @@ export class MessengerPanel {
|
|
|
20
20
|
|
|
21
21
|
render() {
|
|
22
22
|
this.element = document.createElement('div');
|
|
23
|
-
this.element.className = `
|
|
23
|
+
this.element.className = `web-chat-panel web-chat-panel-${this.options.position}`;
|
|
24
24
|
|
|
25
25
|
this.element.innerHTML = `
|
|
26
|
-
<div class="
|
|
27
|
-
<div class="
|
|
28
|
-
<div class="
|
|
26
|
+
<div class="web-chat-panel-content">
|
|
27
|
+
<div class="web-chat-panel-views"></div>
|
|
28
|
+
<div class="web-chat-panel-nav"></div>
|
|
29
29
|
</div>
|
|
30
30
|
`;
|
|
31
31
|
|
|
32
32
|
this.navigationTabs = new NavigationTabs(this.state, this.options);
|
|
33
|
-
const navContainer = this.element.querySelector('.
|
|
33
|
+
const navContainer = this.element.querySelector('.web-chat-panel-nav');
|
|
34
34
|
navContainer.appendChild(this.navigationTabs.render());
|
|
35
35
|
|
|
36
36
|
this._renderCurrentView();
|
|
@@ -45,8 +45,8 @@ export class MessengerPanel {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
_renderCurrentView() {
|
|
48
|
-
const viewsContainer = this.element.querySelector('.
|
|
49
|
-
const navContainer = this.element.querySelector('.
|
|
48
|
+
const viewsContainer = this.element.querySelector('.web-chat-panel-views');
|
|
49
|
+
const navContainer = this.element.querySelector('.web-chat-panel-nav');
|
|
50
50
|
|
|
51
51
|
if (this.currentViewComponent && this.currentViewComponent.destroy) {
|
|
52
52
|
this.currentViewComponent.destroy();
|
|
@@ -59,7 +59,7 @@ export class MessengerPanel {
|
|
|
59
59
|
this.currentViewComponent = new ViewClass(this.state, this.options);
|
|
60
60
|
viewsContainer.appendChild(this.currentViewComponent.render());
|
|
61
61
|
} else {
|
|
62
|
-
viewsContainer.innerHTML = `<div class="
|
|
62
|
+
viewsContainer.innerHTML = `<div class="web-chat-empty-state">
|
|
63
63
|
<p>View not found: ${this.state.currentView}</p>
|
|
64
64
|
</div>`;
|
|
65
65
|
}
|
|
@@ -88,7 +88,7 @@ export class MessengerPanel {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
setHeader(headerContent) {
|
|
91
|
-
const header = this.element.querySelector('.
|
|
91
|
+
const header = this.element.querySelector('.web-chat-panel-header');
|
|
92
92
|
if (header) {
|
|
93
93
|
header.innerHTML = headerContent;
|
|
94
94
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export class ChangelogView {
|
|
1
|
+
export class ChangelogView {
|
|
2
2
|
constructor(state, options = {}) {
|
|
3
3
|
this.state = state;
|
|
4
4
|
this.options = options;
|
|
@@ -11,7 +11,7 @@ export class ChangelogView {
|
|
|
11
11
|
|
|
12
12
|
render() {
|
|
13
13
|
this.element = document.createElement('div');
|
|
14
|
-
this.element.className = '
|
|
14
|
+
this.element.className = 'web-chat-view web-chat-changelog-view';
|
|
15
15
|
|
|
16
16
|
this._updateContent();
|
|
17
17
|
|
|
@@ -26,17 +26,17 @@ export class ChangelogView {
|
|
|
26
26
|
|
|
27
27
|
_updateContent() {
|
|
28
28
|
this.element.innerHTML = `
|
|
29
|
-
<div class="
|
|
30
|
-
<div class="
|
|
29
|
+
<div class="web-chat-changelog-header">
|
|
30
|
+
<div class="web-chat-changelog-header-top">
|
|
31
31
|
<h2>Latest Updates</h2>
|
|
32
|
-
<button class="sdk-close-btn
|
|
32
|
+
<button class="sdk-close-btn web-chat-changelog-close-btn web-chat-mobile-close-btn" aria-label="Close">
|
|
33
33
|
<iconify-icon icon="ph:x" width="18" height="18"></iconify-icon>
|
|
34
34
|
</button>
|
|
35
35
|
</div>
|
|
36
36
|
</div>
|
|
37
37
|
|
|
38
|
-
<div class="
|
|
39
|
-
<div class="
|
|
38
|
+
<div class="web-chat-changelog-body">
|
|
39
|
+
<div class="web-chat-changelog-list"></div>
|
|
40
40
|
</div>
|
|
41
41
|
`;
|
|
42
42
|
|
|
@@ -46,7 +46,7 @@ export class ChangelogView {
|
|
|
46
46
|
|
|
47
47
|
_updateChangelogList() {
|
|
48
48
|
const changelogContainer = this.element.querySelector(
|
|
49
|
-
'.
|
|
49
|
+
'.web-chat-changelog-list'
|
|
50
50
|
);
|
|
51
51
|
const changelogItems = this.state.changelogItems;
|
|
52
52
|
|
|
@@ -71,11 +71,11 @@ export class ChangelogView {
|
|
|
71
71
|
|
|
72
72
|
_renderChangelogCard(item) {
|
|
73
73
|
return `
|
|
74
|
-
<div class="
|
|
75
|
-
${item.coverImage ? `<div class="
|
|
76
|
-
<div class="
|
|
77
|
-
<h3 class="
|
|
78
|
-
${item.description ? `<p class="
|
|
74
|
+
<div class="web-chat-changelog-card" data-changelog-id="${item.id}">
|
|
75
|
+
${item.coverImage ? `<div class="web-chat-changelog-thumb"><img src="${item.coverImage}" alt="${item.title}" onerror="this.parentElement.style.display='none';" /></div>` : ''}
|
|
76
|
+
<div class="web-chat-changelog-content">
|
|
77
|
+
<h3 class="web-chat-changelog-title">${item.title}</h3>
|
|
78
|
+
${item.description ? `<p class="web-chat-changelog-description">${this._stripHtml(item.description)}</p>` : ''}
|
|
79
79
|
</div>
|
|
80
80
|
</div>
|
|
81
81
|
`;
|
|
@@ -92,8 +92,8 @@ export class ChangelogView {
|
|
|
92
92
|
|
|
93
93
|
_renderEmptyState() {
|
|
94
94
|
return `
|
|
95
|
-
<div class="
|
|
96
|
-
<div class="
|
|
95
|
+
<div class="web-chat-empty-state">
|
|
96
|
+
<div class="web-chat-empty-state-icon">
|
|
97
97
|
<iconify-icon icon="ph:megaphone-duotone" width="48" height="48"></iconify-icon>
|
|
98
98
|
</div>
|
|
99
99
|
<h3>No changelog yet</h3>
|
|
@@ -120,7 +120,7 @@ export class ChangelogView {
|
|
|
120
120
|
|
|
121
121
|
_attachEvents() {
|
|
122
122
|
const mobileCloseBtn = this.element.querySelector(
|
|
123
|
-
'.
|
|
123
|
+
'.web-chat-changelog-close-btn'
|
|
124
124
|
);
|
|
125
125
|
if (mobileCloseBtn) {
|
|
126
126
|
mobileCloseBtn.addEventListener('click', () => {
|
|
@@ -133,7 +133,7 @@ export class ChangelogView {
|
|
|
133
133
|
|
|
134
134
|
_attachChangelogEvents() {
|
|
135
135
|
this.element
|
|
136
|
-
.querySelectorAll('.
|
|
136
|
+
.querySelectorAll('.web-chat-changelog-card')
|
|
137
137
|
.forEach((card) => {
|
|
138
138
|
card.addEventListener('click', () => {
|
|
139
139
|
const changelogId = card.dataset.changelogId;
|