@subiz/widget-v4 4.1.122 → 4.1.124

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 (76) hide show
  1. package/assets/less/form.less +1 -1
  2. package/assets/less/message.less +7 -0
  3. package/assets/less/widget_header.less +5 -3
  4. package/compiled_src/chatbox/Event.js +15 -11
  5. package/compiled_src/chatbox/TextMessage.js +6 -2
  6. package/compiled_src/chatbox/Widget.js +4 -6
  7. package/compiled_src/plugin.js +1 -0
  8. package/compiled_src/store/api.js +5 -2
  9. package/compiled_src/store/api_fake.js +0 -1
  10. package/compiled_src/store/chain.js +228 -0
  11. package/compiled_src/store/inmem_localstorage.js +33 -0
  12. package/compiled_src/store/kv.js +86 -0
  13. package/compiled_src/store/lsdb.js +68 -0
  14. package/compiled_src/store/store.js +27 -20
  15. package/dist/132.js +6433 -2574
  16. package/dist/178.js +406 -0
  17. package/dist/18a02a9c54e.132.js +1 -0
  18. package/dist/18a02a9c54e.178.js +1 -0
  19. package/dist/18a02a9c54e.213.js +1 -0
  20. package/dist/18a02a9c54e.335.js +1 -0
  21. package/dist/18a02a9c54e.362.js +1 -0
  22. package/dist/18a02a9c54e.441.js +1 -0
  23. package/dist/18a02a9c54e.605.js +1 -0
  24. package/dist/18a02a9c54e.678.js +1 -0
  25. package/dist/18a02a9c54e.782.js +1 -0
  26. package/dist/18a02a9c54e.app.js +1 -0
  27. package/dist/{19643345ab6.index.html → 18a02a9c54e.index.html} +4 -28
  28. package/dist/{19643345ab6.library.html → 18a02a9c54e.library.html} +4 -28
  29. package/dist/18a02a9c54e.library.js +1 -0
  30. package/dist/{19643345ab6.preview.html → 18a02a9c54e.preview.html} +1 -1
  31. package/dist/18a02a9c54e.preview.js +1 -0
  32. package/dist/18a02a9c54e.screenshoot.js +1 -0
  33. package/dist/18a02a9c54e.webview.js +1 -0
  34. package/dist/213.js +2780 -0
  35. package/dist/{74.js → 335.js} +35 -35
  36. package/dist/362.js +107 -0
  37. package/dist/441.js +2855 -0
  38. package/dist/{490.js → 605.js} +82 -82
  39. package/dist/{997.js → 678.js} +6 -6
  40. package/dist/782.js +107 -0
  41. package/dist/HASH +1 -1
  42. package/dist/assets/img/{subiz-mono.8fbc067.svg → subiz-mono.877e9f5.svg} +1 -1
  43. package/dist/malicious-app.js +4 -6
  44. package/dist/screenshoot.html +1 -1
  45. package/dist/screenshoot.js +4849 -9583
  46. package/package.json +1 -2
  47. package/src/chatbox/Event.js +5 -3
  48. package/src/chatbox/TextMessage.js +6 -2
  49. package/src/chatbox/Widget.js +3 -4
  50. package/src/chatbox/main.js +1 -0
  51. package/src/plugin.js +2 -0
  52. package/src/store/api.js +5 -2
  53. package/src/store/api_fake.js +0 -1
  54. package/src/store/chain.js +255 -0
  55. package/src/store/inmem_localstorage.js +40 -0
  56. package/src/store/kv.js +103 -0
  57. package/src/store/lsdb.js +74 -0
  58. package/src/store/store.js +27 -22
  59. package/dist/127.js +0 -273
  60. package/dist/185.js +0 -1885
  61. package/dist/19643345ab6.127.js +0 -1
  62. package/dist/19643345ab6.132.js +0 -1
  63. package/dist/19643345ab6.185.js +0 -1
  64. package/dist/19643345ab6.27.js +0 -1
  65. package/dist/19643345ab6.278.js +0 -1
  66. package/dist/19643345ab6.459.js +0 -1
  67. package/dist/19643345ab6.490.js +0 -1
  68. package/dist/19643345ab6.74.js +0 -1
  69. package/dist/19643345ab6.997.js +0 -1
  70. package/dist/19643345ab6.app.js +0 -1
  71. package/dist/19643345ab6.library.js +0 -1
  72. package/dist/19643345ab6.preview.js +0 -1
  73. package/dist/19643345ab6.webview.js +0 -1
  74. package/dist/27.js +0 -107
  75. package/dist/278.js +0 -406
  76. package/dist/459.js +0 -107
