@subiz/widget-v4 4.0.61 → 4.0.66

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 (134) hide show
  1. package/assets/img/caret.svg +1 -0
  2. package/assets/img/done_green.svg +4 -0
  3. package/assets/img/empty_1.svg +11 -0
  4. package/assets/img/ghn.svg +17 -0
  5. package/assets/img/ghtk.svg +18 -0
  6. package/assets/img/home.svg +1 -0
  7. package/assets/img/info.svg +1 -0
  8. package/assets/img/loader.svg +1 -0
  9. package/assets/img/map-pin.svg +1 -0
  10. package/assets/img/not_found_search.png +0 -0
  11. package/assets/img/package.svg +5 -0
  12. package/assets/img/package_fade.svg +1 -0
  13. package/assets/img/phone.svg +1 -0
  14. package/assets/img/search.svg +1 -0
  15. package/assets/img/shop.svg +1 -0
  16. package/assets/img/shop_faded.svg +1 -0
  17. package/assets/img/user.svg +1 -0
  18. package/assets/img/x.svg +5 -0
  19. package/assets/less/chatbox.less +39 -1
  20. package/assets/less/dropdown_select.less +130 -0
  21. package/assets/less/form.less +7 -20
  22. package/assets/less/order.less +489 -0
  23. package/assets/less/rating.less +3 -8
  24. package/babel.config.js +2 -4
  25. package/compiled_src/bot.js +7 -1
  26. package/compiled_src/chatbox/ChatButton.js +3 -1
  27. package/compiled_src/chatbox/DropdownSelect.js +248 -0
  28. package/compiled_src/chatbox/Event.js +5 -2
  29. package/compiled_src/chatbox/Events.js +1 -0
  30. package/compiled_src/chatbox/Order.js +285 -0
  31. package/compiled_src/chatbox/OrderAttachments.js +2 -1
  32. package/compiled_src/chatbox/ProductAttachments.js +40 -4
  33. package/compiled_src/chatbox/TextMessage.js +9 -2
  34. package/compiled_src/chatbox/Typing.js +3 -1
  35. package/compiled_src/chatbox/Widget.js +44 -3
  36. package/compiled_src/chatbox/main.js +2 -0
  37. package/compiled_src/chatbox/spinner.js +1 -1
  38. package/compiled_src/chatbox/time.js +3 -1
  39. package/compiled_src/common.js +40 -1
  40. package/compiled_src/contact/contact.js +1 -3
  41. package/compiled_src/order/address_picker.js +249 -0
  42. package/compiled_src/order/icon.js +62 -0
  43. package/compiled_src/order/index.js +113 -0
  44. package/compiled_src/order/order.js +1234 -0
  45. package/compiled_src/plugin.js +9 -42
  46. package/compiled_src/store/api.js +20 -0
  47. package/compiled_src/store/store.js +67 -3
  48. package/compiled_src/util/common.js +36 -2
  49. package/dist/{74.js → 132.js} +2355 -271
  50. package/dist/178.js +1 -1
  51. package/dist/17fdfed03d1.132.js +1 -0
  52. package/dist/17fdfed03d1.178.js +1 -0
  53. package/dist/17fdfed03d1.213.js +1 -0
  54. package/dist/17fdfed03d1.335.js +1 -0
  55. package/dist/17fdfed03d1.362.js +1 -0
  56. package/dist/17fdfed03d1.441.js +1 -0
  57. package/dist/17fdfed03d1.605.js +1 -0
  58. package/dist/{17db8166252.678.js → 17fdfed03d1.678.js} +0 -0
  59. package/dist/17fdfed03d1.782.js +1 -0
  60. package/dist/17fdfed03d1.app.js +1 -0
  61. package/dist/{17db8166252.index.html → 17fdfed03d1.index.html} +1 -1
  62. package/dist/{17db8166252.library.html → 17fdfed03d1.library.html} +1 -1
  63. package/dist/17fdfed03d1.library.js +1 -0
  64. package/dist/{17db8166252.preview.html → 17fdfed03d1.preview.html} +1 -1
  65. package/dist/17fdfed03d1.preview.js +1 -0
  66. package/dist/17fdfed03d1.screenshoot.js +1 -0
  67. package/dist/213.js +5 -69
  68. package/dist/335.js +411 -0
  69. package/dist/362.js +1 -1
  70. package/dist/441.js +70 -44
  71. package/dist/605.js +1 -64
  72. package/dist/782.js +1 -1
  73. package/dist/HASH +1 -1
  74. package/dist/assets/img/caret.998eb8f.svg +1 -0
  75. package/dist/assets/img/done_green.b817fd4.svg +4 -0
  76. package/dist/assets/img/empty_1.0b98af0.svg +11 -0
  77. package/dist/assets/img/ghn.070f8e3.svg +17 -0
  78. package/dist/assets/img/ghtk.326eac1.svg +18 -0
  79. package/dist/assets/img/info.ebce7ea.svg +1 -0
  80. package/dist/assets/img/loader.37000a7.svg +1 -0
  81. package/dist/assets/img/not_found_search.2ddb8d1.png +0 -0
  82. package/dist/assets/img/package.8d37d0f.svg +5 -0
  83. package/dist/assets/img/package_fade.763c001.svg +1 -0
  84. package/dist/assets/img/search.f9705ff.svg +1 -0
  85. package/dist/assets/img/shop.f7dc7d8.svg +1 -0
  86. package/dist/assets/img/shop_faded.df7845a.svg +1 -0
  87. package/dist/assets/img/x.26fdfa3.svg +5 -0
  88. package/dist/screenshoot.html +1 -1
  89. package/dist/screenshoot.js +281 -98
  90. package/order.html +19 -771
  91. package/package.json +15 -16
  92. package/src/bot.js +2 -1
  93. package/src/chatbox/Buttons.js +8 -8
  94. package/src/chatbox/ChatButton.js +2 -2
  95. package/src/chatbox/DropdownSelect.js +229 -0
  96. package/src/chatbox/Event.js +3 -3
  97. package/src/chatbox/Events.js +43 -42
  98. package/src/chatbox/Order.js +232 -0
  99. package/src/chatbox/OrderAttachments.js +2 -1
  100. package/src/chatbox/ProductAttachments.js +41 -5
  101. package/src/chatbox/TextMessage.js +21 -12
  102. package/src/chatbox/Typing.js +5 -1
  103. package/src/chatbox/Widget.js +34 -4
  104. package/src/chatbox/main.js +4 -1
  105. package/src/chatbox/spinner.js +1 -1
  106. package/src/chatbox/time.js +1 -1
  107. package/src/common.js +52 -8
  108. package/src/contact/contact.js +1 -1
  109. package/src/order/address_picker.js +235 -0
  110. package/src/order/icon.js +32 -0
  111. package/src/order/index.js +86 -0
  112. package/src/order/order.js +1157 -0
  113. package/src/order/scratch +211 -0
  114. package/src/plugin.js +7 -52
  115. package/src/store/api.js +26 -1
  116. package/src/store/store.js +53 -3
  117. package/src/util/common.js +48 -2
  118. package/up +1 -1
  119. package/webpack.dev.js +2 -0
  120. package/dist/17db8166252.178.js +0 -1
  121. package/dist/17db8166252.213.js +0 -1
  122. package/dist/17db8166252.362.js +0 -1
  123. package/dist/17db8166252.441.js +0 -1
  124. package/dist/17db8166252.605.js +0 -1
  125. package/dist/17db8166252.619.js +0 -1
  126. package/dist/17db8166252.74.js +0 -1
  127. package/dist/17db8166252.782.js +0 -1
  128. package/dist/17db8166252.app.js +0 -1
  129. package/dist/17db8166252.library.js +0 -1
  130. package/dist/17db8166252.preview.js +0 -1
  131. package/dist/17db8166252.screenshoot.js +0 -1
  132. package/dist/619.js +0 -777
  133. package/order.js +0 -0
  134. package/test.js +0 -1
