@subiz/widget-v4 4.1.210 → 4.1.212

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 (130) hide show
  1. package/README.md +21 -2
  2. package/assets/img/dot_chat.svg +3 -0
  3. package/assets/less/chatbox.less +9 -0
  4. package/assets/less/form.less +10 -0
  5. package/assets/less/message.less +114 -13
  6. package/assets/less/widget.less +15 -18
  7. package/compiled_src/call/css.js +1 -1
  8. package/compiled_src/chatbox/Buttons.js +7 -4
  9. package/compiled_src/chatbox/ChatButton.js +127 -29
  10. package/compiled_src/chatbox/Event.js +37 -5
  11. package/compiled_src/chatbox/Events.js +348 -129
  12. package/compiled_src/chatbox/FormAttachment.js +1 -1
  13. package/compiled_src/chatbox/Header.js +7 -2
  14. package/compiled_src/chatbox/InfoMessage.js +1 -1
  15. package/compiled_src/chatbox/MessageInput.js +24 -9
  16. package/compiled_src/chatbox/OrderAttachments.js +13 -13
  17. package/compiled_src/chatbox/QuoteMessage.js +3 -2
  18. package/compiled_src/chatbox/TextMessage.js +22 -18
  19. package/compiled_src/chatbox/Widget.js +200 -129
  20. package/compiled_src/chatbox/block.js +39 -29
  21. package/compiled_src/chatbox/conversation-history.js +44 -0
  22. package/compiled_src/chatbox/event-layout.js +59 -0
  23. package/compiled_src/chatbox/greeting.js +32 -0
  24. package/compiled_src/chatbox/main.js +3 -0
  25. package/compiled_src/common.js +13 -9
  26. package/compiled_src/form/css.js +1 -1
  27. package/compiled_src/lib.js +22 -32
  28. package/compiled_src/notif/css.js +1 -1
  29. package/compiled_src/plugin.js +11 -18
  30. package/compiled_src/popup/css.js +1 -1
  31. package/compiled_src/popup/popup.js +1 -1
  32. package/compiled_src/store/api.js +0 -2
  33. package/compiled_src/store/api_fake.js +1 -1
  34. package/compiled_src/store/attachments.js +28 -0
  35. package/compiled_src/store/chain.js +24 -10
  36. package/compiled_src/store/kv.js +9 -13
  37. package/compiled_src/store/lsdb.js +1 -1
  38. package/compiled_src/store/store.js +356 -117
  39. package/compiled_src/util/common.js +48 -41
  40. package/compiled_src/util/event.js +15 -0
  41. package/compiled_src/util/pubsub.js +28 -13
  42. package/compiled_src/util/url.js +18 -0
  43. package/dist/127.js +13 -13
  44. package/dist/132.js +1 -1
  45. package/dist/1a0f6f3ff1a.127.js +1 -0
  46. package/dist/{1a0d80f6e72.132.js → 1a0f6f3ff1a.132.js} +1 -1
  47. package/dist/{1a0d80f6e72.27.js → 1a0f6f3ff1a.27.js} +1 -1
  48. package/dist/1a0f6f3ff1a.278.js +1 -0
  49. package/dist/{1a0d80f6e72.339.js → 1a0f6f3ff1a.339.js} +1 -1
  50. package/dist/1a0f6f3ff1a.459.js +1 -0
  51. package/dist/1a0f6f3ff1a.app.js +1 -0
  52. package/dist/{1a0d80f6e72.chat.html → 1a0f6f3ff1a.chat.html} +1 -1
  53. package/dist/1a0f6f3ff1a.chat.js +1 -0
  54. package/dist/{1a0d80f6e72.form.html → 1a0f6f3ff1a.form.html} +1 -1
  55. package/dist/1a0f6f3ff1a.form.js +1 -0
  56. package/dist/{1a0d80f6e72.index.html → 1a0f6f3ff1a.index.html} +1 -1
  57. package/dist/{1a0d80f6e72.library.html → 1a0f6f3ff1a.library.html} +1 -1
  58. package/dist/1a0f6f3ff1a.library.js +1 -0
  59. package/dist/{1a0d80f6e72.preview.html → 1a0f6f3ff1a.preview.html} +1 -1
  60. package/dist/1a0f6f3ff1a.preview.js +1 -0
  61. package/dist/1a0f6f3ff1a.webview.js +1 -0
  62. package/dist/27.js +2 -2
  63. package/dist/459.js +2 -2
  64. package/dist/HASH +1 -1
  65. package/dist/assets/img/dot_chat.335fd8a.svg +3 -0
  66. package/dist/screenshoot.js +1523 -619
  67. package/package.json +12 -5
  68. package/src/chatbox/Buttons.js +5 -4
  69. package/src/chatbox/ChatButton.js +133 -39
  70. package/src/chatbox/Event.js +38 -5
  71. package/src/chatbox/Events.js +306 -134
  72. package/src/chatbox/FormAttachment.js +1 -1
  73. package/src/chatbox/Header.js +5 -4
  74. package/src/chatbox/InfoMessage.js +1 -1
  75. package/src/chatbox/MessageInput.js +15 -10
  76. package/src/chatbox/OrderAttachments.js +13 -13
  77. package/src/chatbox/QuoteMessage.js +3 -2
  78. package/src/chatbox/TextMessage.js +21 -20
  79. package/src/chatbox/Widget.js +150 -150
  80. package/src/chatbox/block.js +29 -27
  81. package/src/chatbox/conversation-history.js +37 -0
  82. package/src/chatbox/event-layout.js +72 -0
  83. package/src/chatbox/greeting.js +13 -0
  84. package/src/chatbox/main.js +3 -0
  85. package/src/common.js +15 -9
  86. package/src/lib.js +22 -35
  87. package/src/plugin.js +11 -13
  88. package/src/popup/popup.js +1 -1
  89. package/src/store/api.js +0 -2
  90. package/src/store/api_fake.js +1 -1
  91. package/src/store/attachments.js +21 -0
  92. package/src/store/chain.js +25 -12
  93. package/src/store/kv.js +10 -19
  94. package/src/store/lsdb.js +1 -1
  95. package/src/store/store.js +313 -130
  96. package/src/util/common.js +48 -43
  97. package/src/util/event.js +7 -0
  98. package/src/util/pubsub.js +27 -8
  99. package/src/util/url.js +14 -0
  100. package/test.cjs +59 -0
  101. package/assets/less/contact.less +0 -126
  102. package/compiled_src/util/common.test.js +0 -414
  103. package/compiled_src/util/event.test.js +0 -38
  104. package/compiled_src/util/extractor.test.js +0 -299
  105. package/compiled_src/util/extractor.test2.js +0 -61
  106. package/compiled_src/util/gate.test.js +0 -18
  107. package/compiled_src/util/pubsub.test.js +0 -35
  108. package/dist/1a0d80f6e72.127.js +0 -1
  109. package/dist/1a0d80f6e72.278.js +0 -1
  110. package/dist/1a0d80f6e72.459.js +0 -1
  111. package/dist/1a0d80f6e72.74.js +0 -1
  112. package/dist/1a0d80f6e72.997.js +0 -1
  113. package/dist/1a0d80f6e72.app.js +0 -1
  114. package/dist/1a0d80f6e72.chat.js +0 -1
  115. package/dist/1a0d80f6e72.form.js +0 -1
  116. package/dist/1a0d80f6e72.library.js +0 -1
  117. package/dist/1a0d80f6e72.preview.js +0 -1
  118. package/dist/1a0d80f6e72.webview.js +0 -1
  119. package/dist/74.js +0 -376
  120. package/dist/997.js +0 -37
  121. package/src/contact/contact.js +0 -400
  122. package/src/contact/css.js +0 -1
  123. package/src/util/common.test.js +0 -301
  124. package/src/util/event.test.js +0 -31
  125. package/src/util/extractor.test.js +0 -240
  126. package/src/util/extractor.test2.js +0 -56
  127. package/src/util/gate.test.js +0 -20
  128. package/src/util/pubsub.test.js +0 -37
  129. /package/dist/{1a0d80f6e72.185.js → 1a0f6f3ff1a.185.js} +0 -0
  130. /package/dist/{1a0d80f6e72.490.js → 1a0f6f3ff1a.490.js} +0 -0