@@ -94,7 +94,7 @@ select.form-control.input--error:focus {
94
94
  .label {
95
95
  display: block;
96
96
  padding-bottom: 6px;
97
- margin-top: 14px;
97
+ margin-top: 8px;
98
98
  .color(@gray-600);
99
99
  font-size: 14px;
100
100
  font-weight: 500;
@@ -111,6 +111,10 @@
111
111
  //padding: 12px;
112
112
  }
113
113
 
114
+ .message-text--user.message-user--error {
115
+ background-color: @red;
116
+ }
117
+
114
118
  .message-text--agent {
115
119
  line-height: 1.5;
116
120
  white-space: pre-wrap;
@@ -178,11 +182,14 @@
178
182
 
179
183
  a.message_error {
180
184
  .color(@red);
185
+ opacity: 0.8;
181
186
  display: block;
182
187
  text-align: end;
183
188
  font-size: 13px;
189
+ margin-top: 5px;
184
190
  margin-bottom: 10px;
185
191
  &:hover {
192
+ opacity: 1;
186
193
  .color(@red);
187
194
  }
188
195
  }
@@ -123,21 +123,23 @@
123
123
  flex: 1;
124
124
  display: flex;
125
125
  flex-direction: column;
126
- margin-left: @spacer2;
127
126
  z-index: 1;
128
127
  }
129
128
 
130
129
  .widget-header--button-close {
131
130
  display: flex;
131
+ border-radius: 6px;
132
132
  justify-self: flex-end;
133
133
  align-items: center;
134
134
  align-self: flex-start;
135
-
135
+ opacity: 0.6;
136
136
  transition:
137
+ opacity 0.15s ease,
137
138
  scale 0.15s ease,
138
139
  filter 0.15s ease;
139
140
  filter: brightness(0.95);
140
141
  &:hover {
142
+ opacity: 1;
141
143
  filter: brightness(1.1);
142
144
  scale: 1.1;
143
145
  }
@@ -149,7 +151,6 @@
149
151
  background-size: contain;
150
152
  background-repeat: no-repeat;
151
153
  background-position: center;
152
-
153
154
  width: 24px;
154
155
  height: 24px;
155
156
  display: block;
@@ -182,6 +183,7 @@
182
183
  .widget-header--wrap-button-back {
183
184
  display: flex;
184
185
  position: relative;
186
+ margin-right: @spacer1;
185
187
  }
186
188
 
187
189
  .fade-enter-active,
@@ -21,6 +21,9 @@ var _time = _interopRequireDefault(require("./time.js"));
21
21
  var _common = require("../common.js");
22
22
  var _preact = require("preact");
23
23
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
24
+ 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; }
25
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
26
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
24
27
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
25
28
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
26
29
  let OrderAttachments = false;
@@ -28,6 +31,13 @@ const LoadOrderAttachments = () => Promise.resolve().then(() => _interopRequireW
28
31
  class Event extends _common.Com {
29
32
  constructor(props) {
30
33
  super(props);
34
+ _defineProperty(this, "resendMessage", () => {
35
+ let cid = _index.default.convoOfEv(this.props.event.ev);
36
+ const message = _index.default.get(this.props.event, 'ev.data.message');
37
+ this.props.store.sendConvoEvent(cid, 'message_sent', {
38
+ message
39
+ });
40
+ });
31
41
  this.props.store.onConvoEvent(this, ev => this.onEvent(ev));
32
42
  this.refForm = (0, _preact.createRef)();
33
43
  this.state = {
@@ -318,18 +328,19 @@ class Event extends _common.Com {
318
328
  class: "pt-3"
319
329
  });
320
330
  let $error = null;
331
+ if (ev._error) $dot = null;
321
332
  if (ev._error && ev.type === 'message_sent') {
322
333
  let msg = this.props.t('error_send_message');
323
334
  if (ev._error_message) msg = this.props.t(ev._error_message);
324
335
  $error = (0, _preact.h)("a", {
325
336
  class: "message_error",
326
337
  src: "javascript:;",
327
- onClick: e => this.resendMessage()
338
+ onClick: this.resendMessage
328
339
  }, (0, _preact.h)("div", {
329
- class: "message_error__text"
330
- }, msg), (0, _preact.h)("div", {
331
340
  class: "message_error__icon"
332
- }));
341
+ }), "\xA0", (0, _preact.h)("div", {
342
+ class: "message_error__text"
343
+ }, msg));
333
344
  }
334
345
  return (0, _preact.h)("div", {
335
346
  class: "convo-event user-message"
@@ -480,13 +491,6 @@ class Event extends _common.Com {
480
491
  state
481
492
  }));
482
493
  }
