@preline/pin-input 2.5.0 → 2.6.0
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/index.d.ts +12 -0
- package/index.js +5 -5
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export interface IPinInputOptions {
|
|
|
21
21
|
}
|
|
22
22
|
export interface IPinInput {
|
|
23
23
|
options?: IPinInputOptions;
|
|
24
|
+
destroy(): void;
|
|
24
25
|
}
|
|
25
26
|
declare class HSPinInput extends HSBasePlugin<IPinInputOptions> implements IPinInput {
|
|
26
27
|
private items;
|
|
@@ -28,6 +29,16 @@ declare class HSPinInput extends HSBasePlugin<IPinInputOptions> implements IPinI
|
|
|
28
29
|
private currentValue;
|
|
29
30
|
private readonly placeholders;
|
|
30
31
|
private readonly availableCharsRE;
|
|
32
|
+
private onElementInputListener;
|
|
33
|
+
private onElementPasteListener;
|
|
34
|
+
private onElementKeydownListener;
|
|
35
|
+
private onElementFocusinListener;
|
|
36
|
+
private onElementFocusoutListener;
|
|
37
|
+
private elementInput;
|
|
38
|
+
private elementPaste;
|
|
39
|
+
private elementKeydown;
|
|
40
|
+
private elementFocusin;
|
|
41
|
+
private elementFocusout;
|
|
31
42
|
constructor(el: HTMLElement, options?: IPinInputOptions);
|
|
32
43
|
private init;
|
|
33
44
|
private build;
|
|
@@ -41,6 +52,7 @@ declare class HSPinInput extends HSBasePlugin<IPinInputOptions> implements IPinI
|
|
|
41
52
|
private onFocusIn;
|
|
42
53
|
private onFocusOut;
|
|
43
54
|
private onPaste;
|
|
55
|
+
destroy(): void;
|
|
44
56
|
static getInstance(target: HTMLElement | string, isInstance?: boolean): HSPinInput | ICollectionItem<HSPinInput>;
|
|
45
57
|
static autoInit(): void;
|
|
46
58
|
}
|
package/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n=e();for(var
|
|
1
|
+
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n=e();for(var o in n)("object"==typeof exports?exports:t)[o]=n[o]}}(self,(()=>(()=>{"use strict";var t={961:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(t,e,n){this.el=t,this.options=e,this.events=n,this.el=t,this.options=e,this.events={}}return t.prototype.createCollection=function(t,e){var n;t.push({id:(null===(n=null==e?void 0:e.el)||void 0===n?void 0:n.id)||t.length+1,element:e})},t.prototype.fireEvent=function(t,e){if(void 0===e&&(e=null),this.events.hasOwnProperty(t))return this.events[t](e)},t.prototype.on=function(t,e){this.events[t]=e},t}();e.default=n},60:function(t,e,n){
|
|
2
2
|
/*
|
|
3
3
|
* HSPinInput
|
|
4
|
-
* @version: 2.
|
|
4
|
+
* @version: 2.6.0
|
|
5
5
|
* @author: Preline Labs Ltd.
|
|
6
6
|
* @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html)
|
|
7
7
|
* Copyright 2024 Preline Labs Ltd.
|
|
8
8
|
*/
|
|
9
|
-
var i
|
|
9
|
+
var o,i=this&&this.__extends||(o=function(t,e){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},o(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),r=this&&this.__assign||function(){return r=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},r.apply(this,arguments)},u=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var s=n(292),l=function(t){function e(e,n){var o=t.call(this,e,n)||this,i=e.getAttribute("data-hs-pin-input"),u=i?JSON.parse(i):{},s=r(r({},u),n);return o.items=o.el.querySelectorAll("[data-hs-pin-input-item]"),o.currentItem=null,o.currentValue=new Array(o.items.length).fill(""),o.placeholders=[],o.availableCharsRE=new RegExp((null==s?void 0:s.availableCharsRE)||"^[a-zA-Z0-9]+$"),o.onElementInputListener=[],o.onElementPasteListener=[],o.onElementKeydownListener=[],o.onElementFocusinListener=[],o.onElementFocusoutListener=[],o.init(),o}return i(e,t),e.prototype.elementInput=function(t,e){this.onInput(t,e)},e.prototype.elementPaste=function(t){this.onPaste(t)},e.prototype.elementKeydown=function(t,e){this.onKeydown(t,e)},e.prototype.elementFocusin=function(t){this.onFocusIn(t)},e.prototype.elementFocusout=function(t){this.onFocusOut(t)},e.prototype.init=function(){this.createCollection(window.$hsPinInputCollection,this),this.items.length&&this.build()},e.prototype.build=function(){this.buildInputItems()},e.prototype.buildInputItems=function(){var t=this;this.items.forEach((function(e,n){t.placeholders.push(e.getAttribute("placeholder")||""),e.hasAttribute("autofocus")&&t.onFocusIn(n),t.onElementInputListener.push({el:e,fn:function(e){return t.elementInput(e,n)}}),t.onElementPasteListener.push({el:e,fn:function(e){return t.elementPaste(e)}}),t.onElementKeydownListener.push({el:e,fn:function(e){return t.elementKeydown(e,n)}}),t.onElementFocusinListener.push({el:e,fn:function(){return t.elementFocusin(n)}}),t.onElementFocusoutListener.push({el:e,fn:function(){return t.elementFocusout(n)}}),e.addEventListener("input",t.onElementInputListener.find((function(t){return t.el===e})).fn),e.addEventListener("paste",t.onElementPasteListener.find((function(t){return t.el===e})).fn),e.addEventListener("keydown",t.onElementKeydownListener.find((function(t){return t.el===e})).fn),e.addEventListener("focusin",t.onElementFocusinListener.find((function(t){return t.el===e})).fn),e.addEventListener("focusout",t.onElementFocusoutListener.find((function(t){return t.el===e})).fn)}))},e.prototype.checkIfNumber=function(t){return t.match(this.availableCharsRE)},e.prototype.autoFillAll=function(t){var e=this;Array.from(t).forEach((function(t,n){if(!(null==e?void 0:e.items[n]))return!1;e.items[n].value=t,e.items[n].dispatchEvent(new Event("input",{bubbles:!0}))}))},e.prototype.setCurrentValue=function(){this.currentValue=Array.from(this.items).map((function(t){return t.value}))},e.prototype.toggleCompleted=function(){this.currentValue.includes("")?this.el.classList.remove("active"):this.el.classList.add("active")},e.prototype.onInput=function(t,e){var n=t.target.value;if(this.currentItem=t.target,this.currentItem.value="",this.currentItem.value=n[n.length-1],!this.checkIfNumber(this.currentItem.value))return this.currentItem.value=this.currentValue[e]||"",!1;if(this.setCurrentValue(),this.currentItem.value){if(e<this.items.length-1&&this.items[e+1].focus(),!this.currentValue.includes("")){var o={currentValue:this.currentValue};this.fireEvent("completed",o),(0,s.dispatch)("completed.hs.pinInput",this.el,o)}this.toggleCompleted()}else e>0&&this.items[e-1].focus()},e.prototype.onKeydown=function(t,e){"Backspace"===t.key&&e>0&&(""===this.items[e].value?(this.items[e-1].value="",this.items[e-1].focus()):this.items[e].value=""),this.setCurrentValue(),this.toggleCompleted()},e.prototype.onFocusIn=function(t){this.items[t].setAttribute("placeholder","")},e.prototype.onFocusOut=function(t){this.items[t].setAttribute("placeholder",this.placeholders[t])},e.prototype.onPaste=function(t){var e=this;t.preventDefault(),this.items.forEach((function(n){document.activeElement===n&&e.autoFillAll(t.clipboardData.getData("text"))}))},e.prototype.destroy=function(){var t=this;this.el.classList.remove("active"),this.items.length&&this.items.forEach((function(e){e.removeEventListener("input",t.onElementInputListener.find((function(t){return t.el===e})).fn),e.removeEventListener("paste",t.onElementPasteListener.find((function(t){return t.el===e})).fn),e.removeEventListener("keydown",t.onElementKeydownListener.find((function(t){return t.el===e})).fn),e.removeEventListener("focusin",t.onElementFocusinListener.find((function(t){return t.el===e})).fn),e.removeEventListener("focusout",t.onElementFocusoutListener.find((function(t){return t.el===e})).fn)})),this.items=null,this.currentItem=null,this.currentValue=null,window.$hsPinInputCollection=window.$hsPinInputCollection.filter((function(e){return e.element.el!==t.el}))},e.getInstance=function(t,e){var n=window.$hsPinInputCollection.find((function(e){return e.element.el===("string"==typeof t?document.querySelector(t):t)}));return n?e?n:n.element:null},e.autoInit=function(){window.$hsPinInputCollection||(window.$hsPinInputCollection=[]),window.$hsPinInputCollection&&(window.$hsPinInputCollection=window.$hsPinInputCollection.filter((function(t){var e=t.element;return document.contains(e.el)}))),document.querySelectorAll("[data-hs-pin-input]:not(.--prevent-on-load-init)").forEach((function(t){window.$hsPinInputCollection.find((function(e){var n;return(null===(n=null==e?void 0:e.element)||void 0===n?void 0:n.el)===t}))||new e(t)}))},e}(u(n(961)).default);window.addEventListener("load",(function(){l.autoInit()})),"undefined"!=typeof window&&(window.HSPinInput=l),e.default=l},292:function(t,e){
|
|
10
10
|
/*
|
|
11
|
-
* @version: 2.
|
|
11
|
+
* @version: 2.6.0
|
|
12
12
|
* @author: Preline Labs Ltd.
|
|
13
13
|
* @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html)
|
|
14
14
|
* Copyright 2024 Preline Labs Ltd.
|
|
15
15
|
*/
|
|
16
|
-
var n=this;Object.defineProperty(e,"__esModule",{value:!0}),e.menuSearchHistory=e.classToClassList=e.htmlToElement=e.afterTransition=e.dispatch=e.debounce=e.isDirectChild=e.isFormElement=e.isParentOrElementHidden=e.isEnoughSpace=e.isIpadOS=e.isIOS=e.getZIndex=e.getClassPropertyAlt=e.getClassProperty=e.stringToBoolean=void 0,e.getHighestZIndex=function(t){var e=Number.NEGATIVE_INFINITY;return t.forEach((function(t){var n=
|
|
16
|
+
var n=this;Object.defineProperty(e,"__esModule",{value:!0}),e.menuSearchHistory=e.classToClassList=e.htmlToElement=e.afterTransition=e.dispatch=e.debounce=e.isJson=e.isDirectChild=e.isFormElement=e.isParentOrElementHidden=e.isEnoughSpace=e.isIpadOS=e.isIOS=e.getZIndex=e.getClassPropertyAlt=e.getClassProperty=e.stringToBoolean=void 0,e.getHighestZIndex=function(t){var e=Number.NEGATIVE_INFINITY;return t.forEach((function(t){var n=o(t);"auto"!==n&&(n=parseInt(n,10))>e&&(e=n)})),e};e.stringToBoolean=function(t){return"true"===t};e.getClassProperty=function(t,e,n){return void 0===n&&(n=""),(window.getComputedStyle(t).getPropertyValue(e)||n).replace(" ","")};e.getClassPropertyAlt=function(t,e,n){void 0===n&&(n="");var o="";return t.classList.forEach((function(t){t.includes(e)&&(o=t)})),o.match(/:(.*)]/)?o.match(/:(.*)]/)[1]:n};var o=function(t){return window.getComputedStyle(t).getPropertyValue("z-index")};e.getZIndex=o;e.isIOS=function(){return!!/iPad|iPhone|iPod/.test(navigator.platform)||navigator.maxTouchPoints&&navigator.maxTouchPoints>2&&/MacIntel/.test(navigator.platform)};e.isIpadOS=function(){return navigator.maxTouchPoints&&navigator.maxTouchPoints>2&&/MacIntel/.test(navigator.platform)};e.isDirectChild=function(t,e){for(var n=t.children,o=0;o<n.length;o++)if(n[o]===e)return!0;return!1};e.isEnoughSpace=function(t,e,n,o,i){void 0===n&&(n="auto"),void 0===o&&(o=10),void 0===i&&(i=null);var r=e.getBoundingClientRect(),u=i?i.getBoundingClientRect():null,s=window.innerHeight,l=u?r.top-u.top:r.top,a=(i?u.bottom:s)-r.bottom,c=t.clientHeight+o;return"bottom"===n?a>=c:"top"===n?l>=c:l>=c||a>=c};e.isFormElement=function(t){return t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement};var i=function(t){return!!t&&("none"===window.getComputedStyle(t).display||i(t.parentElement))};e.isParentOrElementHidden=i;e.isJson=function(t){if("string"!=typeof t)return!1;var e=t.trim()[0],n=t.trim().slice(-1);if("{"===e&&"}"===n||"["===e&&"]"===n)try{return JSON.parse(t),!0}catch(t){return!1}return!1};e.debounce=function(t,e){var o;return void 0===e&&(e=200),function(){for(var i=[],r=0;r<arguments.length;r++)i[r]=arguments[r];clearTimeout(o),o=setTimeout((function(){t.apply(n,i)}),e)}};e.dispatch=function(t,e,n){void 0===n&&(n=null);var o=new CustomEvent(t,{detail:{payload:n},bubbles:!0,cancelable:!0,composed:!1});e.dispatchEvent(o)};e.afterTransition=function(t,e){var n=function(){e(),t.removeEventListener("transitionend",n,!0)},o=window.getComputedStyle(t),i=o.getPropertyValue("transition-duration");"none"!==o.getPropertyValue("transition-property")&&parseFloat(i)>0?t.addEventListener("transitionend",n,!0):e()};e.htmlToElement=function(t){var e=document.createElement("template");return t=t.trim(),e.innerHTML=t,e.content.firstChild};e.classToClassList=function(t,e,n,o){void 0===n&&(n=" "),void 0===o&&(o="add"),t.split(n).forEach((function(t){return"add"===o?e.classList.add(t):e.classList.remove(t)}))};e.menuSearchHistory={historyIndex:-1,addHistory:function(t){this.historyIndex=t},existsInHistory:function(t){return t>this.historyIndex},clearHistory:function(){this.historyIndex=-1}}}},e={};var n=function n(o){var i=e[o];if(void 0!==i)return i.exports;var r=e[o]={exports:{}};return t[o].call(r.exports,r,r.exports,n),r.exports}(60);return n})()));
|
package/package.json
CHANGED