@@ -104,6 +104,20 @@ class Chain {
104
104
  this.cache[chain] = inmemItemM;
105
105
  return {};
106
106
  }
107
+ merge(chain, items) {
108
+ if (this.dead) return;
109
+ const cached = this.cache[chain] || {};
110
+ for (const item of items) {
111
+ const node = {
112
+ ...item,
113
+ chain,
114
+ full_id: chain + ':' + item.id
115
+ };
116
+ cached[item.id] = node;
117
+ this.db.put('items', node.full_id, node);
118
+ }
119
+ this.cache[chain] = cached;
120
+ }
107
121
  del(chain, id) {
108
122
  if (this.dead) return;
109
123
  let inmemItemM = this.cache[chain] || {};
@@ -116,7 +130,7 @@ class Chain {
116
130
  }
117
131
  async reload(chain, api) {
118
132
  if (this.dead) return;
119
- let top = maxIndex(this.listM(chain)) || {};
133
+ let top = maxIndex(this.cache[chain] || {}) || {};
120
134
  let topindex = top.index;
121
135
  if (!topindex) topindex = Date.now();
122
136
  var lastanchor = '';
@@ -133,7 +147,12 @@ class Chain {
133
147
  });
134
148
  });
135
149
  if (newItems.length === 0 || newanchor === lastanchor) break;
