@subiz/widget-v4 4.0.81 → 4.0.85

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 (73) hide show
  1. package/compiled_src/chatbox/ShadowDomRoot.js +1 -2
  2. package/compiled_src/chatbox/TextMessage.js +66 -3
  3. package/compiled_src/chatbox/Typing.js +1 -1
  4. package/compiled_src/chatbox/Widget.js +9 -1
  5. package/compiled_src/popup/popup.js +7 -0
  6. package/compiled_src/store/store.js +1 -1
  7. package/dist/132.js +152 -36
  8. package/dist/178.js +174 -341
  9. package/dist/181a9b734bb.132.js +1 -0
  10. package/dist/181a9b734bb.178.js +1 -0
  11. package/dist/{17f00e48d38.213.js → 181a9b734bb.213.js} +1 -1
  12. package/dist/{17f00e48d38.335.js → 181a9b734bb.335.js} +1 -1
  13. package/dist/181a9b734bb.362.js +1 -0
  14. package/dist/181a9b734bb.441.js +1 -0
  15. package/dist/{17f00e48d38.605.js → 181a9b734bb.605.js} +0 -0
  16. package/dist/181a9b734bb.678.js +1 -0
  17. package/dist/181a9b734bb.782.js +1 -0
  18. package/dist/181a9b734bb.app.js +1 -0
  19. package/dist/{17f00e48d38.index.html → 181a9b734bb.index.html} +7 -3
  20. package/dist/{17f00e48d38.library.html → 181a9b734bb.library.html} +7 -3
  21. package/dist/181a9b734bb.library.js +1 -0
  22. package/dist/{17f00e48d38.preview.html → 181a9b734bb.preview.html} +1 -1
  23. package/dist/181a9b734bb.preview.js +1 -0
  24. package/dist/181a9b734bb.screenshoot.js +1 -0
  25. package/dist/213.js +10 -0
  26. package/dist/335.js +2 -2
  27. package/dist/362.js +21 -71
  28. package/dist/441.js +138 -56
  29. package/dist/678.js +20 -70
  30. package/dist/782.js +21 -118
  31. package/dist/HASH +1 -1
  32. package/dist/screenshoot.html +1 -1
  33. package/dist/screenshoot.js +185 -131
  34. package/package.json +14 -14
  35. package/src/chatbox/ShadowDomRoot.js +1 -2
  36. package/src/chatbox/TextMessage.js +70 -2
  37. package/src/chatbox/Typing.js +10 -11
  38. package/src/chatbox/Widget.js +7 -2
  39. package/src/popup/popup.js +23 -11
  40. package/src/store/store.js +1 -1
  41. package/dist/0b82fa7e5c3b07b40a44.png +0 -1
  42. package/dist/0f4af006e38ee8b93633.png +0 -1
  43. package/dist/17f00e48d38.132.js +0 -1
  44. package/dist/17f00e48d38.178.js +0 -1
  45. package/dist/17f00e48d38.362.js +0 -1
  46. package/dist/17f00e48d38.441.js +0 -1
  47. package/dist/17f00e48d38.678.js +0 -1
  48. package/dist/17f00e48d38.782.js +0 -1
  49. package/dist/17f00e48d38.app.js +0 -1
  50. package/dist/17f00e48d38.library.js +0 -1
  51. package/dist/17f00e48d38.preview.js +0 -1
  52. package/dist/17f00e48d38.screenshoot.js +0 -1
  53. package/dist/1ea1c6cd21d25176810c.png +0 -1
  54. package/dist/292d42404e1b03398f61.png +0 -1
  55. package/dist/312d376370831b7bea83.png +0 -1
  56. package/dist/313d1bfc1cf776d1aefe.png +0 -1
  57. package/dist/4aa58bb7a66bb44975aa.png +0 -1
  58. package/dist/56ce063bc6c81adb7322.png +0 -1
  59. package/dist/6a411166ef5cc79e0714.png +0 -1
  60. package/dist/6faf403782fefacc1649.png +0 -1
  61. package/dist/79dca33c68fab79c067f.png +0 -1
  62. package/dist/82da1578fa84f9debaeb.png +0 -1
  63. package/dist/8b8e0f0824743974b282.png +0 -1
  64. package/dist/8d551390d81e39130a3c.png +0 -1
  65. package/dist/9fc61b9479877ebdb6c7.png +0 -1
  66. package/dist/a165d31dcb3dc90f1057.png +0 -1
  67. package/dist/a98d4a5698812c4426b3.png +0 -1
  68. package/dist/c41606bf9d1b604e46d5.png +0 -1
  69. package/dist/ce1f7450ce6c1aacd330.png +0 -1
  70. package/dist/cf8c01e88f4770a6e3e5.png +0 -1
  71. package/dist/dfbcfeab1d5622a737e2.png +0 -1
  72. package/dist/e4893ed8c2f7b8329919.png +0 -1
  73. package/dist/ec2ab4eb4ef73d186186.png +0 -1
