@subiz/widget-v4 4.1.62 → 4.1.65
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/README.md +10 -0
- package/assets/less/widget.less +19 -7
- package/compiled_src/chatbox/Widget.js +57 -28
- package/compiled_src/store/api.js +17 -0
- package/compiled_src/store/api_fake.js +1 -0
- package/compiled_src/store/store.js +5 -30
- package/dist/{792.js → 132.js} +121 -121
- package/dist/18dd22fb422.132.js +1 -0
- package/dist/18dd22fb422.27.js +1 -0
- package/dist/18dd22fb422.278.js +1 -0
- package/dist/{18d7db7ca8c.756.js → 18dd22fb422.459.js} +1 -1
- package/dist/18dd22fb422.490.js +1 -0
- package/dist/18dd22fb422.497.js +1 -0
- package/dist/18dd22fb422.74.js +1 -0
- package/dist/18dd22fb422.997.js +1 -0
- package/dist/18dd22fb422.app.js +1 -0
- package/dist/{18d7db7ca8c.index.html → 18dd22fb422.index.html} +1 -1
- package/dist/{18d7db7ca8c.library.html → 18dd22fb422.library.html} +1 -1
- package/dist/18dd22fb422.library.js +1 -0
- package/dist/{18d7db7ca8c.preview.html → 18dd22fb422.preview.html} +1 -1
- package/dist/18dd22fb422.preview.js +1 -0
- package/dist/18dd22fb422.screenshoot.js +1 -0
- package/dist/18dd22fb422.webview.js +1 -0
- package/dist/{444.js → 27.js} +6 -6
- package/dist/{176.js → 278.js} +54 -54
- package/dist/{756.js → 459.js} +6 -6
- package/dist/{104.js → 490.js} +57 -57
- package/dist/{928.js → 497.js} +676 -676
- package/dist/{508.js → 74.js} +30 -30
- package/dist/{672.js → 997.js} +6 -6
- package/dist/HASH +1 -1
- package/dist/malicious-app.js +4 -8
- package/dist/screenshoot.html +1 -1
- package/dist/screenshoot.js +292 -292
- package/package.json +2 -2
- package/src/chatbox/Widget.js +53 -32
- package/src/store/api.js +17 -0
- package/src/store/api_fake.js +3 -0
- package/src/store/store.js +16 -50
- package/dist/18d7db7ca8c.104.js +0 -1
- package/dist/18d7db7ca8c.176.js +0 -1
- package/dist/18d7db7ca8c.444.js +0 -1
- package/dist/18d7db7ca8c.508.js +0 -1
- package/dist/18d7db7ca8c.672.js +0 -1
- package/dist/18d7db7ca8c.792.js +0 -1
- package/dist/18d7db7ca8c.928.js +0 -1
- package/dist/18d7db7ca8c.app.js +0 -1
- package/dist/18d7db7ca8c.library.js +0 -1
- package/dist/18d7db7ca8c.preview.js +0 -1
- package/dist/18d7db7ca8c.screenshoot.js +0 -1
- package/dist/18d7db7ca8c.webview.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@subiz/widget-v4",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.65",
|
|
4
4
|
"main": "./compiled_src/lib.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "npx webpack serve --config webpack.dev.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"file-loader": "^6.2.0",
|
|
20
20
|
"less": "^4.2.0",
|
|
21
21
|
"less-loader": "^12.2.0",
|
|
22
|
-
"preact": "
|
|
22
|
+
"preact": "10.19.3"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@babel/cli": "^7.23.9",
|
package/src/chatbox/Widget.js
CHANGED
|
@@ -43,12 +43,14 @@ export default class Widget extends Com {
|
|
|
43
43
|
msgInput = createRef()
|
|
44
44
|
componentDidMount() {
|
|
45
45
|
if (!this.props.store.isMobile()) this.focusInput()
|
|
46
|
+
this.updateFormDataFields()
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
componentDidUpdate(prevProp) {
|
|
49
50
|
if (prevProp.isShow !== this.props.isShow) {
|
|
50
51
|
if (this.props.isShow && !this.props.store.isMobile()) this.focusInput()
|
|
51
52
|
if (this.props.isShow && this.props.store.isMobile()) this.blur()
|
|
53
|
+
this.updateFormDataFields()
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
if (prevProp.cid !== this.props.cid) {
|
|
@@ -62,9 +64,9 @@ export default class Widget extends Com {
|
|
|
62
64
|
this.events && this.events.focus()
|
|
63
65
|
if (!this.props.store.isMobile()) this.focusInput()
|
|
64
66
|
}, 100)
|
|
67
|
+
this.updateFormDataFields()
|
|
65
68
|
}
|
|
66
|
-
|
|
67
|
-
this.updateFormDataFields()
|
|
69
|
+
// this.updateFormDataFields()
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
shouldShowForm() {
|
|
@@ -85,6 +87,7 @@ export default class Widget extends Com {
|
|
|
85
87
|
|
|
86
88
|
render() {
|
|
87
89
|
let showform = this.shouldShowForm()
|
|
90
|
+
let formName = ''
|
|
88
91
|
|
|
89
92
|
let form
|
|
90
93
|
// choose form to display
|
|
@@ -97,11 +100,13 @@ export default class Widget extends Com {
|
|
|
97
100
|
if (this.isOffline(acc, accountSetting) && offlineEnabled) {
|
|
98
101
|
form = accountSetting.offline_form
|
|
99
102
|
submitLabel = this.props.t('offline_form_btn')
|
|
103
|
+
formName = 'offline'
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
if (this.props.view === 'offline_form') {
|
|
103
107
|
showform = true
|
|
104
108
|
form = accountSetting.offline_form
|
|
109
|
+
formName = 'offline'
|
|
105
110
|
submitLabel = this.props.t('offline_form_btn')
|
|
106
111
|
}
|
|
107
112
|
|
|
@@ -109,11 +114,12 @@ export default class Widget extends Com {
|
|
|
109
114
|
showform = true
|
|
110
115
|
form = accountSetting.prechat_form
|
|
111
116
|
submitLabel = this.props.t('prechat_form_btn')
|
|
117
|
+
formName = 'prechat'
|
|
112
118
|
}
|
|
113
119
|
|
|
114
120
|
let $body = null
|
|
115
121
|
if (this.props.view === 'list') $body = this.renderConvoList()
|
|
116
|
-
else if (showform) $body = this.renderForm(form, submitLabel)
|
|
122
|
+
else if (showform) $body = this.renderForm(form, submitLabel, formName)
|
|
117
123
|
else $body = this.renderChat()
|
|
118
124
|
|
|
119
125
|
let position = sb.get(accountSetting, 'desktop_button.position') || 'right'
|
|
@@ -138,7 +144,8 @@ export default class Widget extends Com {
|
|
|
138
144
|
)
|
|
139
145
|
}
|
|
140
146
|
|
|
141
|
-
async submitPrechatForm(form) {
|
|
147
|
+
async submitPrechatForm(form, fornName) {
|
|
148
|
+
if (this.state.submiting) return
|
|
142
149
|
// check error first
|
|
143
150
|
var hasError = false
|
|
144
151
|
sb.map(this.state.formData, (field, key) => {
|
|
@@ -183,8 +190,21 @@ export default class Widget extends Com {
|
|
|
183
190
|
let firstmsg = sb.get(data, 'question.value')
|
|
184
191
|
let groupid = sb.get(data, 'group.value', '')
|
|
185
192
|
|
|
193
|
+
// creating convo
|
|
194
|
+
this._creating = (this._creating || 0) + 1
|
|
195
|
+
let _creating = this._creating
|
|
196
|
+
this.setState({creating: true})
|
|
197
|
+
let out = await this.props.store.submitForm(
|
|
198
|
+
'chatbox_' + fornName,
|
|
199
|
+
sb.map(data, (field, key) => {
|
|
200
|
+
return {key: key, type: field.type, value: field.value + ''}
|
|
201
|
+
}),
|
|
202
|
+
user,
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
if (_creating != this._creating) return // outdated
|
|
186
206
|
if (this.props.cid) {
|
|
187
|
-
this.props.store.setUser(user)
|
|
207
|
+
// this.props.store.setUser(user)
|
|
188
208
|
this.setState({clickedJoin: false})
|
|
189
209
|
// form will auto disappear after rerender
|
|
190
210
|
await this.props.store.sendConvoEvent(this.props.cid, 'message_sent', {
|
|
@@ -195,36 +215,38 @@ export default class Widget extends Com {
|
|
|
195
215
|
attachments: this.state.quickReplyMessage.attachments,
|
|
196
216
|
},
|
|
197
217
|
})
|
|
198
|
-
|
|
218
|
+
if (_creating != this._creating) return // outdated
|
|
199
219
|
// reset quickReplyMessage
|
|
200
|
-
this.setState({quickReplyMessage: {}})
|
|
220
|
+
this.setState({creating: false, quickReplyMessage: {}})
|
|
201
221
|
|
|
202
222
|
// end_conversation_after_submit only for offline form or prechat form
|
|
203
223
|
if (form.end_conversation_after_submit) await this.props.store.endConvo(this.props.cid)
|
|
224
|
+
if (_creating != this._creating) return // outdated
|
|
204
225
|
return
|
|
205
226
|
}
|
|
206
227
|
|
|
207
|
-
// creating convo
|
|
208
|
-
this.setState({creating: true})
|
|
209
228
|
let message = {text: firstmsg, format: 'plaintext'}
|
|
210
229
|
let req = {group_id: groupid, message: firstmsg, locale: this.props.t.locale(), initial_by: user.id}
|
|
211
230
|
|
|
212
231
|
this.setState({creatingError: null})
|
|
213
|
-
await this.props.store.setUser(user)
|
|
232
|
+
// await this.props.store.setUser(user)
|
|
214
233
|
const {error, convo} = await this.props.store.startConvo(req)
|
|
234
|
+
|
|
235
|
+
if (_creating != this._creating) return // outdated
|
|
215
236
|
if (error) {
|
|
216
237
|
this.setState({creating: false, creatingError: error})
|
|
217
238
|
return
|
|
218
239
|
}
|
|
219
240
|
let newconvoid = convo.id
|
|
220
241
|
this.userSent[newconvoid] = true
|
|
221
|
-
this.props.
|
|
222
|
-
this.
|
|
242
|
+
await this.props.store.sendConvoEvent(newconvoid, 'message_sent', {message})
|
|
243
|
+
if (_creating != this._creating) return // outdated
|
|
223
244
|
this.setState({
|
|
224
245
|
creating: false,
|
|
225
246
|
clickedJoin: false,
|
|
226
247
|
quickReplyMessage: {},
|
|
227
248
|
})
|
|
249
|
+
this.props.onGo({view: 'chat', cid: newconvoid})
|
|
228
250
|
if (!this.props.store.isMobile()) this.focusInput()
|
|
229
251
|
}
|
|
230
252
|
|
|
@@ -240,7 +262,6 @@ export default class Widget extends Com {
|
|
|
240
262
|
}
|
|
241
263
|
|
|
242
264
|
this.setState({formData})
|
|
243
|
-
|
|
244
265
|
if (!this.props.store.isMobile()) this.focusInput()
|
|
245
266
|
}
|
|
246
267
|
|
|
@@ -401,7 +422,6 @@ export default class Widget extends Com {
|
|
|
401
422
|
|
|
402
423
|
renderFields() {
|
|
403
424
|
if (sb.size(this.state.formData) === 0) return null
|
|
404
|
-
|
|
405
425
|
let $fields = sb.map(this.state.formData, (field, key) => {
|
|
406
426
|
// not display question when click bot quick reply
|
|
407
427
|
if (this.state.quickReplyMessage.text && key === 'question') return null
|
|
@@ -437,6 +457,7 @@ export default class Widget extends Com {
|
|
|
437
457
|
}}
|
|
438
458
|
value={field.value || ''}
|
|
439
459
|
onInput={(e) => this.onInputChange(key, e.target.value)}
|
|
460
|
+
onChange={(e) => this.onInputChange(key, e.target.value)}
|
|
440
461
|
row='4'
|
|
441
462
|
class='form-control'
|
|
442
463
|
></textarea>
|
|
@@ -446,6 +467,7 @@ export default class Widget extends Com {
|
|
|
446
467
|
<input
|
|
447
468
|
value={field.value || ''}
|
|
448
469
|
onInput={(e) => this.onInputChange(key, e.target.value)}
|
|
470
|
+
onChange={(e) => this.onInputChange(key, e.target.value)}
|
|
449
471
|
ref={(ref) => {
|
|
450
472
|
this['form_' + encode(key)] = ref
|
|
451
473
|
}}
|
|
@@ -537,9 +559,8 @@ export default class Widget extends Com {
|
|
|
537
559
|
label = field.label || this.props.t('your_question')
|
|
538
560
|
}
|
|
539
561
|
if (field.label) label = field.label
|
|
540
|
-
|
|
541
562
|
return (
|
|
542
|
-
<div>
|
|
563
|
+
<div key={'form_' + encode(key)}>
|
|
543
564
|
<div class='label'>
|
|
544
565
|
{label}
|
|
545
566
|
{field.is_required ? <span class='ml-1 red'>*</span> : ''}
|
|
@@ -552,15 +573,7 @@ export default class Widget extends Com {
|
|
|
552
573
|
return <div class='pt-2'>{$fields}</div>
|
|
553
574
|
}
|
|
554
575
|
|
|
555
|
-
renderForm(form, submitLabel) {
|
|
556
|
-
let $loading = null
|
|
557
|
-
if (this.state.creating)
|
|
558
|
-
$loading = (
|
|
559
|
-
<span class='ml-2'>
|
|
560
|
-
<Spinner size='16' mode='white' />
|
|
561
|
-
</span>
|
|
562
|
-
)
|
|
563
|
-
|
|
576
|
+
renderForm(form, submitLabel, formName) {
|
|
564
577
|
let title = this.props.t.i18n(sb.get(form, `i18n_title`, {}))
|
|
565
578
|
if (!title) title = sb.get(form, 'title', this.props.t('capture_lead_title'))
|
|
566
579
|
// replace ↵ character
|
|
@@ -581,8 +594,12 @@ export default class Widget extends Com {
|
|
|
581
594
|
</div>
|
|
582
595
|
|
|
583
596
|
<div class='message-input message-input--preform'>
|
|
584
|
-
<button
|
|
585
|
-
|
|
597
|
+
<button
|
|
598
|
+
class='btn--start-convo'
|
|
599
|
+
onClick={(_) => this.submitPrechatForm(form, formName)}
|
|
600
|
+
disabled={this.state.creating}
|
|
601
|
+
>
|
|
602
|
+
{submitLabel}
|
|
586
603
|
</button>
|
|
587
604
|
</div>
|
|
588
605
|
</div>
|
|
@@ -710,23 +727,27 @@ export default class Widget extends Com {
|
|
|
710
727
|
|
|
711
728
|
let text = message.text
|
|
712
729
|
if (!this.props.cid) {
|
|
713
|
-
this.
|
|
730
|
+
this._creating = (this._creating || 0) + 1
|
|
731
|
+
let _creating = this._creating
|
|
732
|
+
this.setState({creating: true})
|
|
714
733
|
const {convo, error} = await this.props.store.startConvo({
|
|
715
734
|
locale: this.props.t.locale(),
|
|
716
735
|
message: text,
|
|
717
736
|
initial_by: this.props.store.matchUser().id,
|
|
718
737
|
})
|
|
738
|
+
if (_creating != this._creating) return // outdated
|
|
719
739
|
if (error) {
|
|
720
740
|
// show error and try again
|
|
721
741
|
}
|
|
722
|
-
this.
|
|
723
|
-
this.
|
|
742
|
+
await this.props.store.sendConvoEvent(convo.id, 'message_sent', {message})
|
|
743
|
+
if (_creating != this._creating) return // outdated
|
|
744
|
+
this.setState({creating: false})
|
|
724
745
|
|
|
725
746
|
this.props.onGo({view: 'chat', cid: convo.id})
|
|
726
|
-
|
|
727
747
|
return
|
|
728
748
|
}
|
|
729
|
-
this.props.store.sendConvoEvent(this.props.cid, 'message_sent', {message})
|
|
749
|
+
await this.props.store.sendConvoEvent(this.props.cid, 'message_sent', {message})
|
|
750
|
+
this.setState({creating: false})
|
|
730
751
|
}
|
|
731
752
|
|
|
732
753
|
createPostback(postback) {
|
package/src/store/api.js
CHANGED
|
@@ -220,6 +220,23 @@ export default class {
|
|
|
220
220
|
getLocaleContent = (locale) => this.apireq.get(`/accounts/${this.accid}/locales/${locale}`)
|
|
221
221
|
sendEvent = (data) =>
|
|
222
222
|
this.apireq.addQuery('shorten', true).post(`/accounts/${this.accid}/users/${this.uid}/events`, data)
|
|
223
|
+
|
|
224
|
+
submitForm = (form_id, page_url, device, data, user) =>
|
|
225
|
+
this.apireq.post(`/accounts/${this.accid}/users/${this.uid}/events`, {
|
|
226
|
+
by: {id: this.uid, device: device},
|
|
227
|
+
type: 'form_submitted',
|
|
228
|
+
data: {
|
|
229
|
+
user: user,
|
|
230
|
+
form_submitted: {
|
|
231
|
+
user_id: this.uid,
|
|
232
|
+
form_id: form_id,
|
|
233
|
+
page_url: page_url,
|
|
234
|
+
submitted_at: sb.Date.now(),
|
|
235
|
+
values: data,
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
})
|
|
239
|
+
|
|
223
240
|
sendTyping = (cid) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/typing`)
|
|
224
241
|
|
|
225
242
|
sendLostFocus = (device, productid, source_id, sku) =>
|
package/src/store/api_fake.js
CHANGED
|
@@ -63,6 +63,9 @@ export default class {
|
|
|
63
63
|
Promise.resolve({body: makeFakeConvo(this.accid, 'csqwudlkftltnbebvq', this.uid, this.agentid), code: 200})
|
|
64
64
|
getLocaleContent = (locale) => this.apireq.get(`/accounts/${this.accid}/locales/${locale}`)
|
|
65
65
|
sendEvent = (data) => OK200
|
|
66
|
+
|
|
67
|
+
submitForm = (form_id, page_url, device, data, user) => OK200
|
|
68
|
+
|
|
66
69
|
sendTyping = (cid) => OK200
|
|
67
70
|
|
|
68
71
|
sendPresence = (data) => OK200
|
package/src/store/store.js
CHANGED
|
@@ -372,16 +372,16 @@ export default class Store {
|
|
|
372
372
|
return
|
|
373
373
|
}
|
|
374
374
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
375
|
+
if (this._track_page_view) {
|
|
376
|
+
this.api.sendContentView(
|
|
377
|
+
this.device,
|
|
378
|
+
location.href,
|
|
379
|
+
document.title,
|
|
380
|
+
this._currentViewingProduct.id,
|
|
381
|
+
this._currentViewingProduct.source_id,
|
|
382
|
+
this._currentViewingProduct.sku,
|
|
383
|
+
)
|
|
384
|
+
}
|
|
385
385
|
},
|
|
386
386
|
1000, // dont send presence update too tight
|
|
387
387
|
{leading: false}, // dont send right after load. should send after content_view
|
|
@@ -572,6 +572,12 @@ export default class Store {
|
|
|
572
572
|
return this.reconnectGate.open()
|
|
573
573
|
}
|
|
574
574
|
|
|
575
|
+
async submitForm(formid, data, user) {
|
|
576
|
+
await this.readyGate.entry()
|
|
577
|
+
if (user) await this.setUser(user)
|
|
578
|
+
return this.api.submitForm(formid, document.URL, this.device, data, user)
|
|
579
|
+
}
|
|
580
|
+
|
|
575
581
|
// set user info, keeping old user id and account id
|
|
576
582
|
async setUser(user) {
|
|
577
583
|
if (!user) return
|
|
@@ -814,7 +820,6 @@ export default class Store {
|
|
|
814
820
|
}
|
|
815
821
|
|
|
816
822
|
convo.last_message_sent = ev
|
|
817
|
-
// this.handleFormSubmit(convoKey, ev)
|
|
818
823
|
}
|
|
819
824
|
|
|
820
825
|
// dont store pong and typing
|
|
@@ -825,45 +830,6 @@ export default class Store {
|
|
|
825
830
|
this.pubsub.publish('account')
|
|
826
831
|
}
|
|
827
832
|
|
|
828
|
-
handleFormSubmit(convoKey, ev) {
|
|
829
|
-
// find form submit
|
|
830
|
-
if (ev.type !== 'message_sent') return
|
|
831
|
-
// has form submit
|
|
832
|
-
let formSubmits = []
|
|
833
|
-
let attachments = sb.get(ev, 'data.message.attachments') || []
|
|
834
|
-
sb.each(attachments, (att) => {
|
|
835
|
-
if (!att) return
|
|
836
|
-
if (att.type !== 'form_submit') return
|
|
837
|
-
formSubmits.push(att.form_submit)
|
|
838
|
-
})
|
|
839
|
-
|
|
840
|
-
sb.each(formSubmits, (submit) => {
|
|
841
|
-
let formev = sb.get(this.convoEventM, convoKey + '.' + submit.form_message_id)
|
|
842
|
-
if (!formev) return
|
|
843
|
-
|
|
844
|
-
// find form attachment
|
|
845
|
-
let forms = sb.filter(sb.get(formev, 'data.message.attachments'), (att) => {
|
|
846
|
-
if (!att) return false
|
|
847
|
-
if (att.type !== 'form' && att.type !== 'ask_info_form') return false
|
|
848
|
-
return true
|
|
849
|
-
})
|
|
850
|
-
|
|
851
|
-
sb.each(forms, (form) => {
|
|
852
|
-
form = form.form
|
|
853
|
-
sb.each(form.fields, (formfield) => {
|
|
854
|
-
sb.each(submit.fields, (submitfield) => {
|
|
855
|
-
if (formfield.name !== submitfield.name) return
|
|
856
|
-
if (formfield.default_answer) return
|
|
857
|
-
|
|
858
|
-
formfield.default_answer = submitfield.value
|
|
859
|
-
})
|
|
860
|
-
})
|
|
861
|
-
})
|
|
862
|
-
|
|
863
|
-
if (sb.size(forms) > 0) this.pubsub.publish('state.convoEventM', this.convoEventM, convoKey)
|
|
864
|
-
})
|
|
865
|
-
}
|
|
866
|
-
|
|
867
833
|
typing(cid) {
|
|
868
834
|
if (!cid) return
|
|
869
835
|
this._typing(cid)
|
package/dist/18d7db7ca8c.104.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";(self.webpackChunk_subiz_widget_v4=self.webpackChunk_subiz_widget_v4||[]).push([[104],{3104:(t,e,s)=>{s.r(e),s.d(e,{default:()=>l});var i=s(5780),o=s(4284),n=s(6304);let a=s.e(756).then(s.bind(s,3756));class l extends n.Sq{constructor(t){var e,s,o,n;super(t),e=this,o={close:!0,cssready:!1,closeAnimation:!0,imageReady:!1,user:{},timestamp:"",message:"",title:"",last_show:0},(s="symbol"==typeof(n=function(t,e){if("object"!=typeof t||!t)return t;var s=t[Symbol.toPrimitive];if(void 0!==s){var i=s.call(t,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(s="state"))?n:String(n))in e?Object.defineProperty(e,s,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[s]=o,i.c.setTimeout((async()=>{let{body:t}=await this.props.store.sendImpression(this.props.plugin.id);this.impressionToken=i.c.get(t,"impression_token")||"";let e=i.c.get(this.props,"plugin.notification.background_url");i.c.preloadImg(e,(()=>this.setState({imageReady:!0})))}))}setOver(t){this.mouse_leave=t?0:i.c.Date.now()}randomTimestampt(){let t=Math.floor(5*Math.random());return 0==t?this.props.t("just_now"):1==t?"1 "+this.props.t("minute_ago"):2==t?"2 "+this.props.t("minutes_ago"):3==t?"3 "+this.props.t("minutes_ago"):"4 "+this.props.t("minutes_ago")}onClick(t){if(this.props.plugin._dont_follow)return;this.props.store.sendConversion(this.props.plugin.id,null,this.impressionToken);let e=i.c.get(this.props,"plugin.notification.url");return e?(e.startsWith("http://")||e.startsWith("https://")||(e="//"+e),i.c.get(this.props,"plugin.notification.new_tab",!1)?window.open(e):void(window.location.href=e)):void 0}onCloseButtonClick(t){t.preventDefault(),t.stopPropagation(),this.setClose(!0)}renderCloseButton(){return(0,o.h)("div",{class:"btn_close",onClick:t=>this.onCloseButtonClick(t)},(0,o.h)("svg",{class:"btn_close__icon",xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24","stroke-linecap":"round","stroke-linejoin":"round"},(0,o.h)("line",{x1:"18",y1:"6",x2:"6",y2:"18",style:"stroke-width: 3 !important;"}),(0,o.h)("line",{x1:"6",y1:"6",x2:"18",y2:"18",style:"stroke-width: 3 !important;"})))}async waitForT(){if(!this.props.t)return await i.c.sleep(100),this.waitForT()}async setClose(t){if(await this.waitForT(),this.props.t){if(!t){i.c.clearTimeout(this.lastCloseTimeout),this.setState({closeAnimation:!1});let t=this.randomTimestampt(),e=i.c.get(this.props,"plugin.notification.profiles",[]),s=e[Math.floor(Math.random()*i.c.size(e))]||{};s.avatar_url&&s.avatar_url.startsWith("http")&&await i.c.preloadImg(s.avatar_url),i.c.map(i.c.get(this.props.plugin,"notification.custom_avatar_urls"),(t=>{e.push({type:"person",fullname:r(),avatar_url:t,email:r().split(" ").join(".").toLowerCase()+"@gmail.com",address:h(),phone:"+84"+Math.floor(10*Math.random())+Math.floor(10*Math.random())+Math.floor(10*Math.random())+Math.floor(10*Math.random())+Math.floor(10*Math.random())+Math.floor(10*Math.random())+"xxxx",age:15+Math.floor(20*Math.random())})}));let o=i.c.get(this.props,"plugin.notification.i18n_message_quill_deltas",[]),n=o[Math.floor(Math.random()*i.c.size(o))],a=i.c.get(this.props,"plugin.notification.message_quill_deltas",[]),l=a[Math.floor(Math.random()*i.c.size(a))],p=i.c.get(this.props,"plugin.notification.i18n_title_quill_delta");return this.setState({close:!1,last_show:i.c.Date.now(),timestamp:t,user:s,title:this.props.t.i18n(p)||i.c.get(this.props,"plugin.notification.title_quill_delta"),message:this.props.t.i18n(n)||l})}this.setState({closeAnimation:!0}),this.mouse_leave=i.c.Date.now(),this.lastCloseTimeout=i.c.setTimeout((()=>this.setState({close:!0,closeAnimation:!1})),150),this.props.plugin._dont_close&&i.c.setTimeout((()=>this.setState({closeAnimation:!1,close:!1})),1e3)}}async refreshCSS(){let t=this.props.store.matchPlugin();if(!i.c.find(t,(t=>t.id===this.props.plugin.id)))return;let e=(await a).default.default.toString();i.c.setCss(this.props.plugin.id,this.$cssStyleDiv,e),this.setClose(this.state.close)}componentWillUnmount(){i.c.clearInterval(this.interval),i.c.setCss(this.props.plugin.id,this.$cssStyleDiv,"")}async componentDidMount(){this.setState({last_show:i.c.Date.now()}),this.$cssStyleDiv=document.getElementById("subiz-style-for-"+this.props.plugin.id),this.$cssStyleDiv||(this.$cssStyleDiv=document.createElement("style"),document.head.appendChild(this.$cssStyleDiv),this.$cssStyleDiv.type="text/css",this.$cssStyleDiv.id="subiz-style-for-"+this.props.plugin.id),this.props.store.onResetCSS(this,(()=>this.refreshCSS())),await this.refreshCSS(),this.interval=i.c.setInterval((()=>{if(this.props._destroy)return this.componentWillUnmount();let t=this.mouse_leave;return 0===t&&(t=i.c.Date.now()),i.c.Date.now()-t<1e3?void 0:this.state.close||this.props.plugin._dont_close?i.c.Date.now()-this.state.last_show>this.props.plugin.notification.interval_sec?this.setClose(!1):void 0:i.c.Date.now()-this.state.last_show>8e3?this.setClose(!0):void 0}),1e3),i.c.setTimeout((()=>{this.setState({cssready:!0}),this.setClose(!1)}),50)}renderTextFromQuillDelta(t,e){let s=i.c.parseJSON(t);if(!s||!s.ops)return null;let n=i.c.map(s.ops,(t=>{let s=null;if(!t.insert)return null;if("string"==typeof t.insert&&(s=t.insert),i.c.get(t,"insert.dynamicField")){let o=i.c.get(t,"insert.dynamicField.key");"user.fullname"===o&&(s=e.fullname),"user.email"===o&&(s=e.email),"user.address"===o&&(s=e.address),"user.phone"===o&&(s=e.phone)}return i.c.get(t,"attributes.bold")&&(s=(0,o.h)("b",null,s)),i.c.get(t,"attributes.italic")&&(s=(0,o.h)("b",null,s)),s})).filter((t=>t));return 1!=n.length||"\n"!=n[0]&&""!=n[0]?n:[]}render(){if(!this.props.t)return null;if(!this.state.cssready)return null;if(!this.state.imageReady)return null;if(this.state.close)return null;if(!this.state.message)return null;let t=i.c.get(this.props.plugin,"notification",{});if(!t)return null;let e="",s=i.c.get(t,"position","bottom-left");this.props.mobile&&(s=i.c.get(t,"mobile_position",s)),"top-left"===s||"top-right"===s?e="fadeInDown":"top-center"===s?e="fadeInDownCenter":"bottom-center"===s?e="fadeInUpCenter":("bottom-right"===s||(s="bottom-left"),e="fadeInUpBig");let n=this.state.user||{},a=t.subtext_style||{};void 0===a.color&&(a.color=i.c.get(t,"message_style.color","black"));let l="position: fixed !important; z-index: 1000000000 !important";this.props.plugin._preview&&(l="position: absolute !important;"),this.state.closeAnimation&&(e="fadeOut");let r=null;n.avatar_url&&(r=(0,o.h)("img",{alt:"notification avatar",class:"notif_avatar__img",src:n.avatar_url}));let h=(0,o.h)("div",{class:"notif_time",style:i.c.js2css(t.subtext_style)},this.state.timestamp),p=this.renderTextFromQuillDelta(this.state.title,n),c=this.renderTextFromQuillDelta(this.state.message,n);return i.c.size(p)||i.c.size(c)||(h=null),(0,o.h)("div",{class:e+" notif notif__"+s,onClick:t=>this.onClick(t),onmouseover:t=>this.setOver(!0),style:l,onmouseleave:t=>this.setOver(!1)},(0,o.h)("div",{style:"position: relative !important; display: flex !important; align-items: center !important;"},(0,o.h)("img",{alt:"notification background",class:"notif_bg",src:t.background_url,style:i.c.js2css(t.background_style)}),this.renderCloseButton(),(0,o.h)("div",{class:"notif_avatar",style:i.c.js2css(t.avatar_style)},r),(0,o.h)("div",{class:"notif_body"},(0,o.h)("div",{class:"notif_title",style:i.c.js2css(t.title_style)},p),(0,o.h)("div",{class:"notif_message",style:i.c.js2css(t.message_style)},c),h)))}}function r(){let t=["Kiều Thanh","Phương Anh","Lê Thùy Linh","Trang Nguyễn","Thanh Hoa","Hoài Đức","Huơng Giang"];return t[Math.floor(Math.random()*t.length)]}function h(){let t=["Dịch Vọng Hậu, Cầu Giấy","Quận 1, TP Hồ Chí Minh","Ngõ 34 Tôn Thất Thuyết","87 Phạm Hùng","Đống Đa, Hà Nội"];return t[Math.floor(Math.random()*t.length)]}}}]);
|