@subiz/widget-v4 4.1.210 → 4.1.212

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 (130) hide show
  1. package/README.md +21 -2
  2. package/assets/img/dot_chat.svg +3 -0
  3. package/assets/less/chatbox.less +9 -0
  4. package/assets/less/form.less +10 -0
  5. package/assets/less/message.less +114 -13
  6. package/assets/less/widget.less +15 -18
  7. package/compiled_src/call/css.js +1 -1
  8. package/compiled_src/chatbox/Buttons.js +7 -4
  9. package/compiled_src/chatbox/ChatButton.js +127 -29
  10. package/compiled_src/chatbox/Event.js +37 -5
  11. package/compiled_src/chatbox/Events.js +348 -129
  12. package/compiled_src/chatbox/FormAttachment.js +1 -1
  13. package/compiled_src/chatbox/Header.js +7 -2
  14. package/compiled_src/chatbox/InfoMessage.js +1 -1
  15. package/compiled_src/chatbox/MessageInput.js +24 -9
  16. package/compiled_src/chatbox/OrderAttachments.js +13 -13
  17. package/compiled_src/chatbox/QuoteMessage.js +3 -2
  18. package/compiled_src/chatbox/TextMessage.js +22 -18
  19. package/compiled_src/chatbox/Widget.js +200 -129
  20. package/compiled_src/chatbox/block.js +39 -29
  21. package/compiled_src/chatbox/conversation-history.js +44 -0
  22. package/compiled_src/chatbox/event-layout.js +59 -0
  23. package/compiled_src/chatbox/greeting.js +32 -0
  24. package/compiled_src/chatbox/main.js +3 -0
  25. package/compiled_src/common.js +13 -9
  26. package/compiled_src/form/css.js +1 -1
  27. package/compiled_src/lib.js +22 -32
  28. package/compiled_src/notif/css.js +1 -1
  29. package/compiled_src/plugin.js +11 -18
  30. package/compiled_src/popup/css.js +1 -1
  31. package/compiled_src/popup/popup.js +1 -1
  32. package/compiled_src/store/api.js +0 -2
  33. package/compiled_src/store/api_fake.js +1 -1
  34. package/compiled_src/store/attachments.js +28 -0
  35. package/compiled_src/store/chain.js +24 -10
  36. package/compiled_src/store/kv.js +9 -13
  37. package/compiled_src/store/lsdb.js +1 -1
  38. package/compiled_src/store/store.js +356 -117
  39. package/compiled_src/util/common.js +48 -41
  40. package/compiled_src/util/event.js +15 -0
  41. package/compiled_src/util/pubsub.js +28 -13
  42. package/compiled_src/util/url.js +18 -0
  43. package/dist/127.js +13 -13
  44. package/dist/132.js +1 -1
  45. package/dist/1a0f6f3ff1a.127.js +1 -0
  46. package/dist/{1a0d80f6e72.132.js → 1a0f6f3ff1a.132.js} +1 -1
  47. package/dist/{1a0d80f6e72.27.js → 1a0f6f3ff1a.27.js} +1 -1
  48. package/dist/1a0f6f3ff1a.278.js +1 -0
  49. package/dist/{1a0d80f6e72.339.js → 1a0f6f3ff1a.339.js} +1 -1
  50. package/dist/1a0f6f3ff1a.459.js +1 -0
  51. package/dist/1a0f6f3ff1a.app.js +1 -0
  52. package/dist/{1a0d80f6e72.chat.html → 1a0f6f3ff1a.chat.html} +1 -1
  53. package/dist/1a0f6f3ff1a.chat.js +1 -0
  54. package/dist/{1a0d80f6e72.form.html → 1a0f6f3ff1a.form.html} +1 -1
  55. package/dist/1a0f6f3ff1a.form.js +1 -0
  56. package/dist/{1a0d80f6e72.index.html → 1a0f6f3ff1a.index.html} +1 -1
  57. package/dist/{1a0d80f6e72.library.html → 1a0f6f3ff1a.library.html} +1 -1
  58. package/dist/1a0f6f3ff1a.library.js +1 -0
  59. package/dist/{1a0d80f6e72.preview.html → 1a0f6f3ff1a.preview.html} +1 -1
  60. package/dist/1a0f6f3ff1a.preview.js +1 -0
  61. package/dist/1a0f6f3ff1a.webview.js +1 -0
  62. package/dist/27.js +2 -2
  63. package/dist/459.js +2 -2
  64. package/dist/HASH +1 -1
  65. package/dist/assets/img/dot_chat.335fd8a.svg +3 -0
  66. package/dist/screenshoot.js +1523 -619
  67. package/package.json +12 -5
  68. package/src/chatbox/Buttons.js +5 -4
  69. package/src/chatbox/ChatButton.js +133 -39
  70. package/src/chatbox/Event.js +38 -5
  71. package/src/chatbox/Events.js +306 -134
  72. package/src/chatbox/FormAttachment.js +1 -1
  73. package/src/chatbox/Header.js +5 -4
  74. package/src/chatbox/InfoMessage.js +1 -1
  75. package/src/chatbox/MessageInput.js +15 -10
  76. package/src/chatbox/OrderAttachments.js +13 -13
  77. package/src/chatbox/QuoteMessage.js +3 -2
  78. package/src/chatbox/TextMessage.js +21 -20
  79. package/src/chatbox/Widget.js +150 -150
  80. package/src/chatbox/block.js +29 -27
  81. package/src/chatbox/conversation-history.js +37 -0
  82. package/src/chatbox/event-layout.js +72 -0
  83. package/src/chatbox/greeting.js +13 -0
  84. package/src/chatbox/main.js +3 -0
  85. package/src/common.js +15 -9
  86. package/src/lib.js +22 -35
  87. package/src/plugin.js +11 -13
  88. package/src/popup/popup.js +1 -1
  89. package/src/store/api.js +0 -2
  90. package/src/store/api_fake.js +1 -1
  91. package/src/store/attachments.js +21 -0
  92. package/src/store/chain.js +25 -12
  93. package/src/store/kv.js +10 -19
  94. package/src/store/lsdb.js +1 -1
  95. package/src/store/store.js +313 -130
  96. package/src/util/common.js +48 -43
  97. package/src/util/event.js +7 -0
  98. package/src/util/pubsub.js +27 -8
  99. package/src/util/url.js +14 -0
  100. package/test.cjs +59 -0
  101. package/assets/less/contact.less +0 -126
  102. package/compiled_src/util/common.test.js +0 -414
  103. package/compiled_src/util/event.test.js +0 -38
  104. package/compiled_src/util/extractor.test.js +0 -299
  105. package/compiled_src/util/extractor.test2.js +0 -61
  106. package/compiled_src/util/gate.test.js +0 -18
  107. package/compiled_src/util/pubsub.test.js +0 -35
  108. package/dist/1a0d80f6e72.127.js +0 -1
  109. package/dist/1a0d80f6e72.278.js +0 -1
  110. package/dist/1a0d80f6e72.459.js +0 -1
  111. package/dist/1a0d80f6e72.74.js +0 -1
  112. package/dist/1a0d80f6e72.997.js +0 -1
  113. package/dist/1a0d80f6e72.app.js +0 -1
  114. package/dist/1a0d80f6e72.chat.js +0 -1
  115. package/dist/1a0d80f6e72.form.js +0 -1
  116. package/dist/1a0d80f6e72.library.js +0 -1
  117. package/dist/1a0d80f6e72.preview.js +0 -1
  118. package/dist/1a0d80f6e72.webview.js +0 -1
  119. package/dist/74.js +0 -376
  120. package/dist/997.js +0 -37
  121. package/src/contact/contact.js +0 -400
  122. package/src/contact/css.js +0 -1
  123. package/src/util/common.test.js +0 -301
  124. package/src/util/event.test.js +0 -31
  125. package/src/util/extractor.test.js +0 -240
  126. package/src/util/extractor.test2.js +0 -56
  127. package/src/util/gate.test.js +0 -20
  128. package/src/util/pubsub.test.js +0 -37
  129. /package/dist/{1a0d80f6e72.185.js → 1a0f6f3ff1a.185.js} +0 -0
  130. /package/dist/{1a0d80f6e72.490.js → 1a0f6f3ff1a.490.js} +0 -0
