toggle-components-library 1.22.3 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toggle-components-library",
3
- "version": "1.22.3",
3
+ "version": "1.22.6",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -51,7 +51,6 @@
51
51
  "babel-preset-vue": "^2.0.2",
52
52
  "eslint": "^6.7.2",
53
53
  "eslint-plugin-vue": "^6.2.2",
54
- "node-sass": "^4.13.1",
55
54
  "react": "^16.13.1",
56
55
  "react-is": "^16.13.1",
57
56
  "sass": "^1.26.8",
@@ -46,6 +46,7 @@ export default {
46
46
  'Anton',
47
47
  'Arvo',
48
48
  'Bodoni Moda',
49
+ 'Courier Prime',
49
50
  'EB Garamond',
50
51
  'Fredoka One',
51
52
  'Helvetica',
@@ -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 mcount = count ? count.length : 0;
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>
@@ -44,6 +44,10 @@
44
44
  font-weight: 900;
45
45
  }
46
46
 
47
+ span{
48
+ padding:0 !important;
49
+ }
50
+
47
51
  }
48
52
 
49
53
  .toggle-button-float-left{