@subiz/widget-v4 4.1.63 → 4.1.67

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.
Files changed (59) hide show
  1. package/assets/less/widget.less +3 -0
  2. package/compiled_src/chatbox/TextMessage.js +1 -1
  3. package/compiled_src/chatbox/Widget.js +58 -28
  4. package/compiled_src/chatbox/main.js +1 -0
  5. package/compiled_src/lib.js +8 -1
  6. package/compiled_src/store/api.js +17 -0
  7. package/compiled_src/store/api_fake.js +1 -0
  8. package/compiled_src/store/store.js +9 -28
  9. package/dist/132.js +6432 -2567
  10. package/dist/{278.js → 178.js} +55 -55
  11. package/dist/18a02a9c54e.132.js +1 -0
  12. package/dist/18a02a9c54e.178.js +1 -0
  13. package/dist/18a02a9c54e.213.js +1 -0
  14. package/dist/18a02a9c54e.335.js +1 -0
  15. package/dist/18a02a9c54e.362.js +1 -0
  16. package/dist/18a02a9c54e.441.js +1 -0
  17. package/dist/18a02a9c54e.605.js +1 -0
  18. package/dist/18a02a9c54e.678.js +1 -0
  19. package/dist/18a02a9c54e.782.js +1 -0
  20. package/dist/18a02a9c54e.app.js +1 -0
  21. package/dist/{18dd22fb422.index.html → 18a02a9c54e.index.html} +4 -4
  22. package/dist/{18dd22fb422.library.html → 18a02a9c54e.library.html} +4 -4
  23. package/dist/18a02a9c54e.library.js +1 -0
  24. package/dist/{18dd22fb422.preview.html → 18a02a9c54e.preview.html} +1 -1
  25. package/dist/18a02a9c54e.preview.js +1 -0
  26. package/dist/18a02a9c54e.screenshoot.js +1 -0
  27. package/dist/18a02a9c54e.webview.js +1 -0
  28. package/dist/213.js +2780 -0
  29. package/dist/{74.js → 335.js} +34 -34
  30. package/dist/{459.js → 362.js} +7 -7
  31. package/dist/441.js +2855 -0
  32. package/dist/{490.js → 605.js} +60 -59
  33. package/dist/{997.js → 678.js} +6 -6
  34. package/dist/{27.js → 782.js} +7 -7
  35. package/dist/HASH +1 -1
  36. package/dist/malicious-app.js +4 -6
  37. package/dist/screenshoot.html +1 -1
  38. package/dist/screenshoot.js +691 -615
  39. package/package.json +4 -4
  40. package/src/chatbox/TextMessage.js +1 -1
  41. package/src/chatbox/Widget.js +6 -12
  42. package/src/chatbox/main.js +7 -2
  43. package/src/lib.js +10 -1
  44. package/src/store/api.js +1 -1
  45. package/src/store/store.js +5 -0
  46. package/dist/18dd22fb422.132.js +0 -1
  47. package/dist/18dd22fb422.27.js +0 -1
  48. package/dist/18dd22fb422.278.js +0 -1
  49. package/dist/18dd22fb422.459.js +0 -1
  50. package/dist/18dd22fb422.490.js +0 -1
  51. package/dist/18dd22fb422.497.js +0 -1
  52. package/dist/18dd22fb422.74.js +0 -1
  53. package/dist/18dd22fb422.997.js +0 -1
  54. package/dist/18dd22fb422.app.js +0 -1
  55. package/dist/18dd22fb422.library.js +0 -1
  56. package/dist/18dd22fb422.preview.js +0 -1
  57. package/dist/18dd22fb422.screenshoot.js +0 -1
  58. package/dist/18dd22fb422.webview.js +0 -1
  59. package/dist/497.js +0 -6685
@@ -37,6 +37,9 @@
37
37
  }
38
38
 
39
39
  .convo-list--footer {
40
+ display: flex;
41
+ flex-direction: column;
42
+ align-items: center;
40
43
  margin-top: @spacer3;
41
44
  }
42
45
 
