@subiz/widget-v4 4.1.83 → 4.1.84
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/compiled_src/chatbox/ChatButton.js +7 -29
- package/compiled_src/chatbox/TextMessage.js +17 -96
- package/compiled_src/chatbox/block.js +152 -0
- package/compiled_src/notif/notif.js +35 -35
- package/compiled_src/util/common.js +174 -1
- package/compiled_src/util/index.js +0 -2
- package/package.json +1 -1
- package/src/chatbox/ChatButton.js +5 -36
- package/src/chatbox/Emoji.js +1 -1
- package/src/chatbox/TextMessage.js +18 -96
- package/src/chatbox/block.js +161 -0
- package/src/common.js +2 -10
- package/src/notif/notif.js +30 -43
- package/src/util/common.js +224 -0
- package/src/util/index.js +0 -3
- package/compiled_src/util/extractor.js +0 -136
- package/src/util/extractor.js +0 -166
|
@@ -7,6 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _index = _interopRequireDefault(require("../util/index.js"));
|
|
8
8
|
var _Emoji = _interopRequireDefault(require("./Emoji.js"));
|
|
9
9
|
var _common = require("../common.js");
|
|
10
|
+
var _block = _interopRequireDefault(require("./block.js"));
|
|
10
11
|
var _preact = require("preact");
|
|
11
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
13
|
var defaultBubble = require('../../assets/img/bubble_default.svg');
|
|
@@ -341,46 +342,23 @@ class ChatButton extends _common.Com {
|
|
|
341
342
|
}
|
|
342
343
|
renderMessagePreview(ev, defmsg) {
|
|
343
344
|
defmsg = defmsg || this.props.t('sent_you_a_message');
|
|
344
|
-
let message = _index.default.get(ev, 'data.message.text');
|
|
345
345
|
var format = _index.default.get(ev, 'data.message.format');
|
|
346
|
-
|
|
347
|
-
if (
|
|
346
|
+
let block = _index.default.get(ev, 'data.message.block');
|
|
347
|
+
if (block || format == 'block') return (0, _preact.h)(_block.default, {
|
|
348
|
+
block: block
|
|
349
|
+
});
|
|
350
|
+
let message = _index.default.get(ev, 'data.message.text', defmsg);
|
|
348
351
|
if (!message && _index.default.size(_index.default.get(ev, 'data.message.attachments')) > 0) message = defmsg;
|
|
349
352
|
if (!message) return null;
|
|
350
353
|
let byType = _index.default.get(ev, 'by.type');
|
|
351
354
|
var tags = _index.default.extractText(message).map(tag => {
|
|
352
355
|
if (tag.type === 'emoji') return (0, _preact.h)(_Emoji.default, {
|
|
353
|
-
emojiCode: tag.text
|
|
354
|
-
byType: byType
|
|
356
|
+
emojiCode: tag.text
|
|
355
357
|
});
|
|
356
358
|
return tag.text;
|
|
357
359
|
});
|
|
358
360
|
return tags;
|
|
359
361
|
}
|
|
360
|
-
renderDeltaMessagePreview(ev, defmsg) {
|
|
361
|
-
defmsg = defmsg || this.props.t('sent_you_a_message');
|
|
362
|
-
let message = _index.default.get(ev, 'data.message.quill_delta');
|
|
363
|
-
if (!message && _index.default.size(_index.default.get(ev, 'data.message.attachments')) > 0) message = defmsg;
|
|
364
|
-
if (!message) return;
|
|
365
|
-
let quilldeltas = _index.default.parseJSON(message) || {};
|
|
366
|
-
if (!quilldeltas || _index.default.size(quilldeltas.ops) === 0) return null;
|
|
367
|
-
let $deltas = _index.default.map(quilldeltas.ops, delta => {
|
|
368
|
-
let html = '';
|
|
369
|
-
let insert = delta.insert;
|
|
370
|
-
let attributes = delta.attributes;
|
|
371
|
-
if (insert.dynamicField) {
|
|
372
|
-
return _index.default.get(insert, 'dynamicField.text', '');
|
|
373
|
-
}
|
|
374
|
-
if (insert.emoji) return (0, _preact.h)(_Emoji.default, {
|
|
375
|
-
emojiCode: `:${insert.emoji}:`
|
|
376
|
-
});
|
|
377
|
-
if (typeof insert === 'string') {
|
|
378
|
-
return insert;
|
|
379
|
-
}
|
|
380
|
-
return null;
|
|
381
|
-
});
|
|
382
|
-
return $deltas;
|
|
383
|
-
}
|
|
384
362
|
closePreview(e) {
|
|
385
363
|
if (e) {
|
|
386
364
|
e.preventDefault();
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _index = _interopRequireDefault(require("../util/index.js"));
|
|
8
|
+
var _block = _interopRequireDefault(require("./block.js"));
|
|
8
9
|
var _common = require("../common.js");
|
|
9
10
|
var _preact = require("preact");
|
|
10
11
|
var _Emoji = _interopRequireDefault(require("./Emoji.js"));
|
|
@@ -12,7 +13,8 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
12
13
|
class TextMessage extends _common.Com {
|
|
13
14
|
render() {
|
|
14
15
|
var format = _index.default.get(this.props.ev, 'data.message.format', 'plaintext');
|
|
15
|
-
|
|
16
|
+
let block = _index.default.get(this.props.ev, 'data.message.block');
|
|
17
|
+
if (block) return this.renderBlock(block);
|
|
16
18
|
return this.renderPlainText();
|
|
17
19
|
}
|
|
18
20
|
renderPlainText() {
|
|
@@ -20,6 +22,7 @@ class TextMessage extends _common.Com {
|
|
|
20
22
|
text = _index.default.trim(text);
|
|
21
23
|
if (_index.default.size(text) === 0) return null;
|
|
22
24
|
let byType = _index.default.get(this.props.ev, 'by.type');
|
|
25
|
+
if (byType !== 'user') byType = 'agent';
|
|
23
26
|
var tags = _index.default.extractText(text).map(tag => {
|
|
24
27
|
if (tag.type === 'emoji') return (0, _preact.h)(_Emoji.default, {
|
|
25
28
|
emojiCode: tag.text,
|
|
@@ -45,111 +48,29 @@ class TextMessage extends _common.Com {
|
|
|
45
48
|
return tag.text;
|
|
46
49
|
});
|
|
47
50
|
if (_index.default.size(tags) === 0) return null;
|
|
48
|
-
if (byType === 'agent') {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}, tags);
|
|
52
|
-
}
|
|
51
|
+
if (byType === 'agent') return (0, _preact.h)("div", {
|
|
52
|
+
class: "message-agent message-text--agent"
|
|
53
|
+
}, tags);
|
|
53
54
|
return (0, _preact.h)("div", {
|
|
54
55
|
class: "message-user message-text--user"
|
|
55
56
|
}, tags);
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
let
|
|
60
|
-
quilldeltas = trimQuillDelta(quilldeltas);
|
|
61
|
-
if (!quilldeltas || _index.default.size(quilldeltas.ops) === 0) return null;
|
|
62
|
-
let $deltas = _index.default.map(quilldeltas.ops, delta => {
|
|
63
|
-
let html = '';
|
|
64
|
-
let insert = delta.insert;
|
|
65
|
-
let attributes = delta.attributes;
|
|
66
|
-
if (insert.dynamicField) {
|
|
67
|
-
return _index.default.get(insert, 'dynamicField.text', '');
|
|
68
|
-
}
|
|
69
|
-
if (insert.emoji) return (0, _preact.h)(_Emoji.default, {
|
|
70
|
-
emojiCode: `:${insert.emoji}:`
|
|
71
|
-
});
|
|
72
|
-
if (typeof insert === 'string') {
|
|
73
|
-
let $tags = _index.default.extractText(insert).map((tag, i) => {
|
|
74
|
-
if (tag.type === 'link') {
|
|
75
|
-
return (0, _preact.h)("a", {
|
|
76
|
-
href: absLink(tag.text),
|
|
77
|
-
target: "_blank"
|
|
78
|
-
}, tag.text);
|
|
79
|
-
}
|
|
80
|
-
return tag.text;
|
|
81
|
-
});
|
|
82
|
-
if (attributes) {
|
|
83
|
-
if (attributes.italic && attributes.bold) return (0, _preact.h)("span", {
|
|
84
|
-
style: "font-weight: bold !important; font-style: italic !important"
|
|
85
|
-
}, $tags);
|
|
86
|
-
if (attributes.italic) return (0, _preact.h)("span", {
|
|
87
|
-
style: "font-style: italic !important"
|
|
88
|
-
}, $tags);
|
|
89
|
-
if (attributes.bold) return (0, _preact.h)("span", {
|
|
90
|
-
style: "font-weight: bold !important"
|
|
91
|
-
}, $tags);
|
|
92
|
-
}
|
|
93
|
-
return (0, _preact.h)("span", null, $tags);
|
|
94
|
-
}
|
|
95
|
-
return null;
|
|
96
|
-
});
|
|
97
|
-
let byType = _index.default.get(this.ev, 'by.type');
|
|
58
|
+
renderBlock(block) {
|
|
59
|
+
if (_index.default.size(block) == 0) return null;
|
|
60
|
+
let byType = _index.default.get(this.props.ev, 'by.type');
|
|
98
61
|
if (byType !== 'user') byType = 'agent';
|
|
99
|
-
if (_index.default.size($deltas) === 0) return null;
|
|
100
62
|
if (byType === 'agent') {
|
|
101
63
|
return (0, _preact.h)("div", {
|
|
102
64
|
class: "message-agent message-text--agent"
|
|
103
|
-
},
|
|
65
|
+
}, (0, _preact.h)(_block.default, {
|
|
66
|
+
block: block
|
|
67
|
+
}));
|
|
104
68
|
}
|
|
105
69
|
return (0, _preact.h)("div", {
|
|
106
70
|
class: "message-user message-text--user"
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
exports.default = TextMessage;
|
|
111
|
-
const emojiCodes = {
|
|
112
|
-
like: '👍',
|
|
113
|
-
unlike: '👎',
|
|
114
|
-
angry: '😠',
|
|
115
|
-
confused: '😕',
|
|
116
|
-
crying: '😢',
|
|
117
|
-
grinning: '😀',
|
|
118
|
-
'heart-eyes': '😍',
|
|
119
|
-
neutral: '😐',
|
|
120
|
-
sleepy: '😪',
|
|
121
|
-
sad: '😞',
|
|
122
|
-
smiling: '😄',
|
|
123
|
-
'tongue-out': '😛',
|
|
124
|
-
tired: '😩',
|
|
125
|
-
surprised: '😮',
|
|
126
|
-
wink: '😉'
|
|
127
|
-
};
|
|
128
|
-
function trimQuillDelta(delta) {
|
|
129
|
-
if (!delta) return delta;
|
|
130
|
-
if (!delta.ops || !delta.ops.length) return delta;
|
|
131
|
-
let last = delta.ops[delta.ops.length - 1];
|
|
132
|
-
if (typeof last.insert != 'string') return delta;
|
|
133
|
-
let insert = last.insert.trimEnd();
|
|
134
|
-
if (insert) {
|
|
135
|
-
if (last.insert != insert) {
|
|
136
|
-
let newops = delta.ops.slice();
|
|
137
|
-
let last = newops.pop();
|
|
138
|
-
last.insert = insert;
|
|
139
|
-
newops.push(last);
|
|
140
|
-
return {
|
|
141
|
-
ops: newops
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
return delta;
|
|
71
|
+
}, (0, _preact.h)(_block.default, {
|
|
72
|
+
block: block
|
|
73
|
+
}));
|
|
145
74
|
}
|
|
146
|
-
let newops = delta.ops.slice();
|
|
147
|
-
newops.pop();
|
|
148
|
-
return trimQuillDelta({
|
|
149
|
-
ops: newops
|
|
150
|
-
});
|
|
151
75
|
}
|
|
152
|
-
|
|
153
|
-
if (!url.startsWith('http://') && !url.startsWith('https://') && !url.startsWith('//')) return 'http://' + url;
|
|
154
|
-
return url;
|
|
155
|
-
}
|
|
76
|
+
exports.default = TextMessage;
|
|
@@ -0,0 +1,152 @@
|
|
|
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
|
+
var _Emoji = _interopRequireDefault(require("./Emoji.js"));
|
|
9
|
+
var _common = require("../common.js");
|
|
10
|
+
var _preact = require("preact");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
class Block extends _common.Com {
|
|
13
|
+
constructor(props) {
|
|
14
|
+
super(props);
|
|
15
|
+
}
|
|
16
|
+
renderBlock(block) {
|
|
17
|
+
if (_index.default.size(block) == 0) return null;
|
|
18
|
+
let ele = {};
|
|
19
|
+
ele.style = '';
|
|
20
|
+
if (block.style) {
|
|
21
|
+
_index.default.map(block.style, (v, k) => {
|
|
22
|
+
ele.style += k + ': ' + v + ';';
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
ele.attrs = {};
|
|
26
|
+
if (block.title != '') {
|
|
27
|
+
ele.attrs['title'] = block.title;
|
|
28
|
+
}
|
|
29
|
+
if (block.href != '') {
|
|
30
|
+
ele.attrs['href'] = block.href;
|
|
31
|
+
}
|
|
32
|
+
ele.class = block.class;
|
|
33
|
+
_index.default.map(block.attrs, (v, k) => {
|
|
34
|
+
ele.attrs[k] = v;
|
|
35
|
+
});
|
|
36
|
+
if (block.type == 'bullet_list' || block.type == 'ordered_list') {
|
|
37
|
+
if (block.type == 'bullet_list') {
|
|
38
|
+
ele.tag = 'ol';
|
|
39
|
+
} else {
|
|
40
|
+
ele.tag = 'ul';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (block.type == 'list_item') {
|
|
44
|
+
ele.tag = 'li';
|
|
45
|
+
}
|
|
46
|
+
if (block.type == 'heading') {
|
|
47
|
+
if (block.level < 1) block.level = 1;
|
|
48
|
+
if (block.level > 6) block.level = 6;
|
|
49
|
+
ele.tag = 'h' + block.level;
|
|
50
|
+
}
|
|
51
|
+
if (block.type == 'paragraph') ele.tag = 'div';
|
|
52
|
+
ele.text = block.text;
|
|
53
|
+
if (block.type == '' || block.type == 'text' || block.type == 'dynamic-field') {
|
|
54
|
+
ele.tag = 'span';
|
|
55
|
+
if (block.bold) ele.tag = 'b';
|
|
56
|
+
if (block.italic) {
|
|
57
|
+
if (ele.tag == 'b') {
|
|
58
|
+
ele.style += 'font-style: italic;';
|
|
59
|
+
} else {
|
|
60
|
+
ele.tag = 'em';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (block.underline) ele.Style += 'text-decoration:underline;';
|
|
64
|
+
if (block.strike_through) ele.Style += 'text-decoration: line-through;';
|
|
65
|
+
}
|
|
66
|
+
if (block.type == 'dynamic-field') {
|
|
67
|
+
let key = _index.default.get(block.attrs, 'key');
|
|
68
|
+
ele.text = _index.default.get(this.props.data, [key], ele.text);
|
|
69
|
+
}
|
|
70
|
+
if (block.type == 'link') {
|
|
71
|
+
ele.tag = 'a';
|
|
72
|
+
ele.attrs['href'] = block.href;
|
|
73
|
+
ele.attrs['target'] = block.target;
|
|
74
|
+
ele.attrs['title'] = block.title;
|
|
75
|
+
}
|
|
76
|
+
if (block.type == 'mention-agent' || block.type == 'mention') {
|
|
77
|
+
ele.tag = 'span';
|
|
78
|
+
ele.class = 'mention';
|
|
79
|
+
let id = block.attrs.id = '';
|
|
80
|
+
if (block.attrs.id == '*' || block.attrs.id == 'all') {
|
|
81
|
+
ele.text = '@' + this.$t('all');
|
|
82
|
+
}
|
|
83
|
+
if (id.startsWith('ag')) {
|
|
84
|
+
let ag = store.matchAgent(id);
|
|
85
|
+
let name = _index.default.getAgentDisplayName(ag, insert.mention.fullname);
|
|
86
|
+
ele.text = '@' + name;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (block.type == 'horizontal_rule') ele.tag = 'hr';
|
|
90
|
+
if (block.type == 'emoji') {
|
|
91
|
+
let code = '';
|
|
92
|
+
if (_index.default.size(block.attrs) > 0) code = block.attrs['code'];
|
|
93
|
+
if (code == '') code = block.Text;
|
|
94
|
+
if (code != '') {
|
|
95
|
+
ele.tag = 'Emoji';
|
|
96
|
+
ele.attrs['emojiCode'] = code;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (block.type == 'table') {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
let $body = null;
|
|
103
|
+
if (_index.default.size(block.content)) $body = _index.default.map(block.content, block => this.renderBlock(block));else $body = ele.text;
|
|
104
|
+
switch (ele.tag) {
|
|
105
|
+
case 'div':
|
|
106
|
+
return (0, _preact.h)("div", null, $body);
|
|
107
|
+
case 'h1':
|
|
108
|
+
return (0, _preact.h)("h1", null, $body);
|
|
109
|
+
case 'h2':
|
|
110
|
+
return (0, _preact.h)("h2", null, $body);
|
|
111
|
+
case 'h3':
|
|
112
|
+
return (0, _preact.h)("h3", null, $body);
|
|
113
|
+
case 'h4':
|
|
114
|
+
return (0, _preact.h)("h4", null, $body);
|
|
115
|
+
case 'h5':
|
|
116
|
+
return (0, _preact.h)("h5", null, $body);
|
|
117
|
+
case 'h6':
|
|
118
|
+
return (0, _preact.h)("h6", null, $body);
|
|
119
|
+
case 'ol':
|
|
120
|
+
return (0, _preact.h)("ol", null, $body);
|
|
121
|
+
case 'ul':
|
|
122
|
+
return (0, _preact.h)("ul", null, $body);
|
|
123
|
+
case 'span':
|
|
124
|
+
return (0, _preact.h)("span", null, $body);
|
|
125
|
+
case 'em':
|
|
126
|
+
return (0, _preact.h)("em", null, $body);
|
|
127
|
+
case 'b':
|
|
128
|
+
return (0, _preact.h)("b", null, $body);
|
|
129
|
+
case 'hr':
|
|
130
|
+
return (0, _preact.h)("hr", null);
|
|
131
|
+
case 'a':
|
|
132
|
+
return (0, _preact.h)("a", {
|
|
133
|
+
href: ele.attrs['href'],
|
|
134
|
+
target: ele.attrs['target'],
|
|
135
|
+
title: ele.attrs['title']
|
|
136
|
+
}, $body);
|
|
137
|
+
case 'Emoji':
|
|
138
|
+
return (0, _preact.h)(_Emoji.default, {
|
|
139
|
+
emojiCode: ele.attrs['emojiCode']
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
render() {
|
|
145
|
+
return this.renderBlock(this.props.block);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.default = Block;
|
|
149
|
+
function absLink(url) {
|
|
150
|
+
if (!url.startsWith('http://') && !url.startsWith('https://') && !url.startsWith('//')) return 'http://' + url;
|
|
151
|
+
return url;
|
|
152
|
+
}
|
|
@@ -7,6 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _index = _interopRequireDefault(require("../util/index.js"));
|
|
8
8
|
var _preact = require("preact");
|
|
9
9
|
var _common = require("../common.js");
|
|
10
|
+
var _block = _interopRequireDefault(require("../chatbox/block.js"));
|
|
10
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
12
|
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; }
|
|
12
13
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
@@ -106,10 +107,6 @@ class Notif extends _common.Com {
|
|
|
106
107
|
});
|
|
107
108
|
let timestamp = this.randomTimestampt();
|
|
108
109
|
let profiles = _index.default.get(this.props, 'plugin.notification.profiles', []);
|
|
109
|
-
let user = profiles[Math.floor(Math.random() * _index.default.size(profiles))] || {};
|
|
110
|
-
if (user.avatar_url && user.avatar_url.startsWith('http')) {
|
|
111
|
-
await _index.default.preloadImg(user.avatar_url);
|
|
112
|
-
}
|
|
113
110
|
_index.default.map(_index.default.get(this.props.plugin, 'notification.custom_avatar_urls'), url => {
|
|
114
111
|
profiles.push({
|
|
115
112
|
type: 'person',
|
|
@@ -121,17 +118,32 @@ class Notif extends _common.Com {
|
|
|
121
118
|
age: randomAge()
|
|
122
119
|
});
|
|
123
120
|
});
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
121
|
+
if (_index.default.size(profiles) == 0) {
|
|
122
|
+
profiles.push({
|
|
123
|
+
type: 'person',
|
|
124
|
+
fullname: randomName(),
|
|
125
|
+
avatar_url: 'https://public-gcs.subiz-cdn.com/widget_assets/profile_images/VNF25.png',
|
|
126
|
+
email: randomEmail(),
|
|
127
|
+
address: randomAddress(),
|
|
128
|
+
phone: ramdomPhone(),
|
|
129
|
+
age: randomAge()
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
let user = profiles[Math.floor(Math.random() * _index.default.size(profiles))] || {};
|
|
133
|
+
if (user.avatar_url && user.avatar_url.startsWith('http')) {
|
|
134
|
+
await _index.default.preloadImg(user.avatar_url);
|
|
135
|
+
}
|
|
136
|
+
let i18n_messages = _index.default.get(this.props, 'plugin.notification.i18n_message_blocks', []);
|
|
137
|
+
let i18n_message = i18n_messages[Math.floor(Math.random() * _index.default.size(i18n_messages))].i18n;
|
|
138
|
+
let fallbackmsgs = _index.default.get(this.props, 'plugin.notification.message_blocks', []);
|
|
127
139
|
let fallbackmessage = fallbackmsgs[Math.floor(Math.random() * _index.default.size(fallbackmsgs))];
|
|
128
|
-
let i18n_title = _index.default.get(this.props, 'plugin.notification.
|
|
140
|
+
let i18n_title = _index.default.get(this.props, 'plugin.notification.i18n_title_block');
|
|
129
141
|
return this.setState({
|
|
130
142
|
close: false,
|
|
131
143
|
last_show: _index.default.Date.now(),
|
|
132
144
|
timestamp: timestamp,
|
|
133
145
|
user: user,
|
|
134
|
-
title: this.props.t.i18n(i18n_title) || _index.default.get(this.props, 'plugin.notification.
|
|
146
|
+
title: this.props.t.i18n(i18n_title) || _index.default.get(this.props, 'plugin.notification.title_block'),
|
|
135
147
|
message: this.props.t.i18n(i18n_message) || fallbackmessage
|
|
136
148
|
});
|
|
137
149
|
}
|
|
@@ -193,27 +205,6 @@ class Notif extends _common.Com {
|
|
|
193
205
|
this.setClose(false);
|
|
194
206
|
}, 50);
|
|
195
207
|
}
|
|
196
|
-
renderTextFromQuillDelta(quilldelta, profile) {
|
|
197
|
-
let qd = _index.default.parseJSON(quilldelta);
|
|
198
|
-
if (!qd || !qd.ops) return null;
|
|
199
|
-
let out = _index.default.map(qd.ops, op => {
|
|
200
|
-
let out = null;
|
|
201
|
-
if (!op.insert) return null;
|
|
202
|
-
if (typeof op.insert == 'string') out = op.insert;
|
|
203
|
-
if (_index.default.get(op, 'insert.dynamicField')) {
|
|
204
|
-
let key = _index.default.get(op, 'insert.dynamicField.key');
|
|
205
|
-
if (key === 'user.fullname') out = profile.fullname;
|
|
206
|
-
if (key === 'user.email') out = profile.email;
|
|
207
|
-
if (key === 'user.address') out = profile.address;
|
|
208
|
-
if (key === 'user.phone') out = profile.phone;
|
|
209
|
-
}
|
|
210
|
-
if (_index.default.get(op, 'attributes.bold')) out = (0, _preact.h)("b", null, out);
|
|
211
|
-
if (_index.default.get(op, 'attributes.italic')) out = (0, _preact.h)("b", null, out);
|
|
212
|
-
return out;
|
|
213
|
-
}).filter(a => a);
|
|
214
|
-
if (out.length == 1 && (out[0] == '\n' || out[0] == '')) return [];
|
|
215
|
-
return out;
|
|
216
|
-
}
|
|
217
208
|
render() {
|
|
218
209
|
if (!this.props.t) return null;
|
|
219
210
|
if (!this.state.cssready) return null;
|
|
@@ -247,9 +238,12 @@ class Notif extends _common.Com {
|
|
|
247
238
|
class: "notif_time",
|
|
248
239
|
style: _index.default.js2css(notif.subtext_style)
|
|
249
240
|
}, this.state.timestamp);
|
|
250
|
-
let
|
|
251
|
-
|
|
252
|
-
|
|
241
|
+
let data = {
|
|
242
|
+
'user.fullname': user.fullname,
|
|
243
|
+
'user.email': user.email,
|
|
244
|
+
'user.address': user.address,
|
|
245
|
+
'user.phone': user.phone
|
|
246
|
+
};
|
|
253
247
|
return (0, _preact.h)("div", {
|
|
254
248
|
class: animation + ' notif' + ' notif__' + pos,
|
|
255
249
|
onClick: e => this.onClick(e),
|
|
@@ -271,10 +265,16 @@ class Notif extends _common.Com {
|
|
|
271
265
|
}, (0, _preact.h)("div", {
|
|
272
266
|
class: "notif_title",
|
|
273
267
|
style: _index.default.js2css(notif.title_style)
|
|
274
|
-
},
|
|
268
|
+
}, (0, _preact.h)(_block.default, {
|
|
269
|
+
block: this.state.title,
|
|
270
|
+
data: data
|
|
271
|
+
})), (0, _preact.h)("div", {
|
|
275
272
|
class: "notif_message",
|
|
276
273
|
style: _index.default.js2css(notif.message_style)
|
|
277
|
-
},
|
|
274
|
+
}, (0, _preact.h)(_block.default, {
|
|
275
|
+
block: this.state.message,
|
|
276
|
+
data: data
|
|
277
|
+
})), $time)));
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
280
|
exports.default = Notif;
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.XMLHttpRequest = exports.Date = exports.DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL = exports.DEFVAL = void 0;
|
|
7
7
|
exports.agentsOfConvo = agentsOfConvo;
|
|
8
|
+
exports.blockToText = blockToText;
|
|
8
9
|
exports.checkRunConditions = checkRunConditions;
|
|
9
10
|
exports.clearTimeout = exports.clearInterval = void 0;
|
|
10
11
|
exports.cloneDeep = cloneDeep;
|
|
@@ -14,6 +15,12 @@ exports.detectLang = detectLang;
|
|
|
14
15
|
exports.diffDay = diffDay;
|
|
15
16
|
exports.diffYear = diffYear;
|
|
16
17
|
exports.each = each;
|
|
18
|
+
exports.extract = extract;
|
|
19
|
+
exports.extractEmails = extractEmails;
|
|
20
|
+
exports.extractEmojis = extractEmojis;
|
|
21
|
+
exports.extractLinks = extractLinks;
|
|
22
|
+
exports.extractPhones = extractPhones;
|
|
23
|
+
exports.extractText = extractText;
|
|
17
24
|
exports.filter = filter;
|
|
18
25
|
exports.find = find;
|
|
19
26
|
exports.formatCurrency = formatCurrency;
|
|
@@ -39,6 +46,7 @@ exports.offsetToMin = offsetToMin;
|
|
|
39
46
|
exports.orderBy = orderBy;
|
|
40
47
|
exports.orderByF = orderByF;
|
|
41
48
|
exports.parseJSON = parseJSON;
|
|
49
|
+
exports.pipeExtracts = pipeExtracts;
|
|
42
50
|
exports.preloadImg = preloadImg;
|
|
43
51
|
exports.preloadWebfonts = preloadWebfonts;
|
|
44
52
|
exports.randomString = randomString;
|
|
@@ -64,6 +72,127 @@ exports.unicodeToAscii = unicodeToAscii;
|
|
|
64
72
|
exports.unixSec = unixSec;
|
|
65
73
|
exports.usersOfConvo = usersOfConvo;
|
|
66
74
|
var op = require('./op.js');
|
|
75
|
+
function extractEmojis(text) {
|
|
76
|
+
var out = [];
|
|
77
|
+
for (var i = 0; i < text.length; i++) {
|
|
78
|
+
for (var e = 0; e < emojis.length; e++) {
|
|
79
|
+
if (text.indexOf(emojis[e], i) !== i) continue;
|
|
80
|
+
out.push({
|
|
81
|
+
index: i,
|
|
82
|
+
length: emojis[e].length
|
|
83
|
+
});
|
|
84
|
+
i += emojis[e].length - 1;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
function extractLinks(text) {
|
|
91
|
+
text = text || '';
|
|
92
|
+
var reg = /(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.,~#?&//=]*)/gim;
|
|
93
|
+
var out = [];
|
|
94
|
+
var match;
|
|
95
|
+
while (match = reg.exec(text)) {
|
|
96
|
+
out.push({
|
|
97
|
+
index: match.index,
|
|
98
|
+
length: reg.lastIndex - match.index
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
function extractEmails(text) {
|
|
104
|
+
text = text || '';
|
|
105
|
+
var reg = /(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/gim;
|
|
106
|
+
var out = [];
|
|
107
|
+
var match;
|
|
108
|
+
while (match = reg.exec(text)) {
|
|
109
|
+
out.push({
|
|
110
|
+
index: match.index,
|
|
111
|
+
length: reg.lastIndex - match.index
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
function extractPhones(msg) {
|
|
117
|
+
msg = msg || '';
|
|
118
|
+
var fgmsg = '';
|
|
119
|
+
var realchmap = {};
|
|
120
|
+
for (var i = 0; i < msg.length; i++) {
|
|
121
|
+
var ch = msg.charAt(i);
|
|
122
|
+
if (ch !== '.' && ch !== '-' && ch !== ' ') {
|
|
123
|
+
fgmsg += ch;
|
|
124
|
+
realchmap[fgmsg.length - 1] = i;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
var prevCh = i > 0 ? msg.charAt(i - 1) : '-';
|
|
128
|
+
var nextCh = i < msg.length - 1 ? msg.charAt(i + 1) : '-';
|
|
129
|
+
if ('0123456789'.indexOf(prevCh) !== -1 && '0123456789'.indexOf(nextCh) !== -1) continue;
|
|
130
|
+
fgmsg += ch;
|
|
131
|
+
realchmap[fgmsg.length - 1] = i;
|
|
132
|
+
}
|
|
133
|
+
var reg = /([0-9]{8,13})/gim;
|
|
134
|
+
var out = [];
|
|
135
|
+
var match;
|
|
136
|
+
while (match = reg.exec(fgmsg)) {
|
|
137
|
+
out.push({
|
|
138
|
+
index: realchmap[match.index],
|
|
139
|
+
length: realchmap[reg.lastIndex - 1] - realchmap[match.index] + 1
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
function extract(text, extractor, type) {
|
|
145
|
+
if (!text) return [];
|
|
146
|
+
var out = [];
|
|
147
|
+
var lastindex = 0;
|
|
148
|
+
var tags = extractor(text);
|
|
149
|
+
if (size(tags) === 0) return [{
|
|
150
|
+
type: 'text',
|
|
151
|
+
text
|
|
152
|
+
}];
|
|
153
|
+
each(tags, tag => {
|
|
154
|
+
out.push({
|
|
155
|
+
type: 'text',
|
|
156
|
+
text: text.substr(lastindex, tag.index - lastindex)
|
|
157
|
+
});
|
|
158
|
+
out.push({
|
|
159
|
+
type,
|
|
160
|
+
text: text.substr(tag.index, tag.length)
|
|
161
|
+
});
|
|
162
|
+
lastindex = tag.index + tag.length;
|
|
163
|
+
});
|
|
164
|
+
var lastTag = last(tags);
|
|
165
|
+
out.push({
|
|
166
|
+
type: 'text',
|
|
167
|
+
text: text.substr(lastTag.index + lastTag.length, text.length - lastTag.index + lastTag.length)
|
|
168
|
+
});
|
|
169
|
+
return filter(out, o => o.text !== '');
|
|
170
|
+
}
|
|
171
|
+
function pipeExtracts(text, extractors) {
|
|
172
|
+
var out = [];
|
|
173
|
+
if (size(extractors) === 0) return [{
|
|
174
|
+
type: 'text',
|
|
175
|
+
text
|
|
176
|
+
}];
|
|
177
|
+
var ext = extractors.shift();
|
|
178
|
+
var tags = extract(text, ext, ext.type);
|
|
179
|
+
each(tags, t => {
|
|
180
|
+
if (t.type !== 'text') return out.push(t);
|
|
181
|
+
out = out.concat(pipeExtracts(t.text, extractors.slice()));
|
|
182
|
+
});
|
|
183
|
+
return out;
|
|
184
|
+
}
|
|
185
|
+
function extractText(text) {
|
|
186
|
+
var link = extractLinks;
|
|
187
|
+
link.type = 'link';
|
|
188
|
+
var email = extractEmails;
|
|
189
|
+
email.type = 'email';
|
|
190
|
+
var phone = extractPhones;
|
|
191
|
+
phone.type = 'phone';
|
|
192
|
+
var emoji = extractEmojis;
|
|
193
|
+
emoji.type = 'emoji';
|
|
194
|
+
return pipeExtracts(text, [email, link, phone, emoji]);
|
|
195
|
+
}
|
|
67
196
|
function parseJSON(str) {
|
|
68
197
|
try {
|
|
69
198
|
return parse(str);
|
|
@@ -974,4 +1103,48 @@ const ALL_CURRENCIES = [{
|
|
|
974
1103
|
}, {
|
|
975
1104
|
code: 'VND',
|
|
976
1105
|
symbol: '₫'
|
|
977
|
-
}];
|
|
1106
|
+
}];
|
|
1107
|
+
function blockToText(block) {
|
|
1108
|
+
return _blockToText(block).trim();
|
|
1109
|
+
}
|
|
1110
|
+
function _blockToText(block) {
|
|
1111
|
+
if (!block || !block.type) return '';
|
|
1112
|
+
let out = '';
|
|
1113
|
+
if (block.type == 'bullet_list' || block.type == 'ordered_list') {
|
|
1114
|
+
map(block.content, item => {
|
|
1115
|
+
preifx = '\n* ';
|
|
1116
|
+
if (block.type == 'ordered_list') {
|
|
1117
|
+
prefix = i + '\n. ';
|
|
1118
|
+
}
|
|
1119
|
+
out += prefix + blockToText(item).trim();
|
|
1120
|
+
});
|
|
1121
|
+
return out;
|
|
1122
|
+
}
|
|
1123
|
+
if (block.type == 'heading' || block.type == 'paragraph') {
|
|
1124
|
+
out += '\n';
|
|
1125
|
+
}
|
|
1126
|
+
if (block.type == '' || block.type == 'text' || block.type == 'link' || block.type == 'mention-agent' || block.type == 'dynamic-field') {
|
|
1127
|
+
return out + block.text;
|
|
1128
|
+
}
|
|
1129
|
+
if (block.type == 'horizontal_rule') return out + '\n---\n';
|
|
1130
|
+
if (block.type == 'emoji') {
|
|
1131
|
+
let code;
|
|
1132
|
+
if (size(block.attrs) > 0) code = block.attrs['code'];
|
|
1133
|
+
if (code == '') code = block.text;
|
|
1134
|
+
if (code != '') {
|
|
1135
|
+
let emoji = find(LEXICAL_EMOJI_LIST, emoji => emoji.code === code);
|
|
1136
|
+
out + op.get(emoji, 'text', code);
|
|
1137
|
+
}
|
|
1138
|
+
return out;
|
|
1139
|
+
}
|
|
1140
|
+
map(block.content, block => {
|
|
1141
|
+
out += blockToText(block);
|
|
1142
|
+
});
|
|
1143
|
+
return out;
|
|
1144
|
+
}
|
|
1145
|
+
let emojis = ['like', 'unlike', 'wink', 'tongue-out', 'tired', 'surprised', 'smiling', 'sleepy', 'sad', 'neutral', 'heart-eyes', 'grinning', 'crying', 'confused', 'angry', 'cry', 'heart_eyes', 'neutral_face', 'emoji--disappointed', 'smile', 'open_mouth', 'tired_face', 'stuck_out_tongue', 'moyai', 'thumbsdown', 'dislike', 'thumbsup', 'ok_hand', 'octopus', 'pig2', 'wave', 'mouse', 'mouse2', 'rat'];
|
|
1146
|
+
emojis = map(emojis, e => ':' + e + ':');
|
|
1147
|
+
function absLink(url) {
|
|
1148
|
+
if (!url.startsWith('http://') && !url.startsWith('https://') && !url.startsWith('//')) return 'http://' + url;
|
|
1149
|
+
return url;
|
|
1150
|
+
}
|