@@ -7,6 +7,8 @@ exports.default = void 0;
7
7
 
8
8
  var _index = _interopRequireDefault(require("./util/index.js"));
9
9
 
10
+ var common = _interopRequireWildcard(require("./common.js"));
11
+
10
12
  var _preact = require("preact");
11
13
 
12
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -23,16 +25,13 @@ const LoadPopup = () => Promise.resolve().then(() => _interopRequireWildcard(req
23
25
 
24
26
  const LoadNotif = () => Promise.resolve().then(() => _interopRequireWildcard(require('./notif/notif.js')));
25
27
 
26
- let langMessages = {};
27
- let downloadLock = false;
28
-
29
28
  function Plugin(plugin, store, $container, lib) {
30
29
  if (!$container) throw '$div must is a valid html node';
31
30
  var $div = document.createElement('div');
32
31
  $div.id = plugin.id;
33
32
  $container.appendChild($div);
34
33
 
35
- let _locale = getLocale(plugin, _index.default.detectLang());
34
+ let _locale = common.getLocale(plugin, _index.default.detectLang());
36
35
 
37
36
  var domGate = new _index.default.Gate();
38
37
  var pageIndex = 0;
@@ -165,7 +164,7 @@ function Plugin(plugin, store, $container, lib) {
165
164
  let t = key => {
166
165
  if (_locale === 'debug') return `{{${key}}}`;
167
166
 
168
- let messages = _index.default.get(langMessages, _locale, []);
167
+ let messages = _index.default.get(common.langMessages, _locale, []);
169
168
 
170
169
  let message = _index.default.find(messages, message => message.key === key);
171
170
 
@@ -187,7 +186,7 @@ function Plugin(plugin, store, $container, lib) {
187
186
  t.locale = () => _locale;
188
187
 
189
188
  this.forceDownloadLanguage = async () => {
190
- await downloadLanguage(store, _locale, true);
189
+ await common.downloadLanguage(store, _locale, true);
191
190
  this.update(plugin);
192
191
  };
193
192
 
@@ -197,8 +196,8 @@ function Plugin(plugin, store, $container, lib) {
197
196
 
198
197
  _render();
199
198
 
200
- _locale = getLocale(plugin, locale);
201
- await downloadLanguage(store, _locale);
199
+ _locale = common.getLocale(plugin, locale);
200
+ await common.downloadLanguage(store, _locale);
202
201
  this.t = t;
203
202
 
204
203
  _render();
@@ -237,7 +236,7 @@ function Plugin(plugin, store, $container, lib) {
237
236
  }
238
237
 
239
238
  this.update(plugin);
240
- downloadLanguage(store, _locale).then(() => {
239
+ common.downloadLanguage(store, _locale).then(() => {
241
240
  this.t = t;
242
241
  this.update(plugin);
243
242
  });
@@ -387,36 +386,4 @@ class PluginMgr {
387
386
 
388
387
  }
389
388
 
390
- exports.default = PluginMgr;
391
-
392
- function downloadLanguage(store, locale, force) {
393
- if (downloadLock) return new Promise(resolve => setTimeout(() => downloadLanguage(store, locale, force).then(resolve), 100));
394
- downloadLock = true;
395
- let messages;
396
-
397
- if (locale === 'debug' || langMessages[locale] && !force) {
398
- downloadLock = false;
399
- return Promise.resolve();
400
- }
401
-
402
- return store.getLocaleContent(locale).then(res => {
403
- downloadLock = false;
404
- messages = _index.default.get(res, 'body.messages', []);
405
- langMessages[locale] = messages;
406
- });
407
- }
408
-
409
- const getLocale = (plugin, loc) => {
410
- if (!loc) loc = '';
411
-
412
- let found = _index.default.find(plugin.locales, l => l.toLowerCase().trim() === loc.toLowerCase().trim());
413
-
414
- if (found) return found;
415
- found = _index.default.find(plugin.locales, l => {
416
- l = l.replace('-', '_').split('_')[0].trim().toLowerCase();
417
- let compareloc = loc.replace('-', '_').split('_')[0].trim().toLowerCase();
418
- return l == compareloc;
419
- });
420
- if (found) return found;
421
- return plugin.locale || 'en-US';
422
- };
389
+ exports.default = PluginMgr;
@@ -113,6 +113,26 @@ class _default {
113
113
 
114
114
  _defineProperty(this, "sendConversion", conversion => this.apireq.post(`/accounts/${this.accid}/campaigns/${conversion.campaign_id}/conversions`, conversion));
115
115
 
116
+ _defineProperty(this, "lookupOrder", key => ajax.setBaseUrl(this.ApiURL).setContentType('text/plain').beforeHook(jsonifyTextPlain).setParser('json').addQuery('x-signed-key', key).get(`/orders/123`));
117
+
118
+ _defineProperty(this, "getOrder", id => this.apireq.get(`/accounts/${this.accid}/orders/` + id));
119
+
120
+ _defineProperty(this, "updateOrder", order => this.apireq.post(`/accounts/${this.accid}/orders/` + order.id, order));
121
+
122
+ _defineProperty(this, "fetchShippingAddresses", () => this.apireq.get(`/accounts/${this.accid}/users/${this.uid}/shipping-addresses`));
123
+
124
+ _defineProperty(this, "createShippingAddress", addr => this.apireq.post(`/accounts/${this.accid}/users/${this.uid}/shipping-addresses`, addr));
125
+
126
+ _defineProperty(this, "list_provinces", () => this.apireq.get(`/accounts/${this.accid}/provinces`));
127
+
128
+ _defineProperty(this, "list_districts", p => this.apireq.setQuery(p).get(`/accounts/${this.accid}/districts`));
129
+
130
+ _defineProperty(this, "list_wards", p => this.apireq.setQuery(p).get(`/accounts/${this.accid}/wards`));
131
+
132
+ _defineProperty(this, "suggest_address", keyword => this.apireq.setQuery({
133
+ keyword: keyword
134
+ }).get(`/accounts/${this.accid}/addresses`));
135
+
116
136
  this.FileURL = FileURL;
117
137
  this.ApiURL = ApiURL;
118
138
  this.apireq = ajax.setBaseUrl(ApiURL).withCredentials(true).addQuery('v', '6').setContentType('text/plain').beforeHook(jsonifyTextPlain).setParser('json').beforeHook((param, done) => {
@@ -46,10 +46,14 @@ class Store {
46
46
  return this.kv.match('user');
47
47
  });
48
48
 
49
+ _defineProperty(this, "suggest_addresses", keyword => this.api.suggest_address(keyword));
50
+
49
51
  _defineProperty(this, "matchSession", () => this.kv.match('session') || {});
50
52
 
51
53
  _defineProperty(this, "matchAccount", () => this.cache.match('account'));
52
54
 
55
+ _defineProperty(this, "matchPaymentMethods", () => this.cache.match('payment_methods'));
56
+
53
57
  _defineProperty(this, "matchUnread", () => {
54
58
  let user = this.matchUser();
55
59
  let allconvos = this.matchConvo('*');
@@ -103,6 +107,14 @@ class Store {
103
107
  return this.reconnectGate.open();
104
108
  });
105
109
 
110
+ _defineProperty(this, "list_provinces", () => this.api.list_provinces());
111
+
112
+ _defineProperty(this, "list_districts", p => this.api.list_districts(p));
113
+
114
+ _defineProperty(this, "list_wards", p => this.api.list_wards(p));
115
+
116
+ _defineProperty(this, "list_provices", void 0);
117
+
106
118
  _defineProperty(this, "listEvents", id => {
107
119
  if (!id || id === '*' || typeof id !== 'string') return;
108
120
 
@@ -178,7 +190,10 @@ class Store {
178
190
  _defineProperty(this, "setIsOpen", isopen => {
179
191
  let lastisopen = this.kv.match('isopen');
180
192
  this.kv.put('isopen', isopen);
181
- if (!lastisopen && isopen) sendEventToThirdParty('SUBIZ Chat', 'Opened', 'Subiz Windows');
193
+
194
+ if (!lastisopen && isopen) {
195
+ sendEventToThirdParty('SUBIZ Chat', 'Opened', 'Subiz Windows');
196
+ }
182
197
  });
183
198
 
184
199
  _defineProperty(this, "closePreview", () => this.kv.put('close_preview_at', new _index.default.Date().getTime()));
@@ -247,6 +262,24 @@ class Store {
247
262
  return _index.default.Date.now() - (this.g_sync[key] || 0) < 300000;
248
263
  }
249
264
 
265
+ async fetchShippingAddresses() {
266
+ let out = await this.api.fetchShippingAddresses();
267
+ if (out.error) return null;
268
+ this.cache.put('shipping_address', out.body.shipping_addresses);
269
+ }
270
+
271
+ matchShippingAddresses() {
272
+ return this.cache.match('shipping_address');
273
+ }
274
+
275
+ updateOrder(order) {
276
+ return this.api.updateOrder(order);
277
+ }
278
+
279
+ createShippingAddress(addr) {
280
+ return this.api.createShippingAddress(addr);
281
+ }
282
+
250
283
  async overrideAcc(acc) {
251
284
  this.forceAcc = _index.default.cloneDeep(acc);
252
285
  await this.readyGate.entry();
@@ -470,6 +503,7 @@ class Store {
470
503
  }
471
504
 
472
505
  _setUser(user) {
506
+ user = _index.default.cloneDeep(user);
473
507
  let olduser = this.kv.match('user') || {};
474
508
  var accid = olduser.account_id || user.account_id;
475
509
  var id = olduser.id || user.id;
@@ -573,6 +607,9 @@ class Store {
573
607
  this.cache.put('agent', agentM);
574
608
  }
575
609
 
610
+ let pms = _index.default.get(setting, 'payment_methods', []);
611
+
612
+ this.cache.put('payment_methods', pms);
576
613
  this.pubsub.publish('account');
577
614
  }
578
615
 
@@ -795,6 +832,14 @@ class Store {
795
832
  };
796
833
  }
797
834
 
835
+ fetchOrder(id) {
836
+ return this.api.getOrder(id);
837
+ }
838
+
839
+ lookupOrder(key) {
840
+ return this.api.lookupOrder(key);
841
+ }
842
+
798
843
  createPostback(cid, postback) {
799
844
  return this.api.createPostback(cid, postback);
800
845
  }
@@ -862,6 +907,19 @@ class Store {
862
907
 
863
908
  this.onWs(ret);
864
909
  sendEventToThirdParty('SUBIZ Chat', 'Sent', 'User');
910
+ let lastMsgSent = this.kv.match('last_msg_sent');
911
+
912
+ if (!lastMsgSent) {
913
+ let dataLayer = window.dataLayer || [];
914
+ dataLayer.push({
915
+ event: 'SUBIZ Chat',
916
+ event_action: 'Sent',
917
+ event_label: 'User',
918
+ first_interaction: 1
919
+ });
920
+ }
921
+
922
+ this.kv.put('last_msg_sent', _index.default.Date.now());
865
923
  }
866
924
 
867
925
  _setConvo(convo) {
@@ -1002,7 +1060,7 @@ class Store {
1002
1060
  async loopTime() {
1003
1061
  let startms = _index.default.Date.now();
1004
1062
 
1005
- if (!_index.default.get(this.kv.match('user'), 'id')) return setTimeout(() => this.loopTime(), 30000);
1063
+ if (!_index.default.get(this.kv.match('user'), 'id')) return setTimeout(() => this.loopTime(), 120000);
1006
1064
  let {
1007
1065
  body: t,
1008
1066
  error
@@ -1014,7 +1072,7 @@ class Store {
1014
1072
  var localMs = _index.default.Date.now();
1015
1073
 
1016
1074
  this.timeDiff = Math.floor(serverMs - localMs);
1017
- setTimeout(() => this.loopTime(), 60000);
1075
+ setTimeout(() => this.loopTime(), 120000);
1018
1076
  }
1019
1077
 
1020
1078
  replaceFileUrl(src) {
@@ -1172,6 +1230,12 @@ function sendEventToThirdParty(category, action, label) {
1172
1230
  }));
1173
1231
  sendToGA(category, action, label);
1174
1232
  sendToFBPixel(category, action, label);
1233
+ let dataLayer = window.dataLayer || [];
1234
+ dataLayer.push({
1235
+ event: category,
1236
+ event_action: action,
1237
+ event_label: label
1238
+ });
1175
1239
  }
1176
1240
 
1177
1241
  let mobileCheck = function (a) {
@@ -47,6 +47,7 @@ exports.replaceCssVariable = replaceCssVariable;
47
47
  exports.replaceCssVariablePlugin = replaceCssVariablePlugin;
48
48
  exports.requestAnimationFrame = void 0;
49
49
  exports.sameDay = sameDay;
50
+ exports.scrollIntoViewIfNeeded = scrollIntoViewIfNeeded;
50
51
  exports.setCss = setCss;
51
52
  exports.setInterval = void 0;
52
53
  exports.setMsgField = setMsgField;
@@ -61,6 +62,7 @@ exports.throttle = throttle;
61
62
  exports.tokenize = tokenize;
62
63
  exports.trim = trim;
63
64
  exports.trimStart = trimStart;
65
+ exports.unicodeToAscii = unicodeToAscii;
64
66
  exports.unixSec = unixSec;
65
67
  exports.usersOfConvo = usersOfConvo;
66
68
 
@@ -998,6 +1000,7 @@ function preloadWebfonts(fonts, done) {
998
1000
  node.style.color = 'transparent';
999
1001
  node.style.fontSize = '20px';
1000
1002
  node.style.height = '0px';
1003
+ node.style.top = '0px';
1001
1004
  node.style.width = '0px';
1002
1005
  node.style.fontWeight = weight;
1003
1006
  node.setAttribute('subiz-preload', font + ':' + weight);
@@ -1133,9 +1136,9 @@ var sleep = ms => new Promise(res => setTimeout(res, ms));
1133
1136
  exports.sleep = sleep;
1134
1137
 
1135
1138
  function formatCurrency(val) {
1136
- if (!val) return 0;
1139
+ if (!val) return '0 đ';
1137
1140
  val = Math.round(val);
1138
- return val.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
1141
+ return val.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,') + ' đ';
1139
1142
  }
1140
1143
 
1141
1144
  function replaceFileUrl(src) {
@@ -1161,4 +1164,35 @@ function replaceFileUrl(src) {
1161
1164
  src = src.replace('https://file.mysubiz.com/', fileurl);
1162
1165
  src = src.replace('http://file.mysubiz.com/', fileurl);
1163
1166
  return src;
1167
+ }
1168
+
1169
+ function unicodeToAscii(str) {
1170
+ str = str + '';
1171
+ str = str.replace('đ', 'd').replace('Đ', 'D');
1172
+ return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
1173
+ }
1174
+
1175
+ function scrollIntoViewIfNeeded($ele) {
1176
+ centerIfNeeded = arguments.length === 0 ? true : !!centerIfNeeded;
1177
+ var parent = $ele.parentNode;
1178
+ var parentComputedStyle = window.getComputedStyle(parent, null);
1179
+ var parentBorderTopWidth = parseInt(parentComputedStyle.getPropertyValue('border-top-width'));
1180
+ var parentBorderLeftWidth = parseInt(parentComputedStyle.getPropertyValue('border-left-width'));
1181
+ var overTop = $ele.offsetTop - parent.offsetTop < parent.scrollTop;
1182
+ var overBottom = $ele.offsetTop - parent.offsetTop + $ele.clientHeight - parentBorderTopWidth > parent.scrollTop + parent.clientHeight;
1183
+ var overLeft = $ele.offsetLeft - parent.offsetLeft < parent.scrollLeft;
1184
+ var overRight = $ele.offsetLeft - parent.offsetLeft + $ele.clientWidth - parentBorderLeftWidth > parent.scrollLeft + parent.clientWidth;
1185
+ var alignWithTop = overTop && !overBottom;
1186
+
1187
+ if ((overTop || overBottom) && centerIfNeeded) {
1188
+ parent.scrollTop = $ele.offsetTop - parent.offsetTop - parent.clientHeight / 2 - parentBorderTopWidth + $ele.clientHeight / 2;
1189
+ }
1190
+
1191
+ if ((overLeft || overRight) && centerIfNeeded) {
1192
+ parent.scrollLeft = $ele.offsetLeft - parent.offsetLeft - parent.clientWidth / 2 - parentBorderLeftWidth + $ele.clientWidth / 2;
1193
+ }
1194
+
1195
+ if ((overTop || overBottom || overLeft || overRight) && !centerIfNeeded) {
1196
+ $ele.scrollIntoView(alignWithTop);
1197
+ }
1164
1198
  }