@subiz/widget-v4 4.1.210 → 4.1.211

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 (124) hide show
  1. package/README.md +21 -2
  2. package/assets/less/chatbox.less +9 -0
  3. package/assets/less/form.less +10 -0
  4. package/assets/less/message.less +114 -13
  5. package/assets/less/widget.less +21 -16
  6. package/compiled_src/call/css.js +1 -1
  7. package/compiled_src/chatbox/Buttons.js +7 -4
  8. package/compiled_src/chatbox/ChatButton.js +115 -29
  9. package/compiled_src/chatbox/Event.js +37 -5
  10. package/compiled_src/chatbox/Events.js +348 -129
  11. package/compiled_src/chatbox/FormAttachment.js +1 -1
  12. package/compiled_src/chatbox/Header.js +6 -2
  13. package/compiled_src/chatbox/InfoMessage.js +1 -1
  14. package/compiled_src/chatbox/MessageInput.js +24 -9
  15. package/compiled_src/chatbox/OrderAttachments.js +13 -13
  16. package/compiled_src/chatbox/QuoteMessage.js +3 -2
  17. package/compiled_src/chatbox/TextMessage.js +22 -18
  18. package/compiled_src/chatbox/Widget.js +200 -129
  19. package/compiled_src/chatbox/block.js +39 -29
  20. package/compiled_src/chatbox/conversation-history.js +44 -0
  21. package/compiled_src/chatbox/event-layout.js +59 -0
  22. package/compiled_src/chatbox/greeting.js +32 -0
  23. package/compiled_src/common.js +13 -9
  24. package/compiled_src/form/css.js +1 -1
  25. package/compiled_src/lib.js +22 -32
  26. package/compiled_src/notif/css.js +1 -1
  27. package/compiled_src/plugin.js +11 -18
  28. package/compiled_src/popup/css.js +1 -1
  29. package/compiled_src/popup/popup.js +1 -1
  30. package/compiled_src/store/api.js +0 -2
  31. package/compiled_src/store/api_fake.js +1 -1
  32. package/compiled_src/store/attachments.js +28 -0
  33. package/compiled_src/store/chain.js +24 -10
  34. package/compiled_src/store/kv.js +9 -13
  35. package/compiled_src/store/lsdb.js +1 -1
  36. package/compiled_src/store/store.js +356 -117
  37. package/compiled_src/util/common.js +48 -41
  38. package/compiled_src/util/event.js +15 -0
  39. package/compiled_src/util/pubsub.js +28 -13
  40. package/compiled_src/util/url.js +18 -0
  41. package/dist/.HASH +1 -0
  42. package/dist/127.js +13 -13
  43. package/dist/132.js +1 -1
  44. package/dist/1a0ddc53cbb.127.js +1 -0
  45. package/dist/{1a0d80f6e72.132.js → 1a0ddc53cbb.132.js} +1 -1
  46. package/dist/1a0ddc53cbb.278.js +1 -0
  47. package/dist/{1a0d80f6e72.339.js → 1a0ddc53cbb.339.js} +1 -1
  48. package/dist/1a0ddc53cbb.app.js +1 -0
  49. package/dist/{1a0d80f6e72.chat.html → 1a0ddc53cbb.chat.html} +1 -1
  50. package/dist/1a0ddc53cbb.chat.js +1 -0
  51. package/dist/{1a0d80f6e72.form.html → 1a0ddc53cbb.form.html} +1 -1
  52. package/dist/1a0ddc53cbb.form.js +1 -0
  53. package/dist/{1a0d80f6e72.index.html → 1a0ddc53cbb.index.html} +1 -1
  54. package/dist/{1a0d80f6e72.library.html → 1a0ddc53cbb.library.html} +1 -1
  55. package/dist/1a0ddc53cbb.library.js +1 -0
  56. package/dist/{1a0d80f6e72.preview.html → 1a0ddc53cbb.preview.html} +1 -1
  57. package/dist/1a0ddc53cbb.preview.js +1 -0
  58. package/dist/1a0ddc53cbb.webview.js +1 -0
  59. package/dist/screenshoot.js +1492 -616
  60. package/package.json +10 -3
  61. package/src/chatbox/Buttons.js +5 -4
  62. package/src/chatbox/ChatButton.js +120 -39
  63. package/src/chatbox/Event.js +38 -5
  64. package/src/chatbox/Events.js +306 -134
  65. package/src/chatbox/FormAttachment.js +1 -1
  66. package/src/chatbox/Header.js +4 -4
  67. package/src/chatbox/InfoMessage.js +1 -1
  68. package/src/chatbox/MessageInput.js +15 -10
  69. package/src/chatbox/OrderAttachments.js +13 -13
  70. package/src/chatbox/QuoteMessage.js +3 -2
  71. package/src/chatbox/TextMessage.js +21 -20
  72. package/src/chatbox/Widget.js +150 -150
  73. package/src/chatbox/block.js +29 -27
  74. package/src/chatbox/conversation-history.js +37 -0
  75. package/src/chatbox/event-layout.js +72 -0
  76. package/src/chatbox/greeting.js +13 -0
  77. package/src/common.js +15 -9
  78. package/src/lib.js +22 -35
  79. package/src/plugin.js +11 -13
  80. package/src/popup/popup.js +1 -1
  81. package/src/store/api.js +0 -2
  82. package/src/store/api_fake.js +1 -1
  83. package/src/store/attachments.js +21 -0
  84. package/src/store/chain.js +25 -12
  85. package/src/store/kv.js +10 -19
  86. package/src/store/lsdb.js +1 -1
  87. package/src/store/store.js +313 -130
  88. package/src/util/common.js +48 -43
  89. package/src/util/event.js +7 -0
  90. package/src/util/pubsub.js +27 -8
  91. package/src/util/url.js +14 -0
  92. package/test.cjs +59 -0
  93. package/assets/less/contact.less +0 -126
  94. package/compiled_src/util/common.test.js +0 -414
  95. package/compiled_src/util/event.test.js +0 -38
  96. package/compiled_src/util/extractor.test.js +0 -299
  97. package/compiled_src/util/extractor.test2.js +0 -61
  98. package/compiled_src/util/gate.test.js +0 -18
  99. package/compiled_src/util/pubsub.test.js +0 -35
  100. package/dist/1a0d80f6e72.127.js +0 -1
  101. package/dist/1a0d80f6e72.278.js +0 -1
  102. package/dist/1a0d80f6e72.74.js +0 -1
  103. package/dist/1a0d80f6e72.997.js +0 -1
  104. package/dist/1a0d80f6e72.app.js +0 -1
  105. package/dist/1a0d80f6e72.chat.js +0 -1
  106. package/dist/1a0d80f6e72.form.js +0 -1
  107. package/dist/1a0d80f6e72.library.js +0 -1
  108. package/dist/1a0d80f6e72.preview.js +0 -1
  109. package/dist/1a0d80f6e72.webview.js +0 -1
  110. package/dist/74.js +0 -376
  111. package/dist/997.js +0 -37
  112. package/dist/HASH +0 -1
  113. package/src/contact/contact.js +0 -400
  114. package/src/contact/css.js +0 -1
  115. package/src/util/common.test.js +0 -301
  116. package/src/util/event.test.js +0 -31
  117. package/src/util/extractor.test.js +0 -240
  118. package/src/util/extractor.test2.js +0 -56
  119. package/src/util/gate.test.js +0 -20
  120. package/src/util/pubsub.test.js +0 -37
  121. /package/dist/{1a0d80f6e72.185.js → 1a0ddc53cbb.185.js} +0 -0
  122. /package/dist/{1a0d80f6e72.27.js → 1a0ddc53cbb.27.js} +0 -0
  123. /package/dist/{1a0d80f6e72.459.js → 1a0ddc53cbb.459.js} +0 -0
  124. /package/dist/{1a0d80f6e72.490.js → 1a0ddc53cbb.490.js} +0 -0
