playkit-sdk 1.1.3-beta.4 → 1.1.4-beta

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * playkit-sdk v1.1.3-beta.4
2
+ * playkit-sdk v1.1.4-beta
3
3
  * PlayKit SDK for JavaScript
4
4
  * @license SEE LICENSE IN LICENSE
5
5
  */
@@ -658,6 +658,7 @@
658
658
  this.identifierPanel = null;
659
659
  this.verificationPanel = null;
660
660
  this.loadingOverlay = null;
661
+ this.otpInstance = null;
661
662
  // @ts-ignore - replaced at build time
662
663
  this.baseURL = baseURL || "https://playkit.agentlandlab.com";
663
664
  this.currentLanguage = this.detectLanguage();
@@ -788,12 +789,12 @@
788
789
 
789
790
  <div class="playkit-auth-input-group">
790
791
  <div class="playkit-code-inputs">
791
- <input type="text" maxlength="1" class="playkit-code-input" data-index="0">
792
- <input type="text" maxlength="1" class="playkit-code-input" data-index="1">
793
- <input type="text" maxlength="1" class="playkit-code-input" data-index="2">
794
- <input type="text" maxlength="1" class="playkit-code-input" data-index="3">
795
- <input type="text" maxlength="1" class="playkit-code-input" data-index="4">
796
- <input type="text" maxlength="1" class="playkit-code-input" data-index="5">
792
+ <input type="number" maxlength="1" class="playkit-code-input" data-index="0">
793
+ <input type="number" maxlength="1" class="playkit-code-input" data-index="1">
794
+ <input type="number" maxlength="1" class="playkit-code-input" data-index="2">
795
+ <input type="number" maxlength="1" class="playkit-code-input" data-index="3">
796
+ <input type="number" maxlength="1" class="playkit-code-input" data-index="4">
797
+ <input type="number" maxlength="1" class="playkit-code-input" data-index="5">
797
798
  </div>
798
799
  </div>
799
800
 
@@ -810,8 +811,9 @@
810
811
  </div>
811
812
  </div>
