toggle-components-library 1.22.4 → 1.22.7

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.4",
3
+ "version": "1.22.7",
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",
@@ -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,7 +124,19 @@ 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
 
@@ -133,4 +151,4 @@ export default {
133
151
  }
134
152
 
135
153
 
136
- </script>
154
+ </script>
@@ -44,5 +44,59 @@ export const mixins = {
44
44
 
45
45
  },
46
46
 
47
+ /*
48
+ * Converts emojis to html entity
49
+ * @param str (the entire message)
50
+ * @return string of entire message including decoded emojis
51
+ */
52
+ convertEmojis(str) {
53
+
54
+ let result = '';
55
+
56
+ //converts unicode decimal value into an HTML entity
57
+ let decimal2Html = (num) => `&#${num};`;
58
+
59
+ //converts a character into an HTML entity
60
+ const char2Html = (char) => {
61
+ let item = `${char}`;
62
+
63
+ //spread operator can detect emoji surrogate pairs
64
+ if([...item].length > 1) {
65
+
66
+ //handle and convert utf surrogate pairs
67
+ let concat = '';
68
+ let unicode = '';
69
+
70
+ //for each part of the pair
71
+ for(let i = 0; i < 2; i++){
72
+
73
+ //get the character code value
74
+ let dec = char[i].codePointAt();
75
+ //convert to binary
76
+ let bin = dec.toString(2);
77
+ //take the last 10 bits
78
+ let last10 = bin.slice(-10);
79
+ //concatenate into 20 bit binary
80
+ concat = concat + last10;
81
+ //add 0x10000 to get unicode value
82
+ unicode = parseInt(concat,2) + 0x10000;
83
+ }
84
+
85
+ //html entity from unicode value
86
+ return decimal2Html(unicode);
87
+ }
88
+
89
+ //ASCII character or html entity from character code
90
+ return char.codePointAt() > 127 ? decimal2Html(char.codePointAt()) : char;
91
+ };
92
+
93
+ //check each character
94
+ [...str].forEach(char=>{
95
+ result += char2Html(char);
96
+ });
97
+
98
+ return result;
99
+ },
100
+
47
101
  }
48
102
  }
@@ -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{