@@ -8,6 +8,7 @@ var _index = _interopRequireDefault(require("../util/index.js"));
8
8
  var _Emoji = _interopRequireDefault(require("./Emoji.js"));
9
9
  var _common = require("../common.js");
10
10
  var _preact = require("preact");
11
+ var _url = require("../util/url.js");
11
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
13
  class Block extends _common.Com {
13
14
  constructor(props) {
@@ -44,9 +45,8 @@ class Block extends _common.Com {
44
45
  ele.tag = 'li';
45
46
  }
46
47
  if (block.type == 'heading') {
47
- if (block.level < 1) block.level = 1;
48
- if (block.level > 6) block.level = 6;
49
- ele.tag = 'h' + block.level;
48
+ let level = Math.max(1, Math.min(6, Math.floor(Number(block.level) || 1)));
49
+ ele.tag = 'h' + level;
50
50
  }
51
51
  if (block.type == 'paragraph' || block.type == 'section' || block.type == 'div') ele.tag = 'div';
52
52
  ele.text = block.text;
@@ -60,8 +60,10 @@ class Block extends _common.Com {
60
60
  ele.tag = 'em';
61
61
  }
62
62
  }
63
- if (block.underline) ele.Style += 'text-decoration:underline;';
64
- if (block.strike_through) ele.Style += 'text-decoration: line-through;';
63
+ let decorations = [];
64
+ if (block.underline) decorations.push('underline');
65
+ if (block.strike_through) decorations.push('line-through');
66
+ if (decorations.length) ele.style += 'text-decoration: ' + decorations.join(' ') + ' !important;';
65
67
  }
