@subiz/widget-v4 4.1.62 → 4.1.65

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 (51) hide show
  1. package/README.md +10 -0
  2. package/assets/less/widget.less +19 -7
  3. package/compiled_src/chatbox/Widget.js +57 -28
  4. package/compiled_src/store/api.js +17 -0
  5. package/compiled_src/store/api_fake.js +1 -0
  6. package/compiled_src/store/store.js +5 -30
  7. package/dist/{792.js → 132.js} +121 -121
  8. package/dist/18dd22fb422.132.js +1 -0
  9. package/dist/18dd22fb422.27.js +1 -0
  10. package/dist/18dd22fb422.278.js +1 -0
  11. package/dist/{18d7db7ca8c.756.js → 18dd22fb422.459.js} +1 -1
  12. package/dist/18dd22fb422.490.js +1 -0
  13. package/dist/18dd22fb422.497.js +1 -0
  14. package/dist/18dd22fb422.74.js +1 -0
  15. package/dist/18dd22fb422.997.js +1 -0
  16. package/dist/18dd22fb422.app.js +1 -0
  17. package/dist/{18d7db7ca8c.index.html → 18dd22fb422.index.html} +1 -1
  18. package/dist/{18d7db7ca8c.library.html → 18dd22fb422.library.html} +1 -1
  19. package/dist/18dd22fb422.library.js +1 -0
  20. package/dist/{18d7db7ca8c.preview.html → 18dd22fb422.preview.html} +1 -1
  21. package/dist/18dd22fb422.preview.js +1 -0
  22. package/dist/18dd22fb422.screenshoot.js +1 -0
  23. package/dist/18dd22fb422.webview.js +1 -0
  24. package/dist/{444.js → 27.js} +6 -6
  25. package/dist/{176.js → 278.js} +54 -54
  26. package/dist/{756.js → 459.js} +6 -6
  27. package/dist/{104.js → 490.js} +57 -57
  28. package/dist/{928.js → 497.js} +676 -676
  29. package/dist/{508.js → 74.js} +30 -30
  30. package/dist/{672.js → 997.js} +6 -6
  31. package/dist/HASH +1 -1
  32. package/dist/malicious-app.js +4 -8
  33. package/dist/screenshoot.html +1 -1
  34. package/dist/screenshoot.js +292 -292
  35. package/package.json +2 -2
  36. package/src/chatbox/Widget.js +53 -32
  37. package/src/store/api.js +17 -0
  38. package/src/store/api_fake.js +3 -0
  39. package/src/store/store.js +16 -50
  40. package/dist/18d7db7ca8c.104.js +0 -1
  41. package/dist/18d7db7ca8c.176.js +0 -1
  42. package/dist/18d7db7ca8c.444.js +0 -1
  43. package/dist/18d7db7ca8c.508.js +0 -1
  44. package/dist/18d7db7ca8c.672.js +0 -1
  45. package/dist/18d7db7ca8c.792.js +0 -1
  46. package/dist/18d7db7ca8c.928.js +0 -1
  47. package/dist/18d7db7ca8c.app.js +0 -1
  48. package/dist/18d7db7ca8c.library.js +0 -1
  49. package/dist/18d7db7ca8c.preview.js +0 -1
  50. package/dist/18d7db7ca8c.screenshoot.js +0 -1
  51. package/dist/18d7db7ca8c.webview.js +0 -1
package/README.md CHANGED
@@ -21,3 +21,13 @@ Since our script is running in client site. The built-in function may be overrid
21
21
 
22
22
  JSON.stringify => sb.stringify
23
23
  JSON.parse => sb.parseJSON
24
+
25
+
26
+ ### Note about preact
27
+ preact above 10.19.3 cause form input problem
28
+ reproduct: ,
29
+ 1. checkout to commit
30
+ 2. IMPORTANT: open new incognitor browser
31
+ 2. visit http://localhost:8082/?account_id=acpxkgumifuoofoosble
32
+ 3. input into form offline
33
+ 4. cannot submit (expted: can submit)
@@ -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
 
@@ -225,9 +228,9 @@
225
228
  }
226
229
 
227
230
  .widget-container.widget-container--full {
228
- max-height: 100%;
229
- height: 100%;
230
- margin-bottom: 0;
231
+ max-height: 100%;
232
+ height: 100%;
233
+ margin-bottom: 0;
231
234
  }
232
235
 
233
236
  .widget-container.widget-container--hide {
@@ -238,6 +241,7 @@
238
241
 
239
242
  .btn--start-convo {
240
243
  border-radius: 7px;
244
+ display: block;
241
245
  padding-left: 32px;
242
246
  padding-right: 32px;
243
247
  height: 40px;
@@ -246,15 +250,23 @@
246
250
  line-height: 20px;
247
251
  text-align: center;
248
252
  background: @primary-color;
249
- display: flex;
250
- align-items: center;
251
- margin-left: auto;
252
- margin-right: auto;
253
+ max-width: 250px;
254
+ width: 70%;
255
+ text-overflow: ellipsis;
256
+ white-space: nowrap;
257
+ overflow: hidden;
258
+
253
259
  &::after {
254
260
  display: none;
255
261
  }
256
262
  }
257
263
 
264
+ .btn--start-convo:disabled {
265
+ opacity: 0.5;
266
+ cursor: default;
267
+ pointer-events: none;
268
+ }
269
+
258
270
  .widget-body.widget-body--none {
259
271
  display: none;
260
272
  }
@@ -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, fornName) {
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,20 @@ 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 out = await this.props.store.submitForm('chatbox_' + fornName, _index.default.map(data, (field, key) => {
237
+ return {
238
+ key: key,
239
+ type: field.type,
240
+ value: field.value + ''
241
+ };
242
+ }), user);
243
+ if (_creating != this._creating) return;
213
244
  if (this.props.cid) {
214
- this.props.store.setUser(user);
215
245
  this.setState({
216
246
  clickedJoin: false
217
247
  });
@@ -226,15 +256,15 @@ class Widget extends _common.Com {
226
256
  attachments: this.state.quickReplyMessage.attachments
227
257
  }
228
258
  });