483
- resendMessage() {
484
- let cid = _index.default.convoOfEv(this.props.event.ev);
485
- const message = _index.default.get(this.props.event, 'ev.data.message');
486
- this.props.store.sendConvoEvent(cid, 'message_sent', {
487
- message
488
- });
489
- }
490
494
  getSenderName(ev) {
491
495
  let bytype = _index.default.get(ev, 'by.type');
492
496
  let byid = _index.default.get(ev, 'by.display_id', _index.default.get(ev, 'by.id'));
@@ -63,8 +63,10 @@ class TextMessage extends _common.Com {
63
63
  class: "message-agent message-text--agent",
64
64
  title: t
65
65
  }, tags, this.renderTime());
66
+ let msgcls = 'message-user message-text--user';
67
+ if (this.props.ev._error) msgcls += ' message-user--error';
66
68
  return (0, _preact.h)("div", {
67
- class: "message-user message-text--user",
69
+ class: msgcls,
68
70
  title: t
69
71
  }, tags);
70
72
  }
@@ -82,8 +84,10 @@ class TextMessage extends _common.Com {
82
84
  onLink: this.props.onLink
83
85
  }), this.renderTime());
84
86
  }
87
+ let msgcls = 'message-user message-text--user';
88
+ if (this.props.ev._error) msgcls += ' message-user--error';
85
89
  return (0, _preact.h)("div", {
86
- class: "message-user message-text--user",
90
+ class: msgcls,
87
91
  title: t
88
92
  }, (0, _preact.h)(_block.default, {
89
93
  block: block,
@@ -637,7 +637,7 @@ class Widget extends _common.Com {
637
637
  class: "label",
638
638
  for: 'form_' + encode(key)
639
639
  }, label, field.is_required ? (0, _preact.h)("span", {
640
- class: "ml-1 red"
640
+ class: "red"
641
641
  }, "*") : ''), $field, field.error ? (0, _preact.h)("div", {
642
642
  class: "form-control--valid-input--error"
643
643
  }, field.error) : '');
@@ -661,18 +661,16 @@ class Widget extends _common.Com {
661
661
  form: form,
662
662
  onMount: this.formMounted
663
663
  }), (0, _preact.h)("div", {
664
- class: "widget-body--content flex-grow-1 pl-3 pr-3 d-flex flex-column"
664
+ class: "widget-body--content flex-grow-1 pl-3 pr-3 pb-2 d-flex flex-column"
665
665
  }, (0, _preact.h)("div", {
666
- class: "mt-3 d-flex flex-column"
666
+ class: "mt-2 d-flex flex-column"
667
667
  }, (0, _preact.h)("div", null, title), this.renderFields(form, formName)), (0, _preact.h)("div", {
668
668
  style: "min-height: 15px !important; flex: 1 !important; flex-shrink: 0 !important"
669
669
  }), (0, _preact.h)("button", {
670
670
  class: btncls,
671
671
  onClick: _ => this.submitPrechatForm(form, formName),
672
672
  disabled: !!hasEmptyError || !!hasError || this.state.creating
673
- }, submitLabel)), (0, _preact.h)("div", {
674
- class: "mt-2"
675
- }));
673
+ }, submitLabel)));
676
674
  }
