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
  */
@@ -311,6 +311,7 @@ class AuthFlowManager extends EventEmitter {
311
311
  this.identifierPanel = null;
312
312
  this.verificationPanel = null;
313
313
  this.loadingOverlay = null;
314
+ this.otpInstance = null;
314
315
  // @ts-ignore - replaced at build time
315
316
  this.baseURL = baseURL || "https://playkit.agentlandlab.com";
316
317
  this.currentLanguage = this.detectLanguage();
@@ -441,12 +442,12 @@ class AuthFlowManager extends EventEmitter {
441
442
 
442
443
  <div class="playkit-auth-input-group">
443
444
  <div class="playkit-code-inputs">
444
- <input type="text" maxlength="1" class="playkit-code-input" data-index="0">
445
- <input type="text" maxlength="1" class="playkit-code-input" data-index="1">
446
- <input type="text" maxlength="1" class="playkit-code-input" data-index="2">
447
- <input type="text" maxlength="1" class="playkit-code-input" data-index="3">
448
- <input type="text" maxlength="1" class="playkit-code-input" data-index="4">
449
- <input type="text" maxlength="1" class="playkit-code-input" data-index="5">
445
+ <input type="number" maxlength="1" class="playkit-code-input" data-index="0">
446
+ <input type="number" maxlength="1" class="playkit-code-input" data-index="1">
447
+ <input type="number" maxlength="1" class="playkit-code-input" data-index="2">
448
+ <input type="number" maxlength="1" class="playkit-code-input" data-index="3">
449
+ <input type="number" maxlength="1" class="playkit-code-input" data-index="4">
450
+ <input type="number" maxlength="1" class="playkit-code-input" data-index="5">
450
451
  </div>
451
452
  </div>
452
453
 
@@ -463,8 +464,9 @@ class AuthFlowManager extends EventEmitter {
463
464
  </div>
464
465
  </div>
465
466
  `;
466
- // Add styles
467
+ // Add styles and load VanillaOTP
467
468
  this.addStyles();
469
+ this.loadVanillaOTP();
468
470
  // Append to body
469
471
  document.body.appendChild(this.modal);
470
472
  // Get references
@@ -474,6 +476,18 @@ class AuthFlowManager extends EventEmitter {
474
476
  // Setup event listeners
475
477
  this.setupEventListeners();
476
478
  }
479
+ /**
480
+ * Load VanillaOTP library
481
+ */
482
+ loadVanillaOTP() {
483
+ // Check if VanillaOTP is already loaded
484
+ if (window.VanillaOTP)
485
+ return;
486
+ // Inject VanillaOTP script
487
+ const script = document.createElement('script');
488
+ 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())};`;
489
+ document.head.appendChild(script);
490
+ }
477
491
  /**
478
492
  * Add CSS styles to the page
479
493
  */
@@ -653,6 +667,13 @@ class AuthFlowManager extends EventEmitter {
653
667
  padding: 0 !important;
654
668
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
655
669
  background: #FFFFFF;
670
+ -moz-appearance: textfield;
671
+ }
672
+
673
+ .playkit-code-input::-webkit-outer-spin-button,
674
+ .playkit-code-input::-webkit-inner-spin-button {
675
+ -webkit-appearance: none;
676
+ margin: 0;
656
677
  }
657
678
 
658
679
  .playkit-code-input:hover {
@@ -762,7 +783,7 @@ class AuthFlowManager extends EventEmitter {
762
783
  * Setup event listeners
763
784
  */
764
785
  setupEventListeners() {
765
- var _a, _b, _c;
786
+ var _a, _b, _c, _d;
766
787
  // Auth type toggle
767
788
  const emailRadio = (_a = this.modal) === null || _a === void 0 ? void 0 : _a.querySelector('input[value="email"]');
768
789
  const phoneRadio = (_b = this.modal) === null || _b === void 0 ? void 0 : _b.querySelector('input[value="phone"]');
@@ -797,44 +818,23 @@ class AuthFlowManager extends EventEmitter {
797
818
  this.onSendCodeClicked();
798
819
  }
799
820
  });
800
- // Code inputs
801
- const codeInputs = (_c = this.modal) === null || _c === void 0 ? void 0 : _c.querySelectorAll('.playkit-code-input');
802
- codeInputs === null || codeInputs === void 0 ? void 0 : codeInputs.forEach((input, index) => {
803
- input.addEventListener('input', (e) => {
804
- const target = e.target;
805
- // Only allow digits and limit to 1 character
806
- const value = target.value.replace(/\D/g, '');
807
- target.value = value.slice(0, 1);
808
- // Move to next input if a digit was entered
809
- if (target.value.length === 1 && index < codeInputs.length - 1) {
810
- codeInputs[index + 1].focus();
811
- }
812
- // Auto-submit when all 6 digits entered
813
- if (index === 5 && target.value.length === 1) {
814
- this.onVerifyClicked();
815
- }
816
- });
817
- input.addEventListener('keydown', (e) => {
818
- if (e.key === 'Backspace' && !input.value && index > 0) {
819
- codeInputs[index - 1].focus();
820
- }
821
- });
822
- // Paste support
823
- input.addEventListener('paste', (e) => {
824
- var _a;
825
- e.preventDefault();
826
- const pastedData = ((_a = e.clipboardData) === null || _a === void 0 ? void 0 : _a.getData('text')) || '';
827
- const digits = pastedData.replace(/\D/g, '').slice(0, 6);
828
- digits.split('').forEach((digit, i) => {
829
- if (codeInputs[i]) {
830
- codeInputs[i].value = digit;
821
+ // Initialize VanillaOTP for code inputs
822
+ const codeInputsContainer = (_c = this.modal) === null || _c === void 0 ? void 0 : _c.querySelector('.playkit-code-inputs');
823
+ if (codeInputsContainer && window.VanillaOTP) {
824
+ this.otpInstance = new window.VanillaOTP(codeInputsContainer);
825
+ // Auto-submit when all 6 digits entered
826
+ const codeInputs = (_d = this.modal) === null || _d === void 0 ? void 0 : _d.querySelectorAll('.playkit-code-input');
827
+ codeInputs === null || codeInputs === void 0 ? void 0 : codeInputs.forEach((input, index) => {
828
+ input.addEventListener('input', () => {
829
+ // Check if all inputs are filled
830
+ const allFilled = Array.from(codeInputs).every(inp => inp.value.length === 1);
831
+ if (allFilled) {
832
+ // Small delay to ensure the last input is processed
833
+ setTimeout(() => this.onVerifyClicked(), 100);
831
834
  }
832
835
  });
833
- if (digits.length === 6) {
834
- this.onVerifyClicked();
835
- }
836
836
  });
837
- });
837
+ }
838
838
  // Verify button
839
839
  const verifyBtn = document.getElementById('playkit-verify-btn');
840
840
  verifyBtn === null || verifyBtn === void 0 ? void 0 : verifyBtn.addEventListener('click', () => this.onVerifyClicked());
@@ -887,9 +887,16 @@ class AuthFlowManager extends EventEmitter {
887
887
  async onVerifyClicked() {
888
888
  var _a;
889
889
  this.clearError('verify');
890
- const codeInputs = (_a = this.modal) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.playkit-code-input');
891
- const code = Array.from(codeInputs).map((input) => input.value).join('');
892
- if (code.length !== 6) {
890
+ // Get code from VanillaOTP instance or fallback to manual collection
891
+ let code = '';
892
+ if (this.otpInstance) {
893
+ code = this.otpInstance.getValue().replace(/\s/g, ''); // Remove spaces
894
+ }
895
+ else {
896
+ const codeInputs = (_a = this.modal) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.playkit-code-input');
897
+ code = Array.from(codeInputs).map((input) => input.value).join('');
898
+ }
899
+ if (code.length !== 6 || !/^\d{6}$/.test(code)) {
893
900
  this.showError(this.t('enterAllDigits'), 'verify');
894
901
  return;
895
902
  }
@@ -978,8 +985,13 @@ class AuthFlowManager extends EventEmitter {
978
985
  if (this.verificationPanel)
979
986
  this.verificationPanel.style.display = 'none';
980
987
  // Clear code inputs
981
- const codeInputs = (_a = this.modal) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.playkit-code-input');
982
- codeInputs === null || codeInputs === void 0 ? void 0 : codeInputs.forEach((input) => (input.value = ''));
988
+ if (this.otpInstance) {
989
+ this.otpInstance.setValue(''); // Clear all inputs using VanillaOTP
990
+ }
991
+ else {
992
+ const codeInputs = (_a = this.modal) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.playkit-code-input');
993
+ codeInputs === null || codeInputs === void 0 ? void 0 : codeInputs.forEach((input) => (input.value = ''));
994
+ }
983
995
  }
984
996
  showVerificationPanel() {
985
997
  var _a;