toggle-components-library 1.22.5 → 1.22.6
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/dist/toggle-components-library.common.js +5895 -2958
- package/dist/toggle-components-library.common.js.map +1 -1
- package/dist/toggle-components-library.css +1 -1
- package/dist/toggle-components-library.umd.js +5895 -2958
- package/dist/toggle-components-library.umd.js.map +1 -1
- package/dist/toggle-components-library.umd.min.js +3 -3
- package/dist/toggle-components-library.umd.min.js.map +1 -1
- package/package-lock.json +45674 -0
- package/package.json +1 -1
- package/src/components/forms/ToggleInputText.vue +74 -2
package/package.json
CHANGED
|
@@ -90,6 +90,12 @@ export default {
|
|
|
90
90
|
required: false,
|
|
91
91
|
default: false
|
|
92
92
|
},
|
|
93
|
+
includeEmojiEntitiesInCharCount: {
|
|
94
|
+
descripion: "If true, emoji's are counted as the length of their HTML entities rather than a signle character length",
|
|
95
|
+
type: Boolean,
|
|
96
|
+
required: false,
|
|
97
|
+
default: false
|
|
98
|
+
},
|
|
93
99
|
readonly: {
|
|
94
100
|
type: Boolean,
|
|
95
101
|
required: false,
|
|
@@ -118,10 +124,76 @@ export default {
|
|
|
118
124
|
*/
|
|
119
125
|
messageLength(count, maxLenght)
|
|
120
126
|
{
|
|
121
|
-
let
|
|
127
|
+
let message = count;
|
|
128
|
+
let mcount = 0;
|
|
129
|
+
|
|
130
|
+
// If the emoji flag is set, make sure the character count takes account of the decoded emoji characters (this will include £ signs)
|
|
131
|
+
if (this.includeEmojiEntitiesInCharCount && count) {
|
|
132
|
+
|
|
133
|
+
let message = this.convertEmojis(count)
|
|
134
|
+
mcount = message ? this.convertEmojis(message).length : 0;
|
|
135
|
+
|
|
136
|
+
} else {
|
|
137
|
+
mcount = message ? message.length : 0;
|
|
138
|
+
}
|
|
139
|
+
|
|
122
140
|
return mcount+' / '+maxLenght;
|
|
123
141
|
},
|
|
124
142
|
|
|
143
|
+
/*
|
|
144
|
+
* Converts emojis to html entity
|
|
145
|
+
* @param str (the entire message)
|
|
146
|
+
* @return string of entire message including decoded emojis
|
|
147
|
+
*/
|
|
148
|
+
convertEmojis(str) {
|
|
149
|
+
|
|
150
|
+
let result = '';
|
|
151
|
+
|
|
152
|
+
//converts unicode decimal value into an HTML entity
|
|
153
|
+
let decimal2Html = (num) => `&#${num};`;
|
|
154
|
+
|
|
155
|
+
//converts a character into an HTML entity
|
|
156
|
+
const char2Html = (char) => {
|
|
157
|
+
let item = `${char}`;
|
|
158
|
+
|
|
159
|
+
//spread operator can detect emoji surrogate pairs
|
|
160
|
+
if([...item].length > 1) {
|
|
161
|
+
|
|
162
|
+
//handle and convert utf surrogate pairs
|
|
163
|
+
let concat = '';
|
|
164
|
+
let unicode = '';
|
|
165
|
+
|
|
166
|
+
//for each part of the pair
|
|
167
|
+
for(let i = 0; i < 2; i++){
|
|
168
|
+
|
|
169
|
+
//get the character code value
|
|
170
|
+
let dec = char[i].charCodeAt();
|
|
171
|
+
//convert to binary
|
|
172
|
+
let bin = dec.toString(2);
|
|
173
|
+
//take the last 10 bits
|
|
174
|
+
let last10 = bin.slice(-10);
|
|
175
|
+
//concatenate into 20 bit binary
|
|
176
|
+
concat = concat + last10;
|
|
177
|
+
//add 0x10000 to get unicode value
|
|
178
|
+
unicode = parseInt(concat,2) + 0x10000;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
//html entity from unicode value
|
|
182
|
+
return decimal2Html(unicode);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
//ASCII character or html entity from character code
|
|
186
|
+
return char.charCodeAt() > 127 ? decimal2Html(char.charCodeAt()) : char;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
//check each character
|
|
190
|
+
[...str].forEach(char=>{
|
|
191
|
+
result += char2Html(char);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
return result;
|
|
195
|
+
},
|
|
196
|
+
|
|
125
197
|
onFocus() {
|
|
126
198
|
this.$emit('onFocus');
|
|
127
199
|
},
|
|
@@ -133,4 +205,4 @@ export default {
|
|
|
133
205
|
}
|
|
134
206
|
|
|
135
207
|
|
|
136
|
-
</script>
|
|
208
|
+
</script>
|