@subiz/widget-v4 4.0.88 → 4.0.89

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 (36) hide show
  1. package/assets/less/chatbox.less +2 -0
  2. package/compiled_src/chatbox/Event.js +1 -1
  3. package/compiled_src/chatbox/Widget.js +55 -6
  4. package/compiled_src/util/common.js +1 -1
  5. package/dist/132.js +52 -7
  6. package/dist/178.js +1 -1
  7. package/dist/1833a09e682.132.js +1 -0
  8. package/dist/1833a09e682.178.js +1 -0
  9. package/dist/{182ee177a49.213.js → 1833a09e682.213.js} +0 -0
  10. package/dist/{182ee177a49.335.js → 1833a09e682.335.js} +0 -0
  11. package/dist/{182ee177a49.362.js → 1833a09e682.362.js} +0 -0
  12. package/dist/1833a09e682.441.js +1 -0
  13. package/dist/{182ee177a49.605.js → 1833a09e682.605.js} +0 -0
  14. package/dist/{182ee177a49.678.js → 1833a09e682.678.js} +0 -0
  15. package/dist/{182ee177a49.782.js → 1833a09e682.782.js} +0 -0
  16. package/dist/1833a09e682.app.js +1 -0
  17. package/dist/{182ee177a49.index.html → 1833a09e682.index.html} +1 -1
  18. package/dist/{182ee177a49.library.html → 1833a09e682.library.html} +1 -1
  19. package/dist/1833a09e682.library.js +1 -0
  20. package/dist/{182ee177a49.preview.html → 1833a09e682.preview.html} +1 -1
  21. package/dist/1833a09e682.preview.js +1 -0
  22. package/dist/1833a09e682.screenshoot.js +1 -0
  23. package/dist/441.js +52 -45
  24. package/dist/HASH +1 -1
  25. package/dist/screenshoot.html +1 -1
  26. package/dist/screenshoot.js +1 -1
  27. package/package.json +8 -8
  28. package/src/chatbox/Widget.js +52 -3
  29. package/src/util/common.js +1 -1
  30. package/dist/182ee177a49.132.js +0 -1
  31. package/dist/182ee177a49.178.js +0 -1
  32. package/dist/182ee177a49.441.js +0 -1
  33. package/dist/182ee177a49.app.js +0 -1
  34. package/dist/182ee177a49.library.js +0 -1
  35. package/dist/182ee177a49.preview.js +0 -1
  36. package/dist/182ee177a49.screenshoot.js +0 -1
package/dist/441.js CHANGED
@@ -37,6 +37,7 @@ __webpack_require__.r(__webpack_exports__);
37
37
 
38
38
  function getDefaults() {
39
39
  return {
40
+ async: false,
40
41
  baseUrl: null,
41
42
  breaks: false,
42
43
  extensions: null,
@@ -355,7 +356,7 @@ function outputLink(cap, link, raw, lexer) {
355
356
  href,
356
357
  title,
357
358
  text,
358
- tokens: lexer.inlineTokens(text, [])
359
+ tokens: lexer.inlineTokens(text)
359
360
  };
360
361
  lexer.state.inLink = false;
361
362
  return token;
@@ -461,15 +462,13 @@ class Tokenizer {
461
462
  }
462
463
  }
463
464
 
464
- const token = {
465
+ return {
465
466
  type: 'heading',
466
467
  raw: cap[0],
467
468
  depth: cap[1].length,
468
469
  text,
469
- tokens: []
470
+ tokens: this.lexer.inline(text)
470
471
  };
471
- this.lexer.inline(token.text, token.tokens);
472
- return token;
473
472
  }
474
473
  }
475
474
 
@@ -691,10 +690,10 @@ class Tokenizer {
691
690
  text: cap[0]
692
691
  };
693
692
  if (this.options.sanitize) {
693
+ const text = this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]);
694
694
  token.type = 'paragraph';
695
- token.text = this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]);
696
- token.tokens = [];
697
- this.lexer.inline(token.text, token.tokens);
695
+ token.text = text;
696
+ token.tokens = this.lexer.inline(text);
698
697
  }
699
698
  return token;
700
699
  }
