@subiz/widget-v4 4.1.117 → 4.1.119

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 (56) hide show
  1. package/assets/less/base.less +1 -0
  2. package/assets/less/chatbox.less +2 -0
  3. package/assets/less/message.less +42 -22
  4. package/assets/less/message_input.less +2 -0
  5. package/assets/less/order.less +1 -1
  6. package/assets/less/widget.less +33 -16
  7. package/assets/less/widget_header.less +35 -36
  8. package/compiled_src/chatbox/AgentsAvatar.js +1 -1
  9. package/compiled_src/chatbox/Event.js +70 -15
  10. package/compiled_src/chatbox/Events.js +108 -19
  11. package/compiled_src/chatbox/Header.js +5 -4
  12. package/compiled_src/chatbox/InfoMessage.js +2 -13
  13. package/compiled_src/chatbox/MessageInput.js +19 -9
  14. package/compiled_src/chatbox/TextMessage.js +11 -2
  15. package/compiled_src/chatbox/Widget.js +22 -21
  16. package/compiled_src/chatbox/time.js +1 -0
  17. package/compiled_src/util/common.js +89 -0
  18. package/dist/185.js +19 -19
  19. package/dist/19641cfa41e.278.js +1 -0
  20. package/dist/19641cfa41e.app.js +1 -0
  21. package/dist/{195ec5442e3.index.html → 19641cfa41e.index.html} +1 -1
  22. package/dist/{195ec5442e3.library.html → 19641cfa41e.library.html} +1 -1
  23. package/dist/19641cfa41e.library.js +1 -0
  24. package/dist/{195ec5442e3.preview.html → 19641cfa41e.preview.html} +1 -1
  25. package/dist/19641cfa41e.preview.js +1 -0
  26. package/dist/19641cfa41e.webview.js +1 -0
  27. package/dist/278.js +1 -1
  28. package/dist/HASH +1 -1
  29. package/dist/screenshoot.js +562 -185
  30. package/package.json +2 -2
  31. package/src/chatbox/AgentsAvatar.js +1 -1
  32. package/src/chatbox/Event.js +76 -15
  33. package/src/chatbox/Events.js +95 -14
  34. package/src/chatbox/Header.js +3 -2
  35. package/src/chatbox/InfoMessage.js +0 -14
  36. package/src/chatbox/MessageInput.js +18 -7
  37. package/src/chatbox/TextMessage.js +13 -0
  38. package/src/chatbox/Widget.js +13 -16
  39. package/src/chatbox/time.js +12 -8
  40. package/src/util/common.js +121 -0
  41. package/up +33 -21
  42. package/compiled_src/chatbox/Typing.js +0 -77
  43. package/dist/195ec5442e3.278.js +0 -1
  44. package/dist/195ec5442e3.app.js +0 -1
  45. package/dist/195ec5442e3.library.js +0 -1
  46. package/dist/195ec5442e3.preview.js +0 -1
  47. package/dist/195ec5442e3.webview.js +0 -1
  48. package/src/chatbox/Typing.js +0 -72
  49. /package/dist/{195ec5442e3.127.js → 19641cfa41e.127.js} +0 -0
  50. /package/dist/{195ec5442e3.132.js → 19641cfa41e.132.js} +0 -0
  51. /package/dist/{195ec5442e3.185.js → 19641cfa41e.185.js} +0 -0
  52. /package/dist/{195ec5442e3.27.js → 19641cfa41e.27.js} +0 -0
  53. /package/dist/{195ec5442e3.459.js → 19641cfa41e.459.js} +0 -0
  54. /package/dist/{195ec5442e3.490.js → 19641cfa41e.490.js} +0 -0
  55. /package/dist/{195ec5442e3.74.js → 19641cfa41e.74.js} +0 -0
  56. /package/dist/{195ec5442e3.997.js → 19641cfa41e.997.js} +0 -0
@@ -26,9 +26,64 @@ class Events extends _common.Com {
26
26
  }, 500);
27
27
  this.checkAndSeen();
28
28
  }