677
675
  goToConvo(cid) {
678
676
  this.props.onGo({
@@ -60,6 +60,7 @@ function Plugin(plugin, store, $container, lib) {
60
60
  var _render = async () => {
61
61
  if (_destroy) return;
62
62
  if (!$div) return;
63
+ if (!this.t) return;
63
64
  if (plugin.type === 'chatbox') {
64
65
  (0, _preact.render)((0, _preact.h)(_main.default, {
65
66
  destroy: _destroy,
@@ -100,7 +100,6 @@ class _default {
100
100
  _defineProperty(this, "updateUser", data => this.apireq.post(`/accounts/${this.accid}/users/${this.uid}`, data));
101
101
  _defineProperty(this, "getUser", _ => this.apireq.get(`/accounts/${this.accid}/users/${this.uid}`));
102
102
  _defineProperty(this, "getAccountSetting", () => this.apireq.get(`/accounts/${this.accid}/settings`));
103
- _defineProperty(this, "getIsOnline", () => this.apireq.get(`/accounts/${this.accid}/is_online`));
104
103
  _defineProperty(this, "sendImpression", impression => this.apireq.post(`/accounts/${this.accid}/campaigns/${impression.campaign_id}/impressions`, impression));
105
104
  _defineProperty(this, "sendConversion", conversion => this.apireq.post(`/accounts/${this.accid}/campaigns/${conversion.campaign_id}/conversions`, conversion));
106
105
  _defineProperty(this, "lookupOrder", key => ajax.setBaseUrl(this.ApiURL).setContentType('text/plain').beforeHook(jsonifyTextPlain).setParser('json').addQuery('x-signed-key', key).get(`/orders/123`));
@@ -146,7 +145,11 @@ class _default {
146
145
  let outuser;
147
146
  for (let i = 0; true; i++) {
148
147
  outuser = await ajax.setBaseUrl(this.ApiURL).withCredentials(true).addQuery('v', '6').addQuery('x-user-ref', this.ref).setParser('json').get(`/accounts/${this.accid}/users/${this.ref}`);
149
- if (outuser.error && _index.default.get(outuser, 'body.error.code', '').indexOf('locked_account') != -1) break;
148
+ if (_index.default.get(outuser, 'body.error.code', '').indexOf('locked_account') != -1) break;
149
+ if (_index.default.get(outuser, 'body.error.code', '').indexOf('user_is_banned') != -1) {
150
+ await _index.default.sleep(120000);
151
+ continue;
152
+ }
150
153
  if (!_index.default.get(outuser, 'body.id')) {
151
154
  let sleeptime = Math.min(2000 + i * 400, 60000);
152
155
  await _index.default.sleep(sleeptime);
@@ -73,7 +73,6 @@ class _default {
73
73
  }
74
74
  }));
75
75
  _defineProperty(this, "getAccountSetting", () => this.apireq.get(`/accounts/${this.accid}/settings`));
76
- _defineProperty(this, "getIsOnline", () => this.apireq.get(`/accounts/${this.accid}/is_online`));
77
76
  _defineProperty(this, "sendImpression", impression => OK200);
78
77
  _defineProperty(this, "sendConversion", conversion => OK200);
79
78
  this.FileURL = FileURL;
@@ -0,0 +1,228 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const ChainMaxSize = 50;
8
+ class Chain {
9
+ constructor(db, schema, inmem) {
10
+ this.schema = schema + '_chain';
11
+ this.dead = false;
12
+ this.db = db;
13
+ this.anchorCache = {};
14
+ this.cache = {};
15
+ this.init();
16
+ }
17
+ init() {
18
+ let inmemItemM = {};
19
+ let allitems = this.db.all('items');
20
+ allitems.map(item => {
21
+ inmemItemM[item.chain] = inmemItemM[item.chain] || {};
22
+ inmemItemM[item.chain][item.id] = {
23
+ id: item.id,
24
+ chain: item.chain,
25
+ full_id: item.full_id,
26
+ index: item.index,
27
+ value: item.value
28
+ };
29
+ });
30
+ map(inmemItemM, (itemM, chain) => {
31
+ if (size(itemM) < ChainMaxSize) return;
32
+ let items = orderBy(map(itemM), ['index'], 'desc');
33
+ let removekeys = [];
34
+ for (var i = ChainMaxSize; i < items.length; i++) {
35
+ removekeys.push(items[i].full_id);
36
+ delete itemM[items[i].id];
37
+ }
38
+ this.db.removes('items', removekeys);
39
+ inmemItemM[chain] = itemM;
40
+ });
41
+ this.cache = inmemItemM;
42
+ }
43
+ destroy() {
44
+ this.db.clear('items');
45
+ this.dead = true;
46
+ this.cache = {};
47
+ this.anchorCache = {};
48
+ this.db = undefined;
49
+ }
50
+ put(chain, id, node_index, value) {
51
+ if (this.dead) return;
52
+ let inmemItemM = this.cache[chain] || {};
53
+ let bottom = minIndex(inmemItemM) || {};
54
+ let bottomIndex = bottom.index || 'z';
55
+ if (size(inmemItemM) == 0) bottomIndex = '';
56
+ let item = {
57
+ id,
58
+ index: node_index,
59
+ value,
60
+ chain,
61
+ full_id: chain + ':' + id
62
+ };
63
+ delete inmemItemM[item.id];
64
+ if (bottomIndex > item.index + '') return;
65
+ inmemItemM[item.id] = item;
66
+ this.cache[chain] = inmemItemM;
67
+ this.db.put('items', item.full_id, item);
68
+ }
69
+ listM(chain) {
70
+ if (this.dead) return {};
71
+ let inmemItemM = this.cache[chain] || {};
72
+ let out = {};
73
+ map(inmemItemM, (item, id) => {
74
+ out[id] = item.value;
75
+ });
76
+ return out;
77
+ }
78
+ async fetchMore(chain, limit = 20, api) {
79
+ if (this.dead) return {
80
+ error: 'dead'
81
+ };
82
+ if (!api) return {
83
+ error: 'no api'
84
+ };
85
+ let anchor = this.anchorCache[chain] || '';
86
+ var [apiItems, newanchor, error] = await api(chain, anchor, limit);
87
+ if (error) return {
88
+ error
89
+ };
90
+ if (this.dead) return {
91
+ error: 'dead'
92
+ };
93
+ let inmemItemM = this.cache[chain] || {};
94
+ if (apiItems.length === 0) return {
95
+ end: true
96
+ };
97
+ apiItems.forEach(item => {
98
+ item.chain = chain;
99
+ item.full_id = chain + ':' + item.id;
100
+ inmemItemM[item.id] = item;
101
+ this.db.put('items', item.full_id, item);
102
+ });
103
+ this.anchorCache[chain] = newanchor;
104
+ this.cache[chain] = inmemItemM;
105
+ return {};
106
+ }
107
+ del(chain, id) {
108
+ if (this.dead) return;
109
+ let inmemItemM = this.cache[chain] || {};
110
+ let full_id = chain + ':' + id;
111
+ delete inmemItemM[id];
112
+ this.db.removes('items', [full_id]);
113
+ }
114
+ match(chain, id) {
115
+ return this.listM(chain)[id];
116
+ }
117
+ async reload(chain, api) {
118
+ if (this.dead) return;
119
+ let top = maxIndex(this.listM(chain)) || {};
120
+ let topindex = top.index;
121
+ if (!topindex) topindex = Date.now();
122
+ var lastanchor = '';
123
+ var fetchedItems = {};
124
+ for (;;) {
125
+ if (this.dead) return;
126
+ let [newItems, newanchor, error] = await api(chain, lastanchor, 50);
127
+ if (error) return;
128
+ if (this.dead) return;
129
+ newItems.map(item => {
130
+ fetchedItems[item.id] = Object.assign({}, item, {
131
+ chain,
132
+ full_id: chain + ':' + item.id
133
+ });
134
+ });
135
+ if (newItems.length === 0 || newanchor === lastanchor) break;
136
+ if (fetchedItems.length >= 200) {
137
+ let inmemItemM = this.cache[chain] || {};
138
+ let removeids = [];
139
+ map(inmemItemM, item => {
140
+ if (item.chain !== chain) return;
141
+ removeids.push(item.full_id);
142
+ });
143
+ this.db.removes('items', removeids);
144
+ this.cache[chain] = {};
145
+ break;
146
+ }
147
+ let minindexitem = minIndex(fetchedItems) || {};
148
+ if (minindexitem.index <= topindex) {
149
+ lastanchor = this.anchorCache[chain] || newanchor;
150
+ break;
151
+ }
152
+ lastanchor = newanchor;
153
+ }
154
+ for (var i = 0; i < Object.keys(fetchedItems).length; i++) {
155
+ let item = fetchedItems[Object.keys(fetchedItems)[i]];
156
+ this.db.put('items', item.full_id, item);
157
+ this.cache[item.chain] = this.cache[item.chain] || {};
158
+ this.cache[item.chain][item.id] = item;
159
+ }
160
+ this.anchorCache[chain] = lastanchor;
161
+ }
162
+ }
163
+ exports.default = Chain;
164
+ function minIndex(obj) {
165
+ if (!obj) return;
166
+ let keys = Object.keys(obj);
167
+ if (!keys.length) return;
168
+ let min = Infinity;
169
+ let minKey = Object.keys(obj)[0];
170
+ for (var i = 0; i < keys.length; i++) {
171
+ let index = obj[keys[i]] && obj[keys[i]].index || Infinity;
172
+ if (index < min) {
173
+ min = index;
174
+ minKey = keys[i];
175
+ }
176
+ }
177
+ return obj[minKey];
178
+ }
179
+ function maxIndex(obj) {
180
+ if (!obj) return;
181
+ let keys = Object.keys(obj);
182
+ if (!keys.length) return;
183
+ let max = -Infinity;
184
+ let maxKey = Object.keys(obj)[0];
185
+ for (var i = 0; i < keys.length; i++) {
186
+ let index = obj[keys[i]] && obj[keys[i]].index || -Infinity;
187
+ if (index > max) {
188
+ max = index;
189
+ maxKey = keys[i];
190
+ }
191
+ }
192
+ return obj[keys[maxKey]];
193
+ }
194
+ function map(collection, predicate) {
195
+ if (!collection) return [];
196
+ if (!predicate) return collection;
197
+ var out = [];
198
+ if (Array.isArray(collection)) {
199
+ for (let i = 0; i < collection.length; i++) {
200
+ out.push(predicate(collection[i], i));
201
+ }
202
+ return out;
203
+ }
204
+ if (typeof collection === 'object') {
205
+ var keys = Object.keys(collection);
206
+ for (let i = 0; i < keys.length; i++) {
207
+ var k = keys[i];
208
+ out.push(predicate(collection[k], k));
209
+ }
210
+ return out;
211
+ }
212
+ return out;
213
+ }
214
+ function size(o) {
215
+ if (!o) return 0;
216
+ if (o.length !== undefined) return o.length;
217
+ return Object.keys(o).length;
218
+ }
219
+ function orderBy(a, k, d) {
220
+ var clone = [];
221
+ map(a, v => clone.push(v));
222
+ clone.sort((i, j) => {
223
+ if (i[k] === j[k]) return 0;
224
+ var r = i[k] < j[k] ? -1 : 1;
225
+ return d === 'desc' ? -r : r;
226
+ });
227
+ return clone;
228
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ var localStorageMemory = {};
4
+ var cache = {};
5
+ localStorageMemory.length = 0;
6
+ localStorageMemory.getItem = function (key) {
7
+ if (key in cache) return cache[key];
8
+ return null;
9
+ };
10
+ localStorageMemory.setItem = function (key, value) {
11
+ if (typeof value === 'undefined') {
12
+ localStorageMemory.removeItem(key);
13
+ } else {
14
+ if (!Object.prototype.hasOwnProperty.call(cache, key)) {
15
+ localStorageMemory.length++;
16
+ }
17
+ cache[key] = value;
18
+ }
19
+ };
20
+ localStorageMemory.removeItem = function (key) {
21
+ if (Object.prototype.hasOwnProperty.call(cache, key)) {
22
+ delete cache[key];
23
+ localStorageMemory.length--;
24
+ }
25
+ };
26
+ localStorageMemory.key = function (index) {
27
+ return Object.keys(cache)[index] || null;
28
+ };
29
+ localStorageMemory.clear = function () {
30
+ cache = {};
31
+ localStorageMemory.length = 0;
32
+ };
33
+ module.exports = localStorageMemory;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ let KvMaxSize = 500;
8
+ class _default {
9
+ constructor(db, schema) {
10
+ this.name = schema;
11
+ schema += '_kv';
12
+ this.dead = false;
13
+ this.db = db;
14
+ this.cache = {};
15
+ this.initialized = false;
16
+ this.init();
17
+ }
18
+ refreshCache() {
19
+ if (this.dead) return;
20
+ let inmemItemM = {};
21
+ let allitems = this.db.all('items');
22
+ allitems.forEach(function (item) {
23
+ inmemItemM[item.key] = item.value;
24
+ });
25
+ this.cache = inmemItemM;
26
+ }
27
+ init() {
28
+ if (this.initialized) return;
29
+ let inmemItemM = {};
30
+ console.time('KV' + this.name);
31
+ let allitems = this.db.all('items');
32
+ allitems.forEach(function (item) {
33
+ inmemItemM[item.key] = item.value;
34
+ });
35
+ this.cache = inmemItemM;
36
+ let allkeys = Object.keys(this.cache);
37
+ if (allkeys.length > KvMaxSize) {
38
+ let liveChance = KvMaxSize / 2 / allkeys.lenth;
39
+ let removekeys = [];
40
+ for (var i = 0; i < KvMaxSize; i++) {
41
+ let live = Math.random() <= liveChance;
42
+ if (live) continue;
43
+ let key = allkeys[i];
44
+ delete this.cache[key];
45
+ removekeys.push(key);
46
+ }
47
+ this.db.removes('items', [removekeys]);
48
+ }
49
+ this.initialized = true;
50
+ console.timeEnd('KV' + this.name);
51
+ }
52
+ all() {
53
+ if (this.dead) return [];
54
+ if (!this.initialized) return [];
55
+ return this.cache;
56
+ }
57
+ match(key) {
58
+ if (this.dead || !this.initialized) return;
59
+ if (!key) return;
60
+ return this.cache[key];
61
+ }
62
+ put(key, value) {
63
+ if (!key) return;
64
+ if (this.dead) return [];
65
+ if (!this.initialized) throw new Error('uninitialized');
66
+ this.cache[key] = value;
67
+ this.db.put('items', key, {
68
+ key,
69
+ value
70
+ });
71
+ }
72
+ del(key) {
73
+ if (this.dead) return;
74
+ if (!this.initialized) throw new Error('uninitialized');
75
+ delete this.cache[key];
76
+ this.db.removes('items', [key]);
77
+ }
78
+ destroy() {
79
+ this.db.clear('items');
80
+ this.dead = true;
81
+ this.db = undefined;
82
+ this.cache = undefined;
83
+ this.initialized = false;
84
+ }
85
+ }
86
+ exports.default = _default;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _index = _interopRequireDefault(require("../util/index.js"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ let memlocalStorage = require('./inmem_localstorage.js');
10
+ let requestIdleCallback = typeof window !== 'undefined' ? window.requestIdleCallback : null;
11
+ if (!requestIdleCallback) requestIdleCallback = cb => cb();
12
+ const LIMIT = 80;
13
+ class _default {
14
+ constructor(schema, inmem) {
15
+ this.localStorage = memlocalStorage;
16
+ this.inmem = inmem;
17
+ this.allkeys = {};
18
+ if (!inmem) {
19
+ try {
20
+ window.localStorage.setItem('sbzstore1029', '?');
21
+ window.localStorage.removeItem('sbzstore1029');
22
+ this.localStorage = window.localStorage;
23
+ } catch (e) {}
24
+ }
25
+ this.schema = schema;
26
+ }
27
+ all(table) {
28
+ let items = [];
29
+ for (var i = 0; i < this.localStorage.length; i++) {
30
+ let key = this.localStorage.key(i);
31
+ if (!key.startsWith(this.schema + '#' + table + '#')) continue;
32
+ this.allkeys[key] = true;
33
+ if (this.inmem) items.push(this.localStorage.getItem(key));else items.push(_index.default.parseJSON(this.localStorage.getItem(key)));
34
+ }
35
+ return items;
36
+ }
37
+ removes(table, keys) {
38
+ for (var i = 0; i < keys.length; i++) {
39
+ delete this.allkeys[this.schema + '#' + table + '#' + keys[i]];
40
+ this.localStorage.removeItem(this.schema + '#' + table + '#' + keys[i]);
41
+ }
42
+ }
43
+ clear(table) {
44
+ for (var i = 0; i < this.localStorage.length; i++) {
45
+ let key = this.localStorage.key(i);
46
+ if (!key.startsWith(this.schema + '#' + table + '#')) continue;
47
+ this.localStorage.removeItem(key);
48
+ }
49
+ this.allkeys = {};
50
+ }
51
+ put(table, key, value) {
52
+ this.allkeys[this.schema + '#' + table + '#' + key] = true;
53
+ if (this.inmem) return this.localStorage.setItem(this.schema + '#' + table + '#' + key, value);
54
+ if (Object.keys(this.allkeys).length > LIMIT) this.clear(table);
55
+ requestIdleCallback(() => {
56
+ try {
57
+ this.localStorage.setItem(this.schema + '#' + table + '#' + key, toString(value));
58
+ } catch (e) {
59
+ this.clear(table);
60
+ }
61
+ });
62
+ }
63
+ }
64
+ exports.default = _default;
65
+ function toString(obj) {
66
+ if (obj === undefined) return 'null';
67
+ return JSON.stringify(obj);
68
+ }