@subiz/widget-v4 4.1.206 → 4.1.208
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.
- package/assets/less/chatbox.less +1 -0
- package/assets/less/widget.less +2 -2
- package/compiled_src/chatbox/block.js +5 -0
- package/compiled_src/chatbox/main.js +11 -6
- package/compiled_src/util/common.js +2 -0
- package/compiled_src/util/common.test.js +8 -0
- package/package.json +7 -7
- package/src/chatbox/block.js +6 -1
- package/src/chatbox/main.js +16 -8
- package/src/util/common.js +2 -0
- package/src/util/common.test.js +7 -0
- package/dist/127.js +0 -273
- package/dist/132.js +0 -2817
- package/dist/185.js +0 -1917
- package/dist/1a0475c4721.127.js +0 -1
- package/dist/1a0475c4721.132.js +0 -1
- package/dist/1a0475c4721.185.js +0 -1
- package/dist/1a0475c4721.27.js +0 -1
- package/dist/1a0475c4721.278.js +0 -1
- package/dist/1a0475c4721.339.js +0 -1
- package/dist/1a0475c4721.459.js +0 -1
- package/dist/1a0475c4721.490.js +0 -1
- package/dist/1a0475c4721.74.js +0 -1
- package/dist/1a0475c4721.997.js +0 -1
- package/dist/1a0475c4721.app.js +0 -1
- package/dist/1a0475c4721.chat.html +0 -1
- package/dist/1a0475c4721.chat.js +0 -1
- package/dist/1a0475c4721.form.html +0 -1
- package/dist/1a0475c4721.form.js +0 -1
- package/dist/1a0475c4721.index.html +0 -1
- package/dist/1a0475c4721.library.html +0 -1
- package/dist/1a0475c4721.library.js +0 -1
- package/dist/1a0475c4721.preview.html +0 -1
- package/dist/1a0475c4721.preview.js +0 -1
- package/dist/1a0475c4721.webview.js +0 -1
- package/dist/27.js +0 -37
- package/dist/459.js +0 -37
- package/dist/490.js +0 -305
- package/dist/74.js +0 -376
- package/dist/997.js +0 -37
- package/dist/HASH +0 -1
- package/dist/assets/img/Facebook.64607ec.png +0 -0
- package/dist/assets/img/Zalo.6845707.png +0 -0
- package/dist/assets/img/award1a.1a58e10.png +0 -0
- package/dist/assets/img/award3a.3b74423.png +0 -0
- package/dist/assets/img/award4a.ed6ccd4.png +0 -0
- package/dist/assets/img/award5.39eb7ae.png +0 -0
- package/dist/assets/img/bubble_default.7d5e4ab.svg +0 -20
- package/dist/assets/img/caret.998eb8f.svg +0 -1
- package/dist/assets/img/convos_empty.2353007.svg +0 -72
- package/dist/assets/img/default.06e6ee0.jpg +0 -0
- package/dist/assets/img/default_avatar.e449b04.png +0 -0
- package/dist/assets/img/default_logo.dd13a2b.svg +0 -5
- package/dist/assets/img/done_gray.d7e8203.svg +0 -4
- package/dist/assets/img/done_green.b817fd4.svg +0 -4
- package/dist/assets/img/emoji/messenger/sub_23.529_58.824.d5faf14.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_23.529_60.784.1420241.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_25.490_0.000.1e6b2c0.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_25.490_45.098.3dfbc08.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_25.490_5.882.4b49e94.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_27.451_72.549.7114f58.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_27.451_84.314.231e2b7.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_27.451_96.078.ddbb008.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_29.412_5.882.61f3359.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_100.000.6df72bc.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_45.098.3d7a7ad.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_47.059.0f4d6e2.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_54.902.65724c1.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_64.706.9da3cba.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_72.549.edca5cf.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_78.431.f910f2a.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_88.235.def4e71.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_11.765.49c03d0.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_27.451.46b54e5.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_29.412.e36d284.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_3.922.bb191b0.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_35.294.af7b927.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_7.843.98f2a99.png +0 -0
- package/dist/assets/img/empty.29bed2d.svg +0 -23
- package/dist/assets/img/empty_1.0b98af0.svg +0 -11
- package/dist/assets/img/examplte_logo.f86535f.svg +0 -1
- package/dist/assets/img/external-link.90577cc.svg +0 -1
- package/dist/assets/img/fb_inverse_circle.36c2cfc.png +0 -0
- package/dist/assets/img/ghn.070f8e3.svg +0 -17
- package/dist/assets/img/ghtk.326eac1.svg +0 -18
- package/dist/assets/img/image_default.be0698b.png +0 -0
- package/dist/assets/img/info.ebce7ea.svg +0 -1
- package/dist/assets/img/loader.37000a7.svg +0 -1
- package/dist/assets/img/loading_static.a27f0ac.svg +0 -10
- package/dist/assets/img/main-service1.d536cc2.png +0 -0
- package/dist/assets/img/main-service2.9b99549.png +0 -0
- package/dist/assets/img/not_found_search.2ddb8d1.png +0 -0
- package/dist/assets/img/package.8d37d0f.svg +0 -5
- package/dist/assets/img/package_fade.763c001.svg +0 -1
- package/dist/assets/img/rating--average.1ea492c.svg +0 -12
- package/dist/assets/img/rating--great.e3d712e.svg +0 -16
- package/dist/assets/img/rating--poor.2938a25.svg +0 -12
- package/dist/assets/img/search.f9705ff.svg +0 -1
- package/dist/assets/img/send.6db52a9.svg +0 -3
- package/dist/assets/img/shop.f7dc7d8.svg +0 -1
- package/dist/assets/img/shop_faded.df7845a.svg +0 -1
- package/dist/assets/img/stars_v2.79cf728.png +0 -0
- package/dist/assets/img/subiz-mono.8fbc067.svg +0 -3
- package/dist/assets/img/x.26fdfa3.svg +0 -5
- package/dist/malicious-app.js +0 -17
- package/dist/screenshoot.html +0 -7
- package/dist/screenshoot.js +0 -13480
package/assets/less/chatbox.less
CHANGED
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
//@mobile-chat-button-background-mask-url : '@mobile_button.background_mask_url'; // @default-chat-button-background-image-url;
|
|
38
38
|
@mobile-chat-button-margin-x: '@mobile_button.margin_x'; // 20px;
|
|
39
39
|
@mobile-chat-button-margin-y: '@mobile_button.margin_y'; //20px;
|
|
40
|
+
@mobile-widget-height: '@mobile_height'; // 100%;
|
|
40
41
|
|
|
41
42
|
@widget-position: '@widget_position';
|
|
42
43
|
|
package/assets/less/widget.less
CHANGED
|
@@ -154,11 +154,11 @@
|
|
|
154
154
|
border-radius: 0px;
|
|
155
155
|
max-height: 100%;
|
|
156
156
|
margin-bottom: 0;
|
|
157
|
-
top:
|
|
157
|
+
top: auto;
|
|
158
158
|
left: 0;
|
|
159
159
|
right: 0;
|
|
160
160
|
width: 100%;
|
|
161
|
-
height:
|
|
161
|
+
height: @mobile-widget-height;
|
|
162
162
|
|
|
163
163
|
opacity: 1;
|
|
164
164
|
transition: opacity 0.15s cubic-bezier(1, 0.5, 0.8, 1);
|
|
@@ -104,6 +104,9 @@ class Block extends _common.Com {
|
|
|
104
104
|
ele.attrs['src'] = _index.default.get(block, 'image.url');
|
|
105
105
|
ele.attrs['alt'] = block.alt_text;
|
|
106
106
|
}
|
|
107
|
+
if (block.type == 'hard_break') {
|
|
108
|
+
ele.tag = 'br';
|
|
109
|
+
}
|
|
107
110
|
let $body = null;
|
|
108
111
|
if (_index.default.size(block.content)) {
|
|
109
112
|
$body = _index.default.map(block.content, block => this.renderBlock(block));
|
|
@@ -177,6 +180,8 @@ class Block extends _common.Com {
|
|
|
177
180
|
return (0, _preact.h)("b", null, $body);
|
|
178
181
|
case 'hr':
|
|
179
182
|
return (0, _preact.h)("hr", null);
|
|
183
|
+
case 'br':
|
|
184
|
+
return (0, _preact.h)("br", null);
|
|
180
185
|
case 'a':
|
|
181
186
|
return (0, _preact.h)("a", {
|
|
182
187
|
class: this.props.textMessage ? 'message-text-link' : '',
|
|
@@ -62,7 +62,7 @@ class Main extends _common.Com {
|
|
|
62
62
|
});
|
|
63
63
|
this.refreshCSS();
|
|
64
64
|
let lastview = this.props.store.matchLastview() || {};
|
|
65
|
-
let cid = _index.default.get(lastview, 'opts.cid');
|
|
65
|
+
let cid = _index.default.get(lastview, 'screen') === 'widget' ? _index.default.get(lastview, 'opts.cid') : '';
|
|
66
66
|
if (cid) {
|
|
67
67
|
this._last_cid = cid;
|
|
68
68
|
this.setState({
|
|
@@ -172,7 +172,7 @@ class Main extends _common.Com {
|
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
174
|
onNewMessageShowWidget(cid) {
|
|
175
|
-
if (this.props.store.isMobile()) modifyViewport();
|
|
175
|
+
if (this.props.store.isMobile()) modifyViewport(this.shouldLockPageScroll());
|
|
176
176
|
this.props.store.updateLastview({
|
|
177
177
|
screen: 'widget',
|
|
178
178
|
previewEvent: {},
|
|
@@ -183,6 +183,9 @@ class Main extends _common.Com {
|
|
|
183
183
|
});
|
|
184
184
|
this.forceUpdate();
|
|
185
185
|
}
|
|
186
|
+
shouldLockPageScroll() {
|
|
187
|
+
return _index.default.get(this.props.plugin, 'chatbox.mobile_height') === undefined;
|
|
188
|
+
}
|
|
186
189
|
async showWidget(p) {
|
|
187
190
|
let cid = p.cid;
|
|
188
191
|
let newView = {
|
|
@@ -203,7 +206,7 @@ class Main extends _common.Com {
|
|
|
203
206
|
cid
|
|
204
207
|
};
|
|
205
208
|
}
|
|
206
|
-
if (this.props.store.isMobile()) modifyViewport();
|
|
209
|
+
if (this.props.store.isMobile()) modifyViewport(this.shouldLockPageScroll());
|
|
207
210
|
this.props.store.updateLastview(newView);
|
|
208
211
|
this.forceUpdate();
|
|
209
212
|
}
|
|
@@ -248,9 +251,11 @@ function restoreViewport() {
|
|
|
248
251
|
let metatag = document.getElementById('subiz-meta-viewport');
|
|
249
252
|
if (metatag) metatag.remove();
|
|
250
253
|
}
|
|
251
|
-
function modifyViewport() {
|
|
252
|
-
if (
|
|
253
|
-
|
|
254
|
+
function modifyViewport(lockPageScroll) {
|
|
255
|
+
if (lockPageScroll) {
|
|
256
|
+
if (document.body && document.body.classList) document.body.classList.add('sbz_no_scroll');
|
|
257
|
+
if (document.documentElement && document.documentElement.classList) document.documentElement.classList.add('sbz_no_scroll');
|
|
258
|
+
}
|
|
254
259
|
let currentMetas = document.querySelectorAll('meta[name="viewport"]');
|
|
255
260
|
let shouldAddMetaTag = true;
|
|
256
261
|
for (let i = 0; i < currentMetas.length; i++) {
|
|
@@ -640,6 +640,7 @@ function replaceCssVariable(css, setting) {
|
|
|
640
640
|
tokens = tokenize(tokens, "'@mobile_button.border_radius'");
|
|
641
641
|
tokens = tokenize(tokens, "'@mobile_button.margin_x'");
|
|
642
642
|
tokens = tokenize(tokens, "'@mobile_button.margin_y'");
|
|
643
|
+
tokens = tokenize(tokens, "'@mobile_height'");
|
|
643
644
|
tokens = tokenize(tokens, "'@widget_position'");
|
|
644
645
|
tokens = tokenize(tokens, "'@z_index'");
|
|
645
646
|
tokens = tokenize(tokens, "'@z_index_2'");
|
|
@@ -763,6 +764,7 @@ const DEFVAL = exports.DEFVAL = {
|
|
|
763
764
|
margin_x: 0.3,
|
|
764
765
|
margin_y: 0.3
|
|
765
766
|
},
|
|
767
|
+
mobile_height: '100%',
|
|
766
768
|
widget_position: 'fixed',
|
|
767
769
|
z_index: 2000000000
|
|
768
770
|
};
|
|
@@ -51,6 +51,14 @@ test('util.randomString', t => {
|
|
|
51
51
|
t.equal(12, util.randomString(12).length);
|
|
52
52
|
t.end();
|
|
53
53
|
});
|
|
54
|
+
test('replaceCssVariable mobile height', t => {
|
|
55
|
+
let css = "height: '@mobile_height';";
|
|
56
|
+
t.equal(util.replaceCssVariable(css, {}), 'height: 100%;', 'defaults to full mobile height');
|
|
57
|
+
t.equal(util.replaceCssVariable(css, {
|
|
58
|
+
mobile_height: '50%'
|
|
59
|
+
}), 'height: 50%;', 'uses configured mobile height');
|
|
60
|
+
t.end();
|
|
61
|
+
});
|
|
54
62
|
test('convert message event first msg send', t => {
|
|
55
63
|
var events = [{
|
|
56
64
|
by: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@subiz/widget-v4",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.208",
|
|
4
4
|
"main": "./compiled_src/lib.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "npx webpack serve --config webpack.dev.js",
|
|
@@ -21,19 +21,19 @@
|
|
|
21
21
|
"preact": "10.19.3"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@babel/cli": "^7.28.
|
|
25
|
-
"@babel/core": "^7.29.
|
|
24
|
+
"@babel/cli": "^7.28.7",
|
|
25
|
+
"@babel/core": "^7.29.7",
|
|
26
26
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
27
|
-
"@babel/plugin-transform-react-jsx": "^7.28.
|
|
28
|
-
"@babel/preset-env": "^7.29.
|
|
27
|
+
"@babel/plugin-transform-react-jsx": "^7.28.7",
|
|
28
|
+
"@babel/preset-env": "^7.29.7",
|
|
29
29
|
"babel-loader": "^10.1.1",
|
|
30
30
|
"babel-plugin-syntax-jsx": "^6.18.0",
|
|
31
31
|
"html-webpack-plugin": "^5.6.8",
|
|
32
32
|
"puppeteer": "^25.9.0",
|
|
33
33
|
"tape": "^5.10.2",
|
|
34
|
-
"webpack": "^5.110.
|
|
34
|
+
"webpack": "^5.110.3",
|
|
35
35
|
"webpack-bundle-analyzer": "^5.3.2",
|
|
36
|
-
"webpack-cli": "^7.2.
|
|
36
|
+
"webpack-cli": "^7.2.3",
|
|
37
37
|
"webpack-dev-server": "^6.0.0"
|
|
38
38
|
}
|
|
39
39
|
}
|
package/src/chatbox/block.js
CHANGED
|
@@ -111,6 +111,9 @@ export default class Block extends Com {
|
|
|
111
111
|
ele.attrs['src'] = sb.get(block, 'image.url')
|
|
112
112
|
ele.attrs['alt'] = block.alt_text
|
|
113
113
|
}
|
|
114
|
+
if (block.type == 'hard_break') {
|
|
115
|
+
ele.tag = 'br'
|
|
116
|
+
}
|
|
114
117
|
|
|
115
118
|
let $body = null
|
|
116
119
|
if (sb.size(block.content)) {
|
|
@@ -185,10 +188,12 @@ export default class Block extends Com {
|
|
|
185
188
|
return <b>{$body}</b>
|
|
186
189
|
case 'hr':
|
|
187
190
|
return <hr />
|
|
191
|
+
case 'br':
|
|
192
|
+
return <br />
|
|
188
193
|
case 'a':
|
|
189
194
|
return (
|
|
190
195
|
<a
|
|
191
|
-
|
|
196
|
+
class={this.props.textMessage ? 'message-text-link' : ''}
|
|
192
197
|
href={ele.attrs['href']}
|
|
193
198
|
target={this.props.textMessage ? '_blank' : ele.attrs['target']}
|
|
194
199
|
title={ele.attrs['title']}
|
package/src/chatbox/main.js
CHANGED
|
@@ -66,7 +66,9 @@ export default class Main extends Com {
|
|
|
66
66
|
this.refreshCSS()
|
|
67
67
|
|
|
68
68
|
let lastview = this.props.store.matchLastview() || {}
|
|
69
|
-
|
|
69
|
+
// Only validate a saved cid when restoring an opened widget.
|
|
70
|
+
// Mobile init may downgrade a saved widget state to preview while keeping stale opts.
|
|
71
|
+
let cid = sb.get(lastview, 'screen') === 'widget' ? sb.get(lastview, 'opts.cid') : ''
|
|
70
72
|
if (cid) {
|
|
71
73
|
this._last_cid = cid
|
|
72
74
|
this.setState({changing: true}, () => {
|
|
@@ -177,11 +179,15 @@ export default class Main extends Com {
|
|
|
177
179
|
}
|
|
178
180
|
|
|
179
181
|
onNewMessageShowWidget(cid) {
|
|
180
|
-
if (this.props.store.isMobile()) modifyViewport()
|
|
182
|
+
if (this.props.store.isMobile()) modifyViewport(this.shouldLockPageScroll())
|
|
181
183
|
this.props.store.updateLastview({screen: 'widget', previewEvent: {}, view: 'chat', opts: {cid}})
|
|
182
184
|
this.forceUpdate()
|
|
183
185
|
}
|
|
184
186
|
|
|
187
|
+
shouldLockPageScroll() {
|
|
188
|
+
return sb.get(this.props.plugin, 'chatbox.mobile_height') === undefined
|
|
189
|
+
}
|
|
190
|
+
|
|
185
191
|
async showWidget(p) {
|
|
186
192
|
//this.refButton.current && this.refButton.current.ClearPreview()
|
|
187
193
|
|
|
@@ -196,7 +202,7 @@ export default class Main extends Com {
|
|
|
196
202
|
newView.opts = {cid}
|
|
197
203
|
}
|
|
198
204
|
|
|
199
|
-
if (this.props.store.isMobile()) modifyViewport()
|
|
205
|
+
if (this.props.store.isMobile()) modifyViewport(this.shouldLockPageScroll())
|
|
200
206
|
this.props.store.updateLastview(newView)
|
|
201
207
|
this.forceUpdate()
|
|
202
208
|
}
|
|
@@ -248,11 +254,13 @@ function restoreViewport() {
|
|
|
248
254
|
if (metatag) metatag.remove()
|
|
249
255
|
}
|
|
250
256
|
|
|
251
|
-
function modifyViewport() {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
document.documentElement.classList
|
|
257
|
+
function modifyViewport(lockPageScroll) {
|
|
258
|
+
if (lockPageScroll) {
|
|
259
|
+
// dont allow to scroll background document
|
|
260
|
+
if (document.body && document.body.classList) document.body.classList.add('sbz_no_scroll')
|
|
261
|
+
if (document.documentElement && document.documentElement.classList)
|
|
262
|
+
document.documentElement.classList.add('sbz_no_scroll')
|
|
263
|
+
}
|
|
256
264
|
|
|
257
265
|
let currentMetas = document.querySelectorAll('meta[name="viewport"]')
|
|
258
266
|
let shouldAddMetaTag = true
|
package/src/util/common.js
CHANGED
|
@@ -682,6 +682,7 @@ export function replaceCssVariable(css, setting) {
|
|
|
682
682
|
//tokens = tokenize(tokens, "'@mobile_button.background_mask_url'")
|
|
683
683
|
tokens = tokenize(tokens, "'@mobile_button.margin_x'")
|
|
684
684
|
tokens = tokenize(tokens, "'@mobile_button.margin_y'")
|
|
685
|
+
tokens = tokenize(tokens, "'@mobile_height'")
|
|
685
686
|
tokens = tokenize(tokens, "'@widget_position'")
|
|
686
687
|
tokens = tokenize(tokens, "'@z_index'")
|
|
687
688
|
tokens = tokenize(tokens, "'@z_index_2'")
|
|
@@ -838,6 +839,7 @@ export const DEFVAL = {
|
|
|
838
839
|
margin_x: 0.3,
|
|
839
840
|
margin_y: 0.3,
|
|
840
841
|
},
|
|
842
|
+
mobile_height: '100%',
|
|
841
843
|
widget_position: 'fixed',
|
|
842
844
|
z_index: 2000000000,
|
|
843
845
|
}
|
package/src/util/common.test.js
CHANGED
|
@@ -56,6 +56,13 @@ test('util.randomString', (t) => {
|
|
|
56
56
|
t.end()
|
|
57
57
|
})
|
|
58
58
|
|
|
59
|
+
test('replaceCssVariable mobile height', (t) => {
|
|
60
|
+
let css = "height: '@mobile_height';"
|
|
61
|
+
t.equal(util.replaceCssVariable(css, {}), 'height: 100%;', 'defaults to full mobile height')
|
|
62
|
+
t.equal(util.replaceCssVariable(css, {mobile_height: '50%'}), 'height: 50%;', 'uses configured mobile height')
|
|
63
|
+
t.end()
|
|
64
|
+
})
|
|
65
|
+
|
|
59
66
|
test('convert message event first msg send', (t) => {
|
|
60
67
|
var events = [
|
|
61
68
|
{by: {id: 1}, type: 'message_sent', created: 1100},
|
package/dist/127.js
DELETED
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
(self["webpackChunk_subiz_widget_v4"] = self["webpackChunk_subiz_widget_v4"] || []).push([[127],{
|
|
3
|
-
|
|
4
|
-
/***/ 6127
|
|
5
|
-
(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
6
|
-
|
|
7
|
-
__webpack_require__.r(__webpack_exports__);
|
|
8
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
9
|
-
/* harmony export */ "default": () => (/* binding */ ProductAttachments)
|
|
10
|
-
/* harmony export */ });
|
|
11
|
-
/* harmony import */ var _util_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8026);
|
|
12
|
-
/* harmony import */ var _common_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2840);
|
|
13
|
-
/* harmony import */ var preact__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(172);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class ProductAttachments extends _common_js__WEBPACK_IMPORTED_MODULE_1__/* .Com */ .Mw {
|
|
18
|
-
render() {
|
|
19
|
-
let byType = _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(this.props.ev, 'by.type');
|
|
20
|
-
if (byType === 'user') return null;
|
|
21
|
-
let acc = this.props.store.matchAccount();
|
|
22
|
-
var attachments = _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(this.props.ev, 'data.message.attachments', []);
|
|
23
|
-
let orders = _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.filter(attachments, att => att.type === 'order' && att.order).map(att => att.order);
|
|
24
|
-
if (orders.length === 0) return null;
|
|
25
|
-
let $orders = _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.map(orders, (order, index) => {
|
|
26
|
-
calcOrderTotal(order);
|
|
27
|
-
let $note = null;
|
|
28
|
-
if (order.note) {
|
|
29
|
-
$note = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
30
|
-
class: "order_attachment__label"
|
|
31
|
-
}, this.props.t('note')), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
32
|
-
class: "order_attachment__note",
|
|
33
|
-
title: order.note
|
|
34
|
-
}, order.note));
|
|
35
|
-
}
|
|
36
|
-
let $products = null;
|
|
37
|
-
if (_util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.size(order.items) > 0) {
|
|
38
|
-
$products = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
39
|
-
class: "order_attachment__label"
|
|
40
|
-
}, this.props.t('product')), _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.map(order.items, item => {
|
|
41
|
-
let product = item.product || {};
|
|
42
|
-
return (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
43
|
-
class: "order_attachment__product"
|
|
44
|
-
}, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("img", {
|
|
45
|
-
class: "order_attachment__product_img",
|
|
46
|
-
alt: '' + _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(product, 'id'),
|
|
47
|
-
src: _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(product, 'image', __webpack_require__(2876))
|
|
48
|
-
}), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
49
|
-
style: "overflow: hidden !important;"
|
|
50
|
-
}, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
51
|
-
class: "order_attachment__product_name",
|
|
52
|
-
title: this.props.t.i18n(product.i18n_name) || product.name
|
|
53
|
-
}, this.props.t.i18n(product.i18n_name) || product.name), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
54
|
-
class: "order_attachment__product_desc"
|
|
55
|
-
}, getProductPropName(product, ' / ')), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
56
|
-
class: "order_attachment__product_desc"
|
|
57
|
-
}, this.props.t('qty'), " ", item.quantity, "\xA0\xB7\xA0", _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(product.price))));
|
|
58
|
-
}));
|
|
59
|
-
}
|
|
60
|
-
let $total = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
61
|
-
class: "order_attachment__footer"
|
|
62
|
-
}, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
63
|
-
class: "d-flex align-items-center justify-content-between"
|
|
64
|
-
}, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, this.props.t('total')), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("b", {
|
|
65
|
-
class: "order_attachment__total"
|
|
66
|
-
}, _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order.total)))));
|
|
67
|
-
let phoneattr = _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.find(_util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(order, 'user.attributes', []), attr => attr.key === 'phones') || {
|
|
68
|
-
key: 'phones',
|
|
69
|
-
text: ''
|
|
70
|
-
};
|
|
71
|
-
let phone = _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(order, 'shipping.address.phone', '').trim();
|
|
72
|
-
phone = phone || _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.trim(phoneattr.text);
|
|
73
|
-
if (phone) phone = this.props.t('phn') + ': ' + phone;
|
|
74
|
-
let $shipto = null;
|
|
75
|
-
if (displayOrderShippingAddress(order) || phone) {
|
|
76
|
-
$shipto = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
77
|
-
class: "order_attachment__label"
|
|
78
|
-
}, this.props.t('ship_to')), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, displayOrderShippingAddress(order)), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
79
|
-
class: "order_attachment__text_truncate"
|
|
80
|
-
}, phone));
|
|
81
|
-
}
|
|
82
|
-
let $beforeTax = null;
|
|
83
|
-
if (order._discount_before_tax) {
|
|
84
|
-
$beforeTax = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
85
|
-
class: "order_attachment__footer"
|
|
86
|
-
}, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
87
|
-
class: "d-flex align-items-center justify-content-between"
|
|
88
|
-
}, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
89
|
-
class: "order_attachment__label no_margin"
|
|
90
|
-
}, this.props.t('subtotal_before_tax')), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order._order_value))), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
91
|
-
class: "d-flex align-items-center justify-content-between"
|
|
92
|
-
}, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
93
|
-
class: "order_attachment__label no_margin"
|
|
94
|
-
}, this.props.t('discount_before_tax')), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, "-", _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order._discount_before_tax))));
|
|
95
|
-
}
|
|
96
|
-
let $subtotal = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
97
|
-
class: "d-flex align-items-center justify-content-between"
|
|
98
|
-
}, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
99
|
-
class: "order_attachment__label no_margin"
|
|
100
|
-
}, this.props.t('subtotal')), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
101
|
-
style: ""
|
|
102
|
-
}, _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order.subtotal)));
|
|
103
|
-
let $tax = null;
|
|
104
|
-
if (order.total_tax) {
|
|
105
|
-
let taxname = '';
|
|
106
|
-
if (_util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.size(order._taxM) === 1) {
|
|
107
|
-
let tax = _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(order._taxM, '0.tax', {});
|
|
108
|
-
if (tax.name && tax.percentage) taxname = `(${tax.name} ${Math.round(tax.percentage || 0) / 100}%)`;
|
|
109
|
-
}
|
|
110
|
-
$tax = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
111
|
-
class: "d-flex align-items-center justify-content-between"
|
|
112
|
-
}, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
113
|
-
class: "order_attachment__label no_margin"
|
|
114
|
-
}, this.props.t('tax'), " ", taxname), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
115
|
-
style: ""
|
|
116
|
-
}, _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order.total_tax)));
|
|
117
|
-
}
|
|
118
|
-
let $discount = null;
|
|
119
|
-
if (order.discount_type === 'percentage' && order.discount_percentage) {
|
|
120
|
-
$discount = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
121
|
-
class: "d-flex align-items-center justify-content-between"
|
|
122
|
-
}, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
123
|
-
class: "order_attachment__label no_margin"
|
|
124
|
-
}, this.props.t('discount_after_tax'), " (", Math.round(order.discount_percentage / 100), "%)"), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
125
|
-
style: ""
|
|
126
|
-
}, "-", _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order._computed_discount)));
|
|
127
|
-
}
|
|
128
|
-
if (order.discount_type === 'amount' && order.discount_amount) {
|
|
129
|
-
$discount = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
130
|
-
class: "d-flex align-items-center justify-content-between"
|
|
131
|
-
}, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
132
|
-
class: "order_attachment__label no_margin"
|
|
133
|
-
}, this.props.t('discount_after_tax')), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
134
|
-
class: "no-shrink"
|
|
135
|
-
}, "-", _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order._computed_discount)));
|
|
136
|
-
}
|
|
137
|
-
let $shipping = null;
|
|
138
|
-
if (_util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(order, 'shipping.nominal_fee')) {
|
|
139
|
-
$shipping = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
140
|
-
class: "d-flex align-items-center justify-content-between"
|
|
141
|
-
}, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
142
|
-
class: "order_attachment__label no_margin"
|
|
143
|
-
}, this.props.t('shipping_fee')), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
144
|
-
style: ""
|
|
145
|
-
}, _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(_util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(order, 'shipping.nominal_fee', 0))));
|
|
146
|
-
}
|
|
147
|
-
let $adjustment = null;
|
|
148
|
-
if (order.adjustment) {
|
|
149
|
-
$adjustment = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
150
|
-
class: "d-flex align-items-center justify-content-between"
|
|
151
|
-
}, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
152
|
-
class: "order_attachment__label no_margin"
|
|
153
|
-
}, order.adjustment_description), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
154
|
-
class: "no-shrink"
|
|
155
|
-
}, _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order.adjustment)));
|
|
156
|
-
}
|
|
157
|
-
$subtotal = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
158
|
-
class: "order_attachment__footer"
|
|
159
|
-
}, $subtotal, $tax, $shipping, $discount, $adjustment);
|
|
160
|
-
if (!$shipping && !$adjustment && !$discount && !$tax) {
|
|
161
|
-
$subtotal = null;
|
|
162
|
-
}
|
|
163
|
-
return (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
164
|
-
class: `order_attachment order_attachment__${byType}`
|
|
165
|
-
}, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
|
|
166
|
-
class: "order_attachment__header"
|
|
167
|
-
}, this.props.t('order'), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("span", {
|
|
168
|
-
class: "order_attachment__text_muted order_attachment__text_sm"
|
|
169
|
-
}, getOrderDisplayName(order))), $products, $shipto, $note, $beforeTax, $subtotal, $total);
|
|
170
|
-
});
|
|
171
|
-
return $orders;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
function getProductPropName(product, seperator = ' - ') {
|
|
175
|
-
let options = op.get(product, 'options', []);
|
|
176
|
-
let props = op.get(product, 'props', []);
|
|
177
|
-
let multiPropsOptions = op.filter(options, option => op.size(option.values) > 1);
|
|
178
|
-
let names = [];
|
|
179
|
-
op.each(multiPropsOptions, option => {
|
|
180
|
-
let prop = op.find(props, prop => prop.key === option.key) || {};
|
|
181
|
-
if (prop.value) names.push(prop.value);
|
|
182
|
-
});
|
|
183
|
-
return names.join(seperator);
|
|
184
|
-
}
|
|
185
|
-
function getOrderDisplayName(order = {}) {
|
|
186
|
-
return order.number || order.id || '';
|
|
187
|
-
}
|
|
188
|
-
function displayOrderShippingAddress(order, isShorten) {
|
|
189
|
-
let addr = op.get(order, 'shipping.address', {});
|
|
190
|
-
let fulladdr = [addr.address, addr.ward, addr.district, addr.province].filter(a => a).join(', ').trim();
|
|
191
|
-
if (isShorten) fulladdr = shortenAddr(fulladdr);
|
|
192
|
-
return fulladdr;
|
|
193
|
-
}
|
|
194
|
-
function shortenAddr(str) {
|
|
195
|
-
str = str || '';
|
|
196
|
-
str = str.replace(/Hà Nội/gi, 'HN');
|
|
197
|
-
str = str.replace(/Hồ Chí Minh/gi, 'HCM');
|
|
198
|
-
str = str.replace(/Thành Phố/gi, 'TP');
|
|
199
|
-
return str;
|
|
200
|
-
}
|
|
201
|
-
function calcOrderTotal(order) {
|
|
202
|
-
let subtotal = 0;
|
|
203
|
-
let beforeTaxDiscount = 0;
|
|
204
|
-
let ordervalue = 0;
|
|
205
|
-
op.map(order.items, item => {
|
|
206
|
-
if (!item.product) return 0;
|
|
207
|
-
let price = op.get(item, 'product.price', 0) * (item.quantity || 0);
|
|
208
|
-
ordervalue += price;
|
|
209
|
-
if (item.discount_type == 'percentage') {
|
|
210
|
-
if (item.discount_percentage > 0) {
|
|
211
|
-
beforeTaxDiscount += price * item.discount_percentage / 10000;
|
|
212
|
-
price = price * (1 - (item.discount_percentage || 0) / 10000);
|
|
213
|
-
}
|
|
214
|
-
} else if (item.discount_type == 'amount') {
|
|
215
|
-
if (item.discount_amount > 0) {
|
|
216
|
-
beforeTaxDiscount += item.discount_amount;
|
|
217
|
-
price = price - (item.discount_amount || 0);
|
|
218
|
-
if (price <= 0) price = 0;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
item.total = price;
|
|
222
|
-
subtotal += price;
|
|
223
|
-
});
|
|
224
|
-
let taxM = {};
|
|
225
|
-
op.map(order.items, (item, i) => {
|
|
226
|
-
if (!item.product) return;
|
|
227
|
-
let tax = item.product.tax;
|
|
228
|
-
if (!tax) return;
|
|
229
|
-
if (!tax.id) return;
|
|
230
|
-
let taxprice = item.total * tax.percentage / 10000;
|
|
231
|
-
item.total_tax = taxprice;
|
|
232
|
-
taxM[i] = {
|
|
233
|
-
tax: tax,
|
|
234
|
-
taxprice: taxprice
|
|
235
|
-
};
|
|
236
|
-
});
|
|
237
|
-
let totaltax = 0;
|
|
238
|
-
op.map(taxM, t => totaltax += t.taxprice);
|
|
239
|
-
let computed_discount = 0;
|
|
240
|
-
if (order.discount_type == 'percentage' && order.discount_percentage > 0) {
|
|
241
|
-
computed_discount = (subtotal + totaltax) * order.discount_percentage / 10000;
|
|
242
|
-
} else if (order.discount_type == 'amount') {
|
|
243
|
-
computed_discount = order.discount_amount || 0;
|
|
244
|
-
}
|
|
245
|
-
let shippingfee = op.get(order, 'shipping.nominal_fee', 0);
|
|
246
|
-
if (shippingfee > 0) {
|
|
247
|
-
if (op.get(order, 'shipping.tax.id')) {
|
|
248
|
-
let tax = order.shipping.tax;
|
|
249
|
-
let taxprice = shippingfee * (tax.percentage / 10000);
|
|
250
|
-
taxM['ship'] = {
|
|
251
|
-
tax: tax,
|
|
252
|
-
taxprice: taxprice
|
|
253
|
-
};
|
|
254
|
-
order.shipping.total_tax = taxprice;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
totaltax = 0;
|
|
258
|
-
op.map(taxM, t => totaltax += t.taxprice);
|
|
259
|
-
let total = subtotal + totaltax - computed_discount + shippingfee;
|
|
260
|
-
total += order.adjustment || 0;
|
|
261
|
-
if (total < 0) total = 0;
|
|
262
|
-
order.subtotal = subtotal;
|
|
263
|
-
order._computed_discount = computed_discount;
|
|
264
|
-
order._taxM = taxM;
|
|
265
|
-
order.total = total;
|
|
266
|
-
order.total_tax = totaltax;
|
|
267
|
-
order._discount_before_tax = beforeTaxDiscount;
|
|
268
|
-
order._order_value = ordervalue;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/***/ }
|
|
272
|
-
|
|
273
|
-
}]);
|