259
+ if (_creating != this._creating) return;
229
260
  this.setState({
261
+ creating: false,
230
262
  quickReplyMessage: {}
231
263
  });
232
264
  if (form.end_conversation_after_submit) await this.props.store.endConvo(this.props.cid);
265
+ if (_creating != this._creating) return;
233
266
  return;
234
267
  }
235
- this.setState({
236
- creating: true
237
- });
238
268
  let message = {
239
269
  text: firstmsg,
240
270
  format: 'plaintext'
@@ -248,11 +278,11 @@ class Widget extends _common.Com {
248
278
  this.setState({
249
279
  creatingError: null
250
280
  });
251
- await this.props.store.setUser(user);
252
281
  const {
253
282
  error,
254
283
  convo
255
284
  } = await this.props.store.startConvo(req);
285
+ if (_creating != this._creating) return;
256
286
  if (error) {
257
287
  this.setState({
258
288
  creating: false,
@@ -262,18 +292,19 @@ class Widget extends _common.Com {
262
292
  }
263
293
  let newconvoid = convo.id;
264
294
  this.userSent[newconvoid] = true;
265
- this.props.onGo({
266
- view: 'chat',
267
- cid: newconvoid
268
- });
269
- this.props.store.sendConvoEvent(newconvoid, 'message_sent', {
295
+ await this.props.store.sendConvoEvent(newconvoid, 'message_sent', {
270
296
  message
271
297
  });
298
+ if (_creating != this._creating) return;
272
299
  this.setState({
273
300
  creating: false,
274
301
  clickedJoin: false,
275
302
  quickReplyMessage: {}
276
303
  });
304
+ this.props.onGo({
305
+ view: 'chat',
306
+ cid: newconvoid
307
+ });
277
308
  if (!this.props.store.isMobile()) this.focusInput();
278
309
  }
279
310
  formMounted(form) {
@@ -455,6 +486,7 @@ class Widget extends _common.Com {
455
486
  },
456
487
  value: field.value || '',
457
488
  onInput: e => this.onInputChange(key, e.target.value),
489
+ onChange: e => this.onInputChange(key, e.target.value),
458
490
  row: "4",
459
491
  class: "form-control"
460
492
  });
@@ -462,6 +494,7 @@ class Widget extends _common.Com {
462
494
  $field = (0, _preact.h)("input", {
463
495
  value: field.value || '',
464
496
  onInput: e => this.onInputChange(key, e.target.value),
497
+ onChange: e => this.onInputChange(key, e.target.value),
465
498
  ref: ref => {
466
499
  this['form_' + encode(key)] = ref;
467
500
  },
@@ -540,7 +573,9 @@ class Widget extends _common.Com {
540
573
  label = field.label || this.props.t('your_question');
541
574
  }
542
575
  if (field.label) label = field.label;
543
- return (0, _preact.h)("div", null, (0, _preact.h)("div", {
576
+ return (0, _preact.h)("div", {
577
+ key: 'form_' + encode(key)
578
+ }, (0, _preact.h)("div", {
544
579
  class: "label"
545
580
  }, label, field.is_required ? (0, _preact.h)("span", {
546
581
  class: "ml-1 red"
@@ -552,14 +587,7 @@ class Widget extends _common.Com {
552
587
  class: "pt-2"
553
588
  }, $fields);
554
589
  }
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
- }));
590
+ renderForm(form, submitLabel, formName) {
563
591
  let title = this.props.t.i18n(_index.default.get(form, `i18n_title`, {}));
564
592
  if (!title) title = _index.default.get(form, 'title', this.props.t('capture_lead_title'));
565
593
  title = title.replace('↵', '');
@@ -581,8 +609,9 @@ class Widget extends _common.Com {
581
609
  class: "message-input message-input--preform"
582
610
  }, (0, _preact.h)("button", {
583
611
  class: "btn--start-convo",
584
- onClick: _ => this.submitPrechatForm(form)
585
- }, submitLabel, " ", $loading)));
612
+ onClick: _ => this.submitPrechatForm(form, formName),
613
+ disabled: this.state.creating
614
+ }, submitLabel)));
586
615
  }
587
616
  goToConvo(cid) {
588
617
  this.props.onGo({
@@ -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_submitted: {
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);
@@ -481,6 +481,11 @@ class Store {
481
481
  }
482
482
  return this.reconnectGate.open();
483
483
  }
484
+ async submitForm(formid, data, user) {
485
+ await this.readyGate.entry();
486
+ if (user) await this.setUser(user);
487
+ return this.api.submitForm(formid, document.URL, this.device, data, user);
488
+ }
484
489
  async setUser(user) {
485
490
  if (!user) return;
486
491
  await this.readyGate.entry();
@@ -684,36 +689,6 @@ class Store {
684
689
  this._setConvo(convo);
685
690
  this.pubsub.publish('account');
686
691
  }
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);
715
- });
716
- }
717
692
  typing(cid) {
718
693
  if (!cid) return;
719
694
  this._typing(cid);