@@ -21,8 +21,7 @@ img { max-width: 100%; display: block; margin: 10px auto; }
21
21
  * { white-space: normal }
22
22
  ul > li { margin-bottom: 5px }
23
23
  ul:last-child { margin-bottom: 0 }
24
- p:first-child { margin-top: 0;}
25
- p:last-child { margin-bottom: 0;}
24
+ p { margin-bottom: 0; margin-top: 0;}
26
25
  </style>
27
26
  <div>${html}</div>`
28
27
  let links = this.shadowRoot.querySelectorAll('a')
@@ -22,7 +22,11 @@ export default class TextMessage extends Com {
22
22
  render() {
23
23
  var format = sb.get(this.props.ev, 'data.message.format', 'plaintext')
24
24
  if (format === 'markdown') return this.renderMarkdown()
25
+ if (format === 'delta') return this.renderDelta()
26
+ return this.renderPlainText()
27
+ }
25
28
 
29
+ renderPlainText() {
26
30
  var text = sb.get(this.props.ev, 'data.message.text')
27
31
  text = sb.trim(text)
28
32
  if (sb.size(text) === 0) return null
@@ -60,8 +64,27 @@ export default class TextMessage extends Com {
60
64
  return <div class='message-user message-text--user'>{tags}</div>
61
65
  }
62
66
 
63
- renderMarkdown() {
64
- var text = sb.get(this.props.ev, 'data.message.text')
67
+ renderDelta() {
68
+ let deltas = sb.get(this.props.ev, 'data.message.quill_delta')
69
+ deltas = sb.parseJSON(deltas) || {}
70
+ deltas = deltas.ops || []
71
+ let isMarkdown = sb.find(
72
+ deltas,
73
+ (delta) =>
74
+ sb.get(delta, 'attributes.bold') ||
75
+ sb.get(delta, 'attributes.italic') ||
76
+ sb.get(delta, 'attributes.underline') ||
77
+ sb.get(delta, 'insert.emoji'),
78
+ )
79
+ if (isMarkdown) {
80
+ var text = deltaToMarkdown(deltas)
81
+ return this.renderMarkdown(text)
82
+ }
83
+ return this.renderPlainText()
84
+ }
85
+
86
+ renderMarkdown(text) {
87
+ if (!text) text = sb.get(this.props.ev, 'data.message.text')
65
88
  if (sb.size(text) === 0) return null
66
89
 
67
90
  let byType = sb.get(this.props.ev, 'by.type')
@@ -86,3 +109,48 @@ export default class TextMessage extends Com {
86
109
  )
87
110
  }
88
111
  }
112
+
113
+ function deltaToMarkdown(deltas) {
114
+ let output = ''
115
+ sb.each(deltas, (delta, idx) => {
116
+ let text = ''
117
+ let insert = delta.insert
118
+ let attributes = delta.attributes
119
+ // emoji
120
+ if (insert.emoji) text = emojiCodes[insert.emoji] || ''
121
+ // insert bold, italic, underline
122
+ if (attributes) {
123
+ if (attributes.italic && attributes.bold) text = `*__${insert}__*`
124
+ else if (attributes.italic) text = `*${insert}*`
125
+ else if (attributes.bold) text = `**${insert}**`
126
+ else text = insert
127
+ }
128
+ if (insert.dynamicField) text = `${sb.get(insert, 'dynamicField.text', '')}`
129
+ if (!insert.emoji && !attributes && !insert.dynamicField) {
130
+ text = insert || ''
131
+ // markdown need newline to <br/> characters to newline
132
+ text = text.replace(/\n/g, '<br/>')
133
+ }
134
+
135
+ output += text
136
+ })
137
+ return output
138
+ }
139
+
140
+ const emojiCodes = {
141
+ like: '👍',
142
+ unlike: '👎',
143
+ angry: '😠',
144
+ confused: '😕',
145
+ crying: '😢',
146
+ grinning: '😀',
147
+ 'heart-eyes': '😍',
148
+ neutral: '😐',
149
+ sleepy: '😪',
150
+ sad: '😞',
151
+ smiling: '😄',
152
+ 'tongue-out': '😛',
153
+ tired: '😩',
154
+ surprised: '😮',
155
+ wink: '😉',
156
+ }
@@ -1,24 +1,23 @@
1
1
  import sb from '../util/index.js'
2
- import { Com } from '../common.js'
3
- import { h } from 'preact'
2
+ import {Com} from '../common.js'
3
+ import {h} from 'preact'
4
4
 
5
5
  export default class Typing extends Com {
6
- constructor (props) {
6
+ constructor(props) {
7
7
  super(props)
8
8
  }
9
9
 
10
- componentDidMount () {
10
+ componentDidMount() {
11
11
  this.setState({
12
12
  isShow: false,
13
13
  ev: {},
14
14
  })
15
15
 
16
- this.props.store.onConvoEvent(this, ev => {
16
+ this.props.store.onConvoEvent(this, (ev) => {
17
17
  if (sb.convoOfEv(ev) !== this.props.cid) return
18
18
  let user = this.props.store.matchUser()
19
19
  if (sb.get(ev, 'by.id') === user.id) return
20
20
 
21
-
22
21
  let oldby = sb.get(this.state.ev, 'by.id')
23
22
  if (oldby && sb.get(ev, 'by.id') !== oldby) return
24
23
 
@@ -26,27 +25,27 @@ export default class Typing extends Com {
26
25
  // stop the typing
27
26
  if (this.timer) clearTimeout(this.timer)
28
27
  this.timer = null
29
- this.setState({ isShow: false })
28
+ this.setState({isShow: false})
30
29
  return
31
30
  }
32
31
 
33
32
  // dont show typing of agent, some agent dont like this
34
- let ag = this.props.store.matchAgent(ev.by.id)
33
+ let ag = this.props.store.matchAgent(ev.by.id) || {}
35
34
  if (ag.type == 'agent') return
36
35
 
37
36
  if (sb.get(ev, 'type') !== 'conversation_typing') return
38
- this.setState({ ev: ev, isShow: true })
37
+ this.setState({ev: ev, isShow: true})
39
38
  if (this.timer) clearTimeout(this.timer)
40
39
  this.timer = setTimeout(() => {
41
40
  if (sb.convoOfEv(ev) !== this.props.cid) return
42
41
 
43
42
  this.timer = null
44
- this.setState({ isShow: false })
43
+ this.setState({isShow: false})
45
44
  }, 5000)
46
45
  })
47
46
  }
48
47
 
49
- render () {
48
+ render() {
50
49
  let account = this.props.store.matchAccount()
51
50
  var cls = this.state.isShow ? '' : 'typing--hidden'
52
51
  let byid = sb.get(this.state.ev, 'by.display_id', sb.get(this.state.ev, 'by.id'))
@@ -148,9 +148,11 @@ export default class Widget extends Com {
148
148
  let data = sb.cloneDeep(this.state.formData)
149
149
  // update user info based on form data
150
150
  let user = sb.cloneDeep(this.props.store.matchUser())
151
+ let is_lead = false
151
152
  sb.map(data, (field, key) => {
152
153
  if (!key.startsWith('attr:')) return
153
154
  var attr = {key: key.substr(5)}
155
+ is_lead = is_lead || key == 'emails' || key == 'phones'
154
156
  if (field.type === 'number') attr.number = parseInt(field.value)
155
157
  if (field.type === 'datetime') attr.datetime = new sb.Date(field.value).toISOString()
156
158
  if (field.type === 'list') attr.list = field.value
@@ -158,6 +160,8 @@ export default class Widget extends Com {
158
160
  sb.setUserAttr(user, attr)
159
161
  })
160
162
 
163
+ if (is_lead) sb.setUserAttr(user, {key: 'lead_source', text: 'widget'})
164
+
161
165
  let firstmsg = sb.get(data, 'question.value')
162
166
  let groupid = sb.get(data, 'group.value', '')
163
167
 
@@ -184,8 +188,8 @@ export default class Widget extends Com {
184
188
  let req = {group_id: groupid, message: firstmsg, locale: this.props.t.locale(), initial_by: user.id}
185
189
 
186
190
  this.setState({creatingError: null})
191
+ await this.props.store.setUser(user)
187
192
  const {error, convo} = await this.props.store.startConvo(req)
188
- this.props.store.setUser(user)
189
193
  if (error) {
190
194
  this.setState({creating: false, creatingError: error})
191
195
  return
@@ -269,7 +273,8 @@ export default class Widget extends Com {
269
273
  value={field.value || ''}
270
274
  onInput={(e) => this.onInputChange(key, e.target.value)}
271
275
  row='4'
272
- class='form-control'></textarea>
276
+ class='form-control'
277
+ ></textarea>
273
278
  )
274
279
  } else {
275
280
  $field = (
@@ -156,7 +156,8 @@ export default class Popup extends Com {
156
156
  height='24'
157
157
  viewBox='0 0 24 24'
158
158
  stroke-linecap='round'
159
- stroke-linejoin='round'>
159
+ stroke-linejoin='round'
160
+ >
160
161
  <line x1='17' y1='7' x2='7' y2='17' style='stroke-width: 3 !important;'></line>
161
162
  <line x1='7' y1='7' x2='17' y2='17' style='stroke-width: 3 !important;'></line>
162
163
  </svg>
@@ -213,6 +214,7 @@ export default class Popup extends Com {
213
214
  var summitFields = []
214
215
 
215
216
  let user = sb.cloneDeep(this.props.store.matchUser())
217
+ let is_lead = false
216
218
  for (var pair of formData.entries()) {
217
219
  let page = sb.get(this.props.plugin.popup, `pages.${this.getPageIndex()}`)
218
220
  let form = sb.find(page.components, (com) => com.type === 'form')
@@ -226,10 +228,12 @@ export default class Popup extends Com {
226
228
  let key = pair[0]
227
229
  if (key === 'email') key = 'emails'
228
230
  if (key === 'phone') key = 'phones'
229
-
231
+ is_lead = is_lead || key == 'emails' || key == 'phones'
230
232
  sb.setUserAttr(user, {key: key, text: pair[1]})
231
233
  }
234
+ if (is_lead) sb.setUserAttr(user, {key: 'lead_source', text: 'plugin.' + this.props.plugin.id})
232
235
  this.props.store.sendConversion(this.props.plugin.id, summitFields, this.impressionToken)
236
+
233
237
  this.props.store.setUser(user)
234
238
  }
235
239
 
@@ -277,7 +281,8 @@ export default class Popup extends Com {
277
281
  <div
278
282
  class={'btn btn__primary '}
279
283
  style={this.js2css(primarystyle)}
280
- onClick={(e) => this.onButtonClick(e, 'primary')}>
284
+ onClick={(e) => this.onButtonClick(e, 'primary')}
285
+ >
281
286
  {this.props.t.i18n(com.buttons.i18n_primary_text) || com.buttons.primary_text}
282
287
  </div>
283
288
  )
@@ -290,7 +295,8 @@ export default class Popup extends Com {
290
295
  <div
291
296
  class={'btn btn__secondary'}
292
297
  style={this.js2css(style)}
293
- onClick={(e) => this.onButtonClick(e, 'secondary')}>
298
+ onClick={(e) => this.onButtonClick(e, 'secondary')}
299
+ >
294
300
  {this.props.t.i18n(com.buttons.i18n_secondary_text) || com.buttons.secondary_text}
295
301
  </div>
296
302
  )
@@ -303,7 +309,8 @@ export default class Popup extends Com {
303
309
  display: 'flex',
304
310
  flex_direction: buttonsstyle.flex_direction,
305
311
  align_items: buttonsstyle.align_items,
306
- })}>
312
+ })}
313
+ >
307
314
  {$primary}
308
315
  <div style={this.js2css({width: '10px', height: '1px'})} />
309
316
  {$secondary}
@@ -503,7 +510,8 @@ export default class Popup extends Com {
503
510
  color: popup.text_color,
504
511
  font_family: popup.font_family,
505
512
  font_size: popup.font_size || '14px',
506
- })}>
513
+ })}
514
+ >
507
515
  {this.props.t.i18n(field.i18n_label) || field.label}
508
516
  </div>
509
517
  )
@@ -517,7 +525,8 @@ export default class Popup extends Com {
517
525
  $error = (
518
526
  <div
519
527
  class='text__danger '
520
- style={this.js2css({margin_top: '5px', font_family: popup.font_family, font_size: popup.font_size})}>
528
+ style={this.js2css({margin_top: '5px', font_family: popup.font_family, font_size: popup.font_size})}
529
+ >
521
530
  {this.props.t('invalid_field')}
522
531
  </div>
523
532
  )
@@ -527,7 +536,8 @@ export default class Popup extends Com {
527
536
  $error = (
528
537
  <div
529
538
  class='text__danger '
530
- style={this.js2css({margin_top: '5px', font_family: popup.font_family, font_size: popup.font_size})}>
539
+ style={this.js2css({margin_top: '5px', font_family: popup.font_family, font_size: popup.font_size})}
540
+ >
531
541
  {this.props.t('required')}
532
542
  </div>
533
543
  )
@@ -547,7 +557,8 @@ export default class Popup extends Com {
547
557
  style={this.js2css(com.style)}
548
558
  class='form popup_component'
549
559
  ref={this._formRef}
550
- onClick={(e) => e.stopPropagation()}>
560
+ onClick={(e) => e.stopPropagation()}
561
+ >
551
562
  {$fields}
552
563
  </form>
553
564
  )
@@ -600,7 +611,8 @@ export default class Popup extends Com {
600
611
  <span
601
612
  style={this.js2css(
602
613
  Object.assign({white_space: 'nowrap', overflow: 'hidden', text_overflow: 'ellipsis'}, textstyle),
603
- )}>
614
+ )}
615
+ >
604
616
  {this.props.t('follow_us_on_facebook')}
605
617
  </span>
606
618
  </div>
@@ -919,7 +931,7 @@ export default class Popup extends Com {
919
931
  if (com.type === 'image') return this.renderImageComponent(com, i)
920
932
  })
921
933
 
922
- // fix bug image only popup has white block
934
+ // fix bug image only popup has white block
923
935
  let formComponents = sb.filter(page.components, (com) => com.type !== 'image')
924
936
  if (!formComponents.length) {
925
937
  formcss.background = 'transparent'
@@ -704,7 +704,7 @@ export default class Store {
704
704
  sb.map(pongs, (pong) => {
705
705
  if (pong.member_id == user.id && pong.type === 'seen') {
706
706
  let mem = sb.find(convo.members, (mem) => mem.id === user.id)
707
- mem.seen_at = pong.created
707
+ if (mem) mem.seen_at = pong.created
708
708
  }
709
709
  })
710
710
  this.chain.put(cid, oldev.id, sb.getMs(oldev.created), oldev)
@@ -1 +0,0 @@
1
- module.exports = __webpack_public_path__ + "assets/img/emoji/messenger/sub_58.824_78.431.f910f2a.png";
@@ -1 +0,0 @@
1
- module.exports = __webpack_public_path__ + "assets/img/emoji/messenger/sub_60.784_29.412.e36d284.png";