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