@@ -752,8 +751,7 @@ class Tokenizer {
752
751
  // header child tokens
753
752
  l = item.header.length;
754
753
  for (j = 0; j < l; j++) {
755
- item.header[j].tokens = [];
756
- this.lexer.inline(item.header[j].text, item.header[j].tokens);
754
+ item.header[j].tokens = this.lexer.inline(item.header[j].text);
757
755
  }
758
756
 
759
757
  // cell child tokens
@@ -761,8 +759,7 @@ class Tokenizer {
761
759
  for (j = 0; j < l; j++) {
762
760
  row = item.rows[j];
763
761
  for (k = 0; k < row.length; k++) {
764
- row[k].tokens = [];
765
- this.lexer.inline(row[k].text, row[k].tokens);
762
+ row[k].tokens = this.lexer.inline(row[k].text);
766
763
  }
767
764
  }
768
765
 
@@ -774,45 +771,40 @@ class Tokenizer {
774
771
  lheading(src) {
775
772
  const cap = this.rules.block.lheading.exec(src);
776
773
  if (cap) {
777
- const token = {
774
+ return {
778
775
  type: 'heading',
779
776
  raw: cap[0],
780
777
  depth: cap[2].charAt(0) === '=' ? 1 : 2,
781
778
  text: cap[1],
782
- tokens: []
779
+ tokens: this.lexer.inline(cap[1])
783
780
  };
784
- this.lexer.inline(token.text, token.tokens);
785
- return token;
786
781
  }
787
782
  }
788
783
 
789
784
  paragraph(src) {
790
785
  const cap = this.rules.block.paragraph.exec(src);
791
786
  if (cap) {
792
- const token = {
787
+ const text = cap[1].charAt(cap[1].length - 1) === '\n'
788
+ ? cap[1].slice(0, -1)
789
+ : cap[1];
790
+ return {
793
791
  type: 'paragraph',
794
792
  raw: cap[0],
795
- text: cap[1].charAt(cap[1].length - 1) === '\n'
796
- ? cap[1].slice(0, -1)
797
- : cap[1],
798
- tokens: []
793
+ text,
794
+ tokens: this.lexer.inline(text)
799
795
  };
800
- this.lexer.inline(token.text, token.tokens);
801
- return token;
802
796
  }
803
797
  }
804
798
 
805
799
  text(src) {
806
800
  const cap = this.rules.block.text.exec(src);
807
801
  if (cap) {
808
- const token = {
802
+ return {
809
803
  type: 'text',
810
804
  raw: cap[0],
811
805
  text: cap[0],
812
- tokens: []
806
+ tokens: this.lexer.inline(cap[0])
813
807
  };
814
- this.lexer.inline(token.text, token.tokens);
815
- return token;
816
808
  }
817
809
  }
818
810
 
@@ -981,7 +973,7 @@ class Tokenizer {
981
973
  type: 'em',
982
974
  raw: src.slice(0, lLength + match.index + rLength + 1),
983
975
  text,
984
- tokens: this.lexer.inlineTokens(text, [])
976
+ tokens: this.lexer.inlineTokens(text)
985
977
  };
986
978
  }
987
979
 
@@ -991,7 +983,7 @@ class Tokenizer {
991
983
  type: 'strong',
992
984
  raw: src.slice(0, lLength + match.index + rLength + 1),
993
985
  text,
994
- tokens: this.lexer.inlineTokens(text, [])
986
+ tokens: this.lexer.inlineTokens(text)
995
987
  };
996
988
  }
997
989
  }
@@ -1032,7 +1024,7 @@ class Tokenizer {
1032
1024
  type: 'del',
1033
1025
  raw: cap[0],
1034
1026
  text: cap[2],
1035
- tokens: this.lexer.inlineTokens(cap[2], [])
1027
+ tokens: this.lexer.inlineTokens(cap[2])
1036
1028
  };
1037
1029
  }
1038
1030
  }
@@ -2581,13 +2573,7 @@ function marked(src, opt, callback) {
2581
2573
  return;
2582
2574
  }
2583
2575
 
2584
- try {
2585
- const tokens = Lexer.lex(src, opt);
2586
- if (opt.walkTokens) {
2587
- marked.walkTokens(tokens, opt.walkTokens);
2588
- }
2589
- return Parser.parse(tokens, opt);
2590
- } catch (e) {
2576
+ function onError(e) {
2591
2577
  e.message += '\nPlease report this to https://github.com/markedjs/marked.';
2592
2578
  if (opt.silent) {
2593
2579
  return '<p>An error occurred:</p><pre>'
@@ -2596,6 +2582,23 @@ function marked(src, opt, callback) {
2596
2582
  }
2597
2583
  throw e;
2598
2584
  }
2585
+
2586
+ try {
2587
+ const tokens = Lexer.lex(src, opt);
2588
+ if (opt.walkTokens) {
2589
+ if (opt.async) {
2590
+ return Promise.all(marked.walkTokens(tokens, opt.walkTokens))
2591
+ .then(() => {
2592
+ return Parser.parse(tokens, opt);
2593
+ })
2594
+ .catch(onError);
2595
+ }
2596
+ marked.walkTokens(tokens, opt.walkTokens);
2597
+ }
2598
+ return Parser.parse(tokens, opt);
2599
+ } catch (e) {
2600
+ onError(e);
2601
+ }
2599
2602
  }
2600
2603
 
2601
2604
  /**
@@ -2712,10 +2715,12 @@ marked.use = function(...args) {
2712
2715
  if (pack.walkTokens) {
2713
2716
  const walkTokens = marked.defaults.walkTokens;
2714
2717
  opts.walkTokens = function(token) {
2715
- pack.walkTokens.call(this, token);
2718
+ let values = [];
2719
+ values.push(pack.walkTokens.call(this, token));
2716
2720
  if (walkTokens) {
2717
- walkTokens.call(this, token);
2721
+ values = values.concat(walkTokens.call(this, token));
2718
2722
  }
2723
+ return values;
2719
2724
  };
2720
2725
  }
2721
2726
 
@@ -2732,35 +2737,37 @@ marked.use = function(...args) {
2732
2737
  */
2733
2738
 
2734
2739
  marked.walkTokens = function(tokens, callback) {
2740
+ let values = [];
2735
2741
  for (const token of tokens) {
2736
- callback.call(marked, token);
2742
+ values = values.concat(callback.call(marked, token));
2737
2743
  switch (token.type) {
2738
2744
  case 'table': {
2739
2745
  for (const cell of token.header) {
2740
- marked.walkTokens(cell.tokens, callback);
2746
+ values = values.concat(marked.walkTokens(cell.tokens, callback));
2741
2747
  }
2742
2748
  for (const row of token.rows) {
2743
2749
  for (const cell of row) {
2744
- marked.walkTokens(cell.tokens, callback);
2750
+ values = values.concat(marked.walkTokens(cell.tokens, callback));
2745
2751
  }
2746
2752
  }
2747
2753
  break;
2748
2754
  }
2749
2755
  case 'list': {
2750
- marked.walkTokens(token.items, callback);
2756
+ values = values.concat(marked.walkTokens(token.items, callback));
2751
2757
  break;
2752
2758
  }
2753
2759
  default: {
2754
2760
  if (marked.defaults.extensions && marked.defaults.extensions.childTokens && marked.defaults.extensions.childTokens[token.type]) { // Walk any extensions
2755
2761
  marked.defaults.extensions.childTokens[token.type].forEach(function(childTokens) {
2756
- marked.walkTokens(token[childTokens], callback);
2762
+ values = values.concat(marked.walkTokens(token[childTokens], callback));
2757
2763
  });
2758
2764
  } else if (token.tokens) {
2759
- marked.walkTokens(token.tokens, callback);
2765
+ values = values.concat(marked.walkTokens(token.tokens, callback));
2760
2766
  }
2761
2767
  }
2762
2768
  }
2763
2769
  }
2770
+ return values;
2764
2771
  };
2765
2772
 
2766
2773
  /**
package/dist/HASH CHANGED
@@ -1 +1 @@
1
- 182ee177a49
1
+ 1833a09e682
@@ -4,4 +4,4 @@
4
4
  }
5
5
  body {
6
6
  background: #ddd;
7
- }</style></head><body><script defer="defer" src="https://vcdn.subiz-cdn.com/widget-v4/public/182ee177a49.screenshoot.js"></script></body></html>
7
+ }</style></head><body><script defer="defer" src="https://vcdn.subiz-cdn.com/widget-v4/public/1833a09e682.screenshoot.js"></script></body></html>
@@ -2294,7 +2294,7 @@ function checkRunConditions(freq, conds, lastrun, store) {
2294
2294
 
2295
2295
  case 'source':
2296
2296
  if (size(cond.sources) > 0) {
2297
- let source = store.matchTrafficSource();
2297
+ let source = store.matchTrafficSource() || 'direct';
2298
2298
  if (!find(cond.sources, src => norm(src) === norm(source))) return false;
2299
2299
  }
2300
2300
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@subiz/widget-v4",
3
- "version": "4.0.88",
3
+ "version": "4.0.89",
4
4
  "main": "./compiled_src/lib.js",
5
5
  "scripts": {
6
6
  "dev": "npx webpack serve --config webpack.dev.js",
@@ -14,28 +14,28 @@
14
14
  "@subiz/storage": "0.0.8",
15
15
  "@subiz/wsclient": "^3.1.7",
16
16
  "cookie_js": "1.4.2",
17
- "core-js": "^3.25.0",
17
+ "core-js": "^3.25.1",
18
18
  "css-loader": "5.2.7",
19
19
  "file-loader": "^6.2.0",
20
20
  "less": "^4.1.3",
21
21
  "less-loader": "^11.0.0",
22
22
  "marked": "^4.1.0",
23
- "preact": "^10.10.6"
23
+ "preact": "^10.11.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@babel/cli": "^7.18.10",
27
- "@babel/core": "^7.18.13",
27
+ "@babel/core": "^7.19.0",
28
28
  "@babel/plugin-proposal-class-properties": "^7.18.6",
29
- "@babel/plugin-transform-react-jsx": "^7.18.10",
30
- "@babel/preset-env": "^7.18.10",
29
+ "@babel/plugin-transform-react-jsx": "^7.19.0",
30
+ "@babel/preset-env": "^7.19.0",
31
31
  "babel-loader": "^8.2.5",
32
32
  "babel-plugin-syntax-jsx": "^6.18.0",
33
33
  "html-webpack-plugin": "^5.5.0",
34
34
  "prettier": "^2.7.1",
35
- "puppeteer": "^15.4.0",
35
+ "puppeteer": "^17.1.3",
36
36
  "webpack": "^5.74.0",
37
37
  "webpack-bundle-analyzer": "^4.6.1",
38
38
  "webpack-cli": "^4.10.0",
39
- "webpack-dev-server": "^4.10.1"
39
+ "webpack-dev-server": "^4.11.0"
40
40
  }
41
41
  }
@@ -31,6 +31,8 @@ export default class Widget extends Com {
31
31
  formData: {},
32
32
  showOrder: false,
33
33
  order_id: '',
34
+ // hot fix for prechat with bot quick reply
35
+ quickReplyMessage: '',
34
36
  })
35
37
 
36
38
  this.props.store.onUpdate(this, (_) => this.forceUpdate())
@@ -49,7 +51,7 @@ export default class Widget extends Com {
49
51
 
50
52
  if (prevProp.cid !== this.props.cid) {
51
53
  this.closeOrder()
52
- this.setState({clickedJoin: false})
54
+ this.setState({clickedJoin: false, quickReplyMessage: ''})
53
55
  // this.props.store.setLastview('chat', { cid: this.props.cid })
54
56
  setTimeout(() => {
55
57
  // focus Events then focus MessageInput
@@ -64,6 +66,17 @@ export default class Widget extends Com {
64
66
  }
65
67
 
66
68
  shouldShowForm() {
69
+ // always show form when ask agentgroup
70
+ let form
71
+ let accountSetting = this.props.plugin.chatbox || {}
72
+ let acc = this.props.store.matchAccount() || {}
73
+ if (sb.get(accountSetting, 'prechat_form.enabled')) form = accountSetting.prechat_form
74
+
75
+ let offlineEnabled = sb.get(accountSetting, 'offline_form.enabled')
76
+ if (this.isOffline(acc, accountSetting) && offlineEnabled) form = accountSetting.offline_form
77
+
78
+ if (!this.hasSentMessage(this.props.cid) && form && (sb.size(form.groups) || form.group_required)) return true
79
+
67
80
  let formRequired = this.isFormRequired()
68
81
  return (formRequired && !this.props.cid) || (formRequired && this.props.cid && this.state.clickedJoin)
69
82
  }
@@ -178,6 +191,9 @@ export default class Widget extends Com {
178
191
  },
179
192
  })
180
193
 
194
+ // reset quickReplyMessage
195
+ this.setState({quickReplyMessage: ''})
196
+
181
197
  // end_conversation_after_submit only for offline form or prechat form
182
198
  if (form.end_conversation_after_submit) await this.props.store.endConvo(this.props.cid)
183
199
  return
@@ -202,6 +218,7 @@ export default class Widget extends Com {
202
218
  this.setState({
203
219
  creating: false,
204
220
  clickedJoin: false,
221
+ quickReplyMessage: '',
205
222
  })
206
223
  if (!this.props.store.isMobile()) this.focusInput()
207
224
  }
@@ -214,9 +231,11 @@ export default class Widget extends Com {
214
231
  is_required: true,
215
232
  label: this.props.t.i18n(sb.get(form, `i18n_question_label`, {})) || form.question_label,
216
233
  type: 'text',
234
+ value: this.state.quickReplyMessage,
217
235
  }
218
236
 
219
237
  this.setState({formData})
238
+
220
239
  if (!this.props.store.isMobile()) this.focusInput()
221
240
  }
222
241
 
@@ -261,6 +280,9 @@ export default class Widget extends Com {
261
280
  if (sb.size(this.state.formData) === 0) return null
262
281
 
263
282
  let $fields = sb.map(this.state.formData, (field, key) => {
283
+ // not display question when click bot quick reply
284
+ if (this.state.quickReplyMessage && key === 'question') return null
285
+
264
286
  let $field = null
265
287
  var errclass = field.error ? 'input--error' : ''
266
288
  if (field.type === 'text') {
@@ -525,7 +547,23 @@ export default class Widget extends Com {
525
547
  this.focusInput()
526
548
  }
527
549
 
550
+ fillQuickReplyToQuestion(message) {
551
+ let formData = this.state.formData
552
+ if (formData) {
553
+ sb.set(formData, 'question.value', message.text)
554
+ }
555
+ this.setState({formData, quickReplyMessage: message.text})
556
+ }
557
+
528
558
  sendMessage = async (message) => {
559
+ // hot fix click quick reply with prechat with display prechat form
560
+ let hasPostback = sb.find(message.attachments, (att) => att.type === 'postback')
561
+ if (this.isFormRequired() && hasPostback) {
562
+ this.onStartConvoClick()
563
+ this.fillQuickReplyToQuestion(message)
564
+ return
565
+ }
566
+
529
567
  let text = message.text
530
568
  if (!this.props.cid) {
531
569
  this.creating = true
@@ -635,7 +673,7 @@ export default class Widget extends Com {
635
673
  async onStartConvoClick() {
636
674
  var convo = this.props.store.matchConvo(this.props.cid) || {}
637
675
  if (convo.state === 'ended') return this.props.onGo({view: 'chat', cid: ''})
638
- this.setState({clickedJoin: true})
676
+ this.setState({clickedJoin: true, quickReplyMessage: ''})
639
677
  }
640
678
 
641
679
  onEventFormSubmit() {
@@ -675,7 +713,8 @@ export default class Widget extends Com {
675
713
  let convo = this.props.store.matchConvo(this.props.cid) || {}
676
714
 
677
715
  if (convo.state === 'ended') return true
678
- if (this.userHasSent(this.props.cid)) return false
716
+ // allow button "Tiep tuc chat" display when sent quick_replies msg
717
+ //if (this.userHasSent(this.props.cid)) return false
679
718
  if (convo.state && convo.state !== 'pending') delete formData.group
680
719
  return !!sb.find(formData, (field) => field.value == null || field.value === '')
681
720
  }
@@ -778,6 +817,16 @@ export default class Widget extends Com {
778
817
  return joined
779
818
  }
780
819
 
820
+ hasSentMessage(cid) {
821
+ let convo = this.props.store.matchConvo(cid) || {}
822
+ let joined = sb.find(convo.members, (mem) => {
823
+ // sometime bot didnt update last_sent
824
+ if (mem.type === 'bot') return true
825
+ return mem.last_sent
826
+ })
827
+ return joined
828
+ }
829
+
781
830
  isOffline(acc, accSetting) {
782
831
  let enableWhen = sb.get(accSetting, 'offline_form.enable_when')
783
832
  let isonline = true
@@ -824,7 +824,7 @@ export function checkRunConditions(freq, conds, lastrun, store) {
824
824
  break
825
825
  case 'source':
826
826
  if (size(cond.sources) > 0) {
827
- let source = store.matchTrafficSource()
827
+ let source = store.matchTrafficSource() || 'direct'
828
828
  if (!find(cond.sources, (src) => norm(src) === norm(source))) return false
829
829
  }
830
830
  break