@@ -56,10 +56,26 @@ class Event extends _common.Com {
56
56
  this.state = {
57
57
  pongs: _index.default.get(this.props.event, 'ev.data.message.pongs') || []
58
58
  };
59
+ const _ev = this.props.event.ev;
60
+ const age = (this.props.store.now ? this.props.store.now() : _index.default.Date.now()) - _ev.created;
61
+ this.animateSend = !props.isHistory && _ev.type === 'message_sent' && _index.default.get(_ev, 'by.type') === 'user' && _ev.id === _index.default.get(_ev, 'source_event_id') && age >= 0 && age < 2000;
59
62
  this.textMessageRef = (0, _preact.createRef)();
60
63
  this.fileAttachmentRef = (0, _preact.createRef)();
61
64
  this.imageAttachmentRef = (0, _preact.createRef)();
62
65
  }
66
+ componentDidMount() {
67
+ if (!this.animateSend) return;
68
+ this.sendAnimationFrame = window.requestAnimationFrame(() => {
69
+ this.sendAnimationFrame = window.requestAnimationFrame(() => {
70
+ if (this._isMounted) this.setState({
71
+ sendEntered: true
72
+ });
73
+ });
74
+ });
75
+ }
76
+ componentWillUnmount() {
77
+ if (this.sendAnimationFrame) window.cancelAnimationFrame(this.sendAnimationFrame);
78
+ }
63
79
  render() {
64
80
  var ev = _index.default.get(this.props.event, 'ev', {});
65
81
  switch (ev.type) {
@@ -104,6 +120,7 @@ class Event extends _common.Com {
104
120
  return !!_index.default.find(pongs, pong => pong.type === 'dislike');
105
121
  }
106
122
  chooseQuickReply(reply) {
123
+ if (this.props.isHistory) return;
107
124
  let ev = _index.default.get(this.props.event, 'ev', {});
108
125
  let message = {
109
126
  text: reply.title,
@@ -121,6 +138,7 @@ class Event extends _common.Com {
121
138
  this.props.onSend(message);
122
139
  }
123
140
  choosePostbackBtn(button) {
141
+ if (this.props.isHistory) return;
124
142
  let ev = _index.default.get(this.props.event, 'ev', {});
125
143
  let message = {
126
144
  text: button.title,
@@ -261,6 +279,17 @@ class Event extends _common.Com {
261
279
  }
262
280
  renderMessageSent() {
263
281
  let ev = this.props.event.ev;
282
+ if (_index.default.get(ev, 'data.message.deleted')) {
283
+ let byType = _index.default.get(ev, 'by.type') === 'user' ? 'user' : 'agent';
284
+ return (0, _preact.h)("div", {
285
+ class: 'convo-event ' + byType + '-message',
286
+ "data-ev-id": ev.id
287
+ }, (0, _preact.h)(_TextMessage.default, {
288
+ ev: ev,
289
+ t: this.props.t,
290
+ store: this.props.store
291
+ }));
292
+ }
264
293
  let attachments = _index.default.get(ev, 'data.message.attachments');
265
294
  let hasForm = _index.default.find(attachments, att => att.type === 'form');
266
295
  if (_index.default.isEmptyMessage(_index.default.get(ev, 'data.message'))) return null;
@@ -331,13 +360,13 @@ class Event extends _common.Com {
331
360
  t: this.props.t,
332
361
  store: this.props.store,
333
362
  ev: ev
334
- }), (0, _preact.h)(_QuickReplies.default, {
363
+ }), !this.props.isHistory && (0, _preact.h)(_QuickReplies.default, {
335
364
  store: this.props.store,
336
365
  ev: ev,
337
366
  onSelect: e => this.chooseQuickReply(e)
338
367
  }), this.renderReactions(), this.renderAIDevNote())));
339
368
  }
340
- if (_index.default.get(ev, 'data.message.idempotency_key') === ev.id && this.props.store.now() - ev.created < 900) {
369
+ if (_index.default.get(ev, 'source_event_id') === ev.id && this.props.store.now() - ev.created < 900) {
341
370
  _index.default.setTimeout(() => this.setState({
342
371
  refresh: this.state.refresh
343
372
  }), 1000);
@@ -345,7 +374,7 @@ class Event extends _common.Com {
345
374
  let $dot = (0, _preact.h)("div", {
346
375
  class: "sending_dot"
347
376
  });
348
- if (this.props.store.now() - ev.created < 900 || _index.default.get(ev, 'data.message.idempotency_key') !== ev.id) {
377
+ if (this.props.store.now() - ev.created < 900 || _index.default.get(ev, 'source_event_id') !== ev.id) {
349
378
  $dot = (0, _preact.h)("div", {
350
379
  class: "sending_dot sending_dot__hide"
351
380
  });
@@ -373,10 +402,11 @@ class Event extends _common.Com {
373
402
  class: "convo-event user-message",
374
403
  "data-ev-id": ev.id
375
404
  }, $sender, (0, _preact.h)("div", {
376
- class: "message-user__container"
405
+ class: 'message-user__container' + (this.animateSend && !this.props.isHistory ? ' message-user__container--send' + (this.state.sendEntered ? '' : ' message-user__container--enter') : '')
377
406
  }, $dot, (0, _preact.h)(_TextMessage.default, {
378
407
  ref: this.textMessageRef,
379
408
  store: this.props.store,
409
+ t: this.props.t,
380
410
  ev: ev,
381
411
  refresh: this.state.refresh,
382
412
  onLink: this.props.onLink
@@ -412,6 +442,7 @@ class Event extends _common.Com {
412
442
  })), $error);
413
443
  }
414
444
  async onSendReaction(action) {
445
+ if (this.props.isHistory) return;
415
446
  if (this._reacting) return;
416
447
  let ev = this.props.event.ev;
417
448
  let cid = _index.default.get(ev, 'data.message.conversation_id');
@@ -463,6 +494,7 @@ class Event extends _common.Com {
463
494
  this._reacting = false;
464
495
  }
465
496
  renderReactions() {
497
+ if (this.props.isHistory) return null;
466
498
  if (this.props.store.isAIDevMode()) return null;
467
499
  let cid = _index.default.get(this.props.event.ev, 'data.message.conversation_id', '');
468
500
  if (cid.startsWith('cslight')) return null;
@@ -550,7 +582,7 @@ class Event extends _common.Com {
550
582
  let byid = _index.default.get(ev, 'by.display_id', _index.default.get(ev, 'by.id')) || '';
551
583
  if (bytype === 'user') return _index.default.getUserDisplayName(this.props.store.matchUser());
552
584
  let acc = this.props.store.matchAccount();
553
- if (bytype === 'agent') return _index.default.getAgentDisplayName(acc, this.props.store.matchAgent(byid));
585
+ if (bytype === 'agent' || _index.default.get(ev, 'by.display_type') === 'agent') return _index.default.getAgentDisplayName(acc, this.props.store.matchAgent(byid));
554
586
  if (byid.startsWith('at')) return _index.default.getAgentDisplayName(acc, this.props.store.matchAgent(byid));
555
587
  if (bytype === 'bot') {
556
588
  let bot = this.props.store.matchBot()[byid];