@product7/product7-js 0.3.2 → 0.3.5

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.
@@ -92,6 +92,7 @@ export class SurveyWidget extends BaseWidget {
92
92
 
93
93
  SurveyWidget.removeDanglingElements();
94
94
  this._renderSurvey();
95
+ this.state.isOpen = true;
95
96
  this.surveyState.isVisible = true;
96
97
  this.sdk.eventBus.emit('survey:shown', {
97
98
  widget: this,
@@ -101,6 +102,7 @@ export class SurveyWidget extends BaseWidget {
101
102
  }
102
103
 
103
104
  hide() {
105
+ this.state.isOpen = false;
104
106
  this._closeSurvey();
105
107
  return this;
106
108
  }
@@ -175,6 +177,7 @@ export class SurveyWidget extends BaseWidget {
175
177
  this._attachSurveyEvents();
176
178
 
177
179
  requestAnimationFrame(() => {
180
+ if (!this.surveyElement) return;
178
181
  this.surveyElement.style.opacity = '1';
179
182
  this.surveyElement.style.transform =
180
183
  this.surveyOptions.position === 'center'
@@ -1312,6 +1315,7 @@ export class SurveyWidget extends BaseWidget {
1312
1315
  }
1313
1316
 
1314
1317
  _closeSurvey(resetState = true, immediate = false) {
1318
+ this.state.isOpen = false;
1315
1319
  if (this._escapeHandler) {
1316
1320
  document.removeEventListener('keydown', this._escapeHandler);
1317
1321
  this._escapeHandler = null;
@@ -1374,6 +1378,22 @@ export class SurveyWidget extends BaseWidget {
1374
1378
  this.sdk.eventBus.emit('survey:closed', { widget: this });
1375
1379
  }
1376
1380
 
1381
+ open() {
1382
+ return this.show();
1383
+ }
1384
+
1385
+ close() {
1386
+ return this.hide();
1387
+ }
1388
+
1389
+ toggle() {
1390
+ if (this.surveyState.isVisible) {
1391
+ return this.hide();
1392
+ }
1393
+
1394
+ return this.show();
1395
+ }
1396
+
1377
1397
  destroy() {
1378
1398
  this._closeSurvey(true, true);
1379
1399
  super.destroy();
@@ -21,7 +21,9 @@ export class ChatView {
21
21
 
22
22
  this._unsubscribe = this.state.subscribe((type, data) => {
23
23
  if (type === 'connectionChange') {
24
- const banner = this.element?.querySelector('.messenger-connection-banner');
24
+ const banner = this.element?.querySelector(
25
+ '.messenger-connection-banner'
26
+ );
25
27
  if (banner) {
26
28
  banner.style.display = data.connected ? 'none' : 'flex';
27
29
  }
@@ -71,9 +73,10 @@ export class ChatView {
71
73
  ? this._renderEmptyState(isNewConversation)
72
74
  : this._renderGroupedMessages(messages);
73
75
 
74
- const defaultPlaceholder = this.options.composePlaceholder || 'Write a message...';
76
+ const defaultPlaceholder =
77
+ this.options.composePlaceholder || 'Write a message...';
75
78
  const placeholder = isNewConversation
76
- ? (this.options.composePlaceholder || 'Start typing your message...')
79
+ ? this.options.composePlaceholder || 'Start typing your message...'
77
80
  : isClosed
78
81
  ? 'Conversation closed'
79
82
  : defaultPlaceholder;
@@ -94,7 +97,7 @@ export class ChatView {
94
97
  </div>
95
98
  <div class="messenger-chat-header-info">
96
99
  <span class="messenger-chat-title">${this._escapeHtml(teamName)}</span>
97
- <span class="messenger-chat-subtitle">${isClosed ? 'Conversation resolved' : (this.state.responseTime || 'Typically replies within minutes')}</span>
100
+ <span class="messenger-chat-subtitle">${isClosed ? 'Conversation resolved' : this.state.responseTime || 'Typically replies within minutes'}</span>
98
101
  </div>
99
102
  <div class="messenger-chat-header-actions">
100
103
  <button class="sdk-btn-icon sdk-close-btn messenger-mobile-close-btn" aria-label="Close">
@@ -211,7 +214,9 @@ export class ChatView {
211
214
  const messageClass = isOwn
212
215
  ? 'messenger-message-own'
213
216
  : 'messenger-message-received';
214
- const timeStr = isLastInGroup ? this._formatMessageTime(message.timestamp) : '';
217
+ const timeStr = isLastInGroup
218
+ ? this._formatMessageTime(message.timestamp)
219
+ : '';
215
220
  const attachmentsHtml = this._renderMessageAttachments(message.attachments);
216
221
  const isOptimistic = message.isOptimistic;
217
222
 
@@ -225,9 +230,10 @@ export class ChatView {
225
230
  if (isOwn) {
226
231
  const sentIndicator = isLastInGroup
227
232
  ? `<div class="messenger-message-meta messenger-message-meta-own">
228
- ${isOptimistic
229
- ? `<span class="messenger-message-sent-status">Sending…</span>`
230
- : `<span class="messenger-message-sent-status">Sent</span>`
233
+ ${
234
+ isOptimistic
235
+ ? `<span class="messenger-message-sent-status">Sending…</span>`
236
+ : `<span class="messenger-message-sent-status">Sent</span>`
231
237
  }
232
238
  ${timeStr ? `<span>·</span><span>${timeStr}</span>` : ''}
233
239
  </div>`
@@ -137,7 +137,8 @@ export class HomeView {
137
137
  const title = conversation.title || teamName;
138
138
  const timeAgo = this._formatTimeAgo(conversation.lastMessageTime);
139
139
  const preview = conversation.lastMessage
140
- ? conversation.lastMessage.substring(0, 48) + (conversation.lastMessage.length > 48 ? '...' : '')
140
+ ? conversation.lastMessage.substring(0, 48) +
141
+ (conversation.lastMessage.length > 48 ? '...' : '')
141
142
  : '';
142
143
  const hasUnread = conversation.unread > 0;
143
144
 
@@ -253,7 +254,9 @@ export class HomeView {
253
254
  }
254
255
 
255
256
  _attachEvents() {
256
- const recentCard = this.element.querySelector('.messenger-home-recent-card');
257
+ const recentCard = this.element.querySelector(
258
+ '.messenger-home-recent-card'
259
+ );
257
260
  if (recentCard) {
258
261
  recentCard.addEventListener('click', () => {
259
262
  const convId = recentCard.dataset.conversationId;
package/types/index.d.ts CHANGED
@@ -19,11 +19,13 @@ declare module '@product7/product7-js' {
19
19
  user_id?: string;
20
20
  email?: string;
21
21
  name?: string;
22
+ profile_picture?: string;
22
23
  custom_fields?: Record<string, any>;
23
24
  company?: {
24
25
  id?: string;
25
26
  name?: string;
26
27
  monthly_spend?: number;
28
+ custom_fields?: Record<string, any>;
27
29
  };
28
30
  }
29
31
 
@@ -44,11 +46,15 @@ declare module '@product7/product7-js' {
44
46
  triggerText?: string;
45
47
  label?: string;
46
48
  text?: string;
49
+ headless?: boolean;
47
50
  customStyles?: Record<string, string>;
48
51
  trigger?: boolean | string | Element;
49
52
  }
50
53
 
54
+ export interface FeedbackWidgetOptions extends ButtonWidgetOptions {}
55
+
51
56
  export interface WidgetConfigMap {
57
+ feedback?: Partial<FeedbackWidgetOptions> | Record<string, any>;
52
58
  button?: Partial<ButtonWidgetOptions> | Record<string, any>;
53
59
  survey?: Partial<SurveyWidgetOptions> | Record<string, any>;
54
60
  messenger?: Partial<MessengerWidgetOptions> | Record<string, any>;
@@ -63,6 +69,9 @@ declare module '@product7/product7-js' {
63
69
  destroy(): void;
64
70
  show(): this;
65
71
  hide(): this;
72
+ open(): this;
73
+ close(): this;
74
+ toggle(): this;
66
75
  openPanel(): void;
67
76
  closePanel(): void;
68
77
  openModal(): void;
@@ -73,6 +82,8 @@ declare module '@product7/product7-js' {
73
82
  ): void;
74
83
  }
75
84
 
85
+ export interface FeedbackWidget extends ButtonWidget {}
86
+
76
87
  export class Product7 {
77
88
  constructor(config: FeedbackConfig);
78
89
  static create(config: FeedbackConfig): Product7;
@@ -84,7 +95,21 @@ declare module '@product7/product7-js' {
84
95
  status?: boolean;
85
96
  message?: string | null;
86
97
  configVersion?: number | null;
98
+ identified?: boolean;
99
+ }>;
100
+ identify(metadata: Metadata): Promise<{
101
+ identified: boolean;
102
+ metadata: Metadata | null;
103
+ response: any;
87
104
  }>;
105
+ createFeedbackWidget(options?: FeedbackWidgetOptions): FeedbackWidget;
106
+ createMessengerWidget(options?: MessengerWidgetOptions): MessengerWidget;
107
+ createChangelogWidget(options?: ChangelogWidgetOptions): ChangelogWidget;
108
+ createSurveyWidget(options?: SurveyWidgetOptions): SurveyWidget;
109
+ createWidget(
110
+ type: 'feedback',
111
+ options?: FeedbackWidgetOptions
112
+ ): FeedbackWidget;
88
113
  createWidget(type: 'button', options?: ButtonWidgetOptions): ButtonWidget;
89
114
  createWidget(type: 'survey', options?: SurveyWidgetOptions): SurveyWidget;
90
115
  createWidget(
@@ -182,8 +207,12 @@ declare module '@product7/product7-js' {
182
207
  }
183
208
 
184
209
  export interface SurveyWidget {
210
+ mount(container?: string | HTMLElement): this;
185
211
  show(): this;
186
212
  hide(): this;
213
+ open(): this;
214
+ close(): this;
215
+ toggle(): this;
187
216
  destroy(): void;
188
217
  surveyOptions: SurveyWidgetOptions;
189
218
  surveyState: {
@@ -235,6 +264,7 @@ declare module '@product7/product7-js' {
235
264
  enabled?: boolean;
236
265
  position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
237
266
  theme?: 'light' | 'dark';
267
+ headless?: boolean;
238
268
  showBackdrop?: boolean;
239
269
  triggerText?: string;
240
270
  showBadge?: boolean;
@@ -251,6 +281,9 @@ declare module '@product7/product7-js' {
251
281
  type: 'changelog';
252
282
  mount(container?: string | HTMLElement): this;
253
283
  destroy(): void;
284
+ open(): this;
285
+ close(): this;
286
+ toggle(): this;
254
287
  openModal(): void;
255
288
  closeModal(): void;
256
289
  openSidebar(): void;
@@ -266,6 +299,7 @@ declare module '@product7/product7-js' {
266
299
  enabled?: boolean;
267
300
  position?: 'bottom-right' | 'bottom-left';
268
301
  theme?: 'light' | 'dark';
302
+ headless?: boolean;
269
303
  teamName?: string;
270
304
  teamAvatars?: string[];
271
305
  greetingMessage?: string;