812
813
  `;
813
- // Add styles
814
+ // Add styles and load VanillaOTP
814
815
  this.addStyles();
816
+ this.loadVanillaOTP();
815
817
  // Append to body
816
818
  document.body.appendChild(this.modal);
817
819
  // Get references
@@ -821,6 +823,18 @@
821
823
  // Setup event listeners
822
824
  this.setupEventListeners();
823
825
  }
826
+ /**
827
+ * Load VanillaOTP library
828
+ */
829
+ loadVanillaOTP() {
830
+ // Check if VanillaOTP is already loaded
831
+ if (window.VanillaOTP)
832
+ return;
833
+ // Inject VanillaOTP script
834
+ const script = document.createElement('script');
835
+ script.textContent = `"use strict";var VanillaOTP=function(t,e=null){if(this.emptyChar=" ","string"==typeof t)this.container=document.querySelector(t);else{if(!(t instanceof Element))return;this.container=t}e&&("string"==typeof e?this.updateTo=document.querySelector(e)||null:e instanceof Element?this.updateTo=e:this.updateTo=null),this.inputs=Array.from(this.container.querySelectorAll("input[type=text], input[type=number], input[type=password]"));let n=this,u=n.inputs.length;for(let i=0;i<u;i++){let l=n.inputs[i];l.addEventListener("input",function(){if(isNaN(l.value))return l.value=l.dataset.otpInputRestore||"",n._updateValue();if(0==l.value.length)return n._saveInputValue(i);if(1==l.value.length){n._saveInputValue(i),n._updateValue(),i+1<u&&n.inputs[i+1].focus();return}if(i==u-1)return n._setInputValue(i,l.value);let t=l.value.split("");for(let e=0;e<t.length&&!(e+i>=u);e++)n._setInputValue(e+i,t[e]);let a=Math.min(u-1,i+t.length);n.inputs[a].focus()}),l.addEventListener("keydown",function(t){if(8==t.keyCode&&""==l.value&&0!=i){n._setInputValue(i-1,""),n.inputs[i-1].focus();return}if(46==t.keyCode&&i!=u-1){let e=l.selectionStart||0;for(let a=i+e;a<u-1;a++)n._setInputValue(a,n.inputs[a+1].value);n._setInputValue(u-1,""),l.selectionStart&&(l.selectionStart=e),t.preventDefault();return}if(37==t.keyCode&&(null==l.selectionStart||0==l.selectionStart)){i>0&&(t.preventDefault(),n.inputs[i-1].focus(),n.inputs[i-1].select());return}if(39==t.keyCode&&(null==l.selectionStart||l.selectionEnd==l.value.length)){i+1<u&&(t.preventDefault(),n.inputs[i+1].focus(),n.inputs[i+1].select());return}})}};VanillaOTP.prototype.setEmptyChar=function(t){this.emptyChar=t},VanillaOTP.prototype.getValue=function(){let t="",e=this;return this.inputs.forEach(function(n){t+=""==n.value?e.emptyChar:n.value}),t},VanillaOTP.prototype.setValue=function(t){if(isNaN(t)){console.error("Please enter an integer value.");return}let e=(t=""+t).split("");for(let n=0;n<this.inputs.length;n++)this._setInputValue(n,e[n]||"")},VanillaOTP.prototype._setInputValue=function(t,e){return isNaN(e)?console.error("Please enter an integer value."):this.inputs[t]?void(this.inputs[t].value=String(e).substring(0,1),this._saveInputValue(t),this._updateValue()):console.error("Index not found.")},VanillaOTP.prototype._saveInputValue=function(t,e){if(!this.inputs[t])return console.error("Index not found.");this.inputs[t].dataset.otpInputRestore=e||this.inputs[t].value},VanillaOTP.prototype._updateValue=function(){this.updateTo&&(this.updateTo.value=this.getValue())};`;
836
+ document.head.appendChild(script);
837
+ }
824
838
  /**
825
839
  * Add CSS styles to the page
826
840
  */
@@ -1000,6 +1014,13 @@
1000
1014
  padding: 0 !important;
1001
1015
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
1002
1016
  background: #FFFFFF;
1017
+ -moz-appearance: textfield;
1018
+ }
1019
+
1020
+ .playkit-code-input::-webkit-outer-spin-button,
1021
+ .playkit-code-input::-webkit-inner-spin-button {
1022
+ -webkit-appearance: none;
1023
+ margin: 0;
1003
1024
  }
1004
1025
 
1005
1026
  .playkit-code-input:hover {
@@ -1109,7 +1130,7 @@
1109
1130
  * Setup event listeners
1110
1131
  */
1111
1132
  setupEventListeners() {
1112
- var _a, _b, _c;
1133
+ var _a, _b, _c, _d;
1113
1134
  // Auth type toggle
1114
1135
  const emailRadio = (_a = this.modal) === null || _a === void 0 ? void 0 : _a.querySelector('input[value="email"]');
1115
1136
  const phoneRadio = (_b = this.modal) === null || _b === void 0 ? void 0 : _b.querySelector('input[value="phone"]');
@@ -1144,44 +1165,23 @@
1144
1165
  this.onSendCodeClicked();
1145
1166
  }
1146
1167
  });
1147
- // Code inputs
1148
- const codeInputs = (_c = this.modal) === null || _c === void 0 ? void 0 : _c.querySelectorAll('.playkit-code-input');
1149
- codeInputs === null || codeInputs === void 0 ? void 0 : codeInputs.forEach((input, index) => {
1150
- input.addEventListener('input', (e) => {
1151
- const target = e.target;
1152
- // Only allow digits and limit to 1 character
1153
- const value = target.value.replace(/\D/g, '');
1154
- target.value = value.slice(0, 1);
1155
- // Move to next input if a digit was entered
1156
- if (target.value.length === 1 && index < codeInputs.length - 1) {
1157
- codeInputs[index + 1].focus();
1158
- }
1159
- // Auto-submit when all 6 digits entered
1160
- if (index === 5 && target.value.length === 1) {
1161
- this.onVerifyClicked();
1162
- }
1163
- });
1164
- input.addEventListener('keydown', (e) => {
1165
- if (e.key === 'Backspace' && !input.value && index > 0) {
1166
- codeInputs[index - 1].focus();
1167
- }
1168
- });
1169
- // Paste support
1170
- input.addEventListener('paste', (e) => {
1171
- var _a;
1172
- e.preventDefault();
1173
- const pastedData = ((_a = e.clipboardData) === null || _a === void 0 ? void 0 : _a.getData('text')) || '';
1174
- const digits = pastedData.replace(/\D/g, '').slice(0, 6);
1175
- digits.split('').forEach((digit, i) => {
1176
- if (codeInputs[i]) {
1177
- codeInputs[i].value = digit;
1168
+ // Initialize VanillaOTP for code inputs
1169
+ const codeInputsContainer = (_c = this.modal) === null || _c === void 0 ? void 0 : _c.querySelector('.playkit-code-inputs');
1170
+ if (codeInputsContainer && window.VanillaOTP) {
1171
+ this.otpInstance = new window.VanillaOTP(codeInputsContainer);
1172
+ // Auto-submit when all 6 digits entered
1173
+ const codeInputs = (_d = this.modal) === null || _d === void 0 ? void 0 : _d.querySelectorAll('.playkit-code-input');
1174
+ codeInputs === null || codeInputs === void 0 ? void 0 : codeInputs.forEach((input, index) => {
1175
+ input.addEventListener('input', () => {
1176
+ // Check if all inputs are filled
1177
+ const allFilled = Array.from(codeInputs).every(inp => inp.value.length === 1);
1178
+ if (allFilled) {
1179
+ // Small delay to ensure the last input is processed
1180
+ setTimeout(() => this.onVerifyClicked(), 100);
1178
1181
  }
1179
1182
  });
1180
- if (digits.length === 6) {
1181
- this.onVerifyClicked();
1182
- }
1183
1183
  });
1184
- });
1184
+ }
1185
1185
  // Verify button
1186
1186
  const verifyBtn = document.getElementById('playkit-verify-btn');
1187
1187
  verifyBtn === null || verifyBtn === void 0 ? void 0 : verifyBtn.addEventListener('click', () => this.onVerifyClicked());
@@ -1234,9 +1234,16 @@
1234
1234
  async onVerifyClicked() {
1235
1235
  var _a;
1236
1236
  this.clearError('verify');
1237
- const codeInputs = (_a = this.modal) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.playkit-code-input');
1238
- const code = Array.from(codeInputs).map((input) => input.value).join('');
1239
- if (code.length !== 6) {
1237
+ // Get code from VanillaOTP instance or fallback to manual collection
1238
+ let code = '';
1239
+ if (this.otpInstance) {
1240
+ code = this.otpInstance.getValue().replace(/\s/g, ''); // Remove spaces
1241
+ }
1242
+ else {
1243
+ const codeInputs = (_a = this.modal) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.playkit-code-input');
1244
+ code = Array.from(codeInputs).map((input) => input.value).join('');
1245
+ }
1246
+ if (code.length !== 6 || !/^\d{6}$/.test(code)) {
1240
1247
  this.showError(this.t('enterAllDigits'), 'verify');
1241
1248
  return;
1242
1249
  }
@@ -1325,8 +1332,13 @@
1325
1332
  if (this.verificationPanel)
1326
1333
  this.verificationPanel.style.display = 'none';
1327
1334
  // Clear code inputs
1328
- const codeInputs = (_a = this.modal) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.playkit-code-input');
1329
- codeInputs === null || codeInputs === void 0 ? void 0 : codeInputs.forEach((input) => (input.value = ''));
1335
+ if (this.otpInstance) {
1336
+ this.otpInstance.setValue(''); // Clear all inputs using VanillaOTP
1337
+ }
1338
+ else {
1339
+ const codeInputs = (_a = this.modal) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.playkit-code-input');
1340
+ codeInputs === null || codeInputs === void 0 ? void 0 : codeInputs.forEach((input) => (input.value = ''));
1341
+ }
1330
1342
  }
1331
1343
  showVerificationPanel() {
1332
1344
  var _a;