@subiz/widget-v4 4.1.40 → 4.1.41

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 (48) hide show
  1. package/compiled_src/lib.js +4 -0
  2. package/compiled_src/plugin.js +1 -2
  3. package/compiled_src/store/store.js +26 -6
  4. package/compiled_src/util/campaign.js +2 -6
  5. package/compiled_src/util/common.js +2 -6
  6. package/compiled_src/util/order.js +2 -4
  7. package/compiled_src/util/pubsub.js +3 -6
  8. package/dist/132.js +531 -525
  9. package/dist/18a3a577516.132.js +1 -0
  10. package/dist/18a3a577516.213.js +1 -0
  11. package/dist/18a3a577516.335.js +1 -0
  12. package/dist/{18a02a9c54e.362.js → 18a3a577516.362.js} +1 -1
  13. package/dist/18a3a577516.441.js +1 -0
  14. package/dist/18a3a577516.605.js +1 -0
  15. package/dist/{18a02a9c54e.782.js → 18a3a577516.782.js} +1 -1
  16. package/dist/18a3a577516.app.js +1 -0
  17. package/dist/{18a02a9c54e.index.html → 18a3a577516.index.html} +4 -4
  18. package/dist/{18a02a9c54e.library.html → 18a3a577516.library.html} +4 -4
  19. package/dist/18a3a577516.library.js +1 -0
  20. package/dist/{18a02a9c54e.preview.html → 18a3a577516.preview.html} +1 -1
  21. package/dist/18a3a577516.preview.js +1 -0
  22. package/dist/18a3a577516.screenshoot.js +1 -0
  23. package/dist/18a3a577516.webview.js +1 -0
  24. package/dist/213.js +118 -100
  25. package/dist/335.js +25 -25
  26. package/dist/362.js +1 -1
  27. package/dist/441.js +2441 -2597
  28. package/dist/605.js +50 -50
  29. package/dist/782.js +1 -1
  30. package/dist/HASH +1 -1
  31. package/dist/screenshoot.html +1 -1
  32. package/dist/screenshoot.js +396 -412
  33. package/package.json +10 -10
  34. package/src/lib.js +6 -0
  35. package/src/plugin.js +2 -3
  36. package/src/store/store.js +26 -5
  37. package/dist/18a02a9c54e.132.js +0 -1
  38. package/dist/18a02a9c54e.213.js +0 -1
  39. package/dist/18a02a9c54e.335.js +0 -1
  40. package/dist/18a02a9c54e.441.js +0 -1
  41. package/dist/18a02a9c54e.605.js +0 -1
  42. package/dist/18a02a9c54e.app.js +0 -1
  43. package/dist/18a02a9c54e.library.js +0 -1
  44. package/dist/18a02a9c54e.preview.js +0 -1
  45. package/dist/18a02a9c54e.screenshoot.js +0 -1
  46. package/dist/18a02a9c54e.webview.js +0 -1
  47. /package/dist/{18a02a9c54e.178.js → 18a3a577516.178.js} +0 -0
  48. /package/dist/{18a02a9c54e.678.js → 18a3a577516.678.js} +0 -0