@@ -144,7 +144,7 @@ function trimQuillDelta(delta) {
144
144
  if (!delta.ops || !delta.ops.length) return delta;
145
145
  let last = delta.ops[delta.ops.length - 1];
146
146
  if (typeof last.insert != 'string') return delta;
147
- let insert = last.insert.trim();
147
+ let insert = last.insert.trimEnd();
148
148
  if (insert) {
149
149
  if (last.insert != insert) {
150
150
  let newops = delta.ops.slice();
@@ -40,7 +40,11 @@ class Widget extends _common.Com {
40
40
  }
41
41
  let text = message.text;
42
42
  if (!this.props.cid) {
43
- this.creating = true;
43
+ this._creating = (this._creating || 0) + 1;
44
+ let _creating = this._creating;
45
+ this.setState({
46
+ creating: true
47
+ });
44
48
  const {
45
49
  convo,
46
50
  error
@@ -49,20 +53,27 @@ class Widget extends _common.Com {
49
53
  message: text,
50
54
  initial_by: this.props.store.matchUser().id
51
55
  });
56
+ if (_creating != this._creating) return;
52
57
  if (error) {}
53
- this.creating = false;
54
- this.props.store.sendConvoEvent(convo.id, 'message_sent', {
58
+ await this.props.store.sendConvoEvent(convo.id, 'message_sent', {
55
59
  message
56
60
  });
61
+ if (_creating != this._creating) return;
62
+ this.setState({
63
+ creating: false
64
+ });
57
65
  this.props.onGo({
58
66
  view: 'chat',
59
67
  cid: convo.id
60
68
  });
61
69
  return;
62
70
  }
63
- this.props.store.sendConvoEvent(this.props.cid, 'message_sent', {
71
+ await this.props.store.sendConvoEvent(this.props.cid, 'message_sent', {
64
72
  message
65
73
  });
74
+ this.setState({
75
+ creating: false
76
+ });
66
77
  });
67
78
  _defineProperty(this, "onLink", (e, url) => {
68
79
  if (!url) return e.preventDefault();
@@ -99,11 +110,13 @@ class Widget extends _common.Com {
99
110
  }
100
111
  componentDidMount() {
101
112
  if (!this.props.store.isMobile()) this.focusInput();
113
+ this.updateFormDataFields();
102
114
  }
103
115
  componentDidUpdate(prevProp) {
104
116
  if (prevProp.isShow !== this.props.isShow) {
105
117
  if (this.props.isShow && !this.props.store.isMobile()) this.focusInput();
106
118
  if (this.props.isShow && this.props.store.isMobile()) this.blur();
119
+ this.updateFormDataFields();
107
120
  }
108
121
  if (prevProp.cid !== this.props.cid) {
109
122
  this.closeOrder();
@@ -115,8 +128,8 @@ class Widget extends _common.Com {
115
128
  this.events && this.events.focus();
116
129
  if (!this.props.store.isMobile()) this.focusInput();
117
130
  }, 100);
131
+ this.updateFormDataFields();
118
132
  }
119
- this.updateFormDataFields();
120
133
  }
121
134
  shouldShowForm() {
122
135
  let form;
@@ -131,6 +144,7 @@ class Widget extends _common.Com {
131
144
  }
132
145
  render() {
133
146
  let showform = this.shouldShowForm();
147
+ let formName = '';
134
148
  let form;
135
149
  let accountSetting = this.props.plugin.chatbox || {};
136
150
  let acc = this.props.store.matchAccount() || {};
@@ -140,19 +154,22 @@ class Widget extends _common.Com {
140
154
  if (this.isOffline(acc, accountSetting) && offlineEnabled) {
141
155
  form = accountSetting.offline_form;
142
156
  submitLabel = this.props.t('offline_form_btn');
157
+ formName = 'offline';
143
158
  }
144
159
  if (this.props.view === 'offline_form') {
145
160
  showform = true;
146
161
  form = accountSetting.offline_form;
162
+ formName = 'offline';
147
163
  submitLabel = this.props.t('offline_form_btn');
148
164
  }
149
165
  if (this.props.view === 'prechat_form') {
150
166
  showform = true;
151
167
  form = accountSetting.prechat_form;
152
168
  submitLabel = this.props.t('prechat_form_btn');
169
+ formName = 'prechat';
153
170
  }
154
171
  let $body = null;
155
- if (this.props.view === 'list') $body = this.renderConvoList();else if (showform) $body = this.renderForm(form, submitLabel);else $body = this.renderChat();
172
+ if (this.props.view === 'list') $body = this.renderConvoList();else if (showform) $body = this.renderForm(form, submitLabel, formName);else $body = this.renderChat();
156
173
  let position = _index.default.get(accountSetting, 'desktop_button.position') || 'right';
157
174
  if (this.props.store.isMobile()) position = _index.default.get(accountSetting, 'mobile_button.position', position);
158
175
  let cls = 'widget-container widget-container--' + position;
@@ -172,7 +189,8 @@ class Widget extends _common.Com {
172
189
  })
173
190
  }), $body);
174
191
  }
175
- async submitPrechatForm(form) {
192
+ async submitPrechatForm(form, formName) {
193
+ if (this.state.submiting) return;
176
194
  var hasError = false;
177
195
  _index.default.map(this.state.formData, (field, key) => {
178
196
  if (field.is_required && (field.value === undefined || field.value === '' || _index.default.size(field.value) === 0 && Array.isArray(field.value))) {
@@ -210,8 +228,21 @@ class Widget extends _common.Com {
210
228
  });
211
229
  let firstmsg = _index.default.get(data, 'question.value');
212
230
  let groupid = _index.default.get(data, 'group.value', '');
231
+ this._creating = (this._creating || 0) + 1;
232
+ let _creating = this._creating;
233
+ this.setState({
234
+ creating: true
235
+ });
236
+ let formData = _index.default.map(data, (field, key) => {
237
+ return {
238
+ key: key,
239
+ type: field.type,
240
+ value: _index.default.stringify(field.value)
241
+ };
242
+ });
243
+ this.props.store.submitForm('chatbox_' + formName, formData, user);
244
+ if (_creating != this._creating) return;
213
245
  if (this.props.cid) {
214
- this.props.store.setUser(user);
215
246
  this.setState({
216
247
  clickedJoin: false
217
248
  });
@@ -226,15 +257,15 @@ class Widget extends _common.Com {
226
257
  attachments: this.state.quickReplyMessage.attachments
227
258
  }
228
259
  });
260
+ if (_creating != this._creating) return;
229
261
  this.setState({
262
+ creating: false,
230
263
  quickReplyMessage: {}
231
264
  });
232
265
  if (form.end_conversation_after_submit) await this.props.store.endConvo(this.props.cid);
266
+ if (_creating != this._creating) return;
233
267
  return;
234
268
  }
235
- this.setState({
236
- creating: true
237
- });
238
269
  let message = {
239
270
  text: firstmsg,
240
271
  format: 'plaintext'
@@ -248,11 +279,11 @@ class Widget extends _common.Com {
248
279
  this.setState({
249
280
  creatingError: null
250
281
  });
251
- await this.props.store.setUser(user);
252
282
  const {
253
283
  error,
254
284
  convo
255
285
  } = await this.props.store.startConvo(req);
286
+ if (_creating != this._creating) return;
256
287
  if (error) {
257
288
  this.setState({
258
289
  creating: false,
@@ -262,18 +293,19 @@ class Widget extends _common.Com {
262
293
  }
263
294
  let newconvoid = convo.id;
264
295
  this.userSent[newconvoid] = true;
265
- this.props.onGo({
266
- view: 'chat',
267
- cid: newconvoid
268
- });
269
- this.props.store.sendConvoEvent(newconvoid, 'message_sent', {
296
+ await this.props.store.sendConvoEvent(newconvoid, 'message_sent', {
270
297
  message
271
298
  });
299
+ if (_creating != this._creating) return;
272
300
  this.setState({
273
301
  creating: false,
274
302
  clickedJoin: false,
275
303
  quickReplyMessage: {}
276
304
  });
305
+ this.props.onGo({
306
+ view: 'chat',
307
+ cid: newconvoid
308
+ });
277
309
  if (!this.props.store.isMobile()) this.focusInput();
278
310
  }
279
311
  formMounted(form) {
@@ -455,6 +487,7 @@ class Widget extends _common.Com {
455
487
  },
456
488
  value: field.value || '',
457
489
  onInput: e => this.onInputChange(key, e.target.value),
490
+ onChange: e => this.onInputChange(key, e.target.value),
458
491
  row: "4",
459
492
  class: "form-control"
460
493
  });
@@ -462,6 +495,7 @@ class Widget extends _common.Com {
462
495
  $field = (0, _preact.h)("input", {
463
496
  value: field.value || '',
464
497
  onInput: e => this.onInputChange(key, e.target.value),
498
+ onChange: e => this.onInputChange(key, e.target.value),
465
499
  ref: ref => {
466
500
  this['form_' + encode(key)] = ref;
467
501
  },
@@ -540,7 +574,9 @@ class Widget extends _common.Com {
540
574
  label = field.label || this.props.t('your_question');
541
575
  }
542
576
  if (field.label) label = field.label;
543
- return (0, _preact.h)("div", null, (0, _preact.h)("div", {
577
+ return (0, _preact.h)("div", {
578
+ key: 'form_' + encode(key)
579
+ }, (0, _preact.h)("div", {
544
580
  class: "label"
545
581
  }, label, field.is_required ? (0, _preact.h)("span", {
546
582
  class: "ml-1 red"
@@ -552,14 +588,7 @@ class Widget extends _common.Com {
552
588
  class: "pt-2"
553
589
  }, $fields);
554
590
  }
555
- renderForm(form, submitLabel) {
556
- let $loading = null;
557
- if (this.state.creating) $loading = (0, _preact.h)("span", {
558
- class: "ml-2"
559
- }, (0, _preact.h)(_spinner.default, {
560
- size: "16",
561
- mode: "white"
562
- }));
591
+ renderForm(form, submitLabel, formName) {
563
592
  let title = this.props.t.i18n(_index.default.get(form, `i18n_title`, {}));
564
593
  if (!title) title = _index.default.get(form, 'title', this.props.t('capture_lead_title'));
565
594
  title = title.replace('↵', '');
@@ -581,8 +610,9 @@ class Widget extends _common.Com {
581
610
  class: "message-input message-input--preform"
582
611
  }, (0, _preact.h)("button", {
583
612
  class: "btn--start-convo",
584
- onClick: _ => this.submitPrechatForm(form)
585
- }, submitLabel, " ", $loading)));
613
+ onClick: _ => this.submitPrechatForm(form, formName),
614
+ disabled: this.state.creating
615
+ }, submitLabel)));
586
616
  }
587
617
  goToConvo(cid) {
588
618
  this.props.onGo({
@@ -172,6 +172,7 @@ class Main extends _common.Com {
172
172
  this.refButton.current && this.refButton.current.ClearPreview();
173
173
  this.props.store.setHasManuallyClosed();
174
174
  this.hideWidget();
175
+ this.props.store.emitCloseWidgetEvent();
175
176
  }
176
177
  }
177
178
  exports.default = Main;
@@ -33,7 +33,14 @@ class Widget {
33
33
  this.subs = [];
34
34
  this.store.onConvoEvent({
35
35
  _isMounted: true
36
- }, ev => _index.default.map(this.subs, sub => sub(ev)));
36
+ }, ev => _index.default.map(this.subs, sub => {
37
+ if (sub && typeof sub === 'function') sub(ev);
38
+ }));
39
+ this.store.onWidgetClose({
40
+ _isMounted: true
41
+ }, ev => _index.default.map(this.subs, sub => {
42
+ if (sub && typeof sub === 'function') sub(ev);
43
+ }));
37
44
  }
38
45
  async waitReady(cb) {
39
46
  await this.store.readyGate.entry();
@@ -40,6 +40,23 @@ class _default {
40
40
  _defineProperty(this, "getConversation", cid => this.apireq.get(`/accounts/${this.accid}/conversations/${cid}`));
41
41
  _defineProperty(this, "getLocaleContent", locale => this.apireq.get(`/accounts/${this.accid}/locales/${locale}`));
42
42
  _defineProperty(this, "sendEvent", data => this.apireq.addQuery('shorten', true).post(`/accounts/${this.accid}/users/${this.uid}/events`, data));
43
+ _defineProperty(this, "submitForm", (form_id, page_url, device, data, user) => this.apireq.post(`/accounts/${this.accid}/users/${this.uid}/events`, {
44
+ by: {
45
+ id: this.uid,
46
+ device: device
47
+ },
48
+ type: 'form_submitted',
49
+ data: {
50
+ user: user,
51
+ form_submission: {
52
+ user_id: this.uid,
53
+ form_id: form_id,
54
+ page_url: page_url,
55
+ submitted_at: _index.default.Date.now(),
56
+ values: data
57
+ }
58
+ }
59
+ }));
43
60
  _defineProperty(this, "sendTyping", cid => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/typing`));
44
61
  _defineProperty(this, "sendLostFocus", (device, productid, source_id, sku) => this.sendEvent({
45
62
  by: {
@@ -51,6 +51,7 @@ class _default {
51
51
  }));
52
52
  _defineProperty(this, "getLocaleContent", locale => this.apireq.get(`/accounts/${this.accid}/locales/${locale}`));
53
53
  _defineProperty(this, "sendEvent", data => OK200);
54
+ _defineProperty(this, "submitForm", (form_id, page_url, device, data, user) => OK200);
54
55
  _defineProperty(this, "sendTyping", cid => OK200);
55
56
  _defineProperty(this, "sendPresence", data => OK200);
56
57
  _defineProperty(this, "sendContent", data => OK200);
@@ -142,6 +142,7 @@ class Store {
142
142
  trailing: false
143
143
  }));
144
144
  _defineProperty(this, "onConvoEvent", (o, cb) => this.pubsub.on2(o, 'events', cb));
145
+ _defineProperty(this, "onWidgetClose", (o, cb) => this.pubsub.on2(o, 'sbz_close_widget', cb));
145
146
  _defineProperty(this, "seenConvo", id => {
146
147
  if (!id || id === 'create') return;
147
148
  this.seenQueue.push(id);
@@ -481,6 +482,11 @@ class Store {
481
482
  }
482
483
  return this.reconnectGate.open();
483
484
  }
485
+ async submitForm(formid, data, user) {
486
+ await this.readyGate.entry();
487
+ if (user) await this.setUser(user);
488
+ return this.api.submitForm(formid, document.URL, this.device, data, user);
489
+ }
484
490
  async setUser(user) {
485
491
  if (!user) return;
486
492
  await this.readyGate.entry();
@@ -684,34 +690,9 @@ class Store {
684
690
  this._setConvo(convo);
685
691
  this.pubsub.publish('account');
686
692
  }
687
- handleFormSubmit(convoKey, ev) {
688
- if (ev.type !== 'message_sent') return;
689
- let formSubmits = [];
690
- let attachments = _index.default.get(ev, 'data.message.attachments') || [];
691
- _index.default.each(attachments, att => {
692
- if (!att) return;
693
- if (att.type !== 'form_submit') return;
694
- formSubmits.push(att.form_submit);
695
- });
696
- _index.default.each(formSubmits, submit => {
697
- let formev = _index.default.get(this.convoEventM, convoKey + '.' + submit.form_message_id);
698
- if (!formev) return;
699
- let forms = _index.default.filter(_index.default.get(formev, 'data.message.attachments'), att => {
700
- if (!att) return false;
701
- if (att.type !== 'form' && att.type !== 'ask_info_form') return false;
702
- return true;
703
- });
704
- _index.default.each(forms, form => {
705
- form = form.form;
706
- _index.default.each(form.fields, formfield => {
707
- _index.default.each(submit.fields, submitfield => {
708
- if (formfield.name !== submitfield.name) return;
709
- if (formfield.default_answer) return;
710
- formfield.default_answer = submitfield.value;
711
- });
712
- });
713
- });
714
- if (_index.default.size(forms) > 0) this.pubsub.publish('state.convoEventM', this.convoEventM, convoKey);
693
+ emitCloseWidgetEvent() {
694
+ this.pubsub.publish('sbz_close_widget', {
695
+ type: 'chatbox_closed'
715
696
  });
716
697
  }
717
698
  typing(cid) {