29
+ componentDidMount() {
30
+ this.setState({
31
+ isShowTyping: false,
32
+ typing_event: {}
33
+ });
34
+ this.props.store.onConvoEvent(this, ev => {
35
+ if (_index.default.convoOfEv(ev) !== this.props.cid) return;
36
+ if (_index.default.get(ev, 'by.type') === 'user') return;
37
+ let oldby = _index.default.get(this.state.typing_event, 'by.id');
38
+ if (oldby && _index.default.get(ev, 'by.id') !== oldby) return;
39
+ if (_index.default.get(ev, 'type') === 'message_sent') {
40
+ if (this.timer) _index.default.clearTimeout(this.timer);
41
+ this.timer = null;
42
+ this.setState({
43
+ isShowTyping: false
44
+ });
45
+ return;
46
+ }
47
+ if (_index.default.get(ev, 'type') !== 'conversation_typing') return;
48
+ let ag = this.props.store.matchAgent(_index.default.get(ev, 'by.id')) || {};
49
+ if (ag.type == 'agent' && !_index.default.get(this.props.plugin, 'chatbox.show_agent_typing')) return;
50
+ this.setState({
51
+ typing_event: ev,
52
+ isShowTyping: true
53
+ });
54
+ if (this.timer) _index.default.clearTimeout(this.timer);
55
+ this.timer = _index.default.setTimeout(() => {
56
+ if (_index.default.convoOfEv(ev) !== this.props.cid) return;
57
+ this.timer = null;
58
+ this.setState({
59
+ isShowTyping: false
60
+ });
61
+ }, 5000);
62
+ });
63
+ }
29
64
  componentDidUpdate(prevProps) {
30
65
  if (prevProps.cid !== this.props.cid) this.loadConvo();
31
66
  }