@@ -205,6 +205,10 @@ class Widget {
205
205
  _overrideDeviceType(type) {
206
206
  this.store.overrideDeviceType(type);
207
207
  }
208
+ unload() {
209
+ if (this.pluginMgr) this.pluginMgr.destroy();
210
+ this.store.destroy();
211
+ }
208
212
  _overridePlugin(plugins) {
209
213
  this.store.overridePlugin(plugins);
210
214
  }
@@ -295,8 +295,7 @@ class PluginMgr {
295
295
  }
296
296
  destroy() {
297
297
  _index.default.map(this.pluginM, (conf, id) => {
298
- if (this.pluginM[id]) return;
299
- this.pluginM[id].destroy();
298
+ conf.destroy();
300
299
  delete this.pluginM[id];
301
300
  });
302
301
  this._destroy = true;
@@ -64,6 +64,7 @@ class Store {
64
64
  return this.cache.match('convo_' + id);
65
65
  });
66
66
  _defineProperty(this, "fetchConvo", async cid => {
67
+ if (this._die) return dieErr;
67
68
  await this.readyGate.entry();
68
69
  await this.reconnectGate.entry(undefined, true);
69
70
  if (this.isInsync(cid)) return this.reconnectGate.open();
@@ -119,6 +120,7 @@ class Store {
119
120
  _defineProperty(this, "matchHasManuallyClosed", () => !!this.kv.match('hasManuallyClosed'));
120
121
  _defineProperty(this, "matchClosePreviewAt", () => this.kv.match('close_preview_at') || 0);
121
122
  _defineProperty(this, "sendPresence", _index.default.throttle(async () => {
123
+ if (this._die) return dieErr;
122
124
  await this.readyGate.entry();
123
125
  if (!_index.default.get(this.cache.match('user'), 'id')) return;
124
126
  if (_index.default.isUserBanned(this.cache.match('user'))) return;
@@ -165,6 +167,7 @@ class Store {
165
167
  });
166
168
  _defineProperty(this, "timeDiff", 0);
167
169
  this.g_sync = {};
170
+ this._die = false;
168
171
  this.forceDevice = null;
169
172
  this.forcePlugins = {};
170
173
  this.forceAcc = {};
@@ -192,11 +195,18 @@ class Store {
192
195
  this.chain = new _storage.default.chain(new _storage.default.lsdb('cbz2023', true), 'ch');
193
196
  this.getLocaleContent = this.api.getLocaleContent;
194
197
  this.g_haveSentSeenM = {};
195
- window.addEventListener('blur', () => this.sendPresence());
196
- window.addEventListener('focus', () => this.sendPresence());
197
- _index.default.setInterval(() => this.browserVisibility === 'visible' && document.hasFocus() && this.sendPresence(), 20000);
198
- _index.default.setInterval(() => (this.browserVisibility !== 'visible' || document.hasFocus()) && this.sendPresence(), 60000);
198
+ window.addEventListener('blur', this.sendPresence);
199
+ window.addEventListener('focus', this.sendPresence);
200
+ this._presenceInterval1 = _index.default.setInterval(() => {
201
+ if (this._die) return _index.default.clearInterval(this._presenceInterval1);
202
+ if (this.browserVisibility === 'visible' && document.hasFocus()) this.sendPresence();
203
+ }, 20000);
204
+ this._presenceInterval2 = _index.default.setInterval(() => {
205
+ if (this._die) return _index.default.clearInterval(this._presenceInterval2);
206
+ if (this.browserVisibility !== 'visible' || document.hasFocus()) this.sendPresence();
207
+ }, 60000);
199
208
  onVisibilityChange(val => {
209
+ if (this._die) return;
200
210
  this.browserVisibility = val;
201
211
  this.sendPresence();
202
212
  });
@@ -304,6 +314,7 @@ class Store {
304
314
  return page_loaded;
305
315
  }
306
316
  overridePlugin(plugins) {
317
+ if (this._die) return dieErr;
307
318
  if (!Array.isArray(plugins)) throw 'plugins must be be an array';
308
319
  let pluginM = {};
309
320
  _index.default.map(plugins, function (plugin) {
@@ -377,6 +388,7 @@ class Store {
377
388
  return user;
378
389
  }
379
390
  async login(accid, user_id, tokenGenerator) {
391
+ if (this._die) return dieErr;
380
392
  let user = await this.api.setAuth({
381
393
  accid: accid,
382
394
  profile_id: user_id,
@@ -409,6 +421,7 @@ class Store {
409
421
  this.seenQueue = [];
410
422
  _index.default.clearInterval(this._seenInterval);
411
423
  this._seenInterval = _index.default.setInterval(() => {
424
+ if (this._die) return _index.default.clearInterval(this._seenInterval);
412
425
  this.seenQueue = [...new Set(this.seenQueue)];
413
426
  let user = this.cache.match('user') || {};
414
427
  _index.default.map(this.seenQueue, id => {
@@ -558,6 +571,7 @@ class Store {
558
571
  this.wsGate.open();
559
572
  }
560
573
  async _onWs(ev) {
574
+ if (this._die) return;
561
575
  if (!ev || !ev.type) return;
562
576
  ev.created = _index.default.getMs(ev.created);
563
577
  if (ev.type === 'user_info_updated') {
@@ -901,6 +915,7 @@ class Store {
901
915
  return [events, anchor];
902
916
  }
903
917
  async loopTime() {
918
+ if (this._die) return;
904
919
  let startms = _index.default.Date.now();
905
920
  if (!_index.default.get(this.cache.match('user'), 'id')) return _index.default.setTimeout(() => this.loopTime(), 240000);
906
921
  let {
@@ -946,9 +961,13 @@ class Store {
946
961
  }
947
962
  destroy() {
948
963
  this._die = true;
949
- this.clearBrowserData();
964
+ if (this.kv) this.kv.destroy();
965
+ if (this.chain) this.chain.destroy();
966
+ _index.default.clearInterval(this._seenInterval);
950
967
  if (this.realtime) this.realtime.stop();
951
968
  this.readyGate.close();
969
+ window.removeEventListener('blur', this.sendPresence);
970
+ window.removeEventListener('focus', this.sendPresence);
952
971
  }
953
972
  }
954
973
  exports.default = Store;
@@ -1113,4 +1132,5 @@ var xhrsend = function (method, url, body, cb) {
1113
1132
  request.open(method, url);
1114
1133
  if (body) request.setRequestHeader('content-type', 'text/plain');
1115
1134
  request.send(body);
1116
- };
1135
+ };
1136
+ const dieErr = new Error('sdk unloaded');
@@ -37,9 +37,7 @@ function trackAreaClicked(selector, cb) {
37
37
  on('click', selector, cb);
38
38
  });
39
39
  }
40
- function trackInactivity() {
41
- let seconds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
42
- let cb = arguments.length > 1 ? arguments[1] : undefined;
40
+ function trackInactivity(seconds = 0, cb) {
43
41
  let events = ['scroll', 'keyup', 'keydown', 'mousemove', 'mousewheel', 'mouseenter', 'mouseover', 'mousedown', 'touchstart', 'touchmove', 'touchenter'];
44
42
  let inactiveSeconds = 0;
45
43
  let resetTime = () => {
@@ -62,9 +60,7 @@ let timeOnPage = 0;
62
60
  common.setInterval(() => {
63
61
  timeOnPage += 5;
64
62
  }, 5000);
65
- function trackTimeOnPage() {
66
- let seconds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
67
- let cb = arguments.length > 1 ? arguments[1] : undefined;
63
+ function trackTimeOnPage(seconds = 0, cb) {
68
64
  if (seconds < 1) {
69
65
  return common.setTimeout(function () {
70
66
  cb(seconds);
@@ -159,10 +159,7 @@ function getMsgField(ev, fieldName) {
159
159
  function isObject(item) {
160
160
  return item && typeof item === 'object' && !Array.isArray(item);
161
161
  }
162
- function merge(target) {
163
- for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
164
- sources[_key - 1] = arguments[_key];
165
- }
162
+ function merge(target, ...sources) {
166
163
  if (!sources.length) return target;
167
164
  const source = sources.shift();
168
165
  if (isObject(target) && isObject(source)) {
@@ -963,8 +960,7 @@ function getUrlParameter() {
963
960
  }
964
961
  var sleep = ms => new Promise(res => setTimeout(res, ms));
965
962
  exports.sleep = sleep;
966
- function formatCurrency(val) {
967
- let currency = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'VND';
963
+ function formatCurrency(val, currency = 'VND') {
968
964
  let currencyObj = ALL_CURRENCIES.find(cur => cur.code === currency) || {
969
965
  name: 'Dong',
970
966
  code: 'VND',
@@ -14,8 +14,7 @@ op.map = common.map;
14
14
  op.each = common.each;
15
15
  op.size = common.size;
16
16
  op.find = common.find;
17
- function getProductPropName(product) {
18
- let seperator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ' - ';
17
+ function getProductPropName(product, seperator = ' - ') {
19
18
  let options = op.get(product, 'options', []);
20
19
  let props = op.get(product, 'props', []);
21
20
  let multiPropsOptions = op.filter(options, option => op.size(option.values) > 1);
@@ -26,8 +25,7 @@ function getProductPropName(product) {
26
25
  });
27
26
  return names.join(seperator);
28
27
  }
29
- function getOrderDisplayName() {
30
- let order = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
28
+ function getOrderDisplayName(order = {}) {
31
29
  return order.number || order.id || '';
32
30
  }
33
31
  function displayOrderShippingAddress(order, isShorten) {
@@ -14,12 +14,9 @@ class Pubsub {
14
14
  }
15
15
  publish(topic, payload, payload2, payload3) {
16
16
  this.listeners[topic] = filter(this.listeners[topic], sub => sub.obj._isMounted);
17
- map(this.listeners[topic], _ref => {
18
- let {
19
- cb
20
- } = _ref;
21
- return cb(payload, payload2, payload3);
22
- });
17
+ map(this.listeners[topic], ({
18
+ cb
19
+ }) => cb(payload, payload2, payload3));
23
20
  }
24
21
  on2(obj, topic, cb) {
25
22
  if (!this.listeners[topic]) this.listeners[topic] = [];