136
- if (fetchedItems.length >= 200) {
150
+ let minindexitem = minIndex(fetchedItems) || {};
151
+ if (minindexitem.index <= topindex) {
152
+ lastanchor = this.anchorCache[chain] || newanchor;
153
+ break;
154
+ }
155
+ if (size(fetchedItems) >= 200) {
137
156
  let inmemItemM = this.cache[chain] || {};
138
157
  let removeids = [];
139
158
  map(inmemItemM, item => {
@@ -142,17 +161,12 @@ class Chain {
142
161
  });
143
162
  this.db.removes('items', removeids);
144
163
  this.cache[chain] = {};
145
- break;
146
- }
147
- let minindexitem = minIndex(fetchedItems) || {};
148
- if (minindexitem.index <= topindex) {
149
- lastanchor = this.anchorCache[chain] || newanchor;
164
+ lastanchor = newanchor;
150
165
  break;
151
166
  }
152
167
  lastanchor = newanchor;
153
168
  }
154
- for (var i = 0; i < Object.keys(fetchedItems).length; i++) {
155
- let item = fetchedItems[Object.keys(fetchedItems)[i]];
169
+ for (const item of Object.values(fetchedItems)) {
156
170
  this.db.put('items', item.full_id, item);
157
171
  this.cache[item.chain] = this.cache[item.chain] || {};
158
172
  this.cache[item.chain][item.id] = item;
@@ -189,7 +203,7 @@ function maxIndex(obj) {
189
203
  maxKey = keys[i];
190
204
  }
191
205
  }
192
- return obj[keys[maxKey]];
206
+ return obj[maxKey];
193
207
  }
194
208
  function map(collection, predicate) {
195
209
  if (!collection) return [];
@@ -32,21 +32,16 @@ class _default {
32
32
  inmemItemM[item.key] = item.value;
33
33
  });
34
34
  this.cache = inmemItemM;
35
- let allkeys = Object.keys(this.cache);
36
- if (allkeys.length > KvMaxSize) {
37
- let liveChance = KvMaxSize / 2 / allkeys.lenth;
38
- let removekeys = [];
39
- for (var i = 0; i < KvMaxSize; i++) {
40
- let live = Math.random() <= liveChance;
41
- if (live) continue;
42
- let key = allkeys[i];
43
- delete this.cache[key];
44
- removekeys.push(key);
45
- }
46
- this.db.removes('items', [removekeys]);
47
- }
35
+ this.trimCache();
48
36
  this.initialized = true;
49
37
  }
38
+ trimCache() {
39
+ const keys = Object.keys(this.cache);
40
+ if (keys.length <= KvMaxSize) return;
41
+ const removed = keys.slice(0, keys.length - Math.floor(KvMaxSize / 2));
42
+ for (const key of removed) delete this.cache[key];
43
+ this.db.removes('items', removed);
44
+ }
50
45
  all() {
51
46
  if (this.dead) return [];
52
47
  if (!this.initialized) return [];
@@ -66,6 +61,7 @@ class _default {
66
61
  key,
67
62
  value
68
63
  });
64
+ this.trimCache();
69
65
  }
70
66
  del(key) {
71
67
  if (this.dead) return;
@@ -68,5 +68,5 @@ class _default {
68
68
  exports.default = _default;
69
69
  function toString(obj) {
70
70
  if (obj === undefined) return 'null';
71
- return JSON.stringify(obj);
71
+ return _index.default.stringify(obj);
72
72
  }