67
+ ShowTyping() {
68
+ this.setState({
69
+ isShowTyping: true,
70
+ typing_event: {
71
+ id: 'evzz' + _index.default.Date.now(),
72
+ created: _index.default.Date.now(),
73
+ by: {
74
+ type: 'agent'
75
+ },
76
+ type: 'conversation_typing'
77
+ }
78
+ });
79
+ if (this.timer) _index.default.clearTimeout(this.timer);
80
+ this.timer = _index.default.setTimeout(() => {
81
+ this.timer = null;
82
+ this.setState({
83
+ isShowTyping: false
84
+ });
85
+ }, 5000);
86
+ }
32
87
  render() {
33
88
  if (this.state.error) return this.renderError();
34
89
  let events = _index.default.map(this.props.store.listEvents(this.props.cid));
@@ -51,18 +106,36 @@ class Events extends _common.Com {
51
106
  events = _index.default.map(events, ev => ({
52
107
  ev: ev
53
108
  }));
54
- processEvents(convo, events);
55
- let lastAgentMessageSentId = '';
56
- for (let i = events.length - 1; i >= 0; i--) {
57
- let ev = _index.default.get(events, [i, 'ev']) || {};
58
- let bytype = _index.default.get(ev, 'by.type');
59
- if (bytype !== 'user' && ev.type === 'message_sent') {
60
- lastAgentMessageSentId = ev.id;
61
- break;
62
- }
109
+ if (this.state.isShowTyping) {
110
+ let ev = this.state.typing_event || {
111
+ id: 'evzz' + _index.default.Date.now(),
112
+ created: _index.default.Date.now(),
113
+ by: {
114
+ type: 'agent'
115
+ }
116
+ };
117
+ let fakeev = {
118
+ is_typing: true,
119
+ id: ev.id,
120
+ ev: {
121
+ id: ev.id,
122
+ created: ev.created,
123
+ by: ev.by,
124
+ type: 'message_sent',
125
+ data: {
126
+ message: {
127
+ text: '...',
128
+ conversation_id: this.props.cid
129
+ }
130
+ }
131
+ }
132
+ };
133
+ console.log('FA', fakeev);
134
+ events.push(fakeev);
63
135
  }
136
+ processEvents(convo, events);
64
137
  let $events = _index.default.map(events, ev => {
65
- let isLast = ev.ev.id === lastAgentMessageSentId;
138
+ let isLast = ev.ev.id === _index.default.get(convo, 'last_message_sent.id');
66
139
  return (0, _preact.h)(_Event.default, {
67
140
  isLast: isLast,
68
141
  chatbox: this.props.chatbox,
@@ -78,7 +151,7 @@ class Events extends _common.Com {
78
151
  });
79
152
  let $loading = null;
80
153
  let style = 'opacity: 1 !important';
81
- if (this.state.loading || this.props.creating) {
154
+ if (this.props.creating) {
82
155
  $loading = (0, _preact.h)(_spinner.default, {
83
156
  static: true,
84
157
  mode: _index.default.get(this.props.chatbox, 'primary_color', 'dark'),
@@ -87,6 +160,17 @@ class Events extends _common.Com {
87
160
  });
88
161
  style = 'opacity: 0 !important';
89
162
  }
163
+ if (this.state.loading) {
164
+ if (_index.default.Date.now() - this.state.loading > 500) {
165
+ $loading = (0, _preact.h)(_spinner.default, {
166
+ static: true,
167
+ mode: _index.default.get(this.props.chatbox, 'primary_color', 'dark'),
168
+ size: "120",
169
+ center: true
170
+ });
171
+ style = 'opacity: 0 !important';
172
+ }
173
+ }
90
174
  return (0, _preact.h)(_preact.Fragment, null, $loading, (0, _preact.h)("div", {
91
175
  style: style,
92
176
  ref: ref => this.refBody = ref,
@@ -154,10 +238,16 @@ class Events extends _common.Com {
154
238
  if (!this.props.cid) return;
155
239
  this.lastContentOffsetY = 0;
156
240
  this.setState({
157
- loading: true
241
+ loading: false
158
242
  });
159
243
  let events = this.props.store.listEvents(this.props.cid);
160
244
  if (_index.default.size(events) === 0) {
245
+ this.setState({
246
+ loading: _index.default.Date.now()
247
+ });
248
+ _index.default.setTimeout(() => {
249
+ this.forceUpdate();
250
+ }, 800);
161
251
  let cid = this.props.cid;
162
252
  let {
163
253
  error
@@ -173,17 +263,11 @@ class Events extends _common.Com {
173
263
  return;
174
264
  }
175
265
  }
176
- this.setState({
177
- loading: true
178
- });
179
266
  this.props.store.fetchMoreEvents(this.props.cid);
180
267
  this.setState({
181
268
  error: false
182
269
  });
183
270
  this.scrollToBottom();
184
- _index.default.setTimeout(() => this.setState({
185
- loading: false
186
- }), 50);
187
271
  }
188
272
  isBottom() {
189
273
  let $container = this.refBody;
@@ -198,7 +282,7 @@ class Events extends _common.Com {
198
282
  _index.default.setTimeout(() => {
199
283
  const $div = this.refBody;
200
284
  if ($div) $div.scrollTop = $div.scrollHeight;
201
- }, 200);
285
+ }, 100);
202
286
  if (this.props.isShow) {
203
287
  if (this.props.store.browserVisibility === 'visible' && document.hasFocus()) {
204
288
  this.props.store.seenConvo(this.props.cid);
@@ -210,14 +294,19 @@ exports.default = Events;
210
294
  function processEvents(convo, events) {
211
295
  events = events.filter(event => visibleEvent(event.ev));
212
296
  if (events.length < 1) return;
297
+ var lastAgentEvent;
213
298
  for (var i = 1; i < events.length; i++) {
214
299
  let curEvent = events[i];
215
300
  let lastEvent = events[i - 1];
301
+ if (_index.default.get(curEvent, 'ev.by.type') != 'user' && !curEvent.is_typing) {
302
+ lastAgentEvent = curEvent;
303
+ }
216
304
  if (visibleEvent(curEvent.ev)) {
217
305
  let elapsedSec = _index.default.unixSec(curEvent.ev.created) - _index.default.unixSec(lastEvent.ev.created);
218
306
  if (elapsedSec > 120) curEvent.show_time = true;
219
307
  }
220
308
  }
309
+ if (lastAgentEvent) lastAgentEvent.show_time = true;
221
310
  for (var i = 0; i < events.length; i++) {
222
311
  let curEvent = events[i];
223
312
  if (_index.default.get(curEvent, 'ev.type') === 'message_sent') {
@@ -49,11 +49,12 @@ class Header extends _common.Com {
49
49
  return (0, _preact.h)("div", {
50
50
  class: cls,
51
51
  style: style
52
- }, $back, (0, _preact.h)(_AgentsAvatar.default, {
52
+ }, $back, (0, _preact.h)("div", {
53
+ class: "mr-2"
54
+ }), (0, _preact.h)(_AgentsAvatar.default, {
53
55
  plugin: this.props.plugin,
54
56
  store: this.props.store,
55
- mode: "secondary",
56
- agent_ids: agentIdsJoined
57
+ mode: "secondary"
57
58
  }), (0, _preact.h)("div", {
58
59
  class: "widget-header--title-container"
59
60
  }, (0, _preact.h)("div", {
@@ -188,7 +189,7 @@ Vui lòng hỏi chúng tôi bất cứ điều gì hoặc chia sẻ phản hồi
188
189
  let accSetting = this.props.plugin.chatbox || {};
189
190
  if (accSetting.hide_close_button) return null;
190
191
  return (0, _preact.h)("div", {
191
- class: "widget-header--button widget-header--button-close",
192
+ class: "widget-header--button-close",
192
193
  "data-tooltip": this.props.t('close'),
193
194
  "data-tooltip-position": "bottom",
194
195
  onClick: e => this.onCloseClick(e)
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _index = _interopRequireDefault(require("../util/index.js"));
8
- var _time = _interopRequireDefault(require("./time.js"));
9
8
  var _common = require("../common.js");
10
9
  var _preact = require("preact");
11
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -18,16 +17,6 @@ function getRateLang(rating) {
18
17
  class InfoMessage extends _common.Com {
19
18
  render() {
20
19
  let ev = this.props.ev.ev;
21
- var $time = null;
22
- if (this.props.ev.show_time) {
23
- $time = (0, _preact.h)("div", {
24
- class: "convo-event-time"
25
- }, (0, _preact.h)(_time.default, {
26
- time: ev.created,
27
- t: this.props.t
28
- }));
29
- }
30
- if (this.props.store.isAIDevMode()) $time = null;
31
20
  if (ev.type === 'conversation_rated') {
32
21
  var rating = _index.default.get(ev, 'data.conversation.ratings.0', {
33
22
  no_rating: true,
@@ -36,14 +25,14 @@ class InfoMessage extends _common.Com {
36
25
  if (rating.no_rating) return null;
37
26
  return (0, _preact.h)("div", {
38
27
  class: "convo-event"
39
- }, $time, (0, _preact.h)("div", {
28
+ }, (0, _preact.h)("div", {
40
29
  class: "info-message"
41
30
  }, this.props.t('rated_as') + ' ' + this.props.t(getRateLang(rating.rating)).toLowerCase()));
42
31
  }
43
32
  if (ev.type === 'conversation_state_updated' && _index.default.get(ev, 'data.conversation.state') === 'ended') {
44
33
  return (0, _preact.h)("div", {
45
34
  class: "convo-event"
46
- }, $time, (0, _preact.h)("div", {
35
+ }, (0, _preact.h)("div", {
47
36
  class: "info-message"
48
37
  }, this.props.t('conversation_ended')));
49
38
  }
@@ -7,6 +7,7 @@ exports.default = void 0;
7
7
  var _index = _interopRequireDefault(require("../util/index.js"));
8
8
  var _common = require("../common.js");
9
9
  var _preact = require("preact");
10
+ var _spinner = _interopRequireDefault(require("./spinner.js"));
10
11
  var _Emoji = _interopRequireDefault(require("./Emoji.js"));
11
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
13
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
@@ -43,7 +44,7 @@ class MessageInput extends _common.Com {
43
44
  $input.blur();
44
45
  }
45
46
  render() {
46
- var buttons = (0, _preact.h)("div", {
47
+ var $buttons = (0, _preact.h)("div", {
47
48
  class: "d-flex flex-row align-self-end"
48
49
  }, this.renderEmoji(), (0, _preact.h)("div", {
49
50
  "data-tooltip-poasition": "top-left",
@@ -52,7 +53,7 @@ class MessageInput extends _common.Com {
52
53
  }));
53
54
  var msg = _index.default.trim(this.state.msgValue);
54
55
  if (msg.length > 0) {
55
- buttons = (0, _preact.h)("div", {
56
+ $buttons = (0, _preact.h)("div", {
56
57
  class: "d-flex flex-row align-self-end"
57
58
  }, this.renderEmoji(), (0, _preact.h)("div", {
58
59
  "data-tooltip-position": "top-left",
@@ -60,9 +61,16 @@ class MessageInput extends _common.Com {
60
61
  onClick: () => this.submitMessage()
61
62
  }));
62
63
  }
64
+ if (this.props.is_loading) {
65
+ $buttons = (0, _preact.h)("div", {
66
+ class: "d-flex flex-row align-self-end"
67
+ }, (0, _preact.h)(_spinner.default, {
68
+ size: "32"
69
+ }));
70
+ }
63
71
  var containercls = '';
64
72
  var disabled = this.hasUnfinishRequiredFormOrLock() || this.props.disabled;
65
- if (disabled) containercls = 'message-input--disabled';
73
+ if (disabled || this.props.is_loading) containercls = 'message-input--disabled';
66
74
  return (0, _preact.h)("div", {
67
75
  class: `message-input ${containercls}`,
68
76
  onClick: e => {
@@ -78,7 +86,7 @@ class MessageInput extends _common.Com {
78
86
  disabled: disabled,
79
87
  class: "message-input--input",
80
88
  maxlength: "1024",
81
- placeholder: this.props.t('message_input_help'),
89
+ placeholder: this.props.t('message_input_help').substr(0, 25),
82
90
  ref: this.refMessageInput,
83
91
  rows: "1",
84
92
  value: this.state.msgValue,
@@ -86,7 +94,7 @@ class MessageInput extends _common.Com {
86
94
  onPaste: e => this.pasteImage(e),
87
95
  "data-emojiable": "true",
88
96
  onKeydown: e => this.onKeydown(e)
89
- }), buttons);
97
+ }), $buttons);
90
98
  }
91
99
  hasUnfinishRequiredFormOrLock() {
92
100
  let convo = this.props.store.matchConvo(this.props.cid);
@@ -298,15 +306,17 @@ class MessageInput extends _common.Com {
298
306
  msg = msg || _index.default.trim(this.state.msgValue) || '';
299
307
  if (!msg) return;
300
308
  if (this.props.disabled) return;
309
+ if (this.props.onSend) {
310
+ await this.props.onSend({
311
+ text: msg,
312
+ format: 'plaintext'
313
+ });
314
+ }
301
315
  this.setState({
302
316
  openEmoji: false,
303
317
  msgValue: ''
304
318
  });
305
319
  this.resizeInput();
306
- this.props.onSend && this.props.onSend({
307
- text: msg,
308
- format: 'plaintext'
309
- });
310
320
  }
311
321
  sendTyping() {
312
322
  if (!this.props.cid) return;
@@ -9,8 +9,17 @@ var _block = _interopRequireDefault(require("./block.js"));
9
9
  var _common = require("../common.js");
10
10
  var _preact = require("preact");
11
11
  var _Emoji = _interopRequireDefault(require("./Emoji.js"));
12
+ var _time = _interopRequireDefault(require("./time.js"));
12
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
14
  class TextMessage extends _common.Com {
15
+ renderTime() {
16
+ if (!this.props.showTime && !this.props.isLast && !this.props.isFirst) return null;
17
+ return (0, _preact.h)("div", null, (0, _preact.h)(_time.default, {
18
+ class: "inline-time",
19
+ time: _index.default.get(this.props.ev, 'created', _index.default.Date.now()),
20
+ t: this.props.t
21
+ }));
22
+ }
14
23
  render() {
15
24
  var format = _index.default.get(this.props.ev, 'data.message.format', 'plaintext');
16
25
  let block = _index.default.get(this.props.ev, 'data.message.block');
@@ -52,7 +61,7 @@ class TextMessage extends _common.Com {
52
61
  if (byType === 'agent') return (0, _preact.h)("div", {
53
62
  class: "message-agent message-text--agent",
54
63
  title: t
55
- }, tags);
64
+ }, tags, this.renderTime());
56
65
  return (0, _preact.h)("div", {
57
66
  class: "message-user message-text--user",
58
67
  title: t
@@ -70,7 +79,7 @@ class TextMessage extends _common.Com {
70
79
  }, (0, _preact.h)(_block.default, {
71
80
  block: block,
72
81
  onLink: this.props.onLink
73
- }));
82
+ }), this.renderTime());
74
83
  }
75
84
  return (0, _preact.h)("div", {
76
85
  class: "message-user message-text--user",
@@ -11,10 +11,8 @@ var _AgentsAvatar = _interopRequireDefault(require("./AgentsAvatar.js"));
11
11
  var _Header = _interopRequireDefault(require("./Header.js"));
12
12
  var _MessageInput = _interopRequireDefault(require("./MessageInput.js"));
13
13
  var _Events = _interopRequireDefault(require("./Events.js"));
14
- var _Typing = _interopRequireDefault(require("./Typing.js"));
15
14
  var _Rating = _interopRequireDefault(require("./Rating.js"));
16
15
  var _ListField = _interopRequireDefault(require("./ListField.js"));
17
- var _spinner = _interopRequireDefault(require("./spinner.js"));
18
16
  var _time = _interopRequireDefault(require("./time.js"));
19
17
  var _common = require("../common.js");
20
18
  var _preact = require("preact");
@@ -73,26 +71,33 @@ class Widget extends _common.Com {
73
71
  initial_by: this.props.store.matchUser().id
74
72
  });
75
73
  if (_creating != this._creating) return;
76
- if (error) {}
74
+ if (error) {
75
+ this.setState({
76
+ creating: false
77
+ });
78
+ return;
79
+ }
77
80
  await this.props.store.sendConvoEvent(convo.id, 'message_sent', {
78
81
  message
79
82
  });
80
83
  if (_creating != this._creating) return;
81
- this.setState({
82
- creating: false
83
- });
84
84
  this.props.onGo({
85
85
  view: 'chat',
86
86
  cid: convo.id
87
87
  });
88
+ this.setState({
89
+ creating: false
90
+ });
88
91
  return;
89
92
  }
90
- await this.props.store.sendConvoEvent(this.props.cid, 'message_sent', {
91
- message
92
- });
93
- this.setState({
94
- creating: false
95
- });
93
+ _index.default.setTimeout(async () => {
94
+ await this.props.store.sendConvoEvent(this.props.cid, 'message_sent', {
95
+ message
96
+ });
97
+ this.setState({
98
+ creating: false
99
+ });
100
+ }, 1);
96
101
  });
97
102
  _defineProperty(this, "onLink", (e, url) => {
98
103
  if (!url) return e.preventDefault();
@@ -151,14 +156,14 @@ class Widget extends _common.Com {
151
156
  quickReplyMessage: {}
152
157
  });
153
158
  _index.default.setTimeout(() => {
154
- this.events && this.events.focus();
159
+ this.$events && this.$events.focus();
155
160
  if (!this.props.store.isMobile()) this.focusInput();
156
161
  }, 100);
157
162
  this.updateFormDataFields();
158
163
  }
159
164
  }
160
165
  ShowTyping() {
161
- this.refTyping.current && this.refTyping.current.ShowTyping();
166
+ this.$events && this.$events.ShowTyping();
162
167
  }
163
168
  shouldShowForm() {
164
169
  let form;
@@ -783,6 +788,7 @@ class Widget extends _common.Com {
783
788
  ref: this.msgInput,
784
789
  cid: this.props.cid,
785
790
  onChange: this.onChangeMessageInput,
791
+ is_loading: this.state.creating,
786
792
  onSend: this.sendMessage,
787
793
  t: this.props.t
788
794
  });
@@ -806,18 +812,13 @@ class Widget extends _common.Com {
806
812
  store: this.props.store,
807
813
  chatbox: this.props.plugin.chatbox || {},
808
814
  onFormSubmit: e => this.onEventFormSubmit(e),
809
- ref: ref => this.events = ref,
815
+ ref: ref => this.$events = ref,
810
816
  cid: this.props.cid,
811
817
  creating: this.creating,
812
818
  onSend: e => this.sendMessage(e),
813
819
  onPostback: e => this.createPostback(e),
814
- t: this.props.t
815
- }), (0, _preact.h)(_Typing.default, {
816
- store: this.props.store,
817
- cid: this.props.cid,
818
820
  t: this.props.t,
819
- plugin: this.props.plugin,
820
- ref: this.refTyping
821
+ plugin: this.props.plugin
821
822
  })), (0, _preact.h)(_Rating.default, {
822
823
  forceView: this.props.view,
823
824
  plugin: this.props.plugin,
@@ -49,6 +49,7 @@ class Time extends _common.Com {
49
49
  }
50
50
  let title = new Date(this.props.time).toLocaleString(locale);
51
51
  return (0, _preact.h)("span", {
52
+ class: this.props.class,
52
53
  style: this.props.style,
53
54
  title: title
54
55
  }, this.state.t);
@@ -29,6 +29,7 @@ exports.getDayName = getDayName;
29
29
  exports.getMs = getMs;
30
30
  exports.getUrlParameter = getUrlParameter;
31
31
  exports.getUserAttr = getUserAttr;
32
+ exports.hslToRgb = hslToRgb;
32
33
  exports.includes = includes;
33
34
  exports.isConvoSeen = isConvoSeen;
34
35
  exports.isEmail = isEmail;
@@ -54,6 +55,7 @@ exports.replaceAll = replaceAll;
54
55
  exports.replaceCssVariable = replaceCssVariable;
55
56
  exports.replaceCssVariablePlugin = replaceCssVariablePlugin;
56
57
  exports.requestAnimationFrame = void 0;
58
+ exports.rgbToHsl = rgbToHsl;
57
59
  exports.sameDay = sameDay;
58
60
  exports.scrollIntoViewIfNeeded = scrollIntoViewIfNeeded;
59
61
  exports.setCss = setCss;
@@ -72,6 +74,55 @@ exports.unicodeToAscii = unicodeToAscii;
72
74
  exports.unixSec = unixSec;
73
75
  exports.usersOfConvo = usersOfConvo;
74
76
  var op = require('./op.js');
77
+ function rgbToHsl(r, g, b) {
78
+ ;
79
+ r /= 255, g /= 255, b /= 255;
80
+ var max = Math.max(r, g, b),
81
+ min = Math.min(r, g, b);
82
+ var h,
83
+ s,
84
+ l = (max + min) / 2;
85
+ if (max == min) {
86
+ h = s = 0;
87
+ } else {
88
+ var d = max - min;
89
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
90
+ switch (max) {
91
+ case r:
92
+ h = (g - b) / d + (g < b ? 6 : 0);
93
+ break;
94
+ case g:
95
+ h = (b - r) / d + 2;
96
+ break;
97
+ case b:
98
+ h = (r - g) / d + 4;
99
+ break;
100
+ }
101
+ h /= 6;
102
+ }
103
+ return [h, s, l];
104
+ }
105
+ function hslToRgb(h, s, l) {
106
+ var r, g, b;
107
+ if (s == 0) {
108
+ r = g = b = l;
109
+ } else {
110
+ function hue2rgb(p, q, t) {
111
+ if (t < 0) t += 1;
112
+ if (t > 1) t -= 1;
113
+ if (t < 1 / 6) return p + (q - p) * 6 * t;
114
+ if (t < 1 / 2) return q;
115
+ if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
116
+ return p;
117
+ }
118
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
119
+ var p = 2 * l - q;
120
+ r = hue2rgb(p, q, h + 1 / 3);
121
+ g = hue2rgb(p, q, h);
122
+ b = hue2rgb(p, q, h - 1 / 3);
123
+ }
124
+ return [r * 255, g * 255, b * 255];
125
+ }
75
126
  function extractEmojis(text) {
76
127
  var out = [];
77
128
  for (var i = 0; i < text.length; i++) {
@@ -201,6 +252,8 @@ function parseJSON(str) {
201
252
  var f = document.createElement('iframe');
202
253
  f.style.display = 'none';
203
254
  document.documentElement.appendChild(f);
255
+ const tempElement = f.contentDocument.createElement('div');
256
+ f.contentDocument.body.appendChild(tempElement);
204
257
  var stringify = exports.stringify = f.contentWindow.JSON.stringify;
205
258
  var parse = f.contentWindow.JSON.parse;
206
259
  var Date = exports.Date = f.contentWindow.Date;
@@ -508,6 +561,16 @@ function replaceCssVariablePlugin(css, setting) {
508
561
  tokens = tokenize(tokens, "'@spacer0'");
509
562
  tokens = tokenize(tokens, "'@spacer2'");
510
563
  tokens = tokenize(tokens, "'@spacer3'");
564
+ var primary_color = op.get(setting, 'primary_color') || op.get(DEFVAL, 'primary_color');
565
+ let parseColor = parseCssColor(primary_color);
566
+ if (!parseColor) parseColor = {
567
+ red: 238,
568
+ blue: 238,
569
+ green: 238
570
+ };
571
+ let hue = rgbToHsl(parseColor.red, parseColor.green, parseColor.blue)[0];
572
+ let [r, g, b] = hslToRgb(hue, 0.5, 0.95);
573
+ DEFVAL.primary_color_faded = `rgb(${r},${g},${b})`;
511
574
  var ret = [];
512
575
  for (var i = 0; i < tokens.length; i++) {
513
576
  var item = tokens[i];
@@ -524,6 +587,7 @@ function replaceCssVariablePlugin(css, setting) {
524
587
  function replaceCssVariable(css, setting) {
525
588
  var tokens = [css];
526
589
  tokens = tokenize(tokens, "'@primary_color'");
590
+ tokens = tokenize(tokens, "'@primary_color_faded'");
527
591
  tokens = tokenize(tokens, '@esc-primary-color-esc');
528
592
  tokens = tokenize(tokens, "'@secondary_color'");
529
593
  tokens = tokenize(tokens, "'@background'");
@@ -548,6 +612,16 @@ function replaceCssVariable(css, setting) {
548
612
  tokens = tokenize(tokens, "'@z_index_3'");
549
613
  tokens = tokenize(tokens, "'@z_index_4'");
550
614
  tokens = tokenize(tokens, "'@z_index_5'");
615
+ var primary_color = op.get(setting, 'primary_color') || op.get(DEFVAL, 'primary_color');
616
+ let parseColor = parseCssColor(primary_color);
617
+ if (!parseColor) parseColor = {
618
+ red: 238,
619
+ blue: 238,
620
+ green: 238
621
+ };
622
+ let hue = rgbToHsl(parseColor.red, parseColor.green, parseColor.blue)[0];
623
+ let [r, g, b] = hslToRgb(hue, 0.5, 0.95);
624
+ DEFVAL.primary_color_faded = `rgb(${r},${g},${b})`;
551
625
  var ret = [];
552
626
  for (var i = 0; i < tokens.length; i++) {
553
627
  var item = tokens[i];
@@ -1175,6 +1249,21 @@ function _blockToText(block) {
1175
1249
  });
1176
1250
  return out;
1177
1251
  }
1252
+ function parseCssColor(color) {
1253
+ if (!color || !color.split) return '';
1254
+ tempElement.style.color = color;
1255
+ const computedColor = f.contentWindow.getComputedStyle(tempElement).color;
1256
+ const match = computedColor.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)/);
1257
+ if (match) {
1258
+ return {
1259
+ red: parseInt(match[1]),
1260
+ green: parseInt(match[2]),
1261
+ blue: parseInt(match[3])
1262
+ };
1263
+ } else {
1264
+ return null;
1265
+ }
1266
+ }
1178
1267
  let emojis = ['like', 'unlike', 'wink', 'tongue-out', 'tired', 'surprised', 'smiling', 'sleepy', 'sad', 'neutral', 'heart-eyes', 'grinning', 'crying', 'confused', 'angry', 'cry', 'heart_eyes', 'neutral_face', 'emoji--disappointed', 'smile', 'open_mouth', 'tired_face', 'stuck_out_tongue', 'moyai', 'thumbsdown', 'dislike', 'thumbsup', 'ok_hand', 'octopus', 'pig2', 'wave', 'mouse', 'mouse2', 'rat'];
1179
1268
  emojis = map(emojis, e => ':' + e + ':');
1180
1269
  function absLink(url) {