66
68
  if (block.type == 'dynamic-field') {
67
69
  let key = _index.default.get(block.attrs, 'key');
@@ -69,20 +71,20 @@ class Block extends _common.Com {
69
71
  }
70
72
  if (block.type == 'link') {
71
73
  ele.tag = 'a';
72
- ele.attrs['href'] = block.href;
74
+ ele.attrs['href'] = (0, _url.safeUrl)(block.href);
73
75
  ele.attrs['target'] = block.target;
74
76
  ele.attrs['title'] = block.title;
75
77
  }
76
78
  if (block.type == 'mention-agent' || block.type == 'mention') {
77
79
  ele.tag = 'span';
78
80
  ele.class = 'mention';
79
- let id = block.attrs.id = '';
80
- if (block.attrs.id == '*' || block.attrs.id == 'all') {
81
- ele.text = '@' + this.$t('all');
81
+ let id = _index.default.get(block, 'attrs.id', '');
82
+ if (id == '*' || id == 'all') {
83
+ ele.text = '@' + (this.props.t ? this.props.t('all') : 'all');
82
84
  }
83
- if (id.startsWith('ag')) {
84
- let ag = store.matchAgent(id);
85
- let name = _index.default.getAgentDisplayName(ag, insert.mention.fullname);
85
+ if (typeof id === 'string' && /^(ag|at)/.test(id) && this.props.store) {
86
+ let ag = this.props.store.matchAgent(id);
87
+ let name = _index.default.getAgentDisplayName(this.props.store.matchAccount(), ag);
86
88
  ele.text = '@' + name;
87
89
  }
88
90
  }
@@ -90,18 +92,15 @@ class Block extends _common.Com {
90
92
  if (block.type == 'emoji') {
91
93
  let code = '';
92
94
  if (_index.default.size(block.attrs) > 0) code = block.attrs['code'];
93
- if (code == '') code = block.Text;
95
+ if (!code) code = block.text || block.Text;
94
96
  if (code != '') {
95
97
  ele.tag = 'Emoji';
96
98
  ele.attrs['emojiCode'] = code;
97
99
  }
98
100
  }
99
- if (block.type == 'table') {
100
- return null;
101
- }
102
101
  if (block.type === 'image') {
103
102
  ele.tag = 'img';
104
- ele.attrs['src'] = _index.default.get(block, 'image.url');
103
+ ele.attrs['src'] = (0, _url.safeUrl)(_index.default.get(block, 'image.url'), true);
105
104
  ele.attrs['alt'] = block.alt_text;
106
105
  }
107
106
  if (block.type == 'hard_break') {
@@ -118,10 +117,13 @@ class Block extends _common.Com {
118
117
  if (!url.startsWith('//') && !url.startsWith('https://') && !url.startsWith('http://') && !url.startsWith('data:')) {
119
118
  url = '//' + url;
120
119
  }
120
+ url = (0, _url.safeUrl)(url);
121
+ if (!url) return tag.text;
121
122
  return (0, _preact.h)("a", {
122
123
  href: url,
123
124
  target: "_blank",
124
- onClick: e => this.props.onLink(e, url)
125
+ rel: "noopener noreferrer",
126
+ onClick: e => this.props.onLink && this.props.onLink(e, url)
125
127
  }, tag.text);
126
128
  }
127
129
  if (tag.type === 'phone') return (0, _preact.h)("a", {
@@ -138,10 +140,12 @@ class Block extends _common.Com {
138
140
  }
139
141
  switch (ele.tag) {
140
142
  case 'img':
143
+ if (!ele.attrs.src) return block.alt_text || null;
141
144
  return (0, _preact.h)("a", {
142
145
  class: this.props.textMessage ? 'message-text-inline-image-wrapper' : '',
143
146
  href: _index.default.get(ele, 'attrs.src'),
144
- target: "_blank"
147
+ target: "_blank",
148
+ rel: "noopener noreferrer"
145
149
  }, (0, _preact.h)("img", {
146
150
  class: this.props.textMessage ? 'message-text-inline-image' : '',
147
151
  src: _index.default.get(ele, 'attrs.src'),
@@ -182,35 +186,41 @@ class Block extends _common.Com {
182
186
  class: this.props.textMessage ? 'text-message-li' : ''
183
187
  }, $body);
184
188
  case 'span':
185
- return (0, _preact.h)("span", null, $body);
189
+ return (0, _preact.h)("span", {
190
+ class: ele.class,
191
+ style: ele.style
192
+ }, $body);
186
193
  case 'em':
187
- return (0, _preact.h)("em", null, $body);
194
+ return (0, _preact.h)("em", {
195
+ style: ele.style
196
+ }, $body);
188
197
  case 'b':
189
- return (0, _preact.h)("b", null, $body);
198
+ return (0, _preact.h)("b", {
199
+ style: ele.style
200
+ }, $body);
190
201
  case 'hr':
191
202
  return (0, _preact.h)("hr", null);
192
203
  case 'br':
193
204
  return (0, _preact.h)("br", null);
194
205
  case 'a':
206
+ if (!ele.attrs.href) return (0, _preact.h)("span", null, $body);
195
207
  return (0, _preact.h)("a", {
196
208
  class: this.props.textMessage ? 'message-text-link' : '',
197
209
  href: ele.attrs['href'],
198
210
  target: this.props.textMessage ? '_blank' : ele.attrs['target'],
199
- title: ele.attrs['title']
211
+ title: ele.attrs['title'],
212
+ rel: "noopener noreferrer",
213
+ onClick: e => this.props.onLink && this.props.onLink(e, ele.attrs.href)
200
214
  }, $body);
201
215
  case 'Emoji':
202
216
  return (0, _preact.h)(_Emoji.default, {
203
217
  emojiCode: ele.attrs['emojiCode']
204
218
  });
205
219
  }
206
- return null;
220
+ return $body;
207
221
  }
208
222
  render() {
209
223
  return this.renderBlock(this.props.block);
210
224
  }
211
225
  }
212
- exports.default = Block;
213
- function absLink(url) {
214
- if (!url.startsWith('http://') && !url.startsWith('https://') && !url.startsWith('//')) return 'http://' + url;
215
- return url;
216
- }
226
+ exports.default = Block;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.conversationEventKey = conversationEventKey;
7
+ exports.conversationEvents = conversationEvents;
8
+ exports.conversationHistory = conversationHistory;
9
+ var _index = _interopRequireDefault(require("../util/index.js"));
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ function conversationHistory(store, cid) {
12
+ if (!cid) return [];
13
+ const current = store.matchConvo(cid);
14
+ if (!current || !current.created) return [current || {
15
+ id: cid
16
+ }];
17
+ const conversations = _index.default.map(store.matchConvo('*'));
18
+ const unique = new Map();
19
+ for (const convo of conversations) {
20
+ if (!convo || !convo.id || convo.id === cid || convo.id.startsWith('cslight')) continue;
21
+ if (current.account_id && convo.account_id !== current.account_id) continue;
22
+ if (convo.created && _index.default.getMs(convo.created) < _index.default.getMs(current.created)) unique.set(convo.id, convo);
23
+ }
24
+ return [...unique.values()].sort((a, b) => _index.default.getMs(a.created) - _index.default.getMs(b.created) || a.id.localeCompare(b.id)).concat(current);
25
+ }
26
+ function conversationEvents(store, convo) {
27
+ const events = _index.default.orderBy(_index.default.map(store.listEvents(convo.id)), 'created', 'asc');
28
+ const unique = new Map();
29
+ for (const ev of events) {
30
+ const key = conversationEventKey(ev);
31
+ const previous = unique.get(key);
32
+ if (!previous) unique.set(key, ev);else if (previous.id === previous.source_event_id && ev.id !== ev.source_event_id) unique.set(key, {
33
+ ...ev,
34
+ created: previous.created
35
+ });
36
+ }
37
+ return [...unique.values()].map(ev => ({
38
+ ev
39
+ }));
40
+ }
41
+ function conversationEventKey(ev) {
42
+ const id = ev.type === 'message_sent' ? ev.source_event_id || ev.id : ev.id;
43
+ return ev.type + ':' + id;
44
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.processEvents = processEvents;
7
+ var _index = _interopRequireDefault(require("../util/index.js"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ function processEvents(convo, events) {
10
+ events = events.filter(event => visibleEvent(event.ev));
11
+ if (events.length < 1) return;
12
+ var lastAgentEvent;
13
+ for (var i = 1; i < events.length; i++) {
14
+ let curEvent = events[i];
15
+ let lastEvent = events[i - 1];
16
+ if (_index.default.get(curEvent, 'ev.by.type') != 'user' && !curEvent.is_typing) {
17
+ lastAgentEvent = curEvent;
18
+ }
19
+ if (visibleEvent(curEvent.ev)) {
20
+ let elapsedSec = _index.default.unixSec(curEvent.ev.created) - _index.default.unixSec(lastEvent.ev.created);
21
+ if (elapsedSec > 300) curEvent.show_time = true;
22
+ }
23
+ }
24
+ if (lastAgentEvent) lastAgentEvent.show_time = true;
25
+ for (var i = 0; i < events.length; i++) {
26
+ let curEvent = events[i];
27
+ if (_index.default.get(curEvent, 'ev.type') === 'message_sent') {
28
+ curEvent.show_time = true;
29
+ break;
30
+ }
31
+ }
32
+ let lastMsgSentIdx = -1;
33
+ for (var i = 0; i < events.length; i++) {
34
+ let curEvent = events[i];
35
+ let prevEvent = events[i - 1];
36
+ let nextEvent = events[i + 1];
37
+ if (curEvent.ev.type === 'message_sent') {
38
+ lastMsgSentIdx = i;
39
+ curEvent.mode = 'lead';
40
+ if (_index.default.get(prevEvent, 'ev.type') === 'message_sent' && _index.default.get(prevEvent, 'ev.by.id') === _index.default.get(curEvent, 'ev.by.id')) {
41
+ curEvent.mode = 'follow';
42
+ }
43
+ if (_index.default.get(nextEvent, 'ev.type') !== 'message_sent' || _index.default.get(nextEvent, 'ev.by.id') !== _index.default.get(curEvent, 'ev.by.id')) {
44
+ curEvent.is_end = true;
45
+ }
46
+ continue;
47
+ }
48
+ }
49
+ if (lastMsgSentIdx > -1) {
50
+ events[lastMsgSentIdx].is_last_message_send = true;
51
+ }
52
+ }
53
+ function visibleEvent(ev) {
54
+ let type = _index.default.get(ev, 'type');
55
+ if (type === 'message_sent') return true;
56
+ if (type === 'conversation_state_updated') {
57
+ return _index.default.get(ev, 'data.conversation.state') == 'ended';
58
+ }
59
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.widgetGreeting = widgetGreeting;
7
+ var _index = _interopRequireDefault(require("../util/index.js"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ function widgetGreeting(chatbox, t, created = _index.default.Date.now()) {
10
+ const greeting = _index.default.get(chatbox, 'greeting', {});
11
+ const localized = t.i18n ? t.i18n(greeting.greeting || {}) : '';
12
+ const text = _index.default.trim(localized) || _index.default.trim(greeting.message) || _index.default.trim(t('team_intro')) || t('empty_convo_text');
13
+ return {
14
+ id: 'widget-greeting-' + _index.default.randomString(24),
15
+ type: 'message_sent',
16
+ created,
17
+ by: {
18
+ type: 'system',
19
+ id: 'system',
20
+ ...(greeting.agent_id ? {
21
+ display_type: 'agent',
22
+ display_id: greeting.agent_id
23
+ } : {})
24
+ },
25
+ data: {
26
+ message: {
27
+ text,
28
+ format: 'plaintext'
29
+ }
30
+ }
31
+ };
32
+ }
@@ -13,15 +13,19 @@ class Com extends _preact.Component {
13
13
  constructor(props) {
14
14
  super(props);
15
15
  this._isMounted = true;
16
- _index.default.setTimeout(() => {
17
- if (this.componentWillUnmount) {
18
- let old = this.componentWillUnmount.bind(this);
19
- this.componentWillUnmount = () => {
20
- old();
21
- this._isMounted = false;
22
- };
23
- }
24
- }, 10);
16
+ this._subscriptions = new Set();
17
+ const onUnmount = this.componentWillUnmount;
18
+ this.componentWillUnmount = () => {
19
+ if (!this._isMounted) return;
20
+ this._isMounted = false;
21
+ for (const unsubscribe of this._subscriptions) unsubscribe();
22
+ this._subscriptions.clear();
23
+ if (onUnmount) onUnmount.call(this);
24
+ };
25
+ }
26
+ onDispose(cleanup) {
27
+ if (this._isMounted) this._subscriptions.add(cleanup);else cleanup();
28
+ return () => this._subscriptions.delete(cleanup);
25
29
  }
26
30
  }
27
31
  exports.Com = Com;
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = exports.default = require('css-loader!less-loader!../../assets/less/form-page.less');
7
+ var _default = exports.default = require('css-loader?import=false!less-loader!../../assets/less/form-page.less');
@@ -7,6 +7,7 @@ exports.default = void 0;
7
7
  var _store = _interopRequireDefault(require("./store/store.js"));
8
8
  var _index = _interopRequireDefault(require("./util/index.js"));
9
9
  var _plugin = _interopRequireDefault(require("./plugin.js"));
10
+ var _event = require("./util/event.js");
10
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
12
  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; }
12
13
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
@@ -23,10 +24,11 @@ class Widget {
23
24
  _defineProperty(this, "track", v => this.store.track(v));
24
25
  _defineProperty(this, "event", async (type, payload, options) => {
25
26
  await this.store.readyGate.entry();
26
- return this.store.api.sendEvent(normalizeCdpEvent(type, payload, options));
27
+ return this.store.api.sendEvent((0, _event.normalizeCdpEvent)(type, payload, options));
27
28
  });
28
29
  _defineProperty(this, "pageview", v => this.store.sendPageview(v));
29
30
  this.impressionTokens = {};
31
+ this._containerTimers = new Set();
30
32
  this.domGate = new _index.default.Gate();
31
33
  this.store = new _store.default(ApiURL, FileURL, RealtimeURL, inmem, fake);
32
34
  window.sbz_store = this.store;
@@ -46,6 +48,16 @@ class Widget {
46
48
  await this.store.readyGate.entry();
47
49
  cb();
48
50
  }
51
+ watchContainer(container) {
52
+ const manager = this.pluginMgr;
53
+ const timer = _index.default.setInterval(() => {
54
+ if (!this.store.isDead() && container && container.isConnected) return;
55
+ manager.destroy();
56
+ _index.default.clearInterval(timer);
57
+ this._containerTimers.delete(timer);
58
+ }, 1000);
59
+ this._containerTimers.add(timer);
60
+ }
49
61
  setAIDevMode(mode) {
50
62
  this.store.setAIDevMode(mode);
51
63
  }
@@ -63,11 +75,7 @@ class Widget {
63
75
  let user = await this.store.login(accid, user_id, tokenGenerator);
64
76
  if (!$container) $container = document.body;
65
77
  this.pluginMgr = new _plugin.default(this, $container);
66
- let clean = _index.default.setInterval(() => {
67
- if ($container && $container.isConnected) return;
68
- this.pluginMgr.destroy();
69
- _index.default.clearInterval(clean);
70
- }, 1000);
78
+ this.watchContainer($container);
71
79
  this.domGate.open();
72
80
  return user;
73
81
  }
@@ -89,11 +97,7 @@ class Widget {
89
97
  }, '*'), 0);
90
98
  if (!$container) $container = document.body || document;
91
99
  this.pluginMgr = new _plugin.default(this, $container);
92
- let clean = _index.default.setInterval(() => {
93
- if ($container && $container.isConnected) return;
94
- this.pluginMgr.destroy();
95
- _index.default.clearInterval(clean);
96
- }, 1000);
100
+ this.watchContainer($container);
97
101
  this.domGate.open();
98
102
  return user;
99
103
  }
@@ -107,11 +111,7 @@ class Widget {
107
111
  }, '*'), 0);
108
112
  if (!$container) $container = document.body || document;
109
113
  this.pluginMgr = new _plugin.default(this, $container);
110
- let clean = _index.default.setInterval(() => {
111
- if ($container && $container.isConnected) return;
112
- this.pluginMgr.destroy();
113
- _index.default.clearInterval(clean);
114
- }, 1000);
114
+ this.watchContainer($container);
115
115
  this.domGate.open();
116
116
  cb && cb(outmask);
117
117
  return outmask;
@@ -135,11 +135,7 @@ class Widget {
135
135
  }, '*'), 0);
136
136
  if (!$container) $container = document.body || document;
137
137
  this.pluginMgr = new _plugin.default(this, $container);
138
- let clean = _index.default.setInterval(() => {
139
- if ($container && $container.isConnected) return;
140
- this.pluginMgr.destroy();
141
- _index.default.clearInterval(clean);
142
- }, 1000);
138
+ this.watchContainer($container);
143
139
  this.domGate.open();
144
140
  if (typeof sbz_info != 'undefined') sbz_info.set_account_done = _index.default.Date.now();
145
141
  cb && cb(outmask);
@@ -166,7 +162,7 @@ class Widget {
166
162
  }
167
163
  async createTicket(ticket) {
168
164
  await this.domGate.entry();
169
- return this.createTicket(ticket);
165
+ return this.store.createTicket(ticket);
170
166
  }
171
167
  expandWidget(view, convo) {
172
168
  return this.showWidget(view, convo);
@@ -272,7 +268,7 @@ class Widget {
272
268
  if (req.bot_id) {
273
269
  let botid = req.bot_id;
274
270
  delete req.bot_id;
275
- if (!_index.default.find(members, m => b.id == botid)) {
271
+ if (!_index.default.find(members, m => m.id == botid)) {
276
272
  members.push({
277
273
  type: 'bot',
278
274
  id: botid,
@@ -323,6 +319,9 @@ class Widget {
323
319
  this.store.overrideDeviceType(type);
324
320
  }
325
321
  unload() {
322
+ for (const timer of this._containerTimers) _index.default.clearInterval(timer);
323
+ this._containerTimers.clear();
324
+ this.subs = [];
326
325
  if (this.pluginMgr) this.pluginMgr.destroy();
327
326
  this.store.destroy();
328
327
  }
@@ -369,14 +368,5 @@ class Widget {
369
368
  this.store.doNotStartBot();
370
369
  }
371
370
  }
372
- function normalizeCdpEvent(type, payload, options) {
373
- if (type && typeof type === 'object') return type;
374
- let data = {
375
- type: type
376
- };
377
- if (payload !== undefined) data.payload = payload;
378
- if (options && typeof options === 'object') data = Object.assign({}, options, data);
379
- return data;
380
- }
381
371
  window.__sbz_WIDGET = Widget;
382
372
  var _default = exports.default = Widget;
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = exports.default = require('css-loader!less-loader!../../assets/less/notif.less');
7
+ var _default = exports.default = require('css-loader?import=false!less-loader!../../assets/less/notif.less');
@@ -10,7 +10,6 @@ var _preact = require("preact");
10
10
  var _main = _interopRequireDefault(require("./chatbox/main.js"));
11
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
12
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
13
- const LoadContact = () => Promise.resolve().then(() => _interopRequireWildcard(require('./contact/contact.js')));
14
13
  const LoadPopup = () => Promise.resolve().then(() => _interopRequireWildcard(require('./popup/popup.js')));
15
14
  const LoadNotif = () => Promise.resolve().then(() => _interopRequireWildcard(require('./notif/notif.js')));
16
15
  function Plugin(plugin, store, $container, lib) {
@@ -52,7 +51,6 @@ function Plugin(plugin, store, $container, lib) {
52
51
  };
53
52
  var _ref = (0, _preact.createRef)();
54
53
  let Popup = null;
55
- let Contact = null;
56
54
  let Notif = null;
57
55
  var showCurrentChatbox = p => lib.showWidget(p);
58
56
  var nextPage = () => {
@@ -99,16 +97,6 @@ function Plugin(plugin, store, $container, lib) {
99
97
  ref: _ref
100
98
  }), $div);
101
99
  }
102
- if (plugin.type === 'contact') {
103
- if (!Contact) Contact = (await LoadContact()).default;
104
- (0, _preact.render)((0, _preact.h)(Contact, {
105
- destroy: _destroy,
106
- t: this.t,
107
- plugin: plugin,
108
- store: store,
109
- ref: _ref
110
- }), $div);
111
- }
112
100
  domGate.open();
113
101
  };
114
102
  this.call = (method, param) => domGate.entry().then(() => {
@@ -117,9 +105,10 @@ function Plugin(plugin, store, $container, lib) {
117
105
  });
118
106
  var _destroy = false;
119
107
  this.destroy = () => {
108
+ if (_destroy) return;
120
109
  _destroy = true;
121
110
  (0, _preact.render)(null, $div);
122
- $div.parentNode.removeChild($div);
111
+ if ($div.parentNode) $div.parentNode.removeChild($div);
123
112
  };
124
113
  this.highlight = comref => {
125
114
  highlight = comref;
@@ -200,14 +189,15 @@ class PluginMgr {
200
189
  this.$div = $div;
201
190
  this.pluginM = {};
202
191
  this._destroy = false;
203
- lib.store.onHighlight({
192
+ this._subscriptions = [];
193
+ this._subscriptions.push(lib.store.onHighlight({
204
194
  _isMounted: true
205
195
  }, (id, comref) => {
206
196
  let plugin = this.pluginM[id];
207
197
  if (!plugin) return;
208
198
  plugin.highlight(comref);
209
- });
210
- lib.store.onUpdate({
199
+ }));
200
+ this._subscriptions.push(lib.store.onUpdate({
211
201
  _isMounted: true
212
202
  }, () => {
213
203
  if (this._destroy) return;
@@ -229,7 +219,7 @@ class PluginMgr {
229
219
  this.pluginM[id].destroy();
230
220
  delete this.pluginM[id];
231
221
  });
232
- });
222
+ }));
233
223
  let pluginM = this.lib.store.matchPlugin();
234
224
  if (typeof sbz_info != 'undefined') sbz_info['plugins'] = pluginM;
235
225
  let foundchatbox = false;
@@ -303,11 +293,14 @@ class PluginMgr {
303
293
  if (chatbox) return chatbox.setLocale(locale);
304
294
  }
305
295
  destroy() {
296
+ if (this._destroy) return;
297
+ this._destroy = true;
298
+ for (const unsubscribe of this._subscriptions) unsubscribe();
299
+ this._subscriptions = [];
306
300
  _index.default.map(this.pluginM, (conf, id) => {
307
301
  conf.destroy();
308
302
  delete this.pluginM[id];
309
303
  });
310
- this._destroy = true;
311
304
  }
312
305
  }
313
306
  exports.default = PluginMgr;
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = exports.default = require('css-loader!less-loader!../../assets/less/popup.less');
7
+ var _default = exports.default = require('css-loader?import=false!less-loader!../../assets/less/popup.less');
@@ -72,7 +72,7 @@ class Popup extends _common.Com {
72
72
  for (var i = 0; i < fonts.length; i++) {
73
73
  try {
74
74
  if (document.fonts.check('normal 16px ' + fonts[i])) ready[fonts[i]] = true;
75
- if (Object.keys(readycount) == fonts.length) return;
75
+ if (Object.keys(ready).length == fonts.length) return;
76
76
  } catch (e) {}
77
77
  }
78
78
  await _index.default.sleep(200);
@@ -45,7 +45,6 @@ let trackResponseFn = (param, done) => {
45
45
  };
46
46
  class _default {
47
47
  constructor(ApiURL, FileURL) {
48
- _defineProperty(this, "sendBugReport", str => this.bugReq.post('/bugs', str));
49
48
  _defineProperty(this, "listConversations", _ => this.apireq.addQuery('user_id', this.uid).addQuery('integration_id', `${this.accid}.subizv4.subikon`).get(`/accounts/${this.accid}/conversations`));
50
49
  _defineProperty(this, "listMessages", (cid, limit, start_id) => this.apireq.addQuery('limit', limit).addQuery('start_id', start_id).get(`/accounts/${this.accid}/conversations/${cid}/messages`));
51
50
  _defineProperty(this, "ajax", ajax);
@@ -215,7 +214,6 @@ class _default {
215
214
  this.refreshLock = new _index.default.Mutex();
216
215
  this.FileURL = FileURL;
217
216
  this.ApiURL = ApiURL;
218
- this.bugReq = ajax.setBaseUrl('https://api5.subiz.com.vn/4.1').setContentType('text/plain');
219
217
  this.api41 = ajax.setBaseUrl('https://api.sbz.vn/4.1').withCredentials(true).setContentType('text/plain').beforeHook(jsonifyTextPlain).afterHook(trackResponseFn).beforeHook(trackRequestFn).setParser('json');
220
218
  this.apireq = ajax.setBaseUrl(ApiURL).withCredentials(true).addQuery('v', '6').setContentType('text/plain').beforeHook(jsonifyTextPlain).afterHook(trackResponseFn).setParser('json').beforeHook(trackRequestFn).beforeHook((param, done) => {
221
219
  if (this.token_generator) {
@@ -243,6 +243,7 @@ function makeFakeMessages(accid, convoid, userid, agentid) {
243
243
  }
244
244
  }, {
245
245
  id: 'evqyiyjmzatvtgpdmmpzwnwgn',
246
+ source_event_id: 'wrueysyjbhqrkiwhsejpqrwqrdkkyaibajdw',
246
247
  account_id: accid,
247
248
  created: 1616213202685,
248
249
  type: 'message_sent',
@@ -256,7 +257,6 @@ function makeFakeMessages(accid, convoid, userid, agentid) {
256
257
  conversation_id: convoid,
257
258
  text: 'Xin chào',
258
259
  format: 'plaintext',
259
- idempotency_key: 'wrueysyjbhqrkiwhsejpqrwqrdkkyaibajdw',
260
260
  integration_id: inteid,
261
261
  pongs: [{
262
262
  member_id: userid,
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.uploadAttachments = uploadAttachments;
7
+ async function uploadAttachments(attachments, upload) {
8
+ let error, errorMessage;
9
+ for (const attachment of attachments) {
10
+ try {
11
+ const result = await upload(attachment._file);
12
+ if (result.body && result.body.code === 'invalid_field_size') {
13
+ errorMessage = 'cannot_send_too_big_file';
14
+ }
15
+ if (result.error || !result.url) {
16
+ error = error || result.error || 'upload_failed';
17
+ continue;
18
+ }
19
+ attachment.url = result.url;
20
+ } catch (err) {
21
+ error = error || err;
22
+ }
23
+ }
24
+ return {
25
+ error,
26
+ errorMessage
27
+ };
28
+ }